Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2003 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 | |
Eric Anholt | f6ca4a3 | 2011-03-09 12:54:14 -0800 | [diff] [blame] | 28 | #include <errno.h> |
Brian Paul | ecadb51 | 2008-09-18 15:17:05 -0600 | [diff] [blame] | 29 | #include "main/glheader.h" |
| 30 | #include "main/context.h" |
| 31 | #include "main/framebuffer.h" |
Brian Paul | ecadb51 | 2008-09-18 15:17:05 -0600 | [diff] [blame] | 32 | #include "main/renderbuffer.h" |
Kristian Høgsberg | 2d99588 | 2010-02-11 17:18:01 -0500 | [diff] [blame] | 33 | #include "main/hash.h" |
Kristian Høgsberg | d7322c9 | 2010-02-26 14:49:31 -0500 | [diff] [blame] | 34 | #include "main/fbobject.h" |
Vinson Lee | 45a56e4 | 2011-01-09 01:25:54 -0800 | [diff] [blame] | 35 | #include "main/mfeatures.h" |
Brian Paul | 14aff23 | 2012-01-02 15:20:04 -0700 | [diff] [blame] | 36 | #include "main/version.h" |
Brian Paul | d0dc75c | 2011-12-05 20:40:48 -0700 | [diff] [blame] | 37 | #include "swrast/s_renderbuffer.h" |
Brian Paul | 6c244b0 | 2009-01-26 12:38:46 -0700 | [diff] [blame] | 38 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 39 | #include "utils.h" |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 40 | #include "xmlpool.h" |
| 41 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 42 | PUBLIC const char __driConfigOptions[] = |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 43 | DRI_CONF_BEGIN |
| 44 | DRI_CONF_SECTION_PERFORMANCE |
Jesse Barnes | e9bf3e4 | 2008-07-31 11:50:37 -0700 | [diff] [blame] | 45 | DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC) |
Eric Anholt | fe91c05 | 2008-03-05 14:14:54 -0800 | [diff] [blame] | 46 | /* Options correspond to DRI_CONF_BO_REUSE_DISABLED, |
| 47 | * DRI_CONF_BO_REUSE_ALL |
| 48 | */ |
Dave Airlie | f75843a | 2008-08-24 17:59:10 +1000 | [diff] [blame] | 49 | DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1") |
Eric Anholt | fe91c05 | 2008-03-05 14:14:54 -0800 | [diff] [blame] | 50 | DRI_CONF_DESC_BEGIN(en, "Buffer object reuse") |
| 51 | DRI_CONF_ENUM(0, "Disable buffer object reuse") |
| 52 | DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects") |
| 53 | DRI_CONF_DESC_END |
| 54 | DRI_CONF_OPT_END |
Eric Anholt | 1ba9665 | 2009-06-03 16:40:20 +0000 | [diff] [blame] | 55 | |
Eric Anholt | 8e7a8d6 | 2010-03-03 11:51:51 -0800 | [diff] [blame] | 56 | DRI_CONF_OPT_BEGIN(texture_tiling, bool, true) |
| 57 | DRI_CONF_DESC(en, "Enable texture tiling") |
| 58 | DRI_CONF_OPT_END |
Eric Anholt | 1ba9665 | 2009-06-03 16:40:20 +0000 | [diff] [blame] | 59 | |
Eric Anholt | d09fce5 | 2012-03-06 11:05:20 -0800 | [diff] [blame] | 60 | DRI_CONF_OPT_BEGIN(hiz, bool, true) |
| 61 | DRI_CONF_DESC(en, "Enable Hierarchical Z on gen6+") |
| 62 | DRI_CONF_OPT_END |
| 63 | |
Eric Anholt | b30dc2c | 2009-06-09 16:12:43 -0700 | [diff] [blame] | 64 | DRI_CONF_OPT_BEGIN(early_z, bool, false) |
| 65 | DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).") |
| 66 | DRI_CONF_OPT_END |
| 67 | |
Eric Anholt | a58514c | 2010-08-17 15:07:22 -0700 | [diff] [blame] | 68 | DRI_CONF_OPT_BEGIN(fragment_shader, bool, true) |
Eric Anholt | 862a2a5 | 2009-07-29 13:00:09 -0700 | [diff] [blame] | 69 | DRI_CONF_DESC(en, "Enable limited ARB_fragment_shader support on 915/945.") |
| 70 | DRI_CONF_OPT_END |
| 71 | |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 72 | DRI_CONF_SECTION_END |
| 73 | DRI_CONF_SECTION_QUALITY |
| 74 | DRI_CONF_FORCE_S3TC_ENABLE(false) |
Michel Dänzer | acba9c1 | 2008-04-29 18:43:28 +0200 | [diff] [blame] | 75 | DRI_CONF_ALLOW_LARGE_TEXTURES(2) |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 76 | DRI_CONF_SECTION_END |
| 77 | DRI_CONF_SECTION_DEBUG |
| 78 | DRI_CONF_NO_RAST(false) |
Eric Anholt | 40bc274 | 2009-03-05 17:18:49 -0800 | [diff] [blame] | 79 | DRI_CONF_ALWAYS_FLUSH_BATCH(false) |
Eric Anholt | f368728 | 2009-03-05 17:08:36 -0800 | [diff] [blame] | 80 | DRI_CONF_ALWAYS_FLUSH_CACHE(false) |
Eric Anholt | 6422478 | 2012-01-25 14:13:13 -0800 | [diff] [blame] | 81 | DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(false) |
Eric Anholt | 81aa5d7 | 2009-07-29 13:07:49 -0700 | [diff] [blame] | 82 | |
| 83 | DRI_CONF_OPT_BEGIN(stub_occlusion_query, bool, false) |
| 84 | DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.") |
| 85 | DRI_CONF_OPT_END |
Eric Anholt | c6abde2 | 2011-11-23 10:01:39 -0800 | [diff] [blame] | 86 | |
| 87 | DRI_CONF_OPT_BEGIN(shader_precompile, bool, false) |
| 88 | DRI_CONF_DESC(en, "Perform code generation at shader link time.") |
| 89 | DRI_CONF_OPT_END |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 90 | DRI_CONF_SECTION_END |
| 91 | DRI_CONF_END; |
| 92 | |
Eric Anholt | d09fce5 | 2012-03-06 11:05:20 -0800 | [diff] [blame] | 93 | const GLuint __driNConfigOptions = 14; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 94 | |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 95 | #include "intel_batchbuffer.h" |
| 96 | #include "intel_buffers.h" |
| 97 | #include "intel_bufmgr.h" |
| 98 | #include "intel_chipset.h" |
| 99 | #include "intel_fbo.h" |
Chad Versace | da2816a | 2011-11-16 14:04:25 -0800 | [diff] [blame] | 100 | #include "intel_mipmap_tree.h" |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 101 | #include "intel_screen.h" |
| 102 | #include "intel_tex.h" |
| 103 | #include "intel_regions.h" |
| 104 | |
| 105 | #include "i915_drm.h" |
| 106 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 107 | #ifdef USE_NEW_INTERFACE |
Eric Anholt | 85063f1 | 2008-02-13 16:08:19 -0800 | [diff] [blame] | 108 | static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 109 | #endif /*USE_NEW_INTERFACE */ |
| 110 | |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 111 | void |
| 112 | aub_dump_bmp(struct gl_context *ctx) |
| 113 | { |
| 114 | struct gl_framebuffer *fb = ctx->DrawBuffer; |
| 115 | |
| 116 | for (int i = 0; i < fb->_NumColorDrawBuffers; i++) { |
| 117 | struct intel_renderbuffer *irb = |
| 118 | intel_renderbuffer(fb->_ColorDrawBuffers[i]); |
| 119 | |
| 120 | if (irb && irb->mt) { |
| 121 | enum aub_dump_bmp_format format; |
| 122 | |
| 123 | switch (irb->Base.Base.Format) { |
| 124 | case MESA_FORMAT_ARGB8888: |
| 125 | case MESA_FORMAT_XRGB8888: |
| 126 | format = AUB_DUMP_BMP_FORMAT_ARGB_8888; |
| 127 | break; |
| 128 | default: |
| 129 | continue; |
| 130 | } |
| 131 | |
| 132 | drm_intel_gem_bo_aub_dump_bmp(irb->mt->region->bo, |
| 133 | irb->draw_x, |
| 134 | irb->draw_y, |
| 135 | irb->Base.Base.Width, |
| 136 | irb->Base.Base.Height, |
| 137 | format, |
| 138 | irb->mt->region->pitch * |
| 139 | irb->mt->region->cpp, |
| 140 | 0); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
Kristian Høgsberg | 6d48779 | 2008-02-14 22:12:51 -0500 | [diff] [blame] | 145 | static const __DRItexBufferExtension intelTexBufferExtension = { |
| 146 | { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, |
| 147 | intelSetTexBuffer, |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 148 | intelSetTexBuffer2, |
Kristian Høgsberg | 6d48779 | 2008-02-14 22:12:51 -0500 | [diff] [blame] | 149 | }; |
| 150 | |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 151 | static void |
| 152 | intelDRI2Flush(__DRIdrawable *drawable) |
| 153 | { |
Eric Anholt | dea5e57 | 2011-02-14 18:57:49 -0800 | [diff] [blame] | 154 | GET_CURRENT_CONTEXT(ctx); |
| 155 | struct intel_context *intel = intel_context(ctx); |
Anuj Phogat | ce1c949 | 2012-01-17 13:21:52 -0800 | [diff] [blame] | 156 | if (intel == NULL) |
| 157 | return; |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 158 | |
Anuj Phogat | ce1c949 | 2012-01-17 13:21:52 -0800 | [diff] [blame] | 159 | if (intel->gen < 4) |
| 160 | INTEL_FIREVERTICES(intel); |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 161 | |
Anuj Phogat | ce1c949 | 2012-01-17 13:21:52 -0800 | [diff] [blame] | 162 | intel->need_throttle = true; |
Kristian Høgsberg | e67c338 | 2010-05-18 21:50:44 -0400 | [diff] [blame] | 163 | |
Anuj Phogat | ce1c949 | 2012-01-17 13:21:52 -0800 | [diff] [blame] | 164 | if (intel->batch.used) |
| 165 | intel_batchbuffer_flush(intel); |
Eric Anholt | 0247d89 | 2012-03-06 15:31:42 -0800 | [diff] [blame] | 166 | |
| 167 | if (INTEL_DEBUG & DEBUG_AUB) { |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 168 | aub_dump_bmp(ctx); |
Eric Anholt | 0247d89 | 2012-03-06 15:31:42 -0800 | [diff] [blame] | 169 | } |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 172 | static const struct __DRI2flushExtensionRec intelFlushExtension = { |
| 173 | { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, |
| 174 | intelDRI2Flush, |
Kristian Høgsberg | e67c338 | 2010-05-18 21:50:44 -0400 | [diff] [blame] | 175 | dri2InvalidateDrawable, |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 176 | }; |
| 177 | |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 178 | static __DRIimage * |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 179 | intel_create_image_from_name(__DRIscreen *screen, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 180 | int width, int height, int format, |
| 181 | int name, int pitch, void *loaderPrivate) |
| 182 | { |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 183 | struct intel_screen *intelScreen = screen->driverPrivate; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 184 | __DRIimage *image; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 185 | int cpp; |
| 186 | |
| 187 | image = CALLOC(sizeof *image); |
| 188 | if (image == NULL) |
| 189 | return NULL; |
| 190 | |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 191 | image->dri_format = format; |
| 192 | |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 193 | switch (format) { |
| 194 | case __DRI_IMAGE_FORMAT_RGB565: |
| 195 | image->format = MESA_FORMAT_RGB565; |
| 196 | image->internal_format = GL_RGB; |
| 197 | image->data_type = GL_UNSIGNED_BYTE; |
| 198 | break; |
| 199 | case __DRI_IMAGE_FORMAT_XRGB8888: |
| 200 | image->format = MESA_FORMAT_XRGB8888; |
| 201 | image->internal_format = GL_RGB; |
| 202 | image->data_type = GL_UNSIGNED_BYTE; |
| 203 | break; |
| 204 | case __DRI_IMAGE_FORMAT_ARGB8888: |
| 205 | image->format = MESA_FORMAT_ARGB8888; |
| 206 | image->internal_format = GL_RGBA; |
| 207 | image->data_type = GL_UNSIGNED_BYTE; |
| 208 | break; |
Chia-I Wu | 9fe197c | 2011-08-21 21:36:40 +0800 | [diff] [blame] | 209 | case __DRI_IMAGE_FORMAT_ABGR8888: |
| 210 | image->format = MESA_FORMAT_RGBA8888_REV; |
| 211 | image->internal_format = GL_RGBA; |
| 212 | image->data_type = GL_UNSIGNED_BYTE; |
| 213 | break; |
Sean V Kelley | fd0082c | 2012-04-24 07:49:10 -0700 | [diff] [blame^] | 214 | case __DRI_IMAGE_FORMAT_XBGR8888: |
| 215 | image->format = MESA_FORMAT_RGBX8888_REV; |
| 216 | image->internal_format = GL_RGB; |
| 217 | image->data_type = GL_UNSIGNED_BYTE; |
| 218 | break; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 219 | default: |
| 220 | free(image); |
| 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | image->data = loaderPrivate; |
| 225 | cpp = _mesa_get_format_bytes(image->format); |
| 226 | |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 227 | image->region = intel_region_alloc_for_handle(intelScreen, |
Kristian Høgsberg | 9087ba1 | 2010-06-03 21:56:21 -0400 | [diff] [blame] | 228 | cpp, width, height, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 229 | pitch, name, "image"); |
| 230 | if (image->region == NULL) { |
| 231 | FREE(image); |
| 232 | return NULL; |
| 233 | } |
| 234 | |
| 235 | return image; |
| 236 | } |
| 237 | |
| 238 | static __DRIimage * |
| 239 | intel_create_image_from_renderbuffer(__DRIcontext *context, |
| 240 | int renderbuffer, void *loaderPrivate) |
| 241 | { |
| 242 | __DRIimage *image; |
| 243 | struct intel_context *intel = context->driverPrivate; |
| 244 | struct gl_renderbuffer *rb; |
| 245 | struct intel_renderbuffer *irb; |
| 246 | |
Kristian Høgsberg | d7322c9 | 2010-02-26 14:49:31 -0500 | [diff] [blame] | 247 | rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 248 | if (!rb) { |
| 249 | _mesa_error(&intel->ctx, |
| 250 | GL_INVALID_OPERATION, "glRenderbufferExternalMESA"); |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | irb = intel_renderbuffer(rb); |
| 255 | image = CALLOC(sizeof *image); |
| 256 | if (image == NULL) |
| 257 | return NULL; |
| 258 | |
| 259 | image->internal_format = rb->InternalFormat; |
| 260 | image->format = rb->Format; |
Brian Paul | f9874fe | 2012-01-16 12:03:09 -0700 | [diff] [blame] | 261 | image->data_type = GL_UNSIGNED_BYTE; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 262 | image->data = loaderPrivate; |
Chad Versace | da2816a | 2011-11-16 14:04:25 -0800 | [diff] [blame] | 263 | intel_region_reference(&image->region, irb->mt->region); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 264 | |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 265 | switch (image->format) { |
| 266 | case MESA_FORMAT_RGB565: |
| 267 | image->dri_format = __DRI_IMAGE_FORMAT_RGB565; |
| 268 | break; |
| 269 | case MESA_FORMAT_XRGB8888: |
| 270 | image->dri_format = __DRI_IMAGE_FORMAT_XRGB8888; |
| 271 | break; |
| 272 | case MESA_FORMAT_ARGB8888: |
| 273 | image->dri_format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 274 | break; |
| 275 | case MESA_FORMAT_RGBA8888_REV: |
| 276 | image->dri_format = __DRI_IMAGE_FORMAT_ABGR8888; |
| 277 | break; |
| 278 | } |
| 279 | |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 280 | return image; |
| 281 | } |
| 282 | |
| 283 | static void |
| 284 | intel_destroy_image(__DRIimage *image) |
| 285 | { |
| 286 | intel_region_release(&image->region); |
| 287 | FREE(image); |
| 288 | } |
| 289 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 290 | static __DRIimage * |
| 291 | intel_create_image(__DRIscreen *screen, |
| 292 | int width, int height, int format, |
| 293 | unsigned int use, |
| 294 | void *loaderPrivate) |
| 295 | { |
| 296 | __DRIimage *image; |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 297 | struct intel_screen *intelScreen = screen->driverPrivate; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 298 | uint32_t tiling; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 299 | int cpp; |
| 300 | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 301 | tiling = I915_TILING_X; |
| 302 | if (use & __DRI_IMAGE_USE_CURSOR) { |
| 303 | if (width != 64 || height != 64) |
| 304 | return NULL; |
| 305 | tiling = I915_TILING_NONE; |
| 306 | } |
| 307 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 308 | image = CALLOC(sizeof *image); |
| 309 | if (image == NULL) |
| 310 | return NULL; |
| 311 | |
Jesse Barnes | 8de5c35 | 2012-02-21 12:53:09 -0800 | [diff] [blame] | 312 | image->dri_format = format; |
| 313 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 314 | switch (format) { |
| 315 | case __DRI_IMAGE_FORMAT_RGB565: |
| 316 | image->format = MESA_FORMAT_RGB565; |
| 317 | image->internal_format = GL_RGB; |
| 318 | image->data_type = GL_UNSIGNED_BYTE; |
| 319 | break; |
| 320 | case __DRI_IMAGE_FORMAT_XRGB8888: |
| 321 | image->format = MESA_FORMAT_XRGB8888; |
| 322 | image->internal_format = GL_RGB; |
| 323 | image->data_type = GL_UNSIGNED_BYTE; |
| 324 | break; |
| 325 | case __DRI_IMAGE_FORMAT_ARGB8888: |
| 326 | image->format = MESA_FORMAT_ARGB8888; |
| 327 | image->internal_format = GL_RGBA; |
| 328 | image->data_type = GL_UNSIGNED_BYTE; |
| 329 | break; |
Chia-I Wu | 9fe197c | 2011-08-21 21:36:40 +0800 | [diff] [blame] | 330 | case __DRI_IMAGE_FORMAT_ABGR8888: |
| 331 | image->format = MESA_FORMAT_RGBA8888_REV; |
| 332 | image->internal_format = GL_RGBA; |
| 333 | image->data_type = GL_UNSIGNED_BYTE; |
| 334 | break; |
Sean V Kelley | fd0082c | 2012-04-24 07:49:10 -0700 | [diff] [blame^] | 335 | case __DRI_IMAGE_FORMAT_XBGR8888: |
| 336 | image->format = MESA_FORMAT_RGBX8888_REV; |
| 337 | image->internal_format = GL_RGB; |
| 338 | image->data_type = GL_UNSIGNED_BYTE; |
| 339 | break; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 340 | default: |
| 341 | free(image); |
| 342 | return NULL; |
| 343 | } |
| 344 | |
| 345 | image->data = loaderPrivate; |
| 346 | cpp = _mesa_get_format_bytes(image->format); |
| 347 | |
| 348 | image->region = |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 349 | intel_region_alloc(intelScreen, tiling, |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 350 | cpp, width, height, true); |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 351 | if (image->region == NULL) { |
| 352 | FREE(image); |
| 353 | return NULL; |
| 354 | } |
| 355 | |
| 356 | return image; |
| 357 | } |
| 358 | |
| 359 | static GLboolean |
| 360 | intel_query_image(__DRIimage *image, int attrib, int *value) |
| 361 | { |
| 362 | switch (attrib) { |
| 363 | case __DRI_IMAGE_ATTRIB_STRIDE: |
| 364 | *value = image->region->pitch * image->region->cpp; |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 365 | return true; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 366 | case __DRI_IMAGE_ATTRIB_HANDLE: |
Eric Anholt | 8004a1c | 2011-09-22 11:58:37 -0700 | [diff] [blame] | 367 | *value = image->region->bo->handle; |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 368 | return true; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 369 | case __DRI_IMAGE_ATTRIB_NAME: |
| 370 | return intel_region_flink(image->region, (uint32_t *) value); |
Jesse Barnes | 8de5c35 | 2012-02-21 12:53:09 -0800 | [diff] [blame] | 371 | case __DRI_IMAGE_ATTRIB_FORMAT: |
Ander Conselvan de Oliveira | fc7d224 | 2012-04-26 16:21:19 +0300 | [diff] [blame] | 372 | *value = image->dri_format; |
| 373 | return true; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 374 | default: |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 375 | return false; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 379 | static __DRIimage * |
| 380 | intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) |
| 381 | { |
| 382 | __DRIimage *image; |
| 383 | |
| 384 | image = CALLOC(sizeof *image); |
| 385 | if (image == NULL) |
| 386 | return NULL; |
| 387 | |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 388 | intel_region_reference(&image->region, orig_image->region); |
| 389 | if (image->region == NULL) { |
| 390 | FREE(image); |
| 391 | return NULL; |
| 392 | } |
| 393 | |
| 394 | image->internal_format = orig_image->internal_format; |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 395 | image->dri_format = orig_image->dri_format; |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 396 | image->format = orig_image->format; |
| 397 | image->data_type = orig_image->data_type; |
| 398 | image->data = loaderPrivate; |
| 399 | |
| 400 | return image; |
| 401 | } |
| 402 | |
Kristian Høgsberg | 221c678 | 2012-01-18 15:32:35 -0500 | [diff] [blame] | 403 | static GLboolean |
| 404 | intel_validate_usage(__DRIimage *image, unsigned int use) |
| 405 | { |
| 406 | if (use & __DRI_IMAGE_USE_CURSOR) { |
| 407 | if (image->region->width != 64 || image->region->height != 64) |
| 408 | return GL_FALSE; |
| 409 | } |
| 410 | |
| 411 | return GL_TRUE; |
| 412 | } |
| 413 | |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 414 | static struct __DRIimageExtensionRec intelImageExtension = { |
Jesse Barnes | 0beed7f | 2012-02-22 09:52:09 -0800 | [diff] [blame] | 415 | { __DRI_IMAGE, 3 }, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 416 | intel_create_image_from_name, |
| 417 | intel_create_image_from_renderbuffer, |
| 418 | intel_destroy_image, |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 419 | intel_create_image, |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 420 | intel_query_image, |
Kristian Høgsberg | 221c678 | 2012-01-18 15:32:35 -0500 | [diff] [blame] | 421 | intel_dup_image, |
| 422 | intel_validate_usage |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 423 | }; |
| 424 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 425 | static const __DRIextension *intelScreenExtensions[] = { |
Kristian Høgsberg | 6d48779 | 2008-02-14 22:12:51 -0500 | [diff] [blame] | 426 | &intelTexBufferExtension.base, |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 427 | &intelFlushExtension.base, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 428 | &intelImageExtension.base, |
Jesse Barnes | 234286c | 2010-04-22 12:47:41 -0700 | [diff] [blame] | 429 | &dri2ConfigQueryExtension.base, |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 430 | NULL |
| 431 | }; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 432 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 433 | static bool |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 434 | intel_get_param(__DRIscreen *psp, int param, int *value) |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 435 | { |
| 436 | int ret; |
Alan Hourihane | 1c718c0 | 2008-02-22 00:18:54 +0000 | [diff] [blame] | 437 | struct drm_i915_getparam gp; |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 438 | |
Eric Anholt | f33d100 | 2012-02-16 11:30:49 -0800 | [diff] [blame] | 439 | memset(&gp, 0, sizeof(gp)); |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 440 | gp.param = param; |
| 441 | gp.value = value; |
| 442 | |
Alan Hourihane | 1c718c0 | 2008-02-22 00:18:54 +0000 | [diff] [blame] | 443 | ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 444 | if (ret) { |
Eric Anholt | f6ca4a3 | 2011-03-09 12:54:14 -0800 | [diff] [blame] | 445 | if (ret != -EINVAL) |
| 446 | _mesa_warning(NULL, "drm_i915_getparam: %d", ret); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 447 | return false; |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 448 | } |
| 449 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 450 | return true; |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 451 | } |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 452 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 453 | static bool |
Chris Wilson | 900a5c9 | 2011-03-01 14:46:50 +0000 | [diff] [blame] | 454 | intel_get_boolean(__DRIscreen *psp, int param) |
| 455 | { |
| 456 | int value = 0; |
| 457 | return intel_get_param(psp, param, &value) && value; |
| 458 | } |
| 459 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 460 | static void |
Kristian Høgsberg | 2d99588 | 2010-02-11 17:18:01 -0500 | [diff] [blame] | 461 | nop_callback(GLuint key, void *data, void *userData) |
| 462 | { |
| 463 | } |
| 464 | |
| 465 | static void |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 466 | intelDestroyScreen(__DRIscreen * sPriv) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 467 | { |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 468 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 469 | |
Eric Anholt | 904f31a | 2008-09-16 17:01:06 -0700 | [diff] [blame] | 470 | dri_bufmgr_destroy(intelScreen->bufmgr); |
Eric Anholt | 6d66f23 | 2009-07-02 13:30:20 -0700 | [diff] [blame] | 471 | driDestroyOptionInfo(&intelScreen->optionCache); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 472 | |
Kristian Høgsberg | 2d99588 | 2010-02-11 17:18:01 -0500 | [diff] [blame] | 473 | /* Some regions may still have references to them at this point, so |
| 474 | * flush the hash table to prevent _mesa_DeleteHashTable() from |
| 475 | * complaining about the hash not being empty; */ |
| 476 | _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL); |
| 477 | _mesa_DeleteHashTable(intelScreen->named_regions); |
| 478 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 479 | FREE(intelScreen); |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 480 | sPriv->driverPrivate = NULL; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
| 484 | /** |
| 485 | * This is called when we need to set up GL rendering to a new X window. |
| 486 | */ |
| 487 | static GLboolean |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 488 | intelCreateBuffer(__DRIscreen * driScrnPriv, |
| 489 | __DRIdrawable * driDrawPriv, |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 490 | const struct gl_config * mesaVis, GLboolean isPixmap) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 491 | { |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 492 | struct intel_renderbuffer *rb; |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 493 | struct intel_screen *screen = (struct intel_screen*) driScrnPriv->driverPrivate; |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 494 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 495 | if (isPixmap) { |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 496 | return false; /* not implemented */ |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 497 | } |
| 498 | else { |
Brian Paul | 4a25343 | 2009-10-29 19:12:50 -0600 | [diff] [blame] | 499 | gl_format rgbFormat; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 500 | |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 501 | struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer); |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 502 | |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 503 | if (!fb) |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 504 | return false; |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 505 | |
Francisco Jerez | 2ec50d2 | 2010-02-03 03:21:04 -0800 | [diff] [blame] | 506 | _mesa_initialize_window_framebuffer(fb, mesaVis); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 507 | |
Eric Anholt | 119f34e | 2009-02-25 22:54:51 -0800 | [diff] [blame] | 508 | if (mesaVis->redBits == 5) |
Brian Paul | 4a25343 | 2009-10-29 19:12:50 -0600 | [diff] [blame] | 509 | rgbFormat = MESA_FORMAT_RGB565; |
Eric Anholt | 119f34e | 2009-02-25 22:54:51 -0800 | [diff] [blame] | 510 | else if (mesaVis->alphaBits == 0) |
Brian Paul | 409469f | 2009-10-30 09:12:11 -0600 | [diff] [blame] | 511 | rgbFormat = MESA_FORMAT_XRGB8888; |
Eric Anholt | 119f34e | 2009-02-25 22:54:51 -0800 | [diff] [blame] | 512 | else |
Brian Paul | 4a25343 | 2009-10-29 19:12:50 -0600 | [diff] [blame] | 513 | rgbFormat = MESA_FORMAT_ARGB8888; |
Eric Anholt | 119f34e | 2009-02-25 22:54:51 -0800 | [diff] [blame] | 514 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 515 | /* setup the hardware-based renderbuffers */ |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 516 | rb = intel_create_renderbuffer(rgbFormat); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 517 | _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 518 | |
| 519 | if (mesaVis->doubleBufferMode) { |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 520 | rb = intel_create_renderbuffer(rgbFormat); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 521 | _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Chad Versace | f4efb7f | 2011-05-26 14:55:54 -0700 | [diff] [blame] | 524 | /* |
| 525 | * Assert here that the gl_config has an expected depth/stencil bit |
| 526 | * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(), |
| 527 | * which constructs the advertised configs.) |
| 528 | */ |
Eric Anholt | 38c6162 | 2007-11-08 14:49:37 -0800 | [diff] [blame] | 529 | if (mesaVis->depthBits == 24) { |
Eric Anholt | 800a4b2 | 2010-03-16 12:59:59 -0700 | [diff] [blame] | 530 | assert(mesaVis->stencilBits == 8); |
Chad Versace | aea2236 | 2011-06-03 16:33:32 -0700 | [diff] [blame] | 531 | |
| 532 | if (screen->hw_has_separate_stencil |
| 533 | && screen->dri2_has_hiz != INTEL_DRI2_HAS_HIZ_FALSE) { |
| 534 | /* |
| 535 | * Request a separate stencil buffer even if we do not yet know if |
| 536 | * the screen supports it. (See comments for |
| 537 | * enum intel_dri2_has_hiz). |
| 538 | */ |
| 539 | rb = intel_create_renderbuffer(MESA_FORMAT_X8_Z24); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 540 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
Chad Versace | aea2236 | 2011-06-03 16:33:32 -0700 | [diff] [blame] | 541 | rb = intel_create_renderbuffer(MESA_FORMAT_S8); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 542 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
Chad Versace | aea2236 | 2011-06-03 16:33:32 -0700 | [diff] [blame] | 543 | } else { |
| 544 | /* |
| 545 | * Use combined depth/stencil. Note that the renderbuffer is |
| 546 | * attached to two attachment points. |
| 547 | */ |
| 548 | rb = intel_create_renderbuffer(MESA_FORMAT_S8_Z24); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 549 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
| 550 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
Chad Versace | aea2236 | 2011-06-03 16:33:32 -0700 | [diff] [blame] | 551 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 552 | } |
| 553 | else if (mesaVis->depthBits == 16) { |
Chad Versace | f4efb7f | 2011-05-26 14:55:54 -0700 | [diff] [blame] | 554 | assert(mesaVis->stencilBits == 0); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 555 | /* just 16-bit depth buffer, no hw stencil */ |
| 556 | struct intel_renderbuffer *depthRb |
Brian Paul | 4a25343 | 2009-10-29 19:12:50 -0600 | [diff] [blame] | 557 | = intel_create_renderbuffer(MESA_FORMAT_Z16); |
Brian Paul | 9f8ed9d | 2012-01-16 12:40:01 -0700 | [diff] [blame] | 558 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base.Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 559 | } |
Chad Versace | f4efb7f | 2011-05-26 14:55:54 -0700 | [diff] [blame] | 560 | else { |
| 561 | assert(mesaVis->depthBits == 0); |
| 562 | assert(mesaVis->stencilBits == 0); |
| 563 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 564 | |
| 565 | /* now add any/all software-based renderbuffers we may need */ |
Brian Paul | d0dc75c | 2011-12-05 20:40:48 -0700 | [diff] [blame] | 566 | _swrast_add_soft_renderbuffers(fb, |
| 567 | false, /* never sw color */ |
| 568 | false, /* never sw depth */ |
| 569 | false, /* never sw stencil */ |
| 570 | mesaVis->accumRedBits > 0, |
| 571 | false, /* never sw alpha */ |
| 572 | false /* never sw aux */ ); |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 573 | driDrawPriv->driverPrivate = fb; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 574 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 575 | return true; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | static void |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 580 | intelDestroyBuffer(__DRIdrawable * driDrawPriv) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 581 | { |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 582 | struct gl_framebuffer *fb = driDrawPriv->driverPrivate; |
| 583 | |
| 584 | _mesa_reference_framebuffer(&fb, NULL); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 587 | /* There are probably better ways to do this, such as an |
| 588 | * init-designated function to register chipids and createcontext |
| 589 | * functions. |
| 590 | */ |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 591 | extern bool |
| 592 | i830CreateContext(const struct gl_config *mesaVis, |
| 593 | __DRIcontext *driContextPriv, |
| 594 | void *sharedContextPrivate); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 595 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 596 | extern bool |
| 597 | i915CreateContext(int api, |
| 598 | const struct gl_config *mesaVis, |
| 599 | __DRIcontext *driContextPriv, |
| 600 | void *sharedContextPrivate); |
| 601 | extern bool |
| 602 | brwCreateContext(int api, |
| 603 | const struct gl_config *mesaVis, |
| 604 | __DRIcontext *driContextPriv, |
| 605 | void *sharedContextPrivate); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 606 | |
| 607 | static GLboolean |
Kristian Høgsberg | a7a9a91 | 2010-04-27 11:04:51 -0400 | [diff] [blame] | 608 | intelCreateContext(gl_api api, |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 609 | const struct gl_config * mesaVis, |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 610 | __DRIcontext * driContextPriv, |
Ian Romanick | e532b62 | 2011-12-01 14:06:58 -0800 | [diff] [blame] | 611 | unsigned major_version, |
| 612 | unsigned minor_version, |
| 613 | uint32_t flags, |
| 614 | unsigned *error, |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 615 | void *sharedContextPrivate) |
| 616 | { |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 617 | __DRIscreen *sPriv = driContextPriv->driScreenPriv; |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 618 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
Eric Anholt | 35cdd7b | 2012-01-11 12:07:15 -0800 | [diff] [blame] | 619 | bool success = false; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 620 | |
Eric Anholt | bea6b5f | 2007-12-20 11:29:39 -0800 | [diff] [blame] | 621 | #ifdef I915 |
Eric Anholt | 19420e6 | 2008-02-15 13:16:01 -0800 | [diff] [blame] | 622 | if (IS_9XX(intelScreen->deviceID)) { |
| 623 | if (!IS_965(intelScreen->deviceID)) { |
Ian Romanick | e532b62 | 2011-12-01 14:06:58 -0800 | [diff] [blame] | 624 | success = i915CreateContext(api, mesaVis, driContextPriv, |
| 625 | sharedContextPrivate); |
Eric Anholt | 19420e6 | 2008-02-15 13:16:01 -0800 | [diff] [blame] | 626 | } |
Eric Anholt | bea6b5f | 2007-12-20 11:29:39 -0800 | [diff] [blame] | 627 | } else { |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 628 | intelScreen->no_vbo = true; |
Ian Romanick | e532b62 | 2011-12-01 14:06:58 -0800 | [diff] [blame] | 629 | success = i830CreateContext(mesaVis, driContextPriv, |
| 630 | sharedContextPrivate); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 631 | } |
Eric Anholt | bea6b5f | 2007-12-20 11:29:39 -0800 | [diff] [blame] | 632 | #else |
| 633 | if (IS_965(intelScreen->deviceID)) |
Ian Romanick | e532b62 | 2011-12-01 14:06:58 -0800 | [diff] [blame] | 634 | success = brwCreateContext(api, mesaVis, |
| 635 | driContextPriv, |
| 636 | sharedContextPrivate); |
Eric Anholt | bea6b5f | 2007-12-20 11:29:39 -0800 | [diff] [blame] | 637 | #endif |
Ian Romanick | e532b62 | 2011-12-01 14:06:58 -0800 | [diff] [blame] | 638 | |
| 639 | if (success) { |
| 640 | struct gl_context *ctx = |
| 641 | (struct gl_context *) driContextPriv->driverPrivate; |
| 642 | |
| 643 | _mesa_compute_version(ctx); |
| 644 | if (ctx->VersionMajor > major_version |
| 645 | || (ctx->VersionMajor == major_version |
| 646 | && ctx->VersionMinor >= minor_version)) { |
| 647 | *error = __DRI_CTX_ERROR_BAD_VERSION; |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | intelDestroyContext(driContextPriv); |
| 652 | } else { |
| 653 | *error = __DRI_CTX_ERROR_NO_MEMORY; |
| 654 | fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID); |
| 655 | } |
| 656 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 657 | return false; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 660 | static bool |
Kristian Høgsberg | 5777dee | 2010-02-11 16:44:21 -0500 | [diff] [blame] | 661 | intel_init_bufmgr(struct intel_screen *intelScreen) |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 662 | { |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 663 | __DRIscreen *spriv = intelScreen->driScrnPriv; |
Eric Anholt | cb4ef34 | 2009-07-01 17:08:16 -0700 | [diff] [blame] | 664 | int num_fences = 0; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 665 | |
Eric Anholt | 2222aa0 | 2012-03-09 16:27:35 -0800 | [diff] [blame] | 666 | intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 667 | |
Eric Anholt | 827ba44 | 2009-11-18 18:15:25 +0100 | [diff] [blame] | 668 | intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ); |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 669 | if (intelScreen->bufmgr == NULL) { |
Eric Anholt | 827ba44 | 2009-11-18 18:15:25 +0100 | [diff] [blame] | 670 | fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", |
| 671 | __func__, __LINE__); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 672 | return false; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 673 | } |
| 674 | |
Eric Anholt | bb35000 | 2010-03-04 15:47:19 -0800 | [diff] [blame] | 675 | if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) || |
| 676 | num_fences == 0) { |
| 677 | fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 678 | return false; |
Eric Anholt | bb35000 | 2010-03-04 15:47:19 -0800 | [diff] [blame] | 679 | } |
Eric Anholt | e7aef00 | 2009-04-06 09:38:16 -0700 | [diff] [blame] | 680 | |
Eric Anholt | 06d1472 | 2010-03-02 18:04:40 -0800 | [diff] [blame] | 681 | drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr); |
| 682 | |
Kristian Høgsberg | 2d99588 | 2010-02-11 17:18:01 -0500 | [diff] [blame] | 683 | intelScreen->named_regions = _mesa_NewHashTable(); |
| 684 | |
Chris Wilson | 900a5c9 | 2011-03-01 14:46:50 +0000 | [diff] [blame] | 685 | intelScreen->relaxed_relocations = 0; |
| 686 | intelScreen->relaxed_relocations |= |
| 687 | intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0; |
| 688 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 689 | return true; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 690 | } |
| 691 | |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 692 | /** |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 693 | * Override intel_screen.hw_has_separate_stencil with environment variable |
| 694 | * INTEL_SEPARATE_STENCIL. |
| 695 | * |
| 696 | * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid |
| 697 | * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL |
| 698 | * is ignored. |
| 699 | */ |
| 700 | static void |
| 701 | intel_override_separate_stencil(struct intel_screen *screen) |
| 702 | { |
| 703 | const char *s = getenv("INTEL_SEPARATE_STENCIL"); |
| 704 | if (!s) { |
| 705 | return; |
| 706 | } else if (!strncmp("0", s, 2)) { |
| 707 | screen->hw_has_separate_stencil = false; |
| 708 | } else if (!strncmp("1", s, 2)) { |
| 709 | screen->hw_has_separate_stencil = true; |
| 710 | } else { |
| 711 | fprintf(stderr, |
| 712 | "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has " |
| 713 | "invalid value and is ignored", s); |
| 714 | } |
| 715 | } |
| 716 | |
Daniel Vetter | f172eae | 2012-03-02 21:38:44 +0100 | [diff] [blame] | 717 | static bool |
| 718 | intel_detect_swizzling(struct intel_screen *screen) |
| 719 | { |
| 720 | drm_intel_bo *buffer; |
| 721 | unsigned long flags = 0; |
| 722 | unsigned long aligned_pitch; |
| 723 | uint32_t tiling = I915_TILING_X; |
| 724 | uint32_t swizzle_mode = 0; |
| 725 | |
| 726 | buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test", |
| 727 | 64, 64, 4, |
| 728 | &tiling, &aligned_pitch, flags); |
| 729 | if (buffer == NULL) |
| 730 | return false; |
| 731 | |
| 732 | drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode); |
| 733 | drm_intel_bo_unreference(buffer); |
| 734 | |
| 735 | if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE) |
| 736 | return false; |
| 737 | else |
| 738 | return true; |
| 739 | } |
| 740 | |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 741 | /** |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 742 | * This is the driver specific part of the createNewScreen entry point. |
Brian Paul | 8d976ae | 2008-06-11 19:33:14 -0600 | [diff] [blame] | 743 | * Called when using DRI2. |
| 744 | * |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 745 | * \return the struct gl_config supported by this driver |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 746 | */ |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 747 | static const |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 748 | __DRIconfig **intelInitScreen2(__DRIscreen *psp) |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 749 | { |
Kristian Høgsberg | 5777dee | 2010-02-11 16:44:21 -0500 | [diff] [blame] | 750 | struct intel_screen *intelScreen; |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 751 | GLenum fb_format[3]; |
| 752 | GLenum fb_type[3]; |
Kristian Høgsberg | 5efee4d | 2010-04-27 21:43:40 -0400 | [diff] [blame] | 753 | unsigned int api_mask; |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 754 | |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 755 | static const GLenum back_buffer_modes[] = { |
Ian Romanick | 6bd9da0 | 2010-02-08 13:11:58 -0800 | [diff] [blame] | 756 | GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 757 | }; |
Brian Paul | e135936 | 2009-02-09 11:16:20 -0700 | [diff] [blame] | 758 | uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1]; |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 759 | int color; |
Eric Anholt | 5d5ae37 | 2009-02-10 14:30:38 -0800 | [diff] [blame] | 760 | __DRIconfig **configs = NULL; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 761 | |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 762 | /* Allocate the private area */ |
Kristian Høgsberg | 5777dee | 2010-02-11 16:44:21 -0500 | [diff] [blame] | 763 | intelScreen = CALLOC(sizeof *intelScreen); |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 764 | if (!intelScreen) { |
| 765 | fprintf(stderr, "\nERROR! Allocating private area failed\n"); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 766 | return false; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 767 | } |
| 768 | /* parse information in __driConfigOptions */ |
| 769 | driParseOptionInfo(&intelScreen->optionCache, |
| 770 | __driConfigOptions, __driNConfigOptions); |
| 771 | |
| 772 | intelScreen->driScrnPriv = psp; |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 773 | psp->driverPrivate = (void *) intelScreen; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 774 | |
Eric Anholt | 2222aa0 | 2012-03-09 16:27:35 -0800 | [diff] [blame] | 775 | if (!intel_init_bufmgr(intelScreen)) |
| 776 | return false; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 777 | |
Eric Anholt | 2222aa0 | 2012-03-09 16:27:35 -0800 | [diff] [blame] | 778 | intelScreen->deviceID = drm_intel_bufmgr_gem_get_devid(intelScreen->bufmgr); |
Eric Anholt | 4ac2f09 | 2010-12-02 18:25:45 -0800 | [diff] [blame] | 779 | |
Eric Anholt | cd2a24a | 2011-12-29 23:37:17 -0800 | [diff] [blame] | 780 | intelScreen->kernel_has_gen7_sol_reset = |
| 781 | intel_get_boolean(intelScreen->driScrnPriv, |
| 782 | I915_PARAM_HAS_GEN7_SOL_RESET); |
| 783 | |
Kenneth Graunke | 89a82d7 | 2011-05-16 15:19:22 -0700 | [diff] [blame] | 784 | if (IS_GEN7(intelScreen->deviceID)) { |
| 785 | intelScreen->gen = 7; |
| 786 | } else if (IS_GEN6(intelScreen->deviceID)) { |
Kristian Høgsberg | 7363088 | 2011-04-25 09:49:09 -0400 | [diff] [blame] | 787 | intelScreen->gen = 6; |
| 788 | } else if (IS_GEN5(intelScreen->deviceID)) { |
| 789 | intelScreen->gen = 5; |
| 790 | } else if (IS_965(intelScreen->deviceID)) { |
| 791 | intelScreen->gen = 4; |
| 792 | } else if (IS_9XX(intelScreen->deviceID)) { |
| 793 | intelScreen->gen = 3; |
| 794 | } else { |
| 795 | intelScreen->gen = 2; |
| 796 | } |
| 797 | |
Chad Versace | e5411d8 | 2011-11-17 08:53:39 -0800 | [diff] [blame] | 798 | intelScreen->hw_has_separate_stencil = intelScreen->gen >= 6; |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 799 | intelScreen->hw_must_use_separate_stencil = intelScreen->gen >= 7; |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 800 | intelScreen->dri2_has_hiz = INTEL_DRI2_HAS_HIZ_UNKNOWN; |
| 801 | |
Eric Anholt | 249fc70 | 2012-03-21 14:35:14 -0700 | [diff] [blame] | 802 | int has_llc = 0; |
| 803 | bool success = intel_get_param(intelScreen->driScrnPriv, I915_PARAM_HAS_LLC, |
| 804 | &has_llc); |
| 805 | if (success && has_llc) |
| 806 | intelScreen->hw_has_llc = true; |
| 807 | else if (!success && intelScreen->gen >= 6) |
| 808 | intelScreen->hw_has_llc = true; |
Eugeni Dodonov | 7def293 | 2012-02-01 18:06:53 -0200 | [diff] [blame] | 809 | |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 810 | intel_override_separate_stencil(intelScreen); |
| 811 | |
Kristian Høgsberg | 5efee4d | 2010-04-27 21:43:40 -0400 | [diff] [blame] | 812 | api_mask = (1 << __DRI_API_OPENGL); |
| 813 | #if FEATURE_ES1 |
| 814 | api_mask |= (1 << __DRI_API_GLES); |
| 815 | #endif |
| 816 | #if FEATURE_ES2 |
| 817 | api_mask |= (1 << __DRI_API_GLES2); |
| 818 | #endif |
| 819 | |
| 820 | if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID)) |
| 821 | psp->api_mask = api_mask; |
| 822 | |
Daniel Vetter | f172eae | 2012-03-02 21:38:44 +0100 | [diff] [blame] | 823 | intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen); |
| 824 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 825 | psp->extensions = intelScreenExtensions; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 826 | |
Michel Dänzer | eaf15db | 2009-02-10 13:47:49 +0100 | [diff] [blame] | 827 | msaa_samples_array[0] = 0; |
| 828 | |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 829 | fb_format[0] = GL_RGB; |
| 830 | fb_type[0] = GL_UNSIGNED_SHORT_5_6_5; |
| 831 | |
Eric Anholt | 24ff169 | 2009-01-31 10:32:34 -0800 | [diff] [blame] | 832 | fb_format[1] = GL_BGR; |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 833 | fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV; |
| 834 | |
Eric Anholt | 24ff169 | 2009-01-31 10:32:34 -0800 | [diff] [blame] | 835 | fb_format[2] = GL_BGRA; |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 836 | fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV; |
| 837 | |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 838 | depth_bits[0] = 0; |
| 839 | stencil_bits[0] = 0; |
| 840 | |
Ian Romanick | bb65a1d | 2010-02-08 11:21:29 -0800 | [diff] [blame] | 841 | /* Generate a rich set of useful configs that do not include an |
| 842 | * accumulation buffer. |
| 843 | */ |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 844 | for (color = 0; color < ARRAY_SIZE(fb_format); color++) { |
Eric Anholt | 5d5ae37 | 2009-02-10 14:30:38 -0800 | [diff] [blame] | 845 | __DRIconfig **new_configs; |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 846 | int depth_factor; |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 847 | |
Ian Romanick | 066f45c | 2010-02-08 10:32:29 -0800 | [diff] [blame] | 848 | /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil |
| 849 | * buffer that has a diffferent number of bits per pixel than the color |
| 850 | * buffer. This isn't yet supported here. |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 851 | */ |
| 852 | if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { |
| 853 | depth_bits[1] = 16; |
| 854 | stencil_bits[1] = 0; |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 855 | } else { |
| 856 | depth_bits[1] = 24; |
Ian Romanick | 73e24cd | 2010-02-08 10:34:52 -0800 | [diff] [blame] | 857 | stencil_bits[1] = 8; |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 858 | } |
Ian Romanick | 73e24cd | 2010-02-08 10:34:52 -0800 | [diff] [blame] | 859 | |
| 860 | depth_factor = 2; |
| 861 | |
Eric Anholt | 5d5ae37 | 2009-02-10 14:30:38 -0800 | [diff] [blame] | 862 | new_configs = driCreateConfigs(fb_format[color], fb_type[color], |
| 863 | depth_bits, |
| 864 | stencil_bits, |
Eric Anholt | 160c361 | 2009-02-26 00:18:46 -0800 | [diff] [blame] | 865 | depth_factor, |
Eric Anholt | 5d5ae37 | 2009-02-10 14:30:38 -0800 | [diff] [blame] | 866 | back_buffer_modes, |
| 867 | ARRAY_SIZE(back_buffer_modes), |
| 868 | msaa_samples_array, |
Ian Romanick | 3cce4a1 | 2010-02-08 11:09:15 -0800 | [diff] [blame] | 869 | ARRAY_SIZE(msaa_samples_array), |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 870 | false); |
Ian Romanick | bb65a1d | 2010-02-08 11:21:29 -0800 | [diff] [blame] | 871 | if (configs == NULL) |
| 872 | configs = new_configs; |
| 873 | else |
| 874 | configs = driConcatConfigs(configs, new_configs); |
| 875 | } |
| 876 | |
| 877 | /* Generate the minimum possible set of configs that include an |
| 878 | * accumulation buffer. |
| 879 | */ |
| 880 | for (color = 0; color < ARRAY_SIZE(fb_format); color++) { |
| 881 | __DRIconfig **new_configs; |
| 882 | |
| 883 | if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { |
| 884 | depth_bits[0] = 16; |
| 885 | stencil_bits[0] = 0; |
| 886 | } else { |
| 887 | depth_bits[0] = 24; |
| 888 | stencil_bits[0] = 8; |
| 889 | } |
| 890 | |
| 891 | new_configs = driCreateConfigs(fb_format[color], fb_type[color], |
| 892 | depth_bits, stencil_bits, 1, |
| 893 | back_buffer_modes + 1, 1, |
| 894 | msaa_samples_array, 1, |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 895 | true); |
Eric Anholt | 3ee21f3 | 2009-01-29 14:57:49 -0800 | [diff] [blame] | 896 | if (configs == NULL) |
| 897 | configs = new_configs; |
| 898 | else |
| 899 | configs = driConcatConfigs(configs, new_configs); |
| 900 | } |
| 901 | |
| 902 | if (configs == NULL) { |
| 903 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
| 904 | __LINE__); |
| 905 | return NULL; |
| 906 | } |
| 907 | |
Eric Anholt | 5d5ae37 | 2009-02-10 14:30:38 -0800 | [diff] [blame] | 908 | return (const __DRIconfig **)configs; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 909 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 910 | |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 911 | struct intel_buffer { |
| 912 | __DRIbuffer base; |
| 913 | struct intel_region *region; |
| 914 | }; |
| 915 | |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 916 | /** |
| 917 | * \brief Get tiling format for a DRI buffer. |
| 918 | * |
| 919 | * \param attachment is the buffer's attachmet point, such as |
| 920 | * __DRI_BUFFER_DEPTH. |
| 921 | * \param out_tiling is the returned tiling format for buffer. |
| 922 | * \return false if attachment is unrecognized or is incompatible with screen. |
| 923 | */ |
| 924 | static bool |
| 925 | intel_get_dri_buffer_tiling(struct intel_screen *screen, |
| 926 | uint32_t attachment, |
| 927 | uint32_t *out_tiling) |
| 928 | { |
| 929 | if (screen->gen < 4) { |
| 930 | *out_tiling = I915_TILING_X; |
| 931 | return true; |
| 932 | } |
| 933 | |
| 934 | switch (attachment) { |
| 935 | case __DRI_BUFFER_DEPTH: |
| 936 | case __DRI_BUFFER_DEPTH_STENCIL: |
| 937 | case __DRI_BUFFER_HIZ: |
| 938 | *out_tiling = I915_TILING_Y; |
| 939 | return true; |
| 940 | case __DRI_BUFFER_ACCUM: |
| 941 | case __DRI_BUFFER_FRONT_LEFT: |
| 942 | case __DRI_BUFFER_FRONT_RIGHT: |
| 943 | case __DRI_BUFFER_BACK_LEFT: |
| 944 | case __DRI_BUFFER_BACK_RIGHT: |
| 945 | case __DRI_BUFFER_FAKE_FRONT_LEFT: |
| 946 | case __DRI_BUFFER_FAKE_FRONT_RIGHT: |
| 947 | *out_tiling = I915_TILING_X; |
| 948 | return true; |
| 949 | case __DRI_BUFFER_STENCIL: |
| 950 | /* The stencil buffer is W tiled. However, we request from the kernel |
| 951 | * a non-tiled buffer because the GTT is incapable of W fencing. |
| 952 | */ |
| 953 | *out_tiling = I915_TILING_NONE; |
| 954 | return true; |
| 955 | default: |
| 956 | if(unlikely(INTEL_DEBUG & DEBUG_DRI)) { |
| 957 | fprintf(stderr, "error: %s: unrecognized DRI buffer attachment 0x%x\n", |
| 958 | __FUNCTION__, attachment); |
| 959 | } |
| 960 | return false; |
| 961 | } |
| 962 | } |
| 963 | |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 964 | static __DRIbuffer * |
| 965 | intelAllocateBuffer(__DRIscreen *screen, |
| 966 | unsigned attachment, unsigned format, |
| 967 | int width, int height) |
| 968 | { |
| 969 | struct intel_buffer *intelBuffer; |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 970 | struct intel_screen *intelScreen = screen->driverPrivate; |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 971 | |
Kristian Høgsberg | 5dfba09 | 2011-04-25 09:53:22 -0400 | [diff] [blame] | 972 | uint32_t tiling; |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 973 | uint32_t region_width; |
| 974 | uint32_t region_height; |
| 975 | uint32_t region_cpp; |
| 976 | |
| 977 | bool ok = true; |
| 978 | |
| 979 | ok = intel_get_dri_buffer_tiling(intelScreen, attachment, &tiling); |
| 980 | if (!ok) |
| 981 | return NULL; |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 982 | |
| 983 | intelBuffer = CALLOC(sizeof *intelBuffer); |
| 984 | if (intelBuffer == NULL) |
| 985 | return NULL; |
| 986 | |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 987 | if (attachment == __DRI_BUFFER_STENCIL) { |
Paul Berry | a27c7d8 | 2012-04-06 12:14:28 -0700 | [diff] [blame] | 988 | /* Stencil buffers use W tiling, a tiling format that the DRM functions |
| 989 | * don't properly account for. Therefore, when we allocate a stencil |
| 990 | * buffer that is private to Mesa (see intel_miptree_create), we round |
| 991 | * the height and width up to the next multiple of the tile size (64x64) |
| 992 | * and then ask DRM to allocate an untiled buffer. Consequently, the |
| 993 | * height and the width stored in the stencil buffer's region structure |
| 994 | * are always multiples of 64, even if the stencil buffer itself is |
| 995 | * smaller. |
| 996 | * |
| 997 | * To avoid inconsistencies between how we represent private buffers and |
| 998 | * buffers shared with the window system, round up the height and width |
| 999 | * for window system buffers too. |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 1000 | */ |
| 1001 | region_width = ALIGN(width, 64); |
Paul Berry | a27c7d8 | 2012-04-06 12:14:28 -0700 | [diff] [blame] | 1002 | region_height = ALIGN(height, 64); |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 1003 | } else { |
| 1004 | region_width = width; |
| 1005 | region_height = height; |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 1006 | } |
Kristian Høgsberg | 5dfba09 | 2011-04-25 09:53:22 -0400 | [diff] [blame] | 1007 | |
Paul Berry | a27c7d8 | 2012-04-06 12:14:28 -0700 | [diff] [blame] | 1008 | region_cpp = format / 8; |
| 1009 | |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 1010 | intelBuffer->region = intel_region_alloc(intelScreen, |
| 1011 | tiling, |
| 1012 | region_cpp, |
| 1013 | region_width, |
| 1014 | region_height, |
| 1015 | true); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1016 | |
| 1017 | if (intelBuffer->region == NULL) { |
| 1018 | FREE(intelBuffer); |
| 1019 | return NULL; |
| 1020 | } |
| 1021 | |
| 1022 | intel_region_flink(intelBuffer->region, &intelBuffer->base.name); |
| 1023 | |
| 1024 | intelBuffer->base.attachment = attachment; |
| 1025 | intelBuffer->base.cpp = intelBuffer->region->cpp; |
| 1026 | intelBuffer->base.pitch = |
| 1027 | intelBuffer->region->pitch * intelBuffer->region->cpp; |
| 1028 | |
| 1029 | return &intelBuffer->base; |
| 1030 | } |
| 1031 | |
| 1032 | static void |
| 1033 | intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer) |
| 1034 | { |
| 1035 | struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; |
| 1036 | |
| 1037 | intel_region_release(&intelBuffer->region); |
| 1038 | free(intelBuffer); |
| 1039 | } |
| 1040 | |
| 1041 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1042 | const struct __DriverAPIRec driDriverAPI = { |
George Sapountzis | 7192c37 | 2011-11-03 12:46:08 +0200 | [diff] [blame] | 1043 | .InitScreen = intelInitScreen2, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1044 | .DestroyScreen = intelDestroyScreen, |
| 1045 | .CreateContext = intelCreateContext, |
| 1046 | .DestroyContext = intelDestroyContext, |
| 1047 | .CreateBuffer = intelCreateBuffer, |
| 1048 | .DestroyBuffer = intelDestroyBuffer, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1049 | .MakeCurrent = intelMakeCurrent, |
| 1050 | .UnbindContext = intelUnbindContext, |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1051 | .AllocateBuffer = intelAllocateBuffer, |
| 1052 | .ReleaseBuffer = intelReleaseBuffer |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1053 | }; |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1054 | |
| 1055 | /* This is the table of extensions that the loader will dlsym() for. */ |
| 1056 | PUBLIC const __DRIextension *__driDriverExtensions[] = { |
| 1057 | &driCoreExtension.base, |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1058 | &driDRI2Extension.base, |
| 1059 | NULL |
| 1060 | }; |