D3D12.X: Add opt-in BC3 backing for private sampled textures #3256

Open
gefydev wants to merge 3 commits from upstream-pr/3256 into main
gefydev commented 2026-11-29 01:30:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gefydev on 2026-11-29T01:30:49Z.


Part of #1773. This draft adds opt-in BC3 backing for a narrow class of sampled textures created by address. XCL uses it only for eligible single-layer RGBA8 UNORM/sRGB resources with independent backing, compatible SRVs and a strictly smaller D3D12 allocation. The title's RGBA8 source layout remains the input for refreshes.

Help wanted: in-world VRAM measurements

If you have already reached a rendered 3D scene in this title, please try the draft and post your results here. Our local machine has reached the profile selector and loading screens. We are looking for a repeatable VRAM measurement and a visual check in the world.

  1. Build this PR's exact head with cargo build --release -p xcl. Use that same executable for all four runs.
  2. Keep the launch configuration that reaches the world. Leave the GPU, driver, save, route, resolution, graphics settings and launch flags fixed. BC3 needs independent backing. If you normally use shared texture pages, try XCL_VRAM_ARENAS=1 in all four runs only if that configuration still reaches the world. If it blocks progress, please report where it stops.
  3. Set XCL_TEXTURE_COMPRESSION_QUALITY=balanced for both arms and warm each arm's shader cache before recording. Run OFF → ON → OFF → ON, restarting the title for each run. Set XCL_TEXTURE_COMPRESSION=0 for OFF and XCL_TEXTURE_COMPRESSION=bc3 for ON. Use the same save and repeat the same route and measurement window.
  4. Report the commit, GPU, VRAM capacity, driver and launch flags. For each run, include the furthest point reached, DXGI local and non-local memory at the same in-world checkpoint and their peaks over the matched window. For ON runs, include the BC3 texture at log lines or their count and summed native/BC3 allocation sizes. Please include matching screenshots and any visible artifacts, stalls, OOMs or crashes. Zero conversions and runs that stop at loading are useful results too.

What is in it

  • gpu/block_compression.rs adds BC1/BC3 encoding and three color fits. The D3D12 round-trip checks BC1 and BC3 in UNORM and sRGB across 12 mips.
  • hle/d3d12x/texture_compression.rs and the SRV-by-address hook select private BC3 backing with XCL_TEXTURE_COMPRESSION=bc3. XCL_TEXTURE_COMPRESSION_QUALITY=fast|balanced|high selects the fit, with balanced as the default when enabled.
  • hle/d3d12x/texture_upload.rs encodes refreshed mips from a CPU snapshot and tracks the corresponding source bytes. The dirty-source round-trip checks that an update reaches the BC3 resource.
  • An optional XCL_TEXTURE_COMPRESSION_OBJECTS=1 census records candidate shapes seen by the SRV-by-object hook. These resources keep their native backing.

Tested

  • GeForce GTX 1650 (driver 621.24), Ryzen 5 1600, Windows 11 Pro build 26300, Rust 1.100.0 MSVC. Workspace builds passed in debug for the branch and release for both arms.
  • cargo test --workspace --no-fail-fast -j 6 -- --test-threads=4 --nocapture in debug: 2,618 reported passed, 0 failed, 49 ignored across 41 groups. The log includes 30 SKIPPED markers within those pass totals: 21 wave64, 3 unsupported low-precision instruction forms, 2 heap-window opt-ins, 1 GPU_UPLOAD and 3 debug-layer checks.
  • Synthetic 2048×1024 texture, 12 mips: the driver allocated 1,441,792 B for BC1 and 2,818,048 B for BC3 versus 11,206,656 B for RGBA8 in both UNORM and sRGB. Readback verified every encoded mip. Independent tests on the earlier codec-only commit also reported the same allocation sizes on RTX 5070 Ti and RTX 4080.
  • Opt-in A/B on branch head 49121f46, 90 seconds without input. Both arms used XCL_PREPARE=0, XCL_VRAM_ARENAS=1 (independent backing), XCL_TEXTURE_LEVEL_PAGES=1, XCL_TEXTURE_COMPRESSION_OBJECTS=1, XCL_TEXTURE_COMPRESSION_QUALITY=balanced and XCL_FRAME_DUMP=300. Only XCL_TEXTURE_COMPRESSION changed (0/bc3). Both showed the profile selector and exited cleanly. The BC3 arm logged two eligible allocations before XUserAddAsync, totaling 192 KiB versus 640 KiB in the native format (448 KiB less by GetResourceAllocationInfo). No allocations were converted in the control. Reported video-local peaks were 6,667 MB (off) and 6,666 MB (on).

Regression run

Same title and 60-second run time with scripts/smoke.ps1. Networking and shader preparation were disabled, and both arms used the default texture path. No input was sent. Order was main → branch → branch → main, followed by a warm main/branch repeat. Every run exited 0 with zero crashes and device removals.

Order Revision Frames shown Peak commit (MB)
1 Main 1,307 11,295
2 Branch 1,194 16,036
3 Branch 1,246 16,036
4 Main 1,313 16,129
5 Main (warm repeat) 1,189 15,819
6 Branch (warm repeat) 1,278 16,041

The first main run reached XUserAddAsync at 45.9 s and recovered fewer cached pipeline blobs. Its target-page peak was 693 MB, compared with ~3.5 GB in the runs that advanced further. The blocks below come from the additional main/branch repeat with the cache populated.

xcl-smoke v1
commit: fa204595a488c60c6c5f905244f0172072c9c2a9
gpu: NVIDIA GeForce GTX 1650
title: eddfb802
seconds: 60
exit: 0x0
frames shown: 1189 (PresentX 1189)
presents per 2 s (last 3): 9 0 4
device removals: 0
crashes: 0
peak commit: 15819 MB
xcl-smoke v1
commit: 49121f46267a2991ca8bf1090289035089866f03
gpu: NVIDIA GeForce GTX 1650
title: eddfb802
seconds: 60
exit: 0x0
frames shown: 1278 (PresentX 1278)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16041 MB

Not tested

  • Gameplay rendering, in-world texture quality, and a title with enough eligible textures to measure an overall peak VRAM reduction. The observed 448 KiB applies to the two allocations in the selector run.
  • Runtime on AMD or on other NVIDIA GPUs. The two volunteer results above cover only the synthetic fixture on the earlier commit.
  • Other quality modes inside a retail title. The retail activation run used balanced.

AI use

AI use: Codex (gpt-6.2-sol) for implementation, tests, analysis and drafting.

<!-- greyfinch-sync:ivall/xcl:issue:5546448249 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256). Originally posted by [gefydev](https://github.com/gefydev) on 2026-11-29T01:30:49Z. --- Part of #1773. This draft adds opt-in BC3 backing for a narrow class of sampled textures created by address. XCL uses it only for eligible single-layer RGBA8 UNORM/sRGB resources with independent backing, compatible SRVs and a strictly smaller D3D12 allocation. The title's RGBA8 source layout remains the input for refreshes. ### Help wanted: in-world VRAM measurements If you have already reached a rendered 3D scene in this title, please try the draft and post your results here. Our local machine has reached the profile selector and loading screens. We are looking for a repeatable VRAM measurement and a visual check in the world. 1. Build this PR's exact head with `cargo build --release -p xcl`. Use that same executable for all four runs. 2. Keep the launch configuration that reaches the world. Leave the GPU, driver, save, route, resolution, graphics settings and launch flags fixed. BC3 needs independent backing. If you normally use shared texture pages, try `XCL_VRAM_ARENAS=1` in **all four runs** only if that configuration still reaches the world. If it blocks progress, please report where it stops. 3. Set `XCL_TEXTURE_COMPRESSION_QUALITY=balanced` for both arms and warm each arm's shader cache before recording. Run **OFF → ON → OFF → ON**, restarting the title for each run. Set `XCL_TEXTURE_COMPRESSION=0` for OFF and `XCL_TEXTURE_COMPRESSION=bc3` for ON. Use the same save and repeat the same route and measurement window. 4. Report the commit, GPU, VRAM capacity, driver and launch flags. For each run, include the furthest point reached, DXGI local and non-local memory at the same in-world checkpoint and their peaks over the matched window. For ON runs, include the `BC3 texture at` log lines or their count and summed native/BC3 allocation sizes. Please include matching screenshots and any visible artifacts, stalls, OOMs or crashes. Zero conversions and runs that stop at loading are useful results too. **What is in it** - `gpu/block_compression.rs` adds BC1/BC3 encoding and three color fits. The D3D12 round-trip checks BC1 and BC3 in UNORM and sRGB across 12 mips. - `hle/d3d12x/texture_compression.rs` and the SRV-by-address hook select private BC3 backing with `XCL_TEXTURE_COMPRESSION=bc3`. `XCL_TEXTURE_COMPRESSION_QUALITY=fast|balanced|high` selects the fit, with balanced as the default when enabled. - `hle/d3d12x/texture_upload.rs` encodes refreshed mips from a CPU snapshot and tracks the corresponding source bytes. The dirty-source round-trip checks that an update reaches the BC3 resource. - An optional `XCL_TEXTURE_COMPRESSION_OBJECTS=1` census records candidate shapes seen by the SRV-by-object hook. These resources keep their native backing. **Tested** - GeForce GTX 1650 (driver 621.24), Ryzen 5 1600, Windows 11 Pro build 26300, Rust 1.100.0 MSVC. Workspace builds passed in debug for the branch and release for both arms. - `cargo test --workspace --no-fail-fast -j 6 -- --test-threads=4 --nocapture` in debug: 2,618 reported passed, 0 failed, 49 ignored across 41 groups. The log includes 30 `SKIPPED` markers within those pass totals: 21 wave64, 3 unsupported low-precision instruction forms, 2 heap-window opt-ins, 1 GPU_UPLOAD and 3 debug-layer checks. - Synthetic 2048×1024 texture, 12 mips: the driver allocated 1,441,792 B for BC1 and 2,818,048 B for BC3 versus 11,206,656 B for RGBA8 in both UNORM and sRGB. Readback verified every encoded mip. Independent tests on the earlier codec-only commit also reported the same allocation sizes on [RTX 5070 Ti](https://github.com/xcl-dev/xcl/issues/42#issuecomment-7247462940) and [RTX 4080](https://github.com/xcl-dev/xcl/issues/42#issuecomment-7247736577). - Opt-in A/B on branch head `49121f46`, 90 seconds without input. Both arms used `XCL_PREPARE=0`, `XCL_VRAM_ARENAS=1` (independent backing), `XCL_TEXTURE_LEVEL_PAGES=1`, `XCL_TEXTURE_COMPRESSION_OBJECTS=1`, `XCL_TEXTURE_COMPRESSION_QUALITY=balanced` and `XCL_FRAME_DUMP=300`. Only `XCL_TEXTURE_COMPRESSION` changed (`0`/`bc3`). Both showed the profile selector and exited cleanly. The BC3 arm logged two eligible allocations before `XUserAddAsync`, totaling 192 KiB versus 640 KiB in the native format (448 KiB less by `GetResourceAllocationInfo`). No allocations were converted in the control. Reported video-local peaks were 6,667 MB (off) and 6,666 MB (on). **Regression run** Same title and 60-second run time with `scripts/smoke.ps1`. Networking and shader preparation were disabled, and both arms used the default texture path. No input was sent. Order was main → branch → branch → main, followed by a warm main/branch repeat. Every run exited 0 with zero crashes and device removals. | Order | Revision | Frames shown | Peak commit (MB) | | ---: | --- | ---: | ---: | | 1 | Main | 1,307 | 11,295 | | 2 | Branch | 1,194 | 16,036 | | 3 | Branch | 1,246 | 16,036 | | 4 | Main | 1,313 | 16,129 | | 5 | Main (warm repeat) | 1,189 | 15,819 | | 6 | Branch (warm repeat) | 1,278 | 16,041 | The first main run reached `XUserAddAsync` at 45.9 s and recovered fewer cached pipeline blobs. Its target-page peak was 693 MB, compared with ~3.5 GB in the runs that advanced further. The blocks below come from the additional main/branch repeat with the cache populated. ``` xcl-smoke v1 commit: fa204595a488c60c6c5f905244f0172072c9c2a9 gpu: NVIDIA GeForce GTX 1650 title: eddfb802 seconds: 60 exit: 0x0 frames shown: 1189 (PresentX 1189) presents per 2 s (last 3): 9 0 4 device removals: 0 crashes: 0 peak commit: 15819 MB ``` ``` xcl-smoke v1 commit: 49121f46267a2991ca8bf1090289035089866f03 gpu: NVIDIA GeForce GTX 1650 title: eddfb802 seconds: 60 exit: 0x0 frames shown: 1278 (PresentX 1278) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16041 MB ``` **Not tested** - Gameplay rendering, in-world texture quality, and a title with enough eligible textures to measure an overall peak VRAM reduction. The observed 448 KiB applies to the two allocations in the selector run. - Runtime on AMD or on other NVIDIA GPUs. The two volunteer results above cover only the synthetic fixture on the earlier commit. - Other quality modes inside a retail title. The retail activation run used balanced. **AI use** AI use: Codex (gpt-6.2-sol) for implementation, tests, analysis and drafting.
Auroraooy commented 2026-11-29 04:24:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Auroraooy on 2026-11-29T04:24:00Z.


No-title validation from the #42 volunteer (RTX 2080 Ti 11 GB, driver 595.79, Win10 19045, Core Ultra 7 265K, 96 GB RAM, 18 build jobs). I don't have a retail build, so I cannot do the in-world OFF -> ON -> OFF -> ON measurement — posting the source-level result instead.

Built exact head 49121f46 (gefydev/xcl) with cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4:

  • All 7 gpu::block_compression tests pass, including block_compress_quality_preserves_bc3_alpha_and_block_size, bc3_stores_alpha_endpoints_and_interpolated_indices, and the balanced/high endpoint tests.
  • Two lib GPU tests fail: hle::d3d12x::bind::tests::gpu_two_pass_indirect_commands_keep_their_own_records and failed_binding_keeps_indirect_commands_until_allocator_reset; the log shows error: Invalid bitcode signature. I can't tell yet whether that's this head, my DXIL/SDK setup, or the draft base — happy to rerun with a specific XCL_D3D12_DIR / XCL_DXC_DIR if that helps.
  • test_title_runs_and_game_folder_is_untouched fails as expected without a title.

DXGI local/non-local and conversion counts are not available without the game scene. Disclosure: run and text by GLM (Z.ai), reviewed by the machine owner.

<!-- greyfinch-sync:ivall/xcl:comment:7250628783 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7250628783). Originally posted by [Auroraooy](https://github.com/Auroraooy) on 2026-11-29T04:24:00Z. --- No-title validation from the #42 volunteer (RTX 2080 Ti 11 GB, driver 595.79, Win10 19045, Core Ultra 7 265K, 96 GB RAM, 18 build jobs). I don't have a retail build, so I cannot do the in-world OFF -> ON -> OFF -> ON measurement — posting the source-level result instead. Built exact head `49121f46` (gefydev/xcl) with `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4`: - **All 7 `gpu::block_compression` tests pass**, including `block_compress_quality_preserves_bc3_alpha_and_block_size`, `bc3_stores_alpha_endpoints_and_interpolated_indices`, and the balanced/high endpoint tests. - Two lib GPU tests fail: `hle::d3d12x::bind::tests::gpu_two_pass_indirect_commands_keep_their_own_records` and `failed_binding_keeps_indirect_commands_until_allocator_reset`; the log shows `error: Invalid bitcode signature`. I can't tell yet whether that's this head, my DXIL/SDK setup, or the draft base — happy to rerun with a specific `XCL_D3D12_DIR` / `XCL_DXC_DIR` if that helps. - `test_title_runs_and_game_folder_is_untouched` fails as expected without a title. DXGI local/non-local and conversion counts are not available without the game scene. Disclosure: run and text by GLM (Z.ai), reviewed by the machine owner.
andrewDoing commented 2026-11-29 04:35:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T04:35:41Z.


One accounting caveat for the requested in-world measurement at 49121f46: a logged RGBA8 → BC3 allocation delta need not be a net saving if the same address and resource descriptor are later viewed through a different legal SRV dimension.

For example, a single-layer 1024×1024 RGBA8 resource can use both a Texture2D SRV and a Texture2DArray SRV over slice 0 with ArraySize=1. The first can populate texture_compression::RESOURCES. The second is rejected by bc3_view's dimension check and goes through resource_at's separate MADE cache. With compression off both use the same MADE key. If both private allocations succeed with compression on, they are retained separately.

A native RTX 5070 12 GB D3D12 control created both view descriptors on one RGBA8 resource; GetResourceAllocationInfo reported 4,194,304 bytes RGBA8 and 1,048,576 bytes BC3 (single mip). The logged difference would suggest 3 MiB saved, while the mixed-view case would have 5 MiB of allocation requirements versus 4 MiB off. These are driver allocation sizes plus source tracing; I did not measure DXGI residency, run this through a title, or establish that the title uses this pair.

For interpreting the four-run census, counting fallback allocations that share an already-compressed address/descriptor (in either order) would distinguish potential from realized savings. A one-slice Texture2DArray test could also establish whether it can safely use the same BC3 backing. OpenAI Codex traced the paths, ran the native control and drafted this comment.

<!-- greyfinch-sync:ivall/xcl:comment:7250746329 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7250746329). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T04:35:41Z. --- One accounting caveat for the requested in-world measurement at 49121f46: a logged RGBA8 → BC3 allocation delta need not be a net saving if the same address and resource descriptor are later viewed through a different legal SRV dimension. For example, a single-layer 1024×1024 RGBA8 resource can use both a Texture2D SRV and a Texture2DArray SRV over slice 0 with ArraySize=1. The first can populate texture_compression::RESOURCES. The second is rejected by bc3_view's dimension check and goes through resource_at's separate MADE cache. With compression off both use the same MADE key. If both private allocations succeed with compression on, they are retained separately. A native RTX 5070 12 GB D3D12 control created both view descriptors on one RGBA8 resource; GetResourceAllocationInfo reported 4,194,304 bytes RGBA8 and 1,048,576 bytes BC3 (single mip). The logged difference would suggest 3 MiB saved, while the mixed-view case would have 5 MiB of allocation requirements versus 4 MiB off. These are driver allocation sizes plus source tracing; I did not measure DXGI residency, run this through a title, or establish that the title uses this pair. For interpreting the four-run census, counting fallback allocations that share an already-compressed address/descriptor (in either order) would distinguish potential from realized savings. A one-slice Texture2DArray test could also establish whether it can safely use the same BC3 backing. OpenAI Codex traced the paths, ran the native control and drafted this comment.
andrewDoing commented 2026-11-29 04:55:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T04:55:01Z.


The mixed-view allocation in the earlier source review occurs through the production by-address SRV handler on head 49121f46, RTX 5070 12 GB, driver 616.92. Both backings were live and readable in the same compute dispatch.

One CPU-filled 1024×1024 RGBA8 UNORM texture, one mip and one layer, had the same source address and resource descriptor in every view call. I called dev_create_srv_at_x for a Texture2D SRV and a Texture2DArray SRV over slice 0, ArraySize=1, writing to separate console descriptor slots. Recreating each view in another slot recovered its previous native resource identity.

Compression First view Distinct live resources Sum of native allocation requirements
Off 2D 1 RGBA8 4 MiB
Off Array 1 RGBA8 4 MiB
BC3 2D 1 BC3 + 1 RGBA8 5 MiB
BC3 Array 1 BC3 + 1 RGBA8 5 MiB

Each row used a fresh process with XCL_VRAM_ARENAS=1, small textures off, and balanced quality. I read the resource identities from XCL's descriptor tracking, called GetResourceAllocationInfo for each distinct resource, notified the production refresh path of the known CPU fill, then used the indices in the emitted texture descriptors for native GPU loads. With a red left half and green right half, both SRVs returned red=1 on the left and green=1 on the right in all four runs.

For this source, the BC3 log's 4 MiB → 1 MiB comparison coexists with a 1 MiB increase in combined allocation requirements over OFF. A census keyed by source address and resource descriptor could flag these mixed pairs during the requested world run. This test measures resource identities and allocation requirements; DXGI residency and the frequency of this view pair in a retail title remain unmeasured.

AI-assisted fixture and verification.

<!-- greyfinch-sync:ivall/xcl:comment:7250937675 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7250937675). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T04:55:01Z. --- The mixed-view allocation in [the earlier source review](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7250746329) occurs through the production by-address SRV handler on head `49121f46`, RTX 5070 12 GB, driver 616.92. Both backings were live and readable in the same compute dispatch. One CPU-filled 1024×1024 RGBA8 UNORM texture, one mip and one layer, had the same source address and resource descriptor in every view call. I called `dev_create_srv_at_x` for a Texture2D SRV and a Texture2DArray SRV over slice 0, ArraySize=1, writing to separate console descriptor slots. Recreating each view in another slot recovered its previous native resource identity. | Compression | First view | Distinct live resources | Sum of native allocation requirements | |---|---|---:|---:| | Off | 2D | 1 RGBA8 | 4 MiB | | Off | Array | 1 RGBA8 | 4 MiB | | BC3 | 2D | 1 BC3 + 1 RGBA8 | 5 MiB | | BC3 | Array | 1 BC3 + 1 RGBA8 | 5 MiB | Each row used a fresh process with `XCL_VRAM_ARENAS=1`, small textures off, and balanced quality. I read the resource identities from XCL's descriptor tracking, called `GetResourceAllocationInfo` for each distinct resource, notified the production refresh path of the known CPU fill, then used the indices in the emitted texture descriptors for native GPU loads. With a red left half and green right half, both SRVs returned red=1 on the left and green=1 on the right in all four runs. For this source, the BC3 log's 4 MiB → 1 MiB comparison coexists with a **1 MiB increase** in combined allocation requirements over OFF. A census keyed by source address and resource descriptor could flag these mixed pairs during the requested world run. This test measures resource identities and allocation requirements; DXGI residency and the frequency of this view pair in a retail title remain unmeasured. AI-assisted fixture and verification.
andrewDoing commented 2026-11-29 05:07:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T05:07:16Z.


I tested a narrow eligibility change on 49121f46 for the mixed-view case above. For a resource already passing the single-layer private RGBA8 checks, accept a Texture2DArray SRV only when FirstArraySlice=0, ArraySize=1 and PlaneSlice=0. The guest's SRV dimension and mip fields remain intact. Both view types then find the same BC3 backing through the existing resource key.

Four fresh RTX 5070 processes exercised the production by-address handler, descriptor tracking, texture refresh and native shader loads. With compression off, both creation orders retained one 4 MiB RGBA8 allocation. With BC3 on, both orders retained one 1 MiB BC3 allocation, versus two allocations totaling 5 MiB on the unmodified head. Recreating either view preserved its resource identity. Both views read the expected red and green samples in all four processes. For this controlled pair, the 4 MiB → 1 MiB log now matches the combined allocation requirements. Other fallback view types and actual in-world DXGI residency remain outside this result.

Full production diff below. OpenAI Codex implemented the change and ran the existing synthetic native fixture with updated expectations.

--- a/crates/xcl/src/hle/d3d12x/texture_compression.rs
+++ b/crates/xcl/src/hle/d3d12x/texture_compression.rs
@@ -35,13 +35,22 @@
         DXGI_FORMAT_R8G8B8A8_UNORM_SRGB => DXGI_FORMAT_BC3_UNORM_SRGB,
         _ => return None,
     };
-    if !source_shape(native)
-        || view.ViewDimension != D3D12_SRV_DIMENSION_TEXTURE2D
-    {
+    if !source_shape(native) {
         return None;
     }
+    let plane = match view.ViewDimension {
+        D3D12_SRV_DIMENSION_TEXTURE2D => unsafe { view.Anonymous.Texture2D.PlaneSlice },
+        D3D12_SRV_DIMENSION_TEXTURE2DARRAY => {
+            let array = unsafe { view.Anonymous.Texture2DArray };
+            if array.FirstArraySlice != 0 || array.ArraySize != 1 {
+                return None;
+            }
+            array.PlaneSlice
+        }
+        _ => return None,
+    };
     let view_format = super::device_x::pc_view_format(view.Format.0 as u32);
-    if view_format != native.Format.0 as u32 || unsafe { view.Anonymous.Texture2D.PlaneSlice } != 0 {
+    if view_format != native.Format.0 as u32 || plane != 0 {
         return None;
     }
     Some(D3D12_SHADER_RESOURCE_VIEW_DESC { Format: format, ..*view })
<!-- greyfinch-sync:ivall/xcl:comment:7251062570 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7251062570). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T05:07:16Z. --- I tested a narrow eligibility change on 49121f46 for the mixed-view case above. For a resource already passing the single-layer private RGBA8 checks, accept a Texture2DArray SRV only when FirstArraySlice=0, ArraySize=1 and PlaneSlice=0. The guest's SRV dimension and mip fields remain intact. Both view types then find the same BC3 backing through the existing resource key. Four fresh RTX 5070 processes exercised the production by-address handler, descriptor tracking, texture refresh and native shader loads. With compression off, both creation orders retained one 4 MiB RGBA8 allocation. With BC3 on, both orders retained one 1 MiB BC3 allocation, versus two allocations totaling 5 MiB on the unmodified head. Recreating either view preserved its resource identity. Both views read the expected red and green samples in all four processes. For this controlled pair, the 4 MiB → 1 MiB log now matches the combined allocation requirements. Other fallback view types and actual in-world DXGI residency remain outside this result. Full production diff below. OpenAI Codex implemented the change and ran the existing synthetic native fixture with updated expectations. ```diff --- a/crates/xcl/src/hle/d3d12x/texture_compression.rs +++ b/crates/xcl/src/hle/d3d12x/texture_compression.rs @@ -35,13 +35,22 @@ DXGI_FORMAT_R8G8B8A8_UNORM_SRGB => DXGI_FORMAT_BC3_UNORM_SRGB, _ => return None, }; - if !source_shape(native) - || view.ViewDimension != D3D12_SRV_DIMENSION_TEXTURE2D - { + if !source_shape(native) { return None; } + let plane = match view.ViewDimension { + D3D12_SRV_DIMENSION_TEXTURE2D => unsafe { view.Anonymous.Texture2D.PlaneSlice }, + D3D12_SRV_DIMENSION_TEXTURE2DARRAY => { + let array = unsafe { view.Anonymous.Texture2DArray }; + if array.FirstArraySlice != 0 || array.ArraySize != 1 { + return None; + } + array.PlaneSlice + } + _ => return None, + }; let view_format = super::device_x::pc_view_format(view.Format.0 as u32); - if view_format != native.Format.0 as u32 || unsafe { view.Anonymous.Texture2D.PlaneSlice } != 0 { + if view_format != native.Format.0 as u32 || plane != 0 { return None; } Some(D3D12_SHADER_RESOURCE_VIEW_DESC { Format: format, ..*view }) ```
Foniass commented 2026-12-01 04:47:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:47:56Z.


Review (head 49121f46, diff read, not a merge-check; draft, so not built or run):

  • Scope: 705 lines mixing three things: the encoder (including a BC1 encoder the runtime never uses, kept with #[allow(dead_code)] at block_compression.rs ~147-148 for a benchmark that isn't in the repo), the BC3 backing, and the XCL_TEXTURE_COMPRESSION_OBJECTS census (diagnostics, its own PR).
  • CPU cost isn't measured. plan_compressed (texture_upload.rs ~449) runs on the thread that calls texture_upload::submit, not the worker pool (work_of skips compressed pieces), and it ignores it.changed: one changed page copies the whole texture and re-encodes every mip. Timing a 2048x2048 texture in each quality mode would show what titles pay.
  • Lossy on every eligible texture. Every RGBA8 texture that qualifies is compressed whatever it holds (lookup tables, packed data, UI atlases); worth documenting next to the switch.
  • An unrecognised XCL_TEXTURE_COMPRESSION_QUALITY turns the whole feature off with only an "unrecognized" warning (texture_compression.rs ~21-24).
  • Nothing tests for_view, the BC3 dispatch in plan_item (~513), or the source_hashes write in fill_hashed (the refresh test calls plan_compressed directly with known: None). The memory saving isn't shown yet (448 KiB across two allocations, same DXGI peak), as the PR says.

Fine: off by default with negligible default-path cost (a cached env check per SRV and a field check in uploads); the BC1 / BC3 block encoding is right (c0 > c1 four-colour mode, 8-alpha mode, edge pixels replicated); textures with RT / UAV flags, arrays, MSAA, shared pages, and allocations that wouldn't shrink are excluded; footprints are checked; page hashes come from the exact bytes encoded; no new dependency; AI use names the model. Please confirm the encoder isn't adapted from another project (otherwise it needs a provenance note and a THIRD_PARTY entry).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7301111930 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7301111930). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:47:56Z. --- Review (head 49121f46, diff read, not a merge-check; draft, so not built or run): - **Scope:** 705 lines mixing three things: the encoder (including a BC1 encoder the runtime never uses, kept with `#[allow(dead_code)]` at `block_compression.rs` ~147-148 for a benchmark that isn't in the repo), the BC3 backing, and the `XCL_TEXTURE_COMPRESSION_OBJECTS` census (diagnostics, its own PR). - **CPU cost isn't measured.** `plan_compressed` (`texture_upload.rs` ~449) runs on the thread that calls `texture_upload::submit`, not the worker pool (`work_of` skips compressed pieces), and it ignores `it.changed`: one changed page copies the whole texture and re-encodes every mip. Timing a 2048x2048 texture in each quality mode would show what titles pay. - **Lossy on every eligible texture.** Every RGBA8 texture that qualifies is compressed whatever it holds (lookup tables, packed data, UI atlases); worth documenting next to the switch. - An unrecognised `XCL_TEXTURE_COMPRESSION_QUALITY` turns the whole feature off with only an "unrecognized" warning (`texture_compression.rs` ~21-24). - Nothing tests `for_view`, the BC3 dispatch in `plan_item` (~513), or the `source_hashes` write in `fill_hashed` (the refresh test calls `plan_compressed` directly with `known: None`). The memory saving isn't shown yet (448 KiB across two allocations, same DXGI peak), as the PR says. Fine: off by default with negligible default-path cost (a cached env check per SRV and a field check in uploads); the BC1 / BC3 block encoding is right (c0 > c1 four-colour mode, 8-alpha mode, edge pixels replicated); textures with RT / UAV flags, arrays, MSAA, shared pages, and allocations that wouldn't shrink are excluded; footprints are checked; page hashes come from the exact bytes encoded; no new dependency; AI use names the model. Please confirm the encoder isn't adapted from another project (otherwise it needs a provenance note and a THIRD_PARTY entry). AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 16:38:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T16:38:41Z.


Test report (not a merge-check: draft)
base: b2b1f109d2
head: 49121f4626
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7301111930, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed, its new tests included); the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7317952364 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7317952364). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T16:38:41Z. --- Test report (not a merge-check: draft) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: 49121f46267a2991ca8bf1090289035089866f03 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3256#issuecomment-7301111930, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main. performance: no smoke run. assessment: merges, builds and passes the whole suite on current main (0 failed, its new tests included); the findings in my review stand hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3256:upstream-pr/3256'
git switch 'upstream-pr/3256'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3256'
git switch 'upstream-pr/3256'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3256'
git switch 'upstream-pr/3256'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3256'
git switch 'main'
git merge --squash 'upstream-pr/3256'
git switch 'main'
git merge --ff-only 'upstream-pr/3256'
git switch 'main'
git merge 'upstream-pr/3256'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3256
No description provided.