mesa: add GL_NV_viewport_swizzle support
authorIlia Mirkin <imirkin@alum.mit.edu>
Mon, 6 Apr 2020 05:56:48 +0000 (01:56 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sun, 12 Apr 2020 16:01:46 +0000 (12:01 -0400)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4519>

src/mapi/glapi/gen/NV_viewport_swizzle.xml [new file with mode: 0644]
src/mapi/glapi/gen/gl_API.xml
src/mapi/glapi/gen/meson.build
src/mapi/glapi/gen/static_data.py
src/mesa/main/extensions_table.h
src/mesa/main/get.c
src/mesa/main/get_hash_params.py
src/mesa/main/mtypes.h
src/mesa/main/tests/dispatch_sanity.cpp
src/mesa/main/viewport.c
src/mesa/main/viewport.h

diff --git a/src/mapi/glapi/gen/NV_viewport_swizzle.xml b/src/mapi/glapi/gen/NV_viewport_swizzle.xml
new file mode 100644 (file)
index 0000000..3b653bc
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
+
+<!-- Note: no GLX protocol info yet. -->
+
+<OpenGLAPI>
+
+<category name="GL_NV_viewport_swizzle" number="483">
+
+    <function name="ViewportSwizzleNV" no_error="true" es2="3.1">
+        <param name="index" type="GLuint"/>
+        <param name="swizzlex" type="GLenum"/>
+        <param name="swizzley" type="GLenum"/>
+        <param name="swizzlez" type="GLenum"/>
+        <param name="swizzlew" type="GLenum"/>
+    </function>
+
+    <enum name="VIEWPORT_SWIZZLE_POSITIVE_X_NV" value="0x9350"/>
+    <enum name="VIEWPORT_SWIZZLE_NEGATIVE_X_NV" value="0x9351"/>
+    <enum name="VIEWPORT_SWIZZLE_POSITIVE_Y_NV" value="0x9352"/>
+    <enum name="VIEWPORT_SWIZZLE_NEGATIVE_Y_NV" value="0x9353"/>
+    <enum name="VIEWPORT_SWIZZLE_POSITIVE_Z_NV" value="0x9354"/>
+    <enum name="VIEWPORT_SWIZZLE_NEGATIVE_Z_NV" value="0x9355"/>
+    <enum name="VIEWPORT_SWIZZLE_POSITIVE_W_NV" value="0x9358"/>
+    <enum name="VIEWPORT_SWIZZLE_NEGATIVE_W_NV" value="0x9357"/>
+
+    <enum name="VIEWPORT_SWIZZLE_X_NV" value="0x9358"/>
+    <enum name="VIEWPORT_SWIZZLE_Y_NV" value="0x9359"/>
+    <enum name="VIEWPORT_SWIZZLE_Z_NV" value="0x935A"/>
+    <enum name="VIEWPORT_SWIZZLE_W_NV" value="0x935B"/>
+
+</category>
+
+</OpenGLAPI>
index 8c64eed6dae439cbd77f9809e57aeb46c1fbb4d0..4188bbf198689cdc199dc210aa1c35f48e59a251 100644 (file)
 <xi:include href="EXT_external_objects.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 <xi:include href="EXT_external_objects_fd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
+<xi:include href="NV_viewport_swizzle.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
 <xi:include href="GL4x.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
 </OpenGLAPI>
index d04ccf19ae4f1c58a7c82fcf91975dd305bd1c9c..8f9a08f5294d429e031e641d5b0d0f63c132698c 100644 (file)
@@ -138,6 +138,7 @@ api_xml_files = files(
   'NV_primitive_restart.xml',
   'NV_texture_barrier.xml',
   'NV_vdpau_interop.xml',
+  'NV_viewport_swizzle.xml',
   'OES_EGL_image.xml',
   'OES_fixed_point.xml',
   'OES_single_precision.xml',
index 367b51338b94d3985006fd5f11f6421319e0eaa4..99be40aac6e1830d3dcf111d82b9541d167867ac 100644 (file)
@@ -1641,6 +1641,7 @@ offsets = {
     "EGLImageTargetTexStorageEXT" : 1605,
     "EGLImageTargetTextureStorageEXT" : 1606,
     "CopyImageSubDataNV": 1607,
+    "ViewportSwizzleNV": 1608,
 }
 
 functions = [
index 9a678e247b8aece8ff925cc3d942494dbcf8981d..5239a230cfde66e242dcd67e8f15133f8a8108d9 100644 (file)
@@ -402,6 +402,7 @@ EXT(NV_texture_barrier                      , NV_texture_barrier
 EXT(NV_texture_env_combine4                 , NV_texture_env_combine4                , GLL,  x ,  x ,  x , 1999)
 EXT(NV_texture_rectangle                    , NV_texture_rectangle                   , GLL,  x ,  x ,  x , 2000)
 EXT(NV_vdpau_interop                        , NV_vdpau_interop                       , GLL, GLC,  x ,  x , 2010)
+EXT(NV_viewport_swizzle                     , NV_viewport_swizzle                    , GLL, GLC,  x ,  31, 2015)
 
 EXT(OES_EGL_image                           , OES_EGL_image                          , GLL, GLC, ES1, ES2, 2006) /* FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
 EXT(OES_EGL_image_external                  , OES_EGL_image_external                 ,  x ,  x , ES1, ES2, 2010)
index 083155171677e1536095d341fbcddb3ad8cc7a82..7e9767d95e135df9db38b5418e6baa41a72f0bc2 100644 (file)
@@ -561,6 +561,7 @@ EXTRA_EXT(NV_conservative_raster_pre_snap_triangles);
 EXTRA_EXT(ARB_sample_locations);
 EXTRA_EXT(AMD_framebuffer_multisample_advanced);
 EXTRA_EXT(ARB_spirv_extensions);
+EXTRA_EXT(NV_viewport_swizzle);
 
 static const int
 extra_ARB_color_buffer_float_or_glcore[] = {
@@ -1326,6 +1327,20 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
       memcpy(v->value_int_n.ints, ctx->Const.SupportedMultisampleModes,
              v->value_int_n.n * sizeof(GLint));
       break;
+
+   /* GL_NV_viewport_swizzle */
+   case GL_VIEWPORT_SWIZZLE_X_NV:
+      v->value_enum = ctx->ViewportArray[0].SwizzleX;
+      break;
+   case GL_VIEWPORT_SWIZZLE_Y_NV:
+      v->value_enum = ctx->ViewportArray[0].SwizzleY;
+      break;
+   case GL_VIEWPORT_SWIZZLE_Z_NV:
+      v->value_enum = ctx->ViewportArray[0].SwizzleZ;
+      break;
+   case GL_VIEWPORT_SWIZZLE_W_NV:
+      v->value_enum = ctx->ViewportArray[0].SwizzleW;
+      break;
    }
 }
 
@@ -2825,6 +2840,35 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
          goto invalid_enum;
       v->value_matrix = ctx->TextureMatrixStack[index].Top;
       return TYPE_MATRIX_T;
+   /* GL_NV_viewport_swizzle */
+   case GL_VIEWPORT_SWIZZLE_X_NV:
+      if (!ctx->Extensions.NV_viewport_swizzle)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxViewports)
+         goto invalid_value;
+      v->value_int = ctx->ViewportArray[index].SwizzleX;
+      return TYPE_INT;
+   case GL_VIEWPORT_SWIZZLE_Y_NV:
+      if (!ctx->Extensions.NV_viewport_swizzle)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxViewports)
+         goto invalid_value;
+      v->value_int = ctx->ViewportArray[index].SwizzleY;
+      return TYPE_INT;
+   case GL_VIEWPORT_SWIZZLE_Z_NV:
+      if (!ctx->Extensions.NV_viewport_swizzle)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxViewports)
+         goto invalid_value;
+      v->value_int = ctx->ViewportArray[index].SwizzleZ;
+      return TYPE_INT;
+   case GL_VIEWPORT_SWIZZLE_W_NV:
+      if (!ctx->Extensions.NV_viewport_swizzle)
+         goto invalid_enum;
+      if (index >= ctx->Const.MaxViewports)
+         goto invalid_value;
+      v->value_int = ctx->ViewportArray[index].SwizzleW;
+      return TYPE_INT;
    }
 
  invalid_enum:
index bd56b4e6c0061cc9e63484e7fb3194f7373b4fe2..31563679593b938d8d1af5561533dfd262c3338d 100644 (file)
@@ -668,6 +668,12 @@ descriptor=[
 
 # INTEL_conservative_rasterization
   [ "CONSERVATIVE_RASTERIZATION_INTEL", "CONTEXT_BOOL(IntelConservativeRasterization), extra_INTEL_conservative_rasterization" ],
+
+# GL_NV_viewport_swizzle
+  [ "VIEWPORT_SWIZZLE_X_NV", "LOC_CUSTOM, TYPE_ENUM, 0, extra_NV_viewport_swizzle" ],
+  [ "VIEWPORT_SWIZZLE_Y_NV", "LOC_CUSTOM, TYPE_ENUM, 0, extra_NV_viewport_swizzle" ],
+  [ "VIEWPORT_SWIZZLE_Z_NV", "LOC_CUSTOM, TYPE_ENUM, 0, extra_NV_viewport_swizzle" ],
+  [ "VIEWPORT_SWIZZLE_W_NV", "LOC_CUSTOM, TYPE_ENUM, 0, extra_NV_viewport_swizzle" ],
 ]},
 
 # Enums in OpenGL and ES 3.2
index 86b1a7035b886365be900e2aa3e6b8db22d7f0c2..7560a828b324c0b11c6449ae83786a676b8ab112 100644 (file)
@@ -1312,6 +1312,9 @@ struct gl_viewport_attrib
    GLfloat X, Y;               /**< position */
    GLfloat Width, Height;      /**< size */
    GLfloat Near, Far;          /**< Depth buffer range */
+
+   /**< GL_NV_viewport_swizzle */
+   GLenum16 SwizzleX, SwizzleY, SwizzleZ, SwizzleW;
 };
 
 
@@ -4438,6 +4441,7 @@ struct gl_extensions
    GLboolean NV_conservative_raster_dilate;
    GLboolean NV_conservative_raster_pre_snap_triangles;
    GLboolean NV_conservative_raster_pre_snap;
+   GLboolean NV_viewport_swizzle;
    GLboolean NVX_gpu_memory_info;
    GLboolean TDFX_texture_compression_FXT1;
    GLboolean OES_EGL_image;
index f03317a2d5fa9110a9009877d7c1b4bfb6349080..69dd56598e2402e31b3286b6f03116f4f99be811 100644 (file)
@@ -1435,6 +1435,9 @@ const struct function common_desktop_functions_possible[] = {
    { "glProgramUniform3ui64vARB", 40, -1 },
    { "glProgramUniform4ui64vARB", 40, -1 },
 
+   /* GL_NV_viewport_swizzle */
+   { "glViewportSwizzleNV", 11, -1 },
+
    { NULL, 0, -1 }
 };
 
@@ -2770,5 +2773,8 @@ const struct function gles31_functions_possible[] = {
    { "glNamedFramebufferSampleLocationsfvARB", 31, -1 },
    { "glEvaluateDepthValuesARB", 31, -1 },
 
+   /* GL_NV_viewport_swizzle */
+   { "glViewportSwizzleNV", 31, -1 },
+
    { NULL, 0, -1 },
  };
index f4dc74ae41a02e66f06fbaff81274ec11ce01e97..a501e245626f2acb45d98ea339db627462d17e09 100644 (file)
@@ -488,6 +488,10 @@ void _mesa_init_viewport(struct gl_context *ctx)
       ctx->ViewportArray[i].Height = 0;
       ctx->ViewportArray[i].Near = 0.0;
       ctx->ViewportArray[i].Far = 1.0;
+      ctx->ViewportArray[i].SwizzleX = GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV;
+      ctx->ViewportArray[i].SwizzleY = GL_VIEWPORT_SWIZZLE_POSITIVE_Y_NV;
+      ctx->ViewportArray[i].SwizzleZ = GL_VIEWPORT_SWIZZLE_POSITIVE_Z_NV;
+      ctx->ViewportArray[i].SwizzleW = GL_VIEWPORT_SWIZZLE_POSITIVE_W_NV;
    }
 
    ctx->SubpixelPrecisionBias[0] = 0;
@@ -658,3 +662,96 @@ _mesa_SubpixelPrecisionBiasNV(GLuint xbits, GLuint ybits)
 
    subpixel_precision_bias(ctx, xbits, ybits);
 }
+
+static void
+set_viewport_swizzle(struct gl_context *ctx, GLuint index,
+                     GLenum swizzlex, GLenum swizzley,
+                     GLenum swizzlez, GLenum swizzlew)
+{
+   struct gl_viewport_attrib *viewport = &ctx->ViewportArray[index];
+   if (viewport->SwizzleX == swizzlex &&
+       viewport->SwizzleY == swizzley &&
+       viewport->SwizzleZ == swizzlez &&
+       viewport->SwizzleW == swizzlew)
+      return;
+
+   FLUSH_VERTICES(ctx, _NEW_VIEWPORT);
+   ctx->NewDriverState |= ctx->DriverFlags.NewViewport;
+
+   viewport->SwizzleX = swizzlex;
+   viewport->SwizzleY = swizzley;
+   viewport->SwizzleZ = swizzlez;
+   viewport->SwizzleW = swizzlew;
+}
+
+void GLAPIENTRY
+_mesa_ViewportSwizzleNV_no_error(GLuint index,
+                                 GLenum swizzlex, GLenum swizzley,
+                                 GLenum swizzlez, GLenum swizzlew)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glViewportSwizzleNV(%x, %x, %x, %x)\n",
+                  swizzlex, swizzley, swizzlez, swizzlew);
+
+   set_viewport_swizzle(ctx, index, swizzlex, swizzley, swizzlez, swizzlew);
+}
+
+static bool
+verify_viewport_swizzle(GLenum swizzle)
+{
+   return swizzle >= GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV &&
+      swizzle <= GL_VIEWPORT_SWIZZLE_NEGATIVE_W_NV;
+}
+
+void GLAPIENTRY
+_mesa_ViewportSwizzleNV(GLuint index,
+                        GLenum swizzlex, GLenum swizzley,
+                        GLenum swizzlez, GLenum swizzlew)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glViewportSwizzleNV(%x, %x, %x, %x)\n",
+                  swizzlex, swizzley, swizzlez, swizzlew);
+
+   if (!ctx->Extensions.NV_viewport_swizzle) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glViewportSwizzleNV not supported");
+      return;
+   }
+
+   if (index >= ctx->Const.MaxViewports) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glViewportSwizzleNV: index (%d) >= MaxViewports (%d)",
+                  index, ctx->Const.MaxViewports);
+      return;
+   }
+
+   if (!verify_viewport_swizzle(swizzlex)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glViewportSwizzleNV(swizzlex=%x)", swizzlex);
+      return;
+   }
+
+   if (!verify_viewport_swizzle(swizzley)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glViewportSwizzleNV(swizzley=%x)", swizzley);
+      return;
+   }
+
+   if (!verify_viewport_swizzle(swizzlez)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glViewportSwizzleNV(swizzlez=%x)", swizzlez);
+      return;
+   }
+
+   if (!verify_viewport_swizzle(swizzlew)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glViewportSwizzleNV(swizzlew=%x)", swizzlew);
+      return;
+   }
+
+   set_viewport_swizzle(ctx, index, swizzlex, swizzley, swizzlez, swizzlew);
+}
index aca62965b0678f5583e2caa62b893c61e80d1297..655873d4774078318b73ba5a5b5c9ba9b8608abd 100644 (file)
@@ -110,4 +110,14 @@ _mesa_SubpixelPrecisionBiasNV_no_error(GLuint xbits, GLuint ybits);
 extern void GLAPIENTRY
 _mesa_SubpixelPrecisionBiasNV(GLuint xbits, GLuint ybits);
 
+extern void GLAPIENTRY
+_mesa_ViewportSwizzleNV_no_error(GLuint index,
+                                 GLenum swizzlex, GLenum swizzley,
+                                 GLenum swizzlez, GLenum swizzlew);
+
+extern void GLAPIENTRY
+_mesa_ViewportSwizzleNV(GLuint index,
+                        GLenum swizzlex, GLenum swizzley,
+                        GLenum swizzlez, GLenum swizzlew);
+
 #endif