Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_context.h
4570 views
1
/*
2
* Copyright © 2017 Intel Corporation
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* on the rights to use, copy, modify, merge, publish, distribute, sub
8
* license, and/or sell copies of the Software, and to permit persons to whom
9
* the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
*/
23
#ifndef CROCUS_CONTEXT_H
24
#define CROCUS_CONTEXT_H
25
26
#include "pipe/p_context.h"
27
#include "pipe/p_state.h"
28
#include "util/u_debug.h"
29
#include "util/u_threaded_context.h"
30
#include "intel/blorp/blorp.h"
31
#include "intel/dev/intel_debug.h"
32
#include "intel/compiler/brw_compiler.h"
33
#include "crocus_batch.h"
34
#include "crocus_fence.h"
35
#include "crocus_resource.h"
36
#include "crocus_screen.h"
37
#include "util/u_blitter.h"
38
39
struct crocus_bo;
40
struct crocus_context;
41
struct blorp_batch;
42
struct blorp_params;
43
44
#define CROCUS_MAX_TEXTURE_BUFFER_SIZE (1 << 27)
45
#define CROCUS_MAX_TEXTURE_SAMPLERS 32
46
/* CROCUS_MAX_ABOS and CROCUS_MAX_SSBOS must be the same. */
47
#define CROCUS_MAX_ABOS 16
48
#define CROCUS_MAX_SSBOS 16
49
#define CROCUS_MAX_VIEWPORTS 16
50
#define CROCUS_MAX_CLIP_PLANES 8
51
52
enum crocus_param_domain {
53
BRW_PARAM_DOMAIN_BUILTIN = 0,
54
BRW_PARAM_DOMAIN_IMAGE,
55
};
56
57
enum {
58
DRI_CONF_BO_REUSE_DISABLED,
59
DRI_CONF_BO_REUSE_ALL
60
};
61
62
#define BRW_PARAM(domain, val) (BRW_PARAM_DOMAIN_##domain << 24 | (val))
63
#define BRW_PARAM_DOMAIN(param) ((uint32_t)(param) >> 24)
64
#define BRW_PARAM_VALUE(param) ((uint32_t)(param) & 0x00ffffff)
65
#define BRW_PARAM_IMAGE(idx, offset) BRW_PARAM(IMAGE, ((idx) << 8) | (offset))
66
#define BRW_PARAM_IMAGE_IDX(value) (BRW_PARAM_VALUE(value) >> 8)
67
#define BRW_PARAM_IMAGE_OFFSET(value)(BRW_PARAM_VALUE(value) & 0xf)
68
69
/**
70
* Dirty flags. When state changes, we flag some combination of these
71
* to indicate that particular GPU commands need to be re-emitted.
72
*
73
* Each bit typically corresponds to a single 3DSTATE_* command packet, but
74
* in rare cases they map to a group of related packets that need to be
75
* emitted together.
76
*
77
* See crocus_upload_render_state().
78
*/
79
#define CROCUS_DIRTY_COLOR_CALC_STATE (1ull << 0)
80
#define CROCUS_DIRTY_POLYGON_STIPPLE (1ull << 1)
81
#define CROCUS_DIRTY_CC_VIEWPORT (1ull << 2)
82
#define CROCUS_DIRTY_SF_CL_VIEWPORT (1ull << 3)
83
#define CROCUS_DIRTY_RASTER (1ull << 4)
84
#define CROCUS_DIRTY_CLIP (1ull << 5)
85
#define CROCUS_DIRTY_LINE_STIPPLE (1ull << 6)
86
#define CROCUS_DIRTY_VERTEX_ELEMENTS (1ull << 7)
87
#define CROCUS_DIRTY_VERTEX_BUFFERS (1ull << 8)
88
#define CROCUS_DIRTY_DRAWING_RECTANGLE (1ull << 9)
89
#define CROCUS_DIRTY_GEN6_URB (1ull << 10)
90
#define CROCUS_DIRTY_DEPTH_BUFFER (1ull << 11)
91
#define CROCUS_DIRTY_WM (1ull << 12)
92
#define CROCUS_DIRTY_SO_DECL_LIST (1ull << 13)
93
#define CROCUS_DIRTY_STREAMOUT (1ull << 14)
94
#define CROCUS_DIRTY_GEN4_CONSTANT_COLOR (1ull << 15)
95
#define CROCUS_DIRTY_GEN4_CURBE (1ull << 16)
96
#define CROCUS_DIRTY_GEN4_URB_FENCE (1ull << 17)
97
#define CROCUS_DIRTY_GEN5_PIPELINED_POINTERS (1ull << 18)
98
#define CROCUS_DIRTY_GEN5_BINDING_TABLE_POINTERS (1ull << 19)
99
#define CROCUS_DIRTY_GEN6_BLEND_STATE (1ull << 20)
100
#define CROCUS_DIRTY_GEN6_SCISSOR_RECT (1ull << 21)
101
#define CROCUS_DIRTY_GEN6_WM_DEPTH_STENCIL (1ull << 22)
102
#define CROCUS_DIRTY_GEN6_MULTISAMPLE (1ull << 23)
103
#define CROCUS_DIRTY_GEN6_SAMPLE_MASK (1ull << 24)
104
#define CROCUS_DIRTY_GEN7_SBE (1ull << 25)
105
#define CROCUS_DIRTY_GEN7_L3_CONFIG (1ull << 26)
106
#define CROCUS_DIRTY_GEN7_SO_BUFFERS (1ull << 27)
107
#define CROCUS_DIRTY_GEN75_VF (1ull << 28)
108
#define CROCUS_DIRTY_RENDER_RESOLVES_AND_FLUSHES (1ull << 29)
109
#define CROCUS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES (1ull << 30)
110
#define CROCUS_DIRTY_VF_STATISTICS (1ull << 31)
111
#define CROCUS_DIRTY_GEN4_CLIP_PROG (1ull << 32)
112
#define CROCUS_DIRTY_GEN4_SF_PROG (1ull << 33)
113
#define CROCUS_DIRTY_GEN4_FF_GS_PROG (1ull << 34)
114
#define CROCUS_DIRTY_GEN6_SAMPLER_STATE_POINTERS (1ull << 35)
115
#define CROCUS_DIRTY_GEN6_SVBI (1ull << 36)
116
#define CROCUS_DIRTY_GEN8_VF_TOPOLOGY (1ull << 37)
117
#define CROCUS_DIRTY_GEN8_PMA_FIX (1ull << 38)
118
#define CROCUS_DIRTY_GEN8_VF_SGVS (1ull << 39)
119
#define CROCUS_DIRTY_GEN8_PS_BLEND (1ull << 40)
120
121
#define CROCUS_ALL_DIRTY_FOR_COMPUTE (CROCUS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES)
122
123
#define CROCUS_ALL_DIRTY_FOR_RENDER (~CROCUS_ALL_DIRTY_FOR_COMPUTE)
124
125
/**
126
* Per-stage dirty flags. When state changes, we flag some combination of
127
* these to indicate that particular GPU commands need to be re-emitted.
128
* Unlike the IRIS_DIRTY_* flags these are shader stage-specific and can be
129
* indexed by shifting the mask by the shader stage index.
130
*
131
* See crocus_upload_render_state().
132
*/
133
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_VS (1ull << 0)
134
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_TCS (1ull << 1)
135
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_TES (1ull << 2)
136
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_GS (1ull << 3)
137
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_PS (1ull << 4)
138
#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_CS (1ull << 5)
139
#define CROCUS_STAGE_DIRTY_UNCOMPILED_VS (1ull << 6)
140
#define CROCUS_STAGE_DIRTY_UNCOMPILED_TCS (1ull << 7)
141
#define CROCUS_STAGE_DIRTY_UNCOMPILED_TES (1ull << 8)
142
#define CROCUS_STAGE_DIRTY_UNCOMPILED_GS (1ull << 9)
143
#define CROCUS_STAGE_DIRTY_UNCOMPILED_FS (1ull << 10)
144
#define CROCUS_STAGE_DIRTY_UNCOMPILED_CS (1ull << 11)
145
#define CROCUS_STAGE_DIRTY_VS (1ull << 12)
146
#define CROCUS_STAGE_DIRTY_TCS (1ull << 13)
147
#define CROCUS_STAGE_DIRTY_TES (1ull << 14)
148
#define CROCUS_STAGE_DIRTY_GS (1ull << 15)
149
#define CROCUS_STAGE_DIRTY_FS (1ull << 16)
150
#define CROCUS_STAGE_DIRTY_CS (1ull << 17)
151
#define CROCUS_SHIFT_FOR_STAGE_DIRTY_CONSTANTS 18
152
#define CROCUS_STAGE_DIRTY_CONSTANTS_VS (1ull << 18)
153
#define CROCUS_STAGE_DIRTY_CONSTANTS_TCS (1ull << 19)
154
#define CROCUS_STAGE_DIRTY_CONSTANTS_TES (1ull << 20)
155
#define CROCUS_STAGE_DIRTY_CONSTANTS_GS (1ull << 21)
156
#define CROCUS_STAGE_DIRTY_CONSTANTS_FS (1ull << 22)
157
#define CROCUS_STAGE_DIRTY_CONSTANTS_CS (1ull << 23)
158
#define CROCUS_STAGE_DIRTY_BINDINGS_VS (1ull << 24)
159
#define CROCUS_STAGE_DIRTY_BINDINGS_TCS (1ull << 25)
160
#define CROCUS_STAGE_DIRTY_BINDINGS_TES (1ull << 26)
161
#define CROCUS_STAGE_DIRTY_BINDINGS_GS (1ull << 27)
162
#define CROCUS_STAGE_DIRTY_BINDINGS_FS (1ull << 28)
163
#define CROCUS_STAGE_DIRTY_BINDINGS_CS (1ull << 29)
164
165
#define CROCUS_ALL_STAGE_DIRTY_FOR_COMPUTE (CROCUS_STAGE_DIRTY_CS | \
166
CROCUS_STAGE_DIRTY_SAMPLER_STATES_CS | \
167
CROCUS_STAGE_DIRTY_UNCOMPILED_CS | \
168
CROCUS_STAGE_DIRTY_CONSTANTS_CS | \
169
CROCUS_STAGE_DIRTY_BINDINGS_CS)
170
171
#define CROCUS_ALL_STAGE_DIRTY_FOR_RENDER (~CROCUS_ALL_STAGE_DIRTY_FOR_COMPUTE)
172
173
#define CROCUS_ALL_STAGE_DIRTY_BINDINGS (CROCUS_STAGE_DIRTY_BINDINGS_VS | \
174
CROCUS_STAGE_DIRTY_BINDINGS_TCS | \
175
CROCUS_STAGE_DIRTY_BINDINGS_TES | \
176
CROCUS_STAGE_DIRTY_BINDINGS_GS | \
177
CROCUS_STAGE_DIRTY_BINDINGS_FS | \
178
CROCUS_STAGE_DIRTY_BINDINGS_CS)
179
180
#define CROCUS_RENDER_STAGE_DIRTY_CONSTANTS (CROCUS_STAGE_DIRTY_CONSTANTS_VS | \
181
CROCUS_STAGE_DIRTY_CONSTANTS_TCS | \
182
CROCUS_STAGE_DIRTY_CONSTANTS_TES | \
183
CROCUS_STAGE_DIRTY_CONSTANTS_GS | \
184
CROCUS_STAGE_DIRTY_CONSTANTS_FS)
185
186
/**
187
* Non-orthogonal state (NOS) dependency flags.
188
*
189
* Shader programs may depend on non-orthogonal state. These flags are
190
* used to indicate that a shader's key depends on the state provided by
191
* a certain Gallium CSO. Changing any CSOs marked as a dependency will
192
* cause the driver to re-compute the shader key, possibly triggering a
193
* shader recompile.
194
*/
195
enum crocus_nos_dep {
196
CROCUS_NOS_FRAMEBUFFER,
197
CROCUS_NOS_DEPTH_STENCIL_ALPHA,
198
CROCUS_NOS_RASTERIZER,
199
CROCUS_NOS_BLEND,
200
CROCUS_NOS_LAST_VUE_MAP,
201
CROCUS_NOS_TEXTURES,
202
CROCUS_NOS_VERTEX_ELEMENTS,
203
CROCUS_NOS_COUNT,
204
};
205
206
struct crocus_depth_stencil_alpha_state;
207
208
/**
209
* Cache IDs for the in-memory program cache (ice->shaders.cache).
210
*/
211
enum crocus_program_cache_id {
212
CROCUS_CACHE_VS = MESA_SHADER_VERTEX,
213
CROCUS_CACHE_TCS = MESA_SHADER_TESS_CTRL,
214
CROCUS_CACHE_TES = MESA_SHADER_TESS_EVAL,
215
CROCUS_CACHE_GS = MESA_SHADER_GEOMETRY,
216
CROCUS_CACHE_FS = MESA_SHADER_FRAGMENT,
217
CROCUS_CACHE_CS = MESA_SHADER_COMPUTE,
218
CROCUS_CACHE_BLORP,
219
CROCUS_CACHE_SF,
220
CROCUS_CACHE_CLIP,
221
CROCUS_CACHE_FF_GS,
222
};
223
224
/** @{
225
*
226
* Defines for PIPE_CONTROL operations, which trigger cache flushes,
227
* synchronization, pipelined memory writes, and so on.
228
*
229
* The bits here are not the actual hardware values. The actual fields
230
* move between various generations, so we just have flags for each
231
* potential operation, and use genxml to encode the actual packet.
232
*/
233
enum pipe_control_flags
234
{
235
PIPE_CONTROL_FLUSH_LLC = (1 << 1),
236
PIPE_CONTROL_LRI_POST_SYNC_OP = (1 << 2),
237
PIPE_CONTROL_STORE_DATA_INDEX = (1 << 3),
238
PIPE_CONTROL_CS_STALL = (1 << 4),
239
PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET = (1 << 5),
240
PIPE_CONTROL_SYNC_GFDT = (1 << 6),
241
PIPE_CONTROL_TLB_INVALIDATE = (1 << 7),
242
PIPE_CONTROL_MEDIA_STATE_CLEAR = (1 << 8),
243
PIPE_CONTROL_WRITE_IMMEDIATE = (1 << 9),
244
PIPE_CONTROL_WRITE_DEPTH_COUNT = (1 << 10),
245
PIPE_CONTROL_WRITE_TIMESTAMP = (1 << 11),
246
PIPE_CONTROL_DEPTH_STALL = (1 << 12),
247
PIPE_CONTROL_RENDER_TARGET_FLUSH = (1 << 13),
248
PIPE_CONTROL_INSTRUCTION_INVALIDATE = (1 << 14),
249
PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE = (1 << 15),
250
PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE = (1 << 16),
251
PIPE_CONTROL_NOTIFY_ENABLE = (1 << 17),
252
PIPE_CONTROL_FLUSH_ENABLE = (1 << 18),
253
PIPE_CONTROL_DATA_CACHE_FLUSH = (1 << 19),
254
PIPE_CONTROL_VF_CACHE_INVALIDATE = (1 << 20),
255
PIPE_CONTROL_CONST_CACHE_INVALIDATE = (1 << 21),
256
PIPE_CONTROL_STATE_CACHE_INVALIDATE = (1 << 22),
257
PIPE_CONTROL_STALL_AT_SCOREBOARD = (1 << 23),
258
PIPE_CONTROL_DEPTH_CACHE_FLUSH = (1 << 24),
259
PIPE_CONTROL_TILE_CACHE_FLUSH = (1 << 25),
260
};
261
262
#define PIPE_CONTROL_CACHE_FLUSH_BITS \
263
(PIPE_CONTROL_DEPTH_CACHE_FLUSH | \
264
PIPE_CONTROL_DATA_CACHE_FLUSH | \
265
PIPE_CONTROL_RENDER_TARGET_FLUSH)
266
267
#define PIPE_CONTROL_CACHE_INVALIDATE_BITS \
268
(PIPE_CONTROL_STATE_CACHE_INVALIDATE | \
269
PIPE_CONTROL_CONST_CACHE_INVALIDATE | \
270
PIPE_CONTROL_VF_CACHE_INVALIDATE | \
271
PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \
272
PIPE_CONTROL_INSTRUCTION_INVALIDATE)
273
274
enum crocus_predicate_state {
275
/* The first two states are used if we can determine whether to draw
276
* without having to look at the values in the query object buffer. This
277
* will happen if there is no conditional render in progress, if the query
278
* object is already completed or if something else has already added
279
* samples to the preliminary result.
280
*/
281
CROCUS_PREDICATE_STATE_RENDER,
282
CROCUS_PREDICATE_STATE_DONT_RENDER,
283
284
/* In this case whether to draw or not depends on the result of an
285
* MI_PREDICATE command so the predicate enable bit needs to be checked.
286
*/
287
CROCUS_PREDICATE_STATE_USE_BIT,
288
/* In this case, either MI_PREDICATE doesn't exist or we lack the
289
* necessary kernel features to use it. Stall for the query result.
290
*/
291
CROCUS_PREDICATE_STATE_STALL_FOR_QUERY,
292
};
293
294
/** @} */
295
296
/**
297
* An uncompiled, API-facing shader. This is the Gallium CSO for shaders.
298
* It primarily contains the NIR for the shader.
299
*
300
* Each API-facing shader can be compiled into multiple shader variants,
301
* based on non-orthogonal state dependencies, recorded in the shader key.
302
*
303
* See crocus_compiled_shader, which represents a compiled shader variant.
304
*/
305
struct crocus_uncompiled_shader {
306
struct nir_shader *nir;
307
308
struct pipe_stream_output_info stream_output;
309
310
/* A SHA1 of the serialized NIR for the disk cache. */
311
unsigned char nir_sha1[20];
312
313
unsigned program_id;
314
315
/** Bitfield of (1 << CROCUS_NOS_*) flags. */
316
unsigned nos;
317
318
/** Have any shader variants been compiled yet? */
319
bool compiled_once;
320
321
/** Should we use ALT mode for math? Useful for ARB programs. */
322
bool use_alt_mode;
323
324
bool needs_edge_flag;
325
326
/** Constant data scraped from the shader by nir_opt_large_constants */
327
struct pipe_resource *const_data;
328
329
/** Surface state for const_data */
330
struct crocus_state_ref const_data_state;
331
};
332
333
enum crocus_surface_group {
334
CROCUS_SURFACE_GROUP_RENDER_TARGET,
335
CROCUS_SURFACE_GROUP_RENDER_TARGET_READ,
336
CROCUS_SURFACE_GROUP_SOL,
337
CROCUS_SURFACE_GROUP_CS_WORK_GROUPS,
338
CROCUS_SURFACE_GROUP_TEXTURE,
339
CROCUS_SURFACE_GROUP_TEXTURE_GATHER,
340
CROCUS_SURFACE_GROUP_IMAGE,
341
CROCUS_SURFACE_GROUP_UBO,
342
CROCUS_SURFACE_GROUP_SSBO,
343
344
CROCUS_SURFACE_GROUP_COUNT,
345
};
346
347
enum {
348
/* Invalid value for a binding table index. */
349
CROCUS_SURFACE_NOT_USED = 0xa0a0a0a0,
350
};
351
352
struct crocus_binding_table {
353
uint32_t size_bytes;
354
355
/** Number of surfaces in each group, before compacting. */
356
uint32_t sizes[CROCUS_SURFACE_GROUP_COUNT];
357
358
/** Initial offset of each group. */
359
uint32_t offsets[CROCUS_SURFACE_GROUP_COUNT];
360
361
/** Mask of surfaces used in each group. */
362
uint64_t used_mask[CROCUS_SURFACE_GROUP_COUNT];
363
};
364
365
/**
366
* A compiled shader variant, containing a pointer to the GPU assembly,
367
* as well as program data and other packets needed by state upload.
368
*
369
* There can be several crocus_compiled_shader variants per API-level shader
370
* (crocus_uncompiled_shader), due to state-based recompiles (brw_*_prog_key).
371
*/
372
struct crocus_compiled_shader {
373
/** Reference to the uploaded assembly. */
374
uint32_t offset;
375
376
/* asm size in map */
377
uint32_t map_size;
378
379
/** The program data (owned by the program cache hash table) */
380
struct brw_stage_prog_data *prog_data;
381
uint32_t prog_data_size;
382
383
/** A list of system values to be uploaded as uniforms. */
384
enum brw_param_builtin *system_values;
385
unsigned num_system_values;
386
387
/** Number of constbufs expected by the shader. */
388
unsigned num_cbufs;
389
390
/**
391
* Derived 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets
392
* (the VUE-based information for transform feedback outputs).
393
*/
394
uint32_t *streamout;
395
396
struct crocus_binding_table bt;
397
398
uint32_t bind_bo_offset;
399
uint32_t surf_offset[128];//TODO
400
};
401
402
/**
403
* API context state that is replicated per shader stage.
404
*/
405
struct crocus_shader_state {
406
/** Uniform Buffers */
407
struct pipe_constant_buffer constbufs[PIPE_MAX_CONSTANT_BUFFERS];
408
409
bool sysvals_need_upload;
410
411
/** Shader Storage Buffers */
412
struct pipe_shader_buffer ssbo[PIPE_MAX_SHADER_BUFFERS];
413
414
/** Shader Storage Images (image load store) */
415
struct crocus_image_view image[PIPE_MAX_SHADER_IMAGES];
416
417
struct crocus_sampler_state *samplers[CROCUS_MAX_TEXTURE_SAMPLERS];
418
struct crocus_sampler_view *textures[CROCUS_MAX_TEXTURE_SAMPLERS];
419
420
/** Bitfield of which constant buffers are bound (non-null). */
421
uint32_t bound_cbufs;
422
423
/** Bitfield of which image views are bound (non-null). */
424
uint32_t bound_image_views;
425
426
/** Bitfield of which sampler views are bound (non-null). */
427
uint32_t bound_sampler_views;
428
429
/** Bitfield of which shader storage buffers are bound (non-null). */
430
uint32_t bound_ssbos;
431
432
/** Bitfield of which shader storage buffers are writable. */
433
uint32_t writable_ssbos;
434
435
uint32_t sampler_offset;
436
};
437
438
/**
439
* The API context (derived from pipe_context).
440
*
441
* Most driver state is tracked here.
442
*/
443
struct crocus_context {
444
struct pipe_context ctx;
445
struct threaded_context *thrctx;
446
447
/** A debug callback for KHR_debug output. */
448
struct pipe_debug_callback dbg;
449
450
/** A device reset status callback for notifying that the GPU is hosed. */
451
struct pipe_device_reset_callback reset;
452
453
/** Slab allocator for crocus_transfer_map objects. */
454
struct slab_child_pool transfer_pool;
455
456
/** Slab allocator for threaded_context's crocus_transfer_map objects */
457
struct slab_child_pool transfer_pool_unsync;
458
459
struct blorp_context blorp;
460
461
int batch_count;
462
struct crocus_batch batches[CROCUS_BATCH_COUNT];
463
464
struct u_upload_mgr *query_buffer_uploader;
465
466
struct blitter_context *blitter;
467
468
struct {
469
struct {
470
/**
471
* Either the value of BaseVertex for indexed draw calls or the value
472
* of the argument <first> for non-indexed draw calls.
473
*/
474
int firstvertex;
475
int baseinstance;
476
} params;
477
478
/**
479
* Are the above values the ones stored in the draw_params buffer?
480
* If so, we can compare them against new values to see if anything
481
* changed. If not, we need to assume they changed.
482
*/
483
bool params_valid;
484
485
/**
486
* Resource and offset that stores draw_parameters from the indirect
487
* buffer or to the buffer that stures the previous values for non
488
* indirect draws.
489
*/
490
struct crocus_state_ref draw_params;
491
492
struct {
493
/**
494
* The value of DrawID. This always comes in from it's own vertex
495
* buffer since it's not part of the indirect draw parameters.
496
*/
497
int drawid;
498
499
/**
500
* Stores if an indexed or non-indexed draw (~0/0). Useful to
501
* calculate BaseVertex as an AND of firstvertex and is_indexed_draw.
502
*/
503
int is_indexed_draw;
504
} derived_params;
505
506
/**
507
* Resource and offset used for GL_ARB_shader_draw_parameters which
508
* contains parameters that are not present in the indirect buffer as
509
* drawid and is_indexed_draw. They will go in their own vertex element.
510
*/
511
struct crocus_state_ref derived_draw_params;
512
} draw;
513
514
struct {
515
struct crocus_uncompiled_shader *uncompiled[MESA_SHADER_STAGES];
516
struct crocus_compiled_shader *prog[MESA_SHADER_STAGES];
517
struct brw_vue_map *last_vue_map;
518
519
struct crocus_bo *cache_bo;
520
uint32_t cache_next_offset;
521
void *cache_bo_map;
522
struct hash_table *cache;
523
524
unsigned urb_size;
525
526
/* gen 4/5 clip/sf progs */
527
struct crocus_compiled_shader *clip_prog;
528
struct crocus_compiled_shader *sf_prog;
529
/* gen4/5 prims, gen6 streamout */
530
struct crocus_compiled_shader *ff_gs_prog;
531
uint32_t clip_offset;
532
uint32_t sf_offset;
533
uint32_t wm_offset;
534
uint32_t vs_offset;
535
uint32_t gs_offset;
536
uint32_t cc_offset;
537
538
/** Is a GS or TES outputting points or lines? */
539
bool output_topology_is_points_or_lines;
540
541
/* Track last VS URB entry size */
542
unsigned last_vs_entry_size;
543
544
/**
545
* Scratch buffers for various sizes and stages.
546
*
547
* Indexed by the "Per-Thread Scratch Space" field's 4-bit encoding,
548
* and shader stage.
549
*/
550
struct crocus_bo *scratch_bos[1 << 4][MESA_SHADER_STAGES];
551
} shaders;
552
553
struct {
554
struct crocus_query *query;
555
bool condition;
556
enum pipe_render_cond_flag mode;
557
} condition;
558
559
struct intel_perf_context *perf_ctx;
560
561
struct {
562
uint64_t dirty;
563
uint64_t stage_dirty;
564
uint64_t stage_dirty_for_nos[CROCUS_NOS_COUNT];
565
566
unsigned num_viewports;
567
unsigned sample_mask;
568
struct crocus_blend_state *cso_blend;
569
struct crocus_rasterizer_state *cso_rast;
570
struct crocus_depth_stencil_alpha_state *cso_zsa;
571
struct crocus_vertex_element_state *cso_vertex_elements;
572
struct pipe_blend_color blend_color;
573
struct pipe_poly_stipple poly_stipple;
574
struct pipe_viewport_state viewports[CROCUS_MAX_VIEWPORTS];
575
struct pipe_scissor_state scissors[CROCUS_MAX_VIEWPORTS];
576
struct pipe_stencil_ref stencil_ref;
577
struct pipe_framebuffer_state framebuffer;
578
struct pipe_clip_state clip_planes;
579
580
float default_outer_level[4];
581
float default_inner_level[2];
582
583
/** Bitfield of which vertex buffers are bound (non-null). */
584
uint32_t bound_vertex_buffers;
585
struct pipe_vertex_buffer vertex_buffers[16];
586
uint32_t vb_end[16];
587
588
bool primitive_restart;
589
unsigned cut_index;
590
enum pipe_prim_type prim_mode:8;
591
bool prim_is_points_or_lines;
592
uint8_t vertices_per_patch;
593
594
bool window_space_position;
595
596
/** The last compute group size */
597
uint32_t last_block[3];
598
599
/** The last compute grid size */
600
uint32_t last_grid[3];
601
/** Reference to the BO containing the compute grid size */
602
struct crocus_state_ref grid_size;
603
604
/**
605
* Array of aux usages for drawing, altered to account for any
606
* self-dependencies from resources bound for sampling and rendering.
607
*/
608
enum isl_aux_usage draw_aux_usage[BRW_MAX_DRAW_BUFFERS];
609
610
/** Aux usage of the fb's depth buffer (which may or may not exist). */
611
enum isl_aux_usage hiz_usage;
612
613
/** Bitfield of whether color blending is enabled for RT[i] */
614
uint8_t blend_enables;
615
616
/** Are depth writes enabled? (Depth buffer may or may not exist.) */
617
bool depth_writes_enabled;
618
619
/** Are stencil writes enabled? (Stencil buffer may or may not exist.) */
620
bool stencil_writes_enabled;
621
622
/** GenX-specific current state */
623
struct crocus_genx_state *genx;
624
625
struct crocus_shader_state shaders[MESA_SHADER_STAGES];
626
627
/** Do vertex shader uses shader draw parameters ? */
628
bool vs_uses_draw_params;
629
bool vs_uses_derived_draw_params;
630
bool vs_needs_sgvs_element;
631
bool vs_uses_vertexid;
632
bool vs_uses_instanceid;
633
634
/** Do vertex shader uses edge flag ? */
635
bool vs_needs_edge_flag;
636
637
struct pipe_stream_output_target *so_target[PIPE_MAX_SO_BUFFERS];
638
bool streamout_active;
639
int so_targets;
640
641
bool statistics_counters_enabled;
642
643
/** Current conditional rendering mode */
644
enum crocus_predicate_state predicate;
645
bool predicate_supported;
646
647
/**
648
* Query BO with a MI_PREDICATE_RESULT snapshot calculated on the
649
* render context that needs to be uploaded to the compute context.
650
*/
651
struct crocus_bo *compute_predicate;
652
653
/** Is a PIPE_QUERY_PRIMITIVES_GENERATED query active? */
654
bool prims_generated_query_active;
655
656
/** 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets */
657
uint32_t *streamout;
658
659
/**
660
* Resources containing streamed state which our render context
661
* currently points to. Used to re-add these to the validation
662
* list when we start a new batch and haven't resubmitted commands.
663
*/
664
struct {
665
struct pipe_resource *res;
666
uint32_t offset;
667
uint32_t size;
668
uint32_t index_size;
669
bool prim_restart;
670
} index_buffer;
671
672
uint32_t sf_vp_address;
673
uint32_t clip_vp_address;
674
uint32_t cc_vp_address;
675
676
uint32_t stats_wm;
677
float global_depth_offset_clamp;
678
679
uint32_t last_xfb_verts_per_prim;
680
uint64_t svbi;
681
} state;
682
683
/* BRW_NEW_URB_ALLOCATIONS:
684
*/
685
struct {
686
uint32_t vsize; /* vertex size plus header in urb registers */
687
uint32_t gsize; /* GS output size in urb registers */
688
uint32_t hsize; /* Tessellation control output size in urb registers */
689
uint32_t dsize; /* Tessellation evaluation output size in urb registers */
690
uint32_t csize; /* constant buffer size in urb registers */
691
uint32_t sfsize; /* setup data size in urb registers */
692
693
bool constrained;
694
695
uint32_t nr_vs_entries;
696
uint32_t nr_hs_entries;
697
uint32_t nr_ds_entries;
698
uint32_t nr_gs_entries;
699
uint32_t nr_clip_entries;
700
uint32_t nr_sf_entries;
701
uint32_t nr_cs_entries;
702
703
uint32_t vs_start;
704
uint32_t hs_start;
705
uint32_t ds_start;
706
uint32_t gs_start;
707
uint32_t clip_start;
708
uint32_t sf_start;
709
uint32_t cs_start;
710
/**
711
* URB size in the current configuration. The units this is expressed
712
* in are somewhat inconsistent, see intel_device_info::urb::size.
713
*
714
* FINISHME: Represent the URB size consistently in KB on all platforms.
715
*/
716
uint32_t size;
717
718
/* True if the most recently sent _3DSTATE_URB message allocated
719
* URB space for the GS.
720
*/
721
bool gs_present;
722
723
/* True if the most recently sent _3DSTATE_URB message allocated
724
* URB space for the HS and DS.
725
*/
726
bool tess_present;
727
} urb;
728
729
/* GEN4/5 curbe */
730
struct {
731
unsigned wm_start;
732
unsigned wm_size;
733
unsigned clip_start;
734
unsigned clip_size;
735
unsigned vs_start;
736
unsigned vs_size;
737
unsigned total_size;
738
739
struct crocus_resource *curbe_res;
740
unsigned curbe_offset;
741
} curbe;
742
743
/**
744
* A buffer containing a marker + description of the driver. This buffer is
745
* added to all execbufs syscalls so that we can identify the driver that
746
* generated a hang by looking at the content of the buffer in the error
747
* state. It is also used for hardware workarounds that require scratch
748
* writes or reads from some unimportant memory. To avoid overriding the
749
* debug data, use the workaround_address field for workarounds.
750
*/
751
struct crocus_bo *workaround_bo;
752
unsigned workaround_offset;
753
};
754
755
#define perf_debug(dbg, ...) do { \
756
if (INTEL_DEBUG & DEBUG_PERF) \
757
dbg_printf(__VA_ARGS__); \
758
if (unlikely(dbg)) \
759
pipe_debug_message(dbg, PERF_INFO, __VA_ARGS__); \
760
} while(0)
761
762
763
struct pipe_context *
764
crocus_create_context(struct pipe_screen *screen, void *priv, unsigned flags);
765
766
void crocus_lost_context_state(struct crocus_batch *batch);
767
768
void crocus_init_blit_functions(struct pipe_context *ctx);
769
void crocus_init_clear_functions(struct pipe_context *ctx);
770
void crocus_init_program_functions(struct pipe_context *ctx);
771
void crocus_init_resource_functions(struct pipe_context *ctx);
772
bool crocus_update_compiled_shaders(struct crocus_context *ice);
773
void crocus_update_compiled_compute_shader(struct crocus_context *ice);
774
void crocus_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,
775
unsigned threads, uint32_t *dst);
776
777
778
/* crocus_blit.c */
779
enum crocus_blitter_op
780
{
781
CROCUS_SAVE_TEXTURES = 1,
782
CROCUS_SAVE_FRAMEBUFFER = 2,
783
CROCUS_SAVE_FRAGMENT_STATE = 4,
784
CROCUS_DISABLE_RENDER_COND = 8,
785
};
786
void crocus_blitter_begin(struct crocus_context *ice, enum crocus_blitter_op op, bool render_cond);
787
788
void crocus_blorp_surf_for_resource(struct crocus_vtable *vtbl,
789
struct isl_device *isl_dev,
790
struct blorp_surf *surf,
791
struct pipe_resource *p_res,
792
enum isl_aux_usage aux_usage,
793
unsigned level,
794
bool is_render_target);
795
void crocus_copy_region(struct blorp_context *blorp,
796
struct crocus_batch *batch,
797
struct pipe_resource *dst,
798
unsigned dst_level,
799
unsigned dstx, unsigned dsty, unsigned dstz,
800
struct pipe_resource *src,
801
unsigned src_level,
802
const struct pipe_box *src_box);
803
804
/* crocus_draw.c */
805
void crocus_draw_vbo(struct pipe_context *ctx,
806
const struct pipe_draw_info *info,
807
unsigned drawid_offset,
808
const struct pipe_draw_indirect_info *indirect,
809
const struct pipe_draw_start_count_bias *draws,
810
unsigned num_draws);
811
void crocus_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
812
813
/* crocus_pipe_control.c */
814
815
void crocus_emit_pipe_control_flush(struct crocus_batch *batch,
816
const char *reason, uint32_t flags);
817
void crocus_emit_pipe_control_write(struct crocus_batch *batch,
818
const char *reason, uint32_t flags,
819
struct crocus_bo *bo, uint32_t offset,
820
uint64_t imm);
821
void crocus_emit_mi_flush(struct crocus_batch *batch);
822
void crocus_emit_depth_stall_flushes(struct crocus_batch *batch);
823
void crocus_emit_post_sync_nonzero_flush(struct crocus_batch *batch);
824
void crocus_emit_end_of_pipe_sync(struct crocus_batch *batch,
825
const char *reason, uint32_t flags);
826
void crocus_flush_all_caches(struct crocus_batch *batch);
827
828
#define crocus_handle_always_flush_cache(batch) \
829
if (unlikely(batch->screen->driconf.always_flush_cache)) \
830
crocus_flush_all_caches(batch);
831
832
void crocus_init_flush_functions(struct pipe_context *ctx);
833
834
/* crocus_program.c */
835
const struct shader_info *crocus_get_shader_info(const struct crocus_context *ice,
836
gl_shader_stage stage);
837
struct crocus_bo *crocus_get_scratch_space(struct crocus_context *ice,
838
unsigned per_thread_scratch,
839
gl_shader_stage stage);
840
/**
841
* Map a <group, index> pair to a binding table index.
842
*
843
* For example: <UBO, 5> => binding table index 12
844
*/
845
static inline uint32_t crocus_group_index_to_bti(const struct crocus_binding_table *bt,
846
enum crocus_surface_group group,
847
uint32_t index)
848
{
849
assert(index < bt->sizes[group]);
850
uint64_t mask = bt->used_mask[group];
851
uint64_t bit = 1ull << index;
852
if (bit & mask) {
853
return bt->offsets[group] + util_bitcount64((bit - 1) & mask);
854
} else {
855
return CROCUS_SURFACE_NOT_USED;
856
}
857
}
858
859
/**
860
* Map a binding table index back to a <group, index> pair.
861
*
862
* For example: binding table index 12 => <UBO, 5>
863
*/
864
static inline uint32_t
865
crocus_bti_to_group_index(const struct crocus_binding_table *bt,
866
enum crocus_surface_group group, uint32_t bti)
867
{
868
uint64_t used_mask = bt->used_mask[group];
869
assert(bti >= bt->offsets[group]);
870
871
uint32_t c = bti - bt->offsets[group];
872
while (used_mask) {
873
int i = u_bit_scan64(&used_mask);
874
if (c == 0)
875
return i;
876
c--;
877
}
878
879
return CROCUS_SURFACE_NOT_USED;
880
}
881
882
883
/* crocus_disk_cache.c */
884
885
void crocus_disk_cache_store(struct disk_cache *cache,
886
const struct crocus_uncompiled_shader *ish,
887
const struct crocus_compiled_shader *shader,
888
void *map,
889
const void *prog_key,
890
uint32_t prog_key_size);
891
struct crocus_compiled_shader *
892
crocus_disk_cache_retrieve(struct crocus_context *ice,
893
const struct crocus_uncompiled_shader *ish,
894
const void *prog_key,
895
uint32_t prog_key_size);
896
897
/* crocus_program_cache.c */
898
899
void crocus_init_program_cache(struct crocus_context *ice);
900
void crocus_destroy_program_cache(struct crocus_context *ice);
901
void crocus_print_program_cache(struct crocus_context *ice);
902
struct crocus_compiled_shader *crocus_find_cached_shader(struct crocus_context *ice,
903
enum crocus_program_cache_id,
904
uint32_t key_size,
905
const void *key);
906
struct crocus_compiled_shader *crocus_upload_shader(struct crocus_context *ice,
907
enum crocus_program_cache_id,
908
uint32_t key_size,
909
const void *key,
910
const void *assembly,
911
uint32_t asm_size,
912
struct brw_stage_prog_data *,
913
uint32_t prog_data_size,
914
uint32_t *streamout,
915
enum brw_param_builtin *sysv,
916
unsigned num_system_values,
917
unsigned num_cbufs,
918
const struct crocus_binding_table *bt);
919
const void *crocus_find_previous_compile(const struct crocus_context *ice,
920
enum crocus_program_cache_id cache_id,
921
unsigned program_string_id);
922
bool crocus_blorp_lookup_shader(struct blorp_batch *blorp_batch,
923
const void *key,
924
uint32_t key_size,
925
uint32_t *kernel_out,
926
void *prog_data_out);
927
bool crocus_blorp_upload_shader(struct blorp_batch *blorp_batch,
928
uint32_t stage,
929
const void *key, uint32_t key_size,
930
const void *kernel, uint32_t kernel_size,
931
const struct brw_stage_prog_data *prog_data,
932
uint32_t prog_data_size,
933
uint32_t *kernel_out,
934
void *prog_data_out);
935
936
/* crocus_resolve.c */
937
938
void crocus_predraw_resolve_inputs(struct crocus_context *ice,
939
struct crocus_batch *batch,
940
bool *draw_aux_buffer_disabled,
941
gl_shader_stage stage,
942
bool consider_framebuffer);
943
void crocus_predraw_resolve_framebuffer(struct crocus_context *ice,
944
struct crocus_batch *batch,
945
bool *draw_aux_buffer_disabled);
946
void crocus_postdraw_update_resolve_tracking(struct crocus_context *ice,
947
struct crocus_batch *batch);
948
void crocus_cache_sets_clear(struct crocus_batch *batch);
949
void crocus_flush_depth_and_render_caches(struct crocus_batch *batch);
950
void crocus_cache_flush_for_read(struct crocus_batch *batch, struct crocus_bo *bo);
951
void crocus_cache_flush_for_render(struct crocus_batch *batch,
952
struct crocus_bo *bo,
953
enum isl_format format,
954
enum isl_aux_usage aux_usage);
955
void crocus_render_cache_add_bo(struct crocus_batch *batch,
956
struct crocus_bo *bo,
957
enum isl_format format,
958
enum isl_aux_usage aux_usage);
959
void crocus_cache_flush_for_depth(struct crocus_batch *batch, struct crocus_bo *bo);
960
void crocus_depth_cache_add_bo(struct crocus_batch *batch, struct crocus_bo *bo);
961
int crocus_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
962
struct pipe_driver_query_info *info);
963
int crocus_get_driver_query_group_info(struct pipe_screen *pscreen,
964
unsigned index,
965
struct pipe_driver_query_group_info *info);
966
967
struct pipe_rasterizer_state *crocus_get_rast_state(struct crocus_context *ctx);
968
969
bool crocus_sw_check_cond_render(struct crocus_context *ice);
970
static inline bool crocus_check_conditional_render(struct crocus_context *ice)
971
{
972
if (ice->state.predicate == CROCUS_PREDICATE_STATE_STALL_FOR_QUERY)
973
return crocus_sw_check_cond_render(ice);
974
return ice->state.predicate != CROCUS_PREDICATE_STATE_DONT_RENDER;
975
}
976
977
#ifdef genX
978
# include "crocus_genx_protos.h"
979
#else
980
# define genX(x) gfx4_##x
981
# include "crocus_genx_protos.h"
982
# undef genX
983
# define genX(x) gfx45_##x
984
# include "crocus_genx_protos.h"
985
# undef genX
986
# define genX(x) gfx5_##x
987
# include "crocus_genx_protos.h"
988
# undef genX
989
# define genX(x) gfx6_##x
990
# include "crocus_genx_protos.h"
991
# undef genX
992
# define genX(x) gfx7_##x
993
# include "crocus_genx_protos.h"
994
# undef genX
995
# define genX(x) gfx75_##x
996
# include "crocus_genx_protos.h"
997
# undef genX
998
# define genX(x) gfx8_##x
999
# include "crocus_genx_protos.h"
1000
# undef genX
1001
#endif
1002
1003
#endif
1004
1005