Repository navigation
Conversation
|
Pushed d168476: mesh_vs now writes the barycentrics stand-ins itself. On the mesh-as-compute path (#2580) the pixel shader behind a mesh program still read
MEASURED on the 1050 Ti:
NOT measured: the visual difference in game (no side-by-side capture yet). AI-assisted (Claude Code). |
lixonik
left a comment
There was a problem hiding this comment.
Reviewed d16847611 (including #2580) merged locally with main 1bc055e6c. All 19 barycentric tests passed in profile diag on Windows 10 22H2, RTX 5070 (610.88), with DXIL validator 1.9.2609 and Agility SDK 1.614.1. The unit-test executable used local Agility exports so the GPU checks actually reached SM 6.6. Hardware readbacks matched native barycentrics; WARP did not run on this host.
I also reran the draw fixture with clip W values of 0.5, 1, and 2, scaling clip XYZ per vertex to keep the same screen-space triangle. The fallback and native path still matched all 64 pixels for each of the seven synthetic programs, at the fixture's 1e-4 tolerance. Unequal W is a useful permanent test case because the existing W=1 triangle cannot distinguish linear from perspective-correct interpolation. The mesh fallback check here validates the generated stage and matching signatures.
AI-assisted.
Windows 11 + RTX 3090 D3D12 & WARP Verification (
|
…ers (D3D12-MESH-COMPUTE-FALLBACK) set_host_mesh_shaders(false) lowers a mesh program as cs_6_6. setMeshOutputCounts goes. emitIndices, storeVertexOutput and storePrimitiveOutput become raw stores into the root UAV SLOT_MESH_OUT (251), in the group's MeshOut slot: max_vertices vertices, then max_primitives primitives (three indices, then the per-primitive outputs). - The buffer is MESH_OUT_BYTES (64 MiB). A 256-byte header holds a draw's arguments: lane 0 of each group raises its instance count to the group id + 1, so an indirect dispatch's draw needs no CPU read. - Groups past MeshOut::groups_cap write to one sink slot after the last. - mesh_vs() builds the pass-through vertex shader that draws it. SV_VertexID gives primitive and corner, SV_InstanceID the group. It reads the root SRV SLOT_MESH_IN (250) and outputs the program's vertex outputs register for register, plus the per-primitive outputs where the pixel shader reads them, constant. A group past the cap draws a triangle of no area. - HostShader carries the layout and the signatures, and the shader cache encodes them. host_settings() has a word for it, so a translation for one kind of host never serves the other. Tests: the triangle mesh fixture translates as compute (layout, root UAV, empty output signature; dxil.dll takes it for plain, edge-flagged and culled primitives) and stays a mesh shader with mesh shaders. Its vertex shader validates. On a device, the program run as compute and drawn lights the texels the mesh pipeline lights, compared texel for texel where the device has mesh shaders. The test harness gets a root UAV for dispatches, root SRVs in draws and a vertex count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t mesh shaders At device creation the translator is told whether the host has mesh shaders at shader model 6.6 (LEONIDA_MESH_COMPUTE=1 takes the fallback on any card). Without them, a mesh pipeline is made as two: - the mesh program as a compute pipeline; - the pass-through vertex shader with the title's pixel shader and state, drawing triangle lists with no vertex input. The draw path: - A mesh dispatch binds the compute pipeline with the title's graphics root arguments (roots_ref reads them while title_side_graphics is set). - It dispatches and draws 3 * max_primitives vertices, one instance a group. - An indirect one writes the header's draw arguments (WriteBufferImmediate), runs the title's record with a dispatch signature, and draws from the header with ExecuteIndirect. - The buffer goes common -> UAV -> shader resource and indirect argument -> common. shortcut: an indirect call of several records is left out (each would fill the same slots). MEASURED on a GTX 1050 Ti (Pascal: mesh shader tier 0), Windows 10 with ProjectLeonida#2557: the title gets past its start screen through the opening cutscenes into the first playable scene. Without this, every mesh pipeline was refused and the world drew nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d168476 to
c2f4cd3
Compare
|
Rebased onto
MEASURED on a GTX 1050 Ti (582.66), Windows 10, with Agility 1.614.1 for the test binary:
Thanks @lixonik, @zmasi and @merzleckeier for the runs. AI-assisted (Claude Code). |
timbot103
left a comment
There was a problem hiding this comment.
Static audit of c2f4cd3 against 48bae6c. The patch applies cleanly in check mode. Please address these before merge.
d3d12/crates/leonida-shader/src/emit/bary_gs.rs:79reassigns a packed flat float and integer different interpolation modes in the same row. Preserve the VS output modes from PSV0.d3d12/crates/leonida-gpu/src/pipeline/host.rs:658can keep native mesh while forced barycentrics lowering makes the PS require stand-ins. Route this pairing through a path that emits those inputs.d3d12/crates/leonida-gpu/src/pipeline/host.rs:963removes the rectangle GS, which drops indexed rectangles. Combine rectangle completion and barycentrics in one GS.d3d12/crates/leonida-gpu/src/draw.rs:4707andd3d12/crates/leonida-gpu/src/draw.rs:4782leave IA topology set to triangle list. Restore it before the next conventional draw.d3d12/crates/leonida-shader/src/emit/bary_gs.rs:186emits only a triangle-input GS, which is incompatible with triangle adjacency draws. Select an adjacency variant at draw time.d3d12/crates/leonida-shader/src/emit/bary_gs.rs:112andd3d12/crates/leonida-shader/src/emit/mesh_vs.rs:134can reject system-value relocation despite free rows below the highest occupied row. Allocate from those holes.d3d12/crates/leonida-shader/src/emit/mesh_vs.rs:207allows instancecapto rasterize from the shared overflow slot. Excludegroup >= capand cap the instance count.
No builds or GPU tests were run for this review.
AI-assisted.
… slot drawn by no instance, the title's topology back, offsets beside their elements From timbot103's audit of dc5818b (ProjectLeonida#2580): - An indirect mesh dispatch run as compute makes no host mesh command signature first: a host without mesh shaders may refuse one, and the fallback needs none (draw.rs). - Slot `groups_cap` is the sink every group from the cap on writes to at once: mesh_vs draws nothing for an instance from the cap on (it took only those past it), and the direct path draws at most `cap` instances. - The fallback's triangle list no longer stays the list's topology: the title's comes back after it (`restore_topology`). - MeshOut's OSG1/PSG1 parts keep their elements in the order of the byte offsets made for them: sorted by register, an element stood beside another's offset where the outputs were not in register order. - A per-primitive render-target or viewport index is refused by mesh_vs rather than left out (the translator does not export them yet). - The host device is made before a pipeline chooses between the mesh path and the fallback, so a pipeline made first cannot keep the mesh path. - The mesh program's own stores (to title buffers) count after a fallback draw, as the draw's do (`drew_mesh_as_compute`). Tests: mesh_out_parts_keep_their_elements_beside_their_offsets (fails without the fix), the_mesh_sink_slot_draws_nothing (GPU; the test harness's Draw takes an instance count). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both callers are in leonida-shader; a public constructor taking a crate-private type set off private_interfaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Mechanical note, no review: this branch conflicts with
So a rebase is all it needs - the change itself may well be fine, I have not looked at its content, only at whether git can apply it. Written with an AI assistant. |
… on a device The commands the mesh fallback records between and after the pipelines the draw path binds (barriers, the dispatch or counted indirect dispatch, the header of the indirect draw, the triangle list drawn from the buffer, the title's topology again) move from draw.rs into mesh_fallback::MeshRun, which draw.rs calls. A test records the same commands on a device of its own, as a title does in one list: a counted indirect run (count 1), a direct run of three groups, a run whose triangle is culled, a counted indirect run with a count of 0, then the title's triangle strip; every texel comes out as the runs and the strip draw it. Without the topology restored the strip draws one triangle (64 texels differ); without the header's instance count reset the count-0 run draws the first run's groups again (100 differ). leonida-shader's host checks (emit::host) take the test programs this needs: triangle_mesh_program (the triangle mesh program its own tests used), color_ps and position_vs; dxbc::build is there for them too. draw.rs names its topology mapping (host_topology). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rycentrics (D3D12-BARYCENTRICS-FALLBACK) Without D3D12 barycentrics (before Turing) every pixel shader that reads SV_Barycentrics or attributeAtVertex is refused at pipeline creation (the debug layer: "Shader uses Barycentrics, but the device does not support this"). set_host_barycentrics(false) translates them with ordinary inputs instead: - LEONIDA_BARY, a float3 per interpolation mode, for SV_Barycentrics; - LEONIDA_VTX, constant one-channel inputs whose semantic index names the element, column and vertex, for attributeAtVertex at vertices 1 and 2 (vertex 0 is the element itself). - They take rows past the title's own, packed four to a row; a shader that would need more than 32 rows is refused. bary_gs() builds the geometry stage that writes them. It passes the vertex shader's outputs through, register for register, and adds: - one-hot weights (1,0,0) / (0,1,0) / (0,0,1) at the corners; - each corner's value of the elements read at a vertex; - the primitive id if the pixel shader wants it. A stand-in that lands on a vertex shader register moves a system value to a free row and drops a user output the pixel shader does not read. host_settings() gets a sixth word. MEASURED before coding (the title's translated pixel shaders): 4058 read barycentrics, 4040 of them through attributeAtVertex; packed, 54 need more than 32 rows. Tests: seven hand-worked barycentric programs read the stand-ins; the pixel shaders and the geometry stage validate in dxil.dll. A device test draws them through the stage and checks the hand-worked values (compared with native barycentrics where the device has them). A weight rotation mutant fails it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…centrics At device creation, OPTIONS3.BarycentricsSupported tells the translator whether to use stand-ins (LEONIDA_BARY_FALLBACK=1 takes the fallback on any card). A graphics pipeline whose pixel shader reads them gets bary_gs between its vertex and pixel shaders, named apart in the pipeline library. shortcut: a rectangle list drops its own geometry stage for it (logged); mesh-as-compute pipelines do not get it yet. MEASURED on a GTX 1050 Ti, Windows 10 with ProjectLeonida#2557 and the D3D12 debug layer, 10 minutes of play: - "host pipeline refused": 0 (369 before); - "Shader uses Barycentrics": 0 (435 before); - no geometry/pixel stage linkage messages; - 2 pixel shaders refused for 32 rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…un as compute A pixel shader drawn behind a mesh program on a host without barycentrics reads LEONIDA_BARY and LEONIDA_VTX, which no geometry stage writes on that path: they read zero, and what the title draws with mesh shaders came out black. mesh_vs writes them itself, since every corner is its own vertex there: - the weights are 1 at the corner's column; - vertex k's value is read through the primitive's corner-k index, the same at all three corners. A vertex output on a stand-in's register is left out, or moves past them if it is a system value (as bary_gs). Pipelines that draw through mesh_vs do not get bary_gs. Test: for the seven barycentric programs, every stand-in their pixel shader reads is a mesh_vs output in the same register, and dxil.dll takes the vertex shader (mesh 8, barycentric 19 tests pass on a GTX 1050 Ti). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion, no mesh pipeline with the stand-ins, triangles only, moved outputs into free registers From timbot103's audit of c2f4cd3 (ProjectLeonida#2581): - bary_gs takes the vertex shader's interpolation from its PSV0, as the translator declared it from the title's (a float packed beside an integer can be constant there), instead of a default by type: the stage's rows carry the vertex shader's modes. - With the barycentrics stand-ins (no barycentrics, or LEONIDA_BARY_FALLBACK=1) mesh programs run as compute: a mesh pipeline has no stage after the mesh program to write the stand-ins, and mesh_vs writes them. - A pipeline with the barycentrics stage (`HostPipeline::bary`) draws triangle lists and strips only; a draw with points, lines or adjacency is left out and logged once (shortcut: no stage for those inputs yet). - A system value moved out of the stand-ins' rows takes the lowest free register (`lowest_free_row`), below the highest in use where one is free, in bary_gs and mesh_vs alike. Not in this commit: a rectangle list whose pixel shader needs the stand-ins still goes without the rectangle stage (the marked shortcut in pipeline/host.rs); the sink slot and the IA topology are fixed in the mesh commit below. Tests: the_vertex_shaders_interpolation_comes_from_its_psv0, moved_outputs_take_the_lowest_free_register. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rectangle list draw whose pixel shader needs the barycentrics fallback had to pick one geometry shader: the rectangle stage (fourth corner) or the barycentrics stage (weights and per-vertex values). It now gets rect_bary_gs, which completes the rectangle and writes the stand-ins for each of its two triangles, six vertices in one stage. bary_gs is split into layout/values/store so both stages share the signature walk and the stand-in sources. Tests: a portable one (six vertices, every pixel shader input written, no position refused) and, on Windows, the validator and a draw compared with host barycentrics where the device has them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t takes six vertices A pipeline with the barycentrics stage left out every draw of triangle lists or strips with adjacency (the stage takes three vertices). Such a draw now goes out with a variant whose stage, bary_gs_adjacency, takes triangles with adjacency (DXIL input primitive 7) and draws the triangle at 0, 2, 4, as the rasterizer would without a geometry shader. The variant is made at the first such draw, on the same chain as the per-format variants (make::for_adjacency), so barycentrics pipelines are not all made twice. GraphicsState carries the flag into its description (a name of its own in the library) and into the pipeline book (bit 1 of the depth bounds byte; books written before read as without), so the next run makes it ahead of time. Geometry and PSV0 take the input primitive instead of a fixed 3. Points and lines with the stage are still left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c2f4cd3 to
66afbce
Compare
|
Thanks, @timbot103. Fixed in 7e691b6, 8bd30f5 and 66afbce (rebased on #2580; the sink and topology points are fixed there):
New tests:
Tested on GTX 1050 Ti 4 GB / NVIDIA 582.66 / Windows 10 (no SV_Barycentrics, so the stand-ins path):
Not run here: a pixel-for-pixel comparison against hardware barycentrics. The 1050 Ti has none, so on it those tests check the stand-in path's output only. AI-assisted (Claude Code). |
Conflicts: draw.rs (the signature is an Option for the mesh fallback, and main reads mesh_test() once per dispatch: the fallback takes that mode too), emit/mod.rs (both sets of exports; main's pixel mask test with the mesh test programs from emit::host). Main's new test initializers take the fields this branch adds (Parts::mesh_compute, Draw::vertex_count/instances, HostShader::mesh_out). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mesh, colour and position programs 924b294 put in emit::host are needed by portable tests too (primitive_export_indices_drop_the_edge_flags), and emit::host is Windows-only: the Linux test build did not resolve them. They need no device, so they live in emit::test_programs, built for tests and the host feature on every platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: draw.rs (main picks the pipeline through graphics_pipeline(), the sample mask's twin; a draw of triangles with adjacency then takes the barycentrics variant, which draws every pixel as the title's pipeline does while its masked twin is made), pipeline.rs (host_pipeline_adjacency beside main's host_pipeline_masked), emit/mod.rs (both sets of exports). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's Shader gained mask and masked_twins (the sample mask's pixel shader twins); the mesh program seen as compute and its pass-through vertex shader are the title's own forms: no mask, no twins yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iants masked_for (main) picks a variant of the masked pipeline for the bound formats through variant(), which now also says whether the variant is for triangles with adjacency: these are not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged main (through #2580's merge) in ae1ecd2, d5f666a and 1e13fef. Conflicts:
GTX 1050 Ti / 582.66 / Windows 10:
Linux: leonida-shader 232 passed. AI-assisted (Claude Code). |
|
One follow-up on the Static review of this interaction. AI-assisted. |
|
Partial check by OreoFR on macOS 27.2.1 (26B131), Apple M5, Rust 1.98.1 (d3d12/rust-toolchain.toml), main 060c471 (merges cleanly; does not force a rebase of #2566 at eade956), PR head 1e13fef (stacked on #2580)
Verdict: leonida-shader part green (no red possible); leonida-gpu not buildable on macOS; one open review question. AI-assisted: Claude Code |
|
Verified by OreoFR (Windows part: leonida-gpu, plus leonida-shader's Windows-only tests; oreofr-mac covered leonida-shader on macOS) PR head
Verdict: NO RED (green on Windows, no failing test possible without the change). This verification was AI-assisted (Claude Code, oreofr-agent). |
|
Measured on Windows 11 with the Windows SDK's On this pull request's head ( and every one of the 11 says the same thing: The cause is not in the geometry stage this pull request builds: the With that change applied to this pull request's head (the patch applies cleanly to All the validator failures are gone; the one that is left is not the validator: It fails on this pull request's head without #2864 as well, and it passes on the current One thing to know before reading a green CI run as a check of the container: the No game files and no GPU were needed for this check; the validator is the Windows SDK's |

Claimed in the coordination issue as: D3D12-BARYCENTRICS-FALLBACK (#2570#issuecomment-7242150584)
Depends on: #2580 (built on it; the shader-cache key words follow on).
What and why
Without D3D12 barycentrics (before Turing) every pixel shader that reads
SV_BarycentricsorattributeAtVertexis refused at pipeline creation. The debug layer saysShader uses Barycentrics, but the device does not support this. On a GTX 1050 Ti that is 369 refused pipelines (bloom and more).set_host_barycentrics(false):LEONIDA_BARY(a float3 per interpolation mode), andLEONIDA_VTX(constant values at vertices 1 and 2 forattributeAtVertex), packed past the title's own rows;bary_gs():OPTIONS3.BarycentricsSupporteddecides (LEONIDA_BARY_FALLBACK=1forces it);Tested
attributeAtVertex; packed, 54 would need more than 32 rows.host pipeline refused369 → 0;Shader uses Barycentrics435 → 0;cargo test -p leonida-shader --lib barycentric): 18 pass on the 1050 Ti.GPUs tested: GTX 1050 Ti 4 GB (Pascal, profile S), 582.66, Windows 10.
AI-assisted (Claude Code).
🤖 Generated with Claude Code