summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-02-11 21:34:20 -0500
committerGravatar Subv2018-02-11 22:42:48 -0500
commite01a8f218707b6f3ed0f111c432440b07ea5b6ff (patch)
treef5a95dc16a129a5c1a8a4d1309dfbbc3e4ccdb3f /src
parentnvdrv: Make the GPU memory manager available to nvhost-gpu. (diff)
downloadyuzu-e01a8f218707b6f3ed0f111c432440b07ea5b6ff.tar.gz
yuzu-e01a8f218707b6f3ed0f111c432440b07ea5b6ff.tar.xz
yuzu-e01a8f218707b6f3ed0f111c432440b07ea5b6ff.zip
GPU: Added a command processor to decode the GPU pushbuffers and forward the commands to their respective engines.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.h2
-rw-r--r--src/video_core/CMakeLists.txt8
-rw-r--r--src/video_core/command_processor.cpp130
-rw-r--r--src/video_core/command_processor.h43
-rw-r--r--src/video_core/engines/fermi_2d.cpp15
-rw-r--r--src/video_core/engines/fermi_2d.h18
-rw-r--r--src/video_core/engines/maxwell_3d.cpp15
-rw-r--r--src/video_core/engines/maxwell_3d.h18
-rw-r--r--src/video_core/engines/maxwell_compute.cpp15
-rw-r--r--src/video_core/engines/maxwell_compute.h18
12 files changed, 285 insertions, 3 deletions
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
index 44ffddcd9..301a8a79f 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
@@ -21,7 +21,7 @@ class nvmap;
21class nvhost_as_gpu final : public nvdevice { 21class nvhost_as_gpu final : public nvdevice {
22public: 22public:
23 nvhost_as_gpu(std::shared_ptr<nvmap> nvmap_dev, std::shared_ptr<MemoryManager> memory_manager) 23 nvhost_as_gpu(std::shared_ptr<nvmap> nvmap_dev, std::shared_ptr<MemoryManager> memory_manager)
24 : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} 24 : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {}
25 ~nvhost_as_gpu() override = default; 25 ~nvhost_as_gpu() override = default;
26 26
27 u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override; 27 u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override;
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
index 229048d37..1c3079889 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -6,6 +6,7 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/hle/service/nvdrv/devices/nvhost_gpu.h" 8#include "core/hle/service/nvdrv/devices/nvhost_gpu.h"
9#include "video_core/command_processor.h"
9 10
10namespace Service { 11namespace Service {
11namespace Nvidia { 12namespace Nvidia {
@@ -130,7 +131,8 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector<u8>& input, std::vector<u8>& outp
130 std::memcpy(&entries[0], &input.data()[sizeof(IoctlSubmitGpfifo)], 131 std::memcpy(&entries[0], &input.data()[sizeof(IoctlSubmitGpfifo)],
131 params.num_entries * sizeof(IoctlGpfifoEntry)); 132 params.num_entries * sizeof(IoctlGpfifoEntry));
132 for (auto entry : entries) { 133 for (auto entry : entries) {
133 VAddr va_addr = entry.Address(); 134 VAddr va_addr = memory_manager->PhysicalToVirtualAddress(entry.Address());
135 Tegra::CommandProcessor::ProcessCommandList(va_addr, entry.sz);
134 // TODO(ogniK): Process these 136 // TODO(ogniK): Process these
135 } 137 }
136 params.fence_out.id = 0; 138 params.fence_out.id = 0;
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h
index 5b40eaa88..6f9b90b05 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h
@@ -22,7 +22,7 @@ constexpr u32 NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO(0x8);
22class nvhost_gpu final : public nvdevice { 22class nvhost_gpu final : public nvdevice {
23public: 23public:
24 nvhost_gpu(std::shared_ptr<nvmap> nvmap_dev, std::shared_ptr<MemoryManager> memory_manager) 24 nvhost_gpu(std::shared_ptr<nvmap> nvmap_dev, std::shared_ptr<MemoryManager> memory_manager)
25 : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} 25 : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {}
26 ~nvhost_gpu() override = default; 26 ~nvhost_gpu() override = default;
27 27
28 u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override; 28 u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override;
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 69f2b4afd..70728d2f6 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -1,4 +1,12 @@
1add_library(video_core STATIC 1add_library(video_core STATIC
2 command_processor.cpp
3 command_processor.h
4 engines/fermi_2d.cpp
5 engines/fermi_2d.h
6 engines/maxwell_3d.cpp
7 engines/maxwell_3d.h
8 engines/maxwell_compute.cpp
9 engines/maxwell_compute.h
2 renderer_base.cpp 10 renderer_base.cpp
3 renderer_base.h 11 renderer_base.h
4 renderer_opengl/gl_resource_manager.h 12 renderer_opengl/gl_resource_manager.h
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
new file mode 100644
index 000000000..e1df875e7
--- /dev/null
+++ b/src/video_core/command_processor.cpp
@@ -0,0 +1,130 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <array>
6#include <cstddef>
7#include <memory>
8#include <utility>
9#include "common/assert.h"
10#include "common/logging/log.h"
11#include "common/microprofile.h"
12#include "common/vector_math.h"
13#include "core/memory.h"
14#include "core/tracer/recorder.h"
15#include "video_core/command_processor.h"
16#include "video_core/engines/fermi_2d.h"
17#include "video_core/engines/maxwell_3d.h"
18#include "video_core/engines/maxwell_compute.h"
19#include "video_core/renderer_base.h"
20#include "video_core/video_core.h"
21
22namespace Tegra {
23
24namespace CommandProcessor {
25
26enum class BufferMethods {
27 BindObject = 0,
28 CountBufferMethods = 0x100,
29};
30
31enum class EngineID {
32 FERMI_TWOD_A = 0x902D, // 2D Engine
33 MAXWELL_B = 0xB197, // 3D Engine
34 MAXWELL_COMPUTE_B = 0xB1C0,
35 KEPLER_INLINE_TO_MEMORY_B = 0xA140,
36 MAXWELL_DMA_COPY_A = 0xB0B5,
37};
38
39// Mapping of subchannels to their bound engine ids.
40static std::unordered_map<u32, EngineID> bound_engines;
41
42static void WriteReg(u32 method, u32 subchannel, u32 value) {
43 LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u value %08X", method, subchannel,
44 value);
45
46 if (method == static_cast<u32>(BufferMethods::BindObject)) {
47 // Bind the current subchannel to the desired engine id.
48 LOG_DEBUG(HW_GPU, "Binding subchannel %u to engine %u", subchannel, value);
49 ASSERT(bound_engines.find(subchannel) == bound_engines.end());
50 bound_engines[subchannel] = static_cast<EngineID>(value);
51 return;
52 }
53
54 if (method < static_cast<u32>(BufferMethods::CountBufferMethods)) {
55 // TODO(Subv): Research and implement these methods.
56 LOG_ERROR(HW_GPU, "Special buffer methods other than Bind are not implemented");
57 return;
58 }
59
60 ASSERT(bound_engines.find(subchannel) != bound_engines.end());
61
62 const EngineID engine = bound_engines[subchannel];
63
64 switch (engine) {
65 case EngineID::FERMI_TWOD_A:
66 Engines::Fermi2D::WriteReg(method, value);
67 break;
68 case EngineID::MAXWELL_B:
69 Engines::Maxwell3D::WriteReg(method, value);
70 break;
71 case EngineID::MAXWELL_COMPUTE_B:
72 Engines::MaxwellCompute::WriteReg(method, value);
73 break;
74 default:
75 UNIMPLEMENTED();
76 }
77}
78
79void ProcessCommandList(VAddr address, u32 size) {
80 VAddr current_addr = address;
81 while (current_addr < address + size * sizeof(CommandHeader)) {
82 const CommandHeader header = {Memory::Read32(current_addr)};
83 current_addr += sizeof(u32);
84
85 switch (header.mode.Value()) {
86 case SubmissionMode::IncreasingOld:
87 case SubmissionMode::Increasing: {
88 // Increase the method value with each argument.
89 for (unsigned i = 0; i < header.arg_count; ++i) {
90 WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr));
91 current_addr += sizeof(u32);
92 }
93 break;
94 }
95 case SubmissionMode::NonIncreasingOld:
96 case SubmissionMode::NonIncreasing: {
97 // Use the same method value for all arguments.
98 for (unsigned i = 0; i < header.arg_count; ++i) {
99 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr));
100 current_addr += sizeof(u32);
101 }
102 break;
103 }
104 case SubmissionMode::IncreaseOnce: {
105 ASSERT(header.arg_count.Value() >= 1);
106 // Use the original method for the first argument and then the next method for all other
107 // arguments.
108 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr));
109 current_addr += sizeof(u32);
110 // Use the same method value for all arguments.
111 for (unsigned i = 1; i < header.arg_count; ++i) {
112 WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr));
113 current_addr += sizeof(u32);
114 }
115 break;
116 }
117 case SubmissionMode::Inline: {
118 // The register value is stored in the bits 16-28 as an immediate
119 WriteReg(header.method, header.subchannel, header.inline_data);
120 break;
121 }
122 default:
123 UNIMPLEMENTED();
124 }
125 }
126}
127
128} // namespace CommandProcessor
129
130} // namespace Tegra
diff --git a/src/video_core/command_processor.h b/src/video_core/command_processor.h
new file mode 100644
index 000000000..90e64629e
--- /dev/null
+++ b/src/video_core/command_processor.h
@@ -0,0 +1,43 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <type_traits>
8#include "common/bit_field.h"
9#include "common/common_types.h"
10
11namespace Tegra {
12
13namespace CommandProcessor {
14
15enum class SubmissionMode : u32 {
16 IncreasingOld = 0,
17 Increasing = 1,
18 NonIncreasingOld = 2,
19 NonIncreasing = 3,
20 Inline = 4,
21 IncreaseOnce = 5
22};
23
24union CommandHeader {
25 u32 hex;
26
27 BitField<0, 13, u32> method;
28 BitField<13, 3, u32> subchannel;
29
30 BitField<16, 13, u32> arg_count;
31 BitField<16, 13, u32> inline_data;
32
33 BitField<29, 3, SubmissionMode> mode;
34};
35static_assert(std::is_standard_layout<CommandHeader>::value == true,
36 "CommandHeader does not use standard layout");
37static_assert(sizeof(CommandHeader) == sizeof(u32), "CommandHeader has incorrect size!");
38
39void ProcessCommandList(VAddr address, u32 size);
40
41} // namespace CommandProcessor
42
43} // namespace Tegra
diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp
new file mode 100644
index 000000000..3d62c321f
--- /dev/null
+++ b/src/video_core/engines/fermi_2d.cpp
@@ -0,0 +1,15 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "video_core/engines/fermi_2d.h"
6
7namespace Tegra {
8namespace Engines {
9namespace Fermi2D {
10
11void WriteReg(u32 method, u32 value) {}
12
13} // namespace Fermi2D
14} // namespace Engines
15} // namespace Tegra
diff --git a/src/video_core/engines/fermi_2d.h b/src/video_core/engines/fermi_2d.h
new file mode 100644
index 000000000..6f3f5dfbc
--- /dev/null
+++ b/src/video_core/engines/fermi_2d.h
@@ -0,0 +1,18 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Tegra {
10namespace Engines {
11namespace Fermi2D {
12
13void WriteReg(u32 method, u32 value);
14
15} // namespace Fermi2D
16
17} // namespace Engines
18} // namespace Tegra
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
new file mode 100644
index 000000000..c2697c960
--- /dev/null
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -0,0 +1,15 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "video_core/engines/maxwell_3d.h"
6
7namespace Tegra {
8namespace Engines {
9namespace Maxwell3D {
10
11void WriteReg(u32 method, u32 value) {}
12
13} // namespace Maxwell3D
14} // namespace Engines
15} // namespace Tegra
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
new file mode 100644
index 000000000..6957fb721
--- /dev/null
+++ b/src/video_core/engines/maxwell_3d.h
@@ -0,0 +1,18 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Tegra {
10namespace Engines {
11namespace Maxwell3D {
12
13void WriteReg(u32 method, u32 value);
14
15} // namespace Maxwell3D
16
17} // namespace Engines
18} // namespace Tegra
diff --git a/src/video_core/engines/maxwell_compute.cpp b/src/video_core/engines/maxwell_compute.cpp
new file mode 100644
index 000000000..c2134d63b
--- /dev/null
+++ b/src/video_core/engines/maxwell_compute.cpp
@@ -0,0 +1,15 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "video_core/engines/maxwell_compute.h"
6
7namespace Tegra {
8namespace Engines {
9namespace MaxwellCompute {
10
11void WriteReg(u32 method, u32 value) {}
12
13} // namespace MaxwellCompute
14} // namespace Engines
15} // namespace Tegra
diff --git a/src/video_core/engines/maxwell_compute.h b/src/video_core/engines/maxwell_compute.h
new file mode 100644
index 000000000..dc9a13593
--- /dev/null
+++ b/src/video_core/engines/maxwell_compute.h
@@ -0,0 +1,18 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Tegra {
10namespace Engines {
11namespace MaxwellCompute {
12
13void WriteReg(u32 method, u32 value);
14
15} // namespace MaxwellCompute
16
17} // namespace Engines
18} // namespace Tegra