From 13eb92547c662702e900b1d1c37acfb6fd05c252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 22:16:06 +0100 Subject: [PATCH 01/11] pvr/g5p: skip refused passes, pipelines and draws by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The port of 57654c67d9e and 65c0a5ba355 to main (7f5c0a15a03 and 3b559c10cd9) gated skip_refused_work behind driconf on A9, while 778ab412695 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 --- src/imagination/vulkan/pvr_g5p_hooks.h | 5 +++-- src/imagination/vulkan/pvr_physical_device.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/imagination/vulkan/pvr_g5p_hooks.h b/src/imagination/vulkan/pvr_g5p_hooks.h index ca09f93c78b..921452edf77 100644 --- a/src/imagination/vulkan/pvr_g5p_hooks.h +++ b/src/imagination/vulkan/pvr_g5p_hooks.h @@ -308,8 +308,9 @@ #define PVR_G5P_HOOK_clear_attachments(cmd_buffer, count, attachments, rect_count, rects) \ if (PVR_HAS_FEATURE(&(cmd_buffer)->device->pdevice->dev_info, apple_g5p)) { \ VkResult r_ = pvr_arch_g5p_clear_attachments(cmd_buffer, count, attachments, rect_count, rects); \ - if (r_ != VK_SUCCESS) \ - pvr_cmd_buffer_set_error_unwarned(cmd_buffer, pvr_refusal_to_api(r_)); \ + if (r_ != VK_SUCCESS && \ + !(r_ == VK_ERROR_FEATURE_NOT_PRESENT && (cmd_buffer)->device->pdevice->skip_refused_work)) \ + pvr_cmd_buffer_set_error_unwarned(cmd_buffer, pvr_refusal_to_api(r_)); \ return; \ } diff --git a/src/imagination/vulkan/pvr_physical_device.c b/src/imagination/vulkan/pvr_physical_device.c index d63073999f5..3e8747d6c34 100644 --- a/src/imagination/vulkan/pvr_physical_device.c +++ b/src/imagination/vulkan/pvr_physical_device.c @@ -1451,13 +1451,16 @@ VkResult pvr_physical_device_init(struct pvr_physical_device *pdevice, g5p_usc_g4p_cube_slots = g5p_usc_g4p_cube_alu && debug_get_bool_option("PVR_A8_CUBE_SLOTS", true); } - /* The A8 skips refused work by default: a refused program or pass loses its draws (named on stderr) instead of - * failing the command buffer, which Zink turns into a lost context for the whole application. PVR_A8_STRICT=1 - * restores the failure. */ + /* G5P skips refused work by default: a refused program, pass, or draw is + * named on stderr and skipped instead of failing the command buffer, which + * Zink and wgpu turn into a lost context or device. PVR_G5P_STRICT_DRAWS=1 + * (or PVR_A8_STRICT=1 on A8) restores the failure unless driconf enables + * pvr_skip_refused_work. */ + const bool strict = debug_get_bool_option("PVR_G5P_STRICT_DRAWS", false) || + (PVR_HAS_FEATURE(&pdevice->dev_info, apple_g4p) && + debug_get_bool_option("PVR_A8_STRICT", false)); pdevice->skip_refused_work = PVR_HAS_FEATURE(&pdevice->dev_info, apple_g5p) && - (instance->drirc.misc.pvr_skip_refused_work || - (PVR_HAS_FEATURE(&pdevice->dev_info, apple_g4p) && - !debug_get_bool_option("PVR_A8_STRICT", false))); + (instance->drirc.misc.pvr_skip_refused_work || !strict); pdevice->sync_type = ws->syncobj_type; if (ws->job_sync_size) { From 41404e34cc756572d341622b36bf30fafd93ac2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 22:16:06 +0100 Subject: [PATCH 02/11] pvr/g5p: skip refused compute pipelines and dispatches under skip_refused_work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/vulkan/pvr_arch_g5p_compute.c | 9 +++++++++ src/imagination/vulkan/pvr_g5p_compute_hooks.h | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/imagination/vulkan/pvr_arch_g5p_compute.c b/src/imagination/vulkan/pvr_arch_g5p_compute.c index 3da2046451b..7a3adb426e2 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_compute.c +++ b/src/imagination/vulkan/pvr_arch_g5p_compute.c @@ -205,6 +205,12 @@ PVR_PER_ARCH(g5p_compute_pipeline_compile)( out: ralloc_free(mem_ctx); + if (result == VK_ERROR_FEATURE_NOT_PRESENT && !pvr_g5p_internal_pipeline && + device->pdevice->skip_refused_work) { + mesa_logw("pvr/g5p: compute pipeline admitted without program after a compile refusal"); + state->shader_bo = NULL; + return VK_SUCCESS; + } return pvr_refusal_to_api(result); } @@ -348,6 +354,9 @@ PVR_PER_ARCH(g5p_cmd_dispatch)(struct pvr_cmd_buffer *cmd_buffer, if (PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g3)) return pvr_refusal_to_api(pvr_arch_g3_cmd_dispatch(cmd_buffer, sub_cmd, indirect_va, base_group, group_count)); + if (!state->shader_bo) + return G5P_REFUSE(cmd_buffer, + "a dispatch of a compute pipeline without a G5P program (refused at creation, named there)"); if (state->a9_compute_log) { result = g5p_record_dispatch(cmd_buffer, sub_cmd, indirect_va, indirect_offset, group_count); if (result != VK_SUCCESS) return result; diff --git a/src/imagination/vulkan/pvr_g5p_compute_hooks.h b/src/imagination/vulkan/pvr_g5p_compute_hooks.h index 8d7a613928f..37ebf77cd40 100644 --- a/src/imagination/vulkan/pvr_g5p_compute_hooks.h +++ b/src/imagination/vulkan/pvr_g5p_compute_hooks.h @@ -26,7 +26,9 @@ #define PVR_G5P_HOOK_compute_dispatch() \ if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g5p)) { \ result = pvr_arch_g5p_cmd_dispatch(cmd_buffer, sub_cmd, indirect_addr.addr, indirect_offset, base_group, workgroup_size); \ - if (result != VK_SUCCESS) pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result); \ + if (result != VK_SUCCESS && \ + !(result == VK_ERROR_FEATURE_NOT_PRESENT && cmd_buffer->device->pdevice->skip_refused_work)) \ + pvr_cmd_buffer_set_error_unwarned(cmd_buffer, pvr_refusal_to_api(result)); \ goto end_cmd_dispatch; \ } #define PVR_G5P_HOOK_compute_end_pass() \ From 276c5c853fa0da44a274233ffeeec48b50cc532c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 22:26:19 +0100 Subject: [PATCH 03/11] pvr/g5p: support 4x MSAA with multiple colour targets and store+resolve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/g5p/g5p_mrt_programs.h | 12 +- src/imagination/vulkan/pvr_arch_g5p.c | 180 +++++++++++++++++---- src/imagination/vulkan/pvr_arch_g5p_ds.c | 5 +- src/imagination/vulkan/pvr_arch_g5p_gfx.c | 23 +-- src/imagination/vulkan/pvr_arch_g5p_mrt.c | 57 +++++-- src/imagination/vulkan/pvr_arch_g5p_msaa.c | 134 +++++++++++---- src/imagination/vulkan/pvr_g5p.h | 18 ++- src/imagination/vulkan/pvr_g5p_msaa.c | 27 +++- src/imagination/vulkan/pvr_g5p_msaa.h | 36 ++++- 9 files changed, 386 insertions(+), 106 deletions(-) diff --git a/src/imagination/g5p/g5p_mrt_programs.h b/src/imagination/g5p/g5p_mrt_programs.h index c328dfd0c28..9c71f9050c1 100644 --- a/src/imagination/g5p/g5p_mrt_programs.h +++ b/src/imagination/g5p/g5p_mrt_programs.h @@ -87,7 +87,8 @@ static inline uint32_t g5p_mrt_restore1(unsigned n) * halves: output halves per target, 4 for an 8-bit RGBA target (two packed * f16x2 dwords), 8 for a 32-bit integer target of the raw32 output (four * raw words, so target 1 starts at output dword 4). */ -static inline unsigned g5p_mrt_pbe_block_halves(uint32_t *out, unsigned n, const uint64_t pbe[][3], unsigned halves) +static inline unsigned g5p_mrt_pbe_block_offsets(uint32_t *out, unsigned n, const uint64_t pbe[][3], + const uint32_t *halves) { for (unsigned t = 0; t < n; t++) { uint32_t *w = out + G5P_MRT_PBE_STRIDE * t; @@ -95,12 +96,19 @@ static inline unsigned g5p_mrt_pbe_block_halves(uint32_t *out, unsigned n, const w[2 * q] = (uint32_t)pbe[t][q]; w[2 * q + 1] = (uint32_t)(pbe[t][q] >> 32); } - w[6] = halves * t; + w[6] = halves[t]; if (t + 1 < n) w[7] = 0xffffffff; } return g5p_mrt_pbe_dwords(n); } +static inline unsigned g5p_mrt_pbe_block_halves(uint32_t *out, unsigned n, const uint64_t pbe[][3], unsigned halves) +{ + uint32_t offs[G5P_MRT_MAX]; + for (unsigned t = 0; t < n; t++) + offs[t] = halves * t; + return g5p_mrt_pbe_block_offsets(out, n, pbe, offs); +} static inline unsigned g5p_mrt_pbe_block(uint32_t *out, unsigned n, const uint64_t pbe[][3]) { return g5p_mrt_pbe_block_halves(out, n, pbe, 4); diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index d1e87eb764d..c15a01c892f 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -276,8 +276,10 @@ g5p_free_programs(struct pvr_device *device, struct pvr_g5p_programs *p) pvr_bo_suballoc_free(p->null_rt); pvr_bo_suballoc_free(p->scissor_pool); pvr_bo_suballoc_free(p->dbias_pool); - pvr_bo_suballoc_free(p->eot_usc_ms); - pvr_bo_suballoc_free(p->clear_kick_ms.pvr_bo); + for (unsigned i = 0; i < p->eot_ms_count; i++) + pvr_bo_suballoc_free(p->eot_ms[i].usc); + for (unsigned i = 0; i < ARRAY_SIZE(p->clear_kick_ms); i++) + pvr_bo_suballoc_free(p->clear_kick_ms[i].pvr_bo); pvr_bo_suballoc_free(p->load_usc); pvr_bo_suballoc_free(p->load_kick.pvr_bo); pvr_bo_suballoc_free(p->load_dma.pvr_bo); @@ -422,6 +424,46 @@ g5p_raw_programs(struct pvr_device *device, unsigned raw, unsigned words, unsign return result; } +static VkResult +g5p_msaa_eot_program(struct pvr_cmd_buffer *cmd_buffer, unsigned emits, uint8_t store_mask, + const struct pvr_suballoc_bo **out) +{ + struct pvr_device *device = cmd_buffer->device; + struct pvr_g5p_programs *p = &device->g5p->programs; + VkResult result = VK_SUCCESS; + + simple_mtx_lock(&device->g5p->clear_lock); + for (unsigned i = 0; i < p->eot_ms_count; i++) { + if (p->eot_ms[i].emits == emits && p->eot_ms[i].store_mask == store_mask) { + *out = p->eot_ms[i].usc; + simple_mtx_unlock(&device->g5p->clear_lock); + return VK_SUCCESS; + } + } + if (p->eot_ms_count >= ARRAY_SIZE(p->eot_ms)) { + simple_mtx_unlock(&device->g5p->clear_lock); + return G5P_REFUSE(cmd_buffer, "more than %u distinct 4x end-of-tile emit masks", + (unsigned)ARRAY_SIZE(p->eot_ms)); + } + uint8_t code[G5P_MRT_EOT_USC_MAX]; + const unsigned size = pvr_g5p_msaa_eot_usc_mask(code, emits, store_mask); + if (!size) { + simple_mtx_unlock(&device->g5p->clear_lock); + return G5P_REFUSE(cmd_buffer, "4x end-of-tile program for %u emits (mask %#x)", emits, store_mask); + } + struct pvr_suballoc_bo *usc = NULL; + result = pvr_gpu_upload_usc(device, code, size, 64, &usc); + if (result == VK_SUCCESS) { + p->eot_ms[p->eot_ms_count].emits = (uint8_t)emits; + p->eot_ms[p->eot_ms_count].store_mask = store_mask; + p->eot_ms[p->eot_ms_count].usc = usc; + p->eot_ms_count++; + *out = usc; + } + simple_mtx_unlock(&device->g5p->clear_lock); + return result; +} + static VkResult g5p_upload_programs(struct pvr_device *device, struct pvr_g5p_programs *p) { @@ -545,17 +587,15 @@ g5p_upload_programs(struct pvr_device *device, struct pvr_g5p_programs *p) if (result != VK_SUCCESS) return result; } - /* 4x (one target): the multisample store's end of tile, and the clear's - * kick at sample rate */ + /* 4x (1, 2 and 4 logical targets): sample-rate kicks of clear_usc[0..2]; + * the per-(emits, store_mask) 4x end-of-tile USC programs are uploaded + * lazily by g5p_msaa_eot_program(). */ if (!g4p) { - uint8_t code[G5P_MRT_EOT_USC_MAX]; - const unsigned size = pvr_g5p_msaa_eot_usc(code); - result = pvr_gpu_upload_usc(device, code, size, 64, &p->eot_usc_ms); - if (result != VK_SUCCESS) - return result; - result = g5p_upload_kick(device, p->clear_usc[0], 4, &p->clear_kick_ms); - if (result != VK_SUCCESS) - return result; + for (unsigned i = 0; i < ARRAY_SIZE(p->clear_kick_ms); i++) { + result = g5p_upload_kick(device, p->clear_usc[i], 4, &p->clear_kick_ms[i]); + if (result != VK_SUCCESS) + return result; + } } uint32_t pds[8]; @@ -987,7 +1027,7 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd * Apple's own depth-only pass is not captured (bench-gaps.md section 6.5); this takes only the forms the * one-target pass already runs. */ const bool null_target = hw_render->eot_surface_count == 0; - const unsigned n = null_target ? 1 : hw_render->eot_surface_count; + const unsigned n = null_target ? 1 : pvr_arch_g5p_colour_outputs(hw_render); unsigned v; memset(g, 0, sizeof(*g)); @@ -1024,6 +1064,9 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd g->samples = MAX2(hw_render->sample_count, 1); if (null_target && g->samples != 1) return G5P_REFUSE(cmd_buffer, "a %u-sample render without colour attachments", g->samples); + struct pvr_g5p_msaa_plan ms_plan = { 0 }; + if (!null_target && g->samples == 4 && !pvr_arch_g5p_msaa_build_plan(hw_render, &ms_plan)) + return G5P_REFUSE(cmd_buffer, "4x render pass surface layout"); /* the render's depth-bias table (upstream's, uploaded before this hook): * the kernel takes its entries from ISP_DBIAS_BASE */ if (sub_cmd->depth_bias_bo) @@ -1055,9 +1098,12 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd /* targets: PBE words and clear colours */ uint64_t pbe[G5P_MRT_MAX][3]; + uint32_t ms_pbe_halves[G5P_MRT_MAX] = { 0 }; + unsigned ms_emits = 0; + uint8_t ms_store_mask = 0; unsigned raw = 0; const VkFormat first_format = null_target ? VK_FORMAT_UNDEFINED - : info->attachments[hw_render->eot_surfaces[0].attachment_idx]->vk.format; + : info->attachments[g->samples == 4 ? ms_plan.color_att[0] : hw_render->eot_surfaces[0].attachment_idx]->vk.format; /* 32-bit integer targets (R, RG, RGBA; unsigned 1, signed 2): the four-word raw program, the PBE storing the * target's channels (pvr_g5p_raw32_kind()); RGBA16UI clears: five (below) */ raw = pvr_g5p_raw32_kind(first_format); @@ -1121,7 +1167,60 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd } uint64_t target0_addr = 0; /* the A8's end of tile takes the target's address (below) */ bool a8_load_twiddled = false; /* the A8's LOAD samples a twiddled target only (Apple's capture) */ - for (unsigned t = 0; t < n && !null_target; t++) { + if (g->samples == 4 && !null_target) { + /* 4x pass (1..4 logical targets): build PBE entries in Apple's order + * (for each logical target t: store slot t first if present, then + * resolve slot 8 + t if present, both reading output half 4t). */ + const struct pvr_image_view *v0 = info->attachments[ms_plan.color_att[0]]; + g->width = v0->vk.extent.width; + g->height = v0->vk.extent.height; + for (unsigned t = 0; t < ms_plan.outputs; t++) { + if (ms_plan.store_idx[t] >= 0) { + const struct pvr_image_view *iview = + info->attachments[hw_render->eot_surfaces[ms_plan.store_idx[t]].attachment_idx]; + const struct pvr_image *image = pvr_image_view_get_image(iview); + const struct pvr_image_plane *plane = pvr_single_plane_const(image); + const struct pvr_mip_level *level = &plane->mip_levels[iview->vk.base_mip_level]; + const uint64_t addr = image->dev_addr.addr + plane->offset + level->offset + + iview->vk.base_array_layer * plane->layer_size; + uint32_t key; + bool srgb; + if (!g5p_pbe_key(iview->vk.format, &key, &srgb)) + return G5P_REFUSE(cmd_buffer, "4x colour target format %s", vk_Format_to_str(iview->vk.format)); + if (addr % 64) + return G5P_REFUSE(cmd_buffer, "a 4x colour target at %#" PRIx64 " (64-byte base)", addr); + pvr_g5p_msaa_pbe_store(pbe[ms_emits], key, addr, iview->vk.extent.width, iview->vk.extent.height, + vk_format_is_srgb(iview->vk.format)); + ms_pbe_halves[ms_emits] = 4 * t; + ms_store_mask |= (uint8_t)(1u << ms_emits); + ms_emits++; + } + if (ms_plan.resolve_idx[t] >= 0) { + const struct pvr_image_view *r = + info->attachments[hw_render->eot_surfaces[ms_plan.resolve_idx[t]].attachment_idx]; + const struct pvr_image *ri = pvr_image_view_get_image(r); + const struct pvr_image_plane *rplane = pvr_single_plane_const(ri); + const struct pvr_mip_level *rlevel = &rplane->mip_levels[r->vk.base_mip_level]; + const uint64_t raddr = ri->dev_addr.addr + rplane->offset + rlevel->offset + + r->vk.base_array_layer * rplane->layer_size; + const bool rtwiddled = ri->memlayout != PVR_MEMLAYOUT_LINEAR; + uint32_t key; + bool srgb; + if (!g5p_pbe_key(r->vk.format, &key, &srgb)) + return G5P_REFUSE(cmd_buffer, "resolve target format %s", vk_Format_to_str(r->vk.format)); + if ((rlevel->pitch % 16 && !rtwiddled) || raddr % 64) + return G5P_REFUSE(cmd_buffer, "a resolve target at %#" PRIx64 " with pitch %u (64-byte base, 16-byte rows)", + raddr, rlevel->pitch); + g5p_pbe_2d(pbe[ms_emits], key, srgb, raddr, r->vk.extent.width, r->vk.extent.height, rlevel->pitch, + rtwiddled); + pvr_g5p_msaa_pbe_resolve(pbe[ms_emits]); + ms_pbe_halves[ms_emits] = 4 * t; + g->msaa_resolve = true; + ms_emits++; + } + } + } + for (unsigned t = 0; t < n && !null_target && g->samples != 4; t++) { const struct pvr_image_view *iview = info->attachments[hw_render->eot_surfaces[t].attachment_idx]; const struct pvr_image *image = pvr_image_view_get_image(iview); const struct pvr_image_plane *plane = pvr_single_plane_const(image); @@ -1330,7 +1429,7 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd g->height = iview->vk.extent.height; } } - if (nt == 4 && n == 3) { + if (nt == 4 && n == 3 && g->samples != 4) { uint32_t key; bool srgb; if (!g5p_pbe_key(first_format, &key, &srgb)) @@ -1357,7 +1456,18 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd * only a later subpass of the same render reads, its store op not storing) has nothing to act on. Taken, * it ran the background LOAD / empty tiles against the null target, and the render hung. */ for (unsigned i = 0; i < (null_target ? 0 : hw_render->color_init_count); i++) { - const unsigned t = i; /* color_init follows the EOT surfaces' order */ + unsigned t = i; /* color_init follows the EOT surfaces' order */ + if (g->samples == 4) { + t = n; + for (unsigned k = 0; k < ms_plan.outputs; k++) { + if (ms_plan.color_att[k] == hw_render->color_init[i].index) { + t = k; + break; + } + } + if (t >= n) + continue; + } if (partial && !sub_cmd->barrier_load && hw_render->color_init[i].op == VK_ATTACHMENT_LOAD_OP_CLEAR) return G5P_REFUSE(cmd_buffer, "a CLEAR of colour attachment %u in a partial render area (%d,%d %ux%u of " "%ux%u): no clear of the area alone", t, area->offset.x, area->offset.y, @@ -1394,14 +1504,12 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd if (load && g->samples == 4) { /* Apple's 4x loader (an iOS capture of a 4x colour load): kicked at sample rate, each instance * samples the multisample surface at its own sample (pvr_g5p_compile_load_ms()), from the 4x texture - * state of that surface (pvr_g5p_msaa_tex_state()). One target (pvr_arch_g5p_msaa.c); integer targets - * are refused above at 4x. */ - const struct pvr_renderpass_hwsetup_eot_surface *eot = &hw_render->eot_surfaces[0]; - if (eot->need_resolve && (partial || sub_cmd->barrier_load)) + * state of that surface (pvr_g5p_msaa_tex_state()). One target (n > 1 LOAD refused above); integer + * targets are refused above at 4x. */ + if (ms_plan.store_idx[0] < 0 && (partial || sub_cmd->barrier_load)) return G5P_REFUSE(cmd_buffer, "a 4x %s with a resolve: the pass stores no samples to reload", partial ? "partial render area" : "VDM continuation"); - const struct pvr_image_view *src = info->attachments[eot->need_resolve ? eot->src_attachment_idx - : eot->attachment_idx]; + const struct pvr_image_view *src = info->attachments[ms_plan.color_att[0]]; const struct pvr_image *image = pvr_image_view_get_image(src); const struct pvr_image_plane *plane = pvr_single_plane_const(image); const uint64_t addr = image->dev_addr.addr + plane->offset; @@ -1459,9 +1567,12 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd } struct pvr_suballoc_bo *floats, *block; uint32_t pbe_words[G5P_MRT_PBE_STRIDE * G5P_MRT_MAX]; - /* each target's source: output half 4t (8-bit RGBA, two dwords), 8t (raw32, four words) */ - unsigned pbe_dwords = g5p_mrt_pbe_block_halves(pbe_words, nt, (const uint64_t(*)[3])pbe, - raw ? 2 * raw_words : compact ? 2 : 4); + /* each target's source: output half 4t (8-bit RGBA, two dwords), 8t (raw32, four words); + * 4x passes carry explicit per-entry offsets (store and resolve of target t both read 4t). */ + unsigned pbe_dwords = g->samples == 4 && !null_target + ? g5p_mrt_pbe_block_offsets(pbe_words, ms_emits, (const uint64_t(*)[3])pbe, ms_pbe_halves) + : g5p_mrt_pbe_block_halves(pbe_words, nt, (const uint64_t(*)[3])pbe, + raw ? 2 * raw_words : compact ? 2 : 4); if (PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g4p)) { /* * The A8's end of tile DMAs four dwords: the target's address and 2, 0 @@ -1510,8 +1621,15 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd return result; } { - /* a 4x store's end of tile emits per sample (pvr_g5p_msaa_eot_usc()); a resolve keeps the 1x one */ - const struct pvr_suballoc_bo *eot_usc = raw ? (narrow ? p->narrow_eot_usc : p->raw_eot_usc[n - 1]) : g->samples == 4 && !g->msaa_resolve ? p->eot_usc_ms : p->eot_usc[v]; + /* a 4x pass's end of tile sets sample mode per entry (1c 09 store, 1c 05 resolve) */ + const struct pvr_suballoc_bo *eot_usc = NULL; + if (g->samples == 4) { + result = g5p_msaa_eot_program(cmd_buffer, ms_emits, ms_store_mask, &eot_usc); + if (result != VK_SUCCESS) + return result; + } else { + eot_usc = raw ? (narrow ? p->narrow_eot_usc : p->raw_eot_usc[n - 1]) : p->eot_usc[v]; + } const uint64_t doutu = g5p_doutu_src0(g5p_usc_off(device, eot_usc), G5P_TEMPS); const uint32_t data[8] = { (uint32_t)block->dev_addr.addr, (uint32_t)(block->dev_addr.addr >> 32), g5p_doutd_control(pbe_dwords), 0, (uint32_t)doutu, (uint32_t)(doutu >> 32), @@ -1571,7 +1689,7 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd return result; } else { pvr_csb_pack (&bgnd[0], CR_PDS_BGRND0_BASE, b0) { - b0.shader_addr = PVR_DEV_ADDR(raw ? p->raw_clear_kick[g5p_raw_variant(raw_total)].data_offset : g->samples == 4 ? p->clear_kick_ms.data_offset + b0.shader_addr = PVR_DEV_ADDR(raw ? p->raw_clear_kick[g5p_raw_variant(raw_total)].data_offset : g->samples == 4 ? p->clear_kick_ms[v].data_offset : g->a8_narrow_halves ? p->clear_kick_narrow[g->a8_narrow_halves - 1].data_offset : a8_rgba8ui ? p->clear_kick_rgba8ui.data_offset : a8_r32f ? p->clear_kick_r32f.data_offset @@ -1610,7 +1728,9 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd memcpy(g->background, bgnd, sizeof(g->background)); g->eot[0] = eot_data.data_offset; g->eot[1] = p->eot.code_offset; - g->eot[2] = PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g4p) ? g5p_mrt_eot_info_g4p(nt) : g5p_mrt_eot_info(nt); + const unsigned eot_entries = g->samples == 4 && !null_target ? ms_emits : nt; + g->eot[2] = PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g4p) ? g5p_mrt_eot_info_g4p(eot_entries) + : g5p_mrt_eot_info(eot_entries); g->enabled = true; return VK_SUCCESS; } diff --git a/src/imagination/vulkan/pvr_arch_g5p_ds.c b/src/imagination/vulkan/pvr_arch_g5p_ds.c index 32a372a99e9..24a78bd81c8 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_ds.c +++ b/src/imagination/vulkan/pvr_arch_g5p_ds.c @@ -25,6 +25,7 @@ #include "pvr_device.h" #include "pvr_physical_device.h" #include "pvr_g5p_ds.h" +#include "pvr_g5p_msaa.h" #include "pvr_g5p_shader_dump.h" #include "pvr_g5p_tex_encode.h" #include "pvr_hw_pass.h" @@ -64,9 +65,9 @@ PVR_PER_ARCH(g5p_ds_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_r /* upstream's own test (pvr_arch_hw_pass.c): a resolve mode; the index is set only with one */ if (hw_render->depth_resolve_mode || hw_render->stencil_resolve_mode) return G5P_REFUSE(cmd_buffer, "a depth/stencil resolve (no capture)"); - if (hw_render->eot_surface_count > 1) + if (pvr_arch_g5p_colour_outputs(hw_render) > 1) return G5P_REFUSE(cmd_buffer, "depth/stencil beside %u colour targets (no capture of the combination)", - hw_render->eot_surface_count); + pvr_arch_g5p_colour_outputs(hw_render)); if (hw_render->eot_surface_count) { const struct pvr_image_view *c = info->attachments[hw_render->eot_surfaces[0].attachment_idx]; if (c->vk.extent.width != iview->vk.extent.width || c->vk.extent.height != iview->vk.extent.height) diff --git a/src/imagination/vulkan/pvr_arch_g5p_gfx.c b/src/imagination/vulkan/pvr_arch_g5p_gfx.c index 6fe858b5cc7..36bb283e052 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g5p_gfx.c @@ -528,10 +528,13 @@ g5p_check_state(struct pvr_device *device, const VkGraphicsPipelineCreateInfo *c /* pvr_* gives a render pass without multiview the view mask 1 */ if (s->mv && util_bitcount(s->mv->view_mask) > 1) return G5P_REFUSE(device, "multiview (view mask %#x)", s->mv->view_mask); - /* several colour targets: 2 or 4 in one format (pvr_g5p_mrt.h) */ + /* several colour targets: 2 or 4 in one format (pvr_g5p_mrt.h); 5..8 compact targets are 1x only */ if (colors > 1) { if (colors > PVR_G5P_MRT_MAX_COLORS) return G5P_REFUSE(device, "%u colour attachments (at most %u)", colors, PVR_G5P_MRT_MAX_COLORS); + if (colors > PVR_G5P_MSAA_MAX_TARGETS && s->ms && s->ms->rasterization_samples != VK_SAMPLE_COUNT_1_BIT) + return G5P_REFUSE(device, "%u colour attachments at %u samples (at most %u targets at 4 samples)", colors, + s->ms->rasterization_samples, PVR_G5P_MSAA_MAX_TARGETS); VkResult mrt = pvr_arch_g5p_mrt_pipeline_check(device, colors, cfs); if (mrt != VK_SUCCESS) return mrt; @@ -1621,7 +1624,7 @@ PVR_PER_ARCH(g5p_graphics_pipeline_compile)(struct pvr_device *device, * disabled, user pass 0: depth/stencil updates only, pvr_g5p_blend.h). The * depth/stencil tests and writes are the draw's dynamic state. */ static VkResult -g5p_clear_pipeline(struct pvr_cmd_buffer *cmd_buffer, VkFormat format, uint8_t write_mask, +g5p_clear_pipeline(struct pvr_cmd_buffer *cmd_buffer, VkFormat format, uint8_t write_mask, uint8_t samples, const struct pvr_graphics_pipeline **out) { struct pvr_device *device = cmd_buffer->device; @@ -1632,7 +1635,7 @@ g5p_clear_pipeline(struct pvr_cmd_buffer *cmd_buffer, VkFormat format, uint8_t w simple_mtx_lock(&gd->clear_lock); for (unsigned i = 0; i < gd->clear_count; i++) - if (gd->clear[i].format == format && gd->clear[i].write_mask == write_mask) + if (gd->clear[i].format == format && gd->clear[i].write_mask == write_mask && gd->clear[i].samples == samples) pipe = gd->clear[i].pipeline; if (pipe) goto done; @@ -1677,7 +1680,7 @@ g5p_clear_pipeline(struct pvr_cmd_buffer *cmd_buffer, VkFormat format, uint8_t w .cullMode = VK_CULL_MODE_NONE, .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, .lineWidth = 1.0f }; const VkPipelineMultisampleStateCreateInfo ms = { .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT }; + .rasterizationSamples = (VkSampleCountFlagBits)samples }; const VkPipelineColorBlendAttachmentState cba = { .colorWriteMask = write_mask }; const VkPipelineColorBlendStateCreateInfo cb = { .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, .attachmentCount = format != VK_FORMAT_UNDEFINED, @@ -1704,6 +1707,7 @@ g5p_clear_pipeline(struct pvr_cmd_buffer *cmd_buffer, VkFormat format, uint8_t w } gd->clear[gd->clear_count].format = format; gd->clear[gd->clear_count].write_mask = write_mask; + gd->clear[gd->clear_count].samples = samples; gd->clear[gd->clear_count++].pipeline = pipe; done: simple_mtx_unlock(&gd->clear_lock); @@ -1805,11 +1809,12 @@ PVR_PER_ARCH(g5p_clear_attachments)(struct pvr_cmd_buffer *cmd_buffer, uint32_t return G5P_REFUSE(cmd_buffer, "vkCmdClearAttachments outside a render pass"); const struct pvr_renderpass_hwsetup_render *hw_render = pvr_arch_pass_info_get_hw_render(info, info->current_hw_subpass); - if (hw_render->eot_surface_count > 1) + if (pvr_arch_g5p_colour_outputs(hw_render) > 1) return G5P_REFUSE(cmd_buffer, "vkCmdClearAttachments with %u colour targets (one is built)", - hw_render->eot_surface_count); - if (MAX2(hw_render->sample_count, 1) != 1) - return G5P_REFUSE(cmd_buffer, "vkCmdClearAttachments at %u samples (one is built)", hw_render->sample_count); + pvr_arch_g5p_colour_outputs(hw_render)); + const uint32_t samples = MAX2(hw_render->sample_count, 1); + if (samples != 1 && samples != 4) + return G5P_REFUSE(cmd_buffer, "vkCmdClearAttachments at %u samples (1 and 4 are built)", samples); /* no colour attachment (a depth/stencil-only pass): depth/stencil rectangles alone, the clear pipeline * without a colour attachment */ const VkFormat format = hw_render->eot_surface_count @@ -1853,7 +1858,7 @@ PVR_PER_ARCH(g5p_clear_attachments)(struct pvr_cmd_buffer *cmd_buffer, uint32_t rects[r].baseArrayLayer, rects[r].baseArrayLayer + rects[r].layerCount - 1); const struct pvr_graphics_pipeline *pipeline; - VkResult result = g5p_clear_pipeline(cmd_buffer, format, colour ? 0xf : 0, &pipeline); + VkResult result = g5p_clear_pipeline(cmd_buffer, format, colour ? 0xf : 0, (uint8_t)samples, &pipeline); if (result != VK_SUCCESS) return result; /* one triangle covering the viewport (the whole attachment) at the clear depth: each rectangle is its scissor */ diff --git a/src/imagination/vulkan/pvr_arch_g5p_mrt.c b/src/imagination/vulkan/pvr_arch_g5p_mrt.c index bf6d34ca220..dd091ae3c49 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_mrt.c +++ b/src/imagination/vulkan/pvr_arch_g5p_mrt.c @@ -22,6 +22,7 @@ #include "pvr_g5p.h" #include "pvr_g5p_formats.h" #include "pvr_g5p_mrt.h" +#include "pvr_g5p_msaa.h" #include "pvr_hw_pass.h" #include "pvr_image.h" @@ -83,7 +84,13 @@ g5p_mrt_target_va(const struct pvr_image_view *iview, uint64_t *bytes) const struct pvr_image_plane *plane = pvr_single_plane_const(image); const struct pvr_mip_level *level = &plane->mip_levels[iview->vk.base_mip_level]; - *bytes = (uint64_t)level->pitch * iview->vk.extent.height; + if (image->vk.samples == VK_SAMPLE_COUNT_4_BIT) + *bytes = pvr_g5p_msaa_layout(iview->vk.extent.width, iview->vk.extent.height, + vk_format_get_blocksize(iview->vk.format)); + else if (image->memlayout != PVR_MEMLAYOUT_LINEAR) + *bytes = level->size; + else + *bytes = (uint64_t)level->pitch * iview->vk.extent.height; return image->dev_addr.addr + plane->offset + level->offset + iview->vk.base_array_layer * plane->layer_size; } @@ -92,9 +99,19 @@ PVR_PER_ARCH(g5p_mrt_pass_check)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_renderpass_hwsetup_render *hw_render) { const struct pvr_render_pass_info *info = &cmd_buffer->state.render_pass_info; - const unsigned n = hw_render->eot_surface_count; + const bool ms4 = hw_render->sample_count == 4; + struct pvr_g5p_msaa_plan ms_plan; + unsigned n = hw_render->eot_surface_count; const struct pvr_image_view *iview[G5P_MRT_MAX_TARGETS]; uint64_t va[G5P_MRT_MAX_TARGETS], bytes[G5P_MRT_MAX_TARGETS]; + unsigned va_count = 0; + + if (ms4) { + /* Defer malformed 4x surface shapes to pvr_arch_g5p_msaa_admit(). */ + if (!pvr_arch_g5p_msaa_build_plan(hw_render, &ms_plan)) + return VK_SUCCESS; + n = ms_plan.outputs; + } if (n <= 1) return VK_SUCCESS; @@ -103,13 +120,13 @@ PVR_PER_ARCH(g5p_mrt_pass_check)(struct pvr_cmd_buffer *cmd_buffer, return G5P_REFUSE(cmd_buffer, "%u colour targets: %s", n, g5p_mrt_refusal_str(G5P_MRT_TOO_MANY_TARGETS)); for (unsigned t = 0; t < n; t++) { - const uint32_t idx = hw_render->eot_surfaces[t].attachment_idx; + const uint32_t idx = ms4 ? ms_plan.color_att[t] : hw_render->eot_surfaces[t].attachment_idx; if (idx >= info->attachment_count || !info->attachments[idx]) return G5P_REFUSE(cmd_buffer, "colour target %u of %u has no image view", t, n); iview[t] = info->attachments[idx]; const struct pvr_image *image = pvr_image_view_get_image(iview[t]); - const int pair = g5p_mrt_raw32_pair(n, iview[0]->vk.format, iview[t]->vk.format); + const int pair = ms4 ? 0 : g5p_mrt_raw32_pair(n, iview[0]->vk.format, iview[t]->vk.format); if (pair < 0) return G5P_REFUSE(cmd_buffer, "colour target %u of %u is %s: %s", t, n, vk_Format_to_str(iview[t]->vk.format), G5P_MRT_RAW32_PROBE); @@ -120,16 +137,31 @@ PVR_PER_ARCH(g5p_mrt_pass_check)(struct pvr_cmd_buffer *cmd_buffer, return G5P_REFUSE(cmd_buffer, "colour target %u of %u is %s, target 0 %s: %s", t, n, vk_Format_to_str(iview[t]->vk.format), vk_Format_to_str(iview[0]->vk.format), g5p_mrt_refusal_str(G5P_MRT_MIXED_FORMATS)); - if (iview[t]->vk.base_mip_level || iview[t]->vk.layer_count != 1 || image->vk.samples != VK_SAMPLE_COUNT_1_BIT) + const VkSampleCountFlagBits expected_samples = ms4 ? VK_SAMPLE_COUNT_4_BIT : VK_SAMPLE_COUNT_1_BIT; + if (iview[t]->vk.base_mip_level || iview[t]->vk.layer_count != 1 || image->vk.samples != expected_samples) return G5P_REFUSE(cmd_buffer, "colour target %u of %u: mip %u, %u layers, %u samples (one level, one layer, " - "one sample)", t, n, iview[t]->vk.base_mip_level, iview[t]->vk.layer_count, - image->vk.samples); + "%u sample%s)", t, n, iview[t]->vk.base_mip_level, iview[t]->vk.layer_count, + image->vk.samples, expected_samples, ms4 ? "s" : ""); if (iview[t]->vk.extent.width != iview[0]->vk.extent.width || iview[t]->vk.extent.height != iview[0]->vk.extent.height) return G5P_REFUSE(cmd_buffer, "colour target %u is %ux%u, target 0 %ux%u (one size per pass)", t, iview[t]->vk.extent.width, iview[t]->vk.extent.height, iview[0]->vk.extent.width, iview[0]->vk.extent.height); - va[t] = g5p_mrt_target_va(iview[t], &bytes[t]); + if (!ms4) { + va[va_count] = g5p_mrt_target_va(iview[t], &bytes[va_count]); + va_count++; + } + } + + if (ms4) { + /* Check overlap across every stored and resolved EOT destination surface. */ + for (unsigned i = 0; i < hw_render->eot_surface_count; i++) { + const uint32_t idx = hw_render->eot_surfaces[i].attachment_idx; + if (idx >= info->attachment_count || !info->attachments[idx]) + return G5P_REFUSE(cmd_buffer, "4x end-of-tile surface %u has no image view", i); + va[va_count] = g5p_mrt_target_va(info->attachments[idx], &bytes[va_count]); + va_count++; + } } /* 5..8 compact targets: the compact LOAD background loads every target, so a pass mixing CLEAR and LOAD @@ -160,9 +192,9 @@ PVR_PER_ARCH(g5p_mrt_pass_check)(struct pvr_cmd_buffer *cmd_buffer, area->offset.x, area->offset.y, area->extent.width, area->extent.height, iview[0]->vk.extent.width, iview[0]->vk.extent.height); - /* One end-of-tile store per target: aliased targets would be written twice */ - for (unsigned a = 0; a < n; a++) - for (unsigned c = a + 1; c < n; c++) + /* One end-of-tile store per surface: aliased destinations would be written twice */ + for (unsigned a = 0; a < va_count; a++) + for (unsigned c = a + 1; c < va_count; c++) if (va[a] < va[c] + bytes[c] && va[c] < va[a] + bytes[a]) return G5P_REFUSE(cmd_buffer, "colour targets %u and %u overlap in memory", a, c); @@ -181,7 +213,8 @@ PVR_PER_ARCH(g5p_mrt_draw_check)(struct pvr_cmd_buffer *cmd_buffer, unsigned pip const struct pvr_renderpass_hwsetup_render *hw_render = pvr_arch_pass_info_get_hw_render(info, info->current_hw_subpass); /* a 3-target pass runs, and its pipelines compile, as four targets */ - const unsigned rn = hw_render->eot_surface_count == 3 ? 4 : hw_render->eot_surface_count; + const unsigned outputs = pvr_arch_g5p_colour_outputs(hw_render); + const unsigned rn = outputs == 3 ? 4 : outputs; if ((rn > 1 || pn > 1) && pn != rn) return G5P_REFUSE(cmd_buffer, "the pipeline writes %u colour targets, the pass has %u", pn, rn); return VK_SUCCESS; diff --git a/src/imagination/vulkan/pvr_arch_g5p_msaa.c b/src/imagination/vulkan/pvr_arch_g5p_msaa.c index a978ca033c4..1623088e283 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_msaa.c +++ b/src/imagination/vulkan/pvr_arch_g5p_msaa.c @@ -6,8 +6,10 @@ */ #include +#include #include "util/log.h" +#include "g5p_mrt_programs.h" #include "pvr_g5p.h" #include "vk_format.h" #include "vk_log.h" @@ -18,13 +20,71 @@ #include "pvr_image.h" +bool +PVR_PER_ARCH(g5p_msaa_build_plan)(const struct pvr_renderpass_hwsetup_render *hw_render, + struct pvr_g5p_msaa_plan *plan) +{ + memset(plan, 0, sizeof(*plan)); + for (unsigned i = 0; i < PVR_G5P_MSAA_MAX_TARGETS; i++) { + plan->color_att[i] = VK_ATTACHMENT_UNUSED; + plan->store_idx[i] = -1; + plan->resolve_idx[i] = -1; + } + if (hw_render->sample_count != 4 || !hw_render->eot_surface_count || + hw_render->eot_surface_count > G5P_MRT_MAX) + return false; + + unsigned max_mrt = 0; + for (unsigned i = 0; i < hw_render->eot_surface_count; i++) { + const struct pvr_renderpass_hwsetup_eot_surface *s = &hw_render->eot_surfaces[i]; + const unsigned t = s->mrt_idx; + if (t >= PVR_G5P_MSAA_MAX_TARGETS) + return false; + const uint32_t color_att = s->need_resolve ? s->src_attachment_idx : s->attachment_idx; + if (color_att == VK_ATTACHMENT_UNUSED) + return false; + if (plan->color_att[t] != VK_ATTACHMENT_UNUSED && plan->color_att[t] != color_att) + return false; + plan->color_att[t] = color_att; + if (s->need_resolve) { + if (plan->resolve_idx[t] >= 0) + return false; + plan->resolve_idx[t] = (int8_t)i; + } else { + if (plan->store_idx[t] >= 0) + return false; + plan->store_idx[t] = (int8_t)i; + } + if (t + 1 > max_mrt) + max_mrt = t + 1; + } + for (unsigned t = 0; t < max_mrt; t++) { + if (plan->color_att[t] == VK_ATTACHMENT_UNUSED) + return false; + } + plan->outputs = max_mrt; + plan->emits = hw_render->eot_surface_count; + return true; +} + +unsigned +PVR_PER_ARCH(g5p_colour_outputs)(const struct pvr_renderpass_hwsetup_render *hw_render) +{ + if (hw_render->sample_count == 4 && hw_render->eot_surface_count) { + struct pvr_g5p_msaa_plan plan; + if (pvr_arch_g5p_msaa_build_plan(hw_render, &plan)) + return plan.outputs; + } + return hw_render->eot_surface_count; +} + /* - * The captured 4x pass: one colour target of 4-byte samples, cleared, - * loaded or don't-care, either stored with its samples or resolved by - * the PBE into a one-sample target at the end of each tile, - * a depth/stencil attachment on chip only. Upstream's hardware setup lists - * the resolve as an end-of-tile surface with need_resolve and resolve_type - * PVR_RESOLVE_TYPE_PBE. + * 4x multisampled pass: 1 to 4 colour targets of 4-byte non-integer samples, + * each stored with its samples, resolved by the PBE into a one-sample target + * (linear mip 0 or twiddled 2D single-layer, matching Apple's msaa4-resolve), + * or both stored and resolved in one end of tile (AGXMetalA9 + * MTLStoreActionStoreAndMultisampleResolve: store slot t and resolve slot + * 8 + t read the same draw buffer). */ VkResult PVR_PER_ARCH(g5p_msaa_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_renderpass_hwsetup_render *hw_render) @@ -35,33 +95,43 @@ PVR_PER_ARCH(g5p_msaa_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr return VK_SUCCESS; if (hw_render->sample_count != 4) return G5P_REFUSE(cmd_buffer, "%u samples (1 and 4 are built)", hw_render->sample_count); - if (hw_render->eot_surface_count != 1) - return G5P_REFUSE(cmd_buffer, "4x with %u end-of-tile surfaces (one target, stored or resolved: a " - "STORE with a resolve needs the CPU resolve after the job)", - hw_render->eot_surface_count); - /* a LOAD of the target: Apple's 4x loader (pvr_arch_g5p.c) */ - const struct pvr_renderpass_hwsetup_eot_surface *eot = &hw_render->eot_surfaces[0]; - const struct pvr_image_view *iview = info->attachments[eot->need_resolve ? eot->src_attachment_idx - : eot->attachment_idx]; - const struct pvr_image *image = pvr_image_view_get_image(iview); - if (image->vk.samples != VK_SAMPLE_COUNT_4_BIT || vk_format_get_blocksize(iview->vk.format) != 4 || - vk_format_is_depth_or_stencil(iview->vk.format)) - return G5P_REFUSE(cmd_buffer, "a 4x colour target %s of %u samples (4-byte samples are built)", - vk_Format_to_str(iview->vk.format), image->vk.samples); - if (iview->vk.base_mip_level || iview->vk.base_array_layer) - return G5P_REFUSE(cmd_buffer, "a 4-sample view of level %u layer %u", iview->vk.base_mip_level, - iview->vk.base_array_layer); - if (eot->need_resolve) { - const struct pvr_image_view *r = info->attachments[eot->attachment_idx]; - const struct pvr_image *ri = pvr_image_view_get_image(r); - if (eot->resolve_type != PVR_RESOLVE_TYPE_PBE) - return G5P_REFUSE(cmd_buffer, "a 4x resolve outside the PBE (transfer resolves are lane g's)"); - if (ri->vk.samples != VK_SAMPLE_COUNT_1_BIT || ri->memlayout != PVR_MEMLAYOUT_LINEAR || - r->vk.format != iview->vk.format || r->vk.extent.width != iview->vk.extent.width || - r->vk.extent.height != iview->vk.extent.height || r->vk.base_mip_level) - return G5P_REFUSE(cmd_buffer, "a resolve view that is not a %ux%u one-sample linear %s view", - iview->vk.extent.width, iview->vk.extent.height, vk_Format_to_str(iview->vk.format)); + struct pvr_g5p_msaa_plan plan; + if (!pvr_arch_g5p_msaa_build_plan(hw_render, &plan)) + return G5P_REFUSE(cmd_buffer, "4x with %u end-of-tile surfaces (1 to 4 colour targets, stored and/or PBE " + "resolved, at most 8 emits)", hw_render->eot_surface_count); + + for (unsigned t = 0; t < plan.outputs; t++) { + if (plan.color_att[t] >= info->attachment_count || !info->attachments[plan.color_att[t]]) + return G5P_REFUSE(cmd_buffer, "4x colour target %u of %u has no image view", t, plan.outputs); + const struct pvr_image_view *iview = info->attachments[plan.color_att[t]]; + const struct pvr_image *image = pvr_image_view_get_image(iview); + if (image->vk.samples != VK_SAMPLE_COUNT_4_BIT || vk_format_get_blocksize(iview->vk.format) != 4 || + vk_format_is_int(iview->vk.format) || vk_format_is_compressed(iview->vk.format) || + vk_format_is_depth_or_stencil(iview->vk.format)) + return G5P_REFUSE(cmd_buffer, "a 4x colour target %s of %u samples (4-byte non-integer samples are built)", + vk_Format_to_str(iview->vk.format), image->vk.samples); + if (iview->vk.base_mip_level || iview->vk.base_array_layer || iview->vk.layer_count != 1) + return G5P_REFUSE(cmd_buffer, "a 4-sample view of level %u layer %u (%u layers)", iview->vk.base_mip_level, + iview->vk.base_array_layer, iview->vk.layer_count); + if (plan.resolve_idx[t] >= 0) { + const struct pvr_renderpass_hwsetup_eot_surface *resolve = &hw_render->eot_surfaces[plan.resolve_idx[t]]; + if (resolve->attachment_idx >= info->attachment_count || !info->attachments[resolve->attachment_idx]) + return G5P_REFUSE(cmd_buffer, "4x resolve target %u has no image view", t); + const struct pvr_image_view *r = info->attachments[resolve->attachment_idx]; + const struct pvr_image *ri = pvr_image_view_get_image(r); + if (resolve->resolve_type != PVR_RESOLVE_TYPE_PBE) + return G5P_REFUSE(cmd_buffer, "a 4x resolve outside the PBE (transfer resolves are not built)"); + const bool twiddled_ok = ri->memlayout == PVR_MEMLAYOUT_TWIDDLED && + ri->vk.image_type == VK_IMAGE_TYPE_2D && r->vk.layer_count == 1; + if (ri->vk.samples != VK_SAMPLE_COUNT_1_BIT || + !((ri->memlayout == PVR_MEMLAYOUT_LINEAR && !r->vk.base_mip_level) || twiddled_ok) || + r->vk.format != iview->vk.format || r->vk.extent.width != iview->vk.extent.width || + r->vk.extent.height != iview->vk.extent.height) + return G5P_REFUSE(cmd_buffer, "a resolve view that is not a %ux%u one-sample linear mip-0 or " + "twiddled 2D %s view", iview->vk.extent.width, iview->vk.extent.height, + vk_Format_to_str(iview->vk.format)); + } } return VK_SUCCESS; } diff --git a/src/imagination/vulkan/pvr_g5p.h b/src/imagination/vulkan/pvr_g5p.h index 3c0c2f5c457..ec1abe306d4 100644 --- a/src/imagination/vulkan/pvr_g5p.h +++ b/src/imagination/vulkan/pvr_g5p.h @@ -161,11 +161,16 @@ struct pvr_g5p_programs { /* a render without colour attachments: the PBE target of its end of tile, a 16x16 R8 surface the PBE cuts * every pixel past to (pvr_arch_g5p.c g5p_job_init()) */ struct pvr_suballoc_bo *null_rt; - /* 4x (pvr_g5p_msaa.c): the end of tile of a one-target multisample - * store (emitpix per sample), and the one-target clear's kick at sample - * rate (DOUTU src0[34:33] 2) */ - struct pvr_suballoc_bo *eot_usc_ms; - struct pvr_pds_upload clear_kick_ms; + /* 4x (pvr_g5p_msaa.c): per-(emits, store_mask) end-of-tile USC programs + * (cached lazily under clear_lock), and sample-rate kicks of clear_usc[0..2] + * (1, 2, 4 targets; DOUTU src0[34:33] 2) */ + struct { + uint8_t emits; + uint8_t store_mask; + struct pvr_suballoc_bo *usc; + } eot_ms[32]; + unsigned eot_ms_count; + struct pvr_pds_upload clear_kick_ms[3]; /* the background of a loaded colour attachment (loadOp LOAD): the * compiled load program (pvr_g5p_compile_load()), its kick, and the PDS * code of its uploads, one DOUTD each (data per render: the sources, @@ -232,8 +237,9 @@ struct pvr_g5p_device { struct { VkFormat format; uint8_t write_mask; + uint8_t samples; VkPipeline pipeline; - } clear[8]; + } clear[16]; unsigned clear_count; /* vk_meta: image blits as fragment work (pvr_arch_g5p_meta.c) */ struct vk_meta_device meta; diff --git a/src/imagination/vulkan/pvr_g5p_msaa.c b/src/imagination/vulkan/pvr_g5p_msaa.c index a12cb40091e..a9cfacacd3b 100644 --- a/src/imagination/vulkan/pvr_g5p_msaa.c +++ b/src/imagination/vulkan/pvr_g5p_msaa.c @@ -136,18 +136,31 @@ pvr_g5p_msaa_pbe_resolve(uint64_t q[3]) } unsigned -pvr_g5p_msaa_eot_usc(uint8_t *out) +pvr_g5p_msaa_eot_usc_mask(uint8_t *out, unsigned emits, uint8_t store_mask) { - const unsigned n = g5p_mrt_eot_usc(out, 1); - /* the one-target program: one 12-byte state load, then the emitpix */ - const unsigned emit = 12; - - if (out[emit] != 0x1c) + if (emits < 1 || emits > G5P_MRT_MAX) + return 0; + const unsigned n = g5p_mrt_eot_usc_mode(out, emits, false); + if (!n) return 0; - out[emit + 1] = (uint8_t)((out[emit + 1] & ~G5P_EMIT_SAMPLES_MASK) | G5P_EMIT_SAMPLES_MS << G5P_EMIT_SAMPLES_SHIFT); + /* emits 12-byte state loads, then emit k at 12 * emits + 8 * k */ + for (unsigned k = 0; k < emits; k++) { + const unsigned emit = 12 * emits + 8 * k; + if (out[emit] != 0x1c) + return 0; + if (store_mask & (1u << k)) + out[emit + 1] = (uint8_t)((out[emit + 1] & ~G5P_EMIT_SAMPLES_MASK) | + G5P_EMIT_SAMPLES_MS << G5P_EMIT_SAMPLES_SHIFT); + } return n; } +unsigned +pvr_g5p_msaa_eot_usc(uint8_t *out) +{ + return pvr_g5p_msaa_eot_usc_mask(out, 1, 1u); +} + uint64_t pvr_g5p_msaa_doutu(uint64_t src0, uint32_t samples) { diff --git a/src/imagination/vulkan/pvr_g5p_msaa.h b/src/imagination/vulkan/pvr_g5p_msaa.h index ef80653dae9..d94be30301d 100644 --- a/src/imagination/vulkan/pvr_g5p_msaa.h +++ b/src/imagination/vulkan/pvr_g5p_msaa.h @@ -65,10 +65,14 @@ void pvr_g5p_msaa_pbe_resolve(uint64_t q[3]); * fields). */ void pvr_g5p_msaa_tex_state(uint64_t q[3], uint32_t key, uint64_t va, uint32_t width, uint32_t height, bool srgb); -/* The end-of-tile program of a one-target 4x store: the one-target program - * (g5p_mrt_eot_usc(out, 1)) with the emitpix's sample field 2 instead of 1 - * (captured 1c 05 -> 1c 09). The resolve keeps the one-sample program. - * Returns its size (G5P_MRT_EOT_USC_MAX bytes at most). */ +/* The end-of-tile program of a 4x pass with `emits` (1..8) PBE entries: + * g5p_mrt_eot_usc_mode(out, emits, false) with each store entry's emitpix + * sample field set to 2 (1c 09) and each resolve entry kept at 1 (1c 05), + * selected by bit k of `store_mask`. Matches Apple's A9 builtin EOT compiler + * byte-for-byte for 1..4 colour targets with store, resolve, or + * StoreAndMultisampleResolve (up to 8 emits). Returns its size (at most + * G5P_MRT_EOT_USC_MAX bytes), or 0 on invalid inputs. */ +unsigned pvr_g5p_msaa_eot_usc_mask(uint8_t *out, unsigned emits, uint8_t store_mask); unsigned pvr_g5p_msaa_eot_usc(uint8_t *out); /* A fragment-side DOUTU src0 (the background program's and the fragment @@ -104,12 +108,32 @@ void pvr_g5p_msaa_image_samples(struct pvr_physical_device *pdevice, const VkPhy struct pvr_cmd_buffer; struct pvr_renderpass_hwsetup_render; +#define PVR_G5P_MSAA_MAX_TARGETS 4 + +/* Logical-target decomposition of a 4x render pass's end-of-tile surfaces: + * each logical colour output t (0..outputs-1, matching mrt_idx) may have a + * 4x store surface, a PBE resolve surface, or both (StoreAndMultisampleResolve, + * in either eot_surfaces[] order). */ +struct pvr_g5p_msaa_plan { + unsigned outputs; + unsigned emits; + uint32_t color_att[PVR_G5P_MSAA_MAX_TARGETS]; + int8_t store_idx[PVR_G5P_MSAA_MAX_TARGETS]; + int8_t resolve_idx[PVR_G5P_MSAA_MAX_TARGETS]; +}; + +bool PVR_PER_ARCH(g5p_msaa_build_plan)(const struct pvr_renderpass_hwsetup_render *hw_render, + struct pvr_g5p_msaa_plan *plan); +unsigned PVR_PER_ARCH(g5p_colour_outputs)(const struct pvr_renderpass_hwsetup_render *hw_render); + /* job_init: refuses, by name, a multisample render this lane does not - * build (only 1 and 4 samples; at 4: one colour target, stored or resolved; - * its LOAD is Apple's 4x loader, pvr_arch_g5p.c). VK_SUCCESS at one sample. */ + * build (1 and 4 samples; at 4: 1..4 colour targets, each stored, PBE + * resolved, or stored and resolved in one end of tile). VK_SUCCESS at 1x. */ VkResult PVR_PER_ARCH(g5p_msaa_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_renderpass_hwsetup_render *hw_render); +# define pvr_arch_g5p_msaa_build_plan PVR_PER_ARCH(g5p_msaa_build_plan) +# define pvr_arch_g5p_colour_outputs PVR_PER_ARCH(g5p_colour_outputs) # define pvr_arch_g5p_msaa_admit PVR_PER_ARCH(g5p_msaa_admit) #endif /* PVR_PER_ARCH */ From ea63eceb8701df3ac2fa03e393e840c1ed26348f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:34:13 +0100 Subject: [PATCH 04/11] pvr/g5p: support vertex-only (depth/stencil-only) graphics pipelines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/vulkan/pvr_arch_g5p_gfx.c | 45 +++++++++++++++++------ 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/imagination/vulkan/pvr_arch_g5p_gfx.c b/src/imagination/vulkan/pvr_arch_g5p_gfx.c index 36bb283e052..454232c0ae0 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g5p_gfx.c @@ -476,8 +476,10 @@ g5p_check_state(struct pvr_device *device, const VkGraphicsPipelineCreateInfo *c memcpy(g5p_rp_record->cfs, cfs, sizeof(cfs)); } - if (s->shader_stages != (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) || s->ts) - return G5P_REFUSE(device, "shader stages %#x (a vertex and a fragment shader)", s->shader_stages); + if ((s->shader_stages != (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) && + s->shader_stages != VK_SHADER_STAGE_VERTEX_BIT) || s->ts) + return G5P_REFUSE(device, "shader stages %#x (a vertex shader, with or without a fragment shader)", + s->shader_stages); if (s->rs && s->rs->polygon_mode != VK_POLYGON_MODE_FILL && !pvr_g5p_polygon_mode_enabled()) return G5P_REFUSE(device, "polygon mode %d", s->rs->polygon_mode); /* depth clip and clamp: the draw judges them with its viewport and bias @@ -560,9 +562,20 @@ g5p_check_state(struct pvr_device *device, const VkGraphicsPipelineCreateInfo *c */ key->last_read_groups = true; key->fuse_ffma = pco_g5p_fuse_ffma(); - const char *why = pvr_arch_g5p_blend_fs_key(s, colors, key); - if (why) - return G5P_REFUSE(device, "colour blend state: %s", why); + const bool has_fs = (s->shader_stages & VK_SHADER_STAGE_FRAGMENT_BIT) != 0; + if (has_fs) { + const char *why = pvr_arch_g5p_blend_fs_key(s, colors, key); + if (why) + return G5P_REFUSE(device, "colour blend state: %s", why); + } else { + /* Vertex-only pipeline (depth/stencil-only shadow pass or rasterizer + * discard): blend state is ignored and no colour is written. */ + key->blend = false; + key->write_mask = 0; + key->color_targets = colors > 1 ? colors : 0; + if (colors > 1 && colors <= 4) + key->mrt_blend_state = true; + } /* three colour targets compile as four: the fourth (the pass's null target) is written zeros */ if (colors == 3) key->color_targets = 4; @@ -592,9 +605,10 @@ g5p_check_state(struct pvr_device *device, const VkGraphicsPipelineCreateInfo *c key->a8_packed_word = true; if (PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g4p) && colors == 1 && cf == VK_FORMAT_R32_SFLOAT) key->color_output = PCO_G5P_COLOR_F32; - /* no colour attachment: the program writes no colour (the no-colour ISP form: depth/stencil only, a - * discarding program still runs for its feedback) */ - if (!colors) + /* no colour attachment or no fragment shader: the program writes no colour + * (the no-colour ISP form: tag_write_disable, upass 0, depth/stencil only; + * a discarding fragment program still runs for its feedback) */ + if (!colors || !has_fs) key->write_mask = 0; /* Apple's masked form (discarding and non-discarding shaders under write mask RGB, * no blending, BGRA8: kill mode 1 / 0, A none, B 7 -> FAST_PUNCH_THROUGH / OPAQUE, output mask 7; the program @@ -730,8 +744,8 @@ g5p_pipeline_build(struct pvr_device *device, const VkGraphicsPipelineCreateInfo else return G5P_REFUSE(device, "shader stage %#x", st->stage); } - if (!vs_info || !fs_info) - return G5P_REFUSE(device, "a pipeline without a vertex and a fragment shader"); + if (!vs_info) + return G5P_REFUSE(device, "a pipeline without a vertex shader"); /* the vertex input layout: the fetches, and the registers the vertex program reads them from * (pvr_g5p_vertex.h) */ @@ -748,7 +762,16 @@ g5p_pipeline_build(struct pvr_device *device, const VkGraphicsPipelineCreateInfo const uint32_t dump_samples = g->samples; const struct pvr_g5p_dump_blob fs_blobs[] = { { "fs_key", &key, sizeof(key) }, { "samples", &dump_samples, sizeof(dump_samples) } }; - if (!pvr_g5p_compile_stage(fs_info, true, g->samples, NULL, &key, NULL, fs)) { + if (!fs_info) { + /* Vertex-only pipeline (depth/stencil-only or rasterizer-discard): + * compile the minimal stub with write_mask = 0 so the backend emits the + * empty no-colour program (0 varyings, 0 uploads) and ISP sets + * tag_write_disable = 1, upass = 0. */ + const VkPipelineShaderStageCreateInfo *empty_fs = + pvr_g5p_stub_stage(VK_SHADER_STAGE_FRAGMENT_BIT, &fs_stub_info, &fs_stub_module); + if (!pvr_g5p_compile_stage(empty_fs, true, g->samples, NULL, &key, NULL, fs)) + return G5P_REFUSE(device, "depth-only fragment program: %s", fs->refusal); + } else if (!pvr_g5p_compile_stage(fs_info, true, g->samples, NULL, &key, NULL, fs)) { const bool stub = pvr_g5p_capture_stub(); pvr_g5p_shader_dump(fs_info, create_info->layout, "frag", fs_blobs, ARRAY_SIZE(fs_blobs), stub ? "STUB" : "REFUSE", fs->refusal); From 55ee070b96757ed127454cf5ba1b4be9ec469998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:35:37 +0100 Subject: [PATCH 05/11] pvr/g5p: support mixed two-word f16 MRT formats and depth/stencil with MRT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/vulkan/pvr_arch_g5p.c | 6 +-- src/imagination/vulkan/pvr_arch_g5p_ds.c | 3 -- src/imagination/vulkan/pvr_arch_g5p_mrt.c | 47 +++++++++++++++++++---- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index c15a01c892f..fee66e58564 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -1432,10 +1432,10 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd if (nt == 4 && n == 3 && g->samples != 4) { uint32_t key; bool srgb; - if (!g5p_pbe_key(first_format, &key, &srgb)) - return G5P_REFUSE(cmd_buffer, "the padding target's %s key", vk_Format_to_str(first_format)); + if (!g5p_pbe_key(VK_FORMAT_R8_UNORM, &key, &srgb)) + return G5P_REFUSE(cmd_buffer, "the padding target's R8 key"); g5p_pbe_encode(pbe[3], key, srgb, p->null_rt->dev_addr.addr, G5P_NULL_RT_SIDE, G5P_NULL_RT_SIDE, - G5P_NULL_RT_PITCH4); + G5P_NULL_RT_PITCH); } /* A render area smaller than the attachment: every tile runs the * background and is stored, so the tiles outside the area must load what diff --git a/src/imagination/vulkan/pvr_arch_g5p_ds.c b/src/imagination/vulkan/pvr_arch_g5p_ds.c index 24a78bd81c8..b9c059ad665 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_ds.c +++ b/src/imagination/vulkan/pvr_arch_g5p_ds.c @@ -65,9 +65,6 @@ PVR_PER_ARCH(g5p_ds_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_r /* upstream's own test (pvr_arch_hw_pass.c): a resolve mode; the index is set only with one */ if (hw_render->depth_resolve_mode || hw_render->stencil_resolve_mode) return G5P_REFUSE(cmd_buffer, "a depth/stencil resolve (no capture)"); - if (pvr_arch_g5p_colour_outputs(hw_render) > 1) - return G5P_REFUSE(cmd_buffer, "depth/stencil beside %u colour targets (no capture of the combination)", - pvr_arch_g5p_colour_outputs(hw_render)); if (hw_render->eot_surface_count) { const struct pvr_image_view *c = info->attachments[hw_render->eot_surfaces[0].attachment_idx]; if (c->vk.extent.width != iview->vk.extent.width || c->vk.extent.height != iview->vk.extent.height) diff --git a/src/imagination/vulkan/pvr_arch_g5p_mrt.c b/src/imagination/vulkan/pvr_arch_g5p_mrt.c index dd091ae3c49..74d5038fa66 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_mrt.c +++ b/src/imagination/vulkan/pvr_arch_g5p_mrt.c @@ -14,6 +14,7 @@ #include "util/log.h" #include "vk_enum_to_str.h" +#include "vk_format.h" #include "vk_log.h" #include "g5p_mrt_out.h" @@ -27,6 +28,23 @@ #include "pvr_image.h" +/* Colour formats rendered by the two-word packed-f16 fragment output (four + * f16 halves in o(2t)..o(2t+1), packed per target by its own PBE state). + * Apple's A9 compiler uses this uniform two-word per-target layout for BGRA8, + * RGBA8, sRGB, RGB10A2, RGBA16F, R8, RG8, R16F, RG16F and RG11B10F + * (gles3-tex.md §1.2; gles3-continued107.md §0.3 mixed-format MRT witness). */ +static bool +g5p_mrt_f16_format_ok(VkFormat format) +{ + uint32_t key; + bool srgb; + + return format != VK_FORMAT_R32_SFLOAT && + pvr_g5p_format_pbe(format, &key, &srgb) && + !pvr_g5p_raw32_kind(format) && + !vk_format_is_int(format); +} + /* Two 32-bit integer targets of one format (dEQP's ShaderExecutor: a mat2xN * output's columns, modf's two results): the raw32 output's four words each, * eight in one emitpix, the width of Apple's 4-target pass; each target's PBE @@ -69,10 +87,16 @@ PVR_PER_ARCH(g5p_mrt_pipeline_check)(struct pvr_device *device, unsigned n, cons if (n > 2 && pvr_g5p_raw32_kind(formats[i])) return G5P_REFUSE(device, "%u colour attachments of %s: %s", n, vk_Format_to_str(formats[i]), G5P_MRT_RAW32_WIDE); - if (!pvr_g5p_mrt_format_ok(formats[i]) || formats[i] != formats[0]) - return G5P_REFUSE(device, "colour attachment %u of %u is %s, attachment 0 %s: %s", i, n, - vk_Format_to_str(formats[i]), vk_Format_to_str(formats[0]), - g5p_mrt_refusal_str(G5P_MRT_MIXED_FORMATS)); + if (n > 4) { + /* 5..8 compact UNORM8 targets: shader packs one homogeneous byte order */ + if (!pvr_g5p_mrt_format_ok(formats[i]) || formats[i] != formats[0]) + return G5P_REFUSE(device, "colour attachment %u of %u is %s, attachment 0 %s: %s", i, n, + vk_Format_to_str(formats[i]), vk_Format_to_str(formats[0]), + g5p_mrt_refusal_str(G5P_MRT_MIXED_FORMATS)); + } else if (!g5p_mrt_f16_format_ok(formats[i])) { + return G5P_REFUSE(device, "colour attachment %u of %u is %s: not a two-word f16 MRT format", i, n, + vk_Format_to_str(formats[i])); + } } return VK_SUCCESS; } @@ -133,10 +157,17 @@ PVR_PER_ARCH(g5p_mrt_pass_check)(struct pvr_cmd_buffer *cmd_buffer, if (!pair && n > 2 && pvr_g5p_raw32_kind(iview[t]->vk.format)) return G5P_REFUSE(cmd_buffer, "%u colour targets of %s: %s", n, vk_Format_to_str(iview[t]->vk.format), G5P_MRT_RAW32_WIDE); - if (!pair && (!pvr_g5p_mrt_format_ok(iview[t]->vk.format) || iview[t]->vk.format != iview[0]->vk.format)) - return G5P_REFUSE(cmd_buffer, "colour target %u of %u is %s, target 0 %s: %s", t, n, - vk_Format_to_str(iview[t]->vk.format), vk_Format_to_str(iview[0]->vk.format), - g5p_mrt_refusal_str(G5P_MRT_MIXED_FORMATS)); + if (!pair) { + if (n > 4) { + if (!pvr_g5p_mrt_format_ok(iview[t]->vk.format) || iview[t]->vk.format != iview[0]->vk.format) + return G5P_REFUSE(cmd_buffer, "colour target %u of %u is %s, target 0 %s: %s", t, n, + vk_Format_to_str(iview[t]->vk.format), vk_Format_to_str(iview[0]->vk.format), + g5p_mrt_refusal_str(G5P_MRT_MIXED_FORMATS)); + } else if (!g5p_mrt_f16_format_ok(iview[t]->vk.format)) { + return G5P_REFUSE(cmd_buffer, "colour target %u of %u is %s: not a two-word f16 MRT format", t, n, + vk_Format_to_str(iview[t]->vk.format)); + } + } const VkSampleCountFlagBits expected_samples = ms4 ? VK_SAMPLE_COUNT_4_BIT : VK_SAMPLE_COUNT_1_BIT; if (iview[t]->vk.base_mip_level || iview[t]->vk.layer_count != 1 || image->vk.samples != expected_samples) return G5P_REFUSE(cmd_buffer, "colour target %u of %u: mip %u, %u layers, %u samples (one level, one layer, " From bf7c56dc73dce88f705121816405e0671901ecf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:36:46 +0100 Subject: [PATCH 06/11] pvr/g5p: use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/g5p/pco_g5p_general.c | 27 ++++++++++++++++------- src/imagination/vulkan/pvr_arch_g5p_gfx.c | 25 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/imagination/g5p/pco_g5p_general.c b/src/imagination/g5p/pco_g5p_general.c index a92dad2ba2a..99a796f38d6 100644 --- a/src/imagination/g5p/pco_g5p_general.c +++ b/src/imagination/g5p/pco_g5p_general.c @@ -272,6 +272,7 @@ struct gctx { /* common store */ struct tex_bind tex[16]; unsigned ntex, fetch_sampler_common; + bool fs_fetch_shared; /* compact FS uses shared fetch_sampler_common for txf */ int vtx_lod_common; /* the A8 vertex sample's level 0.0 in the common store (PCO_G5P_UPLOAD_ZERO), -1 without */ bool cube_gradient; /* fixed native bank0 r0..r8 operand tuple */ struct { unsigned set, binding, element, lod, common; } tsize[4]; /* textureSize/QueryLevels */ @@ -2379,11 +2380,13 @@ static void plan_common(struct gctx *c) if (g5p_usc_g4p && !g5p_usc_g4p_a9_forms && compact && c->ntex && !(c->vs && g5p_usc_g4p_vtex)) refuse(c, "the A8 samples one image slot (common dword 0); more than four textures or vertex textures are " "not captured"); + const bool fs_fetch = !c->vs && !g5p_usc_g4p; + const bool use_fetch = qualified || fs_fetch; unsigned sampler_count = 0; bool fetch_sampler = false; for (unsigned i = 0; i < c->ntex; i++) { - sampler_count += !qualified || c->tex[i].needs_sampler; - fetch_sampler |= qualified && c->tex[i].needs_fetch_sampler; + sampler_count += !use_fetch || c->tex[i].needs_sampler; + fetch_sampler |= use_fetch && c->tex[i].needs_fetch_sampler; } /* the samplerless read's sampler policy is the A9's one-qword word (pvr_g5p_fetch_sampler_word()); the A8's, * with vertex textures, four dwords of Rogue sampler words (point, non-normalized, clamped) */ @@ -2466,6 +2469,7 @@ static void plan_common(struct gctx *c) c->a8_one_sampler = c->a8_slots && (c->ntex == 1 || (one_sampler && !a8_each)); c->a8_sampler_each = c->a8_slots && a8_each; c->fetch_sampler_common = sampler_base + sdw * sampler_count; + c->fs_fetch_shared = fs_fetch && compact && fetch_sampler; for (unsigned i = 0; c->a8_slots && i < c->ntex; i++) { struct tex_bind *t = &c->tex[i]; t->image = slot_base + 4 * i; @@ -2483,22 +2487,27 @@ static void plan_common(struct gctx *c) for (unsigned i = 0; !c->a8_slots && i < c->ntex; i++) { struct tex_bind *t = &c->tex[i]; t->image = compact ? image_base + istride * i : align(next, 8); - t->sampler = compact ? ((!qualified || t->needs_sampler) ? sampler_cursor : c->fetch_sampler_common) : t->image + idw; - sampler_cursor += compact && (!qualified || t->needs_sampler) ? sdw : 0; - next = compact ? c->fetch_sampler_common + (g5p_usc_g4p ? sdw : 2) * (qualified && fetch_sampler) + t->sampler = compact ? ((!use_fetch || t->needs_sampler) ? sampler_cursor : c->fetch_sampler_common) : t->image + idw; + sampler_cursor += compact && (!use_fetch || t->needs_sampler) ? sdw : 0; + next = compact ? c->fetch_sampler_common + (g5p_usc_g4p ? sdw : 2) * (use_fetch && fetch_sampler) : t->image + idw + sdw; if (t->image / 2 > (compact ? 120 : 28) || t->sampler / 2 > (compact ? 124 : 32)) refuse(c, "texture descriptors beyond the bounded qualified selectors"); add_upload(c, PCO_G5P_UPLOAD_IMAGE, t->set, t->binding, t->element, t->image_flags, idw, t->image); - if (!qualified || t->needs_sampler) + if (!use_fetch || t->needs_sampler) add_upload(c, PCO_G5P_UPLOAD_SAMPLER, t->sset, t->sbinding, t->selement, 32 | (t->fetch ? PCO_G5P_UPLOAD_SAMPLER_FETCH | t->fetch_level << PCO_G5P_UPLOAD_SAMPLER_FETCH_LEVEL_SHIFT | (t->fetch_read ? PCO_G5P_UPLOAD_SAMPLER_READ : 0) : 0), sdw, t->sampler); + else if (!compact && fs_fetch) + add_upload(c, PCO_G5P_UPLOAD_FETCH_SAMPLER, 0, 0, 0, 0, 2, t->sampler); } - if (qualified && fetch_sampler) + if (compact && use_fetch && fetch_sampler) { + if (c->fetch_sampler_common / 2 > 124) + refuse(c, "texture descriptors beyond the bounded qualified selectors"); add_upload(c, PCO_G5P_UPLOAD_FETCH_SAMPLER, 0, 0, 0, 0, g5p_usc_g4p ? sdw : 2, c->fetch_sampler_common); + } /* Pointer pairs of register-indexed UBO arrays: even dwords below 32 (the * addr.add_shift base field, 0x81 | 4 * dword). */ for (unsigned i = 0; i < c->nuptr; i++) { @@ -5199,7 +5208,9 @@ static void emit_tex_ext(struct gctx *c, nir_tex_instr *t) bool third = array || sd == GLSL_SAMPLER_DIM_3D || sd == GLSL_SAMPLER_DIM_CUBE; int packed = packed_offset_components(t, sd == GLSL_SAMPLER_DIM_3D ? 3 : 2); struct g5p_tex_ext x = { - .image_qword = b->image / 2, .sampler_qword = g5p_usc_g4p ? b->sampler : b->sampler / 2, .read = read, + .image_qword = b->image / 2, + .sampler_qword = g5p_usc_g4p ? b->sampler : (read && c->fs_fetch_shared ? c->fetch_sampler_common : b->sampler) / 2, + .read = read, .dim = sd == GLSL_SAMPLER_DIM_CUBE ? G5P_TEX_CUBE : sd == GLSL_SAMPLER_DIM_3D ? G5P_TEX_3D : array ? G5P_TEX_2D_ARRAY : G5P_TEX_2D, .mask = t->is_shadow ? 1 : 0xf, .compare = t->is_shadow, .offset = packed >= 0, diff --git a/src/imagination/vulkan/pvr_arch_g5p_gfx.c b/src/imagination/vulkan/pvr_arch_g5p_gfx.c index 454232c0ae0..78860161285 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g5p_gfx.c @@ -844,6 +844,7 @@ g5p_pipeline_build(struct pvr_device *device, const VkGraphicsPipelineCreateInfo switch (u->kind) { case PCO_G5P_UPLOAD_IMAGE: case PCO_G5P_UPLOAD_SAMPLER: + case PCO_G5P_UPLOAD_FETCH_SAMPLER: case PCO_G5P_UPLOAD_IMAGE_SIZE: case PCO_G5P_UPLOAD_BLEND_CONSTANTS: case PCO_G5P_UPLOAD_SAMPLER_META: @@ -905,6 +906,7 @@ g5p_pipeline_build(struct pvr_device *device, const VkGraphicsPipelineCreateInfo const struct pco_g5p_upload *u = &fs->uploads[i]; bool copy = fs->num_uploads > 12 && (u->kind == PCO_G5P_UPLOAD_IMAGE || u->kind == PCO_G5P_UPLOAD_SAMPLER || + u->kind == PCO_G5P_UPLOAD_FETCH_SAMPLER || u->kind == PCO_G5P_UPLOAD_IMAGE_SIZE || u->kind == PCO_G5P_UPLOAD_BLEND_CONSTANTS || u->kind == PCO_G5P_UPLOAD_SAMPLER_META); if (u->common + u->dwords > ARRAY_SIZE(cpu)) @@ -2108,6 +2110,20 @@ fs_uploads(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_pipeline *g, copied[i] = true; continue; } + case PCO_G5P_UPLOAD_FETCH_SAMPLER: { + if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g4p)) { + if (u->dwords != 4) + return G5P_REFUSE(cmd_buffer, "A8 fetch sampler of %u dwords", u->dwords); + pvr_g5p_a8_fetch_sampler(out, NULL, 0); + } else { + if (u->dwords != 2) + return G5P_REFUSE(cmd_buffer, "A9 fetch sampler of %u dwords", u->dwords); + const uint64_t policy = pvr_g5p_fetch_sampler_word(); + memcpy(out, &policy, sizeof(policy)); + } + copied[i] = true; + continue; + } case PCO_G5P_UPLOAD_PUSH: /* the bytes the program reads, as they are now (a copy per draw) */ if (u->offset + bytes > PVR_MAX_PUSH_CONSTANTS_SIZE) @@ -2206,6 +2222,15 @@ fs_uploads(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_pipeline *g, break; } case PCO_G5P_UPLOAD_SAMPLER: + /* the A8's texelFetch drawn as a sample on a standalone SAMPLED_IMAGE has no descriptor sampler */ + if ((u->offset & PCO_G5P_UPLOAD_SAMPLER_FETCH) && u->dwords == 4 && + lb->type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) { + if (u->offset & PCO_G5P_UPLOAD_SAMPLER_READ) + pvr_g5p_a8_read_sampler(out); + else + pvr_g5p_a8_fetch_sampler(out, NULL, (u->offset >> PCO_G5P_UPLOAD_SAMPLER_FETCH_LEVEL_SHIFT) & 0xf); + break; + } /* a combined descriptor's sampler is at +32 (the upload's offset), * a standalone sampler's at +0 */ if (lb->type != VK_DESCRIPTOR_TYPE_SAMPLER) From 10d13ce42b6363dd3836b9fcb2b1cf4dea193a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:37:38 +0100 Subject: [PATCH 07/11] pvr/g5p: support 4x multisampled passes with zero colour EOT surfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/vulkan/pvr_arch_g5p.c | 26 +++++++++++++++++----- src/imagination/vulkan/pvr_arch_g5p_msaa.c | 4 ++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index fee66e58564..a6c38fc8d33 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -1062,7 +1062,7 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd if (admit != VK_SUCCESS) return admit; g->samples = MAX2(hw_render->sample_count, 1); - if (null_target && g->samples != 1) + if (null_target && g->samples != 1 && g->samples != 4) return G5P_REFUSE(cmd_buffer, "a %u-sample render without colour attachments", g->samples); struct pvr_g5p_msaa_plan ms_plan = { 0 }; if (!null_target && g->samples == 4 && !pvr_arch_g5p_msaa_build_plan(hw_render, &ms_plan)) @@ -1158,10 +1158,26 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd if (null_target) { uint32_t key; bool srgb; - if (!g5p_pbe_key(VK_FORMAT_R8_UNORM, &key, &srgb)) - return G5P_REFUSE(cmd_buffer, "the null colour target's R8 key"); - g5p_pbe_encode(pbe[0], key, srgb, p->null_rt->dev_addr.addr, G5P_NULL_RT_SIDE, G5P_NULL_RT_SIDE, - G5P_NULL_RT_PITCH); + if (g->samples == 4) { + /* 4x depth/stencil-only (or no-store) pass: resolve one 16x16 BGRA8 + * target into null_rt (1024 bytes, 64-byte aligned), matching the + * hardware-proven msaa4-resolve pass shape (1c 05 EOT, PBE resolve, + * sample-rate clear kick). */ + if (!g5p_pbe_key(VK_FORMAT_B8G8R8A8_UNORM, &key, &srgb)) + return G5P_REFUSE(cmd_buffer, "the 4x null colour target's BGRA8 key"); + g5p_pbe_encode(pbe[0], key, srgb, p->null_rt->dev_addr.addr, G5P_NULL_RT_SIDE, G5P_NULL_RT_SIDE, + G5P_NULL_RT_PITCH4); + pvr_g5p_msaa_pbe_resolve(pbe[0]); + ms_pbe_halves[0] = 0; + ms_store_mask = 0; + ms_emits = 1; + g->msaa_resolve = true; + } else { + if (!g5p_pbe_key(VK_FORMAT_R8_UNORM, &key, &srgb)) + return G5P_REFUSE(cmd_buffer, "the null colour target's R8 key"); + g5p_pbe_encode(pbe[0], key, srgb, p->null_rt->dev_addr.addr, G5P_NULL_RT_SIDE, G5P_NULL_RT_SIDE, + G5P_NULL_RT_PITCH); + } g->width = info->rstate->width; g->height = info->rstate->height; } diff --git a/src/imagination/vulkan/pvr_arch_g5p_msaa.c b/src/imagination/vulkan/pvr_arch_g5p_msaa.c index 1623088e283..5d292e20059 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_msaa.c +++ b/src/imagination/vulkan/pvr_arch_g5p_msaa.c @@ -95,6 +95,10 @@ PVR_PER_ARCH(g5p_msaa_admit)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr return VK_SUCCESS; if (hw_render->sample_count != 4) return G5P_REFUSE(cmd_buffer, "%u samples (1 and 4 are built)", hw_render->sample_count); + /* 4x depth/stencil-only (or no-store) pass: resolved into the 16x16 null + * colour target in g5p_job_init(), matching the 1x null_target path. */ + if (!hw_render->eot_surface_count) + return VK_SUCCESS; struct pvr_g5p_msaa_plan plan; if (!pvr_arch_g5p_msaa_build_plan(hw_render, &plan)) From 8295d8c4b7a2116c9e6f16be01a7311ae49c483b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:42:51 +0100 Subject: [PATCH 08/11] g9p/a9: support image_deref_size and non-overlapping size slots in compute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/imagination/g9p/g9p_a9.h | 2 +- src/imagination/g9p/g9p_a9_compute.h | 20 ++-- src/imagination/g9p/g9p_a9_intrinsics.h | 92 +++++++++++++++++++ src/imagination/g9p/g9p_a9_tex.h | 29 ++++-- src/imagination/vulkan/pvr_arch_g5p_compute.c | 4 +- 5 files changed, 129 insertions(+), 18 deletions(-) diff --git a/src/imagination/g9p/g9p_a9.h b/src/imagination/g9p/g9p_a9.h index d7b27d97d04..1dcb4dd132a 100644 --- a/src/imagination/g9p/g9p_a9.h +++ b/src/imagination/g9p/g9p_a9.h @@ -24,7 +24,7 @@ struct g9p_a9_upload { /* Keep main's G9P numbering; only the A9 backend uses NIR-order breaks. */ #define G9P_A9_EMPTY_BREAK_BEFORE(ctx, side) do { if (!(ctx)->out->a9 || !(side)) (ctx)->ip++; } while (0) #define G9P_A9_EMPTY_BREAK_AFTER(ctx, side) do { if ((ctx)->out->a9 && (side)) (ctx)->ip++; } while (0) -#define G9P_A9_CTX_FIELDS unsigned a9_barriers_remaining; +#define G9P_A9_CTX_FIELDS unsigned a9_barriers_remaining; uint8_t a9_storage_images, a9_sampled_images; #define G9P_A9_GENERATE_INIT a9_generate_init(ctx, impl) #define G9P_A9_SET_BODYLESS(ctx, n) do { \ if ((ctx)->out->a9 && (ctx)->stage == MESA_SHADER_COMPUTE) \ diff --git a/src/imagination/g9p/g9p_a9_compute.h b/src/imagination/g9p/g9p_a9_compute.h index 56f282e758a..e61c28a493e 100644 --- a/src/imagination/g9p/g9p_a9_compute.h +++ b/src/imagination/g9p/g9p_a9_compute.h @@ -371,11 +371,9 @@ bool g9p_a9_compile_compute(nir_shader *nir, struct g9p_shader *out, void *mem_c } } /* the fixed common-store places of texture words (g9p_a9_tex.h) */ - bool sizes = false, lods = false; - for (unsigned i = 0; i < out->a9_num_uploads; i++) { - sizes |= out->a9_uploads[i].kind == G9P_A9_UP_SIZE; + bool lods = false; + for (unsigned i = 0; i < out->a9_num_uploads; i++) lods |= out->a9_uploads[i].kind == G9P_A9_UP_LOD; - } if (lods && out->num_buffers > 13) { if (!out->a9_refusal[0]) snprintf(out->a9_refusal, sizeof(out->a9_refusal), @@ -389,11 +387,15 @@ bool g9p_a9_compile_compute(nir_shader *nir, struct g9p_shader *out, void *mem_c out->num_buffers); return backend_failure(out, &(struct g9p_ctx){0}); } - if (sizes && out->num_textures) { - if (!out->a9_refusal[0]) - snprintf(out->a9_refusal, sizeof(out->a9_refusal), - "a texture size query together with a storage image (both at common 40-47)"); - return backend_failure(out, &(struct g9p_ctx){0}); + for (unsigned i = 0; i < out->a9_num_uploads && out->num_textures; i++) { + const struct g9p_a9_upload *u = &out->a9_uploads[i]; + if (u->common < 40 + 8 * out->num_textures && u->common + u->dwords > 40) { + if (!out->a9_refusal[0]) + snprintf(out->a9_refusal, sizeof(out->a9_refusal), + "compute texture upload at common %u..%u overlaps storage image slots 40..%u", + u->common, u->common + u->dwords - 1, 40 + 8 * out->num_textures - 1); + return backend_failure(out, &(struct g9p_ctx){0}); + } } return true; } diff --git a/src/imagination/g9p/g9p_a9_intrinsics.h b/src/imagination/g9p/g9p_a9_intrinsics.h index 564a902d99d..ac46d7dc8bf 100644 --- a/src/imagination/g9p/g9p_a9_intrinsics.h +++ b/src/imagination/g9p/g9p_a9_intrinsics.h @@ -65,13 +65,44 @@ static bool a9_shared(struct g9p_ctx *ctx, nir_intrinsic_instr *in) static void a9_generate_init(struct g9p_ctx *ctx, nir_function_impl *impl) { ctx->a9_barriers_remaining = 0; + ctx->a9_storage_images = 0; + ctx->a9_sampled_images = 0; ctx->out->a9_device_fence = false; if (!ctx->out->a9) return; unsigned n = ctx->out->local_size[0] * ctx->out->local_size[1] * ctx->out->local_size[2]; + uint32_t st_keys[4], sm_keys[4]; + unsigned nst = 0, nsm = 0; nir_foreach_block(block, impl) { nir_foreach_instr(instr, block) { + if (instr->type == nir_instr_type_tex) { + nir_tex_instr *tex = nir_instr_as_tex(instr); + unsigned set, binding, element; + if (tex->op != nir_texop_txs && tex->op != nir_texop_query_levels && + a9_tex_var(tex, nir_tex_src_texture_deref, &set, &binding, &element)) { + const uint32_t k = (set << 16) | (binding << 8) | (element & 0xff); + bool seen = false; + for (unsigned i = 0; i < nsm; i++) + seen |= sm_keys[i] == k; + if (!seen && nsm < ARRAY_SIZE(sm_keys)) + sm_keys[nsm++] = k; + } + continue; + } if (instr->type != nir_instr_type_intrinsic) continue; nir_intrinsic_instr *in = nir_instr_as_intrinsic(instr); + if (in->intrinsic == nir_intrinsic_image_deref_load || + in->intrinsic == nir_intrinsic_image_deref_store) { + nir_deref_instr *deref = nir_src_as_deref(in->src[0]); + nir_variable *v = deref ? nir_deref_instr_get_variable(deref) : NULL; + if (v) { + const uint32_t k = (v->data.descriptor_set << 16) | v->data.binding; + bool seen = false; + for (unsigned i = 0; i < nst; i++) + seen |= st_keys[i] == k; + if (!seen && nst < ARRAY_SIZE(st_keys)) + st_keys[nst++] = k; + } + } if (in->intrinsic == nir_intrinsic_barrier && (nir_intrinsic_memory_modes(in) & (nir_var_mem_ssbo | nir_var_mem_global | nir_var_image))) ctx->out->a9_device_fence = true; @@ -82,6 +113,8 @@ static void a9_generate_init(struct g9p_ctx *ctx, nir_function_impl *impl) ctx->a9_barriers_remaining++; } } + ctx->a9_storage_images = (uint8_t)nst; + ctx->a9_sampled_images = (uint8_t)nsm; ctx->out->a9_has_barriers = n > 32 && ctx->a9_barriers_remaining; if (ctx->out->a9_has_barriers) ctx->busy |= ctx->pinned |= BITFIELD64_BIT(0); } @@ -344,10 +377,69 @@ static bool a9_image(struct g9p_ctx *ctx, nir_intrinsic_instr *in) } return true; } +/* textureDimensions() on a storage image (nir_intrinsic_image_deref_size): + * reuses the CPU-computed G9P_A9_UP_SIZE block (pvr_g5p_image_size() reads the + * storage descriptor's A9 image state), placed in common slots not occupied by + * storage or sampled images. */ +static bool a9_image_size(struct g9p_ctx *ctx, nir_intrinsic_instr *in) +{ + if (!ctx->out->a9 || ctx->stage != MESA_SHADER_COMPUTE) + return false; + if (nir_intrinsic_image_dim(in) == GLSL_SAMPLER_DIM_BUF) { + a9_tex_refuse(ctx, "storage texel-buffer size query in a compute shader"); + return false; + } + nir_deref_instr *deref = nir_src_as_deref(in->src[0]); + nir_variable *v = deref ? nir_deref_instr_get_variable(deref) : NULL; + unsigned element = 0; + if (!v) { + a9_tex_refuse(ctx, "storage image size query without a constant binding"); + return false; + } + if (deref->deref_type == nir_deref_type_array) { + if (!nir_src_is_const(deref->arr.index)) { + a9_tex_refuse(ctx, "storage image size query with a non-constant array index"); + return false; + } + element = nir_src_as_uint(deref->arr.index); + } else if (deref->deref_type != nir_deref_type_var) { + a9_tex_refuse(ctx, "storage image size query without a constant binding"); + return false; + } + if (!nir_src_is_const(in->src[1])) { + a9_tex_refuse(ctx, "storage image size query at a non-constant level"); + return false; + } + const unsigned level = nir_src_as_uint(in->src[1]); + const int common = a9_tex_upload(ctx, G9P_A9_UP_SIZE, v->data.descriptor_set, v->data.binding, element, 0, level); + if (common < 0) + return false; + int zero = const_reg(ctx, 0); + if (zero < 0 || (zero = low_reg(ctx, zero)) < 0) + return false; + const bool array_1d = nir_intrinsic_image_dim(in) == GLSL_SAMPLER_DIM_1D && nir_intrinsic_image_array(in); + const unsigned n = in->def.num_components; + int dst[4]; + for (unsigned c = 0; c < n; c++) { + if (!ctx->last_use[key(&in->def, c)]) { + dst[c] = -1; + continue; + } + dst[c] = alloc_reg(ctx); + if (dst[c] < 0) + return false; + g9p_mov_uniform(ctx->c, dst[c], common + (array_1d && c == 1 ? 2 : c), zero); + } + release(ctx, &in->instr); + for (unsigned c = 0; c < n; c++) + ctx->reg[key(&in->def, c)] = dst[c]; + return true; +} #define G9P_A9_INTRINSICS \ if (ctx->out->a9) { switch (intr->intrinsic) { \ case nir_intrinsic_image_deref_atomic: case nir_intrinsic_image_deref_atomic_swap: \ a9_tex_refuse(ctx, "image atomics unsupported on A9"); return false; \ + case nir_intrinsic_image_deref_size: return a9_image_size(ctx, intr); \ case nir_intrinsic_image_deref_store: case nir_intrinsic_image_deref_load: return a9_image(ctx, intr); \ case nir_intrinsic_shared_atomic: case nir_intrinsic_shared_atomic_swap: return a9_shared_atomic(ctx, intr); \ case nir_intrinsic_ssbo_atomic_swap: return a9_ssbo_cas(ctx, intr); \ diff --git a/src/imagination/g9p/g9p_a9_tex.h b/src/imagination/g9p/g9p_a9_tex.h index 3fa0e2d8402..53224541d7e 100644 --- a/src/imagination/g9p/g9p_a9_tex.h +++ b/src/imagination/g9p/g9p_a9_tex.h @@ -22,7 +22,6 @@ */ static const uint8_t a9_tex_image_dw[] = { 32, 48 }; static const uint8_t a9_tex_sampler_dw[] = { 58, 60, 62 }; -static const uint8_t a9_tex_size_dw[] = { 40, 44 }; static void a9_tex_refuse(struct g9p_ctx *ctx, const char *why) @@ -36,10 +35,27 @@ a9_tex_upload(struct g9p_ctx *ctx, unsigned kind, unsigned set, unsigned binding unsigned combined, unsigned level) { struct g9p_shader *out = ctx->out; + uint8_t size_dw[4]; + unsigned nsize = 0; + if (kind == G9P_A9_UP_SIZE) { + if (!ctx->a9_storage_images) { + size_dw[nsize++] = 40; + size_dw[nsize++] = 44; + } else { + if (!ctx->a9_sampled_images) { + size_dw[nsize++] = 32; + size_dw[nsize++] = 36; + } + if (ctx->a9_storage_images < 2 && ctx->a9_sampled_images < 2) { + size_dw[nsize++] = 48; + size_dw[nsize++] = 52; + } + } + } const uint8_t *slots = kind == G9P_A9_UP_IMAGE ? a9_tex_image_dw : - kind == G9P_A9_UP_SIZE ? a9_tex_size_dw : a9_tex_sampler_dw; + kind == G9P_A9_UP_SIZE ? size_dw : a9_tex_sampler_dw; const unsigned nslots = kind == G9P_A9_UP_IMAGE ? ARRAY_SIZE(a9_tex_image_dw) : - kind == G9P_A9_UP_SIZE ? ARRAY_SIZE(a9_tex_size_dw) : ARRAY_SIZE(a9_tex_sampler_dw); + kind == G9P_A9_UP_SIZE ? nsize : ARRAY_SIZE(a9_tex_sampler_dw); unsigned used = 0; for (unsigned i = 0; i < out->a9_num_uploads; i++) { @@ -52,14 +68,15 @@ a9_tex_upload(struct g9p_ctx *ctx, unsigned kind, unsigned set, unsigned binding return u->common; used += same_class; } - if (kind == G9P_A9_UP_IMAGE && slots[used < nslots ? used : 0] == 48 && out->num_textures >= 2) { + if (kind == G9P_A9_UP_IMAGE && nslots && slots[used < nslots ? used : 0] == 48 && out->num_textures >= 2) { a9_tex_refuse(ctx, "a second sampled texture with two storage images (both at common 48)"); return -1; } - if (used == nslots || out->a9_num_uploads == G9P_A9_MAX_UPLOADS || set > 255 || binding > 255 || + if (used >= nslots || out->a9_num_uploads == G9P_A9_MAX_UPLOADS || set > 255 || binding > 255 || element > 255 || level > 255) { a9_tex_refuse(ctx, kind == G9P_A9_UP_IMAGE ? "more than 2 sampled textures in a compute shader" : - kind == G9P_A9_UP_SIZE ? "more than 2 texture size queries in a compute shader" : + kind == G9P_A9_UP_SIZE ? (nslots ? "too many texture size queries in a compute shader" + : "no free common-store slot for texture size query") : "more than 3 samplers in a compute shader"); return -1; } diff --git a/src/imagination/vulkan/pvr_arch_g5p_compute.c b/src/imagination/vulkan/pvr_arch_g5p_compute.c index 7a3adb426e2..9bd423fe130 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_compute.c +++ b/src/imagination/vulkan/pvr_arch_g5p_compute.c @@ -110,7 +110,7 @@ PVR_PER_ARCH(g5p_compute_pipeline_compile)( if (!stub) { mesa_logw("pvr/g5p: compute pipeline refused: %s", reason); result = vk_errorf(device, VK_ERROR_FEATURE_NOT_PRESENT, - "G5P compute: shader not supported by the backend yet"); + "G5P compute: %s", reason); goto out; } state->a9_capture_stub = true; @@ -345,7 +345,7 @@ PVR_PER_ARCH(g5p_cmd_dispatch)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_suballoc_bo *uniforms_bo; uint32_t uniforms[2 * G9P_MAX_BUFFERS + 4 + 8 * G9P_A9_MAX_UPLOADS] = { 0 }; uint32_t bind_data[4 * (G9P_MAX_BUFFERS + 1) + 4 + 3 * G9P_A9_MAX_UPLOADS] = { 0 }; - uint32_t bind_code[G9P_MAX_BUFFERS + 5 + G9P_A9_MAX_UPLOADS]; + uint32_t bind_code[G9P_MAX_BUFFERS + 8 + G9P_A9_MAX_UPLOADS]; uint32_t kernel_data[12] = { 0 }, kernel_code[8]; bool from_uniforms[G9P_MAX_BUFFERS] = { false }; struct pvr_pds_upload bind, kernel; From aa52d5df003bd1ab9d8bce3beb84f12000f32fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:43:43 +0100 Subject: [PATCH 09/11] pvr/g5p: advertise STORAGE_IMAGE for 8- and 16-bit integer formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commits 5eb2d3fe942 ("pvr/g9p: A9 image stores of 8- and 16-bit integer formats") and 000b8499824 ("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 --- src/imagination/vulkan/pvr_g5p_format_table.h | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/imagination/vulkan/pvr_g5p_format_table.h b/src/imagination/vulkan/pvr_g5p_format_table.h index bb21e452bc3..1f1db6bab3c 100644 --- a/src/imagination/vulkan/pvr_g5p_format_table.h +++ b/src/imagination/vulkan/pvr_g5p_format_table.h @@ -182,25 +182,27 @@ static const struct pvr_g5p_format pvr_g5p_format_table[] = { G5P_FMT(A4B4G4R4_UNORM_PACK16, 2, false, G5P_SF | G5P_PS, AGX, 0x0c, 0, 1, 2, 3), /* integer (g3b-sample-b t5-t18, fmt-rgba8ui; textypes int-fetch and * int-sample on the device). RGBA32 UINT/SINT clear/draw/LOAD/masks - * passed the integer-r4 core/compat device cases. Narrow integer render - * targets remain absent or probe-only; integer blending is not exposed. */ - G5P_FMT(R8_UINT, 1, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x100, G5P_SEL_R001), - G5P_FMT(R8G8_UINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x10a, G5P_SEL_RG01), - G5P_FMT(R8G8B8A8_UINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x128, G5P_SEL_RGBA), + * passed the integer-r4 core/compat device cases; 8- and 16-bit integer + * compute storage loads/stores passed on S8003 (5eb2d3fe942, 000b8499824). + * Narrow integer render targets remain absent or probe-only; integer + * blending is not exposed. */ + G5P_FMT(R8_UINT, 1, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x100, G5P_SEL_R001), + G5P_FMT(R8G8_UINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x10a, G5P_SEL_RG01), + G5P_FMT(R8G8B8A8_UINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x128, G5P_SEL_RGBA), G5P_FMT(A8B8G8R8_UINT_PACK32, 4, false, G5P_SI, G5P1B, 0x128, G5P_SEL_RGBA), - G5P_FMT(R16_UINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x109, G5P_SEL_R001), - G5P_FMT(R16G16_UINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x123, G5P_SEL_RG01), - G5P_FMT(R16G16B16A16_UINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x132, G5P_SEL_RGBA), + G5P_FMT(R16_UINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x109, G5P_SEL_R001), + G5P_FMT(R16G16_UINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x123, G5P_SEL_RG01), + G5P_FMT(R16G16B16A16_UINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x132, G5P_SEL_RGBA), G5P_FMT(R32_UINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x121, G5P_SEL_R001), G5P_FMT(R32G32_UINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x131, G5P_SEL_RG01), G5P_FMT(R32G32B32A32_UINT, 16, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x138, G5P_SEL_RGBA), - G5P_FMT(R8_SINT, 1, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x180, G5P_SEL_R001), - G5P_FMT(R8G8_SINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x18a, G5P_SEL_RG01), - G5P_FMT(R8G8B8A8_SINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x1a8, G5P_SEL_RGBA), + G5P_FMT(R8_SINT, 1, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x180, G5P_SEL_R001), + G5P_FMT(R8G8_SINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x18a, G5P_SEL_RG01), + G5P_FMT(R8G8B8A8_SINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x1a8, G5P_SEL_RGBA), G5P_FMT(A8B8G8R8_SINT_PACK32, 4, false, G5P_SI, G5P1B, 0x1a8, G5P_SEL_RGBA), - G5P_FMT(R16_SINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x189, G5P_SEL_R001), - G5P_FMT(R16G16_SINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x1a3, G5P_SEL_RG01), - G5P_FMT(R16G16B16A16_SINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x1b2, G5P_SEL_RGBA), + G5P_FMT(R16_SINT, 2, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x189, G5P_SEL_R001), + G5P_FMT(R16G16_SINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x1a3, G5P_SEL_RG01), + G5P_FMT(R16G16B16A16_SINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x1b2, G5P_SEL_RGBA), G5P_FMT(R32_SINT, 4, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x1a1, G5P_SEL_R001), G5P_FMT(R32G32_SINT, 8, false, G5P_SI | PVR_G5P_FMT_RENDER, G5P1B, 0x1b1, G5P_SEL_RG01), G5P_FMT(R32G32B32A32_SINT, 16, false, G5P_SI | PVR_G5P_FMT_RENDER | PVR_G5P_FMT_STORAGE, G5P1B, 0x1b8, G5P_SEL_RGBA), From d95c0cb8d096ce2eab83b667cdeb0b5c92753083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 23:53:57 +0100 Subject: [PATCH 10/11] pvr/g5p: handle PCO_G5P_UPLOAD_FETCH_SAMPLER in colour LOAD background programs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 5c997f12743 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: bf7c56dc73d ("pvr/g5p: use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf") Assisted-by: LLM Signed-off-by: Berkay Kösebay --- src/imagination/vulkan/pvr_arch_g5p.c | 14 +++++++++----- src/imagination/vulkan/pvr_arch_g5p_upload.c | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index a6c38fc8d33..66a1c91c6e2 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -314,6 +314,7 @@ g5p_upload_load(struct pvr_device *device, struct pvr_g5p_programs *p, unsigned for (unsigned i = 0; i < prog.num_uploads; i++) { const struct pco_g5p_upload *u = &prog.uploads[i]; if ((u->kind != PCO_G5P_UPLOAD_IMAGE && u->kind != PCO_G5P_UPLOAD_SAMPLER && + u->kind != PCO_G5P_UPLOAD_FETCH_SAMPLER && u->kind != PCO_G5P_UPLOAD_IMAGE_SIZE) || u->set || u->binding >= (raw >= 12 && raw != G5P_LOAD_MS4 ? 8u : 1u)) { snprintf(p->load_refusal, sizeof(p->load_refusal), "a load program upload of kind %u at %u.%u", @@ -745,10 +746,11 @@ g5p_load_background(struct pvr_cmd_buffer *cmd_buffer, const uint64_t state[][4] .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, }; - uint64_t sampler[2] = { 0 }; + uint64_t sampler[4] = { 0 }; const char *why = pvr_g5p_sampler_encode(&sci, false, false, &sampler[0]); if (why) return G5P_REFUSE(cmd_buffer, "the load sampler: %s", why); + sampler[2] = pvr_g5p_fetch_sampler_word(); /* textureSize()'s block (PCO_G5P_UPLOAD_IMAGE_SIZE): width, height, layers, levels */ const uint32_t size[4] = { width, height, 1, 1 }; @@ -772,10 +774,12 @@ g5p_load_background(struct pvr_cmd_buffer *cmd_buffer, const uint64_t state[][4] uint32_t data[4 * ARRAY_SIZE(p->load_upload)] = { 0 }; for (unsigned i = 0; i < n; i++) { const unsigned kind = p->load_upload[i].kind; - const uint64_t src = kind == PCO_G5P_UPLOAD_IMAGE ? state_bo->dev_addr.addr + 32 * p->load_upload[i].binding - : kind == PCO_G5P_UPLOAD_SAMPLER ? sampler_bo->dev_addr.addr - : size_bo->dev_addr.addr; - if (p->load_upload[i].dwords > (kind == PCO_G5P_UPLOAD_IMAGE ? 8u : kind == PCO_G5P_UPLOAD_SAMPLER ? 2u : 4u)) + const bool is_sampler = kind == PCO_G5P_UPLOAD_SAMPLER || kind == PCO_G5P_UPLOAD_FETCH_SAMPLER; + const uint64_t src = kind == PCO_G5P_UPLOAD_IMAGE ? state_bo->dev_addr.addr + 32 * p->load_upload[i].binding + : kind == PCO_G5P_UPLOAD_SAMPLER ? sampler_bo->dev_addr.addr + : kind == PCO_G5P_UPLOAD_FETCH_SAMPLER ? sampler_bo->dev_addr.addr + 16 + : size_bo->dev_addr.addr; + if (p->load_upload[i].dwords > (kind == PCO_G5P_UPLOAD_IMAGE ? 8u : is_sampler ? 2u : 4u)) return G5P_REFUSE(cmd_buffer, "a load program upload of %u dwords", p->load_upload[i].dwords); data[2 * i] = (uint32_t)src; data[2 * i + 1] = (uint32_t)(src >> 32); diff --git a/src/imagination/vulkan/pvr_arch_g5p_upload.c b/src/imagination/vulkan/pvr_arch_g5p_upload.c index 714a7c4b727..4385a9fb3df 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_upload.c +++ b/src/imagination/vulkan/pvr_arch_g5p_upload.c @@ -76,6 +76,7 @@ g5p_up_kind_str(unsigned kind) case PCO_G5P_UPLOAD_SSBO_ADDR: return "a storage buffer address"; case PCO_G5P_UPLOAD_IMAGE: return "an image state"; case PCO_G5P_UPLOAD_SAMPLER: return "a sampler"; + case PCO_G5P_UPLOAD_FETCH_SAMPLER: return "a fetch sampler"; case PCO_G5P_UPLOAD_PUSH: return "push constants"; case PCO_G5P_UPLOAD_UBO: return "a uniform buffer"; case PCO_G5P_UPLOAD_UBO_ADDR: return "a uniform buffer address"; From 21daf4eddca9d9841982eab21c566841d2f57dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Thu, 3 Dec 2026 00:04:42 +0100 Subject: [PATCH 11/11] pvr/g5p: keep the colour LOAD programs on their own sampler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 5c997f12743 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 5c997f12743; compute uses the G9P uploads. Fixes: bf7c56dc73d ("pvr/g5p: use PCO_G5P_UPLOAD_FETCH_SAMPLER for samplerless fragment txf") Assisted-by: LLM Signed-off-by: Berkay Kösebay --- src/imagination/g5p/pco_g5p_general.c | 2 +- src/imagination/g5p/pco_g5p_general.h | 4 ++++ src/imagination/vulkan/pvr_g5p_nir.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/imagination/g5p/pco_g5p_general.c b/src/imagination/g5p/pco_g5p_general.c index 99a796f38d6..ba4b9d9b61e 100644 --- a/src/imagination/g5p/pco_g5p_general.c +++ b/src/imagination/g5p/pco_g5p_general.c @@ -2380,7 +2380,7 @@ static void plan_common(struct gctx *c) if (g5p_usc_g4p && !g5p_usc_g4p_a9_forms && compact && c->ntex && !(c->vs && g5p_usc_g4p_vtex)) refuse(c, "the A8 samples one image slot (common dword 0); more than four textures or vertex textures are " "not captured"); - const bool fs_fetch = !c->vs && !g5p_usc_g4p; + const bool fs_fetch = !c->vs && !g5p_usc_g4p && !c->key->txf_own_sampler; const bool use_fetch = qualified || fs_fetch; unsigned sampler_count = 0; bool fetch_sampler = false; diff --git a/src/imagination/g5p/pco_g5p_general.h b/src/imagination/g5p/pco_g5p_general.h index 013dd9b6ee5..7bcc92ec35e 100644 --- a/src/imagination/g5p/pco_g5p_general.h +++ b/src/imagination/g5p/pco_g5p_general.h @@ -143,6 +143,10 @@ struct pco_g5p_fs_key { * Apple's 4x form); several discards keep the one-sample test (Apple's several-discard 4x form is not * ported: such draws are refused at 4x) */ bool ms4_kill; + /* The driver's own background programs (the colour LOAD programs): the driver supplies each texture's + * sampler (g5p_load_background()), so a samplerless texelFetch keeps a PCO_G5P_UPLOAD_SAMPLER slot per + * texture instead of the shared PCO_G5P_UPLOAD_FETCH_SAMPLER of application fragment programs. */ + bool txf_own_sampler; }; #define PCO_G5P_HAS_MASK_UPASS 1 #define PCO_G5P_FS_KEY_DEFAULT ((struct pco_g5p_fs_key){.write_mask = 0xf}) diff --git a/src/imagination/vulkan/pvr_g5p_nir.c b/src/imagination/vulkan/pvr_g5p_nir.c index a7a350a9287..be21e3ddd22 100644 --- a/src/imagination/vulkan/pvr_g5p_nir.c +++ b/src/imagination/vulkan/pvr_g5p_nir.c @@ -1448,6 +1448,7 @@ g5p_compile_load_type(struct pco_g5p_program *out, unsigned raw) * output component 0 (B G R A = 0 0 R 0). */ struct pco_g5p_fs_key key = PCO_G5P_FS_KEY_DEFAULT; key.last_read_groups = true; + key.txf_own_sampler = true; /* g5p_load_background() supplies the sampler, as before the fetch sampler */ key.packed_uint_bits = (raw == 5 || raw == 9) ? 16 : (raw == 6 || raw == 8 || raw == 10 || raw == 11) ? 8 : raw == 7 ? 10 : 0; key.packed_sint = raw == 8 || raw == 9 || raw == 11; key.packed_scalar8 = raw == 10 || raw == 11; @@ -1576,6 +1577,7 @@ pvr_g5p_compile_load_mrt(struct pco_g5p_program *out, unsigned targets, bool bgr nir_shader *nir = graphics_lower(g5p_nir_prepare(b.shader), targets, &sample_mask, false, NULL); struct pco_g5p_fs_key key = PCO_G5P_FS_KEY_DEFAULT; key.last_read_groups = true; + key.txf_own_sampler = true; key.color_targets = targets; key.color_output = bgra ? PCO_G5P_COLOR_PACKED_BGRA8 : PCO_G5P_COLOR_PACKED_RGBA8; bool ok = nir && pco_g5p_compile_general_link(nir, true, NULL, &key, NULL, out);