Repository navigation
Conversation
emit opened a vkCmdBeginRendering/vkCmdEndRendering scope for every draw, with an attachment-to-attachment barrier per bound attachment in front of it, so the GPU drained between every two draws. Consecutive draws whose attachments are the same views in the same layouts, with the same render area, layer count and depth/stencil attachments, now share one scope (detail::DrawScope): the attachments move and get their barrier once, when it opens, and rasterization order keeps the draws' attachment writes ordered. Any command other than a draw ends the scope first, so barriers, clears, copies, queries, predication and markers still run outside one, and the scope ends before conditional rendering does. Inside a scope, pipeline, descriptor set, push constants, viewport, scissor, topology, primitive restart, stencil references, blend constants and vertex and index buffers are only set again when they change. Every translated graphics pipeline declares the same dynamic states, so binding another one keeps them; the cache is dropped with the scope. replay_draw_scope_test (CPU, mocked Vulkan) checks one scope for matching draws, new scopes for other targets or depth/stencil attachments, the scope ending before barriers, markers and conditional rendering, state set again only when it changes, and the layout tracker.
DrawScope::reset assigned a fresh DrawScope, about 1.3 KB with the 32 vertex-buffer slots and the pushed constants, and freed the colour attachment vector, for every scope that closed. When no two consecutive draws share their attachments (one scope per draw), that cost about 0.2 us a draw on the CPU. The small state a scope compares and sets is now DrawScope::State and is the only thing reset; the pushed constants and the vertex-buffer slots stay in place and are read only where State says they are valid (push_layout, vertex_valid). The attachment vectors, including the VkRenderingAttachmentInfo scratch, keep their storage between scopes. Measured on an RTX 3060 Ti (driver 32.0.15.9186) with 4000 draws whose render target alternates every draw, emit with no-op Vulkan calls (median): 1.41 ms without the shared scope, about 2.0 ms with it before this change, 1.62 ms after. With the driver the difference is within noise (18.5 ms without the shared scope, 17.7 ms now). Draws that share targets keep their gain (GPU 14.6 ms -> 0.17 ms for 4000 draws). replay_draw_scope_test also checks that vertex and index buffers are bound again in every new scope.
|
Independent Windows 11 build 26300 / MSVC 19.52 / NVIDIA RTX 5070 Ti, driver 621.24 check of Built with the Vulkan SDK's
The draw test exercises consecutive draws with pipeline, viewport and vertex-binding changes and checks image readback. M2 matched 4,096 pixels; M3 checked six frames, three targets per frame, and occlusion counts. I did not independently benchmark the speedup or test another vendor. No game files were used. — LocalFirst-AI |
|
AI-assisted independent review of head Replay correctness issue. In one scope, bind a vertex-input PSO, draw with a no-vertex-input full-screen PSO, then return to the original PSO and unchanged vertex bindings. The full-screen PSO provides vertex-input state but omits
|
|
Tested d3f25ca on Windows 11, RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1):
AI-assisted. |
|
Tested d3f25ca on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
|
Tested
AI-assisted (Claude Code). No game files. |
|
Code review of d3f25ca (read only, no runs): looks correct to me. I'd written nearly the same change before I found this PR (my mistake: D3D-324 was yours first; I've released my claim on #3574), so I went through the rules closely. What I checked:
Two small things, neither blocking:
On merge order: this conflicts with my #2123, which moves a draw's prepared data into AI-assisted (Claude Code). |
|
One addition to my review, from reading #3167 (D3D-353, with #2676 under it). That PR binds index buffers with their view's size ( AI-assisted (Claude Code). |
A pipeline whose input layout has no elements leaves VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE out of its dynamic states (d3d12_vulkan_device.cpp, pipeline creation), so binding it invalidates the strides set before. In one scope, a draw with vertex input, then a full-screen draw, then the first pipeline again with the same vertex buffers skipped vkCmdBindVertexBuffers2 on the third draw, which then ran with no stride set (VUID-vkCmdDrawIndexed-pStrides-04913). Found by whattheflop in the review of ProjectLeonida#3346. Binding a pipeline with no vertex slots now clears the scope's vertex binding cache. replay_draw_scope_test checks that sequence: it fails without the change and passes with it.
|
@traeb0n thanks for the careful review, and for releasing your claim on #3574. It helps a lot to have it checked by someone who wrote the same change. I think point 3 (every graphics pipeline declares the same dynamic states) doesn't hold, and that's the bug @whattheflop reported above. The list is the same array, but its length isn't: a pipeline with no vertex bindings drops the last entry, When a pipeline without a state as dynamic is bound, the dynamic value set before is invalidated (dynamic state). So within one scope: a draw with vertex input → a full-screen draw → the first pipeline again with the same vertex buffers. The cache says slot 0 is still bound and skips Fixed in 73698b9: binding a pipeline with no vertex slots clears On the two other points:
Merge order: fine with me either way. If #2123 lands first I'll do the AI-assisted (Claude Code). |
…#2123) ProjectLeonida#2123 moved a draw's prepared data into detail::PreparedDraw (p.colors -> d.colors, p.graphics -> *d.graphics) and binds d.pipeline, the pipeline or its variant for unbound slots. The scope now caches d.pipeline, so a variant is bound when it differs. to_attachment takes a const attachment, so the const_cast is gone. DrawScope keeps its colour attachments and the vkCmdBeginRendering scratch in std::array<..., max_render_targets> with a count instead of vectors (prepare refuses more than eight), so a scope never allocates, as traeb0n suggested in the review of ProjectLeonida#3346. Its comment no longer says every pipeline declares the same dynamic states: the vertex strides are the exception.
|
@traeb0n #2123 landed first, so I've done the rebase onto
Tested on 0a8e369: full runtime build and The AI-assisted (Claude Code). |
|
Tested 0a8e369 (merged onto main aa2988c) on RTX 3060 (Ampere), driver 617.14, Windows 11, MSVC 14.44, RelWithDebInfo: pass
AI-assisted: this check was run and written with Claude Code (Anthropic) on my machine; the numbers above are its unedited output. |
|
Build break on current Cause: Fix in @@ -219,9 +219,11 @@ int main() {
Draw d{};
d.pipeline = pso;
d.user_data[0] = seed;
- d.render_targets = {TargetView{target, 0, 0, 1}};
d.depth = TargetView{depth_id, 0, 0, 1};
- d.vertex_buffers = {VertexBufferView{0x10000, 1024, 16}};
+ DrawViews views;
+ views.render_targets = {TargetView{target, 0, 0, 1}};
+ views.vertex_buffers = {VertexBufferView{0x10000, 1024, 16}};
+ d.views = std::make_shared<const DrawViews>(views);
d.index = IndexBufferView{0x20000, 1024, 57};
d.topology = 4; // triangle list
d.viewport = {0, 0, 64, 64, 0, 1};With it, on AI-assisted (Claude Code). |
…d D3D-391's DrawViews D3D-314 (e8a23c1) binds set 0 from the device's current bindless generation, vk.bindless_set, and falls back to the pipeline's own set. The scope now caches the set it actually bound. That set stays the same for the whole list, so pipelines made before and after a flush (different markers, same layout) share one bind instead of rebinding at every pipeline change. D3D-391 (f506039) moved a draw's render targets and vertex buffers into the shared DrawViews block (Draw::views). replay_draw_scope_test's make_draw fills a DrawViews, as ddm-j suggested in the review of ProjectLeonida#3346. render_target_count keeps its default of 8, as on the old Draw. replay_draw_scope_test case 9 covers both sources of set 0: each pipeline's own set without a current generation, and the device's set bound once for both pipelines with one. docs/d3d12_vulkan.md says which set the scope compares.
|
@ddm-j thanks, your
Tested on an RTX 3060 Ti, driver 591.86, Windows 11, MSVC 14.41 (VS 2022), RelWithDebInfo with
Not run: AI-assisted (Claude Code). |
devnull34
left a comment
There was a problem hiding this comment.
Tested at head 22775ac on Windows 11 with MSVC 19.44 (VS 2022) on AMD Radeon RX 7900 GRE:
- Build: Built target
eplay_draw_scope_test cleanly with 0 warnings/errors. -
Test execution:
eplay_draw_scope_test.exe: PASS (draws share a rendering scope while their attachments match; other commands end it first).
- CTest
eplay_draw_scope: 5/5 passed (--repeat until-fail:5). Confirms that case 9 properly validates shared set binding across pipelines with current device generations vs distinct bindings, as well as preserving attachments matching across consecutive draws. - Python tests est_docs_cli_flags.py (3/3 OK) and est_text_write_line_endings.py (3/3 OK) pass cleanly.
- Diff & formatting: git diff --check origin/main..HEAD is clean with no trailing whitespace or leftover merge conflicts.
No retail game files or keys used.
AI-assisted verification.
Item: D3D-324 (claimed in #2516, #2516 (comment))
emitopened avkCmdBeginRendering/vkCmdEndRenderingscope for every draw, with an attachment-to-attachmentbarrier per bound attachment in front of it, so the GPU drained between every two draws. Measured below: about
3.7 µs of GPU time per draw on an RTX 3060 Ti for the scope and its barriers alone.
Changes (
runtime/src/vulkan_replay.h)count and depth/stencil attachments, share one rendering scope (
detail::DrawScope). The attachments move and gettheir barrier once, when the scope opens; rasterization order keeps the draws' attachment writes ordered.
markers still run outside one, and the scope ends before conditional rendering does.
references, blend constants and vertex/index buffers are only set again when they change. Every translated graphics
pipeline declares the same dynamic states (
d3d12_vulkan_device.cpp, pipeline creation), so binding anotherpipeline keeps them; the cache is dropped with the scope.
DrawScope::State; pushed constants and vertex slots stay in place behindvalidity fields, and the vectors keep their storage, so a list with no shareable draws costs about the same as
before.
docs/d3d12_vulkan.md: the draw replay and render-pass notes describe the shared scope.Tests
replay_draw_scope_test(new, CPU, mocked Vulkan, in CTest): one scope for matching draws; new scopes for anotherrender target or another depth/stencil attachment set; the scope ends before a UAV barrier, a marker and the end of
conditional rendering; no barrier while a scope is open; state set again only when it changes and in every new
scope; layout tracker updated.
cteston top off847748c: 123/123 passed (gameinputis disabled and the skipped testsskip on
maintoo).vk_command_replay_testpasses on the RTX 3060 Ti (no draws in it).Measurements
A standalone bench (not in this PR) replays real draws through
prepare/emiton the GPU, built once againstf847748c'svulkan_replay.hand once against this branch: 4000 draws of ~650 px (hand-assembled SPIR-V VS/FS,additive blending, depth test), 1920×1080 RGBA8 + D32, the pipeline changing every 50 draws and the root constants
every draw. GPU time from timestamps around the list, CPU time for
prepare+emitwith the driver'svkCmd*cost; each figure is the median of three runs of the median of 20 submissions.
identical before and after.
f847748c),emitfor C costs 1.41 ms before and1.62 ms after (about 0.05 µs a draw).
Not tested
d3d12_draw_test,d3d12_m2_textured_test,d3d12_m3_frame_test,d3d12_msaa_draw_test):they need
glslangValidator, not installed here. A run on any GPU would help, AMD and Intel especially.LEONIDA_VK_VALIDATION=1.and debug markers between draws end the scope.
Windows 11, MSVC (Visual Studio 18), NVIDIA GeForce RTX 3060 Ti, driver 32.0.15.9186. No game files.
AI-assisted (Claude Code); reviewed and tested as above.