2013-04-06 09:30:56 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-12-12 07:55:31 +00:00
|
|
|
*
|
2013-04-06 09:30:56 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-12 22:42:50 +00:00
|
|
|
#ifndef __VIDEO_SHADER_PARSE_H
|
|
|
|
#define __VIDEO_SHADER_PARSE_H
|
2013-04-06 09:30:56 +00:00
|
|
|
|
2016-06-03 03:43:49 +00:00
|
|
|
#include <boolean.h>
|
|
|
|
#include <retro_common_api.h>
|
2014-10-21 06:39:37 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-06-03 03:43:49 +00:00
|
|
|
#include <file/config_file.h>
|
2020-01-22 13:30:55 +00:00
|
|
|
#include <file/file_path.h>
|
2021-09-11 16:15:35 +00:00
|
|
|
#include <lists/string_list.h>
|
|
|
|
|
|
|
|
#include "../configuration.h"
|
2013-04-06 09:30:56 +00:00
|
|
|
|
2016-06-03 03:43:49 +00:00
|
|
|
RETRO_BEGIN_DECLS
|
2013-04-07 00:02:41 +00:00
|
|
|
|
2014-05-31 19:23:53 +00:00
|
|
|
#ifndef GFX_MAX_SHADERS
|
2020-07-05 17:45:58 +00:00
|
|
|
#define GFX_MAX_SHADERS 64
|
2014-05-31 19:23:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GFX_MAX_TEXTURES
|
2020-11-22 14:50:24 +00:00
|
|
|
#define GFX_MAX_TEXTURES 64
|
2014-05-31 19:23:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GFX_MAX_PARAMETERS
|
2021-07-22 14:20:50 +00:00
|
|
|
#define GFX_MAX_PARAMETERS 1024
|
2014-05-31 19:23:53 +00:00
|
|
|
#endif
|
2013-04-06 09:30:56 +00:00
|
|
|
|
2018-02-03 12:29:00 +00:00
|
|
|
#ifndef GFX_MAX_FRAME_HISTORY
|
|
|
|
#define GFX_MAX_FRAME_HISTORY 128
|
|
|
|
#endif
|
|
|
|
|
2014-06-17 14:41:06 +00:00
|
|
|
enum rarch_shader_type
|
|
|
|
{
|
2014-09-15 19:54:03 +00:00
|
|
|
RARCH_SHADER_NONE = 0,
|
2014-06-17 14:41:06 +00:00
|
|
|
RARCH_SHADER_CG,
|
|
|
|
RARCH_SHADER_HLSL,
|
2016-02-16 19:24:00 +00:00
|
|
|
RARCH_SHADER_GLSL,
|
2018-06-21 04:29:53 +00:00
|
|
|
RARCH_SHADER_SLANG,
|
|
|
|
RARCH_SHADER_METAL
|
2014-06-17 14:41:06 +00:00
|
|
|
};
|
|
|
|
|
2013-04-06 09:30:56 +00:00
|
|
|
enum gfx_scale_type
|
|
|
|
{
|
|
|
|
RARCH_SCALE_INPUT = 0,
|
|
|
|
RARCH_SCALE_ABSOLUTE,
|
|
|
|
RARCH_SCALE_VIEWPORT
|
|
|
|
};
|
|
|
|
|
2014-08-17 17:02:03 +00:00
|
|
|
enum
|
2013-04-06 09:30:56 +00:00
|
|
|
{
|
|
|
|
RARCH_FILTER_UNSPEC = 0,
|
|
|
|
RARCH_FILTER_LINEAR,
|
2018-02-02 16:18:41 +00:00
|
|
|
RARCH_FILTER_NEAREST,
|
|
|
|
RARCH_FILTER_MAX
|
2013-08-15 22:30:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum gfx_wrap_type
|
|
|
|
{
|
2017-12-12 07:55:31 +00:00
|
|
|
RARCH_WRAP_BORDER = 0, /* Kinda deprecated, but keep as default.
|
2014-09-08 15:57:18 +00:00
|
|
|
Will be translated to EDGE in GLES. */
|
2013-08-15 22:30:54 +00:00
|
|
|
RARCH_WRAP_DEFAULT = RARCH_WRAP_BORDER,
|
|
|
|
RARCH_WRAP_EDGE,
|
|
|
|
RARCH_WRAP_REPEAT,
|
2018-01-09 15:41:01 +00:00
|
|
|
RARCH_WRAP_MIRRORED_REPEAT,
|
|
|
|
RARCH_WRAP_MAX
|
2013-04-06 09:30:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gfx_fbo_scale
|
|
|
|
{
|
2020-08-27 20:17:51 +00:00
|
|
|
unsigned abs_x;
|
|
|
|
unsigned abs_y;
|
2013-04-06 09:30:56 +00:00
|
|
|
float scale_x;
|
|
|
|
float scale_y;
|
2020-08-27 20:17:51 +00:00
|
|
|
enum gfx_scale_type type_x;
|
|
|
|
enum gfx_scale_type type_y;
|
2013-04-06 09:30:56 +00:00
|
|
|
bool fp_fbo;
|
2014-05-11 17:35:54 +00:00
|
|
|
bool srgb_fbo;
|
2013-11-04 04:57:41 +00:00
|
|
|
bool valid;
|
2013-04-06 09:30:56 +00:00
|
|
|
};
|
|
|
|
|
2015-01-19 20:24:08 +00:00
|
|
|
struct video_shader_parameter
|
2014-05-22 19:24:52 +00:00
|
|
|
{
|
2020-08-27 20:17:51 +00:00
|
|
|
int pass;
|
2014-05-22 19:24:52 +00:00
|
|
|
float current;
|
|
|
|
float minimum;
|
|
|
|
float initial;
|
|
|
|
float maximum;
|
|
|
|
float step;
|
2020-08-27 20:17:51 +00:00
|
|
|
char id[64];
|
|
|
|
char desc[64];
|
2014-05-22 19:24:52 +00:00
|
|
|
};
|
|
|
|
|
2021-09-11 16:15:35 +00:00
|
|
|
struct rarch_dir_shader_list
|
|
|
|
{
|
|
|
|
struct string_list *shader_list;
|
|
|
|
char *directory;
|
|
|
|
size_t selection;
|
|
|
|
bool shader_loaded;
|
|
|
|
bool remember_last_preset_dir;
|
|
|
|
};
|
|
|
|
|
2015-01-19 20:24:08 +00:00
|
|
|
struct video_shader_pass
|
2013-04-06 09:30:56 +00:00
|
|
|
{
|
2020-08-27 20:17:51 +00:00
|
|
|
struct gfx_fbo_scale fbo; /* unsigned alignment */
|
|
|
|
unsigned filter;
|
|
|
|
unsigned frame_count_mod;
|
|
|
|
enum gfx_wrap_type wrap;
|
2013-04-07 10:41:05 +00:00
|
|
|
struct
|
2013-04-06 09:30:56 +00:00
|
|
|
{
|
2013-04-07 10:41:05 +00:00
|
|
|
struct
|
|
|
|
{
|
2014-12-21 19:41:26 +00:00
|
|
|
char *vertex; /* Dynamically allocated. Must be free'd. */
|
|
|
|
char *fragment; /* Dynamically allocated. Must be free'd. */
|
2014-05-25 15:16:33 +00:00
|
|
|
} string;
|
2020-08-27 20:17:51 +00:00
|
|
|
char path[PATH_MAX_LENGTH];
|
2013-04-06 09:30:56 +00:00
|
|
|
} source;
|
2014-05-23 13:02:12 +00:00
|
|
|
char alias[64];
|
2014-05-11 11:13:38 +00:00
|
|
|
bool mipmap;
|
2018-02-02 18:57:45 +00:00
|
|
|
bool feedback;
|
2013-04-06 09:30:56 +00:00
|
|
|
};
|
|
|
|
|
2015-01-19 20:24:08 +00:00
|
|
|
struct video_shader_lut
|
2013-04-06 09:30:56 +00:00
|
|
|
{
|
2020-08-27 20:17:51 +00:00
|
|
|
unsigned filter;
|
|
|
|
enum gfx_wrap_type wrap;
|
2013-04-06 09:30:56 +00:00
|
|
|
char id[64];
|
2015-01-07 19:42:36 +00:00
|
|
|
char path[PATH_MAX_LENGTH];
|
2014-05-08 17:39:12 +00:00
|
|
|
bool mipmap;
|
2013-04-06 09:30:56 +00:00
|
|
|
};
|
|
|
|
|
2014-09-08 15:57:18 +00:00
|
|
|
/* This is pretty big, shouldn't be put on the stack.
|
|
|
|
* Avoid lots of allocation for convenience. */
|
2015-01-19 20:24:08 +00:00
|
|
|
struct video_shader
|
2013-04-06 09:30:56 +00:00
|
|
|
{
|
2020-08-27 20:17:51 +00:00
|
|
|
struct video_shader_parameter parameters[GFX_MAX_PARAMETERS]; /* int alignment */
|
|
|
|
/* If < 0, no feedback pass is used. Otherwise,
|
|
|
|
* the FBO after pass #N is passed a texture to next frame. */
|
|
|
|
int feedback_pass;
|
|
|
|
int history_size;
|
|
|
|
|
|
|
|
struct video_shader_pass pass[GFX_MAX_SHADERS]; /* unsigned alignment */
|
|
|
|
struct video_shader_lut lut[GFX_MAX_TEXTURES]; /* unsigned alignment */
|
|
|
|
unsigned passes;
|
|
|
|
unsigned luts;
|
|
|
|
unsigned num_parameters;
|
|
|
|
unsigned variables;
|
|
|
|
|
2013-04-07 10:41:05 +00:00
|
|
|
char prefix[64];
|
2020-11-01 14:18:40 +00:00
|
|
|
|
|
|
|
/* Path to the root preset */
|
2018-08-18 16:39:17 +00:00
|
|
|
char path[PATH_MAX_LENGTH];
|
2020-03-06 16:05:20 +00:00
|
|
|
|
2020-11-01 14:18:40 +00:00
|
|
|
/* Path to the original preset loaded, if this is a preset with the #reference
|
|
|
|
* directive then this will be different than the path*/
|
|
|
|
char loaded_preset_path[PATH_MAX_LENGTH];
|
|
|
|
|
2017-09-08 22:02:38 +00:00
|
|
|
bool modern; /* Only used for XML shaders. */
|
2020-03-06 16:05:20 +00:00
|
|
|
/* indicative of whether shader was modified -
|
|
|
|
* for instance from the menus */
|
|
|
|
bool modified;
|
2013-04-06 09:30:56 +00:00
|
|
|
};
|
|
|
|
|
2020-12-27 02:09:27 +00:00
|
|
|
|
2019-08-19 10:36:44 +00:00
|
|
|
/**
|
2020-12-27 02:09:27 +00:00
|
|
|
* video_shader_resolve_parameters:
|
|
|
|
* @conf : Preset file to read from.
|
|
|
|
* @shader : Shader passes handle.
|
2019-08-19 10:36:44 +00:00
|
|
|
*
|
2020-12-27 02:09:27 +00:00
|
|
|
* Resolves all shader parameters belonging to shaders
|
|
|
|
* from the #pragma parameter lines in the shader for each pass.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
2019-08-19 10:36:44 +00:00
|
|
|
**/
|
2020-12-27 02:09:27 +00:00
|
|
|
bool video_shader_resolve_parameters(struct video_shader *shader);
|
|
|
|
|
2019-08-19 10:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 02:09:27 +00:00
|
|
|
* video_shader_load_current_parameter_values:
|
|
|
|
* @conf : Preset file to read from.
|
|
|
|
* @shader : Shader passes handle.
|
2019-08-19 10:36:44 +00:00
|
|
|
*
|
2020-12-27 02:09:27 +00:00
|
|
|
* Reads the current value for all parameters from config file.
|
2019-08-19 10:36:44 +00:00
|
|
|
*
|
2020-12-27 02:09:27 +00:00
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
2019-08-19 10:36:44 +00:00
|
|
|
**/
|
2020-12-27 02:09:27 +00:00
|
|
|
bool video_shader_load_current_parameter_values(config_file_t *conf, struct video_shader *shader);
|
|
|
|
|
2019-08-19 10:36:44 +00:00
|
|
|
|
2017-12-12 07:55:31 +00:00
|
|
|
/**
|
2020-12-27 02:09:27 +00:00
|
|
|
* video_shader_load_preset_into_shader:
|
|
|
|
* @path : Path to preset file, could be a Simple Preset (including a #reference) or Full Preset
|
|
|
|
* @shader : Shader
|
|
|
|
*
|
|
|
|
* Loads preset file to a shader including passes, textures and parameters
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
|
|
|
**/
|
|
|
|
bool video_shader_load_preset_into_shader(const char *path, struct video_shader *shader);
|
|
|
|
|
|
|
|
|
2017-12-12 07:55:31 +00:00
|
|
|
/**
|
2020-12-27 02:09:27 +00:00
|
|
|
* video_shader_write_preset:
|
|
|
|
* @path : File to write to
|
|
|
|
* @shader : Shader to write
|
|
|
|
* @reference : Whether a simple preset should be written with the #reference to another preset in it
|
2015-01-11 18:59:59 +00:00
|
|
|
*
|
2020-12-27 02:09:27 +00:00
|
|
|
* Writes a preset to disk. Can be written as a simple preset (With the #reference directive in it) or a full preset.
|
2015-01-11 18:59:59 +00:00
|
|
|
**/
|
2020-12-27 02:09:27 +00:00
|
|
|
bool video_shader_write_preset(const char *path,
|
|
|
|
const char *shader_dir,
|
|
|
|
const struct video_shader *shader,
|
|
|
|
bool reference);
|
|
|
|
|
2014-09-08 15:57:18 +00:00
|
|
|
|
2020-12-27 02:09:27 +00:00
|
|
|
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext, bool *is_preset);
|
2020-01-22 13:30:55 +00:00
|
|
|
|
2015-01-11 19:10:01 +00:00
|
|
|
/**
|
2015-01-19 20:09:39 +00:00
|
|
|
* video_shader_parse_type:
|
2015-01-11 19:10:01 +00:00
|
|
|
* @path : Shader path.
|
|
|
|
*
|
|
|
|
* Parses type of shader.
|
|
|
|
*
|
2019-06-17 16:26:41 +00:00
|
|
|
* Returns: value of shader type if it could be determined,
|
|
|
|
* otherwise RARCH_SHADER_NONE.
|
2015-01-11 19:10:01 +00:00
|
|
|
**/
|
2020-01-22 13:30:55 +00:00
|
|
|
#define video_shader_parse_type(path) video_shader_get_type_from_ext(path_get_extension((path)), NULL)
|
2018-02-25 16:20:22 +00:00
|
|
|
|
|
|
|
bool video_shader_is_supported(enum rarch_shader_type type);
|
|
|
|
|
2018-02-25 22:03:39 +00:00
|
|
|
bool video_shader_any_supported(void);
|
|
|
|
|
2018-01-25 20:50:57 +00:00
|
|
|
bool video_shader_check_for_changes(void);
|
|
|
|
|
2020-12-27 02:09:27 +00:00
|
|
|
const char *video_shader_type_to_str(enum rarch_shader_type type);
|
2019-06-04 19:52:58 +00:00
|
|
|
|
2021-09-11 16:15:35 +00:00
|
|
|
void dir_free_shader(
|
|
|
|
struct rarch_dir_shader_list *dir_list,
|
|
|
|
bool shader_remember_last_dir);
|
|
|
|
|
|
|
|
void dir_init_shader(
|
|
|
|
void *menu_driver_data_,
|
|
|
|
settings_t *settings,
|
|
|
|
struct rarch_dir_shader_list *dir_list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dir_check_shader:
|
|
|
|
* @pressed_next : Was next shader key pressed?
|
|
|
|
* @pressed_prev : Was previous shader key pressed?
|
|
|
|
*
|
|
|
|
* Checks if any one of the shader keys has been pressed for this frame:
|
|
|
|
* a) Next shader index.
|
|
|
|
* b) Previous shader index.
|
|
|
|
*
|
|
|
|
* Will also immediately apply the shader.
|
|
|
|
**/
|
|
|
|
void dir_check_shader(
|
|
|
|
void *menu_driver_data_,
|
|
|
|
settings_t *settings,
|
|
|
|
struct rarch_dir_shader_list *dir_list,
|
|
|
|
bool pressed_next,
|
|
|
|
bool pressed_prev);
|
|
|
|
|
2021-09-18 20:05:03 +00:00
|
|
|
/**
|
|
|
|
* load_shader_preset:
|
|
|
|
*
|
|
|
|
* Tries to load a supported core-, game-, folder-specific or global
|
|
|
|
* shader preset from its respective location:
|
|
|
|
*
|
|
|
|
* global: $CONFIG_DIR/global.$PRESET_EXT
|
|
|
|
* core-specific: $CONFIG_DIR/$CORE_NAME/$CORE_NAME.$PRESET_EXT
|
|
|
|
* folder-specific: $CONFIG_DIR/$CORE_NAME/$FOLDER_NAME.$PRESET_EXT
|
|
|
|
* game-specific: $CONFIG_DIR/$CORE_NAME/$GAME_NAME.$PRESET_EXT
|
|
|
|
*
|
|
|
|
* $CONFIG_DIR is expected to be Menu Config directory, or failing that, the
|
|
|
|
* directory where retroarch.cfg is stored.
|
|
|
|
*
|
|
|
|
* For compatibility purposes with versions 1.8.7 and older, the presets
|
|
|
|
* subdirectory on the Video Shader path is used as a fallback directory.
|
|
|
|
*
|
|
|
|
* Note: Uses video_shader_is_supported() which only works after
|
|
|
|
* context driver initialization.
|
|
|
|
*
|
|
|
|
* Returns: false if there was an error or no action was performed.
|
|
|
|
*/
|
|
|
|
bool load_shader_preset(settings_t *settings, const char *core_name, char *s, size_t len);
|
|
|
|
|
2021-10-29 12:13:16 +00:00
|
|
|
bool apply_shader(
|
|
|
|
settings_t *settings,
|
|
|
|
enum rarch_shader_type type,
|
|
|
|
const char *preset_path, bool message);
|
|
|
|
|
2019-06-17 12:10:55 +00:00
|
|
|
const char *video_shader_get_preset_extension(enum rarch_shader_type type);
|
|
|
|
|
2016-06-03 03:43:49 +00:00
|
|
|
RETRO_END_DECLS
|
2013-04-07 00:02:41 +00:00
|
|
|
|
2013-04-06 09:30:56 +00:00
|
|
|
#endif
|