summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2013-03-26 17:53:27 -0700
committerZack Rusin <zackr@vmware.com>2013-03-27 03:53:02 -0700
commitd066133a7637864bde46b8118778c526826583a6 (patch)
tree96853c80ffec9a82804935c18ccd80df42d0af9e /src/gallium/auxiliary/draw
parent186a6bffdd5792c78dab0be8f986c8c1b0a83db3 (diff)
downloadexternal_mesa3d-d066133a7637864bde46b8118778c526826583a6.zip
external_mesa3d-d066133a7637864bde46b8118778c526826583a6.tar.gz
external_mesa3d-d066133a7637864bde46b8118778c526826583a6.tar.bz2
llvmpipe/draw: Fix texture sampling in geometry shaders
We weren't correctly propagating the samplers and sampler views when they were related to geometry shaders. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: José Fonseca <jfonseca@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/draw')
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c4
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c90
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h52
3 files changed, 84 insertions, 62 deletions
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index d64b82b..ceb74df 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -792,8 +792,8 @@ draw_set_samplers(struct draw_context *draw,
draw->num_samplers[shader_stage] = num;
#ifdef HAVE_LLVM
- if (draw->llvm && shader_stage == PIPE_SHADER_VERTEX)
- draw_llvm_set_sampler_state(draw);
+ if (draw->llvm)
+ draw_llvm_set_sampler_state(draw, shader_stage);
#endif
}
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 9ab3a9f..3ce48d8 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -241,7 +241,7 @@ create_gs_jit_context_type(struct gallivm_state *gallivm,
LLVMTargetDataRef target = gallivm->target;
LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context);
LLVMTypeRef int_type = LLVMInt32TypeInContext(gallivm->context);
- LLVMTypeRef elem_types[8];
+ LLVMTypeRef elem_types[DRAW_GS_JIT_CTX_NUM_FIELDS];
LLVMTypeRef context_type;
elem_types[0] = LLVMArrayType(LLVMPointerType(float_type, 0), /* constants */
@@ -249,17 +249,17 @@ create_gs_jit_context_type(struct gallivm_state *gallivm,
elem_types[1] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4),
DRAW_TOTAL_CLIP_PLANES), 0);
elem_types[2] = LLVMPointerType(float_type, 0); /* viewport */
-
- elem_types[3] = LLVMPointerType(LLVMPointerType(int_type, 0), 0);
- elem_types[4] = LLVMPointerType(LLVMVectorType(int_type,
- vector_length), 0);
- elem_types[5] = LLVMPointerType(LLVMVectorType(int_type,
- vector_length), 0);
- elem_types[6] = LLVMArrayType(texture_type,
+ elem_types[3] = LLVMArrayType(texture_type,
PIPE_MAX_SHADER_SAMPLER_VIEWS); /* textures */
- elem_types[7] = LLVMArrayType(sampler_type,
+ elem_types[4] = LLVMArrayType(sampler_type,
PIPE_MAX_SAMPLERS); /* samplers */
+
+ elem_types[5] = LLVMPointerType(LLVMPointerType(int_type, 0), 0);
+ elem_types[6] = LLVMPointerType(LLVMVectorType(int_type,
+ vector_length), 0);
+ elem_types[7] = LLVMPointerType(LLVMVectorType(int_type,
+ vector_length), 0);
context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
Elements(elem_types), 0);
@@ -270,23 +270,26 @@ create_gs_jit_context_type(struct gallivm_state *gallivm,
#endif
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, constants,
- target, context_type, 0);
+ target, context_type, DRAW_GS_JIT_CTX_CONSTANTS);
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, planes,
- target, context_type, 1);
+ target, context_type, DRAW_GS_JIT_CTX_PLANES);
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, viewport,
- target, context_type, 2);
- LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, prim_lengths,
- target, context_type, 3);
- LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, emitted_vertices,
- target, context_type, 4);
- LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, emitted_prims,
- target, context_type, 5);
+ target, context_type, DRAW_GS_JIT_CTX_VIEWPORT);
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, textures,
target, context_type,
DRAW_GS_JIT_CTX_TEXTURES);
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, samplers,
target, context_type,
DRAW_GS_JIT_CTX_SAMPLERS);
+ LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, prim_lengths,
+ target, context_type,
+ DRAW_GS_JIT_CTX_PRIM_LENGTHS);
+ LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, emitted_vertices,
+ target, context_type,
+ DRAW_GS_JIT_CTX_EMITTED_VERTICES);
+ LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, emitted_prims,
+ target, context_type,
+ DRAW_GS_JIT_CTX_EMITTED_PRIMS);
LP_CHECK_STRUCT_SIZE(struct draw_gs_jit_context,
target, context_type);
@@ -1721,33 +1724,36 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
void
-draw_llvm_set_sampler_state(struct draw_context *draw)
+draw_llvm_set_sampler_state(struct draw_context *draw,
+ unsigned shader_type)
{
unsigned i;
- for (i = 0; i < draw->num_samplers[PIPE_SHADER_VERTEX]; i++) {
- struct draw_jit_sampler *jit_sam = &draw->llvm->jit_context.samplers[i];
-
- if (draw->samplers[i]) {
- const struct pipe_sampler_state *s
- = draw->samplers[PIPE_SHADER_VERTEX][i];
- jit_sam->min_lod = s->min_lod;
- jit_sam->max_lod = s->max_lod;
- jit_sam->lod_bias = s->lod_bias;
- COPY_4V(jit_sam->border_color, s->border_color.f);
+ if (shader_type == PIPE_SHADER_VERTEX) {
+ for (i = 0; i < draw->num_samplers[PIPE_SHADER_VERTEX]; i++) {
+ struct draw_jit_sampler *jit_sam = &draw->llvm->jit_context.samplers[i];
+
+ if (draw->samplers[i]) {
+ const struct pipe_sampler_state *s
+ = draw->samplers[PIPE_SHADER_VERTEX][i];
+ jit_sam->min_lod = s->min_lod;
+ jit_sam->max_lod = s->max_lod;
+ jit_sam->lod_bias = s->lod_bias;
+ COPY_4V(jit_sam->border_color, s->border_color.f);
+ }
}
- }
-
- for (i = 0; i < draw->num_samplers[PIPE_SHADER_GEOMETRY]; i++) {
- struct draw_jit_sampler *jit_sam = &draw->llvm->gs_jit_context.samplers[i];
-
- if (draw->samplers[i]) {
- const struct pipe_sampler_state *s
- = draw->samplers[PIPE_SHADER_GEOMETRY][i];
- jit_sam->min_lod = s->min_lod;
- jit_sam->max_lod = s->max_lod;
- jit_sam->lod_bias = s->lod_bias;
- COPY_4V(jit_sam->border_color, s->border_color.f);
+ } else if (shader_type == PIPE_SHADER_GEOMETRY) {
+ for (i = 0; i < draw->num_samplers[PIPE_SHADER_GEOMETRY]; i++) {
+ struct draw_jit_sampler *jit_sam = &draw->llvm->gs_jit_context.samplers[i];
+
+ if (draw->samplers[i]) {
+ const struct pipe_sampler_state *s
+ = draw->samplers[PIPE_SHADER_GEOMETRY][i];
+ jit_sam->min_lod = s->min_lod;
+ jit_sam->max_lod = s->max_lod;
+ jit_sam->lod_bias = s->lod_bias;
+ COPY_4V(jit_sam->border_color, s->border_color.f);
+ }
}
}
}
@@ -1951,6 +1957,8 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
&llvm->draw->gs.geometry_shader->info,
&gs_iface);
+ sampler->destroy(sampler);
+
lp_build_mask_end(&mask);
LLVMBuildRet(builder, lp_build_zero(gallivm, lp_type_uint(32)));
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index fc0d2bd..84ee601 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -186,35 +186,40 @@ struct draw_gs_jit_context
float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
float *viewport;
+ /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
+ * DRAW_JIT_CTX_SAMPLERS positions in the struct */
+ struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+ struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+
int **prim_lengths;
int *emitted_vertices;
int *emitted_prims;
-
- struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
- struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
};
+enum {
+ DRAW_GS_JIT_CTX_CONSTANTS = 0,
+ DRAW_GS_JIT_CTX_PLANES = 1,
+ DRAW_GS_JIT_CTX_VIEWPORT = 2,
+ /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
+ * and DRAW_JIT_CTX_SAMPLERS, because they both need
+ * to be at exactly the same locations as they are in the
+ * VS ctx structure for sampling to work. */
+ DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
+ DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
+ DRAW_GS_JIT_CTX_PRIM_LENGTHS = 5,
+ DRAW_GS_JIT_CTX_EMITTED_VERTICES = 6,
+ DRAW_GS_JIT_CTX_EMITTED_PRIMS = 7,
+ DRAW_GS_JIT_CTX_NUM_FIELDS = 8
+};
#define draw_gs_jit_context_constants(_gallivm, _ptr) \
- lp_build_struct_get_ptr(_gallivm, _ptr, 0, "constants")
+ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
#define draw_gs_jit_context_planes(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 1, "planes")
+ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
#define draw_gs_jit_context_viewport(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 2, "viewport")
-
-#define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 3, "prim_lengths")
-
-#define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 4, "emitted_vertices")
-
-#define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 5, "emitted_prims")
-
-#define DRAW_GS_JIT_CTX_TEXTURES 6
-#define DRAW_GS_JIT_CTX_SAMPLERS 7
+ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewport")
#define draw_gs_jit_context_textures(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
@@ -222,6 +227,15 @@ struct draw_gs_jit_context
#define draw_gs_jit_context_samplers(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
+#define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
+
+#define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
+
+#define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
+
typedef int
@@ -478,7 +492,7 @@ draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_stat
LLVMValueRef context_ptr);
void
-draw_llvm_set_sampler_state(struct draw_context *draw);
+draw_llvm_set_sampler_state(struct draw_context *draw, unsigned shader_stage);
void
draw_llvm_set_mapped_texture(struct draw_context *draw,