Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-swiftshader: Commit

external/swiftshader


Commit MetaInfo

Revision9da287fd0264892a8997426a2d7d154aae560de4 (tree)
Zeit2019-11-12 07:56:45
AutorTim Van Patten <timvp@goog...>
CommiterTim Van Patten

Log Message

Output Swiftshader version to logcat

This change allows for outputting the SwiftShader version to Android's
logcat. The version information is as follows:

major.minor.patch.commit_hash

In logcat, when SwiftShader is loaded by ANGLE, this looks like:

11-07 12:17:10.152 9110 9110 I SwiftShader: SwiftShader Version: 5.0.0.9c7bf8093a75
11-07 12:17:10.162 9110 9110 I ANGLE : Version (2.1.0.a2b1a958e2d8), Renderer (Vulkan 1.1.0(SwiftShader Device (0x0000C0DE)))

This allows developers to verify that they are running the expecting
build of SwiftShader when debugging problems or running conformance
tests.

The version information is logged to logcat when the build flag
"ENABLE_BUILD_VERSION_OUTPUT" is enabled within src/Android.bp.

Bug: b/142828252
Change-Id: Iff773b16a2f3532aa843629ec50519b519bbadac
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37990
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Tim Van Patten <timvp@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>

Ändern Zusammenfassung

Diff

--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@
77 .vs
88 .vscode/ipch
99 CMakeFiles/
10+.idea/
11+cmake-build-debug/
1012
1113 # Per user vscode config files.
1214 .vscode/launch.json
@@ -42,4 +44,4 @@ CMakeFiles/
4244 *.opendb
4345 *.db
4446 *~
45-CMakeCache.txt
\ No newline at end of file
47+CMakeCache.txt
--- a/src/Android.bp
+++ b/src/Android.bp
@@ -501,6 +501,13 @@ cc_library_shared {
501501
502502 // Vulkan
503503
504+genrule {
505+ name: "commit_header",
506+ out: ["commit.h"],
507+ tool_files: ["commit_id.py"],
508+ cmd: "$(location commit_id.py) gen $(genDir)/commit.h",
509+}
510+
504511 cc_defaults {
505512 name: "libvk_swiftshader_defaults",
506513 vendor: true,
@@ -520,6 +527,8 @@ cc_defaults {
520527 "-Wno-unused-parameter",
521528 "-Wno-unused-local-typedef",
522529 "-Wno-missing-field-initializers",
530+ // Enable to output commit hash when SwiftShader is initialized
531+ //"-DENABLE_BUILD_VERSION_OUTPUT",
523532 ],
524533
525534 cppflags: [
@@ -531,6 +540,8 @@ cc_defaults {
531540
532541 version_script: "Vulkan/vk_swiftshader.lds",
533542
543+ generated_headers: [ "commit_header" ],
544+
534545 target: {
535546 android: {
536547 relative_install_path: "hw",
--- a/src/Vulkan/Version.h
+++ b/src/Vulkan/Version.h
@@ -12,6 +12,9 @@
1212 // See the License for the specific language governing permissions and
1313 // limitations under the License.
1414
15+#ifndef Version_h
16+#define Version_h
17+
1518 #define MAJOR_VERSION 5
1619 #define MINOR_VERSION 0
1720 #define PATCH_VERSION 0
@@ -22,3 +25,5 @@
2225
2326 #define REVISION_STRING MACRO_STRINGIFY(BUILD_REVISION)
2427 #define VERSION_STRING MACRO_STRINGIFY(MAJOR_VERSION) "." MACRO_STRINGIFY(MINOR_VERSION) "." MACRO_STRINGIFY(PATCH_VERSION)
28+
29+#endif // Version_h
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -59,8 +59,10 @@
5959 #endif
6060
6161 #ifdef __ANDROID__
62+#include <android/log.h>
6263 #include "System/GrallocAndroid.hpp"
6364 #include <sync/sync.h>
65+#include "commit.h"
6466 #endif
6567
6668 #include "WSI/VkSwapchainKHR.hpp"
@@ -80,6 +82,16 @@
8082 namespace
8183 {
8284
85+// Enable commit_id.py and #include commit.h for other platforms.
86+#if defined(__ANDROID__) && defined(ENABLE_BUILD_VERSION_OUTPUT)
87+void logBuildVersionInformation()
88+{
89+ // TODO(b/144093703): Don't call __android_log_print() directly
90+ __android_log_print(ANDROID_LOG_INFO, "SwiftShader", "SwiftShader Version: %s", SWIFTSHADER_VERSION_STRING);
91+}
92+#endif // __ANDROID__ && ENABLE_BUILD_VERSION_OUTPUT
93+
94+
8395 bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount)
8496 {
8597 for(uint32_t j = 0; j < extensionPropertiesCount; ++j)
@@ -143,6 +155,9 @@ std::shared_ptr<marl::Scheduler> getOrCreateScheduler()
143155 void initializeLibrary()
144156 {
145157 static bool doOnce = [] {
158+#if defined(__ANDROID__) && defined(ENABLE_BUILD_VERSION_OUTPUT)
159+ logBuildVersionInformation();
160+#endif // __ANDROID__ && ENABLE_BUILD_VERSION_OUTPUT
146161 setReactorDefaultConfig();
147162 setCPUDefaults();
148163 return true;
--- /dev/null
+++ b/src/commit_id.py
@@ -0,0 +1,72 @@
1+#!/usr/bin/env python
2+# Copyright 2019 The SwiftShader Authors. All Rights Reserved.
3+#
4+# Licensed under the Apache License, Version 2.0 (the "License");
5+# you may not use this file except in compliance with the License.
6+# You may obtain a copy of the License at
7+#
8+# http://www.apache.org/licenses/LICENSE-2.0
9+#
10+# Unless required by applicable law or agreed to in writing, software
11+# distributed under the License is distributed on an "AS IS" BASIS,
12+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+# See the License for the specific language governing permissions and
14+# limitations under the License.
15+#
16+# Generate commit.h with git commit hash.
17+#
18+
19+import subprocess as sp
20+import sys
21+import os
22+
23+usage = """\
24+Usage: commit_id.py check - check if git is present
25+ commit_id.py gen <file_to_write> - generate commit.h"""
26+
27+
28+def grab_output(command, cwd):
29+ return sp.Popen(command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip()
30+
31+
32+if len(sys.argv) < 2:
33+ sys.exit(usage)
34+
35+operation = sys.argv[1]
36+cwd = sys.path[0]
37+
38+if operation == 'check':
39+ index_path = os.path.join(cwd, '.git', 'index')
40+ if os.path.exists(index_path):
41+ print("1")
42+ else:
43+ print("0")
44+ sys.exit(0)
45+
46+if len(sys.argv) < 3 or operation != 'gen':
47+ sys.exit(usage)
48+
49+output_file = sys.argv[2]
50+commit_id_size = 12
51+
52+commit_id = 'invalid-hash'
53+commit_date = 'invalid-date'
54+
55+try:
56+ commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
57+ commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
58+except:
59+ pass
60+
61+hfile = open(output_file, 'w')
62+
63+hfile.write('#define SWIFTSHADER_COMMIT_HASH "%s"\n' % commit_id)
64+hfile.write('#define SWIFTSHADER_COMMIT_HASH_SIZE %d\n' % commit_id_size)
65+hfile.write('#define SWIFTSHADER_COMMIT_DATE "%s"\n' % commit_date)
66+hfile.write('#define SWIFTSHADER_VERSION_STRING \\\n'
67+ 'MACRO_STRINGIFY(MAJOR_VERSION) \".\" \\\n'
68+ 'MACRO_STRINGIFY(MINOR_VERSION) \".\" \\\n'
69+ 'MACRO_STRINGIFY(PATCH_VERSION) \".\" \\\n'
70+ 'SWIFTSHADER_COMMIT_HASH\n')
71+
72+hfile.close()
Show on old repository browser