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