Bug fixes, Scene changes and new features #376

Merged
glencelow merged 15 commits from PlayerController into main 2023-02-28 23:10:33 +08:00
7 changed files with 38 additions and 14 deletions
Showing only changes of commit 7f13462db7 - Show all commits

View File

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

View File

@ -44,8 +44,8 @@ namespace SHADE
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.colorBlendOp = vk::BlendOp::eAdd,
.srcAlphaBlendFactor = vk::BlendFactor::eOne,
.dstAlphaBlendFactor = vk::BlendFactor::eZero,
.srcAlphaBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstAlphaBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.alphaBlendOp = vk::BlendOp::eAdd,
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
}
@ -60,7 +60,7 @@ namespace SHADE
newPipeline->ConstructPipeline();
// Emplace the new pipeline
graphicsPipelines.emplace (vsFsPair, newPipeline);
graphicsPipelines.emplace (std::make_tuple(vsFsPair.first, vsFsPair.second, subpass), newPipeline);
return newPipeline;
}
@ -70,19 +70,19 @@ namespace SHADE
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
if (graphicsPipelines.contains(vsFsPair))
return graphicsPipelines.at(vsFsPair);
if (graphicsPipelines.contains(pipelineCombo))
return graphicsPipelines.at(pipelineCombo);
else
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
return graphicsPipelines.contains(vsFsPair);
return graphicsPipelines.contains(pipelineCombo);
}
}

View File

@ -20,11 +20,13 @@ namespace SHADE
private:
// 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
Handle<SHVkLogicalDevice> logicalDevice;
//! a map of pipelines that are hashed using a pair of shader module handles
std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>> graphicsPipelines;
std::unordered_map<PipelineCombo, Handle<SHVkPipeline>> graphicsPipelines;
public:
void Init (Handle<SHVkLogicalDevice> device) noexcept;
@ -38,8 +40,8 @@ namespace SHADE
SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(),
SHRasterizationState const& rasterState = SHRasterizationState{}
) noexcept;
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
Handle<SHVkPipeline> GetGraphicsPipeline (PipelineCombo const& pipelineCombo) 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)
{
// default to batching system type

View File

@ -37,6 +37,7 @@ namespace SHADE
case vk::Format::eR32G32Sfloat:
case vk::Format::eR32G32B32Sfloat:
case vk::Format::eR32G32B32A32Sfloat:
case vk::Format::eB8G8R8A8Unorm:
return true;
}
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;
};
/// <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"

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);
}
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);
}
}