gpu: create 16-bit packed targets the adapter cannot use as R8G8B8A8 #1285
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1292"
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 R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T06:59:56Z.
Refs #870, #874.
Problem
A console executable creates B5G5R5A1_UNORM and B4G4R4A4_UNORM textures as render targets and for unordered access. The startup device wrapper passes those descriptions to desktop unchanged. On an adapter without that use for the packed format the description is refused:
GetResourceAllocationInfoanswers all ones (the wrapper logsinvalid desc[0]=...);null_texture_view.halready handles the same two formats, but only for views with no resource.Change
src/startup_stubs/packed_target_format.h:packed_target_stand_inreturns R8G8B8A8_UNORM for a B5G5R5A1/B4G4R4A4 texture description that asks for render-target or unordered-access use the adapter lacks, provided R8G8B8A8_UNORM has that use. Otherwise it returns the format unchanged.packed_view_formatmakes a view that names a packed format on such a texture use R8G8B8A8_UNORM.sanitized()applies the first after the console-format mapping, withCheckFeatureSupportas the support query; the view slots apply the second. The first four stand-ins are logged as a shortcut.Not converted: texel data the executable writes itself in the packed layout. The two textures seen here are 2560 x 1440 targets that are only drawn to.
Evidence
Commit under test: the head of this branch, on
mainat93cb6a2a.Device-free check (
tests/startup_packed_target_check.cpp, registered asstartup_packed_target), which drives the selection with adapters described by theirD3D12_FORMAT_SUPPORT1bits:The controls inside it: an adapter that supports both packed formats changes nothing; an adapter with render-target but no typed-UAV support changes RT|UAV and leaves RT alone; no stand-in is chosen when R8G8B8A8_UNORM lacks the use too, when no RT/UAV use is asked, for B5G6R5 and for buffers; a packed view of a texture that is not a stand-in keeps its format.
Whole-program run. One console executable under the startup debugger, offline; Linux host, Wine with vkd3d-proton, NVIDIA RTX 4070 Ti SUPER. Measured with a local build that has the same selection inline (not this branch's header):
invalid desclines.invalid descline is logged, and the run continues.This change alone did not move where that run stopped; the stop was the allocation sizes in #1290.
Also ran
python -B tests/docs_links_check.py(pass) andgit diff --check(clean).Not measured
d3d12_xs_device.cppwas syntax-checked the same way; CI is the first MSVC build.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:03:54Z.
Review: COMMENTED
Dual-platform review at commit
64985368cf97b7ba0ef8aca8e9d7f77869679959:Linux checks
git diff --check origin/main...HEAD: passedpython -B tests/docs_links_check.py: passed (16 Markdown files, 286 links)python -B tests/bidi_controls_check.py: passed (1081 tracked files)Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)
--preset dev):cmake --build --preset dev --target startup_packed_target_check -- -j 6:3.72sctest --preset dev -R '^startup_packed_target$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed/O2(--preset release):cmake --build --preset release --target startup_packed_target_check -- -j 6:1.13sctest --preset release -R '^startup_packed_target$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passedNotes & Edge Cases
src/startup_stubs/packed_target_format.hcleanly restricts theR8G8B8A8_UNORMstand-in toB5G5R5A1_UNORMandB4G4R4A4_UNORMtextures requestingALLOW_RENDER_TARGETorALLOW_UNORDERED_ACCESSwhen the adapter lacks those support bits whileR8G8B8A8_UNORMhas them, leaving buffers, sampled-only textures, and supported adapters untouched.src/startup_stubs/d3d12_xs_device.cpp, bothsanitized()(used for allocation info and resource creation) andview_slot()(slots 18–21) are wired consistently, andDXGI_FORMAT_UNKNOWNview descriptors continue to inherit the stand-in resource'sR8G8B8A8_UNORMformat.startup_packed_target_checktestspacked_target_format.hstandalone against mock support-bit adapters;d3d12_xs_device.cppitself was reviewed by inspection and not compiled in this targeted run.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:26:16Z.
Review: CHANGES_REQUESTED
The view fallback currently decides from the requested and desktop formats alone. That also rewrites a packed view requested on an ordinary RGBA8 resource, even though the resource was never substituted. Please carry explicit substitution provenance on the resource, refuse mismatched packed views, and narrow the first path to the demonstrated 2D target roles. The device-free matrix alone cannot show view/creation behavior. Please add a source-built Windows resource, view and draw/readback comparison, including a plain RGBA8 resource and a supported packed format as controls. Describe quantization and CPU-authored texture limits explicitly.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T09:47:26Z.
All five points are addressed in
9845a1a8. The fixture you asked for also found a bug in the PR, described under "Draw path".Provenance. A stand-in texture now carries the format it was asked for as private data on the desktop resource (
mark_packed_stand_in/packed_stand_in_of), set at each place a texture is created from a sanitized description. The view decision no longer looks at formats alone.Views.
packed_view(view format, resource format, stands in for)gives one of three verdicts:Draw path. The translated draw path builds its own shader-resource view from the recorded description, and it still named the packed format on a stand-in texture. The first run of the new fixture read garbage instead of the clear colour because of it. That path now applies the same verdict, and binds a null texture for a refused view.
Narrowed rule. Only what was measured: a single-sample 2D texture with one array slice that is a render target, alone or with unordered access. 1D and 3D textures, arrays, multisampled textures, and unordered access without the render-target flag keep their format (new unit cases for each).
Windows fixture.
tests/startup_packed_target_draw_check.py(startup_packed_target_draw_warp/_hardware) goes through the wrapper for each case: slot 133 creates a 64x64 texture, a render-target view clears it to (0.45, 0.2, 0.8, 1), a shader-resource view samples it in a full-target draw, and every pixel of that draw is read back. The consumer reports the adapter's support bits and the format the helper selects, so the expected pixel follows the path the adapter takes:Controls: B5G6R5_UNORM (a packed format outside the rule) and R8G8B8A8_UNORM are drawn and must never be substituted or logged as stand-ins. B5G5R5A1 views of a plain R8G8B8A8_UNORM texture, and of a B4G4R4A4 target, must both be refused (render-target view and shader-resource view), the draw must bind null, and the clear colour must not appear.
Limits, now stated in the header and
docs/startup-runtime.md: the stand-in keeps 8 bits where the packed formats keep 5, 4 or 1, so rendered values are not quantized (0.45 reads 115 here, 119 from B4G4R4A4); texel data the executable writes or reads itself in the 16-bit layout is not converted; unordered-access writes to a stand-in have no fixture.Results here (clang-cl build under Wine 11.0 with vkd3d-proton, RTX 4070 Ti SUPER; translation-layer,
hardwareonly):The existing
startup_xg_bc7_drawandstartup_stream_drawchecks still pass on the same build.Not verified: Windows and WARP. On an adapter that supports the packed formats as render targets the fixture takes the "as described" branch and expects the quantized pixels above; that branch has not run anywhere yet, so CI on WARP will be its first run, and the 5- and 4-bit expectations there are computed, not measured. Here the shaders were compiled with fxc in place of DXC.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:05:47Z.
Review: COMMENTED
Technical peer-review (retest) of commit
9845a1a80069fece03bae20c5c2a71b1867dce87:Verification
git diff --check origin/main...HEAD: clean.tests/docs_links_check.py: passed (16 Markdown files, 308 links).tests/bidi_controls_check.py: passed (1,156 files).python -B -m py_compile tests/startup_packed_target_draw_check.py: passed.--preset dev): targets built (24.35s, configure1.66s);ctest -R '^(startup_packed_target|startup_packed_target_draw_warp|startup_stream_draw_warp|startup_stubs)$'4/4 passed (1.67s:startup_packed_target0.01s,startup_stubs0.53s,startup_packed_target_draw_warp0.74s,startup_stream_draw_warp1.59s)./O2(--preset release): targets built (35.85s, configure1.60s);ctest4/4 passed (1.77s:startup_packed_target0.02s,startup_stubs0.38s,startup_packed_target_draw_warp0.69s,startup_stream_draw_warp1.71s).Findings
SetPrivateData(packed_stand_in_tag, ...)acrosscreate_slot,device_place_resource_x,device_create_committed_x, andsampled_address_texture.packed_target_stand_inis narrowed to single-sample 2DALLOW_RENDER_TARGET(with optionalALLOW_UNORDERED_ACCESS, excludingALLOW_DEPTH_STENCIL).packed_viewrefuses mismatched packed views (including packed views on plainR8G8B8A8_UNORMor on the other packed format's stand-in) in bothview_slotanddraw_translated.startup_packed_target(device-free matrix: 3 stand-ins, 13 unchanged, 9 view verdicts) andstartup_packed_target_draw_warp(source-built D3D12 resource/view/draw/readback withB5G6R5_UNORMandR8G8B8A8_UNORMcontrols plus refused-view pairs) pass, anddocs/startup-runtime.mddocuments quantization and CPU-authored texel limits.src/startup_stubs/d3d12_xs_device.cpp,view_slot):view_slot<17, 1>(CreateConstantBufferView) andview_slot<22, 1>(CreateSampler) havedesc_index == 1, whereargs[0]is the descriptor pointer rather than anID3D12Resource*anddesc_copystarts withBufferLocation/Filterrather thanDXGI_FORMAT. Guarding the packed-view check withdesc_index >= 2(slots 18–21) would preventargs[0]from ever being cast toID3D12Resource*if the low 32 bits of aBufferLocationever equalled86or115.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:10:09Z.
Review: APPROVED
Reviewed the resource provenance tag, refused mismatched views and the exact endpoint for the B5G6R5 control. The Windows hardware and WARP draw results address the original review.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:07:06Z.
On RTX 4060 Laptop (32.0.16.1656), both substituted targets and the previous draw tests passed, but the ordinary B5G6R5 control read green 48 where the fixture expected 53. WARP passed. I pushed
5e94fe47so the six-bit green channel uses an exact endpoint, with red and blue still distinguishing the packed formats from RGBA8. The five Release cases now pass on WARP and RTX, including the two refused view pairs. GitHub checks are running on the new head.