tgsi_dump(tokens, 0);
- llvm::Module *irmod = tgsi_to_llvmir(ir, tokens);
+ llvm::Module *mod = tgsi_to_llvmir(ir, tokens);
- llvm::Module *mod = tgsi_to_llvm(ir, tokens);
+ //llvm::Module *mod = tgsi_to_llvm(ir, tokens);
ir->module = mod;
gallivm_ir_dump(ir, 0);
}
#ifdef MESA_LLVM
+#include "gallivm.h"
+#include "pipe/p_shader_tokens.h"
+#include "pipe/p_compiler.h"
+
namespace llvm {
class Module;
}
int num_interp;
};
+static INLINE void gallivm_swizzle_components(int swizzle,
+ int *xc, int *yc,
+ int *zc, int *wc)
+{
+ int x = swizzle / 1000; swizzle -= x * 1000;
+ int y = swizzle / 100; swizzle -= y * 100;
+ int z = swizzle / 10; swizzle -= z * 10;
+ int w = swizzle;
+
+ if (xc) *xc = x;
+ if (yc) *yc = y;
+ if (zc) *zc = z;
+ if (wc) *wc = w;
+}
+
+static INLINE boolean gallivm_is_swizzle(int swizzle)
+{
+ const int NO_SWIZZLE = TGSI_SWIZZLE_X * 1000 + TGSI_SWIZZLE_Y * 100 +
+ TGSI_SWIZZLE_Z * 10 + TGSI_SWIZZLE_W;
+ return swizzle != NO_SWIZZLE;
+}
+
+static INLINE int gallivm_x_swizzle(int swizzle)
+{
+ int x;
+ gallivm_swizzle_components(swizzle, &x, 0, 0, 0);
+ return x;
+}
+
+static INLINE int gallivm_y_swizzle(int swizzle)
+{
+ int y;
+ gallivm_swizzle_components(swizzle, 0, &y, 0, 0);
+ return y;
+}
+
+static INLINE int gallivm_z_swizzle(int swizzle)
+{
+ int z;
+ gallivm_swizzle_components(swizzle, 0, 0, &z, 0);
+ return z;
+}
+
+static INLINE int gallivm_w_swizzle(int swizzle)
+{
+ int w;
+ gallivm_swizzle_components(swizzle, 0, 0, 0, &w);
+ return w;
+}
+
#endif /* MESA_LLVM */
#if defined __cplusplus
#include "storage.h"
+#include "gallivm_p.h"
+
#include "pipe/p_shader_tokens.h"
#include <llvm/BasicBlock.h>
#include <llvm/Module.h>
if (origVec == 0) {
const_vec = Constant::getNullValue(m_intVecType);
} else {
- int x = vec / 1000; vec -= x * 1000;
- int y = vec / 100; vec -= y * 100;
- int z = vec / 10; vec -= z * 10;
- int w = vec;
+ int x = gallivm_x_swizzle(vec);
+ int y = gallivm_y_swizzle(vec);
+ int z = gallivm_z_swizzle(vec);
+ int w = gallivm_w_swizzle(vec);
std::vector<Constant*> elems;
elems.push_back(constantInt(x));
elems.push_back(constantInt(y));
void StorageSoa::storeOutput(int dstIdx, 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_output, dstIdx, 0);
+ llvm::Value *yChannel = elementPointer(m_output, dstIdx, 1);
+ llvm::Value *zChannel = elementPointer(m_output, dstIdx, 2);
+ llvm::Value *wChannel = elementPointer(m_output, dstIdx, 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::storeTemp(int idx, const std::vector<llvm::Value*> &val,
Storage *storage)
{
int swizzle = swizzleInt(src);
- const int NO_SWIZZLE = TGSI_SWIZZLE_X * 1000 + TGSI_SWIZZLE_Y * 100 +
- TGSI_SWIZZLE_Z * 10 + TGSI_SWIZZLE_W;
- if (swizzle != NO_SWIZZLE) {
+
+ if (gallivm_is_swizzle(swizzle)) {
/*fprintf(stderr, "XXXXXXXX swizzle = %d\n", swizzle);*/
val = storage->shuffleVector(val, swizzle);
}
llvm::Module * tgsi_to_llvmir(struct gallivm_ir *ir,
const struct tgsi_token *tokens)
{
- llvm::Module *mod = createBaseShader();
+ llvm::Module *mod = new Module("shader");
struct tgsi_parse_context parse;
struct tgsi_full_instruction fi;
struct tgsi_full_declaration fd;
unsigned instno = 0;
- Function* shader = mod->getFunction("execute_shader");
std::ostringstream stream;
if (ir->type == GALLIVM_VS) {
stream << "vs_shader";
}
stream << ir->id;
std::string func_name = stream.str();
- shader->setName(func_name.c_str());
+ Function *shader = llvm::cast<Function>(mod->getOrInsertFunction(
+ func_name.c_str(),
+ (const llvm::FunctionType*)0));
Function::arg_iterator args = shader->arg_begin();
Value *input = args++;