d3d12_xs: R9G9B9E5 UAV textures stored as RGBA16F on hosts without typed UAV for that format (core: creation and views) #277
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!277
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-277"
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?
@QuentinDanblon on GitHub · 2026-11-23 10:53 UTC · original
pr/uav-rgb9e5-core→main· +2158 −28 · 8 files · 2 commits · closed without mergingLibrary / area:
d3d12_xs: resource creation (device_wrap.rsslots 27, 29, 44), view creation, copies on the Xbox command list (slots 16, 17, 83, 84),upload.rsmirroring. Newuav_subst.rs,uav_subst_copy.rs,uav_subst_hw.rs.Exports changed (exports.txt rows): none
Source of the behaviour:
7539ae8b), read only:Kits/FidelityFX/backend/dx12/ffx_dx12.cppmapsFFX_API_SURFACE_FORMAT_R9G9B9E5_SHAREDEXPone to one toDXGI_FORMAT_R9G9B9E5_SHAREDEXPand UAV usage toALLOW_UNORDERED_ACCESS(line 715). No code taken.d3d12_xs.dll. No string in it names R9G9B9E5, so which resource asks for the format is not established. No file of the title is in this PR.CheckFeatureSupport(FORMAT_SUPPORT): RTX 5090Support1 = 0x8013f0for format 67, no typed UAV,CreateCommittedResourcereturnsE_INVALIDARG. WARP:0x2ecd3f1, accepted.EXT_texture_shared_exponentspecification (N=9, B=15, Emax=31, max 65408, negatives and NaN to 0, round to nearest, half up). No code taken from any project.Two commits: the core (creation and views), then the conversion that replaces the copy and upload refusals of the first version.
Commit 1: creation and views
A 1D/2D/3D texture in format 67 with
ALLOW_UNORDERED_ACCESS, one sample, no RT or DS flag, is stored asR16G16B16A16_FLOATwhen the device that creates it reports no typed UAV for format 67. Unknown support never substitutes. On a host with native support (WARP) nothing changes.R16G16B16A16_FLOATholds every RGB9E5 texel exactly:rgb9e5_channels_are_exact_f16checks all 16384 channel values.CreateCommittedResource(slot 27, also reached from 76 and 83): decided afterdepth_uav, then throughres_pool::try_createwith the substituted desc.CreatePlacedResource(slot 29): the substituted texture is twice the console layout reserved at that heap offset, so it is created committed with the heap's properties, the fallbackalias::committed_when_too_bigalready uses.CreatePlacedResourceX(slot 44): the substituted desc goes throughalias::create_placed_x;gpu_vaandplacedkeep the console desc, because the title's memory holds console texels.E_FAIL.R16G16B16A16_FLOAT. An SRV with formatUNKNOWNor a null desc gets an explicit view. SRV swizzles that read source alpha are forced to 1. Views in any other format are forwarded unchanged.Commit 2: copies and uploads convert
CopyTextureRegion/CopyBufferRegion, in the states the title set.CopyBufferRegionruns, so bytes between rows and outside the box are never written.cl2_state::reapply, asdepth_uavdoes. Predication is not touched.CopyResource(17) andCopyResourceX(84) between a substituted and an R9G9B9E5 texture with the same dimensions and mips: converted subresource by subresource. Slot 84 flags go through the existingcopy_resource_x_planvalidation first.upload.rsmirrors title memory into a substituted texture: the detiler widens each RGB9E5 texel to RGBA16F while writing the host layout (widen_span), and host-side sizes use 8 bytes per texel.note_gpu_writeis called on the destination.Still refused (logged and counted, nothing copied)
These calls return void, so the title is not told. I list them so you can say which ones you want handled another way.
CopyResourcewith a buffer on one side or with mismatched dimensions, mips or array size,CopyResourceXwhose flags fail the console validation. As far as I know none of these is a valid copy for an R9G9B9E5 texture on the console either.upload.rs: a substitute other than RGBA16F, or an XG element size other than 4 bytes.Not covered, not claimed
GetDescon a substituted texture returns the host format.GetResourceAllocationInfoanswers with the console layout. The view hook covers at most four device method tables.device_wrap.rsis not re-checked against #239 yet: #239 is still open. I will rebase and re-check when it lands.Tests
Base
f89e410, RTX 5090 PC, Windows 11, and WARP (TOMBOX_HW_ADAPTER=warp).Unit,
cargo test -p d3d12_xs --release --lib: 21 tests matchinguav_subst/rgb9e5pass, among themdecode_matches_the_exact_value_of_every_channel(all 16384 channel values and 100000 random words), the copy and resource-copy rule tables, scratch layout and run merging,rgb9e5_texels_are_widened_to_rgba16f_while_detiling.upload: 15 pass.Hardware. WARP binds R9G9B9E5 as a typed UAV, so a test-only flag (
FORCE_NO_TYPED_UAV) clears that bit and the conversion path runs there too.hw_rgb9e5_copies_out_of_a_substituted_texture_are_encoded_bit_exact: 256x256 texels covering every f16 value per channel; whole footprint, boxed slot 83 copy with untouched padding, texture copy,CopyResource,CopyResourceX, compared bit-exact with a reference written in the test from the specification.hw_rgb9e5_copies_into_a_substituted_texture_are_decoded_exact: every mantissa and exponent; footprint, boxed footprint with a marker kept outside the box, texture via slot 83,CopyResource.hw_rgb9e5_conversions_on_a_copy_queue_list_are_refused.hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_textureneeds anxg_xs.dllon the search path. With the workspace's own one (cargo build --release -p xg_xs,target/releaseonPATH): 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice (first upload, then after a CPU rewrite, no write lost). The layout there comes from the workspace'sxg_xs, not a console DLL.Mutations: dropping the half-up rounding term in the HLSL encode makes the encode test fail on WARP (33027 of 65536 texels differ); moving the subnormal bound in
rgb9e5_halfmakes the exact decode unit test fail. Both restored.hw_uav_subst_view_hook_cost_per_call(commit 1): best of 9 rounds of 100000 calls, tens of nanoseconds per view at most, run-to-run noise larger than the hook's cost.pr_gate.py --base origin/main: 0 problems.cargo test -p d3d12_xspasses for what is listed aboveNo game or console files and no binaries included
No fake success: the copies and uploads that were refused now convert; what is still refused is listed above, with a log line and a counter
🤖 Generated with Claude Code
The previous commit stores an R9G9B9E5 UAV texture as R16G16B16A16_FLOAT when the host has no typed UAV for R9G9B9E5, and refused every copy and every upload that touched it. This commit converts where the console meaning is defined. Conversion (uav_subst_copy.rs): - Copies on the Xbox command list (slots 16, 17, 83, 84) are staged through a DEFAULT-heap scratch buffer. Title resources are only read or written by CopyTextureRegion/CopyBufferRegion, in the states the title set. The scratch goes COMMON, COPY_DEST, UNORDERED_ACCESS, COPY_SOURCE, COMMON. - A cs_6_0 shader compiled with DXC, with an embedded root signature (9 root constants and one root UAV), converts the scratch in place in raw-buffer form: decode reads 4-byte RGB9E5 words and writes 8-byte RGBA16F texels, encode the reverse. - Copy-out to a footprint writes merged per-row CopyBufferRegion runs, so bytes between rows and outside the box are never written. - After the pass, the title's root signature, PSO, root arguments and descriptor heaps are restored with cl2_state::reapply, the same path depth_uav uses. Predication is not touched. - One scratch buffer per list origin, grown by powers of two from 64 KiB. A replaced scratch is kept alive, never freed, because a list already recorded may still reference it. - Every converted copy is logged and counted; note_gpu_write is called on the destination. Encode follows the Khronos EXT_texture_shared_exponent specification (N=9, B=15, Emax=31, sharedexp_max=65408, negative and NaN clamp to 0, round to nearest with half up), computed with exact integer arithmetic on the f16 bits. Decode builds the exact f16 value with integer arithmetic (rgb9e5_half, rgb9e5_to_rgba16f), alpha 1.0. No code was taken from any other project. What each former refusal became: - Copy out of a substituted texture into an R9G9B9E5 footprint or an unsubstituted R9G9B9E5 texture (slots 16 and 83): encoded. - Copy into a substituted texture from an R9G9B9E5 footprint or an unsubstituted R9G9B9E5 texture (slots 16 and 83): decoded. - Substituted to substituted with the same host format: forwarded unchanged, the bytes are already the same representation. - CopyResource (slot 17) and CopyResourceX (slot 84) between a substituted and an R9G9B9E5 texture with the same dimensions and mips: converted subresource by subresource. Slot 84 flags first go through the existing copy_resource_x_plan validation. - upload.rs mirroring of title memory into a substituted texture: no longer refused. The detiler widens each RGB9E5 texel to RGBA16F while writing the host layout (widen_span), and all host-side sizes use 8 bytes per texel. Still refused, logged and counted (nothing copied): - Conversion on a copy-queue list: the pass needs a compute dispatch. - Copies whose other side is not R9G9B9E5, for example an RGBA16F footprint: the console has no such copy for an R9G9B9E5 texture. - Copies between different substitutes. - CopyResource with a buffer on one side, or with mismatched dimensions, mips or array size. - CopyResourceX whose flags fail the console validation. - DXC, PSO, root signature or scratch creation failure, a region past 32-bit scratch size, or depth over 65535. - upload.rs: a substitute other than RGBA16F for RGB9E5, or an XG element size other than 4 bytes. - Textures in CPU-visible heaps are still not substituted. Limitations: - The scratch is per list origin; a list executed on two queues at once would share it. - Slot 83 flags are ignored, as the chain bottom already does. - Non-canonical RGB9E5 words (a value with several encodings) come back canonical after a decode and encode round trip: the value is exact, the bits may differ. - Console hardware rounding for its own RGB9E5 UAV stores is not known; this encode is the specification's. Tests: - Unit: 21 tests matching uav_subst/rgb9e5 pass, among them decode_matches_the_exact_value_of_every_channel (all 16384 channel values and 100000 random words), copy and resource-copy rule tables, scratch layout and run merging, and rgb9e5_texels_are_widened_to_rgba16f_while_detiling. upload: 15 pass. - Hardware, run on WARP (TOMBOX_HW_ADAPTER=warp) and on the RTX 5090. WARP binds R9G9B9E5 as a typed UAV, so a test-only flag (FORCE_NO_TYPED_UAV) clears that bit and the conversion path runs there too. - hw_rgb9e5_copies_out_of_a_substituted_texture_are_encoded_bit_exact: 256x256 texels covering every f16 value per channel; whole footprint, boxed slot 83 copy with untouched padding, texture copy, CopyResource and CopyResourceX, compared bit-exact with a reference written in the test from the specification. - hw_rgb9e5_copies_into_a_substituted_texture_are_decoded_exact: every mantissa and exponent; footprint, boxed footprint with a marker kept outside the box, texture via slot 83, CopyResource. - hw_rgb9e5_conversions_on_a_copy_queue_list_are_refused. - The three tests from the previous commit, adjusted: the slot 16 copy to an R9G9B9E5 footprint is checked bit-exact, the RGBA16F footprint copy is refused. 6 of 7 pass on WARP and 6 of 7 on the RTX 5090. hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture needs xg_xs.dll, which this machine does not have; it fails at load on both, as the existing upload_ww_hw tests do here. The upload path is covered only by the unit test. - Mutation checks: dropping the half-up rounding term in the HLSL encode made the encode test fail on WARP (33027 of 65536 texels differ); changing the subnormal bound in rgb9e5_half made the exact decode unit test fail. Both restored. Co-Authored-By: Claude Opus 5.5 <[email protected]>@omonkeyz on GitHub · 2026-11-23 13:31 UTC · original
Review, changes needed: (1) the commit message cites a GPL-2.0 project; that code can't come into a GPL-3 tree, and the name must not be in the history, so please reword it. (2) Copies on slots 16/17/83/84 that touch a substituted texture, and title-memory mirroring into it, are refused. Those calls return void, so the title sees success while the data never moves. That is accept-and-drop, which the project rules out. Copies and uploads need a real RGB9E5<->RGBA16F conversion. Also re-check device_wrap.rs once #239 lands.
@QuentinDanblon on GitHub · 2026-11-23 13:58 UTC · original
Thanks for the review, both points are fair. As I said on #279, I've stopped writing code and PRs for now, so I won't make these changes. Feel free to close this PR, or leave it open if someone wants to take it over. Since its commit is only on this branch, closing it keeps that name out of the history.
@QuentinDanblon on GitHub · 2026-11-23 17:30 UTC · original
Correction to my earlier reply: I picked this back up, so please disregard "I won't make these changes". Both points of your review are addressed in the force-pushed branch (
7fff05a, basef89e410):git log origin/main..has no match). The source for the format is now the FidelityFX SDK (MIT) DX12 backend, facts only.upload.rswidens each texel while detiling. Hardware tests pass on WARP and the RTX 5090; the upload one needsxg_xs.dllhere, so that path is covered by a unit test only.What is still refused, since those calls return void too:
Closeinstead, or run the pass on a compute list of our own.CopyResourceshapes,CopyResourceXflags that fail the console validation. As far as I know these are not valid copies for an R9G9B9E5 texture on the console either.#239 is still open, so
device_wrap.rsis not re-checked against it yet. I will rebase and re-check when it lands. The PR body has the full list of what is done, refused and not claimed.@QuentinDanblon on GitHub · 2026-11-23 18:07 UTC · original
Update on the one hardware test I could not run:
hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_textureonly needs anxg_xs.dllon the search path, and the workspace builds one. Withcargo build --release -p xg_xsandtarget/releaseonPATH, it passes on the RTX 5090 and on WARP: 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice, no CPU write lost. So 7 of 7 hardware tests pass on both. The layout in that run comes from the workspace xg_xs, not a console DLL. PR body updated.@omonkeyz on GitHub · 2026-11-25 13:51 UTC · original
Thanks, the conversion work looks right and the history is clean now. One drop is left: a copy on a copy-queue list that needs conversion is refused while the void call reports nothing. Please take one of the two options you offered, either running the pass on an internal compute list and syncing the copy queue to it, or failing the list at Close with the reason logged. Then it can be applied.
Pull request closed