diff options
Diffstat (limited to 'src/video_core/dma_pusher.cpp')
| -rw-r--r-- | src/video_core/dma_pusher.cpp | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index f2f96ac33..105b85a92 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/cityhash.h" | ||
| 5 | #include "common/microprofile.h" | 6 | #include "common/microprofile.h" |
| 6 | #include "core/core.h" | 7 | #include "core/core.h" |
| 7 | #include "core/memory.h" | 8 | #include "core/memory.h" |
| @@ -12,6 +13,20 @@ | |||
| 12 | 13 | ||
| 13 | namespace Tegra { | 14 | namespace Tegra { |
| 14 | 15 | ||
| 16 | void CommandList::RefreshIntegrityChecks(GPU& gpu) { | ||
| 17 | command_list_hashes.resize(command_lists.size()); | ||
| 18 | |||
| 19 | for (std::size_t index = 0; index < command_lists.size(); ++index) { | ||
| 20 | const CommandListHeader command_list_header = command_lists[index]; | ||
| 21 | std::vector<CommandHeader> command_headers(command_list_header.size); | ||
| 22 | gpu.MemoryManager().ReadBlockUnsafe(command_list_header.addr, command_headers.data(), | ||
| 23 | command_list_header.size * sizeof(u32)); | ||
| 24 | command_list_hashes[index] = | ||
| 25 | Common::CityHash64(reinterpret_cast<char*>(command_headers.data()), | ||
| 26 | command_list_header.size * sizeof(u32)); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 15 | DmaPusher::DmaPusher(Core::System& system, GPU& gpu) : gpu{gpu}, system{system} {} | 30 | DmaPusher::DmaPusher(Core::System& system, GPU& gpu) : gpu{gpu}, system{system} {} |
| 16 | 31 | ||
| 17 | DmaPusher::~DmaPusher() = default; | 32 | DmaPusher::~DmaPusher() = default; |
| @@ -45,32 +60,51 @@ bool DmaPusher::Step() { | |||
| 45 | return false; | 60 | return false; |
| 46 | } | 61 | } |
| 47 | 62 | ||
| 48 | const CommandList& command_list{dma_pushbuffer.front()}; | 63 | CommandList& command_list{dma_pushbuffer.front()}; |
| 49 | ASSERT_OR_EXECUTE(!command_list.empty(), { | ||
| 50 | // Somehow the command_list is empty, in order to avoid a crash | ||
| 51 | // We ignore it and assume its size is 0. | ||
| 52 | dma_pushbuffer.pop(); | ||
| 53 | dma_pushbuffer_subindex = 0; | ||
| 54 | return true; | ||
| 55 | }); | ||
| 56 | const CommandListHeader command_list_header{command_list[dma_pushbuffer_subindex++]}; | ||
| 57 | const GPUVAddr dma_get = command_list_header.addr; | ||
| 58 | |||
| 59 | if (dma_pushbuffer_subindex >= command_list.size()) { | ||
| 60 | // We've gone through the current list, remove it from the queue | ||
| 61 | dma_pushbuffer.pop(); | ||
| 62 | dma_pushbuffer_subindex = 0; | ||
| 63 | } | ||
| 64 | 64 | ||
| 65 | if (command_list_header.size == 0) { | 65 | ASSERT_OR_EXECUTE( |
| 66 | return true; | 66 | command_list.command_lists.size() || command_list.prefetch_command_list.size(), { |
| 67 | } | 67 | // Somehow the command_list is empty, in order to avoid a crash |
| 68 | // We ignore it and assume its size is 0. | ||
| 69 | dma_pushbuffer.pop(); | ||
| 70 | dma_pushbuffer_subindex = 0; | ||
| 71 | return true; | ||
| 72 | }); | ||
| 68 | 73 | ||
| 69 | // Push buffer non-empty, read a word | 74 | if (command_list.prefetch_command_list.size()) { |
| 70 | command_headers.resize(command_list_header.size); | 75 | // Prefetched command list from nvdrv, used for things like synchronization |
| 71 | gpu.MemoryManager().ReadBlockUnsafe(dma_get, command_headers.data(), | 76 | command_headers = std::move(command_list.prefetch_command_list); |
| 72 | command_list_header.size * sizeof(u32)); | 77 | dma_pushbuffer.pop(); |
| 78 | } else { | ||
| 79 | const CommandListHeader command_list_header{ | ||
| 80 | command_list.command_lists[dma_pushbuffer_subindex]}; | ||
| 81 | const u64 next_hash = command_list.command_list_hashes[dma_pushbuffer_subindex++]; | ||
| 82 | const GPUVAddr dma_get = command_list_header.addr; | ||
| 83 | |||
| 84 | if (dma_pushbuffer_subindex >= command_list.command_lists.size()) { | ||
| 85 | // We've gone through the current list, remove it from the queue | ||
| 86 | dma_pushbuffer.pop(); | ||
| 87 | dma_pushbuffer_subindex = 0; | ||
| 88 | } | ||
| 73 | 89 | ||
| 90 | if (command_list_header.size == 0) { | ||
| 91 | return true; | ||
| 92 | } | ||
| 93 | |||
| 94 | // Push buffer non-empty, read a word | ||
| 95 | command_headers.resize(command_list_header.size); | ||
| 96 | gpu.MemoryManager().ReadBlockUnsafe(dma_get, command_headers.data(), | ||
| 97 | command_list_header.size * sizeof(u32)); | ||
| 98 | |||
| 99 | // Integrity check | ||
| 100 | const u64 new_hash = Common::CityHash64(reinterpret_cast<char*>(command_headers.data()), | ||
| 101 | command_list_header.size * sizeof(u32)); | ||
| 102 | if (new_hash != next_hash) { | ||
| 103 | LOG_CRITICAL(HW_GPU, "CommandList at addr=0x{:X} is corrupt, skipping!", dma_get); | ||
| 104 | dma_pushbuffer.pop(); | ||
| 105 | return true; | ||
| 106 | } | ||
| 107 | } | ||
| 74 | for (std::size_t index = 0; index < command_headers.size();) { | 108 | for (std::size_t index = 0; index < command_headers.size();) { |
| 75 | const CommandHeader& command_header = command_headers[index]; | 109 | const CommandHeader& command_header = command_headers[index]; |
| 76 | 110 | ||