Integrate BCeNabler support into QuirkManager

Allows using BCn format textures on devices where they are unsupported by the driver.
This commit is contained in:
Billy Laws 2022-01-12 20:45:05 +00:00 committed by PixelyIon
parent 47d920d91e
commit 175ba11f07
8 changed files with 54 additions and 7 deletions

8
.gitmodules vendored
View File

@ -51,3 +51,11 @@
[submodule "Shader Compiler"]
path = app/libraries/shader-compiler
url = https://github.com/skyline-emu/shader-compiler.git
[submodule "libadrenotools"]
path = app/libraries/adrenotools
url = https://github.com/bylaws/libadrenotools/
branch = master
[submodule "app/libraries/adrenotools"]
path = app/libraries/adrenotools
url = https://github.com/bylaws/libadrenotools/
branch = master

View File

@ -104,6 +104,9 @@ add_subdirectory("libraries/range")
# Sirit
add_subdirectory("libraries/sirit")
# libadrenotools
add_subdirectory("libraries/adrenotools")
# Build Skyline with full debugging data and -Og for debug builds
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -glldb -gdwarf-5")
@ -305,4 +308,4 @@ target_include_directories(skyline PRIVATE ${source_DIR}/skyline)
target_compile_options(skyline PRIVATE -Wall -Wno-unknown-attributes -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c99-designator -Wno-reorder -Wno-missing-braces -Wno-unused-variable -Wno-unused-private-field -Wno-dangling-else -Wconversion -fsigned-bitfields)
target_link_libraries(skyline PRIVATE shader_recompiler)
target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode oboe vkma mbedcrypto opus Boost::intrusive Boost::container range-v3)
target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode oboe vkma mbedcrypto opus Boost::intrusive Boost::container range-v3 adrenotools)

@ -0,0 +1 @@
Subproject commit 526ed96751ab7c83959e51ecf594f004341a7ae8

View File

@ -119,7 +119,10 @@ namespace skyline::gpu {
return std::move(vk::raii::PhysicalDevices(instance).front()); // We just select the first device as we aren't expecting multiple GPUs
}
static vk::raii::Device CreateDevice(const vk::raii::PhysicalDevice &physicalDevice, decltype(vk::DeviceQueueCreateInfo::queueCount) &vkQueueFamilyIndex, QuirkManager &quirks) {
static vk::raii::Device CreateDevice(const vk::raii::Context &context,
const vk::raii::PhysicalDevice &physicalDevice,
decltype(vk::DeviceQueueCreateInfo::queueCount) &vkQueueFamilyIndex,
QuirkManager &quirks) {
auto deviceFeatures2{physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceCustomBorderColorFeaturesEXT, vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT, vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT, vk::PhysicalDeviceShaderFloat16Int8Features, vk::PhysicalDeviceShaderAtomicInt64Features>()};
decltype(deviceFeatures2) enabledFeatures2{}; // We only want to enable features we required due to potential overhead from unused features
@ -152,6 +155,7 @@ namespace skyline::gpu {
auto deviceProperties2{physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFloatControlsProperties, vk::PhysicalDeviceSubgroupProperties>()};
quirks = QuirkManager(deviceFeatures2, enabledFeatures2, deviceExtensions, enabledExtensions, deviceProperties2);
quirks.ApplyDriverPatches(context);
std::vector<const char *> pEnabledExtensions;
pEnabledExtensions.reserve(enabledExtensions.size());
@ -207,7 +211,7 @@ namespace skyline::gpu {
: vkInstance(CreateInstance(state, vkContext)),
vkDebugReportCallback(CreateDebugReportCallback(vkInstance)),
vkPhysicalDevice(CreatePhysicalDevice(vkInstance)),
vkDevice(CreateDevice(vkPhysicalDevice, vkQueueFamilyIndex, quirks)),
vkDevice(CreateDevice(vkContext, vkPhysicalDevice, vkQueueFamilyIndex, quirks)),
vkQueue(vkDevice, vkQueueFamilyIndex, 0),
memory(*this),
scheduler(*this),

View File

@ -13,13 +13,13 @@
#include "gpu/shader_manager.h"
namespace skyline::gpu {
static constexpr u32 VkApiVersion{VK_API_VERSION_1_1}; //!< The version of core Vulkan that we require
/**
* @brief An interface to host GPU structures, anything concerning host GPU/Presentation APIs is encapsulated by this
*/
class GPU {
public:
static constexpr u32 VkApiVersion{VK_API_VERSION_1_1}; //!< The version of core Vulkan that we require
vk::raii::Context vkContext;
vk::raii::Instance vkInstance;
vk::raii::DebugReportCallbackEXT vkDebugReportCallback; //!< An RAII Vulkan debug report manager which calls into 'GPU::DebugCallback'

View File

@ -65,7 +65,7 @@ namespace skyline::gpu::memory {
.device = *gpu.vkDevice,
.instance = *gpu.vkInstance,
.pVulkanFunctions = &vulkanFunctions,
.vulkanApiVersion = GPU::VkApiVersion,
.vulkanApiVersion = VkApiVersion,
};
ThrowOnFail(vmaCreateAllocator(&allocatorCreateInfo, &vmaAllocator));
}

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <adrenotools/bcenabler.h>
#include "quirk_manager.h"
namespace skyline::gpu {
@ -103,6 +104,31 @@ namespace skyline::gpu {
subgroupSize = deviceProperties2.get<vk::PhysicalDeviceSubgroupProperties>().subgroupSize;
}
void QuirkManager::ApplyDriverPatches(const vk::raii::Context &context) {
// Create an instance without validation layers in order to get pointers to the functions we need to patch from the driver
vk::ApplicationInfo applicationInfo{
.apiVersion = VK_API_VERSION_1_0,
};
auto instance{vk::raii::Instance(context, vk::InstanceCreateInfo{
.pApplicationInfo = &applicationInfo
})};
auto physicalDevice{std::move(instance.enumeratePhysicalDevices().front())};
auto properties{physicalDevice.getProperties()};
// Apply BCeNabler for Adreno devices
auto type{adrenotools_get_bcn_type( VK_VERSION_MAJOR(properties.driverVersion), VK_VERSION_MINOR(properties.driverVersion), properties.vendorID)};
if (type == ADRENOTOOLS_BCN_PATCH) {
if (adrenotools_patch_bcn(reinterpret_cast<void *>(physicalDevice.getDispatcher()->vkGetPhysicalDeviceFormatProperties)))
Logger::Info("Applied BCeNabler patch");
else
throw exception("Failed to apply BCeNabler patch!");
} else if (type == ADRENOTOOLS_BCN_BLOB) {
Logger::Info("BCeNabler skipped, blob BCN support is present");
}
}
std::string QuirkManager::Summary() {
return fmt::format(
"\n* Supports U8 Indices: {}\n* Supports Sampler Mirror Clamp To Edge: {}\n* Supports Sampler Reduction Mode: {}\n* Supports Custom Border Color (Without Format): {}\n* Supports Last Provoking Vertex: {}\n* Supports Logical Operations: {}\n* Supports Vertex Attribute Divisor: {}\n* Supports Vertex Attribute Zero Divisor: {}\n* Supports Multiple Viewports: {}\n* Supports Shader Viewport Index: {}\n* Supports SPIR-V 1.4: {}\n* Supports Shader Invocation Demotion: {}\n* Supports 16-bit FP: {}\n* Supports 8-bit Integers: {}\n* Supports 16-bit Integers: {}\n* Supports 64-bit Integers: {}\n* Supports Atomic 64-bit Integers: {}\n* Supports Floating Point Behavior Control: {}\n* Supports Image Read Without Format: {}\n* Supports Subgroup Vote: {}\n* Subgroup Size: {}",

View File

@ -3,7 +3,7 @@
#pragma once
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_raii.hpp>
#include <common.h>
namespace skyline::gpu {
@ -43,6 +43,11 @@ namespace skyline::gpu {
QuirkManager(const DeviceFeatures2 &deviceFeatures2, DeviceFeatures2 &enabledFeatures2, const std::vector<vk::ExtensionProperties> &deviceExtensions, std::vector<std::array<char, VK_MAX_EXTENSION_NAME_SIZE>> &enabledExtensions, const DeviceProperties2 &deviceProperties2);
/**
* @brief Applies driver specific binary patches to the driver (e.g. BCeNabler)
*/
void ApplyDriverPatches(const vk::raii::Context &context);
/**
* @return A summary of all the GPU quirks as a human-readable string
*/