More ray tracing changes

This commit is contained in:
Dynamitos
2024-06-18 09:48:00 +02:00
parent 7cdbb19331
commit cff14981ff
12 changed files with 109 additions and 3 deletions
View File
+13 -1
View File
@@ -2,7 +2,6 @@
#include "Containers/Array.h"
#include "Initializer.h"
#include "MinimalEngine.h"
#include "Query.h"
#include "RenderTarget.h"
#include "Resources.h"
@@ -32,8 +31,15 @@ DECLARE_REF(ComputePipeline)
DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand)
DECLARE_REF(OcclusionQuery)
DECLARE_REF(PipelineStatisticsQuery)
DECLARE_REF(BottomLevelAS)
DECLARE_REF(TopLevelAS)
DECLARE_REF(RayGenShader)
DECLARE_REF(AnyHitShader)
DECLARE_REF(ClosestHitShader)
DECLARE_REF(MissShader)
DECLARE_REF(IntersectionShader)
DECLARE_REF(CallableShader)
class Graphics {
public:
Graphics();
@@ -93,6 +99,12 @@ class Graphics {
virtual OBottomLevelAS createBottomLevelAccelerationStructure(const BottomLevelASCreateInfo& createInfo) = 0;
virtual OTopLevelAS createTopLevelAccelerationStructure(const TopLevelASCreateInfo& createInfo) = 0;
virtual ORayGenShader createRayGenShader(const ShaderCreateInfo& createInfo) = 0;
virtual OAnyHitShader createAnyHitShader(const ShaderCreateInfo& createInfo) = 0;
virtual OClosestHitShader createClosestHitShader(const ShaderCreateInfo& createInfo) = 0;
virtual OMissShader createMissShader(const ShaderCreateInfo& createInfo) = 0;
virtual OIntersectionShader createIntersectionShader(const ShaderCreateInfo& createInfo) = 0;
virtual OCallableShader createCallableShader(const ShaderCreateInfo& createInfo) = 0;
protected:
QueueFamilyMapping queueMapping;
OShaderCompiler shaderCompiler;
+9 -1
View File
@@ -224,7 +224,15 @@ struct ComputePipelineCreateInfo {
Gfx::PComputeShader computeShader = nullptr;
Gfx::PPipelineLayout pipelineLayout = nullptr;
};
DECLARE_REF(ShaderBuffer)
struct RayTracingPipelineCreateInfo {
PPipelineLayout pipelineLayout = nullptr;
PRayGenShader rayGenShader = nullptr;
Array<PClosestHitShader> closestHitShaders;
Array<PAnyHitShader> anyHitShaders;
Array<PIntersectionShader> intersectionShaders;
Array<PMissShader> missShaders;
Array<PCallableShader> callableShaders;
};
struct BottomLevelASCreateInfo {
PMesh mesh;
};
+7
View File
@@ -71,6 +71,13 @@ class MissShader {
};
DEFINE_REF(MissShader)
class IntersectionShader {
public:
IntersectionShader() {}
virtual ~IntersectionShader() {}
};
DEFINE_REF(IntersectionShader)
class CallableShader {
public:
CallableShader() {}
+5
View File
@@ -231,6 +231,7 @@ void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline gfxPipeline) {
pipeline = gfxPipeline.cast<GraphicsPipeline>();
pipeline->bind(handle);
}
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) {
assert(threadId == std::this_thread::get_id());
auto descriptor = descriptorSet.cast<DescriptorSet>();
@@ -268,6 +269,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
dynamicOffsets.size(), dynamicOffsets.data());
delete[] sets;
}
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& streams) {
assert(threadId == std::this_thread::get_id());
Array<VkBuffer> buffers(streams.size());
@@ -281,6 +283,7 @@ void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& streams) {
};
vkCmdBindVertexBuffers(handle, 0, (uint32)streams.size(), buffers.data(), offsets.data());
}
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) {
assert(threadId == std::this_thread::get_id());
PIndexBuffer buf = indexBuffer.cast<IndexBuffer>();
@@ -313,6 +316,8 @@ void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, u
vkCmdDrawMeshTasksIndirectEXT(handle, buffer.cast<ShaderBuffer>()->getHandle(), offset, drawCount, stride);
}
void RenderCommand::traceRays() { vkCmdTraceRaysKHR(handle, ); }
ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool) : graphics(graphics), owner(cmdPool) {
VkCommandBufferAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+2
View File
@@ -86,6 +86,8 @@ class RenderCommand : public Gfx::RenderCommand {
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
virtual void drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override;
virtual void traceRays();
private:
PGraphicsPipeline pipeline;
bool ready;
+36
View File
@@ -319,6 +319,42 @@ Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLev
return new TopLevelAS(this, createInfo);
}
Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) {
ORayGenShader shader = new RayGenShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OAnyHitShader Graphics::createAnyHitShader(const ShaderCreateInfo& createInfo) {
OAnyHitShader shader = new AnyHitShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OClosestHitShader Graphics::createClosestHitShader(const ShaderCreateInfo& createInfo) {
OClosestHitShader shader = new ClosestHitShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OMissShader Graphics::createMissShader(const ShaderCreateInfo& createInfo) {
OMissShader shader = new MissShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OIntersectionShader Graphics::createIntersectionShader(const ShaderCreateInfo& createInfo) {
OIntersectionShader shader = new IntersectionShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OCallableShader Graphics::createCallableShader(const ShaderCreateInfo& createInfo) {
OCallableShader shader = new CallableShader(this);
shader->create(createInfo);
return shader;
}
PCommandPool Graphics::getQueueCommands(Gfx::QueueType queueType) {
switch (queueType) {
case Gfx::QueueType::GRAPHICS:
+7
View File
@@ -77,6 +77,13 @@ class Graphics : public Gfx::Graphics {
virtual Gfx::OBottomLevelAS createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) override;
virtual Gfx::OTopLevelAS createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) override;
virtual Gfx::ORayGenShader createRayGenShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OAnyHitShader createAnyHitShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OClosestHitShader createClosestHitShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OMissShader createMissShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OIntersectionShader createIntersectionShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OCallableShader createCallableShader(const ShaderCreateInfo& createInfo) override;
protected:
Array<const char*> getRequiredExtensions();
void initInstance(GraphicsInitializer initInfo);
+5 -1
View File
@@ -464,4 +464,8 @@ PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo co
PComputePipeline result = pipeline;
graphicsPipelines[hash] = std::move(pipeline);
return result;
}
}
PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) {
}
@@ -1,5 +1,6 @@
#pragma once
#include "Pipeline.h"
#include "RayTracing.h"
namespace Seele {
namespace Vulkan {
@@ -11,6 +12,8 @@ class PipelineCache {
PGraphicsPipeline createPipeline(Gfx::MeshPipelineCreateInfo createInfo);
PComputePipeline createPipeline(Gfx::ComputePipelineCreateInfo createInfo);
PRayTracingPipeline createPipeline(Gfx::RayTracingPipelineCreateInfo createInfo);
private:
Map<uint32, OGraphicsPipeline> graphicsPipelines;
Map<uint32, OComputePipeline> computePipelines;
+7
View File
@@ -29,5 +29,12 @@ class TopLevelAS : public Gfx::TopLevelAS {
VkAccelerationStructureKHR handle;
};
DEFINE_REF(TopLevelAS)
class RayTracingPipeline : public Gfx::RayTracingPipeline
{
public:
private:
};
DEFINE_REF(RayTracingPipeline)
} // namespace Vulkan
} // namespace Seele
+15
View File
@@ -47,5 +47,20 @@ DEFINE_REF(FragmentShader)
DEFINE_REF(ComputeShader)
DEFINE_REF(TaskShader)
DEFINE_REF(MeshShader)
// Ray Tracing
using RayGenShader = ShaderBase<Gfx::RayGenShader, VK_SHADER_STAGE_RAYGEN_BIT_KHR>;
using AnyHitShader = ShaderBase<Gfx::AnyHitShader, VK_SHADER_STAGE_ANY_HIT_BIT_KHR>;
using ClosestHitShader = ShaderBase<Gfx::ClosestHitShader, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR>;
using MissShader = ShaderBase<Gfx::MissShader, VK_SHADER_STAGE_MISS_BIT_KHR>;
using IntersectionShader = ShaderBase<Gfx::IntersectionShader, VK_SHADER_STAGE_INTERSECTION_BIT_KHR>;
using CallableShader = ShaderBase<Gfx::CallableShader, VK_SHADER_STAGE_CALLABLE_BIT_KHR>;
DEFINE_REF(RayGenShader)
DEFINE_REF(AnyHitShader)
DEFINE_REF(ClosestHitShader)
DEFINE_REF(MissShader)
DEFINE_REF(IntersectionShader)
DEFINE_REF(CallableShader)
} // namespace Vulkan
} // namespace Seele