diff --git a/src/asahi/layout/README b/src/asahi/layout/README index a544d9e7079..a6afa6d3003 100644 --- a/src/asahi/layout/README +++ b/src/asahi/layout/README @@ -5,5 +5,26 @@ encountered with AGX hardware. Its design is inspired by isl. In particular, ail strives to use isl unit suffixes and to represent quantities in a canonical, API-agnostic fashion. -See the isl documentation for conventions in mesa/docs/isl for the conventions -that ail tries to adhere to, in particular mesa/docs/isl/units.rst. +ail conventions differ slightly from isl. See the isl documentation in +mesa/docs/isl for the conventions that inspired ail, in particular +mesa/docs/isl/units.rst. + +In ail, we have the following units: + +**Bytes (B)**: 8-bits. + +**Samples (sa)**: An individual sample. The number of bytes per sample depends +on the format. + +**Pixels (px)**: The unit everything starts as from the API. A pixel contains a +fixed number of samples, given as the layout's `sample_count_sa`. For twiddled +layouts, these samples are stored together in emmory. + +**Elements (el)**: For a block-compressed format, a single compression block +containing multiple pixels. Otherwise, equal to a single pixel. + +**Tiles (tiles)**: Defined only for tiled/twiddled layouts. A group of elements +forming the layout-specific tile. + +We do not support any multisampled block-compressed layouts, so either pixels +equals either samples or elements. diff --git a/src/asahi/layout/layout.c b/src/asahi/layout/layout.c index 227b2d17910..eec482896c1 100644 --- a/src/asahi/layout/layout.c +++ b/src/asahi/layout/layout.c @@ -73,12 +73,28 @@ ail_get_max_tile_size(unsigned blocksize_B) } } +/* + * Calculate the number of bytes in a block. This must take both block + * dimensions and multisampling into account. + */ +static uint32_t +ail_get_block_size_B(struct ail_layout *layout) +{ + ASSERTED const struct util_format_description *desc = + util_format_description(layout->format); + + assert(((layout->sample_count_sa == 1) || + (desc->block.width == 1 && desc->block.height == 1)) && + "multisampling and block-compression are mutually-exclusive"); + + return util_format_get_blocksize(layout->format) * layout->sample_count_sa; +} + static void ail_initialize_twiddled(struct ail_layout *layout) { unsigned offset_B = 0; - unsigned blocksize_B = util_format_get_blocksize(layout->format); - + unsigned blocksize_B = ail_get_block_size_B(layout); unsigned w_el = util_format_get_nblocksx(layout->format, layout->width_px); unsigned h_el = util_format_get_nblocksy(layout->format, layout->height_px); @@ -161,6 +177,8 @@ ail_make_miptree(struct ail_layout *layout) if (layout->tiling == AIL_TILING_LINEAR) { assert(layout->depth_px == 1 && "Invalid linear layout"); assert(layout->levels == 1 && "Invalid linear layout"); + assert(layout->sample_count_sa == 1 && + "Multisampled linear layouts not supported"); assert(util_format_get_blockwidth(layout->format) == 1 && "Strided linear block formats unsupported"); assert(util_format_get_blockheight(layout->format) == 1 && @@ -169,6 +187,7 @@ ail_make_miptree(struct ail_layout *layout) assert(layout->linear_stride_B == 0 && "Invalid nonlinear layout"); assert(layout->depth_px >= 1 && "Invalid dimensions"); assert(layout->levels >= 1 && "Invalid dimensions"); + assert(layout->sample_count_sa >= 1 && "Invalid samplt count"); } assert(util_format_get_blockdepth(layout->format) == 1 && diff --git a/src/asahi/layout/layout.h b/src/asahi/layout/layout.h index 91a5cf5ea5a..2282d36649d 100644 --- a/src/asahi/layout/layout.h +++ b/src/asahi/layout/layout.h @@ -68,6 +68,9 @@ struct ail_layout { /** Width, height, and depth in pixels at level 0 */ uint32_t width_px, height_px, depth_px; + /** Number of samples per pixel. 1 if multisampling is disabled. */ + uint8_t sample_count_sa; + /** Number of miplevels. 1 if no mipmapping is used. */ uint8_t levels; @@ -164,6 +167,8 @@ ail_get_linear_pixel_B(struct ail_layout *layout, ASSERTED unsigned level, "Strided linear block formats unsupported"); assert(util_format_get_blockheight(layout->format) == 1 && "Strided linear block formats unsupported"); + assert(layout->sample_count_sa == 1 && + "Strided linear multisampling unsupported"); return (y_px * ail_get_linear_stride_B(layout, level)) + (x_px * util_format_get_blocksize(layout->format)); diff --git a/src/asahi/layout/tests/test-layout.cpp b/src/asahi/layout/tests/test-layout.cpp index 9c9e4e45e58..3e007079953 100644 --- a/src/asahi/layout/tests/test-layout.cpp +++ b/src/asahi/layout/tests/test-layout.cpp @@ -30,6 +30,7 @@ TEST(Cubemap, Nonmipmapped) .width_px = 512, .height_px = 512, .depth_px = 6, + .sample_count_sa = 1, .levels = 1, .tiling = AIL_TILING_TWIDDLED, .format = PIPE_FORMAT_R8G8B8A8_UNORM, @@ -47,6 +48,7 @@ TEST(Miptree, SmokeTestBuffer) .width_px = 81946, .height_px = 1, .depth_px = 1, + .sample_count_sa = 1, .levels = 1, .tiling = AIL_TILING_LINEAR, .format = PIPE_FORMAT_R8_UINT, @@ -1299,6 +1301,7 @@ TEST(Miptree, Tests2D) .width_px = test.width, .height_px = test.height, .depth_px = 1, + .sample_count_sa = 1, .levels = test.levels, .tiling = AIL_TILING_TWIDDLED, .format = test.format, diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index ddbd0ffd23f..11668d1cc05 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -147,6 +147,7 @@ agx_resource_setup(struct agx_device *dev, .width_px = templ->width0, .height_px = templ->height0, .depth_px = templ->depth0 * templ->array_size, + .sample_count_sa = MAX2(templ->nr_samples, 1), .levels = templ->last_level + 1, }; }