blob: 2a0d6fbcc3e94ed4d7247680c2ca219c58050fd7 [file] [log] [blame]
Chia-I Wu714df452015-01-01 07:55:04 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu714df452015-01-01 07:55:04 +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.
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
32static 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 Barbour426b9052015-06-24 16:06:58 -060039static VkResult buf_get_memory_requirements(struct intel_base *base,
40 VkMemoryRequirements *pRequirements)
Chia-I Wu714df452015-01-01 07:55:04 +080041{
42 struct intel_buf *buf = intel_buf_from_base(base);
Chia-I Wu714df452015-01-01 07:55:04 +080043
Tony Barbour426b9052015-06-24 16:06:58 -060044 /*
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 Wu714df452015-01-01 07:55:04 +080056 }
57
Mark Lobodzinski72346292015-07-02 16:49:40 -060058 pRequirements->alignment = 4096;
59 pRequirements->memoryTypeBits = (1 << INTEL_MEMORY_TYPE_COUNT) - 1;
Tony Barbour426b9052015-06-24 16:06:58 -060060
61 return VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +080062}
63
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060064VkResult intel_buf_create(struct intel_dev *dev,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060065 const VkBufferCreateInfo *info,
Chia-I Wu714df452015-01-01 07:55:04 +080066 struct intel_buf **buf_ret)
67{
68 struct intel_buf *buf;
69
Chia-I Wu545c2e12015-02-22 13:19:54 +080070 buf = (struct intel_buf *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071 sizeof(*buf), dev->base.dbg, VK_OBJECT_TYPE_BUFFER, info, 0);
Chia-I Wu714df452015-01-01 07:55:04 +080072 if (!buf)
Tony Barbour8205d902015-04-16 15:59:00 -060073 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu714df452015-01-01 07:55:04 +080074
75 buf->size = info->size;
76 buf->usage = info->usage;
77
78 buf->obj.destroy = buf_destroy;
Tony Barbour426b9052015-06-24 16:06:58 -060079 buf->obj.base.get_memory_requirements = buf_get_memory_requirements;
Chia-I Wu714df452015-01-01 07:55:04 +080080
81 *buf_ret = buf;
82
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083 return VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +080084}
85
86void intel_buf_destroy(struct intel_buf *buf)
87{
88 intel_base_destroy(&buf->obj.base);
89}
90
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091ICD_EXPORT VkResult VKAPI vkCreateBuffer(
92 VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060093 const VkBufferCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060094 VkBuffer* pBuffer)
Chia-I Wu714df452015-01-01 07:55:04 +080095{
96 struct intel_dev *dev = intel_dev(device);
97
98 return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer);
99}