00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
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
00136
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