Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_jit.h
4570 views
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 <[email protected]>
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 lp_compute_shader_variant;
49
struct llvmpipe_screen;
50
51
52
struct lp_jit_texture
53
{
54
uint32_t width; /* same as number of elements */
55
uint32_t height;
56
uint32_t depth; /* doubles as array size */
57
const void *base;
58
uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
59
uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
60
uint32_t first_level;
61
uint32_t last_level;
62
uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
63
uint32_t num_samples;
64
uint32_t sample_stride;
65
};
66
67
68
struct lp_jit_sampler
69
{
70
float min_lod;
71
float max_lod;
72
float lod_bias;
73
float border_color[4];
74
};
75
76
77
struct lp_jit_viewport
78
{
79
float min_depth;
80
float max_depth;
81
};
82
83
84
struct lp_jit_image
85
{
86
uint32_t width; /* same as number of elements */
87
uint32_t height;
88
uint32_t depth;
89
const void *base;
90
uint32_t row_stride;
91
uint32_t img_stride;
92
uint32_t num_samples;
93
uint32_t sample_stride;
94
};
95
96
enum {
97
LP_JIT_TEXTURE_WIDTH = 0,
98
LP_JIT_TEXTURE_HEIGHT,
99
LP_JIT_TEXTURE_DEPTH,
100
LP_JIT_TEXTURE_BASE,
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 */
109
};
110
111
112
enum {
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 */
118
};
119
120
121
enum {
122
LP_JIT_VIEWPORT_MIN_DEPTH,
123
LP_JIT_VIEWPORT_MAX_DEPTH,
124
LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */
125
};
126
127
enum {
128
LP_JIT_IMAGE_WIDTH = 0,
129
LP_JIT_IMAGE_HEIGHT,
130
LP_JIT_IMAGE_DEPTH,
131
LP_JIT_IMAGE_BASE,
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 */
137
};
138
/**
139
* This structure is passed directly to the generated fragment shader.
140
*
141
* It contains the derived state.
142
*
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.
145
*
146
* Only use types with a clear size and padding here, in particular prefer the
147
* stdint.h types to the basic integer types.
148
*/
149
struct lp_jit_context
150
{
151
const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
152
int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
153
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];
157
158
float alpha_ref_value;
159
160
uint32_t stencil_ref_front, stencil_ref_back;
161
162
uint8_t *u8_blend_color;
163
float *f_blend_color;
164
165
struct lp_jit_viewport *viewports;
166
167
const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
168
int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
169
170
uint32_t sample_mask;
171
};
172
173
174
/**
175
* These enum values must match the position of the fields in the
176
* lp_jit_context struct above.
177
*/
178
enum {
179
LP_JIT_CTX_CONSTANTS = 0,
180
LP_JIT_CTX_NUM_CONSTANTS,
181
LP_JIT_CTX_TEXTURES,
182
LP_JIT_CTX_SAMPLERS,
183
LP_JIT_CTX_IMAGES,
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,
190
LP_JIT_CTX_SSBOS,
191
LP_JIT_CTX_NUM_SSBOS,
192
LP_JIT_CTX_SAMPLE_MASK,
193
LP_JIT_CTX_COUNT
194
};
195
196
197
#define lp_jit_context_constants(_gallivm, _ptr) \
198
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
199
200
#define lp_jit_context_num_constants(_gallivm, _ptr) \
201
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
202
203
#define lp_jit_context_textures(_gallivm, _ptr) \
204
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
205
206
#define lp_jit_context_samplers(_gallivm, _ptr) \
207
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
208
209
#define lp_jit_context_images(_gallivm, _ptr) \
210
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")
211
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")
214
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")
217
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")
220
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")
223
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")
226
227
#define lp_jit_context_viewports(_gallivm, _ptr) \
228
lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
229
230
#define lp_jit_context_ssbos(_gallivm, _ptr) \
231
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
232
233
#define lp_jit_context_num_ssbos(_gallivm, _ptr) \
234
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
235
236
#define lp_jit_context_sample_mask(_gallivm, _ptr) \
237
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLE_MASK, "sample_mask")
238
239
struct lp_jit_thread_data
240
{
241
struct lp_build_format_cache *cache;
242
uint64_t vis_counter;
243
uint64_t ps_invocations;
244
245
/*
246
* Non-interpolated rasterizer state passed through to the fragment shader.
247
*/
248
struct {
249
uint32_t viewport_index;
250
uint32_t view_index;
251
} raster_state;
252
};
253
254
255
enum {
256
LP_JIT_THREAD_DATA_CACHE = 0,
257
LP_JIT_THREAD_DATA_COUNTER,
258
LP_JIT_THREAD_DATA_INVOCATIONS,
259
LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX,
260
LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX,
261
LP_JIT_THREAD_DATA_COUNT
262
};
263
264
265
#define lp_jit_thread_data_cache(_gallivm, _ptr) \
266
lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
267
268
#define lp_jit_thread_data_counter(_gallivm, _ptr) \
269
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
270
271
#define lp_jit_thread_data_invocations(_gallivm, _ptr) \
272
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
273
274
#define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
275
lp_build_struct_get(_gallivm, _ptr, \
276
LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
277
"raster_state.viewport_index")
278
279
#define lp_jit_thread_data_raster_state_view_index(_gallivm, _ptr) \
280
lp_build_struct_get(_gallivm, _ptr, \
281
LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX, \
282
"raster_state.view_index")
283
284
/**
285
* typedef for fragment shader function
286
*
287
* @param context jit context
288
* @param x block start x
289
* @param y block start y
290
* @param facing is front facing
291
* @param a0 shader input a0
292
* @param dadx shader input dadx
293
* @param dady shader input dady
294
* @param color color buffer
295
* @param depth depth buffer
296
* @param mask mask of visible pixels in block (16-bits per sample)
297
* @param thread_data task thread data
298
* @param stride color buffer row stride in bytes
299
* @param depth_stride depth buffer row stride in bytes
300
*/
301
typedef void
302
(*lp_jit_frag_func)(const struct lp_jit_context *context,
303
uint32_t x,
304
uint32_t y,
305
uint32_t facing,
306
const void *a0,
307
const void *dadx,
308
const void *dady,
309
uint8_t **color,
310
uint8_t *depth,
311
uint64_t mask,
312
struct lp_jit_thread_data *thread_data,
313
unsigned *stride,
314
unsigned depth_stride,
315
unsigned *color_sample_stride,
316
unsigned depth_sample_stride);
317
318
319
struct lp_jit_cs_thread_data
320
{
321
struct lp_build_format_cache *cache;
322
void *shared;
323
};
324
325
enum {
326
LP_JIT_CS_THREAD_DATA_CACHE = 0,
327
LP_JIT_CS_THREAD_DATA_SHARED = 1,
328
LP_JIT_CS_THREAD_DATA_COUNT
329
};
330
331
332
#define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \
333
lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")
334
335
#define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \
336
lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")
337
338
struct lp_jit_cs_context
339
{
340
const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
341
int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
342
343
struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
344
struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
345
struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES];
346
347
const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
348
int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
349
350
void *kernel_args;
351
352
uint32_t shared_size;
353
};
354
355
/**
356
* These enum values must match the position of the fields in the
357
* lp_jit_context struct above.
358
*/
359
enum {
360
LP_JIT_CS_CTX_CONSTANTS = 0,
361
LP_JIT_CS_CTX_NUM_CONSTANTS,
362
LP_JIT_CS_CTX_TEXTURES, /* must match the LP_JIT_CTX_TEXTURES */
363
LP_JIT_CS_CTX_SAMPLERS,
364
LP_JIT_CS_CTX_IMAGES,
365
LP_JIT_CS_CTX_SSBOS,
366
LP_JIT_CS_CTX_NUM_SSBOS,
367
LP_JIT_CS_CTX_KERNEL_ARGS,
368
LP_JIT_CS_CTX_SHARED_SIZE,
369
LP_JIT_CS_CTX_COUNT
370
};
371
372
#define lp_jit_cs_context_constants(_gallivm, _ptr) \
373
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")
374
375
#define lp_jit_cs_context_num_constants(_gallivm, _ptr) \
376
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")
377
378
#define lp_jit_cs_context_textures(_gallivm, _ptr) \
379
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")
380
381
#define lp_jit_cs_context_samplers(_gallivm, _ptr) \
382
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")
383
384
#define lp_jit_cs_context_images(_gallivm, _ptr) \
385
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")
386
387
#define lp_jit_cs_context_ssbos(_gallivm, _ptr) \
388
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")
389
390
#define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \
391
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")
392
393
#define lp_jit_cs_context_shared_size(_gallivm, _ptr) \
394
lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")
395
396
#define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \
397
lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")
398
399
400
typedef void
401
(*lp_jit_cs_func)(const struct lp_jit_cs_context *context,
402
uint32_t x,
403
uint32_t y,
404
uint32_t z,
405
uint32_t grid_x,
406
uint32_t grid_y,
407
uint32_t grid_z,
408
uint32_t grid_size_x,
409
uint32_t grid_size_y,
410
uint32_t grid_size_z,
411
uint32_t work_dim,
412
struct lp_jit_cs_thread_data *thread_data);
413
414
void
415
lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
416
417
418
boolean
419
lp_jit_screen_init(struct llvmpipe_screen *screen);
420
421
422
void
423
lp_jit_init_types(struct lp_fragment_shader_variant *lp);
424
425
void
426
lp_jit_init_cs_types(struct lp_compute_shader_variant *lp);
427
#endif /* LP_JIT_H */
428
429