diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index d426b955f2..e6e93fbac3 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -37,7 +37,9 @@ line upon naming the release. Refer to previous for appropriate section names. - `dx::IsDebuggerPresent()` returns true if a debugger is attached. - SPIR-V: `DebugBreak()` emits `NonSemantic.DebugBreak` extended instruction; `IsDebuggerPresent()` is not supported. -#### Other Changes +#### Bug Fixes + +- Fixed non-deterministic DXIL/PDB output when compiling shaders with resource arrays, debug info, and SM 6.6+. [#8171](https://github.com/microsoft/DirectXShaderCompiler/issues/8171) - Fixed mesh shader semantics that were incorrectly case sensitive. ### Version 1.9.2602 diff --git a/lib/HLSL/DxilPromoteResourcePasses.cpp b/lib/HLSL/DxilPromoteResourcePasses.cpp index 9ba6e3cb3d..afbd566298 100644 --- a/lib/HLSL/DxilPromoteResourcePasses.cpp +++ b/lib/HLSL/DxilPromoteResourcePasses.cpp @@ -16,6 +16,7 @@ #include "dxc/HLSL/DxilGenerationPass.h" #include "dxc/HLSL/HLModule.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SetVector.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/DebugInfo.h" @@ -313,7 +314,7 @@ class DxilMutateResourceToHandle : public ModulePass { hlsl::OP *hlslOP = nullptr; Function *createHandleForLibOnHandle = nullptr; DxilTypeSystem *pTypeSys; - DenseSet MutateValSet; + SetVector MutateValSet; DenseMap MutateTypeMap; }; @@ -613,7 +614,7 @@ void DxilMutateResourceToHandle::collectCandidates(Module &M) { for (Value *Val : newCandidates) { // New candidate find. - if (MutateValSet.insert(Val).second) { + if (MutateValSet.insert(Val)) { WorkList.emplace_back(Val); } } diff --git a/tools/clang/test/DXC/deterministic_output_resource_array.hlsl b/tools/clang/test/DXC/deterministic_output_resource_array.hlsl new file mode 100644 index 0000000000..335260fbf7 --- /dev/null +++ b/tools/clang/test/DXC/deterministic_output_resource_array.hlsl @@ -0,0 +1,23 @@ +// Test that compiling a shader with resource arrays produces deterministic output. +// This is a regression test for https://github.com/microsoft/DirectXShaderCompiler/issues/8171 +// where compiling the same shader multiple times with -Zi and SM 6.6+ produced +// non-identical disassembly due to non-deterministic handle name suffixes. + +// RUN: %dxc -T cs_6_6 -E CSMain -Zi -Fc %t1 %s +// RUN: %dxc -T cs_6_6 -E CSMain -Zi -Fc %t2 %s +// RUN: diff %t1 %t2 + +Texture2D inMaps[16]; +RWTexture2D Output; + +[numthreads(1,1,1)] +void CSMain(uint3 threadID : SV_DispatchThreadID) +{ + Output[threadID.xy] = inMaps[0][threadID.xy]; + Output[threadID.xy] = inMaps[1][threadID.xy]; + Output[threadID.xy] = inMaps[2][threadID.xy]; + Output[threadID.xy] = inMaps[3][threadID.xy]; + Output[threadID.xy] = inMaps[4][threadID.xy]; + Output[threadID.xy] = inMaps[5][threadID.xy]; + Output[threadID.xy] = inMaps[6][threadID.xy]; +}