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[0] = LLVMArrayType(LLVMPointerType(float_type, 0), /* vs_constants */
+ LP_MAX_TGSI_CONST_BUFFERS);
+ elem_types[1] = elem_types[0]; /* gs_constants */
elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4),
DRAW_TOTAL_CLIP_PLANES), 0);
elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */
#include "draw/draw_vs.h"
#include "gallivm/lp_bld_sample.h"
+#include "gallivm/lp_bld_limits.h"
#include "pipe/p_context.h"
#include "util/u_simple_list.h"
*/
struct draw_jit_context
{
- const float *vs_constants;
- const float *gs_constants;
+ const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
+ const float *gs_constants[LP_MAX_TGSI_CONST_BUFFERS];
float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
float *viewport;
#define draw_jit_context_vs_constants(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 0, "vs_constants")
+ lp_build_struct_get_ptr(_gallivm, _ptr, 0, "vs_constants")
#define draw_jit_context_gs_constants(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, 1, "gs_constants")
+ lp_build_struct_get_ptr(_gallivm, _ptr, 1, "gs_constants")
#define draw_jit_context_planes(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 2, "planes")
const unsigned nr = MAX2( shader->base.info.num_inputs,
shader->base.info.num_outputs + 1 );
+ unsigned i;
+
fpme->input_prim = in_prim;
fpme->opt = opt;
}
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.
fpme->current_variant = variant;
- /*XXX we only support one constant buffer */
- fpme->llvm->jit_context.vs_constants =
- draw->pt.user.vs_constants[0];
- fpme->llvm->jit_context.gs_constants =
- draw->pt.user.gs_constants[0];
+ for (i = 0; i < Elements(fpme->llvm->jit_context.vs_constants); ++i) {
+ fpme->llvm->jit_context.vs_constants[i] =
+ draw->pt.user.vs_constants[i];
+ }
+ for (i = 0; i < Elements(fpme->llvm->jit_context.gs_constants); ++i) {
+ fpme->llvm->jit_context.gs_constants[i] =
+ draw->pt.user.gs_constants[i];
+ }
fpme->llvm->jit_context.planes =
(float (*) [DRAW_TOTAL_CLIP_PLANES][4]) draw->pt.user.planes[0];
fpme->llvm->jit_context.viewport =
#define LP_MAX_TGSI_PREDS 16
+#define LP_MAX_TGSI_CONST_BUFFERS 16
+
+
/**
* Maximum control flow nesting
*
#include "lp_bld_debug.h"
#include "lp_bld_printf.h"
#include "lp_bld_sample.h"
+#include "lp_bld_struct.h"
static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context *bld)
struct lp_build_context *uint_bld = &bld_base->uint_bld;
LLVMValueRef indirect_index = NULL;
struct lp_build_context *bld_fetch = stype_to_fetch(bld_base, stype);
-
+ unsigned dimension = 0;
+ LLVMValueRef dimension_index;
+ LLVMValueRef consts_ptr;
+
/* XXX: Handle fetching xyzw components as a vector */
assert(swizzle != ~0);
+ if (reg->Register.Dimension) {
+ assert(!reg->Dimension.Indirect);
+ dimension = reg->Dimension.Index;
+ assert(dimension < LP_MAX_TGSI_CONST_BUFFERS);
+ }
+
+ dimension_index = lp_build_const_int32(gallivm, dimension);
+ consts_ptr = lp_build_array_get(gallivm, bld->consts_ptr, dimension_index);
+
if (reg->Register.Indirect) {
indirect_index = get_indirect_index(bld,
reg->Register.File,
index_vec = lp_build_add(uint_bld, index_vec, swizzle_vec);
/* Gather values from the constant buffer */
- return build_gather(bld_fetch, bld->consts_ptr, index_vec);
+ return build_gather(bld_fetch, consts_ptr, index_vec);
}
else {
LLVMValueRef index; /* index into the const buffer */
index = lp_build_const_int32(gallivm, reg->Register.Index*4 + swizzle);
- scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
+ scalar_ptr = LLVMBuildGEP(builder, consts_ptr,
&index, 1, "");
if (stype != TGSI_TYPE_FLOAT && stype != TGSI_TYPE_UNTYPED) {
struct pipe_blend_color blend_color;
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
- struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
+ struct pipe_resource *constants[PIPE_SHADER_TYPES][LP_MAX_TGSI_CONST_BUFFERS];
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
LLVMTypeRef elem_types[LP_JIT_CTX_COUNT];
LLVMTypeRef context_type;
- elem_types[LP_JIT_CTX_CONSTANTS] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0);
+ elem_types[LP_JIT_CTX_CONSTANTS] =
+ LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc), 0), LP_MAX_TGSI_CONST_BUFFERS);
elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatTypeInContext(lc);
elem_types[LP_JIT_CTX_STENCIL_REF_FRONT] =
elem_types[LP_JIT_CTX_STENCIL_REF_BACK] = LLVMInt32TypeInContext(lc);
#include "gallivm/lp_bld_struct.h"
+#include "gallivm/lp_bld_limits.h"
#include "pipe/p_state.h"
#include "lp_texture.h"
*/
struct lp_jit_context
{
- const float *constants;
+ const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
float alpha_ref_value;
#define lp_jit_context_constants(_gallivm, _ptr) \
- lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
+ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
#define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
void lp_setup_reset( struct lp_setup_context *setup )
{
+ unsigned i;
+
LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__);
/* Reset derived state */
- setup->constants.stored_size = 0;
- setup->constants.stored_data = NULL;
+ for (i = 0; i < Elements(setup->constants); ++i) {
+ setup->constants[i].stored_size = 0;
+ setup->constants[i].stored_data = NULL;
+ }
setup->fs.stored = NULL;
setup->dirty = ~0;
void
lp_setup_set_fs_constants(struct lp_setup_context *setup,
- struct pipe_resource *buffer)
+ unsigned num,
+ struct pipe_resource **buffers)
{
- LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer);
+ unsigned i;
+
+ LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffers);
- pipe_resource_reference(&setup->constants.current, buffer);
+ assert(num <= Elements(setup->constants));
- setup->dirty |= LP_SETUP_NEW_CONSTANTS;
+ for (i = 0; i < num; ++i) {
+ if (setup->constants[i].current != buffers[i]) {
+ pipe_resource_reference(&setup->constants[i].current, buffers[i]);
+ setup->dirty |= LP_SETUP_NEW_CONSTANTS;
+ }
+ }
}
{
boolean new_scene = (setup->fs.stored == NULL);
struct lp_scene *scene = setup->scene;
+ unsigned i;
assert(scene);
setup->dirty |= LP_SETUP_NEW_FS;
}
- if(setup->dirty & LP_SETUP_NEW_CONSTANTS) {
- struct pipe_resource *buffer = setup->constants.current;
+ if (setup->dirty & LP_SETUP_NEW_CONSTANTS) {
+ for (i = 0; i < Elements(setup->constants); ++i) {
+ struct pipe_resource *buffer = setup->constants[i].current;
- if(buffer) {
- unsigned current_size = buffer->width0;
- const void *current_data = llvmpipe_resource_data(buffer);
+ if (buffer) {
+ unsigned current_size = buffer->width0;
+ const void *current_data = llvmpipe_resource_data(buffer);
- /* TODO: copy only the actually used constants? */
+ /* TODO: copy only the actually used constants? */
- if(setup->constants.stored_size != current_size ||
- !setup->constants.stored_data ||
- memcmp(setup->constants.stored_data,
- current_data,
- current_size) != 0) {
- void *stored;
+ if (setup->constants[i].stored_size != current_size ||
+ !setup->constants[i].stored_data ||
+ memcmp(setup->constants[i].stored_data,
+ current_data,
+ current_size) != 0) {
+ void *stored;
- stored = lp_scene_alloc(scene, current_size);
- if (!stored) {
- assert(!new_scene);
- return FALSE;
- }
+ stored = lp_scene_alloc(scene, current_size);
+ if (!stored) {
+ assert(!new_scene);
+ return FALSE;
+ }
- memcpy(stored,
- current_data,
- current_size);
- setup->constants.stored_size = current_size;
- setup->constants.stored_data = stored;
+ memcpy(stored,
+ current_data,
+ current_size);
+ setup->constants[i].stored_size = current_size;
+ setup->constants[i].stored_data = stored;
+ }
+ }
+ else {
+ setup->constants[i].stored_size = 0;
+ setup->constants[i].stored_data = NULL;
}
- }
- else {
- setup->constants.stored_size = 0;
- setup->constants.stored_data = NULL;
- }
- setup->fs.current.jit_context.constants = setup->constants.stored_data;
- setup->dirty |= LP_SETUP_NEW_FS;
+ setup->fs.current.jit_context.constants[i] = setup->constants[i].stored_data;
+ setup->dirty |= LP_SETUP_NEW_FS;
+ }
}
sizeof setup->fs.current) != 0)
{
struct lp_rast_state *stored;
- uint i;
/* The fs state that's been stored in the scene is different from
* the new, current state. So allocate a new lp_rast_state object
pipe_resource_reference(&setup->fs.current_tex[i], NULL);
}
- pipe_resource_reference(&setup->constants.current, NULL);
+ for (i = 0; i < Elements(setup->constants); i++) {
+ pipe_resource_reference(&setup->constants[i].current, NULL);
+ }
/* free the scenes in the 'empty' queue */
for (i = 0; i < Elements(setup->scenes); i++) {
void
lp_setup_set_fs_constants(struct lp_setup_context *setup,
- struct pipe_resource *buffer);
+ unsigned num,
+ struct pipe_resource **buffers);
void
struct pipe_resource *current;
unsigned stored_size;
const void *stored_data;
- } constants;
+ } constants[LP_MAX_TGSI_CONST_BUFFERS];
struct {
struct pipe_blend_color current;
}
if (llvmpipe->dirty & LP_NEW_CONSTANTS)
- lp_setup_set_fs_constants(llvmpipe->setup,
- llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]);
+ lp_setup_set_fs_constants(llvmpipe->setup,
+ Elements(llvmpipe->constants[PIPE_SHADER_FRAGMENT]),
+ llvmpipe->constants[PIPE_SHADER_FRAGMENT]);
if (llvmpipe->dirty & (LP_NEW_SAMPLER_VIEW))
lp_setup_set_fragment_sampler_views(llvmpipe->setup,
data = constants ? llvmpipe_resource_data(constants) : NULL;
assert(shader < PIPE_SHADER_TYPES);
- assert(index < PIPE_MAX_CONSTANT_BUFFERS);
+ assert(index < Elements(llvmpipe->constants[shader]));
if(llvmpipe->constants[shader][index] == constants)
return;