José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2008 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 | |
| 29 | #include "util/u_memory.h" |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 30 | #include "util/u_math.h" |
| 31 | #include "util/u_cpu_detect.h" |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 32 | #include "util/u_format.h" |
José Fonseca | fe130a7 | 2010-04-06 22:49:57 +0100 | [diff] [blame] | 33 | #include "util/u_format_s3tc.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 34 | #include "pipe/p_defines.h" |
| 35 | #include "pipe/p_screen.h" |
Luca Barbieri | a508d2d | 2010-09-05 20:50:50 +0200 | [diff] [blame] | 36 | #include "draw/draw_context.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 37 | |
| 38 | #include "lp_texture.h" |
Brian Paul | 2876b68 | 2009-12-11 17:32:45 -0700 | [diff] [blame] | 39 | #include "lp_fence.h" |
José Fonseca | 08dd41f | 2009-08-23 05:52:20 +0100 | [diff] [blame] | 40 | #include "lp_jit.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 41 | #include "lp_screen.h" |
Keith Whitwell | 7f41f54 | 2010-02-08 12:55:59 +0000 | [diff] [blame] | 42 | #include "lp_context.h" |
Keith Whitwell | dec35d0 | 2009-10-09 14:59:35 +0100 | [diff] [blame] | 43 | #include "lp_debug.h" |
Keith Whitwell | 3c57c01 | 2010-03-09 15:25:42 +0000 | [diff] [blame] | 44 | #include "lp_public.h" |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 45 | #include "lp_limits.h" |
Roland Scheidegger | edac740 | 2010-07-13 19:58:58 +0200 | [diff] [blame] | 46 | #include "lp_rast.h" |
Keith Whitwell | dec35d0 | 2009-10-09 14:59:35 +0100 | [diff] [blame] | 47 | |
Keith Whitwell | 23e951d | 2010-03-04 16:23:05 +0000 | [diff] [blame] | 48 | #include "state_tracker/sw_winsys.h" |
| 49 | |
Keith Whitwell | dec35d0 | 2009-10-09 14:59:35 +0100 | [diff] [blame] | 50 | #ifdef DEBUG |
| 51 | int LP_DEBUG = 0; |
| 52 | |
| 53 | static const struct debug_named_value lp_debug_flags[] = { |
Joakim Sindholt | 8413b92 | 2010-06-01 20:11:30 +0200 | [diff] [blame] | 54 | { "pipe", DEBUG_PIPE, NULL }, |
| 55 | { "tgsi", DEBUG_TGSI, NULL }, |
| 56 | { "tex", DEBUG_TEX, NULL }, |
| 57 | { "setup", DEBUG_SETUP, NULL }, |
| 58 | { "rast", DEBUG_RAST, NULL }, |
| 59 | { "query", DEBUG_QUERY, NULL }, |
| 60 | { "screen", DEBUG_SCREEN, NULL }, |
| 61 | { "show_tiles", DEBUG_SHOW_TILES, NULL }, |
| 62 | { "show_subtiles", DEBUG_SHOW_SUBTILES, NULL }, |
| 63 | { "counters", DEBUG_COUNTERS, NULL }, |
Keith Whitwell | b6e03ea | 2010-08-20 15:14:19 +0100 | [diff] [blame] | 64 | { "scene", DEBUG_SCENE, NULL }, |
| 65 | { "fence", DEBUG_FENCE, NULL }, |
Keith Whitwell | bc759cd | 2010-09-08 18:37:45 +0100 | [diff] [blame] | 66 | { "mem", DEBUG_MEM, NULL }, |
Keith Whitwell | 0986355 | 2010-09-16 15:16:27 +0100 | [diff] [blame] | 67 | { "fs", DEBUG_FS, NULL }, |
Joakim Sindholt | 8413b92 | 2010-06-01 20:11:30 +0200 | [diff] [blame] | 68 | DEBUG_NAMED_VALUE_END |
Keith Whitwell | dec35d0 | 2009-10-09 14:59:35 +0100 | [diff] [blame] | 69 | }; |
| 70 | #endif |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 71 | |
Keith Whitwell | 5f00819 | 2010-09-16 10:45:52 +0100 | [diff] [blame] | 72 | int LP_PERF = 0; |
| 73 | static const struct debug_named_value lp_perf_flags[] = { |
| 74 | { "texmem", PERF_TEX_MEM, NULL }, |
| 75 | { "no_mipmap", PERF_NO_MIPMAPS, NULL }, |
| 76 | { "no_linear", PERF_NO_LINEAR, NULL }, |
| 77 | { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL }, |
| 78 | { "no_tex", PERF_NO_TEX, NULL }, |
| 79 | { "no_blend", PERF_NO_BLEND, NULL }, |
| 80 | { "no_depth", PERF_NO_DEPTH, NULL }, |
| 81 | { "no_alphatest", PERF_NO_ALPHATEST, NULL }, |
| 82 | DEBUG_NAMED_VALUE_END |
| 83 | }; |
| 84 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 85 | |
| 86 | static const char * |
| 87 | llvmpipe_get_vendor(struct pipe_screen *screen) |
| 88 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 89 | return "VMware, Inc."; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
| 93 | static const char * |
| 94 | llvmpipe_get_name(struct pipe_screen *screen) |
| 95 | { |
| 96 | return "llvmpipe"; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | static int |
José Fonseca | e1238b5 | 2010-05-11 11:11:03 +0100 | [diff] [blame] | 101 | llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 102 | { |
| 103 | switch (param) { |
| 104 | case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: |
| 105 | return PIPE_MAX_SAMPLERS; |
| 106 | case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: |
Brian Paul | 4418a49 | 2010-08-26 11:45:25 -0600 | [diff] [blame] | 107 | /* At this time, the draw module and llvmpipe driver only |
| 108 | * support vertex shader texture lookups when LLVM is enabled in |
| 109 | * the draw module. |
| 110 | */ |
| 111 | if (debug_get_bool_option("DRAW_USE_LLVM", TRUE)) |
| 112 | return PIPE_MAX_VERTEX_SAMPLERS; |
| 113 | else |
| 114 | return 0; |
José Fonseca | c0a13bb | 2009-12-04 21:25:40 +0000 | [diff] [blame] | 115 | case PIPE_CAP_MAX_COMBINED_SAMPLERS: |
| 116 | return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 117 | case PIPE_CAP_NPOT_TEXTURES: |
| 118 | return 1; |
| 119 | case PIPE_CAP_TWO_SIDED_STENCIL: |
| 120 | return 1; |
| 121 | case PIPE_CAP_GLSL: |
| 122 | return 1; |
Jakob Bornecrantz | c4e89d1 | 2010-04-29 16:18:43 +0100 | [diff] [blame] | 123 | case PIPE_CAP_SM3: |
| 124 | return 1; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 125 | case PIPE_CAP_ANISOTROPIC_FILTER: |
| 126 | return 0; |
| 127 | case PIPE_CAP_POINT_SPRITE: |
| 128 | return 1; |
| 129 | case PIPE_CAP_MAX_RENDER_TARGETS: |
| 130 | return PIPE_MAX_COLOR_BUFS; |
| 131 | case PIPE_CAP_OCCLUSION_QUERY: |
| 132 | return 1; |
Mathias Fröhlich | cdbd5f4 | 2010-05-17 11:48:56 -0700 | [diff] [blame] | 133 | case PIPE_CAP_TIMER_QUERY: |
| 134 | return 0; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 135 | case PIPE_CAP_TEXTURE_MIRROR_CLAMP: |
| 136 | return 1; |
| 137 | case PIPE_CAP_TEXTURE_MIRROR_REPEAT: |
| 138 | return 1; |
| 139 | case PIPE_CAP_TEXTURE_SHADOW_MAP: |
| 140 | return 1; |
José Fonseca | 9881b5c | 2010-06-05 14:48:39 +0100 | [diff] [blame] | 141 | case PIPE_CAP_TEXTURE_SWIZZLE: |
| 142 | return 1; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 143 | case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: |
Brian Paul | d73fadf | 2010-03-08 13:36:34 -0700 | [diff] [blame] | 144 | return LP_MAX_TEXTURE_2D_LEVELS; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 145 | case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: |
Brian Paul | d73fadf | 2010-03-08 13:36:34 -0700 | [diff] [blame] | 146 | return LP_MAX_TEXTURE_3D_LEVELS; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 147 | case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: |
Brian Paul | d73fadf | 2010-03-08 13:36:34 -0700 | [diff] [blame] | 148 | return LP_MAX_TEXTURE_2D_LEVELS; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 149 | case PIPE_CAP_BLEND_EQUATION_SEPARATE: |
| 150 | return 1; |
Roland Scheidegger | 1a9d01d | 2010-01-26 17:32:57 +0100 | [diff] [blame] | 151 | case PIPE_CAP_INDEP_BLEND_ENABLE: |
Brian Paul | 7b937cf | 2010-05-10 17:03:10 -0600 | [diff] [blame] | 152 | return 1; |
Roland Scheidegger | 1a9d01d | 2010-01-26 17:32:57 +0100 | [diff] [blame] | 153 | case PIPE_CAP_INDEP_BLEND_FUNC: |
| 154 | return 0; |
Luca Barbieri | 6c403750 | 2010-01-21 05:36:14 +0100 | [diff] [blame] | 155 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: |
| 156 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: |
| 157 | return 1; |
| 158 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: |
| 159 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: |
| 160 | return 0; |
Roland Scheidegger | 1e17178 | 2010-05-29 01:31:01 +0200 | [diff] [blame] | 161 | case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: |
| 162 | return 1; |
Marek Olšák | 1a3fa3e | 2010-07-21 22:31:59 +0200 | [diff] [blame] | 163 | case PIPE_CAP_DEPTH_CLAMP: |
| 164 | return 0; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 165 | default: |
| 166 | return 0; |
| 167 | } |
| 168 | } |
| 169 | |
Luca Barbieri | a508d2d | 2010-09-05 20:50:50 +0200 | [diff] [blame] | 170 | static int |
| 171 | llvmpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) |
| 172 | { |
| 173 | switch(shader) |
| 174 | { |
| 175 | case PIPE_SHADER_FRAGMENT: |
| 176 | return tgsi_exec_get_shader_param(param); |
| 177 | case PIPE_SHADER_VERTEX: |
| 178 | case PIPE_SHADER_GEOMETRY: |
| 179 | return draw_get_shader_param(shader, param); |
| 180 | default: |
| 181 | return 0; |
| 182 | } |
| 183 | } |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 184 | |
| 185 | static float |
José Fonseca | e1238b5 | 2010-05-11 11:11:03 +0100 | [diff] [blame] | 186 | llvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_cap param) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 187 | { |
| 188 | switch (param) { |
| 189 | case PIPE_CAP_MAX_LINE_WIDTH: |
| 190 | /* fall-through */ |
| 191 | case PIPE_CAP_MAX_LINE_WIDTH_AA: |
| 192 | return 255.0; /* arbitrary */ |
| 193 | case PIPE_CAP_MAX_POINT_WIDTH: |
| 194 | /* fall-through */ |
| 195 | case PIPE_CAP_MAX_POINT_WIDTH_AA: |
| 196 | return 255.0; /* arbitrary */ |
| 197 | case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: |
| 198 | return 16.0; /* not actually signficant at this time */ |
| 199 | case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: |
| 200 | return 16.0; /* arbitrary */ |
José Fonseca | cf9baf6 | 2010-05-12 17:25:17 +0100 | [diff] [blame] | 201 | case PIPE_CAP_GUARD_BAND_LEFT: |
| 202 | case PIPE_CAP_GUARD_BAND_TOP: |
| 203 | case PIPE_CAP_GUARD_BAND_RIGHT: |
| 204 | case PIPE_CAP_GUARD_BAND_BOTTOM: |
| 205 | return 0.0; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 206 | default: |
José Fonseca | a1b3ca6 | 2010-05-12 14:10:23 +0100 | [diff] [blame] | 207 | assert(0); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /** |
| 214 | * Query format support for creating a texture, drawing surface, etc. |
| 215 | * \param format the format to test |
| 216 | * \param type one of PIPE_TEXTURE, PIPE_SURFACE |
| 217 | */ |
| 218 | static boolean |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 219 | llvmpipe_is_format_supported( struct pipe_screen *_screen, |
Roland Scheidegger | e121a73 | 2010-05-17 21:23:31 +0200 | [diff] [blame] | 220 | enum pipe_format format, |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 221 | enum pipe_texture_target target, |
Roland Scheidegger | e121a73 | 2010-05-17 21:23:31 +0200 | [diff] [blame] | 222 | unsigned sample_count, |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 223 | unsigned bind, |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 224 | unsigned geom_flags ) |
| 225 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 226 | struct llvmpipe_screen *screen = llvmpipe_screen(_screen); |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame] | 227 | struct sw_winsys *winsys = screen->winsys; |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 228 | const struct util_format_description *format_desc; |
| 229 | |
| 230 | format_desc = util_format_description(format); |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 231 | if (!format_desc) |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 232 | return FALSE; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 233 | |
Brian Paul | e6d8b40 | 2010-05-28 13:31:23 -0600 | [diff] [blame] | 234 | assert(target == PIPE_BUFFER || |
| 235 | target == PIPE_TEXTURE_1D || |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 236 | target == PIPE_TEXTURE_2D || |
Luca Barbieri | ae0ef6f | 2010-08-18 17:28:08 +0200 | [diff] [blame] | 237 | target == PIPE_TEXTURE_RECT || |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 238 | target == PIPE_TEXTURE_3D || |
| 239 | target == PIPE_TEXTURE_CUBE); |
| 240 | |
Roland Scheidegger | e121a73 | 2010-05-17 21:23:31 +0200 | [diff] [blame] | 241 | if (sample_count > 1) |
| 242 | return FALSE; |
| 243 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 244 | if (bind & PIPE_BIND_RENDER_TARGET) { |
| 245 | if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) |
José Fonseca | fe130a7 | 2010-04-06 22:49:57 +0100 | [diff] [blame] | 246 | return FALSE; |
| 247 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 248 | if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) |
José Fonseca | fe130a7 | 2010-04-06 22:49:57 +0100 | [diff] [blame] | 249 | return FALSE; |
| 250 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 251 | if (format_desc->block.width != 1 || |
| 252 | format_desc->block.height != 1) |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 253 | return FALSE; |
| 254 | } |
| 255 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 256 | if (bind & PIPE_BIND_DISPLAY_TARGET) { |
| 257 | if(!winsys->is_displaytarget_format_supported(winsys, bind, format)) |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 258 | return FALSE; |
| 259 | } |
| 260 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 261 | if (bind & PIPE_BIND_DEPTH_STENCIL) { |
| 262 | if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) |
| 263 | return FALSE; |
| 264 | |
| 265 | if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 266 | return FALSE; |
| 267 | |
| 268 | /* FIXME: Temporary restriction. See lp_state_fs.c. */ |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 269 | if (format_desc->block.bits != 32) |
José Fonseca | b375526 | 2009-11-10 17:51:06 -0800 | [diff] [blame] | 270 | return FALSE; |
| 271 | } |
| 272 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 273 | if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { |
José Fonseca | 510669c | 2010-04-22 15:12:30 +0100 | [diff] [blame] | 274 | return util_format_s3tc_enabled; |
José Fonseca | 510669c | 2010-04-22 15:12:30 +0100 | [diff] [blame] | 275 | } |
| 276 | |
José Fonseca | adc7cd6 | 2010-04-25 14:52:27 +0100 | [diff] [blame] | 277 | /* |
| 278 | * Everything else should be supported by u_format. |
| 279 | */ |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 280 | return TRUE; |
| 281 | } |
| 282 | |
| 283 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 284 | |
| 285 | |
| 286 | static void |
| 287 | llvmpipe_flush_frontbuffer(struct pipe_screen *_screen, |
| 288 | struct pipe_surface *surface, |
| 289 | void *context_private) |
| 290 | { |
| 291 | struct llvmpipe_screen *screen = llvmpipe_screen(_screen); |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame] | 292 | struct sw_winsys *winsys = screen->winsys; |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 293 | struct llvmpipe_resource *texture = llvmpipe_resource(surface->texture); |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 294 | |
| 295 | assert(texture->dt); |
| 296 | if (texture->dt) |
| 297 | winsys->displaytarget_display(winsys, texture->dt, context_private); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | |
| 301 | static void |
José Fonseca | 2d6b39f | 2009-08-09 23:10:19 +0100 | [diff] [blame] | 302 | llvmpipe_destroy_screen( struct pipe_screen *_screen ) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 303 | { |
José Fonseca | 2d6b39f | 2009-08-09 23:10:19 +0100 | [diff] [blame] | 304 | struct llvmpipe_screen *screen = llvmpipe_screen(_screen); |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame] | 305 | struct sw_winsys *winsys = screen->winsys; |
José Fonseca | 2d6b39f | 2009-08-09 23:10:19 +0100 | [diff] [blame] | 306 | |
Roland Scheidegger | edac740 | 2010-07-13 19:58:58 +0200 | [diff] [blame] | 307 | if (screen->rast) |
| 308 | lp_rast_destroy(screen->rast); |
| 309 | |
José Fonseca | 08dd41f | 2009-08-23 05:52:20 +0100 | [diff] [blame] | 310 | lp_jit_screen_cleanup(screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 311 | |
| 312 | if(winsys->destroy) |
| 313 | winsys->destroy(winsys); |
| 314 | |
Roland Scheidegger | edac740 | 2010-07-13 19:58:58 +0200 | [diff] [blame] | 315 | pipe_mutex_destroy(screen->rast_mutex); |
| 316 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 317 | FREE(screen); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | |
Keith Whitwell | 5a45e53 | 2010-08-20 15:25:27 +0100 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * Fence reference counting. |
| 325 | */ |
| 326 | static void |
| 327 | llvmpipe_fence_reference(struct pipe_screen *screen, |
| 328 | struct pipe_fence_handle **ptr, |
| 329 | struct pipe_fence_handle *fence) |
| 330 | { |
| 331 | struct lp_fence **old = (struct lp_fence **) ptr; |
| 332 | struct lp_fence *f = (struct lp_fence *) fence; |
| 333 | |
| 334 | lp_fence_reference(old, f); |
| 335 | } |
| 336 | |
| 337 | |
| 338 | /** |
| 339 | * Has the fence been executed/finished? |
| 340 | */ |
| 341 | static int |
| 342 | llvmpipe_fence_signalled(struct pipe_screen *screen, |
| 343 | struct pipe_fence_handle *fence, |
| 344 | unsigned flag) |
| 345 | { |
| 346 | struct lp_fence *f = (struct lp_fence *) fence; |
| 347 | return lp_fence_signalled(f); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /** |
| 352 | * Wait for the fence to finish. |
| 353 | */ |
| 354 | static int |
| 355 | llvmpipe_fence_finish(struct pipe_screen *screen, |
| 356 | struct pipe_fence_handle *fence_handle, |
| 357 | unsigned flag) |
| 358 | { |
| 359 | struct lp_fence *f = (struct lp_fence *) fence_handle; |
| 360 | |
| 361 | lp_fence_wait(f); |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 367 | /** |
| 368 | * Create a new pipe_screen object |
| 369 | * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen). |
| 370 | */ |
| 371 | struct pipe_screen * |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame] | 372 | llvmpipe_create_screen(struct sw_winsys *winsys) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 373 | { |
Török Edwin | 4d52a25 | 2010-05-06 22:19:57 +0100 | [diff] [blame] | 374 | struct llvmpipe_screen *screen; |
| 375 | |
| 376 | #ifdef PIPE_ARCH_X86 |
| 377 | /* require SSE2 due to LLVM PR6960. */ |
| 378 | util_cpu_detect(); |
| 379 | if (!util_cpu_caps.has_sse2) |
| 380 | return NULL; |
| 381 | #endif |
| 382 | |
| 383 | screen = CALLOC_STRUCT(llvmpipe_screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 384 | |
Keith Whitwell | dec35d0 | 2009-10-09 14:59:35 +0100 | [diff] [blame] | 385 | #ifdef DEBUG |
| 386 | LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 ); |
| 387 | #endif |
| 388 | |
Keith Whitwell | 5f00819 | 2010-09-16 10:45:52 +0100 | [diff] [blame] | 389 | LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 ); |
| 390 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 391 | if (!screen) |
| 392 | return NULL; |
| 393 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 394 | screen->winsys = winsys; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 395 | |
| 396 | screen->base.destroy = llvmpipe_destroy_screen; |
| 397 | |
| 398 | screen->base.get_name = llvmpipe_get_name; |
| 399 | screen->base.get_vendor = llvmpipe_get_vendor; |
| 400 | screen->base.get_param = llvmpipe_get_param; |
Luca Barbieri | a508d2d | 2010-09-05 20:50:50 +0200 | [diff] [blame] | 401 | screen->base.get_shader_param = llvmpipe_get_shader_param; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 402 | screen->base.get_paramf = llvmpipe_get_paramf; |
| 403 | screen->base.is_format_supported = llvmpipe_is_format_supported; |
| 404 | |
Keith Whitwell | 7f41f54 | 2010-02-08 12:55:59 +0000 | [diff] [blame] | 405 | screen->base.context_create = llvmpipe_create_context; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 406 | screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; |
Keith Whitwell | 5a45e53 | 2010-08-20 15:25:27 +0100 | [diff] [blame] | 407 | screen->base.fence_reference = llvmpipe_fence_reference; |
| 408 | screen->base.fence_signalled = llvmpipe_fence_signalled; |
| 409 | screen->base.fence_finish = llvmpipe_fence_finish; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 410 | |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 411 | llvmpipe_init_screen_resource_funcs(&screen->base); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 412 | |
José Fonseca | 08dd41f | 2009-08-23 05:52:20 +0100 | [diff] [blame] | 413 | lp_jit_screen_init(screen); |
José Fonseca | 2d6b39f | 2009-08-09 23:10:19 +0100 | [diff] [blame] | 414 | |
José Fonseca | 65822eb | 2010-09-16 20:27:13 +0100 | [diff] [blame^] | 415 | screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0; |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 416 | #ifdef PIPE_OS_EMBEDDED |
| 417 | screen->num_threads = 0; |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 418 | #endif |
| 419 | screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads); |
| 420 | screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS); |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 421 | |
Roland Scheidegger | edac740 | 2010-07-13 19:58:58 +0200 | [diff] [blame] | 422 | screen->rast = lp_rast_create(screen->num_threads); |
| 423 | if (!screen->rast) { |
| 424 | lp_jit_screen_cleanup(screen); |
| 425 | FREE(screen); |
| 426 | return NULL; |
| 427 | } |
| 428 | pipe_mutex_init(screen->rast_mutex); |
| 429 | |
José Fonseca | 39be50d | 2010-04-24 13:20:39 +0100 | [diff] [blame] | 430 | util_format_s3tc_init(); |
| 431 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 432 | return &screen->base; |
| 433 | } |