Merge branch 'SP3-1-Rendering' of https://github.com/SHADE-DP/SHADE_Y3 into SP3-1-Rendering

This commit is contained in:
Kah Wei 2022-09-22 12:39:10 +08:00
commit f28d966ebb
30 changed files with 229 additions and 146 deletions

View File

@ -20,23 +20,6 @@ namespace SHADE
} }
/***************************************************************************/
/*!
\brief
Links the write infos to the vulkan write descriptor sets.
*/
/***************************************************************************/
void SHDescriptorSetUpdater::LinkInfoToWriteDescSet(void) noexcept
{
for (uint32_t i = 0; i < writeInfos.size(); ++i)
{
writeDescSets[i].pImageInfo = writeInfos[i].descImageInfos.data();
writeDescSets[i].pBufferInfo = writeInfos[i].descBufferInfos.data();
writeDescSets[i].pTexelBufferView = writeInfos[i].descTexelBufferInfos.data();
}
}
SHDescriptorWriteInfo& SHDescriptorWriteInfo::operator=(SHDescriptorWriteInfo&& rhs) noexcept SHDescriptorWriteInfo& SHDescriptorWriteInfo::operator=(SHDescriptorWriteInfo&& rhs) noexcept
{ {
@ -65,11 +48,6 @@ namespace SHADE
} }
std::vector<vk::WriteDescriptorSet> const& SHDescriptorSetUpdater::GetWriteDescriptorSets(void) const noexcept
{
return writeDescSets;
}
SHDescriptorSetUpdater& SHDescriptorSetUpdater::operator=(SHDescriptorSetUpdater&& rhs) noexcept SHDescriptorSetUpdater& SHDescriptorSetUpdater::operator=(SHDescriptorSetUpdater&& rhs) noexcept
{ {
if (&rhs == this) if (&rhs == this)

View File

@ -41,10 +41,6 @@ namespace SHADE
//! When we want to update a write, we need to use this to identify the index of the write. //! When we want to update a write, we need to use this to identify the index of the write.
std::unordered_map<BindingAndSetHash, uint32_t> writeHashMap; std::unordered_map<BindingAndSetHash, uint32_t> writeHashMap;
//! We keep this here because we want this to be immediately passable to vkUpdateDescriptorSets
std::vector<vk::WriteDescriptorSet> writeDescSets;
void LinkInfoToWriteDescSet(void) noexcept;
public: public:
SHDescriptorSetUpdater (void) noexcept; SHDescriptorSetUpdater (void) noexcept;
@ -52,8 +48,6 @@ namespace SHADE
SHDescriptorSetUpdater& operator= (SHDescriptorSetUpdater&& rhs) noexcept; SHDescriptorSetUpdater& operator= (SHDescriptorSetUpdater&& rhs) noexcept;
public: public:
std::vector<vk::WriteDescriptorSet> const& GetWriteDescriptorSets (void) const noexcept;
friend class SHVkDescriptorSetGroup; friend class SHVkDescriptorSetGroup;
}; };
} }

View File

@ -50,9 +50,8 @@ namespace SHADE
return *this; return *this;
} }
std::vector<Handle<SHVkDescriptorSetGroup>> SHVkDescriptorPool::Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts) Handle<SHVkDescriptorSetGroup> SHVkDescriptorPool::Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts)
{ {
SHVkInstance::GetResourceManager().Create<SHVkDescriptorSetGroup>(device, GetHandle(), layouts, variableDescCounts); return SHVkInstance::GetResourceManager().Create<SHVkDescriptorSetGroup>(device, GetHandle(), layouts, variableDescCounts);
return {};
} }
} }

View File

@ -101,7 +101,7 @@ namespace SHADE
/// Handles to the created Descriptor Sets. If this DescriptorPool has run out of /// Handles to the created Descriptor Sets. If this DescriptorPool has run out of
/// space, lesser number of Handles will be returned. /// space, lesser number of Handles will be returned.
/// </returns> /// </returns>
std::vector<Handle<SHVkDescriptorSetGroup>> Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts); Handle<SHVkDescriptorSetGroup> Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts);
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -7,6 +7,11 @@
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h"
#include "Tools/SHLogger.h" #include "Tools/SHLogger.h"
#include "Graphics/Images/SHVkImage.h"
#include "Graphics/Images/SHVkImageView.h"
#include "Graphics/Images/SHVkSampler.h"
#include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/SHVkUtil.h"
namespace SHADE namespace SHADE
{ {
@ -39,6 +44,7 @@ namespace SHADE
: device{deviceHdl} : device{deviceHdl}
, descPool {pool} , descPool {pool}
, descSets{} , descSets{}
, layoutsUsed {layouts}
{ {
// Create the layout for each concurrent frame // Create the layout for each concurrent frame
std::vector<vk::DescriptorSetLayout> vkLayouts{ layouts.size() }; std::vector<vk::DescriptorSetLayout> vkLayouts{ layouts.size() };
@ -47,6 +53,7 @@ namespace SHADE
for (uint32_t i = 0; i < layouts.size(); ++i) for (uint32_t i = 0; i < layouts.size(); ++i)
{ {
vkLayouts[i] = layouts[i]->GetVkHandle(); vkLayouts[i] = layouts[i]->GetVkHandle();
setIndexing.emplace(layouts[i]->GetSetIndex(), i);
} }
// Check for variable descriptor count // Check for variable descriptor count
@ -73,34 +80,22 @@ namespace SHADE
// allocate descriptor sets // allocate descriptor sets
descSets = device->GetVkLogicalDevice().allocateDescriptorSets(DESC_SET_LAYOUT_CREATE_INFO); descSets = device->GetVkLogicalDevice().allocateDescriptorSets(DESC_SET_LAYOUT_CREATE_INFO);
// Now we want to prepare the write descriptor sets info for writing later.
// Now we want to prepare the write descriptor sets for writing later.
for (uint32_t i = 0; i < layouts.size(); ++i) for (uint32_t i = 0; i < layouts.size(); ++i)
{ {
auto const& bindings = layouts[i]->GetBindings(); auto const& bindings = layouts[i]->GetBindings();
for (auto& binding : bindings) for (auto& binding : bindings)
{ {
BindingAndSetHash writeHash = binding.BindPoint; BindingAndSetHash writeHash = binding.BindPoint;
writeHash |= static_cast<uint64_t>(i) << 32; writeHash |= static_cast<uint64_t>(layouts[i]->GetSetIndex()) << 32;
// new write for the binding // new write for the binding
updater.writeInfos.emplace_back(); updater.writeInfos.emplace_back();
updater.writeHashMap.try_emplace(writeHash, updater.writeInfos.size() - 1); updater.writeHashMap.try_emplace(writeHash, updater.writeInfos.size() - 1);
auto& writeInfo = updater.writeInfos.back(); auto& writeInfo = updater.writeInfos.back();
updater.writeDescSets.emplace_back();
auto& writeDescSet = updater.writeDescSets.back();
// Initialize info for write
writeDescSet.descriptorType = binding.Type;
writeDescSet.dstArrayElement = 0;
writeDescSet.dstSet = descSets[i];
writeDescSet.dstBinding = binding.BindPoint;
// Descriptor count for the write descriptor set. Usually this is set to 1, but if binding is variable sized, set to info passed in // Descriptor count for the write descriptor set. Usually this is set to 1, but if binding is variable sized, set to info passed in
uint32_t descriptorCount = (binding.flags & vk::DescriptorBindingFlagBits::eVariableDescriptorCount) ? variableDescCounts[i] : 1; uint32_t descriptorCount = (binding.flags & vk::DescriptorBindingFlagBits::eVariableDescriptorCount) ? variableDescCounts[i] : 1;
writeDescSet.descriptorCount = descriptorCount;
switch (binding.Type) switch (binding.Type)
{ {
@ -114,8 +109,10 @@ namespace SHADE
case vk::DescriptorType::eUniformTexelBuffer: case vk::DescriptorType::eUniformTexelBuffer:
case vk::DescriptorType::eStorageTexelBuffer: case vk::DescriptorType::eStorageTexelBuffer:
case vk::DescriptorType::eUniformBuffer: case vk::DescriptorType::eUniformBuffer:
case vk::DescriptorType::eUniformBufferDynamic:
case vk::DescriptorType::eStorageBuffer: case vk::DescriptorType::eStorageBuffer:
writeInfo.descImageInfos.resize (descriptorCount); case vk::DescriptorType::eStorageBufferDynamic:
writeInfo.descBufferInfos.resize (descriptorCount);
break; break;
//case vk::DescriptorType::eUniformBufferDynamic: //case vk::DescriptorType::eUniformBufferDynamic:
// break; // break;
@ -130,8 +127,6 @@ namespace SHADE
} }
} }
} }
// Link all the writeDescSet data for vkUpdateDescriptorSets to write to the linked descriptors
updater.LinkInfoToWriteDescSet();
} }
/***************************************************************************/ /***************************************************************************/
@ -160,7 +155,7 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHVkDescriptorSetGroup::ModifyWriteDescImage(uint32_t set, uint32_t binding, std::vector<std::pair<vk::ImageView, vk::Sampler>> const& imageViewsAndSamplers) noexcept void SHVkDescriptorSetGroup::ModifyWriteDescImage(uint32_t set, uint32_t binding, std::span<std::pair<Handle<SHVkImageView>, Handle<SHVkSampler>>> const& imageViewsAndSamplers) noexcept
{ {
// Find the target writeDescSet // Find the target writeDescSet
BindingAndSetHash writeHash = binding; BindingAndSetHash writeHash = binding;
@ -176,32 +171,81 @@ namespace SHADE
{ {
// write sampler and image view // write sampler and image view
auto& ivs = imageViewsAndSamplers[i]; auto& ivs = imageViewsAndSamplers[i];
writeInfo.descImageInfos[i].imageView = ivs.first; writeInfo.descImageInfos[i].imageView = ivs.first->GetImageView();
writeInfo.descImageInfos[i].sampler = ivs.second; writeInfo.descImageInfos[i].sampler = ivs.second->GetVkSampler();
} }
} }
void SHVkDescriptorSetGroup::ModifyWriteDescBuffer(uint32_t set, uint32_t binding, std::span<Handle<SHVkBuffer>> const& buffers) noexcept
void SHVkDescriptorSetGroup::UpdateDescriptorSet(void) noexcept
{ {
device->UpdateDescriptorSets(updater.GetWriteDescriptorSets()); // Find the target writeDescSet
BindingAndSetHash writeHash = binding;
writeHash |= static_cast<uint64_t>(set) << 32;
auto& writeInfo = updater.writeInfos[updater.writeHashMap.at(writeHash)];
if (buffers.size() > writeInfo.descBufferInfos.size())
{
SHLOG_ERROR("Attempting write too many descriptors into descriptor set. Failed to write to vk::WriteDescriptorSet. ");
} }
for (uint32_t i = 0; i < buffers.size(); ++i)
{
// write sampler and image view
auto& buffer = buffers[i];
writeInfo.descBufferInfos[i].buffer = buffer->GetVkBuffer();
}
void SHVkDescriptorSetGroup::UpdateSingleDescriptorSetImages(uint32_t set, uint32_t binding) noexcept }
void SHVkDescriptorSetGroup::UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept
{ {
vk::WriteDescriptorSet writeDescSet{}; vk::WriteDescriptorSet writeDescSet{};
// Get binding + set hash
BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding);
// to index a set
uint32_t setIndex = setIndexing[bsHash];
// to index a write for a binding
uint32_t writeInfoIndex = updater.writeHashMap[bsHash];
// Initialize info for write // Initialize info for write
writeDescSet.descriptorType = vk::DescriptorType::eCombinedImageSampler; writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type;
writeDescSet.dstArrayElement = 0; writeDescSet.dstArrayElement = 0;
writeDescSet.dstSet = descSets[set]; writeDescSet.dstSet = descSets[setIndex];
writeDescSet.dstBinding = binding; writeDescSet.dstBinding = binding;
writeDescSet.pImageInfo = updater.writeInfos[set].descImageInfos.data(); writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data();
writeDescSet.descriptorCount = static_cast<uint32_t>(updater.writeInfos[set].descImageInfos.size()); writeDescSet.descriptorCount = static_cast<uint32_t>(updater.writeInfos[writeInfoIndex].descImageInfos.size());
device->UpdateDescriptorSet(writeDescSet); device->UpdateDescriptorSet(writeDescSet);
} }
void SHVkDescriptorSetGroup::UpdateDescriptorSetBuffer(uint32_t set, uint32_t binding) noexcept
{
vk::WriteDescriptorSet writeDescSet{};
// Get binding + set hash
BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding);
// to index a set
uint32_t setIndex = setIndexing[bsHash];
// to index a write for a binding
uint32_t writeInfoIndex = updater.writeHashMap[bsHash];
// Initialize info for write
writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type;
writeDescSet.dstArrayElement = 0;
writeDescSet.dstSet = descSets[setIndex];
writeDescSet.dstBinding = binding;
writeDescSet.pBufferInfo = updater.writeInfos[writeInfoIndex].descBufferInfos.data();
writeDescSet.descriptorCount = static_cast<uint32_t>(updater.writeInfos[writeInfoIndex].descBufferInfos.size());
device->UpdateDescriptorSet(writeDescSet);
}
} }

View File

@ -14,6 +14,10 @@ namespace SHADE
class SHVkLogicalDevice; class SHVkLogicalDevice;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHVkDescriptorSetLayout; class SHVkDescriptorSetLayout;
class SHVkSampler;
class SHVkImage;
class SHVkImageView;
class SHVkBuffer;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -54,12 +58,14 @@ namespace SHADE
SHVkDescriptorSetGroup& operator=(SHVkDescriptorSetGroup&& rhs) noexcept = default; SHVkDescriptorSetGroup& operator=(SHVkDescriptorSetGroup&& rhs) noexcept = default;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Descriptor set writing */ /* Public member functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void ModifyWriteDescImage(uint32_t set, uint32_t binding, std::vector<std::pair<vk::ImageView, vk::Sampler>> const& imageViewsAndSamplers) noexcept; void UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept;
void UpdateDescriptorSet(void) noexcept; void UpdateDescriptorSetBuffer(uint32_t set, uint32_t binding) noexcept;
void ModifyWriteDescImage(uint32_t set, uint32_t binding, std::span<std::pair<Handle<SHVkImageView>, Handle<SHVkSampler>>> const& imageViewsAndSamplers) noexcept;
void ModifyWriteDescBuffer (uint32_t set, uint32_t binding, std::span<Handle<SHVkBuffer>> const& buffers) noexcept;
void UpdateSingleDescriptorSetImages(uint32_t set, uint32_t binding) noexcept;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Getter Functions */ /* Getter Functions */
@ -81,9 +87,17 @@ namespace SHADE
//! Descriptor pool to allocate descriptor sets //! Descriptor pool to allocate descriptor sets
Handle<SHVkDescriptorPool> descPool; Handle<SHVkDescriptorPool> descPool;
//! Sometimes when we pass in a layout, the set of the layout used in the
//! shader cannot be used to index into descSets. This is to mitigate that issue
//! when we update descriptor sets.
std::unordered_map<SetIndex, uint32_t> setIndexing;
//! Descriptor sets //! Descriptor sets
std::vector<vk::DescriptorSet> descSets; std::vector<vk::DescriptorSet> descSets;
//! Layouts used to create this descriptor set group
std::vector<Handle<SHVkDescriptorSetLayout>> layoutsUsed;
//! for updating descriptor sets. We want to cache this so that we don't create the //! for updating descriptor sets. We want to cache this so that we don't create the
//! write structs at runtime. //! write structs at runtime.
SHDescriptorSetUpdater updater; SHDescriptorSetUpdater updater;

View File

@ -7,9 +7,10 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructor/Destructor */ /* Constructor/Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, const std::vector<Binding>& bindings) SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, SetIndex set, const std::vector<Binding>& bindings)
: device { device } : device { device }
, layoutDesc { bindings } , layoutDesc { bindings }
, setIndex {set}
{ {
// Check if auto-binding point calculation configuration is valid // Check if auto-binding point calculation configuration is valid
bool autoCalc = false; bool autoCalc = false;
@ -74,6 +75,7 @@ namespace SHADE
: device {rhs.device} : device {rhs.device}
, setLayout {rhs.setLayout} , setLayout {rhs.setLayout}
, layoutDesc{std::move (rhs.layoutDesc)} , layoutDesc{std::move (rhs.layoutDesc)}
, setIndex {rhs.setIndex}
{ {
rhs.setLayout = VK_NULL_HANDLE; rhs.setLayout = VK_NULL_HANDLE;
} }
@ -90,6 +92,11 @@ namespace SHADE
return layoutDesc; return layoutDesc;
} }
SetIndex SHVkDescriptorSetLayout::GetSetIndex(void) const noexcept
{
return setIndex;
}
SHVkDescriptorSetLayout& SHVkDescriptorSetLayout::operator=(SHVkDescriptorSetLayout&& rhs) noexcept SHVkDescriptorSetLayout& SHVkDescriptorSetLayout::operator=(SHVkDescriptorSetLayout&& rhs) noexcept
{ {
if (&rhs == this) if (&rhs == this)
@ -98,6 +105,7 @@ namespace SHADE
device = rhs.device; device = rhs.device;
setLayout = rhs.setLayout; setLayout = rhs.setLayout;
layoutDesc = std::move(rhs.layoutDesc); layoutDesc = std::move(rhs.layoutDesc);
setIndex = rhs.setIndex;
rhs.setLayout = VK_NULL_HANDLE; rhs.setLayout = VK_NULL_HANDLE;

View File

@ -74,7 +74,7 @@ namespace SHADE
/// </summary> /// </summary>
/// <param name="device"></param> /// <param name="device"></param>
/// <param name="bindings"></param> /// <param name="bindings"></param>
SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, const std::vector<Binding>& bindings); SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, SetIndex setIndex, const std::vector<Binding>& bindings);
SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete; SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete;
SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept; SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept;
/// <summary> /// <summary>
@ -97,6 +97,7 @@ namespace SHADE
/// <returns>Handle to the Vulkan Descriptor Set Layout handle.</returns> /// <returns>Handle to the Vulkan Descriptor Set Layout handle.</returns>
inline const vk::DescriptorSetLayout& GetVkHandle() const { return setLayout; } inline const vk::DescriptorSetLayout& GetVkHandle() const { return setLayout; }
std::vector<Binding> const& GetBindings (void) const noexcept; std::vector<Binding> const& GetBindings (void) const noexcept;
SetIndex GetSetIndex (void) const noexcept;
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -105,5 +106,6 @@ namespace SHADE
Handle<SHVkLogicalDevice> device; Handle<SHVkLogicalDevice> device;
vk::DescriptorSetLayout setLayout; vk::DescriptorSetLayout setLayout;
std::vector<Binding> layoutDesc; // Stores description of the layout std::vector<Binding> layoutDesc; // Stores description of the layout
SetIndex setIndex; // Index of the set
}; };
} }

View File

@ -510,9 +510,9 @@ namespace SHADE
} }
Handle<SHVkDescriptorSetLayout> SHVkLogicalDevice::CreateDescriptorSetLayout(std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept Handle<SHVkDescriptorSetLayout> SHVkLogicalDevice::CreateDescriptorSetLayout(SetIndex setIndex, std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept
{ {
return SHVkInstance::GetResourceManager().Create <SHVkDescriptorSetLayout>(GetHandle(), bindings); return SHVkInstance::GetResourceManager().Create <SHVkDescriptorSetLayout>(GetHandle(), setIndex, bindings);
} }

View File

@ -182,7 +182,7 @@ namespace SHADE
Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::vector<SHVkSubpassParams> const& subpasses) noexcept; Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::vector<SHVkSubpassParams> const& subpasses) noexcept;
Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::span<vk::SubpassDescription> const spDescs, std::span<vk::SubpassDependency> const spDeps) noexcept; Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::span<vk::SubpassDescription> const spDescs, std::span<vk::SubpassDependency> const spDeps) noexcept;
Handle<SHVkFramebuffer> CreateFramebuffer (Handle<SHVkRenderpass> const& renderpassHdl, std::vector<Handle<SHVkImageView>> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept; Handle<SHVkFramebuffer> CreateFramebuffer (Handle<SHVkRenderpass> const& renderpassHdl, std::vector<Handle<SHVkImageView>> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept;
Handle<SHVkDescriptorSetLayout> CreateDescriptorSetLayout (std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept; Handle<SHVkDescriptorSetLayout> CreateDescriptorSetLayout (SetIndex setIndex, std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept;
Handle<SHVkDescriptorPool> CreateDescriptorPools (const SHVkDescriptorPool::Config& config = {}) noexcept; Handle<SHVkDescriptorPool> CreateDescriptorPools (const SHVkDescriptorPool::Config& config = {}) noexcept;
Handle<SHVkDescriptorSetGroup> CreateDescriptorSetGroup(Handle<SHVkDescriptorPool> pool, Handle<SHVkDescriptorSetGroup> CreateDescriptorSetGroup(Handle<SHVkDescriptorPool> pool,
std::vector<Handle<SHVkDescriptorSetLayout>> const& layouts, std::vector<Handle<SHVkDescriptorSetLayout>> const& layouts,

View File

@ -4,4 +4,9 @@
namespace SHADE namespace SHADE
{ {
vk::Sampler SHVkSampler::GetVkSampler(void) const noexcept
{
return vkSampler;
}
} }

View File

@ -22,6 +22,7 @@ namespace SHADE
SHVkSampler (SHVkSampler&& rhs) noexcept; SHVkSampler (SHVkSampler&& rhs) noexcept;
SHVkSampler&& operator=(SHVkSampler&& rhs) noexcept; SHVkSampler&& operator=(SHVkSampler&& rhs) noexcept;
vk::Sampler GetVkSampler (void) const noexcept;
}; };
} }

View File

@ -27,7 +27,7 @@ namespace SHADE
}; };
// For global data (generic data and textures) // For global data (generic data and textures)
Handle<SHVkDescriptorSetLayout> staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ genericDataBinding, texturesBinding }); Handle<SHVkDescriptorSetLayout> staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,{ genericDataBinding, texturesBinding });
SHVkDescriptorSetLayout::Binding lightBinding SHVkDescriptorSetLayout::Binding lightBinding
{ {
@ -38,7 +38,7 @@ namespace SHADE
}; };
// For Dynamic global data (lights) // For Dynamic global data (lights)
Handle<SHVkDescriptorSetLayout> dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ lightBinding }); Handle<SHVkDescriptorSetLayout> dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, { lightBinding });
SHVkDescriptorSetLayout::Binding cameraDataBinding SHVkDescriptorSetLayout::Binding cameraDataBinding
{ {
@ -49,7 +49,7 @@ namespace SHADE
}; };
// For High frequency global data (camera) // For High frequency global data (camera)
Handle<SHVkDescriptorSetLayout> cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ cameraDataBinding }); Handle<SHVkDescriptorSetLayout> cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, { cameraDataBinding });
SHVkDescriptorSetLayout::Binding materialDataBinding SHVkDescriptorSetLayout::Binding materialDataBinding
{ {
@ -60,7 +60,7 @@ namespace SHADE
}; };
// For High frequency global data (camera) // For High frequency global data (camera)
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding });
globalDescSetLayouts.push_back(staticGlobalLayout); globalDescSetLayouts.push_back(staticGlobalLayout);
globalDescSetLayouts.push_back(dynamicGlobalLayout); globalDescSetLayouts.push_back(dynamicGlobalLayout);

View File

@ -29,6 +29,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h"
#include "SHGraphicsConstants.h" #include "SHGraphicsConstants.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
#include "Graphics/Buffers/SHVkBuffer.h"
namespace SHADE namespace SHADE
{ {
@ -129,7 +130,7 @@ namespace SHADE
} }
// Initialize world render graph // Initialize world render graph
worldRenderGraph->Init(device, swapchain, renderContextCmdPools, globalData); worldRenderGraph->Init(device, swapchain, globalData);
//worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
//worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
//worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
@ -167,7 +168,7 @@ namespace SHADE
debugWorldRenderer->SetCamera(worldCamera);*/ debugWorldRenderer->SetCamera(worldCamera);*/
// Add world renderer to default viewport // Add world renderer to default viewport
worldRenderer = defaultViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), descPool, globalData->GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph); worldRenderer = defaultViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, globalData->GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph);
worldRenderer->SetCamera(worldCamera); worldRenderer->SetCamera(worldCamera);
@ -203,6 +204,7 @@ namespace SHADE
{ {
// Frame data for the current frame // Frame data for the current frame
auto const& frameData = renderContext.GetCurrentFrameData(); auto const& frameData = renderContext.GetCurrentFrameData();
uint32_t frameIndex = renderContext.GetCurrentFrame();
// semaphore index. This is for render graphs to have semaphores to signal that the next render graph will use to wait on. // semaphore index. This is for render graphs to have semaphores to signal that the next render graph will use to wait on.
bool semIndex = 0; bool semIndex = 0;
@ -228,16 +230,40 @@ namespace SHADE
// For every renderer // For every renderer
for (int renIndex = 0; renIndex < static_cast<int>(renderers.size()); ++renIndex) for (int renIndex = 0; renIndex < static_cast<int>(renderers.size()); ++renIndex)
{ {
// Draw first /*-----------------------------------------------------------------------*/
renderers[renIndex]->Draw(renderContext.GetCurrentFrame(), MESH_DATA); /* Renderer start */
/*-----------------------------------------------------------------------*/
// get command buffer of the renderer in the current frame
auto currentCmdBuffer = renderers[renIndex]->GetCommandBuffer(frameIndex);
// get render graph // Begin recording the command buffer
auto rg = renderers[renIndex]->GetRenderGraph(); currentCmdBuffer->BeginRecording();
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
currentCmdBuffer->BindIndexBuffer(buffer, 0);
}
// bind camera data
renderers[renIndex]->BindDescriptorSet(currentCmdBuffer, frameIndex);
// Draw first
renderers[renIndex]->Draw(frameIndex);
// End the command buffer recording
currentCmdBuffer->EndRecording();
/*-----------------------------------------------------------------------*/
/* Renderer end */
/*-----------------------------------------------------------------------*/
// submit a command buffer from the current render graph and make it wait for the previous render graph before submitting it to GPU. // submit a command buffer from the current render graph and make it wait for the previous render graph before submitting it to GPU.
graphicsQueue->SubmitCommandBuffer graphicsQueue->SubmitCommandBuffer
( (
{ rg->GetCommandBuffer(renderContext.GetCurrentFrame()) }, { currentCmdBuffer },
{ (vpIndex == viewports.size() - 1 && renIndex == renderers.size() - 1) ? frameData.semRenderFinishHdl : graphSemaphores[!semIndex] }, { (vpIndex == viewports.size() - 1 && renIndex == renderers.size() - 1) ? frameData.semRenderFinishHdl : graphSemaphores[!semIndex] },
{ (vpIndex == 0 && renIndex == 0) ? frameData.semImgAvailableHdl : graphSemaphores[semIndex] }, { (vpIndex == 0 && renIndex == 0) ? frameData.semImgAvailableHdl : graphSemaphores[semIndex] },
{ vk::PipelineStageFlagBits::eColorAttachmentOutput }, { vk::PipelineStageFlagBits::eColorAttachmentOutput },

View File

@ -20,20 +20,34 @@ of DigiPen Institute of Technology is prohibited.
#include "SHMaterial.h" #include "SHMaterial.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Graphics/Buffers/SHVkBuffer.h"
namespace SHADE namespace SHADE
{ {
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Constructor/Destructors */ /* Constructor/Destructors */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHRenderer::SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph) SHRenderer::SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph)
: viewport { viewport } : viewport { viewport }
, renderGraph { renderGraph } , renderGraph { renderGraph }
{ {
cameraDescriptorSet = logicalDevice->CreateDescriptorSetGroup(descriptorPool, { cameraDescLayout }, { 1 }); commandBuffers.resize(static_cast<std::size_t>(numFrames));
for (uint32_t i = 0; i < commandBuffers.size(); ++i)
commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
cameraDescriptorSet = descriptorPool->Allocate({ cameraDescLayout }, { 1 });
cpuCameraData.resize(numFrames); cpuCameraData.resize(numFrames);
cameraDataAlignedSize = logicalDevice->PadUBOSize(sizeof(SHShaderCameraData)); cameraDataAlignedSize = logicalDevice->PadUBOSize(sizeof(SHShaderCameraData));
cameraBuffer = logicalDevice->CreateBuffer(cameraDataAlignedSize * numFrames, nullptr, cameraDataAlignedSize * numFrames, vk::BufferUsageFlagBits::eUniformBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
std::array cameraBufferArray{cameraBuffer};
cameraDescriptorSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, std::span<Handle<SHVkBuffer>>{ cameraBufferArray.data(), cameraBufferArray.size()});
cameraDescriptorSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -47,9 +61,9 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Drawing Functions */ /* Drawing Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHRenderer::Draw(uint32_t frameIndex, std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> graphScopeBuffers) noexcept void SHRenderer::Draw(uint32_t frameIndex) noexcept
{ {
renderGraph->Execute(frameIndex, graphScopeBuffers); renderGraph->Execute(frameIndex, commandBuffers[frameIndex]);
} }
void SHRenderer::BindDescriptorSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept void SHRenderer::BindDescriptorSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
@ -64,4 +78,9 @@ namespace SHADE
return renderGraph; return renderGraph;
} }
Handle<SHVkCommandBuffer> SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept
{
return commandBuffers[frameIndex];
}
} }

View File

@ -39,6 +39,7 @@ namespace SHADE
class SHVkDescriptorSetGroup; class SHVkDescriptorSetGroup;
class SHGraphicsGlobalData; class SHGraphicsGlobalData;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHVkBuffer;
struct SHShaderCameraData struct SHShaderCameraData
{ {
@ -63,7 +64,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Constructor/Destructors */ /* Constructor/Destructors */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph); SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Camera Registration */ /* Camera Registration */
@ -73,13 +74,14 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Drawing Functions */ /* Drawing Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void Draw(uint32_t frameIndex, std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> graphScopeBuffers) noexcept; void Draw(uint32_t frameIndex) noexcept;
void BindDescriptorSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept; void BindDescriptorSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Setters and Getters */ /* Setters and Getters */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<SHRenderGraph> GetRenderGraph (void) const noexcept; Handle<SHRenderGraph> GetRenderGraph (void) const noexcept;
Handle<SHVkCommandBuffer> GetCommandBuffer(uint32_t frameIndex) const noexcept;
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -92,7 +94,13 @@ namespace SHADE
Handle<SHCamera> camera; Handle<SHCamera> camera;
Handle<SHRenderGraph> renderGraph; Handle<SHRenderGraph> renderGraph;
Handle<SHVkDescriptorSetGroup> cameraDescriptorSet; Handle<SHVkDescriptorSetGroup> cameraDescriptorSet;
Handle<SHVkBuffer> cameraBuffer;
std::vector<SHShaderCameraData> cpuCameraData; std::vector<SHShaderCameraData> cpuCameraData;
//! Command buffers for the render graph
std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
}; };
} }

View File

@ -49,10 +49,10 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Renderer Registration Functions */ /* Renderer Registration Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Handle<SHRenderer> SHViewport::AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph) Handle<SHRenderer> SHViewport::AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph)
{ {
// Create the renderer // Create the renderer
auto renderer = resourceManager.Create<SHRenderer>(device, numFrames, descriptorPool, cameraDescLayout, GetHandle(), renderGraph); auto renderer = resourceManager.Create<SHRenderer>(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph);
// Store // Store
renderers.emplace_back(renderer); renderers.emplace_back(renderer);

View File

@ -32,6 +32,7 @@ namespace SHADE
class SHRenderGraph; class SHRenderGraph;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHVkDescriptorSetLayout; class SHVkDescriptorSetLayout;
class SHVkCommandPool;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */
@ -58,7 +59,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Renderers Registration Functions */ /* Renderers Registration Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<SHRenderer> AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph); Handle<SHRenderer> AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph);
void RemoveRenderer(Handle<SHRenderer> renderer); void RemoveRenderer(Handle<SHRenderer> renderer);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -98,7 +98,7 @@ namespace SHADE
} }
// Build Descriptor // Build Descriptor
Handle<SHVkDescriptorSetGroup> descSetGroup = descPool->Allocate({ descLayout }, { 1 }).front(); Handle<SHVkDescriptorSetGroup> descSetGroup = descPool->Allocate({ descLayout }, { 1 });
isDirty = false; isDirty = false;

View File

@ -198,7 +198,7 @@ namespace SHADE
// 1 descriptor set layout for every descriptor set detected. // 1 descriptor set layout for every descriptor set detected.
for (auto const& set : setsWithBindings) for (auto const& set : setsWithBindings)
{ {
auto newDescriptorSetLayout = logicalDeviceHdl->CreateDescriptorSetLayout(set.second); auto newDescriptorSetLayout = logicalDeviceHdl->CreateDescriptorSetLayout(set.first, set.second);
descriptorSetLayoutsAllocate.push_back(newDescriptorSetLayout); descriptorSetLayoutsAllocate.push_back(newDescriptorSetLayout);
} }

View File

@ -946,25 +946,6 @@ namespace SHADE
} }
} }
/***************************************************************************/
/*!
\brief
Configures command pools and command buffers.
*/
/***************************************************************************/
void SHRenderGraph::ConfigureCommands(void) noexcept
{
//commandPools.resize (static_cast<std::size_t>(swapchainHdl->GetNumImages()));
commandBuffers.resize(static_cast<std::size_t>(swapchainHdl->GetNumImages()));
for (uint32_t i = 0; i < commandBuffers.size(); ++i)
{
commandBuffers[i] = commandPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
}
}
/***************************************************************************/ /***************************************************************************/
/*! /*!
@ -980,12 +961,11 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHRenderGraph::Init(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHVkCommandPool>> const& cmdPools, Handle<SHGraphicsGlobalData> inGlobalData) noexcept void SHRenderGraph::Init(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, Handle<SHGraphicsGlobalData> inGlobalData) noexcept
{ {
logicalDeviceHdl = logicalDevice; logicalDeviceHdl = logicalDevice;
swapchainHdl = swapchain; swapchainHdl = swapchain;
globalData = inGlobalData; globalData = inGlobalData;
commandPools = cmdPools;
} }
/***************************************************************************/ /***************************************************************************/
@ -1087,33 +1067,17 @@ namespace SHADE
ConfigureSubpasses(); ConfigureSubpasses();
ConfigureRenderpasses(); ConfigureRenderpasses();
ConfigureFramebuffers(); ConfigureFramebuffers();
ConfigureCommands();
} }
// TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a // TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a
// better way to manage these // better way to manage these
void SHRenderGraph::Execute(uint32_t frameIndex, std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> graphScopeBuffers) noexcept void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkCommandBuffer> cmdBuffer) noexcept
{ {
//commandPools[frameIndex]->Reset();
auto& cmdBuffer = commandBuffers[frameIndex];
cmdBuffer->BeginRecording();
// TODO: DON'T HARDCODE THIS // TODO: DON'T HARDCODE THIS
cmdBuffer->SetViewportScissor(1920.0f, 1080.0f, 1920, 1080); cmdBuffer->SetViewportScissor(1920.0f, 1080.0f, 1920, 1080);
for (auto& [buffer, bindingPoint]: graphScopeBuffers)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
cmdBuffer->BindIndexBuffer(buffer, 0);
}
for (auto& node : nodes) for (auto& node : nodes)
node->Execute(cmdBuffer, frameIndex); node->Execute(cmdBuffer, frameIndex);
cmdBuffer->EndRecording();
} }
void SHRenderGraph::FinaliseBatch() void SHRenderGraph::FinaliseBatch()
@ -1132,9 +1096,5 @@ namespace SHADE
return {}; return {};
} }
Handle<SHVkCommandBuffer> const& SHRenderGraph::GetCommandBuffer(uint32_t frameIndex) const noexcept
{
return commandBuffers[frameIndex];
}
} }

View File

@ -250,7 +250,6 @@ namespace SHADE
void ConfigureSubpasses (void) noexcept; void ConfigureSubpasses (void) noexcept;
void ConfigureRenderpasses (void) noexcept; void ConfigureRenderpasses (void) noexcept;
void ConfigureFramebuffers (void) noexcept; void ConfigureFramebuffers (void) noexcept;
void ConfigureCommands (void) noexcept;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* PRIVATE MEMBER VARIABLES */ /* PRIVATE MEMBER VARIABLES */
@ -272,12 +271,6 @@ namespace SHADE
//! Resource library for graph handles //! Resource library for graph handles
ResourceManager resourceManager; ResourceManager resourceManager;
//! Command pool for the render graph. DO NOT RESET OR FREE THESE, THEY ARE NON-OWNING. TODO: If application is multithreaded, we need more pools.
std::vector<Handle<SHVkCommandPool>> commandPools;
//! Command buffers for the render graph
std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
//! Handle to global data //! Handle to global data
Handle<SHGraphicsGlobalData> globalData; Handle<SHGraphicsGlobalData> globalData;
@ -290,18 +283,17 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */ /* PUBLIC MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
void Init (Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHVkCommandPool>> const& cmdPools, Handle<SHGraphicsGlobalData> inGlobalData) noexcept; void Init (Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, Handle<SHGraphicsGlobalData> inGlobalData) noexcept;
void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {}); void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {});
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<std::string> resourceNames, std::initializer_list<std::string> predecessorNodes) noexcept; Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<std::string> resourceNames, std::initializer_list<std::string> predecessorNodes) noexcept;
void Generate (void) noexcept; void Generate (void) noexcept;
void Execute (uint32_t frameIndex, std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> graphScopeBuffers) noexcept; void Execute (uint32_t frameIndex, Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
void FinaliseBatch(); void FinaliseBatch();
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */ /* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
Handle<SHRenderGraphNode> GetNode (std::string const& nodeName) const noexcept; Handle<SHRenderGraphNode> GetNode (std::string const& nodeName) const noexcept;
Handle<SHVkCommandBuffer> const& GetCommandBuffer (uint32_t frameIndex) const noexcept;
}; };
} }

View File

@ -71,4 +71,14 @@ namespace SHADE
); );
} }
} }
BindingAndSetHash SHVkUtil::GenBindingSetHash(uint32_t set, uint32_t binding) noexcept
{
// Find the target writeDescSet
BindingAndSetHash writeHash = binding;
writeHash |= static_cast<uint64_t>(set) << 32;
return writeHash;
}
} }

View File

@ -76,6 +76,8 @@ namespace SHADE
*/ */
/***********************************************************************************/ /***********************************************************************************/
static void EnsureBufferAndCopyHostVisibleData(Handle<SHVkLogicalDevice> device, Handle<SHVkBuffer>& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage); static void EnsureBufferAndCopyHostVisibleData(Handle<SHVkLogicalDevice> device, Handle<SHVkBuffer>& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage);
static BindingAndSetHash GenBindingSetHash (uint32_t set, uint32_t binding) noexcept;
}; };
} }

View File

@ -6,6 +6,8 @@
namespace SHADE namespace SHADE
{ {
using SHQueueFamilyIndex = uint32_t; using SHQueueFamilyIndex = uint32_t;
using BindingAndSetHash = uint64_t;
using SetIndex = uint32_t;
} }

View File

@ -6,5 +6,6 @@
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#define VULKAN_HPP_NO_NODISCARD_WARNINGS #define VULKAN_HPP_NO_NODISCARD_WARNINGS
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "Graphics/SHVulkanDefines.h"
#endif #endif

View File

@ -9,8 +9,6 @@
namespace SHADE namespace SHADE
{ {
using BindingAndSetHash = uint64_t;
struct SHShaderDescriptorBindingInfo struct SHShaderDescriptorBindingInfo
{ {
private: private:

View File

@ -0,0 +1,11 @@
#define SET_STATIC_GLOBALS 0
#define SET_DYNAMIC_GLOBALS 1
#define SET_HIGH_FREQUENCY_GLOBALS 2
#define BINDING_GENERIC_DATA 0
#define BINDING_IMAGE_AND_SAMPLERS_DATA 1
#define BINDING_LIGHTS_DATA 0
#define BINDING_CAMERA_DATA 0
#define BINDING_BATCHED_PER_INST_DATA 0

View File

@ -1,6 +1,8 @@
#version 450 #version 450
#extension GL_KHR_vulkan_glsl : enable #extension GL_KHR_vulkan_glsl : enable
//#include "ShaderDescriptorDefinitions.glsl"
layout(location = 0) in vec3 aVertexPos; layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in vec2 aUV; layout(location = 1) in vec2 aUV;
layout(location = 2) in vec3 aNormal; layout(location = 2) in vec3 aNormal;
@ -28,6 +30,12 @@ layout(location = 0) out struct
} Out; } Out;
layout(set = 2, binding = 0) uniform CameraData
{
vec4 position;
mat4 vpMat;
} cameraData;
void main() void main()
{ {
//const float gamma = testPushConstant.eyePosition.w; //const float gamma = testPushConstant.eyePosition.w;

Binary file not shown.