Added serialization and deserialization of pipeline on the material (no shader loading yet)
This commit is contained in:
parent
9d8dfd334f
commit
6ea5ae7707
|
@ -158,7 +158,11 @@ namespace SHADE
|
|||
worldRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
||||
worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
|
||||
auto node = worldRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Scene"}, {}); // no predecessors
|
||||
auto node = worldRenderGraph->AddNode
|
||||
(
|
||||
G_BUFFER_RENDER_GRAPH_NODE_NAME.data(),
|
||||
{ "Entity ID", "Depth Buffer", "Scene"}, {}
|
||||
); // no predecessors
|
||||
|
||||
//First subpass to write to G-Buffer
|
||||
auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write");
|
||||
|
@ -749,5 +753,10 @@ namespace SHADE
|
|||
}
|
||||
|
||||
|
||||
Handle<SHRenderGraphNode> SHGraphicsSystem::GetPrimaryRenderpass() const noexcept
|
||||
{
|
||||
return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
|
||||
}
|
||||
|
||||
#pragma endregion MISC
|
||||
}
|
||||
|
|
|
@ -286,12 +286,17 @@ namespace SHADE
|
|||
#endif
|
||||
Handle<SHMousePickSystem> GetMousePickSystem(void) const noexcept {return mousePickSystem;};
|
||||
Handle<SHPostOffscreenRenderSystem> GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;};
|
||||
Handle<SHRenderGraphNode> GetPrimaryRenderpass() const noexcept;
|
||||
//SHRenderGraph const& GetRenderGraph(void) const noexcept;
|
||||
|
||||
//Handle<SHVkRenderpass> GetRenderPass() const { return renderPass; }
|
||||
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constants */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
static constexpr std::string_view G_BUFFER_RENDER_GRAPH_NODE_NAME = "G-Buffer";
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -318,7 +323,7 @@ namespace SHADE
|
|||
SHTextureLibrary texLibrary;
|
||||
SHSamplerCache samplerCache;
|
||||
SHMaterialInstanceCache materialInstanceCache;
|
||||
// Viewports
|
||||
// Viewports
|
||||
#ifdef SHEDITOR
|
||||
Handle<SHViewport> editorViewport;
|
||||
Handle<SHRenderer> editorRenderer;
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Add subpass to container and create mapping for it
|
||||
subpasses.emplace_back(resourceManager->Create<SHSubpass>(GetHandle(), subpasses.size(), &resourceAttachmentMapping, ptrToResources));
|
||||
subpasses.emplace_back(resourceManager->Create<SHSubpass>(GetHandle(), subpassName, subpasses.size(), &resourceAttachmentMapping, ptrToResources));
|
||||
subpassIndexing.try_emplace(subpassName, static_cast<uint32_t>(subpasses.size()) - 1u);
|
||||
Handle<SHSubpass> subpass = subpasses.back();
|
||||
subpass->Init(*resourceManager);
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/***************************************************************************/
|
||||
SHSubpass::SHSubpass(Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
|
||||
SHSubpass::SHSubpass(Handle<SHRenderGraphNode> const& parent, const std::string& name, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
|
||||
: resourceAttachmentMapping{ mapping }
|
||||
, ptrToResources{ resources }
|
||||
, parentNode{ parent }
|
||||
|
@ -32,6 +32,7 @@ namespace SHADE
|
|||
, colorReferences{}
|
||||
, depthReferences{}
|
||||
, inputReferences{}
|
||||
, name { name }
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -224,4 +225,8 @@ namespace SHADE
|
|||
return parentNode->GetResource(attachmentReference)->GetResourceFormat();
|
||||
}
|
||||
|
||||
const std::string& SHSubpass::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -56,13 +56,15 @@ namespace SHADE
|
|||
//! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING
|
||||
//! COMPLEX.
|
||||
std::vector<std::function<void(Handle<SHVkCommandBuffer>&)>> exteriorDrawCalls;
|
||||
/// For identifying subpasses
|
||||
std::string name;
|
||||
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* CTORS AND DTORS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
SHSubpass(Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources) noexcept;
|
||||
SHSubpass(Handle<SHRenderGraphNode> const& parent, const std::string& name, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources) noexcept;
|
||||
SHSubpass(SHSubpass&& rhs) noexcept;
|
||||
SHSubpass& operator=(SHSubpass&& rhs) noexcept;
|
||||
|
||||
|
@ -88,6 +90,7 @@ namespace SHADE
|
|||
Handle<SHSuperBatch> GetSuperBatch(void) const noexcept;
|
||||
std::vector<vk::AttachmentReference> const& GetColorAttachmentReferences (void) const noexcept;
|
||||
vk::Format GetFormatFromAttachmentReference (uint32_t attachmentReference) const noexcept;
|
||||
const std::string& GetName() const;
|
||||
|
||||
friend class SHRenderGraphNode;
|
||||
friend class SHRenderGraph;
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace YAML
|
|||
{
|
||||
static constexpr std::string_view VERT_SHADER_YAML_TAG = "VertexShader";
|
||||
static constexpr std::string_view FRAG_SHADER_YAML_TAG = "FragmentShader";
|
||||
static constexpr std::string_view SUBPASS_YAML_TAG = "SubPass";
|
||||
static constexpr std::string_view PROPS_YAML_TAG = "Properties";
|
||||
|
||||
static YAML::Node encode(SHMaterial const& rhs)
|
||||
|
@ -61,25 +62,70 @@ namespace YAML
|
|||
propertiesNode[VAR_NAME.data()] = propNode;
|
||||
}
|
||||
|
||||
// Get Shader Handles
|
||||
const auto& SHADERS = rhs.GetPipeline()->GetPipelineLayout()->GetShaderModules();
|
||||
Handle<SHVkShaderModule> vertexShader, fragShader;
|
||||
for (const auto& shader : SHADERS)
|
||||
{
|
||||
const auto FLAG_BITS = shader->GetShaderStageFlagBits();
|
||||
if (FLAG_BITS & vk::ShaderStageFlagBits::eVertex)
|
||||
vertexShader = shader;
|
||||
else if (FLAG_BITS & vk::ShaderStageFlagBits::eFragment)
|
||||
fragShader = shader;
|
||||
}
|
||||
|
||||
// Write Material
|
||||
YAML::Node node;
|
||||
|
||||
node[VERT_SHADER_YAML_TAG.data()] = 0;
|
||||
node[FRAG_SHADER_YAML_TAG.data()] = 0;
|
||||
node[PROPS_YAML_TAG.data()] = propertiesNode;
|
||||
node[VERT_SHADER_YAML_TAG.data()] = 0; // SHResourceManager::GetAssetID<SHVkShaderModule>(vertexShader).value_or(0);
|
||||
node[FRAG_SHADER_YAML_TAG.data()] = 0; // SHResourceManager::GetAssetID<SHVkShaderModule>(fragShader).value_or(0);
|
||||
node[SUBPASS_YAML_TAG.data()] = rhs.GetPipeline()->GetPipelineState().GetSubpass()->GetName();
|
||||
node[PROPS_YAML_TAG.data()] = propertiesNode;
|
||||
|
||||
return node;
|
||||
}
|
||||
static bool decode(YAML::Node const& node, SHMaterial& rhs)
|
||||
{
|
||||
// Retrieve Shader Asset IDs
|
||||
AssetID vertShaderId = 0;
|
||||
AssetID fragShaderId = 0;
|
||||
if (node[VERT_SHADER_YAML_TAG.data()])
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
vertShaderId = node[VERT_SHADER_YAML_TAG.data()].as<AssetID>();
|
||||
if (node[FRAG_SHADER_YAML_TAG.data()])
|
||||
fragShaderId = node[FRAG_SHADER_YAML_TAG.data()].as<AssetID>();
|
||||
|
||||
// Ensure that both shaders are present
|
||||
if (vertShaderId == 0 || fragShaderId == 0)
|
||||
return false; // No pipeline
|
||||
|
||||
// Get Shader Modules
|
||||
Handle<SHVkShaderModule> vertexShader, fragShader;
|
||||
// vertexShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(vertShaderId);
|
||||
// fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(fragShaderId);
|
||||
|
||||
// Get Pipeline Library
|
||||
if (node[SUBPASS_YAML_TAG.data()])
|
||||
{
|
||||
// TODO
|
||||
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
if (!gfxSystem)
|
||||
return false;
|
||||
|
||||
// Grab subpass from worldRenderer
|
||||
auto renderPass = gfxSystem->GetPrimaryRenderpass();
|
||||
if (!renderPass)
|
||||
return false;
|
||||
auto subPass = renderPass->GetSubpass(node[SUBPASS_YAML_TAG.data()].as<std::string>());
|
||||
if (!subPass)
|
||||
return false;
|
||||
|
||||
// Set Pipeline
|
||||
rhs.SetPipeline(renderPass->GetOrCreatePipeline
|
||||
(
|
||||
std::make_pair(vertexShader, fragShader),
|
||||
subPass
|
||||
));
|
||||
}
|
||||
|
||||
if (node[PROPS_YAML_TAG.data()])
|
||||
{
|
||||
// Loop through all properties
|
||||
|
@ -139,7 +185,7 @@ namespace YAML
|
|||
{
|
||||
if (node[MESH_YAML_TAG.data()])
|
||||
{
|
||||
rhs.Mesh = {};//SHResourceManager::LoadOrGet<SHMesh>(node[MESH_YAML_TAG].as<AssetID>());
|
||||
rhs.Mesh = SHResourceManager::LoadOrGet<SHMesh>(node[MESH_YAML_TAG.data()].as<AssetID>());
|
||||
}
|
||||
if (node[MAT_YAML_TAG.data()])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue