d3d12: console rectangle lists and quad lists draw as triangles (PSO topology type 19; retail boot CreatePipelineState 50,470 of 50,470) #7

Open
tedin9 wants to merge 5 commits from tedin9/leonida:rect-list-geometry into main
Contributor

Upstream GitHub PR: ItsNotRexed/Leonida#7448 (same change, rebased onto forge/main).

What

The console's rectangle-list topology (PSO topology type 19, IASetPrimitiveTopology(17)) and quad-list topology (IASetPrimitiveTopology(19)) draw as triangles on Vulkan. A generated geometry stage adds each rectangle's fourth corner (v2 + v3 - v1, for the position and every interpolant); non-indexed quad lists draw from a shared triangle-list index buffer (0 1 2) (0 2 3) so flat inputs use the first quad vertex. The PSO topology type is read as raw bits, so the console's out-of-range value 19 survives strict-enum optimisation. The quad-list batching and the raw-bit read come from a follow-up patch by @matheuskshn (GitHub 930e78a2).

Why

Without it CreatePipelineState refuses the type-19 pipelines of the retail boot ("primitive topology type not supported: 19").

Evidence

  • Retail boot by @lunarminus (his own 1.0.2.1 copy, Wine 11.22, Radeon 760M, RADV): CreatePipelineState 4 failed / 50,466 ok before, 50,470 ok, 0 failed with this change.
  • Independent native runs on the GitHub PR: RX 9060 XT (validation on, 0 errors), RTX 4070 Ti, RTX 3060, plus Wine runs on RTX 5080 and a Ryzen iGPU; d3d12_rect_list 4096/4096 pixels, quad list exact.
  • Re-run on this branch (forge/main 097e9f46e, runtime built fresh on RunPod, Wine 11, RTX 4090): replay_quad_list_test exit 0, d3d12_rect_list_test exit 0 ("rect list: 4096 of 4096 pixels on the colour plane (worst error 0), all four quadrants; quad list: 4096 of 4096 pixels exact"). Negative control (production files reverted) fails d3d12_rect_list at line 141 on the GitHub PR.

Known limit

The fourth corner is computed with float add/sub on every vec4 float vertex output. An attribute the translator exports as two packed f16 halves would get a wrong corner; nothing on the vertex side tells them apart (recorded in a comment at rect_list_geometry.h).

Not verified

Native Windows on this exact branch, and the draws' pixel output on the title (frames stay black for other reasons, see slot 133).

AI-assisted.

Upstream GitHub PR: ItsNotRexed/Leonida#7448 (same change, rebased onto forge/main). ## What The console's rectangle-list topology (PSO topology type 19, `IASetPrimitiveTopology(17)`) and quad-list topology (`IASetPrimitiveTopology(19)`) draw as triangles on Vulkan. A generated geometry stage adds each rectangle's fourth corner (v2 + v3 - v1, for the position and every interpolant); non-indexed quad lists draw from a shared triangle-list index buffer `(0 1 2) (0 2 3)` so flat inputs use the first quad vertex. The PSO topology type is read as raw bits, so the console's out-of-range value 19 survives strict-enum optimisation. The quad-list batching and the raw-bit read come from a follow-up patch by @matheuskshn (GitHub 930e78a2). ## Why Without it `CreatePipelineState` refuses the type-19 pipelines of the retail boot ("primitive topology type not supported: 19"). ## Evidence - Retail boot by @lunarminus (his own 1.0.2.1 copy, Wine 11.22, Radeon 760M, RADV): `CreatePipelineState` 4 failed / 50,466 ok before, **50,470 ok, 0 failed** with this change. - Independent native runs on the GitHub PR: RX 9060 XT (validation on, 0 errors), RTX 4070 Ti, RTX 3060, plus Wine runs on RTX 5080 and a Ryzen iGPU; `d3d12_rect_list` 4096/4096 pixels, quad list exact. - Re-run on this branch (forge/main 097e9f46e, runtime built fresh on RunPod, Wine 11, RTX 4090): `replay_quad_list_test` exit 0, `d3d12_rect_list_test` exit 0 ("rect list: 4096 of 4096 pixels on the colour plane (worst error 0), all four quadrants; quad list: 4096 of 4096 pixels exact"). Negative control (production files reverted) fails `d3d12_rect_list` at line 141 on the GitHub PR. ## Known limit The fourth corner is computed with float add/sub on every vec4 float vertex output. An attribute the translator exports as two packed f16 halves would get a wrong corner; nothing on the vertex side tells them apart (recorded in a comment at `rect_list_geometry.h`). ## Not verified Native Windows on this exact branch, and the draws' pixel output on the title (frames stay black for other reasons, see slot 133). AI-assisted.
d3d12: console rectangle lists and quad lists draw as triangles (PSO topology type 19 read as raw bits, quad lists as (0 1 2) (0 2 3))
Some checks failed
CI / translator-tests (pull_request) Has been cancelled
CI / semantic-tests (pull_request) Has been cancelled
CI / viewer-tests (pull_request) Has been cancelled
CI / stdlib-tests-linux (pull_request) Has been cancelled
No Game Data / no-game-data (pull_request) Has been cancelled
Runtime / linux-gpu-tools (pull_request) Has been cancelled
c28b207945
enx requested changes 2026-11-23 20:42:56 +00:00
enx left a comment

Lowering checks out (replay_quad_list passes, generated stage passes spirv-val). Changes requested:

  1. docs/d3d12_vulkan.md "Console rectangle and quad lists": the fourth-corner rule, "a quad is four vertices" and the (0 1 2)(0 2 3) split come from xvalkyrie, not measured here; label them as a hypothesis. Only the RTX 4090 4096/4096 result is measured.
  2. Same section says the stage emits the strip v1 v2 v3 v4; the code emits two triangles (v1,v2,v4) and (v1,v4,v3). Fix the doc.
  3. Comments: rect_list_geometry.h (header and inline blocks), vulkan_replay.h emit() and d3d12_vulkan_device.cpp have multi-line comments; one short line each.
  4. vulkan_replay.h emit() quad branch: non-indexed lists over 16384 quads are silently truncated with a stderr line per emit; rate-limit it or return an error.
  5. Document that packed-f16 vertex outputs get a wrong fourth corner, and that Component and PointSize are dropped.
Lowering checks out (replay_quad_list passes, generated stage passes spirv-val). Changes requested: 1. docs/d3d12_vulkan.md "Console rectangle and quad lists": the fourth-corner rule, "a quad is four vertices" and the (0 1 2)(0 2 3) split come from xvalkyrie, not measured here; label them as a hypothesis. Only the RTX 4090 4096/4096 result is measured. 2. Same section says the stage emits the strip v1 v2 v3 v4; the code emits two triangles (v1,v2,v4) and (v1,v4,v3). Fix the doc. 3. Comments: rect_list_geometry.h (header and inline blocks), vulkan_replay.h emit() and d3d12_vulkan_device.cpp have multi-line comments; one short line each. 4. vulkan_replay.h emit() quad branch: non-indexed lists over 16384 quads are silently truncated with a stderr line per emit; rate-limit it or return an error. 5. Document that packed-f16 vertex outputs get a wrong fourth corner, and that Component and PointSize are dropped.
d3d12: the rectangle-list geometry module is acquired through the shader module cache, so modules_ releases it (it was a direct vkCreateShaderModule handle the cache does not own)
Some checks failed
CI / translator-tests (pull_request) Has been cancelled
CI / semantic-tests (pull_request) Has been cancelled
CI / viewer-tests (pull_request) Has been cancelled
CI / stdlib-tests-linux (pull_request) Has been cancelled
No Game Data / no-game-data (pull_request) Has been cancelled
Runtime / linux-gpu-tools (pull_request) Has been cancelled
5e2b951457
Author
Contributor

Forge integration finding applied (thanks akimfomin): the rectangle geometry module is now created with device_.shader_modules().acquire(words) instead of a direct vkCreateShaderModule, so modules_ releases it through ShaderModuleCache like the other stages. Pushed 5e2b95145 on rect-list-geometry, after merging current forge/main (b5163905e, which has the cache) into the branch; the merge was clean.

Evidence: I did not add a test. shader_module_cache_test covers the cache with fake create/destroy functions; the leak was in the device code's choice of creation call, which needs a real Vulkan device to observe, and akimfomin's Windows A/B (two PSOs sharing one module, zero left after release) is the measurement for it. I did not re-run it here.

AI-assisted.

Forge integration finding applied (thanks akimfomin): the rectangle geometry module is now created with device_.shader_modules().acquire(words) instead of a direct vkCreateShaderModule, so modules_ releases it through ShaderModuleCache like the other stages. Pushed 5e2b95145 on rect-list-geometry, after merging current forge/main (b5163905e, which has the cache) into the branch; the merge was clean. Evidence: I did not add a test. shader_module_cache_test covers the cache with fake create/destroy functions; the leak was in the device code's choice of creation call, which needs a real Vulkan device to observe, and akimfomin's Windows A/B (two PSOs sharing one module, zero left after release) is the measurement for it. I did not re-run it here. AI-assisted.
d3d12: rect list test: every pixel well inside a non-right triangle is drawn; geometry notes edges are measured in NDC
Some checks are pending
CI / translator-tests (pull_request) Waiting to run
CI / semantic-tests (pull_request) Waiting to run
CI / viewer-tests (pull_request) Waiting to run
CI / stdlib-tests-linux (pull_request) Waiting to run
No Game Data / no-game-data (pull_request) Waiting to run
Runtime / linux-gpu-tools (pull_request) Waiting to run
3b4c3b8ff6
Author
Contributor

Etr0p's finding applied (thanks): the stage no longer assumes the right angle is at the first vertex. It takes the vertex opposite the longest edge in screen space (position.xy / position.w; the first vertex on a tie) as p, its two neighbours a and b in the drawn order (same winding), and the fourth corner a + b - p for the position and every interpolant. OpSelect on squared edge lengths, no new capabilities, no branches.

Tested on an RTX 4090 pod (Wine, cross-built), d3d12_rect_list_test:

  • unchanged case (right angle at the first vertex): 4096/4096 pixels on the colour plane, worst error 0; quad list 4096/4096 exact
  • new: right angle at the second vertex 4096/4096, at the third 4096/4096 (worst error 6e-8)
  • new: a triangle with no right angle: every pixel well inside it is drawn (the old and new corner both give a parallelogram that holds it); 2156 pixels drawn in total
  • negative control, same test with the previous rect_list_geometry.h: exit 1, "right angle at the second vertex: 2080 of 4096 pixels on the plane" (about half, as Etr0p measured on the retail boot)
  • replay_quad_list_test passes. The validation layer is not installed on that pod, so I did not run LEONIDA_VK_VALIDATION=1 for this change.

Known limit, noted in the header: edges are measured in NDC, so a rotated rectangle in a very non-square viewport can pick a different corner than the pixel-space right angle. Flat inputs now come from p, which changes with the corner. I did not re-measure on the retail boot.

AI-assisted.

Etr0p's finding applied (thanks): the stage no longer assumes the right angle is at the first vertex. It takes the vertex opposite the longest edge in screen space (position.xy / position.w; the first vertex on a tie) as p, its two neighbours a and b in the drawn order (same winding), and the fourth corner a + b - p for the position and every interpolant. OpSelect on squared edge lengths, no new capabilities, no branches. Tested on an RTX 4090 pod (Wine, cross-built), d3d12_rect_list_test: - unchanged case (right angle at the first vertex): 4096/4096 pixels on the colour plane, worst error 0; quad list 4096/4096 exact - new: right angle at the second vertex 4096/4096, at the third 4096/4096 (worst error 6e-8) - new: a triangle with no right angle: every pixel well inside it is drawn (the old and new corner both give a parallelogram that holds it); 2156 pixels drawn in total - negative control, same test with the previous rect_list_geometry.h: exit 1, "right angle at the second vertex: 2080 of 4096 pixels on the plane" (about half, as Etr0p measured on the retail boot) - replay_quad_list_test passes. The validation layer is not installed on that pod, so I did not run LEONIDA_VK_VALIDATION=1 for this change. Known limit, noted in the header: edges are measured in NDC, so a rotated rectangle in a very non-square viewport can pick a different corner than the pixel-space right angle. Flat inputs now come from p, which changes with the corner. I did not re-measure on the retail boot. AI-assisted.
Some checks are pending
CI / translator-tests (pull_request) Waiting to run
CI / semantic-tests (pull_request) Waiting to run
CI / viewer-tests (pull_request) Waiting to run
CI / stdlib-tests-linux (pull_request) Waiting to run
No Game Data / no-game-data (pull_request) Waiting to run
Runtime / linux-gpu-tools (pull_request) Waiting to run
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'rect-list-geometry:tedin9-rect-list-geometry'
git switch 'tedin9-rect-list-geometry'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'tedin9-rect-list-geometry'
git switch 'tedin9-rect-list-geometry'
git rebase 'main'
git switch 'main'
git merge --ff-only 'tedin9-rect-list-geometry'
git switch 'tedin9-rect-list-geometry'
git rebase 'main'
git switch 'main'
git merge --no-ff 'tedin9-rect-list-geometry'
git switch 'main'
git merge --squash 'tedin9-rect-list-geometry'
git switch 'main'
git merge --ff-only 'tedin9-rect-list-geometry'
git switch 'main'
git merge 'tedin9-rect-list-geometry'
git push origin 'main'
Sign in to join this conversation.
No reviewers
enx
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
enx/leonida!7
No description provided.