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 intelDRI2Flush(drawable
);
132 drawable
->validBuffers
= GL_FALSE
;
135 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
136 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
138 intelDRI2FlushInvalidate
,
141 static const __DRIextension
*intelScreenExtensions
[] = {
142 &driReadDrawableExtension
,
143 &intelTexOffsetExtension
.base
,
144 &intelTexBufferExtension
.base
,
145 &intelFlushExtension
.base
,
150 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
153 struct drm_i915_getparam gp
;
158 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
160 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
168 intelDestroyScreen(__DRIscreen
* sPriv
)
170 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
172 dri_bufmgr_destroy(intelScreen
->bufmgr
);
173 driDestroyOptionInfo(&intelScreen
->optionCache
);
176 sPriv
->private = NULL
;
181 * This is called when we need to set up GL rendering to a new X window.
184 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
185 __DRIdrawable
* driDrawPriv
,
186 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
188 struct intel_renderbuffer
*rb
;
191 return GL_FALSE
; /* not implemented */
194 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
195 mesaVis
->depthBits
!= 24);
198 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
203 _mesa_initialize_framebuffer(fb
, mesaVis
);
205 if (mesaVis
->redBits
== 5)
206 rgbFormat
= MESA_FORMAT_RGB565
;
207 else if (mesaVis
->alphaBits
== 0)
208 rgbFormat
= MESA_FORMAT_XRGB8888
;
210 rgbFormat
= MESA_FORMAT_ARGB8888
;
212 /* setup the hardware-based renderbuffers */
213 rb
= intel_create_renderbuffer(rgbFormat
);
214 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
216 if (mesaVis
->doubleBufferMode
) {
217 rb
= intel_create_renderbuffer(rgbFormat
);
218 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
221 if (mesaVis
->depthBits
== 24) {
222 if (mesaVis
->stencilBits
== 8) {
223 /* combined depth/stencil buffer */
224 struct intel_renderbuffer
*depthStencilRb
225 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
226 /* note: bind RB to two attachment points */
227 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
228 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
230 struct intel_renderbuffer
*depthRb
231 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
232 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
235 else if (mesaVis
->depthBits
== 16) {
236 /* just 16-bit depth buffer, no hw stencil */
237 struct intel_renderbuffer
*depthRb
238 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
239 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
242 /* now add any/all software-based renderbuffers we may need */
243 _mesa_add_soft_renderbuffers(fb
,
244 GL_FALSE
, /* never sw color */
245 GL_FALSE
, /* never sw depth */
246 swStencil
, mesaVis
->accumRedBits
> 0,
247 GL_FALSE
, /* never sw alpha */
248 GL_FALSE
/* never sw aux */ );
249 driDrawPriv
->driverPrivate
= fb
;
256 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
258 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
260 _mesa_reference_framebuffer(&fb
, NULL
);
263 /* There are probably better ways to do this, such as an
264 * init-designated function to register chipids and createcontext
267 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
268 __DRIcontext
* driContextPriv
,
269 void *sharedContextPrivate
);
271 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
272 __DRIcontext
* driContextPriv
,
273 void *sharedContextPrivate
);
274 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
275 __DRIcontext
* driContextPriv
,
276 void *sharedContextPrivate
);
279 intelCreateContext(const __GLcontextModes
* mesaVis
,
280 __DRIcontext
* driContextPriv
,
281 void *sharedContextPrivate
)
283 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
284 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
287 if (IS_9XX(intelScreen
->deviceID
)) {
288 if (!IS_965(intelScreen
->deviceID
)) {
289 return i915CreateContext(mesaVis
, driContextPriv
,
290 sharedContextPrivate
);
293 intelScreen
->no_vbo
= GL_TRUE
;
294 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
297 if (IS_965(intelScreen
->deviceID
))
298 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
300 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
305 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
307 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
310 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
312 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
313 /* Otherwise, use the classic buffer manager. */
314 if (intelScreen
->bufmgr
== NULL
) {
315 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
320 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
321 intelScreen
->kernel_exec_fencing
= !!num_fences
;
323 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
329 * This is the driver specific part of the createNewScreen entry point.
330 * Called when using DRI2.
332 * \return the __GLcontextModes supported by this driver
335 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
337 intelScreenPrivate
*intelScreen
;
341 static const GLenum back_buffer_modes
[] = {
342 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
,
343 GLX_SWAP_EXCHANGE_OML
, GLX_SWAP_COPY_OML
345 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
347 __DRIconfig
**configs
= NULL
;
349 /* Allocate the private area */
350 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
352 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
355 /* parse information in __driConfigOptions */
356 driParseOptionInfo(&intelScreen
->optionCache
,
357 __driConfigOptions
, __driNConfigOptions
);
359 intelScreen
->driScrnPriv
= psp
;
360 psp
->private = (void *) intelScreen
;
362 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
364 /* Determine chipset ID */
365 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
366 &intelScreen
->deviceID
))
369 if (!intel_init_bufmgr(intelScreen
))
372 intelScreen
->irq_active
= 1;
373 psp
->extensions
= intelScreenExtensions
;
384 msaa_samples_array
[0] = 0;
386 fb_format
[0] = GL_RGB
;
387 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
389 fb_format
[1] = GL_BGR
;
390 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
392 fb_format
[2] = GL_BGRA
;
393 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
398 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
399 __DRIconfig
**new_configs
;
402 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
403 * with the same cpp as the drawable. So we can't support depth cpp !=
404 * color cpp currently.
406 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
419 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
424 ARRAY_SIZE(back_buffer_modes
),
426 ARRAY_SIZE(msaa_samples_array
));
428 configs
= new_configs
;
430 configs
= driConcatConfigs(configs
, new_configs
);
433 if (configs
== NULL
) {
434 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
439 return (const __DRIconfig
**)configs
;
442 const struct __DriverAPIRec driDriverAPI
= {
443 .DestroyScreen
= intelDestroyScreen
,
444 .CreateContext
= intelCreateContext
,
445 .DestroyContext
= intelDestroyContext
,
446 .CreateBuffer
= intelCreateBuffer
,
447 .DestroyBuffer
= intelDestroyBuffer
,
448 .MakeCurrent
= intelMakeCurrent
,
449 .UnbindContext
= intelUnbindContext
,
450 .InitScreen2
= intelInitScreen2
,
453 /* This is the table of extensions that the loader will dlsym() for. */
454 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
455 &driCoreExtension
.base
,
456 &driDRI2Extension
.base
,