Skip to content

d3d12: console rectangle lists and quad lists draw as triangles (rect list PSO topology type 19, list topologies 17 and 19), bit-exact on an RTX 4090 - #7448

Open
tedin7 wants to merge 2 commits into
ItsNotRexed:mainfrom
tedin7:fast-rectlist
Open

tedin7 wants to merge 2 commits into
ItsNotRexed:mainfrom
tedin7:fast-rectlist

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #7231 (comment)

@ItsNotRexed: an exe PR, as you asked.

What

The console's rectangle list (IASetPrimitiveTopology(17), PSO topology type 19) and quad list (IASetPrimitiveTopology(19)) are accepted and drawn as triangles, instead of refusing the PSO (type 19, E_INVALIDARG) or silently drawing a plain triangle list.

  • Rectangle list: three corners, the fourth is v2 + v3 - v1 for the position and every interpolant. A type-19 PSO becomes a triangle-list pipeline plus a small generated geometry stage (runtime/src/rect_list_geometry.h), written from the vertex shader's own SPIR-V outputs. It emits (v1, v2, v4) and (v1, v4, v3), so both triangles start at v1 and a flat input is v1's.
  • Quad list: one 4-vertex triangle fan per quad, which is the index pattern 0 1 2, 0 2 3. Each fan is drawn with the index values 4q..4q+3 (indexed draws read the application's index buffer; non-indexed draws read a shared 0, 1, 2, ... buffer in the arena's reserved pages, 16384 quads per draw, more is cut off with a log line).
  • PSO type 19 stays mapped to the triangle topology. Docs: docs/d3d12_vulkan.md, "Console rectangle and quad lists".

Why

Option choice: the fourth corner is a function of what the vertex stage wrote, not of what it read, and the translated vertex shaders fetch their vertices themselves through V# buffer loads (no vertex buffer to expand). So a CPU expansion or a compute pre-pass over the vertex data would be wrong for any non-linear shader. A geometry stage after the vertex stage is exact and needs only the geometryShader feature (else E_NOTIMPL). For quads, the translated vertex id is VertexIndex - BaseVertex, so splitting a draw by firstVertex would zero it; indexing with real values 4q..4q+3 keeps it right.
Credit for the facts: xvalkyrie backlog V8 (GPL-3.0, commit 53af7df77c10). No code was copied.

Tested

New d3d12_rect_list_test (translated vs_m15 + ps_m15, real FSSM lookup, 64x64 R32G32B32A32_FLOAT, read back), on pod p2 (NVIDIA GeForce RTX 4090, vulkaninfo driverName NVIDIA), Wine:

  • rectangle list, 3 corners with a colour interpolant: 4096 of 4096 pixels on the colour plane, worst error 0, and the four quadrant centres checked on their own (the bottom-right quadrant is only right when the fourth corner is).
  • quad list, two quads (top-left and bottom-right quadrants): 4096 of 4096 pixels bit-exact; the other two quadrants stay the clear colour.
  • Negative control: the same test on origin/main sources fails at the PSO ("primitive topology type not supported: 19", exit 1).
  • Regression on the branch: d3d12_translated_draw_test (4064/4096 + the 32 diagonal edge pixels, unchanged), d3d12_geometry_test, d3d12_draw_test, d3d12_depth24_draw_test all pass.
  • Not covered: the validation layer is not installed on the pod; an indexed quad list and a multi-instance quad list are not in the GPU test (several instances of a quad are drawn together, so overlapping blended instances rasterize quad by quad); a vertex shader that writes ClipDistance, CullDistance, Layer or ViewportIndex is refused for a rectangle list.

…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)
@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Code read of a6b31d5 (not run). The rectangle path checks out: v4 = v2 + v3 - v1, and both emitted triangles (v1 v2 v4) and (v1 v4 v3) keep (v1 v2 v3)'s winding (both cross products reduce to (v2-v1) x (v3-v1)) and start at v1 for flat inputs.

One point on quad lists (vulkan_replay.h, emit): every quad is its own vkCmdDrawIndexed (for (quad ...) draw_indexed(4, ...)), so a list of N quads records N draws, which gets costly for particle or UI batches of thousands. For the non-indexed case there's a cheap alternative: fill the reserved buffer with the triangle-list pattern 4q, 4q+1, 4q+2, 4q, 4q+2, 4q+3 instead of 0, 1, 2, ... and draw all quads in one vkCmdDrawIndexed(6 * quads, instances, 0, first, first_instance). The index values (and so the translated vertex id) are the same 4q+k, the first vertex of each triangle is still v0 for flat inputs, instance order becomes the API's again, and it needs no VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN (triangleFans is optional under VK_KHR_portability_subset, e.g. MoltenVK, which matters if the macOS host in #7446 lands). Same reserved size gives 65536 / 6 quads instead of / 4, or grow it. The indexed case still needs the per-quad fans, or an index expansion pass.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants