2009-07-26 23:44:38 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-08-14 10:27:32 +01:00
|
|
|
* Copyright 2009 VMware, Inc.
|
2009-07-26 23:44:38 +01:00
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* 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 above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* 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 TUNGSTEN GRAPHICS 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.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "pipe/p_defines.h"
|
|
|
|
#include "util/u_memory.h"
|
2009-08-19 20:42:50 +01:00
|
|
|
#include "util/u_debug_dump.h"
|
2009-07-26 23:44:38 +01:00
|
|
|
#include "pipe/internal/p_winsys_screen.h"
|
|
|
|
#include "pipe/p_shader_tokens.h"
|
|
|
|
#include "draw/draw_context.h"
|
|
|
|
#include "tgsi/tgsi_dump.h"
|
|
|
|
#include "tgsi/tgsi_scan.h"
|
|
|
|
#include "tgsi/tgsi_parse.h"
|
2009-08-14 10:27:32 +01:00
|
|
|
#include "lp_bld_type.h"
|
|
|
|
#include "lp_bld_tgsi.h"
|
2009-08-19 20:42:50 +01:00
|
|
|
#include "lp_bld_alpha.h"
|
2009-08-19 17:58:04 +01:00
|
|
|
#include "lp_bld_swizzle.h"
|
2009-08-16 11:50:17 +01:00
|
|
|
#include "lp_bld_debug.h"
|
2009-08-14 10:27:32 +01:00
|
|
|
#include "lp_screen.h"
|
|
|
|
#include "lp_context.h"
|
|
|
|
#include "lp_state.h"
|
|
|
|
#include "lp_quad.h"
|
|
|
|
|
|
|
|
|
2009-08-19 17:58:04 +01:00
|
|
|
static const unsigned char quad_offset_x[4] = {0, 1, 0, 1};
|
|
|
|
static const unsigned char quad_offset_y[4] = {0, 0, 1, 1};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_pos_vector(LLVMBuilderRef builder,
|
|
|
|
LLVMValueRef x,
|
|
|
|
LLVMValueRef y,
|
|
|
|
LLVMValueRef a0_ptr,
|
|
|
|
LLVMValueRef dadx_ptr,
|
|
|
|
LLVMValueRef dady_ptr,
|
|
|
|
LLVMValueRef *pos)
|
|
|
|
{
|
|
|
|
LLVMTypeRef int_elem_type = LLVMInt32Type();
|
|
|
|
LLVMTypeRef int_vec_type = LLVMVectorType(int_elem_type, QUAD_SIZE);
|
|
|
|
LLVMTypeRef elem_type = LLVMFloatType();
|
|
|
|
LLVMTypeRef vec_type = LLVMVectorType(elem_type, QUAD_SIZE);
|
|
|
|
LLVMValueRef x_offsets[QUAD_SIZE];
|
|
|
|
LLVMValueRef y_offsets[QUAD_SIZE];
|
|
|
|
unsigned chan;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
x = lp_build_broadcast(builder, int_vec_type, x);
|
|
|
|
y = lp_build_broadcast(builder, int_vec_type, y);
|
|
|
|
|
|
|
|
for(i = 0; i < QUAD_SIZE; ++i) {
|
|
|
|
x_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_x[i], 0);
|
|
|
|
y_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_y[i], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = LLVMBuildAdd(builder, x, LLVMConstVector(x_offsets, QUAD_SIZE), "");
|
|
|
|
y = LLVMBuildAdd(builder, y, LLVMConstVector(y_offsets, QUAD_SIZE), "");
|
|
|
|
|
|
|
|
x = LLVMBuildSIToFP(builder, x, vec_type, "");
|
|
|
|
y = LLVMBuildSIToFP(builder, y, vec_type, "");
|
|
|
|
|
|
|
|
pos[0] = x;
|
|
|
|
pos[1] = y;
|
|
|
|
|
|
|
|
for(chan = 2; chan < NUM_CHANNELS; ++chan) {
|
|
|
|
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), chan, 0);
|
|
|
|
LLVMValueRef a0 = LLVMBuildLoad(builder, LLVMBuildGEP(builder, a0_ptr, &index, 1, ""), "");
|
|
|
|
LLVMValueRef dadx = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dadx_ptr, &index, 1, ""), "");
|
|
|
|
LLVMValueRef dady = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dady_ptr, &index, 1, ""), "");
|
|
|
|
LLVMValueRef res;
|
|
|
|
a0 = lp_build_broadcast(builder, vec_type, a0);
|
|
|
|
dadx = lp_build_broadcast(builder, vec_type, dadx);
|
|
|
|
dady = lp_build_broadcast(builder, vec_type, dady);
|
|
|
|
res = a0;
|
|
|
|
res = LLVMBuildAdd(builder, res, LLVMBuildMul(builder, dadx, x, ""), "");
|
|
|
|
res = LLVMBuildAdd(builder, res, LLVMBuildMul(builder, dady, y, ""), "");
|
|
|
|
pos[chan] = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(chan = 0; chan < NUM_CHANNELS; ++chan)
|
|
|
|
lp_build_name(pos[chan], "pos.%c", "xyzw"[chan]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
static struct lp_fragment_shader_variant *
|
2009-08-14 10:27:32 +01:00
|
|
|
shader_generate(struct llvmpipe_screen *screen,
|
2009-08-19 20:42:50 +01:00
|
|
|
struct lp_fragment_shader *shader,
|
|
|
|
const struct pipe_alpha_state *alpha)
|
2009-08-14 10:27:32 +01:00
|
|
|
{
|
2009-08-19 20:42:50 +01:00
|
|
|
struct lp_fragment_shader_variant *variant;
|
2009-08-14 10:27:32 +01:00
|
|
|
const struct tgsi_token *tokens = shader->base.tokens;
|
|
|
|
union lp_type type;
|
|
|
|
LLVMTypeRef elem_type;
|
|
|
|
LLVMTypeRef vec_type;
|
2009-08-16 21:01:57 +01:00
|
|
|
LLVMTypeRef int_vec_type;
|
2009-08-19 17:58:04 +01:00
|
|
|
LLVMTypeRef arg_types[10];
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMTypeRef func_type;
|
2009-08-19 17:58:04 +01:00
|
|
|
LLVMValueRef x;
|
|
|
|
LLVMValueRef y;
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMValueRef a0_ptr;
|
|
|
|
LLVMValueRef dadx_ptr;
|
|
|
|
LLVMValueRef dady_ptr;
|
|
|
|
LLVMValueRef consts_ptr;
|
2009-08-16 21:01:57 +01:00
|
|
|
LLVMValueRef mask_ptr;
|
2009-08-19 09:24:20 +01:00
|
|
|
LLVMValueRef color_ptr;
|
|
|
|
LLVMValueRef depth_ptr;
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMValueRef samplers_ptr;
|
|
|
|
LLVMBasicBlockRef block;
|
|
|
|
LLVMBuilderRef builder;
|
|
|
|
LLVMValueRef pos[NUM_CHANNELS];
|
|
|
|
LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
|
2009-08-16 21:01:57 +01:00
|
|
|
LLVMValueRef mask;
|
2009-08-19 20:42:50 +01:00
|
|
|
LLVMValueRef fetch_texel;
|
2009-08-19 09:24:20 +01:00
|
|
|
unsigned i;
|
|
|
|
unsigned attrib;
|
|
|
|
unsigned chan;
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
tgsi_dump(shader->base.tokens, 0);
|
|
|
|
debug_printf("alpha.enabled = %u\n", alpha->enabled);
|
|
|
|
debug_printf("alpha.func = %s\n", debug_dump_func(alpha->func, TRUE));
|
|
|
|
debug_printf("alpha.ref_value = %f\n", alpha->ref_value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
variant = CALLOC_STRUCT(lp_fragment_shader_variant);
|
|
|
|
if(!variant)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
variant->shader = shader;
|
|
|
|
memcpy(&variant->alpha, alpha, sizeof *alpha);
|
|
|
|
|
2009-08-14 10:27:32 +01:00
|
|
|
type.value = 0;
|
2009-08-19 20:14:59 +01:00
|
|
|
type.floating = TRUE; /* floating point values */
|
|
|
|
type.sign = TRUE; /* values are signed */
|
|
|
|
type.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */
|
|
|
|
type.width = 32; /* 32-bit float */
|
|
|
|
type.length = 4; /* 4 element per vector */
|
2009-08-14 10:27:32 +01:00
|
|
|
|
|
|
|
elem_type = lp_build_elem_type(type);
|
|
|
|
vec_type = lp_build_vec_type(type);
|
2009-08-16 21:01:57 +01:00
|
|
|
int_vec_type = lp_build_int_vec_type(type);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-08-19 17:58:04 +01:00
|
|
|
arg_types[0] = LLVMInt32Type(); /* x */
|
|
|
|
arg_types[1] = LLVMInt32Type(); /* y */
|
|
|
|
arg_types[2] = LLVMPointerType(elem_type, 0); /* a0 */
|
|
|
|
arg_types[3] = LLVMPointerType(elem_type, 0); /* dadx */
|
|
|
|
arg_types[4] = LLVMPointerType(elem_type, 0); /* dady */
|
|
|
|
arg_types[5] = LLVMPointerType(elem_type, 0); /* consts */
|
|
|
|
arg_types[6] = LLVMPointerType(int_vec_type, 0); /* mask */
|
|
|
|
arg_types[7] = LLVMPointerType(vec_type, 0); /* color */
|
|
|
|
arg_types[8] = LLVMPointerType(vec_type, 0); /* depth */
|
|
|
|
arg_types[9] = LLVMPointerType(LLVMInt8Type(), 0); /* samplers */
|
2009-08-14 10:27:32 +01:00
|
|
|
|
|
|
|
func_type = LLVMFunctionType(LLVMVoidType(), arg_types, Elements(arg_types), 0);
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
variant->function = LLVMAddFunction(screen->module, "shader", func_type);
|
|
|
|
LLVMSetFunctionCallConv(variant->function, LLVMCCallConv);
|
2009-08-16 10:02:17 +01:00
|
|
|
for(i = 0; i < Elements(arg_types); ++i)
|
2009-08-19 17:58:04 +01:00
|
|
|
if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind)
|
2009-08-19 20:42:50 +01:00
|
|
|
LLVMAddAttribute(LLVMGetParam(variant->function, i), LLVMNoAliasAttribute);
|
|
|
|
|
|
|
|
x = LLVMGetParam(variant->function, 0);
|
|
|
|
y = LLVMGetParam(variant->function, 1);
|
|
|
|
a0_ptr = LLVMGetParam(variant->function, 2);
|
|
|
|
dadx_ptr = LLVMGetParam(variant->function, 3);
|
|
|
|
dady_ptr = LLVMGetParam(variant->function, 4);
|
|
|
|
consts_ptr = LLVMGetParam(variant->function, 5);
|
|
|
|
mask_ptr = LLVMGetParam(variant->function, 6);
|
|
|
|
color_ptr = LLVMGetParam(variant->function, 7);
|
|
|
|
depth_ptr = LLVMGetParam(variant->function, 8);
|
|
|
|
samplers_ptr = LLVMGetParam(variant->function, 9);
|
2009-08-19 17:58:04 +01:00
|
|
|
|
|
|
|
lp_build_name(x, "x");
|
|
|
|
lp_build_name(y, "y");
|
2009-08-18 20:23:35 +01:00
|
|
|
lp_build_name(a0_ptr, "a0");
|
|
|
|
lp_build_name(dadx_ptr, "dadx");
|
|
|
|
lp_build_name(dady_ptr, "dady");
|
|
|
|
lp_build_name(consts_ptr, "consts");
|
|
|
|
lp_build_name(mask_ptr, "mask");
|
2009-08-19 09:24:20 +01:00
|
|
|
lp_build_name(color_ptr, "color");
|
|
|
|
lp_build_name(depth_ptr, "depth");
|
2009-08-18 20:23:35 +01:00
|
|
|
lp_build_name(samplers_ptr, "samplers");
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
block = LLVMAppendBasicBlock(variant->function, "entry");
|
2009-08-14 10:27:32 +01:00
|
|
|
builder = LLVMCreateBuilder();
|
|
|
|
LLVMPositionBuilderAtEnd(builder, block);
|
|
|
|
|
2009-08-19 17:58:04 +01:00
|
|
|
setup_pos_vector(builder, x, y, a0_ptr, dadx_ptr, dady_ptr, pos);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
|
|
|
memset(outputs, 0, sizeof outputs);
|
|
|
|
|
2009-08-16 21:01:57 +01:00
|
|
|
mask = lp_build_tgsi_soa(builder, tokens, type,
|
|
|
|
pos, a0_ptr, dadx_ptr, dady_ptr,
|
|
|
|
consts_ptr, outputs, samplers_ptr);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-08-19 09:24:20 +01:00
|
|
|
for (attrib = 0; attrib < shader->info.num_outputs; ++attrib) {
|
|
|
|
for(chan = 0; chan < NUM_CHANNELS; ++chan) {
|
|
|
|
if(outputs[attrib][chan]) {
|
|
|
|
lp_build_name(outputs[attrib][chan], "output%u.%c", attrib, "xyzw"[chan]);
|
|
|
|
|
|
|
|
switch (shader->info.output_semantic_name[attrib]) {
|
|
|
|
case TGSI_SEMANTIC_COLOR:
|
|
|
|
{
|
|
|
|
unsigned cbuf = shader->info.output_semantic_index[attrib];
|
|
|
|
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), cbuf*NUM_CHANNELS + chan, 0);
|
|
|
|
LLVMValueRef output_ptr = LLVMBuildGEP(builder, color_ptr, &index, 1, "");
|
|
|
|
lp_build_name(outputs[attrib][chan], "color%u.%c", attrib, "rgba"[chan]);
|
|
|
|
LLVMBuildStore(builder, outputs[attrib][chan], output_ptr);
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
/* Alpha test */
|
|
|
|
/* XXX: should the alpha reference value be passed separately? */
|
|
|
|
if(cbuf == 0 && chan == 3)
|
|
|
|
mask = lp_build_alpha_test(builder, alpha, type, outputs[attrib][chan], mask);
|
|
|
|
|
2009-08-19 09:24:20 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TGSI_SEMANTIC_POSITION:
|
|
|
|
if(chan == 3)
|
|
|
|
LLVMBuildStore(builder, outputs[attrib][chan], depth_ptr);
|
|
|
|
break;
|
|
|
|
}
|
2009-08-14 10:27:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-16 21:01:57 +01:00
|
|
|
if(mask)
|
|
|
|
LLVMBuildStore(builder, mask, mask_ptr);
|
|
|
|
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMBuildRetVoid(builder);;
|
|
|
|
|
|
|
|
LLVMDisposeBuilder(builder);
|
2009-07-26 23:44:38 +01:00
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
LLVMRunFunctionPassManager(screen->pass, variant->function);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2009-08-19 20:42:50 +01:00
|
|
|
LLVMDumpValue(variant->function);
|
2009-08-14 10:27:32 +01:00
|
|
|
debug_printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
if(LLVMVerifyFunction(variant->function, LLVMPrintMessageAction)) {
|
|
|
|
LLVMDumpValue(variant->function);
|
2009-08-14 10:27:32 +01:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_texel = LLVMGetNamedFunction(screen->module, "fetch_texel");
|
|
|
|
if(fetch_texel) {
|
|
|
|
static boolean first_time = TRUE;
|
|
|
|
if(first_time) {
|
|
|
|
LLVMAddGlobalMapping(screen->engine, fetch_texel, lp_build_tgsi_fetch_texel_soa);
|
|
|
|
first_time = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
variant->jit_function = (lp_shader_fs_func)LLVMGetPointerToGlobal(screen->engine, variant->function);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-08-16 11:50:17 +01:00
|
|
|
#ifdef DEBUG
|
2009-08-19 20:42:50 +01:00
|
|
|
lp_disassemble(variant->jit_function);
|
2009-08-16 11:50:17 +01:00
|
|
|
#endif
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
variant->next = shader->variants;
|
|
|
|
shader->variants = variant;
|
|
|
|
|
|
|
|
return variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
llvmpipe_create_fs_state(struct pipe_context *pipe,
|
|
|
|
const struct pipe_shader_state *templ)
|
|
|
|
{
|
|
|
|
struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
|
|
|
|
struct lp_fragment_shader *shader;
|
|
|
|
|
|
|
|
shader = CALLOC_STRUCT(lp_fragment_shader);
|
|
|
|
if (!shader)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* get/save the summary info for this shader */
|
|
|
|
tgsi_scan_shader(templ->tokens, &shader->info);
|
|
|
|
|
|
|
|
/* we need to keep a local copy of the tokens */
|
|
|
|
shader->base.tokens = tgsi_dup_tokens(templ->tokens);
|
|
|
|
|
|
|
|
shader->screen = screen;
|
|
|
|
|
2009-08-14 10:27:32 +01:00
|
|
|
return shader;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
|
|
|
|
llvmpipe->fs = (struct lp_fragment_shader *) fs;
|
|
|
|
|
2009-07-27 11:36:24 +01:00
|
|
|
llvmpipe->dirty |= LP_NEW_FS;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
|
|
|
|
{
|
2009-08-14 10:27:32 +01:00
|
|
|
struct lp_fragment_shader *shader = fs;
|
2009-08-19 20:42:50 +01:00
|
|
|
struct lp_fragment_shader_variant *variant;
|
2009-08-14 10:27:32 +01:00
|
|
|
struct llvmpipe_screen *screen = shader->screen;
|
2009-07-26 23:44:38 +01:00
|
|
|
|
|
|
|
assert(fs != llvmpipe_context(pipe)->fs);
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
variant = shader->variants;
|
|
|
|
while(variant) {
|
|
|
|
struct lp_fragment_shader_variant *next = variant->next;
|
|
|
|
|
|
|
|
if(variant->function) {
|
|
|
|
if(variant->jit_function)
|
|
|
|
LLVMFreeMachineCodeForFunction(screen->engine, variant->function);
|
|
|
|
LLVMDeleteFunction(variant->function);
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(variant);
|
|
|
|
|
|
|
|
variant = next;
|
2009-08-14 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FREE((void *) shader->base.tokens);
|
|
|
|
FREE(shader);
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
llvmpipe_create_vs_state(struct pipe_context *pipe,
|
|
|
|
const struct pipe_shader_state *templ)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
struct lp_vertex_shader *state;
|
|
|
|
|
|
|
|
state = CALLOC_STRUCT(lp_vertex_shader);
|
|
|
|
if (state == NULL )
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* copy shader tokens, the ones passed in will go away.
|
|
|
|
*/
|
|
|
|
state->shader.tokens = tgsi_dup_tokens(templ->tokens);
|
|
|
|
if (state->shader.tokens == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
state->draw_data = draw_create_vertex_shader(llvmpipe->draw, templ);
|
|
|
|
if (state->draw_data == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (state) {
|
|
|
|
FREE( (void *)state->shader.tokens );
|
|
|
|
FREE( state->draw_data );
|
|
|
|
FREE( state );
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
llvmpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
|
|
|
|
llvmpipe->vs = (const struct lp_vertex_shader *)vs;
|
|
|
|
|
|
|
|
draw_bind_vertex_shader(llvmpipe->draw,
|
|
|
|
(llvmpipe->vs ? llvmpipe->vs->draw_data : NULL));
|
|
|
|
|
2009-07-27 11:36:24 +01:00
|
|
|
llvmpipe->dirty |= LP_NEW_VS;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
llvmpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
|
|
|
|
struct lp_vertex_shader *state =
|
|
|
|
(struct lp_vertex_shader *)vs;
|
|
|
|
|
|
|
|
draw_delete_vertex_shader(llvmpipe->draw, state->draw_data);
|
|
|
|
FREE( state );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
llvmpipe_set_constant_buffer(struct pipe_context *pipe,
|
|
|
|
uint shader, uint index,
|
|
|
|
const struct pipe_constant_buffer *buf)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
|
|
|
|
assert(shader < PIPE_SHADER_TYPES);
|
|
|
|
assert(index == 0);
|
|
|
|
|
|
|
|
/* note: reference counting */
|
|
|
|
pipe_buffer_reference(&llvmpipe->constants[shader].buffer,
|
|
|
|
buf ? buf->buffer : NULL);
|
|
|
|
|
2009-07-27 11:36:24 +01:00
|
|
|
llvmpipe->dirty |= LP_NEW_CONSTANTS;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
void llvmpipe_update_fs(struct llvmpipe_context *lp)
|
|
|
|
{
|
|
|
|
struct lp_fragment_shader *shader = lp->fs;
|
|
|
|
const struct pipe_alpha_state *alpha = &lp->depth_stencil->alpha;
|
|
|
|
struct lp_fragment_shader_variant *variant;
|
|
|
|
|
|
|
|
variant = shader->variants;
|
|
|
|
while(variant) {
|
|
|
|
if(memcmp(&variant->alpha, alpha, sizeof *alpha) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
variant = variant->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!variant)
|
|
|
|
variant = shader_generate(shader->screen, shader, alpha);
|
|
|
|
|
|
|
|
shader->current = variant;
|
|
|
|
}
|