external/swiftshader
Revision | 9da287fd0264892a8997426a2d7d154aae560de4 (tree) |
---|---|
Zeit | 2019-11-12 07:56:45 |
Autor | Tim Van Patten <timvp@goog...> |
Commiter | Tim Van Patten |
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>
@@ -7,6 +7,8 @@ | ||
7 | 7 | .vs |
8 | 8 | .vscode/ipch |
9 | 9 | CMakeFiles/ |
10 | +.idea/ | |
11 | +cmake-build-debug/ | |
10 | 12 | |
11 | 13 | # Per user vscode config files. |
12 | 14 | .vscode/launch.json |
@@ -42,4 +44,4 @@ CMakeFiles/ | ||
42 | 44 | *.opendb |
43 | 45 | *.db |
44 | 46 | *~ |
45 | -CMakeCache.txt | |
\ No newline at end of file | ||
47 | +CMakeCache.txt |
@@ -501,6 +501,13 @@ cc_library_shared { | ||
501 | 501 | |
502 | 502 | // Vulkan |
503 | 503 | |
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 | + | |
504 | 511 | cc_defaults { |
505 | 512 | name: "libvk_swiftshader_defaults", |
506 | 513 | vendor: true, |
@@ -520,6 +527,8 @@ cc_defaults { | ||
520 | 527 | "-Wno-unused-parameter", |
521 | 528 | "-Wno-unused-local-typedef", |
522 | 529 | "-Wno-missing-field-initializers", |
530 | + // Enable to output commit hash when SwiftShader is initialized | |
531 | + //"-DENABLE_BUILD_VERSION_OUTPUT", | |
523 | 532 | ], |
524 | 533 | |
525 | 534 | cppflags: [ |
@@ -531,6 +540,8 @@ cc_defaults { | ||
531 | 540 | |
532 | 541 | version_script: "Vulkan/vk_swiftshader.lds", |
533 | 542 | |
543 | + generated_headers: [ "commit_header" ], | |
544 | + | |
534 | 545 | target: { |
535 | 546 | android: { |
536 | 547 | relative_install_path: "hw", |
@@ -12,6 +12,9 @@ | ||
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 | |
15 | +#ifndef Version_h | |
16 | +#define Version_h | |
17 | + | |
15 | 18 | #define MAJOR_VERSION 5 |
16 | 19 | #define MINOR_VERSION 0 |
17 | 20 | #define PATCH_VERSION 0 |
@@ -22,3 +25,5 @@ | ||
22 | 25 | |
23 | 26 | #define REVISION_STRING MACRO_STRINGIFY(BUILD_REVISION) |
24 | 27 | #define VERSION_STRING MACRO_STRINGIFY(MAJOR_VERSION) "." MACRO_STRINGIFY(MINOR_VERSION) "." MACRO_STRINGIFY(PATCH_VERSION) |
28 | + | |
29 | +#endif // Version_h |
@@ -59,8 +59,10 @@ | ||
59 | 59 | #endif |
60 | 60 | |
61 | 61 | #ifdef __ANDROID__ |
62 | +#include <android/log.h> | |
62 | 63 | #include "System/GrallocAndroid.hpp" |
63 | 64 | #include <sync/sync.h> |
65 | +#include "commit.h" | |
64 | 66 | #endif |
65 | 67 | |
66 | 68 | #include "WSI/VkSwapchainKHR.hpp" |
@@ -80,6 +82,16 @@ | ||
80 | 82 | namespace |
81 | 83 | { |
82 | 84 | |
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 | + | |
83 | 95 | bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount) |
84 | 96 | { |
85 | 97 | for(uint32_t j = 0; j < extensionPropertiesCount; ++j) |
@@ -143,6 +155,9 @@ std::shared_ptr<marl::Scheduler> getOrCreateScheduler() | ||
143 | 155 | void initializeLibrary() |
144 | 156 | { |
145 | 157 | static bool doOnce = [] { |
158 | +#if defined(__ANDROID__) && defined(ENABLE_BUILD_VERSION_OUTPUT) | |
159 | + logBuildVersionInformation(); | |
160 | +#endif // __ANDROID__ && ENABLE_BUILD_VERSION_OUTPUT | |
146 | 161 | setReactorDefaultConfig(); |
147 | 162 | setCPUDefaults(); |
148 | 163 | return true; |
@@ -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() |