Skip to content

Commit

Permalink
wgsl: Fix field semantics even if input struct doesn't need flattening (
Browse files Browse the repository at this point in the history
#5642)

* wgsl: Fix field semantics even if input struct doesn't need flattening

Helps to address issue #5633.

* Add test for multiple stage IO locations

This verifies part of issue #5633.
  • Loading branch information
aleino-nv authored Nov 25, 2024
1 parent e30f053 commit aaca2d2
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 3 deletions.
5 changes: 2 additions & 3 deletions source/slang/slang-ir-wgsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ struct LegalizeWGSLEntryPointContext
structType,
mapOldFieldToNewField,
semanticInfoToRemove);
// Validate/rearange all semantics which overlap in our flat struct.
fixFieldSemanticsOfFlatStruct(flattenedStruct);
if (flattenedStruct != structType)
{
// Validate/rearange all semantics which overlap in our flat struct
fixFieldSemanticsOfFlatStruct(flattenedStruct);

// Replace the 'old IRParam type' with a 'new IRParam type'
param->setFullType(flattenedStruct);

Expand Down
1 change: 1 addition & 0 deletions tests/expected-failure-github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tests/language-feature/saturated-cooperation/fuse-product.slang (vk)
tests/language-feature/saturated-cooperation/fuse.slang (vk)
tests/bugs/byte-address-buffer-interlocked-add-f32.slang (vk)
tests/render/render0.hlsl (mtl)
tests/render/multiple-stage-io-locations.slang (mtl)
tests/render/nointerpolation.hlsl (mtl)
tests/serialization/obfuscated-serialized-module-test.slang.2 syn (mtl)
tests/autodiff/custom-intrinsic.slang.2 syn (wgpu)
Expand Down
78 changes: 78 additions & 0 deletions tests/render/multiple-stage-io-locations.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//TEST(smoke,render):COMPARE_HLSL_RENDER:
// TODO: Investigate Metal failure
//DISABLE_TEST(smoke,render):COMPARE_HLSL_RENDER: -mtl

cbuffer Uniforms
{
float4x4 modelViewProjection;
}

struct AssembledVertex
{
float3 position;
float3 color;
};

struct Fragment
{
float4 color;
};

// Vertex Shader

struct VertexStageInput
{
AssembledVertex assembledVertex : A;
};

struct VertexStageOutput
{
float3 color : VERTEX_COLOR;
float3 localPosition : VERTEX_LOCAL_POSITION;
float4 sv_position : SV_Position;
};

VertexStageOutput vertexMain(VertexStageInput input)
{
VertexStageOutput output;

float3 position = input.assembledVertex.position;
float3 color = input.assembledVertex.color;

output.color = color;
output.sv_position = mul(modelViewProjection, float4(position, 1.0));
output.localPosition = position;

return output;
}

// Fragment Shader

struct FragmentStageInput
{
float3 color : VERTEX_COLOR;
float3 localPosition : VERTEX_LOCAL_POSITION;
};

struct FragmentStageOutput
{
Fragment fragment : SV_Target;
};

FragmentStageOutput fragmentMain(FragmentStageInput input)
{
FragmentStageOutput output;

float3 color = input.color;

if (input.color.y < input.color.z)
{
output.fragment.color = float4(input.localPosition, 1.0);
}
else
{
output.fragment.color = float4(input.color, 1.0);
}

return output;
}
5 changes: 5 additions & 0 deletions tests/render/multiple-stage-io-locations.slang.1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
result code = 0
standard error = {
}
standard output = {
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/render/multiple-stage-io-locations.slang.2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
result code = 0
standard error = {
}
standard output = {
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/render/multiple-stage-io-locations.slang.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
result code = 0
standard error = {
}
standard output = {
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aaca2d2

Please sign in to comment.