Add support for extension GL_ARB_shader_bit_encoding (#2183)
authorpmistryNV <63069047+pmistryNV@users.noreply.github.com>
Fri, 17 Apr 2020 11:24:12 +0000 (04:24 -0700)
committerGitHub <noreply@github.com>
Fri, 17 Apr 2020 11:24:12 +0000 (05:24 -0600)
Test/150.frag
Test/baseResults/150.frag.out
glslang/MachineIndependent/Initialize.cpp
glslang/MachineIndependent/Versions.cpp
glslang/MachineIndependent/Versions.h

index 1985d6e..e24dba0 100644 (file)
@@ -57,4 +57,25 @@ double type3 = 2.0;
 int absTest = sqrt(type3);\r
 double absTest2 = sqrt(type3);\r
 double absTest3 = sqrt(2);\r
-float dk = sqrt(11);
\ No newline at end of file
+float dk = sqrt(11);\r
+\r
+#extension GL_ARB_shader_bit_encoding: enable\r
+\r
+float f;\r
+vec4 v4;\r
+ivec4 iv4a;\r
+uvec2 uv2c;\r
+void bitEncodingPass()\r
+{\r
+    int i = floatBitsToInt(f);\r
+    uvec4 uv11 = floatBitsToUint(v4);\r
+    vec4 v14 = intBitsToFloat(iv4a);\r
+    vec2 v15 = uintBitsToFloat(uv2c);\r
+}\r
+\r
+#extension GL_ARB_shader_bit_encoding: disable\r
+\r
+void bitEncodingFail()\r
+{\r
+    int i = floatBitsToInt(f); // Error, extention GL_ARB_bit_encoding is diabled\r
+}\r
index 18c1953..4a55ea4 100644 (file)
@@ -9,11 +9,13 @@ ERROR: 0:53: 'double' : Reserved word.
 ERROR: 0:53: 'double' : not supported for this version or the enabled extensions 
 ERROR: 0:53: 'double' : must be qualified as flat in
 ERROR: 0:57: '=' :  cannot convert from ' global double' to ' global int'
-ERROR: 10 compilation errors.  No code generated.
+ERROR: 0:80: 'floatBitsToInt' : required extension not requested: GL_ARB_shader_bit_encoding
+ERROR: 11 compilation errors.  No code generated.
 
 
 Shader version: 150
 Requested GL_ARB_gpu_shader_fp64
+Requested GL_ARB_shader_bit_encoding
 gl_FragCoord pixel center is integer
 gl_FragCoord origin is upper left
 ERROR: node is still EOpNull!
@@ -134,6 +136,37 @@ ERROR: node is still EOpNull!
 0:60      'dk' ( global float)
 0:60      Constant:
 0:60        3.316625
+0:68  Function Definition: bitEncodingPass( ( global void)
+0:68    Function Parameters: 
+0:70    Sequence
+0:70      Sequence
+0:70        move second child to first child ( temp int)
+0:70          'i' ( temp int)
+0:70          floatBitsToInt ( global int)
+0:70            'f' ( global float)
+0:71      Sequence
+0:71        move second child to first child ( temp 4-component vector of uint)
+0:71          'uv11' ( temp 4-component vector of uint)
+0:71          floatBitsToUint ( global 4-component vector of uint)
+0:71            'v4' ( global 4-component vector of float)
+0:72      Sequence
+0:72        move second child to first child ( temp 4-component vector of float)
+0:72          'v14' ( temp 4-component vector of float)
+0:72          intBitsToFloat ( global 4-component vector of float)
+0:72            'iv4a' ( global 4-component vector of int)
+0:73      Sequence
+0:73        move second child to first child ( temp 2-component vector of float)
+0:73          'v15' ( temp 2-component vector of float)
+0:73          uintBitsToFloat ( global 2-component vector of float)
+0:73            'uv2c' ( global 2-component vector of uint)
+0:78  Function Definition: bitEncodingFail( ( global void)
+0:78    Function Parameters: 
+0:80    Sequence
+0:80      Sequence
+0:80        move second child to first child ( temp int)
+0:80          'i' ( temp int)
+0:80          floatBitsToInt ( global int)
+0:80            'f' ( global float)
 0:?   Linker Objects
 0:?     'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord)
 0:?     'foo' ( smooth in 4-component vector of float)
@@ -155,6 +188,10 @@ ERROR: node is still EOpNull!
 0:?     'absTest2' ( global double)
 0:?     'absTest3' ( global double)
 0:?     'dk' ( global float)
+0:?     'f' ( global float)
+0:?     'v4' ( global 4-component vector of float)
+0:?     'iv4a' ( global 4-component vector of int)
+0:?     'uv2c' ( global 2-component vector of uint)
 
 
 Linked fragment stage:
@@ -162,6 +199,7 @@ Linked fragment stage:
 
 Shader version: 150
 Requested GL_ARB_gpu_shader_fp64
+Requested GL_ARB_shader_bit_encoding
 gl_FragCoord pixel center is integer
 gl_FragCoord origin is upper left
 ERROR: node is still EOpNull!
@@ -218,4 +256,8 @@ ERROR: node is still EOpNull!
 0:?     'absTest2' ( global double)
 0:?     'absTest3' ( global double)
 0:?     'dk' ( global float)
+0:?     'f' ( global float)
+0:?     'v4' ( global 4-component vector of float)
+0:?     'iv4a' ( global 4-component vector of int)
+0:?     'uv2c' ( global 2-component vector of uint)
 
index 344594a..32106c7 100644 (file)
@@ -1262,7 +1262,7 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
 #endif
 
     if ((profile == EEsProfile && version >= 300) ||
-        (profile != EEsProfile && version >= 330)) {
+        (profile != EEsProfile && version >= 150)) { // GL_ARB_shader_bit_encoding
         commonBuiltins.append(
             "int   floatBitsToInt(highp float value);"
             "ivec2 floatBitsToInt(highp vec2  value);"
@@ -7816,6 +7816,13 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
         }
 
+        if (profile != EEsProfile && version < 330 ) {
+            symbolTable.setFunctionExtensions("floatBitsToInt", 1, &E_GL_ARB_shader_bit_encoding);
+            symbolTable.setFunctionExtensions("floatBitsToUint", 1, &E_GL_ARB_shader_bit_encoding);
+            symbolTable.setFunctionExtensions("intBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
+            symbolTable.setFunctionExtensions("uintBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
+        }
+
         symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
         BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
         symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
index d6b961d..2da1dbc 100644 (file)
@@ -197,6 +197,7 @@ void TParseVersions::initializeExtensionBehavior()
     extensionBehavior[E_GL_ARB_shader_clock]                 = EBhDisable;
     extensionBehavior[E_GL_ARB_uniform_buffer_object]        = EBhDisable;
     extensionBehavior[E_GL_ARB_sample_shading]               = EBhDisable;
+    extensionBehavior[E_GL_ARB_shader_bit_encoding]          = EBhDisable;
 
     extensionBehavior[E_GL_KHR_shader_subgroup_basic]            = EBhDisable;
     extensionBehavior[E_GL_KHR_shader_subgroup_vote]             = EBhDisable;
@@ -409,6 +410,7 @@ void TParseVersions::getPreamble(std::string& preamble)
             "#define GL_ARB_post_depth_coverage 1\n"
             "#define GL_ARB_fragment_shader_interlock 1\n"
             "#define GL_ARB_uniform_buffer_object 1\n"
+            "#define GL_ARB_shader_bit_encoding 1\n"
             "#define GL_EXT_shader_non_constant_global_initializers 1\n"
             "#define GL_EXT_shader_image_load_formatted 1\n"
             "#define GL_EXT_post_depth_coverage 1\n"
index 170efb0..f9ab2e2 100644 (file)
@@ -152,6 +152,7 @@ const char* const E_GL_ARB_fragment_shader_interlock    = "GL_ARB_fragment_shade
 const char* const E_GL_ARB_shader_clock                 = "GL_ARB_shader_clock";
 const char* const E_GL_ARB_uniform_buffer_object        = "GL_ARB_uniform_buffer_object";
 const char* const E_GL_ARB_sample_shading               = "GL_ARB_sample_shading";
+const char* const E_GL_ARB_shader_bit_encoding          = "GL_ARB_shader_bit_encoding";
 
 const char* const E_GL_KHR_shader_subgroup_basic            = "GL_KHR_shader_subgroup_basic";
 const char* const E_GL_KHR_shader_subgroup_vote             = "GL_KHR_shader_subgroup_vote";