blob: f42571c2a86c1dde306c700f36752380029a5314 [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
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060039static VkResult buf_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060040 size_t *size, void *data)
Chia-I Wu714df452015-01-01 07:55:04 +080041{
42 struct intel_buf *buf = intel_buf_from_base(base);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060043 VkResult ret = VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +080044
45 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -060046 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS:
Chia-I Wu714df452015-01-01 07:55:04 +080047 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060048 VkMemoryRequirements *mem_req = data;
Chia-I Wu714df452015-01-01 07:55:04 +080049
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060050 *size = sizeof(VkMemoryRequirements);
Chia-I Wu714df452015-01-01 07:55:04 +080051 if (data == NULL)
52 return ret;
53
54 /*
55 * From the Sandy Bridge PRM, volume 1 part 1, page 118:
56 *
57 * "For buffers, which have no inherent "height," padding
58 * requirements are different. A buffer must be padded to the
59 * next multiple of 256 array elements, with an additional 16
60 * bytes added beyond that to account for the L1 cache line."
61 */
62 mem_req->size = buf->size;
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -060063 if (buf->usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
64 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Chia-I Wu714df452015-01-01 07:55:04 +080065 mem_req->size = u_align(mem_req->size, 256) + 16;
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -060066 }
Chia-I Wu714df452015-01-01 07:55:04 +080067
68 mem_req->alignment = 4096;
Chia-I Wu714df452015-01-01 07:55:04 +080069
Jeremy Hayesd02809a2015-04-15 14:17:56 -060070 mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL;
Chia-I Wu714df452015-01-01 07:55:04 +080071 }
72 break;
Chia-I Wu714df452015-01-01 07:55:04 +080073 default:
74 ret = intel_base_get_info(base, type, size, data);
75 break;
76 }
77
78 return ret;
79}
80
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060081VkResult intel_buf_create(struct intel_dev *dev,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060082 const VkBufferCreateInfo *info,
Chia-I Wu714df452015-01-01 07:55:04 +080083 struct intel_buf **buf_ret)
84{
85 struct intel_buf *buf;
86
Chia-I Wu545c2e12015-02-22 13:19:54 +080087 buf = (struct intel_buf *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060088 sizeof(*buf), dev->base.dbg, VK_DBG_OBJECT_BUFFER, info, 0);
Chia-I Wu714df452015-01-01 07:55:04 +080089 if (!buf)
Tony Barbour8205d902015-04-16 15:59:00 -060090 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu714df452015-01-01 07:55:04 +080091
92 buf->size = info->size;
93 buf->usage = info->usage;
94
95 buf->obj.destroy = buf_destroy;
96 buf->obj.base.get_info = buf_get_info;
97
98 *buf_ret = buf;
99
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600100 return VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +0800101}
102
103void intel_buf_destroy(struct intel_buf *buf)
104{
105 intel_base_destroy(&buf->obj.base);
106}
107
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600108ICD_EXPORT VkResult VKAPI vkCreateBuffer(
109 VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600110 const VkBufferCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600111 VkBuffer* pBuffer)
Chia-I Wu714df452015-01-01 07:55:04 +0800112{
113 struct intel_dev *dev = intel_dev(device);
114
115 return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer);
116}