intel: Request DRI2 buffers for separate stencil and hiz
[profile/ivi/mesa.git] / src / mesa / drivers / dri / intel / intel_screen.h
1 /**************************************************************************
2  * 
3  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  * 
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:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
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.
25  * 
26  **************************************************************************/
27
28 #ifndef _INTEL_INIT_H_
29 #define _INTEL_INIT_H_
30
31 #include <sys/time.h>
32 #include "dri_util.h"
33 #include "intel_bufmgr.h"
34 #include "i915_drm.h"
35 #include "xmlconfig.h"
36
37 /**
38  * \brief Does X driver support DRI2BufferHiz and DRI2BufferStencil?
39  *
40  * (Here, "X driver" referes to the DDX driver, xf86-video-intel).
41  *
42  * The DRI2 protocol does not allow us to query the X driver's version nor
43  * query for a list of buffer formats that the driver supports. So, to
44  * determine if the X driver supports DRI2BufferHiz and DRI2BufferStencil we
45  * must resort to a handshake.
46  *
47  * If the hardware lacks support for separate stencil (and consequently, lacks
48  * support for hiz also), then the X driver's separate stencil and hiz support
49  * is irrelevant and the handshake never occurs.
50  *
51  * Complications
52  * -------------
53  * The handshake is complicated by a bug in xf86-video-intel 2.15. Even though
54  * that version of the X driver did not supppot requests for DRI2BufferHiz or
55  * DRI2BufferStencil, if requested one it still allocated and returned one.
56  * The returned buffer, however, was incorrectly X tiled.
57  *
58  * How the handshake works
59  * -----------------------
60  * Initially, intel_screen.dri2_has_hiz is set to unknown. The first time the
61  * user requests a depth and stencil buffer, intelCreateBuffers() creates a
62  * framebuffer with separate depth and stencil attachments (with formats
63  * x8_z24 and s8).
64  *
65  * Eventually, intel_update_renderbuffers() makes a DRI2 request for
66  * DRI2BufferStencil and DRI2BufferHiz. If the returned buffers are Y tiled,
67  * then we joyfully set intel_screen.dri2_has_hiz to true and continue as if
68  * nothing happend.
69  *
70  * If the buffers are X tiled, however, the handshake has failed and we must
71  * clean up.
72  *    1. Angrily set intel_screen.dri2_has_hiz to false.
73  *    2. Discard the framebuffer's depth and stencil attachments.
74  *    3. Attach a packed depth/stencil buffer to the framebuffer (with format
75  *       s8_z24).
76  *    4. Make a DRI2 request for the new buffer, using attachment type
77  *       DRI2BufferDepthStencil).
78  *
79  * Future Considerations
80  * ---------------------
81  * On a sunny day in the far future, when we are certain that no one has an
82  * xf86-video-intel installed without hiz and separate stencil support, then
83  * this enumerant and the handshake should die.
84  */
85 enum intel_dri2_has_hiz {
86    INTEL_DRI2_HAS_HIZ_UNKNOWN,
87    INTEL_DRI2_HAS_HIZ_TRUE,
88    INTEL_DRI2_HAS_HIZ_FALSE,
89 };
90
91 struct intel_screen
92 {
93    int deviceID;
94    int gen;
95
96    int logTextureGranularity;
97
98    __DRIscreen *driScrnPriv;
99
100    GLboolean no_hw;
101    GLuint relaxed_relocations;
102
103    /*
104     * The hardware hiz and separate stencil fields are needed in intel_screen,
105     * rather than solely in intel_context, because glXCreatePbuffer and
106     * glXCreatePixmap are not passed a GLXContext.
107     */
108    GLboolean hw_has_separate_stencil;
109    GLboolean hw_must_use_separate_stencil;
110    GLboolean hw_has_hiz;
111    enum intel_dri2_has_hiz dri2_has_hiz;
112
113    GLboolean no_vbo;
114    dri_bufmgr *bufmgr;
115    struct _mesa_HashTable *named_regions;
116
117    /**
118    * Configuration cache with default values for all contexts
119    */
120    driOptionCache optionCache;
121 };
122
123 extern GLboolean intelMapScreenRegions(__DRIscreen * sPriv);
124
125 extern void intelDestroyContext(__DRIcontext * driContextPriv);
126
127 extern GLboolean intelUnbindContext(__DRIcontext * driContextPriv);
128
129 extern GLboolean
130 intelMakeCurrent(__DRIcontext * driContextPriv,
131                  __DRIdrawable * driDrawPriv,
132                  __DRIdrawable * driReadPriv);
133
134 #endif