cbbfeeccc56c151e3ebc710a20e069af104180d8
[mesa.git] / src / gallium / auxiliary / draw / draw_llvm.h
1 #ifndef DRAW_LLVM_H
2 #define DRAW_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
13 struct draw_jit_texture
14 {
15 uint32_t width;
16 uint32_t height;
17 uint32_t stride;
18 const void *data;
19 };
20
21 enum {
22 DRAW_JIT_TEXTURE_WIDTH = 0,
23 DRAW_JIT_TEXTURE_HEIGHT,
24 DRAW_JIT_TEXTURE_STRIDE,
25 DRAW_JIT_TEXTURE_DATA
26 };
27
28 enum {
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 */
45 struct 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 /* we are construction a function of the form:
67
68 struct vertex_header {
69 uint32 vertex_id;
70
71 float clip[4];
72 float data[][4];
73 };
74
75 struct draw_jit_context
76 {
77 const float *vs_constants;
78 const float *gs_constants;
79
80 struct draw_jit_texture textures[PIPE_MAX_SAMPLERS];
81 };
82
83 void
84 draw_shader(struct draw_jit_context *context,
85 struct vertex_header *io,
86 const void *vbuffers[PIPE_MAX_ATTRIBS],
87 unsigned start,
88 unsigned count,
89 unsigned stride)
90 {
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,
100 context->vbuffers);
101
102 codegened_vertex_shader(header->data, context->vs_constants);
103 }
104
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];
109 }
110 codegened_geometry_shader(prim, gs_constants);
111 }
112 }
113 */
114
115 typedef void
116 (*draw_jit_vert_func)(struct draw_jit_context *context,
117 struct vertex_header *io,
118 const void *vbuffers[PIPE_MAX_ATTRIBS],
119 unsigned start,
120 unsigned count,
121 unsigned stride);
122
123 struct draw_llvm {
124 struct draw_context *draw;
125
126 struct draw_jit_context jit_context;
127
128 draw_jit_vert_func jit_func;
129
130 LLVMModuleRef module;
131 LLVMExecutionEngineRef engine;
132 LLVMModuleProviderRef provider;
133 LLVMTargetDataRef target;
134 LLVMPassManagerRef pass;
135
136 LLVMTypeRef context_ptr_type;
137 LLVMTypeRef vertex_header_ptr_type;
138 LLVMTypeRef buffer_ptr_type;
139 };
140
141
142 struct draw_llvm *
143 draw_llvm_create(struct draw_context *draw);
144
145 void
146 draw_llvm_destroy(struct draw_llvm *llvm);
147
148 void
149 draw_llvm_prepare(struct draw_llvm *llvm);
150
151 /* generates the draw jit function */
152 void
153 draw_llvm_generate(struct draw_llvm *llvm);
154
155 LLVMValueRef
156 draw_llvm_translate_from(LLVMBuilderRef builder,
157 LLVMValueRef vbuffer,
158 enum pipe_format from_format);
159
160 #endif