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 <jasuarez@igalia.com>tags/17.2-branchpoint
static uint32_t | static uint32_t | ||||
anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state) | anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state) | ||||
{ | { | ||||
size_t size; | |||||
uint32_t size; | |||||
void *map; | void *map; | ||||
uint32_t gem_handle; | uint32_t gem_handle; | ||||
struct anv_mmap_cleanup *cleanup; | struct anv_mmap_cleanup *cleanup; | ||||
assert(state == &pool->state || back_used > 0); | 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 && | if (old_size != 0 && | ||||
back_used * 2 <= pool->center_bo_offset && | back_used * 2 <= pool->center_bo_offset && | ||||
static void | static void | ||||
anv_fixed_size_state_pool_init(struct anv_fixed_size_state_pool *pool, | 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. */ | /* At least a cache line and must divide the block size. */ | ||||
assert(state_size >= 64 && util_is_power_of_two(state_size)); | assert(state_size >= 64 && util_is_power_of_two(state_size)); | ||||
{ | { | ||||
pool->block_pool = block_pool; | pool->block_pool = block_pool; | ||||
for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) { | 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); | anv_fixed_size_state_pool_init(&pool->buckets[i], size); | ||||
} | } | ||||
VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false)); | VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false)); | ||||
static struct anv_state | static struct anv_state | ||||
anv_state_pool_alloc_no_vg(struct anv_state_pool *pool, | 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); | unsigned size_log2 = ilog2_round_up(size < align ? align : size); | ||||
assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2); | assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2); | ||||
} | } | ||||
struct anv_state | 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) | if (size == 0) | ||||
return ANV_STATE_NULL; | return ANV_STATE_NULL; |
* Return gem handle, or 0 on failure. Gem handles are never 0. | * Return gem handle, or 0 on failure. Gem handles are never 0. | ||||
*/ | */ | ||||
uint32_t | 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 = { | struct drm_i915_gem_create gem_create = { | ||||
.size = size, | .size = size, |
} | } | ||||
uint32_t | 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); | int fd = memfd_create("fake bo", MFD_CLOEXEC); | ||||
if (fd == -1) | if (fd == -1) |
#define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 }) | #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 }) | ||||
struct anv_fixed_size_state_pool { | struct anv_fixed_size_state_pool { | ||||
size_t state_size; | |||||
uint32_t state_size; | |||||
union anv_free_list free_list; | union anv_free_list free_list; | ||||
struct anv_block_state block; | struct anv_block_state block; | ||||
}; | }; | ||||
struct anv_block_pool *block_pool); | struct anv_block_pool *block_pool); | ||||
void anv_state_pool_finish(struct anv_state_pool *pool); | void anv_state_pool_finish(struct anv_state_pool *pool); | ||||
struct anv_state anv_state_pool_alloc(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_pool_free(struct anv_state_pool *pool, struct anv_state state); | ||||
void anv_state_stream_init(struct anv_state_stream *stream, | void anv_state_stream_init(struct anv_state_stream *stream, | ||||
struct anv_state_pool *state_pool, | struct anv_state_pool *state_pool, | ||||
void* anv_gem_mmap(struct anv_device *device, | void* anv_gem_mmap(struct anv_device *device, | ||||
uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags); | uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags); | ||||
void anv_gem_munmap(void *p, uint64_t size); | 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); | 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); | 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); | int anv_gem_busy(struct anv_device *device, uint32_t gem_handle); | ||||
VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size); | VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size); | ||||
struct anv_reloc_list { | 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 drm_i915_gem_relocation_entry * relocs; | ||||
struct anv_bo ** reloc_bos; | struct anv_bo ** reloc_bos; | ||||
}; | }; | ||||
struct anv_bo bo; | struct anv_bo bo; | ||||
/* Bytes actually consumed in this batch BO */ | /* Bytes actually consumed in this batch BO */ | ||||
size_t length; | |||||
uint32_t length; | |||||
struct anv_reloc_list relocs; | struct anv_reloc_list relocs; | ||||
}; | }; |