Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docs/experiments/native-dxil-llvm-ident.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Direct DXIL `!llvm.ident` metadata for AMD RDNA 4 pipeline creation (#2915)

[The fixture](../../tests/native_dxil_llvm_ident_check.py) verifies that every direct DXIL emitter in
`src/dxil_module.h` (`DxilModule::finish_compute`, covering `cs`, `vs`, `gs`, and `ps`) and
`src/gfx1013_pixel.cpp` (`x2w::direct_gfx1013_constant_pixel`) emits `!llvm.ident = !{!<id>}` (`!{!"x2w"}`),
and draws both direct pixel paths on WARP and hardware with negative controls.

## Cause of the AMD `0xC0000005` PSO crash

On `cpp-migration` (`40365770`..`ee76dfa8`), all direct-DXIL `_hardware` tests crashed with `0xC0000005`
inside `amdxc64.dll` during `CreateComputePipelineState` and `CreateGraphicsPipelineState` on an
AMD Radeon RX 9070 XT (`1002:7550`, driver `32.0.32029.2010`), even though `IDxcValidator::Validate`
accepted every container and both WARP and NVIDIA passed:

- `native_scalar_lds_hardware`
- `native_adjacent_srv_hardware`
- `native_mtbuf_hardware`
- `native_indexed_atomic_hardware`
- `native_dpp_mirror_hardware`
- `native_graphics_wqm_hardware`
- `native_graphics_vertex_vcc_join_hardware`

Comparing disassembled DXIL modules (`dxc.exe -dumpbin`) re-assembled through `IDxcAssembler::AssembleToContainer`
and `IDxcValidator::Validate` isolated the crash to a single missing named metadata entry:

- Re-assembling DXC's `ps_6_6` output passed (`rc = 0`, `debug_errors=0 debug_warnings=0`).
- Re-assembling `DxilModule` output as-is crashed (`0xC0000005`), and bumping `!dx.valver` to `1.8` or `1.9`
alone still crashed (`0xC0000005`).
- Adding `!llvm.ident = !{!<id>}` (`!{!"x2w"}`) alone made the identical `DxilModule` IR pass (`rc = 0`,
`debug_errors=0 debug_warnings=0`).

`dxc.exe` always emits `!llvm.ident`; `IDxcValidator` treats it as optional, whereas `amdxc64.dll` queries
`llvm::Module::getNamedMetadata("llvm.ident")` and dereferences the returned `NamedMDNode*` (`[rcx + 0x40]`)
without a null check.

## Verification and negative controls

1. **`container` mode (`native_dxil_llvm_ident_controls`):** compiles source-built shaders across
`gfx1013-container-cs`, `gfx1013-container-vs`, `gfx1013-container-ps`, `gfx1013-container-rect`
(`vs`, `gs`, `ps`), and `gfx1013-direct-constant-ps`, checks `dxc.exe -dumpbin` for `!llvm.ident`
resolving to `!"x2w"`, and runs a negative control that strips `!llvm.ident`, re-assembles + validates
through `dxcompiler.dll` / `dxil.dll`, and verifies the `!llvm.ident` check rejects the stripped module.
2. **`draw` mode (`native_dxil_llvm_ident_warp`, `native_dxil_llvm_ident_hardware`):** pairs a direct-DXIL
fullscreen-triangle vertex shader (`gfx1013-container-vs`) with `gfx1013-direct-constant-ps` and
`gfx1013-container-ps` on an `8x2` float target, checks bit-exact RGBA readback and zero D3D12 debug-layer
errors/warnings, and requires mutated-channel negative controls on each path to fail readback.

```powershell
cmake --build --preset release --target compile_dxil native_store_replay native_recording_check offscreen_check
ctest --preset release --no-tests=error -V -R "^native_dxil_llvm_ident_(controls|warp|hardware)$"
```

Verified on Windows 11 (`10.0.26100`), Release build, with the D3D12 debug layer enabled (`0` errors, `0` warnings)
across Microsoft Basic Render Driver (`1414:008c`, driver `10.0.26100.9818`) and AMD Radeon RX 9070 XT (`1002:7550`,
driver `32.0.32029.2010`), alongside all seven direct-DXIL `_hardware` tests listed above.

## Limits

- The committed `draw` check does not execute the stripped negative-control container on a GPU adapter, because
triggering an access violation inside a user-mode driver is driver-version-dependent rather than a D3D12
contract.
- The separate adapter-independent decoder refusal message in `native_wave_request_hardware` is tracked independently
on #2915.
8 changes: 5 additions & 3 deletions src/dxil_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ class DxilModule {
Text res = "null";
if (!resources.empty())
res = node(list(groups[0]) + ", " + list(groups[1]) + ", " + list(groups[2]) + ", " + list(groups[3]));
const auto version = node("i32 1, i32 6"), model = node("!\"" + stage + "\", i32 6, i32 6");
// AMD's DXIL compiler (amdxc64.dll) dereferences Module::getNamedMetadata("llvm.ident") without a null check.
const auto ident = node("!\"x2w\""), version = node("i32 1, i32 6"),
model = node("!\"" + stage + "\", i32 6, i32 6");
const unsigned flags = features | (uses_wave ? 524288 : 0);
Text properties = "null", signature = "null", view_state;
if (stage == "cs") {
Expand Down Expand Up @@ -261,8 +263,8 @@ class DxilModule {
"readnone\n"
"declare %dx.types.Handle "
"@dx.op.annotateHandle(i32,%dx.types.Handle,%dx.types.ResourceProperties) nounwind readnone\n";
out << "!dx.version = !{" << version << "}\n!dx.valver = !{" << version << "}\n!dx.shaderModel = !{" << model
<< "}\n";
out << "!llvm.ident = !{" << ident << "}\n!dx.version = !{" << version << "}\n!dx.valver = !{" << version
<< "}\n!dx.shaderModel = !{" << model << "}\n";
if (res != "null")
out << "!dx.resources = !{" << res << "}\n";
out << "!dx.entryPoints = !{" << entry << "}\n";
Expand Down
30 changes: 16 additions & 14 deletions src/gfx1013_pixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ std::string x2w::direct_gfx1013_constant_pixel(std::string_view code) {
out << R"( ret void
}
declare void @dx.op.storeOutput.f32(i32,i32,i32,i8,float) nounwind
!dx.version = !{!0}
!dx.valver = !{!0}
!dx.shaderModel = !{!1}
!dx.viewIdState = !{!2}
!dx.entryPoints = !{!3}
!0 = !{i32 1, i32 0}
!1 = !{!"ps", i32 6, i32 0}
!2 = !{[2 x i32] [i32 0, i32 4]}
!3 = !{void ()* @main, !"main", !4, null, null}
!4 = !{null, !5, null}
!5 = !{!6}
!6 = !{i32 0, !"SV_Target", i8 9, i8 16, !7, i8 0, i32 1, i8 4, i32 0, i8 0, !8}
!7 = !{i32 0}
!8 = !{i32 3, i32 15}
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!1}
!dx.shaderModel = !{!2}
!dx.viewIdState = !{!3}
!dx.entryPoints = !{!4}
!0 = !{!"x2w"}
!1 = !{i32 1, i32 0}
!2 = !{!"ps", i32 6, i32 0}
!3 = !{[2 x i32] [i32 0, i32 4]}
!4 = !{void ()* @main, !"main", !5, null, null}
!5 = !{null, !6, null}
!6 = !{!7}
!7 = !{i32 0, !"SV_Target", i8 9, i8 16, !8, i8 0, i32 1, i8 4, i32 0, i8 0, !9}
!8 = !{i32 0}
!9 = !{i32 3, i32 15}
)";
return out.str();
}
13 changes: 13 additions & 0 deletions tests/cmake/native_dxil_llvm_ident.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Direct DXIL !llvm.ident metadata check and WARP/hardware draw verification (#2915).
if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_dxil_llvm_ident_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_dxil_llvm_ident_check.py" container
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_dxil_llvm_ident_controls PROPERTIES TIMEOUT 60)
foreach(backend IN ITEMS warp hardware)
add_test(NAME native_dxil_llvm_ident_${backend} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_dxil_llvm_ident_check.py" draw
"$<TARGET_FILE:compile_dxil>" "$<TARGET_FILE:offscreen_check>" "${DXC_BIN_DIR}" ${backend})
set_tests_properties(native_dxil_llvm_ident_${backend} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endforeach()
endif()
Loading