summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mesa/pipe/llvm/gallivm.cpp4
-rw-r--r--src/mesa/pipe/llvm/gallivm_p.h54
-rw-r--r--src/mesa/pipe/llvm/storage.cpp10
-rw-r--r--src/mesa/pipe/llvm/storagesoa.cpp14
-rw-r--r--src/mesa/pipe/llvm/tgsitollvm.cpp12
5 files changed, 82 insertions, 12 deletions
diff --git a/src/mesa/pipe/llvm/gallivm.cpp b/src/mesa/pipe/llvm/gallivm.cpp
index b99dc6db5b8..ab13be09151 100644
--- a/src/mesa/pipe/llvm/gallivm.cpp
+++ b/src/mesa/pipe/llvm/gallivm.cpp
@@ -289,9 +289,9 @@ void gallivm_ir_fill_from_tgsi(struct gallivm_ir *ir,
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);
}
diff --git a/src/mesa/pipe/llvm/gallivm_p.h b/src/mesa/pipe/llvm/gallivm_p.h
index 2c6e5e8f5f2..cfe7b1901b3 100644
--- a/src/mesa/pipe/llvm/gallivm_p.h
+++ b/src/mesa/pipe/llvm/gallivm_p.h
@@ -3,6 +3,10 @@
#ifdef MESA_LLVM
+#include "gallivm.h"
+#include "pipe/p_shader_tokens.h"
+#include "pipe/p_compiler.h"
+
namespace llvm {
class Module;
}
@@ -47,6 +51,56 @@ struct gallivm_prog {
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
diff --git a/src/mesa/pipe/llvm/storage.cpp b/src/mesa/pipe/llvm/storage.cpp
index 08b9d29a24a..c4326de8c53 100644
--- a/src/mesa/pipe/llvm/storage.cpp
+++ b/src/mesa/pipe/llvm/storage.cpp
@@ -33,6 +33,8 @@
#include "storage.h"
+#include "gallivm_p.h"
+
#include "pipe/p_shader_tokens.h"
#include <llvm/BasicBlock.h>
#include <llvm/Module.h>
@@ -82,10 +84,10 @@ llvm::Constant *Storage::shuffleMask(int vec)
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));
diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp
index ff94307c85d..8f82989cc5d 100644
--- a/src/mesa/pipe/llvm/storagesoa.cpp
+++ b/src/mesa/pipe/llvm/storagesoa.cpp
@@ -119,6 +119,20 @@ llvm::Value * StorageSoa::extractIndex(llvm::Value *vec)
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,
diff --git a/src/mesa/pipe/llvm/tgsitollvm.cpp b/src/mesa/pipe/llvm/tgsitollvm.cpp
index bc4df610717..574e340f668 100644
--- a/src/mesa/pipe/llvm/tgsitollvm.cpp
+++ b/src/mesa/pipe/llvm/tgsitollvm.cpp
@@ -178,9 +178,8 @@ swizzleVector(llvm::Value *val, struct tgsi_full_src_register *src,
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);
}
@@ -1107,12 +1106,11 @@ tgsi_to_llvm(struct gallivm_ir *ir, const struct tgsi_token *tokens)
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";
@@ -1121,7 +1119,9 @@ llvm::Module * tgsi_to_llvmir(struct gallivm_ir *ir,
}
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++;