Repository navigation
pvr, pco: preload constant-offset UBO reads into shared registers - #55
Merged
Merged
Conversation
pco turns every load_ubo into a per-instance memory load: the address from the descriptor's shared registers, two 64-bit adds, ld and wdf, behind the null-descriptor tests when nullDescriptor is on. A fragment shader pays that for every uniform scalar on every fragment. Zink keeps all of a GL program's uniforms in a UBO, so every GL client pays it. On the Apple A7 (iPad mini 2, 1536x2048 offscreen target through Zink, GPU at 450 MHz, fragment time the firmware reports for one full-screen draw) a constant colour takes 5 ms and the same colour read from a vec4 uniform 57 ms, about 13 ms per scalar read. Read such uniforms once per draw instead, the way push constants already are. A new pass, pco_nir_preload_ubos, runs before the robust-access and null-descriptor lowering. It rewrites 32-bit load_ubo with a constant offset in the block's first 64 dwords, on a single-element uniform buffer binding of a vertex or fragment shader, to load_ubo_preload_pco, and records per binding the range of dwords read (up to four bindings a stage). The pipeline gives each range shared registers and a PVR_BUFFER_TYPE_UBO entry in the PDS descriptor program; that type and pvr_const_map_entry_constant_buffer existed but had no user. pvr_setup_descriptor_mappings() writes the DMA's source for each draw from the bound buffer, dynamic or not, through the new pvr_descriptor_set_buffer(). The load is translated by trans_load_common_store(), as a push constant is. The offset of a load_ubo is still the descriptor's third component plus constants at that point, so the pass folds constants first and follows the adds. A binding with no buffer, or a null one, reads the device's zero page. So does a buffer whose bound range ends before the preloaded range when reading on would cross a page of the general heap: members inside the bound range then read as zero as well. Zink binds the whole block, so it never gets there. Same target and measurement, before -> after: - vec4 uniform colour: 57 ms -> 6.5 ms - vec4 uniform * varying: 57 ms -> 6.5 ms - texture * vec4 uniform: 59 ms -> 17 ms - texture * float uniform: 23 ms -> 17 ms - texture alone: 17 ms -> 17 ms 65 GLES2 draws read back with glReadPixels (uniform colours and floats, a uniform array read from its last element only and from two elements with a gap, textures, eight draws in one frame each with another colour, blending) give the same pixels as the build without this. No GPU fault. The Omarchy A desktop (Labwc on wlroots' GLES2 renderer, Quickshell) runs on it. Not run: dynamic uniform buffers, a Vulkan client other than Zink, the dEQP lists, and Rogue hardware other than the A7. The A8, A9 and A10 have their own backends and do not take this path. Generated-by: LLM Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: cDurham <47431093+cDurham@users.noreply.github.com>
Contributor
|
Merged — thank you @cDurham! Loading constant-offset UBO reads into shared registers once per draw is exactly the kind of win the A7 desktop needed: 57 → 6.5 ms for a uniform colour is huge. It only takes the stock pco path, so A8/A9/A10 are untouched. Small follow-ups, none blocking:
|
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.
On the A7 a fragment shader reads each uniform from memory for every fragment: pco turns
load_ubointo an address computation,ldandwdf, behind the null-descriptor tests. Zink keeps all of a GL program's uniforms in a UBO, so every GL client pays it. On an iPad mini 2 a full-screen draw of a constant colour takes 5 ms of fragment time; the same colour from a vec4 uniform takes 57 ms.Change: read such uniforms once per draw, as push constants already are. A new pass (
pco_nir_preload_ubos) rewrites 32-bitload_ubowith a constant offset in the block's first 64 dwords, on single-element uniform buffer bindings of vertex and fragment shaders. The PDS descriptor program copies the dwords a shader reads into shared registers, throughPVR_BUFFER_TYPE_UBOandpvr_const_map_entry_constant_buffer, which existed without a user.Which chips: the stock pco path, so the A7 and upstream's Rogue cores. The A8, A9 and A10 backends do not go through it.
Tested on an iPad mini 2 Wi-Fi (J85, A7), 1536x2048 through Zink, GPU at 450 MHz, firmware fragment time per full-screen draw:
glReadPixelsmatch the build without this, pixel for pixel. No GPU fault.Not covered: dynamic uniform buffers, Vulkan clients other than Zink, dEQP and other Rogue hardware have not run. If a bound range ends before the preloaded one and reading on would cross a page, the whole preloaded range reads as zero. A local package build of this head is still running; the Build workflow here covers the same.
🤖 Generated with Claude Code