From 367031a5c82b62ec3359dab862387e679093c9b7 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sun, 23 Apr 2017 18:25:17 -0700 Subject: [PATCH] anv: Get rid of a bunch of uses of size_t We should only use size_t when referring to sizes of bits of CPU memory. Anything on the GPU or just a regular array length should be a type that has the same size on both 32 and 64-bit architectures. For state objects, we use a uint32_t because we'll never allocate a piece of driver-internal GPU state larger than 2GB (more like 16KB). Reviewed-by: Juan A. Suarez Romero --- src/intel/vulkan/anv_allocator.c | 12 ++++++------ src/intel/vulkan/anv_gem.c | 2 +- src/intel/vulkan/anv_gem_stubs.c | 2 +- src/intel/vulkan/anv_private.h | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index d332e895695..592ab1caa15 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -344,7 +344,7 @@ anv_block_pool_finish(struct anv_block_pool *pool) static uint32_t anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state) { - size_t size; + uint32_t size; void *map; uint32_t gem_handle; struct anv_mmap_cleanup *cleanup; @@ -369,7 +369,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state) assert(state == &pool->state || back_used > 0); - size_t old_size = pool->bo.size; + uint32_t old_size = pool->bo.size; if (old_size != 0 && back_used * 2 <= pool->center_bo_offset && @@ -618,7 +618,7 @@ anv_block_pool_free(struct anv_block_pool *pool, int32_t offset) static void anv_fixed_size_state_pool_init(struct anv_fixed_size_state_pool *pool, - size_t state_size) + uint32_t state_size) { /* At least a cache line and must divide the block size. */ assert(state_size >= 64 && util_is_power_of_two(state_size)); @@ -677,7 +677,7 @@ anv_state_pool_init(struct anv_state_pool *pool, { pool->block_pool = block_pool; for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) { - size_t size = 1 << (ANV_MIN_STATE_SIZE_LOG2 + i); + uint32_t size = 1 << (ANV_MIN_STATE_SIZE_LOG2 + i); anv_fixed_size_state_pool_init(&pool->buckets[i], size); } VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false)); @@ -691,7 +691,7 @@ anv_state_pool_finish(struct anv_state_pool *pool) static struct anv_state anv_state_pool_alloc_no_vg(struct anv_state_pool *pool, - size_t size, size_t align) + uint32_t size, uint32_t align) { unsigned size_log2 = ilog2_round_up(size < align ? align : size); assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2); @@ -708,7 +708,7 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool, } struct anv_state -anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t align) +anv_state_pool_alloc(struct anv_state_pool *pool, uint32_t size, uint32_t align) { if (size == 0) return ANV_STATE_NULL; diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c index 185086fefcc..4b6ee580702 100644 --- a/src/intel/vulkan/anv_gem.c +++ b/src/intel/vulkan/anv_gem.c @@ -48,7 +48,7 @@ anv_ioctl(int fd, unsigned long request, void *arg) * Return gem handle, or 0 on failure. Gem handles are never 0. */ uint32_t -anv_gem_create(struct anv_device *device, size_t size) +anv_gem_create(struct anv_device *device, uint64_t size) { struct drm_i915_gem_create gem_create = { .size = size, diff --git a/src/intel/vulkan/anv_gem_stubs.c b/src/intel/vulkan/anv_gem_stubs.c index a63e96d52be..8d81eb5b289 100644 --- a/src/intel/vulkan/anv_gem_stubs.c +++ b/src/intel/vulkan/anv_gem_stubs.c @@ -34,7 +34,7 @@ memfd_create(const char *name, unsigned int flags) } uint32_t -anv_gem_create(struct anv_device *device, size_t size) +anv_gem_create(struct anv_device *device, uint64_t size) { int fd = memfd_create("fake bo", MFD_CLOEXEC); if (fd == -1) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 27ae0d294b1..bab0e6bd984 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -493,7 +493,7 @@ struct anv_state { #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 }) struct anv_fixed_size_state_pool { - size_t state_size; + uint32_t state_size; union anv_free_list free_list; struct anv_block_state block; }; @@ -565,7 +565,7 @@ void anv_state_pool_init(struct anv_state_pool *pool, struct anv_block_pool *block_pool); void anv_state_pool_finish(struct anv_state_pool *pool); struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool, - size_t state_size, size_t alignment); + uint32_t state_size, uint32_t alignment); void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state); void anv_state_stream_init(struct anv_state_stream *stream, struct anv_state_pool *state_pool, @@ -778,7 +778,7 @@ VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo, void* anv_gem_mmap(struct anv_device *device, uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags); void anv_gem_munmap(void *p, uint64_t size); -uint32_t anv_gem_create(struct anv_device *device, size_t size); +uint32_t anv_gem_create(struct anv_device *device, uint64_t size); void anv_gem_close(struct anv_device *device, uint32_t gem_handle); uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size); int anv_gem_busy(struct anv_device *device, uint32_t gem_handle); @@ -806,8 +806,8 @@ int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle, VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size); struct anv_reloc_list { - size_t num_relocs; - size_t array_length; + uint32_t num_relocs; + uint32_t array_length; struct drm_i915_gem_relocation_entry * relocs; struct anv_bo ** reloc_bos; }; @@ -829,7 +829,7 @@ struct anv_batch_bo { struct anv_bo bo; /* Bytes actually consumed in this batch BO */ - size_t length; + uint32_t length; struct anv_reloc_list relocs; }; -- 2.30.2