1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
30 #include "framebuffer.h"
31 #include "renderbuffer.h"
33 #include "nouveau_context.h"
34 #include "nouveau_screen.h"
35 #include "nouveau_object.h"
36 #include "nouveau_span.h"
37 #include "nouveau_msg.h"
42 #include "drirenderbuffer.h"
44 #include "GL/internal/dri_interface.h"
48 PUBLIC
const char __driConfigOptions
[] =
50 DRI_CONF_SECTION_DEBUG
51 DRI_CONF_NO_RAST(false)
54 static const GLuint __driNConfigOptions
= 1;
56 extern const struct dri_extension common_extensions
[];
57 extern const struct dri_extension nv10_extensions
[];
58 extern const struct dri_extension nv20_extensions
[];
59 extern const struct dri_extension nv30_extensions
[];
60 extern const struct dri_extension nv40_extensions
[];
61 extern const struct dri_extension nv50_extensions
[];
63 static nouveauScreenPtr
nouveauCreateScreen(__DRIscreenPrivate
*sPriv
)
65 nouveauScreenPtr screen
;
66 NOUVEAUDRIPtr dri_priv
=(NOUVEAUDRIPtr
)sPriv
->pDevPriv
;
69 screen
= (nouveauScreenPtr
) CALLOC( sizeof(*screen
) );
71 __driUtilMessage("%s: Could not allocate memory for screen structure",__FUNCTION__
);
75 screen
->card
=nouveau_card_lookup(dri_priv
->device_id
);
77 __driUtilMessage("%s: Unknown card type 0x%04x:0x%04x\n",
78 __func__
, dri_priv
->device_id
>> 16, dri_priv
->device_id
& 0xFFFF);
83 /* parse information in __driConfigOptions */
84 driParseOptionInfo (&screen
->optionCache
,__driConfigOptions
, __driNConfigOptions
);
86 screen
->fbFormat
= dri_priv
->bpp
/ 8;
87 screen
->frontOffset
= dri_priv
->front_offset
;
88 screen
->frontPitch
= dri_priv
->front_pitch
;
89 screen
->backOffset
= dri_priv
->back_offset
;
90 screen
->backPitch
= dri_priv
->back_pitch
;
91 screen
->depthOffset
= dri_priv
->depth_offset
;
92 screen
->depthPitch
= dri_priv
->depth_pitch
;
94 screen
->driScreen
= sPriv
;
99 nouveauDestroyScreen(__DRIscreenPrivate
*sPriv
)
101 nouveauScreenPtr screen
= (nouveauScreenPtr
)sPriv
->private;
105 /* free all option information */
106 driDestroyOptionInfo (&screen
->optionCache
);
109 sPriv
->private = NULL
;
112 static GLboolean
nouveauInitDriver(__DRIscreenPrivate
*sPriv
)
114 sPriv
->private = (void *) nouveauCreateScreen( sPriv
);
115 if ( !sPriv
->private ) {
116 nouveauDestroyScreen( sPriv
);
124 * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
126 * \todo This function (and its interface) will need to be updated to support
130 nouveauCreateBuffer(__DRIscreenPrivate
*driScrnPriv
,
131 __DRIdrawablePrivate
*driDrawPriv
,
132 const __GLcontextModes
*mesaVis
,
135 nouveauScreenPtr screen
= (nouveauScreenPtr
) driScrnPriv
->private;
136 nouveau_renderbuffer_t
*nrb
;
137 struct gl_framebuffer
*fb
;
138 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
139 const GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
140 mesaVis
->depthBits
!= 24);
141 GLenum color_format
= screen
->fbFormat
== 4 ? GL_RGBA8
: GL_RGB5
;
144 return GL_FALSE
; /* not implemented */
146 fb
= _mesa_create_framebuffer(mesaVis
);
151 nrb
= nouveau_renderbuffer_new(color_format
);
152 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &nrb
->mesa
);
154 if (mesaVis
->doubleBufferMode
) {
155 nrb
= nouveau_renderbuffer_new(color_format
);
156 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &nrb
->mesa
);
159 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
160 nrb
= nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT
);
161 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
162 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &nrb
->mesa
);
164 if (mesaVis
->depthBits
== 24) {
165 nrb
= nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24
);
166 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
168 if (mesaVis
->depthBits
== 16) {
169 nrb
= nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16
);
170 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
173 _mesa_add_soft_renderbuffers(fb
,
174 GL_FALSE
, /* color */
175 GL_FALSE
, /* depth */
178 GL_FALSE
, /* alpha */
181 driDrawPriv
->driverPrivate
= (void *) fb
;
182 return (driDrawPriv
->driverPrivate
!= NULL
);
187 nouveauDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
189 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
193 nouveauGetSwapInfo(__DRIdrawablePrivate
*dpriv
, __DRIswapInfo
*sInfo
)
198 static __DRIconfig
**
199 nouveauFillInModes( __DRIscreenPrivate
*psp
,
200 unsigned pixel_bits
, unsigned depth_bits
,
201 unsigned stencil_bits
, GLboolean have_back_buffer
)
203 unsigned depth_buffer_factor
;
204 unsigned back_buffer_factor
;
206 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
207 * support pageflipping at all.
209 static const GLenum back_buffer_modes
[] = {
210 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
213 u_int8_t depth_bits_array
[4] = { 0, 16, 24, 24 };
214 u_int8_t stencil_bits_array
[4] = { 0, 0, 0, 8 };
216 depth_buffer_factor
= 4;
217 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
219 if (pixel_bits
== 16)
220 return driCreateConfigs(GL_RGB
,
221 GL_UNSIGNED_SHORT_5_6_5
,
228 return driCreateConfigs(GL_RGBA
,
229 GL_UNSIGNED_INT_8_8_8_8_REV
,
239 * This is the driver specific part of the createNewScreen entry point.
241 * \todo maybe fold this into intelInitDriver
243 * \return the __GLcontextModes supported by this driver
245 static const __DRIconfig
**
246 nouveauInitScreen(__DRIscreenPrivate
*psp
)
248 static const __DRIversion ddx_expected
= { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL
};
249 static const __DRIversion dri_expected
= { 4, 0, 0 };
250 static const __DRIversion drm_expected
= { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL
};
251 NOUVEAUDRIPtr dri_priv
= (NOUVEAUDRIPtr
)psp
->pDevPriv
;
253 WARN_ONCE("\nThis driver is not currently maintained\n\n"
254 "Current work on 3D is in the gallium-0.1 branch of:\n"
255 " git://anongit.freedesktop.org/git/nouveau/mesa\n");
257 #if NOUVEAU_DRM_HEADER_PATCHLEVEL != 10
258 #error nouveau_drm.h version does not match expected version
261 if (!driCheckDriDdxDrmVersions2("nouveau",
262 &psp
->dri_version
, & dri_expected
,
263 &psp
->ddx_version
, & ddx_expected
,
264 &psp
->drm_version
, & drm_expected
))
267 // temporary lock step versioning
268 if (drm_expected
.patch
!= psp
->drm_version
.patch
) {
269 __driUtilMessage("%s: wrong DRM version, expected %d, got %d\n",
271 drm_expected
.patch
, psp
->drm_version
.patch
);
275 /* Calling driInitExtensions here, with a NULL context
276 * pointer, does not actually enable the extensions. It just
277 * makes sure that all the dispatch offsets for all the
278 * extensions that *might* be enables are known. This is
279 * needed because the dispatch offsets need to be known when
280 * _mesa_context_create is called, but we can't enable the
281 * extensions until we have a context pointer.
283 * Hello chicken. Hello egg. How are you two today?
285 driInitExtensions( NULL
, common_extensions
, GL_FALSE
);
286 driInitExtensions( NULL
, nv10_extensions
, GL_FALSE
);
287 driInitExtensions( NULL
, nv10_extensions
, GL_FALSE
);
288 driInitExtensions( NULL
, nv30_extensions
, GL_FALSE
);
289 driInitExtensions( NULL
, nv40_extensions
, GL_FALSE
);
290 driInitExtensions( NULL
, nv50_extensions
, GL_FALSE
);
292 if (!nouveauInitDriver(psp
))
295 return (const __DRIconfig
**)
296 nouveauFillInModes(psp
,
298 (dri_priv
->bpp
== 16) ? 16 : 24,
299 (dri_priv
->bpp
== 16) ? 0 : 8,
303 const struct __DriverAPIRec driDriverAPI
= {
304 .InitScreen
= nouveauInitScreen
,
305 .DestroyScreen
= nouveauDestroyScreen
,
306 .CreateContext
= nouveauCreateContext
,
307 .DestroyContext
= nouveauDestroyContext
,
308 .CreateBuffer
= nouveauCreateBuffer
,
309 .DestroyBuffer
= nouveauDestroyBuffer
,
310 .SwapBuffers
= nouveauSwapBuffers
,
311 .MakeCurrent
= nouveauMakeCurrent
,
312 .UnbindContext
= nouveauUnbindContext
,
313 .GetSwapInfo
= nouveauGetSwapInfo
,
314 .GetDrawableMSC
= driDrawableGetMSC32
,
315 .WaitForMSC
= driWaitForMSC32
,
317 .SwapBuffersMSC
= NULL
,
318 .CopySubBuffer
= nouveauCopySubBuffer
321 const __DRIextension
*__driDriverExtensions
[] = {
322 &driCoreExtension
.base
,
323 &driLegacyExtension
.base
,