diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2014-07-19 01:28:37 +0200 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2014-07-19 01:28:37 +0200 |
| commit | 5646ffdacdc0221720369df464f0e7addbacbd6f (patch) | |
| tree | fafb7892fd466a3d6a54ca66641a982a316da127 /Source/Core | |
| parent | b9dc69105d0529c74a4f3c8f3579fa699f2d7bdc (diff) | |
| parent | bc9ef95643c73838800274be9afd691b542b9f1a (diff) | |
Merge pull request #471 from Sonicadvance1/sampler_binding
Support Sampler binding in the shader.
Diffstat (limited to 'Source/Core')
7 files changed, 28 insertions, 27 deletions
diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index cb21fc382f..62f112af2e 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -169,7 +169,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms { // non-msaa, so just fetch the pixel sampler = - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "vec4 sampleEFB(ivec2 pos) {\n" " return texelFetch(samp9, pos, 0);\n" "}\n"; @@ -180,7 +180,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms // This will lead to sample shading, but it's the only way to not loose // the values of each sample. sampler = - "uniform sampler2DMS samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2DMS samp9;\n" "vec4 sampleEFB(ivec2 pos) {\n" " return texelFetch(samp9, pos, gl_SampleID);\n" "}\n"; @@ -191,7 +191,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms std::stringstream samples; samples << m_msaaSamples; sampler = - "uniform sampler2DMS samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2DMS samp9;\n" "vec4 sampleEFB(ivec2 pos) {\n" " vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n" " for(int i=0; i<" + samples.str() + "; i++)\n" diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 99f3ad5485..768663f56a 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -61,12 +61,12 @@ static std::string GetGLSLVersionString() void SHADER::SetProgramVariables() { - // glsl shader must be bind to set samplers - Bind(); - - // Bind UBO + // Bind UBO and texture samplers if (!g_ActiveConfig.backend_info.bSupportsBindingLayout) { + // glsl shader must be bind to set samplers if we don't support binding layout + Bind(); + GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock"); GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock"); @@ -74,20 +74,19 @@ void SHADER::SetProgramVariables() glUniformBlockBinding(glprogid, PSBlock_id, 1); if (VSBlock_id != -1) glUniformBlockBinding(glprogid, VSBlock_id, 2); - } - // Bind Texture Sampler - for (int a = 0; a <= 9; ++a) - { - char name[8]; - snprintf(name, 8, "samp%d", a); + // Bind Texture Sampler + for (int a = 0; a <= 9; ++a) + { + char name[8]; + snprintf(name, 8, "samp%d", a); - // Still need to get sampler locations since we aren't binding them statically in the shaders - int loc = glGetUniformLocation(glprogid, name); - if (loc != -1) - glUniform1i(loc, a); + // Still need to get sampler locations since we aren't binding them statically in the shaders + int loc = glGetUniformLocation(glprogid, name); + if (loc != -1) + glUniform1i(loc, a); + } } - } void SHADER::SetProgramBindings() @@ -479,6 +478,7 @@ void ProgramShaderCache::CreateHeader ( void ) "%s\n" // 420pack "%s\n" // msaa "%s\n" // sample shading + "%s\n" // Sampler binding // Precision defines for GLSL ES "%s\n" @@ -509,6 +509,7 @@ void ProgramShaderCache::CreateHeader ( void ) , (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : "" , (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : "" , (g_ogl_config.bSupportSampleShading) ? "#extension GL_ARB_sample_shading : enable" : "" + , g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)" , v>=GLSLES_300 ? "precision highp float;" : "" , v>=GLSLES_300 ? "precision highp int;" : "" diff --git a/Source/Core/VideoBackends/OGL/RasterFont.cpp b/Source/Core/VideoBackends/OGL/RasterFont.cpp index d281f9a554..7d96e03ab8 100644 --- a/Source/Core/VideoBackends/OGL/RasterFont.cpp +++ b/Source/Core/VideoBackends/OGL/RasterFont.cpp @@ -124,7 +124,7 @@ static const char *s_vertexShaderSrc = "}\n"; static const char *s_fragmentShaderSrc = - "uniform sampler2D samp8;\n" + "SAMPLER_BINDING(8) uniform sampler2D samp8;\n" "uniform vec4 color;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 198ffda169..8b38fca25c 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -346,7 +346,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo TextureCache::TextureCache() { const char *pColorMatrixProg = - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "uniform vec4 colmat[7];\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" @@ -358,7 +358,7 @@ TextureCache::TextureCache() "}\n"; const char *pDepthMatrixProg = - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "uniform vec4 colmat[5];\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" @@ -372,7 +372,7 @@ TextureCache::TextureCache() const char *VProgram = "out vec2 uv0;\n" - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "uniform vec4 copy_position;\n" // left, top, right, bottom "void main()\n" "{\n" diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index 055a1e6d7c..7381969822 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -72,7 +72,7 @@ static void CreatePrograms() const char *VProgramRgbToYuyv = "out vec2 uv0;\n" "uniform vec4 copy_position;\n" // left, top, right, bottom - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "void main()\n" "{\n" " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" @@ -80,7 +80,7 @@ static void CreatePrograms() " uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0));\n" "}\n"; const char *FProgramRgbToYuyv = - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" "void main()\n" @@ -111,7 +111,7 @@ static void CreatePrograms() " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" "}\n"; const char *FProgramYuyvToRgb = - "uniform sampler2D samp9;\n" + "SAMPLER_BINDING(9) uniform sampler2D samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" "void main()\n" diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 630d998e24..8e90713fd0 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -204,7 +204,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T { // Declare samplers for (int i = 0; i < 8; ++i) - out.Write("uniform sampler2D samp%d;\n", i); + out.Write("SAMPLER_BINDING(%d) uniform sampler2D samp%d;\n", i, i); } else // D3D { diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index ad4dd6f1f6..76e49ce464 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -70,7 +70,7 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) if (ApiType == API_OPENGL) { WRITE(p, "#define samp0 samp9\n"); - WRITE(p, "uniform sampler2D samp0;\n"); + WRITE(p, "SAMPLER_BINDING(9) uniform sampler2D samp0;\n"); WRITE(p, " out vec4 ocol0;\n"); WRITE(p, "void main()\n"); |
