mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 19:21:03 +00:00
(glslang_util.cpp) Cleanups/style nits
This commit is contained in:
parent
52ad8fb125
commit
0ee34b0076
@ -55,9 +55,12 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
|
|
||||||
while (ptr && *ptr)
|
while (ptr && *ptr)
|
||||||
{
|
{
|
||||||
|
char *next_ptr = NULL;
|
||||||
|
|
||||||
lines.push_back(ptr);
|
lines.push_back(ptr);
|
||||||
|
|
||||||
char *next_ptr = strchr(ptr, '\n');
|
next_ptr = strchr(ptr, '\n');
|
||||||
|
|
||||||
if (next_ptr)
|
if (next_ptr)
|
||||||
{
|
{
|
||||||
ptr = next_ptr + 1;
|
ptr = next_ptr + 1;
|
||||||
@ -68,10 +71,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lines.empty())
|
if (lines.empty())
|
||||||
{
|
goto error;
|
||||||
free(buf);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root_file)
|
if (root_file)
|
||||||
{
|
{
|
||||||
@ -104,9 +104,9 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
if (!c)
|
if (!c)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Invalid include statement \"%s\".\n", line);
|
RARCH_ERR("Invalid include statement \"%s\".\n", line);
|
||||||
free(buf);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
closing = (char*)strchr(c, '"');
|
closing = (char*)strchr(c, '"');
|
||||||
@ -114,8 +114,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
if (!closing)
|
if (!closing)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Invalid include statement \"%s\".\n", line);
|
RARCH_ERR("Invalid include statement \"%s\".\n", line);
|
||||||
free(buf);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*closing = '\0';
|
*closing = '\0';
|
||||||
@ -123,10 +122,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
fill_pathname_resolve_relative(include_path, path, c, sizeof(include_path));
|
fill_pathname_resolve_relative(include_path, path, c, sizeof(include_path));
|
||||||
|
|
||||||
if (!glslang_read_shader_file(include_path, output, false))
|
if (!glslang_read_shader_file(include_path, output, false))
|
||||||
{
|
goto error;
|
||||||
free(buf);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* After including a file, use line directive
|
/* After including a file, use line directive
|
||||||
* to pull it back to current file. */
|
* to pull it back to current file. */
|
||||||
@ -150,6 +146,10 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
|||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(buf);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string build_stage_source(const vector<string> &lines, const char *stage)
|
static string build_stage_source(const vector<string> &lines, const char *stage)
|
||||||
@ -270,22 +270,27 @@ static glslang_format glslang_find_format(const char *fmt)
|
|||||||
|
|
||||||
bool glslang_parse_meta(const vector<string> &lines, glslang_meta *meta)
|
bool glslang_parse_meta(const vector<string> &lines, glslang_meta *meta)
|
||||||
{
|
{
|
||||||
char id[64] = {};
|
char id[64];
|
||||||
char desc[64] = {};
|
char desc[64];
|
||||||
|
|
||||||
*meta = glslang_meta{};
|
id[0] = desc[0] = '\0';
|
||||||
|
|
||||||
|
*meta = glslang_meta{};
|
||||||
|
|
||||||
for (auto &line : lines)
|
for (auto &line : lines)
|
||||||
{
|
{
|
||||||
if (line.find("#pragma name ") == 0)
|
if (line.find("#pragma name ") == 0)
|
||||||
{
|
{
|
||||||
|
const char *str = NULL;
|
||||||
|
|
||||||
if (!meta->name.empty())
|
if (!meta->name.empty())
|
||||||
{
|
{
|
||||||
RARCH_ERR("[slang]: Trying to declare multiple names for file.\n");
|
RARCH_ERR("[slang]: Trying to declare multiple names for file.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *str = line.c_str() + strlen("#pragma name ");
|
str = line.c_str() + strlen("#pragma name ");
|
||||||
|
|
||||||
while (*str == ' ')
|
while (*str == ' ')
|
||||||
str++;
|
str++;
|
||||||
meta->name = str;
|
meta->name = str;
|
||||||
@ -299,7 +304,7 @@ bool glslang_parse_meta(const vector<string> &lines, glslang_meta *meta)
|
|||||||
if (ret == 5)
|
if (ret == 5)
|
||||||
{
|
{
|
||||||
step = 0.1f * (maximum - minimum);
|
step = 0.1f * (maximum - minimum);
|
||||||
ret = 6;
|
ret = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 6)
|
if (ret == 6)
|
||||||
@ -312,11 +317,12 @@ bool glslang_parse_meta(const vector<string> &lines, glslang_meta *meta)
|
|||||||
* if they are exactly the same. */
|
* if they are exactly the same. */
|
||||||
if (itr != end(meta->parameters))
|
if (itr != end(meta->parameters))
|
||||||
{
|
{
|
||||||
if ( itr->desc != desc ||
|
if ( itr->desc != desc ||
|
||||||
itr->initial != initial ||
|
itr->initial != initial ||
|
||||||
itr->minimum != minimum ||
|
itr->minimum != minimum ||
|
||||||
itr->maximum != maximum ||
|
itr->maximum != maximum ||
|
||||||
itr->step != step)
|
itr->step != step
|
||||||
|
)
|
||||||
{
|
{
|
||||||
RARCH_ERR("[slang]: Duplicate parameters found for \"%s\", but arguments do not match.\n", id);
|
RARCH_ERR("[slang]: Duplicate parameters found for \"%s\", but arguments do not match.\n", id);
|
||||||
return false;
|
return false;
|
||||||
@ -362,20 +368,21 @@ bool glslang_compile_shader(const char *shader_path, glslang_output *output)
|
|||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
|
|
||||||
RARCH_LOG("[slang]: Compiling shader \"%s\".\n", shader_path);
|
RARCH_LOG("[slang]: Compiling shader \"%s\".\n", shader_path);
|
||||||
|
|
||||||
if (!glslang_read_shader_file(shader_path, &lines, true))
|
if (!glslang_read_shader_file(shader_path, &lines, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!glslang_parse_meta(lines, &output->meta))
|
if (!glslang_parse_meta(lines, &output->meta))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!glslang::compile_spirv(build_stage_source(lines, "vertex"),
|
if ( !glslang::compile_spirv(build_stage_source(lines, "vertex"),
|
||||||
glslang::StageVertex, &output->vertex))
|
glslang::StageVertex, &output->vertex))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to compile vertex shader stage.\n");
|
RARCH_ERR("Failed to compile vertex shader stage.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glslang::compile_spirv(build_stage_source(lines, "fragment"),
|
if ( !glslang::compile_spirv(build_stage_source(lines, "fragment"),
|
||||||
glslang::StageFragment, &output->fragment))
|
glslang::StageFragment, &output->fragment))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to compile fragment shader stage.\n");
|
RARCH_ERR("Failed to compile fragment shader stage.\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user