• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014-2017 Broadcom
3  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #ifndef V3D_CONTEXT_H
26 #define V3D_CONTEXT_H
27 
28 #ifdef V3D_VERSION
29 #include "broadcom/common/v3d_macros.h"
30 #endif
31 
32 #include <stdio.h>
33 
34 #include "pipe/p_context.h"
35 #include "pipe/p_state.h"
36 #include "util/bitset.h"
37 #include "util/slab.h"
38 #include "xf86drm.h"
39 #include "drm-uapi/v3d_drm.h"
40 #include "v3d_screen.h"
41 #include "broadcom/common/v3d_limits.h"
42 
43 #include "broadcom/simulator/v3d_simulator.h"
44 
45 struct v3d_job;
46 struct v3d_bo;
47 void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *bo);
48 
49 #include "v3d_bufmgr.h"
50 #include "v3d_resource.h"
51 #include "v3d_cl.h"
52 
53 #ifdef USE_V3D_SIMULATOR
54 #define using_v3d_simulator true
55 #else
56 #define using_v3d_simulator false
57 #endif
58 
59 #define V3D_DIRTY_BLEND               (1ull <<  0)
60 #define V3D_DIRTY_RASTERIZER          (1ull <<  1)
61 #define V3D_DIRTY_ZSA                 (1ull <<  2)
62 #define V3D_DIRTY_COMPTEX             (1ull <<  3)
63 #define V3D_DIRTY_VERTTEX             (1ull <<  4)
64 #define V3D_DIRTY_GEOMTEX             (1ull <<  5)
65 #define V3D_DIRTY_FRAGTEX             (1ull <<  6)
66 
67 #define V3D_DIRTY_SHADER_IMAGE        (1ull <<  9)
68 #define V3D_DIRTY_BLEND_COLOR         (1ull << 10)
69 #define V3D_DIRTY_STENCIL_REF         (1ull << 11)
70 #define V3D_DIRTY_SAMPLE_STATE        (1ull << 12)
71 #define V3D_DIRTY_FRAMEBUFFER         (1ull << 13)
72 #define V3D_DIRTY_STIPPLE             (1ull << 14)
73 #define V3D_DIRTY_VIEWPORT            (1ull << 15)
74 #define V3D_DIRTY_CONSTBUF            (1ull << 16)
75 #define V3D_DIRTY_VTXSTATE            (1ull << 17)
76 #define V3D_DIRTY_VTXBUF              (1ull << 18)
77 #define V3D_DIRTY_SCISSOR             (1ull << 19)
78 #define V3D_DIRTY_FLAT_SHADE_FLAGS    (1ull << 20)
79 #define V3D_DIRTY_PRIM_MODE           (1ull << 21)
80 #define V3D_DIRTY_CLIP                (1ull << 22)
81 #define V3D_DIRTY_UNCOMPILED_CS       (1ull << 23)
82 #define V3D_DIRTY_UNCOMPILED_VS       (1ull << 24)
83 #define V3D_DIRTY_UNCOMPILED_GS       (1ull << 25)
84 #define V3D_DIRTY_UNCOMPILED_FS       (1ull << 26)
85 
86 #define V3D_DIRTY_COMPILED_CS         (1ull << 29)
87 #define V3D_DIRTY_COMPILED_VS         (1ull << 30)
88 #define V3D_DIRTY_COMPILED_GS_BIN     (1ULL << 31)
89 #define V3D_DIRTY_COMPILED_GS         (1ULL << 32)
90 #define V3D_DIRTY_COMPILED_FS         (1ull << 33)
91 
92 #define V3D_DIRTY_FS_INPUTS           (1ull << 38)
93 #define V3D_DIRTY_GS_INPUTS           (1ull << 39)
94 #define V3D_DIRTY_STREAMOUT           (1ull << 40)
95 #define V3D_DIRTY_OQ                  (1ull << 41)
96 #define V3D_DIRTY_CENTROID_FLAGS      (1ull << 42)
97 #define V3D_DIRTY_NOPERSPECTIVE_FLAGS (1ull << 43)
98 #define V3D_DIRTY_SSBO                (1ull << 44)
99 
100 #define V3D_MAX_FS_INPUTS 64
101 
102 #define MAX_JOB_SCISSORS 16
103 
104 enum v3d_sampler_state_variant {
105         V3D_SAMPLER_STATE_BORDER_0,
106         V3D_SAMPLER_STATE_F16,
107         V3D_SAMPLER_STATE_F16_UNORM,
108         V3D_SAMPLER_STATE_F16_SNORM,
109         V3D_SAMPLER_STATE_F16_BGRA,
110         V3D_SAMPLER_STATE_F16_BGRA_UNORM,
111         V3D_SAMPLER_STATE_F16_BGRA_SNORM,
112         V3D_SAMPLER_STATE_F16_A,
113         V3D_SAMPLER_STATE_F16_A_SNORM,
114         V3D_SAMPLER_STATE_F16_A_UNORM,
115         V3D_SAMPLER_STATE_F16_LA,
116         V3D_SAMPLER_STATE_F16_LA_UNORM,
117         V3D_SAMPLER_STATE_F16_LA_SNORM,
118         V3D_SAMPLER_STATE_32,
119         V3D_SAMPLER_STATE_32_UNORM,
120         V3D_SAMPLER_STATE_32_SNORM,
121         V3D_SAMPLER_STATE_32_A,
122         V3D_SAMPLER_STATE_32_A_UNORM,
123         V3D_SAMPLER_STATE_32_A_SNORM,
124         V3D_SAMPLER_STATE_1010102U,
125         V3D_SAMPLER_STATE_16U,
126         V3D_SAMPLER_STATE_16I,
127         V3D_SAMPLER_STATE_8I,
128         V3D_SAMPLER_STATE_8U,
129 
130         V3D_SAMPLER_STATE_VARIANT_COUNT,
131 };
132 
133 enum v3d_flush_cond {
134         /* Flush job unless we are flushing for transform feedback, where we
135          * handle flushing in the driver via the 'Wait for TF' packet.
136          */
137         V3D_FLUSH_DEFAULT,
138         /* Always flush the job, even for cases where we would normally not
139          * do it, such as transform feedback.
140          */
141         V3D_FLUSH_ALWAYS,
142         /* Flush job if it is not the current FBO job. This is intended to
143          * skip automatic flushes of the current job for resources that we
144          * expect to be externally synchronized by the application using
145          * glMemoryBarrier(), such as SSBOs and shader images.
146          */
147         V3D_FLUSH_NOT_CURRENT_JOB,
148 };
149 
150 struct v3d_sampler_view {
151         struct pipe_sampler_view base;
152         uint32_t p0;
153         uint32_t p1;
154         /* Precomputed swizzles to pass in to the shader key. */
155         uint8_t swizzle[4];
156 
157         uint8_t texture_shader_state[32];
158         /* V3D 4.x: Texture state struct. */
159         struct v3d_bo *bo;
160 
161         enum v3d_sampler_state_variant sampler_variant;
162 
163         /* Actual texture to be read by this sampler view.  May be different
164          * from base.texture in the case of having a shadow tiled copy of a
165          * raster texture.
166          */
167         struct pipe_resource *texture;
168 };
169 
170 struct v3d_sampler_state {
171         struct pipe_sampler_state base;
172         uint32_t p0;
173         uint32_t p1;
174 
175         /* V3D 3.x: Packed texture state. */
176         uint8_t texture_shader_state[32];
177         /* V3D 4.x: Sampler state struct. */
178         struct pipe_resource *sampler_state;
179         uint32_t sampler_state_offset[V3D_SAMPLER_STATE_VARIANT_COUNT];
180 
181         bool border_color_variants;
182 };
183 
184 struct v3d_texture_stateobj {
185         struct pipe_sampler_view *textures[V3D_MAX_TEXTURE_SAMPLERS];
186         unsigned num_textures;
187         struct pipe_sampler_state *samplers[V3D_MAX_TEXTURE_SAMPLERS];
188         unsigned num_samplers;
189         struct v3d_cl_reloc texture_state[V3D_MAX_TEXTURE_SAMPLERS];
190 };
191 
192 struct v3d_shader_uniform_info {
193         enum quniform_contents *contents;
194         uint32_t *data;
195         uint32_t count;
196 };
197 
198 struct v3d_uncompiled_shader {
199         /** A name for this program, so you can track it in shader-db output. */
200         uint32_t program_id;
201         /** How many variants of this program were compiled, for shader-db. */
202         uint32_t compiled_variant_count;
203         struct pipe_shader_state base;
204         uint32_t num_tf_outputs;
205         struct v3d_varying_slot *tf_outputs;
206         uint16_t tf_specs[16];
207         uint16_t tf_specs_psiz[16];
208         uint32_t num_tf_specs;
209 };
210 
211 struct v3d_compiled_shader {
212         struct pipe_resource *resource;
213         uint32_t offset;
214 
215         union {
216                 struct v3d_prog_data *base;
217                 struct v3d_vs_prog_data *vs;
218                 struct v3d_gs_prog_data *gs;
219                 struct v3d_fs_prog_data *fs;
220                 struct v3d_compute_prog_data *compute;
221         } prog_data;
222 
223         /**
224          * V3D_DIRTY_* flags that, when set in v3d->dirty, mean that the
225          * uniforms have to be rewritten (and therefore the shader state
226          * reemitted).
227          */
228         uint64_t uniform_dirty_bits;
229 };
230 
231 struct v3d_program_stateobj {
232         struct v3d_uncompiled_shader *bind_vs, *bind_gs, *bind_fs, *bind_compute;
233         struct v3d_compiled_shader *cs, *vs, *gs_bin, *gs, *fs, *compute;
234 
235         struct hash_table *cache[MESA_SHADER_STAGES];
236 
237         struct v3d_bo *spill_bo;
238         int spill_size_per_thread;
239 };
240 
241 struct v3d_constbuf_stateobj {
242         struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
243         uint32_t enabled_mask;
244         uint32_t dirty_mask;
245 };
246 
247 struct v3d_vertexbuf_stateobj {
248         struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
249         unsigned count;
250         uint32_t enabled_mask;
251         uint32_t dirty_mask;
252 };
253 
254 struct v3d_vertex_stateobj {
255         struct pipe_vertex_element pipe[V3D_MAX_VS_INPUTS / 4];
256         unsigned num_elements;
257 
258         uint8_t attrs[16 * (V3D_MAX_VS_INPUTS / 4)];
259         struct pipe_resource *defaults;
260         uint32_t defaults_offset;
261 };
262 
263 struct v3d_stream_output_target {
264         struct pipe_stream_output_target base;
265         /* Number of transform feedback vertices written to this target */
266         uint32_t recorded_vertex_count;
267 };
268 
269 struct v3d_streamout_stateobj {
270         struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
271         /* Number of vertices we've written into the buffer so far. */
272         uint32_t offsets[PIPE_MAX_SO_BUFFERS];
273         unsigned num_targets;
274 };
275 
276 struct v3d_ssbo_stateobj {
277         struct pipe_shader_buffer sb[PIPE_MAX_SHADER_BUFFERS];
278         uint32_t enabled_mask;
279 };
280 
281 /* Hash table key for v3d->jobs */
282 struct v3d_job_key {
283         struct pipe_surface *cbufs[4];
284         struct pipe_surface *zsbuf;
285         struct pipe_surface *bbuf;
286 };
287 
288 enum v3d_ez_state {
289         V3D_EZ_UNDECIDED = 0,
290         V3D_EZ_GT_GE,
291         V3D_EZ_LT_LE,
292         V3D_EZ_DISABLED,
293 };
294 
295 struct v3d_image_view {
296         struct pipe_image_view base;
297         /* V3D 4.x texture shader state struct */
298         struct pipe_resource *tex_state;
299         uint32_t tex_state_offset;
300 };
301 
302 struct v3d_shaderimg_stateobj {
303         struct v3d_image_view si[PIPE_MAX_SHADER_IMAGES];
304         uint32_t enabled_mask;
305 };
306 
307 struct v3d_perfmon_state {
308         /* The kernel perfmon id */
309         uint32_t kperfmon_id;
310         /* True if at least one job was submitted with this perfmon. */
311         bool job_submitted;
312         /* Fence to be signaled when the last job submitted with this perfmon
313          * is executed by the GPU.
314          */
315         struct v3d_fence *last_job_fence;
316         uint8_t counters[DRM_V3D_MAX_PERF_COUNTERS];
317         uint64_t values[DRM_V3D_MAX_PERF_COUNTERS];
318 };
319 
320 /**
321  * A complete bin/render job.
322  *
323  * This is all of the state necessary to submit a bin/render to the kernel.
324  * We want to be able to have multiple in progress at a time, so that we don't
325  * need to flush an existing CL just to switch to rendering to a new render
326  * target (which would mean reading back from the old render target when
327  * starting to render to it again).
328  */
329 struct v3d_job {
330         struct v3d_context *v3d;
331         struct v3d_cl bcl;
332         struct v3d_cl rcl;
333         struct v3d_cl indirect;
334         struct v3d_bo *tile_alloc;
335         struct v3d_bo *tile_state;
336 
337         struct drm_v3d_submit_cl submit;
338 
339         /**
340          * Set of all BOs referenced by the job.  This will be used for making
341          * the list of BOs that the kernel will need to have paged in to
342          * execute our job.
343          */
344         struct set *bos;
345 
346         /** Sum of the sizes of the BOs referenced by the job. */
347         uint32_t referenced_size;
348 
349         struct set *write_prscs;
350         struct set *tf_write_prscs;
351 
352         /* Size of the submit.bo_handles array. */
353         uint32_t bo_handles_size;
354 
355         /** @{
356          * Surfaces to submit rendering for.
357          * For blit operations, bbuf is the source surface, and cbufs[0] is
358          * the destination surface.
359          */
360         uint32_t nr_cbufs;
361         struct pipe_surface *cbufs[4];
362         struct pipe_surface *zsbuf;
363         struct pipe_surface *bbuf;
364         /** @} */
365         /** @{
366          * Bounding box of the scissor across all queued drawing.
367          *
368          * Note that the max values are exclusive.
369          */
370         uint32_t draw_min_x;
371         uint32_t draw_min_y;
372         uint32_t draw_max_x;
373         uint32_t draw_max_y;
374 
375         /** @} */
376         /** @{
377          * List of scissor rects used for all queued drawing. All scissor
378          * rects will be contained in the draw_{min/max}_{x/y} bounding box.
379          *
380          * This is used as an optimization when all drawing is scissored to
381          * limit tile flushing only to tiles that intersect a scissor rect.
382          * If scissor is used together with non-scissored drawing, then
383          * the optimization is disabled.
384          */
385         struct {
386                 bool disabled;
387                 uint32_t count;
388                 struct {
389                         uint32_t min_x, min_y;
390                         uint32_t max_x, max_y;
391                 } rects[MAX_JOB_SCISSORS];
392         } scissor;
393 
394         /** @} */
395         /** @{
396          * Width/height of the color framebuffer being rendered to,
397          * for V3D_TILE_RENDERING_MODE_CONFIG.
398          */
399         uint32_t draw_width;
400         uint32_t draw_height;
401         uint32_t num_layers;
402 
403         /** @} */
404         /** @{ Tile information, depending on MSAA and float color buffer. */
405         uint32_t draw_tiles_x; /** @< Number of tiles wide for framebuffer. */
406         uint32_t draw_tiles_y; /** @< Number of tiles high for framebuffer. */
407 
408         uint32_t tile_width; /** @< Width of a tile. */
409         uint32_t tile_height; /** @< Height of a tile. */
410         /** maximum internal_bpp of all color render targets. */
411         uint32_t internal_bpp;
412 
413         /** Whether the current rendering is in a 4X MSAA tile buffer. */
414         bool msaa;
415         /** @} */
416 
417         /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the
418          * first rendering.
419          */
420         uint32_t clear;
421         /* Bitmask of PIPE_CLEAR_* of buffers that have been read by a draw
422          * call without having been cleared first.
423          */
424         uint32_t load;
425         /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to
426          * (either clears or draws) and should be stored.
427          */
428         uint32_t store;
429         uint32_t clear_color[4][4];
430         float clear_z;
431         uint8_t clear_s;
432 
433         /**
434          * Set if some drawing (triangles, blits, or just a glClear()) has
435          * been done to the FBO, meaning that we need to
436          * DRM_IOCTL_V3D_SUBMIT_CL.
437          */
438         bool needs_flush;
439 
440         /* Set if any shader has dirtied cachelines in the TMU that need to be
441          * flushed before job end.
442          */
443         bool tmu_dirty_rcl;
444 
445         /**
446          * Set if a packet enabling TF has been emitted in the job (V3D 4.x).
447          */
448         bool tf_enabled;
449 
450         bool needs_primitives_generated;
451 
452         /**
453          * Current EZ state for drawing. Updated at the start of draw after
454          * we've decided on the shader being rendered.
455          */
456         enum v3d_ez_state ez_state;
457         /**
458          * The first EZ state that was used for drawing with a decided EZ
459          * direction (so either UNDECIDED, GT, or LT).
460          */
461         enum v3d_ez_state first_ez_state;
462 
463         /**
464          * Number of draw calls (not counting full buffer clears) queued in
465          * the current job.
466          */
467         uint32_t draw_calls_queued;
468 
469         /**
470          * Number of draw calls (not counting full buffer clears) queued in
471          * the current job during active transform feedback.
472          */
473         uint32_t tf_draw_calls_queued;
474 
475         struct v3d_job_key key;
476 };
477 
478 struct v3d_context {
479         struct pipe_context base;
480 
481         int fd;
482         struct v3d_screen *screen;
483 
484         /** The 3D rendering job for the currently bound FBO. */
485         struct v3d_job *job;
486 
487         /* Map from struct v3d_job_key to the job for that FBO.
488          */
489         struct hash_table *jobs;
490 
491         /**
492          * Map from v3d_resource to a job writing to that resource.
493          *
494          * Primarily for flushing jobs rendering to textures that are now
495          * being read from.
496          */
497         struct hash_table *write_jobs;
498 
499         struct slab_child_pool transfer_pool;
500         struct blitter_context *blitter;
501 
502         /** bitfield of V3D_DIRTY_* */
503         uint64_t dirty;
504 
505         uint32_t next_uncompiled_program_id;
506         uint64_t next_compiled_program_id;
507 
508         struct v3d_compiler_state *compiler_state;
509 
510         uint8_t prim_mode;
511 
512         /** Maximum index buffer valid for the current shader_rec. */
513         uint32_t max_index;
514 
515         /** Sync object that our RCL or TFU job will update as its out_sync. */
516         uint32_t out_sync;
517 
518         /* Stream uploader used by gallium internals.  This could also be used
519          * by driver internals, but we tend to use the v3d_cl.h interfaces
520          * instead.
521          */
522         struct u_upload_mgr *uploader;
523         /* State uploader used inside the driver.  This is for packing bits of
524          * long-term state inside buffers, since the kernel interfaces
525          * allocate a page at a time.
526          */
527         struct u_upload_mgr *state_uploader;
528 
529         struct pipe_shader_state *sand8_blit_vs;
530         struct pipe_shader_state *sand8_blit_fs_luma;
531         struct pipe_shader_state *sand8_blit_fs_chroma;
532 
533         /** @{ Current pipeline state objects */
534         struct pipe_scissor_state scissor;
535         struct v3d_blend_state *blend;
536         struct v3d_rasterizer_state *rasterizer;
537         struct v3d_depth_stencil_alpha_state *zsa;
538 
539         struct v3d_program_stateobj prog;
540         uint32_t compute_num_workgroups[3];
541         struct v3d_bo *compute_shared_memory;
542 
543         struct v3d_vertex_stateobj *vtx;
544 
545         struct {
546                 struct pipe_blend_color f;
547                 uint16_t hf[4];
548         } blend_color;
549         struct pipe_stencil_ref stencil_ref;
550         unsigned sample_mask;
551         struct pipe_framebuffer_state framebuffer;
552 
553         /* Per render target, whether we should swap the R and B fields in the
554          * shader's color output and in blending.  If render targets disagree
555          * on the R/B swap and use the constant color, then we would need to
556          * fall back to in-shader blending.
557          */
558         uint8_t swap_color_rb;
559 
560         /* Per render target, whether we should treat the dst alpha values as
561          * one in blending.
562          *
563          * For RGBX formats, the tile buffer's alpha channel will be
564          * undefined.
565          */
566         uint8_t blend_dst_alpha_one;
567 
568         bool active_queries;
569 
570         /**
571          * If a compute job writes a resource read by a non-compute stage we
572          * should sync on the last compute job.
573          */
574         bool sync_on_last_compute_job;
575 
576         uint32_t tf_prims_generated;
577         uint32_t prims_generated;
578 
579         uint32_t n_primitives_generated_queries_in_flight;
580 
581         struct pipe_poly_stipple stipple;
582         struct pipe_clip_state clip;
583         struct pipe_viewport_state viewport;
584         struct v3d_ssbo_stateobj ssbo[PIPE_SHADER_TYPES];
585         struct v3d_shaderimg_stateobj shaderimg[PIPE_SHADER_TYPES];
586         struct v3d_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
587         struct v3d_texture_stateobj tex[PIPE_SHADER_TYPES];
588         struct v3d_vertexbuf_stateobj vertexbuf;
589         struct v3d_streamout_stateobj streamout;
590         struct v3d_bo *current_oq;
591         struct pipe_resource *prim_counts;
592         uint32_t prim_counts_offset;
593         struct pipe_debug_callback debug;
594         struct v3d_perfmon_state *active_perfmon;
595         struct v3d_perfmon_state *last_perfmon;
596         /** @} */
597 };
598 
599 struct v3d_rasterizer_state {
600         struct pipe_rasterizer_state base;
601 
602         float point_size;
603 
604         uint8_t depth_offset[9];
605         uint8_t depth_offset_z16[9];
606 };
607 
608 struct v3d_depth_stencil_alpha_state {
609         struct pipe_depth_stencil_alpha_state base;
610 
611         enum v3d_ez_state ez_state;
612 
613         uint8_t stencil_front[6];
614         uint8_t stencil_back[6];
615 };
616 
617 struct v3d_blend_state {
618         struct pipe_blend_state base;
619 
620         /* Per-RT mask of whether blending is enabled. */
621         uint8_t blend_enables;
622 };
623 
624 #define perf_debug(...) do {                            \
625         if (unlikely(V3D_DEBUG & V3D_DEBUG_PERF))       \
626                 fprintf(stderr, __VA_ARGS__);           \
627         if (unlikely(v3d->debug.debug_message))         \
628                 pipe_debug_message(&v3d->debug, PERF_INFO, __VA_ARGS__);    \
629 } while (0)
630 
631 static inline struct v3d_context *
v3d_context(struct pipe_context * pcontext)632 v3d_context(struct pipe_context *pcontext)
633 {
634         return (struct v3d_context *)pcontext;
635 }
636 
637 static inline struct v3d_sampler_view *
v3d_sampler_view(struct pipe_sampler_view * psview)638 v3d_sampler_view(struct pipe_sampler_view *psview)
639 {
640         return (struct v3d_sampler_view *)psview;
641 }
642 
643 static inline struct v3d_sampler_state *
v3d_sampler_state(struct pipe_sampler_state * psampler)644 v3d_sampler_state(struct pipe_sampler_state *psampler)
645 {
646         return (struct v3d_sampler_state *)psampler;
647 }
648 
649 static inline struct v3d_stream_output_target *
v3d_stream_output_target(struct pipe_stream_output_target * ptarget)650 v3d_stream_output_target(struct pipe_stream_output_target *ptarget)
651 {
652         return (struct v3d_stream_output_target *)ptarget;
653 }
654 
655 static inline uint32_t
v3d_stream_output_target_get_vertex_count(struct pipe_stream_output_target * ptarget)656 v3d_stream_output_target_get_vertex_count(struct pipe_stream_output_target *ptarget)
657 {
658     return v3d_stream_output_target(ptarget)->recorded_vertex_count;
659 }
660 
661 int v3d_get_driver_query_group_info(struct pipe_screen *pscreen,
662                                     unsigned index,
663                                     struct pipe_driver_query_group_info *info);
664 int v3d_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
665                               struct pipe_driver_query_info *info);
666 
667 struct pipe_context *v3d_context_create(struct pipe_screen *pscreen,
668                                         void *priv, unsigned flags);
669 void v3d_program_init(struct pipe_context *pctx);
670 void v3d_program_fini(struct pipe_context *pctx);
671 void v3d_query_init(struct pipe_context *pctx);
672 
673 static inline int
v3d_ioctl(int fd,unsigned long request,void * arg)674 v3d_ioctl(int fd, unsigned long request, void *arg)
675 {
676         if (using_v3d_simulator)
677                 return v3d_simulator_ioctl(fd, request, arg);
678         else
679                 return drmIoctl(fd, request, arg);
680 }
681 
682 static inline bool
v3d_transform_feedback_enabled(struct v3d_context * v3d)683 v3d_transform_feedback_enabled(struct v3d_context *v3d)
684 {
685         return (v3d->prog.bind_vs->num_tf_specs != 0 ||
686                 (v3d->prog.bind_gs && v3d->prog.bind_gs->num_tf_specs != 0)) &&
687                v3d->active_queries;
688 }
689 
690 void v3d_set_shader_uniform_dirty_flags(struct v3d_compiled_shader *shader);
691 struct v3d_cl_reloc v3d_write_uniforms(struct v3d_context *v3d,
692                                        struct v3d_job *job,
693                                        struct v3d_compiled_shader *shader,
694                                        enum pipe_shader_type stage);
695 
696 void v3d_flush(struct pipe_context *pctx);
697 void v3d_job_init(struct v3d_context *v3d);
698 struct v3d_job *v3d_job_create(struct v3d_context *v3d);
699 void v3d_job_free(struct v3d_context *v3d, struct v3d_job *job);
700 struct v3d_job *v3d_get_job(struct v3d_context *v3d,
701                             uint32_t nr_cbufs,
702                             struct pipe_surface **cbufs,
703                             struct pipe_surface *zsbuf,
704                             struct pipe_surface *bbuf);
705 struct v3d_job *v3d_get_job_for_fbo(struct v3d_context *v3d);
706 void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *bo);
707 void v3d_job_add_write_resource(struct v3d_job *job, struct pipe_resource *prsc);
708 void v3d_job_add_tf_write_resource(struct v3d_job *job, struct pipe_resource *prsc);
709 void v3d_job_submit(struct v3d_context *v3d, struct v3d_job *job);
710 void v3d_flush_jobs_using_bo(struct v3d_context *v3d, struct v3d_bo *bo);
711 void v3d_flush_jobs_writing_resource(struct v3d_context *v3d,
712                                      struct pipe_resource *prsc,
713                                      enum v3d_flush_cond flush_cond,
714                                      bool is_compute_pipeline);
715 void v3d_flush_jobs_reading_resource(struct v3d_context *v3d,
716                                      struct pipe_resource *prsc,
717                                      enum v3d_flush_cond flush_cond,
718                                      bool is_compute_pipeline);
719 void v3d_update_compiled_shaders(struct v3d_context *v3d, uint8_t prim_mode);
720 void v3d_update_compiled_cs(struct v3d_context *v3d);
721 
722 bool v3d_rt_format_supported(const struct v3d_device_info *devinfo,
723                              enum pipe_format f);
724 bool v3d_tex_format_supported(const struct v3d_device_info *devinfo,
725                               enum pipe_format f);
726 uint8_t v3d_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f);
727 uint8_t v3d_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f);
728 uint8_t v3d_get_tex_return_size(const struct v3d_device_info *devinfo,
729                                 enum pipe_format f,
730                                 enum pipe_tex_compare compare);
731 uint8_t v3d_get_tex_return_channels(const struct v3d_device_info *devinfo,
732                                     enum pipe_format f);
733 const uint8_t *v3d_get_format_swizzle(const struct v3d_device_info *devinfo,
734                                       enum pipe_format f);
735 void v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo,
736                                                  uint32_t format,
737                                                  uint32_t *type,
738                                                  uint32_t *bpp);
739 bool v3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo,
740                                  uint32_t tex_format,
741                                  bool for_mipmap);
742 bool v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo,
743                                           enum pipe_format f);
744 
745 void v3d_init_query_functions(struct v3d_context *v3d);
746 void v3d_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info);
747 void v3d_blitter_save(struct v3d_context *v3d);
748 bool v3d_generate_mipmap(struct pipe_context *pctx,
749                          struct pipe_resource *prsc,
750                          enum pipe_format format,
751                          unsigned int base_level,
752                          unsigned int last_level,
753                          unsigned int first_layer,
754                          unsigned int last_layer);
755 
756 void
757 v3d_fence_unreference(struct v3d_fence **fence);
758 
759 struct v3d_fence *v3d_fence_create(struct v3d_context *v3d);
760 
761 bool v3d_fence_wait(struct v3d_screen *screen,
762                     struct v3d_fence *fence,
763                     uint64_t timeout_ns);
764 
765 void v3d_update_primitive_counters(struct v3d_context *v3d);
766 
767 bool v3d_line_smoothing_enabled(struct v3d_context *v3d);
768 
769 float v3d_get_real_line_width(struct v3d_context *v3d);
770 
771 void v3d_ensure_prim_counts_allocated(struct v3d_context *ctx);
772 
773 void v3d_flag_dirty_sampler_state(struct v3d_context *v3d,
774                                   enum pipe_shader_type shader);
775 
776 void v3d_create_texture_shader_state_bo(struct v3d_context *v3d,
777                                         struct v3d_sampler_view *so);
778 
779 void v3d_get_tile_buffer_size(bool is_msaa,
780                               uint32_t nr_cbufs,
781                               struct pipe_surface **cbufs,
782                               struct pipe_surface *bbuf,
783                               uint32_t *tile_width,
784                               uint32_t *tile_height,
785                               uint32_t *max_bpp);
786 
787 #ifdef v3dX
788 #  include "v3dx_context.h"
789 #else
790 #  define v3dX(x) v3d33_##x
791 #  include "v3dx_context.h"
792 #  undef v3dX
793 
794 #  define v3dX(x) v3d41_##x
795 #  include "v3dx_context.h"
796 #  undef v3dX
797 #endif
798 
799 #endif /* V3D_CONTEXT_H */
800