Skip to content
Closed
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
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,20 @@ target_compile_features(startup_runtime_gpa_patch PRIVATE cxx_std_17)
add_test(NAME startup_runtime_gpa_patch COMMAND startup_runtime_gpa_patch)
add_test(NAME startup_runtime_gpa_patch_name_only_control COMMAND startup_runtime_gpa_patch --mutate name-only)
set_tests_properties(startup_runtime_gpa_patch_name_only_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# X2W_DEVICE_TYPE: the OEM ConsoleMode registry read, answered or passed on, against fake registry
# functions. The control leaves the switch unset for the answered cases and must FAIL.
add_executable(startup_console_mode tests/startup_console_mode_check.cpp)
target_include_directories(startup_console_mode PRIVATE src)
target_compile_features(startup_console_mode PRIVATE cxx_std_17)
add_test(NAME startup_console_mode COMMAND startup_console_mode)
add_test(NAME startup_console_mode_control COMMAND startup_console_mode --control)
set_tests_properties(startup_console_mode_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
add_executable(startup_view_dimension tests/startup_view_dimension_check.cpp)
target_include_directories(startup_view_dimension PRIVATE src)
target_compile_features(startup_view_dimension PRIVATE cxx_std_17)
add_test(NAME startup_view_dimension COMMAND startup_view_dimension)
add_test(NAME startup_view_dimension_control COMMAND startup_view_dimension --control)
set_tests_properties(startup_view_dimension_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# EXE + late-loaded package helper through the real Windows loader: proxied xgameruntime QueryApiImpl,
# unrelated same-named export stays original. Notification only enqueues; rewrite runs after link.
if (WIN32)
Expand Down Expand Up @@ -1899,6 +1913,12 @@ 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()
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)
add_test(NAME startup_present_planes COMMAND startup_present_planes)
add_test(NAME startup_present_planes_control COMMAND startup_present_planes --control)
set_tests_properties(startup_present_planes_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# Static samplers built from smp and smpc manifest lines (src/startup_stubs/translated_sampler_bindings.h).
add_executable(startup_sampler_comparison_check tests/startup_sampler_comparison_check.cpp)
target_include_directories(startup_sampler_comparison_check PRIVATE src)
Expand Down
52 changes: 52 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ presenter, its owned window and a dialog stay visible. Where the host lets the t
it also checks that the foreground moves to the output window. A run under Wine did; the fixture prints
which case applied.

### Presented planes

A console present (CommandQueue slot 32) carries a plane count and an array of plane records
(`src/startup_stubs/present_planes.h`). Measured from the first presents: one record is 0x48 bytes,
with +0x00 a frame token, +0x08 the resource count and +0x10 a pointer to the resource array. On the
Series S profile a title presented two planes: plane 0 at 1920x1080 stayed black and plane 1 at
3840x2160 held the picture, with alpha 255 wherever it drew. Showing plane 0 alone gave a black
window. The output window now composites the planes bottom to top: the lowest shown plane opaque, each
later one blended by its own alpha (`composite_steps`); planes the presenter cannot draw and repeats of
a surface are left out. The plane whose surface is read back and reported is the topmost one. Why
plane 0 stays black is not known. The first presents and every 300th log each plane:

```text
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; the control reads 0x40-byte records and composites plane 0 alone, and must
print `FAIL:`.

## Null Texture2D descriptors

When the adapter lacks typed UAV support for B5G5R5A1_UNORM or render-target support for
Expand Down Expand Up @@ -1352,6 +1372,8 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `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_DEVICE_TYPE=<n>` | with `X2W_RUNTIME_PROXY=1`, answers the title's reads of the OEM `ConsoleMode` registry value: `6` = 0x60 (Series S), `7` = 0x64 (Series X), `1` = value missing (PC); unset, the real registry answers. See [Console profile](#console-profile) |
| `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) instead of compositing every plane. 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` | 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). |
| `X2W_AUDIO_PERMISSIVE=1` | enables the audio stand-ins. Without a DSP provider, `XDspActivate` clears valid outputs and reports unavailable resources, and failed `XDspSubmitCommand` calls leave the sequence unchanged. `XDspDeactivate` and `XDspDisconnect` refuse null and unknown handles with `E_INVALIDARG`. |
Expand Down Expand Up @@ -1384,6 +1406,36 @@ together under their original name. A 16-dword table load can contain two
independent image descriptors at offsets 0 and 32 from the load address.
For a read-only census of cached shader refusals, use `python -B tools/startup/gfx2hlsl.py --refusals <cache-directory> [--json]` with a translator that supports the flag. Earlier versions treat it as `--pending` and write into the directory. See [Startup translator refusal census](experiments.md#startup-translator-refusal-census).

## Console profile

`X2W_DEVICE_TYPE` answers the two registry reads a title makes of
`HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode`
(`src/startup_stubs/console_mode.h`, `registry_console_mode.inl`): with `X2W_RUNTIME_PROXY=1` the
stand-in rewrites the registry imports of the EXE and package helpers. `6` answers 0x60 (Series S),
`7` answers 0x64 (Series X) and `1` reports the value missing (PC); unset, every call goes to the real
registry. Opening the key and reading the value are logged a few times either way. What the values
mean on the console is taken from public notes, not measured here.
`ctest --preset dev --no-tests=error -R '^startup_console_mode(_control)?$'` runs it against fake
registry functions; the control leaves the switch unset for the answered cases and must print `FAIL:`.

The Series S profile loads an upscaler package module that the other profiles do not. Three desktop
refusals stopped it; the stand-in now avoids each:

- `Device::slot76` (Xbox order) is desktop `CreateCommittedResource` with seven arguments (heap
properties, heap flags, desc, initial state, clear value, riid, ppv). It shares the committed-resource
path of slot 127.
- A view description with `ViewDimension` 0 (UNKNOWN) makes desktop D3D12 remove the device. Measured:
the module makes such SRVs on 2D RGBA8 textures. Views of slots 18 to 21 with dimension 0 now get the
resource's default view (null description) where desktop allows one (not for buffers, typeless or
unknown formats, or depth formats in an SRV); otherwise the view is skipped and logged. A view whose
dimension does not fit the resource is skipped too (`src/startup_stubs/view_dimension.h`;
`ctest --preset dev --no-tests=error -R '^startup_view_dimension(_control)?$'`).
- `R9G9B9E5_SHAREDEXP` textures with unordered access fail with `E_INVALIDARG`; the
[shared-exponent stand-in](#shared-exponent-render-and-unordered-access-targets) covers them.

With these, a Series S profile run reaches the same scripted point as the Series X and PC profiles.
That is a start-up milestone, not evidence that a title runs.

## D3D12 resource budget

Set `X2W_D3D12_BUDGET=1` before startup to add one `x2w-budget` line to each
Expand Down
96 changes: 96 additions & 0 deletions src/startup_stubs/console_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Experimental (docs/startup-runtime.md): which console the title is told it runs on.
//
// Public GDK documentation describes XSystemGetDeviceType and the XSystemDeviceType values
// (Pc = 1, XboxScarlettLockhart = 6, XboxScarlettAnaconda = 7). The proxied runtime calls seen in
// startup runs include no device-type method. A public runtime reimplementation's notes
// (github.com/Marvisak/VIctory, facts only) say the value is not a runtime call: title code reads
// HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM, DWORD value ConsoleMode, where 0x60 is
// Series S, 0x64 is Series X and a missing value is a PC. Those three readings are that source's,
// not measured here.
//
// X2W_DEVICE_TYPE=<n> (with X2W_RUNTIME_PROXY) answers that one value: 6 -> 0x60, 7 -> 0x64,
// 1 -> missing. Unset or any other number passes every read to the real registry.
// Pure helpers, no Windows calls, so a source-built control can check them.
#pragma once

#include <cstddef>
#include <cstdint>

namespace x2w_console_mode {

constexpr long status_ok = 0, status_not_found = 2, status_invalid = 87, status_more_data = 234, status_wrong_type = 1630;
constexpr unsigned long type_dword = 4;
constexpr unsigned long rrf_rt_reg_dword = 0x10;
constexpr std::uint32_t series_s = 0x60, series_x = 0x64;

inline wchar_t fold(wchar_t c) noexcept
{
return (c >= L'A' && c <= L'Z') ? static_cast<wchar_t>(c - L'A' + L'a') : c;
}

inline bool equal_ci(const wchar_t* a, const wchar_t* b) noexcept
{
if (!a || !b) return false;
for (;; ++a, ++b) {
if (fold(*a) != fold(*b)) return false;
if (!*a) return true;
}
}

// Subkey of HKEY_LOCAL_MACHINE. One leading or trailing backslash is accepted.
inline bool is_oem_subkey(const wchar_t* subkey) noexcept
{
static constexpr wchar_t expect[] = L"software\\microsoft\\windows nt\\currentversion\\oem";
if (!subkey) return false;
if (*subkey == L'\\') ++subkey;
std::size_t i = 0;
for (; expect[i]; ++i)
if (fold(subkey[i]) != expect[i]) return false;
return !subkey[i] || (subkey[i] == L'\\' && !subkey[i + 1]);
}

inline bool is_console_mode_value(const wchar_t* name) noexcept
{
return equal_ci(name, L"ConsoleMode");
}

enum class Answer { pass, value, missing };

// device_set is false when X2W_DEVICE_TYPE is absent or not a number.
inline Answer answer_for(bool device_set, unsigned long device_type, std::uint32_t* mode) noexcept
{
if (!device_set) return Answer::pass;
switch (device_type) {
case 1: return Answer::missing;
case 6: if (mode) *mode = series_s; return Answer::value;
case 7: if (mode) *mode = series_x; return Answer::value;
default: return Answer::pass;
}
}

// RegQueryValueExW's output rules for one REG_DWORD.
inline long fill_query(std::uint32_t value, unsigned long* type, unsigned char* data, unsigned long* bytes) noexcept
{
if (data && !bytes) return status_invalid;
if (type) *type = type_dword;
if (!data) {
if (bytes) *bytes = sizeof(value);
return status_ok;
}
if (*bytes < sizeof(value)) {
*bytes = sizeof(value);
return status_more_data;
}
for (std::size_t i = 0; i < sizeof(value); ++i) data[i] = static_cast<unsigned char>(value >> (8 * i));
*bytes = sizeof(value);
return status_ok;
}

// RegGetValueW's: the flags must allow a DWORD (RRF_RT_REG_DWORD, part of RRF_RT_DWORD and RRF_RT_ANY).
inline long fill_get(unsigned long flags, std::uint32_t value, unsigned long* type, void* data, unsigned long* bytes) noexcept
{
if (!(flags & rrf_rt_reg_dword)) return status_wrong_type;
return fill_query(value, type, static_cast<unsigned char*>(data), bytes);
}

} // namespace x2w_console_mode
Loading
Loading