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();