Ian Romanick | aa1a5c0 | 2015-08-19 19:24:45 -0700 | [diff] [blame] | 1 | /* |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 2 | * Copyright 2003 VMware, Inc. |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 3 | * All Rights Reserved. |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 4 | * |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
Ian Romanick | 284dcad | 2015-08-19 16:36:35 -0700 | [diff] [blame] | 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 12 | * |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial portions |
| 15 | * of the Software. |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 16 | * |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Ian Romanick | 284dcad | 2015-08-19 16:36:35 -0700 | [diff] [blame] | 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 20 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Ian Romanick | aa1a5c0 | 2015-08-19 19:24:45 -0700 | [diff] [blame] | 24 | */ |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 25 | |
Eric Anholt | f6ca4a3 | 2011-03-09 12:54:14 -0800 | [diff] [blame] | 26 | #include <errno.h> |
Quentin Glidic | 7cb8764 | 2012-10-09 15:15:47 +0200 | [diff] [blame] | 27 | #include <time.h> |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 28 | #include <unistd.h> |
Brian Paul | ecadb51 | 2008-09-18 15:17:05 -0600 | [diff] [blame] | 29 | #include "main/context.h" |
| 30 | #include "main/framebuffer.h" |
Brian Paul | ecadb51 | 2008-09-18 15:17:05 -0600 | [diff] [blame] | 31 | #include "main/renderbuffer.h" |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 32 | #include "main/texobj.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" |
Brian Paul | 14aff23 | 2012-01-02 15:20:04 -0700 | [diff] [blame] | 35 | #include "main/version.h" |
Brian Paul | d0dc75c | 2011-12-05 20:40:48 -0700 | [diff] [blame] | 36 | #include "swrast/s_renderbuffer.h" |
Kenneth Graunke | 1e0da62 | 2014-02-24 23:39:14 -0800 | [diff] [blame] | 37 | #include "util/ralloc.h" |
Jason Ekstrand | ae3870d | 2015-04-16 12:01:09 -0700 | [diff] [blame] | 38 | #include "brw_shader.h" |
Emil Velikov | a39a8fb | 2016-01-18 12:54:03 +0200 | [diff] [blame] | 39 | #include "compiler/nir/nir.h" |
Brian Paul | 6c244b0 | 2009-01-26 12:38:46 -0700 | [diff] [blame] | 40 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 41 | #include "utils.h" |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 42 | #include "xmlpool.h" |
| 43 | |
Eric Anholt | 6868923 | 2013-09-27 15:25:40 -0700 | [diff] [blame] | 44 | static const __DRIconfigOptionsExtension brw_config_options = { |
| 45 | .base = { __DRI_CONFIG_OPTIONS, 1 }, |
| 46 | .xml = |
| 47 | DRI_CONF_BEGIN |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 48 | DRI_CONF_SECTION_PERFORMANCE |
Jesse Barnes | e9bf3e4 | 2008-07-31 11:50:37 -0700 | [diff] [blame] | 49 | DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC) |
Eric Anholt | fe91c05 | 2008-03-05 14:14:54 -0800 | [diff] [blame] | 50 | /* Options correspond to DRI_CONF_BO_REUSE_DISABLED, |
| 51 | * DRI_CONF_BO_REUSE_ALL |
| 52 | */ |
Dave Airlie | f75843a | 2008-08-24 17:59:10 +1000 | [diff] [blame] | 53 | DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1") |
Eric Anholt | fe91c05 | 2008-03-05 14:14:54 -0800 | [diff] [blame] | 54 | DRI_CONF_DESC_BEGIN(en, "Buffer object reuse") |
| 55 | DRI_CONF_ENUM(0, "Disable buffer object reuse") |
| 56 | DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects") |
| 57 | DRI_CONF_DESC_END |
| 58 | DRI_CONF_OPT_END |
Eric Anholt | 1ba9665 | 2009-06-03 16:40:20 +0000 | [diff] [blame] | 59 | |
Eric Anholt | ea6cf2b | 2013-01-02 17:02:58 -0800 | [diff] [blame] | 60 | DRI_CONF_OPT_BEGIN_B(hiz, "true") |
Eric Anholt | d09fce5 | 2012-03-06 11:05:20 -0800 | [diff] [blame] | 61 | DRI_CONF_DESC(en, "Enable Hierarchical Z on gen6+") |
| 62 | DRI_CONF_OPT_END |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 63 | DRI_CONF_SECTION_END |
Chad Versace | 2f89662 | 2013-11-03 13:14:50 -0800 | [diff] [blame] | 64 | |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 65 | DRI_CONF_SECTION_QUALITY |
Eric Anholt | ea6cf2b | 2013-01-02 17:02:58 -0800 | [diff] [blame] | 66 | DRI_CONF_FORCE_S3TC_ENABLE("false") |
Chad Versace | 2f89662 | 2013-11-03 13:14:50 -0800 | [diff] [blame] | 67 | |
Gurchetan Singh | d9546b0 | 2016-05-11 13:32:09 -0700 | [diff] [blame] | 68 | DRI_CONF_PRECISE_TRIG("false") |
| 69 | |
Chad Versace | 2f89662 | 2013-11-03 13:14:50 -0800 | [diff] [blame] | 70 | DRI_CONF_OPT_BEGIN(clamp_max_samples, int, -1) |
| 71 | DRI_CONF_DESC(en, "Clamp the value of GL_MAX_SAMPLES to the " |
| 72 | "given integer. If negative, then do not clamp.") |
| 73 | DRI_CONF_OPT_END |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 74 | DRI_CONF_SECTION_END |
Chad Versace | 2f89662 | 2013-11-03 13:14:50 -0800 | [diff] [blame] | 75 | |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 76 | DRI_CONF_SECTION_DEBUG |
Eric Anholt | ea6cf2b | 2013-01-02 17:02:58 -0800 | [diff] [blame] | 77 | DRI_CONF_NO_RAST("false") |
| 78 | DRI_CONF_ALWAYS_FLUSH_BATCH("false") |
| 79 | DRI_CONF_ALWAYS_FLUSH_CACHE("false") |
| 80 | DRI_CONF_DISABLE_THROTTLING("false") |
| 81 | DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false") |
| 82 | DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false") |
| 83 | DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false") |
Kenneth Graunke | b3340cd | 2016-01-20 17:33:14 -0800 | [diff] [blame] | 84 | DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false") |
Kenneth Graunke | 31f1cbc | 2014-08-08 01:03:15 -0700 | [diff] [blame] | 85 | DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false") |
Eric Anholt | 81aa5d7 | 2009-07-29 13:07:49 -0700 | [diff] [blame] | 86 | |
Eric Anholt | ea6cf2b | 2013-01-02 17:02:58 -0800 | [diff] [blame] | 87 | DRI_CONF_OPT_BEGIN_B(shader_precompile, "true") |
Eric Anholt | c6abde2 | 2011-11-23 10:01:39 -0800 | [diff] [blame] | 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 |
Rob Clark | f78a6b1 | 2016-06-24 14:28:51 -0400 | [diff] [blame] | 91 | |
| 92 | DRI_CONF_SECTION_MISCELLANEOUS |
| 93 | DRI_CONF_GLSL_ZERO_INIT("false") |
| 94 | DRI_CONF_SECTION_END |
Eric Anholt | 6868923 | 2013-09-27 15:25:40 -0700 | [diff] [blame] | 95 | DRI_CONF_END |
| 96 | }; |
Eric Anholt | a0e453a | 2008-01-17 14:23:04 -0800 | [diff] [blame] | 97 | |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 98 | #include "intel_batchbuffer.h" |
| 99 | #include "intel_buffers.h" |
| 100 | #include "intel_bufmgr.h" |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 101 | #include "intel_fbo.h" |
Chad Versace | da2816a | 2011-11-16 14:04:25 -0800 | [diff] [blame] | 102 | #include "intel_mipmap_tree.h" |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 103 | #include "intel_screen.h" |
| 104 | #include "intel_tex.h" |
Eric Anholt | 5566747 | 2014-04-29 15:30:15 -0700 | [diff] [blame] | 105 | #include "intel_image.h" |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 106 | |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 107 | #include "brw_context.h" |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 108 | |
Eric Anholt | df9f891 | 2010-12-13 11:02:15 -0800 | [diff] [blame] | 109 | #include "i915_drm.h" |
| 110 | |
Eric Anholt | 006c1a3 | 2012-08-07 10:05:38 -0700 | [diff] [blame] | 111 | /** |
| 112 | * For debugging purposes, this returns a time in seconds. |
| 113 | */ |
| 114 | double |
| 115 | get_time(void) |
| 116 | { |
| 117 | struct timespec tp; |
| 118 | |
| 119 | clock_gettime(CLOCK_MONOTONIC, &tp); |
| 120 | |
| 121 | return tp.tv_sec + tp.tv_nsec / 1000000000.0; |
| 122 | } |
| 123 | |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 124 | void |
| 125 | aub_dump_bmp(struct gl_context *ctx) |
| 126 | { |
| 127 | struct gl_framebuffer *fb = ctx->DrawBuffer; |
| 128 | |
Rhys Kidd | 65fe7c6 | 2015-08-06 16:34:00 +1000 | [diff] [blame] | 129 | for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) { |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 130 | struct intel_renderbuffer *irb = |
| 131 | intel_renderbuffer(fb->_ColorDrawBuffers[i]); |
| 132 | |
| 133 | if (irb && irb->mt) { |
| 134 | enum aub_dump_bmp_format format; |
| 135 | |
| 136 | switch (irb->Base.Base.Format) { |
Mark Mueller | ef145ba | 2014-01-20 14:21:43 -0800 | [diff] [blame] | 137 | case MESA_FORMAT_B8G8R8A8_UNORM: |
| 138 | case MESA_FORMAT_B8G8R8X8_UNORM: |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 139 | format = AUB_DUMP_BMP_FORMAT_ARGB_8888; |
| 140 | break; |
| 141 | default: |
| 142 | continue; |
| 143 | } |
| 144 | |
Eric Anholt | e16c5c9 | 2014-04-25 13:29:41 -0700 | [diff] [blame] | 145 | drm_intel_gem_bo_aub_dump_bmp(irb->mt->bo, |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 146 | irb->draw_x, |
| 147 | irb->draw_y, |
| 148 | irb->Base.Base.Width, |
| 149 | irb->Base.Base.Height, |
| 150 | format, |
Eric Anholt | e16c5c9 | 2014-04-25 13:29:41 -0700 | [diff] [blame] | 151 | irb->mt->pitch, |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 152 | 0); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Kristian Høgsberg | 6d48779 | 2008-02-14 22:12:51 -0500 | [diff] [blame] | 157 | static const __DRItexBufferExtension intelTexBufferExtension = { |
Emil Velikov | 38f20f7 | 2014-02-12 17:47:53 +0000 | [diff] [blame] | 158 | .base = { __DRI_TEX_BUFFER, 3 }, |
Chad Versace | c9f5126 | 2012-11-19 11:43:51 -0800 | [diff] [blame] | 159 | |
| 160 | .setTexBuffer = intelSetTexBuffer, |
| 161 | .setTexBuffer2 = intelSetTexBuffer2, |
| 162 | .releaseTexBuffer = NULL, |
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 |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 166 | intel_dri2_flush_with_flags(__DRIcontext *cPriv, |
| 167 | __DRIdrawable *dPriv, |
| 168 | unsigned flags, |
| 169 | enum __DRI2throttleReason reason) |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 170 | { |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 171 | struct brw_context *brw = cPriv->driverPrivate; |
| 172 | |
| 173 | if (!brw) |
Anuj Phogat | ce1c949 | 2012-01-17 13:21:52 -0800 | [diff] [blame] | 174 | return; |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 175 | |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 176 | struct gl_context *ctx = &brw->ctx; |
Kristian Høgsberg | e67c338 | 2010-05-18 21:50:44 -0400 | [diff] [blame] | 177 | |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 178 | FLUSH_VERTICES(ctx, 0); |
| 179 | |
| 180 | if (flags & __DRI2_FLUSH_DRAWABLE) |
| 181 | intel_resolve_for_dri2_flush(brw, dPriv); |
| 182 | |
Chris Wilson | 8b9bd19 | 2015-02-26 11:25:18 +0000 | [diff] [blame] | 183 | if (reason == __DRI2_THROTTLE_SWAPBUFFER) |
| 184 | brw->need_swap_throttle = true; |
| 185 | if (reason == __DRI2_THROTTLE_FLUSHFRONT) |
| 186 | brw->need_flush_throttle = true; |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 187 | |
| 188 | intel_batchbuffer_flush(brw); |
Eric Anholt | 0247d89 | 2012-03-06 15:31:42 -0800 | [diff] [blame] | 189 | |
| 190 | if (INTEL_DEBUG & DEBUG_AUB) { |
Kenneth Graunke | 252d311 | 2012-03-29 23:37:09 -0700 | [diff] [blame] | 191 | aub_dump_bmp(ctx); |
Eric Anholt | 0247d89 | 2012-03-06 15:31:42 -0800 | [diff] [blame] | 192 | } |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 193 | } |
| 194 | |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 195 | /** |
| 196 | * Provides compatibility with loaders that only support the older (version |
| 197 | * 1-3) flush interface. |
| 198 | * |
| 199 | * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13. |
| 200 | */ |
| 201 | static void |
| 202 | intel_dri2_flush(__DRIdrawable *drawable) |
| 203 | { |
| 204 | intel_dri2_flush_with_flags(drawable->driContextPriv, drawable, |
| 205 | __DRI2_FLUSH_DRAWABLE, |
| 206 | __DRI2_THROTTLE_SWAPBUFFER); |
| 207 | } |
Chad Versace | c9f5126 | 2012-11-19 11:43:51 -0800 | [diff] [blame] | 208 | |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 209 | static const struct __DRI2flushExtensionRec intelFlushExtension = { |
| 210 | .base = { __DRI2_FLUSH, 4 }, |
| 211 | |
| 212 | .flush = intel_dri2_flush, |
Chad Versace | c9f5126 | 2012-11-19 11:43:51 -0800 | [diff] [blame] | 213 | .invalidate = dri2InvalidateDrawable, |
Eric Anholt | 313f2bc | 2012-12-28 11:44:08 -0800 | [diff] [blame] | 214 | .flush_with_flags = intel_dri2_flush_with_flags, |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 215 | }; |
| 216 | |
Eric Anholt | 9ba6f47 | 2012-09-21 10:36:22 +0200 | [diff] [blame] | 217 | static struct intel_image_format intel_image_formats[] = { |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 218 | { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
| 219 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }, |
| 220 | |
Gwenole Beauchesne | e1c50ab | 2014-09-09 10:56:24 +0200 | [diff] [blame] | 221 | { __DRI_IMAGE_FOURCC_ABGR8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
| 222 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888, 4 } } }, |
| 223 | |
Keith Packard | aea4757 | 2013-11-21 20:08:35 -0800 | [diff] [blame] | 224 | { __DRI_IMAGE_FOURCC_SARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
| 225 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } }, |
| 226 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 227 | { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1, |
| 228 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, |
| 229 | |
Gwenole Beauchesne | e1c50ab | 2014-09-09 10:56:24 +0200 | [diff] [blame] | 230 | { __DRI_IMAGE_FOURCC_XBGR8888, __DRI_IMAGE_COMPONENTS_RGB, 1, |
| 231 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888, 4 }, } }, |
| 232 | |
Chad Versace | e2d69d5 | 2016-12-22 15:00:12 -0800 | [diff] [blame] | 233 | { __DRI_IMAGE_FOURCC_ARGB1555, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
| 234 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } }, |
| 235 | |
Singh, Satyeshwar | e2620c1 | 2013-10-16 01:11:02 +0000 | [diff] [blame] | 236 | { __DRI_IMAGE_FOURCC_RGB565, __DRI_IMAGE_COMPONENTS_RGB, 1, |
| 237 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } }, |
| 238 | |
Chad Versace | 56f1f47 | 2015-06-23 15:48:40 -0700 | [diff] [blame] | 239 | { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1, |
| 240 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } }, |
| 241 | |
| 242 | { __DRI_IMAGE_FOURCC_GR88, __DRI_IMAGE_COMPONENTS_RG, 1, |
| 243 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } }, |
| 244 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 245 | { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 246 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 247 | { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 248 | { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 249 | |
| 250 | { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 251 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 252 | { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 253 | { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 254 | |
| 255 | { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 256 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 257 | { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 258 | { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 259 | |
| 260 | { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 261 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 262 | { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 263 | { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 264 | |
| 265 | { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 266 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 267 | { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 268 | { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 269 | |
Kristian Høgsberg Kristensen | 2bb935b | 2016-04-27 15:00:54 -0700 | [diff] [blame] | 270 | { __DRI_IMAGE_FOURCC_YVU410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 271 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 272 | { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 273 | { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 274 | |
| 275 | { __DRI_IMAGE_FOURCC_YVU411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 276 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 277 | { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 278 | { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 279 | |
| 280 | { __DRI_IMAGE_FOURCC_YVU420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 281 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 282 | { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 283 | { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 284 | |
| 285 | { __DRI_IMAGE_FOURCC_YVU422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 286 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 287 | { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 288 | { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 289 | |
| 290 | { __DRI_IMAGE_FOURCC_YVU444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
| 291 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 292 | { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 293 | { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 294 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 295 | { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
| 296 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 297 | { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
| 298 | |
| 299 | { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
| 300 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 301 | { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
| 302 | |
| 303 | /* For YUYV buffers, we set up two overlapping DRI images and treat |
| 304 | * them as planar buffers in the compositors. Plane 0 is GR88 and |
| 305 | * samples YU or YV pairs and places Y into the R component, while |
| 306 | * plane 1 is ARGB and samples YUYV clusters and places pairs and |
| 307 | * places U into the G component and V into A. This lets the |
| 308 | * texture sampler interpolate the Y components correctly when |
| 309 | * sampling from plane 0, and interpolate U and V correctly when |
| 310 | * sampling from plane 1. */ |
| 311 | { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2, |
| 312 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, |
| 313 | { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } |
| 314 | }; |
| 315 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 316 | static void |
| 317 | intel_image_warn_if_unaligned(__DRIimage *image, const char *func) |
| 318 | { |
| 319 | uint32_t tiling, swizzle; |
| 320 | drm_intel_bo_get_tiling(image->bo, &tiling, &swizzle); |
| 321 | |
| 322 | if (tiling != I915_TILING_NONE && (image->offset & 0xfff)) { |
| 323 | _mesa_warning(NULL, "%s: offset 0x%08x not on tile boundary", |
| 324 | func, image->offset); |
| 325 | } |
| 326 | } |
| 327 | |
Topi Pohjolainen | 904587a | 2012-12-28 12:22:54 +0200 | [diff] [blame] | 328 | static struct intel_image_format * |
| 329 | intel_image_format_lookup(int fourcc) |
| 330 | { |
| 331 | struct intel_image_format *f = NULL; |
| 332 | |
| 333 | for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
| 334 | if (intel_image_formats[i].fourcc == fourcc) { |
| 335 | f = &intel_image_formats[i]; |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | return f; |
| 341 | } |
| 342 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 343 | static boolean intel_lookup_fourcc(int dri_format, int *fourcc) |
| 344 | { |
| 345 | for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
| 346 | if (intel_image_formats[i].planes[0].dri_format == dri_format) { |
| 347 | *fourcc = intel_image_formats[i].fourcc; |
| 348 | return true; |
| 349 | } |
| 350 | } |
| 351 | return false; |
| 352 | } |
| 353 | |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 354 | static __DRIimage * |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 355 | intel_allocate_image(int dri_format, void *loaderPrivate) |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 356 | { |
| 357 | __DRIimage *image; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 358 | |
Brian Paul | 4fdac65 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 359 | image = calloc(1, sizeof *image); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 360 | if (image == NULL) |
| 361 | return NULL; |
| 362 | |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 363 | image->dri_format = dri_format; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 364 | image->offset = 0; |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 365 | |
Keith Packard | 1f085ba | 2013-11-04 17:33:34 -0800 | [diff] [blame] | 366 | image->format = driImageFormatToGLFormat(dri_format); |
Ander Conselvan de Oliveira | 5ba6be2 | 2013-11-12 14:47:08 +0200 | [diff] [blame] | 367 | if (dri_format != __DRI_IMAGE_FORMAT_NONE && |
| 368 | image->format == MESA_FORMAT_NONE) { |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 369 | free(image); |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Kristian Høgsberg | 454fc07 | 2012-07-05 00:07:15 -0400 | [diff] [blame] | 373 | image->internal_format = _mesa_get_format_base_format(image->format); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 374 | image->data = loaderPrivate; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 375 | |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 376 | return image; |
| 377 | } |
| 378 | |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 379 | /** |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 380 | * Sets up a DRIImage structure to point to a slice out of a miptree. |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 381 | */ |
| 382 | static void |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 383 | intel_setup_image_from_mipmap_tree(struct brw_context *brw, __DRIimage *image, |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 384 | struct intel_mipmap_tree *mt, GLuint level, |
| 385 | GLuint zoffset) |
| 386 | { |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 387 | intel_miptree_make_shareable(brw, mt); |
Paul Berry | ef9142d | 2013-05-21 14:21:44 -0700 | [diff] [blame] | 388 | |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 389 | intel_miptree_check_level_layer(mt, level, zoffset); |
| 390 | |
Kenneth Graunke | b18871c | 2014-02-22 23:47:30 -0800 | [diff] [blame] | 391 | image->width = minify(mt->physical_width0, level - mt->first_level); |
| 392 | image->height = minify(mt->physical_height0, level - mt->first_level); |
Eric Anholt | e16c5c9 | 2014-04-25 13:29:41 -0700 | [diff] [blame] | 393 | image->pitch = mt->pitch; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 394 | |
Eric Anholt | 6db640d | 2014-04-25 11:26:27 -0700 | [diff] [blame] | 395 | image->offset = intel_miptree_get_tile_offsets(mt, level, zoffset, |
| 396 | &image->tile_x, |
| 397 | &image->tile_y); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 398 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 399 | drm_intel_bo_unreference(image->bo); |
Eric Anholt | e16c5c9 | 2014-04-25 13:29:41 -0700 | [diff] [blame] | 400 | image->bo = mt->bo; |
| 401 | drm_intel_bo_reference(mt->bo); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 404 | static __DRIimage * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 405 | intel_create_image_from_name(__DRIscreen *dri_screen, |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 406 | int width, int height, int format, |
| 407 | int name, int pitch, void *loaderPrivate) |
| 408 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 409 | struct intel_screen *screen = dri_screen->driverPrivate; |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 410 | __DRIimage *image; |
| 411 | int cpp; |
| 412 | |
| 413 | image = intel_allocate_image(format, loaderPrivate); |
Anuj Phogat | 484b89a | 2013-04-16 10:34:43 -0700 | [diff] [blame] | 414 | if (image == NULL) |
| 415 | return NULL; |
| 416 | |
Kristian Høgsberg | 636646a | 2012-07-16 10:54:30 -0400 | [diff] [blame] | 417 | if (image->format == MESA_FORMAT_NONE) |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 418 | cpp = 1; |
Kristian Høgsberg | 636646a | 2012-07-16 10:54:30 -0400 | [diff] [blame] | 419 | else |
| 420 | cpp = _mesa_get_format_bytes(image->format); |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 421 | |
| 422 | image->width = width; |
| 423 | image->height = height; |
| 424 | image->pitch = pitch * cpp; |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 425 | image->bo = drm_intel_bo_gem_create_from_name(screen->bufmgr, "image", |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 426 | name); |
| 427 | if (!image->bo) { |
Brian Paul | fe72a06 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 428 | free(image); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 429 | return NULL; |
| 430 | } |
| 431 | |
Iago Toral Quiroga | 2bba215 | 2015-11-24 12:49:55 +0100 | [diff] [blame] | 432 | return image; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static __DRIimage * |
| 436 | intel_create_image_from_renderbuffer(__DRIcontext *context, |
| 437 | int renderbuffer, void *loaderPrivate) |
| 438 | { |
| 439 | __DRIimage *image; |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 440 | struct brw_context *brw = context->driverPrivate; |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 441 | struct gl_context *ctx = &brw->ctx; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 442 | struct gl_renderbuffer *rb; |
| 443 | struct intel_renderbuffer *irb; |
| 444 | |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 445 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 446 | if (!rb) { |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 447 | _mesa_error(ctx, GL_INVALID_OPERATION, "glRenderbufferExternalMESA"); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 448 | return NULL; |
| 449 | } |
| 450 | |
| 451 | irb = intel_renderbuffer(rb); |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 452 | intel_miptree_make_shareable(brw, irb->mt); |
Brian Paul | 4fdac65 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 453 | image = calloc(1, sizeof *image); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 454 | if (image == NULL) |
| 455 | return NULL; |
| 456 | |
| 457 | image->internal_format = rb->InternalFormat; |
| 458 | image->format = rb->Format; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 459 | image->offset = 0; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 460 | image->data = loaderPrivate; |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 461 | drm_intel_bo_unreference(image->bo); |
Eric Anholt | e16c5c9 | 2014-04-25 13:29:41 -0700 | [diff] [blame] | 462 | image->bo = irb->mt->bo; |
| 463 | drm_intel_bo_reference(irb->mt->bo); |
| 464 | image->width = rb->Width; |
| 465 | image->height = rb->Height; |
| 466 | image->pitch = irb->mt->pitch; |
Keith Packard | 1f085ba | 2013-11-04 17:33:34 -0800 | [diff] [blame] | 467 | image->dri_format = driGLFormatToImageFormat(image->format); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 468 | image->has_depthstencil = irb->mt->stencil_mt? true : false; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 469 | |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 470 | rb->NeedsFinishRenderTexture = true; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 471 | return image; |
| 472 | } |
| 473 | |
| 474 | static __DRIimage * |
| 475 | intel_create_image_from_texture(__DRIcontext *context, int target, |
| 476 | unsigned texture, int zoffset, |
| 477 | int level, |
| 478 | unsigned *error, |
| 479 | void *loaderPrivate) |
| 480 | { |
| 481 | __DRIimage *image; |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 482 | struct brw_context *brw = context->driverPrivate; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 483 | struct gl_texture_object *obj; |
| 484 | struct intel_texture_object *iobj; |
| 485 | GLuint face = 0; |
| 486 | |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 487 | obj = _mesa_lookup_texture(&brw->ctx, texture); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 488 | if (!obj || obj->Target != target) { |
| 489 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
| 490 | return NULL; |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 491 | } |
| 492 | |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 493 | if (target == GL_TEXTURE_CUBE_MAP) |
| 494 | face = zoffset; |
| 495 | |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 496 | _mesa_test_texobj_completeness(&brw->ctx, obj); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 497 | iobj = intel_texture_object(obj); |
| 498 | if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) { |
| 499 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | if (level < obj->BaseLevel || level > obj->_MaxLevel) { |
| 504 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
| 505 | return NULL; |
| 506 | } |
| 507 | |
| 508 | if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < zoffset) { |
| 509 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
| 510 | return NULL; |
| 511 | } |
| 512 | image = calloc(1, sizeof *image); |
| 513 | if (image == NULL) { |
| 514 | *error = __DRI_IMAGE_ERROR_BAD_ALLOC; |
| 515 | return NULL; |
| 516 | } |
| 517 | |
| 518 | image->internal_format = obj->Image[face][level]->InternalFormat; |
| 519 | image->format = obj->Image[face][level]->TexFormat; |
| 520 | image->data = loaderPrivate; |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 521 | intel_setup_image_from_mipmap_tree(brw, image, iobj->mt, level, zoffset); |
Keith Packard | 1f085ba | 2013-11-04 17:33:34 -0800 | [diff] [blame] | 522 | image->dri_format = driGLFormatToImageFormat(image->format); |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 523 | image->has_depthstencil = iobj->mt->stencil_mt? true : false; |
| 524 | if (image->dri_format == MESA_FORMAT_NONE) { |
| 525 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
| 526 | free(image); |
| 527 | return NULL; |
| 528 | } |
| 529 | |
| 530 | *error = __DRI_IMAGE_ERROR_SUCCESS; |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 531 | return image; |
| 532 | } |
| 533 | |
| 534 | static void |
| 535 | intel_destroy_image(__DRIimage *image) |
| 536 | { |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 537 | drm_intel_bo_unreference(image->bo); |
| 538 | free(image); |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 539 | } |
| 540 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 541 | static __DRIimage * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 542 | intel_create_image(__DRIscreen *dri_screen, |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 543 | int width, int height, int format, |
| 544 | unsigned int use, |
| 545 | void *loaderPrivate) |
| 546 | { |
| 547 | __DRIimage *image; |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 548 | struct intel_screen *screen = dri_screen->driverPrivate; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 549 | uint32_t tiling; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 550 | int cpp; |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 551 | unsigned long pitch; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 552 | |
Daniel Stone | e54b2e9 | 2016-05-02 15:34:40 +0100 | [diff] [blame] | 553 | tiling = I915_TILING_X; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 554 | if (use & __DRI_IMAGE_USE_CURSOR) { |
| 555 | if (width != 64 || height != 64) |
| 556 | return NULL; |
| 557 | tiling = I915_TILING_NONE; |
| 558 | } |
| 559 | |
Axel Davy | e8f9195 | 2013-08-15 12:47:58 +0200 | [diff] [blame] | 560 | if (use & __DRI_IMAGE_USE_LINEAR) |
| 561 | tiling = I915_TILING_NONE; |
| 562 | |
Kristian Høgsberg | 1bb15c0 | 2012-07-05 00:17:47 -0400 | [diff] [blame] | 563 | image = intel_allocate_image(format, loaderPrivate); |
Anuj Phogat | 484b89a | 2013-04-16 10:34:43 -0700 | [diff] [blame] | 564 | if (image == NULL) |
| 565 | return NULL; |
| 566 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 567 | cpp = _mesa_get_format_bytes(image->format); |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 568 | image->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, "image", |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 569 | width, height, cpp, &tiling, |
| 570 | &pitch, 0); |
| 571 | if (image->bo == NULL) { |
Brian Paul | fe72a06 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 572 | free(image); |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 573 | return NULL; |
| 574 | } |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 575 | image->width = width; |
| 576 | image->height = height; |
| 577 | image->pitch = pitch; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 578 | |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 579 | return image; |
| 580 | } |
| 581 | |
| 582 | static GLboolean |
| 583 | intel_query_image(__DRIimage *image, int attrib, int *value) |
| 584 | { |
| 585 | switch (attrib) { |
| 586 | case __DRI_IMAGE_ATTRIB_STRIDE: |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 587 | *value = image->pitch; |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 588 | return true; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 589 | case __DRI_IMAGE_ATTRIB_HANDLE: |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 590 | *value = image->bo->handle; |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 591 | return true; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 592 | case __DRI_IMAGE_ATTRIB_NAME: |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 593 | return !drm_intel_bo_flink(image->bo, (uint32_t *) value); |
Jesse Barnes | 8de5c35 | 2012-02-21 12:53:09 -0800 | [diff] [blame] | 594 | case __DRI_IMAGE_ATTRIB_FORMAT: |
Ander Conselvan de Oliveira | fc7d224 | 2012-04-26 16:21:19 +0300 | [diff] [blame] | 595 | *value = image->dri_format; |
| 596 | return true; |
Kristian Høgsberg | 44f066b | 2012-07-13 11:19:24 -0400 | [diff] [blame] | 597 | case __DRI_IMAGE_ATTRIB_WIDTH: |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 598 | *value = image->width; |
Kristian Høgsberg | 44f066b | 2012-07-13 11:19:24 -0400 | [diff] [blame] | 599 | return true; |
| 600 | case __DRI_IMAGE_ATTRIB_HEIGHT: |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 601 | *value = image->height; |
Kristian Høgsberg | 44f066b | 2012-07-13 11:19:24 -0400 | [diff] [blame] | 602 | return true; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 603 | case __DRI_IMAGE_ATTRIB_COMPONENTS: |
| 604 | if (image->planar_format == NULL) |
| 605 | return false; |
| 606 | *value = image->planar_format->components; |
| 607 | return true; |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 608 | case __DRI_IMAGE_ATTRIB_FD: |
Eric Engestrom | 2532743 | 2016-08-15 15:51:20 +0100 | [diff] [blame] | 609 | return !drm_intel_bo_gem_export_to_prime(image->bo, value); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 610 | case __DRI_IMAGE_ATTRIB_FOURCC: |
Eric Engestrom | 2532743 | 2016-08-15 15:51:20 +0100 | [diff] [blame] | 611 | return intel_lookup_fourcc(image->dri_format, value); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 612 | case __DRI_IMAGE_ATTRIB_NUM_PLANES: |
| 613 | *value = 1; |
| 614 | return true; |
Chuanbo Weng | e4648ba | 2016-09-14 01:07:18 +0800 | [diff] [blame] | 615 | case __DRI_IMAGE_ATTRIB_OFFSET: |
| 616 | *value = image->offset; |
| 617 | return true; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 618 | |
Kristian Høgsberg | 44f066b | 2012-07-13 11:19:24 -0400 | [diff] [blame] | 619 | default: |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 620 | return false; |
Kristian Høgsberg | f301932 | 2010-06-06 20:39:19 -0400 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 624 | static __DRIimage * |
| 625 | intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) |
| 626 | { |
| 627 | __DRIimage *image; |
| 628 | |
Brian Paul | 4fdac65 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 629 | image = calloc(1, sizeof *image); |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 630 | if (image == NULL) |
| 631 | return NULL; |
| 632 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 633 | drm_intel_bo_reference(orig_image->bo); |
| 634 | image->bo = orig_image->bo; |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 635 | image->internal_format = orig_image->internal_format; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 636 | image->planar_format = orig_image->planar_format; |
Ander Conselvan de Oliveira | 249817e | 2012-04-30 12:32:45 +0300 | [diff] [blame] | 637 | image->dri_format = orig_image->dri_format; |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 638 | image->format = orig_image->format; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 639 | image->offset = orig_image->offset; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 640 | image->width = orig_image->width; |
| 641 | image->height = orig_image->height; |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 642 | image->pitch = orig_image->pitch; |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 643 | image->tile_x = orig_image->tile_x; |
| 644 | image->tile_y = orig_image->tile_y; |
| 645 | image->has_depthstencil = orig_image->has_depthstencil; |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 646 | image->data = loaderPrivate; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 647 | |
| 648 | memcpy(image->strides, orig_image->strides, sizeof(image->strides)); |
| 649 | memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets)); |
| 650 | |
Benjamin Franzke | 3af3c58 | 2011-03-09 20:56:02 +0100 | [diff] [blame] | 651 | return image; |
| 652 | } |
| 653 | |
Kristian Høgsberg | 221c678 | 2012-01-18 15:32:35 -0500 | [diff] [blame] | 654 | static GLboolean |
| 655 | intel_validate_usage(__DRIimage *image, unsigned int use) |
| 656 | { |
| 657 | if (use & __DRI_IMAGE_USE_CURSOR) { |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 658 | if (image->width != 64 || image->height != 64) |
Kristian Høgsberg | 221c678 | 2012-01-18 15:32:35 -0500 | [diff] [blame] | 659 | return GL_FALSE; |
| 660 | } |
| 661 | |
| 662 | return GL_TRUE; |
| 663 | } |
| 664 | |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 665 | static __DRIimage * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 666 | intel_create_image_from_names(__DRIscreen *dri_screen, |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 667 | int width, int height, int fourcc, |
| 668 | int *names, int num_names, |
| 669 | int *strides, int *offsets, |
| 670 | void *loaderPrivate) |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 671 | { |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 672 | struct intel_image_format *f = NULL; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 673 | __DRIimage *image; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 674 | int i, index; |
| 675 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 676 | if (dri_screen == NULL || names == NULL || num_names != 1) |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 677 | return NULL; |
| 678 | |
Topi Pohjolainen | 904587a | 2012-12-28 12:22:54 +0200 | [diff] [blame] | 679 | f = intel_image_format_lookup(fourcc); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 680 | if (f == NULL) |
| 681 | return NULL; |
| 682 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 683 | image = intel_create_image_from_name(dri_screen, width, height, |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 684 | __DRI_IMAGE_FORMAT_NONE, |
| 685 | names[0], strides[0], |
| 686 | loaderPrivate); |
| 687 | |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 688 | if (image == NULL) |
| 689 | return NULL; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 690 | |
| 691 | image->planar_format = f; |
| 692 | for (i = 0; i < f->nplanes; i++) { |
| 693 | index = f->planes[i].buffer_index; |
| 694 | image->offsets[index] = offsets[index]; |
| 695 | image->strides[index] = strides[index]; |
| 696 | } |
| 697 | |
| 698 | return image; |
| 699 | } |
| 700 | |
| 701 | static __DRIimage * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 702 | intel_create_image_from_fds(__DRIscreen *dri_screen, |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 703 | int width, int height, int fourcc, |
| 704 | int *fds, int num_fds, int *strides, int *offsets, |
| 705 | void *loaderPrivate) |
| 706 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 707 | struct intel_screen *screen = dri_screen->driverPrivate; |
Topi Pohjolainen | 904587a | 2012-12-28 12:22:54 +0200 | [diff] [blame] | 708 | struct intel_image_format *f; |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 709 | __DRIimage *image; |
| 710 | int i, index; |
| 711 | |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 712 | if (fds == NULL || num_fds < 1) |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 713 | return NULL; |
| 714 | |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 715 | /* We only support all planes from the same bo */ |
| 716 | for (i = 0; i < num_fds; i++) |
| 717 | if (fds[0] != fds[i]) |
| 718 | return NULL; |
| 719 | |
Topi Pohjolainen | 904587a | 2012-12-28 12:22:54 +0200 | [diff] [blame] | 720 | f = intel_image_format_lookup(fourcc); |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 721 | if (f == NULL) |
| 722 | return NULL; |
| 723 | |
Topi Pohjolainen | e8568a0 | 2013-04-25 14:33:09 +0300 | [diff] [blame] | 724 | if (f->nplanes == 1) |
| 725 | image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate); |
| 726 | else |
| 727 | image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate); |
| 728 | |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 729 | if (image == NULL) |
| 730 | return NULL; |
| 731 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 732 | image->width = width; |
| 733 | image->height = height; |
| 734 | image->pitch = strides[0]; |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 735 | |
| 736 | image->planar_format = f; |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 737 | int size = 0; |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 738 | for (i = 0; i < f->nplanes; i++) { |
| 739 | index = f->planes[i].buffer_index; |
| 740 | image->offsets[index] = offsets[index]; |
| 741 | image->strides[index] = strides[index]; |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 742 | |
Kristian Høgsberg Kristensen | 89bb4be | 2016-05-25 09:30:26 -0700 | [diff] [blame] | 743 | const int plane_height = height >> f->planes[i].height_shift; |
| 744 | const int end = offsets[index] + plane_height * strides[index]; |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 745 | if (size < end) |
| 746 | size = end; |
| 747 | } |
| 748 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 749 | image->bo = drm_intel_bo_gem_create_from_prime(screen->bufmgr, |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 750 | fds[0], size); |
| 751 | if (image->bo == NULL) { |
| 752 | free(image); |
| 753 | return NULL; |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 754 | } |
| 755 | |
Gwenole Beauchesne | 3bd65dc | 2014-03-10 16:55:21 +0100 | [diff] [blame] | 756 | if (f->nplanes == 1) { |
| 757 | image->offset = image->offsets[0]; |
Marius Predut | 28d9e90 | 2015-04-07 22:05:28 +0300 | [diff] [blame] | 758 | intel_image_warn_if_unaligned(image, __func__); |
Gwenole Beauchesne | 3bd65dc | 2014-03-10 16:55:21 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 761 | return image; |
| 762 | } |
| 763 | |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 764 | static __DRIimage * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 765 | intel_create_image_from_dma_bufs(__DRIscreen *dri_screen, |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 766 | int width, int height, int fourcc, |
| 767 | int *fds, int num_fds, |
| 768 | int *strides, int *offsets, |
| 769 | enum __DRIYUVColorSpace yuv_color_space, |
| 770 | enum __DRISampleRange sample_range, |
| 771 | enum __DRIChromaSiting horizontal_siting, |
| 772 | enum __DRIChromaSiting vertical_siting, |
| 773 | unsigned *error, |
| 774 | void *loaderPrivate) |
| 775 | { |
| 776 | __DRIimage *image; |
| 777 | struct intel_image_format *f = intel_image_format_lookup(fourcc); |
| 778 | |
Kristian Høgsberg Kristensen | 1be1114 | 2016-05-01 21:25:35 -0700 | [diff] [blame] | 779 | if (!f) { |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 780 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
| 781 | return NULL; |
| 782 | } |
| 783 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 784 | image = intel_create_image_from_fds(dri_screen, width, height, fourcc, fds, |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 785 | num_fds, strides, offsets, |
| 786 | loaderPrivate); |
| 787 | |
| 788 | /* |
| 789 | * Invalid parameters and any inconsistencies between are assumed to be |
| 790 | * checked by the caller. Therefore besides unsupported formats one can fail |
| 791 | * only in allocation. |
| 792 | */ |
| 793 | if (!image) { |
| 794 | *error = __DRI_IMAGE_ERROR_BAD_ALLOC; |
| 795 | return NULL; |
| 796 | } |
| 797 | |
Topi Pohjolainen | 3a52cd3 | 2013-06-18 13:47:43 +0300 | [diff] [blame] | 798 | image->dma_buf_imported = true; |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 799 | image->yuv_color_space = yuv_color_space; |
| 800 | image->sample_range = sample_range; |
| 801 | image->horizontal_siting = horizontal_siting; |
| 802 | image->vertical_siting = vertical_siting; |
| 803 | |
| 804 | *error = __DRI_IMAGE_ERROR_SUCCESS; |
| 805 | return image; |
| 806 | } |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 807 | |
| 808 | static __DRIimage * |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 809 | intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) |
| 810 | { |
Eric Anholt | 60894ed | 2013-01-10 15:11:28 -0800 | [diff] [blame] | 811 | int width, height, offset, stride, dri_format, index; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 812 | struct intel_image_format *f; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 813 | __DRIimage *image; |
| 814 | |
| 815 | if (parent == NULL || parent->planar_format == NULL) |
| 816 | return NULL; |
| 817 | |
| 818 | f = parent->planar_format; |
| 819 | |
| 820 | if (plane >= f->nplanes) |
| 821 | return NULL; |
| 822 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 823 | width = parent->width >> f->planes[plane].width_shift; |
| 824 | height = parent->height >> f->planes[plane].height_shift; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 825 | dri_format = f->planes[plane].dri_format; |
| 826 | index = f->planes[plane].buffer_index; |
| 827 | offset = parent->offsets[index]; |
| 828 | stride = parent->strides[index]; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 829 | |
| 830 | image = intel_allocate_image(dri_format, loaderPrivate); |
Anuj Phogat | 484b89a | 2013-04-16 10:34:43 -0700 | [diff] [blame] | 831 | if (image == NULL) |
| 832 | return NULL; |
| 833 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 834 | if (offset + height * stride > parent->bo->size) { |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 835 | _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds"); |
Brian Paul | fe72a06 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 836 | free(image); |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 837 | return NULL; |
| 838 | } |
| 839 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 840 | image->bo = parent->bo; |
| 841 | drm_intel_bo_reference(parent->bo); |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 842 | |
Eric Anholt | e3a9ca4 | 2014-04-25 12:14:34 -0700 | [diff] [blame] | 843 | image->width = width; |
| 844 | image->height = height; |
| 845 | image->pitch = stride; |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 846 | image->offset = offset; |
| 847 | |
Marius Predut | 28d9e90 | 2015-04-07 22:05:28 +0300 | [diff] [blame] | 848 | intel_image_warn_if_unaligned(image, __func__); |
Kristian Høgsberg | 95bc052 | 2012-07-05 13:02:02 -0400 | [diff] [blame] | 849 | |
| 850 | return image; |
| 851 | } |
| 852 | |
Emil Velikov | 38f20f7 | 2014-02-12 17:47:53 +0000 | [diff] [blame] | 853 | static const __DRIimageExtension intelImageExtension = { |
Chuanbo Weng | e4648ba | 2016-09-14 01:07:18 +0800 | [diff] [blame] | 854 | .base = { __DRI_IMAGE, 13 }, |
Chad Versace | c9f5126 | 2012-11-19 11:43:51 -0800 | [diff] [blame] | 855 | |
| 856 | .createImageFromName = intel_create_image_from_name, |
| 857 | .createImageFromRenderbuffer = intel_create_image_from_renderbuffer, |
| 858 | .destroyImage = intel_destroy_image, |
| 859 | .createImage = intel_create_image, |
| 860 | .queryImage = intel_query_image, |
| 861 | .dupImage = intel_dup_image, |
| 862 | .validateUsage = intel_validate_usage, |
| 863 | .createImageFromNames = intel_create_image_from_names, |
Abdiel Janulgue | 6c7e95c | 2012-11-28 13:30:18 +0200 | [diff] [blame] | 864 | .fromPlanar = intel_from_planar, |
Kristian Høgsberg | 2356e28 | 2013-02-02 08:38:07 -0500 | [diff] [blame] | 865 | .createImageFromTexture = intel_create_image_from_texture, |
Topi Pohjolainen | 674dedc | 2013-03-26 15:14:20 +0200 | [diff] [blame] | 866 | .createImageFromFds = intel_create_image_from_fds, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 867 | .createImageFromDmaBufs = intel_create_image_from_dma_bufs, |
| 868 | .blitImage = NULL, |
Chuanbo Weng | e4648ba | 2016-09-14 01:07:18 +0800 | [diff] [blame] | 869 | .getCapabilities = NULL, |
| 870 | .mapImage = NULL, |
| 871 | .unmapImage = NULL, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 872 | }; |
| 873 | |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 874 | static int |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 875 | brw_query_renderer_integer(__DRIscreen *dri_screen, |
| 876 | int param, unsigned int *value) |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 877 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 878 | const struct intel_screen *const screen = |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 879 | (struct intel_screen *) dri_screen->driverPrivate; |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 880 | |
| 881 | switch (param) { |
| 882 | case __DRI2_RENDERER_VENDOR_ID: |
| 883 | value[0] = 0x8086; |
| 884 | return 0; |
| 885 | case __DRI2_RENDERER_DEVICE_ID: |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 886 | value[0] = screen->deviceID; |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 887 | return 0; |
| 888 | case __DRI2_RENDERER_ACCELERATED: |
| 889 | value[0] = 1; |
| 890 | return 0; |
| 891 | case __DRI2_RENDERER_VIDEO_MEMORY: { |
| 892 | /* Once a batch uses more than 75% of the maximum mappable size, we |
| 893 | * assume that there's some fragmentation, and we start doing extra |
| 894 | * flushing, etc. That's the big cliff apps will care about. |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 895 | */ |
Ian Romanick | cb6182b | 2013-11-11 10:57:55 -0800 | [diff] [blame] | 896 | size_t aper_size; |
| 897 | size_t mappable_size; |
| 898 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 899 | drm_intel_get_aperture_sizes(dri_screen->fd, &mappable_size, &aper_size); |
Ian Romanick | cb6182b | 2013-11-11 10:57:55 -0800 | [diff] [blame] | 900 | |
| 901 | const unsigned gpu_mappable_megabytes = |
| 902 | (aper_size / (1024 * 1024)) * 3 / 4; |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 903 | |
| 904 | const long system_memory_pages = sysconf(_SC_PHYS_PAGES); |
| 905 | const long system_page_size = sysconf(_SC_PAGE_SIZE); |
| 906 | |
| 907 | if (system_memory_pages <= 0 || system_page_size <= 0) |
| 908 | return -1; |
| 909 | |
| 910 | const uint64_t system_memory_bytes = (uint64_t) system_memory_pages |
| 911 | * (uint64_t) system_page_size; |
| 912 | |
| 913 | const unsigned system_memory_megabytes = |
Emil Velikov | fc25956 | 2014-02-22 03:04:02 +0000 | [diff] [blame] | 914 | (unsigned) (system_memory_bytes / (1024 * 1024)); |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 915 | |
| 916 | value[0] = MIN2(system_memory_megabytes, gpu_mappable_megabytes); |
| 917 | return 0; |
| 918 | } |
| 919 | case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: |
| 920 | value[0] = 1; |
| 921 | return 0; |
Adam Jackson | 8ce2afe | 2016-09-21 09:13:36 -0400 | [diff] [blame] | 922 | case __DRI2_RENDERER_HAS_TEXTURE_3D: |
| 923 | value[0] = 1; |
| 924 | return 0; |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 925 | default: |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 926 | return driQueryRendererIntegerCommon(dri_screen, param, value); |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | return -1; |
| 930 | } |
| 931 | |
| 932 | static int |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 933 | brw_query_renderer_string(__DRIscreen *dri_screen, |
| 934 | int param, const char **value) |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 935 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 936 | const struct intel_screen *screen = |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 937 | (struct intel_screen *) dri_screen->driverPrivate; |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 938 | |
| 939 | switch (param) { |
| 940 | case __DRI2_RENDERER_VENDOR_ID: |
| 941 | value[0] = brw_vendor_string; |
| 942 | return 0; |
| 943 | case __DRI2_RENDERER_DEVICE_ID: |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 944 | value[0] = brw_get_renderer_string(screen); |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 945 | return 0; |
| 946 | default: |
| 947 | break; |
| 948 | } |
| 949 | |
| 950 | return -1; |
| 951 | } |
| 952 | |
Emil Velikov | 38f20f7 | 2014-02-12 17:47:53 +0000 | [diff] [blame] | 953 | static const __DRI2rendererQueryExtension intelRendererQueryExtension = { |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 954 | .base = { __DRI2_RENDERER_QUERY, 1 }, |
| 955 | |
| 956 | .queryInteger = brw_query_renderer_integer, |
| 957 | .queryString = brw_query_renderer_string |
| 958 | }; |
| 959 | |
Emil Velikov | 38f20f7 | 2014-02-12 17:47:53 +0000 | [diff] [blame] | 960 | static const __DRIrobustnessExtension dri2Robustness = { |
| 961 | .base = { __DRI2_ROBUSTNESS, 1 } |
Ian Romanick | 1f712bd | 2012-09-11 11:08:44 +0300 | [diff] [blame] | 962 | }; |
| 963 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 964 | static const __DRIextension *screenExtensions[] = { |
Kristian Høgsberg | 6d48779 | 2008-02-14 22:12:51 -0500 | [diff] [blame] | 965 | &intelTexBufferExtension.base, |
Chad Versace | c636284 | 2015-05-05 19:05:32 -0700 | [diff] [blame] | 966 | &intelFenceExtension.base, |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 967 | &intelFlushExtension.base, |
Kristian Høgsberg | c262471 | 2010-02-11 18:59:40 -0500 | [diff] [blame] | 968 | &intelImageExtension.base, |
Ian Romanick | 1e4ce08 | 2013-02-14 16:50:28 -0800 | [diff] [blame] | 969 | &intelRendererQueryExtension.base, |
Jesse Barnes | 234286c | 2010-04-22 12:47:41 -0700 | [diff] [blame] | 970 | &dri2ConfigQueryExtension.base, |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 971 | NULL |
| 972 | }; |
| 973 | |
| 974 | static const __DRIextension *intelRobustScreenExtensions[] = { |
| 975 | &intelTexBufferExtension.base, |
Chad Versace | c636284 | 2015-05-05 19:05:32 -0700 | [diff] [blame] | 976 | &intelFenceExtension.base, |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 977 | &intelFlushExtension.base, |
| 978 | &intelImageExtension.base, |
| 979 | &intelRendererQueryExtension.base, |
| 980 | &dri2ConfigQueryExtension.base, |
Ian Romanick | 1f712bd | 2012-09-11 11:08:44 +0300 | [diff] [blame] | 981 | &dri2Robustness.base, |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 982 | NULL |
| 983 | }; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 984 | |
Ben Widawsky | a8975a9 | 2016-04-11 09:49:41 -0700 | [diff] [blame] | 985 | static int |
Chad Versace | 844e0bd | 2016-06-27 11:29:27 -0700 | [diff] [blame] | 986 | intel_get_param(struct intel_screen *screen, int param, int *value) |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 987 | { |
Chad Versace | d3a147b | 2016-06-27 11:33:36 -0700 | [diff] [blame] | 988 | int ret = 0; |
Alan Hourihane | 1c718c0 | 2008-02-22 00:18:54 +0000 | [diff] [blame] | 989 | struct drm_i915_getparam gp; |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 990 | |
Eric Anholt | f33d100 | 2012-02-16 11:30:49 -0800 | [diff] [blame] | 991 | memset(&gp, 0, sizeof(gp)); |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 992 | gp.param = param; |
| 993 | gp.value = value; |
| 994 | |
Chad Versace | d3a147b | 2016-06-27 11:33:36 -0700 | [diff] [blame] | 995 | if (drmIoctl(screen->driScrnPriv->fd, DRM_IOCTL_I915_GETPARAM, &gp) == -1) { |
| 996 | ret = -errno; |
| 997 | if (ret != -EINVAL) |
| 998 | _mesa_warning(NULL, "drm_i915_getparam: %d", ret); |
| 999 | } |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 1000 | |
Ben Widawsky | a8975a9 | 2016-04-11 09:49:41 -0700 | [diff] [blame] | 1001 | return ret; |
Kristian Høgsberg | 24e7e45 | 2008-01-09 18:04:19 -0500 | [diff] [blame] | 1002 | } |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 1003 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 1004 | static bool |
Chad Versace | 844e0bd | 2016-06-27 11:29:27 -0700 | [diff] [blame] | 1005 | intel_get_boolean(struct intel_screen *screen, int param) |
Chris Wilson | 900a5c9 | 2011-03-01 14:46:50 +0000 | [diff] [blame] | 1006 | { |
| 1007 | int value = 0; |
Chad Versace | 844e0bd | 2016-06-27 11:29:27 -0700 | [diff] [blame] | 1008 | return (intel_get_param(screen, param, &value) == 0) && value; |
Chris Wilson | 900a5c9 | 2011-03-01 14:46:50 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Chris Wilson | f92a87a | 2016-08-24 20:35:46 +0100 | [diff] [blame] | 1011 | static int |
| 1012 | intel_get_integer(struct intel_screen *screen, int param) |
| 1013 | { |
| 1014 | int value = -1; |
| 1015 | |
| 1016 | if (intel_get_param(screen, param, &value) == 0) |
| 1017 | return value; |
| 1018 | |
| 1019 | return -1; |
| 1020 | } |
| 1021 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1022 | static void |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 1023 | intelDestroyScreen(__DRIscreen * sPriv) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1024 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1025 | struct intel_screen *screen = sPriv->driverPrivate; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1026 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1027 | dri_bufmgr_destroy(screen->bufmgr); |
| 1028 | driDestroyOptionInfo(&screen->optionCache); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1029 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1030 | ralloc_free(screen); |
George Sapountzis | 875a757 | 2011-11-03 13:04:57 +0200 | [diff] [blame] | 1031 | sPriv->driverPrivate = NULL; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | /** |
| 1036 | * This is called when we need to set up GL rendering to a new X window. |
| 1037 | */ |
| 1038 | static GLboolean |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1039 | intelCreateBuffer(__DRIscreen *dri_screen, |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 1040 | __DRIdrawable * driDrawPriv, |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 1041 | const struct gl_config * mesaVis, GLboolean isPixmap) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1042 | { |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 1043 | struct intel_renderbuffer *rb; |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1044 | struct intel_screen *screen = (struct intel_screen *) |
| 1045 | dri_screen->driverPrivate; |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 1046 | mesa_format rgbFormat; |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1047 | unsigned num_samples = |
| 1048 | intel_quantize_num_samples(screen, mesaVis->samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1049 | struct gl_framebuffer *fb; |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 1050 | |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1051 | if (isPixmap) |
| 1052 | return false; |
| 1053 | |
| 1054 | fb = CALLOC_STRUCT(gl_framebuffer); |
| 1055 | if (!fb) |
| 1056 | return false; |
| 1057 | |
| 1058 | _mesa_initialize_window_framebuffer(fb, mesaVis); |
| 1059 | |
Eric Anholt | 4103350 | 2014-03-21 16:36:22 -0700 | [diff] [blame] | 1060 | if (screen->winsys_msaa_samples_override != -1) { |
| 1061 | num_samples = screen->winsys_msaa_samples_override; |
| 1062 | fb->Visual.samples = num_samples; |
| 1063 | } |
| 1064 | |
Haixia Shi | 35ade36 | 2016-04-07 11:05:09 -0700 | [diff] [blame] | 1065 | if (mesaVis->redBits == 5) { |
| 1066 | rgbFormat = mesaVis->redMask == 0x1f ? MESA_FORMAT_R5G6B5_UNORM |
| 1067 | : MESA_FORMAT_B5G6R5_UNORM; |
| 1068 | } else if (mesaVis->sRGBCapable) { |
| 1069 | rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8A8_SRGB |
| 1070 | : MESA_FORMAT_B8G8R8A8_SRGB; |
| 1071 | } else if (mesaVis->alphaBits == 0) { |
| 1072 | rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8X8_UNORM |
| 1073 | : MESA_FORMAT_B8G8R8X8_UNORM; |
| 1074 | } else { |
| 1075 | rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8A8_SRGB |
| 1076 | : MESA_FORMAT_B8G8R8A8_SRGB; |
Eric Anholt | 6fddd37 | 2013-06-20 16:10:43 -0700 | [diff] [blame] | 1077 | fb->Visual.sRGBCapable = true; |
Eric Anholt | e15c21a | 2013-02-15 07:41:42 -0800 | [diff] [blame] | 1078 | } |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1079 | |
| 1080 | /* setup the hardware-based renderbuffers */ |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1081 | rb = intel_create_renderbuffer(rgbFormat, num_samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1082 | _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base); |
| 1083 | |
| 1084 | if (mesaVis->doubleBufferMode) { |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1085 | rb = intel_create_renderbuffer(rgbFormat, num_samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1086 | _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base); |
| 1087 | } |
| 1088 | |
| 1089 | /* |
| 1090 | * Assert here that the gl_config has an expected depth/stencil bit |
| 1091 | * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(), |
| 1092 | * which constructs the advertised configs.) |
| 1093 | */ |
| 1094 | if (mesaVis->depthBits == 24) { |
| 1095 | assert(mesaVis->stencilBits == 8); |
| 1096 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1097 | if (screen->devinfo.has_hiz_and_separate_stencil) { |
Kenneth Graunke | a487ef8 | 2014-02-07 21:53:18 -0800 | [diff] [blame] | 1098 | rb = intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_X8_UINT, |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1099 | num_samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1100 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
Mark Mueller | 50a01d2 | 2014-01-20 19:08:54 -0800 | [diff] [blame] | 1101 | rb = intel_create_private_renderbuffer(MESA_FORMAT_S_UINT8, |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1102 | num_samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1103 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
| 1104 | } else { |
| 1105 | /* |
| 1106 | * Use combined depth/stencil. Note that the renderbuffer is |
| 1107 | * attached to two attachment points. |
| 1108 | */ |
Kenneth Graunke | a487ef8 | 2014-02-07 21:53:18 -0800 | [diff] [blame] | 1109 | rb = intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_S8_UINT, |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1110 | num_samples); |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1111 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
| 1112 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
| 1113 | } |
| 1114 | } |
| 1115 | else if (mesaVis->depthBits == 16) { |
| 1116 | assert(mesaVis->stencilBits == 0); |
Mark Mueller | 50a01d2 | 2014-01-20 19:08:54 -0800 | [diff] [blame] | 1117 | rb = intel_create_private_renderbuffer(MESA_FORMAT_Z_UNORM16, |
Chad Versace | e2f2376 | 2012-07-11 15:10:49 -0700 | [diff] [blame] | 1118 | num_samples); |
Chad Versace | 8c94f6b | 2012-07-09 17:01:29 -0700 | [diff] [blame] | 1119 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1120 | } |
| 1121 | else { |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1122 | assert(mesaVis->depthBits == 0); |
| 1123 | assert(mesaVis->stencilBits == 0); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1124 | } |
Chad Versace | 2b4fbc4 | 2012-07-09 16:51:23 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* now add any/all software-based renderbuffers we may need */ |
| 1127 | _swrast_add_soft_renderbuffers(fb, |
| 1128 | false, /* never sw color */ |
| 1129 | false, /* never sw depth */ |
| 1130 | false, /* never sw stencil */ |
| 1131 | mesaVis->accumRedBits > 0, |
| 1132 | false, /* never sw alpha */ |
| 1133 | false /* never sw aux */ ); |
| 1134 | driDrawPriv->driverPrivate = fb; |
| 1135 | |
| 1136 | return true; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | static void |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 1140 | intelDestroyBuffer(__DRIdrawable * driDrawPriv) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1141 | { |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 1142 | struct gl_framebuffer *fb = driDrawPriv->driverPrivate; |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 1143 | |
Kristian Høgsberg | d282128 | 2010-01-01 23:21:16 -0500 | [diff] [blame] | 1144 | _mesa_reference_framebuffer(&fb, NULL); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1147 | static void |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1148 | intel_detect_sseu(struct intel_screen *screen) |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1149 | { |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1150 | assert(screen->devinfo.gen >= 8); |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1151 | int ret; |
| 1152 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1153 | screen->subslice_total = -1; |
| 1154 | screen->eu_total = -1; |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1155 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1156 | ret = intel_get_param(screen, I915_PARAM_SUBSLICE_TOTAL, |
| 1157 | &screen->subslice_total); |
Ben Widawsky | a8975a9 | 2016-04-11 09:49:41 -0700 | [diff] [blame] | 1158 | if (ret < 0 && ret != -EINVAL) |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1159 | goto err_out; |
| 1160 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1161 | ret = intel_get_param(screen, |
| 1162 | I915_PARAM_EU_TOTAL, &screen->eu_total); |
Ben Widawsky | a8975a9 | 2016-04-11 09:49:41 -0700 | [diff] [blame] | 1163 | if (ret < 0 && ret != -EINVAL) |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1164 | goto err_out; |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1165 | |
| 1166 | /* Without this information, we cannot get the right Braswell brandstrings, |
| 1167 | * and we have to use conservative numbers for GPGPU on many platforms, but |
| 1168 | * otherwise, things will just work. |
| 1169 | */ |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1170 | if (screen->subslice_total < 1 || screen->eu_total < 1) |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1171 | _mesa_warning(NULL, |
| 1172 | "Kernel 4.1 required to properly query GPU properties.\n"); |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1173 | |
| 1174 | return; |
| 1175 | |
| 1176 | err_out: |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1177 | screen->subslice_total = -1; |
| 1178 | screen->eu_total = -1; |
Mark Janes | a2d28dd | 2016-05-19 13:42:16 -0700 | [diff] [blame] | 1179 | _mesa_warning(NULL, "Failed to query GPU properties (%s).\n", strerror(-ret)); |
Ben Widawsky | 4213b00 | 2016-04-07 10:53:12 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 1182 | static bool |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1183 | intel_init_bufmgr(struct intel_screen *screen) |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 1184 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1185 | __DRIscreen *dri_screen = screen->driScrnPriv; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 1186 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1187 | screen->no_hw = getenv("INTEL_NO_HW") != NULL; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 1188 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1189 | screen->bufmgr = intel_bufmgr_gem_init(dri_screen->fd, BATCH_SZ); |
| 1190 | if (screen->bufmgr == NULL) { |
Eric Anholt | 827ba44 | 2009-11-18 18:15:25 +0100 | [diff] [blame] | 1191 | fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", |
| 1192 | __func__, __LINE__); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 1193 | return false; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 1194 | } |
| 1195 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1196 | drm_intel_bufmgr_gem_enable_fenced_relocs(screen->bufmgr); |
Eric Anholt | 06d1472 | 2010-03-02 18:04:40 -0800 | [diff] [blame] | 1197 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1198 | if (!intel_get_boolean(screen, I915_PARAM_HAS_RELAXED_DELTA)) { |
Kenneth Graunke | 394edb5 | 2013-04-05 23:59:52 -0700 | [diff] [blame] | 1199 | fprintf(stderr, "[%s: %u] Kernel 2.6.39 required.\n", __func__, __LINE__); |
| 1200 | return false; |
| 1201 | } |
Chris Wilson | 900a5c9 | 2011-03-01 14:46:50 +0000 | [diff] [blame] | 1202 | |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 1203 | return true; |
Eric Anholt | 7e0bbdc | 2008-09-04 22:16:31 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
Daniel Vetter | f172eae | 2012-03-02 21:38:44 +0100 | [diff] [blame] | 1206 | static bool |
| 1207 | intel_detect_swizzling(struct intel_screen *screen) |
| 1208 | { |
| 1209 | drm_intel_bo *buffer; |
| 1210 | unsigned long flags = 0; |
| 1211 | unsigned long aligned_pitch; |
Daniel Stone | e54b2e9 | 2016-05-02 15:34:40 +0100 | [diff] [blame] | 1212 | uint32_t tiling = I915_TILING_X; |
Daniel Vetter | f172eae | 2012-03-02 21:38:44 +0100 | [diff] [blame] | 1213 | uint32_t swizzle_mode = 0; |
| 1214 | |
| 1215 | buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test", |
| 1216 | 64, 64, 4, |
| 1217 | &tiling, &aligned_pitch, flags); |
| 1218 | if (buffer == NULL) |
| 1219 | return false; |
| 1220 | |
| 1221 | drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode); |
| 1222 | drm_intel_bo_unreference(buffer); |
| 1223 | |
| 1224 | if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE) |
| 1225 | return false; |
| 1226 | else |
| 1227 | return true; |
| 1228 | } |
| 1229 | |
Chris Wilson | 013d731 | 2015-07-21 11:12:57 +0100 | [diff] [blame] | 1230 | static int |
Chris Wilson | c8d3eba | 2015-04-29 13:32:38 +0100 | [diff] [blame] | 1231 | intel_detect_timestamp(struct intel_screen *screen) |
| 1232 | { |
Chris Wilson | 013d731 | 2015-07-21 11:12:57 +0100 | [diff] [blame] | 1233 | uint64_t dummy = 0, last = 0; |
| 1234 | int upper, lower, loops; |
Chris Wilson | c8d3eba | 2015-04-29 13:32:38 +0100 | [diff] [blame] | 1235 | |
Chris Wilson | 013d731 | 2015-07-21 11:12:57 +0100 | [diff] [blame] | 1236 | /* On 64bit systems, some old kernels trigger a hw bug resulting in the |
| 1237 | * TIMESTAMP register being shifted and the low 32bits always zero. |
| 1238 | * |
| 1239 | * More recent kernels offer an interface to read the full 36bits |
| 1240 | * everywhere. |
Chris Wilson | c8d3eba | 2015-04-29 13:32:38 +0100 | [diff] [blame] | 1241 | */ |
Chris Wilson | 013d731 | 2015-07-21 11:12:57 +0100 | [diff] [blame] | 1242 | if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP | 1, &dummy) == 0) |
| 1243 | return 3; |
Chris Wilson | c8d3eba | 2015-04-29 13:32:38 +0100 | [diff] [blame] | 1244 | |
Chris Wilson | 013d731 | 2015-07-21 11:12:57 +0100 | [diff] [blame] | 1245 | /* Determine if we have a 32bit or 64bit kernel by inspecting the |
| 1246 | * upper 32bits for a rapidly changing timestamp. |
| 1247 | */ |
| 1248 | if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP, &last)) |
| 1249 | return 0; |
| 1250 | |
| 1251 | upper = lower = 0; |
| 1252 | for (loops = 0; loops < 10; loops++) { |
| 1253 | /* The TIMESTAMP should change every 80ns, so several round trips |
| 1254 | * through the kernel should be enough to advance it. |
| 1255 | */ |
| 1256 | if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP, &dummy)) |
| 1257 | return 0; |
| 1258 | |
| 1259 | upper += (dummy >> 32) != (last >> 32); |
| 1260 | if (upper > 1) /* beware 32bit counter overflow */ |
| 1261 | return 2; /* upper dword holds the low 32bits of the timestamp */ |
| 1262 | |
| 1263 | lower += (dummy & 0xffffffff) != (last & 0xffffffff); |
| 1264 | if (lower > 1) |
| 1265 | return 1; /* timestamp is unshifted */ |
| 1266 | |
| 1267 | last = dummy; |
| 1268 | } |
| 1269 | |
| 1270 | /* No advancement? No timestamp! */ |
| 1271 | return 0; |
Chris Wilson | c8d3eba | 2015-04-29 13:32:38 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Chris Wilson | 02a4448 | 2017-01-04 08:34:59 +0100 | [diff] [blame] | 1274 | /** |
| 1275 | * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer. |
| 1276 | * |
| 1277 | * Some combinations of hardware and kernel versions allow this feature, |
| 1278 | * while others don't. Instead of trying to enumerate every case, just |
| 1279 | * try and write a register and see if works. |
| 1280 | */ |
| 1281 | static bool |
| 1282 | intel_detect_pipelined_register(struct intel_screen *screen, |
| 1283 | int reg, uint32_t expected_value, bool reset) |
| 1284 | { |
| 1285 | drm_intel_bo *results, *bo; |
| 1286 | uint32_t *batch; |
| 1287 | uint32_t offset = 0; |
| 1288 | bool success = false; |
| 1289 | |
| 1290 | /* Create a zero'ed temporary buffer for reading our results */ |
| 1291 | results = drm_intel_bo_alloc(screen->bufmgr, "registers", 4096, 0); |
| 1292 | if (results == NULL) |
| 1293 | goto err; |
| 1294 | |
| 1295 | bo = drm_intel_bo_alloc(screen->bufmgr, "batchbuffer", 4096, 0); |
| 1296 | if (bo == NULL) |
| 1297 | goto err_results; |
| 1298 | |
| 1299 | if (drm_intel_bo_map(bo, 1)) |
| 1300 | goto err_batch; |
| 1301 | |
| 1302 | batch = bo->virtual; |
| 1303 | |
| 1304 | /* Write the register. */ |
| 1305 | *batch++ = MI_LOAD_REGISTER_IMM | (3 - 2); |
| 1306 | *batch++ = reg; |
| 1307 | *batch++ = expected_value; |
| 1308 | |
| 1309 | /* Save the register's value back to the buffer. */ |
| 1310 | *batch++ = MI_STORE_REGISTER_MEM | (3 - 2); |
| 1311 | *batch++ = reg; |
| 1312 | drm_intel_bo_emit_reloc(bo, (char *)batch -(char *)bo->virtual, |
| 1313 | results, offset*sizeof(uint32_t), |
| 1314 | I915_GEM_DOMAIN_INSTRUCTION, |
| 1315 | I915_GEM_DOMAIN_INSTRUCTION); |
| 1316 | *batch++ = results->offset + offset*sizeof(uint32_t); |
| 1317 | |
| 1318 | /* And afterwards clear the register */ |
| 1319 | if (reset) { |
| 1320 | *batch++ = MI_LOAD_REGISTER_IMM | (3 - 2); |
| 1321 | *batch++ = reg; |
| 1322 | *batch++ = 0; |
| 1323 | } |
| 1324 | |
| 1325 | *batch++ = MI_BATCH_BUFFER_END; |
| 1326 | |
| 1327 | drm_intel_bo_mrb_exec(bo, ALIGN((char *)batch - (char *)bo->virtual, 8), |
| 1328 | NULL, 0, 0, |
| 1329 | I915_EXEC_RENDER); |
| 1330 | |
| 1331 | /* Check whether the value got written. */ |
| 1332 | if (drm_intel_bo_map(results, false) == 0) { |
| 1333 | success = *((uint32_t *)results->virtual + offset) == expected_value; |
| 1334 | drm_intel_bo_unmap(results); |
| 1335 | } |
| 1336 | |
| 1337 | err_batch: |
| 1338 | drm_intel_bo_unreference(bo); |
| 1339 | err_results: |
| 1340 | drm_intel_bo_unreference(results); |
| 1341 | err: |
| 1342 | return success; |
| 1343 | } |
| 1344 | |
| 1345 | static bool |
| 1346 | intel_detect_pipelined_so(struct intel_screen *screen) |
| 1347 | { |
| 1348 | /* Supposedly, Broadwell just works. */ |
| 1349 | if (screen->devinfo.gen >= 8) |
| 1350 | return true; |
| 1351 | |
| 1352 | if (screen->devinfo.gen <= 6) |
| 1353 | return false; |
| 1354 | |
| 1355 | /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the |
| 1356 | * statistics registers), and we already reset it to zero before using it. |
| 1357 | */ |
| 1358 | return intel_detect_pipelined_register(screen, |
| 1359 | GEN7_SO_WRITE_OFFSET(0), |
| 1360 | 0x1337d0d0, |
| 1361 | false); |
| 1362 | } |
| 1363 | |
Chad Versace | 95ebabb | 2013-11-06 19:40:25 -0800 | [diff] [blame] | 1364 | /** |
| 1365 | * Return array of MSAA modes supported by the hardware. The array is |
| 1366 | * zero-terminated and sorted in decreasing order. |
| 1367 | */ |
| 1368 | const int* |
| 1369 | intel_supported_msaa_modes(const struct intel_screen *screen) |
| 1370 | { |
Neil Roberts | 6c5f371 | 2015-09-07 18:23:14 +0100 | [diff] [blame] | 1371 | static const int gen9_modes[] = {16, 8, 4, 2, 0, -1}; |
Kenneth Graunke | 5740560 | 2014-02-10 11:42:47 -0800 | [diff] [blame] | 1372 | static const int gen8_modes[] = {8, 4, 2, 0, -1}; |
Chad Versace | 95ebabb | 2013-11-06 19:40:25 -0800 | [diff] [blame] | 1373 | static const int gen7_modes[] = {8, 4, 0, -1}; |
| 1374 | static const int gen6_modes[] = {4, 0, -1}; |
| 1375 | static const int gen4_modes[] = {0, -1}; |
| 1376 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1377 | if (screen->devinfo.gen >= 9) { |
Neil Roberts | 6c5f371 | 2015-09-07 18:23:14 +0100 | [diff] [blame] | 1378 | return gen9_modes; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1379 | } else if (screen->devinfo.gen >= 8) { |
Kenneth Graunke | 5740560 | 2014-02-10 11:42:47 -0800 | [diff] [blame] | 1380 | return gen8_modes; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1381 | } else if (screen->devinfo.gen >= 7) { |
Chad Versace | 95ebabb | 2013-11-06 19:40:25 -0800 | [diff] [blame] | 1382 | return gen7_modes; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1383 | } else if (screen->devinfo.gen == 6) { |
Chad Versace | 95ebabb | 2013-11-06 19:40:25 -0800 | [diff] [blame] | 1384 | return gen6_modes; |
| 1385 | } else { |
| 1386 | return gen4_modes; |
| 1387 | } |
| 1388 | } |
| 1389 | |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1390 | static __DRIconfig** |
| 1391 | intel_screen_make_configs(__DRIscreen *dri_screen) |
| 1392 | { |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 1393 | static const mesa_format formats[] = { |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 1394 | MESA_FORMAT_B5G6R5_UNORM, |
Boyan Ding | 28090b3 | 2015-03-25 19:36:54 +0800 | [diff] [blame] | 1395 | MESA_FORMAT_B8G8R8A8_UNORM, |
| 1396 | MESA_FORMAT_B8G8R8X8_UNORM |
Ian Romanick | 1f6e10f | 2012-07-12 13:52:06 -0700 | [diff] [blame] | 1397 | }; |
| 1398 | |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1399 | /* GLX_SWAP_COPY_OML is not supported due to page flipping. */ |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1400 | static const GLenum back_buffer_modes[] = { |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1401 | GLX_SWAP_UNDEFINED_OML, GLX_NONE, |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1402 | }; |
| 1403 | |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1404 | static const uint8_t singlesample_samples[1] = {0}; |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1405 | static const uint8_t multisample_samples[2] = {4, 8}; |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1406 | |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1407 | struct intel_screen *screen = dri_screen->driverPrivate; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1408 | const struct gen_device_info *devinfo = &screen->devinfo; |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1409 | uint8_t depth_bits[4], stencil_bits[4]; |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1410 | __DRIconfig **configs = NULL; |
| 1411 | |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1412 | /* Generate singlesample configs without accumulation buffer. */ |
Rhys Kidd | f4ef8d0 | 2015-08-06 16:34:03 +1000 | [diff] [blame] | 1413 | for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1414 | __DRIconfig **new_configs; |
Tapani Pälli | e4e3b07 | 2012-10-29 11:56:28 -0700 | [diff] [blame] | 1415 | int num_depth_stencil_bits = 2; |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1416 | |
| 1417 | /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil |
| 1418 | * buffer that has a different number of bits per pixel than the color |
Tapani Pälli | e4e3b07 | 2012-10-29 11:56:28 -0700 | [diff] [blame] | 1419 | * buffer, gen >= 6 supports this. |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1420 | */ |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1421 | depth_bits[0] = 0; |
| 1422 | stencil_bits[0] = 0; |
| 1423 | |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 1424 | if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) { |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1425 | depth_bits[1] = 16; |
| 1426 | stencil_bits[1] = 0; |
Kenneth Graunke | afe05e7 | 2013-07-04 12:35:22 -0700 | [diff] [blame] | 1427 | if (devinfo->gen >= 6) { |
Tapani Pälli | e4e3b07 | 2012-10-29 11:56:28 -0700 | [diff] [blame] | 1428 | depth_bits[2] = 24; |
| 1429 | stencil_bits[2] = 8; |
| 1430 | num_depth_stencil_bits = 3; |
| 1431 | } |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1432 | } else { |
| 1433 | depth_bits[1] = 24; |
| 1434 | stencil_bits[1] = 8; |
| 1435 | } |
| 1436 | |
Ian Romanick | 1f6e10f | 2012-07-12 13:52:06 -0700 | [diff] [blame] | 1437 | new_configs = driCreateConfigs(formats[i], |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1438 | depth_bits, |
| 1439 | stencil_bits, |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1440 | num_depth_stencil_bits, |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1441 | back_buffer_modes, 2, |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1442 | singlesample_samples, 1, |
Ilia Mirkin | 5283900 | 2016-08-20 16:10:20 -0400 | [diff] [blame] | 1443 | false, false); |
Chad Versace | a4bf68c | 2012-08-01 21:23:47 -0700 | [diff] [blame] | 1444 | configs = driConcatConfigs(configs, new_configs); |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /* Generate the minimum possible set of configs that include an |
| 1448 | * accumulation buffer. |
| 1449 | */ |
Rhys Kidd | f4ef8d0 | 2015-08-06 16:34:03 +1000 | [diff] [blame] | 1450 | for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1451 | __DRIconfig **new_configs; |
| 1452 | |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 1453 | if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) { |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1454 | depth_bits[0] = 16; |
| 1455 | stencil_bits[0] = 0; |
| 1456 | } else { |
| 1457 | depth_bits[0] = 24; |
| 1458 | stencil_bits[0] = 8; |
| 1459 | } |
| 1460 | |
Ian Romanick | 1f6e10f | 2012-07-12 13:52:06 -0700 | [diff] [blame] | 1461 | new_configs = driCreateConfigs(formats[i], |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1462 | depth_bits, stencil_bits, 1, |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1463 | back_buffer_modes, 1, |
Chad Versace | 8b5d68d | 2012-08-02 14:51:47 -0700 | [diff] [blame] | 1464 | singlesample_samples, 1, |
Ilia Mirkin | 5283900 | 2016-08-20 16:10:20 -0400 | [diff] [blame] | 1465 | true, false); |
Chad Versace | a4bf68c | 2012-08-01 21:23:47 -0700 | [diff] [blame] | 1466 | configs = driConcatConfigs(configs, new_configs); |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1469 | /* Generate multisample configs. |
| 1470 | * |
| 1471 | * This loop breaks early, and hence is a no-op, on gen < 6. |
| 1472 | * |
| 1473 | * Multisample configs must follow the singlesample configs in order to |
| 1474 | * work around an X server bug present in 1.12. The X server chooses to |
| 1475 | * associate the first listed RGBA888-Z24S8 config, regardless of its |
| 1476 | * sample count, with the 32-bit depth visual used for compositing. |
| 1477 | * |
| 1478 | * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are |
| 1479 | * supported. Singlebuffer configs are not supported because no one wants |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1480 | * them. |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1481 | */ |
Rhys Kidd | f4ef8d0 | 2015-08-06 16:34:03 +1000 | [diff] [blame] | 1482 | for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { |
Kenneth Graunke | afe05e7 | 2013-07-04 12:35:22 -0700 | [diff] [blame] | 1483 | if (devinfo->gen < 6) |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | |
| 1486 | __DRIconfig **new_configs; |
| 1487 | const int num_depth_stencil_bits = 2; |
Eric Anholt | 3aaeb3e | 2012-08-07 11:33:10 -0700 | [diff] [blame] | 1488 | int num_msaa_modes = 0; |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1489 | |
| 1490 | depth_bits[0] = 0; |
| 1491 | stencil_bits[0] = 0; |
| 1492 | |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 1493 | if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) { |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1494 | depth_bits[1] = 16; |
| 1495 | stencil_bits[1] = 0; |
| 1496 | } else { |
| 1497 | depth_bits[1] = 24; |
| 1498 | stencil_bits[1] = 8; |
| 1499 | } |
| 1500 | |
Kenneth Graunke | afe05e7 | 2013-07-04 12:35:22 -0700 | [diff] [blame] | 1501 | if (devinfo->gen >= 7) |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1502 | num_msaa_modes = 2; |
Kenneth Graunke | afe05e7 | 2013-07-04 12:35:22 -0700 | [diff] [blame] | 1503 | else if (devinfo->gen == 6) |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1504 | num_msaa_modes = 1; |
| 1505 | |
Ian Romanick | 1f6e10f | 2012-07-12 13:52:06 -0700 | [diff] [blame] | 1506 | new_configs = driCreateConfigs(formats[i], |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1507 | depth_bits, |
| 1508 | stencil_bits, |
| 1509 | num_depth_stencil_bits, |
Chad Versace | 7dc0be8 | 2012-08-09 09:06:42 -0700 | [diff] [blame] | 1510 | back_buffer_modes, 1, |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1511 | multisample_samples, |
| 1512 | num_msaa_modes, |
Ilia Mirkin | 5283900 | 2016-08-20 16:10:20 -0400 | [diff] [blame] | 1513 | false, false); |
Chad Versace | e943e5c | 2012-08-02 17:13:17 -0700 | [diff] [blame] | 1514 | configs = driConcatConfigs(configs, new_configs); |
| 1515 | } |
| 1516 | |
Chad Versace | b2d428c | 2012-07-12 14:17:22 -0700 | [diff] [blame] | 1517 | if (configs == NULL) { |
| 1518 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
| 1519 | __LINE__); |
| 1520 | return NULL; |
| 1521 | } |
| 1522 | |
| 1523 | return configs; |
| 1524 | } |
| 1525 | |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1526 | static void |
| 1527 | set_max_gl_versions(struct intel_screen *screen) |
| 1528 | { |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1529 | __DRIscreen *dri_screen = screen->driScrnPriv; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1530 | const bool has_astc = screen->devinfo.gen >= 9; |
Jordan Justen | fde59a2 | 2013-02-21 16:59:33 -0800 | [diff] [blame] | 1531 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1532 | switch (screen->devinfo.gen) { |
Jordan Justen | e813728 | 2014-04-20 17:31:30 -0700 | [diff] [blame] | 1533 | case 9: |
Kenneth Graunke | 232140a | 2013-11-01 11:45:47 -0700 | [diff] [blame] | 1534 | case 8: |
Kenneth Graunke | 75128d6 | 2016-10-14 16:33:19 -0700 | [diff] [blame] | 1535 | dri_screen->max_gl_core_version = 45; |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1536 | dri_screen->max_gl_compat_version = 30; |
| 1537 | dri_screen->max_gl_es1_version = 11; |
Kenneth Graunke | a53da57 | 2016-09-20 20:33:54 -0700 | [diff] [blame] | 1538 | dri_screen->max_gl_es2_version = has_astc ? 32 : 31; |
Jordan Justen | e97b207 | 2015-12-15 15:53:20 -0800 | [diff] [blame] | 1539 | break; |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1540 | case 7: |
Iago Toral Quiroga | e3123c8 | 2017-01-03 09:27:09 +0100 | [diff] [blame] | 1541 | dri_screen->max_gl_core_version = screen->devinfo.is_haswell && |
Kenneth Graunke | d2590eb | 2017-01-13 22:53:34 -0800 | [diff] [blame^] | 1542 | can_do_pipelined_register_writes(screen) ? 45 : 33; |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1543 | dri_screen->max_gl_compat_version = 30; |
| 1544 | dri_screen->max_gl_es1_version = 11; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1545 | dri_screen->max_gl_es2_version = screen->devinfo.is_haswell ? 31 : 30; |
Jordan Justen | 93f5eb7 | 2016-06-08 13:17:41 -0700 | [diff] [blame] | 1546 | break; |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1547 | case 6: |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1548 | dri_screen->max_gl_core_version = 33; |
| 1549 | dri_screen->max_gl_compat_version = 30; |
| 1550 | dri_screen->max_gl_es1_version = 11; |
| 1551 | dri_screen->max_gl_es2_version = 30; |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1552 | break; |
| 1553 | case 5: |
| 1554 | case 4: |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1555 | dri_screen->max_gl_core_version = 0; |
| 1556 | dri_screen->max_gl_compat_version = 21; |
| 1557 | dri_screen->max_gl_es1_version = 11; |
| 1558 | dri_screen->max_gl_es2_version = 20; |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1559 | break; |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1560 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 1561 | unreachable("unrecognized intel_screen::gen"); |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1562 | } |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Ben Widawsky | 9ecfc6b | 2015-10-23 14:38:39 -0700 | [diff] [blame] | 1565 | /** |
| 1566 | * Return the revision (generally the revid field of the PCI header) of the |
| 1567 | * graphics device. |
| 1568 | * |
| 1569 | * XXX: This function is useful to keep around even if it is not currently in |
| 1570 | * use. It is necessary for new platforms and revision specific workarounds or |
| 1571 | * features. Please don't remove it so that we know it at least continues to |
| 1572 | * build. |
| 1573 | */ |
| 1574 | static __attribute__((__unused__)) int |
Jason Ekstrand | 38dc2dd | 2015-04-16 17:52:03 -0700 | [diff] [blame] | 1575 | brw_get_revision(int fd) |
| 1576 | { |
| 1577 | struct drm_i915_getparam gp; |
| 1578 | int revision; |
| 1579 | int ret; |
| 1580 | |
| 1581 | memset(&gp, 0, sizeof(gp)); |
| 1582 | gp.param = I915_PARAM_REVISION; |
| 1583 | gp.value = &revision; |
| 1584 | |
| 1585 | ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); |
| 1586 | if (ret) |
| 1587 | revision = -1; |
| 1588 | |
| 1589 | return revision; |
| 1590 | } |
| 1591 | |
Abdiel Janulgue | 090529a | 2013-07-02 11:48:22 -0400 | [diff] [blame] | 1592 | /* Drop when RS headers get pulled to libdrm */ |
| 1593 | #ifndef I915_PARAM_HAS_RESOURCE_STREAMER |
| 1594 | #define I915_PARAM_HAS_RESOURCE_STREAMER 36 |
| 1595 | #endif |
| 1596 | |
Jason Ekstrand | 870ff6c | 2016-05-25 18:19:50 -0700 | [diff] [blame] | 1597 | static void |
| 1598 | shader_debug_log_mesa(void *data, const char *fmt, ...) |
| 1599 | { |
| 1600 | struct brw_context *brw = (struct brw_context *)data; |
| 1601 | va_list args; |
| 1602 | |
| 1603 | va_start(args, fmt); |
| 1604 | GLuint msg_id = 0; |
| 1605 | _mesa_gl_vdebug(&brw->ctx, &msg_id, |
| 1606 | MESA_DEBUG_SOURCE_SHADER_COMPILER, |
| 1607 | MESA_DEBUG_TYPE_OTHER, |
| 1608 | MESA_DEBUG_SEVERITY_NOTIFICATION, fmt, args); |
| 1609 | va_end(args); |
| 1610 | } |
| 1611 | |
| 1612 | static void |
| 1613 | shader_perf_log_mesa(void *data, const char *fmt, ...) |
| 1614 | { |
| 1615 | struct brw_context *brw = (struct brw_context *)data; |
| 1616 | |
| 1617 | va_list args; |
| 1618 | va_start(args, fmt); |
| 1619 | |
| 1620 | if (unlikely(INTEL_DEBUG & DEBUG_PERF)) { |
| 1621 | va_list args_copy; |
| 1622 | va_copy(args_copy, args); |
| 1623 | vfprintf(stderr, fmt, args_copy); |
| 1624 | va_end(args_copy); |
| 1625 | } |
| 1626 | |
| 1627 | if (brw->perf_debug) { |
| 1628 | GLuint msg_id = 0; |
| 1629 | _mesa_gl_vdebug(&brw->ctx, &msg_id, |
| 1630 | MESA_DEBUG_SOURCE_SHADER_COMPILER, |
| 1631 | MESA_DEBUG_TYPE_PERFORMANCE, |
| 1632 | MESA_DEBUG_SEVERITY_MEDIUM, fmt, args); |
| 1633 | } |
| 1634 | va_end(args); |
| 1635 | } |
| 1636 | |
Chad Versace | 6b2bf27 | 2011-05-26 15:24:48 -0700 | [diff] [blame] | 1637 | /** |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1638 | * This is the driver specific part of the createNewScreen entry point. |
Brian Paul | 8d976ae | 2008-06-11 19:33:14 -0600 | [diff] [blame] | 1639 | * Called when using DRI2. |
| 1640 | * |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 1641 | * \return the struct gl_config supported by this driver |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1642 | */ |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1643 | static const |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1644 | __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen) |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1645 | { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1646 | struct intel_screen *screen; |
Kristian Høgsberg | 7c50d29 | 2010-01-08 12:35:47 -0500 | [diff] [blame] | 1647 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1648 | if (dri_screen->image.loader) { |
| 1649 | } else if (dri_screen->dri2.loader->base.version <= 2 || |
| 1650 | dri_screen->dri2.loader->getBuffersWithFormat == NULL) { |
Eric Anholt | 1b4374d | 2012-07-04 10:52:34 -0700 | [diff] [blame] | 1651 | fprintf(stderr, |
| 1652 | "\nERROR! DRI2 loader with getBuffersWithFormat() " |
| 1653 | "support required\n"); |
| 1654 | return false; |
| 1655 | } |
| 1656 | |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1657 | /* Allocate the private area */ |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1658 | screen = rzalloc(NULL, struct intel_screen); |
| 1659 | if (!screen) { |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1660 | fprintf(stderr, "\nERROR! Allocating private area failed\n"); |
Kenneth Graunke | 2e5a1a2 | 2011-10-07 12:26:50 -0700 | [diff] [blame] | 1661 | return false; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1662 | } |
| 1663 | /* parse information in __driConfigOptions */ |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1664 | driParseOptionInfo(&screen->optionCache, brw_config_options.xml); |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1665 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1666 | screen->driScrnPriv = dri_screen; |
| 1667 | dri_screen->driverPrivate = (void *) screen; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1668 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1669 | if (!intel_init_bufmgr(screen)) |
Eric Anholt | 2222aa0 | 2012-03-09 16:27:35 -0800 | [diff] [blame] | 1670 | return false; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1671 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1672 | screen->deviceID = drm_intel_bufmgr_gem_get_devid(screen->bufmgr); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1673 | if (!gen_get_device_info(screen->deviceID, &screen->devinfo)) |
Kenneth Graunke | eaf3358 | 2014-02-10 01:54:23 -0800 | [diff] [blame] | 1674 | return false; |
Eric Anholt | 4ac2f09 | 2010-12-02 18:25:45 -0800 | [diff] [blame] | 1675 | |
Kristian Høgsberg Kristensen | 99ca225 | 2015-10-06 16:19:04 -0700 | [diff] [blame] | 1676 | brw_process_intel_debug_variable(); |
| 1677 | |
| 1678 | if (INTEL_DEBUG & DEBUG_BUFMGR) |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1679 | dri_bufmgr_set_debug(screen->bufmgr, true); |
Kristian Høgsberg Kristensen | 99ca225 | 2015-10-06 16:19:04 -0700 | [diff] [blame] | 1680 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1681 | if ((INTEL_DEBUG & DEBUG_SHADER_TIME) && screen->devinfo.gen < 7) { |
Kristian Høgsberg Kristensen | 99ca225 | 2015-10-06 16:19:04 -0700 | [diff] [blame] | 1682 | fprintf(stderr, |
| 1683 | "shader_time debugging requires gen7 (Ivybridge) or better.\n"); |
| 1684 | INTEL_DEBUG &= ~DEBUG_SHADER_TIME; |
| 1685 | } |
| 1686 | |
| 1687 | if (INTEL_DEBUG & DEBUG_AUB) |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1688 | drm_intel_bufmgr_gem_set_aub_dump(screen->bufmgr, true); |
Jason Ekstrand | 1bc3b62 | 2015-04-16 17:39:13 -0700 | [diff] [blame] | 1689 | |
Chris Wilson | f92a87a | 2016-08-24 20:35:46 +0100 | [diff] [blame] | 1690 | #ifndef I915_PARAM_MMAP_GTT_VERSION |
| 1691 | #define I915_PARAM_MMAP_GTT_VERSION 40 /* XXX delete me with new libdrm */ |
| 1692 | #endif |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1693 | if (intel_get_integer(screen, I915_PARAM_MMAP_GTT_VERSION) >= 1) { |
Chris Wilson | f92a87a | 2016-08-24 20:35:46 +0100 | [diff] [blame] | 1694 | /* Theorectically unlimited! At least for individual objects... |
| 1695 | * |
| 1696 | * Currently the entire (global) address space for all GTT maps is |
| 1697 | * limited to 64bits. That is all objects on the system that are |
| 1698 | * setup for GTT mmapping must fit within 64bits. An attempt to use |
| 1699 | * one that exceeds the limit with fail in drm_intel_bo_map_gtt(). |
| 1700 | * |
| 1701 | * Long before we hit that limit, we will be practically limited by |
| 1702 | * that any single object must fit in physical memory (RAM). The upper |
| 1703 | * limit on the CPU's address space is currently 48bits (Skylake), of |
| 1704 | * which only 39bits can be physical memory. (The GPU itself also has |
| 1705 | * a 48bit addressable virtual space.) We can fit over 32 million |
| 1706 | * objects of the current maximum allocable size before running out |
| 1707 | * of mmap space. |
| 1708 | */ |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1709 | screen->max_gtt_map_object_size = UINT64_MAX; |
Chris Wilson | f92a87a | 2016-08-24 20:35:46 +0100 | [diff] [blame] | 1710 | } else { |
| 1711 | /* Estimate the size of the mappable aperture into the GTT. There's an |
| 1712 | * ioctl to get the whole GTT size, but not one to get the mappable subset. |
| 1713 | * It turns out it's basically always 256MB, though some ancient hardware |
| 1714 | * was smaller. |
| 1715 | */ |
| 1716 | uint32_t gtt_size = 256 * 1024 * 1024; |
| 1717 | |
| 1718 | /* We don't want to map two objects such that a memcpy between them would |
| 1719 | * just fault one mapping in and then the other over and over forever. So |
| 1720 | * we would need to divide the GTT size by 2. Additionally, some GTT is |
| 1721 | * taken up by things like the framebuffer and the ringbuffer and such, so |
| 1722 | * be more conservative. |
| 1723 | */ |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1724 | screen->max_gtt_map_object_size = gtt_size / 4; |
Chris Wilson | f92a87a | 2016-08-24 20:35:46 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1727 | screen->hw_has_swizzling = intel_detect_swizzling(screen); |
| 1728 | screen->hw_has_timestamp = intel_detect_timestamp(screen); |
Daniel Vetter | f172eae | 2012-03-02 21:38:44 +0100 | [diff] [blame] | 1729 | |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1730 | /* GENs prior to 8 do not support EU/Subslice info */ |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1731 | if (screen->devinfo.gen >= 8) { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1732 | intel_detect_sseu(screen); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1733 | } else if (screen->devinfo.gen == 7) { |
| 1734 | screen->subslice_total = 1 << (screen->devinfo.gt - 1); |
Kenneth Graunke | 9cd8f95 | 2016-06-08 23:36:16 -0700 | [diff] [blame] | 1735 | } |
Ben Widawsky | cc01b63 | 2016-04-07 10:53:13 -0700 | [diff] [blame] | 1736 | |
Chris Wilson | 02a4448 | 2017-01-04 08:34:59 +0100 | [diff] [blame] | 1737 | if (intel_detect_pipelined_so(screen)) |
Iago Toral Quiroga | a98f2e5 | 2017-01-04 10:46:08 +0100 | [diff] [blame] | 1738 | screen->kernel_features |= KERNEL_ALLOWS_SOL_OFFSET_WRITES; |
Chris Wilson | 02a4448 | 2017-01-04 08:34:59 +0100 | [diff] [blame] | 1739 | |
Eric Anholt | 4103350 | 2014-03-21 16:36:22 -0700 | [diff] [blame] | 1740 | const char *force_msaa = getenv("INTEL_FORCE_MSAA"); |
| 1741 | if (force_msaa) { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1742 | screen->winsys_msaa_samples_override = |
| 1743 | intel_quantize_num_samples(screen, atoi(force_msaa)); |
Eric Anholt | 4103350 | 2014-03-21 16:36:22 -0700 | [diff] [blame] | 1744 | printf("Forcing winsys sample count to %d\n", |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1745 | screen->winsys_msaa_samples_override); |
Eric Anholt | 4103350 | 2014-03-21 16:36:22 -0700 | [diff] [blame] | 1746 | } else { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1747 | screen->winsys_msaa_samples_override = -1; |
Eric Anholt | 4103350 | 2014-03-21 16:36:22 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1750 | set_max_gl_versions(screen); |
Chad Versace | 4945086f3 | 2012-11-21 15:08:27 -0800 | [diff] [blame] | 1751 | |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 1752 | /* Notification of GPU resets requires hardware contexts and a kernel new |
| 1753 | * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is |
| 1754 | * supported, calling it with a context of 0 will either generate EPERM or |
| 1755 | * no error. If the ioctl is not supported, it always generate EINVAL. |
| 1756 | * Use this to determine whether to advertise the __DRI2_ROBUSTNESS |
| 1757 | * extension to the loader. |
Kenneth Graunke | 0380ec4 | 2014-03-12 01:43:40 -0700 | [diff] [blame] | 1758 | * |
| 1759 | * Don't even try on pre-Gen6, since we don't attempt to use contexts there. |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 1760 | */ |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1761 | if (screen->devinfo.gen >= 6) { |
Kenneth Graunke | 0380ec4 | 2014-03-12 01:43:40 -0700 | [diff] [blame] | 1762 | struct drm_i915_reset_stats stats; |
| 1763 | memset(&stats, 0, sizeof(stats)); |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 1764 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1765 | const int ret = drmIoctl(dri_screen->fd, DRM_IOCTL_I915_GET_RESET_STATS, &stats); |
Ian Romanick | 9b1c686 | 2013-11-19 17:01:23 -0800 | [diff] [blame] | 1766 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1767 | screen->has_context_reset_notification = |
Kenneth Graunke | 0380ec4 | 2014-03-12 01:43:40 -0700 | [diff] [blame] | 1768 | (ret != -1 || errno != EINVAL); |
| 1769 | } |
Ian Romanick | 53a65e5 | 2013-11-26 16:27:57 -0800 | [diff] [blame] | 1770 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1771 | if (intel_get_param(screen, I915_PARAM_CMD_PARSER_VERSION, |
| 1772 | &screen->cmd_parser_version) < 0) { |
| 1773 | screen->cmd_parser_version = 0; |
Chad Versace | a2ae888 | 2016-06-27 11:50:17 -0700 | [diff] [blame] | 1774 | } |
Neil Roberts | 8a59f2f | 2014-11-07 18:20:17 +0000 | [diff] [blame] | 1775 | |
Rafael Antognolli | ea7e4b1 | 2017-01-05 10:33:53 -0800 | [diff] [blame] | 1776 | if (screen->devinfo.gen >= 8 || screen->cmd_parser_version >= 2) |
Iago Toral Quiroga | a98f2e5 | 2017-01-04 10:46:08 +0100 | [diff] [blame] | 1777 | screen->kernel_features |= KERNEL_ALLOWS_PREDICATE_WRITES; |
| 1778 | |
| 1779 | /* Haswell requires command parser version 4 in order to have L3 |
| 1780 | * atomic scratch1 and chicken3 bits |
| 1781 | */ |
| 1782 | if (screen->devinfo.is_haswell && screen->cmd_parser_version >= 4) { |
| 1783 | screen->kernel_features |= |
| 1784 | KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3; |
| 1785 | } |
| 1786 | |
Kenneth Graunke | 4c71c8a | 2016-05-05 01:57:30 -0700 | [diff] [blame] | 1787 | /* Haswell requires command parser version 6 in order to write to the |
| 1788 | * MI_MATH GPR registers, and version 7 in order to use |
| 1789 | * MI_LOAD_REGISTER_REG (which all users of MI_MATH use). |
| 1790 | */ |
Iago Toral Quiroga | a98f2e5 | 2017-01-04 10:46:08 +0100 | [diff] [blame] | 1791 | if (screen->devinfo.gen >= 8 || |
| 1792 | (screen->devinfo.is_haswell && screen->cmd_parser_version >= 7)) { |
| 1793 | screen->kernel_features |= KERNEL_ALLOWS_MI_MATH_AND_LRR; |
| 1794 | } |
| 1795 | |
| 1796 | /* Gen7 needs at least command parser version 5 to support compute */ |
| 1797 | if (screen->devinfo.gen >= 8 || screen->cmd_parser_version >= 5) |
| 1798 | screen->kernel_features |= KERNEL_ALLOWS_COMPUTE_DISPATCH; |
Kenneth Graunke | 4c71c8a | 2016-05-05 01:57:30 -0700 | [diff] [blame] | 1799 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1800 | dri_screen->extensions = !screen->has_context_reset_notification |
| 1801 | ? screenExtensions : intelRobustScreenExtensions; |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1802 | |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1803 | screen->compiler = brw_compiler_create(screen, |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1804 | &screen->devinfo); |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1805 | screen->compiler->shader_debug_log = shader_debug_log_mesa; |
| 1806 | screen->compiler->shader_perf_log = shader_perf_log_mesa; |
| 1807 | screen->program_id = 1; |
Kenneth Graunke | 7a0fd3c | 2014-03-17 13:53:44 -0700 | [diff] [blame] | 1808 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 1809 | if (screen->devinfo.has_resource_streamer) { |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1810 | screen->has_resource_streamer = |
| 1811 | intel_get_boolean(screen, I915_PARAM_HAS_RESOURCE_STREAMER); |
Abdiel Janulgue | 090529a | 2013-07-02 11:48:22 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1814 | return (const __DRIconfig**) intel_screen_make_configs(dri_screen); |
Kristian Høgsberg | c5c73c1 | 2008-01-21 17:07:33 -0500 | [diff] [blame] | 1815 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1816 | |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1817 | struct intel_buffer { |
| 1818 | __DRIbuffer base; |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1819 | drm_intel_bo *bo; |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1820 | }; |
| 1821 | |
| 1822 | static __DRIbuffer * |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1823 | intelAllocateBuffer(__DRIscreen *dri_screen, |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1824 | unsigned attachment, unsigned format, |
| 1825 | int width, int height) |
| 1826 | { |
| 1827 | struct intel_buffer *intelBuffer; |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1828 | struct intel_screen *screen = dri_screen->driverPrivate; |
Chad Versace | 79653c1 | 2011-11-15 07:08:49 -0800 | [diff] [blame] | 1829 | |
Chad Versace | 83fa084 | 2012-07-09 15:51:06 -0700 | [diff] [blame] | 1830 | assert(attachment == __DRI_BUFFER_FRONT_LEFT || |
| 1831 | attachment == __DRI_BUFFER_BACK_LEFT); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1832 | |
Brian Paul | 4fdac65 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 1833 | intelBuffer = calloc(1, sizeof *intelBuffer); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1834 | if (intelBuffer == NULL) |
| 1835 | return NULL; |
| 1836 | |
Chad Versace | 83fa084 | 2012-07-09 15:51:06 -0700 | [diff] [blame] | 1837 | /* The front and back buffers are color buffers, which are X tiled. */ |
Daniel Stone | e54b2e9 | 2016-05-02 15:34:40 +0100 | [diff] [blame] | 1838 | uint32_t tiling = I915_TILING_X; |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1839 | unsigned long pitch; |
| 1840 | int cpp = format / 8; |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 1841 | intelBuffer->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1842 | "intelAllocateBuffer", |
| 1843 | width, |
| 1844 | height, |
| 1845 | cpp, |
| 1846 | &tiling, &pitch, |
| 1847 | BO_ALLOC_FOR_RENDER); |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 1848 | |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1849 | if (intelBuffer->bo == NULL) { |
Brian Paul | fe72a06 | 2012-09-01 07:47:24 -0600 | [diff] [blame] | 1850 | free(intelBuffer); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1851 | return NULL; |
| 1852 | } |
Kenneth Graunke | a7bdd4c | 2013-11-25 15:46:34 -0800 | [diff] [blame] | 1853 | |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1854 | drm_intel_bo_flink(intelBuffer->bo, &intelBuffer->base.name); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1855 | |
| 1856 | intelBuffer->base.attachment = attachment; |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1857 | intelBuffer->base.cpp = cpp; |
| 1858 | intelBuffer->base.pitch = pitch; |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1859 | |
| 1860 | return &intelBuffer->base; |
| 1861 | } |
| 1862 | |
| 1863 | static void |
Kenneth Graunke | 8fec9fb | 2015-11-30 16:04:08 -0800 | [diff] [blame] | 1864 | intelReleaseBuffer(__DRIscreen *dri_screen, __DRIbuffer *buffer) |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1865 | { |
| 1866 | struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; |
| 1867 | |
Eric Anholt | 3278f96 | 2014-04-25 13:44:41 -0700 | [diff] [blame] | 1868 | drm_intel_bo_unreference(intelBuffer->bo); |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1869 | free(intelBuffer); |
| 1870 | } |
| 1871 | |
Eric Anholt | 1925a9a | 2013-06-26 13:04:51 -0700 | [diff] [blame] | 1872 | static const struct __DriverAPIRec brw_driver_api = { |
George Sapountzis | 7192c37 | 2011-11-03 12:46:08 +0200 | [diff] [blame] | 1873 | .InitScreen = intelInitScreen2, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1874 | .DestroyScreen = intelDestroyScreen, |
Eric Anholt | ee8983b | 2013-09-26 17:08:28 -0700 | [diff] [blame] | 1875 | .CreateContext = brwCreateContext, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1876 | .DestroyContext = intelDestroyContext, |
| 1877 | .CreateBuffer = intelCreateBuffer, |
| 1878 | .DestroyBuffer = intelDestroyBuffer, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1879 | .MakeCurrent = intelMakeCurrent, |
| 1880 | .UnbindContext = intelUnbindContext, |
Benjamin Franzke | 2adfde3 | 2011-02-04 12:01:31 +0100 | [diff] [blame] | 1881 | .AllocateBuffer = intelAllocateBuffer, |
| 1882 | .ReleaseBuffer = intelReleaseBuffer |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1883 | }; |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1884 | |
Eric Anholt | 1925a9a | 2013-06-26 13:04:51 -0700 | [diff] [blame] | 1885 | static const struct __DRIDriverVtableExtensionRec brw_vtable = { |
| 1886 | .base = { __DRI_DRIVER_VTABLE, 1 }, |
| 1887 | .vtable = &brw_driver_api, |
| 1888 | }; |
| 1889 | |
| 1890 | static const __DRIextension *brw_driver_extensions[] = { |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1891 | &driCoreExtension.base, |
Keith Packard | 4424420 | 2013-11-04 18:09:51 -0800 | [diff] [blame] | 1892 | &driImageDriverExtension.base, |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1893 | &driDRI2Extension.base, |
Eric Anholt | 1925a9a | 2013-06-26 13:04:51 -0700 | [diff] [blame] | 1894 | &brw_vtable.base, |
Eric Anholt | 6868923 | 2013-09-27 15:25:40 -0700 | [diff] [blame] | 1895 | &brw_config_options.base, |
Kristian Høgsberg | 39a0e4e | 2010-01-01 17:56:29 -0500 | [diff] [blame] | 1896 | NULL |
| 1897 | }; |
Eric Anholt | 1925a9a | 2013-06-26 13:04:51 -0700 | [diff] [blame] | 1898 | |
| 1899 | PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void) |
| 1900 | { |
| 1901 | globalDriverAPI = &brw_driver_api; |
| 1902 | |
| 1903 | return brw_driver_extensions; |
| 1904 | } |