summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2007-10-12 13:57:53 -0400
committerZack Rusin <zack@tungstengraphics.com>2007-10-24 11:21:03 -0400
commit2dbba8b024720c11cb2d812b5ccb61ecb9887faa (patch)
treeed3fd1386378a7e64bf2a2ba7521930f9c973b86 /src
parent11bc1f015a781760c419bdd53b326132b5146971 (diff)
Implement the conversion and do the initial execution pass.
Diffstat (limited to 'src')
-rw-r--r--src/mesa/pipe/draw/draw_private.h1
-rw-r--r--src/mesa/pipe/draw/draw_vertex_fetch.c4
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader.c13
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader_llvm.c129
-rw-r--r--src/mesa/pipe/llvm/llvm_builtins.c90
-rw-r--r--src/mesa/pipe/llvm/llvmtgsi.cpp6
-rw-r--r--src/mesa/pipe/llvm/llvmtgsi.h6
-rw-r--r--src/mesa/pipe/softpipe/sp_quad_fs.c2
-rw-r--r--src/mesa/sources1
9 files changed, 242 insertions, 10 deletions
diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h
index b7811e891e..b672cc2e8b 100644
--- a/src/mesa/pipe/draw/draw_private.h
+++ b/src/mesa/pipe/draw/draw_private.h
@@ -251,6 +251,7 @@ extern void draw_vertex_cache_reset_vertex_ids( struct draw_context *draw );
extern void draw_vertex_shader_queue_flush( struct draw_context *draw );
+extern void draw_vertex_shader_queue_flush_llvm( struct draw_context *draw );
struct tgsi_exec_machine;
diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c
index de1cd06da6..1b093b7342 100644
--- a/src/mesa/pipe/draw/draw_vertex_fetch.c
+++ b/src/mesa/pipe/draw/draw_vertex_fetch.c
@@ -96,7 +96,7 @@ void draw_vertex_fetch( struct draw_context *draw,
for (j = 0; j < count; j++) {
uint attr;
- /*printf("fetch vertex %u: \n", j);*/
+ printf("fetch vertex %u: \n", j);
/* loop over vertex attributes (vertex shader inputs) */
for (attr = 0; attr < draw->vertex_shader->state->num_inputs; attr++) {
@@ -111,7 +111,7 @@ void draw_vertex_fetch( struct draw_context *draw,
fetch_attrib4(src, draw->vertex_element[attr].src_format, p);
- /*printf(" %u: %f %f %f %f\n", attr, p[0], p[1], p[2], p[3]);*/
+ printf("> %u: %f %f %f %f\n", attr, p[0], p[1], p[2], p[3]);
/* Transform to AoS xxxx/yyyy/zzzz/wwww representation:
*/
diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c
index fd0183f8cd..874259e727 100644
--- a/src/mesa/pipe/draw/draw_vertex_shader.c
+++ b/src/mesa/pipe/draw/draw_vertex_shader.c
@@ -91,6 +91,8 @@ run_vertex_program(struct draw_context *draw,
assert(draw->vertex_shader->state->output_semantic_name[0]
== TGSI_SEMANTIC_POSITION);
+ fprintf(stderr, "------ run_vertex\n");
+
/* Consts does not require 16 byte alignment. */
machine->Consts = (float (*)[4]) draw->mapped_constants;
@@ -161,10 +163,6 @@ run_vertex_program(struct draw_context *draw,
vOut[j]->data[slot][3] = machine->Outputs[slot].xyzw[3].f[j];
#if DBG
printf("output[%d][%d]: %f %f %f %f\n", j, slot,
- vOut[j]->data[slot][0],
- vOut[j]->data[slot][1],
- vOut[j]->data[slot][2],
- vOut[j]->data[slot][3]);
#endif
}
} /* loop over vertices */
@@ -179,7 +177,12 @@ void draw_vertex_shader_queue_flush( struct draw_context *draw )
{
unsigned i, j;
-// fprintf(stderr, " q(%d) ", draw->vs.queue_nr );
+ fprintf(stderr, "XX q(%d) ", draw->vs.queue_nr );
+
+ if (draw->vertex_shader->state->llvm_prog) {
+ draw_vertex_shader_queue_flush_llvm(draw);
+ return;
+ }
/* run vertex shader on vertex cache entries, four per invokation */
for (i = 0; i < draw->vs.queue_nr; i += 4) {
diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
new file mode 100644
index 0000000000..b38498efc5
--- /dev/null
+++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
@@ -0,0 +1,129 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Zack Rusin zack@tungstengraphics.com
+ */
+
+#include "pipe/p_util.h"
+#include "draw_private.h"
+#include "draw_context.h"
+#include "draw_vertex.h"
+
+#include "pipe/llvm/llvmtgsi.h"
+#include "pipe/tgsi/exec/tgsi_core.h"
+
+static INLINE void
+fetch_attrib4(const void *ptr, unsigned format, float attrib[4])
+{
+ /* defaults */
+ attrib[1] = 0.0;
+ attrib[2] = 0.0;
+ attrib[3] = 1.0;
+ switch (format) {
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ attrib[3] = ((float *) ptr)[3];
+ /* fall-through */
+ case PIPE_FORMAT_R32G32B32_FLOAT:
+ attrib[2] = ((float *) ptr)[2];
+ /* fall-through */
+ case PIPE_FORMAT_R32G32_FLOAT:
+ attrib[1] = ((float *) ptr)[1];
+ /* fall-through */
+ case PIPE_FORMAT_R32_FLOAT:
+ attrib[0] = ((float *) ptr)[0];
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+/**
+ * Fetch vertex attributes for 'count' vertices.
+ */
+static INLINE
+void vertex_fetch(struct draw_context *draw,
+ const unsigned elt,
+ float (*inputs)[4])
+{
+ uint attr;
+
+ printf("fetch vertex %u: \n", elt);
+
+ /* loop over vertex attributes (vertex shader inputs) */
+ for (attr = 0; attr < draw->vertex_shader->state->num_inputs; attr++) {
+
+ unsigned buf = draw->vertex_element[attr].vertex_buffer_index;
+ const void *src
+ = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf]
+ + draw->vertex_buffer[buf].buffer_offset
+ + draw->vertex_element[attr].src_offset
+ + elt * draw->vertex_buffer[buf].pitch);
+ float p[4];
+
+ fetch_attrib4(src, draw->vertex_element[attr].src_format, p);
+
+ printf("> %u: %f %f %f %f\n", attr, p[0], p[1], p[2], p[3]);
+
+ inputs[attr][0] = p[0]; /*X*/
+ inputs[attr][1] = p[1]; /*Y*/
+ inputs[attr][2] = p[2]; /*Z*/
+ inputs[attr][3] = p[3]; /*W*/
+ }
+}
+
+
+/**
+ * Called by the draw module when the vertx cache needs to be flushed.
+ * This involves running the vertex shader.
+ */
+void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
+{
+ unsigned i;
+
+ struct vertex_header *dests[VS_QUEUE_LENGTH];
+ float inputs[VS_QUEUE_LENGTH][PIPE_MAX_SHADER_INPUTS][4];
+ float (*consts)[4] = (float (*)[4]) draw->mapped_constants;
+ struct ga_llvm_prog *prog = draw->vertex_shader->state->llvm_prog;
+
+ fprintf(stderr, "XX q(%d) ", draw->vs.queue_nr);
+
+ /* fetch the inputs */
+ for (i = 0; i < draw->vs.queue_nr; ++i) {
+ unsigned elt = draw->vs.queue[i].elt;
+ dests[i] = draw->vs.queue[i].dest;
+ vertex_fetch(draw, elt, inputs[i]);
+ }
+
+ /* batch execute the shaders on all the vertices */
+ ga_llvm_prog_exec(prog, inputs, dests, consts,
+ draw->vs.queue_nr);
+
+ draw->vs.queue_nr = 0;
+}
diff --git a/src/mesa/pipe/llvm/llvm_builtins.c b/src/mesa/pipe/llvm/llvm_builtins.c
new file mode 100644
index 0000000000..0f0efeb303
--- /dev/null
+++ b/src/mesa/pipe/llvm/llvm_builtins.c
@@ -0,0 +1,90 @@
+
+
+inline float4 compute_clip(float4 vec, float4 scale, float4 trans)
+{
+ return vec*scale + trans;
+}
+
+
+inline float
+dot4(const float4 a, const 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)
+{
+ unsigned mask = 0;
+ unsigned i;
+
+ for (i = 0; i < nr; i++) {
+ if (dot4(clip, plane[i]) < 0)
+ mask |= (1<<i);
+ }
+
+ return mask;
+}
+
+inline void collect_results(float4 *results, struct vertex_header *vOut,
+ float4 *planes, int nr_planes,
+ float4 scale, float4 trans)
+{
+ /* store results */
+ unsigned slot;
+ float x, y, z, w;
+
+ /* 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;
+
+ vOut[i]->clipmask = compute_clipmask(res0, planes, nr_planes);
+ vOut[i]->edgeflag = 1;
+
+ /* divide by w */
+ w = 1.0f / w;
+ x *= w;
+ y *= w;
+ z *= w;
+ 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;
+ vOut->data[0][3] = w;
+
+ /* Remaining attributes are packed into sequential post-transform
+ * vertex attrib slots.
+ * 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++) {
+ float4 vec = results[slot];
+ vOut->data[slot][0] = vec.x;
+ vOut->data[slot][1] = vec.y;
+ vOut->data[slot][2] = vec.z;
+ vOut->data[slot][3] = vec.w;
+
+ printf("output %d: %f %f %f %f\n", slot,
+ vOut->data[slot][0],
+ vOut->data[slot][1],
+ vOut->data[slot][2],
+ vOut->data[slot][3]);
+ }
+}
+
+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)
+{
+ float4 inputs[VS_QUEUE_LENGTH][PIPE_MAX_SHADER_INPUTS];
+ float4 *consts;
+}
diff --git a/src/mesa/pipe/llvm/llvmtgsi.cpp b/src/mesa/pipe/llvm/llvmtgsi.cpp
index 2221a2c353..46b7561b5e 100644
--- a/src/mesa/pipe/llvm/llvmtgsi.cpp
+++ b/src/mesa/pipe/llvm/llvmtgsi.cpp
@@ -426,7 +426,11 @@ void ga_llvm_prog_delete(struct ga_llvm_prog *prog)
free(prog);
}
-int ga_llvm_prog_exec(struct ga_llvm_prog *prog)
+int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
+ float (*inputs)[32][4],
+ void *dests[16*32*4],
+ float (*consts)[4],
+ int count)
{
//std::cout << "START "<<std::endl;
llvm::Module *mod = static_cast<llvm::Module*>(prog->module);
diff --git a/src/mesa/pipe/llvm/llvmtgsi.h b/src/mesa/pipe/llvm/llvmtgsi.h
index c0cee915b9..9fbb0ea8f9 100644
--- a/src/mesa/pipe/llvm/llvmtgsi.h
+++ b/src/mesa/pipe/llvm/llvmtgsi.h
@@ -18,7 +18,11 @@ ga_llvm_from_tgsi(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);
+int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
+ float (*inputs)[32][4],
+ void *dests[16*32*4],
+ float (*consts)[4],
+ int count);
#if defined __cplusplus
} // extern "C"
diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c
index 035f05170b..00afcd930a 100644
--- a/src/mesa/pipe/softpipe/sp_quad_fs.c
+++ b/src/mesa/pipe/softpipe/sp_quad_fs.c
@@ -109,7 +109,7 @@ shade_quad(
machine->InterpCoefs );
}
else {
- ga_llvm_prog_exec(softpipe->fs->llvm_prog);
+ //ga_llvm_prog_exec(softpipe->fs->llvm_prog);
quad->mask &= tgsi_exec_machine_run( machine );
}
diff --git a/src/mesa/sources b/src/mesa/sources
index 41c3ae387e..c2544ed322 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -172,6 +172,7 @@ DRAW_SOURCES = \
pipe/draw/draw_vertex_cache.c \
pipe/draw/draw_vertex_fetch.c \
pipe/draw/draw_vertex_shader.c \
+ pipe/draw/draw_vertex_shader_llvm.c \
pipe/draw/draw_wide_prims.c
TGSIEXEC_SOURCES = \