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
+1 -1
View File
@@ -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(); }
+2 -2
View File
@@ -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)
+3 -2
View File
@@ -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);
}
+6 -6
View File
@@ -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;
@@ -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;
};
@@ -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();
@@ -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;
@@ -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));
}
@@ -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;
@@ -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());
@@ -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
+1 -1
View File
@@ -38,7 +38,7 @@ class RenderGraph {
return res;
}
private:
PRenderGraphResources res;
ORenderGraphResources res;
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
//StaticArray<Vector4, 4> 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);
+1 -1
View File
@@ -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;
@@ -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,
};
+1 -1
View File
@@ -26,7 +26,7 @@ class ShadowPass : public RenderPass {
Array<Gfx::OTextureView> views;
Array<Matrix4> lightSpaceMatrices;
Gfx::OShaderBuffer lightSpaceBuffer;
Array<Gfx::PDescriptorSet> viewParams;
Array<Gfx::ODescriptorSet> viewParams;
};
StaticArray<Cascade, NUM_CASCADES> cascades;
Gfx::OUniformBuffer cascadeSplitsBuffer;
@@ -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();
@@ -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;
};
}
+3 -3
View File
@@ -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;
@@ -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
@@ -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;
+1 -1
View File
@@ -50,6 +50,6 @@ class StaticMeshVertexData : public VertexData {
Array<BiTangentType> bitData;
Array<ColorType> colData;
Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::ODescriptorSet descriptorSet;
};
} // namespace Seele
+1 -1
View File
@@ -158,7 +158,7 @@ class VertexData {
Array<Gfx::PBottomLevelAS> rayTracingScene;
Gfx::PDescriptorSet descriptorSet;
Gfx::ODescriptorSet descriptorSet;
uint64 idCounter;
uint64 head;
uint64 verticesAllocated;
+12 -12
View File
@@ -256,8 +256,8 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
assert(threadId == std::this_thread::get_id());
auto descriptorSet = descriptor.cast<DescriptorSet>();
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<Gfx::PDescriptorSet>& descriptorS
for (uint32 i = 0; i < descriptorSets.size(); ++i) {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
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<Gfx::PDescriptorSet>& 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<DescriptorSet>();
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<Gfx::PDescriptorSet>& descriptor
for (uint32 i = 0; i < descriptorSets.size(); ++i) {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
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<Gfx::PDescriptorSet>& descriptor
}
}
if (descriptorSet->constantsBuffer != nullptr) {
descriptorSet->bind();
descriptorSet->setHandle->bind();
boundResources.add(PBufferAllocation(descriptorSet->constantsBuffer));
}
sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle();
+26 -22
View File
@@ -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 <iostream>
#include "vulkan/vulkan_core.h"
#include <algorithm>
#include <iostream>
#include <mutex>
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();
+17 -7
View File
@@ -3,6 +3,7 @@
#include "Graphics/Descriptor.h"
#include "Graphics/Vulkan/Buffer.h"
#include "Resources.h"
#include <vulkan/vulkan_core.h>
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<ODescriptorSet, maxSets> cachedHandles;
StaticArray<ODescriptorSetHandle, maxSets> 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<uint8> constantData;
@@ -81,7 +91,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
// would not work anyways, so casts should be safe
// Array<void*> cachedData;
Array<Array<PCommandBoundResource>> boundResources;
VkDescriptorSet setHandle;
PDescriptorSetHandle setHandle;
PGraphics graphics;
PDescriptorPool owner;
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());
framebuffer = allocatedFramebuffers[framebufferHash];
} else {
framebuffer = std::move(found->value);
framebuffer = found->value;
}
}
getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer);