Home | History | Annotate | Download | only in nvc0
      1 #ifndef __NVC0_CONTEXT_H__
      2 #define __NVC0_CONTEXT_H__
      3 
      4 #include "pipe/p_context.h"
      5 #include "pipe/p_defines.h"
      6 #include "pipe/p_state.h"
      7 
      8 #include "util/u_memory.h"
      9 #include "util/u_math.h"
     10 #include "util/u_inlines.h"
     11 #include "util/u_dynarray.h"
     12 
     13 #ifdef NVC0_WITH_DRAW_MODULE
     14 #include "draw/draw_vertex.h"
     15 #endif
     16 
     17 #include "nv50/nv50_debug.h"
     18 #include "nvc0_winsys.h"
     19 #include "nvc0_stateobj.h"
     20 #include "nvc0_screen.h"
     21 #include "nvc0_program.h"
     22 #include "nvc0_resource.h"
     23 
     24 #include "nv50/nv50_transfer.h"
     25 
     26 #include "nouveau/nouveau_context.h"
     27 
     28 #include "nvc0_3ddefs.xml.h"
     29 #include "nvc0_3d.xml.h"
     30 #include "nvc0_2d.xml.h"
     31 #include "nvc0_m2mf.xml.h"
     32 #include "nve4_p2mf.xml.h"
     33 
     34 /* NOTE: must keep NVC0_NEW_...PROG in consecutive bits in this order */
     35 #define NVC0_NEW_BLEND        (1 << 0)
     36 #define NVC0_NEW_RASTERIZER   (1 << 1)
     37 #define NVC0_NEW_ZSA          (1 << 2)
     38 #define NVC0_NEW_VERTPROG     (1 << 3)
     39 #define NVC0_NEW_TCTLPROG     (1 << 4)
     40 #define NVC0_NEW_TEVLPROG     (1 << 5)
     41 #define NVC0_NEW_GMTYPROG     (1 << 6)
     42 #define NVC0_NEW_FRAGPROG     (1 << 7)
     43 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
     44 #define NVC0_NEW_STENCIL_REF  (1 << 9)
     45 #define NVC0_NEW_CLIP         (1 << 10)
     46 #define NVC0_NEW_SAMPLE_MASK  (1 << 11)
     47 #define NVC0_NEW_FRAMEBUFFER  (1 << 12)
     48 #define NVC0_NEW_STIPPLE      (1 << 13)
     49 #define NVC0_NEW_SCISSOR      (1 << 14)
     50 #define NVC0_NEW_VIEWPORT     (1 << 15)
     51 #define NVC0_NEW_ARRAYS       (1 << 16)
     52 #define NVC0_NEW_VERTEX       (1 << 17)
     53 #define NVC0_NEW_CONSTBUF     (1 << 18)
     54 #define NVC0_NEW_TEXTURES     (1 << 19)
     55 #define NVC0_NEW_SAMPLERS     (1 << 20)
     56 #define NVC0_NEW_TFB_TARGETS  (1 << 21)
     57 #define NVC0_NEW_IDXBUF       (1 << 22)
     58 
     59 #define NVC0_BIND_FB            0
     60 #define NVC0_BIND_VTX           1
     61 #define NVC0_BIND_VTX_TMP       2
     62 #define NVC0_BIND_IDX           3
     63 #define NVC0_BIND_TEX(s, i)  (  4 + 32 * (s) + (i))
     64 #define NVC0_BIND_CB(s, i)   (164 + 16 * (s) + (i))
     65 #define NVC0_BIND_TFB         244
     66 #define NVC0_BIND_SCREEN      245
     67 #define NVC0_BIND_TLS         246
     68 #define NVC0_BIND_COUNT       247
     69 
     70 #define NVC0_BIND_2D            0
     71 #define NVC0_BIND_M2MF          0
     72 #define NVC0_BIND_FENCE         1
     73 
     74 struct nvc0_context {
     75    struct nouveau_context base;
     76 
     77    struct nouveau_bufctx *bufctx_3d;
     78    struct nouveau_bufctx *bufctx;
     79 
     80    struct nvc0_screen *screen;
     81 
     82    void (*m2mf_copy_rect)(struct nvc0_context *,
     83                           const struct nv50_m2mf_rect *dst,
     84                           const struct nv50_m2mf_rect *src,
     85                           uint32_t nblocksx, uint32_t nblocksy);
     86 
     87    uint32_t dirty;
     88 
     89    struct {
     90       boolean flushed;
     91       boolean rasterizer_discard;
     92       boolean early_z_forced;
     93       boolean prim_restart;
     94       uint32_t instance_elts; /* bitmask of per-instance elements */
     95       uint32_t instance_base;
     96       uint32_t constant_vbos;
     97       uint32_t constant_elts;
     98       int32_t index_bias;
     99       uint16_t scissor;
    100       uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
    101       uint8_t num_vtxbufs;
    102       uint8_t num_vtxelts;
    103       uint8_t num_textures[5];
    104       uint8_t num_samplers[5];
    105       uint8_t tls_required; /* bitmask of shader types using l[] */
    106       uint8_t c14_bound; /* whether immediate array constbuf is bound */
    107       uint8_t clip_enable;
    108       uint32_t clip_mode;
    109       uint32_t uniform_buffer_bound[5];
    110       struct nvc0_transform_feedback_state *tfb;
    111    } state;
    112 
    113    struct nvc0_blend_stateobj *blend;
    114    struct nvc0_rasterizer_stateobj *rast;
    115    struct nvc0_zsa_stateobj *zsa;
    116    struct nvc0_vertex_stateobj *vertex;
    117 
    118    struct nvc0_program *vertprog;
    119    struct nvc0_program *tctlprog;
    120    struct nvc0_program *tevlprog;
    121    struct nvc0_program *gmtyprog;
    122    struct nvc0_program *fragprog;
    123 
    124    struct nvc0_constbuf constbuf[5][NVC0_MAX_PIPE_CONSTBUFS];
    125    uint16_t constbuf_dirty[5];
    126 
    127    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
    128    unsigned num_vtxbufs;
    129    struct pipe_index_buffer idxbuf;
    130    uint32_t constant_vbos;
    131    uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
    132    uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
    133    uint32_t vb_elt_limit; /* max - min element (count - 1) */
    134    uint32_t instance_off; /* current base vertex for instanced arrays */
    135    uint32_t instance_max; /* last instance for current draw call */
    136 
    137    struct pipe_sampler_view *textures[5][PIPE_MAX_SAMPLERS];
    138    unsigned num_textures[5];
    139    uint32_t textures_dirty[5];
    140    struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
    141    unsigned num_samplers[5];
    142    uint16_t samplers_dirty[5];
    143 
    144    uint32_t tex_handles[5][PIPE_MAX_SAMPLERS]; /* for nve4 */
    145 
    146    struct pipe_framebuffer_state framebuffer;
    147    struct pipe_blend_color blend_colour;
    148    struct pipe_stencil_ref stencil_ref;
    149    struct pipe_poly_stipple stipple;
    150    struct pipe_scissor_state scissor;
    151    struct pipe_viewport_state viewport;
    152    struct pipe_clip_state clip;
    153 
    154    unsigned sample_mask;
    155 
    156    boolean vbo_push_hint;
    157 
    158    uint8_t tfbbuf_dirty;
    159    struct pipe_stream_output_target *tfbbuf[4];
    160    unsigned num_tfbbufs;
    161 
    162 #ifdef NVC0_WITH_DRAW_MODULE
    163    struct draw_context *draw;
    164 #endif
    165 };
    166 
    167 static INLINE struct nvc0_context *
    168 nvc0_context(struct pipe_context *pipe)
    169 {
    170    return (struct nvc0_context *)pipe;
    171 }
    172 
    173 static INLINE unsigned
    174 nvc0_shader_stage(unsigned pipe)
    175 {
    176    switch (pipe) {
    177    case PIPE_SHADER_VERTEX: return 0;
    178 /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
    179 /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
    180    case PIPE_SHADER_GEOMETRY: return 3;
    181    case PIPE_SHADER_FRAGMENT: return 4;
    182    case PIPE_SHADER_COMPUTE: return 5;
    183    default:
    184       assert(!"invalid PIPE_SHADER type");
    185       return 0;
    186    }
    187 }
    188 
    189 
    190 /* nvc0_context.c */
    191 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
    192 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
    193                        boolean on_flush);
    194 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
    195 
    196 /* nvc0_draw.c */
    197 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
    198 
    199 /* nvc0_program.c */
    200 boolean nvc0_program_translate(struct nvc0_program *, uint16_t chipset);
    201 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
    202 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
    203 void nvc0_program_library_upload(struct nvc0_context *);
    204 
    205 /* nvc0_query.c */
    206 void nvc0_init_query_functions(struct nvc0_context *);
    207 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
    208                                struct pipe_query *, unsigned result_offset);
    209 void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
    210 void nvc0_so_target_save_offset(struct pipe_context *,
    211                                 struct pipe_stream_output_target *, unsigned i,
    212                                 boolean *serialize);
    213 
    214 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
    215 
    216 /* nvc0_shader_state.c */
    217 void nvc0_vertprog_validate(struct nvc0_context *);
    218 void nvc0_tctlprog_validate(struct nvc0_context *);
    219 void nvc0_tevlprog_validate(struct nvc0_context *);
    220 void nvc0_gmtyprog_validate(struct nvc0_context *);
    221 void nvc0_fragprog_validate(struct nvc0_context *);
    222 
    223 void nvc0_tfb_validate(struct nvc0_context *);
    224 
    225 /* nvc0_state.c */
    226 extern void nvc0_init_state_functions(struct nvc0_context *);
    227 
    228 /* nvc0_state_validate.c */
    229 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
    230                                    unsigned space_words);
    231 
    232 /* nvc0_surface.c */
    233 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
    234                        const union pipe_color_union *color,
    235                        double depth, unsigned stencil);
    236 extern void nvc0_init_surface_functions(struct nvc0_context *);
    237 
    238 /* nvc0_tex.c */
    239 void nvc0_validate_textures(struct nvc0_context *);
    240 void nvc0_validate_samplers(struct nvc0_context *);
    241 void nve4_set_tex_handles(struct nvc0_context *);
    242 
    243 struct pipe_sampler_view *
    244 nvc0_create_sampler_view(struct pipe_context *,
    245                          struct pipe_resource *,
    246                          const struct pipe_sampler_view *);
    247 
    248 /* nvc0_transfer.c */
    249 void
    250 nvc0_init_transfer_functions(struct nvc0_context *);
    251 
    252 void
    253 nvc0_m2mf_push_linear(struct nouveau_context *nv,
    254                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
    255                       unsigned size, const void *data);
    256 void
    257 nve4_p2mf_push_linear(struct nouveau_context *nv,
    258                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
    259                       unsigned size, const void *data);
    260 void
    261 nvc0_cb_push(struct nouveau_context *,
    262              struct nouveau_bo *bo, unsigned domain,
    263              unsigned base, unsigned size,
    264              unsigned offset, unsigned words, const uint32_t *data);
    265 
    266 /* nvc0_vbo.c */
    267 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
    268 
    269 void *
    270 nvc0_vertex_state_create(struct pipe_context *pipe,
    271                          unsigned num_elements,
    272                          const struct pipe_vertex_element *elements);
    273 void
    274 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
    275 
    276 void nvc0_vertex_arrays_validate(struct nvc0_context *);
    277 
    278 void nvc0_idxbuf_validate(struct nvc0_context *);
    279 
    280 /* nvc0_push.c */
    281 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
    282 
    283 #endif
    284