<div dir="ltr">On Thu, Nov 21, 2013 at 5:56 PM, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I'd rename this summary as something like "mesa: implement the _mesa_TextureView() function"<div>
<div class="h5"><br>
<br>
<br>
On 11/19/2013 04:16 PM, Courtney Goeltzenleuchter wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Add Mesa TextureView logic.<br>
Incorporate feedback on ARB_texture_view<br>
<br>
Signed-off-by: Courtney Goeltzenleuchter <courtney@LunarG.com><br>
---<br>
  src/mesa/main/textureview.c | 562 ++++++++++++++++++++++++++++++<u></u>+++++++++++++-<br>
  1 file changed, 561 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c<br>
index 4a6bd62..1858465 100644<br>
--- a/src/mesa/main/textureview.c<br>
+++ b/src/mesa/main/textureview.c<br>
@@ -40,8 +40,346 @@<br>
  #include "texobj.h"<br>
  #include "texstorage.h"<br>
  #include "textureview.h"<br>
+#include "stdbool.h"<br>
  #include "mtypes.h"<br>
<br>
+/* Table 3.X.2 (Compatible internal formats for TextureView)<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | Class                 | Internal formats                                |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_128_BITS   | RGBA32F, RGBA32UI, RGBA32I                      |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_96_BITS    | RGB32F, RGB32UI, RGB32I                         |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_64_BITS    | RGBA16F, RG32F, RGBA16UI, RG32UI, RGBA16I,      |<br>
+    |                       | RG32I, RGBA16, RGBA16_SNORM                     |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_48_BITS    | RGB16, RGB16_SNORM, RGB16F, RGB16UI, RGB16I     |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_32_BITS    | RG16F, R11F_G11F_B10F, R32F,                    |<br>
+    |                       | RGB10_A2UI, RGBA8UI, RG16UI, R32UI,             |<br>
+    |                       | RGBA8I, RG16I, R32I, RGB10_A2, RGBA8, RG16,     |<br>
+    |                       | RGBA8_SNORM, RG16_SNORM, SRGB8_ALPHA8, RGB9_E5  |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_24_BITS    | RGB8, RGB8_SNORM, SRGB8, RGB8UI, RGB8I          |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_16_BITS    | R16F, RG8UI, R16UI, RG8I, R16I, RG8, R16,       |<br>
+    |                       | RG8_SNORM, R16_SNORM                            |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_8_BITS     | R8UI, R8I, R8, R8_SNORM                         |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_RGTC1_RED  | COMPRESSED_RED_RGTC1,                           |<br>
+    |                       | COMPRESSED_SIGNED_RED_RGTC1                     |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_RGTC2_RG   | COMPRESSED_RG_RGTC2,                            |<br>
+    |                       | COMPRESSED_SIGNED_RG_RGTC2                      |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_BPTC_UNORM | COMPRESSED_RGBA_BPTC_UNORM,                     |<br>
+    |                       | COMPRESSED_SRGB_ALPHA_BPTC_<u></u>UNORM                |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+    | VIEW_CLASS_BPTC_FLOAT | COMPRESSED_RGB_BPTC_SIGNED_<u></u>FLOAT,               |<br>
+    |                       | COMPRESSED_RGB_BPTC_UNSIGNED_<u></u>FLOAT              |<br>
+    ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ */<br>
+struct internal_format_class_info {<br>
+   GLenum view_class;<br>
+   GLenum internal_format;<br>
+};<br>
+#define INFO(c,f) {GL_##c, GL_##f}<br>
+static const struct internal_format_class_info _compatible_internal_formats[] = {<br>
+   INFO(VIEW_CLASS_128_BITS, RGBA32F),<br>
</blockquote>
<br></div></div>
If the point of the macro is just to save typing GL_ prefixes, I don't think it's worth it.<br></blockquote><div>I mostly did it so that I could copy & paste the values from the spec to here.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
The leading underscore on _compatible_internal_formats isn't really necessary.</blockquote><div>underscore removed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+   INFO(VIEW_CLASS_128_BITS, RGBA32UI),<br>
+   INFO(VIEW_CLASS_128_BITS, RGBA32I),<br>
+   INFO(VIEW_CLASS_96_BITS, RGB32F),<br>
+   INFO(VIEW_CLASS_96_BITS, RGB32UI),<br>
+   INFO(VIEW_CLASS_96_BITS, RGB32I),<br>
+   INFO(VIEW_CLASS_64_BITS, RGBA16F),<br>
+   INFO(VIEW_CLASS_64_BITS, RG32F),<br>
+   INFO(VIEW_CLASS_64_BITS, RGBA16UI),<br>
+   INFO(VIEW_CLASS_64_BITS, RG32UI),<br>
+   INFO(VIEW_CLASS_64_BITS, RGBA16I),<br>
+   INFO(VIEW_CLASS_64_BITS, RG32I),<br>
+   INFO(VIEW_CLASS_64_BITS, RGBA16),<br>
+   INFO(VIEW_CLASS_64_BITS, RGBA16_SNORM),<br>
+   INFO(VIEW_CLASS_48_BITS, RGB16),<br>
+   INFO(VIEW_CLASS_48_BITS, RGB16_SNORM),<br>
+   INFO(VIEW_CLASS_48_BITS, RGB16F),<br>
+   INFO(VIEW_CLASS_48_BITS, RGB16UI),<br>
+   INFO(VIEW_CLASS_48_BITS, RGB16I),<br>
+   INFO(VIEW_CLASS_32_BITS, RG16F),<br>
+   INFO(VIEW_CLASS_32_BITS, R11F_G11F_B10F),<br>
+   INFO(VIEW_CLASS_32_BITS, R32F),<br>
+   INFO(VIEW_CLASS_32_BITS, RGB10_A2UI),<br>
+   INFO(VIEW_CLASS_32_BITS, RGBA8UI),<br>
+   INFO(VIEW_CLASS_32_BITS, RG16UI),<br>
+   INFO(VIEW_CLASS_32_BITS, R32UI),<br>
+   INFO(VIEW_CLASS_32_BITS, RGBA8I),<br>
+   INFO(VIEW_CLASS_32_BITS, RG16I),<br>
+   INFO(VIEW_CLASS_32_BITS, R32I),<br>
+   INFO(VIEW_CLASS_32_BITS, RGB10_A2),<br>
+   INFO(VIEW_CLASS_32_BITS, RGBA8),<br>
+   INFO(VIEW_CLASS_32_BITS, RG16),<br>
+   INFO(VIEW_CLASS_32_BITS, RGBA8_SNORM),<br>
+   INFO(VIEW_CLASS_32_BITS, RG16_SNORM),<br>
+   INFO(VIEW_CLASS_32_BITS, SRGB8_ALPHA8),<br>
+   INFO(VIEW_CLASS_32_BITS, RGB9_E5),<br>
+   INFO(VIEW_CLASS_24_BITS, RGB8),<br>
+   INFO(VIEW_CLASS_24_BITS, RGB8_SNORM),<br>
+   INFO(VIEW_CLASS_24_BITS, SRGB8),<br>
+   INFO(VIEW_CLASS_24_BITS, RGB8UI),<br>
+   INFO(VIEW_CLASS_24_BITS, RGB8I),<br>
+   INFO(VIEW_CLASS_16_BITS, R16F),<br>
+   INFO(VIEW_CLASS_16_BITS, RG8UI),<br>
+   INFO(VIEW_CLASS_16_BITS, R16UI),<br>
+   INFO(VIEW_CLASS_16_BITS, RG8I),<br>
+   INFO(VIEW_CLASS_16_BITS, R16I),<br>
+   INFO(VIEW_CLASS_16_BITS, RG8),<br>
+   INFO(VIEW_CLASS_16_BITS, R16),<br>
+   INFO(VIEW_CLASS_16_BITS, RG8_SNORM),<br>
+   INFO(VIEW_CLASS_16_BITS, R16_SNORM),<br>
+   INFO(VIEW_CLASS_8_BITS, R8UI),<br>
+   INFO(VIEW_CLASS_8_BITS, R8I),<br>
+   INFO(VIEW_CLASS_8_BITS, R8),<br>
+   INFO(VIEW_CLASS_8_BITS, R8_SNORM),<br>
+   INFO(VIEW_CLASS_RGTC1_RED, COMPRESSED_RED_RGTC1),<br>
+   INFO(VIEW_CLASS_RGTC1_RED, COMPRESSED_SIGNED_RED_RGTC1),<br>
+   INFO(VIEW_CLASS_RGTC2_RG, COMPRESSED_RG_RGTC2),<br>
+   INFO(VIEW_CLASS_RGTC2_RG, COMPRESSED_SIGNED_RG_RGTC2),<br>
+   INFO(VIEW_CLASS_BPTC_UNORM, COMPRESSED_RGBA_BPTC_UNORM_<u></u>ARB),<br>
+   INFO(VIEW_CLASS_BPTC_UNORM, COMPRESSED_SRGB_ALPHA_BPTC_<u></u>UNORM_ARB),<br>
+   INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_SIGNED_<u></u>FLOAT_ARB),<br>
+   INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_UNSIGNED_<u></u>FLOAT_ARB),<br>
+};<br>
+#undef INFO<br>
+<br>
+/**<br>
+ * Lookup format view class based on internalformat<br>
+ * \return VIEW_CLASS if internalformat found in table, GL_FALSE otherwise.<br>
+ */<br>
+static unsigned int<br>
</blockquote>
<br></div></div>
Return GLenum?</blockquote><div>I had feedback elsewhere that it was better to stay away from GLenums for internal functions.</div><div>So I could either change the comment to match the return of false.  Hmm, as I look at this again the function is going to either return a GL_VIEW_CLASS... enum from the lookup table or false. Yeah, probably make more sense to just be GLenum for consistency.</div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+lookup_view_class(GLenum internalformat)<br>
+{<br>
+   uint i;<br>
+<br>
+   for (i = 0; i < ARRAY_SIZE(_compatible_<u></u>internal_formats); i++) {<br>
+      if (_compatible_internal_formats[<u></u>i].internal_format == internalformat)<br>
+         return _compatible_internal_formats[<u></u>i].view_class;<br>
+   }<br>
+   return false;<br>
</blockquote>
<br></div>
return GL_FALSE, per the comment.</blockquote><div>got it. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+}<br>
+<br>
+/**<br>
+ * Compute the size of the next mipmap level.<br>
+ */<br>
+static void<br>
+next_mipmap_level_size(GLenum target,<br>
+                       GLint *width, GLint *height, GLint *depth)<br>
+{<br>
+   if (*width > 1) {<br>
+      *width /= 2;<br>
+   }<br>
+<br>
+   if ((*height > 1) && (target != GL_TEXTURE_1D_ARRAY)) {<br>
+      *height /= 2;<br>
+   }<br>
+<br>
+   if ((*depth > 1) && (target != GL_TEXTURE_2D_ARRAY)) {<br>
+      *depth /= 2;<br>
+   }<br>
+}<br>
</blockquote>
<br></div>
Can the next_mipmap_level_size() helper in mipmap.c be re-used?<br>
<br>
And yes, we should probably re-use that function in texstorage.c</blockquote><div>Sure, that will work. So will one in texstorage.c.</div><div>Okay, I'll make both texstorage.c and textureview.c use the mipmap function.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
+/** Helper to get a particular texture image in a texture object */<br>
+static struct gl_texture_image *<br>
+get_tex_image(struct gl_context *ctx,<br>
+              struct gl_texture_object *texObj,<br>
+              GLuint face, GLuint level)<br>
+{<br>
+   struct gl_texture_image *texImage;<br>
+<br>
+   if (!texObj)<br>
+      return NULL;<br>
+<br>
+   texImage = texObj->Image[face][level];<br>
+   if (!texImage) {<br>
+      texImage = ctx->Driver.NewTextureImage(<u></u>ctx);<br>
+      if (!texImage) {<br>
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");<br>
+         return NULL;<br>
+      }<br>
+<br>
+      texObj->Image[face][level] = texImage;<br>
+<br>
+      /* Set the 'back' pointer */<br>
+      texImage->TexObject = texObj;<br>
+      texImage->Level = level;<br>
+      texImage->Face = face;<br>
+   }<br>
+<br>
+   return texImage;<br>
+}<br>
</blockquote>
<br></div></div>
That function looks a lot like _mesa_get_tex_image(), or get_tex_image() in texstorage.c.</blockquote><div>Hadn't seen that one. _mesa_get_tex_image() does the same thing.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div class="h5"><br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
+/**<br>
+ * Initialize new texture's gl_texture_image structures. Will not call driver<br>
+ * to allocate new space, simply record relevant layer, face, format, etc.<br>
+ * \return GL_FALSE if any error, GL_TRUE otherwise.<br>
+ */<br>
+static GLboolean<br>
+initialize_texture_fields(<u></u>struct gl_context *ctx,<br>
+                          GLenum target,<br>
+                          struct gl_texture_object *texObj,<br>
+                          GLint levels,<br>
+                          GLsizei width, GLsizei height, GLsizei depth,<br>
+                          GLenum internalFormat, gl_format texFormat)<br>
+{<br>
+   const GLuint numFaces = _mesa_num_tex_faces(target);<br>
+   GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;<br>
+   GLuint face;<br>
+<br>
+   /* Pretend we are bound to initialize the gl_texture_image structs */<br>
+   texObj->Target = target;<br>
+<br>
+   /* Set up all the texture object's gl_texture_images */<br>
+   for (level = 0; level < levels; level++) {<br>
+      for (face = 0; face < numFaces; face++) {<br>
+         struct gl_texture_image *texImage =<br>
+                 get_tex_image(ctx, texObj, face, level);<br>
+<br>
+         if (!texImage) {<br>
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage");<br>
+            return GL_FALSE;<br>
+         }<br>
+<br>
+         _mesa_init_teximage_fields(<u></u>ctx, texImage,<br>
+                                    levelWidth, levelHeight, levelDepth,<br>
+                                    0, internalFormat, texFormat);<br>
+      }<br>
+<br>
+      next_mipmap_level_size(target, &levelWidth, &levelHeight, &levelDepth);<br>
+   }<br>
+<br>
+   /* "unbind" */<br>
+   texObj->Target = 0;<br>
+<br>
+   return GL_TRUE;<br>
+}<br>
+<br>
+#define RETURN_IF_SUPPORTED(t) do {            \<br>
+   if (newTarget == GL_ ## t)                   \<br>
+      return GL_TRUE;                          \<br>
+} while (0)<br>
+<br>
+/**<br>
+ * Check for compatible target<br>
+ * If an error is found, record it with _mesa_error()<br>
+ * \return GL_FALSE if any error, GL_TRUE otherwise.<br>
+ */<br>
+static GLboolean<br>
+target_valid(struct gl_context *ctx, GLenum origTarget, GLenum newTarget)<br>
+{<br>
+   /*<br>
+    * From ARB_texture_view spec:<br>
+   ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+   | Original target              | Valid new targets |<br>
+   ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+   | TEXTURE_1D                   | TEXTURE_1D, TEXTURE_1D_ARRAY |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_2D                   | TEXTURE_2D, TEXTURE_2D_ARRAY |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_3D                   | TEXTURE_3D |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_CUBE_MAP             | TEXTURE_CUBE_MAP, TEXTURE_2D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_RECTANGLE            | TEXTURE_RECTANGLE |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_BUFFER               | <none> |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_1D_ARRAY             | TEXTURE_1D_ARRAY, TEXTURE_1D |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_2D_ARRAY             | TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP, TEXTURE_CUBE_MAP_ARRAY |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_CUBE_MAP_ARRAY       | TEXTURE_CUBE_MAP_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_2D_MULTISAMPLE       | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
+   | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+   | TEXTURE_2D_MULTISAMPLE_ARRAY | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
+   ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+    */<br>
+<br>
+   switch (origTarget) {<br>
+   case GL_TEXTURE_1D:<br>
+   case GL_TEXTURE_1D_ARRAY:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>1D);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>1D_ARRAY);<br>
+      break;<br>
+   case GL_TEXTURE_2D:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_ARRAY);<br>
+      break;<br>
+   case GL_TEXTURE_3D:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>3D);<br>
+      break;<br>
+   case GL_TEXTURE_RECTANGLE:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>RECTANGLE);<br>
+      break;<br>
+   case GL_TEXTURE_CUBE_MAP:<br>
+   case GL_TEXTURE_2D_ARRAY:<br>
+   case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_ARRAY);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>CUBE_MAP);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>CUBE_MAP_ARRAY);<br>
+      break;<br>
+   case GL_TEXTURE_2D_MULTISAMPLE:<br>
+   case GL_TEXTURE_2D_MULTISAMPLE_<u></u>ARRAY:<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_MULTISAMPLE);<br>
+      RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_MULTISAMPLE_ARRAY);<br>
+      break;<br>
+   }<br>
+   _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+               "glTextureView(illegal target=%s)",<br>
+               _mesa_lookup_enum_by_nr(<u></u>newTarget));<br>
+   return GL_FALSE;<br>
</blockquote>
<br></div></div>
Typically, we put a _mesa_error() call like that after a default switch case.</blockquote><div><br></div><div>I modeled this function after _mesa_choose_tex_format which uses the same pattern. Default case will not catch all the error conditions.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+}<br>
+#undef RETURN_IF_SUPPORTED<br>
+<br>
+/**<br>
+ * Check for compatible format<br>
+ * If an error is found, record it with _mesa_error()<br>
+ * \return GL_FALSE if any error, GL_TRUE otherwise.<br>
+ */<br>
+static GLboolean<br>
</blockquote>
<br></div>
Since this is an internal function, it could return bool.</blockquote><div>OK </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+compatible_format(struct gl_context *ctx, struct gl_texture_object *origTexObj,<br>
</blockquote>
<br></div>
origTexObj could be const qualified.</blockquote><div>OK </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+                  GLenum internalformat)<br>
+{<br>
+   /* Level 0 of a texture created by glTextureStorage or glTextureView<br>
+    * is always defined.<br>
+    */<br>
+   struct gl_texture_image *texImage = origTexObj->Image[0][0];<br>
+   GLint origInternalFormat = texImage->InternalFormat;<br>
+   unsigned int origViewClass, newViewClass;<br>
+<br>
+<br>
+   /* The two textures' internal formats must be compatible according to<br>
+    * Table 3.X.2 (Compatible internal formats for TextureView)<br>
+    * if the internal format exists in that table the view class must match.<br>
+    * The internal formats must be identical if not in that table,<br>
+    * or an INVALID_OPERATION error is generated.<br>
+    */<br>
+   if (origInternalFormat == internalformat)<br>
+      return GL_TRUE;<br>
+<br>
+   origViewClass = lookup_view_class(<u></u>origInternalFormat);<br>
+   newViewClass = lookup_view_class(<u></u>internalformat);<br>
+   if ((origViewClass == newViewClass) && origViewClass != false)<br>
</blockquote>
<br></div>
!= GL_FALSE</blockquote><div>Another internal function, I'll change it to bool.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+      return GL_TRUE;<br>
+<br>
+   _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+               "glTextureView(internalformat  %s not compatible with origtexture %s)",<br>
</blockquote>
<br></div>
Extra space before first %s<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+               _mesa_lookup_enum_by_nr(<u></u>internalformat),<br>
+               _mesa_lookup_enum_by_nr(<u></u>origInternalFormat));<br>
+   return GL_FALSE;<br>
+}<br>
+<br>
  /**<br>
   * glTextureView (ARB_texture_view)<br>
   * If an error is found, record it with _mesa_error()<br>
@@ -53,13 +391,235 @@ _mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture,<br>
                    GLuint minlevel, GLuint numlevels,<br>
                    GLuint minlayer, GLuint numlayers)<br>
  {<br>
+   struct gl_texture_object *texObj;<br>
+   struct gl_texture_object *origTexObj;<br>
+   struct gl_texture_image *origTexImage;<br>
+   GLuint newViewMinLevel, newViewMinLayer;<br>
+   GLuint newViewNumLevels, newViewNumLayers;<br>
+   GLsizei width, height, depth;<br>
+   gl_format texFormat;<br>
+   GLboolean sizeOK, dimensionsOK;<br>
+   GLenum faceTarget;<br>
+<br>
     GET_CURRENT_CONTEXT(ctx);<br>
<br>
     if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE))<br>
-      _mesa_debug(ctx, "glTextureView (unfinished) %d %s %d %s %d %d %d %d\n",<br>
+      _mesa_debug(ctx, "glTextureView %d %s %d %s %d %d %d %d\n",<br>
                    texture, _mesa_lookup_enum_by_nr(<u></u>target), origtexture,<br>
                    _mesa_lookup_enum_by_nr(<u></u>internalformat),<br>
                    minlevel, numlevels, minlayer, numlayers);<br>
<br>
+   if (origtexture == 0) {<br>
+      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = 0x%x)", origtexture);<br>
+      return;<br>
+   }<br>
+<br>
+   /* Need original texture information to validate arguments */<br>
+   origTexObj = _mesa_lookup_texture(ctx, origtexture);<br>
+<br>
+   /* If <origtexture> is not the name of a texture, INVALID_VALUE is generated. */<br>
+   if (!origTexObj) {<br>
+      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = 0x%x)", origtexture);<br>
</blockquote>
<br></div></div>
I think we usually print/record object IDs as decimal.</blockquote><div>OK </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+      return;<br>
+   }<br>
+<br>
+   /* If <origtexture>'s TEXTURE_IMMUTABLE_FORMAT value is not TRUE,<br>
+    * INVALID_OPERATION is generated.<br>
+    */<br>
+   if (!origTexObj->Immutable) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(origtexture not immutable)");<br>
+      return;<br>
+   }<br>
+<br>
+   /* If <texture> is 0, INVALID_VALUE is generated. */<br>
+   if (texture == 0) {<br>
+      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(texture = 0)");<br>
+      return;<br>
+   }<br>
+<br>
+   /* If <texture> is not a valid name returned by GenTextures,<br>
+    * the error INVALID_OPERATION is generated.<br>
+    */<br>
+   texObj = _mesa_lookup_texture(ctx, texture);<br>
+   if (texObj == NULL) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(texture 0x%x non-gen name)", texture);<br>
+      return;<br>
+   }<br>
+<br>
+   /* If <texture> has already been bound and given a target, then<br>
+    * the error INVALID_OPERATION is generated.<br>
+    */<br>
+   if (texObj->Target) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(texture 0x%x already bound)", texture);<br>
+      return;<br>
+   }<br>
+<br>
+   /* Check for compatible target */<br>
+   if (!target_valid(ctx, origTexObj->Target, target)) {<br>
+      return; /* error was recorded */<br>
+   }<br>
+<br>
+   /* minlevel and minlayer are relative to the view of origtexture */<br>
+   /* If minlevel or minlayer is greater than level or layer, respectively,<br>
+    * of origtexture return INVALID_VALUE.<br>
+    */<br>
+   newViewMinLevel = origTexObj->MinLevel + minlevel;<br>
+   newViewMinLayer = origTexObj->MinLayer + minlayer;<br>
+   if (newViewMinLevel >= (origTexObj->MinLevel + origTexObj->NumLevels) ||<br>
+       newViewMinLayer >= (origTexObj->MinLayer + origTexObj->NumLayers)) {<br>
+      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = 0x%x)", origtexture);<br>
+      return;<br>
+   }<br>
</blockquote>
<br></div></div>
I'd probably split the level and layer error checks into two separate if statements.  Then, the error message could have more detailed info about the invalid layer or level.<div class="im"><br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+   if (!compatible_format(ctx, origTexObj, internalformat)) {<br>
+      return; // Error logged<br>
</blockquote>
<br></div>
/* error logged */  just to be consistent with other comments.</blockquote><div>OK</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+   }<br>
+<br>
+   texFormat = _mesa_choose_texture_format(<u></u>ctx, texObj, target, 0,<br>
+                                           internalformat, GL_NONE, GL_NONE);<br>
+   assert(texFormat != MESA_FORMAT_NONE);<br>
</blockquote>
<br></div>
Just to be safe, let's also put in a "if (texFormat == MESA_FORMAT_NONE) return" here for release builds.</blockquote><div>OK </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
+   newViewNumLevels = MIN2(numlevels, origTexObj->NumLevels - minlevel);<br>
+   newViewNumLayers = MIN2(numlayers, origTexObj->NumLayers - minlayer);<br>
+<br>
+   faceTarget = origTexObj->Target;<br>
+   if (faceTarget == GL_TEXTURE_CUBE_MAP)<br>
</blockquote>
<br></div>
or GL_TEXTURE_CUBE_MAP_ARRAY?</blockquote><div>That's a great question! I believe the answer is no. As I understand it, for a CUBE_MAP the numlayers parameter corresponds to the faces (a CUBE_MAP will always have numlayers = 6). For a CUBE_MAP_ARRAY the numlayers refers to the depth not the face.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+      faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + minlayer;<br>
+<br>
+   /* Get a reference to what will become this View's base level */<br>
+   origTexImage = _mesa_select_tex_image(ctx, origTexObj,<br>
+                                         faceTarget, minlevel);<br>
+   width = origTexImage->Width;<br>
+   height = origTexImage->Height;<br>
+   depth = origTexImage->Depth;<br>
+<br>
+   /* Adjust width, height, depth to be appropriate for new target */<br>
+   switch (target) {<br>
+   case GL_TEXTURE_1D:<br>
+   case GL_TEXTURE_3D:<br>
+      break;<br>
+<br>
+   case GL_TEXTURE_1D_ARRAY:<br>
+      height = (GLsizei) newViewNumLayers;<br>
+      break;<br>
+<br>
+   case GL_TEXTURE_2D:<br>
+   case GL_TEXTURE_2D_MULTISAMPLE:<br>
+   case GL_TEXTURE_RECTANGLE:<br>
+   case GL_TEXTURE_CUBE_MAP:<br>
+      depth = 1;<br>
+      break;<br>
+<br>
+   case GL_TEXTURE_2D_ARRAY:<br>
+   case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+   case GL_TEXTURE_2D_MULTISAMPLE_<u></u>ARRAY:<br>
+      depth = newViewNumLayers;<br>
+      break;<br>
+   }<br>
+<br>
+   /* If the dimensions of the original texture are larger than the maximum<br>
+    * supported dimensions of the new target, the error INVALID_OPERATION is<br>
+    * generated. For example, if the original texture has a TEXTURE_2D_ARRAY<br>
+    * target and its width is greater than MAX_CUBE_MAP_TEXTURE_SIZE, an error<br>
+    * will be generated if TextureView is called to create a TEXTURE_CUBE_MAP<br>
+    * view.<br>
+    */<br>
+   dimensionsOK = _mesa_legal_texture_<u></u>dimensions(ctx, target, 0,<br>
+                                                 width, height, depth, 0);<br>
+   if (!dimensionsOK) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(invalid width or height or depth)");<br>
+      return;<br>
+   }<br>
+<br>
+   sizeOK = ctx->Driver.TestProxyTexImage(<u></u>ctx, target, 0, texFormat,<br>
+                                          width, height, depth, 0);<br>
+   if (!sizeOK) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(invalid texture size)");<br>
+      return;<br>
+   }<br>
+<br>
+   /* If <target> is TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_RECTANGLE,<br>
+    * or TEXTURE_2D_MULTISAMPLE and <numlayers> does not equal 1, the error<br>
+    * INVALID_VALUE is generated.<br>
+    */<br>
+   switch (target) {<br>
+   case GL_TEXTURE_1D:<br>
+   case GL_TEXTURE_2D:<br>
+   case GL_TEXTURE_3D:<br>
+   case GL_TEXTURE_RECTANGLE:<br>
+   case GL_TEXTURE_2D_MULTISAMPLE:<br>
+      if (numlayers != 1) {<br>
+         _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(numlayers %d != 1)", numlayers);<br>
+         return;<br>
+      }<br>
+      break;<br>
+<br>
+   case GL_TEXTURE_CUBE_MAP:<br>
+      /* If the new texture's target is TEXTURE_CUBE_MAP, the clamped <numlayers><br>
+       * must be equal to 6.<br>
+       */<br>
+      if (newViewNumLayers != 6) {<br>
+         _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(clamped numlayers %d != 6)",<br>
+                     newViewNumLayers);<br>
+         return;<br>
+      }<br>
+      break;<br>
+<br>
+   case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+      /* If the new texture's target is TEXTURE_CUBE_MAP_ARRAY,<br>
+       * then <numlayers> counts layer-faces rather than layers,<br>
+       * and the clamped <numlayers> must be a multiple of 6.<br>
+       * Otherwise, the error INVALID_VALUE is generated.<br>
+       */<br>
+      if ((newViewNumLayers % 6) != 0) {<br>
+         _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(clamped numlayers %d is not a multiple of 6)",<br>
</blockquote>
<br></div></div>
If that line's longer than 78 chars, can you wrap it?</blockquote><div>OK</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+                     newViewNumLayers);<br>
+         return;<br>
+      }<br>
+      break;<br>
+   }<br>
+<br>
+   /* If the new texture's target is TEXTURE_CUBE_MAP or<br>
+    * TEXTURE_CUBE_MAP_ARRAY, the width and height of the original texture's<br>
+    * levels must be equal otherwise the error INVALID_OPERATION is generated.<br>
+    */<br>
+   if ((target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) &&<br>
+       (origTexImage->Width != origTexImage->Height)) {<br>
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(origtexture width (%d) != height (%d))",<br>
+                  origTexImage->Width, origTexImage->Height);<br>
+      return;<br>
+   }<br>
+<br>
+   /* When the original texture's target is TEXTURE_CUBE_MAP, the layer<br>
+    * parameters are interpreted in the same order as if it were a<br>
+    * TEXTURE_CUBE_MAP_ARRAY with 6 layer-faces.<br>
+    */<br>
+<br>
+   /* If the internal format does not exactly match the internal format of the<br>
+    * original texture, the contents of the memory are reinterpreted in the<br>
+    * same manner as for image bindings described in<br>
+    * section 3.9.20 (Texture Image Loads and Stores).<br>
+    */<br>
+<br>
+   /* TEXTURE_BASE_LEVEL and TEXTURE_MAX_LEVEL are interpreted<br>
+    * relative to the view and not relative to the original data store.<br>
+    */<br>
+<br>
+   if (!initialize_texture_fields(<u></u>ctx, target, texObj, newViewNumLevels,<br>
+                                  width, height, depth,<br>
+                                  internalformat, texFormat)) {<br>
+      return; /* Already recorded error */<br>
+   }<br>
+<br>
+   texObj->MinLevel = newViewMinLevel;<br>
+   texObj->MinLayer = newViewMinLayer;<br>
+   texObj->NumLevels = newViewNumLevels;<br>
+   texObj->NumLayers = newViewNumLayers;<br>
+   texObj->Immutable = GL_TRUE;<br>
+   texObj->ImmutableLevels = origTexObj->ImmutableLevels;<br>
+   texObj->Target = target;<br>
</blockquote>
<br></div></div>
Maybe these assignments should be rolled into initialize_texture_fields()?</blockquote><div>Why?</div><div><br></div><div>initialize_texture_fields is initializing the teximage properties of the texture whereas the assignments are setting the texture object's properties.</div>
<div><br></div><div>Thanks for the feedback!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
+   if (!ctx->Driver.TextureView(ctx, texObj, origTexObj)) {<br>
+      return; /* driver recorded error */<br>
+   }<br>
  }<br>
<br>
</blockquote>
<br></div>
______________________________<u></u>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Courtney Goeltzenleuchter<br><div>LunarG</div><div><img src="http://media.lunarg.com/wp-content/themes/LunarG/images/logo.png" width="96" height="65"><br>
</div></div>
</div></div>