#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include "genxml/genX_bits.h"
#include "isl.h"
#include "isl_gfx4.h"
#include "isl_gfx6.h"
#include "isl_gfx7.h"
#include "isl_gfx8.h"
#include "isl_gfx9.h"
#include "isl_gfx12.h"
#include "isl_priv.h"
void
isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
uint32_t yt1, uint32_t yt2,
char *dst, const char *src,
uint32_t dst_pitch, int32_t src_pitch,
bool has_swizzling,
enum isl_tiling tiling,
isl_memcpy_type copy_type)
{
#ifdef USE_SSE41
if (copy_type == ISL_MEMCPY_STREAMING_LOAD) {
_isl_memcpy_linear_to_tiled_sse41(
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
tiling, copy_type);
return;
}
#endif
_isl_memcpy_linear_to_tiled(
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
tiling, copy_type);
}
void
isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
uint32_t yt1, uint32_t yt2,
char *dst, const char *src,
int32_t dst_pitch, uint32_t src_pitch,
bool has_swizzling,
enum isl_tiling tiling,
isl_memcpy_type copy_type)
{
#ifdef USE_SSE41
if (copy_type == ISL_MEMCPY_STREAMING_LOAD) {
_isl_memcpy_tiled_to_linear_sse41(
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
tiling, copy_type);
return;
}
#endif
_isl_memcpy_tiled_to_linear(
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
tiling, copy_type);
}
void PRINTFLIKE(3, 4) UNUSED
__isl_finishme(const char *file, int line, const char *fmt, ...)
{
va_list ap;
char buf[512];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buf);
}
static void
isl_device_setup_mocs(struct isl_device *dev)
{
if (dev->info->ver >= 12) {
if (dev->info->is_dg1) {
dev->mocs.internal = 5 << 1;
dev->mocs.external = 5 << 1;
} else {
dev->mocs.external = 3 << 1;
dev->mocs.internal = 2 << 1;
dev->mocs.l1_hdc_l3_llc = 48 << 1;
}
} else if (dev->info->ver >= 9) {
dev->mocs.external = 1 << 1;
dev->mocs.internal = 2 << 1;
} else if (dev->info->ver >= 8) {
dev->mocs.external = 0x18;
dev->mocs.internal = 0x78;
} else if (dev->info->ver >= 7) {
if (dev->info->is_haswell) {
dev->mocs.internal = 1;
dev->mocs.external = 1;
} else {
dev->mocs.internal = 1;
dev->mocs.external = 1;
}
} else {
dev->mocs.internal = 0;
dev->mocs.external = 0;
}
}
uint32_t
isl_mocs(const struct isl_device *dev, isl_surf_usage_flags_t usage,
bool external)
{
if (external)
return dev->mocs.external;
if (dev->info->ver >= 12 && !dev->info->is_dg1) {
if (usage & ISL_SURF_USAGE_STAGING_BIT)
return dev->mocs.internal;
if (usage & ISL_SURF_USAGE_STORAGE_BIT)
return dev->mocs.internal;
if (usage & (ISL_SURF_USAGE_CONSTANT_BUFFER_BIT |
ISL_SURF_USAGE_RENDER_TARGET_BIT |
ISL_SURF_USAGE_TEXTURE_BIT))
return dev->mocs.l1_hdc_l3_llc;
}
return dev->mocs.internal;
}
void
isl_device_init(struct isl_device *dev,
const struct intel_device_info *info,
bool has_bit6_swizzling)
{
assert(!(has_bit6_swizzling && info->ver >= 8));
dev->info = info;
dev->use_separate_stencil = ISL_GFX_VER(dev) >= 6;
dev->has_bit6_swizzling = has_bit6_swizzling;
ISL_GFX_VER_SANITIZE(dev);
ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(dev);
if (ISL_DEV_USE_SEPARATE_STENCIL(dev))
assert(info->has_hiz_and_separate_stencil);
if (info->must_use_separate_stencil)
assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
dev->ss.size = RENDER_SURFACE_STATE_length(info) * 4;
dev->ss.align = isl_align(dev->ss.size, 32);
dev->ss.clear_color_state_size =
isl_align(CLEAR_COLOR_length(info) * 4, 64);
dev->ss.clear_color_state_offset =
RENDER_SURFACE_STATE_ClearValueAddress_start(info) / 32 * 4;
dev->ss.clear_value_size =
isl_align(RENDER_SURFACE_STATE_RedClearColor_bits(info) +
RENDER_SURFACE_STATE_GreenClearColor_bits(info) +
RENDER_SURFACE_STATE_BlueClearColor_bits(info) +
RENDER_SURFACE_STATE_AlphaClearColor_bits(info), 32) / 8;
dev->ss.clear_value_offset =
RENDER_SURFACE_STATE_RedClearColor_start(info) / 32 * 4;
assert(RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) % 8 == 0);
dev->ss.addr_offset =
RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) / 8;
dev->ss.aux_addr_offset =
(RENDER_SURFACE_STATE_AuxiliarySurfaceBaseAddress_start(info) & ~31) / 8;
dev->ds.size = _3DSTATE_DEPTH_BUFFER_length(info) * 4;
assert(_3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
dev->ds.depth_offset =
_3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
if (dev->use_separate_stencil) {
dev->ds.size += _3DSTATE_STENCIL_BUFFER_length(info) * 4 +
_3DSTATE_HIER_DEPTH_BUFFER_length(info) * 4 +
_3DSTATE_CLEAR_PARAMS_length(info) * 4;
assert(_3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
dev->ds.stencil_offset =
_3DSTATE_DEPTH_BUFFER_length(info) * 4 +
_3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) / 8;
assert(_3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
dev->ds.hiz_offset =
_3DSTATE_DEPTH_BUFFER_length(info) * 4 +
_3DSTATE_STENCIL_BUFFER_length(info) * 4 +
_3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
} else {
dev->ds.stencil_offset = 0;
dev->ds.hiz_offset = 0;
}
if (ISL_GFX_VERX10(dev) == 120) {
dev->ds.size += GFX12_MI_LOAD_REGISTER_IMM_length * 4 * 2;
}
isl_device_setup_mocs(dev);
}
isl_sample_count_mask_t ATTRIBUTE_CONST
isl_device_get_sample_counts(struct isl_device *dev)
{
if (ISL_GFX_VER(dev) >= 9) {
return ISL_SAMPLE_COUNT_1_BIT |
ISL_SAMPLE_COUNT_2_BIT |
ISL_SAMPLE_COUNT_4_BIT |
ISL_SAMPLE_COUNT_8_BIT |
ISL_SAMPLE_COUNT_16_BIT;
} else if (ISL_GFX_VER(dev) >= 8) {
return ISL_SAMPLE_COUNT_1_BIT |
ISL_SAMPLE_COUNT_2_BIT |
ISL_SAMPLE_COUNT_4_BIT |
ISL_SAMPLE_COUNT_8_BIT;
} else if (ISL_GFX_VER(dev) >= 7) {
return ISL_SAMPLE_COUNT_1_BIT |
ISL_SAMPLE_COUNT_4_BIT |
ISL_SAMPLE_COUNT_8_BIT;
} else if (ISL_GFX_VER(dev) >= 6) {
return ISL_SAMPLE_COUNT_1_BIT |
ISL_SAMPLE_COUNT_4_BIT;
} else {
return ISL_SAMPLE_COUNT_1_BIT;
}
}
void
isl_tiling_get_info(enum isl_tiling tiling,
uint32_t format_bpb,
struct isl_tile_info *tile_info)
{
const uint32_t bs = format_bpb / 8;
struct isl_extent4d logical_el;
struct isl_extent2d phys_B;
if (tiling != ISL_TILING_LINEAR && !isl_is_pow2(format_bpb)) {
assert(tiling == ISL_TILING_X || tiling == ISL_TILING_Y0);
assert(bs % 3 == 0 && isl_is_pow2(format_bpb / 3));
isl_tiling_get_info(tiling, format_bpb / 3, tile_info);
return;
}
switch (tiling) {
case ISL_TILING_LINEAR:
assert(bs > 0);
logical_el = isl_extent4d(1, 1, 1, 1);
phys_B = isl_extent2d(bs, 1);
break;
case ISL_TILING_X:
assert(bs > 0);
logical_el = isl_extent4d(512 / bs, 8, 1, 1);
phys_B = isl_extent2d(512, 8);
break;
case ISL_TILING_Y0:
assert(bs > 0);
logical_el = isl_extent4d(128 / bs, 32, 1, 1);
phys_B = isl_extent2d(128, 32);
break;
case ISL_TILING_W:
assert(bs == 1);
logical_el = isl_extent4d(64, 64, 1, 1);
phys_B = isl_extent2d(128, 32);
break;
case ISL_TILING_Yf:
case ISL_TILING_Ys: {
bool is_Ys = tiling == ISL_TILING_Ys;
assert(bs > 0);
unsigned width = 1 << (6 + (ffs(bs) / 2) + (2 * is_Ys));
unsigned height = 1 << (6 - (ffs(bs) / 2) + (2 * is_Ys));
logical_el = isl_extent4d(width / bs, height, 1, 1);
phys_B = isl_extent2d(width, height);
break;
}
case ISL_TILING_HIZ:
assert(bs == 16);
logical_el = isl_extent4d(16, 16, 1, 1);
phys_B = isl_extent2d(128, 32);
break;
case ISL_TILING_CCS:
assert(format_bpb == 1 || format_bpb == 2);
logical_el = isl_extent4d(128, 256 / format_bpb, 1, 1);
phys_B = isl_extent2d(128, 32);
break;
case ISL_TILING_GFX12_CCS:
assert(format_bpb == 4);
logical_el = isl_extent4d(16, 8, 1, 1);
phys_B = isl_extent2d(64, 1);
break;
default:
unreachable("not reached");
}
*tile_info = (struct isl_tile_info) {
.tiling = tiling,
.format_bpb = format_bpb,
.logical_extent_el = logical_el,
.phys_extent_B = phys_B,
};
}
bool
isl_color_value_is_zero(union isl_color_value value,
enum isl_format format)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
#define RETURN_FALSE_IF_NOT_0(c, i) \
if (fmtl->channels.c.bits && value.u32[i] != 0) \
return false
RETURN_FALSE_IF_NOT_0(r, 0);
RETURN_FALSE_IF_NOT_0(g, 1);
RETURN_FALSE_IF_NOT_0(b, 2);
RETURN_FALSE_IF_NOT_0(a, 3);
#undef RETURN_FALSE_IF_NOT_0
return true;
}
bool
isl_color_value_is_zero_one(union isl_color_value value,
enum isl_format format)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
#define RETURN_FALSE_IF_NOT_0_1(c, i, field) \
if (fmtl->channels.c.bits && value.field[i] != 0 && value.field[i] != 1) \
return false
if (isl_format_has_int_channel(format)) {
RETURN_FALSE_IF_NOT_0_1(r, 0, u32);
RETURN_FALSE_IF_NOT_0_1(g, 1, u32);
RETURN_FALSE_IF_NOT_0_1(b, 2, u32);
RETURN_FALSE_IF_NOT_0_1(a, 3, u32);
} else {
RETURN_FALSE_IF_NOT_0_1(r, 0, f32);
RETURN_FALSE_IF_NOT_0_1(g, 1, f32);
RETURN_FALSE_IF_NOT_0_1(b, 2, f32);
RETURN_FALSE_IF_NOT_0_1(a, 3, f32);
}
#undef RETURN_FALSE_IF_NOT_0_1
return true;
}
static bool
isl_surf_choose_tiling(const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
enum isl_tiling *tiling)
{
isl_tiling_flags_t tiling_flags = info->tiling_flags;
if (info->usage & ISL_SURF_USAGE_HIZ_BIT) {
assert(info->format == ISL_FORMAT_HIZ);
assert(tiling_flags == ISL_TILING_HIZ_BIT);
*tiling = isl_tiling_flag_to_enum(tiling_flags);
return true;
}
if (info->usage & ISL_SURF_USAGE_CCS_BIT) {
assert(isl_format_get_layout(info->format)->txc == ISL_TXC_CCS);
UNUSED bool ivb_ccs = ISL_GFX_VER(dev) < 12 &&
tiling_flags == ISL_TILING_CCS_BIT;
UNUSED bool tgl_ccs = ISL_GFX_VER(dev) >= 12 &&
tiling_flags == ISL_TILING_GFX12_CCS_BIT;
assert(ivb_ccs != tgl_ccs);
*tiling = isl_tiling_flag_to_enum(tiling_flags);
return true;
}
if (ISL_GFX_VER(dev) >= 6) {
isl_gfx6_filter_tiling(dev, info, &tiling_flags);
} else {
isl_gfx4_filter_tiling(dev, info, &tiling_flags);
}
#define CHOOSE(__tiling) \
do { \
if (tiling_flags & (1u << (__tiling))) { \
*tiling = (__tiling); \
return true; \
} \
} while (0)
if (info->dim == ISL_SURF_DIM_1D) {
CHOOSE(ISL_TILING_LINEAR);
}
CHOOSE(ISL_TILING_Ys);
CHOOSE(ISL_TILING_Yf);
CHOOSE(ISL_TILING_Y0);
CHOOSE(ISL_TILING_X);
CHOOSE(ISL_TILING_W);
CHOOSE(ISL_TILING_LINEAR);
#undef CHOOSE
return false;
}
static bool
isl_choose_msaa_layout(const struct isl_device *dev,
const struct isl_surf_init_info *info,
enum isl_tiling tiling,
enum isl_msaa_layout *msaa_layout)
{
if (ISL_GFX_VER(dev) >= 8) {
return isl_gfx8_choose_msaa_layout(dev, info, tiling, msaa_layout);
} else if (ISL_GFX_VER(dev) >= 7) {
return isl_gfx7_choose_msaa_layout(dev, info, tiling, msaa_layout);
} else if (ISL_GFX_VER(dev) >= 6) {
return isl_gfx6_choose_msaa_layout(dev, info, tiling, msaa_layout);
} else {
return isl_gfx4_choose_msaa_layout(dev, info, tiling, msaa_layout);
}
}
struct isl_extent2d
isl_get_interleaved_msaa_px_size_sa(uint32_t samples)
{
assert(isl_is_pow2(samples));
return (struct isl_extent2d) {
.width = 1 << ((ffs(samples) - 0) / 2),
.height = 1 << ((ffs(samples) - 1) / 2),
};
}
static void
isl_msaa_interleaved_scale_px_to_sa(uint32_t samples,
uint32_t *width, uint32_t *height)
{
const struct isl_extent2d px_size_sa =
isl_get_interleaved_msaa_px_size_sa(samples);
if (width)
*width = isl_align(*width, 2) * px_size_sa.width;
if (height)
*height = isl_align(*height, 2) * px_size_sa.height;
}
static enum isl_array_pitch_span
isl_choose_array_pitch_span(const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
enum isl_dim_layout dim_layout,
const struct isl_extent4d *phys_level0_sa)
{
switch (dim_layout) {
case ISL_DIM_LAYOUT_GFX9_1D:
case ISL_DIM_LAYOUT_GFX4_2D:
if (ISL_GFX_VER(dev) >= 8) {
return ISL_ARRAY_PITCH_SPAN_COMPACT;
} else if (ISL_GFX_VER(dev) >= 7) {
if (phys_level0_sa->array_len == 1) {
return ISL_ARRAY_PITCH_SPAN_COMPACT;
}
if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
(info->usage & ISL_SURF_USAGE_HIZ_BIT)) {
return ISL_ARRAY_PITCH_SPAN_FULL;
}
if (info->levels == 1) {
return ISL_ARRAY_PITCH_SPAN_COMPACT;
}
return ISL_ARRAY_PITCH_SPAN_FULL;
} else if ((ISL_GFX_VER(dev) == 5 || ISL_GFX_VER(dev) == 6) &&
ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
isl_surf_usage_is_stencil(info->usage)) {
assert(info->levels == 1);
return ISL_ARRAY_PITCH_SPAN_COMPACT;
} else {
if ((ISL_GFX_VER(dev) == 5 || ISL_GFX_VER(dev) == 6) &&
ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
isl_surf_usage_is_stencil(info->usage)) {
assert(info->levels == 1);
assert(phys_level0_sa->array_len == 1);
return ISL_ARRAY_PITCH_SPAN_COMPACT;
}
if (phys_level0_sa->array_len == 1) {
return ISL_ARRAY_PITCH_SPAN_COMPACT;
}
return ISL_ARRAY_PITCH_SPAN_FULL;
}
case ISL_DIM_LAYOUT_GFX4_3D:
return ISL_ARRAY_PITCH_SPAN_COMPACT;
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
return ISL_ARRAY_PITCH_SPAN_COMPACT;
}
unreachable("bad isl_dim_layout");
return ISL_ARRAY_PITCH_SPAN_FULL;
}
static void
isl_choose_image_alignment_el(const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
enum isl_tiling tiling,
enum isl_dim_layout dim_layout,
enum isl_msaa_layout msaa_layout,
struct isl_extent3d *image_align_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
if (fmtl->txc == ISL_TXC_MCS) {
assert(tiling == ISL_TILING_Y0);
*image_align_el = isl_extent3d(4, 4, 1);
return;
} else if (info->format == ISL_FORMAT_HIZ) {
assert(ISL_GFX_VER(dev) >= 6);
if (ISL_GFX_VER(dev) == 6) {
*image_align_el = isl_extent3d(1, 1, 1);
} else if (ISL_GFX_VER(dev) < 12) {
*image_align_el = isl_extent3d(2, 2, 1);
} else {
*image_align_el = isl_extent3d(2, 4, 1);
}
return;
}
if (ISL_GFX_VER(dev) >= 12) {
isl_gfx12_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
} else if (ISL_GFX_VER(dev) >= 9) {
isl_gfx9_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
} else if (ISL_GFX_VER(dev) >= 8) {
isl_gfx8_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
} else if (ISL_GFX_VER(dev) >= 7) {
isl_gfx7_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
} else if (ISL_GFX_VER(dev) >= 6) {
isl_gfx6_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
} else {
isl_gfx4_choose_image_alignment_el(dev, info, tiling, dim_layout,
msaa_layout, image_align_el);
}
}
static enum isl_dim_layout
isl_surf_choose_dim_layout(const struct isl_device *dev,
enum isl_surf_dim logical_dim,
enum isl_tiling tiling,
isl_surf_usage_flags_t usage)
{
if (ISL_GFX_VER(dev) == 6 &&
(tiling == ISL_TILING_W || tiling == ISL_TILING_HIZ))
return ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ;
if (ISL_GFX_VER(dev) >= 9) {
switch (logical_dim) {
case ISL_SURF_DIM_1D:
if (tiling == ISL_TILING_LINEAR)
return ISL_DIM_LAYOUT_GFX9_1D;
else
return ISL_DIM_LAYOUT_GFX4_2D;
case ISL_SURF_DIM_2D:
case ISL_SURF_DIM_3D:
return ISL_DIM_LAYOUT_GFX4_2D;
}
} else {
switch (logical_dim) {
case ISL_SURF_DIM_1D:
case ISL_SURF_DIM_2D:
if (ISL_GFX_VER(dev) == 4 && (usage & ISL_SURF_USAGE_CUBE_BIT))
return ISL_DIM_LAYOUT_GFX4_3D;
return ISL_DIM_LAYOUT_GFX4_2D;
case ISL_SURF_DIM_3D:
return ISL_DIM_LAYOUT_GFX4_3D;
}
}
unreachable("bad isl_surf_dim");
return ISL_DIM_LAYOUT_GFX4_2D;
}
static void
isl_calc_phys_level0_extent_sa(const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
enum isl_dim_layout dim_layout,
enum isl_tiling tiling,
enum isl_msaa_layout msaa_layout,
struct isl_extent4d *phys_level0_sa)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
if (isl_format_is_planar(info->format))
unreachable("Planar formats unsupported");
switch (info->dim) {
case ISL_SURF_DIM_1D:
assert(info->height == 1);
assert(info->depth == 1);
assert(info->samples == 1);
switch (dim_layout) {
case ISL_DIM_LAYOUT_GFX4_3D:
unreachable("bad isl_dim_layout");
case ISL_DIM_LAYOUT_GFX9_1D:
case ISL_DIM_LAYOUT_GFX4_2D:
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = 1,
.d = 1,
.a = info->array_len,
};
break;
}
break;
case ISL_SURF_DIM_2D:
if (ISL_GFX_VER(dev) == 4 && (info->usage & ISL_SURF_USAGE_CUBE_BIT))
assert(dim_layout == ISL_DIM_LAYOUT_GFX4_3D);
else
assert(dim_layout == ISL_DIM_LAYOUT_GFX4_2D ||
dim_layout == ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ);
if (tiling == ISL_TILING_Ys && info->samples > 1)
isl_finishme("%s:%s: multisample TileYs layout", __FILE__, __func__);
switch (msaa_layout) {
case ISL_MSAA_LAYOUT_NONE:
assert(info->depth == 1);
assert(info->samples == 1);
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = info->height,
.d = 1,
.a = info->array_len,
};
break;
case ISL_MSAA_LAYOUT_ARRAY:
assert(info->depth == 1);
assert(info->levels == 1);
assert(isl_format_supports_multisampling(dev->info, info->format));
assert(fmtl->bw == 1 && fmtl->bh == 1);
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = info->height,
.d = 1,
.a = info->array_len * info->samples,
};
break;
case ISL_MSAA_LAYOUT_INTERLEAVED:
assert(info->depth == 1);
assert(info->levels == 1);
assert(isl_format_supports_multisampling(dev->info, info->format));
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = info->height,
.d = 1,
.a = info->array_len,
};
isl_msaa_interleaved_scale_px_to_sa(info->samples,
&phys_level0_sa->w,
&phys_level0_sa->h);
break;
}
break;
case ISL_SURF_DIM_3D:
assert(info->array_len == 1);
assert(info->samples == 1);
if (fmtl->bd > 1) {
isl_finishme("%s:%s: compression block with depth > 1",
__FILE__, __func__);
}
switch (dim_layout) {
case ISL_DIM_LAYOUT_GFX9_1D:
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
unreachable("bad isl_dim_layout");
case ISL_DIM_LAYOUT_GFX4_2D:
assert(ISL_GFX_VER(dev) >= 9);
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = info->height,
.d = 1,
.a = info->depth,
};
break;
case ISL_DIM_LAYOUT_GFX4_3D:
assert(ISL_GFX_VER(dev) < 9);
*phys_level0_sa = (struct isl_extent4d) {
.w = info->width,
.h = info->height,
.d = info->depth,
.a = 1,
};
break;
}
break;
}
}
static uint32_t
isl_calc_array_pitch_el_rows_gfx4_2d(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_tile_info *tile_info,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
enum isl_array_pitch_span array_pitch_span,
const struct isl_extent2d *phys_slice0_sa)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
uint32_t pitch_sa_rows = 0;
switch (array_pitch_span) {
case ISL_ARRAY_PITCH_SPAN_COMPACT:
pitch_sa_rows = isl_align_npot(phys_slice0_sa->h, image_align_sa->h);
break;
case ISL_ARRAY_PITCH_SPAN_FULL: {
uint32_t H0_sa = phys_level0_sa->h;
uint32_t H1_sa = isl_minify(H0_sa, 1);
uint32_t h0_sa = isl_align_npot(H0_sa, image_align_sa->h);
uint32_t h1_sa = isl_align_npot(H1_sa, image_align_sa->h);
uint32_t m;
if (ISL_GFX_VER(dev) >= 7) {
m = 12;
} else {
m = 11;
}
pitch_sa_rows = h0_sa + h1_sa + (m * image_align_sa->h);
if (ISL_GFX_VER(dev) == 6 && info->samples > 1 &&
(info->height % 4 == 1)) {
pitch_sa_rows += 4;
}
pitch_sa_rows = isl_align_npot(pitch_sa_rows, fmtl->bh);
}
break;
}
assert(pitch_sa_rows % fmtl->bh == 0);
uint32_t pitch_el_rows = pitch_sa_rows / fmtl->bh;
if (ISL_GFX_VER(dev) >= 9 && ISL_GFX_VER(dev) <= 11 &&
fmtl->txc == ISL_TXC_CCS) {
assert(fmtl->bh == 4);
pitch_el_rows = isl_align(pitch_el_rows, 256 / 4);
}
if (ISL_GFX_VER(dev) >= 9 &&
info->dim == ISL_SURF_DIM_3D &&
tile_info->tiling != ISL_TILING_LINEAR) {
pitch_el_rows = isl_align(pitch_el_rows, tile_info->logical_extent_el.height);
}
return pitch_el_rows;
}
static void
isl_calc_phys_slice0_extent_sa_gfx4_2d(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
enum isl_msaa_layout msaa_layout,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
struct isl_extent2d *phys_slice0_sa)
{
assert(phys_level0_sa->depth == 1);
if (info->levels == 1) {
*phys_slice0_sa = (struct isl_extent2d) {
.w = phys_level0_sa->w,
.h = phys_level0_sa->h,
};
return;
}
uint32_t slice_top_w = 0;
uint32_t slice_bottom_w = 0;
uint32_t slice_left_h = 0;
uint32_t slice_right_h = 0;
uint32_t W0 = phys_level0_sa->w;
uint32_t H0 = phys_level0_sa->h;
for (uint32_t l = 0; l < info->levels; ++l) {
uint32_t W = isl_minify(W0, l);
uint32_t H = isl_minify(H0, l);
uint32_t w = isl_align_npot(W, image_align_sa->w);
uint32_t h = isl_align_npot(H, image_align_sa->h);
if (l == 0) {
slice_top_w = w;
slice_left_h = h;
slice_right_h = h;
} else if (l == 1) {
slice_bottom_w = w;
slice_left_h += h;
} else if (l == 2) {
slice_bottom_w += w;
slice_right_h += h;
} else {
slice_right_h += h;
}
}
*phys_slice0_sa = (struct isl_extent2d) {
.w = MAX(slice_top_w, slice_bottom_w),
.h = MAX(slice_left_h, slice_right_h),
};
}
static void
isl_calc_phys_total_extent_el_gfx4_2d(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_tile_info *tile_info,
enum isl_msaa_layout msaa_layout,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
enum isl_array_pitch_span array_pitch_span,
uint32_t *array_pitch_el_rows,
struct isl_extent4d *phys_total_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
struct isl_extent2d phys_slice0_sa;
isl_calc_phys_slice0_extent_sa_gfx4_2d(dev, info, msaa_layout,
image_align_sa, phys_level0_sa,
&phys_slice0_sa);
*array_pitch_el_rows =
isl_calc_array_pitch_el_rows_gfx4_2d(dev, info, tile_info,
image_align_sa, phys_level0_sa,
array_pitch_span,
&phys_slice0_sa);
*phys_total_el = (struct isl_extent4d) {
.w = isl_align_div_npot(phys_slice0_sa.w, fmtl->bw),
.h = *array_pitch_el_rows * (phys_level0_sa->array_len - 1) +
isl_align_div_npot(phys_slice0_sa.h, fmtl->bh),
.d = 1,
.a = 1,
};
}
static void
isl_calc_phys_total_extent_el_gfx4_3d(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
uint32_t *array_pitch_el_rows,
struct isl_extent4d *phys_total_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
assert(info->samples == 1);
if (info->dim != ISL_SURF_DIM_3D) {
assert(ISL_GFX_VER(dev) == 4);
assert(info->usage & ISL_SURF_USAGE_CUBE_BIT);
assert(phys_level0_sa->array_len == 6);
} else {
assert(phys_level0_sa->array_len == 1);
}
uint32_t total_w = 0;
uint32_t total_h = 0;
uint32_t W0 = phys_level0_sa->w;
uint32_t H0 = phys_level0_sa->h;
uint32_t D0 = phys_level0_sa->d;
uint32_t A0 = phys_level0_sa->a;
for (uint32_t l = 0; l < info->levels; ++l) {
uint32_t level_w = isl_align_npot(isl_minify(W0, l), image_align_sa->w);
uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa->h);
uint32_t level_d = info->dim == ISL_SURF_DIM_3D ? isl_minify(D0, l) : A0;
uint32_t max_layers_horiz = MIN(level_d, 1u << l);
uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
total_w = MAX(total_w, level_w * max_layers_horiz);
total_h += level_h * max_layers_vert;
}
*array_pitch_el_rows =
isl_align_npot(phys_level0_sa->h, image_align_sa->h) / fmtl->bw;
*phys_total_el = (struct isl_extent4d) {
.w = isl_assert_div(total_w, fmtl->bw),
.h = isl_assert_div(total_h, fmtl->bh),
.d = 1,
.a = 1,
};
}
static void
isl_calc_phys_total_extent_el_gfx6_stencil_hiz(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_tile_info *tile_info,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
uint32_t *array_pitch_el_rows,
struct isl_extent4d *phys_total_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
const struct isl_extent2d tile_extent_sa = {
.w = tile_info->logical_extent_el.w * fmtl->bw,
.h = tile_info->logical_extent_el.h * fmtl->bh,
};
assert(tile_extent_sa.w % image_align_sa->w == 0);
assert(tile_extent_sa.h % image_align_sa->h == 0);
const uint32_t W0 = phys_level0_sa->w;
const uint32_t H0 = phys_level0_sa->h;
const uint32_t H = isl_align(H0, image_align_sa->h) * phys_level0_sa->a;
uint32_t total_top_w = 0;
uint32_t total_bottom_w = 0;
uint32_t total_h = 0;
for (uint32_t l = 0; l < info->levels; ++l) {
const uint32_t W = isl_minify(W0, l);
const uint32_t w = isl_align(W, tile_extent_sa.w);
const uint32_t h = isl_align(H, tile_extent_sa.h);
if (l == 0) {
total_top_w = w;
total_h = h;
} else if (l == 1) {
total_bottom_w = w;
total_h += h;
} else {
total_bottom_w += w;
}
}
*array_pitch_el_rows =
isl_assert_div(isl_align(H0, image_align_sa->h), fmtl->bh);
*phys_total_el = (struct isl_extent4d) {
.w = isl_assert_div(MAX(total_top_w, total_bottom_w), fmtl->bw),
.h = isl_assert_div(total_h, fmtl->bh),
.d = 1,
.a = 1,
};
}
static void
isl_calc_phys_total_extent_el_gfx9_1d(
const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
uint32_t *array_pitch_el_rows,
struct isl_extent4d *phys_total_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
assert(phys_level0_sa->height == 1);
assert(phys_level0_sa->depth == 1);
assert(info->samples == 1);
assert(image_align_sa->w >= fmtl->bw);
uint32_t slice_w = 0;
const uint32_t W0 = phys_level0_sa->w;
for (uint32_t l = 0; l < info->levels; ++l) {
uint32_t W = isl_minify(W0, l);
uint32_t w = isl_align_npot(W, image_align_sa->w);
slice_w += w;
}
*array_pitch_el_rows = 1;
*phys_total_el = (struct isl_extent4d) {
.w = isl_assert_div(slice_w, fmtl->bw),
.h = phys_level0_sa->array_len,
.d = 1,
.a = 1,
};
}
static void
isl_calc_phys_total_extent_el(const struct isl_device *dev,
const struct isl_surf_init_info *restrict info,
const struct isl_tile_info *tile_info,
enum isl_dim_layout dim_layout,
enum isl_msaa_layout msaa_layout,
const struct isl_extent3d *image_align_sa,
const struct isl_extent4d *phys_level0_sa,
enum isl_array_pitch_span array_pitch_span,
uint32_t *array_pitch_el_rows,
struct isl_extent4d *phys_total_el)
{
switch (dim_layout) {
case ISL_DIM_LAYOUT_GFX9_1D:
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
isl_calc_phys_total_extent_el_gfx9_1d(dev, info,
image_align_sa, phys_level0_sa,
array_pitch_el_rows,
phys_total_el);
return;
case ISL_DIM_LAYOUT_GFX4_2D:
isl_calc_phys_total_extent_el_gfx4_2d(dev, info, tile_info, msaa_layout,
image_align_sa, phys_level0_sa,
array_pitch_span,
array_pitch_el_rows,
phys_total_el);
return;
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
isl_calc_phys_total_extent_el_gfx6_stencil_hiz(dev, info, tile_info,
image_align_sa,
phys_level0_sa,
array_pitch_el_rows,
phys_total_el);
return;
case ISL_DIM_LAYOUT_GFX4_3D:
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
isl_calc_phys_total_extent_el_gfx4_3d(dev, info,
image_align_sa, phys_level0_sa,
array_pitch_el_rows,
phys_total_el);
return;
}
unreachable("invalid value for dim_layout");
}
static uint32_t
isl_calc_row_pitch_alignment(const struct isl_device *dev,
const struct isl_surf_init_info *surf_info,
const struct isl_tile_info *tile_info)
{
if (tile_info->tiling != ISL_TILING_LINEAR) {
if (ISL_GFX_VER(dev) >= 12 &&
isl_format_supports_ccs_e(dev->info, surf_info->format) &&
tile_info->tiling != ISL_TILING_X &&
!(surf_info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT) &&
surf_info->row_pitch_B == 0) {
return isl_align(tile_info->phys_extent_B.width, 512);
}
return tile_info->phys_extent_B.width;
}
const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
const uint32_t bs = fmtl->bpb / 8;
uint32_t alignment;
if (surf_info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
if (isl_format_is_yuv(surf_info->format)) {
alignment = 2 * bs;
} else {
alignment = bs;
}
} else {
alignment = 1;
}
if (surf_info->usage & ISL_SURF_USAGE_DISPLAY_BIT)
alignment = isl_align(alignment, 256);
return alignment;
}
static uint32_t
isl_calc_linear_min_row_pitch(const struct isl_device *dev,
const struct isl_surf_init_info *info,
const struct isl_extent4d *phys_total_el,
uint32_t alignment_B)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
const uint32_t bs = fmtl->bpb / 8;
return isl_align_npot(bs * phys_total_el->w, alignment_B);
}
static uint32_t
isl_calc_tiled_min_row_pitch(const struct isl_device *dev,
const struct isl_surf_init_info *surf_info,
const struct isl_tile_info *tile_info,
const struct isl_extent4d *phys_total_el,
uint32_t alignment_B)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
assert(fmtl->bpb % tile_info->format_bpb == 0);
const uint32_t tile_el_scale = fmtl->bpb / tile_info->format_bpb;
const uint32_t total_w_tl =
isl_align_div(phys_total_el->w * tile_el_scale,
tile_info->logical_extent_el.width);
assert(alignment_B >= tile_info->phys_extent_B.width);
return isl_align(total_w_tl * tile_info->phys_extent_B.width, alignment_B);
}
static uint32_t
isl_calc_min_row_pitch(const struct isl_device *dev,
const struct isl_surf_init_info *surf_info,
const struct isl_tile_info *tile_info,
const struct isl_extent4d *phys_total_el,
uint32_t alignment_B)
{
if (tile_info->tiling == ISL_TILING_LINEAR) {
return isl_calc_linear_min_row_pitch(dev, surf_info, phys_total_el,
alignment_B);
} else {
return isl_calc_tiled_min_row_pitch(dev, surf_info, tile_info,
phys_total_el, alignment_B);
}
}
static bool
pitch_in_range(uint32_t n, uint32_t bits)
{
assert(n != 0);
return likely(bits != 0 && 1 <= n && n <= (1 << bits));
}
static bool
isl_calc_row_pitch(const struct isl_device *dev,
const struct isl_surf_init_info *surf_info,
const struct isl_tile_info *tile_info,
enum isl_dim_layout dim_layout,
const struct isl_extent4d *phys_total_el,
uint32_t *out_row_pitch_B)
{
uint32_t alignment_B =
isl_calc_row_pitch_alignment(dev, surf_info, tile_info);
const uint32_t min_row_pitch_B =
isl_calc_min_row_pitch(dev, surf_info, tile_info, phys_total_el,
alignment_B);
if (surf_info->row_pitch_B != 0) {
if (surf_info->row_pitch_B < min_row_pitch_B)
return false;
if (surf_info->row_pitch_B % alignment_B != 0)
return false;
}
const uint32_t row_pitch_B =
surf_info->row_pitch_B != 0 ? surf_info->row_pitch_B : min_row_pitch_B;
const uint32_t row_pitch_tl = row_pitch_B / tile_info->phys_extent_B.width;
if (row_pitch_B == 0)
return false;
if (dim_layout == ISL_DIM_LAYOUT_GFX9_1D) {
goto done;
}
if ((surf_info->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
ISL_SURF_USAGE_TEXTURE_BIT |
ISL_SURF_USAGE_STORAGE_BIT)) &&
!pitch_in_range(row_pitch_B, RENDER_SURFACE_STATE_SurfacePitch_bits(dev->info)))
return false;
if ((surf_info->usage & (ISL_SURF_USAGE_CCS_BIT |
ISL_SURF_USAGE_MCS_BIT)) &&
!pitch_in_range(row_pitch_tl, RENDER_SURFACE_STATE_AuxiliarySurfacePitch_bits(dev->info)))
return false;
if ((surf_info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
!pitch_in_range(row_pitch_B, _3DSTATE_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
return false;
if ((surf_info->usage & ISL_SURF_USAGE_HIZ_BIT) &&
!pitch_in_range(row_pitch_B, _3DSTATE_HIER_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
return false;
const uint32_t stencil_pitch_bits = dev->use_separate_stencil ?
_3DSTATE_STENCIL_BUFFER_SurfacePitch_bits(dev->info) :
_3DSTATE_DEPTH_BUFFER_SurfacePitch_bits(dev->info);
if ((surf_info->usage & ISL_SURF_USAGE_STENCIL_BIT) &&
!pitch_in_range(row_pitch_B, stencil_pitch_bits))
return false;
done:
*out_row_pitch_B = row_pitch_B;
return true;
}
bool
isl_surf_init_s(const struct isl_device *dev,
struct isl_surf *surf,
const struct isl_surf_init_info *restrict info)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
const struct isl_extent4d logical_level0_px = {
.w = info->width,
.h = info->height,
.d = info->depth,
.a = info->array_len,
};
enum isl_tiling tiling;
if (!isl_surf_choose_tiling(dev, info, &tiling))
return false;
struct isl_tile_info tile_info;
isl_tiling_get_info(tiling, fmtl->bpb, &tile_info);
const enum isl_dim_layout dim_layout =
isl_surf_choose_dim_layout(dev, info->dim, tiling, info->usage);
enum isl_msaa_layout msaa_layout;
if (!isl_choose_msaa_layout(dev, info, tiling, &msaa_layout))
return false;
struct isl_extent3d image_align_el;
isl_choose_image_alignment_el(dev, info, tiling, dim_layout, msaa_layout,
&image_align_el);
struct isl_extent3d image_align_sa =
isl_extent3d_el_to_sa(info->format, image_align_el);
struct isl_extent4d phys_level0_sa;
isl_calc_phys_level0_extent_sa(dev, info, dim_layout, tiling, msaa_layout,
&phys_level0_sa);
enum isl_array_pitch_span array_pitch_span =
isl_choose_array_pitch_span(dev, info, dim_layout, &phys_level0_sa);
uint32_t array_pitch_el_rows;
struct isl_extent4d phys_total_el;
isl_calc_phys_total_extent_el(dev, info, &tile_info,
dim_layout, msaa_layout,
&image_align_sa, &phys_level0_sa,
array_pitch_span, &array_pitch_el_rows,
&phys_total_el);
uint32_t row_pitch_B;
if (!isl_calc_row_pitch(dev, info, &tile_info, dim_layout,
&phys_total_el, &row_pitch_B))
return false;
uint32_t base_alignment_B;
uint64_t size_B;
if (tiling == ISL_TILING_LINEAR) {
assert(phys_total_el.d == 1 && phys_total_el.a == 1);
size_B = (uint64_t) row_pitch_B * phys_total_el.h;
base_alignment_B = MAX(1, info->min_alignment_B);
if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
if (isl_format_is_yuv(info->format)) {
base_alignment_B = MAX(base_alignment_B, fmtl->bpb / 4);
} else {
base_alignment_B = MAX(base_alignment_B, fmtl->bpb / 8);
}
}
base_alignment_B = isl_round_up_to_power_of_two(base_alignment_B);
if (isl_surf_usage_is_display(info->usage))
base_alignment_B = MAX(base_alignment_B, 64);
} else {
assert(row_pitch_B % tile_info.phys_extent_B.width == 0);
uint32_t array_slices, array_pitch_tl_rows;
if (phys_total_el.d > 1) {
assert(phys_total_el.a == 1);
array_pitch_tl_rows = isl_assert_div(array_pitch_el_rows,
tile_info.logical_extent_el.h);
array_slices = isl_align_div(phys_total_el.d,
tile_info.logical_extent_el.d);
} else if (phys_total_el.a > 1) {
assert(phys_total_el.d == 1);
array_pitch_tl_rows = isl_assert_div(array_pitch_el_rows,
tile_info.logical_extent_el.h);
array_slices = isl_align_div(phys_total_el.a,
tile_info.logical_extent_el.a);
assert(array_pitch_el_rows % tile_info.logical_extent_el.h == 0);
} else {
assert(phys_total_el.d == 1 && phys_total_el.a == 1);
array_pitch_tl_rows = 0;
array_slices = 1;
}
const uint32_t total_h_tl =
(array_slices - 1) * array_pitch_tl_rows +
isl_align_div(phys_total_el.h, tile_info.logical_extent_el.height);
size_B = (uint64_t) total_h_tl * tile_info.phys_extent_B.height * row_pitch_B;
const uint32_t tile_size_B = tile_info.phys_extent_B.width *
tile_info.phys_extent_B.height;
assert(isl_is_pow2(info->min_alignment_B) && isl_is_pow2(tile_size_B));
base_alignment_B = MAX(info->min_alignment_B, tile_size_B);
if (tiling == ISL_TILING_GFX12_CCS)
base_alignment_B = MAX(base_alignment_B, 4096);
if (ISL_GFX_VER(dev) >= 12 &&
!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) {
base_alignment_B = MAX(base_alignment_B, 64 * 1024);
}
}
if (ISL_GFX_VER(dev) < 9) {
if (size_B > (uint64_t) 1 << 31)
return false;
} else if (ISL_GFX_VER(dev) < 11) {
if (size_B > (uint64_t) 1 << 38)
return false;
} else {
if (size_B > (uint64_t) 1 << 44)
return false;
}
*surf = (struct isl_surf) {
.dim = info->dim,
.dim_layout = dim_layout,
.msaa_layout = msaa_layout,
.tiling = tiling,
.format = info->format,
.levels = info->levels,
.samples = info->samples,
.image_alignment_el = image_align_el,
.logical_level0_px = logical_level0_px,
.phys_level0_sa = phys_level0_sa,
.size_B = size_B,
.alignment_B = base_alignment_B,
.row_pitch_B = row_pitch_B,
.array_pitch_el_rows = array_pitch_el_rows,
.array_pitch_span = array_pitch_span,
.usage = info->usage,
};
return true;
}
void
isl_surf_get_tile_info(const struct isl_surf *surf,
struct isl_tile_info *tile_info)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
isl_tiling_get_info(surf->tiling, fmtl->bpb, tile_info);
}
bool
isl_surf_get_hiz_surf(const struct isl_device *dev,
const struct isl_surf *surf,
struct isl_surf *hiz_surf)
{
assert(ISL_GFX_VER(dev) >= 5 && ISL_DEV_USE_SEPARATE_STENCIL(dev));
if (!isl_surf_usage_is_depth(surf->usage))
return false;
if (!isl_tiling_is_any_y(surf->tiling))
return false;
switch (surf->format) {
case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
if (isl_surf_usage_is_depth_and_stencil(surf->usage)) {
assert(ISL_GFX_VER(dev) == 5);
unreachable("This should work, but is untested");
}
FALLTHROUGH;
case ISL_FORMAT_R16_UNORM:
case ISL_FORMAT_R32_FLOAT:
break;
case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
if (ISL_GFX_VER(dev) == 5) {
assert(isl_surf_usage_is_depth_and_stencil(surf->usage));
unreachable("This should work, but is untested");
}
FALLTHROUGH;
default:
return false;
}
assert(surf->msaa_layout == ISL_MSAA_LAYOUT_NONE ||
surf->msaa_layout == ISL_MSAA_LAYOUT_INTERLEAVED);
const unsigned samples = ISL_GFX_VER(dev) >= 9 ? 1 : surf->samples;
return isl_surf_init(dev, hiz_surf,
.dim = surf->dim,
.format = ISL_FORMAT_HIZ,
.width = surf->logical_level0_px.width,
.height = surf->logical_level0_px.height,
.depth = surf->logical_level0_px.depth,
.levels = surf->levels,
.array_len = surf->logical_level0_px.array_len,
.samples = samples,
.usage = ISL_SURF_USAGE_HIZ_BIT,
.tiling_flags = ISL_TILING_HIZ_BIT);
}
bool
isl_surf_get_mcs_surf(const struct isl_device *dev,
const struct isl_surf *surf,
struct isl_surf *mcs_surf)
{
if (surf->msaa_layout != ISL_MSAA_LAYOUT_ARRAY)
return false;
if (mcs_surf->size_B > 0)
return false;
assert(surf->samples > 1);
assert(surf->dim == ISL_SURF_DIM_2D);
assert(surf->levels == 1);
assert(surf->logical_level0_px.depth == 1);
if (ISL_GFX_VER(dev) == 7 && isl_format_has_sint_channel(surf->format))
return false;
if (surf->samples == 16 && surf->logical_level0_px.width > 8192)
return false;
enum isl_format mcs_format;
switch (surf->samples) {
case 2: mcs_format = ISL_FORMAT_MCS_2X; break;
case 4: mcs_format = ISL_FORMAT_MCS_4X; break;
case 8: mcs_format = ISL_FORMAT_MCS_8X; break;
case 16: mcs_format = ISL_FORMAT_MCS_16X; break;
default:
unreachable("Invalid sample count");
}
return isl_surf_init(dev, mcs_surf,
.dim = ISL_SURF_DIM_2D,
.format = mcs_format,
.width = surf->logical_level0_px.width,
.height = surf->logical_level0_px.height,
.depth = 1,
.levels = 1,
.array_len = surf->logical_level0_px.array_len,
.samples = 1,
.usage = ISL_SURF_USAGE_MCS_BIT,
.tiling_flags = ISL_TILING_Y0_BIT);
}
bool
isl_surf_supports_ccs(const struct isl_device *dev,
const struct isl_surf *surf,
const struct isl_surf *hiz_or_mcs_surf)
{
if (ISL_GFX_VER(dev) <= 6)
return false;
if (dev->info->is_alderlake && dev->info->gt == 2 &&
dev->info->revision == 0)
return false;
if (surf->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)
return false;
if (isl_format_is_compressed(surf->format))
return false;
if (!isl_is_pow2(isl_format_get_layout(surf->format)->bpb))
return false;
if (surf->tiling == ISL_TILING_LINEAR)
return false;
if (ISL_GFX_VER(dev) >= 12) {
if (isl_surf_usage_is_stencil(surf->usage)) {
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
if (surf->samples > 1)
return false;
} else if (isl_surf_usage_is_depth(surf->usage)) {
const struct isl_surf *hiz_surf = hiz_or_mcs_surf;
if (hiz_surf == NULL || hiz_surf->size_B == 0)
return false;
assert(hiz_surf->usage & ISL_SURF_USAGE_HIZ_BIT);
assert(hiz_surf->tiling == ISL_TILING_HIZ);
assert(hiz_surf->format == ISL_FORMAT_HIZ);
} else if (surf->samples > 1) {
const struct isl_surf *mcs_surf = hiz_or_mcs_surf;
if (mcs_surf == NULL || mcs_surf->size_B == 0)
return false;
assert(mcs_surf->usage & ISL_SURF_USAGE_MCS_BIT);
assert(isl_tiling_is_any_y(mcs_surf->tiling));
assert(isl_format_is_mcs(mcs_surf->format));
} else {
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
}
if (surf->row_pitch_B % 512 != 0)
return false;
if (surf->dim == ISL_SURF_DIM_3D) {
isl_finishme("%s:%s: CCS for 3D textures is disabled, but a workaround"
" is available.", __FILE__, __func__);
return false;
}
if (surf->tiling != ISL_TILING_Y0)
return false;
} else {
if (surf->samples > 1)
return false;
if (isl_surf_usage_is_depth_or_stencil(surf->usage))
return false;
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
if (ISL_GFX_VER(dev) <= 8 && surf->dim != ISL_SURF_DIM_2D)
return false;
if (ISL_GFX_VER(dev) <= 7 &&
(surf->levels > 1 || surf->logical_level0_px.array_len > 1))
return false;
if (isl_format_get_layout(surf->format)->bpb < 32)
return false;
if (ISL_GFX_VER(dev) >= 9 && !isl_tiling_is_any_y(surf->tiling))
return false;
}
return true;
}
bool
isl_surf_get_ccs_surf(const struct isl_device *dev,
const struct isl_surf *surf,
const struct isl_surf *hiz_or_mcs_surf,
struct isl_surf *ccs_surf,
uint32_t row_pitch_B)
{
if (!isl_surf_supports_ccs(dev, surf, hiz_or_mcs_surf))
return false;
if (ISL_GFX_VER(dev) >= 12) {
enum isl_format ccs_format;
switch (isl_format_get_layout(surf->format)->bpb) {
case 8: ccs_format = ISL_FORMAT_GFX12_CCS_8BPP_Y0; break;
case 16: ccs_format = ISL_FORMAT_GFX12_CCS_16BPP_Y0; break;
case 32: ccs_format = ISL_FORMAT_GFX12_CCS_32BPP_Y0; break;
case 64: ccs_format = ISL_FORMAT_GFX12_CCS_64BPP_Y0; break;
case 128: ccs_format = ISL_FORMAT_GFX12_CCS_128BPP_Y0; break;
default:
return false;
}
const bool ok =
isl_surf_init(dev, ccs_surf,
.dim = ISL_SURF_DIM_2D,
.format = ccs_format,
.width = isl_surf_get_row_pitch_el(surf),
.height = surf->size_B / surf->row_pitch_B,
.depth = 1,
.levels = 1,
.array_len = 1,
.samples = 1,
.row_pitch_B = row_pitch_B,
.usage = ISL_SURF_USAGE_CCS_BIT,
.tiling_flags = ISL_TILING_GFX12_CCS_BIT);
assert(!ok || ccs_surf->size_B == surf->size_B / 256);
return ok;
} else {
enum isl_format ccs_format;
if (ISL_GFX_VER(dev) >= 9) {
switch (isl_format_get_layout(surf->format)->bpb) {
case 32: ccs_format = ISL_FORMAT_GFX9_CCS_32BPP; break;
case 64: ccs_format = ISL_FORMAT_GFX9_CCS_64BPP; break;
case 128: ccs_format = ISL_FORMAT_GFX9_CCS_128BPP; break;
default: unreachable("Unsupported CCS format");
return false;
}
} else if (surf->tiling == ISL_TILING_Y0) {
switch (isl_format_get_layout(surf->format)->bpb) {
case 32: ccs_format = ISL_FORMAT_GFX7_CCS_32BPP_Y; break;
case 64: ccs_format = ISL_FORMAT_GFX7_CCS_64BPP_Y; break;
case 128: ccs_format = ISL_FORMAT_GFX7_CCS_128BPP_Y; break;
default: unreachable("Unsupported CCS format");
}
} else if (surf->tiling == ISL_TILING_X) {
switch (isl_format_get_layout(surf->format)->bpb) {
case 32: ccs_format = ISL_FORMAT_GFX7_CCS_32BPP_X; break;
case 64: ccs_format = ISL_FORMAT_GFX7_CCS_64BPP_X; break;
case 128: ccs_format = ISL_FORMAT_GFX7_CCS_128BPP_X; break;
default: unreachable("Unsupported CCS format");
}
} else {
unreachable("Invalid tiling format");
}
return isl_surf_init(dev, ccs_surf,
.dim = surf->dim,
.format = ccs_format,
.width = surf->logical_level0_px.width,
.height = surf->logical_level0_px.height,
.depth = surf->logical_level0_px.depth,
.levels = surf->levels,
.array_len = surf->logical_level0_px.array_len,
.samples = 1,
.row_pitch_B = row_pitch_B,
.usage = ISL_SURF_USAGE_CCS_BIT,
.tiling_flags = ISL_TILING_CCS_BIT);
}
}
#define isl_genX_call(dev, func, ...) \
switch (ISL_GFX_VERX10(dev)) { \
case 40: \
isl_gfx4_##func(__VA_ARGS__); \
break; \
case 45: \
\
case 50: \
isl_gfx5_##func(__VA_ARGS__); \
break; \
case 60: \
isl_gfx6_##func(__VA_ARGS__); \
break; \
case 70: \
isl_gfx7_##func(__VA_ARGS__); \
break; \
case 75: \
isl_gfx75_##func(__VA_ARGS__); \
break; \
case 80: \
isl_gfx8_##func(__VA_ARGS__); \
break; \
case 90: \
isl_gfx9_##func(__VA_ARGS__); \
break; \
case 110: \
isl_gfx11_##func(__VA_ARGS__); \
break; \
case 120: \
isl_gfx12_##func(__VA_ARGS__); \
break; \
case 125: \
isl_gfx125_##func(__VA_ARGS__); \
break; \
default: \
assert(!"Unknown hardware generation"); \
}
void
isl_surf_fill_state_s(const struct isl_device *dev, void *state,
const struct isl_surf_fill_state_info *restrict info)
{
#ifndef NDEBUG
isl_surf_usage_flags_t _base_usage =
info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
ISL_SURF_USAGE_TEXTURE_BIT |
ISL_SURF_USAGE_STORAGE_BIT);
assert(__builtin_popcount(_base_usage) == 1);
assert((info->view->usage & ~ISL_SURF_USAGE_CUBE_BIT) == _base_usage);
#endif
if (info->surf->dim == ISL_SURF_DIM_3D) {
assert(info->view->base_array_layer + info->view->array_len <=
info->surf->logical_level0_px.depth);
} else {
assert(info->view->base_array_layer + info->view->array_len <=
info->surf->logical_level0_px.array_len);
}
isl_genX_call(dev, surf_fill_state_s, dev, state, info);
}
void
isl_buffer_fill_state_s(const struct isl_device *dev, void *state,
const struct isl_buffer_fill_state_info *restrict info)
{
isl_genX_call(dev, buffer_fill_state_s, dev, state, info);
}
void
isl_null_fill_state_s(const struct isl_device *dev, void *state,
const struct isl_null_fill_state_info *restrict info)
{
isl_genX_call(dev, null_fill_state, state, info);
}
void
isl_emit_depth_stencil_hiz_s(const struct isl_device *dev, void *batch,
const struct isl_depth_stencil_hiz_emit_info *restrict info)
{
if (info->depth_surf && info->stencil_surf) {
if (!dev->info->has_hiz_and_separate_stencil) {
assert(info->depth_surf == info->stencil_surf);
assert(info->depth_address == info->stencil_address);
}
assert(info->depth_surf->dim == info->stencil_surf->dim);
}
if (info->depth_surf) {
assert((info->depth_surf->usage & ISL_SURF_USAGE_DEPTH_BIT));
if (info->depth_surf->dim == ISL_SURF_DIM_3D) {
assert(info->view->base_array_layer + info->view->array_len <=
info->depth_surf->logical_level0_px.depth);
} else {
assert(info->view->base_array_layer + info->view->array_len <=
info->depth_surf->logical_level0_px.array_len);
}
}
if (info->stencil_surf) {
assert((info->stencil_surf->usage & ISL_SURF_USAGE_STENCIL_BIT));
if (info->stencil_surf->dim == ISL_SURF_DIM_3D) {
assert(info->view->base_array_layer + info->view->array_len <=
info->stencil_surf->logical_level0_px.depth);
} else {
assert(info->view->base_array_layer + info->view->array_len <=
info->stencil_surf->logical_level0_px.array_len);
}
}
isl_genX_call(dev, emit_depth_stencil_hiz_s, dev, batch, info);
}
static void
get_image_offset_sa_gfx4_2d(const struct isl_surf *surf,
uint32_t level, uint32_t logical_array_layer,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
assert(level < surf->levels);
if (surf->dim == ISL_SURF_DIM_3D)
assert(logical_array_layer < surf->logical_level0_px.depth);
else
assert(logical_array_layer < surf->logical_level0_px.array_len);
const struct isl_extent3d image_align_sa =
isl_surf_get_image_alignment_sa(surf);
const uint32_t W0 = surf->phys_level0_sa.width;
const uint32_t H0 = surf->phys_level0_sa.height;
const uint32_t phys_layer = logical_array_layer *
(surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY ? surf->samples : 1);
uint32_t x = 0;
uint32_t y = phys_layer * isl_surf_get_array_pitch_sa_rows(surf);
for (uint32_t l = 0; l < level; ++l) {
if (l == 1) {
uint32_t W = isl_minify(W0, l);
x += isl_align_npot(W, image_align_sa.w);
} else {
uint32_t H = isl_minify(H0, l);
y += isl_align_npot(H, image_align_sa.h);
}
}
*x_offset_sa = x;
*y_offset_sa = y;
}
static void
get_image_offset_sa_gfx4_3d(const struct isl_surf *surf,
uint32_t level, uint32_t logical_z_offset_px,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
assert(level < surf->levels);
if (surf->dim == ISL_SURF_DIM_3D) {
assert(surf->phys_level0_sa.array_len == 1);
assert(logical_z_offset_px < isl_minify(surf->phys_level0_sa.depth, level));
} else {
assert(surf->dim == ISL_SURF_DIM_2D);
assert(surf->usage & ISL_SURF_USAGE_CUBE_BIT);
assert(surf->phys_level0_sa.array_len == 6);
assert(logical_z_offset_px < surf->phys_level0_sa.array_len);
}
const struct isl_extent3d image_align_sa =
isl_surf_get_image_alignment_sa(surf);
const uint32_t W0 = surf->phys_level0_sa.width;
const uint32_t H0 = surf->phys_level0_sa.height;
const uint32_t D0 = surf->phys_level0_sa.depth;
const uint32_t AL = surf->phys_level0_sa.array_len;
uint32_t x = 0;
uint32_t y = 0;
for (uint32_t l = 0; l < level; ++l) {
const uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa.h);
const uint32_t level_d =
isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, l) : AL,
image_align_sa.d);
const uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
y += level_h * max_layers_vert;
}
const uint32_t level_w = isl_align_npot(isl_minify(W0, level), image_align_sa.w);
const uint32_t level_h = isl_align_npot(isl_minify(H0, level), image_align_sa.h);
const uint32_t level_d =
isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, level) : AL,
image_align_sa.d);
const uint32_t max_layers_horiz = MIN(level_d, 1u << level);
x += level_w * (logical_z_offset_px % max_layers_horiz);
y += level_h * (logical_z_offset_px / max_layers_horiz);
*x_offset_sa = x;
*y_offset_sa = y;
}
static void
get_image_offset_sa_gfx6_stencil_hiz(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
assert(level < surf->levels);
assert(surf->logical_level0_px.depth == 1);
assert(logical_array_layer < surf->logical_level0_px.array_len);
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
const struct isl_extent3d image_align_sa =
isl_surf_get_image_alignment_sa(surf);
struct isl_tile_info tile_info;
isl_tiling_get_info(surf->tiling, fmtl->bpb, &tile_info);
const struct isl_extent2d tile_extent_sa = {
.w = tile_info.logical_extent_el.w * fmtl->bw,
.h = tile_info.logical_extent_el.h * fmtl->bh,
};
assert(tile_extent_sa.w % image_align_sa.w == 0);
assert(tile_extent_sa.h % image_align_sa.h == 0);
const uint32_t W0 = surf->phys_level0_sa.w;
const uint32_t H0 = surf->phys_level0_sa.h;
const uint32_t H = isl_align(H0, image_align_sa.h);
if (surf->phys_level0_sa.array_len > 1)
assert(surf->array_pitch_el_rows == isl_assert_div(H, fmtl->bh));
uint32_t x = 0, y = 0;
for (uint32_t l = 0; l < level; ++l) {
const uint32_t W = isl_minify(W0, l);
const uint32_t w = isl_align(W, tile_extent_sa.w);
const uint32_t h = isl_align(H * surf->phys_level0_sa.a,
tile_extent_sa.h);
if (l == 0) {
y += h;
} else {
x += w;
}
}
y += H * logical_array_layer;
*x_offset_sa = x;
*y_offset_sa = y;
}
static void
get_image_offset_sa_gfx9_1d(const struct isl_surf *surf,
uint32_t level, uint32_t layer,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
assert(level < surf->levels);
assert(layer < surf->phys_level0_sa.array_len);
assert(surf->phys_level0_sa.height == 1);
assert(surf->phys_level0_sa.depth == 1);
assert(surf->samples == 1);
const uint32_t W0 = surf->phys_level0_sa.width;
const struct isl_extent3d image_align_sa =
isl_surf_get_image_alignment_sa(surf);
uint32_t x = 0;
for (uint32_t l = 0; l < level; ++l) {
uint32_t W = isl_minify(W0, l);
uint32_t w = isl_align_npot(W, image_align_sa.w);
x += w;
}
*x_offset_sa = x;
*y_offset_sa = layer * isl_surf_get_array_pitch_sa_rows(surf);
}
void
isl_surf_get_image_offset_sa(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa,
uint32_t *z_offset_sa,
uint32_t *array_offset)
{
assert(level < surf->levels);
assert(logical_array_layer < surf->logical_level0_px.array_len);
assert(logical_z_offset_px
< isl_minify(surf->logical_level0_px.depth, level));
switch (surf->dim_layout) {
case ISL_DIM_LAYOUT_GFX9_1D:
get_image_offset_sa_gfx9_1d(surf, level, logical_array_layer,
x_offset_sa, y_offset_sa);
*z_offset_sa = 0;
*array_offset = 0;
break;
case ISL_DIM_LAYOUT_GFX4_2D:
get_image_offset_sa_gfx4_2d(surf, level, logical_array_layer
+ logical_z_offset_px,
x_offset_sa, y_offset_sa);
*z_offset_sa = 0;
*array_offset = 0;
break;
case ISL_DIM_LAYOUT_GFX4_3D:
get_image_offset_sa_gfx4_3d(surf, level, logical_array_layer +
logical_z_offset_px,
x_offset_sa, y_offset_sa);
*z_offset_sa = 0;
*array_offset = 0;
break;
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
get_image_offset_sa_gfx6_stencil_hiz(surf, level, logical_array_layer +
logical_z_offset_px,
x_offset_sa, y_offset_sa);
*z_offset_sa = 0;
*array_offset = 0;
break;
default:
unreachable("not reached");
}
}
void
isl_surf_get_image_offset_el(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
uint32_t *x_offset_el,
uint32_t *y_offset_el,
uint32_t *z_offset_el,
uint32_t *array_offset)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
assert(level < surf->levels);
assert(logical_array_layer < surf->logical_level0_px.array_len);
assert(logical_z_offset_px
< isl_minify(surf->logical_level0_px.depth, level));
uint32_t x_offset_sa, y_offset_sa, z_offset_sa;
isl_surf_get_image_offset_sa(surf, level,
logical_array_layer,
logical_z_offset_px,
&x_offset_sa,
&y_offset_sa,
&z_offset_sa,
array_offset);
*x_offset_el = x_offset_sa / fmtl->bw;
*y_offset_el = y_offset_sa / fmtl->bh;
*z_offset_el = z_offset_sa / fmtl->bd;
}
void
isl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
uint32_t *offset_B,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
uint32_t x_offset_el, y_offset_el;
isl_surf_get_image_offset_B_tile_el(surf, level,
logical_array_layer,
logical_z_offset_px,
offset_B,
&x_offset_el,
&y_offset_el);
if (x_offset_sa) {
*x_offset_sa = x_offset_el * fmtl->bw;
} else {
assert(x_offset_el == 0);
}
if (y_offset_sa) {
*y_offset_sa = y_offset_el * fmtl->bh;
} else {
assert(y_offset_el == 0);
}
}
void
isl_surf_get_image_offset_B_tile_el(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
uint32_t *offset_B,
uint32_t *x_offset_el,
uint32_t *y_offset_el)
{
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
uint32_t total_x_offset_el, total_y_offset_el;
uint32_t total_z_offset_el, total_array_offset;
isl_surf_get_image_offset_el(surf, level, logical_array_layer,
logical_z_offset_px,
&total_x_offset_el,
&total_y_offset_el,
&total_z_offset_el,
&total_array_offset);
uint32_t z_offset_el, array_offset;
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
surf->row_pitch_B,
surf->array_pitch_el_rows,
total_x_offset_el,
total_y_offset_el,
total_z_offset_el,
total_array_offset,
offset_B,
x_offset_el,
y_offset_el,
&z_offset_el,
&array_offset);
assert(z_offset_el == 0);
assert(array_offset == 0);
}
void
isl_surf_get_image_range_B_tile(const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
uint32_t *start_tile_B,
uint32_t *end_tile_B)
{
uint32_t start_x_offset_el, start_y_offset_el;
uint32_t start_z_offset_el, start_array_slice;
isl_surf_get_image_offset_el(surf, level, logical_array_layer,
logical_z_offset_px,
&start_x_offset_el,
&start_y_offset_el,
&start_z_offset_el,
&start_array_slice);
const uint32_t subimage_w_sa = isl_minify(surf->phys_level0_sa.w, level);
const uint32_t subimage_h_sa = isl_minify(surf->phys_level0_sa.h, level);
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
const uint32_t subimage_w_el = isl_align_div_npot(subimage_w_sa, fmtl->bw);
const uint32_t subimage_h_el = isl_align_div_npot(subimage_h_sa, fmtl->bh);
uint32_t end_x_offset_el = start_x_offset_el + subimage_w_el - 1;
uint32_t end_y_offset_el = start_y_offset_el + subimage_h_el - 1;
const uint32_t end_z_offset_el = start_z_offset_el;
const uint32_t end_array_slice = start_array_slice;
UNUSED uint32_t x_offset_el, y_offset_el, z_offset_el, array_slice;
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
surf->row_pitch_B,
surf->array_pitch_el_rows,
start_x_offset_el,
start_y_offset_el,
start_z_offset_el,
start_array_slice,
start_tile_B,
&x_offset_el,
&y_offset_el,
&z_offset_el,
&array_slice);
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
surf->row_pitch_B,
surf->array_pitch_el_rows,
end_x_offset_el,
end_y_offset_el,
end_z_offset_el,
end_array_slice,
end_tile_B,
&x_offset_el,
&y_offset_el,
&z_offset_el,
&array_slice);
(*end_tile_B)++;
assert(*end_tile_B <= surf->size_B);
}
void
isl_surf_get_image_surf(const struct isl_device *dev,
const struct isl_surf *surf,
uint32_t level,
uint32_t logical_array_layer,
uint32_t logical_z_offset_px,
struct isl_surf *image_surf,
uint32_t *offset_B,
uint32_t *x_offset_sa,
uint32_t *y_offset_sa)
{
isl_surf_get_image_offset_B_tile_sa(surf,
level,
logical_array_layer,
logical_z_offset_px,
offset_B,
x_offset_sa,
y_offset_sa);
const isl_surf_usage_flags_t usage =
surf->usage & (~ISL_SURF_USAGE_CUBE_BIT);
bool ok UNUSED;
ok = isl_surf_init(dev, image_surf,
.dim = ISL_SURF_DIM_2D,
.format = surf->format,
.width = isl_minify(surf->logical_level0_px.w, level),
.height = isl_minify(surf->logical_level0_px.h, level),
.depth = 1,
.levels = 1,
.array_len = 1,
.samples = surf->samples,
.row_pitch_B = surf->row_pitch_B,
.usage = usage,
.tiling_flags = (1 << surf->tiling));
assert(ok);
}
bool
isl_surf_get_uncompressed_surf(const struct isl_device *dev,
const struct isl_surf *surf,
const struct isl_view *view,
struct isl_surf *ucompr_surf,
struct isl_view *ucompr_view,
uint32_t *offset_B,
uint32_t *x_offset_el,
uint32_t *y_offset_el)
{
const struct isl_format_layout *fmtl =
isl_format_get_layout(surf->format);
const enum isl_format view_format = view->format;
assert(fmtl->bw > 1 || fmtl->bh > 1 || fmtl->bd > 1);
assert(isl_format_is_compressed(surf->format));
assert(!isl_format_is_compressed(view->format));
assert(isl_format_get_layout(view->format)->bpb == fmtl->bpb);
assert(view->levels == 1);
const uint32_t view_width =
isl_minify(surf->logical_level0_px.width, view->base_level);
const uint32_t view_height =
isl_minify(surf->logical_level0_px.height, view->base_level);
const uint32_t ucompr_width = isl_align_div_npot(view_width, fmtl->bw);
const uint32_t ucompr_height = isl_align_div_npot(view_height, fmtl->bh);
assert(fmtl->bd == 1);
uint32_t x_offset_sa = 0, y_offset_sa = 0;
if (view->array_len > 1) {
if (view->base_level > 0)
return false;
if (ISL_GFX_VER(dev) < 9)
return false;
*ucompr_surf = *surf;
ucompr_surf->levels = 1;
*offset_B = 0;
*ucompr_view = *view;
} else {
isl_surf_get_image_surf(dev, surf,
view->base_level,
surf->dim == ISL_SURF_DIM_3D ?
0 : view->base_array_layer,
surf->dim == ISL_SURF_DIM_3D ?
view->base_array_layer : 0,
ucompr_surf,
offset_B, &x_offset_sa, &y_offset_sa);
*ucompr_view = *view;
ucompr_view->base_array_layer = 0;
ucompr_view->base_level = 0;
}
ucompr_surf->format = view_format;
assert(ucompr_surf->logical_level0_px.width == view_width);
assert(ucompr_surf->logical_level0_px.height == view_height);
ucompr_surf->logical_level0_px.width = ucompr_width;
ucompr_surf->logical_level0_px.height = ucompr_height;
ucompr_surf->phys_level0_sa = isl_surf_get_phys_level0_el(surf);
*x_offset_el = isl_assert_div(x_offset_sa, fmtl->bw);
*y_offset_el = isl_assert_div(y_offset_sa, fmtl->bh);
return true;
}
void
isl_tiling_get_intratile_offset_el(enum isl_tiling tiling,
uint32_t bpb,
uint32_t row_pitch_B,
uint32_t array_pitch_el_rows,
uint32_t total_x_offset_el,
uint32_t total_y_offset_el,
uint32_t total_z_offset_el,
uint32_t total_array_offset,
uint32_t *base_address_offset,
uint32_t *x_offset_el,
uint32_t *y_offset_el,
uint32_t *z_offset_el,
uint32_t *array_offset)
{
if (tiling == ISL_TILING_LINEAR) {
assert(bpb % 8 == 0);
assert(total_z_offset_el == 0 && total_array_offset == 0);
*base_address_offset = total_y_offset_el * row_pitch_B +
total_x_offset_el * (bpb / 8);
*x_offset_el = 0;
*y_offset_el = 0;
*z_offset_el = 0;
*array_offset = 0;
return;
}
struct isl_tile_info tile_info;
isl_tiling_get_info(tiling, bpb, &tile_info);
assert(row_pitch_B % tile_info.phys_extent_B.width == 0);
if (tile_info.logical_extent_el.d > 1 || tile_info.logical_extent_el.a > 1)
assert(array_pitch_el_rows % tile_info.logical_extent_el.h == 0);
const uint32_t tile_el_scale = bpb / tile_info.format_bpb;
tile_info.phys_extent_B.width *= tile_el_scale;
*x_offset_el = total_x_offset_el % tile_info.logical_extent_el.w;
*y_offset_el = total_y_offset_el % tile_info.logical_extent_el.h;
*z_offset_el = total_z_offset_el % tile_info.logical_extent_el.d;
*array_offset = total_array_offset % tile_info.logical_extent_el.a;
uint32_t x_offset_tl = total_x_offset_el / tile_info.logical_extent_el.w;
uint32_t y_offset_tl = total_y_offset_el / tile_info.logical_extent_el.h;
uint32_t z_offset_tl = total_z_offset_el / tile_info.logical_extent_el.d;
uint32_t a_offset_tl = total_array_offset / tile_info.logical_extent_el.a;
uint32_t array_pitch_tl_rows =
array_pitch_el_rows / tile_info.logical_extent_el.h;
y_offset_tl += (z_offset_tl + a_offset_tl) * array_pitch_tl_rows;
*base_address_offset =
y_offset_tl * tile_info.phys_extent_B.h * row_pitch_B +
x_offset_tl * tile_info.phys_extent_B.h * tile_info.phys_extent_B.w;
}
uint32_t
isl_surf_get_depth_format(const struct isl_device *dev,
const struct isl_surf *surf)
{
bool has_stencil = surf->usage & ISL_SURF_USAGE_STENCIL_BIT;
assert(surf->usage & ISL_SURF_USAGE_DEPTH_BIT);
if (has_stencil)
assert(ISL_GFX_VER(dev) < 7);
switch (surf->format) {
default:
unreachable("bad isl depth format");
case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
assert(ISL_GFX_VER(dev) < 7);
return 0;
case ISL_FORMAT_R32_FLOAT:
assert(!has_stencil);
return 1;
case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
if (has_stencil) {
assert(ISL_GFX_VER(dev) < 7);
return 2;
} else {
assert(ISL_GFX_VER(dev) >= 5);
return 3;
}
case ISL_FORMAT_R16_UNORM:
assert(!has_stencil);
return 5;
}
}
bool
isl_swizzle_supports_rendering(const struct intel_device_info *devinfo,
struct isl_swizzle swizzle)
{
if (devinfo->is_haswell) {
return true;
} else if (devinfo->ver <= 7) {
return isl_swizzle_is_identity(swizzle);
} else {
return (swizzle.r == ISL_CHANNEL_SELECT_RED ||
swizzle.r == ISL_CHANNEL_SELECT_GREEN ||
swizzle.r == ISL_CHANNEL_SELECT_BLUE) &&
(swizzle.g == ISL_CHANNEL_SELECT_RED ||
swizzle.g == ISL_CHANNEL_SELECT_GREEN ||
swizzle.g == ISL_CHANNEL_SELECT_BLUE) &&
(swizzle.b == ISL_CHANNEL_SELECT_RED ||
swizzle.b == ISL_CHANNEL_SELECT_GREEN ||
swizzle.b == ISL_CHANNEL_SELECT_BLUE) &&
swizzle.r != swizzle.g &&
swizzle.r != swizzle.b &&
swizzle.g != swizzle.b &&
swizzle.a == ISL_CHANNEL_SELECT_ALPHA;
}
}
static enum isl_channel_select
swizzle_select(enum isl_channel_select chan, struct isl_swizzle swizzle)
{
switch (chan) {
case ISL_CHANNEL_SELECT_ZERO:
case ISL_CHANNEL_SELECT_ONE:
return chan;
case ISL_CHANNEL_SELECT_RED:
return swizzle.r;
case ISL_CHANNEL_SELECT_GREEN:
return swizzle.g;
case ISL_CHANNEL_SELECT_BLUE:
return swizzle.b;
case ISL_CHANNEL_SELECT_ALPHA:
return swizzle.a;
default:
unreachable("Invalid swizzle component");
}
}
struct isl_swizzle
isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second)
{
return (struct isl_swizzle) {
.r = swizzle_select(first.r, second),
.g = swizzle_select(first.g, second),
.b = swizzle_select(first.b, second),
.a = swizzle_select(first.a, second),
};
}
struct isl_swizzle
isl_swizzle_invert(struct isl_swizzle swizzle)
{
enum isl_channel_select chans[4] = {
ISL_CHANNEL_SELECT_ZERO,
ISL_CHANNEL_SELECT_ZERO,
ISL_CHANNEL_SELECT_ZERO,
ISL_CHANNEL_SELECT_ZERO,
};
if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
chans[swizzle.a - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_ALPHA;
if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
chans[swizzle.b - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_BLUE;
if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
chans[swizzle.g - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_GREEN;
if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
chans[swizzle.r - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_RED;
return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3] };
}
union isl_color_value
isl_color_value_swizzle_inv(union isl_color_value src,
struct isl_swizzle swizzle)
{
union isl_color_value dst = { .u32 = { 0, } };
if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
dst.u32[swizzle.a - ISL_CHANNEL_SELECT_RED] = src.u32[3];
if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
dst.u32[swizzle.b - ISL_CHANNEL_SELECT_RED] = src.u32[2];
if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
dst.u32[swizzle.g - ISL_CHANNEL_SELECT_RED] = src.u32[1];
if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
dst.u32[swizzle.r - ISL_CHANNEL_SELECT_RED] = src.u32[0];
return dst;
}
uint8_t
isl_format_get_aux_map_encoding(enum isl_format format)
{
switch(format) {
case ISL_FORMAT_R32G32B32A32_FLOAT: return 0x11;
case ISL_FORMAT_R32G32B32X32_FLOAT: return 0x11;
case ISL_FORMAT_R32G32B32A32_SINT: return 0x12;
case ISL_FORMAT_R32G32B32A32_UINT: return 0x13;
case ISL_FORMAT_R16G16B16A16_UNORM: return 0x14;
case ISL_FORMAT_R16G16B16A16_SNORM: return 0x15;
case ISL_FORMAT_R16G16B16A16_SINT: return 0x16;
case ISL_FORMAT_R16G16B16A16_UINT: return 0x17;
case ISL_FORMAT_R16G16B16A16_FLOAT: return 0x10;
case ISL_FORMAT_R16G16B16X16_FLOAT: return 0x10;
case ISL_FORMAT_R32G32_FLOAT: return 0x11;
case ISL_FORMAT_R32G32_SINT: return 0x12;
case ISL_FORMAT_R32G32_UINT: return 0x13;
case ISL_FORMAT_B8G8R8A8_UNORM: return 0xA;
case ISL_FORMAT_B8G8R8X8_UNORM: return 0xA;
case ISL_FORMAT_B8G8R8A8_UNORM_SRGB: return 0xA;
case ISL_FORMAT_B8G8R8X8_UNORM_SRGB: return 0xA;
case ISL_FORMAT_R10G10B10A2_UNORM: return 0x18;
case ISL_FORMAT_R10G10B10A2_UNORM_SRGB: return 0x18;
case ISL_FORMAT_R10G10B10_FLOAT_A2_UNORM: return 0x19;
case ISL_FORMAT_R10G10B10A2_UINT: return 0x1A;
case ISL_FORMAT_R8G8B8A8_UNORM: return 0xA;
case ISL_FORMAT_R8G8B8A8_UNORM_SRGB: return 0xA;
case ISL_FORMAT_R8G8B8A8_SNORM: return 0x1B;
case ISL_FORMAT_R8G8B8A8_SINT: return 0x1C;
case ISL_FORMAT_R8G8B8A8_UINT: return 0x1D;
case ISL_FORMAT_R16G16_UNORM: return 0x14;
case ISL_FORMAT_R16G16_SNORM: return 0x15;
case ISL_FORMAT_R16G16_SINT: return 0x16;
case ISL_FORMAT_R16G16_UINT: return 0x17;
case ISL_FORMAT_R16G16_FLOAT: return 0x10;
case ISL_FORMAT_B10G10R10A2_UNORM: return 0x18;
case ISL_FORMAT_B10G10R10A2_UNORM_SRGB: return 0x18;
case ISL_FORMAT_R11G11B10_FLOAT: return 0x1E;
case ISL_FORMAT_R32_SINT: return 0x12;
case ISL_FORMAT_R32_UINT: return 0x13;
case ISL_FORMAT_R32_FLOAT: return 0x11;
case ISL_FORMAT_R24_UNORM_X8_TYPELESS: return 0x13;
case ISL_FORMAT_B5G6R5_UNORM: return 0xA;
case ISL_FORMAT_B5G6R5_UNORM_SRGB: return 0xA;
case ISL_FORMAT_B5G5R5A1_UNORM: return 0xA;
case ISL_FORMAT_B5G5R5A1_UNORM_SRGB: return 0xA;
case ISL_FORMAT_B4G4R4A4_UNORM: return 0xA;
case ISL_FORMAT_B4G4R4A4_UNORM_SRGB: return 0xA;
case ISL_FORMAT_R8G8_UNORM: return 0xA;
case ISL_FORMAT_R8G8_SNORM: return 0x1B;
case ISL_FORMAT_R8G8_SINT: return 0x1C;
case ISL_FORMAT_R8G8_UINT: return 0x1D;
case ISL_FORMAT_R16_UNORM: return 0x14;
case ISL_FORMAT_R16_SNORM: return 0x15;
case ISL_FORMAT_R16_SINT: return 0x16;
case ISL_FORMAT_R16_UINT: return 0x17;
case ISL_FORMAT_R16_FLOAT: return 0x10;
case ISL_FORMAT_B5G5R5X1_UNORM: return 0xA;
case ISL_FORMAT_B5G5R5X1_UNORM_SRGB: return 0xA;
case ISL_FORMAT_A1B5G5R5_UNORM: return 0xA;
case ISL_FORMAT_A4B4G4R4_UNORM: return 0xA;
case ISL_FORMAT_R8_UNORM: return 0xA;
case ISL_FORMAT_R8_SNORM: return 0x1B;
case ISL_FORMAT_R8_SINT: return 0x1C;
case ISL_FORMAT_R8_UINT: return 0x1D;
case ISL_FORMAT_A8_UNORM: return 0xA;
case ISL_FORMAT_PLANAR_420_8: return 0xF;
case ISL_FORMAT_PLANAR_420_10: return 0x7;
case ISL_FORMAT_PLANAR_420_12: return 0x8;
case ISL_FORMAT_PLANAR_420_16: return 0x8;
case ISL_FORMAT_YCRCB_NORMAL: return 0x3;
case ISL_FORMAT_YCRCB_SWAPY: return 0xB;
default:
unreachable("Unsupported aux-map format!");
return 0;
}
}