From fa46de0068546f52d8ec4421e9deef3792d8600f Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 05:04:59 +0100 Subject: [PATCH 1/3] mesh57: name the part when a fixed mesh profile does not match prepare_native_mesh57 compared six parts of the reviewed profile (normalized descriptor, state_a, state_b, root blob, mesh shader, pixel shader) and the end of the file in one expression and threw a single "profile input bytes differ". The message now names the first failing check: the part and whether its length or its content differs, or trailing bytes after the pixel shader. The prefix, the check order and the set of accepted and refused profiles are unchanged. --- src/startup_stubs/native_mesh57.inl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/startup_stubs/native_mesh57.inl b/src/startup_stubs/native_mesh57.inl index 0063aa47bb..8acc02e78f 100644 --- a/src/startup_stubs/native_mesh57.inl +++ b/src/startup_stubs/native_mesh57.inl @@ -298,18 +298,25 @@ void prepare_native_mesh57(Wrapper* pipeline) if (direct_heap && (!file.read(reinterpret_cast(&heap_sgpr), sizeof(heap_sgpr)) || !(root_heap_flags(root) & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED))) throw std::runtime_error("missing MS resource heap mapping"); - const auto match = [&](UINT part, const void* bytes, size_t size) { + const auto match = [&](UINT part, const char* name, const void* bytes, size_t size) { if (size != profile.lengths[part]) - return false; + throw std::runtime_error(std::string("profile input bytes differ: ") + name + + " length " + std::to_string(profile.lengths[part]) + + " != " + std::to_string(size)); if (!size) - return true; + return; std::string copy(size, 0); - return file.read(copy.data(), size) && !std::memcmp(copy.data(), bytes, size); + if (!file.read(copy.data(), size) || std::memcmp(copy.data(), bytes, size)) + throw std::runtime_error(std::string("profile input bytes differ: ") + name + " content"); }; - if (!match(0, normalized.data(), normalized.size()) || !match(1, info->state_a.data(), info->state_a.size()) || - !match(2, info->state_b.data(), info->state_b.size()) || !match(3, root_blob.data(), root_blob.size()) || - !match(4, ms_bytes.data(), ms_bytes.size()) || !match(5, ps_bytes.data(), ps_bytes.size()) || file.peek() != EOF) - throw std::runtime_error("profile input bytes differ"); + match(0, "normalized descriptor", normalized.data(), normalized.size()); + match(1, "state_a", info->state_a.data(), info->state_a.size()); + match(2, "state_b", info->state_b.data(), info->state_b.size()); + match(3, "root blob", root_blob.data(), root_blob.size()); + match(4, "mesh shader", ms_bytes.data(), ms_bytes.size()); + match(5, "pixel shader", ps_bytes.data(), ps_bytes.size()); + if (file.peek() != EOF) + throw std::runtime_error("profile input bytes differ: trailing bytes after the pixel shader"); if (!profile.targets.NumRenderTargets || profile.targets.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT || ((profile.depth.DepthEnable || profile.depth.StencilEnable) && profile.depth_format == DXGI_FORMAT_UNKNOWN) || profile.samples.Count != 1 || From af406982af2ee88496ad59df1bd9751f29fb0337 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 08:35:53 +0100 Subject: [PATCH 2/3] tests: check the slot-57 descriptor content refusal text Capture the fixture's log and require the exact refusal line for the unreviewed fixed mesh state, so a wrong part name or message fails. --- tests/startup_indirect_draw_indexed.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index e4fa387b6e..46d69e69ee 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -2053,7 +2053,8 @@ bool fixed_mesh_create_contract(ID3D12Device* guest) #include "startup_indirect_mesh_lease.inl" } // namespace -static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer) +static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer, + const std::wstring& log_path) { const bool mrt = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_MRT", nullptr, 0) != 0; const bool waterfall=GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_WATERFALL",nullptr,0)!=0; @@ -2070,6 +2071,8 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, if (std::filesystem::create_directory(cache)) break; } check(SetEnvironmentVariableW(L"X2W_SHADER_CACHE", cache.c_str()) ? S_OK : E_FAIL, "native mesh cache"); + DeleteFileW(log_path.c_str()); + check(SetEnvironmentVariableW(L"X2W_TRAP_LOG", log_path.c_str()) ? S_OK : E_FAIL, "native mesh log"); // 2000 other cache files: the profile lookups below must not open a name the cache does not hold. for (UINT64 i = 0; i < 2000; ++i) { static const char* const others[]{"req_%016llx.c67", "%016llx.txt", "%016llx.cs.cso", "req_%016llx.ia"}; @@ -2270,6 +2273,20 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, const auto pso = create(); fields[15] = 1; // Same stages and root, unreviewed fixed pipeline state. const auto mismatched = create(); + { + // native_mesh57.inl: throw std::runtime_error(std::string("profile input bytes differ: ") + name + " content"); + char expected[128]; + std::snprintf(expected, sizeof(expected), + "x2w-render native slot57 mesh %016llx refused: profile input bytes differ: normalized descriptor content", + key); + std::ifstream log{std::filesystem::path(log_path)}; + std::string line; + while (std::getline(log, line) && line != expected) {} + if (!log) { + std::fprintf(stderr, "unreviewed fixed mesh state: missing log line '%s'\n", expected); + return 1; + } + } // 64 more fixed states without a profile. Only the two profiles above may be opened. for (UINT64 extra = 2; extra < 66; ++extra) { fields[15] = extra; @@ -2358,6 +2375,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, } std::printf("fixed mesh state archives matching creation bytes: accepted=%d refused=%d\n", saw_valid, saw_other); if (!saw_valid || !saw_other) return 1; + DeleteFileW(log_path.c_str()); std::filesystem::remove_all(cache); return 0; } @@ -2491,7 +2509,7 @@ int main(int argc, char** argv) try const D3D12_ROOT_SIGNATURE_DESC graphics_desc{0, nullptr, 0, nullptr, root_flags}; const auto writer = create_root(device.Get(), writer_desc); if (mesh && GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57", nullptr, 0)) - return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get()); + return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get(), log_path); wchar_t mesh86_dir[MAX_PATH]{}; if (mesh && GetEnvironmentVariableW(L"X2W_MESH86_FIXTURE_DIR", mesh86_dir, MAX_PATH)) { const bool depth_only = GetEnvironmentVariableA("X2W_MESH86_FIXTURE_DEPTH", nullptr, 0) != 0; From 50900f60140cf8a47ee9c79fd336815a3913a920 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:59:45 +0100 Subject: [PATCH 3/3] tests: check the slot-57 length and trailing-bytes refusal texts --- tests/startup_indirect_draw_indexed.cpp | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 46d69e69ee..835026a24a 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -2298,6 +2298,47 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, std::printf("native fixed mesh profile lookups %ld, opens %ld (2 profiles, 2000 other cache files)\n", lookups, opens); if (lookups != 66 || opens != 2) return 1; + const auto expect_profile_refusal = [&](const char* reason) { + char expected[160]; + std::snprintf(expected, sizeof(expected), + "x2w-render native slot57 mesh %016llx refused: profile input bytes differ: %s", + key, reason); + std::ifstream log{std::filesystem::path(log_path)}; + std::string line; + while (std::getline(log, line) && line != expected) {} + if (log) + return true; + std::fprintf(stderr, "malformed fixed mesh profile: missing log line '%s'\n", expected); + return false; + }; + // Reuse the indexed profile filename with the original descriptor after checking lookup counts. + fields[15] = 0; + const auto profile_path = cache / name; + auto wrong_length = profile; + ++wrong_length.lengths[0]; + { + std::fstream file(profile_path, std::ios::binary | std::ios::in | std::ios::out); + file.write(reinterpret_cast(&wrong_length), sizeof(wrong_length)); + file.close(); + if (!file) + return 1; + } + create(); + if (!expect_profile_refusal("normalized descriptor length 769 != 768")) + return 1; + { + std::fstream file(profile_path, std::ios::binary | std::ios::in | std::ios::out); + file.write(reinterpret_cast(&profile), sizeof(profile)); + file.seekp(0, std::ios::end); + file.put('\0'); + file.close(); + if (!file) + return 1; + } + create(); + if (!expect_profile_refusal("trailing bytes after the pixel shader")) + return 1; + fields[15] = 1; state_a.fill(0); state_b.fill(0); check(SetEnvironmentVariableA("X2W_MESH57_CAPTURE_STATE", "1") ? S_OK : E_FAIL, "enable fixed-state archive");