aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2020-01-28 19:48:50 -0500
committerMarek Olšák <[email protected]>2020-02-04 15:12:03 -0500
commit56de59b931ac162de932d650176fbd981cc68aed (patch)
tree77a99fb3c04778562a6f59c987246dbad5762fd2 /src
parent052e8f758e68061adaee7f6f95bdbb01ae8f519d (diff)
vbo: move reusable code from vbo_attrib_tmp.h into vbo_util.h
Reviewed-by: Kristian H. Kristensen <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3611>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/Makefile.sources3
-rw-r--r--src/mesa/meson.build1
-rw-r--r--src/mesa/vbo/vbo_attrib_tmp.h98
-rw-r--r--src/mesa/vbo/vbo_util.h131
4 files changed, 135 insertions, 98 deletions
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 2d302c40d51..f55ae3de302 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -422,7 +422,8 @@ VBO_FILES = \
vbo/vbo_save.c \
vbo/vbo_save_draw.c \
vbo/vbo_save.h \
- vbo/vbo_save_loopback.c
+ vbo/vbo_save_loopback.c \
+ vbo/vbo_util.h
STATETRACKER_FILES = \
state_tracker/st_atifs_to_tgsi.c \
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index 06b38fbe3b6..1060cfe3388 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -347,6 +347,7 @@ files_libmesa_common = files(
'vbo/vbo_save_draw.c',
'vbo/vbo_save.h',
'vbo/vbo_save_loopback.c',
+ 'vbo/vbo_util.h',
'x86/common_x86.c',
)
diff --git a/src/mesa/vbo/vbo_attrib_tmp.h b/src/mesa/vbo/vbo_attrib_tmp.h
index 5c4beb540bf..ff3304b8458 100644
--- a/src/mesa/vbo/vbo_attrib_tmp.h
+++ b/src/mesa/vbo/vbo_attrib_tmp.h
@@ -27,6 +27,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "util/format_r11g11b10f.h"
#include "main/varray.h"
+#include "vbo_util.h"
/* ATTR */
@@ -80,16 +81,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#define MAT_ATTR( A, N, V ) ATTRF( A, N, (V)[0], (V)[1], (V)[2], (V)[3] )
-static inline float conv_ui10_to_norm_float(unsigned ui10)
-{
- return ui10 / 1023.0f;
-}
-
-static inline float conv_ui2_to_norm_float(unsigned ui2)
-{
- return ui2 / 3.0f;
-}
-
#define ATTRUI10_1( A, UI ) ATTRF( A, 1, (UI) & 0x3ff, 0, 0, 1 )
#define ATTRUI10_2( A, UI ) ATTRF( A, 2, (UI) & 0x3ff, ((UI) >> 10) & 0x3ff, 0, 1 )
#define ATTRUI10_3( A, UI ) ATTRF( A, 3, (UI) & 0x3ff, ((UI) >> 10) & 0x3ff, ((UI) >> 20) & 0x3ff, 1 )
@@ -109,73 +100,6 @@ static inline float conv_ui2_to_norm_float(unsigned ui2)
conv_ui10_to_norm_float(((UI) >> 20) & 0x3ff), \
conv_ui2_to_norm_float(((UI) >> 30) & 0x3) )
-struct attr_bits_10 {signed int x:10;};
-struct attr_bits_2 {signed int x:2;};
-
-static inline float conv_i10_to_i(int i10)
-{
- struct attr_bits_10 val;
- val.x = i10;
- return (float)val.x;
-}
-
-static inline float conv_i2_to_i(int i2)
-{
- struct attr_bits_2 val;
- val.x = i2;
- return (float)val.x;
-}
-
-static inline float conv_i10_to_norm_float(const struct gl_context *ctx, int i10)
-{
- struct attr_bits_10 val;
- val.x = i10;
-
- /* Traditionally, OpenGL has had two equations for converting from
- * normalized fixed-point data to floating-point data. In the OpenGL 3.2
- * specification, these are equations 2.2 and 2.3, respectively:
- *
- * f = (2c + 1)/(2^b - 1). (2.2)
- *
- * Comments below this equation state: "In general, this representation is
- * used for signed normalized fixed-point parameters in GL commands, such
- * as vertex attribute values." Which is what we're doing here.
- *
- * f = max{c/(2^(b-1) - 1), -1.0} (2.3)
- *
- * Comments below this equation state: "In general, this representation is
- * used for signed normalized fixed-point texture or floating point values."
- *
- * OpenGL 4.2+ and ES 3.0 remedy this and state that equation 2.3 (above)
- * is used in every case. They remove equation 2.2 completely.
- */
- if (_mesa_is_gles3(ctx) ||
- (_mesa_is_desktop_gl(ctx) && ctx->Version >= 42)) {
- /* Equation 2.3 above. */
- float f = ((float) val.x) / 511.0F;
- return MAX2(f, -1.0f);
- } else {
- /* Equation 2.2 above. */
- return (2.0F * (float)val.x + 1.0F) * (1.0F / 1023.0F);
- }
-}
-
-static inline float conv_i2_to_norm_float(const struct gl_context *ctx, int i2)
-{
- struct attr_bits_2 val;
- val.x = i2;
-
- if (_mesa_is_gles3(ctx) ||
- (_mesa_is_desktop_gl(ctx) && ctx->Version >= 42)) {
- /* Equation 2.3 above. */
- float f = (float) val.x;
- return MAX2(f, -1.0f);
- } else {
- /* Equation 2.2 above. */
- return (2.0F * (float)val.x + 1.0F) * (1.0F / 3.0F);
- }
-}
-
#define ATTRI10_1( A, I10 ) ATTRF( A, 1, conv_i10_to_i((I10) & 0x3ff), 0, 0, 1 )
#define ATTRI10_2( A, I10 ) ATTRF( A, 2, \
conv_i10_to_i((I10) & 0x3ff), \
@@ -868,26 +792,6 @@ TAG(VertexAttrib4fvNV)(GLuint index, const GLfloat * v)
ATTR4FV(index, v);
}
-
-#define ERROR_IF_NOT_PACKED_TYPE(ctx, type, func) \
- if (type != GL_INT_2_10_10_10_REV && type != GL_UNSIGNED_INT_2_10_10_10_REV) { \
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(type)", func); \
- return; \
- }
-
-/* Extended version of ERROR_IF_NOT_PACKED_TYPE which also
- * accepts GL_UNSIGNED_INT_10F_11F_11F_REV.
- *
- * Only used for VertexAttribP[123]ui[v]; VertexAttribP4* cannot use this type,
- * and neither can legacy vertex attribs.
- */
-#define ERROR_IF_NOT_PACKED_TYPE_EXT(ctx, type, func) \
- if (type != GL_INT_2_10_10_10_REV && type != GL_UNSIGNED_INT_2_10_10_10_REV && \
- type != GL_UNSIGNED_INT_10F_11F_11F_REV) { \
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(type)", func); \
- return; \
- }
-
static void GLAPIENTRY
TAG(VertexP2ui)(GLenum type, GLuint value)
{
diff --git a/src/mesa/vbo/vbo_util.h b/src/mesa/vbo/vbo_util.h
new file mode 100644
index 00000000000..2748bff5ecc
--- /dev/null
+++ b/src/mesa/vbo/vbo_util.h
@@ -0,0 +1,131 @@
+/**************************************************************************
+ *
+ * Copyright 2002 VMware, Inc.
+ * Copyright 2011 Dave Airlie (ARB_vertex_type_2_10_10_10_rev support)
+ * Copyright 2020 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef VBO_UTIL_H
+#define VBO_UTIL_H
+
+#include "main/mtypes.h"
+
+static inline float conv_ui10_to_norm_float(unsigned ui10)
+{
+ return ui10 / 1023.0f;
+}
+
+static inline float conv_ui2_to_norm_float(unsigned ui2)
+{
+ return ui2 / 3.0f;
+}
+
+struct attr_bits_10 {signed int x:10;};
+struct attr_bits_2 {signed int x:2;};
+
+static inline float conv_i10_to_i(int i10)
+{
+ struct attr_bits_10 val;
+ val.x = i10;
+ return (float)val.x;
+}
+
+static inline float conv_i2_to_i(int i2)
+{
+ struct attr_bits_2 val;
+ val.x = i2;
+ return (float)val.x;
+}
+
+static inline float conv_i10_to_norm_float(const struct gl_context *ctx, int i10)
+{
+ struct attr_bits_10 val;
+ val.x = i10;
+
+ /* Traditionally, OpenGL has had two equations for converting from
+ * normalized fixed-point data to floating-point data. In the OpenGL 3.2
+ * specification, these are equations 2.2 and 2.3, respectively:
+ *
+ * f = (2c + 1)/(2^b - 1). (2.2)
+ *
+ * Comments below this equation state: "In general, this representation is
+ * used for signed normalized fixed-point parameters in GL commands, such
+ * as vertex attribute values." Which is what we're doing here.
+ *
+ * f = max{c/(2^(b-1) - 1), -1.0} (2.3)
+ *
+ * Comments below this equation state: "In general, this representation is
+ * used for signed normalized fixed-point texture or floating point values."
+ *
+ * OpenGL 4.2+ and ES 3.0 remedy this and state that equation 2.3 (above)
+ * is used in every case. They remove equation 2.2 completely.
+ */
+ if (_mesa_is_gles3(ctx) ||
+ (_mesa_is_desktop_gl(ctx) && ctx->Version >= 42)) {
+ /* Equation 2.3 above. */
+ float f = ((float) val.x) / 511.0F;
+ return MAX2(f, -1.0f);
+ } else {
+ /* Equation 2.2 above. */
+ return (2.0F * (float)val.x + 1.0F) * (1.0F / 1023.0F);
+ }
+}
+
+static inline float conv_i2_to_norm_float(const struct gl_context *ctx, int i2)
+{
+ struct attr_bits_2 val;
+ val.x = i2;
+
+ if (_mesa_is_gles3(ctx) ||
+ (_mesa_is_desktop_gl(ctx) && ctx->Version >= 42)) {
+ /* Equation 2.3 above. */
+ float f = (float) val.x;
+ return MAX2(f, -1.0f);
+ } else {
+ /* Equation 2.2 above. */
+ return (2.0F * (float)val.x + 1.0F) * (1.0F / 3.0F);
+ }
+}
+
+#define ERROR_IF_NOT_PACKED_TYPE(ctx, type, func) \
+ if (type != GL_INT_2_10_10_10_REV && type != GL_UNSIGNED_INT_2_10_10_10_REV) { \
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(type)", func); \
+ return; \
+ }
+
+/* Extended version of ERROR_IF_NOT_PACKED_TYPE which also
+ * accepts GL_UNSIGNED_INT_10F_11F_11F_REV.
+ *
+ * Only used for VertexAttribP[123]ui[v]; VertexAttribP4* cannot use this type,
+ * and neither can legacy vertex attribs.
+ */
+#define ERROR_IF_NOT_PACKED_TYPE_EXT(ctx, type, func) \
+ if (type != GL_INT_2_10_10_10_REV && type != GL_UNSIGNED_INT_2_10_10_10_REV && \
+ type != GL_UNSIGNED_INT_10F_11F_11F_REV) { \
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(type)", func); \
+ return; \
+ }
+
+#endif