summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/llvm/llvm_builtins.c
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2007-10-15 08:12:22 -0400
committerZack Rusin <zack@tungstengraphics.com>2007-10-24 11:21:03 -0400
commit9e6d58fac26a12246e9e560f3802ebcbce2423bc (patch)
tree34ecae9618556f873819e76478ab466446f10caf /src/mesa/pipe/llvm/llvm_builtins.c
parent2dbba8b024720c11cb2d812b5ccb61ecb9887faa (diff)
Generate the base shader.
Diffstat (limited to 'src/mesa/pipe/llvm/llvm_builtins.c')
-rw-r--r--src/mesa/pipe/llvm/llvm_builtins.c115
1 files changed, 91 insertions, 24 deletions
diff --git a/src/mesa/pipe/llvm/llvm_builtins.c b/src/mesa/pipe/llvm/llvm_builtins.c
index 0f0efeb303..c7a9ea0d5a 100644
--- a/src/mesa/pipe/llvm/llvm_builtins.c
+++ b/src/mesa/pipe/llvm/llvm_builtins.c
@@ -1,20 +1,29 @@
+/* clang --emit-llvm llvm_builtins.c |llvm-as |opt -std-compile-opts |llvm-dis */
+/* clang --emit-llvm llvm_builtins.c |llvm-as |opt -std-compile-opts |llvm2cpp -for=Shader -gen-module -funcname=createBaseShader */
+typedef __attribute__(( ocu_vector_type(4) )) float float4;
+#if 0
+//clang doesn't suppoer "struct->member" notation yet
+struct vertex_header {
+ unsigned clipmask:12;
+ unsigned edgeflag:1;
+ unsigned pad:3;
+ unsigned vertex_id:16;
-inline float4 compute_clip(float4 vec, float4 scale, float4 trans)
-{
- return vec*scale + trans;
-}
+ float clip[4];
+ float data[][4];
+};
inline float
-dot4(const float4 a, const float4 b)
+dot4(float4 a, float4 b)
{
float4 c = a*b;
return c.x + c.y + c.z + c.w;
}
inline unsigned
-compute_clipmask(float4 clip, const float4 (*plane), unsigned nr)
+compute_clipmask(float4 clip, float4 (*plane), unsigned nr)
{
unsigned mask = 0;
unsigned i;
@@ -29,7 +38,8 @@ compute_clipmask(float4 clip, const float4 (*plane), unsigned nr)
inline void collect_results(float4 *results, struct vertex_header *vOut,
float4 *planes, int nr_planes,
- float4 scale, float4 trans)
+ float4 scale, float4 trans,
+ int num_attribs)
{
/* store results */
unsigned slot;
@@ -38,13 +48,14 @@ inline void collect_results(float4 *results, struct vertex_header *vOut,
/* Handle attr[0] (position) specially:
*/
float4 res0 = results[0];
- x = vOut->clip[0] = clip.x;
- y = vOut->clip[1] = clip.y;
- z = vOut->clip[2] = clip.z;
- w = vOut->clip[3] = clip.w;
+ float *clip = vOut->clip;
+ x = clip[0] = res0.x;
+ y = clip[1] = res0.y;
+ z = clip[2] = res0.z;
+ w = clip[3] = res0.w;
- vOut[i]->clipmask = compute_clipmask(res0, planes, nr_planes);
- vOut[i]->edgeflag = 1;
+ vOut->clipmask = compute_clipmask(res0, planes, nr_planes);
+ vOut->edgeflag = 1;
/* divide by w */
w = 1.0f / w;
@@ -54,10 +65,10 @@ inline void collect_results(float4 *results, struct vertex_header *vOut,
res0.x = x; res0.y = y; res0.z = z; res0.w = 1;
/* Viewport mapping */
- res = res * scale + trans;
- vOut->data[0][0] = res.x;
- vOut->data[0][1] = res.y;
- vOut->data[0][2] = res.z;
+ res0 = res0 * scale + trans;
+ vOut->data[0][0] = res0.x;
+ vOut->data[0][1] = res0.y;
+ vOut->data[0][2] = res0.z;
vOut->data[0][3] = w;
/* Remaining attributes are packed into sequential post-transform
@@ -65,7 +76,7 @@ inline void collect_results(float4 *results, struct vertex_header *vOut,
* Skip 0 since we just did it above.
* Subtract two because of the VERTEX_HEADER, CLIP_POS attribs.
*/
- for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) {
+ for (slot = 1; slot < num_attribs - 2; slot++) {
float4 vec = results[slot];
vOut->data[slot][0] = vec.x;
vOut->data[slot][1] = vec.y;
@@ -79,12 +90,68 @@ inline void collect_results(float4 *results, struct vertex_header *vOut,
vOut->data[slot][3]);
}
}
+#endif
-void run_vertex_shader(float ainputs[VS_QUEUE_LENGTH][PIPE_MAX_SHADER_INPUTS][4],
- struct vertex_header *dests[VS_QUEUE_LENGTH],
- float *aconsts[4]
- int count)
+void from_array(float4 (*res)[32], float (*ainputs)[32][4],
+ int count, int num_attribs)
{
- float4 inputs[VS_QUEUE_LENGTH][PIPE_MAX_SHADER_INPUTS];
- float4 *consts;
+ for (int i = 0; i < count; ++i) {
+ for (int j = 0; j < num_attribs; ++j) {
+ float4 vec;
+ vec.x = ainputs[i][j][0];
+ vec.y = ainputs[i][j][1];
+ vec.z = ainputs[i][j][2];
+ vec.w = ainputs[i][j][3];
+ res[i][j] = vec;
+ }
+ }
+}
+
+void from_consts(float4 *res, float (*ainputs)[4],
+ int count)
+{
+ for (int i = 0; i < count; ++i) {
+ float4 vec;
+ vec.x = ainputs[i][0];
+ vec.y = ainputs[i][1];
+ vec.z = ainputs[i][2];
+ vec.w = ainputs[i][3];
+ res[i] = vec;
+ }
+}
+
+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];
+ rd[0] = ri.x;
+ rd[1] = ri.y;
+ rd[2] = ri.z;
+ rd[3] = ri.w;
+ }
+}
+
+extern void execute_shader(float4 *dests, float4 *inputs,
+ float4 *consts);
+
+void run_vertex_shader(float (*ainputs)[32][4],
+ float (*dests)[32][4],
+ float (*aconsts)[4],
+ int count,
+ int num_attribs)
+{
+ float4 inputs[16*32*4][32];
+ float4 consts[32];
+ float4 results[16*32*4][32];
+
+ printf("XXXXXXXXXXX run_vertex_shader\n");
+ from_array(inputs, ainputs, count, num_attribs);
+ from_consts(consts, aconsts, 32);
+ 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);
+ }
}