From 0192a5ed9904a952106e3e1b1f90a78eb9e4ae5f Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 19:53:44 +0100 Subject: [PATCH 1/2] feat: record the compute root signature and descriptor tables (slots 33 and 35) Header-only state in list_compute_root.h with a Linux-testable check. Dispatch (slot 14) is not handled here; the state is exposed through ready() and table() for it. Refs #870. --- CMakeLists.txt | 6 +++ src/startup_stubs/d3d12_xs_device.cpp | 19 +++++++ src/startup_stubs/list_compute_root.h | 65 +++++++++++++++++++++++ tests/startup_compute_root.cpp | 75 +++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 src/startup_stubs/list_compute_root.h create mode 100644 tests/startup_compute_root.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e42aadcf71..efb59d3e26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -975,6 +975,12 @@ target_sources(offscreen_check PRIVATE tests/startup_cb_blend.cpp "${startup_cb_ # The same decoder without a device (#1149): each factor value in each of the four factor slots, # colour and alpha combine functions apart, refusal reasons, MIN / MAX per slot, the write mask and # control_word. The mutated run (destination alpha left in its colour form) is the negative control. +# Compute root state (command-list slots 33 and 35): signature, descriptor tables, clear on a different signature, +# range limit, closed list. Checked against real mutations of list_compute_root.h before submission. +add_executable(startup_compute_root tests/startup_compute_root.cpp) +target_include_directories(startup_compute_root PRIVATE src) +target_compile_features(startup_compute_root PRIVATE cxx_std_17) +add_test(NAME startup_compute_root COMMAND startup_compute_root) add_executable(startup_cb_blend_check tests/startup_cb_blend_check.cpp) target_include_directories(startup_cb_blend_check PRIVATE src) target_compile_features(startup_cb_blend_check PRIVATE cxx_std_17) diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 8c96001c34..b87e39f3bb 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -15,6 +15,7 @@ #include "startup_stubs/trap.h" #include "startup_stubs/local_log.h" #include "startup_stubs/logical_view_table.h" +#include "startup_stubs/list_compute_root.h" #include "startup_stubs/overlay_window.h" #include "startup_stubs/draw_bmp.h" #include "startup_stubs/draw_dump_tracking.h" @@ -1678,6 +1679,7 @@ struct Pass { Wrapper* pipeline = nullptr; UINT topology = 0; x2w_startup::ViewTable view_tables[16]{}; + x2w_startup::ComputeRootState compute_root; // slots 33 and 35, read by a Dispatch handler u64 source_view_heap = 0; u64 root_address[16] = {}; // title address of each root descriptor std::uint32_t constants[16][8] = {}; @@ -1800,6 +1802,21 @@ void __stdcall list_graphics_root(Wrapper* self, void* root) log("x2w-render root signature %p with heap flags 0x%x not set on the desktop list (title heaps are not forwarded)", static_cast(w), pass.root_heap_flags); } +// List slot 33 (desktop 29 + 4), SetComputeRootSignature. Recorded only; nothing is forwarded to the desktop list yet. +void __stdcall list_compute_root_signature(Wrapper* self, void* root) +{ + Wrapper* w = as_wrapper(root); + pass_of(self).compute_root.set_signature(self->own().list_open, w ? root_info(w) : nullptr); +} +// List slot 35 (desktop 31 + 4), SetComputeRootDescriptorTable(parameter, gpu_handle). Recorded only. +void __stdcall list_compute_table(Wrapper* self, UINT parameter, u64 gpu_handle) +{ + static LONG dropped; + if (pass_of(self).compute_root.set_table(self->own().list_open, parameter, gpu_handle) == x2w_startup::ComputeRootState::Result::out_of_range && + first_calls(dropped, 4)) + log("x2w-render compute descriptor table dropped: parameter %u (%u parameters are kept)", parameter, + x2w_startup::ComputeRootState::max_parameters); +} DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target) { DXGI_FORMAT format = target->GetDesc().Format; @@ -3428,6 +3445,8 @@ void build_tables() list_typed[25] = reinterpret_cast(&list_pipeline); list_typed[32] = reinterpret_cast(&list_set_descriptor_heaps); list_typed[34] = reinterpret_cast(&list_graphics_root); + list_typed[33] = reinterpret_cast(&list_compute_root_signature); + list_typed[35] = reinterpret_cast(&list_compute_table); list_typed[44] = reinterpret_cast(&list_root_srv); list_typed[42] = reinterpret_cast(&list_root_cbv); list_typed[50] = reinterpret_cast(&list_targets); diff --git a/src/startup_stubs/list_compute_root.h b/src/startup_stubs/list_compute_root.h new file mode 100644 index 0000000000..4580ae9303 --- /dev/null +++ b/src/startup_stubs/list_compute_root.h @@ -0,0 +1,65 @@ +#pragma once + +// Compute root state of one command list: command-list slot 33 (desktop 29 + 4, SetComputeRootSignature) and +// slot 35 (desktop 31 + 4, SetComputeRootDescriptorTable). Both are seen in real logs next to Dispatch (slot 14). +// Only the state is recorded here and nothing is forwarded to the desktop list. A Dispatch handler reads it through +// ready() and table(): without a compute root signature set, the desktop list rejects the dispatch. +// +// The rules follow the graphics side (slot 34): setting the root signature that is already set keeps the descriptor +// tables, setting a different one (or none) leaves no table bound. A parameter index past the kept range is +// refused and counted, and a list that is not recording ignores both calls. + +#include + +namespace x2w_startup { + +class ComputeRootState { +public: + static constexpr unsigned max_parameters = 16; // same range as the graphics tables + + // What a call did, so the caller can log it and tests can check it. + enum class Result { recorded, ignored_closed, out_of_range }; + + // The root signature is identified by any stable pointer (the title wrapper's parameter list); null clears it. + Result set_signature(bool recording, const void* signature) + { + if (!recording) { + ++closed_ignored_; + return Result::ignored_closed; + } + if (signature != signature_) + for (auto& handle : tables_) handle = 0; + signature_ = signature; + return Result::recorded; + } + + // gpu_handle is the title's GPU descriptor handle of the table, kept as given (0 = nothing bound). + Result set_table(bool recording, unsigned parameter, std::uint64_t gpu_handle) + { + if (!recording) { + ++closed_ignored_; + return Result::ignored_closed; + } + if (parameter >= max_parameters) { + ++out_of_range_; + return Result::out_of_range; + } + tables_[parameter] = gpu_handle; + return Result::recorded; + } + + // Accessors for a Dispatch handler. + bool ready() const { return signature_ != nullptr; } + const void* signature() const { return signature_; } + std::uint64_t table(unsigned parameter) const { return parameter < max_parameters ? tables_[parameter] : 0; } + std::uint32_t out_of_range_count() const { return out_of_range_; } + std::uint32_t closed_ignored_count() const { return closed_ignored_; } + +private: + const void* signature_ = nullptr; + std::uint64_t tables_[max_parameters] = {}; + std::uint32_t out_of_range_ = 0; + std::uint32_t closed_ignored_ = 0; +}; + +} // namespace x2w_startup diff --git a/tests/startup_compute_root.cpp b/tests/startup_compute_root.cpp new file mode 100644 index 0000000000..6cfb00cb85 --- /dev/null +++ b/tests/startup_compute_root.cpp @@ -0,0 +1,75 @@ +// Checks src/startup_stubs/list_compute_root.h without a device: the compute root signature and descriptor +// tables a command list records for a later Dispatch. +#include "startup_stubs/list_compute_root.h" + +#include +#include +#include + +namespace { +using x2w_startup::ComputeRootState; +int failures; + +void check(bool ok, const char* name) +{ + if (!ok) { + std::printf("FAIL %s\n", name); + ++failures; + } +} + +} // namespace + +int main() +{ + int root_a = 0, root_b = 0; + + { + ComputeRootState s; + check(!s.ready(), "a fresh list has no compute root"); + check(s.set_signature(true, &root_a) == ComputeRootState::Result::recorded && s.ready() && s.signature() == &root_a, "signature set"); + check(s.set_table(true, 2, 0x1000) == ComputeRootState::Result::recorded && s.table(2) == 0x1000, "table set"); + check(s.table(3) == 0, "an unset parameter has no table"); + } + { + ComputeRootState s; + s.set_signature(true, &root_a); + s.set_table(true, 0, 0x2000); + s.set_table(true, 5, 0x3000); + s.set_signature(true, &root_a); + check(s.table(0) == 0x2000 && s.table(5) == 0x3000, "the same signature keeps the tables"); + } + { + ComputeRootState s; + s.set_signature(true, &root_a); + s.set_table(true, 0, 0x2000); + s.set_table(true, 5, 0x3000); + s.set_signature(true, &root_b); + check(s.signature() == &root_b && s.table(0) == 0 && s.table(5) == 0, "a different signature leaves no table bound"); + s.set_signature(true, nullptr); + check(!s.ready(), "a null signature clears the compute root"); + } + { + ComputeRootState s; + s.set_signature(true, &root_a); + s.set_table(true, 1, 0x4000); + const auto at_limit = s.set_table(true, ComputeRootState::max_parameters - 1, 0x5000); + const auto past = s.set_table(true, ComputeRootState::max_parameters, 0x6000); + check(at_limit == ComputeRootState::Result::recorded && s.table(ComputeRootState::max_parameters - 1) == 0x5000, "the last parameter is kept"); + check(past == ComputeRootState::Result::out_of_range && s.out_of_range_count() == 1 && s.table(ComputeRootState::max_parameters) == 0, + "a parameter out of range is refused and counted"); + s.set_table(true, 1000, 1); + check(s.out_of_range_count() == 2 && s.table(1) == 0x4000, "a refused call leaves the other tables alone"); + } + { + ComputeRootState s; + const auto closed_sig = s.set_signature(false, &root_a); + check(closed_sig == ComputeRootState::Result::ignored_closed && !s.ready(), "a closed list ignores the signature"); + s.set_signature(true, &root_a); + const auto closed_table = s.set_table(false, 0, 0x7000); + check(closed_table == ComputeRootState::Result::ignored_closed && s.table(0) == 0, "a closed list ignores the table"); + check(s.closed_ignored_count() >= 1, "ignored calls are counted"); + } + std::printf("startup_compute_root: %s\n", failures ? "FAILED" : "ok"); + return failures ? 1 : 0; +} From 682b0e0de7c1d33fef54a3eec1df41a0fd35a095 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Wed, 25 Nov 2026 01:40:20 +0100 Subject: [PATCH 2/2] feat: record compute descriptor tables (slot 35) and clear them on a root or heap change --- CMakeLists.txt | 6 ++ src/startup_stubs/d3d12_draw.inl | 32 +++++++++-- src/startup_stubs/d3d12_xs_device.cpp | 4 ++ src/startup_stubs/list_compute_root.h | 55 ++++++++++++++++++ tests/startup_compute_root.cpp | 82 +++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 src/startup_stubs/list_compute_root.h create mode 100644 tests/startup_compute_root.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c67aa831e3..c88e23cf0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1315,6 +1315,12 @@ add_executable(startup_logical_view_table_check tests/startup_logical_view_table target_include_directories(startup_logical_view_table_check PRIVATE src) target_compile_features(startup_logical_view_table_check PRIVATE cxx_std_17) add_test(NAME startup_logical_view_table COMMAND startup_logical_view_table_check) +# Compute descriptor tables (command-list slot 35, src/startup_stubs/list_compute_root.h): a table at a nonzero +# descriptor offset, a wrong handle, clear on a different signature or a view heap change, range limit. +add_executable(startup_compute_root tests/startup_compute_root.cpp) +target_include_directories(startup_compute_root PRIVATE src) +target_compile_features(startup_compute_root PRIVATE cxx_std_17) +add_test(NAME startup_compute_root COMMAND startup_compute_root) # Local switch, logging, and page-probe helpers (src/startup_stubs/local_log.h, #1149). add_executable(startup_local_log_check tests/startup_local_log_check.cpp) target_include_directories(startup_local_log_check PRIVATE src) diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index f12dd8038b..c715727a79 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1222,17 +1222,17 @@ void __stdcall list_set_descriptor_heaps(Wrapper* self, UINT count, void* const* } auto& pass = pass_of(self); if (pass.source_view_heap != view_heap) + { for (auto& table : pass.view_tables) table = {}; + pass.compute_tables.clear(); + } pass.source_view_heap = view_heap; pass.title_samplers = source; } -// List slot 36 (desktop 32 + 4), SetGraphicsRootDescriptorTable(parameter, GPU handle): the table's -// address in the title's descriptor memory is kept for the draw. -void __stdcall list_table(Wrapper* self, UINT parameter, u64 gpu_handle) +// The table at a title GPU handle, looked up in the title's view heap (the one set by slot 32 when known). +x2w_startup::ViewTable resolve_title_table(const Pass& pass, u64 gpu_handle) { - if (parameter >= 16) return; - auto& pass = pass_of(self); x2w_startup::ViewTable table; AcquireSRWLockShared(¬e_lock); for (const HeapInfo& heap : heap_infos()) { @@ -1243,7 +1243,27 @@ void __stdcall list_table(Wrapper* self, UINT parameter, u64 gpu_handle) if (table.address) break; } ReleaseSRWLockShared(¬e_lock); - pass.view_tables[parameter] = table; + return table; +} + +// List slot 36 (desktop 32 + 4), SetGraphicsRootDescriptorTable(parameter, GPU handle): the table's +// address in the title's descriptor memory is kept for the draw. +void __stdcall list_table(Wrapper* self, UINT parameter, u64 gpu_handle) +{ + if (parameter >= 16) return; + auto& pass = pass_of(self); + pass.view_tables[parameter] = resolve_title_table(pass, gpu_handle); +} +// List slot 35 (desktop 31 + 4), SetComputeRootDescriptorTable(parameter, GPU handle). Recorded only for a later +// Dispatch; slot 33 keeps the desktop compute root bind. +void __stdcall list_compute_table(Wrapper* self, UINT parameter, u64 gpu_handle) +{ + static LONG dropped; + if (!self->own().list_open) return; + auto& pass = pass_of(self); + if (!pass.compute_tables.set_table(parameter, resolve_title_table(pass, gpu_handle)) && first_calls(dropped, 4)) + log("x2w-render compute descriptor table dropped: parameter %u (%u parameters are kept)", parameter, + x2w_startup::ComputeTables::max_parameters); } // List slot 40 (desktop 36 + 4), SetGraphicsRoot32BitConstants(parameter, count, data, offset). void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, const std::uint32_t* data, UINT offset) diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 105d7b93f1..954c13f8bc 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -15,6 +15,7 @@ #include "startup_stubs/trap.h" #include "startup_stubs/local_log.h" #include "startup_stubs/logical_view_table.h" +#include "startup_stubs/list_compute_root.h" #include "startup_stubs/overlay_window.h" #include "startup_stubs/draw_bmp.h" #include "startup_stubs/draw_dump_tracking.h" @@ -1872,6 +1873,7 @@ struct Pass { Wrapper* pipeline = nullptr; UINT topology = 0; x2w_startup::ViewTable view_tables[16]{}; + x2w_startup::ComputeTables compute_tables; // slot 35, read by a Dispatch handler u64 source_view_heap = 0; u64 root_address[16] = {}; // title address of each root descriptor std::uint32_t constants[16][8] = {}; @@ -1979,6 +1981,7 @@ void __stdcall list_compute_root(Wrapper* self, void* root) Pass& pass = pass_of(self); const bool real = w && w->own().kind == root_signature_kind && w->own().real && !root_heap_flags(w); pass.compute_root = real ? static_cast(w->own().real) : nullptr; + pass.compute_tables.set_signature(w ? root_info(w) : nullptr); // a different signature leaves no table bound if (pass.compute_root) list->SetComputeRootSignature(pass.compute_root); } @@ -3793,6 +3796,7 @@ void build_tables() list_typed[42] = reinterpret_cast(&list_root_cbv); list_typed[50] = reinterpret_cast(&list_targets); list_typed[13] = reinterpret_cast(&list_draw_indexed); + list_typed[35] = reinterpret_cast(&list_compute_table); list_typed[36] = reinterpret_cast(&list_table); list_typed[40] = reinterpret_cast(&list_root_constants); list_typed[47] = reinterpret_cast(&list_index_buffer); diff --git a/src/startup_stubs/list_compute_root.h b/src/startup_stubs/list_compute_root.h new file mode 100644 index 0000000000..6e5d89c469 --- /dev/null +++ b/src/startup_stubs/list_compute_root.h @@ -0,0 +1,55 @@ +#pragma once + +// Descriptor tables of the compute root of one command list: command-list slot 35 (desktop 31 + 4, +// SetComputeRootDescriptorTable). Slot 33 (SetComputeRootSignature) keeps its own desktop bind; it only tells this +// state which root signature is current. Tables are recorded for a later Dispatch handler and are not forwarded. +// +// The rules follow the graphics side (slots 34 and 36): setting the root signature that is already set keeps the +// tables, setting a different one (or none) leaves no table bound, and so does a change of the title's view heap. +// A parameter past the kept range is refused and counted. + +#include + +#include "startup_stubs/logical_view_table.h" + +namespace x2w_startup { + +class ComputeTables { +public: + static constexpr unsigned max_parameters = 16; // same range as the graphics tables + + // The root signature is identified by any stable pointer (the title wrapper's parameter list); null clears it. + void set_signature(const void* signature) + { + if (signature != signature_) clear(); + signature_ = signature; + } + + // Slot 32 with another view heap: the recorded addresses belong to the old one. + void clear() + { + for (auto& table : tables_) table = {}; + } + + // False when the parameter is out of range (counted). + bool set_table(unsigned parameter, const ViewTable& table) + { + if (parameter >= max_parameters) { + ++out_of_range_; + return false; + } + tables_[parameter] = table; + return true; + } + + const void* signature() const { return signature_; } + ViewTable table(unsigned parameter) const { return parameter < max_parameters ? tables_[parameter] : ViewTable{}; } + std::uint32_t out_of_range_count() const { return out_of_range_; } + +private: + const void* signature_ = nullptr; + ViewTable tables_[max_parameters] = {}; + std::uint32_t out_of_range_ = 0; +}; + +} // namespace x2w_startup diff --git a/tests/startup_compute_root.cpp b/tests/startup_compute_root.cpp new file mode 100644 index 0000000000..b31cd9bcce --- /dev/null +++ b/tests/startup_compute_root.cpp @@ -0,0 +1,82 @@ +// Checks src/startup_stubs/list_compute_root.h without a device: the descriptor tables slot 35 records for a +// compute Dispatch, resolved against a title view heap the way the graphics tables are (slot 36). +#include "startup_stubs/list_compute_root.h" + +#include +#include + +namespace { +using x2w_startup::ComputeTables; +using x2w_startup::ViewTable; +using x2w_startup::resolve_view_table; +int failures; + +void check(bool ok, const char* name) +{ + if (!ok) { + std::printf("FAIL %s\n", name); + ++failures; + } +} + +// A title heap of 8 descriptors of 32 bytes: GPU base 0x10000, CPU base 0x7000. +constexpr std::uint64_t gpu_base = 0x10000, cpu_base = 0x7000; +constexpr unsigned count = 8, stride = 32; +ViewTable at(unsigned descriptor) { return resolve_view_table(gpu_base, cpu_base, count, stride, gpu_base + std::uint64_t{descriptor} * stride); } +} // namespace + +int main() +{ + int root_a = 0, root_b = 0; + + { + // A UAV table at a nonzero descriptor offset resolves to that offset, not to the heap start. + ComputeTables s; + s.set_signature(&root_a); + check(s.set_table(2, at(3)), "table set"); + check(s.table(2).address == cpu_base + 3 * stride && s.table(2).bytes == 5 * stride, "slot 35 keeps the offset table"); + check(s.table(2).address != at(0).address, "a nonzero offset is not the default table"); + check(s.table(3).address == 0, "an unset parameter has no table"); + } + { + // A handle that is not in the heap resolves to nothing: the wrong binding is not turned into a default. + check(resolve_view_table(gpu_base, cpu_base, count, stride, gpu_base + count * stride).address == 0, "past the heap"); + check(resolve_view_table(gpu_base, cpu_base, count, stride, gpu_base + 5).address == 0, "inside a descriptor"); + check(resolve_view_table(gpu_base, cpu_base, count, stride, gpu_base - stride).address == 0, "before the heap"); + ComputeTables s; + s.set_signature(&root_a); + s.set_table(0, at(1)); + s.set_table(0, resolve_view_table(gpu_base, cpu_base, count, stride, 0xdead0000)); + check(s.table(0).address == 0, "a wrong handle replaces the earlier binding with nothing"); + } + { + ComputeTables s; + s.set_signature(&root_a); + s.set_table(0, at(1)); + s.set_table(5, at(4)); + s.set_signature(&root_a); + check(s.table(0).address == cpu_base + stride && s.table(5).address == cpu_base + 4 * stride, "the same signature keeps the tables"); + s.set_signature(&root_b); + check(s.signature() == &root_b && s.table(0).address == 0 && s.table(5).address == 0, "a different signature clears the tables"); + s.set_table(1, at(2)); + s.set_signature(nullptr); + check(s.signature() == nullptr && s.table(1).address == 0, "a null signature clears the tables"); + } + { + ComputeTables s; + s.set_signature(&root_a); + s.set_table(7, at(6)); + s.clear(); + check(s.table(7).address == 0 && s.signature() == &root_a, "a view heap change clears the tables and keeps the signature"); + } + { + ComputeTables s; + s.set_signature(&root_a); + s.set_table(1, at(1)); + check(s.set_table(ComputeTables::max_parameters - 1, at(2)) && s.table(ComputeTables::max_parameters - 1).address, "the last parameter is kept"); + check(!s.set_table(ComputeTables::max_parameters, at(3)) && s.out_of_range_count() == 1, "a parameter out of range is refused and counted"); + check(s.table(ComputeTables::max_parameters).address == 0 && s.table(1).address == cpu_base + stride, "a refused call leaves the other tables alone"); + } + std::printf("startup_compute_root: %s\n", failures ? "FAILED" : "ok"); + return failures ? 1 : 0; +}