Create a render pass directly and keep the builder for composition - #469
Open
botoddly wants to merge 4 commits into
Open
Create a render pass directly and keep the builder for composition#469botoddly wants to merge 4 commits into
botoddly wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the first of the three allocation sources in #468:
new RenderPassBuilder(commandBuffer)allocated the builder plus the twoList<>it holds, once per render pass per frame, anddocs/render-pass-flow.mdtaught that as the pattern.Rather than making the builder allocation-free, this separates the two jobs it was doing.
A direct method for the per-frame path
CommandBuffer.CreateRenderPassnow takes the description directly, allocating nothing:The general overload takes
ReadOnlySpan<Texture>/ReadOnlySpan<ColorTargetSettings>instead ofList<>, and validates its own arguments: one settings entry per color target, at mostCommandBuffer.MaxColorTargetstargets, and at least one color target or a depth buffer.MaxColorTargetsis 8, the point at whichSDL_BeginGPURenderPassitself rejects the pass (MAX_COLOR_TARGET_BINDINGSinSDL_sysgpu.h; SDL exposes no constant, and the prose inSDL_gpu.hstill says four).The builder stays a class, for composition
RenderPassBuilderkeeps its shape and itsList<>storage — no cap, no value-type surprises — and is documented as the option for a pass composed conditionally or from a varying number of targets, which allocates. Every per-frame caller now uses the direct method instead.All 13 call sites in
src/Pixely.Pencuilandtutorials/moved over; nothing outside the builder's own tests constructs one any more.docs/render-pass-flow.mdteachesCreateRenderPassand describes the builder as the composition option;docs/subrenderers.mdshows the G-buffer case with caller-owned arrays.Behaviour changes
IRenderPassBuilderis gone. It had no users outside its own file, and the builder's fluent methods now return the concrete type.AddColorTarget(texture)andAddColorTarget(texture, settings)used to misalign the two lists silently — the settings given for the second target were applied to the first. The counts must now match, andBuild()throws when they do not.Verification
dotnet test Pixely.slnxgreen.RenderPassBuilderTestscovers the builder's four validation paths.SDL_VIDEODRIVER=offscreenwithout error, exercising the single-target, depth and depth-only overloads on a real device. Nothing asserts the rendered output.Not in scope
The other two sources in #468 are untouched:
Build()andCreateRenderPassstill return a heap-allocatedRenderPass, andCreateAndTrackTransferBufferstill creates a native transfer buffer perUpdate*call.