From bbb6875f35c783d4f350dc9fbf2e2904b3d47a5a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg=20Kristensen?= Date: Thu, 3 Dec 2015 23:58:05 -0800 Subject: [PATCH] vk: Map uncached, coherent memory as write-combine This gives us the required characteristics for the memory type. --- src/vulkan/anv_allocator.c | 2 +- src/vulkan/anv_device.c | 14 ++++++++++++-- src/vulkan/anv_gem.c | 7 ++----- src/vulkan/anv_private.h | 2 +- src/vulkan/anv_query.c | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/vulkan/anv_allocator.c b/src/vulkan/anv_allocator.c index 970d809e8a3..e8129c6d909 100644 --- a/src/vulkan/anv_allocator.c +++ b/src/vulkan/anv_allocator.c @@ -825,7 +825,7 @@ anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo) assert(new_bo.size == pool->bo_size); - new_bo.map = anv_gem_mmap(pool->device, new_bo.gem_handle, 0, pool->bo_size); + new_bo.map = anv_gem_mmap(pool->device, new_bo.gem_handle, 0, pool->bo_size, 0); if (new_bo.map == NULL) { anv_gem_close(pool->device, new_bo.gem_handle); return vk_error(VK_ERROR_MEMORY_MAP_FAILED); diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index a8bc409144d..7e1b552ca7f 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -121,6 +121,12 @@ anv_physical_device_init(struct anv_physical_device *device, goto fail; } + if (anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION < 1)) { + result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + "kernel missing wc mmap"); + goto fail; + } + close(fd); brw_process_intel_debug_variable(); @@ -1059,7 +1065,11 @@ VkResult anv_MapMemory( * pointer here, but that may exhaust virtual memory on 32 bit * userspace. */ - mem->map = anv_gem_mmap(device, mem->bo.gem_handle, offset, size); + uint32_t gem_flags = 0; + if (!device->info.has_llc && mem->type_index == 0) + gem_flags |= I915_MMAP_WC; + + mem->map = anv_gem_mmap(device, mem->bo.gem_handle, offset, size, gem_flags); mem->map_size = size; *ppData = mem->map; @@ -1254,7 +1264,7 @@ VkResult anv_CreateFence( goto fail; fence->bo.map = - anv_gem_mmap(device, fence->bo.gem_handle, 0, fence->bo.size); + anv_gem_mmap(device, fence->bo.gem_handle, 0, fence->bo.size, 0); batch.next = batch.start = fence->bo.map; batch.end = fence->bo.map + fence->bo.size; anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END); diff --git a/src/vulkan/anv_gem.c b/src/vulkan/anv_gem.c index 57b8505e156..429f4a29fad 100644 --- a/src/vulkan/anv_gem.c +++ b/src/vulkan/anv_gem.c @@ -84,7 +84,7 @@ anv_gem_close(struct anv_device *device, int gem_handle) */ void* anv_gem_mmap(struct anv_device *device, uint32_t gem_handle, - uint64_t offset, uint64_t size) + uint64_t offset, uint64_t size, uint32_t flags) { struct drm_i915_gem_mmap gem_mmap; int ret; @@ -94,10 +94,7 @@ anv_gem_mmap(struct anv_device *device, uint32_t gem_handle, gem_mmap.offset = offset; gem_mmap.size = size; VG_CLEAR(gem_mmap.addr_ptr); - -#ifdef I915_MMAP_WC - gem_mmap.flags = 0; -#endif + gem_mmap.flags = flags; ret = anv_ioctl(device->fd, DRM_IOCTL_I915_GEM_MMAP, &gem_mmap); if (ret != 0) { diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 7c8cf241624..cc0281a0d9a 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -597,7 +597,7 @@ struct anv_device { }; void* anv_gem_mmap(struct anv_device *device, - uint32_t gem_handle, uint64_t offset, uint64_t size); + 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); void anv_gem_close(struct anv_device *device, int gem_handle); diff --git a/src/vulkan/anv_query.c b/src/vulkan/anv_query.c index 911b9a41264..6f9d7d89aa6 100644 --- a/src/vulkan/anv_query.c +++ b/src/vulkan/anv_query.c @@ -69,7 +69,7 @@ VkResult anv_CreateQueryPool( if (result != VK_SUCCESS) goto fail; - pool->bo.map = anv_gem_mmap(device, pool->bo.gem_handle, 0, size); + pool->bo.map = anv_gem_mmap(device, pool->bo.gem_handle, 0, size, 0); *pQueryPool = anv_query_pool_to_handle(pool); -- 2.30.2