Added a render target to store entity ID

Pipelines created from pipeline library now checks if the resources pointed to by a subpass requires blending and adds a blend state accordingly.
Fragment shader writes to this new render target for testing (works)
This commit is contained in:
Brandon Mak 2022-10-13 16:57:08 +08:00
parent b153ccd1e3
commit 0a3d211f02
13 changed files with 88 additions and 26 deletions

View File

@ -143,26 +143,22 @@ namespace SHADE
// Initialize world render graph
worldRenderGraph->Init(device, swapchain);
worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second);
worldRenderGraph->AddResource("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
worldRenderGraph->AddResource("Entity ID", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR32Uint);
//worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
//worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
//worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
//worldRenderGraph->AddResource("Scene", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eB8G8R8A8Unorm);
worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second);
auto node = worldRenderGraph->AddNode("G-Buffer", { /*"Composite", "Position", */"Depth Buffer", "Present" }, {}); // no predecessors
auto node = worldRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Present"}, {}); // no predecessors
//First subpass to write to G-Buffer
auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write");
//gBufferWriteSubpass->AddColorOutput("Scene");
gBufferWriteSubpass->AddColorOutput("Present");
gBufferWriteSubpass->AddColorOutput("Entity ID");
gBufferWriteSubpass->AddDepthOutput ("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL);
//writeSubpass->AddColorOutput("Normals");
// //Second subpass to read from G-Buffer
//auto compositeSubpass = node->AddSubpass("G-Buffer Composite");
//compositeSubpass->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present"
//compositeSubpass->AddInput("Normals");
//compositeSubpass->AddInput("Position");
// TODO: Use macro to add this node when SH_EDITOR is enabled
auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {"G-Buffer"});

View File

@ -2,6 +2,8 @@
#include "SHPipelineLibrary.h"
#include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
#include "Graphics/RenderGraph/SHSubpass.h"
#include "Graphics/SHVkUtil.h"
namespace SHADE
{
@ -20,6 +22,31 @@ namespace SHADE
// Create the pipeline and configure the default vertex input state
auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass);
newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsGlobalData::GetDefaultViState());
SHColorBlendState colorBlendState{};
colorBlendState.logic_op_enable = VK_FALSE;
colorBlendState.logic_op = vk::LogicOp::eCopy;
auto const& subpassColorReferences = subpass->GetColorAttachmentReferences();
colorBlendState.attachments.reserve(subpassColorReferences.size());
for (auto& att : subpassColorReferences)
{
colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState
{
.blendEnable = SHVkUtil::IsBlendCompatible (subpass->GetFormatFromAttachmentReference(att.attachment)) ? true : false,
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.colorBlendOp = vk::BlendOp::eAdd,
.srcAlphaBlendFactor = vk::BlendFactor::eOne,
.dstAlphaBlendFactor = vk::BlendFactor::eZero,
.alphaBlendOp = vk::BlendOp::eAdd,
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
}
);
}
newPipeline->GetPipelineState().SetColorBlenState(colorBlendState);
// Actually construct the pipeline
newPipeline->ConstructPipeline();

View File

@ -137,22 +137,9 @@ namespace SHADE
{
VkBool32 logic_op_enable{ VK_FALSE };
vk::LogicOp logic_op{ VK_LOGIC_OP_COPY };
vk::LogicOp logic_op{ vk::LogicOp::eCopy };
std::vector<vk::PipelineColorBlendAttachmentState> attachments =
{
vk::PipelineColorBlendAttachmentState
{
.blendEnable = true,
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.colorBlendOp = vk::BlendOp::eAdd,
.srcAlphaBlendFactor = vk::BlendFactor::eOne,
.dstAlphaBlendFactor = vk::BlendFactor::eZero,
.alphaBlendOp = vk::BlendOp::eAdd,
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
}
};
std::vector<vk::PipelineColorBlendAttachmentState> attachments{};
};
// TODO: Specialization constants

View File

@ -261,6 +261,7 @@ namespace SHADE
return {};
}
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(vsFsPair);
if (!pipeline)
{
@ -301,4 +302,12 @@ namespace SHADE
return subpasses[subpassIndexing.at(subpassName.data())];
}
Handle<SHRenderGraphResource> SHRenderGraphNode::GetResource(uint32_t resourceIndex) const noexcept
{
if (resourceIndex < attResources.size())
return attResources[resourceIndex];
else
return {};
}
}

View File

@ -105,6 +105,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
Handle<SHVkRenderpass> GetRenderpass(void) const noexcept;
Handle<SHSubpass> GetSubpass(std::string_view subpassName) const noexcept;
Handle<SHRenderGraphResource> GetResource (uint32_t resourceIndex) const noexcept;
friend class SHRenderGraph;
};

View File

@ -242,4 +242,9 @@ namespace SHADE
}
}
vk::Format SHRenderGraphResource::GetResourceFormat(void) const noexcept
{
return resourceFormat;
}
}

View File

@ -72,6 +72,8 @@ namespace SHADE
void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept;
vk::Format GetResourceFormat (void) const noexcept;
friend class SHRenderGraphNode;
friend class SHRenderGraph;
};

View File

@ -2,6 +2,8 @@
#include "SHSubpass.h"
#include "Graphics/MiddleEnd/Batching/SHSuperBatch.h"
#include "Graphics/Devices/SHVkLogicalDevice.h"
#include "SHRenderGraphNode.h"
#include "SHRenderGraphResource.h"
namespace SHADE
{
@ -207,4 +209,15 @@ namespace SHADE
{
return superBatch;
}
std::vector<vk::AttachmentReference> const& SHSubpass::GetColorAttachmentReferences(void) const noexcept
{
return colorReferences;
}
vk::Format SHSubpass::GetFormatFromAttachmentReference(uint32_t attachmentReference) const noexcept
{
return parentNode->GetResource(attachmentReference)->GetResourceFormat();
}
}

View File

@ -86,7 +86,8 @@ namespace SHADE
Handle<SHRenderGraphNode> const& GetParentNode(void) const noexcept;
SHSubPassIndex GetIndex() const noexcept;
Handle<SHSuperBatch> GetSuperBatch(void) const noexcept;
std::vector<vk::AttachmentReference> const& GetColorAttachmentReferences (void) const noexcept;
vk::Format GetFormatFromAttachmentReference (uint32_t attachmentReference) const noexcept;
friend class SHRenderGraphNode;
friend class SHRenderGraph;

View File

@ -23,6 +23,25 @@ namespace SHADE
IsDepthOnlyFormat(format);
}
bool SHVkUtil::IsBlendCompatible(vk::Format format) noexcept
{
// TODO: Update with all formats
switch (format)
{
case vk::Format::eR32Sint:
case vk::Format::eR32G32Sint:
case vk::Format::eR32G32B32Sint:
case vk::Format::eR32G32B32A32Sint:
return false;
case vk::Format::eR32Sfloat:
case vk::Format::eR32G32Sfloat:
case vk::Format::eR32G32B32Sfloat:
case vk::Format::eR32G32B32A32Sfloat:
return true;
}
return false;
}
void SHVkUtil::EnsureBufferAndCopyData(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHVkBuffer>& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage)
{
if (bufferHandle)

View File

@ -22,6 +22,7 @@ namespace SHADE
public:
static bool IsDepthOnlyFormat (vk::Format format) noexcept;
static bool IsDepthStencilAttachment(vk::Format format) noexcept;
static bool IsBlendCompatible (vk::Format format) noexcept;
/***********************************************************************************/
/*!

View File

@ -33,12 +33,13 @@ layout (set = 3, binding = 0) buffer MaterialProperties // For materials
} MatProp;
layout(location = 0) out vec4 outColor;
layout(location = 1) out uint outEntityID;
void main()
{
outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) +
MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha;
outEntityID = 5;
//outColor = vec4 (1.0f);
}

Binary file not shown.