mesa/formatquery: Added queries related to image textures
authorAntia Puentes <apuentes@igalia.com>
Sat, 19 Dec 2015 18:50:25 +0000 (19:50 +0100)
committerEduardo Lima Mitev <elima@igalia.com>
Thu, 3 Mar 2016 14:14:07 +0000 (15:14 +0100)
From the ARB_internalformat_query2 specification:

   "- IMAGE_TEXEL_SIZE: The size of a texel when the resource when used as
      an image texture is returned in <params>.  This is the value from the
      /Size/ column in Table 3.22. If the resource is not supported for image
      textures, or if image textures are not supported, zero is returned.

    - IMAGE_COMPATIBILITY_CLASS: The compatibility class of the resource when
      used as an image texture is returned in <params>.  This corresponds to
      the value from the /Class/ column in Table 3.22. The possible values
      returned are IMAGE_CLASS_4_X_32, IMAGE_CLASS_2_X_32, IMAGE_CLASS_1_X_32,
      IMAGE_CLASS_4_X_16, IMAGE_CLASS_2_X_16, IMAGE_CLASS_1_X_16,
      IMAGE_CLASS_4_X_8, IMAGE_CLASS_2_X_8, IMAGE_CLASS_1_X_8,
      IMAGE_CLASS_11_11_10, and IMAGE_CLASS_10_10_10_2, which correspond to
      the 4x32, 2x32, 1x32, 4x16, 2x16, 1x16, 4x8, 2x8, 1x8, the class
      (a) 11/11/10 packed floating-point format, and the class (b)
      10/10/10/2 packed formats, respectively.
      If the resource is not supported for image textures, or if image
      textures are not supported, NONE is returned.

    - IMAGE_PIXEL_FORMAT: The pixel format of the resource when used as an
      image texture is returned in <params>.  This is the value
      from the /Pixel format/ column in Table 3.22. If the resource is not
      supported for image textures, or if image textures are not supported,
      NONE is returned.

    - IMAGE_PIXEL_TYPE: The pixel type of the resource when used as an
      image texture is returned in <params>.  This is the value from
      the /Pixel type/ column in Table 3.22. If the resource is not supported
      for image textures, or if image textures are not supported, NONE is
      returned."

Reviewed-by: Dave Airlie <airlied@redhat.com>
src/mesa/main/formatquery.c

index f487f32e7f590e4c7adc7acf2601599ed3385087..289f133114d094aa0f1335960c222a6c9de2abe2 100644 (file)
@@ -1220,21 +1220,70 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
                                       buffer);
       break;
 
-   case GL_IMAGE_TEXEL_SIZE:
-      /* @TODO */
+   case GL_IMAGE_TEXEL_SIZE: {
+      mesa_format image_format;
+
+      if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
+          target == GL_RENDERBUFFER)
+         goto end;
+
+      image_format = _mesa_get_shader_image_format(internalformat);
+      if (image_format == MESA_FORMAT_NONE)
+         goto end;
+
+      /* We return bits */
+      buffer[0] = (_mesa_get_format_bytes(image_format) * 8);
       break;
+   }
 
    case GL_IMAGE_COMPATIBILITY_CLASS:
-      /* @TODO */
+      if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
+          target == GL_RENDERBUFFER)
+         goto end;
+
+      buffer[0] = _mesa_get_image_format_class(internalformat);
       break;
 
-   case GL_IMAGE_PIXEL_FORMAT:
-      /* @TODO */
+   case GL_IMAGE_PIXEL_FORMAT: {
+      GLint base_format;
+
+      if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
+          target == GL_RENDERBUFFER ||
+          !_mesa_is_shader_image_format_supported(ctx, internalformat))
+         goto end;
+
+      base_format = _mesa_base_tex_format(ctx, internalformat);
+      if (base_format == -1)
+         goto end;
+
+      if (_mesa_is_enum_format_integer(internalformat))
+         buffer[0] = _mesa_base_format_to_integer_format(base_format);
+      else
+         buffer[0] = base_format;
       break;
+   }
 
-   case GL_IMAGE_PIXEL_TYPE:
-      /* @TODO */
+   case GL_IMAGE_PIXEL_TYPE: {
+      mesa_format image_format;
+      GLenum datatype;
+      GLuint comps;
+
+      if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
+          target == GL_RENDERBUFFER)
+         goto end;
+
+      image_format = _mesa_get_shader_image_format(internalformat);
+      if (image_format == MESA_FORMAT_NONE)
+         goto end;
+
+      _mesa_uncompressed_format_to_type_and_comps(image_format, &datatype,
+                                                  &comps);
+      if (!datatype)
+         goto end;
+
+      buffer[0] = datatype;
       break;
+   }
 
    case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE: {
       if (!_mesa_has_ARB_shader_image_load_store(ctx))