diff options
author | Lingfeng Yang <lfy@google.com> | 2020-10-28 15:56:23 -0700 |
---|---|---|
committer | Lingfeng Yang <lfy@google.com> | 2020-10-28 15:56:23 -0700 |
commit | bcb607f942c065268c3739839f418524bb666e35 (patch) | |
tree | 0fd714a947a3a3f49285f0a88b5e72dad258c250 | |
parent | cf7f11a31e4e945e09aeac32314ce02d085d96c0 (diff) | |
download | vulkan-cereal-bcb607f942c065268c3739839f418524bb666e35.tar.gz |
Build gles2 translator
Bug: 171711491
Change-Id: I70f8350cd173f3ff81cac48a9ef55e7f101316f9
19 files changed, 220 insertions, 427 deletions
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 0725a042..eddff140 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -4,6 +4,7 @@ endif() set(gfxstream-base-common-sources CompressingStream.cpp + CpuTime.cpp DecompressingStream.cpp GLObjectCounter.cpp MemStream.cpp diff --git a/base/CpuTime.cpp b/base/CpuTime.cpp new file mode 100644 index 00000000..4adc580c --- /dev/null +++ b/base/CpuTime.cpp @@ -0,0 +1,52 @@ +// Copyright 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "base/CpuTime.h" + +namespace android { +namespace base { + +CpuTime operator-(const CpuTime& a, const CpuTime& other) { + CpuTime res = a; + res -= other; + return res; +} + +CpuTime& CpuTime::operator-=(const CpuTime& other) { + wall_time_us -= other.wall_time_us; + user_time_us -= other.user_time_us; + system_time_us -= other.system_time_us; + return *this; +} + +uint64_t CpuTime::usageUs() const { + return user_time_us + system_time_us; +} + +float CpuTime::usage() const { + if (!wall_time_us) return 0.0f; + return (float)(user_time_us + system_time_us) / (float)(wall_time_us); +} + +float CpuTime::usageUser() const { + if (!wall_time_us) return 0.0f; + return (float)(user_time_us) / (float)(wall_time_us); +} + +float CpuTime::usageSystem() const { + if (!wall_time_us) return 0.0f; + return (float)(system_time_us) / (float)(wall_time_us); +} + +} // namespace android +} // namespace base diff --git a/base/CpuTime.h b/base/CpuTime.h new file mode 100644 index 00000000..8ddcba91 --- /dev/null +++ b/base/CpuTime.h @@ -0,0 +1,40 @@ +// Copyright 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once + +#include <inttypes.h> + +namespace android { +namespace base { + +// CPU usage tracking +struct CpuTime { + uint64_t wall_time_us = 0; + uint64_t user_time_us = 0; + uint64_t system_time_us = 0; + + CpuTime& operator-=(const CpuTime& other); + + uint64_t usageUs() const; + // Usage proportion; convert to percent by + // multiplying by 100. + float usage() const; + float usageUser() const; + float usageSystem() const; +}; + +CpuTime operator-(const CpuTime& a, const CpuTime& b); + +} // namespace base +} // namespace android diff --git a/base/Stream.cpp b/base/Stream.cpp index 6820d3ba..bd88ad34 100644 --- a/base/Stream.cpp +++ b/base/Stream.cpp @@ -112,6 +112,10 @@ void Stream::putString(const char* str, size_t len) { this->write(str, len); } +void Stream::putString(const std::string& str) { + putString(str.c_str()); +} + std::string Stream::getString() { std::string result; size_t len = this->getBe32(); diff --git a/base/Stream.h b/base/Stream.h index 8537d2c4..01a9964a 100644 --- a/base/Stream.h +++ b/base/Stream.h @@ -76,6 +76,7 @@ public: // Write a 0-terminated C string |str| into the stream. Ignore error. void putString(const char* str); + void putString(const std::string& str); // Write a string |str| of |strlen| bytes into the stream. // Ignore errors. diff --git a/base/System.h b/base/System.h index 2c90b49e..b40cf7c1 100644 --- a/base/System.h +++ b/base/System.h @@ -1,3 +1,5 @@ +#include "base/CpuTime.h" + #include <string> namespace android { @@ -17,5 +19,7 @@ uint64_t getFileSize(int fd, uint64_t* size); void sleepMs(uint64_t ms); +CpuTime cpuTime(); + } // namespace base } // namespace android diff --git a/stream-servers/glestranslator/CMakeLists.txt b/stream-servers/glestranslator/CMakeLists.txt index 589389fd..c889614c 100644 --- a/stream-servers/glestranslator/CMakeLists.txt +++ b/stream-servers/glestranslator/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(GLcommon) -# add_subdirectory(GLES_V2) +add_subdirectory(GLES_V2) diff --git a/stream-servers/glestranslator/GLES_V2/ANGLEShaderParser.cpp b/stream-servers/glestranslator/GLES_V2/ANGLEShaderParser.cpp index 2ef79580..66b2b57b 100644 --- a/stream-servers/glestranslator/GLES_V2/ANGLEShaderParser.cpp +++ b/stream-servers/glestranslator/GLES_V2/ANGLEShaderParser.cpp @@ -10,15 +10,15 @@ // GNU General Public License for more details. #include "ANGLEShaderParser.h" +#include "ShaderTranslator.h" -#include "android/base/synchronization/Lock.h" -#include "android/base/memory/LazyInstance.h" - -#include "emugl/common/shared_library.h" +#include "base/Lock.h" #include <map> #include <string> +#include <string.h> + #define GL_COMPUTE_SHADER 0x91B9 namespace ANGLEShaderParser { @@ -27,81 +27,6 @@ ST_BuiltInResources kResources; bool kInitialized = false; bool sIsGles2Gles = false; -class LazyLoadedSTDispatch { -public: - LazyLoadedSTDispatch() { - memset(&mDispatch, 0, sizeof(STDispatch)); - -#ifdef __APPLE__ - const char kLibName[] = "libshadertranslator.dylib"; -#elif defined(_WIN32) - const char kLibName[] = "libshadertranslator.dll"; -#else - const char kLibName[] = "libshadertranslator.so"; -#endif - char error[256]; - mLib = emugl::SharedLibrary::open(kLibName, error, sizeof(error)); - if (!mLib) { - fprintf(stderr, "%s: Could not open shader translator library %s [%s]\n", - __func__, kLibName, error); - return; - } - - mDispatch.initialize = - (STInitialize_t)mLib->findSymbol("STInitialize"); - mDispatch.finalize = - (STFinalize_t)mLib->findSymbol("STFinalize"); - mDispatch.generateResources = - (STGenerateResources_t)mLib->findSymbol("STGenerateResources"); - mDispatch.compileAndResolve = - (STCompileAndResolve_t)mLib->findSymbol("STCompileAndResolve"); - mDispatch.freeShaderResolveState = - (STFreeShaderResolveState_t)mLib->findSymbol("STFreeShaderResolveState"); - mDispatch.copyVariable = - (STCopyVariable_t)mLib->findSymbol("STCopyVariable"); - mDispatch.copyInterfaceBlock = - (STCopyInterfaceBlock_t)mLib->findSymbol("STCopyInterfaceBlock"); - mDispatch.destroyVariable = - (STDestroyVariable_t)mLib->findSymbol("STDestroyVariable"); - mDispatch.destroyInterfaceBlock = - (STDestroyInterfaceBlock_t)mLib->findSymbol("STDestroyInterfaceBlock"); - - mValid = dispatchValid(); - - if (!mValid) { - fprintf(stderr, "%s: error, shader translator dispatch not valid\n", __func__); - } - } - - STDispatch* getDispatch() { - if (!mValid) return nullptr; - return &mDispatch; - } - -private: - bool dispatchValid() { - return (nullptr != mDispatch.initialize) && - (nullptr != mDispatch.finalize) && - (nullptr != mDispatch.generateResources) && - (nullptr != mDispatch.compileAndResolve) && - (nullptr != mDispatch.copyVariable) && - (nullptr != mDispatch.copyInterfaceBlock) && - (nullptr != mDispatch.destroyVariable) && - (nullptr != mDispatch.destroyInterfaceBlock); - } - - emugl::SharedLibrary* mLib = nullptr; - bool mValid = false; - STDispatch mDispatch; -}; - -static android::base::LazyInstance<LazyLoadedSTDispatch> sLazyLoadedSTDispatch = - LAZY_INSTANCE_INIT; - -STDispatch* getSTDispatch() { - return sLazyLoadedSTDispatch->getDispatch(); -} - ShaderLinkInfo::ShaderLinkInfo() = default; ShaderLinkInfo::ShaderLinkInfo(const ShaderLinkInfo& other) { clear(); @@ -140,12 +65,11 @@ void ShaderLinkInfo::copyFromOther(const ShaderLinkInfo& other) { esslVersion = other.esslVersion; if (!sIsGles2Gles) { - auto dispatch = getSTDispatch(); - for (const auto& var: other.uniforms) { uniforms.push_back(dispatch->copyVariable(&var)); } - for (const auto& var: other.varyings) { varyings.push_back(dispatch->copyVariable(&var)); } - for (const auto& var: other.attributes) { attributes.push_back(dispatch->copyVariable(&var)); } - for (const auto& var: other.outputVars) { outputVars.push_back(dispatch->copyVariable(&var)); } - for (const auto& var: other.interfaceBlocks) { interfaceBlocks.push_back(dispatch->copyInterfaceBlock(&var)); } + for (const auto& var: other.uniforms) { uniforms.push_back(STCopyVariable(&var)); } + for (const auto& var: other.varyings) { varyings.push_back(STCopyVariable(&var)); } + for (const auto& var: other.attributes) { attributes.push_back(STCopyVariable(&var)); } + for (const auto& var: other.outputVars) { outputVars.push_back(STCopyVariable(&var)); } + for (const auto& var: other.interfaceBlocks) { interfaceBlocks.push_back(STCopyInterfaceBlock(&var)); } } nameMap = other.nameMap; @@ -155,12 +79,11 @@ void ShaderLinkInfo::copyFromOther(const ShaderLinkInfo& other) { void ShaderLinkInfo::clear() { if (!sIsGles2Gles) { - auto dispatch = getSTDispatch(); - for (auto& var: uniforms) { dispatch->destroyVariable(&var); } - for (auto& var: varyings) { dispatch->destroyVariable(&var); } - for (auto& var: attributes) { dispatch->destroyVariable(&var); } - for (auto& var: outputVars) { dispatch->destroyVariable(&var); } - for (auto& var: interfaceBlocks) { dispatch->destroyInterfaceBlock(&var); } + for (auto& var: uniforms) { STDestroyVariable(&var); } + for (auto& var: varyings) { STDestroyVariable(&var); } + for (auto& var: attributes) { STDestroyVariable(&var); } + for (auto& var: outputVars) { STDestroyVariable(&var); } + for (auto& var: interfaceBlocks) { STDestroyInterfaceBlock(&var); } } uniforms.clear(); @@ -221,11 +144,14 @@ struct ShaderSpecKeyCompare { }; typedef std::map<ShaderSpecKey, ST_Handle, ShaderSpecKeyCompare> ShaderCompilerMap; -static android::base::LazyInstance<ShaderCompilerMap> sCompilerMap = LAZY_INSTANCE_INIT; +static ShaderCompilerMap* sCompilerMap() { + static ShaderCompilerMap* m = new ShaderCompilerMap; + return m; +} static ST_Handle getShaderCompiler(bool coreProfileHost, ShaderSpecKey key) { - auto it = sCompilerMap->find(key); - if (it == sCompilerMap->end()) return (ST_Handle)nullptr; + auto it = sCompilerMap()->find(key); + if (it == sCompilerMap()->end()) return (ST_Handle)nullptr; return it->second; } @@ -235,7 +161,7 @@ void initializeResources( BuiltinResourcesEditCallback callback) { if (!sIsGles2Gles) { - getSTDispatch()->generateResources(&kResources); + STGenerateResources(&kResources); } callback(kResources); @@ -248,7 +174,7 @@ bool globalInitialize( sIsGles2Gles = isGles2Gles; if (!sIsGles2Gles) { - getSTDispatch()->initialize(); + STInitialize(); } initializeResources(editCallback); @@ -286,23 +212,19 @@ static void getShaderLinkInfo(int esslVersion, linkInfo->nameMapReverse[elt.second] = elt.first; } - auto st = getSTDispatch(); - auto stCopyVar = st->copyVariable; - auto stCopyIb = st->copyInterfaceBlock; - linkInfo->uniforms = convertArrayToVecWithCopy( compileResult->uniformsCount, compileResult->pUniforms, - stCopyVar); + STCopyVariable); std::vector<ST_ShaderVariable> inputVaryings = convertArrayToVecWithCopy( compileResult->inputVaryingsCount, compileResult->pInputVaryings, - stCopyVar); + STCopyVariable); std::vector<ST_ShaderVariable> outputVaryings = convertArrayToVecWithCopy( compileResult->outputVaryingsCount, compileResult->pOutputVaryings, - stCopyVar); + STCopyVariable); linkInfo->varyings.clear(); linkInfo->varyings.insert( @@ -318,19 +240,19 @@ static void getShaderLinkInfo(int esslVersion, convertArrayToVecWithCopy( compileResult->allAttributesCount, compileResult->pAllAttributes, - stCopyVar); + STCopyVariable); linkInfo->outputVars = convertArrayToVecWithCopy( compileResult->activeOutputVariablesCount, compileResult->pActiveOutputVariables, - stCopyVar); + STCopyVariable); linkInfo->interfaceBlocks = convertArrayToVecWithCopy( compileResult->uniformBlocksCount, compileResult->pUniformBlocks, - stCopyIb); + STCopyInterfaceBlock); // todo: split to uniform and ssbo } @@ -411,11 +333,9 @@ bool translate(bool hostUsesCoreProfile, ST_ShaderCompileResult* res = nullptr; - auto st = getSTDispatch(); - - st->compileAndResolve(&ci, &res); + STCompileAndResolve(&ci, &res); - sCompilerMap->emplace(key, res->outputHandle); + sCompilerMap()->emplace(key, res->outputHandle); *outInfolog = std::string(res->infoLog); *outObjCode = std::string(res->translatedSource); @@ -423,7 +343,7 @@ bool translate(bool hostUsesCoreProfile, bool ret = res->compileStatus == 1; - st->freeShaderResolveState(res); + STFreeShaderResolveState(res); return ret; } diff --git a/stream-servers/glestranslator/GLES_V2/CMakeLists.txt b/stream-servers/glestranslator/GLES_V2/CMakeLists.txt index 227b4010..5aa33187 100644 --- a/stream-servers/glestranslator/GLES_V2/CMakeLists.txt +++ b/stream-servers/glestranslator/GLES_V2/CMakeLists.txt @@ -1,24 +1,15 @@ -# add_library( -# GLES_V2_translator_static -# SRC -# ANGLEShaderParser.cpp -# GLESv2Context.cpp -# GLESv2Imp.cpp -# GLESv2Validate.cpp -# ProgramData.cpp -# SamplerData.cpp -# ShaderParser.cpp -# ShaderValidator.cpp -# TransformFeedbackData.cpp) -# target_compile_options(GLES_V2_translator_static PRIVATE -fvisibility=hidden -# -Wno-macro-redefined) -# if(OPTION_GFXSTREAM_BACKEND) -# target_link_libraries( -# GLES_V2_translator_static PRIVATE GLcommon OpenglCodecCommon emugl_common -# android-emu-shared ANGLE::ANGLE) -# else() -# target_link_libraries( -# GLES_V2_translator_static PRIVATE GLcommon OpenglCodecCommon emugl_common -# android-emu ANGLE::ANGLE) -# endif() -# target_link_libraries(GLES_V2_translator_static PRIVATE emugl_base) +add_library( + GLES_V2_translator_static + ANGLEShaderParser.cpp + GLESv2Context.cpp + GLESv2Imp.cpp + GLESv2Validate.cpp + ProgramData.cpp + SamplerData.cpp + ShaderParser.cpp + ShaderValidator.cpp + TransformFeedbackData.cpp) +target_compile_options( + GLES_V2_translator_static PRIVATE -fvisibility=hidden -Wno-macro-redefined) +target_link_libraries( + GLES_V2_translator_static PRIVATE GLcommon apigen-codec-common gfxstream-base angle_shader_translator) diff --git a/stream-servers/glestranslator/GLES_V2/GLESv2Context.cpp b/stream-servers/glestranslator/GLES_V2/GLESv2Context.cpp index 8d5de4da..243f5e4c 100644 --- a/stream-servers/glestranslator/GLES_V2/GLESv2Context.cpp +++ b/stream-servers/glestranslator/GLES_V2/GLESv2Context.cpp @@ -20,9 +20,10 @@ #include "SamplerData.h" #include "ShaderParser.h" #include "TransformFeedbackData.h" -#include "android/base/files/StreamSerializing.h" +#include "base/Lock.h" +#include "base/StreamSerializing.h" -#include "emugl/common/crash_reporter.h" +#include "host-common/crash_reporter.h" #include <string.h> @@ -64,7 +65,7 @@ void GLESv2Context::initGlobal(EGLiface* iface) { } void GLESv2Context::init() { - emugl::Mutex::AutoLock mutex(s_lock); + android::base::AutoLock mutex(s_lock); if(!m_initialized) { GLEScontext::init(); addVertexArrayObject(0); @@ -585,8 +586,8 @@ void GLESv2Context::drawWithEmulations( s_glDispatch.glDrawArraysInstanced(mode, first, count, primcount); break; default: - emugl::emugl_crash_reporter( - "drawWithEmulations has corrupt call parameters!"); + emugl_crash_reporter( + "drawWithEmulations has corrupt call parameters!"); } if (needClientIBOSetup) { diff --git a/stream-servers/glestranslator/GLES_V2/GLESv2Imp.cpp b/stream-servers/glestranslator/GLES_V2/GLESv2Imp.cpp index 3afd1186..6665576d 100644 --- a/stream-servers/glestranslator/GLES_V2/GLESv2Imp.cpp +++ b/stream-servers/glestranslator/GLES_V2/GLESv2Imp.cpp @@ -26,9 +26,8 @@ #include <GLES3/gl3.h> #include <GLES3/gl31.h> -#include "android/base/memory/LazyInstance.h" -#include "android/base/system/System.h" -#include "OpenglCodecCommon/ErrorLog.h" +#include "base/System.h" +#include "ErrorLog.h" #include "GLESv2Context.h" #include "GLESv2Validate.h" #include "GLcommon/FramebufferData.h" @@ -37,14 +36,12 @@ #include "GLcommon/TextureData.h" #include "GLcommon/TextureUtils.h" #include "GLcommon/TranslatorIfaces.h" -#include "OpenglCodecCommon/ErrorLog.h" #include "ProgramData.h" #include "SamplerData.h" #include "ShaderParser.h" #include "TransformFeedbackData.h" -#include "emugl/common/crash_reporter.h" -#include "emugl/common/metrics.h" +#include "host-common/crash_reporter.h" #include "ANGLEShaderParser.h" @@ -63,8 +60,6 @@ #define GLES2_NAMESPACED(f) translator::gles2::f -using android::base::c_str; - namespace translator { namespace gles2 { @@ -145,8 +140,6 @@ static GLESiface s_glesIface = { #include <GLcommon/GLESmacros.h> -static android::base::LazyInstance<GLES3Usage> gles30usages = {}; - namespace translator { namespace gles2 { @@ -352,10 +345,10 @@ static void blitFromCurrentReadBufferANDROID(EGLImage image) { ImagePtr img = s_eglIface->getEGLImage(imagehndl); if (!img || !ctx->shareGroup().get()) { - emugl::emugl_crash_reporter( - "FATAL: blitFromCurrentReadBufferANDROID: " - "image (%p) or share group (%p) not found", - img.get(), ctx->shareGroup().get()); + // emugl_crash_reporter( + // "FATAL: blitFromCurrentReadBufferANDROID: " + // "image (%p) or share group (%p) not found", + // img.get(), ctx->shareGroup().get()); return; } @@ -471,7 +464,7 @@ GL_APICALL void GL_APIENTRY glBindAttribLocation(GLuint program, GLuint index, ctx->dispatcher().glBindAttribLocation( globalProgramName, index, - c_str(pData->getTranslatedName(name))); + pData->getTranslatedName(name).c_str()); pData->bindAttribLocation(name, index); } @@ -1081,7 +1074,7 @@ GL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type){ if (!shaderParserInitialized) { shaderParserInitialized = true; sDebugPrintShaders = - android::base::System::getEnvironmentVariable( + android::base::getEnvironmentVariable( "ANDROID_EMUGL_SHADER_PRINT") == "1"; auto& gl = ctx->dispatcher(); @@ -1900,7 +1893,7 @@ GL_APICALL int GL_APIENTRY glGetAttribLocation(GLuint program, const GLchar* nam -1); #endif int ret = ctx->dispatcher().glGetAttribLocation( - globalProgramName, c_str(pData->getTranslatedName(name))); + globalProgramName, pData->getTranslatedName(name).c_str()); if (ret != -1) { pData->linkedAttribLocation(name, ret); } @@ -4306,7 +4299,7 @@ glTestHostDriverPerformance(GLuint count, uint32_t drawCount = 0; - auto cpuTimeStart = android::base::System::cpuTime(); + auto cpuTimeStart = android::base::cpuTime(); fprintf(stderr, "%s: transform loc %d\n", __func__, transformLoc); fprintf(stderr, "%s: begin count %d\n", __func__, count); @@ -4319,7 +4312,7 @@ fprintf(stderr, "%s: begin count %d\n", __func__, count); gl->glFinish(); - auto cpuTime = android::base::System::cpuTime() - cpuTimeStart; + auto cpuTime = android::base::cpuTime() - cpuTimeStart; *duration_us = cpuTime.wall_time_us; *duration_cpu_us = cpuTime.usageUs(); @@ -4386,7 +4379,6 @@ GL_APICALL void GL_APIENTRY glGetMemoryObjectParameterivEXT(GLuint memoryObject, GL_APICALL void GL_APIENTRY glTexStorageMem2DEXT(GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset) { GET_CTX_V2(); - gles30usages->set_is_used(true); GLint err = GL_NO_ERROR; GLenum format, type; GLESv2Validate::getCompatibleFormatTypeForInternalFormat(internalFormat, &format, &type); diff --git a/stream-servers/glestranslator/GLES_V2/GLESv30Imp.cpp b/stream-servers/glestranslator/GLES_V2/GLESv30Imp.cpp index b994af9d..44ba75dd 100644 --- a/stream-servers/glestranslator/GLES_V2/GLESv30Imp.cpp +++ b/stream-servers/glestranslator/GLES_V2/GLESv30Imp.cpp @@ -14,7 +14,6 @@ GL_APICALL void GL_APIENTRY glGenVertexArrays(GLsizei n, GLuint* arrays) { } GL_APICALL void GL_APIENTRY glBindVertexArray(GLuint array) { - if (array) gles30usages->set_is_used(true); glBindVertexArrayOES(array); } @@ -29,7 +28,6 @@ GL_APICALL GLboolean GL_APIENTRY glIsVertexArray(GLuint array) { GL_APICALL void * GL_APIENTRY glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) { GET_CTX_V2_RET(0); RET_AND_SET_ERROR_IF(!GLESv2Validate::bufferTarget(ctx, target),GL_INVALID_ENUM,0); - gles30usages->set_is_used(true); void * glMapBufferRangeRET = ctx->dispatcher().glMapBufferRange(target, offset, length, access); return glMapBufferRangeRET; } @@ -50,7 +48,6 @@ GL_APICALL void GL_APIENTRY glFlushMappedBufferRange(GLenum target, GLintptr off GL_APICALL void GL_APIENTRY glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) { GET_CTX_V2(); SET_ERROR_IF(!GLESv2Validate::bufferTarget(ctx, target),GL_INVALID_ENUM); - gles30usages->set_is_used(true); ctx->bindBuffer(target, buffer); ctx->bindIndexedBuffer(target, index, buffer, offset, size); if (ctx->shareGroup().get()) { @@ -62,7 +59,6 @@ GL_APICALL void GL_APIENTRY glBindBufferRange(GLenum target, GLuint index, GLuin GL_APICALL void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer) { GET_CTX_V2(); SET_ERROR_IF(!GLESv2Validate::bufferTarget(ctx, target),GL_INVALID_ENUM); - gles30usages->set_is_used(true); ctx->bindBuffer(target, buffer); ctx->bindIndexedBuffer(target, index, buffer); if (ctx->shareGroup().get()) { @@ -73,7 +69,6 @@ GL_APICALL void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint GL_APICALL void GL_APIENTRY glCopyBufferSubData(GLenum readtarget, GLenum writetarget, GLintptr readoffset, GLintptr writeoffset, GLsizeiptr size) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glCopyBufferSubData(readtarget, writetarget, readoffset, writeoffset, size); } @@ -111,7 +106,6 @@ GL_APICALL void GL_APIENTRY glGetBufferPointerv(GLenum target, GLenum pname, GLv GL_APICALL void GL_APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->shareGroup().get()) { const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(NamedObjectType::SHADER_OR_PROGRAM, program); ctx->dispatcher().glUniformBlockBinding(globalProgramName, uniformBlockIndex, uniformBlockBinding); @@ -281,31 +275,26 @@ GL_APICALL void GL_APIENTRY glGetActiveUniformsiv(GLuint program, GLsizei unifor GL_APICALL void GL_APIENTRY glVertexAttribI4i(GLuint index, GLint v0, GLint v1, GLint v2, GLint v3) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glVertexAttribI4i(index, v0, v1, v2, v3); } GL_APICALL void GL_APIENTRY glVertexAttribI4ui(GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glVertexAttribI4ui(index, v0, v1, v2, v3); } GL_APICALL void GL_APIENTRY glVertexAttribI4iv(GLuint index, const GLint * v) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glVertexAttribI4iv(index, v); } GL_APICALL void GL_APIENTRY glVertexAttribI4uiv(GLuint index, const GLuint * v) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glVertexAttribI4uiv(index, v); } GL_APICALL void GL_APIENTRY glVertexAttribIPointerWithDataSize(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* ptr, GLsizei dataSize) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); s_glPrepareVertexAttribPointer(ctx, index, size, type, false, stride, ptr, dataSize, true); @@ -316,7 +305,6 @@ GL_APICALL void GL_APIENTRY glVertexAttribIPointerWithDataSize(GLuint index, GL GL_APICALL void GL_APIENTRY glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); s_glPrepareVertexAttribPointer(ctx, index, size, type, false, stride, pointer, 0, true); if (ctx->isBindedBuffer(GL_ARRAY_BUFFER)) { @@ -336,7 +324,6 @@ GL_APICALL void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GL GL_APICALL void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); ctx->setVertexAttribBindingIndex(index, index); ctx->setVertexAttribDivisor(index, divisor); @@ -345,7 +332,6 @@ GL_APICALL void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor) GL_APICALL void GL_APIENTRY glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(count < 0,GL_INVALID_VALUE) SET_ERROR_IF(!(GLESv2Validate::drawMode(mode)),GL_INVALID_ENUM); if (ctx->vertexAttributesBufferBacked()) { @@ -362,7 +348,6 @@ GL_APICALL void GL_APIENTRY glDrawArraysInstanced(GLenum mode, GLint first, GLsi GL_APICALL void GL_APIENTRY glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei primcount) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(count < 0,GL_INVALID_VALUE) SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM); @@ -381,7 +366,6 @@ GL_APICALL void GL_APIENTRY glDrawElementsInstanced(GLenum mode, GLsizei count, GL_APICALL void GL_APIENTRY glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(count < 0,GL_INVALID_VALUE) SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM); @@ -455,15 +439,18 @@ public: return mSyncs.find(guestSync) != mSyncs.end(); } - emugl::Mutex& lock() { return mLock; } + android::base::Lock& lock() { return mLock; } private: std::unordered_map<GLsync, GLsync> mSyncs; - mutable emugl::Mutex mLock; + mutable android::base::Lock mLock; uint32_t mNameCounter = 0x1; }; -static android::base::LazyInstance<GuestSyncs> sSyncs = LAZY_INSTANCE_INIT; +static GuestSyncs* sSyncs() { + static GuestSyncs* s = new GuestSyncs; + return s; +} static GLsync internal_glFenceSync(GLenum condition, GLbitfield flags) { GET_CTX_V2_RET(0); @@ -530,44 +517,39 @@ static void internal_glGetSynciv(GLsync sync, GLenum pname, GLsizei bufsize, GLs GL_APICALL GLsync GL_APIENTRY glFenceSync(GLenum condition, GLbitfield flags) { GET_CTX_V2_RET(0); - gles30usages->set_is_used(true); - gles30usages->set_fence_sync(true); - emugl::Mutex::AutoLock lock(sSyncs->lock()); + android::base::AutoLock lock(sSyncs()->lock()); GLsync hostSync = internal_glFenceSync(condition, flags); - GLsync guestSync = sSyncs->create(hostSync); + GLsync guestSync = sSyncs()->create(hostSync); return guestSync; } GL_APICALL GLenum GL_APIENTRY glClientWaitSync(GLsync wait_on, GLbitfield flags, GLuint64 timeout) { GET_CTX_V2_RET(GL_WAIT_FAILED); - gles30usages->set_is_used(true); GLint err = GL_NO_ERROR; - emugl::Mutex::AutoLock lock(sSyncs->lock()); - GLsync hostSync = sSyncs->lookupWithError(wait_on, &err); + android::base::AutoLock lock(sSyncs()->lock()); + GLsync hostSync = sSyncs()->lookupWithError(wait_on, &err); RET_AND_SET_ERROR_IF(err != GL_NO_ERROR, err, GL_WAIT_FAILED); return internal_glClientWaitSync(hostSync, flags, timeout); } GL_APICALL void GL_APIENTRY glWaitSync(GLsync wait_on, GLbitfield flags, GLuint64 timeout) { GET_CTX_V2(); - gles30usages->set_is_used(true); GLint err = GL_NO_ERROR; - emugl::Mutex::AutoLock lock(sSyncs->lock()); - GLsync hostSync = sSyncs->lookupWithError(wait_on, &err); + android::base::AutoLock lock(sSyncs()->lock()); + GLsync hostSync = sSyncs()->lookupWithError(wait_on, &err); SET_ERROR_IF(err != GL_NO_ERROR, err); internal_glWaitSync(hostSync, flags, timeout); } GL_APICALL void GL_APIENTRY glDeleteSync(GLsync to_delete) { GET_CTX_V2(); - gles30usages->set_is_used(true); GLint err = GL_NO_ERROR; - emugl::Mutex::AutoLock lock(sSyncs->lock()); - GLsync hostSync = sSyncs->removeWithError(to_delete, &err); + android::base::AutoLock lock(sSyncs()->lock()); + GLsync hostSync = sSyncs()->removeWithError(to_delete, &err); SET_ERROR_IF(err != GL_NO_ERROR, err); internal_glDeleteSync(hostSync); } @@ -575,24 +557,22 @@ GL_APICALL void GL_APIENTRY glDeleteSync(GLsync to_delete) { GL_APICALL GLboolean GL_APIENTRY glIsSync(GLsync sync) { GET_CTX_V2_RET(0); - emugl::Mutex::AutoLock lock(sSyncs->lock()); - gles30usages->set_is_used(true); - return sSyncs->isSync(sync) ? GL_TRUE : GL_FALSE; + android::base::AutoLock lock(sSyncs()->lock()); + return sSyncs()->isSync(sync) ? GL_TRUE : GL_FALSE; } GL_APICALL void GL_APIENTRY glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei * length, GLint * values) { GET_CTX_V2(); GLint err = GL_NO_ERROR; - emugl::Mutex::AutoLock lock(sSyncs->lock()); - GLsync hostSync = sSyncs->lookupWithError(sync, &err); + android::base::AutoLock lock(sSyncs()->lock()); + GLsync hostSync = sSyncs()->lookupWithError(sync, &err); SET_ERROR_IF(err != GL_NO_ERROR, err); ctx->dispatcher().glGetSynciv(hostSync, pname, bufSize, length, values); } GL_APICALL void GL_APIENTRY glDrawBuffers(GLsizei n, const GLenum * bufs) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->isDefaultFBOBound(GL_DRAW_FRAMEBUFFER)) { SET_ERROR_IF(n != 1 || (bufs[0] != GL_NONE && bufs[0] != GL_BACK), GL_INVALID_OPERATION); @@ -610,7 +590,6 @@ GL_APICALL void GL_APIENTRY glDrawBuffers(GLsizei n, const GLenum * bufs) { GL_APICALL void GL_APIENTRY glReadBuffer(GLenum src) { GET_CTX_V2(); - gles30usages->set_is_used(true); // if default fbo is bound and src is GL_BACK, // use GL_COLOR_ATTACHMENT0 all of a sudden. // bc we are using fbo emulation. @@ -630,7 +609,6 @@ GL_APICALL void GL_APIENTRY glReadBuffer(GLenum src) { GL_APICALL void GL_APIENTRY glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); } @@ -654,7 +632,6 @@ static std::vector<GLenum> sGetEmulatedAttachmentList(GLESv2Context* ctx, GLenum GL_APICALL void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum * attachments) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER, GL_INVALID_ENUM); @@ -680,7 +657,6 @@ GL_APICALL void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAt GL_APICALL void GL_APIENTRY glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum * attachments, GLint x, GLint y, GLsizei width, GLsizei height) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER, GL_INVALID_ENUM); @@ -706,8 +682,6 @@ GL_APICALL void GL_APIENTRY glInvalidateSubFramebuffer(GLenum target, GLsizei nu GL_APICALL void GL_APIENTRY glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) { GET_CTX_V2(); - gles30usages->set_is_used(true); - gles30usages->set_framebuffer_texture_layer(true); GLenum textarget = GL_TEXTURE_2D_ARRAY; SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(ctx, target) && GLESv2Validate::framebufferAttachment(ctx, attachment)), GL_INVALID_ENUM); @@ -735,8 +709,6 @@ GL_APICALL void GL_APIENTRY glFramebufferTextureLayer(GLenum target, GLenum atta GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) { GET_CTX_V2(); - gles30usages->set_is_used(true); - gles30usages->set_renderbuffer_storage_multisample(true); GLint err = GL_NO_ERROR; internalformat = sPrepareRenderbufferStorage(internalformat, width, height, samples, &err); SET_ERROR_IF(err != GL_NO_ERROR, err); @@ -750,7 +722,6 @@ GL_APICALL void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internal GL_APICALL void GL_APIENTRY glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) { GET_CTX_V2(); - gles30usages->set_is_used(true); GLint err = GL_NO_ERROR; GLenum format, type; GLESv2Validate::getCompatibleFormatTypeForInternalFormat(internalformat, &format, &type); @@ -763,7 +734,6 @@ GL_APICALL void GL_APIENTRY glTexStorage2D(GLenum target, GLsizei levels, GLenum GL_APICALL void GL_APIENTRY glBeginTransformFeedback(GLenum primitiveMode) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->boundTransformFeedback()->mIsActive = true; ctx->dispatcher().glBeginTransformFeedback(primitiveMode); } @@ -777,10 +747,6 @@ GL_APICALL void GL_APIENTRY glEndTransformFeedback() { GL_APICALL void GL_APIENTRY glGenTransformFeedbacks(GLsizei n, GLuint * ids) { GET_CTX_V2(); SET_ERROR_IF(n < 0,GL_INVALID_VALUE); - if (n) { - gles30usages->set_is_used(true); - gles30usages->set_gen_transform_feedbacks(true); - } for (int i = 0; i < n; i++) { ids[i] = ctx->genTransformFeedbackName(0, true); } @@ -810,10 +776,6 @@ GL_APICALL void GL_APIENTRY glDeleteTransformFeedbacks(GLsizei n, const GLuint * GL_APICALL void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id) { GET_CTX_V2(); - if (id) { - gles30usages->set_is_used(true); - gles30usages->set_gen_transform_feedbacks(true); - } unsigned int globalName = ctx->getTransformFeedbackGlobalName(id); SET_ERROR_IF(id != 0 && globalName == 0, GL_INVALID_OPERATION); ctx->bindTransformFeedback(id); @@ -837,7 +799,6 @@ GL_APICALL GLboolean GL_APIENTRY glIsTransformFeedback(GLuint id) { EXTERN_PART GL_APICALL void GL_APIENTRY glTransformFeedbackVaryings(GLuint program, GLsizei count, const char ** varyings, GLenum bufferMode) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->shareGroup().get()) { const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(NamedObjectType::SHADER_OR_PROGRAM, program); ctx->dispatcher().glTransformFeedbackVaryings(globalProgramName, count, varyings, bufferMode); @@ -879,7 +840,6 @@ GL_APICALL void GL_APIENTRY glDeleteSamplers(GLsizei n, const GLuint * samplers) GL_APICALL void GL_APIENTRY glBindSampler(GLuint unit, GLuint sampler) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->shareGroup().get()) { const GLuint globalSampler = ctx->shareGroup()->getGlobalName(NamedObjectType::SAMPLER, sampler); SET_ERROR_IF(sampler && !globalSampler, GL_INVALID_OPERATION); @@ -980,8 +940,6 @@ GL_APICALL void GL_APIENTRY glDeleteQueries(GLsizei n, const GLuint * queries) { GL_APICALL void GL_APIENTRY glBeginQuery(GLenum target, GLuint query) { GET_CTX_V2(); - gles30usages->set_is_used(true); - gles30usages->set_begin_query(true); if (ctx->shareGroup().get()) { const GLuint globalQuery = ctx->shareGroup()->getGlobalName(NamedObjectType::QUERY, query); ctx->dispatcher().glBeginQuery(target, globalQuery); @@ -1017,7 +975,6 @@ GL_APICALL GLboolean GL_APIENTRY glIsQuery(GLuint query) { GL_APICALL void GL_APIENTRY glProgramParameteri(GLuint program, GLenum pname, GLint value) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->shareGroup().get()) { const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(NamedObjectType::SHADER_OR_PROGRAM, program); ctx->dispatcher().glProgramParameteri(globalProgramName, pname, value); @@ -1026,7 +983,6 @@ GL_APICALL void GL_APIENTRY glProgramParameteri(GLuint program, GLenum pname, GL GL_APICALL void GL_APIENTRY glProgramBinary(GLuint program, GLenum binaryFormat, const void * binary, GLsizei length) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (ctx->shareGroup().get()) { const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(NamedObjectType::SHADER_OR_PROGRAM, program); ctx->dispatcher().glProgramBinary(globalProgramName, binaryFormat, binary, length); @@ -1067,7 +1023,6 @@ GL_APICALL void GL_APIENTRY glGetInteger64i_v(GLenum target, GLuint index, GLint GL_APICALL void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * data) { GET_CTX_V2(); - gles30usages->set_is_used(true); SET_ERROR_IF(!GLESv2Validate::pixelItnlFrmt(ctx,internalFormat), GL_INVALID_VALUE); SET_ERROR_IF(!GLESv2Validate::isCompressedFormat(internalFormat) && !GLESv2Validate::pixelSizedFrmt(ctx, internalFormat, format, type), @@ -1093,7 +1048,6 @@ GL_APICALL void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint inter GL_APICALL void GL_APIENTRY glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) { GET_CTX_V2(); - gles30usages->set_is_used(true); GLenum format, type; GLESv2Validate::getCompatibleFormatTypeForInternalFormat(internalformat, &format, &type); s_glInitTexImage3D(target, 0, internalformat, width, height, depth, 0, @@ -1110,7 +1064,6 @@ GL_APICALL void GL_APIENTRY glTexStorage3D(GLenum target, GLsizei levels, GLenum GL_APICALL void GL_APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * data) { GET_CTX_V2(); - gles30usages->set_is_used(true); if (isCoreProfile() && isCoreProfileEmulatedFormat(format)) { format = getCoreProfileEmulatedFormat(format); @@ -1125,7 +1078,6 @@ GL_APICALL void GL_APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xo GL_APICALL void GL_APIENTRY glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid * data) { GET_CTX_V2(); - gles30usages->set_is_used(true); ctx->dispatcher().glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data); if (ctx->shareGroup().get()) { TextureData *texData = getTextureTargetData(target); @@ -1141,7 +1093,6 @@ GL_APICALL void GL_APIENTRY glCompressedTexImage3D(GLenum target, GLint level, G GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid * data) { GET_CTX_V2(); - gles30usages->set_is_used(true); TextureData* texData = getTextureTargetData(target); if (texData) { texData->makeDirty(); @@ -1151,7 +1102,6 @@ GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level GL_APICALL void GL_APIENTRY glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) { GET_CTX_V2(); - gles30usages->set_is_used(true); TextureData* texData = getTextureTargetData(target); if (texData) { texData->makeDirty(); diff --git a/stream-servers/glestranslator/GLES_V2/ProgramData.cpp b/stream-servers/glestranslator/GLES_V2/ProgramData.cpp index 9534cc3b..3e2f8962 100644 --- a/stream-servers/glestranslator/GLES_V2/ProgramData.cpp +++ b/stream-servers/glestranslator/GLES_V2/ProgramData.cpp @@ -15,10 +15,10 @@ */ #include "ProgramData.h" -#include "OpenglCodecCommon/glUtils.h" +#include "apigen-codec-common/glUtils.h" -#include "android/base/containers/Lookup.h" -#include "android/base/files/StreamSerializing.h" +#include "base/Lookup.h" +#include "base/StreamSerializing.h" #include "ANGLEShaderParser.h" #include "GLcommon/GLutils.h" #include "GLcommon/GLESmacros.h" @@ -28,9 +28,6 @@ #include <string.h> #include <unordered_set> -using android::base::c_str; -using android::base::StringView; - GLUniformDesc::GLUniformDesc(const char* name, GLint location, GLsizei count, GLboolean transpose, GLenum type, GLsizei size, unsigned char* val) : mCount(count), mTranspose(transpose), mType(type) @@ -466,7 +463,7 @@ void ProgramData::restore(ObjectLocalName localName, #endif // DEBUG for (const auto& uniform : mUniNameToGuestLoc) { GLint hostLoc = dispatcher.glGetUniformLocation( - globalName, c_str(getTranslatedName(uniform.first))); + globalName, getTranslatedName(uniform.first).c_str()); if (hostLoc != -1) { mGuestLocToHostLoc.add(uniform.second, hostLoc); } @@ -474,7 +471,7 @@ void ProgramData::restore(ObjectLocalName localName, for (const auto& uniformEntry : uniforms) { const auto& uniform = uniformEntry.second; GLint location = dispatcher.glGetUniformLocation( - globalName, c_str(getTranslatedName(uniform.mGuestName))); + globalName, getTranslatedName(uniform.mGuestName).c_str()); if (location == -1) { // Location changed after loading from a snapshot. // likely loading from different GPU backend (and they @@ -662,8 +659,8 @@ GLuint ProgramData::getAttachedShader(GLenum type) const { return attachedShaders[s_glShaderType2ShaderType(type)].localName; } -StringView -ProgramData::getTranslatedName(StringView userVarName) const { +std::string +ProgramData::getTranslatedName(const std::string& userVarName) const { if (isGles2Gles()) { return userVarName; } @@ -677,8 +674,8 @@ ProgramData::getTranslatedName(StringView userVarName) const { return userVarName; } -StringView -ProgramData::getDetranslatedName(StringView driverName) const { +std::string +ProgramData::getDetranslatedName(const std::string& driverName) const { if (isGles2Gles()) { return driverName; } @@ -1110,7 +1107,7 @@ static void sInitializeUniformLocs(ProgramData* pData, } } -void ProgramData::initGuestUniformLocForKey(StringView key) { +void ProgramData::initGuestUniformLocForKey(const std::string& key) { // fprintf(stderr, "%s: for %s\n", __func__, key.str().c_str()); if (mUniNameToGuestLoc.find(key) == mUniNameToGuestLoc.end()) { mUniNameToGuestLoc[key] = mCurrUniformBaseLoc; @@ -1129,7 +1126,7 @@ void ProgramData::initGuestUniformLocForKey(StringView key) { } } -void ProgramData::initGuestUniformLocForKey(StringView key, StringView key2) { +void ProgramData::initGuestUniformLocForKey(const std::string& key, const std::string& key2) { bool newUniform = false; if (mUniNameToGuestLoc.find(key) == mUniNameToGuestLoc.end()) { mUniNameToGuestLoc[key] = mCurrUniformBaseLoc; @@ -1199,7 +1196,7 @@ int ProgramData::getGuestUniformLocation(const char* uniName) { } } else { return dispatcher.glGetUniformLocation( - ProgramName, c_str(getTranslatedName(uniName))); + ProgramName, getTranslatedName(uniName).c_str()); } } diff --git a/stream-servers/glestranslator/GLES_V2/ProgramData.h b/stream-servers/glestranslator/GLES_V2/ProgramData.h index 3303d349..3ff06e24 100644 --- a/stream-servers/glestranslator/GLES_V2/ProgramData.h +++ b/stream-servers/glestranslator/GLES_V2/ProgramData.h @@ -18,8 +18,7 @@ #include "ShaderParser.h" -#include "android/base/containers/HybridComponentManager.h" -#include "android/base/StringView.h" +#include "base/HybridComponentManager.h" #include <memory> #include <sstream> @@ -74,8 +73,8 @@ public: GLuint getAttachedComputeShader() const; GLuint getAttachedShader(GLenum type) const; - android::base::StringView getTranslatedName(android::base::StringView userVarName) const; - android::base::StringView getDetranslatedName(android::base::StringView driverName) const; + std::string getTranslatedName(const std::string& userVarName) const; + std::string getDetranslatedName(const std::string& driverName) const; bool attachShader(GLuint shader, ShaderParser* shaderData, GLenum type); bool isAttached(GLuint shader) const; @@ -117,9 +116,9 @@ public: // Virtualize uniform locations // It handles location -1 as well - void initGuestUniformLocForKey(android::base::StringView key); - void initGuestUniformLocForKey(android::base::StringView key, - android::base::StringView key2); + void initGuestUniformLocForKey(const std::string& key); + void initGuestUniformLocForKey(const std::string& key, + const std::string& key2); int getGuestUniformLocation(const char* uniName); int getHostUniformLocation(int guestLocation); diff --git a/stream-servers/glestranslator/GLES_V2/SamplerData.cpp b/stream-servers/glestranslator/GLES_V2/SamplerData.cpp index ab8e92fd..2b3646b7 100644 --- a/stream-servers/glestranslator/GLES_V2/SamplerData.cpp +++ b/stream-servers/glestranslator/GLES_V2/SamplerData.cpp @@ -16,7 +16,7 @@ #include "SamplerData.h" -#include "android/base/files/StreamSerializing.h" +#include "base/StreamSerializing.h" #include "GLcommon/GLEScontext.h" SamplerData::SamplerData(android::base::Stream* stream) diff --git a/stream-servers/glestranslator/GLES_V2/ShaderValidator.cpp b/stream-servers/glestranslator/GLES_V2/ShaderValidator.cpp index 017319ef..166b65a2 100644 --- a/stream-servers/glestranslator/GLES_V2/ShaderValidator.cpp +++ b/stream-servers/glestranslator/GLES_V2/ShaderValidator.cpp @@ -9,170 +9,4 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -#include "emugl/common/stringparsing.h" - #include "ShaderValidator.h" - -// TODO: Improve parsing/analysis -// https://code.google.com/p/android/issues/detail?id=206951 - -static std::vector<std::string> parse_raw_declarations(std::string text) { - std::string emp(""); - std::string sp(" "); - - std::string newline("\n"); - std::string scol(";"); - - std::string openpar("("); - std::string openparsp("( "); - std::string closepar(")"); - std::string openbr("{"); - std::string closebr("}"); - std::string brscol("};"); - - std::string linecomment("//"); - std::string multilinecomment_begin("/*"); - std::string multilinecomment_end("*/"); - - text.insert(0, sp); - - bool err = false; - std::string preprocessed = replace_with(newline, sp, - replace_with(openpar, openparsp, - replace_with(closebr, brscol, - remove_in_out( - remove_in_out( - text, - multilinecomment_begin, - multilinecomment_end, - &err), - linecomment, - newline, - &err)))); - - // Comment parsing is allowed to fail - err = false; - - std::vector<std::string> decls; - std::string no_func_impls = remove_in_out(preprocessed, - openbr, - closebr, - &err); - - if (!err) { - decls = split(scol, no_func_impls); - } - return decls; -} - -// Validates arrangement of keywords in -// a GLSL ES variable declaration or function parameter. -// With the given parsing functions, this is only designed to pass -// dEQP-GLES2.shaders.qualification_order.* -static void validate_keywords_in_decls(const std::vector<std::string>& decls, - bool* err) { - std::vector<std::string> variance_keywords; - - variance_keywords.push_back(std::string("invariant")); - - std::vector<std::string> storage_keywords; - - storage_keywords.push_back(std::string(" const ")); - storage_keywords.push_back(std::string(" uniform ")); - storage_keywords.push_back(std::string(" attribute ")); - storage_keywords.push_back(std::string(" varying ")); - storage_keywords.push_back(std::string(" sampler ")); - - std::vector<std::string> precision_keywords; - - precision_keywords.push_back(std::string(" lowp ")); - precision_keywords.push_back(std::string(" mediump ")); - precision_keywords.push_back(std::string(" highp ")); - precision_keywords.push_back(std::string(" superp ")); - - std::vector<std::string> parameter_keywords; - - parameter_keywords.push_back(std::string(" in ")); // c.f., "int" - parameter_keywords.push_back(std::string(" out ")); - parameter_keywords.push_back(std::string(" inout ")); - - for (size_t i = 0; i < decls.size(); i++) { - std::string variance, storage, precision, parameter; - size_t storage_pos, precision_pos, parameter_pos; - - storage_pos = multi_find(decls[i], storage_keywords); - precision_pos = multi_find(decls[i], precision_keywords); - parameter_pos = multi_find(decls[i], parameter_keywords); - - if (storage_pos != std::string::npos && - precision_pos != std::string::npos) { - if (storage_pos < precision_pos) { - if (parameter_pos != std::string::npos) { - if (parameter_pos > precision_pos) { - *err = true; - } - } - } else { - *err = true; - } - } else if (precision_pos != std::string::npos && - parameter_pos != std::string::npos) { - if (parameter_pos > precision_pos) { - *err = true; - } - } - } -} - -static void validate_glsles_variable_decls( - const std::vector<std::string>& raw_decls, - bool* err) { - std::string openpar("("); - std::vector<std::string> non_function_decls; - for (size_t i = 0; i < raw_decls.size(); i++) { - if (raw_decls[i].find(openpar) == std::string::npos) { - non_function_decls.push_back(raw_decls[i]); - } - } - validate_keywords_in_decls(non_function_decls, err); -} - -static void validate_glsles_function_parameters( - const std::vector<std::string>& raw_decls, - bool* err) { - - bool parse_err = false; - std::string openpar("("); - std::string closepar(")"); - std::string comma(","); - std::vector<std::string> func_param_decls; - for (size_t i = 0; i < raw_decls.size(); i++) { - if (raw_decls[i].find(openpar) != std::string::npos) { - std::vector<std::string> func_params = - isolate_in_out(raw_decls[i], openpar, closepar, &parse_err); - if (func_params.size() > 0) { - // Just use the first set of parens - std::vector<std::string> these_params = - split(comma, func_params[0]); - func_param_decls.insert(func_param_decls.end(), - these_params.begin(), - these_params.end()); - } - } - } - - validate_keywords_in_decls(func_param_decls, err); -} - -bool validate_glsles_keywords(const char* src) { - bool err = false; - - std::vector<std::string> raw_decls = parse_raw_declarations(src); - - // Liberal validation if parsing fails - if (raw_decls.empty()) { return true; } - - validate_glsles_variable_decls(raw_decls, &err); - validate_glsles_function_parameters(raw_decls, &err); - return !err; -} diff --git a/stream-servers/glestranslator/GLES_V2/ShaderValidator.h b/stream-servers/glestranslator/GLES_V2/ShaderValidator.h index d0877a09..00ff4b4a 100644 --- a/stream-servers/glestranslator/GLES_V2/ShaderValidator.h +++ b/stream-servers/glestranslator/GLES_V2/ShaderValidator.h @@ -8,7 +8,5 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - #pragma once -bool validate_glsles_keywords(const char* src); diff --git a/stream-servers/glestranslator/include/GLcommon/GLESmacros.h b/stream-servers/glestranslator/include/GLcommon/GLESmacros.h index 09d177af..6fa7fbd4 100644 --- a/stream-servers/glestranslator/include/GLcommon/GLESmacros.h +++ b/stream-servers/glestranslator/include/GLcommon/GLESmacros.h @@ -7,21 +7,28 @@ #include "base/PathUtils.h" #include "base/MemoryTracker.h" +#if 0 + #define MEM_TRACE_IF(condition, group) \ if ((condition)) { \ static std::once_flag once_flag; \ const std::string func(__FUNCTION__); \ std::call_once(once_flag, [&func]() { \ - if (emugl::getMemoryTracker()) { \ - android::base::StringView file(__FILE__); \ - android::base::StringView baseName; \ - android::base::PathUtils::split(file, NULL, &baseName); \ - emugl::getMemoryTracker()->addToGroup( \ - group, baseName.str() + ":" + func); \ + if (android::base::MemoryTracker::get()) { \ + std::string baseName; \ + android::base::PathUtils::split(std::string(__FILE__), NULL, &baseName); \ + android::base::MemoryTracker::get()->addToGroup( \ + group, baseName.r() + ":" + func); \ } \ }); \ } #else + +#define MEM_TRACE_IF(condition, group) + +#endif + +#else // windows #define MEM_TRACE_IF(condition, group) #endif diff --git a/third-party/angle/CMakeLists.txt b/third-party/angle/CMakeLists.txt index 30e582fb..6e239161 100644 --- a/third-party/angle/CMakeLists.txt +++ b/third-party/angle/CMakeLists.txt @@ -371,7 +371,9 @@ target_include_directories( src/compiler/translator/tree_ops src/compiler/translator/tree_util src/compiler/preprocessor - src/third_party/compiler) + src/third_party/compiler + PUBLIC + src/libShaderTranslator) target_compile_definitions( angle_shader_translator PRIVATE |