• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2020 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "anv_private.h"
25 
26 void
anv_GetAccelerationStructureBuildSizesKHR(VkDevice device,VkAccelerationStructureBuildTypeKHR buildType,const VkAccelerationStructureBuildGeometryInfoKHR * pBuildInfo,const uint32_t * pMaxPrimitiveCounts,VkAccelerationStructureBuildSizesInfoKHR * pSizeInfo)27 anv_GetAccelerationStructureBuildSizesKHR(
28     VkDevice                                    device,
29     VkAccelerationStructureBuildTypeKHR         buildType,
30     const VkAccelerationStructureBuildGeometryInfoKHR* pBuildInfo,
31     const uint32_t*                             pMaxPrimitiveCounts,
32     VkAccelerationStructureBuildSizesInfoKHR*   pSizeInfo)
33 {
34    assert(pSizeInfo->sType ==
35           VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR);
36 
37    uint64_t max_prim_count = 0;
38    for (uint32_t i = 0; i < pBuildInfo->geometryCount; i++)
39       max_prim_count += pMaxPrimitiveCounts[i];
40 
41    pSizeInfo->accelerationStructureSize = 0; /* TODO */
42 
43    uint64_t cpu_build_scratch_size = 0; /* TODO */
44    uint64_t cpu_update_scratch_size = cpu_build_scratch_size;
45 
46    uint64_t gpu_build_scratch_size = 0; /* TODO */
47    uint64_t gpu_update_scratch_size = gpu_build_scratch_size;
48 
49    switch (buildType) {
50    case VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_KHR:
51       pSizeInfo->buildScratchSize = cpu_build_scratch_size;
52       pSizeInfo->updateScratchSize = cpu_update_scratch_size;
53       break;
54 
55    case VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR:
56       pSizeInfo->buildScratchSize = gpu_build_scratch_size;
57       pSizeInfo->updateScratchSize = gpu_update_scratch_size;
58       break;
59 
60    case VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_OR_DEVICE_KHR:
61       pSizeInfo->buildScratchSize = MAX2(cpu_build_scratch_size,
62                                          gpu_build_scratch_size);
63       pSizeInfo->updateScratchSize = MAX2(cpu_update_scratch_size,
64                                           gpu_update_scratch_size);
65       break;
66 
67    default:
68       unreachable("Invalid acceleration structure build type");
69    }
70 }
71 
72 VkResult
anv_CreateAccelerationStructureKHR(VkDevice _device,const VkAccelerationStructureCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkAccelerationStructureKHR * pAccelerationStructure)73 anv_CreateAccelerationStructureKHR(
74     VkDevice                                    _device,
75     const VkAccelerationStructureCreateInfoKHR* pCreateInfo,
76     const VkAllocationCallbacks*                pAllocator,
77     VkAccelerationStructureKHR*                 pAccelerationStructure)
78 {
79    ANV_FROM_HANDLE(anv_device, device, _device);
80    ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
81    struct anv_acceleration_structure *accel;
82 
83    accel = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*accel), 8,
84                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
85    if (accel == NULL)
86       return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
87 
88    vk_object_base_init(&device->vk, &accel->base,
89                        VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR);
90 
91    accel->size = pCreateInfo->size;
92    accel->address = anv_address_add(buffer->address, pCreateInfo->offset);
93 
94    *pAccelerationStructure = anv_acceleration_structure_to_handle(accel);
95 
96    return VK_SUCCESS;
97 }
98 
99 void
anv_DestroyAccelerationStructureKHR(VkDevice _device,VkAccelerationStructureKHR accelerationStructure,const VkAllocationCallbacks * pAllocator)100 anv_DestroyAccelerationStructureKHR(
101     VkDevice                                    _device,
102     VkAccelerationStructureKHR                  accelerationStructure,
103     const VkAllocationCallbacks*                pAllocator)
104 {
105    ANV_FROM_HANDLE(anv_device, device, _device);
106    ANV_FROM_HANDLE(anv_acceleration_structure, accel, accelerationStructure);
107 
108    if (!accel)
109       return;
110 
111    vk_object_base_finish(&accel->base);
112    vk_free2(&device->vk.alloc, pAllocator, accel);
113 }
114 
115 VkDeviceAddress
anv_GetAccelerationStructureDeviceAddressKHR(VkDevice device,const VkAccelerationStructureDeviceAddressInfoKHR * pInfo)116 anv_GetAccelerationStructureDeviceAddressKHR(
117     VkDevice                                    device,
118     const VkAccelerationStructureDeviceAddressInfoKHR* pInfo)
119 {
120    ANV_FROM_HANDLE(anv_acceleration_structure, accel,
121                    pInfo->accelerationStructure);
122 
123    assert(!anv_address_is_null(accel->address));
124    assert(accel->address.bo->flags & EXEC_OBJECT_PINNED);
125 
126    return anv_address_physical(accel->address);
127 }
128 
129 void
anv_GetDeviceAccelerationStructureCompatibilityKHR(VkDevice device,const VkAccelerationStructureVersionInfoKHR * pVersionInfo,VkAccelerationStructureCompatibilityKHR * pCompatibility)130 anv_GetDeviceAccelerationStructureCompatibilityKHR(
131     VkDevice                                    device,
132     const VkAccelerationStructureVersionInfoKHR* pVersionInfo,
133     VkAccelerationStructureCompatibilityKHR*    pCompatibility)
134 {
135    unreachable("Unimplemented");
136 }
137 
138 VkResult
anv_BuildAccelerationStructuresKHR(VkDevice _device,VkDeferredOperationKHR deferredOperation,uint32_t infoCount,const VkAccelerationStructureBuildGeometryInfoKHR * pInfos,const VkAccelerationStructureBuildRangeInfoKHR * const * ppBuildRangeInfos)139 anv_BuildAccelerationStructuresKHR(
140     VkDevice                                    _device,
141     VkDeferredOperationKHR                      deferredOperation,
142     uint32_t                                    infoCount,
143     const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
144     const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos)
145 {
146    ANV_FROM_HANDLE(anv_device, device, _device);
147    unreachable("Unimplemented");
148    return vk_error(device, VK_ERROR_FEATURE_NOT_PRESENT);
149 }
150 
151 VkResult
anv_CopyAccelerationStructureKHR(VkDevice _device,VkDeferredOperationKHR deferredOperation,const VkCopyAccelerationStructureInfoKHR * pInfo)152 anv_CopyAccelerationStructureKHR(
153     VkDevice                                    _device,
154     VkDeferredOperationKHR                      deferredOperation,
155     const VkCopyAccelerationStructureInfoKHR*   pInfo)
156 {
157    ANV_FROM_HANDLE(anv_device, device, _device);
158    unreachable("Unimplemented");
159    return vk_error(device, VK_ERROR_FEATURE_NOT_PRESENT);
160 }
161 
162 VkResult
anv_CopyAccelerationStructureToMemoryKHR(VkDevice _device,VkDeferredOperationKHR deferredOperation,const VkCopyAccelerationStructureToMemoryInfoKHR * pInfo)163 anv_CopyAccelerationStructureToMemoryKHR(
164     VkDevice                                    _device,
165     VkDeferredOperationKHR                      deferredOperation,
166     const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo)
167 {
168    ANV_FROM_HANDLE(anv_device, device, _device);
169    unreachable("Unimplemented");
170    return vk_error(device, VK_ERROR_FEATURE_NOT_PRESENT);
171 }
172 
173 VkResult
anv_CopyMemoryToAccelerationStructureKHR(VkDevice _device,VkDeferredOperationKHR deferredOperation,const VkCopyMemoryToAccelerationStructureInfoKHR * pInfo)174 anv_CopyMemoryToAccelerationStructureKHR(
175     VkDevice                                    _device,
176     VkDeferredOperationKHR                      deferredOperation,
177     const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo)
178 {
179    ANV_FROM_HANDLE(anv_device, device, _device);
180    unreachable("Unimplemented");
181    return vk_error(device, VK_ERROR_FEATURE_NOT_PRESENT);
182 }
183 
184 VkResult
anv_WriteAccelerationStructuresPropertiesKHR(VkDevice _device,uint32_t accelerationStructureCount,const VkAccelerationStructureKHR * pAccelerationStructures,VkQueryType queryType,size_t dataSize,void * pData,size_t stride)185 anv_WriteAccelerationStructuresPropertiesKHR(
186     VkDevice                                    _device,
187     uint32_t                                    accelerationStructureCount,
188     const VkAccelerationStructureKHR*           pAccelerationStructures,
189     VkQueryType                                 queryType,
190     size_t                                      dataSize,
191     void*                                       pData,
192     size_t                                      stride)
193 {
194    ANV_FROM_HANDLE(anv_device, device, _device);
195    unreachable("Unimplemented");
196    return vk_error(device, VK_ERROR_FEATURE_NOT_PRESENT);
197 }
198 
199 void
anv_CmdBuildAccelerationStructuresKHR(VkCommandBuffer commandBuffer,uint32_t infoCount,const VkAccelerationStructureBuildGeometryInfoKHR * pInfos,const VkAccelerationStructureBuildRangeInfoKHR * const * ppBuildRangeInfos)200 anv_CmdBuildAccelerationStructuresKHR(
201     VkCommandBuffer                             commandBuffer,
202     uint32_t                                    infoCount,
203     const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
204     const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos)
205 {
206    unreachable("Unimplemented");
207 }
208 
209 void
anv_CmdBuildAccelerationStructuresIndirectKHR(VkCommandBuffer commandBuffer,uint32_t infoCount,const VkAccelerationStructureBuildGeometryInfoKHR * pInfos,const VkDeviceAddress * pIndirectDeviceAddresses,const uint32_t * pIndirectStrides,const uint32_t * const * ppMaxPrimitiveCounts)210 anv_CmdBuildAccelerationStructuresIndirectKHR(
211     VkCommandBuffer                             commandBuffer,
212     uint32_t                                    infoCount,
213     const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
214     const VkDeviceAddress*                      pIndirectDeviceAddresses,
215     const uint32_t*                             pIndirectStrides,
216     const uint32_t* const*                      ppMaxPrimitiveCounts)
217 {
218    unreachable("Unimplemented");
219 }
220 
221 void
anv_CmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,const VkCopyAccelerationStructureInfoKHR * pInfo)222 anv_CmdCopyAccelerationStructureKHR(
223     VkCommandBuffer                             commandBuffer,
224     const VkCopyAccelerationStructureInfoKHR*   pInfo)
225 {
226    unreachable("Unimplemented");
227 }
228 
229 void
anv_CmdCopyAccelerationStructureToMemoryKHR(VkCommandBuffer commandBuffer,const VkCopyAccelerationStructureToMemoryInfoKHR * pInfo)230 anv_CmdCopyAccelerationStructureToMemoryKHR(
231     VkCommandBuffer                             commandBuffer,
232     const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo)
233 {
234    unreachable("Unimplemented");
235 }
236 
237 void
anv_CmdCopyMemoryToAccelerationStructureKHR(VkCommandBuffer commandBuffer,const VkCopyMemoryToAccelerationStructureInfoKHR * pInfo)238 anv_CmdCopyMemoryToAccelerationStructureKHR(
239     VkCommandBuffer                             commandBuffer,
240     const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo)
241 {
242    unreachable("Unimplemented");
243 }
244 
245 void
anv_CmdWriteAccelerationStructuresPropertiesKHR(VkCommandBuffer commandBuffer,uint32_t accelerationStructureCount,const VkAccelerationStructureKHR * pAccelerationStructures,VkQueryType queryType,VkQueryPool queryPool,uint32_t firstQuery)246 anv_CmdWriteAccelerationStructuresPropertiesKHR(
247     VkCommandBuffer                             commandBuffer,
248     uint32_t                                    accelerationStructureCount,
249     const VkAccelerationStructureKHR*           pAccelerationStructures,
250     VkQueryType                                 queryType,
251     VkQueryPool                                 queryPool,
252     uint32_t                                    firstQuery)
253 {
254    unreachable("Unimplemented");
255 }
256