summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/hle/service/nvdrv/core/container.cpp8
-rw-r--r--src/core/hle/service/nvdrv/core/container.h10
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.cpp33
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.h18
-rw-r--r--src/core/hle/service/nvdrv/core/syncpoint_manager.cpp6
-rw-r--r--src/core/hle/service/nvdrv/core/syncpoint_manager.h12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp37
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp2
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/cdma_pusher.cpp12
-rw-r--r--src/video_core/cdma_pusher.h7
-rw-r--r--src/video_core/gpu.cpp27
-rw-r--r--src/video_core/gpu.h6
-rw-r--r--src/video_core/host1x/codecs/codec.cpp10
-rw-r--r--src/video_core/host1x/codecs/codec.h9
-rw-r--r--src/video_core/host1x/codecs/h264.cpp13
-rw-r--r--src/video_core/host1x/codecs/h264.h10
-rw-r--r--src/video_core/host1x/codecs/vp8.cpp8
-rw-r--r--src/video_core/host1x/codecs/vp8.h10
-rw-r--r--src/video_core/host1x/codecs/vp9.cpp12
-rw-r--r--src/video_core/host1x/codecs/vp9.h10
-rw-r--r--src/video_core/host1x/codecs/vp9_types.h1
-rw-r--r--src/video_core/host1x/control.cpp5
-rw-r--r--src/video_core/host1x/control.h6
-rw-r--r--src/video_core/host1x/host1x.cpp18
-rw-r--r--src/video_core/host1x/host1x.h27
-rw-r--r--src/video_core/host1x/nvdec.cpp5
-rw-r--r--src/video_core/host1x/nvdec.h7
-rw-r--r--src/video_core/host1x/sync_manager.cpp5
-rw-r--r--src/video_core/host1x/sync_manager.h8
-rw-r--r--src/video_core/host1x/vic.cpp22
-rw-r--r--src/video_core/host1x/vic.h6
33 files changed, 201 insertions, 173 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index fa059a394..13d02e75f 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -216,7 +216,7 @@ struct System::Impl {
216 216
217 telemetry_session = std::make_unique<Core::TelemetrySession>(); 217 telemetry_session = std::make_unique<Core::TelemetrySession>();
218 218
219 host1x_core = std::make_unique<Tegra::Host1x::Host1x>(); 219 host1x_core = std::make_unique<Tegra::Host1x::Host1x>(system);
220 gpu_core = VideoCore::CreateGPU(emu_window, system); 220 gpu_core = VideoCore::CreateGPU(emu_window, system);
221 if (!gpu_core) { 221 if (!gpu_core) {
222 return SystemResultStatus::ErrorVideoCore; 222 return SystemResultStatus::ErrorVideoCore;
diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp
index 97b5b2c86..fbd66f001 100644
--- a/src/core/hle/service/nvdrv/core/container.cpp
+++ b/src/core/hle/service/nvdrv/core/container.cpp
@@ -6,18 +6,18 @@
6#include "core/hle/service/nvdrv/core/container.h" 6#include "core/hle/service/nvdrv/core/container.h"
7#include "core/hle/service/nvdrv/core/nvmap.h" 7#include "core/hle/service/nvdrv/core/nvmap.h"
8#include "core/hle/service/nvdrv/core/syncpoint_manager.h" 8#include "core/hle/service/nvdrv/core/syncpoint_manager.h"
9#include "video_core/gpu.h" 9#include "video_core/host1x/host1x.h"
10 10
11namespace Service::Nvidia::NvCore { 11namespace Service::Nvidia::NvCore {
12 12
13struct ContainerImpl { 13struct ContainerImpl {
14 ContainerImpl(Tegra::GPU& gpu_) : file{}, manager{gpu_} {} 14 ContainerImpl(Tegra::Host1x::Host1x& host1x_) : file{host1x_}, manager{host1x_} {}
15 NvMap file; 15 NvMap file;
16 SyncpointManager manager; 16 SyncpointManager manager;
17}; 17};
18 18
19Container::Container(Tegra::GPU& gpu_) { 19Container::Container(Tegra::Host1x::Host1x& host1x_) {
20 impl = std::make_unique<ContainerImpl>(gpu_); 20 impl = std::make_unique<ContainerImpl>(host1x_);
21} 21}
22 22
23Container::~Container() = default; 23Container::~Container() = default;
diff --git a/src/core/hle/service/nvdrv/core/container.h b/src/core/hle/service/nvdrv/core/container.h
index 91ac2305a..da75d74ff 100644
--- a/src/core/hle/service/nvdrv/core/container.h
+++ b/src/core/hle/service/nvdrv/core/container.h
@@ -8,8 +8,12 @@
8#include <memory> 8#include <memory>
9 9
10namespace Tegra { 10namespace Tegra {
11class GPU; 11
12} 12namespace Host1x {
13class Host1x;
14} // namespace Host1x
15
16} // namespace Tegra
13 17
14namespace Service::Nvidia::NvCore { 18namespace Service::Nvidia::NvCore {
15 19
@@ -20,7 +24,7 @@ struct ContainerImpl;
20 24
21class Container { 25class Container {
22public: 26public:
23 Container(Tegra::GPU& gpu_); 27 Container(Tegra::Host1x::Host1x& host1x);
24 ~Container(); 28 ~Container();
25 29
26 NvMap& GetNvMapFile(); 30 NvMap& GetNvMapFile();
diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp
index 1126daeb5..9acec7ba6 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/core/nvmap.cpp
@@ -7,6 +7,7 @@
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/hle/service/nvdrv/core/nvmap.h" 8#include "core/hle/service/nvdrv/core/nvmap.h"
9#include "core/memory.h" 9#include "core/memory.h"
10#include "video_core/host1x/host1x.h"
10 11
11using Core::Memory::YUZU_PAGESIZE; 12using Core::Memory::YUZU_PAGESIZE;
12 13
@@ -61,7 +62,7 @@ NvResult NvMap::Handle::Duplicate(bool internal_session) {
61 return NvResult::Success; 62 return NvResult::Success;
62} 63}
63 64
64NvMap::NvMap() = default; 65NvMap::NvMap(Tegra::Host1x::Host1x& host1x_) : host1x{host1x_} {}
65 66
66void NvMap::AddHandle(std::shared_ptr<Handle> handle_description) { 67void NvMap::AddHandle(std::shared_ptr<Handle> handle_description) {
67 std::scoped_lock lock(handles_lock); 68 std::scoped_lock lock(handles_lock);
@@ -77,12 +78,11 @@ void NvMap::UnmapHandle(Handle& handle_description) {
77 } 78 }
78 79
79 // Free and unmap the handle from the SMMU 80 // Free and unmap the handle from the SMMU
80 /* 81 host1x.MemoryManager().Unmap(static_cast<GPUVAddr>(handle_description.pin_virt_address),
81 state.soc->smmu.Unmap(handle_description.pin_virt_address, 82 handle_description.aligned_size);
82 static_cast<u32>(handle_description.aligned_size)); 83 host1x.Allocator().Free(handle_description.pin_virt_address,
83 smmuAllocator.Free(handle_description.pin_virt_address, 84 static_cast<u32>(handle_description.aligned_size));
84 static_cast<u32>(handle_description.aligned_size)); handle_description.pin_virt_address = 0; 85 handle_description.pin_virt_address = 0;
85 */
86} 86}
87 87
88bool NvMap::TryRemoveHandle(const Handle& handle_description) { 88bool NvMap::TryRemoveHandle(const Handle& handle_description) {
@@ -131,12 +131,9 @@ VAddr NvMap::GetHandleAddress(Handle::Id handle) {
131} 131}
132 132
133u32 NvMap::PinHandle(NvMap::Handle::Id handle) { 133u32 NvMap::PinHandle(NvMap::Handle::Id handle) {
134 UNIMPLEMENTED_MSG("pinning");
135 return 0;
136 /*
137 auto handle_description{GetHandle(handle)}; 134 auto handle_description{GetHandle(handle)};
138 if (!handle_description) 135 if (!handle_description) [[unlikely]]
139 [[unlikely]] return 0; 136 return 0;
140 137
141 std::scoped_lock lock(handle_description->mutex); 138 std::scoped_lock lock(handle_description->mutex);
142 if (!handle_description->pins) { 139 if (!handle_description->pins) {
@@ -157,8 +154,10 @@ u32 NvMap::PinHandle(NvMap::Handle::Id handle) {
157 154
158 // If not then allocate some space and map it 155 // If not then allocate some space and map it
159 u32 address{}; 156 u32 address{};
157 auto& smmu_allocator = host1x.Allocator();
158 auto& smmu_memory_manager = host1x.MemoryManager();
160 while (!(address = 159 while (!(address =
161 smmuAllocator.Allocate(static_cast<u32>(handle_description->aligned_size)))) { 160 smmu_allocator.Allocate(static_cast<u32>(handle_description->aligned_size)))) {
162 // Free handles until the allocation succeeds 161 // Free handles until the allocation succeeds
163 std::scoped_lock queueLock(unmap_queue_lock); 162 std::scoped_lock queueLock(unmap_queue_lock);
164 if (auto freeHandleDesc{unmap_queue.front()}) { 163 if (auto freeHandleDesc{unmap_queue.front()}) {
@@ -172,19 +171,16 @@ u32 NvMap::PinHandle(NvMap::Handle::Id handle) {
172 } 171 }
173 } 172 }
174 173
175 state.soc->smmu.Map(address, handle_description->GetPointer(), 174 smmu_memory_manager.Map(static_cast<GPUVAddr>(address), handle_description->address,
176 static_cast<u32>(handle_description->aligned_size)); 175 handle_description->aligned_size);
177 handle_description->pin_virt_address = address; 176 handle_description->pin_virt_address = address;
178 } 177 }
179 178
180 handle_description->pins++; 179 handle_description->pins++;
181 return handle_description->pin_virt_address; 180 return handle_description->pin_virt_address;
182 */
183} 181}
184 182
185void NvMap::UnpinHandle(Handle::Id handle) { 183void NvMap::UnpinHandle(Handle::Id handle) {
186 UNIMPLEMENTED_MSG("Unpinning");
187 /*
188 auto handle_description{GetHandle(handle)}; 184 auto handle_description{GetHandle(handle)};
189 if (!handle_description) 185 if (!handle_description)
190 return; 186 return;
@@ -199,7 +195,6 @@ void NvMap::UnpinHandle(Handle::Id handle) {
199 unmap_queue.push_back(handle_description); 195 unmap_queue.push_back(handle_description);
200 handle_description->unmap_queue_entry = std::prev(unmap_queue.end()); 196 handle_description->unmap_queue_entry = std::prev(unmap_queue.end());
201 } 197 }
202 */
203} 198}
204 199
205std::optional<NvMap::FreeInfo> NvMap::FreeHandle(Handle::Id handle, bool internal_session) { 200std::optional<NvMap::FreeInfo> NvMap::FreeHandle(Handle::Id handle, bool internal_session) {
diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h
index 5e6c73589..5acdc961e 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.h
+++ b/src/core/hle/service/nvdrv/core/nvmap.h
@@ -15,6 +15,14 @@
15#include "common/common_types.h" 15#include "common/common_types.h"
16#include "core/hle/service/nvdrv/nvdata.h" 16#include "core/hle/service/nvdrv/nvdata.h"
17 17
18namespace Tegra {
19
20namespace Host1x {
21class Host1x;
22} // namespace Host1x
23
24} // namespace Tegra
25
18namespace Service::Nvidia::NvCore { 26namespace Service::Nvidia::NvCore {
19/** 27/**
20 * @brief The nvmap core class holds the global state for nvmap and provides methods to manage 28 * @brief The nvmap core class holds the global state for nvmap and provides methods to manage
@@ -90,15 +98,17 @@ public:
90 }; 98 };
91 99
92private: 100private:
93 std::list<std::shared_ptr<Handle>> unmap_queue; 101 std::list<std::shared_ptr<Handle>> unmap_queue{};
94 std::mutex unmap_queue_lock; //!< Protects access to `unmap_queue` 102 std::mutex unmap_queue_lock{}; //!< Protects access to `unmap_queue`
95 103
96 std::unordered_map<Handle::Id, std::shared_ptr<Handle>> handles; //!< Main owning map of handles 104 std::unordered_map<Handle::Id, std::shared_ptr<Handle>>
105 handles{}; //!< Main owning map of handles
97 std::mutex handles_lock; //!< Protects access to `handles` 106 std::mutex handles_lock; //!< Protects access to `handles`
98 107
99 static constexpr u32 HandleIdIncrement{ 108 static constexpr u32 HandleIdIncrement{
100 4}; //!< Each new handle ID is an increment of 4 from the previous 109 4}; //!< Each new handle ID is an increment of 4 from the previous
101 std::atomic<u32> next_handle_id{HandleIdIncrement}; 110 std::atomic<u32> next_handle_id{HandleIdIncrement};
111 Tegra::Host1x::Host1x& host1x;
102 112
103 void AddHandle(std::shared_ptr<Handle> handle); 113 void AddHandle(std::shared_ptr<Handle> handle);
104 114
@@ -125,7 +135,7 @@ public:
125 bool was_uncached; //!< If the handle was allocated as uncached 135 bool was_uncached; //!< If the handle was allocated as uncached
126 }; 136 };
127 137
128 NvMap(); 138 NvMap(Tegra::Host1x::Host1x& host1x);
129 139
130 /** 140 /**
131 * @brief Creates an unallocated handle of the given size 141 * @brief Creates an unallocated handle of the given size
diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
index ff6cbb37e..61e00448c 100644
--- a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
+++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
@@ -3,16 +3,16 @@
3 3
4#include "common/assert.h" 4#include "common/assert.h"
5#include "core/hle/service/nvdrv/core/syncpoint_manager.h" 5#include "core/hle/service/nvdrv/core/syncpoint_manager.h"
6#include "video_core/gpu.h" 6#include "video_core/host1x/host1x.h"
7 7
8namespace Service::Nvidia::NvCore { 8namespace Service::Nvidia::NvCore {
9 9
10SyncpointManager::SyncpointManager(Tegra::GPU& gpu_) : gpu{gpu_} {} 10SyncpointManager::SyncpointManager(Tegra::Host1x::Host1x& host1x_) : host1x{host1x_} {}
11 11
12SyncpointManager::~SyncpointManager() = default; 12SyncpointManager::~SyncpointManager() = default;
13 13
14u32 SyncpointManager::RefreshSyncpoint(u32 syncpoint_id) { 14u32 SyncpointManager::RefreshSyncpoint(u32 syncpoint_id) {
15 syncpoints[syncpoint_id].min = gpu.GetSyncpointValue(syncpoint_id); 15 syncpoints[syncpoint_id].min = host1x.GetSyncpointManager().GetHostSyncpointValue(syncpoint_id);
16 return GetSyncpointMin(syncpoint_id); 16 return GetSyncpointMin(syncpoint_id);
17} 17}
18 18
diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.h b/src/core/hle/service/nvdrv/core/syncpoint_manager.h
index cf7f0b4be..f332edc6e 100644
--- a/src/core/hle/service/nvdrv/core/syncpoint_manager.h
+++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.h
@@ -10,14 +10,18 @@
10#include "core/hle/service/nvdrv/nvdata.h" 10#include "core/hle/service/nvdrv/nvdata.h"
11 11
12namespace Tegra { 12namespace Tegra {
13class GPU; 13
14} 14namespace Host1x {
15class Host1x;
16} // namespace Host1x
17
18} // namespace Tegra
15 19
16namespace Service::Nvidia::NvCore { 20namespace Service::Nvidia::NvCore {
17 21
18class SyncpointManager final { 22class SyncpointManager final {
19public: 23public:
20 explicit SyncpointManager(Tegra::GPU& gpu_); 24 explicit SyncpointManager(Tegra::Host1x::Host1x& host1x);
21 ~SyncpointManager(); 25 ~SyncpointManager();
22 26
23 /** 27 /**
@@ -78,7 +82,7 @@ private:
78 82
79 std::array<Syncpoint, MaxSyncPoints> syncpoints{}; 83 std::array<Syncpoint, MaxSyncPoints> syncpoints{};
80 84
81 Tegra::GPU& gpu; 85 Tegra::Host1x::Host1x& host1x;
82}; 86};
83 87
84} // namespace Service::Nvidia::NvCore 88} // namespace Service::Nvidia::NvCore
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp
index 77e6a1cd6..b17589aa3 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp
@@ -13,6 +13,7 @@
13#include "core/hle/service/nvdrv/core/syncpoint_manager.h" 13#include "core/hle/service/nvdrv/core/syncpoint_manager.h"
14#include "core/hle/service/nvdrv/devices/nvhost_nvdec_common.h" 14#include "core/hle/service/nvdrv/devices/nvhost_nvdec_common.h"
15#include "core/memory.h" 15#include "core/memory.h"
16#include "video_core/host1x/host1x.h"
16#include "video_core/memory_manager.h" 17#include "video_core/memory_manager.h"
17#include "video_core/renderer_base.h" 18#include "video_core/renderer_base.h"
18 19
@@ -140,29 +141,8 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector<u8>& input, std::vecto
140 141
141 SliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer)); 142 SliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
142 143
143 auto& gpu = system.GPU();
144
145 for (auto& cmd_buffer : cmd_buffer_handles) { 144 for (auto& cmd_buffer : cmd_buffer_handles) {
146 auto object{nvmap.GetHandle(cmd_buffer.map_handle)}; 145 cmd_buffer.map_address = nvmap.PinHandle(cmd_buffer.map_handle);
147 if (!object) {
148 LOG_ERROR(Service_NVDRV, "invalid cmd_buffer nvmap_handle={:X}", cmd_buffer.map_handle);
149 std::memcpy(output.data(), &params, output.size());
150 return NvResult::InvalidState;
151 }
152 if (object->dma_map_addr == 0) {
153 // NVDEC and VIC memory is in the 32-bit address space
154 // MapAllocate32 will attempt to map a lower 32-bit value in the shared gpu memory space
155 const GPUVAddr low_addr =
156 gpu.MemoryManager().MapAllocate32(object->address, object->size);
157 object->dma_map_addr = static_cast<u32>(low_addr);
158 // Ensure that the dma_map_addr is indeed in the lower 32-bit address space.
159 ASSERT(object->dma_map_addr == low_addr);
160 }
161 if (!object->dma_map_addr) {
162 LOG_ERROR(Service_NVDRV, "failed to map size={}", object->size);
163 } else {
164 cmd_buffer.map_address = static_cast<u32_le>(object->dma_map_addr);
165 }
166 } 146 }
167 std::memcpy(output.data(), &params, sizeof(IoctlMapBuffer)); 147 std::memcpy(output.data(), &params, sizeof(IoctlMapBuffer));
168 std::memcpy(output.data() + sizeof(IoctlMapBuffer), cmd_buffer_handles.data(), 148 std::memcpy(output.data() + sizeof(IoctlMapBuffer), cmd_buffer_handles.data(),
@@ -172,11 +152,16 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector<u8>& input, std::vecto
172} 152}
173 153
174NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& output) { 154NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& output) {
175 // This is intntionally stubbed. 155 IoctlMapBuffer params{};
176 // Skip unmapping buffers here, as to not break the continuity of the VP9 reference frame 156 std::memcpy(&params, input.data(), sizeof(IoctlMapBuffer));
177 // addresses, and risk invalidating data before the async GPU thread is done with it 157 std::vector<MapBufferEntry> cmd_buffer_handles(params.num_entries);
158
159 SliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
160 for (auto& cmd_buffer : cmd_buffer_handles) {
161 nvmap.UnpinHandle(cmd_buffer.map_handle);
162 }
163
178 std::memset(output.data(), 0, output.size()); 164 std::memset(output.data(), 0, output.size());
179 LOG_DEBUG(Service_NVDRV, "(STUBBED) called");
180 return NvResult::Success; 165 return NvResult::Success;
181} 166}
182 167
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index b39a4c6db..8a9f3c717 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -71,7 +71,7 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger
71} 71}
72 72
73Module::Module(Core::System& system) 73Module::Module(Core::System& system)
74 : service_context{system, "nvdrv"}, events_interface{*this}, container{system.GPU()} { 74 : service_context{system, "nvdrv"}, events_interface{*this}, container{system.Host1x()} {
75 builders["/dev/nvhost-as-gpu"] = [this, &system](DeviceFD fd) { 75 builders["/dev/nvhost-as-gpu"] = [this, &system](DeviceFD fd) {
76 std::shared_ptr<Devices::nvdevice> device = 76 std::shared_ptr<Devices::nvdevice> device =
77 std::make_shared<Devices::nvhost_as_gpu>(system, *this, container); 77 std::make_shared<Devices::nvhost_as_gpu>(system, *this, container);
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 723f9b67c..40e6d1ec4 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -56,6 +56,8 @@ add_library(video_core STATIC
56 host1x/codecs/vp9_types.h 56 host1x/codecs/vp9_types.h
57 host1x/control.cpp 57 host1x/control.cpp
58 host1x/control.h 58 host1x/control.h
59 host1x/host1x.cpp
60 host1x/host1x.h
59 host1x/nvdec.cpp 61 host1x/nvdec.cpp
60 host1x/nvdec.h 62 host1x/nvdec.h
61 host1x/nvdec_common.h 63 host1x/nvdec_common.h
diff --git a/src/video_core/cdma_pusher.cpp b/src/video_core/cdma_pusher.cpp
index 148126347..28a2d2090 100644
--- a/src/video_core/cdma_pusher.cpp
+++ b/src/video_core/cdma_pusher.cpp
@@ -4,8 +4,8 @@
4#include <bit> 4#include <bit>
5#include "video_core/cdma_pusher.h" 5#include "video_core/cdma_pusher.h"
6#include "video_core/engines/maxwell_3d.h" 6#include "video_core/engines/maxwell_3d.h"
7#include "video_core/gpu.h"
8#include "video_core/host1x/control.h" 7#include "video_core/host1x/control.h"
8#include "video_core/host1x/host1x.h"
9#include "video_core/host1x/nvdec.h" 9#include "video_core/host1x/nvdec.h"
10#include "video_core/host1x/nvdec_common.h" 10#include "video_core/host1x/nvdec_common.h"
11#include "video_core/host1x/sync_manager.h" 11#include "video_core/host1x/sync_manager.h"
@@ -13,11 +13,11 @@
13#include "video_core/memory_manager.h" 13#include "video_core/memory_manager.h"
14 14
15namespace Tegra { 15namespace Tegra {
16CDmaPusher::CDmaPusher(GPU& gpu_) 16CDmaPusher::CDmaPusher(Host1x::Host1x& host1x_)
17 : gpu{gpu_}, nvdec_processor(std::make_shared<Host1x::Nvdec>(gpu)), 17 : host1x{host1x_}, nvdec_processor(std::make_shared<Host1x::Nvdec>(host1x)),
18 vic_processor(std::make_unique<Host1x::Vic>(gpu, nvdec_processor)), 18 vic_processor(std::make_unique<Host1x::Vic>(host1x, nvdec_processor)),
19 host1x_processor(std::make_unique<Host1x::Control>(gpu)), 19 host1x_processor(std::make_unique<Host1x::Control>(host1x)),
20 sync_manager(std::make_unique<Host1x::SyncptIncrManager>(gpu)) {} 20 sync_manager(std::make_unique<Host1x::SyncptIncrManager>(host1x)) {}
21 21
22CDmaPusher::~CDmaPusher() = default; 22CDmaPusher::~CDmaPusher() = default;
23 23
diff --git a/src/video_core/cdma_pusher.h b/src/video_core/cdma_pusher.h
index de17c2082..83112dfce 100644
--- a/src/video_core/cdma_pusher.h
+++ b/src/video_core/cdma_pusher.h
@@ -12,10 +12,9 @@
12 12
13namespace Tegra { 13namespace Tegra {
14 14
15class GPU;
16
17namespace Host1x { 15namespace Host1x {
18class Control; 16class Control;
17class Host1x;
19class Nvdec; 18class Nvdec;
20class SyncptIncrManager; 19class SyncptIncrManager;
21class Vic; 20class Vic;
@@ -91,7 +90,7 @@ enum class ThiMethod : u32 {
91 90
92class CDmaPusher { 91class CDmaPusher {
93public: 92public:
94 explicit CDmaPusher(GPU& gpu_); 93 explicit CDmaPusher(Host1x::Host1x& host1x);
95 ~CDmaPusher(); 94 ~CDmaPusher();
96 95
97 /// Process the command entry 96 /// Process the command entry
@@ -104,7 +103,7 @@ private:
104 /// Write arguments value to the ThiRegisters member at the specified offset 103 /// Write arguments value to the ThiRegisters member at the specified offset
105 void ThiStateWrite(ThiRegisters& state, u32 offset, u32 argument); 104 void ThiStateWrite(ThiRegisters& state, u32 offset, u32 argument);
106 105
107 GPU& gpu; 106 Host1x::Host1x& host1x;
108 std::shared_ptr<Tegra::Host1x::Nvdec> nvdec_processor; 107 std::shared_ptr<Tegra::Host1x::Nvdec> nvdec_processor;
109 std::unique_ptr<Tegra::Host1x::Vic> vic_processor; 108 std::unique_ptr<Tegra::Host1x::Vic> vic_processor;
110 std::unique_ptr<Tegra::Host1x::Control> host1x_processor; 109 std::unique_ptr<Tegra::Host1x::Control> host1x_processor;
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 1097db08a..e05c9a357 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -83,19 +83,11 @@ struct GPU::Impl {
83 UNIMPLEMENTED(); 83 UNIMPLEMENTED();
84 } 84 }
85 85
86 void CreateHost1xChannel() {
87 if (host1x_channel) {
88 return;
89 }
90 host1x_channel = CreateChannel(0);
91 host1x_channel->memory_manager = std::make_shared<Tegra::MemoryManager>(system);
92 InitChannel(*host1x_channel);
93 }
94
95 /// Binds a renderer to the GPU. 86 /// Binds a renderer to the GPU.
96 void BindRenderer(std::unique_ptr<VideoCore::RendererBase> renderer_) { 87 void BindRenderer(std::unique_ptr<VideoCore::RendererBase> renderer_) {
97 renderer = std::move(renderer_); 88 renderer = std::move(renderer_);
98 rasterizer = renderer->ReadRasterizer(); 89 rasterizer = renderer->ReadRasterizer();
90 host1x.MemoryManager().BindRasterizer(rasterizer);
99 } 91 }
100 92
101 /// Flush all current written commands into the host GPU for execution. 93 /// Flush all current written commands into the host GPU for execution.
@@ -173,12 +165,6 @@ struct GPU::Impl {
173 return *current_channel->kepler_compute; 165 return *current_channel->kepler_compute;
174 } 166 }
175 167
176 /// Returns a reference to the GPU memory manager.
177 [[nodiscard]] Tegra::MemoryManager& MemoryManager() {
178 CreateHost1xChannel();
179 return *host1x_channel->memory_manager;
180 }
181
182 /// Returns a reference to the GPU DMA pusher. 168 /// Returns a reference to the GPU DMA pusher.
183 [[nodiscard]] Tegra::DmaPusher& DmaPusher() { 169 [[nodiscard]] Tegra::DmaPusher& DmaPusher() {
184 ASSERT(current_channel); 170 ASSERT(current_channel);
@@ -299,7 +285,7 @@ struct GPU::Impl {
299 } 285 }
300 286
301 if (!cdma_pushers.contains(id)) { 287 if (!cdma_pushers.contains(id)) {
302 cdma_pushers.insert_or_assign(id, std::make_unique<Tegra::CDmaPusher>(gpu)); 288 cdma_pushers.insert_or_assign(id, std::make_unique<Tegra::CDmaPusher>(host1x));
303 } 289 }
304 290
305 // SubmitCommandBuffer would make the nvdec operations async, this is not currently working 291 // SubmitCommandBuffer would make the nvdec operations async, this is not currently working
@@ -389,7 +375,6 @@ struct GPU::Impl {
389 VideoCore::RasterizerInterface* rasterizer = nullptr; 375 VideoCore::RasterizerInterface* rasterizer = nullptr;
390 const bool use_nvdec; 376 const bool use_nvdec;
391 377
392 std::shared_ptr<Control::ChannelState> host1x_channel;
393 s32 new_channel_id{1}; 378 s32 new_channel_id{1};
394 /// Shader build notifier 379 /// Shader build notifier
395 std::unique_ptr<VideoCore::ShaderNotify> shader_notify; 380 std::unique_ptr<VideoCore::ShaderNotify> shader_notify;
@@ -510,14 +495,6 @@ const Engines::KeplerCompute& GPU::KeplerCompute() const {
510 return impl->KeplerCompute(); 495 return impl->KeplerCompute();
511} 496}
512 497
513Tegra::MemoryManager& GPU::MemoryManager() {
514 return impl->MemoryManager();
515}
516
517const Tegra::MemoryManager& GPU::MemoryManager() const {
518 return impl->MemoryManager();
519}
520
521Tegra::DmaPusher& GPU::DmaPusher() { 498Tegra::DmaPusher& GPU::DmaPusher() {
522 return impl->DmaPusher(); 499 return impl->DmaPusher();
523} 500}
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index c1a538257..f04edf5c4 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -153,12 +153,6 @@ public:
153 /// Returns a reference to the KeplerCompute GPU engine. 153 /// Returns a reference to the KeplerCompute GPU engine.
154 [[nodiscard]] const Engines::KeplerCompute& KeplerCompute() const; 154 [[nodiscard]] const Engines::KeplerCompute& KeplerCompute() const;
155 155
156 /// Returns a reference to the GPU memory manager.
157 [[nodiscard]] Tegra::MemoryManager& MemoryManager();
158
159 /// Returns a const reference to the GPU memory manager.
160 [[nodiscard]] const Tegra::MemoryManager& MemoryManager() const;
161
162 /// Returns a reference to the GPU DMA pusher. 156 /// Returns a reference to the GPU DMA pusher.
163 [[nodiscard]] Tegra::DmaPusher& DmaPusher(); 157 [[nodiscard]] Tegra::DmaPusher& DmaPusher();
164 158
diff --git a/src/video_core/host1x/codecs/codec.cpp b/src/video_core/host1x/codecs/codec.cpp
index 70c47ae03..42e7d6e4f 100644
--- a/src/video_core/host1x/codecs/codec.cpp
+++ b/src/video_core/host1x/codecs/codec.cpp
@@ -6,11 +6,11 @@
6#include <vector> 6#include <vector>
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/settings.h" 8#include "common/settings.h"
9#include "video_core/gpu.h"
10#include "video_core/host1x/codecs/codec.h" 9#include "video_core/host1x/codecs/codec.h"
11#include "video_core/host1x/codecs/h264.h" 10#include "video_core/host1x/codecs/h264.h"
12#include "video_core/host1x/codecs/vp8.h" 11#include "video_core/host1x/codecs/vp8.h"
13#include "video_core/host1x/codecs/vp9.h" 12#include "video_core/host1x/codecs/vp9.h"
13#include "video_core/host1x/host1x.h"
14#include "video_core/memory_manager.h" 14#include "video_core/memory_manager.h"
15 15
16extern "C" { 16extern "C" {
@@ -73,10 +73,10 @@ void AVFrameDeleter(AVFrame* ptr) {
73 av_frame_free(&ptr); 73 av_frame_free(&ptr);
74} 74}
75 75
76Codec::Codec(GPU& gpu_, const Host1x::NvdecCommon::NvdecRegisters& regs) 76Codec::Codec(Host1x::Host1x& host1x_, const Host1x::NvdecCommon::NvdecRegisters& regs)
77 : gpu(gpu_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(gpu)), 77 : host1x(host1x_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(host1x)),
78 vp8_decoder(std::make_unique<Decoder::VP8>(gpu)), 78 vp8_decoder(std::make_unique<Decoder::VP8>(host1x)),
79 vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {} 79 vp9_decoder(std::make_unique<Decoder::VP9>(host1x)) {}
80 80
81Codec::~Codec() { 81Codec::~Codec() {
82 if (!initialized) { 82 if (!initialized) {
diff --git a/src/video_core/host1x/codecs/codec.h b/src/video_core/host1x/codecs/codec.h
index 117cb3ccd..0d45fb7fe 100644
--- a/src/video_core/host1x/codecs/codec.h
+++ b/src/video_core/host1x/codecs/codec.h
@@ -21,7 +21,6 @@ extern "C" {
21} 21}
22 22
23namespace Tegra { 23namespace Tegra {
24class GPU;
25 24
26void AVFrameDeleter(AVFrame* ptr); 25void AVFrameDeleter(AVFrame* ptr);
27using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>; 26using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>;
@@ -32,9 +31,13 @@ class VP8;
32class VP9; 31class VP9;
33} // namespace Decoder 32} // namespace Decoder
34 33
34namespace Host1x {
35class Host1x;
36} // namespace Host1x
37
35class Codec { 38class Codec {
36public: 39public:
37 explicit Codec(GPU& gpu, const Host1x::NvdecCommon::NvdecRegisters& regs); 40 explicit Codec(Host1x::Host1x& host1x, const Host1x::NvdecCommon::NvdecRegisters& regs);
38 ~Codec(); 41 ~Codec();
39 42
40 /// Initialize the codec, returning success or failure 43 /// Initialize the codec, returning success or failure
@@ -69,7 +72,7 @@ private:
69 AVCodecContext* av_codec_ctx{nullptr}; 72 AVCodecContext* av_codec_ctx{nullptr};
70 AVBufferRef* av_gpu_decoder{nullptr}; 73 AVBufferRef* av_gpu_decoder{nullptr};
71 74
72 GPU& gpu; 75 Host1x::Host1x& host1x;
73 const Host1x::NvdecCommon::NvdecRegisters& state; 76 const Host1x::NvdecCommon::NvdecRegisters& state;
74 std::unique_ptr<Decoder::H264> h264_decoder; 77 std::unique_ptr<Decoder::H264> h264_decoder;
75 std::unique_ptr<Decoder::VP8> vp8_decoder; 78 std::unique_ptr<Decoder::VP8> vp8_decoder;
diff --git a/src/video_core/host1x/codecs/h264.cpp b/src/video_core/host1x/codecs/h264.cpp
index 95534bc85..e87bd65fa 100644
--- a/src/video_core/host1x/codecs/h264.cpp
+++ b/src/video_core/host1x/codecs/h264.cpp
@@ -5,8 +5,8 @@
5#include <bit> 5#include <bit>
6 6
7#include "common/settings.h" 7#include "common/settings.h"
8#include "video_core/gpu.h"
9#include "video_core/host1x/codecs/h264.h" 8#include "video_core/host1x/codecs/h264.h"
9#include "video_core/host1x/host1x.h"
10#include "video_core/memory_manager.h" 10#include "video_core/memory_manager.h"
11 11
12namespace Tegra::Decoder { 12namespace Tegra::Decoder {
@@ -24,19 +24,20 @@ constexpr std::array<u8, 16> zig_zag_scan{
24}; 24};
25} // Anonymous namespace 25} // Anonymous namespace
26 26
27H264::H264(GPU& gpu_) : gpu(gpu_) {} 27H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {}
28 28
29H264::~H264() = default; 29H264::~H264() = default;
30 30
31const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, 31const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
32 bool is_first_frame) { 32 bool is_first_frame) {
33 H264DecoderContext context; 33 H264DecoderContext context;
34 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext)); 34 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context,
35 sizeof(H264DecoderContext));
35 36
36 const s64 frame_number = context.h264_parameter_set.frame_number.Value(); 37 const s64 frame_number = context.h264_parameter_set.frame_number.Value();
37 if (!is_first_frame && frame_number != 0) { 38 if (!is_first_frame && frame_number != 0) {
38 frame.resize(context.stream_len); 39 frame.resize(context.stream_len);
39 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); 40 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size());
40 return frame; 41 return frame;
41 } 42 }
42 43
@@ -155,8 +156,8 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist
155 frame.resize(encoded_header.size() + context.stream_len); 156 frame.resize(encoded_header.size() + context.stream_len);
156 std::memcpy(frame.data(), encoded_header.data(), encoded_header.size()); 157 std::memcpy(frame.data(), encoded_header.data(), encoded_header.size());
157 158
158 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, 159 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset,
159 frame.data() + encoded_header.size(), context.stream_len); 160 frame.data() + encoded_header.size(), context.stream_len);
160 161
161 return frame; 162 return frame;
162} 163}
diff --git a/src/video_core/host1x/codecs/h264.h b/src/video_core/host1x/codecs/h264.h
index a98730474..5cc86454e 100644
--- a/src/video_core/host1x/codecs/h264.h
+++ b/src/video_core/host1x/codecs/h264.h
@@ -11,7 +11,11 @@
11#include "video_core/host1x/nvdec_common.h" 11#include "video_core/host1x/nvdec_common.h"
12 12
13namespace Tegra { 13namespace Tegra {
14class GPU; 14
15namespace Host1x {
16class Host1x;
17} // namespace Host1x
18
15namespace Decoder { 19namespace Decoder {
16 20
17class H264BitWriter { 21class H264BitWriter {
@@ -55,7 +59,7 @@ private:
55 59
56class H264 { 60class H264 {
57public: 61public:
58 explicit H264(GPU& gpu); 62 explicit H264(Host1x::Host1x& host1x);
59 ~H264(); 63 ~H264();
60 64
61 /// Compose the H264 frame for FFmpeg decoding 65 /// Compose the H264 frame for FFmpeg decoding
@@ -64,7 +68,7 @@ public:
64 68
65private: 69private:
66 std::vector<u8> frame; 70 std::vector<u8> frame;
67 GPU& gpu; 71 Host1x::Host1x& host1x;
68 72
69 struct H264ParameterSet { 73 struct H264ParameterSet {
70 s32 log2_max_pic_order_cnt_lsb_minus4; ///< 0x00 74 s32 log2_max_pic_order_cnt_lsb_minus4; ///< 0x00
diff --git a/src/video_core/host1x/codecs/vp8.cpp b/src/video_core/host1x/codecs/vp8.cpp
index aac026e17..28fb12cb8 100644
--- a/src/video_core/host1x/codecs/vp8.cpp
+++ b/src/video_core/host1x/codecs/vp8.cpp
@@ -3,18 +3,18 @@
3 3
4#include <vector> 4#include <vector>
5 5
6#include "video_core/gpu.h"
7#include "video_core/host1x/codecs/vp8.h" 6#include "video_core/host1x/codecs/vp8.h"
7#include "video_core/host1x/host1x.h"
8#include "video_core/memory_manager.h" 8#include "video_core/memory_manager.h"
9 9
10namespace Tegra::Decoder { 10namespace Tegra::Decoder {
11VP8::VP8(GPU& gpu_) : gpu(gpu_) {} 11VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {}
12 12
13VP8::~VP8() = default; 13VP8::~VP8() = default;
14 14
15const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { 15const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
16 VP8PictureInfo info; 16 VP8PictureInfo info;
17 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); 17 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo));
18 18
19 const bool is_key_frame = info.key_frame == 1u; 19 const bool is_key_frame = info.key_frame == 1u;
20 const auto bitstream_size = static_cast<size_t>(info.vld_buffer_size); 20 const auto bitstream_size = static_cast<size_t>(info.vld_buffer_size);
@@ -45,7 +45,7 @@ const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegiste
45 frame[9] = static_cast<u8>(((info.frame_height >> 8) & 0x3f)); 45 frame[9] = static_cast<u8>(((info.frame_height >> 8) & 0x3f));
46 } 46 }
47 const u64 bitstream_offset = state.frame_bitstream_offset; 47 const u64 bitstream_offset = state.frame_bitstream_offset;
48 gpu.MemoryManager().ReadBlock(bitstream_offset, frame.data() + header_size, bitstream_size); 48 host1x.MemoryManager().ReadBlock(bitstream_offset, frame.data() + header_size, bitstream_size);
49 49
50 return frame; 50 return frame;
51} 51}
diff --git a/src/video_core/host1x/codecs/vp8.h b/src/video_core/host1x/codecs/vp8.h
index a1dfa5f03..5bf07ecab 100644
--- a/src/video_core/host1x/codecs/vp8.h
+++ b/src/video_core/host1x/codecs/vp8.h
@@ -11,12 +11,16 @@
11#include "video_core/host1x/nvdec_common.h" 11#include "video_core/host1x/nvdec_common.h"
12 12
13namespace Tegra { 13namespace Tegra {
14class GPU; 14
15namespace Host1x {
16class Host1x;
17} // namespace Host1x
18
15namespace Decoder { 19namespace Decoder {
16 20
17class VP8 { 21class VP8 {
18public: 22public:
19 explicit VP8(GPU& gpu); 23 explicit VP8(Host1x::Host1x& host1x);
20 ~VP8(); 24 ~VP8();
21 25
22 /// Compose the VP8 frame for FFmpeg decoding 26 /// Compose the VP8 frame for FFmpeg decoding
@@ -25,7 +29,7 @@ public:
25 29
26private: 30private:
27 std::vector<u8> frame; 31 std::vector<u8> frame;
28 GPU& gpu; 32 Host1x::Host1x& host1x;
29 33
30 struct VP8PictureInfo { 34 struct VP8PictureInfo {
31 INSERT_PADDING_WORDS_NOINIT(14); 35 INSERT_PADDING_WORDS_NOINIT(14);
diff --git a/src/video_core/host1x/codecs/vp9.cpp b/src/video_core/host1x/codecs/vp9.cpp
index bc50c6ba4..667aadc6a 100644
--- a/src/video_core/host1x/codecs/vp9.cpp
+++ b/src/video_core/host1x/codecs/vp9.cpp
@@ -4,8 +4,8 @@
4#include <algorithm> // for std::copy 4#include <algorithm> // for std::copy
5#include <numeric> 5#include <numeric>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "video_core/gpu.h"
8#include "video_core/host1x/codecs/vp9.h" 7#include "video_core/host1x/codecs/vp9.h"
8#include "video_core/host1x/host1x.h"
9#include "video_core/memory_manager.h" 9#include "video_core/memory_manager.h"
10 10
11namespace Tegra::Decoder { 11namespace Tegra::Decoder {
@@ -236,7 +236,7 @@ constexpr std::array<u8, 254> map_lut{
236} 236}
237} // Anonymous namespace 237} // Anonymous namespace
238 238
239VP9::VP9(GPU& gpu_) : gpu{gpu_} {} 239VP9::VP9(Host1x::Host1x& host1x_) : host1x{host1x_} {}
240 240
241VP9::~VP9() = default; 241VP9::~VP9() = default;
242 242
@@ -357,7 +357,7 @@ void VP9::WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_
357 357
358Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters& state) { 358Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters& state) {
359 PictureInfo picture_info; 359 PictureInfo picture_info;
360 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo)); 360 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo));
361 Vp9PictureInfo vp9_info = picture_info.Convert(); 361 Vp9PictureInfo vp9_info = picture_info.Convert();
362 362
363 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy); 363 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy);
@@ -372,17 +372,17 @@ Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters&
372 372
373void VP9::InsertEntropy(u64 offset, Vp9EntropyProbs& dst) { 373void VP9::InsertEntropy(u64 offset, Vp9EntropyProbs& dst) {
374 EntropyProbs entropy; 374 EntropyProbs entropy;
375 gpu.MemoryManager().ReadBlock(offset, &entropy, sizeof(EntropyProbs)); 375 host1x.MemoryManager().ReadBlock(offset, &entropy, sizeof(EntropyProbs));
376 entropy.Convert(dst); 376 entropy.Convert(dst);
377} 377}
378 378
379Vp9FrameContainer VP9::GetCurrentFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { 379Vp9FrameContainer VP9::GetCurrentFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
380 Vp9FrameContainer current_frame{}; 380 Vp9FrameContainer current_frame{};
381 { 381 {
382 gpu.SyncGuestHost(); 382 // gpu.SyncGuestHost(); epic, why?
383 current_frame.info = GetVp9PictureInfo(state); 383 current_frame.info = GetVp9PictureInfo(state);
384 current_frame.bit_stream.resize(current_frame.info.bitstream_size); 384 current_frame.bit_stream.resize(current_frame.info.bitstream_size);
385 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, current_frame.bit_stream.data(), 385 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, current_frame.bit_stream.data(),
386 current_frame.info.bitstream_size); 386 current_frame.info.bitstream_size);
387 } 387 }
388 if (!next_frame.bit_stream.empty()) { 388 if (!next_frame.bit_stream.empty()) {
diff --git a/src/video_core/host1x/codecs/vp9.h b/src/video_core/host1x/codecs/vp9.h
index a425c0fa4..d4083e8d3 100644
--- a/src/video_core/host1x/codecs/vp9.h
+++ b/src/video_core/host1x/codecs/vp9.h
@@ -12,7 +12,11 @@
12#include "video_core/host1x/nvdec_common.h" 12#include "video_core/host1x/nvdec_common.h"
13 13
14namespace Tegra { 14namespace Tegra {
15class GPU; 15
16namespace Host1x {
17class Host1x;
18} // namespace Host1x
19
16namespace Decoder { 20namespace Decoder {
17 21
18/// The VpxRangeEncoder, and VpxBitStreamWriter classes are used to compose the 22/// The VpxRangeEncoder, and VpxBitStreamWriter classes are used to compose the
@@ -106,7 +110,7 @@ private:
106 110
107class VP9 { 111class VP9 {
108public: 112public:
109 explicit VP9(GPU& gpu_); 113 explicit VP9(Host1x::Host1x& host1x);
110 ~VP9(); 114 ~VP9();
111 115
112 VP9(const VP9&) = delete; 116 VP9(const VP9&) = delete;
@@ -176,7 +180,7 @@ private:
176 [[nodiscard]] std::vector<u8> ComposeCompressedHeader(); 180 [[nodiscard]] std::vector<u8> ComposeCompressedHeader();
177 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); 181 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader();
178 182
179 GPU& gpu; 183 Host1x::Host1x& host1x;
180 std::vector<u8> frame; 184 std::vector<u8> frame;
181 185
182 std::array<s8, 4> loop_filter_ref_deltas{}; 186 std::array<s8, 4> loop_filter_ref_deltas{};
diff --git a/src/video_core/host1x/codecs/vp9_types.h b/src/video_core/host1x/codecs/vp9_types.h
index bb3d8df6e..adad8ed7e 100644
--- a/src/video_core/host1x/codecs/vp9_types.h
+++ b/src/video_core/host1x/codecs/vp9_types.h
@@ -9,7 +9,6 @@
9#include "common/common_types.h" 9#include "common/common_types.h"
10 10
11namespace Tegra { 11namespace Tegra {
12class GPU;
13 12
14namespace Decoder { 13namespace Decoder {
15struct Vp9FrameDimensions { 14struct Vp9FrameDimensions {
diff --git a/src/video_core/host1x/control.cpp b/src/video_core/host1x/control.cpp
index b72b01aa3..a81c635ae 100644
--- a/src/video_core/host1x/control.cpp
+++ b/src/video_core/host1x/control.cpp
@@ -3,13 +3,12 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/assert.h" 5#include "common/assert.h"
6#include "video_core/gpu.h"
7#include "video_core/host1x/control.h" 6#include "video_core/host1x/control.h"
8#include "video_core/host1x/host1x.h" 7#include "video_core/host1x/host1x.h"
9 8
10namespace Tegra::Host1x { 9namespace Tegra::Host1x {
11 10
12Control::Control(GPU& gpu_) : gpu(gpu_) {} 11Control::Control(Host1x& host1x_) : host1x(host1x_) {}
13 12
14Control::~Control() = default; 13Control::~Control() = default;
15 14
@@ -29,7 +28,7 @@ void Control::ProcessMethod(Method method, u32 argument) {
29} 28}
30 29
31void Control::Execute(u32 data) { 30void Control::Execute(u32 data) {
32 gpu.Host1x().GetSyncpointManager().WaitHost(data, syncpoint_value); 31 host1x.GetSyncpointManager().WaitHost(data, syncpoint_value);
33} 32}
34 33
35} // namespace Tegra::Host1x 34} // namespace Tegra::Host1x
diff --git a/src/video_core/host1x/control.h b/src/video_core/host1x/control.h
index 04dac7d51..18a9b56c0 100644
--- a/src/video_core/host1x/control.h
+++ b/src/video_core/host1x/control.h
@@ -8,10 +8,10 @@
8#include "common/common_types.h" 8#include "common/common_types.h"
9 9
10namespace Tegra { 10namespace Tegra {
11class GPU;
12 11
13namespace Host1x { 12namespace Host1x {
14 13
14class Host1x;
15class Nvdec; 15class Nvdec;
16 16
17class Control { 17class Control {
@@ -22,7 +22,7 @@ public:
22 WaitSyncpt32 = 0x50, 22 WaitSyncpt32 = 0x50,
23 }; 23 };
24 24
25 explicit Control(GPU& gpu); 25 explicit Control(Host1x& host1x);
26 ~Control(); 26 ~Control();
27 27
28 /// Writes the method into the state, Invoke Execute() if encountered 28 /// Writes the method into the state, Invoke Execute() if encountered
@@ -33,7 +33,7 @@ private:
33 void Execute(u32 data); 33 void Execute(u32 data);
34 34
35 u32 syncpoint_value{}; 35 u32 syncpoint_value{};
36 GPU& gpu; 36 Host1x& host1x;
37}; 37};
38 38
39} // namespace Host1x 39} // namespace Host1x
diff --git a/src/video_core/host1x/host1x.cpp b/src/video_core/host1x/host1x.cpp
new file mode 100644
index 000000000..eb00f4855
--- /dev/null
+++ b/src/video_core/host1x/host1x.cpp
@@ -0,0 +1,18 @@
1// Copyright 2022 yuzu Emulator Project
2// Licensed under GPLv3 or any later version
3// Refer to the license.txt file included.
4
5#include "core/core.h"
6#include "video_core/host1x/host1x.h"
7
8namespace Tegra {
9
10namespace Host1x {
11
12Host1x::Host1x(Core::System& system_)
13 : system{system_}, syncpoint_manager{}, memory_manager{system, 32, 12},
14 allocator{std::make_unique<Common::FlatAllocator<u32, 0, 32>>(1 << 12)} {}
15
16} // namespace Host1x
17
18} // namespace Tegra
diff --git a/src/video_core/host1x/host1x.h b/src/video_core/host1x/host1x.h
index 2971be286..e4b69d75a 100644
--- a/src/video_core/host1x/host1x.h
+++ b/src/video_core/host1x/host1x.h
@@ -6,7 +6,13 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8 8
9#include "common/address_space.h"
9#include "video_core/host1x/syncpoint_manager.h" 10#include "video_core/host1x/syncpoint_manager.h"
11#include "video_core/memory_manager.h"
12
13namespace Core {
14class System;
15} // namespace Core
10 16
11namespace Tegra { 17namespace Tegra {
12 18
@@ -14,7 +20,7 @@ namespace Host1x {
14 20
15class Host1x { 21class Host1x {
16public: 22public:
17 Host1x() : syncpoint_manager{} {} 23 Host1x(Core::System& system);
18 24
19 SyncpointManager& GetSyncpointManager() { 25 SyncpointManager& GetSyncpointManager() {
20 return syncpoint_manager; 26 return syncpoint_manager;
@@ -24,8 +30,27 @@ public:
24 return syncpoint_manager; 30 return syncpoint_manager;
25 } 31 }
26 32
33 Tegra::MemoryManager& MemoryManager() {
34 return memory_manager;
35 }
36
37 const Tegra::MemoryManager& MemoryManager() const {
38 return memory_manager;
39 }
40
41 Common::FlatAllocator<u32, 0, 32>& Allocator() {
42 return *allocator;
43 }
44
45 const Common::FlatAllocator<u32, 0, 32>& Allocator() const {
46 return *allocator;
47 }
48
27private: 49private:
50 Core::System& system;
28 SyncpointManager syncpoint_manager; 51 SyncpointManager syncpoint_manager;
52 Tegra::MemoryManager memory_manager;
53 std::unique_ptr<Common::FlatAllocator<u32, 0, 32>> allocator;
29}; 54};
30 55
31} // namespace Host1x 56} // namespace Host1x
diff --git a/src/video_core/host1x/nvdec.cpp b/src/video_core/host1x/nvdec.cpp
index 5f6decd0d..a4bd5b79f 100644
--- a/src/video_core/host1x/nvdec.cpp
+++ b/src/video_core/host1x/nvdec.cpp
@@ -2,7 +2,7 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/assert.h" 4#include "common/assert.h"
5#include "video_core/gpu.h" 5#include "video_core/host1x/host1x.h"
6#include "video_core/host1x/nvdec.h" 6#include "video_core/host1x/nvdec.h"
7 7
8namespace Tegra::Host1x { 8namespace Tegra::Host1x {
@@ -10,7 +10,8 @@ namespace Tegra::Host1x {
10#define NVDEC_REG_INDEX(field_name) \ 10#define NVDEC_REG_INDEX(field_name) \
11 (offsetof(NvdecCommon::NvdecRegisters, field_name) / sizeof(u64)) 11 (offsetof(NvdecCommon::NvdecRegisters, field_name) / sizeof(u64))
12 12
13Nvdec::Nvdec(GPU& gpu_) : gpu(gpu_), state{}, codec(std::make_unique<Codec>(gpu, state)) {} 13Nvdec::Nvdec(Host1x& host1x_)
14 : host1x(host1x_), state{}, codec(std::make_unique<Codec>(host1x, state)) {}
14 15
15Nvdec::~Nvdec() = default; 16Nvdec::~Nvdec() = default;
16 17
diff --git a/src/video_core/host1x/nvdec.h b/src/video_core/host1x/nvdec.h
index 41ba1f7a0..3949d5181 100644
--- a/src/video_core/host1x/nvdec.h
+++ b/src/video_core/host1x/nvdec.h
@@ -9,13 +9,14 @@
9#include "video_core/host1x/codecs/codec.h" 9#include "video_core/host1x/codecs/codec.h"
10 10
11namespace Tegra { 11namespace Tegra {
12class GPU;
13 12
14namespace Host1x { 13namespace Host1x {
15 14
15class Host1x;
16
16class Nvdec { 17class Nvdec {
17public: 18public:
18 explicit Nvdec(GPU& gpu); 19 explicit Nvdec(Host1x& host1x);
19 ~Nvdec(); 20 ~Nvdec();
20 21
21 /// Writes the method into the state, Invoke Execute() if encountered 22 /// Writes the method into the state, Invoke Execute() if encountered
@@ -28,7 +29,7 @@ private:
28 /// Invoke codec to decode a frame 29 /// Invoke codec to decode a frame
29 void Execute(); 30 void Execute();
30 31
31 GPU& gpu; 32 Host1x& host1x;
32 NvdecCommon::NvdecRegisters state; 33 NvdecCommon::NvdecRegisters state;
33 std::unique_ptr<Codec> codec; 34 std::unique_ptr<Codec> codec;
34}; 35};
diff --git a/src/video_core/host1x/sync_manager.cpp b/src/video_core/host1x/sync_manager.cpp
index 8694f77e2..5ef9ea217 100644
--- a/src/video_core/host1x/sync_manager.cpp
+++ b/src/video_core/host1x/sync_manager.cpp
@@ -3,14 +3,13 @@
3 3
4#include <algorithm> 4#include <algorithm>
5#include "sync_manager.h" 5#include "sync_manager.h"
6#include "video_core/gpu.h"
7#include "video_core/host1x/host1x.h" 6#include "video_core/host1x/host1x.h"
8#include "video_core/host1x/syncpoint_manager.h" 7#include "video_core/host1x/syncpoint_manager.h"
9 8
10namespace Tegra { 9namespace Tegra {
11namespace Host1x { 10namespace Host1x {
12 11
13SyncptIncrManager::SyncptIncrManager(GPU& gpu_) : gpu(gpu_) {} 12SyncptIncrManager::SyncptIncrManager(Host1x& host1x_) : host1x(host1x_) {}
14SyncptIncrManager::~SyncptIncrManager() = default; 13SyncptIncrManager::~SyncptIncrManager() = default;
15 14
16void SyncptIncrManager::Increment(u32 id) { 15void SyncptIncrManager::Increment(u32 id) {
@@ -40,7 +39,7 @@ void SyncptIncrManager::IncrementAllDone() {
40 if (!increments[done_count].complete) { 39 if (!increments[done_count].complete) {
41 break; 40 break;
42 } 41 }
43 auto& syncpoint_manager = gpu.Host1x().GetSyncpointManager(); 42 auto& syncpoint_manager = host1x.GetSyncpointManager();
44 syncpoint_manager.IncrementGuest(increments[done_count].syncpt_id); 43 syncpoint_manager.IncrementGuest(increments[done_count].syncpt_id);
45 syncpoint_manager.IncrementHost(increments[done_count].syncpt_id); 44 syncpoint_manager.IncrementHost(increments[done_count].syncpt_id);
46 } 45 }
diff --git a/src/video_core/host1x/sync_manager.h b/src/video_core/host1x/sync_manager.h
index aba72d5c5..7bb77fa27 100644
--- a/src/video_core/host1x/sync_manager.h
+++ b/src/video_core/host1x/sync_manager.h
@@ -9,10 +9,10 @@
9 9
10namespace Tegra { 10namespace Tegra {
11 11
12class GPU;
13
14namespace Host1x { 12namespace Host1x {
15 13
14class Host1x;
15
16struct SyncptIncr { 16struct SyncptIncr {
17 u32 id; 17 u32 id;
18 u32 class_id; 18 u32 class_id;
@@ -25,7 +25,7 @@ struct SyncptIncr {
25 25
26class SyncptIncrManager { 26class SyncptIncrManager {
27public: 27public:
28 explicit SyncptIncrManager(GPU& gpu); 28 explicit SyncptIncrManager(Host1x& host1x);
29 ~SyncptIncrManager(); 29 ~SyncptIncrManager();
30 30
31 /// Add syncpoint id and increment all 31 /// Add syncpoint id and increment all
@@ -45,7 +45,7 @@ private:
45 std::mutex increment_lock; 45 std::mutex increment_lock;
46 u32 current_id{}; 46 u32 current_id{};
47 47
48 GPU& gpu; 48 Host1x& host1x;
49}; 49};
50 50
51} // namespace Host1x 51} // namespace Host1x
diff --git a/src/video_core/host1x/vic.cpp b/src/video_core/host1x/vic.cpp
index a9422670a..5d8039841 100644
--- a/src/video_core/host1x/vic.cpp
+++ b/src/video_core/host1x/vic.cpp
@@ -19,7 +19,7 @@ extern "C" {
19#include "common/logging/log.h" 19#include "common/logging/log.h"
20 20
21#include "video_core/engines/maxwell_3d.h" 21#include "video_core/engines/maxwell_3d.h"
22#include "video_core/gpu.h" 22#include "video_core/host1x/host1x.h"
23#include "video_core/host1x/nvdec.h" 23#include "video_core/host1x/nvdec.h"
24#include "video_core/host1x/vic.h" 24#include "video_core/host1x/vic.h"
25#include "video_core/memory_manager.h" 25#include "video_core/memory_manager.h"
@@ -49,8 +49,8 @@ union VicConfig {
49 BitField<46, 14, u64_le> surface_height_minus1; 49 BitField<46, 14, u64_le> surface_height_minus1;
50}; 50};
51 51
52Vic::Vic(GPU& gpu_, std::shared_ptr<Nvdec> nvdec_processor_) 52Vic::Vic(Host1x& host1x_, std::shared_ptr<Nvdec> nvdec_processor_)
53 : gpu(gpu_), 53 : host1x(host1x_),
54 nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} {} 54 nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} {}
55 55
56Vic::~Vic() = default; 56Vic::~Vic() = default;
@@ -81,7 +81,7 @@ void Vic::Execute() {
81 LOG_ERROR(Service_NVDRV, "VIC Luma address not set."); 81 LOG_ERROR(Service_NVDRV, "VIC Luma address not set.");
82 return; 82 return;
83 } 83 }
84 const VicConfig config{gpu.MemoryManager().Read<u64>(config_struct_address + 0x20)}; 84 const VicConfig config{host1x.MemoryManager().Read<u64>(config_struct_address + 0x20)};
85 const AVFramePtr frame_ptr = nvdec_processor->GetFrame(); 85 const AVFramePtr frame_ptr = nvdec_processor->GetFrame();
86 const auto* frame = frame_ptr.get(); 86 const auto* frame = frame_ptr.get();
87 if (!frame) { 87 if (!frame) {
@@ -159,12 +159,12 @@ void Vic::WriteRGBFrame(const AVFrame* frame, const VicConfig& config) {
159 Texture::SwizzleSubrect(width, height, width * 4, width, 4, luma_buffer.data(), 159 Texture::SwizzleSubrect(width, height, width * 4, width, 4, luma_buffer.data(),
160 converted_frame_buf_addr, block_height, 0, 0); 160 converted_frame_buf_addr, block_height, 0, 0);
161 161
162 gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), size); 162 host1x.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), size);
163 } else { 163 } else {
164 // send pitch linear frame 164 // send pitch linear frame
165 const size_t linear_size = width * height * 4; 165 const size_t linear_size = width * height * 4;
166 gpu.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr, 166 host1x.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr,
167 linear_size); 167 linear_size);
168 } 168 }
169} 169}
170 170
@@ -192,8 +192,8 @@ void Vic::WriteYUVFrame(const AVFrame* frame, const VicConfig& config) {
192 luma_buffer[dst + x] = luma_src[src + x]; 192 luma_buffer[dst + x] = luma_src[src + x];
193 } 193 }
194 } 194 }
195 gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), 195 host1x.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(),
196 luma_buffer.size()); 196 luma_buffer.size());
197 197
198 // Chroma 198 // Chroma
199 const std::size_t half_height = frame_height / 2; 199 const std::size_t half_height = frame_height / 2;
@@ -234,8 +234,8 @@ void Vic::WriteYUVFrame(const AVFrame* frame, const VicConfig& config) {
234 ASSERT(false); 234 ASSERT(false);
235 break; 235 break;
236 } 236 }
237 gpu.MemoryManager().WriteBlock(output_surface_chroma_address, chroma_buffer.data(), 237 host1x.MemoryManager().WriteBlock(output_surface_chroma_address, chroma_buffer.data(),
238 chroma_buffer.size()); 238 chroma_buffer.size());
239} 239}
240 240
241} // namespace Host1x 241} // namespace Host1x
diff --git a/src/video_core/host1x/vic.h b/src/video_core/host1x/vic.h
index c51f8af7e..2b78786e8 100644
--- a/src/video_core/host1x/vic.h
+++ b/src/video_core/host1x/vic.h
@@ -10,10 +10,10 @@
10struct SwsContext; 10struct SwsContext;
11 11
12namespace Tegra { 12namespace Tegra {
13class GPU;
14 13
15namespace Host1x { 14namespace Host1x {
16 15
16class Host1x;
17class Nvdec; 17class Nvdec;
18union VicConfig; 18union VicConfig;
19 19
@@ -28,7 +28,7 @@ public:
28 SetOutputSurfaceChromaUnusedOffset = 0x1ca 28 SetOutputSurfaceChromaUnusedOffset = 0x1ca
29 }; 29 };
30 30
31 explicit Vic(GPU& gpu, std::shared_ptr<Nvdec> nvdec_processor); 31 explicit Vic(Host1x& host1x, std::shared_ptr<Nvdec> nvdec_processor);
32 32
33 ~Vic(); 33 ~Vic();
34 34
@@ -42,7 +42,7 @@ private:
42 42
43 void WriteYUVFrame(const AVFrame* frame, const VicConfig& config); 43 void WriteYUVFrame(const AVFrame* frame, const VicConfig& config);
44 44
45 GPU& gpu; 45 Host1x& host1x;
46 std::shared_ptr<Tegra::Host1x::Nvdec> nvdec_processor; 46 std::shared_ptr<Tegra::Host1x::Nvdec> nvdec_processor;
47 47
48 /// Avoid reallocation of the following buffers every frame, as their 48 /// Avoid reallocation of the following buffers every frame, as their