texture_cache: Improve support for stencil reads (#1758)

* texture_cache: Improve support for stencil reads

* libraries: Supress some spammy logs

* core: Support loading font libraries

* texture_cache: Remove assert
This commit is contained in:
TheTurtle 2024-12-13 18:28:19 +02:00 committed by GitHub
parent 8acefd25e7
commit cfbd869126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 69 additions and 13 deletions

View file

@ -145,8 +145,10 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
const ImageInfo& info_)
: instance{&instance_}, scheduler{&scheduler_}, info{info_},
image{instance->GetDevice(), instance->GetAllocator()} {
if (info.pixel_format == vk::Format::eUndefined) {
return;
}
mip_hashes.resize(info.resources.levels);
ASSERT(info.pixel_format != vk::Format::eUndefined);
// Here we force `eExtendedUsage` as don't know all image usage cases beforehand. In normal case
// the texture cache should re-create the resource with the usage requested
vk::ImageCreateFlags flags{vk::ImageCreateFlagBits::eMutableFormat |

View file

@ -92,6 +92,10 @@ struct Image {
return image_view_ids[std::distance(image_view_infos.begin(), it)];
}
void AssociateDepth(ImageId image_id) {
depth_id = image_id;
}
boost::container::small_vector<vk::ImageMemoryBarrier2, 32> GetBarriers(
vk::ImageLayout dst_layout, vk::Flags<vk::AccessFlagBits2> dst_mask,
vk::PipelineStageFlags2 dst_stage, std::optional<SubresourceRange> subres_range);
@ -116,6 +120,7 @@ struct Image {
VAddr track_addr_end = 0;
std::vector<ImageViewInfo> image_view_infos;
std::vector<ImageViewId> image_view_ids;
ImageId depth_id{};
// Resource state tracking
struct {

View file

@ -298,6 +298,9 @@ ImageInfo::ImageInfo(const AmdGpu::Liverpool::DepthBuffer& buffer, u32 num_slice
resources.layers = num_slices;
meta_info.htile_addr = buffer.z_info.tile_surface_en ? htile_address : 0;
stencil_addr = buffer.StencilAddress();
stencil_size = pitch * size.height * sizeof(u8);
guest_address = buffer.Address();
const auto depth_slice_sz = buffer.GetDepthSliceSize();
guest_size_bytes = depth_slice_sz * num_slices;

View file

@ -69,7 +69,7 @@ struct ImageInfo {
} props{}; // Surface properties with impact on various calculation factors
vk::Format pixel_format = vk::Format::eUndefined;
vk::ImageType type = vk::ImageType::e1D;
vk::ImageType type = vk::ImageType::e2D;
SubresourceExtent resources;
Extent3D size{1, 1, 1};
u32 num_bits{};

View file

@ -170,7 +170,7 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info
format = image.info.pixel_format;
aspect = vk::ImageAspectFlagBits::eDepth;
}
if (image.aspect_mask & vk::ImageAspectFlagBits::eStencil && format == vk::Format::eR8Unorm) {
if (image.aspect_mask & vk::ImageAspectFlagBits::eStencil && format == vk::Format::eR8Uint) {
format = image.info.pixel_format;
aspect = vk::ImageAspectFlagBits::eStencil;
}

View file

@ -443,6 +443,27 @@ ImageView& TextureCache::FindDepthTarget(BaseDesc& desc) {
}
}
// If there is a stencil attachment, link depth and stencil.
if (desc.info.stencil_addr != 0) {
ImageId stencil_id{};
ForEachImageInRegion(desc.info.stencil_addr, desc.info.stencil_size,
[&](ImageId image_id, Image& image) {
if (image.info.guest_address == desc.info.stencil_addr) {
stencil_id = image_id;
}
});
if (!stencil_id) {
ImageInfo info{};
info.guest_address = desc.info.stencil_addr;
info.guest_size_bytes = desc.info.stencil_size;
info.size = desc.info.size;
stencil_id = slot_images.insert(instance, scheduler, info);
RegisterImage(stencil_id);
}
Image& image = slot_images[stencil_id];
image.AssociateDepth(image_id);
}
return RegisterImageView(image_id, desc.view_info);
}