Skip to content

Commit

Permalink
Add support for extension GL_ARB_shader_storage_buffer_object
Browse files Browse the repository at this point in the history
Enable below features for GL Core version 420:
* layout qualifier "std430"
* storage qualifier "buffer"
* atomic memory functions
  • Loading branch information
pmistryNV committed Apr 20, 2020
1 parent 3f4e5c4 commit 9c12b8f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 12 deletions.
28 changes: 28 additions & 0 deletions Test/420.frag
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,31 @@ uniform writeonly image2D i2D;
ivec2 iv2dim = imageSize(i2D); // ERROR: imageSize called without enabling GL_ARB_shader_image_size extension
#extension GL_ARB_shader_image_size : enable
ivec2 iv2dim1 = imageSize(i2D);

#extension GL_ARB_shader_storage_buffer_object : enable

layout(binding = 0,std430) buffer Buffer
{
int atomi;
uint atomu;
};

void atomicOpPass()
{
int origi = atomicAdd(atomi, 3);
uint origu = atomicAnd(atomu, 7u);
origi = atomicExchange(atomi, 4);
origu = atomicCompSwap(atomu, 10u, 8u);
}

#extension GL_ARB_shader_storage_buffer_object : disable

layout(binding = 1,std430) buffer BufferFail // Error std430 and "buffer" block support disabled
{
int atom1i;
};

void atomicOpFail()
{
int origi = atomicAdd(atom1i, 3); // Error, atomic operations disabled
}
67 changes: 66 additions & 1 deletion Test/baseResults/420.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ ERROR: 0:11: 'layout qualifier' : can only apply depth layout to gl_FragDepth
ERROR: 0:12: 'gl_FragDepth' : cannot redeclare after use
ERROR: 0:14: 'atomic_uint' : array must be explicitly sized
ERROR: 0:17: 'imageSize' : required extension not requested: GL_ARB_shader_image_size
ERROR: 5 compilation errors. No code generated.
ERROR: 0:39: 'std430' : not supported for this version or the enabled extensions
ERROR: 0:39: 'buffer block' : not supported for this version or the enabled extensions
ERROR: 0:46: 'atomicAdd' : required extension not requested: GL_ARB_shader_storage_buffer_object
ERROR: 8 compilation errors. No code generated.


Shader version: 420
Requested GL_ARB_shader_image_size
Requested GL_ARB_shader_storage_buffer_object
using depth_any
ERROR: node is still EOpNull!
0:6 Function Definition: main( ( global void)
Expand All @@ -28,20 +32,79 @@ ERROR: node is still EOpNull!
0:19 'iv2dim1' ( global 2-component vector of int)
0:19 imageQuerySize ( global 2-component vector of int)
0:19 'i2D' ( writeonly uniform image2D)
0:29 Function Definition: atomicOpPass( ( global void)
0:29 Function Parameters:
0:31 Sequence
0:31 Sequence
0:31 move second child to first child ( temp int)
0:31 'origi' ( temp int)
0:31 AtomicAdd ( global int)
0:31 atomi: direct index for structure (layout( column_major std430 offset=0) buffer int)
0:31 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:31 Constant:
0:31 0 (const uint)
0:31 Constant:
0:31 3 (const int)
0:32 Sequence
0:32 move second child to first child ( temp uint)
0:32 'origu' ( temp uint)
0:32 AtomicAnd ( global uint)
0:32 atomu: direct index for structure (layout( column_major std430 offset=4) buffer uint)
0:32 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:32 Constant:
0:32 1 (const uint)
0:32 Constant:
0:32 7 (const uint)
0:33 move second child to first child ( temp int)
0:33 'origi' ( temp int)
0:33 AtomicExchange ( global int)
0:33 atomi: direct index for structure (layout( column_major std430 offset=0) buffer int)
0:33 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:33 Constant:
0:33 0 (const uint)
0:33 Constant:
0:33 4 (const int)
0:34 move second child to first child ( temp uint)
0:34 'origu' ( temp uint)
0:34 AtomicCompSwap ( global uint)
0:34 atomu: direct index for structure (layout( column_major std430 offset=4) buffer uint)
0:34 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:34 Constant:
0:34 1 (const uint)
0:34 Constant:
0:34 10 (const uint)
0:34 Constant:
0:34 8 (const uint)
0:44 Function Definition: atomicOpFail( ( global void)
0:44 Function Parameters:
0:46 Sequence
0:46 Sequence
0:46 move second child to first child ( temp int)
0:46 'origi' ( temp int)
0:46 AtomicAdd ( global int)
0:46 atom1i: direct index for structure (layout( column_major std430 offset=0) buffer int)
0:46 'anon@1' (layout( binding=1 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atom1i})
0:46 Constant:
0:46 0 (const uint)
0:46 Constant:
0:46 3 (const int)
0:? Linker Objects
0:? 'gl_FragDepth' ( gl_FragDepth float FragDepth)
0:? 'depth' ( smooth in float)
0:? 'a' (layout( binding=0 offset=0) uniform unsized 1-element array of atomic_uint)
0:? 'i2D' ( writeonly uniform image2D)
0:? 'iv2dim' ( global 2-component vector of int)
0:? 'iv2dim1' ( global 2-component vector of int)
0:? 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:? 'anon@1' (layout( binding=1 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atom1i})


Linked fragment stage:


Shader version: 420
Requested GL_ARB_shader_image_size
Requested GL_ARB_shader_storage_buffer_object
using depth_any
ERROR: node is still EOpNull!
0:6 Function Definition: main( ( global void)
Expand All @@ -68,4 +131,6 @@ ERROR: node is still EOpNull!
0:? 'i2D' ( writeonly uniform image2D)
0:? 'iv2dim' ( global 2-component vector of int)
0:? 'iv2dim1' ( global 2-component vector of int)
0:? 'anon@0' (layout( binding=0 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atomi, layout( column_major std430 offset=4) buffer uint atomu})
0:? 'anon@1' (layout( binding=1 column_major std430) buffer block{layout( column_major std430 offset=0) buffer int atom1i})

33 changes: 25 additions & 8 deletions glslang/MachineIndependent/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECo
{ EBadProfile } };
const Versioning* Es300Desktop130 = &Es300Desktop130Version[0];

const Versioning Es310Desktop420Version[] = { { EEsProfile, 0, 310, 0, nullptr },
{ EDesktopProfile, 0, 420, 0, nullptr },
{ EBadProfile } };
const Versioning* Es310Desktop420 = &Es310Desktop420Version[0];

const Versioning Es310Desktop430Version[] = { { EEsProfile, 0, 310, 0, nullptr },
{ EDesktopProfile, 0, 430, 0, nullptr },
{ EBadProfile } };
Expand Down Expand Up @@ -256,14 +261,14 @@ const BuiltInFunction BaseFunctions[] = {
{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeU, ClassBNS, Es300Desktop130 },
{ EOpVectorEqual, "equal", 2, TypeU, ClassBNS, Es300Desktop130 },
{ EOpVectorNotEqual, "notEqual", 2, TypeU, ClassBNS, Es300Desktop130 },
{ EOpAtomicAdd, "atomicAdd", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicMin, "atomicMin", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicMax, "atomicMax", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicAnd, "atomicAnd", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicOr, "atomicOr", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicXor, "atomicXor", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicExchange, "atomicExchange", 2, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicCompSwap, "atomicCompSwap", 3, TypeIU, ClassV1FIOCV, Es310Desktop430 },
{ EOpAtomicAdd, "atomicAdd", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicMin, "atomicMin", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicMax, "atomicMax", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicAnd, "atomicAnd", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicOr, "atomicOr", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicXor, "atomicXor", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicExchange, "atomicExchange", 2, TypeIU, ClassV1FIOCV, Es310Desktop420 },
{ EOpAtomicCompSwap, "atomicCompSwap", 3, TypeIU, ClassV1FIOCV, Es310Desktop420 },
#ifndef GLSLANG_WEB
{ EOpMix, "mix", 3, TypeB, ClassRegular, Es310Desktop450 },
{ EOpMix, "mix", 3, TypeIU, ClassLB, Es310Desktop450 },
Expand Down Expand Up @@ -7827,6 +7832,18 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
}

// GL_ARB_shader_storage_buffer_object
if (profile != EEsProfile && version < 430 ) {
symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
}

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
4 changes: 2 additions & 2 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4899,7 +4899,7 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
#ifndef GLSLANG_WEB
if (id == TQualifier::getLayoutPackingString(ElpStd430)) {
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, "std430");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, nullptr, "std430");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_shader_storage_buffer_object, "std430");
profileRequires(loc, EEsProfile, 310, nullptr, "std430");
publicType.qualifier.layoutPacking = ElpStd430;
return;
Expand Down Expand Up @@ -7669,7 +7669,7 @@ void TParseContext::blockStageIoCheck(const TSourceLoc& loc, const TQualifier& q
break;
case EvqBuffer:
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, "buffer block");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, nullptr, "buffer block");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_shader_storage_buffer_object, "buffer block");
profileRequires(loc, EEsProfile, 310, nullptr, "buffer block");
break;
case EvqVaryingIn:
Expand Down
2 changes: 1 addition & 1 deletion glslang/MachineIndependent/Scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ int TScanContext::tokenizeIdentifier()
case BUFFER:
afterBuffer = true;
if ((parseContext.isEsProfile() && parseContext.version < 310) ||
(!parseContext.isEsProfile() && parseContext.version < 430))
(!parseContext.isEsProfile() && parseContext.version < 420))
return identifierOrType();
return keyword;

Expand Down
2 changes: 2 additions & 0 deletions glslang/MachineIndependent/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void TParseVersions::initializeExtensionBehavior()
extensionBehavior[E_GL_ARB_sample_shading] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_bit_encoding] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_image_size] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_storage_buffer_object] = EBhDisable;

extensionBehavior[E_GL_KHR_shader_subgroup_basic] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_vote] = EBhDisable;
Expand Down Expand Up @@ -413,6 +414,7 @@ void TParseVersions::getPreamble(std::string& preamble)
"#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_ARB_shader_storage_buffer_object 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 @@ -154,6 +154,7 @@ const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer
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_ARB_shader_image_size = "GL_ARB_shader_image_size";
const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";

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 9c12b8f

Please sign in to comment.