diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c07c5b5a8..5da721cd70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json index 57f5998522..e649592f3b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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", @@ -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)$" } } }, diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index ea9c9626db..0294c057e5 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -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=` 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 @@ -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 (not composited): surface x format , sample , mean level /255, mean alpha /255 @@ -345,9 +353,10 @@ The first presents and every 300th log each plane: x2w-present frame plane /: x format flags=0x ``` -`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 @@ -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=` | 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=` | 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 (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=` | 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 (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=` | 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=`, `X2W_DRAW_DUMP_DIR`, `X2W_DRAW_DUMP_PIXEL=,` | 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=` | 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 detached= released=` 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. | @@ -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=` 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=` 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 ` line shows whether the higher plane holds a picture. diff --git a/src/startup_stubs/d3d12_present.inl b/src/startup_stubs/d3d12_present.inl index cc5beab24c..19438fede1 100644 --- a/src/startup_stubs/d3d12_present.inl +++ b/src/startup_stubs/d3d12_present.inl @@ -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 { @@ -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; @@ -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(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(hr)); check_device("window presenter", 0); return SUCCEEDED(hr); @@ -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) { diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index cc1f9abc54..4b18f2f223 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -71,6 +71,7 @@ #include "startup_stubs/present_signature_sampler.h" #include "startup_stubs/present_planes.h" #include "startup_stubs/plane_compositor.h" +#include "startup_stubs/window_plane_capacity.h" #include #include "command_list_slot_names.h" @@ -7817,7 +7818,8 @@ void report_budget(ID3D12CommandQueue* queue) } // X2W_PRESENT_COMPOSITE=1 (experimental, docs/startup-runtime.md#presented-planes): the output -// window composites every presented plane. Unset, the window shows plane 0 alone, as before. +// window composites every presented plane, including for a one-plane present, and enables the +// raw-plane sample. Unset, the window shows plane 0 alone, as before. bool present_composite_enabled() { static const bool on = x2w_local::env_on("X2W_PRESENT_COMPOSITE"); @@ -7825,9 +7827,10 @@ bool present_composite_enabled() } // The planes the output window draws for a present, resolved to real resources it can draw. -// X2W_PRESENT_PLANE= (diagnostic) keeps plane n alone (plane 0 when n is past the count). Otherwise -// plane 0 alone is kept, unless X2W_PRESENT_COMPOSITE=1 keeps every plane for the composite -// (present_planes.h). The baseline capture and readback do not use this: they read plane 0 as before. +// X2W_PRESENT_PLANE= (diagnostic) keeps plane n alone (plane 0 when n is past the count) and wins +// over the switch. Otherwise plane 0 alone is kept, unless X2W_PRESENT_COMPOSITE=1 keeps every plane +// (present_planes.h select_presented_planes). The baseline capture and readback do not use this: +// they read plane 0 as before. struct PresentedPlanes { ID3D12Resource* drawable[window_planes] = {}; // per plane, null when left out x2w_startup::PlaneStep steps[window_planes]; @@ -7845,11 +7848,10 @@ PresentedPlanes presented_planes(UINT planes, const void* plane_parameters) PresentedPlanes out; std::uint64_t shown[window_planes] = {}; const unsigned total = planes < window_planes ? planes : window_planes; - const unsigned only = wanted >= 0 ? (static_cast(wanted) < planes ? static_cast(wanted) : 0u) - : present_composite_enabled() ? ~0u - : 0u; + const x2w_startup::PlaneSelection selection = + x2w_startup::select_presented_planes(planes, wanted, present_composite_enabled()); for (unsigned i = 0; i < total; ++i) { - if (only != ~0u && i != only) continue; + if (!selection.all && i != selection.only) continue; const std::uint64_t resource = x2w_startup::present_plane_resource(plane_parameters, planes, i, readable); Wrapper* const surface = resource ? as_wrapper(reinterpret_cast(resource)) : nullptr; if (!surface || surface->own().kind != resource_kind || !surface->own().real) continue; @@ -7946,7 +7948,7 @@ HRESULT __stdcall queue_present(Wrapper* self, UINT planes, const void* plane_pa if (first_calls(plane_log, 4)) log("x2w-present render mode: %u drawable planes", presented.count); shown_in_window = present_to_window(static_cast(self->own().real), presented.steps, presented.count, - presented.drawable, present_composite_enabled() ? window_planes : 1); + presented.drawable, window_planes); } if (present_composite_enabled() && presented.top && presented.top_plane > 0) { raw_surface = presented.top; diff --git a/src/startup_stubs/present_planes.h b/src/startup_stubs/present_planes.h index 0c71c7ac1d..a1d370f7e3 100644 --- a/src/startup_stubs/present_planes.h +++ b/src/startup_stubs/present_planes.h @@ -39,6 +39,26 @@ struct PlaneStep { bool blended = false; }; +// Which planes of a present the output window draws. A diagnostic choice (X2W_PRESENT_PLANE=) +// keeps plane n alone and wins over the switch; n past the count falls back to plane 0. Otherwise +// plane 0 alone is kept, unless `composite` (X2W_PRESENT_COMPOSITE=1) keeps every plane, so a black +// or empty plane 0 does not hide a picture on a higher plane. The switch is opt-in because a matched +// real-present comparison is still missing; it also covers a one-plane present. +struct PlaneSelection { + bool all = false; // keep every plane + unsigned only = 0; // otherwise the single plane kept +}; + +inline PlaneSelection select_presented_planes(unsigned planes, long wanted, bool composite) +{ + PlaneSelection selection; + if (wanted >= 0) + selection.only = static_cast(wanted) < planes ? static_cast(wanted) : 0u; + else if (composite) + selection.all = true; + return selection; +} + // The window composite of a present, bottom to top, the way planes stack on the console: plane 0 // first, each later plane over it. `resources[i]` is plane i's surface, 0 when it cannot be shown; // those planes and repeats of a surface already drawn are left out. The lowest drawn plane is diff --git a/src/startup_stubs/window_plane_capacity.h b/src/startup_stubs/window_plane_capacity.h new file mode 100644 index 0000000000..bd147a85a5 --- /dev/null +++ b/src/startup_stubs/window_plane_capacity.h @@ -0,0 +1,13 @@ +// The largest number of planes the output window compositor can draw. Its capacity is fixed on the +// first present (d3d12_present.inl), so it must cover a later multi-plane present: a first +// one-plane present must not cap every present at one plane. Shared with the pure selection test so +// the value the presenter passes is checked there too. +#pragma once + +#include + +namespace x2w_startup { +// The presenter's capacity is a count of planes; std::uint32_t is the same width as D3D12's UINT +// on the supported x64 host, and this header is also included by the pure C++ test. +inline constexpr std::uint32_t window_present_max_planes = 4; +} // namespace x2w_startup diff --git a/tests/startup_present_planes_check.cpp b/tests/startup_present_planes_check.cpp index 88473d3c6c..2f2947d542 100644 --- a/tests/startup_present_planes_check.cpp +++ b/tests/startup_present_planes_check.cpp @@ -1,10 +1,12 @@ // Checks src/startup_stubs/present_planes.h on synthetic plane records: two 0x48-byte records, each // with a frame token, a resource count and a pointer to its resource array. -// Also checks the window composite order (composite_steps) on synthetic plane surfaces. -// --control reads the records with a 0x40-byte stride (the record size before the second plane was -// measured) and composites plane 0 alone (the window present before planes were composited); the -// second-plane rows must print FAIL. +// Also checks the plane selection policy, the presenter's plane capacity and the window composite +// order (composite_steps) on synthetic plane surfaces. --control reads the records with a 0x40-byte +// stride (the record size before the second plane was measured), composites plane 0 alone, keeps the +// old single-plane selection and reserves a capacity of one plane (the window present before planes +// were composited); the second-plane, multi-plane and capacity rows must print FAIL. #include "startup_stubs/present_planes.h" +#include "startup_stubs/window_plane_capacity.h" #include #include @@ -58,6 +60,38 @@ int main(int argc, char** argv) const auto unreadable = [](const void*, std::size_t) { return false; }; check("an unreadable record has no resource", present_plane_resource(records, 2, 0, unreadable, stride) == 0); + // Selection: plane 0 alone by default; X2W_PRESENT_COMPOSITE=1 keeps every plane; + // X2W_PRESENT_PLANE= keeps one plane and takes priority. + using x2w_startup::select_presented_planes; + const auto defaults_to_plane0 = [&](unsigned planes) { + // The control models the withdrawn "compose by default" policy, so the row prints FAIL. + // Call the policy in both modes so the control exercises the same function. + const bool selected = select_presented_planes(planes, -1, false).all; + return control ? selected : !selected; + }; + check("two planes keep plane 0 alone by default", defaults_to_plane0(2)); + check("four planes keep plane 0 alone by default", defaults_to_plane0(4)); + x2w_startup::PlaneSelection selection = select_presented_planes(1, -1, false); + check("a single plane is plane 0 alone", !selection.all && selection.only == 0); + selection = select_presented_planes(2, -1, true); + check("X2W_PRESENT_COMPOSITE keeps every plane", selection.all); + selection = select_presented_planes(2, 1, false); + check("X2W_PRESENT_PLANE=1 keeps plane 1 alone", !selection.all && selection.only == 1); + selection = select_presented_planes(2, 1, true); + check("X2W_PRESENT_PLANE wins over the composite switch", !selection.all && selection.only == 1); + selection = select_presented_planes(2, 9, false); + check("a plane past the count falls back to plane 0", !selection.all && selection.only == 0); + selection = select_presented_planes(1, -1, true); + check("the composite switch keeps the only plane", selection.all); + selection = select_presented_planes(0, -1, false); + check("no planes keeps plane 0 alone", !selection.all && selection.only == 0); + + // The compositor's capacity is fixed on the first present. The presenter must always reserve + // the largest present it can draw so that a later multi-plane present is not capped at one + // plane. The control keeps the old capacity of one plane; that row must print FAIL. + check("the presenter reserves the maximum plane capacity", + !control && x2w_startup::window_present_max_planes == 4u); + // Composite order: the lowest shown plane is opaque, later ones blend over it. using x2w_startup::PlaneStep; const auto composite = [&](const std::uint64_t* resources, unsigned count, PlaneStep* steps) {