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")
66 /* we are construction a function of the form:
68 struct vertex_header {
75 struct draw_jit_context
77 const float *vs_constants;
78 const float *gs_constants;
80 struct draw_jit_texture textures[PIPE_MAX_SAMPLERS];
84 draw_shader(struct draw_jit_context *context,
85 struct vertex_header *io,
86 const void *vbuffers[PIPE_MAX_ATTRIBS],
91 // do a fetch and a run vertex shader
92 for (int i = 0; i < count; ++i) {
93 struct vertex_header *header = &io[i];
94 header->vertex_id = 0xffff;
95 // follows code-genarted fetch/translate section
96 // for each vertex_element ...
97 codegened_translate(header->data[num_element],
98 context->vertex_elements[num_element],
99 context->vertex_buffers,
102 codegened_vertex_shader(header->data, context->vs_constants);
105 for (int i = 0; i < count; i += context->primitive_size) {
106 struct vertex_header *prim[MAX_PRIMITIVE_SIZE];
107 for (int j = 0; j < context->primitive_size; ++j) {
108 header[j] = &io[i + j];
110 codegened_geometry_shader(prim, gs_constants);
116 (*draw_jit_vert_func
)(struct draw_jit_context
*context
,
117 struct vertex_header
*io
,
118 const void *vbuffers
[PIPE_MAX_ATTRIBS
],
124 struct draw_context
*draw
;
126 struct draw_jit_context jit_context
;
128 draw_jit_vert_func jit_func
;
130 LLVMModuleRef module
;
131 LLVMExecutionEngineRef engine
;
132 LLVMModuleProviderRef provider
;
133 LLVMTargetDataRef target
;
134 LLVMPassManagerRef pass
;
136 LLVMTypeRef context_ptr_type
;
137 LLVMTypeRef vertex_header_ptr_type
;
138 LLVMTypeRef buffer_ptr_type
;
143 draw_llvm_create(struct draw_context
*draw
);
146 draw_llvm_destroy(struct draw_llvm
*llvm
);
149 draw_llvm_prepare(struct draw_llvm
*llvm
);
151 /* generates the draw jit function */
153 draw_llvm_generate(struct draw_llvm
*llvm
);
156 draw_llvm_translate_from(LLVMBuilderRef builder
,
157 LLVMValueRef vbuffer
,
158 enum pipe_format from_format
);