Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/experiments/native-fixed-mesh57.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The `native_fixed_mesh57_waterfall_{warp,hardware}` fixture draws a triangle cov

Set `X2W_SHADER_CACHE` to the request cache and `X2W_MESH57_CAPTURE_STATE=1` to retain the fixed creation state when a matching root consumes a mesh pipeline. A `req_<variant>.s57` file contains the little-endian 64-bit stage/root request key, three little-endian 32-bit lengths, and the corresponding byte spans for the normalized descriptor, register block A and register block B. For the base layout the stand-in clears the captured root and span pointer fields at DWORD-pair indices 0, 1, 3, 5 and 13. It preserves the lengths and other fields. The variant key extends the existing stage/root key with those three length-prefixed spans. Distinct fixed states can coexist for one stage pair. The fixture overwrites both blocks after creation and checks their archived bytes for accepted and refused variants.

When the attachments bound at that draw are single-sample, the same capture writes `req_<variant>.t57` immediately before `.s57`. It is one line, `targets <N> <fmt...> dsv <fmt> writable <0|1> samples 1 0`, with decimal DXGI formats; `tools/startup/mesh57_profile_draft.py` reads it through `mesh57_profile.py`'s `TARGET_TUPLE`. A bind with no attachments writes no `.t57`, and a non-single-sample attachment writes no `.t57` because the tuple carries only one sample count and quality. `.s57` stays the archive in both cases. The default fixture binds one `R8G8B8A8_UNORM` target and no DSV; the MRT fixture binds `29 28 28 28 34 28` with `D32_FLOAT_S8X24_UINT`.

Native preparation reads a separately reviewed `<variant>.mesh57-state` profile from the cache. The stand-in lists the cache's top-level file names once per process, at the first profile lookup (`src/startup_stubs/cache_index.h`), and opens a profile only when that listing has its name. A profile written while the process runs is read by the next process. Its versioned Windows x64 header is defined by `Mesh57Profile` in `src/startup_stubs/mesh57_profile.h`. The header supplies the MS entry layout and desktop fixed-function state. The file ends with the normalized descriptor, register blocks, serialized root and both guest programs. The stand-in compares every byte before building a PSO. The fixture authors this profile from its own known inputs. A captured register block alone does not establish the desktop rasterizer state or MS entry layout.

To serialize reviewed desktop and entry state, run
Expand Down
1 change: 1 addition & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,7 @@ ctest --preset dev --no-tests=error -R '^startup_hook_(window|overlap)$' -V
| `X2W_PIPELINE_COLOUR=1` | diagnostic only, debug switch, in render mode: a `DrawInstanced`, `DrawIndexedInstanced` or `ExecuteIndirect` draw that draws nothing gets one flat marker tile in render target 0, in a colour taken from its pipeline key, and logs `x2w-draw colour #rrggbb for <key> <reason>` once per key ([details](experiments/pipeline-colour-fallback.md)). Not a fallback: the refused draw still draws nothing, and the tiles can tint later passes. Unset, nothing is drawn or logged |
| `X2W_SHADER_CACHE=<dir>` | translation cache: the runtime writes source requests `req_<key>.{a,b,root}`, when needed RTV variants `req_<key>.rtv`, and for device slot 67 compute pipelines `req_<key>.{desc,sa,sb,data,root,c67}` (see [Compute pipeline requests](#compute-pipeline-requests)). A console pipeline that an `ExecuteIndirect` draw (list slot 61) refuses writes the same request as a direct draw, once per pipeline, and draws nothing (`startup_indirect_requests_warp`). Only direct draws poll for its manifest, so such a pipeline stays in the `missing` count until a direct draw uses it; the `x2w-render totals` line counts `pipelines first looked up by ExecuteIndirect N`. This is a per-process lookup count. Check for the ready marker `req_<key>.a` to confirm a complete request is available. Run `tools/startup/gfx2hlsl.py --pending <dir>` while the process is running, or start the run with `run.ps1 -Translate` (see [Translating shaders during a run](#translating-shaders-during-a-run)). Active draws poll for an absent manifest at most once per second per pipeline and use the published translation on a subsequent draw. The translator compiles `.vs.cso` and `.ps.cso` with `fxc.exe`: `X2W_FXC`, else the Windows SDK 10.0.26100.0 copy, else the newest `Windows Kits\10\bin\<version>\x64`, else `PATH`. When none exists it writes `<key>.fail` naming `X2W_FXC` without publishing a new manifest. `X2W_FXC=` (empty) publishes the manifest alone. Rerun `--pending` with compilation enabled to fill in missing bytecode for an existing manifest. At its first cache lookup the runtime starts a change feed on the directory (`ReadDirectoryChangesW`, top-level file names), then lists the directory's top-level file names once on the feed's thread and logs `x2w-draw cache index: <n> names in <ms> ms; change feed <state>` (`src/startup_stubs/cache_index.h`). A `<variant>.mesh57-state` profile is opened only when that listing has its name, so a profile written while the process runs is read by the next process. The request-part and compute-marker probes (`req_` names, which only runtimes write) skip the disk for a name that is absent from the listing and from this process's own writes. The probes for `<key>.txt` (graphics and compute manifests and the slot 57 base manifest) and `<key>.cs.hlsl` skip it only while the change feed is reading and was reading before the listing began, so a file the translator writes later is found once its change record arrives. After a dropped batch or a feed error they use the disk again. A compute manifest retry (an absent, stale or unmarked `<key>.txt`) whose `<key>.*` names have no change record from the feed since its last miss repeats that miss without a file-system call; the feed records created, removed, renamed and rewritten files, and without a reading feed every retry looks on disk. Every 10 s while probes run, `x2w-draw cache probes (skipped as absent/on disk): ...` gives each probe's counts (and the compute retries repeated without I/O), the feed state, records and added names, the lookups that found a name added after the listing, and contradictions (a write that found a file the index had reported absent). |
| `X2W_NATIVE_SHADERS=<dir>` (`run.ps1 -NativeShaders <dir>`) | experimental, in render mode: translates device slot 67 compute requests in the stand-in with the C++ compiler; `<dir>` holds `dxcompiler.dll` and `dxil.dll`. See [Translating compute programs in the stand-in](#translating-compute-programs-in-the-stand-in) |
| `X2W_MESH57_CAPTURE_STATE=1` | opt-in, render mode: archives each slot 57 fixed mesh variant as `req_<variant>.s57` and, when the bound attachments are single-sample and at least one target or the DSV has a known format, writes `req_<variant>.t57` immediately before it. The sidecar is one `targets <N> <fmt...> dsv <fmt> writable <0|1> samples 1 0` line with decimal DXGI formats; a bind with no attachments or a non-single-sample attachment writes no `.t57` and keeps `.s57`. `tools/startup/mesh57_profile_draft.py` consumes the pair. See [fixed mesh pipelines through slot 57](experiments/native-fixed-mesh57.md) |
| `X2W_ALLOW_PUBLISHED_MESH57_PAIR=1` | opt-in, in render mode with `X2W_NATIVE_SHADERS`: permits the buffer-view slot 57 path to load a publisher's `.ms57.cso` / `.ps57.cso` pair after native translation refuses with the exact `mesh57_group_index` code. Native translation still runs first. Unset, the pair is ignored and that native refusal is rethrown before the manifest or a CSO is opened, including with `X2W_NATIVE_SHADERS_ONLY=1`. See [fixed mesh pipelines through slot 57](experiments/native-fixed-mesh57.md#published-pair-for-the-r1-group-index-exchange) |
| `X2W_D3D12_LINEAR_BUFFERS=1` or `=copy` | opt-in backing for linear buffers placed at a title address (device slot 133, initial state `COMMON`): shared where the adapter, extent and memory allow it (private allocations larger than 256 MiB are skipped only with `X2W_D3D12_CAP_EXISTING_HEAP=1`), otherwise copied from title memory at each submission, otherwise the default backing is kept and the refusal recorded; `copy` never shares. Unset or `0`, slot 133 keeps its default backing. See [Linear buffer backing (device slot 133, opt-in)](#linear-buffer-backing-device-slot-133-opt-in) |
| `X2W_D3D12_CAP_EXISTING_HEAP=1` | opt-in 256 MiB (`unplaced_existing_heap_allowed`) allocation-size cap on `OpenExistingHeapFromAddress` in device slot 133 (`startup_slot133_heap_cap_*`). Unset (default), private allocations larger than 256 MiB keep the formerly aliased path: a capped copied placement is refused by `CopyBufferRegion` (list slot 15) as `title_backed_source`, losing a late guest write made after recording and before submit. Set, allocations larger than 256 MiB skip `OpenExistingHeapFromAddress` so multi-GiB startup blocks are not pinned in `WorkingSetSize` and `NonLocal` GPU memory |
Expand Down
18 changes: 16 additions & 2 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ u64 publish_compute_request(const void* desc)

// Slot 57 fixed descriptors consumed by a decoded DispatchMesh signature.
// The vertex span must be absent. A null/zero PS span is valid for depth-only work.
void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* bound_root)
void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* bound_root,
const Mesh57Attachments& attachments)
{
wchar_t marker[MAX_PATH];
if (!bound_root || !cache_path(marker, L"req_", 0, L".m57")) return;
Expand Down Expand Up @@ -1060,14 +1061,27 @@ void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* bo
// Payload: request key, three uint32 lengths, normalized descriptor, state A, state B.
const auto desc = x2w_startup::normalize_mesh57_descriptor(info->desc);
const auto variant = fnv_part(info->state_b, fnv_part(info->state_a, fnv_part(desc, key)));
const std::string tuple = mesh57_attachment_tuple(attachments);
if (tuple.empty()) {
const char* reason = !attachments.single_sample ? "attachments are not single-sample" :
(!attachments.count && attachments.dsv == DXGI_FORMAT_UNKNOWN) ? "no attachments were bound" :
"a bound attachment has no format";
static LONG logged_not_single, logged_none, logged_unknown;
LONG& logged = !attachments.single_sample ? logged_not_single :
(!attachments.count && attachments.dsv == DXGI_FORMAT_UNKNOWN) ? logged_none : logged_unknown;
if (first_calls(logged, 1))
log("x2w-draw fixed mesh capture %016llx: %s; publishing .s57 without .t57", variant, reason);
}
std::vector<unsigned char> packed(sizeof(key) + 3 * sizeof(UINT));
const UINT lengths[]{static_cast<UINT>(desc.size()), static_cast<UINT>(info->state_a.size()),
static_cast<UINT>(info->state_b.size())};
std::memcpy(packed.data(), &key, sizeof(key));
std::memcpy(packed.data() + sizeof(key), lengths, sizeof(lengths));
for (const auto* bytes : {&desc, &info->state_a, &info->state_b})
packed.insert(packed.end(), bytes->begin(), bytes->end());
if (!publish_shader_request(variant, L".s57", packed.data(), packed.size()))
// The tuple precedes the .s57 marker so a reader never sees an archive without its attachments.
if ((!tuple.empty() && !publish_shader_request(variant, L".t57", tuple.data(), tuple.size())) ||
!publish_shader_request(variant, L".s57", packed.data(), packed.size()))
log("x2w-draw fixed mesh state %016llx could not be published", variant);
}
const unsigned char none = 0;
Expand Down
20 changes: 17 additions & 3 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "startup_stubs/draw_bmp.h"
#include "startup_stubs/pipeline_colour.h"
#include "startup_stubs/mesh57_profile.h"
#include "startup_stubs/mesh57_capture.h"
#include "startup_stubs/cache_index.h"
#include "startup_stubs/draw_dump_tracking.h"
#include "startup_stubs/present_readback_state.h"
Expand Down Expand Up @@ -336,7 +337,8 @@ void log(const char* format, ...);
bool first_calls(LONG& counter, LONG limit);
void request_translation(Wrapper* pipeline);
struct RootParameter;
void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* bound_root);
void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* bound_root,
const Mesh57Attachments& attachments);
std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mask);

std::uint64_t desktop_cpu_handle(std::uint64_t handle, UINT* contiguous = nullptr, UINT* available = nullptr,
Expand Down Expand Up @@ -4521,6 +4523,18 @@ bool root_srv_at_draw()
}
LONG root_srv_copies_skipped, root_srv_copies_made;

Mesh57Attachments mesh57_attachments(const Pass& pass)
{
Mesh57Attachments capture;
if (!pass.targets_bound || pass.target_count > 8) return capture;
capture.count = pass.target_count;
std::copy_n(pass.target_formats, pass.target_count, capture.rtvs);
capture.dsv = pass.dsv_format;
capture.writable = pass.depth_view_writable;
capture.single_sample = pass.targets_single_sample;
return capture;
}

void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count, void* argument, u64 offset,
void* count_buffer, u64 count_offset)
{
Expand Down Expand Up @@ -4619,7 +4633,7 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
(pass.requested_mesh_pipeline != pass.pipeline || pass.requested_mesh_root != pass.root)) {
pass.requested_mesh_pipeline = pass.pipeline;
pass.requested_mesh_root = pass.root;
request_slot57_mesh(pass.pipeline, pass.root);
request_slot57_mesh(pass.pipeline, pass.root, mesh57_attachments(pass));
}
refusal_pipeline = pass.pipeline;
// A slot 62 builder pipeline is tracked by the wrapper itself, not by a slot 67 request key.
Expand Down Expand Up @@ -4652,7 +4666,7 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
(pass.requested_mesh_pipeline != pass.pipeline || pass.requested_mesh_root != pass.root)) {
pass.requested_mesh_pipeline = pass.pipeline;
pass.requested_mesh_root = pass.root;
request_slot57_mesh(pass.pipeline, pass.root);
request_slot57_mesh(pass.pipeline, pass.root, mesh57_attachments(pass));
} else if (!mesh && pass.pipeline && !pass.pipeline->own().real && pass.requested_pipeline != pass.pipeline) {
pass.requested_pipeline = pass.pipeline;
request_translation(pass.pipeline);
Expand Down
37 changes: 37 additions & 0 deletions src/startup_stubs/mesh57_capture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Experimental (docs/startup-runtime.md): one captured attachment tuple for a slot 57 mesh variant.
//
// The runtime writes req_<variant>.t57 beside req_<variant>.s57 only while X2W_MESH57_CAPTURE_STATE=1.
// tools/startup/mesh57_profile.py reads one line:
// targets <N> <fmt...> dsv <fmt> writable <0|1> samples <count> <quality>
// The tuple carries one sample count and quality, so a non-single-sample bind is not represented.
#pragma once

#include <d3d12.h>

#include <string>

struct Mesh57Attachments
{
UINT count{};
DXGI_FORMAT rtvs[8]{};
DXGI_FORMAT dsv{DXGI_FORMAT_UNKNOWN};
bool writable{};
bool single_sample{};
};

// The TARGET_TUPLE line, or empty when the bind cannot be represented without inventing a value.
inline std::string mesh57_attachment_tuple(const Mesh57Attachments& capture)
{
if (capture.count > 8 || !capture.single_sample) return {};
if (!capture.count && capture.dsv == DXGI_FORMAT_UNKNOWN) return {};
std::string line = "targets " + std::to_string(capture.count);
for (UINT i = 0; i < capture.count; ++i) {
if (capture.rtvs[i] == DXGI_FORMAT_UNKNOWN) return {};
line += " " + std::to_string(static_cast<unsigned>(capture.rtvs[i]));
}
const UINT dsv = static_cast<unsigned>(capture.dsv);
line += " dsv " + std::to_string(dsv);
line += " writable " + std::to_string(capture.writable && dsv ? 1 : 0);
line += " samples 1 0\n";
return line;
}
37 changes: 37 additions & 0 deletions tests/startup_indirect_draw_indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "xmem_section_lease.h"
#include "startup_stubs/rect_indirect_args.h"
#include "startup_stubs/mesh57_profile.h"
#include "startup_stubs/mesh57_capture.h"
#include "startup_indirect_mesh_mesh.h"
#include "startup_indirect_mesh_amplify.h"
#include "startup_indirect_mesh_amplified_mesh.h"
Expand Down Expand Up @@ -3058,6 +3059,42 @@ 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;
std::string expected_tuple = "targets " + std::to_string(profile.targets.NumRenderTargets);
for (UINT i = 0; i < profile.targets.NumRenderTargets; ++i)
expected_tuple += " " + std::to_string(static_cast<unsigned>(profile.targets.RTFormats[i]));
const bool depth_writable = profile.depth_format != DXGI_FORMAT_UNKNOWN &&
profile.depth.DepthWriteMask != D3D12_DEPTH_WRITE_MASK_ZERO;
expected_tuple += " dsv " + std::to_string(static_cast<unsigned>(profile.depth_format));
expected_tuple += " writable " + std::to_string(depth_writable ? 1 : 0);
expected_tuple += " samples 1 0";
expected_tuple += static_cast<char>(10);
std::size_t tuple_sidecars = 0;
for (const auto& f : std::filesystem::directory_iterator(cache))
if (f.path().extension() == ".s57") {
auto sidecar = f.path();
sidecar.replace_extension(".t57");
std::ifstream in(sidecar, std::ios::binary);
const std::string observed((std::istreambuf_iterator<char>(in)), {});
if (observed != expected_tuple) {
std::fprintf(stderr, "mesh57 attachment sidecar mismatch for %s: got %s, expected %s", sidecar.string().c_str(), observed.c_str(), expected_tuple.c_str());
return 1;
}
++tuple_sidecars;
}
if (tuple_sidecars < 2) return 1;
Mesh57Attachments depth_only;
depth_only.dsv = DXGI_FORMAT_D32_FLOAT;
depth_only.writable = true;
depth_only.single_sample = true;
if (mesh57_attachment_tuple(depth_only) !=
std::string("targets 0 dsv 40 writable 1 samples 1 0") + static_cast<char>(10)) return 1;
Mesh57Attachments no_attachments;
if (!mesh57_attachment_tuple(no_attachments).empty()) return 1;
Mesh57Attachments multisample;
multisample.count = 1;
multisample.rtvs[0] = format;
multisample.single_sample = false;
if (!mesh57_attachment_tuple(multisample).empty()) return 1;
DeleteFileW(log_path.c_str());
std::filesystem::remove_all(cache);
return 0;
Expand Down
Loading