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/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(_variant, _ptr) \
192 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
193
194 #define draw_jit_context_num_vs_constants(_variant, _ptr) \
195 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
196
197 #define draw_jit_context_planes(_gallivm, _type, _ptr) \
198 lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_CTX_PLANES, "planes")
199
200 #define draw_jit_context_viewports(_variant, _ptr) \
201 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
213 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
214
215 #define draw_jit_context_num_vs_ssbos(_variant, _ptr) \
216 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
217
218 #define draw_jit_context_aniso_filter_table(_variant, _ptr) \
219 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
220
221
222 #define draw_jit_header_id(_gallivm, _type, _ptr) \
223 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
224
225 #define draw_jit_header_clip_pos(_gallivm, _type, _ptr) \
226 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
227
228 #define draw_jit_header_data(_gallivm, _type, _ptr) \
229 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_DATA, "data")
230
231
232 #define draw_jit_vbuffer_stride(_gallivm, _type, _ptr) \
233 lp_build_struct_get2(_gallivm, _type, _ptr, 0, "stride")
234
235 #define draw_jit_vbuffer_offset(_gallivm, _type, _ptr) \
236 lp_build_struct_get2(_gallivm, _type, _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, _type, _ptr) \
245 lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
246
247 #define draw_jit_dvbuffer_size(_gallivm, _type, _ptr) \
248 lp_build_struct_get2(_gallivm, _type, _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(_variant, _ptr) \
306 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
307
308 #define draw_gs_jit_context_num_constants(_variant, _ptr) \
309 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
327 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
328
329 #define draw_gs_jit_emitted_vertices(_variant, _ptr) \
330 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
331
332 #define draw_gs_jit_emitted_prims(_variant, _ptr) \
333 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
334
335 #define draw_gs_jit_context_ssbos(_variant, _ptr) \
336 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
337
338 #define draw_gs_jit_context_num_ssbos(_variant, _ptr) \
339 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
340
341 #define draw_gs_jit_context_aniso_filter_table(_variant, _ptr) \
342 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
375 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
376
377 #define draw_tcs_jit_context_num_constants(_variant, _ptr) \
378 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
390 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
391
392 #define draw_tcs_jit_context_num_ssbos(_variant, _ptr) \
393 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
394
395 #define draw_tcs_jit_context_aniso_filter_table(_variant, _ptr) \
396 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
429 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
430
431 #define draw_tes_jit_context_num_constants(_variant, _ptr) \
432 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _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(_variant, _ptr) \
444 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
445
446 #define draw_tes_jit_context_num_ssbos(_variant, _ptr) \
447 lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
448
449 #define draw_tes_jit_context_aniso_filter_table(_variant, _ptr) \
450 lp_build_struct_get2(_variant->gallivm, _variant->context_type, _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_sampler_views,unsigned nr_images)579 draw_llvm_variant_key_size(unsigned nr_vertex_elements,
580 unsigned nr_samplers,
581 unsigned nr_sampler_views,
582 unsigned nr_images)
583 {
584 return (sizeof(struct draw_llvm_variant_key) +
585 (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element) +
586 MAX2(nr_samplers, nr_sampler_views) *
587 sizeof(struct draw_sampler_static_state) +
588 nr_images * sizeof(struct draw_image_static_state));
589 }
590
591
592 static inline size_t
draw_gs_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_sampler_views,unsigned nr_images)593 draw_gs_llvm_variant_key_size(unsigned nr_samplers,
594 unsigned nr_sampler_views,
595 unsigned nr_images)
596 {
597 return (sizeof(struct draw_gs_llvm_variant_key) +
598 (MAX2(nr_samplers, nr_sampler_views) - 1) *
599 sizeof(struct draw_sampler_static_state) +
600 nr_images * sizeof(struct draw_sampler_static_state));
601 }
602
603 static inline size_t
draw_tcs_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_sampler_views,unsigned nr_images)604 draw_tcs_llvm_variant_key_size(unsigned nr_samplers,
605 unsigned nr_sampler_views,
606 unsigned nr_images)
607 {
608 return (sizeof(struct draw_tcs_llvm_variant_key) +
609 (MAX2(nr_samplers, nr_sampler_views) - 1) *
610 sizeof(struct draw_sampler_static_state) +
611 nr_images * sizeof(struct draw_sampler_static_state));
612 }
613
614 static inline size_t
draw_tes_llvm_variant_key_size(unsigned nr_samplers,unsigned nr_sampler_views,unsigned nr_images)615 draw_tes_llvm_variant_key_size(unsigned nr_samplers,
616 unsigned nr_sampler_views,
617 unsigned nr_images)
618 {
619 return (sizeof(struct draw_tes_llvm_variant_key) +
620 (MAX2(nr_samplers, nr_sampler_views) - 1) *
621 sizeof(struct draw_sampler_static_state) +
622 nr_images * sizeof(struct draw_sampler_static_state));
623 }
624
625 static inline struct draw_sampler_static_state *
draw_llvm_variant_key_samplers(struct draw_llvm_variant_key * key)626 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
627 {
628 return (struct draw_sampler_static_state *)
629 &key->vertex_element[key->nr_vertex_elements];
630 }
631
632 static inline struct draw_image_static_state *
draw_llvm_variant_key_images(struct draw_llvm_variant_key * key)633 draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
634 {
635 struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
636 (&key->vertex_element[key->nr_vertex_elements]);
637 return (struct draw_image_static_state *)
638 &samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
639 }
640
641 static inline struct draw_image_static_state *
draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key * key)642 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
643 {
644 return (struct draw_image_static_state *)
645 &key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
646 }
647
648 static inline struct draw_image_static_state *
draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key * key)649 draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)
650 {
651 return (struct draw_image_static_state *)
652 &key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
653 }
654
655 static inline struct draw_image_static_state *
draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key * key)656 draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)
657 {
658 return (struct draw_image_static_state *)
659 &key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
660 }
661
662 struct draw_llvm_variant_list_item
663 {
664 struct list_head list;
665 struct draw_llvm_variant *base;
666 };
667
668 struct draw_gs_llvm_variant_list_item
669 {
670 struct list_head list;
671 struct draw_gs_llvm_variant *base;
672 };
673
674 struct draw_tcs_llvm_variant_list_item
675 {
676 struct list_head list;
677 struct draw_tcs_llvm_variant *base;
678 };
679
680 struct draw_tes_llvm_variant_list_item
681 {
682 struct list_head list;
683 struct draw_tes_llvm_variant *base;
684 };
685
686 struct draw_llvm_variant
687 {
688 struct gallivm_state *gallivm;
689
690 /* LLVM JIT builder types */
691 LLVMTypeRef context_type;
692 LLVMTypeRef context_ptr_type;
693
694 LLVMTypeRef buffer_type;
695 LLVMTypeRef buffer_ptr_type;
696
697 LLVMTypeRef vb_type;
698 LLVMTypeRef vb_ptr_type;
699
700 LLVMTypeRef vertex_header_type;
701 LLVMTypeRef vertex_header_ptr_type;
702
703 LLVMValueRef function;
704 draw_jit_vert_func jit_func;
705
706 struct llvm_vertex_shader *shader;
707
708 struct draw_llvm *llvm;
709 struct draw_llvm_variant_list_item list_item_global;
710 struct draw_llvm_variant_list_item list_item_local;
711
712 /* key is variable-sized, must be last */
713 struct draw_llvm_variant_key key;
714 };
715
716
717 struct draw_gs_llvm_variant
718 {
719 struct gallivm_state *gallivm;
720
721 /* LLVM JIT builder types */
722 LLVMTypeRef context_type;
723 LLVMTypeRef context_ptr_type;
724
725 LLVMTypeRef vertex_header_type;
726 LLVMTypeRef vertex_header_ptr_type;
727
728 LLVMTypeRef input_array_type;
729
730 LLVMValueRef context_ptr;
731 LLVMValueRef io_ptr;
732 LLVMValueRef num_prims;
733 LLVMValueRef function;
734 draw_gs_jit_func jit_func;
735
736 struct llvm_geometry_shader *shader;
737
738 struct draw_llvm *llvm;
739 struct draw_gs_llvm_variant_list_item list_item_global;
740 struct draw_gs_llvm_variant_list_item list_item_local;
741
742 /* key is variable-sized, must be last */
743 struct draw_gs_llvm_variant_key key;
744 };
745
746 struct draw_tcs_llvm_variant
747 {
748 struct gallivm_state *gallivm;
749
750 /* LLVM JIT builder types */
751 LLVMTypeRef context_type;
752 LLVMTypeRef context_ptr_type;
753 LLVMTypeRef input_array_type;
754 LLVMTypeRef output_array_type;
755
756 LLVMValueRef context_ptr;
757 /* LLVMValueRef io_ptr; */
758 LLVMValueRef num_prims;
759 LLVMValueRef function;
760 draw_tcs_jit_func jit_func;
761
762 struct llvm_tess_ctrl_shader *shader;
763
764 struct draw_llvm *llvm;
765 struct draw_tcs_llvm_variant_list_item list_item_global;
766 struct draw_tcs_llvm_variant_list_item list_item_local;
767
768 /* key is variable-sized, must be last */
769 struct draw_tcs_llvm_variant_key key;
770 };
771
772 struct draw_tes_llvm_variant
773 {
774 struct gallivm_state *gallivm;
775
776 /* LLVM JIT builder types */
777 LLVMTypeRef context_type;
778 LLVMTypeRef context_ptr_type;
779 LLVMTypeRef vertex_header_ptr_type;
780 LLVMTypeRef input_array_type;
781 LLVMTypeRef patch_input_array_type;
782
783 LLVMTypeRef input_array_deref_type;
784 LLVMTypeRef vertex_header_type;
785
786 LLVMValueRef context_ptr;
787 LLVMValueRef io_ptr;
788 LLVMValueRef num_prims;
789 LLVMValueRef function;
790 draw_tes_jit_func jit_func;
791
792 struct llvm_tess_eval_shader *shader;
793
794 struct draw_llvm *llvm;
795 struct draw_tes_llvm_variant_list_item list_item_global;
796 struct draw_tes_llvm_variant_list_item list_item_local;
797
798 /* key is variable-sized, must be last */
799 struct draw_tes_llvm_variant_key key;
800 };
801
802 struct llvm_vertex_shader {
803 struct draw_vertex_shader base;
804
805 unsigned variant_key_size;
806 struct draw_llvm_variant_list_item variants;
807 unsigned variants_created;
808 unsigned variants_cached;
809 };
810
811 struct llvm_geometry_shader {
812 struct draw_geometry_shader base;
813
814 unsigned variant_key_size;
815 struct draw_gs_llvm_variant_list_item variants;
816 unsigned variants_created;
817 unsigned variants_cached;
818 };
819
820 struct llvm_tess_ctrl_shader {
821 struct draw_tess_ctrl_shader base;
822
823 unsigned variant_key_size;
824 struct draw_tcs_llvm_variant_list_item variants;
825 unsigned variants_created;
826 unsigned variants_cached;
827 };
828
829 struct llvm_tess_eval_shader {
830 struct draw_tess_eval_shader base;
831
832 unsigned variant_key_size;
833 struct draw_tes_llvm_variant_list_item variants;
834 unsigned variants_created;
835 unsigned variants_cached;
836 };
837
838 struct draw_llvm {
839 struct draw_context *draw;
840
841 LLVMContextRef context;
842 boolean context_owned;
843
844 struct draw_jit_context jit_context;
845 struct draw_gs_jit_context gs_jit_context;
846 struct draw_tcs_jit_context tcs_jit_context;
847 struct draw_tes_jit_context tes_jit_context;
848
849 struct draw_llvm_variant_list_item vs_variants_list;
850 int nr_variants;
851
852 struct draw_gs_llvm_variant_list_item gs_variants_list;
853 int nr_gs_variants;
854
855 struct draw_tcs_llvm_variant_list_item tcs_variants_list;
856 int nr_tcs_variants;
857
858 struct draw_tes_llvm_variant_list_item tes_variants_list;
859 int nr_tes_variants;
860 };
861
862
863 static inline struct llvm_vertex_shader *
llvm_vertex_shader(struct draw_vertex_shader * vs)864 llvm_vertex_shader(struct draw_vertex_shader *vs)
865 {
866 return (struct llvm_vertex_shader *)vs;
867 }
868
869 static inline struct llvm_geometry_shader *
llvm_geometry_shader(struct draw_geometry_shader * gs)870 llvm_geometry_shader(struct draw_geometry_shader *gs)
871 {
872 return (struct llvm_geometry_shader *)gs;
873 }
874
875 static inline struct llvm_tess_ctrl_shader *
llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader * tcs)876 llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader *tcs)
877 {
878 return (struct llvm_tess_ctrl_shader *)tcs;
879 }
880
881 static inline struct llvm_tess_eval_shader *
llvm_tess_eval_shader(struct draw_tess_eval_shader * tes)882 llvm_tess_eval_shader(struct draw_tess_eval_shader *tes)
883 {
884 return (struct llvm_tess_eval_shader *)tes;
885 }
886
887 struct draw_llvm *
888 draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
889
890 void
891 draw_llvm_destroy(struct draw_llvm *llvm);
892
893 struct draw_llvm_variant *
894 draw_llvm_create_variant(struct draw_llvm *llvm,
895 unsigned num_vertex_header_attribs,
896 const struct draw_llvm_variant_key *key);
897
898 void
899 draw_llvm_destroy_variant(struct draw_llvm_variant *variant);
900
901 struct draw_llvm_variant_key *
902 draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
903
904 void
905 draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);
906
907
908 struct draw_gs_llvm_variant *
909 draw_gs_llvm_create_variant(struct draw_llvm *llvm,
910 unsigned num_vertex_header_attribs,
911 const struct draw_gs_llvm_variant_key *key);
912
913 void
914 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);
915
916 struct draw_gs_llvm_variant_key *
917 draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
918
919 void
920 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
921
922 struct draw_tcs_llvm_variant *
923 draw_tcs_llvm_create_variant(struct draw_llvm *llvm,
924 unsigned num_vertex_header_attribs,
925 const struct draw_tcs_llvm_variant_key *key);
926
927 void
928 draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant);
929
930 struct draw_tcs_llvm_variant_key *
931 draw_tcs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
932
933 void
934 draw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key *key);
935
936 struct draw_tes_llvm_variant *
937 draw_tes_llvm_create_variant(struct draw_llvm *llvm,
938 unsigned num_vertex_header_attribs,
939 const struct draw_tes_llvm_variant_key *key);
940
941 void
942 draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant);
943
944 struct draw_tes_llvm_variant_key *
945 draw_tes_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
946
947 void
948 draw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key *key);
949
950 struct lp_build_sampler_soa *
951 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
952 unsigned nr_samplers);
953
954 struct lp_build_image_soa *
955 draw_llvm_image_soa_create(const struct draw_image_static_state *static_state,
956 unsigned nr_images);
957
958 void
959 draw_llvm_set_sampler_state(struct draw_context *draw,
960 enum pipe_shader_type shader_stage);
961
962 void
963 draw_llvm_set_mapped_texture(struct draw_context *draw,
964 enum pipe_shader_type shader_stage,
965 unsigned sview_idx,
966 uint32_t width, uint32_t height, uint32_t depth,
967 uint32_t first_level, uint32_t last_level,
968 uint32_t num_samples,
969 uint32_t sample_stride,
970 const void *base_ptr,
971 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
972 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
973 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
974
975 void
976 draw_llvm_set_mapped_image(struct draw_context *draw,
977 enum pipe_shader_type shader_stage,
978 unsigned idx,
979 uint32_t width, uint32_t height, uint32_t depth,
980 const void *base_ptr,
981 uint32_t row_stride,
982 uint32_t img_stride,
983 uint32_t num_samples,
984 uint32_t sample_stride);
985 #endif
986