ail: Handle multisampling

It appears that multisampled textures on AGX have all samples of the same pixel
contiguous in memory, effectively using the layout of a single-sampled texture
with a larger block size. Handle in ail.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19871>
This commit is contained in:
Alyssa Rosenzweig
2022-11-18 22:38:27 -05:00
committed by Marge Bot
parent 8781aef6b4
commit 53d013a605
5 changed files with 53 additions and 4 deletions

View File

@@ -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.

View File

@@ -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 &&

View File

@@ -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));

View File

@@ -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,

View File

@@ -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,
};
}