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 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/extensions.h"
32 #include "main/fbobject.h"
33 #include "main/framebuffer.h"
34 #include "main/imports.h"
35 #include "main/points.h"
36 #include "main/renderbuffer.h"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
41 #include "drivers/common/driverfuncs.h"
42 #include "drivers/common/meta.h"
44 #include "intel_chipset.h"
45 #include "intel_buffers.h"
46 #include "intel_tex.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_clear.h"
49 #include "intel_extensions.h"
50 #include "intel_pixel.h"
51 #include "intel_regions.h"
52 #include "intel_buffer_objects.h"
53 #include "intel_fbo.h"
54 #include "intel_bufmgr.h"
55 #include "intel_screen.h"
58 #include "../glsl/ralloc.h"
61 int INTEL_DEBUG
= (0);
65 static const GLubyte
*
66 intelGetString(struct gl_context
* ctx
, GLenum name
)
68 const struct intel_context
*const intel
= intel_context(ctx
);
70 static char buffer
[128];
74 return (GLubyte
*) "Tungsten Graphics, Inc";
78 switch (intel
->intelScreen
->deviceID
) {
80 chipset
= "Intel(R) 845G";
83 chipset
= "Intel(R) 830M";
85 case PCI_CHIP_I855_GM
:
86 chipset
= "Intel(R) 852GM/855GM";
89 chipset
= "Intel(R) 865G";
92 chipset
= "Intel(R) 915G";
94 case PCI_CHIP_E7221_G
:
95 chipset
= "Intel (R) E7221G (i915)";
97 case PCI_CHIP_I915_GM
:
98 chipset
= "Intel(R) 915GM";
100 case PCI_CHIP_I945_G
:
101 chipset
= "Intel(R) 945G";
103 case PCI_CHIP_I945_GM
:
104 chipset
= "Intel(R) 945GM";
106 case PCI_CHIP_I945_GME
:
107 chipset
= "Intel(R) 945GME";
110 chipset
= "Intel(R) G33";
113 chipset
= "Intel(R) Q35";
116 chipset
= "Intel(R) Q33";
118 case PCI_CHIP_IGD_GM
:
120 chipset
= "Intel(R) IGD";
122 case PCI_CHIP_I965_Q
:
123 chipset
= "Intel(R) 965Q";
125 case PCI_CHIP_I965_G
:
126 case PCI_CHIP_I965_G_1
:
127 chipset
= "Intel(R) 965G";
129 case PCI_CHIP_I946_GZ
:
130 chipset
= "Intel(R) 946GZ";
132 case PCI_CHIP_I965_GM
:
133 chipset
= "Intel(R) 965GM";
135 case PCI_CHIP_I965_GME
:
136 chipset
= "Intel(R) 965GME/GLE";
138 case PCI_CHIP_GM45_GM
:
139 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
141 case PCI_CHIP_IGD_E_G
:
142 chipset
= "Intel(R) Integrated Graphics Device";
145 chipset
= "Intel(R) G45/G43";
148 chipset
= "Intel(R) Q45/Q43";
151 chipset
= "Intel(R) G41";
154 case PCI_CHIP_B43_G1
:
155 chipset
= "Intel(R) B43";
158 chipset
= "Intel(R) Ironlake Desktop";
161 chipset
= "Intel(R) Ironlake Mobile";
163 case PCI_CHIP_SANDYBRIDGE_GT1
:
164 case PCI_CHIP_SANDYBRIDGE_GT2
:
165 case PCI_CHIP_SANDYBRIDGE_GT2_PLUS
:
166 chipset
= "Intel(R) Sandybridge Desktop";
168 case PCI_CHIP_SANDYBRIDGE_M_GT1
:
169 case PCI_CHIP_SANDYBRIDGE_M_GT2
:
170 case PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS
:
171 chipset
= "Intel(R) Sandybridge Mobile";
173 case PCI_CHIP_SANDYBRIDGE_S
:
174 chipset
= "Intel(R) Sandybridge Server";
176 case PCI_CHIP_IVYBRIDGE_GT1
:
177 case PCI_CHIP_IVYBRIDGE_GT2
:
178 chipset
= "Intel(R) Ivybridge Desktop";
180 case PCI_CHIP_IVYBRIDGE_M_GT1
:
181 case PCI_CHIP_IVYBRIDGE_M_GT2
:
182 chipset
= "Intel(R) Ivybridge Mobile";
184 case PCI_CHIP_IVYBRIDGE_S_GT1
:
185 chipset
= "Intel(R) Ivybridge Server";
188 chipset
= "Unknown Intel Chipset";
192 (void) driGetRendererString(buffer
, chipset
, 0);
193 return (GLubyte
*) buffer
;
201 intel_flush_front(struct gl_context
*ctx
)
203 struct intel_context
*intel
= intel_context(ctx
);
204 __DRIcontext
*driContext
= intel
->driContext
;
205 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
207 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
208 if (screen
->dri2
.loader
&&
209 (screen
->dri2
.loader
->base
.version
>= 2)
210 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
211 driContext
->driDrawablePriv
&&
212 driContext
->driDrawablePriv
->loaderPrivate
) {
213 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
214 driContext
->driDrawablePriv
->loaderPrivate
);
216 /* We set the dirty bit in intel_prepare_render() if we're
217 * front buffer rendering once we get there.
219 intel
->front_buffer_dirty
= false;
225 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
227 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
231 intel_query_dri2_buffers_no_separate_stencil(struct intel_context
*intel
,
232 __DRIdrawable
*drawable
,
233 __DRIbuffer
**buffers
,
237 intel_process_dri2_buffer_no_separate_stencil(struct intel_context
*intel
,
238 __DRIdrawable
*drawable
,
240 struct intel_renderbuffer
*rb
,
241 const char *buffer_name
);
244 intel_query_dri2_buffers_with_separate_stencil(struct intel_context
*intel
,
245 __DRIdrawable
*drawable
,
246 __DRIbuffer
**buffers
,
247 unsigned **attachments
,
251 intel_process_dri2_buffer_with_separate_stencil(struct intel_context
*intel
,
252 __DRIdrawable
*drawable
,
254 struct intel_renderbuffer
*rb
,
255 const char *buffer_name
);
257 intel_verify_dri2_has_hiz(struct intel_context
*intel
,
258 __DRIdrawable
*drawable
,
259 __DRIbuffer
**buffers
,
260 unsigned **attachments
,
264 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
266 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
267 struct intel_renderbuffer
*rb
;
268 struct intel_context
*intel
= context
->driverPrivate
;
269 __DRIbuffer
*buffers
= NULL
;
270 unsigned *attachments
= NULL
;
272 const char *region_name
;
274 bool try_separate_stencil
=
275 intel
->has_separate_stencil
&&
276 intel
->intelScreen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
&&
277 intel
->intelScreen
->driScrnPriv
->dri2
.loader
!= NULL
&&
278 intel
->intelScreen
->driScrnPriv
->dri2
.loader
->base
.version
> 2 &&
279 intel
->intelScreen
->driScrnPriv
->dri2
.loader
->getBuffersWithFormat
!= NULL
;
281 assert(!intel
->must_use_separate_stencil
|| try_separate_stencil
);
283 /* If we're rendering to the fake front buffer, make sure all the
284 * pending drawing has landed on the real front buffer. Otherwise
285 * when we eventually get to DRI2GetBuffersWithFormat the stale
286 * real front buffer contents will get copied to the new fake front
289 if (intel
->is_front_buffer_rendering
) {
290 intel_flush(&intel
->ctx
);
291 intel_flush_front(&intel
->ctx
);
294 /* Set this up front, so that in case our buffers get invalidated
295 * while we're getting new buffers, we don't clobber the stamp and
296 * thus ignore the invalidate. */
297 drawable
->lastStamp
= drawable
->dri2
.stamp
;
299 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
300 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
302 if (try_separate_stencil
) {
303 intel_query_dri2_buffers_with_separate_stencil(intel
, drawable
, &buffers
,
304 &attachments
, &count
);
306 intel_query_dri2_buffers_no_separate_stencil(intel
, drawable
, &buffers
,
313 for (i
= 0; i
< count
; i
++) {
314 switch (buffers
[i
].attachment
) {
315 case __DRI_BUFFER_FRONT_LEFT
:
316 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
317 region_name
= "dri2 front buffer";
320 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
321 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
322 region_name
= "dri2 fake front buffer";
325 case __DRI_BUFFER_BACK_LEFT
:
326 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
327 region_name
= "dri2 back buffer";
330 case __DRI_BUFFER_DEPTH
:
331 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
332 region_name
= "dri2 depth buffer";
335 case __DRI_BUFFER_HIZ
:
336 /* The hiz region resides in the depth renderbuffer. */
337 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
338 region_name
= "dri2 hiz buffer";
341 case __DRI_BUFFER_DEPTH_STENCIL
:
342 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
343 region_name
= "dri2 depth / stencil buffer";
346 case __DRI_BUFFER_STENCIL
:
347 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
348 region_name
= "dri2 stencil buffer";
351 case __DRI_BUFFER_ACCUM
:
354 "unhandled buffer attach event, attachment type %d\n",
355 buffers
[i
].attachment
);
359 if (try_separate_stencil
) {
360 intel_process_dri2_buffer_with_separate_stencil(intel
, drawable
,
364 intel_process_dri2_buffer_no_separate_stencil(intel
, drawable
,
370 if (try_separate_stencil
371 && intel
->intelScreen
->dri2_has_hiz
== INTEL_DRI2_HAS_HIZ_UNKNOWN
) {
372 intel_verify_dri2_has_hiz(intel
, drawable
, &buffers
, &attachments
,
379 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
383 * intel_prepare_render should be called anywhere that curent read/drawbuffer
387 intel_prepare_render(struct intel_context
*intel
)
389 __DRIcontext
*driContext
= intel
->driContext
;
390 __DRIdrawable
*drawable
;
392 drawable
= driContext
->driDrawablePriv
;
393 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
394 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
395 intel_update_renderbuffers(driContext
, drawable
);
396 intel_draw_buffer(&intel
->ctx
);
397 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
400 drawable
= driContext
->driReadablePriv
;
401 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
402 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
403 intel_update_renderbuffers(driContext
, drawable
);
404 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
407 /* If we're currently rendering to the front buffer, the rendering
408 * that will happen next will probably dirty the front buffer. So
409 * mark it as dirty here.
411 if (intel
->is_front_buffer_rendering
)
412 intel
->front_buffer_dirty
= true;
414 /* Wait for the swapbuffers before the one we just emitted, so we
415 * don't get too many swaps outstanding for apps that are GPU-heavy
418 * We're using intelDRI2Flush (called from the loader before
419 * swapbuffer) and glFlush (for front buffer rendering) as the
420 * indicator that a frame is done and then throttle when we get
421 * here as we prepare to render the next frame. At this point for
422 * round trips for swap/copy and getting new buffers are done and
423 * we'll spend less time waiting on the GPU.
425 * Unfortunately, we don't have a handle to the batch containing
426 * the swap, and getting our hands on that doesn't seem worth it,
427 * so we just us the first batch we emitted after the last swap.
429 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
430 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
431 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
432 intel
->first_post_swapbuffers_batch
= NULL
;
433 intel
->need_throttle
= false;
438 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
440 struct intel_context
*intel
= intel_context(ctx
);
441 __DRIcontext
*driContext
= intel
->driContext
;
443 if (intel
->saved_viewport
)
444 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
446 if (ctx
->DrawBuffer
->Name
== 0) {
447 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
448 dri2InvalidateDrawable(driContext
->driReadablePriv
);
452 static const struct dri_debug_control debug_control
[] = {
453 { "tex", DEBUG_TEXTURE
},
454 { "state", DEBUG_STATE
},
455 { "ioctl", DEBUG_IOCTL
},
456 { "blit", DEBUG_BLIT
},
457 { "mip", DEBUG_MIPTREE
},
458 { "fall", DEBUG_FALLBACKS
},
459 { "verb", DEBUG_VERBOSE
},
460 { "bat", DEBUG_BATCH
},
461 { "pix", DEBUG_PIXEL
},
462 { "buf", DEBUG_BUFMGR
},
463 { "reg", DEBUG_REGION
},
466 { "sync", DEBUG_SYNC
},
467 { "prim", DEBUG_PRIMS
},
468 { "vert", DEBUG_VERTS
},
469 { "dri", DEBUG_DRI
},
471 { "san", DEBUG_SANITY
},
472 { "sleep", DEBUG_SLEEP
},
473 { "stats", DEBUG_STATS
},
474 { "tile", DEBUG_TILE
},
476 { "urb", DEBUG_URB
},
478 { "clip", DEBUG_CLIP
},
484 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
486 struct intel_context
*intel
= intel_context(ctx
);
488 _swrast_InvalidateState(ctx
, new_state
);
489 _vbo_InvalidateState(ctx
, new_state
);
491 intel
->NewGLState
|= new_state
;
493 if (intel
->vtbl
.invalidate_state
)
494 intel
->vtbl
.invalidate_state( intel
, new_state
);
498 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
500 struct intel_context
*intel
= intel_context(ctx
);
506 INTEL_FIREVERTICES(intel
);
510 intel_flush(struct gl_context
*ctx
)
512 struct intel_context
*intel
= intel_context(ctx
);
514 intel_flush_rendering_to_batch(ctx
);
516 if (intel
->batch
.used
)
517 intel_batchbuffer_flush(intel
);
521 intel_glFlush(struct gl_context
*ctx
)
523 struct intel_context
*intel
= intel_context(ctx
);
526 intel_flush_front(ctx
);
527 if (intel
->is_front_buffer_rendering
)
528 intel
->need_throttle
= true;
532 intelFinish(struct gl_context
* ctx
)
534 struct intel_context
*intel
= intel_context(ctx
);
537 intel_flush_front(ctx
);
539 if (intel
->batch
.last_bo
)
540 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
544 intelInitDriverFunctions(struct dd_function_table
*functions
)
546 _mesa_init_driver_functions(functions
);
548 functions
->Flush
= intel_glFlush
;
549 functions
->Finish
= intelFinish
;
550 functions
->GetString
= intelGetString
;
551 functions
->UpdateState
= intelInvalidateState
;
553 intelInitTextureFuncs(functions
);
554 intelInitTextureImageFuncs(functions
);
555 intelInitTextureSubImageFuncs(functions
);
556 intelInitTextureCopyImageFuncs(functions
);
557 intelInitStateFuncs(functions
);
558 intelInitClearFuncs(functions
);
559 intelInitBufferFuncs(functions
);
560 intelInitPixelFuncs(functions
);
561 intelInitBufferObjectFuncs(functions
);
562 intel_init_syncobj_functions(functions
);
566 intelInitContext(struct intel_context
*intel
,
568 const struct gl_config
* mesaVis
,
569 __DRIcontext
* driContextPriv
,
570 void *sharedContextPrivate
,
571 struct dd_function_table
*functions
)
573 struct gl_context
*ctx
= &intel
->ctx
;
574 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
575 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
576 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
578 struct gl_config visual
;
580 /* we can't do anything without a connection to the device */
581 if (intelScreen
->bufmgr
== NULL
)
584 /* Can't rely on invalidate events, fall back to glViewport hack */
585 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
586 intel
->saved_viewport
= functions
->Viewport
;
587 functions
->Viewport
= intel_viewport
;
590 if (mesaVis
== NULL
) {
591 memset(&visual
, 0, sizeof visual
);
595 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
596 functions
, (void *) intel
)) {
597 printf("%s: failed to init mesa context\n", __FUNCTION__
);
601 driContextPriv
->driverPrivate
= intel
;
602 intel
->intelScreen
= intelScreen
;
603 intel
->driContext
= driContextPriv
;
604 intel
->driFd
= sPriv
->fd
;
606 intel
->gen
= intelScreen
->gen
;
608 const int devID
= intelScreen
->deviceID
;
610 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
))
612 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
))
618 intel
->is_g4x
= true;
619 } else if (IS_945(devID
)) {
620 intel
->is_945
= true;
623 if (intel
->gen
>= 5) {
624 intel
->needs_ff_sync
= true;
627 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
628 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
629 intel
->has_hiz
= intel
->intelScreen
->hw_has_hiz
;
631 memset(&ctx
->TextureFormatSupported
, 0,
632 sizeof(ctx
->TextureFormatSupported
));
633 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB8888
] = true;
634 if (devID
!= PCI_CHIP_I830_M
&& devID
!= PCI_CHIP_845_G
)
635 ctx
->TextureFormatSupported
[MESA_FORMAT_XRGB8888
] = true;
636 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB4444
] = true;
637 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB1555
] = true;
638 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB565
] = true;
639 ctx
->TextureFormatSupported
[MESA_FORMAT_L8
] = true;
640 ctx
->TextureFormatSupported
[MESA_FORMAT_A8
] = true;
641 ctx
->TextureFormatSupported
[MESA_FORMAT_I8
] = true;
642 ctx
->TextureFormatSupported
[MESA_FORMAT_AL88
] = true;
643 if (intel
->gen
>= 4) {
644 ctx
->TextureFormatSupported
[MESA_FORMAT_L16
] = true;
645 ctx
->TextureFormatSupported
[MESA_FORMAT_A16
] = true;
646 ctx
->TextureFormatSupported
[MESA_FORMAT_I16
] = true;
647 ctx
->TextureFormatSupported
[MESA_FORMAT_AL1616
] = true;
650 /* Depth and stencil */
651 ctx
->TextureFormatSupported
[MESA_FORMAT_S8_Z24
] = true;
652 ctx
->TextureFormatSupported
[MESA_FORMAT_X8_Z24
] = true;
653 ctx
->TextureFormatSupported
[MESA_FORMAT_S8
] = intel
->has_separate_stencil
;
656 * This was disabled in initial FBO enabling to avoid combinations
657 * of depth+stencil that wouldn't work together. We since decided
658 * that it was OK, since it's up to the app to come up with the
659 * combo that actually works, so this can probably be re-enabled.
662 ctx->TextureFormatSupported[MESA_FORMAT_Z16] = true;
663 ctx->TextureFormatSupported[MESA_FORMAT_Z24] = true;
666 /* ctx->Extensions.MESA_ycbcr_texture */
667 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR
] = true;
668 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR_REV
] = true;
670 /* GL_3DFX_texture_compression_FXT1 */
671 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_FXT1
] = true;
672 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FXT1
] = true;
674 /* GL_EXT_texture_compression_s3tc */
675 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_DXT1
] = true;
676 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT1
] = true;
677 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT3
] = true;
678 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT5
] = true;
681 /* GL_ARB_texture_compression_rgtc */
682 ctx
->TextureFormatSupported
[MESA_FORMAT_RED_RGTC1
] = true;
683 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RED_RGTC1
] = true;
684 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_RGTC2
] = true;
685 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG_RGTC2
] = true;
687 /* GL_ARB_texture_rg */
688 ctx
->TextureFormatSupported
[MESA_FORMAT_R8
] = true;
689 ctx
->TextureFormatSupported
[MESA_FORMAT_R16
] = true;
690 ctx
->TextureFormatSupported
[MESA_FORMAT_RG88
] = true;
691 ctx
->TextureFormatSupported
[MESA_FORMAT_RG1616
] = true;
693 /* GL_MESA_texture_signed_rgba / GL_EXT_texture_snorm */
694 ctx
->TextureFormatSupported
[MESA_FORMAT_DUDV8
] = true;
695 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = true;
696 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R8
] = true;
697 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG88_REV
] = true;
698 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R16
] = true;
699 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_GR1616
] = true;
701 /* GL_EXT_texture_sRGB */
702 ctx
->TextureFormatSupported
[MESA_FORMAT_SARGB8
] = true;
703 if (intel
->gen
>= 5 || intel
->is_g4x
)
704 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGB_DXT1
] = true;
705 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT1
] = true;
706 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT3
] = true;
707 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT5
] = true;
708 if (intel
->gen
>= 5 || intel
->is_g4x
) {
709 ctx
->TextureFormatSupported
[MESA_FORMAT_SL8
] = true;
710 ctx
->TextureFormatSupported
[MESA_FORMAT_SLA8
] = true;
713 if (intel
->gen
>= 4) {
714 /* Each combination of 32-bit ints are supported, but the RGB 32-bit ints
715 * don't support use as a render target (GPU hangs).
717 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT32
] = true;
718 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT32
] = true;
719 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_INT32
] = true;
720 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT32
] = true;
722 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT32
] = true;
723 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT32
] = true;
724 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_UINT32
] = true;
725 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT32
] = true;
727 /* For 16 and 8 bits, RGB is unsupported entirely. */
728 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT16
] = true;
729 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT16
] = true;
730 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT16
] = true;
731 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT16
] = true;
732 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT16
] = true;
733 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT16
] = true;
735 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT8
] = true;
736 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT8
] = true;
737 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT8
] = true;
738 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT8
] = true;
739 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT8
] = true;
740 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT8
] = true;
743 #ifdef TEXTURE_FLOAT_ENABLED
744 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FLOAT32
] = true;
745 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_FLOAT32
] = true;
746 ctx
->TextureFormatSupported
[MESA_FORMAT_R_FLOAT32
] = true;
747 ctx
->TextureFormatSupported
[MESA_FORMAT_INTENSITY_FLOAT32
] = true;
748 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_FLOAT32
] = true;
749 ctx
->TextureFormatSupported
[MESA_FORMAT_ALPHA_FLOAT32
] = true;
750 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = true;
752 /* GL_EXT_texture_shared_exponent */
753 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB9_E5_FLOAT
] = true;
755 /* GL_EXT_packed_float */
756 ctx
->TextureFormatSupported
[MESA_FORMAT_R11_G11_B10_FLOAT
] = true;
761 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
762 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
764 intel
->maxBatchSize
= 4096;
766 intel
->maxBatchSize
= sizeof(intel
->batch
.map
);
768 intel
->bufmgr
= intelScreen
->bufmgr
;
770 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
771 switch (bo_reuse_mode
) {
772 case DRI_CONF_BO_REUSE_DISABLED
:
774 case DRI_CONF_BO_REUSE_ALL
:
775 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
779 /* This doesn't yet catch all non-conformant rendering, but it's a
782 if (getenv("INTEL_STRICT_CONFORMANCE")) {
783 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
785 intel
->conformance_mode
= value
;
788 intel
->conformance_mode
= 1;
792 if (intel
->conformance_mode
> 0) {
793 ctx
->Const
.MinLineWidth
= 1.0;
794 ctx
->Const
.MinLineWidthAA
= 1.0;
795 ctx
->Const
.MaxLineWidth
= 1.0;
796 ctx
->Const
.MaxLineWidthAA
= 1.0;
797 ctx
->Const
.LineWidthGranularity
= 1.0;
800 ctx
->Const
.MinLineWidth
= 1.0;
801 ctx
->Const
.MinLineWidthAA
= 1.0;
802 ctx
->Const
.MaxLineWidth
= 5.0;
803 ctx
->Const
.MaxLineWidthAA
= 5.0;
804 ctx
->Const
.LineWidthGranularity
= 0.5;
807 ctx
->Const
.MinPointSize
= 1.0;
808 ctx
->Const
.MinPointSizeAA
= 1.0;
809 ctx
->Const
.MaxPointSize
= 255.0;
810 ctx
->Const
.MaxPointSizeAA
= 3.0;
811 ctx
->Const
.PointSizeGranularity
= 1.0;
813 ctx
->Const
.MaxSamples
= 1.0;
816 ctx
->Const
.MaxClipPlanes
= 8;
818 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
820 /* reinitialize the context point state.
821 * It depend on constants in __struct gl_contextRec::Const
823 _mesa_init_point(ctx
);
825 if (intel
->gen
>= 4) {
826 ctx
->Const
.sRGBCapable
= true;
827 if (MAX_WIDTH
> 8192)
828 ctx
->Const
.MaxRenderbufferSize
= 8192;
830 if (MAX_WIDTH
> 2048)
831 ctx
->Const
.MaxRenderbufferSize
= 2048;
834 /* Initialize the software rasterizer and helper modules. */
835 _swrast_CreateContext(ctx
);
836 _vbo_CreateContext(ctx
);
837 _tnl_CreateContext(ctx
);
838 _swsetup_CreateContext(ctx
);
840 /* Configure swrast to match hardware characteristics: */
841 _swrast_allow_pixel_fog(ctx
, false);
842 _swrast_allow_vertex_fog(ctx
, true);
844 _mesa_meta_init(ctx
);
846 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
847 intel
->hw_stipple
= 1;
849 /* XXX FBO: this doesn't seem to be used anywhere */
850 switch (mesaVis
->depthBits
) {
851 case 0: /* what to do in this case? */
853 intel
->polygon_offset_scale
= 1.0;
856 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
864 intel
->polygon_offset_scale
/= 0xffff;
866 intel
->RenderIndex
= ~0;
870 intelInitExtensions(ctx
);
873 intelInitExtensionsES1(ctx
);
876 intelInitExtensionsES2(ctx
);
880 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
881 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
882 dri_bufmgr_set_debug(intel
->bufmgr
, true);
884 intel_batchbuffer_init(intel
);
886 intel_fbo_init(intel
);
888 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
890 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
892 intel
->prim
.primitive
= ~0;
894 /* Force all software fallbacks */
895 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
896 fprintf(stderr
, "disabling 3D rasterization\n");
900 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
901 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
902 intel
->always_flush_batch
= 1;
905 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
906 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
907 intel
->always_flush_cache
= 1;
914 intelDestroyContext(__DRIcontext
* driContextPriv
)
916 struct intel_context
*intel
=
917 (struct intel_context
*) driContextPriv
->driverPrivate
;
919 assert(intel
); /* should never be null */
921 INTEL_FIREVERTICES(intel
);
923 _mesa_meta_free(&intel
->ctx
);
925 intel
->vtbl
.destroy(intel
);
927 _swsetup_DestroyContext(&intel
->ctx
);
928 _tnl_DestroyContext(&intel
->ctx
);
929 _vbo_DestroyContext(&intel
->ctx
);
931 _swrast_DestroyContext(&intel
->ctx
);
932 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
934 intel_batchbuffer_free(intel
);
936 free(intel
->prim
.vb
);
937 intel
->prim
.vb
= NULL
;
938 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
939 intel
->prim
.vb_bo
= NULL
;
940 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
941 intel
->first_post_swapbuffers_batch
= NULL
;
943 driDestroyOptionCache(&intel
->optionCache
);
945 /* free the Mesa context */
946 _mesa_free_context_data(&intel
->ctx
);
948 _math_matrix_dtr(&intel
->ViewportMatrix
);
951 driContextPriv
->driverPrivate
= NULL
;
956 intelUnbindContext(__DRIcontext
* driContextPriv
)
958 /* Unset current context and dispath table */
959 _mesa_make_current(NULL
, NULL
, NULL
);
965 intelMakeCurrent(__DRIcontext
* driContextPriv
,
966 __DRIdrawable
* driDrawPriv
,
967 __DRIdrawable
* driReadPriv
)
969 struct intel_context
*intel
;
970 GET_CURRENT_CONTEXT(curCtx
);
973 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
977 /* According to the glXMakeCurrent() man page: "Pending commands to
978 * the previous context, if any, are flushed before it is released."
979 * But only flush if we're actually changing contexts.
981 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
985 if (driContextPriv
) {
986 struct gl_framebuffer
*fb
, *readFb
;
988 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
989 fb
= _mesa_get_incomplete_framebuffer();
990 readFb
= _mesa_get_incomplete_framebuffer();
992 fb
= driDrawPriv
->driverPrivate
;
993 readFb
= driReadPriv
->driverPrivate
;
994 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
995 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
998 intel_prepare_render(intel
);
999 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
1001 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
1002 * is NULL at that point. We can't call _mesa_makecurrent()
1003 * first, since we need the buffer size for the initial
1004 * viewport. So just call intel_draw_buffer() again here. */
1005 intel_draw_buffer(&intel
->ctx
);
1008 _mesa_make_current(NULL
, NULL
, NULL
);
1015 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1017 * To determine which DRI buffers to request, examine the renderbuffers
1018 * attached to the drawable's framebuffer. Then request the buffers with
1019 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
1021 * This is called from intel_update_renderbuffers(). It is used only if either
1022 * the hardware or the X driver lacks separate stencil support.
1024 * \param drawable Drawable whose buffers are queried.
1025 * \param buffers [out] List of buffers returned by DRI2 query.
1026 * \param buffer_count [out] Number of buffers returned.
1028 * \see intel_update_renderbuffers()
1029 * \see DRI2GetBuffers()
1030 * \see DRI2GetBuffersWithFormat()
1033 intel_query_dri2_buffers_no_separate_stencil(struct intel_context
*intel
,
1034 __DRIdrawable
*drawable
,
1035 __DRIbuffer
**buffers
,
1038 assert(!intel
->must_use_separate_stencil
);
1040 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1041 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1043 if (screen
->dri2
.loader
1044 && screen
->dri2
.loader
->base
.version
> 2
1045 && screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
) {
1048 const int max_attachments
= 4;
1049 unsigned *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
1051 struct intel_renderbuffer
*front_rb
;
1052 struct intel_renderbuffer
*back_rb
;
1053 struct intel_renderbuffer
*depth_rb
;
1054 struct intel_renderbuffer
*stencil_rb
;
1056 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1057 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1058 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1059 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1061 if ((intel
->is_front_buffer_rendering
||
1062 intel
->is_front_buffer_reading
||
1063 !back_rb
) && front_rb
) {
1064 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1065 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
1069 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1070 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
1073 if (depth_rb
&& stencil_rb
) {
1074 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
1075 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
1076 } else if (depth_rb
) {
1077 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
1078 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
1079 } else if (stencil_rb
) {
1080 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
1081 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
1084 assert(i
<= 2 * max_attachments
);
1086 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1091 drawable
->loaderPrivate
);
1094 } else if (screen
->dri2
.loader
) {
1097 const int max_attachments
= 4;
1098 unsigned *attachments
= calloc(max_attachments
, sizeof(unsigned));
1100 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
1101 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1102 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
1103 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1104 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
1105 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
1106 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
1107 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
1109 assert(i
<= max_attachments
);
1111 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1116 drawable
->loaderPrivate
);
1126 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1128 * This is called from intel_update_renderbuffers(). It is used only if
1129 * either the hardware or the X driver lacks separate stencil support.
1132 * DRI buffers whose attachment point is DRI2BufferStencil or
1133 * DRI2BufferDepthStencil are handled as special cases.
1135 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1136 * that is passed to intel_region_alloc_for_handle().
1138 * \see intel_update_renderbuffers()
1139 * \see intel_region_alloc_for_handle()
1142 intel_process_dri2_buffer_no_separate_stencil(struct intel_context
*intel
,
1143 __DRIdrawable
*drawable
,
1144 __DRIbuffer
*buffer
,
1145 struct intel_renderbuffer
*rb
,
1146 const char *buffer_name
)
1148 assert(!intel
->must_use_separate_stencil
);
1150 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1151 struct intel_renderbuffer
*depth_rb
= NULL
;
1156 if (rb
->region
&& rb
->region
->name
== buffer
->name
)
1159 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1161 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1162 buffer
->name
, buffer
->attachment
,
1163 buffer
->cpp
, buffer
->pitch
);
1166 bool identify_depth_and_stencil
= false;
1167 if (buffer
->attachment
== __DRI_BUFFER_STENCIL
) {
1168 struct intel_renderbuffer
*depth_rb
=
1169 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1170 identify_depth_and_stencil
= depth_rb
&& depth_rb
->region
;
1173 if (identify_depth_and_stencil
) {
1174 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1175 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
1177 intel_region_reference(&rb
->region
, depth_rb
->region
);
1179 intel_region_release(&rb
->region
);
1180 rb
->region
= intel_region_alloc_for_handle(intel
->intelScreen
,
1184 buffer
->pitch
/ buffer
->cpp
,
1189 if (buffer
->attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
1190 struct intel_renderbuffer
*stencil_rb
=
1191 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1196 /* The rb passed in is the BUFFER_DEPTH attachment, and we need
1197 * to associate this region to BUFFER_STENCIL as well.
1199 intel_region_reference(&stencil_rb
->region
, rb
->region
);
1204 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1206 * To determine which DRI buffers to request, examine the renderbuffers
1207 * attached to the drawable's framebuffer. Then request the buffers with
1208 * DRI2GetBuffersWithFormat().
1210 * This is called from intel_update_renderbuffers(). It is used when 1) the
1211 * hardware supports separate stencil and 2) the X driver's separate stencil
1212 * support has been verified to work or is still unknown.
1214 * \param drawable Drawable whose buffers are queried.
1215 * \param buffers [out] List of buffers returned by DRI2 query.
1216 * \param buffer_count [out] Number of buffers returned.
1217 * \param attachments [out] List of pairs (attachment_point, bits_per_pixel)
1218 * that were submitted in the DRI2 query. Number of pairs
1219 * is same as buffer_count.
1221 * \see intel_update_renderbuffers()
1222 * \see DRI2GetBuffersWithFormat()
1223 * \see enum intel_dri2_has_hiz
1226 intel_query_dri2_buffers_with_separate_stencil(struct intel_context
*intel
,
1227 __DRIdrawable
*drawable
,
1228 __DRIbuffer
**buffers
,
1229 unsigned **attachments
,
1232 assert(intel
->has_separate_stencil
);
1234 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1235 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1237 const int max_attachments
= 5;
1240 *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
1241 if (!*attachments
) {
1247 struct intel_renderbuffer
*front_rb
;
1248 struct intel_renderbuffer
*back_rb
;
1249 struct intel_renderbuffer
*depth_rb
;
1250 struct intel_renderbuffer
*stencil_rb
;
1252 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1253 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1254 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1255 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1257 if ((intel
->is_front_buffer_rendering
||
1258 intel
->is_front_buffer_reading
||
1259 !back_rb
) && front_rb
) {
1260 (*attachments
)[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1261 (*attachments
)[i
++] = intel_bits_per_pixel(front_rb
);
1265 (*attachments
)[i
++] = __DRI_BUFFER_BACK_LEFT
;
1266 (*attachments
)[i
++] = intel_bits_per_pixel(back_rb
);
1270 * We request a separate stencil buffer, and perhaps a hiz buffer too, even
1271 * if we do not yet know if the X driver supports it. See the comments for
1272 * 'enum intel_dri2_has_hiz'.
1276 (*attachments
)[i
++] = __DRI_BUFFER_DEPTH
;
1277 (*attachments
)[i
++] = intel_bits_per_pixel(depth_rb
);
1279 if (intel
->vtbl
.is_hiz_depth_format(intel
, depth_rb
->Base
.Format
)) {
1280 /* Depth and hiz buffer have same bpp. */
1281 (*attachments
)[i
++] = __DRI_BUFFER_HIZ
;
1282 (*attachments
)[i
++] = intel_bits_per_pixel(depth_rb
);
1287 assert(stencil_rb
->Base
.Format
== MESA_FORMAT_S8
);
1288 (*attachments
)[i
++] = __DRI_BUFFER_STENCIL
;
1289 (*attachments
)[i
++] = intel_bits_per_pixel(stencil_rb
);
1292 assert(i
<= 2 * max_attachments
);
1294 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1297 *attachments
, i
/ 2,
1299 drawable
->loaderPrivate
);
1303 *attachments
= NULL
;
1309 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1311 * This is called from intel_update_renderbuffers(). It is used when 1) the
1312 * hardware supports separate stencil and 2) the X driver's separate stencil
1313 * support has been verified to work or is still unknown.
1316 * DRI buffers whose attachment point is DRI2BufferStencil or DRI2BufferHiz
1317 * are handled as special cases.
1319 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1320 * that is passed to intel_region_alloc_for_handle().
1322 * \see intel_update_renderbuffers()
1323 * \see intel_region_alloc_for_handle()
1324 * \see enum intel_dri2_has_hiz
1327 intel_process_dri2_buffer_with_separate_stencil(struct intel_context
*intel
,
1328 __DRIdrawable
*drawable
,
1329 __DRIbuffer
*buffer
,
1330 struct intel_renderbuffer
*rb
,
1331 const char *buffer_name
)
1333 assert(intel
->has_separate_stencil
);
1334 assert(buffer
->attachment
!= __DRI_BUFFER_DEPTH_STENCIL
);
1339 /* If the renderbuffer's and DRIbuffer's regions match, then continue. */
1340 if ((buffer
->attachment
!= __DRI_BUFFER_HIZ
&&
1342 rb
->region
->name
== buffer
->name
) ||
1343 (buffer
->attachment
== __DRI_BUFFER_HIZ
&&
1345 rb
->hiz_region
->name
== buffer
->name
)) {
1349 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1351 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1352 buffer
->name
, buffer
->attachment
,
1353 buffer
->cpp
, buffer
->pitch
);
1357 * The stencil buffer has quirky pitch requirements. From Section
1358 * 2.11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
1359 * The pitch must be set to 2x the value computed based on width, as
1360 * the stencil buffer is stored with two rows interleaved.
1361 * If we neglect to double the pitch, then drm_intel_gem_bo_map_gtt()
1362 * maps the memory incorrectly.
1364 * To satisfy the pitch requirement, the X driver hackishly allocated
1365 * the gem buffer with bpp doubled and height halved. So buffer->cpp is
1366 * correct, but drawable->height is not.
1368 int buffer_height
= drawable
->h
;
1369 if (buffer
->attachment
== __DRI_BUFFER_STENCIL
) {
1373 struct intel_region
*region
=
1374 intel_region_alloc_for_handle(intel
->intelScreen
,
1378 buffer
->pitch
/ buffer
->cpp
,
1382 if (buffer
->attachment
== __DRI_BUFFER_HIZ
) {
1383 intel_region_reference(&rb
->hiz_region
, region
);
1385 intel_region_reference(&rb
->region
, region
);
1388 intel_region_release(®ion
);
1392 * \brief Verify that the X driver supports hiz and separate stencil.
1394 * This implements the cleanup stage of the handshake described in the
1395 * comments for 'enum intel_dri2_has_hiz'.
1397 * This should be called from intel_update_renderbuffers() after 1) the
1398 * DRIdrawable has been queried for its buffers via DRI2GetBuffersWithFormat()
1399 * and 2) the DRM region of each returned DRIbuffer has been assigned to the
1400 * appropriate intel_renderbuffer. Furthermore, this should be called *only*
1401 * when 1) intel_update_renderbuffers() tried to used the X driver's separate
1402 * stencil functionality and 2) it has not yet been determined if the X driver
1403 * supports separate stencil.
1405 * If we determine that the X driver does have support, then we set
1406 * intel_screen.dri2_has_hiz to true and return.
1408 * If we determine that the X driver lacks support, and we requested
1409 * a DRI2BufferDepth and DRI2BufferStencil, then we must remedy the mistake by
1410 * taking the following actions:
1411 * 1. Discard the framebuffer's stencil and depth renderbuffers.
1412 * 2. Create a combined depth/stencil renderbuffer and attach
1413 * it to the framebuffer's depth and stencil attachment points.
1414 * 3. Query the drawable for a new set of buffers, which consists of the
1415 * originally requested set plus DRI2BufferDepthStencil.
1416 * 4. Assign the DRI2BufferDepthStencil's DRM region to the new
1417 * depth/stencil renderbuffer.
1419 * \pre intel->intelScreen->dri2_has_hiz == INTEL_DRI2_HAS_HIZ_UNKNOWN
1421 * \param drawable Drawable whose buffers were queried.
1423 * \param buffers [in/out] As input, the buffer list returned by the
1424 * original DRI2 query. As output, the current buffer
1425 * list, which may have been altered by a new DRI2 query.
1427 * \param attachments [in/out] As input, the attachment list submitted
1428 * in the original DRI2 query. As output, the attachment
1429 * list that was submitted in the DRI2 query that
1430 * obtained the current buffer list, as returned in the
1431 * output parameter \c buffers. (Note: If no new query
1432 * was made, then the list remains unaltered).
1434 * \param count [out] Number of buffers in the current buffer list, as
1435 * returned in the output parameter \c buffers.
1437 * \see enum intel_dri2_has_hiz
1438 * \see struct intel_screen::dri2_has_hiz
1439 * \see intel_update_renderbuffers
1442 intel_verify_dri2_has_hiz(struct intel_context
*intel
,
1443 __DRIdrawable
*drawable
,
1444 __DRIbuffer
**buffers
,
1445 unsigned **attachments
,
1448 assert(intel
->intelScreen
->dri2_has_hiz
== INTEL_DRI2_HAS_HIZ_UNKNOWN
);
1450 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1451 struct intel_renderbuffer
*stencil_rb
=
1452 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1456 * We requested a DRI2BufferStencil without knowing if the X driver
1457 * supports it. Now, check if X handled the request correctly and clean
1458 * up if it did not. (See comments for 'enum intel_dri2_has_hiz').
1460 struct intel_renderbuffer
*depth_rb
=
1461 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1462 assert(stencil_rb
->Base
.Format
== MESA_FORMAT_S8
);
1463 assert(depth_rb
&& depth_rb
->Base
.Format
== MESA_FORMAT_X8_Z24
);
1465 if (stencil_rb
->region
->tiling
== I915_TILING_NONE
) {
1467 * The stencil buffer is actually W tiled. The region's tiling is
1468 * I915_TILING_NONE, however, because the GTT is incapable of W
1471 intel
->intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_TRUE
;
1475 * Oops... the screen doesn't support separate stencil. Discard the
1476 * separate depth and stencil buffers and replace them with
1477 * a combined depth/stencil buffer. Discard the hiz buffer too.
1479 intel
->intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_FALSE
;
1480 if (intel
->must_use_separate_stencil
) {
1481 _mesa_problem(&intel
->ctx
,
1482 "intel_context requires separate stencil, but the "
1483 "DRIscreen does not support it. You may need to "
1484 "upgrade the Intel X driver to 2.16.0");
1488 /* 1. Discard depth and stencil renderbuffers. */
1489 _mesa_remove_renderbuffer(fb
, BUFFER_DEPTH
);
1491 _mesa_remove_renderbuffer(fb
, BUFFER_STENCIL
);
1494 /* 2. Create new depth/stencil renderbuffer. */
1495 struct intel_renderbuffer
*depth_stencil_rb
=
1496 intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
1497 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depth_stencil_rb
->Base
);
1498 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depth_stencil_rb
->Base
);
1500 /* 3. Append DRI2BufferDepthStencil to attachment list. */
1501 int old_count
= *count
;
1502 unsigned int *old_attachments
= *attachments
;
1503 *count
= old_count
+ 1;
1504 *attachments
= malloc(2 * (*count
) * sizeof(unsigned));
1505 memcpy(*attachments
, old_attachments
, 2 * old_count
* sizeof(unsigned));
1506 free(old_attachments
);
1507 (*attachments
)[2 * old_count
+ 0] = __DRI_BUFFER_DEPTH_STENCIL
;
1508 (*attachments
)[2 * old_count
+ 1] = intel_bits_per_pixel(depth_stencil_rb
);
1510 /* 4. Request new set of DRI2 attachments. */
1511 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1512 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1518 drawable
->loaderPrivate
);
1523 * I don't know how to recover from the failure assertion below.
1524 * Rather than fail gradually and unexpectedly, we should just die
1527 assert(*count
== old_count
+ 1);
1529 /* 5. Assign the DRI buffer's DRM region to the its renderbuffers. */
1530 __DRIbuffer
*depth_stencil_buffer
= NULL
;
1531 for (int i
= 0; i
< *count
; ++i
) {
1532 if ((*buffers
)[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
1533 depth_stencil_buffer
= &(*buffers
)[i
];
1537 struct intel_region
*region
=
1538 intel_region_alloc_for_handle(intel
->intelScreen
,
1539 depth_stencil_buffer
->cpp
,
1542 depth_stencil_buffer
->pitch
1543 / depth_stencil_buffer
->cpp
,
1544 depth_stencil_buffer
->name
,
1545 "dri2 depth / stencil buffer");
1546 intel_region_reference(&intel_get_renderbuffer(fb
, BUFFER_DEPTH
)->region
,
1548 intel_region_reference(&intel_get_renderbuffer(fb
, BUFFER_STENCIL
)->region
,
1550 intel_region_release(®ion
);
1554 if (intel_framebuffer_has_hiz(fb
)) {
1556 * In the future, the driver may advertise a GL config with hiz
1557 * compatible depth bits and 0 stencil bits (for example, when the
1558 * driver gains support for float32 depth buffers). When that day comes,
1559 * here we need to verify that the X driver does in fact support hiz and
1560 * clean up if it doesn't.
1562 * Presently, however, no verification or clean up is necessary, and
1563 * execution should not reach here. If the framebuffer still has a hiz
1564 * region, then we have already set dri2_has_hiz to true after
1565 * confirming above that the stencil buffer is W tiled.