(shaders slang) Cut down on code duplication
This commit is contained in:
parent
4465a7bd0b
commit
cce2ac6904
|
@ -39,22 +39,6 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
static bool gl_core_shader_set_unique_map(unordered_map<string, P> &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(
|
GLuint gl_core_cross_compile_program(
|
||||||
const uint32_t *vertex, size_t vertex_size,
|
const uint32_t *vertex, size_t vertex_size,
|
||||||
const uint32_t *fragment, size_t fragment_size,
|
const uint32_t *fragment, size_t fragment_size,
|
||||||
|
@ -875,7 +859,7 @@ bool Pass::build()
|
||||||
|
|
||||||
for (i = 0; i < parameters.size(); i++)
|
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 }))
|
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j }))
|
||||||
return false;
|
return false;
|
||||||
j++;
|
j++;
|
||||||
|
@ -1919,21 +1903,21 @@ bool gl_core_filter_chain::init_alias()
|
||||||
|
|
||||||
j = &passes[i] - passes.data();
|
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 }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
||||||
return false;
|
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",
|
name + "Size",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!gl_core_shader_set_unique_map(common.texture_semantic_map,
|
if (!slang_set_unique_map(common.texture_semantic_map,
|
||||||
name + "Feedback",
|
name + "Feedback",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
||||||
return false;
|
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",
|
name + "FeedbackSize",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
||||||
return false;
|
return false;
|
||||||
|
@ -1942,12 +1926,12 @@ bool gl_core_filter_chain::init_alias()
|
||||||
for (i = 0; i < common.luts.size(); i++)
|
for (i = 0; i < common.luts.size(); i++)
|
||||||
{
|
{
|
||||||
j = &common.luts[i] - common.luts.data();
|
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(),
|
common.luts[i]->get_id(),
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
||||||
return false;
|
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",
|
common.luts[i]->get_id() + "Size",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -431,22 +431,6 @@ struct vulkan_filter_chain
|
||||||
void update_history_info();
|
void update_history_info();
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
static bool vk_shader_set_unique_map(unordered_map<string, P> &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)
|
static unsigned num_miplevels(unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
unsigned size = MAX(width, height);
|
unsigned size = MAX(width, height);
|
||||||
|
@ -1165,7 +1149,6 @@ bool vulkan_filter_chain::init_feedback()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool vulkan_filter_chain::init_alias()
|
bool vulkan_filter_chain::init_alias()
|
||||||
{
|
{
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
@ -1180,22 +1163,22 @@ bool vulkan_filter_chain::init_alias()
|
||||||
|
|
||||||
j = &passes[i] - passes.data();
|
j = &passes[i] - passes.data();
|
||||||
|
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_map, name,
|
common.texture_semantic_map, name,
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_uniform_map, name + "Size",
|
common.texture_semantic_uniform_map, name + "Size",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_map, name + "Feedback",
|
common.texture_semantic_map, name + "Feedback",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_uniform_map, name + "FeedbackSize",
|
common.texture_semantic_uniform_map, name + "FeedbackSize",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
|
||||||
return false;
|
return false;
|
||||||
|
@ -1204,13 +1187,13 @@ bool vulkan_filter_chain::init_alias()
|
||||||
for (i = 0; i < common.luts.size(); i++)
|
for (i = 0; i < common.luts.size(); i++)
|
||||||
{
|
{
|
||||||
j = &common.luts[i] - common.luts.data();
|
j = &common.luts[i] - common.luts.data();
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_map,
|
common.texture_semantic_map,
|
||||||
common.luts[i]->get_id(),
|
common.luts[i]->get_id(),
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!vk_shader_set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
common.texture_semantic_uniform_map,
|
common.texture_semantic_uniform_map,
|
||||||
common.luts[i]->get_id() + "Size",
|
common.luts[i]->get_id() + "Size",
|
||||||
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
|
||||||
|
@ -1996,7 +1979,8 @@ bool Pass::build()
|
||||||
|
|
||||||
for (i = 0; i < parameters.size(); i++)
|
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 }))
|
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j }))
|
||||||
return false;
|
return false;
|
||||||
j++;
|
j++;
|
||||||
|
|
|
@ -36,21 +36,6 @@ using namespace spirv_cross;
|
||||||
#endif
|
#endif
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
static bool set_unique_map(unordered_map<string, P>& 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 <typename M, typename S>
|
template <typename M, typename S>
|
||||||
static string get_semantic_name(const unordered_map<string, M>* map,
|
static string get_semantic_name(const unordered_map<string, M>* map,
|
||||||
S semantic, unsigned index)
|
S semantic, unsigned index)
|
||||||
|
@ -139,25 +124,25 @@ static bool slang_process_reflection(
|
||||||
|
|
||||||
string name = shader_info->pass[i].alias;
|
string name = shader_info->pass[i].alias;
|
||||||
|
|
||||||
if (!set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
texture_semantic_map, name,
|
texture_semantic_map, name,
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i }))
|
SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
texture_semantic_uniform_map, name + "Size",
|
texture_semantic_uniform_map, name + "Size",
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i }))
|
SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
texture_semantic_map, name + "Feedback",
|
texture_semantic_map, name + "Feedback",
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i }))
|
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
texture_semantic_uniform_map, name + "FeedbackSize",
|
texture_semantic_uniform_map, name + "FeedbackSize",
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i }))
|
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i }))
|
||||||
|
@ -166,13 +151,13 @@ static bool slang_process_reflection(
|
||||||
|
|
||||||
for (i = 0; i < shader_info->luts; i++)
|
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,
|
texture_semantic_map, shader_info->lut[i].id,
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
SLANG_TEXTURE_SEMANTIC_USER, i }))
|
SLANG_TEXTURE_SEMANTIC_USER, i }))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!set_unique_map(
|
if (!slang_set_unique_map(
|
||||||
texture_semantic_uniform_map,
|
texture_semantic_uniform_map,
|
||||||
string(shader_info->lut[i].id) + "Size",
|
string(shader_info->lut[i].id) + "Size",
|
||||||
slang_texture_semantic_map{
|
slang_texture_semantic_map{
|
||||||
|
@ -184,7 +169,7 @@ static bool slang_process_reflection(
|
||||||
|
|
||||||
for (i = 0; i < shader_info->num_parameters; i++)
|
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,
|
uniform_semantic_map, shader_info->parameters[i].id,
|
||||||
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, i }))
|
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, i }))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -79,6 +79,18 @@ struct slang_reflection
|
||||||
unsigned pass_number = 0;
|
unsigned pass_number = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename P>
|
||||||
|
static bool slang_set_unique_map(std::unordered_map<std::string, P> &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(
|
bool slang_reflect_spirv(
|
||||||
const std::vector<uint32_t> &vertex,
|
const std::vector<uint32_t> &vertex,
|
||||||
const std::vector<uint32_t> &fragment,
|
const std::vector<uint32_t> &fragment,
|
||||||
|
|
Loading…
Reference in New Issue