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 26void 27anv_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 72VkResult 73anv_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 99void 100anv_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 115VkDeviceAddress 116anv_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 129void 130anv_GetDeviceAccelerationStructureCompatibilityKHR( 131 VkDevice device, 132 const VkAccelerationStructureVersionInfoKHR* pVersionInfo, 133 VkAccelerationStructureCompatibilityKHR* pCompatibility) 134{ 135 unreachable("Unimplemented"); 136} 137 138VkResult 139anv_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 151VkResult 152anv_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 162VkResult 163anv_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 173VkResult 174anv_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 184VkResult 185anv_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 199void 200anv_CmdBuildAccelerationStructuresKHR( 201 VkCommandBuffer commandBuffer, 202 uint32_t infoCount, 203 const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, 204 const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos) 205{ 206 unreachable("Unimplemented"); 207} 208 209void 210anv_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 221void 222anv_CmdCopyAccelerationStructureKHR( 223 VkCommandBuffer commandBuffer, 224 const VkCopyAccelerationStructureInfoKHR* pInfo) 225{ 226 unreachable("Unimplemented"); 227} 228 229void 230anv_CmdCopyAccelerationStructureToMemoryKHR( 231 VkCommandBuffer commandBuffer, 232 const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo) 233{ 234 unreachable("Unimplemented"); 235} 236 237void 238anv_CmdCopyMemoryToAccelerationStructureKHR( 239 VkCommandBuffer commandBuffer, 240 const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo) 241{ 242 unreachable("Unimplemented"); 243} 244 245void 246anv_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