diff --git a/src/Editor/Asset/EnvironmentLoader.cpp b/src/Editor/Asset/EnvironmentLoader.cpp index fba6b53..db57097 100644 --- a/src/Editor/Asset/EnvironmentLoader.cpp +++ b/src/Editor/Asset/EnvironmentLoader.cpp @@ -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)), }; - Gfx::PDescriptorSet set = cubeRenderLayout->allocateDescriptorSet(); + Gfx::ODescriptorSet set = cubeRenderLayout->allocateDescriptorSet(); set->updateConstants("view", 0, captureViews); set->updateConstants("projection", 0, &captureProjection); set->updateTexture("equirectangularMap", 0, hdrTexture->getDefaultView()); @@ -262,7 +262,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset graphics->beginRenderPass(cubeRenderPass); Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("CubeMapRender"); renderCommand->bindPipeline(cubeRenderPipeline); - renderCommand->bindDescriptor({set}); + renderCommand->bindDescriptor(set); renderCommand->setViewport(cubeRenderViewport); renderCommand->draw(6, 1, i * 6, 0); graphics->executeCommands(std::move(renderCommand)); @@ -329,7 +329,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset graphics->beginRenderPass(convolutionPass); Gfx::ORenderCommand cmd = graphics->createRenderCommand("ConvolutionPass"); cmd->bindPipeline(convolutionPipeline); - cmd->bindDescriptor({set}); + cmd->bindDescriptor(set); cmd->setViewport(convolutionViewport); cmd->draw(6, 1, i * 6, 0); graphics->executeCommands(std::move(cmd)); @@ -391,7 +391,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset graphics->beginRenderPass(prefilterPass); Gfx::ORenderCommand cmd = graphics->createRenderCommand("PrefilterPass"); cmd->bindPipeline(prefilterPipeline); - cmd->bindDescriptor({set}); + cmd->bindDescriptor(set); float roughness = (float)mip / (float)(prefilteredCubeMap->getMipLevels() - 1); cmd->pushConstants(Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(float), &roughness); cmd->setViewport(prefilterViewports[mip]); diff --git a/src/Engine/Graphics/Descriptor.cpp b/src/Engine/Graphics/Descriptor.cpp index 4d81705..a30ab36 100644 --- a/src/Engine/Graphics/Descriptor.cpp +++ b/src/Engine/Graphics/Descriptor.cpp @@ -11,7 +11,7 @@ void DescriptorLayout::addDescriptorBinding(DescriptorBinding binding) { descriptorBindings.add(binding); } -PDescriptorSet DescriptorLayout::allocateDescriptorSet() { return pool->allocateDescriptorSet(); } +ODescriptorSet DescriptorLayout::allocateDescriptorSet() { return pool->allocateDescriptorSet(); } void DescriptorLayout::reset() { pool->reset(); } diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index 04e89d3..2011420 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -25,7 +25,7 @@ class DescriptorLayout { virtual ~DescriptorLayout(); void addDescriptorBinding(DescriptorBinding binding); void reset(); - PDescriptorSet allocateDescriptorSet(); + ODescriptorSet allocateDescriptorSet(); virtual void create() = 0; constexpr uint32 getHash() const { return hash; } constexpr const std::string& getName() const { return name; } @@ -45,7 +45,7 @@ class DescriptorPool { public: DescriptorPool(); virtual ~DescriptorPool(); - virtual PDescriptorSet allocateDescriptorSet() = 0; + virtual ODescriptorSet allocateDescriptorSet() = 0; virtual void reset() = 0; }; DEFINE_REF(DescriptorPool) diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 845e4d8..4dfaddd 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -1,6 +1,5 @@ #include "BasePass.h" #include "Asset/AssetRegistry.h" -#include "Asset/EnvironmentMapAsset.h" #include "Component/Camera.h" #include "Graphics/Command.h" #include "Graphics/Descriptor.h" @@ -14,6 +13,9 @@ #include "Math/Vector.h" #include "MinimalEngine.h" #include "ShadowPass.h" +#include "Scene/Scene.h" +#include "Asset/EnvironmentMapAsset.h" +#include "Scene/LightEnvironment.h" using namespace Seele; @@ -481,7 +483,6 @@ void BasePass::publishOutputs() { resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment); - timestamps = graphics->createTimestampQuery(2, "BaseTS"); query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics"); resources->registerQueryOutput("BASEPASS_QUERY", query); } diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index beeea30..04972f2 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -37,9 +37,9 @@ class BasePass : public RenderPass { constexpr static const char* SHADOWSAMPLER_NAME = "shadowSampler"; constexpr static const char* CASCADE_SPLIT_NAME = "cascadeSplit"; - Gfx::PDescriptorSet opaqueCulling; - Gfx::PDescriptorSet transparentCulling; - Gfx::PDescriptorSet shadowMapping; + Gfx::ODescriptorSet opaqueCulling; + Gfx::ODescriptorSet transparentCulling; + Gfx::ODescriptorSet shadowMapping; // use a different texture here so we can do multisampling Gfx::OTexture2D msBasePassDepth; @@ -51,7 +51,7 @@ class BasePass : public RenderPass { // used for transparency sorting Vector cameraPos; Vector cameraForward; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; PCameraActor source; Gfx::OPipelineLayout basePassLayout; @@ -82,9 +82,9 @@ class BasePass : public RenderPass { // Skybox Gfx::ODescriptorLayout skyboxDataLayout; - Gfx::PDescriptorSet skyboxDataSet; + Gfx::ODescriptorSet skyboxDataSet; Gfx::ODescriptorLayout textureLayout; - Gfx::PDescriptorSet textureSet; + Gfx::ODescriptorSet textureSet; Gfx::OVertexShader vertexShader; Gfx::OFragmentShader fragmentShader; Gfx::OPipelineLayout pipelineLayout; diff --git a/src/Engine/Graphics/RenderPass/CachedDepthPass.h b/src/Engine/Graphics/RenderPass/CachedDepthPass.h index 58f5d89..bbb8ffa 100644 --- a/src/Engine/Graphics/RenderPass/CachedDepthPass.h +++ b/src/Engine/Graphics/RenderPass/CachedDepthPass.h @@ -24,7 +24,7 @@ class CachedDepthPass : public RenderPass { Gfx::OPipelineStatisticsQuery query; Gfx::OTimestampQuery timestamps; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; Gfx::PShaderBuffer cullingBuffer; PScene scene; }; diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index ba1a3ff..4c0ae75 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -72,7 +72,7 @@ void DepthCullingPass::beginFrame(const Component::Camera& cam, const Component: void DepthCullingPass::render() { graphics->beginDebugRegion("DepthCullingPass"); - Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); + Gfx::ODescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); { graphics->beginDebugRegion("MipGeneration"); query->beginQuery(); diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.h b/src/Engine/Graphics/RenderPass/DepthCullingPass.h index 84e908c..2c55be5 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.h +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.h @@ -44,7 +44,7 @@ class DepthCullingPass : public RenderPass { Gfx::PComputePipeline depthSourceCopy; Gfx::OComputeShader depthReduceLevelShader; Gfx::PComputePipeline depthReduceLevel; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; Gfx::PShaderBuffer cullingBuffer; PScene scene; diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 853cf89..1674143 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -143,7 +143,7 @@ void LightCullingPass::publishOutputs() { Gfx::ComputePipelineCreateInfo pipelineInfo; pipelineInfo.computeShader = cullingShader; - pipelineInfo.pipelineLayout = std::move(cullingLayout); + pipelineInfo.pipelineLayout = cullingLayout; cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo)); } @@ -167,7 +167,7 @@ void LightCullingPass::publishOutputs() { Gfx::ComputePipelineCreateInfo pipelineInfo; pipelineInfo.computeShader = cullingShader; - pipelineInfo.pipelineLayout = std::move(cullingEnableLayout); + pipelineInfo.pipelineLayout = cullingEnableLayout; cullingEnabledPipeline = graphics->createComputePipeline(std::move(pipelineInfo)); } diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index db1dfae..d0c2373 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -29,11 +29,11 @@ class LightCullingPass : public RenderPass { Gfx::OShaderBuffer frustumBuffer; const char* FRUSTUMBUFFER_NAME = "frustums"; Gfx::ODescriptorLayout dispatchParamsLayout; - Gfx::PDescriptorSet dispatchParamsSet; + Gfx::ODescriptorSet dispatchParamsSet; Gfx::OComputeShader frustumShader; Gfx::PComputePipeline frustumPipeline; Gfx::OPipelineLayout frustumLayout; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; PLightEnvironment lightEnv; Gfx::PTextureView depthAttachment; @@ -50,7 +50,7 @@ class LightCullingPass : public RenderPass { constexpr static const char* OLIGHTGRID_NAME = "oLightGrid"; Gfx::OTexture2D tLightGrid; constexpr static const char* TLIGHTGRID_NAME = "tLightGrid"; - Gfx::PDescriptorSet cullingDescriptorSet; + Gfx::ODescriptorSet cullingDescriptorSet; Gfx::ODescriptorLayout cullingDescriptorLayout; Gfx::OPipelineLayout cullingLayout; Gfx::OPipelineLayout cullingEnableLayout; diff --git a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp index 2a5301b..5c72fb8 100644 --- a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp +++ b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp @@ -66,7 +66,8 @@ static uint32 pass = 0; static Component::Transform lastCam; void RayTracingPass::beginFrame(const Component::Camera& cam, const Component::Transform& 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; pass = 0; } @@ -149,7 +150,7 @@ void RayTracingPass::render() { .instances = instanceData, .bottomLevelStructures = accelerationStructures, }); - Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet(); + Gfx::ODescriptorSet desc = paramsLayout->allocateDescriptorSet(); desc->updateAccelerationStructure(TLAS_NAME, 0, tlas); desc->updateTexture(ACCUMULATOR_NAME, 0, radianceAccumulator->getDefaultView()); desc->updateTexture(TEXTURE_NAME, 0, texture->getDefaultView()); diff --git a/src/Engine/Graphics/RenderPass/RayTracingPass.h b/src/Engine/Graphics/RenderPass/RayTracingPass.h index 2e63267..7abdb27 100644 --- a/src/Engine/Graphics/RenderPass/RayTracingPass.h +++ b/src/Engine/Graphics/RenderPass/RayTracingPass.h @@ -32,7 +32,7 @@ class RayTracingPass : public RenderPass { Gfx::OAnyHitShader anyhit; Gfx::OMissShader miss; Gfx::PRayTracingPipeline pipeline; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; PScene scene; }; } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPass/RenderGraph.h b/src/Engine/Graphics/RenderPass/RenderGraph.h index 8fdf5c1..bf6d323 100644 --- a/src/Engine/Graphics/RenderPass/RenderGraph.h +++ b/src/Engine/Graphics/RenderPass/RenderGraph.h @@ -38,7 +38,7 @@ class RenderGraph { return res; } private: - PRenderGraphResources res; + ORenderGraphResources res; List passes; }; diff --git a/src/Engine/Graphics/RenderPass/RenderPass.cpp b/src/Engine/Graphics/RenderPass/RenderPass.cpp index afeccf2..be37eb0 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/RenderPass.cpp @@ -49,7 +49,7 @@ void RenderPass::updateViewParameters(const Component::Camera& cam, const Compon }; } -Gfx::PDescriptorSet RenderPass::createViewParamsSet() +Gfx::ODescriptorSet RenderPass::createViewParamsSet() { // screen space //StaticArray corners = { @@ -71,8 +71,7 @@ Gfx::PDescriptorSet RenderPass::createViewParamsSet() // extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum); - viewParamsLayout->reset(); - Gfx::PDescriptorSet viewParamsSet = viewParamsLayout->allocateDescriptorSet(); + Gfx::ODescriptorSet viewParamsSet = viewParamsLayout->allocateDescriptorSet(); viewParamsSet->updateConstants("viewMatrix", 0, &viewParams.viewMatrix); viewParamsSet->updateConstants("inverseViewMatrix", 0, &viewParams.inverseViewMatrix); viewParamsSet->updateConstants("projectionMatrix", 0, &viewParams.projectionMatrix); diff --git a/src/Engine/Graphics/RenderPass/RenderPass.h b/src/Engine/Graphics/RenderPass/RenderPass.h index 92c1ad0..7702afc 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.h +++ b/src/Engine/Graphics/RenderPass/RenderPass.h @@ -28,7 +28,7 @@ class RenderPass { protected: void updateViewParameters(const Component::Camera& cam, const Component::Transform& transform); - Gfx::PDescriptorSet createViewParamsSet(); + Gfx::ODescriptorSet createViewParamsSet(); struct Plane { Vector n; float d; diff --git a/src/Engine/Graphics/RenderPass/ShadowPass.cpp b/src/Engine/Graphics/RenderPass/ShadowPass.cpp index 029a2c3..6e5c180 100644 --- a/src/Engine/Graphics/RenderPass/ShadowPass.cpp +++ b/src/Engine/Graphics/RenderPass/ShadowPass.cpp @@ -62,6 +62,7 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr float uniform = minZ + range * p; float d = cascadeSplitLambda * (log - uniform) + uniform; cascadeSplits[i] = (d - nearClip) / clipRange; + cascades[i].viewParams.clear(); } // call this to update view params member, ignore descriptor set @@ -210,7 +211,7 @@ void ShadowPass::render() { command->bindPipeline(pipeline); } command->bindDescriptor( - {cascades[c].viewParams[c], vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()}); + {cascades[c].viewParams[shadowIndex], vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()}); VertexData::DrawCallOffsets offsets = { .instanceOffset = 0, }; diff --git a/src/Engine/Graphics/RenderPass/ShadowPass.h b/src/Engine/Graphics/RenderPass/ShadowPass.h index 6d7a3bf..c897ad7 100644 --- a/src/Engine/Graphics/RenderPass/ShadowPass.h +++ b/src/Engine/Graphics/RenderPass/ShadowPass.h @@ -26,7 +26,7 @@ class ShadowPass : public RenderPass { Array views; Array lightSpaceMatrices; Gfx::OShaderBuffer lightSpaceBuffer; - Array viewParams; + Array viewParams; }; StaticArray cascades; Gfx::OUniformBuffer cascadeSplitsBuffer; diff --git a/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp b/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp index 19f704c..c43ddc3 100644 --- a/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp +++ b/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp @@ -148,7 +148,7 @@ void ToneMappingPass::render() { { Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("HistogramCommand"); computeCommand->bindPipeline(histogramPipeline); - computeCommand->bindDescriptor({histogramSet}); + computeCommand->bindDescriptor(histogramSet); computeCommand->dispatch(threadGroups.x, threadGroups.y, 1); graphics->executeCommands(std::move(computeCommand)); } @@ -158,7 +158,7 @@ void ToneMappingPass::render() { { Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("ExposureCommand"); computeCommand->bindPipeline(exposurePipeline); - computeCommand->bindDescriptor({histogramSet}); + computeCommand->bindDescriptor(histogramSet); computeCommand->dispatch(1, 1, 1); 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); tonemappingLayout->reset(); - Gfx::PDescriptorSet tonemappingSet = tonemappingLayout->allocateDescriptorSet(); + Gfx::ODescriptorSet tonemappingSet = tonemappingLayout->allocateDescriptorSet(); tonemappingSet->updateConstants("offset", 0, &offset); tonemappingSet->updateConstants("slope", 0, &slope); tonemappingSet->updateConstants("power", 0, &power); @@ -181,7 +181,7 @@ void ToneMappingPass::render() { Gfx::ORenderCommand command = graphics->createRenderCommand("ToneMapping"); command->setViewport(viewport); command->bindPipeline(pipeline); - command->bindDescriptor({tonemappingSet}); + command->bindDescriptor(tonemappingSet); command->draw(3, 1, 0, 0); graphics->executeCommands(std::move(command)); graphics->endRenderPass(); diff --git a/src/Engine/Graphics/RenderPass/ToneMappingPass.h b/src/Engine/Graphics/RenderPass/ToneMappingPass.h index 1181f95..36715ef 100644 --- a/src/Engine/Graphics/RenderPass/ToneMappingPass.h +++ b/src/Engine/Graphics/RenderPass/ToneMappingPass.h @@ -28,7 +28,7 @@ class ToneMappingPass : public RenderPass { uint32 numPixels; UVector2 threadGroups; Gfx::ODescriptorLayout histogramLayout; - Gfx::PDescriptorSet histogramSet; + Gfx::ODescriptorSet histogramSet; Gfx::OPipelineLayout histogramPipelineLayout; Gfx::OComputeShader histogramShader; Gfx::PComputePipeline histogramPipeline; @@ -48,6 +48,6 @@ class ToneMappingPass : public RenderPass { Gfx::OFragmentShader frag; Gfx::PGraphicsPipeline pipeline; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; }; } \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h index 75e6b59..572f1ad 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.h +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -52,7 +52,7 @@ class UIPass : public RenderPass { Gfx::OTexture2D depthBuffer; Gfx::ODescriptorLayout textDescriptorLayout; - Gfx::PDescriptorSet textDescriptorSet; + Gfx::ODescriptorSet textDescriptorSet; Gfx::OVertexShader textVertexShader; Gfx::OFragmentShader textFragmentShader; @@ -60,9 +60,9 @@ class UIPass : public RenderPass { Gfx::PGraphicsPipeline textPipeline; Gfx::ODescriptorLayout uiDescriptorLayout; - Gfx::PDescriptorSet uiDescriptorSet; + Gfx::ODescriptorSet uiDescriptorSet; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; Gfx::OVertexShader uiVertexShader; Gfx::OFragmentShader uiFragmentShader; diff --git a/src/Engine/Graphics/RenderPass/VisibilityPass.h b/src/Engine/Graphics/RenderPass/VisibilityPass.h index b8815a5..3302018 100644 --- a/src/Engine/Graphics/RenderPass/VisibilityPass.h +++ b/src/Engine/Graphics/RenderPass/VisibilityPass.h @@ -19,14 +19,14 @@ class VisibilityPass : public RenderPass { private: static constexpr uint32 BLOCK_SIZE = 32; Gfx::RenderTargetAttachment visibilityAttachment; - Gfx::PDescriptorSet visibilitySet; + Gfx::ODescriptorSet visibilitySet; Gfx::ODescriptorLayout visibilityDescriptor; Gfx::OPipelineLayout visibilityLayout; Gfx::OComputeShader visibilityShader; Gfx::PComputePipeline visibilityPipeline; Gfx::OPipelineStatisticsQuery query; Gfx::PTimestampQuery timestamps; - Gfx::PDescriptorSet viewParamsSet; + Gfx::ODescriptorSet viewParamsSet; constexpr static const char* VISIBILITY_NAME = "visibilityTexture"; // Holds culling information for every meshlet for each instance diff --git a/src/Engine/Graphics/RenderPass/WaterRenderer.h b/src/Engine/Graphics/RenderPass/WaterRenderer.h index b995f4c..d4a314e 100644 --- a/src/Engine/Graphics/RenderPass/WaterRenderer.h +++ b/src/Engine/Graphics/RenderPass/WaterRenderer.h @@ -18,7 +18,7 @@ class WaterRenderer { Gfx::PGraphics graphics; PScene scene; Gfx::ODescriptorLayout computeLayout; - Gfx::PDescriptorSet computeSet; + Gfx::ODescriptorSet computeSet; Gfx::OPipelineLayout pipelineLayout; Gfx::OComputeShader initSpectrumCS; @@ -145,7 +145,7 @@ class WaterRenderer { Gfx::OMeshShader waterMesh; Gfx::OFragmentShader waterFragment; Gfx::ODescriptorLayout materialLayout; - Gfx::PDescriptorSet materialSet; + Gfx::ODescriptorSet materialSet; Gfx::OPipelineLayout waterLayout; Gfx::PGraphicsPipeline waterPipeline; diff --git a/src/Engine/Graphics/StaticMeshVertexData.h b/src/Engine/Graphics/StaticMeshVertexData.h index 0005944..bb8697d 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.h +++ b/src/Engine/Graphics/StaticMeshVertexData.h @@ -50,6 +50,6 @@ class StaticMeshVertexData : public VertexData { Array bitData; Array colData; Gfx::ODescriptorLayout descriptorLayout; - Gfx::PDescriptorSet descriptorSet; + Gfx::ODescriptorSet descriptorSet; }; } // namespace Seele diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 510a2a8..ceaa2f3 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -158,7 +158,7 @@ class VertexData { Array rayTracingScene; - Gfx::PDescriptorSet descriptorSet; + Gfx::ODescriptorSet descriptorSet; uint64 idCounter; uint64 head; uint64 verticesAllocated; diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index 8623ef7..a255a74 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -256,8 +256,8 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { assert(threadId == std::this_thread::get_id()); auto descriptorSet = descriptor.cast(); assert(descriptorSet->writeDescriptors.size() == 0); - descriptorSet->bind(); - boundResources.add(descriptorSet); + descriptorSet->setHandle->bind(); + boundResources.add(descriptorSet->setHandle); for (auto& binding : descriptorSet->boundResources) { for (auto& res : binding) { // partially bound descriptors can include nulls @@ -268,7 +268,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { } } if (descriptorSet->constantsBuffer != nullptr) { - descriptorSet->bind(); + descriptorSet->setHandle->bind(); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); } @@ -286,8 +286,8 @@ void RenderCommand::bindDescriptor(const Array& descriptorS for (uint32 i = 0; i < descriptorSets.size(); ++i) { auto descriptorSet = descriptorSets[i].cast(); assert(descriptorSet->writeDescriptors.size() == 0); - descriptorSet->bind(); - boundResources.add(descriptorSet); + descriptorSet->setHandle->bind(); + boundResources.add(descriptorSet->setHandle); for (auto& binding : descriptorSet->boundResources) { for (auto& res : binding) { @@ -299,7 +299,7 @@ void RenderCommand::bindDescriptor(const Array& descriptorS } } if (descriptorSet->constantsBuffer != nullptr) { - descriptorSet->bind(); + descriptorSet->setHandle->bind(); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); } sets[layout->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); @@ -436,8 +436,8 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { assert(threadId == std::this_thread::get_id()); auto descriptorSet = descriptor.cast(); assert(descriptorSet->writeDescriptors.size() == 0); - descriptorSet->bind(); - boundResources.add(descriptorSet.getHandle()); + descriptorSet->setHandle->bind(); + boundResources.add(descriptorSet->setHandle); for (auto& binding : descriptorSet->boundResources) { for (auto& res : binding) { @@ -449,7 +449,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { } } if (descriptorSet->constantsBuffer != nullptr) { - descriptorSet->bind(); + descriptorSet->setHandle->bind(); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); } @@ -464,8 +464,8 @@ void ComputeCommand::bindDescriptor(const Array& descriptor for (uint32 i = 0; i < descriptorSets.size(); ++i) { auto descriptorSet = descriptorSets[i].cast(); assert(descriptorSet->writeDescriptors.size() == 0); - descriptorSet->bind(); - boundResources.add(descriptorSet.getHandle()); + descriptorSet->setHandle->bind(); + boundResources.add(descriptorSet->setHandle); for (auto& binding : descriptorSet->boundResources) { for (auto& res : binding) { // partially bound descriptors can include nulls @@ -476,7 +476,7 @@ void ComputeCommand::bindDescriptor(const Array& descriptor } } if (descriptorSet->constantsBuffer != nullptr) { - descriptorSet->bind(); + descriptorSet->setHandle->bind(); boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer)); } sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 69d37d9..66417f2 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -2,17 +2,18 @@ #include "Buffer.h" #include "CRC.h" #include "Command.h" +#include "Enums.h" #include "Graphics.h" #include "Graphics/Buffer.h" #include "Graphics/Descriptor.h" #include "Graphics/Enums.h" #include "Graphics/Initializer.h" +#include "Graphics/Vulkan/Resources.h" #include "RayTracing.h" #include "Texture.h" -#include "Enums.h" -#include #include "vulkan/vulkan_core.h" #include +#include #include 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)) { bindings.add({ .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, .stageFlags = VK_SHADER_STAGE_ALL, // todo .pImmutableSamplers = nullptr, @@ -129,7 +131,7 @@ DescriptorPool::~DescriptorPool() { } } -Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { +Gfx::ODescriptorSet DescriptorPool::allocateDescriptorSet() { VkDescriptorSetLayout layoutHandle = layout->getHandle(); VkDescriptorSetVariableDescriptorCountAllocateInfo setCounts = { .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) { if (cachedHandles[setIndex] == nullptr) { - cachedHandles[setIndex] = new DescriptorSet(graphics, this); + cachedHandles[setIndex] = new DescriptorSetHandle(graphics, layout->getName()); } if (cachedHandles[setIndex]->isCurrentlyBound()) { // Currently in use, skip @@ -163,21 +165,19 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { } if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) { // 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 = { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, .pNext = nullptr, .objectType = VK_OBJECT_TYPE_DESCRIPTOR_SET, - .objectHandle = (uint64)cachedHandles[setIndex]->setHandle, + .objectHandle = (uint64)cachedHandles[setIndex]->getHandle(), .pObjectName = name.c_str(), }; vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo); } - PDescriptorSet vulkanSet = cachedHandles[setIndex]; - // Found set, stop searching - return vulkanSet; + return new DescriptorSet(graphics, this, cachedHandles[setIndex]); } if (nextAlloc == nullptr) { nextAlloc = new DescriptorPool(graphics, layout); @@ -198,8 +198,12 @@ void DescriptorPool::reset() { } } -DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) - : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics, owner->getLayout()->getName()), setHandle(VK_NULL_HANDLE), +DescriptorSetHandle::DescriptorSetHandle(PGraphics graphics, const std::string& name) : CommandBoundResource(graphics, name) {} + +DescriptorSetHandle::~DescriptorSetHandle() {} + +DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle) + : Gfx::DescriptorSet(owner->getLayout()), setHandle(setHandle), graphics(graphics), owner(owner) { boundResources.resize(owner->getLayout()->bindings.size()); 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{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -261,7 +265,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -288,7 +292,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -315,7 +319,7 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -343,7 +347,7 @@ void DescriptorSet::updateSampler(const std::string& mappingName, uint32 index, writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -371,7 +375,7 @@ void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -394,7 +398,7 @@ void DescriptorSet::updateAccelerationStructure(const std::string& mappingName, writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = &accelerationInfos.back(), - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = binding, .dstArrayElement = index, .descriptorCount = 1, @@ -429,7 +433,7 @@ void DescriptorSet::writeChanges() { writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, - .dstSet = setHandle, + .dstSet = setHandle->getHandle(), .dstBinding = 0, .dstArrayElement = 0, .descriptorCount = 1, @@ -439,9 +443,9 @@ void DescriptorSet::writeChanges() { } if (writeDescriptors.size() > 0) { - if (isCurrentlyBound()) { + if (setHandle->isCurrentlyBound()) { 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); writeDescriptors.clear(); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.h b/src/Engine/Graphics/Vulkan/Descriptor.h index b9ce938..9df1a2b 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.h +++ b/src/Engine/Graphics/Vulkan/Descriptor.h @@ -3,6 +3,7 @@ #include "Graphics/Descriptor.h" #include "Graphics/Vulkan/Buffer.h" #include "Resources.h" +#include namespace Seele { namespace Vulkan { @@ -32,12 +33,22 @@ class DescriptorLayout : public Gfx::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) class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource { public: DescriptorPool(PGraphics graphics, PDescriptorLayout layout); virtual ~DescriptorPool(); - virtual Gfx::PDescriptorSet allocateDescriptorSet() override; + virtual Gfx::ODescriptorSet allocateDescriptorSet() override; virtual void reset() override; constexpr VkDescriptorPool getHandle() const { return poolHandle; } @@ -47,15 +58,14 @@ class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource { PGraphics graphics; PDescriptorLayout layout; const static int maxSets = 64; - StaticArray cachedHandles; + StaticArray cachedHandles; VkDescriptorPool poolHandle; DescriptorPool* nextAlloc = nullptr; }; DEFINE_REF(DescriptorPool) - -class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { +class DescriptorSet : public Gfx::DescriptorSet { public: - DescriptorSet(PGraphics graphics, PDescriptorPool owner); + DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle); virtual ~DescriptorSet(); virtual void writeChanges() 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 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: std::vector constantData; @@ -81,7 +91,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { // would not work anyways, so casts should be safe // Array cachedData; Array> boundResources; - VkDescriptorSet setHandle; + PDescriptorSetHandle setHandle; PGraphics graphics; PDescriptorPool owner; friend class DescriptorPool; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 884fcfd..03f00af 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -186,7 +186,7 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { allocatedFramebuffers[framebufferHash] = new Framebuffer(this, rp, rp->getLayout()); framebuffer = allocatedFramebuffers[framebufferHash]; } else { - framebuffer = std::move(found->value); + framebuffer = found->value; } } getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer); diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index 1626787..fa871ad 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -14,7 +14,7 @@ Array Material::samplers; Gfx::OShaderBuffer Material::floatBuffer; Array Material::floatData; Gfx::ODescriptorLayout Material::layout; -Gfx::PDescriptorSet Material::set; +Gfx::ODescriptorSet Material::set; std::atomic_uint64_t Material::materialIdCounter = 0; Array Material::materials; diff --git a/src/Engine/Material/Material.h b/src/Engine/Material/Material.h index dbb7fa9..720f891 100644 --- a/src/Engine/Material/Material.h +++ b/src/Engine/Material/Material.h @@ -63,7 +63,7 @@ class Material { static Gfx::OShaderBuffer floatBuffer; static Array floatData; static Gfx::ODescriptorLayout layout; - static Gfx::PDescriptorSet set; + static Gfx::ODescriptorSet set; static std::atomic_uint64_t materialIdCounter; static Array materials; }; diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index 1bf9ace..1c5499f 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -5,7 +5,6 @@ #include #include - #define DEFINE_REF(x) \ typedef ::Seele::RefPtr P##x; \ typedef ::Seele::UniquePtr UP##x; \ @@ -26,10 +25,12 @@ } namespace Seele { +template class OwningPtr; template class RefPtr { public: constexpr RefPtr() noexcept : object(nullptr) {} constexpr RefPtr(std::nullptr_t) noexcept : object(nullptr) {} + constexpr RefPtr(OwningPtr&&) = delete; RefPtr(T* ptr) : object(ptr) {} constexpr RefPtr(const RefPtr& other) noexcept : object(other.object) {} constexpr RefPtr(RefPtr&& rhs) noexcept : object(std::move(rhs.object)) { rhs.object = nullptr; } @@ -49,6 +50,7 @@ template class RefPtr { } return RefPtr(f); } + constexpr RefPtr& operator=(OwningPtr&&) = delete; constexpr RefPtr& operator=(const RefPtr& other) { if (this != &other) { object = other.object; @@ -62,6 +64,10 @@ template class RefPtr { } return *this; } + constexpr RefPtr& operator=(std::nullptr_t) noexcept { + object = nullptr; + return *this; + } constexpr ~RefPtr() {} constexpr bool 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 class RefPtr { private: T* object; }; -template > class OwningPtr { +template class OwningPtr { public: OwningPtr() : pointer(nullptr) {} OwningPtr(T* ptr) : pointer(ptr) {} @@ -94,14 +100,18 @@ template > class OwningPtr OwningPtr& operator=(OwningPtr&& other) noexcept { if (this != &other) { if (pointer != nullptr) { - Deleter()(pointer); + std::default_delete d; + d(pointer); } pointer = other.pointer; other.pointer = nullptr; } return *this; } - ~OwningPtr() { Deleter()(pointer); } + ~OwningPtr() { + std::default_delete d; + d(pointer); + } constexpr operator RefPtr() { return RefPtr(pointer); } constexpr operator RefPtr() const { return RefPtr(pointer); } constexpr T* operator->() { return pointer; } diff --git a/src/Engine/Scene/LightEnvironment.h b/src/Engine/Scene/LightEnvironment.h index 4546063..a978145 100644 --- a/src/Engine/Scene/LightEnvironment.h +++ b/src/Engine/Scene/LightEnvironment.h @@ -41,7 +41,7 @@ class LightEnvironment { PEnvironmentMapAsset environment; Gfx::OSampler environmentSampler; Gfx::ODescriptorLayout layout; - Gfx::PDescriptorSet set; + Gfx::ODescriptorSet set; }; DEFINE_REF(LightEnvironment) } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index aad86e4..5872388 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -1,15 +1,11 @@ #include "GameView.h" -#include "Actor/CameraActor.h" #include "Asset/AssetRegistry.h" -#include "Component/KeyboardInput.h" #include "Graphics/Graphics.h" -#include "Graphics/Query.h" #include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/CachedDepthPass.h" #include "Graphics/RenderPass/DepthCullingPass.h" #include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/RayTracingPass.h" -#include "Graphics/RenderPass/RenderGraphResources.h" #include "Graphics/RenderPass/ToneMappingPass.h" #include "Graphics/RenderPass/VisibilityPass.h" #include "Graphics/RenderPass/ShadowPass.h" diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index 27a4011..173f8d3 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -31,7 +31,7 @@ class GameView : public View { RenderGraph renderGraph; RenderGraph rayTracingGraph; - PSystemGraph systemGraph; + OSystemGraph systemGraph; System::PKeyboardInput keyboardSystem; float updateTime = 0;