summaryrefslogtreecommitdiff
path: root/src/mesa/pipe
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2007-10-16 05:41:06 -0400
committerZack Rusin <zack@tungstengraphics.com>2007-10-24 11:21:03 -0400
commit5e0205023e8e6a08b0eb61286e15eb095f32ab3d (patch)
tree6261e444496113f5558a8bb041c57f10c8d0a2dd /src/mesa/pipe
parent5ffdada717466a78b5b148764ba23c7a95098887 (diff)
Cleanup some of the testing code. Implement first pass at actually
running shaders in llvm.
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader.c1
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader_llvm.c29
-rw-r--r--src/mesa/pipe/llvm/llvm_builtins.c19
-rw-r--r--src/mesa/pipe/llvm/llvmtgsi.cpp195
-rw-r--r--src/mesa/pipe/llvm/llvmtgsi.h6
5 files changed, 208 insertions, 42 deletions
diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c
index 874259e727..e36ecdc849 100644
--- a/src/mesa/pipe/draw/draw_vertex_shader.c
+++ b/src/mesa/pipe/draw/draw_vertex_shader.c
@@ -132,6 +132,7 @@ run_vertex_program(struct draw_context *draw,
y = vOut[j]->clip[1] = machine->Outputs[0].xyzw[1].f[j];
z = vOut[j]->clip[2] = machine->Outputs[0].xyzw[2].f[j];
w = vOut[j]->clip[3] = machine->Outputs[0].xyzw[3].f[j];
+ printf("output %d: %f %f %f %f\n", 0, x, y, z, w);
vOut[j]->clipmask = compute_clipmask(vOut[j]->clip, draw->plane, draw->nr_planes);
vOut[j]->edgeflag = 1;
diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
index 37315f7566..97a0480b5c 100644
--- a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
+++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
@@ -98,11 +98,6 @@ void vertex_fetch(struct draw_context *draw,
}
}
-void execute_shader(void *dests, void *inputs, void *consts)
-{
- fprintf(stderr, "EXECUTING--\n");
-}
-
/**
* Called by the draw module when the vertx cache needs to be flushed.
* This involves running the vertex shader.
@@ -118,28 +113,6 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
struct ga_llvm_prog *prog = draw->vertex_shader->state->llvm_prog;
fprintf(stderr, "--- XX q(%d) \n", draw->vs.queue_nr);
- /* Consts does not require 16 byte alignment. */
- fprintf(stderr, "0AAAAA = %f %f %f %f\n",
- consts[0][0],
- consts[0][1],
- consts[0][2],
- consts[0][3]);
-
- fprintf(stderr, "1AAAAA = %f %f %f %f\n",
- consts[1][0],
- consts[1][1],
- consts[1][2],
- consts[1][3]);
- fprintf(stderr, "2AAAAA = %f %f %f %f\n",
- consts[2][0],
- consts[2][1],
- consts[2][2],
- consts[2][3]);
- fprintf(stderr, "3AAAAA = %f %f %f %f\n",
- consts[3][0],
- consts[3][1],
- consts[3][2],
- consts[3][3]);
/* fetch the inputs */
for (i = 0; i < draw->vs.queue_nr; ++i) {
@@ -151,7 +124,7 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
/* batch execute the shaders on all the vertices */
ga_llvm_prog_exec(prog, inputs, outputs, consts,
draw->vs.queue_nr,
- draw->vertex_info.num_attribs);
+ draw->vertex_shader->state->num_inputs);
/* FIXME: finish conversion */
/* dests = outputs */
diff --git a/src/mesa/pipe/llvm/llvm_builtins.c b/src/mesa/pipe/llvm/llvm_builtins.c
index c7a9ea0d5a..e135b4781d 100644
--- a/src/mesa/pipe/llvm/llvm_builtins.c
+++ b/src/mesa/pipe/llvm/llvm_builtins.c
@@ -92,7 +92,7 @@ inline void collect_results(float4 *results, struct vertex_header *vOut,
}
#endif
-void from_array(float4 (*res)[32], float (*ainputs)[32][4],
+void from_array(float4 (*res)[16], float (*ainputs)[16][4],
int count, int num_attribs)
{
for (int i = 0; i < count; ++i) {
@@ -102,6 +102,7 @@ void from_array(float4 (*res)[32], float (*ainputs)[32][4],
vec.y = ainputs[i][j][1];
vec.z = ainputs[i][j][2];
vec.w = ainputs[i][j][3];
+ //printf("FAR(%d %d) %f %f %f %f\n", i, j, vec.x, vec.y, vec.z, vec.w);
res[i][j] = vec;
}
}
@@ -116,6 +117,7 @@ void from_consts(float4 *res, float (*ainputs)[4],
vec.y = ainputs[i][1];
vec.z = ainputs[i][2];
vec.w = ainputs[i][3];
+ //printf("VCONST %f %f %f %f\n", vec.x, vec.y, vec.z, vec.w);
res[i] = vec;
}
}
@@ -125,6 +127,7 @@ void to_array(float (*dests)[4], float4 *in, int num_attribs)
for (int i = 0; i < num_attribs; ++i) {
float *rd = dests[i];
float4 ri = in[i];
+ printf("DEST = %f %f %f %f\n", ri.x, ri.y, ri.z, ri.w);
rd[0] = ri.x;
rd[1] = ri.y;
rd[2] = ri.z;
@@ -135,23 +138,23 @@ void to_array(float (*dests)[4], float4 *in, int num_attribs)
extern void execute_shader(float4 *dests, float4 *inputs,
float4 *consts);
-void run_vertex_shader(float (*ainputs)[32][4],
- float (*dests)[32][4],
+void run_vertex_shader(float (*ainputs)[16][4],
+ float (*dests)[16][4],
float (*aconsts)[4],
int count,
int num_attribs)
{
- float4 inputs[16*32*4][32];
- float4 consts[32];
- float4 results[16*32*4][32];
+ float4 inputs[16*32*4][16];
+ float4 consts[16];
+ float4 results[16*32*4][16];
printf("XXXXXXXXXXX run_vertex_shader\n");
from_array(inputs, ainputs, count, num_attribs);
- from_consts(consts, aconsts, 32);
+ from_consts(consts, aconsts, 5);
for (int i = 0; i < count; ++i) {
float4 *in = inputs[i];
float4 *res = results[i];
- to_array(dests[i], results[i], num_attribs);
execute_shader(res, in, consts);
+ to_array(dests[i], res, num_attribs);
}
}
diff --git a/src/mesa/pipe/llvm/llvmtgsi.cpp b/src/mesa/pipe/llvm/llvmtgsi.cpp
index a616355f8f..4ff6281c74 100644
--- a/src/mesa/pipe/llvm/llvmtgsi.cpp
+++ b/src/mesa/pipe/llvm/llvmtgsi.cpp
@@ -420,6 +420,19 @@ tgsi_to_llvm(const struct tgsi_token *tokens)
struct tgsi_full_instruction fi;
struct tgsi_full_declaration fd;
+ Function* shader = mod->getFunction("execute_shader");
+ shader->setName("execute_shader_2");
+
+ Function::arg_iterator args = shader->arg_begin();
+ Value *ptr_OUT = args++;
+ ptr_OUT->setName("OUT");
+ Value *ptr_IN = args++;
+ ptr_IN->setName("IN");
+ Value *ptr_CONST = args++;
+ ptr_CONST->setName("CONST");
+
+ BasicBlock *label_entry = new BasicBlock("entry", shader, 0);
+
tgsi_parse_init(&parse, tokens);
//parse.FullHeader.Processor.Processor
@@ -462,10 +475,184 @@ tgsi_to_llvm(const struct tgsi_token *tokens)
}
}
+
+ Function* func_printf = mod->getFunction("printf");
+#if 1
+
+ // Type Definitions
+ ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(8), 19);
+
+ PointerType* PointerTy_1 = PointerType::get(ArrayTy_0);
+
+ VectorType* VectorTy_4 = VectorType::get(Type::FloatTy, 4);
+
+ PointerType* PointerTy_3 = PointerType::get(VectorTy_4);
+
+
+ VectorType* VectorTy_5 = VectorType::get(IntegerType::get(32), 4);
+
+
+ PointerType* PointerTy_8 = PointerType::get(IntegerType::get(8));
+
+
+ // Global Variable Declarations
+
+
+ GlobalVariable* gvar_array__str = new GlobalVariable(
+ /*Type=*/ArrayTy_0,
+ /*isConstant=*/true,
+ /*Linkage=*/GlobalValue::InternalLinkage,
+ /*Initializer=*/0, // has initializer, specified below
+ /*Name=*/".str",
+ mod);
+
+ GlobalVariable* gvar_array__str1 = new GlobalVariable(
+ /*Type=*/ArrayTy_0,
+ /*isConstant=*/true,
+ /*Linkage=*/GlobalValue::InternalLinkage,
+ /*Initializer=*/0, // has initializer, specified below
+ /*Name=*/".str1",
+ mod);
+
+ GlobalVariable* gvar_array__str2 = new GlobalVariable(
+ /*Type=*/ArrayTy_0,
+ /*isConstant=*/true,
+ /*Linkage=*/GlobalValue::InternalLinkage,
+ /*Initializer=*/0, // has initializer, specified below
+ /*Name=*/".str2",
+ mod);
+
+ // Constant Definitions
+ Constant* const_array_9 = ConstantArray::get("const %f %f %f %f\x0A", true);
+ Constant* const_array_10 = ConstantArray::get("resul %f %f %f %f\x0A", true);
+ Constant* const_array_11 = ConstantArray::get("outpu %f %f %f %f\x0A", true);
+ UndefValue* const_packed_12 = UndefValue::get(VectorTy_4);
+ Constant* const_packed_13 = Constant::getNullValue(VectorTy_5);
+ std::vector<Constant*> const_packed_14_elems;
+ ConstantInt* const_int32_15 = ConstantInt::get(APInt(32, "1", 10));
+ const_packed_14_elems.push_back(const_int32_15);
+ const_packed_14_elems.push_back(const_int32_15);
+ const_packed_14_elems.push_back(const_int32_15);
+ const_packed_14_elems.push_back(const_int32_15);
+ Constant* const_packed_14 = ConstantVector::get(VectorTy_5, const_packed_14_elems);
+ std::vector<Constant*> const_packed_16_elems;
+ ConstantInt* const_int32_17 = ConstantInt::get(APInt(32, "2", 10));
+ const_packed_16_elems.push_back(const_int32_17);
+ const_packed_16_elems.push_back(const_int32_17);
+ const_packed_16_elems.push_back(const_int32_17);
+ const_packed_16_elems.push_back(const_int32_17);
+ Constant* const_packed_16 = ConstantVector::get(VectorTy_5, const_packed_16_elems);
+ std::vector<Constant*> const_packed_18_elems;
+ ConstantInt* const_int32_19 = ConstantInt::get(APInt(32, "3", 10));
+ const_packed_18_elems.push_back(const_int32_19);
+ const_packed_18_elems.push_back(const_int32_19);
+ const_packed_18_elems.push_back(const_int32_19);
+ const_packed_18_elems.push_back(const_int32_19);
+ Constant* const_packed_18 = ConstantVector::get(VectorTy_5, const_packed_18_elems);
+ std::vector<Constant*> const_ptr_20_indices;
+ Constant* const_int32_21 = Constant::getNullValue(IntegerType::get(32));
+ const_ptr_20_indices.push_back(const_int32_21);
+ const_ptr_20_indices.push_back(const_int32_21);
+ Constant* const_ptr_20 = ConstantExpr::getGetElementPtr(gvar_array__str, &const_ptr_20_indices[0], const_ptr_20_indices.size() );
+ UndefValue* const_double_22 = UndefValue::get(Type::DoubleTy);
+ std::vector<Constant*> const_ptr_23_indices;
+ const_ptr_23_indices.push_back(const_int32_21);
+ const_ptr_23_indices.push_back(const_int32_21);
+ Constant* const_ptr_23 = ConstantExpr::getGetElementPtr(gvar_array__str1, &const_ptr_23_indices[0], const_ptr_23_indices.size() );
+ std::vector<Constant*> const_ptr_24_indices;
+ const_ptr_24_indices.push_back(const_int32_21);
+ const_ptr_24_indices.push_back(const_int32_21);
+ Constant* const_ptr_24 = ConstantExpr::getGetElementPtr(gvar_array__str2, &const_ptr_24_indices[0], const_ptr_24_indices.size() );
+
+ // Global Variable Definitions
+ gvar_array__str->setInitializer(const_array_9);
+ gvar_array__str1->setInitializer(const_array_10);
+ gvar_array__str2->setInitializer(const_array_11);
+
+ // Function Definitions
+
+ // Function: execute_shader (func_execute_shader)
+ {
+ // Block entry (label_entry)
+ LoadInst* packed_tmp1 = new LoadInst(ptr_IN, "tmp1", false, label_entry);
+ ShuffleVectorInst* packed_tmp3 = new ShuffleVectorInst(packed_tmp1, const_packed_12, const_packed_13, "tmp3", label_entry);
+ LoadInst* packed_tmp6 = new LoadInst(ptr_CONST, "tmp6", false, label_entry);
+ BinaryOperator* packed_mul = BinaryOperator::create(Instruction::Mul, packed_tmp3, packed_tmp6, "mul", label_entry);
+ ShuffleVectorInst* packed_tmp8 = new ShuffleVectorInst(packed_tmp1, const_packed_12, const_packed_14, "tmp8", label_entry);
+ GetElementPtrInst* ptr_arrayidx10 = new GetElementPtrInst(ptr_CONST, const_int32_15, "arrayidx10", label_entry);
+ LoadInst* packed_tmp11 = new LoadInst(ptr_arrayidx10, "tmp11", false, label_entry);
+ BinaryOperator* packed_mul12 = BinaryOperator::create(Instruction::Mul, packed_tmp8, packed_tmp11, "mul12", label_entry);
+ BinaryOperator* packed_add = BinaryOperator::create(Instruction::Add, packed_mul12, packed_mul, "add", label_entry);
+ ShuffleVectorInst* packed_tmp15 = new ShuffleVectorInst(packed_tmp1, const_packed_12, const_packed_16, "tmp15", label_entry);
+ GetElementPtrInst* ptr_arrayidx17 = new GetElementPtrInst(ptr_CONST, const_int32_17, "arrayidx17", label_entry);
+ LoadInst* packed_tmp18 = new LoadInst(ptr_arrayidx17, "tmp18", false, label_entry);
+ BinaryOperator* packed_mul19 = BinaryOperator::create(Instruction::Mul, packed_tmp15, packed_tmp18, "mul19", label_entry);
+ BinaryOperator* packed_add21 = BinaryOperator::create(Instruction::Add, packed_mul19, packed_add, "add21", label_entry);
+ ShuffleVectorInst* packed_tmp25 = new ShuffleVectorInst(packed_tmp1, const_packed_12, const_packed_18, "tmp25", label_entry);
+ GetElementPtrInst* ptr_arrayidx27 = new GetElementPtrInst(ptr_CONST, const_int32_19, "arrayidx27", label_entry);
+ LoadInst* packed_tmp28 = new LoadInst(ptr_arrayidx27, "tmp28", false, label_entry);
+ BinaryOperator* packed_mul29 = BinaryOperator::create(Instruction::Mul, packed_tmp25, packed_tmp28, "mul29", label_entry);
+ BinaryOperator* packed_add31 = BinaryOperator::create(Instruction::Add, packed_mul29, packed_add21, "add31", label_entry);
+ StoreInst* void_25 = new StoreInst(packed_add31, ptr_OUT, false, label_entry);
+ GetElementPtrInst* ptr_arrayidx33 = new GetElementPtrInst(ptr_OUT, const_int32_15, "arrayidx33", label_entry);
+ GetElementPtrInst* ptr_arrayidx35 = new GetElementPtrInst(ptr_IN, const_int32_15, "arrayidx35", label_entry);
+ LoadInst* packed_tmp36 = new LoadInst(ptr_arrayidx35, "tmp36", false, label_entry);
+ StoreInst* void_26 = new StoreInst(packed_tmp36, ptr_arrayidx33, false, label_entry);
+ std::vector<Value*> int32_call_params;
+ int32_call_params.push_back(const_ptr_20);
+ int32_call_params.push_back(const_double_22);
+ int32_call_params.push_back(const_double_22);
+ int32_call_params.push_back(const_double_22);
+ int32_call_params.push_back(const_double_22);
+ //CallInst* int32_call = new CallInst(func_printf, int32_call_params.begin(), int32_call_params.end(), "call", label_entry);
+ //int32_call->setCallingConv(CallingConv::C);
+ //int32_call->setTailCall(true);
+ ExtractElementInst* float_tmp52 = new ExtractElementInst(packed_tmp1, const_int32_21, "tmp52", label_entry);
+ CastInst* double_conv53 = new FPExtInst(float_tmp52, Type::DoubleTy, "conv53", label_entry);
+ ExtractElementInst* float_tmp55 = new ExtractElementInst(packed_tmp1, const_int32_15, "tmp55", label_entry);
+ CastInst* double_conv56 = new FPExtInst(float_tmp55, Type::DoubleTy, "conv56", label_entry);
+ ExtractElementInst* float_tmp58 = new ExtractElementInst(packed_tmp1, const_int32_17, "tmp58", label_entry);
+ CastInst* double_conv59 = new FPExtInst(float_tmp58, Type::DoubleTy, "conv59", label_entry);
+ ExtractElementInst* float_tmp61 = new ExtractElementInst(packed_tmp1, const_int32_19, "tmp61", label_entry);
+ CastInst* double_conv62 = new FPExtInst(float_tmp61, Type::DoubleTy, "conv62", label_entry);
+ std::vector<Value*> int32_call63_params;
+ int32_call63_params.push_back(const_ptr_23);
+ int32_call63_params.push_back(double_conv53);
+ int32_call63_params.push_back(double_conv56);
+ int32_call63_params.push_back(double_conv59);
+ int32_call63_params.push_back(double_conv62);
+ //CallInst* int32_call63 = new CallInst(func_printf, int32_call63_params.begin(), int32_call63_params.end(), "call63", label_entry);
+ //int32_call63->setCallingConv(CallingConv::C);
+ //int32_call63->setTailCall(true);
+ ExtractElementInst* float_tmp65 = new ExtractElementInst(packed_add31, const_int32_21, "tmp65", label_entry);
+ CastInst* double_conv66 = new FPExtInst(float_tmp65, Type::DoubleTy, "conv66", label_entry);
+ ExtractElementInst* float_tmp68 = new ExtractElementInst(packed_add31, const_int32_15, "tmp68", label_entry);
+ CastInst* double_conv69 = new FPExtInst(float_tmp68, Type::DoubleTy, "conv69", label_entry);
+ ExtractElementInst* float_tmp71 = new ExtractElementInst(packed_add31, const_int32_17, "tmp71", label_entry);
+ CastInst* double_conv72 = new FPExtInst(float_tmp71, Type::DoubleTy, "conv72", label_entry);
+ ExtractElementInst* float_tmp74 = new ExtractElementInst(packed_add31, const_int32_19, "tmp74", label_entry);
+ CastInst* double_conv75 = new FPExtInst(float_tmp74, Type::DoubleTy, "conv75", label_entry);
+ std::vector<Value*> int32_call76_params;
+ int32_call76_params.push_back(const_ptr_24);
+ int32_call76_params.push_back(double_conv66);
+ int32_call76_params.push_back(double_conv69);
+ int32_call76_params.push_back(double_conv72);
+ int32_call76_params.push_back(double_conv75);
+ //CallInst* int32_call76 = new CallInst(func_printf, int32_call76_params.begin(), int32_call76_params.end(), "call76", label_entry);
+ //int32_call76->setCallingConv(CallingConv::C);
+ //int32_call76->setTailCall(true);
+ }
+#endif
+
+ new ReturnInst(label_entry);
+
//TXT("\ntgsi-dump end -------------------\n");
tgsi_parse_free(&parse);
+ std::cout<<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<std::endl;
+ std::cout<<*mod<<std::endl;
+ std::cout<<"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"<<std::endl;
return mod;
}
@@ -520,15 +707,15 @@ void ga_llvm_prog_delete(struct ga_llvm_prog *prog)
free(prog);
}
-typedef void (*vertex_shader_runner)(float (*ainputs)[32][4],
- float (*dests)[32][4],
+typedef void (*vertex_shader_runner)(float (*ainputs)[PIPE_MAX_SHADER_INPUTS][4],
+ float (*dests)[PIPE_MAX_SHADER_INPUTS][4],
float (*aconsts)[4],
int count,
int num_attribs);
int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
- float (*inputs)[32][4],
- float (*dests)[32][4],
+ float (*inputs)[PIPE_MAX_SHADER_INPUTS][4],
+ float (*dests)[PIPE_MAX_SHADER_INPUTS][4],
float (*consts)[4],
int count,
int num_attribs)
diff --git a/src/mesa/pipe/llvm/llvmtgsi.h b/src/mesa/pipe/llvm/llvmtgsi.h
index f78fbce4c6..f957a69a72 100644
--- a/src/mesa/pipe/llvm/llvmtgsi.h
+++ b/src/mesa/pipe/llvm/llvmtgsi.h
@@ -5,6 +5,8 @@
extern "C" {
#endif
+#include "pipe/p_state.h"
+
struct tgsi_exec_machine;
struct tgsi_token;
struct tgsi_sampler;
@@ -21,8 +23,8 @@ ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens);
void ga_llvm_prog_delete(struct ga_llvm_prog *prog);
int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
- float (*inputs)[32][4],
- float (*dests)[32][4],
+ float (*inputs)[PIPE_MAX_SHADER_INPUTS][4],
+ float (*dests)[PIPE_MAX_SHADER_INPUTS][4],
float (*consts)[4],
int count,
int num_attribs);