Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nv04_context.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (C) 2009-2010 Francisco Jerez.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "nouveau_driver.h"
  27. #include "nouveau_context.h"
  28. #include "nouveau_fbo.h"
  29. #include "nouveau_util.h"
  30. #include "nv04_3d.xml.h"
  31. #include "nv04_driver.h"
  32. static GLboolean
  33. texunit_needs_combiners(struct gl_texture_unit *u)
  34. {
  35. struct gl_texture_object *t = u->_Current;
  36. struct gl_texture_image *ti = t->Image[0][t->BaseLevel];
  37. return ti->TexFormat == MESA_FORMAT_A8 ||
  38. ti->TexFormat == MESA_FORMAT_L8 ||
  39. u->EnvMode == GL_COMBINE ||
  40. u->EnvMode == GL_COMBINE4_NV ||
  41. u->EnvMode == GL_BLEND ||
  42. u->EnvMode == GL_ADD;
  43. }
  44. struct nouveau_object *
  45. nv04_context_engine(struct gl_context *ctx)
  46. {
  47. struct nv04_context *nctx = to_nv04_context(ctx);
  48. struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw;
  49. struct nouveau_pushbuf *push = context_push(ctx);
  50. struct nouveau_object *fahrenheit;
  51. if ((ctx->Texture.Unit[0]._ReallyEnabled &&
  52. texunit_needs_combiners(&ctx->Texture.Unit[0])) ||
  53. ctx->Texture.Unit[1]._ReallyEnabled ||
  54. ctx->Stencil.Enabled ||
  55. !(ctx->Color.ColorMask[0][RCOMP] &&
  56. ctx->Color.ColorMask[0][GCOMP] &&
  57. ctx->Color.ColorMask[0][BCOMP] &&
  58. ctx->Color.ColorMask[0][ACOMP]))
  59. fahrenheit = hw->eng3dm;
  60. else
  61. fahrenheit = hw->eng3d;
  62. if (fahrenheit != nctx->eng3d) {
  63. BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
  64. PUSH_DATA (push, fahrenheit->handle);
  65. nctx->eng3d = fahrenheit;
  66. }
  67. return fahrenheit;
  68. }
  69. static void
  70. nv04_hwctx_init(struct gl_context *ctx)
  71. {
  72. struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw;
  73. struct nouveau_pushbuf *push = context_push(ctx);
  74. struct nv04_fifo *fifo = hw->chan->data;
  75. BEGIN_NV04(push, NV01_SUBC(SURF, OBJECT), 1);
  76. PUSH_DATA (push, hw->surf3d->handle);
  77. BEGIN_NV04(push, NV04_SF3D(DMA_NOTIFY), 3);
  78. PUSH_DATA (push, hw->ntfy->handle);
  79. PUSH_DATA (push, fifo->vram);
  80. PUSH_DATA (push, fifo->vram);
  81. BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
  82. PUSH_DATA (push, hw->eng3d->handle);
  83. BEGIN_NV04(push, NV04_TTRI(DMA_NOTIFY), 4);
  84. PUSH_DATA (push, hw->ntfy->handle);
  85. PUSH_DATA (push, fifo->vram);
  86. PUSH_DATA (push, fifo->gart);
  87. PUSH_DATA (push, hw->surf3d->handle);
  88. BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
  89. PUSH_DATA (push, hw->eng3dm->handle);
  90. BEGIN_NV04(push, NV04_MTRI(DMA_NOTIFY), 4);
  91. PUSH_DATA (push, hw->ntfy->handle);
  92. PUSH_DATA (push, fifo->vram);
  93. PUSH_DATA (push, fifo->gart);
  94. PUSH_DATA (push, hw->surf3d->handle);
  95. PUSH_KICK (push);
  96. }
  97. static void
  98. init_dummy_texture(struct gl_context *ctx)
  99. {
  100. struct nouveau_surface *s = &to_nv04_context(ctx)->dummy_texture;
  101. nouveau_surface_alloc(ctx, s, SWIZZLED,
  102. NOUVEAU_BO_MAP | NOUVEAU_BO_VRAM,
  103. MESA_FORMAT_ARGB8888, 1, 1);
  104. nouveau_bo_map(s->bo, NOUVEAU_BO_WR, context_client(ctx));
  105. *(uint32_t *)s->bo->map = 0xffffffff;
  106. }
  107. static void
  108. nv04_context_destroy(struct gl_context *ctx)
  109. {
  110. struct nouveau_context *nctx = to_nouveau_context(ctx);
  111. nv04_surface_takedown(ctx);
  112. nv04_render_destroy(ctx);
  113. nouveau_surface_ref(NULL, &to_nv04_context(ctx)->dummy_texture);
  114. nouveau_object_del(&nctx->hw.eng3d);
  115. nouveau_object_del(&nctx->hw.eng3dm);
  116. nouveau_object_del(&nctx->hw.surf3d);
  117. nouveau_context_deinit(ctx);
  118. free(ctx);
  119. }
  120. static struct gl_context *
  121. nv04_context_create(struct nouveau_screen *screen, const struct gl_config *visual,
  122. struct gl_context *share_ctx)
  123. {
  124. struct nv04_context *nctx;
  125. struct nouveau_hw_state *hw;
  126. struct gl_context *ctx;
  127. int ret;
  128. nctx = CALLOC_STRUCT(nv04_context);
  129. if (!nctx)
  130. return NULL;
  131. ctx = &nctx->base.base;
  132. hw = &nctx->base.hw;
  133. if (!nouveau_context_init(ctx, screen, visual, share_ctx))
  134. goto fail;
  135. /* GL constants. */
  136. ctx->Const.MaxTextureLevels = 11;
  137. ctx->Const.MaxTextureCoordUnits = NV04_TEXTURE_UNITS;
  138. ctx->Const.FragmentProgram.MaxTextureImageUnits = NV04_TEXTURE_UNITS;
  139. ctx->Const.MaxTextureUnits = NV04_TEXTURE_UNITS;
  140. ctx->Const.MaxTextureMaxAnisotropy = 2;
  141. ctx->Const.MaxTextureLodBias = 15;
  142. /* 2D engine. */
  143. ret = nv04_surface_init(ctx);
  144. if (!ret)
  145. goto fail;
  146. /* 3D engine. */
  147. ret = nouveau_object_new(context_chan(ctx), 0xbeef0001,
  148. NV04_TEXTURED_TRIANGLE_CLASS, NULL, 0,
  149. &hw->eng3d);
  150. if (ret)
  151. goto fail;
  152. ret = nouveau_object_new(context_chan(ctx), 0xbeef0002,
  153. NV04_MULTITEX_TRIANGLE_CLASS, NULL, 0,
  154. &hw->eng3dm);
  155. if (ret)
  156. goto fail;
  157. ret = nouveau_object_new(context_chan(ctx), 0xbeef0003,
  158. NV04_SURFACE_3D_CLASS, NULL, 0,
  159. &hw->surf3d);
  160. if (ret)
  161. goto fail;
  162. init_dummy_texture(ctx);
  163. nv04_hwctx_init(ctx);
  164. nv04_render_init(ctx);
  165. return ctx;
  166. fail:
  167. nv04_context_destroy(ctx);
  168. return NULL;
  169. }
  170. const struct nouveau_driver nv04_driver = {
  171. .context_create = nv04_context_create,
  172. .context_destroy = nv04_context_destroy,
  173. .surface_copy = nv04_surface_copy,
  174. .surface_fill = nv04_surface_fill,
  175. .emit = (nouveau_state_func[]) {
  176. nv04_defer_control,
  177. nouveau_emit_nothing,
  178. nv04_defer_blend,
  179. nv04_defer_blend,
  180. nouveau_emit_nothing,
  181. nouveau_emit_nothing,
  182. nouveau_emit_nothing,
  183. nouveau_emit_nothing,
  184. nouveau_emit_nothing,
  185. nouveau_emit_nothing,
  186. nv04_defer_control,
  187. nouveau_emit_nothing,
  188. nv04_defer_control,
  189. nouveau_emit_nothing,
  190. nv04_defer_control,
  191. nv04_defer_control,
  192. nouveau_emit_nothing,
  193. nv04_emit_framebuffer,
  194. nv04_defer_blend,
  195. nouveau_emit_nothing,
  196. nouveau_emit_nothing,
  197. nouveau_emit_nothing,
  198. nouveau_emit_nothing,
  199. nouveau_emit_nothing,
  200. nouveau_emit_nothing,
  201. nouveau_emit_nothing,
  202. nouveau_emit_nothing,
  203. nouveau_emit_nothing,
  204. nouveau_emit_nothing,
  205. nouveau_emit_nothing,
  206. nouveau_emit_nothing,
  207. nouveau_emit_nothing,
  208. nouveau_emit_nothing,
  209. nouveau_emit_nothing,
  210. nouveau_emit_nothing,
  211. nouveau_emit_nothing,
  212. nouveau_emit_nothing,
  213. nouveau_emit_nothing,
  214. nouveau_emit_nothing,
  215. nouveau_emit_nothing,
  216. nouveau_emit_nothing,
  217. nouveau_emit_nothing,
  218. nouveau_emit_nothing,
  219. nouveau_emit_nothing,
  220. nouveau_emit_nothing,
  221. nouveau_emit_nothing,
  222. nouveau_emit_nothing,
  223. nouveau_emit_nothing,
  224. nv04_emit_scissor,
  225. nv04_defer_blend,
  226. nv04_defer_control,
  227. nv04_defer_control,
  228. nv04_defer_control,
  229. nv04_emit_tex_env,
  230. nv04_emit_tex_env,
  231. nouveau_emit_nothing,
  232. nouveau_emit_nothing,
  233. nouveau_emit_nothing,
  234. nouveau_emit_nothing,
  235. nouveau_emit_nothing,
  236. nouveau_emit_nothing,
  237. nouveau_emit_nothing,
  238. nouveau_emit_nothing,
  239. nouveau_emit_nothing,
  240. nouveau_emit_nothing,
  241. nv04_emit_tex_obj,
  242. nv04_emit_tex_obj,
  243. nouveau_emit_nothing,
  244. nouveau_emit_nothing,
  245. nouveau_emit_nothing,
  246. nv04_emit_blend,
  247. nv04_emit_control,
  248. },
  249. .num_emit = NUM_NV04_STATE,
  250. };