From d8c18ac6d819341d3a693556e11671182031cf9d Mon Sep 17 00:00:00 2001 From: Jamie Madill Date: Fri, 8 Oct 2021 13:00:19 -0400 Subject: [PATCH] Re-land: "Isolate commit_id.h from other code." Re-land limits the angle_version deps to Windows to fix an iOS visibility rule violation in GN. Instead of recompiling multiple source files, we can seal off the files that include commit_id to prevent recompilations when the commit changes and source files don't change. Bug: angleproject:2551 Change-Id: I033f00ec7afe4bfd01e29e0eea8848eea27747a0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3233899 Reviewed-by: Shahbaz Youssefi Commit-Queue: Jamie Madill --- BUILD.gn | 70 ++++++++++++++----- src/common/angle_version_info.cpp | 31 ++++++++ src/common/angle_version_info.h | 19 +++++ src/libANGLE/Context.cpp | 8 +-- src/libANGLE/MemoryProgramCache.cpp | 4 +- src/libANGLE/Program.cpp | 15 ++-- src/libANGLE/capture/FrameCapture.cpp | 4 +- src/libANGLE/renderer/cl/BUILD.gn | 1 + src/libANGLE/renderer/cl/CLPlatformCL.cpp | 12 ++-- src/libANGLE/renderer/vulkan/BUILD.gn | 4 ++ src/libANGLE/renderer/vulkan/CLPlatformVk.cpp | 5 +- .../vulkan/android/DisplayVkAndroid.cpp | 4 +- src/libGL/entry_points_wgl.cpp | 1 - src/libGLESv2.gni | 8 --- src/libGLESv2/egl_stubs.cpp | 8 ++- 15 files changed, 140 insertions(+), 54 deletions(-) create mode 100644 src/common/angle_version_info.cpp create mode 100644 src/common/angle_version_info.h diff --git a/BUILD.gn b/BUILD.gn index 82460738c..ab390c138 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -376,7 +376,6 @@ angle_static_library("angle_common") { public_deps = [ ":angle_abseil", - ":angle_version", ":includes", ] public_configs += [ ":angle_common_config" ] @@ -663,10 +662,12 @@ config("angle_commit_id_config") { visibility = [ ":angle_commit_id" ] } -_commit_id_output_file = "$root_gen_dir/angle/angle_commit.h" action("angle_commit_id") { + _commit_id_header = "$root_gen_dir/angle/angle_commit.h" script = "src/commit_id.py" - outputs = [ _commit_id_output_file ] + outputs = [ _commit_id_header ] + + visibility = [ ":angle_version" ] # Add git as a dependency if it is available. if (angle_enable_commit_id && @@ -692,7 +693,7 @@ action("angle_commit_id") { args = [ "gen", - rebase_path(_commit_id_output_file, root_build_dir), + rebase_path(_commit_id_header, root_build_dir), ] public_configs = [ ":angle_commit_id_config" ] @@ -701,6 +702,34 @@ action("angle_commit_id") { angle_source_set("angle_version") { sources = [ "src/common/angle_version.h" ] public_deps = [ ":angle_commit_id" ] + visibility = [ ":angle_version_info" ] + + # The version headers are used directly in Windows .RC files. + if (is_win) { + visibility += [ + ":libEGL", + ":libGL", + ":libGLESv1_CM", + ":libGLESv2", + ":libGLESv2_capture_complement", + ] + } + + # TODO(jmadill): Remove once headers isolated. http://anglebug.com/2551 + if (build_with_chromium) { + visibility += [ + "//content/browser:browser", + "//gpu/command_buffer/service:gles2_sources", + ] + } +} + +angle_source_set("angle_version_info") { + sources = [ + "src/common/angle_version_info.cpp", + "src/common/angle_version_info.h", + ] + deps = [ ":angle_version" ] } config("angle_backend_config") { @@ -854,7 +883,7 @@ angle_source_set("libANGLE_base") { public_deps = [ ":angle_common", ":angle_gpu_info_util", - ":angle_version", + ":angle_version_info", ":libANGLE_headers", ":translator", ] @@ -1118,10 +1147,6 @@ template("angle_libGLESv2") { sources += libglesv2_cl_sources } - if (is_win) { - sources += [ "src/libGLESv2/${invoker.output_name}_autogen.def" ] - } - output_name = "${invoker.output_name}${angle_libs_suffix}" configs += [ @@ -1134,7 +1159,13 @@ template("angle_libGLESv2") { deps = invoker.deps + [ ":includes" ] - public_deps = [ ":angle_version" ] + if (is_win) { + sources += [ + "src/libGLESv2/${invoker.output_name}_autogen.def", + "src/libGLESv2/libGLESv2.rc", + ] + deps += [ ":angle_version" ] + } } } @@ -1182,7 +1213,9 @@ if (is_win && !angle_is_winuwp) { ":libANGLE", ] - public_deps = [ ":angle_version" ] + if (is_win) { + deps += [ ":angle_version" ] + } } } @@ -1217,6 +1250,7 @@ angle_shared_library("libGLESv1_CM") { if (is_win) { sources += [ "src/libGLESv1_CM/libGLESv1_CM.def" ] + deps += [ ":angle_version" ] } } @@ -1240,6 +1274,10 @@ angle_source_set("libEGL_egl_loader") { angle_shared_library("libEGL") { sources = libegl_sources + if (is_win) { + sources += [ "src/libEGL/libEGL.rc" ] + } + output_name = "libEGL${angle_libs_suffix}" configs += [ @@ -1254,16 +1292,16 @@ angle_shared_library("libEGL") { defines += [ "EGLAPI=__attribute__((visibility(\"default\")))" ] } - if (is_win) { - sources += [ "src/libEGL/libEGL_autogen.def" ] - } - deps = [ ":angle_common", - ":angle_version", ":libEGL_egl_loader", ] + if (is_win) { + sources += [ "src/libEGL/libEGL_autogen.def" ] + deps += [ ":angle_version" ] + } + public_deps = [ ":includes" ] data_deps = [ ":libGLESv2" ] diff --git a/src/common/angle_version_info.cpp b/src/common/angle_version_info.cpp new file mode 100644 index 000000000..7a1d6ad80 --- /dev/null +++ b/src/common/angle_version_info.cpp @@ -0,0 +1,31 @@ +// +// Copyright 2021 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// angle_version_info.cpp: ANGLE version queries. + +#include "common/angle_version.h" + +namespace angle +{ +int GetANGLERevision() +{ + return ANGLE_REVISION; +} + +const char *GetANGLEVersionString() +{ + return ANGLE_VERSION_STRING; +} + +const char *GetANGLECommitHash() +{ + return ANGLE_COMMIT_HASH; +} + +int GetANGLECommitHashSize() +{ + return ANGLE_COMMIT_HASH_SIZE; +} +} // namespace angle diff --git a/src/common/angle_version_info.h b/src/common/angle_version_info.h new file mode 100644 index 000000000..2f65fafb4 --- /dev/null +++ b/src/common/angle_version_info.h @@ -0,0 +1,19 @@ +// +// Copyright 2021 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// angle_version_info.h: ANGLE version queries. + +#ifndef COMMON_VERSION_H_ +#define COMMON_VERSION_H_ + +namespace angle +{ +int GetANGLERevision(); +const char *GetANGLEVersionString(); +const char *GetANGLECommitHash(); +int GetANGLECommitHashSize(); +} // namespace angle + +#endif // COMMON_VERSION_H_ diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp index 92f6db390..48a61343a 100644 --- a/src/libANGLE/Context.cpp +++ b/src/libANGLE/Context.cpp @@ -15,7 +15,7 @@ #include #include "common/PackedEnums.h" -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "common/matrix_utils.h" #include "common/platform.h" #include "common/system_utils.h" @@ -3210,7 +3210,7 @@ void Context::initVersionStrings() versionString << "OpenGL ES "; } versionString << clientVersion.major << "." << clientVersion.minor << ".0 (ANGLE " - << ANGLE_VERSION_STRING << ")"; + << angle::GetANGLEVersionString() << ")"; mVersionString = MakeStaticString(versionString.str()); std::ostringstream shadingLanguageVersionString; @@ -3224,8 +3224,8 @@ void Context::initVersionStrings() shadingLanguageVersionString << "OpenGL GLSL "; } shadingLanguageVersionString << (clientVersion.major == 2 ? 1 : clientVersion.major) << "." - << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING - << ")"; + << clientVersion.minor << "0 (ANGLE " + << angle::GetANGLEVersionString() << ")"; mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str()); } diff --git a/src/libANGLE/MemoryProgramCache.cpp b/src/libANGLE/MemoryProgramCache.cpp index 6cabc4d35..43bfba112 100644 --- a/src/libANGLE/MemoryProgramCache.cpp +++ b/src/libANGLE/MemoryProgramCache.cpp @@ -16,7 +16,7 @@ #include #include -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "common/utilities.h" #include "libANGLE/BinaryStream.h" #include "libANGLE/Context.h" @@ -116,7 +116,7 @@ void MemoryProgramCache::ComputeHash(const Context *context, } // Add some ANGLE metadata and Context properties, such as version and back-end. - hashStream << ANGLE_COMMIT_HASH << context->getClientMajorVersion() + hashStream << angle::GetANGLECommitHash() << context->getClientMajorVersion() << context->getClientMinorVersion() << context->getString(GL_RENDERER); // Hash pre-link program properties. diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp index 810f2c345..8b7dbc690 100644 --- a/src/libANGLE/Program.cpp +++ b/src/libANGLE/Program.cpp @@ -12,7 +12,7 @@ #include #include -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "common/bitset_utils.h" #include "common/debug.h" #include "common/platform.h" @@ -4635,8 +4635,8 @@ angle::Result Program::serialize(const Context *context, angle::MemoryBuffer *bi { BinaryOutputStream stream; - stream.writeBytes(reinterpret_cast(ANGLE_COMMIT_HASH), - ANGLE_COMMIT_HASH_SIZE); + stream.writeBytes(reinterpret_cast(angle::GetANGLECommitHash()), + angle::GetANGLECommitHashSize()); // nullptr context is supported when computing binary length. if (context) @@ -4716,7 +4716,7 @@ angle::Result Program::serialize(const Context *context, angle::MemoryBuffer *bi } else { - // If we dont have an attached shader, which would occur if this program was + // If we don't have an attached shader, which would occur if this program was // created via glProgramBinary, pull from our cached copy const angle::ProgramSources &cachedLinkedSources = context->getShareGroup()->getFrameCaptureShared()->getProgramSources(id()); @@ -4744,10 +4744,9 @@ angle::Result Program::deserialize(const Context *context, BinaryInputStream &stream, InfoLog &infoLog) { - unsigned char commitString[ANGLE_COMMIT_HASH_SIZE]; - stream.readBytes(commitString, ANGLE_COMMIT_HASH_SIZE); - if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != - 0) + std::vector commitString(angle::GetANGLECommitHashSize(), 0); + stream.readBytes(commitString.data(), commitString.size()); + if (memcmp(commitString.data(), angle::GetANGLECommitHash(), commitString.size()) != 0) { infoLog << "Invalid program binary version."; return angle::Result::Stop; diff --git a/src/libANGLE/capture/FrameCapture.cpp b/src/libANGLE/capture/FrameCapture.cpp index 59e236466..6340c5d79 100644 --- a/src/libANGLE/capture/FrameCapture.cpp +++ b/src/libANGLE/capture/FrameCapture.cpp @@ -16,7 +16,7 @@ #include "sys/stat.h" -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "common/mathutil.h" #include "common/serializer/JsonSerializer.h" #include "common/string_utils.h" @@ -6034,7 +6034,7 @@ void FrameCaptureShared::writeCppReplayIndexFiles(const gl::Context *context, JsonSerializer json; json.startGroup("TraceMetadata"); - json.addScalar("CaptureRevision", ANGLE_REVISION); + json.addScalar("CaptureRevision", GetANGLERevision()); json.addScalar("ContextClientMajorVersion", context->getClientMajorVersion()); json.addScalar("ContextClientMinorVersion", context->getClientMinorVersion()); json.addHexValue("DisplayPlatformType", displayAttribs.getAsInt(EGL_PLATFORM_ANGLE_TYPE_ANGLE)); diff --git a/src/libANGLE/renderer/cl/BUILD.gn b/src/libANGLE/renderer/cl/BUILD.gn index ad88ddffe..ec4154017 100644 --- a/src/libANGLE/renderer/cl/BUILD.gn +++ b/src/libANGLE/renderer/cl/BUILD.gn @@ -40,6 +40,7 @@ angle_source_set("angle_cl_backend") { sources = _cl_backend_sources public_deps = [ + "$angle_root:angle_version_info", "$angle_root:libANGLE_headers", "$angle_root/third_party/OpenCL-ICD-Loader:opencl_icd_loader", ] diff --git a/src/libANGLE/renderer/cl/CLPlatformCL.cpp b/src/libANGLE/renderer/cl/CLPlatformCL.cpp index 239fc9cdb..d9be40feb 100644 --- a/src/libANGLE/renderer/cl/CLPlatformCL.cpp +++ b/src/libANGLE/renderer/cl/CLPlatformCL.cpp @@ -7,15 +7,13 @@ #include "libANGLE/renderer/cl/CLPlatformCL.h" -#include "libANGLE/renderer/cl/CLContextCL.h" -#include "libANGLE/renderer/cl/CLDeviceCL.h" -#include "libANGLE/renderer/cl/cl_util.h" - +#include "common/angle_version_info.h" #include "libANGLE/CLContext.h" #include "libANGLE/CLDevice.h" #include "libANGLE/CLPlatform.h" - -#include "common/angle_version.h" +#include "libANGLE/renderer/cl/CLContextCL.h" +#include "libANGLE/renderer/cl/CLDeviceCL.h" +#include "libANGLE/renderer/cl/cl_util.h" extern "C" { #include "icd.h" @@ -173,7 +171,7 @@ CLPlatformImpl::Info CLPlatformCL::createInfo() const } // Customize version string and name - info.versionStr += " (ANGLE " ANGLE_VERSION_STRING ")"; + info.versionStr += std::string(" (ANGLE ") + angle::GetANGLEVersionString() + ")"; info.name.insert(0u, "ANGLE pass-through -> "); if (version >= CL_MAKE_VERSION(2, 1, 0) && diff --git a/src/libANGLE/renderer/vulkan/BUILD.gn b/src/libANGLE/renderer/vulkan/BUILD.gn index 6110d1ff5..ead0c6f61 100644 --- a/src/libANGLE/renderer/vulkan/BUILD.gn +++ b/src/libANGLE/renderer/vulkan/BUILD.gn @@ -264,6 +264,10 @@ angle_source_set("angle_vulkan_backend") { "$angle_spirv_headers_dir:spv_headers", ] + if (angle_enable_cl || is_android) { + deps += [ "$angle_root:angle_version_info" ] + } + public_deps = [ "$angle_root:angle_glslang_wrapper", "$angle_root:libANGLE_headers", diff --git a/src/libANGLE/renderer/vulkan/CLPlatformVk.cpp b/src/libANGLE/renderer/vulkan/CLPlatformVk.cpp index 19556dd2d..ced79aa4c 100644 --- a/src/libANGLE/renderer/vulkan/CLPlatformVk.cpp +++ b/src/libANGLE/renderer/vulkan/CLPlatformVk.cpp @@ -12,7 +12,7 @@ #include "libANGLE/CLPlatform.h" #include "anglebase/no_destructor.h" -#include "common/angle_version.h" +#include "common/angle_version_info.h" namespace rx { @@ -98,7 +98,8 @@ const std::string &CLPlatformVk::GetVersionString() { static const angle::base::NoDestructor sVersion( "OpenCL " + std::to_string(CL_VERSION_MAJOR(GetVersion())) + "." + - std::to_string(CL_VERSION_MINOR(GetVersion())) + " ANGLE " ANGLE_VERSION_STRING); + std::to_string(CL_VERSION_MINOR(GetVersion())) + " ANGLE " + + angle::GetANGLEVersionString()); return *sVersion; } diff --git a/src/libANGLE/renderer/vulkan/android/DisplayVkAndroid.cpp b/src/libANGLE/renderer/vulkan/android/DisplayVkAndroid.cpp index 1d5afabf5..6301cd08e 100644 --- a/src/libANGLE/renderer/vulkan/android/DisplayVkAndroid.cpp +++ b/src/libANGLE/renderer/vulkan/android/DisplayVkAndroid.cpp @@ -13,7 +13,7 @@ #include #include -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "libANGLE/renderer/driver_utils.h" #include "libANGLE/renderer/vulkan/RendererVk.h" #include "libANGLE/renderer/vulkan/android/HardwareBufferImageSiblingVkAndroid.h" @@ -30,7 +30,7 @@ egl::Error DisplayVkAndroid::initialize(egl::Display *display) ANGLE_TRY(DisplayVk::initialize(display)); std::stringstream strstr; - strstr << "Version (" << ANGLE_VERSION_STRING << "), "; + strstr << "Version (" << angle::GetANGLEVersionString() << "), "; strstr << "Renderer (" << mRenderer->getRendererDescription() << ")"; __android_log_print(ANDROID_LOG_INFO, "ANGLE", "%s", strstr.str().c_str()); diff --git a/src/libGL/entry_points_wgl.cpp b/src/libGL/entry_points_wgl.cpp index 46108fa65..f0045d08a 100644 --- a/src/libGL/entry_points_wgl.cpp +++ b/src/libGL/entry_points_wgl.cpp @@ -7,7 +7,6 @@ #include "entry_points_wgl.h" -#include "common/angle_version.h" #include "common/debug.h" #include "common/event_tracer.h" #include "common/utilities.h" diff --git a/src/libGLESv2.gni b/src/libGLESv2.gni index 93d2121bd..e18c61dc8 100644 --- a/src/libGLESv2.gni +++ b/src/libGLESv2.gni @@ -625,10 +625,6 @@ libglesv2_cl_sources = [ "src/libGLESv2/proc_table_cl_autogen.cpp", ] -if (is_win) { - libglesv2_sources += [ "src/libGLESv2/libGLESv2.rc" ] -} - libglesv1_cm_sources = [ "src/libGLESv1_CM/libGLESv1_CM.cpp", "src/libGLESv1_CM/resource.h", @@ -645,7 +641,3 @@ libegl_sources = [ "src/libGLESv2/entry_points_egl_autogen.h", "src/libGLESv2/entry_points_egl_ext_autogen.h", ] - -if (is_win) { - libegl_sources += [ "src/libEGL/libEGL.rc" ] -} diff --git a/src/libGLESv2/egl_stubs.cpp b/src/libGLESv2/egl_stubs.cpp index 561c38aa8..eef0128b3 100644 --- a/src/libGLESv2/egl_stubs.cpp +++ b/src/libGLESv2/egl_stubs.cpp @@ -8,7 +8,7 @@ #include "libGLESv2/egl_stubs_autogen.h" -#include "common/angle_version.h" +#include "common/angle_version_info.h" #include "libANGLE/Context.h" #include "libANGLE/Display.h" #include "libANGLE/EGLSync.h" @@ -534,8 +534,12 @@ const char *QueryString(Thread *thread, Display *display, EGLint name) result = display->getVendorString().c_str(); break; case EGL_VERSION: - result = "1.5 (ANGLE " ANGLE_VERSION_STRING ")"; + { + static const char *sVersionString = + MakeStaticString(std::string("1.5 (ANGLE ") + angle::GetANGLEVersionString() + ")"); + result = sVersionString; break; + } default: UNREACHABLE(); break;