Advertisement
Guest User

GSDX Load Shader File

a guest
Sep 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.30 KB | None | 0 0
  1. diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp
  2. index 9b1f1bfe6..ff978fd1b 100644
  3. --- a/plugins/GSdx/GSDevice11.cpp
  4. +++ b/plugins/GSdx/GSDevice11.cpp
  5. @@ -186,7 +186,8 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
  6.     };
  7.  
  8.     std::vector<char> shader;
  9. -   theApp.LoadResource(IDR_CONVERT_FX, shader);
  10. +  
  11. +   if(!theApp.LoadFile("convert.fx", shader)) theApp.LoadResource(IDR_CONVERT_FX, shader);
  12.     CompileShader(shader.data(), shader.size(), "convert.fx", nullptr, "vs_main", nullptr, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
  13.  
  14.     for(size_t i = 0; i < countof(m_convert.ps); i++)
  15. @@ -217,7 +218,7 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
  16.  
  17.     hr = m_dev->CreateBuffer(&bd, NULL, &m_merge.cb);
  18.  
  19. -   theApp.LoadResource(IDR_MERGE_FX, shader);
  20. +   if(!theApp.LoadFile("merge.fx", shader)) theApp.LoadResource(IDR_MERGE_FX, shader);
  21.     for(size_t i = 0; i < countof(m_merge.ps); i++)
  22.     {
  23.         CompileShader(shader.data(), shader.size(), "merge.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_merge.ps[i]);
  24. @@ -246,7 +247,7 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
  25.  
  26.     hr = m_dev->CreateBuffer(&bd, NULL, &m_interlace.cb);
  27.  
  28. -   theApp.LoadResource(IDR_INTERLACE_FX, shader);
  29. +   if(!theApp.LoadFile("interlace.fx", shader)) theApp.LoadResource(IDR_INTERLACE_FX, shader);
  30.     for(size_t i = 0; i < countof(m_interlace.ps); i++)
  31.     {
  32.         CompileShader(shader.data(), shader.size(), "interlace.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_interlace.ps[i]);
  33. @@ -280,7 +281,7 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
  34.  
  35.     hr = m_dev->CreateBuffer(&bd, NULL, &m_shadeboost.cb);
  36.  
  37. -   theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
  38. +   if(!theApp.LoadFile("shadeboost.fx", shader)) theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
  39.     CompileShader(shader.data(), shader.size(), "shadeboost.fx", nullptr, "ps_main", macro, &m_shadeboost.ps);
  40.  
  41.     // External fx shader
  42. @@ -834,7 +835,7 @@ void GSDevice11::InitFXAA()
  43.     {
  44.         try {
  45.             std::vector<char> shader;
  46. -           theApp.LoadResource(IDR_FXAA_FX, shader);
  47. +           if(!theApp.LoadFile("fxaa.fx", shader)) theApp.LoadResource(IDR_FXAA_FX, shader);
  48.             CompileShader(shader.data(), shader.size(), "fxaa.fx", nullptr, "ps_main", nullptr, &m_fxaa.ps);
  49.         }
  50.         catch (GSDXRecoverableError) {
  51. diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp
  52. index cbc806910..304e011ae 100644
  53. --- a/plugins/GSdx/GSDevice9.cpp
  54. +++ b/plugins/GSdx/GSDevice9.cpp
  55. @@ -291,7 +291,7 @@ bool GSDevice9::Create(const std::shared_ptr<GSWnd> &wnd)
  56.     };
  57.  
  58.     std::vector<char> shader;
  59. -   theApp.LoadResource(IDR_CONVERT_FX, shader);
  60. +   if(!theApp.LoadFile("convert.fx", shader)) theApp.LoadResource(IDR_CONVERT_FX, shader);
  61.     CompileShader(shader.data(), shader.size(), "convert.fx", "vs_main", nullptr, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
  62.  
  63.     for(size_t i = 0; i < countof(m_convert.ps); i++)
  64. @@ -325,7 +325,7 @@ bool GSDevice9::Create(const std::shared_ptr<GSWnd> &wnd)
  65.  
  66.     // merge
  67.  
  68. -   theApp.LoadResource(IDR_MERGE_FX, shader);
  69. +   if(!theApp.LoadFile("merge.fx", shader)) theApp.LoadResource(IDR_MERGE_FX, shader);
  70.     for(size_t i = 0; i < countof(m_merge.ps); i++)
  71.     {
  72.         CompileShader(shader.data(), shader.size(), "merge.fx", format("ps_main%d", i), nullptr, &m_merge.ps[i]);
  73. @@ -342,7 +342,7 @@ bool GSDevice9::Create(const std::shared_ptr<GSWnd> &wnd)
  74.  
  75.     // interlace
  76.  
  77. -   theApp.LoadResource(IDR_INTERLACE_FX, shader);
  78. +   if(!theApp.LoadFile("interlace.fx", shader)) theApp.LoadResource(IDR_INTERLACE_FX, shader);
  79.     for(size_t i = 0; i < countof(m_interlace.ps); i++)
  80.     {
  81.         CompileShader(shader.data(), shader.size(), "interlace.fx", format("ps_main%d", i), nullptr, &m_interlace.ps[i]);
  82. @@ -368,7 +368,7 @@ bool GSDevice9::Create(const std::shared_ptr<GSWnd> &wnd)
  83.         {NULL, NULL},
  84.     };
  85.  
  86. -   theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
  87. +   if(!theApp.LoadFile("shadeboost.fx", shader)) theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
  88.     CompileShader(shader.data(), shader.size(), "shadeboost.fx", "ps_main", macro, &m_shadeboost.ps);
  89.  
  90.     // create shader layout
  91. @@ -997,7 +997,7 @@ void GSDevice9::InitFXAA()
  92.     {
  93.         try {
  94.             std::vector<char> shader;
  95. -           theApp.LoadResource(IDR_FXAA_FX, shader);
  96. +           if(!theApp.LoadFile("fxaa.fx", shader)) theApp.LoadResource(IDR_FXAA_FX, shader);
  97.             CompileShader(shader.data(), shader.size(), "fxaa.fx", "ps_main", nullptr, &m_fxaa.ps);
  98.         }
  99.         catch (GSDXRecoverableError) {
  100. diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp
  101. index edef23e95..4e44614d5 100644
  102. --- a/plugins/GSdx/GSDeviceOGL.cpp
  103. +++ b/plugins/GSdx/GSDeviceOGL.cpp
  104. @@ -384,7 +384,7 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
  105.         m_misc_cb_cache.ScalingFactor = GSVector4i(theApp.GetConfigI("upscale_multiplier"));
  106.         m_convert.cb->cache_upload(&m_misc_cb_cache);
  107.  
  108. -       theApp.LoadResource(IDR_CONVERT_GLSL, shader);
  109. +       if(!theApp.LoadFile("convert.glsl", m_shader_tfx_fs)) theApp.LoadResource(IDR_CONVERT_GLSL, shader);
  110.  
  111.         vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, shader.data());
  112.  
  113. @@ -416,7 +416,7 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
  114.  
  115.         m_merge_obj.cb = new GSUniformBufferOGL("Merge UBO", g_merge_cb_index, sizeof(MergeConstantBuffer));
  116.  
  117. -       theApp.LoadResource(IDR_MERGE_GLSL, shader);
  118. +       if(!theApp.LoadFile("merge.glsl", m_shader_tfx_fs)) theApp.LoadResource(IDR_MERGE_GLSL, shader);
  119.  
  120.         for(size_t i = 0; i < countof(m_merge_obj.ps); i++) {
  121.             ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
  122. @@ -433,7 +433,7 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
  123.  
  124.         m_interlace.cb = new GSUniformBufferOGL("Interlace UBO", g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
  125.  
  126. -       theApp.LoadResource(IDR_INTERLACE_GLSL, shader);
  127. +       if(!theApp.LoadFile("interlace.glsl", m_shader_tfx_fs)) theApp.LoadResource(IDR_INTERLACE_GLSL, shader);
  128.  
  129.         for(size_t i = 0; i < countof(m_interlace.ps); i++) {
  130.             ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, shader.data());
  131. @@ -455,7 +455,7 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
  132.             + format("#define SB_BRIGHTNESS %d.0\n", ShadeBoost_Brightness)
  133.             + format("#define SB_CONTRAST %d.0\n", ShadeBoost_Contrast);
  134.  
  135. -       theApp.LoadResource(IDR_SHADEBOOST_GLSL, shader);
  136. +       if(!theApp.LoadFile("shadeboost.glsl", m_shader_tfx_fs)) theApp.LoadResource(IDR_SHADEBOOST_GLSL, shader);
  137.  
  138.         ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, shader.data(), shade_macro);
  139.         m_shadeboost.ps = m_shader->LinkPipeline("ShadeBoost pipe", vs, 0, ps);
  140. @@ -577,8 +577,8 @@ void GSDeviceOGL::CreateTextureFX()
  141.     m_vs_cb = new GSUniformBufferOGL("HW VS UBO", g_vs_cb_index, sizeof(VSConstantBuffer));
  142.     m_ps_cb = new GSUniformBufferOGL("HW PS UBO", g_ps_cb_index, sizeof(PSConstantBuffer));
  143.  
  144. -   theApp.LoadResource(IDR_TFX_VGS_GLSL, m_shader_tfx_vgs);
  145. -   theApp.LoadResource(IDR_TFX_FS_GLSL, m_shader_tfx_fs);
  146. +   if(!theApp.LoadFile("tfx_vgs.glsl", m_shader_tfx_vgs)) theApp.LoadResource(IDR_TFX_VGS_GLSL, m_shader_tfx_vgs);
  147. +   if(!theApp.LoadFile("tfx_fs.glsl", m_shader_tfx_fs)) theApp.LoadResource(IDR_TFX_FS_GLSL, m_shader_tfx_fs);
  148.  
  149.     // warning 1 sampler by image unit. So you cannot reuse m_ps_ss...
  150.     m_palette_ss = CreateSampler(PSSamplerSelector(0));
  151. @@ -1497,7 +1497,7 @@ void GSDeviceOGL::DoFXAA(GSTexture* sTex, GSTexture* dTex)
  152.         fxaa_macro += "#extension GL_ARB_gpu_shader5 : enable\n";
  153.  
  154.         std::vector<char> shader;
  155. -       theApp.LoadResource(IDR_FXAA_FX, shader);
  156. +       if(!theApp.LoadFile("fxaa.fx", shader)) theApp.LoadResource(IDR_FXAA_FX, shader);
  157.  
  158.         GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, shader.data(), fxaa_macro);
  159.         m_fxaa.ps = m_shader->LinkPipeline("FXAA pipe", m_convert.vs, 0, ps);
  160. diff --git a/plugins/GSdx/GSRendererCL.cpp b/plugins/GSdx/GSRendererCL.cpp
  161. index 839f3932a..b6f1d98ac 100644
  162. --- a/plugins/GSdx/GSRendererCL.cpp
  163. +++ b/plugins/GSdx/GSRendererCL.cpp
  164. @@ -1931,7 +1931,7 @@ GSRendererCL::CL::CL()
  165.  
  166.     std::vector<char> buff;
  167.  
  168. -   if(theApp.LoadResource(IDR_TFX_CL, buff))
  169. +   if(theApp.LoadFile("tfx.cl", m_common_header) || theApp.LoadResource(IDR_TFX_CL, buff))
  170.     {
  171.         kernel_str = std::string(buff.data(), buff.size());
  172.     }
  173. diff --git a/plugins/GSdx/GSShaderOGL.cpp b/plugins/GSdx/GSShaderOGL.cpp
  174. index 5d8b53a1c..a89951193 100644
  175. --- a/plugins/GSdx/GSShaderOGL.cpp
  176. +++ b/plugins/GSdx/GSShaderOGL.cpp
  177. @@ -33,7 +33,7 @@ GSShaderOGL::GSShaderOGL(bool debug) :
  178.     m_pipeline(0),
  179.     m_debug_shader(debug)
  180.  {
  181. -   theApp.LoadResource(IDR_COMMON_GLSL, m_common_header);
  182. +   if(!theApp.LoadFile("common_header.glsl", m_common_header)) theApp.LoadResource(IDR_COMMON_GLSL, m_common_header);
  183.  
  184.     // Create a default pipeline
  185.     m_pipeline = LinkPipeline("HW pipe", 0, 0, 0);
  186. diff --git a/plugins/GSdx/GSTextureFX11.cpp b/plugins/GSdx/GSTextureFX11.cpp
  187. index 6f549621b..0d5097a90 100644
  188. --- a/plugins/GSdx/GSTextureFX11.cpp
  189. +++ b/plugins/GSdx/GSTextureFX11.cpp
  190. @@ -133,7 +133,7 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
  191.         GSVertexShader11 vs;
  192.  
  193.         std::vector<char> shader;
  194. -       theApp.LoadResource(IDR_TFX_FX, shader);
  195. +       if(!theApp.LoadFile("tfx.fx", shader)) theApp.LoadResource(IDR_TFX_FX, shader);
  196.         CompileShader(shader.data(), shader.size(), "tfx.fx", nullptr, "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il);
  197.  
  198.         m_vs[sel] = vs;
  199. @@ -185,7 +185,7 @@ void GSDevice11::SetupGS(GSSelector sel, const GSConstantBuffer* cb)
  200.             };
  201.  
  202.             std::vector<char> shader;
  203. -           theApp.LoadResource(IDR_TFX_FX, shader);
  204. +           if(!theApp.LoadFile("tfx.fx", shader)) theApp.LoadResource(IDR_TFX_FX, shader);
  205.             CompileShader(shader.data(), shader.size(), "tfx.fx", nullptr, "gs_main", macro, &gs);
  206.  
  207.             m_gs[sel] = gs;
  208. @@ -262,7 +262,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
  209.         CComPtr<ID3D11PixelShader> ps;
  210.  
  211.         std::vector<char> shader;
  212. -       theApp.LoadResource(IDR_TFX_FX, shader);
  213. +       if(!theApp.LoadFile("tfx.fx", shader)) theApp.LoadResource(IDR_TFX_FX, shader);
  214.         CompileShader(shader.data(), shader.size(), "tfx.fx", nullptr, "ps_main", macro, &ps);
  215.  
  216.         m_ps[sel] = ps;
  217. diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp
  218. index 586286bf2..bf6d0c342 100644
  219. --- a/plugins/GSdx/GSTextureFX9.cpp
  220. +++ b/plugins/GSdx/GSTextureFX9.cpp
  221. @@ -97,7 +97,7 @@ void GSDevice9::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
  222.         GSVertexShader9 vs;
  223.  
  224.         std::vector<char> shader;
  225. -       theApp.LoadResource(IDR_TFX_FX, shader);
  226. +       if(!theApp.LoadFile("tfx.fx", shader)) theApp.LoadResource(IDR_TFX_FX, shader);
  227.         CompileShader(shader.data(), shader.size(), "tfx.fx", "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il);
  228.  
  229.         m_vs[sel] = vs;
  230. @@ -184,7 +184,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
  231.         CComPtr<IDirect3DPixelShader9> ps;
  232.  
  233.         std::vector<char> shader;
  234. -       theApp.LoadResource(IDR_TFX_FX, shader);
  235. +       if(!theApp.LoadFile("tfx.fx", shader)) theApp.LoadResource(IDR_TFX_FX, shader);
  236.         CompileShader(shader.data(), shader.size(), "tfx.fx", "ps_main", macro, &ps);
  237.  
  238.         m_ps[sel] = ps;
  239. diff --git a/plugins/GSdx/GSdx.cpp b/plugins/GSdx/GSdx.cpp
  240. index 9ef606a84..3b41436a6 100644
  241. --- a/plugins/GSdx/GSdx.cpp
  242. +++ b/plugins/GSdx/GSdx.cpp
  243. @@ -174,6 +174,24 @@ int GSdxApp::GetPrivateProfileInt(const char* lpAppName, const char* lpKeyName,
  244.  }
  245.  #endif
  246.  
  247. +bool GSdxApp::LoadFile(const char* fn, std::vector<char>& buff)
  248. +{
  249. +   std::ifstream file(fn, std::ios::binary | std::ios::ate);
  250. +  
  251. +   if(file.is_open()) {
  252. +       size_t fsize = (size_t)file.tellg();
  253. +      
  254. +       if(fsize) {
  255. +           buff.resize(fsize);
  256. +           file.seekg(0, std::ios::beg);
  257. +           file.read(&buff[0], fsize);
  258. +           return true;
  259. +       }
  260. +   }
  261. +  
  262. +   return false;
  263. +}
  264. +
  265.  GSdxApp theApp;
  266.  
  267.  GSdxApp::GSdxApp()
  268. diff --git a/plugins/GSdx/GSdx.h b/plugins/GSdx/GSdx.h
  269. index 4cc159592..cce24c324 100644
  270. --- a/plugins/GSdx/GSdx.h
  271. +++ b/plugins/GSdx/GSdx.h
  272. @@ -54,6 +54,7 @@ public:
  273.  #endif
  274.  
  275.     bool LoadResource(int id, std::vector<char>& buff, const char* type = nullptr);
  276. +   bool LoadFile( const char* fn, std::vector<char>& buff);
  277.  
  278.     void SetConfig(const char* entry, const char* value);
  279.     void SetConfig(const char* entry, int value);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement