Skip to content

OLD-9940: draw Xbox rectangle and indexed quad lists as triangles - #682

Merged
aslan2142 merged 13 commits into
mainfrom
qemmhd/old-9940-rectangle-quad-lists
Nov 25, 2026
Merged

aslan2142 merged 13 commits into
mainfrom
qemmhd/old-9940-rectangle-quad-lists

Conversation

@QemmHD

@QemmHD QemmHD commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Claimed in #14 as OLD-9940. Follow-up to #207. This branch carries tedin7's six original patches onto current main and keeps their authorship.

What and why

The Xbox rectangle-list pipeline uses topology type 19. The Vulkan backend currently rejects it. This adds the rectangle geometry stage and draws quad lists as triangles.

The first indexed quad implementation used a triangle fan per quad. That picks the wrong vertex for flat attributes and changes draw order when instances overlap. This branch expands indices on the GPU and issues a single instanced triangle-list draw. Flat attributes come from the quad's first vertex and instance order is preserved.

Shader-addressable standalone buffers now round their Vulkan backing size to a four-byte word for 16-bit index loads. D3D resource sizes and index-view bounds stay the same.

Tested

  • Windows 11 x64, MSVC 14.44 RelWithDebInfo, RTX 4070 SUPER, NVIDIA 621.24, on main 21625bca8.
  • d3d12_rect_list, d3d12_quad_index, replay_quad_list, vulkan_scratch, and d3d12_xmem_placed: 5/5 passed.
  • GPU-assisted Vulkan validation: all seven quad frames matched all 4,096 pixels, including the standalone 16-bit upload index case. No validation errors were reported in that run.
  • The prepared-draw bounds guard passes the unchanged replay_query_predication fixture and the replay and GPU quad tests. GPU validation remained clean.
  • Repository game-data scan, git diff --check, and local merge check passed.

Live game coverage for this branch is pending. AI-assisted: yes (Claude Code and Codex).

tedin7 and others added 12 commits November 24, 2026 05:10
…lists (19) as triangles

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.
…ty Geometry, log cut-off quads (review fixes)
…at inputs use the first quad vertex, and the PSO topology type is read as raw bits

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 a6b31d5 and passes with it). Re-run here: replay_quad_list_test and d3d12_rect_list_test exit 0 on the pod (Wine, RTX 4090).
…e told apart from float outputs on the vertex side (comment only)
…ngle (the vertex opposite the longest screen edge) instead of assuming the first; tests for the corner at the second and third vertex and for a non-right triangle
…s drawn; geometry notes edges are measured in NDC
…from size_t (C4267)

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
…destination

ScratchBuffers creates every chunk as a transfer source and destination, which is all the
staged copies need. Its owner can now add usage flags: the expanded indices of indexed quad
lists (next commit) live in the same scratch, as an index buffer that a compute pass writes
through its device address. The default is unchanged.

vulkan_scratch_test checks the usage a chunk is created with, with and without the flags.

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
…xpands on the GPU (OLD-9940)

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
…ex, flat inputs, overlapping instances (d3d12_quad_index)

d3d12_rect_list draws its quads without an index buffer, so it could not see what #207's
review measured on indexed ones. d3d12_quad_index_test draws six 64x64 frames through
DrawIndexedInstanced with IASetPrimitiveTopology(19) and compares every pixel bit for bit:

  0  non-indexed control
  1  16-bit indices, a quad whose corners all differ: the first vertex's colour everywhere
  2  32-bit indices from StartIndexLocation 3
  3  16-bit indices from StartIndexLocation 5 (an address of 2 modulo 4), BaseVertexLocation 3
  4  two quads and two instances whose quads overlap: the later instance on top
  5  a view that ends inside the second quad: its last two indices read 0

The index buffer is in a DEFAULT heap and filled by a copy in the first list, so only the
GPU can read it. Two translated fixtures, like vs_m15 and ps_m15: vs_quad_inst.asm reads
the instance id (v3) to move and recolour each later instance, ps_quad_flat.asm reads its
colour with v_interp_mov, which makes the input Flat.

RTX 4070 SUPER (621.24), Windows 11, LEONIDA_VK_VALIDATION=1:
  on the six commits of #207: frames 1, 2, 3 and 5 match in 0 of 4096 pixels (black and
  blue, the second and third vertex), frame 4 in 2048, frame 0 in 4096; exit 1
  with the expansion: 4096 of 4096 in all six, 0 validation errors

run_gpu_tests.py lists the two fixtures as run by this test, and docs/testing.md names the
test (and d3d12_rect_list) among those that need llvm-mc and the SPIR-V tools.

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
…e index expansion

The quad list entry of "Console rectangle and quad lists" described the fan per quad and
its two faults. It now describes both paths as one triangle-list draw, the compute pass
for indexed draws and where it runs, what it does with the base vertex, the strip-cut
values and indices past the view, what it needs, the measurement that replaced the fans,
and what is still not covered (ExecuteIndirect draws, which record no topology).

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
@towade

towade commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@QemmHD, a heads-up for when this meets #511 (LEONIDA_LAZY_PSO): the two merge without a textual conflict, but in the merged d3d12_vulkan_device.cpp, #511's stage.words = {}; (end of the stage loop) runs before this PR's if (rect_list) block. That block calls leonida::rect_list_geometry(vs_stage.words, why), so it would get empty words. The clear is outside #511's lazy branch, so this happens with LEONIDA_LAZY_PSO unset too, and every rectangle-list PSO would return E_NOTIMPL ("cannot be drawn as a rectangle list").

Building the rectangle-list stage before the clear, or keeping the vertex stage's words until after it, would avoid it. The same word-lifetime problem was found for #207 on #511.

Found by reading the merged source (git merge-tree of both heads, 6aa8eb11c and 88658f1b3). I have not built or run the combination yet.

AI-assisted (Claude Code).

@Dezmonius

Copy link
Copy Markdown
Contributor

Native Windows follow-up to the #511 integration warning. I applied the #511 diff at 88658f1b to #682 at 6aa8eb11. Windows 10 22H2, RTX 5070 / NVIDIA 610.88, MSVC 19.51.36256, Khronos Vulkan validation 1.4.369.

  • Plain combination: with LEONIDA_LAZY_PSO=0 and =1, d3d12_rect_list failed on the same message: the vertex shader is not a SPIR-V module. Indexed quad and replay tests passed in both modes.
  • Local ordering-only control: retained vs_stage.words when rect_list is set and released it immediately after rect_list_geometry. Both modes passed all three tests with validation enabled. The three rectangle colour-plane cases matched 4,096/4,096 pixels each, and all seven indexed-quad frames matched 4,096/4,096 pixels each.

This checks the combined revisions with synthetic fixtures only. No game files or retail boot. AI-assisted (Codex).

@aslan2142
aslan2142 merged commit be767b6 into main Nov 25, 2026
8 of 13 checks passed
aslan2142 pushed a commit that referenced this pull request Nov 25, 2026
Carry only runtime/src/rect_list_geometry.h, byte-for-byte from 6aa8eb1. The stage generator and its original commits are by tedin7 (#207, carried forward in #682). This makes the draw-time change buildable against main while the explicit rectangle/quad work is in review.
aslan2142 pushed a commit that referenced this pull request Nov 25, 2026
…first-run UI

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.
aslan2142 pushed a commit that referenced this pull request Nov 25, 2026
…published renderer fixes

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants