4e7859d5dacf9b24e64e3446e04c504556cdf9ce
[mesa.git] / src / gallium / auxiliary / draw / draw_llvm.h
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef DRAW_LLVM_H
29 #define DRAW_LLVM_H
30
31 #include "draw/draw_private.h"
32
33 #include "draw/draw_vs.h"
34 #include "draw/draw_gs.h"
35 #include "draw/draw_tess.h"
36
37 #include "gallivm/lp_bld_sample.h"
38 #include "gallivm/lp_bld_limits.h"
39
40 #include "pipe/p_context.h"
41 #include "util/simple_list.h"
42
43
44 struct draw_llvm;
45 struct llvm_vertex_shader;
46 struct llvm_geometry_shader;
47
48 struct draw_jit_texture
49 {
50 uint32_t width;
51 uint32_t height;
52 uint32_t depth;
53 const void *base;
54 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
55 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
56 uint32_t first_level;
57 uint32_t last_level;
58 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
59 };
60
61
62 struct draw_sampler_static_state
63 {
64 /*
65 * These attributes are effectively interleaved for more sane key handling.
66 * However, there might be lots of null space if the amount of samplers and
67 * textures isn't the same.
68 */
69 struct lp_static_sampler_state sampler_state;
70 struct lp_static_texture_state texture_state;
71 };
72
73 struct draw_image_static_state
74 {
75 struct lp_static_texture_state image_state;
76 };
77
78
79 struct draw_jit_sampler
80 {
81 float min_lod;
82 float max_lod;
83 float lod_bias;
84 float border_color[4];
85 };
86
87
88 struct draw_jit_image
89 {
90 uint32_t width;
91 uint32_t height;
92 uint32_t depth;
93 const void *base;
94 uint32_t row_stride;
95 uint32_t img_stride;
96 };
97
98 enum {
99 DRAW_JIT_TEXTURE_WIDTH = 0,
100 DRAW_JIT_TEXTURE_HEIGHT,
101 DRAW_JIT_TEXTURE_DEPTH,
102 DRAW_JIT_TEXTURE_BASE,
103 DRAW_JIT_TEXTURE_ROW_STRIDE,
104 DRAW_JIT_TEXTURE_IMG_STRIDE,
105 DRAW_JIT_TEXTURE_FIRST_LEVEL,
106 DRAW_JIT_TEXTURE_LAST_LEVEL,
107 DRAW_JIT_TEXTURE_MIP_OFFSETS,
108 DRAW_JIT_TEXTURE_NUM_FIELDS /* number of fields above */
109 };
110
111
112 enum {
113 DRAW_JIT_SAMPLER_MIN_LOD,
114 DRAW_JIT_SAMPLER_MAX_LOD,
115 DRAW_JIT_SAMPLER_LOD_BIAS,
116 DRAW_JIT_SAMPLER_BORDER_COLOR,
117 DRAW_JIT_SAMPLER_NUM_FIELDS /* number of fields above */
118 };
119
120
121 enum {
122 DRAW_JIT_VERTEX_VERTEX_ID = 0,
123 DRAW_JIT_VERTEX_CLIP_POS,
124 DRAW_JIT_VERTEX_DATA
125 };
126
127 enum {
128 DRAW_JIT_IMAGE_WIDTH = 0,
129 DRAW_JIT_IMAGE_HEIGHT,
130 DRAW_JIT_IMAGE_DEPTH,
131 DRAW_JIT_IMAGE_BASE,
132 DRAW_JIT_IMAGE_ROW_STRIDE,
133 DRAW_JIT_IMAGE_IMG_STRIDE,
134 DRAW_JIT_IMAGE_NUM_FIELDS /* number of fields above */
135 };
136
137 /**
138 * This structure is passed directly to the generated vertex shader.
139 *
140 * It contains the derived state.
141 *
142 * Changes here must be reflected in the draw_jit_context_* macros.
143 * Changes to the ordering should be avoided.
144 *
145 * Only use types with a clear size and padding here, in particular prefer the
146 * stdint.h types to the basic integer types.
147 */
148 struct draw_jit_context
149 {
150 const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
151 int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
152 float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
153 struct pipe_viewport_state *viewports;
154
155 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
156 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
157 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
158
159 const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
160 int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
161 };
162
163 enum {
164 DRAW_JIT_CTX_CONSTANTS = 0,
165 DRAW_JIT_CTX_NUM_CONSTANTS = 1,
166 DRAW_JIT_CTX_PLANES = 2,
167 DRAW_JIT_CTX_VIEWPORT = 3,
168 DRAW_JIT_CTX_TEXTURES = 4,
169 DRAW_JIT_CTX_SAMPLERS = 5,
170 DRAW_JIT_CTX_IMAGES = 6,
171 DRAW_JIT_CTX_SSBOS = 7,
172 DRAW_JIT_CTX_NUM_SSBOS = 8,
173 DRAW_JIT_CTX_NUM_FIELDS
174 };
175
176 #define draw_jit_context_vs_constants(_gallivm, _ptr) \
177 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
178
179 #define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
180 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
181
182 #define draw_jit_context_planes(_gallivm, _ptr) \
183 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
184
185 #define draw_jit_context_viewports(_gallivm, _ptr) \
186 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
187
188 #define draw_jit_context_textures(_gallivm, _ptr) \
189 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
190
191 #define draw_jit_context_samplers(_gallivm, _ptr) \
192 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
193
194 #define draw_jit_context_images(_gallivm, _ptr) \
195 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
196
197 #define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
198 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
199
200 #define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
201 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
202
203
204 #define draw_jit_header_id(_gallivm, _ptr) \
205 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
206
207 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
208 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
209
210 #define draw_jit_header_data(_gallivm, _ptr) \
211 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
212
213
214 #define draw_jit_vbuffer_stride(_gallivm, _ptr) \
215 lp_build_struct_get(_gallivm, _ptr, 0, "stride")
216
217 #define draw_jit_vbuffer_offset(_gallivm, _ptr) \
218 lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
219
220 enum {
221 DRAW_JIT_DVBUFFER_MAP = 0,
222 DRAW_JIT_DVBUFFER_SIZE,
223 DRAW_JIT_DVBUFFER_NUM_FIELDS /* number of fields above */
224 };
225
226 #define draw_jit_dvbuffer_map(_gallivm, _ptr) \
227 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
228
229 #define draw_jit_dvbuffer_size(_gallivm, _ptr) \
230 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
231
232
233 /**
234 * This structure is passed directly to the generated geometry shader.
235 *
236 * It contains the derived state.
237 *
238 * Changes here must be reflected in the draw_gs_jit_context_* macros.
239 * Changes to the ordering should be avoided.
240 *
241 * Only use types with a clear size and padding here, in particular prefer the
242 * stdint.h types to the basic integer types.
243 */
244 struct draw_gs_jit_context
245 {
246 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
247 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
248 float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
249 struct pipe_viewport_state *viewports;
250
251 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
252 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
253 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
254 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
255 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
256
257 int **prim_lengths;
258 int *emitted_vertices;
259 int *emitted_prims;
260 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
261 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
262
263 };
264
265 enum {
266 DRAW_GS_JIT_CTX_CONSTANTS = 0,
267 DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,
268 DRAW_GS_JIT_CTX_PLANES = 2,
269 DRAW_GS_JIT_CTX_VIEWPORT = 3,
270 /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
271 * and DRAW_JIT_CTX_SAMPLERS, because they both need
272 * to be at exactly the same locations as they are in the
273 * VS ctx structure for sampling to work. */
274 DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
275 DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
276 DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
277 DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,
278 DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,
279 DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,
280 DRAW_GS_JIT_CTX_SSBOS = 10,
281 DRAW_GS_JIT_CTX_NUM_SSBOS = 11,
282 DRAW_GS_JIT_CTX_NUM_FIELDS = 12
283 };
284
285 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
286 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
287
288 #define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
289 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
290
291 #define draw_gs_jit_context_planes(_gallivm, _ptr) \
292 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
293
294 #define draw_gs_jit_context_viewports(_gallivm, _ptr) \
295 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
296
297 #define draw_gs_jit_context_textures(_gallivm, _ptr) \
298 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
299
300 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
301 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
302
303 #define draw_gs_jit_context_images(_gallivm, _ptr) \
304 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
305
306 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
307 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
308
309 #define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
310 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
311
312 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
313 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
314
315 #define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
316 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
317
318 #define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
319 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
320
321
322 struct draw_tcs_jit_context {
323 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
324 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
325
326 int dummy1;
327 int dummy2;
328 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
329 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
330 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
331 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
332 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
333
334 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
335 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
336 };
337
338 enum {
339 DRAW_TCS_JIT_CTX_CONSTANTS = 0,
340 DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1,
341 DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
342 DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
343 DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
344 DRAW_TCS_JIT_CTX_SSBOS = 7,
345 DRAW_TCS_JIT_CTX_NUM_SSBOS = 8,
346 DRAW_TCS_JIT_CTX_NUM_FIELDS = 9,
347 };
348
349 #define draw_tcs_jit_context_constants(_gallivm, _ptr) \
350 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
351
352 #define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \
353 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")
354
355 #define draw_tcs_jit_context_textures(_gallivm, _ptr) \
356 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
357
358 #define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
359 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
360
361 #define draw_tcs_jit_context_images(_gallivm, _ptr) \
362 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
363
364 #define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
365 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
366
367 #define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \
368 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
369
370 struct draw_tes_jit_context {
371 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
372 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
373
374 int dummy1;
375 int dummy2;
376 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
377 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
378 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
379 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
380 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
381
382 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
383 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
384 };
385
386 enum {
387 DRAW_TES_JIT_CTX_CONSTANTS = 0,
388 DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1,
389 DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
390 DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
391 DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
392 DRAW_TES_JIT_CTX_SSBOS = 7,
393 DRAW_TES_JIT_CTX_NUM_SSBOS = 8,
394 DRAW_TES_JIT_CTX_NUM_FIELDS = 9,
395 };
396
397 #define draw_tes_jit_context_constants(_gallivm, _ptr) \
398 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
399
400 #define draw_tes_jit_context_num_constants(_gallivm, _ptr) \
401 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")
402
403 #define draw_tes_jit_context_textures(_gallivm, _ptr) \
404 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
405
406 #define draw_tes_jit_context_samplers(_gallivm, _ptr) \
407 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
408
409 #define draw_tes_jit_context_images(_gallivm, _ptr) \
410 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
411
412 #define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
413 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
414
415 #define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \
416 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
417
418 typedef boolean
419 (*draw_jit_vert_func)(struct draw_jit_context *context,
420 struct vertex_header *io,
421 const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
422 unsigned count,
423 unsigned start_or_maxelt,
424 unsigned stride,
425 struct pipe_vertex_buffer *vertex_buffers,
426 unsigned instance_id,
427 unsigned vertex_id_offset,
428 unsigned start_instance,
429 const unsigned *fetch_elts,
430 unsigned draw_id);
431
432
433 typedef int
434 (*draw_gs_jit_func)(struct draw_gs_jit_context *context,
435 float inputs[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS],
436 struct vertex_header **output,
437 unsigned num_prims,
438 unsigned instance_id,
439 int *prim_ids,
440 unsigned invocation_id);
441
442 typedef int
443 (*draw_tcs_jit_func)(struct draw_tcs_jit_context *context,
444 float inputs[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS],
445 float outputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
446 uint32_t prim_id, uint32_t patch_vertices_in);
447
448 typedef int
449 (*draw_tes_jit_func)(struct draw_tes_jit_context *context,
450 float inputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
451 struct vertex_header *io,
452 uint32_t prim_id, uint32_t num_tess_coord,
453 float *tess_coord_x, float *tess_coord_y, float *tess_outer,
454 float *tess_inner);
455
456
457 struct draw_llvm_variant_key
458 {
459 unsigned nr_vertex_elements:8;
460 unsigned nr_samplers:8;
461 unsigned nr_sampler_views:8;
462 unsigned nr_images:8;
463 unsigned clamp_vertex_color:1;
464 unsigned clip_xy:1;
465 unsigned clip_z:1;
466 unsigned clip_user:1;
467 unsigned clip_halfz:1;
468 unsigned bypass_viewport:1;
469 unsigned need_edgeflags:1;
470 unsigned has_gs:1;
471 unsigned num_outputs:8;
472 unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
473 /* note padding here - must use memset */
474
475 /* Variable number of vertex elements:
476 */
477 struct pipe_vertex_element vertex_element[1];
478
479 /* Followed by variable number of samplers:
480 */
481 /* struct draw_sampler_static_state sampler; */
482 /* Followed by variable number of images
483 */
484 };
485
486 struct draw_gs_llvm_variant_key
487 {
488 unsigned nr_samplers:8;
489 unsigned nr_sampler_views:8;
490 unsigned nr_images:8;
491 unsigned num_outputs:8;
492 /* note padding here - must use memset */
493
494 struct draw_sampler_static_state samplers[1];
495 /* Followed by variable number of images.*/
496 };
497
498 #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
499 (sizeof(struct draw_llvm_variant_key) + \
500 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \
501 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
502 (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
503
504 #define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
505 (sizeof(struct draw_gs_llvm_variant_key) + \
506 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
507 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
508
509
510 static inline size_t
511 draw_llvm_variant_key_size(unsigned nr_vertex_elements,
512 unsigned nr_samplers, unsigned nr_images)
513 {
514 return (sizeof(struct draw_llvm_variant_key) +
515 nr_samplers * sizeof(struct draw_sampler_static_state) +
516 nr_images * sizeof(struct draw_image_static_state) +
517 (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
518 }
519
520
521 static inline size_t
522 draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
523 {
524 return (sizeof(struct draw_gs_llvm_variant_key) +
525 (nr_images) * sizeof(struct draw_sampler_static_state) +
526 (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
527 }
528
529
530 static inline struct draw_sampler_static_state *
531 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
532 {
533 return (struct draw_sampler_static_state *)
534 &key->vertex_element[key->nr_vertex_elements];
535 }
536
537 static inline struct draw_image_static_state *
538 draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
539 {
540 struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
541 (&key->vertex_element[key->nr_vertex_elements]);
542 return (struct draw_image_static_state *)
543 &samplers[key->nr_samplers];
544 }
545
546 static inline struct draw_image_static_state *
547 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
548 {
549 return (struct draw_image_static_state *)
550 &key->samplers[key->nr_samplers];
551 }
552
553 struct draw_llvm_variant_list_item
554 {
555 struct draw_llvm_variant *base;
556 struct draw_llvm_variant_list_item *next, *prev;
557 };
558
559 struct draw_gs_llvm_variant_list_item
560 {
561 struct draw_gs_llvm_variant *base;
562 struct draw_gs_llvm_variant_list_item *next, *prev;
563 };
564
565
566 struct draw_llvm_variant
567 {
568 struct gallivm_state *gallivm;
569
570 /* LLVM JIT builder types */
571 LLVMTypeRef context_ptr_type;
572 LLVMTypeRef buffer_ptr_type;
573 LLVMTypeRef vb_ptr_type;
574 LLVMTypeRef vertex_header_ptr_type;
575
576 LLVMValueRef function;
577 draw_jit_vert_func jit_func;
578
579 struct llvm_vertex_shader *shader;
580
581 struct draw_llvm *llvm;
582 struct draw_llvm_variant_list_item list_item_global;
583 struct draw_llvm_variant_list_item list_item_local;
584
585 /* key is variable-sized, must be last */
586 struct draw_llvm_variant_key key;
587 };
588
589
590 struct draw_gs_llvm_variant
591 {
592 struct gallivm_state *gallivm;
593
594 /* LLVM JIT builder types */
595 LLVMTypeRef context_ptr_type;
596 LLVMTypeRef vertex_header_ptr_type;
597 LLVMTypeRef input_array_type;
598
599 LLVMValueRef context_ptr;
600 LLVMValueRef io_ptr;
601 LLVMValueRef num_prims;
602 LLVMValueRef function;
603 draw_gs_jit_func jit_func;
604
605 struct llvm_geometry_shader *shader;
606
607 struct draw_llvm *llvm;
608 struct draw_gs_llvm_variant_list_item list_item_global;
609 struct draw_gs_llvm_variant_list_item list_item_local;
610
611 /* key is variable-sized, must be last */
612 struct draw_gs_llvm_variant_key key;
613 };
614
615 struct llvm_vertex_shader {
616 struct draw_vertex_shader base;
617
618 unsigned variant_key_size;
619 struct draw_llvm_variant_list_item variants;
620 unsigned variants_created;
621 unsigned variants_cached;
622 };
623
624 struct llvm_geometry_shader {
625 struct draw_geometry_shader base;
626
627 unsigned variant_key_size;
628 struct draw_gs_llvm_variant_list_item variants;
629 unsigned variants_created;
630 unsigned variants_cached;
631 };
632
633
634 struct draw_llvm {
635 struct draw_context *draw;
636
637 LLVMContextRef context;
638 boolean context_owned;
639
640 struct draw_jit_context jit_context;
641 struct draw_gs_jit_context gs_jit_context;
642
643 struct draw_llvm_variant_list_item vs_variants_list;
644 int nr_variants;
645
646 struct draw_gs_llvm_variant_list_item gs_variants_list;
647 int nr_gs_variants;
648 };
649
650
651 static inline struct llvm_vertex_shader *
652 llvm_vertex_shader(struct draw_vertex_shader *vs)
653 {
654 return (struct llvm_vertex_shader *)vs;
655 }
656
657 static inline struct llvm_geometry_shader *
658 llvm_geometry_shader(struct draw_geometry_shader *gs)
659 {
660 return (struct llvm_geometry_shader *)gs;
661 }
662
663
664
665
666 struct draw_llvm *
667 draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
668
669 void
670 draw_llvm_destroy(struct draw_llvm *llvm);
671
672 struct draw_llvm_variant *
673 draw_llvm_create_variant(struct draw_llvm *llvm,
674 unsigned num_vertex_header_attribs,
675 const struct draw_llvm_variant_key *key);
676
677 void
678 draw_llvm_destroy_variant(struct draw_llvm_variant *variant);
679
680 struct draw_llvm_variant_key *
681 draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
682
683 void
684 draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);
685
686
687 struct draw_gs_llvm_variant *
688 draw_gs_llvm_create_variant(struct draw_llvm *llvm,
689 unsigned num_vertex_header_attribs,
690 const struct draw_gs_llvm_variant_key *key);
691
692 void
693 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);
694
695 struct draw_gs_llvm_variant_key *
696 draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
697
698 void
699 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
700
701 struct lp_build_sampler_soa *
702 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state);
703
704 struct lp_build_image_soa *
705 draw_llvm_image_soa_create(const struct draw_image_static_state *static_state);
706
707 void
708 draw_llvm_set_sampler_state(struct draw_context *draw,
709 enum pipe_shader_type shader_stage);
710
711 void
712 draw_llvm_set_mapped_texture(struct draw_context *draw,
713 enum pipe_shader_type shader_stage,
714 unsigned sview_idx,
715 uint32_t width, uint32_t height, uint32_t depth,
716 uint32_t first_level, uint32_t last_level,
717 const void *base_ptr,
718 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
719 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
720 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
721
722 void
723 draw_llvm_set_mapped_image(struct draw_context *draw,
724 enum pipe_shader_type shader_stage,
725 unsigned idx,
726 uint32_t width, uint32_t height, uint32_t depth,
727 const void *base_ptr,
728 uint32_t row_stride,
729 uint32_t img_stride);
730 #endif