[Mesa-dev] [PATCH] mesa: add missing queries for ARB_direct_state_access

Daniel Scharrer daniel at constexpr.org
Fri Jul 24 23:12:55 PDT 2015


---

ARB_dsa / GL 4.5 add indexed GL_TEXTURE_BINDING_* and GL_SAMPLER_BINDING
queries, as well as a GL_TEXTURE_TARGET query on texture objects.

The implementation for the GL_TEXTURE_BINDING_* and GL_SAMPLER_BINDING
queries is based on their non-indexed variants. To map the binding enum
to a texture target index I added a new helper based on
_mesa_tex_target_to_index. The non-indexed GL_TEXTURE_BINDING_* queries
use the offset stored in the get_hash for this, but that didn't seem
easy to access.

 src/mesa/main/get.c      | 90 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/texparam.c | 12 +++++++
 2 files changed, 102 insertions(+)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index ce78691..8ffa8b9 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1746,6 +1746,52 @@ _mesa_GetDoublev(GLenum pname, GLdouble *params)
    }
 }
 
+/**
+ * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
+ * into the corresponding Mesa texture target index.
+ * \return TEXTURE_x_INDEX or -1 if binding is invalid
+ */
+static int
+_mesa_tex_binding_to_index(const struct gl_context *ctx, GLenum binding)
+{
+   switch (binding) {
+   case GL_TEXTURE_BINDING_1D:
+      return _mesa_is_desktop_gl(ctx) ? TEXTURE_1D_INDEX : -1;
+   case GL_TEXTURE_BINDING_2D:
+      return TEXTURE_2D_INDEX;
+   case GL_TEXTURE_BINDING_3D:
+      return ctx->API != API_OPENGLES ? TEXTURE_3D_INDEX : -1;
+   case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
+      return ctx->Extensions.ARB_texture_cube_map
+         ? TEXTURE_CUBE_INDEX : -1;
+   case GL_TEXTURE_BINDING_RECTANGLE_NV:
+      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle
+         ? TEXTURE_RECT_INDEX : -1;
+   case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
+      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array
+         ? TEXTURE_1D_ARRAY_INDEX : -1;
+   case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
+      return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array)
+         || _mesa_is_gles3(ctx)
+         ? TEXTURE_2D_ARRAY_INDEX : -1;
+   case GL_TEXTURE_BINDING_BUFFER:
+      return ctx->API == API_OPENGL_CORE &&
+             ctx->Extensions.ARB_texture_buffer_object ?
+             TEXTURE_BUFFER_INDEX : -1;
+   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
+      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_cube_map_array
+         ? TEXTURE_CUBE_ARRAY_INDEX : -1;
+   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
+      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
+         ? TEXTURE_2D_MULTISAMPLE_INDEX: -1;
+   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
+      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
+         ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX: -1;
+   default:
+      return -1;
+   }
+}
+
 static enum value_type
 find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
 {
@@ -2009,6 +2055,50 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
       v->value_int = ctx->ImageUnits[index].Format;
       return TYPE_INT;
 
+   /* ARB_direct_state_access */
+   case GL_TEXTURE_BINDING_1D:
+   case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
+   case GL_TEXTURE_BINDING_2D:
+   case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
+   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
+   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
+   case GL_TEXTURE_BINDING_3D:
+   case GL_TEXTURE_BINDING_BUFFER:
+   case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
+   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
+   case GL_TEXTURE_BINDING_RECTANGLE_NV: {
+      if (ctx->API != API_OPENGL_CORE)
+         goto invalid_enum;
+      GLint targetIndex = _mesa_tex_binding_to_index(ctx, pname);
+      if (targetIndex < 0)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxTextureUnits)
+         goto invalid_value;
+      v->value_int = ctx->Texture.Unit[index].CurrentTex[targetIndex]->Name;
+      return TYPE_INT;
+   }
+
+   case GL_SAMPLER_BINDING: {
+      struct gl_sampler_object *samp;
+
+      if (ctx->API != API_OPENGL_CORE)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxTextureUnits)
+         goto invalid_value;
+
+      samp = ctx->Texture.Unit[index].Sampler;
+      /*
+       * The sampler object may have been deleted on another context,
+       * so we try to lookup the sampler object before returning its Name.
+       */
+      if (samp && _mesa_lookup_samplerobj(ctx, samp->Name)) {
+         v->value_int = samp->Name;
+      } else {
+         v->value_int = 0;
+      }
+      return TYPE_INT;
+   }
+
    case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
       if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_compute_shader)
          goto invalid_enum;
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index efdeed5..59afc79 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -1888,6 +1888,12 @@ get_tex_parameterfv(struct gl_context *ctx,
          *params = (GLfloat) obj->Sampler.sRGBDecode;
          break;
 
+      case GL_TEXTURE_TARGET:
+         if (ctx->API != API_OPENGL_CORE)
+            goto invalid_pname;
+         *params = ENUM_TO_FLOAT(obj->Target);
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -2113,6 +2119,12 @@ get_tex_parameteriv(struct gl_context *ctx,
          *params = obj->ImageFormatCompatibilityType;
          break;
 
+      case GL_TEXTURE_TARGET:
+         if (ctx->API != API_OPENGL_CORE)
+            goto invalid_pname;
+         *params = (GLint) obj->Target;
+         break;
+
       default:
          goto invalid_pname;
    }
-- 
2.4.6



More information about the mesa-dev mailing list