Trying to fix invalid descriptorlayout

This commit is contained in:
Dynamitos
2020-10-03 11:00:10 +02:00
parent 79388bf41a
commit ceee96b462
69 changed files with 1087 additions and 393 deletions
+110 -22
View File
@@ -1,11 +1,14 @@
#include "BasePass.h"
#include "Graphics/Graphics.h"
#include "Graphics/Window.h"
#include "Scene/Components/CameraComponent.h"
#include "Scene/Actor/CameraActor.h"
using namespace Seele;
BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PGraphics graphics, uint8 translucentBasePass)
BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass)
: MeshProcessor(scene, graphics)
, target(viewport)
, translucentBasePass(translucentBasePass)
{
}
@@ -16,31 +19,49 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
void BasePassMeshProcessor::addMeshBatch(
const MeshBatch& batch,
const PPrimitiveComponent primitiveComponent,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId)
{
const PMaterial material = batch.material;
const PMaterialAsset material = batch.material;
const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
const PVertexShaderInput vertexInput = batch.vertexInput;
//TODO query tesselation
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
const Gfx::ShaderCollection* collection = material->getRenderMaterial()->getShaders(Gfx::RenderPassType::BasePass, 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();
buildMeshDrawCommand(batch,
primitiveComponent,
renderPass,
renderCommand,
material,
collection->vertexShader,
collection->controlShader,
collection->evalutionShader,
collection->geometryShader,
collection->fragmentShader,
false);
renderCommand->setViewport(target);
uint32 primitiveDescriptorIndex = 0;
for(uint32 i = 0; i < batch.elements.size(); ++i)
{
pipelineLayout->addDescriptorLayout(2, material->getRenderMaterial()->getDescriptorLayout());
pipelineLayout->create();
descriptorSets[2] = material->getDescriptor();
descriptorSets[3] = cachedPrimitiveSets[primitiveDescriptorIndex++];
buildMeshDrawCommand(batch,
// primitiveComponent,
renderPass,
pipelineLayout,
renderCommand,
descriptorSets,
collection->vertexShader,
collection->controlShader,
collection->evalutionShader,
collection->geometryShader,
collection->fragmentShader,
false);
}
renderCommands.add(renderCommand);
}
@@ -52,12 +73,16 @@ Array<Gfx::PRenderCommand> BasePassMeshProcessor::getRenderCommands()
void BasePassMeshProcessor::clearCommands()
{
renderCommands.clear();
cachedPrimitiveSets.clear();
}
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport)
: processor(new BasePassMeshProcessor(scene, graphics, false))
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: 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;
@@ -70,20 +95,83 @@ BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport v
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout);
BulkResourceData uniformInitializer;
basePassLayout = graphics->createPipelineLayout();
lightLayout = graphics->createDescriptorLayout();
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformInitializer.size = sizeof(LightEnv);
uniformInitializer.data = (uint8*)&scene->getLightEnvironment();
lightUniform = graphics->createUniformBuffer(uniformInitializer);
lightLayout->create();
basePassLayout->addDescriptorLayout(0, lightLayout);
descriptorSets[0] = lightLayout->allocatedDescriptorSet();
viewLayout = graphics->createDescriptorLayout();
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformInitializer.size = sizeof(ViewParameter);
uniformInitializer.data = (uint8*)&viewParams;
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
viewLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformInitializer.size = sizeof(ScreenToViewParameter);
uniformInitializer.data = (uint8*)&screenToViewParams;
screenToViewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
viewLayout->create();
basePassLayout->addDescriptorLayout(1, viewLayout);
descriptorSets[1] = viewLayout->allocatedDescriptorSet();
primitiveLayout = graphics->createDescriptorLayout();
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
primitiveLayout->create();
basePassLayout->addDescriptorLayout(3, primitiveLayout);
}
BasePass::~BasePass()
BasePass::~BasePass()
{
}
void BasePass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
BulkResourceData uniformUpdate;
uniformUpdate.size = sizeof(LightEnv);
uniformUpdate.data = (uint8*)&scene->getLightEnvironment();
lightUniform->updateContents(uniformUpdate);
descriptorSets[0]->beginFrame();
descriptorSets[0]->updateBuffer(0, lightUniform);
descriptorSets[0]->writeChanges();
viewParams.viewMatrix = source->getViewMatrix();
viewParams.projectionMatrix = source->getProjectionMatrix();
viewParams.cameraPosition = Vector4(source->getTransform().getPosition(), 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[1]->beginFrame();
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
descriptorSets[1]->writeChanges();
}
void BasePass::render()
{
processor->clearCommands();
graphics->beginRenderPass(renderPass);
for (auto &&primitive : scene->getStaticMeshes())
{
processor->addMeshBatch(primitive, nullptr, renderPass);
processor->addMeshBatch(primitive, renderPass, basePassLayout, primitiveLayout, descriptorSets);
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
}
void BasePass::endFrame()
{
}
+39 -3
View File
@@ -7,33 +7,69 @@ namespace Seele
class BasePassMeshProcessor : public MeshProcessor
{
public:
BasePassMeshProcessor(const PScene scene, Gfx::PGraphics graphics, uint8 translucentBasePass);
BasePassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor();
virtual void addMeshBatch(
const MeshBatch& batch,
const PPrimitiveComponent primitiveComponent,
// const PPrimitiveComponent primitiveComponent,
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;
uint8 translucentBasePass;
};
DEFINE_REF(BasePassMeshProcessor);
DECLARE_REF(CameraActor);
DECLARE_REF(CameraComponent);
class BasePass
{
public:
BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport);
BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
~BasePass();
void beginFrame();
void render();
void endFrame();
private:
struct ViewParameter
{
Matrix4 viewMatrix;
Matrix4 projectionMatrix;
Vector4 cameraPosition;
} viewParams;
struct ScreenToViewParameter
{
Matrix4 inverseProjectionMatrix;
Vector2 screenDimensions;
} screenToViewParams;
Gfx::PRenderPass renderPass;
Gfx::PTexture2D depthBuffer;
const PScene scene;
UPBasePassMeshProcessor processor;
Gfx::PPipelineLayout basePassLayout;
// Set 0: Light environment
Gfx::PDescriptorLayout lightLayout;
Gfx::PUniformBuffer lightUniform;
// Set 1: viewParameter
Gfx::PDescriptorLayout viewLayout;
Gfx::PUniformBuffer viewParamBuffer;
Gfx::PUniformBuffer screenToViewParamBuffer;
// Set 2: materials, generated
// Set 3: primitive scene data
Gfx::PDescriptorLayout primitiveLayout;
Gfx::PUniformBuffer primitiveUniformBuffer;
Array<Gfx::PDescriptorSet> descriptorSets;
Gfx::PGraphics graphics;
PCameraComponent source;
Gfx::PViewport viewport;
};
DEFINE_REF(BasePass);
} // namespace Seele
@@ -17,10 +17,11 @@ MeshProcessor::~MeshProcessor()
void MeshProcessor::buildMeshDrawCommand(
const MeshBatch& meshBatch,
const PPrimitiveComponent primitiveComponent,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PRenderCommand drawCommand,
PMaterial material,
Array<Gfx::PDescriptorSet> descriptors,
Gfx::PVertexShader vertexShader,
Gfx::PControlShader controlShader,
Gfx::PEvaluationShader evaluationShader,
@@ -40,6 +41,7 @@ void MeshProcessor::buildMeshDrawCommand(
pipelineInitializer.geometryShader = geometryShader;
pipelineInitializer.fragmentShader = fragmentShader;
pipelineInitializer.renderPass = renderPass;
pipelineInitializer.pipelineLayout = pipelineLayout;
VertexInputStreamArray vertexStreams;
if(positionOnly)
@@ -50,9 +52,10 @@ void MeshProcessor::buildMeshDrawCommand(
{
vertexInput->getStreams(vertexStreams);
}
drawCommand->bindVertexBuffer(vertexStreams);
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInitializer);
drawCommand->bindPipeline(pipeline);
drawCommand->bindVertexBuffer(vertexStreams);
drawCommand->bindDescriptor(descriptors);
for(auto element : meshBatch.elements)
{
drawCommand->bindIndexBuffer(element.indexBuffer);
@@ -16,15 +16,19 @@ protected:
Gfx::PGraphics graphics;
virtual void addMeshBatch(
const MeshBatch& meshBatch,
const PPrimitiveComponent primitiveComponent,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId = -1) = 0;
void buildMeshDrawCommand(
const MeshBatch& meshBatch,
const PPrimitiveComponent primitiveComponent,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PRenderCommand drawCommand,
PMaterial material,
Array<Gfx::PDescriptorSet> descriptors,
Gfx::PVertexShader vertexShader,
Gfx::PControlShader controlShader,
Gfx::PEvaluationShader evaluationShader,