Skip to content

Commit 08ae29a

Browse files
authored
Allow derivatives in coalescing nodes (#7942)
Per the spec ( https://github.com/microsoft/DirectX-Specs/blob/master/d3d/WorkGraphs.md#quad-and-derivative-operation-semantics ) derivatives are allowed in all but thread launch nodes, but the validator disallowed them in coalescing nodes. This changes the validator to allow derivatives in coalescind nodes and adds testing for derivatives in coalescing and broadcast nodes. Fixes #7723
1 parent ba86cc0 commit 08ae29a

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

docs/DXIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,7 @@ SM.HSINPUTCONTROLPOINTCOUNTRANGE HS input control p
33043304
SM.HULLPASSTHRUCONTROLPOINTCOUNTMATCH For pass thru hull shader, input control point count must match output control point count
33053305
SM.INCOMPATIBLECALLINENTRY Features used in internal function calls must be compatible with entry
33063306
SM.INCOMPATIBLEDERIVINCOMPUTESHADERMODEL Derivatives in compute-model shaders require shader model 6.6 and above
3307-
SM.INCOMPATIBLEDERIVLAUNCH Node shaders only support derivatives in broadcasting launch mode
3307+
SM.INCOMPATIBLEDERIVLAUNCH Node shaders only support derivatives in broadcasting and coalescing launch modes
33083308
SM.INCOMPATIBLEOPERATION Operations used in entry function must be compatible with shader stage and other properties
33093309
SM.INCOMPATIBLEREQUIRESGROUP Functions requiring groupshared memory must be called from shaders with a visible group
33103310
SM.INCOMPATIBLESHADERMODEL Functions may only use features available in the current shader model

lib/DxilValidation/DxilValidation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,12 +5463,11 @@ struct CompatibilityChecker {
54635463
MaskForDeriv |=
54645464
static_cast<uint32_t>(ConflictFlags::DerivInComputeShaderModel);
54655465
} else if (ShaderKind == DXIL::ShaderKind::Node) {
5466-
// Only broadcasting launch supports derivatives.
5467-
if (Props.Node.LaunchType != DXIL::NodeLaunchType::Broadcasting)
5468-
MaskForDeriv |= static_cast<uint32_t>(ConflictFlags::DerivLaunch);
5469-
// Thread launch node has no group.
5470-
if (Props.Node.LaunchType == DXIL::NodeLaunchType::Thread)
5466+
// Thread launch node has no group and doesn't support derivatives.
5467+
if (Props.Node.LaunchType == DXIL::NodeLaunchType::Thread) {
54715468
MaskForGroup |= static_cast<uint32_t>(ConflictFlags::RequiresGroup);
5469+
MaskForDeriv |= static_cast<uint32_t>(ConflictFlags::DerivLaunch);
5470+
}
54725471
}
54735472

54745473
if (ShaderKind == DXIL::ShaderKind::Mesh ||

tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/derivatives_in_csmsas.hlsl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// RUN: %dxc -DSTAGE=1 -T cs_6_6 %s | FileCheck %s
22
// RUN: %dxc -DSTAGE=2 -T as_6_6 %s | FileCheck %s -check-prefixes=CHECK,ASMSCHECK
33
// RUN: %dxc -DSTAGE=3 -T ms_6_6 %s | FileCheck %s -check-prefixes=CHECK,ASMSCHECK
4+
// RUN: %dxc -DSTAGE=4 -T lib_6_8 %s | FileCheck %s
5+
// RUN: %dxc -DSTAGE=5 -T lib_6_8 %s | FileCheck %s
46
// RUN: %dxilver 1.6 | %dxc -DSTAGE=1 -T cs_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK
57
// RUN: %dxilver 1.6 | %dxc -DSTAGE=2 -T as_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK
68
// RUN: %dxilver 1.6 | %dxc -DSTAGE=3 -T ms_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK
79

810
#define CS 1
911
#define AS 2
1012
#define MS 3
13+
#define BNS 4
14+
#define CNS 5
1115

1216
// Test 6.6 feature allowing derivative operations in compute shaders
1317

@@ -20,13 +24,26 @@ SamplerState samp : register(s5);
2024
SamplerComparisonState cmpSamp : register(s6);
2125
float cmpVal;
2226

27+
28+
struct NodeRecord {
29+
uint w, h;
30+
};
31+
32+
2333
[numthreads( 8, 8, 1 )]
2434
#if STAGE==MS
2535
[outputtopology("triangle")]
36+
#elif STAGE==BNS
37+
[Shader("node")]
38+
[NodeLaunch("broadcasting")]
39+
[NodeDispatchGrid(1, 1, 1)]
40+
#elif STAGE==CNS
41+
[Shader("node")]
42+
[NodeLaunch("coalescing")]
2643
#endif
27-
void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID )
28-
{
29-
float2 uv = DTid.xy/float2(8, 8);
44+
void main( uint GI : SV_GroupIndex, uint2 GTid : SV_GroupThreadID
45+
) {
46+
float2 uv = GTid.xy/float2(8, 8);
3047
float4 res = 0;
3148
uint status = 0;
3249

@@ -100,8 +117,8 @@ void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID )
100117
// ERRCHECK: error: opcode 'Derivatives in CS/MS/AS' should only be used in 'Shader Model 6.6+'
101118
res += input.SampleCmp(cmpSamp, uv, cmpVal);
102119
res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-3, 4));
103-
res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-4, 6), DTid.z);
104-
res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-5, 7), DTid.z, status);
120+
res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-4, 6), GI);
121+
res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-5, 7), GI, status);
105122
res *= status;
106123

107124
#if STAGE == AS

tools/clang/test/HLSLFileCheck/validation/callgraph/deriv-in-nested-fn-node-lib68-launch.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; Sample called from node shader is not allowed with thread launch.
44

55
; CHECK: Function: main: error: Entry function calls one or more functions using incompatible features. See other errors for details.
6-
; CHECK: Function: {{.*}}fn_sample{{.*}}: error: Function called from Thread launch node shader uses derivatives; only broadcasting launch supports derivatives.
6+
; CHECK: Function: {{.*}}fn_sample{{.*}}: error: Function called from Thread launch node shader uses derivatives; only broadcasting and coalescing launch modes support derivatives.
77
; CHECK: Function: {{.*}}fn_sample{{.*}}: error: Function uses derivatives in compute-model shader with NumThreads (1, 1, 1); derivatives require NumThreads to be 1D and a multiple of 4, or 2D/3D with X and Y both being a multiple of 2.
88

99
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"

utils/hct/hctdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8668,8 +8668,8 @@ def build_valrules(self):
86688668
)
86698669
self.add_valrule_msg(
86708670
"Sm.IncompatibleDerivLaunch",
8671-
"Node shaders only support derivatives in broadcasting launch mode",
8672-
"Function called from %0 launch node shader uses derivatives; only broadcasting launch supports derivatives.",
8671+
"Node shaders only support derivatives in broadcasting and coalescing launch modes",
8672+
"Function called from %0 launch node shader uses derivatives; only broadcasting and coalescing launch modes support derivatives.",
86738673
)
86748674

86758675
# Assign sensible category names and build up an enumeration description

0 commit comments

Comments
 (0)