4 #include "draw/draw_private.h"
6 #include "pipe/p_context.h"
8 #include <llvm-c/Core.h>
9 #include <llvm-c/Analysis.h>
10 #include <llvm-c/Target.h>
11 #include <llvm-c/ExecutionEngine.h>
13 struct draw_jit_texture
22 DRAW_JIT_TEXTURE_WIDTH
= 0,
23 DRAW_JIT_TEXTURE_HEIGHT
,
24 DRAW_JIT_TEXTURE_STRIDE
,
29 DRAW_JIT_VERTEX_VERTEX_ID
= 0,
35 * This structure is passed directly to the generated vertex shader.
37 * It contains the derived state.
39 * Changes here must be reflected in the draw_jit_context_* macros.
40 * Changes to the ordering should be avoided.
42 * Only use types with a clear size and padding here, in particular prefer the
43 * stdint.h types to the basic integer types.
45 struct draw_jit_context
47 const float *vs_constants
;
48 const float *gs_constants
;
51 struct draw_jit_texture textures
[PIPE_MAX_SAMPLERS
];
55 #define draw_jit_context_vs_constants(_builder, _ptr) \
56 lp_build_struct_get(_builder, _ptr, 0, "vs_constants")
58 #define draw_jit_context_gs_constants(_builder, _ptr) \
59 lp_build_struct_get(_builder, _ptr, 1, "gs_constants")
61 #define DRAW_JIT_CONTEXT_TEXTURES_INDEX 2
63 #define draw_jit_context_textures(_builder, _ptr) \
64 lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CONTEXT_TEXTURES_INDEX, "textures")
68 #define draw_jit_header_id(_builder, _ptr) \
69 lp_build_struct_get_ptr(_builder, _ptr, 0, "id")
71 #define draw_jit_header_clip(_builder, _ptr) \
72 lp_build_struct_get(_builder, _ptr, 1, "clip")
74 #define draw_jit_header_data(_builder, _ptr) \
75 lp_build_struct_get_ptr(_builder, _ptr, 2, "data")
77 /* we are construction a function of the form:
79 struct vertex_header {
86 struct draw_jit_context
88 const float *vs_constants;
89 const float *gs_constants;
91 struct draw_jit_texture textures[PIPE_MAX_SAMPLERS];
95 draw_shader(struct draw_jit_context *context,
96 struct vertex_header *io,
97 const void *vbuffers[PIPE_MAX_ATTRIBS],
102 // do a fetch and a run vertex shader
103 for (int i = 0; i < count; ++i) {
104 struct vertex_header *header = &io[i];
105 header->vertex_id = 0xffff;
106 // follows code-genarted fetch/translate section
107 // for each vertex_element ...
108 codegened_translate(header->data[num_element],
109 context->vertex_elements[num_element],
110 context->vertex_buffers,
113 codegened_vertex_shader(header->data, context->vs_constants);
116 for (int i = 0; i < count; i += context->primitive_size) {
117 struct vertex_header *prim[MAX_PRIMITIVE_SIZE];
118 for (int j = 0; j < context->primitive_size; ++j) {
119 header[j] = &io[i + j];
121 codegened_geometry_shader(prim, gs_constants);
127 (*draw_jit_vert_func
)(struct draw_jit_context
*context
,
128 struct vertex_header
*io
,
129 const char *vbuffers
[PIPE_MAX_ATTRIBS
],
135 struct draw_context
*draw
;
137 struct draw_jit_context jit_context
;
139 LLVMModuleRef module
;
140 LLVMExecutionEngineRef engine
;
141 LLVMModuleProviderRef provider
;
142 LLVMTargetDataRef target
;
143 LLVMPassManagerRef pass
;
145 LLVMTypeRef context_ptr_type
;
146 LLVMTypeRef vertex_header_ptr_type
;
147 LLVMTypeRef buffer_ptr_type
;
151 struct draw_llvm_variant_key
153 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
154 unsigned nr_vertex_buffers
;
155 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
156 unsigned nr_vertex_elements
;
157 struct pipe_shader_state vs
;
160 struct draw_llvm_variant
162 struct draw_llvm_variant_key key
;
163 LLVMValueRef function
;
164 draw_jit_vert_func jit_func
;
166 struct draw_llvm_variant
*next
;
170 draw_llvm_create(struct draw_context
*draw
);
173 draw_llvm_destroy(struct draw_llvm
*llvm
);
175 struct draw_llvm_variant
*
176 draw_llvm_prepare(struct draw_llvm
*llvm
, int num_inputs
);
179 draw_llvm_make_variant_key(struct draw_llvm
*llvm
,
180 struct draw_llvm_variant_key
*key
);
183 draw_llvm_translate_from(LLVMBuilderRef builder
,
184 LLVMValueRef vbuffer
,
185 enum pipe_format from_format
);