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 <ian.d.romanick@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user