diff options
author | Jason Macnak <natsu@google.com> | 2024-02-21 17:25:11 -0800 |
---|---|---|
committer | Jason Macnak <natsu@google.com> | 2024-02-27 10:12:50 -0800 |
commit | f044f011451e3faea7388a768f7f8d608e2344a6 (patch) | |
tree | 4142e1da8c6ad1c5fe33221d694162c3096d03e8 | |
parent | e2656c570c905a7c04687852191a42b7301125a2 (diff) | |
download | gfxstream-f044f011451e3faea7388a768f7f8d608e2344a6.tar.gz |
Add renderer param for passing feature enables/disables
... which can be used with aosp/2972172.
Bug: b/326648397
Test: cvd start --gpu_mode=gfxstream
Test: rm -rf build
mkdir build
cd build
cmake .. -G Ninja
ninja
Test: meson setup build \
-Ddefault_library=static \
-Dvalgrind=disabled \
-Dgfxstream-build=both \
meson compile -C build
Change-Id: I38475dc73acdb12053c282feab71dbc85f3320d5
-rw-r--r-- | common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/meson.build | 1 | ||||
-rw-r--r-- | common/utils/Android.bp | 16 | ||||
-rw-r--r-- | common/utils/CMakeLists.txt | 14 | ||||
-rw-r--r-- | common/utils/Strings.cpp | 38 | ||||
-rw-r--r-- | common/utils/include/gfxstream/Strings.h | 24 | ||||
-rw-r--r-- | common/utils/meson.build | 14 | ||||
-rw-r--r-- | host/Android.bp | 1 | ||||
-rw-r--r-- | host/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h | 4 | ||||
-rw-r--r-- | host/meson.build | 4 | ||||
-rw-r--r-- | host/virtio-gpu-gfxstream-renderer.cpp | 42 |
12 files changed, 156 insertions, 4 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ff962c38..00e6638c 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(detector) add_subdirectory(etc) +add_subdirectory(utils) add_subdirectory(vulkan)
\ No newline at end of file diff --git a/common/meson.build b/common/meson.build index 27636921..c1bebf29 100644 --- a/common/meson.build +++ b/common/meson.build @@ -2,3 +2,4 @@ # SPDX-License-Identifier: MIT subdir('etc') +subdir('utils') diff --git a/common/utils/Android.bp b/common/utils/Android.bp new file mode 100644 index 00000000..9d8040b6 --- /dev/null +++ b/common/utils/Android.bp @@ -0,0 +1,16 @@ + +package { + // See: http://go/android-license-faq + default_applicable_licenses: ["hardware_google_gfxstream_license"], +} + +cc_library_static { + name: "libgfxstream_common_utils", + defaults: ["gfxstream_defaults"], + export_include_dirs: [ + "include", + ], + srcs: [ + "Strings.cpp", + ], +} diff --git a/common/utils/CMakeLists.txt b/common/utils/CMakeLists.txt new file mode 100644 index 00000000..6e877b40 --- /dev/null +++ b/common/utils/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library( + gfxstream_common_utils.headers + INTERFACE) +target_include_directories( + gfxstream_common_utils.headers + INTERFACE + include) +add_library( + gfxstream_common_utils + Strings.cpp) +target_link_libraries( + gfxstream_common_utils + PUBLIC + gfxstream_common_utils.headers)
\ No newline at end of file diff --git a/common/utils/Strings.cpp b/common/utils/Strings.cpp new file mode 100644 index 00000000..0389b08e --- /dev/null +++ b/common/utils/Strings.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2024 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 "gfxstream/Strings.h" + +namespace gfxstream { + +std::vector<std::string> Split(const std::string& s, const std::string& delimiters) { + if (delimiters.empty()) { + return {}; + } + + std::vector<std::string> result; + + size_t base = 0; + size_t found; + while (true) { + found = s.find_first_of(delimiters, base); + result.push_back(s.substr(base, found - base)); + if (found == s.npos) break; + base = found + 1; + } + + return result; +} + +} // namespace gfxstream diff --git a/common/utils/include/gfxstream/Strings.h b/common/utils/include/gfxstream/Strings.h new file mode 100644 index 00000000..f7a017eb --- /dev/null +++ b/common/utils/include/gfxstream/Strings.h @@ -0,0 +1,24 @@ +// Copyright 2024 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 <string> +#include <vector> + +namespace gfxstream { + +std::vector<std::string> Split(const std::string& s, const std::string& delimiters); + +} // namespace gfxstream diff --git a/common/utils/meson.build b/common/utils/meson.build new file mode 100644 index 00000000..040300fb --- /dev/null +++ b/common/utils/meson.build @@ -0,0 +1,14 @@ +# Copyright 2024 Android Open Source Project +# SPDX-License-Identifier: MIT + +inc_common_utils = include_directories('include') + +files_lib_common_utils = files( + 'Strings.cpp', +) + +lib_common_utils = static_library( + 'common_utils', + files_lib_common_utils, + include_directories: [inc_common_utils], +)
\ No newline at end of file diff --git a/host/Android.bp b/host/Android.bp index b2e37dcc..6e770f31 100644 --- a/host/Android.bp +++ b/host/Android.bp @@ -53,6 +53,7 @@ cc_library_shared { "gfxstream_glm", "gfxstream_compressedTextures", "gfxstream_emulated_textures", + "libgfxstream_common_utils", "libgfxstream_etc", ], export_static_lib_headers: [ diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 3e280f1e..f19f51c1 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -129,6 +129,7 @@ add_library( target_link_libraries( gfxstream_backend PUBLIC + gfxstream_common_utils gfxstream_backend_static PRIVATE ) diff --git a/host/include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h b/host/include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h index 952718ed..f913f07d 100644 --- a/host/include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h +++ b/host/include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h @@ -54,6 +54,10 @@ typedef void (*stream_renderer_param_metrics_callback_add_vulkan_out_of_memory_e int64_t result_code, uint32_t op_code, const char* function, uint32_t line, uint64_t allocation_size, bool is_host_side_result, bool is_allocation); +// STREAM_RENDERER_PARAM_RENDERER_FEATURES: stream_renderer_param::value is a pointer to a null +// terminated string of the form "<feature1 name>:[enabled|disabled],<feature 2 ...>". +#define STREAM_RENDERER_PARAM_RENDERER_FEATURES 11 + #define STREAM_RENDERER_PARAM_METRICS_CALLBACK_SET_ANNOTATION 1028 typedef void (*stream_renderer_param_metrics_callback_set_annotation)(const char* key, const char* value); diff --git a/host/meson.build b/host/meson.build index 060bbf74..c78142c4 100644 --- a/host/meson.build +++ b/host/meson.build @@ -153,9 +153,9 @@ subdir('apigen-codec-common') subdir('gl/gl-host-common') inc_gfxstream_backend = [inc_root, inc_gfxstream_include, inc_include, inc_apigen_codec, inc_utils, - inc_gl_host_common, inc_host_include] + inc_gl_host_common, inc_host_include, inc_common_utils] -link_gfxstream_backend = [lib_gl_host_common, lib_apigen_codec] +link_gfxstream_backend = [lib_gl_host_common, lib_apigen_codec, lib_common_utils] files_lib_gfxstream_backend = files( 'Buffer.cpp', diff --git a/host/virtio-gpu-gfxstream-renderer.cpp b/host/virtio-gpu-gfxstream-renderer.cpp index 1d9706d8..080238aa 100644 --- a/host/virtio-gpu-gfxstream-renderer.cpp +++ b/host/virtio-gpu-gfxstream-renderer.cpp @@ -30,6 +30,7 @@ #include "aemu/base/Tracing.h" #include "aemu/base/memory/SharedMemory.h" #include "aemu/base/synchronization/Lock.h" +#include "gfxstream/Strings.h" #include "host-common/AddressSpaceService.h" #include "host-common/GfxstreamFatalError.h" #include "host-common/address_space_device.h" @@ -2137,7 +2138,7 @@ static const GoldfishPipeServiceOps goldfish_pipe_service_ops = { }; static int stream_renderer_opengles_init(uint32_t display_width, uint32_t display_height, - int renderer_flags) { + int renderer_flags, const std::string& renderer_features) { stream_renderer_info("start. display dimensions: width %u height %u, renderer flags: 0x%x", display_width, display_height, renderer_flags); @@ -2224,6 +2225,36 @@ static int stream_renderer_opengles_init(uint32_t display_width, uint32_t displa feature_set_enabled_override(kFeature_VulkanSnapshots, true); } + for (const std::string& renderer_feature : gfxstream::Split(renderer_features, ",")) { + if (renderer_feature.empty()) continue; + + const std::vector<std::string>& parts = gfxstream::Split(renderer_feature, ":"); + if (parts.size() != 2) { + stream_renderer_error("Error: invalid renderer features: %s", + renderer_features.c_str()); + return -EINVAL; + } + + const std::string& feature_name = parts[0]; + const Feature feature = feature_from_name(feature_name.c_str()); + if (feature == kFeature_unknown) { + stream_renderer_error("Error: invalid renderer feature: '%s'", feature_name.c_str()); + return -EINVAL; + } + + const std::string& feature_status = parts[1]; + if (feature_status != "enabled" && feature_status != "disabled") { + stream_renderer_error("Error: invalid option %s for renderer feature: %s", + feature_status.c_str(), feature_name.c_str()); + return -EINVAL; + } + + feature_set_enabled_override(feature, feature_status == "enabled"); + + stream_renderer_error("Gfxstream feature %s %s", feature_name.c_str(), + feature_status.c_str()); + } + android::featurecontrol::productFeatureOverride(); if (useVulkanNativeSwapchain && !enableVk) { @@ -2341,6 +2372,7 @@ VG_EXPORT int stream_renderer_init(struct stream_renderer_param* stream_renderer uint32_t display_height = 0; void* renderer_cookie = nullptr; int renderer_flags = 0; + std::string renderer_features; stream_renderer_fence_callback fence_callback = nullptr; bool skip_opengles = false; @@ -2419,6 +2451,11 @@ VG_EXPORT int stream_renderer_init(struct stream_renderer_param* stream_renderer static_cast<uintptr_t>(param.value)); break; } + case STREAM_RENDERER_PARAM_RENDERER_FEATURES: { + renderer_features = + std::string(reinterpret_cast<const char*>(static_cast<uintptr_t>(param.value))); + break; + } case STREAM_RENDERER_PARAM_METRICS_CALLBACK_SET_ANNOTATION: { MetricsLogger::set_crash_annotation_callback = reinterpret_cast<stream_renderer_param_metrics_callback_set_annotation>( @@ -2481,7 +2518,8 @@ VG_EXPORT int stream_renderer_init(struct stream_renderer_param* stream_renderer if (!skip_opengles) { // aemu currently does its own opengles initialization in // qemu/android/android-emu/android/opengles.cpp. - int ret = stream_renderer_opengles_init(display_width, display_height, renderer_flags); + int ret = stream_renderer_opengles_init(display_width, display_height, renderer_flags, + renderer_features); if (ret) { return ret; } |