2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <nouveau_drm.h>
29 #include "nouveau_driver.h"
30 #include "nouveau_context.h"
31 #include "nouveau_fbo.h"
32 #include "nouveau_texture.h"
33 #include "nv04_driver.h"
34 #include "nv10_driver.h"
35 #include "nv20_driver.h"
37 #include "main/framebuffer.h"
38 #include "main/fbobject.h"
39 #include "main/renderbuffer.h"
40 #include "swrast/s_renderbuffer.h"
42 static const __DRIextension
*nouveau_screen_extensions
[];
45 nouveau_destroy_screen(__DRIscreen
*dri_screen
);
47 static const __DRIconfig
**
48 nouveau_get_configs(void)
50 __DRIconfig
**configs
= NULL
;
53 const uint8_t depth_bits
[] = { 0, 16, 24, 24 };
54 const uint8_t stencil_bits
[] = { 0, 0, 0, 8 };
55 const uint8_t msaa_samples
[] = { 0 };
57 static const mesa_format formats
[3] = {
58 MESA_FORMAT_B5G6R5_UNORM
,
59 MESA_FORMAT_B8G8R8A8_UNORM
,
60 MESA_FORMAT_B8G8R8X8_UNORM
,
63 const GLenum back_buffer_modes
[] = {
64 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
67 for (i
= 0; i
< Elements(formats
); i
++) {
70 config
= driCreateConfigs(formats
[i
],
71 depth_bits
, stencil_bits
,
74 Elements(back_buffer_modes
),
76 Elements(msaa_samples
),
80 configs
= driConcatConfigs(configs
, config
);
83 return (const __DRIconfig
**)configs
;
86 static const __DRIconfig
**
87 nouveau_init_screen2(__DRIscreen
*dri_screen
)
89 const __DRIconfig
**configs
;
90 struct nouveau_screen
*screen
;
93 /* Allocate the screen. */
94 screen
= CALLOC_STRUCT(nouveau_screen
);
98 dri_screen
->driverPrivate
= screen
;
100 /* Open the DRM device. */
101 ret
= nouveau_device_wrap(dri_screen
->fd
, 0, &screen
->device
);
103 nouveau_error("Error opening the DRM device.\n");
107 /* Choose the card specific function pointers. */
108 switch (screen
->device
->chipset
& 0xf0) {
110 screen
->driver
= &nv04_driver
;
111 dri_screen
->max_gl_compat_version
= 12;
114 screen
->driver
= &nv10_driver
;
115 dri_screen
->max_gl_compat_version
= 12;
116 dri_screen
->max_gl_es1_version
= 10;
119 screen
->driver
= &nv20_driver
;
120 dri_screen
->max_gl_compat_version
= 13;
121 dri_screen
->max_gl_es1_version
= 10;
124 nouveau_error("Unknown chipset: %02X\n",
125 screen
->device
->chipset
);
129 dri_screen
->extensions
= nouveau_screen_extensions
;
130 screen
->dri_screen
= dri_screen
;
132 configs
= nouveau_get_configs();
138 nouveau_destroy_screen(dri_screen
);
144 nouveau_query_renderer_integer(__DRIscreen
*psp
, int param
,
147 const struct nouveau_screen
*const screen
=
148 (struct nouveau_screen
*) psp
->driverPrivate
;
151 case __DRI2_RENDERER_VENDOR_ID
:
154 case __DRI2_RENDERER_DEVICE_ID
: {
157 if (nouveau_getparam(screen
->device
,
158 NOUVEAU_GETPARAM_PCI_DEVICE
,
160 nouveau_error("Error retrieving the device PCIID.\n");
163 value
[0] = (unsigned int) device_id
;
166 case __DRI2_RENDERER_ACCELERATED
:
169 case __DRI2_RENDERER_VIDEO_MEMORY
:
170 /* XXX: return vram_size or vram_limit ? */
171 value
[0] = screen
->device
->vram_size
>> 20;
173 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
177 return driQueryRendererIntegerCommon(psp
, param
, value
);
182 nouveau_query_renderer_string(__DRIscreen
*psp
, int param
, const char **value
)
184 const struct nouveau_screen
*const screen
=
185 (struct nouveau_screen
*) psp
->driverPrivate
;
188 case __DRI2_RENDERER_VENDOR_ID
:
189 value
[0] = nouveau_vendor_string
;
191 case __DRI2_RENDERER_DEVICE_ID
:
192 value
[0] = nouveau_get_renderer_string(screen
->device
->chipset
);
199 static const __DRI2rendererQueryExtension nouveau_renderer_query_extension
= {
200 .base
= { __DRI2_RENDERER_QUERY
, 1 },
202 .queryInteger
= nouveau_query_renderer_integer
,
203 .queryString
= nouveau_query_renderer_string
207 nouveau_destroy_screen(__DRIscreen
*dri_screen
)
209 struct nouveau_screen
*screen
= dri_screen
->driverPrivate
;
214 nouveau_device_del(&screen
->device
);
217 dri_screen
->driverPrivate
= NULL
;
221 nouveau_create_buffer(__DRIscreen
*dri_screen
,
222 __DRIdrawable
*drawable
,
223 const struct gl_config
*visual
,
226 struct gl_renderbuffer
*rb
;
227 struct gl_framebuffer
*fb
;
231 return GL_FALSE
; /* not implemented */
233 if (visual
->redBits
== 5)
234 color_format
= GL_RGB5
;
235 else if (visual
->alphaBits
== 0)
236 color_format
= GL_RGB8
;
238 color_format
= GL_RGBA8
;
240 fb
= nouveau_framebuffer_dri_new(visual
);
245 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
246 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, rb
);
249 if (visual
->doubleBufferMode
) {
250 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
251 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, rb
);
254 /* Depth/stencil buffer. */
255 if (visual
->depthBits
== 24 && visual
->stencilBits
== 8) {
256 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH24_STENCIL8_EXT
, drawable
);
257 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
258 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
260 } else if (visual
->depthBits
== 24) {
261 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT24
, drawable
);
262 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
264 } else if (visual
->depthBits
== 16) {
265 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT16
, drawable
);
266 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
269 /* Software renderbuffers. */
270 _swrast_add_soft_renderbuffers(fb
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
271 visual
->accumRedBits
> 0,
274 drawable
->driverPrivate
= fb
;
280 nouveau_destroy_buffer(__DRIdrawable
*drawable
)
282 _mesa_reference_framebuffer(
283 (struct gl_framebuffer
**)&drawable
->driverPrivate
, NULL
);
287 nouveau_drawable_flush(__DRIdrawable
*draw
)
291 static const struct __DRI2flushExtensionRec nouveau_flush_extension
= {
292 .base
= { __DRI2_FLUSH
, 3 },
294 .flush
= nouveau_drawable_flush
,
295 .invalidate
= dri2InvalidateDrawable
,
298 static const struct __DRItexBufferExtensionRec nouveau_texbuffer_extension
= {
299 .base
= { __DRI_TEX_BUFFER
, 3 },
301 .setTexBuffer
= NULL
,
302 .setTexBuffer2
= nouveau_set_texbuffer
,
303 .releaseTexBuffer
= NULL
,
306 static const __DRIextension
*nouveau_screen_extensions
[] = {
307 &nouveau_flush_extension
.base
,
308 &nouveau_texbuffer_extension
.base
,
309 &nouveau_renderer_query_extension
.base
,
310 &dri2ConfigQueryExtension
.base
,
314 const struct __DriverAPIRec nouveau_driver_api
= {
315 .InitScreen
= nouveau_init_screen2
,
316 .DestroyScreen
= nouveau_destroy_screen
,
317 .CreateBuffer
= nouveau_create_buffer
,
318 .DestroyBuffer
= nouveau_destroy_buffer
,
319 .CreateContext
= nouveau_context_create
,
320 .DestroyContext
= nouveau_context_destroy
,
321 .MakeCurrent
= nouveau_context_make_current
,
322 .UnbindContext
= nouveau_context_unbind
,
325 static const struct __DRIDriverVtableExtensionRec nouveau_vtable
= {
326 .base
= { __DRI_DRIVER_VTABLE
, 1 },
327 .vtable
= &nouveau_driver_api
,
330 /* This is the table of extensions that the loader will dlsym() for. */
331 static const __DRIextension
*nouveau_driver_extensions
[] = {
332 &driCoreExtension
.base
,
333 &driDRI2Extension
.base
,
334 &nouveau_vtable
.base
,
338 PUBLIC
const __DRIextension
**__driDriverGetExtensions_nouveau_vieux(void)
340 globalDriverAPI
= &nouveau_driver_api
;
342 return nouveau_driver_extensions
;