Repository navigation
Conversation
For a draw with no textures or samplers, draw_indexed_on bound its
CBV/SRV/UAV and sampler heaps through
`bind_resources(...).map(|_| Vec::new())`, which drops the returned
`Bound`, and the heaps with it, right after SetDescriptorHeaps. D3D12
command lists hold no reference to the heaps they bind, so the list was
executed with released heaps.
On D3DMetal (CrossOver 26.3, Apple M5 Pro) such a list never completes:
the fence wait times out after 10 s, then GetDeviceRemovedReason blocks,
so the seven graphics tests that draw without textures hang
(gpu_graphics_vs_ps_draw, the three gpu_rect_list_* tests and the three
gpu_wave64_{ps,vs}_* tests).
bind_views handles the empty case the same way (two CBV/SRV/UAV slots,
one sampler slot) and returns the heaps, so every draw now goes through
it and keeps them until the fence wait. The compute paths already keep
theirs.
|
Overlap with #239: this is the same empty-draw heap fix as in #239 ( |
|
Tested The seven draw tests listed in the PR description passed on both exact parent 508a0c7 and PR head be2b06c on native Windows D3D12. Each revision had 7 passed, 0 failed, 0 ignored, and no reported skips or timeouts. The CrossOver hang did not occur here. RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. I built each revision separately with Not tested D3DMetal, the D3D12 debug layer, full workspace, and retail titles. AI use Codex with GPT-6.2 Sol ran the tests and drafted this report. |
|
Hardware check of Tested
Regression run PR ( Not tested
AI use
|
|
@ivall: could this one get the What it has instead: the Windows runs above, on an RTX 3080 Ti and on an RX 9070 XT (full suite, 680 passed, 0 failed), and on D3DMetal it is what stops the 7 draw tests from hanging. It still merges cleanly onto |
|
Test report from a second Mac, head Tested
Not tested
AI use
|
|
Test report from a second Apple silicon Mac (different chip and toolchain), plus an independent bisection that lands on the same cause. Tested
Bisection, before I found this PR (on
Not tested
AI-assisted (Claude Code, Claude Opus 5.5): bisected, built and ran the tests, wrote this report. |
|
Windows test report for Tested
Not tested
Follow-up offered /// `runner::draw` without textures, on any adapter with DXC (plain HLSL VS/PS, no wave size
/// needed, so also the CI runner's WARP): a triangle over the whole target, every pixel its
/// colour. The draw's descriptor heaps have to live until the command list has run. They were
/// released right after `SetDescriptorHeaps`, which a hardware driver did not notice; WARP
/// removed the device (0x887A0020) or faulted in the test process.
#[test]
fn gpu_draw_keeps_its_descriptor_heaps() {
if runner::adapter().is_err() || super::dxc::location().is_err() {
return runner::skip_test(if runner::adapter().is_err() { "no GPU" } else { "no DXC" });
}
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32G32B32A32_FLOAT;
let vs_hlsl = "struct V { float4 pos : SV_Position; float4 color : COLOR0; };\nV main(float4 pos : POSITION, float4 color : COLOR0) { V o; o.pos = pos; o.color = color; return o; }\n";
let ps_hlsl = "float4 main(float4 pos : SV_Position, float4 color : COLOR0) : SV_Target { return color; }\n";
let vs = super::dxc::compile(vs_hlsl, "main", "vs_6_6", &[]).unwrap();
let ps = super::dxc::compile(ps_hlsl, "main", "ps_6_6", &[]).unwrap();
let layout = [
runner::VertexElement { semantic: "POSITION", index: 0, format: DXGI_FORMAT_R32G32B32A32_FLOAT, offset: 0 },
runner::VertexElement { semantic: "COLOR", index: 0, format: DXGI_FORMAT_R32G32B32A32_FLOAT, offset: 16 },
];
let color = [0.25f32, 0.5, 0.75, 1.0];
let v: Vec<f32> = [[-1.0f32, -1.0], [-1.0, 3.0], [3.0, -1.0]].iter().flat_map(|&[x, y]| [x, y, 0.0, 1.0, color[0], color[1], color[2], color[3]]).collect();
// a few draws: each makes and binds its own heaps
for run in 0..4 {
let px = runner::draw(&vs, &ps, &layout, &v, 32, &[], &[], 8, [0.0; 4]).unwrap();
assert!(px.len() == 64 && px.iter().all(|p| *p == color), "run {run}: {px:?}");
}
}AI use: Claude Code (Claude Fable 5.2, Claude Opus 5.5) |
…pter The seven draw tests skip on an adapter that runs neither 64- nor 32-lane waves, so on the CI runner's WARP no draw reached the released heaps. gpu_draw_keeps_its_descriptor_heaps draws a plain HLSL VS / PS triangle through runner::draw four times, gated only on an adapter and DXC. Without the heap fix it removes the device (0x887A0020) or faults on WARP (Kalmarv's runs on xcl-dev#553) and has no result after 60 s on D3DMetal (Apple M5 Pro, CrossOver 26.3); with it, it passes on both, 3 of 3 runs. Co-authored-by: Kalmarv <59708937+Kalmarv@users.noreply.github.com>
At the end of tests.rs it conflicted with the tests main has added there since 508a0c7.
|
Test report for this PR ( Tested
41 ignored in every run. SKIPPED: none with the variable; The gap (not caused by this PR): since #680, with The change is small and touches the line this PR rewrites, so here it is on top of it: the raw views of Patch on top of this PR (+33 −10)diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs
index 92d9d88..54b310e 100644
--- a/crates/xcl/src/gpu/recomp/runner.rs
+++ b/crates/xcl/src/gpu/recomp/runner.rs
@@ -741,3 +741,3 @@ fn draw_gs_views(
let draw = Draw { sgprs: sgprs.to_vec(), scissor: [0, 0, size as i32, size as i32] };
- draw_indexed_on(dev, &pso, &rs, vertices, stride, indices, &[draw], mem, textures, samplers, size, clear)
+ draw_indexed_on(dev, &pso, &rs, vertices, stride, indices, &[draw], mem, textures, samplers, size, clear, 0)
}
@@ -766,3 +766,3 @@ pub fn draw_on(
/// A texture in D3D12 terms (e.g. decoded from a console T# by `gpu::desc`): SRV at
-/// descriptor heap index 2·i; `data` = the `MipLevels` levels one after the other, each in
+/// descriptor heap index `texture_heap_base()` + 2·i in `draw_on_multi`; `data` = the `MipLevels` levels one after the other, each in
/// tightly packed rows (`row_bytes` for level 0, its width's share for the smaller ones).
@@ -782,4 +782,22 @@ pub struct Draw {
-/// Heaps with `textures` (SRV at 2·i) and `samplers` (at j), bound on `list`.
-unsafe fn bind_views(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, textures: &[ViewTexture], samplers: &[D3D12_SAMPLER_DESC]) -> Result<Vec<windows::core::IUnknown>, String> {
+/// Where the textures of `draw_on_multi` start in the view heap: after the memory windows'
+/// raw views when a PSO built by the backend's hook reads them there (`Options::heap_windows`).
+pub fn texture_heap_base() -> u32 {
+ if super::pso::heap_windows() { super::MEM_HEAP_BASE + 4 } else { 0 }
+}
+
+/// The raw views of `mem` for every window slot (see `dispatch_with`).
+unsafe fn window_views(dev: &ID3D12Device, heap: &ID3D12DescriptorHeap, mem: &ID3D12Resource, mem_bytes: u64) {
+ let inc = dev.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) as usize;
+ for k in 0..4usize {
+ let mut h = heap.GetCPUDescriptorHandleForHeapStart();
+ h.ptr += (super::MEM_HEAP_BASE as usize + k) * inc;
+ dev.CreateUnorderedAccessView(mem, None::<&ID3D12Resource>, Some(&raw_window_uav(mem_bytes)), h);
+ }
+}
+
+/// Heaps with `textures` (SRV at `base` + 2·i) and `samplers` (at j), bound on `list`; with
+/// `base` > 0 the memory windows' raw views of `mem` come first.
+unsafe fn bind_views(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, textures: &[ViewTexture], samplers: &[D3D12_SAMPLER_DESC], mem: &ID3D12Resource, mem_bytes: u64, base: u32) -> Result<Vec<windows::core::IUnknown>, String> {
+ let base = base as usize;
let heap: ID3D12DescriptorHeap = dev
@@ -787,3 +805,3 @@ unsafe fn bind_views(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, textu
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
- NumDescriptors: (2 * textures.len()).max(2) as u32,
+ NumDescriptors: (base + (2 * textures.len()).max(2)) as u32,
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
@@ -807,2 +825,5 @@ unsafe fn bind_views(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, textu
let mut keep: Vec<windows::core::IUnknown> = vec![heap.cast().map_err(e)?, sheap.cast().map_err(e)?];
+ if base != 0 {
+ window_views(dev, &heap, mem, mem_bytes);
+ }
for (i, t) in textures.iter().enumerate() {
@@ -837,3 +858,3 @@ unsafe fn bind_views(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, textu
list.ResourceBarrier(&[transition(&r, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)]);
- dev.CreateShaderResourceView(&r, Some(&t.srv), at(&heap, 2 * i, inc));
+ dev.CreateShaderResourceView(&r, Some(&t.srv), at(&heap, base + 2 * i, inc));
keep.push(r.cast().map_err(e)?);
@@ -862,6 +883,7 @@ pub fn draw_on_multi(
) -> Result<Vec<[f32; 4]>, String> {
- draw_indexed_on(dev, pso, rs, vertices, stride, &[], draws, mem, textures, samplers, size, clear)
+ draw_indexed_on(dev, pso, rs, vertices, stride, &[], draws, mem, textures, samplers, size, clear, texture_heap_base())
}
-/// `draw_on_multi`, the draws indexed when there are `indices` (one index buffer for all).
+/// `draw_on_multi`, the draws indexed when there are `indices` (one index buffer for all);
+/// `base`: where the textures start in the view heap (`texture_heap_base`).
#[allow(clippy::too_many_arguments)]
@@ -880,2 +902,3 @@ fn draw_indexed_on(
clear: [f32; 4],
+ base: u32,
) -> Result<Vec<[f32; 4]>, String> {
@@ -959,3 +982,3 @@ fn draw_indexed_on(
// Keep the descriptor heaps alive until the list has run: D3D12 command lists do not hold a reference to them.
- let _bound = bind_views(dev, &list, textures, samplers)?;
+ let _bound = bind_views(dev, &list, textures, samplers, &mem_buf, mem_bytes, base)?;
list.SetGraphicsRootSignature(rs);
diff --git a/crates/xcl/tests/gpu_pso_e2e.rs b/crates/xcl/tests/gpu_pso_e2e.rs
index 6e3968f..3ca9c09 100644
--- a/crates/xcl/tests/gpu_pso_e2e.rs
+++ b/crates/xcl/tests/gpu_pso_e2e.rs
@@ -439,3 +439,3 @@ fn retail_textured_ps_decoded_descriptors_and_a_descriptor_change_between_draws(
mem[table / 4..table / 4 + 4].copy_from_slice(&vsharp(0x1000));
- mem[(table + 0x20) / 4..(table + 0x20) / 4 + 8].copy_from_slice(&desc::xcl_image_words(&t, heap_index));
+ mem[(table + 0x20) / 4..(table + 0x20) / 4 + 8].copy_from_slice(&desc::xcl_image_words(&t, runner::texture_heap_base() + heap_index));
mem[(table + 0x40) / 4..(table + 0x40) / 4 + 4].copy_from_slice(&vsharp(0x2000));Not tested
Own brain use: Double-checked code and tests. It works on my RX 7900 XTX but still needs a run on other GPUs (NVIDIA, Intel, RDNA2/RDNA4). |
…eate D3DMetal calls Release on adopted resources from a native thread of its own at submit time (4 per drain in the two tests below). That thread has no Wine TEB. res_release takes XCL's mutexes and, for a last reference, the late-release hold; uncontended, a std Mutex is a few atomics and gets through, but a contended one waits in Wine's ntdll, which never returns there. This commit keeps all of that off the host's thread. On a foreign thread the caller's Release does not run at all: the pointer goes into a lock-free ring, and a Wine thread (the late-release worker, or the next res_release on a Wine thread) runs it through res_release. Checking for the last reference there instead (AddRef returning 2) is not safe: a Release on another thread between that check and ours can take the count to 0 on the host's thread. The returned count is read with an AddRef and its Release, which cannot reach 0 while the caller's reference is still held. The ring has one consumer at a time (a flag; a drain that finds it set returns at once), and the consumer empties a slot before moving the tail past it, so a producer reusing the slot never has its entry erased. It has 16,384 slots: every foreign Release goes through it, and a full ring keeps the reference (the object leaks; the worker logs how many). Detection: only on a macOS host (util::mac_host, read once at adoption), so the path is off on Windows and on Wine on Linux. There, a thread whose stack pointer is at or above 0x7000_0000_0000 is a native thread. Measured on an M5 Pro (CrossOver 26.3, Rosetta 2): Wine threads 0x0180ea9f..0x0220fb37, D3DMetal threads 0x7ff2063df667..0x7ff2066c3677. The TEB pointer (gs:[0x30]) is not read: that read hangs on a D3DMetal thread (measured). Tested on main 85e3826 + xcl-dev#553 + ddf3be7: console_wave64_compute_through_ the_pso_hook_dispatch_and_read_back and gpu_mirror_upload_follows_cpu_ writes_and_later_mapping_changes hang without this series, and pass with "read the late-release setting at adoption" alone and with the series. No test here hangs without this commit; it covers contention those tests do not produce. Part of xcl-dev#258. Assisted-by: Claude Code (Claude Opus 4.6 wrote the first version; Claude Opus 5.5 rewrote the ring and the foreign Release after review by Ahmet-Dedeler)
|
Regression run of Against the limits in CONTRIBUTING.md: 90 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
Draws with no textures or samplers released their descriptor heaps right after
SetDescriptorHeaps, before the command list ran. On D3DMetal (CrossOver on Apple Silicon) such a list never completes: this is the draw hang reported for Apple Silicon in #42.What is in it
draw_indexed_onbinds its heaps withbind_viewsin every case and keeps them until the fence wait. The no-texture case went throughbind_resources(...).map(|_| Vec::new()), which dropped theBoundand its heaps at once, and D3D12 command lists do not keep the heaps they bind alive.bind_viewsalready handles the empty case (2 CBV/SRV/UAV slots, 1 sampler slot).gpu_draw_keeps_its_descriptor_heaps(Kalmarv's test from the report below, co-authored): a plain HLSL VS / PS triangle throughrunner::draw, gated only on an adapter and DXC, so it runs on the CI runner's WARP, where the seven draw tests skip.Tested
mainb7aa9f3has 723 passed, 0 failed on WARP and on an RTX 5070 Ti.gpu_draw_keeps_its_descriptor_heapson D3DMetal (Apple M5 Pro): 3 of 3 passed with the change; no result after 60 s without it.XCL_DXC_DIR). Unit-test binary run under CrossOver'swine.gpu_graphics_vs_ps_draw,gpu_rect_list_corners,gpu_rect_list_flat_outputs,gpu_rect_list_fullscreen_order,gpu_wave64_ps_spill_slots,gpu_wave64_ps_whole_wave_reductions,gpu_wave64_vs_spill_slots_and_identity), one per process with--exact: on this PR (be2b06c), 7 passed, about 0.5 s each. On main 508a0c7,gpu_graphics_vs_ps_drawhas no result after 60 s; on 2b4bb43 (samerunner.rs) none of the 7 had a result after 2 minutes.gpu::recomp(200 tests) with this change on 2b4bb43 (runner.rs,tests.rsandfence.rsare unchanged on 508a0c7): 160 passed (2 of them printSKIPPED: no wave64), 22 failed, 18 ignored. Without it: 153 passed, 22 failed, 7 hung, 18 ignored. The 22 failures are the same tests in both runs (FP64,OpenExistingHeapFromAddressand the others listed in GPU test results: NVIDIA RTX 3080 (wave32) and AMD RDNA2 iGPU (no mesh shaders) #42).tests/gpu_pso_e2e.rs: 7 passed;tests/console_shaders.rs: 3 passed, 4 ignored. WithoutXCL_SAMPLE_RPF/XCL_SAMPLE_DXCthey return early, so they do not draw here.Regression run
Not run: I have no Xbox title to run
scripts/smoke.ps1on.runner.rsis undercrates/xcl/src, but the changed function is only reached from tests (runner::draw,draw_on,draw_on_multi); the runtime uses onlyadapter(),wave64_supported()andgraphics_wave32()from this file.Not tested
cargo test --workspace.gpu::recompin one process with--test-threads=4did not finish: after 139 results,gpu_unified_memory_arena(fails on D3DMetal withE_NOTIMPL) and three other tests stayed "running for over 60 seconds" at 100 % CPU. One per process, the other three pass. Not investigated; I could not compare it without this change, because the draw tests hang first there.AI use