1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
31 #include "draw/draw_private.h"
33 #include "draw/draw_vs.h"
34 #include "draw/draw_gs.h"
35 #include "draw/draw_tess.h"
37 #include "gallivm/lp_bld_sample.h"
38 #include "gallivm/lp_bld_limits.h"
40 #include "pipe/p_context.h"
41 #include "util/simple_list.h"
45 struct llvm_vertex_shader
;
46 struct llvm_geometry_shader
;
47 struct llvm_tess_ctrl_shader
;
48 struct llvm_tess_eval_shader
;
50 struct draw_jit_texture
56 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
];
57 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
];
60 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
];
64 struct draw_sampler_static_state
67 * These attributes are effectively interleaved for more sane key handling.
68 * However, there might be lots of null space if the amount of samplers and
69 * textures isn't the same.
71 struct lp_static_sampler_state sampler_state
;
72 struct lp_static_texture_state texture_state
;
75 struct draw_image_static_state
77 struct lp_static_texture_state image_state
;
81 struct draw_jit_sampler
86 float border_color
[4];
101 DRAW_JIT_TEXTURE_WIDTH
= 0,
102 DRAW_JIT_TEXTURE_HEIGHT
,
103 DRAW_JIT_TEXTURE_DEPTH
,
104 DRAW_JIT_TEXTURE_BASE
,
105 DRAW_JIT_TEXTURE_ROW_STRIDE
,
106 DRAW_JIT_TEXTURE_IMG_STRIDE
,
107 DRAW_JIT_TEXTURE_FIRST_LEVEL
,
108 DRAW_JIT_TEXTURE_LAST_LEVEL
,
109 DRAW_JIT_TEXTURE_MIP_OFFSETS
,
110 DRAW_JIT_TEXTURE_NUM_FIELDS
/* number of fields above */
115 DRAW_JIT_SAMPLER_MIN_LOD
,
116 DRAW_JIT_SAMPLER_MAX_LOD
,
117 DRAW_JIT_SAMPLER_LOD_BIAS
,
118 DRAW_JIT_SAMPLER_BORDER_COLOR
,
119 DRAW_JIT_SAMPLER_NUM_FIELDS
/* number of fields above */
124 DRAW_JIT_VERTEX_VERTEX_ID
= 0,
125 DRAW_JIT_VERTEX_CLIP_POS
,
130 DRAW_JIT_IMAGE_WIDTH
= 0,
131 DRAW_JIT_IMAGE_HEIGHT
,
132 DRAW_JIT_IMAGE_DEPTH
,
134 DRAW_JIT_IMAGE_ROW_STRIDE
,
135 DRAW_JIT_IMAGE_IMG_STRIDE
,
136 DRAW_JIT_IMAGE_NUM_FIELDS
/* number of fields above */
140 * This structure is passed directly to the generated vertex shader.
142 * It contains the derived state.
144 * Changes here must be reflected in the draw_jit_context_* macros.
145 * Changes to the ordering should be avoided.
147 * Only use types with a clear size and padding here, in particular prefer the
148 * stdint.h types to the basic integer types.
150 struct draw_jit_context
152 const float *vs_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
153 int num_vs_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
154 float (*planes
) [DRAW_TOTAL_CLIP_PLANES
][4];
155 struct pipe_viewport_state
*viewports
;
157 struct draw_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
158 struct draw_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
159 struct draw_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
161 const uint32_t *vs_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
162 int num_vs_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
166 DRAW_JIT_CTX_CONSTANTS
= 0,
167 DRAW_JIT_CTX_NUM_CONSTANTS
= 1,
168 DRAW_JIT_CTX_PLANES
= 2,
169 DRAW_JIT_CTX_VIEWPORT
= 3,
170 DRAW_JIT_CTX_TEXTURES
= 4,
171 DRAW_JIT_CTX_SAMPLERS
= 5,
172 DRAW_JIT_CTX_IMAGES
= 6,
173 DRAW_JIT_CTX_SSBOS
= 7,
174 DRAW_JIT_CTX_NUM_SSBOS
= 8,
175 DRAW_JIT_CTX_NUM_FIELDS
178 #define draw_jit_context_vs_constants(_gallivm, _ptr) \
179 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
181 #define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
182 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
184 #define draw_jit_context_planes(_gallivm, _ptr) \
185 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
187 #define draw_jit_context_viewports(_gallivm, _ptr) \
188 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
190 #define draw_jit_context_textures(_gallivm, _ptr) \
191 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
193 #define draw_jit_context_samplers(_gallivm, _ptr) \
194 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
196 #define draw_jit_context_images(_gallivm, _ptr) \
197 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
199 #define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
200 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
202 #define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
203 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
206 #define draw_jit_header_id(_gallivm, _ptr) \
207 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
209 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
210 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
212 #define draw_jit_header_data(_gallivm, _ptr) \
213 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
216 #define draw_jit_vbuffer_stride(_gallivm, _ptr) \
217 lp_build_struct_get(_gallivm, _ptr, 0, "stride")
219 #define draw_jit_vbuffer_offset(_gallivm, _ptr) \
220 lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
223 DRAW_JIT_DVBUFFER_MAP
= 0,
224 DRAW_JIT_DVBUFFER_SIZE
,
225 DRAW_JIT_DVBUFFER_NUM_FIELDS
/* number of fields above */
228 #define draw_jit_dvbuffer_map(_gallivm, _ptr) \
229 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
231 #define draw_jit_dvbuffer_size(_gallivm, _ptr) \
232 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
236 * This structure is passed directly to the generated geometry shader.
238 * It contains the derived state.
240 * Changes here must be reflected in the draw_gs_jit_context_* macros.
241 * Changes to the ordering should be avoided.
243 * Only use types with a clear size and padding here, in particular prefer the
244 * stdint.h types to the basic integer types.
246 struct draw_gs_jit_context
248 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
249 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
250 float (*planes
) [DRAW_TOTAL_CLIP_PLANES
][4];
251 struct pipe_viewport_state
*viewports
;
253 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
254 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
255 struct draw_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
256 struct draw_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
257 struct draw_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
260 int *emitted_vertices
;
262 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
263 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
268 DRAW_GS_JIT_CTX_CONSTANTS
= 0,
269 DRAW_GS_JIT_CTX_NUM_CONSTANTS
= 1,
270 DRAW_GS_JIT_CTX_PLANES
= 2,
271 DRAW_GS_JIT_CTX_VIEWPORT
= 3,
272 /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
273 * and DRAW_JIT_CTX_SAMPLERS, because they both need
274 * to be at exactly the same locations as they are in the
275 * VS ctx structure for sampling to work. */
276 DRAW_GS_JIT_CTX_TEXTURES
= DRAW_JIT_CTX_TEXTURES
,
277 DRAW_GS_JIT_CTX_SAMPLERS
= DRAW_JIT_CTX_SAMPLERS
,
278 DRAW_GS_JIT_CTX_IMAGES
= DRAW_JIT_CTX_IMAGES
,
279 DRAW_GS_JIT_CTX_PRIM_LENGTHS
= 7,
280 DRAW_GS_JIT_CTX_EMITTED_VERTICES
= 8,
281 DRAW_GS_JIT_CTX_EMITTED_PRIMS
= 9,
282 DRAW_GS_JIT_CTX_SSBOS
= 10,
283 DRAW_GS_JIT_CTX_NUM_SSBOS
= 11,
284 DRAW_GS_JIT_CTX_NUM_FIELDS
= 12
287 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
288 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
290 #define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
291 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
293 #define draw_gs_jit_context_planes(_gallivm, _ptr) \
294 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
296 #define draw_gs_jit_context_viewports(_gallivm, _ptr) \
297 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
299 #define draw_gs_jit_context_textures(_gallivm, _ptr) \
300 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
302 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
303 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
305 #define draw_gs_jit_context_images(_gallivm, _ptr) \
306 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
308 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
309 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
311 #define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
312 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
314 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
315 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
317 #define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
318 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
320 #define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
321 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
324 struct draw_tcs_jit_context
{
325 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
326 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
330 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
331 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
332 struct draw_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
333 struct draw_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
334 struct draw_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
336 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
337 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
341 DRAW_TCS_JIT_CTX_CONSTANTS
= 0,
342 DRAW_TCS_JIT_CTX_NUM_CONSTANTS
= 1,
343 DRAW_TCS_JIT_CTX_TEXTURES
= DRAW_JIT_CTX_TEXTURES
,
344 DRAW_TCS_JIT_CTX_SAMPLERS
= DRAW_JIT_CTX_SAMPLERS
,
345 DRAW_TCS_JIT_CTX_IMAGES
= DRAW_JIT_CTX_IMAGES
,
346 DRAW_TCS_JIT_CTX_SSBOS
= 7,
347 DRAW_TCS_JIT_CTX_NUM_SSBOS
= 8,
348 DRAW_TCS_JIT_CTX_NUM_FIELDS
= 9,
351 #define draw_tcs_jit_context_constants(_gallivm, _ptr) \
352 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
354 #define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \
355 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")
357 #define draw_tcs_jit_context_textures(_gallivm, _ptr) \
358 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
360 #define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
361 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
363 #define draw_tcs_jit_context_images(_gallivm, _ptr) \
364 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
366 #define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
367 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
369 #define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \
370 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
372 struct draw_tes_jit_context
{
373 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
374 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
378 /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
379 * DRAW_JIT_CTX_SAMPLERS positions in the struct */
380 struct draw_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
381 struct draw_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
382 struct draw_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
384 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
385 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
389 DRAW_TES_JIT_CTX_CONSTANTS
= 0,
390 DRAW_TES_JIT_CTX_NUM_CONSTANTS
= 1,
391 DRAW_TES_JIT_CTX_TEXTURES
= DRAW_JIT_CTX_TEXTURES
,
392 DRAW_TES_JIT_CTX_SAMPLERS
= DRAW_JIT_CTX_SAMPLERS
,
393 DRAW_TES_JIT_CTX_IMAGES
= DRAW_JIT_CTX_IMAGES
,
394 DRAW_TES_JIT_CTX_SSBOS
= 7,
395 DRAW_TES_JIT_CTX_NUM_SSBOS
= 8,
396 DRAW_TES_JIT_CTX_NUM_FIELDS
= 9,
399 #define draw_tes_jit_context_constants(_gallivm, _ptr) \
400 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
402 #define draw_tes_jit_context_num_constants(_gallivm, _ptr) \
403 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")
405 #define draw_tes_jit_context_textures(_gallivm, _ptr) \
406 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
408 #define draw_tes_jit_context_samplers(_gallivm, _ptr) \
409 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
411 #define draw_tes_jit_context_images(_gallivm, _ptr) \
412 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
414 #define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
415 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
417 #define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \
418 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
421 (*draw_jit_vert_func
)(struct draw_jit_context
*context
,
422 struct vertex_header
*io
,
423 const struct draw_vertex_buffer vbuffers
[PIPE_MAX_ATTRIBS
],
425 unsigned start_or_maxelt
,
427 struct pipe_vertex_buffer
*vertex_buffers
,
428 unsigned instance_id
,
429 unsigned vertex_id_offset
,
430 unsigned start_instance
,
431 const unsigned *fetch_elts
,
436 (*draw_gs_jit_func
)(struct draw_gs_jit_context
*context
,
437 float inputs
[6][PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
][TGSI_NUM_CHANNELS
],
438 struct vertex_header
**output
,
440 unsigned instance_id
,
442 unsigned invocation_id
);
445 (*draw_tcs_jit_func
)(struct draw_tcs_jit_context
*context
,
446 float inputs
[32][NUM_TCS_INPUTS
][TGSI_NUM_CHANNELS
],
447 float outputs
[32][PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
],
448 uint32_t prim_id
, uint32_t patch_vertices_in
);
451 (*draw_tes_jit_func
)(struct draw_tes_jit_context
*context
,
452 float inputs
[32][PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
],
453 struct vertex_header
*io
,
454 uint32_t prim_id
, uint32_t num_tess_coord
,
455 float *tess_coord_x
, float *tess_coord_y
, float *tess_outer
,
459 struct draw_llvm_variant_key
461 unsigned nr_vertex_elements
:8;
462 unsigned nr_samplers
:8;
463 unsigned nr_sampler_views
:8;
464 unsigned nr_images
:8;
465 unsigned clamp_vertex_color
:1;
468 unsigned clip_user
:1;
469 unsigned clip_halfz
:1;
470 unsigned bypass_viewport
:1;
471 unsigned need_edgeflags
:1;
472 unsigned has_gs_or_tes
:1;
473 unsigned num_outputs
:8;
474 unsigned ucp_enable
:PIPE_MAX_CLIP_PLANES
;
475 /* note padding here - must use memset */
477 /* Variable number of vertex elements:
479 struct pipe_vertex_element vertex_element
[1];
481 /* Followed by variable number of samplers:
483 /* struct draw_sampler_static_state sampler; */
484 /* Followed by variable number of images
488 struct draw_gs_llvm_variant_key
490 unsigned nr_samplers
:8;
491 unsigned nr_sampler_views
:8;
492 unsigned nr_images
:8;
493 unsigned num_outputs
:8;
494 /* note padding here - must use memset */
496 struct draw_sampler_static_state samplers
[1];
497 /* Followed by variable number of images.*/
500 struct draw_tcs_llvm_variant_key
502 unsigned nr_samplers
:8;
503 unsigned nr_sampler_views
:8;
504 unsigned nr_images
:8;
505 struct draw_sampler_static_state samplers
[1];
506 /* Followed by variable number of images.*/
509 struct draw_tes_llvm_variant_key
511 unsigned nr_samplers
:8;
512 unsigned nr_sampler_views
:8;
513 unsigned nr_images
:8;
514 struct draw_sampler_static_state samplers
[1];
515 /* Followed by variable number of images.*/
518 #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
519 (sizeof(struct draw_llvm_variant_key) + \
520 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \
521 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
522 (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
524 #define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
525 (sizeof(struct draw_gs_llvm_variant_key) + \
526 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
527 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
529 #define DRAW_TCS_LLVM_MAX_VARIANT_KEY_SIZE \
530 (sizeof(struct draw_tcs_llvm_variant_key) + \
531 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
532 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
534 #define DRAW_TES_LLVM_MAX_VARIANT_KEY_SIZE \
535 (sizeof(struct draw_tes_llvm_variant_key) + \
536 PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
537 PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
541 draw_llvm_variant_key_size(unsigned nr_vertex_elements
,
542 unsigned nr_samplers
, unsigned nr_images
)
544 return (sizeof(struct draw_llvm_variant_key
) +
545 nr_samplers
* sizeof(struct draw_sampler_static_state
) +
546 nr_images
* sizeof(struct draw_image_static_state
) +
547 (nr_vertex_elements
- 1) * sizeof(struct pipe_vertex_element
));
552 draw_gs_llvm_variant_key_size(unsigned nr_samplers
, unsigned nr_images
)
554 return (sizeof(struct draw_gs_llvm_variant_key
) +
555 (nr_images
) * sizeof(struct draw_sampler_static_state
) +
556 (nr_samplers
- 1) * sizeof(struct draw_sampler_static_state
));
560 draw_tcs_llvm_variant_key_size(unsigned nr_samplers
, unsigned nr_images
)
562 return (sizeof(struct draw_tcs_llvm_variant_key
) +
563 (nr_images
) * sizeof(struct draw_sampler_static_state
) +
564 (nr_samplers
- 1) * sizeof(struct draw_sampler_static_state
));
568 draw_tes_llvm_variant_key_size(unsigned nr_samplers
, unsigned nr_images
)
570 return (sizeof(struct draw_tes_llvm_variant_key
) +
571 (nr_images
) * sizeof(struct draw_sampler_static_state
) +
572 (nr_samplers
- 1) * sizeof(struct draw_sampler_static_state
));
575 static inline struct draw_sampler_static_state
*
576 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key
*key
)
578 return (struct draw_sampler_static_state
*)
579 &key
->vertex_element
[key
->nr_vertex_elements
];
582 static inline struct draw_image_static_state
*
583 draw_llvm_variant_key_images(struct draw_llvm_variant_key
*key
)
585 struct draw_sampler_static_state
*samplers
= (struct draw_sampler_static_state
*)
586 (&key
->vertex_element
[key
->nr_vertex_elements
]);
587 return (struct draw_image_static_state
*)
588 &samplers
[key
->nr_samplers
];
591 static inline struct draw_image_static_state
*
592 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key
*key
)
594 return (struct draw_image_static_state
*)
595 &key
->samplers
[key
->nr_samplers
];
598 static inline struct draw_image_static_state
*
599 draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key
*key
)
601 return (struct draw_image_static_state
*)
602 &key
->samplers
[key
->nr_samplers
];
605 static inline struct draw_image_static_state
*
606 draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key
*key
)
608 return (struct draw_image_static_state
*)
609 &key
->samplers
[key
->nr_samplers
];
612 struct draw_llvm_variant_list_item
614 struct draw_llvm_variant
*base
;
615 struct draw_llvm_variant_list_item
*next
, *prev
;
618 struct draw_gs_llvm_variant_list_item
620 struct draw_gs_llvm_variant
*base
;
621 struct draw_gs_llvm_variant_list_item
*next
, *prev
;
624 struct draw_tcs_llvm_variant_list_item
626 struct draw_tcs_llvm_variant
*base
;
627 struct draw_tcs_llvm_variant_list_item
*next
, *prev
;
630 struct draw_tes_llvm_variant_list_item
632 struct draw_tes_llvm_variant
*base
;
633 struct draw_tes_llvm_variant_list_item
*next
, *prev
;
636 struct draw_llvm_variant
638 struct gallivm_state
*gallivm
;
640 /* LLVM JIT builder types */
641 LLVMTypeRef context_ptr_type
;
642 LLVMTypeRef buffer_ptr_type
;
643 LLVMTypeRef vb_ptr_type
;
644 LLVMTypeRef vertex_header_ptr_type
;
646 LLVMValueRef function
;
647 draw_jit_vert_func jit_func
;
649 struct llvm_vertex_shader
*shader
;
651 struct draw_llvm
*llvm
;
652 struct draw_llvm_variant_list_item list_item_global
;
653 struct draw_llvm_variant_list_item list_item_local
;
655 /* key is variable-sized, must be last */
656 struct draw_llvm_variant_key key
;
660 struct draw_gs_llvm_variant
662 struct gallivm_state
*gallivm
;
664 /* LLVM JIT builder types */
665 LLVMTypeRef context_ptr_type
;
666 LLVMTypeRef vertex_header_ptr_type
;
667 LLVMTypeRef input_array_type
;
669 LLVMValueRef context_ptr
;
671 LLVMValueRef num_prims
;
672 LLVMValueRef function
;
673 draw_gs_jit_func jit_func
;
675 struct llvm_geometry_shader
*shader
;
677 struct draw_llvm
*llvm
;
678 struct draw_gs_llvm_variant_list_item list_item_global
;
679 struct draw_gs_llvm_variant_list_item list_item_local
;
681 /* key is variable-sized, must be last */
682 struct draw_gs_llvm_variant_key key
;
685 struct draw_tcs_llvm_variant
687 struct gallivm_state
*gallivm
;
689 /* LLVM JIT builder types */
690 LLVMTypeRef context_ptr_type
;
691 LLVMTypeRef input_array_type
;
692 LLVMTypeRef output_array_type
;
694 LLVMValueRef context_ptr
;
696 LLVMValueRef num_prims
;
697 LLVMValueRef function
;
698 draw_tcs_jit_func jit_func
;
700 struct llvm_tess_ctrl_shader
*shader
;
702 struct draw_llvm
*llvm
;
703 struct draw_tcs_llvm_variant_list_item list_item_global
;
704 struct draw_tcs_llvm_variant_list_item list_item_local
;
706 /* key is variable-sized, must be last */
707 struct draw_tcs_llvm_variant_key key
;
710 struct draw_tes_llvm_variant
712 struct gallivm_state
*gallivm
;
714 /* LLVM JIT builder types */
715 LLVMTypeRef context_ptr_type
;
716 LLVMTypeRef vertex_header_ptr_type
;
717 LLVMTypeRef input_array_type
;
718 LLVMTypeRef patch_input_array_type
;
720 LLVMValueRef context_ptr
;
722 LLVMValueRef num_prims
;
723 LLVMValueRef function
;
724 draw_tes_jit_func jit_func
;
726 struct llvm_tess_eval_shader
*shader
;
728 struct draw_llvm
*llvm
;
729 struct draw_tes_llvm_variant_list_item list_item_global
;
730 struct draw_tes_llvm_variant_list_item list_item_local
;
732 /* key is variable-sized, must be last */
733 struct draw_tes_llvm_variant_key key
;
736 struct llvm_vertex_shader
{
737 struct draw_vertex_shader base
;
739 unsigned variant_key_size
;
740 struct draw_llvm_variant_list_item variants
;
741 unsigned variants_created
;
742 unsigned variants_cached
;
745 struct llvm_geometry_shader
{
746 struct draw_geometry_shader base
;
748 unsigned variant_key_size
;
749 struct draw_gs_llvm_variant_list_item variants
;
750 unsigned variants_created
;
751 unsigned variants_cached
;
754 struct llvm_tess_ctrl_shader
{
755 struct draw_tess_ctrl_shader base
;
757 unsigned variant_key_size
;
758 struct draw_tcs_llvm_variant_list_item variants
;
759 unsigned variants_created
;
760 unsigned variants_cached
;
763 struct llvm_tess_eval_shader
{
764 struct draw_tess_eval_shader base
;
766 unsigned variant_key_size
;
767 struct draw_tes_llvm_variant_list_item variants
;
768 unsigned variants_created
;
769 unsigned variants_cached
;
773 struct draw_context
*draw
;
775 LLVMContextRef context
;
776 boolean context_owned
;
778 struct draw_jit_context jit_context
;
779 struct draw_gs_jit_context gs_jit_context
;
780 struct draw_tcs_jit_context tcs_jit_context
;
781 struct draw_tes_jit_context tes_jit_context
;
783 struct draw_llvm_variant_list_item vs_variants_list
;
786 struct draw_gs_llvm_variant_list_item gs_variants_list
;
789 struct draw_tcs_llvm_variant_list_item tcs_variants_list
;
792 struct draw_tes_llvm_variant_list_item tes_variants_list
;
797 static inline struct llvm_vertex_shader
*
798 llvm_vertex_shader(struct draw_vertex_shader
*vs
)
800 return (struct llvm_vertex_shader
*)vs
;
803 static inline struct llvm_geometry_shader
*
804 llvm_geometry_shader(struct draw_geometry_shader
*gs
)
806 return (struct llvm_geometry_shader
*)gs
;
809 static inline struct llvm_tess_ctrl_shader
*
810 llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader
*tcs
)
812 return (struct llvm_tess_ctrl_shader
*)tcs
;
815 static inline struct llvm_tess_eval_shader
*
816 llvm_tess_eval_shader(struct draw_tess_eval_shader
*tes
)
818 return (struct llvm_tess_eval_shader
*)tes
;
822 draw_llvm_create(struct draw_context
*draw
, LLVMContextRef llvm_context
);
825 draw_llvm_destroy(struct draw_llvm
*llvm
);
827 struct draw_llvm_variant
*
828 draw_llvm_create_variant(struct draw_llvm
*llvm
,
829 unsigned num_vertex_header_attribs
,
830 const struct draw_llvm_variant_key
*key
);
833 draw_llvm_destroy_variant(struct draw_llvm_variant
*variant
);
835 struct draw_llvm_variant_key
*
836 draw_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
839 draw_llvm_dump_variant_key(struct draw_llvm_variant_key
*key
);
842 struct draw_gs_llvm_variant
*
843 draw_gs_llvm_create_variant(struct draw_llvm
*llvm
,
844 unsigned num_vertex_header_attribs
,
845 const struct draw_gs_llvm_variant_key
*key
);
848 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant
*variant
);
850 struct draw_gs_llvm_variant_key
*
851 draw_gs_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
854 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key
*key
);
856 struct draw_tcs_llvm_variant
*
857 draw_tcs_llvm_create_variant(struct draw_llvm
*llvm
,
858 unsigned num_vertex_header_attribs
,
859 const struct draw_tcs_llvm_variant_key
*key
);
862 draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant
*variant
);
864 struct draw_tcs_llvm_variant_key
*
865 draw_tcs_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
868 draw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key
*key
);
870 struct draw_tes_llvm_variant
*
871 draw_tes_llvm_create_variant(struct draw_llvm
*llvm
,
872 unsigned num_vertex_header_attribs
,
873 const struct draw_tes_llvm_variant_key
*key
);
876 draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant
*variant
);
878 struct draw_tes_llvm_variant_key
*
879 draw_tes_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
882 draw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key
*key
);
884 struct lp_build_sampler_soa
*
885 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state
*static_state
);
887 struct lp_build_image_soa
*
888 draw_llvm_image_soa_create(const struct draw_image_static_state
*static_state
);
891 draw_llvm_set_sampler_state(struct draw_context
*draw
,
892 enum pipe_shader_type shader_stage
);
895 draw_llvm_set_mapped_texture(struct draw_context
*draw
,
896 enum pipe_shader_type shader_stage
,
898 uint32_t width
, uint32_t height
, uint32_t depth
,
899 uint32_t first_level
, uint32_t last_level
,
900 const void *base_ptr
,
901 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
],
902 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
],
903 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
]);
906 draw_llvm_set_mapped_image(struct draw_context
*draw
,
907 enum pipe_shader_type shader_stage
,
909 uint32_t width
, uint32_t height
, uint32_t depth
,
910 const void *base_ptr
,
912 uint32_t img_stride
);