More ray tracing changes
This commit is contained in:
@@ -472,17 +472,19 @@ void BasePass::createRenderPass() {
|
||||
debugPipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
|
||||
debugPipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "DebugVertex",
|
||||
.mainModule = "Debug",
|
||||
.entryPoint = "vertexMain",
|
||||
.modules = {"Debug"},
|
||||
.entryPoints =
|
||||
{
|
||||
{"vertexMain", "Debug"},
|
||||
{"fragmentMain", "Debug"},
|
||||
},
|
||||
.rootSignature = debugPipelineLayout,
|
||||
};
|
||||
debugVertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
createInfo.name = "DebugFragment";
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
debugFragmentShader = graphics->createFragmentShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
debugVertexShader = graphics->createVertexShader({0});
|
||||
debugFragmentShader = graphics->createFragmentShader({1});
|
||||
debugPipelineLayout->create();
|
||||
|
||||
VertexInputStateCreateInfo inputCreate = {
|
||||
@@ -578,17 +580,15 @@ void BasePass::createRenderPass() {
|
||||
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
|
||||
pipelineLayout->addDescriptorLayout(textureLayout);
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "SkyboxVertex",
|
||||
.mainModule = "Skybox",
|
||||
.entryPoint = "vertexMain",
|
||||
.modules = {"Skybox"},
|
||||
.entryPoints = {{"vertexMain", "Skybox"}, {"fragmentMain", "Skybox"}},
|
||||
.rootSignature = pipelineLayout,
|
||||
};
|
||||
vertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
createInfo.name = "SkyboxFragment";
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
vertexShader = graphics->createVertexShader({0});
|
||||
fragmentShader = graphics->createFragmentShader({1});
|
||||
|
||||
pipelineLayout->create();
|
||||
|
||||
|
||||
@@ -65,9 +65,7 @@ DepthCullingPass::DepthCullingPass(Gfx::PGraphics graphics, PScene scene) : Rend
|
||||
|
||||
DepthCullingPass::~DepthCullingPass() {}
|
||||
|
||||
void DepthCullingPass::beginFrame(const Component::Camera& cam) {
|
||||
RenderPass::beginFrame(cam);
|
||||
}
|
||||
void DepthCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
|
||||
|
||||
void DepthCullingPass::render() {
|
||||
query->beginQuery();
|
||||
@@ -231,14 +229,15 @@ void DepthCullingPass::publishOutputs() {
|
||||
};
|
||||
depthMipBuffer = graphics->createShaderBuffer(depthMipInfo);
|
||||
|
||||
ShaderCreateInfo mipComputeInfo = {
|
||||
ShaderCompilationInfo mipComputeInfo = {
|
||||
.name = "DepthMipCompute",
|
||||
.mainModule = "DepthMipGen",
|
||||
.entryPoint = "initialReduce",
|
||||
.modules = {"DepthMipGen"},
|
||||
.entryPoints = {{"initialReduce", "DepthMipGen"}, {"reduceLevel", "DepthMipGen"}},
|
||||
.rootSignature = depthComputeLayout,
|
||||
};
|
||||
|
||||
depthInitialReduceShader = graphics->createComputeShader(mipComputeInfo);
|
||||
graphics->beginShaderCompilation(mipComputeInfo);
|
||||
depthInitialReduceShader = graphics->createComputeShader({0});
|
||||
depthComputeLayout->create();
|
||||
|
||||
Gfx::ComputePipelineCreateInfo pipelineCreateInfo = {
|
||||
@@ -246,10 +245,7 @@ void DepthCullingPass::publishOutputs() {
|
||||
.pipelineLayout = depthComputeLayout,
|
||||
};
|
||||
depthInitialReduce = graphics->createComputePipeline(pipelineCreateInfo);
|
||||
|
||||
mipComputeInfo.entryPoint = "reduceLevel";
|
||||
|
||||
depthMipGenShader = graphics->createComputeShader(mipComputeInfo);
|
||||
depthMipGenShader = graphics->createComputeShader({1});
|
||||
|
||||
pipelineCreateInfo.computeShader = depthMipGenShader;
|
||||
|
||||
|
||||
@@ -144,13 +144,14 @@ void LightCullingPass::publishOutputs() {
|
||||
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
|
||||
cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "Culling",
|
||||
.mainModule = "LightCulling",
|
||||
.entryPoint = "cullLights",
|
||||
.modules = {"LightCulling"},
|
||||
.entryPoints = {{"cullLights", "LightCulling"}},
|
||||
.rootSignature = cullingLayout,
|
||||
};
|
||||
cullingShader = graphics->createComputeShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
cullingShader = graphics->createComputeShader({0});
|
||||
cullingLayout->create();
|
||||
|
||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||
@@ -166,14 +167,15 @@ void LightCullingPass::publishOutputs() {
|
||||
cullingEnableLayout->addDescriptorLayout(cullingDescriptorLayout);
|
||||
cullingEnableLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "Culling",
|
||||
.mainModule = "LightCulling",
|
||||
.entryPoint = "cullLights",
|
||||
.modules = {"LightCulling"},
|
||||
.entryPoints = {{"cullLights", "LightCulling"}},
|
||||
.rootSignature = cullingEnableLayout,
|
||||
};
|
||||
createInfo.defines["LIGHT_CULLING"] = "1";
|
||||
cullingEnabledShader = graphics->createComputeShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
cullingEnabledShader = graphics->createComputeShader({0});
|
||||
cullingEnableLayout->create();
|
||||
|
||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||
@@ -265,14 +267,14 @@ void LightCullingPass::setupFrustums() {
|
||||
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
|
||||
frustumLayout->addDescriptorLayout(viewParamsLayout);
|
||||
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "Frustum",
|
||||
.mainModule = "ComputeFrustums",
|
||||
.entryPoint = "computeFrustums",
|
||||
.modules = {"ComputeFrustums"},
|
||||
.entryPoints = {{"computeFrustums", "ComputeFrustums"}},
|
||||
.rootSignature = frustumLayout,
|
||||
};
|
||||
std::cout << "Compiling frustumShader" << std::endl;
|
||||
frustumShader = graphics->createComputeShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
frustumShader = graphics->createComputeShader({0});
|
||||
// Have to compile shader before finalizing layout as parameters get mapped later
|
||||
frustumLayout->create();
|
||||
dispatchParamsLayout->create();
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
#include "RayTracingPass.h"
|
||||
#include "Graphics/RayTracing.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/StaticMeshVertexData.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
RayTracingPass::RayTracingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
|
||||
paramsLayout = graphics->createDescriptorLayout("pRayTracingParams");
|
||||
paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
|
||||
});
|
||||
paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 2,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
paramsLayout->create();
|
||||
pipelineLayout = graphics->createPipelineLayout("RayTracing");
|
||||
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||
pipelineLayout->addDescriptorLayout(Material::getDescriptorLayout());
|
||||
pipelineLayout->addDescriptorLayout(paramsLayout);
|
||||
pipelineLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
|
||||
graphics->getShaderCompiler()->registerRenderPass("RayTracing", Gfx::PassConfig{
|
||||
.baseLayout = pipelineLayout,
|
||||
.mainFile = "ClosestHit",
|
||||
.useMaterial = true,
|
||||
.rayTracing = true,
|
||||
});
|
||||
}
|
||||
|
||||
void RayTracingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
|
||||
|
||||
void RayTracingPass::render() {
|
||||
Gfx::ORenderCommand command = graphics->createRenderCommand("RayTracing");
|
||||
Array<Gfx::RayTracingHitGroup> hitgroups;
|
||||
Array<Gfx::PBottomLevelAS> accelerationStructures;
|
||||
Array<InstanceData> instanceData;
|
||||
|
||||
for (VertexData* vertexData : VertexData::getList()) {
|
||||
auto& materialData = vertexData->getMaterialData();
|
||||
|
||||
for (auto& matData : materialData) {
|
||||
if (matData.instances.size() == 0)
|
||||
continue;
|
||||
PMaterial mat = matData.material;
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("RayTracing");
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(Gfx::PermutationId(permutation));
|
||||
assert(collection != nullptr);
|
||||
|
||||
for (auto& inst : matData.instances) {
|
||||
for (uint32 i = 0; i < inst.instanceData.size(); ++i) {
|
||||
Gfx::RayTracingHitGroup hitgroup = {
|
||||
.closestHitShader = collection->closestHitShader,
|
||||
.anyHitShader = nullptr,
|
||||
.intersectionShader = nullptr,
|
||||
};
|
||||
hitgroup.parameters.resize(sizeof(VertexData::DrawCallOffsets));
|
||||
std::memcpy(hitgroup.parameters.data(), &inst.offsets, sizeof(VertexData::DrawCallOffsets));
|
||||
hitgroups.add(hitgroup);
|
||||
|
||||
instanceData.add(inst.instanceData[i]);
|
||||
accelerationStructures.add(inst.rayTracingData[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Gfx::OTopLevelAS tlas = graphics->createTopLevelAccelerationStructure(Gfx::TopLevelASCreateInfo{
|
||||
.instances = instanceData,
|
||||
.bottomLevelStructures = accelerationStructures,
|
||||
});
|
||||
Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet();
|
||||
desc->updateAccelerationStructure(0, tlas);
|
||||
desc->updateTexture(1, Gfx::PTexture2D(texture));
|
||||
desc->updateBuffer(2, StaticMeshVertexData::getInstance()->getIndexBuffer());
|
||||
desc->writeChanges();
|
||||
|
||||
Gfx::PRayTracingPipeline pipeline = graphics->createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo{
|
||||
.pipelineLayout = pipelineLayout,
|
||||
.rayGenShader = raygen,
|
||||
.hitgroups = hitgroups,
|
||||
.missShaders = {miss},
|
||||
});
|
||||
|
||||
command->bindPipeline(pipeline);
|
||||
command->bindDescriptor({viewParamsSet, StaticMeshVertexData::getInstance()->getInstanceDataSet(),
|
||||
StaticMeshVertexData::getInstance()->getVertexDataSet(), Material::getDescriptorSet(),
|
||||
scene->getLightEnvironment()->getDescriptorSet()});
|
||||
command->traceRays(texture->getWidth(), texture->getHeight(), 1);
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
commands.add(std::move(command));
|
||||
graphics->executeCommands(std::move(commands));
|
||||
}
|
||||
|
||||
void RayTracingPass::endFrame() {}
|
||||
|
||||
void RayTracingPass::publishOutputs() {
|
||||
ShaderCompilationInfo createInfo{
|
||||
.name = "RayGen",
|
||||
.modules = {"RayGen", "Miss"},
|
||||
.entryPoints = {{"main", "RayGen"}, {"main", "Miss"}},
|
||||
.rootSignature = pipelineLayout,
|
||||
};
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
raygen = graphics->createRayGenShader({0});
|
||||
miss = graphics->createMissShader({1});
|
||||
|
||||
texture = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
});
|
||||
}
|
||||
|
||||
void RayTracingPass::createRenderPass() {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele {
|
||||
@@ -14,5 +15,11 @@ class RayTracingPass : public RenderPass {
|
||||
virtual void createRenderPass() override;
|
||||
|
||||
private:
|
||||
Gfx::PRayGenShader raygen;
|
||||
Gfx::PMissShader miss;
|
||||
Gfx::ODescriptorLayout paramsLayout;
|
||||
Gfx::OPipelineLayout pipelineLayout;
|
||||
Gfx::OTexture2D texture;
|
||||
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -3,7 +3,6 @@
|
||||
using namespace Seele;
|
||||
|
||||
RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene) : graphics(graphics), scene(scene) {
|
||||
|
||||
viewParamsLayout = graphics->createDescriptorLayout("pViewParams");
|
||||
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "Graphics/RenderTarget.h"
|
||||
#include "RenderGraph.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
|
||||
@@ -97,16 +96,15 @@ void TextPass::createRenderPass() {
|
||||
renderTarget = resources->requestRenderTarget("UIPASS_COLOR");
|
||||
depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH");
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "TextVertex",
|
||||
.mainModule = "TextPass",
|
||||
.entryPoint = "vertexMain",
|
||||
.modules = {"TextPass"},
|
||||
.entryPoints = {{"vertexMain", "TextPass"}, {"fragmentMain", "TextFragment"}},
|
||||
};
|
||||
vertexShader = graphics->createVertexShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
vertexShader = graphics->createVertexShader({0});
|
||||
fragmentShader = graphics->createFragmentShader({1});
|
||||
|
||||
createInfo.name = "TextFragment";
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
generalLayout = graphics->createDescriptorLayout("pRender");
|
||||
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "Graphics/RenderTarget.h"
|
||||
#include "RenderGraph.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
UIPass::UIPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
|
||||
@@ -80,16 +79,18 @@ void UIPass::publishOutputs() {
|
||||
}
|
||||
|
||||
void UIPass::createRenderPass() {
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "UIVertex",
|
||||
.mainModule = "UIPass",
|
||||
.entryPoint = "vertexMain",
|
||||
.modules = {"UIPass"},
|
||||
.entryPoints =
|
||||
{
|
||||
{"vertexMain", "UIPass"},
|
||||
{"fragmentMain", "UIFragment"},
|
||||
},
|
||||
};
|
||||
vertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
createInfo.name = "UIFragment";
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
vertexShader = graphics->createVertexShader({0});
|
||||
fragmentShader = graphics->createFragmentShader({1});
|
||||
|
||||
descriptorLayout = graphics->createDescriptorLayout("pParams");
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
|
||||
@@ -59,21 +59,22 @@ void VisibilityPass::publishOutputs() {
|
||||
visibilityDescriptor->create();
|
||||
|
||||
visibilityLayout = graphics->createPipelineLayout("VisibilityLayout");
|
||||
visibilityLayout->addDescriptorLayout(viewParamsLayout);
|
||||
visibilityLayout->addDescriptorLayout(visibilityDescriptor);
|
||||
visibilityLayout->addDescriptorLayout(viewParamsLayout);
|
||||
|
||||
ShaderCreateInfo createInfo = {
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "Visibility",
|
||||
.mainModule = "VisibilityCompute",
|
||||
.entryPoint = "computeMain",
|
||||
.modules = {"VisibilityCompute"},
|
||||
.entryPoints = {{"computeMain", "VisibilityCompute"}},
|
||||
.rootSignature = visibilityLayout,
|
||||
};
|
||||
visibilityShader = graphics->createComputeShader(createInfo);
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
visibilityShader = graphics->createComputeShader({0});
|
||||
visibilityLayout->create();
|
||||
|
||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||
pipelineInfo.computeShader = visibilityShader;
|
||||
pipelineInfo.pipelineLayout = std::move(visibilityLayout);
|
||||
pipelineInfo.pipelineLayout = visibilityLayout;
|
||||
visibilityPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
|
||||
|
||||
cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
|
||||
Reference in New Issue
Block a user