From 634e3960c2bc322bbd51fccc7ff395d9f24e35dc Mon Sep 17 00:00:00 2001 From: Darren Wihandi <65404740+fairywreath@users.noreply.github.com> Date: Mon, 19 May 2025 14:21:25 -0400 Subject: Map `SV_VertexID` to `gl_VertexIndex-gl_BaseVertex`, add `SV_Vulkan*ID` semantics (#7150) * Map SV_VertexID to `gl_VertexIndex - gl_BaseVertex`, provide SV_Vulkan* SV semantics * Fix docs * Regenerate toc * Fix affected pointer-2 test * Add tests --------- Co-authored-by: Yong He --- docs/user-guide/a2-01-spirv-target-specific.md | 19 ++++++++++++------- docs/user-guide/a2-02-metal-target-specific.md | 2 ++ docs/user-guide/a2-03-wgsl-target-specific.md | 4 +++- docs/user-guide/toc.html | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) (limited to 'docs/user-guide') diff --git a/docs/user-guide/a2-01-spirv-target-specific.md b/docs/user-guide/a2-01-spirv-target-specific.md index 1ab143cb0..dee19cd28 100644 --- a/docs/user-guide/a2-01-spirv-target-specific.md +++ b/docs/user-guide/a2-01-spirv-target-specific.md @@ -72,7 +72,7 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_GroupThreadID` | `BuiltIn LocalInvocationId` | | `SV_InnerCoverage` | `BuiltIn FullyCoveredEXT` | | `SV_InsideTessFactor` | `BuiltIn TessLevelInner` | -| `SV_InstanceID`** | `BuiltIn InstanceIndex` | +| `SV_InstanceID`** | `BuiltIn InstanceIndex` - `Builtin BaseInstance` | | `SV_IntersectionAttributes` | *Not supported* | | `SV_IsFrontFace` | `BuiltIn FrontFacing` | | `SV_OutputControlPointID` | `BuiltIn InvocationId` | @@ -88,20 +88,25 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_StencilRef` | `BuiltIn FragStencilRefEXT` | | `SV_Target` | `Location` | | `SV_TessFactor` | `BuiltIn TessLevelOuter` | -| `SV_VertexID` | `BuiltIn VertexIndex` | +| `SV_VertexID`** | `BuiltIn VertexIndex` - `Builtin BaseVertex` | | `SV_ViewID` | `BuiltIn ViewIndex` | | `SV_ViewportArrayIndex` | `BuiltIn ViewportIndex` | +| `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. -Also *Note* that `SV_InstanceID` counts all instances in a draw call, unlike how `InstanceIndex` is relative to `BaseInstance`. See [Using SV_InstanceID with SPIR-V target](#using-sv_instanceid-with-spir-v-target) +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) -Using SV_InstanceID with SPIR-V target +Using SV_InstanceID and SV_VertexID with SPIR-V target -------------------------------------- -When using `SV_InstanceID` with SPIR-V target, it is equivalent to the difference between the `InstanceIndex` and `BaseInstance` builtins. -This matches the behavior of D3D where `SV_InstanceID` starts from zero for each draw call, while in SPIR-V, `InstanceIndex` includes the base instance. +When using `SV_InstanceID` and `SV_VertexID` with SPIR-V target, it is equivalent to the difference between the index and base builtins. +This matches the behavior of D3D where `SV_InstanceID` and `SV_VertexID` starts from zero for each draw call, while in SPIR-V, +`InstanceIndex` and `VertexIndex` includes the base instance. -If you need direct access to the `InstanceIndex` value, you can use parameters with `SV_InstanceID` and `SV_StartInstanceLocation` semantics: +If you need direct access to `InstanceIndex` and `VertexIndex` values, use `SV_VulkanInstanceID` and `SV_VulkanVertexID` semantic names. These are supported for all targets except HLSL. +Alternatively you can use parameters with `SV_InstanceID`(or `SV_VertexID`) and `SV_StartInstanceLocation`(or `SV_StartVertexLocation`) semantics: ```slang void myVertexShader( diff --git a/docs/user-guide/a2-02-metal-target-specific.md b/docs/user-guide/a2-02-metal-target-specific.md index 8d69a5975..c0360efda 100644 --- a/docs/user-guide/a2-02-metal-target-specific.md +++ b/docs/user-guide/a2-02-metal-target-specific.md @@ -44,6 +44,8 @@ The system-value semantics are translated to the following Metal attributes: | `SV_ViewportArrayIndex` | `[[viewport_array_index]]` | | `SV_StartVertexLocation` | `[[base_vertex]]` | | `SV_StartInstanceLocation` | `[[base_instance]]` | +| `SV_VulkanInstanceID` | `[[instance_id]]` | +| `SV_VulkanVertexID` | `[[vertex_id]]` | Custom semantics are mapped to user attributes: diff --git a/docs/user-guide/a2-03-wgsl-target-specific.md b/docs/user-guide/a2-03-wgsl-target-specific.md index cf28d4b49..e8a918dc8 100644 --- a/docs/user-guide/a2-03-wgsl-target-specific.md +++ b/docs/user-guide/a2-03-wgsl-target-specific.md @@ -50,6 +50,8 @@ The system-value semantics are translated to the following WGSL code. | SV_VertexID | `@builtin(vertex_index)` | | SV_ViewID | *Not supported* | | SV_ViewportArrayIndex | *Not supported* | +| SV_VulkanInstanceID | `@builtin(instance_index)` | +| SV_VulkanVertexID | `@builtin(vertex_index)` | Supported HLSL features when targeting WGSL @@ -179,4 +181,4 @@ Translates to: ```wgsl @id(7) override a : i32 = 2; -``` \ No newline at end of file +``` diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html index ace7da1d0..47e0c05ad 100644 --- a/docs/user-guide/toc.html +++ b/docs/user-guide/toc.html @@ -195,7 +195,7 @@
  • Memory model
  • Combined texture sampler
  • System-Value semantics
  • -
  • Using SV_InstanceID with SPIR-V target
  • +
  • Using SV_InstanceID and SV_VertexID with SPIR-V target
  • Behavior of `discard` after SPIR-V 1.6
  • Supported HLSL features when targeting SPIR-V
  • Unsupported GLSL keywords when targeting SPIR-V
  • -- cgit v1.2.3