Skip to content

pco/g5p: compile Google Maps' vertex shaders under bank-1 register pressure - #51

Draft
brkosebay wants to merge 3 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-vertex-pressure
Draft

brkosebay wants to merge 3 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-vertex-pressure

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Draft: the series is in the Mesa the iPad 5 runs, but nobody has yet checked on the device that Google Maps draws with it. It gets marked ready after that check.

Google Maps (WebGL through Zink) refused about 3,000 draws in 30 s on the A9. Its vertex shaders sample textures, and the coupled vertex sample needs a 4-dword run in bank 1 while bank 1 is full of attributes held for later reads: "qualified vertex texture result needs 4 dword(s), 30 of 32 in use". Three steps, each used only after the previous attempts have refused:

  1. Relieve bank-1 pressure: release dying texture sources before allocating the result. Evict arbitrary contiguous bank-1 runs to bank 0 on demand. Allow control flow in the eviction retry by keeping outputs in bank 0 until vout.
  2. Lend bank-1 registers in the last vertex retry: the held values move to bank 0 for that one instruction and back afterwards, so this is valid at any control-flow depth.
  3. Run the whole pressure ladder again with eviction, because the pressure-driven order (bank 0 nearly empty) never evicted, and the eviction retry's own order filled bank 0.

Programs that compile in an earlier attempt are unaffected: the same code, byte for byte. Offline, on a corpus of captured shaders (the Maps capture plus Dolphin, PPSSPP and racing-game captures), Maps goes from 51 admitted + 1 refused to all 52 admitted, the other 51 keep their code hashes, and every other corpus is identical line for line. A vertex shader that still refuses costs one more ladder run at pipeline creation.

Built on this head (Vulkan imagination with asserts on); the G5P meson host tests pass, 9/9.

How to test

On a stock Orchard install with Mesa built from this branch:

PVR_DEBUG=errors firefox https://www.google.com/maps 2>&1 | grep -c 'register pressure'   # 0
glmark2-es2-wayland -b build:duration=10 -b texture:duration=10   # unchanged

Expected on the iPad 5: Maps draws its vector map with no register-pressure refusals. A10: unchanged, because this is the G5P vertex compiler.

…ures

Google Maps WebGL vertex shaders with vertex texture fetches hit bank-1
register pressure ("qualified vertex texture result needs 4 dword(s), 30
of 32 in use") because dying texture inputs remained live across the
result allocation, output-feeding values and addressed buffer loads
occupied bank 1, and bank-1 eviction only checked 8-aligned runs on
straight-line shaders.

- Release dying SSA texture sources in emit_vertex_qualified_texture()
  before allocating the 4-dword bank-1 result run (all operands are
  already copied into the recipe's bank-1 scratch).
- Generalise bank-1 -> bank-0 eviction (evict_vertex_bank1_n()) to
  evict arbitrary contiguous runs on demand inside alloc_run() and
  address-pair loops at cf_depth 0, skipping decl_reg homes.
- Allow control flow in the vs_evict pressure retry: keep output values
  and decl_out in bank 0 (vs_out_reg() moves each into bank 1 at vout),
  park addressed UBO/SSBO load results in bank 0 after wait, and free a
  12-dword bank-1 window before entering top-level if/loop blocks.
- Release vs_out_reg() scratch after each eager vertex output.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…st vertex retry

Google Maps (WebGL through Zink) still refuses a vertex program with
"register pressure: qualified vertex texture result needs 4 dword(s),
30 of 32 in use" after cd1169a. The coupled vertex sample needs its
recipe (coordinates, level or derivatives, extras, the 4-dword result)
in bank 1, and the last vertex retry's eviction (evict_vertex_bank1_n())
cannot always make room: it never runs inside control flow (a move on
one path would leave the value in another register on the other), and
it never moves a decl's register.

In the last vertex retry (vs_evict) only, when a bank-1 run of the
recipe still cannot be allocated, lend the registers of the cheapest
run to the recipe for this instruction: each held value moves into a
free bank-0 register (the bank-1-to-bank-0 move eviction already
emits), and once the result has been parked in bank 0 it moves back
into its own bank-1 register (the bank-0-to-bank-1 move of
vertex_qualified_copy()). Every value ends the instruction in the
register it started in, so this is valid at any control-flow depth and
inside loops. The texture's own sources, the recipe's registers,
reserved and pending registers and busy registers without a value are
never lent, and a run is lent only when bank 0 keeps room for the
result's parked components, so no component stays in a lent register.
Programs that compile in an earlier retry are not affected.

Also report the eviction retry's own refusal after the ladder's, so a
program it still refuses names its reason.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Google Maps (WebGL through Zink) still refuses a vertex program after
ec5699f: "qualified vertex texture result needs 4 dword(s), 30 of 32
in use; bank-1 eviction retry: ... 26 of 32 in use".

The two attempts fail for opposite reasons. The ladder's last attempt
(the pressure-driven order) has bank 0 nearly empty, but bank 1 is full
of attributes held for later reads, and it never evicts. The eviction
retry evicts, but in the program's own order: by the qualified vertex
texture its evicted values fill all 32 bank-0 registers. Bank 1 then has
six free registers, none four in a row, and lending (vtex_lend_run())
has no bank-0 register to lend into.

When the eviction retry refuses too, go through the whole ladder once
more with eviction (and so lending) in every two-bank attempt: in the
program's own order and in the orders the scheduling retries make. In
the pressure-driven order the program fits, with eviction alone (the
captured program, 13062 bytes, 6 uploads). The eviction stays limited to
programs without stores, as in the eviction retry. No new encodings: it
emits the same moves the eviction retry already does.

This runs only after every existing attempt has refused, so a program
that compiles today keeps its bytes: offline replays of the Maps capture
(51 other programs) and of the dolphin-mkw, nfscrb, nfsu2, ppsspp and
selftest corpora give the same code hash before and after.

A refusal now also names the eviction ladder's reason, after the
eviction retry's.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
@henrikklee

Copy link
Copy Markdown
Contributor

Thanks @brkosebay, a careful fix for the Maps shaders. We're happy to merge once you've seen Maps draw with it on the iPad 5 (please post that and mark it ready).

One small request before then: two of the changes, freeing the texture read's dead inputs early and freeing scratch registers after each early vertex output, run whenever vs_bank0 is on, which is from the first attempt for vertex shaders with control flow. Could you gate both on the last-resort retry (vs_evict), so shaders that compile today keep exactly their code? (Or confirm with replays that they don't change.)

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