Skip to content

Commit 0c7753e

Browse files
authored
[0039] Flesh out the SPIRV and DXIL lowering (#608)
This adds the remaining details for the HLSL, DXIL and SPIRV implementations of the debugbreak feature.
1 parent a779ffb commit 0c7753e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

proposals/0039-debugbreak.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,68 @@ void main(uint GI : SV_GroupIndex) {
6060
6161
This aligns with C/C++ conventions that our users are already familiar with.
6262
63+
## Detailed Design
64+
65+
This proposal introduces a new HLSL `DebugBreak` intrinsic which has a
66+
runtime-defined behavior to facilitate shader debugging workflows. If the
67+
runtime does not support or is not configured to enable support for the
68+
corresponding DXIL instruction, it must be treated as a no-op by the driver.
69+
70+
### HLSL Surface
71+
72+
A new `DebugBreak` function is added with the signature:
73+
74+
```
75+
void DebugBreak();
76+
```
77+
78+
A new header `assert.h` is added and included with the compiler packaging which
79+
implements the `assert` macro:
80+
81+
```c
82+
#if NDEBUG
83+
#define assert(cond) do { } while(false)
84+
#else
85+
#define assert(cond) do { if (!cond) DebugBreak();} while(false)
86+
#endif
87+
```
88+
89+
### DXIL Lowering
90+
91+
This change introduces a new DXIL operation:
92+
93+
94+
``` llvm
95+
declare void @dx.op.debugBreak(
96+
immarg i32 ; opcode
97+
)
98+
```
99+
100+
This DXIL operation must be treated as `convergent` even though it is not to
101+
prevent code motion. It should also not be marked `readonly` or `readnone` even
102+
though it technically doesn't read memory.
103+
104+
This instruction will only be valid in a new shader model.
105+
106+
Because it is valid to treat this operation as a no-op, it is a required
107+
supported feature and does not require a capabilities bit.
108+
109+
### SPIRV Lowering
110+
111+
This change will utilize the existing `NonSemantic.DebugBreak` instruction.
112+
While this instruction is not widely supported by Vulkan debuggers, it is
113+
supported by NVIDIA's NSight and can be safely ignored by Vulkan runtimes.
114+
115+
The SPIRV usage will utilize the following instructions:
116+
117+
```
118+
%1 = OpExtInstImport "NonSemantic.DebugBreak"
119+
%2 = OpExtInst %void %1 DebugBreak
120+
```
121+
122+
## Open Questions
123+
124+
* Consider introducing the `convergent` attribute to DXIL.
125+
* This should be "cheap" and would potentially address pre-existing bugs.
126+
* This would preserve the requirement that this operation not be moved during
127+
optimization in the final DXIL.

0 commit comments

Comments
 (0)