ac/surface: add a wrapper structure to hold ADDR_HANDLE
authorMarek Olšák <marek.olsak@amd.com>
Tue, 9 Jun 2020 07:19:04 +0000 (03:19 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 10 Jun 2020 15:35:46 +0000 (15:35 +0000)
and more things in the future.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5398>

src/amd/common/ac_surface.c
src/amd/common/ac_surface.h
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
src/amd/vulkan/winsys/null/radv_null_winsys.h
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h

index 6621411b0087a989b0a6b1d8d77fae78219c80d7..a3f54d84106bca0368bc389abea423719a40a2a0 100644 (file)
 #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;
index 22858206e462e73bc0b677a78a7a361368df4f52..ad8e3e53eb26e5a19c00d9639ed15e499783d61f 100644 (file)
@@ -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);
index acb003e1533cfe2ae40f995d2f8dfbce9b17a966..0f7f5bcf3bfa91a933629dbcaf20a4bf18254927 100644 (file)
@@ -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);
 }
index 8cbac2900439c437b3dca3dbefe2ff14b9d96a54..166b2dfe1ca04b67d8af02f230c49108417b1e11 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "radv_radeon_winsys.h"
 #include "ac_gpu_info.h"
-#include "addrlib/inc/addrinterface.h"
 #include <amdgpu.h>
 #include "util/list.h"
 #include <pthread.h>
@@ -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;
index 7953ab4792def0fc1b27d72f8471db5078458afe..5bb31a7ffba819d4e58c4029d09d676a491fd17c 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "radv_radeon_winsys.h"
 #include "ac_gpu_info.h"
-#include "addrlib/inc/addrinterface.h"
 #include "util/list.h"
 #include <pthread.h>
 
index 2ef7eaa76420211a37b7638a7e9cf001c0a7ba29..b4ae6cf1223f1f92d381721a2c8b8af76dd85232 100644 (file)
@@ -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);
 }
index e6ce1221d979cfc2f71a82789d524f8cf63faa35..36fa43d7946af9a70fac6eb72042ab603d6bc837 100644 (file)
@@ -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 <amdgpu.h>
@@ -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;