Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion src/asahi/lib/tests/test-agx-g17p-mrt-mixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
76 changes: 74 additions & 2 deletions src/asahi/vulkan/hk_agx3_ioto_program_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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,
Expand Down
31 changes: 30 additions & 1 deletion src/asahi/vulkan/hk_agx3_ioto_program_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading