Home | History | Annotate | Download | only in nv50
      1 #ifndef __NV50_CONTEXT_H__
      2 #define __NV50_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 NV50_WITH_DRAW_MODULE
     14 #include "draw/draw_vertex.h"
     15 #endif
     16 
     17 #include "nv50_debug.h"
     18 #include "nv50_winsys.h"
     19 #include "nv50_stateobj.h"
     20 #include "nv50_screen.h"
     21 #include "nv50_program.h"
     22 #include "nv50_resource.h"
     23 #include "nv50_transfer.h"
     24 
     25 #include "nouveau/nouveau_context.h"
     26 #include "nouveau/nv_object.xml.h"
     27 #include "nouveau/nv_m2mf.xml.h"
     28 #include "nv50_3ddefs.xml.h"
     29 #include "nv50_3d.xml.h"
     30 #include "nv50_2d.xml.h"
     31 
     32 #define NV50_NEW_BLEND        (1 << 0)
     33 #define NV50_NEW_RASTERIZER   (1 << 1)
     34 #define NV50_NEW_ZSA          (1 << 2)
     35 #define NV50_NEW_VERTPROG     (1 << 3)
     36 #define NV50_NEW_GMTYPROG     (1 << 6)
     37 #define NV50_NEW_FRAGPROG     (1 << 7)
     38 #define NV50_NEW_BLEND_COLOUR (1 << 8)
     39 #define NV50_NEW_STENCIL_REF  (1 << 9)
     40 #define NV50_NEW_CLIP         (1 << 10)
     41 #define NV50_NEW_SAMPLE_MASK  (1 << 11)
     42 #define NV50_NEW_FRAMEBUFFER  (1 << 12)
     43 #define NV50_NEW_STIPPLE      (1 << 13)
     44 #define NV50_NEW_SCISSOR      (1 << 14)
     45 #define NV50_NEW_VIEWPORT     (1 << 15)
     46 #define NV50_NEW_ARRAYS       (1 << 16)
     47 #define NV50_NEW_VERTEX       (1 << 17)
     48 #define NV50_NEW_CONSTBUF     (1 << 18)
     49 #define NV50_NEW_TEXTURES     (1 << 19)
     50 #define NV50_NEW_SAMPLERS     (1 << 20)
     51 #define NV50_NEW_STRMOUT      (1 << 21)
     52 #define NV50_NEW_CONTEXT      (1 << 31)
     53 
     54 #define NV50_BIND_FB          0
     55 #define NV50_BIND_VERTEX      1
     56 #define NV50_BIND_VERTEX_TMP  2
     57 #define NV50_BIND_INDEX       3
     58 #define NV50_BIND_TEXTURES    4
     59 #define NV50_BIND_CB(s, i)   (5 + 16 * (s) + (i))
     60 #define NV50_BIND_SO         53
     61 #define NV50_BIND_SCREEN     54
     62 #define NV50_BIND_TLS        55
     63 #define NV50_BIND_COUNT      56
     64 #define NV50_BIND_2D          0
     65 #define NV50_BIND_M2MF        0
     66 #define NV50_BIND_FENCE       1
     67 
     68 #define NV50_CB_TMP 123
     69 /* fixed constant buffer binding points - low indices for user's constbufs */
     70 #define NV50_CB_PVP 124
     71 #define NV50_CB_PGP 126
     72 #define NV50_CB_PFP 125
     73 #define NV50_CB_AUX 127
     74 
     75 
     76 struct nv50_context {
     77    struct nouveau_context base;
     78 
     79    struct nv50_screen *screen;
     80 
     81    struct nouveau_bufctx *bufctx_3d;
     82    struct nouveau_bufctx *bufctx;
     83 
     84    uint32_t dirty;
     85 
     86    struct {
     87       uint32_t instance_elts; /* bitmask of per-instance elements */
     88       uint32_t instance_base;
     89       uint32_t interpolant_ctrl;
     90       uint32_t semantic_color;
     91       uint32_t semantic_psize;
     92       int32_t index_bias;
     93       boolean uniform_buffer_bound[3];
     94       boolean prim_restart;
     95       boolean point_sprite;
     96       boolean rt_serialize;
     97       boolean flushed;
     98       boolean rasterizer_discard;
     99       uint8_t tls_required;
    100       boolean new_tls_space;
    101       uint8_t num_vtxbufs;
    102       uint8_t num_vtxelts;
    103       uint8_t num_textures[3];
    104       uint8_t num_samplers[3];
    105       uint8_t prim_size;
    106       uint16_t scissor;
    107    } state;
    108 
    109    struct nv50_blend_stateobj *blend;
    110    struct nv50_rasterizer_stateobj *rast;
    111    struct nv50_zsa_stateobj *zsa;
    112    struct nv50_vertex_stateobj *vertex;
    113 
    114    struct nv50_program *vertprog;
    115    struct nv50_program *gmtyprog;
    116    struct nv50_program *fragprog;
    117 
    118    struct nv50_constbuf constbuf[3][NV50_MAX_PIPE_CONSTBUFS];
    119    uint16_t constbuf_dirty[3];
    120    uint16_t constbuf_valid[3];
    121 
    122    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
    123    unsigned num_vtxbufs;
    124    struct pipe_index_buffer idxbuf;
    125    uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
    126    uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
    127    uint32_t vbo_constant; /* bitmask of user buffers with stride 0 */
    128    uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
    129    uint32_t vb_elt_limit; /* max - min element (count - 1) */
    130    uint32_t instance_off; /* base vertex for instanced arrays */
    131    uint32_t instance_max; /* max instance for current draw call */
    132 
    133    struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
    134    unsigned num_textures[3];
    135    struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
    136    unsigned num_samplers[3];
    137 
    138    uint8_t num_so_targets;
    139    uint8_t so_targets_dirty;
    140    struct pipe_stream_output_target *so_target[4];
    141 
    142    struct pipe_framebuffer_state framebuffer;
    143    struct pipe_blend_color blend_colour;
    144    struct pipe_stencil_ref stencil_ref;
    145    struct pipe_poly_stipple stipple;
    146    struct pipe_scissor_state scissor;
    147    struct pipe_viewport_state viewport;
    148    struct pipe_clip_state clip;
    149 
    150    unsigned sample_mask;
    151 
    152    boolean vbo_push_hint;
    153 
    154 #ifdef NV50_WITH_DRAW_MODULE
    155    struct draw_context *draw;
    156 #endif
    157 };
    158 
    159 static INLINE struct nv50_context *
    160 nv50_context(struct pipe_context *pipe)
    161 {
    162    return (struct nv50_context *)pipe;
    163 }
    164 
    165 static INLINE struct nv50_screen *
    166 nv50_context_screen(struct nv50_context *nv50)
    167 {
    168    return nv50_screen(&nv50->base.screen->base);
    169 }
    170 
    171 /* return index used in nv50_context arrays for a specific shader type */
    172 static INLINE unsigned
    173 nv50_context_shader_stage(unsigned pipe)
    174 {
    175    switch (pipe) {
    176    case PIPE_SHADER_VERTEX: return 0;
    177    case PIPE_SHADER_FRAGMENT: return 1;
    178    case PIPE_SHADER_GEOMETRY: return 2;
    179    case PIPE_SHADER_COMPUTE: return 3;
    180    default:
    181       assert(!"invalid/unhandled shader type");
    182       return 0;
    183    }
    184 }
    185 
    186 /* nv50_context.c */
    187 struct pipe_context *nv50_create(struct pipe_screen *, void *);
    188 
    189 void nv50_bufctx_fence(struct nouveau_bufctx *, boolean on_flush);
    190 
    191 void nv50_default_kick_notify(struct nouveau_pushbuf *);
    192 
    193 /* nv50_draw.c */
    194 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
    195 
    196 /* nv50_query.c */
    197 void nv50_init_query_functions(struct nv50_context *);
    198 void nv50_query_pushbuf_submit(struct nouveau_pushbuf *,
    199                                struct pipe_query *, unsigned result_offset);
    200 void nv84_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
    201 void nva0_so_target_save_offset(struct pipe_context *,
    202                                 struct pipe_stream_output_target *,
    203                                 unsigned index, boolean seralize);
    204 
    205 #define NVA0_QUERY_STREAM_OUTPUT_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
    206 
    207 /* nv50_shader_state.c */
    208 void nv50_vertprog_validate(struct nv50_context *);
    209 void nv50_gmtyprog_validate(struct nv50_context *);
    210 void nv50_fragprog_validate(struct nv50_context *);
    211 void nv50_fp_linkage_validate(struct nv50_context *);
    212 void nv50_gp_linkage_validate(struct nv50_context *);
    213 void nv50_constbufs_validate(struct nv50_context *);
    214 void nv50_validate_derived_rs(struct nv50_context *);
    215 void nv50_stream_output_validate(struct nv50_context *);
    216 
    217 /* nv50_state.c */
    218 extern void nv50_init_state_functions(struct nv50_context *);
    219 
    220 /* nv50_state_validate.c */
    221 /* @words: check for space before emitting relocs */
    222 extern boolean nv50_state_validate(struct nv50_context *, uint32_t state_mask,
    223                                    unsigned space_words);
    224 
    225 /* nv50_surface.c */
    226 extern void nv50_clear(struct pipe_context *, unsigned buffers,
    227                        const union pipe_color_union *color,
    228                        double depth, unsigned stencil);
    229 extern void nv50_init_surface_functions(struct nv50_context *);
    230 
    231 /* nv50_tex.c */
    232 void nv50_validate_textures(struct nv50_context *);
    233 void nv50_validate_samplers(struct nv50_context *);
    234 
    235 struct pipe_sampler_view *
    236 nv50_create_sampler_view(struct pipe_context *,
    237                          struct pipe_resource *,
    238                          const struct pipe_sampler_view *);
    239 
    240 /* nv50_transfer.c */
    241 void
    242 nv50_m2mf_transfer_rect(struct nv50_context *,
    243                         const struct nv50_m2mf_rect *dst,
    244                         const struct nv50_m2mf_rect *src,
    245                         uint32_t nblocksx, uint32_t nblocksy);
    246 void
    247 nv50_sifc_linear_u8(struct nouveau_context *pipe,
    248                     struct nouveau_bo *dst, unsigned offset, unsigned domain,
    249                     unsigned size, const void *data);
    250 void
    251 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
    252                       struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
    253                       struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
    254                       unsigned size);
    255 void
    256 nv50_cb_push(struct nouveau_context *nv,
    257              struct nouveau_bo *bo, unsigned domain,
    258              unsigned base, unsigned size,
    259              unsigned offset, unsigned words, const uint32_t *data);
    260 
    261 /* nv50_vbo.c */
    262 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
    263 
    264 void *
    265 nv50_vertex_state_create(struct pipe_context *pipe,
    266                          unsigned num_elements,
    267                          const struct pipe_vertex_element *elements);
    268 void
    269 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
    270 
    271 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
    272 
    273 /* nv50_push.c */
    274 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
    275 
    276 #endif
    277