Shadows WIP
This commit is contained in:
parent
b771cdbfc6
commit
87b2103f6e
|
@ -279,6 +279,13 @@ namespace SHADE
|
||||||
},
|
},
|
||||||
{ SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()});
|
{ SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()});
|
||||||
|
|
||||||
|
// Add subpass with exterior draw call to transition shadow maps
|
||||||
|
//auto shadowMapTransitionSubpass = deferredCompositeNode->AddSubpass("Shadow Map Transition", {}, {});
|
||||||
|
//shadowMapTransitionSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
|
// {
|
||||||
|
// lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer);
|
||||||
|
// });
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* DEFERRED COMPOSITE SUBPASS INIT */
|
/* DEFERRED COMPOSITE SUBPASS INIT */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
|
@ -526,7 +526,6 @@ namespace SHADE
|
||||||
// so we do it anyway. #NoteToSelf: if at any point it affects performance, do a check before computing.
|
// so we do it anyway. #NoteToSelf: if at any point it affects performance, do a check before computing.
|
||||||
ComputeDynamicOffsets();
|
ComputeDynamicOffsets();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -549,10 +548,10 @@ namespace SHADE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHLightingSubSystem::AddShadowMap(Handle<SHRenderGraphResource> newShadowMap) noexcept
|
void SHLightingSubSystem::AddShadowMap(Handle<SHRenderGraphResource> newShadowMap, EntityID lightEntity) noexcept
|
||||||
{
|
{
|
||||||
// Add to container of shadow maps
|
// Add to container of shadow maps
|
||||||
shadowMaps.emplace_back(newShadowMap);
|
shadowMaps.emplace(lightEntity, newShadowMap);
|
||||||
|
|
||||||
// Just use the image view stored in the resource
|
// Just use the image view stored in the resource
|
||||||
Handle<SHVkImageView> const NEW_IMAGE_VIEW = newShadowMap->GetImageView();
|
Handle<SHVkImageView> const NEW_IMAGE_VIEW = newShadowMap->GetImageView();
|
||||||
|
@ -597,6 +596,12 @@ namespace SHADE
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHLightingSubSystem::PrepareShadowMapsForRead(Handle<SHVkCommandBuffer> cmdBuffer) noexcept
|
||||||
|
{
|
||||||
|
// Issue barrier to transition shadow maps for reading in compute shader
|
||||||
|
cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers);
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHVkDescriptorSetGroup> SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept
|
Handle<SHVkDescriptorSetGroup> SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept
|
||||||
{
|
{
|
||||||
return lightingDataDescSet;
|
return lightingDataDescSet;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
||||||
#include "Graphics/RenderGraph/SHRenderGraphResource.h"
|
#include "Graphics/RenderGraph/SHRenderGraphResource.h"
|
||||||
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -162,8 +163,9 @@ namespace SHADE
|
||||||
//! Handle to sampler that all shadow map descriptors will use
|
//! Handle to sampler that all shadow map descriptors will use
|
||||||
Handle<SHVkSampler> shadowMapSampler;
|
Handle<SHVkSampler> shadowMapSampler;
|
||||||
|
|
||||||
//! Shadow maps for every light that casts a shadow
|
//std::vector<Handle<SHRenderGraphResource>> shadowMaps;
|
||||||
std::vector<Handle<SHRenderGraphResource>> shadowMaps;
|
//! Shadow maps for every light that casts a shadow Order here doesn't matter. We just want to store it
|
||||||
|
std::unordered_map<EntityID, Handle<SHRenderGraphResource>> shadowMaps;
|
||||||
|
|
||||||
//! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array.
|
//! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array.
|
||||||
//! It will also be preallocated.
|
//! It will also be preallocated.
|
||||||
|
@ -193,7 +195,8 @@ namespace SHADE
|
||||||
void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept;
|
void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept;
|
||||||
void Exit (void) noexcept;
|
void Exit (void) noexcept;
|
||||||
void BindDescSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept;
|
void BindDescSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept;
|
||||||
void AddShadowMap (Handle<SHRenderGraphResource> newShadowMap) noexcept;
|
void AddShadowMap (Handle<SHRenderGraphResource> newShadowMap, EntityID lightEntity) noexcept;
|
||||||
|
void PrepareShadowMapsForRead (Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
|
||||||
//void RemoveShadowMap (uint32_t index) noexcept;
|
//void RemoveShadowMap (uint32_t index) noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
|
@ -431,7 +431,7 @@ namespace SHADE
|
||||||
return subpass;
|
return subpass;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHRenderGraphNodeCompute> SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, float numWorkGroupScale/* = 1.0f*/) noexcept
|
Handle<SHRenderGraphNodeCompute> SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, Handle<SHVkDescriptorSetLayout> customComputeLayout/* = {}*/, float numWorkGroupScale/* = 1.0f*/) noexcept
|
||||||
{
|
{
|
||||||
// Look for the required resources in the graph
|
// Look for the required resources in the graph
|
||||||
std::vector<Handle<SHRenderGraphResource>> nodeComputeResources{};
|
std::vector<Handle<SHRenderGraphResource>> nodeComputeResources{};
|
||||||
|
@ -447,7 +447,7 @@ namespace SHADE
|
||||||
std::vector<Handle<SHRenderGraphResource>> temp (nodeComputeResources);
|
std::vector<Handle<SHRenderGraphResource>> temp (nodeComputeResources);
|
||||||
|
|
||||||
// Create the subpass compute with the resources
|
// Create the subpass compute with the resources
|
||||||
auto nodeCompute = graphStorage->resourceHub->Create<SHRenderGraphNodeCompute>(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty());
|
auto nodeCompute = graphStorage->resourceHub->Create<SHRenderGraphNodeCompute>(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), customComputeLayout);
|
||||||
nodeComputes.push_back(nodeCompute);
|
nodeComputes.push_back(nodeCompute);
|
||||||
|
|
||||||
for (auto& resource : temp)
|
for (auto& resource : temp)
|
||||||
|
|
|
@ -109,7 +109,7 @@ namespace SHADE
|
||||||
/* PUBLIC MEMBER FUNCTIONS */
|
/* PUBLIC MEMBER FUNCTIONS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
Handle<SHSubpass> AddSubpass(std::string subpassName, Handle<SHViewport> viewport, Handle<SHRenderer> renderer) noexcept;
|
Handle<SHSubpass> AddSubpass(std::string subpassName, Handle<SHViewport> viewport, Handle<SHRenderer> renderer) noexcept;
|
||||||
Handle<SHRenderGraphNodeCompute> AddNodeCompute(std::string nodeName, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept;
|
Handle<SHRenderGraphNodeCompute> AddNodeCompute(std::string nodeName, Handle<SHVkShaderModule> computeShaderModule, std::initializer_list<std::string> resources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings = {}, Handle<SHVkDescriptorSetLayout> customComputeLayout = {}, float numWorkGroupScale = 1.0f) noexcept;
|
||||||
|
|
||||||
void Execute(Handle<SHVkCommandBuffer> commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
void Execute(Handle<SHVkCommandBuffer> commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
||||||
Handle<SHVkPipeline> GetOrCreatePipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHSubpass> subpass) noexcept;
|
Handle<SHVkPipeline> GetOrCreatePipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHSubpass> subpass) noexcept;
|
||||||
|
|
|
@ -62,7 +62,8 @@ namespace SHADE
|
||||||
followingEndRenderpass = flag;
|
followingEndRenderpass = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale/* = 1.0f*/) noexcept
|
|
||||||
|
SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, bool followingEndRP, Handle<SHVkDescriptorSetLayout> customComputeLayout, float inNumWorkGroupScale/* = 1.0f*/) noexcept
|
||||||
: computePipeline{}
|
: computePipeline{}
|
||||||
, pipelineLayout{}
|
, pipelineLayout{}
|
||||||
, resources{}
|
, resources{}
|
||||||
|
@ -116,10 +117,22 @@ namespace SHADE
|
||||||
// check if all layouts are there
|
// check if all layouts are there
|
||||||
if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1)
|
if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1)
|
||||||
{
|
{
|
||||||
|
Handle<SHVkDescriptorSetLayout> computeResourceLayout = {};
|
||||||
|
uint32_t variableCounts = 0;
|
||||||
|
if (customComputeLayout)
|
||||||
|
{
|
||||||
|
// Just use the descriptor counts in bindings as the variable descriptor counts
|
||||||
|
auto const& bindings = customComputeLayout->GetBindings();
|
||||||
|
variableCounts = bindings.back().DescriptorCount;
|
||||||
|
computeResourceLayout = customComputeLayout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)];
|
||||||
|
|
||||||
|
|
||||||
// create compute resources
|
// create compute resources
|
||||||
computeResource = graphStorage->resourceHub->Create<ComputeResource>();
|
computeResource = graphStorage->resourceHub->Create<ComputeResource>();
|
||||||
auto computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)];
|
computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableCounts});
|
||||||
computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 });
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
for (auto set : computeResource->descSet->GetVkHandle())
|
for (auto set : computeResource->descSet->GetVkHandle())
|
||||||
SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] " + name + " Resources");
|
SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] " + name + " Resources");
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace SHADE
|
||||||
void SetFollowingEndRenderpass (uint32_t flag) noexcept;
|
void SetFollowingEndRenderpass (uint32_t flag) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHRenderGraphNodeCompute(std::string nodeName, Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale = 1.0f) noexcept;
|
SHRenderGraphNodeCompute(std::string nodeName, Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, std::unordered_set<BindingAndSetHash>&& dynamicBufferBindings, bool followingEndRP, Handle<SHVkDescriptorSetLayout> customComputeLayout, float inNumWorkGroupScale = 1.0f) noexcept;
|
||||||
|
|
||||||
void Execute (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void Execute (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||||
void HandleResize (void) noexcept;
|
void HandleResize (void) noexcept;
|
||||||
|
|
Loading…
Reference in New Issue