mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 07:06:11 +00:00
tint/msl: Preserve trailing vec3 padding
In order to preserve padding properly for MSL, we need to use its packed_vec type for all vec3 types in storage buffers, not just struct members. This commit includes a complete rewrite of the PackedVec3 transform to achieve this. The key details are: * An internal `__packed_vec3<>` type was added, which corresponds to a `type::Vector` with an additional flag to indicate that it will be emitted as packed vector. * The `PackedVec3` transform replaces all vec3 types used in host-shareable address spaces with the internal `__packed_vec3` type. This includes vec3 types that appear as the store type of a pointer. * When used as an array element, these `__packed_vec3` types are wrapped in a struct that contains a single `__packed_vec3` member. This allows us to add an `@align()` attribute that ensures that `array<vec3<T>>` still has the correct array element stride. * When the `vec3<T>` appears as a struct member in the input program, we apply the `@align()` to that member to ensure that we do not change its offset. * Matrix types with three rows that are used in memory are replaced with an array of columns, where each column uses a `__packed_vec3` inside an aligned wrapper structure as above. * Accesses to host-shareable memory that involve any of these types invoke a "pack" or "unpack" helper function to convert them to the equivalent type that uses `__packed_vec3` or a regular `vec3` as required. * The `chromium_internal_relaxed_uniform_layout` extension is used to avoid issues where modifying a type in the uniform address space triggers stricter layout validation rules. Bug: tint:1571 Fixed: tint:1837 Change-Id: Idaf2da2f5bcb2be00c85ec657edfb614186476bb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121200 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
55183e6c3a
commit
4d3af66bbd
@@ -14,20 +14,41 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int i() {
|
||||
thread int tint_symbol_2 = 0;
|
||||
tint_symbol_2 = as_type<int>((as_type<uint>(tint_symbol_2) + as_type<uint>(1)));
|
||||
return tint_symbol_2;
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol_3 [[buffer(0)]]) {
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol_3 [[buffer(0)]]) {
|
||||
int const tint_symbol = i();
|
||||
int const p_a_i_save = tint_symbol;
|
||||
int const tint_symbol_1 = i();
|
||||
int const p_a_i_i_save = tint_symbol_1;
|
||||
tint_array<float4x3, 4> const l_a = *(tint_symbol_3);
|
||||
float4x3 const l_a_i = (*(tint_symbol_3))[p_a_i_save];
|
||||
float3 const l_a_i_i = (*(tint_symbol_3))[p_a_i_save][p_a_i_i_save];
|
||||
tint_array<float4x3, 4> const l_a = tint_unpack_vec3_in_composite_1(*(tint_symbol_3));
|
||||
float4x3 const l_a_i = tint_unpack_vec3_in_composite((*(tint_symbol_3))[p_a_i_save]);
|
||||
float3 const l_a_i_i = float3((*(tint_symbol_3))[p_a_i_save][p_a_i_i_save].elements);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,31 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol [[buffer(0)]]) {
|
||||
tint_array<float4x3, 4> const l_a = *(tint_symbol);
|
||||
float4x3 const l_a_i = (*(tint_symbol))[2];
|
||||
float3 const l_a_i_i = (*(tint_symbol))[2][1];
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol [[buffer(0)]]) {
|
||||
tint_array<float4x3, 4> const l_a = tint_unpack_vec3_in_composite_1(*(tint_symbol));
|
||||
float4x3 const l_a_i = tint_unpack_vec3_in_composite((*(tint_symbol))[2]);
|
||||
float3 const l_a_i_i = float3((*(tint_symbol))[2][1].elements);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,23 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol [[buffer(0)]]) {
|
||||
float3x4 const t = transpose((*(tint_symbol))[2]);
|
||||
float const l = length(float3((*(tint_symbol))[0][1]).zxy);
|
||||
float const a = fabs(float3((*(tint_symbol))[0][1]).zxy[0]);
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol [[buffer(0)]]) {
|
||||
float3x4 const t = transpose(tint_unpack_vec3_in_composite((*(tint_symbol))[2]));
|
||||
float const l = length(float3((*(tint_symbol))[0][1].elements).zxy);
|
||||
float const a = fabs(float3((*(tint_symbol))[0][1].elements).zxy[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,27 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void a(tint_array<float4x3, 4> a_1) {
|
||||
}
|
||||
|
||||
@@ -26,11 +47,11 @@ void c(float3 v) {
|
||||
void d(float f_1) {
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol [[buffer(0)]]) {
|
||||
a(*(tint_symbol));
|
||||
b((*(tint_symbol))[1]);
|
||||
c(float3((*(tint_symbol))[1][0]).zxy);
|
||||
d(float3((*(tint_symbol))[1][0]).zxy[0]);
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol [[buffer(0)]]) {
|
||||
a(tint_unpack_vec3_in_composite_1(*(tint_symbol)));
|
||||
b(tint_unpack_vec3_in_composite((*(tint_symbol))[1]));
|
||||
c(float3((*(tint_symbol))[1][0].elements).zxy);
|
||||
d(float3((*(tint_symbol))[1][0].elements).zxy[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,33 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol_1 [[buffer(0)]]) {
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol_1 [[buffer(0)]]) {
|
||||
thread tint_array<float4x3, 4> tint_symbol = {};
|
||||
tint_symbol = *(tint_symbol_1);
|
||||
tint_symbol[1] = (*(tint_symbol_1))[2];
|
||||
tint_symbol[1][0] = float3((*(tint_symbol_1))[0][1]).zxy;
|
||||
tint_symbol[1][0][0] = (*(tint_symbol_1))[0][1][0];
|
||||
tint_symbol = tint_unpack_vec3_in_composite_1(*(tint_symbol_1));
|
||||
tint_symbol[1] = tint_unpack_vec3_in_composite((*(tint_symbol_1))[2]);
|
||||
tint_symbol[1][0] = float3((*(tint_symbol_1))[0][1].elements).zxy;
|
||||
tint_symbol[1][0][0] = (*(tint_symbol_1))[0][1].elements[0];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,24 +14,45 @@ struct tint_array {
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
void assign_and_preserve_padding_1(device float4x3* const dest, float4x3 value) {
|
||||
(*(dest))[0u] = value[0u];
|
||||
(*(dest))[1u] = value[1u];
|
||||
(*(dest))[2u] = value[2u];
|
||||
(*(dest))[3u] = value[3u];
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void assign_and_preserve_padding(device tint_array<float4x3, 4>* const dest, tint_array<float4x3, 4> value) {
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void assign_and_preserve_padding_1(device tint_array<tint_packed_vec3_f32_array_element, 4>* const dest, float4x3 value) {
|
||||
(*(dest))[0u].elements = packed_float3(value[0u]);
|
||||
(*(dest))[1u].elements = packed_float3(value[1u]);
|
||||
(*(dest))[2u].elements = packed_float3(value[2u]);
|
||||
(*(dest))[3u].elements = packed_float3(value[3u]);
|
||||
}
|
||||
|
||||
void assign_and_preserve_padding(device tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* const dest, tint_array<float4x3, 4> value) {
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
assign_and_preserve_padding_1(&((*(dest))[i]), value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
kernel void f(device tint_array<float4x3, 4>* tint_symbol [[buffer(1)]], const constant tint_array<float4x3, 4>* tint_symbol_1 [[buffer(0)]]) {
|
||||
assign_and_preserve_padding(tint_symbol, *(tint_symbol_1));
|
||||
assign_and_preserve_padding_1(&((*(tint_symbol))[1]), (*(tint_symbol_1))[2]);
|
||||
(*(tint_symbol))[1][0] = float3((*(tint_symbol_1))[0][1]).zxy;
|
||||
(*(tint_symbol))[1][0][0] = (*(tint_symbol_1))[0][1][0];
|
||||
kernel void f(device tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol [[buffer(1)]], const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol_1 [[buffer(0)]]) {
|
||||
assign_and_preserve_padding(tint_symbol, tint_unpack_vec3_in_composite_1(*(tint_symbol_1)));
|
||||
assign_and_preserve_padding_1(&((*(tint_symbol))[1]), tint_unpack_vec3_in_composite((*(tint_symbol_1))[2]));
|
||||
(*(tint_symbol))[1][0].elements = packed_float3(float3((*(tint_symbol_1))[0][1].elements).zxy);
|
||||
(*(tint_symbol))[1][0].elements[0] = (*(tint_symbol_1))[0][1].elements[0];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,19 +18,40 @@ struct tint_symbol_5 {
|
||||
tint_array<float4x3, 4> w;
|
||||
};
|
||||
|
||||
void f_inner(uint local_invocation_index, threadgroup tint_array<float4x3, 4>* const tint_symbol, const constant tint_array<float4x3, 4>* const tint_symbol_1) {
|
||||
struct tint_packed_vec3_f32_array_element {
|
||||
/* 0x0000 */ packed_float3 elements;
|
||||
/* 0x000c */ tint_array<int8_t, 4> tint_pad;
|
||||
};
|
||||
|
||||
float4x3 tint_unpack_vec3_in_composite(tint_array<tint_packed_vec3_f32_array_element, 4> in) {
|
||||
float4x3 result = float4x3(0.0f);
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = float3(in[i].elements);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tint_array<float4x3, 4> tint_unpack_vec3_in_composite_1(tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4> in) {
|
||||
tint_array<float4x3, 4> result = {};
|
||||
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
|
||||
result[i] = tint_unpack_vec3_in_composite(in[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void f_inner(uint local_invocation_index, threadgroup tint_array<float4x3, 4>* const tint_symbol, const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* const tint_symbol_1) {
|
||||
for(uint idx = local_invocation_index; (idx < 4u); idx = (idx + 1u)) {
|
||||
uint const i = idx;
|
||||
(*(tint_symbol))[i] = float4x3(float3(0.0f), float3(0.0f), float3(0.0f), float3(0.0f));
|
||||
}
|
||||
threadgroup_barrier(mem_flags::mem_threadgroup);
|
||||
*(tint_symbol) = *(tint_symbol_1);
|
||||
(*(tint_symbol))[1] = (*(tint_symbol_1))[2];
|
||||
(*(tint_symbol))[1][0] = float3((*(tint_symbol_1))[0][1]).zxy;
|
||||
(*(tint_symbol))[1][0][0] = (*(tint_symbol_1))[0][1][0];
|
||||
*(tint_symbol) = tint_unpack_vec3_in_composite_1(*(tint_symbol_1));
|
||||
(*(tint_symbol))[1] = tint_unpack_vec3_in_composite((*(tint_symbol_1))[2]);
|
||||
(*(tint_symbol))[1][0] = float3((*(tint_symbol_1))[0][1].elements).zxy;
|
||||
(*(tint_symbol))[1][0][0] = (*(tint_symbol_1))[0][1].elements[0];
|
||||
}
|
||||
|
||||
kernel void f(const constant tint_array<float4x3, 4>* tint_symbol_4 [[buffer(0)]], threadgroup tint_symbol_5* tint_symbol_3 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
|
||||
kernel void f(const constant tint_array<tint_array<tint_packed_vec3_f32_array_element, 4>, 4>* tint_symbol_4 [[buffer(0)]], threadgroup tint_symbol_5* tint_symbol_3 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
|
||||
threadgroup tint_array<float4x3, 4>* const tint_symbol_2 = &((*(tint_symbol_3)).w);
|
||||
f_inner(local_invocation_index, tint_symbol_2, tint_symbol_4);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user