Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions host/features/include/gfxstream/host/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,21 @@ struct FeatureSet {
"and the available Vulkan driver extensions.",
&map,
};
StringFeatureInfo VulkanValidation = {
"VulkanValidation",
"If set, configures Vulkan validation behavior (off|print|fail|crash).",
&map,
};
StringFeatureInfo VulkanValidationIncludeFilter = {
"VulkanValidationIncludeFilter",
"Comma-separated, case-insensitive list of exact string filters to include for Vulkan validation. Matches against guest application name or engine name. If empty, all applications are included by default.",
&map,
};
StringFeatureInfo VulkanValidationExcludeFilter = {
"VulkanValidationExcludeFilter",
"Comma-separated, case-insensitive list of exact string filters to exclude from Vulkan validation. Matches against guest application name or engine name.",
&map,
};
BoolFeatureInfo VulkanProtectedMemoryEmulation = {
"VulkanProtectedMemoryEmulation",
"If enabled, enables protected memory emulation for the guest.",
Expand Down
6 changes: 6 additions & 0 deletions host/frame_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,12 @@ std::unique_ptr<FrameBuffer::Impl> FrameBuffer::Impl::Create(FrameBuffer* frameb
// used by underlying EGL driver might become invalid,
// preventing new contexts from being created that share
// against those contexts.
if (impl->m_features.VulkanValidation.getValue().has_value() ||
impl->m_features.VulkanValidationIncludeFilter.getValue().has_value() ||
impl->m_features.VulkanValidationExcludeFilter.getValue().has_value()) {
vk::ensureVulkanValidationLayersEnabled();
}

vk::VulkanDispatch* vkDispatch = nullptr;
if (impl->m_features.Vulkan.enabled()) {
vkDispatch = vk::vkDispatch(false /* not for testing */);
Expand Down
6 changes: 6 additions & 0 deletions host/virtio_gpu_gfxstream_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ RendererPtr InitRenderer(uint32_t displayWidth,
GFXSTREAM_DEBUG("Initializing renderer with width:%u height:%u renderer-flags:0x%x",
displayWidth, displayHeight, rendererFlags);

if (features.VulkanValidation.getValue().has_value() ||
features.VulkanValidationIncludeFilter.getValue().has_value() ||
features.VulkanValidationExcludeFilter.getValue().has_value()) {
gfxstream::host::vk::ensureVulkanValidationLayersEnabled();
}

gfxstream::host::vk::vkDispatch(false /* don't use test ICD */);

static gfxstream::RenderLibPtr sRendererLibrary = gfxstream::initLibrary();
Expand Down
1 change: 1 addition & 0 deletions host/vulkan/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ cc_library_static {
"vk_format_utils.cpp",
"vk_reconstruction.cpp",
"vk_utils.cpp",
"vk_vvl_configuration.cpp",
"vulkan_boxed_handles.cpp",
"vulkan_dispatch.cpp",
"vulkan_handle_mapping.cpp",
Expand Down
3 changes: 3 additions & 0 deletions host/vulkan/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cc_library(
"vk_qsri_timeline.h",
"vk_snapshot_handles.h",
"vk_utils.h",
"vk_vvl_configuration.h",
"vulkan_boxed_handles.h",
"vulkan_dispatch.h",
"vulkan_handle_mapping.h",
Expand Down Expand Up @@ -86,6 +87,7 @@ cc_library(
"vk_format_utils.cpp",
"vk_reconstruction.cpp",
"vk_utils.cpp",
"vk_vvl_configuration.cpp",
"vulkan_boxed_handles.cpp",
"vulkan_dispatch.cpp",
"vulkan_handle_mapping.cpp",
Expand Down Expand Up @@ -126,6 +128,7 @@ cc_library(
"vk_reconstruction.h",
"vk_snapshot_handles.h",
"vk_utils.h",
"vk_vvl_configuration.h",
"vulkan_boxed_handles.h",
"vulkan_dispatch.h",
"vulkan_handle_mapping.h",
Expand Down
1 change: 1 addition & 0 deletions host/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_library(gfxstream-vulkan-server
vk_format_utils.cpp
vk_reconstruction.cpp
vk_utils.cpp
vk_vvl_configuration.cpp
vulkan_boxed_handles.cpp
vulkan_dispatch.cpp
vulkan_handle_mapping.cpp
Expand Down
1 change: 1 addition & 0 deletions host/vulkan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ files_lib_vulkan_server = files(
'vk_format_utils.cpp',
'vk_reconstruction.cpp',
'vk_utils.cpp',
'vk_vvl_configuration.cpp',
'vulkan_boxed_handles.cpp',
'vulkan_dispatch.cpp',
'vulkan_handle_mapping.cpp',
Expand Down
13 changes: 13 additions & 0 deletions host/vulkan/vk_common_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ std::unique_ptr<VkEmulation> VkEmulation::create(VulkanDispatch* gvk,
emulation->m_globalState = globalState;
emulation->mGvk = gvk;
emulation->setFeatures(features);
auto vvlConfig = VVLConfiguration::parse(features);
if (vvlConfig.getBehavior() != VVLBehavior::None) {
emulation->mVVLConfig.emplace(std::move(vvlConfig));
}

std::vector<const char*> getPhysicalDeviceProperties2InstanceExtNames = {
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
Expand Down Expand Up @@ -1818,6 +1822,15 @@ bool VkEmulation::createResourcesWithRequirementsEnabled() const {
return mUseCreateResourcesWithRequirements;
}

std::unique_ptr<VVLContext> VkEmulation::createVVLContext(
const std::string& appName, const std::string& engineName,
VkDebugUtilsMessengerCreateInfoEXT* outCreateInfo) const {
if (!mVVLConfig.has_value()) {
return nullptr;
}
return mVVLConfig->createDebugContext(appName, engineName, outCreateInfo);
}

bool VkEmulation::supportsGetPhysicalDeviceProperties2() const {
return mInstanceSupportsGetPhysicalDeviceProperties2;
}
Expand Down
8 changes: 8 additions & 0 deletions host/vulkan/vk_common_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <unordered_set>
#include <vector>

#include "vk_vvl_configuration.h"

#include "color_buffer_vk.h"
#include "compositor_vk.h"
#include "debug_utils_helper.h"
Expand Down Expand Up @@ -187,6 +189,10 @@ class VkEmulation {

bool isGuestVulkanOnly() const;

std::unique_ptr<VVLContext> createVVLContext(
const std::string& appName, const std::string& engineName,
VkDebugUtilsMessengerCreateInfoEXT* outCreateInfo = nullptr) const;

bool commandBufferCheckpointsEnabled() const;

bool supportsSamplerYcbcrConversion() const;
Expand Down Expand Up @@ -801,6 +807,8 @@ class VkEmulation {

// UdmabufCreator
std::unique_ptr<UdmabufCreator> mUdmabufCreator;

std::optional<VVLConfiguration> mVVLConfig;
};

#ifdef __ANDROID__
Expand Down
66 changes: 63 additions & 3 deletions host/vulkan/vk_decoder_global_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,38 @@ class VkDecoderGlobalState::Impl {
deepcopy_VkInstanceCreateInfo(pool, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, pCreateInfo,
&createInfoFiltered);

std::string vvlAppName = "";
std::string vvlEngineName = "";
if (pCreateInfo->pApplicationInfo) {
if (pCreateInfo->pApplicationInfo->pApplicationName) {
vvlAppName = pCreateInfo->pApplicationInfo->pApplicationName;
}
if (pCreateInfo->pApplicationInfo->pEngineName) {
vvlEngineName = pCreateInfo->pApplicationInfo->pEngineName;
}
}

VkDebugUtilsMessengerCreateInfoEXT debugInfo = {};
std::unique_ptr<VVLContext> debugContext =
m_vkEmulation->createVVLContext(vvlAppName, vvlEngineName, &debugInfo);

if (debugContext) {
GFXSTREAM_INFO("Enabling VVL for %s %s", vvlAppName.c_str(), vvlEngineName.c_str());

bool hasDebugUtils = false;
for (const char* ext : finalExts) {
if (ext && strcmp(ext, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) {
hasDebugUtils = true;
break;
}
}
if (!hasDebugUtils) {
finalExts.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
} else {
GFXSTREAM_VERBOSE("Not enabling VVL for %s %s", vvlAppName.c_str(), vvlEngineName.c_str());
}

createInfoFiltered.enabledExtensionCount = static_cast<uint32_t>(finalExts.size());
createInfoFiltered.ppEnabledExtensionNames = finalExts.data();
if (createInfoFiltered.pApplicationInfo != nullptr) {
Expand All @@ -1175,6 +1207,11 @@ class VkDecoderGlobalState::Impl {
vk_struct_chain_filter<VkDebugReportCallbackCreateInfoEXT>(&createInfoFiltered);
vk_struct_chain_filter<VkDebugUtilsMessengerCreateInfoEXT>(&createInfoFiltered);

if (debugContext) {
auto chainIter = vk_make_chain_iterator(&createInfoFiltered);
vk_append_struct(&chainIter, &debugInfo);
}

#if defined(__APPLE__)
if (m_vkEmulation->supportsPortabilityEnumeration()) {
createInfoFiltered.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
Expand Down Expand Up @@ -1234,14 +1271,30 @@ class VkDecoderGlobalState::Impl {
info.contextId = renderThreadInfo->ctx_id;
}

if (debugContext) {
auto vk = dispatch_VkInstance(boxed);
if (vk && vk->vkCreateDebugUtilsMessengerEXT && vk->vkDestroyDebugUtilsMessengerEXT) {
VkDebugUtilsMessengerEXT messenger = VK_NULL_HANDLE;
VkResult messengerRes = vk->vkCreateDebugUtilsMessengerEXT(*pInstance, &debugInfo, nullptr, &messenger);
if (messengerRes == VK_SUCCESS) {
info.debugMessenger = messenger;
} else {
GFXSTREAM_WARNING("Failed to create Vulkan debug utils messenger: %s", string_VkResult(messengerRes));
}
}
}

uint64_t contextId = info.contextId;
info.debugContext = std::move(debugContext);

VALIDATE_NEW_HANDLE_INFO_ENTRY(mInstanceInfo, *pInstance);
mInstanceInfo[*pInstance] = info;
mInstanceInfo[*pInstance] = std::move(info);

*pInstance = (VkInstance)info.boxed;
*pInstance = (VkInstance)boxed;

if (vkCleanupEnabled()) {
m_vkEmulation->getGlobalState()->registerProcessCleanupCallback(
unbox_VkInstance(boxed), info.contextId, [this, boxed] {
unbox_VkInstance(boxed), contextId, [this, boxed] {
if (snapshotsEnabled()) {
snapshot()->vkDestroyInstance(nullptr, kInvalidSnapshotApiCallHandle, nullptr, 0, boxed, nullptr);
}
Expand Down Expand Up @@ -11055,6 +11108,13 @@ class VkDecoderGlobalState::Impl {
destroyDeviceObjects(deviceObjects);
}

if (instanceInfo.debugMessenger != VK_NULL_HANDLE) {
auto vk = dispatch_VkInstance(instanceInfo.boxed);
if (vk && vk->vkDestroyDebugUtilsMessengerEXT) {
vk->vkDestroyDebugUtilsMessengerEXT(instance, instanceInfo.debugMessenger, nullptr);
}
}

m_vk->vkDestroyInstance(instance, nullptr);
GFXSTREAM_INFO("Destroyed VkInstance:%p for application:'%s' engine:'%s'.", instance,
instanceInfo.applicationName.c_str(), instanceInfo.engineName.c_str());
Expand Down
4 changes: 4 additions & 0 deletions host/vulkan/vk_decoder_internal_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <string>
#include <unordered_map>

#include "vk_vvl_configuration.h"

#include "common/goldfish_vk_deepcopy.h"
#include "debug_utils_helper.h"
#include "device_op_tracker.h"
Expand Down Expand Up @@ -216,6 +218,8 @@ struct InstanceInfo {
std::string applicationName;
std::string engineName;
uint32_t contextId = 0;
std::unique_ptr<VVLContext> debugContext;
VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
};

struct PhysicalDeviceInfo {
Expand Down
Loading
Loading