1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
36 #include "intel_batchbuffer.h"
37 #include "intel_buffers.h"
38 #include "intel_bufmgr.h"
39 #include "intel_chipset.h"
40 #include "intel_extensions.h"
41 #include "intel_fbo.h"
42 #include "intel_regions.h"
43 #include "intel_screen.h"
44 #include "intel_span.h"
45 #include "intel_tex.h"
50 #define DRI_CONF_TEXTURE_TILING(def) \
51 DRI_CONF_OPT_BEGIN(texture_tiling, bool, def) \
52 DRI_CONF_DESC(en, "Enable texture tiling") \
55 PUBLIC const char __driConfigOptions[] =
57 DRI_CONF_SECTION_PERFORMANCE
58 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
59 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
60 * DRI_CONF_BO_REUSE_ALL
62 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
63 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
64 DRI_CONF_ENUM(0, "Disable buffer object reuse")
65 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
70 DRI_CONF_TEXTURE_TILING(false)
72 DRI_CONF_TEXTURE_TILING(true)
75 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
76 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
79 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, false)
80 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
84 DRI_CONF_SECTION_QUALITY
85 DRI_CONF_FORCE_S3TC_ENABLE(false)
86 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
88 DRI_CONF_SECTION_DEBUG
89 DRI_CONF_NO_RAST(false)
90 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
91 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
93 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
94 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
99 const GLuint __driNConfigOptions
= 11;
101 #ifdef USE_NEW_INTERFACE
102 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
103 #endif /*USE_NEW_INTERFACE */
105 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
106 { __DRI_TEX_OFFSET
},
110 static const __DRItexBufferExtension intelTexBufferExtension
= {
111 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
116 static const __DRIextension
*intelScreenExtensions
[] = {
117 &driReadDrawableExtension
,
118 &intelTexOffsetExtension
.base
,
119 &intelTexBufferExtension
.base
,
124 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
127 struct drm_i915_getparam gp
;
132 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
134 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
142 intelDestroyScreen(__DRIscreen
* sPriv
)
144 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
146 dri_bufmgr_destroy(intelScreen
->bufmgr
);
147 driDestroyOptionInfo(&intelScreen
->optionCache
);
150 sPriv
->private = NULL
;
155 * This is called when we need to set up GL rendering to a new X window.
158 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
159 __DRIdrawable
* driDrawPriv
,
160 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
163 return GL_FALSE
; /* not implemented */
166 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
167 mesaVis
->depthBits
!= 24);
170 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
175 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
177 if (mesaVis
->redBits
== 5)
178 rgbFormat
= MESA_FORMAT_RGB565
;
179 else if (mesaVis
->alphaBits
== 0)
180 rgbFormat
= MESA_FORMAT_XRGB8888
;
182 rgbFormat
= MESA_FORMAT_ARGB8888
;
184 /* setup the hardware-based renderbuffers */
185 intel_fb
->color_rb
[0] = intel_create_renderbuffer(rgbFormat
);
186 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
187 &intel_fb
->color_rb
[0]->Base
);
189 if (mesaVis
->doubleBufferMode
) {
190 intel_fb
->color_rb
[1] = intel_create_renderbuffer(rgbFormat
);
192 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
193 &intel_fb
->color_rb
[1]->Base
);
197 if (mesaVis
->depthBits
== 24) {
198 if (mesaVis
->stencilBits
== 8) {
199 /* combined depth/stencil buffer */
200 struct intel_renderbuffer
*depthStencilRb
201 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
202 /* note: bind RB to two attachment points */
203 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
204 &depthStencilRb
->Base
);
205 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
206 &depthStencilRb
->Base
);
208 struct intel_renderbuffer
*depthRb
209 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
210 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
214 else if (mesaVis
->depthBits
== 16) {
215 /* just 16-bit depth buffer, no hw stencil */
216 struct intel_renderbuffer
*depthRb
217 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
218 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
221 /* now add any/all software-based renderbuffers we may need */
222 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
223 GL_FALSE
, /* never sw color */
224 GL_FALSE
, /* never sw depth */
225 swStencil
, mesaVis
->accumRedBits
> 0,
226 GL_FALSE
, /* never sw alpha */
227 GL_FALSE
/* never sw aux */ );
228 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
235 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
237 struct intel_framebuffer
*intel_fb
= driDrawPriv
->driverPrivate
;
238 struct intel_renderbuffer
*depth_rb
;
239 struct intel_renderbuffer
*stencil_rb
;
242 if (intel_fb
->color_rb
[0]) {
243 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
246 if (intel_fb
->color_rb
[1]) {
247 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
250 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
252 intel_renderbuffer_set_region(depth_rb
, NULL
);
255 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
257 intel_renderbuffer_set_region(stencil_rb
, NULL
);
261 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
264 /* There are probably better ways to do this, such as an
265 * init-designated function to register chipids and createcontext
268 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
269 __DRIcontext
* driContextPriv
,
270 void *sharedContextPrivate
);
272 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
273 __DRIcontext
* driContextPriv
,
274 void *sharedContextPrivate
);
275 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
276 __DRIcontext
* driContextPriv
,
277 void *sharedContextPrivate
);
280 intelCreateContext(const __GLcontextModes
* mesaVis
,
281 __DRIcontext
* driContextPriv
,
282 void *sharedContextPrivate
)
284 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
285 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
288 if (IS_9XX(intelScreen
->deviceID
)) {
289 if (!IS_965(intelScreen
->deviceID
)) {
290 return i915CreateContext(mesaVis
, driContextPriv
,
291 sharedContextPrivate
);
294 intelScreen
->no_vbo
= GL_TRUE
;
295 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
298 if (IS_965(intelScreen
->deviceID
))
299 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
301 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
306 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
309 struct drm_i915_getparam gp
;
310 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
313 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
315 gp
.param
= I915_PARAM_HAS_GEM
;
316 gp
.value
= &gem_kernel
;
318 (void) drmCommandWriteRead(spriv
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
320 /* If we've got a new enough DDX that's initializing GEM and giving us
321 * object handles for the shared buffers, use that.
323 if (!intelScreen
->driScrnPriv
->dri2
.enabled
&&
324 intelScreen
->driScrnPriv
->ddx_version
.minor
< 9) {
325 fprintf(stderr
, "[%s:%u] Error initializing GEM.\n",
330 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
331 /* Otherwise, use the classic buffer manager. */
332 if (intelScreen
->bufmgr
== NULL
) {
333 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
338 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
339 intelScreen
->kernel_exec_fencing
= !!num_fences
;
341 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
346 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
349 * This should probably change to have the screen allocate a dummy
350 * context at screen creation. For now just use the current context.
353 GET_CURRENT_CONTEXT(ctx
);
355 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
358 return intel_context(ctx
);
362 * This is the driver specific part of the createNewScreen entry point.
363 * Called when using DRI2.
365 * \return the __GLcontextModes supported by this driver
368 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
370 intelScreenPrivate
*intelScreen
;
373 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
374 * support pageflipping at all.
376 static const GLenum back_buffer_modes
[] = {
377 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
379 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
381 __DRIconfig
**configs
= NULL
;
383 /* Allocate the private area */
384 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
386 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
389 /* parse information in __driConfigOptions */
390 driParseOptionInfo(&intelScreen
->optionCache
,
391 __driConfigOptions
, __driNConfigOptions
);
393 intelScreen
->driScrnPriv
= psp
;
394 psp
->private = (void *) intelScreen
;
396 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
398 /* Determine chipset ID */
399 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
400 &intelScreen
->deviceID
))
403 if (!intel_init_bufmgr(intelScreen
))
406 intelScreen
->irq_active
= 1;
407 psp
->extensions
= intelScreenExtensions
;
418 msaa_samples_array
[0] = 0;
420 fb_format
[0] = GL_RGB
;
421 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
423 fb_format
[1] = GL_BGR
;
424 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
426 fb_format
[2] = GL_BGRA
;
427 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
432 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
433 __DRIconfig
**new_configs
;
436 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
437 * with the same cpp as the drawable. So we can't support depth cpp !=
438 * color cpp currently.
440 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
453 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
458 ARRAY_SIZE(back_buffer_modes
),
460 ARRAY_SIZE(msaa_samples_array
));
462 configs
= new_configs
;
464 configs
= driConcatConfigs(configs
, new_configs
);
467 if (configs
== NULL
) {
468 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
473 return (const __DRIconfig
**)configs
;
476 const struct __DriverAPIRec driDriverAPI
= {
477 .DestroyScreen
= intelDestroyScreen
,
478 .CreateContext
= intelCreateContext
,
479 .DestroyContext
= intelDestroyContext
,
480 .CreateBuffer
= intelCreateBuffer
,
481 .DestroyBuffer
= intelDestroyBuffer
,
482 .MakeCurrent
= intelMakeCurrent
,
483 .UnbindContext
= intelUnbindContext
,
484 .InitScreen2
= intelInitScreen2
,
487 /* This is the table of extensions that the loader will dlsym() for. */
488 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
489 &driCoreExtension
.base
,
490 &driDRI2Extension
.base
,