gsdx ogl: use load resource to load shader

* Windows behavior must be checked
* remove glsl_source.h

v2: fix missing include
Big thanks to Turtleli

v3:
fix indentation in gsdx-res.xml
add dependency in cmake
remove old res/glsl/fxaa.fx symlink
add tfx.cl for OpenCL support on Linux

v4, v5
fix cmake indentation
This commit is contained in:
Gregory Hainaut 2017-04-08 18:14:26 +02:00
parent 38c4f5b6e7
commit 2d0a61fc8d
14 changed files with 149 additions and 2495 deletions

View File

@ -34,24 +34,6 @@ eval {
print "Disable MD5\n";
};
########################
# GSdx
########################
my $gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
my $gsdx_out = File::Spec->catdir($gsdx_path, "glsl_source.h");
# Just a hack to reuse glsl2h function easily
$gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res", "glsl");
my @tfx_res = qw/tfx_fs.glsl/;
my $tfx_all = File::Spec->catdir($gsdx_path, "tfx_fs_all.glsl");
my @gsdx_res = qw/common_header.glsl convert.glsl interlace.glsl merge.glsl shadeboost.glsl tfx_vgs.glsl tfx_fs_all.glsl fxaa.fx/;
concat($gsdx_path, $tfx_all, \@tfx_res);
glsl2h($gsdx_path, $gsdx_out, \@gsdx_res);
unlink $tfx_all;
########################
# ZZOGL
########################
@ -60,22 +42,6 @@ my $zz_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "zzogl-
my $zz_out = File::Spec->catdir($zz_path, "ps2hw_gl4.h");
glsl2h($zz_path, $zz_out, \@zz_res);
sub concat {
my $in_dir = shift;
my $out_file = shift;
my $glsl_files = shift;
my $line;
open(my $TMP, ">$out_file");
foreach my $file (@{$glsl_files}) {
open(my $GLSL, File::Spec->catfile($in_dir, $file)) or die "$! : $file";
while(defined($line = <$GLSL>)) {
print $TMP $line;
}
}
}
sub glsl2h {
my $in_dir = shift;
my $out_file = shift;

View File

@ -195,7 +195,6 @@ set(GSdxHeaders
PSX/GPUSetupPrimCodeGenerator.h
PSX/GPUState.h
PSX/GPUVertex.h
res/glsl_source.h
stdafx.h
xbyak/xbyak.h
xbyak/xbyak_mnemonic.h
@ -289,23 +288,30 @@ if(OPENCL_FOUND)
set(GSdxFinalLibs ${GSdxFinalLibs} ${OPENCL_LIBRARIES})
endif()
# 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 ${CMAKE_SOURCE_DIR}/linux_various/glsl2h.pl)
endif()
set(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res")
set(RESOURCE_FILES
res/logo-ogl.bmp
res/fxaa.fx
res/tfx.cl
res/glsl/common_header.glsl
res/glsl/convert.glsl
res/glsl/interlace.glsl
res/glsl/merge.glsl
res/glsl/shadeboost.glsl
res/glsl/tfx_fs.glsl
res/glsl/tfx_vgs.glsl)
# Note: trying to combine --generate-source and --generate-header doesn't work. It outputs whichever one comes last into the file named by the first
add_custom_command(
OUTPUT GSdxResources.h
COMMAND glib-compile-resources --sourcedir "${RESOURCE_DIR}" --generate-header
--c-name GSdx_res "${RESOURCE_DIR}/gsdx-res.xml" --target=GSdxResources.h
DEPENDS res/gsdx-res.xml res/logo-ogl.bmp)
DEPENDS res/gsdx-res.xml ${RESOURCE_FILES})
add_custom_command(
OUTPUT GSdxResources.cpp
COMMAND glib-compile-resources --sourcedir "${RESOURCE_DIR}" --generate-source
--c-name GSdx_res "${RESOURCE_DIR}/gsdx-res.xml" --target=GSdxResources.cpp
DEPENDS res/gsdx-res.xml res/logo-ogl.bmp)
DEPENDS res/gsdx-res.xml ${RESOURCE_FILES})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

View File

@ -27,10 +27,14 @@
#include "GSOsdManager.h"
#include <fstream>
#include "res/glsl_source.h"
//#define ONLY_LINES
#ifdef _WIN32
#include "resource.h"
#else
#include "GSdxResources.h"
#endif
// TODO port those value into PerfMon API
#ifdef ENABLE_OGL_DEBUG_MEM_BW
uint64 g_real_texture_upload_byte = 0;
@ -289,6 +293,7 @@ GSTexture* GSDeviceOGL::FetchSurface(int type, int w, int h, bool msaa, int form
bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
{
std::vector<char> shader;
// ****************************************************************
// Debug helper
// ****************************************************************
@ -381,11 +386,13 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
m_misc_cb_cache.ScalingFactor = GSVector4i(theApp.GetConfigI("upscale_multiplier"));
m_convert.cb->cache_upload(&m_misc_cb_cache);
vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, convert_glsl);
theApp.LoadResource(IDR_CONVERT_GLSL, shader);
vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, shader.data());
m_convert.vs = vs;
for(size_t i = 0; i < countof(m_convert.ps); i++) {
ps = m_shader->Compile("convert.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, convert_glsl);
ps = m_shader->Compile("convert.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
string pretty_name = "Convert pipe " + to_string(i);
m_convert.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -411,8 +418,10 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
m_merge_obj.cb = new GSUniformBufferOGL("Merge UBO", g_merge_cb_index, sizeof(MergeConstantBuffer));
theApp.LoadResource(IDR_MERGE_GLSL, shader);
for(size_t i = 0; i < countof(m_merge_obj.ps); i++) {
ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, merge_glsl);
ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
string pretty_name = "Merge pipe " + to_string(i);
m_merge_obj.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -426,8 +435,10 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
m_interlace.cb = new GSUniformBufferOGL("Interlace UBO", g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
theApp.LoadResource(IDR_INTERLACE_GLSL, shader);
for(size_t i = 0; i < countof(m_interlace.ps); i++) {
ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, interlace_glsl);
ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
string pretty_name = "Interlace pipe " + to_string(i);
m_interlace.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -446,7 +457,9 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
+ format("#define SB_BRIGHTNESS %d.0\n", ShadeBoost_Brightness)
+ format("#define SB_CONTRAST %d.0\n", ShadeBoost_Contrast);
ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, shadeboost_glsl, shade_macro);
theApp.LoadResource(IDR_SHADEBOOST_GLSL, shader);
ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, shader.data(), shade_macro);
m_shadeboost.ps = m_shader->LinkPipeline("ShadeBoost pipe", vs, 0, ps);
}
@ -566,6 +579,9 @@ void GSDeviceOGL::CreateTextureFX()
m_vs_cb = new GSUniformBufferOGL("HW VS UBO", g_vs_cb_index, sizeof(VSConstantBuffer));
m_ps_cb = new GSUniformBufferOGL("HW PS UBO", g_ps_cb_index, sizeof(PSConstantBuffer));
theApp.LoadResource(IDR_TFX_VGS_GLSL, m_shader_tfx_vgs);
theApp.LoadResource(IDR_TFX_FS_GLSL, m_shader_tfx_fs);
// warning 1 sampler by image unit. So you cannot reuse m_ps_ss...
m_palette_ss = CreateSampler(PSSamplerSelector(0));
glBindSampler(1, m_palette_ss);
@ -899,28 +915,25 @@ void GSDeviceOGL::Barrier(GLbitfield b)
glMemoryBarrier(b);
}
/* Note: must be here because tfx_glsl is static */
GLuint GSDeviceOGL::CompileVS(VSSelector sel)
{
if (GLLoader::buggy_sso_dual_src)
return m_shader->CompileShader("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, tfx_vgs_glsl, "");
return m_shader->CompileShader("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_tfx_vgs.data(), "");
else
return m_shader->Compile("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, tfx_vgs_glsl, "");
return m_shader->Compile("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_tfx_vgs.data(), "");
}
/* Note: must be here because tfx_glsl is static */
GLuint GSDeviceOGL::CompileGS(GSSelector sel)
{
std::string macro = format("#define GS_POINT %d\n", sel.point)
+ format("#define GS_LINE %d\n", sel.line);
if (GLLoader::buggy_sso_dual_src)
return m_shader->CompileShader("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_vgs_glsl, macro);
return m_shader->CompileShader("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, m_shader_tfx_vgs.data(), macro);
else
return m_shader->Compile("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_vgs_glsl, macro);
return m_shader->Compile("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, m_shader_tfx_vgs.data(), macro);
}
/* Note: must be here because tfx_glsl is static */
GLuint GSDeviceOGL::CompilePS(PSSelector sel)
{
std::string macro = format("#define PS_FST %d\n", sel.fst)
@ -961,9 +974,9 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
;
if (GLLoader::buggy_sso_dual_src)
return m_shader->CompileShader("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_fs_all_glsl, macro);
return m_shader->CompileShader("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_tfx_fs.data(), macro);
else
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_fs_all_glsl, macro);
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_tfx_fs.data(), macro);
}
void GSDeviceOGL::SelfShaderTestRun(const string& dir, const string& file, const PSSelector& sel, int& nb_shader)
@ -1481,7 +1494,11 @@ void GSDeviceOGL::DoFXAA(GSTexture* sTex, GSTexture* dTex)
std::string fxaa_macro = "#define FXAA_GLSL_130 1\n";
fxaa_macro += "#extension GL_ARB_gpu_shader5 : enable\n";
GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, fxaa_fx, fxaa_macro);
std::vector<char> shader;
theApp.LoadResource(IDR_FXAA_FX, shader);
GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, shader.data(), fxaa_macro);
m_fxaa.ps = m_shader->LinkPipeline("FXAA pipe", m_convert.vs, 0, ps);
}

View File

@ -418,6 +418,10 @@ public:
bool m_disable_hw_gl_draw;
// Place holder for the GLSL shader code (to avoid useless reload)
std::vector<char> m_shader_tfx_vgs;
std::vector<char> m_shader_tfx_fs;
GLuint m_fbo; // frame buffer container
GLuint m_fbo_read; // frame buffer container only for reading

View File

@ -1931,14 +1931,10 @@ GSRendererCL::CL::CL()
std::vector<char> buff;
#ifdef _WIN32
if(theApp.LoadResource(IDR_TFX_CL, buff))
{
kernel_str = std::string(buff.data(), buff.size());
}
#else
ASSERT(0);
#endif
vb.head = vb.tail = vb.size = 0;
ib.head = ib.tail = ib.size = 0;

View File

@ -87,5 +87,15 @@ enum {
IDC_OSD_MONITOR,
IDC_OSD_MAX_LOG,
IDC_OSD_MAX_LOG_EDIT,
// Shader
IDR_CONVERT_GLSL,
IDR_FXAA_FX,
IDR_INTERLACE_GLSL,
IDR_MERGE_GLSL,
IDR_SHADEBOOST_GLSL,
IDR_COMMON_GLSL,
IDR_TFX_VGS_GLSL,
IDR_TFX_FS_GLSL,
IDR_TFX_CL,
};
#endif

View File

@ -23,12 +23,18 @@
#include "GSShaderOGL.h"
#include "GLState.h"
#include "res/glsl_source.h"
#ifdef _WIN32
#include "resource.h"
#else
#include "GSdxResources.h"
#endif
GSShaderOGL::GSShaderOGL(bool debug) :
m_pipeline(0),
m_debug_shader(debug)
{
theApp.LoadResource(IDR_COMMON_GLSL, m_common_header);
// Create a default pipeline
m_pipeline = LinkPipeline("HW pipe", 0, 0, 0);
BindPipeline(m_pipeline);
@ -263,7 +269,7 @@ GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& ent
std::string header = GenGlslHeader(entry, type, macro_sel);
sources[0] = header.c_str();
sources[1] = common_header_glsl;
sources[1] = m_common_header.data();
sources[2] = glsl_h_code;
program = glCreateShaderProgramv(type, shader_nb, sources);
@ -297,7 +303,7 @@ GLuint GSShaderOGL::CompileShader(const std::string& glsl_file, const std::strin
std::string header = GenGlslHeader(entry, type, macro_sel);
sources[0] = header.c_str();
sources[1] = common_header_glsl;
sources[1] = m_common_header.data();
sources[2] = glsl_h_code;
shader = glCreateShader(type);

View File

@ -35,6 +35,7 @@ class GSShaderOGL {
bool ValidatePipeline(GLuint p);
std::string GenGlslHeader(const std::string& entry, GLenum type, const std::string& macro);
std::vector<char> m_common_header;
public:
GSShaderOGL(bool debug);

View File

@ -67,6 +67,33 @@ bool GSdxApp::LoadResource(int id, std::vector<char>& buff, const char* type)
{
std::string path;
switch (id) {
case IDR_COMMON_GLSL:
path = "/GSdx/res/glsl/common_header.glsl";
break;
case IDR_CONVERT_GLSL:
path = "/GSdx/res/glsl/convert.glsl";
break;
case IDR_FXAA_FX:
path = "/GSdx/res/fxaa.fx";
break;
case IDR_INTERLACE_GLSL:
path = "/GSdx/res/glsl/interlace.glsl";
break;
case IDR_MERGE_GLSL:
path = "/GSdx/res/glsl/merge.glsl";
break;
case IDR_SHADEBOOST_GLSL:
path = "/GSdx/res/glsl/shadeboost.glsl";
break;
case IDR_TFX_VGS_GLSL:
path = "/GSdx/res/glsl/tfx_vgs.glsl";
break;
case IDR_TFX_FS_GLSL:
path = "/GSdx/res/glsl/tfx_fs.glsl";
break;
case IDR_TFX_CL:
path = "/GSdx/res/tfx.cl";
break;
default:
printf("LoadResource not implemented for id %d\n", id);
return false;

View File

@ -83,6 +83,19 @@ IDR_SHADEBOOST_FX RCDATA "res\\shadeboost.fx"
IDR_TFX_CL RCDATA "res\\tfx.cl"
IDR_CONVERT_GLSL RCDATA "res\\glsl\\convert.glsl";
IDR_INTERLACE_GLSL RCDATA "res\\glsl\\interlace.glsl";
IDR_MERGE_GLSL RCDATA "res\\glsl\\merge.glsl";
IDR_SHADEBOOST_GLSL RCDATA "res\\glsl\\shadeboost.glsl";
IDR_COMMON_GLSL RCDATA "res\\glsl\\common_header.glsl";
IDR_TFX_VGS_GLSL RCDATA "res\\glsl\\tfx_vgs.glsl";
IDR_TFX_FS_GLSL RCDATA "res\\glsl\\tfx_fs.glsl";
/////////////////////////////////////////////////////////////////////////////
//

View File

@ -1 +0,0 @@
../fxaa.fx

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/GSdx/res/">
<file>logo-ogl.bmp</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>logo-ogl.bmp</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/common_header.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/convert.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>fxaa.fx</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/interlace.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/merge.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/shadeboost.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/tfx_vgs.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>glsl/tfx_fs.glsl</file>
</gresource>
<gresource prefix="/GSdx/res/">
<file>tfx.cl</file>
</gresource>
</gresources>

View File

@ -151,6 +151,13 @@
#define IDR_TFX_CL 10008
#define IDD_HACKS 10009
#define IDD_OSD 10010
#define IDR_CONVERT_GLSL 10011
#define IDR_INTERLACE_GLSL 10012
#define IDR_MERGE_GLSL 10013
#define IDR_SHADEBOOST_GLSL 10014
#define IDR_COMMON_GLSL 10015
#define IDR_TFX_VGS_GLSL 10016
#define IDR_TFX_FS_GLSL 10017
#define IDC_STATIC -1
// Next default values for new objects