From a81efa750f093fdbfcf28c5d9bd619fca119bcde Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 16 Apr 2019 07:46:02 -0700 Subject: Add the missing case for `AssocTypeDecl` in varying parameters' layout generation. (#947) --- source/slang/parameter-binding.cpp | 6 ++ source/slang/type-layout.cpp | 7 ++ tests/compute/type-param-varying.slang | 107 +++++++++++++++++++++ .../compute/type-param-varying.slang.expected.txt | 1 + 4 files changed, 121 insertions(+) create mode 100644 tests/compute/type-param-varying.slang create mode 100644 tests/compute/type-param-varying.slang.expected.txt diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index caab5ce6e..293a24338 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -1736,6 +1736,12 @@ static RefPtr processEntryPointVaryingParameter( genParamTypeLayout->findOrAddResourceInfo(LayoutResourceKind::GenericResource)->count += 1; return genParamTypeLayout; } + else if (auto associatedTypeParam = declRef.as()) + { + RefPtr assocTypeLayout = new TypeLayout(); + assocTypeLayout->type = type; + return assocTypeLayout; + } else { SLANG_UNEXPECTED("unhandled type kind"); diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index ce767fc8b..90acf0d3c 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -2784,6 +2784,13 @@ static TypeLayoutResult _createTypeLayout( return TypeLayoutResult(genParamTypeLayout, info); } + else if (auto assocTypeParam = declRef.as()) + { + return createSimpleTypeLayout( + SimpleLayoutInfo(), + type, + rules); + } else if( auto simpleGenericParam = declRef.as() ) { // A bare generic type parameter can come up during layout diff --git a/tests/compute/type-param-varying.slang b/tests/compute/type-param-varying.slang new file mode 100644 index 000000000..ef9ae9881 --- /dev/null +++ b/tests/compute/type-param-varying.slang @@ -0,0 +1,107 @@ +//TEST(compute):COMPARE_RENDER_COMPUTE: + +//TEST_INPUT: global_type AssembledVertex +//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(1),glbinding(0),out + +// Testing associated types in a varying parameter field + +interface IColorSet +{ + float3 getColor(); +} + +struct NoColorSet : IColorSet +{ + float3 getColor() { return float3(0.0); } +}; + +struct SingleColorSet : IColorSet +{ + float3 color; + float3 getColor() { return color; } +}; + +interface IVertexFormat +{ + associatedtype ColorSet : IColorSet; + ColorSet getColorSet(); + float3 getPosition(); + float2 getUv(); +} + +type_param TVertex : IVertexFormat; + +cbuffer Uniforms +{ + float4x4 modelViewProjection; +} +RWStructuredBuffer outputBuffer; + +struct AssembledVertex : IVertexFormat +{ + typedef SingleColorSet ColorSet; + float3 position; + SingleColorSet colorSet; + float2 uv; + ColorSet getColorSet() { return colorSet; } + float3 getPosition() { return position; } + float2 getUv() { return uv; } +}; + +struct CoarseVertex +{ + TVertex.ColorSet color; + float2 uv; +}; + +struct Fragment +{ + float4 color; +}; + + +// Vertex Shader + +struct VertexStageInput +{ + TVertex assembledVertex : A; +}; + +struct VertexStageOutput +{ + CoarseVertex coarseVertex : CoarseVertex; + float4 sv_position : SV_Position; +}; + +VertexStageOutput vertexMain(VertexStageInput input) +{ + VertexStageOutput output; + + float3 position = input.assembledVertex.getPosition(); + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); + output.coarseVertex.uv = input.assembledVertex.getUv(); + output.coarseVertex.color = input.assembledVertex.getColorSet(); + return output; +} + +// Fragment Shader + +struct FragmentStageInput +{ + CoarseVertex coarseVertex : CoarseVertex; +}; + +struct FragmentStageOutput +{ + Fragment fragment : SV_Target; +}; + +FragmentStageOutput fragmentMain(FragmentStageInput input) +{ + FragmentStageOutput output; + float3 color = input.coarseVertex.color.getColor(); + float2 uv = input.coarseVertex.uv; + output.fragment.color = float4(color, 1.0); + outputBuffer[0] = 1.0; + return output; +} diff --git a/tests/compute/type-param-varying.slang.expected.txt b/tests/compute/type-param-varying.slang.expected.txt new file mode 100644 index 000000000..47b9ba0c8 --- /dev/null +++ b/tests/compute/type-param-varying.slang.expected.txt @@ -0,0 +1 @@ +3F800000 \ No newline at end of file -- cgit v1.2.3