Move C oriented code from slang_reflection.cpp to glslang_util.c

This commit is contained in:
twinaphex 2020-01-22 19:36:49 +01:00
parent ff9701685f
commit a4564b8939
3 changed files with 61 additions and 52 deletions

View file

@ -48,6 +48,56 @@ static void get_include_file(
strlcpy(include_file, start, len);
}
bool slang_texture_semantic_is_array(enum slang_texture_semantic sem)
{
switch (sem)
{
case SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY:
case SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT:
case SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK:
case SLANG_TEXTURE_SEMANTIC_USER:
return true;
default:
break;
}
return false;
}
enum slang_texture_semantic slang_name_to_texture_semantic_array(
const char *name, const char **names,
unsigned *index)
{
unsigned i = 0;
while (*names)
{
const char *n = *names;
enum slang_texture_semantic semantic = (enum slang_texture_semantic)(i);
if (slang_texture_semantic_is_array(semantic))
{
size_t baselen = strlen(n);
int cmp = strncmp(n, name, baselen);
if (cmp == 0)
{
*index = (unsigned)strtoul(name + baselen, NULL, 0);
return semantic;
}
}
else if (string_is_equal(name, n))
{
*index = 0;
return semantic;
}
i++;
names++;
}
return SLANG_INVALID_TEXTURE_SEMANTIC;
}
bool glslang_read_shader_file(const char *path,
struct string_list *output, bool root_file)
{

View file

@ -21,6 +21,8 @@
#include <lists/string_list.h>
#include "slang_reflection.h"
typedef enum glslang_format
{
SLANG_FORMAT_UNKNOWN = 0,
@ -75,6 +77,12 @@ enum glslang_format glslang_find_format(const char *fmt);
bool glslang_read_shader_file(const char *path,
struct string_list *output, bool root_file);
bool slang_texture_semantic_is_array(enum slang_texture_semantic sem);
enum slang_texture_semantic slang_name_to_texture_semantic_array(
const char *name, const char **names,
unsigned *index);
RETRO_END_DECLS
#endif

View file

@ -20,6 +20,7 @@
#include <algorithm>
#include <stdio.h>
#include <compat/strl.h>
#include "glslang_util.h"
#include "../../verbosity.h"
using namespace std;
@ -53,23 +54,6 @@ static const char *semantic_uniform_names[] = {
"FrameDirection",
};
static bool slang_texture_semantic_is_array(slang_texture_semantic sem)
{
switch (sem)
{
case SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY:
case SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT:
case SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK:
case SLANG_TEXTURE_SEMANTIC_USER:
return true;
default:
break;
}
return false;
}
slang_reflection::slang_reflection()
{
unsigned i;
@ -81,39 +65,6 @@ slang_reflection::slang_reflection()
? 0 : 1);
}
static slang_texture_semantic slang_name_to_texture_semantic_array(
const string &name, const char **names,
unsigned *index)
{
unsigned i = 0;
while (*names)
{
const char *n = *names;
slang_texture_semantic semantic = static_cast<slang_texture_semantic>(i);
if (slang_texture_semantic_is_array(semantic))
{
size_t baselen = strlen(n);
int cmp = strncmp(n, name.c_str(), baselen);
if (cmp == 0)
{
*index = (unsigned)strtoul(name.c_str() + baselen, nullptr, 0);
return semantic;
}
}
else if (name == n)
{
*index = 0;
return semantic;
}
i++;
names++;
}
return SLANG_INVALID_TEXTURE_SEMANTIC;
}
static slang_texture_semantic slang_name_to_texture_semantic(
const unordered_map<string, slang_texture_semantic_map> &semantic_map,
const string &name, unsigned *index)
@ -126,7 +77,7 @@ static slang_texture_semantic slang_name_to_texture_semantic(
}
return slang_name_to_texture_semantic_array(
name, texture_semantic_names, index);
name.c_str(), texture_semantic_names, index);
}
static slang_texture_semantic slang_uniform_name_to_texture_semantic(
@ -140,7 +91,7 @@ static slang_texture_semantic slang_uniform_name_to_texture_semantic(
return itr->second.semantic;
}
return slang_name_to_texture_semantic_array(name,
return slang_name_to_texture_semantic_array(name.c_str(),
texture_semantic_uniform_names, index);
}