blob: f1601b8e7ba744664b570b6d19e4548465d986ac [file] [log] [blame]
Chia-I Wu75577d92014-08-11 10:54:33 +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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu75577d92014-08-11 10:54:33 +080026 */
27
28#include "dev.h"
29#include "sampler.h"
30#include "dset.h"
31
32static void dset_destroy(struct intel_obj *obj)
33{
34 struct intel_dset *dset = intel_dset_from_obj(obj);
35
36 intel_dset_destroy(dset);
37}
38
39XGL_RESULT intel_dset_create(struct intel_dev *dev,
40 const XGL_DESCRIPTOR_SET_CREATE_INFO *info,
41 struct intel_dset **dset_ret)
42{
43 struct intel_dset *dset;
44
Chia-I Wub8d04c82014-08-18 15:51:10 +080045 dset = (struct intel_dset *) intel_base_create(dev, sizeof(*dset),
46 dev->base.dbg, XGL_DBG_OBJECT_DESCRIPTOR_SET, info, 0);
Chia-I Wu75577d92014-08-11 10:54:33 +080047 if (!dset)
48 return XGL_ERROR_OUT_OF_MEMORY;
49
50 dset->dev = dev;
51 dset->slots = icd_alloc(sizeof(dset->slots[0]) * info->slots,
52 0, XGL_SYSTEM_ALLOC_INTERNAL);
53 if (!dset->slots) {
54 intel_dset_destroy(dset);
55 return XGL_ERROR_OUT_OF_MEMORY;
56 }
57
58 dset->obj.destroy = dset_destroy;
59
60 *dset_ret = dset;
61
62 return XGL_SUCCESS;
63}
64
65void intel_dset_destroy(struct intel_dset *dset)
66{
67 intel_base_destroy(&dset->obj.base);
68}
69
70XGL_RESULT XGLAPI intelCreateDescriptorSet(
71 XGL_DEVICE device,
72 const XGL_DESCRIPTOR_SET_CREATE_INFO* pCreateInfo,
73 XGL_DESCRIPTOR_SET* pDescriptorSet)
74{
75 struct intel_dev *dev = intel_dev(device);
76
77 return intel_dset_create(dev, pCreateInfo,
78 (struct intel_dset **) pDescriptorSet);
79}
80
81XGL_VOID XGLAPI intelBeginDescriptorSetUpdate(
82 XGL_DESCRIPTOR_SET descriptorSet)
83{
84 /* no-op */
85}
86
87XGL_VOID XGLAPI intelEndDescriptorSetUpdate(
88 XGL_DESCRIPTOR_SET descriptorSet)
89{
90 /* no-op */
91}
92
93XGL_VOID XGLAPI intelAttachSamplerDescriptors(
94 XGL_DESCRIPTOR_SET descriptorSet,
95 XGL_UINT startSlot,
96 XGL_UINT slotCount,
97 const XGL_SAMPLER* pSamplers)
98{
99 struct intel_dset *dset = intel_dset(descriptorSet);
100 XGL_UINT i;
101
102 for (i = 0; i < slotCount; i++) {
103 struct intel_dset_slot *slot = &dset->slots[startSlot + i];
104 struct intel_sampler *sampler = intel_sampler(pSamplers[i]);
105
106 slot->type = INTEL_DSET_SLOT_SAMPLER;
107 slot->u.sampler = sampler;
108 }
109}
110
111XGL_VOID XGLAPI intelAttachImageViewDescriptors(
112 XGL_DESCRIPTOR_SET descriptorSet,
113 XGL_UINT startSlot,
114 XGL_UINT slotCount,
115 const XGL_IMAGE_VIEW_ATTACH_INFO* pImageViews)
116{
117 struct intel_dset *dset = intel_dset(descriptorSet);
118 XGL_UINT i;
119
120 for (i = 0; i < slotCount; i++) {
121 struct intel_dset_slot *slot = &dset->slots[startSlot + i];
122 const XGL_IMAGE_VIEW_ATTACH_INFO *info = &pImageViews[i];
123 struct intel_img_view *view = intel_img_view(info->view);
124
125 slot->type = INTEL_DSET_SLOT_IMG_VIEW;
126 slot->u.img_view = view;
127 }
128}
129
130XGL_VOID XGLAPI intelAttachMemoryViewDescriptors(
131 XGL_DESCRIPTOR_SET descriptorSet,
132 XGL_UINT startSlot,
133 XGL_UINT slotCount,
134 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemViews)
135{
136 struct intel_dset *dset = intel_dset(descriptorSet);
137 XGL_UINT i;
138
139 for (i = 0; i < slotCount; i++) {
140 struct intel_dset_slot *slot = &dset->slots[startSlot + i];
141 const XGL_MEMORY_VIEW_ATTACH_INFO *info = &pMemViews[i];
142
143 slot->type = INTEL_DSET_SLOT_MEM_VIEW;
144 intel_mem_view_init(&slot->u.mem_view, dset->dev, info);
145 }
146}
147
148XGL_VOID XGLAPI intelAttachNestedDescriptors(
149 XGL_DESCRIPTOR_SET descriptorSet,
150 XGL_UINT startSlot,
151 XGL_UINT slotCount,
152 const XGL_DESCRIPTOR_SET_ATTACH_INFO* pNestedDescriptorSets)
153{
154 struct intel_dset *dset = intel_dset(descriptorSet);
155 XGL_UINT i;
156
157 for (i = 0; i < slotCount; i++) {
158 struct intel_dset_slot *slot = &dset->slots[startSlot + i];
159 const XGL_DESCRIPTOR_SET_ATTACH_INFO *info = &pNestedDescriptorSets[i];
160 struct intel_dset *nested = intel_dset(info->descriptorSet);
161
162 slot->type = INTEL_DSET_SLOT_NESTED;
163 slot->u.nested.dset = nested;
164 slot->u.nested.slot_offset = info->slotOffset;
165 }
166}
167
168XGL_VOID XGLAPI intelClearDescriptorSetSlots(
169 XGL_DESCRIPTOR_SET descriptorSet,
170 XGL_UINT startSlot,
171 XGL_UINT slotCount)
172{
173 struct intel_dset *dset = intel_dset(descriptorSet);
174 XGL_UINT i;
175
176 for (i = 0; i < slotCount; i++) {
177 struct intel_dset_slot *slot = &dset->slots[startSlot + i];
178
179 slot->type = INTEL_DSET_SLOT_UNUSED;
180 slot->u.unused = NULL;
181 }
182}