draw_llvm.h revision 52f145a186b8e47439fb4a96d04a099d439477b7
1#ifndef HAVE_LLVM_H 2#define HAVE_LLVM_H 3 4#include "draw/draw_private.h" 5 6#include "pipe/p_context.h" 7 8#include <llvm-c/Core.h> 9#include <llvm-c/Analysis.h> 10#include <llvm-c/Target.h> 11#include <llvm-c/ExecutionEngine.h> 12 13struct draw_jit_texture 14{ 15 uint32_t width; 16 uint32_t height; 17 uint32_t stride; 18 const void *data; 19}; 20 21enum { 22 DRAW_JIT_TEXTURE_WIDTH = 0, 23 DRAW_JIT_TEXTURE_HEIGHT, 24 DRAW_JIT_TEXTURE_STRIDE, 25 DRAW_JIT_TEXTURE_DATA 26}; 27 28enum { 29 DRAW_JIT_VERTEX_VERTEX_ID = 0, 30 DRAW_JIT_VERTEX_CLIP, 31 DRAW_JIT_VERTEX_DATA 32}; 33 34/** 35 * This structure is passed directly to the generated vertex shader. 36 * 37 * It contains the derived state. 38 * 39 * Changes here must be reflected in the draw_jit_context_* macros. 40 * Changes to the ordering should be avoided. 41 * 42 * Only use types with a clear size and padding here, in particular prefer the 43 * stdint.h types to the basic integer types. 44 */ 45struct draw_jit_context 46{ 47 const float *vs_constants; 48 const float *gs_constants; 49 50 51 struct draw_jit_texture textures[PIPE_MAX_SAMPLERS]; 52}; 53 54 55#define draw_jit_context_vs_constants(_builder, _ptr) \ 56 lp_build_struct_get(_builder, _ptr, 0, "vs_constants") 57 58#define draw_jit_context_gs_constants(_builder, _ptr) \ 59 lp_build_struct_get(_builder, _ptr, 1, "gs_constants") 60 61#define DRAW_JIT_CONTEXT_TEXTURES_INDEX 2 62 63#define draw_jit_context_textures(_builder, _ptr) \ 64 lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CONTEXT_TEXTURES_INDEX, "textures") 65 66 67 68#define draw_jit_header_id(_builder, _ptr) \ 69 lp_build_struct_get_ptr(_builder, _ptr, 0, "id") 70 71#define draw_jit_header_clip(_builder, _ptr) \ 72 lp_build_struct_get(_builder, _ptr, 1, "clip") 73 74#define draw_jit_header_data(_builder, _ptr) \ 75 lp_build_struct_get_ptr(_builder, _ptr, 2, "data") 76 77 78#define draw_jit_vbuffer_stride(_builder, _ptr) \ 79 lp_build_struct_get(_builder, _ptr, 0, "stride") 80 81#define draw_jit_vbuffer_max_index(_builder, _ptr) \ 82 lp_build_struct_get(_builder, _ptr, 1, "max_index") 83 84#define draw_jit_vbuffer_offset(_builder, _ptr) \ 85 lp_build_struct_get(_builder, _ptr, 2, "buffer_offset") 86 87 88typedef void 89(*draw_jit_vert_func)(struct draw_jit_context *context, 90 struct vertex_header *io, 91 const char *vbuffers[PIPE_MAX_ATTRIBS], 92 unsigned start, 93 unsigned count, 94 unsigned stride, 95 struct pipe_vertex_buffer *vertex_buffers); 96 97 98typedef void 99(*draw_jit_vert_func_elts)(struct draw_jit_context *context, 100 struct vertex_header *io, 101 const char *vbuffers[PIPE_MAX_ATTRIBS], 102 const unsigned *fetch_elts, 103 unsigned fetch_count, 104 unsigned stride, 105 struct pipe_vertex_buffer *vertex_buffers); 106 107struct draw_llvm { 108 struct draw_context *draw; 109 110 struct draw_jit_context jit_context; 111 112 LLVMModuleRef module; 113 LLVMExecutionEngineRef engine; 114 LLVMModuleProviderRef provider; 115 LLVMTargetDataRef target; 116 LLVMPassManagerRef pass; 117 118 LLVMTypeRef context_ptr_type; 119 LLVMTypeRef vertex_header_ptr_type; 120 LLVMTypeRef buffer_ptr_type; 121 LLVMTypeRef vb_ptr_type; 122}; 123 124struct draw_llvm_variant_key 125{ 126 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; 127 unsigned nr_vertex_elements; 128 struct pipe_shader_state vs; 129}; 130 131struct draw_llvm_variant 132{ 133 struct draw_llvm_variant_key key; 134 LLVMValueRef function; 135 LLVMValueRef function_elts; 136 draw_jit_vert_func jit_func; 137 draw_jit_vert_func_elts jit_func_elts; 138 139 struct draw_llvm_variant *next; 140}; 141 142struct draw_llvm * 143draw_llvm_create(struct draw_context *draw); 144 145void 146draw_llvm_destroy(struct draw_llvm *llvm); 147 148struct draw_llvm_variant * 149draw_llvm_prepare(struct draw_llvm *llvm, int num_inputs); 150 151void 152draw_llvm_make_variant_key(struct draw_llvm *llvm, 153 struct draw_llvm_variant_key *key); 154 155LLVMValueRef 156draw_llvm_translate_from(LLVMBuilderRef builder, 157 LLVMValueRef vbuffer, 158 enum pipe_format from_format); 159#endif 160