diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2025-06-28 21:15:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-29 04:15:48 +0000 |
| commit | 67af8c718ce5e3f95a25e5188840f63b41a33ecc (patch) | |
| tree | bf5d1c7309e136223f1c62a5ec7d215274445b0c /source/slang | |
| parent | 7349dc5cff49cf22c82eb912813e47f30cd7a757 (diff) | |
Support the GLSL/SPIR-V Built-in variable `DeviceIndex` (#7552)
* Support DeviceIndex
* format code
* regenerate command line reference
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/glsl.meta.slang | 13 | ||||
| -rw-r--r-- | source/slang/slang-capabilities.capdef | 13 | ||||
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir-glsl-legalize.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir-legalize-varying-params.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-language-server-completion.cpp | 1 |
6 files changed, 39 insertions, 1 deletions
diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 9b0a28a31..b3323a327 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -127,8 +127,19 @@ public in uvec3 gl_WorkGroupID : SV_GroupID; public in uint gl_LocalInvocationIndex : SV_GroupIndex; public in uvec3 gl_LocalInvocationID : SV_GroupThreadID; -public property uint3 gl_NumWorkGroups { +internal in int _gl_DeviceIndex : SV_DeviceIndex; +public property int gl_DeviceIndex +{ + [__unsafeForceInlineEarly] + [require(glsl_spirv, GL_EXT_device_group)] + get + { + return _gl_DeviceIndex; + } +} +public property uint3 gl_NumWorkGroups +{ [require(glsl_spirv, GLSL_430_SPIRV_1_0_compute)] get { diff --git a/source/slang/slang-capabilities.capdef b/source/slang/slang-capabilities.capdef index 312777340..941ad7ebf 100644 --- a/source/slang/slang-capabilities.capdef +++ b/source/slang/slang-capabilities.capdef @@ -511,6 +511,10 @@ def SPV_KHR_fragment_shader_barycentric : _spirv_1_0; /// [EXT] def SPV_KHR_non_semantic_info : _spirv_1_0; +/// Represents the SPIR-V extension for device-group information. +/// [EXT] +def SPV_KHR_device_group : _spirv_1_0; + /// Represents the SPIR-V extension for ray tracing. /// [EXT] def SPV_KHR_ray_tracing : _spirv_1_4; @@ -596,6 +600,10 @@ def SPV_NV_cooperative_matrix2 : SPV_NV_tensor_addressing + SPV_KHR_cooperative_ // SPIRV Capabilities. +/// Represents the SPIR-V capability for DeviceGroup. +/// [EXT] +def spvDeviceGroup : SPV_KHR_device_group; + /// Represents the SPIR-V capability for atomic float 32 add operations. /// [EXT] def spvAtomicFloat32AddEXT : SPV_EXT_shader_atomic_float_add; @@ -840,6 +848,7 @@ def _GL_EXT_texture_query_lod : glsl; def _GL_EXT_texture_shadow_lod : _GLSL_130; def _GL_EXT_maximal_reconvergence : _GLSL_140; def _GL_EXT_shader_quad_control : _GLSL_140; +def _GL_EXT_device_group : _GLSL_140; def _GL_ARB_derivative_control : _GLSL_400; def _GL_ARB_fragment_shader_interlock : _GLSL_450; @@ -905,6 +914,10 @@ alias GL_EXT_maximal_reconvergence = _GL_EXT_maximal_reconvergence | spvMaximalR /// [EXT] alias GL_EXT_shader_quad_control = _GL_EXT_shader_quad_control | spvQuadControlKHR; +/// Represents the GL_EXT_device_group extension. +/// [EXT] +alias GL_EXT_device_group = _GL_EXT_device_group | spvDeviceGroup; + /// Represents the GL_EXT_fragment_shader_barycentric extension. /// [EXT] alias GL_EXT_fragment_shader_barycentric = _GL_EXT_fragment_shader_barycentric | spvFragmentBarycentricKHR; diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 82fb39d7d..0a3eb2bf1 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -6023,6 +6023,12 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex requireSPIRVCapability(SpvCapabilityDrawParameters); return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInDrawIndex, inst); } + else if (semanticName == "sv_deviceindex") + { + ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_device_group")); + requireSPIRVCapability(SpvCapabilityDeviceGroup); + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInDeviceIndex, inst); + } else if (semanticName == "sv_primitiveid") { auto entryPoints = m_referencingEntryPoints.tryGetValue(inst); diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index 3cf547c17..1a34a9877 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -666,6 +666,12 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( name = "gl_DrawID"; requiredType = builder->getBasicType(BaseType::Int); } + else if (semanticName == "sv_deviceindex") + { + name = "gl_DeviceIndex"; + requiredType = builder->getBasicType(BaseType::Int); + context->requireGLSLExtension(UnownedStringSlice::fromLiteral("GL_EXT_device_group")); + } else if (semanticName == "sv_primitiveid") { // uint in hlsl, int in glsl diff --git a/source/slang/slang-ir-legalize-varying-params.h b/source/slang/slang-ir-legalize-varying-params.h index 233acaf94..fcb4b8b81 100644 --- a/source/slang/slang-ir-legalize-varying-params.h +++ b/source/slang/slang-ir-legalize-varying-params.h @@ -59,6 +59,7 @@ void depointerizeInputParams(IRFunc* entryPoint); M(PointCoord, SV_PointCoord) \ M(PrimitiveID, SV_PrimitiveID) \ M(DrawIndex, SV_DrawIndex) \ + M(DeviceIndex, SV_DeviceIndex) \ M(RenderTargetArrayIndex, SV_RenderTargetArrayIndex) \ M(SampleIndex, SV_SampleIndex) \ M(StencilRef, SV_StencilRef) \ diff --git a/source/slang/slang-language-server-completion.cpp b/source/slang/slang-language-server-completion.cpp index 59aa3e4d8..9a88fbaa7 100644 --- a/source/slang/slang-language-server-completion.cpp +++ b/source/slang/slang-language-server-completion.cpp @@ -121,6 +121,7 @@ static const char* hlslSemanticNames[] = { "SV_PointCoord", "SV_PrimitiveID", "SV_DrawIndex", + "SV_DeviceIndex", "SV_RenderTargetArrayIndex", "SV_SampleIndex", "SV_StencilRef", |
