diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/memory.cpp | 81 | ||||
| -rw-r--r-- | src/core/memory.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 3 |
3 files changed, 22 insertions, 68 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 4fde53033..e0cc5175f 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "core/hle/lock.h" | 18 | #include "core/hle/lock.h" |
| 19 | #include "core/memory.h" | 19 | #include "core/memory.h" |
| 20 | #include "core/memory_setup.h" | 20 | #include "core/memory_setup.h" |
| 21 | #include "video_core/gpu.h" | ||
| 21 | #include "video_core/renderer_base.h" | 22 | #include "video_core/renderer_base.h" |
| 22 | 23 | ||
| 23 | namespace Memory { | 24 | namespace Memory { |
| @@ -69,8 +70,8 @@ static void MapPages(PageTable& page_table, VAddr base, u64 size, u8* memory, Pa | |||
| 69 | 70 | ||
| 70 | // During boot, current_page_table might not be set yet, in which case we need not flush | 71 | // During boot, current_page_table might not be set yet, in which case we need not flush |
| 71 | if (current_page_table) { | 72 | if (current_page_table) { |
| 72 | RasterizerFlushVirtualRegion(base << PAGE_BITS, size * PAGE_SIZE, | 73 | Core::System::GetInstance().GPU().FlushAndInvalidateRegion(base << PAGE_BITS, |
| 73 | FlushMode::FlushAndInvalidate); | 74 | size * PAGE_SIZE); |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | VAddr end = base + size; | 77 | VAddr end = base + size; |
| @@ -183,10 +184,10 @@ T Read(const VAddr vaddr) { | |||
| 183 | ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr); | 184 | ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr); |
| 184 | break; | 185 | break; |
| 185 | case PageType::RasterizerCachedMemory: { | 186 | case PageType::RasterizerCachedMemory: { |
| 186 | RasterizerFlushVirtualRegion(vaddr, sizeof(T), FlushMode::Flush); | 187 | auto host_ptr{GetPointerFromVMA(vaddr)}; |
| 187 | 188 | Core::System::GetInstance().GPU().FlushRegion(ToCacheAddr(host_ptr), sizeof(T)); | |
| 188 | T value; | 189 | T value; |
| 189 | std::memcpy(&value, GetPointerFromVMA(vaddr), sizeof(T)); | 190 | std::memcpy(&value, host_ptr, sizeof(T)); |
| 190 | return value; | 191 | return value; |
| 191 | } | 192 | } |
| 192 | default: | 193 | default: |
| @@ -214,8 +215,9 @@ void Write(const VAddr vaddr, const T data) { | |||
| 214 | ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr); | 215 | ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr); |
| 215 | break; | 216 | break; |
| 216 | case PageType::RasterizerCachedMemory: { | 217 | case PageType::RasterizerCachedMemory: { |
| 217 | RasterizerFlushVirtualRegion(vaddr, sizeof(T), FlushMode::Invalidate); | 218 | auto host_ptr{GetPointerFromVMA(vaddr)}; |
| 218 | std::memcpy(GetPointerFromVMA(vaddr), &data, sizeof(T)); | 219 | Core::System::GetInstance().GPU().InvalidateRegion(ToCacheAddr(host_ptr), sizeof(T)); |
| 220 | std::memcpy(host_ptr, &data, sizeof(T)); | ||
| 219 | break; | 221 | break; |
| 220 | } | 222 | } |
| 221 | default: | 223 | default: |
| @@ -338,47 +340,6 @@ void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) { | |||
| 338 | } | 340 | } |
| 339 | } | 341 | } |
| 340 | 342 | ||
| 341 | void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) { | ||
| 342 | auto& system_instance = Core::System::GetInstance(); | ||
| 343 | |||
| 344 | // Since pages are unmapped on shutdown after video core is shutdown, the renderer may be | ||
| 345 | // null here | ||
| 346 | if (!system_instance.IsPoweredOn()) { | ||
| 347 | return; | ||
| 348 | } | ||
| 349 | |||
| 350 | const VAddr end = start + size; | ||
| 351 | |||
| 352 | const auto CheckRegion = [&](VAddr region_start, VAddr region_end) { | ||
| 353 | if (start >= region_end || end <= region_start) { | ||
| 354 | // No overlap with region | ||
| 355 | return; | ||
| 356 | } | ||
| 357 | |||
| 358 | const VAddr overlap_start = std::max(start, region_start); | ||
| 359 | const VAddr overlap_end = std::min(end, region_end); | ||
| 360 | const VAddr overlap_size = overlap_end - overlap_start; | ||
| 361 | |||
| 362 | auto& gpu = system_instance.GPU(); | ||
| 363 | switch (mode) { | ||
| 364 | case FlushMode::Flush: | ||
| 365 | gpu.FlushRegion(ToCacheAddr(GetPointer(overlap_start)), overlap_size); | ||
| 366 | break; | ||
| 367 | case FlushMode::Invalidate: | ||
| 368 | gpu.InvalidateRegion(ToCacheAddr(GetPointer(overlap_start)), overlap_size); | ||
| 369 | break; | ||
| 370 | case FlushMode::FlushAndInvalidate: | ||
| 371 | gpu.FlushAndInvalidateRegion(ToCacheAddr(GetPointer(overlap_start)), overlap_size); | ||
| 372 | break; | ||
| 373 | } | ||
| 374 | }; | ||
| 375 | |||
| 376 | const auto& vm_manager = Core::CurrentProcess()->VMManager(); | ||
| 377 | |||
| 378 | CheckRegion(vm_manager.GetCodeRegionBaseAddress(), vm_manager.GetCodeRegionEndAddress()); | ||
| 379 | CheckRegion(vm_manager.GetHeapRegionBaseAddress(), vm_manager.GetHeapRegionEndAddress()); | ||
| 380 | } | ||
| 381 | |||
| 382 | u8 Read8(const VAddr addr) { | 343 | u8 Read8(const VAddr addr) { |
| 383 | return Read<u8>(addr); | 344 | return Read<u8>(addr); |
| 384 | } | 345 | } |
| @@ -424,9 +385,9 @@ void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_ | |||
| 424 | break; | 385 | break; |
| 425 | } | 386 | } |
| 426 | case PageType::RasterizerCachedMemory: { | 387 | case PageType::RasterizerCachedMemory: { |
| 427 | RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), | 388 | const auto& host_ptr{GetPointerFromVMA(process, current_vaddr)}; |
| 428 | FlushMode::Flush); | 389 | Core::System::GetInstance().GPU().FlushRegion(ToCacheAddr(host_ptr), copy_amount); |
| 429 | std::memcpy(dest_buffer, GetPointerFromVMA(process, current_vaddr), copy_amount); | 390 | std::memcpy(dest_buffer, host_ptr, copy_amount); |
| 430 | break; | 391 | break; |
| 431 | } | 392 | } |
| 432 | default: | 393 | default: |
| @@ -487,9 +448,9 @@ void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const voi | |||
| 487 | break; | 448 | break; |
| 488 | } | 449 | } |
| 489 | case PageType::RasterizerCachedMemory: { | 450 | case PageType::RasterizerCachedMemory: { |
| 490 | RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), | 451 | const auto& host_ptr{GetPointerFromVMA(process, current_vaddr)}; |
| 491 | FlushMode::Invalidate); | 452 | Core::System::GetInstance().GPU().InvalidateRegion(ToCacheAddr(host_ptr), copy_amount); |
| 492 | std::memcpy(GetPointerFromVMA(process, current_vaddr), src_buffer, copy_amount); | 453 | std::memcpy(host_ptr, src_buffer, copy_amount); |
| 493 | break; | 454 | break; |
| 494 | } | 455 | } |
| 495 | default: | 456 | default: |
| @@ -533,9 +494,9 @@ void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const std: | |||
| 533 | break; | 494 | break; |
| 534 | } | 495 | } |
| 535 | case PageType::RasterizerCachedMemory: { | 496 | case PageType::RasterizerCachedMemory: { |
| 536 | RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), | 497 | const auto& host_ptr{GetPointerFromVMA(process, current_vaddr)}; |
| 537 | FlushMode::Invalidate); | 498 | Core::System::GetInstance().GPU().InvalidateRegion(ToCacheAddr(host_ptr), copy_amount); |
| 538 | std::memset(GetPointerFromVMA(process, current_vaddr), 0, copy_amount); | 499 | std::memset(host_ptr, 0, copy_amount); |
| 539 | break; | 500 | break; |
| 540 | } | 501 | } |
| 541 | default: | 502 | default: |
| @@ -575,9 +536,9 @@ void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr, | |||
| 575 | break; | 536 | break; |
| 576 | } | 537 | } |
| 577 | case PageType::RasterizerCachedMemory: { | 538 | case PageType::RasterizerCachedMemory: { |
| 578 | RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), | 539 | const auto& host_ptr{GetPointerFromVMA(process, current_vaddr)}; |
| 579 | FlushMode::Flush); | 540 | Core::System::GetInstance().GPU().FlushRegion(ToCacheAddr(host_ptr), copy_amount); |
| 580 | WriteBlock(process, dest_addr, GetPointerFromVMA(process, current_vaddr), copy_amount); | 541 | WriteBlock(process, dest_addr, host_ptr, copy_amount); |
| 581 | break; | 542 | break; |
| 582 | } | 543 | } |
| 583 | default: | 544 | default: |
diff --git a/src/core/memory.h b/src/core/memory.h index 1acf5ce8c..c2c6643ee 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -161,10 +161,4 @@ enum class FlushMode { | |||
| 161 | */ | 161 | */ |
| 162 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached); | 162 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached); |
| 163 | 163 | ||
| 164 | /** | ||
| 165 | * Flushes and invalidates any externally cached rasterizer resources touching the given virtual | ||
| 166 | * address region. | ||
| 167 | */ | ||
| 168 | void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode); | ||
| 169 | |||
| 170 | } // namespace Memory | 164 | } // namespace Memory |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index b97576309..5e3d862c6 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -164,8 +164,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf | |||
| 164 | // Reset the screen info's display texture to its own permanent texture | 164 | // Reset the screen info's display texture to its own permanent texture |
| 165 | screen_info.display_texture = screen_info.texture.resource.handle; | 165 | screen_info.display_texture = screen_info.texture.resource.handle; |
| 166 | 166 | ||
| 167 | Memory::RasterizerFlushVirtualRegion(framebuffer_addr, size_in_bytes, | 167 | rasterizer->FlushRegion(ToCacheAddr(Memory::GetPointer(framebuffer_addr)), size_in_bytes); |
| 168 | Memory::FlushMode::Flush); | ||
| 169 | 168 | ||
| 170 | constexpr u32 linear_bpp = 4; | 169 | constexpr u32 linear_bpp = 4; |
| 171 | VideoCore::MortonCopyPixels128(VideoCore::MortonSwizzleMode::MortonToLinear, | 170 | VideoCore::MortonCopyPixels128(VideoCore::MortonSwizzleMode::MortonToLinear, |