diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-11-05 16:31:47 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-05 16:31:47 -0800 |
| commit | 79056cd7e0ba261a007e21a98a6f49cb0b032e25 (patch) | |
| tree | f08c26c9f16ddbfb4a890ce7d201f27d037ccd03 /tests | |
| parent | 4fa76f374c0c35c9c7d186e8addf6861e98baaec (diff) | |
Legalize the Entry-point for WGSL (#5498)
* Legalize the Entry-point for WGSL
The return type of the entry-point needs to be legalized when targeting
WGSL.
This commit flattens the nested-structs of the return type and the input
parameters of the entry-point.
Most of code is copied from the legalization code for Metal. The
following functions are exactly same to the implementation for Metal or
almost same.
- flattenInputParameters() : 136 lines
- reportUnsupportedSystemAttribute() : 7 lines
- ensureResultStructHasUserSemantic() : 46 lines
- struct MapStructToFlatStruct : 176 lines
- flattenNestedStructs() : 95 lines
- maybeFlattenNestedStructs() : 42 lines
- _replaceAllReturnInst() : 19 lines
- _returnNonOverlappingAttributeIndex() : 16 lines
- _replaceAttributeOfLayout() : 23 lines
- tryConvertValue() : 41 lines
- legalizeSystemValueParameters() : 11 lines
They need to be refactored to reduce the duplication later.
The test case, `tests/compute/assoctype-lookup.slang`, had a bug that
the compute shader was trying to use the varying input/output with the
user defined semantics.
This commit removes the user defined semantics, because the compute
shaders cannot use the user defined semantics.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/assoctype-lookup.slang | 6 | ||||
| -rw-r--r-- | tests/wgsl/nested-varying-input.slang | 53 |
2 files changed, 56 insertions, 3 deletions
diff --git a/tests/compute/assoctype-lookup.slang b/tests/compute/assoctype-lookup.slang index 348391e21..8a032528b 100644 --- a/tests/compute/assoctype-lookup.slang +++ b/tests/compute/assoctype-lookup.slang @@ -16,8 +16,8 @@ struct StandardBoneWeightSet : IBoneWeightSet {
struct PackedType
{
- uint boneIds : BONEIDS;
- uint boneWeights : BONEWEIGHTS;
+ uint boneIds;
+ uint boneWeights;
};
PackedType field;
};
@@ -55,4 +55,4 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) int inputVal = int(tid);
int outputVal = test(inputVal);
gOutputBuffer[tid] = outputVal;
-}
\ No newline at end of file +}
diff --git a/tests/wgsl/nested-varying-input.slang b/tests/wgsl/nested-varying-input.slang new file mode 100644 index 000000000..2cdf4f7eb --- /dev/null +++ b/tests/wgsl/nested-varying-input.slang @@ -0,0 +1,53 @@ +//TEST:SIMPLE(filecheck=VERT): -target wgsl -stage vertex -entry vertexMain +//TEST:SIMPLE(filecheck=FRAG): -target wgsl -stage fragment -entry fragmentMain + +// Tests three aspects: +// 1. Flatten the nested struct for the return type of the entry-point +// 2. For fragment shader, SV_TARGET index must be emitted as @location(index) +// 3. For non-fragment shader, the user defined semantics should be emitted as @location(index) + +struct FragmentOutput +{ + //FRAG: @location(1) color1 + float4 color1 : SV_TARGET1; + + //FRAG: @location(0) color0 + float4 color0 : SV_TARGET0; +}; + +struct NestedVertexOutput +{ + float4 color : COLOR0; +}; + +struct VertexOutput +{ + //VERT: @builtin(position) position + //FRAG: @builtin(position) position + float4 position : SV_Position; + + //VERT: @location(0) uv + //FRAG: @location(0) uv + float2 uv : TEXCOORD0; + + //VERT: @location(1) color + //FRAG: @location(1) color + NestedVertexOutput nested; +}; + +VertexOutput vertexMain() +{ + VertexOutput out; + out.position = float4(1.0, 1.0, 1.0, 1.0); + out.uv = float2(0.5, 0.5); + out.nested.color = float4(0.0, 0.0, 0.0, 0.0); + return out; +} + +FragmentOutput fragmentMain(VertexOutput input) +{ + FragmentOutput out; + out.color0 = input.nested.color; + out.color1 = input.nested.color; + return out; +} |
