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