2020-01-14 00:36:03 +01:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
#include <compare>
|
|
|
|
#include <span>
|
2020-01-14 00:36:03 +01:00
|
|
|
|
|
|
|
#include "video_core/texture_cache/texture_cache.h"
|
2021-01-03 22:17:57 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2020-01-14 00:36:03 +01:00
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
using VideoCommon::ImageId;
|
|
|
|
using VideoCommon::NUM_RT;
|
|
|
|
using VideoCommon::Offset2D;
|
|
|
|
using VideoCommon::RenderTargets;
|
|
|
|
using VideoCore::Surface::PixelFormat;
|
|
|
|
|
|
|
|
class BlitImageHelper;
|
2020-12-26 05:10:53 +01:00
|
|
|
class Device;
|
2020-12-30 06:25:23 +01:00
|
|
|
class Image;
|
|
|
|
class ImageView;
|
|
|
|
class Framebuffer;
|
2020-12-31 02:58:05 +01:00
|
|
|
class StagingBufferPool;
|
|
|
|
class VKScheduler;
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
struct RenderPassKey {
|
|
|
|
constexpr auto operator<=>(const RenderPassKey&) const noexcept = default;
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
std::array<PixelFormat, NUM_RT> color_formats;
|
|
|
|
PixelFormat depth_format;
|
|
|
|
VkSampleCountFlagBits samples;
|
|
|
|
};
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
} // namespace Vulkan
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::RenderPassKey> {
|
|
|
|
[[nodiscard]] constexpr size_t operator()(const Vulkan::RenderPassKey& key) const noexcept {
|
|
|
|
size_t value = static_cast<size_t>(key.depth_format) << 48;
|
|
|
|
value ^= static_cast<size_t>(key.samples) << 52;
|
|
|
|
for (size_t i = 0; i < key.color_formats.size(); ++i) {
|
|
|
|
value ^= static_cast<size_t>(key.color_formats[i]) << (i * 6);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
namespace Vulkan {
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
struct ImageBufferMap {
|
|
|
|
[[nodiscard]] VkBuffer Handle() const noexcept {
|
|
|
|
return handle;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] std::span<u8> Span() const noexcept {
|
2020-12-31 02:58:05 +01:00
|
|
|
return span;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
VkBuffer handle;
|
2020-12-31 02:58:05 +01:00
|
|
|
std::span<u8> span;
|
2020-12-30 06:25:23 +01:00
|
|
|
};
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
struct TextureCacheRuntime {
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device& device;
|
2020-12-30 06:25:23 +01:00
|
|
|
VKScheduler& scheduler;
|
2021-01-03 22:11:01 +01:00
|
|
|
MemoryAllocator& memory_allocator;
|
2020-12-31 02:58:05 +01:00
|
|
|
StagingBufferPool& staging_buffer_pool;
|
2020-12-30 06:25:23 +01:00
|
|
|
BlitImageHelper& blit_image_helper;
|
|
|
|
std::unordered_map<RenderPassKey, vk::RenderPass> renderpass_cache;
|
|
|
|
|
|
|
|
void Finish();
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] ImageBufferMap MapUploadBuffer(size_t size);
|
|
|
|
|
2021-01-04 01:05:59 +01:00
|
|
|
[[nodiscard]] ImageBufferMap MapDownloadBuffer(size_t size);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void BlitImage(Framebuffer* dst_framebuffer, ImageView& dst, ImageView& src,
|
|
|
|
const std::array<Offset2D, 2>& dst_region,
|
|
|
|
const std::array<Offset2D, 2>& src_region,
|
|
|
|
Tegra::Engines::Fermi2D::Filter filter,
|
|
|
|
Tegra::Engines::Fermi2D::Operation operation);
|
|
|
|
|
|
|
|
void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
|
|
|
|
|
|
|
|
void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view);
|
|
|
|
|
|
|
|
[[nodiscard]] bool CanAccelerateImageUpload(Image&) const noexcept {
|
|
|
|
return false;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void AccelerateImageUpload(Image&, const ImageBufferMap&, size_t,
|
|
|
|
std::span<const VideoCommon::SwizzleParameters>) {
|
|
|
|
UNREACHABLE();
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void InsertUploadMemoryBarrier() {}
|
2021-01-04 05:56:44 +01:00
|
|
|
|
|
|
|
bool HasBrokenTextureViewFormats() const noexcept {
|
|
|
|
// No known Vulkan driver has broken image views
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-30 06:25:23 +01:00
|
|
|
};
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
class Image : public VideoCommon::ImageBase {
|
|
|
|
public:
|
|
|
|
explicit Image(TextureCacheRuntime&, const VideoCommon::ImageInfo& info, GPUVAddr gpu_addr,
|
|
|
|
VAddr cpu_addr);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void UploadMemory(const ImageBufferMap& map, size_t buffer_offset,
|
|
|
|
std::span<const VideoCommon::BufferImageCopy> copies);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void UploadMemory(const ImageBufferMap& map, size_t buffer_offset,
|
|
|
|
std::span<const VideoCommon::BufferCopy> copies);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void DownloadMemory(const ImageBufferMap& map, size_t buffer_offset,
|
|
|
|
std::span<const VideoCommon::BufferImageCopy> copies);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImage Handle() const noexcept {
|
|
|
|
return *image;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkBuffer Buffer() const noexcept {
|
|
|
|
return *buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] VkImageCreateFlags AspectMask() const noexcept {
|
|
|
|
return aspect_mask;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
private:
|
|
|
|
VKScheduler* scheduler;
|
|
|
|
vk::Image image;
|
2020-03-27 05:33:21 +01:00
|
|
|
vk::Buffer buffer;
|
2020-12-31 02:58:05 +01:00
|
|
|
MemoryCommit commit;
|
2020-12-30 06:25:23 +01:00
|
|
|
VkImageAspectFlags aspect_mask = 0;
|
|
|
|
bool initialized = false;
|
2020-01-14 00:36:03 +01:00
|
|
|
};
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
class ImageView : public VideoCommon::ImageViewBase {
|
2020-01-14 00:36:03 +01:00
|
|
|
public:
|
2020-12-30 06:25:23 +01:00
|
|
|
explicit ImageView(TextureCacheRuntime&, const VideoCommon::ImageViewInfo&, ImageId, Image&);
|
|
|
|
explicit ImageView(TextureCacheRuntime&, const VideoCommon::NullImageParams&);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImageView DepthView();
|
2020-05-30 04:32:41 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImageView StencilView();
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImageView Handle(VideoCommon::ImageViewType query_type) const noexcept {
|
|
|
|
return *image_views[static_cast<size_t>(query_type)];
|
2020-01-16 22:23:10 +01:00
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkBufferView BufferView() const noexcept {
|
|
|
|
return *buffer_view;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImage ImageHandle() const noexcept {
|
|
|
|
return image_handle;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkImageView RenderTarget() const noexcept {
|
|
|
|
return render_target;
|
2020-02-16 08:12:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] PixelFormat ImageFormat() const noexcept {
|
|
|
|
return image_format;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkSampleCountFlagBits Samples() const noexcept {
|
|
|
|
return samples;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
private:
|
|
|
|
[[nodiscard]] vk::ImageView MakeDepthStencilView(VkImageAspectFlags aspect_mask);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device* device = nullptr;
|
2020-12-30 06:25:23 +01:00
|
|
|
std::array<vk::ImageView, VideoCommon::NUM_IMAGE_VIEW_TYPES> image_views;
|
|
|
|
vk::ImageView depth_view;
|
|
|
|
vk::ImageView stencil_view;
|
|
|
|
vk::BufferView buffer_view;
|
|
|
|
VkImage image_handle = VK_NULL_HANDLE;
|
|
|
|
VkImageView render_target = VK_NULL_HANDLE;
|
|
|
|
PixelFormat image_format = PixelFormat::Invalid;
|
|
|
|
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
};
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
class ImageAlloc : public VideoCommon::ImageAllocBase {};
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
class Sampler {
|
|
|
|
public:
|
|
|
|
explicit Sampler(TextureCacheRuntime&, const Tegra::Texture::TSCEntry&);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkSampler Handle() const noexcept {
|
|
|
|
return *sampler;
|
2020-01-14 00:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-12-30 06:25:23 +01:00
|
|
|
vk::Sampler sampler;
|
2020-01-14 00:36:03 +01:00
|
|
|
};
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
class Framebuffer {
|
2020-01-14 00:36:03 +01:00
|
|
|
public:
|
2020-12-30 06:25:23 +01:00
|
|
|
explicit Framebuffer(TextureCacheRuntime&, std::span<ImageView*, NUM_RT> color_buffers,
|
|
|
|
ImageView* depth_buffer, const VideoCommon::RenderTargets& key);
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkFramebuffer Handle() const noexcept {
|
|
|
|
return *framebuffer;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkRenderPass RenderPass() const noexcept {
|
|
|
|
return renderpass;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkExtent2D RenderArea() const noexcept {
|
|
|
|
return render_area;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] VkSampleCountFlagBits Samples() const noexcept {
|
|
|
|
return samples;
|
|
|
|
}
|
2020-01-14 00:36:03 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
[[nodiscard]] u32 NumColorBuffers() const noexcept {
|
|
|
|
return num_color_buffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] u32 NumImages() const noexcept {
|
|
|
|
return num_images;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const std::array<VkImage, 9>& Images() const noexcept {
|
|
|
|
return images;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const std::array<VkImageSubresourceRange, 9>& ImageRanges() const noexcept {
|
|
|
|
return image_ranges;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vk::Framebuffer framebuffer;
|
|
|
|
VkRenderPass renderpass{};
|
|
|
|
VkExtent2D render_area{};
|
|
|
|
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
u32 num_color_buffers = 0;
|
|
|
|
u32 num_images = 0;
|
|
|
|
std::array<VkImage, 9> images{};
|
|
|
|
std::array<VkImageSubresourceRange, 9> image_ranges{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureCacheParams {
|
|
|
|
static constexpr bool ENABLE_VALIDATION = true;
|
|
|
|
static constexpr bool FRAMEBUFFER_BLITS = false;
|
|
|
|
static constexpr bool HAS_EMULATED_COPIES = false;
|
|
|
|
|
|
|
|
using Runtime = Vulkan::TextureCacheRuntime;
|
|
|
|
using Image = Vulkan::Image;
|
|
|
|
using ImageAlloc = Vulkan::ImageAlloc;
|
|
|
|
using ImageView = Vulkan::ImageView;
|
|
|
|
using Sampler = Vulkan::Sampler;
|
|
|
|
using Framebuffer = Vulkan::Framebuffer;
|
2020-01-14 00:36:03 +01:00
|
|
|
};
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
using TextureCache = VideoCommon::TextureCache<TextureCacheParams>;
|
|
|
|
|
2020-01-14 00:36:03 +01:00
|
|
|
} // namespace Vulkan
|