Skip to content

Conversation

@JoeCitizen
Copy link
Collaborator

Add DebugBreak() and dx::IsDebuggerPresent() intrinsics for shader debugging

Description

This PR adds two new intrinsics for shader debugging in experimental Shader Model 6.10:

  • DebugBreak() - Triggers a breakpoint if a debugger is attached
  • dx::IsDebuggerPresent() - Returns true if a debugger is attached

Changes

HLSL Intrinsic Definitions:

  • Added DebugBreak() to the base Intrinsics namespace in gen_intrin_main.txt
  • Added IsDebuggerPresent() to the DxIntrinsics namespace
  • Both require minimum shader model 6.10

DXIL Operations:

  • Added DebugBreak and IsDebuggerPresent DXIL opcodes in hctdb.py
  • DebugBreak: void return, no overload
  • IsDebuggerPresent: i1 (bool) return, no overload

Code Generation:

  • Added HLSL to DXIL lowering in HLOperationLower.cpp
  • Added LICOMPTYPE_BOOL handling in SemaHLSL.cpp for dx:: namespace intrinsic type resolution

SPIR-V Support:

  • DebugBreak() emits NonSemantic.DebugBreak extended instruction
  • Added SPV_KHR_non_semantic_info extension enablement in CapabilityVisitor.cpp
  • dx::IsDebuggerPresent() produces an error (no Vulkan equivalent)

Tests:

  • debugbreak.hlsl - DXIL codegen test
  • debugbreak_sm69_error.hlsl - Shader model version error test
  • isdebugerpresent.hlsl - DXIL codegen test
  • intrinsics.debugbreak.hlsl - SPIR-V codegen test
  • intrinsics.isdebugerpresent.error.hlsl - SPIR-V unsupported error test

Related

https://github.com/microsoft/hlsl-specs/blob/main/proposals/0039-debugbreak.md

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

✅ With the latest revision this PR passed the Python code formatter.

break;
case hlsl::IntrinsicOp::IOP_DebugBreak:
retVal = spvBuilder.createNonSemanticDebugBreakExtInst(srcLoc);
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ordering of the cases arbitrary?

Copy link
Contributor

@tex3d tex3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In intrinsic tests, we should add run lines and checks for -fcgl and -ast-dump. We also need lowering tests (dxilgen pass).

As pointed out in another comment, the opcodes should be in the IR checks, and updated when we move the ops to release. We should include the full arg list in those CHECKs (to verify all expected arguments - just the opcode in this case).

Copy link
Contributor

@tex3d tex3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

5 participants