Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cell_pipe_state.c 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. /* Authors:
  28. * Keith Whitwell <keith@tungstengraphics.com>
  29. * Brian Paul
  30. */
  31. #include "util/u_memory.h"
  32. #include "pipe/p_inlines.h"
  33. #include "draw/draw_context.h"
  34. #include "cell_context.h"
  35. #include "cell_flush.h"
  36. #include "cell_state.h"
  37. #include "cell_texture.h"
  38. static void *
  39. cell_create_blend_state(struct pipe_context *pipe,
  40. const struct pipe_blend_state *blend)
  41. {
  42. return mem_dup(blend, sizeof(*blend));
  43. }
  44. static void
  45. cell_bind_blend_state(struct pipe_context *pipe, void *blend)
  46. {
  47. struct cell_context *cell = cell_context(pipe);
  48. draw_flush(cell->draw);
  49. cell->blend = (struct pipe_blend_state *) blend;
  50. cell->dirty |= CELL_NEW_BLEND;
  51. }
  52. static void
  53. cell_delete_blend_state(struct pipe_context *pipe, void *blend)
  54. {
  55. FREE(blend);
  56. }
  57. static void
  58. cell_set_blend_color(struct pipe_context *pipe,
  59. const struct pipe_blend_color *blend_color)
  60. {
  61. struct cell_context *cell = cell_context(pipe);
  62. draw_flush(cell->draw);
  63. cell->blend_color = *blend_color;
  64. cell->dirty |= CELL_NEW_BLEND;
  65. }
  66. static void *
  67. cell_create_depth_stencil_alpha_state(struct pipe_context *pipe,
  68. const struct pipe_depth_stencil_alpha_state *dsa)
  69. {
  70. return mem_dup(dsa, sizeof(*dsa));
  71. }
  72. static void
  73. cell_bind_depth_stencil_alpha_state(struct pipe_context *pipe,
  74. void *dsa)
  75. {
  76. struct cell_context *cell = cell_context(pipe);
  77. draw_flush(cell->draw);
  78. cell->depth_stencil = (struct pipe_depth_stencil_alpha_state *) dsa;
  79. cell->dirty |= CELL_NEW_DEPTH_STENCIL;
  80. }
  81. static void
  82. cell_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *dsa)
  83. {
  84. FREE(dsa);
  85. }
  86. static void
  87. cell_set_clip_state(struct pipe_context *pipe,
  88. const struct pipe_clip_state *clip)
  89. {
  90. struct cell_context *cell = cell_context(pipe);
  91. /* pass the clip state to the draw module */
  92. draw_set_clip_state(cell->draw, clip);
  93. }
  94. /* Called when driver state tracker notices changes to the viewport
  95. * matrix:
  96. */
  97. static void
  98. cell_set_viewport_state( struct pipe_context *pipe,
  99. const struct pipe_viewport_state *viewport )
  100. {
  101. struct cell_context *cell = cell_context(pipe);
  102. cell->viewport = *viewport; /* struct copy */
  103. cell->dirty |= CELL_NEW_VIEWPORT;
  104. /* pass the viewport info to the draw module */
  105. draw_set_viewport_state(cell->draw, viewport);
  106. /* Using tnl/ and vf/ modules is temporary while getting started.
  107. * Full pipe will have vertex shader, vertex fetch of its own.
  108. */
  109. }
  110. static void
  111. cell_set_scissor_state( struct pipe_context *pipe,
  112. const struct pipe_scissor_state *scissor )
  113. {
  114. struct cell_context *cell = cell_context(pipe);
  115. memcpy( &cell->scissor, scissor, sizeof(*scissor) );
  116. cell->dirty |= CELL_NEW_SCISSOR;
  117. }
  118. static void
  119. cell_set_polygon_stipple( struct pipe_context *pipe,
  120. const struct pipe_poly_stipple *stipple )
  121. {
  122. struct cell_context *cell = cell_context(pipe);
  123. memcpy( &cell->poly_stipple, stipple, sizeof(*stipple) );
  124. cell->dirty |= CELL_NEW_STIPPLE;
  125. }
  126. static void *
  127. cell_create_rasterizer_state(struct pipe_context *pipe,
  128. const struct pipe_rasterizer_state *rasterizer)
  129. {
  130. return mem_dup(rasterizer, sizeof(*rasterizer));
  131. }
  132. static void
  133. cell_bind_rasterizer_state(struct pipe_context *pipe, void *rast)
  134. {
  135. struct pipe_rasterizer_state *rasterizer =
  136. (struct pipe_rasterizer_state *) rast;
  137. struct cell_context *cell = cell_context(pipe);
  138. /* pass-through to draw module */
  139. draw_set_rasterizer_state(cell->draw, rasterizer);
  140. cell->rasterizer = rasterizer;
  141. cell->dirty |= CELL_NEW_RASTERIZER;
  142. }
  143. static void
  144. cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer)
  145. {
  146. FREE(rasterizer);
  147. }
  148. static void *
  149. cell_create_sampler_state(struct pipe_context *pipe,
  150. const struct pipe_sampler_state *sampler)
  151. {
  152. return mem_dup(sampler, sizeof(*sampler));
  153. }
  154. static void
  155. cell_bind_sampler_states(struct pipe_context *pipe,
  156. unsigned num, void **samplers)
  157. {
  158. struct cell_context *cell = cell_context(pipe);
  159. uint i, changed = 0x0;
  160. assert(num <= CELL_MAX_SAMPLERS);
  161. draw_flush(cell->draw);
  162. for (i = 0; i < CELL_MAX_SAMPLERS; i++) {
  163. struct pipe_sampler_state *new_samp = i < num ? samplers[i] : NULL;
  164. if (cell->sampler[i] != new_samp) {
  165. cell->sampler[i] = new_samp;
  166. changed |= (1 << i);
  167. }
  168. }
  169. if (changed) {
  170. cell->dirty |= CELL_NEW_SAMPLER;
  171. cell->dirty_samplers |= changed;
  172. }
  173. }
  174. static void
  175. cell_delete_sampler_state(struct pipe_context *pipe,
  176. void *sampler)
  177. {
  178. FREE( sampler );
  179. }
  180. static void
  181. cell_set_sampler_textures(struct pipe_context *pipe,
  182. unsigned num, struct pipe_texture **texture)
  183. {
  184. struct cell_context *cell = cell_context(pipe);
  185. uint i, changed = 0x0;
  186. assert(num <= CELL_MAX_SAMPLERS);
  187. for (i = 0; i < CELL_MAX_SAMPLERS; i++) {
  188. struct pipe_texture *new_tex = i < num ? texture[i] : NULL;
  189. if ((struct pipe_texture *) cell->texture[i] != new_tex) {
  190. pipe_texture_reference((struct pipe_texture **) &cell->texture[i],
  191. new_tex);
  192. changed |= (1 << i);
  193. }
  194. }
  195. cell->num_textures = num;
  196. if (changed) {
  197. cell->dirty |= CELL_NEW_TEXTURE;
  198. cell->dirty_textures |= changed;
  199. }
  200. }
  201. static void
  202. cell_set_framebuffer_state(struct pipe_context *pipe,
  203. const struct pipe_framebuffer_state *fb)
  204. {
  205. struct cell_context *cell = cell_context(pipe);
  206. if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
  207. struct pipe_surface *csurf = fb->cbufs[0];
  208. struct pipe_surface *zsurf = fb->zsbuf;
  209. uint i;
  210. uint flags = (PIPE_BUFFER_USAGE_GPU_WRITE |
  211. PIPE_BUFFER_USAGE_GPU_READ);
  212. /* unmap old surfaces */
  213. for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
  214. if (cell->framebuffer.cbufs[i] && cell->cbuf_map[i]) {
  215. pipe_surface_unmap(cell->framebuffer.cbufs[i]);
  216. cell->cbuf_map[i] = NULL;
  217. }
  218. }
  219. if (cell->framebuffer.zsbuf && cell->zsbuf_map) {
  220. pipe_surface_unmap(cell->framebuffer.zsbuf);
  221. cell->zsbuf_map = NULL;
  222. }
  223. /* Finish any pending rendering to the current surface before
  224. * installing a new surface!
  225. */
  226. cell_flush_int(cell, CELL_FLUSH_WAIT);
  227. /* update my state
  228. * (this is also where old surfaces will finally get freed)
  229. */
  230. cell->framebuffer.width = fb->width;
  231. cell->framebuffer.height = fb->height;
  232. cell->framebuffer.num_cbufs = fb->num_cbufs;
  233. for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
  234. pipe_surface_reference(&cell->framebuffer.cbufs[i], fb->cbufs[i]);
  235. }
  236. pipe_surface_reference(&cell->framebuffer.zsbuf, fb->zsbuf);
  237. /* map new surfaces */
  238. if (csurf)
  239. cell->cbuf_map[0] = pipe_surface_map(csurf, flags);
  240. if (zsurf)
  241. cell->zsbuf_map = pipe_surface_map(zsurf, flags);
  242. cell->dirty |= CELL_NEW_FRAMEBUFFER;
  243. }
  244. }
  245. void
  246. cell_init_state_functions(struct cell_context *cell)
  247. {
  248. cell->pipe.create_blend_state = cell_create_blend_state;
  249. cell->pipe.bind_blend_state = cell_bind_blend_state;
  250. cell->pipe.delete_blend_state = cell_delete_blend_state;
  251. cell->pipe.create_sampler_state = cell_create_sampler_state;
  252. cell->pipe.bind_sampler_states = cell_bind_sampler_states;
  253. cell->pipe.delete_sampler_state = cell_delete_sampler_state;
  254. cell->pipe.set_sampler_textures = cell_set_sampler_textures;
  255. cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state;
  256. cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state;
  257. cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state;
  258. cell->pipe.create_rasterizer_state = cell_create_rasterizer_state;
  259. cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state;
  260. cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state;
  261. cell->pipe.set_blend_color = cell_set_blend_color;
  262. cell->pipe.set_clip_state = cell_set_clip_state;
  263. cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
  264. cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
  265. cell->pipe.set_scissor_state = cell_set_scissor_state;
  266. cell->pipe.set_viewport_state = cell_set_viewport_state;
  267. }