(glslang_util.cpp) Cleanups/style nits

This commit is contained in:
twinaphex 2017-01-12 10:32:57 +01:00
parent 52ad8fb125
commit 0ee34b0076

View File

@ -55,9 +55,12 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
while (ptr && *ptr)
{
char *next_ptr = NULL;
lines.push_back(ptr);
char *next_ptr = strchr(ptr, '\n');
next_ptr = strchr(ptr, '\n');
if (next_ptr)
{
ptr = next_ptr + 1;
@ -68,10 +71,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
}
if (lines.empty())
{
free(buf);
return false;
}
goto error;
if (root_file)
{
@ -104,9 +104,9 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
if (!c)
{
RARCH_ERR("Invalid include statement \"%s\".\n", line);
free(buf);
return false;
goto error;
}
c++;
closing = (char*)strchr(c, '"');
@ -114,8 +114,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
if (!closing)
{
RARCH_ERR("Invalid include statement \"%s\".\n", line);
free(buf);
return false;
goto error;
}
*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));
if (!glslang_read_shader_file(include_path, output, false))
{
free(buf);
return false;
}
goto error;
/* After including a file, use line directive
* 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);
return true;
error:
free(buf);
return false;
}
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)
{
char id[64] = {};
char desc[64] = {};
char id[64];
char desc[64];
*meta = glslang_meta{};
id[0] = desc[0] = '\0';
*meta = glslang_meta{};
for (auto &line : lines)
{
if (line.find("#pragma name ") == 0)
{
const char *str = NULL;
if (!meta->name.empty())
{
RARCH_ERR("[slang]: Trying to declare multiple names for file.\n");
return false;
}
const char *str = line.c_str() + strlen("#pragma name ");
str = line.c_str() + strlen("#pragma name ");
while (*str == ' ')
str++;
meta->name = str;
@ -299,7 +304,7 @@ bool glslang_parse_meta(const vector<string> &lines, glslang_meta *meta)
if (ret == 5)
{
step = 0.1f * (maximum - minimum);
ret = 6;
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 (itr != end(meta->parameters))
{
if ( itr->desc != desc ||
itr->initial != initial ||
itr->minimum != minimum ||
itr->maximum != maximum ||
itr->step != step)
if ( itr->desc != desc ||
itr->initial != initial ||
itr->minimum != minimum ||
itr->maximum != maximum ||
itr->step != step
)
{
RARCH_ERR("[slang]: Duplicate parameters found for \"%s\", but arguments do not match.\n", id);
return false;
@ -362,20 +368,21 @@ bool glslang_compile_shader(const char *shader_path, glslang_output *output)
vector<string> lines;
RARCH_LOG("[slang]: Compiling shader \"%s\".\n", shader_path);
if (!glslang_read_shader_file(shader_path, &lines, true))
return false;
if (!glslang_parse_meta(lines, &output->meta))
return false;
if (!glslang::compile_spirv(build_stage_source(lines, "vertex"),
if ( !glslang::compile_spirv(build_stage_source(lines, "vertex"),
glslang::StageVertex, &output->vertex))
{
RARCH_ERR("Failed to compile vertex shader stage.\n");
return false;
}
if (!glslang::compile_spirv(build_stage_source(lines, "fragment"),
if ( !glslang::compile_spirv(build_stage_source(lines, "fragment"),
glslang::StageFragment, &output->fragment))
{
RARCH_ERR("Failed to compile fragment shader stage.\n");