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
8 changes: 8 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13384,6 +13384,14 @@ On Intel UHD Graphics (TGL GT1) with Mesa 26.2.7, DXC 1.10.2605.37 and SPIRV-Too
python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device Intel
VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \
python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device llvmpipe

## Startup single root constants

Command-list slot 38 (`SetGraphicsRoot32BitConstant`) stores one root constant word for a translated shader. The cases are in `tests/startup_mrt_check.py`, which sets the slot through `draw_root_constant` in `tests/startup_root_cbv.cpp` and reads the word back through a rewritten `rootconst` manifest entry: set, overwrite, offset 3 read at offset 3 and at offset 0, preserving offset 0 written through slot 40 while writing offset 3 through slot 38, the corner (15, 7), parameter 16, parameter 0xffffffff, offset 8 and offset 0xffffffff dropped, the same root signature again (word kept), a switched one (word cleared) and no call. The fixture is synthetic only and the slot number is derived from the desktop order plus the console shift, not seen in a title log. Details are in [startup-runtime.md](startup-runtime.md#single-root-constants).

```powershell
cmake --build --preset dev --target startup_stream_consumer
ctest --preset dev --no-tests=error -R "^startup_mrt_" -V
```

## SAL (/6) lifting in cpu_switch_aot
Expand Down
12 changes: 12 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ These slots have not been seen in a title log yet. `CopyTextureRegion` (16) and
`ctest -R '^startup_list_copy_validation'` runs the pure checks on any host; `startup_list_copy_{warp,hardware}` copies,
resolves and reads back through the `x2w_d3d12_list_copy_stats` export.

## Single root constants

Command-list slot 38 (desktop `SetGraphicsRoot32BitConstant` plus four) takes `(parameter, value, offset)` and stores one
word in the same per-list table as slot 40, which a translated shader reads through a `rootconst` manifest entry. A parameter
of 16 or more or an offset of 8 or more has no storage and the call is dropped without a log line. Nothing is forwarded
to the desktop list. Setting the graphics root signature to a different signature clears every stored constant, as it
clears the root addresses; setting the same one again keeps them (this also applies to slot 40). The slot number is derived
from the desktop order and the console shift, not yet seen in a title log. The
`startup_mrt_{fxc,dxc}_{warp,hardware}` tests drive it with eleven cases: set, overwrite, an offset that is and is not the one
the shader reads, preserving an offset written through slot 40 while writing another through slot 38, the last stored slot
(15, 7), four out-of-range calls, the same root signature again, a switched one and no call.

## Composite provenance fixture

Issue #1628 asks whether a uniform colour left in a composite's destination came from the composite or was
Expand Down
8 changes: 8 additions & 0 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,14 @@ void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, co
if (parameter >= 16 || offset >= 8 || !count || !x2w_local::readable(data, std::size_t{count} * 4)) return;
for (UINT i = 0; i < count && offset + i < 8; ++i) pass_of(self).constants[parameter][offset + i] = data[i];
}
// List slot 38 (desktop 34 + 4), SetGraphicsRoot32BitConstant(parameter, value, offset): one word of a root
// constant. The word is kept for the draw like the ones of slot 40; a parameter of 16 or more or an offset of 8 or
// more has no storage and the call is dropped. Nothing is forwarded to the desktop list.
void __stdcall list_root_constant(Wrapper* self, UINT parameter, std::uint32_t value, UINT offset)
{
if (!self || parameter >= 16 || offset >= 8) return;
pass_of(self).constants[parameter][offset] = value;
}
// List slot 47 (desktop 43 + 4), IASetIndexBuffer(view).
void __stdcall list_index_buffer(Wrapper* self, const D3D12_INDEX_BUFFER_VIEW* view)
{
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,7 @@ void build_tables()
list_typed[50] = reinterpret_cast<ListTyped>(&list_targets);
list_typed[13] = reinterpret_cast<ListTyped>(&list_draw_indexed);
list_typed[36] = reinterpret_cast<ListTyped>(&list_table);
list_typed[38] = reinterpret_cast<ListTyped>(&list_root_constant);
list_typed[40] = reinterpret_cast<ListTyped>(&list_root_constants);
list_typed[47] = reinterpret_cast<ListTyped>(&list_index_buffer);
list_typed[48] = reinterpret_cast<ListTyped>(&list_vertex_buffers);
Expand Down
26 changes: 26 additions & 0 deletions tests/startup_mrt_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ def compile_pair(key):
manifest.write_text(original)
print(f'{kind} {backend} optimized FLOAT exact {exact.hex()}; nonzero constant readback {pixels.hex()}')

# SetGraphicsRoot32BitConstant (list slot 38) feeds the same root constant words as slot 40. The manifest
# names the (parameter, offset) the shader reads; the title call either lands there or it does not.
flipped = struct.pack('<4I', *(value ^ word for value in FLOAT_WORDS))
preserved_offset3 = struct.pack('<4I', *(value ^ 0x01800000 for value in FLOAT_WORDS))
cases = (
('set', '0 0', flipped),
('overwrite', '0 0', flipped), # the second call replaces the first
('offset3', '0 3', flipped),
('offset3', '0 0', exact), # a different offset does not reach word 0
('preserve', '0 0', flipped), # slot 38 at offset 3 keeps slot 40's word at offset 0
('preserve', '0 3', preserved_offset3), # and stores its own word at offset 3
('corner', '15 7', flipped), # the last stored slot
('outside', '0 0', exact), # parameter 16, parameter -1, offset 8 and offset -1 are dropped
('same_root', '0 0', flipped), # the same root signature again keeps the word
('switch_root', '0 0', exact), # another root signature clears it
('unbound', '0 0', exact),
)
for mode, source, expected in cases:
manifest.write_text(re.sub(r'mrtbits', 'rootconst ' + source, original))
env['X2W_TEST_ROOT_CONSTANT'] = mode
pixels, _ = draw(2, word)
assert pixels == expected, (mode, source, pixels.hex(), expected.hex())
del env['X2W_TEST_ROOT_CONSTANT']
manifest.write_text(original)
print(f'{kind} {backend} slot 38 root constant: {len(cases)} cases (set, overwrite, offset, corner, bounds, same and switched root)')

base = f'{gfx2hlsl.pipeline_key(vs.read_bytes(), ps.read_bytes(), root.read_bytes()):016x}'
ps_source, ps_blob = cache / f'{base}.ps.hlsl', cache / f'{key}.ps.cso'
compile_shader(compiler, kind, 'ps', ps_source, ps_blob, cache / f'{key}.folded.asm')
Expand Down
52 changes: 52 additions & 0 deletions tests/startup_root_cbv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,55 @@ int draw_root_cbv(void* list)
invoke(list, 12, 3, 1);
return 0;
}

// Before the draw, the title sets root constants with SetGraphicsRoot32BitConstant (list slot 38). The check feeds
// one word, `word`, and X2W_TEST_ROOT_CONSTANT names what is done with it:
// set root signature, then (parameter 0, word, offset 0)
// overwrite a first value at (0, 0), then the word at (0, 0)
// offset3 the word at (0, 3)
// preserve slot 40 sets (0, 0..1) with word at offset 0, then slot 38 writes (0, 3): both offsets stay intact
// corner the word at the last stored slot, (15, 7)
// outside (16, word, 0), (0xffffffff, word, 0), (0, word, 8) and (0, word, 0xffffffff): all dropped
// same_root the word at (0, 0), then the same root signature again: kept
// switch_root the word at (0, 0), then a different root signature and back: cleared
// unbound no call
int draw_root_constant(void* list, std::uint32_t word)
{
char mode[16]{};
GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", mode, sizeof(mode));
const StreamWord root = reinterpret_cast<std::uintptr_t>(stream_root_signature());
if (!root) return 40;
invoke(list, 34, root); // SetGraphicsRootSignature
if (!std::strcmp(mode, "set")) {
invoke(list, 38, 0, word, 0);
} else if (!std::strcmp(mode, "overwrite")) {
invoke(list, 38, 0, 0x5a5a5a5au, 0);
invoke(list, 38, 0, word, 0);
} else if (!std::strcmp(mode, "offset3")) {
invoke(list, 38, 0, word, 3);
} else if (!std::strcmp(mode, "preserve")) {
const std::uint32_t pair[2] = {word, 0x01000000u};
invoke(list, 40, 0, 2, reinterpret_cast<StreamWord>(pair), 0);
invoke(list, 38, 0, 0x01800000u, 3);
} else if (!std::strcmp(mode, "corner")) {
invoke(list, 38, 15, word, 7);
} else if (!std::strcmp(mode, "outside")) {
invoke(list, 38, 16, word, 0);
invoke(list, 38, 0xffffffffu, word, 0);
invoke(list, 38, 0, word, 8);
invoke(list, 38, 0, word, 0xffffffffu);
} else if (!std::strcmp(mode, "same_root")) {
invoke(list, 38, 0, word, 0);
invoke(list, 34, root);
} else if (!std::strcmp(mode, "switch_root")) {
const StreamWord alternate = reinterpret_cast<std::uintptr_t>(stream_alternate_root_signature());
if (!alternate) return 40;
invoke(list, 38, 0, word, 0);
invoke(list, 34, alternate);
invoke(list, 34, root);
} else if (std::strcmp(mode, "unbound")) {
return 2;
}
invoke(list, 12, 3, 1);
return 0;
}
6 changes: 5 additions & 1 deletion tests/startup_stream_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char*
auto* list = frame.list;
auto* queue = frame.queue;
auto* fence = frame.fence;
if (export_word) invoke(list, 40, 0, 1, arg(&export_word), 0);
if (export_word && !GetEnvironmentVariableW(L"X2W_TEST_ROOT_CONSTANT", nullptr, 0))
invoke(list, 40, 0, 1, arg(&export_word), 0);
if (GetEnvironmentVariableW(L"X2W_TEST_LOGICAL_VIEW", nullptr, 0)) {
if (int result = draw_logical_tables(desktop.Get(), guest, list)) return result;
} else if (GetEnvironmentVariableW(L"X2W_TEST_PLACED_VERTEX", nullptr, 0)) {
Expand All @@ -315,6 +316,9 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char*
} else if (bc_chain) {
extern int draw_bc_chain(void*, void*);
if (const int result = draw_bc_chain(guest, list)) return result;
} else if (GetEnvironmentVariableW(L"X2W_TEST_ROOT_CONSTANT", nullptr, 0)) {
extern int draw_root_constant(void*, std::uint32_t);
if (const int result = draw_root_constant(list, export_word)) return result;
} else if (GetEnvironmentVariableW(L"X2W_TEST_ROOT_CBV", nullptr, 0)) {
extern int root_heap_control(ID3D12Device*);
extern int draw_root_cbv(void*);
Expand Down
18 changes: 15 additions & 3 deletions tests/startup_stream_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,22 @@ int prepare_stream_pipeline(const char* vs_path, const char* ps_path, const char
return rejected ? rejected : 7;
}
stream_root = root;
if (std::strcmp(cbv_mode, "switch_root") == 0) {
root_cbv.Descriptor.ShaderRegister = 1;
char rc_mode[16]{};
GetEnvironmentVariableA("X2W_TEST_ROOT_CONSTANT", rc_mode, sizeof(rc_mode));
if (std::strcmp(cbv_mode, "switch_root") == 0 || std::strcmp(rc_mode, "switch_root") == 0) {
D3D12_ROOT_SIGNATURE_DESC alt_desc = root_desc;
D3D12_ROOT_PARAMETER alt_param = root_cbv;
if (std::strcmp(cbv_mode, "switch_root") == 0) {
alt_param.Descriptor.ShaderRegister = 1;
} else {
alt_param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
alt_param.Constants = {1, 0, 1};
alt_param.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
}
alt_desc.NumParameters = 1;
alt_desc.pParameters = &alt_param;
ComPtr<ID3DBlob> alternate;
if (FAILED(serialize_root(root_desc, alternate)) ||
if (FAILED(serialize_root(alt_desc, alternate)) ||
FAILED(reinterpret_cast<CreateRoot>(slots[16])(device, 0, alternate->GetBufferPointer(),
alternate->GetBufferSize(), __uuidof(ID3D12RootSignature),
&stream_alternate_root))) return 7;
Expand Down
Loading