Skip to content

Commit a50de6b

Browse files
aleino-nvslangbotcsyonghe
authored
Implement semantics for WGSL (shader-slang#5589)
* Implement semantics for WGSL This helps to address issue shader-slang#4943. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
1 parent f98579d commit a50de6b

File tree

1 file changed

+115
-11
lines changed

1 file changed

+115
-11
lines changed

source/slang/slang-ir-wgsl-legalize.cpp

+115-11
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,54 @@ struct LegalizeWGSLEntryPointContext
206206

207207
switch (result.wgslSystemValueNameEnum)
208208
{
209-
case SystemValueSemanticName::Position:
209+
210+
case SystemValueSemanticName::CullDistance:
210211
{
211-
result.wgslSystemValueName = toSlice("position");
212-
result.permittedTypes.add(builder.getVectorType(
213-
builder.getBasicType(BaseType::Float),
214-
builder.getIntValue(builder.getIntType(), 4)));
215-
break;
212+
result.isUnsupported = true;
213+
}
214+
break;
215+
216+
case SystemValueSemanticName::ClipDistance:
217+
{
218+
// TODO: Implement this based on the 'clip-distances' feature in WGSL
219+
// https: // www.w3.org/TR/webgpu/#dom-gpufeaturename-clip-distances
220+
result.isUnsupported = true;
221+
}
222+
break;
223+
224+
case SystemValueSemanticName::Coverage:
225+
{
226+
result.wgslSystemValueName = toSlice("sample_mask");
227+
result.permittedTypes.add(builder.getUIntType());
228+
}
229+
break;
230+
231+
case SystemValueSemanticName::Depth:
232+
{
233+
result.wgslSystemValueName = toSlice("frag_depth");
234+
result.permittedTypes.add(builder.getBasicType(BaseType::Float));
235+
}
236+
break;
237+
238+
case SystemValueSemanticName::DepthGreaterEqual:
239+
case SystemValueSemanticName::DepthLessEqual:
240+
{
241+
result.isUnsupported = true;
216242
}
243+
break;
217244

218245
case SystemValueSemanticName::DispatchThreadID:
219246
{
220247
result.wgslSystemValueName = toSlice("global_invocation_id");
221-
IRType* const vec3uType{builder.getVectorType(
248+
result.permittedTypes.add(builder.getVectorType(
222249
builder.getBasicType(BaseType::UInt),
223-
builder.getIntValue(builder.getIntType(), 3))};
224-
result.permittedTypes.add(vec3uType);
250+
builder.getIntValue(builder.getIntType(), 3)));
251+
}
252+
break;
253+
254+
case SystemValueSemanticName::DomainLocation:
255+
{
256+
result.isUnsupported = true;
225257
}
226258
break;
227259

@@ -234,6 +266,13 @@ struct LegalizeWGSLEntryPointContext
234266
}
235267
break;
236268

269+
case SystemValueSemanticName::GroupIndex:
270+
{
271+
result.wgslSystemValueName = toSlice("local_invocation_index");
272+
result.permittedTypes.add(builder.getUIntType());
273+
}
274+
break;
275+
237276
case SystemValueSemanticName::GroupThreadID:
238277
{
239278
result.wgslSystemValueName = toSlice("local_invocation_id");
@@ -250,13 +289,78 @@ struct LegalizeWGSLEntryPointContext
250289
}
251290
break;
252291

253-
case SystemValueSemanticName::GroupIndex:
292+
case SystemValueSemanticName::InnerCoverage:
254293
{
255-
result.wgslSystemValueName = toSlice("local_invocation_index");
294+
result.isUnsupported = true;
295+
}
296+
break;
297+
298+
case SystemValueSemanticName::InstanceID:
299+
{
300+
result.wgslSystemValueName = toSlice("instance_index");
256301
result.permittedTypes.add(builder.getUIntType());
257302
}
258303
break;
259304

305+
case SystemValueSemanticName::IsFrontFace:
306+
{
307+
result.wgslSystemValueName = toSlice("front_facing");
308+
result.permittedTypes.add(builder.getBoolType());
309+
}
310+
break;
311+
312+
case SystemValueSemanticName::OutputControlPointID:
313+
case SystemValueSemanticName::PointSize:
314+
{
315+
result.isUnsupported = true;
316+
}
317+
break;
318+
319+
case SystemValueSemanticName::Position:
320+
{
321+
result.wgslSystemValueName = toSlice("position");
322+
result.permittedTypes.add(builder.getVectorType(
323+
builder.getBasicType(BaseType::Float),
324+
builder.getIntValue(builder.getIntType(), 4)));
325+
break;
326+
}
327+
328+
case SystemValueSemanticName::PrimitiveID:
329+
case SystemValueSemanticName::RenderTargetArrayIndex:
330+
{
331+
result.isUnsupported = true;
332+
break;
333+
}
334+
335+
case SystemValueSemanticName::SampleIndex:
336+
{
337+
result.wgslSystemValueName = toSlice("sample_index");
338+
result.permittedTypes.add(builder.getUIntType());
339+
break;
340+
}
341+
342+
case SystemValueSemanticName::StencilRef:
343+
case SystemValueSemanticName::Target:
344+
case SystemValueSemanticName::TessFactor:
345+
{
346+
result.isUnsupported = true;
347+
break;
348+
}
349+
350+
case SystemValueSemanticName::VertexID:
351+
{
352+
result.wgslSystemValueName = toSlice("vertex_index");
353+
result.permittedTypes.add(builder.getUIntType());
354+
break;
355+
}
356+
357+
case SystemValueSemanticName::ViewID:
358+
case SystemValueSemanticName::ViewportArrayIndex:
359+
{
360+
result.isUnsupported = true;
361+
break;
362+
}
363+
260364
default:
261365
{
262366
m_sink->diagnose(

0 commit comments

Comments
 (0)