WIP will update later, afraid for BSOD again
This commit is contained in:
parent
5f2fa7fdf5
commit
44ca317e1d
|
@ -16,8 +16,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
|
@ -15,8 +15,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
|
@ -39,8 +39,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials
|
layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials
|
||||||
|
|
|
@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
|
@ -30,8 +30,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
// push constants
|
// push constants
|
||||||
|
@ -96,6 +95,6 @@ void main()
|
||||||
Out2.textColor = testPushConstant.textColor;
|
Out2.textColor = testPushConstant.textColor;
|
||||||
|
|
||||||
// transform the vertex position to font space
|
// transform the vertex position to font space
|
||||||
gl_Position = cameraData.orthoMat * localModel * vec4(vertexPos, 1.0f);
|
gl_Position = cameraData.projMat * localModel * vec4(vertexPos, 1.0f);
|
||||||
// gl_Position = vec4(vertexPos, 1.0f);
|
// gl_Position = vec4(vertexPos, 1.0f);
|
||||||
}
|
}
|
|
@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
vec4 position;
|
vec4 position;
|
||||||
mat4 vpMat;
|
mat4 vpMat;
|
||||||
mat4 viewMat;
|
mat4 viewMat;
|
||||||
mat4 perspectiveMat;
|
mat4 projMat;
|
||||||
mat4 orthoMat;
|
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -60,7 +59,7 @@ void main()
|
||||||
Out.normal.rgb = normalize (Out.normal.rgb);
|
Out.normal.rgb = normalize (Out.normal.rgb);
|
||||||
|
|
||||||
// clip space for rendering
|
// clip space for rendering
|
||||||
gl_Position = cameraData.orthoMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
gl_Position = cameraData.projMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
||||||
gl_Position.z += 0.1f; // HAX
|
gl_Position.z += 0.1f; // HAX
|
||||||
// gl_Position = vec4 (aVertexPos, 1.0f);
|
// gl_Position = vec4 (aVertexPos, 1.0f);
|
||||||
}
|
}
|
|
@ -500,10 +500,7 @@ namespace SHADE
|
||||||
imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||||
|
|
||||||
//auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers();
|
//auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers();
|
||||||
auto const& renderers = gfxSystem->GetEditorViewport()->GetRenderers();
|
auto renderGraph = gfxSystem->GetRenderGraph();
|
||||||
|
|
||||||
SHASSERT(!renderers.empty(), "No Renderers available")
|
|
||||||
auto renderGraph = renderers[SHGraphicsConstants::RenderGraphIndices::EDITOR]->GetRenderGraph();
|
|
||||||
auto renderPass = renderGraph->GetNode("ImGui Node")->GetRenderpass();
|
auto renderPass = renderGraph->GetNode("ImGui Node")->GetRenderpass();
|
||||||
|
|
||||||
if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false)
|
if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false)
|
||||||
|
@ -523,7 +520,7 @@ namespace SHADE
|
||||||
|
|
||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||||
|
|
||||||
renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd, uint32_t frameIndex)
|
renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer> cmd, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
cmd->BeginLabeledSegment("ImGui Draw");
|
cmd->BeginLabeledSegment("ImGui Draw");
|
||||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
||||||
|
|
|
@ -367,7 +367,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHVkCommandBuffer::BindDescriptorSet(Handle<SHVkDescriptorSetGroup> descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span<uint32_t> dynamicOffsets)
|
void SHVkCommandBuffer::BindDescriptorSet(Handle<SHVkDescriptorSetGroup> descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span<uint32_t> const dynamicOffsets)
|
||||||
{
|
{
|
||||||
uint32_t bindPointIndex = static_cast<uint32_t>(bindPoint);
|
uint32_t bindPointIndex = static_cast<uint32_t>(bindPoint);
|
||||||
vkCommandBuffer.bindDescriptorSets(SHVkUtil::GetPipelineBindPointFromType(bindPoint), bindPointData[bindPointIndex].boundPipelineLayoutHdl->GetVkPipelineLayout(), firstSet, descSetGroup->GetVkHandle(), dynamicOffsets);
|
vkCommandBuffer.bindDescriptorSets(SHVkUtil::GetPipelineBindPointFromType(bindPoint), bindPointData[bindPointIndex].boundPipelineLayoutHdl->GetVkPipelineLayout(), firstSet, descSetGroup->GetVkHandle(), dynamicOffsets);
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace SHADE
|
||||||
void BindPipeline (Handle<SHVkPipeline> const& pipelineHdl) noexcept;
|
void BindPipeline (Handle<SHVkPipeline> const& pipelineHdl) noexcept;
|
||||||
void BindVertexBuffer (uint32_t bindingPoint, Handle<SHVkBuffer> const& buffer, vk::DeviceSize offset) noexcept;
|
void BindVertexBuffer (uint32_t bindingPoint, Handle<SHVkBuffer> const& buffer, vk::DeviceSize offset) noexcept;
|
||||||
void BindIndexBuffer (Handle<SHVkBuffer> const& buffer, uint32_t startingIndex) const noexcept;
|
void BindIndexBuffer (Handle<SHVkBuffer> const& buffer, uint32_t startingIndex) const noexcept;
|
||||||
void BindDescriptorSet (Handle<SHVkDescriptorSetGroup> descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span<uint32_t> dynamicOffsets);
|
void BindDescriptorSet (Handle<SHVkDescriptorSetGroup> descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span<uint32_t> const dynamicOffsets);
|
||||||
|
|
||||||
// Draw Commands
|
// Draw Commands
|
||||||
void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept;
|
void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept;
|
||||||
|
|
|
@ -1,10 +1,31 @@
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHGlobalDescriptorSets.h"
|
#include "SHGlobalDescriptorSets.h"
|
||||||
|
#include "Graphics/MiddleEnd/Lights/SHLightingSubSystem.h"
|
||||||
|
#include "Graphics/Commands/SHVkCommandBuffer.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
||||||
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::lightDescriptorSet;
|
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::staticGlobalDataDescriptorSet;
|
||||||
|
Handle<SHLightingSubSystem> SHGlobalDescriptorSets::lightingSubSystem;
|
||||||
|
|
||||||
|
//void SHGlobalDescriptorSets::BindLightingData(Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t firstSet) noexcept
|
||||||
|
//{
|
||||||
|
// // Bind descriptor set for light data
|
||||||
|
// cmdBuffer->BindDescriptorSet(SHGlobalDescriptorSets::GetLightDescriptorSet(), SH_PIPELINE_TYPE::COMPUTE, descMappings[SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS], const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 });
|
||||||
|
//}
|
||||||
|
|
||||||
|
void SHGlobalDescriptorSets::BindLightingData(Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept
|
||||||
|
{
|
||||||
|
lightingSubSystem->BindDescSet(cmdBuffer, setIndex, frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHGlobalDescriptorSets::BindStaticGlobalData(Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept
|
||||||
|
{
|
||||||
|
// Bind descriptor set for static global data
|
||||||
|
static constexpr std::array<uint32_t, 1> TEX_DYNAMIC_OFFSET{ 0 };
|
||||||
|
cmdBuffer->BindDescriptorSet(staticGlobalDataDescriptorSet, pipelineType, setIndex, const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 });
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
@ -17,14 +38,14 @@ namespace SHADE
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept
|
void SHGlobalDescriptorSets::SetLightingSubSystem(Handle<SHLightingSubSystem> system) noexcept
|
||||||
{
|
{
|
||||||
lightDescriptorSet = lightDescSet;
|
lightingSubSystem = system;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept
|
void SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(Handle<SHVkDescriptorSetGroup> staticGlobalDescSet) noexcept
|
||||||
{
|
{
|
||||||
return lightDescriptorSet;
|
staticGlobalDataDescriptorSet = staticGlobalDescSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,23 +2,35 @@
|
||||||
|
|
||||||
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
|
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
|
#include "Graphics/Pipeline/SHPipelineType.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
class SHLightingSubSystem;
|
||||||
|
class SHVkCommandBuffer;
|
||||||
|
|
||||||
// This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems
|
// 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
|
class SHGlobalDescriptorSets
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! Light data descriptor set
|
|
||||||
static Handle<SHVkDescriptorSetGroup> lightDescriptorSet;
|
//! Static global descriptor sets for miscellaneous data and textures
|
||||||
|
static Handle<SHVkDescriptorSetGroup> staticGlobalDataDescriptorSet;
|
||||||
|
|
||||||
|
//! Lighting sub system required to get information to bind descriptor sets for light data
|
||||||
|
static Handle<SHLightingSubSystem> lightingSubSystem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* PUBLIC MEMBER FUNCTIONS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
static void BindLightingData (Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept;
|
||||||
|
static void BindStaticGlobalData (Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
static void SetLightDescriptorSet (Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept;
|
static void SetLightingSubSystem (Handle<SHLightingSubSystem> system) noexcept;
|
||||||
|
static void SetStaticGlobalDataDescriptorSet (Handle<SHVkDescriptorSetGroup> staticGlobalDescSet) noexcept;
|
||||||
static Handle<SHVkDescriptorSetGroup> GetLightDescriptorSet (void) noexcept;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,33 +125,33 @@ 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);
|
||||||
|
|
||||||
batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
||||||
(
|
(
|
||||||
|
@ -163,7 +163,8 @@ namespace SHADE
|
||||||
textSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
textSystemData.descSetLayouts = GetPredefinedDescSetLayouts
|
||||||
(
|
(
|
||||||
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||||
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA |
|
||||||
|
SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,10 +99,10 @@ namespace SHADE
|
||||||
createMeshBatches();
|
createMeshBatches();
|
||||||
|
|
||||||
// Register function for subpass
|
// Register function for subpass
|
||||||
auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers();
|
//auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers();
|
||||||
auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph();
|
auto renderGraph = gfxSystem->GetRenderGraph();
|
||||||
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
|
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
|
||||||
subPass->AddExteriorDrawCalls([this](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
subPass->AddExteriorDrawCalls([this](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex();
|
const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex();
|
||||||
cmdBuffer->BeginLabeledSegment("SHDebugDraw (No Depth Test)");
|
cmdBuffer->BeginLabeledSegment("SHDebugDraw (No Depth Test)");
|
||||||
|
@ -126,7 +126,7 @@ namespace SHADE
|
||||||
cmdBuffer->EndLabeledSegment();
|
cmdBuffer->EndLabeledSegment();
|
||||||
});
|
});
|
||||||
auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
|
auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
|
||||||
subPassWithDepth->AddExteriorDrawCalls([this](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
subPassWithDepth->AddExteriorDrawCalls([this](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex();
|
const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex();
|
||||||
cmdBuffer->BeginLabeledSegment("SHDebugDraw (Depth Tested)");
|
cmdBuffer->BeginLabeledSegment("SHDebugDraw (Depth Tested)");
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace SHADE
|
||||||
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
|
// This enum is different from the one above in that it is used to initialize a hash table to
|
||||||
|
|
|
@ -44,6 +44,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "../Meshes/SHPrimitiveGenerator.h"
|
#include "../Meshes/SHPrimitiveGenerator.h"
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h"
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -142,7 +143,7 @@ namespace SHADE
|
||||||
static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(RENDER_SC_FS);
|
static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(RENDER_SC_FS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept
|
void SHGraphicsSystem::InitRenderGraph(void) noexcept
|
||||||
{
|
{
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* MIDDLE END SETUP
|
/* MIDDLE END SETUP
|
||||||
|
@ -158,55 +159,66 @@ namespace SHADE
|
||||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||||
|
|
||||||
// Set Up Cameras
|
// Set Up Cameras
|
||||||
screenCamera = resourceManager.Create<SHCamera>();
|
//screenCamera = resourceManager.Create<SHCamera>();
|
||||||
screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f));
|
//screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f));
|
||||||
screenCamera->SetOrthographic(static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.01f, 100.0f);
|
//screenCamera->SetOrthographic(static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.01f, 100.0f);
|
||||||
|
|
||||||
worldCamera = resourceManager.Create<SHCamera>();
|
//worldCamera = resourceManager.Create<SHCamera>();
|
||||||
worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, 0.0f), SHVec3(0.0f, 0.0f, -2.0f), SHVec3(0.0f, 1.0f, 0.0f));
|
//worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, 0.0f), SHVec3(0.0f, 0.0f, -2.0f), SHVec3(0.0f, 1.0f, 0.0f));
|
||||||
worldCamera->SetPerspective(90.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 100.0f);
|
//worldCamera->SetPerspective(90.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 100.0f);
|
||||||
|
|
||||||
worldCameraDirector = cameraSystem->CreateDirector();
|
worldCameraDirector = cameraSystem->CreateDirector();
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* PREPARE RENDERERS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
// Add world renderer to default viewport
|
||||||
|
worldRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE);
|
||||||
|
worldRenderer->SetCameraDirector(worldCameraDirector);
|
||||||
|
|
||||||
|
// Add screen renderer to default viewport
|
||||||
|
screenRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC);
|
||||||
|
screenRenderer->SetCameraDirector(worldCameraDirector);
|
||||||
|
|
||||||
// Create Default Viewport
|
// Create Default Viewport
|
||||||
worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
|
worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
|
||||||
|
|
||||||
// Get render graph from default viewport world renderer
|
|
||||||
worldRenderGraph = resourceManager.Create<SHRenderGraph>();
|
|
||||||
|
|
||||||
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
||||||
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
||||||
{
|
{
|
||||||
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get render graph from default viewport world renderer
|
||||||
|
renderGraph = resourceManager.Create<SHRenderGraph>();
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* WORLD RENDER GRAPH RESOURCES */
|
/* WORLD RENDER GRAPH RESOURCES */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
// Initialize world render graph
|
// Initialize world render graph
|
||||||
worldRenderGraph->Init("World Render Graph", device, swapchain, &resourceManager);
|
renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools);
|
||||||
worldRenderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
||||||
worldRenderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
||||||
//worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
//worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
||||||
worldRenderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
||||||
worldRenderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
||||||
worldRenderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||||
worldRenderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
renderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||||
worldRenderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second);
|
renderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second);
|
||||||
worldRenderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
|
renderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
|
||||||
worldRenderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
|
renderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
|
||||||
|
renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* MAIN NODE */
|
/* MAIN NODE */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
auto gBufferNode = worldRenderGraph->AddNode("G-Buffer",
|
auto gBufferNode = renderGraph->AddNode("G-Buffer",
|
||||||
{
|
{
|
||||||
"Position",
|
"Position",
|
||||||
"Entity ID",
|
"Entity ID",
|
||||||
"Light Layer Indices",
|
"Light Layer Indices",
|
||||||
"Normals",
|
"Normals",
|
||||||
//"Tangents",
|
|
||||||
"Albedo",
|
"Albedo",
|
||||||
"Depth Buffer",
|
"Depth Buffer",
|
||||||
"Scene",
|
"Scene",
|
||||||
|
@ -218,20 +230,21 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* G-BUFFER SUBPASS INIT */
|
/* G-BUFFER SUBPASS INIT */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write");
|
auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write", worldViewport, worldRenderer);
|
||||||
gBufferSubpass->AddColorOutput("Position");
|
gBufferSubpass->AddColorOutput("Position");
|
||||||
gBufferSubpass->AddColorOutput("Entity ID");
|
gBufferSubpass->AddColorOutput("Entity ID");
|
||||||
gBufferSubpass->AddColorOutput("Light Layer Indices");
|
gBufferSubpass->AddColorOutput("Light Layer Indices");
|
||||||
gBufferSubpass->AddColorOutput("Normals");
|
gBufferSubpass->AddColorOutput("Normals");
|
||||||
//gBufferSubpass->AddColorOutput("Tangents");
|
|
||||||
gBufferSubpass->AddColorOutput("Albedo");
|
gBufferSubpass->AddColorOutput("Albedo");
|
||||||
gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL);
|
gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL);
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SSAO PASS AND DATA INIT */
|
/* SSAO PASS AND DATA INIT */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
ssaoStorage = resourceManager.Create<SHSSAO>();
|
ssaoStorage = resourceManager.Create<SHSSAO>();
|
||||||
|
|
||||||
|
// command buffer operation to transfer data for ssao
|
||||||
ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||||
SET_VK_OBJ_NAME(device, vk::ObjectType::eCommandBuffer, ssaoTransferCmdBuffer->GetVkCommandBuffer(), "[Command Buffer] SSAO Pass (Graphics)");
|
SET_VK_OBJ_NAME(device, vk::ObjectType::eCommandBuffer, ssaoTransferCmdBuffer->GetVkCommandBuffer(), "[Command Buffer] SSAO Pass (Graphics)");
|
||||||
ssaoTransferCmdBuffer->BeginRecording();
|
ssaoTransferCmdBuffer->BeginRecording();
|
||||||
|
@ -240,50 +253,80 @@ namespace SHADE
|
||||||
|
|
||||||
ssaoTransferCmdBuffer->EndRecording();
|
ssaoTransferCmdBuffer->EndRecording();
|
||||||
graphicsQueue->SubmitCommandBuffer({ ssaoTransferCmdBuffer });
|
graphicsQueue->SubmitCommandBuffer({ ssaoTransferCmdBuffer });
|
||||||
// Set up Debug Draw Passes
|
|
||||||
// - Depth Tested
|
|
||||||
auto debugDrawNodeDepth = worldRenderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"});
|
|
||||||
auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth");
|
|
||||||
debugDrawDepthSubpass->AddColorOutput("Scene");
|
|
||||||
debugDrawDepthSubpass->AddDepthOutput("Depth Buffer");
|
|
||||||
// - No Depth Test
|
|
||||||
auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" });
|
|
||||||
auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw");
|
|
||||||
debugDrawSubpass->AddColorOutput("Scene");
|
|
||||||
|
|
||||||
|
// wait for command buffer to finish executing
|
||||||
graphicsQueue->WaitIdle();
|
graphicsQueue->WaitIdle();
|
||||||
|
|
||||||
ssaoStorage->PrepareRotationVectorsVkData(device);
|
ssaoStorage->PrepareRotationVectorsVkData(device);
|
||||||
|
|
||||||
|
// Add the pass to generate an image with just SSAO data
|
||||||
Handle<SHRenderGraphNodeCompute> ssaoPass = gBufferNode->AddNodeCompute("SSAO", ssaoShader, { "Position", "Normals", "SSAO" });
|
Handle<SHRenderGraphNodeCompute> ssaoPass = gBufferNode->AddNodeCompute("SSAO", ssaoShader, { "Position", "Normals", "SSAO" });
|
||||||
auto ssaoDataBuffer = ssaoStorage->GetBuffer();
|
auto ssaoDataBuffer = ssaoStorage->GetBuffer();
|
||||||
ssaoPass->ModifyWriteDescBufferComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored());
|
ssaoPass->ModifyWriteDescBufferComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored());
|
||||||
auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout();
|
auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout();
|
||||||
|
|
||||||
ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, {&viewSamplerLayout, 1});
|
ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 });
|
||||||
|
|
||||||
|
// Add another pass to blur SSAO
|
||||||
Handle<SHRenderGraphNodeCompute> ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, {"SSAO", "SSAO Blur"});
|
Handle<SHRenderGraphNodeCompute> ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" });
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* DEFERRED COMPOSITE SUBPASS INIT */
|
/* DEFERRED COMPOSITE SUBPASS INIT */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"});
|
gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" });
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* DEBUG DRAW PASS INIT */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
// Set up Debug Draw Passes
|
||||||
|
// - Depth Tested
|
||||||
|
auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"});
|
||||||
|
auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer);
|
||||||
|
debugDrawDepthSubpass->AddColorOutput("Scene");
|
||||||
|
debugDrawDepthSubpass->AddDepthOutput("Depth Buffer");
|
||||||
|
// - No Depth Test
|
||||||
|
auto debugDrawNode = renderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" });
|
||||||
|
auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer);
|
||||||
|
debugDrawSubpass->AddColorOutput("Scene");
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* SCREEN SPACE PASS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"G-Buffer", "Debug Draw" });
|
||||||
|
auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer);
|
||||||
|
uiSubpass->AddColorOutput("Scene");
|
||||||
|
uiSubpass->AddColorOutput("Entity ID");
|
||||||
|
uiSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
|
{
|
||||||
|
textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* RENDER TO SWAPCHAIN IMAGE FOR PRESENT PASS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
#ifdef SHEDITOR
|
||||||
{
|
{
|
||||||
//// Dummy Node to transition scene render graph resource
|
// Dummy Node to transition scene render graph resource
|
||||||
//auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Debug Draw" }); // no predecessors
|
auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" });
|
||||||
//auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass");
|
auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {});
|
||||||
//dummySubpass->AddInput("Scene");
|
dummySubpass->AddInput("Scene");
|
||||||
|
|
||||||
|
auto imGuiNode = renderGraph->AddNode("ImGui Node", { "Present" }, {});
|
||||||
|
auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {});
|
||||||
|
imGuiSubpass->AddColorOutput("Present");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
renderGraph->AddRenderToSwapchainNode("Scene", "Present", { "Screen Space Pass" }, { renderToSwapchainVS, renderToSwapchainFS });
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* GENERATE WORLD RENDER GRAPH */
|
/* GENERATE RENDER GRAPH */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
// Generate world render graph
|
// Generate render graph
|
||||||
worldRenderGraph->Generate();
|
renderGraph->Generate();
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SCREEN RENDER GRAPH */
|
/* SCREEN RENDER GRAPH */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
@ -317,18 +360,7 @@ namespace SHADE
|
||||||
|
|
||||||
screenRenderGraph->Generate();
|
screenRenderGraph->Generate();
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
#endif
|
||||||
/* BIND RENDER GRAPH TO RENDERER */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
// Add world renderer to default viewport
|
|
||||||
worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph);
|
|
||||||
worldRenderer->SetCamera(worldCamera);
|
|
||||||
worldRenderer->SetCameraDirector(worldCameraDirector);
|
|
||||||
|
|
||||||
// Add screen renderer to default viewport
|
|
||||||
screenRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph);
|
|
||||||
screenRenderer->SetCamera(screenCamera);
|
|
||||||
screenRenderer->SetCameraDirector(worldCameraDirector);
|
|
||||||
|
|
||||||
// Create debug draw pipeline
|
// Create debug draw pipeline
|
||||||
debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false);
|
debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false);
|
||||||
|
@ -361,10 +393,12 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
SHPredefinedData::Init(device);
|
SHPredefinedData::Init(device);
|
||||||
|
|
||||||
InitSceneRenderGraph();
|
InitRenderGraph();
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
#if 0
|
||||||
InitEditorRenderGraph();
|
#ifdef SHEDITOR
|
||||||
|
InitEditorRenderGraph();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create Semaphore
|
// Create Semaphore
|
||||||
|
@ -377,7 +411,7 @@ namespace SHADE
|
||||||
void SHGraphicsSystem::InitSubsystems(void) noexcept
|
void SHGraphicsSystem::InitSubsystems(void) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
mousePickSystem = resourceManager.Create<SHMousePickSystem>();
|
mousePickSubSystem = resourceManager.Create<SHMousePickSystem>();
|
||||||
|
|
||||||
std::vector<Handle<SHVkCommandPool>> cmdPools;
|
std::vector<Handle<SHVkCommandPool>> cmdPools;
|
||||||
cmdPools.reserve(swapchain->GetNumImages());
|
cmdPools.reserve(swapchain->GetNumImages());
|
||||||
|
@ -385,11 +419,11 @@ namespace SHADE
|
||||||
cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]);
|
cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]);
|
||||||
|
|
||||||
// Mouse picking system for the editor (Will still run with editor disabled)
|
// Mouse picking system for the editor (Will still run with editor disabled)
|
||||||
mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID"));
|
mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID"));
|
||||||
|
|
||||||
// Register the post offscreen render to the system
|
// Register the post offscreen render to the system
|
||||||
postOffscreenRender = resourceManager.Create<SHPostOffscreenRenderSystem>();
|
postOffscreenRenderSubSystem = resourceManager.Create<SHPostOffscreenRenderSystem>();
|
||||||
postOffscreenRender->Init(device, worldRenderGraph->GetRenderGraphResource("Scene"), descPool);
|
postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool);
|
||||||
|
|
||||||
lightingSubSystem = resourceManager.Create<SHLightingSubSystem>();
|
lightingSubSystem = resourceManager.Create<SHLightingSubSystem>();
|
||||||
lightingSubSystem->Init(device, descPool);
|
lightingSubSystem->Init(device, descPool);
|
||||||
|
@ -397,11 +431,11 @@ namespace SHADE
|
||||||
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
|
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
|
||||||
|
|
||||||
// initialize the text renderer
|
// initialize the text renderer
|
||||||
auto uiNode = screenRenderGraph->GetNode("Screen Space Pass");
|
auto uiNode = renderGraph->GetNode("Screen Space Pass");
|
||||||
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS, [=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
|
||||||
{
|
|
||||||
screenRenderer->BindDescSet(cmdBuffer, frameIndex);
|
SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(texLibrary.GetTextureDescriptorSetGroup());
|
||||||
});
|
SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,41 +459,42 @@ namespace SHADE
|
||||||
defaultMaterial = AddMaterial
|
defaultMaterial = AddMaterial
|
||||||
(
|
(
|
||||||
defaultVertShader, defaultFragShader,
|
defaultVertShader, defaultFragShader,
|
||||||
worldRenderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write")
|
renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write")
|
||||||
);
|
);
|
||||||
defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
|
defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
#if 0
|
||||||
void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept
|
#ifdef SHEDITOR
|
||||||
{
|
void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept
|
||||||
auto windowDims = window->GetWindowSize();
|
{
|
||||||
|
auto windowDims = window->GetWindowSize();
|
||||||
|
|
||||||
// Create Default Viewport
|
// Create Default Viewport
|
||||||
editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 1.0f));
|
editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 1.0f));
|
||||||
|
|
||||||
// Get render graph from viewport editor renderer
|
// Get render graph from viewport editor renderer
|
||||||
editorRenderGraph = resourceManager.Create<SHRenderGraph>();
|
editorRenderGraph = resourceManager.Create<SHRenderGraph>();
|
||||||
|
|
||||||
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
||||||
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
||||||
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
||||||
|
|
||||||
editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager);
|
editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager);
|
||||||
editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second);
|
editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second);
|
||||||
|
|
||||||
|
|
||||||
auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {});
|
auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {});
|
||||||
auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw");
|
auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw");
|
||||||
imguiSubpass->AddColorOutput("Present");
|
imguiSubpass->AddColorOutput("Present");
|
||||||
|
|
||||||
// Generate world render graph
|
// Generate world render graph
|
||||||
editorRenderGraph->Generate();
|
editorRenderGraph->Generate();
|
||||||
|
|
||||||
// Add world renderer to default viewport
|
// Add world renderer to default viewport
|
||||||
editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph);
|
editorRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE);
|
||||||
editorRenderer->SetCamera(worldCamera);
|
}
|
||||||
}
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -547,6 +582,41 @@ namespace SHADE
|
||||||
|
|
||||||
textRenderingSubSystem->Run(frameIndex);
|
textRenderingSubSystem->Run(frameIndex);
|
||||||
|
|
||||||
|
|
||||||
|
for (auto renderer : renderers)
|
||||||
|
{
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
if (renderer == worldRenderer)
|
||||||
|
{
|
||||||
|
auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
|
||||||
|
if (editorSystem->editorState != SHEditor::State::PLAY)
|
||||||
|
worldRenderer->UpdateDataManual(frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix());
|
||||||
|
else
|
||||||
|
renderer->UpdateData(frameIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
renderer->UpdateData(frameIndex);
|
||||||
|
#else
|
||||||
|
renderers[renIndex]->UpdateDataAndBind(frameIndex);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
renderGraph->Begin(frameIndex);
|
||||||
|
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
|
||||||
|
|
||||||
|
// Bind all the buffers required for meshes
|
||||||
|
for (auto& [buffer, bindingPoint] : MESH_DATA)
|
||||||
|
{
|
||||||
|
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
|
||||||
|
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
|
||||||
|
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
|
||||||
|
cmdBuffer->BindIndexBuffer(buffer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderGraph->Execute(frameIndex, descPool);
|
||||||
|
renderGraph->End(frameIndex);
|
||||||
|
|
||||||
|
#if 0
|
||||||
// For every viewport
|
// For every viewport
|
||||||
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
||||||
{
|
{
|
||||||
|
@ -564,10 +634,10 @@ namespace SHADE
|
||||||
// Begin recording the command buffer
|
// Begin recording the command buffer
|
||||||
currentCmdBuffer->BeginRecording();
|
currentCmdBuffer->BeginRecording();
|
||||||
|
|
||||||
// set viewport and scissor
|
//// set viewport and scissor
|
||||||
uint32_t w = static_cast<uint32_t>(viewports[vpIndex]->GetWidth());
|
//uint32_t w = static_cast<uint32_t>(viewports[vpIndex]->GetWidth());
|
||||||
uint32_t h = static_cast<uint32_t>(viewports[vpIndex]->GetHeight());
|
//uint32_t h = static_cast<uint32_t>(viewports[vpIndex]->GetHeight());
|
||||||
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(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS);
|
currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
@ -601,20 +671,20 @@ namespace SHADE
|
||||||
// bind camera data
|
// bind camera data
|
||||||
//renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
//renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
//#ifdef SHEDITOR
|
||||||
if (renderers[renIndex] == worldRenderer)
|
// if (renderers[renIndex] == worldRenderer)
|
||||||
{
|
// {
|
||||||
auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
|
// auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
|
||||||
if (editorSystem->editorState != SHEditor::State::PLAY)
|
// if (editorSystem->editorState != SHEditor::State::PLAY)
|
||||||
worldRenderer->UpdateDataAndBind(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix());
|
// worldRenderer->UpdateDataManual(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix());
|
||||||
else
|
// else
|
||||||
renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
||||||
#else
|
//#else
|
||||||
renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex);
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
// Draw the scene
|
// Draw the scene
|
||||||
renderers[renIndex]->Draw(frameIndex, descPool);
|
renderers[renIndex]->Draw(frameIndex, descPool);
|
||||||
|
@ -638,8 +708,10 @@ namespace SHADE
|
||||||
semIndex = !semIndex;
|
semIndex = !semIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
@ -677,12 +749,8 @@ namespace SHADE
|
||||||
// #BackEndTest: For for the fence initialized by queue submit
|
// #BackEndTest: For for the fence initialized by queue submit
|
||||||
renderContext.WaitForFence();
|
renderContext.WaitForFence();
|
||||||
|
|
||||||
// Finalise all batches
|
// finalize batches for render graph
|
||||||
for (auto vp : viewports)
|
renderGraph->FinaliseBatch(renderContext.GetCurrentFrame(), descPool);
|
||||||
for (auto renderer : vp->GetRenderers())
|
|
||||||
{
|
|
||||||
renderer->GetRenderGraph()->FinaliseBatch(renderContext.GetCurrentFrame(), descPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
// #BackEndTest: Acquire the next image in the swapchain available
|
// #BackEndTest: Acquire the next image in the swapchain available
|
||||||
renderContext.AcquireNextIamge();
|
renderContext.AcquireNextIamge();
|
||||||
|
@ -723,7 +791,7 @@ namespace SHADE
|
||||||
const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame();
|
const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame();
|
||||||
auto& currFrameData = renderContext.GetCurrentFrameData();
|
auto& currFrameData = renderContext.GetCurrentFrameData();
|
||||||
|
|
||||||
mousePickSystem->Run(graphicsQueue, CURR_FRAME_IDX);
|
mousePickSubSystem->Run(graphicsQueue, CURR_FRAME_IDX);
|
||||||
|
|
||||||
// #BackEndTest: queues an image for presentation
|
// #BackEndTest: queues an image for presentation
|
||||||
if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess)
|
if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess)
|
||||||
|
@ -763,6 +831,40 @@ namespace SHADE
|
||||||
viewports.erase(iter);
|
viewports.erase(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Renderer Registration Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHRenderer> SHGraphicsSystem::AddRenderer(SHRenderer::PROJECTION_TYPE projectionType)
|
||||||
|
{
|
||||||
|
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
||||||
|
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
||||||
|
{
|
||||||
|
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the renderer
|
||||||
|
auto renderer = resourceManager.Create<SHRenderer>(device, swapchain->GetNumImages(), renderContextCmdPools, descPool);
|
||||||
|
|
||||||
|
// Store
|
||||||
|
renderers.emplace_back(renderer);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
void SHGraphicsSystem::RemoveRenderer(Handle<SHRenderer> renderer)
|
||||||
|
{
|
||||||
|
auto iter = std::find(renderers.begin(), renderers.end(), renderer);
|
||||||
|
if (iter == renderers.end())
|
||||||
|
{
|
||||||
|
SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove it
|
||||||
|
iter->Free();
|
||||||
|
renderers.erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHMaterial> SHGraphicsSystem::AddMaterial(Handle<SHVkShaderModule> vertShader, Handle<SHVkShaderModule> fragShader, Handle<SHSubpass> subpass)
|
Handle<SHMaterial> SHGraphicsSystem::AddMaterial(Handle<SHVkShaderModule> vertShader, Handle<SHVkShaderModule> fragShader, Handle<SHSubpass> subpass)
|
||||||
{
|
{
|
||||||
// Retrieve pipeline from pipeline storage or create if unavailable
|
// Retrieve pipeline from pipeline storage or create if unavailable
|
||||||
|
@ -1058,7 +1160,7 @@ namespace SHADE
|
||||||
|
|
||||||
renderContext.HandleResize();
|
renderContext.HandleResize();
|
||||||
|
|
||||||
worldRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
renderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
|
|
||||||
|
@ -1067,13 +1169,13 @@ namespace SHADE
|
||||||
//editorViewport->SetWidth(windowDims.first);
|
//editorViewport->SetWidth(windowDims.first);
|
||||||
//editorViewport->SetHeight(windowDims.second);
|
//editorViewport->SetHeight(windowDims.second);
|
||||||
|
|
||||||
editorRenderGraph->HandleResize(windowDims.first, windowDims.second);
|
//editorRenderGraph->HandleResize(windowDims.first, windowDims.second);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
screenRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
//screenRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||||
|
|
||||||
mousePickSystem->HandleResize();
|
mousePickSubSystem->HandleResize();
|
||||||
postOffscreenRender->HandleResize();
|
postOffscreenRenderSubSystem->HandleResize();
|
||||||
|
|
||||||
worldViewport->SetWidth(static_cast<float>(resizeWidth));
|
worldViewport->SetWidth(static_cast<float>(resizeWidth));
|
||||||
worldViewport->SetHeight(static_cast<float>(resizeHeight));
|
worldViewport->SetHeight(static_cast<float>(resizeHeight));
|
||||||
|
@ -1102,9 +1204,14 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Handle<SHRenderGraph> SHGraphicsSystem::GetRenderGraph(void) const noexcept
|
||||||
|
{
|
||||||
|
return renderGraph;
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHRenderGraphNode> SHGraphicsSystem::GetPrimaryRenderpass() const noexcept
|
Handle<SHRenderGraphNode> SHGraphicsSystem::GetPrimaryRenderpass() const noexcept
|
||||||
{
|
{
|
||||||
return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
|
return renderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHVkPipeline> SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept
|
Handle<SHVkPipeline> SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept
|
||||||
|
@ -1137,7 +1244,7 @@ namespace SHADE
|
||||||
device, SHPipelineLayoutParams
|
device, SHPipelineLayoutParams
|
||||||
{
|
{
|
||||||
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
|
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
|
||||||
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA)
|
.predefinedDescSetLayouts = 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);
|
||||||
|
|
|
@ -34,6 +34,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Graphics/MiddleEnd/PostProcessing/SHSSAO.h"
|
#include "Graphics/MiddleEnd/PostProcessing/SHSSAO.h"
|
||||||
#include "Camera/SHCameraDirector.h"
|
#include "Camera/SHCameraDirector.h"
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHFontLibrary.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHFontLibrary.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderer.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,6 @@ namespace SHADE
|
||||||
class SHVkImage;
|
class SHVkImage;
|
||||||
class SHVkFramebuffer;
|
class SHVkFramebuffer;
|
||||||
class SHVkCommandBuffer;
|
class SHVkCommandBuffer;
|
||||||
class SHRenderer;
|
|
||||||
class SHViewport;
|
class SHViewport;
|
||||||
class SHCamera;
|
class SHCamera;
|
||||||
class SHVkShaderModule;
|
class SHVkShaderModule;
|
||||||
|
@ -99,7 +99,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void InitBoilerplate (void) noexcept;
|
void InitBoilerplate (void) noexcept;
|
||||||
void InitSceneRenderGraph (void) noexcept;
|
void InitRenderGraph (void) noexcept;
|
||||||
void InitMiddleEnd (void) noexcept;
|
void InitMiddleEnd (void) noexcept;
|
||||||
void InitSubsystems (void) noexcept;
|
void InitSubsystems (void) noexcept;
|
||||||
void InitBuiltInResources (void);
|
void InitBuiltInResources (void);
|
||||||
|
@ -171,6 +171,13 @@ namespace SHADE
|
||||||
Handle<SHViewport> AddViewport(const vk::Viewport& viewport);
|
Handle<SHViewport> AddViewport(const vk::Viewport& viewport);
|
||||||
void RemoveViewport(Handle<SHViewport> viewport);
|
void RemoveViewport(Handle<SHViewport> viewport);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Renderers Registration Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Handle<SHRenderer> AddRenderer(SHRenderer::PROJECTION_TYPE projectionType);
|
||||||
|
void RemoveRenderer(Handle<SHRenderer> renderer);
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Material Functions */
|
/* Material Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -382,8 +389,9 @@ namespace SHADE
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
Handle<SHViewport> GetEditorViewport () const {return editorViewport;};
|
Handle<SHViewport> GetEditorViewport () const {return editorViewport;};
|
||||||
#endif
|
#endif
|
||||||
Handle<SHMousePickSystem> GetMousePickSystem(void) const noexcept {return mousePickSystem;};
|
Handle<SHMousePickSystem> GetMousePickSystem(void) const noexcept {return mousePickSubSystem;};
|
||||||
Handle<SHPostOffscreenRenderSystem> GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;};
|
Handle<SHPostOffscreenRenderSystem> GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRenderSubSystem;};
|
||||||
|
Handle<SHRenderGraph> GetRenderGraph (void) const noexcept;
|
||||||
Handle<SHRenderGraphNode> GetPrimaryRenderpass() const noexcept;
|
Handle<SHRenderGraphNode> GetPrimaryRenderpass() const noexcept;
|
||||||
Handle<SHVkPipeline> GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept;
|
Handle<SHVkPipeline> GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept;
|
||||||
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
|
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
|
||||||
|
@ -441,10 +449,8 @@ namespace SHADE
|
||||||
// Renderers
|
// Renderers
|
||||||
Handle<SHRenderer> worldRenderer;
|
Handle<SHRenderer> worldRenderer;
|
||||||
Handle<SHRenderer> screenRenderer;
|
Handle<SHRenderer> screenRenderer;
|
||||||
|
std::vector<Handle<SHRenderer>> renderers;
|
||||||
|
|
||||||
// Temp Cameras
|
|
||||||
Handle<SHCamera> worldCamera;
|
|
||||||
Handle<SHCamera> screenCamera;
|
|
||||||
DirectorHandle worldCameraDirector;
|
DirectorHandle worldCameraDirector;
|
||||||
|
|
||||||
|
|
||||||
|
@ -483,15 +489,15 @@ namespace SHADE
|
||||||
std::array<Handle<SHMesh>, MAX_PRIMITIVE_TYPES> primitiveMeshes;
|
std::array<Handle<SHMesh>, MAX_PRIMITIVE_TYPES> primitiveMeshes;
|
||||||
|
|
||||||
// Render Graphs
|
// Render Graphs
|
||||||
Handle<SHRenderGraph> worldRenderGraph;
|
Handle<SHRenderGraph> renderGraph;
|
||||||
Handle<SHRenderGraph> screenRenderGraph;
|
//Handle<SHRenderGraph> screenRenderGraph;
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
Handle<SHRenderGraph> editorRenderGraph;
|
//Handle<SHRenderGraph> editorRenderGraph;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Sub systems
|
// Sub systems
|
||||||
Handle<SHMousePickSystem> mousePickSystem;
|
Handle<SHMousePickSystem> mousePickSubSystem;
|
||||||
Handle<SHPostOffscreenRenderSystem> postOffscreenRender;
|
Handle<SHPostOffscreenRenderSystem> postOffscreenRenderSubSystem;
|
||||||
Handle<SHLightingSubSystem> lightingSubSystem;
|
Handle<SHLightingSubSystem> lightingSubSystem;
|
||||||
Handle<SHTextRenderingSubSystem> textRenderingSubSystem;
|
Handle<SHTextRenderingSubSystem> textRenderingSubSystem;
|
||||||
Handle<SHSSAO> ssaoStorage;
|
Handle<SHSSAO> ssaoStorage;
|
||||||
|
|
|
@ -14,7 +14,6 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
#include "SHRenderer.h"
|
#include "SHRenderer.h"
|
||||||
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||||
#include "SHViewport.h"
|
|
||||||
#include "Graphics/Buffers/SHVkBuffer.h"
|
#include "Graphics/Buffers/SHVkBuffer.h"
|
||||||
#include "Graphics/Framebuffer/SHVkFramebuffer.h"
|
#include "Graphics/Framebuffer/SHVkFramebuffer.h"
|
||||||
#include "SHMaterial.h"
|
#include "SHMaterial.h"
|
||||||
|
@ -22,22 +21,22 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
|
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
|
||||||
#include "Graphics/Buffers/SHVkBuffer.h"
|
#include "Graphics/Buffers/SHVkBuffer.h"
|
||||||
#include "Camera/SHCameraDirector.h"
|
#include "Camera/SHCameraDirector.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Constructor/Destructors */
|
/* Constructor/Destructors */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
SHRenderer::SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph)
|
SHRenderer::SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, PROJECTION_TYPE type)
|
||||||
: viewport { viewport }
|
: projectionType{type}
|
||||||
, renderGraph { renderGraph }
|
|
||||||
{
|
{
|
||||||
commandBuffers.resize(static_cast<std::size_t>(numFrames));
|
//commandBuffers.resize(static_cast<std::size_t>(numFrames));
|
||||||
|
|
||||||
for (uint32_t i = 0; i < commandBuffers.size(); ++i)
|
//for (uint32_t i = 0; i < commandBuffers.size(); ++i)
|
||||||
commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
// commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||||
|
|
||||||
cameraDescriptorSet = descriptorPool->Allocate({ cameraDescLayout }, { 1 });
|
cameraDescriptorSet = descriptorPool->Allocate(SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 });
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle();
|
const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle();
|
||||||
|
@ -61,18 +60,6 @@ namespace SHADE
|
||||||
|
|
||||||
SHRenderer::~SHRenderer(void)
|
SHRenderer::~SHRenderer(void)
|
||||||
{
|
{
|
||||||
//for (auto& cmdBuffer : commandBuffers)
|
|
||||||
//{
|
|
||||||
// cmdBuffer.Free();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
/* Camera Registration */
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
void SHRenderer::SetCamera(Handle<SHCamera> _camera)
|
|
||||||
{
|
|
||||||
camera = _camera;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRenderer::SetCameraDirector(Handle<SHCameraDirector> director) noexcept
|
void SHRenderer::SetCameraDirector(Handle<SHCameraDirector> director) noexcept
|
||||||
|
@ -80,63 +67,55 @@ namespace SHADE
|
||||||
cameraDirector = director;
|
cameraDirector = director;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
void SHRenderer::UpdateData(uint32_t frameIndex) noexcept
|
||||||
/* Drawing Functions */
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
void SHRenderer::Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept
|
|
||||||
{
|
{
|
||||||
renderGraph->Execute(frameIndex, commandBuffers[frameIndex], descPool);
|
if (cameraDirector)
|
||||||
}
|
|
||||||
|
|
||||||
void SHRenderer::UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
|
||||||
{
|
|
||||||
if (camera && cameraDirector)
|
|
||||||
{
|
{
|
||||||
//UpdateDataAndBind(cmdBuffer, frameIndex, SHMatrix::Transpose(cameraDirector->GetVPMatrix()));
|
switch (projectionType)
|
||||||
UpdateDataAndBind(cmdBuffer, frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix(), cameraDirector->GetOrthoMatrix());
|
{
|
||||||
|
case PROJECTION_TYPE::DEFAULT:
|
||||||
|
UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix());
|
||||||
|
break;
|
||||||
|
case PROJECTION_TYPE::PERSPECTIVE:
|
||||||
|
UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetPerspectiveMatrix());
|
||||||
|
break;
|
||||||
|
case PROJECTION_TYPE::ORTHOGRAPHIC:
|
||||||
|
UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetOrthoMatrix());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRenderer::UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept
|
void SHRenderer::UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept
|
||||||
{
|
{
|
||||||
SetViewProjectionMatrix(viewMatrix, projMatrix, orthoMatrix);
|
SetViewProjectionMatrix(viewMatrix, projMatrix);
|
||||||
|
|
||||||
//cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
|
||||||
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
||||||
|
|
||||||
BindDescSet(cmdBuffer, frameIndex);
|
//BindDescSet(cmdBuffer, frameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRenderer::BindDescSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
void SHRenderer::BindDescriptorSet(Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
||||||
|
|
||||||
cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 });
|
cmdBuffer->BindDescriptorSet(cameraDescriptorSet, pipelineType, setIndex, std::span{ dynamicOffsets.data(), 1 });
|
||||||
cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRenderer::UpdateCameraDataToBuffer(void) noexcept
|
void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept
|
|
||||||
{
|
|
||||||
//cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix();
|
|
||||||
cpuCameraData.viewProjectionMatrix = SHMatrix::Transpose(projMatrix * viewMatrix);
|
cpuCameraData.viewProjectionMatrix = SHMatrix::Transpose(projMatrix * viewMatrix);
|
||||||
cpuCameraData.viewMatrix = SHMatrix::Transpose(viewMatrix);
|
cpuCameraData.viewMatrix = SHMatrix::Transpose(viewMatrix);
|
||||||
cpuCameraData.projectionMatrix = SHMatrix::Transpose(projMatrix);
|
cpuCameraData.projectionMatrix = SHMatrix::Transpose(projMatrix);
|
||||||
cpuCameraData.orthoMatrix = SHMatrix::Transpose (orthoMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept
|
//Handle<SHVkCommandBuffer> SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept
|
||||||
{
|
//{
|
||||||
return renderGraph;
|
// return commandBuffers[frameIndex];
|
||||||
}
|
//}
|
||||||
|
|
||||||
Handle<SHVkCommandBuffer> SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept
|
|
||||||
{
|
|
||||||
return commandBuffers[frameIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle<SHCameraDirector> SHRenderer::GetCameraDirector(void) const noexcept
|
Handle<SHCameraDirector> SHRenderer::GetCameraDirector(void) const noexcept
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,6 @@ namespace SHADE
|
||||||
class SHVkFramebuffer;
|
class SHVkFramebuffer;
|
||||||
class SHMaterial;
|
class SHMaterial;
|
||||||
class SHVkLogicalDevice;
|
class SHVkLogicalDevice;
|
||||||
class SHViewport;
|
|
||||||
class SHVkImageView;
|
class SHVkImageView;
|
||||||
class SHVkCommandBuffer;
|
class SHVkCommandBuffer;
|
||||||
class SHCamera;
|
class SHCamera;
|
||||||
|
@ -48,7 +47,6 @@ namespace SHADE
|
||||||
SHMatrix viewProjectionMatrix;
|
SHMatrix viewProjectionMatrix;
|
||||||
SHMatrix viewMatrix;
|
SHMatrix viewMatrix;
|
||||||
SHMatrix projectionMatrix;
|
SHMatrix projectionMatrix;
|
||||||
SHMatrix orthoMatrix;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -64,35 +62,36 @@ namespace SHADE
|
||||||
/***********************************************************************************/
|
/***********************************************************************************/
|
||||||
class SHRenderer
|
class SHRenderer
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class PROJECTION_TYPE
|
||||||
|
{
|
||||||
|
DEFAULT,
|
||||||
|
PERSPECTIVE,
|
||||||
|
ORTHOGRAPHIC
|
||||||
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructor/Destructors */
|
/* Constructor/Destructors */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHViewport> viewport, Handle<SHRenderGraph> renderGraph);
|
SHRenderer(Handle<SHVkLogicalDevice> logicalDevice, uint32_t numFrames, Handle<SHVkDescriptorPool> descriptorPool, PROJECTION_TYPE type);
|
||||||
~SHRenderer(void);
|
~SHRenderer(void);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Camera Registration */
|
/* Camera Registration */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void SetCamera(Handle<SHCamera> _camera);
|
|
||||||
void SetCameraDirector (Handle<SHCameraDirector> director) noexcept;
|
void SetCameraDirector (Handle<SHCameraDirector> director) noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Drawing Functions */
|
/* Drawing Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
void UpdateData(uint32_t frameIndex) noexcept;
|
||||||
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
||||||
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept;
|
void BindDescriptorSet (Handle<SHVkCommandBuffer> cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept;
|
||||||
void BindDescSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
||||||
void UpdateCameraDataToBuffer (void) noexcept;
|
|
||||||
void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Setters and Getters */
|
/* Setters and Getters */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Handle<SHRenderGraph> GetRenderGraph (void) const noexcept;
|
|
||||||
Handle<SHVkCommandBuffer> GetCommandBuffer(uint32_t frameIndex) const noexcept;
|
|
||||||
Handle<SHCameraDirector> GetCameraDirector (void) const noexcept;
|
Handle<SHCameraDirector> GetCameraDirector (void) const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -102,9 +101,6 @@ namespace SHADE
|
||||||
//! Vulkan UBOs need to be aligned, this is pad SHShaderCameraData struct
|
//! Vulkan UBOs need to be aligned, this is pad SHShaderCameraData struct
|
||||||
uint32_t cameraDataAlignedSize;
|
uint32_t cameraDataAlignedSize;
|
||||||
|
|
||||||
Handle<SHViewport> viewport;
|
|
||||||
Handle<SHCamera> camera;
|
|
||||||
Handle<SHRenderGraph> renderGraph;
|
|
||||||
Handle<SHVkDescriptorSetGroup> cameraDescriptorSet;
|
Handle<SHVkDescriptorSetGroup> cameraDescriptorSet;
|
||||||
Handle<SHVkBuffer> cameraBuffer;
|
Handle<SHVkBuffer> cameraBuffer;
|
||||||
|
|
||||||
|
@ -114,10 +110,10 @@ namespace SHADE
|
||||||
// GPU.
|
// GPU.
|
||||||
SHShaderCameraData cpuCameraData;
|
SHShaderCameraData cpuCameraData;
|
||||||
|
|
||||||
//! Command buffers for the render graph
|
////! Command buffers for the render graph
|
||||||
std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
|
//std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
|
||||||
|
|
||||||
|
|
||||||
|
PROJECTION_TYPE projectionType;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,34 +46,6 @@ namespace SHADE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Renderer Registration Functions */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
Handle<SHRenderer> SHViewport::AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph)
|
|
||||||
{
|
|
||||||
// Create the renderer
|
|
||||||
auto renderer = resourceManager.Create<SHRenderer>(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph);
|
|
||||||
|
|
||||||
// Store
|
|
||||||
renderers.emplace_back(renderer);
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
void SHViewport::RemoveRenderer(Handle<SHRenderer> renderer)
|
|
||||||
{
|
|
||||||
auto iter = std::find(renderers.begin(), renderers.end(), renderer);
|
|
||||||
if (iter == renderers.end())
|
|
||||||
{
|
|
||||||
SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove it
|
|
||||||
iter->Free();
|
|
||||||
renderers.erase(iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SHViewport::SetWidth(float w) noexcept
|
void SHViewport::SetWidth(float w) noexcept
|
||||||
{
|
{
|
||||||
viewport.width = w;
|
viewport.width = w;
|
||||||
|
|
|
@ -56,11 +56,11 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void SetUp(Handle<SHVkCommandBuffer> commandBuffer);
|
void SetUp(Handle<SHVkCommandBuffer> commandBuffer);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
///*-----------------------------------------------------------------------------*/
|
||||||
/* Renderers Registration Functions */
|
///* Renderers Registration Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
///*-----------------------------------------------------------------------------*/
|
||||||
Handle<SHRenderer> AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph);
|
//Handle<SHRenderer> AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph);
|
||||||
void RemoveRenderer(Handle<SHRenderer> renderer);
|
//void RemoveRenderer(Handle<SHRenderer> renderer);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Setters */
|
/* Setters */
|
||||||
|
@ -79,7 +79,7 @@ namespace SHADE
|
||||||
float GetHeight() const { return viewport.height; }
|
float GetHeight() const { return viewport.height; }
|
||||||
float GetMinDepth() const { return viewport.minDepth; }
|
float GetMinDepth() const { return viewport.minDepth; }
|
||||||
float GetMaxDepth() const { return viewport.maxDepth; }
|
float GetMaxDepth() const { return viewport.maxDepth; }
|
||||||
std::vector<Handle<SHRenderer>>& GetRenderers() { return renderers; }
|
//std::vector<Handle<SHRenderer>>& GetRenderers() { return renderers; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -88,7 +88,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Handle<SHVkLogicalDevice> device;
|
Handle<SHVkLogicalDevice> device;
|
||||||
vk::Viewport viewport;
|
vk::Viewport viewport;
|
||||||
std::vector<Handle<SHRenderer>> renderers;
|
//std::vector<Handle<SHRenderer>> renderers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -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({ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes);
|
lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, 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)
|
||||||
|
@ -517,11 +517,16 @@ namespace SHADE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHLightingSubSystem::BindDescSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
void SHLightingSubSystem::BindDescSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
//Bind descriptor set(We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data).
|
//Bind descriptor set(We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data).
|
||||||
cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, { dynamicOffsets[frameIndex] });
|
cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, setIndex, { dynamicOffsets[frameIndex] });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<SHVkDescriptorSetGroup> SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept
|
||||||
|
{
|
||||||
|
return lightingDataDescSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "Math/Vector/SHVec3.h"
|
#include "Math/Vector/SHVec3.h"
|
||||||
#include "Math/Vector/SHVec4.h"
|
#include "Math/Vector/SHVec4.h"
|
||||||
#include "SHLightData.h"
|
#include "SHLightData.h"
|
||||||
|
#include <array>
|
||||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -57,8 +58,11 @@ namespace SHADE
|
||||||
|
|
||||||
class SH_API SHLightingSubSystem
|
class SH_API SHLightingSubSystem
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
|
using DynamicOffsetArray = std::array<std::vector<uint32_t>, static_cast<uint32_t>(SHGraphicsConstants::NUM_FRAME_BUFFERS)>;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
class PerTypeData
|
class PerTypeData
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -130,7 +134,7 @@ namespace SHADE
|
||||||
std::array<PerTypeData, static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData;
|
std::array<PerTypeData, static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData;
|
||||||
|
|
||||||
//! Container to store dynamic offsets for binding descriptor sets
|
//! Container to store dynamic offsets for binding descriptor sets
|
||||||
std::array<std::vector<uint32_t>, static_cast<uint32_t>(SHGraphicsConstants::NUM_FRAME_BUFFERS)> dynamicOffsets;
|
DynamicOffsetArray dynamicOffsets;
|
||||||
|
|
||||||
//! holds the data that represents how many lights are in the scene
|
//! holds the data that represents how many lights are in the scene
|
||||||
std::array<uint32_t, static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData;
|
std::array<uint32_t, static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData;
|
||||||
|
@ -162,7 +166,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 frameIndex) noexcept;
|
void BindDescSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept;
|
||||||
|
Handle<SHVkDescriptorSetGroup> GetLightDataDescriptorSet (void) const noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "Graphics/SHVkUtil.h"
|
#include "Graphics/SHVkUtil.h"
|
||||||
#include "Graphics/RenderGraph/SHSubpass.h"
|
#include "Graphics/RenderGraph/SHSubpass.h"
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderer.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -91,12 +93,10 @@ namespace SHADE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS, std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> const& bindFunction) noexcept
|
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept
|
||||||
{
|
{
|
||||||
SHComponentManager::CreateComponentSparseSet<SHTextRenderableComponent>();
|
SHComponentManager::CreateComponentSparseSet<SHTextRenderableComponent>();
|
||||||
|
|
||||||
cameraDescSetBind = bindFunction;
|
|
||||||
|
|
||||||
logicalDevice = device;
|
logicalDevice = device;
|
||||||
|
|
||||||
// prepare pipeline layout params
|
// prepare pipeline layout params
|
||||||
|
@ -174,9 +174,14 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
auto& textRendererComps = SHComponentManager::GetDense<SHTextRenderableComponent>();
|
auto& textRendererComps = SHComponentManager::GetDense<SHTextRenderableComponent>();
|
||||||
|
auto const& mappings = SHPredefinedData::GetTextSystemData().descMappings;
|
||||||
|
uint32_t fontSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::FONT);
|
||||||
|
uint32_t staticGlobalSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA);
|
||||||
|
uint32_t cameraSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA);
|
||||||
|
|
||||||
for (auto& comp : textRendererComps)
|
for (auto& comp : textRendererComps)
|
||||||
{
|
{
|
||||||
auto* transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID());
|
auto* transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID());
|
||||||
|
@ -187,16 +192,19 @@ namespace SHADE
|
||||||
// bind the pipeline
|
// bind the pipeline
|
||||||
cmdBuffer->BindPipeline(pipeline);
|
cmdBuffer->BindPipeline(pipeline);
|
||||||
|
|
||||||
|
// Bind global data
|
||||||
|
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, staticGlobalSetIndex);
|
||||||
|
|
||||||
|
// Bind camera data
|
||||||
|
renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex);
|
||||||
|
|
||||||
|
// bind descriptors for font (matrices)
|
||||||
|
cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, fontSetIndex, {});
|
||||||
|
|
||||||
// bind VBO (position and indices)
|
// bind VBO (position and indices)
|
||||||
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);
|
|
||||||
|
|
||||||
// bind descriptors for font (matrices)
|
|
||||||
cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {});
|
|
||||||
|
|
||||||
cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS);
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS);
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
cmdBuffer->SetPushConstantVariable("TestPushConstant.textColor", SHVec3 (1.0f, 1.0f, 1.0f), SH_PIPELINE_TYPE::GRAPHICS);
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.textColor", SHVec3 (1.0f, 1.0f, 1.0f), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
@ -206,9 +214,7 @@ namespace SHADE
|
||||||
// call draw call
|
// call draw call
|
||||||
cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0);
|
cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0);
|
||||||
//glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast<GLsizei>(textComp.lastRenderedCharacterIndex) + 1);
|
//glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast<GLsizei>(textComp.lastRenderedCharacterIndex) + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,18 +43,14 @@ namespace SHADE
|
||||||
//! 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
|
|
||||||
//! entire graphics system.
|
|
||||||
std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> cameraDescSetBind;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RecomputePositions(SHTextRenderableComponent& textComp) noexcept;
|
void RecomputePositions(SHTextRenderableComponent& textComp) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS, std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> const& bindFunction) noexcept;
|
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept;
|
||||||
void Run(uint32_t frameIndex) noexcept;
|
void Run(uint32_t frameIndex) noexcept;
|
||||||
|
|
||||||
void Render (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void Render (Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex) noexcept;
|
||||||
void Exit(void) noexcept;
|
void Exit(void) noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "Tools/Utilities/SHUtilities.h"
|
#include "Tools/Utilities/SHUtilities.h"
|
||||||
#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
|
#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
|
||||||
#include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h"
|
#include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -424,7 +426,7 @@ namespace SHADE
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
void SHRenderGraph::Init(std::string graphName, Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain, SHResourceHub* resourceHub) noexcept
|
void SHRenderGraph::Init(std::string graphName, Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain, SHResourceHub* resourceHub, std::vector<Handle<SHVkCommandPool>>& cmdPools) noexcept
|
||||||
{
|
{
|
||||||
//resourceHub = std::make_shared<SHResourceHub>();
|
//resourceHub = std::make_shared<SHResourceHub>();
|
||||||
|
|
||||||
|
@ -437,6 +439,11 @@ namespace SHADE
|
||||||
renderGraphStorage->resourceHub = resourceHub;
|
renderGraphStorage->resourceHub = resourceHub;
|
||||||
renderGraphStorage->descriptorPool = logicalDevice->CreateDescriptorPools();
|
renderGraphStorage->descriptorPool = logicalDevice->CreateDescriptorPools();
|
||||||
|
|
||||||
|
commandBuffers.resize(static_cast<std::size_t>(swapchain->GetNumImages()));
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < commandBuffers.size(); ++i)
|
||||||
|
commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||||
|
|
||||||
name = std::move(graphName);
|
name = std::move(graphName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,16 +562,22 @@ namespace SHADE
|
||||||
if (renderGraphStorage->graphResources->contains(toSwapchainResource) && renderGraphStorage->graphResources->contains(swapchainResource))
|
if (renderGraphStorage->graphResources->contains(toSwapchainResource) && renderGraphStorage->graphResources->contains(swapchainResource))
|
||||||
{
|
{
|
||||||
auto newNode = AddNode("Render To Present", { ResourceInstruction (toSwapchainResource.c_str()), ResourceInstruction(swapchainResource.c_str()) }, predecessorNodes);
|
auto newNode = AddNode("Render To Present", { ResourceInstruction (toSwapchainResource.c_str()), ResourceInstruction(swapchainResource.c_str()) }, predecessorNodes);
|
||||||
auto newSubpass = newNode->AddSubpass("Render");
|
auto newSubpass = newNode->AddSubpass("Render", {}, {});
|
||||||
newSubpass->AddColorOutput(swapchainResource);
|
newSubpass->AddColorOutput(swapchainResource);
|
||||||
newSubpass->AddInput(toSwapchainResource);
|
newSubpass->AddInput(toSwapchainResource);
|
||||||
|
|
||||||
renderToSwapchainImageSystem = renderGraphStorage->resourceHub->Create<SHRenderToSwapchainImageSystem> (newNode, newSubpass, shaderModules);
|
renderToSwapchainImageSystem = renderGraphStorage->resourceHub->Create<SHRenderToSwapchainImageSystem> (newNode, newSubpass, shaderModules);
|
||||||
|
|
||||||
newSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
newSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline());
|
cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline());
|
||||||
|
|
||||||
|
// If we are rendering to present image, the width and height will be the dimensions of that image. So we need to set viewport scissor.
|
||||||
|
auto resource = renderGraphStorage->graphResources->at(swapchainResource);
|
||||||
|
uint32_t w = static_cast<uint32_t>(resource->GetWidth());
|
||||||
|
uint32_t h = static_cast<uint32_t>(resource->GetHeight());
|
||||||
|
cmdBuffer->SetViewportScissor(static_cast<float>(w), static_cast<float>(h), w, h);
|
||||||
|
|
||||||
newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex);
|
newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex);
|
||||||
|
|
||||||
// draw a quad.
|
// draw a quad.
|
||||||
|
@ -616,14 +629,39 @@ namespace SHADE
|
||||||
|
|
||||||
// TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a
|
// TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a
|
||||||
// better way to manage these
|
// better way to manage these
|
||||||
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHVkDescriptorPool> descPool) noexcept
|
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept
|
||||||
{
|
{
|
||||||
|
auto cmdBuffer = commandBuffers[frameIndex];
|
||||||
cmdBuffer->BeginLabeledSegment(name);
|
cmdBuffer->BeginLabeledSegment(name);
|
||||||
|
|
||||||
|
// Force bind pipeline layout
|
||||||
|
cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE);
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
|
||||||
for (auto& node : nodes)
|
for (auto& node : nodes)
|
||||||
|
{
|
||||||
|
// bind static global data
|
||||||
|
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA));
|
||||||
|
|
||||||
node->Execute(cmdBuffer, descPool, frameIndex);
|
node->Execute(cmdBuffer, descPool, frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
cmdBuffer->EndLabeledSegment();
|
cmdBuffer->EndLabeledSegment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHRenderGraph::Begin(uint32_t frameIndex) noexcept
|
||||||
|
{
|
||||||
|
commandBuffers[frameIndex]->BeginRecording();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHRenderGraph::End(uint32_t frameIndex) noexcept
|
||||||
|
{
|
||||||
|
commandBuffers[frameIndex]->EndRecording();
|
||||||
|
}
|
||||||
|
|
||||||
void SHRenderGraph::FinaliseBatch(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
|
void SHRenderGraph::FinaliseBatch(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
|
||||||
{
|
{
|
||||||
for (auto& node : nodes)
|
for (auto& node : nodes)
|
||||||
|
@ -670,4 +708,9 @@ namespace SHADE
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<SHVkCommandBuffer> SHRenderGraph::GetCommandBuffer(uint32_t frameIndex) const noexcept
|
||||||
|
{
|
||||||
|
return commandBuffers[frameIndex];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -74,6 +74,9 @@ namespace SHADE
|
||||||
//! For rendering onto the swapchain
|
//! For rendering onto the swapchain
|
||||||
Handle<SHRenderToSwapchainImageSystem> renderToSwapchainImageSystem;
|
Handle<SHRenderToSwapchainImageSystem> renderToSwapchainImageSystem;
|
||||||
|
|
||||||
|
//! Command buffer to issue rendering commands
|
||||||
|
std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* CTORS AND DTORS */
|
/* CTORS AND DTORS */
|
||||||
|
@ -86,7 +89,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* PUBLIC MEMBER FUNCTIONS */
|
/* PUBLIC MEMBER FUNCTIONS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void Init (std::string graphName, Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain, SHResourceHub* resourceHub) noexcept;
|
void Init (std::string graphName, Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkSwapchain> swapchain, SHResourceHub* resourceHub, std::vector<Handle<SHVkCommandPool>>& cmdPools) noexcept;
|
||||||
void AddResource(std::string resourceName, std::initializer_list<SH_RENDER_GRAPH_RESOURCE_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 = {});
|
void AddResource(std::string resourceName, std::initializer_list<SH_RENDER_GRAPH_RESOURCE_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 = {});
|
||||||
void LinkNonOwningResource (Handle<SHRenderGraph> resourceOrigin, std::string resourceName) noexcept;
|
void LinkNonOwningResource (Handle<SHRenderGraph> resourceOrigin, std::string resourceName) noexcept;
|
||||||
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<ResourceInstruction> resourceInstruction, std::initializer_list<std::string> predecessorNodes) noexcept;
|
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<ResourceInstruction> resourceInstruction, std::initializer_list<std::string> predecessorNodes) noexcept;
|
||||||
|
@ -94,16 +97,19 @@ namespace SHADE
|
||||||
|
|
||||||
void Generate (void) noexcept;
|
void Generate (void) noexcept;
|
||||||
void CheckForNodeComputes (void) noexcept;
|
void CheckForNodeComputes (void) noexcept;
|
||||||
void Execute (uint32_t frameIndex, Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHVkDescriptorPool> descPool) noexcept;
|
void Execute (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
||||||
|
void Begin (uint32_t frameIndex) noexcept;
|
||||||
|
void End (uint32_t frameIndex) noexcept;
|
||||||
void FinaliseBatch (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
void FinaliseBatch (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||||
void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept;
|
void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
Handle<SHRenderGraphNode> GetNode (std::string const& nodeName) const noexcept;
|
Handle<SHRenderGraphNode> GetNode (std::string const& nodeName) const noexcept;
|
||||||
std::vector<Handle<SHRenderGraphNode>> const& GetNodes (void) const noexcept;
|
std::vector<Handle<SHRenderGraphNode>> const& GetNodes (void) const noexcept;
|
||||||
Handle<SHRenderGraphResource> GetRenderGraphResource (std::string const& resourceName) const noexcept;
|
Handle<SHRenderGraphResource> GetRenderGraphResource (std::string const& resourceName) const noexcept;
|
||||||
|
Handle<SHVkCommandBuffer> GetCommandBuffer (uint32_t frameIndex) const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "SHRenderGraphStorage.h"
|
#include "SHRenderGraphStorage.h"
|
||||||
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
|
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
|
||||||
#include "Graphics/SHVkUtil.h"
|
#include "Graphics/SHVkUtil.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -238,7 +240,7 @@ namespace SHADE
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
Handle<SHSubpass> SHRenderGraphNode::AddSubpass(std::string subpassName) noexcept
|
Handle<SHSubpass> SHRenderGraphNode::AddSubpass(std::string subpassName, Handle<SHViewport> viewport, Handle<SHRenderer> renderer) noexcept
|
||||||
{
|
{
|
||||||
// if subpass already exists, don't add.
|
// if subpass already exists, don't add.
|
||||||
if (subpassIndexing.contains(subpassName))
|
if (subpassIndexing.contains(subpassName))
|
||||||
|
@ -253,6 +255,8 @@ namespace SHADE
|
||||||
graphStorage->resourceHub->Create<SHSubpass>
|
graphStorage->resourceHub->Create<SHSubpass>
|
||||||
(
|
(
|
||||||
subpassName,
|
subpassName,
|
||||||
|
viewport,
|
||||||
|
renderer,
|
||||||
graphStorage, GetHandle(), static_cast<uint32_t>(subpasses.size()),
|
graphStorage, GetHandle(), static_cast<uint32_t>(subpasses.size()),
|
||||||
resourceAttachmentMapping.get()
|
resourceAttachmentMapping.get()
|
||||||
)
|
)
|
||||||
|
@ -318,7 +322,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert them all for a subpass to transition them. This subpass is the last subpass
|
// insert them all for a subpass to transition them. This subpass is the last subpass
|
||||||
auto dummySubpass = AddSubpass("dummy");
|
auto dummySubpass = AddSubpass("dummy", {}, {});
|
||||||
for (auto& resource : resourcesInvolved)
|
for (auto& resource : resourcesInvolved)
|
||||||
{
|
{
|
||||||
dummySubpass->AddGeneralInput(resource);
|
dummySubpass->AddGeneralInput(resource);
|
||||||
|
@ -331,7 +335,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRenderGraphNode::Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept
|
void SHRenderGraphNode::Execute(Handle<SHVkCommandBuffer> commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0;
|
uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0;
|
||||||
commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]);
|
commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]);
|
||||||
|
@ -347,10 +351,14 @@ namespace SHADE
|
||||||
|
|
||||||
commandBuffer->EndRenderpass();
|
commandBuffer->EndRenderpass();
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
|
||||||
// Execute all subpass computes
|
// Execute all subpass computes
|
||||||
for (auto& sbCompute : nodeComputes)
|
for (auto& sbCompute : nodeComputes)
|
||||||
{
|
{
|
||||||
|
// bind lighting data
|
||||||
|
SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex);
|
||||||
|
|
||||||
sbCompute->Execute(commandBuffer, frameIndex);
|
sbCompute->Execute(commandBuffer, frameIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ namespace SHADE
|
||||||
class SHPredefinedData;
|
class SHPredefinedData;
|
||||||
class SHRenderGraphStorage;
|
class SHRenderGraphStorage;
|
||||||
class SHRenderGraphNodeCompute;
|
class SHRenderGraphNodeCompute;
|
||||||
|
class SHRenderer;
|
||||||
|
class SHViewport;
|
||||||
|
|
||||||
class SH_API SHRenderGraphNode : public ISelfHandle<SHRenderGraphNode>
|
class SH_API SHRenderGraphNode : public ISelfHandle<SHRenderGraphNode>
|
||||||
{
|
{
|
||||||
|
@ -102,12 +104,12 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* PUBLIC MEMBER FUNCTIONS */
|
/* PUBLIC MEMBER FUNCTIONS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
Handle<SHSubpass> AddSubpass(std::string subpassName) 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 = {}, float numWorkGroupScale = 1.0f) noexcept;
|
||||||
void AddDummySubpassIfNeeded (void) noexcept;
|
void AddDummySubpassIfNeeded (void) noexcept;
|
||||||
|
|
||||||
// TODO: RemoveSubpass()
|
// TODO: RemoveSubpass()
|
||||||
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;
|
||||||
void FinaliseBatch(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
void FinaliseBatch(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ namespace SHADE
|
||||||
//! Compute resources
|
//! Compute resources
|
||||||
Handle<ComputeResource> computeResource;
|
Handle<ComputeResource> computeResource;
|
||||||
|
|
||||||
|
//!
|
||||||
|
|
||||||
//! vector of resources needed by the subpass compute
|
//! vector of resources needed by the subpass compute
|
||||||
std::vector<Handle<SHRenderGraphResource>> resources;
|
std::vector<Handle<SHRenderGraphResource>> resources;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
#include "Graphics/Swapchain/SHVkSwapchain.h"
|
#include "Graphics/Swapchain/SHVkSwapchain.h"
|
||||||
#include "Graphics/Images/SHVkSampler.h"
|
#include "Graphics/Images/SHVkSampler.h"
|
||||||
#include "SHRenderGraphResource.h"
|
#include "SHRenderGraphResource.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHViewport.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderer.h"
|
||||||
|
#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -30,7 +33,7 @@ namespace SHADE
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
SHSubpass::SHSubpass(const std::string& name, Handle<SHRenderGraphStorage> renderGraphStorage, Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping) noexcept
|
SHSubpass::SHSubpass(const std::string& name, Handle<SHViewport> inViewport, Handle<SHRenderer> inRenderer, Handle<SHRenderGraphStorage> renderGraphStorage, Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping) noexcept
|
||||||
: resourceAttachmentMapping{ mapping }
|
: resourceAttachmentMapping{ mapping }
|
||||||
, parentNode{ parent }
|
, parentNode{ parent }
|
||||||
, subpassIndex{ index }
|
, subpassIndex{ index }
|
||||||
|
@ -41,6 +44,8 @@ namespace SHADE
|
||||||
, name { name }
|
, name { name }
|
||||||
, graphStorage{ renderGraphStorage }
|
, graphStorage{ renderGraphStorage }
|
||||||
, inputImageDescriptorSets{}
|
, inputImageDescriptorSets{}
|
||||||
|
, viewport {inViewport}
|
||||||
|
, renderer {inRenderer}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +76,8 @@ namespace SHADE
|
||||||
, inputDescriptorLayout{ rhs.inputDescriptorLayout }
|
, inputDescriptorLayout{ rhs.inputDescriptorLayout }
|
||||||
, inputSamplers{ rhs.inputSamplers }
|
, inputSamplers{ rhs.inputSamplers }
|
||||||
, name { rhs.name }
|
, name { rhs.name }
|
||||||
|
, viewport {rhs.viewport}
|
||||||
|
, renderer {rhs.renderer}
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,6 +113,9 @@ namespace SHADE
|
||||||
inputDescriptorLayout = rhs.inputDescriptorLayout;
|
inputDescriptorLayout = rhs.inputDescriptorLayout;
|
||||||
inputSamplers = rhs.inputSamplers;
|
inputSamplers = rhs.inputSamplers;
|
||||||
name = std::move(rhs.name);
|
name = std::move(rhs.name);
|
||||||
|
renderer = rhs.renderer;
|
||||||
|
viewport = rhs.viewport;
|
||||||
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -199,21 +209,33 @@ namespace SHADE
|
||||||
inputReferences.push_back({ resourceAttachmentMapping->at(graphStorage->graphResources->at(resourceToReference).GetId().Raw), vk::ImageLayout::eGeneral });
|
inputReferences.push_back({ resourceAttachmentMapping->at(graphStorage->graphResources->at(resourceToReference).GetId().Raw), vk::ImageLayout::eGeneral });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSubpass::Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept
|
void SHSubpass::Execute(Handle<SHVkCommandBuffer> commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
commandBuffer->BeginLabeledSegment(name);
|
commandBuffer->BeginLabeledSegment(name);
|
||||||
|
|
||||||
|
|
||||||
// Ensure correct transforms are provided
|
// Ensure correct transforms are provided
|
||||||
superBatch->UpdateBuffers(frameIndex, descPool);
|
superBatch->UpdateBuffers(frameIndex, descPool);
|
||||||
|
|
||||||
|
if (viewport)
|
||||||
|
{
|
||||||
|
// set viewport and scissor
|
||||||
|
uint32_t w = static_cast<uint32_t>(viewport->GetWidth());
|
||||||
|
uint32_t h = static_cast<uint32_t>(viewport->GetHeight());
|
||||||
|
commandBuffer->SetViewportScissor(static_cast<float>(w), static_cast<float>(h), w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
|
||||||
|
|
||||||
|
if (renderer)
|
||||||
|
renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex);
|
||||||
|
|
||||||
// Draw all the batches
|
// Draw all the batches
|
||||||
superBatch->Draw(commandBuffer, frameIndex);
|
superBatch->Draw(commandBuffer, frameIndex);
|
||||||
|
|
||||||
// Draw all the exterior draw calls
|
// Draw all the exterior draw calls
|
||||||
for (auto& drawCall : exteriorDrawCalls)
|
for (auto& drawCall : exteriorDrawCalls)
|
||||||
{
|
{
|
||||||
drawCall(commandBuffer, frameIndex);
|
drawCall(commandBuffer, renderer, frameIndex);
|
||||||
}
|
}
|
||||||
commandBuffer->EndLabeledSegment();
|
commandBuffer->EndLabeledSegment();
|
||||||
}
|
}
|
||||||
|
@ -231,7 +253,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSubpass::AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)> const& newDrawCall) noexcept
|
void SHSubpass::AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept
|
||||||
{
|
{
|
||||||
exteriorDrawCalls.push_back(newDrawCall);
|
exteriorDrawCalls.push_back(newDrawCall);
|
||||||
}
|
}
|
||||||
|
@ -266,7 +288,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
// We build a new descriptor set layout to store our images
|
// We build a new descriptor set layout to store our images
|
||||||
inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, bindings);
|
inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(bindings);
|
||||||
|
|
||||||
// we store a sampler if its an input attachment. if it is storage image, no need sampler, store an empty handle.
|
// we store a sampler if its an input attachment. if it is storage image, no need sampler, store an empty handle.
|
||||||
for (uint32_t i = 0; i < bindings.size(); ++i)
|
for (uint32_t i = 0; i < bindings.size(); ++i)
|
||||||
|
|
|
@ -19,15 +19,28 @@ namespace SHADE
|
||||||
class SHRenderGraphStorage;
|
class SHRenderGraphStorage;
|
||||||
class SHVkShaderModule;
|
class SHVkShaderModule;
|
||||||
class SHVkSampler;
|
class SHVkSampler;
|
||||||
|
class SHRenderer;
|
||||||
|
class SHViewport;
|
||||||
|
|
||||||
class SH_API SHSubpass : public ISelfHandle<SHSubpass>
|
class SH_API SHSubpass : public ISelfHandle<SHSubpass>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
using ExteriorDrawCallFunction = std::function<void(Handle<SHVkCommandBuffer>, Handle<SHRenderer>, uint32_t)>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
/* PRIVATE MEMBER VARIABLES */
|
/* PRIVATE MEMBER VARIABLES */
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
Handle<SHRenderGraphStorage> graphStorage;
|
Handle<SHRenderGraphStorage> graphStorage;
|
||||||
|
|
||||||
|
//! Viewport to specify what part of the screen we want to draw on. This
|
||||||
|
//! will be used in vkCmdSetViewport/Scissor.
|
||||||
|
Handle<SHViewport> viewport;
|
||||||
|
|
||||||
|
//! Renderer used during the subpass execution. This dictates what matrix gets
|
||||||
|
//! passed to the shaders.
|
||||||
|
Handle<SHRenderer> renderer;
|
||||||
|
|
||||||
//! The index of the subpass in the render graph
|
//! The index of the subpass in the render graph
|
||||||
uint32_t subpassIndex;
|
uint32_t subpassIndex;
|
||||||
|
|
||||||
|
@ -79,8 +92,9 @@ namespace SHADE
|
||||||
//! after we draw everything from the batch. Because of this, these draw calls
|
//! after we draw everything from the batch. Because of this, these draw calls
|
||||||
//! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING
|
//! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING
|
||||||
//! COMPLEX.
|
//! COMPLEX.
|
||||||
std::vector<std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)>> exteriorDrawCalls;
|
std::vector<ExteriorDrawCallFunction> exteriorDrawCalls;
|
||||||
/// For identifying subpasses
|
|
||||||
|
// For identifying subpasses
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +102,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* CTORS AND DTORS */
|
/* CTORS AND DTORS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
SHSubpass(const std::string& name, Handle<SHRenderGraphStorage> renderGraphStorage, Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping) noexcept;
|
SHSubpass(const std::string& name, Handle<SHViewport> inViewport, Handle<SHRenderer> inRenderer, Handle<SHRenderGraphStorage> renderGraphStorage, Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping) noexcept;
|
||||||
SHSubpass(SHSubpass&& rhs) noexcept;
|
SHSubpass(SHSubpass&& rhs) noexcept;
|
||||||
SHSubpass& operator=(SHSubpass&& rhs) noexcept;
|
SHSubpass& operator=(SHSubpass&& rhs) noexcept;
|
||||||
|
|
||||||
|
@ -102,10 +116,10 @@ namespace SHADE
|
||||||
void AddGeneralDepthOutput(std::string resourceToReference) noexcept;
|
void AddGeneralDepthOutput(std::string resourceToReference) noexcept;
|
||||||
void AddInput(std::string resourceToReference) noexcept;
|
void AddInput(std::string resourceToReference) noexcept;
|
||||||
void AddGeneralInput (std::string resourceToReference) noexcept;
|
void AddGeneralInput (std::string resourceToReference) noexcept;
|
||||||
void AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)> const& newDrawCall) noexcept;
|
void AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept;
|
||||||
|
|
||||||
// Runtime functions
|
// Runtime functions
|
||||||
void Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
void Execute(Handle<SHVkCommandBuffer> commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
||||||
void HandleResize (void) noexcept;
|
void HandleResize (void) noexcept;
|
||||||
void BindDescriptorInputDescriptorSets (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) const noexcept;
|
void BindDescriptorInputDescriptorSets (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) const noexcept;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue