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"
void
fdl5_layout(struct fdl_layout *layout,
enum pipe_format format, uint32_t nr_samples,
uint32_t width0, uint32_t height0, uint32_t depth0,
uint32_t mip_levels, uint32_t array_size, bool is_3d)
fdl5_layout(struct fdl_layout *layout, enum pipe_format format,
uint32_t nr_samples, uint32_t width0, uint32_t height0,
uint32_t depth0, uint32_t mip_levels, uint32_t array_size,
bool is_3d)
{
assert(nr_samples > 0);
layout->width0 = width0;
layout->height0 = height0;
layout->depth0 = depth0;
assert(nr_samples > 0);
layout->width0 = width0;
layout->height0 = height0;
layout->depth0 = depth0;
layout->cpp = util_format_get_blocksize(format);
layout->cpp *= nr_samples;
layout->cpp_shift = ffs(layout->cpp) - 1;
layout->cpp = util_format_get_blocksize(format);
layout->cpp *= nr_samples;
layout->cpp_shift = ffs(layout->cpp) - 1;
layout->format = format;
layout->nr_samples = nr_samples;
layout->layer_first = !is_3d;
layout->format = format;
layout->nr_samples = nr_samples;
layout->layer_first = !is_3d;
uint32_t heightalign = layout->cpp == 1 ? 32 : 16;
/* in layer_first layout, the level (slice) contains just one
* layer (since in fact the layer contains the slices)
*/
uint32_t layers_in_level = layout->layer_first ? 1 : array_size;
uint32_t heightalign = layout->cpp == 1 ? 32 : 16;
/* in layer_first layout, the level (slice) contains just one
* layer (since in fact the layer contains the slices)
*/
uint32_t layers_in_level = layout->layer_first ? 1 : array_size;
/* use 128 pixel alignment for cpp=1 and cpp=2 */
if (layout->cpp < 4 && layout->tile_mode)
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 7);
else
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 6);
/* use 128 pixel alignment for cpp=1 and cpp=2 */
if (layout->cpp < 4 && layout->tile_mode)
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 7);
else
fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 6);
for (uint32_t level = 0; level < mip_levels; level++) {
struct fdl_slice *slice = &layout->slices[level];
uint32_t tile_mode = fdl_tile_mode(layout, level);
uint32_t pitch = fdl_pitch(layout, level);
uint32_t nblocksy = util_format_get_nblocksy(format, u_minify(height0, level));
for (uint32_t level = 0; level < mip_levels; level++) {
struct fdl_slice *slice = &layout->slices[level];
uint32_t tile_mode = fdl_tile_mode(layout, level);
uint32_t pitch = fdl_pitch(layout, level);
uint32_t nblocksy =
util_format_get_nblocksy(format, u_minify(height0, level));
if (tile_mode) {
nblocksy = align(nblocksy, heightalign);
} else {
/* The blits used for mem<->gmem work at a granularity of
* 32x32, which can cause faults due to over-fetch on the
* last level. The simple solution is to over-allocate a
* bit the last level to ensure any over-fetch is harmless.
* The pitch is already sufficiently aligned, but height
* may not be:
*/
if (level == mip_levels - 1)
nblocksy = align(nblocksy, 32);
}
if (tile_mode) {
nblocksy = align(nblocksy, heightalign);
} else {
/* The blits used for mem<->gmem work at a granularity of
* 32x32, which can cause faults due to over-fetch on the
* last level. The simple solution is to over-allocate a
* bit the last level to ensure any over-fetch is harmless.
* The pitch is already sufficiently aligned, but height
* may not be:
*/
if (level == mip_levels - 1)
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
* 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
* different than what this code does), so as soon as the layer size
* range gets into range, we stop reducing it.
*/
if (is_3d && (
level == 1 ||
(level > 1 && layout->slices[level - 1].size0 > 0xf000)))
slice->size0 = align(nblocksy * pitch, alignment);
else if (level == 0 || layout->layer_first || alignment == 1)
slice->size0 = align(nblocksy * pitch, alignment);
else
slice->size0 = layout->slices[level - 1].size0;
/* 1d array and 2d array textures must all have the same layer size
* 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
* different than what this code does), so as soon as the layer size
* range gets into range, we stop reducing it.
*/
if (is_3d && (level == 1 ||
(level > 1 && layout->slices[level - 1].size0 > 0xf000)))
slice->size0 = align(nblocksy * pitch, alignment);
else if (level == 0 || layout->layer_first || alignment == 1)
slice->size0 = align(nblocksy * pitch, alignment);
else
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
*/
static const struct testcase testcases[] = {
/* Basic POT, non-UBWC layout test */
{
.format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.layout = {
.tile_mode = TILE5_3,
.width0 = 32, .height0 = 32,
.slices = {
{ .offset = 0, .pitch = 256 },
{ .offset = 8192, .pitch = 256 },
{ .offset = 12288, .pitch = 256 },
{ .offset = 14336, .pitch = 256 },
{ .offset = 15360, .pitch = 256 },
{ .offset = 15872, .pitch = 256 },
},
},
},
/* Basic POT, non-UBWC layout test */
{
.format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.layout =
{
.tile_mode = TILE5_3,
.width0 = 32,
.height0 = 32,
.slices =
{
{.offset = 0, .pitch = 256},
{.offset = 8192, .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
* layout.
*/
{
.format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.is_3d = true,
.layout = {
.tile_mode = TILE5_3,
.ubwc = false,
.width0 = 59, .height0 = 37, .depth0 = 11,
.slices = {
{ .offset = 0, .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,
.width0 = 63, .height0 = 29, .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 },
},
},
},
/* Some 3D cases of sizes from the CTS, when I was suspicious of our 3D
* layout.
*/
{
.format = PIPE_FORMAT_R9G9B9E5_FLOAT,
.is_3d = true,
.layout =
{
.tile_mode = TILE5_3,
.ubwc = false,
.width0 = 59,
.height0 = 37,
.depth0 = 11,
.slices =
{
{.offset = 0, .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,
.width0 = 63,
.height0 = 29,
.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
main(int argc, char **argv)
{
int ret = 0;
int ret = 0;
for (int i = 0; i < ARRAY_SIZE(testcases); i++) {
if (!fdl_test_layout(&testcases[i], 540))
ret = 1;
}
for (int i = 0; i < ARRAY_SIZE(testcases); i++) {
if (!fdl_test_layout(&testcases[i], 540))
ret = 1;
}
return ret;
return ret;
}

View File

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

View File

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

View File

@ -32,35 +32,35 @@
void
fdl_layout_buffer(struct fdl_layout *layout, uint32_t size)
{
layout->width0 = size;
layout->height0 = 1;
layout->depth0 = 1;
layout->cpp = 1;
layout->cpp_shift = 0;
layout->size = size;
layout->format = PIPE_FORMAT_R8_UINT;
layout->nr_samples = 1;
layout->width0 = size;
layout->height0 = 1;
layout->depth0 = 1;
layout->cpp = 1;
layout->cpp_shift = 0;
layout->size = size;
layout->format = PIPE_FORMAT_R8_UINT;
layout->nr_samples = 1;
}
void
fdl_dump_layout(struct fdl_layout *layout)
{
for (uint32_t level = 0; level < ARRAY_SIZE(layout->slices) && layout->slices[level].size0; level++) {
struct fdl_slice *slice = &layout->slices[level];
struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level];
for (uint32_t level = 0;
level < ARRAY_SIZE(layout->slices) && layout->slices[level].size0;
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",
util_format_name(layout->format),
u_minify(layout->width0, level),
u_minify(layout->height0, level),
u_minify(layout->depth0, level),
layout->cpp, layout->nr_samples,
level,
fdl_pitch(layout, level),
slice->size0, ubwc_slice->size0,
slice->size0 / fdl_pitch(layout, level),
slice->offset, ubwc_slice->offset,
layout->layer_size, layout->ubwc_layer_size,
fdl_tile_mode(layout, 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",
util_format_name(layout->format), u_minify(layout->width0, level),
u_minify(layout->height0, level), u_minify(layout->depth0, level),
layout->cpp, layout->nr_samples, level, fdl_pitch(layout, level),
slice->size0, ubwc_slice->size0,
slice->size0 / fdl_pitch(layout, level), slice->offset,
ubwc_slice->offset, layout->layer_size, layout->ubwc_layer_size,
fdl_tile_mode(layout, level));
}
}

View File

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