Repository navigation
Conversation
|
The second GPU run on the rebased head you asked for:
AI-assisted (Claude Code). |
|
Tested 8f3e3f4 on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101, Windows 11, native MSVC (VS 2022 Build Tools, Ninja, RelWithDebInfo), with
AI-assisted (Claude Code). |
|
Tested 8f3e3f4 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, fresh RelWithDebInfo build. It conflicts with current
AI-assisted (Claude Code). |
8f3e3f4 to
98d977a
Compare
|
Rebased onto
A GPU run on 98d977a would be welcome; I haven't run the tests on this head yet. AI-assisted (Claude Code). |
|
Tested 98d977a on its base
Synthetic fixtures only, no game files. AI-assisted (Claude Code). |
…te allocations (D3D-289) In `replay_cpu_bench` and real game execution, recording draws was the largest remaining per-draw overhead (~155-160 ns and 4 heap allocations per draw call, measured by @traeb0n in #2123 follow-up finding D3D-289). Previously: - `d3d12_com.cpp` heap-allocated a dynamic `std::vector<TargetView>` for render targets and another `std::vector<VertexBufferView>` for vertex buffers (copying from the list's 32-element array). - `CommandList::draw(const Draw&)` then copied both vectors again into the `Command` variant inside `commands_`, resulting in 4 heap allocations per draw. This change: - In `runtime/src/command_list.h` (`leonida::Draw`): - Replaces `std::vector<TargetView>` with fixed inline `std::array<TargetView, 8> render_targets` (matching `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` = 8) and tracks `render_target_count`. - Replaces `std::vector<VertexBufferView>` with fixed inline `std::array<VertexBufferView, 32> vertex_buffers` (matching `D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT` = 32). - Adds rvalue `bool draw(Draw&&)` overload that moves the command into `append(std::move(draw))`. - In `runtime/shims/d3d12_com.cpp`: - Stores `render_targets_` as an inline `std::array<leonida::TargetView, D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT>`, eliminating heap reallocations on `OMSetRenderTargets`. - Directly passes `vertex_buffers_` without copying into a temporary vector. - Moves `draw` with `check(list_.draw(std::move(draw)))`. - In `runtime/src/vulkan_replay.h`: - Iterates over bound render targets using `slot < draw.render_target_count && slot < draw.render_targets.size()`. - In `runtime/test/d3d12_com_test.cpp`: - Adds static assertions verifying `Draw` move constructibility, move assignability, and fixed inline array sizes. - Updated `docs/d3d12_vulkan.md` with the contract details. Result: 0 heap allocations per draw call (down from 4), eliminating ~155-160 ns recording overhead per draw call. Tested: - `python -m compileall -q make_game.py tools tests`: OK - `python -I make_game.py --help`: OK - `static_assert` checks in `d3d12_com_test.cpp`: verified Hardware: Tested on AMD Radeon RX 7800 XT (driver 24.20.19.05 / Vulkan 1.4.359 / Windows 11). AI-assisted. Standard library / C++ only; no game content or carved assets. Item: D3D-289 Depends on: #2123
The frame's passes now record 16 draws each (three of four indexed), into the colour and depth targets with two vertex streams, and the per-kind table times a draw and an indexed draw on their own. The scene has one graphics pipeline and a geometry arena behind buffer_at, as VulkanContext provides them. i7-14700K: a draw costs 487-500 ns (record 170-180 with 4 allocations, prepare 213, emit 104-107 with 1 allocation), and the frame (37,888 commands) 548 ns per command, 20.8 ms per ExecuteCommandLists for the layer alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every command's detail::Prepared carried a draw's fields (a copy of the GraphicsPipeline, eight attachment slots, depth, vertex and index views), 456 of its 1288 bytes, and the whole entry is refilled for every command on every ExecuteCommandLists. They move to detail::PreparedDraw in PreparedList::draws, which Prepared::draw indexes; the pool is kept between executions like the PreparedList itself and reset() keeps its vectors' storage. The entry is now 856 bytes. The draw keeps a pointer to the context's GraphicsPipeline instead of a copy (a vector and a std::function per draw): VulkanQueue::execute holds the resource lock from prepare through emit, which add/remove_pipeline need exclusively, and unordered_map elements don't move. emit builds the colour attachments in a std::array of D3D12's 8 instead of a vector per draw, and to_attachment takes the attachment const, so the const_cast goes. replay_cpu_bench --self-test prepares an indexed draw with depth, then a draw without either in the same storage, and checks the second keeps neither (fails without reset(), checked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Draw's render targets and vertex buffers are fixed arrays on main now (ItsNotRexed#2483), with render_target_count saying how many targets are bound. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98d977a to
d33e46e
Compare
|
Rebased onto
AI-assisted (Claude Code). |
ItsNotRexed#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 ItsNotRexed#3346. Its comment no longer says every pipeline declares the same dynamic states: the vertex strides are the exception.
Depends on: #893, #901 (both merged; this branch is now just its own two commits on main).
Claim: #1902 (comment)
Every command's
detail::Preparedcarried a draw's fields: a copy of theGraphicsPipeline, eight attachment slots, depth, and the vertex and index views. That's 456 of its 1288 bytes, and the whole entry is refilled for every command on every ExecuteCommandLists.Changes
replay_cpu_benchframe includes draws (a7b4ab6). Each pass records 16 draws (three of four indexed) into the colour and depth targets with two vertex streams, and the per-kind table times a draw and an indexed draw. The scene has one graphics pipeline and a geometry arena behindbuffer_at, asVulkanContextprovides them.detail::PreparedDrawinPreparedList::draws, indexed byPrepared::draw. The pool is kept between executions like thePreparedListitself (Runtime: VulkanQueue keeps its PreparedList storage between executions (layer CPU cost per command halved) #893), andreset()keeps its vectors' storage. The entry is now 856 bytes with MSVC 14.44 (864 with 19.52, from padding).GraphicsPipelineinstead of a copy (which was a vector and astd::functionper draw).VulkanQueue::executeholds the resource lock from prepare through emit,add/remove_pipelinetake it exclusively, andunordered_mapelements don't move.std::arrayof D3D12's 8 instead of a vector per draw.prepare_drawrefuses a pipeline with more than 8.to_attachmenttakes the attachmentconst, so theconst_castgoes.replay_cpu_benchon an i7-14700K. The frame is 8 lists × 128 passes, 37,888 commands. These are medians of 5 alternating runs of the bench at a7b4ab6 (before) and at this branch (after).A draw goes from ~448 to ~393 ns, and every other command gets cheaper with the smaller entry (transition pair 138 → 108 ns).
Tests
replay_cpu_bench --self-testprepares two indexed draws with depth, then a draw with neither in the same storage, and checks the second keeps neither. It fails withoutreset()(checked).d3d12_vulkan_device_testwithLEONIDA_VK_VALIDATION=1passes, 0 validation errors.replay_cpu_bench --self-testpasses.ctest -E loader: everything passes exceptd3d12_computeandd3d12_draw, which fail the same way on a cleanmain6a6704d build. That's the fence-21 wait ind3d12_draw(Tests: bundle blend pass in d3d12_draw waits on fence 21 after line 580 signaled 30 (fails with "bundle blend pixel (0, 0): got 128,0,128,255, expected red 64") #1966) and its follow-onVUID-vkDestroyPipeline-pipeline-00765, plus d3d12_compute_test: release the slot-67 PSO before the device reference check #1898/test(d3d12): reset slot 67 PSOs before device refcount check in d3d12_compute_test #1919.d3d12_drawchecks before the fence bug pass on this branch, including the strip-cut test and its negative control.main4eb6155. The only conflict was wherexdxr_bytes(added by 9fd1aae) goes; it stays inPreparednext toaccel_dst/accel_src. It builds with no new warnings. A second GPU run on the rebased head is welcome.The copy and resolve fields (~360 bytes) could move out the same way. I'd do that as a follow-up so this stays reviewable.
AI-assisted (Claude Code).
🤖 Generated with Claude Code