xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #ifndef __NVC0_SCREEN_H__
2 #define __NVC0_SCREEN_H__
3 
4 #include "nouveau_screen.h"
5 #include "nouveau_mm.h"
6 #include "nouveau_fence.h"
7 #include "nouveau_heap.h"
8 
9 #include "nv_object.xml.h"
10 
11 #include "nvc0/nvc0_winsys.h"
12 #include "nvc0/nvc0_stateobj.h"
13 
14 #define NVC0_TIC_MAX_ENTRIES 2048
15 #define NVC0_TSC_MAX_ENTRIES 2048
16 #define NVE4_IMG_MAX_HANDLES 512
17 
18 /* doesn't count driver-reserved slot */
19 #define NVC0_MAX_PIPE_CONSTBUFS 15
20 #define NVC0_MAX_CONST_BUFFERS  16
21 #define NVC0_MAX_CONSTBUF_SIZE  65536
22 
23 #define NVC0_MAX_SURFACE_SLOTS 16
24 
25 #define NVC0_MAX_VIEWPORTS 16
26 
27 #define NVC0_MAX_BUFFERS 32
28 
29 #define NVC0_MAX_IMAGES 8
30 
31 #define NVC0_MAX_WINDOW_RECTANGLES 8
32 
33 struct nvc0_context;
34 
35 struct nvc0_blitter;
36 
37 struct nvc0_graph_state {
38    bool flushed;
39    bool rasterizer_discard;
40    bool early_z_forced;
41    bool prim_restart;
42    uint32_t instance_elts; /* bitmask of per-instance elements */
43    uint32_t instance_base;
44    uint32_t constant_vbos;
45    uint32_t constant_elts;
46    int32_t index_bias;
47    uint16_t scissor;
48    bool flatshade;
49    uint8_t patch_vertices;
50    uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
51    uint8_t num_vtxbufs;
52    uint8_t num_vtxelts;
53    uint8_t num_textures[6];
54    uint8_t num_samplers[6];
55    uint8_t tls_required; /* bitmask of shader types using l[] */
56    uint8_t clip_enable;
57    uint32_t clip_mode;
58    bool uniform_buffer_bound[6];
59    struct nvc0_transform_feedback_state *tfb;
60    bool seamless_cube_map;
61    bool post_depth_coverage;
62 };
63 
64 struct nvc0_cb_binding {
65    uint64_t addr;
66    int size;
67 };
68 
69 struct nvc0_screen {
70    struct nouveau_screen base;
71 
72    struct nvc0_context *cur_ctx;
73    struct nvc0_graph_state save_state;
74    simple_mtx_t state_lock;
75 
76    int num_occlusion_queries_active;
77 
78    struct nouveau_bo *text;
79    struct nouveau_bo *uniform_bo;
80    struct nouveau_bo *tls;
81    struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
82    struct nouveau_bo *poly_cache;
83 
84    uint8_t gpc_count;
85    uint16_t mp_count;
86    uint16_t mp_count_compute; /* magic reg can make compute use fewer MPs */
87 
88    struct nouveau_heap *text_heap;
89    struct nouveau_heap *lib_code; /* allocated from text_heap */
90 
91    struct nvc0_blitter *blitter;
92 
93    struct {
94       void **entries;
95       int next;
96       uint32_t lock[NVC0_TIC_MAX_ENTRIES / 32];
97       bool maxwell;
98    } tic;
99 
100    struct {
101       void **entries;
102       int next;
103       uint32_t lock[NVC0_TSC_MAX_ENTRIES / 32];
104    } tsc;
105 
106    struct {
107       struct pipe_image_view **entries;
108       int next;
109    } img;
110 
111    struct {
112       struct nouveau_bo *bo;
113       uint32_t *map;
114    } fence;
115 
116    struct {
117       struct nvc0_program *prog; /* compute state object to read MP counters */
118       struct nvc0_hw_sm_query *mp_counter[8]; /* counter to query allocation */
119       uint8_t num_hw_sm_active[2];
120       bool mp_counters_enabled;
121    } pm;
122 
123    /* only maintained on Maxwell+ */
124    struct nvc0_cb_binding cb_bindings[5][NVC0_MAX_CONST_BUFFERS];
125 
126    struct nouveau_object *eng3d; /* sqrt(1/2)|kepler> + sqrt(1/2)|fermi> */
127    struct nouveau_object *eng2d;
128    struct nouveau_object *m2mf;
129    struct nouveau_object *copy;
130    struct nouveau_object *compute;
131    struct nouveau_object *nvsw;
132 };
133 
134 static inline struct nvc0_screen *
nvc0_screen(struct pipe_screen * screen)135 nvc0_screen(struct pipe_screen *screen)
136 {
137    return (struct nvc0_screen *)screen;
138 }
139 
140 int nvc0_screen_get_driver_query_info(struct pipe_screen *, unsigned,
141                                       struct pipe_driver_query_info *);
142 
143 int nvc0_screen_get_driver_query_group_info(struct pipe_screen *, unsigned,
144                                             struct pipe_driver_query_group_info *);
145 
146 bool nvc0_blitter_create(struct nvc0_screen *);
147 void nvc0_blitter_destroy(struct nvc0_screen *);
148 
149 void nvc0_screen_make_buffers_resident(struct nvc0_screen *);
150 
151 int nvc0_screen_tic_alloc(struct nvc0_screen *, void *);
152 int nvc0_screen_tsc_alloc(struct nvc0_screen *, void *);
153 
154 int nve4_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
155 int nvc0_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
156 
157 int nvc0_screen_resize_text_area(struct nvc0_screen *, struct nouveau_pushbuf *, uint64_t);
158 
159 // 3D Only
160 void nvc0_screen_bind_cb_3d(struct nvc0_screen *, struct nouveau_pushbuf *, bool *, int, int, int, uint64_t);
161 
162 struct nvc0_format {
163    uint32_t rt;
164    struct {
165       unsigned format:7;
166       unsigned type_r:3;
167       unsigned type_g:3;
168       unsigned type_b:3;
169       unsigned type_a:3;
170       unsigned src_x:3;
171       unsigned src_y:3;
172       unsigned src_z:3;
173       unsigned src_w:3;
174    } tic;
175    uint32_t usage;
176 };
177 
178 struct nvc0_vertex_format {
179    uint32_t vtx;
180    uint32_t usage;
181 };
182 
183 extern const struct nvc0_format nvc0_format_table[];
184 extern const struct nvc0_vertex_format nvc0_vertex_format[];
185 
186 static inline void
nvc0_screen_tic_unlock(struct nvc0_screen * screen,struct nv50_tic_entry * tic)187 nvc0_screen_tic_unlock(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
188 {
189    if (tic->bindless)
190       return;
191    if (tic->id >= 0)
192       screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
193 }
194 
195 static inline void
nvc0_screen_tsc_unlock(struct nvc0_screen * screen,struct nv50_tsc_entry * tsc)196 nvc0_screen_tsc_unlock(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
197 {
198    if (tsc->id >= 0)
199       screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
200 }
201 
202 static inline void
nvc0_screen_tic_free(struct nvc0_screen * screen,struct nv50_tic_entry * tic)203 nvc0_screen_tic_free(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
204 {
205    if (tic->id >= 0) {
206       screen->tic.entries[tic->id] = NULL;
207       screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
208    }
209 }
210 
211 static inline void
nvc0_screen_tsc_free(struct nvc0_screen * screen,struct nv50_tsc_entry * tsc)212 nvc0_screen_tsc_free(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
213 {
214    if (tsc->id >= 0) {
215       screen->tsc.entries[tsc->id] = NULL;
216       screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
217    }
218 }
219 
220 #endif
221