anv: Fixes struct anv_device::info is not initialized with struct anv_physical_device
authorYonggang Luo <luoyonggang@gmail.com>
Mon, 22 Aug 2022 12:07:21 +0000 (20:07 +0800)
committerMarge Bot <emma+marge@anholt.net>
Mon, 22 Aug 2022 14:18:53 +0000 (14:18 +0000)
Refactoring the function anv_device_set_physical out, so that it's can be called in unittests

Fixes: 356a60bd6c5 ("anv: Do not duplicate intel_device_info memory in each logical device")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7092

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: José Roberto de Souza jose.souza@intel.com
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17928>

src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/tests/block_pool_grow_first.c
src/intel/vulkan/tests/block_pool_no_free.c
src/intel/vulkan/tests/state_pool.c
src/intel/vulkan/tests/state_pool_free_list_only.c
src/intel/vulkan/tests/state_pool_no_free.c
src/intel/vulkan/tests/state_pool_padding.c

index ae7ed92..30b3893 100644 (file)
@@ -3146,7 +3146,7 @@ VkResult anv_CreateDevice(
          INSTRUCTION_STATE_POOL_MIN_ADDRESS;
    }
 
-   device->physical = physical_device;
+   anv_device_set_physical(device, physical_device);
 
    /* XXX(chadv): Can we dup() physicalDevice->fd here? */
    device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
@@ -3271,8 +3271,6 @@ VkResult anv_CreateDevice(
       }
    }
 
-   device->info = &physical_device->info;
-   device->isl_dev = physical_device->isl_dev;
 
    /* On Broadwell and later, we can use batch chaining to more efficiently
     * implement growing command buffers.  Prior to Haswell, the kernel
index 2918738..39c2b8c 100644 (file)
@@ -1410,6 +1410,14 @@ VkResult anv_device_set_bo_tiling(struct anv_device *device,
 void anv_device_release_bo(struct anv_device *device,
                            struct anv_bo *bo);
 
+static inline void anv_device_set_physical(struct anv_device *device,
+                                           struct anv_physical_device *physical_device)
+{
+   device->physical = physical_device;
+   device->info = &physical_device->info;
+   device->isl_dev = physical_device->isl_dev;
+}
+
 static inline struct anv_bo *
 anv_device_lookup_bo(struct anv_device *device, uint32_t gem_handle)
 {
index d2d2b4f..109275b 100644 (file)
@@ -29,9 +29,7 @@ int main(void)
    struct anv_physical_device physical_device = {
       .use_softpin = true,
    };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_block_pool pool;
 
    /* Create a pool with initial size smaller than the block allocated, so
@@ -40,6 +38,7 @@ int main(void)
    const uint32_t block_size = 16 * 1024;
    const uint32_t initial_size = block_size / 2;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
    anv_block_pool_init(&pool, &device, "test", 4096, initial_size);
index f7cc85e..e0e24dc 100644 (file)
@@ -113,11 +113,10 @@ static void run_test()
    struct anv_physical_device physical_device = {
       .use_relocations = true,
    };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_block_pool pool;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
    anv_block_pool_init(&pool, &device, "test", 4096, 4096);
index 0b685ca..57cfa73 100644 (file)
 int main(void)
 {
    struct anv_physical_device physical_device = { };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_state_pool state_pool;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
 
index b5e5146..602346f 100644 (file)
 int main(void)
 {
    struct anv_physical_device physical_device = { };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_state_pool state_pool;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
    anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 4096);
index 0424546..fe07683 100644 (file)
@@ -56,11 +56,10 @@ static void *alloc_states(void *_job)
 static void run_test()
 {
    struct anv_physical_device physical_device = { };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_state_pool state_pool;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
    anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 64);
index 54e8bc9..0ed72e1 100644 (file)
@@ -29,11 +29,10 @@ int main(void)
    struct anv_physical_device physical_device = {
       .use_softpin = true,
    };
-   struct anv_device device = {
-      .physical = &physical_device,
-   };
+   struct anv_device device = {};
    struct anv_state_pool state_pool;
 
+   anv_device_set_physical(&device, &physical_device);
    pthread_mutex_init(&device.mutex, NULL);
    anv_bo_cache_init(&device.bo_cache, &device);
    anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 4096);