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