mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-03 15:54:39 +00:00
Merge slang_preprocess.cpp into slang_process.cpp
This commit is contained in:
parent
0905c8d2ed
commit
d52c573e13
@ -1487,7 +1487,6 @@ endif
|
||||
ifeq ($(HAVE_SLANG),1)
|
||||
DEFINES += -DHAVE_SLANG
|
||||
OBJ += gfx/drivers_shader/slang_process.o
|
||||
OBJ += gfx/drivers_shader/slang_preprocess.o
|
||||
OBJ += gfx/drivers_shader/glslang_util.o
|
||||
OBJ += gfx/drivers_shader/glslang_util_cxx.o
|
||||
OBJ += gfx/drivers_shader/slang_reflection.o
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "../../performance_counters.h"
|
||||
#include "../../menu/menu_driver.h"
|
||||
#include "../video_shader_parse.h"
|
||||
#include "../drivers_shader/slang_preprocess.h"
|
||||
#include "../drivers_shader/slang_process.h"
|
||||
#include "../../managers/state_manager.h"
|
||||
|
||||
#include "../common/d3d_common.h"
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
#include "gfx/common/gx2_common.h"
|
||||
#include "gfx/video_shader_parse.h"
|
||||
#include "gfx/drivers_shader/slang_preprocess.h"
|
||||
#include "gfx/drivers_shader/slang_process.h"
|
||||
#include "system/memory.h"
|
||||
|
||||
#include "wiiu_dbg.h"
|
||||
|
@ -1,117 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2017 - Hans-Kristian Arntzen
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "slang_preprocess.h"
|
||||
#include "glslang_util.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include <compat/strl.h>
|
||||
#include <lists/string_list.h>
|
||||
|
||||
#include "../../verbosity.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool slang_preprocess_parse_parameters(glslang_meta& meta,
|
||||
struct video_shader *shader)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned old_num_parameters = shader->num_parameters;
|
||||
|
||||
/* Assumes num_parameters is
|
||||
* initialized to something sane. */
|
||||
for (i = 0; i < meta.parameters.size(); i++)
|
||||
{
|
||||
bool mismatch_dup = false;
|
||||
bool dup = false;
|
||||
auto itr = find_if(shader->parameters,
|
||||
shader->parameters + shader->num_parameters,
|
||||
[&](const video_shader_parameter &parsed_param)
|
||||
{
|
||||
return meta.parameters[i].id == parsed_param.id;
|
||||
});
|
||||
|
||||
if (itr != shader->parameters + shader->num_parameters)
|
||||
{
|
||||
dup = true;
|
||||
/* Allow duplicate #pragma parameter, but only
|
||||
* if they are exactly the same. */
|
||||
if ( meta.parameters[i].desc != itr->desc ||
|
||||
meta.parameters[i].initial != itr->initial ||
|
||||
meta.parameters[i].minimum != itr->minimum ||
|
||||
meta.parameters[i].maximum != itr->maximum ||
|
||||
meta.parameters[i].step != itr->step)
|
||||
{
|
||||
RARCH_ERR("[slang]: Duplicate parameters"
|
||||
" found for \"%s\", but arguments do not match.\n",
|
||||
itr->id);
|
||||
mismatch_dup = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dup && !mismatch_dup)
|
||||
continue;
|
||||
|
||||
if (mismatch_dup || shader->num_parameters == GFX_MAX_PARAMETERS)
|
||||
{
|
||||
shader->num_parameters = old_num_parameters;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct video_shader_parameter *p = (struct video_shader_parameter*)
|
||||
&shader->parameters[shader->num_parameters++];
|
||||
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
strlcpy(p->id, meta.parameters[i].id.c_str(), sizeof(p->id));
|
||||
strlcpy(p->desc, meta.parameters[i].desc.c_str(), sizeof(p->desc));
|
||||
p->initial = meta.parameters[i].initial;
|
||||
p->minimum = meta.parameters[i].minimum;
|
||||
p->maximum = meta.parameters[i].maximum;
|
||||
p->step = meta.parameters[i].step;
|
||||
p->current = meta.parameters[i].initial;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool slang_preprocess_parse_parameters(const char *shader_path,
|
||||
struct video_shader *shader)
|
||||
{
|
||||
glslang_meta meta;
|
||||
bool ret = false;
|
||||
struct string_list *lines = string_list_new();
|
||||
|
||||
if (!lines)
|
||||
goto end;
|
||||
|
||||
if (!glslang_read_shader_file(shader_path, lines, true))
|
||||
goto end;
|
||||
meta = glslang_meta{};
|
||||
if (!glslang_parse_meta(lines, &meta))
|
||||
goto end;
|
||||
|
||||
ret = slang_preprocess_parse_parameters(meta, shader);
|
||||
|
||||
end:
|
||||
|
||||
if (lines)
|
||||
string_list_free(lines);
|
||||
|
||||
return ret;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2017 - Hans-Kristian Arntzen
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SLANG_PREPROCESS_H
|
||||
#define SLANG_PREPROCESS_H
|
||||
|
||||
#include <boolean.h>
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#include "../../retroarch.h"
|
||||
#include "glslang_util.h"
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
/* Utility function to implement the same parameter reflection
|
||||
* which happens in the slang backend.
|
||||
* This does preprocess over the input file to handle #includes and so on. */
|
||||
bool slang_preprocess_parse_parameters(const char *shader_path,
|
||||
struct video_shader *shader);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "glslang_util_cxx.h"
|
||||
|
||||
bool slang_preprocess_parse_parameters(glslang_meta& meta,
|
||||
struct video_shader *shader);
|
||||
#endif
|
||||
|
||||
#endif
|
@ -24,7 +24,6 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "glslang_util.h"
|
||||
#include "slang_preprocess.h"
|
||||
#include "slang_reflection.h"
|
||||
#include "slang_reflection.hpp"
|
||||
#include "slang_process.h"
|
||||
@ -359,6 +358,96 @@ static bool slang_process_reflection(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool slang_preprocess_parse_parameters(glslang_meta& meta,
|
||||
struct video_shader *shader)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned old_num_parameters = shader->num_parameters;
|
||||
|
||||
/* Assumes num_parameters is
|
||||
* initialized to something sane. */
|
||||
for (i = 0; i < meta.parameters.size(); i++)
|
||||
{
|
||||
bool mismatch_dup = false;
|
||||
bool dup = false;
|
||||
auto itr = find_if(shader->parameters,
|
||||
shader->parameters + shader->num_parameters,
|
||||
[&](const video_shader_parameter &parsed_param)
|
||||
{
|
||||
return meta.parameters[i].id == parsed_param.id;
|
||||
});
|
||||
|
||||
if (itr != shader->parameters + shader->num_parameters)
|
||||
{
|
||||
dup = true;
|
||||
/* Allow duplicate #pragma parameter, but only
|
||||
* if they are exactly the same. */
|
||||
if ( meta.parameters[i].desc != itr->desc ||
|
||||
meta.parameters[i].initial != itr->initial ||
|
||||
meta.parameters[i].minimum != itr->minimum ||
|
||||
meta.parameters[i].maximum != itr->maximum ||
|
||||
meta.parameters[i].step != itr->step)
|
||||
{
|
||||
RARCH_ERR("[slang]: Duplicate parameters"
|
||||
" found for \"%s\", but arguments do not match.\n",
|
||||
itr->id);
|
||||
mismatch_dup = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dup && !mismatch_dup)
|
||||
continue;
|
||||
|
||||
if (mismatch_dup || shader->num_parameters == GFX_MAX_PARAMETERS)
|
||||
{
|
||||
shader->num_parameters = old_num_parameters;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct video_shader_parameter *p = (struct video_shader_parameter*)
|
||||
&shader->parameters[shader->num_parameters++];
|
||||
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
strlcpy(p->id, meta.parameters[i].id.c_str(), sizeof(p->id));
|
||||
strlcpy(p->desc, meta.parameters[i].desc.c_str(), sizeof(p->desc));
|
||||
p->initial = meta.parameters[i].initial;
|
||||
p->minimum = meta.parameters[i].minimum;
|
||||
p->maximum = meta.parameters[i].maximum;
|
||||
p->step = meta.parameters[i].step;
|
||||
p->current = meta.parameters[i].initial;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool slang_preprocess_parse_parameters(const char *shader_path,
|
||||
struct video_shader *shader)
|
||||
{
|
||||
glslang_meta meta;
|
||||
bool ret = false;
|
||||
struct string_list *lines = string_list_new();
|
||||
|
||||
if (!lines)
|
||||
goto end;
|
||||
|
||||
if (!glslang_read_shader_file(shader_path, lines, true))
|
||||
goto end;
|
||||
meta = glslang_meta{};
|
||||
if (!glslang_parse_meta(lines, &meta))
|
||||
goto end;
|
||||
|
||||
ret = slang_preprocess_parse_parameters(meta, shader);
|
||||
|
||||
end:
|
||||
|
||||
if (lines)
|
||||
string_list_free(lines);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool slang_process(
|
||||
video_shader* shader_info,
|
||||
unsigned pass_number,
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#include "../video_shader_parse.h"
|
||||
#include "../../retroarch.h"
|
||||
#include "slang_reflection.h"
|
||||
#include "glslang_util.h"
|
||||
|
||||
@ -84,6 +85,12 @@ typedef struct
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
/* Utility function to implement the same parameter reflection
|
||||
* which happens in the slang backend.
|
||||
* This does preprocess over the input file to handle #includes and so on. */
|
||||
bool slang_preprocess_parse_parameters(const char *shader_path,
|
||||
struct video_shader *shader);
|
||||
|
||||
bool slang_process(
|
||||
struct video_shader* shader_info,
|
||||
unsigned pass_number,
|
||||
@ -94,4 +101,12 @@ bool slang_process(
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "glslang_util_cxx.h"
|
||||
|
||||
bool slang_preprocess_parse_parameters(glslang_meta& meta,
|
||||
struct video_shader *shader);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "video_shader_parse.h"
|
||||
|
||||
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
||||
#include "drivers_shader/slang_preprocess.h"
|
||||
#include "drivers_shader/slang_process.h"
|
||||
#endif
|
||||
|
||||
static path_change_data_t *file_change_data = NULL;
|
||||
|
@ -116,7 +116,6 @@ VIDEO DRIVER
|
||||
#include "../deps/SPIRV-Cross/spirv_cross_parsed_ir.cpp"
|
||||
#ifdef HAVE_SLANG
|
||||
#include "../gfx/drivers_shader/glslang_util_cxx.cpp"
|
||||
#include "../gfx/drivers_shader/slang_preprocess.cpp"
|
||||
#include "../gfx/drivers_shader/slang_process.cpp"
|
||||
#include "../gfx/drivers_shader/slang_reflection.cpp"
|
||||
#endif
|
||||
|
@ -408,7 +408,6 @@
|
||||
05A8C78820DB72F100FF7857 /* gl_raster_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = gl_raster_font.c; sourceTree = "<group>"; };
|
||||
05A8C78920DB72F100FF7857 /* vulkan_raster_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vulkan_raster_font.c; sourceTree = "<group>"; };
|
||||
05A8C78D20DB72F100FF7857 /* video_filter.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_filter.c; sourceTree = "<group>"; };
|
||||
05A8C78F20DB72F100FF7857 /* slang_preprocess.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = slang_preprocess.cpp; sourceTree = "<group>"; };
|
||||
05A8C79020DB72F100FF7857 /* glslang_util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = glslang_util.h; sourceTree = "<group>"; };
|
||||
05A8C79120DB72F100FF7857 /* shader_glsl.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = shader_glsl.c; sourceTree = "<group>"; };
|
||||
05A8C79220DB72F100FF7857 /* slang_process.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = slang_process.h; sourceTree = "<group>"; };
|
||||
@ -419,7 +418,6 @@
|
||||
05A8C79720DB72F100FF7857 /* shader_glsl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shader_glsl.h; sourceTree = "<group>"; };
|
||||
05A8C79820DB72F100FF7857 /* shader_null.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = shader_null.c; sourceTree = "<group>"; };
|
||||
05A8C79920DB72F100FF7857 /* glslang_util.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = glslang_util.cpp; sourceTree = "<group>"; };
|
||||
05A8C79A20DB72F100FF7857 /* slang_preprocess.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = slang_preprocess.h; sourceTree = "<group>"; };
|
||||
05A8C79B20DB72F100FF7857 /* shader_gl_cg.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = shader_gl_cg.c; sourceTree = "<group>"; };
|
||||
05A8C79C20DB72F100FF7857 /* shader_vulkan.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shader_vulkan.h; sourceTree = "<group>"; };
|
||||
05A8C79D20DB72F100FF7857 /* video_crt_switch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_crt_switch.h; sourceTree = "<group>"; };
|
||||
@ -1195,8 +1193,6 @@
|
||||
05A8C79820DB72F100FF7857 /* shader_null.c */,
|
||||
05A8C79520DB72F100FF7857 /* shader_vulkan.cpp */,
|
||||
05A8C79C20DB72F100FF7857 /* shader_vulkan.h */,
|
||||
05A8C78F20DB72F100FF7857 /* slang_preprocess.cpp */,
|
||||
05A8C79A20DB72F100FF7857 /* slang_preprocess.h */,
|
||||
05A8C79420DB72F100FF7857 /* slang_process.cpp */,
|
||||
05A8C79220DB72F100FF7857 /* slang_process.h */,
|
||||
05A8C79620DB72F100FF7857 /* slang_reflection.cpp */,
|
||||
|
Loading…
x
Reference in New Issue
Block a user