Go to the source code of this file.
Data Structures | |
struct | gallivm_cpu_engine |
Defines | |
#define | MAX_TGSI_VERTICES 4 |
Typedefs | |
typedef int(* | fragment_shader_runner )(float x, float y, float(*dests)[16][4], float(*inputs)[16][4], int num_attribs, float(*consts)[4], int num_consts, struct tgsi_sampler *samplers) |
typedef void(* | vertex_shader_runner )(void *ainputs, void *dests, float(*aconsts)[4], void *temps) |
Functions | |
int | gallivm_cpu_fs_exec (struct gallivm_prog *prog, float fx, float fy, float(*dests)[16][4], float(*inputs)[16][4], float(*consts)[4], struct tgsi_sampler *samplers) |
static llvm::Function * | func_for_shader (struct gallivm_prog *prog) |
struct gallivm_cpu_engine * | gallivm_cpu_engine_create (struct gallivm_prog *prog) |
This function creates a CPU based execution engine for the given gallivm_prog. | |
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. | |
void | gallivm_cpu_engine_delete (struct gallivm_cpu_engine *cpu) |
struct gallivm_cpu_engine * | gallivm_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. | |
Variables | |
static struct gallivm_cpu_engine * | CPU = 0 |
#define MAX_TGSI_VERTICES 4 |
Definition at line 185 of file gallivm_cpu.cpp.
typedef int(* fragment_shader_runner)(float x, float y, float(*dests)[16][4], float(*inputs)[16][4], int num_attribs, float(*consts)[4], int num_consts, struct tgsi_sampler *samplers) |
Definition at line 82 of file gallivm_cpu.cpp.
typedef void(* vertex_shader_runner)(void *ainputs, void *dests, float(*aconsts)[4], void *temps) |
Definition at line 180 of file gallivm_cpu.cpp.
static llvm::Function* func_for_shader | ( | struct gallivm_prog * | prog | ) | [static] |
Definition at line 104 of file gallivm_cpu.cpp.
References assert, GALLIVM_FS, GALLIVM_VS, gallivm_prog::module, and gallivm_prog::type.
00105 { 00106 llvm::Module *mod = prog->module; 00107 llvm::Function *func = 0; 00108 00109 switch (prog->type) { 00110 case GALLIVM_VS: 00111 func = mod->getFunction("vs_shader"); 00112 break; 00113 case GALLIVM_FS: 00114 func = mod->getFunction("fs_shader"); 00115 break; 00116 default: 00117 assert(!"Unknown shader type!"); 00118 break; 00119 } 00120 return func; 00121 }
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 * | cpu | ) |
int gallivm_cpu_fs_exec | ( | struct gallivm_prog * | prog, | |
float | fx, | |||
float | fy, | |||
float * | dests[16][4], | |||
float * | inputs[16][4], | |||
float * | consts[4], | |||
struct tgsi_sampler * | samplers | |||
) |
Definition at line 89 of file gallivm_cpu.cpp.
References assert, gallivm_prog::function, gallivm_prog::num_consts, and gallivm_prog::num_interp.
00095 { 00096 fragment_shader_runner runner = reinterpret_cast<fragment_shader_runner>(prog->function); 00097 assert(runner); 00098 00099 return runner(fx, fy, dests, inputs, prog->num_interp, 00100 consts, prog->num_consts, 00101 samplers); 00102 }
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] |
struct gallivm_cpu_engine* CPU = 0 [static] |
Definition at line 80 of file gallivm_cpu.cpp.