Changed descriptorset api

This commit is contained in:
2025-08-10 19:16:55 +02:00
parent aa4b78586e
commit 6537459b77
34 changed files with 124 additions and 102 deletions
+4 -4
View File
@@ -203,7 +203,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f), Vector(0.0f, 1.0f, 0.0f)), glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f), Vector(0.0f, 1.0f, 0.0f)),
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, 1.0f), Vector(0.0f, 1.0f, 0.0f)), glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, 1.0f), Vector(0.0f, 1.0f, 0.0f)),
}; };
Gfx::PDescriptorSet set = cubeRenderLayout->allocateDescriptorSet(); Gfx::ODescriptorSet set = cubeRenderLayout->allocateDescriptorSet();
set->updateConstants("view", 0, captureViews); set->updateConstants("view", 0, captureViews);
set->updateConstants("projection", 0, &captureProjection); set->updateConstants("projection", 0, &captureProjection);
set->updateTexture("equirectangularMap", 0, hdrTexture->getDefaultView()); set->updateTexture("equirectangularMap", 0, hdrTexture->getDefaultView());
@@ -262,7 +262,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
graphics->beginRenderPass(cubeRenderPass); graphics->beginRenderPass(cubeRenderPass);
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("CubeMapRender"); Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("CubeMapRender");
renderCommand->bindPipeline(cubeRenderPipeline); renderCommand->bindPipeline(cubeRenderPipeline);
renderCommand->bindDescriptor({set}); renderCommand->bindDescriptor(set);
renderCommand->setViewport(cubeRenderViewport); renderCommand->setViewport(cubeRenderViewport);
renderCommand->draw(6, 1, i * 6, 0); renderCommand->draw(6, 1, i * 6, 0);
graphics->executeCommands(std::move(renderCommand)); graphics->executeCommands(std::move(renderCommand));
@@ -329,7 +329,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
graphics->beginRenderPass(convolutionPass); graphics->beginRenderPass(convolutionPass);
Gfx::ORenderCommand cmd = graphics->createRenderCommand("ConvolutionPass"); Gfx::ORenderCommand cmd = graphics->createRenderCommand("ConvolutionPass");
cmd->bindPipeline(convolutionPipeline); cmd->bindPipeline(convolutionPipeline);
cmd->bindDescriptor({set}); cmd->bindDescriptor(set);
cmd->setViewport(convolutionViewport); cmd->setViewport(convolutionViewport);
cmd->draw(6, 1, i * 6, 0); cmd->draw(6, 1, i * 6, 0);
graphics->executeCommands(std::move(cmd)); graphics->executeCommands(std::move(cmd));
@@ -391,7 +391,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
graphics->beginRenderPass(prefilterPass); graphics->beginRenderPass(prefilterPass);
Gfx::ORenderCommand cmd = graphics->createRenderCommand("PrefilterPass"); Gfx::ORenderCommand cmd = graphics->createRenderCommand("PrefilterPass");
cmd->bindPipeline(prefilterPipeline); cmd->bindPipeline(prefilterPipeline);
cmd->bindDescriptor({set}); cmd->bindDescriptor(set);
float roughness = (float)mip / (float)(prefilteredCubeMap->getMipLevels() - 1); float roughness = (float)mip / (float)(prefilteredCubeMap->getMipLevels() - 1);
cmd->pushConstants(Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(float), &roughness); cmd->pushConstants(Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(float), &roughness);
cmd->setViewport(prefilterViewports[mip]); cmd->setViewport(prefilterViewports[mip]);
+1 -1
View File
@@ -11,7 +11,7 @@ void DescriptorLayout::addDescriptorBinding(DescriptorBinding binding) {
descriptorBindings.add(binding); descriptorBindings.add(binding);
} }
PDescriptorSet DescriptorLayout::allocateDescriptorSet() { return pool->allocateDescriptorSet(); } ODescriptorSet DescriptorLayout::allocateDescriptorSet() { return pool->allocateDescriptorSet(); }
void DescriptorLayout::reset() { pool->reset(); } void DescriptorLayout::reset() { pool->reset(); }
+2 -2
View File
@@ -25,7 +25,7 @@ class DescriptorLayout {
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
void addDescriptorBinding(DescriptorBinding binding); void addDescriptorBinding(DescriptorBinding binding);
void reset(); void reset();
PDescriptorSet allocateDescriptorSet(); ODescriptorSet allocateDescriptorSet();
virtual void create() = 0; virtual void create() = 0;
constexpr uint32 getHash() const { return hash; } constexpr uint32 getHash() const { return hash; }
constexpr const std::string& getName() const { return name; } constexpr const std::string& getName() const { return name; }
@@ -45,7 +45,7 @@ class DescriptorPool {
public: public:
DescriptorPool(); DescriptorPool();
virtual ~DescriptorPool(); virtual ~DescriptorPool();
virtual PDescriptorSet allocateDescriptorSet() = 0; virtual ODescriptorSet allocateDescriptorSet() = 0;
virtual void reset() = 0; virtual void reset() = 0;
}; };
DEFINE_REF(DescriptorPool) DEFINE_REF(DescriptorPool)
+3 -2
View File
@@ -1,6 +1,5 @@
#include "BasePass.h" #include "BasePass.h"
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "Asset/EnvironmentMapAsset.h"
#include "Component/Camera.h" #include "Component/Camera.h"
#include "Graphics/Command.h" #include "Graphics/Command.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
@@ -14,6 +13,9 @@
#include "Math/Vector.h" #include "Math/Vector.h"
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "ShadowPass.h" #include "ShadowPass.h"
#include "Scene/Scene.h"
#include "Asset/EnvironmentMapAsset.h"
#include "Scene/LightEnvironment.h"
using namespace Seele; using namespace Seele;
@@ -481,7 +483,6 @@ void BasePass::publishOutputs() {
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment); resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment);
timestamps = graphics->createTimestampQuery(2, "BaseTS");
query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics"); query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics");
resources->registerQueryOutput("BASEPASS_QUERY", query); resources->registerQueryOutput("BASEPASS_QUERY", query);
} }
+6 -6
View File
@@ -37,9 +37,9 @@ class BasePass : public RenderPass {
constexpr static const char* SHADOWSAMPLER_NAME = "shadowSampler"; constexpr static const char* SHADOWSAMPLER_NAME = "shadowSampler";
constexpr static const char* CASCADE_SPLIT_NAME = "cascadeSplit"; constexpr static const char* CASCADE_SPLIT_NAME = "cascadeSplit";
Gfx::PDescriptorSet opaqueCulling; Gfx::ODescriptorSet opaqueCulling;
Gfx::PDescriptorSet transparentCulling; Gfx::ODescriptorSet transparentCulling;
Gfx::PDescriptorSet shadowMapping; Gfx::ODescriptorSet shadowMapping;
// use a different texture here so we can do multisampling // use a different texture here so we can do multisampling
Gfx::OTexture2D msBasePassDepth; Gfx::OTexture2D msBasePassDepth;
@@ -51,7 +51,7 @@ class BasePass : public RenderPass {
// used for transparency sorting // used for transparency sorting
Vector cameraPos; Vector cameraPos;
Vector cameraForward; Vector cameraForward;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
PCameraActor source; PCameraActor source;
Gfx::OPipelineLayout basePassLayout; Gfx::OPipelineLayout basePassLayout;
@@ -82,9 +82,9 @@ class BasePass : public RenderPass {
// Skybox // Skybox
Gfx::ODescriptorLayout skyboxDataLayout; Gfx::ODescriptorLayout skyboxDataLayout;
Gfx::PDescriptorSet skyboxDataSet; Gfx::ODescriptorSet skyboxDataSet;
Gfx::ODescriptorLayout textureLayout; Gfx::ODescriptorLayout textureLayout;
Gfx::PDescriptorSet textureSet; Gfx::ODescriptorSet textureSet;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout; Gfx::OPipelineLayout pipelineLayout;
@@ -24,7 +24,7 @@ class CachedDepthPass : public RenderPass {
Gfx::OPipelineStatisticsQuery query; Gfx::OPipelineStatisticsQuery query;
Gfx::OTimestampQuery timestamps; Gfx::OTimestampQuery timestamps;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
Gfx::PShaderBuffer cullingBuffer; Gfx::PShaderBuffer cullingBuffer;
PScene scene; PScene scene;
}; };
@@ -72,7 +72,7 @@ void DepthCullingPass::beginFrame(const Component::Camera& cam, const Component:
void DepthCullingPass::render() { void DepthCullingPass::render() {
graphics->beginDebugRegion("DepthCullingPass"); graphics->beginDebugRegion("DepthCullingPass");
Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); Gfx::ODescriptorSet set = depthAttachmentLayout->allocateDescriptorSet();
{ {
graphics->beginDebugRegion("MipGeneration"); graphics->beginDebugRegion("MipGeneration");
query->beginQuery(); query->beginQuery();
@@ -44,7 +44,7 @@ class DepthCullingPass : public RenderPass {
Gfx::PComputePipeline depthSourceCopy; Gfx::PComputePipeline depthSourceCopy;
Gfx::OComputeShader depthReduceLevelShader; Gfx::OComputeShader depthReduceLevelShader;
Gfx::PComputePipeline depthReduceLevel; Gfx::PComputePipeline depthReduceLevel;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
Gfx::PShaderBuffer cullingBuffer; Gfx::PShaderBuffer cullingBuffer;
PScene scene; PScene scene;
@@ -143,7 +143,7 @@ void LightCullingPass::publishOutputs() {
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader; pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = std::move(cullingLayout); pipelineInfo.pipelineLayout = cullingLayout;
cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo)); cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
} }
@@ -167,7 +167,7 @@ void LightCullingPass::publishOutputs() {
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader; pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = std::move(cullingEnableLayout); pipelineInfo.pipelineLayout = cullingEnableLayout;
cullingEnabledPipeline = graphics->createComputePipeline(std::move(pipelineInfo)); cullingEnabledPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
} }
@@ -29,11 +29,11 @@ class LightCullingPass : public RenderPass {
Gfx::OShaderBuffer frustumBuffer; Gfx::OShaderBuffer frustumBuffer;
const char* FRUSTUMBUFFER_NAME = "frustums"; const char* FRUSTUMBUFFER_NAME = "frustums";
Gfx::ODescriptorLayout dispatchParamsLayout; Gfx::ODescriptorLayout dispatchParamsLayout;
Gfx::PDescriptorSet dispatchParamsSet; Gfx::ODescriptorSet dispatchParamsSet;
Gfx::OComputeShader frustumShader; Gfx::OComputeShader frustumShader;
Gfx::PComputePipeline frustumPipeline; Gfx::PComputePipeline frustumPipeline;
Gfx::OPipelineLayout frustumLayout; Gfx::OPipelineLayout frustumLayout;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
PLightEnvironment lightEnv; PLightEnvironment lightEnv;
Gfx::PTextureView depthAttachment; Gfx::PTextureView depthAttachment;
@@ -50,7 +50,7 @@ class LightCullingPass : public RenderPass {
constexpr static const char* OLIGHTGRID_NAME = "oLightGrid"; constexpr static const char* OLIGHTGRID_NAME = "oLightGrid";
Gfx::OTexture2D tLightGrid; Gfx::OTexture2D tLightGrid;
constexpr static const char* TLIGHTGRID_NAME = "tLightGrid"; constexpr static const char* TLIGHTGRID_NAME = "tLightGrid";
Gfx::PDescriptorSet cullingDescriptorSet; Gfx::ODescriptorSet cullingDescriptorSet;
Gfx::ODescriptorLayout cullingDescriptorLayout; Gfx::ODescriptorLayout cullingDescriptorLayout;
Gfx::OPipelineLayout cullingLayout; Gfx::OPipelineLayout cullingLayout;
Gfx::OPipelineLayout cullingEnableLayout; Gfx::OPipelineLayout cullingEnableLayout;
@@ -66,7 +66,8 @@ static uint32 pass = 0;
static Component::Transform lastCam; static Component::Transform lastCam;
void RayTracingPass::beginFrame(const Component::Camera& cam, const Component::Transform& transform) { void RayTracingPass::beginFrame(const Component::Camera& cam, const Component::Transform& transform) {
updateViewParameters(cam, transform); updateViewParameters(cam, transform);
viewParamsSet = createViewParamsSet(); if (lastCam.getPosition() != transform.getPosition() || lastCam.getForward() != transform.getForward()) { viewParamsSet = createViewParamsSet();
if (lastCam.getPosition() != transform.getPosition() || lastCam.getForward() != transform.getForward()) {
lastCam = transform; lastCam = transform;
pass = 0; pass = 0;
} }
@@ -149,7 +150,7 @@ void RayTracingPass::render() {
.instances = instanceData, .instances = instanceData,
.bottomLevelStructures = accelerationStructures, .bottomLevelStructures = accelerationStructures,
}); });
Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet(); Gfx::ODescriptorSet desc = paramsLayout->allocateDescriptorSet();
desc->updateAccelerationStructure(TLAS_NAME, 0, tlas); desc->updateAccelerationStructure(TLAS_NAME, 0, tlas);
desc->updateTexture(ACCUMULATOR_NAME, 0, radianceAccumulator->getDefaultView()); desc->updateTexture(ACCUMULATOR_NAME, 0, radianceAccumulator->getDefaultView());
desc->updateTexture(TEXTURE_NAME, 0, texture->getDefaultView()); desc->updateTexture(TEXTURE_NAME, 0, texture->getDefaultView());
@@ -32,7 +32,7 @@ class RayTracingPass : public RenderPass {
Gfx::OAnyHitShader anyhit; Gfx::OAnyHitShader anyhit;
Gfx::OMissShader miss; Gfx::OMissShader miss;
Gfx::PRayTracingPipeline pipeline; Gfx::PRayTracingPipeline pipeline;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
PScene scene; PScene scene;
}; };
} // namespace Seele } // namespace Seele
+1 -1
View File
@@ -38,7 +38,7 @@ class RenderGraph {
return res; return res;
} }
private: private:
PRenderGraphResources res; ORenderGraphResources res;
List<ORenderPass> passes; List<ORenderPass> passes;
}; };
@@ -49,7 +49,7 @@ void RenderPass::updateViewParameters(const Component::Camera& cam, const Compon
}; };
} }
Gfx::PDescriptorSet RenderPass::createViewParamsSet() Gfx::ODescriptorSet RenderPass::createViewParamsSet()
{ {
// screen space // screen space
//StaticArray<Vector4, 4> corners = { //StaticArray<Vector4, 4> corners = {
@@ -71,8 +71,7 @@ Gfx::PDescriptorSet RenderPass::createViewParamsSet()
// extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum); // extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
viewParamsLayout->reset(); Gfx::ODescriptorSet viewParamsSet = viewParamsLayout->allocateDescriptorSet();
Gfx::PDescriptorSet viewParamsSet = viewParamsLayout->allocateDescriptorSet();
viewParamsSet->updateConstants("viewMatrix", 0, &viewParams.viewMatrix); viewParamsSet->updateConstants("viewMatrix", 0, &viewParams.viewMatrix);
viewParamsSet->updateConstants("inverseViewMatrix", 0, &viewParams.inverseViewMatrix); viewParamsSet->updateConstants("inverseViewMatrix", 0, &viewParams.inverseViewMatrix);
viewParamsSet->updateConstants("projectionMatrix", 0, &viewParams.projectionMatrix); viewParamsSet->updateConstants("projectionMatrix", 0, &viewParams.projectionMatrix);
+1 -1
View File
@@ -28,7 +28,7 @@ class RenderPass {
protected: protected:
void updateViewParameters(const Component::Camera& cam, const Component::Transform& transform); void updateViewParameters(const Component::Camera& cam, const Component::Transform& transform);
Gfx::PDescriptorSet createViewParamsSet(); Gfx::ODescriptorSet createViewParamsSet();
struct Plane { struct Plane {
Vector n; Vector n;
float d; float d;
@@ -62,6 +62,7 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
float uniform = minZ + range * p; float uniform = minZ + range * p;
float d = cascadeSplitLambda * (log - uniform) + uniform; float d = cascadeSplitLambda * (log - uniform) + uniform;
cascadeSplits[i] = (d - nearClip) / clipRange; cascadeSplits[i] = (d - nearClip) / clipRange;
cascades[i].viewParams.clear();
} }
// call this to update view params member, ignore descriptor set // call this to update view params member, ignore descriptor set
@@ -210,7 +211,7 @@ void ShadowPass::render() {
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
command->bindDescriptor( command->bindDescriptor(
{cascades[c].viewParams[c], vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()}); {cascades[c].viewParams[shadowIndex], vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()});
VertexData::DrawCallOffsets offsets = { VertexData::DrawCallOffsets offsets = {
.instanceOffset = 0, .instanceOffset = 0,
}; };
+1 -1
View File
@@ -26,7 +26,7 @@ class ShadowPass : public RenderPass {
Array<Gfx::OTextureView> views; Array<Gfx::OTextureView> views;
Array<Matrix4> lightSpaceMatrices; Array<Matrix4> lightSpaceMatrices;
Gfx::OShaderBuffer lightSpaceBuffer; Gfx::OShaderBuffer lightSpaceBuffer;
Array<Gfx::PDescriptorSet> viewParams; Array<Gfx::ODescriptorSet> viewParams;
}; };
StaticArray<Cascade, NUM_CASCADES> cascades; StaticArray<Cascade, NUM_CASCADES> cascades;
Gfx::OUniformBuffer cascadeSplitsBuffer; Gfx::OUniformBuffer cascadeSplitsBuffer;
@@ -148,7 +148,7 @@ void ToneMappingPass::render() {
{ {
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("HistogramCommand"); Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("HistogramCommand");
computeCommand->bindPipeline(histogramPipeline); computeCommand->bindPipeline(histogramPipeline);
computeCommand->bindDescriptor({histogramSet}); computeCommand->bindDescriptor(histogramSet);
computeCommand->dispatch(threadGroups.x, threadGroups.y, 1); computeCommand->dispatch(threadGroups.x, threadGroups.y, 1);
graphics->executeCommands(std::move(computeCommand)); graphics->executeCommands(std::move(computeCommand));
} }
@@ -158,7 +158,7 @@ void ToneMappingPass::render() {
{ {
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("ExposureCommand"); Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("ExposureCommand");
computeCommand->bindPipeline(exposurePipeline); computeCommand->bindPipeline(exposurePipeline);
computeCommand->bindDescriptor({histogramSet}); computeCommand->bindDescriptor(histogramSet);
computeCommand->dispatch(1, 1, 1); computeCommand->dispatch(1, 1, 1);
graphics->executeCommands(std::move(computeCommand)); graphics->executeCommands(std::move(computeCommand));
} }
@@ -168,7 +168,7 @@ void ToneMappingPass::render() {
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
tonemappingLayout->reset(); tonemappingLayout->reset();
Gfx::PDescriptorSet tonemappingSet = tonemappingLayout->allocateDescriptorSet(); Gfx::ODescriptorSet tonemappingSet = tonemappingLayout->allocateDescriptorSet();
tonemappingSet->updateConstants("offset", 0, &offset); tonemappingSet->updateConstants("offset", 0, &offset);
tonemappingSet->updateConstants("slope", 0, &slope); tonemappingSet->updateConstants("slope", 0, &slope);
tonemappingSet->updateConstants("power", 0, &power); tonemappingSet->updateConstants("power", 0, &power);
@@ -181,7 +181,7 @@ void ToneMappingPass::render() {
Gfx::ORenderCommand command = graphics->createRenderCommand("ToneMapping"); Gfx::ORenderCommand command = graphics->createRenderCommand("ToneMapping");
command->setViewport(viewport); command->setViewport(viewport);
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
command->bindDescriptor({tonemappingSet}); command->bindDescriptor(tonemappingSet);
command->draw(3, 1, 0, 0); command->draw(3, 1, 0, 0);
graphics->executeCommands(std::move(command)); graphics->executeCommands(std::move(command));
graphics->endRenderPass(); graphics->endRenderPass();
@@ -28,7 +28,7 @@ class ToneMappingPass : public RenderPass {
uint32 numPixels; uint32 numPixels;
UVector2 threadGroups; UVector2 threadGroups;
Gfx::ODescriptorLayout histogramLayout; Gfx::ODescriptorLayout histogramLayout;
Gfx::PDescriptorSet histogramSet; Gfx::ODescriptorSet histogramSet;
Gfx::OPipelineLayout histogramPipelineLayout; Gfx::OPipelineLayout histogramPipelineLayout;
Gfx::OComputeShader histogramShader; Gfx::OComputeShader histogramShader;
Gfx::PComputePipeline histogramPipeline; Gfx::PComputePipeline histogramPipeline;
@@ -48,6 +48,6 @@ class ToneMappingPass : public RenderPass {
Gfx::OFragmentShader frag; Gfx::OFragmentShader frag;
Gfx::PGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
}; };
} }
+3 -3
View File
@@ -52,7 +52,7 @@ class UIPass : public RenderPass {
Gfx::OTexture2D depthBuffer; Gfx::OTexture2D depthBuffer;
Gfx::ODescriptorLayout textDescriptorLayout; Gfx::ODescriptorLayout textDescriptorLayout;
Gfx::PDescriptorSet textDescriptorSet; Gfx::ODescriptorSet textDescriptorSet;
Gfx::OVertexShader textVertexShader; Gfx::OVertexShader textVertexShader;
Gfx::OFragmentShader textFragmentShader; Gfx::OFragmentShader textFragmentShader;
@@ -60,9 +60,9 @@ class UIPass : public RenderPass {
Gfx::PGraphicsPipeline textPipeline; Gfx::PGraphicsPipeline textPipeline;
Gfx::ODescriptorLayout uiDescriptorLayout; Gfx::ODescriptorLayout uiDescriptorLayout;
Gfx::PDescriptorSet uiDescriptorSet; Gfx::ODescriptorSet uiDescriptorSet;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
Gfx::OVertexShader uiVertexShader; Gfx::OVertexShader uiVertexShader;
Gfx::OFragmentShader uiFragmentShader; Gfx::OFragmentShader uiFragmentShader;
@@ -19,14 +19,14 @@ class VisibilityPass : public RenderPass {
private: private:
static constexpr uint32 BLOCK_SIZE = 32; static constexpr uint32 BLOCK_SIZE = 32;
Gfx::RenderTargetAttachment visibilityAttachment; Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::PDescriptorSet visibilitySet; Gfx::ODescriptorSet visibilitySet;
Gfx::ODescriptorLayout visibilityDescriptor; Gfx::ODescriptorLayout visibilityDescriptor;
Gfx::OPipelineLayout visibilityLayout; Gfx::OPipelineLayout visibilityLayout;
Gfx::OComputeShader visibilityShader; Gfx::OComputeShader visibilityShader;
Gfx::PComputePipeline visibilityPipeline; Gfx::PComputePipeline visibilityPipeline;
Gfx::OPipelineStatisticsQuery query; Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps; Gfx::PTimestampQuery timestamps;
Gfx::PDescriptorSet viewParamsSet; Gfx::ODescriptorSet viewParamsSet;
constexpr static const char* VISIBILITY_NAME = "visibilityTexture"; constexpr static const char* VISIBILITY_NAME = "visibilityTexture";
// Holds culling information for every meshlet for each instance // Holds culling information for every meshlet for each instance
@@ -18,7 +18,7 @@ class WaterRenderer {
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
PScene scene; PScene scene;
Gfx::ODescriptorLayout computeLayout; Gfx::ODescriptorLayout computeLayout;
Gfx::PDescriptorSet computeSet; Gfx::ODescriptorSet computeSet;
Gfx::OPipelineLayout pipelineLayout; Gfx::OPipelineLayout pipelineLayout;
Gfx::OComputeShader initSpectrumCS; Gfx::OComputeShader initSpectrumCS;
@@ -145,7 +145,7 @@ class WaterRenderer {
Gfx::OMeshShader waterMesh; Gfx::OMeshShader waterMesh;
Gfx::OFragmentShader waterFragment; Gfx::OFragmentShader waterFragment;
Gfx::ODescriptorLayout materialLayout; Gfx::ODescriptorLayout materialLayout;
Gfx::PDescriptorSet materialSet; Gfx::ODescriptorSet materialSet;
Gfx::OPipelineLayout waterLayout; Gfx::OPipelineLayout waterLayout;
Gfx::PGraphicsPipeline waterPipeline; Gfx::PGraphicsPipeline waterPipeline;
+1 -1
View File
@@ -50,6 +50,6 @@ class StaticMeshVertexData : public VertexData {
Array<BiTangentType> bitData; Array<BiTangentType> bitData;
Array<ColorType> colData; Array<ColorType> colData;
Gfx::ODescriptorLayout descriptorLayout; Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet; Gfx::ODescriptorSet descriptorSet;
}; };
} // namespace Seele } // namespace Seele
+1 -1
View File
@@ -158,7 +158,7 @@ class VertexData {
Array<Gfx::PBottomLevelAS> rayTracingScene; Array<Gfx::PBottomLevelAS> rayTracingScene;
Gfx::PDescriptorSet descriptorSet; Gfx::ODescriptorSet descriptorSet;
uint64 idCounter; uint64 idCounter;
uint64 head; uint64 head;
uint64 verticesAllocated; uint64 verticesAllocated;
+12 -12
View File
@@ -256,8 +256,8 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
assert(threadId == std::this_thread::get_id()); assert(threadId == std::this_thread::get_id());
auto descriptorSet = descriptor.cast<DescriptorSet>(); auto descriptorSet = descriptor.cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(descriptorSet); boundResources.add(descriptorSet->setHandle);
for (auto& binding : descriptorSet->boundResources) { for (auto& binding : descriptorSet->boundResources) {
for (auto& res : binding) { for (auto& res : binding) {
// partially bound descriptors can include nulls // partially bound descriptors can include nulls
@@ -268,7 +268,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
} }
} }
if (descriptorSet->constantsBuffer != nullptr) { if (descriptorSet->constantsBuffer != nullptr) {
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer));
} }
@@ -286,8 +286,8 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
for (uint32 i = 0; i < descriptorSets.size(); ++i) { for (uint32 i = 0; i < descriptorSets.size(); ++i) {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(descriptorSet); boundResources.add(descriptorSet->setHandle);
for (auto& binding : descriptorSet->boundResources) { for (auto& binding : descriptorSet->boundResources) {
for (auto& res : binding) { for (auto& res : binding) {
@@ -299,7 +299,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
} }
} }
if (descriptorSet->constantsBuffer != nullptr) { if (descriptorSet->constantsBuffer != nullptr) {
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer));
} }
sets[layout->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); sets[layout->findParameter(descriptorSet->getName())] = descriptorSet->getHandle();
@@ -436,8 +436,8 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
assert(threadId == std::this_thread::get_id()); assert(threadId == std::this_thread::get_id());
auto descriptorSet = descriptor.cast<DescriptorSet>(); auto descriptorSet = descriptor.cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(descriptorSet.getHandle()); boundResources.add(descriptorSet->setHandle);
for (auto& binding : descriptorSet->boundResources) { for (auto& binding : descriptorSet->boundResources) {
for (auto& res : binding) { for (auto& res : binding) {
@@ -449,7 +449,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
} }
} }
if (descriptorSet->constantsBuffer != nullptr) { if (descriptorSet->constantsBuffer != nullptr) {
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer));
} }
@@ -464,8 +464,8 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
for (uint32 i = 0; i < descriptorSets.size(); ++i) { for (uint32 i = 0; i < descriptorSets.size(); ++i) {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(descriptorSet.getHandle()); boundResources.add(descriptorSet->setHandle);
for (auto& binding : descriptorSet->boundResources) { for (auto& binding : descriptorSet->boundResources) {
for (auto& res : binding) { for (auto& res : binding) {
// partially bound descriptors can include nulls // partially bound descriptors can include nulls
@@ -476,7 +476,7 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
} }
} }
if (descriptorSet->constantsBuffer != nullptr) { if (descriptorSet->constantsBuffer != nullptr) {
descriptorSet->bind(); descriptorSet->setHandle->bind();
boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer));
} }
sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle();
+26 -22
View File
@@ -2,17 +2,18 @@
#include "Buffer.h" #include "Buffer.h"
#include "CRC.h" #include "CRC.h"
#include "Command.h" #include "Command.h"
#include "Enums.h"
#include "Graphics.h" #include "Graphics.h"
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Vulkan/Resources.h"
#include "RayTracing.h" #include "RayTracing.h"
#include "Texture.h" #include "Texture.h"
#include "Enums.h"
#include <iostream>
#include "vulkan/vulkan_core.h" #include "vulkan/vulkan_core.h"
#include <algorithm> #include <algorithm>
#include <iostream>
#include <mutex> #include <mutex>
using namespace Seele; using namespace Seele;
@@ -36,7 +37,8 @@ void DescriptorLayout::create() {
if (std::ranges::contains(descriptorBindings, Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK, &Gfx::DescriptorBinding::descriptorType)) { if (std::ranges::contains(descriptorBindings, Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK, &Gfx::DescriptorBinding::descriptorType)) {
bindings.add({ bindings.add({
.binding = 0, .binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // although we can pretend that we support inline uniforms, slang does not generate them .descriptorType =
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // although we can pretend that we support inline uniforms, slang does not generate them
.descriptorCount = 1, .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_ALL, // todo .stageFlags = VK_SHADER_STAGE_ALL, // todo
.pImmutableSamplers = nullptr, .pImmutableSamplers = nullptr,
@@ -129,7 +131,7 @@ DescriptorPool::~DescriptorPool() {
} }
} }
Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { Gfx::ODescriptorSet DescriptorPool::allocateDescriptorSet() {
VkDescriptorSetLayout layoutHandle = layout->getHandle(); VkDescriptorSetLayout layoutHandle = layout->getHandle();
VkDescriptorSetVariableDescriptorCountAllocateInfo setCounts = { VkDescriptorSetVariableDescriptorCountAllocateInfo setCounts = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO,
@@ -155,7 +157,7 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
} }
for (uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex) { for (uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex) {
if (cachedHandles[setIndex] == nullptr) { if (cachedHandles[setIndex] == nullptr) {
cachedHandles[setIndex] = new DescriptorSet(graphics, this); cachedHandles[setIndex] = new DescriptorSetHandle(graphics, layout->getName());
} }
if (cachedHandles[setIndex]->isCurrentlyBound()) { if (cachedHandles[setIndex]->isCurrentlyBound()) {
// Currently in use, skip // Currently in use, skip
@@ -163,21 +165,19 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
} }
if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) { if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) {
// If it hasnt been initialized, allocate it // If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle)); VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->handle));
VkDebugUtilsObjectNameInfoEXT nameInfo = { VkDebugUtilsObjectNameInfoEXT nameInfo = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pNext = nullptr, .pNext = nullptr,
.objectType = VK_OBJECT_TYPE_DESCRIPTOR_SET, .objectType = VK_OBJECT_TYPE_DESCRIPTOR_SET,
.objectHandle = (uint64)cachedHandles[setIndex]->setHandle, .objectHandle = (uint64)cachedHandles[setIndex]->getHandle(),
.pObjectName = name.c_str(), .pObjectName = name.c_str(),
}; };
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo); vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
} }
PDescriptorSet vulkanSet = cachedHandles[setIndex];
// Found set, stop searching // Found set, stop searching
return vulkanSet; return new DescriptorSet(graphics, this, cachedHandles[setIndex]);
} }
if (nextAlloc == nullptr) { if (nextAlloc == nullptr) {
nextAlloc = new DescriptorPool(graphics, layout); nextAlloc = new DescriptorPool(graphics, layout);
@@ -198,8 +198,12 @@ void DescriptorPool::reset() {
} }
} }
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) DescriptorSetHandle::DescriptorSetHandle(PGraphics graphics, const std::string& name) : CommandBoundResource(graphics, name) {}
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics, owner->getLayout()->getName()), setHandle(VK_NULL_HANDLE),
DescriptorSetHandle::~DescriptorSetHandle() {}
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle)
: Gfx::DescriptorSet(owner->getLayout()), setHandle(setHandle),
graphics(graphics), owner(owner) { graphics(graphics), owner(owner) {
boundResources.resize(owner->getLayout()->bindings.size()); boundResources.resize(owner->getLayout()->bindings.size());
for (uint32 i = 0; i < boundResources.size(); ++i) { for (uint32 i = 0; i < boundResources.size(); ++i) {
@@ -234,7 +238,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -261,7 +265,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -288,7 +292,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -315,7 +319,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -343,7 +347,7 @@ void DescriptorSet::updateSampler(const std::string& mappingName, uint32 index,
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -371,7 +375,7 @@ void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index,
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -394,7 +398,7 @@ void DescriptorSet::updateAccelerationStructure(const std::string& mappingName,
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = &accelerationInfos.back(), .pNext = &accelerationInfos.back(),
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = binding, .dstBinding = binding,
.dstArrayElement = index, .dstArrayElement = index,
.descriptorCount = 1, .descriptorCount = 1,
@@ -429,7 +433,7 @@ void DescriptorSet::writeChanges() {
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
.dstSet = setHandle, .dstSet = setHandle->getHandle(),
.dstBinding = 0, .dstBinding = 0,
.dstArrayElement = 0, .dstArrayElement = 0,
.descriptorCount = 1, .descriptorCount = 1,
@@ -439,9 +443,9 @@ void DescriptorSet::writeChanges() {
} }
if (writeDescriptors.size() > 0) { if (writeDescriptors.size() > 0) {
if (isCurrentlyBound()) { if (setHandle->isCurrentlyBound()) {
std::cout << "Descriptor currently bound, allocate a new one instead" << std::endl; std::cout << "Descriptor currently bound, allocate a new one instead" << std::endl;
assert(!isCurrentlyBound()); assert(!setHandle->isCurrentlyBound());
} }
vkUpdateDescriptorSets(graphics->getDevice(), (uint32)writeDescriptors.size(), writeDescriptors.data(), 0, nullptr); vkUpdateDescriptorSets(graphics->getDevice(), (uint32)writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
writeDescriptors.clear(); writeDescriptors.clear();
+17 -7
View File
@@ -3,6 +3,7 @@
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Vulkan/Buffer.h" #include "Graphics/Vulkan/Buffer.h"
#include "Resources.h" #include "Resources.h"
#include <vulkan/vulkan_core.h>
namespace Seele { namespace Seele {
namespace Vulkan { namespace Vulkan {
@@ -32,12 +33,22 @@ class DescriptorLayout : public Gfx::DescriptorLayout {
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
class DescriptorSetHandle : public CommandBoundResource {
public:
DescriptorSetHandle(PGraphics graphics, const std::string& name);
virtual ~DescriptorSetHandle();
constexpr VkDescriptorSet getHandle() const { return handle; }
PGraphics graphics;
VkDescriptorSet handle = VK_NULL_HANDLE;
};
DEFINE_REF(DescriptorSetHandle)
DECLARE_REF(DescriptorSet) DECLARE_REF(DescriptorSet)
class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource { class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource {
public: public:
DescriptorPool(PGraphics graphics, PDescriptorLayout layout); DescriptorPool(PGraphics graphics, PDescriptorLayout layout);
virtual ~DescriptorPool(); virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override; virtual Gfx::ODescriptorSet allocateDescriptorSet() override;
virtual void reset() override; virtual void reset() override;
constexpr VkDescriptorPool getHandle() const { return poolHandle; } constexpr VkDescriptorPool getHandle() const { return poolHandle; }
@@ -47,15 +58,14 @@ class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource {
PGraphics graphics; PGraphics graphics;
PDescriptorLayout layout; PDescriptorLayout layout;
const static int maxSets = 64; const static int maxSets = 64;
StaticArray<ODescriptorSet, maxSets> cachedHandles; StaticArray<ODescriptorSetHandle, maxSets> cachedHandles;
VkDescriptorPool poolHandle; VkDescriptorPool poolHandle;
DescriptorPool* nextAlloc = nullptr; DescriptorPool* nextAlloc = nullptr;
}; };
DEFINE_REF(DescriptorPool) DEFINE_REF(DescriptorPool)
class DescriptorSet : public Gfx::DescriptorSet {
class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
public: public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner); DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle);
virtual ~DescriptorSet(); virtual ~DescriptorSet();
virtual void writeChanges() override; virtual void writeChanges() override;
virtual void updateConstants(const std::string& name, uint32 offset, void* data) override; virtual void updateConstants(const std::string& name, uint32 offset, void* data) override;
@@ -67,7 +77,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureView texture) override; virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureView texture) override;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override; virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
constexpr VkDescriptorSet getHandle() const { return setHandle; } constexpr VkDescriptorSet getHandle() const { return setHandle->getHandle(); }
private: private:
std::vector<uint8> constantData; std::vector<uint8> constantData;
@@ -81,7 +91,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
// would not work anyways, so casts should be safe // would not work anyways, so casts should be safe
// Array<void*> cachedData; // Array<void*> cachedData;
Array<Array<PCommandBoundResource>> boundResources; Array<Array<PCommandBoundResource>> boundResources;
VkDescriptorSet setHandle; PDescriptorSetHandle setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
friend class DescriptorPool; friend class DescriptorPool;
+1 -1
View File
@@ -186,7 +186,7 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
allocatedFramebuffers[framebufferHash] = new Framebuffer(this, rp, rp->getLayout()); allocatedFramebuffers[framebufferHash] = new Framebuffer(this, rp, rp->getLayout());
framebuffer = allocatedFramebuffers[framebufferHash]; framebuffer = allocatedFramebuffers[framebufferHash];
} else { } else {
framebuffer = std::move(found->value); framebuffer = found->value;
} }
} }
getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer); getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer);
+1 -1
View File
@@ -14,7 +14,7 @@ Array<Gfx::PSampler> Material::samplers;
Gfx::OShaderBuffer Material::floatBuffer; Gfx::OShaderBuffer Material::floatBuffer;
Array<float> Material::floatData; Array<float> Material::floatData;
Gfx::ODescriptorLayout Material::layout; Gfx::ODescriptorLayout Material::layout;
Gfx::PDescriptorSet Material::set; Gfx::ODescriptorSet Material::set;
std::atomic_uint64_t Material::materialIdCounter = 0; std::atomic_uint64_t Material::materialIdCounter = 0;
Array<PMaterial> Material::materials; Array<PMaterial> Material::materials;
+1 -1
View File
@@ -63,7 +63,7 @@ class Material {
static Gfx::OShaderBuffer floatBuffer; static Gfx::OShaderBuffer floatBuffer;
static Array<float> floatData; static Array<float> floatData;
static Gfx::ODescriptorLayout layout; static Gfx::ODescriptorLayout layout;
static Gfx::PDescriptorSet set; static Gfx::ODescriptorSet set;
static std::atomic_uint64_t materialIdCounter; static std::atomic_uint64_t materialIdCounter;
static Array<PMaterial> materials; static Array<PMaterial> materials;
}; };
+14 -4
View File
@@ -5,7 +5,6 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#define DEFINE_REF(x) \ #define DEFINE_REF(x) \
typedef ::Seele::RefPtr<x> P##x; \ typedef ::Seele::RefPtr<x> P##x; \
typedef ::Seele::UniquePtr<x> UP##x; \ typedef ::Seele::UniquePtr<x> UP##x; \
@@ -26,10 +25,12 @@
} }
namespace Seele { namespace Seele {
template <typename T> class OwningPtr;
template <typename T> class RefPtr { template <typename T> class RefPtr {
public: public:
constexpr RefPtr() noexcept : object(nullptr) {} constexpr RefPtr() noexcept : object(nullptr) {}
constexpr RefPtr(std::nullptr_t) noexcept : object(nullptr) {} constexpr RefPtr(std::nullptr_t) noexcept : object(nullptr) {}
constexpr RefPtr(OwningPtr<T>&&) = delete;
RefPtr(T* ptr) : object(ptr) {} RefPtr(T* ptr) : object(ptr) {}
constexpr RefPtr(const RefPtr& other) noexcept : object(other.object) {} constexpr RefPtr(const RefPtr& other) noexcept : object(other.object) {}
constexpr RefPtr(RefPtr&& rhs) noexcept : object(std::move(rhs.object)) { rhs.object = nullptr; } constexpr RefPtr(RefPtr&& rhs) noexcept : object(std::move(rhs.object)) { rhs.object = nullptr; }
@@ -49,6 +50,7 @@ template <typename T> class RefPtr {
} }
return RefPtr<F>(f); return RefPtr<F>(f);
} }
constexpr RefPtr& operator=(OwningPtr<T>&&) = delete;
constexpr RefPtr& operator=(const RefPtr& other) { constexpr RefPtr& operator=(const RefPtr& other) {
if (this != &other) { if (this != &other) {
object = other.object; object = other.object;
@@ -62,6 +64,10 @@ template <typename T> class RefPtr {
} }
return *this; return *this;
} }
constexpr RefPtr& operator=(std::nullptr_t) noexcept {
object = nullptr;
return *this;
}
constexpr ~RefPtr() {} constexpr ~RefPtr() {}
constexpr bool operator==(const RefPtr& rhs) const noexcept { return object == rhs.object; } constexpr bool operator==(const RefPtr& rhs) const noexcept { return object == rhs.object; }
constexpr auto operator<=>(const RefPtr& rhs) const noexcept { return object <=> rhs.object; } constexpr auto operator<=>(const RefPtr& rhs) const noexcept { return object <=> rhs.object; }
@@ -77,7 +83,7 @@ template <typename T> class RefPtr {
private: private:
T* object; T* object;
}; };
template <typename T, typename Deleter = std::default_delete<T>> class OwningPtr { template <typename T> class OwningPtr {
public: public:
OwningPtr() : pointer(nullptr) {} OwningPtr() : pointer(nullptr) {}
OwningPtr(T* ptr) : pointer(ptr) {} OwningPtr(T* ptr) : pointer(ptr) {}
@@ -94,14 +100,18 @@ template <typename T, typename Deleter = std::default_delete<T>> class OwningPtr
OwningPtr& operator=(OwningPtr&& other) noexcept { OwningPtr& operator=(OwningPtr&& other) noexcept {
if (this != &other) { if (this != &other) {
if (pointer != nullptr) { if (pointer != nullptr) {
Deleter()(pointer); std::default_delete<T> d;
d(pointer);
} }
pointer = other.pointer; pointer = other.pointer;
other.pointer = nullptr; other.pointer = nullptr;
} }
return *this; return *this;
} }
~OwningPtr() { Deleter()(pointer); } ~OwningPtr() {
std::default_delete<T> d;
d(pointer);
}
constexpr operator RefPtr<T>() { return RefPtr<T>(pointer); } constexpr operator RefPtr<T>() { return RefPtr<T>(pointer); }
constexpr operator RefPtr<T>() const { return RefPtr<T>(pointer); } constexpr operator RefPtr<T>() const { return RefPtr<T>(pointer); }
constexpr T* operator->() { return pointer; } constexpr T* operator->() { return pointer; }
+1 -1
View File
@@ -41,7 +41,7 @@ class LightEnvironment {
PEnvironmentMapAsset environment; PEnvironmentMapAsset environment;
Gfx::OSampler environmentSampler; Gfx::OSampler environmentSampler;
Gfx::ODescriptorLayout layout; Gfx::ODescriptorLayout layout;
Gfx::PDescriptorSet set; Gfx::ODescriptorSet set;
}; };
DEFINE_REF(LightEnvironment) DEFINE_REF(LightEnvironment)
} // namespace Seele } // namespace Seele
-4
View File
@@ -1,15 +1,11 @@
#include "GameView.h" #include "GameView.h"
#include "Actor/CameraActor.h"
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "Component/KeyboardInput.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Query.h"
#include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/BasePass.h"
#include "Graphics/RenderPass/CachedDepthPass.h" #include "Graphics/RenderPass/CachedDepthPass.h"
#include "Graphics/RenderPass/DepthCullingPass.h" #include "Graphics/RenderPass/DepthCullingPass.h"
#include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/RayTracingPass.h" #include "Graphics/RenderPass/RayTracingPass.h"
#include "Graphics/RenderPass/RenderGraphResources.h"
#include "Graphics/RenderPass/ToneMappingPass.h" #include "Graphics/RenderPass/ToneMappingPass.h"
#include "Graphics/RenderPass/VisibilityPass.h" #include "Graphics/RenderPass/VisibilityPass.h"
#include "Graphics/RenderPass/ShadowPass.h" #include "Graphics/RenderPass/ShadowPass.h"
+1 -1
View File
@@ -31,7 +31,7 @@ class GameView : public View {
RenderGraph renderGraph; RenderGraph renderGraph;
RenderGraph rayTracingGraph; RenderGraph rayTracingGraph;
PSystemGraph systemGraph; OSystemGraph systemGraph;
System::PKeyboardInput keyboardSystem; System::PKeyboardInput keyboardSystem;
float updateTime = 0; float updateTime = 0;