Refactored Graphics #297
|
@ -411,11 +411,12 @@ namespace SHADE
|
||||||
instancedIntegerData.reserve(numTotalElements);
|
instancedIntegerData.reserve(numTotalElements);
|
||||||
instancedIntegerData.clear();
|
instancedIntegerData.clear();
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
|
||||||
// - Material Properties Data
|
// - Material Properties Data
|
||||||
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
|
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
|
||||||
(
|
(
|
||||||
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS),
|
||||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||||
vk::ShaderStageFlagBits::eFragment
|
vk::ShaderStageFlagBits::eFragment
|
||||||
);
|
);
|
||||||
|
@ -570,11 +571,14 @@ namespace SHADE
|
||||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
||||||
if (matPropsDescSet[frameIndex])
|
if (matPropsDescSet[frameIndex])
|
||||||
{
|
{
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
|
||||||
cmdBuffer->BindDescriptorSet
|
cmdBuffer->BindDescriptorSet
|
||||||
(
|
(
|
||||||
matPropsDescSet[frameIndex],
|
matPropsDescSet[frameIndex],
|
||||||
SH_PIPELINE_TYPE::GRAPHICS,
|
SH_PIPELINE_TYPE::GRAPHICS,
|
||||||
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||||
|
descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS),
|
||||||
dynamicOffset
|
dynamicOffset
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -607,7 +611,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
matPropsDescSet[frameIndex] = descPool->Allocate
|
matPropsDescSet[frameIndex] = descPool->Allocate
|
||||||
(
|
(
|
||||||
{ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] },
|
SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS),
|
||||||
{ 0 }
|
{ 0 }
|
||||||
);
|
);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -618,17 +622,21 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
uint32_t const MATERIAL_DESC_SET_INDEX = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS);
|
||||||
|
|
||||||
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
|
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
|
||||||
matPropsDescSet[frameIndex]->ModifyWriteDescBuffer
|
matPropsDescSet[frameIndex]->ModifyWriteDescBuffer
|
||||||
(
|
(
|
||||||
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
MATERIAL_DESC_SET_INDEX,
|
||||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||||
bufferList,
|
bufferList,
|
||||||
0, static_cast<uint32_t>(matPropsDataSize)
|
0, static_cast<uint32_t>(matPropsDataSize)
|
||||||
);
|
);
|
||||||
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
|
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
|
||||||
(
|
(
|
||||||
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
MATERIAL_DESC_SET_INDEX,
|
||||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
|
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHDescriptorMappings.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
void SHDescriptorMappings::AddMappings(std::initializer_list<std::pair<SHGraphicsConstants::DescriptorSetTypes, uint32_t>> inMappings) noexcept
|
||||||
|
{
|
||||||
|
for (auto& map : inMappings)
|
||||||
|
mappings.emplace(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHDescriptorMappings::MapType const& SHDescriptorMappings::GetMappings(void) const noexcept
|
||||||
|
{
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
class SHDescriptorMappings
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using MapType = std::unordered_map<SHGraphicsConstants::DescriptorSetTypes, uint32_t>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! To map an enum value from descriptor set types to set indices
|
||||||
|
MapType mappings;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* PUBLIC MEMBER FUNCTIONS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
void AddMappings (std::initializer_list<std::pair<SHGraphicsConstants::DescriptorSetTypes, uint32_t>> inMappings) noexcept;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* SETTERS AND GETTERS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
MapType const& GetMappings (void) const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHGlobalDescriptorSets.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::lightDescriptorSet;
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
/*!
|
||||||
|
|
||||||
|
\brief
|
||||||
|
Sets the Handle to descriptor set for lights.
|
||||||
|
|
||||||
|
\param lightDescSet
|
||||||
|
The handle to set to.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/***************************************************************************/
|
||||||
|
void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept
|
||||||
|
{
|
||||||
|
lightDescriptorSet = lightDescSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept
|
||||||
|
{
|
||||||
|
return lightDescriptorSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
|
||||||
|
#include "Resource/SHHandle.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
// This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems
|
||||||
|
class SHGlobalDescriptorSets
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
//! Light data descriptor set
|
||||||
|
static Handle<SHVkDescriptorSetGroup> lightDescriptorSet;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* SETTERS AND GETTERS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
static void SetLightDescriptorSet (Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept;
|
||||||
|
|
||||||
|
static Handle<SHVkDescriptorSetGroup> GetLightDescriptorSet (void) noexcept;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
|
@ -13,7 +13,41 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::predefinedLayouts;
|
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::predefinedLayouts;
|
||||||
SHVertexInputState SHPredefinedData::defaultVertexInputState;
|
SHVertexInputState SHPredefinedData::defaultVertexInputState;
|
||||||
Handle<SHVkPipelineLayout> SHPredefinedData::dummyPipelineLayout;
|
SHPredefinedData::PerSystem SHPredefinedData::batchingSystemData;
|
||||||
|
SHPredefinedData::PerSystem SHPredefinedData::textSystemData;
|
||||||
|
SHPredefinedData::PerSystem SHPredefinedData::renderGraphNodeComputeData;
|
||||||
|
|
||||||
|
void SHPredefinedData::InitDescMappings(void) noexcept
|
||||||
|
{
|
||||||
|
batchingSystemData.descMappings.AddMappings
|
||||||
|
({
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::MATERIALS, 2},
|
||||||
|
});
|
||||||
|
|
||||||
|
textSystemData.descMappings.AddMappings
|
||||||
|
({
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::FONT, 2},
|
||||||
|
});
|
||||||
|
|
||||||
|
renderGraphNodeComputeData.descMappings.AddMappings
|
||||||
|
({
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::LIGHTS, 1},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 2},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE, 3},
|
||||||
|
{SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE, 4},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHPredefinedData::InitDummyPipelineLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept
|
||||||
|
{
|
||||||
|
batchingSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ batchingSystemData.descSetLayouts });
|
||||||
|
textSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ textSystemData.descSetLayouts });
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Function Definitions */
|
/* Function Definitions */
|
||||||
|
@ -91,35 +125,46 @@ namespace SHADE
|
||||||
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ 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)
|
//// font bitmap data (texture)
|
||||||
SHVkDescriptorSetLayout::Binding fontBitmapBinding
|
//SHVkDescriptorSetLayout::Binding fontBitmapBinding
|
||||||
{
|
//{
|
||||||
.Type = vk::DescriptorType::eCombinedImageSampler,
|
// .Type = vk::DescriptorType::eCombinedImageSampler,
|
||||||
.Stage = vk::ShaderStageFlagBits::eFragment,
|
// .Stage = vk::ShaderStageFlagBits::eFragment,
|
||||||
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
|
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
|
||||||
.DescriptorCount = 1,
|
// .DescriptorCount = 1,
|
||||||
};
|
//};
|
||||||
|
|
||||||
// font data in the form of matrices
|
//// font data in the form of matrices
|
||||||
SHVkDescriptorSetLayout::Binding fontMatrixBinding
|
//SHVkDescriptorSetLayout::Binding fontMatrixBinding
|
||||||
{
|
//{
|
||||||
.Type = vk::DescriptorType::eStorageBuffer,
|
// .Type = vk::DescriptorType::eStorageBuffer,
|
||||||
.Stage = vk::ShaderStageFlagBits::eVertex,
|
// .Stage = vk::ShaderStageFlagBits::eVertex,
|
||||||
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
|
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
|
||||||
.DescriptorCount = 1,
|
// .DescriptorCount = 1,
|
||||||
};
|
//};
|
||||||
|
|
||||||
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
|
//Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
|
||||||
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
|
//SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
|
||||||
|
|
||||||
|
|
||||||
predefinedLayouts.push_back(staticGlobalLayout);
|
predefinedLayouts.push_back(staticGlobalLayout);
|
||||||
predefinedLayouts.push_back(lightDataDescSetLayout);
|
predefinedLayouts.push_back(lightDataDescSetLayout);
|
||||||
predefinedLayouts.push_back(cameraDataGlobalLayout);
|
predefinedLayouts.push_back(cameraDataGlobalLayout);
|
||||||
predefinedLayouts.push_back(materialDataPerInstanceLayout);
|
predefinedLayouts.push_back(materialDataPerInstanceLayout);
|
||||||
predefinedLayouts.push_back(fontDataDescSetLayout);
|
//predefinedLayouts.push_back(fontDataDescSetLayout);
|
||||||
|
|
||||||
dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{predefinedLayouts});
|
batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
||||||
|
(
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA |
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS
|
||||||
|
);
|
||||||
|
|
||||||
|
textSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
||||||
|
(
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPredefinedData::InitDefaultVertexInputState(void) noexcept
|
void SHPredefinedData::InitDefaultVertexInputState(void) noexcept
|
||||||
|
@ -136,9 +181,11 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
InitDescSetLayouts(logicalDevice);
|
InitDescSetLayouts(logicalDevice);
|
||||||
InitDefaultVertexInputState();
|
InitDefaultVertexInputState();
|
||||||
|
InitDescMappings();
|
||||||
|
InitDummyPipelineLayouts (logicalDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept
|
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper<SHGraphicsConstants::PredefinedDescSetLayoutTypes> types) noexcept
|
||||||
{
|
{
|
||||||
std::vector<Handle<SHVkDescriptorSetLayout>> layoutsFound;
|
std::vector<Handle<SHVkDescriptorSetLayout>> layoutsFound;
|
||||||
for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i)
|
for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i)
|
||||||
|
@ -156,9 +203,20 @@ namespace SHADE
|
||||||
return defaultVertexInputState;
|
return defaultVertexInputState;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHVkPipelineLayout> SHPredefinedData::GetDummyPipelineLayout(void) noexcept
|
|
||||||
|
SHPredefinedData::PerSystem const& SHPredefinedData::GetBatchingSystemData(void) noexcept
|
||||||
{
|
{
|
||||||
return dummyPipelineLayout;
|
return batchingSystemData;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPredefinedData::PerSystem const& SHPredefinedData::GetTextSystemData(void) noexcept
|
||||||
|
{
|
||||||
|
return textSystemData;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPredefinedData::PerSystem const& SHPredefinedData::GetRenderGraphNodeComputeData(void) noexcept
|
||||||
|
{
|
||||||
|
return renderGraphNodeComputeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 "Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h"
|
||||||
#include "Tools/Utilities/SHUtilities.h"
|
#include "Tools/Utilities/SHUtilities.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -12,8 +13,22 @@ namespace SHADE
|
||||||
class SHVkDescriptorSetGroup;
|
class SHVkDescriptorSetGroup;
|
||||||
class SHVkPipelineLayout;
|
class SHVkPipelineLayout;
|
||||||
|
|
||||||
|
|
||||||
class SH_API SHPredefinedData
|
class SH_API SHPredefinedData
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
struct PerSystem
|
||||||
|
{
|
||||||
|
//! vector of descriptor set layouts used by a system
|
||||||
|
std::vector<Handle<SHVkDescriptorSetLayout>> descSetLayouts;
|
||||||
|
|
||||||
|
//! pipeline layout used for binding descriptor sets in the system
|
||||||
|
static Handle<SHVkPipelineLayout> dummyPipelineLayout;
|
||||||
|
|
||||||
|
//! Descriptor type mappings for the system
|
||||||
|
SHDescriptorMappings descMappings;
|
||||||
|
};
|
||||||
|
|
||||||
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>> predefinedLayouts;
|
static std::vector<Handle<SHVkDescriptorSetLayout>> predefinedLayouts;
|
||||||
|
@ -21,10 +36,17 @@ namespace SHADE
|
||||||
//! Default vertex input state (used by everything).
|
//! Default vertex input state (used by everything).
|
||||||
static SHVertexInputState defaultVertexInputState;
|
static SHVertexInputState defaultVertexInputState;
|
||||||
|
|
||||||
//! Since we want to bind global data but can't do so without a pipeline layout,
|
//! predefined data for the batching system
|
||||||
//! we create a dummy pipeline layout to use it for binding.
|
static PerSystem batchingSystemData;
|
||||||
static Handle<SHVkPipelineLayout> dummyPipelineLayout;
|
|
||||||
|
|
||||||
|
//! predefined data for the text system
|
||||||
|
static PerSystem textSystemData;
|
||||||
|
|
||||||
|
//! predefined data for the render graph node computes
|
||||||
|
static PerSystem renderGraphNodeComputeData;
|
||||||
|
|
||||||
|
static void InitDescMappings (void) noexcept;
|
||||||
|
static void InitDummyPipelineLayouts (Handle<SHVkLogicalDevice> logicalDevice) 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;
|
||||||
|
|
||||||
|
@ -42,8 +64,10 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
static std::vector<Handle<SHVkDescriptorSetLayout>> GetPredefinedDescSetLayouts (SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept;
|
static std::vector<Handle<SHVkDescriptorSetLayout>> GetPredefinedDescSetLayouts (SHEnumWrapper<SHGraphicsConstants::PredefinedDescSetLayoutTypes> types) noexcept;
|
||||||
static SHVertexInputState const& GetDefaultViState (void) noexcept;
|
static SHVertexInputState const& GetDefaultViState (void) noexcept;
|
||||||
static Handle<SHVkPipelineLayout> GetDummyPipelineLayout (void) noexcept;
|
static PerSystem const& GetBatchingSystemData(void) noexcept;
|
||||||
|
static PerSystem const& GetTextSystemData(void) noexcept;
|
||||||
|
static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,28 @@ namespace SHADE
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64;
|
static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64;
|
||||||
|
|
||||||
enum class SHPredefinedDescSetLayoutTypes : uint64_t
|
// This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData
|
||||||
|
enum class PredefinedDescSetLayoutTypes : uint64_t
|
||||||
{
|
{
|
||||||
STATIC_DATA = 0x01,
|
STATIC_DATA = 0x01,
|
||||||
LIGHTS = 0x02,
|
LIGHTS = 0x02,
|
||||||
CAMERA = 0x04,
|
CAMERA = 0x04,
|
||||||
MATERIALS = 0x08,
|
MATERIALS = 0x08,
|
||||||
FONT = 0x10,
|
};
|
||||||
|
|
||||||
|
// This enum is different from the one above in that it is used to initialize a hash table to
|
||||||
|
// with the values here as keys and set indices as values. It is worth noting that some values here
|
||||||
|
// are not in the above table. This is because those values don't have predefined descriptor set layouts.
|
||||||
|
// Their layouts and set indices are instead created through introspection in the pipeline layout.
|
||||||
|
enum class DescriptorSetTypes
|
||||||
|
{
|
||||||
|
STATIC_DATA,
|
||||||
|
LIGHTS,
|
||||||
|
CAMERA,
|
||||||
|
MATERIALS,
|
||||||
|
FONT,
|
||||||
|
RENDER_GRAPH_RESOURCE,
|
||||||
|
RENDER_GRAPH_NODE_COMPUTE_RESOURCE,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenderGraphIndices
|
struct RenderGraphIndices
|
||||||
|
@ -42,68 +57,68 @@ namespace SHADE
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
|
@ -903,7 +903,7 @@ namespace SHADE
|
||||||
|
|
||||||
void SHGraphicsSystem::BuildFonts(void) noexcept
|
void SHGraphicsSystem::BuildFonts(void) noexcept
|
||||||
{
|
{
|
||||||
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::FONT)[0], resourceManager);
|
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion ADD_REMOVE
|
#pragma endregion ADD_REMOVE
|
||||||
|
@ -1137,7 +1137,7 @@ namespace SHADE
|
||||||
device, SHPipelineLayoutParams
|
device, SHPipelineLayoutParams
|
||||||
{
|
{
|
||||||
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
|
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
|
||||||
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::CAMERA)
|
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);
|
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace SHADE
|
||||||
SHPipelineLayoutParams params
|
SHPipelineLayoutParams params
|
||||||
{
|
{
|
||||||
.shaderModules = {vsFsPair.first, vsFsPair.second},
|
.shaderModules = {vsFsPair.first, vsFsPair.second},
|
||||||
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
|
.globalDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the pipeline layout
|
// Create the pipeline layout
|
||||||
|
|
|
@ -103,7 +103,7 @@ namespace SHADE
|
||||||
SHPipelineLayoutParams plParams
|
SHPipelineLayoutParams plParams
|
||||||
{
|
{
|
||||||
.shaderModules = {textVS, textFS},
|
.shaderModules = {textVS, textFS},
|
||||||
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
|
.predefinedDescSetLayouts = SHPredefinedData::GetTextSystemData().descSetLayouts
|
||||||
};
|
};
|
||||||
|
|
||||||
pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);
|
pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace SHADE
|
||||||
//! used just for textures or lights for example). In that case, we still
|
//! used just for textures or lights for example). In that case, we still
|
||||||
//! want to use the layout to initialize the pipeline layout but we do not
|
//! want to use the layout to initialize the pipeline layout but we do not
|
||||||
//! want to use it for allocating descriptor sets.
|
//! want to use it for allocating descriptor sets.
|
||||||
std::vector<Handle<SHVkDescriptorSetLayout>> const& globalDescSetLayouts = {};
|
std::vector<Handle<SHVkDescriptorSetLayout>> const& predefinedDescSetLayouts = {};
|
||||||
|
|
||||||
//! Since both SPIRV-Reflect and GLSL don't provide ways to describe UBOs or
|
//! Since both SPIRV-Reflect and GLSL don't provide ways to describe UBOs or
|
||||||
//! SSBOs as dynamic, we need to do it ourselves. This will store bindings
|
//! SSBOs as dynamic, we need to do it ourselves. This will store bindings
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace SHADE
|
||||||
SHPipelineLayoutParams pipelineLayoutParams
|
SHPipelineLayoutParams pipelineLayoutParams
|
||||||
{
|
{
|
||||||
.shaderModules = {computeShaderModule},
|
.shaderModules = {computeShaderModule},
|
||||||
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(),
|
.predefinedDescSetLayouts = SHPredefinedData::GetRenderGraphNodeComputeData().descSetLayouts,
|
||||||
.dynamicBufferBindings = std::move(dynamicBufferBindings),
|
.dynamicBufferBindings = std::move(dynamicBufferBindings),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,10 +45,13 @@ namespace SHADE
|
||||||
// save the resources
|
// save the resources
|
||||||
resources = std::move (subpassComputeResources);
|
resources = std::move (subpassComputeResources);
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
|
||||||
|
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline();
|
||||||
|
|
||||||
//Get the descriptor set layouts required to allocate. We only want the ones for allocate because
|
|
||||||
//global descriptors are already bound in the main system.
|
//Get the descriptor set layouts required to allocate. We only want the ones for allocate because
|
||||||
auto const& graphResourceLayout = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];
|
//global descriptors are already bound in the main system.
|
||||||
|
auto const& graphResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)];
|
||||||
|
|
||||||
// Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE)
|
// Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE)
|
||||||
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||||
|
@ -60,14 +63,12 @@ namespace SHADE
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if all layouts are there
|
||||||
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline();
|
if (layouts.size() == descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1)
|
||||||
|
|
||||||
if (layouts.size() == SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE + 1)
|
|
||||||
{
|
{
|
||||||
// create compute resources
|
// create compute resources
|
||||||
computeResource = graphStorage->resourceHub->Create<ComputeResource>();
|
computeResource = graphStorage->resourceHub->Create<ComputeResource>();
|
||||||
auto computeResourceLayout = layouts[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE];
|
auto computeResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)];
|
||||||
computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 });
|
computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 });
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
for (auto set : computeResource->descSet->GetVkHandle())
|
for (auto set : computeResource->descSet->GetVkHandle())
|
||||||
|
@ -91,12 +92,14 @@ namespace SHADE
|
||||||
// bind the compute pipeline
|
// bind the compute pipeline
|
||||||
cmdBuffer->BindPipeline(computePipeline);
|
cmdBuffer->BindPipeline(computePipeline);
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
|
||||||
|
|
||||||
// bind descriptor sets
|
// bind descriptor sets
|
||||||
cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, {});
|
cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {});
|
||||||
|
|
||||||
if (computeResource)
|
if (computeResource)
|
||||||
{
|
{
|
||||||
cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, computeResource->dynamicOffsets[frameIndex]);
|
cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dispatch compute
|
// dispatch compute
|
||||||
|
@ -109,8 +112,11 @@ namespace SHADE
|
||||||
|
|
||||||
void SHRenderGraphNodeCompute::HandleResize(void) noexcept
|
void SHRenderGraphNodeCompute::HandleResize(void) noexcept
|
||||||
{
|
{
|
||||||
|
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
|
||||||
|
uint32_t renderGraphResourceSetIndex = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE);
|
||||||
|
|
||||||
// Get the layout for the render graph resource. We can index it this way because the container returned is a container of layouts that includes the global ones
|
// Get the layout for the render graph resource. We can index it this way because the container returned is a container of layouts that includes the global ones
|
||||||
auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];
|
auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[renderGraphResourceSetIndex];
|
||||||
|
|
||||||
// everything below here needs resizing
|
// everything below here needs resizing
|
||||||
for (uint32_t frameIndex = 0; frameIndex < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++frameIndex)
|
for (uint32_t frameIndex = 0; frameIndex < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++frameIndex)
|
||||||
|
@ -123,8 +129,8 @@ namespace SHADE
|
||||||
uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast<uint32_t>(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0;
|
uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast<uint32_t>(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0;
|
||||||
|
|
||||||
SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle<SHVkSampler>{}, vk::ImageLayout::eGeneral);
|
SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle<SHVkSampler>{}, vk::ImageLayout::eGeneral);
|
||||||
graphResourceDescSets[frameIndex]->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, { &vsl, 1 });
|
graphResourceDescSets[frameIndex]->ModifyWriteDescImage(renderGraphResourceSetIndex, binding.BindPoint, { &vsl, 1 });
|
||||||
graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint);
|
graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(renderGraphResourceSetIndex, binding.BindPoint);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = SHPredefinedData::GetPredefinedDescSetLayouts(),
|
.predefinedDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts
|
||||||
});
|
});
|
||||||
|
|
||||||
pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass);
|
pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass);
|
||||||
|
|
Loading…
Reference in New Issue