Skip to content

Commit abead0b

Browse files
authored
Merge branch 'microsoft:main' into issue-6615
2 parents a5db248 + c763461 commit abead0b

133 files changed

Lines changed: 5241 additions & 506 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/ReleaseNotes.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ line upon naming the release. Refer to previous for appropriate section names.
3838

3939
#### Bug Fixes
4040

41-
- 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)
41+
- Fixed non-deterministic DXIL/PDB output when compiling shaders with resource
42+
arrays, debug info, and SM 6.6+.
43+
[#8171](https://github.com/microsoft/DirectXShaderCompiler/issues/8171)
4244
- Fixed mesh shader semantics that were incorrectly case sensitive.
45+
- User-defined conversion operators (e.g., `operator float4()`) now produce an
46+
error instead of being silently ignored.
47+
[#5103](https://github.com/microsoft/DirectXShaderCompiler/pull/8206)
4348
- DXIL validation: added validation for `CreateHandleFromBinding`.
44-
- DXIL validation now rejects non-standard integer bit widths (e.g. `i25`) in instructions.
49+
- DXIL validation now rejects non-standard integer bit widths (e.g. `i25`) in
50+
instructions.
4551

4652
#### Other Changes
4753

external/SPIRV-Headers

include/dxc/DxilPIXPasses/DxilPIXPasses.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ModulePass *createDxilShaderAccessTrackingPass();
2828
ModulePass *createDxilPIXAddTidToAmplificationShaderPayloadPass();
2929
ModulePass *createDxilPIXDXRInvocationsLogPass();
3030
ModulePass *createDxilNonUniformResourceIndexInstrumentationPass();
31+
ModulePass *createDxilDebugBreakInstrumentationPass();
3132

3233
void initializeDxilAddPixelHitInstrumentationPass(llvm::PassRegistry &);
3334
void initializeDxilDbgValueToDbgDeclarePass(llvm::PassRegistry &);
@@ -44,5 +45,6 @@ void initializeDxilPIXAddTidToAmplificationShaderPayloadPass(
4445
void initializeDxilPIXDXRInvocationsLogPass(llvm::PassRegistry &);
4546
void initializeDxilNonUniformResourceIndexInstrumentationPass(
4647
llvm::PassRegistry &);
48+
void initializeDxilDebugBreakInstrumentationPass(llvm::PassRegistry &);
4749

4850
} // namespace llvm

include/dxc/Test/HlslTestUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
#include "dxc/Test/TestConfig.h"
4848
#endif
4949

50-
using namespace std;
50+
using std::max;
51+
using std::min;
5152

5253
#ifndef HLSLDATAFILEPARAM
5354
#define HLSLDATAFILEPARAM L"HlslDataDir"
@@ -121,12 +122,12 @@ static constexpr wchar_t wideWhitespaceChars[] = L" \t\r\n";
121122

122123
inline std::string strltrim(const std::string &value) {
123124
size_t first = value.find_first_not_of(whitespaceChars);
124-
return first == string::npos ? value : value.substr(first);
125+
return first == std::string::npos ? value : value.substr(first);
125126
}
126127

127128
inline std::string strrtrim(const std::string &value) {
128129
size_t last = value.find_last_not_of(whitespaceChars);
129-
return last == string::npos ? value : value.substr(0, last + 1);
130+
return last == std::string::npos ? value : value.substr(0, last + 1);
130131
}
131132

132133
inline std::string strtrim(const std::string &value) {

include/dxc/dxcapi.internal.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ enum LEGAL_INTRINSIC_COMPTYPES {
140140

141141
#ifdef ENABLE_SPIRV_CODEGEN
142142
LICOMPTYPE_VK_BUFFER_POINTER = 56,
143-
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 57,
144-
LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY = 58,
145-
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS = 59,
146-
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY = 60,
147-
LICOMPTYPE_COUNT = 61
143+
LICOMPTYPE_VK_SAMPLED_TEXTURE1D = 57,
144+
LICOMPTYPE_VK_SAMPLED_TEXTURE1D_ARRAY = 58,
145+
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 59,
146+
LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY = 60,
147+
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS = 61,
148+
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY = 62,
149+
LICOMPTYPE_VK_SAMPLED_TEXTURE3D = 63,
150+
LICOMPTYPE_VK_SAMPLED_TEXTURECUBE = 64,
151+
LICOMPTYPE_VK_SAMPLED_TEXTURECUBE_ARRAY = 65,
152+
LICOMPTYPE_COUNT = 66
148153
#else
149154
LICOMPTYPE_COUNT = 56
150155
#endif

lib/DXIL/DxilOperations.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,8 +2838,8 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
28382838
"linAlgFillMatrix",
28392839
Attribute::None,
28402840
2,
2841-
{{0x200}, {0x63}},
2842-
{{0x0}, {0x0}}}, // Overloads: o,hfwi
2841+
{{0x200}, {0xe7}},
2842+
{{0x0}, {0x0}}}, // Overloads: o,hfdwil
28432843
{OC::LinAlgCopyConvertMatrix,
28442844
"LinAlgCopyConvertMatrix",
28452845
OCC::LinAlgCopyConvertMatrix,
@@ -2862,8 +2862,8 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
28622862
"linAlgMatrixLoadFromMemory",
28632863
Attribute::None,
28642864
2,
2865-
{{0x200}, {0x63}},
2866-
{{0x0}, {0x0}}}, // Overloads: o,hfwi
2865+
{{0x200}, {0xe7}},
2866+
{{0x0}, {0x0}}}, // Overloads: o,hfdwil
28672867
{OC::LinAlgMatrixLength,
28682868
"LinAlgMatrixLength",
28692869
OCC::LinAlgMatrixLength,
@@ -2886,16 +2886,16 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
28862886
"linAlgMatrixGetElement",
28872887
Attribute::None,
28882888
2,
2889-
{{0x63}, {0x200}},
2890-
{{0x0}, {0x0}}}, // Overloads: hfwi,o
2889+
{{0xe7}, {0x200}},
2890+
{{0x0}, {0x0}}}, // Overloads: hfdwil,o
28912891
{OC::LinAlgMatrixSetElement,
28922892
"LinAlgMatrixSetElement",
28932893
OCC::LinAlgMatrixSetElement,
28942894
"linAlgMatrixSetElement",
28952895
Attribute::None,
28962896
3,
2897-
{{0x200}, {0x200}, {0x63}},
2898-
{{0x0}, {0x0}, {0x0}}}, // Overloads: o,o,hfwi
2897+
{{0x200}, {0x200}, {0xe7}},
2898+
{{0x0}, {0x0}, {0x0}}}, // Overloads: o,o,hfdwil
28992899
{OC::LinAlgMatrixStoreToDescriptor,
29002900
"LinAlgMatrixStoreToDescriptor",
29012901
OCC::LinAlgMatrixStoreToDescriptor,
@@ -2910,8 +2910,8 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
29102910
"linAlgMatrixStoreToMemory",
29112911
Attribute::None,
29122912
2,
2913-
{{0x200}, {0x63}},
2914-
{{0x0}, {0x0}}}, // Overloads: o,hfwi
2913+
{{0x200}, {0xe7}},
2914+
{{0x0}, {0x0}}}, // Overloads: o,hfdwil
29152915
{OC::LinAlgMatrixQueryAccumulatorLayout,
29162916
"LinAlgMatrixQueryAccumulatorLayout",
29172917
OCC::LinAlgMatrixQueryAccumulatorLayout,
@@ -2943,15 +2943,15 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
29432943
Attribute::None,
29442944
3,
29452945
{{0x400}, {0x200}, {0x400}},
2946-
{{0x63}, {0x0}, {0x63}}}, // Overloads: <hfwi,o,<hfwi
2946+
{{0xe7}, {0x0}, {0xe7}}}, // Overloads: <hfdwil,o,<hfdwil
29472947
{OC::LinAlgMatVecMulAdd,
29482948
"LinAlgMatVecMulAdd",
29492949
OCC::LinAlgMatVecMulAdd,
29502950
"linAlgMatVecMulAdd",
29512951
Attribute::None,
29522952
4,
29532953
{{0x400}, {0x200}, {0x400}, {0x400}},
2954-
{{0x63}, {0x0}, {0x63}, {0x63}}}, // Overloads: <hfwi,o,<hfwi,<hfwi
2954+
{{0xe7}, {0x0}, {0xe7}, {0xe7}}}, // Overloads: <hfdwil,o,<hfdwil,<hfdwil
29552955
{OC::LinAlgMatrixAccumulateToDescriptor,
29562956
"LinAlgMatrixAccumulateToDescriptor",
29572957
OCC::LinAlgMatrixAccumulateToDescriptor,
@@ -2966,24 +2966,24 @@ static const OP::OpCodeProperty ExperimentalOps_OpCodeProps[] = {
29662966
"linAlgMatrixAccumulateToMemory",
29672967
Attribute::None,
29682968
2,
2969-
{{0x200}, {0x63}},
2970-
{{0x0}, {0x0}}}, // Overloads: o,hfwi
2969+
{{0x200}, {0xe7}},
2970+
{{0x0}, {0x0}}}, // Overloads: o,hfdwil
29712971
{OC::LinAlgMatrixOuterProduct,
29722972
"LinAlgMatrixOuterProduct",
29732973
OCC::LinAlgMatrixOuterProduct,
29742974
"linAlgMatrixOuterProduct",
29752975
Attribute::None,
29762976
3,
29772977
{{0x200}, {0x400}, {0x400}},
2978-
{{0x0}, {0x63}, {0x63}}}, // Overloads: o,<hfwi,<hfwi
2978+
{{0x0}, {0xe7}, {0xe7}}}, // Overloads: o,<hfdwil,<hfdwil
29792979
{OC::LinAlgConvert,
29802980
"LinAlgConvert",
29812981
OCC::LinAlgConvert,
29822982
"linAlgConvert",
29832983
Attribute::None,
29842984
2,
29852985
{{0x400}, {0x400}},
2986-
{{0x63}, {0x63}}}, // Overloads: <hfwi,<hfwi
2986+
{{0xe7}, {0xe7}}}, // Overloads: <hfdwil,<hfdwil
29872987

29882988
{OC::ReservedE0,
29892989
"ReservedE0",

lib/DxilPIXPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_llvm_library(LLVMDxilPIXPasses
2121
DxilPIXAddTidToAmplificationShaderPayload.cpp
2222
DxilPIXDXRInvocationsLog.cpp
2323
DxilNonUniformResourceIndexInstrumentation.cpp
24+
DxilDebugBreakInstrumentation.cpp
2425

2526
ADDITIONAL_HEADER_DIRS
2627
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// DxilDebugBreakInstrumentation.cpp //
4+
// Copyright (C) Microsoft Corporation. All rights reserved. //
5+
// This file is distributed under the University of Illinois Open Source //
6+
// License. See LICENSE.TXT for details. //
7+
// //
8+
// Provides a pass to instrument DebugBreak() calls for PIX. Each //
9+
// DebugBreak call is replaced with a UAV bit-write so PIX can detect //
10+
// which DebugBreak locations were hit without halting the GPU. //
11+
// //
12+
///////////////////////////////////////////////////////////////////////////////
13+
14+
#include "PixPassHelpers.h"
15+
#include "dxc/DXIL/DxilOperations.h"
16+
#include "dxc/DxilPIXPasses/DxilPIXPasses.h"
17+
#include "dxc/DxilPIXPasses/DxilPIXVirtualRegisters.h"
18+
#include "dxc/Support/Global.h"
19+
#include "llvm/IR/Module.h"
20+
#include "llvm/Support/FormattedStream.h"
21+
22+
using namespace llvm;
23+
using namespace hlsl;
24+
25+
class DxilDebugBreakInstrumentation : public ModulePass {
26+
27+
public:
28+
static char ID; // Pass identification, replacement for typeid
29+
explicit DxilDebugBreakInstrumentation() : ModulePass(ID) {}
30+
StringRef getPassName() const override {
31+
return "DXIL DebugBreak Instrumentation";
32+
}
33+
bool runOnModule(Module &M) override;
34+
};
35+
36+
bool DxilDebugBreakInstrumentation::runOnModule(Module &M) {
37+
DxilModule &DM = M.GetOrCreateDxilModule();
38+
LLVMContext &Ctx = M.getContext();
39+
OP *HlslOP = DM.GetOP();
40+
41+
hlsl::DxilResource *PixUAVResource = nullptr;
42+
43+
UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(Ctx));
44+
45+
// Atomic operation to use for writing to the result UAV resource
46+
Function *AtomicOpFunc =
47+
HlslOP->GetOpFunc(OP::OpCode::AtomicBinOp, Type::getInt32Ty(Ctx));
48+
Constant *AtomicBinOpcode =
49+
HlslOP->GetU32Const((uint32_t)OP::OpCode::AtomicBinOp);
50+
Constant *AtomicOr = HlslOP->GetU32Const((uint32_t)DXIL::AtomicBinOpCode::Or);
51+
52+
std::map<Function *, CallInst *> FunctionToUAVHandle;
53+
54+
// Collect all DebugBreak calls first, then modify.
55+
// This avoids invalidating iterators during modification.
56+
std::vector<CallInst *> DebugBreakCalls;
57+
58+
Function *DebugBreakFunc =
59+
HlslOP->GetOpFunc(OP::OpCode::DebugBreak, Type::getVoidTy(Ctx));
60+
for (const Use &U : DebugBreakFunc->uses()) {
61+
DebugBreakCalls.push_back(cast<CallInst>(U.getUser()));
62+
}
63+
64+
for (CallInst *CI : DebugBreakCalls) {
65+
if (!PixUAVResource)
66+
PixUAVResource =
67+
PIXPassHelpers::CreateGlobalUAVResource(DM, 0, "PixUAVResource");
68+
69+
Function *F = CI->getParent()->getParent();
70+
71+
CallInst *PixUAVHandle = nullptr;
72+
const auto FunctionToUAVHandleIter = FunctionToUAVHandle.lower_bound(F);
73+
74+
if ((FunctionToUAVHandleIter != FunctionToUAVHandle.end()) &&
75+
(FunctionToUAVHandleIter->first == F)) {
76+
PixUAVHandle = FunctionToUAVHandleIter->second;
77+
} else {
78+
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt());
79+
80+
PixUAVHandle = PIXPassHelpers::CreateHandleForResource(
81+
DM, Builder, PixUAVResource, "PixUAVHandle");
82+
83+
FunctionToUAVHandle.insert(FunctionToUAVHandleIter, {F, PixUAVHandle});
84+
}
85+
86+
IRBuilder<> Builder(CI);
87+
88+
uint32_t InstructionNumber = 0;
89+
if (!pix_dxil::PixDxilInstNum::FromInst(CI, &InstructionNumber)) {
90+
DXASSERT(false, "Failed to extract PIX instruction number metadata from "
91+
"DebugBreak call");
92+
}
93+
94+
// The output UAV is treated as a bit array where each bit corresponds
95+
// to an instruction number.
96+
const uint32_t InstructionNumByteOffset =
97+
(InstructionNumber / 32u) * sizeof(uint32_t);
98+
const uint32_t InstructionNumBitPosition = (InstructionNumber % 32u);
99+
const uint32_t InstructionNumBitMask = 1u << InstructionNumBitPosition;
100+
101+
Constant *UAVByteOffsetArg = HlslOP->GetU32Const(InstructionNumByteOffset);
102+
Constant *BitMaskArg = HlslOP->GetU32Const(InstructionNumBitMask);
103+
104+
// Write a 1 bit at the position corresponding to this DebugBreak's
105+
// instruction number, indicating it was hit.
106+
Builder.CreateCall(
107+
AtomicOpFunc,
108+
{
109+
AtomicBinOpcode, // i32, ; opcode
110+
PixUAVHandle, // %dx.types.Handle, ; resource handle
111+
AtomicOr, // i32, ; binary operation code
112+
UAVByteOffsetArg, // i32, ; coordinate c0: byte offset
113+
UndefArg, // i32, ; coordinate c1 (unused)
114+
UndefArg, // i32, ; coordinate c2 (unused)
115+
BitMaskArg // i32); value
116+
},
117+
"DebugBreakBitSet");
118+
119+
// Remove the original DebugBreak call to prevent GPU halt
120+
CI->eraseFromParent();
121+
}
122+
123+
// Clean up the now-unused declaration. Not strictly required for
124+
// correctness, but keeps the module free of dead references.
125+
if (DebugBreakFunc->use_empty())
126+
DebugBreakFunc->eraseFromParent();
127+
128+
const bool modified = (PixUAVResource != nullptr);
129+
130+
if (modified) {
131+
DM.ReEmitDxilResources();
132+
133+
if (OSOverride != nullptr) {
134+
formatted_raw_ostream FOS(*OSOverride);
135+
FOS << "\nFoundDebugBreak\n";
136+
}
137+
}
138+
139+
return modified;
140+
}
141+
142+
char DxilDebugBreakInstrumentation::ID = 0;
143+
144+
ModulePass *llvm::createDxilDebugBreakInstrumentationPass() {
145+
return new DxilDebugBreakInstrumentation();
146+
}
147+
148+
INITIALIZE_PASS(DxilDebugBreakInstrumentation,
149+
"hlsl-dxil-debugbreak-instrumentation",
150+
"HLSL DXIL DebugBreak instrumentation for PIX", false, false)

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7551,6 +7551,8 @@ def err_hlsl_matrix_member_zero_in_one_based: Error<
75517551
"the digit '0' is used in '%0', but the syntax is for one-based rows and columns">;
75527552
def err_hlsl_overloading_operator_disallowed: Error<
75537553
"overloading %select{|non-member }1%0 is not allowed">;
7554+
def err_hlsl_unsupported_conversion_operator: Error<
7555+
"conversion operator overloading is not allowed">;
75547556
def err_hlsl_vector_member_bad_format: Error<
75557557
"invalid format for vector swizzle '%0'">;
75567558
def err_hlsl_vector_member_empty: Error<

0 commit comments

Comments
 (0)