mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 14:42:30 +00:00
Simplify slang_process.cpp
This commit is contained in:
parent
95f68b0625
commit
25a417cdd7
@ -51,18 +51,18 @@ static bool set_unique_map(unordered_map<string, P>& m,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename M, typename S>
|
template <typename M, typename S>
|
||||||
static string get_semantic_name(const unordered_map<string, M>* map,
|
static const char *get_semantic_name(const unordered_map<string, M>* map,
|
||||||
S semantic, unsigned index)
|
S semantic, unsigned index)
|
||||||
{
|
{
|
||||||
for (const pair<string, M>& m : *map)
|
for (const pair<string, M>& m : *map)
|
||||||
{
|
{
|
||||||
if (m.second.semantic == semantic && m.second.index == index)
|
if (m.second.semantic == semantic && m.second.index == index)
|
||||||
return m.first;
|
return m.first.c_str();
|
||||||
}
|
}
|
||||||
return string();
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static string
|
static const char *
|
||||||
get_semantic_name(slang_reflection& reflection,
|
get_semantic_name(slang_reflection& reflection,
|
||||||
slang_semantic semantic, unsigned index)
|
slang_semantic semantic, unsigned index)
|
||||||
{
|
{
|
||||||
@ -74,37 +74,53 @@ get_semantic_name(slang_reflection& reflection,
|
|||||||
"FrameDirection",
|
"FrameDirection",
|
||||||
};
|
};
|
||||||
if ((int)semantic < sizeof(names) / sizeof(*names))
|
if ((int)semantic < sizeof(names) / sizeof(*names))
|
||||||
return std::string(names[semantic]);
|
return names[semantic];
|
||||||
|
|
||||||
return get_semantic_name(reflection.semantic_map, semantic, index);
|
return get_semantic_name(reflection.semantic_map, semantic, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string
|
static const char *
|
||||||
get_semantic_name(slang_reflection& reflection,
|
get_semantic_name(slang_reflection& reflection,
|
||||||
slang_texture_semantic semantic, unsigned index)
|
slang_texture_semantic semantic, unsigned index)
|
||||||
{
|
{
|
||||||
static const char* names[] = {
|
static const char* names[] = {
|
||||||
"Original", "Source", "OriginalHistory", "PassOutput", "PassFeedback",
|
"Original",
|
||||||
|
"Source",
|
||||||
|
"OriginalHistory",
|
||||||
|
"PassOutput",
|
||||||
|
"PassFeedback",
|
||||||
};
|
};
|
||||||
if ((int)semantic < (int)SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY)
|
if ((int)semantic < (int)SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY)
|
||||||
return std::string(names[semantic]);
|
return names[semantic];
|
||||||
else if ((int)semantic < sizeof(names) / sizeof(*names))
|
if ((int)semantic < sizeof(names) / sizeof(*names))
|
||||||
return std::string(names[semantic]) + to_string(index);
|
{
|
||||||
|
static char buf[32] = {0};
|
||||||
|
snprintf(buf, sizeof(buf), "%s%u", names[semantic], index);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
return get_semantic_name(reflection.texture_semantic_map, semantic, index);
|
return get_semantic_name(reflection.texture_semantic_map, semantic, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string get_size_semantic_name(
|
static const char *get_size_semantic_name(
|
||||||
slang_reflection& reflection,
|
slang_reflection& reflection,
|
||||||
slang_texture_semantic semantic, unsigned index)
|
slang_texture_semantic semantic, unsigned index)
|
||||||
{
|
{
|
||||||
static const char* names[] = {
|
static const char* names[] = {
|
||||||
"OriginalSize", "SourceSize", "OriginalHistorySize", "PassOutputSize", "PassFeedbackSize",
|
"OriginalSize",
|
||||||
|
"SourceSize",
|
||||||
|
"OriginalHistorySize",
|
||||||
|
"PassOutputSize",
|
||||||
|
"PassFeedbackSize",
|
||||||
};
|
};
|
||||||
if ((int)semantic < (int)SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY)
|
if ((int)semantic < (int)SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY)
|
||||||
return std::string(names[semantic]);
|
return names[semantic];
|
||||||
if ((int)semantic < sizeof(names) / sizeof(*names))
|
if ((int)semantic < sizeof(names) / sizeof(*names))
|
||||||
return std::string(names[semantic]) + to_string(index);
|
{
|
||||||
|
static char buf[32] = {0};
|
||||||
|
snprintf(buf, sizeof(buf), "%s%u", names[semantic], index);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
return get_semantic_name(reflection.texture_semantic_uniform_map, semantic, index);
|
return get_semantic_name(reflection.texture_semantic_uniform_map, semantic, index);
|
||||||
}
|
}
|
||||||
@ -214,10 +230,10 @@ static bool slang_process_reflection(
|
|||||||
uniform_sem_t uniform = { map->uniforms[semantic],
|
uniform_sem_t uniform = { map->uniforms[semantic],
|
||||||
src.num_components
|
src.num_components
|
||||||
* (unsigned)sizeof(float) };
|
* (unsigned)sizeof(float) };
|
||||||
string uniform_id = get_semantic_name(
|
const char *uniform_id = get_semantic_name(
|
||||||
sl_reflection, (slang_semantic)semantic, 0);
|
sl_reflection, (slang_semantic)semantic, 0);
|
||||||
|
|
||||||
strlcpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
|
strlcpy(uniform.id, uniform_id, sizeof(uniform.id));
|
||||||
|
|
||||||
if (src.push_constant)
|
if (src.push_constant)
|
||||||
{
|
{
|
||||||
@ -241,9 +257,9 @@ static bool slang_process_reflection(
|
|||||||
uniform_sem_t uniform = {
|
uniform_sem_t uniform = {
|
||||||
&shader_info->parameters[i].current, sizeof(float) };
|
&shader_info->parameters[i].current, sizeof(float) };
|
||||||
|
|
||||||
string uniform_id = get_semantic_name(
|
const char *uniform_id = get_semantic_name(
|
||||||
sl_reflection, SLANG_SEMANTIC_FLOAT_PARAMETER, i);
|
sl_reflection, SLANG_SEMANTIC_FLOAT_PARAMETER, i);
|
||||||
strlcpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
|
strlcpy(uniform.id, uniform_id, sizeof(uniform.id));
|
||||||
|
|
||||||
if (src.push_constant)
|
if (src.push_constant)
|
||||||
{
|
{
|
||||||
@ -286,10 +302,10 @@ static bool slang_process_reflection(
|
|||||||
}
|
}
|
||||||
texture.stage_mask = src.stage_mask;
|
texture.stage_mask = src.stage_mask;
|
||||||
texture.binding = src.binding;
|
texture.binding = src.binding;
|
||||||
string id = get_semantic_name(
|
const char *id = get_semantic_name(
|
||||||
sl_reflection, (slang_texture_semantic)semantic, index);
|
sl_reflection, (slang_texture_semantic)semantic, index);
|
||||||
|
|
||||||
strlcpy(texture.id, id.c_str(), sizeof(texture.id));
|
strlcpy(texture.id, id, sizeof(texture.id));
|
||||||
|
|
||||||
textures.push_back(texture);
|
textures.push_back(texture);
|
||||||
|
|
||||||
@ -309,12 +325,12 @@ static bool slang_process_reflection(
|
|||||||
4 * sizeof(float)
|
4 * sizeof(float)
|
||||||
};
|
};
|
||||||
|
|
||||||
string uniform_id =
|
const char *uniform_id =
|
||||||
get_size_semantic_name(
|
get_size_semantic_name(
|
||||||
sl_reflection,
|
sl_reflection,
|
||||||
(slang_texture_semantic)semantic, index);
|
(slang_texture_semantic)semantic, index);
|
||||||
|
|
||||||
strlcpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
|
strlcpy(uniform.id, uniform_id, sizeof(uniform.id));
|
||||||
|
|
||||||
if (src.push_constant)
|
if (src.push_constant)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user