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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ target_compile_features(startup_stream_setup_obj PRIVATE cxx_std_17)
add_executable(startup_stream_consumer tests/startup_stream_consumer.cpp $<TARGET_OBJECTS:startup_stream_setup_obj> tests/startup_stream_draw.cpp
tests/startup_address_srv.cpp tests/startup_root_cbv.cpp tests/startup_root_heap.cpp)
target_compile_features(startup_stream_consumer PRIVATE cxx_std_17)
target_link_libraries(startup_stream_consumer PRIVATE d3d12_xs_shim startup_stub_xg_xs d3d12 dxgi)
target_link_libraries(startup_stream_consumer PRIVATE d3d12_xs_shim startup_stub_xg_xs d3d12 dxgi d3dcompiler)
target_sources(startup_stream_consumer PRIVATE tests/startup_frame_copy.cpp)
target_sources(startup_stream_consumer PRIVATE tests/startup_root_reset.cpp)

Expand Down Expand Up @@ -2712,6 +2712,10 @@ if(EXISTS "${INTAKE_PYTHON}")
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_slot57_blend_draw_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}")
set_tests_properties(startup_slot57_blend_draw_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77)
add_test(NAME startup_indirect_requests_${backend} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_indirect_requests_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}")
set_tests_properties(startup_indirect_requests_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77)
add_test(NAME startup_packed_target_draw_${backend} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_packed_target_draw_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${DXC_EXECUTABLE}" "${backend}")
Expand Down
2 changes: 1 addition & 1 deletion docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `X2W_XMEM_GPU_MIRROR=1` | pairs a no-access graphics reservation with the read-write reservation of the same size made just before it, and maps every physical page into both (same section) |
| `X2W_D3D12_PERMISSIVE=1` | wraps the device: recording command lists, console present, view tracking |
| `X2W_D3D12_RENDER=1` | draws through translated pipelines from `X2W_SHADER_CACHE` and forwards [single-record indirect Dispatch](experiments.md#gpu-written-indirect-dispatch-arguments), [DrawIndexed](experiments.md#gpu-written-indirect-indexed-draw-arguments), [Draw](experiments.md#gpu-written-indirect-draw-arguments), and [DispatchMesh](experiments.md#gpu-written-indirect-mesh-dispatch-arguments) for supported desktop pipelines and tracked placed buffers |
| `X2W_SHADER_CACHE=<dir>` | translation cache: the runtime writes source requests `req_<key>.{a,b,root}` and, when needed, RTV variants `req_<key>.rtv`. 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. |
| `X2W_SHADER_CACHE=<dir>` | translation cache: the runtime writes source requests `req_<key>.{a,b,root}` and, when needed, RTV variants `req_<key>.rtv`. 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. |
| `X2W_D3D12_QUERY_SLOTS=1` | diagnostic, in render mode: binds command-list slots 28 to 30 to the hypothesised occlusion query methods (see [Occlusion queries](#occlusion-queries)). Unset, the three slots stay no-ops |
| `X2W_DRAW_NULL_IDENTITY=1` | null descriptors read as identity values instead of zero |
| `X2W_PRESENT_SIGNATURE_EVERY=<n>` | in render mode, samples a coarse signature of the presented picture every `n` presents from the start, without a script request (`0` off). Unset, sampling starts, every 4 presents, only once a script with a `wait` asks for it: see [Waiting for the presented picture](#waiting-for-the-presented-picture) |
Expand Down
16 changes: 16 additions & 0 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ BoundPipeline* translation_for(Wrapper* pipeline)
return bound;
}

// The request translation_for writes on a direct draw, for a pipeline that slot 61 refuses. Only direct draws poll
// for the manifest afterwards. Count first lookups separately from published request files.
LONG indirect_first_lookups;
void request_translation(Wrapper* pipeline)
{
AcquireSRWLockExclusive(&draw_lock);
const bool known = translation_by_pipeline().count(pipeline) != 0;
translation_for(pipeline);
ReleaseSRWLockExclusive(&draw_lock);
if (!known) InterlockedIncrement(&indirect_first_lookups);
static LONG lookups;
if (first_calls(lookups, 16))
log("x2w-render ExecuteIndirect looks up translation for pipeline %p (%s)", static_cast<void*>(pipeline),
known ? "already known" : "new");
}

bool needs_rtv_variant(DXGI_FORMAT format)
{
switch (format) {
Expand Down
15 changes: 12 additions & 3 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ constexpr std::uint64_t view_heap_probe_floor = 65536;

void log(const char* format, ...);
bool first_calls(LONG& counter, LONG limit);
void request_translation(Wrapper* pipeline);
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 @@ -1874,6 +1875,7 @@ struct Pass {
std::vector<std::pair<ID3D12Resource*, D3D12_RESOURCE_STATES>> states; // resources this list moved out of COMMON
// What the title bound, kept for draws through translated pipelines:
Wrapper* pipeline = nullptr;
Wrapper* requested_pipeline = nullptr; // last pipeline slot 61 asked a translation for; repeats skip draw_lock
UINT topology = 0;
x2w_startup::ViewTable view_tables[16]{};
u64 source_view_heap = 0;
Expand Down Expand Up @@ -2152,9 +2154,16 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
else if (mesh) bytes = sizeof(D3D12_DISPATCH_MESH_ARGUMENTS);
else bytes = sizeof(D3D12_DRAW_ARGUMENTS);
if (type != D3D12_COMMAND_LIST_TYPE_DIRECT || !pass.indirect_graphics.root ||
pass.indirect_graphics.root != pass.graphics_root || pass.indirect_graphics.mesh != mesh)
pass.indirect_graphics.root != pass.graphics_root || pass.indirect_graphics.mesh != mesh) {
// A console pipeline (no desktop pipeline) used only here still gets the request a direct draw writes;
// nothing is drawn.
if (pass.pipeline && !pass.pipeline->own().real && pass.requested_pipeline != pass.pipeline) {
pass.requested_pipeline = pass.pipeline;
request_translation(pass.pipeline);
}
return refuse("indirect graphics requires a direct list with a matching desktop pipeline and root",
indirect_graphics_pipeline);
}
if (!pass.targets_bound || pass.target_count != 1 || !pass.target0 ||
pass.target_formats[0] != pass.indirect_graphics.target_format ||
pass.dsv_format != DXGI_FORMAT_UNKNOWN || !pass.viewport_set || !pass.scissor_set)
Expand Down Expand Up @@ -3778,15 +3787,15 @@ HRESULT __stdcall queue_present(Wrapper* self, UINT planes, const void* plane_pa
log("x2w-render totals: resets %ld (failed %ld), closes %ld, clears %ld, target binds %ld (unresolved %ld), executes %ld, draws %ld (skipped %ld), "
"translated draws %ld (not drawn %ld), pipelines translated %ld / missing %ld, null bindings %ld (entry %ld, buffer %ld, token %ld, wrapper %ld, dimension %ld), "
"textures uploaded %ld (%ld KiB, unreadable %ld), heap-indexed roots deferred %ld (real draws refused: view heap %ld, "
"sampler heap %ld, both heaps %ld, state %ld)", render_resets,
"sampler heap %ld, both heaps %ld, state %ld), pipelines first looked up by ExecuteIndirect %ld", render_resets,
render_reset_failures, render_closes, render_clears, render_target_binds, render_target_unresolved, render_executes, render_draws, render_draws_skipped,
translated_draws, untranslated_draws, translation_ready, translation_missing, null_total,
null_causes[0], null_causes[1], null_causes[2], null_causes[3], null_causes[4], textures_uploaded,
texture_bytes_uploaded, textures_unreadable, heap_roots_deferred,
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::view_heap_missing)],
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::sampler_heap_missing)],
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::both_heaps_missing)],
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::state_not_restorable)]);
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::state_not_restorable)], indirect_first_lookups);
if (render_mode() && frame % 300 == 0) {
// Slot-61 calls since the start, by outcome, then by signature kind (zero kinds left out).
static const char* const outcomes[] = {"forwarded", "refused graphics-pipeline", "compute-pipeline",
Expand Down
96 changes: 96 additions & 0 deletions tests/startup_indirect_requests_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""A console pipeline used only through ExecuteIndirect (list slot 61) still writes its translation request.

usage: startup_indirect_requests_check.py <startup_stream_consumer> <warp|hardware>

The consumer builds the stream pipeline (slot 86, with an input layout so its request key differs), then the
pipeline under test, binds it on a guest list and records refused slot-61 calls (no root or target is bound):

slot57-draw a device slot 57 pipeline from the same shaders and root, three Draw calls: one request with
the slot-57 shaders and root, from one lookup (the pass remembers the pipeline it asked for)
slot57-bound the same pipeline bound with no call: no request (negative control)
slot57-dispatch the same pipeline with one Dispatch call (a compute-state refusal): no request
desktop-draw a slot-86 pipeline with desktop shaders and one Draw call: no lookup

Every slot-61 lookup logs "x2w-render ExecuteIndirect looks up translation for pipeline" (first 16).
"""
import os
from pathlib import Path
import subprocess
import sys
import tempfile

from startup_stream_draw_check import pixel, vertex

LOOKUP = "x2w-render ExecuteIndirect looks up translation for pipeline"


def run(consumer, backend, directory, mode, runs=1):
cache = directory / mode
cache.mkdir()
vs, ps, root = (directory / name for name in ("vs", "ps", "root"))
vs.write_bytes(vertex())
ps.write_bytes(pixel(False))
env = dict(os.environ, X2W_D3D12_PERMISSIVE="1", X2W_D3D12_LIST_NOOP="1", X2W_D3D12_RENDER="1",
X2W_SHADER_CACHE=str(cache), X2W_TEST_INPUT_LAYOUT="1")
env.setdefault("X2W_D3D12_DEBUG", "0")
logs = []
for _ in range(runs):
result = subprocess.run([consumer, vs, ps, root, backend, directory / "unused", f"indirect-{mode}"], env=env,
capture_output=True, text=True)
if backend == "hardware" and result.returncode == 77:
print("No D3D12 feature-level 12 hardware adapter")
sys.exit(77)
if result.returncode:
raise RuntimeError(f"{mode}: consumer failed on {backend}: {result.returncode}\n{result.stderr[-2000:]}")
logs.append(result.stderr)
found = {}
for marker in sorted(cache.glob("req_*.a")):
key = marker.name[4:-2]
found[key] = {ext: (cache / f"req_{key}{ext}").read_bytes() if (cache / f"req_{key}{ext}").exists() else None
for ext in (".a", ".b", ".root", ".ia")}
leftovers = list(cache.glob("*.tmp"))
assert not leftovers, f"{mode}: temporary request files left: {leftovers}"
return found, logs, vs.read_bytes(), ps.read_bytes(), root.read_bytes()


def lookups(log):
return [line for line in log.splitlines() if LOOKUP in line]


def check(consumer, backend):
with tempfile.TemporaryDirectory() as temp:
temp = Path(temp)
bound, logs, *_ = run(consumer, backend, temp, "slot57-bound")
assert len(bound) == 1, f"slot57-bound: {len(bound)} requests, expected only the stream pipeline's"
stream_key, stream = next(iter(bound.items()))
assert stream[".ia"] is not None, "slot57-bound: the stream request has no input layout"
assert not lookups(logs[0]), "slot57-bound: a lookup without a slot-61 call"

dispatch, logs, *_ = run(consumer, backend, temp, "slot57-dispatch")
assert set(dispatch) == {stream_key}, f"slot57-dispatch: {len(dispatch) - 1} extra requests, expected 0"
assert not lookups(logs[0]), "slot57-dispatch: a compute-state refusal looked the pipeline up"

_, logs, *_ = run(consumer, backend, temp, "desktop-draw")
assert "stream pipeline -> REAL desktop pipeline" in logs[0], "desktop-draw: no desktop pipeline was built"
assert not lookups(logs[0]), "desktop-draw: a desktop pipeline was looked up"

# Two processes into one cache: the request is written once, the second process finds it.
found, logs, vs, ps, root = run(consumer, backend, temp, "slot57-draw", runs=2)
assert stream_key in found, "slot57-draw: the stream pipeline's request is missing"
extra = {key: files for key, files in found.items() if key != stream_key}
assert len(extra) == 1, f"slot57-draw: {len(extra)} indirect-only requests, expected 1"
files = next(iter(extra.values()))
# Device slot 57 records the vertex program as a and the pixel program as b.
assert files[".a"] == vs and files[".b"] == ps and files[".root"] == root and files[".ia"] is None, \
"slot57-draw: the request does not carry the slot-57 shaders and root"
for index, log in enumerate(logs):
seen = lookups(log)
assert len(seen) == 1, f"slot57-draw run {index + 1}: {len(seen)} lookups for 3 calls, expected 1"
assert seen[0].endswith("(new)"), f"slot57-draw run {index + 1}: {seen[0]}"
print(f"startup_indirect_requests: PASS on {backend} (slot57-draw: 1 request, 1 lookup for 3 calls, written "
f"once over 2 processes; slot57-bound, slot57-dispatch: no request; desktop-draw: no lookup)")
return 0


if __name__ == "__main__":
sys.exit(check(*sys.argv[1:]))
Loading
Loading