From d0af26b598f11d8099896c2c5ed0fbbd103d4360 Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 06:08:05 +0000 Subject: [PATCH] runtime: read declared CBV and past-table slots in slot 57 meshes A captured depth-only slot 57 request reads constant data through a CBV range of its creation root and through one descriptor past the last declared range. A table is only a heap region on the console, so both reads are valid there; the native loader refused them. Read a slot a CBV range declares, and a slot past the last declared range, as a byte window: s_buffer_load carries no format, filtering or typed element, so the descriptor's memory read as raw dwords is the same value. The submission still resolves each table slot's token and refuses anything that is not a buffer SRV or a CBV, so an undeclared slot with a wrong view class fails before its descriptor table is bound. Add native_fixed_mesh57_cbv_*: the same MS reads the same dword through a table slot declared as a CBV (PSO created, pixels match the SRV variant) and through one declared as a UAV (still refused as a buffer window). Validation: - native_fixed_mesh57_* warp+hardware: 26/26. - Captured key 3e82436207e34109 outside the repository: the raw MS still translates to 12 680 bytes with the partial-EXEC opt-in. Refs #2413 --- CMakeLists.txt | 9 +++++++ src/startup_stubs/native_mesh57.inl | 26 ++++++++++++++++--- tests/startup_indirect_draw_indexed.cpp | 34 ++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da721cd70..c5e1c677cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1979,6 +1979,15 @@ if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${ add_test(NAME native_fixed_mesh57_constant_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh) set_tests_properties(native_fixed_mesh57_constant_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CONSTANT=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}") + # The same MS reads the same dword through table slot 3 of root parameter 1. Declared as a + # CBV range it is a byte window over the descriptor's memory; declared as a UAV range the + # creation still refuses it. + add_test(NAME native_fixed_mesh57_cbv_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh) + set_tests_properties(native_fixed_mesh57_cbv_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CBV=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}") + add_test(NAME native_fixed_mesh57_cbv_uav_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh) + set_tests_properties(native_fixed_mesh57_cbv_uav_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CBV_UAV=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}") add_test(NAME native_fixed_mesh57_mask_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh) set_tests_properties(native_fixed_mesh57_mask_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_MRT=1;X2W_TEST_NATIVE_MESH57_MASK=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}") diff --git a/src/startup_stubs/native_mesh57.inl b/src/startup_stubs/native_mesh57.inl index 8acc02e78f..eb954b5ee9 100644 --- a/src/startup_stubs/native_mesh57.inl +++ b/src/startup_stubs/native_mesh57.inl @@ -42,7 +42,10 @@ const char* bind_mesh57_buffers(Wrapper* self, Pass& pass, ID3D12GraphicsCommand std::memcpy(words, reinterpret_cast(entry), sizeof(words)); if (words[0] == view_token_magic) { ViewRecord record{}; - if (!token_view(words, record) || record.slot != 18) return "MS descriptor table slot is not an SRV"; + if (!token_view(words, record) || (record.slot != 18 && record.slot != 17)) + return "MS descriptor table slot is not an SRV or CBV"; + if (record.slot == 17 && record.desc_bytes < 12) + return "MS descriptor table CBV lacks its buffer location and size"; } else if (words[3] != 0x31016fac || (words[1] & 0xffff0000)) { return "unsupported MS native byte buffer descriptor"; } @@ -370,7 +373,9 @@ void prepare_native_mesh57(Wrapper* pipeline) if (param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_SRV || b.byte_offset) throw std::runtime_error("MS root buffer requires a root SRV"); } else { - if (b.kind != x2w::ComputeViewKind::buffer_srv || param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + if ((b.kind != x2w::ComputeViewKind::buffer_srv && b.kind != x2w::ComputeViewKind::byte_window_srv && + b.kind != x2w::ComputeViewKind::heap_buffer_srv) || + param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) throw std::runtime_error("MS table read requires a scalar SRV"); // Validate this creation root's range even when reflection already classified the slot. using Table = x2w::ComputeViewBinding::ScalarTable; @@ -378,7 +383,22 @@ void prepare_native_mesh57(Wrapper* pipeline) throw std::runtime_error("MS table binding is not an SRV"); b.scalar_table = Table::unknown; x2w::apply_scalar_table_layout(b, param.DescriptorTable); - if (b.scalar_table != x2w::ComputeViewBinding::ScalarTable::srv || b.byte_offset % 32) + // A CBV range is read here through its memory as raw dwords, exactly like a + // byte-window SRV: s_buffer_load has no format, filtering or typed element. + // The console also reads descriptors past the last declared range (a table is + // just a heap region); those stay unclassified here and the submission resolves + // the slot's token, refusing anything that is not a buffer SRV or a CBV. + using ScalarTable = x2w::ComputeViewBinding::ScalarTable; + uint64_t declared_slots = 0; + for (UINT r = 0; r < param.DescriptorTable.NumDescriptorRanges; ++r) { + const auto& range = param.DescriptorTable.pDescriptorRanges[r]; + const uint64_t first = range.OffsetInDescriptorsFromTableStart == D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND + ? declared_slots : range.OffsetInDescriptorsFromTableStart; + declared_slots = (std::max)(declared_slots, first + range.NumDescriptors); + } + const bool past_table = b.scalar_table == ScalarTable::unknown && b.byte_offset / 32 >= declared_slots; + if ((b.scalar_table != ScalarTable::srv && b.scalar_table != ScalarTable::declared_cbv && + !past_table) || b.byte_offset % 32) throw std::runtime_error("MS buffer slot outside a verified SRV range"); } reads.push_back({b.root_parameter, b.byte_offset, b.required_bytes, direct}); diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 3cdc6c77a8..4e6ff9b98c 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -2390,7 +2390,11 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, const bool waterfall=GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_WATERFALL",nullptr,0)!=0; const bool pixel_heap=waterfall || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_PIXEL_HEAP",nullptr,0)!=0; const bool heap = pixel_heap || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_UINT_HEAP",nullptr,0) != 0; - const bool buffers = heap || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_BUFFERS", nullptr, 0) != 0; + // The CBV variants keep the buffers shape: the same MS reads the same dword through a table slot + // that the root signature declares as a constant buffer (positive) or a UAV (negative control). + const bool cbv_slot = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CBV", nullptr, 0) != 0; + const bool cbv_uav = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CBV_UAV", nullptr, 0) != 0; + const bool buffers = heap || cbv_slot || cbv_uav || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_BUFFERS", nullptr, 0) != 0; const bool constants = buffers || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CONSTANT", nullptr, 0) != 0; const bool compare_vcc = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_COMPARE_VCC", nullptr, 0) != 0; const bool varying = compare_vcc || constants || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_VARYING", nullptr, 0) != 0; @@ -2426,6 +2430,10 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, params[i].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; params[i].DescriptorTable = {1, &ranges[i]}; } + // Slot 3 of table 1 holds the dword the MS reads at +4. A CBV range is read as its + // memory; a UAV range stays refused. + if (cbv_slot || cbv_uav) + ranges[1] = {cbv_uav ? D3D12_DESCRIPTOR_RANGE_TYPE_UAV : D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 4, 0, 1, 0}; params[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV; params[3].Descriptor = {0, 3}; } @@ -2609,6 +2617,30 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, return pso; }; const auto pso = create(); + const auto expect_log_line = [&](const char* text) { + std::ifstream log{std::filesystem::path(log_path)}; + std::string line; + while (std::getline(log, line) && line != text) {} + if (!log) std::fprintf(stderr, "missing log line '%s'\n", text); + return static_cast(log); + }; + if (cbv_slot || cbv_uav) { + char expected[192]; + std::snprintf(expected, sizeof(expected), + cbv_slot ? "x2w-render native slot57 mesh %016llx ready" + : "x2w-render native slot57 mesh %016llx refused: MS buffer slot outside a verified SRV range", + key); + if (!expect_log_line(expected)) return 1; + if (cbv_uav) { + // A slot inside a declared UAV range is not a buffer window; the creation must refuse it + // before the draw path, unlike the CBV slot above that resolves to the same memory. + std::printf("native fixed mesh CBV control: UAV table slot refused as a buffer window\n"); + DeleteFileW(log_path.c_str()); + std::filesystem::remove_all(cache); + return 0; + } + std::printf("native fixed mesh CBV table slot: PSO created and read as a byte window\n"); + } if (compare_vcc) std::printf("native fixed mesh compare mask: reviewed stage pair linked and created a color PSO\n"); fields[15] = 1; // Same stages and root, unreviewed fixed pipeline state.