diff options
author | Marek Olšák <[email protected]> | 2013-05-13 15:46:49 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2013-05-28 13:05:30 +0200 |
commit | d4a06d77f5898726e2453ef32795a2183c033c05 (patch) | |
tree | b72e6a5743f0f7abd7d63d30151759970f67246d /src/mesa/program/sampler.cpp | |
parent | b4cb857dbfeb89d56ac0eb67ba1d7d5f65e336d4 (diff) |
mesa: fix GLSL program objects with more than 16 samplers combined
The problem is the sampler units are allocated from the same pool for all
shader stages, so if a vertex shader uses 12 samplers (0..11), the fragment
shader samplers start at index 12, leaving only 4 sampler units
for the fragment shader. The main cause is probably the fact that samplers
(texture unit -> sampler unit mapping, etc.) are tracked globally
for an entire program object.
This commit adapts the GLSL linker and core Mesa such that the sampler units
are assigned to sampler uniforms for each shader stage separately
(if a sampler uniform is used in all shader stages, it may occupy a different
sampler unit in each, and vice versa, an i-th sampler unit may refer to
a different sampler uniform in each shader stage), and the sampler-specific
variables are moved from gl_shader_program to gl_shader.
This doesn't require any driver changes, and it fixes piglit/max-samplers
for gallium and classic swrast. It also works with any number of shader
stages.
v2: - converted tabs to spaces
- added an assertion to _mesa_get_sampler_uniform_value
Reviewed-by: Ian Romanick <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/program/sampler.cpp')
-rw-r--r-- | src/mesa/program/sampler.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/mesa/program/sampler.cpp b/src/mesa/program/sampler.cpp index e3641aaa958..9b941273092 100644 --- a/src/mesa/program/sampler.cpp +++ b/src/mesa/program/sampler.cpp @@ -34,6 +34,7 @@ extern "C" { #include "main/compiler.h" #include "main/mtypes.h" #include "program/prog_parameter.h" +#include "program/program.h" } class get_sampler_name : public ir_hierarchical_visitor @@ -102,14 +103,16 @@ public: ir_dereference *last; }; -extern "C" { -int + +extern "C" int _mesa_get_sampler_uniform_value(class ir_dereference *sampler, struct gl_shader_program *shader_program, const struct gl_program *prog) { get_sampler_name getname(sampler, shader_program); + GLuint shader = _mesa_program_target_to_index(prog->Target); + sampler->accept(&getname); unsigned location; @@ -119,6 +122,15 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler, return 0; } - return shader_program->UniformStorage[location].sampler + getname.offset; -} + if (!shader_program->UniformStorage[location].sampler[shader].active) { + assert(0 && "cannot return a sampler"); + linker_error(shader_program, + "cannot return a sampler named %s, because it is not " + "used in this shader stage. This is a driver bug.\n", + getname.name); + return 0; + } + + return shader_program->UniformStorage[location].sampler[shader].index + + getname.offset; } |