draw_vs_llvm.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Zack Rusin
00031   *   Keith Whitwell <keith@tungstengraphics.com>
00032   *   Brian Paul
00033   */
00034 
00035 #include "util/u_memory.h"
00036 #include "pipe/p_shader_tokens.h"
00037 #include "draw_private.h"
00038 #include "draw_context.h"
00039 #include "draw_vs.h"
00040 
00041 #include "tgsi/tgsi_parse.h"
00042 
00043 #ifdef MESA_LLVM
00044 
00045 #include "gallivm/gallivm.h"
00046 
00047 struct draw_llvm_vertex_shader {
00048    struct draw_vertex_shader base;
00049    struct gallivm_prog *llvm_prog;
00050    struct tgsi_exec_machine *machine;
00051 };
00052 
00053 
00054 static void
00055 vs_llvm_prepare( struct draw_vertex_shader *base,
00056                  struct draw_context *draw )
00057 {
00058 }
00059 
00060 
00061 
00062 
00063 static void
00064 vs_llvm_run_linear( struct draw_vertex_shader *base,
00065                    const float (*input)[4],
00066                    float (*output)[4],
00067                    const float (*constants)[4],
00068                    unsigned count,
00069                    unsigned input_stride,
00070                    unsigned output_stride )
00071 {
00072    struct draw_llvm_vertex_shader *shader =
00073       (struct draw_llvm_vertex_shader *)base;
00074 
00075    gallivm_cpu_vs_exec(shader->llvm_prog, shader->machine,
00076                        input, base->info.num_inputs, output, base->info.num_outputs,
00077                        constants, count, input_stride, output_stride);
00078 }
00079 
00080 
00081 
00082 static void
00083 vs_llvm_delete( struct draw_vertex_shader *base )
00084 {
00085    struct draw_llvm_vertex_shader *shader =
00086       (struct draw_llvm_vertex_shader *)base;
00087 
00088    /* Do something to free compiled shader:
00089     */
00090 
00091    FREE( (void*) shader->base.state.tokens );
00092    FREE( shader );
00093 }
00094 
00095 
00096 
00097 
00098 struct draw_vertex_shader *
00099 draw_create_vs_llvm(struct draw_context *draw,
00100                     const struct pipe_shader_state *templ)
00101 {
00102    struct draw_llvm_vertex_shader *vs;
00103 
00104    vs = CALLOC_STRUCT( draw_llvm_vertex_shader );
00105    if (vs == NULL)
00106       return NULL;
00107 
00108    /* we make a private copy of the tokens */
00109    vs->base.state.tokens = tgsi_dup_tokens(templ->tokens);
00110    if (!vs->base.state.tokens) {
00111       FREE(vs);
00112       return NULL;
00113    }
00114 
00115    tgsi_scan_shader(vs->base.state.tokens, &vs->base.info);
00116 
00117    vs->base.draw = draw;
00118    vs->base.prepare = vs_llvm_prepare;
00119    vs->base.create_varient = draw_vs_varient_generic;
00120    vs->base.run_linear = vs_llvm_run_linear;
00121    vs->base.delete = vs_llvm_delete;
00122    vs->machine = &draw->vs.machine;
00123 
00124    {
00125       struct gallivm_ir *ir = gallivm_ir_new(GALLIVM_VS);
00126       gallivm_ir_set_layout(ir, GALLIVM_SOA);
00127       gallivm_ir_set_components(ir, 4);
00128       gallivm_ir_fill_from_tgsi(ir, vs->base.state.tokens);
00129       vs->llvm_prog = gallivm_ir_compile(ir);
00130       gallivm_ir_delete(ir);
00131    }
00132 
00133    draw->vs.engine = gallivm_global_cpu_engine();
00134 
00135    /* XXX: Why are there two versions of this?  Shouldn't creating the
00136     *      engine be a separate operation to compiling a shader?
00137     */
00138    if (!draw->vs.engine) {
00139       draw->vs.engine = gallivm_cpu_engine_create(vs->llvm_prog);
00140    }
00141    else {
00142       gallivm_cpu_jit_compile(draw->vs.engine, vs->llvm_prog);
00143    }
00144 
00145    return &vs->base;
00146 }
00147 
00148 
00149 
00150 
00151 
00152 #else
00153 
00154 struct draw_vertex_shader *
00155 draw_create_vs_llvm(struct draw_context *draw,
00156                           const struct pipe_shader_state *shader)
00157 {
00158    return NULL;
00159 }
00160 
00161 #endif

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4