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"
56 #include "intel_mipmap_tree.h"
59 #include "../glsl/ralloc.h"
62 int INTEL_DEBUG
= (0);
66 static const GLubyte
*
67 intelGetString(struct gl_context
* ctx
, GLenum name
)
69 const struct intel_context
*const intel
= intel_context(ctx
);
71 static char buffer
[128];
75 return (GLubyte
*) "Tungsten Graphics, Inc";
79 switch (intel
->intelScreen
->deviceID
) {
81 chipset
= "Intel(R) 845G";
84 chipset
= "Intel(R) 830M";
86 case PCI_CHIP_I855_GM
:
87 chipset
= "Intel(R) 852GM/855GM";
90 chipset
= "Intel(R) 865G";
93 chipset
= "Intel(R) 915G";
95 case PCI_CHIP_E7221_G
:
96 chipset
= "Intel (R) E7221G (i915)";
98 case PCI_CHIP_I915_GM
:
99 chipset
= "Intel(R) 915GM";
101 case PCI_CHIP_I945_G
:
102 chipset
= "Intel(R) 945G";
104 case PCI_CHIP_I945_GM
:
105 chipset
= "Intel(R) 945GM";
107 case PCI_CHIP_I945_GME
:
108 chipset
= "Intel(R) 945GME";
111 chipset
= "Intel(R) G33";
114 chipset
= "Intel(R) Q35";
117 chipset
= "Intel(R) Q33";
119 case PCI_CHIP_IGD_GM
:
121 chipset
= "Intel(R) IGD";
123 case PCI_CHIP_I965_Q
:
124 chipset
= "Intel(R) 965Q";
126 case PCI_CHIP_I965_G
:
127 case PCI_CHIP_I965_G_1
:
128 chipset
= "Intel(R) 965G";
130 case PCI_CHIP_I946_GZ
:
131 chipset
= "Intel(R) 946GZ";
133 case PCI_CHIP_I965_GM
:
134 chipset
= "Intel(R) 965GM";
136 case PCI_CHIP_I965_GME
:
137 chipset
= "Intel(R) 965GME/GLE";
139 case PCI_CHIP_GM45_GM
:
140 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
142 case PCI_CHIP_IGD_E_G
:
143 chipset
= "Intel(R) Integrated Graphics Device";
146 chipset
= "Intel(R) G45/G43";
149 chipset
= "Intel(R) Q45/Q43";
152 chipset
= "Intel(R) G41";
155 case PCI_CHIP_B43_G1
:
156 chipset
= "Intel(R) B43";
159 chipset
= "Intel(R) Ironlake Desktop";
162 chipset
= "Intel(R) Ironlake Mobile";
164 case PCI_CHIP_SANDYBRIDGE_GT1
:
165 case PCI_CHIP_SANDYBRIDGE_GT2
:
166 case PCI_CHIP_SANDYBRIDGE_GT2_PLUS
:
167 chipset
= "Intel(R) Sandybridge Desktop";
169 case PCI_CHIP_SANDYBRIDGE_M_GT1
:
170 case PCI_CHIP_SANDYBRIDGE_M_GT2
:
171 case PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS
:
172 chipset
= "Intel(R) Sandybridge Mobile";
174 case PCI_CHIP_SANDYBRIDGE_S
:
175 chipset
= "Intel(R) Sandybridge Server";
177 case PCI_CHIP_IVYBRIDGE_GT1
:
178 case PCI_CHIP_IVYBRIDGE_GT2
:
179 chipset
= "Intel(R) Ivybridge Desktop";
181 case PCI_CHIP_IVYBRIDGE_M_GT1
:
182 case PCI_CHIP_IVYBRIDGE_M_GT2
:
183 chipset
= "Intel(R) Ivybridge Mobile";
185 case PCI_CHIP_IVYBRIDGE_S_GT1
:
186 chipset
= "Intel(R) Ivybridge Server";
189 chipset
= "Unknown Intel Chipset";
193 (void) driGetRendererString(buffer
, chipset
, 0);
194 return (GLubyte
*) buffer
;
202 intel_flush_front(struct gl_context
*ctx
)
204 struct intel_context
*intel
= intel_context(ctx
);
205 __DRIcontext
*driContext
= intel
->driContext
;
206 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
208 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
209 if (screen
->dri2
.loader
&&
210 (screen
->dri2
.loader
->base
.version
>= 2)
211 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
212 driContext
->driDrawablePriv
&&
213 driContext
->driDrawablePriv
->loaderPrivate
) {
214 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
215 driContext
->driDrawablePriv
->loaderPrivate
);
217 /* We set the dirty bit in intel_prepare_render() if we're
218 * front buffer rendering once we get there.
220 intel
->front_buffer_dirty
= false;
226 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
228 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
232 intel_query_dri2_buffers_no_separate_stencil(struct intel_context
*intel
,
233 __DRIdrawable
*drawable
,
234 __DRIbuffer
**buffers
,
238 intel_process_dri2_buffer_no_separate_stencil(struct intel_context
*intel
,
239 __DRIdrawable
*drawable
,
241 struct intel_renderbuffer
*rb
,
242 const char *buffer_name
);
245 intel_query_dri2_buffers_with_separate_stencil(struct intel_context
*intel
,
246 __DRIdrawable
*drawable
,
247 __DRIbuffer
**buffers
,
248 unsigned **attachments
,
252 intel_process_dri2_buffer_with_separate_stencil(struct intel_context
*intel
,
253 __DRIdrawable
*drawable
,
255 struct intel_renderbuffer
*rb
,
256 const char *buffer_name
);
258 intel_verify_dri2_has_hiz(struct intel_context
*intel
,
259 __DRIdrawable
*drawable
,
260 __DRIbuffer
**buffers
,
261 unsigned **attachments
,
265 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
267 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
268 struct intel_renderbuffer
*rb
;
269 struct intel_context
*intel
= context
->driverPrivate
;
270 __DRIbuffer
*buffers
= NULL
;
271 unsigned *attachments
= NULL
;
273 const char *region_name
;
275 bool try_separate_stencil
=
276 intel
->has_separate_stencil
&&
277 intel
->intelScreen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
&&
278 intel
->intelScreen
->driScrnPriv
->dri2
.loader
!= NULL
&&
279 intel
->intelScreen
->driScrnPriv
->dri2
.loader
->base
.version
> 2 &&
280 intel
->intelScreen
->driScrnPriv
->dri2
.loader
->getBuffersWithFormat
!= NULL
;
282 assert(!intel
->must_use_separate_stencil
|| try_separate_stencil
);
284 /* If we're rendering to the fake front buffer, make sure all the
285 * pending drawing has landed on the real front buffer. Otherwise
286 * when we eventually get to DRI2GetBuffersWithFormat the stale
287 * real front buffer contents will get copied to the new fake front
290 if (intel
->is_front_buffer_rendering
) {
291 intel_flush(&intel
->ctx
);
292 intel_flush_front(&intel
->ctx
);
295 /* Set this up front, so that in case our buffers get invalidated
296 * while we're getting new buffers, we don't clobber the stamp and
297 * thus ignore the invalidate. */
298 drawable
->lastStamp
= drawable
->dri2
.stamp
;
300 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
301 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
303 if (try_separate_stencil
) {
304 intel_query_dri2_buffers_with_separate_stencil(intel
, drawable
, &buffers
,
305 &attachments
, &count
);
307 intel_query_dri2_buffers_no_separate_stencil(intel
, drawable
, &buffers
,
314 for (i
= 0; i
< count
; i
++) {
315 switch (buffers
[i
].attachment
) {
316 case __DRI_BUFFER_FRONT_LEFT
:
317 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
318 region_name
= "dri2 front buffer";
321 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
322 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
323 region_name
= "dri2 fake front buffer";
326 case __DRI_BUFFER_BACK_LEFT
:
327 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
328 region_name
= "dri2 back buffer";
331 case __DRI_BUFFER_DEPTH
:
332 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
333 region_name
= "dri2 depth buffer";
336 case __DRI_BUFFER_HIZ
:
337 /* The hiz region resides in the depth renderbuffer. */
338 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
339 region_name
= "dri2 hiz buffer";
342 case __DRI_BUFFER_DEPTH_STENCIL
:
343 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
344 region_name
= "dri2 depth / stencil buffer";
347 case __DRI_BUFFER_STENCIL
:
348 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
349 region_name
= "dri2 stencil buffer";
352 case __DRI_BUFFER_ACCUM
:
355 "unhandled buffer attach event, attachment type %d\n",
356 buffers
[i
].attachment
);
360 if (try_separate_stencil
) {
361 intel_process_dri2_buffer_with_separate_stencil(intel
, drawable
,
365 intel_process_dri2_buffer_no_separate_stencil(intel
, drawable
,
371 if (try_separate_stencil
372 && intel
->intelScreen
->dri2_has_hiz
== INTEL_DRI2_HAS_HIZ_UNKNOWN
) {
373 intel_verify_dri2_has_hiz(intel
, drawable
, &buffers
, &attachments
,
380 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
384 * intel_prepare_render should be called anywhere that curent read/drawbuffer
388 intel_prepare_render(struct intel_context
*intel
)
390 __DRIcontext
*driContext
= intel
->driContext
;
391 __DRIdrawable
*drawable
;
393 drawable
= driContext
->driDrawablePriv
;
394 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
395 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
396 intel_update_renderbuffers(driContext
, drawable
);
397 intel_draw_buffer(&intel
->ctx
);
398 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
401 drawable
= driContext
->driReadablePriv
;
402 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
403 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
404 intel_update_renderbuffers(driContext
, drawable
);
405 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
408 /* If we're currently rendering to the front buffer, the rendering
409 * that will happen next will probably dirty the front buffer. So
410 * mark it as dirty here.
412 if (intel
->is_front_buffer_rendering
)
413 intel
->front_buffer_dirty
= true;
415 /* Wait for the swapbuffers before the one we just emitted, so we
416 * don't get too many swaps outstanding for apps that are GPU-heavy
419 * We're using intelDRI2Flush (called from the loader before
420 * swapbuffer) and glFlush (for front buffer rendering) as the
421 * indicator that a frame is done and then throttle when we get
422 * here as we prepare to render the next frame. At this point for
423 * round trips for swap/copy and getting new buffers are done and
424 * we'll spend less time waiting on the GPU.
426 * Unfortunately, we don't have a handle to the batch containing
427 * the swap, and getting our hands on that doesn't seem worth it,
428 * so we just us the first batch we emitted after the last swap.
430 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
431 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
432 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
433 intel
->first_post_swapbuffers_batch
= NULL
;
434 intel
->need_throttle
= false;
439 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
441 struct intel_context
*intel
= intel_context(ctx
);
442 __DRIcontext
*driContext
= intel
->driContext
;
444 if (intel
->saved_viewport
)
445 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
447 if (ctx
->DrawBuffer
->Name
== 0) {
448 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
449 dri2InvalidateDrawable(driContext
->driReadablePriv
);
453 static const struct dri_debug_control debug_control
[] = {
454 { "tex", DEBUG_TEXTURE
},
455 { "state", DEBUG_STATE
},
456 { "ioctl", DEBUG_IOCTL
},
457 { "blit", DEBUG_BLIT
},
458 { "mip", DEBUG_MIPTREE
},
459 { "fall", DEBUG_FALLBACKS
},
460 { "verb", DEBUG_VERBOSE
},
461 { "bat", DEBUG_BATCH
},
462 { "pix", DEBUG_PIXEL
},
463 { "buf", DEBUG_BUFMGR
},
464 { "reg", DEBUG_REGION
},
467 { "sync", DEBUG_SYNC
},
468 { "prim", DEBUG_PRIMS
},
469 { "vert", DEBUG_VERTS
},
470 { "dri", DEBUG_DRI
},
472 { "san", DEBUG_SANITY
},
473 { "sleep", DEBUG_SLEEP
},
474 { "stats", DEBUG_STATS
},
475 { "tile", DEBUG_TILE
},
477 { "urb", DEBUG_URB
},
479 { "clip", DEBUG_CLIP
},
485 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
487 struct intel_context
*intel
= intel_context(ctx
);
489 _swrast_InvalidateState(ctx
, new_state
);
490 _vbo_InvalidateState(ctx
, new_state
);
492 intel
->NewGLState
|= new_state
;
494 if (intel
->vtbl
.invalidate_state
)
495 intel
->vtbl
.invalidate_state( intel
, new_state
);
499 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
501 struct intel_context
*intel
= intel_context(ctx
);
507 INTEL_FIREVERTICES(intel
);
511 intel_flush(struct gl_context
*ctx
)
513 struct intel_context
*intel
= intel_context(ctx
);
515 intel_flush_rendering_to_batch(ctx
);
517 if (intel
->batch
.used
)
518 intel_batchbuffer_flush(intel
);
522 intel_glFlush(struct gl_context
*ctx
)
524 struct intel_context
*intel
= intel_context(ctx
);
527 intel_flush_front(ctx
);
528 if (intel
->is_front_buffer_rendering
)
529 intel
->need_throttle
= true;
533 intelFinish(struct gl_context
* ctx
)
535 struct intel_context
*intel
= intel_context(ctx
);
538 intel_flush_front(ctx
);
540 if (intel
->batch
.last_bo
)
541 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
545 intelInitDriverFunctions(struct dd_function_table
*functions
)
547 _mesa_init_driver_functions(functions
);
549 functions
->Flush
= intel_glFlush
;
550 functions
->Finish
= intelFinish
;
551 functions
->GetString
= intelGetString
;
552 functions
->UpdateState
= intelInvalidateState
;
554 intelInitTextureFuncs(functions
);
555 intelInitTextureImageFuncs(functions
);
556 intelInitTextureSubImageFuncs(functions
);
557 intelInitTextureCopyImageFuncs(functions
);
558 intelInitStateFuncs(functions
);
559 intelInitClearFuncs(functions
);
560 intelInitBufferFuncs(functions
);
561 intelInitPixelFuncs(functions
);
562 intelInitBufferObjectFuncs(functions
);
563 intel_init_syncobj_functions(functions
);
567 intelInitContext(struct intel_context
*intel
,
569 const struct gl_config
* mesaVis
,
570 __DRIcontext
* driContextPriv
,
571 void *sharedContextPrivate
,
572 struct dd_function_table
*functions
)
574 struct gl_context
*ctx
= &intel
->ctx
;
575 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
576 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
577 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
579 struct gl_config visual
;
581 /* we can't do anything without a connection to the device */
582 if (intelScreen
->bufmgr
== NULL
)
585 /* Can't rely on invalidate events, fall back to glViewport hack */
586 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
587 intel
->saved_viewport
= functions
->Viewport
;
588 functions
->Viewport
= intel_viewport
;
591 if (mesaVis
== NULL
) {
592 memset(&visual
, 0, sizeof visual
);
596 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
597 functions
, (void *) intel
)) {
598 printf("%s: failed to init mesa context\n", __FUNCTION__
);
602 driContextPriv
->driverPrivate
= intel
;
603 intel
->intelScreen
= intelScreen
;
604 intel
->driContext
= driContextPriv
;
605 intel
->driFd
= sPriv
->fd
;
607 intel
->gen
= intelScreen
->gen
;
609 const int devID
= intelScreen
->deviceID
;
611 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
))
613 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
))
619 intel
->is_g4x
= true;
620 } else if (IS_945(devID
)) {
621 intel
->is_945
= true;
624 if (intel
->gen
>= 5) {
625 intel
->needs_ff_sync
= true;
628 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
629 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
630 intel
->has_hiz
= intel
->intelScreen
->hw_has_hiz
;
632 memset(&ctx
->TextureFormatSupported
, 0,
633 sizeof(ctx
->TextureFormatSupported
));
634 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB8888
] = true;
635 if (devID
!= PCI_CHIP_I830_M
&& devID
!= PCI_CHIP_845_G
)
636 ctx
->TextureFormatSupported
[MESA_FORMAT_XRGB8888
] = true;
637 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB4444
] = true;
638 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB1555
] = true;
639 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB565
] = true;
640 ctx
->TextureFormatSupported
[MESA_FORMAT_L8
] = true;
641 ctx
->TextureFormatSupported
[MESA_FORMAT_A8
] = true;
642 ctx
->TextureFormatSupported
[MESA_FORMAT_I8
] = true;
643 ctx
->TextureFormatSupported
[MESA_FORMAT_AL88
] = true;
644 if (intel
->gen
>= 4) {
645 ctx
->TextureFormatSupported
[MESA_FORMAT_L16
] = true;
646 ctx
->TextureFormatSupported
[MESA_FORMAT_A16
] = true;
647 ctx
->TextureFormatSupported
[MESA_FORMAT_I16
] = true;
648 ctx
->TextureFormatSupported
[MESA_FORMAT_AL1616
] = true;
651 /* Depth and stencil */
652 ctx
->TextureFormatSupported
[MESA_FORMAT_S8_Z24
] = true;
653 ctx
->TextureFormatSupported
[MESA_FORMAT_X8_Z24
] = true;
654 ctx
->TextureFormatSupported
[MESA_FORMAT_S8
] = intel
->has_separate_stencil
;
657 * This was disabled in initial FBO enabling to avoid combinations
658 * of depth+stencil that wouldn't work together. We since decided
659 * that it was OK, since it's up to the app to come up with the
660 * combo that actually works, so this can probably be re-enabled.
663 ctx->TextureFormatSupported[MESA_FORMAT_Z16] = true;
664 ctx->TextureFormatSupported[MESA_FORMAT_Z24] = true;
667 /* ctx->Extensions.MESA_ycbcr_texture */
668 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR
] = true;
669 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR_REV
] = true;
671 /* GL_3DFX_texture_compression_FXT1 */
672 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_FXT1
] = true;
673 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FXT1
] = true;
675 /* GL_EXT_texture_compression_s3tc */
676 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_DXT1
] = true;
677 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT1
] = true;
678 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT3
] = true;
679 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT5
] = true;
682 /* GL_ARB_texture_compression_rgtc */
683 ctx
->TextureFormatSupported
[MESA_FORMAT_RED_RGTC1
] = true;
684 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RED_RGTC1
] = true;
685 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_RGTC2
] = true;
686 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG_RGTC2
] = true;
688 /* GL_ARB_texture_rg */
689 ctx
->TextureFormatSupported
[MESA_FORMAT_R8
] = true;
690 ctx
->TextureFormatSupported
[MESA_FORMAT_R16
] = true;
691 ctx
->TextureFormatSupported
[MESA_FORMAT_RG88
] = true;
692 ctx
->TextureFormatSupported
[MESA_FORMAT_RG1616
] = true;
694 /* GL_MESA_texture_signed_rgba / GL_EXT_texture_snorm */
695 ctx
->TextureFormatSupported
[MESA_FORMAT_DUDV8
] = true;
696 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = true;
697 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R8
] = true;
698 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG88_REV
] = true;
699 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R16
] = true;
700 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_GR1616
] = true;
702 /* GL_EXT_texture_sRGB */
703 ctx
->TextureFormatSupported
[MESA_FORMAT_SARGB8
] = true;
704 if (intel
->gen
>= 5 || intel
->is_g4x
)
705 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGB_DXT1
] = true;
706 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT1
] = true;
707 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT3
] = true;
708 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT5
] = true;
709 if (intel
->gen
>= 5 || intel
->is_g4x
) {
710 ctx
->TextureFormatSupported
[MESA_FORMAT_SL8
] = true;
711 ctx
->TextureFormatSupported
[MESA_FORMAT_SLA8
] = true;
714 if (intel
->gen
>= 4) {
715 /* Each combination of 32-bit ints are supported, but the RGB 32-bit ints
716 * don't support use as a render target (GPU hangs).
718 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT32
] = true;
719 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT32
] = true;
720 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_INT32
] = true;
721 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT32
] = true;
723 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT32
] = true;
724 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT32
] = true;
725 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_UINT32
] = true;
726 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT32
] = true;
728 /* For 16 and 8 bits, RGB is unsupported entirely. */
729 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT16
] = true;
730 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT16
] = true;
731 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT16
] = true;
732 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT16
] = true;
733 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT16
] = true;
734 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT16
] = true;
736 ctx
->TextureFormatSupported
[MESA_FORMAT_R_UINT8
] = true;
737 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_UINT8
] = true;
738 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_UINT8
] = true;
739 ctx
->TextureFormatSupported
[MESA_FORMAT_R_INT8
] = true;
740 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_INT8
] = true;
741 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_INT8
] = true;
744 #ifdef TEXTURE_FLOAT_ENABLED
745 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FLOAT32
] = true;
746 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_FLOAT32
] = true;
747 ctx
->TextureFormatSupported
[MESA_FORMAT_R_FLOAT32
] = true;
748 ctx
->TextureFormatSupported
[MESA_FORMAT_INTENSITY_FLOAT32
] = true;
749 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_FLOAT32
] = true;
750 ctx
->TextureFormatSupported
[MESA_FORMAT_ALPHA_FLOAT32
] = true;
751 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = true;
753 /* GL_EXT_texture_shared_exponent */
754 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB9_E5_FLOAT
] = true;
756 /* GL_EXT_packed_float */
757 ctx
->TextureFormatSupported
[MESA_FORMAT_R11_G11_B10_FLOAT
] = true;
762 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
763 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
765 intel
->maxBatchSize
= 4096;
767 intel
->maxBatchSize
= sizeof(intel
->batch
.map
);
769 intel
->bufmgr
= intelScreen
->bufmgr
;
771 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
772 switch (bo_reuse_mode
) {
773 case DRI_CONF_BO_REUSE_DISABLED
:
775 case DRI_CONF_BO_REUSE_ALL
:
776 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
780 /* This doesn't yet catch all non-conformant rendering, but it's a
783 if (getenv("INTEL_STRICT_CONFORMANCE")) {
784 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
786 intel
->conformance_mode
= value
;
789 intel
->conformance_mode
= 1;
793 if (intel
->conformance_mode
> 0) {
794 ctx
->Const
.MinLineWidth
= 1.0;
795 ctx
->Const
.MinLineWidthAA
= 1.0;
796 ctx
->Const
.MaxLineWidth
= 1.0;
797 ctx
->Const
.MaxLineWidthAA
= 1.0;
798 ctx
->Const
.LineWidthGranularity
= 1.0;
801 ctx
->Const
.MinLineWidth
= 1.0;
802 ctx
->Const
.MinLineWidthAA
= 1.0;
803 ctx
->Const
.MaxLineWidth
= 5.0;
804 ctx
->Const
.MaxLineWidthAA
= 5.0;
805 ctx
->Const
.LineWidthGranularity
= 0.5;
808 ctx
->Const
.MinPointSize
= 1.0;
809 ctx
->Const
.MinPointSizeAA
= 1.0;
810 ctx
->Const
.MaxPointSize
= 255.0;
811 ctx
->Const
.MaxPointSizeAA
= 3.0;
812 ctx
->Const
.PointSizeGranularity
= 1.0;
814 ctx
->Const
.MaxSamples
= 1.0;
817 ctx
->Const
.MaxClipPlanes
= 8;
819 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
821 /* reinitialize the context point state.
822 * It depend on constants in __struct gl_contextRec::Const
824 _mesa_init_point(ctx
);
826 if (intel
->gen
>= 4) {
827 ctx
->Const
.sRGBCapable
= true;
828 if (MAX_WIDTH
> 8192)
829 ctx
->Const
.MaxRenderbufferSize
= 8192;
831 if (MAX_WIDTH
> 2048)
832 ctx
->Const
.MaxRenderbufferSize
= 2048;
835 /* Initialize the software rasterizer and helper modules. */
836 _swrast_CreateContext(ctx
);
837 _vbo_CreateContext(ctx
);
838 _tnl_CreateContext(ctx
);
839 _swsetup_CreateContext(ctx
);
841 /* Configure swrast to match hardware characteristics: */
842 _swrast_allow_pixel_fog(ctx
, false);
843 _swrast_allow_vertex_fog(ctx
, true);
845 _mesa_meta_init(ctx
);
847 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
848 intel
->hw_stipple
= 1;
850 /* XXX FBO: this doesn't seem to be used anywhere */
851 switch (mesaVis
->depthBits
) {
852 case 0: /* what to do in this case? */
854 intel
->polygon_offset_scale
= 1.0;
857 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
865 intel
->polygon_offset_scale
/= 0xffff;
867 intel
->RenderIndex
= ~0;
871 intelInitExtensions(ctx
);
874 intelInitExtensionsES1(ctx
);
877 intelInitExtensionsES2(ctx
);
881 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
882 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
883 dri_bufmgr_set_debug(intel
->bufmgr
, true);
885 intel_batchbuffer_init(intel
);
887 intel_fbo_init(intel
);
889 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
891 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
893 intel
->prim
.primitive
= ~0;
895 /* Force all software fallbacks */
896 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
897 fprintf(stderr
, "disabling 3D rasterization\n");
901 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
902 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
903 intel
->always_flush_batch
= 1;
906 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
907 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
908 intel
->always_flush_cache
= 1;
915 intelDestroyContext(__DRIcontext
* driContextPriv
)
917 struct intel_context
*intel
=
918 (struct intel_context
*) driContextPriv
->driverPrivate
;
920 assert(intel
); /* should never be null */
922 INTEL_FIREVERTICES(intel
);
924 _mesa_meta_free(&intel
->ctx
);
926 intel
->vtbl
.destroy(intel
);
928 _swsetup_DestroyContext(&intel
->ctx
);
929 _tnl_DestroyContext(&intel
->ctx
);
930 _vbo_DestroyContext(&intel
->ctx
);
932 _swrast_DestroyContext(&intel
->ctx
);
933 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
935 intel_batchbuffer_free(intel
);
937 free(intel
->prim
.vb
);
938 intel
->prim
.vb
= NULL
;
939 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
940 intel
->prim
.vb_bo
= NULL
;
941 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
942 intel
->first_post_swapbuffers_batch
= NULL
;
944 driDestroyOptionCache(&intel
->optionCache
);
946 /* free the Mesa context */
947 _mesa_free_context_data(&intel
->ctx
);
949 _math_matrix_dtr(&intel
->ViewportMatrix
);
952 driContextPriv
->driverPrivate
= NULL
;
957 intelUnbindContext(__DRIcontext
* driContextPriv
)
959 /* Unset current context and dispath table */
960 _mesa_make_current(NULL
, NULL
, NULL
);
966 intelMakeCurrent(__DRIcontext
* driContextPriv
,
967 __DRIdrawable
* driDrawPriv
,
968 __DRIdrawable
* driReadPriv
)
970 struct intel_context
*intel
;
971 GET_CURRENT_CONTEXT(curCtx
);
974 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
978 /* According to the glXMakeCurrent() man page: "Pending commands to
979 * the previous context, if any, are flushed before it is released."
980 * But only flush if we're actually changing contexts.
982 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
986 if (driContextPriv
) {
987 struct gl_framebuffer
*fb
, *readFb
;
989 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
990 fb
= _mesa_get_incomplete_framebuffer();
991 readFb
= _mesa_get_incomplete_framebuffer();
993 fb
= driDrawPriv
->driverPrivate
;
994 readFb
= driReadPriv
->driverPrivate
;
995 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
996 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
999 intel_prepare_render(intel
);
1000 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
1002 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
1003 * is NULL at that point. We can't call _mesa_makecurrent()
1004 * first, since we need the buffer size for the initial
1005 * viewport. So just call intel_draw_buffer() again here. */
1006 intel_draw_buffer(&intel
->ctx
);
1009 _mesa_make_current(NULL
, NULL
, NULL
);
1016 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1018 * To determine which DRI buffers to request, examine the renderbuffers
1019 * attached to the drawable's framebuffer. Then request the buffers with
1020 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
1022 * This is called from intel_update_renderbuffers(). It is used only if either
1023 * the hardware or the X driver lacks separate stencil support.
1025 * \param drawable Drawable whose buffers are queried.
1026 * \param buffers [out] List of buffers returned by DRI2 query.
1027 * \param buffer_count [out] Number of buffers returned.
1029 * \see intel_update_renderbuffers()
1030 * \see DRI2GetBuffers()
1031 * \see DRI2GetBuffersWithFormat()
1034 intel_query_dri2_buffers_no_separate_stencil(struct intel_context
*intel
,
1035 __DRIdrawable
*drawable
,
1036 __DRIbuffer
**buffers
,
1039 assert(!intel
->must_use_separate_stencil
);
1041 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1042 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1044 if (screen
->dri2
.loader
1045 && screen
->dri2
.loader
->base
.version
> 2
1046 && screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
) {
1049 const int max_attachments
= 4;
1050 unsigned *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
1052 struct intel_renderbuffer
*front_rb
;
1053 struct intel_renderbuffer
*back_rb
;
1054 struct intel_renderbuffer
*depth_rb
;
1055 struct intel_renderbuffer
*stencil_rb
;
1057 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1058 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1059 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1060 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1062 if ((intel
->is_front_buffer_rendering
||
1063 intel
->is_front_buffer_reading
||
1064 !back_rb
) && front_rb
) {
1065 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1066 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
1070 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1071 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
1074 if (depth_rb
&& stencil_rb
) {
1075 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
1076 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
1077 } else if (depth_rb
) {
1078 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
1079 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
1080 } else if (stencil_rb
) {
1081 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
1082 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
1085 assert(i
<= 2 * max_attachments
);
1087 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1092 drawable
->loaderPrivate
);
1095 } else if (screen
->dri2
.loader
) {
1098 const int max_attachments
= 4;
1099 unsigned *attachments
= calloc(max_attachments
, sizeof(unsigned));
1101 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
1102 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1103 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
1104 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1105 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
1106 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
1107 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
1108 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
1110 assert(i
<= max_attachments
);
1112 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1117 drawable
->loaderPrivate
);
1127 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1129 * This is called from intel_update_renderbuffers(). It is used only if
1130 * either the hardware or the X driver lacks separate stencil support.
1133 * DRI buffers whose attachment point is DRI2BufferStencil or
1134 * DRI2BufferDepthStencil are handled as special cases.
1136 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1137 * that is passed to intel_region_alloc_for_handle().
1139 * \see intel_update_renderbuffers()
1140 * \see intel_region_alloc_for_handle()
1143 intel_process_dri2_buffer_no_separate_stencil(struct intel_context
*intel
,
1144 __DRIdrawable
*drawable
,
1145 __DRIbuffer
*buffer
,
1146 struct intel_renderbuffer
*rb
,
1147 const char *buffer_name
)
1149 assert(!intel
->must_use_separate_stencil
);
1151 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1152 struct intel_renderbuffer
*depth_rb
= NULL
;
1159 rb
->mt
->region
->name
== buffer
->name
)
1162 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1164 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1165 buffer
->name
, buffer
->attachment
,
1166 buffer
->cpp
, buffer
->pitch
);
1169 bool identify_depth_and_stencil
= false;
1170 if (buffer
->attachment
== __DRI_BUFFER_STENCIL
) {
1171 struct intel_renderbuffer
*depth_rb
=
1172 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1173 identify_depth_and_stencil
= depth_rb
&& depth_rb
->mt
;
1176 if (identify_depth_and_stencil
) {
1177 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1178 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
1180 intel_miptree_reference(&rb
->mt
, depth_rb
->mt
);
1182 intel_miptree_release(&rb
->mt
);
1183 struct intel_region
*region
=
1184 intel_region_alloc_for_handle(intel
->intelScreen
,
1188 buffer
->pitch
/ buffer
->cpp
,
1194 rb
->mt
= intel_miptree_create_for_region(intel
,
1198 intel_region_release(®ion
);
1203 if (buffer
->attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
1204 struct intel_renderbuffer
*stencil_rb
=
1205 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1210 /* The rb passed in is the BUFFER_DEPTH attachment, and we need
1211 * to associate this region to BUFFER_STENCIL as well.
1213 intel_miptree_reference(&stencil_rb
->mt
, rb
->mt
);
1218 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1220 * To determine which DRI buffers to request, examine the renderbuffers
1221 * attached to the drawable's framebuffer. Then request the buffers with
1222 * DRI2GetBuffersWithFormat().
1224 * This is called from intel_update_renderbuffers(). It is used when 1) the
1225 * hardware supports separate stencil and 2) the X driver's separate stencil
1226 * support has been verified to work or is still unknown.
1228 * \param drawable Drawable whose buffers are queried.
1229 * \param buffers [out] List of buffers returned by DRI2 query.
1230 * \param buffer_count [out] Number of buffers returned.
1231 * \param attachments [out] List of pairs (attachment_point, bits_per_pixel)
1232 * that were submitted in the DRI2 query. Number of pairs
1233 * is same as buffer_count.
1235 * \see intel_update_renderbuffers()
1236 * \see DRI2GetBuffersWithFormat()
1237 * \see enum intel_dri2_has_hiz
1240 intel_query_dri2_buffers_with_separate_stencil(struct intel_context
*intel
,
1241 __DRIdrawable
*drawable
,
1242 __DRIbuffer
**buffers
,
1243 unsigned **attachments
,
1246 assert(intel
->has_separate_stencil
);
1248 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1249 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1251 const int max_attachments
= 5;
1254 *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
1255 if (!*attachments
) {
1261 struct intel_renderbuffer
*front_rb
;
1262 struct intel_renderbuffer
*back_rb
;
1263 struct intel_renderbuffer
*depth_rb
;
1264 struct intel_renderbuffer
*stencil_rb
;
1266 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1267 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1268 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1269 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1271 if ((intel
->is_front_buffer_rendering
||
1272 intel
->is_front_buffer_reading
||
1273 !back_rb
) && front_rb
) {
1274 (*attachments
)[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1275 (*attachments
)[i
++] = intel_bits_per_pixel(front_rb
);
1279 (*attachments
)[i
++] = __DRI_BUFFER_BACK_LEFT
;
1280 (*attachments
)[i
++] = intel_bits_per_pixel(back_rb
);
1284 * We request a separate stencil buffer, and perhaps a hiz buffer too, even
1285 * if we do not yet know if the X driver supports it. See the comments for
1286 * 'enum intel_dri2_has_hiz'.
1290 (*attachments
)[i
++] = __DRI_BUFFER_DEPTH
;
1291 (*attachments
)[i
++] = intel_bits_per_pixel(depth_rb
);
1293 if (intel
->vtbl
.is_hiz_depth_format(intel
, depth_rb
->Base
.Format
)) {
1294 /* Depth and hiz buffer have same bpp. */
1295 (*attachments
)[i
++] = __DRI_BUFFER_HIZ
;
1296 (*attachments
)[i
++] = intel_bits_per_pixel(depth_rb
);
1301 assert(stencil_rb
->Base
.Format
== MESA_FORMAT_S8
);
1302 (*attachments
)[i
++] = __DRI_BUFFER_STENCIL
;
1303 (*attachments
)[i
++] = intel_bits_per_pixel(stencil_rb
);
1306 assert(i
<= 2 * max_attachments
);
1308 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1311 *attachments
, i
/ 2,
1313 drawable
->loaderPrivate
);
1317 *attachments
= NULL
;
1323 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1325 * This is called from intel_update_renderbuffers(). It is used when 1) the
1326 * hardware supports separate stencil and 2) the X driver's separate stencil
1327 * support has been verified to work or is still unknown.
1330 * DRI buffers whose attachment point is DRI2BufferStencil or DRI2BufferHiz
1331 * are handled as special cases.
1333 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1334 * that is passed to intel_region_alloc_for_handle().
1336 * \see intel_update_renderbuffers()
1337 * \see intel_region_alloc_for_handle()
1338 * \see enum intel_dri2_has_hiz
1341 intel_process_dri2_buffer_with_separate_stencil(struct intel_context
*intel
,
1342 __DRIdrawable
*drawable
,
1343 __DRIbuffer
*buffer
,
1344 struct intel_renderbuffer
*rb
,
1345 const char *buffer_name
)
1347 assert(intel
->has_separate_stencil
);
1348 assert(buffer
->attachment
!= __DRI_BUFFER_DEPTH_STENCIL
);
1353 /* If the renderbuffer's and DRIbuffer's regions match, then continue. */
1354 if ((buffer
->attachment
!= __DRI_BUFFER_HIZ
&&
1357 rb
->mt
->region
->name
== buffer
->name
) ||
1358 (buffer
->attachment
== __DRI_BUFFER_HIZ
&&
1360 rb
->mt
->hiz_region
&&
1361 rb
->mt
->hiz_region
->name
== buffer
->name
)) {
1365 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1367 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1368 buffer
->name
, buffer
->attachment
,
1369 buffer
->cpp
, buffer
->pitch
);
1374 if (buffer
->attachment
== __DRI_BUFFER_STENCIL
) {
1375 /* The stencil buffer has quirky pitch requirements. From Section
1376 * 2.11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
1377 * The pitch must be set to 2x the value computed based on width, as
1378 * the stencil buffer is stored with two rows interleaved.
1380 * To satisfy the pitch requirement, the X driver allocated the region
1381 * with the following dimensions.
1383 buffer_width
= ALIGN(drawable
->w
, 64);
1384 buffer_height
= ALIGN(ALIGN(drawable
->h
, 2) / 2, 64);
1386 buffer_width
= drawable
->w
;
1387 buffer_height
= drawable
->h
;
1390 /* Release the buffer storage now in case we have to return early
1391 * due to region allocation failure.
1393 if (buffer
->attachment
== __DRI_BUFFER_HIZ
) {
1394 intel_region_release(&rb
->mt
->hiz_region
);
1396 intel_miptree_release(&rb
->mt
);
1399 struct intel_region
*region
=
1400 intel_region_alloc_for_handle(intel
->intelScreen
,
1404 buffer
->pitch
/ buffer
->cpp
,
1410 /* Associate buffer with new storage. */
1411 if (buffer
->attachment
== __DRI_BUFFER_HIZ
) {
1412 rb
->mt
->hiz_region
= region
;
1414 rb
->mt
= intel_miptree_create_for_region(intel
,
1418 intel_region_release(®ion
);
1423 * \brief Verify that the X driver supports hiz and separate stencil.
1425 * This implements the cleanup stage of the handshake described in the
1426 * comments for 'enum intel_dri2_has_hiz'.
1428 * This should be called from intel_update_renderbuffers() after 1) the
1429 * DRIdrawable has been queried for its buffers via DRI2GetBuffersWithFormat()
1430 * and 2) the DRM region of each returned DRIbuffer has been assigned to the
1431 * appropriate intel_renderbuffer. Furthermore, this should be called *only*
1432 * when 1) intel_update_renderbuffers() tried to used the X driver's separate
1433 * stencil functionality and 2) it has not yet been determined if the X driver
1434 * supports separate stencil.
1436 * If we determine that the X driver does have support, then we set
1437 * intel_screen.dri2_has_hiz to true and return.
1439 * If we determine that the X driver lacks support, and we requested
1440 * a DRI2BufferDepth and DRI2BufferStencil, then we must remedy the mistake by
1441 * taking the following actions:
1442 * 1. Discard the framebuffer's stencil and depth renderbuffers.
1443 * 2. Create a combined depth/stencil renderbuffer and attach
1444 * it to the framebuffer's depth and stencil attachment points.
1445 * 3. Query the drawable for a new set of buffers, which consists of the
1446 * originally requested set plus DRI2BufferDepthStencil.
1447 * 4. Assign the DRI2BufferDepthStencil's DRM region to the new
1448 * depth/stencil renderbuffer.
1450 * \pre intel->intelScreen->dri2_has_hiz == INTEL_DRI2_HAS_HIZ_UNKNOWN
1452 * \param drawable Drawable whose buffers were queried.
1454 * \param buffers [in/out] As input, the buffer list returned by the
1455 * original DRI2 query. As output, the current buffer
1456 * list, which may have been altered by a new DRI2 query.
1458 * \param attachments [in/out] As input, the attachment list submitted
1459 * in the original DRI2 query. As output, the attachment
1460 * list that was submitted in the DRI2 query that
1461 * obtained the current buffer list, as returned in the
1462 * output parameter \c buffers. (Note: If no new query
1463 * was made, then the list remains unaltered).
1465 * \param count [out] Number of buffers in the current buffer list, as
1466 * returned in the output parameter \c buffers.
1468 * \see enum intel_dri2_has_hiz
1469 * \see struct intel_screen::dri2_has_hiz
1470 * \see intel_update_renderbuffers
1473 intel_verify_dri2_has_hiz(struct intel_context
*intel
,
1474 __DRIdrawable
*drawable
,
1475 __DRIbuffer
**buffers
,
1476 unsigned **attachments
,
1479 assert(intel
->intelScreen
->dri2_has_hiz
== INTEL_DRI2_HAS_HIZ_UNKNOWN
);
1481 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1482 struct intel_renderbuffer
*stencil_rb
=
1483 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
1487 * We requested a DRI2BufferStencil without knowing if the X driver
1488 * supports it. Now, check if X handled the request correctly and clean
1489 * up if it did not. (See comments for 'enum intel_dri2_has_hiz').
1491 struct intel_renderbuffer
*depth_rb
=
1492 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
1493 assert(stencil_rb
->Base
.Format
== MESA_FORMAT_S8
);
1494 assert(depth_rb
&& depth_rb
->Base
.Format
== MESA_FORMAT_X8_Z24
);
1496 if (stencil_rb
->mt
->region
->tiling
== I915_TILING_NONE
) {
1498 * The stencil buffer is actually W tiled. The region's tiling is
1499 * I915_TILING_NONE, however, because the GTT is incapable of W
1502 intel
->intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_TRUE
;
1506 * Oops... the screen doesn't support separate stencil. Discard the
1507 * separate depth and stencil buffers and replace them with
1508 * a combined depth/stencil buffer. Discard the hiz buffer too.
1510 intel
->intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_FALSE
;
1511 if (intel
->must_use_separate_stencil
) {
1512 _mesa_problem(&intel
->ctx
,
1513 "intel_context requires separate stencil, but the "
1514 "DRIscreen does not support it. You may need to "
1515 "upgrade the Intel X driver to 2.16.0");
1519 /* 1. Discard depth and stencil renderbuffers. */
1520 _mesa_remove_renderbuffer(fb
, BUFFER_DEPTH
);
1522 _mesa_remove_renderbuffer(fb
, BUFFER_STENCIL
);
1525 /* 2. Create new depth/stencil renderbuffer. */
1526 struct intel_renderbuffer
*depth_stencil_rb
=
1527 intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
1528 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depth_stencil_rb
->Base
);
1529 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depth_stencil_rb
->Base
);
1531 /* 3. Append DRI2BufferDepthStencil to attachment list. */
1532 int old_count
= *count
;
1533 unsigned int *old_attachments
= *attachments
;
1534 *count
= old_count
+ 1;
1535 *attachments
= malloc(2 * (*count
) * sizeof(unsigned));
1536 memcpy(*attachments
, old_attachments
, 2 * old_count
* sizeof(unsigned));
1537 free(old_attachments
);
1538 (*attachments
)[2 * old_count
+ 0] = __DRI_BUFFER_DEPTH_STENCIL
;
1539 (*attachments
)[2 * old_count
+ 1] = intel_bits_per_pixel(depth_stencil_rb
);
1541 /* 4. Request new set of DRI2 attachments. */
1542 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
1543 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1549 drawable
->loaderPrivate
);
1554 * I don't know how to recover from the failure assertion below.
1555 * Rather than fail gradually and unexpectedly, we should just die
1558 assert(*count
== old_count
+ 1);
1560 /* 5. Assign the DRI buffer's DRM region to the its renderbuffers. */
1561 __DRIbuffer
*depth_stencil_buffer
= NULL
;
1562 for (int i
= 0; i
< *count
; ++i
) {
1563 if ((*buffers
)[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
1564 depth_stencil_buffer
= &(*buffers
)[i
];
1568 struct intel_region
*region
=
1569 intel_region_alloc_for_handle(intel
->intelScreen
,
1570 depth_stencil_buffer
->cpp
,
1573 depth_stencil_buffer
->pitch
1574 / depth_stencil_buffer
->cpp
,
1575 depth_stencil_buffer
->name
,
1576 "dri2 depth / stencil buffer");
1580 struct intel_mipmap_tree
*mt
=
1581 intel_miptree_create_for_region(intel
,
1583 depth_stencil_rb
->Base
.Format
,
1585 intel_region_release(®ion
);
1589 intel_miptree_reference(&intel_get_renderbuffer(fb
, BUFFER_DEPTH
)->mt
, mt
);
1590 intel_miptree_reference(&intel_get_renderbuffer(fb
, BUFFER_STENCIL
)->mt
, mt
);
1591 intel_miptree_release(&mt
);
1595 if (intel_framebuffer_has_hiz(fb
)) {
1597 * In the future, the driver may advertise a GL config with hiz
1598 * compatible depth bits and 0 stencil bits (for example, when the
1599 * driver gains support for float32 depth buffers). When that day comes,
1600 * here we need to verify that the X driver does in fact support hiz and
1601 * clean up if it doesn't.
1603 * Presently, however, no verification or clean up is necessary, and
1604 * execution should not reach here. If the framebuffer still has a hiz
1605 * region, then we have already set dri2_has_hiz to true after
1606 * confirming above that the stencil buffer is W tiled.