diff --git a/gfx/drivers_shader/shader_vulkan.cpp b/gfx/drivers_shader/shader_vulkan.cpp index a1fd7d4a73..008d594a2f 100644 --- a/gfx/drivers_shader/shader_vulkan.cpp +++ b/gfx/drivers_shader/shader_vulkan.cpp @@ -219,6 +219,10 @@ struct CommonResources vector original_history; vector framebuffer_feedback; + unordered_map texture_semantic_map; + unordered_map texture_semantic_uniform_map; + unordered_map semantic_map; + VkDevice device; }; @@ -1301,6 +1305,10 @@ bool Pass::build() } reflection = slang_reflection{}; + reflection.texture_semantic_map = &common->texture_semantic_map; + reflection.texture_semantic_uniform_map = &common->texture_semantic_uniform_map; + reflection.semantic_map = &common->semantic_map; + if (!slang_reflect_spirv(vertex_shader, fragment_shader, &reflection)) return false; diff --git a/gfx/drivers_shader/slang_reflection.cpp b/gfx/drivers_shader/slang_reflection.cpp index a6a0c1250a..1bfc616c2b 100644 --- a/gfx/drivers_shader/slang_reflection.cpp +++ b/gfx/drivers_shader/slang_reflection.cpp @@ -102,18 +102,42 @@ static slang_texture_semantic slang_name_to_texture_semantic_array(const string return SLANG_INVALID_TEXTURE_SEMANTIC; } -static slang_texture_semantic slang_name_to_texture_semantic(const string &name, unsigned *index) +static slang_texture_semantic slang_name_to_texture_semantic( + const unordered_map &semantic_map, + const string &name, unsigned *index) { + auto itr = semantic_map.find(name); + if (itr != end(semantic_map)) + { + *index = itr->second.index; + return itr->second.semantic; + } + return slang_name_to_texture_semantic_array(name, texture_semantic_names, index); } -static slang_texture_semantic slang_uniform_name_to_texture_semantic(const string &name, unsigned *index) +static slang_texture_semantic slang_uniform_name_to_texture_semantic( + const unordered_map &semantic_map, + const string &name, unsigned *index) { + auto itr = semantic_map.find(name); + if (itr != end(semantic_map)) + { + *index = itr->second.index; + return itr->second.semantic; + } + return slang_name_to_texture_semantic_array(name, texture_semantic_uniform_names, index); } -static slang_semantic slang_uniform_name_to_semantic(const string &name) +static slang_semantic slang_uniform_name_to_semantic( + const unordered_map &semantic_map, + const string &name) { + auto itr = semantic_map.find(name); + if (itr != end(semantic_map)) + return itr->second; + unsigned i = 0; for (auto n : semantic_uniform_names) { @@ -227,8 +251,9 @@ static bool add_active_buffer_ranges(const Compiler &compiler, const Resource &r auto &type = compiler.get_type(compiler.get_type(resource.type_id).member_types[range.index]); unsigned tex_sem_index = 0; - auto sem = slang_uniform_name_to_semantic(name); - auto tex_sem = slang_uniform_name_to_texture_semantic(name, &tex_sem_index); + auto sem = slang_uniform_name_to_semantic(*reflection->semantic_map, name); + auto tex_sem = slang_uniform_name_to_texture_semantic(*reflection->texture_semantic_uniform_map, + name, &tex_sem_index); if (sem != SLANG_INVALID_SEMANTIC) { @@ -417,7 +442,8 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm binding_mask |= 1 << binding; unsigned array_index = 0; - slang_texture_semantic index = slang_name_to_texture_semantic(texture.name, &array_index); + slang_texture_semantic index = slang_name_to_texture_semantic(*reflection->texture_semantic_map, + texture.name, &array_index); if (index == SLANG_INVALID_TEXTURE_SEMANTIC) { diff --git a/gfx/drivers_shader/slang_reflection.hpp b/gfx/drivers_shader/slang_reflection.hpp index f416b52385..b6b15b5945 100644 --- a/gfx/drivers_shader/slang_reflection.hpp +++ b/gfx/drivers_shader/slang_reflection.hpp @@ -17,6 +17,7 @@ #define SLANG_REFLECTION_HPP #include +#include #include // Textures with built-in meaning. @@ -88,6 +89,12 @@ struct slang_semantic_meta bool uniform = false; }; +struct slang_texture_semantic_map +{ + slang_texture_semantic semantic; + unsigned index; +}; + struct slang_reflection { slang_reflection(); @@ -98,6 +105,10 @@ struct slang_reflection std::vector semantic_textures[SLANG_NUM_TEXTURE_SEMANTICS]; slang_semantic_meta semantics[SLANG_NUM_SEMANTICS]; + + const std::unordered_map *texture_semantic_map = nullptr; + const std::unordered_map *texture_semantic_uniform_map = nullptr; + const std::unordered_map *semantic_map = nullptr; }; bool slang_reflect_spirv(const std::vector &vertex,