Skip to content

TEST-728: world props through the deferred material shaders into the G-buffer - #4119

Open
Joaovitor404silva wants to merge 2 commits into
ItsNotRexed:mainfrom
Joaovitor404silva:gbuffer-props
Open

Joaovitor404silva wants to merge 2 commits into
ItsNotRexed:mainfrom
Joaovitor404silva:gbuffer-props

Conversation

@Joaovitor404silva

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-728

Depends on: #3530 (this branch carries #3530's commit rebased on today's main; review only the last commit)

What and why

This draws the placed world props of #3530 through a translated deferred material pair. The vertex shader pulls
its own vertices (SV_VertexID only) and the pixel shader writes the five G-buffer targets of
gbuffer.md (PROC-146). Every target is then read back and checked. There is no lighting or
shadow pass yet.

  • tools/gbuffer.py picks the pair by user-data layout and listing, never by name. The translator numbers VS
    outputs by param and PS inputs by attribute, while the game links them by semantic. So the script computes the
    link from the two DXBC signatures and passes it on.
  • runtime/test/vk_gbuffer repacks each mesh into the game's compressed vertex stream and fills the tables the
    pair reads: frame, object, view, viewport, index and T#/S#. It draws into mrt0–4 + D32 and reads every target
    back. It prints counts only: covered, shaded, albedo colours, normals facing the camera, still motion vectors.
  • docs/gbuffer_sandbox.md records the tables, the vertex stream layout and the targets. One finding there: the
    three position fields hold model z, y, x, in that order.
  • runtime/test/sandbox_common.h holds the scene loader and camera code moved out of vk_sandbox.cpp.
    vk_sandbox behaves the same.

Tested

NVIDIA GeForce RTX 4070 Ti SUPER, driver 621.24, Windows 11, one retail Xbox Series install (1.0.2.1).

  • python -I tests/test_gbuffer_pick.py: 11 tests OK, on hand-made listings and DXBC signatures. Also run:
    tests/test_sandbox_pick.py and tests/test_sandbox_scene.py OK, python -m compileall -q tools tests.
  • cmake --build runtime/build --target vk_sandbox vk_gbuffer: no warnings.
  • Corpus: 360 VS and 112 PS have the user-data layout, 14 VS and 8 PS also match the listing, and 24 pairs link.
  • tools/gbuffer.py on the TEST-520: real-shader sandbox, placed props through a translated VS/PS pair #3530 test scene (150 props, 446 draws, 442 textured), 640×360: PASS. 114,503
    pixels covered, the same as tools/sandbox.py --check at that camera. 114,503 shaded, 7,325 albedo colours,
    98,778 normals facing the camera, 114,503 still motion vectors (largest 0.003 px).
  • A synthetic cube: each face decodes to its own rotated normal, and the near faces win the depth test.
  • It needs shaders translated after today's 16-bit interpolant fix. An older translation drops
    normals_facing to a few percent of covered.

AI-assisted (Claude Code). A separate code review pass found 8 low-severity issues, all fixed here.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01PiKMETzszqwfnV8QQyzocY

Joaovitor404silva and others added 2 commits November 22, 2026 20:27
vk_sandbox draws the props around a point with one translated game VS/PS
pair chosen by signature and descriptor layout: a real camera through the
VS constants, DiffuseTex albedo through the bindless set and the PS's own
S#, depth, and a fly/walk/drive window. tools/sandbox.py packs the scene
(tools/sandbox_scene.py), picks the pair and runs it; --check prints
counts only. docs/sandbox.md has the table layout and the measurements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PiKMETzszqwfnV8QQyzocY
…G-buffer

tools/gbuffer.py picks a material VS/PS pair by user data and listing
layout. The VS pulls its own vertices and the PS writes the five G-buffer
targets. The script links the pair's interpolants by DXBC semantic and
runs runtime/test/vk_gbuffer. That tool repacks the scene into the
game's compressed vertex stream, fills the tables the pair reads, draws
into mrt0-4 + D32 and reads every target back. It prints counts and
PASS/FAIL only.

The scene and camera helpers move from vk_sandbox.cpp to
sandbox_common.h. docs/gbuffer.md records the tables, the stream and the
target layout. tests/test_gbuffer_pick.py covers picking, linking and
the thresholds on hand-made inputs.

Depends on: ItsNotRexed#3530

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PiKMETzszqwfnV8QQyzocY

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted Windows review at 9d9012261f97864951effcb6fc2b0e0b6945f88f. The 23 synthetic picker and scene tests passed with uv CPython 3.12.13. A separate reordered-signature fixture selected [5, 1, 0] and rejected a candidate with a mismatched TEXCOORD index. MSVC 19.38 built and linked both targets on head and vk_sandbox on parent 5a9a8a81. These checks used CPU only.

The still-motion oracle can pass when mrt4 retains its clear value. The render pass clears it to zero, and covered pixels with zero motion count as still. Clearing both motion components to 1.0 would make untouched pixels fail the 0.1 px threshold while preserving valid still pixels. The same readback block copies back mrt3, whose bytes only feed --dump. Please scope the statement that every target is checked to the actual assertions, or add an mrt3 check before using it for lighting.

@tupacfan04

Copy link
Copy Markdown
Contributor

The test itself is sound, but it makes a repo test fail on Windows CI.

Verified on Windows 11 / Python 3.13.0 without a GPU: compileall clean, test_gbuffer_pick 11 OK, test_sandbox_pick 6 OK, test_sandbox_scene 6 OK, and the other docs tests pass. tests/test_docs_repo_paths.py fails (2 of 2 runs): docs/gbuffer_sandbox.md:11 and docs/sandbox.md:11 backtick runtime/test/vk_gbuffer / runtime/test/vk_sandbox, but only the .cpp files are tracked, so :74 rejects them - and the check job runs that test (ci.yml:85). Add .cpp or reword.

The rest checks out: the negative control works (forcing check_counts's normals_facing true fails test_gbuffer_pick), the GPU path skips loudly (vk_gbuffer.cpp:164 returns 77, tools/gbuffer.py:187,201,207), no renderer assertion it cannot see (vk_gbuffer.cpp:520-554 prints counts only, pass/fail stays in check_counts), and the formats match docs/gbuffer.md:36-40 and docs/gbuffer_sandbox.md:66.

Minor: runtime/CMakeLists.txt:851 only builds vk_gbuffer, with no add_test/SKIP_RETURN_CODE 77, so ctest never exercises the skip path.

AI-assisted review, no game files, no GPU.

@jeremygold02 jeremygold02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the 256-color albedo requirement specific to a known reference scene. The CLI accepts arbitrary placed props, and a correctly sampled solid texture currently makes it return FAIL.

I built the unmodified Windows vk_gbuffer from 9d9012261f97864951effcb6fc2b0e0b6945f88f. A synthetic full-screen triangle used an integer texel fetch from the bound 16×16 RGBA8 image. I compared the albedo PPM with the input RGB byte for byte and passed the harness's printed counts through the PR's parse_counts and check_counts(..., True), as the CLI does for a textured draw.

Texture Covered Exact albedo pixels Shaded / normals facing / still motion Distinct albedo colors Checker
16×16 color ramp 256 256 256 / 256 / 256 256 PASS
Solid RGB (27, 87, 109) 256 256 256 / 256 / 256 1 FAIL

The texture bytes were the only change between those two draws. One way to keep the useful regression check is to retain the color-count assertion for the reference scene and report color diversity as a measurement for arbitrary inputs.

I found a separate pairing issue in tools/gbuffer.py. Starting with the PR's PickPair fixture, I kept the PS TEXCOORD0 declared and read in XY. The picker returned the same link [0, 1, 3] for three VS cases, including the matching XY control, XY with Y marked never written, and X alone. The latter two can select a producer that cannot supply the required Y coordinate. Please retain the declared component mask (signature byte 24) alongside the usage mask (byte 25) and reject a candidate when a component the PS always reads is unavailable from the VS. These were picker tests with synthetic signatures.

I also measured the MRT3 question raised in the earlier review. In a third draw I changed only that target's synthetic output from red to zero. All 256 MRT3 RGB pixels changed, the albedo, normal and MRT2 dumps stayed byte-identical, and both runs had identical counts and passed. The readback distinguishes the two outputs.

NVIDIA GeForce RTX 5070, driver 621.01, Intel Core Ultra 7 265K, Windows 11 Home 25H2 build 26200.9974, Python 3.12.10. All 23 picker and scene tests passed. These draws measure the native harness and its verdict using hand-written SPIR-V and synthetic inputs. The authored shader-pair selection and the 150-prop scene were outside this GPU check.

AI-assisted by Codex.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test exercises depth writes and reads them back, so the render-pass dependency must cover every stage Vulkan may use for those writes.

VkSubpassDescription sd{}; sd.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
sd.colorAttachmentCount = NT; sd.pColorAttachments = car; sd.pDepthStencilAttachment = &dar;
VkSubpassDependency dep{0, VK_SUBPASS_EXTERNAL,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Include early fragment tests in the depth-write dependency. This pipeline enables both depth testing and depth writes, but the external dependency names only LATE_FRAGMENT_TESTS. Vulkan permits depth/stencil writes in either EARLY_FRAGMENT_TESTS or LATE_FRAGMENT_TESTS; the later vkCmdCopyImageToBuffer readback therefore is not ordered against early writes on an implementation that performs them there. Include both stages in srcStageMask (Khronos recommends both when the stage is uncertain: depth synchronization guidance).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 9d901226 on Windows 11:

  • pytest tests/test_gbuffer_pick.py tests/test_sandbox_pick.py tests/test_sandbox_scene.py -q -> 23 passed.
  • compileall (gbuffer/sandbox/sandbox_scene) and git diff --check clean.
  • vk_gbuffer builds cleanly against Vulkan 1.4.363 headers.

The new Python coverage is the shader-pair selection (VS with only SV_VertexID, the PS's five MRT exports and its T#/S# slots), the scene packing, and the --link derivation. I could not run the GPU end of it: tools/gbuffer.py needs the user's entity/model/texture carve and a translated pair, neither of which is in this checkout, and the test itself exits 77 when they are missing. The CPU side and the vk_gbuffer build are verified. No blocking issue.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 9d901226 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: builds, and changes nothing else.

  • tests/test_gbuffer_pick.py, test_sandbox_pick.py, test_sandbox_scene.py: 23 passed.
  • ctest: 144 passed, 10 skipped, 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main aa2988cc.
  • vk_gbuffer / vk_sandbox were not run against package data, so this does not confirm the G-buffer output.

AI-assisted (Claude Code).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 9d90122 merged onto main d0835dd on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 154/155.
  • Failed only in the parallel run: xdxr_build_check (passed when rerun on its own).
  • Warnings: none new in the files this PR changes.

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.

8 participants