gallivm.h File Reference

Include dependency graph for gallivm.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  gallivm_shader_type { GALLIVM_VS, GALLIVM_FS }
enum  gallivm_vector_layout { GALLIVM_AOS, GALLIVM_SOA }

Functions

struct gallivm_irgallivm_ir_new (enum gallivm_shader_type type)
void gallivm_ir_set_layout (struct gallivm_ir *ir, enum gallivm_vector_layout layout)
void gallivm_ir_set_components (struct gallivm_ir *ir, int num)
void gallivm_ir_fill_from_tgsi (struct gallivm_ir *ir, const struct tgsi_token *tokens)
void gallivm_ir_delete (struct gallivm_ir *ir)
struct gallivm_proggallivm_ir_compile (struct gallivm_ir *ir)
void gallivm_prog_inputs_interpolate (struct gallivm_prog *prog, float(*inputs)[PIPE_MAX_SHADER_INPUTS][4], const struct tgsi_interp_coef *coefs)
void gallivm_prog_dump (struct gallivm_prog *prog, const char *file_prefix)
struct gallivm_cpu_enginegallivm_cpu_engine_create (struct gallivm_prog *prog)
 This function creates a CPU based execution engine for the given gallivm_prog.
struct gallivm_cpu_enginegallivm_global_cpu_engine ()
int gallivm_cpu_vs_exec (struct gallivm_prog *prog, struct tgsi_exec_machine *machine, const float(*input)[4], unsigned num_inputs, float(*output)[4], unsigned num_outputs, const float(*constants)[4], unsigned count, unsigned input_stride, unsigned output_stride)
 This function is used to execute the gallivm_prog in software.
int gallivm_cpu_fs_exec (struct gallivm_prog *prog, float x, float y, float(*dests)[PIPE_MAX_SHADER_INPUTS][4], float(*inputs)[PIPE_MAX_SHADER_INPUTS][4], float(*consts)[4], struct tgsi_sampler *samplers)
void gallivm_cpu_jit_compile (struct gallivm_cpu_engine *ee, struct gallivm_prog *prog)
 This function JIT compiles the given gallivm_prog with the given cpu based execution engine.
void gallivm_cpu_engine_delete (struct gallivm_cpu_engine *ee)


Enumeration Type Documentation

enum gallivm_shader_type

Enumerator:
GALLIVM_VS 
GALLIVM_FS 

Definition at line 63 of file gallivm.h.

00063                          {
00064    GALLIVM_VS,
00065    GALLIVM_FS
00066 };

enum gallivm_vector_layout

Enumerator:
GALLIVM_AOS 
GALLIVM_SOA 

Definition at line 68 of file gallivm.h.

00068                            {
00069    GALLIVM_AOS,
00070    GALLIVM_SOA
00071 };


Function Documentation

struct gallivm_cpu_engine* gallivm_cpu_engine_create ( struct gallivm_prog prog  )  [read]

This function creates a CPU based execution engine for the given gallivm_prog.

gallivm_cpu_engine should be used as a singleton throughout the library. Before executing gallivm_prog_exec one needs to call gallivm_cpu_jit_compile. The gallivm_prog instance which is being passed to the constructor is being automatically JIT compiled so one shouldn't call gallivm_cpu_jit_compile with it again.

Definition at line 131 of file gallivm_cpu.cpp.

References gallivm_cpu_engine::engine, func_for_shader(), gallivm_prog::function, and gallivm_prog::module.

00132 {
00133    struct gallivm_cpu_engine *cpu = (struct gallivm_cpu_engine *)
00134                                     calloc(1, sizeof(struct gallivm_cpu_engine));
00135    llvm::Module *mod = static_cast<llvm::Module*>(prog->module);
00136    llvm::ExistingModuleProvider *mp = new llvm::ExistingModuleProvider(mod);
00137    llvm::ExecutionEngine *ee = llvm::ExecutionEngine::create(mp, false);
00138    ee->DisableLazyCompilation();
00139    cpu->engine = ee;
00140 
00141    llvm::Function *func = func_for_shader(prog);
00142 
00143    prog->function = ee->getPointerToFunction(func);
00144    CPU = cpu;
00145    return cpu;
00146 }

void gallivm_cpu_engine_delete ( struct gallivm_cpu_engine ee  ) 

Definition at line 169 of file gallivm_cpu.cpp.

00170 {
00171    free(cpu);
00172 }

int gallivm_cpu_fs_exec ( struct gallivm_prog prog,
float  x,
float  y,
float *  dests[PIPE_MAX_SHADER_INPUTS][4],
float *  inputs[PIPE_MAX_SHADER_INPUTS][4],
float *  consts[4],
struct tgsi_sampler samplers 
)

void gallivm_cpu_jit_compile ( struct gallivm_cpu_engine cpu,
struct gallivm_prog prog 
)

This function JIT compiles the given gallivm_prog with the given cpu based execution engine.

The reference to the generated machine code entry point will be stored in the gallivm_prog program. After executing this function one can call gallivm_prog_exec in order to execute the gallivm_prog on the CPU.

Definition at line 155 of file gallivm_cpu.cpp.

References assert, gallivm_cpu_engine::engine, func_for_shader(), gallivm_prog::function, and gallivm_prog::module.

00156 {
00157    llvm::Module *mod = static_cast<llvm::Module*>(prog->module);
00158    llvm::ExistingModuleProvider *mp = new llvm::ExistingModuleProvider(mod);
00159    llvm::ExecutionEngine *ee = cpu->engine;
00160    assert(ee);
00161    /*FIXME : remove */
00162    ee->DisableLazyCompilation();
00163    ee->addModuleProvider(mp);
00164 
00165    llvm::Function *func = func_for_shader(prog);
00166    prog->function = ee->getPointerToFunction(func);
00167 }

int gallivm_cpu_vs_exec ( struct gallivm_prog prog,
struct tgsi_exec_machine machine,
const float *  input[4],
unsigned  num_inputs,
float *  output[4],
unsigned  num_outputs,
const float *  constants[4],
unsigned  count,
unsigned  input_stride,
unsigned  output_stride 
)

This function is used to execute the gallivm_prog in software.

Before calling this function the gallivm_prog has to be JIT compiled with the gallivm_cpu_jit_compile function.

Definition at line 191 of file gallivm_cpu.cpp.

References assert, tgsi_exec_channel::f, gallivm_prog::function, tgsi_exec_machine::Inputs, MAX_TGSI_VERTICES, MIN2, tgsi_exec_machine::Outputs, tgsi_exec_machine::Temps, and tgsi_exec_vector::xyzw.

00201 {
00202    unsigned int i, j;
00203    unsigned slot;
00204    vertex_shader_runner runner = reinterpret_cast<vertex_shader_runner>(prog->function);
00205 
00206    assert(runner);
00207 
00208    for (i = 0; i < count; i += MAX_TGSI_VERTICES) {
00209       unsigned int max_vertices = MIN2(MAX_TGSI_VERTICES, count - i);
00210 
00211       /* Swizzle inputs.
00212        */
00213       for (j = 0; j < max_vertices; j++) {
00214          for (slot = 0; slot < num_inputs; slot++) {
00215             machine->Inputs[slot].xyzw[0].f[j] = input[slot][0];
00216             machine->Inputs[slot].xyzw[1].f[j] = input[slot][1];
00217             machine->Inputs[slot].xyzw[2].f[j] = input[slot][2];
00218             machine->Inputs[slot].xyzw[3].f[j] = input[slot][3];
00219          }
00220 
00221          input = (const float (*)[4])((const char *)input + input_stride);
00222       }
00223 
00224       /* run shader */
00225       runner(machine->Inputs,
00226              machine->Outputs,
00227              (float (*)[4]) constants,
00228              machine->Temps);
00229 
00230       /* Unswizzle all output results
00231        */
00232       for (j = 0; j < max_vertices; j++) {
00233          for (slot = 0; slot < num_outputs; slot++) {
00234             output[slot][0] = machine->Outputs[slot].xyzw[0].f[j];
00235             output[slot][1] = machine->Outputs[slot].xyzw[1].f[j];
00236             output[slot][2] = machine->Outputs[slot].xyzw[2].f[j];
00237             output[slot][3] = machine->Outputs[slot].xyzw[3].f[j];
00238          }
00239          output = (float (*)[4])((char *)output + output_stride);
00240       }
00241    }
00242 
00243    return 0;
00244 }

struct gallivm_cpu_engine* gallivm_global_cpu_engine (  )  [read]

Definition at line 174 of file gallivm_cpu.cpp.

00175 {
00176    return CPU;
00177 }

struct gallivm_prog* gallivm_ir_compile ( struct gallivm_ir ir  )  [read]

Definition at line 302 of file gallivm.cpp.

References AddStandardCompilePasses(), gallivm_ir::interpolators, gallivm_prog::interpolators, gallivm_prog::module, gallivm_ir::module, gallivm_ir::num_consts, gallivm_prog::num_consts, gallivm_ir::num_interp, and gallivm_prog::num_interp.

00303 {
00304    struct gallivm_prog *prog =
00305       (struct gallivm_prog *)calloc(1, sizeof(struct gallivm_prog));
00306 
00307    std::cout << "Before optimizations:"<<std::endl;
00308    ir->module->dump();
00309    std::cout<<"-------------------------------"<<std::endl;
00310 
00311    PassManager veri;
00312    veri.add(createVerifierPass());
00313    veri.run(*ir->module);
00314    llvm::Module *mod = llvm::CloneModule(ir->module);
00315    prog->num_consts = ir->num_consts;
00316    memcpy(prog->interpolators, ir->interpolators, sizeof(prog->interpolators));
00317    prog->num_interp = ir->num_interp;
00318 
00319    /* Run optimization passes over it */
00320    PassManager passes;
00321    passes.add(new TargetData(mod));
00322    AddStandardCompilePasses(passes);
00323    passes.run(*mod);
00324    prog->module = mod;
00325 
00326    std::cout << "After optimizations:"<<std::endl;
00327    mod->dump();
00328 
00329    return prog;
00330 }

void gallivm_ir_delete ( struct gallivm_ir ir  ) 

Definition at line 296 of file gallivm.cpp.

References gallivm_ir::module.

00297 {
00298    delete ir->module;
00299    free(ir);
00300 }

void gallivm_ir_fill_from_tgsi ( struct gallivm_ir ir,
const struct tgsi_token tokens 
)

Definition at line 285 of file gallivm.cpp.

References gallivm_ir_dump(), gallivm_ir::module, tgsi_dump(), and tgsi_to_llvmir().

00287 {
00288    std::cout << "Creating llvm from: " <<std::endl;
00289    tgsi_dump(tokens, 0);
00290 
00291    llvm::Module *mod = tgsi_to_llvmir(ir, tokens);
00292    ir->module = mod;
00293    gallivm_ir_dump(ir, 0);
00294 }

struct gallivm_ir* gallivm_ir_new ( enum gallivm_shader_type  type  )  [read]

Definition at line 263 of file gallivm.cpp.

References GLOBAL_ID, gallivm_ir::id, and gallivm_ir::type.

00264 {
00265    struct gallivm_ir *ir =
00266       (struct gallivm_ir *)calloc(1, sizeof(struct gallivm_ir));
00267    ++GLOBAL_ID;
00268    ir->id   = GLOBAL_ID;
00269    ir->type = type;
00270 
00271    return ir;
00272 }

void gallivm_ir_set_components ( struct gallivm_ir ir,
int  num 
)

Definition at line 280 of file gallivm.cpp.

References gallivm_ir::num_components.

00281 {
00282    ir->num_components = num;
00283 }

void gallivm_ir_set_layout ( struct gallivm_ir ir,
enum gallivm_vector_layout  layout 
)

Definition at line 274 of file gallivm.cpp.

References gallivm_ir::layout.

00276 {
00277    ir->layout = layout;
00278 }

void gallivm_prog_dump ( struct gallivm_prog prog,
const char *  file_prefix 
)

void gallivm_prog_inputs_interpolate ( struct gallivm_prog prog,
float *  inputs[PIPE_MAX_SHADER_INPUTS][4],
const struct tgsi_interp_coef coefs 
)


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