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
+1 -1
View File
@@ -1,6 +1,6 @@
#include "GraphicsEnums.h"
using namespace Gfx;
using namespace Seele;
uint32 Gfx::currentFrameIndex = 0;
double Gfx::currentFrameDelta = 0;
+1 -1
View File
@@ -1,8 +1,8 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
enum class KeyCode
{
/* Printable keys */
+4 -3
View File
@@ -23,7 +23,7 @@ struct GraphicsInitializer
: applicationName("SeeleEngine")
, engineName("SeeleEngine")
, windowLayoutFile(nullptr)
, layers{}
, layers{"VK_LAYER_KHRONOS_validation"}
, instanceExtensions{}
, deviceExtensions{"VK_KHR_swapchain"}
, windowHandle(nullptr)
@@ -101,12 +101,13 @@ struct IndexBufferCreateInfo
struct UniformBufferCreateInfo
{
BulkResourceData resourceData = BulkResourceData();
uint8 bDynamic : 1 = 0;
uint8 bDynamic = 0;
};
struct StructuredBufferCreateInfo
{
BulkResourceData resourceData;
uint8 bDynamic: 1;
uint32 stride;
uint8 bDynamic = 0;
};
struct ShaderCreateInfo
{
+3 -7
View File
@@ -194,9 +194,10 @@ bool UniformBuffer::updateContents(const BulkResourceData& resourceData)
return true;
}
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData)
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& resourceData)
: Buffer(mapping, resourceData.owner)
, contents(resourceData.size)
, stride(stride)
{
}
StructuredBuffer::~StructuredBuffer()
@@ -366,12 +367,7 @@ RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> inputAttac
}
Window::Window(const WindowCreateInfo &createInfo)
: sizeX(createInfo.width)
, sizeY(createInfo.height)
, bFullscreen(createInfo.bFullscreen)
, title(createInfo.title)
, pixelFormat(createInfo.pixelFormat)
, samples(createInfo.numSamples)
: windowState(createInfo)
{
}
+15 -14
View File
@@ -387,11 +387,11 @@ class IndexBuffer : public Buffer
public:
IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexType index, QueueType startQueueType);
virtual ~IndexBuffer();
inline uint32 getNumIndices() const
constexpr uint32 getNumIndices() const
{
return numIndices;
}
inline Gfx::SeIndexType getIndexType() const
constexpr Gfx::SeIndexType getIndexType() const
{
return indexType;
}
@@ -409,7 +409,7 @@ DEFINE_REF(IndexBuffer)
class StructuredBuffer : public Buffer
{
public:
StructuredBuffer(QueueFamilyMapping mapping, const BulkResourceData& bulkResourceData);
StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& bulkResourceData);
virtual ~StructuredBuffer();
virtual bool updateContents(const BulkResourceData& resourceData);
bool isDataEquals(StructuredBuffer* other)
@@ -428,12 +428,18 @@ public:
}
return true;
}
constexpr uint32 getStride() const
{
return stride;
}
protected:
Array<uint8> contents;
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage,
SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
Array<uint8> contents;
uint32 stride;
};
DEFINE_REF(StructuredBuffer)
@@ -590,28 +596,23 @@ public:
virtual void setCloseCallback(std::function<void()> callback) = 0;
SeFormat getSwapchainFormat() const
{
return pixelFormat;
return windowState.pixelFormat;
}
SeSampleCountFlags getNumSamples() const
{
return samples;
return windowState.numSamples;
}
uint32 getSizeX() const
{
return sizeX;
return windowState.width;
}
uint32 getSizeY() const
{
return sizeY;
return windowState.height;
}
protected:
uint32 sizeX;
uint32 sizeY;
bool bFullscreen;
const char *title;
SeFormat pixelFormat;
uint32 samples;
WindowCreateInfo windowState;
};
DEFINE_REF(Window)
+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:
+10 -12
View File
@@ -90,10 +90,9 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
return nullptr;
}
}
for (auto it : freeRanges)
for (auto& [allocatedOffset, freeAllocation] : freeRanges)
{
PSubAllocation freeAllocation = it.value;
VkDeviceSize allocatedOffset = freeAllocation->allocatedOffset;
assert(allocatedOffset == freeAllocation->allocatedOffset);
VkDeviceSize alignedOffset = align(allocatedOffset, alignment);
VkDeviceSize alignmentAdjustment = alignedOffset - allocatedOffset;
VkDeviceSize size = alignmentAdjustment + requestedSize;
@@ -112,8 +111,8 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
freeAllocation->alignedOffset += size;
PSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, size, alignedOffset, size);
activeAllocations[allocatedOffset] = subAlloc.getHandle();
freeRanges.erase(allocatedOffset);
freeRanges[freeAllocation->allocatedOffset] = freeAllocation;
freeRanges.erase(allocatedOffset);
bytesUsed += size;
return subAlloc;
}
@@ -136,9 +135,8 @@ void Allocation::markFree(SubAllocation *allocation)
{
std::scoped_lock lck(lock);
//Join lower bound
for (auto freeRange : freeRanges)
for (auto& [allocatedOffset, freeAlloc] : freeRanges)
{
PSubAllocation freeAlloc = freeRange.value;
if (freeAlloc->allocatedOffset <= lowerBound
&& freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound)
{
@@ -157,24 +155,24 @@ void Allocation::markFree(SubAllocation *allocation)
auto foundAlloc = freeRanges.find(upperBound);
if (foundAlloc != freeRanges.end())
{
freeRangeToDelete = foundAlloc->value;
freeRangeToDelete = foundAlloc->second;
// There is a free allocation ending where the new free one ends
if (allocHandle != nullptr)
{
// extend allocHandle by another foundAlloc->allocatedSize bytes
allocHandle->allocatedSize += foundAlloc->value->allocatedSize;
freeRanges.erase(foundAlloc->key);
allocHandle->allocatedSize += foundAlloc->second->allocatedSize;
freeRanges.erase(foundAlloc->first);
}
else
{
// set foundAlloc back by size amount
allocHandle = foundAlloc->value;
allocHandle = foundAlloc->second;
allocHandle->allocatedOffset -= allocation->allocatedSize;
allocHandle->alignedOffset -= allocation->allocatedSize;
// place back at correct offset
freeRanges[allocHandle->allocatedOffset] = allocHandle;
// remove from offset map since key changes
freeRanges.erase(foundAlloc->key);
freeRanges.erase(foundAlloc->first);
}
}
@@ -259,7 +257,7 @@ void Allocator::free(Allocation *allocation)
{
if (heap.allocations[i] == allocation)
{
heap.allocations.remove(i, false);
heap.allocations.removeAt(i, false);
return;
}
}
+2 -2
View File
@@ -99,8 +99,8 @@ private:
VkDeviceSize bytesAllocated;
VkDeviceSize bytesUsed;
VkDeviceMemory allocatedMemory;
Map<VkDeviceSize, SubAllocation *> activeAllocations;
Map<VkDeviceSize, PSubAllocation> freeRanges;
std::map<VkDeviceSize, SubAllocation *> activeAllocations;
std::map<VkDeviceSize, PSubAllocation> freeRanges;
std::mutex lock;
void *mappedPointer;
uint8 isDedicated : 1;
+3 -4
View File
@@ -3,7 +3,6 @@
#include "VulkanGraphics.h"
#include "VulkanCommandBuffer.h"
#include "VulkanAllocator.h"
#include "ThreadPool.h"
using namespace Seele;
using namespace Seele::Vulkan;
@@ -65,11 +64,11 @@ ShaderBuffer::~ShaderBuffer()
{
PCmdBuffer cmdBuffer = graphics->getQueueCommands(owner)->getCommands();
VkDevice device = graphics->getDevice();
auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> Job
auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> void
{
//co_await cmdBuffer->asyncWait();
//vkDestroyBuffer(device, buffer, nullptr);
co_return;
//co_return;
};
for (uint32 i = 0; i < numBuffers; ++i)
{
@@ -355,7 +354,7 @@ VkAccessFlags UniformBuffer::getDestAccessMask()
}
StructuredBuffer::StructuredBuffer(PGraphics graphics, const StructuredBufferCreateInfo &resourceData)
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.resourceData)
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.stride, resourceData.resourceData)
, Vulkan::ShaderBuffer(graphics, resourceData.resourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, resourceData.bDynamic)
{
if (resourceData.resourceData.data != nullptr)
@@ -250,6 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{
assert(threadId == std::this_thread::get_id());
auto descriptor = descriptorSet.cast<DescriptorSet>();
assert(descriptor->writeDescriptors.size() == 0);
boundDescriptors.add(descriptor.getHandle());
descriptor->bind();
@@ -263,6 +264,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
for(uint32 i = 0; i < descriptorSets.size(); ++i)
{
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind();
boundDescriptors.add(descriptorSet.getHandle());
@@ -370,6 +372,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{
assert(threadId == std::this_thread::get_id());
auto descriptor = descriptorSet.cast<DescriptorSet>();
assert(descriptor->writeDescriptors.size() == 0);
boundDescriptors.add(descriptor.getHandle());
descriptor->bind();
@@ -384,9 +387,11 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
for(uint32 i = 0; i < descriptorSets.size(); ++i)
{
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
boundDescriptors.add(descriptorSet.getHandle());
assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind();
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
boundDescriptors.add(descriptorSet.getHandle());
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
}
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr);
@@ -139,9 +139,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
cachedData[binding] = new UniformBuffer(*vulkanBuffer.getHandle());
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer structuredBuffer)
{
PStructuredBuffer vulkanBuffer = uniformBuffer.cast<StructuredBuffer>();
PStructuredBuffer vulkanBuffer = structuredBuffer.cast<StructuredBuffer>();
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[binding]);
if(vulkanBuffer.getHandle() == cachedBuffer)
{
@@ -330,7 +330,7 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
uint32 counts = 0;
for(const auto& binding : layout.bindings)
{
if(binding.binding & Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)
if(binding.descriptorCount > 0)
{
counts = binding.descriptorCount;
}
@@ -119,6 +119,8 @@ private:
bool currentlyInUse;
friend class DescriptorAllocator;
friend class CmdBuffer;
friend class RenderCommand;
friend class ComputeCommand;
};
DEFINE_REF(DescriptorSet)
@@ -12,6 +12,7 @@
#include "Graphics/GraphicsResources.h"
#include <GLFW/glfw3.h>
using namespace Seele;
using namespace Seele::Vulkan;
thread_local PCommandBufferManager Seele::Vulkan::Graphics::graphicsCommands = nullptr;
@@ -570,7 +571,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV;
deviceInfo.pNext = &crashDiagInfo;
descriptorIndexing.pNext = &crashDiagInfo;
#endif
deviceInfo.enabledExtensionCount = (uint32)initializer.deviceExtensions.size();
deviceInfo.ppEnabledExtensionNames = initializer.deviceExtensions.data();
@@ -1,5 +1,6 @@
#include "VulkanGraphicsEnums.h"
using namespace Seele;
using namespace Seele::Vulkan;
using namespace Seele::Gfx;
@@ -23,7 +23,7 @@ Semaphore::~Semaphore()
Fence::Fence(PGraphics graphics)
: graphics(graphics)
, signaled("Fence")
, signaled(false)
{
VkFenceCreateInfo info =
init::FenceCreateInfo(0);
@@ -45,8 +45,8 @@ bool Fence::isSignaled()
switch (res)
{
case VK_SUCCESS:
signaled.raise();
return true;
signaled = true;
return signaled;
case VK_NOT_READY:
break;
default:
@@ -60,7 +60,7 @@ void Fence::reset()
if (signaled)
{
vkResetFences(graphics->getDevice(), 1, &fence);
signaled.reset();
signaled = false;
}
}
@@ -71,7 +71,7 @@ void Fence::wait(uint32 timeout)
switch (r)
{
case VK_SUCCESS:
signaled.raise();
signaled = true;
break;
case VK_TIMEOUT:
break;
@@ -3,7 +3,6 @@
#include <functional>
#include "Graphics/GraphicsResources.h"
#include "VulkanAllocator.h"
#include "ThreadPool.h"
namespace Seele
{
@@ -43,10 +42,10 @@ public:
return fence;
}
void wait(uint32 timeout);
Event& operator co_await()
/*Event& operator co_await()
{
return signaled;
}
}*/
bool operator<(const Fence &other) const
{
return fence < other.fence;
@@ -54,7 +53,7 @@ public:
private:
PGraphics graphics;
Event signaled;
bool signaled;
VkFence fence;
};
DEFINE_REF(Fence)
@@ -357,6 +356,11 @@ public:
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
virtual void setCloseCallback(std::function<void()> callback);
VkFormat getPixelFormat() const
{
return cast(windowState.pixelFormat);
}
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
std::function<void(double, double)> mouseMoveCallback;
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
@@ -381,7 +385,6 @@ protected:
VkInstance instance;
VkSwapchainKHR swapchain;
VkSampleCountFlags numSamples;
VkFormat pixelFormat;
VkPresentModeKHR presentMode;
VkSurfaceKHR surface;
VkSurfaceFormatKHR surfaceFormat;
+11 -12
View File
@@ -4,7 +4,6 @@
#include "VulkanGraphicsEnums.h"
#include "VulkanAllocator.h"
#include "VulkanCommandBuffer.h"
#include "ThreadPool.h"
#include <math.h>
using namespace Seele;
@@ -162,21 +161,21 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
TextureHandle::~TextureHandle()
{
auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
VkDevice device = graphics->getDevice();
VkImageView view = defaultView;
VkImage img = image;
auto deletionLambda = [cmdBuffer, device, view, img]() -> Job
{
//vkDestroyImageView(device, view, nullptr);
//vkDestroyImage(device, img, nullptr);
co_return;
};
deletionLambda();
//auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
//VkDevice device = graphics->getDevice();
//VkImageView view = defaultView;
//VkImage img = image;
//vkDestroyImageView(device, view, nullptr);
//vkDestroyImage(device, img, nullptr);
//co_return;
}
TextureHandle* TextureBase::cast(Gfx::PTexture texture)
{
if(texture == nullptr)
{
return nullptr;
}
if(texture->getTexture2D() != nullptr)
{
PTexture2D texture2D = texture.cast<Texture2D>();
+9 -10
View File
@@ -50,7 +50,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
, instance(graphics->getInstance())
, swapchain(VK_NULL_HANDLE)
, numSamples(createInfo.numSamples)
, pixelFormat(cast(createInfo.pixelFormat))
{
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
@@ -194,11 +193,7 @@ void Window::advanceBackBuffer()
void Window::recreateSwapchain(const WindowCreateInfo &windowInfo)
{
destroySwapchain();
sizeX = windowInfo.width;
sizeY = windowInfo.height;
pixelFormat = cast(windowInfo.pixelFormat);
bFullscreen = windowInfo.bFullscreen;
windowState = windowInfo;
uint32_t numFormats;
VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, nullptr));
Array<VkSurfaceFormatKHR> formats(numFormats);
@@ -234,6 +229,10 @@ void Window::present()
while (presentResult != VK_SUCCESS)
{
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
if(presentResult == VK_ERROR_OUT_OF_DATE_KHR)
{
recreateSwapchain(windowState);
}
}
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered;
static double lastFrameTime = 0.f;
@@ -259,8 +258,8 @@ void Window::createSwapchain()
}
VkExtent2D extent;
extent.width = sizeX;
extent.height = sizeY;
extent.width = getSizeX();
extent.height = getSizeY();
VkSwapchainCreateInfoKHR swapchainInfo =
init::SwapchainCreateInfo(
surface,
@@ -283,8 +282,8 @@ void Window::createSwapchain()
TextureCreateInfo backBufferCreateInfo;
backBufferCreateInfo.width = sizeX;
backBufferCreateInfo.height = sizeY;
backBufferCreateInfo.width = getSizeX();
backBufferCreateInfo.height = getSizeY();
backBufferCreateInfo.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
backBufferCreateInfo.resourceData.owner = Gfx::QueueType::GRAPHICS;
backBufferCreateInfo.format = cast(surfaceFormat.format);