1 /*
2 * Copyright © 2014 Broadcom
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef VC4_SCREEN_H
25 #define VC4_SCREEN_H
26
27 #include "pipe/p_screen.h"
28 #include "renderonly/renderonly.h"
29 #include "util/u_thread.h"
30 #include "frontend/drm_driver.h"
31 #include "util/list.h"
32 #include "util/slab.h"
33
34 #ifndef DRM_VC4_PARAM_SUPPORTS_ETC1
35 #define DRM_VC4_PARAM_SUPPORTS_ETC1 4
36 #endif
37
38 struct vc4_bo;
39
40 extern uint32_t vc4_mesa_debug;
41
42 #define VC4_DBG(flag) unlikely(vc4_mesa_debug & VC4_DEBUG_ ## flag)
43
44 #define VC4_DEBUG_CL 0x0001
45 #define VC4_DEBUG_QPU 0x0002
46 #define VC4_DEBUG_QIR 0x0004
47 #define VC4_DEBUG_TGSI 0x0008
48 #define VC4_DEBUG_SHADERDB 0x0010
49 #define VC4_DEBUG_PERF 0x0020
50 #define VC4_DEBUG_NORAST 0x0040
51 #define VC4_DEBUG_ALWAYS_FLUSH 0x0080
52 #define VC4_DEBUG_ALWAYS_SYNC 0x0100
53 #define VC4_DEBUG_NIR 0x0200
54 #define VC4_DEBUG_DUMP 0x0400
55 #define VC4_DEBUG_SURFACE 0x0800
56
57 #define VC4_MAX_MIP_LEVELS 12
58 #define VC4_MAX_TEXTURE_SAMPLERS 16
59
60 struct vc4_simulator_file;
61
62 struct vc4_screen {
63 struct pipe_screen base;
64 struct renderonly *ro;
65
66 int fd;
67
68 int v3d_ver;
69
70 const char *name;
71
72 /** The last seqno we've completed a wait for.
73 *
74 * This lets us slightly optimize our waits by skipping wait syscalls
75 * if we know the job's already done.
76 */
77 uint64_t finished_seqno;
78
79 struct slab_parent_pool transfer_pool;
80
81 struct vc4_bo_cache {
82 /** List of struct vc4_bo freed, by age. */
83 struct list_head time_list;
84 /** List of struct vc4_bo freed, per size, by age. */
85 struct list_head *size_list;
86 uint32_t size_list_size;
87
88 mtx_t lock;
89
90 uint32_t bo_size;
91 uint32_t bo_count;
92 } bo_cache;
93
94 struct hash_table *bo_handles;
95 mtx_t bo_handles_mutex;
96
97 uint32_t bo_size;
98 uint32_t bo_count;
99 uint32_t prim_types;
100 bool has_control_flow;
101 bool has_etc1;
102 bool has_threaded_fs;
103 bool has_madvise;
104 bool has_tiling_ioctl;
105 bool has_perfmon_ioctl;
106 bool has_syncobj;
107
108 #ifdef USE_VC4_SIMULATOR
109 struct vc4_simulator_file *sim_file;
110 #endif
111 };
112
113 static inline struct vc4_screen *
vc4_screen(struct pipe_screen * screen)114 vc4_screen(struct pipe_screen *screen)
115 {
116 return (struct vc4_screen *)screen;
117 }
118
119 struct pipe_screen *vc4_screen_create(int fd,
120 const struct pipe_screen_config *config,
121 struct renderonly *ro);
122
123 const void *
124 vc4_screen_get_compiler_options(struct pipe_screen *pscreen,
125 enum pipe_shader_ir ir,
126 enum pipe_shader_type shader);
127
128 void
129 vc4_fence_screen_init(struct vc4_screen *screen);
130
131 struct vc4_fence *
132 vc4_fence_create(struct vc4_screen *screen, uint64_t seqno, int fd);
133
134 #endif /* VC4_SCREEN_H */
135