summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorChristoph Bumiller <[email protected]>2010-12-19 21:46:33 +0100
committerChristoph Bumiller <[email protected]>2010-12-19 21:46:33 +0100
commit0f68236a2487dbeb0396b996debcda595b0b54a1 (patch)
tree938ae3b779349b6dba6f5a891550604f9a9ca895 /src/gallium/auxiliary
parentd047168d81cfeb39a98f3ae16416872facc6237c (diff)
parent237880463d5168cad8df0bae6018b5fd76617777 (diff)
Merge remote branch 'origin/master' into nvc0-new
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/Makefile10
-rw-r--r--src/gallium/auxiliary/SConscript3
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c29
-rw-r--r--src/gallium/auxiliary/draw/draw_context.h5
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c859
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h61
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm_sample.c20
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm_translate.c338
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aaline.c9
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_pstipple.c5
-rw-r--r--src/gallium/auxiliary/draw/draw_private.h1
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c6
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c27
-rw-r--r--src/gallium/auxiliary/draw/draw_vs.c40
-rw-r--r--src/gallium/auxiliary/draw/draw_vs.h70
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_aos.c50
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_aos.h10
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_exec.c2
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_llvm.c14
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_ppc.c4
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_sse.c4
-rw-r--r--src/gallium/auxiliary/draw/draw_vs_varient.c32
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld.h29
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.c560
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.c21
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.h4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_bitarit.c41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.c44
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.h48
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_conv.c101
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_conv.h8
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_debug.h1
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.c123
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.h41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format.h13
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_aos.c187
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_soa.c73
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c115
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_gather.c41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_gather.h6
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.c361
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.h39
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_intr.c14
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_intr.h7
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_logic.c76
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_logic.h2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_pack.c84
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_pack.h14
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.c39
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.h13
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_quad.c29
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.c185
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.h28
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c114
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c118
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.c33
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.h12
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_swizzle.c92
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_swizzle.h4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi.h7
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c73
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c292
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_type.c37
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_type.h14
-rw-r--r--src/gallium/auxiliary/target-helpers/wrap_screen.c68
-rw-r--r--src/gallium/auxiliary/target-helpers/wrap_screen.h16
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_exec.h2
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_parse.h3
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_text.c3
-rw-r--r--src/gallium/auxiliary/util/u_blit.c72
-rw-r--r--src/gallium/auxiliary/util/u_blit.h5
-rw-r--r--src/gallium/auxiliary/util/u_blitter.c120
-rw-r--r--src/gallium/auxiliary/util/u_blitter.h7
-rw-r--r--src/gallium/auxiliary/util/u_box.h12
-rw-r--r--src/gallium/auxiliary/util/u_debug.c49
-rw-r--r--src/gallium/auxiliary/util/u_debug_describe.c2
-rw-r--r--src/gallium/auxiliary/util/u_debug_stack.c5
-rw-r--r--src/gallium/auxiliary/util/u_debug_symbol.c4
-rw-r--r--src/gallium/auxiliary/util/u_dirty_flags.h4
-rw-r--r--src/gallium/auxiliary/util/u_dirty_surfaces.h5
-rw-r--r--src/gallium/auxiliary/util/u_dump_state.c14
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c411
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.h2
-rw-r--r--src/gallium/auxiliary/util/u_inlines.h98
-rw-r--r--src/gallium/auxiliary/util/u_resource.c62
-rw-r--r--src/gallium/auxiliary/util/u_sampler.c7
-rw-r--r--src/gallium/auxiliary/util/u_simple_screen.h3
-rw-r--r--src/gallium/auxiliary/util/u_simple_shaders.c11
-rw-r--r--src/gallium/auxiliary/util/u_simple_shaders.h4
-rw-r--r--src/gallium/auxiliary/util/u_slab.c (renamed from src/gallium/auxiliary/util/u_mempool.c)94
-rw-r--r--src/gallium/auxiliary/util/u_slab.h (renamed from src/gallium/auxiliary/util/u_mempool.h)50
-rw-r--r--src/gallium/auxiliary/util/u_staging.c37
-rw-r--r--src/gallium/auxiliary/util/u_staging.h2
-rw-r--r--src/gallium/auxiliary/util/u_surface.c78
-rw-r--r--src/gallium/auxiliary/util/u_surface.h24
-rw-r--r--src/gallium/auxiliary/util/u_surfaces.c31
-rw-r--r--src/gallium/auxiliary/util/u_surfaces.h27
-rw-r--r--src/gallium/auxiliary/util/u_transfer.c78
-rw-r--r--src/gallium/auxiliary/util/u_transfer.h122
99 files changed, 3503 insertions, 2771 deletions
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile
index f37d59e9a3a..ff355c47832 100644
--- a/src/gallium/auxiliary/Makefile
+++ b/src/gallium/auxiliary/Makefile
@@ -128,12 +128,12 @@ C_SOURCES = \
util/u_linkage.c \
util/u_network.c \
util/u_math.c \
- util/u_mempool.c \
util/u_mm.c \
util/u_rect.c \
util/u_ringbuffer.c \
util/u_sampler.c \
util/u_simple_shaders.c \
+ util/u_slab.c \
util/u_snprintf.c \
util/u_staging.c \
util/u_surface.c \
@@ -142,8 +142,7 @@ C_SOURCES = \
util/u_tile.c \
util/u_transfer.c \
util/u_resource.c \
- util/u_upload_mgr.c \
- target-helpers/wrap_screen.c
+ util/u_upload_mgr.c
# Disabling until pipe-video branch gets merged in
#vl/vl_bitstream_parser.c \
@@ -186,7 +185,7 @@ GALLIVM_SOURCES = \
draw/draw_pt_fetch_shade_pipeline_llvm.c
GALLIVM_CPP_SOURCES = \
- gallivm/lp_bld_misc.cpp
+ gallivm/lp_bld_misc.cpp
GENERATED_SOURCES = \
indices/u_indices_gen.c \
@@ -204,9 +203,6 @@ CPP_SOURCES += \
endif
-LIBRARY_DEFINES += -D__STDC_CONSTANT_MACROS
-
-
include ../Makefile.template
diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript
index 0e5da1374ff..fca7e5fd117 100644
--- a/src/gallium/auxiliary/SConscript
+++ b/src/gallium/auxiliary/SConscript
@@ -175,13 +175,13 @@ source = [
'util/u_linkage.c',
'util/u_network.c',
'util/u_math.c',
- 'util/u_mempool.c',
'util/u_mm.c',
'util/u_rect.c',
'util/u_resource.c',
'util/u_ringbuffer.c',
'util/u_sampler.c',
'util/u_simple_shaders.c',
+ 'util/u_slab.c',
'util/u_snprintf.c',
'util/u_staging.c',
'util/u_surface.c',
@@ -196,7 +196,6 @@ source = [
#'vl/vl_compositor.c',
#'vl/vl_csc.c',
#'vl/vl_shader_build.c',
- 'target-helpers/wrap_screen.c',
]
if env['llvm']:
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 39d82f32892..73d5b6e403f 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -63,19 +63,32 @@ draw_get_option_use_llvm(void)
}
#endif
-struct draw_context *draw_create( struct pipe_context *pipe )
+
+
+/**
+ * Create new draw module context.
+ */
+struct draw_context *
+draw_create(struct pipe_context *pipe)
+{
+ return draw_create_gallivm(pipe, NULL);
+}
+
+
+
+/**
+ * Create new draw module context with gallivm state for LLVM JIT.
+ */
+struct draw_context *
+draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm)
{
struct draw_context *draw = CALLOC_STRUCT( draw_context );
if (draw == NULL)
goto fail;
#if HAVE_LLVM
- if(draw_get_option_use_llvm())
- {
- lp_build_init();
- assert(lp_build_engine);
- draw->engine = lp_build_engine;
- draw->llvm = draw_llvm_create(draw);
+ if (draw_get_option_use_llvm() && gallivm) {
+ draw->llvm = draw_llvm_create(draw, gallivm);
}
#endif
@@ -91,6 +104,8 @@ fail:
return NULL;
}
+
+
boolean draw_init(struct draw_context *draw)
{
/*
diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h
index ff4f753604f..a0b217e4d33 100644
--- a/src/gallium/auxiliary/draw/draw_context.h
+++ b/src/gallium/auxiliary/draw/draw_context.h
@@ -48,10 +48,15 @@ struct draw_vertex_shader;
struct draw_geometry_shader;
struct draw_fragment_shader;
struct tgsi_sampler;
+struct gallivm_state;
+
struct draw_context *draw_create( struct pipe_context *pipe );
+struct draw_context *
+draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm);
+
void draw_destroy( struct draw_context *draw );
void draw_flush(struct draw_context *draw);
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 2b5f01cda74..943ec44bcde 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -42,6 +42,7 @@
#include "gallivm/lp_bld_printf.h"
#include "gallivm/lp_bld_intr.h"
#include "gallivm/lp_bld_init.h"
+#include "gallivm/lp_bld_type.h"
#include "tgsi/tgsi_exec.h"
#include "tgsi/tgsi_dump.h"
@@ -49,259 +50,352 @@
#include "util/u_math.h"
#include "util/u_pointer.h"
#include "util/u_string.h"
+#include "util/u_simple_list.h"
-#include <llvm-c/Transforms/Scalar.h>
#define DEBUG_STORE 0
-/* generates the draw jit function */
+
+/**
+ * This function is called by the gallivm "garbage collector" when
+ * the LLVM global data structures are freed. We must free all LLVM-related
+ * data. Specifically, all JIT'd shader variants.
+ */
+static void
+draw_llvm_garbage_collect_callback(void *cb_data)
+{
+ struct draw_llvm *llvm = (struct draw_llvm *) cb_data;
+ struct draw_llvm_variant_list_item *li;
+
+ /* free all shader variants */
+ li = first_elem(&llvm->vs_variants_list);
+ while (!at_end(&llvm->vs_variants_list, li)) {
+ struct draw_llvm_variant_list_item *next = next_elem(li);
+ draw_llvm_destroy_variant(li->base);
+ li = next;
+ }
+
+ /* Null-out these pointers so they get remade next time they're needed.
+ * See the accessor functions below.
+ */
+ llvm->context_ptr_type = NULL;
+ llvm->buffer_ptr_type = NULL;
+ llvm->vb_ptr_type = NULL;
+ llvm->vertex_header_ptr_type = NULL;
+}
+
+
static void
draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *var);
+
static void
draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *var);
-static void
-init_globals(struct draw_llvm *llvm)
+
+/**
+ * Create LLVM type for struct draw_jit_texture
+ */
+static LLVMTypeRef
+create_jit_texture_type(struct gallivm_state *gallivm)
{
+ LLVMTargetDataRef target = gallivm->target;
LLVMTypeRef texture_type;
+ LLVMTypeRef elem_types[DRAW_JIT_TEXTURE_NUM_FIELDS];
+ LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context);
+
+ elem_types[DRAW_JIT_TEXTURE_WIDTH] =
+ elem_types[DRAW_JIT_TEXTURE_HEIGHT] =
+ elem_types[DRAW_JIT_TEXTURE_DEPTH] =
+ elem_types[DRAW_JIT_TEXTURE_LAST_LEVEL] = int32_type;
+ elem_types[DRAW_JIT_TEXTURE_ROW_STRIDE] =
+ elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] =
+ LLVMArrayType(int32_type, PIPE_MAX_TEXTURE_LEVELS);
+ elem_types[DRAW_JIT_TEXTURE_DATA] =
+ LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0),
+ PIPE_MAX_TEXTURE_LEVELS);
+ elem_types[DRAW_JIT_TEXTURE_MIN_LOD] =
+ elem_types[DRAW_JIT_TEXTURE_MAX_LOD] =
+ elem_types[DRAW_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(gallivm->context);
+ elem_types[DRAW_JIT_TEXTURE_BORDER_COLOR] =
+ LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
+
+ texture_type = LLVMStructTypeInContext(gallivm->context, elem_types,
+ Elements(elem_types), 0);
+
+ /* Make sure the target's struct layout cache doesn't return
+ * stale/invalid data.
+ */
+ LLVMInvalidateStructLayout(gallivm->target, texture_type);
+
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, width,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_WIDTH);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, height,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_HEIGHT);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, depth,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_DEPTH);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, last_level,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_LAST_LEVEL);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, row_stride,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_ROW_STRIDE);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, img_stride,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_IMG_STRIDE);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, data,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_DATA);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, min_lod,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_MIN_LOD);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, max_lod,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_MAX_LOD);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, lod_bias,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_LOD_BIAS);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, border_color,
+ target, texture_type,
+ DRAW_JIT_TEXTURE_BORDER_COLOR);
+
+ LP_CHECK_STRUCT_SIZE(struct draw_jit_texture, target, texture_type);
+
+ return texture_type;
+}
- /* struct draw_jit_texture */
- {
- LLVMTypeRef elem_types[DRAW_JIT_TEXTURE_NUM_FIELDS];
-
- elem_types[DRAW_JIT_TEXTURE_WIDTH] = LLVMInt32Type();
- elem_types[DRAW_JIT_TEXTURE_HEIGHT] = LLVMInt32Type();
- elem_types[DRAW_JIT_TEXTURE_DEPTH] = LLVMInt32Type();
- elem_types[DRAW_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32Type();
- elem_types[DRAW_JIT_TEXTURE_ROW_STRIDE] =
- LLVMArrayType(LLVMInt32Type(), PIPE_MAX_TEXTURE_LEVELS);
- elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] =
- LLVMArrayType(LLVMInt32Type(), PIPE_MAX_TEXTURE_LEVELS);
- elem_types[DRAW_JIT_TEXTURE_DATA] =
- LLVMArrayType(LLVMPointerType(LLVMInt8Type(), 0),
- PIPE_MAX_TEXTURE_LEVELS);
- elem_types[DRAW_JIT_TEXTURE_MIN_LOD] = LLVMFloatType();
- elem_types[DRAW_JIT_TEXTURE_MAX_LOD] = LLVMFloatType();
- elem_types[DRAW_JIT_TEXTURE_LOD_BIAS] = LLVMFloatType();
- elem_types[DRAW_JIT_TEXTURE_BORDER_COLOR] =
- LLVMArrayType(LLVMFloatType(), 4);
-
- texture_type = LLVMStructType(elem_types, Elements(elem_types), 0);
-
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, width,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_WIDTH);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, height,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_HEIGHT);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, depth,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_DEPTH);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, last_level,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_LAST_LEVEL);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, row_stride,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_ROW_STRIDE);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, img_stride,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_IMG_STRIDE);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, data,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_DATA);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, min_lod,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_MIN_LOD);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, max_lod,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_MAX_LOD);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, lod_bias,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_LOD_BIAS);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, border_color,
- llvm->target, texture_type,
- DRAW_JIT_TEXTURE_BORDER_COLOR);
- LP_CHECK_STRUCT_SIZE(struct draw_jit_texture,
- llvm->target, texture_type);
-
- LLVMAddTypeName(llvm->module, "texture", texture_type);
- }
+/**
+ * Create LLVM type for struct draw_jit_texture
+ */
+static LLVMTypeRef
+create_jit_context_type(struct gallivm_state *gallivm,
+ LLVMTypeRef texture_type)
+{
+ LLVMTargetDataRef target = gallivm->target;
+ LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context);
+ LLVMTypeRef elem_types[5];
+ LLVMTypeRef context_type;
+
+ elem_types[0] = LLVMPointerType(float_type, 0); /* vs_constants */
+ elem_types[1] = LLVMPointerType(float_type, 0); /* gs_constants */
+ elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), 12), 0); /* planes */
+ elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */
+ elem_types[4] = LLVMArrayType(texture_type,
+ PIPE_MAX_VERTEX_SAMPLERS); /* textures */
+
+ context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
+ Elements(elem_types), 0);
+
+ LLVMInvalidateStructLayout(gallivm->target, context_type);
+
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants,
+ target, context_type, 0);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, gs_constants,
+ target, context_type, 1);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes,
+ target, context_type, 2);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, textures,
+ target, context_type,
+ DRAW_JIT_CTX_TEXTURES);
+ LP_CHECK_STRUCT_SIZE(struct draw_jit_context,
+ target, context_type);
+
+ return context_type;
+}
- /* struct draw_jit_context */
- {
- LLVMTypeRef elem_types[5];
- LLVMTypeRef context_type;
-
- elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* vs_constants */
- elem_types[1] = LLVMPointerType(LLVMFloatType(), 0); /* gs_constants */
- elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(LLVMFloatType(), 4), 12), 0); /* planes */
- elem_types[3] = LLVMPointerType(LLVMFloatType(), 0); /* viewport */
- elem_types[4] = LLVMArrayType(texture_type,
- PIPE_MAX_VERTEX_SAMPLERS); /* textures */
-
- context_type = LLVMStructType(elem_types, Elements(elem_types), 0);
-
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants,
- llvm->target, context_type, 0);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, gs_constants,
- llvm->target, context_type, 1);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes,
- llvm->target, context_type, 2);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, textures,
- llvm->target, context_type,
- DRAW_JIT_CTX_TEXTURES);
- LP_CHECK_STRUCT_SIZE(struct draw_jit_context,
- llvm->target, context_type);
-
- LLVMAddTypeName(llvm->module, "draw_jit_context", context_type);
-
- llvm->context_ptr_type = LLVMPointerType(context_type, 0);
- }
- {
- LLVMTypeRef buffer_ptr = LLVMPointerType(LLVMIntType(8), 0);
- llvm->buffer_ptr_type = LLVMPointerType(buffer_ptr, 0);
- }
- /* struct pipe_vertex_buffer */
- {
- LLVMTypeRef elem_types[4];
- LLVMTypeRef vb_type;
- elem_types[0] = LLVMInt32Type();
- elem_types[1] = LLVMInt32Type();
- elem_types[2] = LLVMInt32Type();
- elem_types[3] = LLVMPointerType(LLVMOpaqueType(), 0); /* vs_constants */
+/**
+ * Create LLVM type for struct pipe_vertex_buffer
+ */
+static LLVMTypeRef
+create_jit_vertex_buffer_type(struct gallivm_state *gallivm)
+{
+ LLVMTargetDataRef target = gallivm->target;
+ LLVMTypeRef elem_types[4];
+ LLVMTypeRef vb_type;
- vb_type = LLVMStructType(elem_types, Elements(elem_types), 0);
+ elem_types[0] =
+ elem_types[1] =
+ elem_types[2] = LLVMInt32TypeInContext(gallivm->context);
+ elem_types[3] = LLVMPointerType(LLVMOpaqueTypeInContext(gallivm->context), 0); /* vs_constants */
- LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, stride,
- llvm->target, vb_type, 0);
- LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, buffer_offset,
- llvm->target, vb_type, 2);
- LP_CHECK_STRUCT_SIZE(struct pipe_vertex_buffer,
- llvm->target, vb_type);
+ vb_type = LLVMStructTypeInContext(gallivm->context, elem_types,
+ Elements(elem_types), 0);
- LLVMAddTypeName(llvm->module, "pipe_vertex_buffer", vb_type);
+ LLVMInvalidateStructLayout(gallivm->target, vb_type);
- llvm->vb_ptr_type = LLVMPointerType(vb_type, 0);
- }
+ LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, stride,
+ target, vb_type, 0);
+ LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, buffer_offset,
+ target, vb_type, 2);
+
+ LP_CHECK_STRUCT_SIZE(struct pipe_vertex_buffer, target, vb_type);
+
+ return vb_type;
}
+
+/**
+ * Create LLVM type for struct vertex_header;
+ */
static LLVMTypeRef
-create_vertex_header(struct draw_llvm *llvm, int data_elems)
+create_jit_vertex_header(struct gallivm_state *gallivm, int data_elems)
{
- /* struct vertex_header */
+ LLVMTargetDataRef target = gallivm->target;
LLVMTypeRef elem_types[3];
LLVMTypeRef vertex_header;
char struct_name[24];
util_snprintf(struct_name, 23, "vertex_header%d", data_elems);
- elem_types[0] = LLVMIntType(32);
- elem_types[1] = LLVMArrayType(LLVMFloatType(), 4);
+ elem_types[0] = LLVMIntTypeInContext(gallivm->context, 32);
+ elem_types[1] = LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
elem_types[2] = LLVMArrayType(elem_types[1], data_elems);
- vertex_header = LLVMStructType(elem_types, Elements(elem_types), 0);
+ vertex_header = LLVMStructTypeInContext(gallivm->context, elem_types,
+ Elements(elem_types), 0);
+
+ LLVMInvalidateStructLayout(gallivm->target, vertex_header);
/* these are bit-fields and we can't take address of them
LP_CHECK_MEMBER_OFFSET(struct vertex_header, clipmask,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_CLIPMASK);
LP_CHECK_MEMBER_OFFSET(struct vertex_header, edgeflag,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_EDGEFLAG);
LP_CHECK_MEMBER_OFFSET(struct vertex_header, pad,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_PAD);
LP_CHECK_MEMBER_OFFSET(struct vertex_header, vertex_id,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_VERTEX_ID);
*/
LP_CHECK_MEMBER_OFFSET(struct vertex_header, clip,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_CLIP);
LP_CHECK_MEMBER_OFFSET(struct vertex_header, data,
- llvm->target, vertex_header,
+ target, vertex_header,
DRAW_JIT_VERTEX_DATA);
- LLVMAddTypeName(llvm->module, struct_name, vertex_header);
+ LLVMAddTypeName(gallivm->module, struct_name, vertex_header);
- return LLVMPointerType(vertex_header, 0);
+ return vertex_header;
}
-struct draw_llvm *
-draw_llvm_create(struct draw_context *draw)
+
+/**
+ * Create LLVM types for various structures.
+ */
+static void
+create_jit_types(struct draw_llvm *llvm)
{
- struct draw_llvm *llvm;
+ struct gallivm_state *gallivm = llvm->gallivm;
+ LLVMTypeRef texture_type, context_type, buffer_type, vb_type;
- llvm = CALLOC_STRUCT( draw_llvm );
- if (!llvm)
- return NULL;
+ texture_type = create_jit_texture_type(gallivm);
+ LLVMAddTypeName(gallivm->module, "texture", texture_type);
- llvm->draw = draw;
- llvm->engine = draw->engine;
+ context_type = create_jit_context_type(gallivm, texture_type);
+ LLVMAddTypeName(gallivm->module, "draw_jit_context", context_type);
+ llvm->context_ptr_type = LLVMPointerType(context_type, 0);
- debug_assert(llvm->engine);
+ buffer_type = LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 8), 0);
+ LLVMAddTypeName(gallivm->module, "buffer", buffer_type);
+ llvm->buffer_ptr_type = LLVMPointerType(buffer_type, 0);
- llvm->module = LLVMModuleCreateWithName("draw_llvm");
- llvm->provider = LLVMCreateModuleProviderForExistingModule(llvm->module);
+ vb_type = create_jit_vertex_buffer_type(gallivm);
+ LLVMAddTypeName(gallivm->module, "pipe_vertex_buffer", vb_type);
+ llvm->vb_ptr_type = LLVMPointerType(vb_type, 0);
+}
- LLVMAddModuleProvider(llvm->engine, llvm->provider);
- llvm->target = LLVMGetExecutionEngineTargetData(llvm->engine);
+static LLVMTypeRef
+get_context_ptr_type(struct draw_llvm *llvm)
+{
+ if (!llvm->context_ptr_type)
+ create_jit_types(llvm);
+ return llvm->context_ptr_type;
+}
- llvm->pass = LLVMCreateFunctionPassManager(llvm->provider);
- LLVMAddTargetData(llvm->target, llvm->pass);
- if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
- /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
- * but there are more on SVN. */
- /* TODO: Add more passes */
+static LLVMTypeRef
+get_buffer_ptr_type(struct draw_llvm *llvm)
+{
+ if (!llvm->buffer_ptr_type)
+ create_jit_types(llvm);
+ return llvm->buffer_ptr_type;
+}
- LLVMAddCFGSimplificationPass(llvm->pass);
- if (HAVE_LLVM >= 0x207 && sizeof(void*) == 4) {
- /* For LLVM >= 2.7 and 32-bit build, use this order of passes to
- * avoid generating bad code.
- * Test with piglit glsl-vs-sqrt-zero test.
- */
- LLVMAddConstantPropagationPass(llvm->pass);
- LLVMAddPromoteMemoryToRegisterPass(llvm->pass);
- }
- else {
- LLVMAddPromoteMemoryToRegisterPass(llvm->pass);
- LLVMAddConstantPropagationPass(llvm->pass);
- }
+static LLVMTypeRef
+get_vb_ptr_type(struct draw_llvm *llvm)
+{
+ if (!llvm->vb_ptr_type)
+ create_jit_types(llvm);
+ return llvm->vb_ptr_type;
+}
- LLVMAddInstructionCombiningPass(llvm->pass);
- LLVMAddGVNPass(llvm->pass);
- } else {
- /* We need at least this pass to prevent the backends to fail in
- * unexpected ways.
- */
- LLVMAddPromoteMemoryToRegisterPass(llvm->pass);
- }
+static LLVMTypeRef
+get_vertex_header_ptr_type(struct draw_llvm *llvm)
+{
+ if (!llvm->vertex_header_ptr_type)
+ create_jit_types(llvm);
+ return llvm->vertex_header_ptr_type;
+}
- init_globals(llvm);
+
+/**
+ * Create per-context LLVM info.
+ */
+struct draw_llvm *
+draw_llvm_create(struct draw_context *draw, struct gallivm_state *gallivm)
+{
+ struct draw_llvm *llvm;
+
+ llvm = CALLOC_STRUCT( draw_llvm );
+ if (!llvm)
+ return NULL;
+
+ lp_build_init();
+
+ llvm->draw = draw;
+ llvm->gallivm = gallivm;
if (gallivm_debug & GALLIVM_DEBUG_IR) {
- LLVMDumpModule(llvm->module);
+ LLVMDumpModule(llvm->gallivm->module);
}
llvm->nr_variants = 0;
make_empty_list(&llvm->vs_variants_list);
+ gallivm_register_garbage_collector_callback(
+ draw_llvm_garbage_collect_callback, llvm);
+
return llvm;
}
+
+/**
+ * Free per-context LLVM info.
+ */
void
draw_llvm_destroy(struct draw_llvm *llvm)
{
- LLVMDisposePassManager(llvm->pass);
+ gallivm_remove_garbage_collector_callback(
+ draw_llvm_garbage_collect_callback, llvm);
+ /* XXX free other draw_llvm data? */
FREE(llvm);
}
+
+/**
+ * Create LLVM-generated code for a vertex shader.
+ */
struct draw_llvm_variant *
draw_llvm_create_variant(struct draw_llvm *llvm,
unsigned num_inputs,
@@ -310,6 +404,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
struct draw_llvm_variant *variant;
struct llvm_vertex_shader *shader =
llvm_vertex_shader(llvm->draw->vs.vertex_shader);
+ LLVMTypeRef vertex_header;
variant = MALLOC(sizeof *variant +
shader->variant_key_size -
@@ -321,7 +416,9 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
memcpy(&variant->key, key, shader->variant_key_size);
- llvm->vertex_header_ptr_type = create_vertex_header(llvm, num_inputs);
+ vertex_header = create_jit_vertex_header(llvm->gallivm, num_inputs);
+
+ llvm->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0);
draw_llvm_generate(llvm, variant);
draw_llvm_generate_elts(llvm, variant);
@@ -345,7 +442,7 @@ generate_vs(struct draw_llvm *llvm,
{
const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens;
struct lp_type vs_type;
- LLVMValueRef consts_ptr = draw_jit_context_vs_constants(builder, context_ptr);
+ LLVMValueRef consts_ptr = draw_jit_context_vs_constants(llvm->gallivm, context_ptr);
struct lp_build_sampler_soa *sampler = 0;
memset(&vs_type, 0, sizeof vs_type);
@@ -366,7 +463,7 @@ generate_vs(struct draw_llvm *llvm,
llvm->draw->num_samplers)
sampler = draw_sampler;
- lp_build_tgsi_soa(builder,
+ lp_build_tgsi_soa(llvm->gallivm,
tokens,
vs_type,
NULL /*struct lp_build_mask_context *mask*/,
@@ -384,20 +481,20 @@ static void print_vectorf(LLVMBuilderRef builder,
{
LLVMValueRef val[4];
val[0] = LLVMBuildExtractElement(builder, vec,
- LLVMConstInt(LLVMInt32Type(), 0, 0), "");
+ lp_build_const_int32(gallivm, 0), "");
val[1] = LLVMBuildExtractElement(builder, vec,
- LLVMConstInt(LLVMInt32Type(), 1, 0), "");
+ lp_build_const_int32(gallivm, 1), "");
val[2] = LLVMBuildExtractElement(builder, vec,
- LLVMConstInt(LLVMInt32Type(), 2, 0), "");
+ lp_build_const_int32(gallivm, 2), "");
val[3] = LLVMBuildExtractElement(builder, vec,
- LLVMConstInt(LLVMInt32Type(), 3, 0), "");
+ lp_build_const_int32(gallivm, 3), "");
lp_build_printf(builder, "vector = [%f, %f, %f, %f]\n",
val[0], val[1], val[2], val[3]);
}
#endif
static void
-generate_fetch(LLVMBuilderRef builder,
+generate_fetch(struct gallivm_state *gallivm,
LLVMValueRef vbuffers_ptr,
LLVMValueRef *res,
struct pipe_vertex_element *velem,
@@ -405,19 +502,22 @@ generate_fetch(LLVMBuilderRef builder,
LLVMValueRef index,
LLVMValueRef instance_id)
{
- LLVMValueRef indices = LLVMConstInt(LLVMInt64Type(), velem->vertex_buffer_index, 0);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef indices =
+ LLVMConstInt(LLVMInt64TypeInContext(gallivm->context),
+ velem->vertex_buffer_index, 0);
LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr,
&indices, 1, "");
- LLVMValueRef vb_stride = draw_jit_vbuffer_stride(builder, vbuf);
- LLVMValueRef vb_max_index = draw_jit_vbuffer_max_index(builder, vbuf);
- LLVMValueRef vb_buffer_offset = draw_jit_vbuffer_offset(builder, vbuf);
+ LLVMValueRef vb_stride = draw_jit_vbuffer_stride(gallivm, vbuf);
+ LLVMValueRef vb_max_index = draw_jit_vbuffer_max_index(gallivm, vbuf);
+ LLVMValueRef vb_buffer_offset = draw_jit_vbuffer_offset(gallivm, vbuf);
LLVMValueRef cond;
LLVMValueRef stride;
if (velem->instance_divisor) {
/* array index = instance_id / instance_divisor */
index = LLVMBuildUDiv(builder, instance_id,
- LLVMConstInt(LLVMInt32Type(), velem->instance_divisor, 0),
+ lp_build_const_int32(gallivm, velem->instance_divisor),
"instance_divisor");
}
@@ -433,23 +533,24 @@ generate_fetch(LLVMBuilderRef builder,
vb_buffer_offset,
"");
stride = LLVMBuildAdd(builder, stride,
- LLVMConstInt(LLVMInt32Type(), velem->src_offset, 0),
+ lp_build_const_int32(gallivm, velem->src_offset),
"");
/*lp_build_printf(builder, "vbuf index = %d, stride is %d\n", indices, stride);*/
vbuffer_ptr = LLVMBuildGEP(builder, vbuffer_ptr, &stride, 1, "");
- *res = draw_llvm_translate_from(builder, vbuffer_ptr, velem->src_format);
+ *res = draw_llvm_translate_from(gallivm, vbuffer_ptr, velem->src_format);
}
static LLVMValueRef
-aos_to_soa(LLVMBuilderRef builder,
+aos_to_soa(struct gallivm_state *gallivm,
LLVMValueRef val0,
LLVMValueRef val1,
LLVMValueRef val2,
LLVMValueRef val3,
LLVMValueRef channel)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef ex, res;
ex = LLVMBuildExtractElement(builder, val0,
@@ -457,38 +558,39 @@ aos_to_soa(LLVMBuilderRef builder,
res = LLVMBuildInsertElement(builder,
LLVMConstNull(LLVMTypeOf(val0)),
ex,
- LLVMConstInt(LLVMInt32Type(), 0, 0),
+ lp_build_const_int32(gallivm, 0),
"");
ex = LLVMBuildExtractElement(builder, val1,
channel, "");
res = LLVMBuildInsertElement(builder,
res, ex,
- LLVMConstInt(LLVMInt32Type(), 1, 0),
+ lp_build_const_int32(gallivm, 1),
"");
ex = LLVMBuildExtractElement(builder, val2,
channel, "");
res = LLVMBuildInsertElement(builder,
res, ex,
- LLVMConstInt(LLVMInt32Type(), 2, 0),
+ lp_build_const_int32(gallivm, 2),
"");
ex = LLVMBuildExtractElement(builder, val3,
channel, "");
res = LLVMBuildInsertElement(builder,
res, ex,
- LLVMConstInt(LLVMInt32Type(), 3, 0),
+ lp_build_const_int32(gallivm, 3),
"");
return res;
}
static void
-soa_to_aos(LLVMBuilderRef builder,
+soa_to_aos(struct gallivm_state *gallivm,
LLVMValueRef soa[NUM_CHANNELS],
LLVMValueRef aos[NUM_CHANNELS])
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef comp;
int i = 0;
@@ -498,29 +600,29 @@ soa_to_aos(LLVMBuilderRef builder,
aos[1] = aos[2] = aos[3] = aos[0];
for (i = 0; i < NUM_CHANNELS; ++i) {
- LLVMValueRef channel = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef channel = lp_build_const_int32(gallivm, i);
comp = LLVMBuildExtractElement(builder, soa[i],
- LLVMConstInt(LLVMInt32Type(), 0, 0), "");
+ lp_build_const_int32(gallivm, 0), "");
aos[0] = LLVMBuildInsertElement(builder, aos[0], comp, channel, "");
comp = LLVMBuildExtractElement(builder, soa[i],
- LLVMConstInt(LLVMInt32Type(), 1, 0), "");
+ lp_build_const_int32(gallivm, 1), "");
aos[1] = LLVMBuildInsertElement(builder, aos[1], comp, channel, "");
comp = LLVMBuildExtractElement(builder, soa[i],
- LLVMConstInt(LLVMInt32Type(), 2, 0), "");
+ lp_build_const_int32(gallivm, 2), "");
aos[2] = LLVMBuildInsertElement(builder, aos[2], comp, channel, "");
comp = LLVMBuildExtractElement(builder, soa[i],
- LLVMConstInt(LLVMInt32Type(), 3, 0), "");
+ lp_build_const_int32(gallivm, 3), "");
aos[3] = LLVMBuildInsertElement(builder, aos[3], comp, channel, "");
}
}
static void
-convert_to_soa(LLVMBuilderRef builder,
+convert_to_soa(struct gallivm_state *gallivm,
LLVMValueRef (*aos)[NUM_CHANNELS],
LLVMValueRef (*soa)[NUM_CHANNELS],
int num_attribs)
@@ -535,36 +637,37 @@ convert_to_soa(LLVMBuilderRef builder,
LLVMValueRef val2 = aos[i][2];
LLVMValueRef val3 = aos[i][3];
- soa[i][0] = aos_to_soa(builder, val0, val1, val2, val3,
- LLVMConstInt(LLVMInt32Type(), 0, 0));
- soa[i][1] = aos_to_soa(builder, val0, val1, val2, val3,
- LLVMConstInt(LLVMInt32Type(), 1, 0));
- soa[i][2] = aos_to_soa(builder, val0, val1, val2, val3,
- LLVMConstInt(LLVMInt32Type(), 2, 0));
- soa[i][3] = aos_to_soa(builder, val0, val1, val2, val3,
- LLVMConstInt(LLVMInt32Type(), 3, 0));
+ soa[i][0] = aos_to_soa(gallivm, val0, val1, val2, val3,
+ lp_build_const_int32(gallivm, 0));
+ soa[i][1] = aos_to_soa(gallivm, val0, val1, val2, val3,
+ lp_build_const_int32(gallivm, 1));
+ soa[i][2] = aos_to_soa(gallivm, val0, val1, val2, val3,
+ lp_build_const_int32(gallivm, 2));
+ soa[i][3] = aos_to_soa(gallivm, val0, val1, val2, val3,
+ lp_build_const_int32(gallivm, 3));
}
}
static void
-store_aos(LLVMBuilderRef builder,
+store_aos(struct gallivm_state *gallivm,
LLVMValueRef io_ptr,
LLVMValueRef index,
LLVMValueRef value,
LLVMValueRef clipmask)
{
- LLVMValueRef id_ptr = draw_jit_header_id(builder, io_ptr);
- LLVMValueRef data_ptr = draw_jit_header_data(builder, io_ptr);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_ptr);
+ LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_ptr);
LLVMValueRef indices[3];
LLVMValueRef val, shift;
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = index;
- indices[2] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[2] = lp_build_const_int32(gallivm, 0);
/* initialize vertex id:16 = 0xffff, pad:3 = 0, edgeflag:1 = 1 */
- val = LLVMConstInt(LLVMInt32Type(), 0xffff1, 0);
- shift = LLVMConstInt(LLVMInt32Type(), 12, 0);
+ val = lp_build_const_int32(gallivm, 0xffff1);
+ shift = lp_build_const_int32(gallivm, 12);
val = LLVMBuildShl(builder, val, shift, "");
/* add clipmask:12 */
val = LLVMBuildOr(builder, val, clipmask, "");
@@ -580,7 +683,7 @@ store_aos(LLVMBuilderRef builder,
/*lp_build_printf(builder, " ---- %p storing at %d (%p) ", io_ptr, index, data_ptr);
print_vectorf(builder, value);*/
data_ptr = LLVMBuildBitCast(builder, data_ptr,
- LLVMPointerType(LLVMArrayType(LLVMVectorType(LLVMFloatType(), 4), 0), 0),
+ LLVMPointerType(LLVMArrayType(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), 0), 0),
"datavec");
data_ptr = LLVMBuildGEP(builder, data_ptr, indices, 2, "");
@@ -592,10 +695,10 @@ store_aos(LLVMBuilderRef builder,
LLVMValueRef gep0, gep1, gep2, gep3;
data_ptr = LLVMBuildGEP(builder, data_ptr, indices, 3, "");
- idx0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
- idx1 = LLVMConstInt(LLVMInt32Type(), 1, 0);
- idx2 = LLVMConstInt(LLVMInt32Type(), 2, 0);
- idx3 = LLVMConstInt(LLVMInt32Type(), 3, 0);
+ idx0 = lp_build_const_int32(gallivm, 0);
+ idx1 = lp_build_const_int32(gallivm, 1);
+ idx2 = lp_build_const_int32(gallivm, 2);
+ idx3 = lp_build_const_int32(gallivm, 3);
x = LLVMBuildExtractElement(builder, value,
idx0, "");
@@ -622,18 +725,19 @@ store_aos(LLVMBuilderRef builder,
}
static void
-store_aos_array(LLVMBuilderRef builder,
+store_aos_array(struct gallivm_state *gallivm,
LLVMValueRef io_ptr,
LLVMValueRef aos[NUM_CHANNELS],
int attrib,
int num_outputs,
LLVMValueRef clipmask)
{
- LLVMValueRef attr_index = LLVMConstInt(LLVMInt32Type(), attrib, 0);
- LLVMValueRef ind0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
- LLVMValueRef ind1 = LLVMConstInt(LLVMInt32Type(), 1, 0);
- LLVMValueRef ind2 = LLVMConstInt(LLVMInt32Type(), 2, 0);
- LLVMValueRef ind3 = LLVMConstInt(LLVMInt32Type(), 3, 0);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef attr_index = lp_build_const_int32(gallivm, attrib);
+ LLVMValueRef ind0 = lp_build_const_int32(gallivm, 0);
+ LLVMValueRef ind1 = lp_build_const_int32(gallivm, 1);
+ LLVMValueRef ind2 = lp_build_const_int32(gallivm, 2);
+ LLVMValueRef ind3 = lp_build_const_int32(gallivm, 3);
LLVMValueRef io0_ptr, io1_ptr, io2_ptr, io3_ptr;
LLVMValueRef clipmask0, clipmask1, clipmask2, clipmask3;
@@ -662,20 +766,21 @@ store_aos_array(LLVMBuilderRef builder,
io_ptr, ind0, ind1, ind2, ind3, clipmask0, clipmask1, clipmask2, clipmask3);
#endif
/* store for each of the 4 vertices */
- store_aos(builder, io0_ptr, attr_index, aos[0], clipmask0);
- store_aos(builder, io1_ptr, attr_index, aos[1], clipmask1);
- store_aos(builder, io2_ptr, attr_index, aos[2], clipmask2);
- store_aos(builder, io3_ptr, attr_index, aos[3], clipmask3);
+ store_aos(gallivm, io0_ptr, attr_index, aos[0], clipmask0);
+ store_aos(gallivm, io1_ptr, attr_index, aos[1], clipmask1);
+ store_aos(gallivm, io2_ptr, attr_index, aos[2], clipmask2);
+ store_aos(gallivm, io3_ptr, attr_index, aos[3], clipmask3);
}
static void
-convert_to_aos(LLVMBuilderRef builder,
+convert_to_aos(struct gallivm_state *gallivm,
LLVMValueRef io,
LLVMValueRef (*outputs)[NUM_CHANNELS],
LLVMValueRef clipmask,
int num_outputs,
int max_vertices)
{
+ LLVMBuilderRef builder = gallivm->builder;
unsigned chan, attrib;
#if DEBUG_STORE
@@ -696,8 +801,8 @@ convert_to_aos(LLVMBuilderRef builder,
} else
soa[chan] = 0;
}
- soa_to_aos(builder, soa, aos);
- store_aos_array(builder,
+ soa_to_aos(gallivm, soa, aos);
+ store_aos_array(gallivm,
io,
aos,
attrib,
@@ -715,10 +820,11 @@ convert_to_aos(LLVMBuilderRef builder,
* rather than extracting each element one by one.
*/
static void
-store_clip(LLVMBuilderRef builder,
+store_clip(struct gallivm_state *gallivm,
LLVMValueRef io_ptr,
LLVMValueRef (*outputs)[NUM_CHANNELS])
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef out[4];
LLVMValueRef indices[2];
LLVMValueRef io0_ptr, io1_ptr, io2_ptr, io3_ptr;
@@ -727,13 +833,13 @@ store_clip(LLVMBuilderRef builder,
LLVMValueRef out0elem, out1elem, out2elem, out3elem;
int i;
- LLVMValueRef ind0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
- LLVMValueRef ind1 = LLVMConstInt(LLVMInt32Type(), 1, 0);
- LLVMValueRef ind2 = LLVMConstInt(LLVMInt32Type(), 2, 0);
- LLVMValueRef ind3 = LLVMConstInt(LLVMInt32Type(), 3, 0);
+ LLVMValueRef ind0 = lp_build_const_int32(gallivm, 0);
+ LLVMValueRef ind1 = lp_build_const_int32(gallivm, 1);
+ LLVMValueRef ind2 = lp_build_const_int32(gallivm, 2);
+ LLVMValueRef ind3 = lp_build_const_int32(gallivm, 3);
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
- indices[1] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[0] =
+ indices[1] = lp_build_const_int32(gallivm, 0);
out[0] = LLVMBuildLoad(builder, outputs[0][0], ""); /*x0 x1 x2 x3*/
out[1] = LLVMBuildLoad(builder, outputs[0][1], ""); /*y0 y1 y2 y3*/
@@ -745,29 +851,21 @@ store_clip(LLVMBuilderRef builder,
io2_ptr = LLVMBuildGEP(builder, io_ptr, &ind2, 1, "");
io3_ptr = LLVMBuildGEP(builder, io_ptr, &ind3, 1, "");
- clip_ptr0 = draw_jit_header_clip(builder, io0_ptr);
- clip_ptr1 = draw_jit_header_clip(builder, io1_ptr);
- clip_ptr2 = draw_jit_header_clip(builder, io2_ptr);
- clip_ptr3 = draw_jit_header_clip(builder, io3_ptr);
+ clip_ptr0 = draw_jit_header_clip(gallivm, io0_ptr);
+ clip_ptr1 = draw_jit_header_clip(gallivm, io1_ptr);
+ clip_ptr2 = draw_jit_header_clip(gallivm, io2_ptr);
+ clip_ptr3 = draw_jit_header_clip(gallivm, io3_ptr);
for (i = 0; i<4; i++){
- clip0_ptr = LLVMBuildGEP(builder, clip_ptr0,
- indices, 2, ""); //x0
- clip1_ptr = LLVMBuildGEP(builder, clip_ptr1,
- indices, 2, ""); //x1
- clip2_ptr = LLVMBuildGEP(builder, clip_ptr2,
- indices, 2, ""); //x2
- clip3_ptr = LLVMBuildGEP(builder, clip_ptr3,
- indices, 2, ""); //x3
-
- out0elem = LLVMBuildExtractElement(builder, out[i],
- ind0, ""); //x0
- out1elem = LLVMBuildExtractElement(builder, out[i],
- ind1, ""); //x1
- out2elem = LLVMBuildExtractElement(builder, out[i],
- ind2, ""); //x2
- out3elem = LLVMBuildExtractElement(builder, out[i],
- ind3, ""); //x3
+ clip0_ptr = LLVMBuildGEP(builder, clip_ptr0, indices, 2, ""); /* x0 */
+ clip1_ptr = LLVMBuildGEP(builder, clip_ptr1, indices, 2, ""); /* x1 */
+ clip2_ptr = LLVMBuildGEP(builder, clip_ptr2, indices, 2, ""); /* x2 */
+ clip3_ptr = LLVMBuildGEP(builder, clip_ptr3, indices, 2, ""); /* x3 */
+
+ out0elem = LLVMBuildExtractElement(builder, out[i], ind0, ""); /* x0 */
+ out1elem = LLVMBuildExtractElement(builder, out[i], ind1, ""); /* x1 */
+ out2elem = LLVMBuildExtractElement(builder, out[i], ind2, ""); /* x2 */
+ out3elem = LLVMBuildExtractElement(builder, out[i], ind3, ""); /* x3 */
LLVMBuildStore(builder, out0elem, clip0_ptr);
LLVMBuildStore(builder, out1elem, clip1_ptr);
@@ -781,16 +879,19 @@ store_clip(LLVMBuilderRef builder,
/* Equivalent of _mm_set1_ps(a)
*/
-static LLVMValueRef vec4f_from_scalar(LLVMBuilderRef bld,
- LLVMValueRef a,
- const char *name)
+static LLVMValueRef
+vec4f_from_scalar(struct gallivm_state *gallivm,
+ LLVMValueRef a,
+ const char *name)
{
- LLVMValueRef res = LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4));
+ LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context);
+ LLVMValueRef res = LLVMGetUndef(LLVMVectorType(float_type, 4));
int i;
for(i = 0; i < 4; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(bld, res, a, index, i == 3 ? name : "");
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
+ res = LLVMBuildInsertElement(gallivm->builder, res, a,
+ index, i == 3 ? name : "");
}
return res;
@@ -806,10 +907,11 @@ generate_viewport(struct draw_llvm *llvm,
LLVMValueRef context_ptr)
{
int i;
+ struct gallivm_state *gallivm = llvm->gallivm;
struct lp_type f32_type = lp_type_float_vec(32);
LLVMValueRef out3 = LLVMBuildLoad(builder, outputs[0][3], ""); /*w0 w1 w2 w3*/
- LLVMValueRef const1 = lp_build_const_vec(f32_type, 1.0); /*1.0 1.0 1.0 1.0*/
- LLVMValueRef vp_ptr = draw_jit_context_viewport(builder, context_ptr);
+ LLVMValueRef const1 = lp_build_const_vec(gallivm, f32_type, 1.0); /*1.0 1.0 1.0 1.0*/
+ LLVMValueRef vp_ptr = draw_jit_context_viewport(gallivm, context_ptr);
/* for 1/w convention*/
out3 = LLVMBuildFDiv(builder, const1, out3, "");
@@ -824,14 +926,14 @@ generate_viewport(struct draw_llvm *llvm,
LLVMValueRef trans_i;
LLVMValueRef index;
- index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ index = lp_build_const_int32(gallivm, i);
scale_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, "");
- index = LLVMConstInt(LLVMInt32Type(), i+4, 0);
+ index = lp_build_const_int32(gallivm, i+4);
trans_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, "");
- scale = vec4f_from_scalar(builder, LLVMBuildLoad(builder, scale_i, ""), "scale");
- trans = vec4f_from_scalar(builder, LLVMBuildLoad(builder, trans_i, ""), "trans");
+ scale = vec4f_from_scalar(gallivm, LLVMBuildLoad(builder, scale_i, ""), "scale");
+ trans = vec4f_from_scalar(gallivm, LLVMBuildLoad(builder, trans_i, ""), "trans");
/* divide by w */
out = LLVMBuildFMul(builder, out, out3, "");
@@ -851,7 +953,7 @@ generate_viewport(struct draw_llvm *llvm,
* Returns clipmask as 4xi32 bitmask for the 4 vertices
*/
static LLVMValueRef
-generate_clipmask(LLVMBuilderRef builder,
+generate_clipmask(struct gallivm_state *gallivm,
LLVMValueRef (*outputs)[NUM_CHANNELS],
boolean clip_xy,
boolean clip_z,
@@ -860,6 +962,7 @@ generate_clipmask(LLVMBuilderRef builder,
unsigned nr,
LLVMValueRef context_ptr)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef mask; /* stores the <4xi32> clipmasks */
LLVMValueRef test, temp;
LLVMValueRef zero, shift;
@@ -870,10 +973,10 @@ generate_clipmask(LLVMBuilderRef builder,
struct lp_type f32_type = lp_type_float_vec(32);
- mask = lp_build_const_int_vec(lp_type_int_vec(32), 0);
- temp = lp_build_const_int_vec(lp_type_int_vec(32), 0);
- zero = lp_build_const_vec(f32_type, 0); /* 0.0f 0.0f 0.0f 0.0f */
- shift = lp_build_const_int_vec(lp_type_int_vec(32), 1); /* 1 1 1 1 */
+ mask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0);
+ temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0);
+ zero = lp_build_const_vec(gallivm, f32_type, 0); /* 0.0f 0.0f 0.0f 0.0f */
+ shift = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 1); /* 1 1 1 1 */
/* Assuming position stored at output[0] */
pos_x = LLVMBuildLoad(builder, outputs[0][0], ""); /*x0 x1 x2 x3*/
@@ -884,92 +987,92 @@ generate_clipmask(LLVMBuilderRef builder,
/* Cliptest, for hardwired planes */
if (clip_xy){
/* plane 1 */
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, pos_x , pos_w);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_x , pos_w);
temp = shift;
test = LLVMBuildAnd(builder, test, temp, "");
mask = test;
/* plane 2 */
test = LLVMBuildFAdd(builder, pos_x, pos_w, "");
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, zero, test);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test);
temp = LLVMBuildShl(builder, temp, shift, "");
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
/* plane 3 */
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, pos_y, pos_w);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_y, pos_w);
temp = LLVMBuildShl(builder, temp, shift, "");
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
/* plane 4 */
test = LLVMBuildFAdd(builder, pos_y, pos_w, "");
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, zero, test);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test);
temp = LLVMBuildShl(builder, temp, shift, "");
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
}
if (clip_z){
- temp = lp_build_const_int_vec(lp_type_int_vec(32), 16);
+ temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 16);
if (clip_halfz){
/* plane 5 */
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, zero, pos_z);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, pos_z);
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
}
else{
/* plane 5 */
test = LLVMBuildFAdd(builder, pos_z, pos_w, "");
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, zero, test);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test);
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
}
/* plane 6 */
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, pos_z, pos_w);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_z, pos_w);
temp = LLVMBuildShl(builder, temp, shift, "");
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
}
if (clip_user){
- LLVMValueRef planes_ptr = draw_jit_context_planes(builder, context_ptr);
+ LLVMValueRef planes_ptr = draw_jit_context_planes(gallivm, context_ptr);
LLVMValueRef indices[3];
- temp = lp_build_const_int_vec(lp_type_int_vec(32), 32);
+ temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 32);
/* userclip planes */
for (i = 6; i < nr; i++) {
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
- indices[1] = LLVMConstInt(LLVMInt32Type(), i, 0);
+ indices[0] = lp_build_const_int32(gallivm, 0);
+ indices[1] = lp_build_const_int32(gallivm, i);
- indices[2] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[2] = lp_build_const_int32(gallivm, 0);
plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_x");
- planes = vec4f_from_scalar(builder, plane1, "plane4_x");
+ planes = vec4f_from_scalar(gallivm, plane1, "plane4_x");
sum = LLVMBuildFMul(builder, planes, pos_x, "");
- indices[2] = LLVMConstInt(LLVMInt32Type(), 1, 0);
+ indices[2] = lp_build_const_int32(gallivm, 1);
plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_y");
- planes = vec4f_from_scalar(builder, plane1, "plane4_y");
+ planes = vec4f_from_scalar(gallivm, plane1, "plane4_y");
test = LLVMBuildFMul(builder, planes, pos_y, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
- indices[2] = LLVMConstInt(LLVMInt32Type(), 2, 0);
+ indices[2] = lp_build_const_int32(gallivm, 2);
plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_z");
- planes = vec4f_from_scalar(builder, plane1, "plane4_z");
+ planes = vec4f_from_scalar(gallivm, plane1, "plane4_z");
test = LLVMBuildFMul(builder, planes, pos_z, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
- indices[2] = LLVMConstInt(LLVMInt32Type(), 3, 0);
+ indices[2] = lp_build_const_int32(gallivm, 3);
plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_w");
- planes = vec4f_from_scalar(builder, plane1, "plane4_w");
+ planes = vec4f_from_scalar(gallivm, plane1, "plane4_w");
test = LLVMBuildFMul(builder, planes, pos_w, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
- test = lp_build_compare(builder, f32_type, PIPE_FUNC_GREATER, zero, sum);
+ test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, sum);
temp = LLVMBuildShl(builder, temp, shift, "");
test = LLVMBuildAnd(builder, test, temp, "");
mask = LLVMBuildOr(builder, mask, test, "");
@@ -983,17 +1086,18 @@ generate_clipmask(LLVMBuilderRef builder,
* Used zero/non-zero i32 value to represent boolean
*/
static void
-clipmask_bool(LLVMBuilderRef builder,
+clipmask_bool(struct gallivm_state *gallivm,
LLVMValueRef clipmask,
LLVMValueRef ret_ptr)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef ret = LLVMBuildLoad(builder, ret_ptr, "");
LLVMValueRef temp;
int i;
for (i=0; i<4; i++){
temp = LLVMBuildExtractElement(builder, clipmask,
- LLVMConstInt(LLVMInt32Type(), i, 0) , "");
+ lp_build_const_int32(gallivm, i) , "");
ret = LLVMBuildOr(builder, ret, temp, "");
}
@@ -1003,6 +1107,9 @@ clipmask_bool(LLVMBuilderRef builder,
static void
draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
{
+ struct gallivm_state *gallivm = llvm->gallivm;
+ LLVMContextRef context = gallivm->context;
+ LLVMTypeRef int32_type = LLVMInt32TypeInContext(context);
LLVMTypeRef arg_types[8];
LLVMTypeRef func_type;
LLVMValueRef context_ptr;
@@ -1025,18 +1132,19 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
variant->key.clip_z ||
variant->key.clip_user;
- arg_types[0] = llvm->context_ptr_type; /* context */
- arg_types[1] = llvm->vertex_header_ptr_type; /* vertex_header */
- arg_types[2] = llvm->buffer_ptr_type; /* vbuffers */
- arg_types[3] = LLVMInt32Type(); /* start */
- arg_types[4] = LLVMInt32Type(); /* count */
- arg_types[5] = LLVMInt32Type(); /* stride */
- arg_types[6] = llvm->vb_ptr_type; /* pipe_vertex_buffer's */
- arg_types[7] = LLVMInt32Type(); /* instance_id */
-
- func_type = LLVMFunctionType(LLVMInt32Type(), arg_types, Elements(arg_types), 0);
-
- variant->function = LLVMAddFunction(llvm->module, "draw_llvm_shader", func_type);
+ arg_types[0] = get_context_ptr_type(llvm); /* context */
+ arg_types[1] = get_vertex_header_ptr_type(llvm); /* vertex_header */
+ arg_types[2] = get_buffer_ptr_type(llvm); /* vbuffers */
+ arg_types[3] = int32_type; /* start */
+ arg_types[4] = int32_type; /* count */
+ arg_types[5] = int32_type; /* stride */
+ arg_types[6] = get_vb_ptr_type(llvm); /* pipe_vertex_buffer's */
+ arg_types[7] = int32_type; /* instance_id */
+
+ func_type = LLVMFunctionType(int32_type, arg_types, Elements(arg_types), 0);
+
+ variant->function = LLVMAddFunction(gallivm->module, "draw_llvm_shader",
+ func_type);
LLVMSetFunctionCallConv(variant->function, LLVMCCallConv);
for(i = 0; i < Elements(arg_types); ++i)
if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind)
@@ -1064,19 +1172,20 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
* Function body
*/
- block = LLVMAppendBasicBlock(variant->function, "entry");
- builder = LLVMCreateBuilder();
+ block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function, "entry");
+ builder = gallivm->builder;
+ assert(builder);
LLVMPositionBuilderAtEnd(builder, block);
- lp_build_context_init(&bld, builder, lp_type_int(32));
+ lp_build_context_init(&bld, llvm->gallivm, lp_type_int(32));
end = lp_build_add(&bld, start, count);
- step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0);
+ step = lp_build_const_int32(gallivm, max_vertices);
/* function will return non-zero i32 value if any clipped vertices */
- ret_ptr = lp_build_alloca(builder, LLVMInt32Type(), "");
- LLVMBuildStore(builder, LLVMConstInt(LLVMInt32Type(), 0, 0), ret_ptr);
+ ret_ptr = lp_build_alloca(gallivm, int32_type, "");
+ LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr);
/* code generated texture sampling */
sampler = draw_llvm_sampler_soa_create(
@@ -1087,7 +1196,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
lp_build_printf(builder, "start = %d, end = %d, step = %d\n",
start, end, step);
#endif
- lp_build_loop_begin(builder, start, &lp_loop);
+ lp_build_loop_begin(&lp_loop, llvm->gallivm, start);
{
LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS];
LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS] = { { 0 } };
@@ -1105,20 +1214,18 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
LLVMValueRef true_index = LLVMBuildAdd(
builder,
lp_loop.counter,
- LLVMConstInt(LLVMInt32Type(), i, 0), "");
+ lp_build_const_int32(gallivm, i), "");
for (j = 0; j < draw->pt.nr_vertex_elements; ++j) {
struct pipe_vertex_element *velem = &draw->pt.vertex_element[j];
- LLVMValueRef vb_index = LLVMConstInt(LLVMInt32Type(),
- velem->vertex_buffer_index,
- 0);
+ LLVMValueRef vb_index = lp_build_const_int32(gallivm, velem->vertex_buffer_index);
LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr,
&vb_index, 1, "");
- generate_fetch(builder, vbuffers_ptr,
+ generate_fetch(llvm->gallivm, vbuffers_ptr,
&aos_attribs[j][i], velem, vb, true_index,
instance_id);
}
}
- convert_to_soa(builder, aos_attribs, inputs,
+ convert_to_soa(gallivm, aos_attribs, inputs,
draw->pt.nr_vertex_elements);
ptr_aos = (const LLVMValueRef (*)[NUM_CHANNELS]) inputs;
@@ -1130,12 +1237,12 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
sampler);
/* store original positions in clip before further manipulation */
- store_clip(builder, io, outputs);
+ store_clip(gallivm, io, outputs);
/* do cliptest */
if (enable_cliptest){
/* allocate clipmask, assign it integer type */
- clipmask = generate_clipmask(builder, outputs,
+ clipmask = generate_clipmask(gallivm, outputs,
variant->key.clip_xy,
variant->key.clip_z,
variant->key.clip_user,
@@ -1143,10 +1250,10 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
variant->key.nr_planes,
context_ptr);
/* return clipping boolean value for function */
- clipmask_bool(builder, clipmask, ret_ptr);
+ clipmask_bool(gallivm, clipmask, ret_ptr);
}
else{
- clipmask = lp_build_const_int_vec(lp_type_int_vec(32), 0);
+ clipmask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0);
}
/* do viewport mapping */
@@ -1155,20 +1262,18 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
}
/* store clipmask in vertex header and positions in data */
- convert_to_aos(builder, io, outputs, clipmask,
+ convert_to_aos(gallivm, io, outputs, clipmask,
draw->vs.vertex_shader->info.num_outputs,
max_vertices);
}
- lp_build_loop_end_cond(builder, end, step, LLVMIntUGE, &lp_loop);
+ lp_build_loop_end_cond(&lp_loop, end, step, LLVMIntUGE);
sampler->destroy(sampler);
ret = LLVMBuildLoad(builder, ret_ptr,"");
LLVMBuildRet(builder, ret);
- LLVMDisposeBuilder(builder);
-
/*
* Translate the LLVM IR into machine code.
*/
@@ -1179,14 +1284,14 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
}
#endif
- LLVMRunFunctionPassManager(llvm->pass, variant->function);
+ LLVMRunFunctionPassManager(gallivm->passmgr, variant->function);
if (gallivm_debug & GALLIVM_DEBUG_IR) {
lp_debug_dump_value(variant->function);
debug_printf("\n");
}
- code = LLVMGetPointerToGlobal(llvm->draw->engine, variant->function);
+ code = LLVMGetPointerToGlobal(gallivm->engine, variant->function);
variant->jit_func = (draw_jit_vert_func)pointer_to_func(code);
if (gallivm_debug & GALLIVM_DEBUG_ASM) {
@@ -1199,6 +1304,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
static void
draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
{
+ struct gallivm_state *gallivm = llvm->gallivm;
+ LLVMContextRef context = gallivm->context;
+ LLVMTypeRef int32_type = LLVMInt32TypeInContext(context);
LLVMTypeRef arg_types[8];
LLVMTypeRef func_type;
LLVMValueRef context_ptr;
@@ -1222,18 +1330,18 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
variant->key.clip_z ||
variant->key.clip_user;
- arg_types[0] = llvm->context_ptr_type; /* context */
- arg_types[1] = llvm->vertex_header_ptr_type; /* vertex_header */
- arg_types[2] = llvm->buffer_ptr_type; /* vbuffers */
- arg_types[3] = LLVMPointerType(LLVMInt32Type(), 0); /* fetch_elts * */
- arg_types[4] = LLVMInt32Type(); /* fetch_count */
- arg_types[5] = LLVMInt32Type(); /* stride */
- arg_types[6] = llvm->vb_ptr_type; /* pipe_vertex_buffer's */
- arg_types[7] = LLVMInt32Type(); /* instance_id */
-
- func_type = LLVMFunctionType(LLVMInt32Type(), arg_types, Elements(arg_types), 0);
-
- variant->function_elts = LLVMAddFunction(llvm->module, "draw_llvm_shader_elts", func_type);
+ arg_types[0] = get_context_ptr_type(llvm); /* context */
+ arg_types[1] = get_vertex_header_ptr_type(llvm); /* vertex_header */
+ arg_types[2] = get_buffer_ptr_type(llvm); /* vbuffers */
+ arg_types[3] = LLVMPointerType(int32_type, 0); /* fetch_elts * */
+ arg_types[4] = int32_type; /* fetch_count */
+ arg_types[5] = int32_type; /* stride */
+ arg_types[6] = get_vb_ptr_type(llvm); /* pipe_vertex_buffer's */
+ arg_types[7] = int32_type; /* instance_id */
+
+ func_type = LLVMFunctionType(int32_type, arg_types, Elements(arg_types), 0);
+
+ variant->function_elts = LLVMAddFunction(gallivm->module, "draw_llvm_shader_elts", func_type);
LLVMSetFunctionCallConv(variant->function_elts, LLVMCCallConv);
for(i = 0; i < Elements(arg_types); ++i)
if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind)
@@ -1262,13 +1370,13 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
* Function body
*/
- block = LLVMAppendBasicBlock(variant->function_elts, "entry");
- builder = LLVMCreateBuilder();
+ block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function_elts, "entry");
+ builder = gallivm->builder;
LLVMPositionBuilderAtEnd(builder, block);
- lp_build_context_init(&bld, builder, lp_type_int(32));
+ lp_build_context_init(&bld, gallivm, lp_type_int(32));
- step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0);
+ step = lp_build_const_int32(gallivm, max_vertices);
/* code generated texture sampling */
sampler = draw_llvm_sampler_soa_create(
@@ -1276,14 +1384,14 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
context_ptr);
fetch_max = LLVMBuildSub(builder, fetch_count,
- LLVMConstInt(LLVMInt32Type(), 1, 0),
+ lp_build_const_int32(gallivm, 1),
"fetch_max");
/* function returns non-zero i32 value if any clipped vertices */
- ret_ptr = lp_build_alloca(builder, LLVMInt32Type(), "");
- LLVMBuildStore(builder, LLVMConstInt(LLVMInt32Type(), 0, 0), ret_ptr);
+ ret_ptr = lp_build_alloca(gallivm, int32_type, "");
+ LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr);
- lp_build_loop_begin(builder, LLVMConstInt(LLVMInt32Type(), 0, 0), &lp_loop);
+ lp_build_loop_begin(&lp_loop, gallivm, lp_build_const_int32(gallivm, 0));
{
LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS];
LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS] = { { 0 } };
@@ -1301,7 +1409,7 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
LLVMValueRef true_index = LLVMBuildAdd(
builder,
lp_loop.counter,
- LLVMConstInt(LLVMInt32Type(), i, 0), "");
+ lp_build_const_int32(gallivm, i), "");
LLVMValueRef fetch_ptr;
/* make sure we're not out of bounds which can happen
@@ -1314,17 +1422,15 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
true_index = LLVMBuildLoad(builder, fetch_ptr, "fetch_elt");
for (j = 0; j < draw->pt.nr_vertex_elements; ++j) {
struct pipe_vertex_element *velem = &draw->pt.vertex_element[j];
- LLVMValueRef vb_index = LLVMConstInt(LLVMInt32Type(),
- velem->vertex_buffer_index,
- 0);
+ LLVMValueRef vb_index = lp_build_const_int32(gallivm, velem->vertex_buffer_index);
LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr,
&vb_index, 1, "");
- generate_fetch(builder, vbuffers_ptr,
+ generate_fetch(gallivm, vbuffers_ptr,
&aos_attribs[j][i], velem, vb, true_index,
instance_id);
}
}
- convert_to_soa(builder, aos_attribs, inputs,
+ convert_to_soa(gallivm, aos_attribs, inputs,
draw->pt.nr_vertex_elements);
ptr_aos = (const LLVMValueRef (*)[NUM_CHANNELS]) inputs;
@@ -1336,12 +1442,12 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
sampler);
/* store original positions in clip before further manipulation */
- store_clip(builder, io, outputs);
+ store_clip(gallivm, io, outputs);
/* do cliptest */
if (enable_cliptest){
/* allocate clipmask, assign it integer type */
- clipmask = generate_clipmask(builder, outputs,
+ clipmask = generate_clipmask(gallivm, outputs,
variant->key.clip_xy,
variant->key.clip_z,
variant->key.clip_user,
@@ -1349,10 +1455,10 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
variant->key.nr_planes,
context_ptr);
/* return clipping boolean value for function */
- clipmask_bool(builder, clipmask, ret_ptr);
+ clipmask_bool(gallivm, clipmask, ret_ptr);
}
else{
- clipmask = lp_build_const_int_vec(lp_type_int_vec(32), 0);
+ clipmask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0);
}
/* do viewport mapping */
@@ -1364,20 +1470,18 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
* original positions in clip
* and transformed positions in data
*/
- convert_to_aos(builder, io, outputs, clipmask,
+ convert_to_aos(gallivm, io, outputs, clipmask,
draw->vs.vertex_shader->info.num_outputs,
max_vertices);
}
- lp_build_loop_end_cond(builder, fetch_count, step, LLVMIntUGE, &lp_loop);
+ lp_build_loop_end_cond(&lp_loop, fetch_count, step, LLVMIntUGE);
sampler->destroy(sampler);
ret = LLVMBuildLoad(builder, ret_ptr,"");
LLVMBuildRet(builder, ret);
- LLVMDisposeBuilder(builder);
-
/*
* Translate the LLVM IR into machine code.
*/
@@ -1388,14 +1492,14 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
}
#endif
- LLVMRunFunctionPassManager(llvm->pass, variant->function_elts);
+ LLVMRunFunctionPassManager(gallivm->passmgr, variant->function_elts);
if (gallivm_debug & GALLIVM_DEBUG_IR) {
lp_debug_dump_value(variant->function_elts);
debug_printf("\n");
}
- code = LLVMGetPointerToGlobal(llvm->draw->engine, variant->function_elts);
+ code = LLVMGetPointerToGlobal(gallivm->engine, variant->function_elts);
variant->jit_func_elts = (draw_jit_vert_func_elts)pointer_to_func(code);
if (gallivm_debug & GALLIVM_DEBUG_ASM) {
@@ -1504,19 +1608,16 @@ void
draw_llvm_destroy_variant(struct draw_llvm_variant *variant)
{
struct draw_llvm *llvm = variant->llvm;
- struct draw_context *draw = llvm->draw;
if (variant->function_elts) {
- if (variant->function_elts)
- LLVMFreeMachineCodeForFunction(draw->engine,
- variant->function_elts);
+ LLVMFreeMachineCodeForFunction(llvm->gallivm->engine,
+ variant->function_elts);
LLVMDeleteFunction(variant->function_elts);
}
if (variant->function) {
- if (variant->function)
- LLVMFreeMachineCodeForFunction(draw->engine,
- variant->function);
+ LLVMFreeMachineCodeForFunction(llvm->gallivm->engine,
+ variant->function);
LLVMDeleteFunction(variant->function);
}
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index c3c30c07c64..9f038f1f04d 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -103,41 +103,41 @@ struct draw_jit_context
};
-#define draw_jit_context_vs_constants(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 0, "vs_constants")
+#define draw_jit_context_vs_constants(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 0, "vs_constants")
-#define draw_jit_context_gs_constants(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 1, "gs_constants")
+#define draw_jit_context_gs_constants(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 1, "gs_constants")
-#define draw_jit_context_planes(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 2, "planes")
+#define draw_jit_context_planes(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 2, "planes")
-#define draw_jit_context_viewport(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 3, "viewport")
+#define draw_jit_context_viewport(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 3, "viewport")
#define DRAW_JIT_CTX_TEXTURES 4
-#define draw_jit_context_textures(_builder, _ptr) \
- lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
+#define draw_jit_context_textures(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
-#define draw_jit_header_id(_builder, _ptr) \
- lp_build_struct_get_ptr(_builder, _ptr, 0, "id")
+#define draw_jit_header_id(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, 0, "id")
-#define draw_jit_header_clip(_builder, _ptr) \
- lp_build_struct_get_ptr(_builder, _ptr, 1, "clip")
+#define draw_jit_header_clip(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, 1, "clip")
-#define draw_jit_header_data(_builder, _ptr) \
- lp_build_struct_get_ptr(_builder, _ptr, 2, "data")
+#define draw_jit_header_data(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, 2, "data")
-#define draw_jit_vbuffer_stride(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 0, "stride")
+#define draw_jit_vbuffer_stride(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 0, "stride")
-#define draw_jit_vbuffer_max_index(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 1, "max_index")
+#define draw_jit_vbuffer_max_index(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 1, "max_index")
-#define draw_jit_vbuffer_offset(_builder, _ptr) \
- lp_build_struct_get(_builder, _ptr, 2, "buffer_offset")
+#define draw_jit_vbuffer_offset(_gallivm, _ptr) \
+ lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
typedef int
@@ -229,7 +229,6 @@ struct draw_llvm_variant
/* key is variable-sized, must be last */
struct draw_llvm_variant_key key;
- /* key is variable-sized, must be last */
};
struct llvm_vertex_shader {
@@ -246,21 +245,19 @@ struct draw_llvm {
struct draw_jit_context jit_context;
+ struct gallivm_state *gallivm;
+
struct draw_llvm_variant_list_item vs_variants_list;
int nr_variants;
- LLVMModuleRef module;
- LLVMExecutionEngineRef engine;
- LLVMModuleProviderRef provider;
- LLVMTargetDataRef target;
- LLVMPassManagerRef pass;
-
+ /* LLVM JIT builder types */
LLVMTypeRef context_ptr_type;
- LLVMTypeRef vertex_header_ptr_type;
LLVMTypeRef buffer_ptr_type;
LLVMTypeRef vb_ptr_type;
+ LLVMTypeRef vertex_header_ptr_type;
};
+
static INLINE struct llvm_vertex_shader *
llvm_vertex_shader(struct draw_vertex_shader *vs)
{
@@ -269,7 +266,7 @@ llvm_vertex_shader(struct draw_vertex_shader *vs)
struct draw_llvm *
-draw_llvm_create(struct draw_context *draw);
+draw_llvm_create(struct draw_context *draw, struct gallivm_state *gallivm);
void
draw_llvm_destroy(struct draw_llvm *llvm);
@@ -286,7 +283,7 @@ struct draw_llvm_variant_key *
draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
LLVMValueRef
-draw_llvm_translate_from(LLVMBuilderRef builder,
+draw_llvm_translate_from(struct gallivm_state *gallivm,
LLVMValueRef vbuffer,
enum pipe_format from_format);
diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c
index ac1fbb179c6..574c7cc452f 100644
--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c
+++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c
@@ -32,6 +32,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
+#include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_debug.h"
#include "gallivm/lp_bld_type.h"
#include "gallivm/lp_bld_sample.h"
@@ -84,12 +85,13 @@ struct draw_llvm_sampler_soa
*/
static LLVMValueRef
draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit,
unsigned member_index,
const char *member_name,
boolean emit_load)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct draw_llvm_sampler_dynamic_state *state =
(struct draw_llvm_sampler_dynamic_state *)base;
LLVMValueRef indices[4];
@@ -99,13 +101,13 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
debug_assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
/* context[0] */
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[0] = lp_build_const_int32(gallivm, 0);
/* context[0].textures */
- indices[1] = LLVMConstInt(LLVMInt32Type(), DRAW_JIT_CTX_TEXTURES, 0);
+ indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
/* context[0].textures[unit] */
- indices[2] = LLVMConstInt(LLVMInt32Type(), unit, 0);
+ indices[2] = lp_build_const_int32(gallivm, unit);
/* context[0].textures[unit].member */
- indices[3] = LLVMConstInt(LLVMInt32Type(), member_index, 0);
+ indices[3] = lp_build_const_int32(gallivm, member_index);
ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
@@ -132,10 +134,10 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
#define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \
static LLVMValueRef \
draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
- LLVMBuilderRef builder, \
+ struct gallivm_state *gallivm, \
unsigned unit) \
{ \
- return draw_llvm_texture_member(base, builder, unit, _index, #_name, _emit_load ); \
+ return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \
}
@@ -165,7 +167,7 @@ draw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
*/
static void
draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
unsigned unit,
unsigned num_coords,
@@ -180,7 +182,7 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
- lp_build_sample_soa(builder,
+ lp_build_sample_soa(gallivm,
&sampler->dynamic_state.static_state[unit],
&sampler->dynamic_state.base,
type,
diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c
index 5171327ce2d..77d0af74733 100644
--- a/src/gallium/auxiliary/draw/draw_llvm_translate.c
+++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c
@@ -3,6 +3,7 @@
#include "draw_llvm.h"
+#include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_struct.h"
#include "gallivm/lp_bld_format.h"
#include "gallivm/lp_bld_debug.h"
@@ -16,272 +17,279 @@
#define DRAW_DBG 0
static LLVMValueRef
-from_64_float(LLVMBuilderRef builder, LLVMValueRef val)
+from_64_float(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMDoubleType(), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- return LLVMBuildFPTrunc(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMDoubleTypeInContext(gallivm->context), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ return LLVMBuildFPTrunc(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static LLVMValueRef
-from_32_float(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_float(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMFloatType(), 0) , "");
- return LLVMBuildLoad(builder, bc, "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0) , "");
+ return LLVMBuildLoad(gallivm->builder, bc, "");
}
static INLINE LLVMValueRef
-from_8_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef l = LLVMBuildLoad(builder, val, "");
- return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
+ return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_16_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(16), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_32_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(32), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_8_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef l = LLVMBuildLoad(builder, val, "");
- return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
+ return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_16_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(16), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_32_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(32), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
-from_8_unorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_8_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef l = LLVMBuildLoad(builder, val, "");
- LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 255.), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
+ LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 255.), "");
}
static INLINE LLVMValueRef
-from_16_unorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_16_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(16), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 65535.), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 65535.), "");
}
static INLINE LLVMValueRef
-from_32_unorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(32), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 4294967295.), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 4294967295.), "");
}
static INLINE LLVMValueRef
-from_8_snorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef l = LLVMBuildLoad(builder, val, "");
- LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 127.0), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
+ LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 127.0), "");
}
static INLINE LLVMValueRef
-from_16_snorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_16_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(16), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 32767.0f), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 32767.0f), "");
}
static INLINE LLVMValueRef
-from_32_snorm(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(32), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 2147483647.0), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 2147483647.0), "");
}
static INLINE LLVMValueRef
-from_32_fixed(LLVMBuilderRef builder, LLVMValueRef val)
+from_32_fixed(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef bc = LLVMBuildBitCast(builder, val,
- LLVMPointerType(LLVMIntType(32), 0) , "");
- LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
- LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
+ LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
+ LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
+ LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
- return LLVMBuildFDiv(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 65536.0), "");
+ return LLVMBuildFDiv(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 65536.0), "");
}
static LLVMValueRef
-to_64_float(LLVMBuilderRef builder, LLVMValueRef fp)
+to_64_float(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPExt(builder, l, LLVMDoubleType(), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPExt(gallivm->builder, l, LLVMDoubleTypeInContext(gallivm->context), "");
}
static LLVMValueRef
-to_32_float(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_float(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- return LLVMBuildLoad(builder, fp, "");
+ return LLVMBuildLoad(gallivm->builder, fp, "");
}
static INLINE LLVMValueRef
-to_8_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToUI(builder, l, LLVMIntType(8), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), "");
}
static INLINE LLVMValueRef
-to_16_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToUI(builder, l, LLVMIntType(16), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), "");
}
static INLINE LLVMValueRef
-to_32_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), "");
}
static INLINE LLVMValueRef
-to_8_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToSI(builder, l, LLVMIntType(8), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), "");
}
static INLINE LLVMValueRef
-to_16_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToSI(builder, l, LLVMIntType(16), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), "");
}
static INLINE LLVMValueRef
-to_32_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- return LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), "");
}
static INLINE LLVMValueRef
-to_8_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
+to_8_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(8), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 255.), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 8), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 255.), "");
}
static INLINE LLVMValueRef
-to_16_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
+to_16_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 65535.), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 32), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 65535.), "");
}
static INLINE LLVMValueRef
-to_32_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 32), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 4294967295.), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 4294967295.), "");
}
static INLINE LLVMValueRef
-to_8_snorm(LLVMBuilderRef builder, LLVMValueRef val)
+to_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
- LLVMValueRef l = LLVMBuildLoad(builder, val, "");
- LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(8), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 127.0), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
+ LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 8), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 127.0), "");
}
static INLINE LLVMValueRef
-to_16_snorm(LLVMBuilderRef builder, LLVMValueRef fp)
+to_16_snorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(16), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 32767.0f), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 16), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 32767.0f), "");
}
static INLINE LLVMValueRef
-to_32_snorm(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_snorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 32), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 2147483647.0), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 2147483647.0), "");
}
static INLINE LLVMValueRef
-to_32_fixed(LLVMBuilderRef builder, LLVMValueRef fp)
+to_32_fixed(struct gallivm_state *gallivm, LLVMValueRef fp)
{
- LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
- LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
+ LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
+ LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
+ LLVMIntTypeInContext(gallivm->context, 32), "");
- return LLVMBuildFMul(builder, uscaled,
- LLVMConstReal(LLVMFloatType(), 65536.0), "");
+ return LLVMBuildFMul(gallivm->builder, uscaled,
+ lp_build_const_float(gallivm, 65536.0), "");
}
-typedef LLVMValueRef (*from_func)(LLVMBuilderRef, LLVMValueRef);
-typedef LLVMValueRef (*to_func)(LLVMBuilderRef, LLVMValueRef);
+typedef LLVMValueRef (*from_func)(struct gallivm_state *, LLVMValueRef);
+typedef LLVMValueRef (*to_func)(struct gallivm_state *, LLVMValueRef);
/* so that underneath can avoid function calls which are prohibited
* for static initialization we need this conversion */
@@ -294,21 +302,21 @@ enum ll_type {
};
static INLINE LLVMTypeRef
-ll_type_to_llvm(enum ll_type type)
+ll_type_to_llvm(struct gallivm_state *gallivm, enum ll_type type)
{
switch (type) {
case LL_Double:
- return LLVMDoubleType();
+ return LLVMDoubleTypeInContext(gallivm->context);
case LL_Float:
- return LLVMFloatType();
+ return LLVMFloatTypeInContext(gallivm->context);
case LL_Int32:
- return LLVMInt32Type();
+ return LLVMInt32TypeInContext(gallivm->context);
case LL_Int16:
- return LLVMIntType(16);
+ return LLVMIntTypeInContext(gallivm->context, 16);
case LL_Int8:
- return LLVMIntType(8);
+ return LLVMIntTypeInContext(gallivm->context, 8);
}
- return LLVMIntType(8);
+ return LLVMIntTypeInContext(gallivm->context, 8);
}
static INLINE int
@@ -414,42 +422,42 @@ struct draw_llvm_translate {
static LLVMValueRef
-fetch(LLVMBuilderRef builder,
+fetch(struct gallivm_state *gallivm,
LLVMValueRef ptr, int val_size, int nr_components,
from_func func)
{
int i;
int offset = 0;
- LLVMValueRef res = LLVMConstNull(
- LLVMVectorType(LLVMFloatType(), 4));
+ LLVMValueRef res =
+ LLVMConstNull(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4));
LLVMValueRef defaults[4];
- defaults[0] = LLVMConstReal(LLVMFloatType(), 0);
- defaults[1] = LLVMConstReal(LLVMFloatType(), 0);
- defaults[2] = LLVMConstReal(LLVMFloatType(), 0);
- defaults[3] = LLVMConstReal(LLVMFloatType(), 1);
+ defaults[0] =
+ defaults[1] =
+ defaults[2] = lp_build_const_float(gallivm, 0.0);
+ defaults[3] = lp_build_const_float(gallivm, 1.0);
for (i = 0; i < nr_components; ++i) {
- LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0);
- LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef src_index = lp_build_const_int32(gallivm, offset);
+ LLVMValueRef dst_index = lp_build_const_int32(gallivm, i);
LLVMValueRef src_tmp;
LLVMValueRef component;
- src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, "src_tmp");
+ src_tmp = LLVMBuildGEP(gallivm->builder, ptr, &src_index, 1, "src_tmp");
/* convert src_tmp to float */
- component = func(builder, src_tmp);
+ component = func(gallivm, src_tmp);
/* vec.comp = component */
- res = LLVMBuildInsertElement(builder,
+ res = LLVMBuildInsertElement(gallivm->builder,
res,
component,
dst_index, "");
offset += val_size;
}
for (; i < 4; ++i) {
- LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(builder,
+ LLVMValueRef dst_index = lp_build_const_int32(gallivm, i);
+ res = LLVMBuildInsertElement(gallivm->builder,
res,
defaults[i],
dst_index, "");
@@ -459,7 +467,7 @@ fetch(LLVMBuilderRef builder,
LLVMValueRef
-draw_llvm_translate_from(LLVMBuilderRef builder,
+draw_llvm_translate_from(struct gallivm_state *gallivm,
LLVMValueRef vbuffer,
enum pipe_format from_format)
{
@@ -476,7 +484,7 @@ draw_llvm_translate_from(LLVMBuilderRef builder,
for (i = 0; i < Elements(translates); ++i) {
if (translates[i].format == from_format) {
/*LLVMTypeRef type = ll_type_to_llvm(translates[i].type);*/
- return fetch(builder,
+ return fetch(gallivm,
vbuffer,
ll_type_size(translates[i].type),
translates[i].num_components,
@@ -493,6 +501,6 @@ draw_llvm_translate_from(LLVMBuilderRef builder,
*/
format_desc = util_format_description(from_format);
- zero = LLVMConstNull(LLVMInt32Type());
- return lp_build_fetch_rgba_aos(builder, format_desc, type, vbuffer, zero, zero, zero);
+ zero = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context));
+ return lp_build_fetch_rgba_aos(gallivm, format_desc, type, vbuffer, zero, zero, zero);
}
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
index d1aba763098..0851b9acc0d 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
@@ -406,6 +406,7 @@ aaline_create_texture(struct aaline_stage *aaline)
texTemp.width0 = 1 << MAX_TEXTURE_LEVEL;
texTemp.height0 = 1 << MAX_TEXTURE_LEVEL;
texTemp.depth0 = 1;
+ texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
aaline->texture = screen->resource_create(screen, &texTemp);
@@ -441,10 +442,10 @@ aaline_create_texture(struct aaline_stage *aaline)
/* This texture is new, no need to flush.
*/
transfer = pipe->get_transfer(pipe,
- aaline->texture,
- u_subresource(0, level),
- PIPE_TRANSFER_WRITE,
- &box);
+ aaline->texture,
+ level,
+ PIPE_TRANSFER_WRITE,
+ &box);
data = pipe->transfer_map(pipe, transfer);
if (data == NULL)
diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
index ed9a53e154d..f5515c1df76 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
@@ -393,8 +393,8 @@ pstip_update_texture(struct pstip_stage *pstip)
*/
pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL );
- transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, 0,
- PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
+ transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0,
+ PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
data = pipe->transfer_map(pipe, transfer);
/*
@@ -440,6 +440,7 @@ pstip_create_texture(struct pstip_stage *pstip)
texTemp.width0 = 32;
texTemp.height0 = 32;
texTemp.depth0 = 1;
+ texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
pstip->texture = screen->resource_create(screen, &texTemp);
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index 54163d7f9eb..06ed4d60ef2 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -286,7 +286,6 @@ struct draw_context
#ifdef HAVE_LLVM
struct draw_llvm *llvm;
- LLVMExecutionEngineRef engine;
#endif
struct pipe_sampler_view *sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
index 7c198c6026d..c98fb3d5205 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
@@ -58,8 +58,8 @@ struct fetch_shade_emit {
const ubyte *src[PIPE_MAX_ATTRIBS];
unsigned prim;
- struct draw_vs_varient_key key;
- struct draw_vs_varient *active;
+ struct draw_vs_variant_key key;
+ struct draw_vs_variant *active;
const struct vertex_info *vinfo;
@@ -150,7 +150,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
}
- fse->active = draw_vs_lookup_varient( draw->vs.vertex_shader,
+ fse->active = draw_vs_lookup_variant( draw->vs.vertex_shader,
&fse->key );
if (!fse->active) {
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 a53a768d029..2e3afb22c48 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
@@ -34,6 +34,7 @@
#include "draw/draw_pt.h"
#include "draw/draw_vs.h"
#include "draw/draw_llvm.h"
+#include "gallivm/lp_bld_init.h"
struct llvm_middle_end {
@@ -72,19 +73,18 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
struct draw_llvm_variant_list_item *li;
unsigned i;
unsigned instance_id_index = ~0;
-
-
- unsigned out_prim = (draw->gs.geometry_shader ?
- draw->gs.geometry_shader->output_primitive :
- in_prim);
+ const unsigned out_prim = (draw->gs.geometry_shader ?
+ draw->gs.geometry_shader->output_primitive :
+ in_prim);
/* Add one to num_outputs because the pipeline occasionally tags on
* an additional texcoord, eg for AA lines.
*/
- unsigned nr = MAX2( shader->base.info.num_inputs,
- shader->base.info.num_outputs + 1 );
+ const unsigned nr = MAX2( shader->base.info.num_inputs,
+ shader->base.info.num_outputs + 1 );
/* Scan for instanceID system value.
+ * XXX but we never use instance_id_index?!
*/
for (i = 0; i < shader->base.info.num_inputs; i++) {
if (shader->base.info.input_semantic_name[i] == TGSI_SEMANTIC_INSTANCEID) {
@@ -133,9 +133,10 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
key = draw_llvm_make_variant_key(fpme->llvm, store);
+ /* Search shader's list of variants for the key */
li = first_elem(&shader->variants);
- while(!at_end(&shader->variants, li)) {
- if(memcmp(&li->base->key, key, shader->variant_key_size) == 0) {
+ while (!at_end(&shader->variants, li)) {
+ if (memcmp(&li->base->key, key, shader->variant_key_size) == 0) {
variant = li->base;
break;
}
@@ -143,10 +144,16 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
}
if (variant) {
+ /* found the variant, move to head of global list (for LRU) */
move_to_head(&fpme->llvm->vs_variants_list, &variant->list_item_global);
}
else {
+ /* Need to create new variant */
unsigned i;
+
+ /* First check if we've created too many variants. If so, free
+ * 25% of the LRU to avoid using too much memory.
+ */
if (fpme->llvm->nr_variants >= DRAW_MAX_SHADER_VARIANTS) {
/*
* XXX: should we flush here ?
@@ -422,7 +429,7 @@ draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw)
{
struct llvm_middle_end *fpme = 0;
- if (!draw->engine)
+ if (!draw->llvm->gallivm->engine)
return NULL;
fpme = CALLOC_STRUCT( llvm_middle_end );
diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c
index fb665b08fff..7caad6f0053 100644
--- a/src/gallium/auxiliary/draw/draw_vs.c
+++ b/src/gallium/auxiliary/draw/draw_vs.c
@@ -165,10 +165,10 @@ draw_delete_vertex_shader(struct draw_context *draw,
{
unsigned i;
- for (i = 0; i < dvs->nr_varients; i++)
- dvs->varient[i]->destroy( dvs->varient[i] );
+ for (i = 0; i < dvs->nr_variants; i++)
+ dvs->variant[i]->destroy( dvs->variant[i] );
- dvs->nr_varients = 0;
+ dvs->nr_variants = 0;
dvs->delete( dvs );
}
@@ -225,40 +225,40 @@ draw_vs_destroy( struct draw_context *draw )
}
-struct draw_vs_varient *
-draw_vs_lookup_varient( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key )
+struct draw_vs_variant *
+draw_vs_lookup_variant( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key )
{
- struct draw_vs_varient *varient;
+ struct draw_vs_variant *variant;
unsigned i;
- /* Lookup existing varient:
+ /* Lookup existing variant:
*/
- for (i = 0; i < vs->nr_varients; i++)
- if (draw_vs_varient_key_compare(key, &vs->varient[i]->key) == 0)
- return vs->varient[i];
+ for (i = 0; i < vs->nr_variants; i++)
+ if (draw_vs_variant_key_compare(key, &vs->variant[i]->key) == 0)
+ return vs->variant[i];
/* Else have to create a new one:
*/
- varient = vs->create_varient( vs, key );
- if (varient == NULL)
+ variant = vs->create_variant( vs, key );
+ if (variant == NULL)
return NULL;
/* Add it to our list, could be smarter:
*/
- if (vs->nr_varients < Elements(vs->varient)) {
- vs->varient[vs->nr_varients++] = varient;
+ if (vs->nr_variants < Elements(vs->variant)) {
+ vs->variant[vs->nr_variants++] = variant;
}
else {
- vs->last_varient++;
- vs->last_varient %= Elements(vs->varient);
- vs->varient[vs->last_varient]->destroy(vs->varient[vs->last_varient]);
- vs->varient[vs->last_varient] = varient;
+ vs->last_variant++;
+ vs->last_variant %= Elements(vs->variant);
+ vs->variant[vs->last_variant]->destroy(vs->variant[vs->last_variant]);
+ vs->variant[vs->last_variant] = variant;
}
/* Done
*/
- return varient;
+ return variant;
}
diff --git a/src/gallium/auxiliary/draw/draw_vs.h b/src/gallium/auxiliary/draw/draw_vs.h
index f9a038788fb..bfb72d50efa 100644
--- a/src/gallium/auxiliary/draw/draw_vs.h
+++ b/src/gallium/auxiliary/draw/draw_vs.h
@@ -38,7 +38,7 @@
struct draw_context;
struct pipe_shader_state;
-struct draw_varient_input
+struct draw_variant_input
{
enum pipe_format format;
unsigned buffer;
@@ -46,19 +46,19 @@ struct draw_varient_input
unsigned instance_divisor;
};
-struct draw_varient_output
+struct draw_variant_output
{
enum pipe_format format; /* output format */
unsigned vs_output:8; /* which vertex shader output is this? */
unsigned offset:24; /* offset into output vertex */
};
-struct draw_varient_element {
- struct draw_varient_input in;
- struct draw_varient_output out;
+struct draw_variant_element {
+ struct draw_variant_input in;
+ struct draw_variant_output out;
};
-struct draw_vs_varient_key {
+struct draw_vs_variant_key {
unsigned output_stride;
unsigned nr_elements:8; /* max2(nr_inputs, nr_outputs) */
unsigned nr_inputs:8;
@@ -66,34 +66,34 @@ struct draw_vs_varient_key {
unsigned viewport:1;
unsigned clip:1;
unsigned const_vbuffers:5;
- struct draw_varient_element element[PIPE_MAX_ATTRIBS];
+ struct draw_variant_element element[PIPE_MAX_ATTRIBS];
};
-struct draw_vs_varient;
+struct draw_vs_variant;
-struct draw_vs_varient {
- struct draw_vs_varient_key key;
+struct draw_vs_variant {
+ struct draw_vs_variant_key key;
struct draw_vertex_shader *vs;
- void (*set_buffer)( struct draw_vs_varient *,
+ void (*set_buffer)( struct draw_vs_variant *,
unsigned i,
const void *ptr,
unsigned stride,
unsigned max_stride );
- void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader,
+ void (PIPE_CDECL *run_linear)( struct draw_vs_variant *shader,
unsigned start,
unsigned count,
void *output_buffer );
- void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader,
+ void (PIPE_CDECL *run_elts)( struct draw_vs_variant *shader,
const unsigned *elts,
unsigned count,
void *output_buffer );
- void (*destroy)( struct draw_vs_varient * );
+ void (*destroy)( struct draw_vs_variant * );
};
@@ -117,11 +117,11 @@ struct draw_vertex_shader {
/*
*/
- struct draw_vs_varient *varient[16];
- unsigned nr_varients;
- unsigned last_varient;
- struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
- const struct draw_vs_varient_key *key );
+ struct draw_vs_variant *variant[16];
+ unsigned nr_variants;
+ unsigned last_variant;
+ struct draw_vs_variant *(*create_variant)( struct draw_vertex_shader *shader,
+ const struct draw_vs_variant_key *key );
void (*prepare)( struct draw_vertex_shader *shader,
@@ -144,9 +144,9 @@ struct draw_vertex_shader {
};
-struct draw_vs_varient *
-draw_vs_lookup_varient( struct draw_vertex_shader *base,
- const struct draw_vs_varient_key *key );
+struct draw_vs_variant *
+draw_vs_lookup_variant( struct draw_vertex_shader *base,
+ const struct draw_vs_variant_key *key );
/********************************************************************************
@@ -166,12 +166,12 @@ draw_create_vs_ppc(struct draw_context *draw,
const struct pipe_shader_state *templ);
-struct draw_vs_varient_key;
+struct draw_vs_variant_key;
struct draw_vertex_shader;
-struct draw_vs_varient *
-draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key );
+struct draw_vs_variant *
+draw_vs_create_variant_aos_sse( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key );
#if HAVE_LLVM
struct draw_vertex_shader *
@@ -181,7 +181,7 @@ draw_create_vs_llvm(struct draw_context *draw,
/********************************************************************************
- * Helpers for vs implementations that don't do their own fetch/emit varients.
+ * Helpers for vs implementations that don't do their own fetch/emit variants.
* Means these can be shared between shaders.
*/
struct translate;
@@ -194,21 +194,21 @@ struct translate *draw_vs_get_fetch( struct draw_context *draw,
struct translate *draw_vs_get_emit( struct draw_context *draw,
struct translate_key *key );
-struct draw_vs_varient *
-draw_vs_create_varient_generic( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key );
+struct draw_vs_variant *
+draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key );
-static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
+static INLINE int draw_vs_variant_keysize( const struct draw_vs_variant_key *key )
{
- return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element);
+ return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
}
-static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
- const struct draw_vs_varient_key *b )
+static INLINE int draw_vs_variant_key_compare( const struct draw_vs_variant_key *a,
+ const struct draw_vs_variant_key *b )
{
- int keysize = draw_vs_varient_keysize(a);
+ int keysize = draw_vs_variant_keysize(a);
return memcmp(a, b, keysize);
}
diff --git a/src/gallium/auxiliary/draw/draw_vs_aos.c b/src/gallium/auxiliary/draw/draw_vs_aos.c
index 19f49e34c8b..7b90dba0cd5 100644
--- a/src/gallium/auxiliary/draw/draw_vs_aos.c
+++ b/src/gallium/auxiliary/draw/draw_vs_aos.c
@@ -1918,7 +1918,7 @@ static void find_last_write_outputs( struct aos_compilation *cp )
#define ARG_OUTBUF 4
-static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
+static boolean build_vertex_program( struct draw_vs_variant_aos_sse *variant,
boolean linear )
{
struct tgsi_parse_context parse;
@@ -1927,14 +1927,14 @@ static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
util_init_math();
- tgsi_parse_init( &parse, varient->base.vs->state.tokens );
+ tgsi_parse_init( &parse, variant->base.vs->state.tokens );
memset(&cp, 0, sizeof(cp));
cp.insn_counter = 1;
- cp.vaos = varient;
+ cp.vaos = variant;
cp.have_sse2 = 1;
- cp.func = &varient->func[ linear ? 0 : 1 ];
+ cp.func = &variant->func[ linear ? 0 : 1 ];
cp.tmp_EAX = x86_make_reg(file_REG32, reg_AX);
cp.idx_EBX = x86_make_reg(file_REG32, reg_BX);
@@ -2090,20 +2090,20 @@ static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
/** cast wrapper */
-static INLINE struct draw_vs_varient_aos_sse *
-draw_vs_varient_aos_sse(struct draw_vs_varient *varient)
+static INLINE struct draw_vs_variant_aos_sse *
+draw_vs_variant_aos_sse(struct draw_vs_variant *variant)
{
- return (struct draw_vs_varient_aos_sse *) varient;
+ return (struct draw_vs_variant_aos_sse *) variant;
}
-static void vaos_set_buffer( struct draw_vs_varient *varient,
+static void vaos_set_buffer( struct draw_vs_variant *variant,
unsigned buf,
const void *ptr,
unsigned stride,
unsigned max_stride)
{
- struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
+ struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
if (buf < vaos->nr_vb) {
vaos->buffer[buf].base_ptr = (char *)ptr;
@@ -2115,12 +2115,12 @@ static void vaos_set_buffer( struct draw_vs_varient *varient,
-static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient,
+static void PIPE_CDECL vaos_run_elts( struct draw_vs_variant *variant,
const unsigned *elts,
unsigned count,
void *output_buffer )
{
- struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
+ struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
struct aos_machine *machine = vaos->draw->vs.aos_machine;
unsigned i;
@@ -2139,12 +2139,12 @@ static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient,
output_buffer );
}
-static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient,
+static void PIPE_CDECL vaos_run_linear( struct draw_vs_variant *variant,
unsigned start,
unsigned count,
void *output_buffer )
{
- struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
+ struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
struct aos_machine *machine = vaos->draw->vs.aos_machine;
unsigned i;
@@ -2171,9 +2171,9 @@ static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient,
-static void vaos_destroy( struct draw_vs_varient *varient )
+static void vaos_destroy( struct draw_vs_variant *variant )
{
- struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
+ struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
FREE( vaos->buffer );
@@ -2185,11 +2185,11 @@ static void vaos_destroy( struct draw_vs_varient *varient )
-static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key )
+static struct draw_vs_variant *variant_aos_sse( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key )
{
unsigned i;
- struct draw_vs_varient_aos_sse *vaos = CALLOC_STRUCT(draw_vs_varient_aos_sse);
+ struct draw_vs_variant_aos_sse *vaos = CALLOC_STRUCT(draw_vs_variant_aos_sse);
if (!vaos)
goto fail;
@@ -2249,17 +2249,17 @@ static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs,
}
-struct draw_vs_varient *
-draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key )
+struct draw_vs_variant *
+draw_vs_create_variant_aos_sse( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key )
{
- struct draw_vs_varient *varient = varient_aos_sse( vs, key );
+ struct draw_vs_variant *variant = variant_aos_sse( vs, key );
- if (varient == NULL) {
- varient = draw_vs_create_varient_generic( vs, key );
+ if (variant == NULL) {
+ variant = draw_vs_create_variant_generic( vs, key );
}
- return varient;
+ return variant;
}
diff --git a/src/gallium/auxiliary/draw/draw_vs_aos.h b/src/gallium/auxiliary/draw/draw_vs_aos.h
index 68e8295b5e1..55e63d8b9fa 100644
--- a/src/gallium/auxiliary/draw/draw_vs_aos.h
+++ b/src/gallium/auxiliary/draw/draw_vs_aos.h
@@ -98,9 +98,9 @@ struct aos_buffer {
-/* This is the temporary storage used by all the aos_sse vs varients.
+/* This is the temporary storage used by all the aos_sse vs variants.
* Create one per context and reuse by passing a pointer in at
- * vs_varient creation??
+ * vs_variant creation??
*/
struct aos_machine {
float input [MAX_INPUTS ][4];
@@ -134,7 +134,7 @@ struct aos_machine {
struct aos_compilation {
struct x86_function *func;
- struct draw_vs_varient_aos_sse *vaos;
+ struct draw_vs_variant_aos_sse *vaos;
unsigned insn_counter;
unsigned num_immediates;
@@ -234,8 +234,8 @@ typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
void *output_buffer);
-struct draw_vs_varient_aos_sse {
- struct draw_vs_varient base;
+struct draw_vs_variant_aos_sse {
+ struct draw_vs_variant base;
struct draw_context *draw;
struct aos_buffer *buffer;
diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c
index dab3eb1ca8e..667eb507855 100644
--- a/src/gallium/auxiliary/draw/draw_vs_exec.c
+++ b/src/gallium/auxiliary/draw/draw_vs_exec.c
@@ -203,7 +203,7 @@ draw_create_vs_exec(struct draw_context *draw,
vs->base.prepare = vs_exec_prepare;
vs->base.run_linear = vs_exec_run_linear;
vs->base.delete = vs_exec_delete;
- vs->base.create_varient = draw_vs_create_varient_generic;
+ vs->base.create_variant = draw_vs_create_variant_generic;
vs->machine = draw->vs.machine;
return &vs->base;
diff --git a/src/gallium/auxiliary/draw/draw_vs_llvm.c b/src/gallium/auxiliary/draw/draw_vs_llvm.c
index fa9992db783..54a5574f73f 100644
--- a/src/gallium/auxiliary/draw/draw_vs_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_vs_llvm.c
@@ -65,19 +65,7 @@ static void
vs_llvm_delete( struct draw_vertex_shader *dvs )
{
struct llvm_vertex_shader *shader = llvm_vertex_shader(dvs);
- struct pipe_fence_handle *fence = NULL;
struct draw_llvm_variant_list_item *li;
- struct pipe_context *pipe = dvs->draw->pipe;
-
- /*
- * XXX: This might be not neccessary at all.
- */
- pipe->flush(pipe, 0, &fence);
- if (fence) {
- pipe->screen->fence_finish(pipe->screen, fence, 0);
- pipe->screen->fence_reference(pipe->screen, &fence, NULL);
- }
-
li = first_elem(&shader->variants);
while(!at_end(&shader->variants, li)) {
@@ -119,7 +107,7 @@ draw_create_vs_llvm(struct draw_context *draw,
vs->base.prepare = vs_llvm_prepare;
vs->base.run_linear = vs_llvm_run_linear;
vs->base.delete = vs_llvm_delete;
- vs->base.create_varient = draw_vs_create_varient_generic;
+ vs->base.create_variant = draw_vs_create_variant_generic;
make_empty_list(&vs->variants);
diff --git a/src/gallium/auxiliary/draw/draw_vs_ppc.c b/src/gallium/auxiliary/draw/draw_vs_ppc.c
index 5df84916c51..cf894bbe8af 100644
--- a/src/gallium/auxiliary/draw/draw_vs_ppc.c
+++ b/src/gallium/auxiliary/draw/draw_vs_ppc.c
@@ -187,10 +187,10 @@ draw_create_vs_ppc(struct draw_context *draw,
vs->base.draw = draw;
#if 0
if (1)
- vs->base.create_varient = draw_vs_varient_aos_ppc;
+ vs->base.create_variant = draw_vs_variant_aos_ppc;
else
#endif
- vs->base.create_varient = draw_vs_create_varient_generic;
+ vs->base.create_variant = draw_vs_create_variant_generic;
vs->base.prepare = vs_ppc_prepare;
vs->base.run_linear = vs_ppc_run_linear;
vs->base.delete = vs_ppc_delete;
diff --git a/src/gallium/auxiliary/draw/draw_vs_sse.c b/src/gallium/auxiliary/draw/draw_vs_sse.c
index 0b0c6077c6f..dee7c0da9b6 100644
--- a/src/gallium/auxiliary/draw/draw_vs_sse.c
+++ b/src/gallium/auxiliary/draw/draw_vs_sse.c
@@ -166,9 +166,9 @@ draw_create_vs_sse(struct draw_context *draw,
vs->base.draw = draw;
if (1)
- vs->base.create_varient = draw_vs_create_varient_aos_sse;
+ vs->base.create_variant = draw_vs_create_variant_aos_sse;
else
- vs->base.create_varient = draw_vs_create_varient_generic;
+ vs->base.create_variant = draw_vs_create_variant_generic;
vs->base.prepare = vs_sse_prepare;
vs->base.run_linear = vs_sse_run_linear;
vs->base.delete = vs_sse_delete;
diff --git a/src/gallium/auxiliary/draw/draw_vs_varient.c b/src/gallium/auxiliary/draw/draw_vs_varient.c
index eacd1601877..d8f030f61eb 100644
--- a/src/gallium/auxiliary/draw/draw_vs_varient.c
+++ b/src/gallium/auxiliary/draw/draw_vs_varient.c
@@ -41,8 +41,8 @@
/* A first pass at incorporating vertex fetch/emit functionality into
*/
-struct draw_vs_varient_generic {
- struct draw_vs_varient base;
+struct draw_vs_variant_generic {
+ struct draw_vs_variant base;
struct draw_vertex_shader *shader;
struct draw_context *draw;
@@ -63,13 +63,13 @@ struct draw_vs_varient_generic {
-static void vsvg_set_buffer( struct draw_vs_varient *varient,
+static void vsvg_set_buffer( struct draw_vs_variant *variant,
unsigned buffer,
const void *ptr,
unsigned stride,
unsigned max_index )
{
- struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
+ struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
vsvg->fetch->set_buffer(vsvg->fetch,
buffer,
@@ -81,7 +81,7 @@ static void vsvg_set_buffer( struct draw_vs_varient *varient,
/* Mainly for debug at this stage:
*/
-static void do_rhw_viewport( struct draw_vs_varient_generic *vsvg,
+static void do_rhw_viewport( struct draw_vs_variant_generic *vsvg,
unsigned count,
void *output_buffer )
{
@@ -104,7 +104,7 @@ static void do_rhw_viewport( struct draw_vs_varient_generic *vsvg,
}
}
-static void do_viewport( struct draw_vs_varient_generic *vsvg,
+static void do_viewport( struct draw_vs_variant_generic *vsvg,
unsigned count,
void *output_buffer )
{
@@ -126,12 +126,12 @@ static void do_viewport( struct draw_vs_varient_generic *vsvg,
}
-static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient,
+static void PIPE_CDECL vsvg_run_elts( struct draw_vs_variant *variant,
const unsigned *elts,
unsigned count,
void *output_buffer)
{
- struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
+ struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
@@ -193,12 +193,12 @@ static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient,
}
-static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient,
+static void PIPE_CDECL vsvg_run_linear( struct draw_vs_variant *variant,
unsigned start,
unsigned count,
void *output_buffer )
{
- struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
+ struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
@@ -259,20 +259,20 @@ static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient,
-static void vsvg_destroy( struct draw_vs_varient *varient )
+static void vsvg_destroy( struct draw_vs_variant *variant )
{
- FREE(varient);
+ FREE(variant);
}
-struct draw_vs_varient *
-draw_vs_create_varient_generic( struct draw_vertex_shader *vs,
- const struct draw_vs_varient_key *key )
+struct draw_vs_variant *
+draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
+ const struct draw_vs_variant_key *key )
{
unsigned i;
struct translate_key fetch, emit;
- struct draw_vs_varient_generic *vsvg = CALLOC_STRUCT( draw_vs_varient_generic );
+ struct draw_vs_variant_generic *vsvg = CALLOC_STRUCT( draw_vs_variant_generic );
if (vsvg == NULL)
return NULL;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h
index 8103bc917fc..ee05c6ba01d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -55,4 +55,33 @@
#endif
+/**
+ * Redefine these LLVM entrypoints as invalid macros to make sure we
+ * don't accidentally use them. We need to use the functions which
+ * take an explicit LLVMContextRef parameter.
+ */
+#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION
+#define LLVMIntType ILLEGAL_LLVM_FUNCTION
+#define LLVMFloatType ILLEGAL_LLVM_FUNCTION
+#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION
+#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION
+#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION
+#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION
+#define LLVMStructType ILLEGAL_LLVM_FUNCTION
+#define LLVMVoidType ILLEGAL_LLVM_FUNCTION
+#define LLVMLabelType ILLEGAL_LLVM_FUNCTION
+#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION
+#define LLVMUnionType ILLEGAL_LLVM_FUNCTION
+#define LLVMMDString ILLEGAL_LLVM_FUNCTION
+#define LLVMMDNode ILLEGAL_LLVM_FUNCTION
+#define LLVMConstString ILLEGAL_LLVM_FUNCTION
+#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION
+#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION
+#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION
+#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
+
#endif /* LP_BLD_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index f9a12a41a1b..02b3bde7893 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -53,6 +53,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_logic.h"
#include "lp_bld_pack.h"
@@ -74,6 +75,7 @@ lp_build_min_simple(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const char *intrinsic = NULL;
LLVMValueRef cond;
@@ -107,7 +109,7 @@ lp_build_min_simple(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
return lp_build_select(bld, cond, a, b);
@@ -123,6 +125,7 @@ lp_build_max_simple(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const char *intrinsic = NULL;
LLVMValueRef cond;
@@ -156,7 +159,7 @@ lp_build_max_simple(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
return lp_build_select(bld, cond, a, b);
@@ -170,6 +173,7 @@ LLVMValueRef
lp_build_comp(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_value(type, a));
@@ -183,7 +187,7 @@ lp_build_comp(struct lp_build_context *bld,
if(LLVMIsConstant(a))
return LLVMConstNot(a);
else
- return LLVMBuildNot(bld->builder, a, "");
+ return LLVMBuildNot(builder, a, "");
}
if(LLVMIsConstant(a))
@@ -193,9 +197,9 @@ lp_build_comp(struct lp_build_context *bld,
return LLVMConstSub(bld->one, a);
else
if (type.floating)
- return LLVMBuildFSub(bld->builder, bld->one, a, "");
+ return LLVMBuildFSub(builder, bld->one, a, "");
else
- return LLVMBuildSub(bld->builder, bld->one, a, "");
+ return LLVMBuildSub(builder, bld->one, a, "");
}
@@ -207,6 +211,7 @@ lp_build_add(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -236,7 +241,7 @@ lp_build_add(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
}
if(LLVMIsConstant(a) && LLVMIsConstant(b))
@@ -246,9 +251,9 @@ lp_build_add(struct lp_build_context *bld,
res = LLVMConstAdd(a, b);
else
if (type.floating)
- res = LLVMBuildFAdd(bld->builder, a, b, "");
+ res = LLVMBuildFAdd(builder, a, b, "");
else
- res = LLVMBuildAdd(bld->builder, a, b, "");
+ res = LLVMBuildAdd(builder, a, b, "");
/* clamp to ceiling of 1.0 */
if(bld->type.norm && (bld->type.floating || bld->type.fixed))
@@ -265,6 +270,7 @@ LLVMValueRef
lp_build_sum_vector(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef index, res;
unsigned i;
@@ -277,19 +283,19 @@ lp_build_sum_vector(struct lp_build_context *bld,
assert(!bld->type.norm);
- index = LLVMConstInt(LLVMInt32Type(), 0, 0);
- res = LLVMBuildExtractElement(bld->builder, a, index, "");
+ index = lp_build_const_int32(bld->gallivm, 0);
+ res = LLVMBuildExtractElement(builder, a, index, "");
for (i = 1; i < type.length; i++) {
- index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ index = lp_build_const_int32(bld->gallivm, i);
if (type.floating)
- res = LLVMBuildFAdd(bld->builder, res,
- LLVMBuildExtractElement(bld->builder,
+ res = LLVMBuildFAdd(builder, res,
+ LLVMBuildExtractElement(builder,
a, index, ""),
"");
else
- res = LLVMBuildAdd(bld->builder, res,
- LLVMBuildExtractElement(bld->builder,
+ res = LLVMBuildAdd(builder, res,
+ LLVMBuildExtractElement(builder,
a, index, ""),
"");
}
@@ -306,6 +312,7 @@ lp_build_sub(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -335,7 +342,7 @@ lp_build_sub(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
}
if(LLVMIsConstant(a) && LLVMIsConstant(b))
@@ -345,9 +352,9 @@ lp_build_sub(struct lp_build_context *bld,
res = LLVMConstSub(a, b);
else
if (type.floating)
- res = LLVMBuildFSub(bld->builder, a, b, "");
+ res = LLVMBuildFSub(builder, a, b, "");
else
- res = LLVMBuildSub(bld->builder, a, b, "");
+ res = LLVMBuildSub(builder, a, b, "");
if(bld->type.norm && (bld->type.floating || bld->type.fixed))
res = lp_build_max_simple(bld, res, bld->zero);
@@ -398,10 +405,11 @@ lp_build_sub(struct lp_build_context *bld,
* http://www.stereopsis.com/doubleblend.html
*/
static LLVMValueRef
-lp_build_mul_u8n(LLVMBuilderRef builder,
+lp_build_mul_u8n(struct gallivm_state *gallivm,
struct lp_type i16_type,
LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef c8;
LLVMValueRef ab;
@@ -409,12 +417,12 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
assert(lp_check_value(i16_type, a));
assert(lp_check_value(i16_type, b));
- c8 = lp_build_const_int_vec(i16_type, 8);
+ c8 = lp_build_const_int_vec(gallivm, i16_type, 8);
#if 0
/* a*b/255 ~= (a*(b + 1)) >> 256 */
- b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(i16_type, 1), "");
+ b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(gallium, i16_type, 1), "");
ab = LLVMBuildMul(builder, a, b, "");
#else
@@ -422,7 +430,7 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
/* ab/255 ~= (ab + (ab >> 8) + 0x80) >> 8 */
ab = LLVMBuildMul(builder, a, b, "");
ab = LLVMBuildAdd(builder, ab, LLVMBuildLShr(builder, ab, c8, ""), "");
- ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(i16_type, 0x80), "");
+ ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(gallivm, i16_type, 0x80), "");
#endif
@@ -440,6 +448,7 @@ lp_build_mul(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef shift;
LLVMValueRef res;
@@ -463,14 +472,14 @@ lp_build_mul(struct lp_build_context *bld,
struct lp_type i16_type = lp_wider_type(type);
LLVMValueRef al, ah, bl, bh, abl, abh, ab;
- lp_build_unpack2(bld->builder, type, i16_type, a, &al, &ah);
- lp_build_unpack2(bld->builder, type, i16_type, b, &bl, &bh);
+ lp_build_unpack2(bld->gallivm, type, i16_type, a, &al, &ah);
+ lp_build_unpack2(bld->gallivm, type, i16_type, b, &bl, &bh);
/* PMULLW, PSRLW, PADDW */
- abl = lp_build_mul_u8n(bld->builder, i16_type, al, bl);
- abh = lp_build_mul_u8n(bld->builder, i16_type, ah, bh);
+ abl = lp_build_mul_u8n(bld->gallivm, i16_type, al, bl);
+ abh = lp_build_mul_u8n(bld->gallivm, i16_type, ah, bh);
- ab = lp_build_pack2(bld->builder, i16_type, type, abl, abh);
+ ab = lp_build_pack2(bld->gallivm, i16_type, type, abl, abh);
return ab;
}
@@ -480,7 +489,7 @@ lp_build_mul(struct lp_build_context *bld,
}
if(type.fixed)
- shift = lp_build_const_int_vec(type, type.width/2);
+ shift = lp_build_const_int_vec(bld->gallivm, type, type.width/2);
else
shift = NULL;
@@ -498,14 +507,14 @@ lp_build_mul(struct lp_build_context *bld,
}
else {
if (type.floating)
- res = LLVMBuildFMul(bld->builder, a, b, "");
+ res = LLVMBuildFMul(builder, a, b, "");
else
- res = LLVMBuildMul(bld->builder, a, b, "");
+ res = LLVMBuildMul(builder, a, b, "");
if(shift) {
if(type.sign)
- res = LLVMBuildAShr(bld->builder, res, shift, "");
+ res = LLVMBuildAShr(builder, res, shift, "");
else
- res = LLVMBuildLShr(bld->builder, res, shift, "");
+ res = LLVMBuildLShr(builder, res, shift, "");
}
}
@@ -521,6 +530,7 @@ lp_build_mul_imm(struct lp_build_context *bld,
LLVMValueRef a,
int b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef factor;
assert(lp_check_value(bld->type, a));
@@ -550,20 +560,20 @@ lp_build_mul_imm(struct lp_build_context *bld,
* for Inf and NaN.
*/
unsigned mantissa = lp_mantissa(bld->type);
- factor = lp_build_const_int_vec(bld->type, (unsigned long long)shift << mantissa);
- a = LLVMBuildBitCast(bld->builder, a, lp_build_int_vec_type(bld->type), "");
- a = LLVMBuildAdd(bld->builder, a, factor, "");
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->type), "");
+ factor = lp_build_const_int_vec(bld->gallivm, bld->type, (unsigned long long)shift << mantissa);
+ a = LLVMBuildBitCast(builder, a, lp_build_int_vec_type(bld->type), "");
+ a = LLVMBuildAdd(builder, a, factor, "");
+ a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, bld->type), "");
return a;
#endif
}
else {
- factor = lp_build_const_vec(bld->type, shift);
- return LLVMBuildShl(bld->builder, a, factor, "");
+ factor = lp_build_const_vec(bld->gallivm, bld->type, shift);
+ return LLVMBuildShl(builder, a, factor, "");
}
}
- factor = lp_build_const_vec(bld->type, (double)b);
+ factor = lp_build_const_vec(bld->gallivm, bld->type, (double)b);
return lp_build_mul(bld, a, factor);
}
@@ -576,6 +586,7 @@ lp_build_div(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_value(type, a));
@@ -605,11 +616,11 @@ lp_build_div(struct lp_build_context *bld,
return lp_build_mul(bld, a, lp_build_rcp(bld, b));
if (type.floating)
- return LLVMBuildFDiv(bld->builder, a, b, "");
+ return LLVMBuildFDiv(builder, a, b, "");
else if (type.sign)
- return LLVMBuildSDiv(bld->builder, a, b, "");
+ return LLVMBuildSDiv(builder, a, b, "");
else
- return LLVMBuildUDiv(bld->builder, a, b, "");
+ return LLVMBuildUDiv(builder, a, b, "");
}
@@ -624,6 +635,7 @@ lp_build_lerp_simple(struct lp_build_context *bld,
LLVMValueRef v0,
LLVMValueRef v1)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef delta;
LLVMValueRef res;
@@ -642,7 +654,7 @@ lp_build_lerp_simple(struct lp_build_context *bld,
* but it will be wrong for other uses. Basically we need a more
* powerful lp_type, capable of further distinguishing the values
* interpretation from the value storage. */
- res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(bld->type, (1 << bld->type.width/2) - 1), "");
+ res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(bld->gallivm, bld->type, (1 << bld->type.width/2) - 1), "");
}
return res;
@@ -658,6 +670,7 @@ lp_build_lerp(struct lp_build_context *bld,
LLVMValueRef v0,
LLVMValueRef v1)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -683,22 +696,22 @@ lp_build_lerp(struct lp_build_context *bld,
wide_type.width = type.width*2;
wide_type.length = type.length/2;
- lp_build_context_init(&wide_bld, bld->builder, wide_type);
+ lp_build_context_init(&wide_bld, bld->gallivm, wide_type);
- lp_build_unpack2(bld->builder, type, wide_type, x, &xl, &xh);
- lp_build_unpack2(bld->builder, type, wide_type, v0, &v0l, &v0h);
- lp_build_unpack2(bld->builder, type, wide_type, v1, &v1l, &v1h);
+ lp_build_unpack2(bld->gallivm, type, wide_type, x, &xl, &xh);
+ lp_build_unpack2(bld->gallivm, type, wide_type, v0, &v0l, &v0h);
+ lp_build_unpack2(bld->gallivm, type, wide_type, v1, &v1l, &v1h);
/*
* Scale x from [0, 255] to [0, 256]
*/
- shift = lp_build_const_int_vec(wide_type, type.width - 1);
+ shift = lp_build_const_int_vec(bld->gallivm, wide_type, type.width - 1);
xl = lp_build_add(&wide_bld, xl,
- LLVMBuildAShr(bld->builder, xl, shift, ""));
+ LLVMBuildAShr(builder, xl, shift, ""));
xh = lp_build_add(&wide_bld, xh,
- LLVMBuildAShr(bld->builder, xh, shift, ""));
+ LLVMBuildAShr(builder, xh, shift, ""));
/*
* Lerp both halves.
@@ -707,7 +720,7 @@ lp_build_lerp(struct lp_build_context *bld,
resl = lp_build_lerp_simple(&wide_bld, xl, v0l, v1l);
resh = lp_build_lerp_simple(&wide_bld, xh, v0h, v1h);
- res = lp_build_pack2(bld->builder, wide_type, type, resl, resh);
+ res = lp_build_pack2(bld->gallivm, wide_type, type, resl, resh);
} else {
res = lp_build_lerp_simple(bld, x, v0, v1);
}
@@ -820,8 +833,9 @@ LLVMValueRef
lp_build_abs(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
assert(lp_check_value(type, a));
@@ -830,27 +844,27 @@ lp_build_abs(struct lp_build_context *bld,
if(type.floating) {
/* Mask out the sign bit */
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
unsigned long long absMask = ~(1ULL << (type.width - 1));
- LLVMValueRef mask = lp_build_const_int_vec(type, ((unsigned long long) absMask));
- a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
- a = LLVMBuildAnd(bld->builder, a, mask, "");
- a = LLVMBuildBitCast(bld->builder, a, vec_type, "");
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, ((unsigned long long) absMask));
+ a = LLVMBuildBitCast(builder, a, int_vec_type, "");
+ a = LLVMBuildAnd(builder, a, mask, "");
+ a = LLVMBuildBitCast(builder, a, vec_type, "");
return a;
}
if(type.width*type.length == 128 && util_cpu_caps.has_ssse3) {
switch(type.width) {
case 8:
- return lp_build_intrinsic_unary(bld->builder, "llvm.x86.ssse3.pabs.b.128", vec_type, a);
+ return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.b.128", vec_type, a);
case 16:
- return lp_build_intrinsic_unary(bld->builder, "llvm.x86.ssse3.pabs.w.128", vec_type, a);
+ return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.w.128", vec_type, a);
case 32:
- return lp_build_intrinsic_unary(bld->builder, "llvm.x86.ssse3.pabs.d.128", vec_type, a);
+ return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.d.128", vec_type, a);
}
}
- return lp_build_max(bld, a, LLVMBuildNeg(bld->builder, a, ""));
+ return lp_build_max(bld, a, LLVMBuildNeg(builder, a, ""));
}
@@ -858,14 +872,16 @@ LLVMValueRef
lp_build_negate(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
+
assert(lp_check_value(bld->type, a));
#if HAVE_LLVM >= 0x0207
if (bld->type.floating)
- a = LLVMBuildFNeg(bld->builder, a, "");
+ a = LLVMBuildFNeg(builder, a, "");
else
#endif
- a = LLVMBuildNeg(bld->builder, a, "");
+ a = LLVMBuildNeg(builder, a, "");
return a;
}
@@ -876,6 +892,7 @@ LLVMValueRef
lp_build_sgn(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef cond;
LLVMValueRef res;
@@ -895,20 +912,20 @@ lp_build_sgn(struct lp_build_context *bld,
LLVMValueRef one;
unsigned long long maskBit = (unsigned long long)1 << (type.width - 1);
- int_type = lp_build_int_vec_type(type);
- vec_type = lp_build_vec_type(type);
- mask = lp_build_const_int_vec(type, maskBit);
+ int_type = lp_build_int_vec_type(bld->gallivm, type);
+ vec_type = lp_build_vec_type(bld->gallivm, type);
+ mask = lp_build_const_int_vec(bld->gallivm, type, maskBit);
/* Take the sign bit and add it to 1 constant */
- sign = LLVMBuildBitCast(bld->builder, a, int_type, "");
- sign = LLVMBuildAnd(bld->builder, sign, mask, "");
+ sign = LLVMBuildBitCast(builder, a, int_type, "");
+ sign = LLVMBuildAnd(builder, sign, mask, "");
one = LLVMConstBitCast(bld->one, int_type);
- res = LLVMBuildOr(bld->builder, sign, one, "");
- res = LLVMBuildBitCast(bld->builder, res, vec_type, "");
+ res = LLVMBuildOr(builder, sign, one, "");
+ res = LLVMBuildBitCast(builder, res, vec_type, "");
}
else
{
- LLVMValueRef minus_one = lp_build_const_vec(type, -1.0);
+ LLVMValueRef minus_one = lp_build_const_vec(bld->gallivm, type, -1.0);
cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero);
res = lp_build_select(bld, cond, bld->one, minus_one);
}
@@ -931,11 +948,12 @@ LLVMValueRef
lp_build_set_sign(struct lp_build_context *bld,
LLVMValueRef a, LLVMValueRef sign)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMValueRef shift = lp_build_const_int_vec(type, type.width - 1);
- LLVMValueRef mask = lp_build_const_int_vec(type,
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMValueRef shift = lp_build_const_int_vec(bld->gallivm, type, type.width - 1);
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
~((unsigned long long) 1 << (type.width - 1)));
LLVMValueRef val, res;
@@ -943,15 +961,15 @@ lp_build_set_sign(struct lp_build_context *bld,
assert(lp_check_value(type, a));
/* val = reinterpret_cast<int>(a) */
- val = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
+ val = LLVMBuildBitCast(builder, a, int_vec_type, "");
/* val = val & mask */
- val = LLVMBuildAnd(bld->builder, val, mask, "");
+ val = LLVMBuildAnd(builder, val, mask, "");
/* sign = sign << shift */
- sign = LLVMBuildShl(bld->builder, sign, shift, "");
+ sign = LLVMBuildShl(builder, sign, shift, "");
/* res = val | sign */
- res = LLVMBuildOr(bld->builder, val, sign, "");
+ res = LLVMBuildOr(builder, val, sign, "");
/* res = reinterpret_cast<float>(res) */
- res = LLVMBuildBitCast(bld->builder, res, vec_type, "");
+ res = LLVMBuildBitCast(builder, res, vec_type, "");
return res;
}
@@ -964,12 +982,13 @@ LLVMValueRef
lp_build_int_to_float(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
assert(type.floating);
- return LLVMBuildSIToFP(bld->builder, a, vec_type, "");
+ return LLVMBuildSIToFP(builder, a, vec_type, "");
}
@@ -994,8 +1013,9 @@ lp_build_round_sse41(struct lp_build_context *bld,
LLVMValueRef a,
enum lp_build_round_sse41_mode mode)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
const char *intrinsic;
LLVMValueRef res;
@@ -1027,13 +1047,13 @@ lp_build_round_sse41(struct lp_build_context *bld,
undef = LLVMGetUndef(vec_type);
args[0] = undef;
- args[1] = LLVMBuildInsertElement(bld->builder, undef, a, index0, "");
+ args[1] = LLVMBuildInsertElement(builder, undef, a, index0, "");
args[2] = LLVMConstInt(i32t, mode, 0);
- res = lp_build_intrinsic(bld->builder, intrinsic,
+ res = lp_build_intrinsic(builder, intrinsic,
vec_type, args, Elements(args));
- res = LLVMBuildExtractElement(bld->builder, res, index0, "");
+ res = LLVMBuildExtractElement(builder, res, index0, "");
}
else {
assert(type.width*type.length == 128);
@@ -1050,7 +1070,7 @@ lp_build_round_sse41(struct lp_build_context *bld,
return bld->undef;
}
- res = lp_build_intrinsic_binary(bld->builder, intrinsic,
+ res = lp_build_intrinsic_binary(builder, intrinsic,
bld->vec_type, a,
LLVMConstInt(i32t, mode, 0));
}
@@ -1063,9 +1083,10 @@ static INLINE LLVMValueRef
lp_build_iround_nearest_sse2(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMTypeRef ret_type = lp_build_int_vec_type(type);
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
+ LLVMTypeRef ret_type = lp_build_int_vec_type(bld->gallivm, type);
const char *intrinsic;
LLVMValueRef res;
@@ -1089,9 +1110,9 @@ lp_build_iround_nearest_sse2(struct lp_build_context *bld,
undef = LLVMGetUndef(vec_type);
- arg = LLVMBuildInsertElement(bld->builder, undef, a, index0, "");
+ arg = LLVMBuildInsertElement(builder, undef, a, index0, "");
- res = lp_build_intrinsic_unary(bld->builder, intrinsic,
+ res = lp_build_intrinsic_unary(builder, intrinsic,
ret_type, arg);
}
else {
@@ -1099,7 +1120,7 @@ lp_build_iround_nearest_sse2(struct lp_build_context *bld,
intrinsic = "llvm.x86.sse2.cvtps2dq";
- res = lp_build_intrinsic_unary(bld->builder, intrinsic,
+ res = lp_build_intrinsic_unary(builder, intrinsic,
ret_type, a);
}
@@ -1116,6 +1137,7 @@ LLVMValueRef
lp_build_trunc(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(type.floating);
@@ -1126,11 +1148,11 @@ lp_build_trunc(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_TRUNCATE);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
LLVMValueRef res;
- res = LLVMBuildFPToSI(bld->builder, a, int_vec_type, "");
- res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
+ res = LLVMBuildFPToSI(builder, a, int_vec_type, "");
+ res = LLVMBuildSIToFP(builder, res, vec_type, "");
return res;
}
}
@@ -1146,6 +1168,7 @@ LLVMValueRef
lp_build_round(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(type.floating);
@@ -1156,10 +1179,10 @@ lp_build_round(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_NEAREST);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_iround(bld, a);
- res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
+ res = LLVMBuildSIToFP(builder, res, vec_type, "");
return res;
}
}
@@ -1174,6 +1197,7 @@ LLVMValueRef
lp_build_floor(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(type.floating);
@@ -1184,10 +1208,10 @@ lp_build_floor(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_FLOOR);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_ifloor(bld, a);
- res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
+ res = LLVMBuildSIToFP(builder, res, vec_type, "");
return res;
}
}
@@ -1202,6 +1226,7 @@ LLVMValueRef
lp_build_ceil(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(type.floating);
@@ -1212,10 +1237,10 @@ lp_build_ceil(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_CEIL);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_iceil(bld, a);
- res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
+ res = LLVMBuildSIToFP(builder, res, vec_type, "");
return res;
}
}
@@ -1243,13 +1268,14 @@ LLVMValueRef
lp_build_itrunc(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
assert(type.floating);
assert(lp_check_value(type, a));
- return LLVMBuildFPToSI(bld->builder, a, int_vec_type, "");
+ return LLVMBuildFPToSI(builder, a, int_vec_type, "");
}
@@ -1263,6 +1289,7 @@ LLVMValueRef
lp_build_iround(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMTypeRef int_vec_type = bld->int_vec_type;
LLVMValueRef res;
@@ -1282,27 +1309,28 @@ lp_build_iround(struct lp_build_context *bld,
else {
LLVMValueRef half;
- half = lp_build_const_vec(type, 0.5);
+ half = lp_build_const_vec(bld->gallivm, type, 0.5);
if (type.sign) {
LLVMTypeRef vec_type = bld->vec_type;
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
/* get sign bit */
- sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
- sign = LLVMBuildAnd(bld->builder, sign, mask, "");
+ sign = LLVMBuildBitCast(builder, a, int_vec_type, "");
+ sign = LLVMBuildAnd(builder, sign, mask, "");
/* sign * 0.5 */
- half = LLVMBuildBitCast(bld->builder, half, int_vec_type, "");
- half = LLVMBuildOr(bld->builder, sign, half, "");
- half = LLVMBuildBitCast(bld->builder, half, vec_type, "");
+ half = LLVMBuildBitCast(builder, half, int_vec_type, "");
+ half = LLVMBuildOr(builder, sign, half, "");
+ half = LLVMBuildBitCast(builder, half, vec_type, "");
}
- res = LLVMBuildFAdd(bld->builder, a, half, "");
+ res = LLVMBuildFAdd(builder, a, half, "");
}
- res = LLVMBuildFPToSI(bld->builder, res, int_vec_type, "");
+ res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
return res;
}
@@ -1317,6 +1345,7 @@ LLVMValueRef
lp_build_ifloor(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMTypeRef int_vec_type = bld->int_vec_type;
LLVMValueRef res;
@@ -1335,29 +1364,34 @@ lp_build_ifloor(struct lp_build_context *bld,
/* Take the sign bit and add it to 1 constant */
LLVMTypeRef vec_type = bld->vec_type;
unsigned mantissa = lp_mantissa(type);
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
LLVMValueRef offset;
/* sign = a < 0 ? ~0 : 0 */
- sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
- sign = LLVMBuildAnd(bld->builder, sign, mask, "");
- sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), "ifloor.sign");
+ sign = LLVMBuildBitCast(builder, a, int_vec_type, "");
+ sign = LLVMBuildAnd(builder, sign, mask, "");
+ sign = LLVMBuildAShr(builder, sign,
+ lp_build_const_int_vec(bld->gallivm, type,
+ type.width - 1),
+ "ifloor.sign");
/* offset = -0.99999(9)f */
- offset = lp_build_const_vec(type, -(double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
+ offset = lp_build_const_vec(bld->gallivm, type,
+ -(double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
offset = LLVMConstBitCast(offset, int_vec_type);
/* offset = a < 0 ? offset : 0.0f */
- offset = LLVMBuildAnd(bld->builder, offset, sign, "");
- offset = LLVMBuildBitCast(bld->builder, offset, vec_type, "ifloor.offset");
+ offset = LLVMBuildAnd(builder, offset, sign, "");
+ offset = LLVMBuildBitCast(builder, offset, vec_type, "ifloor.offset");
- res = LLVMBuildFAdd(bld->builder, res, offset, "ifloor.res");
+ res = LLVMBuildFAdd(builder, res, offset, "ifloor.res");
}
}
/* round to nearest (toward zero) */
- res = LLVMBuildFPToSI(bld->builder, res, int_vec_type, "ifloor.res");
+ res = LLVMBuildFPToSI(builder, res, int_vec_type, "ifloor.res");
return res;
}
@@ -1372,6 +1406,7 @@ LLVMValueRef
lp_build_iceil(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMTypeRef int_vec_type = bld->int_vec_type;
LLVMValueRef res;
@@ -1389,29 +1424,34 @@ lp_build_iceil(struct lp_build_context *bld,
LLVMValueRef offset;
/* offset = 0.99999(9)f */
- offset = lp_build_const_vec(type, (double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
+ offset = lp_build_const_vec(bld->gallivm, type,
+ (double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
if (type.sign) {
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
/* sign = a < 0 ? 0 : ~0 */
- sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
- sign = LLVMBuildAnd(bld->builder, sign, mask, "");
- sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), "iceil.sign");
- sign = LLVMBuildNot(bld->builder, sign, "iceil.not");
+ sign = LLVMBuildBitCast(builder, a, int_vec_type, "");
+ sign = LLVMBuildAnd(builder, sign, mask, "");
+ sign = LLVMBuildAShr(builder, sign,
+ lp_build_const_int_vec(bld->gallivm, type,
+ type.width - 1),
+ "iceil.sign");
+ sign = LLVMBuildNot(builder, sign, "iceil.not");
/* offset = a < 0 ? 0.0 : offset */
offset = LLVMConstBitCast(offset, int_vec_type);
- offset = LLVMBuildAnd(bld->builder, offset, sign, "");
- offset = LLVMBuildBitCast(bld->builder, offset, vec_type, "iceil.offset");
+ offset = LLVMBuildAnd(builder, offset, sign, "");
+ offset = LLVMBuildBitCast(builder, offset, vec_type, "iceil.offset");
}
- res = LLVMBuildFAdd(bld->builder, a, offset, "iceil.res");
+ res = LLVMBuildFAdd(builder, a, offset, "iceil.res");
}
/* round to nearest (toward zero) */
- res = LLVMBuildFPToSI(bld->builder, res, int_vec_type, "iceil.res");
+ res = LLVMBuildFPToSI(builder, res, int_vec_type, "iceil.res");
return res;
}
@@ -1429,6 +1469,7 @@ lp_build_ifloor_fract(struct lp_build_context *bld,
LLVMValueRef *out_ipart,
LLVMValueRef *out_fpart)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef ipart;
@@ -1442,8 +1483,8 @@ lp_build_ifloor_fract(struct lp_build_context *bld,
*/
ipart = lp_build_floor(bld, a);
- *out_fpart = LLVMBuildFSub(bld->builder, a, ipart, "fpart");
- *out_ipart = LLVMBuildFPToSI(bld->builder, ipart, bld->int_vec_type, "ipart");
+ *out_fpart = LLVMBuildFSub(builder, a, ipart, "fpart");
+ *out_ipart = LLVMBuildFPToSI(builder, ipart, bld->int_vec_type, "ipart");
}
else {
/*
@@ -1451,8 +1492,8 @@ lp_build_ifloor_fract(struct lp_build_context *bld,
*/
*out_ipart = lp_build_ifloor(bld, a);
- ipart = LLVMBuildSIToFP(bld->builder, *out_ipart, bld->vec_type, "ipart");
- *out_fpart = LLVMBuildFSub(bld->builder, a, ipart, "fpart");
+ ipart = LLVMBuildSIToFP(builder, *out_ipart, bld->vec_type, "ipart");
+ *out_fpart = LLVMBuildFSub(builder, a, ipart, "fpart");
}
}
@@ -1461,8 +1502,9 @@ LLVMValueRef
lp_build_sqrt(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
char intrinsic[32];
assert(lp_check_value(type, a));
@@ -1473,7 +1515,7 @@ lp_build_sqrt(struct lp_build_context *bld,
assert(type.floating);
util_snprintf(intrinsic, sizeof intrinsic, "llvm.sqrt.v%uf%u", type.length, type.width);
- return lp_build_intrinsic_unary(bld->builder, intrinsic, vec_type, a);
+ return lp_build_intrinsic_unary(builder, intrinsic, vec_type, a);
}
@@ -1496,12 +1538,13 @@ lp_build_rcp_refine(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef rcp_a)
{
- LLVMValueRef two = lp_build_const_vec(bld->type, 2.0);
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef two = lp_build_const_vec(bld->gallivm, bld->type, 2.0);
LLVMValueRef res;
- res = LLVMBuildFMul(bld->builder, a, rcp_a, "");
- res = LLVMBuildFSub(bld->builder, two, res, "");
- res = LLVMBuildFMul(bld->builder, rcp_a, res, "");
+ res = LLVMBuildFMul(builder, a, rcp_a, "");
+ res = LLVMBuildFSub(builder, two, res, "");
+ res = LLVMBuildFMul(builder, rcp_a, res, "");
return res;
}
@@ -1511,6 +1554,7 @@ LLVMValueRef
lp_build_rcp(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_value(type, a));
@@ -1545,7 +1589,7 @@ lp_build_rcp(struct lp_build_context *bld,
LLVMValueRef res;
unsigned i;
- res = lp_build_intrinsic_unary(bld->builder, "llvm.x86.sse.rcp.ps", bld->vec_type, a);
+ res = lp_build_intrinsic_unary(builder, "llvm.x86.sse.rcp.ps", bld->vec_type, a);
for (i = 0; i < num_iterations; ++i) {
res = lp_build_rcp_refine(bld, a, res);
@@ -1554,7 +1598,7 @@ lp_build_rcp(struct lp_build_context *bld,
return res;
}
- return LLVMBuildFDiv(bld->builder, bld->one, a, "");
+ return LLVMBuildFDiv(builder, bld->one, a, "");
}
@@ -1571,15 +1615,16 @@ lp_build_rsqrt_refine(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef rsqrt_a)
{
- LLVMValueRef half = lp_build_const_vec(bld->type, 0.5);
- LLVMValueRef three = lp_build_const_vec(bld->type, 3.0);
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef half = lp_build_const_vec(bld->gallivm, bld->type, 0.5);
+ LLVMValueRef three = lp_build_const_vec(bld->gallivm, bld->type, 3.0);
LLVMValueRef res;
- res = LLVMBuildFMul(bld->builder, rsqrt_a, rsqrt_a, "");
- res = LLVMBuildFMul(bld->builder, a, res, "");
- res = LLVMBuildFSub(bld->builder, three, res, "");
- res = LLVMBuildFMul(bld->builder, rsqrt_a, res, "");
- res = LLVMBuildFMul(bld->builder, half, res, "");
+ res = LLVMBuildFMul(builder, rsqrt_a, rsqrt_a, "");
+ res = LLVMBuildFMul(builder, a, res, "");
+ res = LLVMBuildFSub(builder, three, res, "");
+ res = LLVMBuildFMul(builder, rsqrt_a, res, "");
+ res = LLVMBuildFMul(builder, half, res, "");
return res;
}
@@ -1592,6 +1637,7 @@ LLVMValueRef
lp_build_rsqrt(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_value(type, a));
@@ -1603,7 +1649,7 @@ lp_build_rsqrt(struct lp_build_context *bld,
LLVMValueRef res;
unsigned i;
- res = lp_build_intrinsic_unary(bld->builder, "llvm.x86.sse.rsqrt.ps", bld->vec_type, a);
+ res = lp_build_intrinsic_unary(builder, "llvm.x86.sse.rsqrt.ps", bld->vec_type, a);
for (i = 0; i < num_iterations; ++i) {
res = lp_build_rsqrt_refine(bld, a, res);
@@ -1617,17 +1663,17 @@ lp_build_rsqrt(struct lp_build_context *bld,
static inline LLVMValueRef
-lp_build_const_v4si(unsigned long value)
+lp_build_const_v4si(struct gallivm_state *gallivm, unsigned long value)
{
- LLVMValueRef element = LLVMConstInt(LLVMInt32Type(), value, 0);
+ LLVMValueRef element = lp_build_const_int32(gallivm, value);
LLVMValueRef elements[4] = { element, element, element, element };
return LLVMConstVector(elements, 4);
}
static inline LLVMValueRef
-lp_build_const_v4sf(float value)
+lp_build_const_v4sf(struct gallivm_state *gallivm, float value)
{
- LLVMValueRef element = LLVMConstReal(LLVMFloatType(), value);
+ LLVMValueRef element = lp_build_const_float(gallivm, value);
LLVMValueRef elements[4] = { element, element, element, element };
return LLVMConstVector(elements, 4);
}
@@ -1640,17 +1686,19 @@ LLVMValueRef
lp_build_sin(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ struct gallivm_state *gallivm = bld->gallivm;
struct lp_type int_type = lp_int_type(bld->type);
- LLVMBuilderRef b = bld->builder;
- LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatType(), 4);
- LLVMTypeRef v4si = LLVMVectorType(LLVMInt32Type(), 4);
+ LLVMBuilderRef b = builder;
+ LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4);
+ LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4);
/*
* take the absolute value,
* x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
*/
- LLVMValueRef inv_sig_mask = lp_build_const_v4si(~0x80000000);
+ LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000);
LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si");
LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi");
@@ -1660,7 +1708,7 @@ lp_build_sin(struct lp_build_context *bld,
* extract the sign bit (upper one)
* sign_bit = _mm_and_ps(sign_bit, *(v4sf*)_ps_sign_mask);
*/
- LLVMValueRef sig_mask = lp_build_const_v4si(0x80000000);
+ LLVMValueRef sig_mask = lp_build_const_v4si(bld->gallivm, 0x80000000);
LLVMValueRef sign_bit_i = LLVMBuildAnd(b, a_v4si, sig_mask, "sign_bit_i");
/*
@@ -1668,7 +1716,7 @@ lp_build_sin(struct lp_build_context *bld,
* y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
*/
- LLVMValueRef FOPi = lp_build_const_v4sf(1.27323954473516);
+ LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516);
LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y");
/*
@@ -1683,12 +1731,12 @@ lp_build_sin(struct lp_build_context *bld,
* emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1);
*/
- LLVMValueRef all_one = lp_build_const_v4si(1);
+ LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1);
LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add");
/*
* emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1);
*/
- LLVMValueRef inv_one = lp_build_const_v4si(~1);
+ LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1);
LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and");
/*
@@ -1699,13 +1747,13 @@ lp_build_sin(struct lp_build_context *bld,
/* get the swap sign flag
* emm0 = _mm_and_si128(emm2, *(v4si*)_pi32_4);
*/
- LLVMValueRef pi32_4 = lp_build_const_v4si(4);
+ LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4);
LLVMValueRef emm0_and = LLVMBuildAnd(b, emm2_add, pi32_4, "emm0_and");
/*
* emm2 = _mm_slli_epi32(emm0, 29);
*/
- LLVMValueRef const_29 = lp_build_const_v4si(29);
+ LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29);
LLVMValueRef swap_sign_bit = LLVMBuildShl(b, emm0_and, const_29, "swap_sign_bit");
/*
@@ -1718,10 +1766,11 @@ lp_build_sin(struct lp_build_context *bld,
* emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
*/
- LLVMValueRef pi32_2 = lp_build_const_v4si(2);
+ LLVMValueRef pi32_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_and, pi32_2, "emm2_3");
- LLVMValueRef poly_mask = lp_build_compare(b, int_type, PIPE_FUNC_EQUAL,
- emm2_3, lp_build_const_v4si(0));
+ LLVMValueRef poly_mask = lp_build_compare(bld->gallivm,
+ int_type, PIPE_FUNC_EQUAL,
+ emm2_3, lp_build_const_v4si(bld->gallivm, 0));
/*
* sign_bit = _mm_xor_ps(sign_bit, swap_sign_bit);
*/
@@ -1732,9 +1781,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4);
* _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8);
*/
- LLVMValueRef DP1 = lp_build_const_v4sf(-0.78515625);
- LLVMValueRef DP2 = lp_build_const_v4sf(-2.4187564849853515625e-4);
- LLVMValueRef DP3 = lp_build_const_v4sf(-3.77489497744594108e-8);
+ LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625);
+ LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4);
+ LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8);
/*
* The magic pass: "Extended precision modular arithmetic"
@@ -1769,9 +1818,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(coscof_p1, -1.388731625493765E-003);
* _PS_CONST(coscof_p2, 4.166664568298827E-002);
*/
- LLVMValueRef coscof_p0 = lp_build_const_v4sf(2.443315711809948E-005);
- LLVMValueRef coscof_p1 = lp_build_const_v4sf(-1.388731625493765E-003);
- LLVMValueRef coscof_p2 = lp_build_const_v4sf(4.166664568298827E-002);
+ LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005);
+ LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003);
+ LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002);
/*
* y = *(v4sf*)_ps_coscof_p0;
@@ -1790,10 +1839,10 @@ lp_build_sin(struct lp_build_context *bld,
* y = _mm_sub_ps(y, tmp);
* y = _mm_add_ps(y, *(v4sf*)_ps_1);
*/
- LLVMValueRef half = lp_build_const_v4sf(0.5);
+ LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5);
LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp");
LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8");
- LLVMValueRef one = lp_build_const_v4sf(1.0);
+ LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0);
LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9");
/*
@@ -1801,9 +1850,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(sincof_p1, 8.3321608736E-3);
* _PS_CONST(sincof_p2, -1.6666654611E-1);
*/
- LLVMValueRef sincof_p0 = lp_build_const_v4sf(-1.9515295891E-4);
- LLVMValueRef sincof_p1 = lp_build_const_v4sf(8.3321608736E-3);
- LLVMValueRef sincof_p2 = lp_build_const_v4sf(-1.6666654611E-1);
+ LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4);
+ LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3);
+ LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1);
/*
* Evaluate the second polynom (Pi/4 <= x <= 0)
@@ -1836,7 +1885,7 @@ lp_build_sin(struct lp_build_context *bld,
LLVMValueRef y2_i = LLVMBuildBitCast(b, y2_9, v4si, "y2_i");
LLVMValueRef y_i = LLVMBuildBitCast(b, y_10, v4si, "y_i");
LLVMValueRef y2_and = LLVMBuildAnd(b, y2_i, poly_mask, "y2_and");
- LLVMValueRef inv = lp_build_const_v4si(~0);
+ LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0);
LLVMValueRef poly_mask_inv = LLVMBuildXor(b, poly_mask, inv, "poly_mask_inv");
LLVMValueRef y_and = LLVMBuildAnd(b, y_i, poly_mask_inv, "y_and");
LLVMValueRef y_combine = LLVMBuildAdd(b, y_and, y2_and, "y_combine");
@@ -1858,17 +1907,19 @@ LLVMValueRef
lp_build_cos(struct lp_build_context *bld,
LLVMValueRef a)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ struct gallivm_state *gallivm = bld->gallivm;
struct lp_type int_type = lp_int_type(bld->type);
- LLVMBuilderRef b = bld->builder;
- LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatType(), 4);
- LLVMTypeRef v4si = LLVMVectorType(LLVMInt32Type(), 4);
+ LLVMBuilderRef b = builder;
+ LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4);
+ LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4);
/*
* take the absolute value,
* x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
*/
- LLVMValueRef inv_sig_mask = lp_build_const_v4si(~0x80000000);
+ LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000);
LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si");
LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi");
@@ -1879,7 +1930,7 @@ lp_build_cos(struct lp_build_context *bld,
* y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
*/
- LLVMValueRef FOPi = lp_build_const_v4sf(1.27323954473516);
+ LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516);
LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y");
/*
@@ -1894,12 +1945,12 @@ lp_build_cos(struct lp_build_context *bld,
* emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1);
*/
- LLVMValueRef all_one = lp_build_const_v4si(1);
+ LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1);
LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add");
/*
* emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1);
*/
- LLVMValueRef inv_one = lp_build_const_v4si(~1);
+ LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1);
LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and");
/*
@@ -1911,22 +1962,22 @@ lp_build_cos(struct lp_build_context *bld,
/*
* emm2 = _mm_sub_epi32(emm2, *(v4si*)_pi32_2);
*/
- LLVMValueRef const_2 = lp_build_const_v4si(2);
+ LLVMValueRef const_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_2 = LLVMBuildSub(b, emm2_and, const_2, "emm2_2");
/* get the swap sign flag
* emm0 = _mm_andnot_si128(emm2, *(v4si*)_pi32_4);
*/
- LLVMValueRef inv = lp_build_const_v4si(~0);
+ LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0);
LLVMValueRef emm0_not = LLVMBuildXor(b, emm2_2, inv, "emm0_not");
- LLVMValueRef pi32_4 = lp_build_const_v4si(4);
+ LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4);
LLVMValueRef emm0_and = LLVMBuildAnd(b, emm0_not, pi32_4, "emm0_and");
/*
* emm2 = _mm_slli_epi32(emm0, 29);
*/
- LLVMValueRef const_29 = lp_build_const_v4si(29);
+ LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29);
LLVMValueRef sign_bit = LLVMBuildShl(b, emm0_and, const_29, "sign_bit");
/*
@@ -1939,19 +1990,20 @@ lp_build_cos(struct lp_build_context *bld,
* emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
*/
- LLVMValueRef pi32_2 = lp_build_const_v4si(2);
+ LLVMValueRef pi32_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_2, pi32_2, "emm2_3");
- LLVMValueRef poly_mask = lp_build_compare(b, int_type, PIPE_FUNC_EQUAL,
- emm2_3, lp_build_const_v4si(0));
+ LLVMValueRef poly_mask = lp_build_compare(bld->gallivm,
+ int_type, PIPE_FUNC_EQUAL,
+ emm2_3, lp_build_const_v4si(bld->gallivm, 0));
/*
* _PS_CONST(minus_cephes_DP1, -0.78515625);
* _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4);
* _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8);
*/
- LLVMValueRef DP1 = lp_build_const_v4sf(-0.78515625);
- LLVMValueRef DP2 = lp_build_const_v4sf(-2.4187564849853515625e-4);
- LLVMValueRef DP3 = lp_build_const_v4sf(-3.77489497744594108e-8);
+ LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625);
+ LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4);
+ LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8);
/*
* The magic pass: "Extended precision modular arithmetic"
@@ -1986,9 +2038,9 @@ lp_build_cos(struct lp_build_context *bld,
* _PS_CONST(coscof_p1, -1.388731625493765E-003);
* _PS_CONST(coscof_p2, 4.166664568298827E-002);
*/
- LLVMValueRef coscof_p0 = lp_build_const_v4sf(2.443315711809948E-005);
- LLVMValueRef coscof_p1 = lp_build_const_v4sf(-1.388731625493765E-003);
- LLVMValueRef coscof_p2 = lp_build_const_v4sf(4.166664568298827E-002);
+ LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005);
+ LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003);
+ LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002);
/*
* y = *(v4sf*)_ps_coscof_p0;
@@ -2007,10 +2059,10 @@ lp_build_cos(struct lp_build_context *bld,
* y = _mm_sub_ps(y, tmp);
* y = _mm_add_ps(y, *(v4sf*)_ps_1);
*/
- LLVMValueRef half = lp_build_const_v4sf(0.5);
+ LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5);
LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp");
LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8");
- LLVMValueRef one = lp_build_const_v4sf(1.0);
+ LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0);
LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9");
/*
@@ -2018,9 +2070,9 @@ lp_build_cos(struct lp_build_context *bld,
* _PS_CONST(sincof_p1, 8.3321608736E-3);
* _PS_CONST(sincof_p2, -1.6666654611E-1);
*/
- LLVMValueRef sincof_p0 = lp_build_const_v4sf(-1.9515295891E-4);
- LLVMValueRef sincof_p1 = lp_build_const_v4sf(8.3321608736E-3);
- LLVMValueRef sincof_p2 = lp_build_const_v4sf(-1.6666654611E-1);
+ LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4);
+ LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3);
+ LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1);
/*
* Evaluate the second polynom (Pi/4 <= x <= 0)
@@ -2094,7 +2146,8 @@ lp_build_exp(struct lp_build_context *bld,
LLVMValueRef x)
{
/* log2(e) = 1/log(2) */
- LLVMValueRef log2e = lp_build_const_vec(bld->type, 1.4426950408889634);
+ LLVMValueRef log2e = lp_build_const_vec(bld->gallivm, bld->type,
+ 1.4426950408889634);
assert(lp_check_value(bld->type, x));
@@ -2110,7 +2163,8 @@ lp_build_log(struct lp_build_context *bld,
LLVMValueRef x)
{
/* log(2) */
- LLVMValueRef log2 = lp_build_const_vec(bld->type, 0.69314718055994529);
+ LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type,
+ 0.69314718055994529);
assert(lp_check_value(bld->type, x));
@@ -2144,7 +2198,7 @@ lp_build_polynomial(struct lp_build_context *bld,
for (i = num_coeffs; i--; ) {
LLVMValueRef coeff;
- coeff = lp_build_const_vec(type, coeffs[i]);
+ coeff = lp_build_const_vec(bld->gallivm, type, coeffs[i]);
if(res)
res = lp_build_add(bld, coeff, lp_build_mul(bld, x, res));
@@ -2198,9 +2252,10 @@ lp_build_exp2_approx(struct lp_build_context *bld,
LLVMValueRef *p_frac_part,
LLVMValueRef *p_exp2)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
LLVMValueRef ipart = NULL;
LLVMValueRef fpart = NULL;
LLVMValueRef expipart = NULL;
@@ -2219,29 +2274,31 @@ lp_build_exp2_approx(struct lp_build_context *bld,
assert(type.floating && type.width == 32);
- x = lp_build_min(bld, x, lp_build_const_vec(type, 129.0));
- x = lp_build_max(bld, x, lp_build_const_vec(type, -126.99999));
+ x = lp_build_min(bld, x, lp_build_const_vec(bld->gallivm, type, 129.0));
+ x = lp_build_max(bld, x, lp_build_const_vec(bld->gallivm, type, -126.99999));
/* ipart = floor(x) */
ipart = lp_build_floor(bld, x);
/* fpart = x - ipart */
- fpart = LLVMBuildFSub(bld->builder, x, ipart, "");
+ fpart = LLVMBuildFSub(builder, x, ipart, "");
}
if(p_exp2_int_part || p_exp2) {
/* expipart = (float) (1 << ipart) */
- ipart = LLVMBuildFPToSI(bld->builder, ipart, int_vec_type, "");
- expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_const_int_vec(type, 127), "");
- expipart = LLVMBuildShl(bld->builder, expipart, lp_build_const_int_vec(type, 23), "");
- expipart = LLVMBuildBitCast(bld->builder, expipart, vec_type, "");
+ ipart = LLVMBuildFPToSI(builder, ipart, int_vec_type, "");
+ expipart = LLVMBuildAdd(builder, ipart,
+ lp_build_const_int_vec(bld->gallivm, type, 127), "");
+ expipart = LLVMBuildShl(builder, expipart,
+ lp_build_const_int_vec(bld->gallivm, type, 23), "");
+ expipart = LLVMBuildBitCast(builder, expipart, vec_type, "");
}
if(p_exp2) {
expfpart = lp_build_polynomial(bld, fpart, lp_build_exp2_polynomial,
Elements(lp_build_exp2_polynomial));
- res = LLVMBuildFMul(bld->builder, expipart, expfpart, "");
+ res = LLVMBuildFMul(builder, expipart, expfpart, "");
}
if(p_exp2_int_part)
@@ -2279,6 +2336,7 @@ lp_build_extract_exponent(struct lp_build_context *bld,
LLVMValueRef x,
int bias)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
unsigned mantissa = lp_mantissa(type);
LLVMValueRef res;
@@ -2287,11 +2345,14 @@ lp_build_extract_exponent(struct lp_build_context *bld,
assert(lp_check_value(bld->type, x));
- x = LLVMBuildBitCast(bld->builder, x, bld->int_vec_type, "");
+ x = LLVMBuildBitCast(builder, x, bld->int_vec_type, "");
- res = LLVMBuildLShr(bld->builder, x, lp_build_const_int_vec(type, mantissa), "");
- res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(type, 255), "");
- res = LLVMBuildSub(bld->builder, res, lp_build_const_int_vec(type, 127 - bias), "");
+ res = LLVMBuildLShr(builder, x,
+ lp_build_const_int_vec(bld->gallivm, type, mantissa), "");
+ res = LLVMBuildAnd(builder, res,
+ lp_build_const_int_vec(bld->gallivm, type, 255), "");
+ res = LLVMBuildSub(builder, res,
+ lp_build_const_int_vec(bld->gallivm, type, 127 - bias), "");
return res;
}
@@ -2308,9 +2369,11 @@ LLVMValueRef
lp_build_extract_mantissa(struct lp_build_context *bld,
LLVMValueRef x)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
unsigned mantissa = lp_mantissa(type);
- LLVMValueRef mantmask = lp_build_const_int_vec(type, (1ULL << mantissa) - 1);
+ LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type,
+ (1ULL << mantissa) - 1);
LLVMValueRef one = LLVMConstBitCast(bld->one, bld->int_vec_type);
LLVMValueRef res;
@@ -2318,12 +2381,12 @@ lp_build_extract_mantissa(struct lp_build_context *bld,
assert(type.floating);
- x = LLVMBuildBitCast(bld->builder, x, bld->int_vec_type, "");
+ x = LLVMBuildBitCast(builder, x, bld->int_vec_type, "");
/* res = x / 2**ipart */
- res = LLVMBuildAnd(bld->builder, x, mantmask, "");
- res = LLVMBuildOr(bld->builder, res, one, "");
- res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
+ res = LLVMBuildAnd(builder, x, mantmask, "");
+ res = LLVMBuildOr(builder, res, one, "");
+ res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
return res;
}
@@ -2374,12 +2437,13 @@ lp_build_log2_approx(struct lp_build_context *bld,
LLVMValueRef *p_floor_log2,
LLVMValueRef *p_log2)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
- LLVMValueRef expmask = lp_build_const_int_vec(type, 0x7f800000);
- LLVMValueRef mantmask = lp_build_const_int_vec(type, 0x007fffff);
+ LLVMValueRef expmask = lp_build_const_int_vec(bld->gallivm, type, 0x7f800000);
+ LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type, 0x007fffff);
LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type);
LLVMValueRef i = NULL;
@@ -2401,35 +2465,35 @@ lp_build_log2_approx(struct lp_build_context *bld,
assert(type.floating && type.width == 32);
- i = LLVMBuildBitCast(bld->builder, x, int_vec_type, "");
+ i = LLVMBuildBitCast(builder, x, int_vec_type, "");
/* exp = (float) exponent(x) */
- exp = LLVMBuildAnd(bld->builder, i, expmask, "");
+ exp = LLVMBuildAnd(builder, i, expmask, "");
}
if(p_floor_log2 || p_log2) {
- logexp = LLVMBuildLShr(bld->builder, exp, lp_build_const_int_vec(type, 23), "");
- logexp = LLVMBuildSub(bld->builder, logexp, lp_build_const_int_vec(type, 127), "");
- logexp = LLVMBuildSIToFP(bld->builder, logexp, vec_type, "");
+ logexp = LLVMBuildLShr(builder, exp, lp_build_const_int_vec(bld->gallivm, type, 23), "");
+ logexp = LLVMBuildSub(builder, logexp, lp_build_const_int_vec(bld->gallivm, type, 127), "");
+ logexp = LLVMBuildSIToFP(builder, logexp, vec_type, "");
}
if(p_log2) {
/* mant = (float) mantissa(x) */
- mant = LLVMBuildAnd(bld->builder, i, mantmask, "");
- mant = LLVMBuildOr(bld->builder, mant, one, "");
- mant = LLVMBuildBitCast(bld->builder, mant, vec_type, "");
+ mant = LLVMBuildAnd(builder, i, mantmask, "");
+ mant = LLVMBuildOr(builder, mant, one, "");
+ mant = LLVMBuildBitCast(builder, mant, vec_type, "");
logmant = lp_build_polynomial(bld, mant, lp_build_log2_polynomial,
Elements(lp_build_log2_polynomial));
/* This effectively increases the polynomial degree by one, but ensures that log2(1) == 0*/
- logmant = LLVMBuildFMul(bld->builder, logmant, LLVMBuildFSub(bld->builder, mant, bld->one, ""), "");
+ logmant = LLVMBuildFMul(builder, logmant, LLVMBuildFSub(builder, mant, bld->one, ""), "");
- res = LLVMBuildFAdd(bld->builder, logmant, logexp, "");
+ res = LLVMBuildFAdd(builder, logmant, logexp, "");
}
if(p_exp) {
- exp = LLVMBuildBitCast(bld->builder, exp, vec_type, "");
+ exp = LLVMBuildBitCast(builder, exp, vec_type, "");
*p_exp = exp;
}
@@ -2465,6 +2529,7 @@ LLVMValueRef
lp_build_fast_log2(struct lp_build_context *bld,
LLVMValueRef x)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef ipart;
LLVMValueRef fpart;
@@ -2474,13 +2539,13 @@ lp_build_fast_log2(struct lp_build_context *bld,
/* ipart = floor(log2(x)) - 1 */
ipart = lp_build_extract_exponent(bld, x, -1);
- ipart = LLVMBuildSIToFP(bld->builder, ipart, bld->vec_type, "");
+ ipart = LLVMBuildSIToFP(builder, ipart, bld->vec_type, "");
/* fpart = x / 2**ipart */
fpart = lp_build_extract_mantissa(bld, x);
/* ipart + fpart */
- return LLVMBuildFAdd(bld->builder, ipart, fpart, "");
+ return LLVMBuildFAdd(builder, ipart, fpart, "");
}
@@ -2493,7 +2558,8 @@ LLVMValueRef
lp_build_ilog2(struct lp_build_context *bld,
LLVMValueRef x)
{
- LLVMValueRef sqrt2 = lp_build_const_vec(bld->type, M_SQRT2);
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef sqrt2 = lp_build_const_vec(bld->gallivm, bld->type, M_SQRT2);
LLVMValueRef ipart;
assert(bld->type.floating);
@@ -2501,7 +2567,7 @@ lp_build_ilog2(struct lp_build_context *bld,
assert(lp_check_value(bld->type, x));
/* x * 2^(0.5) i.e., add 0.5 to the log2(x) */
- x = LLVMBuildFMul(bld->builder, x, sqrt2, "");
+ x = LLVMBuildFMul(builder, x, sqrt2, "");
/* ipart = floor(log2(x) + 0.5) */
ipart = lp_build_extract_exponent(bld, x, 0);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
index f2ebd868a8d..9de5e8e7b51 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
@@ -56,20 +56,21 @@ lp_assert(int condition, const char *msg)
* \param msg a string to print if the assertion fails.
*/
LLVMValueRef
-lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
+lp_build_assert(struct gallivm_state *gallivm,
+ LLVMValueRef condition,
const char *msg)
{
- LLVMModuleRef module;
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMContextRef context = gallivm->context;
+ LLVMModuleRef module = gallivm->module;
LLVMTypeRef arg_types[2];
LLVMValueRef msg_string, assert_func, params[2], r;
- module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(
- LLVMGetInsertBlock(builder)));
+ msg_string = lp_build_const_string_variable(module, context,
+ msg, strlen(msg) + 1);
- msg_string = lp_build_const_string_variable(module, msg, strlen(msg) + 1);
-
- arg_types[0] = LLVMInt32Type();
- arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
+ arg_types[0] = LLVMInt32TypeInContext(context);
+ arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0);
/* lookup the lp_assert function */
assert_func = LLVMGetNamedFunction(module, "lp_assert");
@@ -77,12 +78,12 @@ lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
/* Create the assertion function if not found */
if (!assert_func) {
LLVMTypeRef func_type =
- LLVMFunctionType(LLVMVoidType(), arg_types, 2, 0);
+ LLVMFunctionType(LLVMVoidTypeInContext(context), arg_types, 2, 0);
assert_func = LLVMAddFunction(module, "lp_assert", func_type);
LLVMSetFunctionCallConv(assert_func, LLVMCCallConv);
LLVMSetLinkage(assert_func, LLVMExternalLinkage);
- LLVMAddGlobalMapping(lp_build_engine, assert_func,
+ LLVMAddGlobalMapping(gallivm->engine, assert_func,
func_to_pointer((func_pointer)lp_assert));
}
assert(assert_func);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.h b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
index ddd879dc2c6..1d2baab30a2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
@@ -30,10 +30,12 @@
#include "lp_bld.h"
+#include "lp_bld_init.h"
LLVMValueRef
-lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
+lp_build_assert(struct gallivm_state *gallivm,
+ LLVMValueRef condition,
const char *msg);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
index 706479b4d56..a9c57d682f2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
@@ -40,6 +40,7 @@
LLVMValueRef
lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -48,14 +49,14 @@ lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
- a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
- b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
+ a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
+ b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
- res = LLVMBuildOr(bld->builder, a, b, "");
+ res = LLVMBuildOr(builder, a, b, "");
if (type.floating) {
- res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
+ res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@@ -68,6 +69,7 @@ lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -76,14 +78,14 @@ lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
- a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
- b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
+ a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
+ b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
- res = LLVMBuildAnd(bld->builder, a, b, "");
+ res = LLVMBuildAnd(builder, a, b, "");
if (type.floating) {
- res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
+ res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@@ -96,6 +98,7 @@ lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -104,15 +107,15 @@ lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
- a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
- b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
+ a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
+ b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
- res = LLVMBuildNot(bld->builder, b, "");
- res = LLVMBuildAnd(bld->builder, a, res, "");
+ res = LLVMBuildNot(builder, b, "");
+ res = LLVMBuildAnd(builder, a, res, "");
if (type.floating) {
- res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
+ res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@@ -125,6 +128,7 @@ lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -133,7 +137,7 @@ lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
- res = LLVMBuildShl(bld->builder, a, b, "");
+ res = LLVMBuildShl(builder, a, b, "");
return res;
}
@@ -145,6 +149,7 @@ lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@@ -154,9 +159,9 @@ lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
assert(lp_check_value(type, b));
if (type.sign) {
- res = LLVMBuildAShr(bld->builder, a, b, "");
+ res = LLVMBuildAShr(builder, a, b, "");
} else {
- res = LLVMBuildLShr(bld->builder, a, b, "");
+ res = LLVMBuildLShr(builder, a, b, "");
}
return res;
@@ -169,7 +174,7 @@ lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
- LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
+ LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shl(bld, a, b);
}
@@ -181,7 +186,7 @@ lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
LLVMValueRef
lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
- LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
+ LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shr(bld, a, b);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c
index dd839c0bea5..6d8b7c26fc8 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c
@@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
unsigned
@@ -211,31 +212,31 @@ lp_const_eps(struct lp_type type)
LLVMValueRef
-lp_build_undef(struct lp_type type)
+lp_build_undef(struct gallivm_state *gallivm, struct lp_type type)
{
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMGetUndef(vec_type);
}
LLVMValueRef
-lp_build_zero(struct lp_type type)
+lp_build_zero(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.length == 1) {
if (type.floating)
- return LLVMConstReal(LLVMFloatType(), 0.0);
+ return lp_build_const_float(gallivm, 0.0);
else
- return LLVMConstInt(LLVMIntType(type.width), 0, 0);
+ return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMConstNull(vec_type);
}
}
LLVMValueRef
-lp_build_one(struct lp_type type)
+lp_build_one(struct gallivm_state *gallivm, struct lp_type type)
{
LLVMTypeRef elem_type;
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
@@ -243,7 +244,7 @@ lp_build_one(struct lp_type type)
assert(type.length <= LP_MAX_VECTOR_LENGTH);
- elem_type = lp_build_elem_type(type);
+ elem_type = lp_build_elem_type(gallivm, type);
if(type.floating)
elems[0] = LLVMConstReal(elem_type, 1.0);
@@ -283,10 +284,11 @@ lp_build_one(struct lp_type type)
* Build constant-valued element from a scalar value.
*/
LLVMValueRef
-lp_build_const_elem(struct lp_type type,
+lp_build_const_elem(struct gallivm_state *gallivm,
+ struct lp_type type,
double val)
{
- LLVMTypeRef elem_type = lp_build_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
LLVMValueRef elem;
if(type.floating) {
@@ -306,15 +308,15 @@ lp_build_const_elem(struct lp_type type,
* Build constant-valued vector from a scalar value.
*/
LLVMValueRef
-lp_build_const_vec(struct lp_type type,
+lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
double val)
{
if (type.length == 1) {
- return lp_build_const_elem(type, val);
+ return lp_build_const_elem(gallivm, type, val);
} else {
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
- elems[0] = lp_build_const_elem(type, val);
+ elems[0] = lp_build_const_elem(gallivm, type, val);
for(i = 1; i < type.length; ++i)
elems[i] = elems[0];
return LLVMConstVector(elems, type.length);
@@ -323,10 +325,10 @@ lp_build_const_vec(struct lp_type type,
LLVMValueRef
-lp_build_const_int_vec(struct lp_type type,
- long long val)
+lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type,
+ long long val)
{
- LLVMTypeRef elem_type = lp_build_int_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -343,7 +345,8 @@ lp_build_const_int_vec(struct lp_type type,
LLVMValueRef
-lp_build_const_aos(struct lp_type type,
+lp_build_const_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle)
{
@@ -355,7 +358,7 @@ lp_build_const_aos(struct lp_type type,
assert(type.length % 4 == 0);
assert(type.length <= LP_MAX_VECTOR_LENGTH);
- elem_type = lp_build_elem_type(type);
+ elem_type = lp_build_elem_type(gallivm, type);
if(swizzle == NULL)
swizzle = default_swizzle;
@@ -386,10 +389,11 @@ lp_build_const_aos(struct lp_type type,
* @param mask TGSI_WRITEMASK_xxx
*/
LLVMValueRef
-lp_build_const_mask_aos(struct lp_type type,
+lp_build_const_mask_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
unsigned mask)
{
- LLVMTypeRef elem_type = LLVMIntType(type.width);
+ LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width);
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h
index 6b1fc590c17..680211fbbd7 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h
@@ -39,6 +39,7 @@
#include "pipe/p_compiler.h"
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
@@ -73,44 +74,71 @@ lp_const_eps(struct lp_type type);
LLVMValueRef
-lp_build_undef(struct lp_type type);
+lp_build_undef(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_zero(struct lp_type type);
+lp_build_zero(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_one(struct lp_type type);
+lp_build_one(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_const_elem(struct lp_type type,
+lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type,
double val);
LLVMValueRef
-lp_build_const_vec(struct lp_type type, double val);
+lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
+ double val);
LLVMValueRef
-lp_build_const_int_vec(struct lp_type type, long long val);
+lp_build_const_int_vec(struct gallivm_state *gallivm,
+ struct lp_type type, long long val);
LLVMValueRef
-lp_build_const_aos(struct lp_type type,
+lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle);
LLVMValueRef
-lp_build_const_mask_aos(struct lp_type type,
+lp_build_const_mask_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
unsigned mask);
static INLINE LLVMValueRef
-lp_build_const_int32(int i)
+lp_build_const_int32(struct gallivm_state *gallivm, int i)
{
- return LLVMConstInt(LLVMInt32Type(), i, 0);
+ return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0);
+}
+
+
+static INLINE LLVMValueRef
+lp_build_const_float(struct gallivm_state *gallivm, float x)
+{
+ return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x);
+}
+
+
+/** Return constant-valued pointer to int */
+static INLINE LLVMValueRef
+lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)
+{
+ LLVMTypeRef int_type;
+ LLVMValueRef v;
+
+ /* int type large enough to hold a pointer */
+ int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *));
+ v = LLVMConstInt(int_type, (unsigned long long) ptr, 0);
+ v = LLVMBuildIntToPtr(gallivm->builder, v,
+ LLVMPointerType(int_type, 0),
+ "cast int to ptr");
+ return v;
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.c b/src/gallium/auxiliary/gallivm/lp_bld_conv.c
index 6967dd26225..c43ee8ac638 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_conv.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.c
@@ -89,12 +89,13 @@
* return { i32, i32, i32, i32 } where each value is in [0, 2^dst_width-1].
*/
LLVMValueRef
-lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
+lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src)
{
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(src_type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, src_type);
LLVMValueRef res;
unsigned mantissa;
@@ -122,10 +123,11 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)mask/ubound;
bias = (double)(1ULL << (mantissa - dst_width));
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
- res = LLVMBuildFAdd(builder, res, lp_build_const_vec(src_type, bias), "");
+ res = LLVMBuildFMul(builder, src, lp_build_const_vec(gallivm, src_type, scale), "");
+ res = LLVMBuildFAdd(builder, res, lp_build_const_vec(gallivm, src_type, bias), "");
res = LLVMBuildBitCast(builder, res, int_vec_type, "");
- res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(src_type, mask), "");
+ res = LLVMBuildAnd(builder, res,
+ lp_build_const_int_vec(gallivm, src_type, mask), "");
}
else if (dst_width == (mantissa + 1)) {
/*
@@ -138,7 +140,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)((1ULL << dst_width) - 1);
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
+ res = LLVMBuildFMul(builder, src,
+ lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
}
else {
@@ -166,7 +169,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
LLVMValueRef lshifted;
LLVMValueRef rshifted;
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
+ res = LLVMBuildFMul(builder, src,
+ lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
/*
@@ -177,7 +181,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
*/
if (lshift) {
lshifted = LLVMBuildShl(builder, res,
- lp_build_const_int_vec(src_type, lshift), "");
+ lp_build_const_int_vec(gallivm, src_type,
+ lshift), "");
} else {
lshifted = res;
}
@@ -186,7 +191,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* Align the most significant bit to the right.
*/
rshifted = LLVMBuildAShr(builder, res,
- lp_build_const_int_vec(src_type, rshift), "");
+ lp_build_const_int_vec(gallivm, src_type, rshift),
+ "");
/*
* Subtract the MSB to the LSB, therefore re-scaling from
@@ -206,13 +212,14 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* return {float, float, float, float} with values in range [0, 1].
*/
LLVMValueRef
-lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
+lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src)
{
- LLVMTypeRef vec_type = lp_build_vec_type(dst_type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(dst_type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, dst_type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, dst_type);
LLVMValueRef bias_;
LLVMValueRef res;
unsigned mantissa;
@@ -230,7 +237,8 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if (src_width == 8) {
scale = 1.0/255.0;
res = LLVMBuildSIToFP(builder, src, vec_type, "");
- res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
+ res = LLVMBuildFMul(builder, res,
+ lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@@ -247,10 +255,11 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if(src_width > mantissa) {
int shift = src_width - mantissa;
- res = LLVMBuildLShr(builder, res, lp_build_const_int_vec(dst_type, shift), "");
+ res = LLVMBuildLShr(builder, res,
+ lp_build_const_int_vec(gallivm, dst_type, shift), "");
}
- bias_ = lp_build_const_vec(dst_type, bias);
+ bias_ = lp_build_const_vec(gallivm, dst_type, bias);
res = LLVMBuildOr(builder,
res,
@@ -259,7 +268,7 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
res = LLVMBuildBitCast(builder, res, vec_type, "");
res = LLVMBuildFSub(builder, res, bias_, "");
- res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
+ res = LLVMBuildFMul(builder, res, lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@@ -272,12 +281,13 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
* to the lp_type union.
*/
void
-lp_build_conv(LLVMBuilderRef builder,
+lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type tmp_type;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned num_tmps;
@@ -342,12 +352,12 @@ lp_build_conv(LLVMBuilderRef builder,
int32_type.length /= 4;
int32_type.sign = 1;
- src_vec_type = lp_build_vec_type(src_type);
- dst_vec_type = lp_build_vec_type(dst_type);
- int16_vec_type = lp_build_vec_type(int16_type);
- int32_vec_type = lp_build_vec_type(int32_type);
+ src_vec_type = lp_build_vec_type(gallivm, src_type);
+ dst_vec_type = lp_build_vec_type(gallivm, dst_type);
+ int16_vec_type = lp_build_vec_type(gallivm, int16_type);
+ int32_vec_type = lp_build_vec_type(gallivm, int32_type);
- const_255f = lp_build_const_vec(src_type, 255.0f);
+ const_255f = lp_build_const_vec(gallivm, src_type, 255.0f);
a = LLVMBuildFMul(builder, src[0], const_255f, "");
b = LLVMBuildFMul(builder, src[1], const_255f, "");
@@ -357,14 +367,14 @@ lp_build_conv(LLVMBuilderRef builder,
{
struct lp_build_context bld;
- bld.builder = builder;
+ bld.gallivm = gallivm;
bld.type = src_type;
bld.vec_type = src_vec_type;
- bld.int_elem_type = lp_build_elem_type(int32_type);
+ bld.int_elem_type = lp_build_elem_type(gallivm, int32_type);
bld.int_vec_type = int32_vec_type;
- bld.undef = lp_build_undef(src_type);
- bld.zero = lp_build_zero(src_type);
- bld.one = lp_build_one(src_type);
+ bld.undef = lp_build_undef(gallivm, src_type);
+ bld.zero = lp_build_zero(gallivm, src_type);
+ bld.one = lp_build_one(gallivm, src_type);
src_int0 = lp_build_iround(&bld, a);
src_int1 = lp_build_iround(&bld, b);
@@ -372,9 +382,9 @@ lp_build_conv(LLVMBuilderRef builder,
src_int3 = lp_build_iround(&bld, d);
}
/* relying on clamping behavior of sse2 intrinsics here */
- lo = lp_build_pack2(builder, int32_type, int16_type, src_int0, src_int1);
- hi = lp_build_pack2(builder, int32_type, int16_type, src_int2, src_int3);
- dst[i] = lp_build_pack2(builder, int16_type, dst_type, lo, hi);
+ lo = lp_build_pack2(gallivm, int32_type, int16_type, src_int0, src_int1);
+ hi = lp_build_pack2(gallivm, int32_type, int16_type, src_int2, src_int3);
+ dst[i] = lp_build_pack2(gallivm, int16_type, dst_type, lo, hi);
}
return;
}
@@ -391,13 +401,13 @@ lp_build_conv(LLVMBuilderRef builder,
double dst_max = lp_const_max(dst_type);
LLVMValueRef thres;
- lp_build_context_init(&bld, builder, tmp_type);
+ lp_build_context_init(&bld, gallivm, tmp_type);
if(src_min < dst_min) {
if(dst_min == 0.0)
thres = bld.zero;
else
- thres = lp_build_const_vec(src_type, dst_min);
+ thres = lp_build_const_vec(gallivm, src_type, dst_min);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_max(&bld, tmp[i], thres);
}
@@ -406,7 +416,7 @@ lp_build_conv(LLVMBuilderRef builder,
if(dst_max == 1.0)
thres = bld.one;
else
- thres = lp_build_const_vec(src_type, dst_max);
+ thres = lp_build_const_vec(gallivm, src_type, dst_max);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_min(&bld, tmp[i], thres);
}
@@ -422,7 +432,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(tmp_type.floating) {
if(!dst_type.fixed && !dst_type.sign && dst_type.norm) {
for(i = 0; i < num_tmps; ++i) {
- tmp[i] = lp_build_clamped_float_to_unsigned_norm(builder,
+ tmp[i] = lp_build_clamped_float_to_unsigned_norm(gallivm,
tmp_type,
dst_type.width,
tmp[i]);
@@ -434,14 +444,14 @@ lp_build_conv(LLVMBuilderRef builder,
LLVMTypeRef tmp_vec_type;
if (dst_scale != 1.0) {
- LLVMValueRef scale = lp_build_const_vec(tmp_type, dst_scale);
+ LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, dst_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = FALSE;
- tmp_vec_type = lp_build_vec_type(tmp_type);
+ tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@@ -461,7 +471,8 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift > dst_shift) {
- LLVMValueRef shift = lp_build_const_int_vec(tmp_type, src_shift - dst_shift);
+ LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type,
+ src_shift - dst_shift);
for(i = 0; i < num_tmps; ++i)
if(src_type.sign)
tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, "");
@@ -485,7 +496,7 @@ lp_build_conv(LLVMBuilderRef builder,
new_type.width = dst_type.width;
new_type.length = dst_type.length;
- lp_build_resize(builder, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
+ lp_build_resize(gallivm, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
tmp_type = new_type;
num_tmps = num_dsts;
@@ -501,7 +512,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(!src_type.floating && dst_type.floating) {
if(!src_type.fixed && !src_type.sign && src_type.norm) {
for(i = 0; i < num_tmps; ++i) {
- tmp[i] = lp_build_unsigned_norm_to_float(builder,
+ tmp[i] = lp_build_unsigned_norm_to_float(gallivm,
src_type.width,
dst_type,
tmp[i]);
@@ -515,7 +526,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = TRUE;
tmp_type.sign = TRUE;
- tmp_vec_type = lp_build_vec_type(tmp_type);
+ tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@@ -529,7 +540,7 @@ lp_build_conv(LLVMBuilderRef builder,
}
if (src_scale != 1.0) {
- LLVMValueRef scale = lp_build_const_vec(tmp_type, 1.0/src_scale);
+ LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, 1.0/src_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
@@ -541,7 +552,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift < dst_shift) {
- LLVMValueRef shift = lp_build_const_int_vec(tmp_type, dst_shift - src_shift);
+ LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type, dst_shift - src_shift);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildShl(builder, tmp[i], shift, "");
}
@@ -565,7 +576,7 @@ lp_build_conv(LLVMBuilderRef builder,
* This is basically a very trimmed down version of lp_build_conv.
*/
void
-lp_build_conv_mask(LLVMBuilderRef builder,
+lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
@@ -599,11 +610,11 @@ lp_build_conv_mask(LLVMBuilderRef builder,
if(src_type.width > dst_type.width) {
assert(num_dsts == 1);
- dst[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
+ dst[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else if(src_type.width < dst_type.width) {
assert(num_srcs == 1);
- lp_build_unpack(builder, src_type, dst_type, src[0], dst, num_dsts);
+ lp_build_unpack(gallivm, src_type, dst_type, src[0], dst, num_dsts);
}
else {
assert(num_srcs == num_dsts);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.h b/src/gallium/auxiliary/gallivm/lp_bld_conv.h
index 628831c3ada..cec655980fa 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_conv.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.h
@@ -44,27 +44,27 @@ struct lp_type;
LLVMValueRef
-lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
+lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src);
LLVMValueRef
-lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
+lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src);
void
-lp_build_conv(LLVMBuilderRef builder,
+lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *srcs, unsigned num_srcs,
LLVMValueRef *dsts, unsigned num_dsts);
void
-lp_build_conv_mask(LLVMBuilderRef builder,
+lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
index eb11dcd4ef4..8a58f95b78f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
@@ -42,6 +42,7 @@
#define GALLIVM_DEBUG_NO_OPT (1 << 3)
#define GALLIVM_DEBUG_PERF (1 << 4)
#define GALLIVM_DEBUG_NO_BRILINEAR (1 << 5)
+#define GALLIVM_DEBUG_GC (1 << 6)
#ifdef DEBUG
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
index a2cee199a01..a9c9c7af10c 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
@@ -34,6 +34,7 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
+#include "lp_bld_init.h"
#include "lp_bld_type.h"
#include "lp_bld_flow.h"
@@ -51,25 +52,25 @@
* be used elsewhere.
*/
LLVMBasicBlockRef
-lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
+lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name)
{
LLVMBasicBlockRef current_block;
LLVMBasicBlockRef next_block;
LLVMBasicBlockRef new_block;
/* get current basic block */
- current_block = LLVMGetInsertBlock(builder);
+ current_block = LLVMGetInsertBlock(gallivm->builder);
/* check if there's another block after this one */
next_block = LLVMGetNextBasicBlock(current_block);
if (next_block) {
/* insert the new block before the next block */
- new_block = LLVMInsertBasicBlock(next_block, name);
+ new_block = LLVMInsertBasicBlockInContext(gallivm->context, next_block, name);
}
else {
/* append new block after current block */
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
- new_block = LLVMAppendBasicBlock(function, name);
+ new_block = LLVMAppendBasicBlockInContext(gallivm->context, function, name);
}
return new_block;
@@ -82,12 +83,11 @@ lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
*/
void
lp_build_flow_skip_begin(struct lp_build_skip_context *skip,
- LLVMBuilderRef builder)
+ struct gallivm_state *gallivm)
{
- skip->builder = builder;
-
+ skip->gallivm = gallivm;
/* create new basic block */
- skip->block = lp_build_insert_new_block(skip->builder, "skip");
+ skip->block = lp_build_insert_new_block(gallivm, "skip");
}
@@ -101,12 +101,12 @@ lp_build_flow_skip_cond_break(struct lp_build_skip_context *skip,
{
LLVMBasicBlockRef new_block;
- new_block = lp_build_insert_new_block(skip->builder, "");
+ new_block = lp_build_insert_new_block(skip->gallivm, "");
/* if cond is true, goto skip->block, else goto new_block */
- LLVMBuildCondBr(skip->builder, cond, skip->block, new_block);
+ LLVMBuildCondBr(skip->gallivm->builder, cond, skip->block, new_block);
- LLVMPositionBuilderAtEnd(skip->builder, new_block);
+ LLVMPositionBuilderAtEnd(skip->gallivm->builder, new_block);
}
@@ -114,8 +114,8 @@ void
lp_build_flow_skip_end(struct lp_build_skip_context *skip)
{
/* goto block */
- LLVMBuildBr(skip->builder, skip->block);
- LLVMPositionBuilderAtEnd(skip->builder, skip->block);
+ LLVMBuildBr(skip->gallivm->builder, skip->block);
+ LLVMPositionBuilderAtEnd(skip->gallivm->builder, skip->block);
}
@@ -125,7 +125,7 @@ lp_build_flow_skip_end(struct lp_build_skip_context *skip)
void
lp_build_mask_check(struct lp_build_mask_context *mask)
{
- LLVMBuilderRef builder = mask->skip.builder;
+ LLVMBuilderRef builder = mask->skip.gallivm->builder;
LLVMValueRef value;
LLVMValueRef cond;
@@ -152,27 +152,27 @@ lp_build_mask_check(struct lp_build_mask_context *mask)
*/
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value)
{
memset(mask, 0, sizeof *mask);
- mask->reg_type = LLVMIntType(type.width * type.length);
- mask->var = lp_build_alloca(builder,
- lp_build_int_vec_type(type),
+ mask->reg_type = LLVMIntTypeInContext(gallivm->context, type.width * type.length);
+ mask->var = lp_build_alloca(gallivm,
+ lp_build_int_vec_type(gallivm, type),
"execution_mask");
- LLVMBuildStore(builder, value, mask->var);
+ LLVMBuildStore(gallivm->builder, value, mask->var);
- lp_build_flow_skip_begin(&mask->skip, builder);
+ lp_build_flow_skip_begin(&mask->skip, gallivm);
}
LLVMValueRef
lp_build_mask_value(struct lp_build_mask_context *mask)
{
- return LLVMBuildLoad(mask->skip.builder, mask->var, "");
+ return LLVMBuildLoad(mask->skip.gallivm->builder, mask->var, "");
}
@@ -185,10 +185,10 @@ void
lp_build_mask_update(struct lp_build_mask_context *mask,
LLVMValueRef value)
{
- value = LLVMBuildAnd(mask->skip.builder,
+ value = LLVMBuildAnd(mask->skip.gallivm->builder,
lp_build_mask_value(mask),
value, "");
- LLVMBuildStore(mask->skip.builder, value, mask->var);
+ LLVMBuildStore(mask->skip.gallivm->builder, value, mask->var);
}
@@ -205,13 +205,17 @@ lp_build_mask_end(struct lp_build_mask_context *mask)
void
-lp_build_loop_begin(LLVMBuilderRef builder,
- LLVMValueRef start,
- struct lp_build_loop_state *state)
+lp_build_loop_begin(struct lp_build_loop_state *state,
+ struct gallivm_state *gallivm,
+ LLVMValueRef start)
+
{
- state->block = lp_build_insert_new_block(builder, "loop_begin");
+ LLVMBuilderRef builder = gallivm->builder;
+
+ state->block = lp_build_insert_new_block(gallivm, "loop_begin");
- state->counter_var = lp_build_alloca(builder, LLVMTypeOf(start), "loop_counter");
+ state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter");
+ state->gallivm = gallivm;
LLVMBuildStore(builder, start, state->counter_var);
@@ -224,12 +228,12 @@ lp_build_loop_begin(LLVMBuilderRef builder,
void
-lp_build_loop_end_cond(LLVMBuilderRef builder,
+lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
- LLVMIntPredicate llvm_cond,
- struct lp_build_loop_state *state)
+ LLVMIntPredicate llvm_cond)
{
+ LLVMBuilderRef builder = state->gallivm->builder;
LLVMValueRef next;
LLVMValueRef cond;
LLVMBasicBlockRef after_block;
@@ -243,7 +247,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
cond = LLVMBuildICmp(builder, llvm_cond, next, end, "");
- after_block = lp_build_insert_new_block(builder, "loop_end");
+ after_block = lp_build_insert_new_block(state->gallivm, "loop_end");
LLVMBuildCondBr(builder, cond, after_block, state->block);
@@ -254,12 +258,11 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
void
-lp_build_loop_end(LLVMBuilderRef builder,
+lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
- LLVMValueRef step,
- struct lp_build_loop_state *state)
+ LLVMValueRef step)
{
- lp_build_loop_end_cond(builder, end, step, LLVMIntNE, state);
+ lp_build_loop_end_cond(state, end, step, LLVMIntNE);
}
@@ -296,24 +299,27 @@ lp_build_loop_end(LLVMBuilderRef builder,
*/
void
lp_build_if(struct lp_build_if_state *ifthen,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
LLVMValueRef condition)
{
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
memset(ifthen, 0, sizeof *ifthen);
- ifthen->builder = builder;
+ ifthen->gallivm = gallivm;
ifthen->condition = condition;
ifthen->entry_block = block;
/* create endif/merge basic block for the phi functions */
- ifthen->merge_block = lp_build_insert_new_block(builder, "endif-block");
+ ifthen->merge_block = lp_build_insert_new_block(gallivm, "endif-block");
/* create/insert true_block before merge_block */
- ifthen->true_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-true-block");
+ ifthen->true_block =
+ LLVMInsertBasicBlockInContext(gallivm->context,
+ ifthen->merge_block,
+ "if-true-block");
/* successive code goes into the true block */
- LLVMPositionBuilderAtEnd(builder, ifthen->true_block);
+ LLVMPositionBuilderAtEnd(gallivm->builder, ifthen->true_block);
}
@@ -323,14 +329,19 @@ lp_build_if(struct lp_build_if_state *ifthen,
void
lp_build_else(struct lp_build_if_state *ifthen)
{
+ LLVMBuilderRef builder = ifthen->gallivm->builder;
+
/* Append an unconditional Br(anch) instruction on the true_block */
- LLVMBuildBr(ifthen->builder, ifthen->merge_block);
+ LLVMBuildBr(builder, ifthen->merge_block);
/* create/insert false_block before the merge block */
- ifthen->false_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-false-block");
+ ifthen->false_block =
+ LLVMInsertBasicBlockInContext(ifthen->gallivm->context,
+ ifthen->merge_block,
+ "if-false-block");
/* successive code goes into the else block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->false_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->false_block);
}
@@ -340,28 +351,30 @@ lp_build_else(struct lp_build_if_state *ifthen)
void
lp_build_endif(struct lp_build_if_state *ifthen)
{
+ LLVMBuilderRef builder = ifthen->gallivm->builder;
+
/* Insert branch to the merge block from current block */
- LLVMBuildBr(ifthen->builder, ifthen->merge_block);
+ LLVMBuildBr(builder, ifthen->merge_block);
/*
* Now patch in the various branch instructions.
*/
/* Insert the conditional branch instruction at the end of entry_block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->entry_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
if (ifthen->false_block) {
/* we have an else clause */
- LLVMBuildCondBr(ifthen->builder, ifthen->condition,
+ LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->false_block);
}
else {
/* no else clause */
- LLVMBuildCondBr(ifthen->builder, ifthen->condition,
+ LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->merge_block);
}
/* Resume building code at end of the ifthen->merge_block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->merge_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
}
@@ -381,15 +394,16 @@ lp_build_endif(struct lp_build_if_state *ifthen)
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
-lp_build_alloca(LLVMBuilderRef builder,
+lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilder();
+ LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {
@@ -422,16 +436,17 @@ lp_build_alloca(LLVMBuilderRef builder,
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
-lp_build_array_alloca(LLVMBuilderRef builder,
+lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilder();
+ LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
index e729ee6eaac..3cd5a9f42a5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
@@ -47,7 +47,7 @@ struct lp_type;
*/
struct lp_build_skip_context
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
/** Block to skip to */
LLVMBasicBlockRef block;
@@ -55,7 +55,7 @@ struct lp_build_skip_context
void
lp_build_flow_skip_begin(struct lp_build_skip_context *ctx,
- LLVMBuilderRef builder);
+ struct gallivm_state *gallivm);
void
lp_build_flow_skip_cond_break(struct lp_build_skip_context *ctx,
@@ -77,7 +77,7 @@ struct lp_build_mask_context
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value);
@@ -107,31 +107,28 @@ lp_build_mask_end(struct lp_build_mask_context *mask);
*/
struct lp_build_loop_state
{
- LLVMBasicBlockRef block;
- LLVMValueRef counter_var;
- LLVMValueRef counter;
+ LLVMBasicBlockRef block;
+ LLVMValueRef counter_var;
+ LLVMValueRef counter;
+ struct gallivm_state *gallivm;
};
void
-lp_build_loop_begin(LLVMBuilderRef builder,
- LLVMValueRef start,
- struct lp_build_loop_state *state);
-
+lp_build_loop_begin(struct lp_build_loop_state *state,
+ struct gallivm_state *gallivm,
+ LLVMValueRef start);
void
-lp_build_loop_end(LLVMBuilderRef builder,
+lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
- LLVMValueRef step,
- struct lp_build_loop_state *state);
+ LLVMValueRef step);
void
-lp_build_loop_end_cond(LLVMBuilderRef builder,
+lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
- LLVMIntPredicate cond,
- struct lp_build_loop_state *state);
-
+ LLVMIntPredicate cond);
@@ -140,7 +137,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
*/
struct lp_build_if_state
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
LLVMValueRef condition;
LLVMBasicBlockRef entry_block;
LLVMBasicBlockRef true_block;
@@ -151,7 +148,7 @@ struct lp_build_if_state
void
lp_build_if(struct lp_build_if_state *ctx,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
LLVMValueRef condition);
void
@@ -161,15 +158,15 @@ void
lp_build_endif(struct lp_build_if_state *ctx);
LLVMBasicBlockRef
-lp_build_insert_new_block(LLVMBuilderRef builder, const char *name);
+lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name);
LLVMValueRef
-lp_build_alloca(LLVMBuilderRef builder,
+lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name);
LLVMValueRef
-lp_build_array_alloca(LLVMBuilderRef builder,
+lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h
index 60e22d727ad..04142d905b1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h
@@ -35,6 +35,7 @@
*/
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
#include "pipe/p_format.h"
@@ -53,12 +54,12 @@ lp_build_format_swizzle_aos(const struct util_format_description *desc,
LLVMValueRef unswizzled);
LLVMValueRef
-lp_build_pack_rgba_aos(LLVMBuilderRef builder,
+lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba);
LLVMValueRef
-lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -78,20 +79,20 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
LLVMValueRef swizzled_out[4]);
void
-lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
+lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4]);
void
-lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
+lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba);
void
-lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
+lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -106,7 +107,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
index 6b9189e1da5..82ab19eda14 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -36,6 +36,7 @@
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_math.h"
+#include "util/u_pointer.h"
#include "util/u_string.h"
#include "lp_bld_arit.h"
@@ -145,10 +146,11 @@ format_matches_type(const struct util_format_description *desc,
* @return RGBA in a float[4] or ubyte[4] or ushort[4] vector.
*/
static INLINE LLVMValueRef
-lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
+lp_build_unpack_arith_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef packed)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef shifted, casted, scaled, masked;
LLVMValueRef shifts[4];
LLVMValueRef masks[4];
@@ -167,21 +169,21 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
/* Do the intermediate integer computations with 32bit integers since it
* matches floating point size */
- assert (LLVMTypeOf(packed) == LLVMInt32Type());
+ assert (LLVMTypeOf(packed) == LLVMInt32TypeInContext(gallivm->context));
/* Broadcast the packed value to all four channels
* before: packed = BGRA
* after: packed = {BGRA, BGRA, BGRA, BGRA}
*/
packed = LLVMBuildInsertElement(builder,
- LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
packed,
- LLVMConstNull(LLVMInt32Type()),
+ LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)),
"");
packed = LLVMBuildShuffleVector(builder,
packed,
- LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
- LLVMConstNull(LLVMVectorType(LLVMInt32Type(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
+ LLVMConstNull(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
"");
/* Initialize vector constants */
@@ -194,9 +196,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
- shifts[i] = LLVMGetUndef(LLVMInt32Type());
- masks[i] = LLVMConstNull(LLVMInt32Type());
- scales[i] = LLVMConstNull(LLVMFloatType());
+ shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
+ masks[i] = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context));
+ scales[i] = LLVMConstNull(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned long long mask = (1ULL << bits) - 1;
@@ -207,15 +209,15 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
needs_uitofp = TRUE;
}
- shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
- masks[i] = LLVMConstInt(LLVMInt32Type(), mask, 0);
+ shifts[i] = lp_build_const_int32(gallivm, shift);
+ masks[i] = lp_build_const_int32(gallivm, mask);
if (desc->channel[i].normalized) {
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0/mask);
+ scales[i] = lp_build_const_float(gallivm, 1.0 / mask);
normalized = TRUE;
}
else
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
+ scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@@ -230,9 +232,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
if (!needs_uitofp) {
/* UIToFP can't be expressed in SSE2 */
- casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
+ casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
} else {
- casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
+ casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
}
/* At this point 'casted' may be a vector of floats such as
@@ -258,10 +260,11 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
* a time is rarely if ever needed.
*/
LLVMValueRef
-lp_build_pack_rgba_aos(LLVMBuilderRef builder,
+lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef type;
LLVMValueRef packed = NULL;
LLVMValueRef swizzles[4];
@@ -276,7 +279,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->block.width == 1);
assert(desc->block.height == 1);
- type = LLVMIntType(desc->block.bits);
+ type = LLVMIntTypeInContext(gallivm->context, desc->block.bits);
/* Unswizzle the color components into the source vector. */
for (i = 0; i < 4; ++i) {
@@ -285,13 +288,13 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
break;
}
if (j < 4)
- swizzles[i] = LLVMConstInt(LLVMInt32Type(), j, 0);
+ swizzles[i] = lp_build_const_int32(gallivm, j);
else
- swizzles[i] = LLVMGetUndef(LLVMInt32Type());
+ swizzles[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
}
unswizzled = LLVMBuildShuffleVector(builder, rgba,
- LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4)),
LLVMConstVector(swizzles, 4), "");
normalized = FALSE;
@@ -300,8 +303,8 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
- shifts[i] = LLVMGetUndef(LLVMInt32Type());
- scales[i] = LLVMGetUndef(LLVMFloatType());
+ shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
+ scales[i] = LLVMGetUndef(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned mask = (1 << bits) - 1;
@@ -309,14 +312,14 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED);
assert(bits < 32);
- shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
+ shifts[i] = lp_build_const_int32(gallivm, shift);
if (desc->channel[i].normalized) {
- scales[i] = LLVMConstReal(LLVMFloatType(), mask);
+ scales[i] = lp_build_const_float(gallivm, mask);
normalized = TRUE;
}
else
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
+ scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@@ -327,14 +330,15 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
else
scaled = unswizzled;
- casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32Type(), 4), "");
+ casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4), "");
shifted = LLVMBuildShl(builder, casted, LLVMConstVector(shifts, 4), "");
/* Bitwise or all components */
for (i = 0; i < 4; ++i) {
if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) {
- LLVMValueRef component = LLVMBuildExtractElement(builder, shifted, LLVMConstInt(LLVMInt32Type(), i, 0), "");
+ LLVMValueRef component = LLVMBuildExtractElement(builder, shifted,
+ lp_build_const_int32(gallivm, i), "");
if (packed)
packed = LLVMBuildOr(builder, packed, component, "");
else
@@ -343,7 +347,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
}
if (!packed)
- packed = LLVMGetUndef(LLVMInt32Type());
+ packed = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
if (desc->block.bits < 32)
packed = LLVMBuildTrunc(builder, packed, type, "");
@@ -364,7 +368,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
* \return a 4 element vector with the pixel's RGBA values.
*/
LLVMValueRef
-lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -372,13 +376,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef i,
LLVMValueRef j)
{
+ LLVMBuilderRef builder = gallivm->builder;
unsigned num_pixels = type.length / 4;
struct lp_build_context bld;
assert(type.length <= LP_MAX_VECTOR_LENGTH);
assert(type.length % 4 == 0);
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
/*
* Trivial case
@@ -397,13 +402,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* scaling or converting.
*/
- packed = lp_build_gather(builder, type.length/4,
+ packed = lp_build_gather(gallivm, type.length/4,
format_desc->block.bits, type.width*4,
base_ptr, offset);
assert(format_desc->block.bits <= type.width * type.length);
- packed = LLVMBuildBitCast(builder, packed, lp_build_vec_type(type), "");
+ packed = LLVMBuildBitCast(gallivm->builder, packed,
+ lp_build_vec_type(gallivm, type), "");
return lp_build_format_swizzle_aos(format_desc, &bld, packed);
}
@@ -435,11 +441,12 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
for (k = 0; k < num_pixels; ++k) {
LLVMValueRef packed;
- packed = lp_build_gather_elem(builder, num_pixels,
+ packed = lp_build_gather_elem(gallivm, num_pixels,
format_desc->block.bits, 32,
base_ptr, offset, k);
- tmps[k] = lp_build_unpack_arith_rgba_aos(builder, format_desc,
+ tmps[k] = lp_build_unpack_arith_rgba_aos(gallivm,
+ format_desc,
packed);
}
@@ -455,7 +462,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
__FUNCTION__, format_desc->short_name);
}
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@@ -476,14 +483,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmp_type.length = num_pixels * 4;
tmp_type.norm = TRUE;
- tmp = lp_build_fetch_subsampled_rgba_aos(builder,
+ tmp = lp_build_fetch_subsampled_rgba_aos(gallivm,
format_desc,
num_pixels,
base_ptr,
offset,
i, j);
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
tmp_type, type,
&tmp, 1, &tmp, 1);
@@ -505,51 +512,52 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* or incentive to optimize.
*/
- LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
- char name[256];
- LLVMTypeRef i8t = LLVMInt8Type();
+ LLVMTypeRef i8t = LLVMInt8TypeInContext(gallivm->context);
LLVMTypeRef pi8t = LLVMPointerType(i8t, 0);
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef function;
LLVMValueRef tmp_ptr;
LLVMValueRef tmp;
LLVMValueRef res;
unsigned k;
- util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_8unorm",
- format_desc->short_name);
-
if (gallivm_debug & GALLIVM_DEBUG_PERF) {
- debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
+ debug_printf("%s: falling back to util_format_%s_fetch_rgba_8unorm\n",
+ __FUNCTION__, format_desc->short_name);
}
/*
* Declare and bind format_desc->fetch_rgba_8unorm().
*/
- function = LLVMGetNamedFunction(module, name);
- if (!function) {
+ {
+ /*
+ * Function to call looks like:
+ * fetch(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
+ */
LLVMTypeRef ret_type;
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
- ret_type = LLVMVoidType();
+ ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pi8t;
arg_types[1] = pi8t;
- arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
- function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
- function = LLVMAddFunction(module, name, function_type);
-
- LLVMSetFunctionCallConv(function, LLVMCCallConv);
- LLVMSetLinkage(function, LLVMExternalLinkage);
-
- assert(LLVMIsDeclaration(function));
-
- LLVMAddGlobalMapping(lp_build_engine, function,
- func_to_pointer((func_pointer)format_desc->fetch_rgba_8unorm));
+ arg_types[2] = i32t;
+ arg_types[3] = i32t;
+ function_type = LLVMFunctionType(ret_type, arg_types,
+ Elements(arg_types), 0);
+
+ /* make const pointer for the C fetch_rgba_8unorm function */
+ function = lp_build_const_int_pointer(gallivm,
+ func_to_pointer((func_pointer) format_desc->fetch_rgba_8unorm));
+
+ /* cast the callee pointer to the function's type */
+ function = LLVMBuildBitCast(builder, function,
+ LLVMPointerType(function_type, 0),
+ "cast callee");
}
- tmp_ptr = lp_build_alloca(builder, i32t, "");
+ tmp_ptr = lp_build_alloca(gallivm, i32t, "");
res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels));
@@ -559,11 +567,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
*/
for (k = 0; k < num_pixels; ++k) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pi8t, "");
- args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
+ args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@@ -608,51 +616,58 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* or incentive to optimize.
*/
- LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
- char name[256];
- LLVMTypeRef f32t = LLVMFloatType();
+ LLVMTypeRef f32t = LLVMFloatTypeInContext(gallivm->context);
LLVMTypeRef f32x4t = LLVMVectorType(f32t, 4);
LLVMTypeRef pf32t = LLVMPointerType(f32t, 0);
+ LLVMTypeRef pi8t = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0);
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef function;
LLVMValueRef tmp_ptr;
LLVMValueRef tmps[LP_MAX_VECTOR_LENGTH/4];
LLVMValueRef res;
unsigned k;
- util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_float",
- format_desc->short_name);
-
if (gallivm_debug & GALLIVM_DEBUG_PERF) {
- debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
+ debug_printf("%s: falling back to util_format_%s_fetch_rgba_float\n",
+ __FUNCTION__, format_desc->short_name);
}
/*
* Declare and bind format_desc->fetch_rgba_float().
*/
- function = LLVMGetNamedFunction(module, name);
- if (!function) {
+ {
+ /*
+ * Function to call looks like:
+ * fetch(float *dst, const uint8_t *src, unsigned i, unsigned j)
+ */
LLVMTypeRef ret_type;
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
- ret_type = LLVMVoidType();
+ ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pf32t;
- arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
- arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
- function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
- function = LLVMAddFunction(module, name, function_type);
+ arg_types[1] = pi8t;
+ arg_types[2] = i32t;
+ arg_types[3] = i32t;
+ function_type = LLVMFunctionType(ret_type, arg_types,
+ Elements(arg_types), 0);
- LLVMSetFunctionCallConv(function, LLVMCCallConv);
- LLVMSetLinkage(function, LLVMExternalLinkage);
+ /* Note: we're using this casting here instead of LLVMAddGlobalMapping()
+ * to work around a bug in LLVM 2.6, and for efficiency/simplicity.
+ */
- assert(LLVMIsDeclaration(function));
+ /* make const pointer for the C fetch_rgba_float function */
+ function = lp_build_const_int_pointer(gallivm,
+ func_to_pointer((func_pointer) format_desc->fetch_rgba_float));
- LLVMAddGlobalMapping(lp_build_engine, function,
- func_to_pointer((func_pointer)format_desc->fetch_rgba_float));
+ /* cast the callee pointer to the function's type */
+ function = LLVMBuildBitCast(builder, function,
+ LLVMPointerType(function_type, 0),
+ "cast callee");
}
- tmp_ptr = lp_build_alloca(builder, f32x4t, "");
+ tmp_ptr = lp_build_alloca(gallivm, f32x4t, "");
/*
* Invoke format_desc->fetch_rgba_float() for each pixel and insert the result
@@ -663,7 +678,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pf32t, "");
- args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
+ args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@@ -671,7 +686,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
args[3] = j;
}
else {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
args[2] = LLVMBuildExtractElement(builder, i, index, "");
args[3] = LLVMBuildExtractElement(builder, j, index, "");
}
@@ -681,7 +696,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmps[k] = LLVMBuildLoad(builder, tmp_ptr, "");
}
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@@ -690,5 +705,5 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
}
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
index ce7e54afc76..0a57b3ce794 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
@@ -97,12 +97,13 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
* \param rgba_out returns the SoA R,G,B,A vectors
*/
void
-lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
+lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4])
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context bld;
LLVMValueRef inputs[4];
unsigned start;
@@ -116,7 +117,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(type.floating);
assert(type.width == 32);
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
/* Decode the input vector components */
start = 0;
@@ -129,7 +130,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
switch(format_desc->channel[chan].type) {
case UTIL_FORMAT_TYPE_VOID:
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
break;
case UTIL_FORMAT_TYPE_UNSIGNED:
@@ -138,7 +139,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (start) {
- input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(type, start), "");
+ input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(gallivm, type, start), "");
}
/*
@@ -147,7 +148,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < format_desc->block.bits) {
unsigned mask = ((unsigned long long)1 << width) - 1;
- input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(type, mask), "");
+ input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(gallivm, type, mask), "");
}
/*
@@ -156,14 +157,15 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (type.floating) {
if(format_desc->channel[chan].normalized)
- input = lp_build_unsigned_norm_to_float(builder, width, type, input);
+ input = lp_build_unsigned_norm_to_float(gallivm, width, type, input);
else
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildSIToFP(builder, input,
+ lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
@@ -175,7 +177,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < type.width) {
unsigned bits = type.width - stop;
- LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
+ LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildShl(builder, input, bits_val, "");
}
@@ -185,7 +187,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (format_desc->channel[chan].size < type.width) {
unsigned bits = type.width - format_desc->channel[chan].size;
- LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
+ LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildAShr(builder, input, bits_val, "");
}
@@ -194,17 +196,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (type.floating) {
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
if (format_desc->channel[chan].normalized) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size - 1)) - 1);
- LLVMValueRef scale_val = lp_build_const_vec(type, scale);
+ LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
input = LLVMBuildFMul(builder, input, scale_val, "");
}
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
@@ -214,32 +216,32 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(start == 0);
assert(stop == 32);
assert(type.width == 32);
- input = LLVMBuildBitCast(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildBitCast(builder, input, lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
case UTIL_FORMAT_TYPE_FIXED:
if (type.floating) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size/2)) - 1);
- LLVMValueRef scale_val = lp_build_const_vec(type, scale);
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
+ input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
input = LLVMBuildFMul(builder, input, scale_val, "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
default:
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
break;
}
@@ -253,16 +255,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
void
-lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
+lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba)
{
- LLVMValueRef mask = lp_build_const_int_vec(dst_type, 0xff);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef mask = lp_build_const_int_vec(gallivm, dst_type, 0xff);
unsigned chan;
packed = LLVMBuildBitCast(builder, packed,
- lp_build_int_vec_type(dst_type), "");
+ lp_build_int_vec_type(gallivm, dst_type), "");
/* Decode the input vector components */
for (chan = 0; chan < 4; ++chan) {
@@ -274,12 +277,12 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
if (start)
input = LLVMBuildLShr(builder, input,
- lp_build_const_int_vec(dst_type, start), "");
+ lp_build_const_int_vec(gallivm, dst_type, start), "");
if (stop < 32)
input = LLVMBuildAnd(builder, input, mask, "");
- input = lp_build_unsigned_norm_to_float(builder, 8, dst_type, input);
+ input = lp_build_unsigned_norm_to_float(gallivm, 8, dst_type, input);
rgba[chan] = input;
}
@@ -303,7 +306,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
* be in [0, block_width-1] and j will be in [0, block_height-1].
*/
void
-lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
+lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -312,6 +315,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef j,
LLVMValueRef rgba_out[4])
{
+ LLVMBuilderRef builder = gallivm->builder;
if (format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN &&
(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
@@ -334,7 +338,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* gather the texels from the texture
* Ex: packed = {BGRA, BGRA, BGRA, BGRA}.
*/
- packed = lp_build_gather(builder,
+ packed = lp_build_gather(gallivm,
type.length,
format_desc->block.bits,
type.width,
@@ -343,7 +347,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
/*
* convert texels to float rgba
*/
- lp_build_unpack_rgba_soa(builder,
+ lp_build_unpack_rgba_soa(gallivm,
format_desc,
type,
packed, rgba_out);
@@ -364,10 +368,10 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = type.length * 4;
tmp_type.norm = TRUE;
- tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
+ tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset, i, j);
- lp_build_rgba8_to_f32_soa(builder,
+ lp_build_rgba8_to_f32_soa(gallivm,
type,
tmp,
rgba_out);
@@ -397,23 +401,24 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = 4;
for (chan = 0; chan < 4; ++chan) {
- rgba_out[chan] = lp_build_undef(type);
+ rgba_out[chan] = lp_build_undef(gallivm, type);
}
/* loop over number of pixels */
for(k = 0; k < type.length; ++k) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef offset_elem;
LLVMValueRef i_elem, j_elem;
LLVMValueRef tmp;
- offset_elem = LLVMBuildExtractElement(builder, offset, index, "");
+ offset_elem = LLVMBuildExtractElement(builder, offset,
+ index, "");
i_elem = LLVMBuildExtractElement(builder, i, index, "");
j_elem = LLVMBuildExtractElement(builder, j, index, "");
/* Get a single float[4]={R,G,B,A} pixel */
- tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
+ tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset_elem,
i_elem, j_elem);
@@ -422,7 +427,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* position = 'index'.
*/
for (chan = 0; chan < 4; ++chan) {
- LLVMValueRef chan_val = LLVMConstInt(LLVMInt32Type(), chan, 0),
+ LLVMValueRef chan_val = lp_build_const_int32(gallivm, chan),
tmp_chan = LLVMBuildExtractElement(builder, tmp, chan_val, "");
rgba_out[chan] = LLVMBuildInsertElement(builder, rgba_out[chan],
tmp_chan, index, "");
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
index 2bce2895551..cdf1956c093 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
@@ -43,6 +43,7 @@
#include "lp_bld_conv.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
/**
@@ -51,7 +52,7 @@
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
-uyvy_to_yuv_soa(LLVMBuilderRef builder,
+uyvy_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@@ -59,6 +60,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@@ -86,25 +88,25 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp, tmp2;
struct lp_build_context bld32;
- lp_build_context_init(&bld32, builder, type);
+ lp_build_context_init(&bld32, gallivm, type);
- tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
- tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(type, 16), "");
- sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
+ tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
+ tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(gallivm, type, 16), "");
+ sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, tmp, tmp2);
} else
#endif
{
LLVMValueRef shift;
- shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
- shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(type, 8), "");
+ shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
+ shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(gallivm, type, 8), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
*u = packed;
- *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
+ *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
- mask = lp_build_const_int_vec(type, 0xff);
+ mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@@ -118,7 +120,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
-yuyv_to_yuv_soa(LLVMBuilderRef builder,
+yuyv_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@@ -126,6 +128,7 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@@ -153,23 +156,23 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp;
struct lp_build_context bld32;
- lp_build_context_init(&bld32, builder, type);
+ lp_build_context_init(&bld32, gallivm, type);
- tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
- sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
+ tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
+ sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, packed, tmp);
} else
#endif
{
LLVMValueRef shift;
- shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
+ shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
- *u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
- *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 24), "");
+ *u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
+ *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 24), "");
- mask = lp_build_const_int_vec(type, 0xff);
+ mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@@ -178,11 +181,12 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
static INLINE void
-yuv_to_rgb_soa(LLVMBuilderRef builder,
+yuv_to_rgb_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef y, LLVMValueRef u, LLVMValueRef v,
LLVMValueRef *r, LLVMValueRef *g, LLVMValueRef *b)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
struct lp_build_context bld;
@@ -203,7 +207,7 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
type.width = 32;
type.length = n;
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
assert(lp_check_value(type, y));
assert(lp_check_value(type, u));
@@ -213,17 +217,17 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
* Constants
*/
- c0 = lp_build_const_int_vec(type, 0);
- c8 = lp_build_const_int_vec(type, 8);
- c16 = lp_build_const_int_vec(type, 16);
- c128 = lp_build_const_int_vec(type, 128);
- c255 = lp_build_const_int_vec(type, 255);
+ c0 = lp_build_const_int_vec(gallivm, type, 0);
+ c8 = lp_build_const_int_vec(gallivm, type, 8);
+ c16 = lp_build_const_int_vec(gallivm, type, 16);
+ c128 = lp_build_const_int_vec(gallivm, type, 128);
+ c255 = lp_build_const_int_vec(gallivm, type, 255);
- cy = lp_build_const_int_vec(type, 298);
- cug = lp_build_const_int_vec(type, -100);
- cub = lp_build_const_int_vec(type, 516);
- cvr = lp_build_const_int_vec(type, 409);
- cvg = lp_build_const_int_vec(type, -208);
+ cy = lp_build_const_int_vec(gallivm, type, 298);
+ cug = lp_build_const_int_vec(gallivm, type, -100);
+ cub = lp_build_const_int_vec(gallivm, type, 516);
+ cvr = lp_build_const_int_vec(gallivm, type, 409);
+ cvg = lp_build_const_int_vec(gallivm, type, -208);
/*
* y -= 16;
@@ -276,10 +280,11 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
static LLVMValueRef
-rgb_to_rgba_aos(LLVMBuilderRef builder,
+rgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef r, LLVMValueRef g, LLVMValueRef b)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef a;
LLVMValueRef rgba;
@@ -298,9 +303,9 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
*/
r = r;
- g = LLVMBuildShl(builder, g, lp_build_const_int_vec(type, 8), "");
- b = LLVMBuildShl(builder, b, lp_build_const_int_vec(type, 16), "");
- a = lp_build_const_int_vec(type, 0xff000000);
+ g = LLVMBuildShl(builder, g, lp_build_const_int_vec(gallivm, type, 8), "");
+ b = LLVMBuildShl(builder, b, lp_build_const_int_vec(gallivm, type, 16), "");
+ a = lp_build_const_int_vec(gallivm, type, 0xff000000);
rgba = r;
rgba = LLVMBuildOr(builder, rgba, g, "");
@@ -308,7 +313,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
rgba = LLVMBuildOr(builder, rgba, a, "");
rgba = LLVMBuildBitCast(builder, rgba,
- LLVMVectorType(LLVMInt8Type(), 4*n), "");
+ LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n), "");
return rgba;
}
@@ -318,7 +323,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed UYVY to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-uyvy_to_rgba_aos(LLVMBuilderRef builder,
+uyvy_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -327,9 +332,9 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- uyvy_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
- yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ uyvy_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
+ yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -339,7 +344,7 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed YUYV to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-yuyv_to_rgba_aos(LLVMBuilderRef builder,
+yuyv_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -348,9 +353,9 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- yuyv_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
- yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ yuyv_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
+ yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -360,7 +365,7 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed RG_BG to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-rgbg_to_rgba_aos(LLVMBuilderRef builder,
+rgbg_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -368,8 +373,8 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- uyvy_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ uyvy_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -379,7 +384,7 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed GR_GB to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-grgb_to_rgba_aos(LLVMBuilderRef builder,
+grgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -387,8 +392,8 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- yuyv_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ yuyv_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -401,7 +406,7 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
* @return a <4*n x i8> vector with the pixel RGBA values in AoS
*/
LLVMValueRef
-lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,
@@ -417,26 +422,26 @@ lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
assert(format_desc->block.width == 2);
assert(format_desc->block.height == 1);
- packed = lp_build_gather(builder, n, 32, 32, base_ptr, offset);
+ packed = lp_build_gather(gallivm, n, 32, 32, base_ptr, offset);
(void)j;
switch (format_desc->format) {
case PIPE_FORMAT_UYVY:
- rgba = uyvy_to_rgba_aos(builder, n, packed, i);
+ rgba = uyvy_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_YUYV:
- rgba = yuyv_to_rgba_aos(builder, n, packed, i);
+ rgba = yuyv_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_R8G8_B8G8_UNORM:
- rgba = rgbg_to_rgba_aos(builder, n, packed, i);
+ rgba = rgbg_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_G8R8_G8B8_UNORM:
- rgba = grgb_to_rgba_aos(builder, n, packed, i);
+ rgba = grgb_to_rgba_aos(gallivm, n, packed, i);
break;
default:
assert(0);
- rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8Type(), 4*n));
+ rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n));
break;
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
index d60472e0656..0dc81b1abbe 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
@@ -31,6 +31,7 @@
#include "lp_bld_const.h"
#include "lp_bld_format.h"
#include "lp_bld_gather.h"
+#include "lp_bld_init.h"
/**
@@ -39,7 +40,7 @@
* @sa lp_build_gather()
*/
LLVMValueRef
-lp_build_gather_elem_ptr(LLVMBuilderRef builder,
+lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
@@ -48,17 +49,17 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
LLVMValueRef offset;
LLVMValueRef ptr;
- assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
+ assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
if (length == 1) {
assert(i == 0);
offset = offsets;
} else {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- offset = LLVMBuildExtractElement(builder, offsets, index, "");
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
+ offset = LLVMBuildExtractElement(gallivm->builder, offsets, index, "");
}
- ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, "");
+ ptr = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, "");
return ptr;
}
@@ -70,7 +71,7 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
* @sa lp_build_gather()
*/
LLVMValueRef
-lp_build_gather_elem(LLVMBuilderRef builder,
+lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -78,23 +79,23 @@ lp_build_gather_elem(LLVMBuilderRef builder,
LLVMValueRef offsets,
unsigned i)
{
- LLVMTypeRef src_type = LLVMIntType(src_width);
+ LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, src_width);
LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0);
- LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
+ LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMValueRef ptr;
LLVMValueRef res;
- assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
+ assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
- ptr = lp_build_gather_elem_ptr(builder, length, base_ptr, offsets, i);
- ptr = LLVMBuildBitCast(builder, ptr, src_ptr_type, "");
- res = LLVMBuildLoad(builder, ptr, "");
+ ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i);
+ ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, "");
+ res = LLVMBuildLoad(gallivm->builder, ptr, "");
assert(src_width <= dst_width);
if (src_width > dst_width)
- res = LLVMBuildTrunc(builder, res, dst_elem_type, "");
+ res = LLVMBuildTrunc(gallivm->builder, res, dst_elem_type, "");
if (src_width < dst_width)
- res = LLVMBuildZExt(builder, res, dst_elem_type, "");
+ res = LLVMBuildZExt(gallivm->builder, res, dst_elem_type, "");
return res;
}
@@ -112,7 +113,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
* @param offsets vector with offsets
*/
LLVMValueRef
-lp_build_gather(LLVMBuilderRef builder,
+lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -123,24 +124,24 @@ lp_build_gather(LLVMBuilderRef builder,
if (length == 1) {
/* Scalar */
- return lp_build_gather_elem(builder, length,
+ return lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, 0);
} else {
/* Vector */
- LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
+ LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length);
unsigned i;
res = LLVMGetUndef(dst_vec_type);
for (i = 0; i < length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef elem;
- elem = lp_build_gather_elem(builder, length,
+ elem = lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, i);
- res = LLVMBuildInsertElement(builder, res, elem, index, "");
+ res = LLVMBuildInsertElement(gallivm->builder, res, elem, index, "");
}
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.h b/src/gallium/auxiliary/gallivm/lp_bld_gather.h
index 131af8ea07e..5b041317302 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.h
@@ -34,14 +34,14 @@
LLVMValueRef
-lp_build_gather_elem_ptr(LLVMBuilderRef builder,
+lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
unsigned i);
LLVMValueRef
-lp_build_gather_elem(LLVMBuilderRef builder,
+lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -50,7 +50,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
unsigned i);
LLVMValueRef
-lp_build_gather(LLVMBuilderRef builder,
+lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 0b9a6f745fb..7504cb5cf2f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -29,6 +29,8 @@
#include "pipe/p_compiler.h"
#include "util/u_cpu_detect.h"
#include "util/u_debug.h"
+#include "util/u_memory.h"
+#include "util/u_simple_list.h"
#include "lp_bld_debug.h"
#include "lp_bld_init.h"
@@ -45,6 +47,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
{ "nopt", GALLIVM_DEBUG_NO_OPT, NULL },
{ "perf", GALLIVM_DEBUG_PERF, NULL },
{ "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL },
+ { "gc", GALLIVM_DEBUG_GC, NULL },
DEBUG_NAMED_VALUE_END
};
@@ -52,11 +55,7 @@ DEBUG_GET_ONCE_FLAGS_OPTION(gallivm_debug, "GALLIVM_DEBUG", lp_bld_debug_flags,
#endif
-LLVMModuleRef lp_build_module = NULL;
-LLVMExecutionEngineRef lp_build_engine = NULL;
-LLVMModuleProviderRef lp_build_provider = NULL;
-LLVMTargetDataRef lp_build_target = NULL;
-LLVMPassManagerRef lp_build_pass = NULL;
+static boolean gallivm_initialized = FALSE;
/*
@@ -82,6 +81,19 @@ enum LLVM_CodeGenOpt_Level {
};
+/**
+ * LLVM 2.6 permits only one ExecutionEngine to be created. This is it.
+ */
+static LLVMExecutionEngineRef GlobalEngine = NULL;
+
+/**
+ * Same gallivm state shared by all contexts.
+ */
+static struct gallivm_state *GlobalGallivm = NULL;
+
+
+
+
extern void
lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE);
@@ -89,26 +101,148 @@ extern void
lp_set_target_options(void);
-void
-lp_build_init(void)
+
+/**
+ * Create the LLVM (optimization) pass manager and install
+ * relevant optimization passes.
+ * \return TRUE for success, FALSE for failure
+ */
+static boolean
+create_pass_manager(struct gallivm_state *gallivm)
{
-#ifdef DEBUG
- gallivm_debug = debug_get_option_gallivm_debug();
+ assert(!gallivm->passmgr);
+
+ gallivm->passmgr = LLVMCreateFunctionPassManager(gallivm->provider);
+ if (!gallivm->passmgr)
+ return FALSE;
+
+ LLVMAddTargetData(gallivm->target, gallivm->passmgr);
+
+ if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
+ /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
+ * but there are more on SVN.
+ * TODO: Add more passes.
+ */
+ LLVMAddCFGSimplificationPass(gallivm->passmgr);
+
+ if (HAVE_LLVM >= 0x207 && sizeof(void*) == 4) {
+ /* For LLVM >= 2.7 and 32-bit build, use this order of passes to
+ * avoid generating bad code.
+ * Test with piglit glsl-vs-sqrt-zero test.
+ */
+ LLVMAddConstantPropagationPass(gallivm->passmgr);
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ }
+ else {
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ LLVMAddConstantPropagationPass(gallivm->passmgr);
+ }
+
+ if (util_cpu_caps.has_sse4_1) {
+ /* FIXME: There is a bug in this pass, whereby the combination
+ * of fptosi and sitofp (necessary for trunc/floor/ceil/round
+ * implementation) somehow becomes invalid code.
+ */
+ LLVMAddInstructionCombiningPass(gallivm->passmgr);
+ }
+ LLVMAddGVNPass(gallivm->passmgr);
+ }
+ else {
+ /* We need at least this pass to prevent the backends to fail in
+ * unexpected ways.
+ */
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * Free gallivm object's LLVM allocations, but not the gallivm object itself.
+ */
+static void
+free_gallivm_state(struct gallivm_state *gallivm)
+{
+#if HAVE_LLVM >= 0x207 /* XXX or 0x208? */
+ /* This leads to crashes w/ some versions of LLVM */
+ LLVMModuleRef mod;
+ char *error;
+
+ if (gallivm->engine && gallivm->provider)
+ LLVMRemoveModuleProvider(gallivm->engine, gallivm->provider,
+ &mod, &error);
#endif
- lp_set_target_options();
+#if 0
+ /* XXX this seems to crash with all versions of LLVM */
+ if (gallivm->provider)
+ LLVMDisposeModuleProvider(gallivm->provider);
+#endif
- LLVMInitializeNativeTarget();
+ if (gallivm->passmgr)
+ LLVMDisposePassManager(gallivm->passmgr);
- LLVMLinkInJIT();
+#if HAVE_LLVM >= 0x207
+ if (gallivm->module)
+ LLVMDisposeModule(gallivm->module);
+#endif
+
+#if 0
+ /* Don't free the exec engine, it's a global/singleton */
+ if (gallivm->engine)
+ LLVMDisposeExecutionEngine(gallivm->engine);
+#endif
+
+#if 0
+ /* Don't free the TargetData, it's owned by the exec engine */
+ LLVMDisposeTargetData(gallivm->target);
+#endif
+
+ if (gallivm->context)
+ LLVMContextDispose(gallivm->context);
- if (!lp_build_module)
- lp_build_module = LLVMModuleCreateWithName("gallivm");
+ if (gallivm->builder)
+ LLVMDisposeBuilder(gallivm->builder);
+
+ gallivm->engine = NULL;
+ gallivm->target = NULL;
+ gallivm->module = NULL;
+ gallivm->provider = NULL;
+ gallivm->passmgr = NULL;
+ gallivm->context = NULL;
+ gallivm->builder = NULL;
+}
- if (!lp_build_provider)
- lp_build_provider = LLVMCreateModuleProviderForExistingModule(lp_build_module);
- if (!lp_build_engine) {
+/**
+ * Allocate gallivm LLVM objects.
+ * \return TRUE for success, FALSE for failure
+ */
+static boolean
+init_gallivm_state(struct gallivm_state *gallivm)
+{
+ assert(gallivm_initialized);
+ assert(!gallivm->context);
+ assert(!gallivm->module);
+ assert(!gallivm->provider);
+
+ gallivm->context = LLVMContextCreate();
+ if (!gallivm->context)
+ goto fail;
+
+ gallivm->module = LLVMModuleCreateWithNameInContext("gallivm",
+ gallivm->context);
+ if (!gallivm->module)
+ goto fail;
+
+ gallivm->provider =
+ LLVMCreateModuleProviderForExistingModule(gallivm->module);
+ if (!gallivm->provider)
+ goto fail;
+
+ if (!GlobalEngine) {
+ /* We can only create one LLVMExecutionEngine (w/ LLVM 2.6 anyway) */
enum LLVM_CodeGenOpt_Level optlevel;
char *error = NULL;
@@ -119,43 +253,153 @@ lp_build_init(void)
optlevel = Default;
}
- if (LLVMCreateJITCompiler(&lp_build_engine, lp_build_provider,
- (unsigned)optlevel, &error)) {
+ if (LLVMCreateJITCompiler(&GlobalEngine, gallivm->provider,
+ (unsigned) optlevel, &error)) {
_debug_printf("%s\n", error);
LLVMDisposeMessage(error);
- assert(0);
+ goto fail;
}
#if defined(DEBUG) || defined(PROFILE)
- lp_register_oprofile_jit_event_listener(lp_build_engine);
+ lp_register_oprofile_jit_event_listener(GlobalEngine);
#endif
}
- if (!lp_build_target)
- lp_build_target = LLVMGetExecutionEngineTargetData(lp_build_engine);
-
- if (!lp_build_pass) {
- lp_build_pass = LLVMCreateFunctionPassManager(lp_build_provider);
- LLVMAddTargetData(lp_build_target, lp_build_pass);
-
- if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
- /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
- * but there are more on SVN. */
- /* TODO: Add more passes */
- LLVMAddCFGSimplificationPass(lp_build_pass);
- LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
- LLVMAddConstantPropagationPass(lp_build_pass);
- LLVMAddInstructionCombiningPass(lp_build_pass);
- LLVMAddGVNPass(lp_build_pass);
- } else {
- /* We need at least this pass to prevent the backends to fail in
- * unexpected ways.
- */
- LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
+ gallivm->engine = GlobalEngine;
+
+ LLVMAddModuleProvider(gallivm->engine, gallivm->provider);//new
+
+ gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine);
+ if (!gallivm->target)
+ goto fail;
+
+ if (!create_pass_manager(gallivm))
+ goto fail;
+
+ gallivm->builder = LLVMCreateBuilderInContext(gallivm->context);
+ if (!gallivm->builder)
+ goto fail;
+
+ return TRUE;
+
+fail:
+ free_gallivm_state(gallivm);
+ return FALSE;
+}
+
+
+struct callback
+{
+ garbage_collect_callback_func func;
+ void *cb_data;
+ struct callback *prev, *next;
+};
+
+
+/** list of all garbage collector callbacks */
+static struct callback callback_list = {NULL, NULL, NULL, NULL};
+
+
+/**
+ * Register a function with gallivm which will be called when we
+ * do garbage collection.
+ */
+void
+gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data)
+{
+ struct callback *cb;
+
+ if (!callback_list.prev) {
+ make_empty_list(&callback_list);
+ }
+
+ /* see if already in list */
+ foreach(cb, &callback_list) {
+ if (cb->func == func && cb->cb_data == cb_data)
+ return;
+ }
+
+ /* add to list */
+ cb = CALLOC_STRUCT(callback);
+ if (cb) {
+ cb->func = func;
+ cb->cb_data = cb_data;
+ insert_at_head(&callback_list, cb);
+ }
+}
+
+
+/**
+ * Remove a callback.
+ */
+void
+gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data)
+{
+ struct callback *cb;
+
+ /* search list */
+ foreach(cb, &callback_list) {
+ if (cb->func == func && cb->cb_data == cb_data) {
+ /* found, remove it */
+ remove_from_list(cb);
+ return;
}
}
+}
+
+
+/**
+ * Call the callback functions (which are typically in the
+ * draw module and llvmpipe driver.
+ */
+static void
+call_garbage_collector_callbacks(void)
+{
+ struct callback *cb;
+ foreach(cb, &callback_list) {
+ cb->func(cb->cb_data);
+ }
+}
+
+
+
+/**
+ * Other gallium components using gallivm should call this periodically
+ * to let us do garbage collection (or at least try to free memory
+ * accumulated by the LLVM libraries).
+ */
+void
+gallivm_garbage_collect(struct gallivm_state *gallivm)
+{
+ if (gallivm->context) {
+ if (gallivm_debug & GALLIVM_DEBUG_GC)
+ debug_printf("***** Doing LLVM garbage collection\n");
+
+ call_garbage_collector_callbacks();
+ free_gallivm_state(gallivm);
+ init_gallivm_state(gallivm);
+ }
+}
+
+
+void
+lp_build_init(void)
+{
+#ifdef DEBUG
+ gallivm_debug = debug_get_option_gallivm_debug();
+#endif
+
+ lp_set_target_options();
+
+ LLVMInitializeNativeTarget();
+
+ LLVMLinkInJIT();
util_cpu_detect();
+
+ gallivm_initialized = TRUE;
#if 0
/* For simulating less capable machines */
@@ -166,6 +410,39 @@ lp_build_init(void)
}
+
+/**
+ * Create a new gallivm_state object.
+ * Note that we return a singleton.
+ */
+struct gallivm_state *
+gallivm_create(void)
+{
+ if (!GlobalGallivm) {
+ GlobalGallivm = CALLOC_STRUCT(gallivm_state);
+ if (GlobalGallivm) {
+ if (!init_gallivm_state(GlobalGallivm)) {
+ FREE(GlobalGallivm);
+ GlobalGallivm = NULL;
+ }
+ }
+ }
+ return GlobalGallivm;
+}
+
+
+/**
+ * Destroy a gallivm_state object.
+ */
+void
+gallivm_destroy(struct gallivm_state *gallivm)
+{
+ /* No-op: don't destroy the singleton */
+ (void) gallivm;
+}
+
+
+
/*
* Hack to allow the linking of release LLVM static libraries on a debug build.
*
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 0b4b1ca7d11..f68bf75a851 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -30,24 +30,53 @@
#define LP_BLD_INIT_H
+#include "pipe/p_compiler.h"
#include "lp_bld.h"
#include <llvm-c/ExecutionEngine.h>
-extern LLVMModuleRef lp_build_module;
-extern LLVMExecutionEngineRef lp_build_engine;
-extern LLVMModuleProviderRef lp_build_provider;
-extern LLVMTargetDataRef lp_build_target;
-extern LLVMPassManagerRef lp_build_pass;
+struct gallivm_state
+{
+ LLVMModuleRef module;
+ LLVMExecutionEngineRef engine;
+ LLVMModuleProviderRef provider;
+ LLVMTargetDataRef target;
+ LLVMPassManagerRef passmgr;
+ LLVMContextRef context;
+ LLVMBuilderRef builder;
+};
void
lp_build_init(void);
+
extern void
lp_func_delete_body(LLVMValueRef func);
+void
+gallivm_garbage_collect(struct gallivm_state *gallivm);
+
+
+typedef void (*garbage_collect_callback_func)(void *cb_data);
+
+void
+gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data);
+
+void
+gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data);
+
+
+struct gallivm_state *
+gallivm_create(void);
+
+void
+gallivm_destroy(struct gallivm_state *gallivm);
+
+
extern LLVMValueRef
lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
const char *Name);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
index 9895749d568..518a01fdb9f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
@@ -46,6 +46,7 @@
#include "util/u_debug.h"
+#include "lp_bld_const.h"
#include "lp_bld_intr.h"
@@ -136,12 +137,13 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map(LLVMBuilderRef builder,
+lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
unsigned num_args)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef ret_elem_type = LLVMGetElementType(ret_type);
unsigned n = LLVMGetVectorSize(ret_type);
unsigned i, j;
@@ -151,7 +153,7 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
res = LLVMGetUndef(ret_type);
for(i = 0; i < n; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef arg_elems[LP_MAX_FUNC_ARGS];
LLVMValueRef res_elem;
for(j = 0; j < num_args; ++j)
@@ -165,17 +167,17 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a)
{
- return lp_build_intrinsic_map(builder, name, ret_type, &a, 1);
+ return lp_build_intrinsic_map(gallivm, name, ret_type, &a, 1);
}
LLVMValueRef
-lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,
@@ -186,7 +188,7 @@ lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
args[0] = a;
args[1] = b;
- return lp_build_intrinsic_map(builder, name, ret_type, args, 2);
+ return lp_build_intrinsic_map(gallivm, name, ret_type, args, 2);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
index 977f7673228..b73dd700362 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
@@ -38,6 +38,7 @@
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
/**
@@ -77,7 +78,7 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map(LLVMBuilderRef builder,
+lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
@@ -85,14 +86,14 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a);
LLVMValueRef
-lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
index 026b60ac36e..f7e6fbaff1a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
@@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_debug.h"
#include "lp_bld_logic.h"
@@ -70,13 +71,14 @@
* The result values will be 0 for false or ~0 for true.
*/
LLVMValueRef
-lp_build_compare(LLVMBuilderRef builder,
+lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,
LLVMValueRef b)
{
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, type);
LLVMValueRef zeros = LLVMConstNull(int_vec_type);
LLVMValueRef ones = LLVMConstAllOnes(int_vec_type);
LLVMValueRef cond;
@@ -115,7 +117,7 @@ lp_build_compare(LLVMBuilderRef builder,
if(type.width * type.length == 128) {
if(type.floating && util_cpu_caps.has_sse) {
/* float[4] comparison */
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
LLVMValueRef args[3];
unsigned cc;
boolean swap;
@@ -144,7 +146,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
if(swap) {
@@ -156,7 +158,7 @@ lp_build_compare(LLVMBuilderRef builder,
args[1] = b;
}
- args[2] = LLVMConstInt(LLVMInt8Type(), cc, 0);
+ args[2] = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), cc, 0);
res = lp_build_intrinsic(builder,
"llvm.x86.sse.cmp.ps",
vec_type,
@@ -185,7 +187,7 @@ lp_build_compare(LLVMBuilderRef builder,
const char *pcmpgt;
LLVMValueRef args[2];
LLVMValueRef res;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
switch (type.width) {
case 8:
@@ -202,14 +204,14 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
/* There are no unsigned comparison instructions. So flip the sign bit
* so that the results match.
*/
if (table[func].gt && !type.sign) {
- LLVMValueRef msb = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef msb = lp_build_const_int_vec(gallivm, type, (unsigned long long)1 << (type.width - 1));
a = LLVMBuildXor(builder, a, msb, "");
b = LLVMBuildXor(builder, b, msb, "");
}
@@ -270,7 +272,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@@ -289,7 +291,7 @@ lp_build_compare(LLVMBuilderRef builder,
debug_printf("%s: warning: using slow element-wise float"
" vector comparison\n", __FUNCTION__);
for (i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildFCmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@@ -326,7 +328,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@@ -348,7 +350,7 @@ lp_build_compare(LLVMBuilderRef builder,
}
for(i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildICmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@@ -379,7 +381,7 @@ lp_build_cmp(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
- return lp_build_compare(bld->builder, bld->type, func, a, b);
+ return lp_build_compare(bld->gallivm, bld->type, func, a, b);
}
@@ -392,6 +394,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_type type = bld->type;
LLVMValueRef res;
@@ -403,25 +406,25 @@ lp_build_select_bitwise(struct lp_build_context *bld,
}
if(type.floating) {
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
- a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
- b = LLVMBuildBitCast(bld->builder, b, int_vec_type, "");
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
+ a = LLVMBuildBitCast(builder, a, int_vec_type, "");
+ b = LLVMBuildBitCast(builder, b, int_vec_type, "");
}
- a = LLVMBuildAnd(bld->builder, a, mask, "");
+ a = LLVMBuildAnd(builder, a, mask, "");
/* This often gets translated to PANDN, but sometimes the NOT is
* pre-computed and stored in another constant. The best strategy depends
* on available registers, so it is not a big deal -- hopefully LLVM does
* the right decision attending the rest of the program.
*/
- b = LLVMBuildAnd(bld->builder, b, LLVMBuildNot(bld->builder, mask, ""), "");
+ b = LLVMBuildAnd(builder, b, LLVMBuildNot(builder, mask, ""), "");
- res = LLVMBuildOr(bld->builder, a, b, "");
+ res = LLVMBuildOr(builder, a, b, "");
if(type.floating) {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- res = LLVMBuildBitCast(bld->builder, res, vec_type, "");
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ res = LLVMBuildBitCast(builder, res, vec_type, "");
}
return res;
@@ -440,6 +443,8 @@ lp_build_select(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMContextRef lc = bld->gallivm->context;
struct lp_type type = bld->type;
LLVMValueRef res;
@@ -450,8 +455,8 @@ lp_build_select(struct lp_build_context *bld,
return a;
if (type.length == 1) {
- mask = LLVMBuildTrunc(bld->builder, mask, LLVMInt1Type(), "");
- res = LLVMBuildSelect(bld->builder, mask, a, b, "");
+ mask = LLVMBuildTrunc(builder, mask, LLVMInt1TypeInContext(lc), "");
+ res = LLVMBuildSelect(builder, mask, a, b, "");
}
else if (util_cpu_caps.has_sse4_1 &&
type.width * type.length == 128 &&
@@ -465,34 +470,34 @@ lp_build_select(struct lp_build_context *bld,
if (type.floating &&
type.width == 64) {
intrinsic = "llvm.x86.sse41.blendvpd";
- arg_type = LLVMVectorType(LLVMDoubleType(), 2);
+ arg_type = LLVMVectorType(LLVMDoubleTypeInContext(lc), 2);
} else if (type.floating &&
type.width == 32) {
intrinsic = "llvm.x86.sse41.blendvps";
- arg_type = LLVMVectorType(LLVMFloatType(), 4);
+ arg_type = LLVMVectorType(LLVMFloatTypeInContext(lc), 4);
} else {
intrinsic = "llvm.x86.sse41.pblendvb";
- arg_type = LLVMVectorType(LLVMInt8Type(), 16);
+ arg_type = LLVMVectorType(LLVMInt8TypeInContext(lc), 16);
}
if (arg_type != bld->int_vec_type) {
- mask = LLVMBuildBitCast(bld->builder, mask, arg_type, "");
+ mask = LLVMBuildBitCast(builder, mask, arg_type, "");
}
if (arg_type != bld->vec_type) {
- a = LLVMBuildBitCast(bld->builder, a, arg_type, "");
- b = LLVMBuildBitCast(bld->builder, b, arg_type, "");
+ a = LLVMBuildBitCast(builder, a, arg_type, "");
+ b = LLVMBuildBitCast(builder, b, arg_type, "");
}
args[0] = b;
args[1] = a;
args[2] = mask;
- res = lp_build_intrinsic(bld->builder, intrinsic,
+ res = lp_build_intrinsic(builder, intrinsic,
arg_type, args, Elements(args));
if (arg_type != bld->vec_type) {
- res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
+ res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
}
else {
@@ -514,6 +519,7 @@ lp_build_select_aos(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@@ -544,7 +550,7 @@ lp_build_select_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
@@ -553,7 +559,7 @@ lp_build_select_aos(struct lp_build_context *bld,
(mask & (1 << i) ? 0 : n) + j + i,
0);
- return LLVMBuildShuffleVector(bld->builder, a, b, LLVMConstVector(shuffles, n), "");
+ return LLVMBuildShuffleVector(builder, a, b, LLVMConstVector(shuffles, n), "");
}
else {
#if 0
@@ -567,9 +573,9 @@ lp_build_select_aos(struct lp_build_context *bld,
cond_vec[j + i] = LLVMConstInt(elem_type,
mask & (1 << i) ? 1 : 0, 0);
- return LLVMBuildSelect(bld->builder, LLVMConstVector(cond_vec, n), a, b, "");
+ return LLVMBuildSelect(builder, LLVMConstVector(cond_vec, n), a, b, "");
#else
- LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask);
+ LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask);
return lp_build_select(bld, mask_vec, a, b);
#endif
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h
index 141fb92058a..ef33a653682 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h
@@ -47,7 +47,7 @@ struct lp_build_context;
LLVMValueRef
-lp_build_compare(LLVMBuilderRef builder,
+lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
index f7eb7148ab8..fde6bb594f1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
@@ -72,6 +72,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_arit.h"
#include "lp_bld_pack.h"
@@ -81,7 +82,8 @@
* Build shuffle vectors that match PUNPCKLxx and PUNPCKHxx instructions.
*/
static LLVMValueRef
-lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
+lp_build_const_unpack_shuffle(struct gallivm_state *gallivm,
+ unsigned n, unsigned lo_hi)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
@@ -92,8 +94,8 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
/* TODO: cache results in a static table */
for(i = 0, j = lo_hi*n/2; i < n; i += 2, ++j) {
- elems[i + 0] = LLVMConstInt(LLVMInt32Type(), 0 + j, 0);
- elems[i + 1] = LLVMConstInt(LLVMInt32Type(), n + j, 0);
+ elems[i + 0] = lp_build_const_int32(gallivm, 0 + j);
+ elems[i + 1] = lp_build_const_int32(gallivm, n + j);
}
return LLVMConstVector(elems, n);
@@ -104,7 +106,7 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
* Build shuffle vectors that match PACKxx instructions.
*/
static LLVMValueRef
-lp_build_const_pack_shuffle(unsigned n)
+lp_build_const_pack_shuffle(struct gallivm_state *gallivm, unsigned n)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -112,7 +114,7 @@ lp_build_const_pack_shuffle(unsigned n)
assert(n <= LP_MAX_VECTOR_LENGTH);
for(i = 0; i < n; ++i)
- elems[i] = LLVMConstInt(LLVMInt32Type(), 2*i, 0);
+ elems[i] = lp_build_const_int32(gallivm, 2*i);
return LLVMConstVector(elems, n);
}
@@ -124,7 +126,7 @@ lp_build_const_pack_shuffle(unsigned n)
* Matches the PUNPCKLxx and PUNPCKHxx SSE instructions.
*/
LLVMValueRef
-lp_build_interleave2(LLVMBuilderRef builder,
+lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@@ -132,9 +134,9 @@ lp_build_interleave2(LLVMBuilderRef builder,
{
LLVMValueRef shuffle;
- shuffle = lp_build_const_unpack_shuffle(type.length, lo_hi);
+ shuffle = lp_build_const_unpack_shuffle(gallivm, type.length, lo_hi);
- return LLVMBuildShuffleVector(builder, a, b, shuffle, "");
+ return LLVMBuildShuffleVector(gallivm->builder, a, b, shuffle, "");
}
@@ -145,13 +147,14 @@ lp_build_interleave2(LLVMBuilderRef builder,
* values themselves.
*/
void
-lp_build_unpack2(LLVMBuilderRef builder,
+lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
LLVMValueRef *dst_lo,
LLVMValueRef *dst_hi)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef msb;
LLVMTypeRef dst_vec_type;
@@ -162,24 +165,24 @@ lp_build_unpack2(LLVMBuilderRef builder,
if(dst_type.sign && src_type.sign) {
/* Replicate the sign bit in the most significant bits */
- msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(src_type, src_type.width - 1), "");
+ msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(gallivm, src_type, src_type.width - 1), "");
}
else
/* Most significant bits always zero */
- msb = lp_build_zero(src_type);
+ msb = lp_build_zero(gallivm, src_type);
/* Interleave bits */
#ifdef PIPE_ARCH_LITTLE_ENDIAN
- *dst_lo = lp_build_interleave2(builder, src_type, src, msb, 0);
- *dst_hi = lp_build_interleave2(builder, src_type, src, msb, 1);
+ *dst_lo = lp_build_interleave2(gallivm, src_type, src, msb, 0);
+ *dst_hi = lp_build_interleave2(gallivm, src_type, src, msb, 1);
#else
- *dst_lo = lp_build_interleave2(builder, src_type, msb, src, 0);
- *dst_hi = lp_build_interleave2(builder, src_type, msb, src, 1);
+ *dst_lo = lp_build_interleave2(gallivm, src_type, msb, src, 0);
+ *dst_hi = lp_build_interleave2(gallivm, src_type, msb, src, 1);
#endif
/* Cast the result into the new type (twice as wide) */
- dst_vec_type = lp_build_vec_type(dst_type);
+ dst_vec_type = lp_build_vec_type(gallivm, dst_type);
*dst_lo = LLVMBuildBitCast(builder, *dst_lo, dst_vec_type, "");
*dst_hi = LLVMBuildBitCast(builder, *dst_hi, dst_vec_type, "");
@@ -193,7 +196,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
* values themselves.
*/
void
-lp_build_unpack(LLVMBuilderRef builder,
+lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -218,7 +221,7 @@ lp_build_unpack(LLVMBuilderRef builder,
tmp_type.length /= 2;
for(i = num_tmps; i--; ) {
- lp_build_unpack2(builder, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
+ lp_build_unpack2(gallivm, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
}
src_type = tmp_type;
@@ -247,16 +250,17 @@ lp_build_unpack(LLVMBuilderRef builder,
* lp_build_packs2 instead.
*/
LLVMValueRef
-lp_build_pack2(LLVMBuilderRef builder,
+lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
LLVMValueRef hi)
{
+ LLVMBuilderRef builder = gallivm->builder;
#if HAVE_LLVM < 0x0207
- LLVMTypeRef src_vec_type = lp_build_vec_type(src_type);
+ LLVMTypeRef src_vec_type = lp_build_vec_type(gallivm, src_type);
#endif
- LLVMTypeRef dst_vec_type = lp_build_vec_type(dst_type);
+ LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, dst_type);
LLVMValueRef shuffle;
LLVMValueRef res = NULL;
@@ -318,7 +322,7 @@ lp_build_pack2(LLVMBuilderRef builder,
lo = LLVMBuildBitCast(builder, lo, dst_vec_type, "");
hi = LLVMBuildBitCast(builder, hi, dst_vec_type, "");
- shuffle = lp_build_const_pack_shuffle(dst_type.length);
+ shuffle = lp_build_const_pack_shuffle(gallivm, dst_type.length);
res = LLVMBuildShuffleVector(builder, lo, hi, shuffle, "");
@@ -334,7 +338,7 @@ lp_build_pack2(LLVMBuilderRef builder,
* destination type.
*/
LLVMValueRef
-lp_build_packs2(LLVMBuilderRef builder,
+lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -360,14 +364,14 @@ lp_build_packs2(LLVMBuilderRef builder,
if(clamp) {
struct lp_build_context bld;
unsigned dst_bits = dst_type.sign ? dst_type.width - 1 : dst_type.width;
- LLVMValueRef dst_max = lp_build_const_int_vec(src_type, ((unsigned long long)1 << dst_bits) - 1);
- lp_build_context_init(&bld, builder, src_type);
+ LLVMValueRef dst_max = lp_build_const_int_vec(gallivm, src_type, ((unsigned long long)1 << dst_bits) - 1);
+ lp_build_context_init(&bld, gallivm, src_type);
lo = lp_build_min(&bld, lo, dst_max);
hi = lp_build_min(&bld, hi, dst_max);
/* FIXME: What about lower bound? */
}
- return lp_build_pack2(builder, src_type, dst_type, lo, hi);
+ return lp_build_pack2(gallivm, src_type, dst_type, lo, hi);
}
@@ -377,13 +381,13 @@ lp_build_packs2(LLVMBuilderRef builder,
* TODO: Handle saturation consistently.
*/
LLVMValueRef
-lp_build_pack(LLVMBuilderRef builder,
+lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
const LLVMValueRef *src, unsigned num_srcs)
{
- LLVMValueRef (*pack2)(LLVMBuilderRef builder,
+ LLVMValueRef (*pack2)(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -419,7 +423,8 @@ lp_build_pack(LLVMBuilderRef builder,
num_srcs /= 2;
for(i = 0; i < num_srcs; ++i)
- tmp[i] = pack2(builder, src_type, tmp_type, tmp[2*i + 0], tmp[2*i + 1]);
+ tmp[i] = pack2(gallivm, src_type, tmp_type,
+ tmp[2*i + 0], tmp[2*i + 1]);
src_type = tmp_type;
}
@@ -437,12 +442,13 @@ lp_build_pack(LLVMBuilderRef builder,
* intrinsics that do saturation.
*/
void
-lp_build_resize(LLVMBuilderRef builder,
+lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -482,7 +488,7 @@ lp_build_resize(LLVMBuilderRef builder,
* Register width remains constant -- use vector packing intrinsics
*/
- tmp[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
+ tmp[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else {
/*
@@ -490,11 +496,11 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
- tmp[0] = lp_build_undef(dst_type);
+ tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
- val = LLVMBuildTrunc(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildTrunc(builder, val, lp_build_elem_type(gallivm, dst_type), "");
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}
}
@@ -510,7 +516,7 @@ lp_build_resize(LLVMBuilderRef builder,
/*
* Register width remains constant -- use vector unpack intrinsics
*/
- lp_build_unpack(builder, src_type, dst_type, src[0], tmp, num_dsts);
+ lp_build_unpack(gallivm, src_type, dst_type, src[0], tmp, num_dsts);
}
else {
/*
@@ -518,15 +524,15 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
- tmp[0] = lp_build_undef(dst_type);
+ tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
if (src_type.sign && dst_type.sign) {
- val = LLVMBuildSExt(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildSExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
} else {
- val = LLVMBuildZExt(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildZExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
}
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.h b/src/gallium/auxiliary/gallivm/lp_bld_pack.h
index e947b90d164..d58da4f01b3 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_pack.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.h
@@ -46,7 +46,7 @@ struct lp_type;
LLVMValueRef
-lp_build_interleave2(LLVMBuilderRef builder,
+lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@@ -54,7 +54,7 @@ lp_build_interleave2(LLVMBuilderRef builder,
void
-lp_build_unpack2(LLVMBuilderRef builder,
+lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -63,7 +63,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
void
-lp_build_unpack(LLVMBuilderRef builder,
+lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -71,7 +71,7 @@ lp_build_unpack(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_packs2(LLVMBuilderRef builder,
+lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -79,7 +79,7 @@ lp_build_packs2(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_pack2(LLVMBuilderRef builder,
+lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -87,7 +87,7 @@ lp_build_pack2(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_pack(LLVMBuilderRef builder,
+lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
@@ -95,7 +95,7 @@ lp_build_pack(LLVMBuilderRef builder,
void
-lp_build_resize(LLVMBuilderRef builder,
+lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
index f418e96aff4..60cc6094f5a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
@@ -31,6 +31,8 @@
#include "util/u_memory.h"
#include "util/u_string.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
+#include "lp_bld_const.h"
#include "lp_bld_printf.h"
@@ -65,12 +67,14 @@ lp_get_printf_arg_count(const char *fmt)
}
LLVMValueRef
-lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
+lp_build_const_string_variable(LLVMModuleRef module,
+ LLVMContextRef context,
+ const char *str, int len)
{
- LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), "");
+ LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8TypeInContext(context), len + 1), "");
LLVMSetGlobalConstant(string, TRUE);
LLVMSetLinkage(string, LLVMInternalLinkage);
- LLVMSetInitializer(string, LLVMConstString(str, len + 1, TRUE));
+ LLVMSetInitializer(string, LLVMConstStringInContext(context, str, len + 1, TRUE));
return string;
}
@@ -83,15 +87,18 @@ lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
* LLVMValueRef.
*/
LLVMValueRef
-lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
+lp_build_printf(struct gallivm_state *gallivm, const char *fmt, ...)
{
va_list arglist;
int i = 0;
int argcount = lp_get_printf_arg_count(fmt);
- LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMContextRef context = gallivm->context;
+ LLVMModuleRef module = gallivm->module;
LLVMValueRef params[50];
- LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1);
- LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ LLVMValueRef fmtarg = lp_build_const_string_variable(module, context,
+ fmt, strlen(fmt) + 1);
+ LLVMValueRef int0 = lp_build_const_int32(gallivm, 0);
LLVMValueRef index[2];
LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf");
@@ -100,7 +107,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
index[0] = index[1] = int0;
if (!func_printf) {
- LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntType(32), NULL, 0, 1);
+ LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntTypeInContext(context, 32), NULL, 0, 1);
func_printf = LLVMAddFunction(module, "printf", printf_type);
}
@@ -113,7 +120,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
/* printf wants doubles, so lets convert so that
* we can actually print them */
if (LLVMGetTypeKind(type) == LLVMFloatTypeKind)
- val = LLVMBuildFPExt(builder, val, LLVMDoubleType(), "");
+ val = LLVMBuildFPExt(builder, val, LLVMDoubleTypeInContext(context), "");
params[i] = val;
}
va_end(arglist);
@@ -127,16 +134,18 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
* Print a float[4] vector.
*/
LLVMValueRef
-lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec)
+lp_build_print_vec4(struct gallivm_state *gallivm,
+ const char *msg, LLVMValueRef vec)
{
+ LLVMBuilderRef builder = gallivm->builder;
char format[1000];
LLVMValueRef x, y, z, w;
- x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(0), "");
- y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(1), "");
- z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(2), "");
- w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(3), "");
+ x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 0), "");
+ y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 1), "");
+ z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 2), "");
+ w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 3), "");
util_snprintf(format, sizeof(format), "%s %%f %%f %%f %%f\n", msg);
- return lp_build_printf(builder, format, x, y, z, w);
+ return lp_build_printf(gallivm, format, x, y, z, w);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
index b6222c62ebe..f6bb8348699 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
@@ -31,12 +31,19 @@
#include "pipe/p_compiler.h"
#include "lp_bld.h"
+#include "lp_bld_init.h"
-LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len);
-LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...);
+
+LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module,
+ LLVMContextRef context,
+ const char *str, int len);
+
+LLVMValueRef lp_build_printf(struct gallivm_state *gallivm,
+ const char *fmt, ...);
LLVMValueRef
-lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec);
+lp_build_print_vec4(struct gallivm_state *gallivm,
+ const char *msg, LLVMValueRef vec);
#endif
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_quad.c b/src/gallium/auxiliary/gallivm/lp_bld_quad.c
index c18c8b47100..b0a5bc0267f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_quad.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_quad.c
@@ -28,6 +28,7 @@
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
+#include "lp_bld_const.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_quad.h"
@@ -81,15 +82,15 @@ LLVMValueRef
lp_build_scalar_ddx(struct lp_build_context *bld,
LLVMValueRef a)
{
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef idx_left = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
- LLVMValueRef idx_right = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_RIGHT, 0);
- LLVMValueRef a_left = LLVMBuildExtractElement(bld->builder, a, idx_left, "left");
- LLVMValueRef a_right = LLVMBuildExtractElement(bld->builder, a, idx_right, "right");
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef idx_left = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
+ LLVMValueRef idx_right = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_RIGHT);
+ LLVMValueRef a_left = LLVMBuildExtractElement(builder, a, idx_left, "left");
+ LLVMValueRef a_right = LLVMBuildExtractElement(builder, a, idx_right, "right");
if (bld->type.floating)
- return LLVMBuildFSub(bld->builder, a_right, a_left, "ddx");
+ return LLVMBuildFSub(builder, a_right, a_left, "ddx");
else
- return LLVMBuildSub(bld->builder, a_right, a_left, "ddx");
+ return LLVMBuildSub(builder, a_right, a_left, "ddx");
}
@@ -97,13 +98,13 @@ LLVMValueRef
lp_build_scalar_ddy(struct lp_build_context *bld,
LLVMValueRef a)
{
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef idx_top = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
- LLVMValueRef idx_bottom = LLVMConstInt(i32t, LP_BLD_QUAD_BOTTOM_LEFT, 0);
- LLVMValueRef a_top = LLVMBuildExtractElement(bld->builder, a, idx_top, "top");
- LLVMValueRef a_bottom = LLVMBuildExtractElement(bld->builder, a, idx_bottom, "bottom");
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef idx_top = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
+ LLVMValueRef idx_bottom = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_BOTTOM_LEFT);
+ LLVMValueRef a_top = LLVMBuildExtractElement(builder, a, idx_top, "top");
+ LLVMValueRef a_bottom = LLVMBuildExtractElement(builder, a, idx_bottom, "bottom");
if (bld->type.floating)
- return LLVMBuildFSub(bld->builder, a_bottom, a_top, "ddy");
+ return LLVMBuildFSub(builder, a_bottom, a_top, "ddy");
else
- return LLVMBuildSub(bld->builder, a_bottom, a_top, "ddy");
+ return LLVMBuildSub(builder, a_bottom, a_top, "ddy");
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index 844d1d935b5..8ad34598a92 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -134,7 +134,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
state->min_img_filter = sampler->min_img_filter;
state->mag_img_filter = sampler->mag_img_filter;
- if (view->last_level && sampler->max_lod > 0.0f) {
+ if (view->u.tex.last_level && sampler->max_lod > 0.0f) {
state->min_mip_filter = sampler->min_mip_filter;
} else {
state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
@@ -155,7 +155,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
state->apply_min_lod = 1;
}
- if (sampler->max_lod < (float)view->last_level) {
+ if (sampler->max_lod < (float)view->u.tex.last_level) {
state->apply_max_lod = 1;
}
}
@@ -190,7 +190,8 @@ lp_build_rho(struct lp_build_sample_context *bld,
struct lp_build_context *float_size_bld = &bld->float_size_bld;
struct lp_build_context *float_bld = &bld->float_bld;
const unsigned dims = bld->dims;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
LLVMValueRef index1 = LLVMConstInt(i32t, 1, 0);
LLVMValueRef index2 = LLVMConstInt(i32t, 2, 0);
@@ -211,21 +212,21 @@ lp_build_rho(struct lp_build_sample_context *bld,
rho_x = float_size_bld->undef;
rho_y = float_size_bld->undef;
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dsdx, index0, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dsdy, index0, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, dsdx, index0, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, dsdy, index0, "");
dtdx = ddx[1];
dtdy = ddy[1];
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dtdx, index1, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dtdy, index1, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, dtdx, index1, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, dtdy, index1, "");
if (dims >= 3) {
drdx = ddx[2];
drdy = ddy[2];
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, drdx, index2, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, drdy, index2, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, drdx, index2, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, drdy, index2, "");
}
}
@@ -245,13 +246,13 @@ lp_build_rho(struct lp_build_sample_context *bld,
if (dims >= 2) {
LLVMValueRef rho_s, rho_t, rho_r;
- rho_s = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
- rho_t = LLVMBuildExtractElement(bld->builder, rho_vec, index1, "");
+ rho_s = LLVMBuildExtractElement(builder, rho_vec, index0, "");
+ rho_t = LLVMBuildExtractElement(builder, rho_vec, index1, "");
rho = lp_build_max(float_bld, rho_s, rho_t);
if (dims >= 3) {
- rho_r = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
+ rho_r = LLVMBuildExtractElement(builder, rho_vec, index0, "");
rho = lp_build_max(float_bld, rho, rho_r);
}
}
@@ -304,19 +305,19 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
double post_offset = 1 - factor;
if (0) {
- lp_build_printf(bld->builder, "lod = %f\n", lod);
+ lp_build_printf(bld->gallivm, "lod = %f\n", lod);
}
lod = lp_build_add(bld, lod,
- lp_build_const_vec(bld->type, pre_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, pre_offset));
lp_build_ifloor_fract(bld, lod, out_lod_ipart, &lod_fpart);
lod_fpart = lp_build_mul(bld, lod_fpart,
- lp_build_const_vec(bld->type, factor));
+ lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
- lp_build_const_vec(bld->type, post_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* It's not necessary to clamp lod_fpart since:
@@ -327,8 +328,8 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
*out_lod_fpart = lod_fpart;
if (0) {
- lp_build_printf(bld->builder, "lod_ipart = %i\n", *out_lod_ipart);
- lp_build_printf(bld->builder, "lod_fpart = %f\n\n", *out_lod_fpart);
+ lp_build_printf(bld->gallivm, "lod_ipart = %i\n", *out_lod_ipart);
+ lp_build_printf(bld->gallivm, "lod_fpart = %f\n\n", *out_lod_fpart);
}
}
@@ -363,7 +364,7 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
* part will not need any post adjustments.
*/
rho = lp_build_mul(bld, rho,
- lp_build_const_vec(bld->type, pre_factor));
+ lp_build_const_vec(bld->gallivm, bld->type, pre_factor));
/* ipart = ifloor(log2(rho)) */
lod_ipart = lp_build_extract_exponent(bld, rho, 0);
@@ -372,10 +373,10 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
lod_fpart = lp_build_extract_mantissa(bld, rho);
lod_fpart = lp_build_mul(bld, lod_fpart,
- lp_build_const_vec(bld->type, factor));
+ lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
- lp_build_const_vec(bld->type, post_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* Like lp_build_brilinear_lod, it's not necessary to clamp lod_fpart since:
@@ -413,6 +414,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
LLVMValueRef *out_lod_fpart)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef lod;
@@ -424,17 +426,17 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
* This is hit during mipmap generation.
*/
LLVMValueRef min_lod =
- bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = min_lod;
}
else {
LLVMValueRef sampler_lod_bias =
- bld->dynamic_state->lod_bias(bld->dynamic_state, bld->builder, unit);
- LLVMValueRef index0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ bld->dynamic_state->lod_bias(bld->dynamic_state, bld->gallivm, unit);
+ LLVMValueRef index0 = lp_build_const_int32(bld->gallivm, 0);
if (explicit_lod) {
- lod = LLVMBuildExtractElement(bld->builder, explicit_lod,
+ lod = LLVMBuildExtractElement(builder, explicit_lod,
index0, "");
}
else {
@@ -479,27 +481,27 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
/* add shader lod bias */
if (lod_bias) {
- lod_bias = LLVMBuildExtractElement(bld->builder, lod_bias,
+ lod_bias = LLVMBuildExtractElement(builder, lod_bias,
index0, "");
- lod = LLVMBuildFAdd(bld->builder, lod, lod_bias, "shader_lod_bias");
+ lod = LLVMBuildFAdd(builder, lod, lod_bias, "shader_lod_bias");
}
}
/* add sampler lod bias */
if (bld->static_state->lod_bias_non_zero)
- lod = LLVMBuildFAdd(bld->builder, lod, sampler_lod_bias, "sampler_lod_bias");
+ lod = LLVMBuildFAdd(builder, lod, sampler_lod_bias, "sampler_lod_bias");
/* clamp lod */
if (bld->static_state->apply_max_lod) {
LLVMValueRef max_lod =
- bld->dynamic_state->max_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->max_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_min(float_bld, lod, max_lod);
}
if (bld->static_state->apply_min_lod) {
LLVMValueRef min_lod =
- bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_max(float_bld, lod, min_lod);
}
@@ -542,10 +544,10 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
struct lp_build_context *int_bld = &bld->int_bld;
LLVMValueRef last_level, level;
- LLVMValueRef zero = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
/* convert float lod to integer */
level = lod_ipart;
@@ -568,7 +570,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
LLVMValueRef *level0_out,
LLVMValueRef *level1_out)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *int_bld = &bld->int_bld;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef last_level;
@@ -579,7 +581,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
*level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
/*
* Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the
@@ -630,11 +632,13 @@ LLVMValueRef
lp_build_get_mipmap_level(struct lp_build_sample_context *bld,
LLVMValueRef level)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], data_ptr;
- indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+
+ indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
- data_ptr = LLVMBuildGEP(bld->builder, bld->data_array, indexes, 2, "");
- data_ptr = LLVMBuildLoad(bld->builder, data_ptr, "");
+ data_ptr = LLVMBuildGEP(builder, bld->data_array, indexes, 2, "");
+ data_ptr = LLVMBuildLoad(builder, data_ptr, "");
return data_ptr;
}
@@ -643,7 +647,7 @@ LLVMValueRef
lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld,
int level)
{
- LLVMValueRef lvl = LLVMConstInt(LLVMInt32Type(), level, 0);
+ LLVMValueRef lvl = lp_build_const_int32(bld->gallivm, level);
return lp_build_get_mipmap_level(bld, lvl);
}
@@ -657,6 +661,7 @@ lp_build_minify(struct lp_build_context *bld,
LLVMValueRef base_size,
LLVMValueRef level)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
assert(lp_check_value(bld->type, base_size));
assert(lp_check_value(bld->type, level));
@@ -666,7 +671,7 @@ lp_build_minify(struct lp_build_context *bld,
}
else {
LLVMValueRef size =
- LLVMBuildLShr(bld->builder, base_size, level, "minify");
+ LLVMBuildLShr(builder, base_size, level, "minify");
assert(bld->type.sign);
size = lp_build_max(bld, size, bld->one);
return size;
@@ -682,11 +687,12 @@ static LLVMValueRef
lp_build_get_level_stride_vec(struct lp_build_sample_context *bld,
LLVMValueRef stride_array, LLVMValueRef level)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], stride;
- indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
- stride = LLVMBuildGEP(bld->builder, stride_array, indexes, 2, "");
- stride = LLVMBuildLoad(bld->builder, stride, "");
+ stride = LLVMBuildGEP(builder, stride_array, indexes, 2, "");
+ stride = LLVMBuildLoad(builder, stride, "");
stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride);
return stride;
}
@@ -747,21 +753,21 @@ lp_build_extract_image_sizes(struct lp_build_sample_context *bld,
LLVMValueRef *out_depth)
{
const unsigned dims = bld->dims;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
- *out_width = lp_build_extract_broadcast(bld->builder,
+ *out_width = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 0, 0));
if (dims >= 2) {
- *out_height = lp_build_extract_broadcast(bld->builder,
+ *out_height = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 1, 0));
if (dims == 3) {
- *out_depth = lp_build_extract_broadcast(bld->builder,
+ *out_depth = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
@@ -812,7 +818,7 @@ static LLVMValueRef
lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord)
{
/* ima = -0.5 / abs(coord); */
- LLVMValueRef negHalf = lp_build_const_vec(coord_bld->type, -0.5);
+ LLVMValueRef negHalf = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, -0.5);
LLVMValueRef absCoord = lp_build_abs(coord_bld, coord);
LLVMValueRef ima = lp_build_div(coord_bld, negHalf, absCoord);
return ima;
@@ -831,7 +837,7 @@ lp_build_cube_coord(struct lp_build_context *coord_bld,
LLVMValueRef coord, LLVMValueRef ima)
{
/* return negate(coord) * ima * sign + 0.5; */
- LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
+ LLVMValueRef half = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef res;
assert(negate_coord == +1 || negate_coord == -1);
@@ -859,12 +865,14 @@ lp_build_cube_face(struct lp_build_sample_context *bld,
LLVMValueRef major_coord,
unsigned pos_face, unsigned neg_face)
{
- LLVMValueRef cmp = LLVMBuildFCmp(bld->builder, LLVMRealUGE,
+ struct gallivm_state *gallivm = bld->gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef cmp = LLVMBuildFCmp(builder, LLVMRealUGE,
major_coord,
bld->float_bld.zero, "");
- LLVMValueRef pos = LLVMConstInt(LLVMInt32Type(), pos_face, 0);
- LLVMValueRef neg = LLVMConstInt(LLVMInt32Type(), neg_face, 0);
- LLVMValueRef res = LLVMBuildSelect(bld->builder, cmp, pos, neg, "");
+ LLVMValueRef pos = lp_build_const_int32(gallivm, pos_face);
+ LLVMValueRef neg = lp_build_const_int32(gallivm, neg_face);
+ LLVMValueRef res = LLVMBuildSelect(builder, cmp, pos, neg, "");
return res;
}
@@ -884,9 +892,10 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
{
struct lp_build_context *float_bld = &bld->float_bld;
struct lp_build_context *coord_bld = &bld->coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef rx, ry, rz;
LLVMValueRef arx, ary, arz;
- LLVMValueRef c25 = LLVMConstReal(LLVMFloatType(), 0.25);
+ LLVMValueRef c25 = lp_build_const_float(bld->gallivm, 0.25);
LLVMValueRef arx_ge_ary, arx_ge_arz;
LLVMValueRef ary_ge_arx, ary_ge_arz;
LLVMValueRef arx_ge_ary_arz, ary_ge_arx_arz;
@@ -911,17 +920,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
/*
* Compare sign/magnitude of rx,ry,rz to determine face
*/
- arx_ge_ary = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, ary, "");
- arx_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, arz, "");
- ary_ge_arx = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arx, "");
- ary_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arz, "");
+ arx_ge_ary = LLVMBuildFCmp(builder, LLVMRealUGE, arx, ary, "");
+ arx_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, arx, arz, "");
+ ary_ge_arx = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arx, "");
+ ary_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arz, "");
- arx_ge_ary_arz = LLVMBuildAnd(bld->builder, arx_ge_ary, arx_ge_arz, "");
- ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
+ arx_ge_ary_arz = LLVMBuildAnd(builder, arx_ge_ary, arx_ge_arz, "");
+ ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
- rx_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rx, float_bld->zero, "");
- ry_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ry, float_bld->zero, "");
- rz_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rz, float_bld->zero, "");
+ rx_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rx, float_bld->zero, "");
+ ry_pos = LLVMBuildFCmp(builder, LLVMRealUGE, ry, float_bld->zero, "");
+ rz_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rz, float_bld->zero, "");
{
struct lp_build_if_state if_ctx;
@@ -929,11 +938,11 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
LLVMValueRef face_t_var;
LLVMValueRef face_var;
- face_s_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_s_var");
- face_t_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_t_var");
- face_var = lp_build_alloca(bld->builder, bld->int_bld.vec_type, "face_var");
+ face_s_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_s_var");
+ face_t_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_t_var");
+ face_var = lp_build_alloca(bld->gallivm, bld->int_bld.vec_type, "face_var");
- lp_build_if(&if_ctx, bld->builder, arx_ge_ary_arz);
+ lp_build_if(&if_ctx, bld->gallivm, arx_ge_ary_arz);
{
/* +/- X face */
LLVMValueRef sign = lp_build_sgn(float_bld, rx);
@@ -943,17 +952,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rx,
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx);
{
struct lp_build_if_state if_ctx2;
- ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
+ ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
- lp_build_if(&if_ctx2, bld->builder, ary_ge_arx_arz);
+ lp_build_if(&if_ctx2, bld->gallivm, ary_ge_arx_arz);
{
/* +/- Y face */
LLVMValueRef sign = lp_build_sgn(float_bld, ry);
@@ -963,9 +972,9 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, ry,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx2);
{
@@ -977,18 +986,18 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rz,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_endif(&if_ctx2);
}
lp_build_endif(&if_ctx);
- *face_s = LLVMBuildLoad(bld->builder, face_s_var, "face_s");
- *face_t = LLVMBuildLoad(bld->builder, face_t_var, "face_t");
- *face = LLVMBuildLoad(bld->builder, face_var, "face");
+ *face_s = LLVMBuildLoad(builder, face_s_var, "face_s");
+ *face_t = LLVMBuildLoad(builder, face_t_var, "face_t");
+ *face = LLVMBuildLoad(builder, face_var, "face");
}
}
@@ -1011,6 +1020,7 @@ lp_build_sample_partial_offset(struct lp_build_context *bld,
LLVMValueRef *out_offset,
LLVMValueRef *out_subcoord)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef offset;
LLVMValueRef subcoord;
@@ -1028,14 +1038,14 @@ lp_build_sample_partial_offset(struct lp_build_context *bld,
*/
#if 0
LLVMValueRef block_width = lp_build_const_int_vec(bld->type, block_length);
- subcoord = LLVMBuildURem(bld->builder, coord, block_width, "");
- coord = LLVMBuildUDiv(bld->builder, coord, block_width, "");
+ subcoord = LLVMBuildURem(builder, coord, block_width, "");
+ coord = LLVMBuildUDiv(builder, coord, block_width, "");
#else
unsigned logbase2 = util_unsigned_logbase2(block_length);
- LLVMValueRef block_shift = lp_build_const_int_vec(bld->type, logbase2);
- LLVMValueRef block_mask = lp_build_const_int_vec(bld->type, block_length - 1);
- subcoord = LLVMBuildAnd(bld->builder, coord, block_mask, "");
- coord = LLVMBuildLShr(bld->builder, coord, block_shift, "");
+ LLVMValueRef block_shift = lp_build_const_int_vec(bld->gallivm, bld->type, logbase2);
+ LLVMValueRef block_mask = lp_build_const_int_vec(bld->gallivm, bld->type, block_length - 1);
+ subcoord = LLVMBuildAnd(builder, coord, block_mask, "");
+ coord = LLVMBuildLShr(builder, coord, block_shift, "");
#endif
}
@@ -1071,7 +1081,8 @@ lp_build_sample_offset(struct lp_build_context *bld,
LLVMValueRef x_stride;
LLVMValueRef offset;
- x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8);
+ x_stride = lp_build_const_vec(bld->gallivm, bld->type,
+ format_desc->block.bits/8);
lp_build_sample_partial_offset(bld,
format_desc->block.width,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index ffed27cee83..8c9d5df4e43 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -105,64 +105,64 @@ struct lp_sampler_dynamic_state
/** Obtain the base texture width (returns int32) */
LLVMValueRef
(*width)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture height (returns int32) */
LLVMValueRef
(*height)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture depth (returns int32) */
LLVMValueRef
(*depth)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the number of mipmap levels minus one (returns int32) */
LLVMValueRef
(*last_level)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image rows/blocks (returns int32) */
LLVMValueRef
(*row_stride)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image slices (returns int32) */
LLVMValueRef
(*img_stride)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain pointer to array of pointers to mimpap levels */
LLVMValueRef
(*data_ptr)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain texture min lod (returns float) */
LLVMValueRef
(*min_lod)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture max lod (returns float) */
LLVMValueRef
(*max_lod)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture lod bias (returns float) */
LLVMValueRef
(*lod_bias)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture border color (returns ptr to float[4]) */
LLVMValueRef
(*border_color)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
};
@@ -171,7 +171,7 @@ struct lp_sampler_dynamic_state
*/
struct lp_build_sample_context
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
const struct lp_sampler_static_state *static_state;
@@ -385,7 +385,7 @@ lp_build_sample_offset(struct lp_build_context *bld,
void
-lp_build_sample_soa(LLVMBuilderRef builder,
+lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type fp_type,
@@ -399,7 +399,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
LLVMValueRef texel_out[4]);
void
-lp_build_sample_nop(struct lp_type type,
+lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4]);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
index d6831a580b3..e61cf9541ea 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
@@ -52,6 +52,7 @@
#include "lp_bld_flow.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
+#include "lp_bld_init.h"
#include "lp_bld_sample.h"
#include "lp_bld_sample_aos.h"
#include "lp_bld_quad.h"
@@ -82,6 +83,7 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
LLVMValueRef *out_i)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
@@ -89,12 +91,12 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if(is_pot)
- coord = LLVMBuildAnd(bld->builder, coord, length_minus_one, "");
+ coord = LLVMBuildAnd(builder, coord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- coord = LLVMBuildAdd(bld->builder, coord, bias, "");
- coord = LLVMBuildURem(bld->builder, coord, length, "");
+ coord = LLVMBuildAdd(builder, coord, bias, "");
+ coord = LLVMBuildURem(builder, coord, length, "");
}
break;
@@ -147,6 +149,7 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
LLVMValueRef *i1)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
LLVMValueRef lmask, umask, mask;
@@ -195,39 +198,39 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if (is_pot) {
- coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
+ coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
- coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
+ coord0 = LLVMBuildAdd(builder, coord0, bias, "");
+ coord0 = LLVMBuildURem(builder, coord0, length, "");
}
- mask = lp_build_compare(bld->builder, int_coord_bld->type,
+ mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
- *offset1 = LLVMBuildAnd(bld->builder,
+ *offset1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, *offset0, stride),
mask, "");
break;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- lmask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
+ lmask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_GEQUAL, coord0, int_coord_bld->zero);
- umask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
+ umask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_LESS, coord0, length_minus_one);
coord0 = lp_build_select(int_coord_bld, lmask, coord0, int_coord_bld->zero);
coord0 = lp_build_select(int_coord_bld, umask, coord0, length_minus_one);
- mask = LLVMBuildAnd(bld->builder, lmask, umask, "");
+ mask = LLVMBuildAnd(builder, lmask, umask, "");
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
*offset1 = lp_build_add(int_coord_bld,
*offset0,
- LLVMBuildAnd(bld->builder, stride, mask, ""));
+ LLVMBuildAnd(builder, stride, mask, ""));
break;
case PIPE_TEX_WRAP_CLAMP:
@@ -263,7 +266,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8;
@@ -273,13 +276,13 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef x_offset, offset;
LLVMValueRef x_subcoord, y_subcoord, z_subcoord;
- lp_build_context_init(&i32, builder, lp_type_int_vec(32));
- lp_build_context_init(&h16, builder, lp_type_ufixed(16));
- lp_build_context_init(&u8n, builder, lp_type_unorm(8));
+ lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
+ lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
+ lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
- i32_vec_type = lp_build_vec_type(i32.type);
- h16_vec_type = lp_build_vec_type(h16.type);
- u8n_vec_type = lp_build_vec_type(u8n.type);
+ i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
+ h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
+ u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@@ -317,7 +320,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* compute floor (shift right 8) */
- i32_c8 = lp_build_const_int_vec(i32.type, 8);
+ i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@@ -325,7 +328,8 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* get pixel, row, image strides */
- x_stride = lp_build_const_vec(bld->int_coord_bld.type,
+ x_stride = lp_build_const_vec(bld->gallivm,
+ bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
/* Do texcoord wrapping, compute texel offset */
@@ -387,7 +391,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
- rgba8 = lp_build_gather(bld->builder,
+ rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@@ -396,7 +400,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
- rgba8 = lp_build_fetch_rgba_aos(bld->builder,
+ rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset,
@@ -405,7 +409,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
- lp_build_unpack2(builder, u8n.type, h16.type,
+ lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
colors_lo, colors_hi);
}
@@ -429,7 +433,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8, i32_c128, i32_c255;
@@ -450,13 +454,13 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
unsigned i, j, k;
unsigned numj, numk;
- lp_build_context_init(&i32, builder, lp_type_int_vec(32));
- lp_build_context_init(&h16, builder, lp_type_ufixed(16));
- lp_build_context_init(&u8n, builder, lp_type_unorm(8));
+ lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
+ lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
+ lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
- i32_vec_type = lp_build_vec_type(i32.type);
- h16_vec_type = lp_build_vec_type(h16.type);
- u8n_vec_type = lp_build_vec_type(u8n.type);
+ i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
+ h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
+ u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@@ -494,7 +498,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* subtract 0.5 (add -128) */
- i32_c128 = lp_build_const_int_vec(i32.type, -128);
+ i32_c128 = lp_build_const_int_vec(bld->gallivm, i32.type, -128);
s = LLVMBuildAdd(builder, s, i32_c128, "");
if (dims >= 2) {
t = LLVMBuildAdd(builder, t, i32_c128, "");
@@ -504,7 +508,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* compute floor (shift right 8) */
- i32_c8 = lp_build_const_int_vec(i32.type, 8);
+ i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@@ -512,7 +516,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* compute fractional part (AND with 0xff) */
- i32_c255 = lp_build_const_int_vec(i32.type, 255);
+ i32_c255 = lp_build_const_int_vec(bld->gallivm, i32.type, 255);
s_fpart = LLVMBuildAnd(builder, s, i32_c255, "");
if (dims >= 2)
t_fpart = LLVMBuildAnd(builder, t, i32_c255, "");
@@ -520,7 +524,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildAnd(builder, r, i32_c255, "");
/* get pixel, row and image strides */
- x_stride = lp_build_const_vec(bld->int_coord_bld.type,
+ x_stride = lp_build_const_vec(bld->gallivm, bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
y_stride = row_stride_vec;
z_stride = img_stride_vec;
@@ -612,7 +616,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildBitCast(builder, r_fpart, h16_vec_type, "");
{
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles_lo[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffles_hi[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffle_lo;
@@ -685,7 +689,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
- rgba8 = lp_build_gather(bld->builder,
+ rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@@ -694,7 +698,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
- rgba8 = lp_build_fetch_rgba_aos(bld->builder,
+ rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset[k][j][i],
@@ -703,7 +707,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
- lp_build_unpack2(builder, u8n.type, h16.type,
+ lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
&neighbors_lo[k][j][i], &neighbors_hi[k][j][i]);
}
@@ -790,7 +794,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors_lo_var,
LLVMValueRef colors_hi_var)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@@ -802,7 +806,6 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors0_lo, colors0_hi;
LLVMValueRef colors1_lo, colors1_hi;
-
/* sample the first mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel0,
&size0,
@@ -829,8 +832,8 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMBuildStore(builder, colors0_hi, colors_hi_var);
if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
- LLVMValueRef h16_scale = LLVMConstReal(LLVMFloatType(), 256.0);
- LLVMTypeRef i32_type = LLVMIntType(32);
+ LLVMValueRef h16_scale = lp_build_const_float(bld->gallivm, 256.0);
+ LLVMTypeRef i32_type = LLVMIntTypeInContext(bld->gallivm->context, 32);
struct lp_build_if_state if_ctx;
LLVMValueRef need_lerp;
@@ -842,11 +845,11 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
lod_fpart, LLVMConstNull(i32_type),
"need_lerp");
- lp_build_if(&if_ctx, builder, need_lerp);
+ lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
struct lp_build_context h16_bld;
- lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
+ lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@@ -885,7 +888,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
int i;
assert(h16_bld.type.length <= Elements(shuffles));
for (i = 0; i < h16_bld.type.length; i++)
- shuffles[i] = lp_build_const_int32(2 * (i & 1));
+ shuffles[i] = lp_build_const_int32(bld->gallivm, 2 * (i & 1));
shuffle = LLVMConstVector(shuffles, h16_bld.type.length);
lod_fpart = LLVMBuildShuffleVector(builder,
lod_fpart, lod_fpart,
@@ -925,7 +928,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef texel_out[4])
{
struct lp_build_context *int_bld = &bld->int_bld;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@@ -936,8 +939,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef unswizzled[4];
LLVMValueRef face_ddx[4], face_ddy[4];
struct lp_build_context h16_bld;
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
/* we only support the common/simple wrap modes at this time */
assert(lp_is_simple_wrap_mode(bld->static_state->wrap_s));
@@ -948,7 +950,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/* make 16-bit fixed-pt builder context */
- lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
+ lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* cube face selection, compute pre-face coords, etc. */
if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
@@ -1026,8 +1028,8 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* Get/interpolate texture colors.
*/
- packed_lo = lp_build_alloca(builder, h16_bld.vec_type, "packed_lo");
- packed_hi = lp_build_alloca(builder, h16_bld.vec_type, "packed_hi");
+ packed_lo = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_lo");
+ packed_hi = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_hi");
if (min_filter == mag_filter) {
/* no need to distinquish between minification and magnification */
@@ -1048,7 +1050,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
- lp_build_if(&if_ctx, builder, minify);
+ lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld,
@@ -1073,7 +1075,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* combine the values stored in 'packed_lo' and 'packed_hi' variables
* into 'packed'
*/
- packed = lp_build_pack2(builder,
+ packed = lp_build_pack2(bld->gallivm,
h16_bld.type, lp_type_unorm(8),
LLVMBuildLoad(builder, packed_lo, ""),
LLVMBuildLoad(builder, packed_hi, ""));
@@ -1081,7 +1083,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/*
* Convert to SoA and swizzle.
*/
- lp_build_rgba8_to_f32_soa(builder,
+ lp_build_rgba8_to_f32_soa(bld->gallivm,
bld->texel_type,
packed, unswizzled);
@@ -1096,6 +1098,4 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
texel_out[2] = unswizzled[2];
texel_out[3] = unswizzled[3];
}
-
- apply_sampler_swizzle(bld, texel_out);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 53cc0c5f345..e685f4b73f0 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -84,6 +84,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
const struct lp_sampler_static_state *static_state = bld->static_state;
const unsigned dims = bld->dims;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef offset;
LLVMValueRef i, j;
LLVMValueRef use_border = NULL;
@@ -95,7 +96,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
LLVMValueRef b1, b2;
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width);
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
if (dims >= 2 &&
@@ -106,11 +107,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height);
if (use_border) {
- use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
- use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
+ use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
+ use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@@ -122,11 +123,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, z, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, z, depth);
if (use_border) {
- use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
- use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
+ use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
+ use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@@ -148,7 +149,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
offset = lp_build_andnot(&bld->int_coord_bld, offset, use_border);
}
- lp_build_fetch_rgba_soa(bld->builder,
+ lp_build_fetch_rgba_soa(bld->gallivm,
bld->format_desc,
bld->texel_type,
data_ptr, offset,
@@ -174,20 +175,18 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
/* select texel color or border color depending on use_border */
LLVMValueRef border_color_ptr =
bld->dynamic_state->border_color(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
int chan;
for (chan = 0; chan < 4; chan++) {
LLVMValueRef border_chan =
- lp_build_array_get(bld->builder, border_color_ptr,
- lp_build_const_int32(chan));
+ lp_build_array_get(bld->gallivm, border_color_ptr,
+ lp_build_const_int32(bld->gallivm, chan));
LLVMValueRef border_chan_vec =
lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan);
texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
border_chan_vec, texel_out[chan]);
}
}
-
- apply_sampler_swizzle(bld, texel_out);
}
@@ -205,7 +204,7 @@ lp_build_coord_mirror(struct lp_build_sample_context *bld,
lp_build_ifloor_fract(coord_bld, coord, &flr, &fract);
/* isOdd = flr & 1 */
- isOdd = LLVMBuildAnd(bld->builder, flr, int_coord_bld->one, "");
+ isOdd = LLVMBuildAnd(bld->gallivm->builder, flr, int_coord_bld->one, "");
/* make coord positive or negative depending on isOdd */
coord = lp_build_set_sign(coord_bld, fract, isOdd);
@@ -239,7 +238,8 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
- LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef half = lp_build_const_vec(bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef coord0, coord1, weight;
@@ -253,18 +253,18 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
/* repeat wrap */
if (is_pot) {
coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
- coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
- coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, "");
+ coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
+ coord1 = LLVMBuildAnd(builder, coord1, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
LLVMValueRef mask;
- coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
- coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
- mask = lp_build_compare(bld->builder, int_coord_bld->type,
+ coord0 = LLVMBuildAdd(builder, coord0, bias, "");
+ coord0 = LLVMBuildURem(builder, coord0, length, "");
+ mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
- coord1 = LLVMBuildAnd(bld->builder,
+ coord1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, coord0, int_coord_bld->one),
mask, "");
}
@@ -318,7 +318,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
}
/* was: clamp to [-0.5, length + 0.5], then sub 0.5 */
coord = lp_build_sub(coord_bld, coord, half);
- min = lp_build_const_vec(coord_bld->type, -1.0F);
+ min = lp_build_const_vec(bld->gallivm, coord_bld->type, -1.0F);
coord = lp_build_clamp(coord_bld, coord, min, length_f);
/* convert to int, compute lerp weight */
lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
@@ -437,6 +437,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef icoord;
@@ -445,12 +446,12 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
coord = lp_build_mul(coord_bld, coord, length_f);
icoord = lp_build_ifloor(coord_bld, coord);
if (is_pot)
- icoord = LLVMBuildAnd(bld->builder, icoord, length_minus_one, "");
+ icoord = LLVMBuildAnd(builder, icoord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- icoord = LLVMBuildAdd(bld->builder, icoord, bias, "");
- icoord = LLVMBuildURem(bld->builder, icoord, length, "");
+ icoord = LLVMBuildAdd(builder, icoord, bias, "");
+ icoord = LLVMBuildURem(builder, icoord, length, "");
}
break;
@@ -830,7 +831,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef lod_fpart,
LLVMValueRef *colors_out)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@@ -878,7 +879,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
bld->float_bld.zero,
"need_lerp");
- lp_build_if(&if_ctx, builder, need_lerp);
+ lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@@ -934,7 +935,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef *colors_out)
{
struct lp_build_context *int_bld = &bld->int_bld;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@@ -942,8 +943,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef ilevel0, ilevel1 = NULL;
LLVMValueRef face_ddx[4], face_ddy[4];
LLVMValueRef texels[4];
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
unsigned chan;
/*
@@ -1030,7 +1030,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
*/
for (chan = 0; chan < 4; ++chan) {
- texels[chan] = lp_build_alloca(builder, bld->texel_bld.vec_type, "");
+ texels[chan] = lp_build_alloca(bld->gallivm, bld->texel_bld.vec_type, "");
lp_build_name(texels[chan], "sampler%u_texel_%c_var", unit, "xyzw"[chan]);
}
@@ -1053,7 +1053,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
- lp_build_if(&if_ctx, builder, minify);
+ lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld, unit,
@@ -1092,6 +1092,7 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
LLVMValueRef texel[4])
{
struct lp_build_context *texel_bld = &bld->texel_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef res;
const unsigned chan = 0;
@@ -1100,11 +1101,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
/* debug code */
if (0) {
- LLVMValueRef indx = lp_build_const_int32(0);
- LLVMValueRef coord = LLVMBuildExtractElement(bld->builder, p, indx, "");
- LLVMValueRef tex = LLVMBuildExtractElement(bld->builder,
- texel[chan], indx, "");
- lp_build_printf(bld->builder, "shadow compare coord %f to texture %f\n",
+ LLVMValueRef indx = lp_build_const_int32(bld->gallivm, 0);
+ LLVMValueRef coord = LLVMBuildExtractElement(builder, p, indx, "");
+ LLVMValueRef tex = LLVMBuildExtractElement(builder, texel[chan], indx, "");
+ lp_build_printf(bld->gallivm, "shadow compare coord %f to texture %f\n",
coord, tex);
}
@@ -1126,10 +1126,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
* For debugging.
*/
void
-lp_build_sample_nop(struct lp_type type,
+lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4])
{
- LLVMValueRef one = lp_build_one(type);
+ LLVMValueRef one = lp_build_one(gallivm, type);
unsigned chan;
for (chan = 0; chan < 4; chan++) {
@@ -1147,7 +1147,7 @@ lp_build_sample_nop(struct lp_type type,
* \param ddy partial derivatives of (s,t,r,q) with respect to y
*/
void
-lp_build_sample_soa(LLVMBuilderRef builder,
+lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type type,
@@ -1162,8 +1162,8 @@ lp_build_sample_soa(LLVMBuilderRef builder,
{
unsigned dims = texture_dims(static_state->target);
struct lp_build_sample_context bld;
- LLVMTypeRef i32t = LLVMInt32Type();
-
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef s;
LLVMValueRef t;
LLVMValueRef r;
@@ -1178,7 +1178,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
/* Setup our build context */
memset(&bld, 0, sizeof bld);
- bld.builder = builder;
+ bld.gallivm = gallivm;
bld.static_state = static_state;
bld.dynamic_state = dynamic_state;
bld.format_desc = util_format_description(static_state->format);
@@ -1195,22 +1195,22 @@ lp_build_sample_soa(LLVMBuilderRef builder,
float_vec_type = lp_type_float_vec(32);
- lp_build_context_init(&bld.float_bld, builder, bld.float_type);
- lp_build_context_init(&bld.float_vec_bld, builder, float_vec_type);
- lp_build_context_init(&bld.int_bld, builder, bld.int_type);
- lp_build_context_init(&bld.coord_bld, builder, bld.coord_type);
- lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type);
- lp_build_context_init(&bld.int_size_bld, builder, bld.int_size_type);
- lp_build_context_init(&bld.float_size_bld, builder, bld.float_size_type);
- lp_build_context_init(&bld.texel_bld, builder, bld.texel_type);
+ lp_build_context_init(&bld.float_bld, gallivm, bld.float_type);
+ lp_build_context_init(&bld.float_vec_bld, gallivm, float_vec_type);
+ lp_build_context_init(&bld.int_bld, gallivm, bld.int_type);
+ lp_build_context_init(&bld.coord_bld, gallivm, bld.coord_type);
+ lp_build_context_init(&bld.int_coord_bld, gallivm, bld.int_coord_type);
+ lp_build_context_init(&bld.int_size_bld, gallivm, bld.int_size_type);
+ lp_build_context_init(&bld.float_size_bld, gallivm, bld.float_size_type);
+ lp_build_context_init(&bld.texel_bld, gallivm, bld.texel_type);
/* Get the dynamic state */
- bld.width = dynamic_state->width(dynamic_state, builder, unit);
- bld.height = dynamic_state->height(dynamic_state, builder, unit);
- bld.depth = dynamic_state->depth(dynamic_state, builder, unit);
- bld.row_stride_array = dynamic_state->row_stride(dynamic_state, builder, unit);
- bld.img_stride_array = dynamic_state->img_stride(dynamic_state, builder, unit);
- bld.data_array = dynamic_state->data_ptr(dynamic_state, builder, unit);
+ bld.width = dynamic_state->width(dynamic_state, gallivm, unit);
+ bld.height = dynamic_state->height(dynamic_state, gallivm, unit);
+ bld.depth = dynamic_state->depth(dynamic_state, gallivm, unit);
+ bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit);
+ bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit);
+ bld.data_array = dynamic_state->data_ptr(dynamic_state, gallivm, unit);
/* Note that data_array is an array[level] of pointers to texture images */
s = coords[0];
@@ -1236,7 +1236,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
if (0) {
/* For debug: no-op texture sampling */
- lp_build_sample_nop(bld.texel_type, texel_out);
+ lp_build_sample_nop(gallivm, bld.texel_type, texel_out);
}
else if (util_format_fits_8unorm(bld.format_desc) &&
lp_is_simple_wrap_mode(static_state->wrap_s) &&
@@ -1266,4 +1266,6 @@ lp_build_sample_soa(LLVMBuilderRef builder,
}
lp_build_sample_compare(&bld, r, texel_out);
+
+ apply_sampler_swizzle(&bld, texel_out);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index 4693c2de6f9..0dc2f24d10a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -37,12 +37,13 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
+#include "lp_bld_const.h"
#include "lp_bld_debug.h"
#include "lp_bld_struct.h"
LLVMValueRef
-lp_build_struct_get_ptr(LLVMBuilderRef builder,
+lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@@ -51,16 +52,16 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
LLVMValueRef member_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
- indices[1] = LLVMConstInt(LLVMInt32Type(), member, 0);
- member_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
+ indices[0] = lp_build_const_int32(gallivm, 0);
+ indices[1] = lp_build_const_int32(gallivm, member);
+ member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name);
return member_ptr;
}
LLVMValueRef
-lp_build_struct_get(LLVMBuilderRef builder,
+lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@@ -69,15 +70,15 @@ lp_build_struct_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
- member_ptr = lp_build_struct_get_ptr(builder, ptr, member, name);
- res = LLVMBuildLoad(builder, member_ptr, "");
+ member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name);
+ res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
return res;
}
LLVMValueRef
-lp_build_array_get_ptr(LLVMBuilderRef builder,
+lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@@ -85,9 +86,9 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = index;
- element_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
+ element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
#ifdef DEBUG
lp_build_name(element_ptr, "&%s[%s]",
LLVMGetValueName(ptr), LLVMGetValueName(index));
@@ -97,7 +98,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_array_get(LLVMBuilderRef builder,
+lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@@ -105,8 +106,8 @@ lp_build_array_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- element_ptr = lp_build_array_get_ptr(builder, ptr, index);
- res = LLVMBuildLoad(builder, element_ptr, "");
+ element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
+ res = LLVMBuildLoad(gallivm->builder, element_ptr, "");
#ifdef DEBUG
lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
#endif
@@ -115,7 +116,7 @@ lp_build_array_get(LLVMBuilderRef builder,
void
-lp_build_array_set(LLVMBuilderRef builder,
+lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value)
@@ -123,8 +124,8 @@ lp_build_array_set(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- element_ptr = lp_build_array_get_ptr(builder, ptr, index);
- LLVMBuildStore(builder, value, element_ptr);
+ element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
+ LLVMBuildStore(gallivm->builder, value, element_ptr);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
index eb87a8eee9e..11605c685f0 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
@@ -38,7 +38,7 @@
#include "gallivm/lp_bld.h"
-#include <llvm-c/Target.h>
+#include "gallivm/lp_bld_init.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
@@ -57,7 +57,7 @@
* Get value pointer to a structure member.
*/
LLVMValueRef
-lp_build_struct_get_ptr(LLVMBuilderRef builder,
+lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@@ -66,7 +66,7 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
* Get the value of a structure member.
*/
LLVMValueRef
-lp_build_struct_get(LLVMBuilderRef builder,
+lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@@ -75,7 +75,7 @@ lp_build_struct_get(LLVMBuilderRef builder,
* Get value pointer to an array element.
*/
LLVMValueRef
-lp_build_array_get_ptr(LLVMBuilderRef builder,
+lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@@ -83,7 +83,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
* Get the value of an array element.
*/
LLVMValueRef
-lp_build_array_get(LLVMBuilderRef builder,
+lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@@ -91,7 +91,7 @@ lp_build_array_get(LLVMBuilderRef builder,
* Set the value of an array element.
*/
void
-lp_build_array_set(LLVMBuilderRef builder,
+lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
index 4685a90e418..71693603c12 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
@@ -37,12 +37,13 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
LLVMValueRef
-lp_build_broadcast(LLVMBuilderRef builder,
+lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar)
{
@@ -52,8 +53,8 @@ lp_build_broadcast(LLVMBuilderRef builder,
res = LLVMGetUndef(vec_type);
for(i = 0; i < n; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(builder, res, scalar, index, "");
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
+ res = LLVMBuildInsertElement(gallivm->builder, res, scalar, index, "");
}
return res;
@@ -67,6 +68,7 @@ LLVMValueRef
lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef scalar)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_elem_type(type, LLVMTypeOf(scalar)));
@@ -82,17 +84,17 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
struct lp_type i32_vec_type = lp_type_int_vec(32);
i32_vec_type.length = type.length;
- res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar,
- LLVMConstInt(LLVMInt32Type(), 0, 0), "");
- res = LLVMBuildShuffleVector(bld->builder, res, bld->undef,
- lp_build_const_int_vec(i32_vec_type, 0), "");
+ res = LLVMBuildInsertElement(builder, bld->undef, scalar,
+ lp_build_const_int32(bld->gallivm, 0), "");
+ res = LLVMBuildShuffleVector(builder, res, bld->undef,
+ lp_build_const_int_vec(bld->gallivm, i32_vec_type, 0), "");
#else
/* XXX: The above path provokes a bug in LLVM 2.6 */
unsigned i;
res = bld->undef;
for(i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(bld->builder, res, scalar, index, "");
+ LLVMValueRef index = lp_build_const_int32(bld->gallivm, i);
+ res = LLVMBuildInsertElement(builder, res, scalar, index, "");
}
#endif
return res;
@@ -104,13 +106,13 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
* Combined extract and broadcast (or a mere shuffle when the two types match)
*/
LLVMValueRef
-lp_build_extract_broadcast(LLVMBuilderRef builder,
+lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
LLVMValueRef index)
{
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef res;
assert(src_type.floating == dst_type.floating);
@@ -132,8 +134,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* Broadcast scalar -> vector.
*/
- res = lp_build_broadcast(builder,
- lp_build_vec_type(dst_type),
+ res = lp_build_broadcast(gallivm,
+ lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@@ -144,16 +146,16 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
*/
LLVMValueRef shuffle;
- shuffle = lp_build_broadcast(builder,
+ shuffle = lp_build_broadcast(gallivm,
LLVMVectorType(i32t, dst_type.length),
index);
- res = LLVMBuildShuffleVector(builder, vector,
- LLVMGetUndef(lp_build_vec_type(dst_type)),
+ res = LLVMBuildShuffleVector(gallivm->builder, vector,
+ LLVMGetUndef(lp_build_vec_type(gallivm, dst_type)),
shuffle, "");
}
else {
LLVMValueRef scalar;
- scalar = LLVMBuildExtractElement(builder, vector, index, "");
+ scalar = LLVMBuildExtractElement(gallivm->builder, vector, index, "");
if (dst_type.length == 1) {
/*
* Trivial extract scalar from vector.
@@ -166,8 +168,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* General case of different sized vectors.
*/
- res = lp_build_broadcast(builder,
- lp_build_vec_type(dst_type),
+ res = lp_build_broadcast(gallivm,
+ lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@@ -185,6 +187,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
LLVMValueRef a,
unsigned channel)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@@ -199,14 +202,14 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
for(i = 0; i < 4; ++i)
shuffles[j + i] = LLVMConstInt(elem_type, j + channel, 0);
- return LLVMBuildShuffleVector(bld->builder, a, bld->undef, LLVMConstVector(shuffles, n), "");
+ return LLVMBuildShuffleVector(builder, a, bld->undef, LLVMConstVector(shuffles, n), "");
}
else {
/*
@@ -226,8 +229,9 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
};
unsigned i;
- a = LLVMBuildAnd(bld->builder, a,
- lp_build_const_mask_aos(type, 1 << channel), "");
+ a = LLVMBuildAnd(builder, a,
+ lp_build_const_mask_aos(bld->gallivm,
+ type, 1 << channel), "");
/*
* Build a type where each element is an integer that cover the four
@@ -239,7 +243,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
+ a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), "");
for(i = 0; i < 2; ++i) {
LLVMValueRef tmp = NULL;
@@ -250,16 +254,16 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
#endif
if(shift > 0)
- tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), "");
+ tmp = LLVMBuildLShr(builder, a, lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
if(shift < 0)
- tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), "");
+ tmp = LLVMBuildShl(builder, a, lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
assert(tmp);
if(tmp)
- a = LLVMBuildOr(bld->builder, a, tmp, "");
+ a = LLVMBuildOr(builder, a, tmp, "");
}
- return LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type), "");
+ return LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type), "");
}
}
@@ -269,6 +273,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
LLVMValueRef a,
const unsigned char swizzles[4])
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@@ -303,8 +308,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(type));
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(bld->gallivm, type));
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
LLVMValueRef aux[LP_MAX_VECTOR_LENGTH];
@@ -326,13 +331,13 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
case PIPE_SWIZZLE_ZERO:
shuffle = type.length + 0;
if (!aux[0]) {
- aux[0] = lp_build_const_elem(type, 0.0);
+ aux[0] = lp_build_const_elem(bld->gallivm, type, 0.0);
}
break;
case PIPE_SWIZZLE_ONE:
shuffle = type.length + 1;
if (!aux[1]) {
- aux[1] = lp_build_const_elem(type, 1.0);
+ aux[1] = lp_build_const_elem(bld->gallivm, type, 1.0);
}
break;
}
@@ -346,7 +351,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
}
}
- return LLVMBuildShuffleVector(bld->builder, a,
+ return LLVMBuildShuffleVector(builder, a,
LLVMConstVector(aux, n),
LLVMConstVector(shuffles, n), "");
} else {
@@ -387,8 +392,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
- res = LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type4), "");
+ a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), "");
+ res = LLVMBuildBitCast(builder, res, lp_build_vec_type(bld->gallivm, type4), "");
/*
* Mask and shift the channels, trying to group as many channels in the
@@ -414,23 +419,24 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
if (0)
debug_printf("shift = %i, mask = 0x%08llx\n", shift, mask);
- masked = LLVMBuildAnd(bld->builder, a,
- lp_build_const_int_vec(type4, mask), "");
+ masked = LLVMBuildAnd(builder, a,
+ lp_build_const_int_vec(bld->gallivm, type4, mask), "");
if (shift > 0) {
- shifted = LLVMBuildShl(bld->builder, masked,
- lp_build_const_int_vec(type4, shift*type.width), "");
+ shifted = LLVMBuildShl(builder, masked,
+ lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
} else if (shift < 0) {
- shifted = LLVMBuildLShr(bld->builder, masked,
- lp_build_const_int_vec(type4, -shift*type.width), "");
+ shifted = LLVMBuildLShr(builder, masked,
+ lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
} else {
shifted = masked;
}
- res = LLVMBuildOr(bld->builder, res, shifted, "");
+ res = LLVMBuildOr(builder, res, shifted, "");
}
}
- return LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type), "");
+ return LLVMBuildBitCast(builder, res,
+ lp_build_vec_type(bld->gallivm, type), "");
}
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
index fdea8442aef..c366a65103e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
@@ -45,7 +45,7 @@ struct lp_build_context;
LLVMValueRef
-lp_build_broadcast(LLVMBuilderRef builder,
+lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar);
@@ -56,7 +56,7 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef
-lp_build_extract_broadcast(LLVMBuilderRef builder,
+lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index a4d3b750c3c..40186befb9f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -46,6 +46,7 @@ struct tgsi_shader_info;
struct lp_type;
struct lp_build_context;
struct lp_build_mask_context;
+struct gallivm_state;
enum lp_build_tex_modifier {
@@ -141,7 +142,7 @@ struct lp_build_sampler_soa
void
(*emit_fetch_texel)( const struct lp_build_sampler_soa *sampler,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
unsigned unit,
unsigned num_coords,
@@ -174,7 +175,7 @@ lp_build_tgsi_info(const struct tgsi_token *tokens,
void
-lp_build_tgsi_soa(LLVMBuilderRef builder,
+lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@@ -187,7 +188,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
void
-lp_build_tgsi_aos(LLVMBuilderRef builder,
+lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
index c3c082b2b95..a021efd69ff 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
@@ -151,6 +151,7 @@ emit_fetch(
const struct tgsi_full_instruction *inst,
unsigned src_op)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
struct lp_type type = bld->base.type;
const struct tgsi_full_src_register *reg = &inst->Src[src_op];
LLVMValueRef res;
@@ -175,14 +176,12 @@ emit_fetch(
LLVMValueRef scalar;
LLVMValueRef swizzle;
- index = LLVMConstInt(LLVMInt32Type(),
- reg->Register.Index*4 + chan,
- 0);
+ index = lp_build_const_int32(bld->base.gallivm, reg->Register.Index * 4 + chan);
- scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
+ scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
&index, 1, "");
- scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
+ scalar = LLVMBuildLoad(builder, scalar_ptr, "");
lp_build_name(scalar, "const[%u].%c", reg->Register.Index, "xyzw"[chan]);
@@ -190,9 +189,9 @@ emit_fetch(
* NOTE: constants array is always assumed to be RGBA
*/
- swizzle = LLVMConstInt(LLVMInt32Type(), chan, 0);
+ swizzle = lp_build_const_int32(bld->base.gallivm, chan);
- res = LLVMBuildInsertElement(bld->base.builder, res, scalar, swizzle, "");
+ res = LLVMBuildInsertElement(builder, res, scalar, swizzle, "");
}
/*
@@ -206,14 +205,14 @@ emit_fetch(
unsigned i;
for (chan = 0; chan < 4; ++chan) {
- shuffles[chan] = LLVMConstInt(LLVMInt32Type(), chan, 0);
+ shuffles[chan] = lp_build_const_int32(bld->base.gallivm, chan);
}
for (i = 4; i < type.length; ++i) {
shuffles[i] = shuffles[i % 4];
}
- res = LLVMBuildShuffleVector(bld->base.builder,
+ res = LLVMBuildShuffleVector(builder,
res, bld->base.undef,
LLVMConstVector(shuffles, type.length),
"");
@@ -234,7 +233,7 @@ emit_fetch(
{
LLVMValueRef temp_ptr;
temp_ptr = bld->temps[reg->Register.Index];
- res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
+ res = LLVMBuildLoad(builder, temp_ptr, "");
if (!res)
return bld->base.undef;
}
@@ -281,6 +280,7 @@ emit_store(
unsigned index,
LLVMValueRef value)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
LLVMValueRef mask = NULL;
LLVMValueRef ptr;
@@ -299,7 +299,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
- value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
+ value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@@ -344,20 +344,20 @@ emit_store(
assert(inst->Predicate.Index < LP_MAX_TGSI_PREDS);
- pred = LLVMBuildLoad(bld->base.builder,
+ pred = LLVMBuildLoad(builder,
bld->preds[inst->Predicate.Index], "");
/*
* Convert the value to an integer mask.
*/
- pred = lp_build_compare(bld->base.builder,
+ pred = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
pred,
bld->base.zero);
if (inst->Predicate.Negate) {
- pred = LLVMBuildNot(bld->base.builder, pred, "");
+ pred = LLVMBuildNot(builder, pred, "");
}
pred = swizzle_aos(bld, pred,
@@ -367,7 +367,7 @@ emit_store(
inst->Predicate.SwizzleW);
if (mask) {
- mask = LLVMBuildAnd(bld->base.builder, mask, pred, "");
+ mask = LLVMBuildAnd(builder, mask, pred, "");
} else {
mask = pred;
}
@@ -380,10 +380,11 @@ emit_store(
if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) {
LLVMValueRef writemask;
- writemask = lp_build_const_mask_aos(bld->base.type, reg->Register.WriteMask);
+ writemask = lp_build_const_mask_aos(bld->base.gallivm, bld->base.type,
+ reg->Register.WriteMask);
if (mask) {
- mask = LLVMBuildAnd(bld->base.builder, mask, writemask, "");
+ mask = LLVMBuildAnd(builder, mask, writemask, "");
} else {
mask = writemask;
}
@@ -392,12 +393,12 @@ emit_store(
if (mask) {
LLVMValueRef orig_value;
- orig_value = LLVMBuildLoad(bld->base.builder, ptr, "");
+ orig_value = LLVMBuildLoad(builder, ptr, "");
value = lp_build_select(&bld->base,
mask, value, orig_value);
}
- LLVMBuildStore(bld->base.builder, value, ptr);
+ LLVMBuildStore(builder, value, ptr);
}
@@ -454,7 +455,8 @@ emit_declaration(
struct lp_build_tgsi_aos_context *bld,
const struct tgsi_full_declaration *decl)
{
- LLVMTypeRef vec_type = lp_build_vec_type(bld->base.type);
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->base.gallivm, bld->base.type);
unsigned first = decl->Range.First;
unsigned last = decl->Range.Last;
@@ -465,31 +467,26 @@ emit_declaration(
case TGSI_FILE_TEMPORARY:
assert(idx < LP_MAX_TGSI_TEMPS);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- last + 1, 0);
- bld->temps_array = lp_build_array_alloca(bld->base.builder,
+ LLVMValueRef array_size = lp_build_const_int32(gallivm, last + 1);
+ bld->temps_array = lp_build_array_alloca(bld->base.gallivm,
vec_type, array_size, "");
} else {
- bld->temps[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->temps[idx] = lp_build_alloca(gallivm, vec_type, "");
}
break;
case TGSI_FILE_OUTPUT:
- bld->outputs[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->outputs[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
- bld->addr[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->addr[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
- bld->preds[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->preds[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
default:
@@ -644,7 +641,7 @@ emit_instruction(
src0 = emit_fetch(bld, inst, 0);
src1 = emit_fetch(bld, inst, 1);
src2 = emit_fetch(bld, inst, 2);
- tmp1 = lp_build_const_vec(bld->base.type, 0.5);
+ tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0 = lp_build_select(&bld->base, tmp0, src0, src1);
break;
@@ -1039,7 +1036,7 @@ emit_instruction(
void
-lp_build_tgsi_aos(LLVMBuilderRef builder,
+lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],
@@ -1058,8 +1055,8 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
- lp_build_context_init(&bld.base, builder, type);
- lp_build_context_init(&bld.int_bld, builder, lp_int_type(type));
+ lp_build_context_init(&bld.base, gallivm, type);
+ lp_build_context_init(&bld.int_bld, gallivm, lp_int_type(type));
for (chan = 0; chan < 4; ++chan) {
bld.swizzles[chan] = swizzles[chan];
@@ -1131,7 +1128,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
imm[swizzle] = parse.FullToken.FullImmediate.u[chan].Float;
}
bld.immediates[num_immediates] =
- lp_build_const_aos(type,
+ lp_build_const_aos(gallivm, type,
imm[0], imm[1], imm[2], imm[3],
NULL);
num_immediates++;
@@ -1156,7 +1153,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
}
if (0) {
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
@@ -1167,7 +1164,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
if (0) {
LLVMModuleRef module = LLVMGetGlobalParent(
- LLVMGetBasicBlockParent(LLVMGetInsertBlock(bld.base.builder)));
+ LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder)));
LLVMDumpModule(module);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 7f0f058c222..1b5a8a5903b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -51,6 +51,7 @@
#include "lp_bld_arit.h"
#include "lp_bld_bitarit.h"
#include "lp_bld_gather.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_flow.h"
@@ -175,22 +176,24 @@ static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context
mask->loop_stack_size = 0;
mask->call_stack_size = 0;
- mask->int_vec_type = lp_build_int_vec_type(mask->bld->type);
+ mask->int_vec_type = lp_build_int_vec_type(bld->gallivm, mask->bld->type);
mask->exec_mask = mask->ret_mask = mask->break_mask = mask->cont_mask = mask->cond_mask =
LLVMConstAllOnes(mask->int_vec_type);
}
static void lp_exec_mask_update(struct lp_exec_mask *mask)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+
if (mask->loop_stack_size) {
/*for loops we need to update the entire mask at runtime */
LLVMValueRef tmp;
assert(mask->break_mask);
- tmp = LLVMBuildAnd(mask->bld->builder,
+ tmp = LLVMBuildAnd(builder,
mask->cont_mask,
mask->break_mask,
"maskcb");
- mask->exec_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->exec_mask = LLVMBuildAnd(builder,
mask->cond_mask,
tmp,
"maskfull");
@@ -198,7 +201,7 @@ static void lp_exec_mask_update(struct lp_exec_mask *mask)
mask->exec_mask = mask->cond_mask;
if (mask->call_stack_size) {
- mask->exec_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->exec_mask = LLVMBuildAnd(builder,
mask->exec_mask,
mask->ret_mask,
"callmask");
@@ -212,13 +215,15 @@ static void lp_exec_mask_update(struct lp_exec_mask *mask)
static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
LLVMValueRef val)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+
assert(mask->cond_stack_size < LP_MAX_TGSI_NESTING);
if (mask->cond_stack_size == 0) {
assert(mask->cond_mask == LLVMConstAllOnes(mask->int_vec_type));
}
mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask;
assert(LLVMTypeOf(val) == mask->int_vec_type);
- mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->cond_mask = LLVMBuildAnd(builder,
mask->cond_mask,
val,
"");
@@ -227,6 +232,7 @@ static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef prev_mask;
LLVMValueRef inv_mask;
@@ -236,9 +242,9 @@ static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
assert(prev_mask == LLVMConstAllOnes(mask->int_vec_type));
}
- inv_mask = LLVMBuildNot(mask->bld->builder, mask->cond_mask, "");
+ inv_mask = LLVMBuildNot(builder, mask->cond_mask, "");
- mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->cond_mask = LLVMBuildAnd(builder,
inv_mask,
prev_mask, "");
lp_exec_mask_update(mask);
@@ -253,6 +259,8 @@ static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask)
static void lp_exec_bgnloop(struct lp_exec_mask *mask)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+
if (mask->loop_stack_size == 0) {
assert(mask->loop_block == NULL);
assert(mask->cont_mask == LLVMConstAllOnes(mask->int_vec_type));
@@ -268,25 +276,26 @@ static void lp_exec_bgnloop(struct lp_exec_mask *mask)
mask->loop_stack[mask->loop_stack_size].break_var = mask->break_var;
++mask->loop_stack_size;
- mask->break_var = lp_build_alloca(mask->bld->builder, mask->int_vec_type, "");
- LLVMBuildStore(mask->bld->builder, mask->break_mask, mask->break_var);
+ mask->break_var = lp_build_alloca(mask->bld->gallivm, mask->int_vec_type, "");
+ LLVMBuildStore(builder, mask->break_mask, mask->break_var);
- mask->loop_block = lp_build_insert_new_block(mask->bld->builder, "bgnloop");
- LLVMBuildBr(mask->bld->builder, mask->loop_block);
- LLVMPositionBuilderAtEnd(mask->bld->builder, mask->loop_block);
+ mask->loop_block = lp_build_insert_new_block(mask->bld->gallivm, "bgnloop");
+ LLVMBuildBr(builder, mask->loop_block);
+ LLVMPositionBuilderAtEnd(builder, mask->loop_block);
- mask->break_mask = LLVMBuildLoad(mask->bld->builder, mask->break_var, "");
+ mask->break_mask = LLVMBuildLoad(builder, mask->break_var, "");
lp_exec_mask_update(mask);
}
static void lp_exec_break(struct lp_exec_mask *mask)
{
- LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+ LLVMValueRef exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"break");
- mask->break_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->break_mask = LLVMBuildAnd(builder,
mask->break_mask,
exec_mask, "break_full");
@@ -295,11 +304,12 @@ static void lp_exec_break(struct lp_exec_mask *mask)
static void lp_exec_continue(struct lp_exec_mask *mask)
{
- LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+ LLVMValueRef exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"");
- mask->cont_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->cont_mask = LLVMBuildAnd(builder,
mask->cont_mask,
exec_mask, "");
@@ -307,11 +317,14 @@ static void lp_exec_continue(struct lp_exec_mask *mask)
}
-static void lp_exec_endloop(struct lp_exec_mask *mask)
+static void lp_exec_endloop(struct gallivm_state *gallivm,
+ struct lp_exec_mask *mask)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMBasicBlockRef endloop;
- LLVMTypeRef reg_type = LLVMIntType(mask->bld->type.width*
- mask->bld->type.length);
+ LLVMTypeRef reg_type = LLVMIntTypeInContext(gallivm->context,
+ mask->bld->type.width *
+ mask->bld->type.length);
LLVMValueRef i1cond;
assert(mask->break_mask);
@@ -327,21 +340,21 @@ static void lp_exec_endloop(struct lp_exec_mask *mask)
* Unlike the continue mask, the break_mask must be preserved across loop
* iterations
*/
- LLVMBuildStore(mask->bld->builder, mask->break_mask, mask->break_var);
+ LLVMBuildStore(builder, mask->break_mask, mask->break_var);
/* i1cond = (mask == 0) */
i1cond = LLVMBuildICmp(
- mask->bld->builder,
+ builder,
LLVMIntNE,
- LLVMBuildBitCast(mask->bld->builder, mask->exec_mask, reg_type, ""),
+ LLVMBuildBitCast(builder, mask->exec_mask, reg_type, ""),
LLVMConstNull(reg_type), "");
- endloop = lp_build_insert_new_block(mask->bld->builder, "endloop");
+ endloop = lp_build_insert_new_block(mask->bld->gallivm, "endloop");
- LLVMBuildCondBr(mask->bld->builder,
+ LLVMBuildCondBr(builder,
i1cond, mask->loop_block, endloop);
- LLVMPositionBuilderAtEnd(mask->bld->builder, endloop);
+ LLVMPositionBuilderAtEnd(builder, endloop);
assert(mask->loop_stack_size);
--mask->loop_stack_size;
@@ -363,10 +376,12 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
LLVMValueRef val,
LLVMValueRef dst)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
+
/* Mix the predicate and execution mask */
if (mask->has_mask) {
if (pred) {
- pred = LLVMBuildAnd(mask->bld->builder, pred, mask->exec_mask, "");
+ pred = LLVMBuildAnd(builder, pred, mask->exec_mask, "");
} else {
pred = mask->exec_mask;
}
@@ -375,14 +390,14 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
if (pred) {
LLVMValueRef real_val, dst_val;
- dst_val = LLVMBuildLoad(mask->bld->builder, dst, "");
+ dst_val = LLVMBuildLoad(builder, dst, "");
real_val = lp_build_select(mask->bld,
pred,
val, dst_val);
- LLVMBuildStore(mask->bld->builder, real_val, dst);
+ LLVMBuildStore(builder, real_val, dst);
} else
- LLVMBuildStore(mask->bld->builder, val, dst);
+ LLVMBuildStore(builder, val, dst);
}
static void lp_exec_mask_call(struct lp_exec_mask *mask,
@@ -398,6 +413,7 @@ static void lp_exec_mask_call(struct lp_exec_mask *mask,
static void lp_exec_mask_ret(struct lp_exec_mask *mask, int *pc)
{
+ LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef exec_mask;
if (mask->call_stack_size == 0) {
@@ -405,11 +421,11 @@ static void lp_exec_mask_ret(struct lp_exec_mask *mask, int *pc)
*pc = -1;
return;
}
- exec_mask = LLVMBuildNot(mask->bld->builder,
+ exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"ret");
- mask->ret_mask = LLVMBuildAnd(mask->bld->builder,
+ mask->ret_mask = LLVMBuildAnd(builder,
mask->ret_mask,
exec_mask, "ret_full");
@@ -441,10 +457,11 @@ get_temp_ptr(struct lp_build_tgsi_soa_context *bld,
unsigned index,
unsigned chan)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
- return LLVMBuildGEP(bld->base.builder, bld->temps_array, &lindex, 1, "");
+ LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm, index * 4 + chan);
+ return LLVMBuildGEP(builder, bld->temps_array, &lindex, 1, "");
}
else {
return bld->temps[index][chan];
@@ -462,10 +479,12 @@ get_output_ptr(struct lp_build_tgsi_soa_context *bld,
unsigned index,
unsigned chan)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_OUTPUT)) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
- return LLVMBuildGEP(bld->base.builder, bld->outputs_array, &lindex, 1, "");
+ LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm,
+ index * 4 + chan);
+ return LLVMBuildGEP(builder, bld->outputs_array, &lindex, 1, "");
}
else {
return bld->outputs[index][chan];
@@ -482,6 +501,7 @@ build_gather(struct lp_build_tgsi_soa_context *bld,
LLVMValueRef base_ptr,
LLVMValueRef indexes)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
LLVMValueRef res = bld->base.undef;
unsigned i;
@@ -489,14 +509,14 @@ build_gather(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, load scalar value, insert it into 'res'.
*/
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
- LLVMValueRef index = LLVMBuildExtractElement(bld->base.builder,
+ LLVMValueRef ii = lp_build_const_int32(bld->base.gallivm, i);
+ LLVMValueRef index = LLVMBuildExtractElement(builder,
indexes, ii, "");
- LLVMValueRef scalar_ptr = LLVMBuildGEP(bld->base.builder, base_ptr,
+ LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr,
&index, 1, "gather_ptr");
- LLVMValueRef scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
+ LLVMValueRef scalar = LLVMBuildLoad(builder, scalar_ptr, "");
- res = LLVMBuildInsertElement(bld->base.builder, res, scalar, ii, "");
+ res = LLVMBuildInsertElement(builder, res, scalar, ii, "");
}
return res;
@@ -514,13 +534,14 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
struct lp_exec_mask *mask,
LLVMValueRef pred)
{
- LLVMBuilderRef builder = bld->base.builder;
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
unsigned i;
/* Mix the predicate and execution mask */
if (mask->has_mask) {
if (pred) {
- pred = LLVMBuildAnd(mask->bld->builder, pred, mask->exec_mask, "");
+ pred = LLVMBuildAnd(builder, pred, mask->exec_mask, "");
}
else {
pred = mask->exec_mask;
@@ -531,7 +552,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, store scalar value.
*/
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, "");
LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr");
LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val");
@@ -539,7 +560,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL;
if (0)
- lp_build_printf(builder, "scatter %d: val %f at %d %p\n",
+ lp_build_printf(gallivm, "scatter %d: val %f at %d %p\n",
ii, val, index, scalar_ptr);
if (scalar_pred) {
@@ -566,6 +587,7 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
unsigned reg_file, unsigned reg_index,
const struct tgsi_src_register *indirect_reg)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
struct lp_build_context *uint_bld = &bld->uint_bld;
/* always use X component of address register */
unsigned swizzle = indirect_reg->SwizzleX;
@@ -576,21 +598,22 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
assert(bld->indirect_files & (1 << reg_file));
- base = lp_build_const_int_vec(uint_bld->type, reg_index);
+ base = lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, reg_index);
assert(swizzle < 4);
- rel = LLVMBuildLoad(bld->base.builder,
+ rel = LLVMBuildLoad(builder,
bld->addr[indirect_reg->Index][swizzle],
"load addr reg");
/* for indexing we want integers */
- rel = LLVMBuildFPToSI(bld->base.builder,
+ rel = LLVMBuildFPToSI(builder,
rel,
uint_bld->vec_type, "");
index = lp_build_add(uint_bld, base, rel);
- max_index = lp_build_const_int_vec(uint_bld->type,
+ max_index = lp_build_const_int_vec(bld->base.gallivm,
+ uint_bld->type,
bld->info->file_max[reg_file]);
assert(!uint_bld->type.sign);
@@ -610,6 +633,8 @@ emit_fetch(
unsigned src_op,
const unsigned chan_index )
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context *uint_bld = &bld->uint_bld;
const struct tgsi_full_src_register *reg = &inst->Src[src_op];
const unsigned swizzle =
@@ -635,7 +660,7 @@ emit_fetch(
case TGSI_FILE_CONSTANT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef index_vec; /* index into the const buffer */
/* index_vec = indirect_index * 4 + swizzle */
@@ -649,11 +674,11 @@ emit_fetch(
LLVMValueRef index; /* index into the const buffer */
LLVMValueRef scalar, scalar_ptr;
- index = lp_build_const_int32(reg->Register.Index*4 + swizzle);
+ index = lp_build_const_int32(gallivm, reg->Register.Index*4 + swizzle);
- scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
+ scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
&index, 1, "");
- scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
+ scalar = LLVMBuildLoad(builder, scalar_ptr, "");
res = lp_build_broadcast_scalar(&bld->base, scalar);
}
@@ -667,9 +692,9 @@ emit_fetch(
case TGSI_FILE_INPUT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef inputs_array;
LLVMTypeRef float4_ptr_type;
@@ -680,18 +705,19 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast inputs_array pointer to float* */
- float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
- inputs_array = LLVMBuildBitCast(uint_bld->builder, bld->inputs_array,
- float4_ptr_type, "");
+ float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
+ inputs_array = LLVMBuildBitCast(builder, bld->inputs_array,
+ float4_ptr_type, "");
/* Gather values from the temporary register array */
res = build_gather(bld, inputs_array, index_vec);
} else {
if (bld->indirect_files & (1 << TGSI_FILE_INPUT)) {
- LLVMValueRef lindex = lp_build_const_int32(reg->Register.Index * 4 + swizzle);
- LLVMValueRef input_ptr = LLVMBuildGEP(bld->base.builder,
+ LLVMValueRef lindex = lp_build_const_int32(gallivm,
+ reg->Register.Index * 4 + swizzle);
+ LLVMValueRef input_ptr = LLVMBuildGEP(builder,
bld->inputs_array, &lindex, 1, "");
- res = LLVMBuildLoad(bld->base.builder, input_ptr, "");
+ res = LLVMBuildLoad(builder, input_ptr, "");
}
else {
res = bld->inputs[reg->Register.Index][swizzle];
@@ -703,9 +729,10 @@ emit_fetch(
case TGSI_FILE_TEMPORARY:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type,
+ bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef temps_array;
LLVMTypeRef float4_ptr_type;
@@ -716,8 +743,8 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast temps_array pointer to float* */
- float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
- temps_array = LLVMBuildBitCast(uint_bld->builder, bld->temps_array,
+ float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(bld->base.gallivm->context), 0);
+ temps_array = LLVMBuildBitCast(builder, bld->temps_array,
float4_ptr_type, "");
/* Gather values from the temporary register array */
@@ -726,7 +753,7 @@ emit_fetch(
else {
LLVMValueRef temp_ptr;
temp_ptr = get_temp_ptr(bld, reg->Register.Index, swizzle);
- res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
+ res = LLVMBuildLoad(builder, temp_ptr, "");
if (!res)
return bld->base.undef;
}
@@ -796,6 +823,7 @@ emit_fetch_predicate(
const struct tgsi_full_instruction *inst,
LLVMValueRef *pred)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
unsigned index;
unsigned char swizzles[4];
LLVMValueRef unswizzled[4] = {NULL, NULL, NULL, NULL};
@@ -825,7 +853,7 @@ emit_fetch_predicate(
* in the swizzles
*/
if (!unswizzled[swizzle]) {
- value = LLVMBuildLoad(bld->base.builder,
+ value = LLVMBuildLoad(builder,
bld->preds[index][swizzle], "");
/*
@@ -835,13 +863,13 @@ emit_fetch_predicate(
* is needlessly causing two comparisons due to storing the intermediate
* result as float vector instead of an integer mask vector.
*/
- value = lp_build_compare(bld->base.builder,
+ value = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
value,
bld->base.zero);
if (inst->Predicate.Negate) {
- value = LLVMBuildNot(bld->base.builder, value, "");
+ value = LLVMBuildNot(builder, value, "");
}
unswizzled[swizzle] = value;
@@ -866,6 +894,8 @@ emit_store(
LLVMValueRef pred,
LLVMValueRef value)
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
struct lp_build_context *uint_bld = &bld->uint_bld;
LLVMValueRef indirect_index = NULL;
@@ -880,7 +910,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
- value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
+ value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@@ -900,11 +930,10 @@ emit_store(
switch( reg->Register.File ) {
case TGSI_FILE_OUTPUT:
if (reg->Register.Indirect) {
- LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
- lp_build_const_int_vec(uint_bld->type, chan_index);
+ lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef outputs_array;
LLVMValueRef pixel_offsets;
@@ -914,7 +943,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = lp_build_const_int32(i);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@@ -925,7 +954,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
- float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float_ptr_type =
+ LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
outputs_array = LLVMBuildBitCast(builder, bld->outputs_array,
float_ptr_type, "");
@@ -942,11 +972,11 @@ emit_store(
case TGSI_FILE_TEMPORARY:
if (reg->Register.Indirect) {
- LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
- lp_build_const_int_vec(uint_bld->type, chan_index);
+ lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type,
+ bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef temps_array;
LLVMValueRef pixel_offsets;
@@ -956,7 +986,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = lp_build_const_int32(i);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@@ -967,7 +997,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
- float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float_ptr_type =
+ LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
temps_array = LLVMBuildBitCast(builder, bld->temps_array,
float_ptr_type, "");
@@ -984,7 +1015,7 @@ emit_store(
case TGSI_FILE_ADDRESS:
lp_exec_mask_store(&bld->exec_mask, pred, value,
- bld->addr[reg->Indirect.Index][chan_index]);
+ bld->addr[reg->Register.Index][chan_index]);
break;
case TGSI_FILE_PREDICATE:
@@ -1008,6 +1039,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
enum lp_build_tex_modifier modifier,
LLVMValueRef *texel)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
unsigned unit;
LLVMValueRef lod_bias, explicit_lod;
LLVMValueRef oow = NULL;
@@ -1073,13 +1105,12 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) {
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef index0 = lp_build_const_int32(bld->base.gallivm, 0);
for (i = 0; i < num_coords; i++) {
LLVMValueRef src1 = emit_fetch( bld, inst, 1, i );
LLVMValueRef src2 = emit_fetch( bld, inst, 2, i );
- ddx[i] = LLVMBuildExtractElement(bld->base.builder, src1, index0, "");
- ddy[i] = LLVMBuildExtractElement(bld->base.builder, src2, index0, "");
+ ddx[i] = LLVMBuildExtractElement(builder, src1, index0, "");
+ ddy[i] = LLVMBuildExtractElement(builder, src2, index0, "");
}
unit = inst->Src[3].Register.Index;
} else {
@@ -1095,7 +1126,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
bld->sampler->emit_fetch_texel(bld->sampler,
- bld->base.builder,
+ bld->base.gallivm,
bld->base.type,
unit, num_coords, coords,
ddx, ddy,
@@ -1150,6 +1181,7 @@ emit_kil(
const struct tgsi_full_instruction *inst,
int pc)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
const struct tgsi_full_src_register *reg = &inst->Src[0];
LLVMValueRef terms[NUM_CHANNELS];
LLVMValueRef mask;
@@ -1181,7 +1213,7 @@ emit_kil(
chan_mask = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, terms[chan_index], bld->base.zero);
if(mask)
- mask = LLVMBuildAnd(bld->base.builder, mask, chan_mask, "");
+ mask = LLVMBuildAnd(builder, mask, chan_mask, "");
else
mask = chan_mask;
}
@@ -1207,13 +1239,14 @@ emit_kilp(struct lp_build_tgsi_soa_context *bld,
const struct tgsi_full_instruction *inst,
int pc)
{
+ LLVMBuilderRef builder = bld->base.gallivm->builder;
LLVMValueRef mask;
/* For those channels which are "alive", disable fragment shader
* execution.
*/
if (bld->exec_mask.has_mask) {
- mask = LLVMBuildNot(bld->base.builder, bld->exec_mask.exec_mask, "kilp");
+ mask = LLVMBuildNot(builder, bld->exec_mask.exec_mask, "kilp");
}
else {
LLVMValueRef zero = LLVMConstNull(bld->base.int_vec_type);
@@ -1234,38 +1267,39 @@ emit_kilp(struct lp_build_tgsi_soa_context *bld,
static void
emit_dump_temps(struct lp_build_tgsi_soa_context *bld)
{
- LLVMBuilderRef builder = bld->base.builder;
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef temp_ptr;
- LLVMValueRef i0 = lp_build_const_int32(0);
- LLVMValueRef i1 = lp_build_const_int32(1);
- LLVMValueRef i2 = lp_build_const_int32(2);
- LLVMValueRef i3 = lp_build_const_int32(3);
+ LLVMValueRef i0 = lp_build_const_int32(gallivm, 0);
+ LLVMValueRef i1 = lp_build_const_int32(gallivm, 1);
+ LLVMValueRef i2 = lp_build_const_int32(gallivm, 2);
+ LLVMValueRef i3 = lp_build_const_int32(gallivm, 3);
int index;
int n = bld->info->file_max[TGSI_FILE_TEMPORARY];
for (index = 0; index < n; index++) {
- LLVMValueRef idx = lp_build_const_int32(index);
+ LLVMValueRef idx = lp_build_const_int32(gallivm, index);
LLVMValueRef v[4][4], res;
int chan;
- lp_build_printf(builder, "TEMP[%d]:\n", idx);
+ lp_build_printf(gallivm, "TEMP[%d]:\n", idx);
for (chan = 0; chan < 4; chan++) {
temp_ptr = get_temp_ptr(bld, index, chan);
- res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
+ res = LLVMBuildLoad(builder, temp_ptr, "");
v[chan][0] = LLVMBuildExtractElement(builder, res, i0, "");
v[chan][1] = LLVMBuildExtractElement(builder, res, i1, "");
v[chan][2] = LLVMBuildExtractElement(builder, res, i2, "");
v[chan][3] = LLVMBuildExtractElement(builder, res, i3, "");
}
- lp_build_printf(builder, " X: %f %f %f %f\n",
+ lp_build_printf(gallivm, " X: %f %f %f %f\n",
v[0][0], v[0][1], v[0][2], v[0][3]);
- lp_build_printf(builder, " Y: %f %f %f %f\n",
+ lp_build_printf(gallivm, " Y: %f %f %f %f\n",
v[1][0], v[1][1], v[1][2], v[1][3]);
- lp_build_printf(builder, " Z: %f %f %f %f\n",
+ lp_build_printf(gallivm, " Z: %f %f %f %f\n",
v[2][0], v[2][1], v[2][2], v[2][3]);
- lp_build_printf(builder, " W: %f %f %f %f\n",
+ lp_build_printf(gallivm, " W: %f %f %f %f\n",
v[3][0], v[3][1], v[3][2], v[3][3]);
}
}
@@ -1277,6 +1311,7 @@ emit_declaration(
struct lp_build_tgsi_soa_context *bld,
const struct tgsi_full_declaration *decl)
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
LLVMTypeRef vec_type = bld->base.vec_type;
const unsigned first = decl->Range.First;
const unsigned last = decl->Range.Last;
@@ -1289,15 +1324,14 @@ emit_declaration(
assert(idx < LP_MAX_TGSI_TEMPS);
if (!(bld->indirect_files & (1 << TGSI_FILE_TEMPORARY))) {
for (i = 0; i < NUM_CHANNELS; i++)
- bld->temps[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "temp");
+ bld->temps[idx][i] = lp_build_alloca(gallivm, vec_type, "temp");
}
break;
case TGSI_FILE_OUTPUT:
if (!(bld->indirect_files & (1 << TGSI_FILE_OUTPUT))) {
for (i = 0; i < NUM_CHANNELS; i++)
- bld->outputs[idx][i] = lp_build_alloca(bld->base.builder,
+ bld->outputs[idx][i] = lp_build_alloca(gallivm,
vec_type, "output");
}
break;
@@ -1305,15 +1339,14 @@ emit_declaration(
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
for (i = 0; i < NUM_CHANNELS; i++)
- bld->addr[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "addr");
+ bld->addr[idx][i] = lp_build_alloca(gallivm, vec_type, "addr");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
for (i = 0; i < NUM_CHANNELS; i++)
- bld->preds[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "predicate");
+ bld->preds[idx][i] = lp_build_alloca(gallivm, vec_type,
+ "predicate");
break;
default:
@@ -1639,7 +1672,7 @@ emit_instruction(
src0 = emit_fetch( bld, inst, 0, chan_index );
src1 = emit_fetch( bld, inst, 1, chan_index );
src2 = emit_fetch( bld, inst, 2, chan_index );
- tmp1 = lp_build_const_vec(bld->base.type, 0.5);
+ tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 );
}
@@ -2151,7 +2184,7 @@ emit_instruction(
break;
case TGSI_OPCODE_ENDLOOP:
- lp_exec_endloop(&bld->exec_mask);
+ lp_exec_endloop(bld->base.gallivm, &bld->exec_mask);
break;
case TGSI_OPCODE_ENDSUB:
@@ -2284,7 +2317,7 @@ emit_instruction(
void
-lp_build_tgsi_soa(LLVMBuilderRef builder,
+lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@@ -2312,9 +2345,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
- lp_build_context_init(&bld.base, builder, type);
- lp_build_context_init(&bld.uint_bld, builder, lp_uint_type(type));
- lp_build_context_init(&bld.elem_bld, builder, lp_elem_type(type));
+ lp_build_context_init(&bld.base, gallivm, type);
+ lp_build_context_init(&bld.uint_bld, gallivm, lp_uint_type(type));
+ lp_build_context_init(&bld.elem_bld, gallivm, lp_elem_type(type));
bld.mask = mask;
bld.pos = pos;
bld.inputs = inputs;
@@ -2334,17 +2367,19 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
lp_exec_mask_init(&bld.exec_mask, &bld.base);
if (bld.indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_TEMPORARY]*4 + 4, 0);
- bld.temps_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm,
+ info->file_max[TGSI_FILE_TEMPORARY] * 4 + 4);
+ bld.temps_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"temp_array");
}
if (bld.indirect_files & (1 << TGSI_FILE_OUTPUT)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_OUTPUT]*4 + 4, 0);
- bld.outputs_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm,
+ info->file_max[TGSI_FILE_OUTPUT] * 4 + 4);
+ bld.outputs_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"output_array");
}
@@ -2354,9 +2389,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
if (bld.indirect_files & (1 << TGSI_FILE_INPUT)) {
unsigned index, chan;
LLVMTypeRef vec_type = bld.base.vec_type;
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_INPUT]*4 + 4, 0);
- bld.inputs_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm, info->file_max[TGSI_FILE_INPUT]*4 + 4);
+ bld.inputs_array = lp_build_array_alloca(gallivm,
vec_type, array_size,
"input_array");
@@ -2364,13 +2399,14 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
for (index = 0; index < info->num_inputs; ++index) {
for (chan = 0; chan < NUM_CHANNELS; ++chan) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
+ LLVMValueRef lindex =
+ lp_build_const_int32(gallivm, index * 4 + chan);
LLVMValueRef input_ptr =
- LLVMBuildGEP(bld.base.builder, bld.inputs_array,
+ LLVMBuildGEP(gallivm->builder, bld.inputs_array,
&lindex, 1, "");
LLVMValueRef value = bld.inputs[index][chan];
if (value)
- LLVMBuildStore(bld.base.builder, value, input_ptr);
+ LLVMBuildStore(gallivm->builder, value, input_ptr);
}
}
}
@@ -2420,7 +2456,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
assert(num_immediates < LP_MAX_TGSI_IMMEDIATES);
for( i = 0; i < size; ++i )
bld.immediates[num_immediates][i] =
- lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float);
+ lp_build_const_vec(gallivm, type, parse.FullToken.FullImmediate.u[i].Float);
for( i = size; i < 4; ++i )
bld.immediates[num_immediates][i] = bld.base.undef;
num_immediates++;
@@ -2457,7 +2493,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
}
if (0) {
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
@@ -2468,7 +2504,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
if (0) {
LLVMModuleRef module = LLVMGetGlobalParent(
- LLVMGetBasicBlockParent(LLVMGetInsertBlock(bld.base.builder)));
+ LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder)));
LLVMDumpModule(module);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c
index 5205c7ada91..c5cf6d4a6c4 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_type.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c
@@ -30,34 +30,35 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
LLVMTypeRef
-lp_build_elem_type(struct lp_type type)
+lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.floating) {
switch(type.width) {
case 32:
- return LLVMFloatType();
+ return LLVMFloatTypeInContext(gallivm->context);
break;
case 64:
- return LLVMDoubleType();
+ return LLVMDoubleTypeInContext(gallivm->context);
break;
default:
assert(0);
- return LLVMFloatType();
+ return LLVMFloatTypeInContext(gallivm->context);
}
}
else {
- return LLVMIntType(type.width);
+ return LLVMIntTypeInContext(gallivm->context, type.width);
}
}
LLVMTypeRef
-lp_build_vec_type(struct lp_type type)
+lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type)
{
- LLVMTypeRef elem_type = lp_build_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@@ -149,16 +150,16 @@ lp_check_value(struct lp_type type, LLVMValueRef val)
LLVMTypeRef
-lp_build_int_elem_type(struct lp_type type)
+lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
- return LLVMIntType(type.width);
+ return LLVMIntTypeInContext(gallivm->context, type.width);
}
LLVMTypeRef
-lp_build_int_vec_type(struct lp_type type)
+lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type)
{
- LLVMTypeRef elem_type = lp_build_int_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@@ -170,7 +171,7 @@ lp_build_int_vec_type(struct lp_type type)
* Build int32[4] vector type
*/
LLVMTypeRef
-lp_build_int32_vec4_type(void)
+lp_build_int32_vec4_type(struct gallivm_state *gallivm)
{
struct lp_type t;
LLVMTypeRef type;
@@ -182,7 +183,7 @@ lp_build_int32_vec4_type(void)
t.width = 32; /* 32-bit int */
t.length = 4; /* 4 elements per vector */
- type = lp_build_int_elem_type(t);
+ type = lp_build_int_elem_type(gallivm, t);
return LLVMVectorType(type, t.length);
}
@@ -383,15 +384,15 @@ lp_dump_llvmtype(LLVMTypeRef t)
void
lp_build_context_init(struct lp_build_context *bld,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type)
{
- bld->builder = builder;
+ bld->gallivm = gallivm;
bld->type = type;
- bld->int_elem_type = lp_build_int_elem_type(type);
+ bld->int_elem_type = lp_build_int_elem_type(gallivm, type);
if (type.floating)
- bld->elem_type = lp_build_elem_type(type);
+ bld->elem_type = lp_build_elem_type(gallivm, type);
else
bld->elem_type = bld->int_elem_type;
@@ -406,5 +407,5 @@ lp_build_context_init(struct lp_build_context *bld,
bld->undef = LLVMGetUndef(bld->vec_type);
bld->zero = LLVMConstNull(bld->vec_type);
- bld->one = lp_build_one(type);
+ bld->one = lp_build_one(gallivm, type);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h
index a135d0df847..5007e83ac5f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_type.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h
@@ -120,7 +120,7 @@ struct lp_type {
*/
struct lp_build_context
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
/**
* This not only describes the input/output LLVM types, but also whether
@@ -285,11 +285,11 @@ lp_type_ufixed(unsigned width)
LLVMTypeRef
-lp_build_elem_type(struct lp_type type);
+lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_vec_type(struct lp_type type);
+lp_build_vec_type(struct gallivm_state *gallivm, struct lp_type type);
boolean
@@ -305,15 +305,15 @@ lp_check_value(struct lp_type type, LLVMValueRef val);
LLVMTypeRef
-lp_build_int_elem_type(struct lp_type type);
+lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_int_vec_type(struct lp_type type);
+lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_int32_vec4_type(void);
+lp_build_int32_vec4_type(struct gallivm_state *gallivm);
static INLINE struct lp_type
@@ -394,7 +394,7 @@ lp_dump_llvmtype(LLVMTypeRef t);
void
lp_build_context_init(struct lp_build_context *bld,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type);
diff --git a/src/gallium/auxiliary/target-helpers/wrap_screen.c b/src/gallium/auxiliary/target-helpers/wrap_screen.c
deleted file mode 100644
index df5d56a53c9..00000000000
--- a/src/gallium/auxiliary/target-helpers/wrap_screen.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- *
- **************************************************************************/
-
-/*
- * Authors:
- * Keith Whitwell
- */
-
-#include "target-helpers/wrap_screen.h"
-#include "trace/tr_public.h"
-#include "rbug/rbug_public.h"
-#include "identity/id_public.h"
-#include "util/u_debug.h"
-
-
-/* Centralized code to inject common wrapping layers:
- */
-struct pipe_screen *
-gallium_wrap_screen( struct pipe_screen *screen )
-{
- /* Screen wrapping functions are required not to fail. If it is
- * impossible to wrap a screen, the unwrapped screen should be
- * returned instead. Any failure condition should be returned in
- * an OUT argument.
- *
- * Otherwise it is really messy trying to clean up in this code.
- */
- if (debug_get_bool_option("GALLIUM_WRAP", FALSE)) {
- screen = identity_screen_create(screen);
- }
-
- /* Trace does its own checking if it should run */
- screen = trace_screen_create(screen);
-
- /* Rbug does its own checking if it should run */
- screen = rbug_screen_create(screen);
-
- return screen;
-}
-
-
-
-
diff --git a/src/gallium/auxiliary/target-helpers/wrap_screen.h b/src/gallium/auxiliary/target-helpers/wrap_screen.h
deleted file mode 100644
index 7e76beb7c5a..00000000000
--- a/src/gallium/auxiliary/target-helpers/wrap_screen.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef WRAP_SCREEN_HELPER_H
-#define WRAP_SCREEN_HELPER_H
-
-#include "pipe/p_compiler.h"
-
-struct pipe_screen;
-
-/* Centralized code to inject common wrapping layers. Other layers
- * can be introduced by specific targets, but these are the generally
- * helpful ones we probably want everywhere.
- */
-struct pipe_screen *
-gallium_wrap_screen( struct pipe_screen *screen );
-
-
-#endif
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h
index 7b077786013..b5ebbfbfaab 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h
@@ -388,6 +388,8 @@ tgsi_exec_get_shader_param(enum pipe_shader_cap param)
case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
return 1;
+ case PIPE_SHADER_CAP_SUBROUTINES:
+ return 1;
default:
return 0;
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.h b/src/gallium/auxiliary/tgsi/tgsi_parse.h
index d4df5851764..2aafa2a6e83 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_parse.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_parse.h
@@ -136,7 +136,8 @@ tgsi_parse_token(
static INLINE unsigned
tgsi_num_tokens(const struct tgsi_token *tokens)
{
- struct tgsi_header header = *(const struct tgsi_header *) tokens;
+ struct tgsi_header header;
+ memcpy(&header, tokens, sizeof(header));
return header.HeaderSize + header.BodySize;
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index b01d2ff4689..9a38c37979c 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -1007,7 +1007,8 @@ static const char *semantic_names[TGSI_SEMANTIC_COUNT] =
"FACE",
"EDGEFLAG",
"PRIM_ID",
- "INSTANCEID"
+ "INSTANCEID",
+ "STENCIL"
};
static const char *interpolate_names[TGSI_INTERPOLATE_COUNT] =
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index dfb142b9e1c..c11f7d383db 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -291,7 +291,7 @@ regions_overlap(int srcX0, int srcY0,
void
util_blit_pixels_writemask(struct blit_state *ctx,
struct pipe_resource *src_tex,
- struct pipe_subresource srcsub,
+ unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,
@@ -316,13 +316,12 @@ util_blit_pixels_writemask(struct blit_state *ctx,
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
filter == PIPE_TEX_MIPFILTER_LINEAR);
- assert(srcsub.level <= src_tex->last_level);
+ assert(src_level <= src_tex->last_level);
/* do the regions overlap? */
overlap = src_tex == dst->texture &&
- dst->face == srcsub.face &&
- dst->level == srcsub.level &&
- dst->zslice == srcZ0 &&
+ dst->u.tex.level == src_level &&
+ dst->u.tex.first_layer == srcZ0 &&
regions_overlap(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1);
@@ -339,16 +338,19 @@ util_blit_pixels_writemask(struct blit_state *ctx,
(dstX1 - dstX0) == (srcX1 - srcX0) &&
(dstY1 - dstY0) == (srcY1 - srcY0) &&
!overlap) {
- struct pipe_subresource subdst;
- subdst.face = dst->face;
- subdst.level = dst->level;
+ struct pipe_box src_box;
+ src_box.x = srcX0;
+ src_box.y = srcY0;
+ src_box.z = srcZ0;
+ src_box.width = srcW;
+ src_box.height = srcH;
+ src_box.depth = 1;
pipe->resource_copy_region(pipe,
- dst->texture, subdst,
- dstX0, dstY0, dst->zslice,/* dest */
- src_tex, srcsub,
- srcX0, srcY0, srcZ0,/* src */
- srcW, srcH); /* size */
- return;
+ dst->texture, dst->u.tex.level,
+ dstX0, dstY0, dst->u.tex.first_layer,/* dest */
+ src_tex, src_level,
+ &src_box);
+ return;
}
/* Create a temporary texture when src and dest alias or when src
@@ -359,16 +361,16 @@ util_blit_pixels_writemask(struct blit_state *ctx,
* This can still be improved upon.
*/
if ((src_tex == dst->texture &&
- dst->face == srcsub.face &&
- dst->level == srcsub.level &&
- dst->zslice == srcZ0) ||
+ dst->u.tex.level == src_level &&
+ dst->u.tex.first_layer == srcZ0) ||
(src_tex->target != PIPE_TEXTURE_2D &&
+ src_tex->target != PIPE_TEXTURE_2D &&
src_tex->target != PIPE_TEXTURE_RECT))
{
struct pipe_resource texTemp;
struct pipe_resource *tex;
struct pipe_sampler_view sv_templ;
- struct pipe_subresource texsub;
+ struct pipe_box src_box;
const int srcLeft = MIN2(srcX0, srcX1);
const int srcTop = MIN2(srcY0, srcY1);
@@ -394,19 +396,23 @@ util_blit_pixels_writemask(struct blit_state *ctx,
texTemp.width0 = srcW;
texTemp.height0 = srcH;
texTemp.depth0 = 1;
+ texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
tex = screen->resource_create(screen, &texTemp);
if (!tex)
return;
- texsub.face = 0;
- texsub.level = 0;
+ src_box.x = srcLeft;
+ src_box.y = srcTop;
+ src_box.z = srcZ0;
+ src_box.width = srcW;
+ src_box.height = srcH;
+ src_box.depth = 1;
/* load temp texture */
pipe->resource_copy_region(pipe,
- tex, texsub, 0, 0, 0, /* dest */
- src_tex, srcsub, srcLeft, srcTop, srcZ0, /* src */
- srcW, srcH); /* size */
+ tex, 0, 0, 0, 0, /* dest */
+ src_tex, src_level, &src_box);
normalized = tex->target != PIPE_TEXTURE_RECT;
if(normalized) {
@@ -433,7 +439,6 @@ util_blit_pixels_writemask(struct blit_state *ctx,
}
else {
u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format);
- sv_templ.first_level = sv_templ.last_level = srcsub.level;
sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ);
if (!sampler_view) {
@@ -447,10 +452,10 @@ util_blit_pixels_writemask(struct blit_state *ctx,
normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT;
if(normalized)
{
- s0 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
- s1 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
- t0 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
- t1 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
+ s0 /= (float)(u_minify(sampler_view->texture->width0, src_level));
+ s1 /= (float)(u_minify(sampler_view->texture->width0, src_level));
+ t0 /= (float)(u_minify(sampler_view->texture->height0, src_level));
+ t1 /= (float)(u_minify(sampler_view->texture->height0, src_level));
}
}
@@ -489,9 +494,8 @@ util_blit_pixels_writemask(struct blit_state *ctx,
ctx->sampler.normalized_coords = normalized;
ctx->sampler.min_img_filter = filter;
ctx->sampler.mag_img_filter = filter;
- /* we've limited this already with the sampler view but you never know... */
- ctx->sampler.min_lod = srcsub.level;
- ctx->sampler.max_lod = srcsub.level;
+ ctx->sampler.min_lod = src_level;
+ ctx->sampler.max_lod = src_level;
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
@@ -575,7 +579,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
void
util_blit_pixels(struct blit_state *ctx,
struct pipe_resource *src_tex,
- struct pipe_subresource srcsub,
+ unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ,
@@ -585,7 +589,7 @@ util_blit_pixels(struct blit_state *ctx,
float z, uint filter )
{
util_blit_pixels_writemask( ctx, src_tex,
- srcsub,
+ src_level,
srcX0, srcY0,
srcX1, srcY1,
srcZ,
@@ -662,6 +666,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_save_rasterizer(ctx->cso);
cso_save_samplers(ctx->cso);
cso_save_fragment_sampler_views(ctx->cso);
+ cso_save_viewport(ctx->cso);
cso_save_framebuffer(ctx->cso);
cso_save_fragment_shader(ctx->cso);
cso_save_vertex_shader(ctx->cso);
@@ -729,6 +734,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_restore_rasterizer(ctx->cso);
cso_restore_samplers(ctx->cso);
cso_restore_fragment_sampler_views(ctx->cso);
+ cso_restore_viewport(ctx->cso);
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);
cso_restore_vertex_shader(ctx->cso);
diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h
index b8a0dfce13f..3009e25eca3 100644
--- a/src/gallium/auxiliary/util/u_blit.h
+++ b/src/gallium/auxiliary/util/u_blit.h
@@ -42,7 +42,6 @@ struct cso_context;
struct pipe_context;
struct pipe_resource;
struct pipe_sampler_view;
-struct pipe_subresource;
struct pipe_surface;
@@ -55,7 +54,7 @@ util_destroy_blit(struct blit_state *ctx);
extern void
util_blit_pixels(struct blit_state *ctx,
struct pipe_resource *src_tex,
- struct pipe_subresource srcsub,
+ unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,
@@ -67,7 +66,7 @@ util_blit_pixels(struct blit_state *ctx,
void
util_blit_pixels_writemask(struct blit_state *ctx,
struct pipe_resource *src_tex,
- struct pipe_subresource srcsub,
+ unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index a163f93cb82..545021d2642 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -63,8 +63,7 @@ struct blitter_context_priv
/* Constant state objects. */
/* Vertex shaders. */
- void *vs_col; /**< Vertex shader which passes {pos, color} to the output */
- void *vs_tex; /**< Vertex shader which passes {pos, texcoord} to the output.*/
+ void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/
/* Fragment shaders. */
/* The shader at index i outputs color to color buffers 0,1,...,i-1. */
@@ -211,20 +210,12 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
/* fragment shaders are created on-demand */
- /* vertex shaders */
- {
- const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
- TGSI_SEMANTIC_COLOR };
- const uint semantic_indices[] = { 0, 0 };
- ctx->vs_col =
- util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
- semantic_indices);
- }
+ /* vertex shader */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indices[] = { 0, 0 };
- ctx->vs_tex =
+ ctx->vs =
util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
semantic_indices);
}
@@ -257,8 +248,7 @@ void util_blitter_destroy(struct blitter_context *blitter)
pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_flush_depth_stencil);
pipe->delete_rasterizer_state(pipe, ctx->rs_state);
- pipe->delete_vs_state(pipe, ctx->vs_col);
- pipe->delete_vs_state(pipe, ctx->vs_tex);
+ pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_vertex_elements_state(pipe, ctx->velem_state);
for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) {
@@ -419,17 +409,17 @@ static void blitter_set_clear_color(struct blitter_context_priv *ctx,
}
static void get_texcoords(struct pipe_resource *src,
- struct pipe_subresource subsrc,
- unsigned x1, unsigned y1,
- unsigned x2, unsigned y2,
- boolean normalized, float out[4])
+ unsigned level,
+ unsigned x1, unsigned y1,
+ unsigned x2, unsigned y2,
+ boolean normalized, float out[4])
{
if(normalized)
{
- out[0] = x1 / (float)u_minify(src->width0, subsrc.level);
- out[1] = y1 / (float)u_minify(src->height0, subsrc.level);
- out[2] = x2 / (float)u_minify(src->width0, subsrc.level);
- out[3] = y2 / (float)u_minify(src->height0, subsrc.level);
+ out[0] = x1 / (float)u_minify(src->width0, level);
+ out[1] = y1 / (float)u_minify(src->height0, level);
+ out[2] = x2 / (float)u_minify(src->width0, level);
+ out[3] = y2 / (float)u_minify(src->height0, level);
}
else
{
@@ -458,14 +448,14 @@ static void set_texcoords_in_vertices(const float coord[4],
static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
+ unsigned level,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
unsigned i;
float coord[4];
- get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord);
+ get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord);
set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8);
for (i = 0; i < 4; i++) {
@@ -476,15 +466,15 @@ static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx,
static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
+ unsigned level,
unsigned zslice,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
int i;
- float r = zslice / (float)u_minify(src->depth0, subsrc.level);
+ float r = zslice / (float)u_minify(src->depth0, level);
- blitter_set_texcoords_2d(ctx, src, subsrc, x1, y1, x2, y2);
+ blitter_set_texcoords_2d(ctx, src, level, x1, y1, x2, y2);
for (i = 0; i < 4; i++)
ctx->vertices[i][1][2] = r; /*r*/
@@ -492,7 +482,7 @@ static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx,
static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
+ unsigned level, unsigned face,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
@@ -500,10 +490,10 @@ static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx,
float coord[4];
float st[4][2];
- get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord);
+ get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord);
set_texcoords_in_vertices(coord, &st[0][0], 2);
- util_map_texcoords2d_onto_cubemap(subsrc.face,
+ util_map_texcoords2d_onto_cubemap(face,
/* pointer, stride in floats */
&st[0][0], 2,
&ctx->vertices[0][1][0], 8);
@@ -522,10 +512,13 @@ static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx,
static void blitter_draw_quad(struct blitter_context_priv *ctx)
{
struct pipe_context *pipe = ctx->base.pipe;
+ struct pipe_box box;
/* write vertices and draw them */
- pipe_buffer_write(pipe, ctx->vbuf,
- 0, sizeof(ctx->vertices), ctx->vertices);
+ u_box_1d(0, sizeof(ctx->vertices), &box);
+ pipe->transfer_inline_write(pipe, ctx->vbuf, 0,
+ PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+ &box, ctx->vertices, sizeof(ctx->vertices), 0);
util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
@@ -566,7 +559,9 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs)
if (!ctx->fs_col[num_cbufs])
ctx->fs_col[num_cbufs] =
- util_make_fragment_clonecolor_shader(pipe, num_cbufs);
+ util_make_fragment_cloneinput_shader(pipe, num_cbufs,
+ TGSI_SEMANTIC_GENERIC,
+ TGSI_INTERPOLATE_LINEAR);
return ctx->fs_col[num_cbufs];
}
@@ -697,7 +692,7 @@ void util_blitter_clear(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs));
- pipe->bind_vs_state(pipe, ctx->vs_col);
+ pipe->bind_vs_state(pipe, ctx->vs);
blitter_set_dst_dimensions(ctx, width, height);
blitter->draw_rectangle(blitter, 0, 0, width, height, depth,
@@ -714,21 +709,22 @@ boolean is_overlap(unsigned sx1, unsigned sx2, unsigned sy1, unsigned sy2,
void util_blitter_copy_region(struct blitter_context *blitter,
struct pipe_resource *dst,
- struct pipe_subresource subdst,
+ unsigned dstlevel,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
- unsigned srcx, unsigned srcy, unsigned srcz,
- unsigned width, unsigned height,
+ unsigned srclevel,
+ const struct pipe_box *srcbox,
boolean ignore_stencil)
{
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
struct pipe_context *pipe = ctx->base.pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_surface *dstsurf;
+ struct pipe_surface *dstsurf, surf_templ;
struct pipe_framebuffer_state fb_state;
struct pipe_sampler_view viewTempl, *view;
unsigned bind;
+ unsigned width = srcbox->width;
+ unsigned height = srcbox->height;
boolean is_stencil, is_depth;
boolean normalized;
@@ -739,12 +735,15 @@ void util_blitter_copy_region(struct blitter_context *blitter,
/* Sanity checks. */
if (dst == src) {
- assert(!is_overlap(srcx, srcx + width, srcy, srcy + height,
+ assert(!is_overlap(srcbox->x, srcbox->x + width, srcbox->y, srcbox->y + height,
dstx, dstx + width, dsty, dsty + height));
} else {
- assert(dst->format == src->format);
+ assert(util_is_format_compatible(util_format_description(src->format),
+ util_format_description(dst->format)));
}
assert(src->target < PIPE_MAX_TEXTURE_TYPES);
+ /* XXX should handle 3d regions */
+ assert(srcbox->depth == 1);
/* Is this a ZS format? */
is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0;
@@ -762,15 +761,18 @@ void util_blitter_copy_region(struct blitter_context *blitter,
dst->nr_samples, bind, 0) ||
!screen->is_format_supported(screen, src->format, src->target,
src->nr_samples, PIPE_BIND_SAMPLER_VIEW, 0)) {
- util_resource_copy_region(pipe, dst, subdst, dstx, dsty, dstz,
- src, subsrc, srcx, srcy, srcz, width, height);
+ util_resource_copy_region(pipe, dst, dstlevel, dstx, dsty, dstz,
+ src, srclevel, srcbox);
return;
}
- /* Get surfaces. */
- dstsurf = screen->get_tex_surface(screen, dst,
- subdst.face, subdst.level, dstz,
- bind);
+ /* Get surface. */
+ memset(&surf_templ, 0, sizeof(surf_templ));
+ u_surface_default_template(&surf_templ, dst, bind);
+ surf_templ.u.tex.level = dstlevel;
+ surf_templ.u.tex.first_layer = dstz;
+ surf_templ.u.tex.last_layer = dstz;
+ dstsurf = pipe->create_surface(pipe, dst, &surf_templ);
/* Check whether the states are properly saved. */
blitter_check_saved_CSOs(ctx);
@@ -810,9 +812,9 @@ void util_blitter_copy_region(struct blitter_context *blitter,
/* Set rasterizer state, shaders, and textures. */
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
- pipe->bind_vs_state(pipe, ctx->vs_tex);
+ pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_fragment_sampler_states(pipe, 1,
- blitter_get_sampler_state(ctx, subsrc.level, normalized));
+ blitter_get_sampler_state(ctx, srclevel, normalized));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->set_fragment_sampler_views(pipe, 1, &view);
pipe->set_framebuffer_state(pipe, &fb_state);
@@ -827,8 +829,8 @@ void util_blitter_copy_region(struct blitter_context *blitter,
{
/* Set texture coordinates. */
float coord[4];
- get_texcoords(src, subsrc, srcx, srcy,
- srcx+width, srcy+height, normalized, coord);
+ get_texcoords(src, srclevel, srcbox->x, srcbox->y,
+ srcbox->x+width, srcbox->y+height, normalized, coord);
/* Draw. */
blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
@@ -841,11 +843,13 @@ void util_blitter_copy_region(struct blitter_context *blitter,
case PIPE_TEXTURE_CUBE:
/* Set texture coordinates. */
if (src->target == PIPE_TEXTURE_3D)
- blitter_set_texcoords_3d(ctx, src, subsrc, srcz,
- srcx, srcy, srcx+width, srcy+height);
+ blitter_set_texcoords_3d(ctx, src, srclevel, srcbox->z,
+ srcbox->x, srcbox->y,
+ srcbox->x + width, srcbox->y + height);
else
- blitter_set_texcoords_cube(ctx, src, subsrc,
- srcx, srcy, srcx+width, srcy+height);
+ blitter_set_texcoords_cube(ctx, src, srclevel, srcbox->z,
+ srcbox->x, srcbox->y,
+ srcbox->x + width, srcbox->y + height);
/* Draw. */
blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0);
@@ -887,7 +891,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1));
- pipe->bind_vs_state(pipe, ctx->vs_col);
+ pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
@@ -947,7 +951,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
- pipe->bind_vs_state(pipe, ctx->vs_col);
+ pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
@@ -988,7 +992,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
- pipe->bind_vs_state(pipe, ctx->vs_col);
+ pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index f9f96f25c77..c5660cf2d00 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -164,12 +164,11 @@ void util_blitter_clear(struct blitter_context *blitter,
*/
void util_blitter_copy_region(struct blitter_context *blitter,
struct pipe_resource *dst,
- struct pipe_subresource subdst,
+ unsigned dstlevel,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
- unsigned srcx, unsigned srcy, unsigned srcz,
- unsigned width, unsigned height,
+ unsigned srclevel,
+ const struct pipe_box *srcbox,
boolean ignore_stencil);
/**
diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h
index e9c71743fc8..0b28d0f12c3 100644
--- a/src/gallium/auxiliary/util/u_box.h
+++ b/src/gallium/auxiliary/util/u_box.h
@@ -60,7 +60,6 @@ void u_box_2d_zslice( unsigned x,
box->depth = 1;
}
-
static INLINE
void u_box_3d( unsigned x,
unsigned y,
@@ -78,15 +77,4 @@ void u_box_3d( unsigned x,
box->depth = d;
}
-
-static INLINE
-struct pipe_subresource u_subresource( unsigned face,
- unsigned level )
-{
- struct pipe_subresource subresource;
- subresource.face = face;
- subresource.level = level;
- return subresource;
-}
-
#endif
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 504e6d2a18f..2ad2f95b13e 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -40,7 +40,8 @@
#include "util/u_string.h"
#include "util/u_math.h"
#include "util/u_tile.h"
-#include "util/u_prim.h"
+#include "util/u_prim.h"
+#include "util/u_surface.h"
#include <limits.h> /* CHAR_BIT */
@@ -453,9 +454,10 @@ void debug_dump_image(const char *prefix,
#endif
}
+/* FIXME: dump resources, not surfaces... */
void debug_dump_surface(struct pipe_context *pipe,
- const char *prefix,
- struct pipe_surface *surface)
+ const char *prefix,
+ struct pipe_surface *surface)
{
struct pipe_resource *texture;
struct pipe_transfer *transfer;
@@ -472,23 +474,23 @@ void debug_dump_surface(struct pipe_context *pipe,
*/
texture = surface->texture;
- transfer = pipe_get_transfer(pipe, texture, surface->face,
- surface->level, surface->zslice,
- PIPE_TRANSFER_READ, 0, 0, surface->width,
- surface->height);
-
+ transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
+ surface->u.tex.first_layer,
+ PIPE_TRANSFER_READ,
+ 0, 0, surface->width, surface->height);
+
data = pipe->transfer_map(pipe, transfer);
if(!data)
goto error;
-
- debug_dump_image(prefix,
+
+ debug_dump_image(prefix,
texture->format,
- util_format_get_blocksize(texture->format),
+ util_format_get_blocksize(texture->format),
util_format_get_nblocksx(texture->format, surface->width),
util_format_get_nblocksy(texture->format, surface->height),
transfer->stride,
data);
-
+
pipe->transfer_unmap(pipe, transfer);
error:
pipe->transfer_destroy(pipe, transfer);
@@ -499,20 +501,18 @@ void debug_dump_texture(struct pipe_context *pipe,
const char *prefix,
struct pipe_resource *texture)
{
- struct pipe_surface *surface;
- struct pipe_screen *screen;
+ struct pipe_surface *surface, surf_tmpl;
if (!texture)
return;
- screen = texture->screen;
-
- /* XXX for now, just dump image for face=0, level=0 */
- surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
- PIPE_BIND_SAMPLER_VIEW);
+ /* XXX for now, just dump image for layer=0, level=0 */
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ u_surface_default_template(&surf_tmpl, texture, 0 /* no bind flag - not a surface */);
+ surface = pipe->create_surface(pipe, texture, &surf_tmpl);
if (surface) {
debug_dump_surface(pipe, prefix, surface);
- screen->tex_surface_destroy(surface);
+ pipe->surface_destroy(pipe, surface);
}
}
@@ -550,17 +550,16 @@ struct bmp_rgb_quad {
void
debug_dump_surface_bmp(struct pipe_context *pipe,
- const char *filename,
+ const char *filename,
struct pipe_surface *surface)
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
struct pipe_transfer *transfer;
struct pipe_resource *texture = surface->texture;
- transfer = pipe_get_transfer(pipe, texture, surface->face,
- surface->level, surface->zslice,
- PIPE_TRANSFER_READ, 0, 0, surface->width,
- surface->height);
+ transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
+ surface->u.tex.first_layer, PIPE_TRANSFER_READ,
+ 0, 0, surface->width, surface->height);
debug_dump_transfer_bmp(pipe, filename, transfer);
diff --git a/src/gallium/auxiliary/util/u_debug_describe.c b/src/gallium/auxiliary/util/u_debug_describe.c
index 1c90ff31069..7ed8ee608a8 100644
--- a/src/gallium/auxiliary/util/u_debug_describe.c
+++ b/src/gallium/auxiliary/util/u_debug_describe.c
@@ -69,7 +69,7 @@ debug_describe_surface(char* buf, const struct pipe_surface *ptr)
{
char res[128];
debug_describe_resource(res, ptr->texture);
- util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->face, ptr->level, ptr->zslice);
+ util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer);
}
void
diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
index 528a1c394be..24e039fd226 100644
--- a/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/src/gallium/auxiliary/util/u_debug_stack.c
@@ -48,7 +48,10 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
if(!nr_frames)
return;
-#if defined(PIPE_CC_GCC)
+#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
+ __asm__ __volatile__("mov (%%ebp),%0": "=r" (frame_pointer));
+ frame_pointer = (const void **)frame_pointer[0];
+#elif defined(PIPE_CC_GCC)
frame_pointer = ((const void **)__builtin_frame_address(1));
#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
__asm {
diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c
index 332952af88b..44d437747a1 100644
--- a/src/gallium/auxiliary/util/u_debug_symbol.c
+++ b/src/gallium/auxiliary/util/u_debug_symbol.c
@@ -40,7 +40,7 @@
#include "u_debug_symbol.h"
#include "u_hash_table.h"
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
+#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
#include <windows.h>
#include <stddef.h>
@@ -165,7 +165,7 @@ debug_symbol_name_glibc(const void *addr, char* buf, unsigned size)
void
debug_symbol_name(const void *addr, char* buf, unsigned size)
{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
+#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
debug_symbol_name_imagehlp(addr, buf, size);
if(buf[0])
return;
diff --git a/src/gallium/auxiliary/util/u_dirty_flags.h b/src/gallium/auxiliary/util/u_dirty_flags.h
index 7e1be45ad5a..40539f0b0ea 100644
--- a/src/gallium/auxiliary/util/u_dirty_flags.h
+++ b/src/gallium/auxiliary/util/u_dirty_flags.h
@@ -24,5 +24,9 @@
#define U_NEW_VERTEX_BUFFER 0x10000
#define U_NEW_QUERY 0x20000
#define U_NEW_DEPTH_STENCIL 0x40000
+#define U_NEW_GS 0x80000
+#define U_NEW_GS_CONSTANTS 0x100000
+#define U_NEW_GS_SAMPLER_VIEW 0x200000
+#define U_NEW_GS_SAMPLER_STATES 0x400000
#endif
diff --git a/src/gallium/auxiliary/util/u_dirty_surfaces.h b/src/gallium/auxiliary/util/u_dirty_surfaces.h
index fd1bbe5ffdf..f3618d9be74 100644
--- a/src/gallium/auxiliary/util/u_dirty_surfaces.h
+++ b/src/gallium/auxiliary/util/u_dirty_surfaces.h
@@ -77,7 +77,7 @@ util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct ut
struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);
next = p->next;
- if(ds->base.level >= first && ds->base.level <= last)
+ if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last)
flush(pipe, &ds->base);
}
}
@@ -86,7 +86,8 @@ static INLINE void
util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush)
{
if(!LIST_IS_EMPTY(&dss->dirty_list))
- util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->first_level, MIN2((unsigned)ceilf(pss->max_lod) + psv->first_level, psv->last_level), flush);
+ util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level,
+ MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush);
}
static INLINE void
diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c
index cda5b8ba512..b471d59eebf 100644
--- a/src/gallium/auxiliary/util/u_dump_state.c
+++ b/src/gallium/auxiliary/util/u_dump_state.c
@@ -279,6 +279,10 @@ util_dump_template(struct os_stream *stream, const struct pipe_resource *templat
util_dump_uint(stream, templat->depth0);
util_dump_member_end(stream);
+ util_dump_member_begin(stream, "array_size");
+ util_dump_uint(stream, templat->array_size);
+ util_dump_member_end(stream);
+
util_dump_member(stream, uint, templat, last_level);
util_dump_member(stream, uint, templat, usage);
util_dump_member(stream, uint, templat, bind);
@@ -633,14 +637,12 @@ util_dump_surface(struct os_stream *stream, const struct pipe_surface *state)
util_dump_member(stream, uint, state, width);
util_dump_member(stream, uint, state, height);
- util_dump_member(stream, uint, state, layout);
- util_dump_member(stream, uint, state, offset);
util_dump_member(stream, uint, state, usage);
util_dump_member(stream, ptr, state, texture);
- util_dump_member(stream, uint, state, face);
- util_dump_member(stream, uint, state, level);
- util_dump_member(stream, uint, state, zslice);
+ util_dump_member(stream, uint, state, u.tex.level);
+ util_dump_member(stream, uint, state, u.tex.first_layer);
+ util_dump_member(stream, uint, state, u.tex.last_layer);
util_dump_struct_end(stream);
}
@@ -660,7 +662,7 @@ util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state)
/*util_dump_member(stream, uint, state, box);*/
util_dump_member(stream, uint, state, stride);
- util_dump_member(stream, uint, state, slice_stride);
+ util_dump_member(stream, uint, state, layer_stride);
/*util_dump_member(stream, ptr, state, data);*/
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 6a931a95819..d22ae8b375b 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -48,6 +48,8 @@
#include "util/u_simple_shaders.h"
#include "util/u_math.h"
#include "util/u_texture.h"
+#include "util/u_half.h"
+#include "util/u_surface.h"
#include "cso_cache/cso_context.h"
@@ -65,7 +67,7 @@ struct gen_mipmap_state
struct pipe_vertex_element velem[2];
void *vs;
- void *fs2d, *fsCube;
+ void *fs1d, *fs2d, *fs3d, *fsCube;
struct pipe_resource *vbuf; /**< quad vertices */
unsigned vbuf_slot;
@@ -89,24 +91,7 @@ enum dtype
};
-typedef ushort half_float;
-
-
-static half_float
-float_to_half(float f)
-{
- /* XXX fix this */
- return 0;
-}
-
-static float
-half_to_float(half_float h)
-{
- /* XXX fix this */
- return 0.0f;
-}
-
-
+typedef uint16_t half_float;
/**
@@ -145,7 +130,7 @@ half_to_float(half_float h)
rowC[j][e], rowC[k][e], \
rowD[j][e], rowD[k][e]); \
} while(0)
-
+
#define FILTER_F_3D(e) \
do { \
dst[i][e] = (rowA[j][e] + rowA[k][e] \
@@ -156,15 +141,15 @@ half_to_float(half_float h)
#define FILTER_HF_3D(e) \
do { \
- const float aj = half_to_float(rowA[j][e]); \
- const float ak = half_to_float(rowA[k][e]); \
- const float bj = half_to_float(rowB[j][e]); \
- const float bk = half_to_float(rowB[k][e]); \
- const float cj = half_to_float(rowC[j][e]); \
- const float ck = half_to_float(rowC[k][e]); \
- const float dj = half_to_float(rowD[j][e]); \
- const float dk = half_to_float(rowD[k][e]); \
- dst[i][e] = float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
+ const float aj = util_half_to_float(rowA[j][e]); \
+ const float ak = util_half_to_float(rowA[k][e]); \
+ const float bj = util_half_to_float(rowB[j][e]); \
+ const float bk = util_half_to_float(rowB[k][e]); \
+ const float cj = util_half_to_float(rowC[j][e]); \
+ const float ck = util_half_to_float(rowC[k][e]); \
+ const float dj = util_half_to_float(rowD[j][e]); \
+ const float dk = util_half_to_float(rowD[k][e]); \
+ dst[i][e] = util_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
* 0.125F); \
} while(0)
/*@}*/
@@ -343,8 +328,7 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
}
}
-#if 0
- else if (datatype == HALF_DTYPE_FLOAT && comps == 4) {
+ else if (datatype == DTYPE_HALF_FLOAT && comps == 4) {
uint i, j, k, comp;
const half_float(*rowA)[4] = (const half_float(*)[4]) srcRowA;
const half_float(*rowB)[4] = (const half_float(*)[4]) srcRowB;
@@ -353,11 +337,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 4; comp++) {
float aj, ak, bj, bk;
- aj = half_to_float(rowA[j][comp]);
- ak = half_to_float(rowA[k][comp]);
- bj = half_to_float(rowB[j][comp]);
- bk = half_to_float(rowB[k][comp]);
- dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
+ aj = util_half_to_float(rowA[j][comp]);
+ ak = util_half_to_float(rowA[k][comp]);
+ bj = util_half_to_float(rowB[j][comp]);
+ bk = util_half_to_float(rowB[k][comp]);
+ dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@@ -370,11 +354,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 3; comp++) {
float aj, ak, bj, bk;
- aj = half_to_float(rowA[j][comp]);
- ak = half_to_float(rowA[k][comp]);
- bj = half_to_float(rowB[j][comp]);
- bk = half_to_float(rowB[k][comp]);
- dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
+ aj = util_half_to_float(rowA[j][comp]);
+ ak = util_half_to_float(rowA[k][comp]);
+ bj = util_half_to_float(rowB[j][comp]);
+ bk = util_half_to_float(rowB[k][comp]);
+ dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@@ -387,11 +371,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 2; comp++) {
float aj, ak, bj, bk;
- aj = half_to_float(rowA[j][comp]);
- ak = half_to_float(rowA[k][comp]);
- bj = half_to_float(rowB[j][comp]);
- bk = half_to_float(rowB[k][comp]);
- dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
+ aj = util_half_to_float(rowA[j][comp]);
+ ak = util_half_to_float(rowA[k][comp]);
+ bj = util_half_to_float(rowB[j][comp]);
+ bk = util_half_to_float(rowB[k][comp]);
+ dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@@ -403,14 +387,13 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
for (i = j = 0, k = k0; i < (uint) dstWidth;
i++, j += colStride, k += colStride) {
float aj, ak, bj, bk;
- aj = half_to_float(rowA[j]);
- ak = half_to_float(rowA[k]);
- bj = half_to_float(rowB[j]);
- bk = half_to_float(rowB[k]);
- dst[i] = float_to_half((aj + ak + bj + bk) * 0.25F);
+ aj = util_half_to_float(rowA[j]);
+ ak = util_half_to_float(rowA[k]);
+ bj = util_half_to_float(rowB[j]);
+ bk = util_half_to_float(rowB[k]);
+ dst[i] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
-#endif
else if (datatype == DTYPE_UINT && comps == 1) {
uint i, j, k;
@@ -1036,32 +1019,34 @@ reduce_2d(enum pipe_format pformat,
static void
reduce_3d(enum pipe_format pformat,
int srcWidth, int srcHeight, int srcDepth,
- int srcRowStride, const ubyte *srcPtr,
+ int srcRowStride, int srcImageStride, const ubyte *srcPtr,
int dstWidth, int dstHeight, int dstDepth,
- int dstRowStride, ubyte *dstPtr)
+ int dstRowStride, int dstImageStride, ubyte *dstPtr)
{
const int bpt = util_format_get_blocksize(pformat);
- const int border = 0;
int img, row;
- int bytesPerSrcImage, bytesPerDstImage;
- int bytesPerSrcRow, bytesPerDstRow;
int srcImageOffset, srcRowOffset;
enum dtype datatype;
uint comps;
format_to_type_comps(pformat, &datatype, &comps);
- bytesPerSrcImage = srcWidth * srcHeight * bpt;
- bytesPerDstImage = dstWidth * dstHeight * bpt;
+ /* XXX I think we should rather assert those strides */
+ if (!srcImageStride)
+ srcImageStride = srcWidth * srcHeight * bpt;
+ if (!dstImageStride)
+ dstImageStride = dstWidth * dstHeight * bpt;
- bytesPerSrcRow = srcWidth * bpt;
- bytesPerDstRow = dstWidth * bpt;
+ if (!srcRowStride)
+ srcRowStride = srcWidth * bpt;
+ if (!dstRowStride)
+ dstRowStride = dstWidth * bpt;
/* Offset between adjacent src images to be averaged together */
- srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage;
+ srcImageOffset = (srcDepth == dstDepth) ? 0 : srcImageStride;
/* Offset between adjacent src rows to be averaged together */
- srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt;
+ srcRowOffset = (srcHeight == dstHeight) ? 0 : srcRowStride;
/*
* Need to average together up to 8 src pixels for each dest pixel.
@@ -1077,16 +1062,13 @@ reduce_3d(enum pipe_format pformat,
*/
for (img = 0; img < dstDepth; img++) {
- /* first source image pointer, skipping border */
+ /* first source image pointer */
const ubyte *imgSrcA = srcPtr
- + (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border
- + img * (bytesPerSrcImage + srcImageOffset);
- /* second source image pointer, skipping border */
+ + img * (srcImageStride + srcImageOffset);
+ /* second source image pointer */
const ubyte *imgSrcB = imgSrcA + srcImageOffset;
- /* address of the dest image, skipping border */
- ubyte *imgDst = dstPtr
- + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border
- + img * bytesPerDstImage;
+ /* address of the dest image */
+ ubyte *imgDst = dstPtr + img * dstImageStride;
/* setup the four source row pointers and the dest row pointer */
const ubyte *srcImgARowA = imgSrcA;
@@ -1102,11 +1084,11 @@ reduce_3d(enum pipe_format pformat,
dstWidth, dstImgRow);
/* advance to next rows */
- srcImgARowA += bytesPerSrcRow + srcRowOffset;
- srcImgARowB += bytesPerSrcRow + srcRowOffset;
- srcImgBRowA += bytesPerSrcRow + srcRowOffset;
- srcImgBRowB += bytesPerSrcRow + srcRowOffset;
- dstImgRow += bytesPerDstRow;
+ srcImgARowA += srcRowStride + srcRowOffset;
+ srcImgARowB += srcRowStride + srcRowOffset;
+ srcImgBRowA += srcRowStride + srcRowOffset;
+ srcImgBRowB += srcRowStride + srcRowOffset;
+ dstImgRow += dstImageStride;
}
}
}
@@ -1117,25 +1099,24 @@ reduce_3d(enum pipe_format pformat,
static void
make_1d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
- uint face, uint baseLevel, uint lastLevel)
+ uint layer, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
- const uint zslice = 0;
uint dstLevel;
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
void *srcMap, *dstMap;
-
- srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel));
- dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
- PIPE_TRANSFER_WRITE, 0, 0,
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel));
+
+ srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer,
+ PIPE_TRANSFER_READ, 0, 0,
+ u_minify(pt->width0, srcLevel),
+ u_minify(pt->height0, srcLevel));
+ dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ u_minify(pt->width0, dstLevel),
+ u_minify(pt->height0, dstLevel));
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
@@ -1156,12 +1137,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx,
static void
make_2d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
- uint face, uint baseLevel, uint lastLevel)
+ uint layer, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
- const uint zslice = 0;
uint dstLevel;
-
+
assert(util_format_get_blockwidth(pt->format) == 1);
assert(util_format_get_blockheight(pt->format) == 1);
@@ -1169,15 +1149,15 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
-
- srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel));
- dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
- PIPE_TRANSFER_WRITE, 0, 0,
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel));
+
+ srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer,
+ PIPE_TRANSFER_READ, 0, 0,
+ u_minify(pt->width0, srcLevel),
+ u_minify(pt->height0, srcLevel));
+ dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ u_minify(pt->width0, dstLevel),
+ u_minify(pt->height0, dstLevel));
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
@@ -1197,41 +1177,49 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
}
+/* XXX looks a bit more like it could work now but need to test */
static void
make_3d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
-#if 0
struct pipe_context *pipe = ctx->pipe;
- struct pipe_screen *screen = pipe->screen;
- uint dstLevel, zslice = 0;
+ uint dstLevel;
+ struct pipe_box src_box, dst_box;
assert(util_format_get_blockwidth(pt->format) == 1);
assert(util_format_get_blockheight(pt->format) == 1);
+ src_box.x = src_box.y = src_box.z = 0;
+ dst_box.x = dst_box.y = dst_box.z = 0;
+
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
-
- srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel));
- dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice,
- PIPE_TRANSFER_WRITE, 0, 0,
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel));
+ struct pipe_box src_box, dst_box;
+ src_box.width = u_minify(pt->width0, srcLevel);
+ src_box.height = u_minify(pt->height0, srcLevel);
+ src_box.depth = u_minify(pt->depth0, srcLevel);
+ dst_box.width = u_minify(pt->width0, dstLevel);
+ dst_box.height = u_minify(pt->height0, dstLevel);
+ dst_box.depth = u_minify(pt->depth0, dstLevel);
+
+ srcTrans = pipe->get_transfer(pipe, pt, srcLevel,
+ PIPE_TRANSFER_READ,
+ &src_box);
+ dstTrans = pipe->get_transfer(pipe, pt, dstLevel,
+ PIPE_TRANSFER_WRITE,
+ &dst_box);
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
reduce_3d(pt->format,
- srcTrans->width, srcTrans->height,
- srcTrans->stride, srcMap,
- dstTrans->width, dstTrans->height,
- dstTrans->stride, dstMap);
+ srcTrans->box.width, srcTrans->box.height, srcTrans->box.depth,
+ srcTrans->stride, srcTrans->layer_stride, srcMap,
+ dstTrans->box.width, dstTrans->box.height, dstTrans->box.depth,
+ dstTrans->stride, dstTrans->layer_stride, dstMap);
pipe->transfer_unmap(pipe, srcTrans);
pipe->transfer_unmap(pipe, dstTrans);
@@ -1239,28 +1227,25 @@ make_3d_mipmap(struct gen_mipmap_state *ctx,
pipe->transfer_destroy(pipe, srcTrans);
pipe->transfer_destroy(pipe, dstTrans);
}
-#else
- (void) reduce_3d;
-#endif
}
static void
fallback_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
- uint face, uint baseLevel, uint lastLevel)
+ uint layer, uint baseLevel, uint lastLevel)
{
switch (pt->target) {
case PIPE_TEXTURE_1D:
- make_1d_mipmap(ctx, pt, face, baseLevel, lastLevel);
+ make_1d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
case PIPE_TEXTURE_2D:
case PIPE_TEXTURE_RECT:
case PIPE_TEXTURE_CUBE:
- make_2d_mipmap(ctx, pt, face, baseLevel, lastLevel);
+ make_2d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
case PIPE_TEXTURE_3D:
- make_3d_mipmap(ctx, pt, face, baseLevel, lastLevel);
+ make_3d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
default:
assert(0);
@@ -1328,8 +1313,12 @@ util_create_gen_mipmap(struct pipe_context *pipe,
}
/* fragment shader */
+ ctx->fs1d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D,
+ TGSI_INTERPOLATE_LINEAR);
ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR);
+ ctx->fs3d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D,
+ TGSI_INTERPOLATE_LINEAR);
ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE,
TGSI_INTERPOLATE_LINEAR);
@@ -1371,7 +1360,7 @@ get_next_slot(struct gen_mipmap_state *ctx)
static unsigned
set_vertex_data(struct gen_mipmap_state *ctx,
enum pipe_texture_target tex_target,
- uint face)
+ uint layer, float r)
{
unsigned offset;
@@ -1397,26 +1386,26 @@ set_vertex_data(struct gen_mipmap_state *ctx,
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
};
- util_map_texcoords2d_onto_cubemap(face, &st[0][0], 2,
+ util_map_texcoords2d_onto_cubemap(layer, &st[0][0], 2,
&ctx->vertices[0][1][0], 8);
}
else {
- /* 1D/2D */
+ /* 1D/2D/3D */
ctx->vertices[0][1][0] = 0.0f; /*s*/
ctx->vertices[0][1][1] = 0.0f; /*t*/
- ctx->vertices[0][1][2] = 0.0f; /*r*/
+ ctx->vertices[0][1][2] = r; /*r*/
ctx->vertices[1][1][0] = 1.0f;
ctx->vertices[1][1][1] = 0.0f;
- ctx->vertices[1][1][2] = 0.0f;
+ ctx->vertices[1][1][2] = r;
ctx->vertices[2][1][0] = 1.0f;
ctx->vertices[2][1][1] = 1.0f;
- ctx->vertices[2][1][2] = 0.0f;
+ ctx->vertices[2][1][2] = r;
ctx->vertices[3][1][0] = 0.0f;
ctx->vertices[3][1][1] = 1.0f;
- ctx->vertices[3][1][2] = 0.0f;
+ ctx->vertices[3][1][2] = r;
}
offset = get_next_slot( ctx );
@@ -1437,9 +1426,11 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
{
struct pipe_context *pipe = ctx->pipe;
- pipe->delete_vs_state(pipe, ctx->vs);
- pipe->delete_fs_state(pipe, ctx->fs2d);
pipe->delete_fs_state(pipe, ctx->fsCube);
+ pipe->delete_fs_state(pipe, ctx->fs3d);
+ pipe->delete_fs_state(pipe, ctx->fs2d);
+ pipe->delete_fs_state(pipe, ctx->fs1d);
+ pipe->delete_vs_state(pipe, ctx->vs);
pipe_resource_reference(&ctx->vbuf, NULL);
@@ -1478,9 +1469,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_screen *screen = pipe->screen;
struct pipe_framebuffer_state fb;
struct pipe_resource *pt = psv->texture;
- void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
+ void *fs;
uint dstLevel;
- uint zslice = 0;
uint offset;
/* The texture object should have room for the levels which we're
@@ -1494,8 +1484,28 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
assert(filter == PIPE_TEX_FILTER_LINEAR ||
filter == PIPE_TEX_FILTER_NEAREST);
+ switch (pt->target) {
+ case PIPE_TEXTURE_1D:
+ fs = ctx->fs1d;
+ break;
+ case PIPE_TEXTURE_2D:
+ fs = ctx->fs2d;
+ break;
+ case PIPE_TEXTURE_3D:
+ fs = ctx->fs3d;
+ break;
+ case PIPE_TEXTURE_CUBE:
+ fs = ctx->fsCube;
+ break;
+ case PIPE_TEXTURE_1D_ARRAY:
+ case PIPE_TEXTURE_2D_ARRAY:
+ default:
+ assert(0);
+ fs = ctx->fs2d;
+ }
+
/* check if we can render in the texture's format */
- if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
+ if (!screen->is_format_supported(screen, psv->format, pt->target,
pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) {
fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
return;
@@ -1539,60 +1549,85 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_viewport_state vp;
-
- struct pipe_surface *surf =
- screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
- PIPE_BIND_RENDER_TARGET);
-
- /*
- * Setup framebuffer / dest surface
- */
- fb.cbufs[0] = surf;
- fb.width = u_minify(pt->width0, dstLevel);
- fb.height = u_minify(pt->height0, dstLevel);
- cso_set_framebuffer(ctx->cso, &fb);
-
- /* viewport */
- vp.scale[0] = 0.5f * fb.width;
- vp.scale[1] = 0.5f * fb.height;
- vp.scale[2] = 1.0f;
- vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * fb.width;
- vp.translate[1] = 0.5f * fb.height;
- vp.translate[2] = 0.0f;
- vp.translate[3] = 0.0f;
- cso_set_viewport(ctx->cso, &vp);
-
- /*
- * Setup sampler state
- * Note: we should only have to set the min/max LOD clamps to ensure
- * we grab texels from the right mipmap level. But some hardware
- * has trouble with min clamping so we also set the lod_bias to
- * try to work around that.
- */
- ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel;
- ctx->sampler.lod_bias = (float) srcLevel;
- cso_single_sampler(ctx->cso, 0, &ctx->sampler);
- cso_single_sampler_done(ctx->cso);
-
- cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
-
- /* quad coords in clip coords */
- offset = set_vertex_data(ctx,
- pt->target,
- face);
-
- util_draw_vertex_buffer(ctx->pipe,
- ctx->vbuf,
- offset,
- PIPE_PRIM_TRIANGLE_FAN,
- 4, /* verts */
- 2); /* attribs/vert */
-
- pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
-
- /* need to signal that the texture has changed _after_ rendering to it */
- pipe_surface_reference( &surf, NULL );
+ unsigned nr_layers, layer, i;
+ float rcoord = 0.0f;
+
+ if (pt->target == PIPE_TEXTURE_3D)
+ nr_layers = u_minify(pt->depth0, dstLevel);
+ else
+ nr_layers = 1;
+
+ for (i = 0; i < nr_layers; i++) {
+ struct pipe_surface *surf, surf_templ;
+ if (pt->target == PIPE_TEXTURE_3D) {
+ /* in theory with geom shaders and driver with full layer support
+ could do that in one go. */
+ layer = i;
+ offset = 1.0f / (float)(nr_layers * 2);
+ /* XXX hmm really? */
+ rcoord = (float)layer / (float)nr_layers + 1.0f / (float)(nr_layers * 2);
+ }
+ else
+ layer = face;
+
+ memset(&surf_templ, 0, sizeof(surf_templ));
+ u_surface_default_template(&surf_templ, pt, PIPE_BIND_RENDER_TARGET);
+ surf_templ.u.tex.level = dstLevel;
+ surf_templ.u.tex.first_layer = layer;
+ surf_templ.u.tex.last_layer = layer;
+ surf = pipe->create_surface(pipe, pt, &surf_templ);
+
+ /*
+ * Setup framebuffer / dest surface
+ */
+ fb.cbufs[0] = surf;
+ fb.width = u_minify(pt->width0, dstLevel);
+ fb.height = u_minify(pt->height0, dstLevel);
+ cso_set_framebuffer(ctx->cso, &fb);
+
+ /* viewport */
+ vp.scale[0] = 0.5f * fb.width;
+ vp.scale[1] = 0.5f * fb.height;
+ vp.scale[2] = 1.0f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * fb.width;
+ vp.translate[1] = 0.5f * fb.height;
+ vp.translate[2] = 0.0f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(ctx->cso, &vp);
+
+ /*
+ * Setup sampler state
+ * Note: we should only have to set the min/max LOD clamps to ensure
+ * we grab texels from the right mipmap level. But some hardware
+ * has trouble with min clamping so we also set the lod_bias to
+ * try to work around that.
+ */
+ ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel;
+ ctx->sampler.lod_bias = (float) srcLevel;
+ cso_single_sampler(ctx->cso, 0, &ctx->sampler);
+ cso_single_sampler_done(ctx->cso);
+
+ cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
+
+ /* quad coords in clip coords */
+ offset = set_vertex_data(ctx,
+ pt->target,
+ face,
+ rcoord);
+
+ util_draw_vertex_buffer(ctx->pipe,
+ ctx->vbuf,
+ offset,
+ PIPE_PRIM_TRIANGLE_FAN,
+ 4, /* verts */
+ 2); /* attribs/vert */
+
+ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+ /* need to signal that the texture has changed _after_ rendering to it */
+ pipe_surface_reference( &surf, NULL );
+ }
}
/* restore state we changed */
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h
index a7502b9982b..a10b6a4aba9 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.h
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.h
@@ -60,7 +60,7 @@ util_gen_mipmap_flush( struct gen_mipmap_state *ctx );
extern void
util_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_sampler_view *psv,
- uint face, uint baseLevel, uint lastLevel, uint filter);
+ uint layer, uint baseLevel, uint lastLevel, uint filter);
#ifdef __cplusplus
diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index 6ed39561fbe..e55aafe90f0 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -109,7 +109,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
if (pipe_reference_described(&(*ptr)->reference, &surf->reference,
(debug_reference_descriptor)debug_describe_surface))
- old_surf->texture->screen->tex_surface_destroy(old_surf);
+ old_surf->context->surface_destroy(old_surf->context, old_surf);
*ptr = surf;
}
@@ -136,26 +136,28 @@ pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_
}
static INLINE void
-pipe_surface_reset(struct pipe_surface* ps, struct pipe_resource *pt,
- unsigned face, unsigned level, unsigned zslice, unsigned flags)
+pipe_surface_reset(struct pipe_context *ctx, struct pipe_surface* ps,
+ struct pipe_resource *pt, unsigned level, unsigned layer,
+ unsigned flags)
{
pipe_resource_reference(&ps->texture, pt);
ps->format = pt->format;
ps->width = u_minify(pt->width0, level);
ps->height = u_minify(pt->height0, level);
ps->usage = flags;
- ps->face = face;
- ps->level = level;
- ps->zslice = zslice;
+ ps->u.tex.level = level;
+ ps->u.tex.first_layer = ps->u.tex.last_layer = layer;
+ ps->context = ctx;
}
static INLINE void
-pipe_surface_init(struct pipe_surface* ps, struct pipe_resource *pt,
- unsigned face, unsigned level, unsigned zslice, unsigned flags)
+pipe_surface_init(struct pipe_context *ctx, struct pipe_surface* ps,
+ struct pipe_resource *pt, unsigned level, unsigned layer,
+ unsigned flags)
{
ps->texture = 0;
pipe_reference_init(&ps->reference, 1);
- pipe_surface_reset(ps, pt, face, level, zslice, flags);
+ pipe_surface_reset(ctx, ps, pt, level, layer, flags);
}
/*
@@ -177,6 +179,7 @@ pipe_buffer_create( struct pipe_screen *screen,
buffer.width0 = size;
buffer.height0 = 1;
buffer.depth0 = 1;
+ buffer.array_size = 1;
return screen->resource_create(screen, &buffer);
}
@@ -202,15 +205,15 @@ pipe_buffer_map_range(struct pipe_context *pipe,
assert(offset < buffer->width0);
assert(offset + length <= buffer->width0);
assert(length);
-
+
u_box_1d(offset, length, &box);
*transfer = pipe->get_transfer( pipe,
- buffer,
- u_subresource(0, 0),
- usage,
- &box);
-
+ buffer,
+ 0,
+ usage,
+ &box);
+
if (*transfer == NULL)
return NULL;
@@ -231,7 +234,7 @@ static INLINE void *
pipe_buffer_map(struct pipe_context *pipe,
struct pipe_resource *buffer,
unsigned usage,
- struct pipe_transfer **transfer)
+ struct pipe_transfer **transfer)
{
return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, transfer);
}
@@ -240,7 +243,7 @@ pipe_buffer_map(struct pipe_context *pipe,
static INLINE void
pipe_buffer_unmap(struct pipe_context *pipe,
struct pipe_resource *buf,
- struct pipe_transfer *transfer)
+ struct pipe_transfer *transfer)
{
if (transfer) {
pipe->transfer_unmap(pipe, transfer);
@@ -250,7 +253,7 @@ pipe_buffer_unmap(struct pipe_context *pipe,
static INLINE void
pipe_buffer_flush_mapped_range(struct pipe_context *pipe,
- struct pipe_transfer *transfer,
+ struct pipe_transfer *transfer,
unsigned offset,
unsigned length)
{
@@ -266,7 +269,7 @@ pipe_buffer_flush_mapped_range(struct pipe_context *pipe,
* mapped range.
*/
transfer_offset = offset - transfer->box.x;
-
+
u_box_1d(transfer_offset, length, &box);
pipe->transfer_flush_region(pipe, transfer, &box);
@@ -276,7 +279,7 @@ static INLINE void
pipe_buffer_write(struct pipe_context *pipe,
struct pipe_resource *buf,
unsigned offset,
- unsigned size,
+ unsigned size,
const void *data)
{
struct pipe_box box;
@@ -284,13 +287,13 @@ pipe_buffer_write(struct pipe_context *pipe,
u_box_1d(offset, size, &box);
pipe->transfer_inline_write( pipe,
- buf,
- u_subresource(0,0),
- PIPE_TRANSFER_WRITE,
- &box,
- data,
- size,
- 0);
+ buf,
+ 0,
+ PIPE_TRANSFER_WRITE,
+ &box,
+ data,
+ size,
+ 0);
}
/**
@@ -309,21 +312,21 @@ pipe_buffer_write_nooverlap(struct pipe_context *pipe,
u_box_1d(offset, size, &box);
- pipe->transfer_inline_write(pipe,
- buf,
- u_subresource(0,0),
- (PIPE_TRANSFER_WRITE |
- PIPE_TRANSFER_NOOVERWRITE),
- &box,
- data,
- 0, 0);
+ pipe->transfer_inline_write(pipe,
+ buf,
+ 0,
+ (PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_NOOVERWRITE),
+ &box,
+ data,
+ 0, 0);
}
static INLINE void
pipe_buffer_read(struct pipe_context *pipe,
struct pipe_resource *buf,
unsigned offset,
- unsigned size,
+ unsigned size,
void *data)
{
struct pipe_transfer *src_transfer;
@@ -343,20 +346,19 @@ pipe_buffer_read(struct pipe_context *pipe,
static INLINE struct pipe_transfer *
pipe_get_transfer( struct pipe_context *context,
- struct pipe_resource *resource,
- unsigned face, unsigned level,
- unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y,
- unsigned w, unsigned h)
+ struct pipe_resource *resource,
+ unsigned level, unsigned layer,
+ enum pipe_transfer_usage usage,
+ unsigned x, unsigned y,
+ unsigned w, unsigned h)
{
struct pipe_box box;
- u_box_2d_zslice( x, y, zslice, w, h, &box );
+ u_box_2d_zslice( x, y, layer, w, h, &box );
return context->get_transfer( context,
- resource,
- u_subresource(face, level),
- usage,
- &box );
+ resource,
+ level,
+ usage,
+ &box );
}
static INLINE void *
@@ -376,7 +378,7 @@ pipe_transfer_unmap( struct pipe_context *context,
static INLINE void
pipe_transfer_destroy( struct pipe_context *context,
- struct pipe_transfer *transfer )
+ struct pipe_transfer *transfer )
{
context->transfer_destroy(context, transfer);
}
diff --git a/src/gallium/auxiliary/util/u_resource.c b/src/gallium/auxiliary/util/u_resource.c
index 9e6474b83de..443c9f8067e 100644
--- a/src/gallium/auxiliary/util/u_resource.c
+++ b/src/gallium/auxiliary/util/u_resource.c
@@ -10,85 +10,85 @@ u_resource( struct pipe_resource *res )
}
boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource,
- struct winsys_handle *handle)
+ struct pipe_resource *resource,
+ struct winsys_handle *handle)
{
struct u_resource *ur = u_resource(resource);
return ur->vtbl->resource_get_handle(screen, resource, handle);
}
void u_resource_destroy_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource)
+ struct pipe_resource *resource)
{
struct u_resource *ur = u_resource(resource);
ur->vtbl->resource_destroy(screen, resource);
}
unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned face, unsigned level)
+ struct pipe_resource *resource,
+ unsigned level, int layer)
{
struct u_resource *ur = u_resource(resource);
- return ur->vtbl->is_resource_referenced(pipe, resource, face, level);
+ return ur->vtbl->is_resource_referenced(pipe, resource, level, layer);
}
struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- enum pipe_transfer_usage usage,
- const struct pipe_box *box)
+ struct pipe_resource *resource,
+ unsigned level,
+ enum pipe_transfer_usage usage,
+ const struct pipe_box *box)
{
struct u_resource *ur = u_resource(resource);
- return ur->vtbl->get_transfer(context, resource, sr, usage, box);
+ return ur->vtbl->get_transfer(context, resource, level, usage, box);
}
void u_transfer_destroy_vtbl(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+ struct pipe_transfer *transfer)
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_destroy(pipe, transfer);
}
void *u_transfer_map_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
+ struct pipe_transfer *transfer )
{
struct u_resource *ur = u_resource(transfer->resource);
return ur->vtbl->transfer_map(pipe, transfer);
}
void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box)
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_flush_region(pipe, transfer, box);
}
void u_transfer_unmap_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
+ struct pipe_transfer *transfer )
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_unmap(pipe, transfer);
}
void u_transfer_inline_write_vtbl( struct pipe_context *pipe,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned slice_stride)
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride)
{
struct u_resource *ur = u_resource(resource);
- ur->vtbl->transfer_inline_write(pipe,
- resource,
- sr,
- usage,
- box,
- data,
- stride,
- slice_stride);
+ ur->vtbl->transfer_inline_write(pipe,
+ resource,
+ level,
+ usage,
+ box,
+ data,
+ stride,
+ layer_stride);
}
diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c
index e77f562ea22..bb26099b7e1 100644
--- a/src/gallium/auxiliary/util/u_sampler.c
+++ b/src/gallium/auxiliary/util/u_sampler.c
@@ -40,8 +40,11 @@ default_template(struct pipe_sampler_view *view,
*/
view->format = format;
- view->first_level = 0;
- view->last_level = texture->last_level;
+ view->u.tex.first_level = 0;
+ view->u.tex.last_level = texture->last_level;
+ view->u.tex.first_layer = 0;
+ view->u.tex.last_layer = texture->target == PIPE_TEXTURE_3D ?
+ texture->depth0 - 1 : texture->array_size - 1;
view->swizzle_r = PIPE_SWIZZLE_RED;
view->swizzle_g = PIPE_SWIZZLE_GREEN;
view->swizzle_b = PIPE_SWIZZLE_BLUE;
diff --git a/src/gallium/auxiliary/util/u_simple_screen.h b/src/gallium/auxiliary/util/u_simple_screen.h
index b52232f025c..7139aaabc56 100644
--- a/src/gallium/auxiliary/util/u_simple_screen.h
+++ b/src/gallium/auxiliary/util/u_simple_screen.h
@@ -57,7 +57,8 @@ struct pipe_winsys
* displayed, eg copy fake frontbuffer.
*/
void (*flush_frontbuffer)( struct pipe_winsys *ws,
- struct pipe_surface *surf,
+ struct pipe_resource *resource,
+ unsigned level, unsigned layer,
void *context_private );
diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c
index 58ef68377fc..b0f2dd8aa29 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.c
+++ b/src/gallium/auxiliary/util/u_simple_shaders.c
@@ -204,7 +204,8 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
void *
util_make_fragment_passthrough_shader(struct pipe_context *pipe)
{
- return util_make_fragment_clonecolor_shader(pipe, 1);
+ return util_make_fragment_cloneinput_shader(pipe, 1, TGSI_SEMANTIC_COLOR,
+ TGSI_INTERPOLATE_PERSPECTIVE);
}
@@ -212,7 +213,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe)
* Make a fragment shader that copies the input color to N output colors.
*/
void *
-util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
+util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
+ int input_semantic,
+ int input_interpolate)
{
struct ureg_program *ureg;
struct ureg_src src;
@@ -225,8 +228,8 @@ util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
if (ureg == NULL)
return NULL;
- src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0,
- TGSI_INTERPOLATE_PERSPECTIVE );
+ src = ureg_DECL_fs_input( ureg, input_semantic, 0,
+ input_interpolate );
for (i = 0; i < num_cbufs; i++)
dst[i] = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, i );
diff --git a/src/gallium/auxiliary/util/u_simple_shaders.h b/src/gallium/auxiliary/util/u_simple_shaders.h
index 4aa34bc4757..1bfec183e34 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.h
+++ b/src/gallium/auxiliary/util/u_simple_shaders.h
@@ -71,7 +71,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe);
extern void *
-util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs);
+util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
+ int input_semantic,
+ int input_interpolate);
#ifdef __cplusplus
}
diff --git a/src/gallium/auxiliary/util/u_mempool.c b/src/gallium/auxiliary/util/u_slab.c
index 1f336b39a1a..21bf2d735ac 100644
--- a/src/gallium/auxiliary/util/u_mempool.c
+++ b/src/gallium/auxiliary/util/u_slab.c
@@ -20,7 +20,7 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
-#include "util/u_mempool.h"
+#include "util/u_slab.h"
#include "util/u_math.h"
#include "util/u_memory.h"
@@ -28,13 +28,13 @@
#include <stdio.h>
-#define UTIL_MEMPOOL_MAGIC 0xcafe4321
+#define UTIL_SLAB_MAGIC 0xcafe4321
/* The block is either allocated memory or free space. */
-struct util_mempool_block {
+struct util_slab_block {
/* The header. */
/* The first next free block. */
- struct util_mempool_block *next_free;
+ struct util_slab_block *next_free;
intptr_t magic;
@@ -42,19 +42,19 @@ struct util_mempool_block {
* The allocated size is always larger than this structure. */
};
-static struct util_mempool_block *
-util_mempool_get_block(struct util_mempool *pool,
- struct util_mempool_page *page, unsigned index)
+static struct util_slab_block *
+util_slab_get_block(struct util_slab_mempool *pool,
+ struct util_slab_page *page, unsigned index)
{
- return (struct util_mempool_block*)
- ((uint8_t*)page + sizeof(struct util_mempool_page) +
+ return (struct util_slab_block*)
+ ((uint8_t*)page + sizeof(struct util_slab_page) +
(pool->block_size * index));
}
-static void util_mempool_add_new_page(struct util_mempool *pool)
+static void util_slab_add_new_page(struct util_slab_mempool *pool)
{
- struct util_mempool_page *page;
- struct util_mempool_block *block;
+ struct util_slab_page *page;
+ struct util_slab_block *block;
int i;
page = MALLOC(pool->page_size);
@@ -62,15 +62,15 @@ static void util_mempool_add_new_page(struct util_mempool *pool)
/* Mark all blocks as free. */
for (i = 0; i < pool->num_blocks-1; i++) {
- block = util_mempool_get_block(pool, page, i);
- block->next_free = util_mempool_get_block(pool, page, i+1);
- block->magic = UTIL_MEMPOOL_MAGIC;
+ block = util_slab_get_block(pool, page, i);
+ block->next_free = util_slab_get_block(pool, page, i+1);
+ block->magic = UTIL_SLAB_MAGIC;
}
- block = util_mempool_get_block(pool, page, pool->num_blocks-1);
+ block = util_slab_get_block(pool, page, pool->num_blocks-1);
block->next_free = pool->first_free;
- block->magic = UTIL_MEMPOOL_MAGIC;
- pool->first_free = util_mempool_get_block(pool, page, 0);
+ block->magic = UTIL_SLAB_MAGIC;
+ pool->first_free = util_slab_get_block(pool, page, 0);
pool->num_pages++;
#if 0
@@ -78,74 +78,74 @@ static void util_mempool_add_new_page(struct util_mempool *pool)
#endif
}
-static void *util_mempool_malloc_st(struct util_mempool *pool)
+static void *util_slab_alloc_st(struct util_slab_mempool *pool)
{
- struct util_mempool_block *block;
+ struct util_slab_block *block;
if (!pool->first_free)
- util_mempool_add_new_page(pool);
+ util_slab_add_new_page(pool);
block = pool->first_free;
- assert(block->magic == UTIL_MEMPOOL_MAGIC);
+ assert(block->magic == UTIL_SLAB_MAGIC);
pool->first_free = block->next_free;
- return (uint8_t*)block + sizeof(struct util_mempool_block);
+ return (uint8_t*)block + sizeof(struct util_slab_block);
}
-static void util_mempool_free_st(struct util_mempool *pool, void *ptr)
+static void util_slab_free_st(struct util_slab_mempool *pool, void *ptr)
{
- struct util_mempool_block *block =
- (struct util_mempool_block*)
- ((uint8_t*)ptr - sizeof(struct util_mempool_block));
+ struct util_slab_block *block =
+ (struct util_slab_block*)
+ ((uint8_t*)ptr - sizeof(struct util_slab_block));
- assert(block->magic == UTIL_MEMPOOL_MAGIC);
+ assert(block->magic == UTIL_SLAB_MAGIC);
block->next_free = pool->first_free;
pool->first_free = block;
}
-static void *util_mempool_malloc_mt(struct util_mempool *pool)
+static void *util_slab_alloc_mt(struct util_slab_mempool *pool)
{
void *mem;
pipe_mutex_lock(pool->mutex);
- mem = util_mempool_malloc_st(pool);
+ mem = util_slab_alloc_st(pool);
pipe_mutex_unlock(pool->mutex);
return mem;
}
-static void util_mempool_free_mt(struct util_mempool *pool, void *ptr)
+static void util_slab_free_mt(struct util_slab_mempool *pool, void *ptr)
{
pipe_mutex_lock(pool->mutex);
- util_mempool_free_st(pool, ptr);
+ util_slab_free_st(pool, ptr);
pipe_mutex_unlock(pool->mutex);
}
-void util_mempool_set_thread_safety(struct util_mempool *pool,
- enum util_mempool_threading threading)
+void util_slab_set_thread_safety(struct util_slab_mempool *pool,
+ enum util_slab_threading threading)
{
pool->threading = threading;
if (threading) {
- pool->malloc = util_mempool_malloc_mt;
- pool->free = util_mempool_free_mt;
+ pool->alloc = util_slab_alloc_mt;
+ pool->free = util_slab_free_mt;
} else {
- pool->malloc = util_mempool_malloc_st;
- pool->free = util_mempool_free_st;
+ pool->alloc = util_slab_alloc_st;
+ pool->free = util_slab_free_st;
}
}
-void util_mempool_create(struct util_mempool *pool,
- unsigned item_size,
- unsigned num_blocks,
- enum util_mempool_threading threading)
+void util_slab_create(struct util_slab_mempool *pool,
+ unsigned item_size,
+ unsigned num_blocks,
+ enum util_slab_threading threading)
{
item_size = align(item_size, sizeof(intptr_t));
pool->num_pages = 0;
pool->num_blocks = num_blocks;
- pool->block_size = sizeof(struct util_mempool_block) + item_size;
+ pool->block_size = sizeof(struct util_slab_block) + item_size;
pool->block_size = align(pool->block_size, sizeof(intptr_t));
- pool->page_size = sizeof(struct util_mempool_page) +
+ pool->page_size = sizeof(struct util_slab_page) +
num_blocks * pool->block_size;
pool->first_free = NULL;
@@ -153,12 +153,12 @@ void util_mempool_create(struct util_mempool *pool,
pipe_mutex_init(pool->mutex);
- util_mempool_set_thread_safety(pool, threading);
+ util_slab_set_thread_safety(pool, threading);
}
-void util_mempool_destroy(struct util_mempool *pool)
+void util_slab_destroy(struct util_slab_mempool *pool)
{
- struct util_mempool_page *page, *temp;
+ struct util_slab_page *page, *temp;
foreach_s(page, temp, &pool->list) {
remove_from_list(page);
diff --git a/src/gallium/auxiliary/util/u_mempool.h b/src/gallium/auxiliary/util/u_slab.h
index a5b5d6a9b7c..6b9718d08a7 100644
--- a/src/gallium/auxiliary/util/u_mempool.h
+++ b/src/gallium/auxiliary/util/u_slab.h
@@ -22,66 +22,66 @@
/**
* @file
- * Simple memory pool for equally sized memory allocations.
- * util_mempool_malloc and util_mempool_free are in O(1).
+ * Simple slab allocator for equally sized memory allocations.
+ * util_slab_alloc and util_slab_free have time complexity in O(1).
*
* Good for allocations which have very low lifetime and are allocated
- * and freed very often. Use a profiler first!
+ * and freed very often. Use a profiler first to know if it's worth using it!
*
* Candidates: get_transfer, user_buffer_create
*
* @author Marek Olšák
*/
-#ifndef U_MEMPOOL_H
-#define U_MEMPOOL_H
+#ifndef U_SLAB_H
+#define U_SLAB_H
#include "os/os_thread.h"
-enum util_mempool_threading {
- UTIL_MEMPOOL_SINGLETHREADED = FALSE,
- UTIL_MEMPOOL_MULTITHREADED = TRUE
+enum util_slab_threading {
+ UTIL_SLAB_SINGLETHREADED = FALSE,
+ UTIL_SLAB_MULTITHREADED = TRUE
};
/* The page is an array of blocks (allocations). */
-struct util_mempool_page {
+struct util_slab_page {
/* The header (linked-list pointers). */
- struct util_mempool_page *prev, *next;
+ struct util_slab_page *prev, *next;
/* Memory after the last member is dedicated to the page itself.
* The allocated size is always larger than this structure. */
};
-struct util_mempool {
+struct util_slab_mempool {
/* Public members. */
- void *(*malloc)(struct util_mempool *pool);
- void (*free)(struct util_mempool *pool, void *ptr);
+ void *(*alloc)(struct util_slab_mempool *pool);
+ void (*free)(struct util_slab_mempool *pool, void *ptr);
/* Private members. */
- struct util_mempool_block *first_free;
+ struct util_slab_block *first_free;
- struct util_mempool_page list;
+ struct util_slab_page list;
unsigned block_size;
unsigned page_size;
unsigned num_blocks;
unsigned num_pages;
- enum util_mempool_threading threading;
+ enum util_slab_threading threading;
pipe_mutex mutex;
};
-void util_mempool_create(struct util_mempool *pool,
- unsigned item_size,
- unsigned num_blocks,
- enum util_mempool_threading threading);
+void util_slab_create(struct util_slab_mempool *pool,
+ unsigned item_size,
+ unsigned num_blocks,
+ enum util_slab_threading threading);
-void util_mempool_destroy(struct util_mempool *pool);
+void util_slab_destroy(struct util_slab_mempool *pool);
-void util_mempool_set_thread_safety(struct util_mempool *pool,
- enum util_mempool_threading threading);
+void util_slab_set_thread_safety(struct util_slab_mempool *pool,
+ enum util_slab_threading threading);
-#define util_mempool_malloc(pool) (pool)->malloc(pool)
-#define util_mempool_free(pool, ptr) (pool)->free(pool, ptr)
+#define util_slab_alloc(pool) (pool)->alloc(pool)
+#define util_slab_free(pool, ptr) (pool)->free(pool, ptr)
#endif
diff --git a/src/gallium/auxiliary/util/u_staging.c b/src/gallium/auxiliary/util/u_staging.c
index c5d68f8df86..b6bf241a22a 100644
--- a/src/gallium/auxiliary/util/u_staging.c
+++ b/src/gallium/auxiliary/util/u_staging.c
@@ -41,6 +41,7 @@ util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigne
template->width0 = width;
template->height0 = height;
template->depth0 = depth;
+ template->array_size = 1;
template->last_level = 0;
template->nr_samples = pt->nr_samples;
template->bind = 0;
@@ -51,7 +52,7 @@ util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigne
struct util_staging_transfer *
util_staging_transfer_init(struct pipe_context *pipe,
struct pipe_resource *pt,
- struct pipe_subresource sr,
+ unsigned level,
unsigned usage,
const struct pipe_box *box,
bool direct, struct util_staging_transfer *tx)
@@ -61,7 +62,7 @@ util_staging_transfer_init(struct pipe_context *pipe,
struct pipe_resource staging_resource_template;
pipe_resource_reference(&tx->base.resource, pt);
- tx->base.sr = sr;
+ tx->base.level = level;
tx->base.usage = usage;
tx->base.box = *box;
@@ -82,12 +83,20 @@ util_staging_transfer_init(struct pipe_context *pipe,
if (usage & PIPE_TRANSFER_READ)
{
- struct pipe_subresource dstsr;
+ /* XXX this looks wrong dst is always the same but looping over src z? */
unsigned zi;
- dstsr.face = 0;
- dstsr.level = 0;
- for(zi = 0; zi < box->depth; ++zi)
- pipe->resource_copy_region(pipe, tx->staging_resource, dstsr, 0, 0, 0, tx->base.resource, sr, box->x, box->y, box->z + zi, box->width, box->height);
+ struct pipe_box sbox;
+ sbox.x = box->x;
+ sbox.y = box->y;
+ sbox.z = box->z;
+ sbox.width = box->width;
+ sbox.height = box->height;
+ sbox.depth = 1;
+ for(zi = 0; zi < box->depth; ++zi) {
+ sbox.z = sbox.z + zi;
+ pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0,
+ tx->base.resource, level, &sbox);
+ }
}
return tx;
@@ -101,12 +110,18 @@ util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *p
if (tx->staging_resource != tx->base.resource)
{
if(tx->base.usage & PIPE_TRANSFER_WRITE) {
- struct pipe_subresource srcsr;
+ /* XXX this looks wrong src is always the same but looping over dst z? */
unsigned zi;
- srcsr.face = 0;
- srcsr.level = 0;
+ struct pipe_box sbox;
+ sbox.x = 0;
+ sbox.y = 0;
+ sbox.z = 0;
+ sbox.width = tx->base.box.width;
+ sbox.height = tx->base.box.height;
+ sbox.depth = 1;
for(zi = 0; zi < tx->base.box.depth; ++zi)
- pipe->resource_copy_region(pipe, tx->base.resource, tx->base.sr, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi, tx->staging_resource, srcsr, 0, 0, 0, tx->base.box.width, tx->base.box.height);
+ pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi,
+ tx->staging_resource, 0, &sbox);
}
pipe_resource_reference(&tx->staging_resource, NULL);
diff --git a/src/gallium/auxiliary/util/u_staging.h b/src/gallium/auxiliary/util/u_staging.h
index 1aab78cc881..49839d25439 100644
--- a/src/gallium/auxiliary/util/u_staging.h
+++ b/src/gallium/auxiliary/util/u_staging.h
@@ -52,7 +52,7 @@ struct util_staging_transfer {
struct util_staging_transfer *
util_staging_transfer_init(struct pipe_context *pipe,
struct pipe_resource *pt,
- struct pipe_subresource sr,
+ unsigned level,
unsigned usage,
const struct pipe_box *box,
bool direct, struct util_staging_transfer *tx);
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index f78b6838a72..4eddd3f519e 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -42,6 +42,18 @@
#include "util/u_surface.h"
#include "util/u_pack_color.h"
+void
+u_surface_default_template(struct pipe_surface *view,
+ const struct pipe_resource *texture,
+ unsigned bind)
+{
+ view->format = texture->format;
+ view->u.tex.level = 0;
+ view->u.tex.first_layer = 0;
+ view->u.tex.last_layer = 0;
+ /* XXX should filter out all non-rt/ds bind flags ? */
+ view->usage = bind;
+}
/**
* Helper to quickly create an RGBA rendering surface of a certain size.
@@ -50,9 +62,9 @@
* \return TRUE for success, FALSE if failure
*/
boolean
-util_create_rgba_surface(struct pipe_screen *screen,
+util_create_rgba_surface(struct pipe_context *pipe,
uint width, uint height,
- uint bind,
+ uint bind,
struct pipe_resource **textureOut,
struct pipe_surface **surfaceOut)
{
@@ -65,6 +77,8 @@ util_create_rgba_surface(struct pipe_screen *screen,
const uint target = PIPE_TEXTURE_2D;
enum pipe_format format = PIPE_FORMAT_NONE;
struct pipe_resource templ;
+ struct pipe_surface surf_templ;
+ struct pipe_screen *screen = pipe->screen;
uint i;
/* Choose surface format */
@@ -86,17 +100,20 @@ util_create_rgba_surface(struct pipe_screen *screen,
templ.width0 = width;
templ.height0 = height;
templ.depth0 = 1;
+ templ.array_size = 1;
templ.bind = bind;
*textureOut = screen->resource_create(screen, &templ);
if (!*textureOut)
return FALSE;
+ /* create surface */
+ memset(&surf_templ, 0, sizeof(surf_templ));
+ u_surface_default_template(&surf_templ, *textureOut, bind);
/* create surface / view into texture */
- *surfaceOut = screen->get_tex_surface(screen,
- *textureOut,
- 0, 0, 0,
- bind);
+ *surfaceOut = pipe->create_surface(pipe,
+ *textureOut,
+ &surf_templ);
if (!*surfaceOut) {
pipe_resource_reference(textureOut, NULL);
return FALSE;
@@ -126,17 +143,18 @@ util_destroy_rgba_surface(struct pipe_resource *texture,
void
util_resource_copy_region(struct pipe_context *pipe,
struct pipe_resource *dst,
- struct pipe_subresource subdst,
+ unsigned dst_level,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
- unsigned src_x, unsigned src_y, unsigned src_z,
- unsigned w, unsigned h)
+ unsigned src_level,
+ const struct pipe_box *src_box)
{
struct pipe_transfer *src_trans, *dst_trans;
void *dst_map;
const void *src_map;
enum pipe_format src_format, dst_format;
+ unsigned w = src_box->width;
+ unsigned h = src_box->height;
assert(src && dst);
if (!src || !dst)
@@ -146,20 +164,18 @@ util_resource_copy_region(struct pipe_context *pipe,
dst_format = dst->format;
src_trans = pipe_get_transfer(pipe,
- src,
- subsrc.face,
- subsrc.level,
- src_z,
- PIPE_TRANSFER_READ,
- src_x, src_y, w, h);
+ src,
+ src_level,
+ src_box->z,
+ PIPE_TRANSFER_READ,
+ src_box->x, src_box->y, w, h);
dst_trans = pipe_get_transfer(pipe,
- dst,
- subdst.face,
- subdst.level,
- src_z,
- PIPE_TRANSFER_WRITE,
- dst_x, dst_y, w, h);
+ dst,
+ dst_level,
+ dst_z,
+ PIPE_TRANSFER_WRITE,
+ dst_x, dst_y, w, h);
assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format));
assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format));
@@ -216,14 +232,13 @@ util_clear_render_target(struct pipe_context *pipe,
assert(dst->texture);
if (!dst->texture)
return;
-
+ /* XXX: should handle multiple layers */
dst_trans = pipe_get_transfer(pipe,
- dst->texture,
- dst->face,
- dst->level,
- dst->zslice,
- PIPE_TRANSFER_WRITE,
- dstx, dsty, width, height);
+ dst->texture,
+ dst->u.tex.level,
+ dst->u.tex.first_layer,
+ PIPE_TRANSFER_WRITE,
+ dstx, dsty, width, height);
dst_map = pipe->transfer_map(pipe, dst_trans);
@@ -271,9 +286,8 @@ util_clear_depth_stencil(struct pipe_context *pipe,
return;
dst_trans = pipe_get_transfer(pipe,
dst->texture,
- dst->face,
- dst->level,
- dst->zslice,
+ dst->u.tex.level,
+ dst->u.tex.first_layer,
(need_rmw ? PIPE_TRANSFER_READ_WRITE :
PIPE_TRANSFER_WRITE),
dstx, dsty, width, height);
diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h
index 6cd12af3a8b..6a7cc82b055 100644
--- a/src/gallium/auxiliary/util/u_surface.h
+++ b/src/gallium/auxiliary/util/u_surface.h
@@ -33,8 +33,18 @@
#include "pipe/p_state.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern void
+u_surface_default_template(struct pipe_surface *view,
+ const struct pipe_resource *texture,
+ unsigned bind);
+
extern boolean
-util_create_rgba_surface(struct pipe_screen *screen,
+util_create_rgba_surface(struct pipe_context *ctx,
uint width, uint height, uint bind,
struct pipe_resource **textureOut,
struct pipe_surface **surfaceOut);
@@ -49,12 +59,11 @@ util_destroy_rgba_surface(struct pipe_resource *texture,
extern void
util_resource_copy_region(struct pipe_context *pipe,
struct pipe_resource *dst,
- struct pipe_subresource subdst,
+ unsigned dst_level,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
struct pipe_resource *src,
- struct pipe_subresource subsrc,
- unsigned src_x, unsigned src_y, unsigned src_z,
- unsigned w, unsigned h);
+ unsigned src_level,
+ const struct pipe_box *src_box);
extern void
util_clear_render_target(struct pipe_context *pipe,
@@ -73,4 +82,9 @@ util_clear_depth_stencil(struct pipe_context *pipe,
unsigned width, unsigned height);
+#ifdef __cplusplus
+}
+#endif
+
+
#endif /* U_SURFACE_H */
diff --git a/src/gallium/auxiliary/util/u_surfaces.c b/src/gallium/auxiliary/util/u_surfaces.c
index 404e1219952..b0cfec2a826 100644
--- a/src/gallium/auxiliary/util/u_surfaces.c
+++ b/src/gallium/auxiliary/util/u_surfaces.c
@@ -29,8 +29,11 @@
#include "util/u_inlines.h"
#include "util/u_memory.h"
-struct pipe_surface *
-util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags)
+boolean
+util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size,
+ struct pipe_context *ctx, struct pipe_resource *pt,
+ unsigned level, unsigned layer, unsigned flags,
+ struct pipe_surface **res)
{
struct pipe_surface *ps;
@@ -39,7 +42,7 @@ util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, str
if(!us->u.hash)
us->u.hash = cso_hash_create();
- ps = cso_hash_iter_data(cso_hash_find(us->u.hash, ((zslice + face) << 8) | level));
+ ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
}
else
{
@@ -48,25 +51,29 @@ util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, str
ps = us->u.array[level];
}
- if(ps)
+ if(ps && ps->context == ctx)
{
p_atomic_inc(&ps->reference.count);
- return ps;
+ *res = ps;
+ return FALSE;
}
ps = (struct pipe_surface *)CALLOC(1, surface_struct_size);
if(!ps)
- return NULL;
+ {
+ *res = NULL;
+ return FALSE;
+ }
- pipe_surface_init(ps, pt, face, level, zslice, flags);
- ps->offset = ~0;
+ pipe_surface_init(ctx, ps, pt, level, layer, flags);
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- cso_hash_insert(us->u.hash, ((zslice + face) << 8) | level, ps);
+ cso_hash_insert(us->u.hash, (layer << 8) | level, ps);
else
us->u.array[level] = ps;
- return ps;
+ *res = ps;
+ return TRUE;
}
void
@@ -75,10 +82,10 @@ util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps)
struct pipe_resource *pt = ps->texture;
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
- cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, ((ps->zslice + ps->face) << 8) | ps->level));
+ cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level));
}
else
- us->u.array[ps->level] = 0;
+ us->u.array[ps->u.tex.level] = 0;
}
void
diff --git a/src/gallium/auxiliary/util/u_surfaces.h b/src/gallium/auxiliary/util/u_surfaces.h
index 17d8a5d3a5b..9581feda7c8 100644
--- a/src/gallium/auxiliary/util/u_surfaces.h
+++ b/src/gallium/auxiliary/util/u_surfaces.h
@@ -42,33 +42,42 @@ struct util_surfaces
} u;
};
-struct pipe_surface *util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags);
+/* Return value indicates if the pipe surface result is new */
+boolean
+util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size,
+ struct pipe_context *ctx, struct pipe_resource *pt,
+ unsigned level, unsigned layer, unsigned flags,
+ struct pipe_surface **res);
/* fast inline path for the very common case */
-static INLINE struct pipe_surface *
-util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags)
+static INLINE boolean
+util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size,
+ struct pipe_context *ctx, struct pipe_resource *pt,
+ unsigned level, unsigned layer, unsigned flags,
+ struct pipe_surface **res)
{
if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array))
{
struct pipe_surface *ps = us->u.array[level];
- if(ps)
+ if(ps && ps->context == ctx)
{
p_atomic_inc(&ps->reference.count);
- return ps;
+ *res = ps;
+ return FALSE;
}
}
- return util_surfaces_do_get(us, surface_struct_size, pscreen, pt, face, level, zslice, flags);
+ return util_surfaces_do_get(us, surface_struct_size, ctx, pt, level, layer, flags, res);
}
static INLINE struct pipe_surface *
-util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice)
+util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned level, unsigned layer)
{
if(!us->u.pv)
return 0;
if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE))
- return cso_hash_iter_data(cso_hash_find(us->u.hash, ((zslice + face) << 8) | level));
+ return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
else
return us->u.array[level];
}
@@ -80,7 +89,7 @@ util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps)
{
if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT))
{
- us->u.array[ps->level] = 0;
+ us->u.array[ps->u.tex.level] = 0;
return;
}
diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c
index 69f6fab9504..e2828cfd99e 100644
--- a/src/gallium/auxiliary/util/u_transfer.c
+++ b/src/gallium/auxiliary/util/u_transfer.c
@@ -8,22 +8,24 @@
* pointer. XXX: strides??
*/
void u_default_transfer_inline_write( struct pipe_context *pipe,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned slice_stride)
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride)
{
struct pipe_transfer *transfer = NULL;
uint8_t *map = NULL;
-
- transfer = pipe->get_transfer(pipe,
- resource,
- sr,
- usage,
- box );
+ const uint8_t *src_data = data;
+ unsigned i;
+
+ transfer = pipe->get_transfer(pipe,
+ resource,
+ level,
+ usage,
+ box );
if (transfer == NULL)
goto out;
@@ -31,17 +33,19 @@ void u_default_transfer_inline_write( struct pipe_context *pipe,
if (map == NULL)
goto out;
- assert(box->depth == 1); /* XXX: fix me */
-
- util_copy_rect(map,
- resource->format,
- transfer->stride, /* bytes */
- 0, 0,
- box->width,
- box->height,
- data,
- stride, /* bytes */
- 0, 0);
+ for (i = 0; i < box->depth; i++) {
+ util_copy_rect(map,
+ resource->format,
+ transfer->stride, /* bytes */
+ 0, 0,
+ box->width,
+ box->height,
+ src_data,
+ stride, /* bytes */
+ 0, 0);
+ map += transfer->layer_stride;
+ src_data += layer_stride;
+ }
out:
if (map)
@@ -53,8 +57,8 @@ out:
boolean u_default_resource_get_handle(struct pipe_screen *screen,
- struct pipe_resource *resource,
- struct winsys_handle *handle)
+ struct pipe_resource *resource,
+ struct winsys_handle *handle)
{
return FALSE;
}
@@ -62,32 +66,32 @@ boolean u_default_resource_get_handle(struct pipe_screen *screen,
void u_default_transfer_flush_region( struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box)
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
{
/* This is a no-op implementation, nothing to do.
*/
}
unsigned u_default_is_resource_referenced( struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned face, unsigned level)
+ struct pipe_resource *resource,
+ unsigned level, int layer)
{
return 0;
}
struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box)
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer);
if (transfer == NULL)
return NULL;
transfer->resource = resource;
- transfer->sr = sr;
+ transfer->level = level;
transfer->usage = usage;
transfer->box = *box;
@@ -98,12 +102,12 @@ struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
}
void u_default_transfer_unmap( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
+ struct pipe_transfer *transfer )
{
}
void u_default_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+ struct pipe_transfer *transfer)
{
FREE(transfer);
}
diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h
index e3a38730f21..3412e13c3cc 100644
--- a/src/gallium/auxiliary/util/u_transfer.h
+++ b/src/gallium/auxiliary/util/u_transfer.h
@@ -11,37 +11,37 @@ struct pipe_context;
struct winsys_handle;
boolean u_default_resource_get_handle(struct pipe_screen *screen,
- struct pipe_resource *resource,
- struct winsys_handle *handle);
+ struct pipe_resource *resource,
+ struct winsys_handle *handle);
void u_default_transfer_inline_write( struct pipe_context *pipe,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned slice_stride);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride);
void u_default_transfer_flush_region( struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box);
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box);
unsigned u_default_is_resource_referenced( struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned face, unsigned level);
+ struct pipe_resource *resource,
+ unsigned level, int layer);
struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box);
void u_default_transfer_unmap( struct pipe_context *pipe,
- struct pipe_transfer *transfer );
+ struct pipe_transfer *transfer );
void u_default_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer);
+ struct pipe_transfer *transfer);
@@ -51,43 +51,43 @@ void u_default_transfer_destroy(struct pipe_context *pipe,
struct u_resource_vtbl {
boolean (*resource_get_handle)(struct pipe_screen *,
- struct pipe_resource *tex,
- struct winsys_handle *handle);
+ struct pipe_resource *tex,
+ struct winsys_handle *handle);
void (*resource_destroy)(struct pipe_screen *,
- struct pipe_resource *pt);
+ struct pipe_resource *pt);
unsigned (*is_resource_referenced)(struct pipe_context *pipe,
- struct pipe_resource *texture,
- unsigned face, unsigned level);
+ struct pipe_resource *texture,
+ unsigned level, int layer);
struct pipe_transfer *(*get_transfer)(struct pipe_context *,
- struct pipe_resource *resource,
- struct pipe_subresource,
- unsigned usage,
- const struct pipe_box *);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *);
void (*transfer_destroy)(struct pipe_context *,
- struct pipe_transfer *);
+ struct pipe_transfer *);
void *(*transfer_map)( struct pipe_context *,
- struct pipe_transfer *transfer );
+ struct pipe_transfer *transfer );
void (*transfer_flush_region)( struct pipe_context *,
- struct pipe_transfer *transfer,
- const struct pipe_box *);
+ struct pipe_transfer *transfer,
+ const struct pipe_box *);
void (*transfer_unmap)( struct pipe_context *,
- struct pipe_transfer *transfer );
+ struct pipe_transfer *transfer );
void (*transfer_inline_write)( struct pipe_context *pipe,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned slice_stride);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride);
};
@@ -98,43 +98,43 @@ struct u_resource {
boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource,
- struct winsys_handle *handle);
+ struct pipe_resource *resource,
+ struct winsys_handle *handle);
void u_resource_destroy_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource);
+ struct pipe_resource *resource);
unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned face, unsigned level);
+ struct pipe_resource *resource,
+ unsigned level, int layer);
struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box);
void u_transfer_destroy_vtbl(struct pipe_context *pipe,
- struct pipe_transfer *transfer);
+ struct pipe_transfer *transfer);
void *u_transfer_map_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer );
+ struct pipe_transfer *transfer );
void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box);
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box);
void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx,
- struct pipe_transfer *transfer );
+ struct pipe_transfer *transfer );
void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned slice_stride);
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride);