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