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
},
117 intelDRI2Flush(__DRIdrawable
*drawable
)
119 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
122 INTEL_FIREVERTICES(intel
);
124 if (intel
->batch
->map
!= intel
->batch
->ptr
)
125 intel_batchbuffer_flush(intel
->batch
);
129 intelDRI2FlushInvalidate(__DRIdrawable
*drawable
)
131 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
133 intelDRI2Flush(drawable
);
134 drawable
->validBuffers
= GL_FALSE
;
136 /* We're using FlushInvalidate as an indicator that a frame is
137 * done. It's only called immediately after SwapBuffers, so it
138 * won't affect front-buffer rendering or applications explicitly
139 * managing swap regions using MESA_copy_buffer.
141 * Wait for the swapbuffers before the one we just emitted, so we don't
142 * get too many swaps outstanding for apps that are GPU-heavy but not
145 * Unfortunately, we don't have a handle to the batch containing the swap,
146 * and getting our hands on that doesn't seem worth it, so we just use the
147 * first batch we emitted after the last swap.
149 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
150 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
151 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
152 intel
->first_post_swapbuffers_batch
= NULL
;
156 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
157 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
159 intelDRI2FlushInvalidate
,
162 static const __DRIextension
*intelScreenExtensions
[] = {
163 &driReadDrawableExtension
,
164 &intelTexOffsetExtension
.base
,
165 &intelTexBufferExtension
.base
,
166 &intelFlushExtension
.base
,
171 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
174 struct drm_i915_getparam gp
;
179 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
181 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
189 intelDestroyScreen(__DRIscreen
* sPriv
)
191 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
193 dri_bufmgr_destroy(intelScreen
->bufmgr
);
194 driDestroyOptionInfo(&intelScreen
->optionCache
);
197 sPriv
->private = NULL
;
202 * This is called when we need to set up GL rendering to a new X window.
205 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
206 __DRIdrawable
* driDrawPriv
,
207 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
209 struct intel_renderbuffer
*rb
;
212 return GL_FALSE
; /* not implemented */
215 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
216 mesaVis
->depthBits
!= 24);
219 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
224 _mesa_initialize_framebuffer(fb
, mesaVis
);
226 if (mesaVis
->redBits
== 5)
227 rgbFormat
= MESA_FORMAT_RGB565
;
228 else if (mesaVis
->alphaBits
== 0)
229 rgbFormat
= MESA_FORMAT_XRGB8888
;
231 rgbFormat
= MESA_FORMAT_ARGB8888
;
233 /* setup the hardware-based renderbuffers */
234 rb
= intel_create_renderbuffer(rgbFormat
);
235 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
237 if (mesaVis
->doubleBufferMode
) {
238 rb
= intel_create_renderbuffer(rgbFormat
);
239 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
242 if (mesaVis
->depthBits
== 24) {
243 if (mesaVis
->stencilBits
== 8) {
244 /* combined depth/stencil buffer */
245 struct intel_renderbuffer
*depthStencilRb
246 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
247 /* note: bind RB to two attachment points */
248 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
249 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
251 struct intel_renderbuffer
*depthRb
252 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
253 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
256 else if (mesaVis
->depthBits
== 16) {
257 /* just 16-bit depth buffer, no hw stencil */
258 struct intel_renderbuffer
*depthRb
259 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
260 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
263 /* now add any/all software-based renderbuffers we may need */
264 _mesa_add_soft_renderbuffers(fb
,
265 GL_FALSE
, /* never sw color */
266 GL_FALSE
, /* never sw depth */
267 swStencil
, mesaVis
->accumRedBits
> 0,
268 GL_FALSE
, /* never sw alpha */
269 GL_FALSE
/* never sw aux */ );
270 driDrawPriv
->driverPrivate
= fb
;
277 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
279 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
281 _mesa_reference_framebuffer(&fb
, NULL
);
284 /* There are probably better ways to do this, such as an
285 * init-designated function to register chipids and createcontext
288 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
289 __DRIcontext
* driContextPriv
,
290 void *sharedContextPrivate
);
292 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
293 __DRIcontext
* driContextPriv
,
294 void *sharedContextPrivate
);
295 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
296 __DRIcontext
* driContextPriv
,
297 void *sharedContextPrivate
);
300 intelCreateContext(const __GLcontextModes
* mesaVis
,
301 __DRIcontext
* driContextPriv
,
302 void *sharedContextPrivate
)
304 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
305 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
308 if (IS_9XX(intelScreen
->deviceID
)) {
309 if (!IS_965(intelScreen
->deviceID
)) {
310 return i915CreateContext(mesaVis
, driContextPriv
,
311 sharedContextPrivate
);
314 intelScreen
->no_vbo
= GL_TRUE
;
315 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
318 if (IS_965(intelScreen
->deviceID
))
319 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
321 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
326 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
328 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
331 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
333 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
334 /* Otherwise, use the classic buffer manager. */
335 if (intelScreen
->bufmgr
== NULL
) {
336 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
341 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
342 intelScreen
->kernel_exec_fencing
= !!num_fences
;
344 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
350 * This is the driver specific part of the createNewScreen entry point.
351 * Called when using DRI2.
353 * \return the __GLcontextModes supported by this driver
356 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
358 intelScreenPrivate
*intelScreen
;
362 static const GLenum back_buffer_modes
[] = {
363 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
,
364 GLX_SWAP_EXCHANGE_OML
, GLX_SWAP_COPY_OML
366 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
368 __DRIconfig
**configs
= NULL
;
370 /* Allocate the private area */
371 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
373 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
376 /* parse information in __driConfigOptions */
377 driParseOptionInfo(&intelScreen
->optionCache
,
378 __driConfigOptions
, __driNConfigOptions
);
380 intelScreen
->driScrnPriv
= psp
;
381 psp
->private = (void *) intelScreen
;
383 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
385 /* Determine chipset ID */
386 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
387 &intelScreen
->deviceID
))
390 if (!intel_init_bufmgr(intelScreen
))
393 intelScreen
->irq_active
= 1;
394 psp
->extensions
= intelScreenExtensions
;
405 msaa_samples_array
[0] = 0;
407 fb_format
[0] = GL_RGB
;
408 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
410 fb_format
[1] = GL_BGR
;
411 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
413 fb_format
[2] = GL_BGRA
;
414 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
419 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
420 __DRIconfig
**new_configs
;
423 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
424 * with the same cpp as the drawable. So we can't support depth cpp !=
425 * color cpp currently.
427 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
440 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
445 ARRAY_SIZE(back_buffer_modes
),
447 ARRAY_SIZE(msaa_samples_array
));
449 configs
= new_configs
;
451 configs
= driConcatConfigs(configs
, new_configs
);
454 if (configs
== NULL
) {
455 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
460 return (const __DRIconfig
**)configs
;
463 const struct __DriverAPIRec driDriverAPI
= {
464 .DestroyScreen
= intelDestroyScreen
,
465 .CreateContext
= intelCreateContext
,
466 .DestroyContext
= intelDestroyContext
,
467 .CreateBuffer
= intelCreateBuffer
,
468 .DestroyBuffer
= intelDestroyBuffer
,
469 .MakeCurrent
= intelMakeCurrent
,
470 .UnbindContext
= intelUnbindContext
,
471 .InitScreen2
= intelInitScreen2
,
474 /* This is the table of extensions that the loader will dlsym() for. */
475 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
476 &driCoreExtension
.base
,
477 &driDRI2Extension
.base
,