startup: preserve typed pixel colour exports #1266

Manually merged
github merged 5 commits from gh-pr/1266/head into gh-pr/1266/base 2026-11-26 22:53:42 +00:00
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 06:16 UTC · original
Jess-Doit:translator/startup-1259-mrt → main · +432 −82 · 9 files · 5 commits · merged 2026-11-24 07:43 UTC

Change

Refs #1259. This covers colour exports from gfx2hlsl.

The flat-parameter half of #1259 is #1262. Both change Stage.export() in tools/startup/gfx2hlsl.py, so whichever merges second needs a small merge there. This branch merges cleanly with current main.

  • Use the ordered, bound RTV formats to select a pixel shader variant before desktop PSO creation. The offline cache publishes separate requests for those variants and validates the format tuple before loading a result. The base shader/root inputs remain available for a new format even when the base translation was already cached.
  • Export uncompressed R32_UINT and R32_SINT through uint4 and int4. The other attachment in the fixture keeps its float-to-UNORM conversion. Packed integer exports and wider or narrower integer formats are outside this change.
  • Keep uncompressed binary32 FLOAT outputs typed as float. XOR the raw register word with a private, zero-valued draw constant before the bitcast. FXC can optimize the rest of the shader while the bitcast sees a run-time value. The exact-bit fixture uses an unblended R32G32B32A32_FLOAT target.

Fixture

The source-built wrapped-stream draw reuses one shader and root with UINT and SINT RTVs over typeless storage. The reflected signatures match each RTV. MRT0 reads 80000001 and MRT1 reads RGBA ff0000ff in both variants. A stale SINT manifest at the UINT key is refused before desktop PSO creation and both targets retain their clear values.

For the FLOAT draw, the exact words are 00000001 00000002 7fc00001 80000001. A nonzero control binds 00800000 and reads 00800001 00800002 7f400001 80800001. With the run-time operand removed, optimized FXC reads 00000000 00000000 7fc00001 00000000. FXC /Od and optimized DXC keep the original four words.

Verification

Tested 136ed589 on base 48b31812. Windows 10 22H2 build 19045.6456, MSVC x64 19.44.35230.0, FXC and DXC from Windows SDK 10.0.26100.0.

Adapter Driver
NVIDIA GeForce GTX 1060 6GB 32.0.15.6094
Windows 10 in-box WARP (Microsoft Basic Render Driver) 10.0.19041.5794
Configuration Passed Failed Skipped D3D12 errors D3D12 warnings
Debug 15 0 0 0 0
Release 15 0 0 0 0

Each configuration includes four MRT tests (FXC and DXC on both adapters) and 11 startup, stream, sampler-heap and unsigned-byte vertex-fetch regressions. The docs-link check also passed. Set $python to a venv with requirements-dev.txt installed.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
$env:XBOX2WINDOWS_ADAPTER = '1060'
$env:X2W_D3D12_DEBUG = '1'
$python = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset "-DINTAKE_PYTHON:FILEPATH=$python"
    cmake --build --preset $preset --target startup_stream_consumer offscreen_check startup_stub_consumer startup_stub_acphal startup_stub_xapu startup_stub_xcrdapi startup_stub_gameinput -j 2
    ctest --preset $preset --no-tests=error -R '^startup_(mrt_|stream_|sampler_heap_|r8_uint|stubs$)' -V
}

AI-assisted (Codex).

**@⁠Jess-Doit** on GitHub · 2026-11-24 06:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266) `Jess-Doit:translator/startup-1259-mrt` → `main` · +432 −82 · 9 files · 5 commits · merged 2026-11-24 07:43 UTC ## Change Refs #1259. This covers colour exports from `gfx2hlsl`. The flat-parameter half of #1259 is #1262. Both change `Stage.export()` in `tools/startup/gfx2hlsl.py`, so whichever merges second needs a small merge there. This branch merges cleanly with current `main`. - Use the ordered, bound RTV formats to select a pixel shader variant before desktop PSO creation. The offline cache publishes separate requests for those variants and validates the format tuple before loading a result. The base shader/root inputs remain available for a new format even when the base translation was already cached. - Export uncompressed `R32_UINT` and `R32_SINT` through `uint4` and `int4`. The other attachment in the fixture keeps its float-to-UNORM conversion. Packed integer exports and wider or narrower integer formats are outside this change. - Keep uncompressed binary32 FLOAT outputs typed as float. XOR the raw register word with a private, zero-valued draw constant before the bitcast. FXC can optimize the rest of the shader while the bitcast sees a run-time value. The exact-bit fixture uses an unblended `R32G32B32A32_FLOAT` target. ## Fixture The source-built wrapped-stream draw reuses one shader and root with UINT and SINT RTVs over typeless storage. The reflected signatures match each RTV. MRT0 reads `80000001` and MRT1 reads RGBA `ff0000ff` in both variants. A stale SINT manifest at the UINT key is refused before desktop PSO creation and both targets retain their clear values. For the FLOAT draw, the exact words are `00000001 00000002 7fc00001 80000001`. A nonzero control binds `00800000` and reads `00800001 00800002 7f400001 80800001`. With the run-time operand removed, optimized FXC reads `00000000 00000000 7fc00001 00000000`. FXC `/Od` and optimized DXC keep the original four words. ## Verification Tested `136ed589` on base `48b31812`. Windows 10 22H2 build `19045.6456`, MSVC x64 `19.44.35230.0`, FXC and DXC from Windows SDK `10.0.26100.0`. | Adapter | Driver | |---|---| | NVIDIA GeForce GTX 1060 6GB | `32.0.15.6094` | | Windows 10 in-box WARP (Microsoft Basic Render Driver) | `10.0.19041.5794` | | Configuration | Passed | Failed | Skipped | D3D12 errors | D3D12 warnings | |---|---:|---:|---:|---:|---:| | Debug | 15 | 0 | 0 | 0 | 0 | | Release | 15 | 0 | 0 | 0 | 0 | Each configuration includes four MRT tests (FXC and DXC on both adapters) and 11 startup, stream, sampler-heap and unsigned-byte vertex-fetch regressions. The docs-link check also passed. Set `$python` to a venv with `requirements-dev.txt` installed. ```powershell . .\tools\dev.ps1 $env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0' $env:XBOX2WINDOWS_ADAPTER = '1060' $env:X2W_D3D12_DEBUG = '1' $python = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path foreach ($preset in 'dev', 'release') { cmake --preset $preset "-DINTAKE_PYTHON:FILEPATH=$python" cmake --build --preset $preset --target startup_stream_consumer offscreen_check startup_stub_consumer startup_stub_acphal startup_stub_xapu startup_stub_xcrdapi startup_stub_gameinput -j 2 ctest --preset $preset --no-tests=error -R '^startup_(mrt_|stream_|sampler_heap_|r8_uint|stubs$)' -V } ``` AI-assisted (Codex).
# Conflicts:
#	CMakeLists.txt
#	tests/startup_stream_draw.cpp
# Conflicts:
#	tests/startup_stream_consumer.cpp
#	tests/startup_stream_draw.cpp
# Conflicts:
#	tests/startup_stream_consumer.cpp
#	tests/startup_stream_draw.cpp
#	tests/startup_stream_draw.h
# Conflicts:
#	tests/startup_stream_draw.cpp
#	tools/startup/gfx2hlsl.py
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:53:39 +00:00
github manually merged commit da6ef404e2 into gh-pr/1266/base 2026-11-26 22:53:42 +00:00
Author
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 06:35 UTC · original

Merged current main (943a9ccd) as f93ae14f. There were two conflicts:

  • CMakeLists.txt: both test registrations are kept.
  • tests/startup_stream_draw.cpp: kept both sides. This PR's check_stream_draw(..., format, export_word) signature and per-format targets stay. main's draw_logical_tables and its X2W_TEST_LOGICAL_VIEW branch stay too, after this PR's root-constant write. With no format given, the logical-view path still draws into the 8x4 target.

Retest: Windows 10 22H2 19045.6456, GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094) and in-box WARP (10.0.19041.5794), X2W_D3D12_DEBUG=1, run with:

ctest --preset <dev|release> --no-tests=error -R '^(startup_mrt_|startup_stream_|startup_logical_view_|startup_sampler_heap_|startup_r8_uint)' -V

Debug and Release gave the same result:

  • 14 passed: startup_mrt_{fxc,dxc}_{warp,hardware}, startup_stream_{request_warp,draw_warp,draw_hardware}, startup_sampler_heap_*, startup_r8_uint_*.
  • 1 skipped: startup_logical_view_warp returned 77.
  • 1 failed: startup_logical_view_hardware exits with 34 after physical capacity 1013760, logical count 1245184. It fails the same way on unmodified main 943a9ccd on this GPU, with or without the debug layer, so this merge does not cause it. It looks specific to this host's descriptor-heap limit and needs a separate look.
**@⁠Jess-Doit** on GitHub · 2026-11-24 06:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266#issuecomment-7124087560) Merged current `main` (`943a9ccd`) as `f93ae14f`. There were two conflicts: - `CMakeLists.txt`: both test registrations are kept. - `tests/startup_stream_draw.cpp`: kept both sides. This PR's `check_stream_draw(..., format, export_word)` signature and per-format targets stay. `main`'s `draw_logical_tables` and its `X2W_TEST_LOGICAL_VIEW` branch stay too, after this PR's root-constant write. With no format given, the logical-view path still draws into the 8x4 target. **Retest:** Windows 10 22H2 `19045.6456`, GTX 1060 6 GB (`10de:1c03`, driver `32.0.15.6094`) and in-box WARP (`10.0.19041.5794`), `X2W_D3D12_DEBUG=1`, run with: ``` ctest --preset <dev|release> --no-tests=error -R '^(startup_mrt_|startup_stream_|startup_logical_view_|startup_sampler_heap_|startup_r8_uint)' -V ``` Debug and Release gave the same result: - **14 passed:** `startup_mrt_{fxc,dxc}_{warp,hardware}`, `startup_stream_{request_warp,draw_warp,draw_hardware}`, `startup_sampler_heap_*`, `startup_r8_uint_*`. - **1 skipped:** `startup_logical_view_warp` returned 77. - **1 failed:** `startup_logical_view_hardware` exits with 34 after `physical capacity 1013760, logical count 1245184`. It fails the same way on unmodified `main` `943a9ccd` on this GPU, with or without the debug layer, so this merge does not cause it. It looks specific to this host's descriptor-heap limit and needs a separate look.
Author
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 06:39 UTC · original

Merged main again (3709e10a, after #1260 and #1263) as 3e48d345. This time the conflicts were in tests/startup_stream_draw.cpp and tests/startup_stream_consumer.cpp. check_stream_draw now takes both inputs: (…, const StartupBc7Input* bc7 = nullptr, std::uint32_t format = 0, std::uint32_t export_word = 0) in startup_stream_draw.h.

  • Consumer arguments: the consumer accepts 4, 6, 7, 8 or 10 arguments. It reads a render-target format only with 7 or 8 arguments, and the BC7 input only with 10.
  • Target size: the BC7 dimensions, else 8x4 for the original draw, else 1x1 for this PR's formatted targets.
  • Draw: the scissor is half width only for the original draw. The BC7 table is bound in main's plain-draw branch.

Retest: same host and filter as before, plus startup_xg_bc7_draw_ and startup_address_srv_, with X2W_D3D12_DEBUG=1. Debug and Release gave the same result:

  • 18 passed: startup_mrt_{fxc,dxc}_{warp,hardware}, startup_xg_bc7_draw_{warp,hardware}, startup_address_srv_{warp,hardware}, startup_stream_{request_warp,draw_warp,draw_hardware}, startup_sampler_heap_*, startup_r8_uint_*.
  • 1 skipped: startup_logical_view_warp returned 77.
  • 1 failed: startup_logical_view_hardware exits with 34. It fails the same way on unmodified main on this GTX 1060, as in my previous comment.
**@⁠Jess-Doit** on GitHub · 2026-11-24 06:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266#issuecomment-7124164357) Merged `main` again (`3709e10a`, after #1260 and #1263) as `3e48d345`. This time the conflicts were in `tests/startup_stream_draw.cpp` and `tests/startup_stream_consumer.cpp`. `check_stream_draw` now takes both inputs: `(…, const StartupBc7Input* bc7 = nullptr, std::uint32_t format = 0, std::uint32_t export_word = 0)` in `startup_stream_draw.h`. - **Consumer arguments:** the consumer accepts 4, 6, 7, 8 or 10 arguments. It reads a render-target format only with 7 or 8 arguments, and the BC7 input only with 10. - **Target size:** the BC7 dimensions, else 8x4 for the original draw, else 1x1 for this PR's formatted targets. - **Draw:** the scissor is half width only for the original draw. The BC7 table is bound in `main`'s plain-draw branch. **Retest:** same host and filter as before, plus `startup_xg_bc7_draw_` and `startup_address_srv_`, with `X2W_D3D12_DEBUG=1`. Debug and Release gave the same result: - **18 passed:** `startup_mrt_{fxc,dxc}_{warp,hardware}`, `startup_xg_bc7_draw_{warp,hardware}`, `startup_address_srv_{warp,hardware}`, `startup_stream_{request_warp,draw_warp,draw_hardware}`, `startup_sampler_heap_*`, `startup_r8_uint_*`. - **1 skipped:** `startup_logical_view_warp` returned 77. - **1 failed:** `startup_logical_view_hardware` exits with 34. It fails the same way on unmodified `main` on this GTX 1060, as in my previous comment.
Author
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 07:10 UTC · original

Merged main (9bc96316, after #1273) as 16326d8a. #1273 adds A8/R8 targets and the BC-view mode to check_stream_draw. The signature is now (…, bc7 = nullptr, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM, std::uint32_t export_word = 0).

  • Consumer: with 7 arguments, parent-a8/child-a8/child-r8 still select main's A8/R8 derive path. A number selects this PR's R32 format.
  • Target size: R32_UINT, R32_SINT and R32G32B32A32_FLOAT draw one pixel. All other formats keep main's 8x4, BC7 and BC-view sizes. The clear alpha and readback row size follow main for A8/R8.

Retest: same host and filter as before, plus startup_address_bc_view_. Debug and Release gave the same result: 20 passed, startup_logical_view_warp skipped (77), and startup_logical_view_hardware failed with exit 34. That test fails the same way on unmodified main on this GTX 1060, as noted above.

**@⁠Jess-Doit** on GitHub · 2026-11-24 07:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266#issuecomment-7124697607) Merged `main` (`9bc96316`, after #1273) as `16326d8a`. #1273 adds A8/R8 targets and the BC-view mode to `check_stream_draw`. The signature is now `(…, bc7 = nullptr, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM, std::uint32_t export_word = 0)`. - **Consumer:** with 7 arguments, `parent-a8`/`child-a8`/`child-r8` still select `main`'s A8/R8 derive path. A number selects this PR's R32 format. - **Target size:** R32_UINT, R32_SINT and R32G32B32A32_FLOAT draw one pixel. All other formats keep `main`'s 8x4, BC7 and BC-view sizes. The clear alpha and readback row size follow `main` for A8/R8. **Retest:** same host and filter as before, plus `startup_address_bc_view_`. Debug and Release gave the same result: 20 passed, `startup_logical_view_warp` skipped (77), and `startup_logical_view_hardware` failed with exit 34. That test fails the same way on unmodified `main` on this GTX 1060, as noted above.
Author
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 07:30 UTC · original

Merged main (dc73c29e, after #1262) as da6ef404.

  • tools/startup/gfx2hlsl.py Stage.export(): this PR's uint/int/bits render-target kinds are kept. #1262's flat uint4 copy for param exports is kept as well: words is set in each branch, and param exports are always the float kind. The startup_flat_param_check.py controls pass on the merged translator.
  • tests/startup_stream_draw.cpp: main's 384x32 X2W_TEST_BC_CHAIN size is added. Its draw uses the full width, as on main.

Retest: same host as before, Debug, X2W_D3D12_DEBUG=1. The filter is as before plus startup_xg_bc_chain_ and startup_flat_param_. 25 passed, startup_logical_view_warp skipped (77), and startup_logical_view_hardware failed with exit 34. As noted above, that test fails the same way on unmodified main on this GPU.

**@⁠Jess-Doit** on GitHub · 2026-11-24 07:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266#issuecomment-7125062626) Merged `main` (`dc73c29e`, after #1262) as `da6ef404`. - **`tools/startup/gfx2hlsl.py` `Stage.export()`:** this PR's `uint`/`int`/`bits` render-target kinds are kept. #1262's flat `uint4` copy for `param` exports is kept as well: `words` is set in each branch, and `param` exports are always the float kind. The `startup_flat_param_check.py` controls pass on the merged translator. - **`tests/startup_stream_draw.cpp`:** `main`'s 384x32 `X2W_TEST_BC_CHAIN` size is added. Its draw uses the full width, as on `main`. **Retest:** same host as before, Debug, `X2W_D3D12_DEBUG=1`. The filter is as before plus `startup_xg_bc_chain_` and `startup_flat_param_`. 25 passed, `startup_logical_view_warp` skipped (77), and `startup_logical_view_hardware` failed with exit 34. As noted above, that test fails the same way on unmodified `main` on this GPU.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 06:30 UTC · original · reviewed

Dual-platform review at commit 136ed5898c33507567c0887edc8a42cfc941782e:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: passed
    • python -B tests/docs_links_check.py: passed (16 Markdown files, 283 links)
    • python -B tests/bidi_controls_check.py: passed (1056 files)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target startup_stream_consumer startup_stub_consumer d3d12_xs_shim -- -j 6 + ctest --preset dev -R '^startup_(mrt_(fxc|dxc)_warp|stream_(draw|request)_warp)$' --parallel 4 --no-tests=error --output-on-failure -> 4/4 passed (2.64s: startup_stream_request_warp, startup_stream_draw_warp, startup_mrt_dxc_warp, startup_mrt_fxc_warp)
    • Release /O2 (--preset release): cmake --build --preset release --target startup_stream_consumer startup_stub_consumer d3d12_xs_shim -- -j 6 + ctest --preset release -R '^startup_(mrt_(fxc|dxc)_warp|stream_(draw|request)_warp)$' --parallel 4 --no-tests=error --output-on-failure -> 4/4 passed (2.88s)

Code Notes

  • publish_shader_request in src/startup_stubs/d3d12_draw.inl stages requests via .tmp and MoveFileExW(..., 0), and translate_to in tools/startup/gfx2hlsl.py uses os.replace on .txt, preventing partial reads by the offline scanner or runtime.
  • load_translation strictly validates the rtv1 line against the requested format tuple and rejects stale/mismatched variants before desktop PSO creation.
  • mrtbits in gfx2hlsl.py + d3d12_draw.inl cleanly prevents FXC constant-folding of binary32 denormals/NaNs/negative zero while keeping UINT/SINT exports strictly scoped to verified R32_UINT/R32_SINT formats (and rejecting compr integer exports).
**@⁠tedin7** on GitHub · 2026-11-24 06:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1266#pullrequestreview-6034690781) · **reviewed** Dual-platform review at commit `136ed5898c33507567c0887edc8a42cfc941782e`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: passed - `python -B tests/docs_links_check.py`: passed (16 Markdown files, 283 links) - `python -B tests/bidi_controls_check.py`: passed (1056 files) - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `cmake --build --preset dev --target startup_stream_consumer startup_stub_consumer d3d12_xs_shim -- -j 6` + `ctest --preset dev -R '^startup_(mrt_(fxc|dxc)_warp|stream_(draw|request)_warp)$' --parallel 4 --no-tests=error --output-on-failure` -> **4/4 passed** (`2.64s`: `startup_stream_request_warp`, `startup_stream_draw_warp`, `startup_mrt_dxc_warp`, `startup_mrt_fxc_warp`) - **Release `/O2` (`--preset release`)**: `cmake --build --preset release --target startup_stream_consumer startup_stub_consumer d3d12_xs_shim -- -j 6` + `ctest --preset release -R '^startup_(mrt_(fxc|dxc)_warp|stream_(draw|request)_warp)$' --parallel 4 --no-tests=error --output-on-failure` -> **4/4 passed** (`2.88s`) ### Code Notes - `publish_shader_request` in `src/startup_stubs/d3d12_draw.inl` stages requests via `.tmp` and `MoveFileExW(..., 0)`, and `translate_to` in `tools/startup/gfx2hlsl.py` uses `os.replace` on `.txt`, preventing partial reads by the offline scanner or runtime. - `load_translation` strictly validates the `rtv1` line against the requested format tuple and rejects stale/mismatched variants before desktop PSO creation. - `mrtbits` in `gfx2hlsl.py` + `d3d12_draw.inl` cleanly prevents FXC constant-folding of binary32 denormals/NaNs/negative zero while keeping `UINT`/`SINT` exports strictly scoped to verified `R32_UINT`/`R32_SINT` formats (and rejecting `compr` integer exports).
This discussion has been locked. Commenting is limited to contributors.
No description provided.