Encode formatted-load metadata from recorded typed buffer views #2273

Merged
R0Y00 merged 2 commits from upstream-pr/2281 into main 2026-11-25 10:07:28 +00:00
R0Y00 commented 2026-11-25 09:34:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T09:34:25Z.


Refs #874

Add a source-built, adapter-independent check for the metadata needed by gfx10 formatted loads. The helper reads a D3D12 typed buffer SRV description and encodes FORMAT and the four destination selectors. It takes no address, guesses no format from buffer stride, and refuses raw, structured, texture and malformed descriptions. It can be used by the recorded-view binding follow-up without changing #2138's native V# descriptor path.

Local Windows Release-style check on 28eaad07, using the x64 MSVC environment from tools/dev.ps1 and running from an ignored out/ directory:

cl.exe /nologo /O2 /DNDEBUG /std:c++17 /W4 /EHsc /MT <repo>/tests/startup_typed_buffer_view.cpp /Fe:startup_typed_buffer_view.exe
.\startup_typed_buffer_view.exe

Passed all 13 FORMAT mappings, the swizzle with forced zero and one, and seven refusal controls. The raw and structured controls include a nonempty 8-byte structured record. This PR adds the CTest entry startup_typed_buffer_view. Production binding and GPU bytecode cache integration are outside this helper change.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6601447667 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2281). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T09:34:25Z. --- Refs #874 Add a source-built, adapter-independent check for the metadata needed by gfx10 formatted loads. The helper reads a D3D12 typed buffer SRV description and encodes FORMAT and the four destination selectors. It takes no address, guesses no format from buffer stride, and refuses raw, structured, texture and malformed descriptions. It can be used by the recorded-view binding follow-up without changing #2138's native V# descriptor path. Local Windows Release-style check on 28eaad07, using the x64 MSVC environment from `tools/dev.ps1` and running from an ignored `out/` directory: ```powershell cl.exe /nologo /O2 /DNDEBUG /std:c++17 /W4 /EHsc /MT <repo>/tests/startup_typed_buffer_view.cpp /Fe:startup_typed_buffer_view.exe .\startup_typed_buffer_view.exe ``` Passed all 13 FORMAT mappings, the swizzle with forced zero and one, and seven refusal controls. The raw and structured controls include a nonempty 8-byte structured record. This PR adds the CTest entry `startup_typed_buffer_view`. Production binding and GPU bytecode cache integration are outside this helper change.
tedin7 commented 2026-11-25 09:38:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:38:41Z.

Review: COMMENTED


Review of head 28eaad0790e44d3bea6677dcca2620dac0cfaa2a (comment only, no approval).

Summary: The encoder is correct for what it covers. I found no P1. I found one P2 (a test gap) and two nits.

Checked locally

  • python3 tests/docs_links_check.py: passed (18 files, 435 links).
  • python3 tests/bidi_controls_check.py: passed.
  • git diff --check origin/main...HEAD: clean.
  • Format numbers (1, 5, 14, 20, 22, 23, 24, 29, 56, 64, 71, 74, 77) match MTBUF_FORMATS in tools/disasm_rdna2.py. They also match the sibling FETCH_DXGI pairs in tools/startup/gfx2hlsl.py.
  • I recomputed the test constants by hand. Identity mapping gives selectors 4,5,6,7, which encodes as 0xfac. The swizzle (1,4,0,5) gives 5 | 0<<3 | 4<<6 | 1<<9 = 0x305, and with format 29 that is 0x1d305. Both match the test.
  • I built tests/startup_typed_buffer_view.cpp with mingw-w64 g++ (-std=c++17 -static) and ran it under wine. Output: typed buffer FORMAT and DST_SEL verified (13 formats, 1 swizzle, 7 refusals), exit 0. This is not a Win2025 run. The change is a header-only helper with no shader or GPU path, so I did not queue the Windows VM.

Mutations of the new logic (each reverted with git checkout -- .)

  • R32_FLOAT format 22 changed to 21: killed ("expected 00016fac, got 00015fac").
  • FORCE_VALUE_1 selector changed from 1 to 0: killed (swizzle case).
  • Removed the NumElements == 0 refusal: killed ("empty view").
  • Removed the reserved-bits check (mapping & ~(present | 0xfffu)): survived. Exit 0.

Findings

  • P2: src/startup_stubs/typed_buffer_view.h:40. The branch that refuses a mapping with bits set outside present | 0xfff has no negative control. The mutation above passes. Add a case such as D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING | (1u << 13) that expects nullopt. Or drop the check if it is not intended.
  • Nit: FirstElement and NumElements are not used for encoding apart from the zero check. The header comment says range is supplied separately, which is fine. It would help to say that a non-zero FirstElement is accepted and ignored.
  • Nit: DST_SEL is encoded without checking that the selected components exist in the format. For example, selecting component 3 of R8_UNORM is accepted. This is fine for a V# encoder, but the PR text should say so, because the shader side (FETCH_FORMATS) fills missing components with 0, 0, 0, 1.

CI and other notes

  • At review time, Run platform-independent Python checks on Linux and Check machine-code inputs with LLVM 15 were failing, and the Windows jobs were still pending. The logs were not yet available (run in progress), so I cannot tell whether the failure comes from this PR. The diff touches no Python. Please re-run after the next push and confirm.
  • The PR is MERGEABLE and the title is neutral. The change adds three files, with no docs/experiments.md entry. That is acceptable for a helper that is not wired in yet.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055116305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2281#pullrequestreview-6055116305). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T09:38:41Z. **Review:** COMMENTED --- Review of head `28eaad0790e44d3bea6677dcca2620dac0cfaa2a` (comment only, no approval). **Summary:** The encoder is correct for what it covers. I found no P1. I found one P2 (a test gap) and two nits. **Checked locally** - `python3 tests/docs_links_check.py`: passed (18 files, 435 links). - `python3 tests/bidi_controls_check.py`: passed. - `git diff --check origin/main...HEAD`: clean. - Format numbers (1, 5, 14, 20, 22, 23, 24, 29, 56, 64, 71, 74, 77) match `MTBUF_FORMATS` in `tools/disasm_rdna2.py`. They also match the sibling `FETCH_DXGI` pairs in `tools/startup/gfx2hlsl.py`. - I recomputed the test constants by hand. Identity mapping gives selectors 4,5,6,7, which encodes as `0xfac`. The swizzle `(1,4,0,5)` gives `5 | 0<<3 | 4<<6 | 1<<9 = 0x305`, and with format 29 that is `0x1d305`. Both match the test. - I built `tests/startup_typed_buffer_view.cpp` with mingw-w64 g++ (`-std=c++17 -static`) and ran it under wine. Output: `typed buffer FORMAT and DST_SEL verified (13 formats, 1 swizzle, 7 refusals)`, exit 0. This is not a Win2025 run. The change is a header-only helper with no shader or GPU path, so I did not queue the Windows VM. **Mutations of the new logic** (each reverted with `git checkout -- .`) - R32_FLOAT format 22 changed to 21: killed ("expected 00016fac, got 00015fac"). - FORCE_VALUE_1 selector changed from 1 to 0: killed (swizzle case). - Removed the `NumElements == 0` refusal: killed ("empty view"). - Removed the reserved-bits check `(mapping & ~(present | 0xfffu))`: **survived**. Exit 0. **Findings** - P2: `src/startup_stubs/typed_buffer_view.h:40`. The branch that refuses a mapping with bits set outside `present | 0xfff` has no negative control. The mutation above passes. Add a case such as `D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING | (1u << 13)` that expects `nullopt`. Or drop the check if it is not intended. - Nit: `FirstElement` and `NumElements` are not used for encoding apart from the zero check. The header comment says range is supplied separately, which is fine. It would help to say that a non-zero `FirstElement` is accepted and ignored. - Nit: DST_SEL is encoded without checking that the selected components exist in the format. For example, selecting component 3 of R8_UNORM is accepted. This is fine for a V# encoder, but the PR text should say so, because the shader side (`FETCH_FORMATS`) fills missing components with 0, 0, 0, 1. **CI and other notes** - At review time, `Run platform-independent Python checks on Linux` and `Check machine-code inputs with LLVM 15` were failing, and the Windows jobs were still pending. The logs were not yet available (run in progress), so I cannot tell whether the failure comes from this PR. The diff touches no Python. Please re-run after the next push and confirm. - The PR is MERGEABLE and the title is neutral. The change adds three files, with no `docs/experiments.md` entry. That is acceptable for a helper that is not wired in yet. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 10:01:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:01:08Z.

Review: COMMENTED


Re-review of head 9778dfd3b3e5ab9d722986a5941d8a0c733e0f6f (comment only, no approval).

Summary: The earlier P2 is NOT resolved. No P1. CI is now green.

What changed since 28eaad07: git diff 28eaad07 HEAD -- src/startup_stubs/typed_buffer_view.h tests/startup_typed_buffer_view.cpp is empty. Only a merge of main landed. The only diff in the PR files is the CMake block that was already there.

Checked locally

  • python3 tests/docs_links_check.py: passed (18 files, 435 links).
  • python3 tests/bidi_controls_check.py: passed.
  • git diff --check origin/main...HEAD: clean.
  • Re-ran the mutation from the first review: removed the reserved-bits check (mapping & ~(present | 0xfffu)) at src/startup_stubs/typed_buffer_view.h:39, rebuilt tests/startup_typed_buffer_view.cpp with mingw-w64 g++ and ran under wine. Output: typed buffer FORMAT and DST_SEL verified (13 formats, 1 swizzle, 7 refusals), exit 0. The mutation survives. Reverted with git checkout -- ..
  • Not a Win2025 run: header-only helper, no shader or GPU path, so I did not queue the VM.

Findings

  • P2 (still open): src/startup_stubs/typed_buffer_view.h:39. No test covers the refusal of a mapping with bits outside present | 0xfff. Add a case such as D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING | (1u << 13) expecting nullopt, or drop the check.
  • Nits from the first review are unchanged (non-zero FirstElement accepted and ignored; DST_SEL not checked against format components). Worth one sentence in the PR text.

CI: Run platform-independent Python checks on Linux, Assemble and translate gfx1013 fixtures and Build and test on Windows pass. The earlier Linux failure is gone. PR is MERGEABLE, title neutral.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055445414 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2281#pullrequestreview-6055445414). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:01:08Z. **Review:** COMMENTED --- Re-review of head `9778dfd3b3e5ab9d722986a5941d8a0c733e0f6f` (comment only, no approval). **Summary:** The earlier P2 is NOT resolved. No P1. CI is now green. **What changed since `28eaad07`:** `git diff 28eaad07 HEAD -- src/startup_stubs/typed_buffer_view.h tests/startup_typed_buffer_view.cpp` is empty. Only a merge of main landed. The only diff in the PR files is the CMake block that was already there. **Checked locally** - `python3 tests/docs_links_check.py`: passed (18 files, 435 links). - `python3 tests/bidi_controls_check.py`: passed. - `git diff --check origin/main...HEAD`: clean. - Re-ran the mutation from the first review: removed the reserved-bits check `(mapping & ~(present | 0xfffu))` at `src/startup_stubs/typed_buffer_view.h:39`, rebuilt `tests/startup_typed_buffer_view.cpp` with mingw-w64 g++ and ran under wine. Output: `typed buffer FORMAT and DST_SEL verified (13 formats, 1 swizzle, 7 refusals)`, exit 0. The mutation **survives**. Reverted with `git checkout -- .`. - Not a Win2025 run: header-only helper, no shader or GPU path, so I did not queue the VM. **Findings** - P2 (still open): `src/startup_stubs/typed_buffer_view.h:39`. No test covers the refusal of a mapping with bits outside `present | 0xfff`. Add a case such as `D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING | (1u << 13)` expecting `nullopt`, or drop the check. - Nits from the first review are unchanged (non-zero `FirstElement` accepted and ignored; DST_SEL not checked against format components). Worth one sentence in the PR text. **CI:** `Run platform-independent Python checks on Linux`, `Assemble and translate gfx1013 fixtures` and `Build and test on Windows` pass. The earlier Linux failure is gone. PR is MERGEABLE, title neutral. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 11:02:17 +00:00
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
R0Y00/Xbox2Windows!2273
No description provided.