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
)
162 struct intel_renderbuffer
*rb
;
165 return GL_FALSE
; /* not implemented */
168 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
169 mesaVis
->depthBits
!= 24);
172 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
177 _mesa_initialize_framebuffer(fb
, mesaVis
);
179 if (mesaVis
->redBits
== 5)
180 rgbFormat
= MESA_FORMAT_RGB565
;
181 else if (mesaVis
->alphaBits
== 0)
182 rgbFormat
= MESA_FORMAT_XRGB8888
;
184 rgbFormat
= MESA_FORMAT_ARGB8888
;
186 /* setup the hardware-based renderbuffers */
187 rb
= intel_create_renderbuffer(rgbFormat
);
188 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
190 if (mesaVis
->doubleBufferMode
) {
191 rb
= intel_create_renderbuffer(rgbFormat
);
192 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
195 if (mesaVis
->depthBits
== 24) {
196 if (mesaVis
->stencilBits
== 8) {
197 /* combined depth/stencil buffer */
198 struct intel_renderbuffer
*depthStencilRb
199 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
200 /* note: bind RB to two attachment points */
201 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
202 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
204 struct intel_renderbuffer
*depthRb
205 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
206 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
209 else if (mesaVis
->depthBits
== 16) {
210 /* just 16-bit depth buffer, no hw stencil */
211 struct intel_renderbuffer
*depthRb
212 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
213 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
216 /* now add any/all software-based renderbuffers we may need */
217 _mesa_add_soft_renderbuffers(fb
,
218 GL_FALSE
, /* never sw color */
219 GL_FALSE
, /* never sw depth */
220 swStencil
, mesaVis
->accumRedBits
> 0,
221 GL_FALSE
, /* never sw alpha */
222 GL_FALSE
/* never sw aux */ );
223 driDrawPriv
->driverPrivate
= fb
;
230 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
232 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
234 _mesa_reference_framebuffer(&fb
, NULL
);
237 /* There are probably better ways to do this, such as an
238 * init-designated function to register chipids and createcontext
241 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
242 __DRIcontext
* driContextPriv
,
243 void *sharedContextPrivate
);
245 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
246 __DRIcontext
* driContextPriv
,
247 void *sharedContextPrivate
);
248 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
249 __DRIcontext
* driContextPriv
,
250 void *sharedContextPrivate
);
253 intelCreateContext(const __GLcontextModes
* mesaVis
,
254 __DRIcontext
* driContextPriv
,
255 void *sharedContextPrivate
)
257 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
258 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
261 if (IS_9XX(intelScreen
->deviceID
)) {
262 if (!IS_965(intelScreen
->deviceID
)) {
263 return i915CreateContext(mesaVis
, driContextPriv
,
264 sharedContextPrivate
);
267 intelScreen
->no_vbo
= GL_TRUE
;
268 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
271 if (IS_965(intelScreen
->deviceID
))
272 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
274 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
279 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
281 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
284 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
286 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
287 /* Otherwise, use the classic buffer manager. */
288 if (intelScreen
->bufmgr
== NULL
) {
289 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
294 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
295 intelScreen
->kernel_exec_fencing
= !!num_fences
;
297 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
303 * This is the driver specific part of the createNewScreen entry point.
304 * Called when using DRI2.
306 * \return the __GLcontextModes supported by this driver
309 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
311 intelScreenPrivate
*intelScreen
;
314 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
315 * support pageflipping at all.
317 static const GLenum back_buffer_modes
[] = {
318 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
320 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
322 __DRIconfig
**configs
= NULL
;
324 /* Allocate the private area */
325 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
327 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
330 /* parse information in __driConfigOptions */
331 driParseOptionInfo(&intelScreen
->optionCache
,
332 __driConfigOptions
, __driNConfigOptions
);
334 intelScreen
->driScrnPriv
= psp
;
335 psp
->private = (void *) intelScreen
;
337 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
339 /* Determine chipset ID */
340 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
341 &intelScreen
->deviceID
))
344 if (!intel_init_bufmgr(intelScreen
))
347 intelScreen
->irq_active
= 1;
348 psp
->extensions
= intelScreenExtensions
;
359 msaa_samples_array
[0] = 0;
361 fb_format
[0] = GL_RGB
;
362 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
364 fb_format
[1] = GL_BGR
;
365 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
367 fb_format
[2] = GL_BGRA
;
368 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
373 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
374 __DRIconfig
**new_configs
;
377 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
378 * with the same cpp as the drawable. So we can't support depth cpp !=
379 * color cpp currently.
381 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
394 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
399 ARRAY_SIZE(back_buffer_modes
),
401 ARRAY_SIZE(msaa_samples_array
));
403 configs
= new_configs
;
405 configs
= driConcatConfigs(configs
, new_configs
);
408 if (configs
== NULL
) {
409 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
414 return (const __DRIconfig
**)configs
;
417 const struct __DriverAPIRec driDriverAPI
= {
418 .DestroyScreen
= intelDestroyScreen
,
419 .CreateContext
= intelCreateContext
,
420 .DestroyContext
= intelDestroyContext
,
421 .CreateBuffer
= intelCreateBuffer
,
422 .DestroyBuffer
= intelDestroyBuffer
,
423 .MakeCurrent
= intelMakeCurrent
,
424 .UnbindContext
= intelUnbindContext
,
425 .InitScreen2
= intelInitScreen2
,
428 /* This is the table of extensions that the loader will dlsym() for. */
429 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
430 &driCoreExtension
.base
,
431 &driDRI2Extension
.base
,