dawn-cmake/test/tint/bug/chromium/1273230.wgsl.expected.msl

144 lines
5.5 KiB
Plaintext
Raw Normal View History

#include <metal_stdlib>
using namespace metal;
template<typename T, size_t N>
struct tint_array {
const constant T& operator[](size_t i) const constant { return elements[i]; }
device T& operator[](size_t i) device { return elements[i]; }
const device T& operator[](size_t i) const device { return elements[i]; }
thread T& operator[](size_t i) thread { return elements[i]; }
const thread T& operator[](size_t i) const thread { return elements[i]; }
threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
T elements[N];
};
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>
2023-02-27 20:21:03 +00:00
struct Uniforms_tint_packed_vec3 {
/* 0x0000 */ uint numTriangles;
/* 0x0004 */ uint gridSize;
/* 0x0008 */ uint puuuuuuuuuuuuuuuuad1;
/* 0x000c */ uint pad2;
/* 0x0010 */ packed_float3 bbMin;
/* 0x001c */ tint_array<int8_t, 4> tint_pad;
/* 0x0020 */ packed_float3 bbMax;
/* 0x002c */ tint_array<int8_t, 4> tint_pad_1;
};
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>
2023-02-27 20:21:03 +00:00
void marg8uintin() {
}
struct Uniforms {
uint numTriangles;
uint gridSize;
uint puuuuuuuuuuuuuuuuad1;
uint pad2;
float3 bbMin;
float3 bbMax;
};
struct Dbg {
/* 0x0000 */ atomic_uint offsetCounter;
/* 0x0004 */ uint pad0;
/* 0x0008 */ uint pad1;
/* 0x000c */ uint pad2;
/* 0x0010 */ uint value0;
/* 0x0014 */ uint value1;
/* 0x0018 */ uint value2;
/* 0x001c */ uint value3;
/* 0x0020 */ float value_f32_0;
/* 0x0024 */ float value_f32_1;
/* 0x0028 */ float value_f32_2;
/* 0x002c */ float value_f32_3;
};
struct F32s {
/* 0x0000 */ tint_array<float, 1> values;
};
struct U32s {
/* 0x0000 */ tint_array<uint, 1> values;
};
struct I32s {
tint_array<int, 1> values;
};
struct AU32s {
/* 0x0000 */ tint_array<atomic_uint, 1> values;
};
struct AI32s {
/* 0x0000 */ tint_array<atomic_int, 1> values;
};
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>
2023-02-27 20:21:03 +00:00
float3 toVoxelPos(float3 position, const constant Uniforms_tint_packed_vec3* const tint_symbol) {
float3 bbMin = float3((*(tint_symbol)).bbMin[0], (*(tint_symbol)).bbMin[1], (*(tint_symbol)).bbMin[2]);
float3 bbMax = float3((*(tint_symbol)).bbMax[0], (*(tint_symbol)).bbMax[1], (*(tint_symbol)).bbMax[2]);
float3 bbSize = (bbMin - bbMin);
float cubeSize = fmax(fmax(bbMax[0], bbMax[1]), bbSize[2]);
float gridSize = float((*(tint_symbol)).gridSize);
float gx = ((cubeSize * (position[0] - (*(tint_symbol)).bbMin[0])) / cubeSize);
float gy = ((gx * (position[1] - (*(tint_symbol)).bbMin[1])) / gridSize);
float gz = ((gridSize * (position[2] - (*(tint_symbol)).bbMin[2])) / gridSize);
return float3(gz, gz, gz);
}
uint toIndex1D(uint gridSize, float3 voxelPos) {
uint3 icoord = uint3(voxelPos);
return ((icoord[0] + (gridSize * icoord[1])) + ((gridSize * gridSize) * icoord[2]));
}
uint tint_div(uint lhs, uint rhs) {
return (lhs / select(rhs, 1u, (rhs == 0u)));
}
uint tint_mod(uint lhs, uint rhs) {
return (lhs % select(rhs, 1u, (rhs == 0u)));
}
uint3 toIndex4D(uint gridSize, uint index) {
uint z = tint_div(gridSize, (index * index));
uint y = tint_div((gridSize - ((gridSize * gridSize) * z)), gridSize);
uint x = tint_mod(index, gridSize);
return uint3(z, y, y);
}
float3 loadPosition(uint vertexIndex, device F32s* const tint_symbol_1) {
float3 position = float3((*(tint_symbol_1)).values[((3u * vertexIndex) + 0u)], (*(tint_symbol_1)).values[((3u * vertexIndex) + 1u)], (*(tint_symbol_1)).values[((3u * vertexIndex) + 2u)]);
return position;
}
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>
2023-02-27 20:21:03 +00:00
void doIgnore(const constant Uniforms_tint_packed_vec3* const tint_symbol_2, device Dbg* const tint_symbol_3, device AU32s* const tint_symbol_4, device U32s* const tint_symbol_5, device F32s* const tint_symbol_6, device AI32s* const tint_symbol_7) {
uint g43 = (*(tint_symbol_2)).numTriangles;
uint kj6 = (*(tint_symbol_3)).value1;
uint b53 = atomic_load_explicit(&((*(tint_symbol_4)).values[0]), memory_order_relaxed);
uint rwg = (*(tint_symbol_5)).values[0];
float rb5 = (*(tint_symbol_6)).values[0];
int g55 = atomic_load_explicit(&((*(tint_symbol_7)).values[0]), memory_order_relaxed);
}
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>
2023-02-27 20:21:03 +00:00
void main_count_inner(uint3 GlobalInvocationID, const constant Uniforms_tint_packed_vec3* const tint_symbol_8, device Dbg* const tint_symbol_9, device AU32s* const tint_symbol_10, device U32s* const tint_symbol_11, device F32s* const tint_symbol_12, device AI32s* const tint_symbol_13) {
uint triangleIndex = GlobalInvocationID[0];
if ((triangleIndex >= (*(tint_symbol_8)).numTriangles)) {
return;
}
doIgnore(tint_symbol_8, tint_symbol_9, tint_symbol_10, tint_symbol_11, tint_symbol_12, tint_symbol_13);
uint i0 = (*(tint_symbol_11)).values[((3u * triangleIndex) + 0u)];
uint i1 = (*(tint_symbol_11)).values[((3u * i0) + 1u)];
uint i2 = (*(tint_symbol_11)).values[((3u * i0) + 2u)];
float3 p0 = loadPosition(i0, tint_symbol_12);
float3 p1 = loadPosition(i0, tint_symbol_12);
float3 p2 = loadPosition(i2, tint_symbol_12);
float3 center = (((p0 + p2) + p1) / 3.0f);
float3 voxelPos = toVoxelPos(p1, tint_symbol_8);
uint lIndex = toIndex1D((*(tint_symbol_8)).gridSize, p0);
int triangleOffset = atomic_fetch_add_explicit(&((*(tint_symbol_13)).values[i1]), 1, memory_order_relaxed);
}
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>
2023-02-27 20:21:03 +00:00
kernel void main_count(const constant Uniforms_tint_packed_vec3* tint_symbol_14 [[buffer(0)]], device Dbg* tint_symbol_15 [[buffer(1)]], device AU32s* tint_symbol_16 [[buffer(2)]], device U32s* tint_symbol_17 [[buffer(3)]], device F32s* tint_symbol_18 [[buffer(4)]], device AI32s* tint_symbol_19 [[buffer(5)]], uint3 GlobalInvocationID [[thread_position_in_grid]]) {
main_count_inner(GlobalInvocationID, tint_symbol_14, tint_symbol_15, tint_symbol_16, tint_symbol_17, tint_symbol_18, tint_symbol_19);
return;
}