dri/radeon: add GLX_MESA_query_renderer support
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 20 Feb 2014 01:07:35 +0000 (01:07 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 15 Aug 2014 16:35:38 +0000 (17:35 +0100)
 - Create radeon{Vendor,GetRenderer}String helpers.
 - Drop __DRI2_RENDERER_PREFERRED_PROFILE case.
 - Cleanup return statements.

To be used by the upcomming GLX_MESA_query_renderer implementation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
src/mesa/drivers/dri/radeon/radeon_common_context.c
src/mesa/drivers/dri/radeon/radeon_common_context.h
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/dri/radeon/radeon_screen.h

index 353ecf5e243025d58276b916c6232eb4a1bef4bf..06b606e8ac87d944a0803fdcbc22a4288c3f4891 100644 (file)
@@ -70,39 +70,47 @@ static const char* get_chip_family_name(int chip_family)
        }
 }
 
+const char const *radeonVendorString = "Mesa Project";
 
-/* Return various strings for glGetString().
+/* Return complete renderer string.
  */
-static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name)
+const char *radeonGetRendererString(radeonScreenPtr radeonScreen)
 {
-       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        static char buffer[128];
+       char hardwarename[32];
 
-       switch (name) {
-       case GL_VENDOR:
-               return (GLubyte *) "Mesa Project";
+       GLuint agp_mode = (radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
+               radeonScreen->AGPMode;
 
-       case GL_RENDERER:
-       {
-               char hardwarename[32];
-               GLuint agp_mode = (radeon->radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
-                       radeon->radeonScreen->AGPMode;
-
-               sprintf(hardwarename, "%s (%s %04X)",
+       snprintf(hardwarename, sizeof(hardwarename), "%s (%s %04X)",
 #if defined(RADEON_R100)
-                       "R100",
+               "R100",
 #elif defined(RADEON_R200)
-                       "R200",
+               "R200",
 #endif
-                       get_chip_family_name(radeon->radeonScreen->chip_family),
-                       radeon->radeonScreen->device_id);
+               get_chip_family_name(radeonScreen->chip_family),
+               radeonScreen->device_id);
 
-               driGetRendererString(buffer, hardwarename, agp_mode);
+       driGetRendererString(buffer, hardwarename, agp_mode);
 
-               strcat(buffer, " DRI2");
+       strcat(buffer, " DRI2");
 
-               return (GLubyte *) buffer;
-       }
+       return buffer;
+}
+
+
+/* Return various strings for glGetString().
+ */
+static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name)
+{
+       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
+
+       switch (name) {
+       case GL_VENDOR:
+               return (GLubyte *) radeonVendorString;
+
+       case GL_RENDERER:
+               return (GLubyte *) radeonGetRendererString(radeon->radeonScreen);
 
        default:
                return NULL;
index ac3e7b529b2c9d69ae90dd7ba1c7d06dc4170c51..2a95d61d6647dc7625d4d8ec5b60df410f3ac94a 100644 (file)
@@ -515,6 +515,10 @@ static inline __DRIdrawable* radeon_get_readable(radeonContextPtr radeon)
        return radeon->dri.context->driReadablePriv;
 }
 
+extern const char const *radeonVendorString;
+
+const char *radeonGetRendererString(radeonScreenPtr radeonScreen);
+
 GLboolean radeonInitContext(radeonContextPtr radeon,
                             gl_api api,
                            struct dd_function_table* functions,
index fe72b775228339a6047c3dc9545ac4d6e9b9e396..9a6fbbdb0511f7efc041bfbc07aa1255fcbcc0cd 100644 (file)
@@ -481,6 +481,73 @@ static int radeon_set_screen_flags(radeonScreenPtr screen, int device_id)
    return 0;
 }
 
+static int
+radeonQueryRendererInteger(__DRIscreen *psp, int param,
+                              unsigned int *value)
+{
+   radeonScreenPtr screen = (radeonScreenPtr)psp->driverPrivate;
+
+   switch (param) {
+   case __DRI2_RENDERER_VENDOR_ID:
+      value[0] = 0x1002;
+      return 0;
+   case __DRI2_RENDERER_DEVICE_ID:
+      value[0] = screen->device_id;
+      return 0;
+   case __DRI2_RENDERER_ACCELERATED:
+      value[0] = 1;
+      return 0;
+   case __DRI2_RENDERER_VIDEO_MEMORY: {
+      struct drm_radeon_gem_info gem_info;
+      int retval;
+      memset(&gem_info, 0, sizeof(gem_info));
+
+      /* Get GEM info. */
+      retval = drmCommandWriteRead(psp->fd, DRM_RADEON_GEM_INFO, &gem_info,
+                                  sizeof(gem_info));
+
+      if (retval) {
+         fprintf(stderr, "radeon: Failed to get MM info, error number %d\n",
+                retval);
+         return -1;
+
+      }
+      /* XXX: Do we want to return vram_size or vram_visible ? */
+      value[0] = gem_info.vram_size >> 20;
+      return 0;
+   }
+   case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
+      value[0] = 0;
+      return 0;
+   default:
+      return driQueryRendererIntegerCommon(psp, param, value);
+   }
+}
+
+static int
+radeonQueryRendererString(__DRIscreen *psp, int param, const char **value)
+{
+   radeonScreenPtr screen = (radeonScreenPtr)psp->driverPrivate;
+
+   switch (param) {
+   case __DRI2_RENDERER_VENDOR_ID:
+      value[0] = radeonVendorString;
+      return 0;
+   case __DRI2_RENDERER_DEVICE_ID:
+      value[0] = radeonGetRendererString(screen);
+      return 0;
+   default:
+      return -1;
+   }
+}
+
+static const __DRI2rendererQueryExtension radeonRendererQueryExtension = {
+   .base = { __DRI2_RENDERER_QUERY, 1 },
+
+   .queryInteger        = radeonQueryRendererInteger,
+   .queryString         = radeonQueryRendererString
+};
+
 
 static const __DRIextension *radeon_screen_extensions[] = {
     &dri2ConfigQueryExtension.base,
@@ -491,6 +558,7 @@ static const __DRIextension *radeon_screen_extensions[] = {
 #endif
     &radeonFlushExtension.base,
     &radeonImageExtension.base,
+    &radeonRendererQueryExtension.base,
     NULL
 };
 
index 76fa1ec05dd7906271cb2a9145c0327001c10809..9b77627b857d306c81bcc4a04586f0f89e16a200 100644 (file)
@@ -209,6 +209,8 @@ struct __DRIimageRec {
 #define untile_image                        r200_untile_image
 #define set_re_cntl_d3d                     r200_set_re_cntl_d3d
 #define radeonDestroyBuffer                 r200_radeonDestroyBuffer
+#define radeonVendorString                  r200_radeonVendorString
+#define radeonGetRendererString             r200_radeonGetRendererString
 #endif
 
 extern void radeonDestroyBuffer(__DRIdrawable *driDrawPriv);