renderer_vulkan: Fix warnings and cleanup

This commit is contained in:
GPUCode
2022-10-07 14:02:55 +03:00
parent 85df778785
commit 0bfaa035b9
21 changed files with 42 additions and 47 deletions

View File

@ -191,7 +191,11 @@ endif()
create_target_directory_groups(video_core)
# Include Vulkan headers
if (NOT MSVC)
# Ignore nullability warnings generated from VMA
target_compile_options(vma INTERFACE -Wno-unused-variable -Wno-nullability-completeness)
endif()
target_link_libraries(video_core PUBLIC common core)
target_link_libraries(video_core PRIVATE glad vma vulkan-headers glm::glm SPIRV glslang nihstro-headers Boost::serialization)
set_target_properties(video_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO})

View File

@ -3,7 +3,7 @@
// Refer to the license.txt file included.
#pragma once
#include <array>
#include "common/logging/log.h"
#include "core/core.h"
#include "video_core/regs.h"
@ -13,20 +13,6 @@ namespace PicaToVK {
using TextureFilter = Pica::TexturingRegs::TextureConfig::TextureFilter;
struct FilterInfo {
vk::Filter mag_filter, min_filter;
vk::SamplerMipmapMode mip_mode;
};
inline FilterInfo TextureFilterMode(TextureFilter mag, TextureFilter min, TextureFilter mip) {
constexpr std::array filter_table = {vk::Filter::eNearest, vk::Filter::eLinear};
constexpr std::array mipmap_table = {vk::SamplerMipmapMode::eNearest,
vk::SamplerMipmapMode::eLinear};
return FilterInfo{filter_table.at(mag), filter_table.at(min), mipmap_table.at(mip)};
}
inline vk::Filter TextureFilterMode(TextureFilter mode) {
switch (mode) {
case TextureFilter::Linear:

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/gtc/matrix_transform.hpp>
#include "common/assert.h"
@ -942,7 +941,7 @@ void RendererVulkan::SwapBuffers() {
// Create swapchain if needed
if (swapchain.NeedsRecreation()) {
swapchain.Create(layout.width, layout.height, false);
swapchain.Create(layout.width, layout.height);
}
// Calling Submit will change the slot so get the required semaphores now

View File

@ -2,8 +2,11 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VMA_IMPLEMENTATION
#include "video_core/renderer_vulkan/vk_common.h"
// Implement vma functions
#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.h>
// Store the dispatch loader here
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

View File

@ -9,13 +9,11 @@
// Include vulkan-hpp header
#define VK_NO_PROTOTYPES 1
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <vulkan/vulkan.hpp>
// Include Vulkan memory allocator
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#define VMA_VULKAN_VERSION 1001000 // Vulkan 1.1
#include <vk_mem_alloc.h>
namespace Vulkan {

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include "video_core/renderer_vulkan/vk_format_reinterpreter.h"
#include "video_core/renderer_vulkan/vk_shader.h"
#include "video_core/renderer_vulkan/vk_texture_runtime.h"

View File

@ -2,13 +2,14 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <span>
#include "common/assert.h"
#include "core/frontend/emu_window.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_platform.h"
#include <vk_mem_alloc.h>
namespace Vulkan {
vk::Format ToVkFormat(VideoCore::PixelFormat format) {

View File

@ -14,6 +14,8 @@ namespace Frontend {
class EmuWindow;
}
VK_DEFINE_HANDLE(VmaAllocator)
namespace Vulkan {
struct FormatTraits {

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <filesystem>
#include "common/common_paths.h"
#include "common/file_util.h"

View File

@ -11,7 +11,7 @@
namespace Frontend {
class EmuWindow;
enum class WindowSystemType : u8;
} // namespace Frontend
}
namespace Vulkan {

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include "common/alignment.h"
#include "common/logging/log.h"
#include "common/math_util.h"
@ -175,7 +174,6 @@ RasterizerVulkan::~RasterizerVulkan() {
renderpass_cache.ExitRenderpass();
scheduler.Submit(SubmitMode::Flush | SubmitMode::Shutdown);
VmaAllocator allocator = instance.GetAllocator();
vk::Device device = instance.GetDevice();
for (auto& [key, sampler] : samplers) {
@ -186,9 +184,13 @@ RasterizerVulkan::~RasterizerVulkan() {
device.destroyFramebuffer(framebuffer);
}
vmaDestroyImage(allocator, default_texture.image, default_texture.allocation);
device.destroyImageView(default_texture.image_view);
device.destroyImageView(default_texture.base_view);
const VideoCore::HostTextureTag tag = {
.format = VideoCore::PixelFormat::RGBA8,
.width = 1,
.height = 1
};
runtime.Recycle(tag, std::move(default_texture));
device.destroySampler(default_sampler);
}

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include "common/assert.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <SPIRV/GlslangToSpv.h>
#include <glslang/Include/ResourceLimits.h>
#include <glslang/Public/ShaderLang.h>

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#pragma once
#include <functional>
#include <optional>
#include "common/hash.h"

View File

@ -2,15 +2,15 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <algorithm>
#include "common/alignment.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_stream_buffer.h"
#include "video_core/renderer_vulkan/vk_task_scheduler.h"
#include <vk_mem_alloc.h>
namespace Vulkan {
inline auto ToVkAccessStageFlags(vk::BufferUsageFlagBits usage) {

View File

@ -3,12 +3,15 @@
// Refer to the license.txt file included.
#pragma once
#include <array>
#include <map>
#include <span>
#include "common/assert.h"
#include "video_core/renderer_vulkan/vk_common.h"
VK_DEFINE_HANDLE(VmaAllocation)
namespace Vulkan {
class Instance;

View File

@ -2,9 +2,9 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include <algorithm>
#include "common/logging/log.h"
#include "core/settings.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
#include "video_core/renderer_vulkan/vk_swapchain.h"
@ -29,7 +29,7 @@ Swapchain::~Swapchain() {
}
}
void Swapchain::Create(u32 width, u32 height, bool vsync_enabled) {
void Swapchain::Create(u32 width, u32 height) {
is_outdated = false;
is_suboptimal = false;
@ -184,12 +184,14 @@ void Swapchain::Configure(u32 width, u32 height) {
// FIFO is guaranteed by the Vulkan standard to be available
present_mode = vk::PresentModeKHR::eFifo;
auto iter = std::ranges::find_if(
modes, [](vk::PresentModeKHR mode) { return vk::PresentModeKHR::eMailbox == mode; });
if (!Settings::values.use_vsync_new) {
auto iter = std::ranges::find_if(
modes, [](vk::PresentModeKHR mode) { return vk::PresentModeKHR::eMailbox == mode; });
// Prefer Mailbox if present for lowest latency
if (iter != modes.end()) {
present_mode = vk::PresentModeKHR::eMailbox;
// Prefer Mailbox when vsync is disabled for lowest latency
if (iter != modes.end()) {
present_mode = vk::PresentModeKHR::eMailbox;
}
}
// Query surface extent

View File

@ -19,7 +19,7 @@ public:
~Swapchain();
/// Creates (or recreates) the swapchain with a given size.
void Create(u32 width, u32 height, bool vsync_enabled);
void Create(u32 width, u32 height);
/// Acquires the next image in the swapchain.
void AcquireNextImage(vk::Semaphore signal_acquired);
@ -83,7 +83,6 @@ private:
std::vector<Image> swapchain_images;
u32 current_image = 0;
u32 current_frame = 0;
bool vsync_enabled = false;
bool is_outdated = true;
bool is_suboptimal = true;
};

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include "common/assert.h"
#include "common/logging/log.h"
#include "video_core/renderer_vulkan/renderer_vulkan.h"

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#define VULKAN_HPP_NO_CONSTRUCTORS
#include "video_core/rasterizer_cache/utils.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
@ -10,6 +9,7 @@
#include "video_core/renderer_vulkan/vk_texture_runtime.h"
#include <vulkan/vulkan_format_traits.hpp>
#include <vk_mem_alloc.h>
namespace Vulkan {

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#pragma once
#include <set>
#include <span>
#include <vulkan/vulkan_hash.hpp>
@ -114,7 +115,6 @@ private:
std::array<u32, SCHEDULER_COMMAND_COUNT> staging_offsets{};
std::unordered_multimap<VideoCore::HostTextureTag, ImageAlloc> texture_recycler;
std::unordered_map<vk::ImageView, vk::Framebuffer> clear_framebuffers;
ReinterpreterList list;
};
class Surface : public VideoCore::SurfaceBase<Surface> {