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.

nv50_state_validate.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * Copyright 2008 Ben Skeggs
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  19. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #include "nv50_context.h"
  23. #include "nouveau/nouveau_stateobj.h"
  24. static void
  25. nv50_state_validate_fb(struct nv50_context *nv50)
  26. {
  27. struct nouveau_grobj *tesla = nv50->screen->tesla;
  28. struct nouveau_stateobj *so = so_new(128, 18);
  29. struct pipe_framebuffer_state *fb = &nv50->framebuffer;
  30. unsigned i, w, h, gw = 0;
  31. for (i = 0; i < fb->nr_cbufs; i++) {
  32. struct pipe_texture *pt = fb->cbufs[i]->texture;
  33. struct nouveau_bo *bo = nv50_miptree(pt)->base.bo;
  34. if (!gw) {
  35. w = fb->cbufs[i]->width;
  36. h = fb->cbufs[i]->height;
  37. gw = 1;
  38. } else {
  39. assert(w == fb->cbufs[i]->width);
  40. assert(h == fb->cbufs[i]->height);
  41. }
  42. so_method(so, tesla, NV50TCL_RT_HORIZ(i), 2);
  43. so_data (so, fb->cbufs[i]->width);
  44. so_data (so, fb->cbufs[i]->height);
  45. so_method(so, tesla, NV50TCL_RT_ADDRESS_HIGH(i), 5);
  46. so_reloc (so, bo, fb->cbufs[i]->offset, NOUVEAU_BO_VRAM |
  47. NOUVEAU_BO_HIGH | NOUVEAU_BO_RDWR, 0, 0);
  48. so_reloc (so, bo, fb->cbufs[i]->offset, NOUVEAU_BO_VRAM |
  49. NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0);
  50. switch (fb->cbufs[i]->format) {
  51. case PIPE_FORMAT_A8R8G8B8_UNORM:
  52. so_data(so, NV50TCL_RT_FORMAT_A8R8G8B8_UNORM);
  53. break;
  54. case PIPE_FORMAT_R5G6B5_UNORM:
  55. so_data(so, NV50TCL_RT_FORMAT_R5G6B5_UNORM);
  56. break;
  57. default:
  58. NOUVEAU_ERR("AIIII unknown format %s\n",
  59. pf_name(fb->cbufs[i]->format));
  60. so_data(so, NV50TCL_RT_FORMAT_X8R8G8B8_UNORM);
  61. break;
  62. }
  63. so_data(so, nv50_miptree(pt)->
  64. level[fb->cbufs[i]->level].tile_mode << 4);
  65. so_data(so, 0x00000000);
  66. so_method(so, tesla, 0x1224, 1);
  67. so_data (so, 1);
  68. }
  69. if (fb->zsbuf) {
  70. struct pipe_texture *pt = fb->zsbuf->texture;
  71. struct nouveau_bo *bo = nv50_miptree(pt)->base.bo;
  72. if (!gw) {
  73. w = fb->zsbuf->width;
  74. h = fb->zsbuf->height;
  75. gw = 1;
  76. } else {
  77. assert(w == fb->zsbuf->width);
  78. assert(h == fb->zsbuf->height);
  79. }
  80. so_method(so, tesla, NV50TCL_ZETA_ADDRESS_HIGH, 5);
  81. so_reloc (so, bo, fb->zsbuf->offset, NOUVEAU_BO_VRAM |
  82. NOUVEAU_BO_HIGH | NOUVEAU_BO_RDWR, 0, 0);
  83. so_reloc (so, bo, fb->zsbuf->offset, NOUVEAU_BO_VRAM |
  84. NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0);
  85. switch (fb->zsbuf->format) {
  86. case PIPE_FORMAT_Z32_FLOAT:
  87. so_data(so, NV50TCL_ZETA_FORMAT_Z32_FLOAT);
  88. break;
  89. case PIPE_FORMAT_Z24S8_UNORM:
  90. so_data(so, NV50TCL_ZETA_FORMAT_Z24S8_UNORM);
  91. break;
  92. case PIPE_FORMAT_X8Z24_UNORM:
  93. so_data(so, NV50TCL_ZETA_FORMAT_X8Z24_UNORM);
  94. break;
  95. case PIPE_FORMAT_S8Z24_UNORM:
  96. so_data(so, NV50TCL_ZETA_FORMAT_S8Z24_UNORM);
  97. break;
  98. default:
  99. NOUVEAU_ERR("AIIII unknown format %s\n",
  100. pf_name(fb->zsbuf->format));
  101. so_data(so, NV50TCL_ZETA_FORMAT_S8Z24_UNORM);
  102. break;
  103. }
  104. so_data(so, nv50_miptree(pt)->
  105. level[fb->zsbuf->level].tile_mode << 4);
  106. so_data(so, 0x00000000);
  107. so_method(so, tesla, 0x1538, 1);
  108. so_data (so, 1);
  109. so_method(so, tesla, NV50TCL_ZETA_HORIZ, 3);
  110. so_data (so, fb->zsbuf->width);
  111. so_data (so, fb->zsbuf->height);
  112. so_data (so, 0x00010001);
  113. }
  114. so_method(so, tesla, NV50TCL_VIEWPORT_HORIZ, 2);
  115. so_data (so, w << 16);
  116. so_data (so, h << 16);
  117. /* set window lower left corner */
  118. so_method(so, tesla, NV50TCL_WINDOW_LEFT, 2);
  119. so_data (so, 0);
  120. so_data (so, 0);
  121. /* set screen scissor rectangle */
  122. so_method(so, tesla, NV50TCL_SCREEN_SCISSOR_HORIZ, 2);
  123. so_data (so, w << 16);
  124. so_data (so, h << 16);
  125. /* we set scissors to framebuffer size when they're 'turned off' */
  126. nv50->dirty |= NV50_NEW_SCISSOR;
  127. so_ref(NULL, &nv50->state.scissor);
  128. so_ref(so, &nv50->state.fb);
  129. so_ref(NULL, &so);
  130. }
  131. static void
  132. nv50_state_emit(struct nv50_context *nv50)
  133. {
  134. struct nv50_screen *screen = nv50->screen;
  135. struct nouveau_channel *chan = screen->base.channel;
  136. if (nv50->pctx_id != screen->cur_pctx) {
  137. if (nv50->state.fb)
  138. nv50->state.dirty |= NV50_NEW_FRAMEBUFFER;
  139. if (nv50->state.blend)
  140. nv50->state.dirty |= NV50_NEW_BLEND;
  141. if (nv50->state.zsa)
  142. nv50->state.dirty |= NV50_NEW_ZSA;
  143. if (nv50->state.vertprog)
  144. nv50->state.dirty |= NV50_NEW_VERTPROG;
  145. if (nv50->state.fragprog)
  146. nv50->state.dirty |= NV50_NEW_FRAGPROG;
  147. if (nv50->state.rast)
  148. nv50->state.dirty |= NV50_NEW_RASTERIZER;
  149. if (nv50->state.blend_colour)
  150. nv50->state.dirty |= NV50_NEW_BLEND_COLOUR;
  151. if (nv50->state.stipple)
  152. nv50->state.dirty |= NV50_NEW_STIPPLE;
  153. if (nv50->state.scissor)
  154. nv50->state.dirty |= NV50_NEW_SCISSOR;
  155. if (nv50->state.viewport)
  156. nv50->state.dirty |= NV50_NEW_VIEWPORT;
  157. if (nv50->state.tsc_upload)
  158. nv50->state.dirty |= NV50_NEW_SAMPLER;
  159. if (nv50->state.tic_upload)
  160. nv50->state.dirty |= NV50_NEW_TEXTURE;
  161. if (nv50->state.vtxfmt && nv50->state.vtxbuf)
  162. nv50->state.dirty |= NV50_NEW_ARRAYS;
  163. screen->cur_pctx = nv50->pctx_id;
  164. }
  165. if (nv50->state.dirty & NV50_NEW_FRAMEBUFFER)
  166. so_emit(chan, nv50->state.fb);
  167. if (nv50->state.dirty & NV50_NEW_BLEND)
  168. so_emit(chan, nv50->state.blend);
  169. if (nv50->state.dirty & NV50_NEW_ZSA)
  170. so_emit(chan, nv50->state.zsa);
  171. if (nv50->state.dirty & NV50_NEW_VERTPROG)
  172. so_emit(chan, nv50->state.vertprog);
  173. if (nv50->state.dirty & NV50_NEW_FRAGPROG)
  174. so_emit(chan, nv50->state.fragprog);
  175. if (nv50->state.dirty & (NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG))
  176. so_emit(chan, nv50->state.programs);
  177. if (nv50->state.dirty & NV50_NEW_RASTERIZER)
  178. so_emit(chan, nv50->state.rast);
  179. if (nv50->state.dirty & NV50_NEW_BLEND_COLOUR)
  180. so_emit(chan, nv50->state.blend_colour);
  181. if (nv50->state.dirty & NV50_NEW_STIPPLE)
  182. so_emit(chan, nv50->state.stipple);
  183. if (nv50->state.dirty & NV50_NEW_SCISSOR)
  184. so_emit(chan, nv50->state.scissor);
  185. if (nv50->state.dirty & NV50_NEW_VIEWPORT)
  186. so_emit(chan, nv50->state.viewport);
  187. if (nv50->state.dirty & NV50_NEW_SAMPLER)
  188. so_emit(chan, nv50->state.tsc_upload);
  189. if (nv50->state.dirty & NV50_NEW_TEXTURE)
  190. so_emit(chan, nv50->state.tic_upload);
  191. if (nv50->state.dirty & NV50_NEW_ARRAYS) {
  192. so_emit(chan, nv50->state.vtxfmt);
  193. so_emit(chan, nv50->state.vtxbuf);
  194. if (nv50->state.vtxattr)
  195. so_emit(chan, nv50->state.vtxattr);
  196. }
  197. nv50->state.dirty = 0;
  198. so_emit_reloc_markers(chan, nv50->state.fb);
  199. so_emit_reloc_markers(chan, nv50->state.vertprog);
  200. so_emit_reloc_markers(chan, nv50->state.fragprog);
  201. so_emit_reloc_markers(chan, nv50->state.vtxbuf);
  202. so_emit_reloc_markers(chan, nv50->screen->static_init);
  203. }
  204. boolean
  205. nv50_state_validate(struct nv50_context *nv50)
  206. {
  207. struct nouveau_grobj *tesla = nv50->screen->tesla;
  208. struct nouveau_stateobj *so;
  209. unsigned i;
  210. if (nv50->dirty & NV50_NEW_FRAMEBUFFER)
  211. nv50_state_validate_fb(nv50);
  212. if (nv50->dirty & NV50_NEW_BLEND)
  213. so_ref(nv50->blend->so, &nv50->state.blend);
  214. if (nv50->dirty & NV50_NEW_ZSA)
  215. so_ref(nv50->zsa->so, &nv50->state.zsa);
  216. if (nv50->dirty & (NV50_NEW_VERTPROG | NV50_NEW_VERTPROG_CB))
  217. nv50_vertprog_validate(nv50);
  218. if (nv50->dirty & (NV50_NEW_FRAGPROG | NV50_NEW_FRAGPROG_CB))
  219. nv50_fragprog_validate(nv50);
  220. if (nv50->dirty & (NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG))
  221. nv50_linkage_validate(nv50);
  222. if (nv50->dirty & NV50_NEW_RASTERIZER)
  223. so_ref(nv50->rasterizer->so, &nv50->state.rast);
  224. if (nv50->dirty & NV50_NEW_BLEND_COLOUR) {
  225. so = so_new(5, 0);
  226. so_method(so, tesla, NV50TCL_BLEND_COLOR(0), 4);
  227. so_data (so, fui(nv50->blend_colour.color[0]));
  228. so_data (so, fui(nv50->blend_colour.color[1]));
  229. so_data (so, fui(nv50->blend_colour.color[2]));
  230. so_data (so, fui(nv50->blend_colour.color[3]));
  231. so_ref(so, &nv50->state.blend_colour);
  232. so_ref(NULL, &so);
  233. }
  234. if (nv50->dirty & NV50_NEW_STIPPLE) {
  235. so = so_new(33, 0);
  236. so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_PATTERN(0), 32);
  237. for (i = 0; i < 32; i++)
  238. so_data(so, nv50->stipple.stipple[i]);
  239. so_ref(so, &nv50->state.stipple);
  240. so_ref(NULL, &so);
  241. }
  242. if (nv50->dirty & (NV50_NEW_SCISSOR | NV50_NEW_RASTERIZER)) {
  243. struct pipe_rasterizer_state *rast = &nv50->rasterizer->pipe;
  244. struct pipe_scissor_state *s = &nv50->scissor;
  245. if (nv50->state.scissor &&
  246. (rast->scissor == 0 && nv50->state.scissor_enabled == 0))
  247. goto scissor_uptodate;
  248. nv50->state.scissor_enabled = rast->scissor;
  249. so = so_new(3, 0);
  250. so_method(so, tesla, NV50TCL_SCISSOR_HORIZ, 2);
  251. if (nv50->state.scissor_enabled) {
  252. so_data(so, (s->maxx << 16) | s->minx);
  253. so_data(so, (s->maxy << 16) | s->miny);
  254. } else {
  255. so_data(so, (nv50->framebuffer.width << 16));
  256. so_data(so, (nv50->framebuffer.height << 16));
  257. }
  258. so_ref(so, &nv50->state.scissor);
  259. so_ref(NULL, &so);
  260. nv50->state.dirty |= NV50_NEW_SCISSOR;
  261. }
  262. scissor_uptodate:
  263. if (nv50->dirty & (NV50_NEW_VIEWPORT | NV50_NEW_RASTERIZER)) {
  264. unsigned bypass;
  265. if (!nv50->rasterizer->pipe.bypass_vs_clip_and_viewport)
  266. bypass = 0;
  267. else
  268. bypass = 1;
  269. if (nv50->state.viewport &&
  270. (bypass || !(nv50->dirty & NV50_NEW_VIEWPORT)) &&
  271. nv50->state.viewport_bypass == bypass)
  272. goto viewport_uptodate;
  273. nv50->state.viewport_bypass = bypass;
  274. so = so_new(12, 0);
  275. if (!bypass) {
  276. so_method(so, tesla, NV50TCL_VIEWPORT_TRANSLATE(0), 3);
  277. so_data (so, fui(nv50->viewport.translate[0]));
  278. so_data (so, fui(nv50->viewport.translate[1]));
  279. so_data (so, fui(nv50->viewport.translate[2]));
  280. so_method(so, tesla, NV50TCL_VIEWPORT_SCALE(0), 3);
  281. so_data (so, fui(nv50->viewport.scale[0]));
  282. so_data (so, fui(nv50->viewport.scale[1]));
  283. so_data (so, fui(nv50->viewport.scale[2]));
  284. so_method(so, tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1);
  285. so_data (so, 1);
  286. /* no idea what 0f90 does */
  287. so_method(so, tesla, 0x0f90, 1);
  288. so_data (so, 0);
  289. } else {
  290. so_method(so, tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1);
  291. so_data (so, 0);
  292. so_method(so, tesla, 0x0f90, 1);
  293. so_data (so, 1);
  294. }
  295. so_ref(so, &nv50->state.viewport);
  296. so_ref(NULL, &so);
  297. nv50->state.dirty |= NV50_NEW_VIEWPORT;
  298. }
  299. viewport_uptodate:
  300. if (nv50->dirty & NV50_NEW_SAMPLER) {
  301. int i;
  302. so = so_new(nv50->sampler_nr * 8 + 3, 0);
  303. so_method(so, tesla, NV50TCL_CB_ADDR, 1);
  304. so_data (so, NV50_CB_TSC);
  305. so_method(so, tesla, NV50TCL_CB_DATA(0) | 0x40000000,
  306. nv50->sampler_nr * 8);
  307. for (i = 0; i < nv50->sampler_nr; i++)
  308. so_datap (so, nv50->sampler[i]->tsc, 8);
  309. so_ref(so, &nv50->state.tsc_upload);
  310. so_ref(NULL, &so);
  311. }
  312. if (nv50->dirty & (NV50_NEW_TEXTURE | NV50_NEW_SAMPLER))
  313. nv50_tex_validate(nv50);
  314. if (nv50->dirty & NV50_NEW_ARRAYS)
  315. nv50_vbo_validate(nv50);
  316. nv50->state.dirty |= nv50->dirty;
  317. nv50->dirty = 0;
  318. nv50_state_emit(nv50);
  319. return TRUE;
  320. }