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
;
48 struct draw_jit_texture
54 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
];
55 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
];
58 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
];
62 struct draw_sampler_static_state
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.
69 struct lp_static_sampler_state sampler_state
;
70 struct lp_static_texture_state texture_state
;
73 struct draw_image_static_state
75 struct lp_static_texture_state image_state
;
79 struct draw_jit_sampler
84 float border_color
[4];
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 */
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 */
122 DRAW_JIT_VERTEX_VERTEX_ID
= 0,
123 DRAW_JIT_VERTEX_CLIP_POS
,
128 DRAW_JIT_IMAGE_WIDTH
= 0,
129 DRAW_JIT_IMAGE_HEIGHT
,
130 DRAW_JIT_IMAGE_DEPTH
,
132 DRAW_JIT_IMAGE_ROW_STRIDE
,
133 DRAW_JIT_IMAGE_IMG_STRIDE
,
134 DRAW_JIT_IMAGE_NUM_FIELDS
/* number of fields above */
138 * This structure is passed directly to the generated vertex shader.
140 * It contains the derived state.
142 * Changes here must be reflected in the draw_jit_context_* macros.
143 * Changes to the ordering should be avoided.
145 * Only use types with a clear size and padding here, in particular prefer the
146 * stdint.h types to the basic integer types.
148 struct draw_jit_context
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
;
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
];
159 const uint32_t *vs_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
160 int num_vs_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
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
176 #define draw_jit_context_vs_constants(_gallivm, _ptr) \
177 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
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")
182 #define draw_jit_context_planes(_gallivm, _ptr) \
183 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
185 #define draw_jit_context_viewports(_gallivm, _ptr) \
186 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
188 #define draw_jit_context_textures(_gallivm, _ptr) \
189 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
191 #define draw_jit_context_samplers(_gallivm, _ptr) \
192 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
194 #define draw_jit_context_images(_gallivm, _ptr) \
195 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
197 #define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
198 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
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")
204 #define draw_jit_header_id(_gallivm, _ptr) \
205 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
207 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
208 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
210 #define draw_jit_header_data(_gallivm, _ptr) \
211 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
214 #define draw_jit_vbuffer_stride(_gallivm, _ptr) \
215 lp_build_struct_get(_gallivm, _ptr, 0, "stride")
217 #define draw_jit_vbuffer_offset(_gallivm, _ptr) \
218 lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
221 DRAW_JIT_DVBUFFER_MAP
= 0,
222 DRAW_JIT_DVBUFFER_SIZE
,
223 DRAW_JIT_DVBUFFER_NUM_FIELDS
/* number of fields above */
226 #define draw_jit_dvbuffer_map(_gallivm, _ptr) \
227 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
229 #define draw_jit_dvbuffer_size(_gallivm, _ptr) \
230 lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
234 * This structure is passed directly to the generated geometry shader.
236 * It contains the derived state.
238 * Changes here must be reflected in the draw_gs_jit_context_* macros.
239 * Changes to the ordering should be avoided.
241 * Only use types with a clear size and padding here, in particular prefer the
242 * stdint.h types to the basic integer types.
244 struct draw_gs_jit_context
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
;
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
];
258 int *emitted_vertices
;
260 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
261 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
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
285 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
286 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
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")
291 #define draw_gs_jit_context_planes(_gallivm, _ptr) \
292 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
294 #define draw_gs_jit_context_viewports(_gallivm, _ptr) \
295 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
297 #define draw_gs_jit_context_textures(_gallivm, _ptr) \
298 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
300 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
301 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
303 #define draw_gs_jit_context_images(_gallivm, _ptr) \
304 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
306 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
307 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
309 #define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
310 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
312 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
313 lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
315 #define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
316 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
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")
322 struct draw_tcs_jit_context
{
323 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
324 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
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
];
334 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
335 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
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,
349 #define draw_tcs_jit_context_constants(_gallivm, _ptr) \
350 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
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")
355 #define draw_tcs_jit_context_textures(_gallivm, _ptr) \
356 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
358 #define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
359 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
361 #define draw_tcs_jit_context_images(_gallivm, _ptr) \
362 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
364 #define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
365 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
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")
370 struct draw_tes_jit_context
{
371 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
372 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
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
];
382 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
383 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
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,
397 #define draw_tes_jit_context_constants(_gallivm, _ptr) \
398 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
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")
403 #define draw_tes_jit_context_textures(_gallivm, _ptr) \
404 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
406 #define draw_tes_jit_context_samplers(_gallivm, _ptr) \
407 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
409 #define draw_tes_jit_context_images(_gallivm, _ptr) \
410 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
412 #define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
413 lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
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")
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
],
423 unsigned start_or_maxelt
,
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
,
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
,
438 unsigned instance_id
,
440 unsigned invocation_id
);
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
);
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
,
457 struct draw_llvm_variant_key
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;
466 unsigned clip_user
:1;
467 unsigned clip_halfz
:1;
468 unsigned bypass_viewport
:1;
469 unsigned need_edgeflags
:1;
471 unsigned num_outputs
:8;
472 unsigned ucp_enable
:PIPE_MAX_CLIP_PLANES
;
473 /* note padding here - must use memset */
475 /* Variable number of vertex elements:
477 struct pipe_vertex_element vertex_element
[1];
479 /* Followed by variable number of samplers:
481 /* struct draw_sampler_static_state sampler; */
482 /* Followed by variable number of images
486 struct draw_gs_llvm_variant_key
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 */
494 struct draw_sampler_static_state samplers
[1];
495 /* Followed by variable number of images.*/
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))
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))
511 draw_llvm_variant_key_size(unsigned nr_vertex_elements
,
512 unsigned nr_samplers
, unsigned nr_images
)
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
));
522 draw_gs_llvm_variant_key_size(unsigned nr_samplers
, unsigned nr_images
)
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
));
530 static inline struct draw_sampler_static_state
*
531 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key
*key
)
533 return (struct draw_sampler_static_state
*)
534 &key
->vertex_element
[key
->nr_vertex_elements
];
537 static inline struct draw_image_static_state
*
538 draw_llvm_variant_key_images(struct draw_llvm_variant_key
*key
)
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
];
546 static inline struct draw_image_static_state
*
547 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key
*key
)
549 return (struct draw_image_static_state
*)
550 &key
->samplers
[key
->nr_samplers
];
553 struct draw_llvm_variant_list_item
555 struct draw_llvm_variant
*base
;
556 struct draw_llvm_variant_list_item
*next
, *prev
;
559 struct draw_gs_llvm_variant_list_item
561 struct draw_gs_llvm_variant
*base
;
562 struct draw_gs_llvm_variant_list_item
*next
, *prev
;
566 struct draw_llvm_variant
568 struct gallivm_state
*gallivm
;
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
;
576 LLVMValueRef function
;
577 draw_jit_vert_func jit_func
;
579 struct llvm_vertex_shader
*shader
;
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
;
585 /* key is variable-sized, must be last */
586 struct draw_llvm_variant_key key
;
590 struct draw_gs_llvm_variant
592 struct gallivm_state
*gallivm
;
594 /* LLVM JIT builder types */
595 LLVMTypeRef context_ptr_type
;
596 LLVMTypeRef vertex_header_ptr_type
;
597 LLVMTypeRef input_array_type
;
599 LLVMValueRef context_ptr
;
601 LLVMValueRef num_prims
;
602 LLVMValueRef function
;
603 draw_gs_jit_func jit_func
;
605 struct llvm_geometry_shader
*shader
;
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
;
611 /* key is variable-sized, must be last */
612 struct draw_gs_llvm_variant_key key
;
615 struct llvm_vertex_shader
{
616 struct draw_vertex_shader base
;
618 unsigned variant_key_size
;
619 struct draw_llvm_variant_list_item variants
;
620 unsigned variants_created
;
621 unsigned variants_cached
;
624 struct llvm_geometry_shader
{
625 struct draw_geometry_shader base
;
627 unsigned variant_key_size
;
628 struct draw_gs_llvm_variant_list_item variants
;
629 unsigned variants_created
;
630 unsigned variants_cached
;
635 struct draw_context
*draw
;
637 LLVMContextRef context
;
638 boolean context_owned
;
640 struct draw_jit_context jit_context
;
641 struct draw_gs_jit_context gs_jit_context
;
643 struct draw_llvm_variant_list_item vs_variants_list
;
646 struct draw_gs_llvm_variant_list_item gs_variants_list
;
651 static inline struct llvm_vertex_shader
*
652 llvm_vertex_shader(struct draw_vertex_shader
*vs
)
654 return (struct llvm_vertex_shader
*)vs
;
657 static inline struct llvm_geometry_shader
*
658 llvm_geometry_shader(struct draw_geometry_shader
*gs
)
660 return (struct llvm_geometry_shader
*)gs
;
667 draw_llvm_create(struct draw_context
*draw
, LLVMContextRef llvm_context
);
670 draw_llvm_destroy(struct draw_llvm
*llvm
);
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
);
678 draw_llvm_destroy_variant(struct draw_llvm_variant
*variant
);
680 struct draw_llvm_variant_key
*
681 draw_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
684 draw_llvm_dump_variant_key(struct draw_llvm_variant_key
*key
);
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
);
693 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant
*variant
);
695 struct draw_gs_llvm_variant_key
*
696 draw_gs_llvm_make_variant_key(struct draw_llvm
*llvm
, char *store
);
699 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key
*key
);
701 struct lp_build_sampler_soa
*
702 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state
*static_state
);
704 struct lp_build_image_soa
*
705 draw_llvm_image_soa_create(const struct draw_image_static_state
*static_state
);
708 draw_llvm_set_sampler_state(struct draw_context
*draw
,
709 enum pipe_shader_type shader_stage
);
712 draw_llvm_set_mapped_texture(struct draw_context
*draw
,
713 enum pipe_shader_type shader_stage
,
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
]);
723 draw_llvm_set_mapped_image(struct draw_context
*draw
,
724 enum pipe_shader_type shader_stage
,
726 uint32_t width
, uint32_t height
, uint32_t depth
,
727 const void *base_ptr
,
729 uint32_t img_stride
);