glsl: Lower shader storage buffer object loads to GLSL IR instrinsics
Extend the existing lower_ubo_reference pass to also detect SSBO loads and lower them to __intrinsic_load_ssbo intrinsics. Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
parent
1966ea5772
commit
ea633db65f
|
@ -150,7 +150,8 @@ public:
|
||||||
int *matrix_columns);
|
int *matrix_columns);
|
||||||
ir_expression *ubo_load(const struct glsl_type *type,
|
ir_expression *ubo_load(const struct glsl_type *type,
|
||||||
ir_rvalue *offset);
|
ir_rvalue *offset);
|
||||||
|
ir_call *ssbo_load(const struct glsl_type *type,
|
||||||
|
ir_rvalue *offset);
|
||||||
|
|
||||||
void check_for_ssbo_store(ir_assignment *ir);
|
void check_for_ssbo_store(ir_assignment *ir);
|
||||||
void write_to_memory(ir_dereference *deref,
|
void write_to_memory(ir_dereference *deref,
|
||||||
|
@ -170,6 +171,7 @@ public:
|
||||||
struct gl_uniform_buffer_variable *ubo_var;
|
struct gl_uniform_buffer_variable *ubo_var;
|
||||||
ir_rvalue *uniform_block;
|
ir_rvalue *uniform_block;
|
||||||
bool progress;
|
bool progress;
|
||||||
|
bool is_shader_storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,6 +268,8 @@ lower_ubo_reference_visitor::setup_for_load_or_store(ir_variable *var,
|
||||||
this->uniform_block = index;
|
this->uniform_block = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->is_shader_storage = shader->UniformBlocks[i].IsShaderStorage;
|
||||||
|
|
||||||
struct gl_uniform_block *block = &shader->UniformBlocks[i];
|
struct gl_uniform_block *block = &shader->UniformBlocks[i];
|
||||||
|
|
||||||
this->ubo_var = var->is_interface_instance()
|
this->ubo_var = var->is_interface_instance()
|
||||||
|
@ -415,7 +419,7 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
|
||||||
if (!var || !var->is_in_buffer_block())
|
if (!var || !var->is_in_buffer_block())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mem_ctx = ralloc_parent(*rvalue);
|
mem_ctx = ralloc_parent(shader->ir);
|
||||||
|
|
||||||
ir_rvalue *offset = NULL;
|
ir_rvalue *offset = NULL;
|
||||||
unsigned const_offset;
|
unsigned const_offset;
|
||||||
|
@ -512,6 +516,42 @@ lower_ubo_reference_visitor::ssbo_store(ir_rvalue *deref,
|
||||||
return new(mem_ctx) ir_call(sig, NULL, &call_params);
|
return new(mem_ctx) ir_call(sig, NULL, &call_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir_call *
|
||||||
|
lower_ubo_reference_visitor::ssbo_load(const struct glsl_type *type,
|
||||||
|
ir_rvalue *offset)
|
||||||
|
{
|
||||||
|
exec_list sig_params;
|
||||||
|
|
||||||
|
ir_variable *block_ref = new(mem_ctx)
|
||||||
|
ir_variable(glsl_type::uint_type, "block_ref" , ir_var_function_in);
|
||||||
|
sig_params.push_tail(block_ref);
|
||||||
|
|
||||||
|
ir_variable *offset_ref = new(mem_ctx)
|
||||||
|
ir_variable(glsl_type::uint_type, "offset_ref" , ir_var_function_in);
|
||||||
|
sig_params.push_tail(offset_ref);
|
||||||
|
|
||||||
|
ir_function_signature *sig =
|
||||||
|
new(mem_ctx) ir_function_signature(type, shader_storage_buffer_object);
|
||||||
|
assert(sig);
|
||||||
|
sig->replace_parameters(&sig_params);
|
||||||
|
sig->is_intrinsic = true;
|
||||||
|
|
||||||
|
ir_function *f = new(mem_ctx) ir_function("__intrinsic_load_ssbo");
|
||||||
|
f->add_signature(sig);
|
||||||
|
|
||||||
|
ir_variable *result = new(mem_ctx)
|
||||||
|
ir_variable(type, "ssbo_load_result", ir_var_temporary);
|
||||||
|
base_ir->insert_before(result);
|
||||||
|
ir_dereference_variable *deref_result = new(mem_ctx)
|
||||||
|
ir_dereference_variable(result);
|
||||||
|
|
||||||
|
exec_list call_params;
|
||||||
|
call_params.push_tail(this->uniform_block->clone(mem_ctx, NULL));
|
||||||
|
call_params.push_tail(offset->clone(mem_ctx, NULL));
|
||||||
|
|
||||||
|
return new(mem_ctx) ir_call(sig, deref_result, &call_params);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
writemask_for_size(unsigned n)
|
writemask_for_size(unsigned n)
|
||||||
{
|
{
|
||||||
|
@ -610,9 +650,17 @@ lower_ubo_reference_visitor::emit_access(bool is_write,
|
||||||
add(base_offset, new(mem_ctx) ir_constant(deref_offset));
|
add(base_offset, new(mem_ctx) ir_constant(deref_offset));
|
||||||
if (is_write)
|
if (is_write)
|
||||||
base_ir->insert_after(ssbo_store(deref, offset, write_mask));
|
base_ir->insert_after(ssbo_store(deref, offset, write_mask));
|
||||||
else
|
else {
|
||||||
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
|
if (!this->is_shader_storage) {
|
||||||
ubo_load(deref->type, offset)));
|
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
|
||||||
|
ubo_load(deref->type, offset)));
|
||||||
|
} else {
|
||||||
|
ir_call *load_ssbo = ssbo_load(deref->type, offset);
|
||||||
|
base_ir->insert_before(load_ssbo);
|
||||||
|
ir_rvalue *value = load_ssbo->return_deref->as_rvalue()->clone(mem_ctx, NULL);
|
||||||
|
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL), value));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned N = deref->type->is_double() ? 8 : 4;
|
unsigned N = deref->type->is_double() ? 8 : 4;
|
||||||
|
|
||||||
|
@ -640,9 +688,18 @@ lower_ubo_reference_visitor::emit_access(bool is_write,
|
||||||
if (is_write) {
|
if (is_write) {
|
||||||
base_ir->insert_after(ssbo_store(swizzle(deref, i, 1), chan_offset, 1));
|
base_ir->insert_after(ssbo_store(swizzle(deref, i, 1), chan_offset, 1));
|
||||||
} else {
|
} else {
|
||||||
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
|
if (!this->is_shader_storage) {
|
||||||
ubo_load(deref_type, chan_offset),
|
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
|
||||||
(1U << i)));
|
ubo_load(deref_type, chan_offset),
|
||||||
|
(1U << i)));
|
||||||
|
} else {
|
||||||
|
ir_call *load_ssbo = ssbo_load(deref_type, chan_offset);
|
||||||
|
base_ir->insert_before(load_ssbo);
|
||||||
|
ir_rvalue *value = load_ssbo->return_deref->as_rvalue()->clone(mem_ctx, NULL);
|
||||||
|
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
|
||||||
|
value,
|
||||||
|
(1U << i)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue