Texture Cache: Redesigning the blitting system (again).
This commit is contained in:
parent
1624f307d0
commit
ecefc932e6
|
@ -472,7 +472,7 @@ template <class P>
|
||||||
void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst,
|
void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst,
|
||||||
const Tegra::Engines::Fermi2D::Surface& src,
|
const Tegra::Engines::Fermi2D::Surface& src,
|
||||||
const Tegra::Engines::Fermi2D::Config& copy) {
|
const Tegra::Engines::Fermi2D::Config& copy) {
|
||||||
const BlitImages images = GetBlitImages(dst, src);
|
const BlitImages images = GetBlitImages(dst, src, copy);
|
||||||
const ImageId dst_id = images.dst_id;
|
const ImageId dst_id = images.dst_id;
|
||||||
const ImageId src_id = images.src_id;
|
const ImageId src_id = images.src_id;
|
||||||
|
|
||||||
|
@ -762,12 +762,15 @@ ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
|
||||||
const bool broken_views =
|
const bool broken_views =
|
||||||
runtime.HasBrokenTextureViewFormats() || True(options & RelaxedOptions::ForceBrokenViews);
|
runtime.HasBrokenTextureViewFormats() || True(options & RelaxedOptions::ForceBrokenViews);
|
||||||
const bool native_bgr = runtime.HasNativeBgr();
|
const bool native_bgr = runtime.HasNativeBgr();
|
||||||
ImageId image_id;
|
const bool flexible_formats = True(options & RelaxedOptions::Format);
|
||||||
|
ImageId image_id{};
|
||||||
|
boost::container::small_vector<ImageId, 1> image_ids;
|
||||||
const auto lambda = [&](ImageId existing_image_id, ImageBase& existing_image) {
|
const auto lambda = [&](ImageId existing_image_id, ImageBase& existing_image) {
|
||||||
if (True(existing_image.flags & ImageFlagBits::Remapped)) {
|
if (True(existing_image.flags & ImageFlagBits::Remapped)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (info.type == ImageType::Linear || existing_image.info.type == ImageType::Linear) {
|
if (info.type == ImageType::Linear || existing_image.info.type == ImageType::Linear)
|
||||||
|
[[unlikely]] {
|
||||||
const bool strict_size = False(options & RelaxedOptions::Size) &&
|
const bool strict_size = False(options & RelaxedOptions::Size) &&
|
||||||
True(existing_image.flags & ImageFlagBits::Strong);
|
True(existing_image.flags & ImageFlagBits::Strong);
|
||||||
const ImageInfo& existing = existing_image.info;
|
const ImageInfo& existing = existing_image.info;
|
||||||
|
@ -776,17 +779,27 @@ ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
|
||||||
IsPitchLinearSameSize(existing, info, strict_size) &&
|
IsPitchLinearSameSize(existing, info, strict_size) &&
|
||||||
IsViewCompatible(existing.format, info.format, broken_views, native_bgr)) {
|
IsViewCompatible(existing.format, info.format, broken_views, native_bgr)) {
|
||||||
image_id = existing_image_id;
|
image_id = existing_image_id;
|
||||||
return true;
|
image_ids.push_back(existing_image_id);
|
||||||
|
return !flexible_formats && existing.format == info.format;
|
||||||
}
|
}
|
||||||
} else if (IsSubresource(info, existing_image, gpu_addr, options, broken_views,
|
} else if (IsSubresource(info, existing_image, gpu_addr, options, broken_views,
|
||||||
native_bgr)) {
|
native_bgr)) {
|
||||||
image_id = existing_image_id;
|
image_id = existing_image_id;
|
||||||
return true;
|
image_ids.push_back(existing_image_id);
|
||||||
|
return !flexible_formats && existing_image.info.format == info.format;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
ForEachImageInRegion(*cpu_addr, CalculateGuestSizeInBytes(info), lambda);
|
ForEachImageInRegion(*cpu_addr, CalculateGuestSizeInBytes(info), lambda);
|
||||||
return image_id;
|
if (image_ids.size() <= 1) [[likely]] {
|
||||||
|
return image_id;
|
||||||
|
}
|
||||||
|
auto image_ids_compare = [this](ImageId a, ImageId b) {
|
||||||
|
auto& image_a = slot_images[a];
|
||||||
|
auto& image_b = slot_images[b];
|
||||||
|
return image_a.modification_tick < image_b.modification_tick;
|
||||||
|
};
|
||||||
|
return *std::ranges::max_element(image_ids, image_ids_compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
|
@ -1078,17 +1091,26 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages(
|
typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages(
|
||||||
const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src) {
|
const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src,
|
||||||
|
const Tegra::Engines::Fermi2D::Config& copy) {
|
||||||
|
|
||||||
static constexpr auto FIND_OPTIONS = RelaxedOptions::Samples;
|
static constexpr auto FIND_OPTIONS = RelaxedOptions::Samples;
|
||||||
const GPUVAddr dst_addr = dst.Address();
|
const GPUVAddr dst_addr = dst.Address();
|
||||||
const GPUVAddr src_addr = src.Address();
|
const GPUVAddr src_addr = src.Address();
|
||||||
ImageInfo dst_info(dst);
|
ImageInfo dst_info(dst);
|
||||||
ImageInfo src_info(src);
|
ImageInfo src_info(src);
|
||||||
|
const bool can_be_depth_blit =
|
||||||
|
dst_info.format == src_info.format && copy.filter == Tegra::Engines::Fermi2D::Filter::Point;
|
||||||
ImageId dst_id;
|
ImageId dst_id;
|
||||||
ImageId src_id;
|
ImageId src_id;
|
||||||
|
RelaxedOptions try_options = FIND_OPTIONS;
|
||||||
|
if (can_be_depth_blit) {
|
||||||
|
try_options |= RelaxedOptions::Format;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
has_deleted_images = false;
|
has_deleted_images = false;
|
||||||
src_id = FindImage(src_info, src_addr, FIND_OPTIONS);
|
src_id = FindImage(src_info, src_addr, try_options);
|
||||||
|
dst_id = FindImage(dst_info, dst_addr, try_options);
|
||||||
const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr;
|
const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr;
|
||||||
if (src_image && src_image->info.num_samples > 1) {
|
if (src_image && src_image->info.num_samples > 1) {
|
||||||
RelaxedOptions find_options{FIND_OPTIONS | RelaxedOptions::ForceBrokenViews};
|
RelaxedOptions find_options{FIND_OPTIONS | RelaxedOptions::ForceBrokenViews};
|
||||||
|
@ -1097,8 +1119,15 @@ typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages(
|
||||||
if (has_deleted_images) {
|
if (has_deleted_images) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (can_be_depth_blit) {
|
||||||
|
const ImageBase* const dst_image = src_id ? &slot_images[src_id] : nullptr;
|
||||||
|
DeduceBlitImages(dst_info, src_info, dst_image, src_image);
|
||||||
|
if (GetFormatType(dst_info.format) != GetFormatType(src_info.format)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dst_id = FindImage(dst_info, dst_addr, FIND_OPTIONS);
|
|
||||||
if (!src_id) {
|
if (!src_id) {
|
||||||
src_id = InsertImage(src_info, src_addr, RelaxedOptions{});
|
src_id = InsertImage(src_info, src_addr, RelaxedOptions{});
|
||||||
}
|
}
|
||||||
|
@ -1106,6 +1135,11 @@ typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages(
|
||||||
dst_id = InsertImage(dst_info, dst_addr, RelaxedOptions{});
|
dst_id = InsertImage(dst_info, dst_addr, RelaxedOptions{});
|
||||||
}
|
}
|
||||||
} while (has_deleted_images);
|
} while (has_deleted_images);
|
||||||
|
if (GetFormatType(dst_info.format) != SurfaceType::ColorTexture) {
|
||||||
|
// Make sure the images are depth and/or stencil textures.
|
||||||
|
src_id = FindOrInsertImage(src_info, src_addr, RelaxedOptions{});
|
||||||
|
dst_id = FindOrInsertImage(dst_info, dst_addr, RelaxedOptions{});
|
||||||
|
}
|
||||||
return BlitImages{
|
return BlitImages{
|
||||||
.dst_id = dst_id,
|
.dst_id = dst_id,
|
||||||
.src_id = src_id,
|
.src_id = src_id,
|
||||||
|
|
|
@ -252,7 +252,8 @@ private:
|
||||||
|
|
||||||
/// Return a blit image pair from the given guest blit parameters
|
/// Return a blit image pair from the given guest blit parameters
|
||||||
[[nodiscard]] BlitImages GetBlitImages(const Tegra::Engines::Fermi2D::Surface& dst,
|
[[nodiscard]] BlitImages GetBlitImages(const Tegra::Engines::Fermi2D::Surface& dst,
|
||||||
const Tegra::Engines::Fermi2D::Surface& src);
|
const Tegra::Engines::Fermi2D::Surface& src,
|
||||||
|
const Tegra::Engines::Fermi2D::Config& copy);
|
||||||
|
|
||||||
/// Find or create a sampler from a guest descriptor sampler
|
/// Find or create a sampler from a guest descriptor sampler
|
||||||
[[nodiscard]] SamplerId FindSampler(const TSCEntry& config);
|
[[nodiscard]] SamplerId FindSampler(const TSCEntry& config);
|
||||||
|
|
|
@ -1151,19 +1151,25 @@ bool IsSubresource(const ImageInfo& candidate, const ImageBase& image, GPUVAddr
|
||||||
|
|
||||||
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
||||||
const ImageBase* src) {
|
const ImageBase* src) {
|
||||||
bool is_resolve = false;
|
const auto original_dst_format = dst_info.format;
|
||||||
if (src) {
|
if (src && GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
|
||||||
is_resolve = src->info.num_samples > 1;
|
src_info.format = src->info.format;
|
||||||
src_info.num_samples = src->info.num_samples;
|
|
||||||
src_info.size.width = src->info.size.width;
|
|
||||||
src_info.size.height = src->info.size.height;
|
|
||||||
}
|
}
|
||||||
if (dst) {
|
if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
|
||||||
dst_info.num_samples = dst->info.num_samples;
|
dst_info.format = dst->info.format;
|
||||||
dst_info.size.width = dst->info.size.width;
|
}
|
||||||
dst_info.size.height = dst->info.size.height;
|
if (src && GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
|
||||||
|
dst_info.format = src->info.format;
|
||||||
|
}
|
||||||
|
if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
|
||||||
|
if (src) {
|
||||||
|
if (GetFormatType(src->info.format) == SurfaceType::ColorTexture) {
|
||||||
|
dst_info.format = original_dst_format;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
src_info.format = dst->info.format;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ASSERT(!is_resolve || dst_info.format == src_info.format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 MapSizeBytes(const ImageBase& image) {
|
u32 MapSizeBytes(const ImageBase& image) {
|
||||||
|
|
Loading…
Reference in New Issue