From de961564a169b5dcbe41dd1c12d612374e0c1cc7 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 18:52:30 +0100 Subject: [PATCH 1/6] startup: record SetGraphicsRoot32BitConstant (slot 38) and clear root constants on a root signature change --- CMakeLists.txt | 2 +- docs/experiments.md | 10 +++++ docs/startup-runtime.md | 12 ++++++ src/startup_stubs/d3d12_draw.inl | 8 ++++ src/startup_stubs/d3d12_xs_device.cpp | 1 + tests/startup_mrt_check.py | 23 ++++++++++++ tests/startup_root_constant.cpp | 53 +++++++++++++++++++++++++++ tests/startup_stream_draw.cpp | 6 ++- 8 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 tests/startup_root_constant.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d667940c03..483651d628 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1058,7 +1058,7 @@ set_tests_properties(startup_dump_fence_removed_control_warp PROPERTIES ENVIRONM add_library(startup_stream_setup_obj OBJECT tests/startup_stream_setup.cpp) target_compile_features(startup_stream_setup_obj PRIVATE cxx_std_17) add_executable(startup_stream_consumer tests/startup_stream_consumer.cpp $ tests/startup_stream_draw.cpp - tests/startup_address_srv.cpp tests/startup_root_cbv.cpp tests/startup_root_heap.cpp) + tests/startup_address_srv.cpp tests/startup_root_cbv.cpp tests/startup_root_heap.cpp tests/startup_root_constant.cpp) target_compile_features(startup_stream_consumer PRIVATE cxx_std_17) target_link_libraries(startup_stream_consumer PRIVATE d3d12_xs_shim startup_stub_xg_xs d3d12 dxgi d3dcompiler) target_sources(startup_stream_consumer PRIVATE tests/startup_frame_copy.cpp) diff --git a/docs/experiments.md b/docs/experiments.md index 79707139dd..3cb0e19045 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -13384,6 +13384,16 @@ On Intel UHD Graphics (TGL GT1) with Mesa 26.2.7, DXC 1.10.2605.37 and SPIRV-Too python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device Intel VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \ python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device llvmpipe + +## Startup single root constants + +Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `tests/startup_root_constant.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The slot number is derived, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants). + +Limits: this was written and checked on Linux only (syntax with MinGW, `git diff --check`, the link and bidi checks). The `startup_mrt_*` tests need Windows with D3D12 and were not run, so the expected pixels and the mutations are not yet confirmed there. + +```powershell +cmake --build --preset dev --target startup_stream_consumer +ctest --preset dev --no-tests=error -R "^startup_mrt_" -V ``` ## SAL (/6) lifting in cpu_switch_aot diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 0fdd338bab..a12e0cd812 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -444,6 +444,18 @@ These slots have not been seen in a title log yet. `CopyTextureRegion` (16) and `ctest -R '^startup_list_copy_validation'` runs the pure checks on any host; `startup_list_copy_{warp,hardware}` copies, resolves and reads back through the `x2w_d3d12_list_copy_stats` export. +## Single root constants + +Command-list slot 38 (desktop `SetGraphicsRoot32BitConstant` plus four) takes `(parameter, value, offset)` and stores one +word in the same per-list table as slot 40, which a translated shader reads through a `rootconst` manifest entry. A parameter +of 16 or more or an offset of 8 or more has no storage and the call is dropped without a log line. Nothing is forwarded +to the desktop list. Setting the graphics root signature to a different signature clears every stored constant, as it +clears the root addresses; setting the same one again keeps them (this also applies to slot 40). The slot number is derived +from the desktop order and the console shift (see the ABI notes for B1 and B2), not yet seen in a title log. The +`startup_mrt_{fxc,dxc}_{warp,hardware}` tests drive it with nine cases: set, overwrite, an offset that is and is not the one +the shader reads, the last stored slot (15, 7), four out-of-range calls, the same root signature again, a switched one +and no call. + ## Composite provenance fixture Issue #1628 asks whether a uniform colour left in a composite's destination came from the composite or was diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 4922a28e6b..f74da3e702 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1944,6 +1944,14 @@ void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, co if (parameter >= 16 || offset >= 8 || !count || !x2w_local::readable(data, std::size_t{count} * 4)) return; for (UINT i = 0; i < count && offset + i < 8; ++i) pass_of(self).constants[parameter][offset + i] = data[i]; } +// List slot 38 (desktop 34 + 4), SetGraphicsRoot32BitConstant(parameter, value, offset): one word of a root +// constant. The word is kept for the draw like the ones of slot 40; a parameter of 16 or more or an offset of 8 or +// more has no storage and the call is dropped. Nothing is forwarded to the desktop list. +void __stdcall list_root_constant(Wrapper* self, UINT parameter, std::uint32_t value, UINT offset) +{ + if (parameter >= 16 || offset >= 8) return; + pass_of(self).constants[parameter][offset] = value; +} // List slot 47 (desktop 43 + 4), IASetIndexBuffer(view). void __stdcall list_index_buffer(Wrapper* self, const D3D12_INDEX_BUFFER_VIEW* view) { diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 133458e612..e06a456956 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -4243,6 +4243,7 @@ void build_tables() list_typed[50] = reinterpret_cast(&list_targets); list_typed[13] = reinterpret_cast(&list_draw_indexed); list_typed[36] = reinterpret_cast(&list_table); + list_typed[38] = reinterpret_cast(&list_root_constant); list_typed[40] = reinterpret_cast(&list_root_constants); list_typed[47] = reinterpret_cast(&list_index_buffer); list_typed[48] = reinterpret_cast(&list_vertex_buffers); diff --git a/tests/startup_mrt_check.py b/tests/startup_mrt_check.py index b58618566c..4f3504beaf 100644 --- a/tests/startup_mrt_check.py +++ b/tests/startup_mrt_check.py @@ -148,6 +148,29 @@ def compile_pair(key): manifest.write_text(original) print(f'{kind} {backend} optimized FLOAT exact {exact.hex()}; nonzero constant readback {pixels.hex()}') + # SetGraphicsRoot32BitConstant (list slot 38) feeds the same root constant words as slot 40. The manifest + # names the (parameter, offset) the shader reads; the title call either lands there or it does not. + flipped = struct.pack('<4I', *(value ^ word for value in FLOAT_WORDS)) + cases = ( + ('set', '0 0', flipped), + ('overwrite', '0 0', flipped), # the second call replaces the first + ('offset3', '0 3', flipped), + ('offset3', '0 0', exact), # a different offset does not reach word 0 + ('corner', '15 7', flipped), # the last stored slot + ('outside', '0 0', exact), # parameter 16, parameter -1, offset 8 and offset -1 are dropped + ('same_root', '0 0', flipped), # the same root signature again keeps the word + ('switch_root', '0 0', exact), # another root signature clears it + ('unbound', '0 0', exact), + ) + for mode, source, expected in cases: + manifest.write_text(re.sub(r'mrtbits', 'rootconst ' + source, original)) + env['X2W_TEST_ROOT_CONSTANT'] = mode + pixels, _ = draw(2, word) + assert pixels == expected, (mode, source, pixels.hex(), expected.hex()) + del env['X2W_TEST_ROOT_CONSTANT'] + manifest.write_text(original) + print(f'{kind} {backend} slot 38 root constant: {len(cases)} cases (set, overwrite, offset, corner, bounds, same and switched root)') + base = f'{gfx2hlsl.pipeline_key(vs.read_bytes(), ps.read_bytes(), root.read_bytes()):016x}' ps_source, ps_blob = cache / f'{base}.ps.hlsl', cache / f'{key}.ps.cso' compile_shader(compiler, kind, 'ps', ps_source, ps_blob, cache / f'{key}.folded.asm') diff --git a/tests/startup_root_constant.cpp b/tests/startup_root_constant.cpp new file mode 100644 index 0000000000..c4c8680d65 --- /dev/null +++ b/tests/startup_root_constant.cpp @@ -0,0 +1,53 @@ +#include + +#include +#include + +#include "startup_stream_setup.h" + +// Before the draw, the title sets root constants with SetGraphicsRoot32BitConstant (list slot 38). The check feeds +// one word, `word`, and X2W_TEST_ROOT_CONSTANT names what is done with it: +// set root signature, then (parameter 0, word, offset 0) +// overwrite a first value at (0, 0), then the word at (0, 0) +// offset3 the word at (0, 3) +// corner the word at the last stored slot, (15, 7) +// outside (16, word, 0), (0xffffffff, word, 0), (0, word, 8) and (0, word, 0xffffffff): all dropped +// same_root the word at (0, 0), then the same root signature again: kept +// switch_root the word at (0, 0), then a different root signature and back: cleared +// unbound no call +int draw_root_constant(void* list, std::uint32_t word) +{ + char mode[16]{}; + GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", mode, sizeof(mode)); + const StreamWord root = reinterpret_cast(stream_root_signature()); + if (!root) return 40; + invoke(list, 34, root); // SetGraphicsRootSignature + if (!std::strcmp(mode, "set")) { + invoke(list, 38, 0, word, 0); + } else if (!std::strcmp(mode, "overwrite")) { + invoke(list, 38, 0, 0x5a5a5a5au, 0); + invoke(list, 38, 0, word, 0); + } else if (!std::strcmp(mode, "offset3")) { + invoke(list, 38, 0, word, 3); + } else if (!std::strcmp(mode, "corner")) { + invoke(list, 38, 15, word, 7); + } else if (!std::strcmp(mode, "outside")) { + invoke(list, 38, 16, word, 0); + invoke(list, 38, 0xffffffffu, word, 0); + invoke(list, 38, 0, word, 8); + invoke(list, 38, 0, word, 0xffffffffu); + } else if (!std::strcmp(mode, "same_root")) { + invoke(list, 38, 0, word, 0); + invoke(list, 34, root); + } else if (!std::strcmp(mode, "switch_root")) { + const StreamWord alternate = reinterpret_cast(stream_alternate_root_signature()); + if (!alternate) return 40; + invoke(list, 38, 0, word, 0); + invoke(list, 34, alternate); + invoke(list, 34, root); + } else if (std::strcmp(mode, "unbound")) { + return 2; + } + invoke(list, 12, 3, 1); + return 0; +} diff --git a/tests/startup_stream_draw.cpp b/tests/startup_stream_draw.cpp index 16384fe809..f64f993118 100644 --- a/tests/startup_stream_draw.cpp +++ b/tests/startup_stream_draw.cpp @@ -306,7 +306,8 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char* auto* list = frame.list; auto* queue = frame.queue; auto* fence = frame.fence; - if (export_word) invoke(list, 40, 0, 1, arg(&export_word), 0); + if (export_word && !GetEnvironmentVariableW(L"X2W_TEST_ROOT_CONSTANT", nullptr, 0)) + invoke(list, 40, 0, 1, arg(&export_word), 0); if (GetEnvironmentVariableW(L"X2W_TEST_LOGICAL_VIEW", nullptr, 0)) { if (int result = draw_logical_tables(desktop.Get(), guest, list)) return result; } else if (GetEnvironmentVariableW(L"X2W_TEST_PLACED_VERTEX", nullptr, 0)) { @@ -315,6 +316,9 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char* } else if (bc_chain) { extern int draw_bc_chain(void*, void*); if (const int result = draw_bc_chain(guest, list)) return result; + } else if (GetEnvironmentVariableW(L"X2W_TEST_ROOT_CONSTANT", nullptr, 0)) { + extern int draw_root_constant(void*, std::uint32_t); + if (const int result = draw_root_constant(list, export_word)) return result; } else if (GetEnvironmentVariableW(L"X2W_TEST_ROOT_CBV", nullptr, 0)) { extern int root_heap_control(ID3D12Device*); extern int draw_root_cbv(void*); From abff66790948fb360ce7268dc265c2e30d06c89c Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 18:52:54 +0100 Subject: [PATCH 2/6] docs: place the single root constants section away from the render target section --- docs/startup-runtime.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index a12e0cd812..9699f4d7ed 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -456,6 +456,17 @@ from the desktop order and the console shift (see the ABI notes for B1 and B2), the shader reads, the last stored slot (15, 7), four out-of-range calls, the same root signature again, a switched one and no call. +## Root constant buffer views + +Command-list slot 42 (desktop `SetGraphicsRootConstantBufferView` plus four) records the title address for a root +parameter that the root signature declares as a CBV. A translated shader that reads through its root pointer sees that +address. The call is ignored when the parameter is out of range or is not a CBV (one log line, `root CBV N ignored`); +a null or unreadable address clears the slot to zero so a previous binding is not left stale. It is not forwarded to the +desktop list and does not set the vertex-fetch bit of `srv_bound`. The slot number is derived from the desktop order and +the console shift, not yet seen in a title log; `startup_root_cbv_{warp,hardware}` checks the handler with a bound, an +unbound, a null-overwrite and a wrong-type call. Rebinding the same root signature keeps +the address. Switching to a different signature invalidates the stored root addresses. + ## Composite provenance fixture Issue #1628 asks whether a uniform colour left in a composite's destination came from the composite or was From d54be65f82a1eb785b7a842bf77e9fbd5dffcb6c Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 18:53:14 +0100 Subject: [PATCH 3/6] tests: keep the slot 38 draw beside the root CBV draw so the build list is untouched --- CMakeLists.txt | 2 +- docs/experiments.md | 2 +- tests/startup_root_cbv.cpp | 47 +++++++++++++++++++++++++++++ tests/startup_root_constant.cpp | 53 --------------------------------- 4 files changed, 49 insertions(+), 55 deletions(-) delete mode 100644 tests/startup_root_constant.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 483651d628..d667940c03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1058,7 +1058,7 @@ set_tests_properties(startup_dump_fence_removed_control_warp PROPERTIES ENVIRONM add_library(startup_stream_setup_obj OBJECT tests/startup_stream_setup.cpp) target_compile_features(startup_stream_setup_obj PRIVATE cxx_std_17) add_executable(startup_stream_consumer tests/startup_stream_consumer.cpp $ tests/startup_stream_draw.cpp - tests/startup_address_srv.cpp tests/startup_root_cbv.cpp tests/startup_root_heap.cpp tests/startup_root_constant.cpp) + tests/startup_address_srv.cpp tests/startup_root_cbv.cpp tests/startup_root_heap.cpp) target_compile_features(startup_stream_consumer PRIVATE cxx_std_17) target_link_libraries(startup_stream_consumer PRIVATE d3d12_xs_shim startup_stub_xg_xs d3d12 dxgi d3dcompiler) target_sources(startup_stream_consumer PRIVATE tests/startup_frame_copy.cpp) diff --git a/docs/experiments.md b/docs/experiments.md index 3cb0e19045..8739569434 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -13387,7 +13387,7 @@ VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \ ## Startup single root constants -Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `tests/startup_root_constant.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The slot number is derived, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants). +Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `draw_root_constant` in `tests/startup_root_cbv.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The slot number is derived, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants). Limits: this was written and checked on Linux only (syntax with MinGW, `git diff --check`, the link and bidi checks). The `startup_mrt_*` tests need Windows with D3D12 and were not run, so the expected pixels and the mutations are not yet confirmed there. diff --git a/tests/startup_root_cbv.cpp b/tests/startup_root_cbv.cpp index 9af9dfb7de..b82c432c8f 100644 --- a/tests/startup_root_cbv.cpp +++ b/tests/startup_root_cbv.cpp @@ -45,3 +45,50 @@ int draw_root_cbv(void* list) invoke(list, 12, 3, 1); return 0; } + +// Before the draw, the title sets root constants with SetGraphicsRoot32BitConstant (list slot 38). The check feeds +// one word, `word`, and X2W_TEST_ROOT_CONSTANT names what is done with it: +// set root signature, then (parameter 0, word, offset 0) +// overwrite a first value at (0, 0), then the word at (0, 0) +// offset3 the word at (0, 3) +// corner the word at the last stored slot, (15, 7) +// outside (16, word, 0), (0xffffffff, word, 0), (0, word, 8) and (0, word, 0xffffffff): all dropped +// same_root the word at (0, 0), then the same root signature again: kept +// switch_root the word at (0, 0), then a different root signature and back: cleared +// unbound no call +int draw_root_constant(void* list, std::uint32_t word) +{ + char mode[16]{}; + GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", mode, sizeof(mode)); + const StreamWord root = reinterpret_cast(stream_root_signature()); + if (!root) return 40; + invoke(list, 34, root); // SetGraphicsRootSignature + if (!std::strcmp(mode, "set")) { + invoke(list, 38, 0, word, 0); + } else if (!std::strcmp(mode, "overwrite")) { + invoke(list, 38, 0, 0x5a5a5a5au, 0); + invoke(list, 38, 0, word, 0); + } else if (!std::strcmp(mode, "offset3")) { + invoke(list, 38, 0, word, 3); + } else if (!std::strcmp(mode, "corner")) { + invoke(list, 38, 15, word, 7); + } else if (!std::strcmp(mode, "outside")) { + invoke(list, 38, 16, word, 0); + invoke(list, 38, 0xffffffffu, word, 0); + invoke(list, 38, 0, word, 8); + invoke(list, 38, 0, word, 0xffffffffu); + } else if (!std::strcmp(mode, "same_root")) { + invoke(list, 38, 0, word, 0); + invoke(list, 34, root); + } else if (!std::strcmp(mode, "switch_root")) { + const StreamWord alternate = reinterpret_cast(stream_alternate_root_signature()); + if (!alternate) return 40; + invoke(list, 38, 0, word, 0); + invoke(list, 34, alternate); + invoke(list, 34, root); + } else if (std::strcmp(mode, "unbound")) { + return 2; + } + invoke(list, 12, 3, 1); + return 0; +} diff --git a/tests/startup_root_constant.cpp b/tests/startup_root_constant.cpp deleted file mode 100644 index c4c8680d65..0000000000 --- a/tests/startup_root_constant.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include - -#include -#include - -#include "startup_stream_setup.h" - -// Before the draw, the title sets root constants with SetGraphicsRoot32BitConstant (list slot 38). The check feeds -// one word, `word`, and X2W_TEST_ROOT_CONSTANT names what is done with it: -// set root signature, then (parameter 0, word, offset 0) -// overwrite a first value at (0, 0), then the word at (0, 0) -// offset3 the word at (0, 3) -// corner the word at the last stored slot, (15, 7) -// outside (16, word, 0), (0xffffffff, word, 0), (0, word, 8) and (0, word, 0xffffffff): all dropped -// same_root the word at (0, 0), then the same root signature again: kept -// switch_root the word at (0, 0), then a different root signature and back: cleared -// unbound no call -int draw_root_constant(void* list, std::uint32_t word) -{ - char mode[16]{}; - GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", mode, sizeof(mode)); - const StreamWord root = reinterpret_cast(stream_root_signature()); - if (!root) return 40; - invoke(list, 34, root); // SetGraphicsRootSignature - if (!std::strcmp(mode, "set")) { - invoke(list, 38, 0, word, 0); - } else if (!std::strcmp(mode, "overwrite")) { - invoke(list, 38, 0, 0x5a5a5a5au, 0); - invoke(list, 38, 0, word, 0); - } else if (!std::strcmp(mode, "offset3")) { - invoke(list, 38, 0, word, 3); - } else if (!std::strcmp(mode, "corner")) { - invoke(list, 38, 15, word, 7); - } else if (!std::strcmp(mode, "outside")) { - invoke(list, 38, 16, word, 0); - invoke(list, 38, 0xffffffffu, word, 0); - invoke(list, 38, 0, word, 8); - invoke(list, 38, 0, word, 0xffffffffu); - } else if (!std::strcmp(mode, "same_root")) { - invoke(list, 38, 0, word, 0); - invoke(list, 34, root); - } else if (!std::strcmp(mode, "switch_root")) { - const StreamWord alternate = reinterpret_cast(stream_alternate_root_signature()); - if (!alternate) return 40; - invoke(list, 38, 0, word, 0); - invoke(list, 34, alternate); - invoke(list, 34, root); - } else if (std::strcmp(mode, "unbound")) { - return 2; - } - invoke(list, 12, 3, 1); - return 0; -} From e758ff45d1f643eafc4b25268bca6e9653930e0f Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 19:01:36 +0100 Subject: [PATCH 4/6] startup: revert stray CMakeLists hunk, guard null list, test slot 38/40 preservation --- docs/experiments.md | 4 +--- docs/startup-runtime.md | 8 ++++---- src/startup_stubs/d3d12_draw.inl | 2 +- tests/startup_mrt_check.py | 3 +++ tests/startup_root_cbv.cpp | 5 +++++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 8739569434..d3530a1f31 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -13387,9 +13387,7 @@ VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \ ## Startup single root constants -Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `draw_root_constant` in `tests/startup_root_cbv.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The slot number is derived, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants). - -Limits: this was written and checked on Linux only (syntax with MinGW, `git diff --check`, the link and bidi checks). The `startup_mrt_*` tests need Windows with D3D12 and were not run, so the expected pixels and the mutations are not yet confirmed there. +Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `draw_root_constant` in `tests/startup_root_cbv.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, preserving offset 0 written through slot 40 while writing offset 3 through slot 38, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The fixture is synthetic only and the slot number is derived from the desktop order plus the console shift, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants). ```powershell cmake --build --preset dev --target startup_stream_consumer diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 9699f4d7ed..3e75eb1c73 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -451,10 +451,10 @@ word in the same per-list table as slot 40, which a translated shader reads thro of 16 or more or an offset of 8 or more has no storage and the call is dropped without a log line. Nothing is forwarded to the desktop list. Setting the graphics root signature to a different signature clears every stored constant, as it clears the root addresses; setting the same one again keeps them (this also applies to slot 40). The slot number is derived -from the desktop order and the console shift (see the ABI notes for B1 and B2), not yet seen in a title log. The -`startup_mrt_{fxc,dxc}_{warp,hardware}` tests drive it with nine cases: set, overwrite, an offset that is and is not the one -the shader reads, the last stored slot (15, 7), four out-of-range calls, the same root signature again, a switched one -and no call. +from the desktop order and the console shift, not yet seen in a title log. The +`startup_mrt_{fxc,dxc}_{warp,hardware}` tests drive it with eleven cases: set, overwrite, an offset that is and is not the one +the shader reads, preserving an offset written through slot 40 while writing another through slot 38, the last stored slot +(15, 7), four out-of-range calls, the same root signature again, a switched one and no call. ## Root constant buffer views diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index f74da3e702..addb5f6bbd 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1949,7 +1949,7 @@ void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, co // more has no storage and the call is dropped. Nothing is forwarded to the desktop list. void __stdcall list_root_constant(Wrapper* self, UINT parameter, std::uint32_t value, UINT offset) { - if (parameter >= 16 || offset >= 8) return; + if (!self || parameter >= 16 || offset >= 8) return; pass_of(self).constants[parameter][offset] = value; } // List slot 47 (desktop 43 + 4), IASetIndexBuffer(view). diff --git a/tests/startup_mrt_check.py b/tests/startup_mrt_check.py index 4f3504beaf..869afc42c8 100644 --- a/tests/startup_mrt_check.py +++ b/tests/startup_mrt_check.py @@ -151,11 +151,14 @@ def compile_pair(key): # SetGraphicsRoot32BitConstant (list slot 38) feeds the same root constant words as slot 40. The manifest # names the (parameter, offset) the shader reads; the title call either lands there or it does not. flipped = struct.pack('<4I', *(value ^ word for value in FLOAT_WORDS)) + preserved_offset3 = struct.pack('<4I', *(value ^ 0x01800000 for value in FLOAT_WORDS)) cases = ( ('set', '0 0', flipped), ('overwrite', '0 0', flipped), # the second call replaces the first ('offset3', '0 3', flipped), ('offset3', '0 0', exact), # a different offset does not reach word 0 + ('preserve', '0 0', flipped), # slot 38 at offset 3 keeps slot 40's word at offset 0 + ('preserve', '0 3', preserved_offset3), # and stores its own word at offset 3 ('corner', '15 7', flipped), # the last stored slot ('outside', '0 0', exact), # parameter 16, parameter -1, offset 8 and offset -1 are dropped ('same_root', '0 0', flipped), # the same root signature again keeps the word diff --git a/tests/startup_root_cbv.cpp b/tests/startup_root_cbv.cpp index b82c432c8f..1ba0211972 100644 --- a/tests/startup_root_cbv.cpp +++ b/tests/startup_root_cbv.cpp @@ -51,6 +51,7 @@ int draw_root_cbv(void* list) // set root signature, then (parameter 0, word, offset 0) // overwrite a first value at (0, 0), then the word at (0, 0) // offset3 the word at (0, 3) +// preserve slot 40 sets (0, 0..1) with word at offset 0, then slot 38 writes (0, 3): both offsets stay intact // corner the word at the last stored slot, (15, 7) // outside (16, word, 0), (0xffffffff, word, 0), (0, word, 8) and (0, word, 0xffffffff): all dropped // same_root the word at (0, 0), then the same root signature again: kept @@ -70,6 +71,10 @@ int draw_root_constant(void* list, std::uint32_t word) invoke(list, 38, 0, word, 0); } else if (!std::strcmp(mode, "offset3")) { invoke(list, 38, 0, word, 3); + } else if (!std::strcmp(mode, "preserve")) { + const std::uint32_t pair[2] = {word, 0x01000000u}; + invoke(list, 40, 0, 2, reinterpret_cast(pair), 0); + invoke(list, 38, 0, 0x01800000u, 3); } else if (!std::strcmp(mode, "corner")) { invoke(list, 38, 15, word, 7); } else if (!std::strcmp(mode, "outside")) { From 0c4447ba5c5284a039c44f7231b22b5c4ad81a43 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 19:04:15 +0100 Subject: [PATCH 5/6] tests: create alternate root signature for X2W_TEST_ROOT_CONSTANT=switch_root --- tests/startup_stream_setup.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/startup_stream_setup.cpp b/tests/startup_stream_setup.cpp index 742e404ea4..72db201c38 100644 --- a/tests/startup_stream_setup.cpp +++ b/tests/startup_stream_setup.cpp @@ -168,10 +168,22 @@ int prepare_stream_pipeline(const char* vs_path, const char* ps_path, const char return rejected ? rejected : 7; } stream_root = root; - if (std::strcmp(cbv_mode, "switch_root") == 0) { - root_cbv.Descriptor.ShaderRegister = 1; + char rc_mode[16]{}; + GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", rc_mode, sizeof(rc_mode)); + if (std::strcmp(cbv_mode, "switch_root") == 0 || std::strcmp(rc_mode, "switch_root") == 0) { + D3D12_ROOT_SIGNATURE_DESC alt_desc = root_desc; + D3D12_ROOT_PARAMETER alt_param = root_cbv; + if (std::strcmp(cbv_mode, "switch_root") == 0) { + alt_param.Descriptor.ShaderRegister = 1; + } else { + alt_param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; + alt_param.Constants = {1, 0, 1}; + alt_param.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; + } + alt_desc.NumParameters = 1; + alt_desc.pParameters = &alt_param; ComPtr alternate; - if (FAILED(serialize_root(root_desc, alternate)) || + if (FAILED(serialize_root(alt_desc, alternate)) || FAILED(reinterpret_cast(slots[16])(device, 0, alternate->GetBufferPointer(), alternate->GetBufferSize(), __uuidof(ID3D12RootSignature), &stream_alternate_root))) return 7; From b8885ac9302e56cc8d66ceec1c44082076ff775a Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 20:31:18 +0100 Subject: [PATCH 6/6] docs: drop the root constant buffer views copy the rebase left behind --- docs/startup-runtime.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 3e75eb1c73..64f162d3b5 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -456,17 +456,6 @@ from the desktop order and the console shift, not yet seen in a title log. The the shader reads, preserving an offset written through slot 40 while writing another through slot 38, the last stored slot (15, 7), four out-of-range calls, the same root signature again, a switched one and no call. -## Root constant buffer views - -Command-list slot 42 (desktop `SetGraphicsRootConstantBufferView` plus four) records the title address for a root -parameter that the root signature declares as a CBV. A translated shader that reads through its root pointer sees that -address. The call is ignored when the parameter is out of range or is not a CBV (one log line, `root CBV N ignored`); -a null or unreadable address clears the slot to zero so a previous binding is not left stale. It is not forwarded to the -desktop list and does not set the vertex-fetch bit of `srv_bound`. The slot number is derived from the desktop order and -the console shift, not yet seen in a title log; `startup_root_cbv_{warp,hardware}` checks the handler with a bound, an -unbound, a null-overwrite and a wrong-type call. Rebinding the same root signature keeps -the address. Switching to a different signature invalidates the stored root addresses. - ## Composite provenance fixture Issue #1628 asks whether a uniform colour left in a composite's destination came from the composite or was