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. #include "nvc0/nvc0_winsys.h"
  14. #include "nvc0/nvc0_stateobj.h"
  15. #include "nvc0/nvc0_screen.h"
  16. #include "nvc0/nvc0_program.h"
  17. #include "nvc0/nvc0_resource.h"
  18.  
  19. #include "nv50/nv50_transfer.h"
  20.  
  21. #include "nouveau_context.h"
  22. #include "nouveau_debug.h"
  23.  
  24. #include "nv50/nv50_3ddefs.xml.h"
  25. #include "nvc0/nvc0_3d.xml.h"
  26. #include "nv50/nv50_2d.xml.h"
  27. #include "nvc0/nvc0_m2mf.xml.h"
  28. #include "nvc0/nve4_p2mf.xml.h"
  29. #include "nvc0/nvc0_macros.h"
  30.  
  31. /* NOTE: must keep NVC0_NEW_...PROG in consecutive bits in this order */
  32. #define NVC0_NEW_BLEND        (1 << 0)
  33. #define NVC0_NEW_RASTERIZER   (1 << 1)
  34. #define NVC0_NEW_ZSA          (1 << 2)
  35. #define NVC0_NEW_VERTPROG     (1 << 3)
  36. #define NVC0_NEW_TCTLPROG     (1 << 4)
  37. #define NVC0_NEW_TEVLPROG     (1 << 5)
  38. #define NVC0_NEW_GMTYPROG     (1 << 6)
  39. #define NVC0_NEW_FRAGPROG     (1 << 7)
  40. #define NVC0_NEW_BLEND_COLOUR (1 << 8)
  41. #define NVC0_NEW_STENCIL_REF  (1 << 9)
  42. #define NVC0_NEW_CLIP         (1 << 10)
  43. #define NVC0_NEW_SAMPLE_MASK  (1 << 11)
  44. #define NVC0_NEW_FRAMEBUFFER  (1 << 12)
  45. #define NVC0_NEW_STIPPLE      (1 << 13)
  46. #define NVC0_NEW_SCISSOR      (1 << 14)
  47. #define NVC0_NEW_VIEWPORT     (1 << 15)
  48. #define NVC0_NEW_ARRAYS       (1 << 16)
  49. #define NVC0_NEW_VERTEX       (1 << 17)
  50. #define NVC0_NEW_CONSTBUF     (1 << 18)
  51. #define NVC0_NEW_TEXTURES     (1 << 19)
  52. #define NVC0_NEW_SAMPLERS     (1 << 20)
  53. #define NVC0_NEW_TFB_TARGETS  (1 << 21)
  54. #define NVC0_NEW_IDXBUF       (1 << 22)
  55. #define NVC0_NEW_SURFACES     (1 << 23)
  56. #define NVC0_NEW_MIN_SAMPLES  (1 << 24)
  57.  
  58. #define NVC0_NEW_CP_PROGRAM   (1 << 0)
  59. #define NVC0_NEW_CP_SURFACES  (1 << 1)
  60. #define NVC0_NEW_CP_TEXTURES  (1 << 2)
  61. #define NVC0_NEW_CP_SAMPLERS  (1 << 3)
  62. #define NVC0_NEW_CP_CONSTBUF  (1 << 4)
  63. #define NVC0_NEW_CP_GLOBALS   (1 << 5)
  64.  
  65. /* 3d bufctx (during draw_vbo, blit_3d) */
  66. #define NVC0_BIND_FB            0
  67. #define NVC0_BIND_VTX           1
  68. #define NVC0_BIND_VTX_TMP       2
  69. #define NVC0_BIND_IDX           3
  70. #define NVC0_BIND_TEX(s, i)  (  4 + 32 * (s) + (i))
  71. #define NVC0_BIND_CB(s, i)   (164 + 16 * (s) + (i))
  72. #define NVC0_BIND_TFB         244
  73. #define NVC0_BIND_SUF         245
  74. #define NVC0_BIND_SCREEN      246
  75. #define NVC0_BIND_TLS         247
  76. #define NVC0_BIND_3D_COUNT    248
  77.  
  78. /* compute bufctx (during launch_grid) */
  79. #define NVC0_BIND_CP_CB(i)     (  0 + (i))
  80. #define NVC0_BIND_CP_TEX(i)    ( 16 + (i))
  81. #define NVC0_BIND_CP_SUF         48
  82. #define NVC0_BIND_CP_GLOBAL      49
  83. #define NVC0_BIND_CP_DESC        50
  84. #define NVC0_BIND_CP_SCREEN      51
  85. #define NVC0_BIND_CP_QUERY       52
  86. #define NVC0_BIND_CP_COUNT       53
  87.  
  88. /* bufctx for other operations */
  89. #define NVC0_BIND_2D            0
  90. #define NVC0_BIND_M2MF          0
  91. #define NVC0_BIND_FENCE         1
  92.  
  93.  
  94. struct nvc0_blitctx;
  95.  
  96. boolean nvc0_blitctx_create(struct nvc0_context *);
  97. void nvc0_blitctx_destroy(struct nvc0_context *);
  98.  
  99. struct nvc0_context {
  100.    struct nouveau_context base;
  101.  
  102.    struct nouveau_bufctx *bufctx_3d;
  103.    struct nouveau_bufctx *bufctx;
  104.    struct nouveau_bufctx *bufctx_cp;
  105.  
  106.    struct nvc0_screen *screen;
  107.  
  108.    void (*m2mf_copy_rect)(struct nvc0_context *,
  109.                           const struct nv50_m2mf_rect *dst,
  110.                           const struct nv50_m2mf_rect *src,
  111.                           uint32_t nblocksx, uint32_t nblocksy);
  112.  
  113.    uint32_t dirty;
  114.    uint32_t dirty_cp; /* dirty flags for compute state */
  115.  
  116.    struct nvc0_graph_state state;
  117.  
  118.    struct nvc0_blend_stateobj *blend;
  119.    struct nvc0_rasterizer_stateobj *rast;
  120.    struct nvc0_zsa_stateobj *zsa;
  121.    struct nvc0_vertex_stateobj *vertex;
  122.  
  123.    struct nvc0_program *vertprog;
  124.    struct nvc0_program *tctlprog;
  125.    struct nvc0_program *tevlprog;
  126.    struct nvc0_program *gmtyprog;
  127.    struct nvc0_program *fragprog;
  128.    struct nvc0_program *compprog;
  129.  
  130.    struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];
  131.    uint16_t constbuf_dirty[6];
  132.    uint16_t constbuf_valid[6];
  133.    boolean cb_dirty;
  134.  
  135.    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
  136.    unsigned num_vtxbufs;
  137.    struct pipe_index_buffer idxbuf;
  138.    uint32_t constant_vbos;
  139.    uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
  140.    uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
  141.    uint32_t vb_elt_limit; /* max - min element (count - 1) */
  142.    uint32_t instance_off; /* current base vertex for instanced arrays */
  143.    uint32_t instance_max; /* last instance for current draw call */
  144.  
  145.    struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];
  146.    unsigned num_textures[6];
  147.    uint32_t textures_dirty[6];
  148.    struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];
  149.    unsigned num_samplers[6];
  150.    uint16_t samplers_dirty[6];
  151.  
  152.    uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */
  153.  
  154.    struct pipe_framebuffer_state framebuffer;
  155.    struct pipe_blend_color blend_colour;
  156.    struct pipe_stencil_ref stencil_ref;
  157.    struct pipe_poly_stipple stipple;
  158.    struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS];
  159.    unsigned scissors_dirty;
  160.    struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
  161.    unsigned viewports_dirty;
  162.    struct pipe_clip_state clip;
  163.  
  164.    unsigned sample_mask;
  165.    unsigned min_samples;
  166.  
  167.    boolean vbo_push_hint;
  168.  
  169.    uint8_t tfbbuf_dirty;
  170.    struct pipe_stream_output_target *tfbbuf[4];
  171.    unsigned num_tfbbufs;
  172.  
  173.    struct pipe_query *cond_query;
  174.    boolean cond_cond; /* inverted rendering condition */
  175.    uint cond_mode;
  176.    uint32_t cond_condmode; /* the calculated condition */
  177.  
  178.    struct nvc0_blitctx *blit;
  179.  
  180.    struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];
  181.    uint16_t surfaces_dirty[2];
  182.    uint16_t surfaces_valid[2];
  183.  
  184.    struct util_dynarray global_residents;
  185. };
  186.  
  187. static INLINE struct nvc0_context *
  188. nvc0_context(struct pipe_context *pipe)
  189. {
  190.    return (struct nvc0_context *)pipe;
  191. }
  192.  
  193. static INLINE unsigned
  194. nvc0_shader_stage(unsigned pipe)
  195. {
  196.    switch (pipe) {
  197.    case PIPE_SHADER_VERTEX: return 0;
  198. /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
  199. /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
  200.    case PIPE_SHADER_GEOMETRY: return 3;
  201.    case PIPE_SHADER_FRAGMENT: return 4;
  202.    case PIPE_SHADER_COMPUTE: return 5;
  203.    default:
  204.       assert(!"invalid PIPE_SHADER type");
  205.       return 0;
  206.    }
  207. }
  208.  
  209.  
  210. /* nvc0_context.c */
  211. struct pipe_context *nvc0_create(struct pipe_screen *, void *);
  212. void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
  213.                        boolean on_flush);
  214. void nvc0_default_kick_notify(struct nouveau_pushbuf *);
  215.  
  216. /* nvc0_draw.c */
  217. extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
  218.  
  219. /* nvc0_program.c */
  220. boolean nvc0_program_translate(struct nvc0_program *, uint16_t chipset);
  221. boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
  222. void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
  223. void nvc0_program_library_upload(struct nvc0_context *);
  224. uint32_t nvc0_program_symbol_offset(const struct nvc0_program *,
  225.                                     uint32_t label);
  226.  
  227. /* nvc0_query.c */
  228. void nvc0_init_query_functions(struct nvc0_context *);
  229. void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
  230.                                struct pipe_query *, unsigned result_offset);
  231. void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
  232. void nvc0_so_target_save_offset(struct pipe_context *,
  233.                                 struct pipe_stream_output_target *, unsigned i,
  234.                                 boolean *serialize);
  235.  
  236. #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
  237.  
  238. /* nvc0_shader_state.c */
  239. void nvc0_vertprog_validate(struct nvc0_context *);
  240. void nvc0_tctlprog_validate(struct nvc0_context *);
  241. void nvc0_tevlprog_validate(struct nvc0_context *);
  242. void nvc0_gmtyprog_validate(struct nvc0_context *);
  243. void nvc0_fragprog_validate(struct nvc0_context *);
  244.  
  245. void nvc0_tfb_validate(struct nvc0_context *);
  246.  
  247. /* nvc0_state.c */
  248. extern void nvc0_init_state_functions(struct nvc0_context *);
  249.  
  250. /* nvc0_state_validate.c */
  251. void nvc0_validate_global_residents(struct nvc0_context *,
  252.                                     struct nouveau_bufctx *, int bin);
  253. extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
  254.                                    unsigned space_words);
  255.  
  256. /* nvc0_surface.c */
  257. extern void nvc0_clear(struct pipe_context *, unsigned buffers,
  258.                        const union pipe_color_union *color,
  259.                        double depth, unsigned stencil);
  260. extern void nvc0_init_surface_functions(struct nvc0_context *);
  261.  
  262. /* nvc0_tex.c */
  263. boolean nve4_validate_tsc(struct nvc0_context *nvc0, int s);
  264. void nvc0_validate_textures(struct nvc0_context *);
  265. void nvc0_validate_samplers(struct nvc0_context *);
  266. void nve4_set_tex_handles(struct nvc0_context *);
  267. void nvc0_validate_surfaces(struct nvc0_context *);
  268. void nve4_set_surface_info(struct nouveau_pushbuf *, struct pipe_surface *,
  269.                            struct nvc0_screen *);
  270.  
  271. struct pipe_sampler_view *
  272. nvc0_create_texture_view(struct pipe_context *,
  273.                          struct pipe_resource *,
  274.                          const struct pipe_sampler_view *,
  275.                          uint32_t flags,
  276.                          enum pipe_texture_target);
  277. struct pipe_sampler_view *
  278. nvc0_create_sampler_view(struct pipe_context *,
  279.                          struct pipe_resource *,
  280.                          const struct pipe_sampler_view *);
  281.  
  282. /* nvc0_transfer.c */
  283. void
  284. nvc0_init_transfer_functions(struct nvc0_context *);
  285.  
  286. void
  287. nvc0_m2mf_push_linear(struct nouveau_context *nv,
  288.                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
  289.                       unsigned size, const void *data);
  290. void
  291. nve4_p2mf_push_linear(struct nouveau_context *nv,
  292.                       struct nouveau_bo *dst, unsigned offset, unsigned domain,
  293.                       unsigned size, const void *data);
  294. void
  295. nvc0_cb_push(struct nouveau_context *,
  296.              struct nouveau_bo *bo, unsigned domain,
  297.              unsigned base, unsigned size,
  298.              unsigned offset, unsigned words, const uint32_t *data);
  299.  
  300. /* nvc0_vbo.c */
  301. void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
  302.  
  303. void *
  304. nvc0_vertex_state_create(struct pipe_context *pipe,
  305.                          unsigned num_elements,
  306.                          const struct pipe_vertex_element *elements);
  307. void
  308. nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
  309.  
  310. void nvc0_vertex_arrays_validate(struct nvc0_context *);
  311.  
  312. void nvc0_idxbuf_validate(struct nvc0_context *);
  313.  
  314. /* nvc0_video.c */
  315. struct pipe_video_codec *
  316. nvc0_create_decoder(struct pipe_context *context,
  317.                     const struct pipe_video_codec *templ);
  318.  
  319. struct pipe_video_buffer *
  320. nvc0_video_buffer_create(struct pipe_context *pipe,
  321.                          const struct pipe_video_buffer *templat);
  322.  
  323. /* nvc0_push.c */
  324. void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
  325.  
  326. /* nve4_compute.c */
  327. void nve4_launch_grid(struct pipe_context *,
  328.                       const uint *, const uint *, uint32_t, const void *);
  329.  
  330. /* nvc0_compute.c */
  331. void nvc0_launch_grid(struct pipe_context *,
  332.                       const uint *, const uint *, uint32_t, const void *);
  333.  
  334. #endif
  335.