WIP (not working)

This commit is contained in:
Brandon Mak 2022-10-20 19:36:43 +08:00
parent 71502daac3
commit c177dabcd0
15 changed files with 172 additions and 72 deletions

View File

@ -233,6 +233,8 @@ namespace SHADE
, vmaAllocator{rhs.vmaAllocator}
, nonDedicatedBestIndex {0}
, parentPhysicalDeviceHdl {rhs.parentPhysicalDeviceHdl}
, uboBufferMemoryAlignment{ 0 }
, ssboBufferMemoryAlignment{ 0 }
{
rhs.vkLogicalDevice = VK_NULL_HANDLE;
}
@ -261,6 +263,8 @@ namespace SHADE
vmaAllocator = rhs.vmaAllocator;
nonDedicatedBestIndex = 0;
parentPhysicalDeviceHdl = rhs.parentPhysicalDeviceHdl;
uboBufferMemoryAlignment = rhs.uboBufferMemoryAlignment;
ssboBufferMemoryAlignment = rhs.ssboBufferMemoryAlignment;
rhs.vkLogicalDevice = VK_NULL_HANDLE;
@ -529,6 +533,11 @@ namespace SHADE
}
Handle<SHVkPipeline> SHVkLogicalDevice::CreateComputePipeline(Handle<SHVkPipelineLayout> const& pipelineLayoutHdl) noexcept
{
return SHVkInstance::GetResourceManager().Create <SHVkPipeline>(GetHandle(), pipelineLayoutHdl);
}
Handle<SHVkSampler> SHVkLogicalDevice::CreateSampler(const SHVkSamplerParams& params) noexcept
{
return SHVkInstance::GetResourceManager().Create <SHVkSampler>(GetHandle(), params);

View File

@ -175,12 +175,17 @@ namespace SHADE
std::string const& shaderName
) noexcept;
Handle<SHVkPipeline> CreateGraphicsPipeline (
Handle<SHVkPipeline> CreateGraphicsPipeline (
Handle<SHVkPipelineLayout> const& pipelineLayoutHdl,
SHVkPipelineState const* const state,
Handle<SHVkRenderpass> const& renderpassHdl,
Handle<SHSubpass> subpass
) noexcept;
Handle<SHVkPipeline> CreateComputePipeline (
Handle<SHVkPipelineLayout> const& pipelineLayoutHdl
) noexcept;
Handle<SHVkSampler> CreateSampler (const SHVkSamplerParams& params) noexcept;
Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::vector<SHVkSubpassParams> const& subpasses) noexcept;

View File

@ -8,7 +8,7 @@
namespace SHADE
{
Handle<SHVkPipeline> SHPipelineLibrary::CreateDrawPipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass) noexcept
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass) noexcept
{
SHPipelineLayoutParams params
{
@ -52,7 +52,7 @@ namespace SHADE
newPipeline->ConstructPipeline();
// Emplace the new pipeline
pipelines.emplace (vsFsPair, newPipeline);
graphicsPipelines.emplace (vsFsPair, newPipeline);
return newPipeline;
}
@ -62,19 +62,19 @@ namespace SHADE
logicalDevice = device;
}
Handle<SHVkPipeline> SHPipelineLibrary::GetDrawPipline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept
Handle<SHVkPipeline> SHPipelineLibrary::GetGraphicsPipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept
{
// return the pipeline requested for
if (pipelines.contains(vsFsPair))
return pipelines.at(vsFsPair);
if (graphicsPipelines.contains(vsFsPair))
return graphicsPipelines.at(vsFsPair);
else
return {};
}
bool SHPipelineLibrary::CheckDrawPipelineExistence(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept
bool SHPipelineLibrary::CheckGraphicsPipelineExistence(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept
{
// Returns if a pipeline exists or not
return pipelines.contains(vsFsPair);
return graphicsPipelines.contains(vsFsPair);
}
}

View File

@ -23,19 +23,19 @@ namespace SHADE
Handle<SHVkLogicalDevice> logicalDevice;
//! a map of pipelines that are hashed using a pair of shader module handles
std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>> pipelines;
std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>> graphicsPipelines;
public:
void Init (Handle<SHVkLogicalDevice> device) noexcept;
// Draw pipeline functions. used only when creating pipelines for drawing using a vertex and fragment shader
Handle<SHVkPipeline> CreateDrawPipeline (
Handle<SHVkPipeline> CreateGraphicsPipelines (
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
Handle<SHVkRenderpass> renderpass,
Handle<SHSubpass> subpass
) noexcept;
Handle<SHVkPipeline> GetDrawPipline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
bool CheckDrawPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
};
}

View File

@ -9,6 +9,7 @@
#include "Graphics/Buffers/SHVkBuffer.h"
#include "Tools/SHLogger.h"
#include "SHAttachmentDescInitParams.h"
#include "SHRenderGraphStorage.h"
namespace SHADE
{
@ -52,12 +53,12 @@ namespace SHADE
// If we set to
if (w == static_cast<uint32_t>(-1) && h == static_cast<uint32_t>(-1))
{
w = swapchainHdl->GetSwapchainImage(0)->GetWidth();
h = swapchainHdl->GetSwapchainImage(0)->GetHeight();
format = swapchainHdl->GetSurfaceFormatKHR().format;
w = renderGraphStorage->swapchain->GetSwapchainImage(0)->GetWidth();
h = renderGraphStorage->swapchain->GetSwapchainImage(0)->GetHeight();
format = renderGraphStorage->swapchain->GetSurfaceFormatKHR().format;
}
graphResources.try_emplace(resourceName, resourceManager->Create<SHRenderGraphResource>(logicalDeviceHdl, swapchainHdl, resourceName, typeFlags, format, w, h, levels, usageFlags, createFlags));
graphResources.try_emplace(resourceName, resourceManager->Create<SHRenderGraphResource>(renderGraphStorage, resourceName, typeFlags, format, w, h, levels, usageFlags, createFlags));
}
/***************************************************************************/
@ -343,10 +344,15 @@ namespace SHADE
*/
/***************************************************************************/
void SHRenderGraph::Init(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain) noexcept
void SHRenderGraph::Init(Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain) noexcept
{
logicalDeviceHdl = logicalDevice;
swapchainHdl = swapchain;
renderGraphStorage = resourceManager->Create<SHRenderGraphStorage>();
renderGraphStorage->logicalDevice = logicalDevice;
renderGraphStorage->swapchain = swapchain;
renderGraphStorage->resourceManager = resourceManager;
renderGraphStorage->descriptorPool = logicalDevice->CreateDescriptorPools();
}
/***************************************************************************/
@ -361,8 +367,7 @@ namespace SHADE
*/
/***************************************************************************/
SHRenderGraph::SHRenderGraph(void) noexcept
: logicalDeviceHdl{ }
, swapchainHdl{ }
: renderGraphStorage{}
, nodes{}
, graphResources{}
, resourceManager{nullptr}
@ -371,8 +376,7 @@ namespace SHADE
}
SHRenderGraph::SHRenderGraph(SHRenderGraph&& rhs) noexcept
: logicalDeviceHdl{ rhs.logicalDeviceHdl }
, swapchainHdl{ rhs.swapchainHdl }
: renderGraphStorage{ rhs.renderGraphStorage }
, nodeIndexing{ std::move(rhs.nodeIndexing) }
, nodes{ std::move(rhs.nodes) }
, graphResources{ std::move(rhs.graphResources) }
@ -386,8 +390,7 @@ namespace SHADE
if (&rhs == this)
return *this;
logicalDeviceHdl = rhs.logicalDeviceHdl;
swapchainHdl = rhs.swapchainHdl;
renderGraphStorage = rhs.renderGraphStorage;
nodeIndexing = std::move(rhs.nodeIndexing);
nodes = std::move(rhs.nodes);
graphResources = std::move(rhs.graphResources);
@ -456,7 +459,7 @@ namespace SHADE
}
}
nodes.emplace_back(resourceManager->Create<SHRenderGraphNode>(resourceManager, logicalDeviceHdl, swapchainHdl, std::move(descInitParams), std::move(predecessors), &graphResources));
nodes.emplace_back(resourceManager->Create<SHRenderGraphNode>(renderGraphStorage, std::move(descInitParams), std::move(predecessors), &graphResources));
nodeIndexing.emplace(nodeName, static_cast<uint32_t>(nodes.size()) - 1u);
return nodes.at(nodeIndexing[nodeName]);
}

View File

@ -30,7 +30,8 @@ namespace SHADE
class SHVkCommandBuffer;
class SHRenderGraphNode;
class SHGraphicsGlobalData;
class SHVkDescriptorPool;
class SHRenderGraphStorage;
class SH_API SHRenderGraph
{
@ -56,10 +57,12 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* PRIVATE MEMBER VARIABLES */
/*-----------------------------------------------------------------------*/
Handle<SHVkLogicalDevice> logicalDeviceHdl;
//Handle<SHVkLogicalDevice> logicalDeviceHdl;
//! swapchain used for querying image count
Handle<SHVkSwapchain> swapchainHdl;
//Handle<SHVkSwapchain> swapchainHdl;
Handle<SHRenderGraphStorage> renderGraphStorage;
//! For indexing render graph node container
std::map<std::string, uint32_t> nodeIndexing;
@ -85,7 +88,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/
void Init (Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain) noexcept;
void Init (Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain) noexcept;
void AddResource(std::string resourceName, std::initializer_list<SH_ATT_DESC_TYPE_FLAGS> typeFlags, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {});
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<ResourceInstruction> resourceInstruction, std::initializer_list<std::string> predecessorNodes) noexcept;

View File

@ -6,6 +6,7 @@
#include "Graphics/Framebuffer/SHVkFramebuffer.h"
#include "SHRenderGraphResource.h"
#include "SHSubpass.h"
#include "SHRenderGraphStorage.h"
namespace SHADE
{
@ -21,7 +22,7 @@ namespace SHADE
/***************************************************************************/
void SHRenderGraphNode::CreateRenderpass(void) noexcept
{
renderpass = logicalDeviceHdl->CreateRenderpass(attachmentDescriptions, spDescs, spDeps);
renderpass = graphStorage->logicalDevice->CreateRenderpass(attachmentDescriptions, spDescs, spDeps);
}
/***************************************************************************/
@ -53,7 +54,7 @@ namespace SHADE
}
framebuffers[i] = logicalDeviceHdl->CreateFramebuffer(renderpass, imageViews, fbWidth, fbHeight);
framebuffers[i] = graphStorage->logicalDevice->CreateFramebuffer(renderpass, imageViews, fbWidth, fbHeight);
}
}
@ -104,8 +105,8 @@ namespace SHADE
*/
/***************************************************************************/
SHRenderGraphNode::SHRenderGraphNode(std::shared_ptr<ResourceManager> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
: logicalDeviceHdl{ logicalDevice }
SHRenderGraphNode::SHRenderGraphNode(Handle<SHRenderGraphStorage> renderGraphStorage, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
: graphStorage{ renderGraphStorage}
, renderpass{}
, framebuffers{}
, prereqNodes{ std::move(predecessors) }
@ -115,11 +116,10 @@ namespace SHADE
, subpasses{}
, executed{ false }
, configured{ false }
, resourceManager{ rm }
, ptrToResources{ resources }
{
// pipeline library initialization
pipelineLibrary.Init(logicalDeviceHdl);
pipelineLibrary.Init(graphStorage->logicalDevice);
// Store all the handles to resources
attResources.reserve (attDescInitParams.size());
@ -155,15 +155,14 @@ namespace SHADE
if (!containsSwapchainImage)
framebuffers.resize(1);
else
framebuffers.resize(swapchain->GetNumImages());
framebuffers.resize(graphStorage->swapchain->GetNumImages());
// At this point, we could configure framebuffers if we had the renderpass object but we don't so their creation has to be
// deferred to when renderpasses are also created.
}
SHRenderGraphNode::SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept
: resourceManager{ std::move (rhs.resourceManager) }
, logicalDeviceHdl{ rhs.logicalDeviceHdl }
: graphStorage{ rhs.graphStorage}
, renderpass{ rhs.renderpass }
, framebuffers{ std::move(rhs.framebuffers) }
, prereqNodes{ std::move(rhs.prereqNodes) }
@ -189,8 +188,7 @@ namespace SHADE
if (&rhs == this)
return *this;
resourceManager = std::move(rhs.resourceManager);
logicalDeviceHdl = rhs.logicalDeviceHdl;
graphStorage = rhs.graphStorage;
renderpass = rhs.renderpass;
framebuffers = std::move(rhs.framebuffers);
prereqNodes = std::move(rhs.prereqNodes);
@ -235,10 +233,10 @@ 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(graphStorage->resourceManager->Create<SHSubpass>(GetHandle(), subpasses.size(), &resourceAttachmentMapping, ptrToResources));
subpassIndexing.try_emplace(subpassName, static_cast<uint32_t>(subpasses.size()) - 1u);
Handle<SHSubpass> subpass = subpasses.back();
subpass->Init(*resourceManager);
subpass->Init(*graphStorage->resourceManager);
// Register the SuperBatch
batcher.RegisterSuperBatch(subpass->GetSuperBatch());
@ -273,10 +271,10 @@ namespace SHADE
}
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(vsFsPair);
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(vsFsPair);
if (!pipeline)
{
pipeline = pipelineLibrary.CreateDrawPipeline
pipeline = pipelineLibrary.CreateGraphicsPipelines
(
vsFsPair,
renderpass,
@ -289,7 +287,7 @@ namespace SHADE
void SHRenderGraphNode::FinaliseBatch(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
{
batcher.FinaliseBatches(logicalDeviceHdl, descPool, frameIndex);
batcher.FinaliseBatches(graphStorage->logicalDevice, descPool, frameIndex);
}
/***************************************************************************/

View File

@ -19,6 +19,8 @@ namespace SHADE
class SHVkLogicalDevice;
class SHVkRenderpass;
class SHVkDescriptorPool;
class SHGraphicsGlobalData;
class SHRenderGraphStorage;
class SH_API SHRenderGraphNode : public ISelfHandle<SHRenderGraphNode>
{
@ -26,10 +28,9 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* PRIVATE MEMBER VARIABLES */
/*-----------------------------------------------------------------------*/
std::shared_ptr<ResourceManager> resourceManager;
//! For Vulkan object creation
Handle<SHVkLogicalDevice> logicalDeviceHdl;
//Handle<SHVkLogicalDevice> logicalDeviceHdl;
Handle<SHRenderGraphStorage> graphStorage;
//! Each node will have a renderpass and each renderpass will have its own subpasses.
//! These subpasses will execute sequentially.
@ -88,7 +89,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* CTORS AND DTORS */
/*-----------------------------------------------------------------------*/
SHRenderGraphNode(std::shared_ptr<ResourceManager> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept;
SHRenderGraphNode(Handle<SHRenderGraphStorage> renderGraphStorage, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept;
SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept;
SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept;

View File

@ -5,6 +5,7 @@
#include "Graphics/Images/SHVkImageView.h"
#include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/SHVkUtil.h"
#include "SHRenderGraphStorage.h"
namespace SHADE
{
@ -45,7 +46,7 @@ namespace SHADE
*/
/***************************************************************************/
SHRenderGraphResource::SHRenderGraphResource(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::string const& name, std::initializer_list<SH_ATT_DESC_TYPE_FLAGS> typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept
SHRenderGraphResource::SHRenderGraphResource(Handle<SHRenderGraphStorage> graphStorage, std::string const& name, std::initializer_list<SH_ATT_DESC_TYPE_FLAGS> typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept
: logicalDevice {logicalDevice}
, swapchain{ swapchain }
, resourceTypeFlags{ }
@ -75,13 +76,13 @@ namespace SHADE
};
// We want an image handle for every swapchain image
images.resize(swapchain->GetNumImages());
imageViews.resize(swapchain->GetNumImages());
images.resize(graphStorage->swapchain->GetNumImages());
imageViews.resize(graphStorage->swapchain->GetNumImages());
for (uint32_t i = 0; i < swapchain->GetNumImages(); ++i)
for (uint32_t i = 0; i < graphStorage->swapchain->GetNumImages(); ++i)
{
images[i] = swapchain->GetSwapchainImage(i);
imageViews[i] = images[i]->CreateImageView(logicalDevice, images[i], viewDetails);
images[i] = graphStorage->swapchain->GetSwapchainImage(i);
imageViews[i] = images[i]->CreateImageView(graphStorage->logicalDevice, images[i], viewDetails);
}
}
else // if swapchain image resource
@ -126,7 +127,7 @@ namespace SHADE
}
// The resource is not a swapchain image, just use the first slot of the vector
images.push_back(logicalDevice->CreateImage(width, height, mipLevels, resourceFormat, usage, createFlags));
images.push_back(graphStorage->logicalDevice->CreateImage(width, height, mipLevels, resourceFormat, usage, createFlags));
// prepare image view details
SHImageViewDetails viewDetails
@ -141,7 +142,7 @@ namespace SHADE
};
// just 1 image view created
imageViews.push_back(images[0]->CreateImageView(logicalDevice, images[0], viewDetails));
imageViews.push_back(images[0]->CreateImageView(graphStorage->logicalDevice, images[0], viewDetails));
}
}

View File

@ -15,6 +15,7 @@ namespace SHADE
class SHVkSwapchain;
class SHVkCommandBuffer;
class SHVkBuffer;
class SHRenderGraphStorage;
static constexpr uint32_t NON_SWAPCHAIN_RESOURCE_INDEX = 0;
@ -69,7 +70,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* CTORS AND DTORS */
/*-----------------------------------------------------------------------*/
SHRenderGraphResource(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::string const& name, std::initializer_list<SH_ATT_DESC_TYPE_FLAGS> typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept;
SHRenderGraphResource(Handle<SHRenderGraphStorage> graphStorage, std::string const& name, std::initializer_list<SH_ATT_DESC_TYPE_FLAGS> typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept;
SHRenderGraphResource(SHRenderGraphResource&& rhs) noexcept;
SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept;
~SHRenderGraphResource(void) noexcept;

View File

@ -0,0 +1,33 @@
#pragma once
#include "Resource/Handle.h"
#include <memory>
namespace SHADE
{
class SHVkLogicalDevice;
class SHVkSwapchain;
class SHGraphicsGlobalData;
class SHVkDescriptorPool;
class SHRenderGraphStorage
{
//! Logical device for creation of vulkan objects
Handle<SHVkLogicalDevice> logicalDevice;
//! swapchain hdl
Handle<SHVkSwapchain> swapchain;
//! Resource manager for creation of objects
std::shared_ptr<ResourceManager> resourceManager;
//! Descriptor pool for the descriptor sets to be created in the subpasses
Handle<SHVkDescriptorPool> descriptorPool;
friend class SHRenderGraph;
friend class SHRenderGraphNode;
friend class SHSubpass;
friend class SHRenderGraphResource;
friend class SHSubpassCompute;
};
}

View File

@ -4,6 +4,10 @@
#include "Graphics/Devices/SHVkLogicalDevice.h"
#include "SHRenderGraphNode.h"
#include "SHRenderGraphResource.h"
#include "Graphics/Shaders/SHVkShaderModule.h"
#include "SHRenderGraphNode.h"
#include "SHRenderGraphStorage.h"
#include "Graphics/RenderGraph/SHSubpassCompute.h"
namespace SHADE
{
@ -23,7 +27,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<SHRenderGraphStorage> renderGraphStorage, 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
: resourceAttachmentMapping{ mapping }
, ptrToResources{ resources }
, parentNode{ parent }
@ -32,6 +36,7 @@ namespace SHADE
, colorReferences{}
, depthReferences{}
, inputReferences{}
, graphStorage{ renderGraphStorage }
{
}
@ -56,7 +61,8 @@ namespace SHADE
, resourceAttachmentMapping{ rhs.resourceAttachmentMapping }
, ptrToResources{ rhs.ptrToResources }
, descriptorSetLayout{ rhs.descriptorSetLayout }
, exteriorDrawCalls{ std::move (rhs.exteriorDrawCalls) }
, exteriorDrawCalls{ std::move(rhs.exteriorDrawCalls) }
, graphStorage{ std::move(rhs.graphStorage) }
{
}
@ -87,6 +93,7 @@ namespace SHADE
ptrToResources = rhs.ptrToResources;
descriptorSetLayout = rhs.descriptorSetLayout;
exteriorDrawCalls = std::move(rhs.exteriorDrawCalls);
graphStorage = std::move(rhs.graphStorage);
return *this;
}
@ -182,6 +189,11 @@ namespace SHADE
exteriorDrawCalls.push_back(newDrawCall);
}
Handle<SHSubpassCompute> SHSubpass::ActivateSubpassCompute(Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources) noexcept
{
//subpassCompute = graphStorage->resourceManager->Create<SHSubpassCompute>(, parentNode->GetGraphDescPool(), resources);
}
void SHSubpass::Init(ResourceManager& resourceManager) noexcept
{
superBatch = resourceManager.Create<SHSuperBatch>(GetHandle());

View File

@ -15,6 +15,9 @@ namespace SHADE
class SHVkCommandBuffer;
class SHVkDescriptorSetLayout;
class SHVkDescriptorPool;
class SHRenderGraphStorage;
class SHSubpassCompute;
class SHVkShaderModule;
class SH_API SHSubpass : public ISelfHandle<SHSubpass>
{
@ -22,6 +25,8 @@ namespace SHADE
/*---------------------------------------------------------------------*/
/* PRIVATE MEMBER VARIABLES */
/*---------------------------------------------------------------------*/
Handle<SHRenderGraphStorage> graphStorage;
//! The index of the subpass in the render graph
uint32_t subpassIndex;
@ -49,6 +54,10 @@ namespace SHADE
//! Pointer to resources in the render graph (for getting handle IDs)
std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources;
//! Sometimes we want the subpass to do something to the images instead
//! of drawing objects on the image (i.e. compute).
Handle<SHSubpassCompute> subpassCompute;
//! Sometimes there exists entities that we want to render onto a render target
//! but don't want it to come from the batching system. An example would be ImGUI.
//! For these entities we want to link a function from the outside and draw them
@ -62,7 +71,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* 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<SHRenderGraphStorage> renderGraphStorage, 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(SHSubpass&& rhs) noexcept;
SHSubpass& operator=(SHSubpass&& rhs) noexcept;
@ -78,6 +87,8 @@ namespace SHADE
void Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
void AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&)> const& newDrawCall) noexcept;
Handle<SHSubpassCompute> ActivateSubpassCompute(Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources) noexcept;
void Init(ResourceManager& resourceManager) noexcept;
/*-----------------------------------------------------------------------*/

View File

@ -3,21 +3,32 @@
#include "Graphics/Pipeline/SHVkPipeline.h"
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/Pipeline/SHVkPipelineLayout.h"
#include "SHRenderGraphStorage.h"
//#include ""
namespace SHADE
{
SHSubpassCompute::SHSubpassCompute(Handle<SHVkPipeline> inPipeline, Handle<SHVkDescriptorPool> descPool) noexcept
: pipeline {inPipeline}
SHSubpassCompute::SHSubpassCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources) noexcept
: pipeline{}
{
SHPipelineLayoutParams pipelineLayoutParams
{
//.globalDescSetLayouts
};
//pipeline = logicalDevice->CreateComputePipeline()
// Get the descriptor set layouts required to allocate. we will bind a different pipeline layout, one that includes the layout for global.
auto const& layouts = pipeline->GetPipelineLayout()->GetDescriptorSetLayoutsAllocate();
// Variable counts for the descriptor sets (all should be 1).
std::vector<uint32_t> variableCounts{static_cast<uint32_t>(layouts.size())};
std::fill (variableCounts.begin(), variableCounts.end(), 0);
std::vector<uint32_t> variableCounts{ static_cast<uint32_t>(layouts.size()) };
std::fill(variableCounts.begin(), variableCounts.end(), 0);
// Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE)
descPool->Allocate(layouts, variableCounts);
descSetGroup = graphStorage->descriptorPool->Allocate(layouts, variableCounts);
}
}

View File

@ -1,24 +1,36 @@
#pragma once
#include <Resource/Handle.h>
#include "Resource/Handle.h"
#include <initializer_list>
#include <string>
namespace SHADE
{
class SHVkPipeline;
class SHVkDescriptorSetGroup;
class SHVkDescriptorPool;
class SHVkLogicalDevice;
class SHVkPipelineLayout;
class SHRenderGraphStorage;
class SHVkShaderModule;
class SHSubpassCompute
{
private:
//! To run the dispatch command
Handle<SHVkPipeline> pipeline;
Handle<SHVkPipeline> pipeline;
//! Descriptor set group
//! Pipeline layout for the pipline creation
Handle<SHVkPipeline> pipelineLayout;
//! Descriptor set group to hold the images for reading (STORAGE_IMAGE)
Handle<SHVkDescriptorSetGroup> descSetGroup;
//! Required resources to be used in the descriptors
std::vector<std::string> resourcesRequired;
public:
SHSubpassCompute (Handle<SHVkPipeline> inPipeline, Handle<SHVkDescriptorPool> descPool) noexcept;
SHSubpassCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources) noexcept;
};
}