Skip to content

Commit a81efa7

Browse files
csyongheTim Foley
authored and
Tim Foley
committed
Add the missing case for AssocTypeDecl in varying parameters' layout generation. (shader-slang#947)
1 parent 7c82ead commit a81efa7

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

source/slang/parameter-binding.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,12 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter(
17361736
genParamTypeLayout->findOrAddResourceInfo(LayoutResourceKind::GenericResource)->count += 1;
17371737
return genParamTypeLayout;
17381738
}
1739+
else if (auto associatedTypeParam = declRef.as<AssocTypeDecl>())
1740+
{
1741+
RefPtr<TypeLayout> assocTypeLayout = new TypeLayout();
1742+
assocTypeLayout->type = type;
1743+
return assocTypeLayout;
1744+
}
17391745
else
17401746
{
17411747
SLANG_UNEXPECTED("unhandled type kind");

source/slang/type-layout.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,13 @@ static TypeLayoutResult _createTypeLayout(
27842784

27852785
return TypeLayoutResult(genParamTypeLayout, info);
27862786
}
2787+
else if (auto assocTypeParam = declRef.as<AssocTypeDecl>())
2788+
{
2789+
return createSimpleTypeLayout(
2790+
SimpleLayoutInfo(),
2791+
type,
2792+
rules);
2793+
}
27872794
else if( auto simpleGenericParam = declRef.as<GenericTypeParamDecl>() )
27882795
{
27892796
// A bare generic type parameter can come up during layout
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//TEST(compute):COMPARE_RENDER_COMPUTE:
2+
3+
//TEST_INPUT: global_type AssembledVertex
4+
//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(1),glbinding(0),out
5+
6+
// Testing associated types in a varying parameter field
7+
8+
interface IColorSet
9+
{
10+
float3 getColor();
11+
}
12+
13+
struct NoColorSet : IColorSet
14+
{
15+
float3 getColor() { return float3(0.0); }
16+
};
17+
18+
struct SingleColorSet : IColorSet
19+
{
20+
float3 color;
21+
float3 getColor() { return color; }
22+
};
23+
24+
interface IVertexFormat
25+
{
26+
associatedtype ColorSet : IColorSet;
27+
ColorSet getColorSet();
28+
float3 getPosition();
29+
float2 getUv();
30+
}
31+
32+
type_param TVertex : IVertexFormat;
33+
34+
cbuffer Uniforms
35+
{
36+
float4x4 modelViewProjection;
37+
}
38+
RWStructuredBuffer<float> outputBuffer;
39+
40+
struct AssembledVertex : IVertexFormat
41+
{
42+
typedef SingleColorSet ColorSet;
43+
float3 position;
44+
SingleColorSet colorSet;
45+
float2 uv;
46+
ColorSet getColorSet() { return colorSet; }
47+
float3 getPosition() { return position; }
48+
float2 getUv() { return uv; }
49+
};
50+
51+
struct CoarseVertex
52+
{
53+
TVertex.ColorSet color;
54+
float2 uv;
55+
};
56+
57+
struct Fragment
58+
{
59+
float4 color;
60+
};
61+
62+
63+
// Vertex Shader
64+
65+
struct VertexStageInput
66+
{
67+
TVertex assembledVertex : A;
68+
};
69+
70+
struct VertexStageOutput
71+
{
72+
CoarseVertex coarseVertex : CoarseVertex;
73+
float4 sv_position : SV_Position;
74+
};
75+
76+
VertexStageOutput vertexMain(VertexStageInput input)
77+
{
78+
VertexStageOutput output;
79+
80+
float3 position = input.assembledVertex.getPosition();
81+
output.sv_position = mul(modelViewProjection, float4(position, 1.0));
82+
output.coarseVertex.uv = input.assembledVertex.getUv();
83+
output.coarseVertex.color = input.assembledVertex.getColorSet();
84+
return output;
85+
}
86+
87+
// Fragment Shader
88+
89+
struct FragmentStageInput
90+
{
91+
CoarseVertex coarseVertex : CoarseVertex;
92+
};
93+
94+
struct FragmentStageOutput
95+
{
96+
Fragment fragment : SV_Target;
97+
};
98+
99+
FragmentStageOutput fragmentMain(FragmentStageInput input)
100+
{
101+
FragmentStageOutput output;
102+
float3 color = input.coarseVertex.color.getColor();
103+
float2 uv = input.coarseVertex.uv;
104+
output.fragment.color = float4(color, 1.0);
105+
outputBuffer[0] = 1.0;
106+
return output;
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3F800000

0 commit comments

Comments
 (0)