blob: e257f1b697e6fc22f3a333c992438f02ce183084 [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;
Tony Barbourfa6cac72015-01-16 14:27:35 -070049 static XGL_UINT heapInfo[1];
Chia-I Wu714df452015-01-01 07:55:04 +080050
51 *size = sizeof(XGL_MEMORY_REQUIREMENTS);
52 if (data == NULL)
53 return ret;
54
55 /*
56 * From the Sandy Bridge PRM, volume 1 part 1, page 118:
57 *
58 * "For buffers, which have no inherent "height," padding
59 * requirements are different. A buffer must be padded to the
60 * next multiple of 256 array elements, with an additional 16
61 * bytes added beyond that to account for the L1 cache line."
62 */
63 mem_req->size = buf->size;
64 if (buf->usage & XGL_BUFFER_USAGE_SHADER_ACCESS_READ_BIT)
65 mem_req->size = u_align(mem_req->size, 256) + 16;
66
67 mem_req->alignment = 4096;
68 mem_req->heapCount = 1;
Tony Barbourfa6cac72015-01-16 14:27:35 -070069 mem_req->pHeaps = heapInfo;
Chia-I Wu714df452015-01-01 07:55:04 +080070
71 }
72 break;
73 default:
74 ret = intel_base_get_info(base, type, size, data);
75 break;
76 }
77
78 return ret;
79}
80
81XGL_RESULT intel_buf_create(struct intel_dev *dev,
82 const XGL_BUFFER_CREATE_INFO *info,
83 struct intel_buf **buf_ret)
84{
85 struct intel_buf *buf;
86
87 buf = (struct intel_buf *) intel_base_create(dev, sizeof(*buf),
88 dev->base.dbg, XGL_DBG_OBJECT_BUFFER, info, 0);
89 if (!buf)
90 return XGL_ERROR_OUT_OF_MEMORY;
91
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
100 return XGL_SUCCESS;
101}
102
103void intel_buf_destroy(struct intel_buf *buf)
104{
105 intel_base_destroy(&buf->obj.base);
106}
107
108ICD_EXPORT XGL_RESULT XGLAPI xglCreateBuffer(
109 XGL_DEVICE device,
110 const XGL_BUFFER_CREATE_INFO* pCreateInfo,
111 XGL_BUFFER* pBuffer)
112{
113 struct intel_dev *dev = intel_dev(device);
114
115 return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer);
116}