Adding basic depth prepass
This commit is contained in:
@@ -48,9 +48,10 @@ public:
|
||||
virtual PGeometryShader createGeometryShader(const ShaderCreateInfo& createInfo) = 0;
|
||||
virtual PFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) = 0;
|
||||
virtual PGraphicsPipeline createGraphicsPipeline(const GraphicsPipelineCreateInfo& createInfo) = 0;
|
||||
virtual PComputePipeline createComputePipeline(const ComputePipelineCreateInfo& createInfo) = 0;
|
||||
virtual PSamplerState createSamplerState(const SamplerCreateInfo& createInfo) = 0;
|
||||
|
||||
virtual PDescriptorLayout createDescriptorLayout() = 0;
|
||||
virtual PDescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
|
||||
virtual PPipelineLayout createPipelineLayout() = 0;
|
||||
|
||||
PVertexBuffer getNullVertexBuffer();
|
||||
|
||||
@@ -120,6 +120,7 @@ struct ShaderCreateInfo
|
||||
{
|
||||
//It's possible to input multiple source files for materials or vertexFactories
|
||||
Array<std::string> shaderCode;
|
||||
std::string name; // Debug info
|
||||
std::string entryPoint;
|
||||
Array<const char*> typeParameter;
|
||||
Map<const char*, const char*> defines;
|
||||
@@ -231,7 +232,7 @@ struct GraphicsPipelineCreateInfo
|
||||
rasterizationState.cullMode = Gfx::SE_CULL_MODE_BACK_BIT;
|
||||
rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
|
||||
rasterizationState.frontFace = Gfx::SE_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
|
||||
depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
||||
depthStencilState.minDepthBounds = 0.0f;
|
||||
depthStencilState.maxDepthBounds = 1.0f;
|
||||
depthStencilState.stencilTestEnable = false;
|
||||
@@ -246,4 +247,13 @@ struct GraphicsPipelineCreateInfo
|
||||
colorBlend.blendConstants[3] = 1.0f;
|
||||
}
|
||||
};
|
||||
struct ComputePipelineCreateInfo
|
||||
{
|
||||
Gfx::PComputeShader computeShader;
|
||||
Gfx::PPipelineLayout pipelineLayout;
|
||||
ComputePipelineCreateInfo()
|
||||
{
|
||||
std::memset((void*)this, 0, sizeof(*this));
|
||||
}
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics.h"
|
||||
#include "RenderPass/DepthPrepass.h"
|
||||
#include "RenderPass/BasePass.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Gfx;
|
||||
@@ -18,6 +20,16 @@ std::string getShaderNameFromRenderPassType(Gfx::RenderPassType type)
|
||||
return "";
|
||||
}
|
||||
}
|
||||
void modifyRenderPassMacros(Gfx::RenderPassType type, Map<const char*, const char*>& defines)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Gfx::RenderPassType::DepthPrepass:
|
||||
DepthPrepass::modifyRenderPassMacros(defines);
|
||||
case Gfx::RenderPassType::BasePass:
|
||||
BasePass::modifyRenderPassMacros(defines);
|
||||
}
|
||||
}
|
||||
|
||||
ShaderMap::ShaderMap()
|
||||
{
|
||||
@@ -55,6 +67,8 @@ ShaderCollection& ShaderMap::createShaders(
|
||||
createInfo.defines["MATERIAL_IMPORT"] = material->getName().c_str();
|
||||
createInfo.defines["NUM_MATERIAL_TEXCOORDS"] = "1";
|
||||
createInfo.defines["USE_INSTANCING"] = "0";
|
||||
modifyRenderPassMacros(renderPass, createInfo.defines);
|
||||
createInfo.name = getShaderNameFromRenderPassType(renderPass) + " Material " + material->getName();
|
||||
|
||||
std::ifstream codeStream("./shaders/" + getShaderNameFromRenderPassType(renderPass), std::ios::ate);
|
||||
auto fileSize = codeStream.tellg();
|
||||
@@ -113,7 +127,8 @@ void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layo
|
||||
{
|
||||
descriptorSetLayouts.resize(setIndex + 1);
|
||||
}
|
||||
if (descriptorSetLayouts[setIndex] != nullptr)
|
||||
// After a second thought, merging descriptor layout bindings is not a good idea
|
||||
/*if (descriptorSetLayouts[setIndex] != nullptr)
|
||||
{
|
||||
auto &thisBindings = descriptorSetLayouts[setIndex]->descriptorBindings;
|
||||
auto &otherBindings = layout->descriptorBindings;
|
||||
@@ -126,7 +141,7 @@ void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layo
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else*/
|
||||
{
|
||||
descriptorSetLayouts[setIndex] = layout;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,14 @@ public:
|
||||
};
|
||||
DEFINE_REF(FragmentShader)
|
||||
|
||||
class ComputeShader
|
||||
{
|
||||
public:
|
||||
ComputeShader() {}
|
||||
virtual ~ComputeShader() {}
|
||||
};
|
||||
DEFINE_REF(ComputeShader)
|
||||
|
||||
//Uniquely identifies a permutation of shaders
|
||||
//using the type parameters used to generate it
|
||||
struct ShaderPermutation
|
||||
@@ -204,8 +212,9 @@ DEFINE_REF(DescriptorSet)
|
||||
class DescriptorLayout
|
||||
{
|
||||
public:
|
||||
DescriptorLayout()
|
||||
DescriptorLayout(const std::string& name)
|
||||
: setIndex(0)
|
||||
, name(name)
|
||||
{
|
||||
}
|
||||
virtual ~DescriptorLayout() {}
|
||||
@@ -232,6 +241,7 @@ protected:
|
||||
Array<DescriptorBinding> descriptorBindings;
|
||||
PDescriptorAllocator allocator;
|
||||
uint32 setIndex;
|
||||
std::string name;
|
||||
friend class PipelineLayout;
|
||||
friend class DescriptorAllocator;
|
||||
};
|
||||
@@ -441,6 +451,19 @@ protected:
|
||||
};
|
||||
DEFINE_REF(GraphicsPipeline)
|
||||
|
||||
class ComputePipeline
|
||||
{
|
||||
public:
|
||||
ComputePipeline(const ComputePipelineCreateInfo& createInfo, PPipelineLayout layout) : createInfo(createInfo), layout(layout) {}
|
||||
virtual ~ComputePipeline(){}
|
||||
const ComputePipelineCreateInfo& getCreateInfo() const { return createInfo; }
|
||||
PPipelineLayout getPipelineLayout() const { return layout; }
|
||||
protected:
|
||||
ComputePipelineCreateInfo createInfo;
|
||||
PPipelineLayout layout;
|
||||
};
|
||||
DEFINE_REF(ComputePipeline)
|
||||
|
||||
// IMPORTANT!!
|
||||
// WHEN DERIVING FROM ANY Gfx:: BASE CLASSES WITH MULTIPLE INHERITANCE
|
||||
// ALWAYS PUT THE Gfx:: BASE CLASS FIRST
|
||||
@@ -505,7 +528,7 @@ public:
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
virtual void onWindowCloseEvent() = 0;
|
||||
virtual PTexture2D getBackBuffer() = 0;
|
||||
virtual PTexture2D getBackBuffer() const = 0;
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) = 0;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
|
||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
|
||||
@@ -559,7 +582,7 @@ public:
|
||||
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
||||
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
|
||||
: texture(texture), loadOp(loadOp), storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp)
|
||||
: loadOp(loadOp), storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp), texture(texture)
|
||||
{
|
||||
}
|
||||
virtual ~RenderTargetAttachment()
|
||||
@@ -583,12 +606,12 @@ public:
|
||||
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
|
||||
SeClearValue clear;
|
||||
SeColorComponentFlags componentFlags;
|
||||
protected:
|
||||
PTexture2D texture;
|
||||
SeAttachmentLoadOp loadOp;
|
||||
SeAttachmentStoreOp storeOp;
|
||||
SeAttachmentLoadOp stencilLoadOp;
|
||||
SeAttachmentStoreOp stencilStoreOp;
|
||||
protected:
|
||||
PTexture2D texture;
|
||||
};
|
||||
DEFINE_REF(RenderTargetAttachment)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Scene/Components/CameraComponent.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -46,10 +47,10 @@ void BasePassMeshProcessor::addMeshBatch(
|
||||
renderCommand->setViewport(target);
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
pipelineLayout->addDescriptorLayout(2, material->getRenderMaterial()->getDescriptorLayout());
|
||||
pipelineLayout->addDescriptorLayout(BasePass::INDEX_MATERIAL, material->getRenderMaterial()->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
descriptorSets[2] = material->getDescriptor();
|
||||
descriptorSets[3] = cachedPrimitiveSets[cachedPrimitiveIndex++];
|
||||
descriptorSets[BasePass::INDEX_MATERIAL] = material->getDescriptor();
|
||||
descriptorSets[BasePass::INDEX_SCENE_DATA] = cachedPrimitiveSets[cachedPrimitiveIndex++];
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
@@ -78,42 +79,29 @@ void BasePassMeshProcessor::clearCommands()
|
||||
cachedPrimitiveIndex = 0;
|
||||
}
|
||||
|
||||
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
: processor(new BasePassMeshProcessor(scene, viewport, graphics, false))
|
||||
BasePass::BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
: RenderPass(renderGraph)
|
||||
, processor(new BasePassMeshProcessor(scene, viewport, graphics, false))
|
||||
, scene(scene)
|
||||
, graphics(graphics)
|
||||
, viewport(viewport)
|
||||
, descriptorSets(4)
|
||||
, source(source->getCameraComponent())
|
||||
{
|
||||
Gfx::PRenderTargetAttachment colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
|
||||
TextureCreateInfo depthBufferInfo;
|
||||
depthBufferInfo.width = viewport->getSizeX();
|
||||
depthBufferInfo.height = viewport->getSizeY();
|
||||
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
|
||||
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
depthBuffer = graphics->createTexture2D(depthBufferInfo);
|
||||
Gfx::PRenderTargetAttachment depthAttachment =
|
||||
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||
depthAttachment->clear.depthStencil.depth = 1.0f;
|
||||
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
||||
renderPass = graphics->createRenderPass(layout);
|
||||
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
|
||||
basePassLayout = graphics->createPipelineLayout();
|
||||
|
||||
lightLayout = graphics->createDescriptorLayout();
|
||||
lightLayout = graphics->createDescriptorLayout("LightLayout");
|
||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
uniformInitializer.resourceData.size = sizeof(LightEnv);
|
||||
uniformInitializer.resourceData.data = nullptr;
|
||||
uniformInitializer.bDynamic = true;
|
||||
lightUniform = graphics->createUniformBuffer(uniformInitializer);
|
||||
lightLayout->create();
|
||||
basePassLayout->addDescriptorLayout(0, lightLayout);
|
||||
descriptorSets[0] = lightLayout->allocatedDescriptorSet();
|
||||
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, lightLayout);
|
||||
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocatedDescriptorSet();
|
||||
|
||||
viewLayout = graphics->createDescriptorLayout();
|
||||
viewLayout = graphics->createDescriptorLayout("ViewLayout");
|
||||
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
uniformInitializer.resourceData.size = sizeof(ViewParameter);
|
||||
uniformInitializer.resourceData.data = (uint8*)&viewParams;
|
||||
@@ -125,13 +113,13 @@ BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport v
|
||||
uniformInitializer.bDynamic = true;
|
||||
screenToViewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
viewLayout->create();
|
||||
basePassLayout->addDescriptorLayout(1, viewLayout);
|
||||
descriptorSets[1] = viewLayout->allocatedDescriptorSet();
|
||||
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocatedDescriptorSet();
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout();
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
primitiveLayout->create();
|
||||
basePassLayout->addDescriptorLayout(3, primitiveLayout);
|
||||
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
}
|
||||
|
||||
BasePass::~BasePass()
|
||||
@@ -146,8 +134,8 @@ void BasePass::beginFrame()
|
||||
uniformUpdate.size = sizeof(LightEnv);
|
||||
uniformUpdate.data = (uint8*)&scene->getLightEnvironment();
|
||||
lightUniform->updateContents(uniformUpdate);
|
||||
descriptorSets[0]->updateBuffer(0, lightUniform);
|
||||
descriptorSets[0]->writeChanges();
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(0, lightUniform);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
|
||||
|
||||
viewParams.viewMatrix = source->getViewMatrix();
|
||||
viewParams.projectionMatrix = source->getProjectionMatrix();
|
||||
@@ -160,9 +148,9 @@ void BasePass::beginFrame()
|
||||
uniformUpdate.size = sizeof(ScreenToViewParameter);
|
||||
uniformUpdate.data = (uint8*)&screenToViewParams;
|
||||
screenToViewParamBuffer->updateContents(uniformUpdate);
|
||||
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
|
||||
descriptorSets[1]->writeChanges();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(1, screenToViewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
for(auto &&meshBatch : scene->getStaticMeshes())
|
||||
{
|
||||
meshBatch.material->updateDescriptorData();
|
||||
@@ -183,3 +171,25 @@ void BasePass::render()
|
||||
void BasePass::endFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void BasePass::publishOutputs()
|
||||
{
|
||||
colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
|
||||
renderGraph->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
||||
}
|
||||
|
||||
void BasePass::createRenderPass()
|
||||
{
|
||||
Gfx::PRenderTargetAttachment depthAttachment = renderGraph->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
||||
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
||||
renderPass = graphics->createRenderPass(layout);
|
||||
}
|
||||
|
||||
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
|
||||
{
|
||||
defines["INDEX_LIGHT_ENV"] = "0";
|
||||
defines["INDEX_VIEW_PARAMS"] = "1";
|
||||
defines["INDEX_MATERIAL"] = "2";
|
||||
defines["INDEX_SCENE_DATA"] = "3";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -30,28 +31,19 @@ private:
|
||||
DEFINE_REF(BasePassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(CameraComponent)
|
||||
class BasePass
|
||||
class BasePass : public RenderPass
|
||||
{
|
||||
public:
|
||||
BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
|
||||
~BasePass();
|
||||
void beginFrame();
|
||||
void render();
|
||||
void endFrame();
|
||||
BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
|
||||
virtual ~BasePass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
struct ViewParameter
|
||||
{
|
||||
Matrix4 viewMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
Vector4 cameraPosition;
|
||||
} viewParams;
|
||||
struct ScreenToViewParameter
|
||||
{
|
||||
Matrix4 inverseProjectionMatrix;
|
||||
Vector2 screenDimensions;
|
||||
} screenToViewParams;
|
||||
|
||||
Gfx::PRenderPass renderPass;
|
||||
Gfx::PRenderTargetAttachment colorAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPBasePassMeshProcessor processor;
|
||||
const PScene scene;
|
||||
@@ -61,16 +53,21 @@ private:
|
||||
PCameraComponent source;
|
||||
Gfx::PPipelineLayout basePassLayout;
|
||||
// Set 0: Light environment
|
||||
static constexpr uint32 INDEX_LIGHT_ENV = 0;
|
||||
Gfx::PDescriptorLayout lightLayout;
|
||||
Gfx::PUniformBuffer lightUniform;
|
||||
// Set 1: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 1;
|
||||
Gfx::PDescriptorLayout viewLayout;
|
||||
Gfx::PUniformBuffer viewParamBuffer;
|
||||
Gfx::PUniformBuffer screenToViewParamBuffer;
|
||||
// Set 2: materials, generated
|
||||
static constexpr uint32 INDEX_MATERIAL = 2;
|
||||
// Set 3: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 3;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class BasePassMeshProcessor;
|
||||
};
|
||||
DEFINE_REF(BasePass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -4,5 +4,11 @@ target_sources(SeeleEngine
|
||||
BasePass.cpp
|
||||
DepthPrepass.h
|
||||
DepthPrepass.cpp
|
||||
LightCullingPass.h
|
||||
LightCullingPass.cpp
|
||||
MeshProcessor.h
|
||||
MeshProcessor.cpp)
|
||||
MeshProcessor.cpp
|
||||
RenderGraph.h
|
||||
RenderGraph.cpp
|
||||
RenderPass.h
|
||||
RenderPass.cpp)
|
||||
@@ -0,0 +1,185 @@
|
||||
#include "DepthPrepass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Scene/Components/CameraComponent.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics)
|
||||
: MeshProcessor(scene, graphics)
|
||||
, target(viewport)
|
||||
, cachedPrimitiveIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepassMeshProcessor::addMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet>& descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
const PMaterialAsset material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getRenderMaterial()->getShaders(Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
assert(collection != nullptr);
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
Gfx::PDescriptorSet descriptorSet = primitiveLayout->allocatedDescriptorSet();
|
||||
descriptorSet->updateBuffer(0, batch.elements[i].uniformBuffer);
|
||||
descriptorSet->writeChanges();
|
||||
cachedPrimitiveSets.add(descriptorSet);
|
||||
}
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
pipelineLayout->addDescriptorLayout(DepthPrepass::INDEX_MATERIAL, material->getRenderMaterial()->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
descriptorSets[DepthPrepass::INDEX_MATERIAL] = material->getDescriptor();
|
||||
descriptorSets[DepthPrepass::INDEX_SCENE_DATA] = cachedPrimitiveSets[cachedPrimitiveIndex++];
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
descriptorSets,
|
||||
collection->vertexShader,
|
||||
collection->controlShader,
|
||||
collection->evalutionShader,
|
||||
collection->geometryShader,
|
||||
collection->fragmentShader,
|
||||
true);
|
||||
}
|
||||
renderCommands.add(renderCommand);
|
||||
}
|
||||
|
||||
Array<Gfx::PRenderCommand> DepthPrepassMeshProcessor::getRenderCommands()
|
||||
{
|
||||
return renderCommands;
|
||||
}
|
||||
|
||||
void DepthPrepassMeshProcessor::clearCommands()
|
||||
{
|
||||
renderCommands.clear();
|
||||
cachedPrimitiveSets.clear();
|
||||
cachedPrimitiveIndex = 0;
|
||||
}
|
||||
|
||||
DepthPrepass::DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
: RenderPass(renderGraph)
|
||||
, processor(new DepthPrepassMeshProcessor(scene, viewport, graphics))
|
||||
, scene(scene)
|
||||
, graphics(graphics)
|
||||
, viewport(viewport)
|
||||
, descriptorSets(3)
|
||||
, source(source->getCameraComponent())
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
|
||||
depthPrepassLayout = graphics->createPipelineLayout();
|
||||
|
||||
viewLayout = graphics->createDescriptorLayout("ViewLayout");
|
||||
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
uniformInitializer.resourceData.size = sizeof(ViewParameter);
|
||||
uniformInitializer.resourceData.data = (uint8*)&viewParams;
|
||||
uniformInitializer.bDynamic = true;
|
||||
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
viewLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
uniformInitializer.resourceData.size = sizeof(ScreenToViewParameter);
|
||||
uniformInitializer.resourceData.data = (uint8*)&screenToViewParams;
|
||||
uniformInitializer.bDynamic = true;
|
||||
screenToViewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
viewLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocatedDescriptorSet();
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
primitiveLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
}
|
||||
|
||||
DepthPrepass::~DepthPrepass()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepass::beginFrame()
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = source->getViewMatrix();
|
||||
viewParams.projectionMatrix = source->getProjectionMatrix();
|
||||
viewParams.cameraPosition = Vector4(source->getCameraPosition(), 0);
|
||||
screenToViewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
|
||||
screenToViewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamBuffer->updateContents(uniformUpdate);
|
||||
uniformUpdate.size = sizeof(ScreenToViewParameter);
|
||||
uniformUpdate.data = (uint8*)&screenToViewParams;
|
||||
screenToViewParamBuffer->updateContents(uniformUpdate);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(1, screenToViewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
for(auto &&meshBatch : scene->getStaticMeshes())
|
||||
{
|
||||
meshBatch.material->updateDescriptorData();
|
||||
}
|
||||
}
|
||||
|
||||
void DepthPrepass::render()
|
||||
{
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (auto &&meshBatch : scene->getStaticMeshes())
|
||||
{
|
||||
processor->addMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
}
|
||||
|
||||
void DepthPrepass::endFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepass::publishOutputs()
|
||||
{
|
||||
TextureCreateInfo depthBufferInfo;
|
||||
depthBufferInfo.width = viewport->getSizeX();
|
||||
depthBufferInfo.height = viewport->getSizeY();
|
||||
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
|
||||
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
depthBuffer = graphics->createTexture2D(depthBufferInfo);
|
||||
depthAttachment =
|
||||
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||
depthAttachment->clear.depthStencil.depth = 1.0f;
|
||||
renderGraph->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
|
||||
}
|
||||
|
||||
void DepthPrepass::createRenderPass()
|
||||
{
|
||||
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(depthAttachment);
|
||||
renderPass = graphics->createRenderPass(layout);
|
||||
}
|
||||
|
||||
void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
|
||||
{
|
||||
defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
defines["INDEX_MATERIAL"] = "1";
|
||||
defines["INDEX_SCENE_DATA"] = "2";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class DepthPrepassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
DepthPrepassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics);
|
||||
virtual ~DepthPrepassMeshProcessor();
|
||||
|
||||
virtual void addMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet>& descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
|
||||
Array<Gfx::PRenderCommand> getRenderCommands();
|
||||
void clearCommands();
|
||||
private:
|
||||
Array<Gfx::PRenderCommand> renderCommands;
|
||||
Array<Gfx::PDescriptorSet> cachedPrimitiveSets;
|
||||
Gfx::PViewport target;
|
||||
uint32 cachedPrimitiveIndex;
|
||||
};
|
||||
DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(CameraComponent)
|
||||
class DepthPrepass : public RenderPass
|
||||
{
|
||||
public:
|
||||
DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
|
||||
~DepthPrepass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPDepthPrepassMeshProcessor processor;
|
||||
const PScene scene;
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
PCameraComponent source;
|
||||
Gfx::PPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
Gfx::PDescriptorLayout viewLayout;
|
||||
Gfx::PUniformBuffer viewParamBuffer;
|
||||
Gfx::PUniformBuffer screenToViewParamBuffer;
|
||||
// Set 1: materials, generated
|
||||
static constexpr uint32 INDEX_MATERIAL = 1;
|
||||
// Set 2: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 2;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class DepthPrepassMeshProcessor;
|
||||
};
|
||||
DEFINE_REF(DepthPrepass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "LightCullingPass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Scene/Components/CameraComponent.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
LightCullingPass::LightCullingPass(PRenderGraph renderGraph, Gfx::PViewport viewport, Gfx::PGraphics graphics, PCameraActor camera)
|
||||
: RenderPass(renderGraph)
|
||||
, viewport(viewport)
|
||||
, graphics(graphics)
|
||||
, source(camera->getCameraComponent())
|
||||
{
|
||||
}
|
||||
|
||||
LightCullingPass::~LightCullingPass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::beginFrame()
|
||||
{
|
||||
uint32_t viewportWidth = viewport->getSizeX();
|
||||
uint32_t viewportHeight = viewport->getSizeY();
|
||||
|
||||
glm::uvec3 numThreads = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
|
||||
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
|
||||
|
||||
dispatchParams.numThreads = numThreads;
|
||||
dispatchParams.numThreadGroups = numThreadGroups;
|
||||
ScreenToView screenToView;
|
||||
screenToView.inverseProjection = glm::inverse(source->getProjectionMatrix());
|
||||
screenToView.screenDimensions = glm::vec2(viewportWidth, viewportHeight);
|
||||
|
||||
frustumShader = renderDevice->createComputeShader(loadPlaintext("./_Game/shaders/ComputeFrustums.slang"), "computeFrustums");
|
||||
frustumDescriptorLayout = renderDevice->createDescriptorLayout();
|
||||
frustumDescriptorLayout->addDescriptorBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
frustumDescriptorLayout->addDescriptorBinding(1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
frustumDescriptorLayout->addDescriptorBinding(2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
frustumLayout = renderDevice->createPipelineLayout();
|
||||
frustumLayout->addPushConstants(init::PushConstantRange(VK_SHADER_STAGE_COMPUTE_BIT, sizeof(DispatchParams), 0));
|
||||
frustumLayout->addDescriptorLayout(0, frustumDescriptorLayout);
|
||||
frustumLayout->create();
|
||||
frustumShader->setPipelineLayout(frustumLayout);
|
||||
RHIResourceCreateInfo frustumInfo;
|
||||
frustumBuffer = renderDevice->createStructuredBuffer(sizeof(Frustum), sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z, BufferUsageFlags::BUF_UnorderedAccess, frustumInfo);
|
||||
dispatchParamsBuffer = renderDevice->createUniformBuffer(&dispatchParams, sizeof(DispatchParams), UniformBuffer_MultiFrame);
|
||||
screenToViewParams = renderDevice->createUniformBuffer(&screenToView, sizeof(ScreenToView), UniformBuffer_MultiFrame);
|
||||
frustumDescriptorSet = frustumDescriptorLayout->allocateDescriptorSet();
|
||||
frustumDescriptorSet->updateBuffer(0, dispatchParamsBuffer);
|
||||
frustumDescriptorSet->updateBuffer(1, screenToViewParams);
|
||||
frustumDescriptorSet->updateBuffer(2, frustumBuffer);
|
||||
frustumDescriptorSet->writeChanges();
|
||||
renderDevice->setComputeShader(frustumShader);
|
||||
renderDevice->bindComputeDescriptors(frustumLayout, frustumDescriptorSet);
|
||||
renderDevice->dispatchComputeShader(numThreadGroups.x, numThreadGroups.y, numThreadGroups.z);
|
||||
renderDevice->pipelineBarrier(frustumBuffer, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
}
|
||||
|
||||
void LightCullingPass::render()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::endFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::publishOutputs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::createRenderPass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(CameraComponent)
|
||||
DECLARE_NAME_REF(Gfx, Viewport)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
class LightCullingPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
LightCullingPass(PRenderGraph renderGraph, Gfx::PViewport viewport, Gfx::PGraphics graphics, PCameraActor camera);
|
||||
virtual ~LightCullingPass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
static constexpr uint32 BLOCK_SIZE = 8;
|
||||
_declspec(align(16)) struct DispatchParams
|
||||
{
|
||||
glm::uvec3 numThreadGroups;
|
||||
uint32_t pad0;
|
||||
glm::uvec3 numThreads;
|
||||
uint32_t pad1;
|
||||
} dispatchParams;
|
||||
__declspec(align(16)) struct Plane
|
||||
{
|
||||
Vector n;
|
||||
float d;
|
||||
Vector p0;
|
||||
Vector p1;
|
||||
Vector p2;
|
||||
};
|
||||
__declspec(align(16)) struct Frustum
|
||||
{
|
||||
Plane planes[4];
|
||||
};
|
||||
struct ScreenToView
|
||||
{
|
||||
Matrix4 inverseProjection;
|
||||
Vector2 screenDimensions;
|
||||
};
|
||||
Gfx::PViewport viewport;
|
||||
Gfx::PGraphics graphics;
|
||||
PCameraComponent source;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "RenderGraph.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
|
||||
RenderGraph::RenderGraph()
|
||||
{
|
||||
}
|
||||
|
||||
RenderGraph::~RenderGraph()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderGraph::setup()
|
||||
{
|
||||
for(auto pass : renderPasses)
|
||||
{
|
||||
pass->publishOutputs();
|
||||
}
|
||||
for(auto pass : renderPasses)
|
||||
{
|
||||
pass->createRenderPass();
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::PRenderTargetAttachment RenderGraph::requestRenderTarget(const std::string& outputName)
|
||||
{
|
||||
if(registeredAttachments.find(outputName) == registeredAttachments.end())
|
||||
{
|
||||
std::cout << "Attachment " << outputName << " not found" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return registeredAttachments[outputName];
|
||||
}
|
||||
|
||||
void RenderGraph::registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment)
|
||||
{
|
||||
registeredAttachments[outputName] = attachment;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class RenderGraph
|
||||
{
|
||||
public:
|
||||
RenderGraph();
|
||||
~RenderGraph();
|
||||
void setup();
|
||||
Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName);
|
||||
void registerRenderPassOutput(const std::string& ouputName, Gfx::PRenderTargetAttachment attachment);
|
||||
private:
|
||||
Map<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
|
||||
List<PRenderPass> renderPasses;
|
||||
};
|
||||
DEFINE_REF(RenderGraph)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "RenderPass.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
RenderPass::RenderPass(PRenderGraph renderGraph)
|
||||
: renderGraph(renderGraph)
|
||||
{
|
||||
}
|
||||
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Math/Math.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_NAME_REF(Gfx, RenderPass)
|
||||
DECLARE_REF(RenderGraph)
|
||||
class RenderPass
|
||||
{
|
||||
public:
|
||||
RenderPass(PRenderGraph rendergraph);
|
||||
virtual ~RenderPass();
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
virtual void publishOutputs() = 0;
|
||||
virtual void createRenderPass() = 0;
|
||||
protected:
|
||||
struct ViewParameter
|
||||
{
|
||||
Matrix4 viewMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
Vector4 cameraPosition;
|
||||
} viewParams;
|
||||
struct ScreenToViewParameter
|
||||
{
|
||||
Matrix4 inverseProjectionMatrix;
|
||||
Vector2 screenDimensions;
|
||||
} screenToViewParams;
|
||||
Gfx::PRenderPass renderPass;
|
||||
PRenderGraph renderGraph;
|
||||
};
|
||||
DEFINE_REF(RenderPass)
|
||||
} // namespace Seele
|
||||
@@ -30,8 +30,8 @@ void StaticMeshVertexInput::init(Gfx::PGraphics graphics)
|
||||
elements.add(accessStreamComponent(data.positionStream, 0));
|
||||
}
|
||||
|
||||
uint8 tangentBasisAttributes[2] = {1, 2};
|
||||
for(int32 axisIndex = 0; axisIndex < 2; axisIndex++)
|
||||
uint8 tangentBasisAttributes[3] = {1, 2, 3};
|
||||
for(int32 axisIndex = 0; axisIndex < 3; axisIndex++)
|
||||
{
|
||||
if(data.tangentBasisComponents[axisIndex].vertexBuffer != nullptr)
|
||||
{
|
||||
@@ -41,15 +41,15 @@ void StaticMeshVertexInput::init(Gfx::PGraphics graphics)
|
||||
|
||||
if(data.colorComponent.vertexBuffer != nullptr)
|
||||
{
|
||||
elements.add(accessStreamComponent(data.colorComponent, 3));
|
||||
elements.add(accessStreamComponent(data.colorComponent, 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
elements.add(accessStreamComponent(VertexStreamComponent(graphics->getNullVertexBuffer(), 0, 0, Gfx::SE_FORMAT_R32G32B32A32_SFLOAT), 3));
|
||||
elements.add(accessStreamComponent(VertexStreamComponent(graphics->getNullVertexBuffer(), 0, 0, Gfx::SE_FORMAT_R32G32B32A32_SFLOAT), 4));
|
||||
}
|
||||
if(data.textureCoordinates.size())
|
||||
{
|
||||
const int32 baseTexCoordAttribute = 4;
|
||||
const int32 baseTexCoordAttribute = 5;
|
||||
for(uint32 coordinateIndex = 0; coordinateIndex < data.textureCoordinates.size(); ++coordinateIndex)
|
||||
{
|
||||
elements.add(accessStreamComponent(
|
||||
|
||||
@@ -7,7 +7,7 @@ enum { MAX_TEXCOORDS = 4 };
|
||||
struct StaticMeshDataType
|
||||
{
|
||||
VertexStreamComponent positionStream;
|
||||
VertexStreamComponent tangentBasisComponents[2];
|
||||
VertexStreamComponent tangentBasisComponents[3];
|
||||
|
||||
//Dont forget these are 4 component vectors
|
||||
Array<VertexStreamComponent> textureCoordinates;
|
||||
|
||||
@@ -101,7 +101,7 @@ Gfx::VertexElement VertexShaderInput::accessPositionStreamComponent(const Vertex
|
||||
vertexStream.stride = component.stride;
|
||||
vertexStream.offset = component.offset;
|
||||
|
||||
return Gfx::VertexElement((uint8)streams.indexOf(streams.addUnique(vertexStream)), component.offset, component.type, attributeIndex, vertexStream.stride);
|
||||
return Gfx::VertexElement((uint8)positionStreams.indexOf(positionStreams.addUnique(vertexStream)), component.offset, component.type, attributeIndex, vertexStream.stride);
|
||||
}
|
||||
|
||||
void VertexShaderInput::initDeclaration(Gfx::PGraphics graphics, Array<Gfx::VertexElement>& elements)
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
DescriptorLayout::DescriptorLayout(PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
||||
: Gfx::DescriptorLayout(name)
|
||||
, graphics(graphics)
|
||||
, layoutHandle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
@@ -67,6 +68,7 @@ void PipelineLayout::create()
|
||||
// There could be unused descriptor set indices
|
||||
if(descriptorSetLayouts[i] == nullptr)
|
||||
{
|
||||
vulkanDescriptorLayouts[i] = VK_NULL_HANDLE;
|
||||
continue;
|
||||
}
|
||||
PDescriptorLayout layout = descriptorSetLayouts[i].cast<DescriptorLayout>();
|
||||
@@ -81,7 +83,7 @@ void PipelineLayout::create()
|
||||
{
|
||||
vkPushConstants[i].offset = pushConstants[i].offset;
|
||||
vkPushConstants[i].size = pushConstants[i].size;
|
||||
vkPushConstants[i].stageFlags = cast((VkShaderStageFlagBits)pushConstants[i].stageFlags);
|
||||
vkPushConstants[i].stageFlags = (VkShaderStageFlagBits)pushConstants[i].stageFlags;
|
||||
}
|
||||
createInfo.pushConstantRangeCount = (uint32)vkPushConstants.size();
|
||||
createInfo.pPushConstantRanges = vkPushConstants.data();
|
||||
|
||||
@@ -9,7 +9,7 @@ DECLARE_REF(Graphics)
|
||||
class DescriptorLayout : public Gfx::DescriptorLayout
|
||||
{
|
||||
public:
|
||||
DescriptorLayout(PGraphics graphics);
|
||||
DescriptorLayout(PGraphics graphics, const std::string& name);
|
||||
virtual ~DescriptorLayout();
|
||||
virtual void create();
|
||||
inline VkDescriptorSetLayout getHandle() const
|
||||
@@ -22,6 +22,7 @@ private:
|
||||
PGraphics graphics;
|
||||
Array<VkDescriptorSetLayoutBinding> bindings;
|
||||
VkDescriptorSetLayout layoutHandle;
|
||||
std::string name;
|
||||
friend class DescriptorAllocator;
|
||||
};
|
||||
DEFINE_REF(DescriptorLayout)
|
||||
|
||||
@@ -164,6 +164,12 @@ Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(const GraphicsPipelineCr
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
Gfx::PComputePipeline Graphics::createComputePipeline(const ComputePipelineCreateInfo& createInfo)
|
||||
{
|
||||
PComputePipeline pipeline = pipelineCache->createPipeline(createInfo);
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
Gfx::PSamplerState Graphics::createSamplerState(const SamplerCreateInfo&)
|
||||
{
|
||||
PSamplerState sampler = new SamplerState(); // TODO: proper sampler creation
|
||||
@@ -172,9 +178,9 @@ Gfx::PSamplerState Graphics::createSamplerState(const SamplerCreateInfo&)
|
||||
VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler));
|
||||
return sampler;
|
||||
}
|
||||
Gfx::PDescriptorLayout Graphics::createDescriptorLayout()
|
||||
Gfx::PDescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
|
||||
{
|
||||
PDescriptorLayout layout = new DescriptorLayout(this);
|
||||
PDescriptorLayout layout = new DescriptorLayout(this, name);
|
||||
return layout;
|
||||
}
|
||||
Gfx::PPipelineLayout Graphics::createPipelineLayout()
|
||||
|
||||
@@ -60,9 +60,10 @@ public:
|
||||
virtual Gfx::PGeometryShader createGeometryShader(const ShaderCreateInfo& createInfo) override;
|
||||
virtual Gfx::PFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
||||
virtual Gfx::PGraphicsPipeline createGraphicsPipeline(const GraphicsPipelineCreateInfo& createInfo) override;
|
||||
virtual Gfx::PComputePipeline createComputePipeline(const ComputePipelineCreateInfo& createInfo) override;
|
||||
virtual Gfx::PSamplerState createSamplerState(const SamplerCreateInfo& createInfo) override;
|
||||
|
||||
virtual Gfx::PDescriptorLayout createDescriptorLayout() override;
|
||||
virtual Gfx::PDescriptorLayout createDescriptorLayout(const std::string& name = "") override;
|
||||
virtual Gfx::PPipelineLayout createPipelineLayout() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
virtual ~Window();
|
||||
virtual void beginFrame() override;
|
||||
virtual void endFrame() override;
|
||||
virtual Gfx::PTexture2D getBackBuffer() override;
|
||||
virtual Gfx::PTexture2D getBackBuffer() const override;
|
||||
virtual void onWindowCloseEvent() override;
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||
|
||||
@@ -24,4 +24,26 @@ void GraphicsPipeline::bind(VkCommandBuffer handle)
|
||||
VkPipelineLayout GraphicsPipeline::getLayout() const
|
||||
{
|
||||
return layout.cast<PipelineLayout>()->getHandle();
|
||||
}
|
||||
|
||||
ComputePipeline::ComputePipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout, const ComputePipelineCreateInfo& createInfo)
|
||||
: Gfx::ComputePipeline(createInfo, pipelineLayout)
|
||||
, graphics(graphics)
|
||||
, pipeline(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ComputePipeline::~ComputePipeline()
|
||||
{
|
||||
}
|
||||
|
||||
void ComputePipeline::bind(VkCommandBuffer handle)
|
||||
{
|
||||
vkCmdBindPipeline(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
|
||||
}
|
||||
|
||||
VkPipelineLayout ComputePipeline::getLayout() const
|
||||
{
|
||||
return layout.cast<PipelineLayout>()->getHandle();
|
||||
}
|
||||
@@ -19,5 +19,17 @@ private:
|
||||
VkPipeline pipeline;
|
||||
};
|
||||
DEFINE_REF(GraphicsPipeline)
|
||||
class ComputePipeline : public Gfx::ComputePipeline
|
||||
{
|
||||
public:
|
||||
ComputePipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout, const ComputePipelineCreateInfo& createInfo);
|
||||
virtual ~ComputePipeline();
|
||||
void bind(VkCommandBuffer handle);
|
||||
VkPipelineLayout getLayout() const;
|
||||
private:
|
||||
PGraphics graphics;
|
||||
VkPipeline pipeline;
|
||||
};
|
||||
DEFINE_REF(ComputePipeline)
|
||||
} // namespace Vulkan
|
||||
} // namespace Seele
|
||||
@@ -352,4 +352,25 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
|
||||
|
||||
PGraphicsPipeline result = new GraphicsPipeline(graphics, pipelineHandle, layout, gfxInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
PComputePipeline PipelineCache::createPipeline(const ComputePipelineCreateInfo& computeInfo)
|
||||
{
|
||||
VkComputePipelineCreateInfo createInfo;
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
|
||||
createInfo.pNext = 0;
|
||||
createInfo.flags = 0;
|
||||
createInfo.basePipelineIndex = 0;
|
||||
createInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
auto layout = computeInfo.pipelineLayout.cast<PipelineLayout>();
|
||||
createInfo.layout = layout->getHandle();
|
||||
auto computeStage = computeInfo.computeShader.cast<ComputeShader>();
|
||||
createInfo.stage = init::PipelineShaderStageCreateInfo(
|
||||
VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
computeStage->getModuleHandle(),
|
||||
computeStage->getEntryPointName());
|
||||
VkPipeline pipelineHandle;
|
||||
VK_CHECK(vkCreateComputePipelines(graphics->getDevice(), cache, 1, &createInfo, nullptr, &pipelineHandle));
|
||||
PComputePipeline result = new ComputePipeline(graphics, pipelineHandle, layout, computeInfo);
|
||||
return result;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public:
|
||||
PipelineCache(PGraphics graphics, const std::string& cacheFilePath);
|
||||
~PipelineCache();
|
||||
PGraphicsPipeline createPipeline(const GraphicsPipelineCreateInfo& createInfo);
|
||||
PComputePipeline createPipeline(const ComputePipelineCreateInfo& createInfo);
|
||||
private:
|
||||
VkPipelineCache cache;
|
||||
PGraphics graphics;
|
||||
|
||||
@@ -118,9 +118,9 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
if(spCompile(request))
|
||||
{
|
||||
char const* diagnostics = spGetDiagnosticOutput(request);
|
||||
std::cout << "Compile error for shader " << createInfo.name << std::endl;
|
||||
std::cout << diagnostics << std::endl;
|
||||
}
|
||||
|
||||
size_t dataSize = 0;
|
||||
const uint32* data = reinterpret_cast<const uint32*>(spGetEntryPointCode(request, entryPointIndex, &dataSize));
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void Window::onWindowCloseEvent()
|
||||
{
|
||||
}
|
||||
|
||||
Gfx::PTexture2D Window::getBackBuffer()
|
||||
Gfx::PTexture2D Window::getBackBuffer() const
|
||||
{
|
||||
return backBufferImages[currentImageIndex];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user