Repository navigation
Conversation
The console's GPU allows uses of some formats that other host GPUs do not. On an RTX 4070 two 2560x1440 textures failed to create with E_INVALIDARG (vkd3d-proton: "Requested resource flags Marvisak#5, but no format in cast list supports it"): format 86 (BGRA8) with unordered access, and format 115 (B4G4R4A4) as a render target. When creation fails, try again without unordered access, then without render-target use, as is already done for depth targets that ask for unordered access. The views the host cannot make are skipped. A clear value is only passed while the texture is still a render target or depth target, since the host refuses it otherwise. Not checked: whether the title draws to or writes these textures in a way that now goes missing. Tested: Linux (Wine 11.21, vkd3d-proton 3.1), i7-12700K, RTX 4070. The two textures are created and the title runs on.
da1517b to
56f1d41
Compare
|
Tested on native Windows 11 D3D12 (Intel i7-12700 + NVIDIA RTX 3070):
|
|
Tested
AI-assisted. |
|
Follow-up to my test above: I implemented the
One difference from the suggestion: instead of leaving the target out of Feel free to take it into this PR; I can open it as a separate PR on top of this one instead if you prefer. Patch (on top of 56f1d41)diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs
index af6ad04..d9e5b2d 100644
--- a/crates/victory-gpu/src/draw.rs
+++ b/crates/victory-gpu/src/draw.rs
@@ -267,7 +267,14 @@ impl State {
self.targets.push(record.resource as usize);
#[cfg(feature = "diagnostics")]
crate::capture::note_target(record.resource);
- rtvs.push(host.rtv(texture, record.desc().as_ref()));
+ let rtv = host.rtv(texture, record.desc().as_ref()).unwrap_or_else(|| {
+ once!(
+ resource = format_args!("{:p}", record.resource),
+ "render target the host cannot render to; bound as a null view"
+ );
+ host.null_rtv()
+ });
+ rtvs.push(rtv);
}
self.depth = 0;
let dsv = crate::descriptor::dsv_record(depth).and_then(|record| {
diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs
index d89159e..7f4835c 100644
--- a/crates/victory-gpu/src/host.rs
+++ b/crates/victory-gpu/src/host.rs
@@ -694,20 +694,48 @@ impl Host {
}
/// A host render target view of `resource`, valid until it is recorded.
+ /// `None` when the host texture was made without render-target use
+ /// (the host refused it, see `resource.rs`): a view of it is an invalid
+ /// call that removes the device.
pub(crate) fn rtv(
&self,
resource: &ID3D12Resource,
desc: Option<&D3D12_RENDER_TARGET_VIEW_DESC>,
- ) -> D3D12_CPU_DESCRIPTOR_HANDLE {
- let slot = self.next_rtv.fetch_add(1, Ordering::Relaxed) % RTV_RING;
+ ) -> Option<D3D12_CPU_DESCRIPTOR_HANDLE> {
+ // SAFETY: a live resource.
+ let flags = unsafe { resource.GetDesc() }.Flags;
+ if (flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET).0 == 0 {
+ return None;
+ }
+ let handle = self.next_rtv_slot();
// SAFETY: a slot of our heap and a live resource.
unsafe {
- let mut handle = self.rtvs.GetCPUDescriptorHandleForHeapStart();
- handle.ptr += (slot * self.rtv_size) as usize;
self.device
.CreateRenderTargetView(resource, desc.map(|d| d as *const _), handle);
- handle
}
+ Some(handle)
+ }
+
+ /// A null render target view: it keeps a slot's place among the bound
+ /// targets, and writes to it are discarded.
+ pub(crate) fn null_rtv(&self) -> D3D12_CPU_DESCRIPTOR_HANDLE {
+ let handle = self.next_rtv_slot();
+ let desc = D3D12_RENDER_TARGET_VIEW_DESC {
+ Format: DXGI_FORMAT_R8G8B8A8_UNORM,
+ ViewDimension: D3D12_RTV_DIMENSION_TEXTURE2D,
+ ..Default::default()
+ };
+ // SAFETY: a slot of our heap; a null resource with a full description.
+ unsafe { self.device.CreateRenderTargetView(None, Some(&desc), handle) };
+ handle
+ }
+
+ fn next_rtv_slot(&self) -> D3D12_CPU_DESCRIPTOR_HANDLE {
+ let slot = self.next_rtv.fetch_add(1, Ordering::Relaxed) % RTV_RING;
+ // SAFETY: the start of our heap.
+ let mut handle = unsafe { self.rtvs.GetCPUDescriptorHandleForHeapStart() };
+ handle.ptr += (slot * self.rtv_size) as usize;
+ handle
}
/// A host depth view of `resource`, valid until it is recorded.
diff --git a/crates/victory-gpu/src/list.rs b/crates/victory-gpu/src/list.rs
index 78d6d73..aa11fbe 100644
--- a/crates/victory-gpu/src/list.rs
+++ b/crates/victory-gpu/src/list.rs
@@ -695,7 +695,10 @@ extern "system" fn clear_rtv(
unsafe { std::slice::from_raw_parts(rects.cast(), count as usize) }
});
const RENDER_TARGET: u32 = 0x4;
- let rtv = host.rtv(texture, record.desc().as_ref());
+ // A texture the host cannot render to has no view to clear.
+ let Some(rtv) = host.rtv(texture, record.desc().as_ref()) else {
+ return;
+ };
// SAFETY: an open list, a fresh view of a live texture.
unsafe {
if let Some((_, before)) = list.transition(record.resource, RENDER_TARGET) {AI-assisted. |
|
Tested |
…uses Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review question (built on Is there a check I missed that skips such binds? If not, #89 takes the other route for the packed 16-bit formats (it renders them as R8G8B8A8, keeping the capability), which avoids the problem for that case. From reading only; I have no copy of the title. |
|
Tested #55 (56f1d41) and #89 (081afbd) together on an AMD CPU, so the Intel start-up blocker above doesn't apply: Windows 10 22H2 (19045.6466), RTX 3070, NVIDIA 621.14, Ryzen 5 5600X, release build. Both merged cleanly on top of #233 (3098672) + #175 (19aec59), so this is the four together, not either PR alone.
No game data in this report. AI-assisted (Claude Code); everything above was run on my machine. |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 56f1d41 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (227 passed, 0 failed; older base). Not tested under vkd3d-proton.
Retrying creation without the refused use is a reasonable fallback, but dropping the render-target use opens a new failure path:
crates/victory-gpu/src/draw.rs:282 and crates/victory-gpu/src/list.rs:704 create RTVs without checking ALLOW_RENDER_TARGET.
- Before this PR, a texture whose creation failed had no host copy, so
host_resourcereturnedNoneand the RT binding was skipped. - Now the texture exists without
ALLOW_RENDER_TARGET. When the title binds it as a target, or clears it (list.rs:704),CreateRenderTargetViewis called on a resource that doesn't allow it. That is invalid usage: a debug-layer error, and possibly device removal on some drivers. - The UAV side is already guarded (
descriptor/host.rs:592checksALLOW_UNORDERED_ACCESS), so dropping UAV is safe. Dropping the RT use needs the same check beforehost.rtv(Some(texture), …). Write a typed null RTV (as #450 does for null records) and skip the clear, or skip the slot.
Smaller point: the retry order drops UAV first, and on failure keeps it dropped before trying to drop RT. A texture whose only problem is RT therefore loses UAV too, which it didn't need to. Trying !RT alone before !(UAV | RT) would keep it.
AI-assisted (Claude Code).
|
A gap this leaves on NVIDIA: the render-target views are still made, and one of them removes the device. When the render-target use is dropped (B4G4R4A4 on NVIDIA), the comment says "the views the host cannot make are skipped as for depth". But the RTV paths don't skip them. Seen on an RTX 2080 with a stack that includes this change (JMAN730's fork + #493 + #189 + #206 + #667 + 2^18 dynamic slots from #747). That stack makes more world draws run. With the debug layer on ( The fix I used is a check in // host.rs
pub(crate) fn renders_to(texture: &ID3D12Resource) -> bool {
let flags = unsafe { texture.GetDesc() }.Flags;
flags.contains(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)
}
// in Host::rtv, before CreateRenderTargetView:
let (resource, desc) = match resource {
Some(r) if !renders_to(r) => (None, Some(&null)), // typed null RTV
_ => (resource, desc),
};
// list.rs, clear_rtv:
if !crate::host::renders_to(texture) { return; }Same build, same input, before and after: the device was removed at world entry 2 of 2 times without it, and the run stayed up for 8 minutes with it (~2,430 draws per frame, median 0.91 s per frame). Main's AI-assisted (Claude Code): the debug-layer run, fix and runs were automated. The hardware, title copy and runs are the user's. |
|
Test report, and a follow-up fix for what this PR exposes. Setup: RTX 3050 6 GB Laptop (NVIDIA, driver 32.0.16.2124), i7-13700H, 16 GB RAM, Windows 11 26300, diag build. Title 1.0.2.1, Series X profile. Tree: What this PR fixes: the two textures What it exposes: an invalid call that removes the device. In all three runs with this PR the device was removed 1:41–1:58 in with
The fix (below, 47 lines; it applies to this PR's head):
With the fix, two runs:
patchdiff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs
index d2537cc..2598d36 100644
--- a/crates/victory-gpu/src/draw.rs
+++ b/crates/victory-gpu/src/draw.rs
@@ -272,6 +272,14 @@ impl State {
let Some(texture) = crate::resource::host_resource(record.resource) else {
continue;
};
+ if !crate::host::renders_to(texture) {
+ once!(
+ resource = format_args!("{:#x}", record.resource as usize),
+ "render target the host cannot render to: a null view in its slot"
+ );
+ rtvs.push(host.null_rtv());
+ continue;
+ }
self.targets.push(record.resource as usize);
#[cfg(feature = "diagnostics")]
crate::capture::note_target(record.resource);
diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs
index 2dc9d27..6e545da 100644
--- a/crates/victory-gpu/src/host.rs
+++ b/crates/victory-gpu/src/host.rs
@@ -1402,6 +1402,25 @@ impl Host {
}
}
+ /// A null render target view, for a slot the title binds a texture the
+ /// host cannot render to (its copy was made without that use): draws
+ /// write nothing there, and the other targets keep their slots.
+ pub(crate) fn null_rtv(&self) -> D3D12_CPU_DESCRIPTOR_HANDLE {
+ let slot = self.next_rtv.fetch_add(1, Ordering::Relaxed) % RTV_RING;
+ let desc = D3D12_RENDER_TARGET_VIEW_DESC {
+ Format: DXGI_FORMAT_R8G8B8A8_UNORM,
+ ViewDimension: D3D12_RTV_DIMENSION_TEXTURE2D,
+ ..Default::default()
+ };
+ // SAFETY: a slot of our heap; a null resource is allowed with a desc.
+ unsafe {
+ let mut handle = self.rtvs.GetCPUDescriptorHandleForHeapStart();
+ handle.ptr += (slot * self.rtv_size) as usize;
+ self.device.CreateRenderTargetView(None, Some(&desc), handle);
+ handle
+ }
+ }
+
/// A host depth view of `resource`, valid until it is recorded.
pub(crate) fn dsv(
&self,
@@ -2533,6 +2552,14 @@ pub(crate) fn legal_state(texture: &ID3D12Resource, state: u32) -> u32 {
legal_for(unsafe { texture.GetDesc() }.Flags.0 as u32, state)
}
+/// Whether the host copy of a texture can be a render target: not when the
+/// host refused that use for its format and the copy was made without it.
+pub(crate) fn renders_to(texture: &ID3D12Resource) -> bool {
+ // SAFETY: a plain query.
+ let flags = unsafe { texture.GetDesc() }.Flags;
+ flags.0 & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET.0 != 0
+}
+
/// [`legal_state`] for a texture with resource flags `flags`.
pub(crate) fn legal_for(flags: u32, state: u32) -> u32 {
// (flag, set or clear forbids, state bits): render target, unordered
diff --git a/crates/victory-gpu/src/list.rs b/crates/victory-gpu/src/list.rs
index 7adb4e4..b076b67 100644
--- a/crates/victory-gpu/src/list.rs
+++ b/crates/victory-gpu/src/list.rs
@@ -703,6 +703,18 @@ extern "system" fn clear_rtv(
unsafe { std::slice::from_raw_parts(rects.cast(), count as usize) }
});
const RENDER_TARGET: u32 = 0x4;
+ if !crate::host::renders_to(texture) {
+ // Its host copy was made without the render-target use (the
+ // host refuses it for the format): no view, no barrier, no clear.
+ static ONCE: std::sync::Once = std::sync::Once::new();
+ ONCE.call_once(|| {
+ tracing::warn!(
+ resource = format_args!("{:#x}", record.resource as usize),
+ "clear of a render target the host cannot render to: skipped"
+ )
+ });
+ return;
+ }
let rtv = host.rtv(texture, record.desc().as_ref());
// SAFETY: an open list, a fresh view of a live texture.
unsafe {Not tested: AMD (where nothing is dropped, so the new paths never run), more runs, a release build. The null view's format is AI use: Claude Code (Claude Opus 5.5) found the cause, wrote the patch, ran the title on my machine and drafted this note; results are from the runs described. |
#55 retried CreateCommittedResource without UAV and then render-target use when the host refused a format's use. A texture made without render-target use can still get render-target views, which is invalid on D3D12. The tester tree leaves #55 out; host_texture is its form again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The render-target guard from my comment above is now a PR on its own: #1613. It applies to |
…e render-target use A host texture made without ALLOW_RENDER_TARGET (Marvisak#55 drops a use the host refuses for the format, e.g. B4G4R4A4_UNORM on NVIDIA) was still cleared and bound as a render target: CreateRenderTargetView, a barrier to RENDER_TARGET and ClearRenderTargetView on it are invalid calls, and the device is removed with DXGI_ERROR_INVALID_CALL. `host::renders_to` tells. The clear skips such a texture (warned once); `set_targets` binds a null RTV in its slot (`Host::null_rtv`), so the other targets keep their slots and draws write nothing there. No change while every texture keeps its render-target use, as on `main` today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
…e render-target use A host texture made without ALLOW_RENDER_TARGET (Marvisak#55 drops a use the host refuses for the format, e.g. B4G4R4A4_UNORM on NVIDIA) was still cleared and bound as a render target: CreateRenderTargetView, a barrier to RENDER_TARGET and ClearRenderTargetView on it are invalid calls, and the device is removed with DXGI_ERROR_INVALID_CALL. `host::renders_to` tells. The clear skips such a texture (warned once); `set_targets` binds a null RTV in its slot (`Host::null_rtv`), so the other targets keep their slots and draws write nothing there. No change while every texture keeps its render-target use, as on `main` today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The console's GPU allows some uses of formats that other GPUs don't. On an RTX 4070 (Linux, vkd3d-proton), two 2560×1440 textures failed to create with
E_INVALIDARG:vkd3d-proton logs:
Requested resource flags #5, but no format in cast list supports it.Tested: