RT Shading works
This commit is contained in:
@@ -117,6 +117,8 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
|
||||
.size = regionSize,
|
||||
};
|
||||
vkCmdCopyBuffer(cmd->getHandle(), staging->buffer, buffer, 1, ©);
|
||||
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
cmd->bindResource(PBufferAllocation(this));
|
||||
cmd->bindResource(PBufferAllocation(staging));
|
||||
|
||||
|
||||
@@ -235,6 +235,9 @@ void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline gfxPipeline) {
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
rtPipeline = gfxPipeline.cast<RayTracingPipeline>();
|
||||
rtPipeline->bind(handle);
|
||||
boundResources.add(PBufferAllocation(rtPipeline->rayGen));
|
||||
boundResources.add(PBufferAllocation(rtPipeline->hit));
|
||||
boundResources.add(PBufferAllocation(rtPipeline->miss));
|
||||
}
|
||||
|
||||
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) {
|
||||
|
||||
@@ -654,6 +654,8 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
|
||||
#ifdef __APPLE__
|
||||
extensions.add("VK_KHR_portability_enumeration");
|
||||
#endif
|
||||
Array<const char*> layers = initInfo.layers;
|
||||
layers.add("VK_LAYER_KHRONOS_validation");
|
||||
VkInstanceCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -661,8 +663,8 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
|
||||
.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
|
||||
#endif
|
||||
.pApplicationInfo = &appInfo,
|
||||
.enabledLayerCount = (uint32)initInfo.layers.size(),
|
||||
.ppEnabledLayerNames = initInfo.layers.data(),
|
||||
.enabledLayerCount = (uint32)layers.size(),
|
||||
.ppEnabledLayerNames = layers.data(),
|
||||
.enabledExtensionCount = (uint32)extensions.size(),
|
||||
.ppEnabledExtensionNames = extensions.data(),
|
||||
};
|
||||
|
||||
@@ -478,6 +478,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
||||
.module = rayGen->getModuleHandle(),
|
||||
.pName = rayGen->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
shaderGroups.add(VkRayTracingShaderGroupCreateInfoKHR{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
@@ -487,6 +488,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.intersectionShader = VK_SHADER_UNUSED_KHR,
|
||||
.pShaderGroupCaptureReplayHandle = nullptr,
|
||||
});
|
||||
}
|
||||
{
|
||||
@@ -499,6 +501,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR,
|
||||
.module = hit->getModuleHandle(),
|
||||
.pName = hit->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
uint32 hitIndex = static_cast<uint32>(shaderStages.size() - 1);
|
||||
uint32 anyHitIndex = VK_SHADER_UNUSED_KHR;
|
||||
@@ -512,6 +515,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_ANY_HIT_BIT_KHR,
|
||||
.module = anyHit->getModuleHandle(),
|
||||
.pName = anyHit->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
}
|
||||
if (hitgroup.intersectionShader != nullptr) {
|
||||
@@ -523,6 +527,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_INTERSECTION_BIT_KHR,
|
||||
.module = intersect->getModuleHandle(),
|
||||
.pName = intersect->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
}
|
||||
shaderGroups.add(VkRayTracingShaderGroupCreateInfoKHR{
|
||||
@@ -533,6 +538,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.closestHitShader = hitIndex,
|
||||
.anyHitShader = anyHitIndex,
|
||||
.intersectionShader = intersectionIndex,
|
||||
.pShaderGroupCaptureReplayHandle = nullptr,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -546,6 +552,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_MISS_BIT_KHR,
|
||||
.module = miss->getModuleHandle(),
|
||||
.pName = miss->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
shaderGroups.add(VkRayTracingShaderGroupCreateInfoKHR{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
@@ -555,6 +562,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.intersectionShader = VK_SHADER_UNUSED_KHR,
|
||||
.pShaderGroupCaptureReplayHandle = nullptr,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -568,6 +576,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.stage = VK_SHADER_STAGE_CALLABLE_BIT_KHR,
|
||||
.module = call->getModuleHandle(),
|
||||
.pName = call->getEntryPointName(),
|
||||
.pSpecializationInfo = nullptr,
|
||||
});
|
||||
shaderGroups.add(VkRayTracingShaderGroupCreateInfoKHR{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
@@ -577,11 +586,15 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.intersectionShader = VK_SHADER_UNUSED_KHR,
|
||||
.pShaderGroupCaptureReplayHandle = nullptr,
|
||||
});
|
||||
}
|
||||
}
|
||||
uint32 hash = CRC::Calculate(shaderStages.data(), sizeof(VkPipelineShaderStageCreateInfo) * shaderStages.size(), CRC::CRC_32());
|
||||
hash = CRC::Calculate(shaderGroups.data(), sizeof(VkRayTracingShaderGroupCreateInfoKHR) * shaderGroups.size(), CRC::CRC_32(), hash);
|
||||
if (rayTracingPipelines.contains(hash)) {
|
||||
return rayTracingPipelines[hash];
|
||||
}
|
||||
VkRayTracingPipelineCreateInfoKHR pipelineInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR,
|
||||
.pNext = nullptr,
|
||||
@@ -593,7 +606,11 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
.layout = createInfo.pipelineLayout.cast<PipelineLayout>()->getHandle(),
|
||||
};
|
||||
VkPipeline pipelineHandle;
|
||||
auto beginTime = std::chrono::high_resolution_clock::now();
|
||||
VK_CHECK(vkCreateRayTracingPipelinesKHR(graphics->getDevice(), VK_NULL_HANDLE, cache, 1, &pipelineInfo, nullptr, &pipelineHandle));
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count();
|
||||
std::cout << "RT creation time: " << delta << std::endl;
|
||||
|
||||
const uint32_t handleSize = graphics->getRayTracingProperties().shaderGroupHandleSize;
|
||||
const uint32_t handleSizeAligned =
|
||||
|
||||
@@ -220,4 +220,9 @@ RayTracingPipeline::~RayTracingPipeline() {
|
||||
graphics->getDestructionManager()->queueResourceForDestruction(std::move(callable));
|
||||
}
|
||||
|
||||
void RayTracingPipeline::bind(VkCommandBuffer handle) { vkCmdBindPipeline(handle, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipeline); }
|
||||
void RayTracingPipeline::bind(VkCommandBuffer handle) {
|
||||
vkCmdBindPipeline(handle, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipeline);
|
||||
rayGen->bind();
|
||||
hit->bind();
|
||||
miss->bind();
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ class RayTracingPipeline : public Gfx::RayTracingPipeline {
|
||||
uint64 missStride;
|
||||
OBufferAllocation callable;
|
||||
uint64 callableStride;
|
||||
friend class RenderCommand;
|
||||
};
|
||||
DEFINE_REF(RayTracingPipeline)
|
||||
} // namespace Vulkan
|
||||
|
||||
Reference in New Issue
Block a user