From 736d10e1a5bd818681358d46d0ec5b9cfaef76ca Mon Sep 17 00:00:00 2001 From: "Abdellah K." <118073627+Abdellah-Khanani@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:45:02 +0100 Subject: [PATCH 1/2] D3D12.X: map the packed mips of a one-slice title texture where D3D12 addresses them On AMD's RDNA1 Windows driver (RX 5700 XT, 32.0.21045.29003) the packed mips of a reserved title texture with standard mips stayed unmapped and read zero. A 64x64x64 RGBA8 texture with 4 mips has 19 tiles there: mip 0 16, mip 1 2, and mips 2-3 packed into one tile (NumStandardMips 2, start 18). After the single run over the overall tiles from subresource 0 in Pages::map, mip 2 read back all zero. The packed block is now mapped again with the first packed mip as the subresource and the tile within the block as X, to the same tiles map chose. Only for a 3D texture or a 2D texture without an array (an array keeps a packed block per slice, not measured), and only when it has standard and packed mips. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/vram.rs | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 507c5b696..4e79003f7 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -309,6 +309,50 @@ impl Pages { let _ = self.queue.Signal(&self.fence, self.value); } + /// Map the packed mips of `res` again, addressed as D3D12 addresses them: the first packed mip as + /// the subresource and the tile within the packed block as X. The run over the overall tiles in + /// `map` does not reach them on every driver: AMD's RDNA1 driver (Windows) left the one packed + /// tile of a 64x64x64 RGBA8 texture with two standard mips unmapped, so its mips 2-3 read zero. + /// Only for one slice (3D, or 2D without an array): an array keeps a packed block per slice. + unsafe fn map_packed_mips(&mut self, dev: &ID3D12Device, res: &ID3D12Resource, tiles: &[Tile]) { + let desc = res.GetDesc(); + if desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D && desc.DepthOrArraySize != 1 { + return; + } + let mut packed = D3D12_PACKED_MIP_INFO::default(); + dev.GetResourceTiling(res, None, Some(&mut packed), None, None, 0, std::ptr::null_mut()); + let (start, n) = (packed.StartTileIndexInOverallResource as usize, packed.NumTilesForPackedMips as usize); + if packed.NumPackedMips == 0 || packed.NumStandardMips == 0 || n == 0 || start + n > tiles.len() { + return; + } + let packed_tiles = &tiles[start..start + n]; + let mut heaps: Vec = packed_tiles.iter().map(|t| t.0).collect(); + heaps.sort_unstable(); + heaps.dedup(); + for h in heaps { + let ranges = heap_ranges(h, packed_tiles); + let flags: Vec = ranges.iter().map(|r| if r.0 { D3D12_TILE_RANGE_FLAG_NONE } else { D3D12_TILE_RANGE_FLAG_SKIP }).collect(); + let offsets: Vec = ranges.iter().map(|r| r.1).collect(); + let counts: Vec = ranges.iter().map(|r| r.2).collect(); + let coord = D3D12_TILED_RESOURCE_COORDINATE { Subresource: packed.NumStandardMips as u32, ..Default::default() }; + let region = D3D12_TILE_REGION_SIZE { NumTiles: n as u32, UseBox: false.into(), ..Default::default() }; + self.queue.UpdateTileMappings( + res, + 1, + Some(&coord), + Some(®ion), + &self.pools[h as usize], + ranges.len() as u32, + Some(flags.as_ptr()), + Some(offsets.as_ptr()), + Some(counts.as_ptr()), + D3D12_TILE_MAPPING_FLAG_NONE, + ); + } + self.value += 1; + let _ = self.queue.Signal(&self.fence, self.value); + } + /// Unmap every tile of `res` (`D3D12_TILE_RANGE_FLAG_NULL`) so its unshared tiles can return /// to the pool even while the title keeps the COM object alive. unsafe fn unmap(&mut self, res: &ID3D12Resource, total: u32) { @@ -412,6 +456,7 @@ impl Pages { return None; } self.map(res, &tiles); + self.map_packed_mips(dev, res, &tiles); Some((used, used_extra)) } } From 3896e4fb97d4971971ab7b178a541170cb96318b Mon Sep 17 00:00:00 2001 From: "Abdellah K." <118073627+Abdellah-Khanani@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:45:02 +0100 Subject: [PATCH 2/2] Tests: the title textures test runs on an adapter that makes no reserved cube a6f5f7a skipped placed_title_textures_share_vram_and_preserve_pixels whole on an adapter that refuses the reserved 256x256x6 cube with 9 mips, because the cube's same-address reuse step then expected shared pages it never got. That also hid the unmapped packed mips of the 3D texture on AMD's RDNA1 driver. The reuse step now runs only when the first cube was reserved (a committed cube has no tiles to reuse); the rest of the test runs. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/title_textures.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index 2f3303a97..bfe31e124 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1396,17 +1396,6 @@ mod tests { println!("SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2"); return; } - // An adapter that reports tier 2 but refuses a reserved cube with packed mips - // (GitHub's runner) does not run the shared-page path this test is about. - { - let mut cube: D3D12_RESOURCE_DESC = std::ptr::read_unaligned(super::super::device_x::pc_resource_desc(&console_desc(3, 256, 256, 6, 9, 28, 0x105)).as_ptr() as *const _); - cube.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; - let mut r: Option = None; - if dev.CreateReservedResource(&cube, D3D12_RESOURCE_STATE_COMMON, None, &mut r).is_err() || r.is_none() { - println!("SKIPPED placed_title_textures_share_vram_and_preserve_pixels: this adapter makes no reserved cube with mips"); - return; - } - } super::super::real::adopt(dev.as_raw(), super::super::real::Kind::Device); let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); let Some(uma) = crate::gpu::uma::get() else { @@ -1621,7 +1610,8 @@ mod tests { assert_eq!(read_sub(&res, sub as u32), exp.data, "{label}: subresource {sub} mismatch"); } // Placing a second cubemap at the same va must reuse every tile including extra_pages. - if label.contains("cubemap") { + // Only when the first one was reserved: a committed one has no tiles to reuse. + if label.contains("cubemap") && placed { let p0 = dev_pages(); let res2 = place_tex(base, &d); assert_eq!(dev_pages(), p0, "cubemap extra_pages must be reused at same va");