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
8 changes: 8 additions & 0 deletions include/drm-uapi/asahi_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ enum drm_asahi_feature {
*/
#define DRM_ASAHI_FEATURE_VDM_USC_INVALIDATE ((1ULL) << 40)

/*
* DRM_ASAHI_FEATURE_TILE_BUFFER_48K: render commands accept tile buffers of
* up to 48 KiB (sample_size_B * utile_width_px * utile_height_px * samples),
* instead of 32 KiB. A feature bit like those of enum drm_asahi_feature,
* defined here like bit 32.
*/
#define DRM_ASAHI_FEATURE_TILE_BUFFER_48K ((1ULL) << 46)

/*
* DRM_ASAHI_FEATURE_COMPUTE_MULTI_CHANNEL: the kernel itself runs the
* independent compute commands of one queue on several firmware compute
Expand Down
13 changes: 11 additions & 2 deletions src/asahi/lib/agx_chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -1166,15 +1166,24 @@ agx_chip_hw_texel_fetch_bounds(enum agx_chip chip)

/*
* Whether the Apple9 imageblock applies: up to 128 bytes a sample in a full
* 32 KiB (32768-byte) tile. Apple's Metal feature set tables give G15 (M3)
* and G17P (A18 Pro) the same Apple9 limits.
* 32 KiB (32768-byte) tile, or 48 KiB where the kernel admits it
* (AGX_NATIVE_TILE_BUFFER_48K_BYTES). Apple's Metal feature set tables give
* G15 (M3) and G17P (A18 Pro) the same Apple9 limits.
*/
static inline bool
agx_chip_native_imageblock(enum agx_chip chip)
{
return agx_chip_info(chip)->quirks & AGX_QUIRK_NATIVE_IMAGEBLOCK;
}

/* Tile buffer budget of a render on chips with the native imageblock. A
* kernel that reports DRM_ASAHI_FEATURE_TILE_BUFFER_48K admits 48 KiB. With
* 24-byte samples at 4x that fits 32x16 tiles instead of 16x16, so a render
* bins half as many tiles.
*/
#define AGX_NATIVE_TILE_BUFFER_BYTES (32768)
#define AGX_NATIVE_TILE_BUFFER_48K_BYTES (49152)

/*
* Whether single-sample 2D colour images are losslessly compressed in the
* Gen9 form Borealis implements for G17P. The image is GPU-tiled, and 8 bytes
Expand Down
7 changes: 5 additions & 2 deletions src/asahi/lib/agx_ioto_state_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,15 @@ agx_ioto_g17p_fragment_speclm_build(
(sample_size_B &&
((samples != 1 && samples != 2 && samples != 4) ||
(sample_size_B & 7) || (sample_size_B >> 3) > 31 ||
sample_size_B * samples * imageblock->tile_size_px > 32768u)))
sample_size_B * samples * imageblock->tile_size_px >
AGX_NATIVE_TILE_BUFFER_48K_BYTES)))
return false;

/* SPECLM encodes the sample stride in 8-byte units (5-bit field at bit 35,
* max 248 B/sample) and log2(samples) in word 1 bits 7..8. The tile cannot
* exceed 32 KiB. Patch only those fields onto the per-tile-geometry seeds,
* exceed the largest tile buffer a kernel admits (48 KiB); the render's
* tilebuffer layout keeps it within what this kernel admits. Patch only
* those fields onto the per-tile-geometry seeds,
* preserving the opaque geometry bits in word 2[5:0]. */
static const uint8_t imageblock_32x32[AGX_IOTO_SPECLM_SIZE] = {
0x77, 0x00, 0x2a, 0x43, 0x4b, 0x00, 0x00, 0x00,
Expand Down
45 changes: 44 additions & 1 deletion src/asahi/lib/tests/test-agx-ioto-state-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: MIT
*
* Differential and fail-closed contract tests for the direct-write G17P
* compiler LDSHDR and SPECTPR packers in agx_ioto_state_core.c.
* compiler LDSHDR and SPECTPR packers in agx_ioto_state_core.c, and for the
* fragment SPECLM imageblock record.
*/

#include "../agx_ioto_core.h"
Expand Down Expand Up @@ -513,11 +514,53 @@ test_g17p_compiler_spectpr_differential(void)
return 0;
}

/* The fragment SPECLM imageblock record. 32x16 tiles of 24-byte samples at 4x
* are 48 KiB; our J773g (G16G) trace of a deferred 4x pass programs exactly
* this record on its fragment, background and end-of-tile programs. Larger
* tiles stay refused, and the output is left untouched. */
static int
test_g17p_fragment_speclm(void)
{
static const uint8_t trace_32x16_24b_4x[AGX_IOTO_SPECLM_SIZE] = {
0x77, 0x00, 0xaa, 0x06, 0x43, 0x00, 0x00, 0x00,
};
uint8_t out[AGX_IOTO_SPECLM_SIZE];

const struct agx_ioto_g17p_imageblock tile48k = {
.sample_size_B = 24, .nr_samples = 4, .tile_size_px = 32 * 16,
};
CHECK(tile48k.sample_size_B * tile48k.nr_samples * tile48k.tile_size_px ==
AGX_NATIVE_TILE_BUFFER_48K_BYTES);
CHECK(agx_ioto_g17p_fragment_speclm_build(&tile48k, out, sizeof(out)));
CHECK(memcmp(out, trace_32x16_24b_4x, sizeof(out)) == 0);
++valid_encodes;

const struct agx_ioto_g17p_imageblock too_large[] = {
/* 64 KiB */
{.sample_size_B = 32, .nr_samples = 4, .tile_size_px = 32 * 16},
/* 96 KiB */
{.sample_size_B = 24, .nr_samples = 4, .tile_size_px = 32 * 32},
/* 56 KiB */
{.sample_size_B = 56, .nr_samples = 1, .tile_size_px = 32 * 32},
};
for (size_t i = 0; i < ARRAY_SIZE(too_large); ++i) {
memset(out, 0xa5, sizeof(out));
CHECK(!agx_ioto_g17p_fragment_speclm_build(&too_large[i], out,
sizeof(out)));
for (size_t b = 0; b < sizeof(out); ++b)
CHECK(out[b] == 0xa5);
++buffer_preserving_rejections;
}

return 0;
}

int
main(void)
{
CHECK(test_g17p_compiler_ldshdr_differential() == 0);
CHECK(test_g17p_compiler_spectpr_differential() == 0);
CHECK(test_g17p_fragment_speclm() == 0);
printf("agx_ioto_state_core: %llu valid_encodes, "
"%llu buffer_preserving_rejections, %llu null_rejections, "
"0 mismatches\n",
Expand Down
62 changes: 62 additions & 0 deletions src/asahi/lib/tests/test-tilebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,68 @@ TEST(Tilebuffer, IndependentNativeStorageAndSampleLimits)
EXPECT_FALSE(spilling.spilled[1]);
}

/* hk_tilebuffer_layout() builds a layout with the 48 KiB budget when the
* kernel reports DRM_ASAHI_FEATURE_TILE_BUFFER_48K, and keeps it only when it
* is 4x, 32x16 and spills nothing; otherwise it builds with 32 KiB. These are
* the layouts it chooses between.
*/
TEST(Tilebuffer, NativeTileBuffer48KLayouts)
{
const auto build = [](const enum pipe_format *formats, unsigned count,
unsigned samples, uint32_t budget) {
return agx_build_tilebuffer_layout_with_limits_resident(
formats, count, samples, false, AGX_G17P_MAX_BYTES_PER_SAMPLE, budget,
2048, 0);
};

/* A deferred G-buffer pass and its lighting target: 24-byte samples. */
enum pipe_format gbuffer[AGX_MAX_RENDER_TARGETS] = {
PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_R16G16B16A16_FLOAT,
PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_R32_FLOAT,
PIPE_FORMAT_R8G8B8A8_UNORM,
};
for (unsigned count : {4u, 5u}) {
const auto narrow =
build(gbuffer, count, 4, AGX_NATIVE_TILE_BUFFER_BYTES);
EXPECT_FALSE(agx_tilebuffer_spills(&narrow));
EXPECT_EQ(narrow.sample_size_B, 24u);
EXPECT_EQ(narrow.tile_size, 16u * 16u);

/* The shape the 48 KiB budget is taken for. */
const auto wide =
build(gbuffer, count, 4, AGX_NATIVE_TILE_BUFFER_48K_BYTES);
EXPECT_FALSE(agx_tilebuffer_spills(&wide));
EXPECT_EQ(wide.nr_samples, 4u);
EXPECT_EQ(wide.sample_size_B, 24u);
EXPECT_EQ(wide.tile_size, 32u * 16u);
EXPECT_EQ(wide.sample_size_B * wide.nr_samples * wide.tile_size,
AGX_NATIVE_TILE_BUFFER_48K_BYTES);
}

/* Eight 2x RGBA32 targets spill under either budget, so they keep the
* 32 KiB layout: with 48 KiB six would stay resident, and the native
* background and end-of-tile programs take four raw 32-bit targets.
*/
enum pipe_format rgba32[AGX_MAX_RENDER_TARGETS];
for (unsigned i = 0; i < AGX_MAX_RENDER_TARGETS; ++i)
rgba32[i] = PIPE_FORMAT_R32G32B32A32_FLOAT;

const auto narrow =
build(rgba32, AGX_MAX_RENDER_TARGETS, 2, AGX_NATIVE_TILE_BUFFER_BYTES);
const auto wide =
build(rgba32, AGX_MAX_RENDER_TARGETS, 2, AGX_NATIVE_TILE_BUFFER_48K_BYTES);
EXPECT_TRUE(agx_tilebuffer_spills(&narrow));
EXPECT_TRUE(agx_tilebuffer_spills(&wide));

unsigned narrow_resident = 0, wide_resident = 0;
for (unsigned i = 0; i < AGX_MAX_RENDER_TARGETS; ++i) {
narrow_resident += !narrow.spilled[i];
wide_resident += !wide.spilled[i];
}
EXPECT_EQ(narrow_resident, 4u);
EXPECT_EQ(wide_resident, 6u);
}

TEST(Tilebuffer, ResidentAttachmentsStayInTheTilebuffer)
{
/* M5 at 4x: 64 bytes per sample. Four RGBA32F targets fill it, so the
Expand Down
24 changes: 23 additions & 1 deletion src/asahi/vulkan/hk_cmd_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3695,9 +3695,31 @@ hk_tilebuffer_layout(const struct hk_device *dev, const VkFormat *vk_formats,
formats, count, samples, layered, max_sample_size_B,
(!m5 && layered) ? 32768 : 65536, 2048, resident_mask);
}
const unsigned max_samples_per_tile =
agx_chip_native_agx3(dev->dev.chip) ? 2048 : 0;

/* A kernel that admits 48 KiB tile buffers lets a 4x layout of 24-byte
* samples take 32x16 tiles instead of 16x16, with every target resident.
* Take the larger budget for that shape only. Elsewhere it would mostly
* keep more targets of a spilling layout resident, in shapes the native
* background and end-of-tile programs refuse: eight 2x RGBA32 targets
* would keep six, and they take four.
*/
if (imageblock &&
(dev->dev.params.features & DRM_ASAHI_FEATURE_TILE_BUFFER_48K)) {
const struct agx_tilebuffer_layout wide =
agx_build_tilebuffer_layout_with_limits_resident(
formats, count, samples, layered, max_sample_size_B,
AGX_NATIVE_TILE_BUFFER_48K_BYTES, max_samples_per_tile,
resident_mask);
if (wide.nr_samples == 4 && wide.tile_size == 32 * 16 &&
!agx_tilebuffer_spills(&wide))
return wide;
}

return agx_build_tilebuffer_layout_with_limits_resident(
formats, count, samples, layered, max_sample_size_B,
imageblock ? 32768 : 0, agx_chip_native_agx3(dev->dev.chip) ? 2048 : 0,
imageblock ? AGX_NATIVE_TILE_BUFFER_BYTES : 0, max_samples_per_tile,
resident_mask);
}

Expand Down