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 struct llvm_tess_ctrl_shader;
48 struct llvm_tess_eval_shader;
49
50 struct draw_jit_texture
51 {
52 uint32_t width;
53 uint32_t height;
54 uint32_t depth;
55 const void *base;
56 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
57 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
58 uint32_t first_level;
59 uint32_t last_level;
60 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
61 uint32_t num_samples;
62 uint32_t sample_stride;
63 };
64
65
66 struct draw_sampler_static_state
67 {
68 /*
69 * These attributes are effectively interleaved for more sane key handling.
70 * However, there might be lots of null space if the amount of samplers and
71 * textures isn't the same.
72 */
73 struct lp_static_sampler_state sampler_state;
74 struct lp_static_texture_state texture_state;
75 };
76
77 struct draw_image_static_state
78 {
79 struct lp_static_texture_state image_state;
80 };
81
82
83 struct draw_jit_sampler
84 {
85 float min_lod;
86 float max_lod;
87 float lod_bias;
88 float border_color[4];
89 };
90
91
92 struct draw_jit_image
93 {
94 uint32_t width;
95 uint32_t height;
96 uint32_t depth;
97 const void *base;
98 uint32_t row_stride;
99 uint32_t img_stride;
100 uint32_t num_samples;
101 uint32_t sample_stride;
102 };
103
104 enum {
105 DRAW_JIT_TEXTURE_WIDTH = 0,
106 DRAW_JIT_TEXTURE_HEIGHT,
107 DRAW_JIT_TEXTURE_DEPTH,
108 DRAW_JIT_TEXTURE_BASE,
109 DRAW_JIT_TEXTURE_ROW_STRIDE,
110 DRAW_JIT_TEXTURE_IMG_STRIDE,
111 DRAW_JIT_TEXTURE_FIRST_LEVEL,
112 DRAW_JIT_TEXTURE_LAST_LEVEL,
113 DRAW_JIT_TEXTURE_MIP_OFFSETS,
114 DRAW_JIT_TEXTURE_NUM_SAMPLES,
115 DRAW_JIT_TEXTURE_SAMPLE_STRIDE,
116 DRAW_JIT_TEXTURE_NUM_FIELDS /* number of fields above */
117 };
118
119
120 enum {
121 DRAW_JIT_SAMPLER_MIN_LOD,
122 DRAW_JIT_SAMPLER_MAX_LOD,
123 DRAW_JIT_SAMPLER_LOD_BIAS,
124 DRAW_JIT_SAMPLER_BORDER_COLOR,
125 DRAW_JIT_SAMPLER_NUM_FIELDS /* number of fields above */
126 };
127
128
129 enum {
130 DRAW_JIT_VERTEX_VERTEX_ID = 0,
131 DRAW_JIT_VERTEX_CLIP_POS,
132 DRAW_JIT_VERTEX_DATA
133 };
134
135 enum {
136 DRAW_JIT_IMAGE_WIDTH = 0,
137 DRAW_JIT_IMAGE_HEIGHT,
138 DRAW_JIT_IMAGE_DEPTH,
139 DRAW_JIT_IMAGE_BASE,
140 DRAW_JIT_IMAGE_ROW_STRIDE,
141 DRAW_JIT_IMAGE_IMG_STRIDE,
142 DRAW_JIT_IMAGE_NUM_SAMPLES,
143 DRAW_JIT_IMAGE_SAMPLE_STRIDE,
144 DRAW_JIT_IMAGE_NUM_FIELDS /* number of fields above */
145 };
146
147 /**
148 * This structure is passed directly to the generated vertex shader.
149 *
150 * It contains the derived state.
151 *
152 * Changes here must be reflected in the draw_jit_context_* macros.
153 * Changes to the ordering should be avoided.
154 *
155 * Only use types with a clear size and padding here, in particular prefer the
156 * stdint.h types to the basic integer types.
157 */
158 struct draw_jit_context
159 {
160 const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
161 int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
162 float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
163 struct pipe_viewport_state *viewports;
164
165 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
166 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
167 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
168
169 const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
170 int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
171 };
172
173 enum {
174 DRAW_JIT_CTX_CONSTANTS = 0,
175 DRAW_JIT_CTX_NUM_CONSTANTS = 1,
176 DRAW_JIT_CTX_PLANES = 2,
177 DRAW_JIT_CTX_VIEWPORT = 3,
178 DRAW_JIT_CTX_TEXTURES = 4,
179 DRAW_JIT_CTX_SAMPLERS = 5,
180 DRAW_JIT_CTX_IMAGES = 6,
181 DRAW_JIT_CTX_SSBOS = 7,
182 DRAW_JIT_CTX_NUM_SSBOS = 8,
183 DRAW_JIT_CTX_NUM_FIELDS
184 };
185
186 #define draw_jit_context_vs_constants(_gallivm, _ptr) \
187 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
188
189 #define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
190 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
191
192 #define draw_jit_context_planes(_gallivm, _ptr) \
193 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
194
195 #define draw_jit_context_viewports(_gallivm, _ptr) \
196 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
197
198 #define draw_jit_context_textures(_gallivm, _ptr) \
199 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
200
201 #define draw_jit_context_samplers(_gallivm, _ptr) \
202 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
203
204 #define draw_jit_context_images(_gallivm, _ptr) \
205 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
206
207 #define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
208 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
209
210 #define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
211 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
212
213
214 #define draw_jit_header_id(_gallivm, _ptr) \
215 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
216
217 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
218 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
219
220 #define draw_jit_header_data(_gallivm, _ptr) \
221 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
222
223
224 #define draw_jit_vbuffer_stride(_gallivm, _ptr) \
225 lp_build_struct_get(_gallivm, _ptr, 0, "stride")
226
227 #define draw_jit_vbuffer_offset(_gallivm, _ptr) \
228 lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
229
230 enum {
231 DRAW_JIT_DVBUFFER_MAP = 0,
232 DRAW_JIT_DVBUFFER_SIZE,
233 DRAW_JIT_DVBUFFER_NUM_FIELDS /* number of fields above */
234 };
235
236 #define draw_jit_dvbuffer_map(_gallivm, _ptr) \
237 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
238
239 #define draw_jit_dvbuffer_size(_gallivm, _ptr) \
240 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
241
242
243 /**
244 * This structure is passed directly to the generated geometry shader.
245 *
246 * It contains the derived state.
247 *
248 * Changes here must be reflected in the draw_gs_jit_context_* macros.
249 * Changes to the ordering should be avoided.
250 *
251 * Only use types with a clear size and padding here, in particular prefer the
252 * stdint.h types to the basic integer types.
253 */
254 struct draw_gs_jit_context
255 {
256 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
257 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
258 float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
259 struct pipe_viewport_state *viewports;
260
261 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
262 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
263 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
264 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
265 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
266
267 int **prim_lengths;
268 int *emitted_vertices;
269 int *emitted_prims;
270 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
271 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
272
273 };
274
275 enum {
276 DRAW_GS_JIT_CTX_CONSTANTS = 0,
277 DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,
278 DRAW_GS_JIT_CTX_PLANES = 2,
279 DRAW_GS_JIT_CTX_VIEWPORT = 3,
280 /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
281 * and DRAW_JIT_CTX_SAMPLERS, because they both need
282 * to be at exactly the same locations as they are in the
283 * VS ctx structure for sampling to work. */
284 DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
285 DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
286 DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
287 DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,
288 DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,
289 DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,
290 DRAW_GS_JIT_CTX_SSBOS = 10,
291 DRAW_GS_JIT_CTX_NUM_SSBOS = 11,
292 DRAW_GS_JIT_CTX_NUM_FIELDS = 12
293 };
294
295 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
296 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
297
298 #define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
299 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
300
301 #define draw_gs_jit_context_planes(_gallivm, _ptr) \
302 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
303
304 #define draw_gs_jit_context_viewports(_gallivm, _ptr) \
305 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
306
307 #define draw_gs_jit_context_textures(_gallivm, _ptr) \
308 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
309
310 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
311 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
312
313 #define draw_gs_jit_context_images(_gallivm, _ptr) \
314 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
315
316 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
317 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
318
319 #define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
320 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
321
322 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
323 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
324
325 #define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
326 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
327
328 #define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
329 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
330
331
332 struct draw_tcs_jit_context {
333 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
334 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
335
336 int dummy1;
337 int dummy2;
338 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
339 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
340 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
341 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
342 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
343
344 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
345 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
346 };
347
348 enum {
349 DRAW_TCS_JIT_CTX_CONSTANTS = 0,
350 DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1,
351 DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
352 DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
353 DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
354 DRAW_TCS_JIT_CTX_SSBOS = 7,
355 DRAW_TCS_JIT_CTX_NUM_SSBOS = 8,
356 DRAW_TCS_JIT_CTX_NUM_FIELDS = 9,
357 };
358
359 #define draw_tcs_jit_context_constants(_gallivm, _ptr) \
360 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
361
362 #define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \
363 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")
364
365 #define draw_tcs_jit_context_textures(_gallivm, _ptr) \
366 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
367
368 #define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
369 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
370
371 #define draw_tcs_jit_context_images(_gallivm, _ptr) \
372 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
373
374 #define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
375 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
376
377 #define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \
378 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
379
380 struct draw_tes_jit_context {
381 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
382 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
383
384 int dummy1;
385 int dummy2;
386 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
387 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
388 struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
389 struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
390 struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
391
392 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
393 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
394 };
395
396 enum {
397 DRAW_TES_JIT_CTX_CONSTANTS = 0,
398 DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1,
399 DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
400 DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
401 DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
402 DRAW_TES_JIT_CTX_SSBOS = 7,
403 DRAW_TES_JIT_CTX_NUM_SSBOS = 8,
404 DRAW_TES_JIT_CTX_NUM_FIELDS = 9,
405 };
406
407 #define draw_tes_jit_context_constants(_gallivm, _ptr) \
408 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
409
410 #define draw_tes_jit_context_num_constants(_gallivm, _ptr) \
411 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")
412
413 #define draw_tes_jit_context_textures(_gallivm, _ptr) \
414 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
415
416 #define draw_tes_jit_context_samplers(_gallivm, _ptr) \
417 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
418
419 #define draw_tes_jit_context_images(_gallivm, _ptr) \
420 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
421
422 #define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
423 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
424
425 #define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \
426 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
427
428 typedef boolean
429 (*draw_jit_vert_func)(struct draw_jit_context *context,
430 struct vertex_header *io,
431 const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
432 unsigned count,
433 unsigned start_or_maxelt,
434 unsigned stride,
435 struct pipe_vertex_buffer *vertex_buffers,
436 unsigned instance_id,
437 unsigned vertex_id_offset,
438 unsigned start_instance,
439 const unsigned *fetch_elts,
440 unsigned draw_id);
441
442
443 typedef int
444 (*draw_gs_jit_func)(struct draw_gs_jit_context *context,
445 float inputs[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS],
446 struct vertex_header **output,
447 unsigned num_prims,
448 unsigned instance_id,
449 int *prim_ids,
450 unsigned invocation_id);
451
452 typedef int
453 (*draw_tcs_jit_func)(struct draw_tcs_jit_context *context,
454 float inputs[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS],
455 float outputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
456 uint32_t prim_id, uint32_t patch_vertices_in);
457
458 typedef int
459 (*draw_tes_jit_func)(struct draw_tes_jit_context *context,
460 float inputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
461 struct vertex_header *io,
462 uint32_t prim_id, uint32_t num_tess_coord,
463 float *tess_coord_x, float *tess_coord_y, float *tess_outer,
464 float *tess_inner, uint32_t patch_vertices_in);
465
466
467 struct draw_llvm_variant_key
468 {
469 unsigned nr_vertex_elements:8;
470 unsigned nr_samplers:8;
471 unsigned nr_sampler_views:8;
472 unsigned nr_images:8;
473 unsigned clamp_vertex_color:1;
474 unsigned clip_xy:1;
475 unsigned clip_z:1;
476 unsigned clip_user:1;
477 unsigned clip_halfz:1;
478 unsigned bypass_viewport:1;
479 unsigned need_edgeflags:1;
480 unsigned has_gs_or_tes:1;
481 unsigned num_outputs:8;
482 unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
483 /* note padding here - must use memset */
484
485 /* Variable number of vertex elements:
486 */
487 struct pipe_vertex_element vertex_element[1];
488
489 /* Followed by variable number of samplers:
490 */
491 /* struct draw_sampler_static_state sampler; */
492 /* Followed by variable number of images
493 */
494 };
495
496 struct draw_gs_llvm_variant_key
497 {
498 unsigned nr_samplers:8;
499 unsigned nr_sampler_views:8;
500 unsigned nr_images:8;
501 unsigned num_outputs:8;
502 /* note padding here - must use memset */
503
504 struct draw_sampler_static_state samplers[1];
505 /* Followed by variable number of images.*/
506 };
507
508 struct draw_tcs_llvm_variant_key
509 {
510 unsigned nr_samplers:8;
511 unsigned nr_sampler_views:8;
512 unsigned nr_images:8;
513 struct draw_sampler_static_state samplers[1];
514 /* Followed by variable number of images.*/
515 };
516
517 struct draw_tes_llvm_variant_key
518 {
519 unsigned nr_samplers:8;
520 unsigned nr_sampler_views:8;
521 unsigned nr_images:8;
522 struct draw_sampler_static_state samplers[1];
523 /* Followed by variable number of images.*/
524 };
525
526 #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
527 (sizeof(struct draw_llvm_variant_key) + \
528 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \
529 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
530 (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
531
532 #define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
533 (sizeof(struct draw_gs_llvm_variant_key) + \
534 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
535 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
536
537 #define DRAW_TCS_LLVM_MAX_VARIANT_KEY_SIZE \
538 (sizeof(struct draw_tcs_llvm_variant_key) + \
539 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
540 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
541
542 #define DRAW_TES_LLVM_MAX_VARIANT_KEY_SIZE \
543 (sizeof(struct draw_tes_llvm_variant_key) + \
544 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
545 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
546
547
548 static inline size_t
draw_llvm_variant_key_size(unsigned nr_vertex_elements,unsigned nr_samplers,unsigned nr_images)549 draw_llvm_variant_key_size(unsigned nr_vertex_elements,
550 unsigned nr_samplers, unsigned nr_images)
551 {
552 return (sizeof(struct draw_llvm_variant_key) +
553 nr_samplers * sizeof(struct draw_sampler_static_state) +
554 nr_images * sizeof(struct draw_image_static_state) +
555 (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
556 }
557
558
559 static inline size_t
draw_gs_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_images)560 draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
561 {
562 return (sizeof(struct draw_gs_llvm_variant_key) +
563 (nr_images) * sizeof(struct draw_sampler_static_state) +
564 (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
565 }
566
567 static inline size_t
draw_tcs_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_images)568 draw_tcs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
569 {
570 return (sizeof(struct draw_tcs_llvm_variant_key) +
571 (nr_images) * sizeof(struct draw_sampler_static_state) +
572 (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
573 }
574
575 static inline size_t
draw_tes_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_images)576 draw_tes_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
577 {
578 return (sizeof(struct draw_tes_llvm_variant_key) +
579 (nr_images) * sizeof(struct draw_sampler_static_state) +
580 (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
581 }
582
583 static inline struct draw_sampler_static_state *
draw_llvm_variant_key_samplers(struct draw_llvm_variant_key * key)584 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
585 {
586 return (struct draw_sampler_static_state *)
587 &key->vertex_element[key->nr_vertex_elements];
588 }
589
590 static inline struct draw_image_static_state *
draw_llvm_variant_key_images(struct draw_llvm_variant_key * key)591 draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
592 {
593 struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
594 (&key->vertex_element[key->nr_vertex_elements]);
595 return (struct draw_image_static_state *)
596 &samplers[key->nr_samplers];
597 }
598
599 static inline struct draw_image_static_state *
draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key * key)600 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
601 {
602 return (struct draw_image_static_state *)
603 &key->samplers[key->nr_samplers];
604 }
605
606 static inline struct draw_image_static_state *
draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key * key)607 draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)
608 {
609 return (struct draw_image_static_state *)
610 &key->samplers[key->nr_samplers];
611 }
612
613 static inline struct draw_image_static_state *
draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key * key)614 draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)
615 {
616 return (struct draw_image_static_state *)
617 &key->samplers[key->nr_samplers];
618 }
619
620 struct draw_llvm_variant_list_item
621 {
622 struct draw_llvm_variant *base;
623 struct draw_llvm_variant_list_item *next, *prev;
624 };
625
626 struct draw_gs_llvm_variant_list_item
627 {
628 struct draw_gs_llvm_variant *base;
629 struct draw_gs_llvm_variant_list_item *next, *prev;
630 };
631
632 struct draw_tcs_llvm_variant_list_item
633 {
634 struct draw_tcs_llvm_variant *base;
635 struct draw_tcs_llvm_variant_list_item *next, *prev;
636 };
637
638 struct draw_tes_llvm_variant_list_item
639 {
640 struct draw_tes_llvm_variant *base;
641 struct draw_tes_llvm_variant_list_item *next, *prev;
642 };
643
644 struct draw_llvm_variant
645 {
646 struct gallivm_state *gallivm;
647
648 /* LLVM JIT builder types */
649 LLVMTypeRef context_ptr_type;
650 LLVMTypeRef buffer_ptr_type;
651 LLVMTypeRef vb_ptr_type;
652 LLVMTypeRef vertex_header_ptr_type;
653
654 LLVMValueRef function;
655 draw_jit_vert_func jit_func;
656
657 struct llvm_vertex_shader *shader;
658
659 struct draw_llvm *llvm;
660 struct draw_llvm_variant_list_item list_item_global;
661 struct draw_llvm_variant_list_item list_item_local;
662
663 /* key is variable-sized, must be last */
664 struct draw_llvm_variant_key key;
665 };
666
667
668 struct draw_gs_llvm_variant
669 {
670 struct gallivm_state *gallivm;
671
672 /* LLVM JIT builder types */
673 LLVMTypeRef context_ptr_type;
674 LLVMTypeRef vertex_header_ptr_type;
675 LLVMTypeRef input_array_type;
676
677 LLVMValueRef context_ptr;
678 LLVMValueRef io_ptr;
679 LLVMValueRef num_prims;
680 LLVMValueRef function;
681 draw_gs_jit_func jit_func;
682
683 struct llvm_geometry_shader *shader;
684
685 struct draw_llvm *llvm;
686 struct draw_gs_llvm_variant_list_item list_item_global;
687 struct draw_gs_llvm_variant_list_item list_item_local;
688
689 /* key is variable-sized, must be last */
690 struct draw_gs_llvm_variant_key key;
691 };
692
693 struct draw_tcs_llvm_variant
694 {
695 struct gallivm_state *gallivm;
696
697 /* LLVM JIT builder types */
698 LLVMTypeRef context_ptr_type;
699 LLVMTypeRef input_array_type;
700 LLVMTypeRef output_array_type;
701
702 LLVMValueRef context_ptr;
703 LLVMValueRef io_ptr;
704 LLVMValueRef num_prims;
705 LLVMValueRef function;
706 draw_tcs_jit_func jit_func;
707
708 struct llvm_tess_ctrl_shader *shader;
709
710 struct draw_llvm *llvm;
711 struct draw_tcs_llvm_variant_list_item list_item_global;
712 struct draw_tcs_llvm_variant_list_item list_item_local;
713
714 /* key is variable-sized, must be last */
715 struct draw_tcs_llvm_variant_key key;
716 };
717
718 struct draw_tes_llvm_variant
719 {
720 struct gallivm_state *gallivm;
721
722 /* LLVM JIT builder types */
723 LLVMTypeRef context_ptr_type;
724 LLVMTypeRef vertex_header_ptr_type;
725 LLVMTypeRef input_array_type;
726 LLVMTypeRef patch_input_array_type;
727
728 LLVMValueRef context_ptr;
729 LLVMValueRef io_ptr;
730 LLVMValueRef num_prims;
731 LLVMValueRef function;
732 draw_tes_jit_func jit_func;
733
734 struct llvm_tess_eval_shader *shader;
735
736 struct draw_llvm *llvm;
737 struct draw_tes_llvm_variant_list_item list_item_global;
738 struct draw_tes_llvm_variant_list_item list_item_local;
739
740 /* key is variable-sized, must be last */
741 struct draw_tes_llvm_variant_key key;
742 };
743
744 struct llvm_vertex_shader {
745 struct draw_vertex_shader base;
746
747 unsigned variant_key_size;
748 struct draw_llvm_variant_list_item variants;
749 unsigned variants_created;
750 unsigned variants_cached;
751 };
752
753 struct llvm_geometry_shader {
754 struct draw_geometry_shader base;
755
756 unsigned variant_key_size;
757 struct draw_gs_llvm_variant_list_item variants;
758 unsigned variants_created;
759 unsigned variants_cached;
760 };
761
762 struct llvm_tess_ctrl_shader {
763 struct draw_tess_ctrl_shader base;
764
765 unsigned variant_key_size;
766 struct draw_tcs_llvm_variant_list_item variants;
767 unsigned variants_created;
768 unsigned variants_cached;
769 };
770
771 struct llvm_tess_eval_shader {
772 struct draw_tess_eval_shader base;
773
774 unsigned variant_key_size;
775 struct draw_tes_llvm_variant_list_item variants;
776 unsigned variants_created;
777 unsigned variants_cached;
778 };
779
780 struct draw_llvm {
781 struct draw_context *draw;
782
783 LLVMContextRef context;
784 boolean context_owned;
785
786 struct draw_jit_context jit_context;
787 struct draw_gs_jit_context gs_jit_context;
788 struct draw_tcs_jit_context tcs_jit_context;
789 struct draw_tes_jit_context tes_jit_context;
790
791 struct draw_llvm_variant_list_item vs_variants_list;
792 int nr_variants;
793
794 struct draw_gs_llvm_variant_list_item gs_variants_list;
795 int nr_gs_variants;
796
797 struct draw_tcs_llvm_variant_list_item tcs_variants_list;
798 int nr_tcs_variants;
799
800 struct draw_tes_llvm_variant_list_item tes_variants_list;
801 int nr_tes_variants;
802 };
803
804
805 static inline struct llvm_vertex_shader *
llvm_vertex_shader(struct draw_vertex_shader * vs)806 llvm_vertex_shader(struct draw_vertex_shader *vs)
807 {
808 return (struct llvm_vertex_shader *)vs;
809 }
810
811 static inline struct llvm_geometry_shader *
llvm_geometry_shader(struct draw_geometry_shader * gs)812 llvm_geometry_shader(struct draw_geometry_shader *gs)
813 {
814 return (struct llvm_geometry_shader *)gs;
815 }
816
817 static inline struct llvm_tess_ctrl_shader *
llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader * tcs)818 llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader *tcs)
819 {
820 return (struct llvm_tess_ctrl_shader *)tcs;
821 }
822
823 static inline struct llvm_tess_eval_shader *
llvm_tess_eval_shader(struct draw_tess_eval_shader * tes)824 llvm_tess_eval_shader(struct draw_tess_eval_shader *tes)
825 {
826 return (struct llvm_tess_eval_shader *)tes;
827 }
828
829 struct draw_llvm *
830 draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
831
832 void
833 draw_llvm_destroy(struct draw_llvm *llvm);
834
835 struct draw_llvm_variant *
836 draw_llvm_create_variant(struct draw_llvm *llvm,
837 unsigned num_vertex_header_attribs,
838 const struct draw_llvm_variant_key *key);
839
840 void
841 draw_llvm_destroy_variant(struct draw_llvm_variant *variant);
842
843 struct draw_llvm_variant_key *
844 draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
845
846 void
847 draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);
848
849
850 struct draw_gs_llvm_variant *
851 draw_gs_llvm_create_variant(struct draw_llvm *llvm,
852 unsigned num_vertex_header_attribs,
853 const struct draw_gs_llvm_variant_key *key);
854
855 void
856 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);
857
858 struct draw_gs_llvm_variant_key *
859 draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
860
861 void
862 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
863
864 struct draw_tcs_llvm_variant *
865 draw_tcs_llvm_create_variant(struct draw_llvm *llvm,
866 unsigned num_vertex_header_attribs,
867 const struct draw_tcs_llvm_variant_key *key);
868
869 void
870 draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant);
871
872 struct draw_tcs_llvm_variant_key *
873 draw_tcs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
874
875 void
876 draw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key *key);
877
878 struct draw_tes_llvm_variant *
879 draw_tes_llvm_create_variant(struct draw_llvm *llvm,
880 unsigned num_vertex_header_attribs,
881 const struct draw_tes_llvm_variant_key *key);
882
883 void
884 draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant);
885
886 struct draw_tes_llvm_variant_key *
887 draw_tes_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
888
889 void
890 draw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key *key);
891
892 struct lp_build_sampler_soa *
893 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
894 unsigned nr_samplers);
895
896 struct lp_build_image_soa *
897 draw_llvm_image_soa_create(const struct draw_image_static_state *static_state,
898 unsigned nr_images);
899
900 void
901 draw_llvm_set_sampler_state(struct draw_context *draw,
902 enum pipe_shader_type shader_stage);
903
904 void
905 draw_llvm_set_mapped_texture(struct draw_context *draw,
906 enum pipe_shader_type shader_stage,
907 unsigned sview_idx,
908 uint32_t width, uint32_t height, uint32_t depth,
909 uint32_t first_level, uint32_t last_level,
910 uint32_t num_samples,
911 uint32_t sample_stride,
912 const void *base_ptr,
913 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
914 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
915 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
916
917 void
918 draw_llvm_set_mapped_image(struct draw_context *draw,
919 enum pipe_shader_type shader_stage,
920 unsigned idx,
921 uint32_t width, uint32_t height, uint32_t depth,
922 const void *base_ptr,
923 uint32_t row_stride,
924 uint32_t img_stride,
925 uint32_t num_samples,
926 uint32_t sample_stride);
927 #endif
928