texture_cache: Simplify image view queries and blacklisting
This commit is contained in:
parent
48d81506a3
commit
56ccda1d99
16 changed files with 192 additions and 192 deletions
|
@ -69,6 +69,8 @@ ImageBase::ImageBase(const ImageInfo& info_, GPUVAddr gpu_addr_, VAddr cpu_addr_
|
|||
}
|
||||
}
|
||||
|
||||
ImageBase::ImageBase(const NullImageParams&) {}
|
||||
|
||||
ImageMapView::ImageMapView(GPUVAddr gpu_addr_, VAddr cpu_addr_, size_t size_, ImageId image_id_)
|
||||
: gpu_addr{gpu_addr_}, cpu_addr{cpu_addr_}, size{size_}, image_id{image_id_} {}
|
||||
|
||||
|
|
|
@ -48,8 +48,11 @@ struct AliasedImage {
|
|||
ImageId id;
|
||||
};
|
||||
|
||||
struct NullImageParams {};
|
||||
|
||||
struct ImageBase {
|
||||
explicit ImageBase(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr);
|
||||
explicit ImageBase(const NullImageParams&);
|
||||
|
||||
[[nodiscard]] std::optional<SubresourceBase> TryFindBase(GPUVAddr other_addr) const noexcept;
|
||||
|
||||
|
|
|
@ -45,6 +45,6 @@ ImageViewBase::ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_in
|
|||
ASSERT_MSG(view_info.type == ImageViewType::Buffer, "Expected texture buffer");
|
||||
}
|
||||
|
||||
ImageViewBase::ImageViewBase(const NullImageParams&) {}
|
||||
ImageViewBase::ImageViewBase(const NullImageViewParams&) : image_id{NULL_IMAGE_ID} {}
|
||||
|
||||
} // namespace VideoCommon
|
||||
|
|
|
@ -15,7 +15,7 @@ using VideoCore::Surface::PixelFormat;
|
|||
struct ImageViewInfo;
|
||||
struct ImageInfo;
|
||||
|
||||
struct NullImageParams {};
|
||||
struct NullImageViewParams {};
|
||||
|
||||
enum class ImageViewFlagBits : u16 {
|
||||
PreemtiveDownload = 1 << 0,
|
||||
|
@ -28,7 +28,7 @@ struct ImageViewBase {
|
|||
explicit ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_info,
|
||||
ImageId image_id);
|
||||
explicit ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_info);
|
||||
explicit ImageViewBase(const NullImageParams&);
|
||||
explicit ImageViewBase(const NullImageViewParams&);
|
||||
|
||||
[[nodiscard]] bool IsBuffer() const noexcept {
|
||||
return type == ImageViewType::Buffer;
|
||||
|
|
|
@ -36,7 +36,6 @@ 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);
|
||||
|
@ -46,7 +45,8 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
|
|||
|
||||
// Make sure the first index is reserved for the null resources
|
||||
// This way the null resource becomes a compile time constant
|
||||
void(slot_image_views.insert(runtime, NullImageParams{}));
|
||||
void(slot_images.insert(NullImageParams{}));
|
||||
void(slot_image_views.insert(runtime, NullImageViewParams{}));
|
||||
void(slot_samplers.insert(runtime, sampler_descriptor));
|
||||
|
||||
if constexpr (HAS_DEVICE_MEMORY_INFO) {
|
||||
|
@ -57,7 +57,7 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
|
|||
critical_memory = std::max(possible_critical_memory, DEFAULT_CRITICAL_MEMORY);
|
||||
minimum_memory = 0;
|
||||
} else {
|
||||
// on OGL we can be more conservatives as the driver takes care.
|
||||
// On OpenGL we can be more conservatives as the driver takes care.
|
||||
expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB;
|
||||
critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB;
|
||||
minimum_memory = expected_memory;
|
||||
|
@ -135,15 +135,14 @@ void TextureCache<P>::MarkModification(ImageId id) noexcept {
|
|||
}
|
||||
|
||||
template <class P>
|
||||
void TextureCache<P>::FillGraphicsImageViews(std::span<const u32> indices,
|
||||
std::span<ImageViewId> image_view_ids) {
|
||||
FillImageViews(graphics_image_table, graphics_image_view_ids, indices, image_view_ids);
|
||||
template <bool has_blacklists>
|
||||
void TextureCache<P>::FillGraphicsImageViews(std::span<ImageViewInOut> views) {
|
||||
FillImageViews<has_blacklists>(graphics_image_table, graphics_image_view_ids, views);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
void TextureCache<P>::FillComputeImageViews(std::span<const u32> indices,
|
||||
std::span<ImageViewId> image_view_ids) {
|
||||
FillImageViews(compute_image_table, compute_image_view_ids, indices, image_view_ids);
|
||||
void TextureCache<P>::FillComputeImageViews(std::span<ImageViewInOut> views) {
|
||||
FillImageViews<false>(compute_image_table, compute_image_view_ids, views);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
@ -346,17 +345,26 @@ typename P::Framebuffer* TextureCache<P>::GetFramebuffer() {
|
|||
}
|
||||
|
||||
template <class P>
|
||||
template <bool has_blacklists>
|
||||
void TextureCache<P>::FillImageViews(DescriptorTable<TICEntry>& table,
|
||||
std::span<ImageViewId> cached_image_view_ids,
|
||||
std::span<const u32> indices,
|
||||
std::span<ImageViewId> image_view_ids) {
|
||||
ASSERT(indices.size() <= image_view_ids.size());
|
||||
std::span<ImageViewInOut> views) {
|
||||
bool has_blacklisted;
|
||||
do {
|
||||
has_deleted_images = false;
|
||||
std::ranges::transform(indices, image_view_ids.begin(), [&](u32 index) {
|
||||
return VisitImageView(table, cached_image_view_ids, index);
|
||||
});
|
||||
} while (has_deleted_images);
|
||||
if constexpr (has_blacklists) {
|
||||
has_blacklisted = false;
|
||||
}
|
||||
for (ImageViewInOut& view : views) {
|
||||
view.id = VisitImageView(table, cached_image_view_ids, view.index);
|
||||
if constexpr (has_blacklists) {
|
||||
if (view.blacklist && view.id != NULL_IMAGE_VIEW_ID) {
|
||||
const ImageViewBase& image_view{slot_image_views[view.id]};
|
||||
has_blacklisted |= BlackListImage(image_view.image_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (has_deleted_images || (has_blacklists && has_blacklisted));
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
@ -622,7 +630,7 @@ void TextureCache<P>::PopAsyncFlushes() {
|
|||
}
|
||||
|
||||
template <class P>
|
||||
bool TextureCache<P>::IsRescaling() {
|
||||
bool TextureCache<P>::IsRescaling() const noexcept {
|
||||
return is_rescaling;
|
||||
}
|
||||
|
||||
|
@ -775,12 +783,11 @@ bool TextureCache<P>::BlackListImage(ImageId image_id) {
|
|||
}
|
||||
|
||||
template <class P>
|
||||
bool TextureCache<P>::ImageCanRescale(Image& image) {
|
||||
bool TextureCache<P>::ImageCanRescale(ImageBase& image) {
|
||||
if (True(image.flags & ImageFlagBits::Blacklisted)) {
|
||||
return false;
|
||||
}
|
||||
if (True(image.flags & ImageFlagBits::Rescaled) ||
|
||||
True(image.flags & ImageFlagBits::RescaleChecked)) {
|
||||
if (True(image.flags & (ImageFlagBits::Rescaled | ImageFlagBits::RescaleChecked))) {
|
||||
return true;
|
||||
}
|
||||
if (!image.info.rescaleable) {
|
||||
|
|
|
@ -39,6 +39,16 @@ using VideoCore::Surface::PixelFormatFromDepthFormat;
|
|||
using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
|
||||
using namespace Common::Literals;
|
||||
|
||||
struct ImageViewInOut {
|
||||
u32 index;
|
||||
bool blacklist;
|
||||
union {
|
||||
struct Empty {
|
||||
} empty{};
|
||||
ImageViewId id;
|
||||
};
|
||||
};
|
||||
|
||||
template <class P>
|
||||
class TextureCache {
|
||||
/// Address shift for caching images into a hash table
|
||||
|
@ -53,11 +63,6 @@ class TextureCache {
|
|||
/// True when the API can provide info about the memory of the device.
|
||||
static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
|
||||
|
||||
/// Image view ID for null descriptors
|
||||
static constexpr ImageViewId NULL_IMAGE_VIEW_ID{0};
|
||||
/// Sampler ID for bugged sampler ids
|
||||
static constexpr SamplerId NULL_SAMPLER_ID{0};
|
||||
|
||||
static constexpr u64 DEFAULT_EXPECTED_MEMORY = 1_GiB;
|
||||
static constexpr u64 DEFAULT_CRITICAL_MEMORY = 2_GiB;
|
||||
|
||||
|
@ -105,11 +110,11 @@ public:
|
|||
void MarkModification(ImageId id) noexcept;
|
||||
|
||||
/// Fill image_view_ids with the graphics images in indices
|
||||
void FillGraphicsImageViews(std::span<const u32> indices,
|
||||
std::span<ImageViewId> image_view_ids);
|
||||
template <bool has_blacklists>
|
||||
void FillGraphicsImageViews(std::span<ImageViewInOut> views);
|
||||
|
||||
/// Fill image_view_ids with the compute images in indices
|
||||
void FillComputeImageViews(std::span<const u32> indices, std::span<ImageViewId> image_view_ids);
|
||||
void FillComputeImageViews(std::span<ImageViewInOut> views);
|
||||
|
||||
/// Get the sampler from the graphics descriptor table in the specified index
|
||||
Sampler* GetGraphicsSampler(u32 index);
|
||||
|
@ -174,7 +179,7 @@ public:
|
|||
/// Return true when a CPU region is modified from the GPU
|
||||
[[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size);
|
||||
|
||||
[[nodiscard]] bool IsRescaling();
|
||||
[[nodiscard]] bool IsRescaling() const noexcept;
|
||||
|
||||
[[nodiscard]] bool BlackListImage(ImageId image_id);
|
||||
|
||||
|
@ -216,9 +221,10 @@ private:
|
|||
void RunGarbageCollector();
|
||||
|
||||
/// Fills image_view_ids in the image views in indices
|
||||
template <bool has_blacklists>
|
||||
void FillImageViews(DescriptorTable<TICEntry>& table,
|
||||
std::span<ImageViewId> cached_image_view_ids, std::span<const u32> indices,
|
||||
std::span<ImageViewId> image_view_ids);
|
||||
std::span<ImageViewId> cached_image_view_ids,
|
||||
std::span<ImageViewInOut> views);
|
||||
|
||||
/// Find or create an image view in the guest descriptor table
|
||||
ImageViewId VisitImageView(DescriptorTable<TICEntry>& table,
|
||||
|
@ -336,7 +342,7 @@ 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);
|
||||
bool ImageCanRescale(ImageBase& image);
|
||||
void InvalidateScale(Image& image);
|
||||
bool ScaleUp(Image& image);
|
||||
bool ScaleDown(Image& image);
|
||||
|
|
|
@ -22,6 +22,13 @@ using ImageAllocId = SlotId;
|
|||
using SamplerId = SlotId;
|
||||
using FramebufferId = SlotId;
|
||||
|
||||
/// Fake image ID for null image views
|
||||
constexpr ImageId NULL_IMAGE_ID{0};
|
||||
/// Image view ID for null descriptors
|
||||
constexpr ImageViewId NULL_IMAGE_VIEW_ID{0};
|
||||
/// Sampler ID for bugged sampler ids
|
||||
constexpr SamplerId NULL_SAMPLER_ID{0};
|
||||
|
||||
enum class ImageType : u32 {
|
||||
e1D,
|
||||
e2D,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue