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 | |
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')
-rw-r--r-- | src/mesa/program/ir_to_mesa.cpp | 15 | ||||
-rw-r--r-- | src/mesa/program/sampler.cpp | 20 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index b3b55a5247c..a5b6699c2b6 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2404,8 +2404,10 @@ print_program(struct prog_instruction *mesa_instructions, class add_uniform_to_shader : public program_resource_visitor { public: add_uniform_to_shader(struct gl_shader_program *shader_program, - struct gl_program_parameter_list *params) - : shader_program(shader_program), params(params), idx(-1) + struct gl_program_parameter_list *params, + gl_shader_type shader_type) + : shader_program(shader_program), params(params), idx(-1), + shader_type(shader_type) { /* empty */ } @@ -2425,6 +2427,7 @@ private: struct gl_shader_program *shader_program; struct gl_program_parameter_list *params; int idx; + gl_shader_type shader_type; }; void @@ -2471,8 +2474,11 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name, struct gl_uniform_storage *storage = &this->shader_program->UniformStorage[location]; + assert(storage->sampler[shader_type].active); + for (unsigned int j = 0; j < size / 4; j++) - params->ParameterValues[index + j][0].f = storage->sampler + j; + params->ParameterValues[index + j][0].f = + storage->sampler[shader_type].index + j; } } @@ -2498,7 +2504,8 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program struct gl_program_parameter_list *params) { - add_uniform_to_shader add(shader_program, params); + add_uniform_to_shader add(shader_program, params, + _mesa_shader_type_to_index(sh->Type)); foreach_list(node, sh->ir) { ir_variable *var = ((ir_instruction *) node)->as_variable(); 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; } |