dri/nouveau: add GLX_MESA_query_renderer support
authorEmil Velikov <emil.l.velikov@gmail.com>
Fri, 14 Feb 2014 23:34:47 +0000 (23:34 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 15 Aug 2014 16:35:37 +0000 (17:35 +0100)
 - Create nouveau_{vendor,get_renderer}_string helpers.
 - Set correct max_gl*version.
 - Query the device PCIID via libdrm_nouveau/nouveau_getparam.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
src/mesa/drivers/dri/nouveau/nouveau_driver.c
src/mesa/drivers/dri/nouveau/nouveau_driver.h
src/mesa/drivers/dri/nouveau/nouveau_screen.c

index b2887f83e6c07e7194616188193a2f501b71e90d..c1f867241614f51aa704917d53217c7dac34fbda 100644 (file)
 
 #include "drivers/common/meta.h"
 
-static const GLubyte *
-nouveau_get_string(struct gl_context *ctx, GLenum name)
+const char const *nouveau_vendor_string = "Nouveau";
+
+const char *
+nouveau_get_renderer_string(unsigned chipset)
 {
-       static char buffer[128];
        char hardware_name[32];
+       static char buffer[128];
+
+       snprintf(hardware_name, sizeof(hardware_name), "nv%02X", chipset);
+       driGetRendererString(buffer, hardware_name, 0);
 
+       return buffer;
+}
+
+static const GLubyte *
+nouveau_get_string(struct gl_context *ctx, GLenum name)
+{
        switch (name) {
                case GL_VENDOR:
-                       return (GLubyte *)"Nouveau";
+                       return (GLubyte *)nouveau_vendor_string;
 
                case GL_RENDERER:
-                       sprintf(hardware_name, "nv%02X", context_chipset(ctx));
-                       driGetRendererString(buffer, hardware_name, 0);
-
-                       return (GLubyte *)buffer;
+                       return (GLubyte *)nouveau_get_renderer_string(context_chipset(ctx));
                default:
                        return NULL;
        }
index 8b46e51cbaf3995aa4598070995d1fe8ee7798b1..a4273a554bd229b31ee5c7cd2cb92c8cc0682f7f 100644 (file)
@@ -69,6 +69,11 @@ struct nouveau_driver {
 #define nouveau_error(format, ...) \
        fprintf(stderr, "%s: " format, __func__, ## __VA_ARGS__)
 
+extern const char const *nouveau_vendor_string;
+
+const char *
+nouveau_get_renderer_string(unsigned chipset);
+
 void
 nouveau_clear(struct gl_context *ctx, GLbitfield buffers);
 
index aec2f729d69336d0d1c728205ae2269658772d20..766ae6f2f79e76767dc2d98fdd7a8e7d78eb876e 100644 (file)
@@ -24,6 +24,8 @@
  *
  */
 
+#include <xf86drm.h>
+#include <nouveau_drm.h>
 #include "nouveau_driver.h"
 #include "nouveau_context.h"
 #include "nouveau_fbo.h"
@@ -104,28 +106,22 @@ nouveau_init_screen2(__DRIscreen *dri_screen)
        switch (screen->device->chipset & 0xf0) {
        case 0x00:
                screen->driver = &nv04_driver;
+               dri_screen->max_gl_compat_version = 12;
                break;
        case 0x10:
                screen->driver = &nv10_driver;
+               dri_screen->max_gl_compat_version = 12;
+               dri_screen->max_gl_es1_version = 10;
                break;
        case 0x20:
                screen->driver = &nv20_driver;
+               dri_screen->max_gl_compat_version = 13;
+               dri_screen->max_gl_es1_version = 10;
                break;
        default:
                assert(0);
        }
 
-       /* Compat version validation will occur at context init after
-        * _mesa_compute_version().
-        */
-       dri_screen->max_gl_compat_version = 15;
-
-       /* NV10 and NV20 can support OpenGL ES 1.0 only.  Older chips
-        * cannot do even that.
-        */
-       if ((screen->device->chipset & 0xf0) != 0x00)
-               dri_screen->max_gl_es1_version = 10;
-
        dri_screen->driverPrivate = screen;
        dri_screen->extensions = nouveau_screen_extensions;
        screen->dri_screen = dri_screen;
@@ -141,6 +137,69 @@ fail:
 
 }
 
+static int
+nouveau_query_renderer_integer(__DRIscreen *psp, int param,
+                              unsigned int *value)
+{
+       const struct nouveau_screen *const screen =
+               (struct nouveau_screen *) psp->driverPrivate;
+
+       switch (param) {
+       case __DRI2_RENDERER_VENDOR_ID:
+               value[0] = 0x10de;
+               return 0;
+       case __DRI2_RENDERER_DEVICE_ID: {
+               uint64_t device_id;
+
+               if (nouveau_getparam(screen->device,
+                                    NOUVEAU_GETPARAM_PCI_DEVICE,
+                                    &device_id)) {
+                       nouveau_error("Error retrieving the device PCIID.\n");
+                       device_id = -1;
+               }
+               value[0] = (unsigned int) device_id;
+               return 0;
+       }
+       case __DRI2_RENDERER_ACCELERATED:
+               value[0] = 1;
+               return 0;
+       case __DRI2_RENDERER_VIDEO_MEMORY:
+               /* XXX: return vram_size or vram_limit ? */
+               value[0] = screen->device->vram_size >> 20;
+               return 0;
+       case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
+               value[0] = 0;
+               return 0;
+       default:
+               return driQueryRendererIntegerCommon(psp, param, value);
+       }
+}
+
+static int
+nouveau_query_renderer_string(__DRIscreen *psp, int param, const char **value)
+{
+       const struct nouveau_screen *const screen =
+               (struct nouveau_screen *) psp->driverPrivate;
+
+       switch (param) {
+       case __DRI2_RENDERER_VENDOR_ID:
+               value[0] = nouveau_vendor_string;
+               return 0;
+       case __DRI2_RENDERER_DEVICE_ID:
+               value[0] = nouveau_get_renderer_string(screen->device->chipset);
+               return 0;
+       default:
+               return -1;
+   }
+}
+
+static const __DRI2rendererQueryExtension nouveau_renderer_query_extension = {
+       .base = { __DRI2_RENDERER_QUERY, 1 },
+
+       .queryInteger        = nouveau_query_renderer_integer,
+       .queryString         = nouveau_query_renderer_string
+};
+
 static void
 nouveau_destroy_screen(__DRIscreen *dri_screen)
 {
@@ -244,6 +303,7 @@ static const struct __DRItexBufferExtensionRec nouveau_texbuffer_extension = {
 static const __DRIextension *nouveau_screen_extensions[] = {
     &nouveau_flush_extension.base,
     &nouveau_texbuffer_extension.base,
+    &nouveau_renderer_query_extension.base,
     &dri2ConfigQueryExtension.base,
     NULL
 };