glsl: Add ir_var_shader_storage

This will be used to identify buffer variables inside shader storage
buffer objects, which are very similar to uniforms except for a few
differences, most important of which is that they are writable.

Since buffer variables are so similar to uniforms, we will almost always
want them to go through the same paths as uniforms.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
Kristian Høgsberg 2015-05-13 10:41:55 +02:00 committed by Samuel Iglesias Gonsalvez
parent 3095ee9b8b
commit 18feaa8f36
11 changed files with 34 additions and 13 deletions

View file

@ -436,11 +436,12 @@ builtin_variable_generator::add_variable(const char *name,
var->data.read_only = true;
break;
case ir_var_shader_out:
case ir_var_shader_storage:
break;
default:
/* The only variables that are added using this function should be
* uniforms, shader inputs, and shader outputs, constants (which use
* ir_var_auto), and system values.
* uniforms, shader storage, shader inputs, and shader outputs, constants
* (which use ir_var_auto), and system values.
*/
assert(0);
break;

View file

@ -36,6 +36,9 @@ public:
case ir_var_uniform:
dest = &ibu;
break;
case ir_var_shader_storage:
dest = &iss;
break;
case ir_var_shader_in:
dest = &ibi;
break;
@ -60,6 +63,8 @@ public:
switch (mode) {
case ir_var_uniform:
return ibu;
case ir_var_shader_storage:
return iss;
case ir_var_shader_in:
return ibi;
case ir_var_shader_out:
@ -71,24 +76,25 @@ public:
}
symbol_table_entry(ir_variable *v) :
v(v), f(0), t(0), ibu(0), ibi(0), ibo(0), a(0) {}
v(v), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
symbol_table_entry(ir_function *f) :
v(0), f(f), t(0), ibu(0), ibi(0), ibo(0), a(0) {}
v(0), f(f), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
symbol_table_entry(const glsl_type *t) :
v(0), f(0), t(t), ibu(0), ibi(0), ibo(0), a(0) {}
v(0), f(0), t(t), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
symbol_table_entry(const glsl_type *t, enum ir_variable_mode mode) :
v(0), f(0), t(0), ibu(0), ibi(0), ibo(0), a(0)
v(0), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0)
{
assert(t->is_interface());
add_interface(t, mode);
}
symbol_table_entry(const class ast_type_specifier *a):
v(0), f(0), t(0), ibu(0), ibi(0), ibo(0), a(a) {}
v(0), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(a) {}
ir_variable *v;
ir_function *f;
const glsl_type *t;
const glsl_type *ibu;
const glsl_type *iss;
const glsl_type *ibi;
const glsl_type *ibo;
const class ast_type_specifier *a;

View file

@ -1975,6 +1975,9 @@ mode_string(const ir_variable *var)
case ir_var_uniform:
return "uniform";
case ir_var_shader_storage:
return "buffer";
case ir_var_shader_in:
return "shader input";

View file

@ -324,6 +324,7 @@ protected:
enum ir_variable_mode {
ir_var_auto = 0, /**< Function local variables and globals. */
ir_var_uniform, /**< Variable declared as a uniform. */
ir_var_shader_storage, /**< Variable declared as an ssbo. */
ir_var_shader_in,
ir_var_shader_out,
ir_var_function_in,
@ -445,7 +446,9 @@ public:
*/
inline bool is_in_uniform_block() const
{
return this->data.mode == ir_var_uniform && this->interface_type != NULL;
return (this->data.mode == ir_var_uniform ||
this->data.mode == ir_var_shader_storage) &&
this->interface_type != NULL;
}
/**

View file

@ -72,6 +72,7 @@ parameter_lists_match(_mesa_glsl_parse_state *state,
switch ((enum ir_variable_mode)(param->data.mode)) {
case ir_var_auto:
case ir_var_uniform:
case ir_var_shader_storage:
case ir_var_temporary:
/* These are all error conditions. It is invalid for a parameter to
* a function to be declared as auto (not in, out, or inout) or

View file

@ -168,7 +168,8 @@ void ir_print_visitor::visit(ir_variable *ir)
const char *const cent = (ir->data.centroid) ? "centroid " : "";
const char *const samp = (ir->data.sample) ? "sample " : "";
const char *const inv = (ir->data.invariant) ? "invariant " : "";
const char *const mode[] = { "", "uniform ", "shader_in ", "shader_out ",
const char *const mode[] = { "", "uniform ", "shader_storage",
"shader_in ", "shader_out ",
"in ", "out ", "inout ",
"const_in ", "sys ", "temporary " };
STATIC_ASSERT(ARRAY_SIZE(mode) == ir_var_mode_count);

View file

@ -421,6 +421,8 @@ ir_reader::read_declaration(s_expression *expr)
var->data.invariant = 1;
} else if (strcmp(qualifier->value(), "uniform") == 0) {
var->data.mode = ir_var_uniform;
} else if (strcmp(qualifier->value(), "shader_storage") == 0) {
var->data.mode = ir_var_shader_storage;
} else if (strcmp(qualifier->value(), "auto") == 0) {
var->data.mode = ir_var_auto;
} else if (strcmp(qualifier->value(), "in") == 0) {

View file

@ -145,6 +145,7 @@ public:
unsupported_variable_indexing = true;
break;
case ir_var_uniform:
case ir_var_shader_storage:
if (options->EmitNoIndirectUniform)
unsupported_variable_indexing = true;
break;

View file

@ -108,7 +108,8 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
* but, this will require changes to the other uniform block
* support code.
*/
if (var->data.mode == ir_var_uniform)
if (var->data.mode == ir_var_uniform ||
var->data.mode == ir_var_shader_storage)
continue;
const glsl_type * iface_t = var->type;
@ -212,7 +213,7 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue)
* but, this will require changes to the other uniform block
* support code.
*/
if (var->data.mode == ir_var_uniform)
if (var->data.mode == ir_var_uniform || var->data.mode == ir_var_shader_storage)
return;
if (var->get_interface_type() != NULL) {

View file

@ -370,6 +370,7 @@ public:
case ir_var_temporary:
return this->lower_temps;
case ir_var_uniform:
case ir_var_shader_storage:
return this->lower_uniforms;
case ir_var_function_in:
case ir_var_const_in:

View file

@ -103,8 +103,9 @@ ir_structure_reference_visitor::get_variable_entry(ir_variable *var)
{
assert(var);
if (!var->type->is_record() || var->data.mode == ir_var_uniform
|| var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out)
if (!var->type->is_record() ||
var->data.mode == ir_var_uniform || var->data.mode == ir_var_shader_storage ||
var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out)
return NULL;
foreach_in_list(variable_entry, entry, &this->variable_list) {