VideoCore: Initial Setup for the Resolution Scaler.

This commit is contained in:
Fernando Sahmkow 2021-07-18 18:40:14 +02:00
parent 720970c4c1
commit 22f4b290b6
11 changed files with 255 additions and 18 deletions

View file

@ -33,6 +33,10 @@ enum class ImageFlagBits : u32 {
///< garbage collection priority
Alias = 1 << 11, ///< This image has aliases and has priority on garbage
///< collection
// Rescaler
Rescaled = 1 << 12,
RescaleChecked = 1 << 13,
};
DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits)

View file

@ -15,7 +15,7 @@ using Tegra::Texture::TICEntry;
using VideoCore::Surface::PixelFormat;
struct ImageInfo {
explicit ImageInfo() = default;
ImageInfo() = default;
explicit ImageInfo(const TICEntry& config) noexcept;
explicit ImageInfo(const Tegra::Engines::Maxwell3D::Regs& regs, size_t index) noexcept;
explicit ImageInfo(const Tegra::Engines::Maxwell3D::Regs& regs) noexcept;

View file

@ -35,6 +35,7 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
Tegra::MemoryManager& gpu_memory_)
: runtime{runtime_}, rasterizer{rasterizer_}, maxwell3d{maxwell3d_},
kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_} {
runtime.Init();
// Configure null sampler
TSCEntry sampler_descriptor{};
sampler_descriptor.min_filter.Assign(Tegra::Texture::TextureFilter::Linear);
@ -103,6 +104,7 @@ void TextureCache<P>::TickFrame() {
sentenced_images.Tick();
sentenced_framebuffers.Tick();
sentenced_image_view.Tick();
runtime.TickFrame();
++frame_tick;
}
@ -208,18 +210,63 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) {
const bool force = flags[Dirty::RenderTargetControl];
flags[Dirty::RenderTargetControl] = false;
bool can_rescale = true;
std::array<ImageId, NUM_RT> tmp_color_images{};
ImageId tmp_depth_image{};
const auto check_rescale = [&](ImageViewId view_id, ImageId& id_save) {
if (view_id) {
const auto& view = slot_image_views[view_id];
const auto image_id = view.image_id;
id_save = image_id;
auto& image = slot_images[image_id];
can_rescale &= ImageCanRescale(image);
} else {
id_save = CORRUPT_ID;
}
};
for (size_t index = 0; index < NUM_RT; ++index) {
ImageViewId& color_buffer_id = render_targets.color_buffer_ids[index];
if (flags[Dirty::ColorBuffer0 + index] || force) {
flags[Dirty::ColorBuffer0 + index] = false;
BindRenderTarget(&color_buffer_id, FindColorBuffer(index, is_clear));
}
PrepareImageView(color_buffer_id, true, is_clear && IsFullClear(color_buffer_id));
check_rescale(color_buffer_id, tmp_color_images[index]);
}
if (flags[Dirty::ZetaBuffer] || force) {
flags[Dirty::ZetaBuffer] = false;
BindRenderTarget(&render_targets.depth_buffer_id, FindDepthBuffer(is_clear));
}
check_rescale(render_targets.depth_buffer_id, tmp_depth_image);
if (can_rescale) {
const auto scale_up = [this](ImageId image_id) {
if (image_id != CORRUPT_ID) {
Image& image = slot_images[image_id];
image.ScaleUp();
}
};
for (size_t index = 0; index < NUM_RT; ++index) {
scale_up(tmp_color_images[index]);
}
scale_up(tmp_depth_image);
} else {
const auto scale_down = [this](ImageId image_id) {
if (image_id != CORRUPT_ID) {
Image& image = slot_images[image_id];
image.ScaleDown();
}
};
for (size_t index = 0; index < NUM_RT; ++index) {
scale_down(tmp_color_images[index]);
}
scale_down(tmp_depth_image);
}
// Rescale End
for (size_t index = 0; index < NUM_RT; ++index) {
ImageViewId& color_buffer_id = render_targets.color_buffer_ids[index];
PrepareImageView(color_buffer_id, true, is_clear && IsFullClear(color_buffer_id));
}
const ImageViewId depth_buffer_id = render_targets.depth_buffer_id;
PrepareImageView(depth_buffer_id, true, is_clear && IsFullClear(depth_buffer_id));
@ -623,6 +670,31 @@ ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
return image_id;
}
template <class P>
bool TextureCache<P>::ImageCanRescale(Image& image) {
if (True(image.flags & ImageFlagBits::Rescaled) ||
True(image.flags & ImageFlagBits::RescaleChecked)) {
return true;
}
const auto& info = image.info;
const bool can_this_rescale =
(info.type == ImageType::e1D || info.type == ImageType::e2D) && info.block.depth == 0;
if (!can_this_rescale) {
image.flags &= ~ImageFlagBits::RescaleChecked;
return false;
}
image.flags |= ImageFlagBits::RescaleChecked;
for (const auto& alias : image.aliased_images) {
Image& other_image = slot_images[alias.id];
if (!ImageCanRescale(other_image)) {
image.flags &= ~ImageFlagBits::RescaleChecked;
return false;
}
}
image.flags &= ~ImageFlagBits::RescaleChecked;
return true;
}
template <class P>
ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr,
RelaxedOptions options) {
@ -660,12 +732,18 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
std::vector<ImageId> right_aliased_ids;
std::unordered_set<ImageId> ignore_textures;
std::vector<ImageId> bad_overlap_ids;
std::vector<ImageId> all_siblings;
const bool this_is_linear = info.type == ImageType::Linear;
const auto region_check = [&](ImageId overlap_id, ImageBase& overlap) {
if (True(overlap.flags & ImageFlagBits::Remapped)) {
ignore_textures.insert(overlap_id);
return;
}
if (info.type == ImageType::Linear) {
const bool overlap_is_linear = overlap.info.type == ImageType::Linear;
if (this_is_linear != overlap_is_linear) {
return;
}
if (this_is_linear && overlap_is_linear) {
if (info.pitch == overlap.info.pitch && gpu_addr == overlap.gpu_addr) {
// Alias linear images with the same pitch
left_aliased_ids.push_back(overlap_id);
@ -681,6 +759,7 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
cpu_addr = solution->cpu_addr;
new_info.resources = solution->resources;
overlap_ids.push_back(overlap_id);
all_siblings.push_back(overlap_id);
return;
}
static constexpr auto options = RelaxedOptions::Size | RelaxedOptions::Format;
@ -688,10 +767,12 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
if (IsSubresource(new_info, overlap, gpu_addr, options, broken_views, native_bgr)) {
left_aliased_ids.push_back(overlap_id);
overlap.flags |= ImageFlagBits::Alias;
all_siblings.push_back(overlap_id);
} else if (IsSubresource(overlap.info, new_image_base, overlap.gpu_addr, options,
broken_views, native_bgr)) {
right_aliased_ids.push_back(overlap_id);
overlap.flags |= ImageFlagBits::Alias;
all_siblings.push_back(overlap_id);
} else {
bad_overlap_ids.push_back(overlap_id);
overlap.flags |= ImageFlagBits::BadOverlap;
@ -709,8 +790,36 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
}
};
ForEachSparseImageInRegion(gpu_addr, size_bytes, region_check_gpu);
bool can_rescale =
(info.type == ImageType::e1D || info.type == ImageType::e2D) && info.block.depth == 0;
for (const ImageId sibling_id : all_siblings) {
if (!can_rescale) {
break;
}
Image& sibling = slot_images[sibling_id];
can_rescale &= ImageCanRescale(sibling);
}
if (can_rescale) {
for (const ImageId sibling_id : all_siblings) {
Image& sibling = slot_images[sibling_id];
sibling.ScaleUp();
}
} else {
for (const ImageId sibling_id : all_siblings) {
Image& sibling = slot_images[sibling_id];
sibling.ScaleDown();
}
}
const ImageId new_image_id = slot_images.insert(runtime, new_info, gpu_addr, cpu_addr);
Image& new_image = slot_images[new_image_id];
if (can_rescale) {
new_image.ScaleUp();
} else {
new_image.ScaleDown();
}
if (!gpu_memory.IsContinousRange(new_image.gpu_addr, new_image.guest_size_bytes)) {
new_image.flags |= ImageFlagBits::Sparse;

View file

@ -142,6 +142,14 @@ public:
const Tegra::Engines::Fermi2D::Surface& src,
const Tegra::Engines::Fermi2D::Config& copy);
/// Invalidate the contents of the color buffer index
/// These contents become unspecified, the cache can assume aggressive optimizations.
void InvalidateColorBuffer(size_t index);
/// Invalidate the contents of the depth buffer
/// These contents become unspecified, the cache can assume aggressive optimizations.
void InvalidateDepthBuffer();
/// Try to find a cached image view in the given CPU address
[[nodiscard]] ImageView* TryFindFramebufferImageView(VAddr cpu_addr);
@ -318,6 +326,8 @@ private:
/// Returns true if the current clear parameters clear the whole image of a given image view
[[nodiscard]] bool IsFullClear(ImageViewId id);
bool ImageCanRescale(Image& image);
Runtime& runtime;
VideoCore::RasterizerInterface& rasterizer;
Tegra::Engines::Maxwell3D& maxwell3d;