llvmpipe: add support for ssbo to the fragment shader jit.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_jit.h
1 /**************************************************************************
2 *
3 * Copyright 2009 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 /**
29 * @file
30 * C - JIT interfaces
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35 #ifndef LP_JIT_H
36 #define LP_JIT_H
37
38
39 #include "gallivm/lp_bld_struct.h"
40 #include "gallivm/lp_bld_limits.h"
41
42 #include "pipe/p_state.h"
43 #include "lp_texture.h"
44
45
46 struct lp_build_format_cache;
47 struct lp_fragment_shader_variant;
48 struct llvmpipe_screen;
49
50
51 struct lp_jit_texture
52 {
53 uint32_t width; /* same as number of elements */
54 uint32_t height;
55 uint32_t depth; /* doubles as array size */
56 uint32_t first_level;
57 uint32_t last_level;
58 const void *base;
59 uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
60 uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
61 uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
62 };
63
64
65 struct lp_jit_sampler
66 {
67 float min_lod;
68 float max_lod;
69 float lod_bias;
70 float border_color[4];
71 };
72
73
74 struct lp_jit_viewport
75 {
76 float min_depth;
77 float max_depth;
78 };
79
80
81 enum {
82 LP_JIT_TEXTURE_WIDTH = 0,
83 LP_JIT_TEXTURE_HEIGHT,
84 LP_JIT_TEXTURE_DEPTH,
85 LP_JIT_TEXTURE_FIRST_LEVEL,
86 LP_JIT_TEXTURE_LAST_LEVEL,
87 LP_JIT_TEXTURE_BASE,
88 LP_JIT_TEXTURE_ROW_STRIDE,
89 LP_JIT_TEXTURE_IMG_STRIDE,
90 LP_JIT_TEXTURE_MIP_OFFSETS,
91 LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */
92 };
93
94
95 enum {
96 LP_JIT_SAMPLER_MIN_LOD,
97 LP_JIT_SAMPLER_MAX_LOD,
98 LP_JIT_SAMPLER_LOD_BIAS,
99 LP_JIT_SAMPLER_BORDER_COLOR,
100 LP_JIT_SAMPLER_NUM_FIELDS /* number of fields above */
101 };
102
103
104 enum {
105 LP_JIT_VIEWPORT_MIN_DEPTH,
106 LP_JIT_VIEWPORT_MAX_DEPTH,
107 LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */
108 };
109
110
111 /**
112 * This structure is passed directly to the generated fragment shader.
113 *
114 * It contains the derived state.
115 *
116 * Changes here must be reflected in the lp_jit_context_* macros and
117 * lp_jit_init_types function. Changes to the ordering should be avoided.
118 *
119 * Only use types with a clear size and padding here, in particular prefer the
120 * stdint.h types to the basic integer types.
121 */
122 struct lp_jit_context
123 {
124 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
125 int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
126
127 float alpha_ref_value;
128
129 uint32_t stencil_ref_front, stencil_ref_back;
130
131 uint8_t *u8_blend_color;
132 float *f_blend_color;
133
134 struct lp_jit_viewport *viewports;
135
136 struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
137 struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
138
139 const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
140 int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
141 };
142
143
144 /**
145 * These enum values must match the position of the fields in the
146 * lp_jit_context struct above.
147 */
148 enum {
149 LP_JIT_CTX_CONSTANTS = 0,
150 LP_JIT_CTX_NUM_CONSTANTS,
151 LP_JIT_CTX_ALPHA_REF,
152 LP_JIT_CTX_STENCIL_REF_FRONT,
153 LP_JIT_CTX_STENCIL_REF_BACK,
154 LP_JIT_CTX_U8_BLEND_COLOR,
155 LP_JIT_CTX_F_BLEND_COLOR,
156 LP_JIT_CTX_VIEWPORTS,
157 LP_JIT_CTX_TEXTURES,
158 LP_JIT_CTX_SAMPLERS,
159 LP_JIT_CTX_SSBOS,
160 LP_JIT_CTX_NUM_SSBOS,
161 LP_JIT_CTX_COUNT
162 };
163
164
165 #define lp_jit_context_constants(_gallivm, _ptr) \
166 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
167
168 #define lp_jit_context_num_constants(_gallivm, _ptr) \
169 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
170
171 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
172 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
173
174 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
175 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
176
177 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
178 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
179
180 #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
181 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
182
183 #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
184 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
185
186 #define lp_jit_context_viewports(_gallivm, _ptr) \
187 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
188
189 #define lp_jit_context_textures(_gallivm, _ptr) \
190 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
191
192 #define lp_jit_context_samplers(_gallivm, _ptr) \
193 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
194
195 #define lp_jit_context_ssbos(_gallivm, _ptr) \
196 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
197
198 #define lp_jit_context_num_ssbos(_gallivm, _ptr) \
199 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
200
201 struct lp_jit_thread_data
202 {
203 struct lp_build_format_cache *cache;
204 uint64_t vis_counter;
205 uint64_t ps_invocations;
206
207 /*
208 * Non-interpolated rasterizer state passed through to the fragment shader.
209 */
210 struct {
211 uint32_t viewport_index;
212 } raster_state;
213 };
214
215
216 enum {
217 LP_JIT_THREAD_DATA_CACHE = 0,
218 LP_JIT_THREAD_DATA_COUNTER,
219 LP_JIT_THREAD_DATA_INVOCATIONS,
220 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX,
221 LP_JIT_THREAD_DATA_COUNT
222 };
223
224
225 #define lp_jit_thread_data_cache(_gallivm, _ptr) \
226 lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
227
228 #define lp_jit_thread_data_counter(_gallivm, _ptr) \
229 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
230
231 #define lp_jit_thread_data_invocations(_gallivm, _ptr) \
232 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
233
234 #define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
235 lp_build_struct_get(_gallivm, _ptr, \
236 LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
237 "raster_state.viewport_index")
238
239 /**
240 * typedef for fragment shader function
241 *
242 * @param context jit context
243 * @param x block start x
244 * @param y block start y
245 * @param facing is front facing
246 * @param a0 shader input a0
247 * @param dadx shader input dadx
248 * @param dady shader input dady
249 * @param color color buffer
250 * @param depth depth buffer
251 * @param mask mask of visible pixels in block
252 * @param thread_data task thread data
253 * @param stride color buffer row stride in bytes
254 * @param depth_stride depth buffer row stride in bytes
255 */
256 typedef void
257 (*lp_jit_frag_func)(const struct lp_jit_context *context,
258 uint32_t x,
259 uint32_t y,
260 uint32_t facing,
261 const void *a0,
262 const void *dadx,
263 const void *dady,
264 uint8_t **color,
265 uint8_t *depth,
266 uint32_t mask,
267 struct lp_jit_thread_data *thread_data,
268 unsigned *stride,
269 unsigned depth_stride);
270
271
272 void
273 lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
274
275
276 boolean
277 lp_jit_screen_init(struct llvmpipe_screen *screen);
278
279
280 void
281 lp_jit_init_types(struct lp_fragment_shader_variant *lp);
282
283
284 #endif /* LP_JIT_H */