summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2013-08-02 01:39:35 -0400
committerZack Rusin <zackr@vmware.com>2013-08-02 20:11:18 -0400
commit05487ef88ded5fea0b1de7bc08d44846648d1ce2 (patch)
tree5a97df0f2d48c4c6e008be4eba0922d99a5304fb /src
parent2e46a1dcb33618f2873ebaaeb3ffe238f11a31a3 (diff)
downloadexternal_mesa3d-05487ef88ded5fea0b1de7bc08d44846648d1ce2.zip
external_mesa3d-05487ef88ded5fea0b1de7bc08d44846648d1ce2.tar.gz
external_mesa3d-05487ef88ded5fea0b1de7bc08d44846648d1ce2.tar.bz2
draw: stop crashing with extra shader outputs
Draw sometimes injects extra shader outputs (aa points, lines or front face), unfortunately most of the pipeline and llvm code didn't handle them at all. It only worked if number of inputs happened to be bigger or equal to the number of shader outputs plus the extra injected outputs. In particular when running the pipeline which depends on the vertex_id in the vertex_header things were completely broken. The patch adjust the code to correctly use the total number of shader outputs (the standard ones plus the injected ones) to make it all stop crashing and work. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c34
-rw-r--r--src/gallium/auxiliary/draw/draw_context.h5
-rw-r--r--src/gallium/auxiliary/draw/draw_gs.c2
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c3
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h4
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe.h3
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c6
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c8
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_variant.c2
9 files changed, 52 insertions, 15 deletions
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 4a6ba1a..29bbc94 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -605,6 +605,40 @@ draw_num_shader_outputs(const struct draw_context *draw)
/**
+ * Return total number of the vertex shader outputs. This function
+ * also counts any extra vertex output attributes that may
+ * be filled in by some draw stages (such as AA point, AA line,
+ * front face).
+ */
+uint
+draw_total_vs_outputs(const struct draw_context *draw)
+{
+ const struct tgsi_shader_info *info = &draw->vs.vertex_shader->info;
+
+ return info->num_outputs + draw->extra_shader_outputs.num;;
+}
+
+/**
+ * Return total number of the geometry shader outputs. This function
+ * also counts any extra geometry output attributes that may
+ * be filled in by some draw stages (such as AA point, AA line, front
+ * face).
+ */
+uint
+draw_total_gs_outputs(const struct draw_context *draw)
+{
+ const struct tgsi_shader_info *info;
+
+ if (!draw->gs.geometry_shader)
+ return 0;
+
+ info = &draw->gs.geometry_shader->info;
+
+ return info->num_outputs + draw->extra_shader_outputs.num;
+}
+
+
+/**
* Provide TGSI sampler objects for vertex/geometry shaders that use
* texture fetches. This state only needs to be set once per context.
* This might only be used by software drivers for the time being.
diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h
index 4a1b27e..c720806 100644
--- a/src/gallium/auxiliary/draw/draw_context.h
+++ b/src/gallium/auxiliary/draw/draw_context.h
@@ -133,6 +133,11 @@ draw_find_shader_output(const struct draw_context *draw,
uint
draw_num_shader_outputs(const struct draw_context *draw);
+uint
+draw_total_vs_outputs(const struct draw_context *draw);
+
+uint
+draw_total_gs_outputs(const struct draw_context *draw);
void
draw_texture_sampler(struct draw_context *draw,
diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c
index cd63e2b..13d3d3b 100644
--- a/src/gallium/auxiliary/draw/draw_gs.c
+++ b/src/gallium/auxiliary/draw/draw_gs.c
@@ -534,7 +534,7 @@ int draw_geometry_shader_run(struct draw_geometry_shader *shader,
{
const float (*input)[4] = (const float (*)[4])input_verts->verts->data;
unsigned input_stride = input_verts->vertex_size;
- unsigned num_outputs = shader->info.num_outputs;
+ unsigned num_outputs = draw_total_gs_outputs(shader->draw);
unsigned vertex_size = sizeof(struct vertex_header) + num_outputs * 4 * sizeof(float);
unsigned num_input_verts = input_prim->linear ?
input_verts->count :
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index cf71a5d..03f8631 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -1833,6 +1833,7 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
key->need_edgeflags = (llvm->draw->vs.edgeflag_output ? TRUE : FALSE);
key->ucp_enable = llvm->draw->rasterizer->clip_plane_enable;
key->has_gs = llvm->draw->gs.geometry_shader != NULL;
+ key->num_outputs = draw_total_vs_outputs(llvm->draw);
key->pad1 = 0;
/* All variants of this shader will have the same value for
@@ -2270,6 +2271,8 @@ draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
key = (struct draw_gs_llvm_variant_key *)store;
+ key->num_outputs = draw_total_gs_outputs(llvm->draw);
+
/* All variants of this shader will have the same value for
* nr_samplers. Not yet trying to compact away holes in the
* sampler array.
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 0675e3b..1d238a2 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -301,12 +301,13 @@ struct draw_llvm_variant_key
unsigned bypass_viewport:1;
unsigned need_edgeflags:1;
unsigned has_gs:1;
+ unsigned num_outputs:8;
/*
* it is important there are no holes in this struct
* (and all padding gets zeroed).
*/
unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
- unsigned pad1:32-PIPE_MAX_CLIP_PLANES;
+ unsigned pad1:24-PIPE_MAX_CLIP_PLANES;
/* Variable number of vertex elements:
*/
@@ -321,6 +322,7 @@ struct draw_gs_llvm_variant_key
{
unsigned nr_samplers:8;
unsigned nr_sampler_views:8;
+ unsigned num_outputs:8;
struct draw_sampler_static_state samplers[1];
};
diff --git a/src/gallium/auxiliary/draw/draw_pipe.h b/src/gallium/auxiliary/draw/draw_pipe.h
index 4792507..547e4bf 100644
--- a/src/gallium/auxiliary/draw/draw_pipe.h
+++ b/src/gallium/auxiliary/draw/draw_pipe.h
@@ -35,6 +35,7 @@
#include "pipe/p_compiler.h"
#include "draw_private.h" /* for sizeof(vertex_header) */
+#include "draw_context.h"
/**
@@ -117,7 +118,7 @@ dup_vert( struct draw_stage *stage,
{
struct vertex_header *tmp = stage->tmp[idx];
const uint vsize = sizeof(struct vertex_header)
- + stage->draw->vs.num_vs_outputs * 4 * sizeof(float);
+ + draw_num_shader_outputs(stage->draw) * 4 * sizeof(float);
memcpy(tmp, vert, vsize);
tmp->vertex_id = UNDEFINED_VERTEX_ID;
return tmp;
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
index 84f86ae..8fcc170 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
@@ -72,12 +72,8 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
const unsigned gs_out_prim = (gs ? gs->output_primitive :
u_assembled_prim(prim));
-
- /* Add one to num_outputs because the pipeline occasionally tags on
- * an additional texcoord, eg for AA lines.
- */
unsigned nr = MAX2( vs->info.num_inputs,
- vs->info.num_outputs + 1 );
+ draw_total_vs_outputs(draw) );
if (gs) {
nr = MAX2(nr, gs->info.num_outputs + 1);
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
index 17b948a..9f17241 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
@@ -141,12 +141,8 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
struct draw_geometry_shader *gs = draw->gs.geometry_shader;
const unsigned out_prim = gs ? gs->output_primitive :
u_assembled_prim(in_prim);
-
- /* Add one to num_outputs because the pipeline occasionally tags on
- * an additional texcoord, eg for AA lines.
- */
- const unsigned nr = MAX2( vs->info.num_inputs,
- vs->info.num_outputs + 1 );
+ const unsigned nr = MAX2(vs->info.num_inputs,
+ draw_total_vs_outputs(draw));
fpme->input_prim = in_prim;
fpme->opt = opt;
diff --git a/src/gallium/auxiliary/draw/draw_vs_variant.c b/src/gallium/auxiliary/draw/draw_vs_variant.c
index 37500c7..9045b63 100644
--- a/src/gallium/auxiliary/draw/draw_vs_variant.c
+++ b/src/gallium/auxiliary/draw/draw_vs_variant.c
@@ -315,7 +315,7 @@ draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
vsvg->draw = vs->draw;
vsvg->temp_vertex_stride = MAX2(key->nr_inputs,
- vsvg->base.vs->info.num_outputs) * 4 * sizeof(float);
+ draw_total_vs_outputs(vs->draw)) * 4 * sizeof(float);
/* Build free-standing fetch and emit functions:
*/