Renamed SHGraphicsGlobalData to SHPredefinedData

- SHPredefinedData now contains the font data descriptor set layout as well 
- Added a function for SHPredefinedData to retrieve descriptor sets based on a bitfield
- Modified descriptor sets to not be tied to a set index anymore
- Descriptor set layout doesn't have a set anymore
- Removed desc set index constants from SHGraphicsConstants since they aren't really needed anymore
This commit is contained in:
Brandon Mak 2022-12-25 14:32:50 +08:00
parent dfa9facfe0
commit b035582b30
27 changed files with 483 additions and 405 deletions

View File

@ -53,7 +53,6 @@ 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
@ -87,7 +86,7 @@ namespace SHADE
for (auto& binding : bindings) for (auto& binding : bindings)
{ {
BindingAndSetHash writeHash = binding.BindPoint; BindingAndSetHash writeHash = binding.BindPoint;
writeHash |= static_cast<uint64_t>(layouts[i]->GetSetIndex()) << 32; writeHash |= static_cast<uint64_t>(i) << 32;
// new write for the binding // new write for the binding
updater.writeInfos.emplace_back(); updater.writeInfos.emplace_back();
@ -208,16 +207,13 @@ namespace SHADE
// Get binding + set hash // Get binding + set hash
BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding);
// to index a set
uint32_t setIndex = setIndexing[set];
// to index a write for a binding // to index a write for a binding
uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; uint32_t writeInfoIndex = updater.writeHashMap[bsHash];
// Initialize info for write // Initialize info for write
writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type; writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type;
writeDescSet.dstArrayElement = 0; writeDescSet.dstArrayElement = 0;
writeDescSet.dstSet = descSets[setIndex]; writeDescSet.dstSet = descSets[set];
writeDescSet.dstBinding = binding; writeDescSet.dstBinding = binding;
writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data(); writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data();
@ -233,16 +229,13 @@ namespace SHADE
// Get binding + set hash // Get binding + set hash
BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding);
// to index a set
uint32_t setIndex = setIndexing[set];
// to index a write for a binding // to index a write for a binding
uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; uint32_t writeInfoIndex = updater.writeHashMap[bsHash];
// Initialize info for write // Initialize info for write
writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type; writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type;
writeDescSet.dstArrayElement = 0; writeDescSet.dstArrayElement = 0;
writeDescSet.dstSet = descSets[setIndex]; writeDescSet.dstSet = descSets[set];
writeDescSet.dstBinding = binding; writeDescSet.dstBinding = binding;
writeDescSet.pBufferInfo = updater.writeInfos[writeInfoIndex].descBufferInfos.data(); writeDescSet.pBufferInfo = updater.writeInfos[writeInfoIndex].descBufferInfos.data();

View File

@ -21,7 +21,6 @@ namespace SHADE
class SHVkImageView; class SHVkImageView;
class SHVkBuffer; class SHVkBuffer;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -91,10 +90,10 @@ 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 ////! 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 ////! shader cannot be used to index into descSets. This is to mitigate that issue
//! when we update descriptor sets. ////! when we update descriptor sets.
std::unordered_map<SetIndex, uint32_t> setIndexing; //std::unordered_map<SetIndex, uint32_t> setIndexing;
//! Descriptor sets //! Descriptor sets
std::vector<vk::DescriptorSet> descSets; std::vector<vk::DescriptorSet> descSets;

View File

@ -8,10 +8,9 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructor/Destructor */ /* Constructor/Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, SetIndex set, const std::vector<Binding>& bindings, bool genImmutableSamplers/* = false*/) SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, const std::vector<Binding>& bindings, bool genImmutableSamplers/* = false*/)
: device{ device } : device{ device }
, layoutDesc{ bindings } , layoutDesc{ bindings }
, setIndex {set}
, immutableSampler{} , immutableSampler{}
{ {
// Check if auto-binding point calculation configuration is valid // Check if auto-binding point calculation configuration is valid
@ -96,7 +95,6 @@ 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 }
, immutableSampler{ rhs.immutableSampler } , immutableSampler{ rhs.immutableSampler }
{ {
rhs.setLayout = VK_NULL_HANDLE; rhs.setLayout = VK_NULL_HANDLE;
@ -114,11 +112,6 @@ namespace SHADE
return layoutDesc; return layoutDesc;
} }
SetIndex SHVkDescriptorSetLayout::GetSetIndex(void) const noexcept
{
return setIndex;
}
uint32_t SHVkDescriptorSetLayout::GetNumDynamicOffsetsRequired(void) const noexcept uint32_t SHVkDescriptorSetLayout::GetNumDynamicOffsetsRequired(void) const noexcept
{ {
uint32_t numDynamicBindings = 0; uint32_t numDynamicBindings = 0;
@ -139,7 +132,6 @@ 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;
immutableSampler = rhs.immutableSampler; immutableSampler = rhs.immutableSampler;
rhs.setLayout = VK_NULL_HANDLE; rhs.setLayout = VK_NULL_HANDLE;

View File

@ -75,7 +75,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, SetIndex setIndex, const std::vector<Binding>& bindings, bool genImmutableSamplers = false); SHVkDescriptorSetLayout(Handle<SHVkLogicalDevice> device, const std::vector<Binding>& bindings, bool genImmutableSamplers = false);
SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete; SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete;
SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept; SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept;
/// <summary> /// <summary>
@ -98,7 +98,6 @@ 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;
uint32_t GetNumDynamicOffsetsRequired(void) const noexcept; uint32_t GetNumDynamicOffsetsRequired(void) const noexcept;
private: private:
@ -108,7 +107,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
Handle<SHVkSampler> immutableSampler; Handle<SHVkSampler> immutableSampler;
}; };
} }

View File

@ -561,9 +561,9 @@ namespace SHADE
} }
Handle<SHVkDescriptorSetLayout> SHVkLogicalDevice::CreateDescriptorSetLayout(SetIndex setIndex, std::vector<SHVkDescriptorSetLayout::Binding> const& bindings, bool genImmutableSamplers/* = false*/) noexcept Handle<SHVkDescriptorSetLayout> SHVkLogicalDevice::CreateDescriptorSetLayout(std::vector<SHVkDescriptorSetLayout::Binding> const& bindings, bool genImmutableSamplers/* = false*/) noexcept
{ {
return SHVkInstance::GetResourceManager().Create <SHVkDescriptorSetLayout>(GetHandle(), setIndex, bindings, genImmutableSamplers); return SHVkInstance::GetResourceManager().Create <SHVkDescriptorSetLayout>(GetHandle(), bindings, genImmutableSamplers);
} }
Handle<SHVkDescriptorPool> SHVkLogicalDevice::CreateDescriptorPools(const SHVkDescriptorPool::Config& config /*= {}*/) noexcept Handle<SHVkDescriptorPool> SHVkLogicalDevice::CreateDescriptorPools(const SHVkDescriptorPool::Config& config /*= {}*/) noexcept

View File

@ -190,7 +190,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 (SetIndex setIndex, std::vector<SHVkDescriptorSetLayout::Binding> const& bindings, bool genImmutableSamplers = false) noexcept; Handle<SHVkDescriptorSetLayout> CreateDescriptorSetLayout (std::vector<SHVkDescriptorSetLayout::Binding> const& bindings, bool genImmutableSamplers = false) 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

@ -25,7 +25,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHComponentManager.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
#include "UI/SHUIComponent.h" #include "UI/SHUIComponent.h"
@ -607,7 +607,7 @@ namespace SHADE
{ {
matPropsDescSet[frameIndex] = descPool->Allocate matPropsDescSet[frameIndex] = descPool->Allocate
( (
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] }, { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] },
{ 0 } { 0 }
); );
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -1,30 +1,24 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHGraphicsGlobalData.h" #include "SHPredefinedData.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/Pipeline/SHPipelineState.h"
#include "Graphics/Pipeline/SHVkPipelineLayout.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h"
#include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h"
#include "Graphics/MiddleEnd/Lights/SHLightData.h" #include "Graphics/MiddleEnd/Lights/SHLightData.h"
#include "Tools/Utilities/SHUtilities.h"
namespace SHADE namespace SHADE
{ {
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Static Definitions */ /* Static Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
std::vector<Handle<SHVkDescriptorSetLayout>> SHGraphicsGlobalData::globalDescSetLayouts; std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::predefinedLayouts;
SHVertexInputState SHGraphicsGlobalData::defaultVertexInputState; SHVertexInputState SHPredefinedData::defaultVertexInputState;
Handle<SHVkPipelineLayout> SHGraphicsGlobalData::dummyPipelineLayout; Handle<SHVkPipelineLayout> SHPredefinedData::dummyPipelineLayout;
void SHGraphicsGlobalData::InitHighFrequencyGlobalData(void) noexcept
{
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Function Definitions */ /* Function Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHGraphicsGlobalData::InitDescSetLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept void SHPredefinedData::InitDescSetLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept
{ {
SHVkDescriptorSetLayout::Binding genericDataBinding SHVkDescriptorSetLayout::Binding genericDataBinding
{ {
@ -44,7 +38,7 @@ namespace SHADE
}; };
// For global data (generic data and textures) // For global data (generic data and textures)
Handle<SHVkDescriptorSetLayout> staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, { genericDataBinding, texturesBinding }); Handle<SHVkDescriptorSetLayout> staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ genericDataBinding, texturesBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, staticGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] Static Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, staticGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] Static Globals");
@ -72,8 +66,8 @@ namespace SHADE
} }
// For Dynamic global data (lights) // For Dynamic global data (lights)
Handle<SHVkDescriptorSetLayout> dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, lightBindings); Handle<SHVkDescriptorSetLayout> lightDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(lightBindings);
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, dynamicGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] Dynamic Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, lightDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Dynamic Globals");
// For High frequency global data (camera) // For High frequency global data (camera)
SHVkDescriptorSetLayout::Binding cameraDataBinding SHVkDescriptorSetLayout::Binding cameraDataBinding
@ -83,7 +77,7 @@ namespace SHADE
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA,
.DescriptorCount = 1, .DescriptorCount = 1,
}; };
Handle<SHVkDescriptorSetLayout> cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, { cameraDataBinding }); Handle<SHVkDescriptorSetLayout> cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ cameraDataBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, cameraDataGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] High Frequency Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, cameraDataGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] High Frequency Globals");
// For per instance data (transforms, materials, etc.) // For per instance data (transforms, materials, etc.)
@ -94,21 +88,41 @@ namespace SHADE
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
.DescriptorCount = 1, .DescriptorCount = 1,
}; };
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding }); Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals");
// font bitmap data (texture)
SHVkDescriptorSetLayout::Binding fontBitmapBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
.DescriptorCount = 1,
};
// font data in the form of matrices
SHVkDescriptorSetLayout::Binding fontMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
.DescriptorCount = 1,
};
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
globalDescSetLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(staticGlobalLayout);
globalDescSetLayouts.push_back(dynamicGlobalLayout); predefinedLayouts.push_back(lightDataDescSetLayout);
globalDescSetLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(cameraDataGlobalLayout);
globalDescSetLayouts.push_back(materialDataPerInstanceLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout);
predefinedLayouts.push_back(fontDataDescSetLayout);
dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{predefinedLayouts});
dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{globalDescSetLayouts});
} }
void SHGraphicsGlobalData::InitDefaultVertexInputState(void) noexcept void SHPredefinedData::InitDefaultVertexInputState(void) noexcept
{ {
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1
@ -118,24 +132,31 @@ namespace SHADE
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8
} }
void SHGraphicsGlobalData::Init(Handle<SHVkLogicalDevice> logicalDevice) noexcept void SHPredefinedData::Init(Handle<SHVkLogicalDevice> logicalDevice) noexcept
{ {
InitDescSetLayouts(logicalDevice); InitDescSetLayouts(logicalDevice);
InitDefaultVertexInputState(); InitDefaultVertexInputState();
} }
std::vector<Handle<SHVkDescriptorSetLayout>> const& SHGraphicsGlobalData::GetDescSetLayouts(void) noexcept std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept
{ {
return globalDescSetLayouts; std::vector<Handle<SHVkDescriptorSetLayout>> layoutsFound;
for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i)
{
if (types & (static_cast<uint64_t>(1) << i))
layoutsFound.push_back(predefinedLayouts[i]);
}
return layoutsFound;
} }
SHVertexInputState const& SHGraphicsGlobalData::GetDefaultViState(void) noexcept SHVertexInputState const& SHPredefinedData::GetDefaultViState(void) noexcept
{ {
return defaultVertexInputState; return defaultVertexInputState;
} }
Handle<SHVkPipelineLayout> SHGraphicsGlobalData::GetDummyPipelineLayout(void) noexcept Handle<SHVkPipelineLayout> SHPredefinedData::GetDummyPipelineLayout(void) noexcept
{ {
return dummyPipelineLayout; return dummyPipelineLayout;
} }

View File

@ -3,6 +3,7 @@
#include "SH_API.h" #include "SH_API.h"
#include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/Pipeline/SHPipelineState.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
#include "Tools/Utilities/SHUtilities.h"
namespace SHADE namespace SHADE
{ {
@ -11,11 +12,11 @@ namespace SHADE
class SHVkDescriptorSetGroup; class SHVkDescriptorSetGroup;
class SHVkPipelineLayout; class SHVkPipelineLayout;
class SH_API SHGraphicsGlobalData class SH_API SHPredefinedData
{ {
private: private:
//! Global descriptor set layouts. Used to allocate descriptor sets //! Global descriptor set layouts. Used to allocate descriptor sets
static std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts; static std::vector<Handle<SHVkDescriptorSetLayout>> predefinedLayouts;
//! Default vertex input state (used by everything). //! Default vertex input state (used by everything).
static SHVertexInputState defaultVertexInputState; static SHVertexInputState defaultVertexInputState;
@ -24,7 +25,6 @@ namespace SHADE
//! we create a dummy pipeline layout to use it for binding. //! we create a dummy pipeline layout to use it for binding.
static Handle<SHVkPipelineLayout> dummyPipelineLayout; static Handle<SHVkPipelineLayout> dummyPipelineLayout;
static void InitHighFrequencyGlobalData (void) noexcept;
static void InitDescSetLayouts (Handle<SHVkLogicalDevice> logicalDevice) noexcept; static void InitDescSetLayouts (Handle<SHVkLogicalDevice> logicalDevice) noexcept;
static void InitDefaultVertexInputState (void) noexcept; static void InitDefaultVertexInputState (void) noexcept;
@ -32,7 +32,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Constructors */ /* Constructors */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
SHGraphicsGlobalData() = delete; SHPredefinedData() = delete;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */ /* PUBLIC MEMBER FUNCTIONS */
@ -42,7 +42,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */ /* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static std::vector<Handle<SHVkDescriptorSetLayout>> const& GetDescSetLayouts (void) noexcept; static std::vector<Handle<SHVkDescriptorSetLayout>> GetPredefinedDescSetLayouts (SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept;
static SHVertexInputState const& GetDefaultViState (void) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept;
static Handle<SHVkPipelineLayout> GetDummyPipelineLayout (void) noexcept; static Handle<SHVkPipelineLayout> GetDummyPipelineLayout (void) noexcept;
}; };

View File

@ -25,74 +25,85 @@ namespace SHADE
struct SHGraphicsConstants struct SHGraphicsConstants
{ {
public: public:
static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64;
enum class SHPredefinedDescSetLayoutTypes : uint64_t
{
STATIC_DATA = 0x01,
LIGHTS = 0x02,
CAMERA = 0x04,
MATERIALS = 0x08,
FONT = 0x10,
};
struct RenderGraphIndices struct RenderGraphIndices
{ {
static constexpr uint32_t WORLD = 0; static constexpr uint32_t WORLD = 0;
static constexpr uint32_t EDITOR = 0; static constexpr uint32_t EDITOR = 0;
}; };
struct DescriptorSetIndex //struct DescriptorSetIndex
{ //{
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for static global values like generic data, and // DescriptorSet Index for static global values like generic data, and
texture samplers // texture samplers
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t STATIC_GLOBALS = 0; // static constexpr uint32_t STATIC_GLOBALS = 0;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for dynamic global values like lights. // DescriptorSet Index for dynamic global values like lights.
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t DYNAMIC_GLOBALS = 1; // static constexpr uint32_t DYNAMIC_GLOBALS = 1;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for high frequency changing global values like // DescriptorSet Index for high frequency changing global values like
camera matrices. // camera matrices.
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; // static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for per-instance/material changing values. // DescriptorSet Index for per-instance/material changing values.
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t PER_INSTANCE = 3; // static constexpr uint32_t PER_INSTANCE = 3;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for render graph resources. Unlike the sets from // DescriptorSet Index for render graph resources. Unlike the sets from
1 to 3 and 6, this set index does not have hard coded bindings and is // 1 to 3 and 6, this set index does not have hard coded bindings and is
NOT part of the layouts included in the global data. // NOT part of the layouts included in the global data.
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; // static constexpr uint32_t RENDERGRAPH_RESOURCE = 4;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
DescriptorSet Index for render graph node compute resources. For data // DescriptorSet Index for render graph node compute resources. For data
that we wish to pass to compute shaders in the render graph, this is // that we wish to pass to compute shaders in the render graph, this is
the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have // the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have
hard coded bindings and is NOT part of the layouts included in the global // hard coded bindings and is NOT part of the layouts included in the global
data. // data.
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; // static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5;
/***************************************************************************/ // /***************************************************************************/
/*! // /*!
\brief // \brief
To store font data. // To store font data.
//
*/ // */
/***************************************************************************/ // /***************************************************************************/
static constexpr uint32_t FONT_DATA = 4; // static constexpr uint32_t FONT_DATA = 4;
}; //};
struct DescriptorSetBindings struct DescriptorSetBindings
{ {

View File

@ -31,7 +31,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#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/SHPredefinedData.h"
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/Images/SHVkSampler.h" #include "Graphics/Images/SHVkSampler.h"
#include "Assets/Asset Types/SHTextureAsset.h" #include "Assets/Asset Types/SHTextureAsset.h"
@ -124,6 +124,9 @@ namespace SHADE
SHFreetypeInstance::Init(); SHFreetypeInstance::Init();
SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_VS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_FS.glsl", false);
// Load Built In Shaders // Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT); static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT); static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
@ -318,12 +321,12 @@ namespace SHADE
/* BIND RENDER GRAPH TO RENDERER */ /* BIND RENDER GRAPH TO RENDERER */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
// Add world renderer to default viewport // Add world renderer to default viewport
worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph); worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph);
worldRenderer->SetCamera(worldCamera); worldRenderer->SetCamera(worldCamera);
worldRenderer->SetCameraDirector(worldCameraDirector); worldRenderer->SetCameraDirector(worldCameraDirector);
// Add screen renderer to default viewport // Add screen renderer to default viewport
screenRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph); screenRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph);
screenRenderer->SetCamera(screenCamera); screenRenderer->SetCamera(screenCamera);
screenRenderer->SetCameraDirector(worldCameraDirector); screenRenderer->SetCameraDirector(worldCameraDirector);
@ -356,7 +359,7 @@ namespace SHADE
void SHGraphicsSystem::InitMiddleEnd(void) noexcept void SHGraphicsSystem::InitMiddleEnd(void) noexcept
{ {
SHGraphicsGlobalData::Init(device); SHPredefinedData::Init(device);
InitSceneRenderGraph(); InitSceneRenderGraph();
@ -454,7 +457,7 @@ namespace SHADE
editorRenderGraph->Generate(); editorRenderGraph->Generate();
// Add world renderer to default viewport // Add world renderer to default viewport
editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph); editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph);
editorRenderer->SetCamera(worldCamera); editorRenderer->SetCamera(worldCamera);
} }
#endif #endif
@ -567,8 +570,8 @@ namespace SHADE
currentCmdBuffer->SetViewportScissor (static_cast<float>(w), static_cast<float>(h), w, h); currentCmdBuffer->SetViewportScissor (static_cast<float>(w), static_cast<float>(h), w, h);
// Force set the pipeline layout // Force set the pipeline layout
currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS);
currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE); currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE);
// Bind all the buffers required for meshes // Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA) for (auto& [buffer, bindingPoint] : MESH_DATA)
@ -900,7 +903,7 @@ namespace SHADE
void SHGraphicsSystem::BuildFonts(void) noexcept void SHGraphicsSystem::BuildFonts(void) noexcept
{ {
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, textRenderingSubSystem->GetFontDataDescSetLayout(), resourceManager); fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::FONT)[0], resourceManager);
} }
#pragma endregion ADD_REMOVE #pragma endregion ADD_REMOVE
@ -1044,6 +1047,10 @@ namespace SHADE
graphSemaphores[0].Free(); graphSemaphores[0].Free();
graphSemaphores[1].Free(); graphSemaphores[1].Free();
for (auto& semaHandle : graphSemaphores)
semaHandle = device->CreateSemaphore();
auto windowDims = window->GetWindowSize(); auto windowDims = window->GetWindowSize();
// Resize the swapchain // Resize the swapchain
@ -1054,6 +1061,12 @@ namespace SHADE
worldRenderGraph->HandleResize(resizeWidth, resizeHeight); worldRenderGraph->HandleResize(resizeWidth, resizeHeight);
#ifdef SHEDITOR #ifdef SHEDITOR
// NOTE: These 2 lines are actually not necessary because the editor viewport is not even used for
// setting dynamic viewport or scissor state. ImGUI takes care of that for us.
//editorViewport->SetWidth(windowDims.first);
//editorViewport->SetHeight(windowDims.second);
editorRenderGraph->HandleResize(windowDims.first, windowDims.second); editorRenderGraph->HandleResize(windowDims.first, windowDims.second);
#endif #endif
@ -1076,8 +1089,6 @@ namespace SHADE
#endif #endif
for (auto& semaHandle : graphSemaphores)
semaHandle = device->CreateSemaphore();
} }
void SHGraphicsSystem::AwaitGraphicsExecution() void SHGraphicsSystem::AwaitGraphicsExecution()
@ -1126,7 +1137,7 @@ namespace SHADE
device, SHPipelineLayoutParams device, SHPipelineLayoutParams
{ {
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::CAMERA)
} }
); );
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass); auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);

View File

@ -51,9 +51,12 @@ namespace SHADE
std::array cameraBufferArray{cameraBuffer}; std::array cameraBufferArray{cameraBuffer};
cameraDescriptorSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, std::span<Handle<SHVkBuffer>>{ cameraBufferArray.data(), cameraBufferArray.size()}, 0, sizeof (SHShaderCameraData)); // We use index 0 because the descriptor set is standalone created from a single desc set layout. What the driver sees is that this set is at index 0 during updating.
static constexpr uint8_t SET_0 = 0;
cameraDescriptorSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA); cameraDescriptorSet->ModifyWriteDescBuffer(SET_0, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, std::span<Handle<SHVkBuffer>>{ cameraBufferArray.data(), cameraBufferArray.size()}, 0, sizeof (SHShaderCameraData));
cameraDescriptorSet->UpdateDescriptorSetBuffer(SET_0, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA);
} }
SHRenderer::~SHRenderer(void) SHRenderer::~SHRenderer(void)

View File

@ -37,7 +37,7 @@ namespace SHADE
class SHVkCommandBuffer; class SHVkCommandBuffer;
class SHCamera; class SHCamera;
class SHVkDescriptorSetGroup; class SHVkDescriptorSetGroup;
class SHGraphicsGlobalData; class SHPredefinedData;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHVkBuffer; class SHVkBuffer;
class SHCameraDirector; class SHCameraDirector;

View File

@ -1,6 +1,6 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHLightingSubSystem.h" #include "SHLightingSubSystem.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Tools/Utilities/SHUtilities.h" #include "Tools/Utilities/SHUtilities.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
@ -385,7 +385,7 @@ namespace SHADE
std::fill (variableSizes.begin(), variableSizes.end(), 1); std::fill (variableSizes.begin(), variableSizes.end(), 1);
// Create the descriptor set // Create the descriptor set
lightingDataDescSet = descPool->Allocate({ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes); lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes);
#ifdef _DEBUG #ifdef _DEBUG
const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle();
for (int i = 0; i < static_cast<int>(CAM_DESC_SETS.size()); ++i) for (int i = 0; i < static_cast<int>(CAM_DESC_SETS.size()); ++i)

View File

@ -1,7 +1,7 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHPipelineLibrary.h" #include "SHPipelineLibrary.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/RenderGraph/SHSubpass.h"
#include "Graphics/SHVkUtil.h" #include "Graphics/SHVkUtil.h"
@ -13,7 +13,7 @@ namespace SHADE
SHPipelineLayoutParams params SHPipelineLayoutParams params
{ {
.shaderModules = {vsFsPair.first, vsFsPair.second}, .shaderModules = {vsFsPair.first, vsFsPair.second},
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
}; };
// Create the pipeline layout // Create the pipeline layout
@ -21,7 +21,7 @@ namespace SHADE
// Create the pipeline and configure the default vertex input state // Create the pipeline and configure the default vertex input state
auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass);
newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsGlobalData::GetDefaultViState()); newPipeline->GetPipelineState().SetVertexInputState(SHPredefinedData::GetDefaultViState());
SHColorBlendState colorBlendState{}; SHColorBlendState colorBlendState{};
colorBlendState.logic_op_enable = VK_FALSE; colorBlendState.logic_op_enable = VK_FALSE;

View File

@ -10,7 +10,7 @@ namespace SHADE
class SHVkDescriptorSetLayouts; class SHVkDescriptorSetLayouts;
class SHVkPipeline; class SHVkPipeline;
class SHSubpass; class SHSubpass;
class SHGraphicsGlobalData; class SHPredefinedData;
// Pipeline library is a PURELY MIDDLE END SYSTEM. It is responsible for only creating pipelines from shaders and caching // Pipeline library is a PURELY MIDDLE END SYSTEM. It is responsible for only creating pipelines from shaders and caching
// them so that they don't need to be recreated again. // them so that they don't need to be recreated again.

View File

@ -1,7 +1,7 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHFont.h" #include "SHFont.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/Images/SHVkSampler.h" #include "Graphics/Images/SHVkSampler.h"

View File

@ -6,7 +6,7 @@
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h"
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/Pipeline/SHVkPipeline.h"
#include "Graphics/SHVkUtil.h" #include "Graphics/SHVkUtil.h"
#include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/RenderGraph/SHSubpass.h"
@ -103,7 +103,7 @@ namespace SHADE
SHPipelineLayoutParams plParams SHPipelineLayoutParams plParams
{ {
.shaderModules = {textVS, textFS}, .shaderModules = {textVS, textFS},
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
}; };
pipelineLayout = logicalDevice->CreatePipelineLayout(plParams); pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);
@ -157,24 +157,6 @@ namespace SHADE
// Construct pipeline // Construct pipeline
pipeline->ConstructPipeline(); pipeline->ConstructPipeline();
SHVkDescriptorSetLayout::Binding fontBitmapBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
.DescriptorCount = 1,
};
SHVkDescriptorSetLayout::Binding fontMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
.DescriptorCount = 1,
};
fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding });
} }
void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept
@ -209,6 +191,7 @@ namespace SHADE
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0);
// bind camera desc set (again). Necessary because pipeline layout is not compatible.
cameraDescSetBind(cmdBuffer, frameIndex); cameraDescSetBind(cmdBuffer, frameIndex);
// bind descriptors for font (matrices) // bind descriptors for font (matrices)
@ -234,9 +217,9 @@ namespace SHADE
} }
Handle<SHVkDescriptorSetLayout> SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept //Handle<SHVkDescriptorSetLayout> SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept
{ //{
return fontDataDescSetLayout; // return fontDataDescSetLayout;
} //}
} }

View File

@ -41,7 +41,7 @@ namespace SHADE
Handle<SHVkPipelineLayout> pipelineLayout; Handle<SHVkPipelineLayout> pipelineLayout;
//! Descriptor set for font data access in shaders //! Descriptor set for font data access in shaders
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout; //Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout;
//! Super temporary. Global descriptor set needs to be revamped along with //! Super temporary. Global descriptor set needs to be revamped along with
//! entire graphics system. //! entire graphics system.
@ -58,7 +58,7 @@ namespace SHADE
void Exit(void) noexcept; void Exit(void) noexcept;
Handle<SHVkDescriptorSetLayout> GetFontDataDescSetLayout (void) const noexcept; //Handle<SHVkDescriptorSetLayout> GetFontDataDescSetLayout (void) const noexcept;
}; };

View File

@ -24,7 +24,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Graphics/Images/SHVkImage.h" #include "Graphics/Images/SHVkImage.h"
#include "Graphics/Images/SHVkImageView.h" #include "Graphics/Images/SHVkImageView.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Assets/Asset Types/SHTextureAsset.h" #include "Assets/Asset Types/SHTextureAsset.h"
namespace SHADE namespace SHADE
@ -168,7 +168,7 @@ namespace SHADE
} }
texDescriptors = descPool->Allocate texDescriptors = descPool->Allocate
( (
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] },
{ static_cast<uint32_t>(texOrder.size()) } { static_cast<uint32_t>(texOrder.size()) }
); );
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -12,7 +12,7 @@
#include "SHRenderGraphStorage.h" #include "SHRenderGraphStorage.h"
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
#include "Tools/Utilities/SHUtilities.h" #include "Tools/Utilities/SHUtilities.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h" #include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h"
namespace SHADE namespace SHADE

View File

@ -29,7 +29,7 @@ namespace SHADE
class SHVkCommandPool; class SHVkCommandPool;
class SHVkCommandBuffer; class SHVkCommandBuffer;
class SHRenderGraphNode; class SHRenderGraphNode;
class SHGraphicsGlobalData; class SHPredefinedData;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHRenderGraphStorage; class SHRenderGraphStorage;
class SHRenderToSwapchainImageSystem; class SHRenderToSwapchainImageSystem;

View File

@ -19,7 +19,7 @@ namespace SHADE
class SHVkLogicalDevice; class SHVkLogicalDevice;
class SHVkRenderpass; class SHVkRenderpass;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHGraphicsGlobalData; class SHPredefinedData;
class SHRenderGraphStorage; class SHRenderGraphStorage;
class SHRenderGraphNodeCompute; class SHRenderGraphNodeCompute;

View File

@ -6,7 +6,7 @@
#include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/Pipeline/SHVkPipelineLayout.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "SHRenderGraphStorage.h" #include "SHRenderGraphStorage.h"
#include "SHRenderGraphResource.h" #include "SHRenderGraphResource.h"
#include "Graphics/Commands/SHVkCommandBuffer.h" #include "Graphics/Commands/SHVkCommandBuffer.h"
@ -27,7 +27,7 @@ namespace SHADE
SHPipelineLayoutParams pipelineLayoutParams SHPipelineLayoutParams pipelineLayoutParams
{ {
.shaderModules = {computeShaderModule}, .shaderModules = {computeShaderModule},
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(),
.dynamicBufferBindings = std::move(dynamicBufferBindings), .dynamicBufferBindings = std::move(dynamicBufferBindings),
}; };

View File

@ -7,7 +7,7 @@ namespace SHADE
{ {
class SHVkLogicalDevice; class SHVkLogicalDevice;
class SHVkSwapchain; class SHVkSwapchain;
class SHGraphicsGlobalData; class SHPredefinedData;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHRenderGraphResource; class SHRenderGraphResource;

View File

@ -1,7 +1,7 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHRenderToSwapchainImageSystem.h" #include "SHRenderToSwapchainImageSystem.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
#include "Graphics/RenderGraph/SHRenderGraphNode.h" #include "Graphics/RenderGraph/SHRenderGraphNode.h"
#include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/RenderGraph/SHSubpass.h"
#include "Graphics/SHVkUtil.h" #include "Graphics/SHVkUtil.h"
@ -24,7 +24,7 @@ namespace SHADE
auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams
{ {
.shaderModules = {shaderModules.first, shaderModules.second}, .shaderModules = {shaderModules.first, shaderModules.second},
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(),
}); });
pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass);

View File

@ -43,6 +43,73 @@ namespace SHADE
static constexpr OutputType ConvertEnum(InputType enumClassMember) noexcept; static constexpr OutputType ConvertEnum(InputType enumClassMember) noexcept;
}; };
template<typename BitType>
class SHEnumWrapper
{
public:
using UnderlyingType = typename std::underlying_type_t<BitType>;
private:
UnderlyingType mask;
public:
constexpr SHEnumWrapper(void) noexcept
: mask{ 0 }
{
};
constexpr SHEnumWrapper(BitType bit) noexcept
: mask{ static_cast<UnderlyingType>(bit) }
{
};
constexpr SHEnumWrapper(SHEnumWrapper<BitType> const& rhs) noexcept = default;
constexpr SHEnumWrapper& operator= (SHEnumWrapper<BitType> const& rhs) noexcept = default;
constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept
: mask{ flags }
{
};
constexpr SHEnumWrapper<BitType> operator| (SHEnumWrapper<BitType> const& rhs) const noexcept
{
return static_cast<SHEnumWrapper<BitType>> (mask | rhs.mask);
};
constexpr SHEnumWrapper<BitType> operator& (SHEnumWrapper<BitType> const& rhs) const noexcept
{
return static_cast<SHEnumWrapper<BitType>> (mask & rhs.mask);
};
constexpr operator UnderlyingType() const noexcept
{
return mask;
};
};
template<typename BitType, typename = std::enable_if_t<std::is_enum_v<BitType>>>
inline BitType operator|(const BitType& left, const BitType& right)
{
return static_cast<BitType>(static_cast<int>(left) | static_cast<int>(right));
}
template<typename BitType, typename = std::enable_if_t<std::is_enum_v<BitType>>>
inline BitType operator&(const BitType& left, const BitType& right)
{
return static_cast<BitType>(static_cast<int>(left) & static_cast<int>(right));
}
template <typename EnumType>
std::ostream& operator<<(std::ostream& os, EnumType const& type)
{
os << static_cast<EnumType::UnderlyingType>(type);
return os;
}
} // namespace SHADE } // namespace SHADE
#include "SHUtilities.hpp" #include "SHUtilities.hpp"