diff --git a/docs/DXIL.rst b/docs/DXIL.rst index 94e153d664..90354539a7 100644 --- a/docs/DXIL.rst +++ b/docs/DXIL.rst @@ -3289,7 +3289,7 @@ SM.HSINPUTCONTROLPOINTCOUNTRANGE HS input control p SM.HULLPASSTHRUCONTROLPOINTCOUNTMATCH For pass thru hull shader, input control point count must match output control point count SM.INCOMPATIBLECALLINENTRY Features used in internal function calls must be compatible with entry SM.INCOMPATIBLEDERIVINCOMPUTESHADERMODEL Derivatives in compute-model shaders require shader model 6.6 and above -SM.INCOMPATIBLEDERIVLAUNCH Node shaders only support derivatives in broadcasting launch mode +SM.INCOMPATIBLEDERIVLAUNCH Node shaders only support derivatives in broadcasting and coalescing launch modes SM.INCOMPATIBLEOPERATION Operations used in entry function must be compatible with shader stage and other properties SM.INCOMPATIBLEREQUIRESGROUP Functions requiring groupshared memory must be called from shaders with a visible group SM.INCOMPATIBLESHADERMODEL Functions may only use features available in the current shader model diff --git a/lib/DxilValidation/DxilValidation.cpp b/lib/DxilValidation/DxilValidation.cpp index 2ea6701581..1dea357507 100644 --- a/lib/DxilValidation/DxilValidation.cpp +++ b/lib/DxilValidation/DxilValidation.cpp @@ -5449,12 +5449,11 @@ struct CompatibilityChecker { MaskForDeriv |= static_cast(ConflictFlags::DerivInComputeShaderModel); } else if (ShaderKind == DXIL::ShaderKind::Node) { - // Only broadcasting launch supports derivatives. - if (Props.Node.LaunchType != DXIL::NodeLaunchType::Broadcasting) - MaskForDeriv |= static_cast(ConflictFlags::DerivLaunch); - // Thread launch node has no group. - if (Props.Node.LaunchType == DXIL::NodeLaunchType::Thread) + // Thread launch node has no group and doesn't support derivatives. + if (Props.Node.LaunchType == DXIL::NodeLaunchType::Thread) { MaskForGroup |= static_cast(ConflictFlags::RequiresGroup); + MaskForDeriv |= static_cast(ConflictFlags::DerivLaunch); + } } if (ShaderKind == DXIL::ShaderKind::Mesh || diff --git a/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/derivatives_in_csmsas.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/derivatives_in_csmsas.hlsl index 4b66f309a2..81973e47d7 100644 --- a/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/derivatives_in_csmsas.hlsl +++ b/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/derivatives_in_csmsas.hlsl @@ -1,6 +1,8 @@ // RUN: %dxc -DSTAGE=1 -T cs_6_6 %s | FileCheck %s // RUN: %dxc -DSTAGE=2 -T as_6_6 %s | FileCheck %s -check-prefixes=CHECK,ASMSCHECK // RUN: %dxc -DSTAGE=3 -T ms_6_6 %s | FileCheck %s -check-prefixes=CHECK,ASMSCHECK +// RUN: %dxc -DSTAGE=4 -T lib_6_8 %s | FileCheck %s +// RUN: %dxc -DSTAGE=5 -T lib_6_8 %s | FileCheck %s // RUN: %dxilver 1.6 | %dxc -DSTAGE=1 -T cs_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK // RUN: %dxilver 1.6 | %dxc -DSTAGE=2 -T as_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK // RUN: %dxilver 1.6 | %dxc -DSTAGE=3 -T ms_6_5 -Wno-hlsl-availability %s | FileCheck %s -check-prefix=ERRCHECK @@ -8,6 +10,8 @@ #define CS 1 #define AS 2 #define MS 3 +#define BNS 4 +#define CNS 5 // Test 6.6 feature allowing derivative operations in compute shaders @@ -20,13 +24,26 @@ SamplerState samp : register(s5); SamplerComparisonState cmpSamp : register(s6); float cmpVal; + +struct NodeRecord { + uint w, h; +}; + + [numthreads( 8, 8, 1 )] #if STAGE==MS [outputtopology("triangle")] +#elif STAGE==BNS +[Shader("node")] +[NodeLaunch("broadcasting")] +[NodeDispatchGrid(1, 1, 1)] +#elif STAGE==CNS +[Shader("node")] +[NodeLaunch("coalescing")] #endif -void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID ) -{ - float2 uv = DTid.xy/float2(8, 8); +void main( uint GI : SV_GroupIndex, uint2 GTid : SV_GroupThreadID + ) { + float2 uv = GTid.xy/float2(8, 8); float4 res = 0; uint status = 0; @@ -100,8 +117,8 @@ void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID ) // ERRCHECK: error: opcode 'Derivatives in CS/MS/AS' should only be used in 'Shader Model 6.6+' res += input.SampleCmp(cmpSamp, uv, cmpVal); res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-3, 4)); - res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-4, 6), DTid.z); - res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-5, 7), DTid.z, status); + res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-4, 6), GI); + res += input.SampleCmp(cmpSamp, uv, cmpVal, uint2(-5, 7), GI, status); res *= status; #if STAGE == AS diff --git a/tools/clang/test/HLSLFileCheck/validation/callgraph/deriv-in-nested-fn-node-lib68-launch.ll b/tools/clang/test/HLSLFileCheck/validation/callgraph/deriv-in-nested-fn-node-lib68-launch.ll index d1bc222151..0a40645f62 100644 --- a/tools/clang/test/HLSLFileCheck/validation/callgraph/deriv-in-nested-fn-node-lib68-launch.ll +++ b/tools/clang/test/HLSLFileCheck/validation/callgraph/deriv-in-nested-fn-node-lib68-launch.ll @@ -3,7 +3,7 @@ ; Sample called from node shader is not allowed with thread launch. ; CHECK: Function: main: error: Entry function calls one or more functions using incompatible features. See other errors for details. -; CHECK: Function: {{.*}}fn_sample{{.*}}: error: Function called from Thread launch node shader uses derivatives; only broadcasting launch supports derivatives. +; CHECK: Function: {{.*}}fn_sample{{.*}}: error: Function called from Thread launch node shader uses derivatives; only broadcasting and coalescing launch modes support derivatives. ; 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. 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" diff --git a/utils/hct/hctdb.py b/utils/hct/hctdb.py index 5d86d1a3e9..8d8e3d9c49 100644 --- a/utils/hct/hctdb.py +++ b/utils/hct/hctdb.py @@ -8962,8 +8962,8 @@ def build_valrules(self): ) self.add_valrule_msg( "Sm.IncompatibleDerivLaunch", - "Node shaders only support derivatives in broadcasting launch mode", - "Function called from %0 launch node shader uses derivatives; only broadcasting launch supports derivatives.", + "Node shaders only support derivatives in broadcasting and coalescing launch modes", + "Function called from %0 launch node shader uses derivatives; only broadcasting and coalescing launch modes support derivatives.", ) # Assign sensible category names and build up an enumeration description