summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/nir/glsl_to_nir.cpp26
-rw-r--r--src/glsl/nir/nir_intrinsics.h23
2 files changed, 32 insertions, 17 deletions
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 0338af67567..54e56145c89 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -43,7 +43,7 @@ namespace {
class nir_visitor : public ir_visitor
{
public:
- nir_visitor(nir_shader *shader, gl_shader_stage stage);
+ nir_visitor(nir_shader *shader, struct gl_shader *sh, gl_shader_stage stage);
~nir_visitor();
virtual void visit(ir_variable *);
@@ -83,6 +83,8 @@ private:
bool supports_ints;
+ struct gl_shader *sh;
+
nir_shader *shader;
gl_shader_stage stage;
nir_function_impl *impl;
@@ -133,7 +135,7 @@ glsl_to_nir(struct gl_shader *sh, const nir_shader_compiler_options *options)
{
nir_shader *shader = nir_shader_create(NULL, options);
- nir_visitor v1(shader, sh->Stage);
+ nir_visitor v1(shader, sh, sh->Stage);
nir_function_visitor v2(&v1);
v2.run(sh->ir);
visit_exec_list(sh->ir, &v1);
@@ -141,10 +143,12 @@ glsl_to_nir(struct gl_shader *sh, const nir_shader_compiler_options *options)
return shader;
}
-nir_visitor::nir_visitor(nir_shader *shader, gl_shader_stage stage)
+nir_visitor::nir_visitor(nir_shader *shader, struct gl_shader *sh,
+ gl_shader_stage stage)
{
this->supports_ints = shader->options->native_integers;
this->shader = shader;
+ this->sh = sh;
this->stage = stage;
this->is_global = true;
this->var_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
@@ -987,11 +991,21 @@ nir_visitor::visit(ir_expression *ir)
} else {
op = nir_intrinsic_load_ubo_indirect;
}
+
+ ir_constant *const_block = ir->operands[0]->as_constant();
+ assert(const_block && "can't figure out descriptor set index");
+ unsigned index = const_block->value.u[0];
+ unsigned set = sh->UniformBlocks[index].Set;
+ unsigned binding = sh->UniformBlocks[index].Binding;
+
nir_intrinsic_instr *load = nir_intrinsic_instr_create(this->shader, op);
load->num_components = ir->type->vector_elements;
- load->const_index[0] = const_index ? const_index->value.u[0] : 0; /* base offset */
- load->const_index[1] = 1; /* number of vec4's */
- load->src[0] = evaluate_rvalue(ir->operands[0]);
+ load->const_index[0] = set;
+ load->const_index[1] = const_index ? const_index->value.u[0] : 0; /* base offset */
+ nir_load_const_instr *load_binding = nir_load_const_instr_create(shader, 1);
+ load_binding->value.u[0] = binding;
+ nir_instr_insert_after_cf_list(this->cf_node_list, &load_binding->instr);
+ load->src[0] = nir_src_for_ssa(&load_binding->def);
if (!const_index)
load->src[1] = evaluate_rvalue(ir->operands[1]);
add_instr(&load->instr, ir->type->vector_elements);
diff --git a/src/glsl/nir/nir_intrinsics.h b/src/glsl/nir/nir_intrinsics.h
index bc6e6b8f498..64861300b55 100644
--- a/src/glsl/nir/nir_intrinsics.h
+++ b/src/glsl/nir/nir_intrinsics.h
@@ -139,11 +139,12 @@ SYSTEM_VALUE(sample_mask_in, 1)
SYSTEM_VALUE(invocation_id, 1)
/*
- * The first and only index is the base address to load from. Indirect
- * loads have an additional register input, which is added to the constant
- * address to compute the final address to load from. For UBO's (and
- * SSBO's), the first source is the (possibly constant) UBO buffer index
- * and the indirect (if it exists) is the second source.
+ * The last index is the base address to load from. Indirect loads have an
+ * additional register input, which is added to the constant address to
+ * compute the final address to load from. For UBO's (and SSBO's), the first
+ * source is the (possibly constant) UBO buffer index and the indirect (if it
+ * exists) is the second source, and the first index is the descriptor set
+ * index.
*
* For vector backends, the address is in terms of one vec4, and so each array
* element is +4 scalar components from the previous array element. For scalar
@@ -151,14 +152,14 @@ SYSTEM_VALUE(invocation_id, 1)
* elements begin immediately after the previous array element.
*/
-#define LOAD(name, extra_srcs, flags) \
- INTRINSIC(load_##name, extra_srcs, ARR(1), true, 0, 0, 1, flags) \
+#define LOAD(name, extra_srcs, extra_indices, flags) \
+ INTRINSIC(load_##name, extra_srcs, ARR(1), true, 0, 0, 1 + extra_indices, flags) \
INTRINSIC(load_##name##_indirect, extra_srcs + 1, ARR(1, 1), \
- true, 0, 0, 1, flags)
+ true, 0, 0, 1 + extra_indices, flags)
-LOAD(uniform, 0, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-LOAD(ubo, 1, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-LOAD(input, 0, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
+LOAD(uniform, 0, 0, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
+LOAD(ubo, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
+LOAD(input, 0, 0, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* LOAD(ssbo, 1, 0) */
/*