(GLSLANG) Move more common code out of shader_gl_core and shader_vulkan

and into glslang_util.h
This commit is contained in:
twinaphex 2020-08-16 02:05:38 +02:00
parent b69ceaea1b
commit bb58b0d6e3
7 changed files with 281 additions and 291 deletions

View File

@ -957,8 +957,9 @@ static bool gl_core_init_default_filter_chain(gl_core_t *gl)
return false; return false;
gl->filter_chain = gl_core_filter_chain_create_default( gl->filter_chain = gl_core_filter_chain_create_default(
gl->video_info.smooth ? gl->video_info.smooth
GL_CORE_FILTER_CHAIN_LINEAR : GL_CORE_FILTER_CHAIN_NEAREST); ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST);
if (!gl->filter_chain) if (!gl->filter_chain)
{ {
@ -973,8 +974,9 @@ static bool gl_core_init_filter_chain_preset(gl_core_t *gl, const char *shader_p
{ {
gl->filter_chain = gl_core_filter_chain_create_from_preset( gl->filter_chain = gl_core_filter_chain_create_from_preset(
shader_path, shader_path,
gl->video_info.smooth ? gl->video_info.smooth
GL_CORE_FILTER_CHAIN_LINEAR : GL_CORE_FILTER_CHAIN_NEAREST); ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST);
if (!gl->filter_chain) if (!gl->filter_chain)
{ {

View File

@ -781,8 +781,9 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
vk->filter_chain = vulkan_filter_chain_create_default( vk->filter_chain = vulkan_filter_chain_create_default(
&info, &info,
vk->video.smooth ? vk->video.smooth
VULKAN_FILTER_CHAIN_LINEAR : VULKAN_FILTER_CHAIN_NEAREST); ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST);
if (!vk->filter_chain) if (!vk->filter_chain)
{ {
@ -814,8 +815,9 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
vk->filter_chain = vulkan_filter_chain_create_from_preset( vk->filter_chain = vulkan_filter_chain_create_from_preset(
&info, shader_path, &info, shader_path,
vk->video.smooth ? vk->video.smooth
VULKAN_FILTER_CHAIN_LINEAR : VULKAN_FILTER_CHAIN_NEAREST); ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST);
if (!vk->filter_chain) if (!vk->filter_chain)
{ {

View File

@ -18,10 +18,12 @@
#include <stdint.h> #include <stdint.h>
#include <retro_common_api.h> #include <retro_common_api.h>
#include <retro_inline.h>
#include <lists/string_list.h> #include <lists/string_list.h>
#include "slang_reflection.h" #include "slang_reflection.h"
#include "../video_shader_parse.h"
typedef enum glslang_format typedef enum glslang_format
{ {
@ -66,10 +68,54 @@ typedef enum glslang_format
SLANG_FORMAT_R32G32B32A32_SFLOAT, SLANG_FORMAT_R32G32B32A32_SFLOAT,
SLANG_FORMAT_MAX SLANG_FORMAT_MAX
}glslang_format; } glslang_format;
typedef enum glslang_filter_chain_filter
{
GLSLANG_FILTER_CHAIN_LINEAR = 0,
GLSLANG_FILTER_CHAIN_NEAREST = 1,
GLSLANG_FILTER_CHAIN_COUNT
} glslang_filter_chain_filter;
typedef enum glslang_filter_chain_address
{
GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT = 0,
GLSLANG_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT = 1,
GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE = 2,
GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER = 3,
GLSLANG_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE = 4,
GLSLANG_FILTER_CHAIN_ADDRESS_COUNT
} glslang_filter_chain_address;
typedef enum glslang_filter_chain_scale
{
GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL,
GLSLANG_FILTER_CHAIN_SCALE_SOURCE,
GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT,
GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE
} glslang_filter_chain_scale;
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
static INLINE enum glslang_filter_chain_address rarch_wrap_to_address(
enum gfx_wrap_type type)
{
switch (type)
{
case RARCH_WRAP_BORDER:
return GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER;
case RARCH_WRAP_REPEAT:
return GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT;
case RARCH_WRAP_MIRRORED_REPEAT:
return GLSLANG_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT;
case RARCH_WRAP_EDGE:
default:
break;
}
return GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
}
const char *glslang_format_to_string(glslang_format fmt); const char *glslang_format_to_string(glslang_format fmt);
enum glslang_format glslang_find_format(const char *fmt); enum glslang_format glslang_find_format(const char *fmt);

View File

@ -267,48 +267,30 @@ static const uint32_t opaque_frag[] =
struct Texture struct Texture
{ {
gl_core_filter_chain_texture texture; gl_core_filter_chain_texture texture;
gl_core_filter_chain_filter filter; glslang_filter_chain_filter filter;
gl_core_filter_chain_filter mip_filter; glslang_filter_chain_filter mip_filter;
gl_core_filter_chain_address address; glslang_filter_chain_address address;
}; };
static gl_core_filter_chain_address wrap_to_address(gfx_wrap_type type) static GLenum address_to_gl(glslang_filter_chain_address type)
{
switch (type)
{
case RARCH_WRAP_BORDER:
return GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER;
case RARCH_WRAP_REPEAT:
return GL_CORE_FILTER_CHAIN_ADDRESS_REPEAT;
case RARCH_WRAP_MIRRORED_REPEAT:
return GL_CORE_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT;
case RARCH_WRAP_EDGE:
default:
break;
}
return GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
}
static GLenum address_to_gl(gl_core_filter_chain_address type)
{ {
switch (type) switch (type)
{ {
#ifdef HAVE_OPENGLES3 #ifdef HAVE_OPENGLES3
case GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER: case GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER:
#if 0 #if 0
RARCH_WARN("[GLCore]: No CLAMP_TO_BORDER in GLES3. Falling back to edge clamp.\n"); RARCH_WARN("[GLCore]: No CLAMP_TO_BORDER in GLES3. Falling back to edge clamp.\n");
#endif #endif
return GL_CLAMP_TO_EDGE; return GL_CLAMP_TO_EDGE;
#else #else
case GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER: case GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER:
return GL_CLAMP_TO_BORDER; return GL_CLAMP_TO_BORDER;
#endif #endif
case GL_CORE_FILTER_CHAIN_ADDRESS_REPEAT: case GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT:
return GL_REPEAT; return GL_REPEAT;
case GL_CORE_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT: case GLSLANG_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT:
return GL_MIRRORED_REPEAT; return GL_MIRRORED_REPEAT;
case GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE: case GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE:
default: default:
break; break;
} }
@ -316,13 +298,13 @@ static GLenum address_to_gl(gl_core_filter_chain_address type)
return GL_CLAMP_TO_EDGE; return GL_CLAMP_TO_EDGE;
} }
static GLenum convert_filter_to_mag_gl(gl_core_filter_chain_filter filter) static GLenum convert_filter_to_mag_gl(glslang_filter_chain_filter filter)
{ {
switch (filter) switch (filter)
{ {
case GL_CORE_FILTER_CHAIN_LINEAR: case GLSLANG_FILTER_CHAIN_LINEAR:
return GL_LINEAR; return GL_LINEAR;
case GL_CORE_FILTER_CHAIN_NEAREST: case GLSLANG_FILTER_CHAIN_NEAREST:
default: default:
break; break;
} }
@ -330,13 +312,15 @@ static GLenum convert_filter_to_mag_gl(gl_core_filter_chain_filter filter)
return GL_NEAREST; return GL_NEAREST;
} }
static GLenum convert_filter_to_min_gl(gl_core_filter_chain_filter filter, gl_core_filter_chain_filter mipfilter) static GLenum convert_filter_to_min_gl(glslang_filter_chain_filter filter, glslang_filter_chain_filter mipfilter)
{ {
if (filter == GL_CORE_FILTER_CHAIN_LINEAR && mipfilter == GL_CORE_FILTER_CHAIN_LINEAR) if ( (filter == GLSLANG_FILTER_CHAIN_LINEAR)
&& (mipfilter == GLSLANG_FILTER_CHAIN_LINEAR)
)
return GL_LINEAR_MIPMAP_LINEAR; return GL_LINEAR_MIPMAP_LINEAR;
else if (filter == GL_CORE_FILTER_CHAIN_LINEAR) else if (filter == GLSLANG_FILTER_CHAIN_LINEAR)
return GL_LINEAR_MIPMAP_NEAREST; return GL_LINEAR_MIPMAP_NEAREST;
else if (mipfilter == GL_CORE_FILTER_CHAIN_LINEAR) else if (mipfilter == GLSLANG_FILTER_CHAIN_LINEAR)
return GL_NEAREST_MIPMAP_LINEAR; return GL_NEAREST_MIPMAP_LINEAR;
return GL_NEAREST_MIPMAP_NEAREST; return GL_NEAREST_MIPMAP_NEAREST;
} }
@ -394,7 +378,7 @@ public:
unsigned width, unsigned height, unsigned width, unsigned height,
bool linear, bool linear,
bool mipmap, bool mipmap,
gl_core_filter_chain_address address); glslang_filter_chain_address address);
~StaticTexture(); ~StaticTexture();
StaticTexture(StaticTexture&&) = delete; StaticTexture(StaticTexture&&) = delete;
@ -412,13 +396,13 @@ private:
StaticTexture::StaticTexture(string id_, GLuint image_, StaticTexture::StaticTexture(string id_, GLuint image_,
unsigned width, unsigned height, bool linear, bool mipmap, unsigned width, unsigned height, bool linear, bool mipmap,
gl_core_filter_chain_address address) glslang_filter_chain_address address)
: id(std::move(id_)), image(image_) : id(std::move(id_)), image(image_)
{ {
GLenum gl_address = address_to_gl(address); GLenum gl_address = address_to_gl(address);
texture.filter = GL_CORE_FILTER_CHAIN_NEAREST; texture.filter = GLSLANG_FILTER_CHAIN_NEAREST;
texture.mip_filter = GL_CORE_FILTER_CHAIN_NEAREST; texture.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
texture.address = address; texture.address = address;
texture.texture.width = width; texture.texture.width = width;
texture.texture.height = height; texture.texture.height = height;
@ -426,9 +410,9 @@ StaticTexture::StaticTexture(string id_, GLuint image_,
texture.texture.image = image; texture.texture.image = image;
if (linear) if (linear)
texture.filter = GL_CORE_FILTER_CHAIN_LINEAR; texture.filter = GLSLANG_FILTER_CHAIN_LINEAR;
if (mipmap && linear) if (mipmap && linear)
texture.mip_filter = GL_CORE_FILTER_CHAIN_LINEAR; texture.mip_filter = GLSLANG_FILTER_CHAIN_LINEAR;
glBindTexture(GL_TEXTURE_2D, image); glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl_address); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl_address);
@ -713,17 +697,17 @@ public:
return pass_name; return pass_name;
} }
gl_core_filter_chain_filter get_source_filter() const glslang_filter_chain_filter get_source_filter() const
{ {
return pass_info.source_filter; return pass_info.source_filter;
} }
gl_core_filter_chain_filter get_mip_filter() const glslang_filter_chain_filter get_mip_filter() const
{ {
return pass_info.mip_filter; return pass_info.mip_filter;
} }
gl_core_filter_chain_address get_address_mode() const glslang_filter_chain_address get_address_mode() const
{ {
return pass_info.address; return pass_info.address;
} }
@ -1021,19 +1005,19 @@ Size2D Pass::get_output_size(const Size2D &original, const Size2D &source) const
float width, height; float width, height;
switch (pass_info.scale_type_x) switch (pass_info.scale_type_x)
{ {
case GL_CORE_FILTER_CHAIN_SCALE_ORIGINAL: case GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL:
width = float(original.width) * pass_info.scale_x; width = float(original.width) * pass_info.scale_x;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_SOURCE: case GLSLANG_FILTER_CHAIN_SCALE_SOURCE:
width = float(source.width) * pass_info.scale_x; width = float(source.width) * pass_info.scale_x;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT: case GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT:
width = current_viewport.width * pass_info.scale_x; width = current_viewport.width * pass_info.scale_x;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_ABSOLUTE: case GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE:
width = pass_info.scale_x; width = pass_info.scale_x;
break; break;
@ -1043,19 +1027,19 @@ Size2D Pass::get_output_size(const Size2D &original, const Size2D &source) const
switch (pass_info.scale_type_y) switch (pass_info.scale_type_y)
{ {
case GL_CORE_FILTER_CHAIN_SCALE_ORIGINAL: case GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL:
height = float(original.height) * pass_info.scale_y; height = float(original.height) * pass_info.scale_y;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_SOURCE: case GLSLANG_FILTER_CHAIN_SCALE_SOURCE:
height = float(source.height) * pass_info.scale_y; height = float(source.height) * pass_info.scale_y;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT: case GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT:
height = current_viewport.height * pass_info.scale_y; height = current_viewport.height * pass_info.scale_y;
break; break;
case GL_CORE_FILTER_CHAIN_SCALE_ABSOLUTE: case GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE:
height = pass_info.scale_y; height = pass_info.scale_y;
break; break;
@ -2099,7 +2083,7 @@ static unique_ptr<gl_core_shader::StaticTexture> gl_core_filter_chain_load_lut(
tex, image.width, image.height, tex, image.width, image.height,
shader->filter != RARCH_FILTER_NEAREST, shader->filter != RARCH_FILTER_NEAREST,
levels > 1, levels > 1,
gl_core_shader::wrap_to_address(shader->wrap))); rarch_wrap_to_address(shader->wrap)));
} }
static bool gl_core_filter_chain_load_luts( static bool gl_core_filter_chain_load_luts(
@ -2123,7 +2107,7 @@ static bool gl_core_filter_chain_load_luts(
} }
gl_core_filter_chain_t *gl_core_filter_chain_create_default( gl_core_filter_chain_t *gl_core_filter_chain_create_default(
gl_core_filter_chain_filter filter) glslang_filter_chain_filter filter)
{ {
struct gl_core_filter_chain_pass_info pass_info; struct gl_core_filter_chain_pass_info pass_info;
@ -2131,14 +2115,14 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_default(
if (!chain) if (!chain)
return nullptr; return nullptr;
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
pass_info.rt_format = 0; pass_info.rt_format = 0;
pass_info.source_filter = filter; pass_info.source_filter = filter;
pass_info.mip_filter = GL_CORE_FILTER_CHAIN_NEAREST; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
pass_info.address = GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
pass_info.max_levels = 0; pass_info.max_levels = 0;
chain->set_pass_info(0, pass_info); chain->set_pass_info(0, pass_info);
@ -2157,7 +2141,7 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_default(
} }
gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset( gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
const char *path, gl_core_filter_chain_filter filter) const char *path, glslang_filter_chain_filter filter)
{ {
unsigned i; unsigned i;
config_file_t *conf = NULL; config_file_t *conf = NULL;
@ -2193,14 +2177,14 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
const video_shader_pass *next_pass = const video_shader_pass *next_pass =
i + 1 < shader->passes ? &shader->pass[i + 1] : nullptr; i + 1 < shader->passes ? &shader->pass[i + 1] : nullptr;
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_ORIGINAL; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL;
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_ORIGINAL; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL;
pass_info.scale_x = 0.0f; pass_info.scale_x = 0.0f;
pass_info.scale_y = 0.0f; pass_info.scale_y = 0.0f;
pass_info.rt_format = 0; pass_info.rt_format = 0;
pass_info.source_filter = GL_CORE_FILTER_CHAIN_LINEAR; pass_info.source_filter = GLSLANG_FILTER_CHAIN_LINEAR;
pass_info.mip_filter = GL_CORE_FILTER_CHAIN_LINEAR; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_LINEAR;
pass_info.address = GL_CORE_FILTER_CHAIN_ADDRESS_REPEAT; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT;
pass_info.max_levels = 0; pass_info.max_levels = 0;
if (!glslang_compile_shader(pass->source.path, &output)) if (!glslang_compile_shader(pass->source.path, &output))
@ -2279,10 +2263,11 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
else else
{ {
pass_info.source_filter = pass_info.source_filter =
pass->filter == RARCH_FILTER_LINEAR ? GL_CORE_FILTER_CHAIN_LINEAR : pass->filter == RARCH_FILTER_LINEAR
GL_CORE_FILTER_CHAIN_NEAREST; ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
} }
pass_info.address = gl_core_shader::wrap_to_address(pass->wrap); pass_info.address = rarch_wrap_to_address(pass->wrap);
pass_info.max_levels = 1; pass_info.max_levels = 1;
/* TODO: Expose max_levels in slangp. /* TODO: Expose max_levels in slangp.
@ -2293,7 +2278,8 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
pass_info.max_levels = ~0u; pass_info.max_levels = ~0u;
pass_info.mip_filter = pass->filter != RARCH_FILTER_NEAREST && pass_info.max_levels > 1 pass_info.mip_filter = pass->filter != RARCH_FILTER_NEAREST && pass_info.max_levels > 1
? GL_CORE_FILTER_CHAIN_LINEAR : GL_CORE_FILTER_CHAIN_NEAREST; ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
bool explicit_format = output.meta.rt_format != SLANG_FORMAT_UNKNOWN; bool explicit_format = output.meta.rt_format != SLANG_FORMAT_UNKNOWN;
@ -2304,11 +2290,11 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
if (!pass->fbo.valid) if (!pass->fbo.valid)
{ {
pass_info.scale_type_x = i + 1 == shader->passes pass_info.scale_type_x = i + 1 == shader->passes
? GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT ? GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT
: GL_CORE_FILTER_CHAIN_SCALE_SOURCE; : GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
pass_info.scale_type_y = i + 1 == shader->passes pass_info.scale_type_y = i + 1 == shader->passes
? GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT ? GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT
: GL_CORE_FILTER_CHAIN_SCALE_SOURCE; : GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
@ -2344,17 +2330,17 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
{ {
case RARCH_SCALE_INPUT: case RARCH_SCALE_INPUT:
pass_info.scale_x = pass->fbo.scale_x; pass_info.scale_x = pass->fbo.scale_x;
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
break; break;
case RARCH_SCALE_ABSOLUTE: case RARCH_SCALE_ABSOLUTE:
pass_info.scale_x = float(pass->fbo.abs_x); pass_info.scale_x = float(pass->fbo.abs_x);
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_ABSOLUTE; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE;
break; break;
case RARCH_SCALE_VIEWPORT: case RARCH_SCALE_VIEWPORT:
pass_info.scale_x = pass->fbo.scale_x; pass_info.scale_x = pass->fbo.scale_x;
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
break; break;
} }
@ -2362,17 +2348,17 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
{ {
case RARCH_SCALE_INPUT: case RARCH_SCALE_INPUT:
pass_info.scale_y = pass->fbo.scale_y; pass_info.scale_y = pass->fbo.scale_y;
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
break; break;
case RARCH_SCALE_ABSOLUTE: case RARCH_SCALE_ABSOLUTE:
pass_info.scale_y = float(pass->fbo.abs_y); pass_info.scale_y = float(pass->fbo.abs_y);
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_ABSOLUTE; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE;
break; break;
case RARCH_SCALE_VIEWPORT: case RARCH_SCALE_VIEWPORT:
pass_info.scale_y = pass->fbo.scale_y; pass_info.scale_y = pass->fbo.scale_y;
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
break; break;
} }
} }
@ -2384,16 +2370,16 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
{ {
struct gl_core_filter_chain_pass_info pass_info; struct gl_core_filter_chain_pass_info pass_info;
pass_info.scale_type_x = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_type_y = GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
pass_info.rt_format = 0; pass_info.rt_format = 0;
pass_info.source_filter = filter; pass_info.source_filter = filter;
pass_info.mip_filter = GL_CORE_FILTER_CHAIN_NEAREST; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
pass_info.address = GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
pass_info.max_levels = 0; pass_info.max_levels = 0;

View File

@ -23,27 +23,12 @@
#include <retro_common_api.h> #include <retro_common_api.h>
#include <glsym/glsym.h> #include <glsym/glsym.h>
#include "glslang_util.h"
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
typedef struct gl_core_filter_chain gl_core_filter_chain_t; typedef struct gl_core_filter_chain gl_core_filter_chain_t;
enum gl_core_filter_chain_filter
{
GL_CORE_FILTER_CHAIN_LINEAR = 0,
GL_CORE_FILTER_CHAIN_NEAREST = 1,
GL_CORE_FILTER_CHAIN_COUNT
};
enum gl_core_filter_chain_address
{
GL_CORE_FILTER_CHAIN_ADDRESS_REPEAT = 0,
GL_CORE_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT = 1,
GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE = 2,
GL_CORE_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER = 3,
GL_CORE_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE = 4,
GL_CORE_FILTER_CHAIN_ADDRESS_COUNT
};
struct gl_core_filter_chain_texture struct gl_core_filter_chain_texture
{ {
GLuint image; GLuint image;
@ -62,85 +47,28 @@ struct gl_core_viewport
GLsizei height; GLsizei height;
}; };
enum gl_core_filter_chain_scale
{
GL_CORE_FILTER_CHAIN_SCALE_ORIGINAL,
GL_CORE_FILTER_CHAIN_SCALE_SOURCE,
GL_CORE_FILTER_CHAIN_SCALE_VIEWPORT,
GL_CORE_FILTER_CHAIN_SCALE_ABSOLUTE
};
struct gl_core_filter_chain_pass_info struct gl_core_filter_chain_pass_info
{ {
/* For the last pass, make sure VIEWPORT scale /* For the last pass, make sure VIEWPORT scale
* with scale factors of 1 are used. */ * with scale factors of 1 are used. */
enum gl_core_filter_chain_scale scale_type_x; enum glslang_filter_chain_scale scale_type_x;
enum gl_core_filter_chain_scale scale_type_y; enum glslang_filter_chain_scale scale_type_y;
float scale_x; float scale_x;
float scale_y; float scale_y;
/* Ignored for the last pass, swapchain info will be used instead. */ /* Ignored for the last pass, swapchain info
* will be used instead. */
GLenum rt_format; GLenum rt_format;
/* The filter to use for source in this pass. */ /* The filter to use for source in this pass. */
enum gl_core_filter_chain_filter source_filter; enum glslang_filter_chain_filter source_filter;
enum gl_core_filter_chain_filter mip_filter; enum glslang_filter_chain_filter mip_filter;
enum gl_core_filter_chain_address address; enum glslang_filter_chain_address address;
/* Maximum number of mip-levels to use. */ /* Maximum number of mip-levels to use. */
unsigned max_levels; unsigned max_levels;
}; };
gl_core_filter_chain_t *gl_core_filter_chain_new(void);
void gl_core_filter_chain_free(gl_core_filter_chain_t *chain);
void gl_core_filter_chain_set_shader(gl_core_filter_chain_t *chain,
unsigned pass,
GLenum shader_type,
const uint32_t *spirv,
size_t spirv_words);
void gl_core_filter_chain_set_pass_info(gl_core_filter_chain_t *chain,
unsigned pass,
const struct gl_core_filter_chain_pass_info *info);
bool gl_core_filter_chain_init(gl_core_filter_chain_t *chain);
void gl_core_filter_chain_set_input_texture(
gl_core_filter_chain_t *chain,
const struct gl_core_filter_chain_texture *texture);
void gl_core_filter_chain_set_frame_count(gl_core_filter_chain_t *chain,
uint64_t count);
void gl_core_filter_chain_set_frame_count_period(gl_core_filter_chain_t *chain,
unsigned pass,
unsigned period);
void gl_core_filter_chain_set_frame_direction(gl_core_filter_chain_t *chain,
int32_t direction);
void gl_core_filter_chain_set_pass_name(gl_core_filter_chain_t *chain,
unsigned pass,
const char *name);
void gl_core_filter_chain_build_offscreen_passes(gl_core_filter_chain_t *chain,
const struct gl_core_viewport *vp);
void gl_core_filter_chain_build_viewport_pass(gl_core_filter_chain_t *chain,
const struct gl_core_viewport *vp,
const float *mvp);
gl_core_filter_chain_t *gl_core_filter_chain_create_default(
enum gl_core_filter_chain_filter filter);
gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
const char *path, enum gl_core_filter_chain_filter filter);
struct video_shader *gl_core_filter_chain_get_preset(
gl_core_filter_chain_t *chain);
void gl_core_filter_chain_end_frame(gl_core_filter_chain_t *chain);
struct gl_core_buffer_locations struct gl_core_buffer_locations
{ {
GLint flat_ubo_vertex; GLint flat_ubo_vertex;
@ -151,9 +79,75 @@ struct gl_core_buffer_locations
GLuint buffer_index_ubo_fragment; GLuint buffer_index_ubo_fragment;
}; };
GLuint gl_core_cross_compile_program(const uint32_t *vertex, size_t vertex_size, gl_core_filter_chain_t *gl_core_filter_chain_new(void);
const uint32_t *fragment, size_t fragment_size,
struct gl_core_buffer_locations *loc, bool flatten); void gl_core_filter_chain_free(
gl_core_filter_chain_t *chain);
void gl_core_filter_chain_set_shader(
gl_core_filter_chain_t *chain,
unsigned pass,
GLenum shader_type,
const uint32_t *spirv,
size_t spirv_words);
void gl_core_filter_chain_set_pass_info(
gl_core_filter_chain_t *chain,
unsigned pass,
const struct gl_core_filter_chain_pass_info *info);
bool gl_core_filter_chain_init(gl_core_filter_chain_t *chain);
void gl_core_filter_chain_set_input_texture(
gl_core_filter_chain_t *chain,
const struct gl_core_filter_chain_texture *texture);
void gl_core_filter_chain_set_frame_count(
gl_core_filter_chain_t *chain,
uint64_t count);
void gl_core_filter_chain_set_frame_count_period(
gl_core_filter_chain_t *chain,
unsigned pass,
unsigned period);
void gl_core_filter_chain_set_frame_direction(
gl_core_filter_chain_t *chain,
int32_t direction);
void gl_core_filter_chain_set_pass_name(
gl_core_filter_chain_t *chain,
unsigned pass,
const char *name);
void gl_core_filter_chain_build_offscreen_passes(
gl_core_filter_chain_t *chain,
const struct gl_core_viewport *vp);
void gl_core_filter_chain_build_viewport_pass(
gl_core_filter_chain_t *chain,
const struct gl_core_viewport *vp,
const float *mvp);
gl_core_filter_chain_t *gl_core_filter_chain_create_default(
enum glslang_filter_chain_filter filter);
gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
const char *path,
enum glslang_filter_chain_filter filter);
struct video_shader *gl_core_filter_chain_get_preset(
gl_core_filter_chain_t *chain);
void gl_core_filter_chain_end_frame(gl_core_filter_chain_t *chain);
GLuint gl_core_cross_compile_program(
const uint32_t *vertex,
size_t vertex_size,
const uint32_t *fragment,
size_t fragment_size,
struct gl_core_buffer_locations *loc,
bool flatten);
RETRO_END_DECLS RETRO_END_DECLS

View File

@ -48,9 +48,9 @@ static const uint32_t opaque_frag[] =
struct Texture struct Texture
{ {
vulkan_filter_chain_texture texture; vulkan_filter_chain_texture texture;
vulkan_filter_chain_filter filter; glslang_filter_chain_filter filter;
vulkan_filter_chain_filter mip_filter; glslang_filter_chain_filter mip_filter;
vulkan_filter_chain_address address; glslang_filter_chain_address address;
}; };
class DeferredDisposer class DeferredDisposer
@ -104,7 +104,7 @@ class StaticTexture
unsigned width, unsigned height, unsigned width, unsigned height,
bool linear, bool linear,
bool mipmap, bool mipmap,
vulkan_filter_chain_address address); glslang_filter_chain_address address);
~StaticTexture(); ~StaticTexture();
StaticTexture(StaticTexture&&) = delete; StaticTexture(StaticTexture&&) = delete;
@ -184,7 +184,7 @@ struct CommonResources
size_t ubo_offset = 0; size_t ubo_offset = 0;
size_t ubo_alignment = 1; size_t ubo_alignment = 1;
VkSampler samplers[VULKAN_FILTER_CHAIN_COUNT][VULKAN_FILTER_CHAIN_COUNT][VULKAN_FILTER_CHAIN_ADDRESS_COUNT]; VkSampler samplers[GLSLANG_FILTER_CHAIN_COUNT][GLSLANG_FILTER_CHAIN_COUNT][GLSLANG_FILTER_CHAIN_ADDRESS_COUNT];
vector<Texture> original_history; vector<Texture> original_history;
vector<Texture> fb_feedback; vector<Texture> fb_feedback;
@ -246,15 +246,15 @@ class Pass
void set_frame_direction(int32_t dir) { frame_direction = dir; } void set_frame_direction(int32_t dir) { frame_direction = dir; }
void set_name(const char *name) { pass_name = name; } void set_name(const char *name) { pass_name = name; }
const string &get_name() const { return pass_name; } const string &get_name() const { return pass_name; }
vulkan_filter_chain_filter get_source_filter() const { glslang_filter_chain_filter get_source_filter() const {
return pass_info.source_filter; } return pass_info.source_filter; }
vulkan_filter_chain_filter get_mip_filter() const glslang_filter_chain_filter get_mip_filter() const
{ {
return pass_info.mip_filter; return pass_info.mip_filter;
} }
vulkan_filter_chain_address get_address_mode() const glslang_filter_chain_address get_address_mode() const
{ {
return pass_info.address; return pass_info.address;
} }
@ -685,7 +685,7 @@ static unique_ptr<StaticTexture> vulkan_filter_chain_load_lut(
tex, view, memory, move(buffer), image.width, image.height, tex, view, memory, move(buffer), image.width, image.height,
shader->filter != RARCH_FILTER_NEAREST, shader->filter != RARCH_FILTER_NEAREST,
image_info.mipLevels > 1, image_info.mipLevels > 1,
vk_wrap_to_address(shader->wrap))); rarch_wrap_to_address(shader->wrap)));
error: error:
if (image.pixels) if (image.pixels)
@ -1344,7 +1344,7 @@ StaticTexture::StaticTexture(string id,
unsigned width, unsigned height, unsigned width, unsigned height,
bool linear, bool linear,
bool mipmap, bool mipmap,
vulkan_filter_chain_address address) glslang_filter_chain_address address)
: device(device), : device(device),
image(image), image(image),
view(view), view(view),
@ -1352,8 +1352,8 @@ StaticTexture::StaticTexture(string id,
buffer(move(buffer)), buffer(move(buffer)),
id(move(id)) id(move(id))
{ {
texture.filter = VULKAN_FILTER_CHAIN_NEAREST; texture.filter = GLSLANG_FILTER_CHAIN_NEAREST;
texture.mip_filter = VULKAN_FILTER_CHAIN_NEAREST; texture.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
texture.address = address; texture.address = address;
texture.texture.image = image; texture.texture.image = image;
texture.texture.view = view; texture.texture.view = view;
@ -1362,9 +1362,9 @@ StaticTexture::StaticTexture(string id,
texture.texture.height = height; texture.texture.height = height;
if (linear) if (linear)
texture.filter = VULKAN_FILTER_CHAIN_LINEAR; texture.filter = GLSLANG_FILTER_CHAIN_LINEAR;
if (mipmap && linear) if (mipmap && linear)
texture.mip_filter = VULKAN_FILTER_CHAIN_LINEAR; texture.mip_filter = GLSLANG_FILTER_CHAIN_LINEAR;
} }
StaticTexture::~StaticTexture() StaticTexture::~StaticTexture()
@ -1467,19 +1467,19 @@ Size2D Pass::get_output_size(const Size2D &original,
float width, height; float width, height;
switch (pass_info.scale_type_x) switch (pass_info.scale_type_x)
{ {
case VULKAN_FILTER_CHAIN_SCALE_ORIGINAL: case GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL:
width = float(original.width) * pass_info.scale_x; width = float(original.width) * pass_info.scale_x;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_SOURCE: case GLSLANG_FILTER_CHAIN_SCALE_SOURCE:
width = float(source.width) * pass_info.scale_x; width = float(source.width) * pass_info.scale_x;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_VIEWPORT: case GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT:
width = current_viewport.width * pass_info.scale_x; width = current_viewport.width * pass_info.scale_x;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_ABSOLUTE: case GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE:
width = pass_info.scale_x; width = pass_info.scale_x;
break; break;
@ -1489,19 +1489,19 @@ Size2D Pass::get_output_size(const Size2D &original,
switch (pass_info.scale_type_y) switch (pass_info.scale_type_y)
{ {
case VULKAN_FILTER_CHAIN_SCALE_ORIGINAL: case GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL:
height = float(original.height) * pass_info.scale_y; height = float(original.height) * pass_info.scale_y;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_SOURCE: case GLSLANG_FILTER_CHAIN_SCALE_SOURCE:
height = float(source.height) * pass_info.scale_y; height = float(source.height) * pass_info.scale_y;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_VIEWPORT: case GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT:
height = current_viewport.height * pass_info.scale_y; height = current_viewport.height * pass_info.scale_y;
break; break;
case VULKAN_FILTER_CHAIN_SCALE_ABSOLUTE: case GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE:
height = pass_info.scale_y; height = pass_info.scale_y;
break; break;
@ -1824,18 +1824,18 @@ CommonResources::CommonResources(VkDevice device,
info.unnormalizedCoordinates = false; info.unnormalizedCoordinates = false;
info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
for (i = 0; i < VULKAN_FILTER_CHAIN_COUNT; i++) for (i = 0; i < GLSLANG_FILTER_CHAIN_COUNT; i++)
{ {
unsigned j; unsigned j;
switch (static_cast<vulkan_filter_chain_filter>(i)) switch (static_cast<glslang_filter_chain_filter>(i))
{ {
case VULKAN_FILTER_CHAIN_LINEAR: case GLSLANG_FILTER_CHAIN_LINEAR:
info.magFilter = VK_FILTER_LINEAR; info.magFilter = VK_FILTER_LINEAR;
info.minFilter = VK_FILTER_LINEAR; info.minFilter = VK_FILTER_LINEAR;
break; break;
case VULKAN_FILTER_CHAIN_NEAREST: case GLSLANG_FILTER_CHAIN_NEAREST:
info.magFilter = VK_FILTER_NEAREST; info.magFilter = VK_FILTER_NEAREST;
info.minFilter = VK_FILTER_NEAREST; info.minFilter = VK_FILTER_NEAREST;
break; break;
@ -1844,17 +1844,17 @@ CommonResources::CommonResources(VkDevice device,
break; break;
} }
for (j = 0; j < VULKAN_FILTER_CHAIN_COUNT; j++) for (j = 0; j < GLSLANG_FILTER_CHAIN_COUNT; j++)
{ {
unsigned k; unsigned k;
switch (static_cast<vulkan_filter_chain_filter>(j)) switch (static_cast<glslang_filter_chain_filter>(j))
{ {
case VULKAN_FILTER_CHAIN_LINEAR: case GLSLANG_FILTER_CHAIN_LINEAR:
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
break; break;
case VULKAN_FILTER_CHAIN_NEAREST: case GLSLANG_FILTER_CHAIN_NEAREST:
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
break; break;
@ -1862,29 +1862,29 @@ CommonResources::CommonResources(VkDevice device,
break; break;
} }
for (k = 0; k < VULKAN_FILTER_CHAIN_ADDRESS_COUNT; k++) for (k = 0; k < GLSLANG_FILTER_CHAIN_ADDRESS_COUNT; k++)
{ {
VkSamplerAddressMode mode = VK_SAMPLER_ADDRESS_MODE_MAX_ENUM; VkSamplerAddressMode mode = VK_SAMPLER_ADDRESS_MODE_MAX_ENUM;
switch (static_cast<vulkan_filter_chain_address>(k)) switch (static_cast<glslang_filter_chain_address>(k))
{ {
case VULKAN_FILTER_CHAIN_ADDRESS_REPEAT: case GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT:
mode = VK_SAMPLER_ADDRESS_MODE_REPEAT; mode = VK_SAMPLER_ADDRESS_MODE_REPEAT;
break; break;
case VULKAN_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT: case GLSLANG_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT:
mode = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; mode = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
break; break;
case VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE: case GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE:
mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
break; break;
case VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER: case GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER:
mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
break; break;
case VULKAN_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE: case GLSLANG_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE:
mode = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; mode = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
break; break;
@ -2512,7 +2512,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_new(
vulkan_filter_chain_t *vulkan_filter_chain_create_default( vulkan_filter_chain_t *vulkan_filter_chain_create_default(
const struct vulkan_filter_chain_create_info *info, const struct vulkan_filter_chain_create_info *info,
vulkan_filter_chain_filter filter) glslang_filter_chain_filter filter)
{ {
struct vulkan_filter_chain_pass_info pass_info; struct vulkan_filter_chain_pass_info pass_info;
auto tmpinfo = *info; auto tmpinfo = *info;
@ -2523,14 +2523,14 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_default(
if (!chain) if (!chain)
return nullptr; return nullptr;
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
pass_info.rt_format = tmpinfo.swapchain.format; pass_info.rt_format = tmpinfo.swapchain.format;
pass_info.source_filter = filter; pass_info.source_filter = filter;
pass_info.mip_filter = VULKAN_FILTER_CHAIN_NEAREST; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
pass_info.address = VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
pass_info.max_levels = 0; pass_info.max_levels = 0;
chain->set_pass_info(0, pass_info); chain->set_pass_info(0, pass_info);
@ -2550,7 +2550,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_default(
vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset( vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
const struct vulkan_filter_chain_create_info *info, const struct vulkan_filter_chain_create_info *info,
const char *path, vulkan_filter_chain_filter filter) const char *path, glslang_filter_chain_filter filter)
{ {
unsigned i; unsigned i;
config_file_t *conf = NULL; config_file_t *conf = NULL;
@ -2588,14 +2588,14 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
const video_shader_pass *next_pass = const video_shader_pass *next_pass =
i + 1 < shader->passes ? &shader->pass[i + 1] : nullptr; i + 1 < shader->passes ? &shader->pass[i + 1] : nullptr;
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_ORIGINAL; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_ORIGINAL; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_ORIGINAL;
pass_info.scale_x = 0.0f; pass_info.scale_x = 0.0f;
pass_info.scale_y = 0.0f; pass_info.scale_y = 0.0f;
pass_info.rt_format = VK_FORMAT_UNDEFINED; pass_info.rt_format = VK_FORMAT_UNDEFINED;
pass_info.source_filter = VULKAN_FILTER_CHAIN_LINEAR; pass_info.source_filter = GLSLANG_FILTER_CHAIN_LINEAR;
pass_info.mip_filter = VULKAN_FILTER_CHAIN_LINEAR; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_LINEAR;
pass_info.address = VULKAN_FILTER_CHAIN_ADDRESS_REPEAT; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_REPEAT;
pass_info.max_levels = 0; pass_info.max_levels = 0;
if (!glslang_compile_shader(pass->source.path, &output)) if (!glslang_compile_shader(pass->source.path, &output))
@ -2674,10 +2674,11 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
else else
{ {
pass_info.source_filter = pass_info.source_filter =
pass->filter == RARCH_FILTER_LINEAR ? VULKAN_FILTER_CHAIN_LINEAR : pass->filter == RARCH_FILTER_LINEAR
VULKAN_FILTER_CHAIN_NEAREST; ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
} }
pass_info.address = vk_wrap_to_address(pass->wrap); pass_info.address = rarch_wrap_to_address(pass->wrap);
pass_info.max_levels = 1; pass_info.max_levels = 1;
/* TODO: Expose max_levels in slangp. /* TODO: Expose max_levels in slangp.
@ -2688,7 +2689,8 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
pass_info.max_levels = ~0u; pass_info.max_levels = ~0u;
pass_info.mip_filter = pass->filter != RARCH_FILTER_NEAREST && pass_info.max_levels > 1 pass_info.mip_filter = pass->filter != RARCH_FILTER_NEAREST && pass_info.max_levels > 1
? VULKAN_FILTER_CHAIN_LINEAR : VULKAN_FILTER_CHAIN_NEAREST; ? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
bool explicit_format = output.meta.rt_format != SLANG_FORMAT_UNKNOWN; bool explicit_format = output.meta.rt_format != SLANG_FORMAT_UNKNOWN;
@ -2698,15 +2700,15 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
if (!pass->fbo.valid) if (!pass->fbo.valid)
{ {
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
if (i + 1 == shader->passes) if (i + 1 == shader->passes)
{ {
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.rt_format = tmpinfo.swapchain.format; pass_info.rt_format = tmpinfo.swapchain.format;
if (explicit_format) if (explicit_format)
@ -2739,17 +2741,17 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
{ {
case RARCH_SCALE_INPUT: case RARCH_SCALE_INPUT:
pass_info.scale_x = pass->fbo.scale_x; pass_info.scale_x = pass->fbo.scale_x;
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
break; break;
case RARCH_SCALE_ABSOLUTE: case RARCH_SCALE_ABSOLUTE:
pass_info.scale_x = float(pass->fbo.abs_x); pass_info.scale_x = float(pass->fbo.abs_x);
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_ABSOLUTE; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE;
break; break;
case RARCH_SCALE_VIEWPORT: case RARCH_SCALE_VIEWPORT:
pass_info.scale_x = pass->fbo.scale_x; pass_info.scale_x = pass->fbo.scale_x;
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
break; break;
} }
@ -2757,17 +2759,17 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
{ {
case RARCH_SCALE_INPUT: case RARCH_SCALE_INPUT:
pass_info.scale_y = pass->fbo.scale_y; pass_info.scale_y = pass->fbo.scale_y;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_SOURCE; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_SOURCE;
break; break;
case RARCH_SCALE_ABSOLUTE: case RARCH_SCALE_ABSOLUTE:
pass_info.scale_y = float(pass->fbo.abs_y); pass_info.scale_y = float(pass->fbo.abs_y);
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_ABSOLUTE; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_ABSOLUTE;
break; break;
case RARCH_SCALE_VIEWPORT: case RARCH_SCALE_VIEWPORT:
pass_info.scale_y = pass->fbo.scale_y; pass_info.scale_y = pass->fbo.scale_y;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
break; break;
} }
} }
@ -2779,16 +2781,16 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
{ {
struct vulkan_filter_chain_pass_info pass_info; struct vulkan_filter_chain_pass_info pass_info;
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_x = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT; pass_info.scale_type_y = GLSLANG_FILTER_CHAIN_SCALE_VIEWPORT;
pass_info.scale_x = 1.0f; pass_info.scale_x = 1.0f;
pass_info.scale_y = 1.0f; pass_info.scale_y = 1.0f;
pass_info.rt_format = tmpinfo.swapchain.format; pass_info.rt_format = tmpinfo.swapchain.format;
pass_info.source_filter = filter; pass_info.source_filter = filter;
pass_info.mip_filter = VULKAN_FILTER_CHAIN_NEAREST; pass_info.mip_filter = GLSLANG_FILTER_CHAIN_NEAREST;
pass_info.address = VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE; pass_info.address = GLSLANG_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
pass_info.max_levels = 0; pass_info.max_levels = 0;

View File

@ -23,29 +23,14 @@
#include <boolean.h> #include <boolean.h>
#include <retro_common_api.h> #include <retro_common_api.h>
#include "glslang_util.h"
#include "../common/vulkan_common.h" #include "../common/vulkan_common.h"
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
typedef struct vulkan_filter_chain vulkan_filter_chain_t; typedef struct vulkan_filter_chain vulkan_filter_chain_t;
enum vulkan_filter_chain_filter
{
VULKAN_FILTER_CHAIN_LINEAR = 0,
VULKAN_FILTER_CHAIN_NEAREST = 1,
VULKAN_FILTER_CHAIN_COUNT
};
enum vulkan_filter_chain_address
{
VULKAN_FILTER_CHAIN_ADDRESS_REPEAT = 0,
VULKAN_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT = 1,
VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE = 2,
VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER = 3,
VULKAN_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE = 4,
VULKAN_FILTER_CHAIN_ADDRESS_COUNT
};
struct vulkan_filter_chain_texture struct vulkan_filter_chain_texture
{ {
VkImage image; VkImage image;
@ -56,20 +41,12 @@ struct vulkan_filter_chain_texture
VkFormat format; VkFormat format;
}; };
enum vulkan_filter_chain_scale
{
VULKAN_FILTER_CHAIN_SCALE_ORIGINAL,
VULKAN_FILTER_CHAIN_SCALE_SOURCE,
VULKAN_FILTER_CHAIN_SCALE_VIEWPORT,
VULKAN_FILTER_CHAIN_SCALE_ABSOLUTE
};
struct vulkan_filter_chain_pass_info struct vulkan_filter_chain_pass_info
{ {
/* For the last pass, make sure VIEWPORT scale /* For the last pass, make sure VIEWPORT scale
* with scale factors of 1 are used. */ * with scale factors of 1 are used. */
enum vulkan_filter_chain_scale scale_type_x; enum glslang_filter_chain_scale scale_type_x;
enum vulkan_filter_chain_scale scale_type_y; enum glslang_filter_chain_scale scale_type_y;
float scale_x; float scale_x;
float scale_y; float scale_y;
@ -77,9 +54,9 @@ struct vulkan_filter_chain_pass_info
VkFormat rt_format; VkFormat rt_format;
/* The filter to use for source in this pass. */ /* The filter to use for source in this pass. */
enum vulkan_filter_chain_filter source_filter; enum glslang_filter_chain_filter source_filter;
enum vulkan_filter_chain_filter mip_filter; enum glslang_filter_chain_filter mip_filter;
enum vulkan_filter_chain_address address; enum glslang_filter_chain_address address;
/* Maximum number of mip-levels to use. */ /* Maximum number of mip-levels to use. */
unsigned max_levels; unsigned max_levels;
@ -111,25 +88,6 @@ struct vulkan_filter_chain_create_info
struct vulkan_filter_chain_swapchain_info swapchain; struct vulkan_filter_chain_swapchain_info swapchain;
}; };
static INLINE enum vulkan_filter_chain_address vk_wrap_to_address(enum gfx_wrap_type type)
{
switch (type)
{
case RARCH_WRAP_BORDER:
return VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER;
case RARCH_WRAP_REPEAT:
return VULKAN_FILTER_CHAIN_ADDRESS_REPEAT;
case RARCH_WRAP_MIRRORED_REPEAT:
return VULKAN_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT;
case RARCH_WRAP_EDGE:
default:
break;
}
return VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE;
}
vulkan_filter_chain_t *vulkan_filter_chain_new( vulkan_filter_chain_t *vulkan_filter_chain_new(
const struct vulkan_filter_chain_create_info *info); const struct vulkan_filter_chain_create_info *info);
void vulkan_filter_chain_free(vulkan_filter_chain_t *chain); void vulkan_filter_chain_free(vulkan_filter_chain_t *chain);
@ -178,11 +136,11 @@ void vulkan_filter_chain_end_frame(vulkan_filter_chain_t *chain,
vulkan_filter_chain_t *vulkan_filter_chain_create_default( vulkan_filter_chain_t *vulkan_filter_chain_create_default(
const struct vulkan_filter_chain_create_info *info, const struct vulkan_filter_chain_create_info *info,
enum vulkan_filter_chain_filter filter); enum glslang_filter_chain_filter filter);
vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset( vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
const struct vulkan_filter_chain_create_info *info, const struct vulkan_filter_chain_create_info *info,
const char *path, enum vulkan_filter_chain_filter filter); const char *path, enum glslang_filter_chain_filter filter);
struct video_shader *vulkan_filter_chain_get_preset( struct video_shader *vulkan_filter_chain_get_preset(
vulkan_filter_chain_t *chain); vulkan_filter_chain_t *chain);