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
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2440,8 +2440,9 @@ foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_sharedexp_target_${adapter} COMMAND offscreen_check ${adapter} --startup-sharedexp-target)
set_tests_properties(startup_sharedexp_target_${adapter} PROPERTIES TIMEOUT 45 SKIP_RETURN_CODE 77)
endforeach()
# Presented planes (src/startup_stubs/present_planes.h): the plane record layout and the composite order
# on synthetic records. The control reads 0x40-byte records and composites plane 0 alone, and must FAIL.
# Presented planes (src/startup_stubs/present_planes.h): the plane record layout, the selection policy
# and the composite order on synthetic records. The control reads 0x40-byte records, composites plane 0
# alone, keeps the old single-plane selection and capacity, and must FAIL.
add_executable(startup_present_planes tests/startup_present_planes_check.cpp)
target_include_directories(startup_present_planes PRIVATE src)
target_compile_features(startup_present_planes PRIVATE cxx_std_17)
Expand Down
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"cpu_fuzz_lifted", "cpu_fuzz_lifted_o2", "pe_map", "intake_candidate",
"archive_gpu_reader", "archive_codec_gpu", "archive_texture_gpu_lifted", "startup_launch_probe",
"startup_indirect_dispatch", "startup_indirect_draw_indexed", "startup_present_readback_check",
"startup_present_planes", "startup_present_composite_warp",
"xmem_shim_test_controls", "startup_stub_xcrdapi", "startup_stub_xcrdapi_break_window_control",
"xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check",
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
Expand All @@ -48,7 +49,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$"
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$"
}
}
},
Expand Down
43 changes: 26 additions & 17 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,16 @@ window. Why plane 0 stays black is not known.

By default the output window still shows plane 0 alone, as before the planes were decoded. The
experimental `X2W_PRESENT_COMPOSITE=1` makes it composite the planes instead
(`src/startup_stubs/plane_compositor.h`, shared by the window presenter and its fixture). It stays
opt-in until a matched comparison on the same executable, with this change alone, shows what it does
to a real present. The contract under the switch:
(`src/startup_stubs/plane_compositor.h`, shared by the window presenter and its fixture), because
plane 0 alone was measured black while plane 1 held the picture. It stays opt-in until a matched
comparison on the same executable, with this change alone, shows what it does to a real present. The
switch also covers a one-plane present. `X2W_PRESENT_PLANE=<n>` keeps one plane alone and takes
priority over the switch. The contract:

- Order: plane 0 first, each later plane over it, in plane order (`composite_steps`). At most four
planes are read.
planes are read. The compositor reserves the largest present it can draw
(`src/startup_stubs/window_plane_capacity.h`); its capacity is fixed on the first present, so an
earlier one-plane present cannot cap a later multi-plane present.
- The lowest drawn plane is opaque: its colour replaces the window and its alpha is ignored.
- Each later plane is blended by its own alpha, not premultiplied:
`rgb = src.rgb * src.a + dst.rgb * (1 - src.a)`, `a = src.a + dst.a * (1 - src.a)` (D3D12
Expand All @@ -316,10 +320,14 @@ to a real present. The contract under the switch:
- Each plane is scaled to the whole window with a linear, clamped sampler. The planes' source and
destination rectangles in the record (after +0x10) are not decoded; a plane that covers only part
of the screen on the console is stretched here.
- The baseline capture is unchanged with or without the switch: the frame capture, the presented
signature, `X2W_D3D12_DUMP_SURFACE` and the `x2w-render presented` readback all read plane 0's
first resource, as before. Under the switch the highest plane above plane 0 with a known resource
is also sampled on the same frames, before compositing, and logged as a raw plane:
- If the multi-plane composite pipeline cannot be created, the presenter retries with one plane so
the output window and a one-plane present still work; a later present can then draw only that one
plane. The fallback is not exercised by the synthetic fixtures and has not been observed; it is
recorded here as a possible failure path, not as a measured result.
- The baseline capture is unchanged by compositing: the frame capture, the presented signature,
`X2W_D3D12_DUMP_SURFACE` and the `x2w-render presented` readback all read plane 0's first resource,
as before. With `X2W_PRESENT_COMPOSITE=1` the highest plane above plane 0 with a known resource is
also sampled on the same frames, before compositing, and logged as a raw plane:

```text
x2w-render raw plane <i> (not composited): surface <w>x<h> format <f>, sample <k>, mean level <l>/255, mean alpha <a>/255
Expand All @@ -345,9 +353,10 @@ The first presents and every 300th log each plane:
x2w-present frame <n> plane <i>/<count>: <width>x<height> format <f> flags=0x<flags>
```

`ctest --preset dev --no-tests=error -R '^startup_present_planes(_control)?$'` checks the record layout
and the composite order on synthetic records; the control reads 0x40-byte records and composites
plane 0 alone, and must print `FAIL:`.
`ctest --preset pr --no-tests=error -R '^startup_present_planes(_control)?$'` checks the record layout,
the plane selection policy, the presenter's plane capacity and the composite order on synthetic
records; the control reads 0x40-byte records, models the withdrawn compose-by-default policy and
reserves a capacity of one plane, and must print `FAIL:`.
`ctest --preset dev --no-tests=error -R '^startup_present_composite_(warp|overlay_removed_control_warp)$'`
draws source-built planes through the same records, `composite_steps` and compositor (directly, without
the switch) into a 64x32 RGBA8 target on WARP and reads every texel back: a single plane is shown as is (including a cell with alpha 0); a black
Expand Down Expand Up @@ -1821,8 +1830,8 @@ ctest --preset dev --no-tests=error -R '^startup_hook_(window|overlap)$' -V
| `X2W_DEPTH_STATE=1` | translated draws of slot 57 pipelines take their depth-stencil state and stencil reference from state block A instead of the desktop default (depth and stencil off); a refused block keeps the default. Off by default, then nothing changes: see [Shortcuts that are known to be wrong](#shortcuts-that-are-known-to-be-wrong) |
| `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) |
| `X2W_D3D12_DUMP_SURFACE=<bmp>` | writes the last presented surface |
| `X2W_PRESENT_COMPOSITE=1` | experimental, in render mode: the output window composites every presented plane, bottom to top, instead of showing plane 0 alone, and the highest plane above plane 0 is sampled as `x2w-render raw plane <i> (not composited)`. Off by default; the baseline capture and `x2w-render presented` read plane 0 either way. See [Presented planes](#presented-planes) |
| `X2W_PRESENT_PLANE=<n>` | diagnostic, in render mode: the output window shows plane `n` of each present alone (plane 0 when `n` is past the count), with or without `X2W_PRESENT_COMPOSITE`. See [Presented planes](#presented-planes) |
| `X2W_PRESENT_COMPOSITE=1` | experimental, in render mode: the output window composites every presented plane, bottom to top, instead of showing plane 0 alone, and the highest plane above plane 0 is sampled as `x2w-render raw plane <i> (not composited)`. Off by default; the baseline capture and `x2w-render presented` read plane 0 either way. The compositor reserves the largest present it can draw (`src/startup_stubs/window_plane_capacity.h`), so an earlier one-plane present does not cap the switch at one plane. See [Presented planes](#presented-planes) |
| `X2W_PRESENT_PLANE=<n>` | diagnostic, in render mode: the output window shows plane `n` of each present alone (plane 0 when `n` is past the count), with or without `X2W_PRESENT_COMPOSITE`; it takes priority over compositing. See [Presented planes](#presented-planes) |
| `X2W_HIDE_TITLE_WINDOW=1` (`run.sh --hide-title-window`) | once a present has reached the output window, hides the title's own window; dialogs stay visible, and the window is shown again when a present misses the output window, until the next present reaches it ([Output window and fallback diagnostics](#output-window-and-fallback-diagnostics)). Keyboard input to the title after the hide is not measured. Off by default on every host |
| `X2W_DRAW_DUMP_FRAME=<n>`, `X2W_DRAW_DUMP_DIR`, `X2W_DRAW_DUMP_PIXEL=<x>,<y>` | Full-resolution RGB snapshots of single-sample RGBA8/BGRA8 UNORM or sRGB targets after translated draws. A later present writes completed queue-fenced copies. At most 48 copies are pending or written; a copy whose fence reports device removal (`UINT64_MAX`) is released unwritten and frees its slot (`src/startup_stubs/draw_dump_tracking.h`, `ctest --preset dev --no-tests=error -R '^startup_dump_fence_(removed_control_)?warp$' -V`; the control must fail). With `X2W_DRAW_DUMP_PIXEL`, each copy covers one texel instead and the present writes `pixel_history.txt` in `X2W_DRAW_DUMP_DIR`: one line per translated draw with `draw=`, `frame=`, `x=`, `y=`, `key=`, `count=`, `format=`, `raw=` and, for an 8-bit four-channel target, `rgba=`. The bounded history names the last draw that changed the texel (`src/startup_stubs/pixel_history.h`, `ctest --preset dev --no-tests=error -R '^startup_pixel_history_' -V`). |
| `X2W_TEARDOWN_REPORT=1`, `X2W_TEARDOWN_NO_GUARD=<pages, readbacks or all>` | Test accounting for the caches whose destructors run during the module's CRT teardown (`src/startup_stubs/d3d12_teardown.h`, #2572). With `X2W_TEARDOWN_REPORT`, each destroyed cache writes one `x2w-teardown <cache> detached=<n> released=<n>` line to stderr with `WriteFile`, because a stdio buffer would not be flushed from a CRT teardown. `X2W_TEARDOWN_NO_GUARD` names a cache whose detach at process exit becomes an ordinary release again: the negative control `startup_teardown_unload` runs against itself, where the termination check has to fail. Unset, both change nothing and no line is written. |
Expand Down Expand Up @@ -1898,10 +1907,10 @@ access, the last covered by the
is not evidence that the path it leads to runs.

A title on the Series S profile may present its picture on a plane above plane 0 and leave plane 0
black (see [Presented planes](#presented-planes) for a measured case). The output window shows plane 0 alone by
default, so it then stays black. `X2W_PRESENT_COMPOSITE=1` composites the planes, and
`X2W_PRESENT_PLANE=<n>` shows one plane alone. Whether other titles, or other profiles, present
this way is not known. Under either switch, `X2W_D3D12_DUMP_SURFACE` and the `x2w-render presented`
black (see [Presented planes](#presented-planes) for a measured case). The output window shows plane 0
alone by default, so it then stays black. `X2W_PRESENT_COMPOSITE=1` composites the planes, and
`X2W_PRESENT_PLANE=<n>` shows one plane alone. Whether other titles, or other profiles, present this
way is not known. Under either switch, `X2W_D3D12_DUMP_SURFACE` and the `x2w-render presented`
readback still read plane 0. With `X2W_PRESENT_COMPOSITE=1`, the `x2w-render raw plane <n>` line
shows whether the higher plane holds a picture.

Expand Down
20 changes: 16 additions & 4 deletions src/startup_stubs/d3d12_present.inl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// A flip-model swap chain on the title window, created on the queue the title presents with; each
// present draws its planes into the back buffer, bottom to top, with the plane compositor
// (plane_compositor.h: one full-window triangle a plane; a surface is usually larger than the
// window), and flips. Plane 0 alone by default; every plane with X2W_PRESENT_COMPOSITE=1. Diagnostics go to the window title, because GDI drawing does not mix with a
// window), and flips. Plane 0 alone for a one-plane present; every selected plane otherwise. The
// compositor capacity is fixed on the first present so a later multi-plane present can still draw
// every plane. Diagnostics go to the window title, because GDI drawing does not mix with a
// flip-model swap chain.

struct WindowPresenter {
Expand All @@ -20,7 +22,7 @@ struct WindowPresenter {
UINT width = 0, height = 0;
bool failed = false;
};
constexpr UINT window_planes = 4;
constexpr UINT window_planes = x2w_startup::window_present_max_planes;
WindowPresenter window_presenter;
LONG window_presents;

Expand Down Expand Up @@ -142,7 +144,16 @@ bool create_window_presenter(ID3D12CommandQueue* queue, HWND window, UINT plane_
if (SUCCEEDED(hr)) hr = p.list->Close();
if (SUCCEEDED(hr)) hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&p.fence));
p.reached = CreateEventW(nullptr, FALSE, FALSE, nullptr);
if (SUCCEEDED(hr)) hr = p.compositor.create(device, DXGI_FORMAT_R8G8B8A8_UNORM, plane_capacity);
if (SUCCEEDED(hr)) {
hr = p.compositor.create(device, DXGI_FORMAT_R8G8B8A8_UNORM, plane_capacity);
if (FAILED(hr) && plane_capacity > 1) {
// A missing blend pipeline must not disable the whole output window. A one-plane
// present only needs the opaque pipeline, so retry with that capacity.
log("x2w-present compositor capacity %u failed 0x%08lx; retrying with one plane",
plane_capacity, static_cast<unsigned long>(hr));
hr = p.compositor.create(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1);
}
}
log("x2w-present window swap chain %ux%u -> 0x%08lx", p.width, p.height, static_cast<unsigned long>(hr));
check_device("window presenter", 0);
return SUCCEEDED(hr);
Expand All @@ -163,7 +174,8 @@ bool presentable_surface(ID3D12Resource* surface)

// Composites the steps of a present (present_planes.h composite_steps) into the window and flips.
// plane_surfaces[step.plane] is that plane's surface (resting in COMMON and presentable), or null to
// leave it out. Returns false if not shown.
// leave it out. plane_capacity is fixed for the window presenter's lifetime: pass the largest present
// it can draw, not this present's step count. Returns false if not shown.
bool present_to_window(ID3D12CommandQueue* queue, const x2w_startup::PlaneStep* steps, unsigned count,
ID3D12Resource* const* plane_surfaces, UINT plane_capacity)
{
Expand Down
Loading
Loading