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
];
71 float border_color
[4];
75 struct lp_jit_viewport
84 uint32_t width
; /* same as number of elements */
93 LP_JIT_TEXTURE_WIDTH
= 0,
94 LP_JIT_TEXTURE_HEIGHT
,
97 LP_JIT_TEXTURE_ROW_STRIDE
,
98 LP_JIT_TEXTURE_IMG_STRIDE
,
99 LP_JIT_TEXTURE_FIRST_LEVEL
,
100 LP_JIT_TEXTURE_LAST_LEVEL
,
101 LP_JIT_TEXTURE_MIP_OFFSETS
,
102 LP_JIT_TEXTURE_NUM_FIELDS
/* number of fields above */
107 LP_JIT_SAMPLER_MIN_LOD
,
108 LP_JIT_SAMPLER_MAX_LOD
,
109 LP_JIT_SAMPLER_LOD_BIAS
,
110 LP_JIT_SAMPLER_BORDER_COLOR
,
111 LP_JIT_SAMPLER_NUM_FIELDS
/* number of fields above */
116 LP_JIT_VIEWPORT_MIN_DEPTH
,
117 LP_JIT_VIEWPORT_MAX_DEPTH
,
118 LP_JIT_VIEWPORT_NUM_FIELDS
/* number of fields above */
122 LP_JIT_IMAGE_WIDTH
= 0,
126 LP_JIT_IMAGE_ROW_STRIDE
,
127 LP_JIT_IMAGE_IMG_STRIDE
,
128 LP_JIT_IMAGE_NUM_FIELDS
/* number of fields above */
131 * This structure is passed directly to the generated fragment shader.
133 * It contains the derived state.
135 * Changes here must be reflected in the lp_jit_context_* macros and
136 * lp_jit_init_types function. Changes to the ordering should be avoided.
138 * Only use types with a clear size and padding here, in particular prefer the
139 * stdint.h types to the basic integer types.
141 struct lp_jit_context
143 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
144 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
146 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
147 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
148 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
150 float alpha_ref_value
;
152 uint32_t stencil_ref_front
, stencil_ref_back
;
154 uint8_t *u8_blend_color
;
155 float *f_blend_color
;
157 struct lp_jit_viewport
*viewports
;
159 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
160 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
165 * These enum values must match the position of the fields in the
166 * lp_jit_context struct above.
169 LP_JIT_CTX_CONSTANTS
= 0,
170 LP_JIT_CTX_NUM_CONSTANTS
,
174 LP_JIT_CTX_ALPHA_REF
,
175 LP_JIT_CTX_STENCIL_REF_FRONT
,
176 LP_JIT_CTX_STENCIL_REF_BACK
,
177 LP_JIT_CTX_U8_BLEND_COLOR
,
178 LP_JIT_CTX_F_BLEND_COLOR
,
179 LP_JIT_CTX_VIEWPORTS
,
181 LP_JIT_CTX_NUM_SSBOS
,
186 #define lp_jit_context_constants(_gallivm, _ptr) \
187 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
189 #define lp_jit_context_num_constants(_gallivm, _ptr) \
190 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
192 #define lp_jit_context_textures(_gallivm, _ptr) \
193 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
195 #define lp_jit_context_samplers(_gallivm, _ptr) \
196 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
198 #define lp_jit_context_images(_gallivm, _ptr) \
199 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")
201 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
202 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
204 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
205 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
207 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
208 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
210 #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
211 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
213 #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
214 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
216 #define lp_jit_context_viewports(_gallivm, _ptr) \
217 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
219 #define lp_jit_context_ssbos(_gallivm, _ptr) \
220 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
222 #define lp_jit_context_num_ssbos(_gallivm, _ptr) \
223 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
225 struct lp_jit_thread_data
227 struct lp_build_format_cache
*cache
;
228 uint64_t vis_counter
;
229 uint64_t ps_invocations
;
232 * Non-interpolated rasterizer state passed through to the fragment shader.
235 uint32_t viewport_index
;
241 LP_JIT_THREAD_DATA_CACHE
= 0,
242 LP_JIT_THREAD_DATA_COUNTER
,
243 LP_JIT_THREAD_DATA_INVOCATIONS
,
244 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
,
245 LP_JIT_THREAD_DATA_COUNT
249 #define lp_jit_thread_data_cache(_gallivm, _ptr) \
250 lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
252 #define lp_jit_thread_data_counter(_gallivm, _ptr) \
253 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
255 #define lp_jit_thread_data_invocations(_gallivm, _ptr) \
256 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
258 #define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
259 lp_build_struct_get(_gallivm, _ptr, \
260 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
261 "raster_state.viewport_index")
264 * typedef for fragment shader function
266 * @param context jit context
267 * @param x block start x
268 * @param y block start y
269 * @param facing is front facing
270 * @param a0 shader input a0
271 * @param dadx shader input dadx
272 * @param dady shader input dady
273 * @param color color buffer
274 * @param depth depth buffer
275 * @param mask mask of visible pixels in block
276 * @param thread_data task thread data
277 * @param stride color buffer row stride in bytes
278 * @param depth_stride depth buffer row stride in bytes
281 (*lp_jit_frag_func
)(const struct lp_jit_context
*context
,
291 struct lp_jit_thread_data
*thread_data
,
293 unsigned depth_stride
);
296 struct lp_jit_cs_thread_data
298 struct lp_build_format_cache
*cache
;
303 LP_JIT_CS_THREAD_DATA_CACHE
= 0,
304 LP_JIT_CS_THREAD_DATA_SHARED
= 1,
305 LP_JIT_CS_THREAD_DATA_COUNT
309 #define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \
310 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")
312 #define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \
313 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")
315 struct lp_jit_cs_context
317 const float *constants
[LP_MAX_TGSI_CONST_BUFFERS
];
318 int num_constants
[LP_MAX_TGSI_CONST_BUFFERS
];
320 struct lp_jit_texture textures
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
321 struct lp_jit_sampler samplers
[PIPE_MAX_SAMPLERS
];
322 struct lp_jit_image images
[PIPE_MAX_SHADER_IMAGES
];
324 const uint32_t *ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
325 int num_ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
329 uint32_t shared_size
;
333 * These enum values must match the position of the fields in the
334 * lp_jit_context struct above.
337 LP_JIT_CS_CTX_CONSTANTS
= 0,
338 LP_JIT_CS_CTX_NUM_CONSTANTS
,
339 LP_JIT_CS_CTX_TEXTURES
, /* must match the LP_JIT_CTX_TEXTURES */
340 LP_JIT_CS_CTX_SAMPLERS
,
341 LP_JIT_CS_CTX_IMAGES
,
343 LP_JIT_CS_CTX_NUM_SSBOS
,
344 LP_JIT_CS_CTX_KERNEL_ARGS
,
345 LP_JIT_CS_CTX_SHARED_SIZE
,
349 #define lp_jit_cs_context_constants(_gallivm, _ptr) \
350 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")
352 #define lp_jit_cs_context_num_constants(_gallivm, _ptr) \
353 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")
355 #define lp_jit_cs_context_textures(_gallivm, _ptr) \
356 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")
358 #define lp_jit_cs_context_samplers(_gallivm, _ptr) \
359 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")
361 #define lp_jit_cs_context_images(_gallivm, _ptr) \
362 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")
364 #define lp_jit_cs_context_ssbos(_gallivm, _ptr) \
365 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")
367 #define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \
368 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")
370 #define lp_jit_cs_context_shared_size(_gallivm, _ptr) \
371 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")
373 #define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \
374 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")
378 (*lp_jit_cs_func
)(const struct lp_jit_cs_context
*context
,
385 uint32_t grid_size_x
,
386 uint32_t grid_size_y
,
387 uint32_t grid_size_z
,
389 struct lp_jit_cs_thread_data
*thread_data
);
392 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
);
396 lp_jit_screen_init(struct llvmpipe_screen
*screen
);
400 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
);
403 lp_jit_init_cs_types(struct lp_compute_shader_variant
*lp
);
404 #endif /* LP_JIT_H */