Optimize out a lot of std::string construction and allocations (#415)
Update CommandLineParameters.hpp Update CommandLineParametersTests.cpp Update WebContext.hpp xmake check-files -f Fix MaterialPassRegistry
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/FramePipelinePass.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <string>
|
||||
@@ -51,8 +52,7 @@ namespace Nz
|
||||
std::vector<std::string> outputs;
|
||||
};
|
||||
|
||||
std::list<std::string> m_passNames; //< in order to allow std::string_view as a key in C++17 (keep std::string stable as well because of SSO)
|
||||
std::unordered_map<std::string_view, std::size_t> m_passIndex;
|
||||
std::unordered_map<std::string, std::size_t, StringHash<>, std::equal_to<>> m_passIndex;
|
||||
std::vector<Pass> m_passes;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -58,10 +58,8 @@ namespace Nz
|
||||
if (m_passIndex.find(passName) != m_passIndex.end())
|
||||
throw std::runtime_error("pass " + passName + " is already registered");
|
||||
|
||||
m_passNames.push_back(std::move(passName));
|
||||
|
||||
std::size_t passIndex = m_passIndex.size();
|
||||
m_passIndex.emplace(m_passNames.back(), passIndex);
|
||||
m_passIndex.emplace(std::move(passName), passIndex);
|
||||
auto& passData = m_passes.emplace_back();
|
||||
passData.factory = std::move(factory);
|
||||
passData.inputs = std::move(inputs);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <Nazara/Graphics/MaterialSettings.hpp>
|
||||
#include <Nazara/Graphics/RenderBufferPool.hpp>
|
||||
#include <Nazara/Graphics/ShaderReflection.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <NZSL/Ast/Module.hpp>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
@@ -51,8 +52,8 @@ namespace Nz
|
||||
|
||||
std::shared_ptr<MaterialInstance> GetDefaultInstance() const;
|
||||
|
||||
inline std::size_t FindTextureByTag(const std::string& tag) const;
|
||||
inline std::size_t FindUniformBlockByTag(const std::string& tag) const;
|
||||
inline std::size_t FindTextureByTag(std::string_view tag) const;
|
||||
inline std::size_t FindUniformBlockByTag(std::string_view tag) const;
|
||||
|
||||
inline UInt32 GetEngineBindingIndex(EngineShaderBinding shaderBinding) const;
|
||||
inline const std::shared_ptr<RenderPipelineLayout>& GetRenderPipelineLayout() const;
|
||||
@@ -93,8 +94,8 @@ namespace Nz
|
||||
private:
|
||||
std::shared_ptr<RenderPipelineLayout> m_renderPipelineLayout;
|
||||
std::unordered_map<UInt32, nzsl::Ast::ConstantSingleValue> m_optionValues;
|
||||
std::unordered_map<std::string /*tag*/, std::size_t> m_textureByTag;
|
||||
std::unordered_map<std::string /*tag*/, std::size_t> m_uniformBlockByTag;
|
||||
std::unordered_map<std::string /*tag*/, std::size_t, StringHash<>, std::equal_to<>> m_textureByTag;
|
||||
std::unordered_map<std::string /*tag*/, std::size_t, StringHash<>, std::equal_to<>> m_uniformBlockByTag;
|
||||
std::vector<TextureData> m_textures;
|
||||
std::vector<UniformBlockData> m_uniformBlocks;
|
||||
mutable std::weak_ptr<MaterialInstance> m_defaultInstance;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline std::size_t Material::FindTextureByTag(const std::string& tag) const
|
||||
inline std::size_t Material::FindTextureByTag(std::string_view tag) const
|
||||
{
|
||||
auto it = m_textureByTag.find(tag);
|
||||
if (it == m_textureByTag.end())
|
||||
@@ -15,7 +15,7 @@ namespace Nz
|
||||
return it->second;
|
||||
}
|
||||
|
||||
inline std::size_t Material::FindUniformBlockByTag(const std::string& tag) const
|
||||
inline std::size_t Material::FindUniformBlockByTag(std::string_view tag) const
|
||||
{
|
||||
auto it = m_uniformBlockByTag.find(tag);
|
||||
if (it == m_uniformBlockByTag.end())
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_GRAPHICS_MATERIALPASSREGISTRY_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -30,8 +31,7 @@ namespace Nz
|
||||
MaterialPassRegistry& operator=(MaterialPassRegistry&&) = default;
|
||||
|
||||
private:
|
||||
std::list<std::string> m_passNames; //< in order to allow std::string_view as a key in C++17 (keep std::string stable as well because of SSO)
|
||||
std::unordered_map<std::string_view, std::size_t> m_passIndex;
|
||||
std::unordered_map<std::string, std::size_t, StringHash<>, std::equal_to<>> m_passIndex;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,11 @@ namespace Nz
|
||||
|
||||
inline std::size_t MaterialPassRegistry::RegisterPass(std::string passName)
|
||||
{
|
||||
if (m_passIndex.find(passName) != m_passIndex.end())
|
||||
if (m_passIndex.contains(passName))
|
||||
throw std::runtime_error("pass " + passName + " is already registered");
|
||||
|
||||
m_passNames.push_back(std::move(passName));
|
||||
|
||||
std::size_t passIndex = m_passIndex.size();
|
||||
m_passIndex.emplace(m_passNames.back(), passIndex);
|
||||
m_passIndex.emplace(std::move(passName), passIndex);
|
||||
|
||||
return passIndex;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <NZSL/Ast/Module.hpp>
|
||||
#include <NZSL/Ast/Option.hpp>
|
||||
#include <NZSL/Ast/RecursiveVisitor.hpp>
|
||||
@@ -31,8 +32,8 @@ namespace Nz
|
||||
~ShaderReflection() = default;
|
||||
|
||||
inline const RenderPipelineLayoutInfo& GetPipelineLayoutInfo() const;
|
||||
inline const ExternalBlockData* GetExternalBlockByTag(const std::string& tag) const;
|
||||
inline const OptionData* GetOptionByName(const std::string& optionName) const;
|
||||
inline const ExternalBlockData* GetExternalBlockByTag(std::string_view tag) const;
|
||||
inline const OptionData* GetOptionByName(std::string_view optionName) const;
|
||||
inline const StructData* GetStructByIndex(std::size_t structIndex) const;
|
||||
|
||||
void Reflect(nzsl::Ast::Module& module);
|
||||
@@ -74,10 +75,10 @@ namespace Nz
|
||||
|
||||
struct ExternalBlockData
|
||||
{
|
||||
std::unordered_map<std::string /*tag*/, ExternalSampler> samplers;
|
||||
std::unordered_map<std::string /*tag*/, ExternalStorageBlock> storageBlocks;
|
||||
std::unordered_map<std::string /*tag*/, ExternalTexture> textures;
|
||||
std::unordered_map<std::string /*tag*/, ExternalUniformBlock> uniformBlocks;
|
||||
std::unordered_map<std::string /*tag*/, ExternalSampler, StringHash<>, std::equal_to<>> samplers;
|
||||
std::unordered_map<std::string /*tag*/, ExternalStorageBlock, StringHash<>, std::equal_to<>> storageBlocks;
|
||||
std::unordered_map<std::string /*tag*/, ExternalTexture, StringHash<>, std::equal_to<>> textures;
|
||||
std::unordered_map<std::string /*tag*/, ExternalUniformBlock, StringHash<>, std::equal_to<>> uniformBlocks;
|
||||
};
|
||||
|
||||
struct OptionData
|
||||
@@ -97,7 +98,7 @@ namespace Nz
|
||||
{
|
||||
StructData(nzsl::StructLayout layout) : fieldOffsets(layout) {}
|
||||
|
||||
std::unordered_map<std::string /*tag*/, StructMemberData> members;
|
||||
std::unordered_map<std::string /*tag*/, StructMemberData, StringHash<>, std::equal_to<>> members;
|
||||
nzsl::FieldOffsets fieldOffsets;
|
||||
};
|
||||
|
||||
@@ -107,8 +108,8 @@ namespace Nz
|
||||
void Visit(nzsl::Ast::DeclareOptionStatement& node) override;
|
||||
void Visit(nzsl::Ast::DeclareStructStatement& node) override;
|
||||
|
||||
std::unordered_map<std::string /*tag*/, ExternalBlockData> m_externalBlocks;
|
||||
std::unordered_map<std::string /*name*/, OptionData> m_options;
|
||||
std::unordered_map<std::string /*tag*/, ExternalBlockData, StringHash<>, std::equal_to<>> m_externalBlocks;
|
||||
std::unordered_map<std::string /*name*/, OptionData, StringHash<>, std::equal_to<>> m_options;
|
||||
std::unordered_map<std::size_t /*structIndex*/, StructData> m_structs;
|
||||
RenderPipelineLayoutInfo m_pipelineLayoutInfo;
|
||||
bool m_isConditional;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Nz
|
||||
return m_pipelineLayoutInfo;
|
||||
}
|
||||
|
||||
inline auto ShaderReflection::GetExternalBlockByTag(const std::string& tag) const -> const ExternalBlockData*
|
||||
inline auto ShaderReflection::GetExternalBlockByTag(std::string_view tag) const -> const ExternalBlockData*
|
||||
{
|
||||
auto it = m_externalBlocks.find(tag);
|
||||
if (it == m_externalBlocks.end())
|
||||
@@ -20,7 +20,7 @@ namespace Nz
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
inline auto ShaderReflection::GetOptionByName(const std::string& optionName) const -> const OptionData*
|
||||
inline auto ShaderReflection::GetOptionByName(std::string_view optionName) const -> const OptionData*
|
||||
{
|
||||
auto it = m_options.find(optionName);
|
||||
if (it == m_options.end())
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <NZSL/ModuleResolver.hpp>
|
||||
#include <NZSL/Ast/Module.hpp>
|
||||
#include <NZSL/Ast/Option.hpp>
|
||||
@@ -38,7 +39,7 @@ namespace Nz
|
||||
|
||||
const std::shared_ptr<ShaderModule>& Get(const Config& config);
|
||||
|
||||
inline bool HasOption(const std::string& optionName, Pointer<const Option>* option = nullptr) const;
|
||||
inline bool HasOption(std::string_view optionName, Pointer<const Option>* option = nullptr) const;
|
||||
|
||||
inline void UpdateConfig(Config& config, const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers);
|
||||
inline void UpdateConfigCallback(ConfigCallback callback);
|
||||
@@ -66,13 +67,13 @@ namespace Nz
|
||||
NazaraSignal(OnShaderUpdated, UberShader* /*uberShader*/);
|
||||
|
||||
private:
|
||||
nzsl::Ast::ModulePtr Validate(const nzsl::Ast::Module& module, std::unordered_map<std::string, Option>* options);
|
||||
nzsl::Ast::ModulePtr Validate(const nzsl::Ast::Module& module, std::unordered_map<std::string, Option, StringHash<>, std::equal_to<>>* options);
|
||||
|
||||
NazaraSlot(nzsl::ModuleResolver, OnModuleUpdated, m_onShaderModuleUpdated);
|
||||
|
||||
std::unordered_map<Config, std::shared_ptr<ShaderModule>, ConfigHasher, ConfigEqual> m_combinations;
|
||||
std::unordered_map<std::string, Option> m_optionIndexByName;
|
||||
std::unordered_set<std::string> m_usedModules;
|
||||
std::unordered_map<std::string, Option, StringHash<>, std::equal_to<>> m_optionIndexByName;
|
||||
std::unordered_set<std::string, StringHash<>, std::equal_to<>> m_usedModules;
|
||||
nzsl::Ast::ModulePtr m_shaderModule;
|
||||
ConfigCallback m_configCallback;
|
||||
nzsl::ShaderStageTypeFlags m_shaderStages;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Nz
|
||||
return m_shaderStages;
|
||||
}
|
||||
|
||||
inline bool UberShader::HasOption(const std::string& optionName, Pointer<const Option>* option) const
|
||||
inline bool UberShader::HasOption(std::string_view optionName, Pointer<const Option>* option) const
|
||||
{
|
||||
auto it = m_optionIndexByName.find(optionName);
|
||||
if (it == m_optionIndexByName.end())
|
||||
|
||||
Reference in New Issue
Block a user