diff --git a/gfx/drivers_shader/shader_gl_core.cpp b/gfx/drivers_shader/shader_gl_core.cpp index c3048b6bdb..e97369625a 100644 --- a/gfx/drivers_shader/shader_gl_core.cpp +++ b/gfx/drivers_shader/shader_gl_core.cpp @@ -39,22 +39,6 @@ using namespace std; -template -static bool gl_core_shader_set_unique_map(unordered_map &m, - const string &name, const P &p) -{ - auto itr = m.find(name); - if (itr != end(m)) - { - RARCH_ERR("[slang]: Alias \"%s\" already exists.\n", - name.c_str()); - return false; - } - - m[name] = p; - return true; -} - GLuint gl_core_cross_compile_program( const uint32_t *vertex, size_t vertex_size, const uint32_t *fragment, size_t fragment_size, @@ -875,7 +859,7 @@ bool Pass::build() for (i = 0; i < parameters.size(); i++) { - if (!gl_core_shader_set_unique_map(semantic_map, parameters[i].id, + if (!slang_set_unique_map(semantic_map, parameters[i].id, slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j })) return false; j++; @@ -1919,21 +1903,21 @@ bool gl_core_filter_chain::init_alias() j = &passes[i] - passes.data(); - if (!gl_core_shader_set_unique_map(common.texture_semantic_map, name, + if (!slang_set_unique_map(common.texture_semantic_map, name, slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j })) return false; - if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, + if (!slang_set_unique_map(common.texture_semantic_uniform_map, name + "Size", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j })) return false; - if (!gl_core_shader_set_unique_map(common.texture_semantic_map, + if (!slang_set_unique_map(common.texture_semantic_map, name + "Feedback", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j })) return false; - if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, + if (!slang_set_unique_map(common.texture_semantic_uniform_map, name + "FeedbackSize", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j })) return false; @@ -1942,12 +1926,12 @@ bool gl_core_filter_chain::init_alias() for (i = 0; i < common.luts.size(); i++) { j = &common.luts[i] - common.luts.data(); - if (!gl_core_shader_set_unique_map(common.texture_semantic_map, + if (!slang_set_unique_map(common.texture_semantic_map, common.luts[i]->get_id(), slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j })) return false; - if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, + if (!slang_set_unique_map(common.texture_semantic_uniform_map, common.luts[i]->get_id() + "Size", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j })) return false; diff --git a/gfx/drivers_shader/shader_vulkan.cpp b/gfx/drivers_shader/shader_vulkan.cpp index 9dd573b4d7..51e069df86 100644 --- a/gfx/drivers_shader/shader_vulkan.cpp +++ b/gfx/drivers_shader/shader_vulkan.cpp @@ -431,22 +431,6 @@ struct vulkan_filter_chain void update_history_info(); }; -template -static bool vk_shader_set_unique_map(unordered_map &m, - const string &name, const P &p) -{ - auto itr = m.find(name); - if (itr != end(m)) - { - RARCH_ERR("[slang]: Alias \"%s\" already exists.\n", - name.c_str()); - return false; - } - - m[name] = p; - return true; -} - static unsigned num_miplevels(unsigned width, unsigned height) { unsigned size = MAX(width, height); @@ -1165,7 +1149,6 @@ bool vulkan_filter_chain::init_feedback() return true; } - bool vulkan_filter_chain::init_alias() { unsigned i, j; @@ -1180,22 +1163,22 @@ bool vulkan_filter_chain::init_alias() j = &passes[i] - passes.data(); - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_map, name, slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j })) return false; - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_uniform_map, name + "Size", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j })) return false; - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_map, name + "Feedback", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j })) return false; - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_uniform_map, name + "FeedbackSize", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j })) return false; @@ -1204,13 +1187,13 @@ bool vulkan_filter_chain::init_alias() for (i = 0; i < common.luts.size(); i++) { j = &common.luts[i] - common.luts.data(); - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_map, common.luts[i]->get_id(), slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j })) return false; - if (!vk_shader_set_unique_map( + if (!slang_set_unique_map( common.texture_semantic_uniform_map, common.luts[i]->get_id() + "Size", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j })) @@ -1996,7 +1979,8 @@ bool Pass::build() for (i = 0; i < parameters.size(); i++) { - if (!vk_shader_set_unique_map(semantic_map, parameters[i].id, + if (!slang_set_unique_map( + semantic_map, parameters[i].id, slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j })) return false; j++; diff --git a/gfx/drivers_shader/slang_process.cpp b/gfx/drivers_shader/slang_process.cpp index 600fb07eb8..5041f96b9d 100644 --- a/gfx/drivers_shader/slang_process.cpp +++ b/gfx/drivers_shader/slang_process.cpp @@ -36,21 +36,6 @@ using namespace spirv_cross; #endif using namespace std; -template -static bool set_unique_map(unordered_map& m, - const string& name, const P& p) -{ - auto itr = m.find(name); - if (itr != end(m)) - { - RARCH_ERR("[slang]: Alias \"%s\" already exists.\n", name.c_str()); - return false; - } - - m[name] = p; - return true; -} - template static string get_semantic_name(const unordered_map* map, S semantic, unsigned index) @@ -139,25 +124,25 @@ static bool slang_process_reflection( string name = shader_info->pass[i].alias; - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_map, name, slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) return false; - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_uniform_map, name + "Size", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) return false; - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_map, name + "Feedback", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) return false; - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_uniform_map, name + "FeedbackSize", slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) @@ -166,13 +151,13 @@ static bool slang_process_reflection( for (i = 0; i < shader_info->luts; i++) { - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_map, shader_info->lut[i].id, slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, i })) return false; - if (!set_unique_map( + if (!slang_set_unique_map( texture_semantic_uniform_map, string(shader_info->lut[i].id) + "Size", slang_texture_semantic_map{ @@ -184,7 +169,7 @@ static bool slang_process_reflection( for (i = 0; i < shader_info->num_parameters; i++) { - if (!set_unique_map( + if (!slang_set_unique_map( uniform_semantic_map, shader_info->parameters[i].id, slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, i })) return false; diff --git a/gfx/drivers_shader/slang_reflection.hpp b/gfx/drivers_shader/slang_reflection.hpp index 46c9abbb8d..25ee781d72 100644 --- a/gfx/drivers_shader/slang_reflection.hpp +++ b/gfx/drivers_shader/slang_reflection.hpp @@ -79,6 +79,18 @@ struct slang_reflection unsigned pass_number = 0; }; +template +static bool slang_set_unique_map(std::unordered_map &m, + const std::string &name, const P &p) +{ + auto itr = m.find(name); + /* Alias already exists? */ + if (itr != end(m)) + return false; + m[name] = p; + return true; +} + bool slang_reflect_spirv( const std::vector &vertex, const std::vector &fragment,