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
8 changes: 8 additions & 0 deletions docs/experiments/native-fixed-mesh57.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ 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.

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.
Expand Down
5 changes: 3 additions & 2 deletions src/startup_stubs/mesh86_cache.inl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ struct Mesh86Request {
std::vector<unsigned char> 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<IDXGIFactory4> factory;
x2w_startup::ComPtr<IDXGIAdapter1> adapter;
Expand Down Expand Up @@ -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;
}
Expand Down
81 changes: 61 additions & 20 deletions src/startup_stubs/native_mesh57.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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_uncaptured);
return note_mesh57_outcome(Mesh57Outcome::unsupported_stage_or_descriptor);
}
const auto& ms_bytes = *info->fixed_ms;
const std::vector<unsigned char> empty;
const auto& ps_bytes = depth_only ? empty : *info->fixed_ps;
auto* root = as_wrapper(reinterpret_cast<const void*>(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<unsigned char> 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;
Expand All @@ -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<char*>(&mapping), sizeof(mapping)) || mapping.root_parameter >= 16 ||
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -669,7 +710,7 @@ void prepare_native_mesh57(Wrapper* pipeline)
x2w::meshlet::MeshOnlyPipelineStream stream{};
stream.root_signature.value = reinterpret_cast<ID3D12RootSignature*>(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;
Expand Down
7 changes: 7 additions & 0 deletions tests/cmake/native_mesh57_depth_only.cmake
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading