blob: 21936a59038571006b72fd7acfa18f020075f1c8 [file] [log] [blame]
Chia-I Wuf9911eb2014-08-06 13:50:31 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wuf9911eb2014-08-06 13:50:31 +08003 *
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 Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wuf9911eb2014-08-06 13:50:31 +080026 */
27
Chia-I Wuf9911eb2014-08-06 13:50:31 +080028#include "dev.h"
29#include "mem.h"
30
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060031VkResult intel_mem_alloc(struct intel_dev *dev,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060032 const VkMemoryAllocInfo *info,
Chia-I Wuf9911eb2014-08-06 13:50:31 +080033 struct intel_mem **mem_ret)
34{
35 struct intel_mem *mem;
36
Jon Ashburnc6ae13d2015-01-19 15:00:26 -070037 /* ignore any IMAGE_INFO and BUFFER_INFO usage: they don't alter allocations */
Chia-I Wuf9911eb2014-08-06 13:50:31 +080038
Chia-I Wu545c2e12015-02-22 13:19:54 +080039 mem = (struct intel_mem *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060040 sizeof(*mem), dev->base.dbg, VK_OBJECT_TYPE_DEVICE_MEMORY, info, 0);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080041 if (!mem)
Tony Barbour8205d902015-04-16 15:59:00 -060042 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wuf9911eb2014-08-06 13:50:31 +080043
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070044 mem->bo = intel_winsys_alloc_bo(dev->winsys,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045 "vk-gpu-memory", info->allocationSize, 0);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080046 if (!mem->bo) {
47 intel_mem_free(mem);
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -060048 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
Chia-I Wuf9911eb2014-08-06 13:50:31 +080049 }
50
Chia-I Wu000747d2014-08-20 15:39:36 +080051 mem->size = info->allocationSize;
52
Courtney Goeltzenleuchterc35ab462014-08-06 17:10:04 -060053 *mem_ret = mem;
54
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060055 return VK_SUCCESS;
Chia-I Wuf9911eb2014-08-06 13:50:31 +080056}
57
58void intel_mem_free(struct intel_mem *mem)
59{
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070060 intel_bo_unref(mem->bo);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080061
Chia-I Wubbf2c932014-08-07 12:20:08 +080062 intel_base_destroy(&mem->base);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080063}
64
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060065ICD_EXPORT VkResult VKAPI vkAllocMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -060066 VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060067 const VkMemoryAllocInfo* pAllocInfo,
Mike Stroyan230e6252015-04-17 12:36:38 -060068 VkDeviceMemory* pMem)
Chia-I Wuf9911eb2014-08-06 13:50:31 +080069{
70 struct intel_dev *dev = intel_dev(device);
71
72 return intel_mem_alloc(dev, pAllocInfo, (struct intel_mem **) pMem);
73}
74
Mark Lobodzinski67b42b72015-09-07 13:59:43 -060075ICD_EXPORT void VKAPI vkFreeMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -060076 VkDevice device,
77 VkDeviceMemory mem_)
Chia-I Wuf9911eb2014-08-06 13:50:31 +080078{
79 struct intel_mem *mem = intel_mem(mem_);
80
81 intel_mem_free(mem);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080082}
83
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060084ICD_EXPORT VkResult VKAPI vkMapMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -060085 VkDevice device,
Tony Barbour3e3420a2015-04-16 19:09:28 -060086 VkDeviceMemory mem_,
87 VkDeviceSize offset,
88 VkDeviceSize size,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060089 VkFlags flags,
Tony Barbour3e3420a2015-04-16 19:09:28 -060090 void** ppData)
Chia-I Wuf9911eb2014-08-06 13:50:31 +080091{
92 struct intel_mem *mem = intel_mem(mem_);
93 void *ptr = intel_mem_map(mem, flags);
94
Tony Barbour3e3420a2015-04-16 19:09:28 -060095 *ppData = (void *)((size_t)ptr + offset);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080096
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -060097 return (ptr) ? VK_SUCCESS : VK_ERROR_MEMORY_MAP_FAILED;
Chia-I Wuf9911eb2014-08-06 13:50:31 +080098}
99
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600100ICD_EXPORT void VKAPI vkUnmapMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -0600101 VkDevice device,
Tony Barbour8205d902015-04-16 15:59:00 -0600102 VkDeviceMemory mem_)
Chia-I Wuf9911eb2014-08-06 13:50:31 +0800103{
104 struct intel_mem *mem = intel_mem(mem_);
105
106 intel_mem_unmap(mem);
Chia-I Wuf9911eb2014-08-06 13:50:31 +0800107}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800108
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600109ICD_EXPORT VkResult VKAPI vkFlushMappedMemoryRanges(
Mike Stroyan230e6252015-04-17 12:36:38 -0600110 VkDevice device,
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600111 uint32_t memRangeCount,
112 const VkMappedMemoryRange* pMemRanges)
113{
114 return VK_SUCCESS;
115}
116
117ICD_EXPORT VkResult VKAPI vkInvalidateMappedMemoryRanges(
118 VkDevice device,
119 uint32_t memRangeCount,
120 const VkMappedMemoryRange* pMemRanges)
Tony Barbour859ceab2015-04-16 19:23:13 -0600121{
122 return VK_SUCCESS;
123}
Courtney Goeltzenleuchterd040c5c2015-07-09 21:57:28 -0600124
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600125ICD_EXPORT void VKAPI vkGetDeviceMemoryCommitment(
Courtney Goeltzenleuchterd040c5c2015-07-09 21:57:28 -0600126 VkDevice device,
127 VkDeviceMemory memory,
128 VkDeviceSize* pCommittedMemoryInBytes)
129{
Courtney Goeltzenleuchterd040c5c2015-07-09 21:57:28 -0600130}