Measured by madhyn on the retail title with this pull request (#974
review): one of its start-up root signatures is past the console's
inline graphics window (24 dwords from s8) and the compute one (28 from
s4), so CreateRootSignature refused it outright and the title stopped
with an unhandled exception before the frame loop it reached without
this change.
On the console such a signature goes to the argument block behind
s[0:1], modelled for compute only (ROOT-SIG-SPILL-MODEL, #1009). Until
it is for graphics, the graphics bind point keeps pack()'s layout for
it (from s0, two dwords per table), what the layer did before the
console layout, so no signature is worse off than on main. The new
RootArgumentLayout::graphics_console tells address() which layout the
table is in; a mesh shader still refuses such a signature.
d3d12_mesh_test: a 30-constant signature is created and DispatchMesh
with it invalidates the list.
The graphics bind point laid root arguments out with pack() (from s0, two
dwords per table), while the console starts them at s8 for VS/PS/GS with
one dword per table (the corpus census, and the retail frame loop reading
its tables at s8..s10). Compute already took the console layout (D3D-448);
graphics waited because a mesh shader (s16) and a pixel shader (s8) share
one push-constant block.
- translator: user_data_dword() - a mesh shader loads s16..s31 from push
dwords 8..23, s8..s15 as 0, s0..s7 unchanged, so root dword k is push
dword 8 + k for every graphics stage; index.json records the window as
"root_window" on mesh shaders. VS/PS/GS/CS are unchanged.
- runtime: CreateRootSignature lays graphics out with
pack_stage(Stage::Vertex) and checks Stage::Mesh (mesh_ok); a table is
one dword at both bind points; DispatchMesh with a signature past the
16-dword mesh window invalidates the list; a mesh PSO whose mesh shader
has no root_window (translated before) is refused with a log line.
- fixtures: the GLSL stand-ins read the root arguments at push dword 8 + k;
the M1.5/M2/M3 asm read their tables as one dword from s8.
- tests: tests/semantic/test_ms_root_window.py (MeshEXT and --mesh-compute
on the CPU interpreter), graphics-window cases in root_signature_test,
the two refusals in d3d12_mesh_test.
- docs: d3d12_vulkan.md 3.5, design.md user-data row.
Merging.
**Why merged:** Comment-only fix in d3d12_vulkan_device.cpp: four stale comments now describe what the code actually does. Oliwettoo checked each one against the code ("Ship").
**Why it's good:** No code change: the diff touches only comments.
Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 47c651174, where the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests) gives 566 passed / 5 skipped / 0 failed with this PR in. git merge-tree against current main 8f05e09e2: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.
AI-assisted (Claude Code, Claude Opus 5.5).
Retain the first-run origin-token poll and shared tokens alongside standard origin, vblank and flip events. Route attached presenter callbacks before the fallback window and dispatch local speech through the Windows provider with the upstream offline fallback.
The offline pipeline checker now enables the runtime mesh query feature for cache-producing runs. A controlled GPU comparison with the same compute shader changed from a miss to an application cache hit.
A DEPTH_STENCIL2 subobject whose FrontFace and BackFace masks differ was
refused with E_NOTIMPL, and OPTIONS14 reported
IndependentFrontAndBackStencilRefMaskSupported = FALSE although the
per-face references of OMSetFrontAndBackStencilRef already reach the
draw. Vulkan has a compare and a write mask per face in VkStencilOpState.
parse_pipeline_stream keeps the front face's masks in the description and
the back face's beside it (PipelineStream::back_stencil), create_graphics
takes them as an optional argument for depth.back, and OPTIONS14 now
reports the cap. The classic CreateGraphicsPipelineState path and its
cached-PSO key are unchanged: D3D12_DEPTH_STENCIL_DESC has one mask pair.
d3d12_state_sweep_test builds 16 more PSOs from a stream with
DEPTH_STENCIL2 (same, split, front-only and back-only masks; one reference
or two through OMSetFrontAndBackStencilRef; front- and back-facing) and
compares the colour and stencil readback with the host D3D12 device: 498
cases, 0 differ on an RTX 5070 Ti. Giving the back face the front face's
masks makes 6 of them differ. d3d12_vulkan_device_test expects the cap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the validated console heap range when the title has no allocation hooks. Preserve partially committed buffer reservations, compare CBVs produced through the same ABI, and use the runtime's image robustness setting in the offline pipeline checker.
Keep the desktop HRESULTs for Xbox-only formats. Check both console and desktop vtable callers in the mock, and exercise the full rectangle target for a derived PSO with a zero sample mask.
Keep completion batches with their owning Vulkan context. Test switching primitives, caller overrides, and the dynamic EXEC and uniform null-descriptor guards used for dimension-specific storage views.
Use the tagged pipeline variants and indexed quad expansion from #722 and #682 with the shared shader cache. Retain title-backed index uploads, cross-queue scratch sharing, amd64 console return conventions and the PC/console caller discriminator. The local shader build indexes native containers and includes the executable's embedded stages.
Build on the public frame-loop integration in #321. Carry the texture-view and depth work from #213 and #261, the layout provider from #461, the responsive window from #526, and the rectangle generator from #682. Integrate the Xbox constant-buffer row addressing measured in #513 and the draw-time rectangle selection in #722. Keep all fixtures synthetic.
The Windows GPU path resolves title-owned shader objects, retires geometry uploads per submission, materializes texture views on use, maps linear surfaces, and delivers completed GPU label writes. A first-run UI launch selects the tested settings for these paths.
Select the geometry-stage variant when the input assembler requests an Xbox rectangle and cache it alongside the attachment-format variants. Keep a shared snapshot of the linked vertex program for that draw. Exercise alternating rectangle and triangle draws through the same PSO and compare the complete target after each switch.
Where the device has the meshShaderQueries feature of VK_EXT_mesh_shader, the number of
primitives the mesh shader emitted comes from a VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT
query run around each mesh segment, and it is added as the clipping invocations of that
segment. CPrimitives stays 0: Vulkan has no clipped-primitive counter, and D3D12's
CPrimitives is the clipper's output.
Claim: D3D-MESH-CLIPPING-COUNTER
Depends on: #540
A default-heap acceleration-structure resource in the GPU address arena handed out buffer address + offset as its
GPU VA without asking the driver. An instance must name its BLAS by a value obtained from
vkGetAccelerationStructureDeviceAddressKHR (VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281), and for a GENERIC
structure the spec only promises consistent offsets between structures of one buffer, not equality with the buffer
address. Query it as the committed path does; if a driver ever returns a different address, use the driver's and
keep the arena address registered too.
GPU-assisted validation only knows addresses it has seen that call return, so it reported every arena BLAS as "an
invalid acceleration structure reference" and rewrote the instance to its dummy BLAS (the ray-query miss marso006
saw). It now reports the remaining layer limitation instead: a GENERIC structure built as bottom level is "not a
bottom level acceleration structure", which the spec allows.
Restored from old upstream PR 8414, which was closed unmerged when the original repository went private.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An indexed quad list was one triangle fan per quad over the application's index buffer.
That is wrong in two ways, both measured on #207 (RTX 4070 Ti there, RTX 4070 SUPER here):
- A fan's triangles are (v1 v2 v0) and (v2 v3 v0), and Vulkan takes a flat input from a
triangle's first vertex. So a quad showed its second and third vertex, never its first:
a quad with a red first vertex came out black and blue, 0 of 4096 pixels red.
- One draw per quad runs every instance of quad 0 before quad 1. D3D12 draws instance by
instance, so where instances overlap the wrong one ended on top (2048 of 4096 pixels).
Neither can be fixed inside that scheme (VK_EXT_provoking_vertex cannot name a fan's hub
either), so the indices are rewritten: a compute pass (quad_index_expand.comp) reads the
application's index buffer on the GPU and writes (i0 i1 i2) (i0 i2 i3) for each quad as
32-bit indices into copy scratch, and the draw is one indexed triangle list over that
scratch with the application's instance count, base vertex and first instance. Both
triangles start at the quad's first vertex, like the non-indexed path.
- The host never reads the indices: a copy or a shader earlier in the list can have
written them. The pass runs before the draw's rendering scope, between a barrier for
those writes and one for its own, and between two segments of an active
pipeline-statistics query, as the other helper dispatches do (D3D-162).
- 16-bit and 32-bit indices, read as whole words, so a 16-bit view at an address of
2 modulo 4 works. Index values are copied as they are: VertexIndex - BaseVertex is still
the application's index.
- The strip-cut values are ordinary indices, as in every list topology. An index past the
view reads 0, as in D3D12, and the pass reads nothing past the view. A draw's last one to
three indices are dropped.
- It needs bufferDeviceAddress. Without it, or inside a statistics query that cannot be
split, the list is refused as unsupported.
- vulkan_topology(19) is a triangle list for both paths; nothing draws a fan any more
(MoltenVK has no fans).
replay_quad_list_test replays indexed draws through prepare() and the real expander on a
recording device: one dispatch before the rendering scope and one draw in it, the push
constants for both index sizes, the view's end, the split of a draw larger than one
dispatch, the refusals, and the order inside a statistics query.
AI-assisted (Claude Code; Claude Opus 5.5 and Claude Fable 5.2).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
std::array::size() is a size_t, and the two constants made from it are 32-bit. MSVC warned
once in d3d12_vulkan_device.cpp and once in every file that includes vulkan_replay.h: 124
C4267 warnings in a Windows build of the runtime and its tests. The values (6 indices for a
quad) are unchanged.
AI-assisted (Claude Code; Claude Opus 5.5 and Claude Fable 5.2).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
Taken from the follow-up patch of @matheuskshn (930e78a2, tested by them on an RTX 4070 Ti: replay_quad_list_test fails the two non-indexed cases on a6b31d51 and passes with it). Re-run here: replay_quad_list_test and d3d12_rect_list_test exit 0 on the pod (Wine, RTX 4090).
A rectangle list is three corners; the fourth is v2 + v3 - v1 for the position and every interpolant, after the vertex stage. A quad list is four vertices per quad. Vulkan has neither. A PSO with topology type 19 was refused (E_INVALIDARG) and the two list topologies drew as a plain triangle list.
Rectangle list: the PSO becomes a triangle-list pipeline with a generated geometry stage (src/rect_list_geometry.h), built from the vertex shader's own SPIR-V outputs, that emits the strip v1 v2 v3 v4. Quad list: one triangle fan per quad (0 1 2, 0 2 3), drawn with the index values 4q..4q+3 so the translated vertex id (VertexIndex - BaseVertex) is right; non-indexed draws read a shared 0, 1, 2, ... buffer reserved in the arena.
Facts from xvalkyrie (GPL-3.0, commit 53af7df77c10); no code copied.
The Vulkan layer created signatures for draw, draw-indexed and dispatch only and answered E_NOTIMPL
for DISPATCH_MESH, which the PC runtime creates on any mesh-shader tier 1 device. A title that
creates such a signature at startup and asserts on the result stopped there.
The signature is created when the device has VK_EXT_mesh_shader (MeshShaderTier 1), as a new
IndirectKind::dispatch_mesh (the name and value #3777 uses, so the two merge). ExecuteIndirect with
it records nothing yet and says so once; #3777 replays it as vkCmdDrawMeshTasksIndirectEXT.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit efc347830b)
NVIDIA has no renderable 4444 Vulkan format (A4R4G4B4, R4G4B4A4, B4G4R4A4 are sampled only), so a B4G4R4A4_UNORM
texture with ALLOW_RENDER_TARGET was refused and GetResourceAllocationInfo answered UINT64_MAX. Such a texture is now
an RGBA8 image, which holds every 4-bit value exactly: RTVs and PSO target formats follow the image, SRV T#s still
name 4_4_4_4, and bind_image views the RGBA8 image with A4R4G4B4's channels. Not covered: buffer copies of it move
4-byte texels.
Test: d3d12_b4g4r4a4_target (size and creation, RTV clears read back, SRV T# format; 0 validation errors).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WriteToSubresource/ReadFromSubresource without host image copy replay a
CopyTextureRegion on a staging VulkanQueue and wait for it. The wait was
VulkanQueue::idle(): vkQueueWaitIdle on info.queue, the VkQueue the first
D3D12 direct queue also uses, under the device's submit lock. Every such
CPU copy waited for all the game work queued there, and no queue could
submit meanwhile.
- VulkanQueue::wait_submitted waits on the queue's own progress timeline
for what it submitted, without the submit lock (bounded slices, wakes on
device loss). The staging copy uses it instead of idle().
- The staging queue is on a VkQueue the game's first queues are not on
(CreateCommandQueue hands each family's out from the first, so the
last): the copy family's for colour textures, whose engine runs beside
queued graphics work; the graphics family's for depth/stencil and rgb96
textures, whose copies may run the D24/rgb96 compute pass. A second
graphics VkQueue alone did not help on NVIDIA: the timeline wait still
took the whole 32 ms, the copy ran behind the busy queue. Where the
family has one VkQueue the copy shares info.queue as before.
- No waits on other queues are attached: D3D12 requires the application
to have seen the texture's GPU work complete before a CPU copy (it waits
on a fence its queue signalled), and that host wait followed by this
submission orders the work before the copy and makes its writes visible.
Pending work of other queues would only be waited for needlessly.
Measured (d3d12_staged_copy_wait_test, RTX 3080 Laptop, standalone
device): a staged 64x64 WriteToSubresource while the direct queue has 32 ms
of buffer copies queued took 31.8 ms before, 0.10 ms now (the direct queue
still busy after it); the bytes round-trip. d3d12_subresource_copy (both
paths, 109 steps against the host and Microsoft's answers), d3d12_rgb96 and
the new test are clean under LEONIDA_VK_VALIDATION=1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Vulkan layer created signatures for draw, draw-indexed and dispatch only and answered E_NOTIMPL
for DISPATCH_MESH, which the PC runtime creates on any mesh-shader tier 1 device. A title that
creates such a signature at startup and asserts on the result stopped there.
The signature is created when the device has VK_EXT_mesh_shader (MeshShaderTier 1), as a new
IndirectKind::dispatch_mesh (the name and value #3777 uses, so the two merge). ExecuteIndirect with
it records nothing yet and says so once; #3777 replays it as vkCmdDrawMeshTasksIndirectEXT.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit efc347830b)
- PipelineState is not compute-only: create_graphics builds graphics PSOs too.
- The R8/R16 SNORM and SINT input-layout formats are mapped (352b9af1), so the format-support note drops its "no mapping yet".
- Buffer UAVs exist (write_buffer_uav writes a typed V#); what the layer does not create is a VkBufferView.
- Timestamps are not read from "the one VkQueue every D3D12 queue submits to": the period is enabled from the graphics family's timestampValidBits.
Comments only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The "[rt] localdbg:" lines and the experiment switches are gone: LEONIDA_RECT_GREEN, LEONIDA_RECT_VS,
LEONIDA_RECT_NOGS, LEONIDA_RECT_NOCULL, LEONIDA_RECT_FORCE, LEONIDA_VTX_TEST and LEONIDA_DEBUG_CLEAR, with the
hard-coded test shader words. vulkan_replay.h returns unresolved_resource directly again.
- The descriptor write-through and the table mirror for title-backed heaps only copy between committed memory
they may read and write. A handle that is only a number (xs_proxy_mock's heaps) is left alone; the test
crashed there before.
- A slot 70 view over memory no buffer holds becomes a raw buffer view only when the title-memory registry
(title_va_alias.h) holds the whole range, instead of any address below 4 GiB. xs_proxy_mock's null-view case
passes again.
Still switches: LEONIDA_GRAPHICS_STAGE_LAYOUT, LEONIDA_DESC_MIRROR, LEONIDA_SLOT70_TITLE, LEONIDA_RECT_FOURTH.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
The stack is ladder-frame (ASTROWwwW's integration of the retail boot pull requests) with the old pull requests
7604, 7286, 7584, 6446, 8591, 7384, 7535, 7448, 9137 and 9419 and local fixes on top. main carries many of those
commits as ancestors without their content, so the merge was made against main's tree, not its history: nothing
main dropped is dropped again here.
Resolved by hand:
- d3d12_xs_device.cpp and frame_pacer.h: the stack's Xbox-ABI layer, plus main's uncapped pacer and its two new
registration hooks (set_placed_at_va_pages_hook is called before slot 133's handler; the console descriptor
heap handler is stored but slot 14 still uses the title-backed heaps of old PR 7021).
- xmem.cpp, xmem_test.cpp: the stack's run-mapped physical pages. main's commit-on-touch xmem with the two
view-protection fixes it lost (7e8e3c1db, 954fcb106) boots to 50,468 pipelines and then fails a submit with an
unknown resource, so it is not used here yet.
- acphal.cpp, acphal_test.cpp, vulkan_replay.h (acceleration structure copy), README: main's.
- CMakeLists.txt, build_runtime.ps1, d3d12_com.cpp, d3d12_vulkan_device.cpp, shader_library.h, docs: both sides.
Measured (Linux, Wine 11.21 staging, RTX 5070 Ti, driver 615.78.08, clang-cl 22.1.8 + xwin, own 1.0.2.1 copy,
network off, LEONIDA_GRAPHICS_STAGE_LAYOUT=1, 300 s): 50,470 pipeline states created, 197,998 ExecuteCommandLists
with none failed, 148,467 DrawInstanced, 99,008 PresentX.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
A retail title places a 256x256 R32_FLOAT texture through Xbox device slot 133
and then clears it through the value GetGPUVirtualAddress returns, used as a CPU
pointer. The layer answers 0 for a texture, as D3D12 does, so the title wrote
256 KB at address 0. XCL measured the same clear and returns the address the
title placed the resource at (its PR #168).
A slot-133 placed texture still gets its committed fallback image, but records
the title address and reports it from GetGPUVirtualAddress. Ordinary textures
still answer 0 and buffers are unchanged. The pixels do not alias the title's
pages yet, so a write through the address is not uploaded; that is the
page-mapper work and is called out in docs/d3d12_vulkan.md.
Tests: d3d12_existing_heap_test checks that the RENDER_TARGET layout and the
COMMON retry both answer the title address; it exits 0, and gta6rt links.
AI-assisted: DeepSeek V4.1 Flash 1017 (Alibaba Token Plan); coordinated by Qwen4 Max Preview.
3630610ca made the Xbox device proxy call
rt::d3d12::create_console_descriptor_heap directly, but d3d12_xs_device.cpp does
not include d3d12_com.h, so the tree does not compile: C3083 ('d3d12' is not
a namespace) and C2039 at d3d12_xs_device.cpp:1606. Including the header would
pull Vulkan types into xs_proxy_mock_test, which compiles the proxy standalone
and does not link the layer.
The proxy now has set_console_descriptor_heap_handler, the same shape as slot
133's placed-at-VA handler: a ConsoleDescriptorHeapHandler typedef and an atomic
in d3d12_xs_device.h/.cpp, registered by every Vulkan device in its constructor.
Heap creation moves into a Device member so the free helper only unwraps the
device and delegates. The new test gets its own reference from
create_device_proxy, reads the PC heap's CPU start through heap_proxy_real_heap()
instead of the Xbox-ABI proxy, and Ref gains operator->.
Tests: xs_proxy_mock_test and d3d12_console_descriptor_heap_test build and exit
0; gta6rt links.
AI-assisted: DeepSeek V4.1 Flash 1017 (Alibaba Token Plan); coordinated by Qwen4 Max Preview.
Reopened from #5275 (closed in the PR reset), rebased on current main.
Brings non-MSAA/non-volume SRV validation to parity with the MSAA/volume
checks: Shader4ComponentMapping (bit 12 and the four selectors) on every
texture and buffer SRV, negative or NaN ResourceMinLODClamp, typeless
resource/view formats outside depth/stencil, finite MipLevels/ArraySize
bounds on every dimension, and the TextureCubeArray NumCubes overflow.
An invalid view leaves the destination slot zeroed. Adds
d3d12_srv_validation_test.
Without VkPhysicalDeviceSamplerFilterMinmaxProperties::
filterMinmaxImageComponentMapping, a minimum/maximum reduction defines
only the R component of a sample; G, B and A are undefined. The AMD
Windows driver on Polaris (RX 580) reports singleComponentFormats = 1
and imageComponentMapping = 0, and returns exactly that: R is correct,
G/B/A vary.
The layer now records the property in VulkanDeviceInfo and logs once
when it creates a reduction sampler on a device without it. The
descriptor test compares R only on such devices, and all four channels
where the device maps every component.
Fixes four bugs in --f16-interp-fallback per-pipeline linking:
1. link_f16_halves() no longer skips patching on its fast path when static
VS/PS half locations exceed top_location or when an unused VS static half
collides with a raw PS input location.
2. Demoting an unused VS static half Output variable to Private now strips
all interface-only decorations (NoPerspective, Flat, Patch, Centroid,
Sample, Invariant, Location, Component), avoiding invalid SPIR-V.
3. keep_ps_locs now preserves raw PS input locations (ps_raw_locs) when
picking relocation slots.
4. CreateGraphicsPipelineState now runs link_f16_halves() when only VS
declares f16_halves and derives top_location from the physical device's
min(maxVertexOutputComponents, maxFragmentInputComponents) instead of
hardcoding 29.
Adds regression tests (cases 6-10) and interface-only decoration validation
in runtime/test/spirv_f16_halves_test.cpp.
AI-assisted (Antigravity).