GetGraphicsPipeline now takes in a subpass (thanks KW)

- Fixed blending issues in pipeline
This commit is contained in:
Brandon Mak 2023-02-28 19:47:52 +08:00
parent 04c19fb586
commit 7f13462db7
7 changed files with 38 additions and 14 deletions

View File

@ -909,7 +909,7 @@ namespace SHADE
SHGraphicsPredefinedData::SystemType::BATCHING, SHGraphicsPredefinedData::SystemType::BATCHING,
SHGraphicsPredefinedData::GetShadowMapViState(), rasterState SHGraphicsPredefinedData::GetShadowMapViState(), rasterState
); );
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS }); shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, newSubpass });
} }
newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline

View File

@ -44,8 +44,8 @@ namespace SHADE
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.colorBlendOp = vk::BlendOp::eAdd, .colorBlendOp = vk::BlendOp::eAdd,
.srcAlphaBlendFactor = vk::BlendFactor::eOne, .srcAlphaBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstAlphaBlendFactor = vk::BlendFactor::eZero, .dstAlphaBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.alphaBlendOp = vk::BlendOp::eAdd, .alphaBlendOp = vk::BlendOp::eAdd,
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
} }
@ -60,7 +60,7 @@ namespace SHADE
newPipeline->ConstructPipeline(); newPipeline->ConstructPipeline();
// Emplace the new pipeline // Emplace the new pipeline
graphicsPipelines.emplace (vsFsPair, newPipeline); graphicsPipelines.emplace (std::make_tuple(vsFsPair.first, vsFsPair.second, subpass), newPipeline);
return newPipeline; return newPipeline;
} }
@ -70,19 +70,19 @@ namespace SHADE
logicalDevice = device; logicalDevice = device;
} }
Handle<SHVkPipeline> SHPipelineLibrary::GetGraphicsPipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept Handle<SHVkPipeline> SHPipelineLibrary::GetGraphicsPipeline(PipelineCombo const& pipelineCombo) noexcept
{ {
// return the pipeline requested for // return the pipeline requested for
if (graphicsPipelines.contains(vsFsPair)) if (graphicsPipelines.contains(pipelineCombo))
return graphicsPipelines.at(vsFsPair); return graphicsPipelines.at(pipelineCombo);
else else
return {}; return {};
} }
bool SHPipelineLibrary::CheckGraphicsPipelineExistence(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept bool SHPipelineLibrary::CheckGraphicsPipelineExistence(PipelineCombo const& pipelineCombo) noexcept
{ {
// Returns if a pipeline exists or not // Returns if a pipeline exists or not
return graphicsPipelines.contains(vsFsPair); return graphicsPipelines.contains(pipelineCombo);
} }
} }

View File

@ -20,11 +20,13 @@ namespace SHADE
private: private:
// TOOD: Move this somewhere eventually. Can use for other things // TOOD: Move this somewhere eventually. Can use for other things
using PipelineCombo = std::tuple<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>, Handle<SHSubpass>>;
//! Logical Device required for creation of pipelines //! Logical Device required for creation of pipelines
Handle<SHVkLogicalDevice> logicalDevice; Handle<SHVkLogicalDevice> logicalDevice;
//! a map of pipelines that are hashed using a pair of shader module handles //! a map of pipelines that are hashed using a pair of shader module handles
std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>> graphicsPipelines; std::unordered_map<PipelineCombo, Handle<SHVkPipeline>> graphicsPipelines;
public: public:
void Init (Handle<SHVkLogicalDevice> device) noexcept; void Init (Handle<SHVkLogicalDevice> device) noexcept;
@ -38,8 +40,8 @@ namespace SHADE
SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(), SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(),
SHRasterizationState const& rasterState = SHRasterizationState{} SHRasterizationState const& rasterState = SHRasterizationState{}
) noexcept; ) noexcept;
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept; Handle<SHVkPipeline> GetGraphicsPipeline (PipelineCombo const& pipelineCombo) noexcept;
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept; bool CheckGraphicsPipelineExistence (PipelineCombo const& pipelineCombo) noexcept;
}; };
} }

View File

@ -688,7 +688,7 @@ namespace SHADE
} }
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(vsFsPair); Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(std::make_tuple(vsFsPair.first, vsFsPair.second, subpass));
if (!pipeline) if (!pipeline)
{ {
// default to batching system type // default to batching system type

View File

@ -37,6 +37,7 @@ namespace SHADE
case vk::Format::eR32G32Sfloat: case vk::Format::eR32G32Sfloat:
case vk::Format::eR32G32B32Sfloat: case vk::Format::eR32G32B32Sfloat:
case vk::Format::eR32G32B32A32Sfloat: case vk::Format::eR32G32B32A32Sfloat:
case vk::Format::eB8G8R8A8Unorm:
return true; return true;
} }
return false; return false;

View File

@ -284,6 +284,16 @@ namespace std
{ {
std::size_t operator() (std::pair<SHADE::Handle<T1>, SHADE::Handle<T2>> const& pair) const; std::size_t operator() (std::pair<SHADE::Handle<T1>, SHADE::Handle<T2>> const& pair) const;
}; };
/// <summary>
/// std::hash template specialization for std::pair<Handle<T1>, Handle<T2>>
/// </summary>
/// <typeparam name="T">Type for the first Handle.</typeparam>
/// <typeparam name="T">Type for the second Handle.</typeparam>
template<typename T1, typename T2, typename T3>
struct hash<std::tuple<SHADE::Handle<T1>, SHADE::Handle<T2>, SHADE::Handle<T3>>>
{
std::size_t operator() (std::tuple<SHADE::Handle<T1>, SHADE::Handle<T2>, SHADE::Handle<T3>> const& tuple) const;
};
} }
#include "SHHandle.hpp" #include "SHHandle.hpp"

View File

@ -163,4 +163,15 @@ namespace std
{ {
return std::hash<uint64_t>{}(pair.first.GetId().Raw) ^ std::hash<uint64_t>{}(pair.second.GetId().Raw); return std::hash<uint64_t>{}(pair.first.GetId().Raw) ^ std::hash<uint64_t>{}(pair.second.GetId().Raw);
} }
template <typename T1, typename T2, typename T3>
std::size_t hash<tuple<SHADE::Handle<T1>, SHADE::Handle<T2>, SHADE::Handle<T3>>>::operator()(
std::tuple<SHADE::Handle<T1>, SHADE::Handle<T2>, SHADE::Handle<T3>> const& tuple) const
{
return std::hash<uint64_t>{}(std::get<0>(tuple).GetId().Raw)
^
std::hash<uint64_t>{}(std::get<1>(tuple).GetId().Raw)
^
std::hash<uint64_t>{}(std::get<2>(tuple).GetId().Raw);
}
} }