Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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. #include "nv50/nv50_winsys.h"
  14. #include "nv50/nv50_stateobj.h"
  15. #include "nv50/nv50_screen.h"
  16. #include "nv50/nv50_program.h"
  17. #include "nv50/nv50_resource.h"
  18. #include "nv50/nv50_transfer.h"
  19.  
  20. #include "nouveau_context.h"
  21. #include "nouveau_debug.h"
  22. #include "nv_object.xml.h"
  23. #include "nv_m2mf.xml.h"
  24. #include "nv50/nv50_3ddefs.xml.h"
  25. #include "nv50/nv50_3d.xml.h"
  26. #include "nv50/nv50_2d.xml.h"
  27.  
  28. #define NV50_NEW_BLEND        (1 << 0)
  29. #define NV50_NEW_RASTERIZER   (1 << 1)
  30. #define NV50_NEW_ZSA          (1 << 2)
  31. #define NV50_NEW_VERTPROG     (1 << 3)
  32. #define NV50_NEW_GMTYPROG     (1 << 6)
  33. #define NV50_NEW_FRAGPROG     (1 << 7)
  34. #define NV50_NEW_BLEND_COLOUR (1 << 8)
  35. #define NV50_NEW_STENCIL_REF  (1 << 9)
  36. #define NV50_NEW_CLIP         (1 << 10)
  37. #define NV50_NEW_SAMPLE_MASK  (1 << 11)
  38. #define NV50_NEW_FRAMEBUFFER  (1 << 12)
  39. #define NV50_NEW_STIPPLE      (1 << 13)
  40. #define NV50_NEW_SCISSOR      (1 << 14)
  41. #define NV50_NEW_VIEWPORT     (1 << 15)
  42. #define NV50_NEW_ARRAYS       (1 << 16)
  43. #define NV50_NEW_VERTEX       (1 << 17)
  44. #define NV50_NEW_CONSTBUF     (1 << 18)
  45. #define NV50_NEW_TEXTURES     (1 << 19)
  46. #define NV50_NEW_SAMPLERS     (1 << 20)
  47. #define NV50_NEW_STRMOUT      (1 << 21)
  48. #define NV50_NEW_MIN_SAMPLES  (1 << 22)
  49. #define NV50_NEW_CONTEXT      (1 << 31)
  50.  
  51. #define NV50_BIND_FB          0
  52. #define NV50_BIND_VERTEX      1
  53. #define NV50_BIND_VERTEX_TMP  2
  54. #define NV50_BIND_INDEX       3
  55. #define NV50_BIND_TEXTURES    4
  56. #define NV50_BIND_CB(s, i)   (5 + 16 * (s) + (i))
  57. #define NV50_BIND_SO         53
  58. #define NV50_BIND_SCREEN     54
  59. #define NV50_BIND_TLS        55
  60. #define NV50_BIND_COUNT      56
  61. #define NV50_BIND_2D          0
  62. #define NV50_BIND_M2MF        0
  63. #define NV50_BIND_FENCE       1
  64.  
  65. #define NV50_CB_TMP 123
  66. /* fixed constant buffer binding points - low indices for user's constbufs */
  67. #define NV50_CB_PVP 124
  68. #define NV50_CB_PGP 126
  69. #define NV50_CB_PFP 125
  70. /* constant buffer permanently mapped in as c15[] */
  71. #define NV50_CB_AUX 127
  72. /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
  73. #define NV50_CB_AUX_SIZE          (1 << 16)
  74. /* 8 user clip planes, at 4 32-bit floats each */
  75. #define NV50_CB_AUX_UCP_OFFSET    0x0000
  76. #define NV50_CB_AUX_UCP_SIZE      (8 * 4 * 4)
  77. /* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */
  78. #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
  79. #define NV50_CB_AUX_TEX_MS_SIZE   (16 * 3 * 2 * 4)
  80. /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
  81. #define NV50_CB_AUX_MS_OFFSET     0x200
  82. #define NV50_CB_AUX_MS_SIZE       (4 * 8 * 4 * 2)
  83. /* Sample position pairs for the current output MS level */
  84. #define NV50_CB_AUX_SAMPLE_OFFSET 0x300
  85. #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
  86. /* next spot: 0x340 */
  87. /* 4 32-bit floats for the vertex runout, put at the end */
  88. #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
  89.  
  90.  
  91.  
  92. struct nv50_blitctx;
  93.  
  94. boolean nv50_blitctx_create(struct nv50_context *);
  95.  
  96. struct nv50_context {
  97.    struct nouveau_context base;
  98.  
  99.    struct nv50_screen *screen;
  100.  
  101.    struct nouveau_bufctx *bufctx_3d;
  102.    struct nouveau_bufctx *bufctx;
  103.  
  104.    uint32_t dirty;
  105.    boolean cb_dirty;
  106.  
  107.    struct nv50_graph_state 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 scissors[NV50_MAX_VIEWPORTS];
  147.    unsigned scissors_dirty;
  148.    struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS];
  149.    unsigned viewports_dirty;
  150.    struct pipe_clip_state clip;
  151.  
  152.    unsigned sample_mask;
  153.    unsigned min_samples;
  154.  
  155.    boolean vbo_push_hint;
  156.  
  157.    uint32_t rt_array_mode;
  158.  
  159.    struct pipe_query *cond_query;
  160.    boolean cond_cond; /* inverted rendering condition */
  161.    uint cond_mode;
  162.    uint32_t cond_condmode; /* the calculated condition */
  163.  
  164.    struct nv50_blitctx *blit;
  165. };
  166.  
  167. static INLINE struct nv50_context *
  168. nv50_context(struct pipe_context *pipe)
  169. {
  170.    return (struct nv50_context *)pipe;
  171. }
  172.  
  173. /* return index used in nv50_context arrays for a specific shader type */
  174. static INLINE unsigned
  175. nv50_context_shader_stage(unsigned pipe)
  176. {
  177.    switch (pipe) {
  178.    case PIPE_SHADER_VERTEX: return 0;
  179.    case PIPE_SHADER_FRAGMENT: return 1;
  180.    case PIPE_SHADER_GEOMETRY: return 2;
  181.    case PIPE_SHADER_COMPUTE: return 3;
  182.    default:
  183.       assert(!"invalid/unhandled shader type");
  184.       return 0;
  185.    }
  186. }
  187.  
  188. /* nv50_context.c */
  189. struct pipe_context *nv50_create(struct pipe_screen *, void *);
  190.  
  191. void nv50_bufctx_fence(struct nouveau_bufctx *, boolean on_flush);
  192.  
  193. void nv50_default_kick_notify(struct nouveau_pushbuf *);
  194.  
  195. /* nv50_draw.c */
  196. extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
  197.  
  198. /* nv50_query.c */
  199. void nv50_init_query_functions(struct nv50_context *);
  200. void nv50_query_pushbuf_submit(struct nouveau_pushbuf *,
  201.                                struct pipe_query *, unsigned result_offset);
  202. void nv84_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
  203. void nva0_so_target_save_offset(struct pipe_context *,
  204.                                 struct pipe_stream_output_target *,
  205.                                 unsigned index, boolean seralize);
  206.  
  207. #define NVA0_QUERY_STREAM_OUTPUT_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
  208.  
  209. /* nv50_shader_state.c */
  210. void nv50_vertprog_validate(struct nv50_context *);
  211. void nv50_gmtyprog_validate(struct nv50_context *);
  212. void nv50_fragprog_validate(struct nv50_context *);
  213. void nv50_fp_linkage_validate(struct nv50_context *);
  214. void nv50_gp_linkage_validate(struct nv50_context *);
  215. void nv50_constbufs_validate(struct nv50_context *);
  216. void nv50_validate_derived_rs(struct nv50_context *);
  217. void nv50_stream_output_validate(struct nv50_context *);
  218.  
  219. /* nv50_state.c */
  220. extern void nv50_init_state_functions(struct nv50_context *);
  221.  
  222. /* nv50_state_validate.c */
  223. /* @words: check for space before emitting relocs */
  224. extern boolean nv50_state_validate(struct nv50_context *, uint32_t state_mask,
  225.                                    unsigned space_words);
  226.  
  227. /* nv50_surface.c */
  228. extern void nv50_clear(struct pipe_context *, unsigned buffers,
  229.                        const union pipe_color_union *color,
  230.                        double depth, unsigned stencil);
  231. extern void nv50_init_surface_functions(struct nv50_context *);
  232.  
  233. /* nv50_tex.c */
  234. void nv50_validate_textures(struct nv50_context *);
  235. void nv50_validate_samplers(struct nv50_context *);
  236. void nv50_upload_ms_info(struct nouveau_pushbuf *);
  237.  
  238. struct pipe_sampler_view *
  239. nv50_create_texture_view(struct pipe_context *,
  240.                          struct pipe_resource *,
  241.                          const struct pipe_sampler_view *,
  242.                          uint32_t flags,
  243.                          enum pipe_texture_target);
  244. struct pipe_sampler_view *
  245. nv50_create_sampler_view(struct pipe_context *,
  246.                          struct pipe_resource *,
  247.                          const struct pipe_sampler_view *);
  248.  
  249. /* nv50_transfer.c */
  250. void
  251. nv50_m2mf_transfer_rect(struct nv50_context *,
  252.                         const struct nv50_m2mf_rect *dst,
  253.                         const struct nv50_m2mf_rect *src,
  254.                         uint32_t nblocksx, uint32_t nblocksy);
  255. void
  256. nv50_sifc_linear_u8(struct nouveau_context *pipe,
  257.                     struct nouveau_bo *dst, unsigned offset, unsigned domain,
  258.                     unsigned size, const void *data);
  259. void
  260. nv50_m2mf_copy_linear(struct nouveau_context *pipe,
  261.                       struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
  262.                       struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
  263.                       unsigned size);
  264. void
  265. nv50_cb_push(struct nouveau_context *nv,
  266.              struct nouveau_bo *bo, unsigned domain,
  267.              unsigned base, unsigned size,
  268.              unsigned offset, unsigned words, const uint32_t *data);
  269.  
  270. /* nv50_vbo.c */
  271. void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
  272.  
  273. void *
  274. nv50_vertex_state_create(struct pipe_context *pipe,
  275.                          unsigned num_elements,
  276.                          const struct pipe_vertex_element *elements);
  277. void
  278. nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
  279.  
  280. void nv50_vertex_arrays_validate(struct nv50_context *nv50);
  281.  
  282. /* nv50_push.c */
  283. void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
  284.  
  285. /* nv84_video.c */
  286. struct pipe_video_codec *
  287. nv84_create_decoder(struct pipe_context *context,
  288.                     const struct pipe_video_codec *templ);
  289.  
  290. struct pipe_video_buffer *
  291. nv84_video_buffer_create(struct pipe_context *pipe,
  292.                          const struct pipe_video_buffer *template);
  293.  
  294. int
  295. nv84_screen_get_video_param(struct pipe_screen *pscreen,
  296.                             enum pipe_video_profile profile,
  297.                             enum pipe_video_entrypoint entrypoint,
  298.                             enum pipe_video_cap param);
  299.  
  300. boolean
  301. nv84_screen_video_supported(struct pipe_screen *screen,
  302.                             enum pipe_format format,
  303.                             enum pipe_video_profile profile,
  304.                             enum pipe_video_entrypoint entrypoint);
  305.  
  306. /* nv98_video.c */
  307. struct pipe_video_codec *
  308. nv98_create_decoder(struct pipe_context *context,
  309.                     const struct pipe_video_codec *templ);
  310.  
  311. struct pipe_video_buffer *
  312. nv98_video_buffer_create(struct pipe_context *pipe,
  313.                          const struct pipe_video_buffer *template);
  314.  
  315. #endif
  316.