Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #471 from Sonicadvance1/sampler_binding
Support Sampler binding in the shader.
  • Loading branch information
delroth committed Jul 18, 2014
2 parents b9dc691 + bc9ef95 commit 5646ffd
Show file tree
Hide file tree
Showing 51 changed files with 74 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/16bit.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/32bit.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/FXAA.glsl
Expand Up @@ -12,7 +12,7 @@

// 0. You just DO WHAT THE FUCK YOU WANT TO.

uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
4 changes: 2 additions & 2 deletions Data/Sys/Shaders/README.txt
@@ -1,5 +1,5 @@
//dummy shader:
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand All @@ -15,4 +15,4 @@ For best results, turn Wordwrap formatting on...
The shaders shown in the dropdown box in the video plugin configuration window are kept in the directory named User/Data/Shaders. They are linked in to the dolphin source from the repository at <http://dolphin-shaders-database.googlecode.com/svn/trunk/>. See <http://code.google.com/p/dolphin-shaders-database/wiki/Documentation> for more details on the way shaders work.

This file will hopefully hold more content in future...
*/
*/
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/acidmetal.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/acidtrip.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/acidtrip2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
4 changes: 2 additions & 2 deletions Data/Sys/Shaders/asciiart.glsl
@@ -1,6 +1,6 @@
// textures
uniform sampler2D samp8;
uniform sampler2D samp9;
SAMPLER_BINDING(8) uniform sampler2D samp8;
SAMPLER_BINDING(9) uniform sampler2D samp9;

const int char_width = 8;
const int char_height = 13;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/auto_toon.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/auto_toon2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/bad_bloom.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/brighten.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/chrismas.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/cool1.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/darkerbrighter.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/emboss.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/fire.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/fire2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/firewater.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/grayscale.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/grayscale2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/invert.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/invert_blue.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/invertedoutline.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/mad_world.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/nightvision.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/nightvision2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/nightvision2scanlines.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/posterize.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/posterize2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/primarycolors.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/sepia.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/sketchy.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/spookey1.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/spookey2.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/stereoscopic.glsl
@@ -1,7 +1,7 @@
// Omega's 3D Stereoscopic filtering
// TODO: Need depth info!

uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/stereoscopic2.glsl
@@ -1,7 +1,7 @@
// Omega's 3D Stereoscopic filtering (Amber/Blue)
// TODO: Need depth info!

uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/sunset.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/swap_RGB_BGR.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/swap_RGB_BRG.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/swap_RGB_GBR.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/swap_RGB_GRB.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/swap_RGB_RBG.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
2 changes: 1 addition & 1 deletion Data/Sys/Shaders/toxic.glsl
@@ -1,4 +1,4 @@
uniform sampler2D samp9;
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/OGL/FramebufferManager.cpp
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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"
Expand Down
31 changes: 16 additions & 15 deletions Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
Expand Up @@ -61,33 +61,32 @@ 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");

if (PSBlock_id != -1)
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()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;" : ""
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/RasterFont.cpp
Expand Up @@ -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"
Expand Down

0 comments on commit 5646ffd

Please sign in to comment.