handle temporaries in llvm code generated paths

This commit is contained in:
Zack Rusin 2008-02-13 04:38:10 -05:00
parent e179d5bdd1
commit 4bb1a14d90
6 changed files with 50 additions and 25 deletions

View file

@ -119,7 +119,8 @@ run_vertex_program(struct draw_context *draw,
gallivm_cpu_vs_exec(prog,
machine->Inputs,
machine->Outputs,
machine->Consts);
machine->Consts,
machine->Temps);
} else
#elif defined(__i386__) || defined(__386__)
if (draw->use_sse) {

View file

@ -82,7 +82,8 @@ struct gallivm_cpu_engine *gallivm_global_cpu_engine();
int gallivm_cpu_vs_exec(struct gallivm_prog *prog,
struct tgsi_exec_vector *inputs,
struct tgsi_exec_vector *dests,
float (*consts)[4]);
float (*consts)[4],
struct tgsi_exec_vector *temps);
int gallivm_cpu_fs_exec(struct gallivm_prog *prog,
float x, float y,
float (*dests)[PIPE_MAX_SHADER_INPUTS][4],

View file

@ -177,10 +177,7 @@ struct gallivm_cpu_engine * gallivm_global_cpu_engine()
typedef void (*vertex_shader_runner)(void *ainputs,
void *dests,
float (*aconsts)[4],
int num_vertices,
int num_inputs,
int num_attribs,
int num_consts);
void *temps);
/*!
@ -191,12 +188,13 @@ typedef void (*vertex_shader_runner)(void *ainputs,
int gallivm_cpu_vs_exec(struct gallivm_prog *prog,
struct tgsi_exec_vector *inputs,
struct tgsi_exec_vector *dests,
float (*consts)[4])
float (*consts)[4],
struct tgsi_exec_vector *temps)
{
vertex_shader_runner runner = reinterpret_cast<vertex_shader_runner>(prog->function);
assert(runner);
/*FIXME*/
runner(inputs, dests, consts, 4, 4, 4, prog->num_consts);
runner(inputs, dests, consts, temps);
return 0;
}

View file

@ -44,11 +44,13 @@ using namespace llvm;
StorageSoa::StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
llvm::Value *output,
llvm::Value *consts)
llvm::Value *consts,
llvm::Value *temps)
: m_block(block),
m_input(input),
m_output(output),
m_consts(consts),
m_temps(temps),
m_idx(0)
{
}
@ -101,6 +103,11 @@ std::vector<llvm::Value*> StorageSoa::tempElement(int idx, int swizzle,
{
std::vector<llvm::Value*> res(4);
res[0] = element(m_temps, idx, 0);
res[1] = element(m_temps, idx, 1);
res[2] = element(m_temps, idx, 2);
res[3] = element(m_temps, idx, 3);
return res;
}
@ -138,6 +145,20 @@ void StorageSoa::storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
void StorageSoa::storeTemp(int idx, const std::vector<llvm::Value*> &val,
int mask)
{
if (mask != TGSI_WRITEMASK_XYZW) {
fprintf(stderr, "requires swizzle!!\n");
assert(0);
} else {
llvm::Value *xChannel = elementPointer(m_temps, idx, 0);
llvm::Value *yChannel = elementPointer(m_temps, idx, 1);
llvm::Value *zChannel = elementPointer(m_temps, idx, 2);
llvm::Value *wChannel = elementPointer(m_temps, idx, 3);
StoreInst *st = new StoreInst(val[0], xChannel, false, m_block);
st = new StoreInst(val[1], yChannel, false, m_block);
st = new StoreInst(val[2], zChannel, false, m_block);
st = new StoreInst(val[3], wChannel, false, m_block);
}
}
void StorageSoa::storeAddress(int idx, const std::vector<llvm::Value*> &val,

View file

@ -46,7 +46,8 @@ public:
StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
llvm::Value *output,
llvm::Value *consts);
llvm::Value *consts,
llvm::Value *temps);
void addImmediate(float *vec);
@ -79,6 +80,7 @@ private:
llvm::Value *m_input;
llvm::Value *m_output;
llvm::Value *m_consts;
llvm::Value *m_temps;
mutable std::map<int, llvm::ConstantInt*> m_constInts;
mutable char m_name[32];

View file

@ -53,23 +53,23 @@ static inline FunctionType *vertexShaderFunctionType()
// pass are castable to the following:
// [4 x <4 x float>] inputs,
// [4 x <4 x float>] output,
// [4 x [4 x float]] consts
// [4 x [4 x float]] consts,
// [4 x <4 x float>] temps
std::vector<const Type*> funcArgs;
{
VectorType *vectorType = VectorType::get(Type::FloatTy, 4);
ArrayType *vectorArray = ArrayType::get(vectorType, 4);
PointerType *vectorArrayPtr = PointerType::get(vectorArray, 0);
VectorType *vectorType = VectorType::get(Type::FloatTy, 4);
ArrayType *vectorArray = ArrayType::get(vectorType, 4);
PointerType *vectorArrayPtr = PointerType::get(vectorArray, 0);
funcArgs.push_back(vectorArrayPtr);//inputs
funcArgs.push_back(vectorArrayPtr);//output
}
{
ArrayType *floatArray = ArrayType::get(Type::FloatTy, 4);
ArrayType *constsArray = ArrayType::get(floatArray, 4);
PointerType *constsArrayPtr = PointerType::get(constsArray, 0);
ArrayType *floatArray = ArrayType::get(Type::FloatTy, 4);
ArrayType *constsArray = ArrayType::get(floatArray, 4);
PointerType *constsArrayPtr = PointerType::get(constsArray, 0);
funcArgs.push_back(vectorArrayPtr);//inputs
funcArgs.push_back(vectorArrayPtr);//output
funcArgs.push_back(constsArrayPtr);//consts
funcArgs.push_back(vectorArrayPtr);//temps
funcArgs.push_back(constsArrayPtr);//consts
}
FunctionType *functionType = FunctionType::get(
/*Result=*/Type::VoidTy,
/*Params=*/funcArgs,
@ -1162,6 +1162,8 @@ llvm::Module * tgsi_to_llvmir(struct gallivm_ir *ir,
output->setName("outputs");
Value *consts = args++;
consts->setName("consts");
Value *temps = args++;
temps->setName("temps");
BasicBlock *label_entry = new BasicBlock("entry", shader, 0);
@ -1170,7 +1172,7 @@ llvm::Module * tgsi_to_llvmir(struct gallivm_ir *ir,
fi = tgsi_default_full_instruction();
fd = tgsi_default_full_declaration();
StorageSoa storage(label_entry, input, output, consts);
StorageSoa storage(label_entry, input, output, consts, temps);
InstructionsSoa instr(mod, shader, label_entry, &storage);
while(!tgsi_parse_end_of_tokens(&parse)) {