Skip to content

Commit

Permalink
attempt to fix std::out_of_range in GetBindKey
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejnau committed Apr 5, 2021
1 parent 0ff0fb2 commit ed823d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/Core/Shader/ShaderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ uint64_t ShaderBase::GetId(const std::string& entry_point) const

const BindKey& ShaderBase::GetBindKey(const std::string& name) const
{
auto it = m_bind_keys.find(name);
if (it != m_bind_keys.end())
return it->second;
assert(m_blob_type == ShaderBlobType::kSPIRV);
return m_bind_keys.at("type." + name);
return m_bind_keys.at(name);
}

const std::vector<ResourceBindingDesc>& ShaderBase::GetResourceBindings() const
Expand Down
2 changes: 1 addition & 1 deletion src/Core/ShaderReflection/SPIRVReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ ResourceBindingDesc GetBindingDesc(const spirv_cross::CompilerHLSL& compiler, co
{
ResourceBindingDesc desc = {};
decltype(auto) resource_type = compiler.get_type(resource.type_id);
desc.name = resource.name;
desc.name = compiler.get_name(resource.id);
desc.type = GetViewType(compiler, resource_type, resource.id);
desc.slot = compiler.get_decoration(resource.id, spv::DecorationBinding);
desc.space = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
Expand Down
5 changes: 5 additions & 0 deletions src/Core/ShaderReflection/ShaderReflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ inline bool operator== (const EntryPoint& lhs, const EntryPoint& rhs)
return std::tie(lhs.name, lhs.kind) == std::tie(rhs.name, rhs.kind);
}

inline bool operator< (const EntryPoint& lhs, const EntryPoint& rhs)
{
return std::tie(lhs.name, lhs.kind) < std::tie(rhs.name, rhs.kind);
}

inline auto MakeTie(const ResourceBindingDesc& desc)
{
return std::tie(desc.name, desc.type, desc.slot, desc.space, desc.dimension);
Expand Down
6 changes: 6 additions & 0 deletions src/Core/ShaderReflection/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class RayTracing : public ShaderTestCase
{ "closest", ShaderKind::kClosestHit },
};
auto entry_points = reflection->GetEntryPoints();
sort(entry_points.begin(), entry_points.end());
sort(expect.begin(), expect.end());
REQUIRE(entry_points.size() == expect.size());
for (size_t i = 0; i < entry_points.size(); ++i)
{
Expand Down Expand Up @@ -78,6 +80,10 @@ class TrianglePS : public ShaderTestCase
};
auto entry_points = reflection->GetEntryPoints();
REQUIRE(entry_points == expect);

auto bindings = reflection->GetBindings();
REQUIRE(bindings.size() == 1);
REQUIRE(bindings.front().name == "Settings");
}

private:
Expand Down

0 comments on commit ed823d8

Please sign in to comment.