Changed descriptorset api
This commit is contained in:
1 parent
aa4b78586e
commit
6537459b77
34 files changed
+124
-102
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user