From 4cf674c8f730bfa7c8dfe8b4ebe86f1f4e5f1bb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 9 Jun 2020 03:19:04 -0400 Subject: [PATCH] ac/surface: add a wrapper structure to hold ADDR_HANDLE and more things in the future. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/common/ac_surface.c | 64 ++++++++++++------- src/amd/common/ac_surface.h | 11 ++-- .../vulkan/winsys/amdgpu/radv_amdgpu_winsys.c | 4 +- .../vulkan/winsys/amdgpu/radv_amdgpu_winsys.h | 3 +- src/amd/vulkan/winsys/null/radv_null_winsys.h | 1 - src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 4 +- src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h | 3 +- 7 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/amd/common/ac_surface.c b/src/amd/common/ac_surface.c index 6621411b008..a3f54d84106 100644 --- a/src/amd/common/ac_surface.c +++ b/src/amd/common/ac_surface.c @@ -50,6 +50,10 @@ #define CIASICIDGFXENGINE_ARCTICISLAND 0x0000000D #endif +struct ac_addrlib { + ADDR_HANDLE handle; +}; + static void *ADDR_API allocSysMem(const ADDR_ALLOCSYSMEM_INPUT * pInput) { return malloc(pInput->sizeInBytes); @@ -61,9 +65,9 @@ static ADDR_E_RETURNCODE ADDR_API freeSysMem(const ADDR_FREESYSMEM_INPUT * pInpu return ADDR_OK; } -ADDR_HANDLE amdgpu_addr_create(const struct radeon_info *info, - const struct amdgpu_gpu_info *amdinfo, - uint64_t *max_alignment) +struct ac_addrlib *ac_addrlib_create(const struct radeon_info *info, + const struct amdgpu_gpu_info *amdinfo, + uint64_t *max_alignment) { ADDR_CREATE_INPUT addrCreateInput = {0}; ADDR_CREATE_OUTPUT addrCreateOutput = {0}; @@ -123,7 +127,21 @@ ADDR_HANDLE amdgpu_addr_create(const struct radeon_info *info, *max_alignment = addrGetMaxAlignmentsOutput.baseAlign; } } - return addrCreateOutput.hLib; + + struct ac_addrlib *addrlib = calloc(1, sizeof(struct ac_addrlib)); + if (!addrlib) { + AddrDestroy(addrCreateOutput.hLib); + return NULL; + } + + addrlib->handle = addrCreateOutput.hLib; + return addrlib; +} + +void ac_addrlib_destroy(struct ac_addrlib *addrlib) +{ + AddrDestroy(addrlib->handle); + free(addrlib); } static int surf_config_sanity(const struct ac_surf_config *config, @@ -1124,7 +1142,7 @@ static bool is_dcc_supported_by_DCN(const struct radeon_info *info, } } -static int gfx9_compute_miptree(ADDR_HANDLE addrlib, +static int gfx9_compute_miptree(struct ac_addrlib *addrlib, const struct radeon_info *info, const struct ac_surf_config *config, struct radeon_surf *surf, bool compressed, @@ -1137,7 +1155,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, out.size = sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT); out.pMipInfo = mip_info; - ret = Addr2ComputeSurfaceInfo(addrlib, in, &out); + ret = Addr2ComputeSurfaceInfo(addrlib->handle, in, &out); if (ret != ADDR_OK) return ret; @@ -1209,7 +1227,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, hin.numMipLevels = in->numMipLevels; hin.firstMipIdInTail = out.firstMipIdInTail; - ret = Addr2ComputeHtileInfo(addrlib, &hin, &hout); + ret = Addr2ComputeHtileInfo(addrlib->handle, &hin, &hout); if (ret != ADDR_OK) return ret; @@ -1242,7 +1260,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, xin.numSamples = in->numSamples; xin.numFrags = in->numFrags; - ret = Addr2ComputePipeBankXor(addrlib, &xin, &xout); + ret = Addr2ComputePipeBankXor(addrlib->handle, &xin, &xout); if (ret != ADDR_OK) return ret; @@ -1282,7 +1300,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, din.dataSurfaceSize = out.surfSize; din.firstMipIdInTail = out.firstMipIdInTail; - ret = Addr2ComputeDccInfo(addrlib, &din, &dout); + ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout); if (ret != ADDR_OK) return ret; @@ -1346,7 +1364,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, assert(surf->u.gfx9.dcc.pipe_aligned || surf->u.gfx9.dcc.rb_aligned); - ret = Addr2ComputeDccInfo(addrlib, &din, &dout); + ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout); if (ret != ADDR_OK) return ret; @@ -1406,7 +1424,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, addrin.dccKeyFlags.rbAligned = surf->u.gfx9.dcc.rb_aligned; addrout.addr = 0; - ret = Addr2ComputeDccAddrFromCoord(addrlib, &addrin, &addrout); + ret = Addr2ComputeDccAddrFromCoord(addrlib->handle, &addrin, &addrout); if (ret != ADDR_OK) return ret; @@ -1417,7 +1435,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, addrin.dccKeyFlags.rbAligned = 0; addrout.addr = 0; - ret = Addr2ComputeDccAddrFromCoord(addrlib, &addrin, &addrout); + ret = Addr2ComputeDccAddrFromCoord(addrlib->handle, &addrin, &addrout); if (ret != ADDR_OK) return ret; @@ -1443,7 +1461,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, fin.size = sizeof(ADDR2_COMPUTE_FMASK_INFO_INPUT); fout.size = sizeof(ADDR2_COMPUTE_FMASK_INFO_OUTPUT); - ret = gfx9_get_preferred_swizzle_mode(addrlib, surf, in, + ret = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, in, true, &fin.swizzleMode); if (ret != ADDR_OK) return ret; @@ -1454,7 +1472,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, fin.numSamples = in->numSamples; fin.numFrags = in->numFrags; - ret = Addr2ComputeFmaskInfo(addrlib, &fin, &fout); + ret = Addr2ComputeFmaskInfo(addrlib->handle, &fin, &fout); if (ret != ADDR_OK) return ret; @@ -1482,7 +1500,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, xin.numSamples = in->numSamples; xin.numFrags = in->numFrags; - ret = Addr2ComputePipeBankXor(addrlib, &xin, &xout); + ret = Addr2ComputePipeBankXor(addrlib->handle, &xin, &xout); if (ret != ADDR_OK) return ret; @@ -1522,7 +1540,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, else cin.swizzleMode = in->swizzleMode; - ret = Addr2ComputeCmaskInfo(addrlib, &cin, &cout); + ret = Addr2ComputeCmaskInfo(addrlib->handle, &cin, &cout); if (ret != ADDR_OK) return ret; @@ -1534,7 +1552,7 @@ static int gfx9_compute_miptree(ADDR_HANDLE addrlib, return 0; } -static int gfx9_compute_surface(ADDR_HANDLE addrlib, +static int gfx9_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info, const struct ac_surf_config *config, enum radeon_surf_mode mode, @@ -1697,7 +1715,7 @@ static int gfx9_compute_surface(ADDR_HANDLE addrlib, break; } - r = gfx9_get_preferred_swizzle_mode(addrlib, surf, &AddrSurfInfoIn, + r = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, &AddrSurfInfoIn, false, &AddrSurfInfoIn.swizzleMode); if (r) return r; @@ -1736,7 +1754,7 @@ static int gfx9_compute_surface(ADDR_HANDLE addrlib, AddrSurfInfoIn.format = ADDR_FMT_8; if (!AddrSurfInfoIn.flags.depth) { - r = gfx9_get_preferred_swizzle_mode(addrlib, surf, &AddrSurfInfoIn, + r = gfx9_get_preferred_swizzle_mode(addrlib->handle, surf, &AddrSurfInfoIn, false, &AddrSurfInfoIn.swizzleMode); if (r) goto error; @@ -1755,8 +1773,8 @@ static int gfx9_compute_surface(ADDR_HANDLE addrlib, /* This is only useful for surfaces that are allocated without SCANOUT. */ bool displayable = false; if (!config->is_3d && !config->is_cube) { - r = Addr2IsValidDisplaySwizzleMode(addrlib, surf->u.gfx9.surf.swizzle_mode, - surf->bpe * 8, &displayable); + r = Addr2IsValidDisplaySwizzleMode(addrlib->handle, surf->u.gfx9.surf.swizzle_mode, + surf->bpe * 8, &displayable); if (r) goto error; @@ -1873,7 +1891,7 @@ error: return r; } -int ac_compute_surface(ADDR_HANDLE addrlib, const struct radeon_info *info, +int ac_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info, const struct ac_surf_config *config, enum radeon_surf_mode mode, struct radeon_surf *surf) @@ -1887,7 +1905,7 @@ int ac_compute_surface(ADDR_HANDLE addrlib, const struct radeon_info *info, if (info->chip_class >= GFX9) r = gfx9_compute_surface(addrlib, info, config, mode, surf); else - r = gfx6_compute_surface(addrlib, info, config, mode, surf); + r = gfx6_compute_surface(addrlib->handle, info, config, mode, surf); if (r) return r; diff --git a/src/amd/common/ac_surface.h b/src/amd/common/ac_surface.h index 22858206e46..ad8e3e53eb2 100644 --- a/src/amd/common/ac_surface.h +++ b/src/amd/common/ac_surface.h @@ -36,7 +36,7 @@ extern "C" { #endif /* Forward declarations. */ -typedef void* ADDR_HANDLE; +struct ac_addrlib; struct amdgpu_gpu_info; struct radeon_info; @@ -282,11 +282,12 @@ struct ac_surf_config { unsigned is_cube : 1; }; -ADDR_HANDLE amdgpu_addr_create(const struct radeon_info *info, - const struct amdgpu_gpu_info *amdinfo, - uint64_t *max_alignment); +struct ac_addrlib *ac_addrlib_create(const struct radeon_info *info, + const struct amdgpu_gpu_info *amdinfo, + uint64_t *max_alignment); +void ac_addrlib_destroy(struct ac_addrlib *addrlib); -int ac_compute_surface(ADDR_HANDLE addrlib, const struct radeon_info *info, +int ac_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info, const struct ac_surf_config * config, enum radeon_surf_mode mode, struct radeon_surf *surf); diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c index acb003e1533..0f7f5bcf3bf 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c @@ -55,7 +55,7 @@ do_winsys_init(struct radv_amdgpu_winsys *ws, int fd) ws->info.use_display_dcc_unaligned = false; ws->info.use_display_dcc_with_retile_blit = false; - ws->addrlib = amdgpu_addr_create(&ws->info, &ws->amdinfo, &ws->info.max_alignment); + ws->addrlib = ac_addrlib_create(&ws->info, &ws->amdinfo, &ws->info.max_alignment); if (!ws->addrlib) { fprintf(stderr, "amdgpu: Cannot create addrlib.\n"); return false; @@ -156,7 +156,7 @@ static void radv_amdgpu_winsys_destroy(struct radeon_winsys *rws) { struct radv_amdgpu_winsys *ws = (struct radv_amdgpu_winsys*)rws; - AddrDestroy(ws->addrlib); + ac_addrlib_destroy(ws->addrlib); amdgpu_device_deinitialize(ws->dev); FREE(rws); } diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h index 8cbac290043..166b2dfe1ca 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h @@ -30,7 +30,6 @@ #include "radv_radeon_winsys.h" #include "ac_gpu_info.h" -#include "addrlib/inc/addrinterface.h" #include #include "util/list.h" #include @@ -41,7 +40,7 @@ struct radv_amdgpu_winsys { struct radeon_info info; struct amdgpu_gpu_info amdinfo; - ADDR_HANDLE addrlib; + struct ac_addrlib *addrlib; bool debug_all_bos; bool use_ib_bos; diff --git a/src/amd/vulkan/winsys/null/radv_null_winsys.h b/src/amd/vulkan/winsys/null/radv_null_winsys.h index 7953ab4792d..5bb31a7ffba 100644 --- a/src/amd/vulkan/winsys/null/radv_null_winsys.h +++ b/src/amd/vulkan/winsys/null/radv_null_winsys.h @@ -30,7 +30,6 @@ #include "radv_radeon_winsys.h" #include "ac_gpu_info.h" -#include "addrlib/inc/addrinterface.h" #include "util/list.h" #include diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index 2ef7eaa7642..b4ae6cf1223 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -100,7 +100,7 @@ static bool do_winsys_init(struct amdgpu_winsys *ws, handle_env_var_force_family(ws); - ws->addrlib = amdgpu_addr_create(&ws->info, &ws->amdinfo, &ws->info.max_alignment); + ws->addrlib = ac_addrlib_create(&ws->info, &ws->amdinfo, &ws->info.max_alignment); if (!ws->addrlib) { fprintf(stderr, "amdgpu: Cannot create addrlib.\n"); goto fail; @@ -147,7 +147,7 @@ static void do_winsys_deinit(struct amdgpu_winsys *ws) simple_mtx_destroy(&ws->global_bo_list_lock); simple_mtx_destroy(&ws->bo_export_table_lock); - AddrDestroy(ws->addrlib); + ac_addrlib_destroy(ws->addrlib); amdgpu_device_deinitialize(ws->dev); FREE(ws); } diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h index e6ce1221d97..36fa43d7946 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h @@ -31,7 +31,6 @@ #include "pipebuffer/pb_cache.h" #include "pipebuffer/pb_slab.h" #include "gallium/drivers/radeon/radeon_winsys.h" -#include "addrlib/inc/addrinterface.h" #include "util/simple_mtx.h" #include "util/u_queue.h" #include @@ -80,7 +79,7 @@ struct amdgpu_winsys { struct util_queue cs_queue; struct amdgpu_gpu_info amdinfo; - ADDR_HANDLE addrlib; + struct ac_addrlib *addrlib; bool check_vm; bool debug_all_bos; -- 2.30.2