Text Rendering works

This commit is contained in:
Dynamitos
2022-04-15 23:45:44 +02:00
parent eb23264c40
commit 03e1a5784d
70 changed files with 1178 additions and 476 deletions
+9 -12
View File
@@ -20,7 +20,7 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
{
}
MainJob BasePassMeshProcessor::processMeshBatch(
void BasePassMeshProcessor::processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass,
@@ -66,7 +66,7 @@ MainJob BasePassMeshProcessor::processMeshBatch(
}
std::scoped_lock lock(commandLock);
renderCommands.add(renderCommand);
co_return;
//co_return;
}
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
@@ -114,7 +114,7 @@ BasePass::~BasePass()
{
}
MainJob BasePass::beginFrame()
void BasePass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
@@ -135,10 +135,10 @@ MainJob BasePass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "BasePass beginFrame()" << std::endl;
co_return;
//co_return;
}
MainJob BasePass::render()
void BasePass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
@@ -155,23 +155,20 @@ MainJob BasePass::render()
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
graphics->beginRenderPass(renderPass);
List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList)
{
//jobs.add(
co_await processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
}
//co_await Job::all(jobs);
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
//std::cout << "BasePass render()" << std::endl;
co_return;
//co_return;
}
MainJob BasePass::endFrame()
void BasePass::endFrame()
{
//std::cout << "BasePass endFrame()" << std::endl;
co_return;
//co_return;
}
void BasePass::publishOutputs()
+4 -4
View File
@@ -11,7 +11,7 @@ public:
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor();
virtual MainJob processMeshBatch(
virtual void processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass,
@@ -37,9 +37,9 @@ class BasePass : public RenderPass<BasePassData>
public:
BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
virtual ~BasePass();
virtual MainJob beginFrame() override;
virtual MainJob render() override;
virtual MainJob endFrame() override;
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);
+10 -13
View File
@@ -18,7 +18,7 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
{
}
MainJob DepthPrepassMeshProcessor::processMeshBatch(
void DepthPrepassMeshProcessor::processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass,
@@ -27,7 +27,7 @@ MainJob DepthPrepassMeshProcessor::processMeshBatch(
Array<Gfx::PDescriptorSet> descriptorSets,
int32 /*staticMeshId*/)
{
//std::cout << "Depth job started" << std::endl;
//std::cout << "Depth void started" << std::endl;
PMaterialAsset material = batch.material;
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
@@ -65,7 +65,7 @@ MainJob DepthPrepassMeshProcessor::processMeshBatch(
std::scoped_lock lock(commandLock);
renderCommands.add(renderCommand);
//std::cout << "Finished depth job" << std::endl;
co_return;
//co_return;
}
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
@@ -97,7 +97,7 @@ DepthPrepass::~DepthPrepass()
{
}
MainJob DepthPrepass::beginFrame()
void DepthPrepass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
@@ -116,33 +116,30 @@ MainJob DepthPrepass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "DepthPrepass beginFrame()" << std::endl;
co_return;
//co_return;
}
MainJob DepthPrepass::render()
void DepthPrepass::render()
{
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
graphics->beginRenderPass(renderPass);
List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList)
{
//jobs.add(
co_await processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
}
//co_await Job::all(jobs);
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
//std::cout << "DepthPrepass render()" << std::endl;
co_return;
//co_return;
}
MainJob DepthPrepass::endFrame()
void DepthPrepass::endFrame()
{
//std::cout << "DepthPrepass endFrame()" << std::endl;
co_return;
//co_return;
}
void DepthPrepass::publishOutputs()
@@ -11,7 +11,7 @@ public:
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
virtual ~DepthPrepassMeshProcessor();
virtual MainJob processMeshBatch(
virtual void processMeshBatch(
const MeshBatch& batch,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
@@ -34,9 +34,9 @@ class DepthPrepass : public RenderPass<DepthPrepassData>
public:
DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
~DepthPrepass();
virtual MainJob beginFrame() override;
virtual MainJob render() override;
virtual MainJob endFrame() override;
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);
@@ -18,7 +18,7 @@ LightCullingPass::~LightCullingPass()
}
MainJob LightCullingPass::beginFrame()
void LightCullingPass::beginFrame()
{
uint32_t viewportWidth = viewport->getSizeX();
uint32_t viewportHeight = viewport->getSizeY();
@@ -61,13 +61,13 @@ MainJob LightCullingPass::beginFrame()
cullingDescriptorSet->updateBuffer(0, viewParamsBuffer);
cullingDescriptorSet->updateBuffer(1, dispatchParamsBuffer);
cullingDescriptorSet->updateBuffer(3, frustumBuffer);
cullingDescriptorSet->updateBuffer(4, oLightIndexCounter);
cullingDescriptorSet->updateBuffer(5, tLightIndexCounter);
cullingDescriptorSet->updateBuffer(6, oLightIndexList);
cullingDescriptorSet->updateBuffer(7, tLightIndexList);
cullingDescriptorSet->updateTexture(8, oLightGrid);
cullingDescriptorSet->updateTexture(9, tLightGrid);
cullingDescriptorSet->updateBuffer(3, oLightIndexCounter);
cullingDescriptorSet->updateBuffer(4, tLightIndexCounter);
cullingDescriptorSet->updateBuffer(5, oLightIndexList);
cullingDescriptorSet->updateBuffer(6, tLightIndexList);
cullingDescriptorSet->updateTexture(7, oLightGrid);
cullingDescriptorSet->updateTexture(8, tLightGrid);
cullingDescriptorSet->updateBuffer(9, frustumBuffer);
lightEnvDescriptorSet->updateBuffer(0, directLightBuffer);
@@ -76,10 +76,10 @@ MainJob LightCullingPass::beginFrame()
lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer);
lightEnvDescriptorSet->writeChanges();
//std::cout << "LightCulling beginFrame()" << std::endl;
co_return;
//co_return;
}
MainJob LightCullingPass::render()
void LightCullingPass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
@@ -104,13 +104,13 @@ MainJob LightCullingPass::render()
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS);
//std::cout << "LightCulling render()" << std::endl;
co_return;
//co_return;
}
MainJob LightCullingPass::endFrame()
void LightCullingPass::endFrame()
{
//std::cout << "LightCulling endFrame()" << std::endl;
co_return;
//co_return;
}
void LightCullingPass::publishOutputs()
@@ -122,65 +122,6 @@ void LightCullingPass::publishOutputs()
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParams.numThreads = numThreadGroups * glm::uvec3(BLOCK_SIZE, BLOCK_SIZE, 1);
BulkResourceData resourceData;
StructuredBufferCreateInfo structInfo;
uint32 counterReset = 0;
resourceData.size = sizeof(uint32);
resourceData.data = (uint8*)&counterReset;
resourceData.owner = Gfx::QueueType::COMPUTE;
structInfo.bDynamic = true;
structInfo.resourceData = resourceData;
oLightIndexCounter = graphics->createStructuredBuffer(structInfo);
tLightIndexCounter = graphics->createStructuredBuffer(structInfo);
resourceData.data = nullptr;
resourceData.size = sizeof(uint32_t)
* dispatchParams.numThreadGroups.x
* dispatchParams.numThreadGroups.y
* dispatchParams.numThreadGroups.z * 200;
structInfo.resourceData = resourceData;
structInfo.bDynamic = false;
oLightIndexList = graphics->createStructuredBuffer(structInfo);
tLightIndexList = graphics->createStructuredBuffer(structInfo);
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
resourceData.size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS;
structInfo.resourceData = resourceData;
structInfo.bDynamic = true;
directLightBuffer = graphics->createStructuredBuffer(structInfo);
resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS;
structInfo.resourceData = resourceData;
pointLightBuffer = graphics->createStructuredBuffer(structInfo);
UniformBufferCreateInfo uniformInfo;
resourceData.size = sizeof(uint32);
uniformInfo.resourceData = resourceData;
uniformInfo.bDynamic = true;
numDirLightBuffer = graphics->createUniformBuffer(uniformInfo);
uniformInfo.resourceData = resourceData;
uniformInfo.bDynamic = true;
numPointLightBuffer = graphics->createUniformBuffer(uniformInfo);
resources->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer);
resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer);
resources->registerBufferOutput("POINT_LIGHTS", pointLightBuffer);
resources->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer);
TextureCreateInfo textureInfo;
textureInfo.width = dispatchParams.numThreadGroups.x;
textureInfo.height = dispatchParams.numThreadGroups.y;
textureInfo.format = Gfx::SE_FORMAT_R32G32_UINT;
textureInfo.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT;
oLightGrid = graphics->createTexture2D(textureInfo);
tLightGrid = graphics->createTexture2D(textureInfo);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid);
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid);
}
void LightCullingPass::createRenderPass()
{
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
//ViewParams
@@ -189,28 +130,28 @@ void LightCullingPass::createRenderPass()
cullingDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
//DepthTexture
cullingDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
//Frustums
cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
//t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(9, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
//Frustums
cullingDescriptorLayout->addDescriptorBinding(9, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, viewportWidth * viewportHeight);
lightEnvDescriptorLayout = graphics->createDescriptorLayout("LightEnv");
// Directional Lights
lightEnvDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
lightEnvDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_DIRECTIONAL_LIGHTS);
lightEnvDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
// Point Lights
lightEnvDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
lightEnvDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_POINT_LIGHTS);
lightEnvDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
cullingLayout = graphics->createPipelineLayout();
@@ -238,7 +179,80 @@ void LightCullingPass::createRenderPass()
pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = cullingLayout;
cullingPipeline = graphics->createComputePipeline(pipelineInfo);
uint32 counterReset = 0;
StructuredBufferCreateInfo structInfo =
{
.resourceData = {
.size = sizeof(uint32),
.data = (uint8*)&counterReset,
.owner = Gfx::QueueType::COMPUTE,
},
.stride = sizeof(uint32),
.bDynamic = true,
};
oLightIndexCounter = graphics->createStructuredBuffer(structInfo);
tLightIndexCounter = graphics->createStructuredBuffer(structInfo);
structInfo = {
.resourceData = {
.size = (uint32)sizeof(uint32)
* dispatchParams.numThreadGroups.x
* dispatchParams.numThreadGroups.y
* dispatchParams.numThreadGroups.z * 200,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE
},
.stride = sizeof(uint32),
.bDynamic = false,
};
oLightIndexList = graphics->createStructuredBuffer(structInfo);
tLightIndexList = graphics->createStructuredBuffer(structInfo);
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
structInfo = {
.resourceData = {
.size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
.data = nullptr,
},
.stride = sizeof(DirectionalLight),
.bDynamic = true,
};
directLightBuffer = graphics->createStructuredBuffer(structInfo);
structInfo.resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS;
pointLightBuffer = graphics->createStructuredBuffer(structInfo);
UniformBufferCreateInfo uniformInfo = {
.resourceData = {
.size = sizeof(uint32),
.data = nullptr
},
.bDynamic = true
};
numDirLightBuffer = graphics->createUniformBuffer(uniformInfo);
numPointLightBuffer = graphics->createUniformBuffer(uniformInfo);
resources->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer);
resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer);
resources->registerBufferOutput("POINT_LIGHTS", pointLightBuffer);
resources->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer);
TextureCreateInfo textureInfo = {
.width = dispatchParams.numThreadGroups.x,
.height = dispatchParams.numThreadGroups.y,
.format = Gfx::SE_FORMAT_R32G32_UINT,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
};
oLightGrid = graphics->createTexture2D(textureInfo);
tLightGrid = graphics->createTexture2D(textureInfo);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid);
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid);
}
void LightCullingPass::createRenderPass()
{
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture();
}
@@ -254,11 +268,13 @@ void LightCullingPass::setupFrustums()
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));
viewParams.viewMatrix = source->getViewMatrix();
viewParams.projectionMatrix = source->getProjectionMatrix();
viewParams.inverseProjectionMatrix = glm::inverse(source->getProjectionMatrix());
viewParams.screenDimensions = glm::vec2(viewportWidth, viewportHeight);
viewParams.cameraPosition = Vector4(source->getCameraPosition(), 0);
viewParams = {
.viewMatrix = source->getViewMatrix(),
.projectionMatrix = source->getProjectionMatrix(),
.inverseProjectionMatrix = glm::inverse(source->getProjectionMatrix()),
.cameraPosition = Vector4(source->getCameraPosition(), 0),
.screenDimensions = glm::vec2(viewportWidth, viewportHeight),
};
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
@@ -283,7 +299,6 @@ void LightCullingPass::setupFrustums()
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
frustumShader = graphics->createComputeShader(createInfo);
ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader;
pipelineInfo.pipelineLayout = frustumLayout;
@@ -304,11 +319,14 @@ void LightCullingPass::setupFrustums()
uniformInfo.bDynamic = false;
dispatchParamsBuffer = graphics->createUniformBuffer(uniformInfo);
StructuredBufferCreateInfo structuredInfo;
resourceInfo.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z;
resourceInfo.data = nullptr;
structuredInfo.resourceData = resourceInfo;
structuredInfo.bDynamic = false;
StructuredBufferCreateInfo structuredInfo = {
.resourceData = {
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr,
},
.stride = sizeof(Frustum),
.bDynamic = false,
};
frustumBuffer = graphics->createStructuredBuffer(structuredInfo);
frustumDescriptorSet = frustumDescriptorLayout->allocateDescriptorSet();
@@ -18,9 +18,9 @@ class LightCullingPass : public RenderPass<LightCullingPassData>
public:
LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera);
virtual ~LightCullingPass();
virtual MainJob beginFrame() override;
virtual MainJob render() override;
virtual MainJob endFrame() override;
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);
@@ -3,7 +3,6 @@
#include "Scene/Scene.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/MeshBatch.h"
#include "ThreadPool.h"
namespace Seele
{
@@ -17,7 +16,7 @@ public:
protected:
PScene scene;
Gfx::PGraphics graphics;
virtual MainJob processMeshBatch(
virtual void processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass,
+3 -4
View File
@@ -2,7 +2,6 @@
#include "MinimalEngine.h"
#include "Math/Math.h"
#include "RenderGraph.h"
#include "ThreadPool.h"
namespace Seele
{
@@ -22,9 +21,9 @@ public:
void updateViewFrame(RenderPassDataType viewFrame) {
passData = std::move(viewFrame);
}
virtual MainJob beginFrame() = 0;
virtual MainJob render() = 0;
virtual MainJob endFrame() = 0;
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
virtual void publishOutputs() = 0;
virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources resources) { this->resources = resources; }
+58 -32
View File
@@ -16,7 +16,7 @@ TextPass::~TextPass()
}
MainJob TextPass::beginFrame()
void TextPass::beginFrame()
{
for(TextRender& render : passData.texts)
{
@@ -37,25 +37,18 @@ MainJob TextPass::beginFrame()
vbInfo.numVertices = static_cast<uint32>(instanceData.size());
vbInfo.vertexSize = sizeof(GlyphInstanceData);
vbInfo.resourceData.data = reinterpret_cast<uint8*>(instanceData.data());
vbInfo.resourceData.size = static_cast<uint32>(instanceData.size());
vbInfo.resourceData.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData));
resources.vertexBuffer = graphics->createVertexBuffer(vbInfo);
resources.descriptorSet = descriptorLayout->allocateDescriptorSet();
resources.descriptorSet->updateBuffer(0, projectionBuffer);
resources.descriptorSet->updateSampler(1, glyphSampler);
resources.descriptorSet->updateBuffer(2, fontData.structuredBuffer);
resources.descriptorSet->writeChanges();
resources.glyphDataSet = fontData.glyphDataSet;
resources.textureArraySet = fontData.textureArraySet;
resources.textureArraySet = descriptorLayout->allocateDescriptorSet();
resources.textureArraySet->updateTextureArray(0, fontData.textures);
resources.textureArraySet->writeChanges();
resources.scale = render.scale;
}
co_return;
//co_return;
}
MainJob TextPass::render()
void TextPass::render()
{
graphics->beginRenderPass(renderPass);
Array<Gfx::PRenderCommand> commands;
@@ -64,7 +57,7 @@ MainJob TextPass::render()
Gfx::PRenderCommand command = graphics->createRenderCommand("TextPassCommand");
command->setViewport(viewport);
command->bindPipeline(pipeline);
command->bindDescriptor({generalSet, resources.glyphDataSet, resources.textureArraySet});
command->bindVertexBuffer({VertexInputStream(0, 0, resources.vertexBuffer)});
command->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &resources.scale);
@@ -73,12 +66,13 @@ MainJob TextPass::render()
}
graphics->executeCommands(commands);
graphics->endRenderPass();
co_return;
textResources.clear();
//co_return;
}
MainJob TextPass::endFrame()
void TextPass::endFrame()
{
co_return;
//co_return;
}
void TextPass::publishOutputs()
@@ -123,16 +117,20 @@ void TextPass::createRenderPass()
});
declaration = graphics->createVertexDeclaration(elements);
descriptorLayout = graphics->createDescriptorLayout("TextDescriptor");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, 128, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
descriptorLayout->create();
generalLayout = graphics->createDescriptorLayout("TextGeneral");
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
generalLayout->create();
glyphDataLayout = graphics->createDescriptorLayout("TextGlyphData");
glyphDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
glyphDataLayout->create();
textureArrayLayout = graphics->createDescriptorLayout("TextureArray");
textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray");
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 128, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
textureArrayLayout->create();
Matrix4 projectionMatrix = glm::ortho(0.f, (float)viewport->getSizeX(), 0.f, (float)viewport->getSizeY());
projectionBuffer = graphics->createUniformBuffer({
.resourceData = {
@@ -146,12 +144,18 @@ void TextPass::createRenderPass()
.magFilter = Gfx::SE_FILTER_LINEAR,
.minFilter = Gfx::SE_FILTER_LINEAR,
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
});
generalSet = generalLayout->allocateDescriptorSet();
generalSet->updateBuffer(0, projectionBuffer);
generalSet->updateSampler(1, glyphSampler);
generalSet->writeChanges();
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->addDescriptorLayout(1, textureArrayLayout);
pipelineLayout->addDescriptorLayout(0, generalLayout);
pipelineLayout->addDescriptorLayout(1, glyphDataLayout);
pipelineLayout->addDescriptorLayout(2, textureArrayLayout);
pipelineLayout->addPushConstants({
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
@@ -168,6 +172,15 @@ void TextPass::createRenderPass()
pipelineInfo.renderPass = renderPass;
pipelineInfo.pipelineLayout = pipelineLayout;
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.colorBlend.attachmentCount = 1;
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
pipelineInfo.colorBlend.blendAttachments[0].colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT | Gfx::SE_COLOR_COMPONENT_A_BIT;
pipelineInfo.colorBlend.blendAttachments[0].srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
pipelineInfo.colorBlend.blendAttachments[0].srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ZERO;
pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipeline = graphics->createGraphicsPipeline(pipelineInfo);
@@ -181,20 +194,33 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font)
const Map<uint32, FontAsset::Glyph>& fontGlyphs = font->getGlyphData();
FontData& fd = fontData[font];
Array<GlyphData> buffer;
Array<Gfx::PTexture> textures;
buffer.reserve(fontGlyphs.size());
for(const auto& [key, value] : fontGlyphs)
{
fd.characterToGlyphIndex[key] = static_cast<uint32>(buffer.size());
fd.characterAdvance[key] = value.advance;
fd.textures.add(value.texture);
GlyphData& gd = buffer.add();
gd.bearing = value.bearing;
gd.size = value.size;
textures.add(value.texture);
}
StructuredBufferCreateInfo bufferInfo;
bufferInfo.bDynamic = false;
bufferInfo.resourceData.data = reinterpret_cast<uint8*>(buffer.data());
bufferInfo.resourceData.size = static_cast<uint32>(buffer.size());
fd.structuredBuffer = graphics->createStructuredBuffer(bufferInfo);
StructuredBufferCreateInfo bufferInfo = {
.resourceData = {
.size = static_cast<uint32>(buffer.size() * sizeof(GlyphData)),
.data = reinterpret_cast<uint8*>(buffer.data()),
},
.stride = sizeof(GlyphData),
.bDynamic = false,
};
Gfx::PStructuredBuffer glyphBuffer = graphics->createStructuredBuffer(bufferInfo);
fd.glyphDataSet = glyphDataLayout->allocateDescriptorSet();
fd.glyphDataSet->updateBuffer(0, glyphBuffer);
fd.glyphDataSet->writeChanges();
fd.textureArraySet = textureArrayLayout->allocateDescriptorSet();
fd.textureArraySet->updateTextureArray(0, textures);
fd.textureArraySet->writeChanges();
return fontData[font];
}
+11 -8
View File
@@ -27,9 +27,9 @@ class TextPass : public RenderPass<TextPassData>
public:
TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
virtual ~TextPass();
virtual MainJob beginFrame() override;
virtual MainJob render() override;
virtual MainJob endFrame() override;
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
@@ -45,8 +45,8 @@ private:
};
struct FontData
{
Gfx::PStructuredBuffer structuredBuffer;
Array<Gfx::PTexture> textures;
Gfx::PDescriptorSet glyphDataSet;
Gfx::PDescriptorSet textureArraySet;
Map<uint32, uint32> characterToGlyphIndex;
// Logically this should be part of GlyphData,
// but because GlyphData mirrors shader data and we need
@@ -58,9 +58,9 @@ private:
struct TextResources
{
Gfx::PDescriptorSet descriptorSet;
Gfx::PDescriptorSet textureArraySet;
Gfx::PVertexBuffer vertexBuffer;
Gfx::PDescriptorSet glyphDataSet;
Gfx::PDescriptorSet textureArraySet;
float scale;
};
Array<TextResources> textResources;
@@ -69,9 +69,12 @@ private:
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer;
Gfx::PDescriptorLayout descriptorLayout;
Gfx::PDescriptorLayout generalLayout;
Gfx::PDescriptorLayout glyphDataLayout;
Gfx::PDescriptorLayout textureArrayLayout;
Gfx::PDescriptorSet generalSet;
Gfx::PUniformBuffer projectionBuffer;
Gfx::PSamplerState glyphSampler;
+6 -6
View File
@@ -15,12 +15,12 @@ UIPass::~UIPass()
}
MainJob UIPass::beginFrame()
void UIPass::beginFrame()
{
co_return;
//co_return;
}
MainJob UIPass::render()
void UIPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
@@ -29,12 +29,12 @@ MainJob UIPass::render()
command->draw(4, 1, 0, 0);
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
graphics->endRenderPass();
co_return;
//co_return;
}
MainJob UIPass::endFrame()
void UIPass::endFrame()
{
co_return;
//co_return;
}
void UIPass::publishOutputs()
+3 -3
View File
@@ -16,9 +16,9 @@ class UIPass : public RenderPass<UIPassData>
public:
UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
virtual ~UIPass();
virtual MainJob beginFrame() override;
virtual MainJob render() override;
virtual MainJob endFrame() override;
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private: