1 /**************************************************************************
3 * Copyright 2009 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 **************************************************************************/
32 * @author Jose Fonseca <jfonseca@vmware.com>
39 #include "gallivm/lp_bld_struct.h"
40 #include "gallivm/lp_bld_limits.h"
42 #include "pipe/p_state.h"
43 #include "lp_texture.h"
46 struct lp_build_format_cache
;
47 struct lp_fragment_shader_variant
;
48 struct lp_compute_shader_variant
;
49 struct llvmpipe_screen
;
54 uint32_t width
; /* same as number of elements */
56 uint32_t depth
; /* doubles as array size */
58 uint32_t row_stride
[LP_MAX_TEXTURE_LEVELS
];
59 uint32_t img_stride
[LP_MAX_TEXTURE_LEVELS
];
62 uint32_t mip_offsets
[LP_MAX_TEXTURE_LEVELS
];
64 uint32_t sample_stride
;
73 float border_color
[4];
77 struct lp_jit_viewport
86 uint32_t width
; /* same as number of elements */
93 uint32_t sample_stride
;
97 LP_JIT_TEXTURE_WIDTH
= 0,
98 LP_JIT_TEXTURE_HEIGHT
,
101 LP_JIT_TEXTURE_ROW_STRIDE
,
102 LP_JIT_TEXTURE_IMG_STRIDE
,
103 LP_JIT_TEXTURE_FIRST_LEVEL
,
104 LP_JIT_TEXTURE_LAST_LEVEL
,
105 LP_JIT_TEXTURE_MIP_OFFSETS
,
106 LP_JIT_TEXTURE_NUM_SAMPLES
,
107 LP_JIT_TEXTURE_SAMPLE_STRIDE
,
108 LP_JIT_TEXTURE_NUM_FIELDS
/* number of fields above */
113 LP_JIT_SAMPLER_MIN_LOD
,
114 LP_JIT_SAMPLER_MAX_LOD
,
115 LP_JIT_SAMPLER_LOD_BIAS
,
116 LP_JIT_SAMPLER_BORDER_COLOR
,
117 LP_JIT_SAMPLER_NUM_FIELDS
/* number of fields above */
122 LP_JIT_VIEWPORT_MIN_DEPTH
,
123 LP_JIT_VIEWPORT_MAX_DEPTH
,
124 LP_JIT_VIEWPORT_NUM_FIELDS
/* number of fields above */
128 LP_JIT_IMAGE_WIDTH
= 0,
132 LP_JIT_IMAGE_ROW_STRIDE
,
133 LP_JIT_IMAGE_IMG_STRIDE
,
134 LP_JIT_IMAGE_NUM_SAMPLES
,
135 LP_JIT_IMAGE_SAMPLE_STRIDE
,
136 LP_JIT_IMAGE_NUM_FIELDS
/* number of fields above */
139 * This structure is passed directly to the generated fragment shader.
141 * It contains the derived state.
143 * Changes here must be reflected in the lp_jit_context_* macros and
144 * lp_jit_init_types function. Changes to the ordering should be avoided.
146 * Only use types with a clear size and padding here, in particular prefer the
147 * stdint.h types to the basic integer types.
149 struct lp_jit_context
151 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
152 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
154 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
155 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
156 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
158 float alpha_ref_value
;
160 uint32_t stencil_ref_front
, stencil_ref_back
;
162 uint8_t *u8_blend_color
;
163 float *f_blend_color
;
165 struct lp_jit_viewport
*viewports
;
167 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
168 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
170 uint32_t sample_mask
;
175 * These enum values must match the position of the fields in the
176 * lp_jit_context struct above.
179 LP_JIT_CTX_CONSTANTS
= 0,
180 LP_JIT_CTX_NUM_CONSTANTS
,
184 LP_JIT_CTX_ALPHA_REF
,
185 LP_JIT_CTX_STENCIL_REF_FRONT
,
186 LP_JIT_CTX_STENCIL_REF_BACK
,
187 LP_JIT_CTX_U8_BLEND_COLOR
,
188 LP_JIT_CTX_F_BLEND_COLOR
,
189 LP_JIT_CTX_VIEWPORTS
,
191 LP_JIT_CTX_NUM_SSBOS
,
192 LP_JIT_CTX_SAMPLE_MASK
,
197 #define lp_jit_context_constants(_gallivm, _ptr) \
198 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
200 #define lp_jit_context_num_constants(_gallivm, _ptr) \
201 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
203 #define lp_jit_context_textures(_gallivm, _ptr) \
204 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
206 #define lp_jit_context_samplers(_gallivm, _ptr) \
207 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
209 #define lp_jit_context_images(_gallivm, _ptr) \
210 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")
212 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
213 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
215 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
216 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
218 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
219 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
221 #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
222 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
224 #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
225 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
227 #define lp_jit_context_viewports(_gallivm, _ptr) \
228 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
230 #define lp_jit_context_ssbos(_gallivm, _ptr) \
231 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
233 #define lp_jit_context_num_ssbos(_gallivm, _ptr) \
234 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
236 #define lp_jit_context_sample_mask(_gallivm, _ptr) \
237 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLE_MASK, "sample_mask")
239 struct lp_jit_thread_data
241 struct lp_build_format_cache
*cache
;
242 uint64_t vis_counter
;
243 uint64_t ps_invocations
;
246 * Non-interpolated rasterizer state passed through to the fragment shader.
249 uint32_t viewport_index
;
255 LP_JIT_THREAD_DATA_CACHE
= 0,
256 LP_JIT_THREAD_DATA_COUNTER
,
257 LP_JIT_THREAD_DATA_INVOCATIONS
,
258 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
,
259 LP_JIT_THREAD_DATA_COUNT
263 #define lp_jit_thread_data_cache(_gallivm, _ptr) \
264 lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
266 #define lp_jit_thread_data_counter(_gallivm, _ptr) \
267 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
269 #define lp_jit_thread_data_invocations(_gallivm, _ptr) \
270 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
272 #define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
273 lp_build_struct_get(_gallivm, _ptr, \
274 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
275 "raster_state.viewport_index")
278 * typedef for fragment shader function
280 * @param context jit context
281 * @param x block start x
282 * @param y block start y
283 * @param facing is front facing
284 * @param a0 shader input a0
285 * @param dadx shader input dadx
286 * @param dady shader input dady
287 * @param color color buffer
288 * @param depth depth buffer
289 * @param mask mask of visible pixels in block (16-bits per sample)
290 * @param thread_data task thread data
291 * @param stride color buffer row stride in bytes
292 * @param depth_stride depth buffer row stride in bytes
295 (*lp_jit_frag_func
)(const struct lp_jit_context
*context
,
305 struct lp_jit_thread_data
*thread_data
,
307 unsigned depth_stride
,
308 unsigned *color_sample_stride
,
309 unsigned depth_sample_stride
);
312 struct lp_jit_cs_thread_data
314 struct lp_build_format_cache
*cache
;
319 LP_JIT_CS_THREAD_DATA_CACHE
= 0,
320 LP_JIT_CS_THREAD_DATA_SHARED
= 1,
321 LP_JIT_CS_THREAD_DATA_COUNT
325 #define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \
326 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")
328 #define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \
329 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")
331 struct lp_jit_cs_context
333 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
334 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
336 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
337 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
338 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
340 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
341 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
345 uint32_t shared_size
;
349 * These enum values must match the position of the fields in the
350 * lp_jit_context struct above.
353 LP_JIT_CS_CTX_CONSTANTS
= 0,
354 LP_JIT_CS_CTX_NUM_CONSTANTS
,
355 LP_JIT_CS_CTX_TEXTURES
, /* must match the LP_JIT_CTX_TEXTURES */
356 LP_JIT_CS_CTX_SAMPLERS
,
357 LP_JIT_CS_CTX_IMAGES
,
359 LP_JIT_CS_CTX_NUM_SSBOS
,
360 LP_JIT_CS_CTX_KERNEL_ARGS
,
361 LP_JIT_CS_CTX_SHARED_SIZE
,
365 #define lp_jit_cs_context_constants(_gallivm, _ptr) \
366 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")
368 #define lp_jit_cs_context_num_constants(_gallivm, _ptr) \
369 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")
371 #define lp_jit_cs_context_textures(_gallivm, _ptr) \
372 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")
374 #define lp_jit_cs_context_samplers(_gallivm, _ptr) \
375 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")
377 #define lp_jit_cs_context_images(_gallivm, _ptr) \
378 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")
380 #define lp_jit_cs_context_ssbos(_gallivm, _ptr) \
381 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")
383 #define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \
384 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")
386 #define lp_jit_cs_context_shared_size(_gallivm, _ptr) \
387 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")
389 #define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \
390 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")
394 (*lp_jit_cs_func
)(const struct lp_jit_cs_context
*context
,
401 uint32_t grid_size_x
,
402 uint32_t grid_size_y
,
403 uint32_t grid_size_z
,
405 struct lp_jit_cs_thread_data
*thread_data
);
408 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
);
412 lp_jit_screen_init(struct llvmpipe_screen
*screen
);
416 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
);
419 lp_jit_init_cs_types(struct lp_compute_shader_variant
*lp
);
420 #endif /* LP_JIT_H */