From 85779052d2619e00e1e9b9c11c7c702c0cd72592 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:27:23 +0100 Subject: [PATCH 1/3] shader: admit depth-only slot 57 mesh pipelines without a pixel stage --- docs/experiments/native-fixed-mesh57.md | 6 + src/startup_stubs/mesh86_cache.inl | 5 +- src/startup_stubs/native_mesh57.inl | 77 +++++++--- tests/cmake/native_mesh57_depth_only.cmake | 7 + tests/startup_indirect_draw_indexed.cpp | 164 ++++++++++++++------- 5 files changed, 186 insertions(+), 73 deletions(-) create mode 100644 tests/cmake/native_mesh57_depth_only.cmake diff --git a/docs/experiments/native-fixed-mesh57.md b/docs/experiments/native-fixed-mesh57.md index c5f456dfc1..9e2fe5bcaf 100644 --- a/docs/experiments/native-fixed-mesh57.md +++ b/docs/experiments/native-fixed-mesh57.md @@ -81,6 +81,12 @@ The three fixture variants use one color target, six color targets with depth/st The ten tests above passed on the working tree based on `671b9ac`, Windows build 26200, with the debug layer enabled on WARP and an NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1656). +## Mesh-only depth + +A reviewed mesh-only profile specifies zero color targets, enabled depth writes and a typed DSV format. The creation descriptor has a zero PS pointer and length, and the exact PS span in the profile is empty. Versions 2–5 use a zeroed pixel entry and retain their MS layout and bindings. + +`native_fixed_mesh57_depth_only_hardware` checks all eight D32 depth texels after slot 61 execution. The WARP fixture checks the physical-adapter refusal, which follows the slot-86 mesh-only guard for a known WARP device removal. Both fixtures check missing and changed profiles, a color target, a zero depth-write mask and a typeless DSV. + ## Per-pixel texture selection The `native_fixed_mesh57_waterfall_{warp,hardware}` fixture draws a triangle covering eight pixels. The guest PS uses READFIRSTLANE, CMPX, an indexed descriptor load, IMAGE_SAMPLE and a WREXEC retry. Neighboring pixels select different Texture2D views. With a unit UV gradient the two views return red and green from mip 1. The `waterfall_fine` variant holds UV constant and both views return blue from mip 0. The shader computes quad derivatives before sampling the per-pixel texture. Both gradient cases passed on WARP and the RTX 4060 Laptop with the debug layer enabled. Run `ctest --preset dev --no-tests=error -R '^native_fixed_mesh57_(pixel_heap|waterfall(_fine)?)_(warp|hardware)$'` to reproduce. diff --git a/src/startup_stubs/mesh86_cache.inl b/src/startup_stubs/mesh86_cache.inl index 1696db4c34..8abde8bbaa 100644 --- a/src/startup_stubs/mesh86_cache.inl +++ b/src/startup_stubs/mesh86_cache.inl @@ -96,7 +96,8 @@ struct Mesh86Request { std::vector ms, ps, stream; }; -bool mesh86_hardware_depth() +// A mesh-only depth fixture removed the device on WARP. Both mesh paths use this guard. +bool mesh_hardware_depth() { x2w_startup::ComPtr factory; x2w_startup::ComPtr adapter; @@ -377,7 +378,7 @@ ID3D12PipelineState* try_cached_mesh86(const D3D12_PIPELINE_STATE_STREAM_DESC& d std::snprintf(why, why_size, "slot86 mesh request %016llx: cache key, stage or bytecode mismatch", key); return nullptr; } - if (!ps && !mesh86_hardware_depth()) { + if (!ps && !mesh_hardware_depth()) { std::snprintf(why, why_size, "slot86 mesh request %016llx: depth-only requires a physical adapter", key); return nullptr; } diff --git a/src/startup_stubs/native_mesh57.inl b/src/startup_stubs/native_mesh57.inl index 3cb399a6e7..cb51a71dbf 100644 --- a/src/startup_stubs/native_mesh57.inl +++ b/src/startup_stubs/native_mesh57.inl @@ -410,41 +410,67 @@ void prepare_native_mesh57(Wrapper* pipeline) if (!sdk_length || sdk_length >= MAX_PATH) return note_mesh57_outcome(Mesh57Outcome::disabled); const auto* info = pipeline_info(pipeline); - if (!info || !info->fixed_ms || info->desc.size() != 0x300) + const auto refuse = [](const char* reason) { + static LONG refusals; + if (first_calls(refusals, 12)) log("x2w-render native slot57 mesh refused: %s", reason); + }; + if (!info || info->desc.size() != 0x300) { + refuse("unsupported fixed descriptor"); return note_mesh57_outcome(Mesh57Outcome::unsupported_stage_or_descriptor); - if (!info->fixed_ps) - return note_mesh57_outcome(Mesh57Outcome::ps_absent); - const auto& ms_bytes = *info->fixed_ms; - const auto& ps_bytes = *info->fixed_ps; + } u64 fields[0x300 / sizeof(u64)]; std::memcpy(fields, info->desc.data(), sizeof(fields)); + const bool depth_only = !fields[5] && !fields[6]; + if (!info->fixed_ms || (!depth_only && !info->fixed_ps)) { + refuse("unsupported or uncaptured shader stages"); + // A nonzero PS pointer without any PS bytes fails capture and cannot use the depth-only path. + if (fields[5] && !fields[6]) + return note_mesh57_outcome(Mesh57Outcome::ps_absent); + return note_mesh57_outcome(Mesh57Outcome::unsupported_stage_or_descriptor); + } + const auto& ms_bytes = *info->fixed_ms; + const std::vector empty; + const auto& ps_bytes = depth_only ? empty : *info->fixed_ps; auto* root = as_wrapper(reinterpret_cast(fields[0])); if (!root || root->own().kind != root_signature_kind || !root->own().real || !root_info(root) || - fields[2] != info->state_a.size() || fields[4] != info->state_b.size()) + fields[2] != info->state_a.size() || fields[4] != info->state_b.size()) { + if (depth_only) refuse("missing depth-only creation root or fixed state"); return note_mesh57_outcome(Mesh57Outcome::missing_creation_root_or_state); + } std::vector root_blob; { x2w_startup::ExclusiveNoteLock guard(note_lock); const auto it = root_blobs().find(root); - if (it == root_blobs().end()) + if (it == root_blobs().end()) { + if (depth_only) refuse("missing depth-only creation root blob"); return note_mesh57_outcome(Mesh57Outcome::missing_creation_root_or_state); + } root_blob = it->second; } constexpr char revision[] = "x2w-startup-mesh-57-4"; const u64 key = fnv_part(root_blob, fnv_part(ps_bytes, fnv_part(ms_bytes, fnv_bytes(revision, sizeof(revision) - 1)))); const auto normalized = x2w_startup::normalize_mesh57_descriptor(info->desc); const auto variant = fnv_part(info->state_b, fnv_part(info->state_a, fnv_part(normalized, key))); - if (!cache_path(path, L"", variant, L".mesh57-state")) + if (!cache_path(path, L"", variant, L".mesh57-state")) { + if (depth_only) refuse("depth-only profile cache unavailable"); return note_mesh57_outcome(Mesh57Outcome::profile_absent); + } InterlockedIncrement(&mesh57_profile_lookups); // Profiles are placed before the process starts and most creations have none: skip the open when the // cache listing has no such name. A profile written while the process runs is read by the next one. - if (cache_lookup(L"", variant, L".mesh57-state") == x2w_startup::CacheLookup::absent) + if (cache_lookup(L"", variant, L".mesh57-state") == x2w_startup::CacheLookup::absent) { + if (depth_only) { + static LONG missing; + if (first_calls(missing, 12)) log("x2w-render native slot57 mesh %016llx refused: depth-only profile absent", key); + } return note_mesh57_outcome(Mesh57Outcome::profile_absent); + } InterlockedIncrement(&mesh57_profile_opens); std::ifstream file(std::filesystem::path(path), std::ios::binary); - if (!file) + if (!file) { + if (depth_only) refuse("depth-only profile could not be opened"); return note_mesh57_outcome(Mesh57Outcome::profile_open_failed); + } auto refusal = Mesh57Outcome::profile_exception; const auto profile_error = [&](Mesh57Outcome reason, const auto& message) { refusal = reason; @@ -466,6 +492,8 @@ void prepare_native_mesh57(Wrapper* pipeline) } else if (std::memcmp(profile.magic, "X2WM571", 8)) { throw profile_error(Mesh57Outcome::profile_version, "unknown fixed profile version"); } + if (depth_only && (pixel_heap || entry.enable || entry.address || entry.wave_size)) + throw profile_error(Mesh57Outcome::profile_pixel_entry, "depth-only profile contains pixel entry metadata"); x2w_startup::Mesh57ConstantEntry mapping{}; if (mapped) { if (!file.read(reinterpret_cast(&mapping), sizeof(mapping)) || mapping.root_parameter >= 16 || @@ -507,12 +535,24 @@ void prepare_native_mesh57(Wrapper* pipeline) match(5, "pixel shader", ps_bytes.data(), ps_bytes.size()); if (file.peek() != EOF) throw profile_error(Mesh57Outcome::profile_trailing_bytes, "profile input bytes differ: trailing bytes after the pixel shader"); - if (!profile.targets.NumRenderTargets || profile.targets.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT || + if (depth_only) { + if (profile.targets.NumRenderTargets) + throw profile_error(Mesh57Outcome::profile_attachment_state, "depth-only profile has color targets"); + if (!profile.depth.DepthEnable || profile.depth.DepthWriteMask != D3D12_DEPTH_WRITE_MASK_ALL) + throw profile_error(Mesh57Outcome::profile_attachment_state, "depth-only profile requires enabled depth writes"); + const auto format = profile.depth_format; + if (format != DXGI_FORMAT_D16_UNORM && format != DXGI_FORMAT_D32_FLOAT && + format != DXGI_FORMAT_D24_UNORM_S8_UINT && format != DXGI_FORMAT_D32_FLOAT_S8X24_UINT) + throw profile_error(Mesh57Outcome::profile_attachment_state, "depth-only profile requires a typed DSV format"); + } + if ((!depth_only && !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 || profile.samples.Quality || profile.sample_mask != UINT_MAX || (profile.wave_size != 32 && profile.wave_size != 64)) throw profile_error(Mesh57Outcome::profile_attachment_state, "unsupported fixed attachment or sample state"); + if (depth_only && !mesh_hardware_depth()) + throw profile_error(Mesh57Outcome::pipeline_refused, "depth-only mesh requires a physical adapter"); const std::string ms(ms_bytes.begin(), ms_bytes.end()), ps(ps_bytes.begin(), ps_bytes.end()); x2w::MeshStageLayout mesh_layout{profile.threads, profile.vertices, profile.primitives, profile.topology, profile.group_stride, profile.wave_size == 32}; @@ -602,7 +642,7 @@ void prepare_native_mesh57(Wrapper* pipeline) } } std::string ps_ir; - if (varying_pixel) { + if (!depth_only && varying_pixel) { auto pixel = x2w::translate_mesh_pixel_program(ps, entry.enable, entry.address, entry.wave_size, pixel_heap ? &guest_desc->Desc_1_1 : nullptr); if (pixel_heap) { if (pixel.pixel_heap_spans.empty()) throw std::runtime_error("missing PS texture heap reads"); @@ -617,24 +657,25 @@ void prepare_native_mesh57(Wrapper* pipeline) throw std::runtime_error("PS needs root or heap bindings"); x2w::validate_raster_link(native, pixel); ps_ir = std::move(pixel.dxil_ir); - } else { + } else if (!depth_only) { ps_ir = x2w::direct_gfx1013_constant_pixel(ps); } refusal = Mesh57Outcome::pipeline_refused; auto compiler = x2w::ShaderDxilCompiler::runtime_worker(sdk); const auto cache = std::filesystem::path(path).parent_path(); const auto ms_output = compiler.compile(native.dxil_ir, L"ms_6_6", cache, x2w::ShaderSourceFormat::dxil_ir); - const auto ps_output = - compiler.compile(ps_ir, L"ps_6_6", cache, x2w::ShaderSourceFormat::dxil_ir); ms_code.assign(ms_output.dxil.begin(), ms_output.dxil.end()); - ps_code.assign(ps_output.dxil.begin(), ps_output.dxil.end()); + if (!depth_only) { + const auto ps_output = compiler.compile(ps_ir, L"ps_6_6", cache, x2w::ShaderSourceFormat::dxil_ir); + ps_code.assign(ps_output.dxil.begin(), ps_output.dxil.end()); + } }; bool published = false; std::string native_refusal; try { prepare_native(); } catch (const x2w::UnsupportedComputeShader& error) { - if (!is_mesh57_group_index_refusal(error) || !allow_published_mesh57_pair()) throw; + if (depth_only || !is_mesh57_group_index_refusal(error) || !allow_published_mesh57_pair()) throw; if (!buffers || direct_heap) throw std::runtime_error("published MS57 pair does not describe this profile"); native_refusal = error.what(); @@ -669,7 +710,7 @@ void prepare_native_mesh57(Wrapper* pipeline) x2w::meshlet::MeshOnlyPipelineStream stream{}; stream.root_signature.value = reinterpret_cast(root); stream.ms.value = {ms_code.data(), ms_code.size()}; - stream.ps.value = {ps_code.data(), ps_code.size()}; + if (!depth_only) stream.ps.value = {ps_code.data(), ps_code.size()}; stream.blend.value = profile.blend; stream.sample_mask.value = profile.sample_mask; stream.rasterizer.value = profile.rasterizer; diff --git a/tests/cmake/native_mesh57_depth_only.cmake b/tests/cmake/native_mesh57_depth_only.cmake new file mode 100644 index 0000000000..dcc4b9c8ca --- /dev/null +++ b/tests/cmake/native_mesh57_depth_only.cmake @@ -0,0 +1,7 @@ +if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(backend warp hardware) + add_test(NAME native_fixed_mesh57_depth_only_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh) + set_tests_properties(native_fixed_mesh57_depth_only_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_DEPTH_ONLY=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}") + endforeach() +endif() diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 02b7c56c32..ee7d62dacd 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -1062,8 +1062,9 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{heap_kind, target_count, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; ComPtr heap; - check((cached_depth_only ? guest : device)->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)), - "create attachment heap"); + if (target_count) + check((cached_depth_only ? guest : device)->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)), + "create attachment heap"); std::vector rtvs; D3D12_CPU_DESCRIPTOR_HANDLE native_dsv{}; D3D12_CPU_DESCRIPTOR_HANDLE rtv{}; @@ -1071,7 +1072,7 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ using GetCpu = UINT64(WINAPI*)(IUnknown*, void*); rtv.ptr = slot(heap.Get(), 9)(heap.Get(), nullptr); native_dsv = native_object(device, guest, heap.Get())->GetCPUDescriptorHandleForHeapStart(); - } else { + } else if (heap) { rtv = heap->GetCPUDescriptorHandleForHeapStart(); } for (UINT i = 0; i < target_count; ++i) { @@ -1089,6 +1090,7 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ rtv.ptr += device->GetDescriptorHandleIncrementSize(heap_kind); } ComPtr fixed_depth; + const bool fixed_stencil = fixed_profile && fixed_profile->depth_format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT; ComPtr fixed_depth_heap; D3D12_CPU_DESCRIPTOR_HANDLE fixed_dsv{}, desktop_fixed_dsv{}; if (fixed_profile && fixed_profile->depth_format != DXGI_FORMAT_UNKNOWN) { @@ -1097,7 +1099,7 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; D3D12_CLEAR_VALUE initial_depth{}; initial_depth.Format = desc.Format; - initial_depth.DepthStencil = {0.25f, 3}; + initial_depth.DepthStencil = {0.25f, static_cast(fixed_stencil ? 3 : 0)}; fixed_depth = resource(device, desc, D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_STATE_COMMON, &initial_depth); const D3D12_DESCRIPTOR_HEAP_DESC descriptors{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1}; check(guest->CreateDescriptorHeap(&descriptors,IID_PPV_ARGS(&fixed_depth_heap)), "create fixture DSV heap"); @@ -1228,9 +1230,12 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ const UINT bound_targets = target_count - (refusal == Refusal::mesh_attachment_count ? 1 : 0); slot(wrapped, 50)(wrapped, bound_targets, rtvs.data(), FALSE, fixed_depth ? &fixed_dsv : nullptr); if (fixed_depth) { - list->ClearDepthStencilView(desktop_fixed_dsv, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 0.25f, 3, 0, nullptr); - using StencilRef = void(WINAPI*)(IUnknown*,UINT); - slot(wrapped,24)(wrapped,7); + const auto flags = fixed_stencil ? D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL : D3D12_CLEAR_FLAG_DEPTH; + list->ClearDepthStencilView(desktop_fixed_dsv, flags, 0.25f, fixed_stencil ? 3 : 0, 0, nullptr); + if (fixed_stencil) { + using StencilRef = void(WINAPI*)(IUnknown*,UINT); + slot(wrapped,24)(wrapped,7); + } } } std::vector> fixed_textures; @@ -1565,14 +1570,15 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_ } } if (fixed_depth) { + const UINT plane_count = fixed_stencil ? 2 : 1; const auto desc = fixed_depth->GetDesc(); D3D12_PLACED_SUBRESOURCE_FOOTPRINT planes[2]{}; UINT64 row_sizes[2]{}; - device->GetCopyableFootprints(&desc, 0, 2, 0, planes, nullptr, row_sizes, &bytes); + device->GetCopyableFootprints(&desc, 0, plane_count, 0, planes, nullptr, row_sizes, &bytes); const auto rb = make_buffer(device, bytes, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); ComputeCommands copy(device, kept_direct_queue(device), nullptr); transition(copy.list.Get(), fixed_depth.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_SOURCE); - for (UINT plane=0; plane<2; ++plane) { + for (UINT plane=0; planeUnmap(0,&untouched); if (!match) return false; - std::printf("%s: 8 depth/stencil texels matched, selected pixel %.2f/%u\n", - label,fixed_mesh_pixels==1?0.5:0.25,fixed_mesh_pixels==1?7:3); + std::printf("%s: 8 texels matched across %u planes, selected depth %.2f\n", + label, plane_count, fixed_mesh_pixels==1 ? 0.5 : 0.25); } return true; } @@ -2513,9 +2519,10 @@ bool fixed_mesh_create_contract(ID3D12Device* guest) } // namespace static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer, - const std::wstring& log_path) + const std::wstring& log_path, bool warp) { const bool outcomes = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_OUTCOMES", nullptr, 0) != 0; + const bool depth_only = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_DEPTH_ONLY", nullptr, 0) != 0; const bool mrt = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_MRT", nullptr, 0) != 0; char allocation_mode[16]{}; const bool guarded_allocation = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_GUARDED_ALLOC", @@ -2650,6 +2657,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, 0xf0800f08,0x00e50005,0xbeb43a34,0xbf85fff7,0xbefe043c, 0xf800180f,0x03020100,0xbf810000}; } + if (depth_only) ps.clear(); const auto ms_size = ms.size()*sizeof(UINT), ps_size = ps.size()*sizeof(UINT); const std::array expected_a{0x12345678, 0x9abcdef0}; const bool masked = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_MASK", nullptr, 0) != 0; @@ -2738,13 +2746,21 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, profile.depth.FrontFace = profile.depth.BackFace = { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_REPLACE, D3D12_COMPARISON_FUNC_ALWAYS}; } + if (depth_only) { + profile.targets = {}; + profile.depth = {}; + profile.depth.DepthEnable = TRUE; + profile.depth.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + profile.depth.DepthFunc = D3D12_COMPARISON_FUNC_GREATER_EQUAL; + profile.depth_format = DXGI_FORMAT_D32_FLOAT; + } { std::ofstream out(cache / name, std::ios::binary); const auto put = [&](const void* data, size_t n) { out.write(static_cast(data), n); }; put(&profile, sizeof(profile)); if (varying) { const UINT position_x = (compare_vcc || waterfall) ? 1u<<8 : 0; - const x2w_startup::Mesh57PixelEntry entry{position_x,position_x,64}; + const x2w_startup::Mesh57PixelEntry entry{position_x,position_x,depth_only ? 0u : 64u}; put(&entry,sizeof(entry)); if (constants) { const x2w_startup::Mesh57ConstantEntry mapping{12,4,1}; @@ -2763,7 +2779,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, put(state_b.data(), sizeof(state_b)); put(blob->GetBufferPointer(), blob->GetBufferSize()); put(ms.data(), ms_size); - put(ps.data(), ps_size); + if (ps_size) put(ps.data(), ps_size); if (!out) return 1; } @@ -2775,7 +2791,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, fields[0] = reinterpret_cast(root.Get()); fields[1] = reinterpret_cast(state_a.data()); fields[3] = reinterpret_cast(state_b.data()); - fields[5] = reinterpret_cast(ps.data()); + fields[5] = ps_size ? reinterpret_cast(ps.data()) : 0; fields[13] = reinterpret_cast(ms.data()); const auto create = [&] { ComPtr pso; @@ -2786,11 +2802,29 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, return pso; }; if (outcomes) { + // The mesh-only creation reaches the profile lookup with an empty PS span. fields[5] = fields[6] = 0; create(); fields[5] = reinterpret_cast(ps.data()); fields[6] = ps_size; } + const auto log_file = std::filesystem::path(log_path); + const auto has_native_pso = [&](IUnknown* candidate) { + return bool(native_object(device, guest, candidate, true)); + }; + const auto logged_refusal = [&](std::uintmax_t offset, const char* reason) { + char expected[180]; + std::snprintf(expected, sizeof(expected), "x2w-render native slot57 mesh %016llx refused: %s", key, reason); + std::ifstream log(log_file, std::ios::binary); + log.seekg(static_cast(offset)); + std::string line; + while (std::getline(log, line)) { + if (!line.empty() && line.back() == '\r') line.pop_back(); + if (line == expected) return true; + } + std::fprintf(stderr, "fixed mesh profile: missing appended log line '%s'\n", expected); + return false; + }; const auto pso = create(); const auto expect_log_line = [&](const char* text) { std::ifstream log{std::filesystem::path(log_path)}; @@ -2825,30 +2859,22 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, 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. const auto mismatched = create(); - { - 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) { + if (!logged_refusal(0, "profile input bytes differ: normalized descriptor content")) return 1; + // Additional fixed states have no profile. Only the two profiles above may be opened. + const UINT extra_limit = depth_only ? 3 : 66; + const auto absent_profile_offset = std::filesystem::file_size(log_file); + for (UINT64 extra = 2; extra < extra_limit; ++extra) { fields[15] = extra; - create(); + const auto missing = create(); + if (depth_only && (has_native_pso(missing.Get()) || !logged_refusal(absent_profile_offset, "depth-only profile absent"))) + return 1; } if (outcomes) { const char* prefix = "x2w-render native slot57 preparation:"; const auto line = render_totals_line(guest, log_path, prefix); const auto expected = std::string(prefix) + - " disabled 0 ps_absent 1 unsupported_stage_or_descriptor 0 missing_creation_root_or_state 0" - " profile_absent 64 profile_open_failed 0 profile_rejected_header 0 profile_rejected_pixel_entry 0" + " disabled 0 ps_absent 0 unsupported_stage_or_descriptor 0 missing_creation_root_or_state 0" + " profile_absent 65 profile_open_failed 0 profile_rejected_header 0 profile_rejected_pixel_entry 0" " profile_rejected_version 0 profile_rejected_constants 0 profile_rejected_root_mapping 0" " profile_rejected_view_count 0 profile_rejected_view_entries 0 profile_rejected_view_mapping 0" " profile_rejected_heap_mapping 0 profile_rejected_input_length 0 profile_rejected_input_content 1" @@ -2863,7 +2889,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, LONG lookups = -1, opens = -1; x2w_d3d12_mesh57_profile_stats(&lookups, &opens); std::printf("native fixed mesh profile lookups %ld, opens %ld (2 profiles, 2000 other cache files)\n", lookups, opens); - if (lookups != 66 || opens != 2) + if (lookups != static_cast(extra_limit) + (outcomes ? 1 : 0) || opens != 2) return 1; // Reuse the indexed profile filename with the original descriptor after checking lookup counts. fields[15] = 0; @@ -2874,7 +2900,6 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, if (!file.read(original_profile.data(), original_profile.size())) return 1; } - const auto log_file = std::filesystem::path(log_path); const auto write_profile = [&](const char* data, size_t size) { std::ofstream file(profile_path, std::ios::binary | std::ios::trunc); file.write(data, size); @@ -2888,27 +2913,60 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, std::fprintf(stderr, "could not write malformed fixed mesh profile\n"); return false; } - create(); + const auto refused = create(); if (!write_profile(original_profile.data(), original_profile.size())) { std::fprintf(stderr, "could not restore original fixed mesh profile\n"); return false; } - char expected[160]; - std::snprintf(expected, sizeof(expected), - "x2w-render native slot57 mesh %016llx refused: %s", key, reason); - std::ifstream log(log_file, std::ios::binary); - log.seekg(static_cast(log_offset)); - std::string line; - while (std::getline(log, line)) { - if (!line.empty() && line.back() == '\r') - line.pop_back(); - if (line == expected) - return true; - } - std::fprintf(stderr, "malformed fixed mesh profile: missing appended log line '%s'\n", expected); - return false; + return logged_refusal(log_offset, reason) && (!depth_only || !has_native_pso(refused.Get())); }; + if (depth_only) { + if (has_native_pso(pso.Get()) == warp || has_native_pso(mismatched.Get())) { + std::fprintf(stderr, "depth-only fixture: unexpected native PSO availability\n"); + return 1; + } + const auto reject = [&](const x2w_startup::Mesh57Profile& state, const char* reason) { + auto input = original_profile; + std::memcpy(input.data(), &state, sizeof(state)); + return check_profile_refusal(input.data(), input.size(), reason); + }; + auto color = profile; + color.targets.NumRenderTargets = 1; + color.targets.RTFormats[0] = format; + auto read_only = profile; + read_only.depth.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; + auto typeless = profile; + typeless.depth_format = DXGI_FORMAT_R32_TYPELESS; + if (!reject(color, "depth-only profile has color targets") || + !reject(read_only, "depth-only profile requires enabled depth writes") || + !reject(typeless, "depth-only profile requires a typed DSV format")) return 1; + // A nonzero pointer with zero PS length is malformed, even with a reviewed depth profile. + fields[5] = reinterpret_cast(ms.data()); + const auto malformed = create(); + fields[5] = 0; + if (has_native_pso(malformed.Get())) return 1; + if (warp) { + if (!logged_refusal(0, "depth-only mesh requires a physical adapter")) return 1; + } else { + D3D12_INDIRECT_ARGUMENT_DESC arg{}; + arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH; + D3D12_COMMAND_SIGNATURE_DESC desc{sizeof(D3D12_DISPATCH_MESH_ARGUMENTS), 1, &arg, 0}; + ComPtr signature; + check(guest->CreateCommandSignature(&desc, nullptr, IID_PPV_ARGS(&signature)), "depth-only mesh signature"); + const auto work = writer_pipeline(device, writer, "write_one_mesh_group"); + const auto verify = [&](IUnknown* pipeline, bool draws, const char* label) { + return run(device, guest, writer, work.Get(), root.Get(), pipeline, signature.Get(), DrawKind::mesh, + false, draws ? Refusal::none : Refusal::mesh_pending, label, nullptr, false, nullptr, + false, false, 0, false, false, nullptr, nullptr, false, draws ? 1 : 2, &profile); + }; + if (!verify(pso.Get(), true, "depth-only native fixed mesh") || + !verify(mismatched.Get(), false, "depth-only fixed mesh with changed state")) return 1; + } + DeleteFileW(log_path.c_str()); + std::filesystem::remove_all(cache); + return 0; + } if (!check_profile_refusal(original_profile.data(), sizeof(profile) - 1, "invalid profile header")) return 1; const bool constants_only = constants && !buffers; @@ -3250,7 +3308,7 @@ int main(int argc, char** argv) try return ok ? 0 : 1; } if (mesh && GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57", nullptr, 0)) - return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get(), log_path); + return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get(), log_path, warp); 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 043b7baefabb96a03039361d285143102a9bcf42 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:59:14 +0100 Subject: [PATCH 2/3] tests: cover the remaining slot 57 preparation outcomes --- tests/startup_indirect_draw_indexed.cpp | 47 +++++++++++++++++-------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index ee7d62dacd..b14732ff84 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -2869,20 +2869,39 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, if (depth_only && (has_native_pso(missing.Get()) || !logged_refusal(absent_profile_offset, "depth-only profile absent"))) return 1; } - if (outcomes) { - const char* prefix = "x2w-render native slot57 preparation:"; - const auto line = render_totals_line(guest, log_path, prefix); - const auto expected = std::string(prefix) + - " disabled 0 ps_absent 0 unsupported_stage_or_descriptor 0 missing_creation_root_or_state 0" - " profile_absent 65 profile_open_failed 0 profile_rejected_header 0 profile_rejected_pixel_entry 0" - " profile_rejected_version 0 profile_rejected_constants 0 profile_rejected_root_mapping 0" - " profile_rejected_view_count 0 profile_rejected_view_entries 0 profile_rejected_view_mapping 0" - " profile_rejected_heap_mapping 0 profile_rejected_input_length 0 profile_rejected_input_content 1" - " profile_rejected_trailing_bytes 0 profile_rejected_attachment_state 0 profile_rejected_creation_root 0" - " profile_rejected_exception 0 lowering_reached 1 lowering_refused 0 pipeline_refused 0 ready 1"; - if (line != expected) { - std::fprintf(stderr, "expected preparation totals:\n%s\nreceived:\n%s\n", expected.c_str(), line.c_str()); - return 1; + if (outcomes || depth_only) { + const auto expect_outcomes = [&](const char* label, int unsupported_count) { + const char* prefix = "x2w-render native slot57 preparation:"; + const auto line = render_totals_line(guest, log_path, prefix); + const auto expected = std::string(prefix) + + " disabled 0 ps_absent 0 unsupported_stage_or_descriptor " + std::to_string(unsupported_count) + + " missing_creation_root_or_state 0 profile_absent " + (depth_only ? "1" : "65") + + " profile_open_failed 0 profile_rejected_header 0 profile_rejected_pixel_entry 0" + " profile_rejected_version 0 profile_rejected_constants 0 profile_rejected_root_mapping 0" + " profile_rejected_view_count 0 profile_rejected_view_entries 0 profile_rejected_view_mapping 0" + " profile_rejected_heap_mapping 0 profile_rejected_input_length 0 profile_rejected_input_content 1" + " profile_rejected_trailing_bytes 0 profile_rejected_attachment_state 0 profile_rejected_creation_root 0" + " profile_rejected_exception 0" + + (depth_only && warp ? " lowering_reached 0 lowering_refused 0 pipeline_refused 1 ready 0" + : " lowering_reached 1 lowering_refused 0 pipeline_refused 0 ready 1"); + if (line == expected) return true; + std::fprintf(stderr, "%s: expected preparation totals:\n%s\nreceived:\n%s\n", + label, expected.c_str(), line.c_str()); + return false; + }; + if (depth_only) { + if (!expect_outcomes("depth-only creation", 0)) return 1; + } else { + fields[15] = 0; + const auto ps_pointer = fields[5]; + // Retain the PS length and the rest of the reviewed descriptor. + fields[5] = 0; + create(); + if (!expect_outcomes("null PS pointer with nonzero length", 1)) return 1; + fields[5] = 1; // Nonzero address in the unreadable low 64 KiB. + create(); + fields[5] = ps_pointer; + if (!expect_outcomes("uncaptured PS with nonzero pointer and length", 2)) return 1; } } fields[15] = 1; From 99defe7ad4dc5356e27fa4e9c5b3c8cb679076d3 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:28:54 +0100 Subject: [PATCH 3/3] startup: name the slot 57 uncaptured pixel outcome --- docs/experiments/native-fixed-mesh57.md | 2 ++ src/startup_stubs/native_mesh57.inl | 6 +++--- tests/startup_indirect_draw_indexed.cpp | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/experiments/native-fixed-mesh57.md b/docs/experiments/native-fixed-mesh57.md index 9e2fe5bcaf..bcfeef6cec 100644 --- a/docs/experiments/native-fixed-mesh57.md +++ b/docs/experiments/native-fixed-mesh57.md @@ -87,6 +87,8 @@ A reviewed mesh-only profile specifies zero color targets, enabled depth writes `native_fixed_mesh57_depth_only_hardware` checks all eight D32 depth texels after slot 61 execution. The WARP fixture checks the physical-adapter refusal, which follows the slot-86 mesh-only guard for a known WARP device removal. Both fixtures check missing and changed profiles, a color target, a zero depth-write mask and a typeless DSV. +The native preparation total `ps_uncaptured` counts descriptors with a nonzero PS pointer and zero PS length. Mesh-only descriptors have both fields zero and proceed to profile lookup. + ## Per-pixel texture selection The `native_fixed_mesh57_waterfall_{warp,hardware}` fixture draws a triangle covering eight pixels. The guest PS uses READFIRSTLANE, CMPX, an indexed descriptor load, IMAGE_SAMPLE and a WREXEC retry. Neighboring pixels select different Texture2D views. With a unit UV gradient the two views return red and green from mip 1. The `waterfall_fine` variant holds UV constant and both views return blue from mip 0. The shader computes quad derivatives before sampling the per-pixel texture. Both gradient cases passed on WARP and the RTX 4060 Laptop with the debug layer enabled. Run `ctest --preset dev --no-tests=error -R '^native_fixed_mesh57_(pixel_heap|waterfall(_fine)?)_(warp|hardware)$'` to reproduce. diff --git a/src/startup_stubs/native_mesh57.inl b/src/startup_stubs/native_mesh57.inl index cb51a71dbf..21fc515da7 100644 --- a/src/startup_stubs/native_mesh57.inl +++ b/src/startup_stubs/native_mesh57.inl @@ -222,7 +222,7 @@ extern "C" __declspec(dllexport) void x2w_d3d12_mesh57_profile_stats(LONG* looku } enum class Mesh57Outcome { - disabled, ps_absent, unsupported_stage_or_descriptor, missing_creation_root_or_state, + disabled, ps_uncaptured, unsupported_stage_or_descriptor, missing_creation_root_or_state, profile_absent, profile_open_failed, profile_header, profile_pixel_entry, profile_version, profile_constants, profile_root_mapping, profile_view_count, profile_view_entries, profile_view_mapping, profile_heap_mapping, profile_input_length, profile_input_content, @@ -240,7 +240,7 @@ void note_mesh57_outcome(Mesh57Outcome outcome) void mesh57_outcome_line(char (&line)[1536]) { static constexpr const char* names[]{ - "disabled", "ps_absent", "unsupported_stage_or_descriptor", "missing_creation_root_or_state", + "disabled", "ps_uncaptured", "unsupported_stage_or_descriptor", "missing_creation_root_or_state", "profile_absent", "profile_open_failed", "profile_rejected_header", "profile_rejected_pixel_entry", "profile_rejected_version", "profile_rejected_constants", "profile_rejected_root_mapping", "profile_rejected_view_count", "profile_rejected_view_entries", "profile_rejected_view_mapping", @@ -425,7 +425,7 @@ void prepare_native_mesh57(Wrapper* pipeline) refuse("unsupported or uncaptured shader stages"); // A nonzero PS pointer without any PS bytes fails capture and cannot use the depth-only path. if (fields[5] && !fields[6]) - return note_mesh57_outcome(Mesh57Outcome::ps_absent); + return note_mesh57_outcome(Mesh57Outcome::ps_uncaptured); return note_mesh57_outcome(Mesh57Outcome::unsupported_stage_or_descriptor); } const auto& ms_bytes = *info->fixed_ms; diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index b14732ff84..d68ae2bb12 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -2870,11 +2870,12 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, return 1; } if (outcomes || depth_only) { - const auto expect_outcomes = [&](const char* label, int unsupported_count) { + const auto expect_outcomes = [&](const char* label, int unsupported_count, int ps_uncaptured = 0) { const char* prefix = "x2w-render native slot57 preparation:"; const auto line = render_totals_line(guest, log_path, prefix); const auto expected = std::string(prefix) + - " disabled 0 ps_absent 0 unsupported_stage_or_descriptor " + std::to_string(unsupported_count) + + " disabled 0 ps_uncaptured " + std::to_string(ps_uncaptured) + + " unsupported_stage_or_descriptor " + std::to_string(unsupported_count) + " missing_creation_root_or_state 0 profile_absent " + (depth_only ? "1" : "65") + " profile_open_failed 0 profile_rejected_header 0 profile_rejected_pixel_entry 0" " profile_rejected_version 0 profile_rejected_constants 0 profile_rejected_root_mapping 0" @@ -2900,8 +2901,12 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, if (!expect_outcomes("null PS pointer with nonzero length", 1)) return 1; fields[5] = 1; // Nonzero address in the unreadable low 64 KiB. create(); - fields[5] = ps_pointer; if (!expect_outcomes("uncaptured PS with nonzero pointer and length", 2)) return 1; + fields[5] = ps_pointer; + fields[6] = 0; + create(); + fields[6] = ps_size; + if (!expect_outcomes("nonzero PS pointer with zero length", 2, 1)) return 1; } } fields[15] = 1;