diff --git a/src/asahi/lib/tests/test-agx-g17p-mrt-mixed.c b/src/asahi/lib/tests/test-agx-g17p-mrt-mixed.c index 78ecef5f51b2..4b83d291002d 100644 --- a/src/asahi/lib/tests/test-agx-g17p-mrt-mixed.c +++ b/src/asahi/lib/tests/test-agx-g17p-mrt-mixed.c @@ -1814,6 +1814,66 @@ test_wide_samples(void) return 0; } +/* Direct EOT MSAA resolve from mixed/subset MRT tilebuffers: both a single + * resolved target at a non-zero sample offset (the 5-RT deferred local-read + * shape) and a multi-target resolve-only EOT emit 2D resolving IMGWBLK + * selectors (low nibble 5, wire-width bit 1 clear) rather than MS store. */ +static int +test_multisample_direct_resolve_eot(void) +{ + /* Single resolved RGBA8 target at byte offset 20 in a 24 B/sample tile. */ + { + const enum pipe_format fmt = PIPE_FORMAT_R8G8B8A8_UNORM; + const uint8_t offset = 20; + struct agx_shader_key key = { + .dev.encoding = AGX_ISA_ENCODING_AGX3B, + .no_preamble = true, + .g17p_rt0_eot_multisample = false, + }; + agx_g17p_configure_rt0_eot_key(fmt, &key); + struct agx_shader_part part = {0}; + CHECK(compile_eot(1, &fmt, &offset, &key, &part)); + CHECK(part.info.binary_size == 68); + CHECK(part.info.nr_gprs == 8); + CHECK(part.info.agx3_staging_known && part.info.agx3_staging_halfs == 8); + CHECK(((const uint8_t *)part.binary)[61] == 0x75); + free(part.binary); + } + + /* Two resolved targets (RGBA8 + RGBA16F) in a mixed MSAA tilebuffer. */ + { + const enum pipe_format fmts[2] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_R16G16B16A16_FLOAT, + }; + const uint8_t offsets[2] = {20, 8}; + struct agx_shader_key key = { + .dev.encoding = AGX_ISA_ENCODING_AGX3B, + .no_preamble = true, + .g17p_rt0_eot_multisample = false, + .g17p_mrt_eot_count = 2, + .g17p_mrt_eot_selectors = { + agx_g17p_mrt_eot_selector(fmts[0]), + agx_g17p_mrt_eot_selector(fmts[1]), + }, + }; + agx_g17p_configure_rt0_eot_key(fmts[0], &key); + struct agx_shader_part part = {0}; + CHECK(compile_eot(2, fmts, offsets, &key, &part)); + CHECK(part.info.binary_size == 32 + 44 * 2); + CHECK(part.info.nr_gprs == 8); + CHECK(part.info.agx3_staging_known && part.info.agx3_staging_halfs == 16); + const uint8_t *bin = part.binary; + CHECK(bin[92 + 9] == 0x75); + CHECK(bin[104 + 9] == 0x15); + CHECK((bin[92 + 8] & 0x80) != 0); + CHECK((bin[104 + 8] & 0x80) != 0); + free(part.binary); + } + + return 0; +} + /* End-to-end compile-and-pack check for single-RT 4-sample background and * sample-shaded fragment shaders on AGX3B (G17P/G16G), verifying both r32f * and rg32f unrolled per-sample txf+st_tile shaders compile without scratch @@ -1919,7 +1979,8 @@ main(void) test_background_programs() || test_epilogs() || test_reused_mrt_payloads() || test_subset_epilogs() || test_octa_subset_epilogs() || - test_multisample_eot_witnesses() || test_multisample_epilogs() || + test_multisample_eot_witnesses() || + test_multisample_direct_resolve_eot() || test_multisample_epilogs() || test_blended_epilogs() || test_preserved_blended_epilogs() || test_wide_samples() || test_multisample_background_load()) return 1; diff --git a/src/asahi/vulkan/hk_agx3_ioto_program_core.c b/src/asahi/vulkan/hk_agx3_ioto_program_core.c index a5d615041d87..a429f19e5e22 100644 --- a/src/asahi/vulkan/hk_agx3_ioto_program_core.c +++ b/src/asahi/vulkan/hk_agx3_ioto_program_core.c @@ -151,9 +151,17 @@ hk_agx3_format_needs_shader_resolve(enum pipe_format format) bool hk_agx3_g17p_direct_color_resolve_supported( struct agx_tilebuffer_layout *tib, unsigned color_attachment_count, - bool has_resolve_target, bool average_resolve, bool store_source) + bool has_resolve_target, bool average_resolve, bool store_source, + bool r11g11b10_own_class) { - if (!tib || hk_agx3_format_needs_shader_resolve(tib->logical_format[0])) + /* When the device does not store R11G11B10_FLOAT through its own PBE class + * (hk_eot_r11g11b10_own_class(), false on G15x and G16G without the own + * class), the EOT PBE uses raw R32_UINT and averages raw bit patterns + * instead of packed float fields. Keep samples for shader resolve there; + * chips with the own class (G17P) average accurately in EOT. */ + if (!tib || hk_agx3_format_needs_shader_resolve(tib->logical_format[0]) || + (tib->logical_format[0] == PIPE_FORMAT_R11G11B10_FLOAT && + !r11g11b10_own_class)) return false; return (tib->nr_samples == 2 || tib->nr_samples == 4) && @@ -162,6 +170,70 @@ hk_agx3_g17p_direct_color_resolve_supported( hk_agx3_g17p_rt0_tile_layout_supported(tib); } +bool +hk_agx3_g17p_mixed_direct_color_resolve_supported( + const struct agx_tilebuffer_layout *framebuffer_tib, + const struct hk_agx3_g17p_mixed_resolve_target *stored_targets, + unsigned stored_count, bool partial_render, bool incomplete_render_area, + bool suspend_resume, bool any_unstored_resolve, + unsigned color_and_resolve_views) +{ + if (!framebuffer_tib || !stored_targets || stored_count == 0 || + stored_count > AGX_MAX_RENDER_TARGETS) + return false; + + /* Partial renders and suspended/resumed dynamic rendering instances must + * not direct-resolve: suspended halves keep unresolved samples for resume, + * and resumed halves return early from hk_begin_rendering() before + * loaded_resolve/process_empty_tiles are configured so a direct-resolving + * EOT could miss tiles drawn only by the suspended half. Mixed BG has no + * preserve_resolve_outside path for incomplete render areas (partial + * renderArea or sparse multiview viewMask). Direct resolve also sets the + * pass-wide g17p_direct_color_resolve flag, so every resolving attachment + * must be stored in-tile (no spills, no unstored resolves) and retained + * color+resolve views must leave headroom for depth and stencil within the + * kernel's fragment write-range budget. */ + if (partial_render || incomplete_render_area || suspend_resume || + any_unstored_resolve || + (framebuffer_tib->nr_samples != 2 && framebuffer_tib->nr_samples != 4) || + agx_tilebuffer_spills((struct agx_tilebuffer_layout *)framebuffer_tib) || + color_and_resolve_views > HK_AGX3_G17P_MAX_COLOR_RESOLVE_WRITE_RANGES) + return false; + + for (unsigned i = 0; i < stored_count; ++i) { + const struct hk_agx3_g17p_mixed_resolve_target *t = &stored_targets[i]; + if (!t->has_resolve_target || !t->average_resolve || t->store_source || + !t->resolve_pbe_valid || !t->resolve_format_matches || + t->resolve_samples != 1) + return false; + + /* Check the unmapped API/view format as well as the EOT key format: + * on chips with hk_eot_r11g11b10_own_class() (G17P, see hk_image.h), + * hk_eot_key_format() remaps R11G11B10_FLOAT to R10G10B10A2_UNORM and + * selects the format's own PBE class, which averages packed floats + * accurately; on chips without it (G15x, and G16G without the own + * class), the PBE uses raw R32_UINT and averages raw bits. Refusing + * R11G11B10_FLOAT via both formats here is required on raw-class chips + * and conservative (forgoing the mixed-MRT fast path) on G17P. Also + * exclude sRGB and pure integer formats via the unmapped view format so + * mixed direct resolve never depends on hk_eot_key_format() leaving them + * intact. */ + if (t->format == PIPE_FORMAT_NONE || + t->view_format == PIPE_FORMAT_NONE || + hk_agx3_format_needs_shader_resolve(t->format) || + hk_agx3_format_needs_shader_resolve(t->view_format) || + t->format == PIPE_FORMAT_R11G11B10_FLOAT || + t->view_format == PIPE_FORMAT_R11G11B10_FLOAT || + util_format_is_srgb(t->format) || + util_format_is_srgb(t->view_format) || + util_format_is_pure_integer(t->format) || + util_format_is_pure_integer(t->view_format)) + return false; + } + + return true; +} + bool hk_agx3_g17p_store_and_resolve_supported( const struct agx_tilebuffer_layout *tib, diff --git a/src/asahi/vulkan/hk_agx3_ioto_program_core.h b/src/asahi/vulkan/hk_agx3_ioto_program_core.h index 857dee8994b6..e37dfe845426 100644 --- a/src/asahi/vulkan/hk_agx3_ioto_program_core.h +++ b/src/asahi/vulkan/hk_agx3_ioto_program_core.h @@ -251,7 +251,36 @@ bool hk_agx3_g17p_multisample_store_supported(struct agx_tilebuffer_layout *tib, bool hk_agx3_g17p_direct_color_resolve_supported( struct agx_tilebuffer_layout *tib, unsigned color_attachment_count, - bool has_resolve_target, bool average_resolve, bool store_source); + bool has_resolve_target, bool average_resolve, bool store_source, + bool r11g11b10_own_class); + +/* Native AGX3 fragment attachment capture encodes at most 16 write ranges in + * the kernel (distinct from HK_DRM_MAX_FRAGMENT_ATTACHMENTS = 20, which sizes + * the uapi array for AGX2). Reserving 2 slots for depth and stencil leaves 14 + * slots for color and direct-resolve views. */ +#define HK_AGX3_G17P_MAX_FRAGMENT_WRITE_RANGES 16u +#define HK_AGX3_G17P_MAX_DEPTH_STENCIL_WRITE_RANGES 2u +#define HK_AGX3_G17P_MAX_COLOR_RESOLVE_WRITE_RANGES \ + (HK_AGX3_G17P_MAX_FRAGMENT_WRITE_RANGES - \ + HK_AGX3_G17P_MAX_DEPTH_STENCIL_WRITE_RANGES) + +struct hk_agx3_g17p_mixed_resolve_target { + enum pipe_format format; + enum pipe_format view_format; + bool has_resolve_target; + bool average_resolve; + bool store_source; + bool resolve_pbe_valid; + bool resolve_format_matches; + unsigned resolve_samples; +}; + +bool hk_agx3_g17p_mixed_direct_color_resolve_supported( + const struct agx_tilebuffer_layout *framebuffer_tib, + const struct hk_agx3_g17p_mixed_resolve_target *stored_targets, + unsigned stored_count, bool partial_render, bool incomplete_render_area, + bool suspend_resume, bool any_unstored_resolve, + unsigned color_and_resolve_views); /* The single colour attachment of a pass whose final end-of-tile program * would both store the multisample samples and resolve them. */ diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index d2a719a479ed..ac13ad75d504 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -426,21 +426,21 @@ hk_g17p_bg_eot_shader_supported(const struct agx_bg_eot_shader *shader) static struct hk_bg_eot hk_build_g17p_mixed_bg_eot(struct hk_cmd_buffer *cmd, const struct agx_bg_eot_key *framebuffer_key, - const VkRenderingInfo *info, bool store) + const VkRenderingInfo *info, bool store, + bool partial_render, bool incomplete_render_area) { struct hk_device *dev = hk_cmd_buffer_device(cmd); + struct hk_rendering_state *render = &cmd->state.gfx.render; struct agx_bg_eot_key key = *framebuffer_key; memset(key.tib.logical_format, 0, sizeof(key.tib.logical_format)); memset(key.tib.spilled, 0, sizeof(key.tib.spilled)); memset(key.tib._offset_B, 0, sizeof(key.tib._offset_B)); memset(key.op, 0, sizeof(key.op)); key.mixed_mrt = true; - /* Multisample targets are stored unresolved: a multi-target pass - * resolves afterwards, from the multisample images. */ - key.multisample_store = store && key.tib.nr_samples > 1; const VkRenderingAttachmentInfo *atts[HK_MAX_RTS]; struct hk_image_view *views[HK_MAX_RTS]; + unsigned logical_rts[HK_MAX_RTS]; static const enum agx_bg_eot_op order[] = {AGX_BG_LOAD, AGX_BG_CLEAR, AGX_EOT_STORE}; unsigned count = 0, reloads = 0; @@ -449,7 +449,7 @@ hk_build_g17p_mixed_bg_eot(struct hk_cmd_buffer *cmd, if (framebuffer_key->op[rt] != order[i]) continue; - struct hk_image_view *view = cmd->state.gfx.render.color_att[rt].iview; + struct hk_image_view *view = render->color_att[rt].iview; if (count == ARRAY_SIZE(views) || rt >= info->colorAttachmentCount || !view || view->vk.image->samples != MAX2(key.tib.nr_samples, 1) || @@ -463,11 +463,72 @@ hk_build_g17p_mixed_bg_eot(struct hk_cmd_buffer *cmd, key.tib._offset_B[count] = framebuffer_key->tib._offset_B[rt]; key.op[count] = order[i]; atts[count] = &info->pColorAttachments[rt]; + logical_rts[count] = rt; views[count++] = view; reloads += order[i] == AGX_BG_LOAD; } } + /* Resolve-only final EOTs on mixed/subset MRT passes (such as a 5-RT + * deferred local-read pass with 4 DONT_CARE G-buffers and 1 resolved color + * target) can resolve directly through single-sample PBE descriptors in EOT + * instead of storing unresolved MSAA samples and running a post-pass meta + * resolve. Partial renders and non-eligible passes keep unresolved MSAA + * stores. */ + bool direct_resolve = false; + if (store && count > 0) { + struct hk_agx3_g17p_mixed_resolve_target resolve_targets[HK_MAX_RTS] = {0}; + for (unsigned i = 0; i < count; ++i) { + const struct hk_image_view *resolve_view = + render->color_att[logical_rts[i]].resolve_iview; + const bool resolve_pbe_valid = + resolve_view && (key.tib.layered + ? resolve_view->planes[0].layered_eot_pbe_valid + : resolve_view->planes[0].eot_pbe_valid); + resolve_targets[i] = (struct hk_agx3_g17p_mixed_resolve_target){ + .format = key.tib.logical_format[i], + .view_format = hk_format_to_pipe_format(views[i]->vk.format), + .has_resolve_target = + atts[i]->resolveImageView != VK_NULL_HANDLE && + atts[i]->resolveMode != VK_RESOLVE_MODE_NONE && + resolve_view != NULL, + .average_resolve = + atts[i]->resolveMode == VK_RESOLVE_MODE_AVERAGE_BIT, + .store_source = atts[i]->storeOp == VK_ATTACHMENT_STORE_OP_STORE, + .resolve_pbe_valid = resolve_pbe_valid, + .resolve_format_matches = + resolve_view && resolve_view->vk.format == views[i]->vk.format, + .resolve_samples = + resolve_view ? resolve_view->vk.image->samples : 0, + }; + } + + const bool suspend_resume = + (render->flags & + (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT)) != 0; + bool any_unstored_resolve = false; + unsigned color_and_resolve_views = 0; + for (unsigned rt = 0; rt < info->colorAttachmentCount; ++rt) { + const VkRenderingAttachmentInfo *att = &info->pColorAttachments[rt]; + if (att->imageView == VK_NULL_HANDLE) + continue; + if (rt < render->color_att_count) { + color_and_resolve_views += render->color_att[rt].iview != NULL; + color_and_resolve_views += + render->color_att[rt].resolve_iview != NULL; + } + if (att->resolveMode != VK_RESOLVE_MODE_NONE && + (rt >= HK_MAX_RTS || framebuffer_key->op[rt] != AGX_EOT_STORE)) + any_unstored_resolve = true; + } + + direct_resolve = hk_agx3_g17p_mixed_direct_color_resolve_supported( + &framebuffer_key->tib, resolve_targets, count, partial_render, + incomplete_render_area, suspend_resume, any_unstored_resolve, + color_and_resolve_views); + } + key.multisample_store = store && !direct_resolve && key.tib.nr_samples > 1; + const unsigned descriptor_generation = agx_chip_descriptor_generation(dev->dev.chip); if (hk_pbe_descriptor_size(descriptor_generation) != @@ -564,14 +625,18 @@ hk_build_g17p_mixed_bg_eot(struct hk_cmd_buffer *cmd, */ struct hk_native_pbe_descriptor pbe_arguments[HK_MAX_RTS] = {0}; for (unsigned rt = 0; rt < count; ++rt) { - if (!(key.tib.layered ? views[rt]->planes[0].layered_eot_pbe_valid - : views[rt]->planes[0].eot_pbe_valid)) { + struct hk_image_view *target = + direct_resolve ? render->color_att[logical_rts[rt]].resolve_iview + : views[rt]; + if (!target || + !(key.tib.layered ? target->planes[0].layered_eot_pbe_valid + : target->planes[0].eot_pbe_valid)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FORMAT_NOT_SUPPORTED); return (struct hk_bg_eot){0}; } - pbe_arguments[rt] = key.tib.layered ? views[rt]->planes[0].layered_eot - : views[rt]->planes[0].eot; + pbe_arguments[rt] = key.tib.layered ? target->planes[0].layered_eot + : target->planes[0].eot; } const uint64_t pbe_argument_va = hk_pool_upload( @@ -679,6 +744,9 @@ hk_build_g17p_mixed_bg_eot(struct hk_cmd_buffer *cmd, if (!published) return (struct hk_bg_eot){0}; + if (direct_resolve) + render->g17p_direct_color_resolve = true; + return (struct hk_bg_eot){ .usc = published, .rsrc_spec = resource_spec, @@ -1021,7 +1089,7 @@ static struct hk_bg_eot hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, struct agx_bg_eot_key *key, const VkRenderingInfo *info, bool store, - bool partial_render, + bool partial_render, bool incomplete_render_area, struct hk_g17p_bg_eot_dev_cache *dc, bool *in_device) { struct hk_device *dev = hk_cmd_buffer_device(cmd); @@ -1038,7 +1106,8 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, assert(!dc); if (dc) return (struct hk_bg_eot){0}; - return hk_build_g17p_mixed_bg_eot(cmd, key, info, store); + return hk_build_g17p_mixed_bg_eot(cmd, key, info, store, partial_render, + incomplete_render_area); } /* Vulkan keeps unused colour attachments as holes in the logical array. @@ -1065,20 +1134,35 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, compact_info.pColorAttachments = attachments; key = &compact_key; info = &compact_info; + const struct hk_rendering_state *render = &cmd->state.gfx.render; + const bool r11g11b10_own_class = hk_eot_r11g11b10_own_class(&dev->dev); + const bool suspend_resume = + (render->flags & + (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT)) != 0; + /* Single-target direct resolve supports partial renderArea via + * preserve_resolve_outside, while refusing sparse multiview viewMask. + * Both are false whenever incomplete_render_area is false. */ + const bool sparse_view_mask = + incomplete_render_area && render->view_mask && + render->view_mask != BITFIELD64_MASK(render->cr.layers); if (!store && !partial_render && active_count == 1) { const VkRenderingAttachmentInfo *att = &attachments[0]; - const struct hk_rendering_state *render = &cmd->state.gfx.render; - const bool partial_area = render->area.offset.x || render->area.offset.y || - render->area.extent.width < render->cr.width || - render->area.extent.height < render->cr.height; + const bool partial_area = incomplete_render_area && + (render->area.offset.x || render->area.offset.y || + render->area.extent.width < render->cr.width || + render->area.extent.height < render->cr.height); /* The EOT resolve writes full tiles. Merge the destination outside the - * API rectangle before that store, retaining native MSAA resolution. */ - key->preserve_resolve_outside = partial_area && + * API rectangle before that store, retaining native MSAA resolution. + * Suspended/resumed passes and sparse multiview masks must not + * direct-resolve. */ + key->preserve_resolve_outside = partial_area && !suspend_resume && + !sparse_view_mask && hk_agx3_g17p_direct_color_resolve_supported( &key->tib, active_count, att->resolveImageView != VK_NULL_HANDLE, att->resolveMode == VK_RESOLVE_MODE_AVERAGE_BIT, - att->storeOp == VK_ATTACHMENT_STORE_OP_STORE); + att->storeOp == VK_ATTACHMENT_STORE_OP_STORE, + r11g11b10_own_class); } if (!hk_agx3_g17p_rt0_tile_layout_supported(&key->tib)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); @@ -1096,8 +1180,9 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, * leave holes before the sole live color attachment; selecting from * logical slot0 and colorAttachmentCount before compaction loses its * STORE requirement and selects a single-sample EOT for an MS surface. - * Keep samples for partial renders, explicit STORE, and resolves that - * execute after the pass. Final direct resolves remain single-sampled. */ + * Keep samples for partial renders, suspended/resumed passes, sparse + * multiview masks, explicit STORE, and resolves that execute after the + * pass. Final direct resolves remain single-sampled. */ if (store && active_count == 1) { const VkRenderingAttachmentInfo *att = &attachments[0]; const struct hk_image_view *iview = color_att[0].iview; @@ -1105,9 +1190,11 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, const bool has_resolve = att->resolveImageView != VK_NULL_HANDLE && att->resolveMode != VK_RESOLVE_MODE_NONE; const bool resolved_after_pass = has_resolve && - !hk_agx3_g17p_direct_color_resolve_supported( - &key->tib, active_count, has_resolve, - att->resolveMode == VK_RESOLVE_MODE_AVERAGE_BIT, store_source); + (suspend_resume || sparse_view_mask || + !hk_agx3_g17p_direct_color_resolve_supported( + &key->tib, active_count, has_resolve, + att->resolveMode == VK_RESOLVE_MODE_AVERAGE_BIT, store_source, + r11g11b10_own_class)); key->multisample_store = hk_agx3_g17p_multisample_store_supported( &key->tib, active_count, partial_render || store_source || resolved_after_pass, @@ -1132,7 +1219,8 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, .source_pbe_valid = iview && iview->planes[0].eot_pbe_valid, .resolve_pbe_valid = resolve && resolve->planes[0].eot_pbe_valid, }; - key->store_and_resolve = key->multisample_store && + key->store_and_resolve = key->multisample_store && !suspend_resume && + !sparse_view_mask && hk_agx3_g17p_store_and_resolve_supported(&key->tib, &fused); } @@ -1312,12 +1400,13 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, * which is what key->multisample_store selects below. */ const bool direct_resolve = - !partial_render && + !partial_render && !suspend_resume && !sparse_view_mask && hk_agx3_g17p_direct_color_resolve_supported( &key->tib, info->colorAttachmentCount, att->resolveImageView != VK_NULL_HANDLE, att->resolveMode == VK_RESOLVE_MODE_AVERAGE_BIT, - att->storeOp == VK_ATTACHMENT_STORE_OP_STORE); + att->storeOp == VK_ATTACHMENT_STORE_OP_STORE, + r11g11b10_own_class); struct hk_image_view *target = direct_resolve ? color_att[0].resolve_iview : iview; struct hk_image_view *iview1 = dual_mrt_active @@ -1394,8 +1483,10 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, struct hk_native_pbe_descriptor pbe_arguments[4] = {target_pbe}; /* The native resolve averages in linear space when its PBE requests * the sRGB transfer. Ordinary stores already have encoded tile bytes - * and retain the unmodified end-of-tile descriptor. */ - if (direct_resolve && util_format_is_srgb(key->tib.logical_format[0]) && + * and retain the unmodified end-of-tile descriptor. Check the unmapped + * view format so this never depends on hk_eot_key_format(). */ + if (direct_resolve && + util_format_is_srgb(hk_format_to_pipe_format(iview->vk.format)) && !(color_att[0].flags & VK_RENDERING_ATTACHMENT_RESOLVE_SKIP_TRANSFER_FUNCTION_BIT_KHR)) ((uint8_t *)&pbe_arguments[0])[15] |= 0x20; @@ -1683,6 +1774,7 @@ struct hk_g17p_bg_eot_cache_key { uint32_t layers; uint8_t color_attachment_count; bool incomplete_render_area; + bool suspend_resume; }; static uint64_t @@ -1720,6 +1812,9 @@ hk_g17p_bg_eot_cache_get(struct hk_cmd_buffer *cmd, .layers = cmd->state.gfx.render.cr.layers, .color_attachment_count = info->colorAttachmentCount, .incomplete_render_area = incomplete_render_area, + .suspend_resume = + (cmd->state.gfx.render.flags & + (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT)) != 0, }; for (unsigned i = 0; i < info->colorAttachmentCount; ++i) { const VkRenderingAttachmentInfo *att = &info->pColorAttachments[i]; @@ -2834,7 +2929,9 @@ hk_build_bg_eot_program(struct hk_cmd_buffer *cmd, const VkRenderingInfo *info, HK_G17P_BG_EOT_DEV_DATA_MAX, 32)) { bool in_device = false; program = hk_build_g17p_bg_eot(cmd, &key, info, store, - partial_render, dc, &in_device); + partial_render, + incomplete_render_area, dc, + &in_device); built = true; if (program.usc && in_device && !vk_command_buffer_has_error(&cmd->vk)) { @@ -2851,7 +2948,8 @@ hk_build_bg_eot_program(struct hk_cmd_buffer *cmd, const VkRenderingInfo *info, } if (!built) program = hk_build_g17p_bg_eot(cmd, &key, info, store, - partial_render, NULL, NULL); + partial_render, + incomplete_render_area, NULL, NULL); if (cache && program.usc && !vk_command_buffer_has_error(&cmd->vk)) { cache->program[variant] = program; cache->valid_variants |= BITFIELD_BIT(variant); @@ -5500,9 +5598,19 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, clear_draw_skips_zs = true; } /* Resolves of loaded samples write the destination even without geometry. */ - const bool loaded_resolve = - render->g17p_direct_color_resolve && - pRenderingInfo->pColorAttachments[0].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD; + bool loaded_resolve = false; + if (render->g17p_direct_color_resolve) { + for (uint32_t i = 0; i < pRenderingInfo->colorAttachmentCount; ++i) { + const VkRenderingAttachmentInfo *att = + &pRenderingInfo->pColorAttachments[i]; + if (att->imageView != VK_NULL_HANDLE && + att->resolveMode != VK_RESOLVE_MODE_NONE && + att->loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { + loaded_resolve = true; + break; + } + } + } const bool process_empty_tiles = resolved_clear || resolved_clear_z || resolved_clear_s || loaded_resolve; render->process_empty_tiles_without_z = diff --git a/src/asahi/vulkan/tests/test-hk-agx3-ioto-program-core.c b/src/asahi/vulkan/tests/test-hk-agx3-ioto-program-core.c index 881bb50653da..3aa7a37b10de 100644 --- a/src/asahi/vulkan/tests/test-hk-agx3-ioto-program-core.c +++ b/src/asahi/vulkan/tests/test-hk-agx3-ioto-program-core.c @@ -1996,7 +1996,7 @@ test_g17p_single_layer_rt0_layout(void) CHECK(tib.nr_samples == 2 && tib.sample_size_B == 8 && tib.tile_size == 32 * 32 && !tib.spilled[0]); CHECK(hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, false)); + &tib, 1, true, true, false, false)); enum pipe_format bgra_srgb[AGX_MAX_RENDER_TARGETS] = { PIPE_FORMAT_B8G8R8A8_SRGB, @@ -2007,13 +2007,13 @@ test_g17p_single_layer_rt0_layout(void) tib.sample_size_B == 8 && tib.tile_size == 32 * 32 && !tib.spilled[0]); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 2, true, true, false)); + &tib, 2, true, true, false, false)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, false, true, false)); + &tib, 1, false, true, false, false)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, false, false)); + &tib, 1, true, false, false, false)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, true)); + &tib, 1, true, true, true, false)); tib = agx_build_tilebuffer_layout(rgba, 1, 4, false); const struct agx_usc_shared_packed msaa4_usc = tib.usc; CHECK(hk_agx3_g17p_rt0_tile_layout_supported(&tib)); @@ -2026,13 +2026,13 @@ test_g17p_single_layer_rt0_layout(void) CHECK(msaa4_cmd.utile_height_px == 16); CHECK(agx_tilebuffer_total_size(&tib) < 32768); CHECK(hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, false)); + &tib, 1, true, true, false, false)); tib = agx_build_tilebuffer_layout(rgba, 1, 8, false); CHECK(!hk_agx3_g17p_rt0_tile_layout_supported(&tib)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, false)); + &tib, 1, true, true, false, false)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - NULL, 1, true, true, false)); + NULL, 1, true, true, false, false)); /* Raw 32-bit float lanes keep their samples for the resolve after the * pass, while the store of those samples stays admitted. */ @@ -2040,7 +2040,7 @@ test_g17p_single_layer_rt0_layout(void) tib = agx_build_tilebuffer_layout(r32f, 1, 4, false); CHECK(hk_agx3_g17p_rt0_tile_layout_supported(&tib)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, false)); + &tib, 1, true, true, false, false)); CHECK(hk_agx3_g17p_multisample_store_supported(&tib, 1, true, 4)); /* So do RGB9E5 samples, each one packed word. */ @@ -2051,7 +2051,23 @@ test_g17p_single_layer_rt0_layout(void) tib = agx_build_tilebuffer_layout(rgb9e5, 1, samples, false); CHECK(hk_agx3_g17p_rt0_tile_layout_supported(&tib)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported( - &tib, 1, true, true, false)); + &tib, 1, true, true, false, false)); + CHECK(hk_agx3_g17p_multisample_store_supported(&tib, 1, true, samples)); + } + + /* R11G11B10_FLOAT direct resolve requires the own-class PBE (G17P); on + * raw-class chips (G15x, and G16G without own-class PBE) it falls back to + * multisample store + shader resolve. */ + enum pipe_format r11g11b10[AGX_MAX_RENDER_TARGETS] = { + PIPE_FORMAT_R11G11B10_FLOAT, + }; + for (unsigned samples = 2; samples <= 4; samples += 2) { + tib = agx_build_tilebuffer_layout(r11g11b10, 1, samples, false); + CHECK(hk_agx3_g17p_rt0_tile_layout_supported(&tib)); + CHECK(!hk_agx3_g17p_direct_color_resolve_supported( + &tib, 1, true, true, false, false)); + CHECK(hk_agx3_g17p_direct_color_resolve_supported( + &tib, 1, true, true, false, true)); CHECK(hk_agx3_g17p_multisample_store_supported(&tib, 1, true, samples)); } CHECK(!hk_agx3_g17p_rt0_tile_layout_supported(NULL)); @@ -2389,6 +2405,220 @@ test_stk_advanced_pipeline_framebuffers(void) return 0; } +static int +test_g17p_mixed_direct_color_resolve(void) +{ + /* Deferred local-read 5-RT MSAA4 shape: 4 G-buffer attachments + * (DONT_CARE) plus 1 RGBA8 color attachment at offset 20 B (resolve-only). */ + const enum pipe_format deferred_formats[AGX_MAX_RENDER_TARGETS] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_R16G16B16A16_FLOAT, + PIPE_FORMAT_R8G8B8A8_UNORM, + }; + struct agx_tilebuffer_layout tib = + agx_build_tilebuffer_layout(deferred_formats, 5, 4, false); + CHECK(tib.nr_samples == 4 && tib.sample_size_B == 24 && + !agx_tilebuffer_spills(&tib)); + CHECK(agx_tilebuffer_offset_B(&tib, 4) == 20); + + struct hk_agx3_g17p_mixed_resolve_target one = { + .format = PIPE_FORMAT_R8G8B8A8_UNORM, + .view_format = PIPE_FORMAT_R8G8B8A8_UNORM, + .has_resolve_target = true, + .average_resolve = true, + .store_source = false, + .resolve_pbe_valid = true, + .resolve_format_matches = true, + .resolve_samples = 1, + }; + + /* Final EOT on full render area with 5 MSAA + 1 resolve view (6 <= 14). */ + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, false, false, false, 6)); + + /* SNORM resolve targets are admitted (hardware PBE averages signed lanes). */ + struct hk_agx3_g17p_mixed_resolve_target snorm = one; + snorm.format = PIPE_FORMAT_R8G8B8A8_SNORM; + snorm.view_format = PIPE_FORMAT_R8G8B8A8_SNORM; + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &snorm, 1, false, false, false, false, 6)); + snorm.format = PIPE_FORMAT_R16G16B16A16_SNORM; + snorm.view_format = PIPE_FORMAT_R16G16B16A16_SNORM; + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &snorm, 1, false, false, false, false, 6)); + + /* sRGB resolve targets are rejected via the unmapped view format, even if + * the EOT key format were remapped to linear UNORM. */ + struct hk_agx3_g17p_mixed_resolve_target srgb = one; + srgb.format = PIPE_FORMAT_B8G8R8A8_SRGB; + srgb.view_format = PIPE_FORMAT_B8G8R8A8_SRGB; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &srgb, 1, false, false, false, false, 6)); + srgb.format = PIPE_FORMAT_B8G8R8A8_UNORM; + srgb.view_format = PIPE_FORMAT_B8G8R8A8_SRGB; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &srgb, 1, false, false, false, false, 6)); + + /* 2x MSAA is admitted; 1x and 8x are refused. */ + struct agx_tilebuffer_layout tib2 = + agx_build_tilebuffer_layout(deferred_formats, 5, 2, false); + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib2, &one, 1, false, false, false, false, 6)); + struct agx_tilebuffer_layout tib1 = + agx_build_tilebuffer_layout(deferred_formats, 5, 1, false); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib1, &one, 1, false, false, false, false, 6)); + + /* Partial render, incomplete render area (including sparse multiview + * viewMask), suspended/resumed dynamic rendering + * (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT), unstored + * resolve, and exceeding the 14 color+resolve write-range budget all fall + * back. */ + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, true, false, false, false, 6)); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, true, false, false, 6)); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, false, true, false, 6)); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, false, false, true, 6)); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, false, false, false, + HK_AGX3_G17P_MAX_COLOR_RESOLVE_WRITE_RANGES + 1)); + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &one, 1, false, false, false, false, + HK_AGX3_G17P_MAX_COLOR_RESOLVE_WRITE_RANGES)); + + /* STORE_OP_STORE, non-AVERAGE, missing/mismatched/MS resolve view fall back. */ + struct hk_agx3_g17p_mixed_resolve_target bad = one; + bad.store_source = true; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + bad = one; + bad.average_resolve = false; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + bad = one; + bad.has_resolve_target = false; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + bad = one; + bad.resolve_pbe_valid = false; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + bad = one; + bad.resolve_format_matches = false; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + bad = one; + bad.resolve_samples = 4; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + + /* Raw-word formats (R32F, RGB9E5, R11G11B10F) and pure integers fall back. */ + const enum pipe_format shader_resolve_formats[] = { + PIPE_FORMAT_R32_FLOAT, + PIPE_FORMAT_R32G32B32A32_FLOAT, + PIPE_FORMAT_R9G9B9E5_FLOAT, + PIPE_FORMAT_R11G11B10_FLOAT, + PIPE_FORMAT_R8G8B8A8_UINT, + PIPE_FORMAT_R16G16_SINT, + }; + for (unsigned i = 0; i < ARRAY_SIZE(shader_resolve_formats); ++i) { + bad = one; + bad.format = shader_resolve_formats[i]; + bad.view_format = shader_resolve_formats[i]; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + } + + /* On G17P hk_eot_key_format() remaps R11G11B10_FLOAT to R10G10B10A2_UNORM + * in key.tib.logical_format[]. Direct resolve must still reject it via the + * unmapped view_format. */ + bad = one; + bad.format = PIPE_FORMAT_R10G10B10A2_UNORM; + bad.view_format = PIPE_FORMAT_R11G11B10_FLOAT; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, &bad, 1, false, false, false, false, 6)); + + /* Multi-target direct resolve succeeds when every stored target qualifies + * and falls back if any target stores source or needs shader resolve. */ + struct hk_agx3_g17p_mixed_resolve_target pair[2] = {one, one}; + pair[1].format = PIPE_FORMAT_R16G16B16A16_FLOAT; + pair[1].view_format = PIPE_FORMAT_R16G16B16A16_FLOAT; + CHECK(hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, pair, 2, false, false, false, false, 7)); + pair[1].store_source = true; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, pair, 2, false, false, false, false, 7)); + pair[1].store_source = false; + pair[1].format = PIPE_FORMAT_R32_FLOAT; + pair[1].view_format = PIPE_FORMAT_R32_FLOAT; + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &tib, pair, 2, false, false, false, false, 7)); + + /* Spilled tilebuffers refuse direct resolve. */ + const enum pipe_format spill_formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_R16G16B16A16_FLOAT, + PIPE_FORMAT_R32G32B32A32_UINT, + }; + struct agx_tilebuffer_layout spilled = agx_build_tilebuffer_layout_bounded( + spill_formats, 3, 4, false, AGX_G17P_MAX_BYTES_PER_SAMPLE); + CHECK(agx_tilebuffer_spills(&spilled)); + CHECK(!hk_agx3_g17p_mixed_direct_color_resolve_supported( + &spilled, &one, 1, false, false, false, false, 4)); + + /* Verify the Ioto EOT program generator accepts both the single-stored-RT + * deferred shape (count=1 at offset 20 B in a 24 B/sample MSAA4 tile) and a + * 2-target mixed-MRT MSAA4 resolve shape. */ + struct agx3_g17p_rt0_eot_program eot = {0}; + const struct agx3_g17p_rt0_eot_program_desc single_desc = { + .program_va = 0x1000000000ULL, + .shader_va = 0x1000002000ULL, + .pbe_argument_va = 0x1000004000ULL, + .imageblock_offset_B = 20, + .attachment_count = 1, + .mixed_mrt = false, + .shader_binary_size = 68, + .scratch_size = 0, + .nr_gprs = 8, + .staging_halfs = 8, + .imageblock = { + .sample_size_B = 24, + .nr_samples = 4, + .tile_size_px = tib.tile_size, + }, + }; + CHECK(agx3_g17p_rt0_eot_program_generate(AGX_CHIP_G16G, &single_desc, &eot)); + CHECK(eot.length > 0); + + const struct agx3_g17p_rt0_eot_program_desc dual_desc = { + .program_va = 0x1000000000ULL, + .shader_va = 0x1000002000ULL, + .pbe_argument_va = 0x1000004000ULL, + .imageblock_offset_B = 0, + .imageblock_offset1_B = 20, + .attachment_count = 2, + .mixed_mrt = true, + .shader_binary_size = 32 + 44 * 2, + .scratch_size = 0, + .nr_gprs = 8, + .staging_halfs = 16, + .imageblock = { + .sample_size_B = 24, + .nr_samples = 4, + .tile_size_px = tib.tile_size, + }, + }; + CHECK(agx3_g17p_rt0_eot_program_generate(AGX_CHIP_G16G, &dual_desc, &eot)); + CHECK(eot.length > 0); + + return 0; +} + /* The fused end-of-tile store + resolve admits exactly the single-target * final pass that stores its multisample samples and AVERAGE-resolves them * over the whole attachment; every other shape keeps the after-pass resolve. */ @@ -2420,7 +2650,7 @@ test_g17p_store_and_resolve(void) * outside the resolve-only program, which needs storeOp != STORE. */ CHECK(hk_agx3_g17p_multisample_store_supported(&tib, 1, true, 4)); CHECK(!hk_agx3_g17p_direct_color_resolve_supported(&tib, 1, true, true, - true)); + true, false)); CHECK(!hk_agx3_g17p_store_and_resolve_supported(NULL, &ok)); CHECK(!hk_agx3_g17p_store_and_resolve_supported(&tib, NULL)); @@ -2528,7 +2758,8 @@ main(void) test_g17p_root_range() || test_g17p_single_layer_rt0_layout() || test_stk_advanced_pipeline_framebuffers() || - test_g17p_store_and_resolve() || test_alias()) + test_g17p_mixed_direct_color_resolve() || test_g17p_store_and_resolve() || + test_alias()) return 1; printf("Honeykrisp AGX3 Ioto program core: %u checks passed\n", checks);