freedreno/fdl: Re-indent

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10293>
This commit is contained in:
Rob Clark 2021-04-16 12:26:04 -07:00 committed by Marge Bot
parent 6050976232
commit c74d93cf01
8 changed files with 1145 additions and 1072 deletions

View File

@ -30,76 +30,75 @@
#include "freedreno_layout.h" #include "freedreno_layout.h"
void void
fdl5_layout(struct fdl_layout *layout, fdl5_layout(struct fdl_layout *layout, enum pipe_format format,
enum pipe_format format, uint32_t nr_samples, uint32_t nr_samples, uint32_t width0, uint32_t height0,
uint32_t width0, uint32_t height0, uint32_t depth0, uint32_t depth0, uint32_t mip_levels, uint32_t array_size,
uint32_t mip_levels, uint32_t array_size, bool is_3d) bool is_3d)
{ {
assert(nr_samples > 0); assert(nr_samples > 0);
layout->width0 = width0; layout->width0 = width0;
layout->height0 = height0; layout->height0 = height0;
layout->depth0 = depth0; layout->depth0 = depth0;
layout->cpp = util_format_get_blocksize(format); layout->cpp = util_format_get_blocksize(format);
layout->cpp *= nr_samples; layout->cpp *= nr_samples;
layout->cpp_shift = ffs(layout->cpp) - 1; layout->cpp_shift = ffs(layout->cpp) - 1;
layout->format = format; layout->format = format;
layout->nr_samples = nr_samples; layout->nr_samples = nr_samples;
layout->layer_first = !is_3d; layout->layer_first = !is_3d;
uint32_t heightalign = layout->cpp == 1 ? 32 : 16; uint32_t heightalign = layout->cpp == 1 ? 32 : 16;
/* in layer_first layout, the level (slice) contains just one /* in layer_first layout, the level (slice) contains just one
* layer (since in fact the layer contains the slices) * layer (since in fact the layer contains the slices)
*/ */
uint32_t layers_in_level = layout->layer_first ? 1 : array_size; uint32_t layers_in_level = layout->layer_first ? 1 : array_size;
/* use 128 pixel alignment for cpp=1 and cpp=2 */ /* use 128 pixel alignment for cpp=1 and cpp=2 */
if (layout->cpp < 4 && layout->tile_mode) if (layout->cpp < 4 && layout->tile_mode)
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 7); fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 7);
else else
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 6); fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 6);
for (uint32_t level = 0; level < mip_levels; level++) { for (uint32_t level = 0; level < mip_levels; level++) {
struct fdl_slice *slice = &layout->slices[level]; struct fdl_slice *slice = &layout->slices[level];
uint32_t tile_mode = fdl_tile_mode(layout, level); uint32_t tile_mode = fdl_tile_mode(layout, level);
uint32_t pitch = fdl_pitch(layout, level); uint32_t pitch = fdl_pitch(layout, level);
uint32_t nblocksy = util_format_get_nblocksy(format, u_minify(height0, level)); uint32_t nblocksy =
util_format_get_nblocksy(format, u_minify(height0, level));
if (tile_mode) { if (tile_mode) {
nblocksy = align(nblocksy, heightalign); nblocksy = align(nblocksy, heightalign);
} else { } else {
/* The blits used for mem<->gmem work at a granularity of /* The blits used for mem<->gmem work at a granularity of
* 32x32, which can cause faults due to over-fetch on the * 32x32, which can cause faults due to over-fetch on the
* last level. The simple solution is to over-allocate a * last level. The simple solution is to over-allocate a
* bit the last level to ensure any over-fetch is harmless. * bit the last level to ensure any over-fetch is harmless.
* The pitch is already sufficiently aligned, but height * The pitch is already sufficiently aligned, but height
* may not be: * may not be:
*/ */
if (level == mip_levels - 1) if (level == mip_levels - 1)
nblocksy = align(nblocksy, 32); nblocksy = align(nblocksy, 32);
} }
slice->offset = layout->size; slice->offset = layout->size;
const int alignment = is_3d ? 4096 : 1; const int alignment = is_3d ? 4096 : 1;
/* 1d array and 2d array textures must all have the same layer size /* 1d array and 2d array textures must all have the same layer size
* for each miplevel on a3xx. 3d textures can have different layer * for each miplevel on a3xx. 3d textures can have different layer
* sizes for high levels, but the hw auto-sizer is buggy (or at least * sizes for high levels, but the hw auto-sizer is buggy (or at least
* different than what this code does), so as soon as the layer size * different than what this code does), so as soon as the layer size
* range gets into range, we stop reducing it. * range gets into range, we stop reducing it.
*/ */
if (is_3d && ( if (is_3d && (level == 1 ||
level == 1 || (level > 1 && layout->slices[level - 1].size0 > 0xf000)))
(level > 1 && layout->slices[level - 1].size0 > 0xf000))) slice->size0 = align(nblocksy * pitch, alignment);
slice->size0 = align(nblocksy * pitch, alignment); else if (level == 0 || layout->layer_first || alignment == 1)
else if (level == 0 || layout->layer_first || alignment == 1) slice->size0 = align(nblocksy * pitch, alignment);
slice->size0 = align(nblocksy * pitch, alignment); else
else slice->size0 = layout->slices[level - 1].size0;
slice->size0 = layout->slices[level - 1].size0;
layout->size += slice->size0 * u_minify(depth0, level) * layers_in_level; layout->size += slice->size0 * u_minify(depth0, level) * layers_in_level;
} }
} }

View File

@ -34,71 +34,82 @@
* on a Pixel 2 * on a Pixel 2
*/ */
static const struct testcase testcases[] = { static const struct testcase testcases[] = {
/* Basic POT, non-UBWC layout test */ /* Basic POT, non-UBWC layout test */
{ {
.format = PIPE_FORMAT_R9G9B9E5_FLOAT, .format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.layout = { .layout =
.tile_mode = TILE5_3, {
.width0 = 32, .height0 = 32, .tile_mode = TILE5_3,
.slices = { .width0 = 32,
{ .offset = 0, .pitch = 256 }, .height0 = 32,
{ .offset = 8192, .pitch = 256 }, .slices =
{ .offset = 12288, .pitch = 256 }, {
{ .offset = 14336, .pitch = 256 }, {.offset = 0, .pitch = 256},
{ .offset = 15360, .pitch = 256 }, {.offset = 8192, .pitch = 256},
{ .offset = 15872, .pitch = 256 }, {.offset = 12288, .pitch = 256},
}, {.offset = 14336, .pitch = 256},
}, {.offset = 15360, .pitch = 256},
}, {.offset = 15872, .pitch = 256},
},
},
},
/* Some 3D cases of sizes from the CTS, when I was suspicious of our 3D /* Some 3D cases of sizes from the CTS, when I was suspicious of our 3D
* layout. * layout.
*/ */
{ {
.format = PIPE_FORMAT_R9G9B9E5_FLOAT, .format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.is_3d = true, .is_3d = true,
.layout = { .layout =
.tile_mode = TILE5_3, {
.ubwc = false, .tile_mode = TILE5_3,
.width0 = 59, .height0 = 37, .depth0 = 11, .ubwc = false,
.slices = { .width0 = 59,
{ .offset = 0, .pitch = 256 }, .height0 = 37,
{ .offset = 135168, .pitch = 256 }, .depth0 = 11,
{ .offset = 176128, .pitch = 256 }, .slices =
{ .offset = 192512, .pitch = 256 }, {
{ .offset = 200704, .pitch = 256 }, {.offset = 0, .pitch = 256},
{ .offset = 208896, .pitch = 256 }, {.offset = 135168, .pitch = 256},
}, {.offset = 176128, .pitch = 256},
}, {.offset = 192512, .pitch = 256},
}, {.offset = 200704, .pitch = 256},
{ {.offset = 208896, .pitch = 256},
.format = PIPE_FORMAT_R32G32_FLOAT, },
.is_3d = true, },
.layout = { },
.tile_mode = TILE5_3, {
.ubwc = false, .format = PIPE_FORMAT_R32G32_FLOAT,
.width0 = 63, .height0 = 29, .depth0 = 11, .is_3d = true,
.slices = { .layout =
{ .offset = 0, .pitch = 512 }, {
{ .offset = 180224, .pitch = 512 }, .tile_mode = TILE5_3,
{ .offset = 221184, .pitch = 512 }, .ubwc = false,
{ .offset = 237568, .pitch = 512 }, .width0 = 63,
{ .offset = 245760, .pitch = 512 }, .height0 = 29,
{ .offset = 253952, .pitch = 512 }, .depth0 = 11,
}, .slices =
}, {
}, {.offset = 0, .pitch = 512},
{.offset = 180224, .pitch = 512},
{.offset = 221184, .pitch = 512},
{.offset = 237568, .pitch = 512},
{.offset = 245760, .pitch = 512},
{.offset = 253952, .pitch = 512},
},
},
},
}; };
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
for (int i = 0; i < ARRAY_SIZE(testcases); i++) { for (int i = 0; i < ARRAY_SIZE(testcases); i++) {
if (!fdl_test_layout(&testcases[i], 540)) if (!fdl_test_layout(&testcases[i], 540))
ret = 1; ret = 1;
} }
return ret; return ret;
} }

View File

@ -32,239 +32,239 @@
static bool static bool
is_r8g8(struct fdl_layout *layout) is_r8g8(struct fdl_layout *layout)
{ {
return layout->cpp == 2 && return layout->cpp == 2 &&
util_format_get_nr_components(layout->format) == 2; util_format_get_nr_components(layout->format) == 2;
} }
void void
fdl6_get_ubwc_blockwidth(struct fdl_layout *layout, fdl6_get_ubwc_blockwidth(struct fdl_layout *layout, uint32_t *blockwidth,
uint32_t *blockwidth, uint32_t *blockheight) uint32_t *blockheight)
{ {
static const struct { static const struct {
uint8_t width; uint8_t width;
uint8_t height; uint8_t height;
} blocksize[] = { } blocksize[] = {
{ 16, 4 }, /* cpp = 1 */ { 16, 4 }, /* cpp = 1 */
{ 16, 4 }, /* cpp = 2 */ { 16, 4 }, /* cpp = 2 */
{ 16, 4 }, /* cpp = 4 */ { 16, 4 }, /* cpp = 4 */
{ 8, 4, }, /* cpp = 8 */ { 8, 4 }, /* cpp = 8 */
{ 4, 4, }, /* cpp = 16 */ { 4, 4 }, /* cpp = 16 */
{ 4, 2 }, /* cpp = 32 */ { 4, 2 }, /* cpp = 32 */
{ 0, 0 }, /* cpp = 64 (TODO) */ { 0, 0 }, /* cpp = 64 (TODO) */
}; };
/* special case for r8g8: */ /* special case for r8g8: */
if (is_r8g8(layout)) { if (is_r8g8(layout)) {
*blockwidth = 16; *blockwidth = 16;
*blockheight = 8; *blockheight = 8;
return; return;
} }
uint32_t cpp = fdl_cpp_shift(layout); uint32_t cpp = fdl_cpp_shift(layout);
assert(cpp < ARRAY_SIZE(blocksize)); assert(cpp < ARRAY_SIZE(blocksize));
*blockwidth = blocksize[cpp].width; *blockwidth = blocksize[cpp].width;
*blockheight = blocksize[cpp].height; *blockheight = blocksize[cpp].height;
} }
static void static void
fdl6_tile_alignment(struct fdl_layout *layout, uint32_t *heightalign) fdl6_tile_alignment(struct fdl_layout *layout, uint32_t *heightalign)
{ {
layout->pitchalign = fdl_cpp_shift(layout); layout->pitchalign = fdl_cpp_shift(layout);
*heightalign = 16; *heightalign = 16;
if (is_r8g8(layout) || layout->cpp == 1) { if (is_r8g8(layout) || layout->cpp == 1) {
layout->pitchalign = 1; layout->pitchalign = 1;
*heightalign = 32; *heightalign = 32;
} else if (layout->cpp == 2) { } else if (layout->cpp == 2) {
layout->pitchalign = 2; layout->pitchalign = 2;
} }
/* note: this base_align is *probably* not always right, /* note: this base_align is *probably* not always right,
* it doesn't really get tested. for example with UBWC we might * it doesn't really get tested. for example with UBWC we might
* want 4k alignment, since we align UBWC levels to 4k * want 4k alignment, since we align UBWC levels to 4k
*/ */
if (layout->cpp == 1) if (layout->cpp == 1)
layout->base_align = 64; layout->base_align = 64;
else if (layout->cpp == 2) else if (layout->cpp == 2)
layout->base_align = 128; layout->base_align = 128;
else else
layout->base_align = 256; layout->base_align = 256;
} }
/* NOTE: good way to test this is: (for example) /* NOTE: good way to test this is: (for example)
* piglit/bin/texelFetch fs sampler3D 100x100x8 * piglit/bin/texelFetch fs sampler3D 100x100x8
*/ */
bool bool
fdl6_layout(struct fdl_layout *layout, fdl6_layout(struct fdl_layout *layout, enum pipe_format format,
enum pipe_format format, uint32_t nr_samples, uint32_t nr_samples, uint32_t width0, uint32_t height0,
uint32_t width0, uint32_t height0, uint32_t depth0, uint32_t depth0, uint32_t mip_levels, uint32_t array_size,
uint32_t mip_levels, uint32_t array_size, bool is_3d, bool is_3d, struct fdl_explicit_layout *explicit_layout)
struct fdl_explicit_layout *explicit_layout)
{ {
uint32_t offset = 0, heightalign; uint32_t offset = 0, heightalign;
uint32_t ubwc_blockwidth, ubwc_blockheight; uint32_t ubwc_blockwidth, ubwc_blockheight;
assert(nr_samples > 0); assert(nr_samples > 0);
layout->width0 = width0; layout->width0 = width0;
layout->height0 = height0; layout->height0 = height0;
layout->depth0 = depth0; layout->depth0 = depth0;
layout->cpp = util_format_get_blocksize(format); layout->cpp = util_format_get_blocksize(format);
layout->cpp *= nr_samples; layout->cpp *= nr_samples;
layout->cpp_shift = ffs(layout->cpp) - 1; layout->cpp_shift = ffs(layout->cpp) - 1;
layout->format = format; layout->format = format;
layout->nr_samples = nr_samples; layout->nr_samples = nr_samples;
layout->layer_first = !is_3d; layout->layer_first = !is_3d;
fdl6_get_ubwc_blockwidth(layout, &ubwc_blockwidth, &ubwc_blockheight); fdl6_get_ubwc_blockwidth(layout, &ubwc_blockwidth, &ubwc_blockheight);
if (depth0 > 1 || ubwc_blockwidth == 0) if (depth0 > 1 || ubwc_blockwidth == 0)
layout->ubwc = false; layout->ubwc = false;
if (layout->ubwc || util_format_is_depth_or_stencil(format)) if (layout->ubwc || util_format_is_depth_or_stencil(format))
layout->tile_all = true; layout->tile_all = true;
/* in layer_first layout, the level (slice) contains just one /* in layer_first layout, the level (slice) contains just one
* layer (since in fact the layer contains the slices) * layer (since in fact the layer contains the slices)
*/ */
uint32_t layers_in_level = layout->layer_first ? 1 : array_size; uint32_t layers_in_level = layout->layer_first ? 1 : array_size;
/* note: for tiled+noubwc layouts, we can use a lower pitchalign /* note: for tiled+noubwc layouts, we can use a lower pitchalign
* which will affect the linear levels only, (the hardware will still * which will affect the linear levels only, (the hardware will still
* expect the tiled alignment on the tiled levels) * expect the tiled alignment on the tiled levels)
*/ */
if (layout->tile_mode) { if (layout->tile_mode) {
fdl6_tile_alignment(layout, &heightalign); fdl6_tile_alignment(layout, &heightalign);
} else { } else {
layout->base_align = 64; layout->base_align = 64;
layout->pitchalign = 0; layout->pitchalign = 0;
/* align pitch to at least 16 pixels: /* align pitch to at least 16 pixels:
* both turnip and galium assume there is enough alignment for 16x4 * both turnip and galium assume there is enough alignment for 16x4
* aligned gmem store. turnip can use CP_BLIT to work without this * aligned gmem store. turnip can use CP_BLIT to work without this
* extra alignment, but gallium driver doesn't implement it yet * extra alignment, but gallium driver doesn't implement it yet
*/ */
if (layout->cpp > 4) if (layout->cpp > 4)
layout->pitchalign = fdl_cpp_shift(layout) - 2; layout->pitchalign = fdl_cpp_shift(layout) - 2;
/* when possible, use a bit more alignment than necessary /* when possible, use a bit more alignment than necessary
* presumably this is better for performance? * presumably this is better for performance?
*/ */
if (!explicit_layout) if (!explicit_layout)
layout->pitchalign = fdl_cpp_shift(layout); layout->pitchalign = fdl_cpp_shift(layout);
/* not used, avoid "may be used uninitialized" warning */ /* not used, avoid "may be used uninitialized" warning */
heightalign = 1; heightalign = 1;
} }
fdl_set_pitchalign(layout, layout->pitchalign + 6); fdl_set_pitchalign(layout, layout->pitchalign + 6);
if (explicit_layout) { if (explicit_layout) {
offset = explicit_layout->offset; offset = explicit_layout->offset;
layout->pitch0 = explicit_layout->pitch; layout->pitch0 = explicit_layout->pitch;
if (align(layout->pitch0, 1 << layout->pitchalign) != layout->pitch0) if (align(layout->pitch0, 1 << layout->pitchalign) != layout->pitch0)
return false; return false;
} }
uint32_t ubwc_width0 = width0; uint32_t ubwc_width0 = width0;
uint32_t ubwc_height0 = height0; uint32_t ubwc_height0 = height0;
uint32_t ubwc_tile_height_alignment = RGB_TILE_HEIGHT_ALIGNMENT; uint32_t ubwc_tile_height_alignment = RGB_TILE_HEIGHT_ALIGNMENT;
if (mip_levels > 1) { if (mip_levels > 1) {
/* With mipmapping enabled, UBWC layout is power-of-two sized, /* With mipmapping enabled, UBWC layout is power-of-two sized,
* specified in log2 width/height in the descriptors. The height * specified in log2 width/height in the descriptors. The height
* alignment is 64 for mipmapping, but for buffer sharing (always * alignment is 64 for mipmapping, but for buffer sharing (always
* single level) other participants expect 16. * single level) other participants expect 16.
*/ */
ubwc_width0 = util_next_power_of_two(width0); ubwc_width0 = util_next_power_of_two(width0);
ubwc_height0 = util_next_power_of_two(height0); ubwc_height0 = util_next_power_of_two(height0);
ubwc_tile_height_alignment = 64; ubwc_tile_height_alignment = 64;
} }
layout->ubwc_width0 = align(DIV_ROUND_UP(ubwc_width0, ubwc_blockwidth), layout->ubwc_width0 = align(DIV_ROUND_UP(ubwc_width0, ubwc_blockwidth),
RGB_TILE_WIDTH_ALIGNMENT); RGB_TILE_WIDTH_ALIGNMENT);
ubwc_height0 = align(DIV_ROUND_UP(ubwc_height0, ubwc_blockheight), ubwc_height0 = align(DIV_ROUND_UP(ubwc_height0, ubwc_blockheight),
ubwc_tile_height_alignment); ubwc_tile_height_alignment);
for (uint32_t level = 0; level < mip_levels; level++) { for (uint32_t level = 0; level < mip_levels; level++) {
uint32_t depth = u_minify(depth0, level); uint32_t depth = u_minify(depth0, level);
struct fdl_slice *slice = &layout->slices[level]; struct fdl_slice *slice = &layout->slices[level];
struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level]; struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level];
uint32_t tile_mode = fdl_tile_mode(layout, level); uint32_t tile_mode = fdl_tile_mode(layout, level);
uint32_t pitch = fdl_pitch(layout, level); uint32_t pitch = fdl_pitch(layout, level);
uint32_t height; uint32_t height;
/* tiled levels of 3D textures are rounded up to PoT dimensions: */ /* tiled levels of 3D textures are rounded up to PoT dimensions: */
if (is_3d && tile_mode) { if (is_3d && tile_mode) {
height = u_minify(util_next_power_of_two(height0), level); height = u_minify(util_next_power_of_two(height0), level);
} else { } else {
height = u_minify(height0, level); height = u_minify(height0, level);
} }
uint32_t nblocksy = util_format_get_nblocksy(format, height); uint32_t nblocksy = util_format_get_nblocksy(format, height);
if (tile_mode) if (tile_mode)
nblocksy = align(nblocksy, heightalign); nblocksy = align(nblocksy, heightalign);
/* The blits used for mem<->gmem work at a granularity of /* The blits used for mem<->gmem work at a granularity of
* 16x4, which can cause faults due to over-fetch on the * 16x4, which can cause faults due to over-fetch on the
* last level. The simple solution is to over-allocate a * last level. The simple solution is to over-allocate a
* bit the last level to ensure any over-fetch is harmless. * bit the last level to ensure any over-fetch is harmless.
* The pitch is already sufficiently aligned, but height * The pitch is already sufficiently aligned, but height
* may not be. note this only matters if last level is linear * may not be. note this only matters if last level is linear
*/ */
if (level == mip_levels - 1) if (level == mip_levels - 1)
nblocksy = align(nblocksy, 4); nblocksy = align(nblocksy, 4);
slice->offset = offset + layout->size; slice->offset = offset + layout->size;
/* 1d array and 2d array textures must all have the same layer size /* 1d array and 2d array textures must all have the same layer size
* for each miplevel on a6xx. 3d textures can have different layer * for each miplevel on a6xx. 3d textures can have different layer
* sizes for high levels, but the hw auto-sizer is buggy (or at least * sizes for high levels, but the hw auto-sizer is buggy (or at least
* different than what this code does), so as soon as the layer size * different than what this code does), so as soon as the layer size
* range gets into range, we stop reducing it. * range gets into range, we stop reducing it.
*/ */
if (is_3d) { if (is_3d) {
if (level < 1 || layout->slices[level - 1].size0 > 0xf000) { if (level < 1 || layout->slices[level - 1].size0 > 0xf000) {
slice->size0 = align(nblocksy * pitch, 4096); slice->size0 = align(nblocksy * pitch, 4096);
} else { } else {
slice->size0 = layout->slices[level - 1].size0; slice->size0 = layout->slices[level - 1].size0;
} }
} else { } else {
slice->size0 = nblocksy * pitch; slice->size0 = nblocksy * pitch;
} }
layout->size += slice->size0 * depth * layers_in_level; layout->size += slice->size0 * depth * layers_in_level;
if (layout->ubwc) { if (layout->ubwc) {
/* with UBWC every level is aligned to 4K */ /* with UBWC every level is aligned to 4K */
layout->size = align(layout->size, 4096); layout->size = align(layout->size, 4096);
uint32_t meta_pitch = fdl_ubwc_pitch(layout, level); uint32_t meta_pitch = fdl_ubwc_pitch(layout, level);
uint32_t meta_height = align(u_minify(ubwc_height0, level), uint32_t meta_height =
ubwc_tile_height_alignment); align(u_minify(ubwc_height0, level), ubwc_tile_height_alignment);
ubwc_slice->size0 = align(meta_pitch * meta_height, UBWC_PLANE_SIZE_ALIGNMENT); ubwc_slice->size0 =
ubwc_slice->offset = offset + layout->ubwc_layer_size; align(meta_pitch * meta_height, UBWC_PLANE_SIZE_ALIGNMENT);
layout->ubwc_layer_size += ubwc_slice->size0; ubwc_slice->offset = offset + layout->ubwc_layer_size;
} layout->ubwc_layer_size += ubwc_slice->size0;
} }
}
if (layout->layer_first) { if (layout->layer_first) {
layout->layer_size = align(layout->size, 4096); layout->layer_size = align(layout->size, 4096);
layout->size = layout->layer_size * array_size; layout->size = layout->layer_size * array_size;
} }
/* Place the UBWC slices before the uncompressed slices, because the /* Place the UBWC slices before the uncompressed slices, because the
* kernel expects UBWC to be at the start of the buffer. In the HW, we * kernel expects UBWC to be at the start of the buffer. In the HW, we
* get to program the UBWC and non-UBWC offset/strides * get to program the UBWC and non-UBWC offset/strides
* independently. * independently.
*/ */
if (layout->ubwc) { if (layout->ubwc) {
for (uint32_t level = 0; level < mip_levels; level++) for (uint32_t level = 0; level < mip_levels; level++)
layout->slices[level].offset += layout->ubwc_layer_size * array_size; layout->slices[level].offset += layout->ubwc_layer_size * array_size;
layout->size += layout->ubwc_layer_size * array_size; layout->size += layout->ubwc_layer_size * array_size;
} }
/* include explicit offset in size */ /* include explicit offset in size */
layout->size += offset; layout->size += offset;
return true; return true;
} }

File diff suppressed because it is too large Load Diff

View File

@ -29,98 +29,85 @@
#include <stdio.h> #include <stdio.h>
bool fdl_test_layout(const struct testcase *testcase, int gpu_id) bool
fdl_test_layout(const struct testcase *testcase, int gpu_id)
{ {
struct fdl_layout layout = { struct fdl_layout layout = {
.ubwc = testcase->layout.ubwc, .ubwc = testcase->layout.ubwc,
.tile_mode = testcase->layout.tile_mode, .tile_mode = testcase->layout.tile_mode,
}; };
bool ok = true; bool ok = true;
int max_size = MAX2(testcase->layout.width0, testcase->layout.height0); int max_size = MAX2(testcase->layout.width0, testcase->layout.height0);
int mip_levels = 1; int mip_levels = 1;
while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) { while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) {
mip_levels++; mip_levels++;
max_size = u_minify(max_size, 1); max_size = u_minify(max_size, 1);
} }
if (gpu_id >= 600) { if (gpu_id >= 600) {
fdl6_layout(&layout, fdl6_layout(&layout, testcase->format,
testcase->format, MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
MAX2(testcase->layout.nr_samples, 1), MAX2(testcase->layout.height0, 1),
testcase->layout.width0, MAX2(testcase->layout.depth0, 1), mip_levels,
MAX2(testcase->layout.height0, 1), MAX2(testcase->array_size, 1), testcase->is_3d, NULL);
MAX2(testcase->layout.depth0, 1), } else {
mip_levels, assert(gpu_id >= 500);
MAX2(testcase->array_size, 1), fdl5_layout(&layout, testcase->format,
testcase->is_3d, MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
NULL); MAX2(testcase->layout.height0, 1),
} else { MAX2(testcase->layout.depth0, 1), mip_levels,
assert(gpu_id >= 500); MAX2(testcase->array_size, 1), testcase->is_3d);
fdl5_layout(&layout, }
testcase->format,
MAX2(testcase->layout.nr_samples, 1),
testcase->layout.width0,
MAX2(testcase->layout.height0, 1),
MAX2(testcase->layout.depth0, 1),
mip_levels,
MAX2(testcase->array_size, 1),
testcase->is_3d);
}
/* fdl lays out UBWC data before the color data, while all we have /* fdl lays out UBWC data before the color data, while all we have
* recorded in this testcase are the color offsets (other than the UBWC * recorded in this testcase are the color offsets (other than the UBWC
* buffer sharing test). Shift the fdl layout down so we can compare * buffer sharing test). Shift the fdl layout down so we can compare
* color offsets. * color offsets.
*/ */
if (layout.ubwc && !testcase->layout.slices[0].offset) { if (layout.ubwc && !testcase->layout.slices[0].offset) {
for (int l = 1; l < mip_levels; l++) for (int l = 1; l < mip_levels; l++)
layout.slices[l].offset -= layout.slices[0].offset; layout.slices[l].offset -= layout.slices[0].offset;
layout.slices[0].offset = 0; layout.slices[0].offset = 0;
} }
for (int l = 0; l < mip_levels; l++) { for (int l = 0; l < mip_levels; l++) {
if (layout.slices[l].offset != testcase->layout.slices[l].offset) { if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n", fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
util_format_short_name(testcase->format), util_format_short_name(testcase->format), layout.width0,
layout.width0, layout.height0, layout.depth0, layout.height0, layout.depth0, layout.nr_samples, l,
layout.nr_samples, l, layout.slices[l].offset, testcase->layout.slices[l].offset);
layout.slices[l].offset, ok = false;
testcase->layout.slices[l].offset); }
ok = false; if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) {
} fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) { util_format_short_name(testcase->format), layout.width0,
fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n", layout.height0, layout.depth0, layout.nr_samples, l,
util_format_short_name(testcase->format), fdl_pitch(&layout, l), testcase->layout.slices[l].pitch);
layout.width0, layout.height0, layout.depth0, ok = false;
layout.nr_samples, l, }
fdl_pitch(&layout, l),
testcase->layout.slices[l].pitch);
ok = false;
}
if (layout.ubwc_slices[l].offset != testcase->layout.ubwc_slices[l].offset) { if (layout.ubwc_slices[l].offset !=
fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n", testcase->layout.ubwc_slices[l].offset) {
util_format_short_name(testcase->format), fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n",
layout.width0, layout.height0, layout.depth0, util_format_short_name(testcase->format), layout.width0,
layout.nr_samples, l, layout.height0, layout.depth0, layout.nr_samples, l,
layout.ubwc_slices[l].offset, layout.ubwc_slices[l].offset,
testcase->layout.ubwc_slices[l].offset); testcase->layout.ubwc_slices[l].offset);
ok = false; ok = false;
} }
if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) { if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) {
fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n", fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n",
util_format_short_name(testcase->format), util_format_short_name(testcase->format), layout.width0,
layout.width0, layout.height0, layout.depth0, layout.height0, layout.depth0, layout.nr_samples, l,
layout.nr_samples, l, fdl_ubwc_pitch(&layout, l),
fdl_ubwc_pitch(&layout, l), testcase->layout.ubwc_slices[l].pitch);
testcase->layout.ubwc_slices[l].pitch); ok = false;
ok = false; }
} }
}
if (!ok) if (!ok)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
return ok; return ok;
} }

View File

@ -22,26 +22,26 @@
*/ */
struct testcase { struct testcase {
enum pipe_format format; enum pipe_format format;
int array_size; /* Size for array textures, or 0 otherwise. */ int array_size; /* Size for array textures, or 0 otherwise. */
bool is_3d; bool is_3d;
/* Partially filled layout of input parameters and expected results. */ /* Partially filled layout of input parameters and expected results. */
struct { struct {
uint32_t tile_mode : 2; uint32_t tile_mode : 2;
bool ubwc : 1; bool ubwc : 1;
uint32_t width0, height0, depth0; uint32_t width0, height0, depth0;
uint32_t nr_samples; uint32_t nr_samples;
struct { struct {
uint32_t offset; uint32_t offset;
uint32_t pitch; uint32_t pitch;
} slices[FDL_MAX_MIP_LEVELS]; } slices[FDL_MAX_MIP_LEVELS];
struct { struct {
uint32_t offset; uint32_t offset;
uint32_t pitch; uint32_t pitch;
} ubwc_slices[FDL_MAX_MIP_LEVELS]; } ubwc_slices[FDL_MAX_MIP_LEVELS];
} layout; } layout;
}; };
bool fdl_test_layout(const struct testcase *testcase, int gpu_id); bool fdl_test_layout(const struct testcase *testcase, int gpu_id);

View File

@ -32,35 +32,35 @@
void void
fdl_layout_buffer(struct fdl_layout *layout, uint32_t size) fdl_layout_buffer(struct fdl_layout *layout, uint32_t size)
{ {
layout->width0 = size; layout->width0 = size;
layout->height0 = 1; layout->height0 = 1;
layout->depth0 = 1; layout->depth0 = 1;
layout->cpp = 1; layout->cpp = 1;
layout->cpp_shift = 0; layout->cpp_shift = 0;
layout->size = size; layout->size = size;
layout->format = PIPE_FORMAT_R8_UINT; layout->format = PIPE_FORMAT_R8_UINT;
layout->nr_samples = 1; layout->nr_samples = 1;
} }
void void
fdl_dump_layout(struct fdl_layout *layout) fdl_dump_layout(struct fdl_layout *layout)
{ {
for (uint32_t level = 0; level < ARRAY_SIZE(layout->slices) && layout->slices[level].size0; level++) { for (uint32_t level = 0;
struct fdl_slice *slice = &layout->slices[level]; level < ARRAY_SIZE(layout->slices) && layout->slices[level].size0;
struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level]; level++) {
struct fdl_slice *slice = &layout->slices[level];
struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level];
fprintf(stderr, "%s: %ux%ux%u@%ux%u:\t%2u: stride=%4u, size=%6u,%6u, aligned_height=%3u, offset=0x%x,0x%x, layersz %5u,%5u tiling=%d\n", fprintf(
util_format_name(layout->format), stderr,
u_minify(layout->width0, level), "%s: %ux%ux%u@%ux%u:\t%2u: stride=%4u, size=%6u,%6u, "
u_minify(layout->height0, level), "aligned_height=%3u, offset=0x%x,0x%x, layersz %5u,%5u tiling=%d\n",
u_minify(layout->depth0, level), util_format_name(layout->format), u_minify(layout->width0, level),
layout->cpp, layout->nr_samples, u_minify(layout->height0, level), u_minify(layout->depth0, level),
level, layout->cpp, layout->nr_samples, level, fdl_pitch(layout, level),
fdl_pitch(layout, level), slice->size0, ubwc_slice->size0,
slice->size0, ubwc_slice->size0, slice->size0 / fdl_pitch(layout, level), slice->offset,
slice->size0 / fdl_pitch(layout, level), ubwc_slice->offset, layout->layer_size, layout->ubwc_layer_size,
slice->offset, ubwc_slice->offset, fdl_tile_mode(layout, level));
layout->layer_size, layout->ubwc_layer_size, }
fdl_tile_mode(layout, level));
}
} }

View File

@ -27,9 +27,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "util/format/u_format.h"
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_math.h" #include "util/u_math.h"
#include "util/format/u_format.h"
/* Shared freedreno mipmap layout helper /* Shared freedreno mipmap layout helper
* *
@ -78,14 +78,14 @@
#define FDL_MAX_MIP_LEVELS 15 #define FDL_MAX_MIP_LEVELS 15
struct fdl_slice { struct fdl_slice {
uint32_t offset; /* offset of first layer in slice */ uint32_t offset; /* offset of first layer in slice */
uint32_t size0; /* size of first layer in slice */ uint32_t size0; /* size of first layer in slice */
}; };
/* parameters for explicit (imported) layout */ /* parameters for explicit (imported) layout */
struct fdl_explicit_layout { struct fdl_explicit_layout {
uint32_t offset; uint32_t offset;
uint32_t pitch; uint32_t pitch;
}; };
/** /**
@ -94,106 +94,107 @@ struct fdl_explicit_layout {
* to derive this. * to derive this.
*/ */
struct fdl_layout { struct fdl_layout {
struct fdl_slice slices[FDL_MAX_MIP_LEVELS]; struct fdl_slice slices[FDL_MAX_MIP_LEVELS];
struct fdl_slice ubwc_slices[FDL_MAX_MIP_LEVELS]; struct fdl_slice ubwc_slices[FDL_MAX_MIP_LEVELS];
uint32_t pitch0; uint32_t pitch0;
uint32_t ubwc_width0; uint32_t ubwc_width0;
uint32_t layer_size; uint32_t layer_size;
uint32_t ubwc_layer_size; /* in bytes */ uint32_t ubwc_layer_size; /* in bytes */
bool ubwc : 1; bool ubwc : 1;
bool layer_first : 1; /* see above description */ bool layer_first : 1; /* see above description */
bool tile_all : 1; bool tile_all : 1;
/* Note that for tiled textures, beyond a certain mipmap level (ie. /* Note that for tiled textures, beyond a certain mipmap level (ie.
* when width is less than block size) things switch to linear. In * when width is less than block size) things switch to linear. In
* general you should not directly look at fdl_layout::tile_mode, * general you should not directly look at fdl_layout::tile_mode,
* but instead use fdl_surface::tile_mode which will correctly take * but instead use fdl_surface::tile_mode which will correctly take
* this into account. * this into account.
*/ */
uint32_t tile_mode : 2; uint32_t tile_mode : 2;
/* Bytes per pixel (where a "pixel" is a single row of a block in the case /* Bytes per pixel (where a "pixel" is a single row of a block in the case
* of compression), including each sample in the case of multisample * of compression), including each sample in the case of multisample
* layouts. * layouts.
*/ */
uint8_t cpp; uint8_t cpp;
/** /**
* Left shift necessary to multiply by cpp. Invalid for NPOT cpp, please * Left shift necessary to multiply by cpp. Invalid for NPOT cpp, please
* use fdl_cpp_shift() to sanity check you aren't hitting that case. * use fdl_cpp_shift() to sanity check you aren't hitting that case.
*/ */
uint8_t cpp_shift; uint8_t cpp_shift;
uint32_t width0, height0, depth0; uint32_t width0, height0, depth0;
uint32_t nr_samples; uint32_t nr_samples;
enum pipe_format format; enum pipe_format format;
uint32_t size; /* Size of the whole image, in bytes. */ uint32_t size; /* Size of the whole image, in bytes. */
uint32_t base_align; /* Alignment of the base address, in bytes. */ uint32_t base_align; /* Alignment of the base address, in bytes. */
uint8_t pitchalign; /* log2(pitchalign) */ uint8_t pitchalign; /* log2(pitchalign) */
}; };
static inline uint32_t static inline uint32_t
fdl_cpp_shift(const struct fdl_layout *layout) fdl_cpp_shift(const struct fdl_layout *layout)
{ {
assert(util_is_power_of_two_or_zero(layout->cpp)); assert(util_is_power_of_two_or_zero(layout->cpp));
return layout->cpp_shift; return layout->cpp_shift;
} }
static inline uint32_t static inline uint32_t
fdl_pitch(const struct fdl_layout *layout, unsigned level) fdl_pitch(const struct fdl_layout *layout, unsigned level)
{ {
return align(u_minify(layout->pitch0, level), 1 << layout->pitchalign); return align(u_minify(layout->pitch0, level), 1 << layout->pitchalign);
} }
#define RGB_TILE_WIDTH_ALIGNMENT 64 #define RGB_TILE_WIDTH_ALIGNMENT 64
#define RGB_TILE_HEIGHT_ALIGNMENT 16 #define RGB_TILE_HEIGHT_ALIGNMENT 16
#define UBWC_PLANE_SIZE_ALIGNMENT 4096 #define UBWC_PLANE_SIZE_ALIGNMENT 4096
static inline uint32_t static inline uint32_t
fdl_ubwc_pitch(const struct fdl_layout *layout, unsigned level) fdl_ubwc_pitch(const struct fdl_layout *layout, unsigned level)
{ {
if (!layout->ubwc) if (!layout->ubwc)
return 0; return 0;
return align(u_minify(layout->ubwc_width0, level), RGB_TILE_WIDTH_ALIGNMENT); return align(u_minify(layout->ubwc_width0, level), RGB_TILE_WIDTH_ALIGNMENT);
} }
static inline uint32_t static inline uint32_t
fdl_layer_stride(const struct fdl_layout *layout, unsigned level) fdl_layer_stride(const struct fdl_layout *layout, unsigned level)
{ {
if (layout->layer_first) if (layout->layer_first)
return layout->layer_size; return layout->layer_size;
else else
return layout->slices[level].size0; return layout->slices[level].size0;
} }
/* a2xx is special and needs PoT alignment for mipmaps: */ /* a2xx is special and needs PoT alignment for mipmaps: */
static inline uint32_t static inline uint32_t
fdl2_pitch(const struct fdl_layout *layout, unsigned level) fdl2_pitch(const struct fdl_layout *layout, unsigned level)
{ {
uint32_t pitch = fdl_pitch(layout, level); uint32_t pitch = fdl_pitch(layout, level);
if (level) if (level)
pitch = util_next_power_of_two(pitch); pitch = util_next_power_of_two(pitch);
return pitch; return pitch;
} }
static inline uint32_t static inline uint32_t
fdl2_pitch_pixels(const struct fdl_layout *layout, unsigned level) fdl2_pitch_pixels(const struct fdl_layout *layout, unsigned level)
{ {
return fdl2_pitch(layout, level) >> fdl_cpp_shift(layout); return fdl2_pitch(layout, level) >> fdl_cpp_shift(layout);
} }
static inline uint32_t static inline uint32_t
fdl_surface_offset(const struct fdl_layout *layout, unsigned level, unsigned layer) fdl_surface_offset(const struct fdl_layout *layout, unsigned level,
unsigned layer)
{ {
const struct fdl_slice *slice = &layout->slices[level]; const struct fdl_slice *slice = &layout->slices[level];
return slice->offset + fdl_layer_stride(layout, level) * layer; return slice->offset + fdl_layer_stride(layout, level) * layer;
} }
static inline uint32_t static inline uint32_t
fdl_ubwc_offset(const struct fdl_layout *layout, unsigned level, unsigned layer) fdl_ubwc_offset(const struct fdl_layout *layout, unsigned level, unsigned layer)
{ {
const struct fdl_slice *slice = &layout->ubwc_slices[level]; const struct fdl_slice *slice = &layout->ubwc_slices[level];
return slice->offset + layer * layout->ubwc_layer_size; return slice->offset + layer * layout->ubwc_layer_size;
} }
/* Minimum layout width to enable UBWC. */ /* Minimum layout width to enable UBWC. */
@ -202,60 +203,54 @@ fdl_ubwc_offset(const struct fdl_layout *layout, unsigned level, unsigned layer)
static inline bool static inline bool
fdl_level_linear(const struct fdl_layout *layout, int level) fdl_level_linear(const struct fdl_layout *layout, int level)
{ {
if (layout->tile_all) if (layout->tile_all)
return false; return false;
unsigned w = u_minify(layout->width0, level); unsigned w = u_minify(layout->width0, level);
if (w < FDL_MIN_UBWC_WIDTH) if (w < FDL_MIN_UBWC_WIDTH)
return true; return true;
return false; return false;
} }
static inline uint32_t static inline uint32_t
fdl_tile_mode(const struct fdl_layout *layout, int level) fdl_tile_mode(const struct fdl_layout *layout, int level)
{ {
if (layout->tile_mode && fdl_level_linear(layout, level)) if (layout->tile_mode && fdl_level_linear(layout, level))
return 0; /* linear */ return 0; /* linear */
else else
return layout->tile_mode; return layout->tile_mode;
} }
static inline bool static inline bool
fdl_ubwc_enabled(const struct fdl_layout *layout, int level) fdl_ubwc_enabled(const struct fdl_layout *layout, int level)
{ {
return layout->ubwc; return layout->ubwc;
} }
void void fdl_layout_buffer(struct fdl_layout *layout, uint32_t size);
fdl_layout_buffer(struct fdl_layout *layout, uint32_t size);
void void fdl5_layout(struct fdl_layout *layout, enum pipe_format format,
fdl5_layout(struct fdl_layout *layout, uint32_t nr_samples, uint32_t width0, uint32_t height0,
enum pipe_format format, uint32_t nr_samples, uint32_t depth0, uint32_t mip_levels, uint32_t array_size,
uint32_t width0, uint32_t height0, uint32_t depth0, bool is_3d);
uint32_t mip_levels, uint32_t array_size, bool is_3d);
bool bool fdl6_layout(struct fdl_layout *layout, enum pipe_format format,
fdl6_layout(struct fdl_layout *layout, uint32_t nr_samples, uint32_t width0, uint32_t height0,
enum pipe_format format, uint32_t nr_samples, uint32_t depth0, uint32_t mip_levels, uint32_t array_size,
uint32_t width0, uint32_t height0, uint32_t depth0, bool is_3d, struct fdl_explicit_layout *plane_layout);
uint32_t mip_levels, uint32_t array_size, bool is_3d,
struct fdl_explicit_layout *plane_layout);
static inline void static inline void
fdl_set_pitchalign(struct fdl_layout *layout, unsigned pitchalign) fdl_set_pitchalign(struct fdl_layout *layout, unsigned pitchalign)
{ {
uint32_t nblocksx = util_format_get_nblocksx(layout->format, layout->width0); uint32_t nblocksx = util_format_get_nblocksx(layout->format, layout->width0);
layout->pitchalign = pitchalign; layout->pitchalign = pitchalign;
layout->pitch0 = align(nblocksx * layout->cpp, 1 << pitchalign); layout->pitch0 = align(nblocksx * layout->cpp, 1 << pitchalign);
} }
void void fdl_dump_layout(struct fdl_layout *layout);
fdl_dump_layout(struct fdl_layout *layout);
void void fdl6_get_ubwc_blockwidth(struct fdl_layout *layout, uint32_t *blockwidth,
fdl6_get_ubwc_blockwidth(struct fdl_layout *layout, uint32_t *blockheight);
uint32_t *blockwidth, uint32_t *blockheight);
#endif /* FREEDRENO_LAYOUT_H_ */ #endif /* FREEDRENO_LAYOUT_H_ */