vk_common: Enable beta extensions

* Required to access the portability subset'
This commit is contained in:
GPUCode
2022-12-30 16:22:53 +02:00
parent 3da6c25fd8
commit 850ec1f8b8
5 changed files with 34 additions and 122 deletions

View File

@ -95,7 +95,6 @@ add_library(video_core STATIC
renderer_vulkan/vk_descriptor_manager.h
renderer_vulkan/vk_format_reinterpreter.cpp
renderer_vulkan/vk_format_reinterpreter.h
renderer_vulkan/vk_layout_tracker.h
renderer_vulkan/vk_master_semaphore.cpp
renderer_vulkan/vk_master_semaphore.h
renderer_vulkan/vk_rasterizer.cpp

View File

@ -8,6 +8,7 @@
#include "common/common_types.h"
// Include vulkan-hpp header
#define VK_ENABLE_BETA_EXTENSIONS
#define VK_NO_PROTOTYPES 1
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#define VULKAN_HPP_NO_CONSTRUCTORS

View File

@ -1,80 +0,0 @@
// Copyright 2022 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "video_core/renderer_vulkan/vk_common.h"
namespace Vulkan {
class LayoutTracker {
static constexpr u32 LAYOUT_BITS = 3;
static constexpr u32 MAX_LAYOUTS = (1 << LAYOUT_BITS);
static constexpr u32 LAYOUT_MASK = MAX_LAYOUTS - 1;
// Build layout pattern masks at compile time for fast range equality checks
static constexpr auto LAYOUT_PATTERNS = []() {
std::array<u64, MAX_LAYOUTS> patterns{};
for (u32 layout = 0; layout < MAX_LAYOUTS; layout++) {
for (u32 i = 0; i < 16; i++) {
patterns[layout] <<= LAYOUT_BITS;
patterns[layout] |= layout;
}
}
return patterns;
}();
public:
LayoutTracker() = default;
/// Returns the image layout of the provided level
[[nodiscard]] constexpr vk::ImageLayout GetLayout(u32 level) const {
const u32 shift = level * LAYOUT_BITS;
return static_cast<vk::ImageLayout>((layouts >> shift) & LAYOUT_MASK);
}
/// Returns true if the level and layer range provided has the same layout
[[nodiscard]] constexpr bool IsRangeEqual(vk::ImageLayout layout, u32 level,
u32 level_count) const {
const u32 shift = level * LAYOUT_BITS;
const u64 range_mask = (1ull << level_count * LAYOUT_BITS) - 1;
const u64 pattern = LAYOUT_PATTERNS[static_cast<u64>(layout)];
return ((layouts >> shift) & range_mask) == (pattern & range_mask);
}
/// Sets the image layout of the provided level
constexpr void SetLayout(vk::ImageLayout layout, u32 level, u32 level_count = 1) {
const u32 shift = level * LAYOUT_BITS;
const u64 range_mask = (1ull << level_count * LAYOUT_BITS) - 1;
const u64 pattern = LAYOUT_PATTERNS[static_cast<u64>(layout)];
layouts &= ~(range_mask << shift);
layouts |= (pattern & range_mask) << shift;
}
/// Calls func for each continuous layout range
template <typename T>
void ForEachLayoutRange(u32 level, u32 level_count, vk::ImageLayout new_layout, T&& func) {
u32 start_level = level;
u32 end_level = level + level_count;
auto current_layout = GetLayout(level);
while (level < end_level) {
level++;
const auto layout = GetLayout(level);
if (layout != current_layout || level == end_level) {
if (current_layout != new_layout) {
func(start_level, level - start_level, current_layout);
}
current_layout = layout;
start_level = level;
}
}
}
public:
u64 layouts{};
};
} // namespace Vulkan

View File

@ -191,8 +191,6 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
ImageAlloc alloc{};
alloc.format = format;
alloc.levels = std::log2(std::max(width, height)) + 1;
alloc.layers = type == VideoCore::TextureType::CubeMap ? 6 : 1;
alloc.aspect = GetImageAspect(format);
// The internal format does not provide enough guarantee of texture uniqueness
@ -214,6 +212,8 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
}
const bool create_storage_view = pixel_format == VideoCore::PixelFormat::RGBA8;
const u32 levels = std::log2(std::max(width, height)) + 1;
const u32 layers = type == VideoCore::TextureType::CubeMap ? 6 : 1;
vk::ImageCreateFlags flags;
if (type == VideoCore::TextureType::CubeMap) {
@ -228,8 +228,8 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {width, height, 1},
.mipLevels = alloc.levels,
.arrayLayers = alloc.layers,
.mipLevels = levels,
.arrayLayers = layers,
.samples = vk::SampleCountFlagBits::e1,
.usage = usage,
};
@ -261,33 +261,31 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
.image = alloc.image,
.viewType = view_type,
.format = format,
.subresourceRange =
{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = alloc.levels,
.baseArrayLayer = 0,
.layerCount = alloc.layers,
},
.subresourceRange{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = levels,
.baseArrayLayer = 0,
.layerCount = layers,
},
};
vk::Device device = instance.GetDevice();
alloc.image_view = device.createImageView(view_info);
// Also create a base mip view in case this is used as an attachment
if (alloc.levels > 1) [[likely]] {
if (levels > 1) [[likely]] {
const vk::ImageViewCreateInfo base_view_info = {
.image = alloc.image,
.viewType = view_type,
.format = format,
.subresourceRange =
{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = alloc.layers,
},
.subresourceRange{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = layers,
},
};
alloc.base_view = device.createImageView(base_view_info);
@ -299,14 +297,13 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
.image = alloc.image,
.viewType = view_type,
.format = format,
.subresourceRange =
{
.aspectMask = vk::ImageAspectFlagBits::eDepth,
.baseMipLevel = 0,
.levelCount = alloc.levels,
.baseArrayLayer = 0,
.layerCount = alloc.layers,
},
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eDepth,
.baseMipLevel = 0,
.levelCount = levels,
.baseArrayLayer = 0,
.layerCount = layers,
},
};
alloc.depth_view = device.createImageView(view_info);
@ -319,14 +316,13 @@ ImageAlloc TextureRuntime::Allocate(u32 width, u32 height, VideoCore::PixelForma
.image = alloc.image,
.viewType = view_type,
.format = vk::Format::eR32Uint,
.subresourceRange =
{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = alloc.levels,
.baseArrayLayer = 0,
.layerCount = alloc.layers,
},
.subresourceRange{
.aspectMask = alloc.aspect,
.baseMipLevel = 0,
.levelCount = levels,
.baseArrayLayer = 0,
.layerCount = layers,
},
};
alloc.storage_view = device.createImageView(storage_view_info);
}

View File

@ -12,7 +12,6 @@
#include "video_core/renderer_vulkan/vk_blit_helper.h"
#include "video_core/renderer_vulkan/vk_format_reinterpreter.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_layout_tracker.h"
#include "video_core/renderer_vulkan/vk_stream_buffer.h"
VK_DEFINE_HANDLE(VmaAllocation)
@ -45,9 +44,6 @@ struct ImageAlloc {
vk::ImageUsageFlags usage;
vk::Format format;
vk::ImageAspectFlags aspect = vk::ImageAspectFlagBits::eColor;
u32 levels = 1;
u32 layers = 1;
LayoutTracker tracker;
};
struct HostTextureTag {