Skip to content

pvr/g5p: WebGPU on the A9: skip refused work, 4x MSAA with several colour targets, and the remaining gaps - #48

Open
brkosebay wants to merge 11 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-webgpu-passes
Open

brkosebay wants to merge 11 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-webgpu-passes

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

WebGPU in Firefox on the A9 brought the adapter and device up, then lost the device before the first frame (Device lost: Out of memory), even for helloTriangle. wgpu records a pass with two colour targets at 4 samples. G5P refused it, and on main one refused pass failed vkEndCommandBuffer with VK_ERROR_OUT_OF_HOST_MEMORY: skipping refused work had stayed driconf-only on the A9 when it was ported to main (on by default only on the A8).

This series:

  • Skips refused work by default on every G5P chip: passes, graphics and compute pipelines, draws, dispatches and vkCmdClearAttachments. Each is still named and logged (G5P_REFUSE, PVR_DEBUG=errors) instead of failing the command buffer. PVR_G5P_STRICT_DRAWS=1 (and PVR_A8_STRICT=1 on the A8) restores strict failure.
  • 4x MSAA with several colour targets, including store+resolve, so wgpu's pass is no longer refused at all.
  • The other gaps WebGPU hit: mixed two-word f16 MRT formats and depth/stencil with MRT; vertex-only (depth/stencil-only) pipelines; 4x passes with zero colour EOT surfaces; samplerless fragment texelFetch through the fetch sampler; image_deref_size in A9 compute; STORAGE_IMAGE for 8- and 16-bit integer formats.
  • Colour LOAD programs keep their own sampler (two Fixes: for the samplerless-fetch commit, which had changed the LOAD background programs).

Tested on the iPad 5 (j71t): this exact series is in the Mesa the device has run since 2026-12-03 (Firefox 161 with WebGPU enabled, daily sites, scroll benchmarks). Built on this head (Vulkan imagination with asserts on, and the Zink GL build); the G5P meson host tests pass, 9/9.

How to test

On a stock Orchard install with Mesa built from this branch, in Firefox with dom.webgpu.enabled=true and gfx.webgpu.ignore-blocklist=true set in about:config:

PVR_DEBUG=errors firefox https://webgpu.github.io/webgpu-samples/?sample=helloTriangleMSAA 2>&1 | grep -E 'G5P refuses|Device lost'
PVR_G5P_STRICT_DRAWS=1 firefox https://webgpu.github.io/webgpu-samples/?sample=rotatingCube   # A/B: old strict behaviour
vkcube --c 600                                                                                # unchanged

Expected on the iPad 5: the samples render and nothing prints Device lost. Anything still refused is named on stderr and skipped. A10: unchanged, because these are G5P paths and the A10 is G9P. The g9p/g9p_a9_* headers touched here are the A9's own compute path.

The port of 57654c67d9e and 65c0a5ba355 to main (7f5c0a1 and
3b559c1) gated skip_refused_work behind driconf on A9, while
778ab41 enabled it by default on A8 only. On A9, any single
unsupported render pass or draw returned VK_ERROR_OUT_OF_HOST_MEMORY
from vkEndCommandBuffer(), causing wgpu/Firefox WebGPU to lose the
device at startup.

Enable skip_refused_work by default across all G5P chips so refused
passes, graphics pipelines, draws and vkCmdClearAttachments calls remain
named and logged via G5P_REFUSE and are skipped instead of failing the
command buffer or device. PVR_G5P_STRICT_DRAWS=1 (and PVR_A8_STRICT=1 on
A8) restores strict failure.

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

When skip_refused_work is enabled, a refused non-internal compute
pipeline is admitted without a shader BO (matching graphics pipelines)
and its dispatches are named via G5P_REFUSE and skipped instead of
failing the command buffer or losing the WebGPU device.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Support 4x multisampled render passes with 1 to 4 colour targets where
each logical target is stored, resolved via the PBE (into either a
linear mip-0 view or a twiddled 2D single-layer view), or both stored
and resolved in one end-of-tile pass (StoreAndMultisampleResolve, in
either VkRenderPass [resolve, store] or dynamic-rendering [store,
resolve] eot_surfaces order).

- Decompose 4x eot_surfaces by mrt_idx via pvr_arch_g5p_msaa_build_plan()
  and count logical colour outputs via pvr_arch_g5p_colour_outputs() in
  pvr_arch_g5p_mrt.c, pvr_arch_g5p_ds.c, pvr_arch_g5p_gfx.c, and
  pvr_arch_g5p.c.
- Generalise 4x EOT USC emission to pvr_g5p_msaa_eot_usc_mask() for 1..8
  PBE emits with per-entry store (1c 09) vs resolve (1c 05) sample mode
  and per-entry output-half offsets (g5p_mrt_pbe_block_offsets()),
  cached lazily per (emits, store_mask). Verified byte-identical against
  Apple's A9 builtin compiler across 14 cases (1..4 targets, store,
  resolve, mixed, and StoreAndMultisampleResolve up to 8 emits).
- Upload sample-rate clear kicks for 1, 2, and 4 logical targets
  (clear_kick_ms[0..2]; clear USC bytes are identical at 1x and 4x) and
  enable 4x vkCmdClearAttachments clear quads.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Accept graphics pipelines with only VK_SHADER_STAGE_VERTEX_BIT (no
fragment shader), as used by WebGPU shadow-map and depth pre-passes
(e.g. shadowMapping).

When no fragment stage is present, blend state is ignored, write_mask is
forced to 0, and the minimal fragment stub is compiled with
write_mask = 0 so the backend emits the empty no-colour program (0
varyings, 0 uploads) and ISP uses Apple's no-colour depth/stencil form
(tag_write_disable = 1, upass = 0).

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

Apple's A9 compiler emits the same two-word packed-f16 per-target output
(four f16 halves at output half 4t) for BGRA8, RGBA8, sRGB, RGB10A2,
RGBA16F, R8, RG8, R16F, RG16F and RG11B10F, with each target packed by
its own PBE state word (gles3-tex.md §1.2; gles3-continued107.md §0.3).
pvr_arch_g5p.c already encodes each target's PBE state independently
from its own format, and ZLS depth/stencil registers are orthogonal to
colour target count.

- Allow any combination of two-word f16-output renderable colour formats
  (including VK_FORMAT_R16G16B16A16_SFLOAT + VK_FORMAT_B8G8R8A8_UNORM,
  as used by WebGPU deferredRendering's G-buffer) for 2 to 4 colour
  targets in pvr_arch_g5p_mrt.c; keep 5..8 compact UNORM8 targets
  homogeneous BGRA8/RGBA8 and raw32 pairs unchanged.
- Store the padding fourth target of a 3-target pass as 16x16 R8_UNORM
  so 8-byte targets (RGBA16F) do not overflow the 1024-byte null_rt.
- Remove the multi-target refusal in pvr_arch_g5p_ds_admit() so MRT
  passes with a depth/stencil attachment (G-buffers) run.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
WebGPU shaders use separate VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE bindings
with textureLoad() (nir_texop_txf) and no sampler. Previously, only
qualified vertex programs emitted PCO_G5P_UPLOAD_FETCH_SAMPLER; fragment
programs emitted PCO_G5P_UPLOAD_SAMPLER referencing the texture binding
at +32 bytes, reading past the 32-byte image descriptor and failing with
"set 0 binding 2: a sampler without A9 words" (deferredRendering).

- Emit PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf reads
  on A9 (at each texture's sampler slot in non-compact layout, or shared
  at fetch_sampler_common in compact layout).
- Handle PCO_G5P_UPLOAD_FETCH_SAMPLER in pvr_arch_g5p_gfx.c (supplying
  pvr_g5p_fetch_sampler_word() on A9 and pvr_g5p_a8_fetch_sampler() on
  A8), and synthesize the A8 fetch sampler for standalone SAMPLED_IMAGE
  descriptors under PCO_G5P_UPLOAD_SAMPLER_FETCH.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
A 4x depth/stencil-only (or colour-store-dont-care) render pass has
eot_surface_count == 0 and was refused by pvr_arch_g5p_msaa_admit()
("4x with 0 end-of-tile surfaces"), hitting Babylon.js WebGPU scenes and
4x depth-only clears.

Mirror the 1x null_target path in g5p_job_init(): admit 4x passes with
zero colour EOT surfaces and resolve a single 16x16 BGRA8 dummy target
into the existing 1024-byte 64-byte-aligned null_rt using the
hardware-proven msaa4-resolve pass shape (sample-rate clear kick,
1-emit resolve EOT 1c 05, PBE resolve bit, PVR_G5P_MSAA_FLAG_RESOLVE)
alongside 4x ZLS depth/stencil.

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

WebGPU compute shaders that query textureDimensions() on a storage image
(e.g. webgpu-samples particles/probabilityMap.wgsl::export_level) emit
nir_intrinsic_image_deref_size, which the A9 compute backend did not
handle. In addition, G9P_A9_UP_SIZE was hardcoded to common dwords 40/44
and g9p_a9_compile_compute() unconditionally refused any size query when
a storage image occupied common 40..47.

Implement a9_image_size() reusing G9P_A9_UP_SIZE (pvr_g5p_image_size()
already reads the A9 image state at offset 0 of storage descriptors),
pre-scan storage and sampled image counts in a9_generate_init() so
size blocks are placed in unused 4-dword common slots (40/44 when no
storage images exist, else 32/36 and/or 48/52), and replace the blanket
sizes+num_textures refusal with an exact common-store overlap check.
Also surface the backend refusal reason in vk_errorf() and give
bind_code room for storage images combined with uploads and fences.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Commits 5eb2d3f ("pvr/g9p: A9 image stores of 8- and 16-bit integer
formats") and 000b849 ("pvr/g9p: A9 image loads of 8- and 16-bit
integer formats") implemented and proved A9 compute storage image loads
and stores for R8/RG8/RGBA8 and R16/RG16/RGBA16 UINT/SINT on S8003,
but pvr_g5p_format_table.h did not yet set PVR_G5P_FMT_STORAGE on those
rows. As a result, pvr_get_image_format_properties() returned
VK_ERROR_FORMAT_NOT_SUPPORTED when WebGPU probed core storage texture
formats rgba8uint, rgba8sint, rgba16uint, and rgba16sint at device
creation.

Set PVR_G5P_FMT_STORAGE on the 12 proven 8- and 16-bit integer rows;
unimplemented storage formats (rgba8snorm, rg32uint/sint/float) remain
unadvertised.

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

Commit 5c997f1 switched samplerless fragment nir_texop_txf to emit
PCO_G5P_UPLOAD_FETCH_SAMPLER (kind 9). The internal colour LOAD programs
(pvr_g5p_compile_load*()) also use samplerless txf and therefore emit
PCO_G5P_UPLOAD_FETCH_SAMPLER, which g5p_upload_load() in pvr_arch_g5p.c
did not recognise, causing every colour LOAD pass to be refused.

Accept PCO_G5P_UPLOAD_FETCH_SAMPLER in g5p_upload_load() and supply
pvr_g5p_fetch_sampler_word() at +16 in g5p_load_background()'s sampler
upload buffer. Also name PCO_G5P_UPLOAD_FETCH_SAMPLER in
g5p_up_kind_str().

Fixes: bf7c56d ("pvr/g5p: use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf")
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Commit 5c997f1 moved every A9 fragment nir_texop_txf to the shared
PCO_G5P_UPLOAD_FETCH_SAMPLER (kind 9). The driver's colour LOAD
background programs (g5p_compile_load_type() and
pvr_g5p_compile_load_mrt()) read the attachment with a samplerless txf
as well, so they changed layout and emitted kind 9, which
g5p_upload_load() refused ("a load program upload of kind 9"): every
pass that LOADs a colour attachment was refused (Firefox's WebRender UI
corrupted, Google Maps blank).

Add pco_g5p_fs_key.txf_own_sampler and set it for those programs. With
it plan_common() keeps the pre-5c997f12743 layout (one
PCO_G5P_UPLOAD_SAMPLER slot per texture, no fetch sampler, the texel
read's sampler qword at the texture's own slot), so the LOAD programs
and g5p_load_background()'s nearest/clamped sampler are byte-identical
to before. The 4x LOAD (pvr_g5p_compile_load_ms()) samples with a
sampler and is unaffected.

The other internal programs: the clear quad reads push constants only;
vk_meta pipelines go through g5p_pipeline_build() and fs_uploads(),
which take kind 9 since 5c997f1; compute uses the G9P uploads.

Fixes: bf7c56d ("pvr/g5p: use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf")
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
@brkosebay

Copy link
Copy Markdown
Contributor Author

Note on the commit messages: 5c997f12743 in the two colour LOAD commits is this series' bf7c56d ("use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf"); their Fixes: trailers already name bf7c56d. 57654c67d9e and 65c0a5ba355 in the first commit are the original skip-refused commits on our older A9 development line, which main carries as 7f5c0a1 and 3b559c1.

@jeroentrappers

Copy link
Copy Markdown
Contributor

A related A9 compute bug that this PR's image_deref_size support exposes, plus a fix on top of this branch.

The bug: a null storage image descriptor is all zeroes, and the A9 compute image access has no bounds check of its own. So robustness2 null_descriptor compute cases write at 0 + texel offset and fault the GPU MMU (PBE0_TEXAS* write page-invalid at 0xfc80, 0x3ffe40). That's a lost device.

Two commits on top of this branch: jeroentrappers/orchard-mesa g5p-null-image-guard:

  1. pvr/g5p: the size of a null storage image is 0 in A9 compute: with this branch, G9P_A9_UP_SIZE on a null descriptor refuses the dispatch ("an image size without A9 texture state"). An all-zero descriptor now uploads size 0 instead, which is what imageSize() must return for a null descriptor.
  2. pvr/g9p: bounds-check A9 storage image loads and stores: a NIR pass before a9_pack_image_store checks each storage image access's coordinates against nir_image_deref_size, i.e. your a9_image_size().
    • Stores: an if around the store alone.
    • Loads: branchless (texel 0, result bcsel to 0), to stay clear of emit_select()'s hazard.
    • Cube arrays: checked too, because a null descriptor can stand in for one; with commit 1 alone, that case went from Fail to a fault.

On an iPhone 6s, this branch against this branch plus the two commits:

  • Vulkan slices with storage image tests: four null_descriptor cases go from Crash/Fail to Pass, with no new device loss and no other change.
  • Device losses already on this branch: 14 in one slice, from renderpass cases (unused_clear_attachments, attachment.1.75, random.seed0, self_dep_clear_draw_ms). They're unchanged by the commits. Happy to share logs if that's useful.
  • The GLES3.1 image load/store slice: identical.

One cost to weigh: every guarded storage image binding now takes a size upload slot, so a shader near the A9's slot limits could start being refused. I didn't see that in the CTS, but you know the slot budget better.

Would you rather fold these into this PR, or should I open a PR on top once it merges?

@henrikklee

Copy link
Copy Markdown
Contributor

Thank you @brkosebay. WebGPU on the A9 going from "device lost" to rendering is a big step. We'd like to merge this. One check first: @jeroentrappers saw 14 lost devices in render-pass CTS groups on this branch (one 4x: self_dep_clear_draw_ms), but without a comparison against main. Since this PR newly lets 4x/multi-target passes through that used to be refused, we need to know those losses aren't new.

Could one of you run those render-pass groups on an A9 with main's Mesa and with this branch, and post both counts? If the branch adds no new lost devices, we merge right away.

Optional, not required: fold 21daf4e into bf7c56d (so no commit in between breaks LOAD of colour attachments) and drop d95c0cb.

@jeroentrappers

Copy link
Copy Markdown
Contributor

Counts, as asked. Main is 58db632, this branch is 21daf4e, on an iPhone 6s (A9) at 340 MHz. The case list is one 1000-case slice of a 1-in-200 sample of the Vulkan CTS: 90 cases run, mostly render passes and robustness2.

Mesa Lost devices (3 runs) Pass / Fail / Crash
main 0, 0 29 / 51 / 10
this branch 14, 16, 13 42 / 41 / 7

So they are new with this branch. Two separate causes:

1. A bug that is already on main, exposed by skipping refused work by default (fragment job never finishes).

  • Where: the input-attachment render-pass cases with a DONT_CARE store, e.g. renderpass1.*.formats.r32g32_sint.input.dont_care.dont_care.self_dep_draw.
  • What happens: the subpass that reads the attachment is refused (image_deref_load). The skipped pass then still runs its first subpass's draw.
  • Why it hangs: that draw writes a colour attachment that isn't stored, so it has no end-of-tile target. g5p_mrt_draw_check() counts 1 target on each side, so the output goes through the other attachment's end-of-tile setup.
  • When: with R32 or R32G32 formats the fragment job never finishes (no fault, just a timeout). Main does the same with pvr_skip_refused_work=true: 6 of 54 formats hang there.
  • Fix: pvr/g5p: refuse a draw into a colour attachment that is not stored #57 (jeroentrappers/orchard-mesa g5p-unstored-colour), one commit, rebased on current main (tested on 58db632). It refuses a draw unless every colour attachment of the subpass is an end-of-tile target (or resolves into one). Two exceptions, each kept because a version without it cost passes:
    • the driver's own vkCmdClearAttachments quads;
    • renders with no end-of-tile target at all, such as occlusion queries.
  • Tested: the full 10-slice sample on main with and without it gives identical results, and 0 lost devices. With skipping on, all the hanging cases now fail cleanly.

2. Texture-unit MMU faults that occur only on this branch.

  • Where: renderpass1.suballocation.formats.d32_sfloat_s8_uint.input.clear.store.clear_draw_use_input_aspect_stencil_read_only and its neighbours.
  • What happens: GPU MMU fault … read type=page-invalid requestor=8/MCU_TEXAS0 at addresses inside an attachment's range. The kernel then refuses that context's later submits (SUBMIT_JOBS errno=5), which is most of the lost-device lines.
  • On main: with pvr_skip_refused_work=true on the same slice, main has 0 faults and 0 resets. So this comes from this branch's own changes.
  • Possible lead: a stricter version of the fix above, which also refused the driver's clear quads into unstored attachments, halved these. So it may involve this branch's clear or LOAD changes.
  • Not reproduced alone: run on its own, the d32 case passes cleanly. It needs the cases before it in the batch.
Mesa Lost devices
this branch 14
this branch + the fix 12 (2 runs)
main + the fix, skipping on 0

Happy to share the logs or run anything you'd like on the A9.

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.

3 participants