GS: Use files on disk instead of embedded resources

This commit is contained in:
Connor McLaughlin 2021-09-25 13:21:41 +10:00 committed by refractionpcsx2
parent 0029dac32d
commit 3e968b4390
32 changed files with 129 additions and 353 deletions

View File

@ -858,42 +858,6 @@ else(WIN32)
USB/usb-pad/evdev/evdev.h
USB/usb-pad/evdev/shared.h
)
# GS resources
set(pcsx2GSResources
GS/res/fxaa.fx
GS/res/glsl/common_header.glsl
GS/res/glsl/convert.glsl
GS/res/glsl/interlace.glsl
GS/res/glsl/merge.glsl
GS/res/glsl/shadeboost.glsl
GS/res/glsl/tfx_fs.glsl
GS/res/glsl/tfx_vgs.glsl)
set(GSBin "${CMAKE_BINARY_DIR}/pcsx2/GS")
target_include_directories(PCSX2_FLAGS INTERFACE "${GSBin}")
file(MAKE_DIRECTORY "${GSBin}")
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/pcsx2/GS/GS_res.h
COMMAND glib-compile-resources --sourcedir "${CMAKE_SOURCE_DIR}/pcsx2/GS/res" --generate-header
--c-name GS_res "${CMAKE_SOURCE_DIR}/pcsx2/GS/res/GS-res.xml" --target=${CMAKE_BINARY_DIR}/pcsx2/GS/GS_res.h
DEPENDS ${pcsx2GSResources})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/pcsx2/GS/GS_res.cpp
COMMAND glib-compile-resources --sourcedir "${CMAKE_SOURCE_DIR}/pcsx2/GS/res" --generate-source
--c-name GS_res "${CMAKE_SOURCE_DIR}/pcsx2/GS/res/GS-res.xml" --target=${CMAKE_BINARY_DIR}/pcsx2/GS/GS_res.cpp
DEPENDS ${pcsx2GSResources})
list(APPEND pcsx2GSSources
GS/GS_res.cpp
)
list(APPEND pcsx2GSHeaders
GS/GS_res.h
)
endif(WIN32)
@ -1539,6 +1503,20 @@ if (APPLE)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/gui/Resources/PCSX2.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties("${CMAKE_SOURCE_DIR}/bin/GameIndex.yaml" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# Add in shaders and other resources.
file(GLOB resource_files "${CMAKE_SOURCE_DIR}/bin/resources/*")
foreach(file ${resource_files})
target_sources(PCSX2 PRIVATE "${file}")
set_source_files_properties("${file}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endforeach()
# Add in shaders and other resources.
file(GLOB resource_files "${CMAKE_SOURCE_DIR}/bin/resources/*")
foreach(file ${resource_files})
target_sources(PCSX2 PRIVATE "${file}")
set_source_files_properties("${file}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endforeach()
# If they say to skip postprocess bundle, leave the target in but make it so they have
# to manually run it
if (SKIP_POSTPROCESS_BUNDLE)

View File

@ -912,91 +912,6 @@ void fifo_free(void* ptr, size_t size, size_t repeat)
#endif
static void* s_hModule;
#ifdef _WIN32
bool GSApp::LoadResource(int id, std::vector<char>& buff, const wchar_t* type)
{
buff.clear();
HRSRC hRsrc = FindResource((HMODULE)s_hModule, MAKEINTRESOURCE(id), type != NULL ? type : (LPWSTR)RT_RCDATA);
if (!hRsrc)
return false;
HGLOBAL hGlobal = ::LoadResource((HMODULE)s_hModule, hRsrc);
if (!hGlobal)
return false;
DWORD size = SizeofResource((HMODULE)s_hModule, hRsrc);
if (!size)
return false;
// On Linux resources are always NULL terminated
// Add + 1 on size to do the same for compatibility sake (required by GSDeviceOGL)
buff.resize(size + 1);
memcpy(buff.data(), LockResource(hGlobal), size);
return true;
}
#else
#include "GS_res.h"
bool GSApp::LoadResource(int id, std::vector<char>& buff, const char* type)
{
std::string path;
switch (id)
{
case IDR_COMMON_GLSL:
path = "/GS/res/glsl/common_header.glsl";
break;
case IDR_CONVERT_GLSL:
path = "/GS/res/glsl/convert.glsl";
break;
case IDR_FXAA_FX:
path = "/GS/res/fxaa.fx";
break;
case IDR_INTERLACE_GLSL:
path = "/GS/res/glsl/interlace.glsl";
break;
case IDR_MERGE_GLSL:
path = "/GS/res/glsl/merge.glsl";
break;
case IDR_SHADEBOOST_GLSL:
path = "/GS/res/glsl/shadeboost.glsl";
break;
case IDR_TFX_VGS_GLSL:
path = "/GS/res/glsl/tfx_vgs.glsl";
break;
case IDR_TFX_FS_GLSL:
path = "/GS/res/glsl/tfx_fs.glsl";
break;
case IDR_FONT_ROBOTO:
path = "/GS/res/fonts-roboto/Roboto-Regular.ttf";
break;
default:
printf("LoadResource not implemented for id %d\n", id);
return false;
}
GBytes* bytes = g_resource_lookup_data(GS_res_get_resource(), path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr);
size_t size = 0;
const void* data = g_bytes_get_data(bytes, &size);
if (data == nullptr || size == 0)
{
printf("Failed to get data for resource: %d\n", id);
return false;
}
buff.clear();
buff.resize(size + 1);
memcpy(buff.data(), data, size + 1);
g_bytes_unref(bytes);
return true;
}
#endif
size_t GSApp::GetIniString(const char* lpAppName, const char* lpKeyName, const char* lpDefault, char* lpReturnedString, size_t nSize, const char* lpFileName)
{
BuildConfigurationMap(lpFileName);
@ -1361,11 +1276,6 @@ void GSApp::BuildConfigurationMap(const char* lpFileName)
}
}
void* GSApp::GetModuleHandlePtr()
{
return s_hModule;
}
void GSApp::SetConfigDir()
{
// we need to initialize the ini folder later at runtime than at theApp init, as

View File

@ -149,14 +149,6 @@ public:
GSApp();
void Init();
void* GetModuleHandlePtr();
#ifdef _WIN32
HMODULE GetModuleHandle()
{
return (HMODULE)GetModuleHandlePtr();
}
#endif
void BuildConfigurationMap(const char* lpFileName);
void ReloadConfig();
@ -165,12 +157,6 @@ public:
bool WriteIniString(const char* lpAppName, const char* lpKeyName, const char* pString, const char* lpFileName);
int GetIniInt(const char* lpAppName, const char* lpKeyName, int nDefault, const char* lpFileName);
#ifdef _WIN32
bool LoadResource(int id, std::vector<char>& buff, const wchar_t* type = nullptr);
#else
bool LoadResource(int id, std::vector<char>& buff, const char* type = nullptr);
#endif
void SetConfig(const char* entry, const char* value);
void SetConfig(const char* entry, int value);
// Avoid issue with overloading

View File

@ -44,54 +44,9 @@ BEGIN
"\0"
END
3 TEXTINCLUDE
BEGIN
"#include ""res/tfx.fx""\r\n"
"#include ""res/convert.fx""\r\n"
"#include ""res/interlace.fx""\r\n"
"#include ""res/merge.fx""\r\n"
"#include ""res/fxaa.fx""\r\n"
"#include ""res/shadeboost.fx""\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// RCDATA
//
IDR_TFX_FX RCDATA "res\\tfx.fx"
IDR_CONVERT_FX RCDATA "res\\convert.fx"
IDR_INTERLACE_FX RCDATA "res\\interlace.fx"
IDR_MERGE_FX RCDATA "res\\merge.fx"
IDR_FXAA_FX RCDATA "res\\fxaa.fx"
IDR_SHADEBOOST_FX RCDATA "res\\shadeboost.fx"
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";
IDR_FONT_ROBOTO RCDATA "res\\fonts-roboto\\Roboto-Regular.ttf";
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
@ -139,18 +94,4 @@ END
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#include "res/tfx.fx"
#include "res/convert.fx"
#include "res/interlace.fx"
#include "res/merge.fx"
#include "res/fxaa.fx"
#include "res/shadeboost.fx"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
// clang-format on

View File

@ -16,9 +16,7 @@
#include "PrecompiledHeader.h"
#include "GSOsdManager.h"
#include "GS/GS.h"
#ifdef _WIN32
#include "GS/resource.h"
#endif
#include "Host.h"
#if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 4)
#include <codecvt>
@ -31,8 +29,12 @@ void GSOsdManager::LoadFont()
if (error)
{
FT_Error error_load_res = 1;
if (theApp.LoadResource(IDR_FONT_ROBOTO, resource_data_buffer))
error_load_res = FT_New_Memory_Face(m_library, (const FT_Byte*)resource_data_buffer.data(), resource_data_buffer.size(), 0, &m_face);
auto buffer = Host::ReadResourceFile("fonts/Roboto-Regular.ttf");
if (buffer.has_value())
{
resource_data_buffer = std::move(*buffer);
error_load_res = FT_New_Memory_Face(m_library, resource_data_buffer.data(), resource_data_buffer.size(), 0, &m_face);
}
if (error_load_res)
{

View File

@ -94,5 +94,5 @@ public:
size_t GeneratePrimitives(GSVertexPT1* dst, size_t count);
private:
std::vector<char> resource_data_buffer;
std::vector<u8> resource_data_buffer;
};

View File

@ -19,7 +19,7 @@
#include "GS/Renderers/DX11/D3D.h"
#include "GS/GSExtra.h"
#include "GS/GSUtil.h"
#include "GS/resource.h"
#include "Host.h"
#include <fstream>
#include <sstream>
#include <VersionHelpers.h>
@ -218,6 +218,11 @@ bool GSDevice11::Create(const WindowInfo& wi)
m_hack_topleft_offset = (m_upscale_multiplier != 1 && D3D::IsNvidia(adapter.get()) && !disable_safe_features) ? -0.01f : 0.0f;
}
std::optional<std::string> shader = Host::ReadResourceFileToString("gs_dx11/tfx.fx");
if (!shader.has_value())
return false;
m_tfx_source = std::move(*shader);
// convert
D3D11_INPUT_ELEMENT_DESC il_convert[] =
@ -229,9 +234,10 @@ bool GSDevice11::Create(const WindowInfo& wi)
ShaderMacro sm_model(m_shader.model);
std::vector<char> shader;
theApp.LoadResource(IDR_CONVERT_FX, shader);
CreateShader(shader, "convert.fx", nullptr, "vs_main", sm_model.GetPtr(), &m_convert.vs, il_convert, std::size(il_convert), m_convert.il.put());
shader = Host::ReadResourceFileToString("gs_dx11/convert.fx");
if (!shader.has_value())
return false;
CreateShader(*shader, "convert.fx", nullptr, "vs_main", sm_model.GetPtr(), &m_convert.vs, il_convert, std::size(il_convert), m_convert.il.put());
ShaderMacro sm_convert(m_shader.model);
sm_convert.AddMacro("PS_SCALE_FACTOR", std::max(1, m_upscale_multiplier));
@ -240,7 +246,7 @@ bool GSDevice11::Create(const WindowInfo& wi)
for (size_t i = 0; i < std::size(m_convert.ps); i++)
{
CreateShader(shader, "convert.fx", nullptr, shaderName(static_cast<ShaderConvert>(i)), sm_convert_ptr, m_convert.ps[i].put());
CreateShader(*shader, "convert.fx", nullptr, shaderName(static_cast<ShaderConvert>(i)), sm_convert_ptr, m_convert.ps[i].put());
}
memset(&dsd, 0, sizeof(dsd));
@ -269,10 +275,13 @@ bool GSDevice11::Create(const WindowInfo& wi)
m_dev->CreateBuffer(&bd, nullptr, m_merge.cb.put());
theApp.LoadResource(IDR_MERGE_FX, shader);
shader = Host::ReadResourceFileToString("gs_dx11/merge.fx");
if (!shader.has_value())
return false;
for (size_t i = 0; i < std::size(m_merge.ps); i++)
{
CreateShader(shader, "merge.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), m_merge.ps[i].put());
CreateShader(*shader, "merge.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), m_merge.ps[i].put());
}
memset(&bsd, 0, sizeof(bsd));
@ -298,10 +307,12 @@ bool GSDevice11::Create(const WindowInfo& wi)
m_dev->CreateBuffer(&bd, nullptr, m_interlace.cb.put());
theApp.LoadResource(IDR_INTERLACE_FX, shader);
shader = Host::ReadResourceFileToString("gs_dx11/interlace.fx");
if (!shader.has_value())
return false;
for (size_t i = 0; i < std::size(m_interlace.ps); i++)
{
CreateShader(shader, "interlace.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), m_interlace.ps[i].put());
CreateShader(*shader, "interlace.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), m_interlace.ps[i].put());
}
// Shade Boost
@ -320,8 +331,10 @@ bool GSDevice11::Create(const WindowInfo& wi)
m_dev->CreateBuffer(&bd, nullptr, m_shadeboost.cb.put());
theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
CreateShader(shader, "shadeboost.fx", nullptr, "ps_main", sm_sboost.GetPtr(), m_shadeboost.ps.put());
shader = Host::ReadResourceFileToString("gs_dx11/shadeboost.fx");
if (!shader.has_value())
return false;
CreateShader(*shader, "shadeboost.fx", nullptr, "ps_main", sm_sboost.GetPtr(), m_shadeboost.ps.put());
// External fx shader
@ -925,9 +938,8 @@ void GSDevice11::DoExternalFX(GSTexture* sTex, GSTexture* dTex)
shader << fshader.rdbuf();
const std::string& s = shader.str();
std::vector<char> buff(s.begin(), s.end());
ShaderMacro sm(m_shader.model);
CreateShader(buff, shader_name.c_str(), D3D_COMPILE_STANDARD_FILE_INCLUDE, "ps_main", sm.GetPtr(), m_shaderfx.ps.put());
CreateShader(s, shader_name.c_str(), D3D_COMPILE_STANDARD_FILE_INCLUDE, "ps_main", sm.GetPtr(), m_shaderfx.ps.put());
}
catch (GSRecoverableError)
{
@ -957,10 +969,12 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex)
{
try
{
std::vector<char> shader;
theApp.LoadResource(IDR_FXAA_FX, shader);
ShaderMacro sm(m_shader.model);
CreateShader(shader, "fxaa.fx", nullptr, "ps_main", sm.GetPtr(), m_fxaa.ps.put());
std::optional<std::string> shader = Host::ReadResourceFileToString("gs_dx11/fxaa.fx");
if (shader.has_value())
{
ShaderMacro sm(m_shader.model);
CreateShader(*shader, "fxaa.fx", nullptr, "ps_main", sm.GetPtr(), m_fxaa.ps.put());
}
}
catch (GSRecoverableError)
{
@ -1399,7 +1413,7 @@ D3D_SHADER_MACRO* GSDevice11::ShaderMacro::GetPtr(void)
return (D3D_SHADER_MACRO*)mout.data();
}
void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il)
void GSDevice11::CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il)
{
HRESULT hr;
@ -1422,7 +1436,7 @@ void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, I
}
}
void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs)
void GSDevice11::CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs)
{
wil::com_ptr_nothrow<ID3DBlob> shader;
@ -1436,7 +1450,7 @@ void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, I
}
}
void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps)
void GSDevice11::CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps)
{
wil::com_ptr_nothrow<ID3DBlob> shader;
@ -1450,7 +1464,7 @@ void GSDevice11::CreateShader(const std::vector<char>& source, const char* fn, I
}
}
void GSDevice11::CompileShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, const std::string& shader_model)
void GSDevice11::CompileShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, const std::string& shader_model)
{
wil::com_ptr_nothrow<ID3DBlob> error;
@ -1461,7 +1475,7 @@ void GSDevice11::CompileShader(const std::vector<char>& source, const char* fn,
#endif
const HRESULT hr = D3DCompile(
source.data(), source.size(), fn, macro,
source.c_str(), source.size(), fn, macro,
include, entry, shader_model.c_str(),
flags, 0, shader, error.put());

View File

@ -515,6 +515,8 @@ private:
std::unique_ptr<GSTexture> m_font;
std::unique_ptr<GSTexture11> m_download_tex;
std::string m_tfx_source;
protected:
struct
{
@ -590,9 +592,9 @@ public:
operator ID3D11Device*() { return m_dev.get(); }
operator ID3D11DeviceContext*() { return m_ctx.get(); }
void CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
void CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs);
void CreateShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps);
void CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
void CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs);
void CreateShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps);
void CompileShader(const std::vector<char>& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, const std::string& shader_model);
void CompileShader(const std::string& source, const char* fn, ID3DInclude* include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, const std::string& shader_model);
};

View File

@ -114,10 +114,7 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
};
GSVertexShader11 vs;
std::vector<char> shader;
theApp.LoadResource(IDR_TFX_FX, shader);
CreateShader(shader, "tfx.fx", nullptr, "vs_main", sm.GetPtr(), &vs.vs, layout, std::size(layout), vs.il.put());
CreateShader(m_tfx_source, "tfx.fx", nullptr, "vs_main", sm.GetPtr(), &vs.vs, layout, std::size(layout), vs.il.put());
m_vs[sel] = vs;
@ -157,9 +154,7 @@ void GSDevice11::SetupGS(GSSelector sel, const GSConstantBuffer* cb)
sm.AddMacro("GS_POINT", sel.point);
sm.AddMacro("GS_LINE", sel.line);
std::vector<char> shader;
theApp.LoadResource(IDR_TFX_FX, shader);
CreateShader(shader, "tfx.fx", nullptr, "gs_main", sm.GetPtr(), gs.put());
CreateShader(m_tfx_source, "tfx.fx", nullptr, "gs_main", sm.GetPtr(), gs.put());
m_gs[sel] = gs;
}
@ -218,10 +213,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
sm.AddMacro("PS_ZCLAMP", sel.zclamp);
wil::com_ptr_nothrow<ID3D11PixelShader> ps;
std::vector<char> shader;
theApp.LoadResource(IDR_TFX_FX, shader);
CreateShader(shader, "tfx.fx", nullptr, "ps_main", sm.GetPtr(), ps.put());
CreateShader(m_tfx_source, "tfx.fx", nullptr, "ps_main", sm.GetPtr(), ps.put());
i = m_ps.try_emplace(sel, std::move(ps)).first;
}

View File

@ -18,17 +18,12 @@
#include "GSDeviceOGL.h"
#include "GLState.h"
#include "GS/GSUtil.h"
#include "Host.h"
#include <fstream>
#include <sstream>
//#define ONLY_LINES
#ifdef _WIN32
#include "GS/resource.h"
#else
#include "GS_res.h"
#endif
// TODO port those value into PerfMon API
#ifdef ENABLE_OGL_DEBUG_MEM_BW
u64 g_real_texture_upload_byte = 0;
@ -310,8 +305,6 @@ GSTexture* GSDeviceOGL::FetchSurface(GSTexture::Type type, int w, int h, GSTextu
bool GSDeviceOGL::Create(const WindowInfo& wi)
{
std::vector<char> shader;
m_gl_context = GL::Context::Create(wi, GL::Context::GetAllVersionsList());
if (!m_gl_context || !m_gl_context->MakeCurrent())
return false;
@ -329,6 +322,14 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
return false;
}
{
auto shader = Host::ReadResourceFileToString("gs_opengl/common_header.glsl");
if (!shader.has_value())
return false;
m_shader_common_header = std::move(*shader);
}
// ****************************************************************
// Debug helper
// ****************************************************************
@ -443,15 +444,17 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
m_misc_cb_cache.ScalingFactor = GSVector4i(std::max(1, theApp.GetConfigI("upscale_multiplier")));
m_convert.cb->cache_upload(&m_misc_cb_cache);
theApp.LoadResource(IDR_CONVERT_GLSL, shader);
const auto shader = Host::ReadResourceFileToString("gs_opengl/convert.glsl");
if (!shader.has_value())
return false;
vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, shader.data());
vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_common_header, shader->c_str());
m_convert.vs = vs;
for (size_t i = 0; i < std::size(m_convert.ps); i++)
{
const char* name = shaderName(static_cast<ShaderConvert>(i));
ps = m_shader->Compile("convert.glsl", name, GL_FRAGMENT_SHADER, shader.data());
ps = m_shader->Compile("convert.glsl", name, GL_FRAGMENT_SHADER, m_shader_common_header, shader->c_str());
std::string pretty_name = std::string("Convert pipe ") + name;
m_convert.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -477,11 +480,13 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
m_merge_obj.cb = new GSUniformBufferOGL("Merge UBO", g_merge_cb_index, sizeof(MergeConstantBuffer));
theApp.LoadResource(IDR_MERGE_GLSL, shader);
const auto shader = Host::ReadResourceFileToString("gs_opengl/merge.glsl");
if (!shader.has_value())
return false;
for (size_t i = 0; i < std::size(m_merge_obj.ps); i++)
{
ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, m_shader_common_header, shader->c_str());
std::string pretty_name = "Merge pipe " + std::to_string(i);
m_merge_obj.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -495,11 +500,13 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
m_interlace.cb = new GSUniformBufferOGL("Interlace UBO", g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
theApp.LoadResource(IDR_INTERLACE_GLSL, shader);
const auto shader = Host::ReadResourceFileToString("gs_opengl/interlace.glsl");
if (!shader.has_value())
return false;
for (size_t i = 0; i < std::size(m_interlace.ps); i++)
{
ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, m_shader_common_header, shader->c_str());
std::string pretty_name = "Interlace pipe " + std::to_string(i);
m_interlace.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
}
@ -518,9 +525,11 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
+ format("#define SB_BRIGHTNESS %d.0\n", ShadeBoost_Brightness)
+ format("#define SB_CONTRAST %d.0\n", ShadeBoost_Contrast);
theApp.LoadResource(IDR_SHADEBOOST_GLSL, shader);
const auto shader = Host::ReadResourceFileToString("gs_opengl/shadeboost.glsl");
if (!shader.has_value())
return false;
ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, shader.data(), shade_macro);
ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, shader->c_str(), shade_macro);
m_shadeboost.ps = m_shader->LinkPipeline("ShadeBoost pipe", vs, 0, ps);
}
@ -569,7 +578,8 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
// ****************************************************************
// HW renderer shader
// ****************************************************************
CreateTextureFX();
if (!CreateTextureFX())
return false;
// ****************************************************************
// Pbo Pool allocation
@ -640,12 +650,17 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
return true;
}
void GSDeviceOGL::CreateTextureFX()
bool GSDeviceOGL::CreateTextureFX()
{
GL_PUSH("GSDeviceOGL::CreateTextureFX");
theApp.LoadResource(IDR_TFX_VGS_GLSL, m_shader_tfx_vgs);
theApp.LoadResource(IDR_TFX_FS_GLSL, m_shader_tfx_fs);
auto vertex_shader = Host::ReadResourceFileToString("gs_opengl/tfx_vgs.glsl");
auto fragment_shader = Host::ReadResourceFileToString("gs_opengl/tfx_fs.glsl");
if (!vertex_shader.has_value() || !fragment_shader.has_value())
return false;
m_shader_tfx_vgs = std::move(*vertex_shader);
m_shader_tfx_fs = std::move(*fragment_shader);
// warning 1 sampler by image unit. So you cannot reuse m_ps_ss...
m_palette_ss = CreateSampler(PSSamplerSelector(0));
@ -672,6 +687,7 @@ void GSDeviceOGL::CreateTextureFX()
// Help to debug FS in apitrace
m_apitrace = CompilePS(PSSelector());
return true;
}
bool GSDeviceOGL::Reset(int w, int h)
@ -993,9 +1009,9 @@ GLuint GSDeviceOGL::CompileVS(VSSelector sel)
std::string macro = format("#define VS_INT_FST %d\n", sel.int_fst);
if (GLLoader::buggy_sso_dual_src)
return m_shader->CompileShader("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_tfx_vgs.data(), macro);
return m_shader->CompileShader("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_common_header, m_shader_tfx_vgs.data(), macro);
else
return m_shader->Compile("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_tfx_vgs.data(), macro);
return m_shader->Compile("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, m_shader_common_header, m_shader_tfx_vgs.data(), macro);
}
GLuint GSDeviceOGL::CompileGS(GSSelector sel)
@ -1004,9 +1020,9 @@ GLuint GSDeviceOGL::CompileGS(GSSelector sel)
+ 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, m_shader_tfx_vgs.data(), macro);
return m_shader->CompileShader("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, m_shader_common_header, m_shader_tfx_vgs.data(), macro);
else
return m_shader->Compile("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, m_shader_tfx_vgs.data(), macro);
return m_shader->Compile("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, m_shader_common_header, m_shader_tfx_vgs.data(), macro);
}
GLuint GSDeviceOGL::CompilePS(PSSelector sel)
@ -1052,9 +1068,9 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
;
if (GLLoader::buggy_sso_dual_src)
return m_shader->CompileShader("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_tfx_fs.data(), macro);
return m_shader->CompileShader("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, m_shader_tfx_fs.data(), macro);
else
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_tfx_fs.data(), macro);
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, m_shader_tfx_fs.data(), macro);
}
void GSDeviceOGL::SelfShaderTestRun(const std::string& dir, const std::string& file, const PSSelector& sel, int& nb_shader)
@ -1596,10 +1612,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";
std::vector<char> shader;
theApp.LoadResource(IDR_FXAA_FX, shader);
std::optional<std::string> shader = Host::ReadResourceFileToString("gs_opengl/fxaa.fx");
if (!shader.has_value())
return;
GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, shader.data(), fxaa_macro);
GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, shader->c_str(), fxaa_macro);
m_fxaa.ps = m_shader->LinkPipeline("FXAA pipe", m_convert.vs, 0, ps);
}
@ -1646,7 +1663,7 @@ void GSDeviceOGL::DoExternalFX(GSTexture* sTex, GSTexture* dTex)
m_shaderfx.cb = new GSUniformBufferOGL("eFX UBO", g_fx_cb_index, sizeof(ExternalFXConstantBuffer));
GLuint ps = m_shader->Compile("Extra", "ps_main", GL_FRAGMENT_SHADER, shader.str().c_str(), config.str());
GLuint ps = m_shader->Compile("Extra", "ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, shader.str().c_str(), config.str());
m_shaderfx.ps = m_shader->LinkPipeline("eFX pipie", m_convert.vs, 0, ps);
}

View File

@ -472,8 +472,9 @@ private:
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;
std::string m_shader_common_header;
std::string m_shader_tfx_vgs;
std::string m_shader_tfx_fs;
GLuint m_fbo; // frame buffer container
GLuint m_fbo_read; // frame buffer container only for reading
@ -633,7 +634,7 @@ public:
bool HasColorSparse() final { return GLLoader::found_compatible_GL_ARB_sparse_texture2; }
bool HasDepthSparse() final { return GLLoader::found_compatible_sparse_depth; }
void CreateTextureFX();
bool CreateTextureFX();
GLuint CompileVS(VSSelector sel);
GLuint CompileGS(GSSelector sel);
GLuint CompilePS(PSSelector sel);

View File

@ -18,18 +18,11 @@
#include "GLState.h"
#include "GS/GS.h"
#ifdef _WIN32
#include "GS/resource.h"
#else
#include "GS_res.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);
@ -272,7 +265,7 @@ std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, co
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 GSShaderOGL::Compile(const char* glsl_file, const std::string& entry, GLenum type, const std::string& common_header, const char* glsl_h_code, const std::string& macro_sel /* = "" */)
{
ASSERT(glsl_h_code != NULL);
@ -286,7 +279,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] = m_common_header.data();
sources[1] = common_header.c_str();
sources[2] = glsl_h_code;
program = glCreateShaderProgramv(type, shader_nb, sources);
@ -296,7 +289,7 @@ GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& ent
if (!status)
{
// print extra info
fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file.c_str(), entry.c_str(), program);
fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file, entry.c_str(), program);
fprintf(stderr, "\n%s", macro_sel.c_str());
fprintf(stderr, "\n");
}
@ -307,7 +300,7 @@ GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& ent
}
// Same as above but for not-separated build
GLuint GSShaderOGL::CompileShader(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel)
GLuint GSShaderOGL::CompileShader(const char* glsl_file, const std::string& entry, GLenum type, const std::string& common_header, const char* glsl_h_code, const std::string& macro_sel /* = "" */)
{
ASSERT(glsl_h_code != NULL);
@ -321,7 +314,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] = m_common_header.data();
sources[1] = common_header.data();
sources[2] = glsl_h_code;
shader = glCreateShader(type);
@ -333,7 +326,7 @@ GLuint GSShaderOGL::CompileShader(const std::string& glsl_file, const std::strin
if (!status)
{
// print extra info
fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file.c_str(), entry.c_str(), shader);
fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file, entry.c_str(), shader);
fprintf(stderr, "\n%s", macro_sel.c_str());
fprintf(stderr, "\n");
}

View File

@ -33,7 +33,6 @@ 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);
@ -42,14 +41,14 @@ public:
void BindPipeline(GLuint vs, GLuint gs, GLuint ps);
void BindPipeline(GLuint pipe);
GLuint Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel = "");
GLuint Compile(const char* glsl_file, const std::string& entry, GLenum type, const std::string& common_header, const char* glsl_h_code, const std::string& macro_sel = "");
GLuint LinkPipeline(const std::string& pretty_print, GLuint vs, GLuint gs, GLuint ps);
// Same as above but for not separated build
void BindProgram(GLuint vs, GLuint gs, GLuint ps);
void BindProgram(GLuint p);
GLuint CompileShader(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel = "");
GLuint CompileShader(const char* glsl_file, const std::string& entry, GLenum type, const std::string& common_header, const char* glsl_h_code, const std::string& macro_sel = "");
GLuint LinkProgram(GLuint vs, GLuint gs, GLuint ps);
int DumpAsm(const std::string& file, GLuint p);

View File

@ -29,7 +29,7 @@ GSDialog::GSDialog(UINT id)
INT_PTR GSDialog::DoModal()
{
return DialogBoxParam(theApp.GetModuleHandle(), MAKEINTRESOURCE(m_id), GetActiveWindow(), DialogProc, (LPARAM)this);
return DialogBoxParam(GetModuleHandle(nullptr), MAKEINTRESOURCE(m_id), GetActiveWindow(), DialogProc, (LPARAM)this);
}
INT_PTR CALLBACK GSDialog::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
@ -324,7 +324,7 @@ void GSDialog::AddTooltip(UINT id)
HWND hwndTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
TTS_ALWAYSTIP | TTS_NOPREFIX,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
m_hWnd, NULL, theApp.GetModuleHandle(), NULL);
m_hWnd, NULL, GetModuleHandle(nullptr), NULL);
if (hwndTip == NULL)
return;

View File

@ -98,18 +98,4 @@ enum
IDC_SHADER_FX,
IDC_FXAA,
IDC_LINEAR_PRESENT,
#ifndef _WIN32
// 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,
// Fonts
IDR_FONT_ROBOTO,
#endif
};

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/GS/res/">
<file>glsl/common_header.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/convert.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>fxaa.fx</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/interlace.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/merge.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/shadeboost.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/tfx_vgs.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>glsl/tfx_fs.glsl</file>
</gresource>
<gresource prefix="/GS/res/">
<file>fonts-roboto/Roboto-Regular.ttf</file>
</gresource>
</gresources>

View File

@ -14,24 +14,9 @@
#define IDC_CONFIGURE 2096
#define IDC_COLORSPACE 2097
#define IDR_CONVERT_FX 10000
#define IDR_TFX_FX 10001
#define IDR_MERGE_FX 10002
#define IDR_INTERLACE_FX 10003
#define IDR_FXAA_FX 10004
#define IDD_SHADER 10006
#define IDR_SHADEBOOST_FX 10007
#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 IDR_FONT_ROBOTO 10018
#define IDC_STATIC -1
// Next default values for new objects