Commit 9da287fd by 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: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 503d196f
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
.vs .vs
.vscode/ipch .vscode/ipch
CMakeFiles/ CMakeFiles/
.idea/
cmake-build-debug/
# Per user vscode config files. # Per user vscode config files.
.vscode/launch.json .vscode/launch.json
...@@ -42,4 +44,4 @@ CMakeFiles/ ...@@ -42,4 +44,4 @@ CMakeFiles/
*.opendb *.opendb
*.db *.db
*~ *~
CMakeCache.txt CMakeCache.txt
\ No newline at end of file
...@@ -501,6 +501,13 @@ cc_library_shared { ...@@ -501,6 +501,13 @@ cc_library_shared {
// Vulkan // Vulkan
genrule {
name: "commit_header",
out: ["commit.h"],
tool_files: ["commit_id.py"],
cmd: "$(location commit_id.py) gen $(genDir)/commit.h",
}
cc_defaults { cc_defaults {
name: "libvk_swiftshader_defaults", name: "libvk_swiftshader_defaults",
vendor: true, vendor: true,
...@@ -520,6 +527,8 @@ cc_defaults { ...@@ -520,6 +527,8 @@ cc_defaults {
"-Wno-unused-parameter", "-Wno-unused-parameter",
"-Wno-unused-local-typedef", "-Wno-unused-local-typedef",
"-Wno-missing-field-initializers", "-Wno-missing-field-initializers",
// Enable to output commit hash when SwiftShader is initialized
//"-DENABLE_BUILD_VERSION_OUTPUT",
], ],
cppflags: [ cppflags: [
...@@ -531,6 +540,8 @@ cc_defaults { ...@@ -531,6 +540,8 @@ cc_defaults {
version_script: "Vulkan/vk_swiftshader.lds", version_script: "Vulkan/vk_swiftshader.lds",
generated_headers: [ "commit_header" ],
target: { target: {
android: { android: {
relative_install_path: "hw", relative_install_path: "hw",
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef Version_h
#define Version_h
#define MAJOR_VERSION 5 #define MAJOR_VERSION 5
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define PATCH_VERSION 0 #define PATCH_VERSION 0
...@@ -22,3 +25,5 @@ ...@@ -22,3 +25,5 @@
#define REVISION_STRING MACRO_STRINGIFY(BUILD_REVISION) #define REVISION_STRING MACRO_STRINGIFY(BUILD_REVISION)
#define VERSION_STRING MACRO_STRINGIFY(MAJOR_VERSION) "." MACRO_STRINGIFY(MINOR_VERSION) "." MACRO_STRINGIFY(PATCH_VERSION) #define VERSION_STRING MACRO_STRINGIFY(MAJOR_VERSION) "." MACRO_STRINGIFY(MINOR_VERSION) "." MACRO_STRINGIFY(PATCH_VERSION)
#endif // Version_h
...@@ -59,8 +59,10 @@ ...@@ -59,8 +59,10 @@
#endif #endif
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <android/log.h>
#include "System/GrallocAndroid.hpp" #include "System/GrallocAndroid.hpp"
#include <sync/sync.h> #include <sync/sync.h>
#include "commit.h"
#endif #endif
#include "WSI/VkSwapchainKHR.hpp" #include "WSI/VkSwapchainKHR.hpp"
...@@ -80,6 +82,16 @@ ...@@ -80,6 +82,16 @@
namespace namespace
{ {
// Enable commit_id.py and #include commit.h for other platforms.
#if defined(__ANDROID__) && defined(ENABLE_BUILD_VERSION_OUTPUT)
void logBuildVersionInformation()
{
// TODO(b/144093703): Don't call __android_log_print() directly
__android_log_print(ANDROID_LOG_INFO, "SwiftShader", "SwiftShader Version: %s", SWIFTSHADER_VERSION_STRING);
}
#endif // __ANDROID__ && ENABLE_BUILD_VERSION_OUTPUT
bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount) bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount)
{ {
for(uint32_t j = 0; j < extensionPropertiesCount; ++j) for(uint32_t j = 0; j < extensionPropertiesCount; ++j)
...@@ -143,6 +155,9 @@ std::shared_ptr<marl::Scheduler> getOrCreateScheduler() ...@@ -143,6 +155,9 @@ std::shared_ptr<marl::Scheduler> getOrCreateScheduler()
void initializeLibrary() void initializeLibrary()
{ {
static bool doOnce = [] { static bool doOnce = [] {
#if defined(__ANDROID__) && defined(ENABLE_BUILD_VERSION_OUTPUT)
logBuildVersionInformation();
#endif // __ANDROID__ && ENABLE_BUILD_VERSION_OUTPUT
setReactorDefaultConfig(); setReactorDefaultConfig();
setCPUDefaults(); setCPUDefaults();
return true; return true;
......
#!/usr/bin/env python
# Copyright 2019 The SwiftShader Authors. All Rights Reserved.
#
# 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.
#
# Generate commit.h with git commit hash.
#
import subprocess as sp
import sys
import os
usage = """\
Usage: commit_id.py check - check if git is present
commit_id.py gen <file_to_write> - generate commit.h"""
def grab_output(command, cwd):
return sp.Popen(command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip()
if len(sys.argv) < 2:
sys.exit(usage)
operation = sys.argv[1]
cwd = sys.path[0]
if operation == 'check':
index_path = os.path.join(cwd, '.git', 'index')
if os.path.exists(index_path):
print("1")
else:
print("0")
sys.exit(0)
if len(sys.argv) < 3 or operation != 'gen':
sys.exit(usage)
output_file = sys.argv[2]
commit_id_size = 12
commit_id = 'invalid-hash'
commit_date = 'invalid-date'
try:
commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
except:
pass
hfile = open(output_file, 'w')
hfile.write('#define SWIFTSHADER_COMMIT_HASH "%s"\n' % commit_id)
hfile.write('#define SWIFTSHADER_COMMIT_HASH_SIZE %d\n' % commit_id_size)
hfile.write('#define SWIFTSHADER_COMMIT_DATE "%s"\n' % commit_date)
hfile.write('#define SWIFTSHADER_VERSION_STRING \\\n'
'MACRO_STRINGIFY(MAJOR_VERSION) \".\" \\\n'
'MACRO_STRINGIFY(MINOR_VERSION) \".\" \\\n'
'MACRO_STRINGIFY(PATCH_VERSION) \".\" \\\n'
'SWIFTSHADER_COMMIT_HASH\n')
hfile.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment