vc4: Move simulator memory management to a u_mm.h heap.
[mesa.git] / src / gallium / drivers / vc4 / vc4_screen.h
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 "os/os_thread.h"
29 #include "state_tracker/drm_driver.h"
30 #include "util/list.h"
31 #include "util/slab.h"
32
33 struct vc4_bo;
34
35 #define VC4_DEBUG_CL 0x0001
36 #define VC4_DEBUG_QPU 0x0002
37 #define VC4_DEBUG_QIR 0x0004
38 #define VC4_DEBUG_TGSI 0x0008
39 #define VC4_DEBUG_SHADERDB 0x0010
40 #define VC4_DEBUG_PERF 0x0020
41 #define VC4_DEBUG_NORAST 0x0040
42 #define VC4_DEBUG_ALWAYS_FLUSH 0x0080
43 #define VC4_DEBUG_ALWAYS_SYNC 0x0100
44 #define VC4_DEBUG_NIR 0x0200
45 #define VC4_DEBUG_DUMP 0x0400
46
47 #define VC4_MAX_MIP_LEVELS 12
48 #define VC4_MAX_TEXTURE_SAMPLERS 16
49
50 struct vc4_simulator_file;
51
52 struct vc4_screen {
53 struct pipe_screen base;
54 int fd;
55
56 int v3d_ver;
57
58 const char *name;
59
60 /** The last seqno we've completed a wait for.
61 *
62 * This lets us slightly optimize our waits by skipping wait syscalls
63 * if we know the job's already done.
64 */
65 uint64_t finished_seqno;
66
67 struct slab_parent_pool transfer_pool;
68
69 struct vc4_bo_cache {
70 /** List of struct vc4_bo freed, by age. */
71 struct list_head time_list;
72 /** List of struct vc4_bo freed, per size, by age. */
73 struct list_head *size_list;
74 uint32_t size_list_size;
75
76 pipe_mutex lock;
77
78 uint32_t bo_size;
79 uint32_t bo_count;
80 } bo_cache;
81
82 struct util_hash_table *bo_handles;
83 pipe_mutex bo_handles_mutex;
84
85 uint32_t bo_size;
86 uint32_t bo_count;
87 bool has_control_flow;
88
89 struct vc4_simulator_file *sim_file;
90 };
91
92 static inline struct vc4_screen *
93 vc4_screen(struct pipe_screen *screen)
94 {
95 return (struct vc4_screen *)screen;
96 }
97
98 struct pipe_screen *vc4_screen_create(int fd);
99 boolean vc4_screen_bo_get_handle(struct pipe_screen *pscreen,
100 struct vc4_bo *bo,
101 unsigned stride,
102 struct winsys_handle *whandle);
103 struct vc4_bo *
104 vc4_screen_bo_from_handle(struct pipe_screen *pscreen,
105 struct winsys_handle *whandle);
106
107 const void *
108 vc4_screen_get_compiler_options(struct pipe_screen *pscreen,
109 enum pipe_shader_ir ir, unsigned shader);
110
111 extern uint32_t vc4_debug;
112
113 void
114 vc4_fence_init(struct vc4_screen *screen);
115
116 struct vc4_fence *
117 vc4_fence_create(struct vc4_screen *screen, uint64_t seqno);
118
119 #endif /* VC4_SCREEN_H */