summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2015-10-02 00:11:01 -0700
committerKenneth Graunke <kenneth@whitecape.org>2015-11-04 10:18:56 -0800
commitd6ea427ad19bdda08de8f45d175a18709a138bbc (patch)
tree5f9046162aa9ccc21179c80557480a2a12e74713
parent4e2d956954c489b80665694532cd12c4a50dc441 (diff)
nir/lower_io: Introduce nir_store_per_vertex_output intrinsics.
Similar to nir_load_per_vertex_input, but for outputs. This is not useful in geometry shaders, but will be useful in tessellation shaders. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
-rw-r--r--src/glsl/nir/nir_intrinsics.h1
-rw-r--r--src/glsl/nir/nir_lower_io.c27
-rw-r--r--src/glsl/nir/nir_print.c2
3 files changed, 25 insertions, 5 deletions
diff --git a/src/glsl/nir/nir_intrinsics.h b/src/glsl/nir/nir_intrinsics.h
index c2b6fe7166..2b69d3f867 100644
--- a/src/glsl/nir/nir_intrinsics.h
+++ b/src/glsl/nir/nir_intrinsics.h
@@ -261,6 +261,7 @@ LOAD(ssbo, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE)
false, 0, 0, 1 + extra_indices, flags)
STORE(output, 0, 0, 0, 0)
+STORE(per_vertex_output, 1, 1, 0, 0)
STORE(ssbo, 1, 1, 1, 0)
LAST_INTRINSIC(store_ssbo_indirect)
diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
index f04b9b85e5..e4601601e3 100644
--- a/src/glsl/nir/nir_lower_io.c
+++ b/src/glsl/nir/nir_lower_io.c
@@ -76,6 +76,13 @@ stage_uses_per_vertex_inputs(struct lower_io_state *state)
stage == MESA_SHADER_GEOMETRY;
}
+static bool
+stage_uses_per_vertex_outputs(struct lower_io_state *state)
+{
+ gl_shader_stage stage = state->builder.shader->stage;
+ return stage == MESA_SHADER_TESS_CTRL;
+}
+
static unsigned
get_io_offset(nir_deref_var *deref, nir_instr *instr,
nir_ssa_def **vertex_index,
@@ -236,16 +243,23 @@ nir_lower_io_block(nir_block *block, void *void_state)
continue;
nir_ssa_def *indirect;
+ nir_ssa_def *vertex_index;
+
+ bool per_vertex = stage_uses_per_vertex_outputs(state) &&
+ !intrin->variables[0]->var->data.patch;
unsigned offset = get_io_offset(intrin->variables[0], &intrin->instr,
- NULL, &indirect, state);
+ per_vertex ? &vertex_index : NULL,
+ &indirect, state);
offset += intrin->variables[0]->var->data.driver_location;
nir_intrinsic_op store_op;
- if (indirect) {
- store_op = nir_intrinsic_store_output_indirect;
+ if (per_vertex) {
+ store_op = indirect ? nir_intrinsic_store_per_vertex_output_indirect
+ : nir_intrinsic_store_per_vertex_output;
} else {
- store_op = nir_intrinsic_store_output;
+ store_op = indirect ? nir_intrinsic_store_output_indirect
+ : nir_intrinsic_store_output;
}
nir_intrinsic_instr *store = nir_intrinsic_instr_create(state->mem_ctx,
@@ -255,8 +269,11 @@ nir_lower_io_block(nir_block *block, void *void_state)
nir_src_copy(&store->src[0], &intrin->src[0], store);
+ if (per_vertex)
+ store->src[1] = nir_src_for_ssa(vertex_index);
+
if (indirect)
- store->src[1] = nir_src_for_ssa(indirect);
+ store->src[per_vertex ? 2 : 1] = nir_src_for_ssa(indirect);
nir_instr_insert_before(&intrin->instr, &store->instr);
nir_instr_remove(&intrin->instr);
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index 30220c5e48..23fcafeb7e 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -450,6 +450,8 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
break;
case nir_intrinsic_store_output:
case nir_intrinsic_store_output_indirect:
+ case nir_intrinsic_store_per_vertex_output:
+ case nir_intrinsic_store_per_vertex_output_indirect:
var_list = &state->shader->outputs;
break;
default: