* redo glsl2h.pl script to generate only one big glsl headers.
* fix gcc warning in GSVector.h
* fix memory leak of GSDeviceOGL.m_shader
* clean shader compilation function => split generation header & drop malloc stuff
cmake:
* only rebuild shader when asked by the use. Avoid perl dependency to build pcsx2


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5698 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-07-07 16:13:11 +00:00
parent dc036ff59d
commit f22b366cea
14 changed files with 1270 additions and 1378 deletions

View File

@ -7,33 +7,36 @@ use File::Basename;
use File::Copy;
use Cwd 'abs_path';
use Digest::file qw/digest_file_hex/;
use Digest::MD5 qw(md5_hex);
# Allow to use the script without the module. I don't want a full PERL as a dependency of PCSX2!
my $g_disable_md5 = 0;
eval {
require Digest::file;
require Digest::MD5;
Digest::file->import(qw/digest_file_hex/);
Digest::MD5->import(qw/md5_hex/);
1;
} or do {
$g_disable_md5 = 1;
print "Disable MD5\n";
};
my @res = qw/convert interlace merge shadeboost tfx/;
my $path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
foreach my $r (@res) {
glsl2h($path, $r, "glsl");
}
glsl2h($path, "fxaa", "fx");
my @gsdx_res = qw/convert.glsl interlace.glsl merge.glsl shadeboost.glsl tfx.glsl fxaa.fx/;
my $gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
my $gsdx_out = File::Spec->catdir($gsdx_path, "glsl_source.h");
glsl2h($gsdx_path, $gsdx_out, \@gsdx_res);
my @zz_res = qw/ps2hw_gl4.glsl/;
my $zz_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "zzogl-pg", "opengl");
glsl2h($zz_path, "ps2hw_gl4", "glsl");
my $zz_out = File::Spec->catdir($zz_path, "ps2hw_gl4.h");
glsl2h($zz_path, $zz_out, \@zz_res);
sub glsl2h {
my $path = shift;
my $glsl = shift;
my $ext = shift;
my $in = File::Spec->catfile($path, "${glsl}.$ext");
my $out = File::Spec->catfile($path, "${glsl}.h");
open(my $GLSL, "<$in") or die;
my $data = "";
my $in_dir = shift;
my $out_file = shift;
my $glsl_files = shift;
my $include = "";
if ($in =~ /GSdx/) {
if ($in_dir =~ /GSdx/) {
$include = "#include \"stdafx.h\""
}
@ -61,28 +64,38 @@ sub glsl2h {
#pragma once
$include
static const char* ${glsl}_${ext} =
EOS
$data = $header;
my $data = $header;
my $line;
while(defined($line = <$GLSL>)) {
chomp $line;
$line =~ s/\\/\\\\/g;
$line =~ s/"/\\"/g;
$data .= "\t\"$line\\n\"\n";
foreach my $file (@{$glsl_files}) {
my $name = $file;
$name =~ s/\./_/;
$data .= "\nstatic const char* $name =\n";
open(my $GLSL, File::Spec->catfile($in_dir, $file)) or die;
my $line;
while(defined($line = <$GLSL>)) {
chomp $line;
$line =~ s/\\/\\\\/g;
$line =~ s/"/\\"/g;
$data .= "\t\"$line\\n\"\n";
}
$data .= "\t;\n";
}
$data .= "\t;\n";
# Rewriting the file will trigger a relink (even if the content is the
# same). So we check first the content with md5 digest
my $old_md5 = digest_file_hex($out, "MD5");
my $new_md5 = md5_hex($data);
if ( -e $out_file and not $g_disable_md5) {
my $old_md5 = digest_file_hex($out_file, "MD5");
my $new_md5 = md5_hex($data);
if ($old_md5 ne $new_md5) {
open(my $H, ">$out") or die;
if ($old_md5 ne $new_md5) {
open(my $H, ">$out_file") or die;
print $H $data;
}
} else {
open(my $H, ">$out_file") or die;
print $H $data;
}
}

View File

@ -171,6 +171,7 @@ set(GSdxHeaders
GSWndOGL.h
GSWndEGL.h
GSdx.h
res/glsl_source.h
stdafx.h
xbyak/xbyak.h
xbyak/xbyak_bin2hex.h
@ -178,19 +179,12 @@ set(GSdxHeaders
xbyak/xbyak_util.h
)
set(GSdxHeaders
res/convert.h
res/fxaa.h
res/interlace.h
res/merge.h
res/shaderboost.h
res/tfx.h
)
include_directories(.)
# Generate Glsl header file
add_custom_command(OUTPUT res/convert.h res/fxaa.h res/interlace.h res/merge.h res/shaderboost.h res/tfx.h COMMAND perl ${PROJECT_SOURCE_DIR}/linux_various/glsl2h.pl)
# Generate Glsl header file. Protect with REBUILD_SHADER to avoid build-dependency on PERL
if (REBUILD_SHADER)
add_custom_command(OUTPUT res/glsl_source.h COMMAND perl ${PROJECT_SOURCE_DIR}/linux_various/glsl2h.pl)
endif()
add_library(${Output} SHARED ${GSdxSources} ${GSdxHeaders})

View File

@ -22,11 +22,7 @@
#include "stdafx.h"
#include "GSDeviceOGL.h"
#include "res/convert.h"
#include "res/interlace.h"
#include "res/merge.h"
#include "res/shadeboost.h"
#include "res/fxaa.h"
#include "res/glsl_source.h"
// TODO performance cost to investigate
// Texture attachment/glDrawBuffer. For the moment it set every draw and potentially multiple time (first time in clear, second time in rendering)
@ -137,6 +133,10 @@ GSDeviceOGL::~GSDeviceOGL()
for (auto it = m_om_bs.begin(); it != m_om_bs.end(); it++) delete it->second;
m_om_bs.clear();
// Must be done after the destruction of all shader/program objects
delete m_shader;
m_shader = NULL;
}
GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int format)
@ -411,7 +411,6 @@ void GSDeviceOGL::Flip()
void GSDeviceOGL::BeforeDraw()
{
m_shader->UseProgram();
m_shader->SetupUniform();
}
void GSDeviceOGL::AfterDraw()
@ -532,6 +531,52 @@ GLuint GSDeviceOGL::CreateSampler(bool bilinear, bool tau, bool tav)
return sampler;
}
GLuint GSDeviceOGL::CompileVS(VSSelector sel)
{
std::string macro = format("#define VS_BPPZ %d\n", sel.bppz)
+ format("#define VS_LOGZ %d\n", sel.logz)
+ format("#define VS_TME %d\n", sel.tme)
+ format("#define VS_FST %d\n", sel.fst);
return m_shader->Compile("tfx.glsl", "vs_main", GL_VERTEX_SHADER, tfx_glsl, macro);
}
GLuint GSDeviceOGL::CompileGS(GSSelector sel)
{
// Easy case
if(! (sel.prim > 0 && (sel.iip == 0 || sel.prim == 3)))
return 0;
std::string macro = format("#define GS_IIP %d\n", sel.iip)
+ format("#define GS_PRIM %d\n", sel.prim);
return m_shader->Compile("tfx.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_glsl, macro);
}
GLuint GSDeviceOGL::CompilePS(PSSelector sel)
{
std::string macro = format("#define PS_FST %d\n", sel.fst)
+ format("#define PS_WMS %d\n", sel.wms)
+ format("#define PS_WMT %d\n", sel.wmt)
+ format("#define PS_FMT %d\n", sel.fmt)
+ format("#define PS_AEM %d\n", sel.aem)
+ format("#define PS_TFX %d\n", sel.tfx)
+ format("#define PS_TCC %d\n", sel.tcc)
+ format("#define PS_ATST %d\n", sel.atst)
+ format("#define PS_FOG %d\n", sel.fog)
+ format("#define PS_CLR1 %d\n", sel.clr1)
+ format("#define PS_FBA %d\n", sel.fba)
+ format("#define PS_AOUT %d\n", sel.aout)
+ format("#define PS_LTF %d\n", sel.ltf)
+ format("#define PS_COLCLIP %d\n", sel.colclip)
+ format("#define PS_DATE %d\n", sel.date)
+ format("#define PS_SPRITEHACK %d\n", sel.spritehack)
+ format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack)
+ format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler);
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_glsl, macro);
}
GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format)
{
return GSDevice::CreateRenderTarget(w, h, msaa, format ? format : GL_RGBA8);

View File

@ -223,108 +223,110 @@ void GSShaderOGL::UseProgram()
if (it == m_single_prog.end()) {
m_prog = LinkNewProgram();
m_single_prog[sel] = m_prog;
SetupUniform();
} else {
m_prog = it->second;
}
gl_UseProgram(m_prog);
// TODO: might be possible to do it only when prog is linked
// Seem to be OK!
//SetupUniform();
} else {
ValidateProgram(m_pipeline);
SetupUniform();
}
}
GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel)
std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, const std::string& macro)
{
// Not supported
if (type == GL_GEOMETRY_SHADER && !GLLoader::found_geometry_shader) {
return 0;
}
// *****************************************************
// Build a header string
// *****************************************************
// First select the version (must be the first line so we need to generate it
std::string version;
std::string header;
if (GLLoader::found_only_gl30) {
version = "#version 130\n";
header = "#version 130\n";
} else {
version = "#version 330\n";
header = "#version 330\n";
}
if (m_glsl420) {
version += "#extension GL_ARB_shading_language_420pack: require\n";
header += "#extension GL_ARB_shading_language_420pack: require\n";
} else {
version += "#define DISABLE_GL42\n";
header += "#define DISABLE_GL42\n";
}
if (m_sso) {
version += "#extension GL_ARB_separate_shader_objects : require\n";
header += "#extension GL_ARB_separate_shader_objects : require\n";
} else {
if (!GLLoader::fglrx_buggy_driver)
version += "#define DISABLE_SSO\n";
header += "#define DISABLE_SSO\n";
}
if (GLLoader::found_only_gl30) {
// Need version 330
version += "#extension GL_ARB_explicit_attrib_location : require\n";
header += "#extension GL_ARB_explicit_attrib_location : require\n";
// Need version 140
version += "#extension GL_ARB_uniform_buffer_object : require\n";
header += "#extension GL_ARB_uniform_buffer_object : require\n";
}
#ifdef ENABLE_OGL_STENCIL_DEBUG
version += "#define ENABLE_OGL_STENCIL_DEBUG 1\n";
header += "#define ENABLE_OGL_STENCIL_DEBUG 1\n";
#endif
// Allow to puts several shader in 1 files
std::string shader_type;
switch (type) {
case GL_VERTEX_SHADER:
shader_type = "#define VERTEX_SHADER 1\n";
header += "#define VERTEX_SHADER 1\n";
break;
case GL_GEOMETRY_SHADER:
shader_type = "#define GEOMETRY_SHADER 1\n";
header += "#define GEOMETRY_SHADER 1\n";
break;
case GL_FRAGMENT_SHADER:
shader_type = "#define FRAGMENT_SHADER 1\n";
header += "#define FRAGMENT_SHADER 1\n";
break;
default: ASSERT(0);
}
// Select the entry point ie the main function
std::string entry_main = format("#define %s main\n", entry.c_str());
header += format("#define %s main\n", entry.c_str());
std::string header = version + shader_type + entry_main + macro_sel;
header += macro;
return header;
}
GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel)
{
GLuint program = 0;
// Not supported
if (type == GL_GEOMETRY_SHADER && !GLLoader::found_geometry_shader) {
return program;
}
// Note it is better to separate header and source file to have the good line number
// in the glsl compiler report
const char** sources_array = (const char**)malloc(2*sizeof(char*));
const char* sources[2];
char* header_str = (char*)malloc(header.size() + 1);
sources_array[0] = header_str;
header.copy(header_str, header.size(), 0);
header_str[header.size()] = '\0';
std::string header = GenGlslHeader(entry, type, macro_sel);
sources[0] = header.c_str();
if (glsl_h_code)
sources_array[1] = glsl_h_code;
sources[1] = glsl_h_code;
else
sources_array[1] = '\0';
sources[1] = '\0';
GLuint program;
if (m_sso) {
#if 0
// Could be useful one day
const GLchar* ShaderSource[1];
ShaderSource[0] = header.append(source).c_str();
ShaderSource[0] = header.append(glsl_h_code).c_str();
program = gl_CreateShaderProgramv(type, 1, &ShaderSource[0]);
#else
program = gl_CreateShaderProgramv(type, 2, sources_array);
program = gl_CreateShaderProgramv(type, 2, sources);
#endif
} else {
program = gl_CreateShader(type);
gl_ShaderSource(program, 2, sources_array, NULL);
gl_ShaderSource(program, 2, sources, NULL);
gl_CompileShader(program);
}
free(header_str);
free(sources_array);
bool status;
if (m_sso)
status = ValidateProgram(program);

View File

@ -33,6 +33,7 @@ class GSShaderOGL {
const bool m_glsl420;
void SetupUniform();
void SetUniformBinding(GLuint prog, GLchar* name, GLuint binding);
void SetSamplerBinding(GLuint prog, GLchar* name, GLuint binding);
@ -40,6 +41,7 @@ class GSShaderOGL {
bool ValidateProgram(GLuint p);
bool ValidatePipeline(GLuint p);
std::string GenGlslHeader(const std::string& entry, GLenum type, const std::string& macro);
GLuint LinkNewProgram();
public:
@ -52,8 +54,6 @@ class GSShaderOGL {
void UseProgram();
void SetupUniform();
GLuint Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel = "");
void Delete(GLuint s);
};

View File

@ -23,8 +23,6 @@
#include "GSDeviceOGL.h"
#include "GSTables.h"
#include "res/tfx.h"
static const uint32 g_vs_cb_index = 20;
static const uint32 g_ps_cb_index = 21;
@ -48,10 +46,9 @@ void GSDeviceOGL::CreateTextureFX()
m_vb = new GSVertexBufferStateOGL(sizeof(GSVertex), vert_format, countof(vert_format));
// Compile some dummy shaders to allow modification inside Apitrace for debug
std::string macro = "\n";
m_shader->Compile("tfx.glsl", "vs_main", GL_VERTEX_SHADER, tfx_glsl, macro);
m_shader->Compile("tfx.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_glsl, macro);
m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_glsl, macro);
CompileVS(VSSelector());
CompileGS(GSSelector());
CompilePS(PSSelector());
// Pre compile all Geometry & Vertex Shader
// It might cost a seconds at startup but it would reduce benchmark pollution
@ -69,28 +66,6 @@ void GSDeviceOGL::CreateTextureFX()
}
GLuint GSDeviceOGL::CompileVS(VSSelector sel)
{
std::string macro = format("#define VS_BPPZ %d\n", sel.bppz)
+ format("#define VS_LOGZ %d\n", sel.logz)
+ format("#define VS_TME %d\n", sel.tme)
+ format("#define VS_FST %d\n", sel.fst);
return m_shader->Compile("tfx.glsl", "vs_main", GL_VERTEX_SHADER, tfx_glsl, macro);
}
GLuint GSDeviceOGL::CompileGS(GSSelector sel)
{
// Easy case
if(! (sel.prim > 0 && (sel.iip == 0 || sel.prim == 3)))
return 0;
std::string macro = format("#define GS_IIP %d\n", sel.iip)
+ format("#define GS_PRIM %d\n", sel.prim);
return m_shader->Compile("tfx.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_glsl, macro);
}
GLuint GSDeviceOGL::CreateSampler(PSSamplerSelector sel)
{
return CreateSampler(sel.ltf, sel.tau, sel.tav);
@ -157,30 +132,6 @@ GSBlendStateOGL* GSDeviceOGL::CreateBlend(OMBlendSelector bsel, uint8 afix)
return bs;
}
GLuint GSDeviceOGL::CompilePS(PSSelector sel)
{
std::string macro = format("#define PS_FST %d\n", sel.fst)
+ format("#define PS_WMS %d\n", sel.wms)
+ format("#define PS_WMT %d\n", sel.wmt)
+ format("#define PS_FMT %d\n", sel.fmt)
+ format("#define PS_AEM %d\n", sel.aem)
+ format("#define PS_TFX %d\n", sel.tfx)
+ format("#define PS_TCC %d\n", sel.tcc)
+ format("#define PS_ATST %d\n", sel.atst)
+ format("#define PS_FOG %d\n", sel.fog)
+ format("#define PS_CLR1 %d\n", sel.clr1)
+ format("#define PS_FBA %d\n", sel.fba)
+ format("#define PS_AOUT %d\n", sel.aout)
+ format("#define PS_LTF %d\n", sel.ltf)
+ format("#define PS_COLCLIP %d\n", sel.colclip)
+ format("#define PS_DATE %d\n", sel.date)
+ format("#define PS_SPRITEHACK %d\n", sel.spritehack)
+ format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack)
+ format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler);
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_glsl, macro);
}
void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
{
GLuint vs = m_vs[sel];

View File

@ -5790,10 +5790,10 @@ public:
#define VECTOR8_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \
__forceinline GSVector8 xs##ys##zs##ws() const {return GSVector8(_mm256_shuffle_ps(m, m, _MM_SHUFFLE(wn, zn, yn, xn)));} \
__forceinline GSVector8 xs##ys##zs##ws(const GSVector8& v) const {return GSVector8(_mm256_shuffle_ps(m, v.m, _MM_SHUFFLE(wn, zn, yn, xn)));} \
__forceinline GSVector8 xs##ys##zs##ws(const GSVector8& v) const {return GSVector8(_mm256_shuffle_ps(m, v.m, _MM_SHUFFLE(wn, zn, yn, xn)));}
// vs2012u3 cannot reuse the result of equivalent shuffles when it is done with _mm256_permute_ps (write v.xxxx() twice, and it will do it twice), but with _mm256_shuffle_ps it can.
//__forceinline GSVector8 xs##ys##zs##ws() const {return GSVector8(_mm256_permute_ps(m, _MM_SHUFFLE(wn, zn, yn, xn)));} \
//__forceinline GSVector8 xs##ys##zs##ws() const {return GSVector8(_mm256_permute_ps(m, _MM_SHUFFLE(wn, zn, yn, xn)));}
#define VECTOR8_SHUFFLE_3(xs, xn, ys, yn, zs, zn) \
VECTOR8_SHUFFLE_4(xs, xn, ys, yn, zs, zn, x, 0) \

View File

@ -1,203 +0,0 @@
/*
* This file was generated by glsl2h.pl script
*
* This Program 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 Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "stdafx.h"
static const char* convert_glsl =
"//#version 420 // Keep it for editor detection\n"
"\n"
"struct vertex_basic\n"
"{\n"
" vec4 p;\n"
" vec2 t;\n"
"};\n"
"\n"
"\n"
"#ifdef VERTEX_SHADER\n"
"\n"
"#if __VERSION__ > 140\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
" float gl_PointSize;\n"
" float gl_ClipDistance[];\n"
"};\n"
"#endif\n"
"\n"
"layout(location = 0) in vec4 POSITION;\n"
"layout(location = 1) in vec2 TEXCOORD0;\n"
"\n"
"// FIXME set the interpolation (don't know what dx do)\n"
"// flat means that there is no interpolation. The value given to the fragment shader is based on the provoking vertex conventions.\n"
"//\n"
"// noperspective means that there will be linear interpolation in window-space. This is usually not what you want, but it can have its uses.\n"
"//\n"
"// smooth, the default, means to do perspective-correct interpolation.\n"
"//\n"
"// The centroid qualifier only matters when multisampling. If this qualifier is not present, then the value is interpolated to the pixel's center, anywhere in the pixel, or to one of the pixel's samples. This sample may lie outside of the actual primitive being rendered, since a primitive can cover only part of a pixel's area. The centroid qualifier is used to prevent this; the interpolation point must fall within both the pixel's area and the primitive's area.\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) out vertex_basic VSout;\n"
"#define VSout_p (VSout.p)\n"
"#define VSout_t (VSout.t)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"out vec4 SHADERp;\n"
"out vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) out vec4 SHADERp;\n"
"layout(location = 1) out vec2 SHADERt;\n"
"#endif\n"
"#define VSout_p SHADERp\n"
"#define VSout_t SHADERt\n"
"#endif\n"
"\n"
"void vs_main()\n"
"{\n"
" VSout_p = POSITION;\n"
" VSout_t = TEXCOORD0;\n"
" gl_Position = POSITION; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position\n"
"}\n"
"\n"
"#endif\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"// NOTE: pixel can be clip with \"discard\"\n"
"\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex_basic PSin;\n"
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"#endif\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"layout(location = 1) out uint SV_Target1;\n"
"\n"
"#ifdef DISABLE_GL42\n"
"uniform sampler2D TextureSampler;\n"
"#else\n"
"layout(binding = 0) uniform sampler2D TextureSampler;\n"
"#endif\n"
"\n"
"vec4 sample_c()\n"
"{\n"
" return texture(TextureSampler, PSin_t );\n"
"}\n"
"\n"
"uniform vec4 mask[4] = vec4[4]\n"
"(\n"
" vec4(1, 0, 0, 0),\n"
" vec4(0, 1, 0, 0),\n"
" vec4(0, 0, 1, 0),\n"
" vec4(1, 1, 1, 0)\n"
");\n"
"\n"
"\n"
"vec4 ps_crt(uint i)\n"
"{\n"
" return sample_c() * clamp((mask[i] + 0.5f), 0.0f, 1.0f);\n"
"}\n"
"\n"
"void ps_main0()\n"
"{\n"
" SV_Target0 = sample_c();\n"
"}\n"
"\n"
"void ps_main1()\n"
"{\n"
" vec4 c = sample_c();\n"
"\n"
" c.a *= 256.0f / 127.0f; // hm, 0.5 won't give us 1.0 if we just multiply with 2\n"
"\n"
" highp uvec4 i = uvec4(c * vec4(uint(0x001f), uint(0x03e0), uint(0x7c00), uint(0x8000)));\n"
"\n"
" SV_Target1 = (i.x & uint(0x001f)) | (i.y & uint(0x03e0)) | (i.z & uint(0x7c00)) | (i.w & uint(0x8000));\n"
"}\n"
"\n"
"void ps_main7()\n"
"{\n"
" vec4 c = sample_c();\n"
"\n"
" c.a = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"void ps_main5() // triangular\n"
"{\n"
" highp uvec4 p = uvec4(PSin_p);\n"
"\n"
" vec4 c = ps_crt(((p.x + ((p.y >> 1u) & 1u) * 3u) >> 1u) % 3u);\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"void ps_main6() // diagonal\n"
"{\n"
" uvec4 p = uvec4(PSin_p);\n"
"\n"
" vec4 c = ps_crt((p.x + (p.y % 3u)) % 3u);\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"// Used for DATE (stencil)\n"
"void ps_main2()\n"
"{\n"
" if((sample_c().a - 127.5f / 255) < 0) // >= 0x80 pass\n"
" discard;\n"
"\n"
"#ifdef ENABLE_OGL_STENCIL_DEBUG\n"
" SV_Target0 = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n"
"#endif\n"
"}\n"
"\n"
"// Used for DATE (stencil)\n"
"void ps_main3()\n"
"{\n"
" if((127.5f / 255 - sample_c().a) < 0) // < 0x80 pass (== 0x80 should not pass)\n"
" discard;\n"
"\n"
"#ifdef ENABLE_OGL_STENCIL_DEBUG\n"
" SV_Target0 = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n"
"#endif\n"
"}\n"
"\n"
"void ps_main4()\n"
"{\n"
" // FIXME mod and fmod are different when value are negative\n"
" // output.c = fmod(sample_c(input.t) * 255 + 0.5f, 256) / 255;\n"
" vec4 c = mod(sample_c() * 255 + 0.5f, 256) / 255;\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"#endif\n"
;

File diff suppressed because it is too large Load Diff

View File

@ -1,107 +0,0 @@
/*
* This file was generated by glsl2h.pl script
*
* This Program 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 Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "stdafx.h"
static const char* interlace_glsl =
"//#version 420 // Keep it for editor detection\n"
"\n"
"struct vertex_basic\n"
"{\n"
" vec4 p;\n"
" vec2 t;\n"
"};\n"
"\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex_basic PSin;\n"
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"#endif\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb11\n"
"#else\n"
"layout(std140, binding = 11) uniform cb11\n"
"#endif\n"
"{\n"
" vec2 ZrH;\n"
" float hH;\n"
"};\n"
"\n"
"#ifdef DISABLE_GL42\n"
"uniform sampler2D TextureSampler;\n"
"#else\n"
"layout(binding = 0) uniform sampler2D TextureSampler;\n"
"#endif\n"
"\n"
"// TODO ensure that clip (discard) is < 0 and not <= 0 ???\n"
"void ps_main0()\n"
"{\n"
" // I'm not sure it impact us but be safe to lookup texture before conditional if\n"
" // see: http://www.opengl.org/wiki/GLSL_Sampler#Non-uniform_flow_control\n"
" vec4 c = texture(TextureSampler, PSin_t);\n"
" if (fract(PSin_t.y * hH) - 0.5 < 0.0)\n"
" discard;\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"void ps_main1()\n"
"{\n"
" // I'm not sure it impact us but be safe to lookup texture before conditional if\n"
" // see: http://www.opengl.org/wiki/GLSL_Sampler#Non-uniform_flow_control\n"
" vec4 c = texture(TextureSampler, PSin_t);\n"
" if (0.5 - fract(PSin_t.y * hH) < 0.0)\n"
" discard;\n"
"\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"void ps_main2()\n"
"{\n"
" vec4 c0 = texture(TextureSampler, PSin_t - ZrH);\n"
" vec4 c1 = texture(TextureSampler, PSin_t);\n"
" vec4 c2 = texture(TextureSampler, PSin_t + ZrH);\n"
"\n"
" SV_Target0 = (c0 + c1 * 2 + c2) / 4;\n"
"}\n"
"\n"
"void ps_main3()\n"
"{\n"
" SV_Target0 = texture(TextureSampler, PSin_t);\n"
"}\n"
"\n"
"#endif\n"
;

View File

@ -1,83 +0,0 @@
/*
* This file was generated by glsl2h.pl script
*
* This Program 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 Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "stdafx.h"
static const char* merge_glsl =
"//#version 420 // Keep it for editor detection\n"
"\n"
"struct vertex_basic\n"
"{\n"
" vec4 p;\n"
" vec2 t;\n"
"};\n"
"\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex_basic PSin;\n"
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"#endif\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb10\n"
"#else\n"
"layout(std140, binding = 10) uniform cb10\n"
"#endif\n"
"{\n"
" vec4 BGColor;\n"
"};\n"
"\n"
"#ifdef DISABLE_GL42\n"
"uniform sampler2D TextureSampler;\n"
"#else\n"
"layout(binding = 0) uniform sampler2D TextureSampler;\n"
"#endif\n"
"\n"
"void ps_main0()\n"
"{\n"
" vec4 c = texture(TextureSampler, PSin_t);\n"
" c.a = min(c.a * 2, 1.0);\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"void ps_main1()\n"
"{\n"
" vec4 c = texture(TextureSampler, PSin_t);\n"
" c.a = BGColor.a;\n"
" SV_Target0 = c;\n"
"}\n"
"\n"
"#endif\n"
;

View File

@ -1,109 +0,0 @@
/*
* This file was generated by glsl2h.pl script
*
* This Program 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 Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "stdafx.h"
static const char* shadeboost_glsl =
"//#version 420 // Keep it for editor detection\n"
"\n"
"/*\n"
"** Contrast, saturation, brightness\n"
"** Code of this function is from TGM's shader pack\n"
"** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057\n"
"*/\n"
"\n"
"struct vertex_basic\n"
"{\n"
" vec4 p;\n"
" vec2 t;\n"
"};\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex_basic PSin;\n"
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"#endif\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb12\n"
"#else\n"
"layout(std140, binding = 12) uniform cb12\n"
"#endif\n"
"{\n"
" vec4 BGColor;\n"
"};\n"
"\n"
"#ifdef DISABLE_GL42\n"
"uniform sampler2D TextureSampler;\n"
"#else\n"
"layout(binding = 0) uniform sampler2D TextureSampler;\n"
"#endif\n"
"\n"
"// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150% \n"
"vec4 ContrastSaturationBrightness(vec4 color)\n"
"{\n"
" const float sat = SB_SATURATION / 50.0;\n"
" const float brt = SB_BRIGHTNESS / 50.0;\n"
" const float con = SB_CONTRAST / 50.0;\n"
" \n"
" // Increase or decrease theese values to adjust r, g and b color channels seperately\n"
" const float AvgLumR = 0.5;\n"
" const float AvgLumG = 0.5;\n"
" const float AvgLumB = 0.5;\n"
" \n"
" const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);\n"
" \n"
" vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);\n"
" vec3 brtColor = color.rgb * brt;\n"
" float dot_intensity = dot(brtColor, LumCoeff);\n"
" vec3 intensity = vec3(dot_intensity, dot_intensity, dot_intensity);\n"
" vec3 satColor = mix(intensity, brtColor, sat);\n"
" vec3 conColor = mix(AvgLumin, satColor, con);\n"
"\n"
" color.rgb = conColor; \n"
" return color;\n"
"}\n"
"\n"
"\n"
"void ps_main()\n"
"{\n"
" vec4 c = texture(TextureSampler, PSin_t);\n"
" SV_Target0 = ContrastSaturationBrightness(c);\n"
"}\n"
"\n"
"\n"
"#endif\n"
;

View File

@ -1,726 +0,0 @@
/*
* This file was generated by glsl2h.pl script
*
* This Program 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 Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "stdafx.h"
static const char* tfx_glsl =
"//#version 420 // Keep it for text editor detection\n"
"\n"
"// note lerp => mix\n"
"\n"
"#define FMT_32 0\n"
"#define FMT_24 1\n"
"#define FMT_16 2\n"
"#define FMT_PAL 4 /* flag bit */\n"
"\n"
"// Not sure we have same issue on opengl. Doesn't work anyway on ATI card\n"
"// And I say this as an ATI user.\n"
"#define ATI_SUCKS 0\n"
"\n"
"#ifndef VS_BPPZ\n"
"#define VS_BPPZ 0\n"
"#define VS_TME 1\n"
"#define VS_FST 1\n"
"#define VS_LOGZ 0\n"
"#endif\n"
"\n"
"#ifndef GS_IIP\n"
"#define GS_IIP 0\n"
"#define GS_PRIM 3\n"
"#endif\n"
"\n"
"#ifndef PS_FST\n"
"#define PS_FST 0\n"
"#define PS_WMS 0\n"
"#define PS_WMT 0\n"
"#define PS_FMT FMT_32\n"
"#define PS_AEM 0\n"
"#define PS_TFX 0\n"
"#define PS_TCC 1\n"
"#define PS_ATST 1\n"
"#define PS_FOG 0\n"
"#define PS_CLR1 0\n"
"#define PS_FBA 0\n"
"#define PS_AOUT 0\n"
"#define PS_LTF 1\n"
"#define PS_COLCLIP 0\n"
"#define PS_DATE 0\n"
"#define PS_SPRITEHACK 0\n"
"#define PS_POINT_SAMPLER 0\n"
"#define PS_TCOFFSETHACK 0\n"
"#endif\n"
"\n"
"struct vertex\n"
"{\n"
" vec4 t;\n"
" vec4 tp;\n"
" vec4 c;\n"
"};\n"
"\n"
"#ifdef VERTEX_SHADER\n"
"layout(location = 0) in vec2 i_st;\n"
"layout(location = 1) in vec4 i_c;\n"
"layout(location = 2) in float i_q;\n"
"layout(location = 3) in uvec2 i_p;\n"
"layout(location = 4) in uint i_z;\n"
"layout(location = 5) in uvec2 i_uv;\n"
"layout(location = 6) in vec4 i_f;\n"
"\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) out vertex VSout;\n"
"#define VSout_p (VSout.p)\n"
"#define VSout_t (VSout.t)\n"
"#define VSout_tp (VSout.tp)\n"
"#define VSout_c (VSout.c)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"out vec4 SHADERt;\n"
"out vec4 SHADERtp;\n"
"out vec4 SHADERc;\n"
"#else\n"
"layout(location = 0) out vec4 SHADERt;\n"
"layout(location = 1) out vec4 SHADERtp;\n"
"layout(location = 2) out vec4 SHADERc;\n"
"#endif\n"
"#define VSout_t SHADERt\n"
"#define VSout_tp SHADERtp\n"
"#define VSout_c SHADERc\n"
"#endif\n"
"\n"
"#if __VERSION__ > 140\n"
"out gl_PerVertex {\n"
" invariant vec4 gl_Position;\n"
" float gl_PointSize;\n"
" float gl_ClipDistance[];\n"
"};\n"
"#endif\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb20\n"
"#else\n"
"layout(std140, binding = 20) uniform cb20\n"
"#endif\n"
"{\n"
" vec2 VertexScale;\n"
" vec2 VertexOffset;\n"
" vec2 TextureScale;\n"
"};\n"
"\n"
"const float exp_min32 = exp2(-32.0f);\n"
"\n"
"void vs_main()\n"
"{\n"
" uint z;\n"
" if(VS_BPPZ == 1) // 24\n"
" z = i_z & uint(0xffffff);\n"
" else if(VS_BPPZ == 2) // 16\n"
" z = i_z & uint(0xffff);\n"
" else\n"
" z = i_z;\n"
"\n"
" // pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)\n"
" // example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty\n"
" // input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel\n"
" // example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133\n"
"\n"
" vec3 p = vec3(i_p, z) - vec3(0.05f, 0.05f, 0.0f);\n"
" p = p * vec3(VertexScale, exp_min32) - vec3(VertexOffset, 0.0f);\n"
"\n"
" if(VS_LOGZ == 1)\n"
" {\n"
" p.z = log2(1.0f + float(z)) / 32.0f;\n"
" }\n"
"\n"
" gl_Position = vec4(p, 1.0f); // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position\n"
"\n"
" if(VS_TME != 0)\n"
" {\n"
" if(VS_FST != 0)\n"
" {\n"
" VSout_t.xy = i_uv * TextureScale;\n"
" VSout_t.w = 1.0f;\n"
" }\n"
" else\n"
" {\n"
" VSout_t.xy = i_st;\n"
" VSout_t.w = i_q;\n"
" }\n"
" }\n"
" else\n"
" {\n"
" VSout_t.xy = vec2(0.0f, 0.0f);\n"
" VSout_t.w = 1.0f;\n"
" }\n"
"\n"
" VSout_c = i_c;\n"
" VSout_t.z = i_f.r;\n"
"}\n"
"\n"
"#endif\n"
"\n"
"#ifdef GEOMETRY_SHADER\n"
"in gl_PerVertex {\n"
" vec4 gl_Position;\n"
" float gl_PointSize;\n"
" float gl_ClipDistance[];\n"
"} gl_in[];\n"
"\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
" float gl_PointSize;\n"
" float gl_ClipDistance[];\n"
"};\n"
"\n"
"layout(location = 0) in vertex GSin[];\n"
"\n"
"layout(location = 0) out vertex GSout;\n"
"\n"
"#if GS_PRIM == 0\n"
"layout(points) in;\n"
"layout(points, max_vertices = 1) out;\n"
"\n"
"void gs_main()\n"
"{\n"
" for(int i = 0; i < gl_in.length(); i++) {\n"
" gl_Position = gl_in[i].gl_Position;\n"
" GSout = GSin[i];\n"
" EmitVertex();\n"
" }\n"
" EndPrimitive();\n"
"}\n"
"\n"
"#elif GS_PRIM == 1\n"
"layout(lines) in;\n"
"layout(line_strip, max_vertices = 2) out;\n"
"\n"
"void gs_main()\n"
"{\n"
" for(int i = 0; i < gl_in.length(); i++) {\n"
" gl_Position = gl_in[i].gl_Position;\n"
" GSout = GSin[i];\n"
"#if GS_IIP == 0\n"
" if (i == 0)\n"
" GSout.c = GSin[1].c;\n"
"#endif\n"
" EmitVertex();\n"
" }\n"
" EndPrimitive();\n"
"}\n"
"\n"
"#elif GS_PRIM == 2\n"
"layout(triangles) in;\n"
"layout(triangle_strip, max_vertices = 3) out;\n"
"\n"
"void gs_main()\n"
"{\n"
" for(int i = 0; i < gl_in.length(); i++) {\n"
" gl_Position = gl_in[i].gl_Position;\n"
" GSout = GSin[i];\n"
"#if GS_IIP == 0\n"
" if (i == 0 || i == 1)\n"
" GSout.c = GSin[2].c;\n"
"#endif\n"
" EmitVertex();\n"
" }\n"
" EndPrimitive();\n"
"}\n"
"\n"
"#elif GS_PRIM == 3\n"
"layout(lines) in;\n"
"layout(triangle_strip, max_vertices = 6) out;\n"
"\n"
"void gs_main()\n"
"{\n"
" // left top => GSin[0];\n"
" // right bottom => GSin[1];\n"
" vertex rb = GSin[1];\n"
" vertex lt = GSin[0];\n"
" vec4 rb_p = gl_in[1].gl_Position;\n"
" vec4 lb_p = gl_in[1].gl_Position;\n"
" vec4 rt_p = gl_in[1].gl_Position;\n"
" vec4 lt_p = gl_in[0].gl_Position;\n"
"\n"
" lt_p.z = rb_p.z;\n"
" lt.t.zw = rb.t.zw;\n"
"#if GS_IIP == 0\n"
" lt.c = rb.c;\n"
"#endif\n"
"\n"
" vertex lb = rb;\n"
" lb_p.x = lt_p.x;\n"
" lb.t.x = lt.t.x;\n"
"\n"
" vertex rt = rb;\n"
" rt_p.y = lt_p.y;\n"
" rt.t.y = lt.t.y;\n"
"\n"
" // Triangle 1\n"
" gl_Position = lt_p;\n"
" GSout = lt;\n"
" EmitVertex();\n"
"\n"
" gl_Position = lb_p;\n"
" GSout = lb;\n"
" EmitVertex();\n"
"\n"
" gl_Position = rt_p;\n"
" GSout = rt;\n"
" EmitVertex();\n"
"\n"
" EndPrimitive();\n"
"\n"
" // Triangle 2\n"
" gl_Position = lb_p;\n"
" GSout = lb;\n"
" EmitVertex();\n"
"\n"
" gl_Position = rt_p;\n"
" GSout = rt;\n"
" EmitVertex();\n"
"\n"
" gl_Position = rb_p;\n"
" GSout = rb;\n"
" EmitVertex();\n"
"\n"
" EndPrimitive();\n"
"\n"
"}\n"
"\n"
"#endif\n"
"\n"
"#endif\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex PSin;\n"
"#define PSin_t (PSin.t)\n"
"#define PSin_tp (PSin.tp)\n"
"#define PSin_c (PSin.c)\n"
"#else\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERt;\n"
"in vec4 SHADERtp;\n"
"in vec4 SHADERc;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERt;\n"
"layout(location = 1) in vec4 SHADERtp;\n"
"layout(location = 2) in vec4 SHADERc;\n"
"#endif\n"
"#define PSin_t SHADERt\n"
"#define PSin_tp SHADERtp\n"
"#define PSin_c SHADERc\n"
"#endif\n"
"\n"
"// Same buffer but 2 colors for dual source blending\n"
"layout(location = 0, index = 0) out vec4 SV_Target0;\n"
"layout(location = 0, index = 1) out vec4 SV_Target1;\n"
"\n"
"#ifdef DISABLE_GL42\n"
"uniform sampler2D TextureSampler;\n"
"uniform sampler2D PaletteSampler;\n"
"uniform sampler2D RTCopySampler;\n"
"#else\n"
"layout(binding = 0) uniform sampler2D TextureSampler;\n"
"layout(binding = 1) uniform sampler2D PaletteSampler;\n"
"layout(binding = 2) uniform sampler2D RTCopySampler;\n"
"#endif\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb21\n"
"#else\n"
"layout(std140, binding = 21) uniform cb21\n"
"#endif\n"
"{\n"
" vec3 FogColor;\n"
" float AREF;\n"
" vec4 HalfTexel;\n"
" vec4 WH;\n"
" vec4 MinMax;\n"
" vec2 MinF;\n"
" vec2 TA;\n"
" uvec4 MskFix;\n"
" vec4 TC_OffsetHack;\n"
"};\n"
"\n"
"vec4 sample_c(vec2 uv)\n"
"{\n"
" // FIXME: check the issue on openGL\n"
" if (ATI_SUCKS == 1 && PS_POINT_SAMPLER == 1)\n"
" {\n"
" // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),\n"
" // it looks like they add 127/128 of a texel to sampling coordinates\n"
" // occasionally causing point sampling to erroneously round up.\n"
" // I'm manually adjusting coordinates to the centre of texels here,\n"
" // though the centre is just paranoia, the top left corner works fine.\n"
" uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;\n"
" }\n"
"\n"
" return texture(TextureSampler, uv);\n"
"}\n"
"\n"
"vec4 sample_p(float u)\n"
"{\n"
" //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim\n"
" // So for the moment cheat with 0.0f dunno if it work\n"
" return texture(PaletteSampler, vec2(u, 0.0f));\n"
"}\n"
"\n"
"vec4 sample_rt(vec2 uv)\n"
"{\n"
" return texture(RTCopySampler, uv);\n"
"}\n"
"\n"
"vec4 wrapuv(vec4 uv)\n"
"{\n"
" vec4 uv_out = uv;\n"
"\n"
" if(PS_WMS == PS_WMT)\n"
" {\n"
" if(PS_WMS == 2)\n"
" {\n"
" uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n"
" }\n"
" else if(PS_WMS == 3)\n"
" {\n"
" uv_out = vec4(((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy);\n"
" }\n"
" }\n"
" else\n"
" {\n"
" if(PS_WMS == 2)\n"
" {\n"
" uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n"
" }\n"
" else if(PS_WMS == 3)\n"
" {\n"
" uv_out.xz = vec2(((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx);\n"
" }\n"
" if(PS_WMT == 2)\n"
" {\n"
" uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n"
" }\n"
" else if(PS_WMT == 3)\n"
" {\n"
" uv_out.yw = vec2(((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy);\n"
" }\n"
" }\n"
"\n"
" return uv_out;\n"
"}\n"
"\n"
"vec2 clampuv(vec2 uv)\n"
"{\n"
" vec2 uv_out = uv;\n"
"\n"
" if(PS_WMS == 2 && PS_WMT == 2) \n"
" {\n"
" uv_out = clamp(uv, MinF, MinMax.zw);\n"
" }\n"
" else if(PS_WMS == 2)\n"
" {\n"
" uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n"
" }\n"
" else if(PS_WMT == 2)\n"
" {\n"
" uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n"
" }\n"
"\n"
" return uv_out;\n"
"}\n"
"\n"
"mat4 sample_4c(vec4 uv)\n"
"{\n"
" mat4 c;\n"
"\n"
" c[0] = sample_c(uv.xy);\n"
" c[1] = sample_c(uv.zy);\n"
" c[2] = sample_c(uv.xw);\n"
" c[3] = sample_c(uv.zw);\n"
"\n"
" return c;\n"
"}\n"
"\n"
"vec4 sample_4a(vec4 uv)\n"
"{\n"
" vec4 c;\n"
"\n"
" // Dx used the alpha channel.\n"
" // Opengl is only 8 bits on red channel.\n"
" c.x = sample_c(uv.xy).r;\n"
" c.y = sample_c(uv.zy).r;\n"
" c.z = sample_c(uv.xw).r;\n"
" c.w = sample_c(uv.zw).r;\n"
"\n"
" return c * 255./256 + 0.5/256;\n"
"}\n"
"\n"
"mat4 sample_4p(vec4 u)\n"
"{\n"
" mat4 c;\n"
"\n"
" c[0] = sample_p(u.x);\n"
" c[1] = sample_p(u.y);\n"
" c[2] = sample_p(u.z);\n"
" c[3] = sample_p(u.w);\n"
"\n"
" return c;\n"
"}\n"
"\n"
"vec4 sample_color(vec2 st, float q)\n"
"{\n"
" if(PS_FST == 0) st /= q;\n"
"\n"
" if(PS_TCOFFSETHACK == 1) st += TC_OffsetHack.xy;\n"
"\n"
" vec4 t;\n"
" mat4 c;\n"
" vec2 dd;\n"
"\n"
" if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)\n"
" {\n"
" c[0] = sample_c(clampuv(st));\n"
" }\n"
" else\n"
" {\n"
" vec4 uv;\n"
"\n"
" if(PS_LTF != 0)\n"
" {\n"
" uv = st.xyxy + HalfTexel;\n"
" dd = fract(uv.xy * WH.zw);\n"
" }\n"
" else\n"
" {\n"
" uv = st.xyxy;\n"
" }\n"
"\n"
" uv = wrapuv(uv);\n"
"\n"
" if((PS_FMT & FMT_PAL) != 0)\n"
" {\n"
" c = sample_4p(sample_4a(uv));\n"
" }\n"
" else\n"
" {\n"
" c = sample_4c(uv);\n"
" }\n"
" }\n"
"\n"
" // PERF: see the impact of the exansion before/after the interpolation\n"
" for (int i = 0; i < 4; i++)\n"
" {\n"
" if((PS_FMT & ~FMT_PAL) == FMT_24)\n"
" {\n"
" // FIXME GLSL any only support bvec so try to mix it with notEqual\n"
" bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );\n"
" c[i].a = ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
" }\n"
" else if((PS_FMT & ~FMT_PAL) == FMT_16)\n"
" {\n"
" // FIXME GLSL any only support bvec so try to mix it with notEqual\n"
" bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );\n"
" c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
" }\n"
" }\n"
"\n"
" if(PS_LTF != 0)\n"
" {\n"
" t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n"
" }\n"
" else\n"
" {\n"
" t = c[0];\n"
" }\n"
"\n"
" return t;\n"
"}\n"
"\n"
"vec4 tfx(vec4 t, vec4 c)\n"
"{\n"
" vec4 c_out = c;\n"
" if(PS_TFX == 0)\n"
" {\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out = c * t * 255.0f / 128;\n"
" }\n"
" else\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128;\n"
" }\n"
" }\n"
" else if(PS_TFX == 1)\n"
" {\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out = t;\n"
" }\n"
" else\n"
" {\n"
" c_out.rgb = t.rgb;\n"
" }\n"
" }\n"
" else if(PS_TFX == 2)\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128 + c.a;\n"
"\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out.a += t.a;\n"
" }\n"
" }\n"
" else if(PS_TFX == 3)\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128 + c.a;\n"
"\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out.a = t.a;\n"
" }\n"
" }\n"
"\n"
" return clamp(c_out, vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(1.0f, 1.0f, 1.0f, 1.0f));\n"
"}\n"
"\n"
"void datst()\n"
"{\n"
"#if PS_DATE > 0\n"
" float alpha = sample_rt(PSin_tp.xy).a;\n"
" float alpha0x80 = 128. / 255;\n"
"\n"
" if (PS_DATE == 1 && alpha >= alpha0x80)\n"
" discard;\n"
" else if (PS_DATE == 2 && alpha < alpha0x80)\n"
" discard;\n"
"#endif\n"
"}\n"
"\n"
"void atst(vec4 c)\n"
"{\n"
" float a = trunc(c.a * 255 + 0.01);\n"
"\n"
" if(PS_ATST == 0) // never\n"
" {\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 1) // always\n"
" {\n"
" // nothing to do\n"
" }\n"
" else if(PS_ATST == 2 ) // l\n"
" {\n"
" if (PS_SPRITEHACK == 0)\n"
" if ((AREF - a - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 3 ) // le\n"
" {\n"
" if ((AREF - a + 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 4) // e\n"
" {\n"
" if ((0.5f - abs(a - AREF)) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 5) // ge\n"
" {\n"
" if ((a-AREF + 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 6) // g\n"
" {\n"
" if ((a-AREF - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 7) // ne\n"
" {\n"
" if ((abs(a - AREF) - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
"}\n"
"\n"
"vec4 fog(vec4 c, float f)\n"
"{\n"
" vec4 c_out = c;\n"
" if(PS_FOG != 0)\n"
" {\n"
" c_out.rgb = mix(FogColor, c.rgb, f);\n"
" }\n"
"\n"
" return c_out;\n"
"}\n"
"\n"
"vec4 ps_color()\n"
"{\n"
" datst();\n"
"\n"
" vec4 t = sample_color(PSin_t.xy, PSin_t.w);\n"
"\n"
" vec4 c = tfx(t, PSin_c);\n"
"\n"
" atst(c);\n"
"\n"
" c = fog(c, PSin_t.z);\n"
"\n"
" if (PS_COLCLIP == 2)\n"
" {\n"
" c.rgb = 256.0f/255.0f - c.rgb;\n"
" }\n"
" if (PS_COLCLIP > 0)\n"
" {\n"
" // FIXME !!!!\n"
" //c.rgb *= c.rgb < 128./255;\n"
" bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f);\n"
" c.rgb *= vec3(factor);\n"
" }\n"
"\n"
" if(PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes\n"
" {\n"
" c.rgb = vec3(1.0f, 1.0f, 1.0f); \n"
" }\n"
"\n"
" return c;\n"
"}\n"
"\n"
"void ps_main()\n"
"{\n"
" vec4 c = ps_color();\n"
"\n"
" float alpha = c.a * 2;\n"
"\n"
" if(PS_AOUT != 0) // 16 bit output\n"
" {\n"
" float a = 128.0f / 255; // alpha output will be 0x80\n"
"\n"
" c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;\n"
" }\n"
" else if(PS_FBA != 0)\n"
" {\n"
" if(c.a < 0.5) c.a += 0.5;\n"
" }\n"
"\n"
" SV_Target0 = c;\n"
" SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n"
"}\n"
"#endif\n"
;

View File

@ -154,8 +154,10 @@ set(zzoglLinuxHeaders
include_directories(.
Linux)
# Generate Glsl header file
add_custom_command(OUTPUT ps2hw_gl4.h COMMAND perl ${PROJECT_SOURCE_DIR}/linux_various/glsl2h.pl)
# Generate Glsl header file. Protect with REBUILD_SHADER to avoid build-dependency on PERL
if (REBUILD_SHADER)
add_custom_command(OUTPUT ps2hw_gl4.h COMMAND perl ${PROJECT_SOURCE_DIR}/linux_various/glsl2h.pl)
endif()
# add library
add_library(${Output} SHARED