From: Kristian Høgsberg Date: Tue, 1 Dec 2015 23:25:07 +0000 (-0800) Subject: vk: Implement vkFlushMappedMemoryRanges() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e0b5f0308c78ff5e6f7459a0f7d05e3fb376a104;p=mesa.git vk: Implement vkFlushMappedMemoryRanges() We'll do a runtime switch on device->info.has_llc for now. --- diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index c25ad34a613..724c4120a06 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -1035,22 +1035,57 @@ void anv_UnmapMemory( anv_gem_munmap(mem->map, mem->map_size); } +static void +clflush_mapped_ranges(struct anv_device *device, + uint32_t count, + const VkMappedMemoryRange *ranges) +{ + for (uint32_t i = 0; i < count; i++) { + ANV_FROM_HANDLE(anv_device_memory, mem, ranges[i].memory); + void *p = mem->map + (ranges[i].offset & ~CACHELINE_MASK); + void *end = mem->map + ranges[i].offset + ranges[i].size; + + while (p < end) { + __builtin_ia32_clflush(p); + p += CACHELINE_SIZE; + } + } +} + VkResult anv_FlushMappedMemoryRanges( - VkDevice device, + VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges) { - /* clflush here for !llc platforms */ + ANV_FROM_HANDLE(anv_device, device, _device); + + if (device->info.has_llc) + return VK_SUCCESS; + + /* Make sure the writes we're flushing have landed. */ + __builtin_ia32_sfence(); + + clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); return VK_SUCCESS; } VkResult anv_InvalidateMappedMemoryRanges( - VkDevice device, + VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges) { - return anv_FlushMappedMemoryRanges(device, memoryRangeCount, pMemoryRanges); + ANV_FROM_HANDLE(anv_device, device, _device); + + if (device->info.has_llc) + return VK_SUCCESS; + + clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); + + /* Make sure no reads get moved up above the invalidate. */ + __builtin_ia32_lfence(); + + return VK_SUCCESS; } void anv_GetBufferMemoryRequirements( diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 3fc305ba15e..c21d9d7c856 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -391,6 +391,9 @@ struct anv_state_stream { uint32_t end; }; +#define CACHELINE_SIZE 64 +#define CACHELINE_MASK 63 + void anv_block_pool_init(struct anv_block_pool *pool, struct anv_device *device, uint32_t block_size); void anv_block_pool_finish(struct anv_block_pool *pool);