Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 28 | #include "dev.h" |
| 29 | #include "mem.h" |
| 30 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 31 | VkResult intel_mem_alloc(struct intel_dev *dev, |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 32 | const VkMemoryAllocInfo *info, |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 33 | struct intel_mem **mem_ret) |
| 34 | { |
| 35 | struct intel_mem *mem; |
| 36 | |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 37 | /* ignore any IMAGE_INFO and BUFFER_INFO usage: they don't alter allocations */ |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 38 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 39 | mem = (struct intel_mem *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 40 | sizeof(*mem), dev->base.dbg, VK_OBJECT_TYPE_DEVICE_MEMORY, info, 0); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 41 | if (!mem) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 42 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 43 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 44 | mem->bo = intel_winsys_alloc_bo(dev->winsys, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 45 | "vk-gpu-memory", info->allocationSize, 0); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 46 | if (!mem->bo) { |
| 47 | intel_mem_free(mem); |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 48 | return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Chia-I Wu | 000747d | 2014-08-20 15:39:36 +0800 | [diff] [blame] | 51 | mem->size = info->allocationSize; |
| 52 | |
Courtney Goeltzenleuchter | c35ab46 | 2014-08-06 17:10:04 -0600 | [diff] [blame] | 53 | *mem_ret = mem; |
| 54 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 55 | return VK_SUCCESS; |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void intel_mem_free(struct intel_mem *mem) |
| 59 | { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 60 | intel_bo_unref(mem->bo); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 61 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 62 | intel_base_destroy(&mem->base); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 63 | } |
| 64 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 65 | ICD_EXPORT VkResult VKAPI vkAllocMemory( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 66 | VkDevice device, |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 67 | const VkMemoryAllocInfo* pAllocInfo, |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 68 | VkDeviceMemory* pMem) |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 69 | { |
| 70 | struct intel_dev *dev = intel_dev(device); |
| 71 | |
| 72 | return intel_mem_alloc(dev, pAllocInfo, (struct intel_mem **) pMem); |
| 73 | } |
| 74 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 75 | ICD_EXPORT void VKAPI vkFreeMemory( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 76 | VkDevice device, |
| 77 | VkDeviceMemory mem_) |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 78 | { |
| 79 | struct intel_mem *mem = intel_mem(mem_); |
| 80 | |
| 81 | intel_mem_free(mem); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 84 | ICD_EXPORT VkResult VKAPI vkMapMemory( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 85 | VkDevice device, |
Tony Barbour | 3e3420a | 2015-04-16 19:09:28 -0600 | [diff] [blame] | 86 | VkDeviceMemory mem_, |
| 87 | VkDeviceSize offset, |
| 88 | VkDeviceSize size, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 89 | VkFlags flags, |
Tony Barbour | 3e3420a | 2015-04-16 19:09:28 -0600 | [diff] [blame] | 90 | void** ppData) |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 91 | { |
| 92 | struct intel_mem *mem = intel_mem(mem_); |
| 93 | void *ptr = intel_mem_map(mem, flags); |
| 94 | |
Tony Barbour | 3e3420a | 2015-04-16 19:09:28 -0600 | [diff] [blame] | 95 | *ppData = (void *)((size_t)ptr + offset); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 96 | |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 97 | return (ptr) ? VK_SUCCESS : VK_ERROR_MEMORY_MAP_FAILED; |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 100 | ICD_EXPORT void VKAPI vkUnmapMemory( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 101 | VkDevice device, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 102 | VkDeviceMemory mem_) |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 103 | { |
| 104 | struct intel_mem *mem = intel_mem(mem_); |
| 105 | |
| 106 | intel_mem_unmap(mem); |
Chia-I Wu | f9911eb | 2014-08-06 13:50:31 +0800 | [diff] [blame] | 107 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 108 | |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 109 | ICD_EXPORT VkResult VKAPI vkFlushMappedMemoryRanges( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 110 | VkDevice device, |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 111 | uint32_t memRangeCount, |
| 112 | const VkMappedMemoryRange* pMemRanges) |
| 113 | { |
| 114 | return VK_SUCCESS; |
| 115 | } |
| 116 | |
| 117 | ICD_EXPORT VkResult VKAPI vkInvalidateMappedMemoryRanges( |
| 118 | VkDevice device, |
| 119 | uint32_t memRangeCount, |
| 120 | const VkMappedMemoryRange* pMemRanges) |
Tony Barbour | 859ceab | 2015-04-16 19:23:13 -0600 | [diff] [blame] | 121 | { |
| 122 | return VK_SUCCESS; |
| 123 | } |
Courtney Goeltzenleuchter | d040c5c | 2015-07-09 21:57:28 -0600 | [diff] [blame] | 124 | |
Courtney Goeltzenleuchter | 01d2ae1 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 125 | ICD_EXPORT void VKAPI vkGetDeviceMemoryCommitment( |
Courtney Goeltzenleuchter | d040c5c | 2015-07-09 21:57:28 -0600 | [diff] [blame] | 126 | VkDevice device, |
| 127 | VkDeviceMemory memory, |
| 128 | VkDeviceSize* pCommittedMemoryInBytes) |
| 129 | { |
Courtney Goeltzenleuchter | d040c5c | 2015-07-09 21:57:28 -0600 | [diff] [blame] | 130 | } |