2017-05-10 17:35:25 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2011 Red Hat All Rights Reserved.
|
|
|
|
|
* Copyright © 2017 Advanced Micro Devices, Inc.
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
|
|
|
|
|
* AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ac_surface.h"
|
2017-05-12 01:24:48 +02:00
|
|
|
#include "amd_family.h"
|
2018-11-19 18:53:09 +01:00
|
|
|
#include "addrlib/src/amdgpu_asic_addr.h"
|
2017-05-12 01:24:48 +02:00
|
|
|
#include "ac_gpu_info.h"
|
2020-06-09 04:55:19 -04:00
|
|
|
#include "util/hash_table.h"
|
2017-05-10 17:35:25 +02:00
|
|
|
#include "util/macros.h"
|
2020-06-09 04:55:19 -04:00
|
|
|
#include "util/simple_mtx.h"
|
2017-07-28 23:08:10 +02:00
|
|
|
#include "util/u_atomic.h"
|
2017-05-10 17:35:25 +02:00
|
|
|
#include "util/u_math.h"
|
2020-06-09 04:55:19 -04:00
|
|
|
#include "util/u_memory.h"
|
2020-04-17 20:37:41 -04:00
|
|
|
#include "sid.h"
|
2017-05-10 17:35:25 +02:00
|
|
|
|
2017-05-10 20:44:51 +02:00
|
|
|
#include <errno.h>
|
2017-05-10 17:35:25 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <amdgpu.h>
|
2020-04-25 20:03:15 +02:00
|
|
|
#include "drm-uapi/amdgpu_drm.h"
|
2017-05-10 17:35:25 +02:00
|
|
|
|
2018-11-19 18:53:09 +01:00
|
|
|
#include "addrlib/inc/addrinterface.h"
|
2017-05-10 17:35:25 +02:00
|
|
|
|
|
|
|
|
#ifndef CIASICIDGFXENGINE_SOUTHERNISLAND
|
|
|
|
|
#define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef CIASICIDGFXENGINE_ARCTICISLAND
|
|
|
|
|
#define CIASICIDGFXENGINE_ARCTICISLAND 0x0000000D
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
struct ac_addrlib {
|
|
|
|
|
ADDR_HANDLE handle;
|
2020-06-09 04:55:19 -04:00
|
|
|
|
|
|
|
|
/* The cache of DCC retile maps for reuse when allocating images of
|
|
|
|
|
* similar sizes.
|
|
|
|
|
*/
|
|
|
|
|
simple_mtx_t dcc_retile_map_lock;
|
|
|
|
|
struct hash_table *dcc_retile_maps;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct dcc_retile_map_key {
|
|
|
|
|
enum radeon_family family;
|
|
|
|
|
unsigned retile_width;
|
|
|
|
|
unsigned retile_height;
|
|
|
|
|
bool rb_aligned;
|
|
|
|
|
bool pipe_aligned;
|
|
|
|
|
unsigned dcc_retile_num_elements;
|
|
|
|
|
ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT input;
|
2020-06-09 03:19:04 -04:00
|
|
|
};
|
|
|
|
|
|
2020-06-09 04:55:19 -04:00
|
|
|
static uint32_t dcc_retile_map_hash_key(const void *key)
|
|
|
|
|
{
|
|
|
|
|
return _mesa_hash_data(key, sizeof(struct dcc_retile_map_key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool dcc_retile_map_keys_equal(const void *a, const void *b)
|
|
|
|
|
{
|
|
|
|
|
return memcmp(a, b, sizeof(struct dcc_retile_map_key)) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void dcc_retile_map_free(struct hash_entry *entry)
|
|
|
|
|
{
|
|
|
|
|
free((void*)entry->key);
|
|
|
|
|
free(entry->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t *ac_compute_dcc_retile_map(struct ac_addrlib *addrlib,
|
|
|
|
|
const struct radeon_info *info,
|
|
|
|
|
unsigned retile_width, unsigned retile_height,
|
|
|
|
|
bool rb_aligned, bool pipe_aligned, bool use_uint16,
|
|
|
|
|
unsigned dcc_retile_num_elements,
|
|
|
|
|
const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT *in)
|
|
|
|
|
{
|
|
|
|
|
unsigned dcc_retile_map_size = dcc_retile_num_elements * (use_uint16 ? 2 : 4);
|
|
|
|
|
struct dcc_retile_map_key key;
|
|
|
|
|
|
|
|
|
|
assert(in->numFrags == 1 && in->numSlices == 1 && in->numMipLevels == 1);
|
|
|
|
|
|
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
|
key.family = info->family;
|
|
|
|
|
key.retile_width = retile_width;
|
|
|
|
|
key.retile_height = retile_height;
|
|
|
|
|
key.rb_aligned = rb_aligned;
|
|
|
|
|
key.pipe_aligned = pipe_aligned;
|
|
|
|
|
key.dcc_retile_num_elements = dcc_retile_num_elements;
|
|
|
|
|
memcpy(&key.input, in, sizeof(*in));
|
|
|
|
|
|
|
|
|
|
simple_mtx_lock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
|
|
|
|
|
/* If we have already computed this retile map, get it from the hash table. */
|
|
|
|
|
struct hash_entry *entry = _mesa_hash_table_search(addrlib->dcc_retile_maps, &key);
|
|
|
|
|
if (entry) {
|
|
|
|
|
uint32_t *map = entry->data;
|
|
|
|
|
simple_mtx_unlock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT addrin;
|
|
|
|
|
memcpy(&addrin, in, sizeof(*in));
|
|
|
|
|
|
|
|
|
|
ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT addrout = {};
|
|
|
|
|
addrout.size = sizeof(addrout);
|
|
|
|
|
|
|
|
|
|
void *dcc_retile_map = malloc(dcc_retile_map_size);
|
|
|
|
|
if (!dcc_retile_map) {
|
|
|
|
|
simple_mtx_unlock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned index = 0;
|
|
|
|
|
|
|
|
|
|
for (unsigned y = 0; y < retile_height; y += in->compressBlkHeight) {
|
|
|
|
|
addrin.y = y;
|
|
|
|
|
|
|
|
|
|
for (unsigned x = 0; x < retile_width; x += in->compressBlkWidth) {
|
|
|
|
|
addrin.x = x;
|
|
|
|
|
|
|
|
|
|
/* Compute src DCC address */
|
|
|
|
|
addrin.dccKeyFlags.pipeAligned = pipe_aligned;
|
|
|
|
|
addrin.dccKeyFlags.rbAligned = rb_aligned;
|
|
|
|
|
addrout.addr = 0;
|
|
|
|
|
|
|
|
|
|
if (Addr2ComputeDccAddrFromCoord(addrlib->handle, &addrin, &addrout) != ADDR_OK) {
|
|
|
|
|
simple_mtx_unlock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_uint16)
|
|
|
|
|
((uint16_t*)dcc_retile_map)[index * 2] = addrout.addr;
|
|
|
|
|
else
|
|
|
|
|
((uint32_t*)dcc_retile_map)[index * 2] = addrout.addr;
|
|
|
|
|
|
|
|
|
|
/* Compute dst DCC address */
|
|
|
|
|
addrin.dccKeyFlags.pipeAligned = 0;
|
|
|
|
|
addrin.dccKeyFlags.rbAligned = 0;
|
|
|
|
|
addrout.addr = 0;
|
|
|
|
|
|
|
|
|
|
if (Addr2ComputeDccAddrFromCoord(addrlib->handle, &addrin, &addrout) != ADDR_OK) {
|
|
|
|
|
simple_mtx_unlock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_uint16)
|
|
|
|
|
((uint16_t*)dcc_retile_map)[index * 2 + 1] = addrout.addr;
|
|
|
|
|
else
|
|
|
|
|
((uint32_t*)dcc_retile_map)[index * 2 + 1] = addrout.addr;
|
|
|
|
|
|
|
|
|
|
assert(index * 2 + 1 < dcc_retile_num_elements);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Fill the remaining pairs with the last one (for the compute shader). */
|
|
|
|
|
for (unsigned i = index * 2; i < dcc_retile_num_elements; i++) {
|
|
|
|
|
if (use_uint16)
|
|
|
|
|
((uint16_t*)dcc_retile_map)[i] = ((uint16_t*)dcc_retile_map)[i - 2];
|
|
|
|
|
else
|
|
|
|
|
((uint32_t*)dcc_retile_map)[i] = ((uint32_t*)dcc_retile_map)[i - 2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Insert the retile map into the hash table, so that it can be reused and
|
|
|
|
|
* the computation can be skipped for similar image sizes.
|
|
|
|
|
*/
|
|
|
|
|
_mesa_hash_table_insert(addrlib->dcc_retile_maps,
|
|
|
|
|
mem_dup(&key, sizeof(key)), dcc_retile_map);
|
|
|
|
|
|
|
|
|
|
simple_mtx_unlock(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
return dcc_retile_map;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 17:35:25 +02:00
|
|
|
static void *ADDR_API allocSysMem(const ADDR_ALLOCSYSMEM_INPUT * pInput)
|
|
|
|
|
{
|
|
|
|
|
return malloc(pInput->sizeInBytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ADDR_E_RETURNCODE ADDR_API freeSysMem(const ADDR_FREESYSMEM_INPUT * pInput)
|
|
|
|
|
{
|
|
|
|
|
free(pInput->pVirtAddr);
|
|
|
|
|
return ADDR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
struct ac_addrlib *ac_addrlib_create(const struct radeon_info *info,
|
|
|
|
|
const struct amdgpu_gpu_info *amdinfo,
|
|
|
|
|
uint64_t *max_alignment)
|
2017-05-10 17:35:25 +02:00
|
|
|
{
|
|
|
|
|
ADDR_CREATE_INPUT addrCreateInput = {0};
|
|
|
|
|
ADDR_CREATE_OUTPUT addrCreateOutput = {0};
|
|
|
|
|
ADDR_REGISTER_VALUE regValue = {0};
|
|
|
|
|
ADDR_CREATE_FLAGS createFlags = {{0}};
|
2019-06-19 20:42:18 -04:00
|
|
|
ADDR_GET_MAX_ALIGNMENTS_OUTPUT addrGetMaxAlignmentsOutput = {0};
|
2017-05-10 17:35:25 +02:00
|
|
|
ADDR_E_RETURNCODE addrRet;
|
|
|
|
|
|
|
|
|
|
addrCreateInput.size = sizeof(ADDR_CREATE_INPUT);
|
|
|
|
|
addrCreateOutput.size = sizeof(ADDR_CREATE_OUTPUT);
|
|
|
|
|
|
2017-05-12 01:24:48 +02:00
|
|
|
regValue.gbAddrConfig = amdinfo->gb_addr_cfg;
|
2017-05-10 17:35:25 +02:00
|
|
|
createFlags.value = 0;
|
|
|
|
|
|
2019-06-19 21:47:46 -04:00
|
|
|
addrCreateInput.chipFamily = info->family_id;
|
|
|
|
|
addrCreateInput.chipRevision = info->chip_external_rev;
|
|
|
|
|
|
2017-05-10 17:35:25 +02:00
|
|
|
if (addrCreateInput.chipFamily == FAMILY_UNKNOWN)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (addrCreateInput.chipFamily >= FAMILY_AI) {
|
|
|
|
|
addrCreateInput.chipEngine = CIASICIDGFXENGINE_ARCTICISLAND;
|
|
|
|
|
} else {
|
2017-05-12 01:24:48 +02:00
|
|
|
regValue.noOfBanks = amdinfo->mc_arb_ramcfg & 0x3;
|
|
|
|
|
regValue.noOfRanks = (amdinfo->mc_arb_ramcfg & 0x4) >> 2;
|
2017-05-10 17:35:25 +02:00
|
|
|
|
2017-05-12 01:24:48 +02:00
|
|
|
regValue.backendDisables = amdinfo->enabled_rb_pipes_mask;
|
|
|
|
|
regValue.pTileConfig = amdinfo->gb_tile_mode;
|
|
|
|
|
regValue.noOfEntries = ARRAY_SIZE(amdinfo->gb_tile_mode);
|
2017-05-10 17:35:25 +02:00
|
|
|
if (addrCreateInput.chipFamily == FAMILY_SI) {
|
|
|
|
|
regValue.pMacroTileConfig = NULL;
|
|
|
|
|
regValue.noOfMacroEntries = 0;
|
|
|
|
|
} else {
|
2017-05-12 01:24:48 +02:00
|
|
|
regValue.pMacroTileConfig = amdinfo->gb_macro_tile_mode;
|
|
|
|
|
regValue.noOfMacroEntries = ARRAY_SIZE(amdinfo->gb_macro_tile_mode);
|
2017-05-10 17:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createFlags.useTileIndex = 1;
|
|
|
|
|
createFlags.useHtileSliceAlign = 1;
|
|
|
|
|
|
|
|
|
|
addrCreateInput.chipEngine = CIASICIDGFXENGINE_SOUTHERNISLAND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addrCreateInput.callbacks.allocSysMem = allocSysMem;
|
|
|
|
|
addrCreateInput.callbacks.freeSysMem = freeSysMem;
|
|
|
|
|
addrCreateInput.callbacks.debugPrint = 0;
|
|
|
|
|
addrCreateInput.createFlags = createFlags;
|
|
|
|
|
addrCreateInput.regValue = regValue;
|
|
|
|
|
|
|
|
|
|
addrRet = AddrCreate(&addrCreateInput, &addrCreateOutput);
|
|
|
|
|
if (addrRet != ADDR_OK)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2017-07-09 20:34:04 +01:00
|
|
|
if (max_alignment) {
|
|
|
|
|
addrRet = AddrGetMaxAlignments(addrCreateOutput.hLib, &addrGetMaxAlignmentsOutput);
|
|
|
|
|
if (addrRet == ADDR_OK){
|
|
|
|
|
*max_alignment = addrGetMaxAlignmentsOutput.baseAlign;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-09 03:19:04 -04:00
|
|
|
|
|
|
|
|
struct ac_addrlib *addrlib = calloc(1, sizeof(struct ac_addrlib));
|
|
|
|
|
if (!addrlib) {
|
|
|
|
|
AddrDestroy(addrCreateOutput.hLib);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addrlib->handle = addrCreateOutput.hLib;
|
2020-06-09 04:55:19 -04:00
|
|
|
simple_mtx_init(&addrlib->dcc_retile_map_lock, mtx_plain);
|
|
|
|
|
addrlib->dcc_retile_maps = _mesa_hash_table_create(NULL, dcc_retile_map_hash_key,
|
|
|
|
|
dcc_retile_map_keys_equal);
|
2020-06-09 03:19:04 -04:00
|
|
|
return addrlib;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ac_addrlib_destroy(struct ac_addrlib *addrlib)
|
|
|
|
|
{
|
|
|
|
|
AddrDestroy(addrlib->handle);
|
2020-06-09 04:55:19 -04:00
|
|
|
simple_mtx_destroy(&addrlib->dcc_retile_map_lock);
|
|
|
|
|
_mesa_hash_table_destroy(addrlib->dcc_retile_maps, dcc_retile_map_free);
|
2020-06-09 03:19:04 -04:00
|
|
|
free(addrlib);
|
2017-05-10 17:35:25 +02:00
|
|
|
}
|
2017-05-10 20:21:36 +02:00
|
|
|
|
2018-04-30 20:54:06 -04:00
|
|
|
static int surf_config_sanity(const struct ac_surf_config *config,
|
|
|
|
|
unsigned flags)
|
2017-05-10 20:44:51 +02:00
|
|
|
{
|
2018-04-30 20:54:06 -04:00
|
|
|
/* FMASK is allocated together with the color surface and can't be
|
|
|
|
|
* allocated separately.
|
|
|
|
|
*/
|
|
|
|
|
assert(!(flags & RADEON_SURF_FMASK));
|
|
|
|
|
if (flags & RADEON_SURF_FMASK)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2017-05-10 20:44:51 +02:00
|
|
|
/* all dimension must be at least 1 ! */
|
|
|
|
|
if (!config->info.width || !config->info.height || !config->info.depth ||
|
|
|
|
|
!config->info.array_size || !config->info.levels)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
switch (config->info.samples) {
|
|
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
case 4:
|
|
|
|
|
case 8:
|
|
|
|
|
break;
|
2018-04-30 22:29:14 -04:00
|
|
|
case 16:
|
|
|
|
|
if (flags & RADEON_SURF_Z_OR_SBUFFER)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
break;
|
2017-05-10 20:44:51 +02:00
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 22:29:14 -04:00
|
|
|
if (!(flags & RADEON_SURF_Z_OR_SBUFFER)) {
|
2018-05-23 22:42:49 -04:00
|
|
|
switch (config->info.storage_samples) {
|
2018-04-30 22:29:14 -04:00
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
case 4:
|
|
|
|
|
case 8:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:44:51 +02:00
|
|
|
if (config->is_3d && config->info.array_size > 1)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (config->is_cube && config->info.depth > 1)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
static int gfx6_compute_level(ADDR_HANDLE addrlib,
|
|
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
struct radeon_surf *surf, bool is_stencil,
|
|
|
|
|
unsigned level, bool compressed,
|
|
|
|
|
ADDR_COMPUTE_SURFACE_INFO_INPUT *AddrSurfInfoIn,
|
|
|
|
|
ADDR_COMPUTE_SURFACE_INFO_OUTPUT *AddrSurfInfoOut,
|
|
|
|
|
ADDR_COMPUTE_DCCINFO_INPUT *AddrDccIn,
|
|
|
|
|
ADDR_COMPUTE_DCCINFO_OUTPUT *AddrDccOut,
|
|
|
|
|
ADDR_COMPUTE_HTILE_INFO_INPUT *AddrHtileIn,
|
|
|
|
|
ADDR_COMPUTE_HTILE_INFO_OUTPUT *AddrHtileOut)
|
|
|
|
|
{
|
|
|
|
|
struct legacy_surf_level *surf_level;
|
|
|
|
|
ADDR_E_RETURNCODE ret;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn->mipLevel = level;
|
|
|
|
|
AddrSurfInfoIn->width = u_minify(config->info.width, level);
|
|
|
|
|
AddrSurfInfoIn->height = u_minify(config->info.height, level);
|
|
|
|
|
|
2017-07-25 00:08:55 +02:00
|
|
|
/* Make GFX6 linear surfaces compatible with GFX9 for hybrid graphics,
|
|
|
|
|
* because GFX9 needs linear alignment of 256 bytes.
|
|
|
|
|
*/
|
|
|
|
|
if (config->info.levels == 1 &&
|
|
|
|
|
AddrSurfInfoIn->tileMode == ADDR_TM_LINEAR_ALIGNED &&
|
2018-05-19 01:03:57 +02:00
|
|
|
AddrSurfInfoIn->bpp &&
|
|
|
|
|
util_is_power_of_two_or_zero(AddrSurfInfoIn->bpp)) {
|
2017-07-25 00:08:55 +02:00
|
|
|
unsigned alignment = 256 / (AddrSurfInfoIn->bpp / 8);
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn->width = align(AddrSurfInfoIn->width, alignment);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 02:02:20 +01:00
|
|
|
/* addrlib assumes the bytes/pixel is a divisor of 64, which is not
|
|
|
|
|
* true for r32g32b32 formats. */
|
|
|
|
|
if (AddrSurfInfoIn->bpp == 96) {
|
|
|
|
|
assert(config->info.levels == 1);
|
|
|
|
|
assert(AddrSurfInfoIn->tileMode == ADDR_TM_LINEAR_ALIGNED);
|
|
|
|
|
|
|
|
|
|
/* The least common multiple of 64 bytes and 12 bytes/pixel is
|
|
|
|
|
* 192 bytes, or 16 pixels. */
|
|
|
|
|
AddrSurfInfoIn->width = align(AddrSurfInfoIn->width, 16);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
if (config->is_3d)
|
|
|
|
|
AddrSurfInfoIn->numSlices = u_minify(config->info.depth, level);
|
|
|
|
|
else if (config->is_cube)
|
|
|
|
|
AddrSurfInfoIn->numSlices = 6;
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn->numSlices = config->info.array_size;
|
|
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
|
/* Set the base level pitch. This is needed for calculation
|
|
|
|
|
* of non-zero levels. */
|
|
|
|
|
if (is_stencil)
|
|
|
|
|
AddrSurfInfoIn->basePitch = surf->u.legacy.stencil_level[0].nblk_x;
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn->basePitch = surf->u.legacy.level[0].nblk_x;
|
|
|
|
|
|
|
|
|
|
/* Convert blocks to pixels for compressed formats. */
|
|
|
|
|
if (compressed)
|
|
|
|
|
AddrSurfInfoIn->basePitch *= surf->blk_w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = AddrComputeSurfaceInfo(addrlib,
|
|
|
|
|
AddrSurfInfoIn,
|
|
|
|
|
AddrSurfInfoOut);
|
|
|
|
|
if (ret != ADDR_OK) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surf_level = is_stencil ? &surf->u.legacy.stencil_level[level] : &surf->u.legacy.level[level];
|
|
|
|
|
surf_level->offset = align64(surf->surf_size, AddrSurfInfoOut->baseAlign);
|
2017-11-14 19:31:39 +01:00
|
|
|
surf_level->slice_size_dw = AddrSurfInfoOut->sliceSize / 4;
|
2017-05-10 20:21:36 +02:00
|
|
|
surf_level->nblk_x = AddrSurfInfoOut->pitch;
|
|
|
|
|
surf_level->nblk_y = AddrSurfInfoOut->height;
|
|
|
|
|
|
|
|
|
|
switch (AddrSurfInfoOut->tileMode) {
|
|
|
|
|
case ADDR_TM_LINEAR_ALIGNED:
|
|
|
|
|
surf_level->mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
|
|
|
|
|
break;
|
|
|
|
|
case ADDR_TM_1D_TILED_THIN1:
|
|
|
|
|
surf_level->mode = RADEON_SURF_MODE_1D;
|
|
|
|
|
break;
|
|
|
|
|
case ADDR_TM_2D_TILED_THIN1:
|
|
|
|
|
surf_level->mode = RADEON_SURF_MODE_2D;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_stencil)
|
|
|
|
|
surf->u.legacy.stencil_tiling_index[level] = AddrSurfInfoOut->tileIndex;
|
|
|
|
|
else
|
|
|
|
|
surf->u.legacy.tiling_index[level] = AddrSurfInfoOut->tileIndex;
|
|
|
|
|
|
|
|
|
|
surf->surf_size = surf_level->offset + AddrSurfInfoOut->surfSize;
|
|
|
|
|
|
|
|
|
|
/* Clear DCC fields at the beginning. */
|
|
|
|
|
surf_level->dcc_offset = 0;
|
|
|
|
|
|
|
|
|
|
/* The previous level's flag tells us if we can use DCC for this level. */
|
|
|
|
|
if (AddrSurfInfoIn->flags.dccCompatible &&
|
|
|
|
|
(level == 0 || AddrDccOut->subLvlCompressible)) {
|
2018-04-16 16:34:56 -04:00
|
|
|
bool prev_level_clearable = level == 0 ||
|
|
|
|
|
AddrDccOut->dccRamSizeAligned;
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrDccIn->colorSurfSize = AddrSurfInfoOut->surfSize;
|
|
|
|
|
AddrDccIn->tileMode = AddrSurfInfoOut->tileMode;
|
|
|
|
|
AddrDccIn->tileInfo = *AddrSurfInfoOut->pTileInfo;
|
|
|
|
|
AddrDccIn->tileIndex = AddrSurfInfoOut->tileIndex;
|
|
|
|
|
AddrDccIn->macroModeIndex = AddrSurfInfoOut->macroModeIndex;
|
|
|
|
|
|
|
|
|
|
ret = AddrComputeDccInfo(addrlib,
|
|
|
|
|
AddrDccIn,
|
|
|
|
|
AddrDccOut);
|
|
|
|
|
|
|
|
|
|
if (ret == ADDR_OK) {
|
|
|
|
|
surf_level->dcc_offset = surf->dcc_size;
|
|
|
|
|
surf->num_dcc_levels = level + 1;
|
|
|
|
|
surf->dcc_size = surf_level->dcc_offset + AddrDccOut->dccRamSize;
|
|
|
|
|
surf->dcc_alignment = MAX2(surf->dcc_alignment, AddrDccOut->dccRamBaseAlign);
|
2018-04-16 16:34:56 -04:00
|
|
|
|
|
|
|
|
/* If the DCC size of a subresource (1 mip level or 1 slice)
|
|
|
|
|
* is not aligned, the DCC memory layout is not contiguous for
|
|
|
|
|
* that subresource, which means we can't use fast clear.
|
|
|
|
|
*
|
|
|
|
|
* We only do fast clears for whole mipmap levels. If we did
|
|
|
|
|
* per-slice fast clears, the same restriction would apply.
|
|
|
|
|
* (i.e. only compute the slice size and see if it's aligned)
|
|
|
|
|
*
|
|
|
|
|
* The last level can be non-contiguous and still be clearable
|
|
|
|
|
* if it's interleaved with the next level that doesn't exist.
|
|
|
|
|
*/
|
|
|
|
|
if (AddrDccOut->dccRamSizeAligned ||
|
|
|
|
|
(prev_level_clearable && level == config->info.levels - 1))
|
|
|
|
|
surf_level->dcc_fast_clear_size = AddrDccOut->dccFastClearSize;
|
|
|
|
|
else
|
|
|
|
|
surf_level->dcc_fast_clear_size = 0;
|
2019-07-01 16:30:55 +02:00
|
|
|
|
|
|
|
|
/* Compute the DCC slice size because addrlib doesn't
|
|
|
|
|
* provide this info. As DCC memory is linear (each
|
|
|
|
|
* slice is the same size) it's easy to compute.
|
|
|
|
|
*/
|
|
|
|
|
surf->dcc_slice_size = AddrDccOut->dccRamSize / config->info.array_size;
|
2019-07-01 16:30:56 +02:00
|
|
|
|
|
|
|
|
/* For arrays, we have to compute the DCC info again
|
|
|
|
|
* with one slice size to get a correct fast clear
|
|
|
|
|
* size.
|
|
|
|
|
*/
|
|
|
|
|
if (config->info.array_size > 1) {
|
|
|
|
|
AddrDccIn->colorSurfSize = AddrSurfInfoOut->sliceSize;
|
|
|
|
|
AddrDccIn->tileMode = AddrSurfInfoOut->tileMode;
|
|
|
|
|
AddrDccIn->tileInfo = *AddrSurfInfoOut->pTileInfo;
|
|
|
|
|
AddrDccIn->tileIndex = AddrSurfInfoOut->tileIndex;
|
|
|
|
|
AddrDccIn->macroModeIndex = AddrSurfInfoOut->macroModeIndex;
|
|
|
|
|
|
|
|
|
|
ret = AddrComputeDccInfo(addrlib,
|
|
|
|
|
AddrDccIn, AddrDccOut);
|
|
|
|
|
if (ret == ADDR_OK) {
|
|
|
|
|
/* If the DCC memory isn't properly
|
|
|
|
|
* aligned, the data are interleaved
|
|
|
|
|
* accross slices.
|
|
|
|
|
*/
|
|
|
|
|
if (AddrDccOut->dccRamSizeAligned)
|
|
|
|
|
surf_level->dcc_slice_fast_clear_size = AddrDccOut->dccFastClearSize;
|
|
|
|
|
else
|
|
|
|
|
surf_level->dcc_slice_fast_clear_size = 0;
|
|
|
|
|
}
|
2020-05-24 12:50:55 +02:00
|
|
|
|
|
|
|
|
if (surf->flags & RADEON_SURF_CONTIGUOUS_DCC_LAYERS &&
|
|
|
|
|
surf->dcc_slice_size != surf_level->dcc_slice_fast_clear_size) {
|
|
|
|
|
surf->dcc_size = 0;
|
|
|
|
|
surf->num_dcc_levels = 0;
|
|
|
|
|
AddrDccOut->subLvlCompressible = false;
|
|
|
|
|
}
|
2019-07-01 16:30:56 +02:00
|
|
|
} else {
|
|
|
|
|
surf_level->dcc_slice_fast_clear_size = surf_level->dcc_fast_clear_size;
|
|
|
|
|
}
|
2017-05-10 20:21:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 21:07:41 -04:00
|
|
|
/* HTILE. */
|
2017-05-10 20:21:36 +02:00
|
|
|
if (!is_stencil &&
|
|
|
|
|
AddrSurfInfoIn->flags.depth &&
|
|
|
|
|
surf_level->mode == RADEON_SURF_MODE_2D &&
|
2019-08-27 21:07:41 -04:00
|
|
|
level == 0 &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_NO_HTILE)) {
|
2019-12-11 16:04:58 +01:00
|
|
|
AddrHtileIn->flags.tcCompatible = AddrSurfInfoOut->tcCompatible;
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrHtileIn->pitch = AddrSurfInfoOut->pitch;
|
|
|
|
|
AddrHtileIn->height = AddrSurfInfoOut->height;
|
|
|
|
|
AddrHtileIn->numSlices = AddrSurfInfoOut->depth;
|
|
|
|
|
AddrHtileIn->blockWidth = ADDR_HTILE_BLOCKSIZE_8;
|
|
|
|
|
AddrHtileIn->blockHeight = ADDR_HTILE_BLOCKSIZE_8;
|
|
|
|
|
AddrHtileIn->pTileInfo = AddrSurfInfoOut->pTileInfo;
|
|
|
|
|
AddrHtileIn->tileIndex = AddrSurfInfoOut->tileIndex;
|
|
|
|
|
AddrHtileIn->macroModeIndex = AddrSurfInfoOut->macroModeIndex;
|
|
|
|
|
|
|
|
|
|
ret = AddrComputeHtileInfo(addrlib,
|
|
|
|
|
AddrHtileIn,
|
|
|
|
|
AddrHtileOut);
|
|
|
|
|
|
|
|
|
|
if (ret == ADDR_OK) {
|
|
|
|
|
surf->htile_size = AddrHtileOut->htileBytes;
|
2017-05-10 22:52:27 +02:00
|
|
|
surf->htile_slice_size = AddrHtileOut->sliceSize;
|
2017-05-10 20:21:36 +02:00
|
|
|
surf->htile_alignment = AddrHtileOut->baseAlign;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gfx6_set_micro_tile_mode(struct radeon_surf *surf,
|
2017-05-12 01:24:48 +02:00
|
|
|
const struct radeon_info *info)
|
2017-05-10 20:21:36 +02:00
|
|
|
{
|
2017-05-12 01:24:48 +02:00
|
|
|
uint32_t tile_mode = info->si_tile_mode_array[surf->u.legacy.tiling_index[0]];
|
2017-05-10 20:21:36 +02:00
|
|
|
|
2019-05-14 22:16:20 -04:00
|
|
|
if (info->chip_class >= GFX7)
|
2017-05-10 20:21:36 +02:00
|
|
|
surf->micro_tile_mode = G_009910_MICRO_TILE_MODE_NEW(tile_mode);
|
|
|
|
|
else
|
|
|
|
|
surf->micro_tile_mode = G_009910_MICRO_TILE_MODE(tile_mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned cik_get_macro_tile_index(struct radeon_surf *surf)
|
|
|
|
|
{
|
|
|
|
|
unsigned index, tileb;
|
|
|
|
|
|
|
|
|
|
tileb = 8 * 8 * surf->bpe;
|
|
|
|
|
tileb = MIN2(surf->u.legacy.tile_split, tileb);
|
|
|
|
|
|
|
|
|
|
for (index = 0; tileb > 64; index++)
|
|
|
|
|
tileb >>= 1;
|
|
|
|
|
|
|
|
|
|
assert(index < 16);
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 12:51:14 -04:00
|
|
|
static bool get_display_flag(const struct ac_surf_config *config,
|
|
|
|
|
const struct radeon_surf *surf)
|
|
|
|
|
{
|
|
|
|
|
unsigned num_channels = config->info.num_channels;
|
|
|
|
|
unsigned bpe = surf->bpe;
|
|
|
|
|
|
2020-04-17 20:19:26 -04:00
|
|
|
if (!config->is_3d &&
|
|
|
|
|
!config->is_cube &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_Z_OR_SBUFFER) &&
|
2019-01-04 19:19:54 -05:00
|
|
|
surf->flags & RADEON_SURF_SCANOUT &&
|
2018-04-02 12:51:14 -04:00
|
|
|
config->info.samples <= 1 &&
|
|
|
|
|
surf->blk_w <= 2 && surf->blk_h == 1) {
|
|
|
|
|
/* subsampled */
|
|
|
|
|
if (surf->blk_w == 2 && surf->blk_h == 1)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (/* RGBA8 or RGBA16F */
|
|
|
|
|
(bpe >= 4 && bpe <= 8 && num_channels == 4) ||
|
|
|
|
|
/* R5G6B5 or R5G5B5A1 */
|
|
|
|
|
(bpe == 2 && num_channels >= 3) ||
|
|
|
|
|
/* C8 palette */
|
|
|
|
|
(bpe == 1 && num_channels == 1))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 16:38:27 +02:00
|
|
|
/**
|
2017-07-29 03:15:27 +02:00
|
|
|
* This must be called after the first level is computed.
|
|
|
|
|
*
|
2017-05-16 16:38:27 +02:00
|
|
|
* Copy surface-global settings like pipe/bank config from level 0 surface
|
2017-07-29 03:15:27 +02:00
|
|
|
* computation, and compute tile swizzle.
|
2017-05-16 16:38:27 +02:00
|
|
|
*/
|
2017-07-29 03:15:27 +02:00
|
|
|
static int gfx6_surface_settings(ADDR_HANDLE addrlib,
|
|
|
|
|
const struct radeon_info *info,
|
|
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
ADDR_COMPUTE_SURFACE_INFO_OUTPUT* csio,
|
|
|
|
|
struct radeon_surf *surf)
|
2017-05-16 16:38:27 +02:00
|
|
|
{
|
|
|
|
|
surf->surf_alignment = csio->baseAlign;
|
|
|
|
|
surf->u.legacy.pipe_config = csio->pTileInfo->pipeConfig - 1;
|
|
|
|
|
gfx6_set_micro_tile_mode(surf, info);
|
|
|
|
|
|
|
|
|
|
/* For 2D modes only. */
|
|
|
|
|
if (csio->tileMode >= ADDR_TM_2D_TILED_THIN1) {
|
|
|
|
|
surf->u.legacy.bankw = csio->pTileInfo->bankWidth;
|
|
|
|
|
surf->u.legacy.bankh = csio->pTileInfo->bankHeight;
|
|
|
|
|
surf->u.legacy.mtilea = csio->pTileInfo->macroAspectRatio;
|
|
|
|
|
surf->u.legacy.tile_split = csio->pTileInfo->tileSplitBytes;
|
|
|
|
|
surf->u.legacy.num_banks = csio->pTileInfo->banks;
|
|
|
|
|
surf->u.legacy.macro_tile_index = csio->macroModeIndex;
|
|
|
|
|
} else {
|
|
|
|
|
surf->u.legacy.macro_tile_index = 0;
|
|
|
|
|
}
|
2017-07-29 03:15:27 +02:00
|
|
|
|
|
|
|
|
/* Compute tile swizzle. */
|
2019-05-14 22:16:20 -04:00
|
|
|
/* TODO: fix tile swizzle with mipmapping for GFX6 */
|
|
|
|
|
if ((info->chip_class >= GFX7 || config->info.levels == 1) &&
|
2017-08-01 00:12:30 +02:00
|
|
|
config->info.surf_index &&
|
2017-07-29 03:15:27 +02:00
|
|
|
surf->u.legacy.level[0].mode == RADEON_SURF_MODE_2D &&
|
|
|
|
|
!(surf->flags & (RADEON_SURF_Z_OR_SBUFFER | RADEON_SURF_SHAREABLE)) &&
|
2018-04-02 12:51:14 -04:00
|
|
|
!get_display_flag(config, surf)) {
|
2017-07-29 03:15:27 +02:00
|
|
|
ADDR_COMPUTE_BASE_SWIZZLE_INPUT AddrBaseSwizzleIn = {0};
|
|
|
|
|
ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT AddrBaseSwizzleOut = {0};
|
|
|
|
|
|
|
|
|
|
AddrBaseSwizzleIn.size = sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT);
|
|
|
|
|
AddrBaseSwizzleOut.size = sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT);
|
|
|
|
|
|
|
|
|
|
AddrBaseSwizzleIn.surfIndex = p_atomic_inc_return(config->info.surf_index) - 1;
|
|
|
|
|
AddrBaseSwizzleIn.tileIndex = csio->tileIndex;
|
|
|
|
|
AddrBaseSwizzleIn.macroModeIndex = csio->macroModeIndex;
|
|
|
|
|
AddrBaseSwizzleIn.pTileInfo = csio->pTileInfo;
|
|
|
|
|
AddrBaseSwizzleIn.tileMode = csio->tileMode;
|
|
|
|
|
|
|
|
|
|
int r = AddrComputeBaseSwizzle(addrlib, &AddrBaseSwizzleIn,
|
|
|
|
|
&AddrBaseSwizzleOut);
|
|
|
|
|
if (r != ADDR_OK)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
assert(AddrBaseSwizzleOut.tileSwizzle <=
|
|
|
|
|
u_bit_consecutive(0, sizeof(surf->tile_swizzle) * 8));
|
|
|
|
|
surf->tile_swizzle = AddrBaseSwizzleOut.tileSwizzle;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2017-05-16 16:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 17:17:23 +02:00
|
|
|
static void ac_compute_cmask(const struct radeon_info *info,
|
|
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
struct radeon_surf *surf)
|
2018-06-21 22:54:59 -04:00
|
|
|
{
|
|
|
|
|
unsigned pipe_interleave_bytes = info->pipe_interleave_bytes;
|
|
|
|
|
unsigned num_pipes = info->num_tile_pipes;
|
|
|
|
|
unsigned cl_width, cl_height;
|
|
|
|
|
|
2020-05-24 13:25:53 +02:00
|
|
|
if (surf->flags & RADEON_SURF_Z_OR_SBUFFER || surf->is_linear ||
|
2019-08-27 20:29:11 -04:00
|
|
|
(config->info.samples >= 2 && !surf->fmask_size))
|
2018-06-21 22:54:59 -04:00
|
|
|
return;
|
|
|
|
|
|
2019-05-14 22:16:20 -04:00
|
|
|
assert(info->chip_class <= GFX8);
|
2018-06-21 22:54:59 -04:00
|
|
|
|
|
|
|
|
switch (num_pipes) {
|
|
|
|
|
case 2:
|
|
|
|
|
cl_width = 32;
|
|
|
|
|
cl_height = 16;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
cl_width = 32;
|
|
|
|
|
cl_height = 32;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
cl_width = 64;
|
|
|
|
|
cl_height = 32;
|
|
|
|
|
break;
|
|
|
|
|
case 16: /* Hawaii */
|
|
|
|
|
cl_width = 64;
|
|
|
|
|
cl_height = 64;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned base_align = num_pipes * pipe_interleave_bytes;
|
|
|
|
|
|
2018-08-28 14:39:09 -04:00
|
|
|
unsigned width = align(surf->u.legacy.level[0].nblk_x, cl_width*8);
|
|
|
|
|
unsigned height = align(surf->u.legacy.level[0].nblk_y, cl_height*8);
|
2018-06-21 22:54:59 -04:00
|
|
|
unsigned slice_elements = (width * height) / (8*8);
|
|
|
|
|
|
|
|
|
|
/* Each element of CMASK is a nibble. */
|
|
|
|
|
unsigned slice_bytes = slice_elements / 2;
|
|
|
|
|
|
|
|
|
|
surf->u.legacy.cmask_slice_tile_max = (width * height) / (128*128);
|
|
|
|
|
if (surf->u.legacy.cmask_slice_tile_max)
|
|
|
|
|
surf->u.legacy.cmask_slice_tile_max -= 1;
|
|
|
|
|
|
|
|
|
|
unsigned num_layers;
|
|
|
|
|
if (config->is_3d)
|
|
|
|
|
num_layers = config->info.depth;
|
|
|
|
|
else if (config->is_cube)
|
|
|
|
|
num_layers = 6;
|
|
|
|
|
else
|
|
|
|
|
num_layers = config->info.array_size;
|
|
|
|
|
|
|
|
|
|
surf->cmask_alignment = MAX2(256, base_align);
|
2019-06-24 18:40:29 +02:00
|
|
|
surf->cmask_slice_size = align(slice_bytes, base_align);
|
|
|
|
|
surf->cmask_size = surf->cmask_slice_size * num_layers;
|
2018-06-21 22:54:59 -04:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
/**
|
|
|
|
|
* Fill in the tiling information in \p surf based on the given surface config.
|
|
|
|
|
*
|
|
|
|
|
* The following fields of \p surf must be initialized by the caller:
|
|
|
|
|
* blk_w, blk_h, bpe, flags.
|
|
|
|
|
*/
|
2017-05-10 20:40:14 +02:00
|
|
|
static int gfx6_compute_surface(ADDR_HANDLE addrlib,
|
2017-05-12 01:24:48 +02:00
|
|
|
const struct radeon_info *info,
|
2017-05-10 20:40:14 +02:00
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
enum radeon_surf_mode mode,
|
|
|
|
|
struct radeon_surf *surf)
|
2017-05-10 20:21:36 +02:00
|
|
|
{
|
|
|
|
|
unsigned level;
|
|
|
|
|
bool compressed;
|
|
|
|
|
ADDR_COMPUTE_SURFACE_INFO_INPUT AddrSurfInfoIn = {0};
|
|
|
|
|
ADDR_COMPUTE_SURFACE_INFO_OUTPUT AddrSurfInfoOut = {0};
|
|
|
|
|
ADDR_COMPUTE_DCCINFO_INPUT AddrDccIn = {0};
|
|
|
|
|
ADDR_COMPUTE_DCCINFO_OUTPUT AddrDccOut = {0};
|
|
|
|
|
ADDR_COMPUTE_HTILE_INFO_INPUT AddrHtileIn = {0};
|
|
|
|
|
ADDR_COMPUTE_HTILE_INFO_OUTPUT AddrHtileOut = {0};
|
|
|
|
|
ADDR_TILEINFO AddrTileInfoIn = {0};
|
|
|
|
|
ADDR_TILEINFO AddrTileInfoOut = {0};
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.size = sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT);
|
|
|
|
|
AddrSurfInfoOut.size = sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT);
|
|
|
|
|
AddrDccIn.size = sizeof(ADDR_COMPUTE_DCCINFO_INPUT);
|
|
|
|
|
AddrDccOut.size = sizeof(ADDR_COMPUTE_DCCINFO_OUTPUT);
|
|
|
|
|
AddrHtileIn.size = sizeof(ADDR_COMPUTE_HTILE_INFO_INPUT);
|
|
|
|
|
AddrHtileOut.size = sizeof(ADDR_COMPUTE_HTILE_INFO_OUTPUT);
|
|
|
|
|
AddrSurfInfoOut.pTileInfo = &AddrTileInfoOut;
|
|
|
|
|
|
|
|
|
|
compressed = surf->blk_w == 4 && surf->blk_h == 4;
|
|
|
|
|
|
2018-04-30 20:54:06 -04:00
|
|
|
/* MSAA requires 2D tiling. */
|
|
|
|
|
if (config->info.samples > 1)
|
2017-05-10 20:21:36 +02:00
|
|
|
mode = RADEON_SURF_MODE_2D;
|
|
|
|
|
|
|
|
|
|
/* DB doesn't support linear layouts. */
|
|
|
|
|
if (surf->flags & (RADEON_SURF_Z_OR_SBUFFER) &&
|
|
|
|
|
mode < RADEON_SURF_MODE_1D)
|
|
|
|
|
mode = RADEON_SURF_MODE_1D;
|
|
|
|
|
|
|
|
|
|
/* Set the requested tiling mode. */
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case RADEON_SURF_MODE_LINEAR_ALIGNED:
|
|
|
|
|
AddrSurfInfoIn.tileMode = ADDR_TM_LINEAR_ALIGNED;
|
|
|
|
|
break;
|
|
|
|
|
case RADEON_SURF_MODE_1D:
|
|
|
|
|
AddrSurfInfoIn.tileMode = ADDR_TM_1D_TILED_THIN1;
|
|
|
|
|
break;
|
|
|
|
|
case RADEON_SURF_MODE_2D:
|
|
|
|
|
AddrSurfInfoIn.tileMode = ADDR_TM_2D_TILED_THIN1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The format must be set correctly for the allocation of compressed
|
|
|
|
|
* textures to work. In other cases, setting the bpp is sufficient.
|
|
|
|
|
*/
|
|
|
|
|
if (compressed) {
|
|
|
|
|
switch (surf->bpe) {
|
|
|
|
|
case 8:
|
|
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_BC1;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_BC3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
AddrDccIn.bpp = AddrSurfInfoIn.bpp = surf->bpe * 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddrDccIn.numSamples = AddrSurfInfoIn.numSamples =
|
2018-04-30 22:29:14 -04:00
|
|
|
MAX2(1, config->info.samples);
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrSurfInfoIn.tileIndex = -1;
|
|
|
|
|
|
2018-04-30 22:29:14 -04:00
|
|
|
if (!(surf->flags & RADEON_SURF_Z_OR_SBUFFER)) {
|
|
|
|
|
AddrDccIn.numSamples = AddrSurfInfoIn.numFrags =
|
2018-05-23 22:42:49 -04:00
|
|
|
MAX2(1, config->info.storage_samples);
|
2018-04-30 22:29:14 -04:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
/* Set the micro tile type. */
|
|
|
|
|
if (surf->flags & RADEON_SURF_SCANOUT)
|
|
|
|
|
AddrSurfInfoIn.tileType = ADDR_DISPLAYABLE;
|
2018-04-30 20:54:06 -04:00
|
|
|
else if (surf->flags & RADEON_SURF_Z_OR_SBUFFER)
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrSurfInfoIn.tileType = ADDR_DEPTH_SAMPLE_ORDER;
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.tileType = ADDR_NON_DISPLAYABLE;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.flags.color = !(surf->flags & RADEON_SURF_Z_OR_SBUFFER);
|
|
|
|
|
AddrSurfInfoIn.flags.depth = (surf->flags & RADEON_SURF_ZBUFFER) != 0;
|
|
|
|
|
AddrSurfInfoIn.flags.cube = config->is_cube;
|
2018-04-02 12:51:14 -04:00
|
|
|
AddrSurfInfoIn.flags.display = get_display_flag(config, surf);
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrSurfInfoIn.flags.pow2Pad = config->info.levels > 1;
|
2020-05-02 16:01:44 -04:00
|
|
|
AddrSurfInfoIn.flags.tcCompatible = (surf->flags & RADEON_SURF_TC_COMPATIBLE_HTILE) != 0;
|
2017-05-10 20:21:36 +02:00
|
|
|
|
|
|
|
|
/* Only degrade the tile mode for space if TC-compatible HTILE hasn't been
|
|
|
|
|
* requested, because TC-compatible HTILE requires 2D tiling.
|
|
|
|
|
*/
|
|
|
|
|
AddrSurfInfoIn.flags.opt4Space = !AddrSurfInfoIn.flags.tcCompatible &&
|
|
|
|
|
!AddrSurfInfoIn.flags.fmask &&
|
|
|
|
|
config->info.samples <= 1 &&
|
2020-04-23 01:00:24 -04:00
|
|
|
!(surf->flags & RADEON_SURF_FORCE_SWIZZLE_MODE);
|
2017-05-10 20:21:36 +02:00
|
|
|
|
|
|
|
|
/* DCC notes:
|
|
|
|
|
* - If we add MSAA support, keep in mind that CB can't decompress 8bpp
|
|
|
|
|
* with samples >= 4.
|
|
|
|
|
* - Mipmapped array textures have low performance (discovered by a closed
|
|
|
|
|
* driver team).
|
|
|
|
|
*/
|
|
|
|
|
AddrSurfInfoIn.flags.dccCompatible =
|
2019-05-14 22:16:20 -04:00
|
|
|
info->chip_class >= GFX8 &&
|
2019-02-07 00:04:32 -05:00
|
|
|
info->has_graphics && /* disable DCC on compute-only chips */
|
2017-05-10 20:21:36 +02:00
|
|
|
!(surf->flags & RADEON_SURF_Z_OR_SBUFFER) &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_DISABLE_DCC) &&
|
2017-11-23 22:29:26 +01:00
|
|
|
!compressed &&
|
2017-05-10 20:21:36 +02:00
|
|
|
((config->info.array_size == 1 && config->info.depth == 1) ||
|
|
|
|
|
config->info.levels == 1);
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.flags.noStencil = (surf->flags & RADEON_SURF_SBUFFER) == 0;
|
2018-06-18 16:29:16 +02:00
|
|
|
AddrSurfInfoIn.flags.compressZ = !!(surf->flags & RADEON_SURF_Z_OR_SBUFFER);
|
2017-05-10 20:21:36 +02:00
|
|
|
|
2019-05-14 22:16:20 -04:00
|
|
|
/* On GFX7-GFX8, the DB uses the same pitch and tile mode (except tilesplit)
|
2017-09-05 16:16:29 +02:00
|
|
|
* for Z and stencil. This can cause a number of problems which we work
|
|
|
|
|
* around here:
|
2017-05-10 20:21:36 +02:00
|
|
|
*
|
2017-09-05 16:16:29 +02:00
|
|
|
* - a depth part that is incompatible with mipmapped texturing
|
|
|
|
|
* - at least on Stoney, entirely incompatible Z/S aspects (e.g.
|
|
|
|
|
* incorrect tiling applied to the stencil part, stencil buffer
|
|
|
|
|
* memory accesses that go out of bounds) even without mipmapping
|
|
|
|
|
*
|
|
|
|
|
* Some piglit tests that are prone to different types of related
|
|
|
|
|
* failures:
|
|
|
|
|
* ./bin/ext_framebuffer_multisample-upsample 2 stencil
|
|
|
|
|
* ./bin/framebuffer-blit-levels {draw,read} stencil
|
|
|
|
|
* ./bin/ext_framebuffer_multisample-unaligned-blit N {depth,stencil} {msaa,upsample,downsample}
|
|
|
|
|
* ./bin/fbo-depth-array fs-writes-{depth,stencil} / {depth,stencil}-{clear,layered-clear,draw}
|
|
|
|
|
* ./bin/depthstencil-render-miplevels 1024 d=s=z24_s8
|
2017-05-10 20:21:36 +02:00
|
|
|
*/
|
2017-09-05 16:16:29 +02:00
|
|
|
int stencil_tile_idx = -1;
|
|
|
|
|
|
|
|
|
|
if (AddrSurfInfoIn.flags.depth && !AddrSurfInfoIn.flags.noStencil &&
|
|
|
|
|
(config->info.levels > 1 || info->family == CHIP_STONEY)) {
|
|
|
|
|
/* Compute stencilTileIdx that is compatible with the (depth)
|
|
|
|
|
* tileIdx. This degrades the depth surface if necessary to
|
|
|
|
|
* ensure that a matching stencilTileIdx exists. */
|
|
|
|
|
AddrSurfInfoIn.flags.matchStencilTileCfg = 1;
|
|
|
|
|
|
|
|
|
|
/* Keep the depth mip-tail compatible with texturing. */
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrSurfInfoIn.flags.noStencil = 1;
|
2017-09-05 16:16:29 +02:00
|
|
|
}
|
2017-05-10 20:21:36 +02:00
|
|
|
|
|
|
|
|
/* Set preferred macrotile parameters. This is usually required
|
|
|
|
|
* for shared resources. This is for 2D tiling only. */
|
|
|
|
|
if (AddrSurfInfoIn.tileMode >= ADDR_TM_2D_TILED_THIN1 &&
|
|
|
|
|
surf->u.legacy.bankw && surf->u.legacy.bankh &&
|
|
|
|
|
surf->u.legacy.mtilea && surf->u.legacy.tile_split) {
|
|
|
|
|
/* If any of these parameters are incorrect, the calculation
|
|
|
|
|
* will fail. */
|
|
|
|
|
AddrTileInfoIn.banks = surf->u.legacy.num_banks;
|
|
|
|
|
AddrTileInfoIn.bankWidth = surf->u.legacy.bankw;
|
|
|
|
|
AddrTileInfoIn.bankHeight = surf->u.legacy.bankh;
|
|
|
|
|
AddrTileInfoIn.macroAspectRatio = surf->u.legacy.mtilea;
|
|
|
|
|
AddrTileInfoIn.tileSplitBytes = surf->u.legacy.tile_split;
|
|
|
|
|
AddrTileInfoIn.pipeConfig = surf->u.legacy.pipe_config + 1; /* +1 compared to GB_TILE_MODE */
|
|
|
|
|
AddrSurfInfoIn.flags.opt4Space = 0;
|
|
|
|
|
AddrSurfInfoIn.pTileInfo = &AddrTileInfoIn;
|
|
|
|
|
|
|
|
|
|
/* If AddrSurfInfoIn.pTileInfo is set, Addrlib doesn't set
|
|
|
|
|
* the tile index, because we are expected to know it if
|
|
|
|
|
* we know the other parameters.
|
|
|
|
|
*
|
|
|
|
|
* This is something that can easily be fixed in Addrlib.
|
|
|
|
|
* For now, just figure it out here.
|
|
|
|
|
* Note that only 2D_TILE_THIN1 is handled here.
|
|
|
|
|
*/
|
|
|
|
|
assert(!(surf->flags & RADEON_SURF_Z_OR_SBUFFER));
|
|
|
|
|
assert(AddrSurfInfoIn.tileMode == ADDR_TM_2D_TILED_THIN1);
|
|
|
|
|
|
2019-05-14 22:16:20 -04:00
|
|
|
if (info->chip_class == GFX6) {
|
2017-05-10 20:21:36 +02:00
|
|
|
if (AddrSurfInfoIn.tileType == ADDR_DISPLAYABLE) {
|
|
|
|
|
if (surf->bpe == 2)
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 11; /* 16bpp */
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 12; /* 32bpp */
|
|
|
|
|
} else {
|
|
|
|
|
if (surf->bpe == 1)
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 14; /* 8bpp */
|
|
|
|
|
else if (surf->bpe == 2)
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 15; /* 16bpp */
|
|
|
|
|
else if (surf->bpe == 4)
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 16; /* 32bpp */
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 17; /* 64bpp (and 128bpp) */
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-05-14 22:16:20 -04:00
|
|
|
/* GFX7 - GFX8 */
|
2017-05-10 20:21:36 +02:00
|
|
|
if (AddrSurfInfoIn.tileType == ADDR_DISPLAYABLE)
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 10; /* 2D displayable */
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.tileIndex = 14; /* 2D non-displayable */
|
|
|
|
|
|
|
|
|
|
/* Addrlib doesn't set this if tileIndex is forced like above. */
|
|
|
|
|
AddrSurfInfoOut.macroModeIndex = cik_get_macro_tile_index(surf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 00:13:37 +02:00
|
|
|
surf->has_stencil = !!(surf->flags & RADEON_SURF_SBUFFER);
|
2017-05-10 20:21:36 +02:00
|
|
|
surf->num_dcc_levels = 0;
|
|
|
|
|
surf->surf_size = 0;
|
|
|
|
|
surf->dcc_size = 0;
|
|
|
|
|
surf->dcc_alignment = 1;
|
|
|
|
|
surf->htile_size = 0;
|
2017-05-10 22:52:27 +02:00
|
|
|
surf->htile_slice_size = 0;
|
2017-05-10 20:21:36 +02:00
|
|
|
surf->htile_alignment = 1;
|
|
|
|
|
|
2017-05-16 16:38:27 +02:00
|
|
|
const bool only_stencil = (surf->flags & RADEON_SURF_SBUFFER) &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_ZBUFFER);
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
/* Calculate texture layout information. */
|
2017-05-16 16:38:27 +02:00
|
|
|
if (!only_stencil) {
|
|
|
|
|
for (level = 0; level < config->info.levels; level++) {
|
|
|
|
|
r = gfx6_compute_level(addrlib, config, surf, false, level, compressed,
|
|
|
|
|
&AddrSurfInfoIn, &AddrSurfInfoOut,
|
|
|
|
|
&AddrDccIn, &AddrDccOut, &AddrHtileIn, &AddrHtileOut);
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
if (level > 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-05-02 16:01:44 -04:00
|
|
|
if (!AddrSurfInfoOut.tcCompatible) {
|
2019-12-12 12:10:58 +01:00
|
|
|
AddrSurfInfoIn.flags.tcCompatible = 0;
|
2020-05-02 16:01:44 -04:00
|
|
|
surf->flags &= ~RADEON_SURF_TC_COMPATIBLE_HTILE;
|
|
|
|
|
}
|
2017-09-05 16:16:29 +02:00
|
|
|
|
|
|
|
|
if (AddrSurfInfoIn.flags.matchStencilTileCfg) {
|
|
|
|
|
AddrSurfInfoIn.flags.matchStencilTileCfg = 0;
|
|
|
|
|
AddrSurfInfoIn.tileIndex = AddrSurfInfoOut.tileIndex;
|
|
|
|
|
stencil_tile_idx = AddrSurfInfoOut.stencilTileIdx;
|
|
|
|
|
|
|
|
|
|
assert(stencil_tile_idx >= 0);
|
|
|
|
|
}
|
2017-09-07 13:20:25 +02:00
|
|
|
|
2017-07-29 03:15:27 +02:00
|
|
|
r = gfx6_surface_settings(addrlib, info, config,
|
|
|
|
|
&AddrSurfInfoOut, surf);
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
2017-05-10 20:21:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Calculate texture layout information for stencil. */
|
|
|
|
|
if (surf->flags & RADEON_SURF_SBUFFER) {
|
2017-09-05 16:16:29 +02:00
|
|
|
AddrSurfInfoIn.tileIndex = stencil_tile_idx;
|
2017-05-10 20:21:36 +02:00
|
|
|
AddrSurfInfoIn.bpp = 8;
|
|
|
|
|
AddrSurfInfoIn.flags.depth = 0;
|
|
|
|
|
AddrSurfInfoIn.flags.stencil = 1;
|
|
|
|
|
AddrSurfInfoIn.flags.tcCompatible = 0;
|
|
|
|
|
/* This will be ignored if AddrSurfInfoIn.pTileInfo is NULL. */
|
|
|
|
|
AddrTileInfoIn.tileSplitBytes = surf->u.legacy.stencil_tile_split;
|
|
|
|
|
|
|
|
|
|
for (level = 0; level < config->info.levels; level++) {
|
|
|
|
|
r = gfx6_compute_level(addrlib, config, surf, true, level, compressed,
|
|
|
|
|
&AddrSurfInfoIn, &AddrSurfInfoOut,
|
|
|
|
|
&AddrDccIn, &AddrDccOut,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
/* DB uses the depth pitch for both stencil and depth. */
|
2017-05-16 16:38:27 +02:00
|
|
|
if (!only_stencil) {
|
|
|
|
|
if (surf->u.legacy.stencil_level[level].nblk_x !=
|
|
|
|
|
surf->u.legacy.level[level].nblk_x)
|
|
|
|
|
surf->u.legacy.stencil_adjusted = true;
|
|
|
|
|
} else {
|
|
|
|
|
surf->u.legacy.level[level].nblk_x =
|
|
|
|
|
surf->u.legacy.stencil_level[level].nblk_x;
|
|
|
|
|
}
|
2017-05-10 20:21:36 +02:00
|
|
|
|
|
|
|
|
if (level == 0) {
|
2017-07-29 03:15:27 +02:00
|
|
|
if (only_stencil) {
|
|
|
|
|
r = gfx6_surface_settings(addrlib, info, config,
|
|
|
|
|
&AddrSurfInfoOut, surf);
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2017-05-16 16:38:27 +02:00
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
/* For 2D modes only. */
|
|
|
|
|
if (AddrSurfInfoOut.tileMode >= ADDR_TM_2D_TILED_THIN1) {
|
|
|
|
|
surf->u.legacy.stencil_tile_split =
|
|
|
|
|
AddrSurfInfoOut.pTileInfo->tileSplitBytes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 20:54:06 -04:00
|
|
|
/* Compute FMASK. */
|
2019-08-27 20:29:11 -04:00
|
|
|
if (config->info.samples >= 2 && AddrSurfInfoIn.flags.color &&
|
2019-09-13 18:27:46 -04:00
|
|
|
info->has_graphics && !(surf->flags & RADEON_SURF_NO_FMASK)) {
|
2018-04-30 20:54:06 -04:00
|
|
|
ADDR_COMPUTE_FMASK_INFO_INPUT fin = {0};
|
|
|
|
|
ADDR_COMPUTE_FMASK_INFO_OUTPUT fout = {0};
|
|
|
|
|
ADDR_TILEINFO fmask_tile_info = {};
|
|
|
|
|
|
|
|
|
|
fin.size = sizeof(fin);
|
|
|
|
|
fout.size = sizeof(fout);
|
|
|
|
|
|
|
|
|
|
fin.tileMode = AddrSurfInfoOut.tileMode;
|
|
|
|
|
fin.pitch = AddrSurfInfoOut.pitch;
|
|
|
|
|
fin.height = config->info.height;
|
|
|
|
|
fin.numSlices = AddrSurfInfoIn.numSlices;
|
|
|
|
|
fin.numSamples = AddrSurfInfoIn.numSamples;
|
|
|
|
|
fin.numFrags = AddrSurfInfoIn.numFrags;
|
2018-05-21 15:43:19 +02:00
|
|
|
fin.tileIndex = -1;
|
2018-04-30 20:54:06 -04:00
|
|
|
fout.pTileInfo = &fmask_tile_info;
|
|
|
|
|
|
|
|
|
|
r = AddrComputeFmaskInfo(addrlib, &fin, &fout);
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
|
2018-04-30 22:35:51 -04:00
|
|
|
surf->fmask_size = fout.fmaskBytes;
|
|
|
|
|
surf->fmask_alignment = fout.baseAlign;
|
|
|
|
|
surf->fmask_tile_swizzle = 0;
|
2018-04-30 20:54:06 -04:00
|
|
|
|
|
|
|
|
surf->u.legacy.fmask.slice_tile_max =
|
|
|
|
|
(fout.pitch * fout.height) / 64;
|
|
|
|
|
if (surf->u.legacy.fmask.slice_tile_max)
|
|
|
|
|
surf->u.legacy.fmask.slice_tile_max -= 1;
|
|
|
|
|
|
|
|
|
|
surf->u.legacy.fmask.tiling_index = fout.tileIndex;
|
|
|
|
|
surf->u.legacy.fmask.bankh = fout.pTileInfo->bankHeight;
|
|
|
|
|
surf->u.legacy.fmask.pitch_in_pixels = fout.pitch;
|
2019-06-24 12:18:01 +02:00
|
|
|
surf->u.legacy.fmask.slice_size = fout.sliceSize;
|
2018-04-30 20:54:06 -04:00
|
|
|
|
|
|
|
|
/* Compute tile swizzle for FMASK. */
|
|
|
|
|
if (config->info.fmask_surf_index &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_SHAREABLE)) {
|
|
|
|
|
ADDR_COMPUTE_BASE_SWIZZLE_INPUT xin = {0};
|
|
|
|
|
ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT xout = {0};
|
|
|
|
|
|
|
|
|
|
xin.size = sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT);
|
|
|
|
|
xout.size = sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT);
|
|
|
|
|
|
|
|
|
|
/* This counter starts from 1 instead of 0. */
|
|
|
|
|
xin.surfIndex = p_atomic_inc_return(config->info.fmask_surf_index);
|
|
|
|
|
xin.tileIndex = fout.tileIndex;
|
|
|
|
|
xin.macroModeIndex = fout.macroModeIndex;
|
|
|
|
|
xin.pTileInfo = fout.pTileInfo;
|
|
|
|
|
xin.tileMode = fin.tileMode;
|
|
|
|
|
|
|
|
|
|
int r = AddrComputeBaseSwizzle(addrlib, &xin, &xout);
|
|
|
|
|
if (r != ADDR_OK)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
assert(xout.tileSwizzle <=
|
|
|
|
|
u_bit_consecutive(0, sizeof(surf->tile_swizzle) * 8));
|
2018-04-30 22:35:51 -04:00
|
|
|
surf->fmask_tile_swizzle = xout.tileSwizzle;
|
2018-04-30 20:54:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:21:36 +02:00
|
|
|
/* Recalculate the whole DCC miptree size including disabled levels.
|
|
|
|
|
* This is what addrlib does, but calling addrlib would be a lot more
|
|
|
|
|
* complicated.
|
|
|
|
|
*/
|
|
|
|
|
if (surf->dcc_size && config->info.levels > 1) {
|
2017-07-29 17:19:01 +02:00
|
|
|
/* The smallest miplevels that are never compressed by DCC
|
|
|
|
|
* still read the DCC buffer via TC if the base level uses DCC,
|
|
|
|
|
* and for some reason the DCC buffer needs to be larger if
|
|
|
|
|
* the miptree uses non-zero tile_swizzle. Otherwise there are
|
|
|
|
|
* VM faults.
|
|
|
|
|
*
|
|
|
|
|
* "dcc_alignment * 4" was determined by trial and error.
|
|
|
|
|
*/
|
2017-05-10 20:21:36 +02:00
|
|
|
surf->dcc_size = align64(surf->surf_size >> 8,
|
2017-07-29 17:19:01 +02:00
|
|
|
surf->dcc_alignment * 4);
|
2017-05-10 20:21:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make sure HTILE covers the whole miptree, because the shader reads
|
|
|
|
|
* TC-compatible HTILE even for levels where it's disabled by DB.
|
|
|
|
|
*/
|
2018-05-01 14:34:19 -04:00
|
|
|
if (surf->htile_size && config->info.levels > 1 &&
|
2020-05-02 16:01:44 -04:00
|
|
|
surf->flags & RADEON_SURF_TC_COMPATIBLE_HTILE) {
|
2018-05-01 14:34:19 -04:00
|
|
|
/* MSAA can't occur with levels > 1, so ignore the sample count. */
|
|
|
|
|
const unsigned total_pixels = surf->surf_size / surf->bpe;
|
|
|
|
|
const unsigned htile_block_size = 8 * 8;
|
|
|
|
|
const unsigned htile_element_size = 4;
|
|
|
|
|
|
|
|
|
|
surf->htile_size = (total_pixels / htile_block_size) *
|
|
|
|
|
htile_element_size;
|
|
|
|
|
surf->htile_size = align(surf->htile_size, surf->htile_alignment);
|
2020-05-02 16:19:00 -04:00
|
|
|
} else if (!surf->htile_size) {
|
|
|
|
|
/* Unset this if HTILE is not present. */
|
|
|
|
|
surf->flags &= ~RADEON_SURF_TC_COMPATIBLE_HTILE;
|
2018-05-01 14:34:19 -04:00
|
|
|
}
|
2017-05-10 20:21:36 +02:00
|
|
|
|
|
|
|
|
surf->is_linear = surf->u.legacy.level[0].mode == RADEON_SURF_MODE_LINEAR_ALIGNED;
|
2020-06-11 04:20:44 -04:00
|
|
|
surf->is_displayable = (surf->is_linear ||
|
|
|
|
|
surf->micro_tile_mode == RADEON_MICRO_MODE_DISPLAY ||
|
|
|
|
|
surf->micro_tile_mode == RADEON_MICRO_MODE_RENDER /* rotated */) &&
|
|
|
|
|
!surf->dcc_size;
|
2018-06-20 20:00:59 -04:00
|
|
|
|
|
|
|
|
/* The rotated micro tile mode doesn't work if both CMASK and RB+ are
|
|
|
|
|
* used at the same time. This case is not currently expected to occur
|
|
|
|
|
* because we don't use rotated. Enforce this restriction on all chips
|
|
|
|
|
* to facilitate testing.
|
|
|
|
|
*/
|
2020-04-23 00:31:36 -04:00
|
|
|
if (surf->micro_tile_mode == RADEON_MICRO_MODE_RENDER) {
|
2018-06-20 20:00:59 -04:00
|
|
|
assert(!"rotate micro tile mode is unsupported");
|
|
|
|
|
return ADDR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 22:54:59 -04:00
|
|
|
ac_compute_cmask(info, config, surf);
|
2017-05-10 20:21:36 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
/* This is only called when expecting a tiled layout. */
|
|
|
|
|
static int
|
|
|
|
|
gfx9_get_preferred_swizzle_mode(ADDR_HANDLE addrlib,
|
2020-01-07 23:53:26 -05:00
|
|
|
struct radeon_surf *surf,
|
2017-05-10 20:36:03 +02:00
|
|
|
ADDR2_COMPUTE_SURFACE_INFO_INPUT *in,
|
2018-06-28 20:55:38 +02:00
|
|
|
bool is_fmask, AddrSwizzleMode *swizzle_mode)
|
2017-05-10 20:36:03 +02:00
|
|
|
{
|
|
|
|
|
ADDR_E_RETURNCODE ret;
|
|
|
|
|
ADDR2_GET_PREFERRED_SURF_SETTING_INPUT sin = {0};
|
|
|
|
|
ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT sout = {0};
|
|
|
|
|
|
|
|
|
|
sin.size = sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_INPUT);
|
|
|
|
|
sout.size = sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT);
|
|
|
|
|
|
|
|
|
|
sin.flags = in->flags;
|
|
|
|
|
sin.resourceType = in->resourceType;
|
|
|
|
|
sin.format = in->format;
|
|
|
|
|
sin.resourceLoction = ADDR_RSRC_LOC_INVIS;
|
|
|
|
|
/* TODO: We could allow some of these: */
|
|
|
|
|
sin.forbiddenBlock.micro = 1; /* don't allow the 256B swizzle modes */
|
|
|
|
|
sin.forbiddenBlock.var = 1; /* don't allow the variable-sized swizzle modes */
|
|
|
|
|
sin.bpp = in->bpp;
|
|
|
|
|
sin.width = in->width;
|
|
|
|
|
sin.height = in->height;
|
|
|
|
|
sin.numSlices = in->numSlices;
|
|
|
|
|
sin.numMipLevels = in->numMipLevels;
|
|
|
|
|
sin.numSamples = in->numSamples;
|
|
|
|
|
sin.numFrags = in->numFrags;
|
|
|
|
|
|
|
|
|
|
if (is_fmask) {
|
2018-04-02 12:51:14 -04:00
|
|
|
sin.flags.display = 0;
|
2017-05-10 20:36:03 +02:00
|
|
|
sin.flags.color = 0;
|
|
|
|
|
sin.flags.fmask = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 23:53:26 -05:00
|
|
|
if (surf->flags & RADEON_SURF_FORCE_MICRO_TILE_MODE) {
|
|
|
|
|
sin.forbiddenBlock.linear = 1;
|
|
|
|
|
|
|
|
|
|
if (surf->micro_tile_mode == RADEON_MICRO_MODE_DISPLAY)
|
|
|
|
|
sin.preferredSwSet.sw_D = 1;
|
2020-04-23 00:31:36 -04:00
|
|
|
else if (surf->micro_tile_mode == RADEON_MICRO_MODE_STANDARD)
|
2020-01-07 23:53:26 -05:00
|
|
|
sin.preferredSwSet.sw_S = 1;
|
|
|
|
|
else if (surf->micro_tile_mode == RADEON_MICRO_MODE_DEPTH)
|
|
|
|
|
sin.preferredSwSet.sw_Z = 1;
|
2020-04-23 00:31:36 -04:00
|
|
|
else if (surf->micro_tile_mode == RADEON_MICRO_MODE_RENDER)
|
2020-01-07 23:53:26 -05:00
|
|
|
sin.preferredSwSet.sw_R = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
ret = Addr2GetPreferredSurfaceSetting(addrlib, &sin, &sout);
|
|
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
*swizzle_mode = sout.swizzleMode;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 20:27:32 -04:00
|
|
|
static bool is_dcc_supported_by_CB(const struct radeon_info *info, unsigned sw_mode)
|
2018-06-28 20:53:51 +02:00
|
|
|
{
|
|
|
|
|
if (info->chip_class >= GFX10)
|
|
|
|
|
return sw_mode == ADDR_SW_64KB_Z_X || sw_mode == ADDR_SW_64KB_R_X;
|
|
|
|
|
|
|
|
|
|
return sw_mode != ADDR_SW_LINEAR;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 20:44:14 -04:00
|
|
|
ASSERTED static bool is_dcc_supported_by_L2(const struct radeon_info *info,
|
|
|
|
|
const struct radeon_surf *surf)
|
|
|
|
|
{
|
|
|
|
|
if (info->chip_class <= GFX9) {
|
|
|
|
|
/* Only independent 64B blocks are supported. */
|
|
|
|
|
return surf->u.gfx9.dcc.independent_64B_blocks &&
|
|
|
|
|
!surf->u.gfx9.dcc.independent_128B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size == V_028C78_MAX_BLOCK_SIZE_64B;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->family == CHIP_NAVI10) {
|
|
|
|
|
/* Only independent 128B blocks are supported. */
|
|
|
|
|
return !surf->u.gfx9.dcc.independent_64B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size <= V_028C78_MAX_BLOCK_SIZE_128B;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->family == CHIP_NAVI12 ||
|
|
|
|
|
info->family == CHIP_NAVI14) {
|
|
|
|
|
/* Either 64B or 128B can be used, but not both.
|
|
|
|
|
* If 64B is used, DCC image stores are unsupported.
|
|
|
|
|
*/
|
|
|
|
|
return surf->u.gfx9.dcc.independent_64B_blocks !=
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks &&
|
|
|
|
|
(!surf->u.gfx9.dcc.independent_64B_blocks ||
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size == V_028C78_MAX_BLOCK_SIZE_64B) &&
|
|
|
|
|
(!surf->u.gfx9.dcc.independent_128B_blocks ||
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size <= V_028C78_MAX_BLOCK_SIZE_128B);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 20:44:39 -04:00
|
|
|
/* 128B is recommended, but 64B can be set too if needed for 4K by DCN.
|
|
|
|
|
* Since there is no reason to ever disable 128B, require it.
|
|
|
|
|
* DCC image stores are always supported.
|
|
|
|
|
*/
|
|
|
|
|
return surf->u.gfx9.dcc.independent_128B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size <= V_028C78_MAX_BLOCK_SIZE_128B;
|
2020-04-17 20:44:14 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-17 20:27:32 -04:00
|
|
|
static bool is_dcc_supported_by_DCN(const struct radeon_info *info,
|
|
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
const struct radeon_surf *surf,
|
|
|
|
|
bool rb_aligned, bool pipe_aligned)
|
|
|
|
|
{
|
|
|
|
|
if (!info->use_display_dcc_unaligned &&
|
|
|
|
|
!info->use_display_dcc_with_retile_blit)
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-04-17 20:37:41 -04:00
|
|
|
/* 16bpp and 64bpp are more complicated, so they are disallowed for now. */
|
|
|
|
|
if (surf->bpe != 4)
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-04-17 20:27:32 -04:00
|
|
|
/* Handle unaligned DCC. */
|
|
|
|
|
if (info->use_display_dcc_unaligned &&
|
|
|
|
|
(rb_aligned || pipe_aligned))
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-04-17 20:37:41 -04:00
|
|
|
switch (info->chip_class) {
|
|
|
|
|
case GFX9:
|
|
|
|
|
/* There are more constraints, but we always set
|
|
|
|
|
* INDEPENDENT_64B_BLOCKS = 1 and MAX_COMPRESSED_BLOCK_SIZE = 64B,
|
|
|
|
|
* which always works.
|
|
|
|
|
*/
|
|
|
|
|
assert(surf->u.gfx9.dcc.independent_64B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size == V_028C78_MAX_BLOCK_SIZE_64B);
|
|
|
|
|
return true;
|
|
|
|
|
case GFX10:
|
2020-04-17 20:44:39 -04:00
|
|
|
case GFX10_3:
|
|
|
|
|
/* DCN requires INDEPENDENT_128B_BLOCKS = 0 only on Navi1x. */
|
|
|
|
|
if (info->chip_class == GFX10 &&
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* For 4K, DCN requires INDEPENDENT_64B_BLOCKS = 1. */
|
|
|
|
|
return ((config->info.width <= 2560 &&
|
2020-04-17 20:37:41 -04:00
|
|
|
config->info.height <= 2560) ||
|
|
|
|
|
(surf->u.gfx9.dcc.independent_64B_blocks &&
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size == V_028C78_MAX_BLOCK_SIZE_64B));
|
|
|
|
|
default:
|
|
|
|
|
unreachable("unhandled chip");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-04-17 20:27:32 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
static int gfx9_compute_miptree(struct ac_addrlib *addrlib,
|
2019-01-04 19:39:01 -05:00
|
|
|
const struct radeon_info *info,
|
2017-07-29 01:40:48 +02:00
|
|
|
const struct ac_surf_config *config,
|
2017-05-10 20:36:03 +02:00
|
|
|
struct radeon_surf *surf, bool compressed,
|
|
|
|
|
ADDR2_COMPUTE_SURFACE_INFO_INPUT *in)
|
|
|
|
|
{
|
|
|
|
|
ADDR2_MIP_INFO mip_info[RADEON_SURF_MAX_LEVELS] = {};
|
|
|
|
|
ADDR2_COMPUTE_SURFACE_INFO_OUTPUT out = {0};
|
|
|
|
|
ADDR_E_RETURNCODE ret;
|
|
|
|
|
|
|
|
|
|
out.size = sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT);
|
|
|
|
|
out.pMipInfo = mip_info;
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeSurfaceInfo(addrlib->handle, in, &out);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
2017-11-19 16:09:28 +01:00
|
|
|
return ret;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
if (in->flags.stencil) {
|
|
|
|
|
surf->u.gfx9.stencil.swizzle_mode = in->swizzleMode;
|
|
|
|
|
surf->u.gfx9.stencil.epitch = out.epitchIsHeight ? out.mipChainHeight - 1 :
|
|
|
|
|
out.mipChainPitch - 1;
|
|
|
|
|
surf->surf_alignment = MAX2(surf->surf_alignment, out.baseAlign);
|
|
|
|
|
surf->u.gfx9.stencil_offset = align(surf->surf_size, out.baseAlign);
|
|
|
|
|
surf->surf_size = surf->u.gfx9.stencil_offset + out.surfSize;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.surf.swizzle_mode = in->swizzleMode;
|
|
|
|
|
surf->u.gfx9.surf.epitch = out.epitchIsHeight ? out.mipChainHeight - 1 :
|
|
|
|
|
out.mipChainPitch - 1;
|
|
|
|
|
|
|
|
|
|
/* CMASK fast clear uses these even if FMASK isn't allocated.
|
|
|
|
|
* FMASK only supports the Z swizzle modes, whose numbers are multiples of 4.
|
|
|
|
|
*/
|
|
|
|
|
surf->u.gfx9.fmask.swizzle_mode = surf->u.gfx9.surf.swizzle_mode & ~0x3;
|
|
|
|
|
surf->u.gfx9.fmask.epitch = surf->u.gfx9.surf.epitch;
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.surf_slice_size = out.sliceSize;
|
|
|
|
|
surf->u.gfx9.surf_pitch = out.pitch;
|
2020-06-03 18:20:15 +02:00
|
|
|
if (!compressed && surf->blk_w > 1 && out.pitch == out.pixelPitch &&
|
|
|
|
|
surf->u.gfx9.surf.swizzle_mode == ADDR_SW_LINEAR) {
|
2020-02-04 18:56:59 +01:00
|
|
|
/* Adjust surf_pitch to be in elements units,
|
|
|
|
|
* not in pixels */
|
2020-06-03 18:20:15 +02:00
|
|
|
surf->u.gfx9.surf_pitch =
|
|
|
|
|
align(surf->u.gfx9.surf_pitch / surf->blk_w, 256 / surf->bpe);
|
|
|
|
|
surf->u.gfx9.surf.epitch = MAX2(surf->u.gfx9.surf.epitch,
|
|
|
|
|
surf->u.gfx9.surf_pitch * surf->blk_w - 1);
|
2020-02-04 18:56:59 +01:00
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->u.gfx9.surf_height = out.height;
|
|
|
|
|
surf->surf_size = out.surfSize;
|
|
|
|
|
surf->surf_alignment = out.baseAlign;
|
|
|
|
|
|
2020-01-03 11:19:35 +01:00
|
|
|
if (in->swizzleMode == ADDR_SW_LINEAR) {
|
|
|
|
|
for (unsigned i = 0; i < in->numMipLevels; i++) {
|
|
|
|
|
surf->u.gfx9.offset[i] = mip_info[i].offset;
|
|
|
|
|
surf->u.gfx9.pitch[i] = mip_info[i].pitch;
|
|
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in->flags.depth) {
|
|
|
|
|
assert(in->swizzleMode != ADDR_SW_LINEAR);
|
|
|
|
|
|
2019-08-27 21:07:41 -04:00
|
|
|
if (surf->flags & RADEON_SURF_NO_HTILE)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
/* HTILE */
|
|
|
|
|
ADDR2_COMPUTE_HTILE_INFO_INPUT hin = {0};
|
|
|
|
|
ADDR2_COMPUTE_HTILE_INFO_OUTPUT hout = {0};
|
|
|
|
|
|
|
|
|
|
hin.size = sizeof(ADDR2_COMPUTE_HTILE_INFO_INPUT);
|
|
|
|
|
hout.size = sizeof(ADDR2_COMPUTE_HTILE_INFO_OUTPUT);
|
|
|
|
|
|
2020-05-02 09:19:18 -04:00
|
|
|
assert(in->flags.metaPipeUnaligned == 0);
|
|
|
|
|
assert(in->flags.metaRbUnaligned == 0);
|
|
|
|
|
|
|
|
|
|
hin.hTileFlags.pipeAligned = 1;
|
|
|
|
|
hin.hTileFlags.rbAligned = 1;
|
2017-05-10 20:36:03 +02:00
|
|
|
hin.depthFlags = in->flags;
|
|
|
|
|
hin.swizzleMode = in->swizzleMode;
|
|
|
|
|
hin.unalignedWidth = in->width;
|
|
|
|
|
hin.unalignedHeight = in->height;
|
|
|
|
|
hin.numSlices = in->numSlices;
|
|
|
|
|
hin.numMipLevels = in->numMipLevels;
|
2019-01-09 12:42:28 +01:00
|
|
|
hin.firstMipIdInTail = out.firstMipIdInTail;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeHtileInfo(addrlib->handle, &hin, &hout);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
surf->htile_size = hout.htileBytes;
|
2017-05-10 22:52:27 +02:00
|
|
|
surf->htile_slice_size = hout.sliceSize;
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->htile_alignment = hout.baseAlign;
|
2019-08-27 21:07:41 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2017-07-29 01:40:48 +02:00
|
|
|
/* Compute tile swizzle for the color surface.
|
|
|
|
|
* All *_X and *_T modes can use the swizzle.
|
|
|
|
|
*/
|
|
|
|
|
if (config->info.surf_index &&
|
|
|
|
|
in->swizzleMode >= ADDR_SW_64KB_Z_T &&
|
|
|
|
|
!out.mipChainInTail &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_SHAREABLE) &&
|
2018-04-02 12:51:14 -04:00
|
|
|
!in->flags.display) {
|
2017-07-29 01:40:48 +02:00
|
|
|
ADDR2_COMPUTE_PIPEBANKXOR_INPUT xin = {0};
|
|
|
|
|
ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT xout = {0};
|
|
|
|
|
|
|
|
|
|
xin.size = sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT);
|
|
|
|
|
xout.size = sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT);
|
|
|
|
|
|
|
|
|
|
xin.surfIndex = p_atomic_inc_return(config->info.surf_index) - 1;
|
|
|
|
|
xin.flags = in->flags;
|
|
|
|
|
xin.swizzleMode = in->swizzleMode;
|
|
|
|
|
xin.resourceType = in->resourceType;
|
|
|
|
|
xin.format = in->format;
|
|
|
|
|
xin.numSamples = in->numSamples;
|
|
|
|
|
xin.numFrags = in->numFrags;
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputePipeBankXor(addrlib->handle, &xin, &xout);
|
2017-07-29 01:40:48 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
assert(xout.pipeBankXor <=
|
|
|
|
|
u_bit_consecutive(0, sizeof(surf->tile_swizzle) * 8));
|
|
|
|
|
surf->tile_swizzle = xout.pipeBankXor;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
/* DCC */
|
2019-02-07 00:04:32 -05:00
|
|
|
if (info->has_graphics &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_DISABLE_DCC) &&
|
|
|
|
|
!compressed &&
|
2020-04-17 20:27:32 -04:00
|
|
|
is_dcc_supported_by_CB(info, in->swizzleMode) &&
|
|
|
|
|
(!in->flags.display ||
|
|
|
|
|
is_dcc_supported_by_DCN(info, config, surf,
|
|
|
|
|
!in->flags.metaRbUnaligned,
|
|
|
|
|
!in->flags.metaPipeUnaligned))) {
|
2017-05-10 20:36:03 +02:00
|
|
|
ADDR2_COMPUTE_DCCINFO_INPUT din = {0};
|
|
|
|
|
ADDR2_COMPUTE_DCCINFO_OUTPUT dout = {0};
|
2017-10-12 11:21:26 +02:00
|
|
|
ADDR2_META_MIP_INFO meta_mip_info[RADEON_SURF_MAX_LEVELS] = {};
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
din.size = sizeof(ADDR2_COMPUTE_DCCINFO_INPUT);
|
|
|
|
|
dout.size = sizeof(ADDR2_COMPUTE_DCCINFO_OUTPUT);
|
2017-10-12 11:21:26 +02:00
|
|
|
dout.pMipInfo = meta_mip_info;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
2017-11-07 02:57:36 +01:00
|
|
|
din.dccKeyFlags.pipeAligned = !in->flags.metaPipeUnaligned;
|
|
|
|
|
din.dccKeyFlags.rbAligned = !in->flags.metaRbUnaligned;
|
2017-05-10 20:36:03 +02:00
|
|
|
din.colorFlags = in->flags;
|
|
|
|
|
din.resourceType = in->resourceType;
|
|
|
|
|
din.swizzleMode = in->swizzleMode;
|
|
|
|
|
din.bpp = in->bpp;
|
|
|
|
|
din.unalignedWidth = in->width;
|
|
|
|
|
din.unalignedHeight = in->height;
|
|
|
|
|
din.numSlices = in->numSlices;
|
|
|
|
|
din.numFrags = in->numFrags;
|
|
|
|
|
din.numMipLevels = in->numMipLevels;
|
|
|
|
|
din.dataSurfaceSize = out.surfSize;
|
2019-01-09 12:42:28 +01:00
|
|
|
din.firstMipIdInTail = out.firstMipIdInTail;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned = din.dccKeyFlags.rbAligned;
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned = din.dccKeyFlags.pipeAligned;
|
2020-04-26 08:38:54 -04:00
|
|
|
surf->u.gfx9.dcc_block_width = dout.compressBlkWidth;
|
|
|
|
|
surf->u.gfx9.dcc_block_height = dout.compressBlkHeight;
|
|
|
|
|
surf->u.gfx9.dcc_block_depth = dout.compressBlkDepth;
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->dcc_size = dout.dccRamSize;
|
|
|
|
|
surf->dcc_alignment = dout.dccRamBaseAlign;
|
2017-08-17 23:35:36 +02:00
|
|
|
surf->num_dcc_levels = in->numMipLevels;
|
|
|
|
|
|
2017-10-12 11:21:26 +02:00
|
|
|
/* Disable DCC for levels that are in the mip tail.
|
|
|
|
|
*
|
|
|
|
|
* There are two issues that this is intended to
|
|
|
|
|
* address:
|
|
|
|
|
*
|
|
|
|
|
* 1. Multiple mip levels may share a cache line. This
|
|
|
|
|
* can lead to corruption when switching between
|
|
|
|
|
* rendering to different mip levels because the
|
|
|
|
|
* RBs don't maintain coherency.
|
|
|
|
|
*
|
|
|
|
|
* 2. Texturing with metadata after rendering sometimes
|
|
|
|
|
* fails with corruption, probably for a similar
|
|
|
|
|
* reason.
|
|
|
|
|
*
|
|
|
|
|
* Working around these issues for all levels in the
|
|
|
|
|
* mip tail may be overly conservative, but it's what
|
|
|
|
|
* Vulkan does.
|
2017-08-17 23:35:36 +02:00
|
|
|
*
|
|
|
|
|
* Alternative solutions that also work but are worse:
|
2017-10-12 11:21:26 +02:00
|
|
|
* - Disable DCC entirely.
|
2017-08-17 23:35:36 +02:00
|
|
|
* - Flush TC L2 after rendering.
|
|
|
|
|
*/
|
2017-10-12 11:21:26 +02:00
|
|
|
for (unsigned i = 0; i < in->numMipLevels; i++) {
|
|
|
|
|
if (meta_mip_info[i].inMiptail) {
|
2017-08-17 23:35:36 +02:00
|
|
|
surf->num_dcc_levels = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-12 11:21:26 +02:00
|
|
|
|
|
|
|
|
if (!surf->num_dcc_levels)
|
|
|
|
|
surf->dcc_size = 0;
|
2019-01-04 19:39:01 -05:00
|
|
|
|
|
|
|
|
surf->u.gfx9.display_dcc_size = surf->dcc_size;
|
|
|
|
|
surf->u.gfx9.display_dcc_alignment = surf->dcc_alignment;
|
|
|
|
|
surf->u.gfx9.display_dcc_pitch_max = dout.pitch - 1;
|
|
|
|
|
|
|
|
|
|
/* Compute displayable DCC. */
|
|
|
|
|
if (in->flags.display &&
|
|
|
|
|
surf->num_dcc_levels &&
|
|
|
|
|
info->use_display_dcc_with_retile_blit) {
|
|
|
|
|
/* Compute displayable DCC info. */
|
|
|
|
|
din.dccKeyFlags.pipeAligned = 0;
|
|
|
|
|
din.dccKeyFlags.rbAligned = 0;
|
|
|
|
|
|
|
|
|
|
assert(din.numSlices == 1);
|
|
|
|
|
assert(din.numMipLevels == 1);
|
|
|
|
|
assert(din.numFrags == 1);
|
|
|
|
|
assert(surf->tile_swizzle == 0);
|
|
|
|
|
assert(surf->u.gfx9.dcc.pipe_aligned ||
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned);
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout);
|
2019-01-04 19:39:01 -05:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.display_dcc_size = dout.dccRamSize;
|
|
|
|
|
surf->u.gfx9.display_dcc_alignment = dout.dccRamBaseAlign;
|
|
|
|
|
surf->u.gfx9.display_dcc_pitch_max = dout.pitch - 1;
|
|
|
|
|
assert(surf->u.gfx9.display_dcc_size <= surf->dcc_size);
|
|
|
|
|
|
2020-06-09 02:08:21 -04:00
|
|
|
surf->u.gfx9.dcc_retile_use_uint16 =
|
|
|
|
|
surf->u.gfx9.display_dcc_size <= UINT16_MAX + 1 &&
|
|
|
|
|
surf->dcc_size <= UINT16_MAX + 1;
|
2020-06-09 04:55:19 -04:00
|
|
|
|
|
|
|
|
/* Align the retile map size to get more hash table hits and
|
|
|
|
|
* decrease the maximum memory footprint when all retile maps
|
|
|
|
|
* are cached in the hash table.
|
|
|
|
|
*/
|
|
|
|
|
unsigned retile_dim[2] = {in->width, in->height};
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
/* Increase the alignment as the size increases.
|
|
|
|
|
* Greater alignment increases retile compute work,
|
|
|
|
|
* but decreases maximum memory footprint for the cache.
|
|
|
|
|
*
|
|
|
|
|
* With this alignment, the worst case memory footprint of
|
|
|
|
|
* the cache is:
|
|
|
|
|
* 1920x1080: 55 MB
|
|
|
|
|
* 2560x1440: 99 MB
|
|
|
|
|
* 3840x2160: 305 MB
|
|
|
|
|
*
|
|
|
|
|
* The worst case size in MB can be computed in Haskell as follows:
|
|
|
|
|
* (sum (map get_retile_size (map get_dcc_size (deduplicate (map align_pair
|
|
|
|
|
* [(i*16,j*16) | i <- [1..maxwidth`div`16], j <- [1..maxheight`div`16]]))))) `div` 1024^2
|
|
|
|
|
* where
|
|
|
|
|
* alignment x = if x <= 512 then 16 else if x <= 1024 then 32 else if x <= 2048 then 64 else 128
|
|
|
|
|
* align x = (x + (alignment x) - 1) `div` (alignment x) * (alignment x)
|
|
|
|
|
* align_pair e = (align (fst e), align (snd e))
|
|
|
|
|
* deduplicate = map head . groupBy (\ a b -> ((fst a) == (fst b)) && ((snd a) == (snd b))) . sortBy compare
|
|
|
|
|
* get_dcc_size e = ((fst e) * (snd e) * bpp) `div` 256
|
|
|
|
|
* get_retile_size dcc_size = dcc_size * 2 * (if dcc_size <= 2^16 then 2 else 4)
|
|
|
|
|
* bpp = 4; maxwidth = 3840; maxheight = 2160
|
|
|
|
|
*/
|
|
|
|
|
if (retile_dim[i] <= 512)
|
|
|
|
|
retile_dim[i] = align(retile_dim[i], 16);
|
|
|
|
|
else if (retile_dim[i] <= 1024)
|
|
|
|
|
retile_dim[i] = align(retile_dim[i], 32);
|
|
|
|
|
else if (retile_dim[i] <= 2048)
|
|
|
|
|
retile_dim[i] = align(retile_dim[i], 64);
|
|
|
|
|
else
|
|
|
|
|
retile_dim[i] = align(retile_dim[i], 128);
|
|
|
|
|
|
|
|
|
|
/* Don't align more than the DCC pixel alignment. */
|
|
|
|
|
assert(dout.metaBlkWidth >= 128 && dout.metaBlkHeight >= 128);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 19:39:01 -05:00
|
|
|
surf->u.gfx9.dcc_retile_num_elements =
|
2020-06-09 04:55:19 -04:00
|
|
|
DIV_ROUND_UP(retile_dim[0], dout.compressBlkWidth) *
|
|
|
|
|
DIV_ROUND_UP(retile_dim[1], dout.compressBlkHeight) * 2;
|
2019-01-04 19:39:01 -05:00
|
|
|
/* Align the size to 4 (for the compute shader). */
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements =
|
|
|
|
|
align(surf->u.gfx9.dcc_retile_num_elements, 4);
|
|
|
|
|
|
2020-06-09 02:08:21 -04:00
|
|
|
if (!(surf->flags & RADEON_SURF_IMPORTED)) {
|
|
|
|
|
/* Compute address mapping from non-displayable to displayable DCC. */
|
2020-06-09 04:55:19 -04:00
|
|
|
ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT addrin;
|
|
|
|
|
memset(&addrin, 0, sizeof(addrin));
|
2020-06-09 02:08:21 -04:00
|
|
|
addrin.size = sizeof(addrin);
|
|
|
|
|
addrin.swizzleMode = din.swizzleMode;
|
|
|
|
|
addrin.resourceType = din.resourceType;
|
|
|
|
|
addrin.bpp = din.bpp;
|
|
|
|
|
addrin.numSlices = 1;
|
|
|
|
|
addrin.numMipLevels = 1;
|
|
|
|
|
addrin.numFrags = 1;
|
2020-06-09 02:40:20 -04:00
|
|
|
addrin.pitch = dout.pitch;
|
|
|
|
|
addrin.height = dout.height;
|
|
|
|
|
addrin.compressBlkWidth = dout.compressBlkWidth;
|
|
|
|
|
addrin.compressBlkHeight = dout.compressBlkHeight;
|
|
|
|
|
addrin.compressBlkDepth = dout.compressBlkDepth;
|
|
|
|
|
addrin.metaBlkWidth = dout.metaBlkWidth;
|
|
|
|
|
addrin.metaBlkHeight = dout.metaBlkHeight;
|
|
|
|
|
addrin.metaBlkDepth = dout.metaBlkDepth;
|
2020-06-09 04:55:19 -04:00
|
|
|
addrin.dccRamSliceSize = 0; /* Don't care for non-layered images. */
|
2020-06-09 02:08:21 -04:00
|
|
|
|
|
|
|
|
surf->u.gfx9.dcc_retile_map =
|
2020-06-09 04:55:19 -04:00
|
|
|
ac_compute_dcc_retile_map(addrlib, info,
|
|
|
|
|
retile_dim[0], retile_dim[1],
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned,
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned,
|
|
|
|
|
surf->u.gfx9.dcc_retile_use_uint16,
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements,
|
|
|
|
|
&addrin);
|
2020-06-09 02:08:21 -04:00
|
|
|
if (!surf->u.gfx9.dcc_retile_map)
|
|
|
|
|
return ADDR_OUTOFMEMORY;
|
2019-01-04 19:39:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* FMASK */
|
2019-09-13 18:27:46 -04:00
|
|
|
if (in->numSamples > 1 && info->has_graphics &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_NO_FMASK)) {
|
2017-05-10 20:36:03 +02:00
|
|
|
ADDR2_COMPUTE_FMASK_INFO_INPUT fin = {0};
|
|
|
|
|
ADDR2_COMPUTE_FMASK_INFO_OUTPUT fout = {0};
|
|
|
|
|
|
|
|
|
|
fin.size = sizeof(ADDR2_COMPUTE_FMASK_INFO_INPUT);
|
|
|
|
|
fout.size = sizeof(ADDR2_COMPUTE_FMASK_INFO_OUTPUT);
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, in,
|
2018-06-28 20:55:38 +02:00
|
|
|
true, &fin.swizzleMode);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
fin.unalignedWidth = in->width;
|
|
|
|
|
fin.unalignedHeight = in->height;
|
|
|
|
|
fin.numSlices = in->numSlices;
|
|
|
|
|
fin.numSamples = in->numSamples;
|
|
|
|
|
fin.numFrags = in->numFrags;
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeFmaskInfo(addrlib->handle, &fin, &fout);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.fmask.swizzle_mode = fin.swizzleMode;
|
|
|
|
|
surf->u.gfx9.fmask.epitch = fout.pitch - 1;
|
2018-04-30 22:35:51 -04:00
|
|
|
surf->fmask_size = fout.fmaskBytes;
|
|
|
|
|
surf->fmask_alignment = fout.baseAlign;
|
2017-07-29 01:40:48 +02:00
|
|
|
|
|
|
|
|
/* Compute tile swizzle for the FMASK surface. */
|
|
|
|
|
if (config->info.fmask_surf_index &&
|
|
|
|
|
fin.swizzleMode >= ADDR_SW_64KB_Z_T &&
|
|
|
|
|
!(surf->flags & RADEON_SURF_SHAREABLE)) {
|
|
|
|
|
ADDR2_COMPUTE_PIPEBANKXOR_INPUT xin = {0};
|
|
|
|
|
ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT xout = {0};
|
|
|
|
|
|
|
|
|
|
xin.size = sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT);
|
|
|
|
|
xout.size = sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT);
|
|
|
|
|
|
|
|
|
|
/* This counter starts from 1 instead of 0. */
|
|
|
|
|
xin.surfIndex = p_atomic_inc_return(config->info.fmask_surf_index);
|
|
|
|
|
xin.flags = in->flags;
|
2018-07-26 22:46:21 -04:00
|
|
|
xin.swizzleMode = fin.swizzleMode;
|
2017-07-29 01:40:48 +02:00
|
|
|
xin.resourceType = in->resourceType;
|
|
|
|
|
xin.format = in->format;
|
|
|
|
|
xin.numSamples = in->numSamples;
|
|
|
|
|
xin.numFrags = in->numFrags;
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputePipeBankXor(addrlib->handle, &xin, &xout);
|
2017-07-29 01:40:48 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
assert(xout.pipeBankXor <=
|
2018-04-30 22:35:51 -04:00
|
|
|
u_bit_consecutive(0, sizeof(surf->fmask_tile_swizzle) * 8));
|
|
|
|
|
surf->fmask_tile_swizzle = xout.pipeBankXor;
|
2017-07-29 01:40:48 +02:00
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-19 17:26:23 +01:00
|
|
|
/* CMASK -- on GFX10 only for FMASK */
|
|
|
|
|
if (in->swizzleMode != ADDR_SW_LINEAR &&
|
2019-12-20 16:19:54 -05:00
|
|
|
in->resourceType == ADDR_RSRC_TEX_2D &&
|
2020-05-19 01:32:38 -04:00
|
|
|
((info->chip_class <= GFX9 &&
|
|
|
|
|
in->numSamples == 1 &&
|
|
|
|
|
in->flags.metaPipeUnaligned == 0 &&
|
|
|
|
|
in->flags.metaRbUnaligned == 0) ||
|
2019-08-27 20:29:11 -04:00
|
|
|
(surf->fmask_size && in->numSamples >= 2))) {
|
2017-05-10 20:36:03 +02:00
|
|
|
ADDR2_COMPUTE_CMASK_INFO_INPUT cin = {0};
|
|
|
|
|
ADDR2_COMPUTE_CMASK_INFO_OUTPUT cout = {0};
|
|
|
|
|
|
|
|
|
|
cin.size = sizeof(ADDR2_COMPUTE_CMASK_INFO_INPUT);
|
|
|
|
|
cout.size = sizeof(ADDR2_COMPUTE_CMASK_INFO_OUTPUT);
|
|
|
|
|
|
2020-05-02 09:19:18 -04:00
|
|
|
assert(in->flags.metaPipeUnaligned == 0);
|
|
|
|
|
assert(in->flags.metaRbUnaligned == 0);
|
|
|
|
|
|
|
|
|
|
cin.cMaskFlags.pipeAligned = 1;
|
|
|
|
|
cin.cMaskFlags.rbAligned = 1;
|
2017-05-10 20:36:03 +02:00
|
|
|
cin.colorFlags = in->flags;
|
|
|
|
|
cin.resourceType = in->resourceType;
|
|
|
|
|
cin.unalignedWidth = in->width;
|
|
|
|
|
cin.unalignedHeight = in->height;
|
|
|
|
|
cin.numSlices = in->numSlices;
|
|
|
|
|
|
|
|
|
|
if (in->numSamples > 1)
|
|
|
|
|
cin.swizzleMode = surf->u.gfx9.fmask.swizzle_mode;
|
|
|
|
|
else
|
|
|
|
|
cin.swizzleMode = in->swizzleMode;
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
ret = Addr2ComputeCmaskInfo(addrlib->handle, &cin, &cout);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (ret != ADDR_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2018-06-21 22:50:51 -04:00
|
|
|
surf->cmask_size = cout.cmaskBytes;
|
|
|
|
|
surf->cmask_alignment = cout.baseAlign;
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
static int gfx9_compute_surface(struct ac_addrlib *addrlib,
|
2017-11-07 02:57:36 +01:00
|
|
|
const struct radeon_info *info,
|
2017-05-10 20:40:14 +02:00
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
enum radeon_surf_mode mode,
|
|
|
|
|
struct radeon_surf *surf)
|
2017-05-10 20:36:03 +02:00
|
|
|
{
|
|
|
|
|
bool compressed;
|
|
|
|
|
ADDR2_COMPUTE_SURFACE_INFO_INPUT AddrSurfInfoIn = {0};
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.size = sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT);
|
|
|
|
|
|
|
|
|
|
compressed = surf->blk_w == 4 && surf->blk_h == 4;
|
|
|
|
|
|
|
|
|
|
/* The format must be set correctly for the allocation of compressed
|
|
|
|
|
* textures to work. In other cases, setting the bpp is sufficient. */
|
|
|
|
|
if (compressed) {
|
|
|
|
|
switch (surf->bpe) {
|
|
|
|
|
case 8:
|
|
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_BC1;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_BC3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-07-29 01:40:48 +02:00
|
|
|
switch (surf->bpe) {
|
|
|
|
|
case 1:
|
2018-03-26 14:32:56 -04:00
|
|
|
assert(!(surf->flags & RADEON_SURF_ZBUFFER));
|
2017-07-29 01:40:48 +02:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_8;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2018-03-26 14:32:56 -04:00
|
|
|
assert(surf->flags & RADEON_SURF_ZBUFFER ||
|
|
|
|
|
!(surf->flags & RADEON_SURF_SBUFFER));
|
2017-07-29 01:40:48 +02:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_16;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2018-03-26 14:32:56 -04:00
|
|
|
assert(surf->flags & RADEON_SURF_ZBUFFER ||
|
|
|
|
|
!(surf->flags & RADEON_SURF_SBUFFER));
|
2017-07-29 01:40:48 +02:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_32;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
2018-03-26 14:32:56 -04:00
|
|
|
assert(!(surf->flags & RADEON_SURF_Z_OR_SBUFFER));
|
2017-07-29 01:40:48 +02:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_32_32;
|
|
|
|
|
break;
|
2018-05-01 04:03:34 +02:00
|
|
|
case 12:
|
|
|
|
|
assert(!(surf->flags & RADEON_SURF_Z_OR_SBUFFER));
|
|
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_32_32_32;
|
|
|
|
|
break;
|
2017-07-29 01:40:48 +02:00
|
|
|
case 16:
|
2018-03-26 14:32:56 -04:00
|
|
|
assert(!(surf->flags & RADEON_SURF_Z_OR_SBUFFER));
|
2017-07-29 01:40:48 +02:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_32_32_32_32;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2017-05-10 20:36:03 +02:00
|
|
|
AddrSurfInfoIn.bpp = surf->bpe * 8;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:01:44 -04:00
|
|
|
bool is_color_surface = !(surf->flags & RADEON_SURF_Z_OR_SBUFFER);
|
|
|
|
|
AddrSurfInfoIn.flags.color = is_color_surface &&
|
2018-12-17 09:59:49 +01:00
|
|
|
!(surf->flags & RADEON_SURF_NO_RENDER_TARGET);
|
2017-05-10 20:36:03 +02:00
|
|
|
AddrSurfInfoIn.flags.depth = (surf->flags & RADEON_SURF_ZBUFFER) != 0;
|
2018-04-02 12:51:14 -04:00
|
|
|
AddrSurfInfoIn.flags.display = get_display_flag(config, surf);
|
2017-07-08 20:22:54 +02:00
|
|
|
/* flags.texture currently refers to TC-compatible HTILE */
|
2020-05-02 16:01:44 -04:00
|
|
|
AddrSurfInfoIn.flags.texture = is_color_surface ||
|
|
|
|
|
surf->flags & RADEON_SURF_TC_COMPATIBLE_HTILE;
|
2017-05-10 20:36:03 +02:00
|
|
|
AddrSurfInfoIn.flags.opt4space = 1;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.numMipLevels = config->info.levels;
|
2018-04-30 22:29:14 -04:00
|
|
|
AddrSurfInfoIn.numSamples = MAX2(1, config->info.samples);
|
2017-05-10 20:36:03 +02:00
|
|
|
AddrSurfInfoIn.numFrags = AddrSurfInfoIn.numSamples;
|
|
|
|
|
|
2018-04-30 22:29:14 -04:00
|
|
|
if (!(surf->flags & RADEON_SURF_Z_OR_SBUFFER))
|
2018-05-23 22:42:49 -04:00
|
|
|
AddrSurfInfoIn.numFrags = MAX2(1, config->info.storage_samples);
|
2018-04-30 22:29:14 -04:00
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
/* GFX9 doesn't support 1D depth textures, so allocate all 1D textures
|
|
|
|
|
* as 2D to avoid having shader variants for 1D vs 2D, so all shaders
|
|
|
|
|
* must sample 1D textures as 2D. */
|
|
|
|
|
if (config->is_3d)
|
|
|
|
|
AddrSurfInfoIn.resourceType = ADDR_RSRC_TEX_3D;
|
2019-07-02 21:40:49 -04:00
|
|
|
else if (info->chip_class != GFX9 && config->is_1d)
|
|
|
|
|
AddrSurfInfoIn.resourceType = ADDR_RSRC_TEX_1D;
|
2017-05-10 20:36:03 +02:00
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.resourceType = ADDR_RSRC_TEX_2D;
|
|
|
|
|
|
|
|
|
|
AddrSurfInfoIn.width = config->info.width;
|
|
|
|
|
AddrSurfInfoIn.height = config->info.height;
|
|
|
|
|
|
|
|
|
|
if (config->is_3d)
|
|
|
|
|
AddrSurfInfoIn.numSlices = config->info.depth;
|
|
|
|
|
else if (config->is_cube)
|
|
|
|
|
AddrSurfInfoIn.numSlices = 6;
|
|
|
|
|
else
|
|
|
|
|
AddrSurfInfoIn.numSlices = config->info.array_size;
|
|
|
|
|
|
2020-05-02 09:19:18 -04:00
|
|
|
/* This is propagated to DCC. It must be 0 for HTILE and CMASK. */
|
2017-11-07 02:57:36 +01:00
|
|
|
AddrSurfInfoIn.flags.metaPipeUnaligned = 0;
|
|
|
|
|
AddrSurfInfoIn.flags.metaRbUnaligned = 0;
|
|
|
|
|
|
2020-04-17 20:37:41 -04:00
|
|
|
/* Optimal values for the L2 cache. */
|
|
|
|
|
if (info->chip_class == GFX9) {
|
|
|
|
|
surf->u.gfx9.dcc.independent_64B_blocks = 1;
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks = 0;
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size = V_028C78_MAX_BLOCK_SIZE_64B;
|
|
|
|
|
} else if (info->chip_class >= GFX10) {
|
|
|
|
|
surf->u.gfx9.dcc.independent_64B_blocks = 0;
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks = 1;
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size = V_028C78_MAX_BLOCK_SIZE_128B;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AddrSurfInfoIn.flags.display) {
|
|
|
|
|
/* The display hardware can only read DCC with RB_ALIGNED=0 and
|
|
|
|
|
* PIPE_ALIGNED=0. PIPE_ALIGNED really means L2CACHE_ALIGNED.
|
|
|
|
|
*
|
|
|
|
|
* The CB block requires RB_ALIGNED=1 except 1 RB chips.
|
|
|
|
|
* PIPE_ALIGNED is optional, but PIPE_ALIGNED=0 requires L2 flushes
|
|
|
|
|
* after rendering, so PIPE_ALIGNED=1 is recommended.
|
|
|
|
|
*/
|
|
|
|
|
if (info->use_display_dcc_unaligned) {
|
|
|
|
|
AddrSurfInfoIn.flags.metaPipeUnaligned = 1;
|
|
|
|
|
AddrSurfInfoIn.flags.metaRbUnaligned = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Adjust DCC settings to meet DCN requirements. */
|
|
|
|
|
if (info->use_display_dcc_unaligned ||
|
|
|
|
|
info->use_display_dcc_with_retile_blit) {
|
|
|
|
|
/* Only Navi12/14 support independent 64B blocks in L2,
|
|
|
|
|
* but without DCC image stores.
|
|
|
|
|
*/
|
|
|
|
|
if (info->family == CHIP_NAVI12 ||
|
|
|
|
|
info->family == CHIP_NAVI14) {
|
|
|
|
|
surf->u.gfx9.dcc.independent_64B_blocks = 1;
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks = 0;
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size = V_028C78_MAX_BLOCK_SIZE_64B;
|
|
|
|
|
}
|
2020-04-17 20:44:39 -04:00
|
|
|
|
|
|
|
|
if (info->chip_class >= GFX10_3) {
|
|
|
|
|
surf->u.gfx9.dcc.independent_64B_blocks = 1;
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks = 1;
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size = V_028C78_MAX_BLOCK_SIZE_64B;
|
|
|
|
|
}
|
2020-04-17 20:37:41 -04:00
|
|
|
}
|
2019-01-04 19:19:54 -05:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
switch (mode) {
|
|
|
|
|
case RADEON_SURF_MODE_LINEAR_ALIGNED:
|
|
|
|
|
assert(config->info.samples <= 1);
|
|
|
|
|
assert(!(surf->flags & RADEON_SURF_Z_OR_SBUFFER));
|
|
|
|
|
AddrSurfInfoIn.swizzleMode = ADDR_SW_LINEAR;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RADEON_SURF_MODE_1D:
|
|
|
|
|
case RADEON_SURF_MODE_2D:
|
2020-05-02 10:56:20 -04:00
|
|
|
if (surf->flags & RADEON_SURF_IMPORTED ||
|
|
|
|
|
(info->chip_class >= GFX10 &&
|
|
|
|
|
surf->flags & RADEON_SURF_FORCE_SWIZZLE_MODE)) {
|
2017-08-17 23:24:00 +02:00
|
|
|
AddrSurfInfoIn.swizzleMode = surf->u.gfx9.surf.swizzle_mode;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
r = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, &AddrSurfInfoIn,
|
2018-06-28 20:55:38 +02:00
|
|
|
false, &AddrSurfInfoIn.swizzleMode);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surf->u.gfx9.resource_type = AddrSurfInfoIn.resourceType;
|
2017-09-07 00:13:37 +02:00
|
|
|
surf->has_stencil = !!(surf->flags & RADEON_SURF_SBUFFER);
|
2017-05-10 20:36:03 +02:00
|
|
|
|
2017-08-17 23:35:36 +02:00
|
|
|
surf->num_dcc_levels = 0;
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->surf_size = 0;
|
2018-04-30 22:35:51 -04:00
|
|
|
surf->fmask_size = 0;
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->dcc_size = 0;
|
|
|
|
|
surf->htile_size = 0;
|
2017-05-10 22:52:27 +02:00
|
|
|
surf->htile_slice_size = 0;
|
2017-05-10 20:36:03 +02:00
|
|
|
surf->u.gfx9.surf_offset = 0;
|
|
|
|
|
surf->u.gfx9.stencil_offset = 0;
|
2018-06-21 22:50:51 -04:00
|
|
|
surf->cmask_size = 0;
|
2019-01-04 19:39:01 -05:00
|
|
|
surf->u.gfx9.dcc_retile_use_uint16 = false;
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements = 0;
|
|
|
|
|
surf->u.gfx9.dcc_retile_map = NULL;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
/* Calculate texture layout information. */
|
2019-01-04 19:39:01 -05:00
|
|
|
r = gfx9_compute_miptree(addrlib, info, config, surf, compressed,
|
2017-07-29 01:40:48 +02:00
|
|
|
&AddrSurfInfoIn);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (r)
|
2019-01-04 19:39:01 -05:00
|
|
|
goto error;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
/* Calculate texture layout information for stencil. */
|
|
|
|
|
if (surf->flags & RADEON_SURF_SBUFFER) {
|
|
|
|
|
AddrSurfInfoIn.flags.stencil = 1;
|
2017-09-17 20:17:33 -07:00
|
|
|
AddrSurfInfoIn.bpp = 8;
|
2018-03-26 14:32:56 -04:00
|
|
|
AddrSurfInfoIn.format = ADDR_FMT_8;
|
2017-09-17 20:17:33 -07:00
|
|
|
|
2017-09-20 16:45:48 +02:00
|
|
|
if (!AddrSurfInfoIn.flags.depth) {
|
2020-06-09 03:19:04 -04:00
|
|
|
r = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, &AddrSurfInfoIn,
|
2018-06-28 20:55:38 +02:00
|
|
|
false, &AddrSurfInfoIn.swizzleMode);
|
2017-09-20 16:45:48 +02:00
|
|
|
if (r)
|
2019-01-04 19:39:01 -05:00
|
|
|
goto error;
|
2017-09-20 16:45:48 +02:00
|
|
|
} else
|
2017-09-17 20:17:33 -07:00
|
|
|
AddrSurfInfoIn.flags.depth = 0;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
2019-01-04 19:39:01 -05:00
|
|
|
r = gfx9_compute_miptree(addrlib, info, config, surf, compressed,
|
2017-07-29 01:40:48 +02:00
|
|
|
&AddrSurfInfoIn);
|
2017-05-10 20:36:03 +02:00
|
|
|
if (r)
|
2019-01-04 19:39:01 -05:00
|
|
|
goto error;
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surf->is_linear = surf->u.gfx9.surf.swizzle_mode == ADDR_SW_LINEAR;
|
|
|
|
|
|
2017-10-09 18:42:48 +02:00
|
|
|
/* Query whether the surface is displayable. */
|
2020-04-17 20:19:26 -04:00
|
|
|
/* This is only useful for surfaces that are allocated without SCANOUT. */
|
2017-10-09 18:42:48 +02:00
|
|
|
bool displayable = false;
|
2018-11-29 18:34:01 +01:00
|
|
|
if (!config->is_3d && !config->is_cube) {
|
2020-06-09 03:19:04 -04:00
|
|
|
r = Addr2IsValidDisplaySwizzleMode(addrlib->handle, surf->u.gfx9.surf.swizzle_mode,
|
|
|
|
|
surf->bpe * 8, &displayable);
|
2018-11-29 18:34:01 +01:00
|
|
|
if (r)
|
2019-01-04 19:39:01 -05:00
|
|
|
goto error;
|
2019-01-04 19:19:54 -05:00
|
|
|
|
|
|
|
|
/* Display needs unaligned DCC. */
|
2020-04-17 20:27:32 -04:00
|
|
|
if (surf->num_dcc_levels &&
|
2020-06-10 11:43:49 -04:00
|
|
|
(!is_dcc_supported_by_DCN(info, config, surf,
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned,
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned) ||
|
|
|
|
|
/* Don't set is_displayable if displayable DCC is missing. */
|
|
|
|
|
(info->use_display_dcc_with_retile_blit &&
|
|
|
|
|
!surf->u.gfx9.dcc_retile_num_elements)))
|
2019-01-04 19:19:54 -05:00
|
|
|
displayable = false;
|
2018-11-29 18:34:01 +01:00
|
|
|
}
|
2017-10-09 18:42:48 +02:00
|
|
|
surf->is_displayable = displayable;
|
|
|
|
|
|
2020-04-17 20:19:26 -04:00
|
|
|
/* Validate that we allocated a displayable surface if requested. */
|
|
|
|
|
assert(!AddrSurfInfoIn.flags.display || surf->is_displayable);
|
|
|
|
|
|
2020-04-17 20:44:14 -04:00
|
|
|
/* Validate that DCC is set up correctly. */
|
|
|
|
|
if (surf->num_dcc_levels) {
|
|
|
|
|
assert(is_dcc_supported_by_L2(info, surf));
|
|
|
|
|
if (AddrSurfInfoIn.flags.color)
|
|
|
|
|
assert(is_dcc_supported_by_CB(info, surf->u.gfx9.surf.swizzle_mode));
|
|
|
|
|
if (AddrSurfInfoIn.flags.display) {
|
|
|
|
|
assert(is_dcc_supported_by_DCN(info, config, surf,
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned,
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->has_graphics &&
|
|
|
|
|
!compressed &&
|
|
|
|
|
!config->is_3d &&
|
|
|
|
|
config->info.levels == 1 &&
|
|
|
|
|
AddrSurfInfoIn.flags.color &&
|
|
|
|
|
!surf->is_linear &&
|
|
|
|
|
surf->surf_alignment >= 64 * 1024 && /* 64KB tiling */
|
|
|
|
|
!(surf->flags & (RADEON_SURF_DISABLE_DCC |
|
|
|
|
|
RADEON_SURF_FORCE_SWIZZLE_MODE |
|
|
|
|
|
RADEON_SURF_FORCE_MICRO_TILE_MODE))) {
|
|
|
|
|
/* Validate that DCC is enabled if DCN can do it. */
|
|
|
|
|
if ((info->use_display_dcc_unaligned ||
|
|
|
|
|
info->use_display_dcc_with_retile_blit) &&
|
|
|
|
|
AddrSurfInfoIn.flags.display &&
|
|
|
|
|
surf->bpe == 4) {
|
|
|
|
|
assert(surf->num_dcc_levels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Validate that non-scanout DCC is always enabled. */
|
|
|
|
|
if (!AddrSurfInfoIn.flags.display)
|
|
|
|
|
assert(surf->num_dcc_levels);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:19:00 -04:00
|
|
|
if (!surf->htile_size) {
|
|
|
|
|
/* Unset this if HTILE is not present. */
|
|
|
|
|
surf->flags &= ~RADEON_SURF_TC_COMPATIBLE_HTILE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:36:03 +02:00
|
|
|
switch (surf->u.gfx9.surf.swizzle_mode) {
|
|
|
|
|
/* S = standard. */
|
|
|
|
|
case ADDR_SW_256B_S:
|
|
|
|
|
case ADDR_SW_4KB_S:
|
|
|
|
|
case ADDR_SW_64KB_S:
|
|
|
|
|
case ADDR_SW_64KB_S_T:
|
|
|
|
|
case ADDR_SW_4KB_S_X:
|
|
|
|
|
case ADDR_SW_64KB_S_X:
|
2020-04-23 00:31:36 -04:00
|
|
|
surf->micro_tile_mode = RADEON_MICRO_MODE_STANDARD;
|
2017-05-10 20:36:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* D = display. */
|
|
|
|
|
case ADDR_SW_LINEAR:
|
|
|
|
|
case ADDR_SW_256B_D:
|
|
|
|
|
case ADDR_SW_4KB_D:
|
|
|
|
|
case ADDR_SW_64KB_D:
|
|
|
|
|
case ADDR_SW_64KB_D_T:
|
|
|
|
|
case ADDR_SW_4KB_D_X:
|
|
|
|
|
case ADDR_SW_64KB_D_X:
|
|
|
|
|
surf->micro_tile_mode = RADEON_MICRO_MODE_DISPLAY;
|
|
|
|
|
break;
|
|
|
|
|
|
2018-06-28 21:01:40 +02:00
|
|
|
/* R = rotated (gfx9), render target (gfx10). */
|
2017-05-10 20:36:03 +02:00
|
|
|
case ADDR_SW_256B_R:
|
|
|
|
|
case ADDR_SW_4KB_R:
|
|
|
|
|
case ADDR_SW_64KB_R:
|
|
|
|
|
case ADDR_SW_64KB_R_T:
|
|
|
|
|
case ADDR_SW_4KB_R_X:
|
|
|
|
|
case ADDR_SW_64KB_R_X:
|
|
|
|
|
case ADDR_SW_VAR_R_X:
|
2018-06-20 20:00:59 -04:00
|
|
|
/* The rotated micro tile mode doesn't work if both CMASK and RB+ are
|
2018-06-28 21:01:40 +02:00
|
|
|
* used at the same time. We currently do not use rotated
|
|
|
|
|
* in gfx9.
|
2018-06-20 20:00:59 -04:00
|
|
|
*/
|
2018-06-28 21:01:40 +02:00
|
|
|
assert(info->chip_class >= GFX10 ||
|
|
|
|
|
!"rotate micro tile mode is unsupported");
|
2020-04-23 00:31:36 -04:00
|
|
|
surf->micro_tile_mode = RADEON_MICRO_MODE_RENDER;
|
2018-06-28 21:01:40 +02:00
|
|
|
break;
|
2017-05-10 20:36:03 +02:00
|
|
|
|
|
|
|
|
/* Z = depth. */
|
|
|
|
|
case ADDR_SW_4KB_Z:
|
|
|
|
|
case ADDR_SW_64KB_Z:
|
|
|
|
|
case ADDR_SW_64KB_Z_T:
|
|
|
|
|
case ADDR_SW_4KB_Z_X:
|
|
|
|
|
case ADDR_SW_64KB_Z_X:
|
|
|
|
|
case ADDR_SW_VAR_Z_X:
|
|
|
|
|
surf->micro_tile_mode = RADEON_MICRO_MODE_DEPTH;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2019-01-04 19:39:01 -05:00
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
free(surf->u.gfx9.dcc_retile_map);
|
|
|
|
|
surf->u.gfx9.dcc_retile_map = NULL;
|
|
|
|
|
return r;
|
2017-05-10 20:36:03 +02:00
|
|
|
}
|
2017-05-10 20:40:14 +02:00
|
|
|
|
2020-06-09 03:19:04 -04:00
|
|
|
int ac_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info,
|
2017-05-10 20:40:14 +02:00
|
|
|
const struct ac_surf_config *config,
|
|
|
|
|
enum radeon_surf_mode mode,
|
|
|
|
|
struct radeon_surf *surf)
|
|
|
|
|
{
|
2017-05-10 20:44:51 +02:00
|
|
|
int r;
|
|
|
|
|
|
2018-04-30 20:54:06 -04:00
|
|
|
r = surf_config_sanity(config, surf->flags);
|
2017-05-10 20:44:51 +02:00
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
|
2017-05-12 01:24:48 +02:00
|
|
|
if (info->chip_class >= GFX9)
|
2019-08-27 21:18:20 -04:00
|
|
|
r = gfx9_compute_surface(addrlib, info, config, mode, surf);
|
2017-05-10 20:40:14 +02:00
|
|
|
else
|
2020-06-09 03:19:04 -04:00
|
|
|
r = gfx6_compute_surface(addrlib->handle, info, config, mode, surf);
|
2019-08-27 21:18:20 -04:00
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
/* Determine the memory layout of multiple allocations in one buffer. */
|
|
|
|
|
surf->total_size = surf->surf_size;
|
2020-05-24 14:23:24 +02:00
|
|
|
surf->alignment = surf->surf_alignment;
|
2019-08-27 21:18:20 -04:00
|
|
|
|
|
|
|
|
if (surf->htile_size) {
|
|
|
|
|
surf->htile_offset = align64(surf->total_size, surf->htile_alignment);
|
|
|
|
|
surf->total_size = surf->htile_offset + surf->htile_size;
|
2020-05-24 14:23:24 +02:00
|
|
|
surf->alignment = MAX2(surf->alignment, surf->htile_alignment);
|
2019-08-27 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (surf->fmask_size) {
|
|
|
|
|
assert(config->info.samples >= 2);
|
|
|
|
|
surf->fmask_offset = align64(surf->total_size, surf->fmask_alignment);
|
|
|
|
|
surf->total_size = surf->fmask_offset + surf->fmask_size;
|
2020-05-24 14:23:24 +02:00
|
|
|
surf->alignment = MAX2(surf->alignment, surf->fmask_alignment);
|
2019-08-27 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Single-sample CMASK is in a separate buffer. */
|
|
|
|
|
if (surf->cmask_size && config->info.samples >= 2) {
|
|
|
|
|
surf->cmask_offset = align64(surf->total_size, surf->cmask_alignment);
|
|
|
|
|
surf->total_size = surf->cmask_offset + surf->cmask_size;
|
2020-05-24 14:23:24 +02:00
|
|
|
surf->alignment = MAX2(surf->alignment, surf->cmask_alignment);
|
2019-08-27 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-26 09:53:27 +02:00
|
|
|
if (surf->is_displayable)
|
|
|
|
|
surf->flags |= RADEON_SURF_SCANOUT;
|
|
|
|
|
|
2019-08-27 21:18:20 -04:00
|
|
|
if (surf->dcc_size &&
|
2020-04-17 20:27:32 -04:00
|
|
|
/* dcc_size is computed on GFX9+ only if it's displayable. */
|
|
|
|
|
(info->chip_class >= GFX9 || !get_display_flag(config, surf))) {
|
2020-04-22 18:51:42 -04:00
|
|
|
/* It's better when displayable DCC is immediately after
|
|
|
|
|
* the image due to hw-specific reasons.
|
|
|
|
|
*/
|
2019-08-27 21:18:20 -04:00
|
|
|
if (info->chip_class >= GFX9 &&
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements) {
|
|
|
|
|
/* Add space for the displayable DCC buffer. */
|
|
|
|
|
surf->display_dcc_offset =
|
|
|
|
|
align64(surf->total_size, surf->u.gfx9.display_dcc_alignment);
|
|
|
|
|
surf->total_size = surf->display_dcc_offset +
|
|
|
|
|
surf->u.gfx9.display_dcc_size;
|
|
|
|
|
|
|
|
|
|
/* Add space for the DCC retile buffer. (16-bit or 32-bit elements) */
|
|
|
|
|
surf->dcc_retile_map_offset =
|
|
|
|
|
align64(surf->total_size, info->tcc_cache_line_size);
|
|
|
|
|
|
|
|
|
|
if (surf->u.gfx9.dcc_retile_use_uint16) {
|
|
|
|
|
surf->total_size = surf->dcc_retile_map_offset +
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements * 2;
|
|
|
|
|
} else {
|
|
|
|
|
surf->total_size = surf->dcc_retile_map_offset +
|
|
|
|
|
surf->u.gfx9.dcc_retile_num_elements * 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-22 18:51:42 -04:00
|
|
|
|
|
|
|
|
surf->dcc_offset = align64(surf->total_size, surf->dcc_alignment);
|
|
|
|
|
surf->total_size = surf->dcc_offset + surf->dcc_size;
|
2020-05-24 14:23:24 +02:00
|
|
|
surf->alignment = MAX2(surf->alignment, surf->dcc_alignment);
|
2019-08-27 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2017-05-10 20:40:14 +02:00
|
|
|
}
|
2020-05-02 10:58:46 -04:00
|
|
|
|
2020-05-02 12:23:51 -04:00
|
|
|
/* This is meant to be used for disabling DCC. */
|
|
|
|
|
void ac_surface_zero_dcc_fields(struct radeon_surf *surf)
|
|
|
|
|
{
|
|
|
|
|
surf->dcc_offset = 0;
|
|
|
|
|
surf->display_dcc_offset = 0;
|
|
|
|
|
surf->dcc_retile_map_offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 10:58:46 -04:00
|
|
|
static unsigned eg_tile_split(unsigned tile_split)
|
|
|
|
|
{
|
|
|
|
|
switch (tile_split) {
|
|
|
|
|
case 0: tile_split = 64; break;
|
|
|
|
|
case 1: tile_split = 128; break;
|
|
|
|
|
case 2: tile_split = 256; break;
|
|
|
|
|
case 3: tile_split = 512; break;
|
|
|
|
|
default:
|
|
|
|
|
case 4: tile_split = 1024; break;
|
|
|
|
|
case 5: tile_split = 2048; break;
|
|
|
|
|
case 6: tile_split = 4096; break;
|
|
|
|
|
}
|
|
|
|
|
return tile_split;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned eg_tile_split_rev(unsigned eg_tile_split)
|
|
|
|
|
{
|
|
|
|
|
switch (eg_tile_split) {
|
|
|
|
|
case 64: return 0;
|
|
|
|
|
case 128: return 1;
|
|
|
|
|
case 256: return 2;
|
|
|
|
|
case 512: return 3;
|
|
|
|
|
default:
|
|
|
|
|
case 1024: return 4;
|
|
|
|
|
case 2048: return 5;
|
|
|
|
|
case 4096: return 6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define AMDGPU_TILING_DCC_MAX_COMPRESSED_BLOCK_SIZE_SHIFT 45
|
|
|
|
|
#define AMDGPU_TILING_DCC_MAX_COMPRESSED_BLOCK_SIZE_MASK 0x3
|
|
|
|
|
|
|
|
|
|
/* This should be called before ac_compute_surface. */
|
|
|
|
|
void ac_surface_set_bo_metadata(const struct radeon_info *info,
|
|
|
|
|
struct radeon_surf *surf, uint64_t tiling_flags,
|
|
|
|
|
enum radeon_surf_mode *mode)
|
|
|
|
|
{
|
|
|
|
|
bool scanout;
|
|
|
|
|
|
|
|
|
|
if (info->chip_class >= GFX9) {
|
|
|
|
|
surf->u.gfx9.surf.swizzle_mode = AMDGPU_TILING_GET(tiling_flags, SWIZZLE_MODE);
|
|
|
|
|
surf->u.gfx9.dcc.independent_64B_blocks = AMDGPU_TILING_GET(tiling_flags, DCC_INDEPENDENT_64B);
|
|
|
|
|
surf->u.gfx9.dcc.independent_128B_blocks = AMDGPU_TILING_GET(tiling_flags, DCC_INDEPENDENT_128B);
|
|
|
|
|
surf->u.gfx9.dcc.max_compressed_block_size = AMDGPU_TILING_GET(tiling_flags, DCC_MAX_COMPRESSED_BLOCK_SIZE);
|
|
|
|
|
surf->u.gfx9.display_dcc_pitch_max = AMDGPU_TILING_GET(tiling_flags, DCC_PITCH_MAX);
|
|
|
|
|
scanout = AMDGPU_TILING_GET(tiling_flags, SCANOUT);
|
|
|
|
|
*mode = surf->u.gfx9.surf.swizzle_mode > 0 ? RADEON_SURF_MODE_2D : RADEON_SURF_MODE_LINEAR_ALIGNED;
|
|
|
|
|
} else {
|
|
|
|
|
surf->u.legacy.pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
|
|
|
|
|
surf->u.legacy.bankw = 1 << AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
|
|
|
|
|
surf->u.legacy.bankh = 1 << AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
|
|
|
|
|
surf->u.legacy.tile_split = eg_tile_split(AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT));
|
|
|
|
|
surf->u.legacy.mtilea = 1 << AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
|
|
|
|
|
surf->u.legacy.num_banks = 2 << AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
|
|
|
|
|
scanout = AMDGPU_TILING_GET(tiling_flags, MICRO_TILE_MODE) == 0; /* DISPLAY */
|
|
|
|
|
|
|
|
|
|
if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == 4) /* 2D_TILED_THIN1 */
|
|
|
|
|
*mode = RADEON_SURF_MODE_2D;
|
|
|
|
|
else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == 2) /* 1D_TILED_THIN1 */
|
|
|
|
|
*mode = RADEON_SURF_MODE_1D;
|
|
|
|
|
else
|
|
|
|
|
*mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scanout)
|
|
|
|
|
surf->flags |= RADEON_SURF_SCANOUT;
|
|
|
|
|
else
|
|
|
|
|
surf->flags &= ~RADEON_SURF_SCANOUT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ac_surface_get_bo_metadata(const struct radeon_info *info,
|
|
|
|
|
struct radeon_surf *surf, uint64_t *tiling_flags)
|
|
|
|
|
{
|
|
|
|
|
*tiling_flags = 0;
|
|
|
|
|
|
|
|
|
|
if (info->chip_class >= GFX9) {
|
|
|
|
|
uint64_t dcc_offset = 0;
|
|
|
|
|
|
|
|
|
|
if (surf->dcc_offset) {
|
2020-05-11 09:18:49 +02:00
|
|
|
dcc_offset = surf->display_dcc_offset ? surf->display_dcc_offset
|
|
|
|
|
: surf->dcc_offset;
|
2020-05-02 10:58:46 -04:00
|
|
|
assert((dcc_offset >> 8) != 0 && (dcc_offset >> 8) < (1 << 24));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(SWIZZLE_MODE, surf->u.gfx9.surf.swizzle_mode);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(DCC_OFFSET_256B, dcc_offset >> 8);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(DCC_PITCH_MAX, surf->u.gfx9.display_dcc_pitch_max);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(DCC_INDEPENDENT_64B, surf->u.gfx9.dcc.independent_64B_blocks);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(DCC_INDEPENDENT_128B, surf->u.gfx9.dcc.independent_128B_blocks);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(DCC_MAX_COMPRESSED_BLOCK_SIZE, surf->u.gfx9.dcc.max_compressed_block_size);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(SCANOUT, (surf->flags & RADEON_SURF_SCANOUT) != 0);
|
|
|
|
|
} else {
|
|
|
|
|
if (surf->u.legacy.level[0].mode >= RADEON_SURF_MODE_2D)
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 4); /* 2D_TILED_THIN1 */
|
|
|
|
|
else if (surf->u.legacy.level[0].mode >= RADEON_SURF_MODE_1D)
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 2); /* 1D_TILED_THIN1 */
|
|
|
|
|
else
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 1); /* LINEAR_ALIGNED */
|
|
|
|
|
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(PIPE_CONFIG, surf->u.legacy.pipe_config);
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(BANK_WIDTH, util_logbase2(surf->u.legacy.bankw));
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(BANK_HEIGHT, util_logbase2(surf->u.legacy.bankh));
|
|
|
|
|
if (surf->u.legacy.tile_split)
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(TILE_SPLIT, eg_tile_split_rev(surf->u.legacy.tile_split));
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(MACRO_TILE_ASPECT, util_logbase2(surf->u.legacy.mtilea));
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(NUM_BANKS, util_logbase2(surf->u.legacy.num_banks)-1);
|
|
|
|
|
|
|
|
|
|
if (surf->flags & RADEON_SURF_SCANOUT)
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(MICRO_TILE_MODE, 0); /* DISPLAY_MICRO_TILING */
|
|
|
|
|
else
|
|
|
|
|
*tiling_flags |= AMDGPU_TILING_SET(MICRO_TILE_MODE, 1); /* THIN_MICRO_TILING */
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-02 12:23:51 -04:00
|
|
|
|
|
|
|
|
static uint32_t ac_get_umd_metadata_word1(const struct radeon_info *info)
|
|
|
|
|
{
|
|
|
|
|
return (ATI_VENDOR_ID << 16) | info->pci_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This should be called after ac_compute_surface. */
|
|
|
|
|
bool ac_surface_set_umd_metadata(const struct radeon_info *info,
|
|
|
|
|
struct radeon_surf *surf,
|
|
|
|
|
unsigned num_storage_samples,
|
|
|
|
|
unsigned num_mipmap_levels,
|
|
|
|
|
unsigned size_metadata,
|
|
|
|
|
uint32_t metadata[64])
|
|
|
|
|
{
|
|
|
|
|
uint32_t *desc = &metadata[2];
|
|
|
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
|
|
if (info->chip_class >= GFX9)
|
|
|
|
|
offset = surf->u.gfx9.surf_offset;
|
|
|
|
|
else
|
|
|
|
|
offset = surf->u.legacy.level[0].offset;
|
|
|
|
|
|
|
|
|
|
if (offset || /* Non-zero planes ignore metadata. */
|
|
|
|
|
size_metadata < 10 * 4 || /* at least 2(header) + 8(desc) dwords */
|
|
|
|
|
metadata[0] == 0 || /* invalid version number */
|
|
|
|
|
metadata[1] != ac_get_umd_metadata_word1(info)) /* invalid PCI ID */ {
|
|
|
|
|
/* Disable DCC because it might not be enabled. */
|
|
|
|
|
ac_surface_zero_dcc_fields(surf);
|
|
|
|
|
|
|
|
|
|
/* Don't report an error if the texture comes from an incompatible driver,
|
|
|
|
|
* but this might not work.
|
|
|
|
|
*/
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Validate that sample counts and the number of mipmap levels match. */
|
|
|
|
|
unsigned desc_last_level = G_008F1C_LAST_LEVEL(desc[3]);
|
|
|
|
|
unsigned type = G_008F1C_TYPE(desc[3]);
|
|
|
|
|
|
|
|
|
|
if (type == V_008F1C_SQ_RSRC_IMG_2D_MSAA || type == V_008F1C_SQ_RSRC_IMG_2D_MSAA_ARRAY) {
|
|
|
|
|
unsigned log_samples = util_logbase2(MAX2(1, num_storage_samples));
|
|
|
|
|
|
|
|
|
|
if (desc_last_level != log_samples) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"amdgpu: invalid MSAA texture import, "
|
|
|
|
|
"metadata has log2(samples) = %u, the caller set %u\n",
|
|
|
|
|
desc_last_level, log_samples);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (desc_last_level != num_mipmap_levels - 1) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"amdgpu: invalid mipmapped texture import, "
|
|
|
|
|
"metadata has last_level = %u, the caller set %u\n",
|
|
|
|
|
desc_last_level, num_mipmap_levels - 1);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->chip_class >= GFX8 && G_008F28_COMPRESSION_EN(desc[6])) {
|
|
|
|
|
/* Read DCC information. */
|
|
|
|
|
switch (info->chip_class) {
|
|
|
|
|
case GFX8:
|
|
|
|
|
surf->dcc_offset = (uint64_t)desc[7] << 8;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GFX9:
|
|
|
|
|
surf->dcc_offset =
|
|
|
|
|
((uint64_t)desc[7] << 8) | ((uint64_t)G_008F24_META_DATA_ADDRESS(desc[5]) << 40);
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned = G_008F24_META_PIPE_ALIGNED(desc[5]);
|
|
|
|
|
surf->u.gfx9.dcc.rb_aligned = G_008F24_META_RB_ALIGNED(desc[5]);
|
|
|
|
|
|
|
|
|
|
/* If DCC is unaligned, this can only be a displayable image. */
|
|
|
|
|
if (!surf->u.gfx9.dcc.pipe_aligned && !surf->u.gfx9.dcc.rb_aligned)
|
|
|
|
|
assert(surf->is_displayable);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GFX10:
|
2020-03-26 22:02:13 -04:00
|
|
|
case GFX10_3:
|
2020-05-02 12:23:51 -04:00
|
|
|
surf->dcc_offset =
|
|
|
|
|
((uint64_t)G_00A018_META_DATA_ADDRESS_LO(desc[6]) << 8) | ((uint64_t)desc[7] << 16);
|
|
|
|
|
surf->u.gfx9.dcc.pipe_aligned = G_00A018_META_PIPE_ALIGNED(desc[6]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Disable DCC. dcc_offset is always set by texture_from_handle
|
|
|
|
|
* and must be cleared here.
|
|
|
|
|
*/
|
|
|
|
|
ac_surface_zero_dcc_fields(surf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ac_surface_get_umd_metadata(const struct radeon_info *info,
|
|
|
|
|
struct radeon_surf *surf,
|
|
|
|
|
unsigned num_mipmap_levels,
|
|
|
|
|
uint32_t desc[8],
|
|
|
|
|
unsigned *size_metadata, uint32_t metadata[64])
|
|
|
|
|
{
|
|
|
|
|
/* Clear the base address and set the relative DCC offset. */
|
|
|
|
|
desc[0] = 0;
|
|
|
|
|
desc[1] &= C_008F14_BASE_ADDRESS_HI;
|
|
|
|
|
|
|
|
|
|
switch (info->chip_class) {
|
|
|
|
|
case GFX6:
|
|
|
|
|
case GFX7:
|
|
|
|
|
break;
|
|
|
|
|
case GFX8:
|
|
|
|
|
desc[7] = surf->dcc_offset >> 8;
|
|
|
|
|
break;
|
|
|
|
|
case GFX9:
|
|
|
|
|
desc[7] = surf->dcc_offset >> 8;
|
|
|
|
|
desc[5] &= C_008F24_META_DATA_ADDRESS;
|
|
|
|
|
desc[5] |= S_008F24_META_DATA_ADDRESS(surf->dcc_offset >> 40);
|
|
|
|
|
break;
|
|
|
|
|
case GFX10:
|
2020-03-26 22:02:13 -04:00
|
|
|
case GFX10_3:
|
2020-05-02 12:23:51 -04:00
|
|
|
desc[6] &= C_00A018_META_DATA_ADDRESS_LO;
|
|
|
|
|
desc[6] |= S_00A018_META_DATA_ADDRESS_LO(surf->dcc_offset >> 8);
|
|
|
|
|
desc[7] = surf->dcc_offset >> 16;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Metadata image format format version 1:
|
|
|
|
|
* [0] = 1 (metadata format identifier)
|
|
|
|
|
* [1] = (VENDOR_ID << 16) | PCI_ID
|
|
|
|
|
* [2:9] = image descriptor for the whole resource
|
|
|
|
|
* [2] is always 0, because the base address is cleared
|
|
|
|
|
* [9] is the DCC offset bits [39:8] from the beginning of
|
|
|
|
|
* the buffer
|
|
|
|
|
* [10:10+LAST_LEVEL] = mipmap level offset bits [39:8] for each level
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
metadata[0] = 1; /* metadata image format version 1 */
|
|
|
|
|
|
|
|
|
|
/* Tiling modes are ambiguous without a PCI ID. */
|
|
|
|
|
metadata[1] = ac_get_umd_metadata_word1(info);
|
|
|
|
|
|
|
|
|
|
/* Dwords [2:9] contain the image descriptor. */
|
|
|
|
|
memcpy(&metadata[2], desc, 8 * 4);
|
|
|
|
|
*size_metadata = 10 * 4;
|
|
|
|
|
|
|
|
|
|
/* Dwords [10:..] contain the mipmap level offsets. */
|
|
|
|
|
if (info->chip_class <= GFX8) {
|
|
|
|
|
for (unsigned i = 0; i < num_mipmap_levels; i++)
|
|
|
|
|
metadata[10 + i] = surf->u.legacy.level[i].offset >> 8;
|
|
|
|
|
|
|
|
|
|
*size_metadata += num_mipmap_levels * 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-04 07:43:44 -04:00
|
|
|
|
|
|
|
|
void ac_surface_override_offset_stride(const struct radeon_info *info,
|
|
|
|
|
struct radeon_surf *surf,
|
|
|
|
|
unsigned num_mipmap_levels,
|
|
|
|
|
uint64_t offset, unsigned pitch)
|
|
|
|
|
{
|
|
|
|
|
if (info->chip_class >= GFX9) {
|
|
|
|
|
if (pitch) {
|
|
|
|
|
surf->u.gfx9.surf_pitch = pitch;
|
|
|
|
|
if (num_mipmap_levels == 1)
|
|
|
|
|
surf->u.gfx9.surf.epitch = pitch - 1;
|
|
|
|
|
surf->u.gfx9.surf_slice_size =
|
|
|
|
|
(uint64_t)pitch * surf->u.gfx9.surf_height * surf->bpe;
|
|
|
|
|
}
|
|
|
|
|
surf->u.gfx9.surf_offset = offset;
|
2020-05-04 07:53:38 -04:00
|
|
|
if (surf->u.gfx9.stencil_offset)
|
|
|
|
|
surf->u.gfx9.stencil_offset += offset;
|
2020-05-04 07:43:44 -04:00
|
|
|
} else {
|
2020-05-08 16:12:56 -04:00
|
|
|
if (pitch) {
|
|
|
|
|
surf->u.legacy.level[0].nblk_x = pitch;
|
|
|
|
|
surf->u.legacy.level[0].slice_size_dw =
|
|
|
|
|
((uint64_t)pitch * surf->u.legacy.level[0].nblk_y * surf->bpe) / 4;
|
|
|
|
|
}
|
2020-05-04 07:43:44 -04:00
|
|
|
|
|
|
|
|
if (offset) {
|
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(surf->u.legacy.level); ++i)
|
|
|
|
|
surf->u.legacy.level[i].offset += offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-04 07:53:38 -04:00
|
|
|
|
|
|
|
|
if (surf->htile_offset)
|
|
|
|
|
surf->htile_offset += offset;
|
|
|
|
|
if (surf->fmask_offset)
|
|
|
|
|
surf->fmask_offset += offset;
|
|
|
|
|
if (surf->cmask_offset)
|
|
|
|
|
surf->cmask_offset += offset;
|
|
|
|
|
if (surf->dcc_offset)
|
|
|
|
|
surf->dcc_offset += offset;
|
|
|
|
|
if (surf->display_dcc_offset)
|
|
|
|
|
surf->display_dcc_offset += offset;
|
|
|
|
|
if (surf->dcc_retile_map_offset)
|
|
|
|
|
surf->dcc_retile_map_offset += offset;
|
2020-05-04 07:43:44 -04:00
|
|
|
}
|