Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +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. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #include "dev.h" |
| 29 | #include "obj.h" |
| 30 | #include "buf.h" |
| 31 | |
| 32 | static void buf_destroy(struct intel_obj *obj) |
| 33 | { |
| 34 | struct intel_buf *buf = intel_buf_from_obj(obj); |
| 35 | |
| 36 | intel_buf_destroy(buf); |
| 37 | } |
| 38 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 39 | static VkResult buf_get_memory_requirements(struct intel_base *base, |
| 40 | VkMemoryRequirements *pRequirements) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 41 | { |
| 42 | struct intel_buf *buf = intel_buf_from_base(base); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 43 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 44 | /* |
| 45 | * From the Sandy Bridge PRM, volume 1 part 1, page 118: |
| 46 | * |
| 47 | * "For buffers, which have no inherent "height," padding |
| 48 | * requirements are different. A buffer must be padded to the |
| 49 | * next multiple of 256 array elements, with an additional 16 |
| 50 | * bytes added beyond that to account for the L1 cache line." |
| 51 | */ |
| 52 | pRequirements->size = buf->size; |
| 53 | if (buf->usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | |
| 54 | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
| 55 | pRequirements->size = u_align(pRequirements->size, 256) + 16; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 58 | pRequirements->alignment = 4096; |
| 59 | pRequirements->memoryTypeBits = (1 << INTEL_MEMORY_TYPE_COUNT) - 1; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 60 | |
| 61 | return VK_SUCCESS; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 62 | } |
| 63 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 64 | VkResult intel_buf_create(struct intel_dev *dev, |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 65 | const VkBufferCreateInfo *info, |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 66 | struct intel_buf **buf_ret) |
| 67 | { |
| 68 | struct intel_buf *buf; |
| 69 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 70 | buf = (struct intel_buf *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 71 | sizeof(*buf), dev->base.dbg, VK_OBJECT_TYPE_BUFFER, info, 0); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 72 | if (!buf) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 73 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 74 | |
| 75 | buf->size = info->size; |
| 76 | buf->usage = info->usage; |
| 77 | |
| 78 | buf->obj.destroy = buf_destroy; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 79 | buf->obj.base.get_memory_requirements = buf_get_memory_requirements; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 80 | |
| 81 | *buf_ret = buf; |
| 82 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | return VK_SUCCESS; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void intel_buf_destroy(struct intel_buf *buf) |
| 87 | { |
| 88 | intel_base_destroy(&buf->obj.base); |
| 89 | } |
| 90 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 91 | ICD_EXPORT VkResult VKAPI vkCreateBuffer( |
| 92 | VkDevice device, |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 93 | const VkBufferCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 94 | VkBuffer* pBuffer) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 95 | { |
| 96 | struct intel_dev *dev = intel_dev(device); |
| 97 | |
| 98 | return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer); |
| 99 | } |