forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_entries2.hlsl
More file actions
197 lines (157 loc) · 4.62 KB
/
lib_entries2.hlsl
File metadata and controls
197 lines (157 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// RUN: %dxc -T lib_6_1 %s | FileCheck %s
// Make sure entry function exist.
// CHECK: @cs_main()
// Make sure signatures are lowered.
// CHECK: dx.op.threadId
// CHECK: dx.op.groupId
// Make sure entry function exist.
// CHECK: @gs_main()
// Make sure signatures are lowered.
// CHECK: dx.op.loadInput
// CHECK: dx.op.storeOutput
// CHECK: dx.op.emitStream
// CHECK: dx.op.cutStream
// Make sure entry function exist.
// CHECK: @ds_main()
// Make sure signatures are lowered.
// CHECK: dx.op.loadPatchConstant
// CHECK: dx.op.domainLocation
// CHECK: dx.op.loadInput
// CHECK: dx.op.storeOutput
// Make sure patch constant function exist.
// CHECK: HSPerPatchFunc
// Make sure signatures are lowered.
// CHECK: dx.op.storePatchConstant
// Make sure entry function exist.
// CHECK: @hs_main()
// Make sure signatures are lowered.
// CHECK: dx.op.outputControlPointID
// CHECK: dx.op.loadInput
// CHECK: dx.op.storeOutput
// Make sure entry function exist.
// CHECK: @vs_main()
// Make sure signatures are lowered.
// CHECK: dx.op.loadInput
// CHECK: dx.op.storeOutput
// Make sure entry function exist.
// CHECK: @ps_main()
// Make sure signatures are lowered.
// CHECK: dx.op.loadInput
// CHECK: dx.op.storeOutput
// Finish ps_main
// CHECK: ret void
// Make sure cloned function signatures are not lowered.
// CHECK-NOT: call float @dx.op.loadInput
// CHECK-NOT: call void @dx.op.storeOutput
// Make sure cloned function exist.
// CHECK: @"\01?ps_main
// Make sure function entrys exist.
// CHECK: dx.func.signatures
// Make sure cs don't have signature.
// CHECK: @cs_main, null
void StoreCSOutput(uint2 tid, uint2 gid);
[shader("cs_6_1")]
[numthreads(8,8,1)]
void cs_main( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
{
StoreCSOutput(tid, gid);
}
// GS
struct GSOut {
float2 uv : TEXCOORD0;
float4 pos : SV_Position;
};
// geometry shader that outputs 3 vertices from a point
[shader("gs_6_1")]
[maxvertexcount(3)]
[instance(24)]
void gs_main(InputPatch<GSOut, 2>points, inout PointStream<GSOut> stream) {
stream.Append(points[0]);
stream.RestartStrip();
}
// DS
struct PSSceneIn {
float4 pos : SV_Position;
float2 tex : TEXCOORD0;
float3 norm : NORMAL;
uint RTIndex : SV_RenderTargetArrayIndex;
};
struct HSPerVertexData {
// This is just the original vertex verbatim. In many real life cases this would be a
// control point instead
PSSceneIn v;
};
struct HSPerPatchData {
// We at least have to specify tess factors per patch
// As we're tesselating triangles, there will be 4 tess factors
// In real life case this might contain face normal, for example
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
// domain shader that actually outputs the triangle vertices
[shader("ds_6_1")]
[domain("tri")] PSSceneIn ds_main(const float3 bary
: SV_DomainLocation,
const OutputPatch<HSPerVertexData, 3> patch,
const HSPerPatchData perPatchData) {
PSSceneIn v;
// Compute interpolated coordinates
v.pos = patch[0].v.pos * bary.x + patch[1].v.pos * bary.y + patch[2].v.pos * bary.z + perPatchData.edges[1];
v.tex = patch[0].v.tex * bary.x + patch[1].v.tex * bary.y + patch[2].v.tex * bary.z + perPatchData.edges[0];
v.norm = patch[0].v.norm * bary.x + patch[1].v.norm * bary.y + patch[2].v.norm * bary.z + perPatchData.inside;
v.RTIndex = 0;
return v;
}
// HS
HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, OutputPatch<HSPerVertexData, 3> outp)
{
HSPerPatchData d;
d.edges[ 0 ] = 1;
d.edges[ 1 ] = 1;
d.edges[ 2 ] = 1;
d.inside = 1;
return d;
}
// hull per-control point shader
[shader("hs_6_1")]
[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[patchconstantfunc("HSPerPatchFunc")]
[outputcontrolpoints(3)]
HSPerVertexData hs_main( const uint id : SV_OutputControlPointID,
const InputPatch< PSSceneIn, 3 > points)
{
HSPerVertexData v;
// Just forward the vertex
v.v = points[ id ];
return v;
}
// VS
struct VS_INPUT
{
float3 vPosition : POSITION;
float3 vNormal : NORMAL;
float2 vTexcoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float3 vNormal : NORMAL;
float2 vTexcoord : TEXCOORD0;
float4 vPosition : SV_POSITION;
};
[shader("vs_6_1")]
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.vPosition = float4( Input.vPosition, 1.0 );
Output.vNormal = Input.vNormal;
Output.vTexcoord = Input.vTexcoord;
return Output;
}
// PS
[shader("ps_6_1")]
float4 ps_main(float4 a : A) : SV_TARGET
{
return a;
}