Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/command-line-slangc-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ A capability describes an optional feature that a target may or may not support.
* `SPV_KHR_quad_control` : enables the SPV_KHR_quad_control extension
* `SPV_KHR_fragment_shader_barycentric` : enables the SPV_KHR_fragment_shader_barycentric extension
* `SPV_KHR_non_semantic_info` : enables the SPV_KHR_non_semantic_info extension
* `SPV_KHR_device_group` : enables the SPV_KHR_device_group extension
* `SPV_KHR_ray_tracing` : enables the SPV_KHR_ray_tracing extension
* `SPV_KHR_ray_query` : enables the SPV_KHR_ray_query extension
* `SPV_KHR_ray_tracing_position_fetch` : enables the SPV_KHR_ray_tracing_position_fetch extension
Expand All @@ -1152,6 +1153,7 @@ A capability describes an optional feature that a target may or may not support.
* `SPV_KHR_cooperative_matrix` : enables the SPV_KHR_cooperative_matrix extension
* `SPV_NV_tensor_addressing` : enables the SPV_NV_tensor_addressing extension
* `SPV_NV_cooperative_matrix2` : enables the SPV_NV_cooperative_matrix2 extension
* `spvDeviceGroup`
* `spvAtomicFloat32AddEXT`
* `spvAtomicFloat16AddEXT`
* `spvAtomicFloat64AddEXT`
Expand Down Expand Up @@ -1254,6 +1256,7 @@ A capability describes an optional feature that a target may or may not support.
* `GL_EXT_demote_to_helper_invocation` : enables the GL_EXT_demote_to_helper_invocation extension
* `GL_EXT_maximal_reconvergence` : enables the GL_EXT_maximal_reconvergence extension
* `GL_EXT_shader_quad_control` : enables the GL_EXT_shader_quad_control extension
* `GL_EXT_device_group` : enables the GL_EXT_device_group extension
* `GL_EXT_fragment_shader_barycentric` : enables the GL_EXT_fragment_shader_barycentric extension
* `GL_EXT_mesh_shader` : enables the GL_EXT_mesh_shader extension
* `GL_EXT_nonuniform_qualifier` : enables the GL_EXT_nonuniform_qualifier extension
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/a2-01-spirv-target-specific.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The system-value semantics are translated to the following SPIR-V code.
| `SV_DispatchThreadID` | `BuiltIn GlobalInvocationId` |
| `SV_DomainLocation` | `BuiltIn TessCoord` |
| `SV_DrawIndex`<sup>*</sup> | `Builtin DrawIndex` |
| `SV_DeviceIndex` | `Builtin DeviceIndex` |
| `SV_GSInstanceID` | `BuiltIn InvocationId` |
| `SV_GroupID` | `BuiltIn WorkgroupId` |
| `SV_GroupIndex` | `BuiltIn LocalInvocationIndex` |
Expand Down
9 changes: 9 additions & 0 deletions docs/user-guide/a3-02-reference-capability-atoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ Extensions
`SPV_KHR_non_semantic_info`
> Represents the SPIR-V extension for non-semantic information.

`SPV_KHR_device_group`
> Represents the SPIR-V extension for device-group information.

`SPV_KHR_ray_tracing`
> Represents the SPIR-V extension for ray tracing.

Expand Down Expand Up @@ -465,6 +468,9 @@ Extensions
`SPV_NV_cooperative_matrix2`
> Represents the SPIR-V extension for SPV_NV_cooperative_matrix2.

`spvDeviceGroup`
> Represents the SPIR-V capability for DeviceGroup.

`spvAtomicFloat32AddEXT`
> Represents the SPIR-V capability for atomic float 32 add operations.

Expand Down Expand Up @@ -636,6 +642,9 @@ Extensions
`GL_EXT_shader_quad_control`
> Represents the GL_EXT_shader_quad_control extension.

`GL_EXT_device_group`
> Represents the GL_EXT_device_group extension.

`GL_EXT_fragment_shader_barycentric`
> Represents the GL_EXT_fragment_shader_barycentric extension.

Expand Down
13 changes: 12 additions & 1 deletion source/slang/glsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
13 changes: 13 additions & 0 deletions source/slang/slang-capabilities.capdef
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-ir-glsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-ir-legalize-varying-params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-language-server-completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static const char* hlslSemanticNames[] = {
"SV_PointCoord",
"SV_PrimitiveID",
"SV_DrawIndex",
"SV_DeviceIndex",
"SV_RenderTargetArrayIndex",
"SV_SampleIndex",
"SV_StencilRef",
Expand Down
16 changes: 16 additions & 0 deletions tests/spirv/device-index-glsl-syntax.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry main -stage fragment -allow-glsl
//TEST:SIMPLE(filecheck=GLSL): -target glsl -entry main -stage fragment -allow-glsl

// SPIRV: OpDecorate %{{.*}} BuiltIn DeviceIndex
// GLSL: gl_DeviceIndex

struct PSIn
{
float3 color;
}

[shader("fragment")]
float4 main(PSIn pin)
{
return float4(pin.color, (float)gl_DeviceIndex);
}
17 changes: 17 additions & 0 deletions tests/spirv/device-index-hlsl-syntax.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry main
//TEST:SIMPLE(filecheck=GLSL): -target glsl -entry main

// SPIRV: OpDecorate %{{.*}} BuiltIn DeviceIndex
// GLSL: gl_DeviceIndex

struct PSIn
{
float3 color;
int deviceIndex : SV_DeviceIndex;
}

[shader("fragment")]
float4 main(PSIn pin)
{
return float4(pin.color, (float)pin.deviceIndex);
}
Loading