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
20 changes: 15 additions & 5 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,10 @@ agx_pack_normalized_agx3(agx_builder *b, const agx_index *channels,
return 0;

if (format == AGX_FORMAT_RGB10A2) {
if (nr_channels != 4)
if (nr_channels != 3 && nr_channels != 4)
return 0;
agx_index pack_sources[4];
for (unsigned i = 0; i < 4; ++i) {
for (unsigned i = 0; i < nr_channels; ++i) {
if (channels[i].size == AGX_SIZE_32) {
pack_sources[i] = channels[i];
} else if (channels[i].size == AGX_SIZE_16) {
Expand All @@ -961,6 +961,8 @@ agx_pack_normalized_agx3(agx_builder *b, const agx_index *channels,
return 0;
}
}
if (nr_channels == 3)
pack_sources[3] = agx_mov_imm(b, 32, fui(1.0f));
packed[0] = agx_pack_rgb10a2_agx3(b, pack_sources[0], pack_sources[1],
pack_sources[2], pack_sources[3]);
return 1;
Expand Down Expand Up @@ -1757,14 +1759,22 @@ agx_unpack_normalized_agx3(agx_builder *b, agx_index dest,
if (b->shader->key->dev.encoding == AGX_ISA_ENCODING_AGX2)
return false;
if (format == AGX_FORMAT_RGB10A2) {
if (nr_comps != 4 || dest.size != AGX_SIZE_32)
if (nr_comps < 1 || nr_comps > 4 || dest.size != AGX_SIZE_32)
return false;
agx_index packed = agx_temp(b->shader, AGX_SIZE_32);
agx_ld_tile_to(b, packed, agx_src_index(&instr->src[0]), agx_null(),
format, 1, nir_intrinsic_base(instr), false,
nir_intrinsic_target(instr));
agx_unpack_rgb10a2_agx3_to(b, dest, packed);
agx_emit_cached_split(b, dest, 4);
if (nr_comps == 4) {
agx_unpack_rgb10a2_agx3_to(b, dest, packed);
agx_emit_cached_split(b, dest, 4);
} else {
agx_index rgba = agx_vec_temp(b->shader, AGX_SIZE_32, 4);
agx_unpack_rgb10a2_agx3_to(b, rgba, packed);
agx_index channels[4] = {agx_null()};
agx_emit_split(b, channels, rgba, 4);
agx_emit_collect_to(b, dest, nr_comps, channels);
}
return true;
}
/* Apple reads an RGB9E5 or RG11B10 target's three float lanes back with
Expand Down
8 changes: 5 additions & 3 deletions src/asahi/compiler/agx_opt_compact_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ agx_opt_compact_constants(agx_context *ctx)
/* Analyze the types that we read constants as */
agx_foreach_instr_global(ctx, I) {
const bool wide_float_op =
g18g && I->nr_dests >= 1 && I->dest[0].size == AGX_SIZE_32 &&
(I->op == AGX_OPCODE_FADD || I->op == AGX_OPCODE_FMUL ||
I->op == AGX_OPCODE_FFMA);
(g18g && I->nr_dests >= 1 && I->dest[0].size == AGX_SIZE_32 &&
(I->op == AGX_OPCODE_FADD || I->op == AGX_OPCODE_FMUL ||
I->op == AGX_OPCODE_FFMA)) ||
(agx3 && (I->op == AGX_OPCODE_FLTNORM_AGX3 ||
I->op == AGX_OPCODE_PACK_RGB10A2_AGX3));

agx_foreach_ssa_src(I, s) {
const bool half_pair =
Expand Down
6 changes: 4 additions & 2 deletions src/asahi/layout/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum ail_tiling {
AIL_TILING_TWIDDLED,

/**
* G17P Interchange (descriptor Layout 3): 16x16-element macroblocks in
* Gen9/G17P Interchange (descriptor Layout 3): 16x16-element macroblocks in
* row-major order, row pitch ceil(width / 16) * 256 * blocksize; inside a
* macroblock, 8x4 blocks in row-major order, each x-first Morton. This is
* the layout the display coprocessor scans out as an address-format-5
Expand Down Expand Up @@ -219,7 +219,9 @@ ail_get_wsi_stride_B(const struct ail_layout *layout, unsigned level)
if (layout->tiling == AIL_TILING_LINEAR)
return ail_get_linear_stride_B(layout, level);
else if (layout->tiling == AIL_TILING_INTERCHANGE)
return ail_get_interchange_stride_B(layout);
/* Per pixel row: DRM core checks pitch * height against the buffer, and
* appledrm derives the macroblock layout itself. */
return ail_get_interchange_stride_B(layout) / 16;
else
return util_format_get_stride(layout->format, layout->width_px);
}
Expand Down
46 changes: 40 additions & 6 deletions src/asahi/layout/tests/test-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,19 @@ TEST(Linear, Packed422Rows)
}

/*
* G17P Interchange (DRM_FORMAT_MOD_APPLE_INTERCHANGE). The row
* pitch, data size and header offset are the contract with appledrm, which
* requires pitch == ceil(w/16)*1024, header offset == data size and a buffer
* Compressed Interchange (DRM_FORMAT_MOD_APPLE_INTERCHANGE; gated per chip by
* AGX_CAP_GEN9_2D_COMPRESSION). The macroblock row pitch, data size
* and header offset are the contract with appledrm, which lays out
* pitch == ceil(w/16)*1024, header offset == data size and a buffer
* of at least data + (8 << (log2ceil(tiles_x) + log2ceil(tiles_y))) bytes.
* appledrm derives that layout itself and ignores the framebuffer pitch, but
* DRM core checks (height - 1) * pitch + width * cpp against the buffer, so
* the pitch handed to the window system is per pixel row: a sixteenth of the
* macroblock row.
*/
static void
check_interchange(unsigned w, unsigned h)
check_interchange(unsigned w, unsigned h,
enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM)
{
struct ail_layout layout = {
.width_px = w,
Expand All @@ -304,20 +310,22 @@ check_interchange(unsigned w, unsigned h)
.levels = 1,
.tiling = AIL_TILING_INTERCHANGE,
.compressed = true,
.format = PIPE_FORMAT_B8G8R8A8_UNORM,
.format = format,
.renderable = true,
};

ail_make_miptree(&layout);

EXPECT_EQ(util_format_get_blocksize(format), 4u);
const unsigned tx = DIV_ROUND_UP(w, 16), ty = DIV_ROUND_UP(h, 16);
const uint64_t pitch = tx * 1024;
const uint64_t data = ty * pitch;
const uint64_t kernel_header =
8ull << (util_logbase2_ceil(tx) + util_logbase2_ceil(ty));

EXPECT_EQ(ail_get_interchange_stride_B(&layout), pitch);
EXPECT_EQ(ail_get_wsi_stride_B(&layout, 0), pitch);
EXPECT_EQ(ail_get_wsi_stride_B(&layout, 0), pitch / 16);
EXPECT_LE((h - 1) * (pitch / 16) + w * 4, layout.size_B);
EXPECT_EQ(layout.level_offsets_B[0], 0u);
EXPECT_EQ(ail_get_level_size_B(&layout, 0), data);
EXPECT_EQ(layout.layer_stride_B, data);
Expand Down Expand Up @@ -348,6 +356,32 @@ TEST(Interchange, OddSizes)
check_interchange(16384, 16);
}

TEST(Interchange, TenBitFormats)
{
static const enum pipe_format formats[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_B8G8R8X8_UNORM,
PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_FORMAT_R8G8B8X8_UNORM,
PIPE_FORMAT_B10G10R10A2_UNORM,
PIPE_FORMAT_B10G10R10X2_UNORM,
PIPE_FORMAT_R10G10B10A2_UNORM,
PIPE_FORMAT_R10G10B10X2_UNORM,
};
static const unsigned dims[][2] = {
{2408, 1506},
{3456, 2234},
{256, 128},
{33, 17},
{1920, 1080},
{16384, 16},
};
for (enum pipe_format fmt : formats) {
for (const auto &d : dims)
check_interchange(d[0], d[1], fmt);
}
}

TEST(Interchange, Modifier)
{
EXPECT_EQ(DRM_FORMAT_MOD_APPLE_GPU_TILED, 0x0c00000000000001ull);
Expand Down
9 changes: 8 additions & 1 deletion src/asahi/lib/agx_chip_caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ enum agx_chip_cap {
* has finished, without the strong cache flush. Measured on G17P and M5
* (G17G, G17S, G17C); G15 and G16G keep the flush until measured there. */
AGX_CAP_CDM_WAR_WEAK_BARRIER = 1u << 11,

/* Gen9 2D depth compression and compressed DRM_FORMAT_MOD_APPLE_INTERCHANGE
* scanout (in both Gallium and Borealis) are enabled on this chip. Private
* Gen9 colour compression is gated separately by
* agx_chip_gen9_color_compression() (G16G and G17P). */
AGX_CAP_GEN9_2D_COMPRESSION = 1u << 12,
};

/* What the admitted AGX2 chips (G13G, G13X, G14G, G14X) share. */
Expand All @@ -95,7 +101,8 @@ enum agx_chip_cap {
(AGX_CAPS_NATIVE | AGX_CAP_NATIVE_PREAMBLE | \
AGX_CAP_VDM_INDIRECT_INDEX_BOUNDS | \
AGX_CAP_TRI_MERGE_ACROSS_SIDE_EFFECTS | AGX_CAP_SPARSE_RESIDENCY_3D | \
AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER)
AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER | \
AGX_CAP_GEN9_2D_COMPRESSION)

/* What the M5 parts (G17G, G17S, G17C) share. */
#define AGX_CAPS_M5 \
Expand Down
58 changes: 58 additions & 0 deletions src/asahi/lib/agx_g17p_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

#pragma once

#include "drm-uapi/drm_fourcc.h"
#include "util/format/u_formats.h"
#include "agx_chip_caps.h"

#include <stdbool.h>
#include <stdint.h>

/* Colour formats whose G17P images Gallium may allocate losslessly
* compressed.
Expand Down Expand Up @@ -121,3 +124,58 @@ agx_g17p_compression_color_format_16b(enum pipe_format format)
return false;
}
}

/* Whether a chip enables compressed 2D Interchange
* (DRM_FORMAT_MOD_APPLE_INTERCHANGE), sharing AGX_CAP_GEN9_2D_COMPRESSION
* with Gallium depth compression and Borealis interchange so they cannot drift
* apart (private Gen9 colour compression is gated separately by
* agx_chip_gen9_color_compression() for G16G and G17P). Which modifiers the
* display accepts comes from the display's own modifier list.
*/
static inline bool
agx_chip_supports_interchange(enum agx_chip chip)
{
return agx_chip_has_cap(chip, AGX_CAP_GEN9_2D_COMPRESSION);
}

/* The plain 32-bit 8-bit and 10-bit RGB/RGBA formats an Interchange image
* may have (4-byte texels matching ail_initialize_interchange()). */
static inline bool
agx_interchange_format(enum pipe_format format)
{
switch (format) {
case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_B8G8R8X8_UNORM:
case PIPE_FORMAT_R8G8B8A8_UNORM:
case PIPE_FORMAT_R8G8B8X8_UNORM:
case PIPE_FORMAT_B10G10R10A2_UNORM:
case PIPE_FORMAT_B10G10R10X2_UNORM:
case PIPE_FORMAT_R10G10B10A2_UNORM:
case PIPE_FORMAT_R10G10B10X2_UNORM:
return true;
default:
return false;
}
}

/* The one rule for advertising and choosing Interchange: GPU capability
* plus format. Modifier queries and agx_interchange_allowed() share it, so
* other chips and formats see the modifier list they always did. */
static inline bool
agx_interchange_modifier_supported(enum agx_chip chip, enum pipe_format format)
{
return agx_chip_supports_interchange(chip) &&
agx_interchange_format(format);
}

static inline bool
agx_dmabuf_modifier_supported(enum agx_chip chip, bool nocompress,
uint64_t modifier, enum pipe_format format)
{
if (modifier == DRM_FORMAT_MOD_APPLE_INTERCHANGE)
return !nocompress && agx_interchange_modifier_supported(chip, format);

return modifier == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED ||
modifier == DRM_FORMAT_MOD_APPLE_GPU_TILED ||
modifier == DRM_FORMAT_MOD_LINEAR;
}
15 changes: 10 additions & 5 deletions src/asahi/lib/agx_nir_lower_tilebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,20 @@ pass(nir_builder *b, nir_intrinsic_instr *intr, void *data)

/* An RGBX/BGRX target lives in a 4-channel tile whose fourth channel
* reaches memory (the PBE has no constant swizzle source). Write 1.0
* there so the X byte is 0xff rather than whatever the tile held: a
* display firmware that blends the byte as alpha (Apple H17P) otherwise
* shows the frame scaled by it. Requested by G18G, whose PBE points
* swizzle_a at this channel.
* there so the X channel is all-ones rather than whatever the tile held:
* a display firmware that blends the channel as alpha (Apple H17P, or
* DCP L10R on 10-bit RGBX) otherwise shows the frame scaled by it.
* Requested by G18G for all RGBX/BGRX formats, and required on G17P/M5
* for RGB10X2/BGR10X2 because AGX3's packed RGB10A2 tile store always
* encodes all four channels into one 32-bit word.
*/
const struct util_format_description *ldesc =
util_format_description(logical_format);
const bool x_alpha =
ctx->x_alpha_one && comps == 3 && ldesc->nr_channels == 4 &&
(ctx->x_alpha_one ||
(ctx->lower_g17p_formats &&
(enum ail_isa_format)format == AIL_ISA_FORMAT_RGB10A2)) &&
comps == 3 && ldesc->nr_channels == 4 &&
ldesc->channel[3].type == UTIL_FORMAT_TYPE_VOID &&
util_format_get_nr_components(format) == 4 &&
!util_format_is_pure_integer(logical_format) && !lower_r11g11b10;
Expand Down
3 changes: 2 additions & 1 deletion src/asahi/lib/tests/test-chip-caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static unsigned checks;
#define CAP_BIT(cap, predicate) | (cap)
static const unsigned all_caps =
(0 CAPS(CAP_BIT)) | AGX_CAP_SPARSE_RESIDENCY_3D | AGX_CAP_DESCRIPTOR_BUFFER |
AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER;
AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER |
AGX_CAP_GEN9_2D_COMPRESSION;
#undef CAP_BIT

/* Each chip of AGX_CHIPS has exactly one row, and the rows are in its
Expand Down
87 changes: 87 additions & 0 deletions src/asahi/lib/tests/test-tilebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,3 +1152,90 @@ TEST(Tilebuffer, PackFirstIfFitsMovesClearedRTIntoFirst8Bytes)
EXPECT_EQ(agx_tilebuffer_offset_B(&def, 3), 0u);
EXPECT_FALSE(agx_tilebuffer_spills(&def));
}

/* Interchange is advertised exactly where the shared Gen9 2D compression
* capability is enabled, and for the eight plain 32-bit 8-bit and 10-bit
* RGB/RGBA formats. Every other chip and format (including FP16 and 10-bit
* UINT) keeps the modifier list it had before. */
TEST(Interchange, ModifierSupport)
{
static const uint64_t all_modifiers[] = {
DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED,
DRM_FORMAT_MOD_APPLE_GPU_TILED,
DRM_FORMAT_MOD_APPLE_INTERCHANGE,
DRM_FORMAT_MOD_LINEAR,
};
const std::vector<uint64_t> base_list = {
DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED,
DRM_FORMAT_MOD_APPLE_GPU_TILED,
DRM_FORMAT_MOD_LINEAR,
};
const std::vector<uint64_t> interchange_list = {
DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED,
DRM_FORMAT_MOD_APPLE_GPU_TILED,
DRM_FORMAT_MOD_APPLE_INTERCHANGE,
DRM_FORMAT_MOD_LINEAR,
};

/* Explicit sanity checks: AGX2 (M1/M2), unmeasured Gen9 parts (G15/G16),
* and Gen10 (M5/M6) refuse Interchange; G17P admits it via the shared
* AGX_CAP_GEN9_2D_COMPRESSION capability. */
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G13G));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G14G));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G15P));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G15G));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G15S));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G15C));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G16G));
EXPECT_TRUE(agx_chip_supports_interchange(AGX_CHIP_G17P));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G17G));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_G18G));
EXPECT_FALSE(agx_chip_supports_interchange(AGX_CHIP_UNKNOWN));

/* Explicit negative checks for unsupported display/HDR formats. */
EXPECT_FALSE(agx_interchange_modifier_supported(AGX_CHIP_G17P,
PIPE_FORMAT_R16G16B16A16_FLOAT));
EXPECT_FALSE(agx_interchange_modifier_supported(AGX_CHIP_G17P,
PIPE_FORMAT_R10G10B10A2_UINT));
EXPECT_FALSE(agx_interchange_modifier_supported(AGX_CHIP_G17P,
PIPE_FORMAT_B10G10R10A2_UINT));
EXPECT_FALSE(agx_interchange_modifier_supported(AGX_CHIP_G17P,
PIPE_FORMAT_R11G11B10_FLOAT));
EXPECT_FALSE(agx_interchange_modifier_supported(AGX_CHIP_G17P,
PIPE_FORMAT_B8G8R8A8_SRGB));

for (unsigned c = 0; c <= AGX_CHIP_UNKNOWN; ++c) {
const enum agx_chip chip = (enum agx_chip)c;
const bool capable = agx_chip_has_cap(chip, AGX_CAP_GEN9_2D_COMPRESSION);

EXPECT_EQ(agx_chip_supports_interchange(chip), capable) << c;

for (unsigned f = 1; f < PIPE_FORMAT_COUNT; ++f) {
const enum pipe_format format = (enum pipe_format)f;
const bool supported = format == PIPE_FORMAT_B8G8R8A8_UNORM ||
format == PIPE_FORMAT_B8G8R8X8_UNORM ||
format == PIPE_FORMAT_R8G8B8A8_UNORM ||
format == PIPE_FORMAT_R8G8B8X8_UNORM ||
format == PIPE_FORMAT_B10G10R10A2_UNORM ||
format == PIPE_FORMAT_B10G10R10X2_UNORM ||
format == PIPE_FORMAT_R10G10B10A2_UNORM ||
format == PIPE_FORMAT_R10G10B10X2_UNORM;

EXPECT_EQ(agx_interchange_modifier_supported(chip, format),
capable && supported)
<< c << " " << util_format_name(format);

for (bool nocompress : {false, true}) {
std::vector<uint64_t> advertised;
for (uint64_t mod : all_modifiers) {
if (agx_dmabuf_modifier_supported(chip, nocompress, mod, format))
advertised.push_back(mod);
}
EXPECT_EQ(advertised,
(capable && supported && !nocompress) ? interchange_list
: base_list)
<< c << " " << util_format_name(format) << " " << nocompress;
}
}
}
}
5 changes: 3 additions & 2 deletions src/asahi/vulkan/hk_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ hk_modifier_features(const struct agx_device *dev, uint64_t mod,
~VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
}

/* Interchange: the 32-bit RGBA formats on G17P; never storage or host
* copies (compressed). */
/* Interchange: the 32-bit 8-bit and 10-bit RGB/RGBA formats on chips with
* AGX_CAP_GEN9_2D_COMPRESSION; never storage or host copies
* (compressed). */
if (mod == DRM_FORMAT_MOD_APPLE_INTERCHANGE) {
if (!hk_interchange_format(dev, vk_format))
return 0;
Expand Down
Loading