glsl: Rename uniform_field_visitor to program_resource_visitor.
There's actually nothing uniform-specific in uniform_field_visitor. It is potentially useful for all kinds of program resources (in particular, future patches will use it for transform feedback varyings). This patch renames it to program_resource_visitor, and clarifies several comments, to reflect the fact that it is useful for more than just uniforms. NOTE: This is a candidate for the 9.1 branch. Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include "main/hash_table.h"
|
#include "main/hash_table.h"
|
||||||
#include "program.h"
|
#include "program.h"
|
||||||
|
|
||||||
class ubo_visitor : public uniform_field_visitor {
|
class ubo_visitor : public program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
|
ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
|
||||||
unsigned num_variables)
|
unsigned num_variables)
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
this->offset = 0;
|
this->offset = 0;
|
||||||
this->buffer_size = 0;
|
this->buffer_size = 0;
|
||||||
this->is_array_instance = strchr(name, ']') != NULL;
|
this->is_array_instance = strchr(name, ']') != NULL;
|
||||||
this->uniform_field_visitor::process(type, name);
|
this->program_resource_visitor::process(type, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned index;
|
unsigned index;
|
||||||
@@ -112,7 +112,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class count_block_size : public uniform_field_visitor {
|
class count_block_size : public program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
count_block_size() : num_active_uniforms(0)
|
count_block_size() : num_active_uniforms(0)
|
||||||
{
|
{
|
||||||
|
@@ -52,7 +52,7 @@ values_for_type(const glsl_type *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uniform_field_visitor::process(const glsl_type *type, const char *name)
|
program_resource_visitor::process(const glsl_type *type, const char *name)
|
||||||
{
|
{
|
||||||
assert(type->is_record()
|
assert(type->is_record()
|
||||||
|| (type->is_array() && type->fields.array->is_record())
|
|| (type->is_array() && type->fields.array->is_record())
|
||||||
@@ -65,7 +65,7 @@ uniform_field_visitor::process(const glsl_type *type, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uniform_field_visitor::process(ir_variable *var)
|
program_resource_visitor::process(ir_variable *var)
|
||||||
{
|
{
|
||||||
const glsl_type *t = var->type;
|
const glsl_type *t = var->type;
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ uniform_field_visitor::process(ir_variable *var)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uniform_field_visitor::recursion(const glsl_type *t, char **name,
|
program_resource_visitor::recursion(const glsl_type *t, char **name,
|
||||||
size_t name_length, bool row_major)
|
size_t name_length, bool row_major)
|
||||||
{
|
{
|
||||||
/* Records need to have each field processed individually.
|
/* Records need to have each field processed individually.
|
||||||
@@ -110,7 +110,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
|
|||||||
if (t->fields.structure[i].type->is_record())
|
if (t->fields.structure[i].type->is_record())
|
||||||
this->visit_field(&t->fields.structure[i]);
|
this->visit_field(&t->fields.structure[i]);
|
||||||
|
|
||||||
/* Append '.field' to the current uniform name. */
|
/* Append '.field' to the current variable name. */
|
||||||
if (name_length == 0) {
|
if (name_length == 0) {
|
||||||
ralloc_asprintf_rewrite_tail(name, &new_length, "%s", field);
|
ralloc_asprintf_rewrite_tail(name, &new_length, "%s", field);
|
||||||
} else {
|
} else {
|
||||||
@@ -125,7 +125,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
|
|||||||
for (unsigned i = 0; i < t->length; i++) {
|
for (unsigned i = 0; i < t->length; i++) {
|
||||||
size_t new_length = name_length;
|
size_t new_length = name_length;
|
||||||
|
|
||||||
/* Append the subscript to the current uniform name */
|
/* Append the subscript to the current variable name */
|
||||||
ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i);
|
ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i);
|
||||||
|
|
||||||
recursion(t->fields.array, name, new_length,
|
recursion(t->fields.array, name, new_length,
|
||||||
@@ -137,7 +137,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uniform_field_visitor::visit_field(const glsl_struct_field *field)
|
program_resource_visitor::visit_field(const glsl_struct_field *field)
|
||||||
{
|
{
|
||||||
(void) field;
|
(void) field;
|
||||||
/* empty */
|
/* empty */
|
||||||
@@ -153,7 +153,7 @@ uniform_field_visitor::visit_field(const glsl_struct_field *field)
|
|||||||
* If the same uniform is added multiple times (i.e., once for each shader
|
* If the same uniform is added multiple times (i.e., once for each shader
|
||||||
* target), it will only be accounted once.
|
* target), it will only be accounted once.
|
||||||
*/
|
*/
|
||||||
class count_uniform_size : public uniform_field_visitor {
|
class count_uniform_size : public program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
count_uniform_size(struct string_to_uint_map *map)
|
count_uniform_size(struct string_to_uint_map *map)
|
||||||
: num_active_uniforms(0), num_values(0), num_shader_samplers(0),
|
: num_active_uniforms(0), num_values(0), num_shader_samplers(0),
|
||||||
@@ -171,10 +171,10 @@ public:
|
|||||||
void process(ir_variable *var)
|
void process(ir_variable *var)
|
||||||
{
|
{
|
||||||
if (var->is_interface_instance())
|
if (var->is_interface_instance())
|
||||||
uniform_field_visitor::process(var->interface_type,
|
program_resource_visitor::process(var->interface_type,
|
||||||
var->interface_type->name);
|
var->interface_type->name);
|
||||||
else
|
else
|
||||||
uniform_field_visitor::process(var);
|
program_resource_visitor::process(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,7 +258,7 @@ private:
|
|||||||
* the \c gl_uniform_storage and \c gl_constant_value arrays are "big
|
* the \c gl_uniform_storage and \c gl_constant_value arrays are "big
|
||||||
* enough."
|
* enough."
|
||||||
*/
|
*/
|
||||||
class parcel_out_uniform_storage : public uniform_field_visitor {
|
class parcel_out_uniform_storage : public program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
parcel_out_uniform_storage(struct string_to_uint_map *map,
|
parcel_out_uniform_storage(struct string_to_uint_map *map,
|
||||||
struct gl_uniform_storage *uniforms,
|
struct gl_uniform_storage *uniforms,
|
||||||
|
@@ -61,38 +61,39 @@ link_uniform_blocks(void *mem_ctx,
|
|||||||
struct gl_uniform_block **blocks_ret);
|
struct gl_uniform_block **blocks_ret);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for processing all of the leaf fields of an uniform
|
* Class for processing all of the leaf fields of a variable that corresponds
|
||||||
|
* to a program resource.
|
||||||
*
|
*
|
||||||
* Leaves are, roughly speaking, the parts of the uniform that the application
|
* The leaf fields are all the parts of the variable that the application
|
||||||
* could query with \c glGetUniformLocation (or that could be returned by
|
* could query using \c glGetProgramResourceIndex (or that could be returned
|
||||||
* \c glGetActiveUniforms).
|
* by \c glGetProgramResourceName).
|
||||||
*
|
*
|
||||||
* Classes my derive from this class to implement specific functionality.
|
* Classes my derive from this class to implement specific functionality.
|
||||||
* This class only provides the mechanism to iterate over the leaves. Derived
|
* This class only provides the mechanism to iterate over the leaves. Derived
|
||||||
* classes must implement \c ::visit_field and may override \c ::process.
|
* classes must implement \c ::visit_field and may override \c ::process.
|
||||||
*/
|
*/
|
||||||
class uniform_field_visitor {
|
class program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Begin processing a uniform
|
* Begin processing a variable
|
||||||
*
|
*
|
||||||
* Classes that overload this function should call \c ::process from the
|
* Classes that overload this function should call \c ::process from the
|
||||||
* base class to start the recursive processing of the uniform.
|
* base class to start the recursive processing of the variable.
|
||||||
*
|
*
|
||||||
* \param var The uniform variable that is to be processed
|
* \param var The variable that is to be processed
|
||||||
*
|
*
|
||||||
* Calls \c ::visit_field for each leaf of the uniform.
|
* Calls \c ::visit_field for each leaf of the variable.
|
||||||
*
|
*
|
||||||
* \warning
|
* \warning
|
||||||
* This entry should only be used with uniform blocks in cases where the
|
* When processing a uniform block, this entry should only be used in cases
|
||||||
* row / column ordering of matrices in the block does not matter. For
|
* where the row / column ordering of matrices in the block does not
|
||||||
* example, enumerating the names of members of the block, but not for
|
* matter. For example, enumerating the names of members of the block, but
|
||||||
* determining the offsets of members.
|
* not for determining the offsets of members.
|
||||||
*/
|
*/
|
||||||
void process(ir_variable *var);
|
void process(ir_variable *var);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin processing a uniform of a structured type.
|
* Begin processing a variable of a structured type.
|
||||||
*
|
*
|
||||||
* This flavor of \c process should be used to handle structured types
|
* This flavor of \c process should be used to handle structured types
|
||||||
* (i.e., structures, interfaces, or arrays there of) that need special
|
* (i.e., structures, interfaces, or arrays there of) that need special
|
||||||
@@ -100,7 +101,7 @@ public:
|
|||||||
* (instead of the instance name) is used for an interface block.
|
* (instead of the instance name) is used for an interface block.
|
||||||
*
|
*
|
||||||
* \param type Type that is to be processed, associated with \c name
|
* \param type Type that is to be processed, associated with \c name
|
||||||
* \param name Base name of the structured uniform being processed
|
* \param name Base name of the structured variable being processed
|
||||||
*
|
*
|
||||||
* \note
|
* \note
|
||||||
* \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
|
* \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
|
||||||
@@ -110,7 +111,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Method invoked for each leaf of the uniform
|
* Method invoked for each leaf of the variable
|
||||||
*
|
*
|
||||||
* \param type Type of the field.
|
* \param type Type of the field.
|
||||||
* \param name Fully qualified name of the field.
|
* \param name Fully qualified name of the field.
|
||||||
|
@@ -2375,7 +2375,7 @@ print_program(struct prog_instruction *mesa_instructions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class add_uniform_to_shader : public uniform_field_visitor {
|
class add_uniform_to_shader : public program_resource_visitor {
|
||||||
public:
|
public:
|
||||||
add_uniform_to_shader(struct gl_shader_program *shader_program,
|
add_uniform_to_shader(struct gl_shader_program *shader_program,
|
||||||
struct gl_program_parameter_list *params)
|
struct gl_program_parameter_list *params)
|
||||||
@@ -2387,7 +2387,7 @@ public:
|
|||||||
void process(ir_variable *var)
|
void process(ir_variable *var)
|
||||||
{
|
{
|
||||||
this->idx = -1;
|
this->idx = -1;
|
||||||
this->uniform_field_visitor::process(var);
|
this->program_resource_visitor::process(var);
|
||||||
|
|
||||||
var->location = this->idx;
|
var->location = this->idx;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user