Files
Seele/src/Engine/Graphics/Vulkan/RayTracing.h
T

108 lines
3.7 KiB
C++
Raw Normal View History

2024-06-09 10:44:24 +02:00
#pragma once
2024-07-10 21:07:10 +02:00
#include "Buffer.h"
2024-07-12 13:33:52 +02:00
#include "Descriptor.h"
2024-06-09 10:44:24 +02:00
#include "Graphics.h"
2024-06-09 12:20:04 +02:00
#include "Graphics/Initializer.h"
2024-06-09 10:44:24 +02:00
#include "Graphics/RayTracing.h"
#include <vulkan/vulkan_core.h>
2024-06-09 12:20:04 +02:00
namespace Seele {
namespace Vulkan {
class BottomLevelAS : public Gfx::BottomLevelAS {
public:
2024-06-09 10:44:24 +02:00
BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateInfo& createInfo);
~BottomLevelAS();
2024-07-12 22:05:52 +02:00
uint64 getDeviceAddress() const {
VkAccelerationStructureDeviceAddressInfoKHR accelerationStructureDeviceInfo{
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR,
.pNext = nullptr,
.accelerationStructure = handle,
};
return vkGetAccelerationStructureDeviceAddressKHR(graphics->getDevice(), &accelerationStructureDeviceInfo);
}
2024-07-12 13:33:52 +02:00
constexpr VkTransformMatrixKHR getTransform() const { return matrix; }
constexpr uint64 getIndexOffset() const { return indexOffset; }
constexpr uint64 getVertexOffset() const { return vertexOffset; }
constexpr uint64 getVertexCount() const { return vertexCount; }
constexpr uint32 getPrimitiveCount() const { return primitiveCount; }
2024-06-09 12:20:04 +02:00
private:
2024-06-09 10:44:24 +02:00
PGraphics graphics;
VkAccelerationStructureKHR handle;
2024-06-14 22:12:26 +02:00
OBufferAllocation buffer;
2024-07-08 13:46:49 +02:00
PMaterialInstance material;
2024-07-12 13:33:52 +02:00
VkTransformMatrixKHR matrix;
uint64 indexOffset;
uint64 vertexOffset;
uint64 vertexCount;
uint32 primitiveCount;
friend class Graphics;
2024-06-09 10:44:24 +02:00
};
DEFINE_REF(BottomLevelAS)
2024-06-09 12:20:04 +02:00
class TopLevelAS : public Gfx::TopLevelAS {
public:
2024-06-09 10:44:24 +02:00
TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& createInfo);
~TopLevelAS();
2024-07-10 21:07:10 +02:00
const VkAccelerationStructureKHR getHandle() const { return handle; }
2024-06-09 12:20:04 +02:00
private:
2024-06-09 10:44:24 +02:00
PGraphics graphics;
VkAccelerationStructureKHR handle;
2024-07-10 21:07:10 +02:00
OBufferAllocation instanceAllocation;
OBufferAllocation buffer;
2024-07-12 13:33:52 +02:00
friend class DescriptorSet;
2024-06-09 10:44:24 +02:00
};
DEFINE_REF(TopLevelAS)
2024-07-10 21:07:10 +02:00
class RayTracingPipeline : public Gfx::RayTracingPipeline {
2024-06-18 09:48:00 +02:00
public:
2024-07-10 21:07:10 +02:00
RayTracingPipeline(PGraphics graphics, VkPipeline handle, OBufferAllocation rayGen, uint64 rayGenStride, OBufferAllocation hit,
2024-07-12 13:33:52 +02:00
uint64 hitStride, OBufferAllocation miss, uint64 missStride, OBufferAllocation callable, uint64 callableStride,
Gfx::PPipelineLayout layout);
2024-06-18 23:33:03 +02:00
virtual ~RayTracingPipeline();
2024-07-10 21:07:10 +02:00
void bind(VkCommandBuffer handle);
VkStridedDeviceAddressRegionKHR getRayGenRegion() {
return VkStridedDeviceAddressRegionKHR{
.deviceAddress = rayGen->deviceAddress,
.stride = rayGenStride,
.size = rayGen->size,
};
}
VkStridedDeviceAddressRegionKHR getHitRegion() {
return VkStridedDeviceAddressRegionKHR{
.deviceAddress = hit->deviceAddress,
.stride = hitStride,
.size = hit->size,
};
}
VkStridedDeviceAddressRegionKHR getMissRegion() {
return VkStridedDeviceAddressRegionKHR{
.deviceAddress = miss->deviceAddress,
.stride = missStride,
.size = miss->size,
};
}
2024-07-12 13:33:52 +02:00
VkStridedDeviceAddressRegionKHR getCallableRegion() {
return VkStridedDeviceAddressRegionKHR{
2024-07-15 08:32:50 +02:00
.deviceAddress = 0,//callable->deviceAddress,
.stride = 0,//callableStride,
.size = 0,//callable->size,
2024-07-12 13:33:52 +02:00
};
}
VkPipelineLayout getLayout() const { return layout.cast<PipelineLayout>()->getHandle(); }
2024-06-18 09:48:00 +02:00
private:
2024-06-18 23:33:03 +02:00
PGraphics graphics;
VkPipeline pipeline;
2024-07-10 21:07:10 +02:00
OBufferAllocation rayGen;
uint64 rayGenStride;
OBufferAllocation hit;
uint64 hitStride;
OBufferAllocation miss;
uint64 missStride;
2024-07-12 13:33:52 +02:00
OBufferAllocation callable;
uint64 callableStride;
2024-07-16 15:32:51 +02:00
friend class RenderCommand;
2024-06-18 09:48:00 +02:00
};
DEFINE_REF(RayTracingPipeline)
2024-06-09 12:20:04 +02:00
} // namespace Vulkan
} // namespace Seele