Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

nvfx_context.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #ifndef __NVFX_CONTEXT_H__
  2. #define __NVFX_CONTEXT_H__
  3. #include <stdio.h>
  4. #include "pipe/p_context.h"
  5. #include "pipe/p_defines.h"
  6. #include "pipe/p_state.h"
  7. #include "pipe/p_compiler.h"
  8. #include "util/u_memory.h"
  9. #include "util/u_math.h"
  10. #include "util/u_inlines.h"
  11. #include "draw/draw_vertex.h"
  12. #include "nouveau/nouveau_winsys.h"
  13. #include "nouveau/nouveau_gldefs.h"
  14. #include "nouveau/nouveau_context.h"
  15. #include "nouveau/nouveau_stateobj.h"
  16. #include "nvfx_state.h"
  17. #define NOUVEAU_ERR(fmt, args...) \
  18. fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
  19. #define NOUVEAU_MSG(fmt, args...) \
  20. fprintf(stderr, "nouveau: "fmt, ##args);
  21. enum nvfx_state_index {
  22. NVFX_STATE_FB = 0,
  23. NVFX_STATE_VIEWPORT = 1,
  24. NVFX_STATE_BLEND = 2,
  25. NVFX_STATE_RAST = 3,
  26. NVFX_STATE_ZSA = 4,
  27. NVFX_STATE_BCOL = 5,
  28. NVFX_STATE_CLIP = 6,
  29. NVFX_STATE_SCISSOR = 7,
  30. NVFX_STATE_STIPPLE = 8,
  31. NVFX_STATE_FRAGPROG = 9,
  32. NVFX_STATE_VERTPROG = 10,
  33. NVFX_STATE_FRAGTEX0 = 11,
  34. NVFX_STATE_FRAGTEX1 = 12,
  35. NVFX_STATE_FRAGTEX2 = 13,
  36. NVFX_STATE_FRAGTEX3 = 14,
  37. NVFX_STATE_FRAGTEX4 = 15,
  38. NVFX_STATE_FRAGTEX5 = 16,
  39. NVFX_STATE_FRAGTEX6 = 17,
  40. NVFX_STATE_FRAGTEX7 = 18,
  41. NVFX_STATE_FRAGTEX8 = 19,
  42. NVFX_STATE_FRAGTEX9 = 20,
  43. NVFX_STATE_FRAGTEX10 = 21,
  44. NVFX_STATE_FRAGTEX11 = 22,
  45. NVFX_STATE_FRAGTEX12 = 23,
  46. NVFX_STATE_FRAGTEX13 = 24,
  47. NVFX_STATE_FRAGTEX14 = 25,
  48. NVFX_STATE_FRAGTEX15 = 26,
  49. NVFX_STATE_VERTTEX0 = 27,
  50. NVFX_STATE_VERTTEX1 = 28,
  51. NVFX_STATE_VERTTEX2 = 29,
  52. NVFX_STATE_VERTTEX3 = 30,
  53. NVFX_STATE_VTXBUF = 31,
  54. NVFX_STATE_VTXFMT = 32,
  55. NVFX_STATE_VTXATTR = 33,
  56. NVFX_STATE_SR = 34,
  57. NVFX_STATE_MAX = 35
  58. };
  59. #include "nvfx_screen.h"
  60. #define NVFX_NEW_BLEND (1 << 0)
  61. #define NVFX_NEW_RAST (1 << 1)
  62. #define NVFX_NEW_ZSA (1 << 2)
  63. #define NVFX_NEW_SAMPLER (1 << 3)
  64. #define NVFX_NEW_FB (1 << 4)
  65. #define NVFX_NEW_STIPPLE (1 << 5)
  66. #define NVFX_NEW_SCISSOR (1 << 6)
  67. #define NVFX_NEW_VIEWPORT (1 << 7)
  68. #define NVFX_NEW_BCOL (1 << 8)
  69. #define NVFX_NEW_VERTPROG (1 << 9)
  70. #define NVFX_NEW_FRAGPROG (1 << 10)
  71. #define NVFX_NEW_ARRAYS (1 << 11)
  72. #define NVFX_NEW_UCP (1 << 12)
  73. #define NVFX_NEW_SR (1 << 13)
  74. struct nvfx_rasterizer_state {
  75. struct pipe_rasterizer_state pipe;
  76. struct nouveau_stateobj *so;
  77. };
  78. struct nvfx_zsa_state {
  79. struct pipe_depth_stencil_alpha_state pipe;
  80. struct nouveau_stateobj *so;
  81. };
  82. struct nvfx_blend_state {
  83. struct pipe_blend_state pipe;
  84. struct nouveau_stateobj *so;
  85. };
  86. struct nvfx_state {
  87. unsigned scissor_enabled;
  88. unsigned stipple_enabled;
  89. unsigned fp_samplers;
  90. uint64_t dirty;
  91. struct nouveau_stateobj *hw[NVFX_STATE_MAX];
  92. };
  93. struct nvfx_vtxelt_state {
  94. struct pipe_vertex_element pipe[16];
  95. unsigned num_elements;
  96. };
  97. struct nvfx_context {
  98. struct pipe_context pipe;
  99. struct nouveau_winsys *nvws;
  100. struct nvfx_screen *screen;
  101. unsigned is_nv4x; /* either 0 or ~0 */
  102. struct draw_context *draw;
  103. /* HW state derived from pipe states */
  104. struct nvfx_state state;
  105. struct {
  106. struct nvfx_vertex_program *vertprog;
  107. unsigned nr_attribs;
  108. unsigned hw[PIPE_MAX_SHADER_INPUTS];
  109. unsigned draw[PIPE_MAX_SHADER_INPUTS];
  110. unsigned emit[PIPE_MAX_SHADER_INPUTS];
  111. } swtnl;
  112. enum {
  113. HW, SWTNL, SWRAST
  114. } render_mode;
  115. unsigned fallback_swtnl;
  116. unsigned fallback_swrast;
  117. /* Context state */
  118. unsigned dirty, draw_dirty;
  119. struct pipe_scissor_state scissor;
  120. unsigned stipple[32];
  121. struct pipe_clip_state clip;
  122. struct nvfx_vertex_program *vertprog;
  123. struct nvfx_fragment_program *fragprog;
  124. struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
  125. unsigned constbuf_nr[PIPE_SHADER_TYPES];
  126. struct nvfx_rasterizer_state *rasterizer;
  127. struct nvfx_zsa_state *zsa;
  128. struct nvfx_blend_state *blend;
  129. struct pipe_blend_color blend_colour;
  130. struct pipe_stencil_ref stencil_ref;
  131. struct pipe_viewport_state viewport;
  132. struct pipe_framebuffer_state framebuffer;
  133. struct pipe_buffer *idxbuf;
  134. unsigned idxbuf_format;
  135. struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
  136. struct nvfx_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
  137. struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
  138. unsigned nr_samplers;
  139. unsigned nr_textures;
  140. unsigned dirty_samplers;
  141. struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
  142. unsigned vtxbuf_nr;
  143. struct nvfx_vtxelt_state *vtxelt;
  144. };
  145. static INLINE struct nvfx_context *
  146. nvfx_context(struct pipe_context *pipe)
  147. {
  148. return (struct nvfx_context *)pipe;
  149. }
  150. struct nvfx_state_entry {
  151. boolean (*validate)(struct nvfx_context *nvfx);
  152. struct {
  153. unsigned pipe;
  154. unsigned hw;
  155. } dirty;
  156. };
  157. extern struct nvfx_state_entry nvfx_state_blend;
  158. extern struct nvfx_state_entry nvfx_state_blend_colour;
  159. extern struct nvfx_state_entry nvfx_state_fragprog;
  160. extern struct nvfx_state_entry nvfx_state_fragtex;
  161. extern struct nvfx_state_entry nvfx_state_framebuffer;
  162. extern struct nvfx_state_entry nvfx_state_rasterizer;
  163. extern struct nvfx_state_entry nvfx_state_scissor;
  164. extern struct nvfx_state_entry nvfx_state_sr;
  165. extern struct nvfx_state_entry nvfx_state_stipple;
  166. extern struct nvfx_state_entry nvfx_state_vbo;
  167. extern struct nvfx_state_entry nvfx_state_vertprog;
  168. extern struct nvfx_state_entry nvfx_state_viewport;
  169. extern struct nvfx_state_entry nvfx_state_vtxfmt;
  170. extern struct nvfx_state_entry nvfx_state_zsa;
  171. extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
  172. extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
  173. /* nvfx_context.c */
  174. struct pipe_context *
  175. nvfx_create(struct pipe_screen *pscreen, void *priv);
  176. /* nvfx_clear.c */
  177. extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
  178. const float *rgba, double depth, unsigned stencil);
  179. /* nvfx_draw.c */
  180. extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
  181. extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
  182. struct pipe_buffer *idxbuf,
  183. unsigned ib_size, unsigned mode,
  184. unsigned start, unsigned count);
  185. /* nvfx_fragprog.c */
  186. extern void nvfx_fragprog_destroy(struct nvfx_context *,
  187. struct nvfx_fragment_program *);
  188. /* nv30_fragtex.c */
  189. extern void
  190. nv30_sampler_state_init(struct pipe_context *pipe,
  191. struct nvfx_sampler_state *ps,
  192. const struct pipe_sampler_state *cso);
  193. extern void nv30_fragtex_bind(struct nvfx_context *);
  194. extern struct nouveau_stateobj *
  195. nv30_fragtex_build(struct nvfx_context *nvfx, int unit);
  196. /* nv40_fragtex.c */
  197. extern void
  198. nv40_sampler_state_init(struct pipe_context *pipe,
  199. struct nvfx_sampler_state *ps,
  200. const struct pipe_sampler_state *cso);
  201. extern void nv40_fragtex_bind(struct nvfx_context *);
  202. extern struct nouveau_stateobj *
  203. nv40_fragtex_build(struct nvfx_context *nvfx, int unit);
  204. /* nvfx_state.c */
  205. extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
  206. /* nvfx_state_emit.c */
  207. extern void nvfx_state_flush_notify(struct nouveau_channel *chan);
  208. extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
  209. extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
  210. extern void nvfx_state_emit(struct nvfx_context *nvfx);
  211. /* nvfx_transfer.c */
  212. extern void nvfx_init_transfer_functions(struct nvfx_context *nvfx);
  213. /* nvfx_vbo.c */
  214. extern void nvfx_draw_arrays(struct pipe_context *, unsigned mode,
  215. unsigned start, unsigned count);
  216. extern void nvfx_draw_elements(struct pipe_context *pipe,
  217. struct pipe_buffer *indexBuffer,
  218. unsigned indexSize,
  219. unsigned mode, unsigned start,
  220. unsigned count);
  221. /* nvfx_vertprog.c */
  222. extern void nvfx_vertprog_destroy(struct nvfx_context *,
  223. struct nvfx_vertex_program *);
  224. #endif