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_fbo.h"
41 #include "intel_regions.h"
42 #include "intel_screen.h"
43 #include "intel_tex.h"
48 #define DRI_CONF_TEXTURE_TILING(def) \
49 DRI_CONF_OPT_BEGIN(texture_tiling, bool, def) \
50 DRI_CONF_DESC(en, "Enable texture tiling") \
53 PUBLIC const char __driConfigOptions[] =
55 DRI_CONF_SECTION_PERFORMANCE
56 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
57 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
58 * DRI_CONF_BO_REUSE_ALL
60 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
61 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
62 DRI_CONF_ENUM(0, "Disable buffer object reuse")
63 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
68 DRI_CONF_TEXTURE_TILING(false)
70 DRI_CONF_TEXTURE_TILING(true)
73 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
74 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
77 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, false)
78 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
82 DRI_CONF_SECTION_QUALITY
83 DRI_CONF_FORCE_S3TC_ENABLE(false)
84 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
86 DRI_CONF_SECTION_DEBUG
87 DRI_CONF_NO_RAST(false)
88 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
89 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
91 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
92 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
97 const GLuint __driNConfigOptions
= 11;
99 #ifdef USE_NEW_INTERFACE
100 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
101 #endif /*USE_NEW_INTERFACE */
103 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
104 { __DRI_TEX_OFFSET
},
108 static const __DRItexBufferExtension intelTexBufferExtension
= {
109 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
115 intelDRI2Flush(__DRIdrawable
*drawable
)
117 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
120 INTEL_FIREVERTICES(intel
);
122 if (intel
->batch
->map
!= intel
->batch
->ptr
)
123 intel_batchbuffer_flush(intel
->batch
);
127 intelDRI2FlushInvalidate(__DRIdrawable
*drawable
)
129 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
131 intel
->using_dri2_swapbuffers
= GL_TRUE
;
133 intelDRI2Flush(drawable
);
134 drawable
->validBuffers
= GL_FALSE
;
136 intel_update_renderbuffers(intel
->driContext
, drawable
);
139 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
140 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
142 intelDRI2FlushInvalidate
,
145 static const __DRIextension
*intelScreenExtensions
[] = {
146 &driReadDrawableExtension
,
147 &intelTexOffsetExtension
.base
,
148 &intelTexBufferExtension
.base
,
149 &intelFlushExtension
.base
,
154 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
157 struct drm_i915_getparam gp
;
162 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
164 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
172 intelDestroyScreen(__DRIscreen
* sPriv
)
174 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
176 dri_bufmgr_destroy(intelScreen
->bufmgr
);
177 driDestroyOptionInfo(&intelScreen
->optionCache
);
180 sPriv
->private = NULL
;
185 * This is called when we need to set up GL rendering to a new X window.
188 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
189 __DRIdrawable
* driDrawPriv
,
190 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
192 struct intel_renderbuffer
*rb
;
195 return GL_FALSE
; /* not implemented */
198 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
199 mesaVis
->depthBits
!= 24);
202 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
207 _mesa_initialize_framebuffer(fb
, mesaVis
);
209 if (mesaVis
->redBits
== 5)
210 rgbFormat
= MESA_FORMAT_RGB565
;
211 else if (mesaVis
->alphaBits
== 0)
212 rgbFormat
= MESA_FORMAT_XRGB8888
;
214 rgbFormat
= MESA_FORMAT_ARGB8888
;
216 /* setup the hardware-based renderbuffers */
217 rb
= intel_create_renderbuffer(rgbFormat
);
218 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
220 if (mesaVis
->doubleBufferMode
) {
221 rb
= intel_create_renderbuffer(rgbFormat
);
222 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
225 if (mesaVis
->depthBits
== 24) {
226 if (mesaVis
->stencilBits
== 8) {
227 /* combined depth/stencil buffer */
228 struct intel_renderbuffer
*depthStencilRb
229 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
230 /* note: bind RB to two attachment points */
231 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
232 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
234 struct intel_renderbuffer
*depthRb
235 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
236 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
239 else if (mesaVis
->depthBits
== 16) {
240 /* just 16-bit depth buffer, no hw stencil */
241 struct intel_renderbuffer
*depthRb
242 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
243 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
246 /* now add any/all software-based renderbuffers we may need */
247 _mesa_add_soft_renderbuffers(fb
,
248 GL_FALSE
, /* never sw color */
249 GL_FALSE
, /* never sw depth */
250 swStencil
, mesaVis
->accumRedBits
> 0,
251 GL_FALSE
, /* never sw alpha */
252 GL_FALSE
/* never sw aux */ );
253 driDrawPriv
->driverPrivate
= fb
;
260 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
262 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
264 _mesa_reference_framebuffer(&fb
, NULL
);
267 /* There are probably better ways to do this, such as an
268 * init-designated function to register chipids and createcontext
271 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
272 __DRIcontext
* driContextPriv
,
273 void *sharedContextPrivate
);
275 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
276 __DRIcontext
* driContextPriv
,
277 void *sharedContextPrivate
);
278 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
279 __DRIcontext
* driContextPriv
,
280 void *sharedContextPrivate
);
283 intelCreateContext(const __GLcontextModes
* mesaVis
,
284 __DRIcontext
* driContextPriv
,
285 void *sharedContextPrivate
)
287 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
288 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
291 if (IS_9XX(intelScreen
->deviceID
)) {
292 if (!IS_965(intelScreen
->deviceID
)) {
293 return i915CreateContext(mesaVis
, driContextPriv
,
294 sharedContextPrivate
);
297 intelScreen
->no_vbo
= GL_TRUE
;
298 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
301 if (IS_965(intelScreen
->deviceID
))
302 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
304 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
309 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
311 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
314 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
316 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
317 /* Otherwise, use the classic buffer manager. */
318 if (intelScreen
->bufmgr
== NULL
) {
319 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
324 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
325 intelScreen
->kernel_exec_fencing
= !!num_fences
;
327 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
333 * This is the driver specific part of the createNewScreen entry point.
334 * Called when using DRI2.
336 * \return the __GLcontextModes supported by this driver
339 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
341 intelScreenPrivate
*intelScreen
;
345 static const GLenum back_buffer_modes
[] = {
346 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
,
347 GLX_SWAP_EXCHANGE_OML
, GLX_SWAP_COPY_OML
349 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
351 __DRIconfig
**configs
= NULL
;
353 /* Allocate the private area */
354 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
356 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
359 /* parse information in __driConfigOptions */
360 driParseOptionInfo(&intelScreen
->optionCache
,
361 __driConfigOptions
, __driNConfigOptions
);
363 intelScreen
->driScrnPriv
= psp
;
364 psp
->private = (void *) intelScreen
;
366 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
368 /* Determine chipset ID */
369 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
370 &intelScreen
->deviceID
))
373 if (!intel_init_bufmgr(intelScreen
))
376 intelScreen
->irq_active
= 1;
377 psp
->extensions
= intelScreenExtensions
;
388 msaa_samples_array
[0] = 0;
390 fb_format
[0] = GL_RGB
;
391 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
393 fb_format
[1] = GL_BGR
;
394 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
396 fb_format
[2] = GL_BGRA
;
397 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
402 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
403 __DRIconfig
**new_configs
;
406 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
407 * with the same cpp as the drawable. So we can't support depth cpp !=
408 * color cpp currently.
410 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
423 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
428 ARRAY_SIZE(back_buffer_modes
),
430 ARRAY_SIZE(msaa_samples_array
));
432 configs
= new_configs
;
434 configs
= driConcatConfigs(configs
, new_configs
);
437 if (configs
== NULL
) {
438 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
443 return (const __DRIconfig
**)configs
;
446 const struct __DriverAPIRec driDriverAPI
= {
447 .DestroyScreen
= intelDestroyScreen
,
448 .CreateContext
= intelCreateContext
,
449 .DestroyContext
= intelDestroyContext
,
450 .CreateBuffer
= intelCreateBuffer
,
451 .DestroyBuffer
= intelDestroyBuffer
,
452 .MakeCurrent
= intelMakeCurrent
,
453 .UnbindContext
= intelUnbindContext
,
454 .InitScreen2
= intelInitScreen2
,
457 /* This is the table of extensions that the loader will dlsym() for. */
458 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
459 &driCoreExtension
.base
,
460 &driDRI2Extension
.base
,