blob: d873b2c837e6f6a708dad05d1473093f632bfc88 [file] [log] [blame]
Chia-I Wu714df452015-01-01 07:55:04 +08001/*
2 * XGL
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
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
39static XGL_RESULT buf_get_info(struct intel_base *base, int type,
40 XGL_SIZE *size, XGL_VOID *data)
41{
42 struct intel_buf *buf = intel_buf_from_base(base);
43 XGL_RESULT ret = XGL_SUCCESS;
44
45 switch (type) {
46 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
47 {
48 XGL_MEMORY_REQUIREMENTS *mem_req = data;
49
50 *size = sizeof(XGL_MEMORY_REQUIREMENTS);
51 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;
63 if (buf->usage & XGL_BUFFER_USAGE_SHADER_ACCESS_READ_BIT)
64 mem_req->size = u_align(mem_req->size, 256) + 16;
65
66 mem_req->alignment = 4096;
Chia-I Wu714df452015-01-01 07:55:04 +080067
68 }
69 break;
Jon Ashburn5567c812015-01-20 08:50:12 -070070 case XGL_INFO_TYPE_BUFFER_MEMORY_REQUIREMENTS:
71 {
72 XGL_BUFFER_MEMORY_REQUIREMENTS *buf_req = data;
73
74 *size = sizeof(XGL_BUFFER_MEMORY_REQUIREMENTS);
75 if (data == NULL)
76 return ret;
77 buf_req->usage = buf->usage;
78 }
79 break;
Chia-I Wu714df452015-01-01 07:55:04 +080080 default:
81 ret = intel_base_get_info(base, type, size, data);
82 break;
83 }
84
85 return ret;
86}
87
88XGL_RESULT intel_buf_create(struct intel_dev *dev,
89 const XGL_BUFFER_CREATE_INFO *info,
90 struct intel_buf **buf_ret)
91{
92 struct intel_buf *buf;
93
94 buf = (struct intel_buf *) intel_base_create(dev, sizeof(*buf),
95 dev->base.dbg, XGL_DBG_OBJECT_BUFFER, info, 0);
96 if (!buf)
97 return XGL_ERROR_OUT_OF_MEMORY;
98
99 buf->size = info->size;
100 buf->usage = info->usage;
101
102 buf->obj.destroy = buf_destroy;
103 buf->obj.base.get_info = buf_get_info;
104
105 *buf_ret = buf;
106
107 return XGL_SUCCESS;
108}
109
110void intel_buf_destroy(struct intel_buf *buf)
111{
112 intel_base_destroy(&buf->obj.base);
113}
114
115ICD_EXPORT XGL_RESULT XGLAPI xglCreateBuffer(
116 XGL_DEVICE device,
117 const XGL_BUFFER_CREATE_INFO* pCreateInfo,
118 XGL_BUFFER* pBuffer)
119{
120 struct intel_dev *dev = intel_dev(device);
121
122 return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer);
123}