Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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. #define NVC0_NEW_SURFACES     (1 << 23)
  59.  
  60. #define NVC0_NEW_CP_PROGRAM   (1 << 0)
  61. #define NVC0_NEW_CP_SURFACES  (1 << 1)
  62. #define NVC0_NEW_CP_TEXTURES  (1 << 2)
  63. #define NVC0_NEW_CP_SAMPLERS  (1 << 3)
  64. #define NVC0_NEW_CP_CONSTBUF  (1 << 4)
  65. #define NVC0_NEW_CP_GLOBALS   (1 << 5)
  66.  
  67. /* 3d bufctx (during draw_vbo, blit_3d) */
  68. #define NVC0_BIND_FB            0
  69. #define NVC0_BIND_VTX           1
  70. #define NVC0_BIND_VTX_TMP       2
  71. #define NVC0_BIND_IDX           3
  72. #define NVC0_BIND_TEX(s, i)  (  4 + 32 * (s) + (i))
  73. #define NVC0_BIND_CB(s, i)   (164 + 16 * (s) + (i))
  74. #define NVC0_BIND_TFB         244
  75. #define NVC0_BIND_SUF         245
  76. #define NVC0_BIND_SCREEN      246
  77. #define NVC0_BIND_TLS         247
  78. #define NVC0_BIND_3D_COUNT    248
  79.  
  80. /* compute bufctx (during launch_grid) */
  81. #define NVC0_BIND_CP_CB(i)     (  0 + (i))
  82. #define NVC0_BIND_CP_TEX(i)    ( 16 + (i))
  83. #define NVC0_BIND_CP_SUF         48
  84. #define NVC0_BIND_CP_GLOBAL      49
  85. #define NVC0_BIND_CP_DESC        50
  86. #define NVC0_BIND_CP_SCREEN      51
  87. #define NVC0_BIND_CP_QUERY       52
  88. #define NVC0_BIND_CP_COUNT       53
  89.  
  90. /* bufctx for other operations */
  91. #define NVC0_BIND_2D            0
  92. #define NVC0_BIND_M2MF          0
  93. #define NVC0_BIND_FENCE         1
  94.  
  95.  
  96. struct nvc0_blitctx;
  97.  
  98. boolean nvc0_blitctx_create(struct nvc0_context *);
  99. void nvc0_blitctx_destroy(struct nvc0_context *);
  100.  
  101. struct nvc0_context {
  102.    struct nouveau_context base;
  103.  
  104.    struct nouveau_bufctx *bufctx_3d;
  105.    struct nouveau_bufctx *bufctx;
  106.    struct nouveau_bufctx *bufctx_cp;
  107.  
  108.    struct nvc0_screen *screen;
  109.  
  110.    void (*m2mf_copy_rect)(struct nvc0_context *,
  111.                           const struct nv50_m2mf_rect *dst,
  112.                           const struct nv50_m2mf_rect *src,
  113.                           uint32_t nblocksx, uint32_t nblocksy);
  114.  
  115.    uint32_t dirty;
  116.    uint32_t dirty_cp; /* dirty flags for compute state */
  117.  
  118.    struct {
  119.       boolean flushed;
  120.       boolean rasterizer_discard;
  121.       boolean early_z_forced;
  122.       boolean prim_restart;
  123.       uint32_t instance_elts; /* bitmask of per-instance elements */
  124.       uint32_t instance_base;
  125.       uint32_t constant_vbos;
  126.       uint32_t constant_elts;
  127.       int32_t index_bias;
  128.       uint16_t scissor;
  129.       uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
  130.       uint8_t num_vtxbufs;
  131.       uint8_t num_vtxelts;
  132.       uint8_t num_textures[6];
  133.       uint8_t num_samplers[6];
  134.       uint8_t tls_required; /* bitmask of shader types using l[] */
  135.       uint8_t c14_bound; /* whether immediate array constbuf is bound */
  136.       uint8_t clip_enable;
  137.       uint32_t clip_mode;
  138.       uint32_t uniform_buffer_bound[5];
  139.       struct nvc0_transform_feedback_state *tfb;
  140.    } state;
  141.  
  142.    struct nvc0_blend_stateobj *blend;
  143.    struct nvc0_rasterizer_stateobj *rast;
  144.    struct nvc0_zsa_stateobj *zsa;
  145.    struct nvc0_vertex_stateobj *vertex;
  146.  
  147.    struct nvc0_program *vertprog;
  148.    struct nvc0_program *tctlprog;
  149.    struct nvc0_program *tevlprog;
  150.    struct nvc0_program *gmtyprog;
  151.    struct nvc0_program *fragprog;
  152.    struct nvc0_program *compprog;
  153.  
  154.    struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];
  155.    uint16_t constbuf_dirty[6];
  156.  
  157.    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
  158.    unsigned num_vtxbufs;
  159.    struct pipe_index_buffer idxbuf;
  160.    uint32_t constant_vbos;
  161.    uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
  162.    uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
  163.    uint32_t vb_elt_limit; /* max - min element (count - 1) */
  164.    uint32_t instance_off; /* current base vertex for instanced arrays */
  165.    uint32_t instance_max; /* last instance for current draw call */
  166.  
  167.    struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];
  168.    unsigned num_textures[6];
  169.    uint32_t textures_dirty[6];
  170.    struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];
  171.    unsigned num_samplers[6];
  172.    uint16_t samplers_dirty[6];
  173.  
  174.    uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */
  175.  
  176.    struct pipe_framebuffer_state framebuffer;
  177.    struct pipe_blend_color blend_colour;
  178.    struct pipe_stencil_ref stencil_ref;
  179.    struct pipe_poly_stipple stipple;
  180.    struct pipe_scissor_state scissor;
  181.    struct pipe_viewport_state viewport;
  182.    struct pipe_clip_state clip;
  183.  
  184.    unsigned sample_mask;
  185.  
  186.    boolean vbo_push_hint;
  187.  
  188.    uint8_t tfbbuf_dirty;
  189.    struct pipe_stream_output_target *tfbbuf[4];
  190.    unsigned num_tfbbufs;
  191.  
  192.    struct pipe_query *cond_query;
  193.    boolean cond_cond;
  194.    uint cond_mode;
  195.  
  196.    struct nvc0_blitctx *blit;
  197.  
  198.    struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];
  199.    uint16_t surfaces_dirty[2];
  200.    uint16_t surfaces_valid[2];
  201.    uint32_t vport_int[2];
  202.  
  203.    struct util_dynarray global_residents;
  204.  
  205. #ifdef NVC0_WITH_DRAW_MODULE
  206.    struct draw_context *draw;
  207. #endif
  208. };
  209.  
  210. static INLINE struct nvc0_context *
  211. nvc0_context(struct pipe_context *pipe)
  212. {
  213.    return (struct nvc0_context *)pipe;
  214. }
  215.  
  216. static INLINE unsigned
  217. nvc0_shader_stage(unsigned pipe)
  218. {
  219.    switch (pipe) {
  220.    case PIPE_SHADER_VERTEX: return 0;
  221. /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
  222. /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
  223.    case PIPE_SHADER_GEOMETRY: return 3;
  224.    case PIPE_SHADER_FRAGMENT: return 4;
  225.    case PIPE_SHADER_COMPUTE: return 5;
  226.    default:
  227.       assert(!"invalid PIPE_SHADER type");
  228.       return 0;
  229.    }
  230. }
  231.  
  232.  
  233. /* nvc0_context.c */
  234. struct pipe_context *nvc0_create(struct pipe_screen *, void *);
  235. void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
  236.                        boolean on_flush);
  237. void nvc0_default_kick_notify(struct nouveau_pushbuf *);
  238.  
  239. /* nvc0_draw.c */
  240. extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
  241.  
  242. /* nvc0_program.c */
  243. boolean nvc0_program_translate(struct nvc0_program *, uint16_t chipset);
  244. boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
  245. void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
  246. void nvc0_program_library_upload(struct nvc0_context *);
  247. uint32_t nvc0_program_symbol_offset(const struct nvc0_program *,
  248.                                     uint32_t label);
  249.  
  250. /* nvc0_query.c */
  251. void nvc0_init_query_functions(struct nvc0_context *);
  252. void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
  253.                                struct pipe_query *, unsigned result_offset);
  254. void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
  255. void nvc0_so_target_save_offset(struct pipe_context *,
  256.                                 struct pipe_stream_output_target *, unsigned i,
  257.                                 boolean *serialize);
  258.  
  259. #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
  260.  
  261. /* nvc0_shader_state.c */
  262. void nvc0_vertprog_validate(struct nvc0_context *);
  263. void nvc0_tctlprog_validate(struct nvc0_context *);
  264. void nvc0_tevlprog_validate(struct nvc0_context *);
  265. void nvc0_gmtyprog_validate(struct nvc0_context *);
  266. void nvc0_fragprog_validate(struct nvc0_context *);
  267.  
  268. void nvc0_tfb_validate(struct nvc0_context *);
  269.  
  270. /* nvc0_state.c */
  271. extern void nvc0_init_state_functions(struct nvc0_context *);
  272.  
  273. /* nvc0_state_validate.c */
  274. void nvc0_validate_global_residents(struct nvc0_context *,
  275.                                     struct nouveau_bufctx *, int bin);
  276. extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
  277.                                    unsigned space_words);
  278.  
  279. /* nvc0_surface.c */
  280. extern void nvc0_clear(struct pipe_context *, unsigned buffers,
  281.                        const union pipe_color_union *color,
  282.                        double depth, unsigned stencil);
  283. extern void nvc0_init_surface_functions(struct nvc0_context *);
  284.  
  285. /* nvc0_tex.c */
  286. boolean nve4_validate_tsc(struct nvc0_context *nvc0, int s);
  287. void nvc0_validate_textures(struct nvc0_context *);
  288. void nvc0_validate_samplers(struct nvc0_context *);
  289. void nve4_set_tex_handles(struct nvc0_context *);
  290. void nvc0_validate_surfaces(struct nvc0_context *);
  291. void nve4_set_surface_info(struct nouveau_pushbuf *, struct pipe_surface *,
  292.                            struct nvc0_screen *);
  293.  
  294. struct pipe_sampler_view *
  295. nvc0_create_texture_view(struct pipe_context *,
  296.                          struct pipe_resource *,
  297.                          const struct pipe_sampler_view *,
  298.                          uint32_t flags,
  299.                          enum pipe_texture_target);
  300. struct pipe_sampler_view *
  301. nvc0_create_sampler_view(struct pipe_context *,
  302.                          struct pipe_resource *,
  303.                          const struct pipe_sampler_view *);
  304.  
  305. /* nvc0_transfer.c */
  306. void
  307. nvc0_init_transfer_functions(struct nvc0_context *);
  308.  
  309. void
  310. nvc0_m2mf_push_linear(struct nouveau_context *nv,
  311.                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
  312.                       unsigned size, const void *data);
  313. void
  314. nve4_p2mf_push_linear(struct nouveau_context *nv,
  315.                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
  316.                       unsigned size, const void *data);
  317. void
  318. nvc0_cb_push(struct nouveau_context *,
  319.              struct nouveau_bo *bo, unsigned domain,
  320.              unsigned base, unsigned size,
  321.              unsigned offset, unsigned words, const uint32_t *data);
  322.  
  323. /* nvc0_vbo.c */
  324. void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
  325.  
  326. void *
  327. nvc0_vertex_state_create(struct pipe_context *pipe,
  328.                          unsigned num_elements,
  329.                          const struct pipe_vertex_element *elements);
  330. void
  331. nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
  332.  
  333. void nvc0_vertex_arrays_validate(struct nvc0_context *);
  334.  
  335. void nvc0_idxbuf_validate(struct nvc0_context *);
  336.  
  337. /* nvc0_video.c */
  338. struct pipe_video_decoder *
  339. nvc0_create_decoder(struct pipe_context *context,
  340.                     enum pipe_video_profile profile,
  341.                     enum pipe_video_entrypoint entrypoint,
  342.                     enum pipe_video_chroma_format chroma_format,
  343.                     unsigned width, unsigned height,
  344.                     unsigned max_references,
  345.                     bool expect_chunked_decode);
  346.  
  347. struct pipe_video_buffer *
  348. nvc0_video_buffer_create(struct pipe_context *pipe,
  349.                          const struct pipe_video_buffer *templat);
  350.  
  351. int
  352. nvc0_screen_get_video_param(struct pipe_screen *pscreen,
  353.                             enum pipe_video_profile profile,
  354.                             enum pipe_video_cap param);
  355.  
  356. /* nvc0_push.c */
  357. void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
  358.  
  359. /* nve4_compute.c */
  360. void nve4_launch_grid(struct pipe_context *,
  361.                       const uint *, const uint *, uint32_t, const void *);
  362.  
  363. #endif
  364.