D3D12.X: Add opt-in BC3 backing for private sampled textures #3256
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3256"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
cargo build --release -p xcl. Use that same executable for all four runs.XCL_VRAM_ARENAS=1in all four runs only if that configuration still reaches the world. If it blocks progress, please report where it stops.XCL_TEXTURE_COMPRESSION_QUALITY=balancedfor both arms and warm each arm's shader cache before recording. Run OFF → ON → OFF → ON, restarting the title for each run. SetXCL_TEXTURE_COMPRESSION=0for OFF andXCL_TEXTURE_COMPRESSION=bc3for ON. Use the same save and repeat the same route and measurement window.BC3 texture atlog 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.rsadds 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.rsand the SRV-by-address hook select private BC3 backing withXCL_TEXTURE_COMPRESSION=bc3.XCL_TEXTURE_COMPRESSION_QUALITY=fast|balanced|highselects the fit, with balanced as the default when enabled.hle/d3d12x/texture_upload.rsencodes 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.XCL_TEXTURE_COMPRESSION_OBJECTS=1census records candidate shapes seen by the SRV-by-object hook. These resources keep their native backing.Tested
cargo test --workspace --no-fail-fast -j 6 -- --test-threads=4 --nocapturein debug: 2,618 reported passed, 0 failed, 49 ignored across 41 groups. The log includes 30SKIPPEDmarkers 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.49121f46, 90 seconds without input. Both arms usedXCL_PREPARE=0,XCL_VRAM_ARENAS=1(independent backing),XCL_TEXTURE_LEVEL_PAGES=1,XCL_TEXTURE_COMPRESSION_OBJECTS=1,XCL_TEXTURE_COMPRESSION_QUALITY=balancedandXCL_FRAME_DUMP=300. OnlyXCL_TEXTURE_COMPRESSIONchanged (0/bc3). Both showed the profile selector and exited cleanly. The BC3 arm logged two eligible allocations beforeXUserAddAsync, totaling 192 KiB versus 640 KiB in the native format (448 KiB less byGetResourceAllocationInfo). 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.The first main run reached
XUserAddAsyncat 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.Not tested
AI use
AI use: Codex (gpt-6.2-sol) for implementation, tests, analysis and drafting.
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) withcargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4:gpu::block_compressiontests pass, includingblock_compress_quality_preserves_bc3_alpha_and_block_size,bc3_stores_alpha_endpoints_and_interpolated_indices, and the balanced/high endpoint tests.hle::d3d12x::bind::tests::gpu_two_pass_indirect_commands_keep_their_own_recordsandfailed_binding_keeps_indirect_commands_until_allocator_reset; the log showserror: 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 specificXCL_D3D12_DIR/XCL_DXC_DIRif that helps.test_title_runs_and_game_folder_is_untouchedfails 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.
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.
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_xfor 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.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, calledGetResourceAllocationInfofor 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.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T05:07:16Z.
I tested a narrow eligibility change on
49121f46for 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.
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):#[allow(dead_code)]atblock_compression.rs~147-148 for a benchmark that isn't in the repo), the BC3 backing, and theXCL_TEXTURE_COMPRESSION_OBJECTScensus (diagnostics, its own PR).plan_compressed(texture_upload.rs~449) runs on the thread that callstexture_upload::submit, not the worker pool (work_ofskips compressed pieces), and it ignoresit.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.XCL_TEXTURE_COMPRESSION_QUALITYturns the whole feature off with only an "unrecognized" warning (texture_compression.rs~21-24).for_view, the BC3 dispatch inplan_item(~513), or thesource_hasheswrite infill_hashed(the refresh test callsplan_compresseddirectly withknown: 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T16:38:41Z.
Test report (not a merge-check: draft)
base:
b2b1f109d2head:
49121f4626merge: 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.