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.

cell_context.c 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. /**
  28. * Authors
  29. * Brian Paul
  30. */
  31. #include <stdio.h>
  32. #include "pipe/p_defines.h"
  33. #include "pipe/p_format.h"
  34. #include "pipe/p_util.h"
  35. #include "pipe/p_winsys.h"
  36. #include "pipe/cell/common.h"
  37. #include "pipe/draw/draw_context.h"
  38. #include "pipe/draw/draw_private.h"
  39. #include "cell_clear.h"
  40. #include "cell_context.h"
  41. #include "cell_draw_arrays.h"
  42. #include "cell_flush.h"
  43. #include "cell_render.h"
  44. #include "cell_state.h"
  45. #include "cell_surface.h"
  46. #include "cell_spu.h"
  47. #include "cell_texture.h"
  48. #include "cell_vbuf.h"
  49. static boolean
  50. cell_is_format_supported( struct pipe_context *pipe,
  51. enum pipe_format format, uint type )
  52. {
  53. /*struct cell_context *cell = cell_context( pipe );*/
  54. switch (type) {
  55. case PIPE_TEXTURE:
  56. /* cell supports all texture formats, XXX for now anyway */
  57. return TRUE;
  58. case PIPE_SURFACE:
  59. /* cell supports all (off-screen) surface formats, XXX for now */
  60. return TRUE;
  61. default:
  62. assert(0);
  63. return FALSE;
  64. }
  65. }
  66. static int cell_get_param(struct pipe_context *pipe, int param)
  67. {
  68. switch (param) {
  69. case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
  70. return 8;
  71. case PIPE_CAP_NPOT_TEXTURES:
  72. return 1;
  73. case PIPE_CAP_TWO_SIDED_STENCIL:
  74. return 1;
  75. case PIPE_CAP_GLSL:
  76. return 1;
  77. case PIPE_CAP_S3TC:
  78. return 0;
  79. case PIPE_CAP_ANISOTROPIC_FILTER:
  80. return 0;
  81. case PIPE_CAP_POINT_SPRITE:
  82. return 1;
  83. case PIPE_CAP_MAX_RENDER_TARGETS:
  84. return 1;
  85. case PIPE_CAP_OCCLUSION_QUERY:
  86. return 1;
  87. case PIPE_CAP_TEXTURE_SHADOW_MAP:
  88. return 1;
  89. case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
  90. return 12; /* max 2Kx2K */
  91. case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
  92. return 8; /* max 128x128x128 */
  93. case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
  94. return 12; /* max 2Kx2K */
  95. default:
  96. return 0;
  97. }
  98. }
  99. static float cell_get_paramf(struct pipe_context *pipe, int param)
  100. {
  101. switch (param) {
  102. case PIPE_CAP_MAX_LINE_WIDTH:
  103. /* fall-through */
  104. case PIPE_CAP_MAX_LINE_WIDTH_AA:
  105. return 255.0; /* arbitrary */
  106. case PIPE_CAP_MAX_POINT_WIDTH:
  107. /* fall-through */
  108. case PIPE_CAP_MAX_POINT_WIDTH_AA:
  109. return 255.0; /* arbitrary */
  110. case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
  111. return 0.0;
  112. case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
  113. return 16.0; /* arbitrary */
  114. default:
  115. return 0;
  116. }
  117. }
  118. static const char *
  119. cell_get_name( struct pipe_context *pipe )
  120. {
  121. return "Cell";
  122. }
  123. static const char *
  124. cell_get_vendor( struct pipe_context *pipe )
  125. {
  126. return "Tungsten Graphics, Inc.";
  127. }
  128. static void
  129. cell_destroy_context( struct pipe_context *pipe )
  130. {
  131. struct cell_context *cell = cell_context(pipe);
  132. cell_spu_exit(cell);
  133. align_free(cell);
  134. }
  135. static struct draw_context *
  136. cell_draw_create(struct cell_context *cell)
  137. {
  138. struct draw_context *draw = draw_create();
  139. if (getenv("GALLIUM_CELL_VS")) {
  140. /* plug in SPU-based vertex transformation code */
  141. draw->shader_queue_flush = cell_vertex_shader_queue_flush;
  142. draw->driver_private = cell;
  143. }
  144. return draw;
  145. }
  146. struct pipe_context *
  147. cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
  148. {
  149. struct cell_context *cell;
  150. uint spu, buf;
  151. /* some fields need to be 16-byte aligned, so align the whole object */
  152. cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16);
  153. if (!cell)
  154. return NULL;
  155. memset(cell, 0, sizeof(*cell));
  156. cell->winsys = cws;
  157. cell->pipe.winsys = winsys;
  158. cell->pipe.destroy = cell_destroy_context;
  159. /* queries */
  160. cell->pipe.is_format_supported = cell_is_format_supported;
  161. cell->pipe.get_name = cell_get_name;
  162. cell->pipe.get_vendor = cell_get_vendor;
  163. cell->pipe.get_param = cell_get_param;
  164. cell->pipe.get_paramf = cell_get_paramf;
  165. /* state setters */
  166. cell->pipe.create_blend_state = cell_create_blend_state;
  167. cell->pipe.bind_blend_state = cell_bind_blend_state;
  168. cell->pipe.delete_blend_state = cell_delete_blend_state;
  169. cell->pipe.create_sampler_state = cell_create_sampler_state;
  170. cell->pipe.bind_sampler_state = cell_bind_sampler_state;
  171. cell->pipe.delete_sampler_state = cell_delete_sampler_state;
  172. cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state;
  173. cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state;
  174. cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state;
  175. cell->pipe.create_rasterizer_state = cell_create_rasterizer_state;
  176. cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state;
  177. cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state;
  178. cell->pipe.create_fs_state = cell_create_fs_state;
  179. cell->pipe.bind_fs_state = cell_bind_fs_state;
  180. cell->pipe.delete_fs_state = cell_delete_fs_state;
  181. cell->pipe.create_vs_state = cell_create_vs_state;
  182. cell->pipe.bind_vs_state = cell_bind_vs_state;
  183. cell->pipe.delete_vs_state = cell_delete_vs_state;
  184. cell->pipe.set_blend_color = cell_set_blend_color;
  185. cell->pipe.set_clip_state = cell_set_clip_state;
  186. cell->pipe.set_constant_buffer = cell_set_constant_buffer;
  187. cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
  188. cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
  189. cell->pipe.set_scissor_state = cell_set_scissor_state;
  190. cell->pipe.set_viewport_state = cell_set_viewport_state;
  191. cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
  192. cell->pipe.set_vertex_element = cell_set_vertex_element;
  193. cell->pipe.draw_arrays = cell_draw_arrays;
  194. cell->pipe.draw_elements = cell_draw_elements;
  195. cell->pipe.clear = cell_clear_surface;
  196. cell->pipe.flush = cell_flush;
  197. /* textures */
  198. cell->pipe.texture_create = cell_texture_create;
  199. cell->pipe.texture_release = cell_texture_release;
  200. cell->pipe.get_tex_surface = cell_get_tex_surface;
  201. cell->pipe.set_sampler_texture = cell_set_sampler_texture;
  202. #if 0
  203. cell->pipe.begin_query = cell_begin_query;
  204. cell->pipe.end_query = cell_end_query;
  205. cell->pipe.wait_query = cell_wait_query;
  206. #endif
  207. cell_init_surface_functions(cell);
  208. cell->draw = cell_draw_create(cell);
  209. cell_init_vbuf(cell);
  210. draw_set_rasterize_stage(cell->draw, cell->vbuf);
  211. /*
  212. * SPU stuff
  213. */
  214. cell->num_spus = 6;
  215. cell_start_spus(cell);
  216. /* init command, vertex/index buffer info */
  217. for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) {
  218. cell->buffer_size[buf] = 0;
  219. /* init batch buffer status values,
  220. * mark 0th buffer as used, rest as free.
  221. */
  222. for (spu = 0; spu < cell->num_spus; spu++) {
  223. if (buf == 0)
  224. cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED;
  225. else
  226. cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_FREE;
  227. }
  228. }
  229. return &cell->pipe;
  230. }