Commit d7c5b0aa by Martin Radev Committed by Commit Bot

Add support for barriers in the compiler

The patch adds support for barriers in vertex, fragment and compute shaders. BUG:angleproject:1442 TEST:angle_unittests Change-Id: Ic85c3337911851a93a3f56bd935774181600eddd Reviewed-on: https://chromium-review.googlesource.com/380641 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f165f0b4
......@@ -589,6 +589,25 @@ void InsertBuiltInFunctions(sh::GLenum type,
symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage2DArray);
symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimageCube);
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrier, voidType,
"memoryBarrier");
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierAtomicCounter,
voidType, "memoryBarrierAtomicCounter");
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierBuffer,
voidType, "memoryBarrierBuffer");
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierImage, voidType,
"memoryBarrierImage");
if (type == GL_COMPUTE_SHADER)
{
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpBarrier, voidType,
"barrier");
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierShared,
voidType, "memoryBarrierShared");
symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpGroupMemoryBarrier,
voidType, "groupMemoryBarrier");
}
//
// Depth range in window coordinates
//
......
......@@ -333,7 +333,20 @@ const char *GetOperatorString(TOperator op)
return "^=";
case EOpBitwiseOrAssign:
return "|=";
case EOpBarrier:
return "barrier";
case EOpMemoryBarrier:
return "memoryBarrier";
case EOpMemoryBarrierAtomicCounter:
return "memoryBarrierAtomicCounter";
case EOpMemoryBarrierBuffer:
return "memoryBarrierBuffer";
case EOpMemoryBarrierImage:
return "memoryBarrierImage";
case EOpMemoryBarrierShared:
return "memoryBarrierShared";
case EOpGroupMemoryBarrier:
return "groupMemoryBarrier";
default:
break;
}
......
......@@ -216,7 +216,16 @@ enum TOperator
EOpBitShiftRightAssign,
EOpBitwiseAndAssign,
EOpBitwiseXorAssign,
EOpBitwiseOrAssign
EOpBitwiseOrAssign,
// barriers
EOpBarrier,
EOpMemoryBarrier,
EOpMemoryBarrierAtomicCounter,
EOpMemoryBarrierBuffer,
EOpMemoryBarrierImage,
EOpMemoryBarrierShared,
EOpGroupMemoryBarrier
};
// Returns the string corresponding to the operator in GLSL
......
......@@ -1113,7 +1113,27 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpMul:
writeBuiltInFunctionTriplet(visit, "matrixCompMult(", useEmulatedFunction);
break;
case EOpBarrier:
writeBuiltInFunctionTriplet(visit, "barrier(", useEmulatedFunction);
break;
case EOpMemoryBarrier:
writeBuiltInFunctionTriplet(visit, "memoryBarrier(", useEmulatedFunction);
break;
case EOpMemoryBarrierAtomicCounter:
writeBuiltInFunctionTriplet(visit, "memoryBarrierAtomicCounter(", useEmulatedFunction);
break;
case EOpMemoryBarrierBuffer:
writeBuiltInFunctionTriplet(visit, "memoryBarrierBuffer(", useEmulatedFunction);
break;
case EOpMemoryBarrierImage:
writeBuiltInFunctionTriplet(visit, "memoryBarrierImage(", useEmulatedFunction);
break;
case EOpMemoryBarrierShared:
writeBuiltInFunctionTriplet(visit, "memoryBarrierShared(", useEmulatedFunction);
break;
case EOpGroupMemoryBarrier:
writeBuiltInFunctionTriplet(visit, "groupMemoryBarrier(", useEmulatedFunction);
break;
default:
UNREACHABLE();
}
......
......@@ -382,6 +382,15 @@ void TSymbolTable::insertBuiltIn(ESymbolLevel level,
}
}
void TSymbolTable::insertBuiltInFunctionNoParameters(ESymbolLevel level,
TOperator op,
const TType *rvalue,
const char *name)
{
insertUnmangledBuiltInName(name, level);
insert(level, new TFunction(NewPoolTString(name), rvalue, op));
}
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const
{
if (!SupportsPrecision(type))
......
......@@ -405,6 +405,11 @@ class TSymbolTable : angle::NonCopyable
insertBuiltIn(level, op, "", rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5);
}
void insertBuiltInFunctionNoParameters(ESymbolLevel level,
TOperator op,
const TType *rvalue,
const char *name);
TSymbol *find(const TString &name,
int shaderVersion,
bool *builtIn = NULL,
......
......@@ -3285,3 +3285,74 @@ TEST_F(VertexShaderValidationTest, InvalidNumViews)
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// memoryBarrierShared is only available in a compute shader.
// GLSL ES 3.10 Revision 4, 8.15 Shader Memory Control Functions
TEST_F(FragmentShaderValidationTest, InvalidUseOfMemoryBarrierShared)
{
const std::string &shaderString =
"#version 310 es\n"
"precision mediump float;\n"
"void main() {\n"
" memoryBarrierShared();\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// groupMemoryBarrier is only available in a compute shader.
// GLSL ES 3.10 Revision 4, 8.15 Shader Memory Control Functions
TEST_F(FragmentShaderValidationTest, InvalidUseOfGroupMemoryBarrier)
{
const std::string &shaderString =
"#version 310 es\n"
"precision mediump float;\n"
"void main() {\n"
" groupMemoryBarrier();\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// barrier can be used in a compute shader.
// GLSL ES 3.10 Revision 4, 8.14 Shader Invocation Control Functions
TEST_F(ComputeShaderValidationTest, ValidUseOfBarrier)
{
const std::string &shaderString =
"#version 310 es\n"
"layout(local_size_x = 15) in;\n"
"void main() {\n"
" barrier();\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success " << mInfoLog;
}
}
// memoryBarrierImage() can be used in all GLSL ES 3.10 shaders.
// GLSL ES 3.10 Revision 4, 8.15 Shader Memory Control Functions
TEST_F(FragmentShaderValidationTest, ValidUseOfMemoryBarrierImageInFragmentShader)
{
const std::string &shaderString =
"#version 310 es\n"
"precision mediump float;\n"
"precision highp image2D;\n"
"layout(r32f) uniform image2D myImage;\n"
"void main() {\n"
" imageStore(myImage, ivec2(0), vec4(1.0));\n"
" memoryBarrierImage();\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success " << mInfoLog;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment