diff --git a/src/lightmap/gpuraytracer.cpp b/src/lightmap/gpuraytracer.cpp index df93ca0..31ea490 100644 --- a/src/lightmap/gpuraytracer.cpp +++ b/src/lightmap/gpuraytracer.cpp @@ -352,7 +352,7 @@ void GPURaytracer::CreateVertexAndIndexBuffers() VkMemoryBarrier barrier = { VK_STRUCTURE_TYPE_MEMORY_BARRIER }; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR; - vkCmdPipelineBarrier(cmdbuffer->buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, 1, &barrier, 0, nullptr, 0, nullptr); + cmdbuffer->pipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, 1, &barrier, 0, nullptr, 0, nullptr); } void GPURaytracer::CreateBottomLevelAccelerationStructure() @@ -420,7 +420,7 @@ void GPURaytracer::CreateBottomLevelAccelerationStructure() buildInfo.dstAccelerationStructure = blAccelStruct->accelstruct; buildInfo.scratchData.deviceAddress = scratchAddress; VkAccelerationStructureBuildRangeInfoKHR* rangeInfos[] = { &rangeInfo }; - vkCmdBuildAccelerationStructuresKHR(cmdbuffer->buffer, 1, &buildInfo, rangeInfos); + cmdbuffer->buildAccelerationStructures(1, &buildInfo, rangeInfos); } void GPURaytracer::CreateTopLevelAccelerationStructure() @@ -457,7 +457,7 @@ void GPURaytracer::CreateTopLevelAccelerationStructure() VkMemoryBarrier barrier = { VK_STRUCTURE_TYPE_MEMORY_BARRIER }; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR; - vkCmdPipelineBarrier(cmdbuffer->buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, 1, &barrier, 0, nullptr, 0, nullptr); + cmdbuffer->pipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, 1, &barrier, 0, nullptr, 0, nullptr); VkBufferDeviceAddressInfo info = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO }; info.buffer = tlInstanceBuffer->buffer; @@ -514,7 +514,7 @@ void GPURaytracer::CreateTopLevelAccelerationStructure() buildInfo.scratchData.deviceAddress = scratchAddress; VkAccelerationStructureBuildRangeInfoKHR* rangeInfos[] = { &rangeInfo }; - vkCmdBuildAccelerationStructuresKHR(cmdbuffer->buffer, 1, &buildInfo, rangeInfos); + cmdbuffer->buildAccelerationStructures(1, &buildInfo, rangeInfos); } void GPURaytracer::CreateShaders() @@ -633,6 +633,9 @@ void GPURaytracer::CreatePipeline() builder.addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR, shaderRayGen.get()); builder.addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, shaderClosestHit.get()); builder.addShader(VK_SHADER_STAGE_MISS_BIT_KHR, shaderMiss.get()); + builder.addRayGenGroup(0); + builder.addTrianglesHitGroup(1); + builder.addMissGroup(2); pipeline = builder.create(device.get()); BufferBuilder bufbuilder; diff --git a/src/lightmap/vulkanbuilders.h b/src/lightmap/vulkanbuilders.h index 36626e8..b030ea1 100644 --- a/src/lightmap/vulkanbuilders.h +++ b/src/lightmap/vulkanbuilders.h @@ -139,7 +139,7 @@ public: void addShader(VkShaderStageFlagBits stage, VulkanShader *shader); void addRayGenGroup(int rayGenShader); void addMissGroup(int missShader); - void addTrianglesHitGroup(int closestHitShader, int anyHitShader); + void addTrianglesHitGroup(int closestHitShader, int anyHitShader = VK_SHADER_UNUSED_KHR); void addProceduralHitGroup(int intersectionShader, int closestHitShader, int anyHitShader); std::unique_ptr create(VulkanDevice *device); @@ -628,7 +628,7 @@ inline void RayTracingPipelineBuilder::setMaxPipelineRayRecursionDepth(int depth inline void RayTracingPipelineBuilder::addShader(VkShaderStageFlagBits stage, VulkanShader *shader) { - VkPipelineShaderStageCreateInfo stageInfo = {}; + VkPipelineShaderStageCreateInfo stageInfo = { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO }; stageInfo.stage = stage; stageInfo.module = shader->module; stageInfo.pName = "main"; diff --git a/src/lightmap/vulkanobjects.h b/src/lightmap/vulkanobjects.h index ffc2d51..bb9839c 100644 --- a/src/lightmap/vulkanobjects.h +++ b/src/lightmap/vulkanobjects.h @@ -372,6 +372,7 @@ public: void endRenderPass(); void executeCommands(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); + void buildAccelerationStructures(uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos); void traceRays(const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width, uint32_t height, uint32_t depth); void writeAccelerationStructuresProperties(uint32_t accelerationStructureCount, const VkAccelerationStructureKHR* pAccelerationStructures, VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery); @@ -905,6 +906,11 @@ inline void VulkanCommandBuffer::executeCommands(uint32_t commandBufferCount, co vkCmdExecuteCommands(buffer, commandBufferCount, pCommandBuffers); } +inline void VulkanCommandBuffer::buildAccelerationStructures(uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos) +{ + vkCmdBuildAccelerationStructuresKHR(buffer, infoCount, pInfos, ppBuildRangeInfos); +} + inline void VulkanCommandBuffer::traceRays(const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width, uint32_t height, uint32_t depth) { vkCmdTraceRaysKHR(buffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, width, height, depth);