diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index af7dfe62..d1bd13b5 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -159,6 +159,11 @@ template inline T* NewPoolObject(T, int instances) return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances]; } +inline bool StartsWith(TString const &str, const char *prefix) +{ + return str.compare(0, strlen(prefix), prefix) == 0; +} + // // Pool allocator versions of vectors, lists, and maps // diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 0462bf1b..ac270c64 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -2527,23 +2527,23 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan } else if(callNode.getType().getBasicType() == EbtFloat16 && ((callNode.getType().getVectorSize() == 2 && arg0->getType().getQualifier().getFormat() == ElfRg16f) || (callNode.getType().getVectorSize() == 4 && arg0->getType().getQualifier().getFormat() == ElfRgba16f))) { - if ((fnCandidate.getName().compare(0, 14, "imageAtomicAdd") == 0) || - (fnCandidate.getName().compare(0, 19, "imageAtomicExchange") == 0) || - (fnCandidate.getName().compare(0, 19, "imageAtomicMin") == 0) || - (fnCandidate.getName().compare(0, 19, "imageAtomicMax") == 0)) { + if (StartsWith(fnCandidate.getName(), "imageAtomicAdd") || + StartsWith(fnCandidate.getName(), "imageAtomicExchange") || + StartsWith(fnCandidate.getName(), "imageAtomicMin") || + StartsWith(fnCandidate.getName(), "imageAtomicMax")) { requireExtensions(loc, 1, &E_GL_NV_shader_atomic_fp16_vector, fnCandidate.getName().c_str()); } else { error(loc, "f16vec2/4 operation not supported on: ", fnCandidate.getName().c_str(), ""); } } else if (imageType.getSampler().type == EbtFloat) { - if (fnCandidate.getName().compare(0, 19, "imageAtomicExchange") == 0) { + if (StartsWith(fnCandidate.getName(), "imageAtomicExchange")) { // imageAtomicExchange doesn't require an extension - } else if ((fnCandidate.getName().compare(0, 14, "imageAtomicAdd") == 0) || - (fnCandidate.getName().compare(0, 15, "imageAtomicLoad") == 0) || - (fnCandidate.getName().compare(0, 16, "imageAtomicStore") == 0)) { + } else if (StartsWith(fnCandidate.getName(), "imageAtomicAdd") || + StartsWith(fnCandidate.getName(), "imageAtomicLoad") || + StartsWith(fnCandidate.getName(), "imageAtomicStore")) { requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float, fnCandidate.getName().c_str()); - } else if ((fnCandidate.getName().compare(0, 14, "imageAtomicMin") == 0) || - (fnCandidate.getName().compare(0, 14, "imageAtomicMax") == 0)) { + } else if (StartsWith(fnCandidate.getName(), "imageAtomicMin") || + StartsWith(fnCandidate.getName(), "imageAtomicMax")) { requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float2, fnCandidate.getName().c_str()); } else { error(loc, "only supported on integer images", fnCandidate.getName().c_str(), "");