Skip to content

Commit

Permalink
Add support for extension GL_ARB_shader_bit_encoding (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmistryNV committed Apr 17, 2020
1 parent 4d2298b commit 9f46e3d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
23 changes: 22 additions & 1 deletion Test/150.frag
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,25 @@ double type3 = 2.0;
int absTest = sqrt(type3);
double absTest2 = sqrt(type3);
double absTest3 = sqrt(2);
float dk = sqrt(11);
float dk = sqrt(11);

#extension GL_ARB_shader_bit_encoding: enable

float f;
vec4 v4;
ivec4 iv4a;
uvec2 uv2c;
void bitEncodingPass()
{
int i = floatBitsToInt(f);
uvec4 uv11 = floatBitsToUint(v4);
vec4 v14 = intBitsToFloat(iv4a);
vec2 v15 = uintBitsToFloat(uv2c);
}

#extension GL_ARB_shader_bit_encoding: disable

void bitEncodingFail()
{
int i = floatBitsToInt(f); // Error, extention GL_ARB_bit_encoding is diabled
}
44 changes: 43 additions & 1 deletion Test/baseResults/150.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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)
Expand All @@ -155,13 +188,18 @@ 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:


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!
Expand Down Expand Up @@ -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)

9 changes: 8 additions & 1 deletion glslang/MachineIndependent/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions glslang/MachineIndependent/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions glslang/MachineIndependent/Versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 9f46e3d

Please sign in to comment.