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 */
95 LP_JIT_TEXTURE_WIDTH
= 0,
96 LP_JIT_TEXTURE_HEIGHT
,
99 LP_JIT_TEXTURE_ROW_STRIDE
,
100 LP_JIT_TEXTURE_IMG_STRIDE
,
101 LP_JIT_TEXTURE_FIRST_LEVEL
,
102 LP_JIT_TEXTURE_LAST_LEVEL
,
103 LP_JIT_TEXTURE_MIP_OFFSETS
,
104 LP_JIT_TEXTURE_NUM_SAMPLES
,
105 LP_JIT_TEXTURE_SAMPLE_STRIDE
,
106 LP_JIT_TEXTURE_NUM_FIELDS
/* number of fields above */
111 LP_JIT_SAMPLER_MIN_LOD
,
112 LP_JIT_SAMPLER_MAX_LOD
,
113 LP_JIT_SAMPLER_LOD_BIAS
,
114 LP_JIT_SAMPLER_BORDER_COLOR
,
115 LP_JIT_SAMPLER_NUM_FIELDS
/* number of fields above */
120 LP_JIT_VIEWPORT_MIN_DEPTH
,
121 LP_JIT_VIEWPORT_MAX_DEPTH
,
122 LP_JIT_VIEWPORT_NUM_FIELDS
/* number of fields above */
126 LP_JIT_IMAGE_WIDTH
= 0,
130 LP_JIT_IMAGE_ROW_STRIDE
,
131 LP_JIT_IMAGE_IMG_STRIDE
,
132 LP_JIT_IMAGE_NUM_FIELDS
/* number of fields above */
135 * This structure is passed directly to the generated fragment shader.
137 * It contains the derived state.
139 * Changes here must be reflected in the lp_jit_context_* macros and
140 * lp_jit_init_types function. Changes to the ordering should be avoided.
142 * Only use types with a clear size and padding here, in particular prefer the
143 * stdint.h types to the basic integer types.
145 struct lp_jit_context
147 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
148 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
150 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
151 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
152 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
154 float alpha_ref_value
;
156 uint32_t stencil_ref_front
, stencil_ref_back
;
158 uint8_t *u8_blend_color
;
159 float *f_blend_color
;
161 struct lp_jit_viewport
*viewports
;
163 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
164 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
169 * These enum values must match the position of the fields in the
170 * lp_jit_context struct above.
173 LP_JIT_CTX_CONSTANTS
= 0,
174 LP_JIT_CTX_NUM_CONSTANTS
,
178 LP_JIT_CTX_ALPHA_REF
,
179 LP_JIT_CTX_STENCIL_REF_FRONT
,
180 LP_JIT_CTX_STENCIL_REF_BACK
,
181 LP_JIT_CTX_U8_BLEND_COLOR
,
182 LP_JIT_CTX_F_BLEND_COLOR
,
183 LP_JIT_CTX_VIEWPORTS
,
185 LP_JIT_CTX_NUM_SSBOS
,
190 #define lp_jit_context_constants(_gallivm, _ptr) \
191 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
193 #define lp_jit_context_num_constants(_gallivm, _ptr) \
194 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
196 #define lp_jit_context_textures(_gallivm, _ptr) \
197 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
199 #define lp_jit_context_samplers(_gallivm, _ptr) \
200 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
202 #define lp_jit_context_images(_gallivm, _ptr) \
203 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")
205 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
206 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
208 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
209 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
211 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
212 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
214 #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
215 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
217 #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
218 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
220 #define lp_jit_context_viewports(_gallivm, _ptr) \
221 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
223 #define lp_jit_context_ssbos(_gallivm, _ptr) \
224 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
226 #define lp_jit_context_num_ssbos(_gallivm, _ptr) \
227 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
229 struct lp_jit_thread_data
231 struct lp_build_format_cache
*cache
;
232 uint64_t vis_counter
;
233 uint64_t ps_invocations
;
236 * Non-interpolated rasterizer state passed through to the fragment shader.
239 uint32_t viewport_index
;
245 LP_JIT_THREAD_DATA_CACHE
= 0,
246 LP_JIT_THREAD_DATA_COUNTER
,
247 LP_JIT_THREAD_DATA_INVOCATIONS
,
248 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
,
249 LP_JIT_THREAD_DATA_COUNT
253 #define lp_jit_thread_data_cache(_gallivm, _ptr) \
254 lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
256 #define lp_jit_thread_data_counter(_gallivm, _ptr) \
257 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
259 #define lp_jit_thread_data_invocations(_gallivm, _ptr) \
260 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
262 #define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
263 lp_build_struct_get(_gallivm, _ptr, \
264 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
265 "raster_state.viewport_index")
268 * typedef for fragment shader function
270 * @param context jit context
271 * @param x block start x
272 * @param y block start y
273 * @param facing is front facing
274 * @param a0 shader input a0
275 * @param dadx shader input dadx
276 * @param dady shader input dady
277 * @param color color buffer
278 * @param depth depth buffer
279 * @param mask mask of visible pixels in block
280 * @param thread_data task thread data
281 * @param stride color buffer row stride in bytes
282 * @param depth_stride depth buffer row stride in bytes
285 (*lp_jit_frag_func
)(const struct lp_jit_context
*context
,
295 struct lp_jit_thread_data
*thread_data
,
297 unsigned depth_stride
);
300 struct lp_jit_cs_thread_data
302 struct lp_build_format_cache
*cache
;
307 LP_JIT_CS_THREAD_DATA_CACHE
= 0,
308 LP_JIT_CS_THREAD_DATA_SHARED
= 1,
309 LP_JIT_CS_THREAD_DATA_COUNT
313 #define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \
314 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")
316 #define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \
317 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")
319 struct lp_jit_cs_context
321 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
322 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
324 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
325 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
326 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
328 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
329 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
333 uint32_t shared_size
;
337 * These enum values must match the position of the fields in the
338 * lp_jit_context struct above.
341 LP_JIT_CS_CTX_CONSTANTS
= 0,
342 LP_JIT_CS_CTX_NUM_CONSTANTS
,
343 LP_JIT_CS_CTX_TEXTURES
, /* must match the LP_JIT_CTX_TEXTURES */
344 LP_JIT_CS_CTX_SAMPLERS
,
345 LP_JIT_CS_CTX_IMAGES
,
347 LP_JIT_CS_CTX_NUM_SSBOS
,
348 LP_JIT_CS_CTX_KERNEL_ARGS
,
349 LP_JIT_CS_CTX_SHARED_SIZE
,
353 #define lp_jit_cs_context_constants(_gallivm, _ptr) \
354 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")
356 #define lp_jit_cs_context_num_constants(_gallivm, _ptr) \
357 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")
359 #define lp_jit_cs_context_textures(_gallivm, _ptr) \
360 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")
362 #define lp_jit_cs_context_samplers(_gallivm, _ptr) \
363 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")
365 #define lp_jit_cs_context_images(_gallivm, _ptr) \
366 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")
368 #define lp_jit_cs_context_ssbos(_gallivm, _ptr) \
369 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")
371 #define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \
372 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")
374 #define lp_jit_cs_context_shared_size(_gallivm, _ptr) \
375 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")
377 #define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \
378 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")
382 (*lp_jit_cs_func
)(const struct lp_jit_cs_context
*context
,
389 uint32_t grid_size_x
,
390 uint32_t grid_size_y
,
391 uint32_t grid_size_z
,
393 struct lp_jit_cs_thread_data
*thread_data
);
396 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
);
400 lp_jit_screen_init(struct llvmpipe_screen
*screen
);
404 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
);
407 lp_jit_init_cs_types(struct lp_compute_shader_variant
*lp
);
408 #endif /* LP_JIT_H */