Execution engine is a singleton, for now keep it in the pipe.
authorZack Rusin <zack@tungstengraphics.com>
Mon, 15 Oct 2007 13:59:19 +0000 (09:59 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Wed, 24 Oct 2007 15:21:03 +0000 (11:21 -0400)
src/mesa/Makefile
src/mesa/pipe/draw/draw_vertex_shader_llvm.c
src/mesa/pipe/llvm/llvmtgsi.cpp
src/mesa/pipe/llvm/llvmtgsi.h
src/mesa/pipe/p_context.h
src/mesa/state_tracker/st_program.c

index cb7c466f47505f4d46e5c4858315511539dc27d9..5b56f76e0be89e07a552b19babebeecde870aebf 100644 (file)
@@ -113,11 +113,11 @@ osmesa-only: depend subdirs $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME)
 
 # Make the GL library
 $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(STAND_ALONE_OBJECTS) $(SOFTPIPE_LIB)
-       $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' \
+       $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' \
                -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \
                -install $(TOP)/$(LIB_DIR) \
-               $(MKLIB_OPTIONS) $(GL_LIB_DEPS) $(STAND_ALONE_OBJECTS) \
-               $(SOFTPIPE_LIB)
+               $(MKLIB_OPTIONS) $(STAND_ALONE_OBJECTS) \
+               $(SOFTPIPE_LIB) $(GL_LIB_DEPS)
 
 # Make the OSMesa library
 $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME): $(OSMESA_DRIVER_OBJECTS) $(OSMESA16_OBJECTS)
index fd499010516da5636cb297087a3e81ae1600b67f..37315f75662ff5cfb3a4c9a37746bab3af714197 100644 (file)
@@ -98,6 +98,10 @@ void vertex_fetch(struct draw_context *draw,
    }
 }
 
+void execute_shader(void *dests, void *inputs, void *consts)
+{
+   fprintf(stderr, "EXECUTING--\n");
+}
 
 /**
  * Called by the draw module when the vertx cache needs to be flushed.
@@ -109,10 +113,33 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
 
    struct vertex_header *dests[VS_QUEUE_LENGTH];
    float                 inputs[VS_QUEUE_LENGTH][PIPE_MAX_SHADER_INPUTS][4];
+   float                 outputs[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);
+   fprintf(stderr, "--- XX q(%d) \n", draw->vs.queue_nr);
+   /* Consts does not require 16 byte alignment. */
+   fprintf(stderr, "0AAAAA = %f %f %f %f\n",
+           consts[0][0],
+           consts[0][1],
+           consts[0][2],
+           consts[0][3]);
+
+      fprintf(stderr, "1AAAAA = %f %f %f %f\n",
+           consts[1][0],
+           consts[1][1],
+           consts[1][2],
+           consts[1][3]);
+         fprintf(stderr, "2AAAAA = %f %f %f %f\n",
+           consts[2][0],
+           consts[2][1],
+           consts[2][2],
+                 consts[2][3]);
+         fprintf(stderr, "3AAAAA = %f %f %f %f\n",
+           consts[3][0],
+           consts[3][1],
+           consts[3][2],
+           consts[3][3]);
 
    /* fetch the inputs */
    for (i = 0; i < draw->vs.queue_nr; ++i) {
@@ -122,9 +149,12 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
    }
 
    /* batch execute the shaders on all the vertices */
-   ga_llvm_prog_exec(prog, inputs, dests, consts,
+   ga_llvm_prog_exec(prog, inputs, outputs, consts,
                      draw->vs.queue_nr,
                      draw->vertex_info.num_attribs);
 
+   /* FIXME: finish conversion */
+   /* dests = outputs */
+
    draw->vs.queue_nr = 0;
 }
index 1abc148521f2d985fc8bb7a5707e00ad2c645e05..a616355f8fd3e64da88bdb067caea4d834dc3574 100644 (file)
@@ -1,5 +1,6 @@
 #include "llvmtgsi.h"
 
+#include "pipe/p_context.h"
 #include "pipe/tgsi/exec/tgsi_exec.h"
 #include "pipe/tgsi/exec/tgsi_token.h"
 #include "pipe/tgsi/exec/tgsi_build.h"
@@ -469,7 +470,7 @@ tgsi_to_llvm(const struct tgsi_token *tokens)
 }
 
 struct ga_llvm_prog *
-ga_llvm_from_tgsi(const struct tgsi_token *tokens)
+ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens)
 {
    std::cout << "Creating llvm " <<std::endl;
    struct ga_llvm_prog *ga_llvm =
@@ -487,20 +488,24 @@ ga_llvm_from_tgsi(const struct tgsi_token *tokens)
 
    llvm::ExistingModuleProvider *mp =
       new llvm::ExistingModuleProvider(mod);
-   llvm::ExecutionEngine *ee =
-      llvm::ExecutionEngine::create(mp, false);
-
+   llvm::ExecutionEngine *ee = 0;
+   if (!pipe->llvm_execution_engine) {
+      ee = llvm::ExecutionEngine::create(mp, false);
+      pipe->llvm_execution_engine = ee;
+   } else {
+      ee = (llvm::ExecutionEngine*)pipe->llvm_execution_engine;
+      ee->addModuleProvider(mp);
+   }
    ga_llvm->module = mod;
-   ga_llvm->engine = ee;
    fprintf(stderr, "DUMPX \n");
    //tgsi_dump(tokens, TGSI_DUMP_VERBOSE);
    tgsi_dump(tokens, 0);
    fprintf(stderr, "DUMPEND \n");
 
    Function *func = mod->getFunction("run_vertex_shader");
-   std::cout << "run_vertex_shader  = "<<func;
+   std::cout << "run_vertex_shader  = "<<func<<std::endl;
    ga_llvm->function = ee->getPointerToFunctionOrStub(func);
-   std::cout << " -- FUNC is " <<ga_llvm->function;
+   std::cout << " -- FUNC is " <<ga_llvm->function<<std::endl;
 
    return ga_llvm;
 }
@@ -515,15 +520,22 @@ void ga_llvm_prog_delete(struct ga_llvm_prog *prog)
    free(prog);
 }
 
+typedef void (*vertex_shader_runner)(float (*ainputs)[32][4],
+                                  float (*dests)[32][4],
+                                  float (*aconsts)[4],
+                                  int count,
+                                  int num_attribs);
+
 int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
                       float (*inputs)[32][4],
-                      void *dests[16*32*4],
+                      float (*dests)[32][4],
                       float (*consts)[4],
                       int count,
                       int num_attribs)
 {
    std::cout << "---- START LLVM Execution "<<std::endl;
-
+   vertex_shader_runner runner = reinterpret_cast<vertex_shader_runner>(prog->function);
+   runner(inputs, dests, consts, count, num_attribs);
 
    std::cout << "---- END LLVM Execution "<<std::endl;
    return 0;
index b1b5717f6d0a0a409dda4534d672dd393aa68907..f78fbce4c61eccf0aafe3a182dc683a0229bbcb7 100644 (file)
@@ -8,6 +8,7 @@ extern "C" {
 struct tgsi_exec_machine;
 struct tgsi_token;
 struct tgsi_sampler;
+struct pipe_context;
 
 struct ga_llvm_prog {
    void *module;
@@ -15,13 +16,13 @@ struct ga_llvm_prog {
    void *function;
 };
 struct ga_llvm_prog *
-ga_llvm_from_tgsi(const struct tgsi_token *tokens);
+ga_llvm_from_tgsi(struct pipe_context *pipe, 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,
                       float (*inputs)[32][4],
-                      void *dests[16*32*4],
+                      float (*dests)[32][4],
                       float (*consts)[4],
                       int count,
                       int num_attribs);
index 8ba1031efe51e9d4c6860e18d7bc46019bd1f1b1..2558a6341ce53bc7481c40d8dbd78bb6c3471f57 100644 (file)
@@ -38,7 +38,9 @@ struct pipe_state_cache;
  */
 struct pipe_context {
    struct pipe_winsys *winsys;
-   
+
+   void *llvm_execution_engine;
+
    void (*destroy)( struct pipe_context * );
 
    /*
index edb2703101f9b8a8ec83513ca925978aa804bfd8..0f9d76926421d16dc40d0fb885a54a751c03bb27 100644 (file)
@@ -251,7 +251,7 @@ st_translate_vertex_program(struct st_context *st,
                                 tokensOut, maxTokens);
 
    vs.tokens = tokensOut;
-   vs.llvm_prog = ga_llvm_from_tgsi(vs.tokens);
+   vs.llvm_prog = ga_llvm_from_tgsi(st->pipe, vs.tokens);
    cso = st_cached_vs_state(st, &vs);
    stvp->vs = cso;
 
@@ -407,7 +407,7 @@ st_translate_fragment_program(struct st_context *st,
                                 tokensOut, maxTokens);
 
    fs.tokens = tokensOut;
-   fs.llvm_prog = ga_llvm_from_tgsi(fs.tokens);
+   fs.llvm_prog = ga_llvm_from_tgsi(st->pipe, fs.tokens);
    cso = st_cached_fs_state(st, &fs);
    stfp->fs = cso;