Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Specify Vulkan version, fix mip level generation calculation #15211

Merged
merged 4 commits into from
Dec 7, 2021
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
11 changes: 10 additions & 1 deletion Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,22 @@ VkResult VulkanContext::CreateInstance(const CreateInfo &info) {
WARN_LOG(G3D, "WARNING: Does not seem that instance extension '%s' is available. Trying to proceed anyway.", ext);
}

// Check which Vulkan version we should request.
// Our code is fine with any version from 1.0 to 1.2, we don't know about higher versions.
u32 vulkanApiVersion = VK_API_VERSION_1_0;
if (vkEnumerateInstanceVersion) {
vkEnumerateInstanceVersion(&vulkanApiVersion);
vulkanApiVersion &= 0xFFFFF000; // Remove patch version.
vulkanApiVersion = std::min(VK_API_VERSION_1_2, vulkanApiVersion);
}

VkApplicationInfo app_info{ VK_STRUCTURE_TYPE_APPLICATION_INFO };
app_info.pApplicationName = info.app_name;
app_info.applicationVersion = info.app_ver;
app_info.pEngineName = info.app_name;
// Let's increment this when we make major engine/context changes.
app_info.engineVersion = 2;
app_info.apiVersion = VK_API_VERSION_1_0;
app_info.apiVersion = vulkanApiVersion;

VkInstanceCreateInfo inst_info{ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
inst_info.flags = 0;
Expand Down
2 changes: 2 additions & 0 deletions Common/GPU/Vulkan/VulkanLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace PPSSPP_VK {
PFN_vkCreateInstance vkCreateInstance;
PFN_vkDestroyInstance vkDestroyInstance;
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion;
PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures;
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
Expand Down Expand Up @@ -485,6 +486,7 @@ bool VulkanLoad() {
LOAD_GLOBAL_FUNC(vkGetInstanceProcAddr);
LOAD_GLOBAL_FUNC(vkGetDeviceProcAddr);

LOAD_GLOBAL_FUNC(vkEnumerateInstanceVersion);
LOAD_GLOBAL_FUNC(vkEnumerateInstanceExtensionProperties);
LOAD_GLOBAL_FUNC(vkEnumerateInstanceLayerProperties);

Expand Down
1 change: 1 addition & 0 deletions Common/GPU/Vulkan/VulkanLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace PPSSPP_VK {
extern PFN_vkCreateInstance vkCreateInstance;
extern PFN_vkDestroyInstance vkDestroyInstance;
extern PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
extern PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion;
extern PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures;
extern PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
extern PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
Expand Down
2 changes: 2 additions & 0 deletions Common/GPU/Vulkan/VulkanQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,8 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
} else {
// Rendering to backbuffer. Might need to rotate.
const VkRect2D &rc = c.scissor.scissor;
_dbg_assert_(rc.offset.x >= 0);
_dbg_assert_(rc.offset.y >= 0);
DisplayRect<int> rotated_rc{ rc.offset.x, rc.offset.y, (int)rc.extent.width, (int)rc.extent.height };
RotateRectToDisplay(rotated_rc, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight());
_dbg_assert_(rotated_rc.x >= 0);
Expand Down
9 changes: 7 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class VulkanRenderManager {

void SetScissor(VkRect2D rc) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER);
_dbg_assert_((int)rc.offset.x >= 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume one could use the display layout editor to make these values negative (i.e. CenterDisplayOutputRect)?

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah, good point - though it technically is the callers responsibility to do the clipping, maybe it indeed makes sense to tolerate bad dimensions here and adjust automatically instead of asserting.

_dbg_assert_((int)rc.offset.y >= 0);
_dbg_assert_((int)rc.extent.width >= 0);
_dbg_assert_((int)rc.extent.height >= 0);

Expand All @@ -300,7 +302,7 @@ class VulkanRenderManager {
rc.extent.width = std::max(1, newWidth);
if (rc.offset.x >= curWidth_) {
// Fallback.
rc.offset.x = curWidth_ - rc.extent.width;
rc.offset.x = std::max(0, curWidth_ - (int)rc.extent.width);
}
}

Expand All @@ -309,9 +311,12 @@ class VulkanRenderManager {
rc.extent.height = std::max(1, newHeight);
if (rc.offset.y >= curHeight_) {
// Fallback.
rc.offset.y = curHeight_ - rc.extent.height;
rc.offset.y = std::max(0, curHeight_ - (int)rc.extent.height);
}
}

// TODO: If any of the dimensions are now zero, we should flip a flag and not do draws, probably.

curRenderArea_.Apply(rc);

VkRenderData data{ VKRRenderCommand::SCISSOR };
Expand Down
7 changes: 6 additions & 1 deletion Common/SysError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ std::string GetStringErrorMsg(int errCode) {

char err_str[buff_size] = {};
snprintf(err_str, buff_size, "%s", ConvertWStringToUTF8(err_strw).c_str());
return std::string(err_str);

std::string err_string = err_str;
if (!err_string.empty() && err_string.back() == '\n') {
err_string.pop_back();
}
return err_string;
#else
char err_str[buff_size] = {};

Expand Down
23 changes: 13 additions & 10 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,6 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {

VkFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());

// TODO: Really should inspect the format capabilities.
if (g_Config.iTexFiltering == TEX_FILTER_AUTO_MAX_QUALITY) {
// Boost the number of mipmaps.
int maxPossibleMipmaps = log2i(std::min(gstate.getTextureWidth(0), gstate.getTextureHeight(0)));
if (maxPossibleMipmaps > maxLevelToGenerate) {
maxLevelToGenerate = maxPossibleMipmaps;
dstFmt = VK_FORMAT_R8G8B8A8_UNORM;
}
}

int scaleFactor = standardScaleFactor_;
bool hardwareScaling = g_Config.bTexHardwareScaling && uploadCS_ != VK_NULL_HANDLE;
Expand All @@ -664,6 +655,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
badMipSizes = false;
}


// Don't scale the PPGe texture.
if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) {
scaleFactor = 1;
Expand All @@ -685,12 +677,23 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}
}

// TODO: Support mip levels for upscaled images.
// TODO: Support reading actual mip levels for upscaled images, instead of just generating them.
// Probably can just remove this check?
if (scaleFactor > 1) {
maxLevel = 0;
}

int maxPossibleMipmaps = log2i(std::min(w * scaleFactor, h * scaleFactor));

// TODO: Really should inspect the format capabilities.
if (g_Config.iTexFiltering == TEX_FILTER_AUTO_MAX_QUALITY) {
// Boost the number of mipmaps.
if (maxPossibleMipmaps > maxLevelToGenerate) {
dstFmt = VK_FORMAT_R8G8B8A8_UNORM;
}
maxLevelToGenerate = maxPossibleMipmaps;
}

// Any texture scaling is gonna move away from the original 16-bit format, if any.
VkFormat actualFmt = scaleFactor > 1 ? VULKAN_8888_FORMAT : dstFmt;
if (replaced.Valid()) {
Expand Down