From 24695174b1c1426a4be2c29502b29d2ed8ba6d30 Mon Sep 17 00:00:00 2001 From: Greem Date: Thu, 26 Nov 2026 11:58:06 +0100 Subject: [PATCH] D3D12.X: a placed view's padding does not make a second texture `prepare_placed_srv_desc` and `prepare_placed_uav_desc` key `placed_srvs` / `placed_uavs` by (address, 0x38-byte console resource description) and clear only 0x34.. of it. Bytes 0x04..0x08 are the padding between `Dimension` and `Alignment`; the retail title leaves stack bytes there, so the same view at the same address made a second PC texture (and its views) whenever that padding differed. Both now clear it too. Measured on the retail title (RX 7900 XT, RADV, Wine, amd-dev b5c0275 with the Wine stack), one 200 s run each: `placed_srvs` held 60,925 entries at 190 s without the change and 41,965 with it (-31 %); the same share as main's `resource_at` (#2743, fixed there by #2762). Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/format_alias.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/format_alias.rs b/crates/xcl/src/hle/d3d12x/format_alias.rs index dfb1f15b27..b601fc8f52 100644 --- a/crates/xcl/src/hle/d3d12x/format_alias.rs +++ b/crates/xcl/src/hle/d3d12x/format_alias.rs @@ -186,6 +186,9 @@ pub(super) fn uav_resource_format(rdesc_fmt: u32, view_fmt: u32) -> u32 { /// `ALLOW_UNORDERED_ACCESS` and a UAV-compatible format so PC D3D12 never drops it to a null view. pub(super) fn prepare_placed_uav_desc(rdesc: &[u8; 0x38], view_fmt: u32) -> [u8; 0x38] { let mut x = *rdesc; + // the padding between `Dimension` and `Alignment` (the title leaves stack bytes there): one + // key per view, not one per padding value + x[0x04..0x08].fill(0); x[0x34..].fill(0); let rdesc_fmt = u32::from_le_bytes(x[0x20..0x24].try_into().unwrap()); let mut flags = u32::from_le_bytes(x[0x30..0x34].try_into().unwrap()); @@ -208,6 +211,7 @@ pub(super) fn prepare_placed_uav_desc(rdesc: &[u8; 0x38], view_fmt: u32) -> [u8; /// retire or overwrite GPU-owned target tracking at `va`. pub(super) fn prepare_placed_srv_desc(rdesc: &[u8; 0x38], view_fmt: u32) -> [u8; 0x38] { let mut x = *rdesc; + x[0x04..0x08].fill(0); x[0x34..].fill(0); let rdesc_fmt = u32::from_le_bytes(x[0x20..0x24].try_into().unwrap()); let mut flags = u32::from_le_bytes(x[0x30..0x34].try_into().unwrap()); @@ -1487,6 +1491,22 @@ mod tests { assert_eq!(srv_flags & (FLAG_RENDER_TARGET | FLAG_UAV), 0); } + #[test] + fn placed_descs_ignore_the_padding_after_dimension() { + // bytes 0x04..0x08 are the padding between `Dimension` and `Alignment`; the title leaves + // stack bytes there, and a different value must not make a second key for the same view + let mut x = [0u8; 0x38]; + x[0..4].copy_from_slice(&3u32.to_le_bytes()); // Texture2D + x[0x10..0x18].copy_from_slice(&256u64.to_le_bytes()); + x[0x18..0x1C].copy_from_slice(&256u32.to_le_bytes()); + x[0x20..0x24].copy_from_slice(&28u32.to_le_bytes()); // R8G8B8A8_UNORM + let mut garbage = x; + garbage[0x04..0x08].copy_from_slice(&[0xd8, 0x7e, 0x3f, 0x01]); + assert_eq!(prepare_placed_srv_desc(&garbage, 28), prepare_placed_srv_desc(&x, 28)); + assert_eq!(prepare_placed_uav_desc(&garbage, 28), prepare_placed_uav_desc(&x, 28)); + assert_eq!(prepare_placed_srv_desc(&garbage, 28)[0x04..0x08], [0u8; 4]); + } + #[test] fn alias_table_links_in_both_creation_orders() { let mut t = AliasTable::new();