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