James Price a5d73ce965 transform/shader_io: Generate a wrapper function
This is a major reworking of this transform. The old transform code
was getting unwieldy, with part of the complication coming from the
handling of multiple return statements. By generating a wrapper
function instead, we can avoid a lot of this complexity.

The original entry point function is stripped of all shader IO
attributes (as well as `stage` and `workgroup_size`), but the body is
left unmodified. A new entry point wrapper function is introduced
which calls the original function, packing/unpacking the shader inputs
as necessary, and propagates the result to the corresponding shader
outputs.

The new code has been refactored to use a state object with the
different parts of the transform split into separate functions, which
makes it much more manageable.

Fixed: tint:1076
Bug: tint:920
Change-Id: I3490a0ea7a3509a4e198ce730e476516649d8d96
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60521
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-08-04 22:15:28 +00:00

144 lines
3.7 KiB
Plaintext

#include <metal_stdlib>
using namespace metal;
struct buf1 {
/* 0x0000 */ packed_float2 injectionSwitch;
};
struct buf2 {
/* 0x0000 */ packed_float2 resolution;
};
struct doesNotMatter {
/* 0x0000 */ int x_compute_data[1];
};
struct tint_array_wrapper {
float arr[1];
};
void main_1(constant buf1& x_10, constant buf2& x_13, device doesNotMatter& x_15, thread uint3* const tint_symbol_1) {
tint_array_wrapper A = {};
int i = 0;
float4 value = 0.0f;
int m = 0;
int l = 0;
int n = 0;
A.arr[0] = 0.0f;
i = 0;
while (true) {
int const x_60 = i;
if ((x_60 < 50)) {
} else {
break;
}
int const x_63 = i;
if ((x_63 > 0)) {
float const x_68 = A.arr[0];
float const x_70 = A.arr[0];
A.arr[0] = (x_70 + x_68);
}
{
int const x_73 = i;
i = as_type<int>((as_type<uint>(x_73) + as_type<uint>(1)));
}
}
while (true) {
uint const x_80 = (*(tint_symbol_1)).x;
if ((x_80 < 100u)) {
value = float4(0.0f, 0.0f, 0.0f, 1.0f);
m = 0;
while (true) {
int const x_89 = m;
if ((x_89 < 1)) {
} else {
break;
}
l = 0;
while (true) {
int const x_96 = l;
if ((x_96 < 1)) {
} else {
break;
}
float const x_100 = x_10.injectionSwitch.x;
float const x_102 = x_10.injectionSwitch.y;
if ((x_100 > x_102)) {
return;
}
{
int const x_106 = l;
l = as_type<int>((as_type<uint>(x_106) + as_type<uint>(1)));
}
}
{
int const x_108 = m;
m = as_type<int>((as_type<uint>(x_108) + as_type<uint>(1)));
}
}
n = 0;
while (true) {
int const x_114 = n;
if ((x_114 < 1)) {
} else {
break;
}
float const x_118 = x_10.injectionSwitch.x;
float const x_120 = x_10.injectionSwitch.y;
if ((x_118 > x_120)) {
threadgroup_barrier(mem_flags::mem_threadgroup);
}
{
int const x_124 = n;
n = as_type<int>((as_type<uint>(x_124) + as_type<uint>(1)));
}
}
} else {
uint const x_127 = (*(tint_symbol_1)).x;
if ((x_127 < 120u)) {
float const x_133 = A.arr[0];
float const x_135 = x_13.resolution.x;
float const x_138 = A.arr[0];
float const x_140 = x_13.resolution.y;
value = float4((x_133 / x_135), (x_138 / x_140), 0.0f, 1.0f);
} else {
float const x_144 = x_10.injectionSwitch.x;
float const x_146 = x_10.injectionSwitch.y;
if ((x_144 > x_146)) {
{
if (false) {
} else {
break;
}
}
continue;
}
}
}
{
if (false) {
} else {
break;
}
}
}
float const x_151 = value.x;
x_15.x_compute_data[0] = int(x_151);
float const x_155 = value.y;
x_15.x_compute_data[1] = int(x_155);
float const x_159 = value.z;
x_15.x_compute_data[2] = int(x_159);
float const x_163 = value.w;
x_15.x_compute_data[3] = int(x_163);
return;
}
void tint_symbol_inner(constant buf1& x_10, constant buf2& x_13, device doesNotMatter& x_15, uint3 gl_GlobalInvocationID_param, thread uint3* const tint_symbol_2) {
*(tint_symbol_2) = gl_GlobalInvocationID_param;
main_1(x_10, x_13, x_15, tint_symbol_2);
}
kernel void tint_symbol(uint3 gl_GlobalInvocationID_param [[thread_position_in_grid]], constant buf1& x_10 [[buffer(1)]], constant buf2& x_13 [[buffer(2)]], device doesNotMatter& x_15 [[buffer(0)]]) {
thread uint3 tint_symbol_3 = 0u;
tint_symbol_inner(x_10, x_13, x_15, gl_GlobalInvocationID_param, &(tint_symbol_3));
return;
}