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"
32 #include "main/hash.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_buffers.h"
39 #include "intel_bufmgr.h"
40 #include "intel_chipset.h"
41 #include "intel_fbo.h"
42 #include "intel_screen.h"
43 #include "intel_tex.h"
47 #define DRI_CONF_TEXTURE_TILING(def) \
48 DRI_CONF_OPT_BEGIN(texture_tiling, bool, def) \
49 DRI_CONF_DESC(en, "Enable texture tiling") \
52 PUBLIC const char __driConfigOptions[] =
54 DRI_CONF_SECTION_PERFORMANCE
55 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
56 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
57 * DRI_CONF_BO_REUSE_ALL
59 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
60 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
61 DRI_CONF_ENUM(0, "Disable buffer object reuse")
62 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
67 DRI_CONF_TEXTURE_TILING(false)
69 DRI_CONF_TEXTURE_TILING(true)
72 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
73 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
76 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, false)
77 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
81 DRI_CONF_SECTION_QUALITY
82 DRI_CONF_FORCE_S3TC_ENABLE(false)
83 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
85 DRI_CONF_SECTION_DEBUG
86 DRI_CONF_NO_RAST(false)
87 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
88 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
90 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
91 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
96 const GLuint __driNConfigOptions
= 11;
98 #ifdef USE_NEW_INTERFACE
99 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
100 #endif /*USE_NEW_INTERFACE */
102 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
103 { __DRI_TEX_OFFSET
},
107 static const __DRItexBufferExtension intelTexBufferExtension
= {
108 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
114 intelDRI2Flush(__DRIdrawable
*drawable
)
116 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
119 INTEL_FIREVERTICES(intel
);
121 if (intel
->batch
->map
!= intel
->batch
->ptr
)
122 intel_batchbuffer_flush(intel
->batch
);
126 intelDRI2FlushInvalidate(__DRIdrawable
*drawable
)
128 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
130 intel
->using_dri2_swapbuffers
= GL_TRUE
;
132 intelDRI2Flush(drawable
);
133 drawable
->validBuffers
= GL_FALSE
;
135 intel_update_renderbuffers(intel
->driContext
, drawable
);
138 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
139 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
141 intelDRI2FlushInvalidate
,
144 static const __DRIextension
*intelScreenExtensions
[] = {
145 &driReadDrawableExtension
,
146 &intelTexOffsetExtension
.base
,
147 &intelTexBufferExtension
.base
,
148 &intelFlushExtension
.base
,
153 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
156 struct drm_i915_getparam gp
;
161 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
163 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
171 nop_callback(GLuint key
, void *data
, void *userData
)
176 intelDestroyScreen(__DRIscreen
* sPriv
)
178 struct intel_screen
*intelScreen
= sPriv
->private;
180 dri_bufmgr_destroy(intelScreen
->bufmgr
);
181 driDestroyOptionInfo(&intelScreen
->optionCache
);
183 /* Some regions may still have references to them at this point, so
184 * flush the hash table to prevent _mesa_DeleteHashTable() from
185 * complaining about the hash not being empty; */
186 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
187 _mesa_DeleteHashTable(intelScreen
->named_regions
);
190 sPriv
->private = NULL
;
195 * This is called when we need to set up GL rendering to a new X window.
198 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
199 __DRIdrawable
* driDrawPriv
,
200 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
202 struct intel_renderbuffer
*rb
;
205 return GL_FALSE
; /* not implemented */
208 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
209 mesaVis
->depthBits
!= 24);
212 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
217 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
219 if (mesaVis
->redBits
== 5)
220 rgbFormat
= MESA_FORMAT_RGB565
;
221 else if (mesaVis
->alphaBits
== 0)
222 rgbFormat
= MESA_FORMAT_XRGB8888
;
224 rgbFormat
= MESA_FORMAT_ARGB8888
;
226 /* setup the hardware-based renderbuffers */
227 rb
= intel_create_renderbuffer(rgbFormat
);
228 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
230 if (mesaVis
->doubleBufferMode
) {
231 rb
= intel_create_renderbuffer(rgbFormat
);
232 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
235 if (mesaVis
->depthBits
== 24) {
236 if (mesaVis
->stencilBits
== 8) {
237 /* combined depth/stencil buffer */
238 struct intel_renderbuffer
*depthStencilRb
239 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
240 /* note: bind RB to two attachment points */
241 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
242 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
244 struct intel_renderbuffer
*depthRb
245 = intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
246 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
249 else if (mesaVis
->depthBits
== 16) {
250 /* just 16-bit depth buffer, no hw stencil */
251 struct intel_renderbuffer
*depthRb
252 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
253 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
256 /* now add any/all software-based renderbuffers we may need */
257 _mesa_add_soft_renderbuffers(fb
,
258 GL_FALSE
, /* never sw color */
259 GL_FALSE
, /* never sw depth */
260 swStencil
, mesaVis
->accumRedBits
> 0,
261 GL_FALSE
, /* never sw alpha */
262 GL_FALSE
/* never sw aux */ );
263 driDrawPriv
->driverPrivate
= fb
;
270 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
272 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
274 _mesa_reference_framebuffer(&fb
, NULL
);
277 /* There are probably better ways to do this, such as an
278 * init-designated function to register chipids and createcontext
281 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
282 __DRIcontext
* driContextPriv
,
283 void *sharedContextPrivate
);
285 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
286 __DRIcontext
* driContextPriv
,
287 void *sharedContextPrivate
);
288 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
289 __DRIcontext
* driContextPriv
,
290 void *sharedContextPrivate
);
293 intelCreateContext(const __GLcontextModes
* mesaVis
,
294 __DRIcontext
* driContextPriv
,
295 void *sharedContextPrivate
)
297 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
298 struct intel_screen
*intelScreen
= sPriv
->private;
301 if (IS_9XX(intelScreen
->deviceID
)) {
302 if (!IS_965(intelScreen
->deviceID
)) {
303 return i915CreateContext(mesaVis
, driContextPriv
,
304 sharedContextPrivate
);
307 intelScreen
->no_vbo
= GL_TRUE
;
308 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
311 if (IS_965(intelScreen
->deviceID
))
312 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
314 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
319 intel_init_bufmgr(struct intel_screen
*intelScreen
)
321 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
324 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
326 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
327 /* Otherwise, use the classic buffer manager. */
328 if (intelScreen
->bufmgr
== NULL
) {
329 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
334 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
335 intelScreen
->kernel_exec_fencing
= !!num_fences
;
337 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
339 intelScreen
->named_regions
= _mesa_NewHashTable();
345 * This is the driver specific part of the createNewScreen entry point.
346 * Called when using DRI2.
348 * \return the __GLcontextModes supported by this driver
351 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
353 struct intel_screen
*intelScreen
;
357 static const GLenum back_buffer_modes
[] = {
358 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
360 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
362 __DRIconfig
**configs
= NULL
;
364 /* Allocate the private area */
365 intelScreen
= CALLOC(sizeof *intelScreen
);
367 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
370 /* parse information in __driConfigOptions */
371 driParseOptionInfo(&intelScreen
->optionCache
,
372 __driConfigOptions
, __driNConfigOptions
);
374 intelScreen
->driScrnPriv
= psp
;
375 psp
->private = (void *) intelScreen
;
377 /* Determine chipset ID */
378 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
379 &intelScreen
->deviceID
))
382 if (!intel_init_bufmgr(intelScreen
))
385 psp
->extensions
= intelScreenExtensions
;
387 msaa_samples_array
[0] = 0;
389 fb_format
[0] = GL_RGB
;
390 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
392 fb_format
[1] = GL_BGR
;
393 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
395 fb_format
[2] = GL_BGRA
;
396 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
401 /* Generate a rich set of useful configs that do not include an
402 * accumulation buffer.
404 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
405 __DRIconfig
**new_configs
;
408 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
409 * buffer that has a diffferent number of bits per pixel than the color
410 * buffer. This isn't yet supported here.
412 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
422 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
427 ARRAY_SIZE(back_buffer_modes
),
429 ARRAY_SIZE(msaa_samples_array
),
432 configs
= new_configs
;
434 configs
= driConcatConfigs(configs
, new_configs
);
437 /* Generate the minimum possible set of configs that include an
438 * accumulation buffer.
440 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
441 __DRIconfig
**new_configs
;
443 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
451 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
452 depth_bits
, stencil_bits
, 1,
453 back_buffer_modes
+ 1, 1,
454 msaa_samples_array
, 1,
457 configs
= new_configs
;
459 configs
= driConcatConfigs(configs
, new_configs
);
462 if (configs
== NULL
) {
463 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
468 return (const __DRIconfig
**)configs
;
471 const struct __DriverAPIRec driDriverAPI
= {
472 .DestroyScreen
= intelDestroyScreen
,
473 .CreateContext
= intelCreateContext
,
474 .DestroyContext
= intelDestroyContext
,
475 .CreateBuffer
= intelCreateBuffer
,
476 .DestroyBuffer
= intelDestroyBuffer
,
477 .MakeCurrent
= intelMakeCurrent
,
478 .UnbindContext
= intelUnbindContext
,
479 .InitScreen2
= intelInitScreen2
,
482 /* This is the table of extensions that the loader will dlsym() for. */
483 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
484 &driCoreExtension
.base
,
485 &driDRI2Extension
.base
,