dawn-cmake/test/tint/var/inferred/global.wgsl.expected.msl
James Price 0e22bdbae7 tint/msl: Fix emission of private variables
In order to avoid declaring too many function parameters, we
previously modified this transform to redeclare private variables that
are only used inside a single function as function-scope
variables. This was broken as it meant that their values did not
persist across multiple calls to the same function.

Instead, wrap all private variables in a structure and pass it around
as a pointer.

Fixed: tint:1875
Change-Id: I83f5eb1071d57b9c6af56d6cf21b3a32c6e94260
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124800
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2023-03-20 21:46:01 +00:00

77 lines
2.3 KiB
Plaintext

#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];
};
struct MyStruct {
float f1;
};
struct tint_private_vars_struct {
int v1;
uint v2;
float v3;
int3 v4;
uint3 v5;
float3 v6;
MyStruct v7;
tint_array<float, 10> v8;
int v9;
uint v10;
float v11;
MyStruct v12;
MyStruct v13;
tint_array<float, 10> v14;
int3 v15;
float3 v16;
};
kernel void f() {
thread tint_private_vars_struct tint_private_vars = {};
tint_private_vars.v1 = 1;
tint_private_vars.v2 = 1u;
tint_private_vars.v3 = 1.0f;
tint_private_vars.v4 = int3(1);
tint_private_vars.v5 = uint3(1u, 2u, 3u);
tint_private_vars.v6 = float3(1.0f, 2.0f, 3.0f);
tint_private_vars.v7 = MyStruct{.f1=1.0f};
tint_private_vars.v8 = tint_array<float, 10>{};
tint_private_vars.v9 = 0;
tint_private_vars.v10 = 0u;
tint_private_vars.v11 = 0.0f;
tint_private_vars.v12 = MyStruct{};
tint_private_vars.v13 = MyStruct{};
tint_private_vars.v14 = tint_array<float, 10>{};
tint_private_vars.v15 = int3(1, 2, 3);
tint_private_vars.v16 = float3(1.0f, 2.0f, 3.0f);
int const l1 = tint_private_vars.v1;
uint const l2 = tint_private_vars.v2;
float const l3 = tint_private_vars.v3;
int3 const l4 = tint_private_vars.v4;
uint3 const l5 = tint_private_vars.v5;
float3 const l6 = tint_private_vars.v6;
MyStruct const l7 = tint_private_vars.v7;
tint_array<float, 10> const l8 = tint_private_vars.v8;
int const l9 = tint_private_vars.v9;
uint const l10 = tint_private_vars.v10;
float const l11 = tint_private_vars.v11;
MyStruct const l12 = tint_private_vars.v12;
MyStruct const l13 = tint_private_vars.v13;
tint_array<float, 10> const l14 = tint_private_vars.v14;
int3 const l15 = tint_private_vars.v15;
float3 const l16 = tint_private_vars.v16;
return;
}