texture_cache: detiler: added support for block coded 128bit images

This commit is contained in:
psucien 2024-06-09 12:54:19 +02:00
parent 1a66fa098f
commit fa73812f32
8 changed files with 115 additions and 35 deletions

View file

@ -33,8 +33,32 @@ static vk::Format ConvertPixelFormat(const VideoOutFormat format) {
return {};
}
static bool IsDepthStencilFormat(vk::Format format) {
switch (format) {
bool ImageInfo::IsBlockCoded() const {
switch (pixel_format) {
case vk::Format::eBc1RgbaSrgbBlock:
case vk::Format::eBc1RgbaUnormBlock:
case vk::Format::eBc1RgbSrgbBlock:
case vk::Format::eBc1RgbUnormBlock:
case vk::Format::eBc2SrgbBlock:
case vk::Format::eBc2UnormBlock:
case vk::Format::eBc3SrgbBlock:
case vk::Format::eBc3UnormBlock:
case vk::Format::eBc4SnormBlock:
case vk::Format::eBc4UnormBlock:
case vk::Format::eBc5SnormBlock:
case vk::Format::eBc5UnormBlock:
case vk::Format::eBc6HSfloatBlock:
case vk::Format::eBc6HUfloatBlock:
case vk::Format::eBc7SrgbBlock:
case vk::Format::eBc7UnormBlock:
return true;
default:
return false;
}
}
bool ImageInfo::IsDepthStencil() const {
switch (pixel_format) {
case vk::Format::eD16Unorm:
case vk::Format::eD16UnormS8Uint:
case vk::Format::eD32Sfloat:
@ -45,17 +69,20 @@ static bool IsDepthStencilFormat(vk::Format format) {
}
}
static vk::ImageUsageFlags ImageUsageFlags(const vk::Format format) {
static vk::ImageUsageFlags ImageUsageFlags(const ImageInfo& info) {
vk::ImageUsageFlags usage = vk::ImageUsageFlagBits::eTransferSrc |
vk::ImageUsageFlagBits::eTransferDst |
vk::ImageUsageFlagBits::eSampled;
if (IsDepthStencilFormat(format)) {
if (info.IsDepthStencil()) {
usage |= vk::ImageUsageFlagBits::eDepthStencilAttachment;
} else {
if (format != vk::Format::eBc3SrgbBlock) {
if (!info.IsBlockCoded()) {
usage |= vk::ImageUsageFlagBits::eColorAttachment;
}
}
if (info.is_tiled || info.is_storage) {
usage |= vk::ImageUsageFlagBits::eStorage;
}
return usage;
}
@ -179,15 +206,12 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
}
if (info.is_tiled) {
flags |= vk::ImageCreateFlagBits::eExtendedUsage;
if (false) { // IsBlockCodedFormat()
if (info.IsBlockCoded()) {
flags |= vk::ImageCreateFlagBits::eBlockTexelViewCompatible;
}
}
info.usage = ImageUsageFlags(info.pixel_format);
if (info.is_tiled || info.is_storage) {
info.usage |= vk::ImageUsageFlagBits::eStorage;
}
info.usage = ImageUsageFlags(info);
if (info.pixel_format == vk::Format::eD32Sfloat) {
aspect_mask = vk::ImageAspectFlagBits::eDepth;

View file

@ -42,6 +42,9 @@ struct ImageInfo {
const AmdGpu::Liverpool::CbDbExtent& hint = {}) noexcept;
explicit ImageInfo(const AmdGpu::Image& image) noexcept;
bool IsBlockCoded() const;
bool IsDepthStencil() const;
bool is_tiled = false;
bool is_storage = false;
vk::Format pixel_format = vk::Format::eUndefined;

View file

@ -84,7 +84,7 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info
.baseMipLevel = 0U,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
.layerCount = image.info.IsBlockCoded() ? 1 : VK_REMAINING_ARRAY_LAYERS,
},
};
image_view = instance.GetDevice().createImageViewUnique(image_view_ci);

View file

@ -8,8 +8,9 @@
#include "video_core/texture_cache/texture_cache.h"
#include "video_core/texture_cache/tile_manager.h"
#include "video_core/host_shaders/detile_m32x1_comp.h"
#include "video_core/host_shaders/detile_m32x4_comp.h"
#include "video_core/host_shaders/detile_m8x1_comp.h"
#include "video_core/host_shaders/detile_m8x4_comp.h"
#include <boost/container/static_vector.hpp>
#include <magic_enum.hpp>
@ -176,25 +177,31 @@ vk::Format DemoteImageFormatForDetiling(vk::Format format) {
switch (format) {
case vk::Format::eB8G8R8A8Srgb:
case vk::Format::eR8G8B8A8Unorm:
return vk::Format::eR8G8B8A8Uint;
return vk::Format::eR32Uint;
case vk::Format::eR8Unorm:
return vk::Format::eR8Uint;
case vk::Format::eBc3SrgbBlock:
case vk::Format::eBc3UnormBlock:
return vk::Format::eR32G32B32A32Uint;
default:
LOG_ERROR(Render_Vulkan, "Unexpected format for demotion {}", vk::to_string(format));
break;
}
LOG_ERROR(Render_Vulkan, "Unexpected format for demotion {}", vk::to_string(format));
return format;
}
const DetilerContext* TileManager::GetDetiler(const Image& image) const {
const auto format = DemoteImageFormatForDetiling(image.info.pixel_format);
if (image.info.tiling_mode == AmdGpu::TilingMode::Texture_MicroTiled) {
if (image.info.tiling_mode == AmdGpu::TilingMode::Texture_MicroTiled ||
image.info.tiling_mode == AmdGpu::TilingMode::Depth_MicroTiled) {
switch (format) {
case vk::Format::eR8Uint:
return &detilers[DetilerType::Micro8x1];
case vk::Format::eR8G8B8A8Uint:
return &detilers[DetilerType::Micro8x4];
case vk::Format::eR32Uint:
return &detilers[DetilerType::Micro32x1];
case vk::Format::eR32G32B32A32Uint:
return &detilers[DetilerType::Micro32x4];
default:
return nullptr;
}
@ -211,7 +218,8 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc
static const std::array detiler_shaders{
HostShaders::DETILE_M8X1_COMP,
HostShaders::DETILE_M8X4_COMP,
HostShaders::DETILE_M32X1_COMP,
HostShaders::DETILE_M32X4_COMP,
};
for (int pl_id = 0; pl_id < DetilerType::Max; ++pl_id) {

View file

@ -19,7 +19,8 @@ vk::Format DemoteImageFormatForDetiling(vk::Format format);
enum DetilerType : u32 {
Micro8x1,
Micro8x4,
Micro32x1,
Micro32x4,
Max
};