From 83675103a1a4fefde11b314aed26f4d37860efe7 Mon Sep 17 00:00:00 2001 From: davli-nv Date: Tue, 5 Aug 2025 10:55:52 -0700 Subject: Implement SPV_EXT_fragment_invocation_density (SPV_NV_shading_rate) (#8037) * Implement SPV_EXT_fragment_invocation_density -Adds semantics SV_FragSize and SV_FragInvocationCount and implements them for SPIRV and GLSL using the appropriate target builtins from extensions. -Adds test case checking for expected target builtins from these semantics. -For future work, could implement SV_FragSize using pixel shader input SV_ShadingRate for HLSL, and SV_FragInvocationCount needs research. Fixes #7974 Generated with Claude Code * address review feedback https://github.com/shader-slang/slang/pull/8037#pullrequestreview-3084645845 * fixup format * review feedback https://github.com/shader-slang/slang/pull/8037#pullrequestreview-3086442819 --- docs/user-guide/a2-01-spirv-target-specific.md | 4 +++- docs/user-guide/a2-02-metal-target-specific.md | 2 ++ docs/user-guide/a2-03-wgsl-target-specific.md | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user-guide/a2-01-spirv-target-specific.md b/docs/user-guide/a2-01-spirv-target-specific.md index 05bf023df..0f64a5e1b 100644 --- a/docs/user-guide/a2-01-spirv-target-specific.md +++ b/docs/user-guide/a2-01-spirv-target-specific.md @@ -67,6 +67,8 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_DomainLocation` | `BuiltIn TessCoord` | | `SV_DrawIndex`* | `Builtin DrawIndex` | | `SV_DeviceIndex` | `Builtin DeviceIndex` | +| `SV_FragInvocationCount` | `Builtin FragInvocationCountExt` | +| `SV_FragSize` | `Builtin FragSizeExt` | | `SV_GSInstanceID` | `BuiltIn InvocationId` | | `SV_GroupID` | `BuiltIn WorkgroupId` | | `SV_GroupIndex` | `BuiltIn LocalInvocationIndex` | @@ -95,7 +97,7 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_VulkanInstanceID` | `BuiltIn InstanceIndex` | | `SV_VulkanVertexID` | `BuiltIn VertexIndex` | -*Note* that `SV_DrawIndex`, `SV_PointSize` and `SV_PointCoord` are Slang-specific semantics that are not defined in HLSL. +*Note* that `SV_DrawIndex`, `SV_FragInvocationCount`, `SV_FragSize`, `SV_PointSize` and `SV_PointCoord` are Slang-specific semantics that are not defined in HLSL. Also *Note* that `SV_InstanceID`/`SV_VertexID` counts all instances/vertices in a draw call, unlike how `InstanceIndex`/`VertexIndex` is relative to `BaseInstance`/`BaseVertex`. See [Using SV_InstanceID/SV_VertexID with SPIR-V target](#using-sv_instanceid-and-sv_vertexid-with-spir-v-target) diff --git a/docs/user-guide/a2-02-metal-target-specific.md b/docs/user-guide/a2-02-metal-target-specific.md index c0360efda..5d3e336db 100644 --- a/docs/user-guide/a2-02-metal-target-specific.md +++ b/docs/user-guide/a2-02-metal-target-specific.md @@ -29,6 +29,8 @@ The system-value semantics are translated to the following Metal attributes: | `SV_DepthGreaterEqual` | `[[depth(greater)]]` | | `SV_DepthLessEqual` | `[[depth(less)]]` | | `SV_DispatchThreadID` | `[[thread_position_in_grid]]` | +| `SV_FragInvocationCount` | `(Not supported)` | +| `SV_FragSize` | `(Not supported)` | | `SV_GroupID` | `[[threadgroup_position_in_grid]]` | | `SV_GroupThreadID` | `[[thread_position_in_threadgroup]]` | | `SV_GroupIndex` | Calculated from `SV_GroupThreadID` and group extents | diff --git a/docs/user-guide/a2-03-wgsl-target-specific.md b/docs/user-guide/a2-03-wgsl-target-specific.md index e8a918dc8..35aecd291 100644 --- a/docs/user-guide/a2-03-wgsl-target-specific.md +++ b/docs/user-guide/a2-03-wgsl-target-specific.md @@ -26,6 +26,8 @@ The system-value semantics are translated to the following WGSL code. | SV_DepthLessEqual | *Not supported* | | SV_DispatchThreadID | `@builtin(global_invocation_id)` | | SV_DomainLocation | *Not supported* | +| SV_FragInvocationCount | *Not supported* | +| SV_FragSize | *Not supported* | | SV_GSInstanceID | *Not supported* | | SV_GroupID | `@builtin(workgroup_id)` | | SV_GroupIndex | `@builtin(local_invocation_index)` | -- cgit v1.2.3