summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2024-11-19 19:07:54 +0200
committerGitHub <noreply@github.com>2024-11-19 09:07:54 -0800
commita50de6bd32de1b064874480a2528fc994597f7ac (patch)
tree405ac54f325213060e2d9e16163d0b756e9bf8ca /source
parentf98579d5ea3a69dd0ed75eeacc017fabfc7cb8e0 (diff)
Implement semantics for WGSL (#5589)
* Implement semantics for WGSL This helps to address issue #4943. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-wgsl-legalize.cpp126
1 files changed, 115 insertions, 11 deletions
diff --git a/source/slang/slang-ir-wgsl-legalize.cpp b/source/slang/slang-ir-wgsl-legalize.cpp
index b990ad12f..adb027668 100644
--- a/source/slang/slang-ir-wgsl-legalize.cpp
+++ b/source/slang/slang-ir-wgsl-legalize.cpp
@@ -206,22 +206,54 @@ struct LegalizeWGSLEntryPointContext
switch (result.wgslSystemValueNameEnum)
{
- case SystemValueSemanticName::Position:
+
+ case SystemValueSemanticName::CullDistance:
{
- result.wgslSystemValueName = toSlice("position");
- result.permittedTypes.add(builder.getVectorType(
- builder.getBasicType(BaseType::Float),
- builder.getIntValue(builder.getIntType(), 4)));
- break;
+ result.isUnsupported = true;
+ }
+ break;
+
+ case SystemValueSemanticName::ClipDistance:
+ {
+ // TODO: Implement this based on the 'clip-distances' feature in WGSL
+ // https: // www.w3.org/TR/webgpu/#dom-gpufeaturename-clip-distances
+ result.isUnsupported = true;
+ }
+ break;
+
+ case SystemValueSemanticName::Coverage:
+ {
+ result.wgslSystemValueName = toSlice("sample_mask");
+ result.permittedTypes.add(builder.getUIntType());
+ }
+ break;
+
+ case SystemValueSemanticName::Depth:
+ {
+ result.wgslSystemValueName = toSlice("frag_depth");
+ result.permittedTypes.add(builder.getBasicType(BaseType::Float));
+ }
+ break;
+
+ case SystemValueSemanticName::DepthGreaterEqual:
+ case SystemValueSemanticName::DepthLessEqual:
+ {
+ result.isUnsupported = true;
}
+ break;
case SystemValueSemanticName::DispatchThreadID:
{
result.wgslSystemValueName = toSlice("global_invocation_id");
- IRType* const vec3uType{builder.getVectorType(
+ result.permittedTypes.add(builder.getVectorType(
builder.getBasicType(BaseType::UInt),
- builder.getIntValue(builder.getIntType(), 3))};
- result.permittedTypes.add(vec3uType);
+ builder.getIntValue(builder.getIntType(), 3)));
+ }
+ break;
+
+ case SystemValueSemanticName::DomainLocation:
+ {
+ result.isUnsupported = true;
}
break;
@@ -234,6 +266,13 @@ struct LegalizeWGSLEntryPointContext
}
break;
+ case SystemValueSemanticName::GroupIndex:
+ {
+ result.wgslSystemValueName = toSlice("local_invocation_index");
+ result.permittedTypes.add(builder.getUIntType());
+ }
+ break;
+
case SystemValueSemanticName::GroupThreadID:
{
result.wgslSystemValueName = toSlice("local_invocation_id");
@@ -250,13 +289,78 @@ struct LegalizeWGSLEntryPointContext
}
break;
- case SystemValueSemanticName::GroupIndex:
+ case SystemValueSemanticName::InnerCoverage:
{
- result.wgslSystemValueName = toSlice("local_invocation_index");
+ result.isUnsupported = true;
+ }
+ break;
+
+ case SystemValueSemanticName::InstanceID:
+ {
+ result.wgslSystemValueName = toSlice("instance_index");
result.permittedTypes.add(builder.getUIntType());
}
break;
+ case SystemValueSemanticName::IsFrontFace:
+ {
+ result.wgslSystemValueName = toSlice("front_facing");
+ result.permittedTypes.add(builder.getBoolType());
+ }
+ break;
+
+ case SystemValueSemanticName::OutputControlPointID:
+ case SystemValueSemanticName::PointSize:
+ {
+ result.isUnsupported = true;
+ }
+ break;
+
+ case SystemValueSemanticName::Position:
+ {
+ result.wgslSystemValueName = toSlice("position");
+ result.permittedTypes.add(builder.getVectorType(
+ builder.getBasicType(BaseType::Float),
+ builder.getIntValue(builder.getIntType(), 4)));
+ break;
+ }
+
+ case SystemValueSemanticName::PrimitiveID:
+ case SystemValueSemanticName::RenderTargetArrayIndex:
+ {
+ result.isUnsupported = true;
+ break;
+ }
+
+ case SystemValueSemanticName::SampleIndex:
+ {
+ result.wgslSystemValueName = toSlice("sample_index");
+ result.permittedTypes.add(builder.getUIntType());
+ break;
+ }
+
+ case SystemValueSemanticName::StencilRef:
+ case SystemValueSemanticName::Target:
+ case SystemValueSemanticName::TessFactor:
+ {
+ result.isUnsupported = true;
+ break;
+ }
+
+ case SystemValueSemanticName::VertexID:
+ {
+ result.wgslSystemValueName = toSlice("vertex_index");
+ result.permittedTypes.add(builder.getUIntType());
+ break;
+ }
+
+ case SystemValueSemanticName::ViewID:
+ case SystemValueSemanticName::ViewportArrayIndex:
+ {
+ result.isUnsupported = true;
+ break;
+ }
+
default:
{
m_sink->diagnose(