mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-21 00:27:53 -05:00
texture_cache: Fermi2D reform and implement View Mirage
This also does some fixes on compressed textures reinterpret and on the Fermi2D engine in general.
This commit is contained in:
committed by
ReinUsesLisp
parent
1bf4154e7d
commit
175aa343ff
@ -126,14 +126,19 @@ public:
|
||||
return MatchStructureResult::None;
|
||||
}
|
||||
// Tiled surface
|
||||
if (std::tie(params.height, params.depth, params.block_width, params.block_height,
|
||||
params.block_depth, params.tile_width_spacing, params.num_levels) ==
|
||||
std::tie(rhs.height, rhs.depth, rhs.block_width, rhs.block_height, rhs.block_depth,
|
||||
if (std::tie(params.depth, params.block_width, params.block_height, params.block_depth,
|
||||
params.tile_width_spacing, params.num_levels) ==
|
||||
std::tie(rhs.depth, rhs.block_width, rhs.block_height, rhs.block_depth,
|
||||
rhs.tile_width_spacing, rhs.num_levels)) {
|
||||
if (params.width == rhs.width) {
|
||||
if (std::tie(params.width, params.height) == std::tie(rhs.width, rhs.height)) {
|
||||
return MatchStructureResult::FullMatch;
|
||||
}
|
||||
if (params.GetBlockAlignedWidth() == rhs.GetBlockAlignedWidth()) {
|
||||
const u32 ws = SurfaceParams::ConvertWidth(rhs.GetBlockAlignedWidth(),
|
||||
params.pixel_format, rhs.pixel_format);
|
||||
const u32 hs =
|
||||
SurfaceParams::ConvertHeight(rhs.height, params.pixel_format, rhs.pixel_format);
|
||||
const u32 w1 = params.GetBlockAlignedWidth();
|
||||
if (std::tie(w1, params.height) == std::tie(ws, hs)) {
|
||||
return MatchStructureResult::SemiMatch;
|
||||
}
|
||||
}
|
||||
|
@ -126,6 +126,20 @@ public:
|
||||
/// Returns the size of a layer in bytes in host memory for a given mipmap level.
|
||||
std::size_t GetHostLayerSize(u32 level) const;
|
||||
|
||||
static u32 ConvertWidth(u32 width, VideoCore::Surface::PixelFormat pixel_format_from,
|
||||
VideoCore::Surface::PixelFormat pixel_format_to) {
|
||||
const u32 bw1 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_from);
|
||||
const u32 bw2 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_to);
|
||||
return (width * bw2 + bw1 - 1) / bw1;
|
||||
}
|
||||
|
||||
static u32 ConvertHeight(u32 height, VideoCore::Surface::PixelFormat pixel_format_from,
|
||||
VideoCore::Surface::PixelFormat pixel_format_to) {
|
||||
const u32 bh1 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_from);
|
||||
const u32 bh2 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_to);
|
||||
return (height * bh2 + bh1 - 1) / bh1;
|
||||
}
|
||||
|
||||
/// Returns the default block width.
|
||||
u32 GetDefaultBlockWidth() const {
|
||||
return VideoCore::Surface::GetDefaultBlockWidth(pixel_format);
|
||||
|
@ -141,11 +141,6 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
if (regs.color_mask[index].raw == 0) {
|
||||
SetEmptyColorBuffer(index);
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto& config{regs.rt[index]};
|
||||
const auto gpu_addr{config.Address()};
|
||||
if (!gpu_addr) {
|
||||
@ -192,11 +187,11 @@ public:
|
||||
|
||||
void DoFermiCopy(const Tegra::Engines::Fermi2D::Regs::Surface& src_config,
|
||||
const Tegra::Engines::Fermi2D::Regs::Surface& dst_config,
|
||||
const Common::Rectangle<u32>& src_rect,
|
||||
const Common::Rectangle<u32>& dst_rect) {
|
||||
TSurface dst_surface = GetFermiSurface(dst_config);
|
||||
ImageBlit(GetFermiSurface(src_config), dst_surface, src_rect, dst_rect);
|
||||
dst_surface->MarkAsModified(true, Tick());
|
||||
const Tegra::Engines::Fermi2D::Config& copy_config) {
|
||||
std::pair<TSurface, TView> dst_surface = GetFermiSurface(dst_config);
|
||||
std::pair<TSurface, TView> src_surface = GetFermiSurface(src_config);
|
||||
ImageBlit(src_surface.second, dst_surface.second, copy_config);
|
||||
dst_surface.first->MarkAsModified(true, Tick());
|
||||
}
|
||||
|
||||
TSurface TryFindFramebufferSurface(const u8* host_ptr) {
|
||||
@ -234,8 +229,8 @@ protected:
|
||||
virtual void ImageCopy(TSurface src_surface, TSurface dst_surface,
|
||||
const CopyParams& copy_params) = 0;
|
||||
|
||||
virtual void ImageBlit(TSurface src, TSurface dst, const Common::Rectangle<u32>& src_rect,
|
||||
const Common::Rectangle<u32>& dst_rect) = 0;
|
||||
virtual void ImageBlit(TView src_view, TView dst_view,
|
||||
const Tegra::Engines::Fermi2D::Config& copy_config) = 0;
|
||||
|
||||
void Register(TSurface surface) {
|
||||
std::lock_guard lock{mutex};
|
||||
@ -282,10 +277,11 @@ protected:
|
||||
return new_surface;
|
||||
}
|
||||
|
||||
TSurface GetFermiSurface(const Tegra::Engines::Fermi2D::Regs::Surface& config) {
|
||||
std::pair<TSurface, TView> GetFermiSurface(
|
||||
const Tegra::Engines::Fermi2D::Regs::Surface& config) {
|
||||
SurfaceParams params = SurfaceParams::CreateForFermiCopySurface(config);
|
||||
const GPUVAddr gpu_addr = config.Address();
|
||||
return GetSurface(gpu_addr, params, true).first;
|
||||
return GetSurface(gpu_addr, params, true);
|
||||
}
|
||||
|
||||
Core::System& system;
|
||||
@ -551,7 +547,21 @@ private:
|
||||
if (view.has_value()) {
|
||||
const bool is_mirage = !current_surface->MatchFormat(params.pixel_format);
|
||||
if (is_mirage) {
|
||||
LOG_CRITICAL(HW_GPU, "Mirage View Unsupported");
|
||||
// On a mirage view, we need to recreate the surface under this new view
|
||||
// and then obtain a view again.
|
||||
SurfaceParams new_params = current_surface->GetSurfaceParams();
|
||||
const u32 wh = SurfaceParams::ConvertWidth(
|
||||
new_params.width, new_params.pixel_format, params.pixel_format);
|
||||
const u32 hh = SurfaceParams::ConvertHeight(
|
||||
new_params.height, new_params.pixel_format, params.pixel_format);
|
||||
new_params.width = wh;
|
||||
new_params.height = hh;
|
||||
new_params.pixel_format = params.pixel_format;
|
||||
std::pair<TSurface, TView> pair = RebuildSurface(current_surface, new_params);
|
||||
std::optional<TView> mirage_view =
|
||||
pair.first->EmplaceView(params, gpu_addr, candidate_size);
|
||||
if (mirage_view)
|
||||
return {pair.first, *mirage_view};
|
||||
return RecycleSurface(overlaps, params, gpu_addr, preserve_contents, false);
|
||||
}
|
||||
return {current_surface, *view};
|
||||
|
Reference in New Issue
Block a user