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>
This commit is contained in:
James Price
2021-08-04 22:15:28 +00:00
committed by Tint LUCI CQ
parent 3e92e9f8ba
commit a5d73ce965
3866 changed files with 49323 additions and 26508 deletions

View File

@@ -7,23 +7,32 @@ struct tint_symbol_2 {
float4 value : SV_Position;
};
tint_symbol_2 vert_main(tint_symbol_1 tint_symbol) {
const float2 a_particlePos = tint_symbol.a_particlePos;
const float2 a_particleVel = tint_symbol.a_particleVel;
const float2 a_pos = tint_symbol.a_pos;
float4 vert_main_inner(float2 a_particlePos, float2 a_particleVel, float2 a_pos) {
float angle = -(atan2(a_particleVel.x, a_particleVel.y));
float2 pos = float2(((a_pos.x * cos(angle)) - (a_pos.y * sin(angle))), ((a_pos.x * sin(angle)) + (a_pos.y * cos(angle))));
const tint_symbol_2 tint_symbol_9 = {float4((pos + a_particlePos), 0.0f, 1.0f)};
return tint_symbol_9;
return float4((pos + a_particlePos), 0.0f, 1.0f);
}
tint_symbol_2 vert_main(tint_symbol_1 tint_symbol) {
const float4 inner_result = vert_main_inner(tint_symbol.a_particlePos, tint_symbol.a_particleVel, tint_symbol.a_pos);
tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.value = inner_result;
return wrapper_result;
}
struct tint_symbol_3 {
float4 value : SV_Target0;
};
float4 frag_main_inner() {
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}
tint_symbol_3 frag_main() {
const tint_symbol_3 tint_symbol_10 = {float4(1.0f, 1.0f, 1.0f, 1.0f)};
return tint_symbol_10;
const float4 inner_result_1 = frag_main_inner();
tint_symbol_3 wrapper_result_1 = (tint_symbol_3)0;
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}
cbuffer cbuffer_params : register(b0, space0) {
@@ -36,9 +45,7 @@ struct tint_symbol_5 {
uint3 gl_GlobalInvocationID : SV_DispatchThreadID;
};
[numthreads(1, 1, 1)]
void comp_main(tint_symbol_5 tint_symbol_4) {
const uint3 gl_GlobalInvocationID = tint_symbol_4.gl_GlobalInvocationID;
void comp_main_inner(uint3 gl_GlobalInvocationID) {
uint index = gl_GlobalInvocationID.x;
if ((index >= 5u)) {
return;
@@ -95,5 +102,10 @@ void comp_main(tint_symbol_5 tint_symbol_4) {
}
particlesB.Store2((16u * index), asuint(vPos));
particlesB.Store2(((16u * index) + 8u), asuint(vVel));
}
[numthreads(1, 1, 1)]
void comp_main(tint_symbol_5 tint_symbol_4) {
comp_main_inner(tint_symbol_4.gl_GlobalInvocationID);
return;
}

View File

@@ -32,22 +32,31 @@ struct Particles {
/* 0x0000 */ tint_array_wrapper particles;
};
vertex tint_symbol_2 vert_main(tint_symbol_1 tint_symbol [[stage_in]]) {
float2 const a_particlePos = tint_symbol.a_particlePos;
float2 const a_particleVel = tint_symbol.a_particleVel;
float2 const a_pos = tint_symbol.a_pos;
float4 vert_main_inner(float2 a_particlePos, float2 a_particleVel, float2 a_pos) {
float angle = -(atan2(a_particleVel.x, a_particleVel.y));
float2 pos = float2(((a_pos.x * cos(angle)) - (a_pos.y * sin(angle))), ((a_pos.x * sin(angle)) + (a_pos.y * cos(angle))));
tint_symbol_2 const tint_symbol_5 = {.value=float4((pos + a_particlePos), 0.0f, 1.0f)};
return tint_symbol_5;
return float4((pos + a_particlePos), 0.0f, 1.0f);
}
vertex tint_symbol_2 vert_main(tint_symbol_1 tint_symbol [[stage_in]]) {
float4 const inner_result = vert_main_inner(tint_symbol.a_particlePos, tint_symbol.a_particleVel, tint_symbol.a_pos);
tint_symbol_2 wrapper_result = {};
wrapper_result.value = inner_result;
return wrapper_result;
}
float4 frag_main_inner() {
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}
fragment tint_symbol_3 frag_main() {
tint_symbol_3 const tint_symbol_6 = {.value=float4(1.0f, 1.0f, 1.0f, 1.0f)};
return tint_symbol_6;
float4 const inner_result_1 = frag_main_inner();
tint_symbol_3 wrapper_result_1 = {};
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}
kernel void comp_main(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant SimParams& params [[buffer(0)]], device Particles& particlesA [[buffer(1)]], device Particles& particlesB [[buffer(2)]]) {
void comp_main_inner(constant SimParams& params, device Particles& particlesA, device Particles& particlesB, uint3 gl_GlobalInvocationID) {
uint index = gl_GlobalInvocationID.x;
if ((index >= 5u)) {
return;
@@ -102,6 +111,10 @@ kernel void comp_main(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], c
}
particlesB.particles.arr[index].pos = vPos;
particlesB.particles.arr[index].vel = vVel;
}
kernel void comp_main(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant SimParams& params [[buffer(0)]], device Particles& particlesA [[buffer(1)]], device Particles& particlesB [[buffer(2)]]) {
comp_main_inner(params, particlesA, particlesB, gl_GlobalInvocationID);
return;
}

View File

@@ -27,13 +27,20 @@ float4x4 tint_symbol_6(uint4 buffer[4], uint offset) {
return float4x4(asfloat(buffer[scalar_offset / 4]), asfloat(buffer[scalar_offset_1 / 4]), asfloat(buffer[scalar_offset_2 / 4]), asfloat(buffer[scalar_offset_3 / 4]));
}
tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol) {
const VertexInput input = {tint_symbol.cur_position, tint_symbol.color};
VertexOutput vtx_main_inner(VertexInput input) {
VertexOutput output = (VertexOutput)0;
output.Position = mul(input.cur_position, tint_symbol_6(uniforms, 0u));
output.vtxFragColor = input.color;
const tint_symbol_2 tint_symbol_8 = {output.vtxFragColor, output.Position};
return tint_symbol_8;
return output;
}
tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol) {
const VertexInput tint_symbol_8 = {tint_symbol.cur_position, tint_symbol.color};
const VertexOutput inner_result = vtx_main_inner(tint_symbol_8);
tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.vtxFragColor = inner_result.vtxFragColor;
wrapper_result.Position = inner_result.Position;
return wrapper_result;
}
struct tint_symbol_4 {
@@ -43,8 +50,13 @@ struct tint_symbol_5 {
float4 value : SV_Target0;
};
tint_symbol_5 frag_main(tint_symbol_4 tint_symbol_3) {
const float4 fragColor = tint_symbol_3.fragColor;
const tint_symbol_5 tint_symbol_9 = {fragColor};
return tint_symbol_9;
float4 frag_main_inner(float4 fragColor) {
return fragColor;
}
tint_symbol_5 frag_main(tint_symbol_4 tint_symbol_3) {
const float4 inner_result_1 = frag_main_inner(tint_symbol_3.fragColor);
tint_symbol_5 wrapper_result_1 = (tint_symbol_5)0;
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}

View File

@@ -27,18 +27,30 @@ struct tint_symbol_5 {
float4 value [[color(0)]];
};
vertex tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol [[stage_in]], constant Uniforms& uniforms [[buffer(0)]]) {
VertexInput const input = {.cur_position=tint_symbol.cur_position, .color=tint_symbol.color};
VertexOutput vtx_main_inner(constant Uniforms& uniforms, VertexInput input) {
VertexOutput output = {};
output.Position = (uniforms.modelViewProjectionMatrix * input.cur_position);
output.vtxFragColor = input.color;
tint_symbol_2 const tint_symbol_6 = {.vtxFragColor=output.vtxFragColor, .Position=output.Position};
return tint_symbol_6;
return output;
}
vertex tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol [[stage_in]], constant Uniforms& uniforms [[buffer(0)]]) {
VertexInput const tint_symbol_6 = {.cur_position=tint_symbol.cur_position, .color=tint_symbol.color};
VertexOutput const inner_result = vtx_main_inner(uniforms, tint_symbol_6);
tint_symbol_2 wrapper_result = {};
wrapper_result.vtxFragColor = inner_result.vtxFragColor;
wrapper_result.Position = inner_result.Position;
return wrapper_result;
}
float4 frag_main_inner(float4 fragColor) {
return fragColor;
}
fragment tint_symbol_5 frag_main(tint_symbol_4 tint_symbol_3 [[stage_in]]) {
float4 const fragColor = tint_symbol_3.fragColor;
tint_symbol_5 const tint_symbol_7 = {.value=fragColor};
return tint_symbol_7;
float4 const inner_result_1 = frag_main_inner(tint_symbol_3.fragColor);
tint_symbol_5 wrapper_result_1 = {};
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}

View File

@@ -5,9 +5,15 @@ struct tint_symbol {
float4 value : SV_Target0;
};
tint_symbol main() {
float4 main_inner() {
float2 a = float2(0.0f, 0.0f);
bar();
const tint_symbol tint_symbol_1 = {float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f)};
return tint_symbol_1;
return float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f);
}
tint_symbol main() {
const float4 inner_result = main_inner();
tint_symbol wrapper_result = (tint_symbol)0;
wrapper_result.value = inner_result;
return wrapper_result;
}

View File

@@ -8,10 +8,16 @@ struct tint_symbol_1 {
void bar() {
}
fragment tint_symbol_1 tint_symbol() {
float4 tint_symbol_inner() {
float2 a = float2();
bar();
tint_symbol_1 const tint_symbol_2 = {.value=float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f)};
return tint_symbol_2;
return float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f);
}
fragment tint_symbol_1 tint_symbol() {
float4 const inner_result = tint_symbol_inner();
tint_symbol_1 wrapper_result = {};
wrapper_result.value = inner_result;
return wrapper_result;
}

View File

@@ -12,9 +12,15 @@ struct tint_symbol {
float4 gl_Position : SV_Position;
};
tint_symbol main() {
main_out main_inner() {
main_1();
const main_out tint_symbol_1 = {gl_Position};
const tint_symbol tint_symbol_2 = {tint_symbol_1.gl_Position};
return tint_symbol_2;
return tint_symbol_1;
}
tint_symbol main() {
const main_out inner_result = main_inner();
tint_symbol wrapper_result = (tint_symbol)0;
wrapper_result.gl_Position = inner_result.gl_Position;
return wrapper_result;
}

View File

@@ -8,16 +8,22 @@ struct tint_symbol_1 {
float4 gl_Position [[position]];
};
void main_1(thread float4* const tint_symbol_4) {
*(tint_symbol_4) = float4(0.0f, 0.0f, 0.0f, 0.0f);
void main_1(thread float4* const tint_symbol_3) {
*(tint_symbol_3) = float4(0.0f, 0.0f, 0.0f, 0.0f);
return;
}
main_out tint_symbol_inner(thread float4* const tint_symbol_4) {
main_1(tint_symbol_4);
main_out const tint_symbol_2 = {.gl_Position=*(tint_symbol_4)};
return tint_symbol_2;
}
vertex tint_symbol_1 tint_symbol() {
thread float4 tint_symbol_5 = 0.0f;
main_1(&(tint_symbol_5));
main_out const tint_symbol_2 = {.gl_Position=tint_symbol_5};
tint_symbol_1 const tint_symbol_3 = {.gl_Position=tint_symbol_2.gl_Position};
return tint_symbol_3;
main_out const inner_result = tint_symbol_inner(&(tint_symbol_5));
tint_symbol_1 wrapper_result = {};
wrapper_result.gl_Position = inner_result.gl_Position;
return wrapper_result;
}

View File

@@ -5,18 +5,29 @@ struct tint_symbol_2 {
float4 value : SV_Position;
};
tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol) {
const uint VertexIndex = tint_symbol.VertexIndex;
float4 vtx_main_inner(uint VertexIndex) {
float2 pos[3] = {float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)};
const tint_symbol_2 tint_symbol_4 = {float4(pos[VertexIndex], 0.0f, 1.0f)};
return tint_symbol_4;
return float4(pos[VertexIndex], 0.0f, 1.0f);
}
tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol) {
const float4 inner_result = vtx_main_inner(tint_symbol.VertexIndex);
tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.value = inner_result;
return wrapper_result;
}
struct tint_symbol_3 {
float4 value : SV_Target0;
};
tint_symbol_3 frag_main() {
const tint_symbol_3 tint_symbol_5 = {float4(1.0f, 0.0f, 0.0f, 1.0f)};
return tint_symbol_5;
float4 frag_main_inner() {
return float4(1.0f, 0.0f, 0.0f, 1.0f);
}
tint_symbol_3 frag_main() {
const float4 inner_result_1 = frag_main_inner();
tint_symbol_3 wrapper_result_1 = (tint_symbol_3)0;
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}

View File

@@ -1,24 +1,36 @@
#include <metal_stdlib>
using namespace metal;
struct tint_symbol_1 {
struct tint_symbol {
float4 value [[position]];
};
struct tint_array_wrapper {
float2 arr[3];
};
struct tint_symbol_2 {
struct tint_symbol_1 {
float4 value [[color(0)]];
};
vertex tint_symbol_1 vtx_main(uint VertexIndex [[vertex_id]]) {
float4 vtx_main_inner(uint VertexIndex) {
tint_array_wrapper pos = {.arr={float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}};
tint_symbol_1 const tint_symbol_3 = {.value=float4(pos.arr[VertexIndex], 0.0f, 1.0f)};
return tint_symbol_3;
return float4(pos.arr[VertexIndex], 0.0f, 1.0f);
}
fragment tint_symbol_2 frag_main() {
tint_symbol_2 const tint_symbol_4 = {.value=float4(1.0f, 0.0f, 0.0f, 1.0f)};
return tint_symbol_4;
vertex tint_symbol vtx_main(uint VertexIndex [[vertex_id]]) {
float4 const inner_result = vtx_main_inner(VertexIndex);
tint_symbol wrapper_result = {};
wrapper_result.value = inner_result;
return wrapper_result;
}
float4 frag_main_inner() {
return float4(1.0f, 0.0f, 0.0f, 1.0f);
}
fragment tint_symbol_1 frag_main() {
float4 const inner_result_1 = frag_main_inner();
tint_symbol_1 wrapper_result_1 = {};
wrapper_result_1.value = inner_result_1;
return wrapper_result_1;
}