Skip to content

pvr, pco: preload constant-offset UBO reads into shared registers - #55

Merged
henrikklee merged 1 commit into
OrchardLinux:mainfrom
cDurham:pvr/ubo-preload
Dec 4, 2026
Merged

henrikklee merged 1 commit into
OrchardLinux:mainfrom
cDurham:pvr/ubo-preload

Conversation

@cDurham

@cDurham cDurham commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

On the A7 a fragment shader reads each uniform from memory for every fragment: pco turns load_ubo into an address computation, ld and wdf, 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-bit load_ubo with 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, through PVR_BUFFER_TYPE_UBO and pvr_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:

  • vec4 uniform colour: 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 match the build without this, pixel for pixel. No GPU fault.
  • The Omarchy A desktop (Labwc, Quickshell, Epiphany) ran on an earlier build of this change with the same logic; the final build has run the benchmark and the pixel checks.

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

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>
@henrikklee
henrikklee merged commit 5a7b536 into OrchardLinux:main Dec 4, 2026
1 check passed
@henrikklee

Copy link
Copy Markdown
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:

  • in the rare case of a UBO bound shorter than the shader reads (within the same page), the preloaded values skip robust-buffer-access zeroing. Zink binds whole blocks, so it doesn't hit this;
  • the description says dynamic UBOs aren't covered, but the code does preload them (with the offset applied). A test of that path would be welcome;
  • a whole-desktop frame/CPU number on an A7 would be great for the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants