mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-10-30 15:39:02 -05:00 
			
		
		
		
	video_core: Move command buffer loop.
This moves the hot loop into video_core. This refactoring shall reduce the CPU overhead of calling ProcessCommandList.
This commit is contained in:
		| @@ -69,57 +69,64 @@ void GPU::WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params) | ||||
|     } | ||||
| } | ||||
|  | ||||
| void GPU::ProcessCommandList(GPUVAddr address, u32 size) { | ||||
|     const boost::optional<VAddr> head_address = memory_manager->GpuToCpuAddress(address); | ||||
|     VAddr current_addr = *head_address; | ||||
|     while (current_addr < *head_address + size * sizeof(CommandHeader)) { | ||||
|         const CommandHeader header = {Memory::Read32(current_addr)}; | ||||
|         current_addr += sizeof(u32); | ||||
| MICROPROFILE_DEFINE(ProcessCommandLists, "GPU", "Execute command buffer", MP_RGB(128, 128, 192)); | ||||
|  | ||||
|         switch (header.mode.Value()) { | ||||
|         case SubmissionMode::IncreasingOld: | ||||
|         case SubmissionMode::Increasing: { | ||||
|             // Increase the method value with each argument. | ||||
|             for (unsigned i = 0; i < header.arg_count; ++i) { | ||||
|                 WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr), | ||||
|                          header.arg_count - i - 1); | ||||
|                 current_addr += sizeof(u32); | ||||
|             } | ||||
|             break; | ||||
|         } | ||||
|         case SubmissionMode::NonIncreasingOld: | ||||
|         case SubmissionMode::NonIncreasing: { | ||||
|             // Use the same method value for all arguments. | ||||
|             for (unsigned i = 0; i < header.arg_count; ++i) { | ||||
|                 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr), | ||||
|                          header.arg_count - i - 1); | ||||
|                 current_addr += sizeof(u32); | ||||
|             } | ||||
|             break; | ||||
|         } | ||||
|         case SubmissionMode::IncreaseOnce: { | ||||
|             ASSERT(header.arg_count.Value() >= 1); | ||||
|  | ||||
|             // Use the original method for the first argument and then the next method for all other | ||||
|             // arguments. | ||||
|             WriteReg(header.method, header.subchannel, Memory::Read32(current_addr), | ||||
|                      header.arg_count - 1); | ||||
| void GPU::ProcessCommandLists(const std::vector<CommandListHeader>& commands) { | ||||
|     MICROPROFILE_SCOPE(ProcessCommandLists); | ||||
|     for (auto entry : commands) { | ||||
|         Tegra::GPUVAddr address = entry.Address(); | ||||
|         u32 size = entry.sz; | ||||
|         const boost::optional<VAddr> head_address = memory_manager->GpuToCpuAddress(address); | ||||
|         VAddr current_addr = *head_address; | ||||
|         while (current_addr < *head_address + size * sizeof(CommandHeader)) { | ||||
|             const CommandHeader header = {Memory::Read32(current_addr)}; | ||||
|             current_addr += sizeof(u32); | ||||
|  | ||||
|             for (unsigned i = 1; i < header.arg_count; ++i) { | ||||
|                 WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr), | ||||
|                          header.arg_count - i - 1); | ||||
|                 current_addr += sizeof(u32); | ||||
|             switch (header.mode.Value()) { | ||||
|             case SubmissionMode::IncreasingOld: | ||||
|             case SubmissionMode::Increasing: { | ||||
|                 // Increase the method value with each argument. | ||||
|                 for (unsigned i = 0; i < header.arg_count; ++i) { | ||||
|                     WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr), | ||||
|                              header.arg_count - i - 1); | ||||
|                     current_addr += sizeof(u32); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case SubmissionMode::NonIncreasingOld: | ||||
|             case SubmissionMode::NonIncreasing: { | ||||
|                 // Use the same method value for all arguments. | ||||
|                 for (unsigned i = 0; i < header.arg_count; ++i) { | ||||
|                     WriteReg(header.method, header.subchannel, Memory::Read32(current_addr), | ||||
|                              header.arg_count - i - 1); | ||||
|                     current_addr += sizeof(u32); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case SubmissionMode::IncreaseOnce: { | ||||
|                 ASSERT(header.arg_count.Value() >= 1); | ||||
|  | ||||
|                 // Use the original method for the first argument and then the next method for all | ||||
|                 // other arguments. | ||||
|                 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr), | ||||
|                          header.arg_count - 1); | ||||
|                 current_addr += sizeof(u32); | ||||
|  | ||||
|                 for (unsigned i = 1; i < header.arg_count; ++i) { | ||||
|                     WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr), | ||||
|                              header.arg_count - i - 1); | ||||
|                     current_addr += sizeof(u32); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case SubmissionMode::Inline: { | ||||
|                 // The register value is stored in the bits 16-28 as an immediate | ||||
|                 WriteReg(header.method, header.subchannel, header.inline_data, 0); | ||||
|                 break; | ||||
|             } | ||||
|             default: | ||||
|                 UNIMPLEMENTED(); | ||||
|             } | ||||
|             break; | ||||
|         } | ||||
|         case SubmissionMode::Inline: { | ||||
|             // The register value is stored in the bits 16-28 as an immediate | ||||
|             WriteReg(header.method, header.subchannel, header.inline_data, 0); | ||||
|             break; | ||||
|         } | ||||
|         default: | ||||
|             UNIMPLEMENTED(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| #include <type_traits> | ||||
| #include "common/bit_field.h" | ||||
| #include "common/common_types.h" | ||||
| #include "video_core/memory_manager.h" | ||||
|  | ||||
| namespace Tegra { | ||||
|  | ||||
| @@ -19,6 +20,22 @@ enum class SubmissionMode : u32 { | ||||
|     IncreaseOnce = 5 | ||||
| }; | ||||
|  | ||||
| struct CommandListHeader { | ||||
|     u32 entry0; // gpu_va_lo | ||||
|     union { | ||||
|         u32 entry1; // gpu_va_hi | (unk_0x02 << 0x08) | (size << 0x0A) | (unk_0x01 << 0x1F) | ||||
|         BitField<0, 8, u32> gpu_va_hi; | ||||
|         BitField<8, 2, u32> unk1; | ||||
|         BitField<10, 21, u32> sz; | ||||
|         BitField<31, 1, u32> unk2; | ||||
|     }; | ||||
|  | ||||
|     GPUVAddr Address() const { | ||||
|         return (static_cast<GPUVAddr>(gpu_va_hi) << 32) | entry0; | ||||
|     } | ||||
| }; | ||||
| static_assert(sizeof(CommandListHeader) == 8, "CommandListHeader is incorrect size"); | ||||
|  | ||||
| union CommandHeader { | ||||
|     u32 hex; | ||||
|  | ||||
|   | ||||
| @@ -6,6 +6,7 @@ | ||||
|  | ||||
| #include <array> | ||||
| #include <memory> | ||||
| #include <vector> | ||||
| #include "common/common_types.h" | ||||
| #include "core/hle/service/nvflinger/buffer_queue.h" | ||||
| #include "video_core/memory_manager.h" | ||||
| @@ -67,6 +68,7 @@ u32 RenderTargetBytesPerPixel(RenderTargetFormat format); | ||||
| /// Returns the number of bytes per pixel of each depth format. | ||||
| u32 DepthFormatBytesPerPixel(DepthFormat format); | ||||
|  | ||||
| struct CommandListHeader; | ||||
| class DebugContext; | ||||
|  | ||||
| /** | ||||
| @@ -115,7 +117,7 @@ public: | ||||
|     ~GPU(); | ||||
|  | ||||
|     /// Processes a command list stored at the specified address in GPU memory. | ||||
|     void ProcessCommandList(GPUVAddr address, u32 size); | ||||
|     void ProcessCommandLists(const std::vector<CommandListHeader>& commands); | ||||
|  | ||||
|     /// Returns a reference to the Maxwell3D GPU engine. | ||||
|     Engines::Maxwell3D& Maxwell3D(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Markus Wick
					Markus Wick