diff options
| author | 2023-12-25 07:32:16 +0100 | |
|---|---|---|
| committer | 2024-01-18 21:12:30 -0500 | |
| commit | 0a2536a0df1f4aea406f2132d3edda0430acc9d1 (patch) | |
| tree | c0ad53890581c9c7e180c5ccb3b66e3c63e3ba64 /src/video_core/texture_cache | |
| parent | SMMU: Implement backing CPU page protect/unprotect (diff) | |
| download | yuzu-0a2536a0df1f4aea406f2132d3edda0430acc9d1.tar.gz yuzu-0a2536a0df1f4aea406f2132d3edda0430acc9d1.tar.xz yuzu-0a2536a0df1f4aea406f2132d3edda0430acc9d1.zip | |
SMMU: Initial adaptation to video_core.
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 75 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache_base.h | 28 | ||||
| -rw-r--r-- | src/video_core/texture_cache/util.cpp | 4 |
3 files changed, 56 insertions, 51 deletions
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 0d5a1709f..7398ed2ec 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -8,10 +8,11 @@ | |||
| 8 | 8 | ||
| 9 | #include "common/alignment.h" | 9 | #include "common/alignment.h" |
| 10 | #include "common/settings.h" | 10 | #include "common/settings.h" |
| 11 | #include "core/memory.h" | ||
| 12 | #include "video_core/control/channel_state.h" | 11 | #include "video_core/control/channel_state.h" |
| 13 | #include "video_core/dirty_flags.h" | 12 | #include "video_core/dirty_flags.h" |
| 14 | #include "video_core/engines/kepler_compute.h" | 13 | #include "video_core/engines/kepler_compute.h" |
| 14 | #include "video_core/guest_memory.h" | ||
| 15 | #include "video_core/host1x/gpu_device_memory_manager.h" | ||
| 15 | #include "video_core/texture_cache/image_view_base.h" | 16 | #include "video_core/texture_cache/image_view_base.h" |
| 16 | #include "video_core/texture_cache/samples_helper.h" | 17 | #include "video_core/texture_cache/samples_helper.h" |
| 17 | #include "video_core/texture_cache/texture_cache_base.h" | 18 | #include "video_core/texture_cache/texture_cache_base.h" |
| @@ -27,8 +28,8 @@ using VideoCore::Surface::SurfaceType; | |||
| 27 | using namespace Common::Literals; | 28 | using namespace Common::Literals; |
| 28 | 29 | ||
| 29 | template <class P> | 30 | template <class P> |
| 30 | TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface& rasterizer_) | 31 | TextureCache<P>::TextureCache(Runtime& runtime_, Tegra::MaxwellDeviceMemoryManager& device_memory_) |
| 31 | : runtime{runtime_}, rasterizer{rasterizer_} { | 32 | : runtime{runtime_}, device_memory{device_memory_} { |
| 32 | // Configure null sampler | 33 | // Configure null sampler |
| 33 | TSCEntry sampler_descriptor{}; | 34 | TSCEntry sampler_descriptor{}; |
| 34 | sampler_descriptor.min_filter.Assign(Tegra::Texture::TextureFilter::Linear); | 35 | sampler_descriptor.min_filter.Assign(Tegra::Texture::TextureFilter::Linear); |
| @@ -49,19 +50,19 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface& | |||
| 49 | void(slot_samplers.insert(runtime, sampler_descriptor)); | 50 | void(slot_samplers.insert(runtime, sampler_descriptor)); |
| 50 | 51 | ||
| 51 | if constexpr (HAS_DEVICE_MEMORY_INFO) { | 52 | if constexpr (HAS_DEVICE_MEMORY_INFO) { |
| 52 | const s64 device_memory = static_cast<s64>(runtime.GetDeviceLocalMemory()); | 53 | const s64 device_local_memory = static_cast<s64>(runtime.GetDeviceLocalMemory()); |
| 53 | const s64 min_spacing_expected = device_memory - 1_GiB; | 54 | const s64 min_spacing_expected = device_local_memory - 1_GiB; |
| 54 | const s64 min_spacing_critical = device_memory - 512_MiB; | 55 | const s64 min_spacing_critical = device_local_memory - 512_MiB; |
| 55 | const s64 mem_threshold = std::min(device_memory, TARGET_THRESHOLD); | 56 | const s64 mem_threshold = std::min(device_local_memory, TARGET_THRESHOLD); |
| 56 | const s64 min_vacancy_expected = (6 * mem_threshold) / 10; | 57 | const s64 min_vacancy_expected = (6 * mem_threshold) / 10; |
| 57 | const s64 min_vacancy_critical = (3 * mem_threshold) / 10; | 58 | const s64 min_vacancy_critical = (3 * mem_threshold) / 10; |
| 58 | expected_memory = static_cast<u64>( | 59 | expected_memory = static_cast<u64>( |
| 59 | std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected), | 60 | std::max(std::min(device_local_memory - min_vacancy_expected, min_spacing_expected), |
| 60 | DEFAULT_EXPECTED_MEMORY)); | 61 | DEFAULT_EXPECTED_MEMORY)); |
| 61 | critical_memory = static_cast<u64>( | 62 | critical_memory = static_cast<u64>( |
| 62 | std::max(std::min(device_memory - min_vacancy_critical, min_spacing_critical), | 63 | std::max(std::min(device_local_memory - min_vacancy_critical, min_spacing_critical), |
| 63 | DEFAULT_CRITICAL_MEMORY)); | 64 | DEFAULT_CRITICAL_MEMORY)); |
| 64 | minimum_memory = static_cast<u64>((device_memory - mem_threshold) / 2); | 65 | minimum_memory = static_cast<u64>((device_local_memory - mem_threshold) / 2); |
| 65 | } else { | 66 | } else { |
| 66 | expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB; | 67 | expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB; |
| 67 | critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB; | 68 | critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB; |
| @@ -513,7 +514,7 @@ FramebufferId TextureCache<P>::GetFramebufferId(const RenderTargets& key) { | |||
| 513 | } | 514 | } |
| 514 | 515 | ||
| 515 | template <class P> | 516 | template <class P> |
| 516 | void TextureCache<P>::WriteMemory(VAddr cpu_addr, size_t size) { | 517 | void TextureCache<P>::WriteMemory(DAddr cpu_addr, size_t size) { |
| 517 | ForEachImageInRegion(cpu_addr, size, [this](ImageId image_id, Image& image) { | 518 | ForEachImageInRegion(cpu_addr, size, [this](ImageId image_id, Image& image) { |
| 518 | if (True(image.flags & ImageFlagBits::CpuModified)) { | 519 | if (True(image.flags & ImageFlagBits::CpuModified)) { |
| 519 | return; | 520 | return; |
| @@ -526,7 +527,7 @@ void TextureCache<P>::WriteMemory(VAddr cpu_addr, size_t size) { | |||
| 526 | } | 527 | } |
| 527 | 528 | ||
| 528 | template <class P> | 529 | template <class P> |
| 529 | void TextureCache<P>::DownloadMemory(VAddr cpu_addr, size_t size) { | 530 | void TextureCache<P>::DownloadMemory(DAddr cpu_addr, size_t size) { |
| 530 | boost::container::small_vector<ImageId, 16> images; | 531 | boost::container::small_vector<ImageId, 16> images; |
| 531 | ForEachImageInRegion(cpu_addr, size, [&images](ImageId image_id, ImageBase& image) { | 532 | ForEachImageInRegion(cpu_addr, size, [&images](ImageId image_id, ImageBase& image) { |
| 532 | if (!image.IsSafeDownload()) { | 533 | if (!image.IsSafeDownload()) { |
| @@ -553,7 +554,7 @@ void TextureCache<P>::DownloadMemory(VAddr cpu_addr, size_t size) { | |||
| 553 | } | 554 | } |
| 554 | 555 | ||
| 555 | template <class P> | 556 | template <class P> |
| 556 | std::optional<VideoCore::RasterizerDownloadArea> TextureCache<P>::GetFlushArea(VAddr cpu_addr, | 557 | std::optional<VideoCore::RasterizerDownloadArea> TextureCache<P>::GetFlushArea(DAddr cpu_addr, |
| 557 | u64 size) { | 558 | u64 size) { |
| 558 | std::optional<VideoCore::RasterizerDownloadArea> area{}; | 559 | std::optional<VideoCore::RasterizerDownloadArea> area{}; |
| 559 | ForEachImageInRegion(cpu_addr, size, [&](ImageId, ImageBase& image) { | 560 | ForEachImageInRegion(cpu_addr, size, [&](ImageId, ImageBase& image) { |
| @@ -579,7 +580,7 @@ std::optional<VideoCore::RasterizerDownloadArea> TextureCache<P>::GetFlushArea(V | |||
| 579 | } | 580 | } |
| 580 | 581 | ||
| 581 | template <class P> | 582 | template <class P> |
| 582 | void TextureCache<P>::UnmapMemory(VAddr cpu_addr, size_t size) { | 583 | void TextureCache<P>::UnmapMemory(DAddr cpu_addr, size_t size) { |
| 583 | boost::container::small_vector<ImageId, 16> deleted_images; | 584 | boost::container::small_vector<ImageId, 16> deleted_images; |
| 584 | ForEachImageInRegion(cpu_addr, size, [&](ImageId id, Image&) { deleted_images.push_back(id); }); | 585 | ForEachImageInRegion(cpu_addr, size, [&](ImageId id, Image&) { deleted_images.push_back(id); }); |
| 585 | for (const ImageId id : deleted_images) { | 586 | for (const ImageId id : deleted_images) { |
| @@ -713,7 +714,7 @@ bool TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, | |||
| 713 | 714 | ||
| 714 | template <class P> | 715 | template <class P> |
| 715 | typename P::ImageView* TextureCache<P>::TryFindFramebufferImageView( | 716 | typename P::ImageView* TextureCache<P>::TryFindFramebufferImageView( |
| 716 | const Tegra::FramebufferConfig& config, VAddr cpu_addr) { | 717 | const Tegra::FramebufferConfig& config, DAddr cpu_addr) { |
| 717 | // TODO: Properly implement this | 718 | // TODO: Properly implement this |
| 718 | const auto it = page_table.find(cpu_addr >> YUZU_PAGEBITS); | 719 | const auto it = page_table.find(cpu_addr >> YUZU_PAGEBITS); |
| 719 | if (it == page_table.end()) { | 720 | if (it == page_table.end()) { |
| @@ -940,7 +941,7 @@ bool TextureCache<P>::IsRescaling(const ImageViewBase& image_view) const noexcep | |||
| 940 | } | 941 | } |
| 941 | 942 | ||
| 942 | template <class P> | 943 | template <class P> |
| 943 | bool TextureCache<P>::IsRegionGpuModified(VAddr addr, size_t size) { | 944 | bool TextureCache<P>::IsRegionGpuModified(DAddr addr, size_t size) { |
| 944 | bool is_modified = false; | 945 | bool is_modified = false; |
| 945 | ForEachImageInRegion(addr, size, [&is_modified](ImageId, ImageBase& image) { | 946 | ForEachImageInRegion(addr, size, [&is_modified](ImageId, ImageBase& image) { |
| 946 | if (False(image.flags & ImageFlagBits::GpuModified)) { | 947 | if (False(image.flags & ImageFlagBits::GpuModified)) { |
| @@ -1059,7 +1060,7 @@ void TextureCache<P>::UploadImageContents(Image& image, StagingBuffer& staging) | |||
| 1059 | return; | 1060 | return; |
| 1060 | } | 1061 | } |
| 1061 | 1062 | ||
| 1062 | Core::Memory::GpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> swizzle_data( | 1063 | Tegra::Memory::GpuGuestMemory<u8, Tegra::Memory::GuestMemoryFlags::UnsafeRead> swizzle_data( |
| 1063 | *gpu_memory, gpu_addr, image.guest_size_bytes, &swizzle_data_buffer); | 1064 | *gpu_memory, gpu_addr, image.guest_size_bytes, &swizzle_data_buffer); |
| 1064 | 1065 | ||
| 1065 | if (True(image.flags & ImageFlagBits::Converted)) { | 1066 | if (True(image.flags & ImageFlagBits::Converted)) { |
| @@ -1124,7 +1125,7 @@ ImageId TextureCache<P>::FindOrInsertImage(const ImageInfo& info, GPUVAddr gpu_a | |||
| 1124 | template <class P> | 1125 | template <class P> |
| 1125 | ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr, | 1126 | ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr, |
| 1126 | RelaxedOptions options) { | 1127 | RelaxedOptions options) { |
| 1127 | std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1128 | std::optional<DAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1128 | if (!cpu_addr) { | 1129 | if (!cpu_addr) { |
| 1129 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, CalculateGuestSizeInBytes(info)); | 1130 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, CalculateGuestSizeInBytes(info)); |
| 1130 | if (!cpu_addr) { | 1131 | if (!cpu_addr) { |
| @@ -1265,7 +1266,7 @@ void TextureCache<P>::QueueAsyncDecode(Image& image, ImageId image_id) { | |||
| 1265 | 1266 | ||
| 1266 | static Common::ScratchBuffer<u8> local_unswizzle_data_buffer; | 1267 | static Common::ScratchBuffer<u8> local_unswizzle_data_buffer; |
| 1267 | local_unswizzle_data_buffer.resize_destructive(image.unswizzled_size_bytes); | 1268 | local_unswizzle_data_buffer.resize_destructive(image.unswizzled_size_bytes); |
| 1268 | Core::Memory::GpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> swizzle_data( | 1269 | Tegra::Memory::GpuGuestMemory<u8, Tegra::Memory::GuestMemoryFlags::UnsafeRead> swizzle_data( |
| 1269 | *gpu_memory, image.gpu_addr, image.guest_size_bytes, &swizzle_data_buffer); | 1270 | *gpu_memory, image.gpu_addr, image.guest_size_bytes, &swizzle_data_buffer); |
| 1270 | 1271 | ||
| 1271 | auto copies = UnswizzleImage(*gpu_memory, image.gpu_addr, image.info, swizzle_data, | 1272 | auto copies = UnswizzleImage(*gpu_memory, image.gpu_addr, image.info, swizzle_data, |
| @@ -1339,14 +1340,14 @@ bool TextureCache<P>::ScaleDown(Image& image) { | |||
| 1339 | template <class P> | 1340 | template <class P> |
| 1340 | ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr, | 1341 | ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr, |
| 1341 | RelaxedOptions options) { | 1342 | RelaxedOptions options) { |
| 1342 | std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1343 | std::optional<DAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1343 | if (!cpu_addr) { | 1344 | if (!cpu_addr) { |
| 1344 | const auto size = CalculateGuestSizeInBytes(info); | 1345 | const auto size = CalculateGuestSizeInBytes(info); |
| 1345 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, size); | 1346 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, size); |
| 1346 | if (!cpu_addr) { | 1347 | if (!cpu_addr) { |
| 1347 | const VAddr fake_addr = ~(1ULL << 40ULL) + virtual_invalid_space; | 1348 | const DAddr fake_addr = ~(1ULL << 40ULL) + virtual_invalid_space; |
| 1348 | virtual_invalid_space += Common::AlignUp(size, 32); | 1349 | virtual_invalid_space += Common::AlignUp(size, 32); |
| 1349 | cpu_addr = std::optional<VAddr>(fake_addr); | 1350 | cpu_addr = std::optional<DAddr>(fake_addr); |
| 1350 | } | 1351 | } |
| 1351 | } | 1352 | } |
| 1352 | ASSERT_MSG(cpu_addr, "Tried to insert an image to an invalid gpu_addr=0x{:x}", gpu_addr); | 1353 | ASSERT_MSG(cpu_addr, "Tried to insert an image to an invalid gpu_addr=0x{:x}", gpu_addr); |
| @@ -1362,7 +1363,7 @@ ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr, | |||
| 1362 | } | 1363 | } |
| 1363 | 1364 | ||
| 1364 | template <class P> | 1365 | template <class P> |
| 1365 | ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr) { | 1366 | ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, DAddr cpu_addr) { |
| 1366 | ImageInfo new_info = info; | 1367 | ImageInfo new_info = info; |
| 1367 | const size_t size_bytes = CalculateGuestSizeInBytes(new_info); | 1368 | const size_t size_bytes = CalculateGuestSizeInBytes(new_info); |
| 1368 | const bool broken_views = runtime.HasBrokenTextureViewFormats(); | 1369 | const bool broken_views = runtime.HasBrokenTextureViewFormats(); |
| @@ -1650,7 +1651,7 @@ std::optional<typename TextureCache<P>::BlitImages> TextureCache<P>::GetBlitImag | |||
| 1650 | 1651 | ||
| 1651 | template <class P> | 1652 | template <class P> |
| 1652 | ImageId TextureCache<P>::FindDMAImage(const ImageInfo& info, GPUVAddr gpu_addr) { | 1653 | ImageId TextureCache<P>::FindDMAImage(const ImageInfo& info, GPUVAddr gpu_addr) { |
| 1653 | std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1654 | std::optional<DAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1654 | if (!cpu_addr) { | 1655 | if (!cpu_addr) { |
| 1655 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, CalculateGuestSizeInBytes(info)); | 1656 | cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr, CalculateGuestSizeInBytes(info)); |
| 1656 | if (!cpu_addr) { | 1657 | if (!cpu_addr) { |
| @@ -1780,7 +1781,7 @@ ImageViewId TextureCache<P>::FindRenderTargetView(const ImageInfo& info, GPUVAdd | |||
| 1780 | 1781 | ||
| 1781 | template <class P> | 1782 | template <class P> |
| 1782 | template <typename Func> | 1783 | template <typename Func> |
| 1783 | void TextureCache<P>::ForEachImageInRegion(VAddr cpu_addr, size_t size, Func&& func) { | 1784 | void TextureCache<P>::ForEachImageInRegion(DAddr cpu_addr, size_t size, Func&& func) { |
| 1784 | using FuncReturn = typename std::invoke_result<Func, ImageId, Image&>::type; | 1785 | using FuncReturn = typename std::invoke_result<Func, ImageId, Image&>::type; |
| 1785 | static constexpr bool BOOL_BREAK = std::is_same_v<FuncReturn, bool>; | 1786 | static constexpr bool BOOL_BREAK = std::is_same_v<FuncReturn, bool>; |
| 1786 | boost::container::small_vector<ImageId, 32> images; | 1787 | boost::container::small_vector<ImageId, 32> images; |
| @@ -1924,11 +1925,11 @@ void TextureCache<P>::ForEachSparseImageInRegion(GPUVAddr gpu_addr, size_t size, | |||
| 1924 | template <class P> | 1925 | template <class P> |
| 1925 | template <typename Func> | 1926 | template <typename Func> |
| 1926 | void TextureCache<P>::ForEachSparseSegment(ImageBase& image, Func&& func) { | 1927 | void TextureCache<P>::ForEachSparseSegment(ImageBase& image, Func&& func) { |
| 1927 | using FuncReturn = typename std::invoke_result<Func, GPUVAddr, VAddr, size_t>::type; | 1928 | using FuncReturn = typename std::invoke_result<Func, GPUVAddr, DAddr, size_t>::type; |
| 1928 | static constexpr bool RETURNS_BOOL = std::is_same_v<FuncReturn, bool>; | 1929 | static constexpr bool RETURNS_BOOL = std::is_same_v<FuncReturn, bool>; |
| 1929 | const auto segments = gpu_memory->GetSubmappedRange(image.gpu_addr, image.guest_size_bytes); | 1930 | const auto segments = gpu_memory->GetSubmappedRange(image.gpu_addr, image.guest_size_bytes); |
| 1930 | for (const auto& [gpu_addr, size] : segments) { | 1931 | for (const auto& [gpu_addr, size] : segments) { |
| 1931 | std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1932 | std::optional<DAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1932 | ASSERT(cpu_addr); | 1933 | ASSERT(cpu_addr); |
| 1933 | if constexpr (RETURNS_BOOL) { | 1934 | if constexpr (RETURNS_BOOL) { |
| 1934 | if (func(gpu_addr, *cpu_addr, size)) { | 1935 | if (func(gpu_addr, *cpu_addr, size)) { |
| @@ -1980,7 +1981,7 @@ void TextureCache<P>::RegisterImage(ImageId image_id) { | |||
| 1980 | } | 1981 | } |
| 1981 | boost::container::small_vector<ImageViewId, 16> sparse_maps; | 1982 | boost::container::small_vector<ImageViewId, 16> sparse_maps; |
| 1982 | ForEachSparseSegment( | 1983 | ForEachSparseSegment( |
| 1983 | image, [this, image_id, &sparse_maps](GPUVAddr gpu_addr, VAddr cpu_addr, size_t size) { | 1984 | image, [this, image_id, &sparse_maps](GPUVAddr gpu_addr, DAddr cpu_addr, size_t size) { |
| 1984 | auto map_id = slot_map_views.insert(gpu_addr, cpu_addr, size, image_id); | 1985 | auto map_id = slot_map_views.insert(gpu_addr, cpu_addr, size, image_id); |
| 1985 | ForEachCPUPage(cpu_addr, size, | 1986 | ForEachCPUPage(cpu_addr, size, |
| 1986 | [this, map_id](u64 page) { page_table[page].push_back(map_id); }); | 1987 | [this, map_id](u64 page) { page_table[page].push_back(map_id); }); |
| @@ -2048,7 +2049,7 @@ void TextureCache<P>::UnregisterImage(ImageId image_id) { | |||
| 2048 | auto& sparse_maps = it->second; | 2049 | auto& sparse_maps = it->second; |
| 2049 | for (auto& map_view_id : sparse_maps) { | 2050 | for (auto& map_view_id : sparse_maps) { |
| 2050 | const auto& map_range = slot_map_views[map_view_id]; | 2051 | const auto& map_range = slot_map_views[map_view_id]; |
| 2051 | const VAddr cpu_addr = map_range.cpu_addr; | 2052 | const DAddr cpu_addr = map_range.cpu_addr; |
| 2052 | const std::size_t size = map_range.size; | 2053 | const std::size_t size = map_range.size; |
| 2053 | ForEachCPUPage(cpu_addr, size, [this, image_id](u64 page) { | 2054 | ForEachCPUPage(cpu_addr, size, [this, image_id](u64 page) { |
| 2054 | const auto page_it = page_table.find(page); | 2055 | const auto page_it = page_table.find(page); |
| @@ -2080,7 +2081,7 @@ void TextureCache<P>::TrackImage(ImageBase& image, ImageId image_id) { | |||
| 2080 | ASSERT(False(image.flags & ImageFlagBits::Tracked)); | 2081 | ASSERT(False(image.flags & ImageFlagBits::Tracked)); |
| 2081 | image.flags |= ImageFlagBits::Tracked; | 2082 | image.flags |= ImageFlagBits::Tracked; |
| 2082 | if (False(image.flags & ImageFlagBits::Sparse)) { | 2083 | if (False(image.flags & ImageFlagBits::Sparse)) { |
| 2083 | rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, 1); | 2084 | device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, 1); |
| 2084 | return; | 2085 | return; |
| 2085 | } | 2086 | } |
| 2086 | if (True(image.flags & ImageFlagBits::Registered)) { | 2087 | if (True(image.flags & ImageFlagBits::Registered)) { |
| @@ -2089,15 +2090,15 @@ void TextureCache<P>::TrackImage(ImageBase& image, ImageId image_id) { | |||
| 2089 | auto& sparse_maps = it->second; | 2090 | auto& sparse_maps = it->second; |
| 2090 | for (auto& map_view_id : sparse_maps) { | 2091 | for (auto& map_view_id : sparse_maps) { |
| 2091 | const auto& map = slot_map_views[map_view_id]; | 2092 | const auto& map = slot_map_views[map_view_id]; |
| 2092 | const VAddr cpu_addr = map.cpu_addr; | 2093 | const DAddr cpu_addr = map.cpu_addr; |
| 2093 | const std::size_t size = map.size; | 2094 | const std::size_t size = map.size; |
| 2094 | rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1); | 2095 | device_memory.UpdatePagesCachedCount(cpu_addr, size, 1); |
| 2095 | } | 2096 | } |
| 2096 | return; | 2097 | return; |
| 2097 | } | 2098 | } |
| 2098 | ForEachSparseSegment(image, | 2099 | ForEachSparseSegment(image, |
| 2099 | [this]([[maybe_unused]] GPUVAddr gpu_addr, VAddr cpu_addr, size_t size) { | 2100 | [this]([[maybe_unused]] GPUVAddr gpu_addr, DAddr cpu_addr, size_t size) { |
| 2100 | rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1); | 2101 | device_memory.UpdatePagesCachedCount(cpu_addr, size, 1); |
| 2101 | }); | 2102 | }); |
| 2102 | } | 2103 | } |
| 2103 | 2104 | ||
| @@ -2106,7 +2107,7 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) { | |||
| 2106 | ASSERT(True(image.flags & ImageFlagBits::Tracked)); | 2107 | ASSERT(True(image.flags & ImageFlagBits::Tracked)); |
| 2107 | image.flags &= ~ImageFlagBits::Tracked; | 2108 | image.flags &= ~ImageFlagBits::Tracked; |
| 2108 | if (False(image.flags & ImageFlagBits::Sparse)) { | 2109 | if (False(image.flags & ImageFlagBits::Sparse)) { |
| 2109 | rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, -1); | 2110 | device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, -1); |
| 2110 | return; | 2111 | return; |
| 2111 | } | 2112 | } |
| 2112 | ASSERT(True(image.flags & ImageFlagBits::Registered)); | 2113 | ASSERT(True(image.flags & ImageFlagBits::Registered)); |
| @@ -2115,9 +2116,9 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) { | |||
| 2115 | auto& sparse_maps = it->second; | 2116 | auto& sparse_maps = it->second; |
| 2116 | for (auto& map_view_id : sparse_maps) { | 2117 | for (auto& map_view_id : sparse_maps) { |
| 2117 | const auto& map = slot_map_views[map_view_id]; | 2118 | const auto& map = slot_map_views[map_view_id]; |
| 2118 | const VAddr cpu_addr = map.cpu_addr; | 2119 | const DAddr cpu_addr = map.cpu_addr; |
| 2119 | const std::size_t size = map.size; | 2120 | const std::size_t size = map.size; |
| 2120 | rasterizer.UpdatePagesCachedCount(cpu_addr, size, -1); | 2121 | device_memory.UpdatePagesCachedCount(cpu_addr, size, -1); |
| 2121 | } | 2122 | } |
| 2122 | } | 2123 | } |
| 2123 | 2124 | ||
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 6caf75b46..8699d40d4 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -36,9 +36,11 @@ | |||
| 36 | #include "video_core/texture_cache/types.h" | 36 | #include "video_core/texture_cache/types.h" |
| 37 | #include "video_core/textures/texture.h" | 37 | #include "video_core/textures/texture.h" |
| 38 | 38 | ||
| 39 | namespace Tegra::Control { | 39 | namespace Tegra { |
| 40 | namespace Control { | ||
| 40 | struct ChannelState; | 41 | struct ChannelState; |
| 41 | } | 42 | } |
| 43 | } // namespace Tegra | ||
| 42 | 44 | ||
| 43 | namespace VideoCommon { | 45 | namespace VideoCommon { |
| 44 | 46 | ||
| @@ -126,7 +128,7 @@ class TextureCache : public VideoCommon::ChannelSetupCaches<TextureCacheChannelI | |||
| 126 | }; | 128 | }; |
| 127 | 129 | ||
| 128 | public: | 130 | public: |
| 129 | explicit TextureCache(Runtime&, VideoCore::RasterizerInterface&); | 131 | explicit TextureCache(Runtime&, Tegra::MaxwellDeviceMemoryManager&); |
| 130 | 132 | ||
| 131 | /// Notify the cache that a new frame has been queued | 133 | /// Notify the cache that a new frame has been queued |
| 132 | void TickFrame(); | 134 | void TickFrame(); |
| @@ -190,15 +192,15 @@ public: | |||
| 190 | Framebuffer* GetFramebuffer(); | 192 | Framebuffer* GetFramebuffer(); |
| 191 | 193 | ||
| 192 | /// Mark images in a range as modified from the CPU | 194 | /// Mark images in a range as modified from the CPU |
| 193 | void WriteMemory(VAddr cpu_addr, size_t size); | 195 | void WriteMemory(DAddr cpu_addr, size_t size); |
| 194 | 196 | ||
| 195 | /// Download contents of host images to guest memory in a region | 197 | /// Download contents of host images to guest memory in a region |
| 196 | void DownloadMemory(VAddr cpu_addr, size_t size); | 198 | void DownloadMemory(DAddr cpu_addr, size_t size); |
| 197 | 199 | ||
| 198 | std::optional<VideoCore::RasterizerDownloadArea> GetFlushArea(VAddr cpu_addr, u64 size); | 200 | std::optional<VideoCore::RasterizerDownloadArea> GetFlushArea(DAddr cpu_addr, u64 size); |
| 199 | 201 | ||
| 200 | /// Remove images in a region | 202 | /// Remove images in a region |
| 201 | void UnmapMemory(VAddr cpu_addr, size_t size); | 203 | void UnmapMemory(DAddr cpu_addr, size_t size); |
| 202 | 204 | ||
| 203 | /// Remove images in a region | 205 | /// Remove images in a region |
| 204 | void UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t size); | 206 | void UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t size); |
| @@ -210,7 +212,7 @@ public: | |||
| 210 | 212 | ||
| 211 | /// Try to find a cached image view in the given CPU address | 213 | /// Try to find a cached image view in the given CPU address |
| 212 | [[nodiscard]] ImageView* TryFindFramebufferImageView(const Tegra::FramebufferConfig& config, | 214 | [[nodiscard]] ImageView* TryFindFramebufferImageView(const Tegra::FramebufferConfig& config, |
| 213 | VAddr cpu_addr); | 215 | DAddr cpu_addr); |
| 214 | 216 | ||
| 215 | /// Return true when there are uncommitted images to be downloaded | 217 | /// Return true when there are uncommitted images to be downloaded |
| 216 | [[nodiscard]] bool HasUncommittedFlushes() const noexcept; | 218 | [[nodiscard]] bool HasUncommittedFlushes() const noexcept; |
| @@ -235,7 +237,7 @@ public: | |||
| 235 | GPUVAddr address = 0, size_t size = 0); | 237 | GPUVAddr address = 0, size_t size = 0); |
| 236 | 238 | ||
| 237 | /// Return true when a CPU region is modified from the GPU | 239 | /// Return true when a CPU region is modified from the GPU |
| 238 | [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); | 240 | [[nodiscard]] bool IsRegionGpuModified(DAddr addr, size_t size); |
| 239 | 241 | ||
| 240 | [[nodiscard]] bool IsRescaling() const noexcept; | 242 | [[nodiscard]] bool IsRescaling() const noexcept; |
| 241 | 243 | ||
| @@ -252,7 +254,7 @@ public: | |||
| 252 | private: | 254 | private: |
| 253 | /// Iterate over all page indices in a range | 255 | /// Iterate over all page indices in a range |
| 254 | template <typename Func> | 256 | template <typename Func> |
| 255 | static void ForEachCPUPage(VAddr addr, size_t size, Func&& func) { | 257 | static void ForEachCPUPage(DAddr addr, size_t size, Func&& func) { |
| 256 | static constexpr bool RETURNS_BOOL = std::is_same_v<std::invoke_result<Func, u64>, bool>; | 258 | static constexpr bool RETURNS_BOOL = std::is_same_v<std::invoke_result<Func, u64>, bool>; |
| 257 | const u64 page_end = (addr + size - 1) >> YUZU_PAGEBITS; | 259 | const u64 page_end = (addr + size - 1) >> YUZU_PAGEBITS; |
| 258 | for (u64 page = addr >> YUZU_PAGEBITS; page <= page_end; ++page) { | 260 | for (u64 page = addr >> YUZU_PAGEBITS; page <= page_end; ++page) { |
| @@ -326,7 +328,7 @@ private: | |||
| 326 | 328 | ||
| 327 | /// Create a new image and join perfectly matching existing images | 329 | /// Create a new image and join perfectly matching existing images |
| 328 | /// Remove joined images from the cache | 330 | /// Remove joined images from the cache |
| 329 | [[nodiscard]] ImageId JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr); | 331 | [[nodiscard]] ImageId JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, DAddr cpu_addr); |
| 330 | 332 | ||
| 331 | [[nodiscard]] ImageId FindDMAImage(const ImageInfo& info, GPUVAddr gpu_addr); | 333 | [[nodiscard]] ImageId FindDMAImage(const ImageInfo& info, GPUVAddr gpu_addr); |
| 332 | 334 | ||
| @@ -349,7 +351,7 @@ private: | |||
| 349 | 351 | ||
| 350 | /// Iterates over all the images in a region calling func | 352 | /// Iterates over all the images in a region calling func |
| 351 | template <typename Func> | 353 | template <typename Func> |
| 352 | void ForEachImageInRegion(VAddr cpu_addr, size_t size, Func&& func); | 354 | void ForEachImageInRegion(DAddr cpu_addr, size_t size, Func&& func); |
| 353 | 355 | ||
| 354 | template <typename Func> | 356 | template <typename Func> |
| 355 | void ForEachImageInRegionGPU(size_t as_id, GPUVAddr gpu_addr, size_t size, Func&& func); | 357 | void ForEachImageInRegionGPU(size_t as_id, GPUVAddr gpu_addr, size_t size, Func&& func); |
| @@ -421,7 +423,7 @@ private: | |||
| 421 | 423 | ||
| 422 | Runtime& runtime; | 424 | Runtime& runtime; |
| 423 | 425 | ||
| 424 | VideoCore::RasterizerInterface& rasterizer; | 426 | Tegra::MaxwellDeviceMemoryManager& device_memory; |
| 425 | std::deque<TextureCacheGPUMap> gpu_page_table_storage; | 427 | std::deque<TextureCacheGPUMap> gpu_page_table_storage; |
| 426 | 428 | ||
| 427 | RenderTargets render_targets; | 429 | RenderTargets render_targets; |
| @@ -432,7 +434,7 @@ private: | |||
| 432 | std::unordered_map<u64, std::vector<ImageId>, Common::IdentityHash<u64>> sparse_page_table; | 434 | std::unordered_map<u64, std::vector<ImageId>, Common::IdentityHash<u64>> sparse_page_table; |
| 433 | std::unordered_map<ImageId, boost::container::small_vector<ImageViewId, 16>> sparse_views; | 435 | std::unordered_map<ImageId, boost::container::small_vector<ImageViewId, 16>> sparse_views; |
| 434 | 436 | ||
| 435 | VAddr virtual_invalid_space{}; | 437 | DAddr virtual_invalid_space{}; |
| 436 | 438 | ||
| 437 | bool has_deleted_images = false; | 439 | bool has_deleted_images = false; |
| 438 | bool is_rescaling = false; | 440 | bool is_rescaling = false; |
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index fcf70068e..96f04b6c8 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "core/memory.h" | 23 | #include "core/memory.h" |
| 24 | #include "video_core/compatible_formats.h" | 24 | #include "video_core/compatible_formats.h" |
| 25 | #include "video_core/engines/maxwell_3d.h" | 25 | #include "video_core/engines/maxwell_3d.h" |
| 26 | #include "video_core/guest_memory.h" | ||
| 26 | #include "video_core/memory_manager.h" | 27 | #include "video_core/memory_manager.h" |
| 27 | #include "video_core/surface.h" | 28 | #include "video_core/surface.h" |
| 28 | #include "video_core/texture_cache/decode_bc.h" | 29 | #include "video_core/texture_cache/decode_bc.h" |
| @@ -552,7 +553,8 @@ void SwizzleBlockLinearImage(Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr | |||
| 552 | for (s32 layer = 0; layer < info.resources.layers; ++layer) { | 553 | for (s32 layer = 0; layer < info.resources.layers; ++layer) { |
| 553 | const std::span<const u8> src = input.subspan(host_offset); | 554 | const std::span<const u8> src = input.subspan(host_offset); |
| 554 | { | 555 | { |
| 555 | Core::Memory::GpuGuestMemoryScoped<u8, Core::Memory::GuestMemoryFlags::UnsafeReadWrite> | 556 | Tegra::Memory::GpuGuestMemoryScoped<u8, |
| 557 | Tegra::Memory::GuestMemoryFlags::UnsafeReadWrite> | ||
| 556 | dst(gpu_memory, gpu_addr + guest_offset, subresource_size, &tmp_buffer); | 558 | dst(gpu_memory, gpu_addr + guest_offset, subresource_size, &tmp_buffer); |
| 557 | 559 | ||
| 558 | SwizzleTexture(dst, src, bytes_per_block, num_tiles.width, num_tiles.height, | 560 | SwizzleTexture(dst, src, bytes_per_block, num_tiles.width, num_tiles.height, |