Skip to content

Commit

Permalink
Implement semantics for WGSL (#5589)
Browse files Browse the repository at this point in the history
* Implement semantics for WGSL

This helps to address issue #4943.

* format code

---------

Co-authored-by: slangbot <[email protected]>
Co-authored-by: Yong He <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent f98579d commit a50de6b
Showing 1 changed file with 115 additions and 11 deletions.
126 changes: 115 additions & 11 deletions source/slang/slang-ir-wgsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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(
Expand Down

0 comments on commit a50de6b

Please sign in to comment.