[Mesa-dev] [PATCH 1/6] New unary opcodes for ARB_shader_bit_encoding support.

Olivier Galibert galibert at pobox.com
Tue May 8 11:40:32 PDT 2012


The opcodes are bitcast_f2u, bitcast_f2i, bitcast_i2f and bitcast_u2f.

Signed-off-by: Olivier Galibert <galibert at pobox.com>
---
 src/glsl/builtins/ir/floatBitsToInt.ir             |   21 ++++++++++++++++
 src/glsl/builtins/ir/floatBitsToUint.ir            |   21 ++++++++++++++++
 src/glsl/builtins/ir/intBitsToFloat.ir             |   21 ++++++++++++++++
 src/glsl/builtins/ir/uintBitsToFloat.ir            |   21 ++++++++++++++++
 .../builtins/profiles/ARB_shader_bit_encoding.glsl |   22 +++++++++++++++++
 src/glsl/ir.cpp                                    |    4 +++
 src/glsl/ir.h                                      |   26 +++++++++++---------
 7 files changed, 125 insertions(+), 11 deletions(-)
 create mode 100644 src/glsl/builtins/ir/floatBitsToInt.ir
 create mode 100644 src/glsl/builtins/ir/floatBitsToUint.ir
 create mode 100644 src/glsl/builtins/ir/intBitsToFloat.ir
 create mode 100644 src/glsl/builtins/ir/uintBitsToFloat.ir
 create mode 100644 src/glsl/builtins/profiles/ARB_shader_bit_encoding.glsl

diff --git a/src/glsl/builtins/ir/floatBitsToInt.ir b/src/glsl/builtins/ir/floatBitsToInt.ir
new file mode 100644
index 0000000..a5db4b3
--- /dev/null
+++ b/src/glsl/builtins/ir/floatBitsToInt.ir
@@ -0,0 +1,21 @@
+((function floatBitsToInt
+   (signature int
+     (parameters
+       (declare (in) float arg))
+     ((return (expression int bitcast_f2i (var_ref arg)))))
+
+   (signature ivec2
+     (parameters
+       (declare (in) vec2 arg))
+     ((return (expression ivec2 bitcast_f2i (var_ref arg)))))
+
+   (signature ivec3
+     (parameters
+       (declare (in) vec3 arg))
+     ((return (expression ivec3 bitcast_f2i (var_ref arg)))))
+
+   (signature ivec4
+     (parameters
+       (declare (in) vec4 arg))
+     ((return (expression ivec4 bitcast_f2i (var_ref arg)))))
+))
diff --git a/src/glsl/builtins/ir/floatBitsToUint.ir b/src/glsl/builtins/ir/floatBitsToUint.ir
new file mode 100644
index 0000000..09463bd
--- /dev/null
+++ b/src/glsl/builtins/ir/floatBitsToUint.ir
@@ -0,0 +1,21 @@
+((function floatBitsToUint
+   (signature uint
+     (parameters
+       (declare (in) float arg))
+     ((return (expression uint bitcast_f2u (var_ref arg)))))
+
+   (signature uvec2
+     (parameters
+       (declare (in) vec2 arg))
+     ((return (expression uvec2 bitcast_f2u (var_ref arg)))))
+
+   (signature uvec3
+     (parameters
+       (declare (in) vec3 arg))
+     ((return (expression uvec3 bitcast_f2u (var_ref arg)))))
+
+   (signature uvec4
+     (parameters
+       (declare (in) vec4 arg))
+     ((return (expression uvec4 bitcast_f2u (var_ref arg)))))
+))
diff --git a/src/glsl/builtins/ir/intBitsToFloat.ir b/src/glsl/builtins/ir/intBitsToFloat.ir
new file mode 100644
index 0000000..cc6aafe
--- /dev/null
+++ b/src/glsl/builtins/ir/intBitsToFloat.ir
@@ -0,0 +1,21 @@
+((function intBitsToFloat
+   (signature float
+     (parameters
+       (declare (in) int arg))
+     ((return (expression float bitcast_i2f (var_ref arg)))))
+
+   (signature vec2
+     (parameters
+       (declare (in) ivec2 arg))
+     ((return (expression vec2 bitcast_i2f (var_ref arg)))))
+
+   (signature vec3
+     (parameters
+       (declare (in) ivec3 arg))
+     ((return (expression vec3 bitcast_i2f (var_ref arg)))))
+
+   (signature vec4
+     (parameters
+       (declare (in) ivec4 arg))
+     ((return (expression vec4 bitcast_i2f (var_ref arg)))))
+))
diff --git a/src/glsl/builtins/ir/uintBitsToFloat.ir b/src/glsl/builtins/ir/uintBitsToFloat.ir
new file mode 100644
index 0000000..1073d76
--- /dev/null
+++ b/src/glsl/builtins/ir/uintBitsToFloat.ir
@@ -0,0 +1,21 @@
+((function uintBitsToFloat
+   (signature float
+     (parameters
+       (declare (in) uint arg))
+     ((return (expression float bitcast_u2f (var_ref arg)))))
+
+   (signature vec2
+     (parameters
+       (declare (in) uvec2 arg))
+     ((return (expression vec2 bitcast_u2f (var_ref arg)))))
+
+   (signature vec3
+     (parameters
+       (declare (in) uvec3 arg))
+     ((return (expression vec3 bitcast_u2f (var_ref arg)))))
+
+   (signature vec4
+     (parameters
+       (declare (in) uvec4 arg))
+     ((return (expression vec4 bitcast_u2f (var_ref arg)))))
+))
diff --git a/src/glsl/builtins/profiles/ARB_shader_bit_encoding.glsl b/src/glsl/builtins/profiles/ARB_shader_bit_encoding.glsl
new file mode 100644
index 0000000..e034594
--- /dev/null
+++ b/src/glsl/builtins/profiles/ARB_shader_bit_encoding.glsl
@@ -0,0 +1,22 @@
+#version 130
+#extension GL_ARB_shader_bit_encoding : enable
+
+int   floatBitsToInt(float value);
+ivec2 floatBitsToInt(vec2  value);
+ivec3 floatBitsToInt(vec3  value);
+ivec4 floatBitsToInt(vec4  value);
+
+uint  floatBitsToUint(float value);
+uvec2 floatBitsToUint(vec2  value);
+uvec3 floatBitsToUint(vec3  value);
+uvec4 floatBitsToUint(vec4  value);
+
+float intBitsToFloat(int   value);
+vec2  intBitsToFloat(ivec2 value);
+vec3  intBitsToFloat(ivec3 value);
+vec4  intBitsToFloat(ivec4 value);
+
+float uintBitsToFloat(uint  value);
+vec2  uintBitsToFloat(uvec2 value);
+vec3  uintBitsToFloat(uvec3 value);
+vec4  uintBitsToFloat(uvec4 value);
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index afe1d43..d83af50 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -427,6 +427,10 @@ static const char *const operator_strs[] = {
    "u2f",
    "i2u",
    "u2i",
+   "bitcast_i2f",
+   "bitcast_f2i",
+   "bitcast_u2f",
+   "bitcast_f2u",
    "any",
    "trunc",
    "ceil",
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 5a7ba88..0e997e4 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -864,19 +864,23 @@ enum ir_expression_operation {
    ir_unop_rcp,
    ir_unop_rsq,
    ir_unop_sqrt,
-   ir_unop_exp,      /**< Log base e on gentype */
-   ir_unop_log,	     /**< Natural log on gentype */
+   ir_unop_exp,         /**< Log base e on gentype */
+   ir_unop_log,	        /**< Natural log on gentype */
    ir_unop_exp2,
    ir_unop_log2,
-   ir_unop_f2i,      /**< Float-to-integer conversion. */
-   ir_unop_i2f,      /**< Integer-to-float conversion. */
-   ir_unop_f2b,      /**< Float-to-boolean conversion */
-   ir_unop_b2f,      /**< Boolean-to-float conversion */
-   ir_unop_i2b,      /**< int-to-boolean conversion */
-   ir_unop_b2i,      /**< Boolean-to-int conversion */
-   ir_unop_u2f,      /**< Unsigned-to-float conversion. */
-   ir_unop_i2u,      /**< Integer-to-unsigned conversion. */
-   ir_unop_u2i,      /**< Unsigned-to-integer conversion. */
+   ir_unop_f2i,         /**< Float-to-integer conversion. */
+   ir_unop_i2f,         /**< Integer-to-float conversion. */
+   ir_unop_f2b,         /**< Float-to-boolean conversion */
+   ir_unop_b2f,         /**< Boolean-to-float conversion */
+   ir_unop_i2b,         /**< int-to-boolean conversion */
+   ir_unop_b2i,         /**< Boolean-to-int conversion */
+   ir_unop_u2f,         /**< Unsigned-to-float conversion. */
+   ir_unop_i2u,         /**< Integer-to-unsigned conversion. */
+   ir_unop_u2i,         /**< Unsigned-to-integer conversion. */
+   ir_unop_bitcast_i2f, /**< Bit-identical int-to-float "conversion" */
+   ir_unop_bitcast_f2i, /**< Bit-identical float-to-int "conversion" */
+   ir_unop_bitcast_u2f, /**< Bit-identical uint-to-float "conversion" */
+   ir_unop_bitcast_f2u, /**< Bit-identical float-to-uint "conversion" */
    ir_unop_any,
 
    /**
-- 
1.7.10.rc3.1.gb306



More information about the mesa-dev mailing list