Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,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)
Expand Down
32 changes: 26 additions & 6 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2388,17 +2388,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(&note_lock);
for (const HeapInfo& heap : heap_infos()) {
Expand All @@ -2409,7 +2409,27 @@ void __stdcall list_table(Wrapper* self, UINT parameter, u64 gpu_handle)
if (table.address) break;
}
ReleaseSRWLockShared(&note_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)
Expand Down
4 changes: 4 additions & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "xmem_page_batch.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"
Expand Down Expand Up @@ -2357,6 +2358,7 @@ struct Pass {
const std::vector<RootParameter>* requested_mesh_root = 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] = {};
Expand Down Expand Up @@ -2560,6 +2562,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<ID3D12RootSignature*>(w->own().real) : nullptr;
pass.compute_tables.set_signature(w ? root_info(w) : nullptr); // a different signature leaves no table bound
pass.compute_params = real ? root_info(w) : nullptr;
if (compute_binding_trace_enabled() && (!pass.compute_trace || pass.compute_trace->root != w)) {
pass.compute_trace = std::make_unique<ComputeBindingTrace>();
Expand Down Expand Up @@ -6063,6 +6066,7 @@ void build_tables()
list_typed[42] = reinterpret_cast<ListTyped>(&list_root_cbv);
list_typed[50] = reinterpret_cast<ListTyped>(&list_targets);
list_typed[13] = reinterpret_cast<ListTyped>(&list_draw_indexed);
list_typed[35] = reinterpret_cast<ListTyped>(&list_compute_table);
list_typed[36] = reinterpret_cast<ListTyped>(&list_table);
list_typed[40] = reinterpret_cast<ListTyped>(&list_root_constants);
list_typed[47] = reinterpret_cast<ListTyped>(&list_index_buffer);
Expand Down
55 changes: 55 additions & 0 deletions src/startup_stubs/list_compute_root.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

#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
82 changes: 82 additions & 0 deletions tests/startup_compute_root.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdint>
#include <cstdio>

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;
}
Loading