summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2022-09-01 05:45:22 +0200
committerGravatar Fernando Sahmkow2022-10-06 21:00:54 +0200
commitca3db0d7c94a20668781830ff852dbf512598efb (patch)
treeedd20d669000e980169db27a896adc09078ceeaa /src/core
parentstate_tracker: workaround channel setup for homebrew (diff)
downloadyuzu-ca3db0d7c94a20668781830ff852dbf512598efb.tar.gz
yuzu-ca3db0d7c94a20668781830ff852dbf512598efb.tar.xz
yuzu-ca3db0d7c94a20668781830ff852dbf512598efb.zip
General: address feedback
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/nvdrv/core/container.cpp12
-rw-r--r--src/core/hle/service/nvdrv/core/container.h23
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.cpp4
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.h59
-rw-r--r--src/core/hle/service/nvdrv/core/syncpoint_manager.cpp32
-rw-r--r--src/core/hle/service/nvdrv/core/syncpoint_manager.h34
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp28
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl.h2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp13
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec.h3
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp13
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h5
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_vic.cpp16
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_vic.h3
-rw-r--r--src/core/hle/service/nvdrv/devices/nvmap.h4
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp4
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h2
18 files changed, 131 insertions, 128 deletions
diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp
index d2a632646..37ca24f5d 100644
--- a/src/core/hle/service/nvdrv/core/container.cpp
+++ b/src/core/hle/service/nvdrv/core/container.cpp
@@ -10,9 +10,11 @@
10namespace Service::Nvidia::NvCore { 10namespace Service::Nvidia::NvCore {
11 11
12struct ContainerImpl { 12struct ContainerImpl {
13 ContainerImpl(Tegra::Host1x::Host1x& host1x_) : file{host1x_}, manager{host1x_} {} 13 explicit ContainerImpl(Tegra::Host1x::Host1x& host1x_)
14 : file{host1x_}, manager{host1x_}, device_file_data{} {}
14 NvMap file; 15 NvMap file;
15 SyncpointManager manager; 16 SyncpointManager manager;
17 Container::Host1xDeviceFileData device_file_data;
16}; 18};
17 19
18Container::Container(Tegra::Host1x::Host1x& host1x_) { 20Container::Container(Tegra::Host1x::Host1x& host1x_) {
@@ -29,6 +31,14 @@ const NvMap& Container::GetNvMapFile() const {
29 return impl->file; 31 return impl->file;
30} 32}
31 33
34Container::Host1xDeviceFileData& Container::Host1xDeviceFile() {
35 return impl->device_file_data;
36}
37
38const Container::Host1xDeviceFileData& Container::Host1xDeviceFile() const {
39 return impl->device_file_data;
40}
41
32SyncpointManager& Container::GetSyncpointManager() { 42SyncpointManager& Container::GetSyncpointManager() {
33 return impl->manager; 43 return impl->manager;
34} 44}
diff --git a/src/core/hle/service/nvdrv/core/container.h b/src/core/hle/service/nvdrv/core/container.h
index 5c8b95803..b4b63ac90 100644
--- a/src/core/hle/service/nvdrv/core/container.h
+++ b/src/core/hle/service/nvdrv/core/container.h
@@ -4,15 +4,15 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <deque>
7#include <memory> 8#include <memory>
9#include <unordered_map>
8 10
9namespace Tegra { 11#include "core/hle/service/nvdrv/nvdata.h"
10 12
11namespace Host1x { 13namespace Tegra::Host1x {
12class Host1x; 14class Host1x;
13} // namespace Host1x 15} // namespace Tegra::Host1x
14
15} // namespace Tegra
16 16
17namespace Service::Nvidia::NvCore { 17namespace Service::Nvidia::NvCore {
18 18
@@ -23,7 +23,7 @@ struct ContainerImpl;
23 23
24class Container { 24class Container {
25public: 25public:
26 Container(Tegra::Host1x::Host1x& host1x); 26 explicit Container(Tegra::Host1x::Host1x& host1x);
27 ~Container(); 27 ~Container();
28 28
29 NvMap& GetNvMapFile(); 29 NvMap& GetNvMapFile();
@@ -34,6 +34,17 @@ public:
34 34
35 const SyncpointManager& GetSyncpointManager() const; 35 const SyncpointManager& GetSyncpointManager() const;
36 36
37 struct Host1xDeviceFileData {
38 std::unordered_map<DeviceFD, u32> fd_to_id{};
39 std::deque<u32> syncpts_accumulated{};
40 u32 nvdec_next_id{};
41 u32 vic_next_id{};
42 };
43
44 Host1xDeviceFileData& Host1xDeviceFile();
45
46 const Host1xDeviceFileData& Host1xDeviceFile() const;
47
37private: 48private:
38 std::unique_ptr<ContainerImpl> impl; 49 std::unique_ptr<ContainerImpl> impl;
39}; 50};
diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp
index e63ec7717..fbd8a74a5 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/core/nvmap.cpp
@@ -119,7 +119,7 @@ std::shared_ptr<NvMap::Handle> NvMap::GetHandle(Handle::Id handle) {
119 std::scoped_lock lock(handles_lock); 119 std::scoped_lock lock(handles_lock);
120 try { 120 try {
121 return handles.at(handle); 121 return handles.at(handle);
122 } catch ([[maybe_unused]] std::out_of_range& e) { 122 } catch (std::out_of_range&) {
123 return nullptr; 123 return nullptr;
124 } 124 }
125} 125}
@@ -128,7 +128,7 @@ VAddr NvMap::GetHandleAddress(Handle::Id handle) {
128 std::scoped_lock lock(handles_lock); 128 std::scoped_lock lock(handles_lock);
129 try { 129 try {
130 return handles.at(handle)->address; 130 return handles.at(handle)->address;
131 } catch ([[maybe_unused]] std::out_of_range& e) { 131 } catch (std::out_of_range&) {
132 return 0; 132 return 0;
133 } 133 }
134} 134}
diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h
index 6d6dac023..b9dd3801f 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.h
+++ b/src/core/hle/service/nvdrv/core/nvmap.h
@@ -98,35 +98,6 @@ public:
98 } 98 }
99 }; 99 };
100 100
101private:
102 std::list<std::shared_ptr<Handle>> unmap_queue{};
103 std::mutex unmap_queue_lock{}; //!< Protects access to `unmap_queue`
104
105 std::unordered_map<Handle::Id, std::shared_ptr<Handle>>
106 handles{}; //!< Main owning map of handles
107 std::mutex handles_lock; //!< Protects access to `handles`
108
109 static constexpr u32 HandleIdIncrement{
110 4}; //!< Each new handle ID is an increment of 4 from the previous
111 std::atomic<u32> next_handle_id{HandleIdIncrement};
112 Tegra::Host1x::Host1x& host1x;
113
114 void AddHandle(std::shared_ptr<Handle> handle);
115
116 /**
117 * @brief Unmaps and frees the SMMU memory region a handle is mapped to
118 * @note Both `unmap_queue_lock` and `handle_description.mutex` MUST be locked when calling this
119 */
120 void UnmapHandle(Handle& handle_description);
121
122 /**
123 * @brief Removes a handle from the map taking its dupes into account
124 * @note handle_description.mutex MUST be locked when calling this
125 * @return If the handle was removed from the map
126 */
127 bool TryRemoveHandle(const Handle& handle_description);
128
129public:
130 /** 101 /**
131 * @brief Encapsulates the result of a FreeHandle operation 102 * @brief Encapsulates the result of a FreeHandle operation
132 */ 103 */
@@ -136,7 +107,7 @@ public:
136 bool was_uncached; //!< If the handle was allocated as uncached 107 bool was_uncached; //!< If the handle was allocated as uncached
137 }; 108 };
138 109
139 NvMap(Tegra::Host1x::Host1x& host1x); 110 explicit NvMap(Tegra::Host1x::Host1x& host1x);
140 111
141 /** 112 /**
142 * @brief Creates an unallocated handle of the given size 113 * @brief Creates an unallocated handle of the given size
@@ -172,5 +143,33 @@ public:
172 * describing the prior state of the handle 143 * describing the prior state of the handle
173 */ 144 */
174 std::optional<FreeInfo> FreeHandle(Handle::Id handle, bool internal_session); 145 std::optional<FreeInfo> FreeHandle(Handle::Id handle, bool internal_session);
146
147private:
148 std::list<std::shared_ptr<Handle>> unmap_queue{};
149 std::mutex unmap_queue_lock{}; //!< Protects access to `unmap_queue`
150
151 std::unordered_map<Handle::Id, std::shared_ptr<Handle>>
152 handles{}; //!< Main owning map of handles
153 std::mutex handles_lock; //!< Protects access to `handles`
154
155 static constexpr u32 HandleIdIncrement{
156 4}; //!< Each new handle ID is an increment of 4 from the previous
157 std::atomic<u32> next_handle_id{HandleIdIncrement};
158 Tegra::Host1x::Host1x& host1x;
159
160 void AddHandle(std::shared_ptr<Handle> handle);
161
162 /**
163 * @brief Unmaps and frees the SMMU memory region a handle is mapped to
164 * @note Both `unmap_queue_lock` and `handle_description.mutex` MUST be locked when calling this
165 */
166 void UnmapHandle(Handle& handle_description);
167
168 /**
169 * @brief Removes a handle from the map taking its dupes into account
170 * @note handle_description.mutex MUST be locked when calling this
171 * @return If the handle was removed from the map
172 */
173 bool TryRemoveHandle(const Handle& handle_description);
175}; 174};
176} // namespace Service::Nvidia::NvCore 175} // namespace Service::Nvidia::NvCore
diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
index 072b3a22f..eda2041a0 100644
--- a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
+++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp
@@ -18,23 +18,23 @@ SyncpointManager::SyncpointManager(Tegra::Host1x::Host1x& host1x_) : host1x{host
18 ReserveSyncpoint(VBlank0SyncpointId, true); 18 ReserveSyncpoint(VBlank0SyncpointId, true);
19 ReserveSyncpoint(VBlank1SyncpointId, true); 19 ReserveSyncpoint(VBlank1SyncpointId, true);
20 20
21 for (u32 syncpointId : channel_syncpoints) { 21 for (u32 syncpoint_id : channel_syncpoints) {
22 if (syncpointId) { 22 if (syncpoint_id) {
23 ReserveSyncpoint(syncpointId, false); 23 ReserveSyncpoint(syncpoint_id, false);
24 } 24 }
25 } 25 }
26} 26}
27 27
28SyncpointManager::~SyncpointManager() = default; 28SyncpointManager::~SyncpointManager() = default;
29 29
30u32 SyncpointManager::ReserveSyncpoint(u32 id, bool clientManaged) { 30u32 SyncpointManager::ReserveSyncpoint(u32 id, bool client_managed) {
31 if (syncpoints.at(id).reserved) { 31 if (syncpoints.at(id).reserved) {
32 ASSERT_MSG(false, "Requested syncpoint is in use"); 32 ASSERT_MSG(false, "Requested syncpoint is in use");
33 return 0; 33 return 0;
34 } 34 }
35 35
36 syncpoints.at(id).reserved = true; 36 syncpoints.at(id).reserved = true;
37 syncpoints.at(id).interfaceManaged = clientManaged; 37 syncpoints.at(id).interface_managed = client_managed;
38 38
39 return id; 39 return id;
40} 40}
@@ -49,9 +49,9 @@ u32 SyncpointManager::FindFreeSyncpoint() {
49 return 0; 49 return 0;
50} 50}
51 51
52u32 SyncpointManager::AllocateSyncpoint(bool clientManaged) { 52u32 SyncpointManager::AllocateSyncpoint(bool client_managed) {
53 std::lock_guard lock(reservation_lock); 53 std::lock_guard lock(reservation_lock);
54 return ReserveSyncpoint(FindFreeSyncpoint(), clientManaged); 54 return ReserveSyncpoint(FindFreeSyncpoint(), client_managed);
55} 55}
56 56
57void SyncpointManager::FreeSyncpoint(u32 id) { 57void SyncpointManager::FreeSyncpoint(u32 id) {
@@ -64,7 +64,7 @@ bool SyncpointManager::IsSyncpointAllocated(u32 id) {
64 return (id <= SyncpointCount) && syncpoints[id].reserved; 64 return (id <= SyncpointCount) && syncpoints[id].reserved;
65} 65}
66 66
67bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) { 67bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) const {
68 const SyncpointInfo& syncpoint{syncpoints.at(id)}; 68 const SyncpointInfo& syncpoint{syncpoints.at(id)};
69 69
70 if (!syncpoint.reserved) { 70 if (!syncpoint.reserved) {
@@ -74,10 +74,10 @@ bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) {
74 74
75 // If the interface manages counters then we don't keep track of the maximum value as it handles 75 // If the interface manages counters then we don't keep track of the maximum value as it handles
76 // sanity checking the values then 76 // sanity checking the values then
77 if (syncpoint.interfaceManaged) { 77 if (syncpoint.interface_managed) {
78 return static_cast<s32>(syncpoint.counterMin - threshold) >= 0; 78 return static_cast<s32>(syncpoint.counter_min - threshold) >= 0;
79 } else { 79 } else {
80 return (syncpoint.counterMax - threshold) >= (syncpoint.counterMin - threshold); 80 return (syncpoint.counter_max - threshold) >= (syncpoint.counter_min - threshold);
81 } 81 }
82} 82}
83 83
@@ -87,7 +87,7 @@ u32 SyncpointManager::IncrementSyncpointMaxExt(u32 id, u32 amount) {
87 return 0; 87 return 0;
88 } 88 }
89 89
90 return syncpoints.at(id).counterMax += amount; 90 return syncpoints.at(id).counter_max += amount;
91} 91}
92 92
93u32 SyncpointManager::ReadSyncpointMinValue(u32 id) { 93u32 SyncpointManager::ReadSyncpointMinValue(u32 id) {
@@ -96,7 +96,7 @@ u32 SyncpointManager::ReadSyncpointMinValue(u32 id) {
96 return 0; 96 return 0;
97 } 97 }
98 98
99 return syncpoints.at(id).counterMin; 99 return syncpoints.at(id).counter_min;
100} 100}
101 101
102u32 SyncpointManager::UpdateMin(u32 id) { 102u32 SyncpointManager::UpdateMin(u32 id) {
@@ -105,8 +105,8 @@ u32 SyncpointManager::UpdateMin(u32 id) {
105 return 0; 105 return 0;
106 } 106 }
107 107
108 syncpoints.at(id).counterMin = host1x.GetSyncpointManager().GetHostSyncpointValue(id); 108 syncpoints.at(id).counter_min = host1x.GetSyncpointManager().GetHostSyncpointValue(id);
109 return syncpoints.at(id).counterMin; 109 return syncpoints.at(id).counter_min;
110} 110}
111 111
112NvFence SyncpointManager::GetSyncpointFence(u32 id) { 112NvFence SyncpointManager::GetSyncpointFence(u32 id) {
@@ -115,7 +115,7 @@ NvFence SyncpointManager::GetSyncpointFence(u32 id) {
115 return NvFence{}; 115 return NvFence{};
116 } 116 }
117 117
118 return {.id = static_cast<s32>(id), .value = syncpoints.at(id).counterMax}; 118 return {.id = static_cast<s32>(id), .value = syncpoints.at(id).counter_max};
119} 119}
120 120
121} // namespace Service::Nvidia::NvCore 121} // namespace Service::Nvidia::NvCore
diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.h b/src/core/hle/service/nvdrv/core/syncpoint_manager.h
index 6b71cd33d..b76ef9032 100644
--- a/src/core/hle/service/nvdrv/core/syncpoint_manager.h
+++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.h
@@ -11,13 +11,9 @@
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/hle/service/nvdrv/nvdata.h" 12#include "core/hle/service/nvdrv/nvdata.h"
13 13
14namespace Tegra { 14namespace Tegra::Host1x {
15
16namespace Host1x {
17class Host1x; 15class Host1x;
18} // namespace Host1x 16} // namespace Tegra::Host1x
19
20} // namespace Tegra
21 17
22namespace Service::Nvidia::NvCore { 18namespace Service::Nvidia::NvCore {
23 19
@@ -54,15 +50,15 @@ public:
54 * @brief Finds a free syncpoint and reserves it 50 * @brief Finds a free syncpoint and reserves it
55 * @return The ID of the reserved syncpoint 51 * @return The ID of the reserved syncpoint
56 */ 52 */
57 u32 AllocateSyncpoint(bool clientManaged); 53 u32 AllocateSyncpoint(bool client_managed);
58 54
59 /** 55 /**
60 * @url 56 * @url
61 * https://github.com/Jetson-TX1-AndroidTV/android_kernel_jetson_tx1_hdmi_primary/blob/8f74a72394efb871cb3f886a3de2998cd7ff2990/drivers/gpu/host1x/syncpt.c#L259 57 * https://github.com/Jetson-TX1-AndroidTV/android_kernel_jetson_tx1_hdmi_primary/blob/8f74a72394efb871cb3f886a3de2998cd7ff2990/drivers/gpu/host1x/syncpt.c#L259
62 */ 58 */
63 bool HasSyncpointExpired(u32 id, u32 threshold); 59 bool HasSyncpointExpired(u32 id, u32 threshold) const;
64 60
65 bool IsFenceSignalled(NvFence fence) { 61 bool IsFenceSignalled(NvFence fence) const {
66 return HasSyncpointExpired(fence.id, fence.value); 62 return HasSyncpointExpired(fence.id, fence.value);
67 } 63 }
68 64
@@ -107,7 +103,7 @@ private:
107 /** 103 /**
108 * @note reservation_lock should be locked when calling this 104 * @note reservation_lock should be locked when calling this
109 */ 105 */
110 u32 ReserveSyncpoint(u32 id, bool clientManaged); 106 u32 ReserveSyncpoint(u32 id, bool client_managed);
111 107
112 /** 108 /**
113 * @return The ID of the first free syncpoint 109 * @return The ID of the first free syncpoint
@@ -115,15 +111,15 @@ private:
115 u32 FindFreeSyncpoint(); 111 u32 FindFreeSyncpoint();
116 112
117 struct SyncpointInfo { 113 struct SyncpointInfo {
118 std::atomic<u32> counterMin; //!< The least value the syncpoint can be (The value it was 114 std::atomic<u32> counter_min; //!< The least value the syncpoint can be (The value it was
119 //!< when it was last synchronized with host1x) 115 //!< when it was last synchronized with host1x)
120 std::atomic<u32> counterMax; //!< The maximum value the syncpoint can reach according to the 116 std::atomic<u32> counter_max; //!< The maximum value the syncpoint can reach according to
121 //!< current usage 117 //!< the current usage
122 bool interfaceManaged; //!< If the syncpoint is managed by a host1x client interface, a 118 bool interface_managed; //!< If the syncpoint is managed by a host1x client interface, a
123 //!< client interface is a HW block that can handle host1x 119 //!< client interface is a HW block that can handle host1x
124 //!< transactions on behalf of a host1x client (Which would otherwise 120 //!< transactions on behalf of a host1x client (Which would
125 //!< need to be manually synced using PIO which is synchronous and 121 //!< otherwise need to be manually synced using PIO which is
126 //!< requires direct cooperation of the CPU) 122 //!< synchronous and requires direct cooperation of the CPU)
127 bool reserved; //!< If the syncpoint is reserved or not, not to be confused with a reserved 123 bool reserved; //!< If the syncpoint is reserved or not, not to be confused with a reserved
128 //!< value 124 //!< value
129 }; 125 };
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
index 192503ffc..6411dbf43 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -106,7 +106,7 @@ NvResult nvhost_as_gpu::AllocAsEx(const std::vector<u8>& input, std::vector<u8>&
106 return NvResult::BadValue; 106 return NvResult::BadValue;
107 } 107 }
108 108
109 if (!(params.big_page_size & VM::SUPPORTED_BIG_PAGE_SIZES)) { 109 if ((params.big_page_size & VM::SUPPORTED_BIG_PAGE_SIZES) == 0) {
110 LOG_ERROR(Service_NVDRV, "Unsupported big page size: 0x{:X}!", params.big_page_size); 110 LOG_ERROR(Service_NVDRV, "Unsupported big page size: 0x{:X}!", params.big_page_size);
111 return NvResult::BadValue; 111 return NvResult::BadValue;
112 } 112 }
@@ -124,12 +124,13 @@ NvResult nvhost_as_gpu::AllocAsEx(const std::vector<u8>& input, std::vector<u8>&
124 vm.va_range_end = params.va_range_end; 124 vm.va_range_end = params.va_range_end;
125 } 125 }
126 126
127 const u64 start_pages{vm.va_range_start >> VM::PAGE_SIZE_BITS}; 127 const auto start_pages{static_cast<u32>(vm.va_range_start >> VM::PAGE_SIZE_BITS)};
128 const u64 end_pages{vm.va_range_split >> VM::PAGE_SIZE_BITS}; 128 const auto end_pages{static_cast<u32>(vm.va_range_split >> VM::PAGE_SIZE_BITS)};
129 vm.small_page_allocator = std::make_shared<VM::Allocator>(start_pages, end_pages); 129 vm.small_page_allocator = std::make_shared<VM::Allocator>(start_pages, end_pages);
130 130
131 const u64 start_big_pages{vm.va_range_split >> vm.big_page_size_bits}; 131 const auto start_big_pages{static_cast<u32>(vm.va_range_split >> vm.big_page_size_bits)};
132 const u64 end_big_pages{(vm.va_range_end - vm.va_range_split) >> vm.big_page_size_bits}; 132 const auto end_big_pages{
133 static_cast<u32>((vm.va_range_end - vm.va_range_split) >> vm.big_page_size_bits)};
133 vm.big_page_allocator = std::make_unique<VM::Allocator>(start_big_pages, end_big_pages); 134 vm.big_page_allocator = std::make_unique<VM::Allocator>(start_big_pages, end_big_pages);
134 135
135 gmmu = std::make_shared<Tegra::MemoryManager>(system, 40, vm.big_page_size_bits, 136 gmmu = std::make_shared<Tegra::MemoryManager>(system, 40, vm.big_page_size_bits,
@@ -210,10 +211,11 @@ void nvhost_as_gpu::FreeMappingLocked(u64 offset) {
210 211
211 // Sparse mappings shouldn't be fully unmapped, just returned to their sparse state 212 // Sparse mappings shouldn't be fully unmapped, just returned to their sparse state
212 // Only FreeSpace can unmap them fully 213 // Only FreeSpace can unmap them fully
213 if (mapping->sparse_alloc) 214 if (mapping->sparse_alloc) {
214 gmmu->MapSparse(offset, mapping->size, mapping->big_page); 215 gmmu->MapSparse(offset, mapping->size, mapping->big_page);
215 else 216 } else {
216 gmmu->Unmap(offset, mapping->size); 217 gmmu->Unmap(offset, mapping->size);
218 }
217 219
218 mapping_map.erase(offset); 220 mapping_map.erase(offset);
219} 221}
@@ -256,7 +258,7 @@ NvResult nvhost_as_gpu::FreeSpace(const std::vector<u8>& input, std::vector<u8>&
256 allocator.Free(static_cast<u32>(params.offset >> page_size_bits), 258 allocator.Free(static_cast<u32>(params.offset >> page_size_bits),
257 static_cast<u32>(allocation.size >> page_size_bits)); 259 static_cast<u32>(allocation.size >> page_size_bits));
258 allocation_map.erase(params.offset); 260 allocation_map.erase(params.offset);
259 } catch ([[maybe_unused]] const std::out_of_range& e) { 261 } catch (const std::out_of_range&) {
260 return NvResult::BadValue; 262 return NvResult::BadValue;
261 } 263 }
262 264
@@ -351,7 +353,7 @@ NvResult nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8
351 gmmu->Map(gpu_address, cpu_address, params.mapping_size, mapping->big_page); 353 gmmu->Map(gpu_address, cpu_address, params.mapping_size, mapping->big_page);
352 354
353 return NvResult::Success; 355 return NvResult::Success;
354 } catch ([[maybe_unused]] const std::out_of_range& e) { 356 } catch (const std::out_of_range&) {
355 LOG_WARNING(Service_NVDRV, "Cannot remap an unmapped GPU address space region: 0x{:X}", 357 LOG_WARNING(Service_NVDRV, "Cannot remap an unmapped GPU address space region: 0x{:X}",
356 params.offset); 358 params.offset);
357 return NvResult::BadValue; 359 return NvResult::BadValue;
@@ -367,11 +369,11 @@ NvResult nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8
367 u64 size{params.mapping_size ? params.mapping_size : handle->orig_size}; 369 u64 size{params.mapping_size ? params.mapping_size : handle->orig_size};
368 370
369 bool big_page{[&]() { 371 bool big_page{[&]() {
370 if (Common::IsAligned(handle->align, vm.big_page_size)) 372 if (Common::IsAligned(handle->align, vm.big_page_size)) {
371 return true; 373 return true;
372 else if (Common::IsAligned(handle->align, VM::YUZU_PAGESIZE)) 374 } else if (Common::IsAligned(handle->align, VM::YUZU_PAGESIZE)) {
373 return false; 375 return false;
374 else { 376 } else {
375 ASSERT(false); 377 ASSERT(false);
376 return false; 378 return false;
377 } 379 }
@@ -450,7 +452,7 @@ NvResult nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8
450 } 452 }
451 453
452 mapping_map.erase(params.offset); 454 mapping_map.erase(params.offset);
453 } catch ([[maybe_unused]] const std::out_of_range& e) { 455 } catch (const std::out_of_range&) {
454 LOG_WARNING(Service_NVDRV, "Couldn't find region to unmap at 0x{:X}", params.offset); 456 LOG_WARNING(Service_NVDRV, "Couldn't find region to unmap at 0x{:X}", params.offset);
455 } 457 }
456 458
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h
index 4aa738b41..0b56d7070 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h
@@ -79,7 +79,7 @@ private:
79 // Used for waiting on a syncpoint & canceling it. 79 // Used for waiting on a syncpoint & canceling it.
80 Tegra::Host1x::SyncpointManager::ActionHandle wait_handle{}; 80 Tegra::Host1x::SyncpointManager::ActionHandle wait_handle{};
81 81
82 bool IsBeingUsed() { 82 bool IsBeingUsed() const {
83 const auto current_status = status.load(std::memory_order_acquire); 83 const auto current_status = status.load(std::memory_order_acquire);
84 return current_status == EventState::Waiting || 84 return current_status == EventState::Waiting ||
85 current_status == EventState::Cancelling || 85 current_status == EventState::Cancelling ||
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
index 32e45540d..45a759fa8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -184,7 +184,7 @@ NvResult nvhost_gpu::AllocGPFIFOEx2(const std::vector<u8>& input, std::vector<u8
184 params.num_entries, params.flags, params.unk0, params.unk1, params.unk2, 184 params.num_entries, params.flags, params.unk0, params.unk1, params.unk2,
185 params.unk3); 185 params.unk3);
186 186
187 if (channel_state->initiated) { 187 if (channel_state->initialized) {
188 LOG_CRITICAL(Service_NVDRV, "Already allocated!"); 188 LOG_CRITICAL(Service_NVDRV, "Already allocated!");
189 return NvResult::AlreadyAllocated; 189 return NvResult::AlreadyAllocated;
190 } 190 }
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp
index fed537039..1703f9cc3 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp
@@ -5,13 +5,12 @@
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/core.h" 7#include "core/core.h"
8#include "core/hle/service/nvdrv/core/container.h"
8#include "core/hle/service/nvdrv/devices/nvhost_nvdec.h" 9#include "core/hle/service/nvdrv/devices/nvhost_nvdec.h"
9#include "video_core/renderer_base.h" 10#include "video_core/renderer_base.h"
10 11
11namespace Service::Nvidia::Devices { 12namespace Service::Nvidia::Devices {
12 13
13u32 nvhost_nvdec::next_id{};
14
15nvhost_nvdec::nvhost_nvdec(Core::System& system_, NvCore::Container& core_) 14nvhost_nvdec::nvhost_nvdec(Core::System& system_, NvCore::Container& core_)
16 : nvhost_nvdec_common{system_, core_, NvCore::ChannelType::NvDec} {} 15 : nvhost_nvdec_common{system_, core_, NvCore::ChannelType::NvDec} {}
17nvhost_nvdec::~nvhost_nvdec() = default; 16nvhost_nvdec::~nvhost_nvdec() = default;
@@ -22,8 +21,9 @@ NvResult nvhost_nvdec::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>&
22 case 0x0: 21 case 0x0:
23 switch (command.cmd) { 22 switch (command.cmd) {
24 case 0x1: { 23 case 0x1: {
25 if (!fd_to_id.contains(fd)) { 24 auto& host1x_file = core.Host1xDeviceFile();
26 fd_to_id[fd] = next_id++; 25 if (!host1x_file.fd_to_id.contains(fd)) {
26 host1x_file.fd_to_id[fd] = host1x_file.nvdec_next_id++;
27 } 27 }
28 return Submit(fd, input, output); 28 return Submit(fd, input, output);
29 } 29 }
@@ -74,8 +74,9 @@ void nvhost_nvdec::OnOpen(DeviceFD fd) {
74 74
75void nvhost_nvdec::OnClose(DeviceFD fd) { 75void nvhost_nvdec::OnClose(DeviceFD fd) {
76 LOG_INFO(Service_NVDRV, "NVDEC video stream ended"); 76 LOG_INFO(Service_NVDRV, "NVDEC video stream ended");
77 const auto iter = fd_to_id.find(fd); 77 auto& host1x_file = core.Host1xDeviceFile();
78 if (iter != fd_to_id.end()) { 78 const auto iter = host1x_file.fd_to_id.find(fd);
79 if (iter != host1x_file.fd_to_id.end()) {
79 system.GPU().ClearCdmaInstance(iter->second); 80 system.GPU().ClearCdmaInstance(iter->second);
80 } 81 }
81 system.AudioCore().SetNVDECActive(false); 82 system.AudioCore().SetNVDECActive(false);
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h
index 3261ce1d4..c1b4e53e8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h
@@ -22,9 +22,6 @@ public:
22 22
23 void OnOpen(DeviceFD fd) override; 23 void OnOpen(DeviceFD fd) override;
24 void OnClose(DeviceFD fd) override; 24 void OnClose(DeviceFD fd) override;
25
26private:
27 static u32 next_id;
28}; 25};
29 26
30} // namespace Service::Nvidia::Devices 27} // namespace Service::Nvidia::Devices
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 2ec1ad3e9..99eede702 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp
@@ -46,13 +46,11 @@ std::size_t WriteVectors(std::vector<u8>& dst, const std::vector<T>& src, std::s
46} 46}
47} // Anonymous namespace 47} // Anonymous namespace
48 48
49std::unordered_map<DeviceFD, u32> nvhost_nvdec_common::fd_to_id{};
50std::deque<u32> nvhost_nvdec_common::syncpts_accumulated{};
51
52nvhost_nvdec_common::nvhost_nvdec_common(Core::System& system_, NvCore::Container& core_, 49nvhost_nvdec_common::nvhost_nvdec_common(Core::System& system_, NvCore::Container& core_,
53 NvCore::ChannelType channel_type_) 50 NvCore::ChannelType channel_type_)
54 : nvdevice{system_}, core{core_}, syncpoint_manager{core.GetSyncpointManager()}, 51 : nvdevice{system_}, core{core_}, syncpoint_manager{core.GetSyncpointManager()},
55 nvmap{core.GetNvMapFile()}, channel_type{channel_type_} { 52 nvmap{core.GetNvMapFile()}, channel_type{channel_type_} {
53 auto& syncpts_accumulated = core.Host1xDeviceFile().syncpts_accumulated;
56 if (syncpts_accumulated.empty()) { 54 if (syncpts_accumulated.empty()) {
57 channel_syncpoint = syncpoint_manager.AllocateSyncpoint(false); 55 channel_syncpoint = syncpoint_manager.AllocateSyncpoint(false);
58 } else { 56 } else {
@@ -60,8 +58,9 @@ nvhost_nvdec_common::nvhost_nvdec_common(Core::System& system_, NvCore::Containe
60 syncpts_accumulated.pop_front(); 58 syncpts_accumulated.pop_front();
61 } 59 }
62} 60}
61
63nvhost_nvdec_common::~nvhost_nvdec_common() { 62nvhost_nvdec_common::~nvhost_nvdec_common() {
64 syncpts_accumulated.push_back(channel_syncpoint); 63 core.Host1xDeviceFile().syncpts_accumulated.push_back(channel_syncpoint);
65} 64}
66 65
67NvResult nvhost_nvdec_common::SetNVMAPfd(const std::vector<u8>& input) { 66NvResult nvhost_nvdec_common::SetNVMAPfd(const std::vector<u8>& input) {
@@ -108,7 +107,7 @@ NvResult nvhost_nvdec_common::Submit(DeviceFD fd, const std::vector<u8>& input,
108 Tegra::ChCommandHeaderList cmdlist(cmd_buffer.word_count); 107 Tegra::ChCommandHeaderList cmdlist(cmd_buffer.word_count);
109 system.Memory().ReadBlock(object->address + cmd_buffer.offset, cmdlist.data(), 108 system.Memory().ReadBlock(object->address + cmd_buffer.offset, cmdlist.data(),
110 cmdlist.size() * sizeof(u32)); 109 cmdlist.size() * sizeof(u32));
111 gpu.PushCommandBuffer(fd_to_id[fd], cmdlist); 110 gpu.PushCommandBuffer(core.Host1xDeviceFile().fd_to_id[fd], cmdlist);
112 } 111 }
113 std::memcpy(output.data(), &params, sizeof(IoctlSubmit)); 112 std::memcpy(output.data(), &params, sizeof(IoctlSubmit));
114 // Some games expect command_buffers to be written back 113 // Some games expect command_buffers to be written back
@@ -186,8 +185,4 @@ Kernel::KEvent* nvhost_nvdec_common::QueryEvent(u32 event_id) {
186 return nullptr; 185 return nullptr;
187} 186}
188 187
189void nvhost_nvdec_common::Reset() {
190 fd_to_id.clear();
191}
192
193} // namespace Service::Nvidia::Devices 188} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h
index 93990bb9b..fe76100c8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h
@@ -25,8 +25,6 @@ public:
25 NvCore::ChannelType channel_type); 25 NvCore::ChannelType channel_type);
26 ~nvhost_nvdec_common() override; 26 ~nvhost_nvdec_common() override;
27 27
28 static void Reset();
29
30protected: 28protected:
31 struct IoctlSetNvmapFD { 29 struct IoctlSetNvmapFD {
32 s32_le nvmap_fd{}; 30 s32_le nvmap_fd{};
@@ -119,7 +117,6 @@ protected:
119 117
120 Kernel::KEvent* QueryEvent(u32 event_id) override; 118 Kernel::KEvent* QueryEvent(u32 event_id) override;
121 119
122 static std::unordered_map<DeviceFD, u32> fd_to_id;
123 u32 channel_syncpoint; 120 u32 channel_syncpoint;
124 s32_le nvmap_fd{}; 121 s32_le nvmap_fd{};
125 u32_le submit_timeout{}; 122 u32_le submit_timeout{};
@@ -128,8 +125,6 @@ protected:
128 NvCore::NvMap& nvmap; 125 NvCore::NvMap& nvmap;
129 NvCore::ChannelType channel_type; 126 NvCore::ChannelType channel_type;
130 std::array<u32, MaxSyncPoints> device_syncpoints{}; 127 std::array<u32, MaxSyncPoints> device_syncpoints{};
131
132 static std::deque<u32> syncpts_accumulated;
133}; 128};
134}; // namespace Devices 129}; // namespace Devices
135} // namespace Service::Nvidia 130} // namespace Service::Nvidia
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
index 2e4ff988c..73f97136e 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
@@ -4,13 +4,12 @@
4#include "common/assert.h" 4#include "common/assert.h"
5#include "common/logging/log.h" 5#include "common/logging/log.h"
6#include "core/core.h" 6#include "core/core.h"
7#include "core/hle/service/nvdrv/core/container.h"
7#include "core/hle/service/nvdrv/devices/nvhost_vic.h" 8#include "core/hle/service/nvdrv/devices/nvhost_vic.h"
8#include "video_core/renderer_base.h" 9#include "video_core/renderer_base.h"
9 10
10namespace Service::Nvidia::Devices { 11namespace Service::Nvidia::Devices {
11 12
12u32 nvhost_vic::next_id{};
13
14nvhost_vic::nvhost_vic(Core::System& system_, NvCore::Container& core_) 13nvhost_vic::nvhost_vic(Core::System& system_, NvCore::Container& core_)
15 : nvhost_nvdec_common{system_, core_, NvCore::ChannelType::VIC} {} 14 : nvhost_nvdec_common{system_, core_, NvCore::ChannelType::VIC} {}
16 15
@@ -21,11 +20,13 @@ NvResult nvhost_vic::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& i
21 switch (command.group) { 20 switch (command.group) {
22 case 0x0: 21 case 0x0:
23 switch (command.cmd) { 22 switch (command.cmd) {
24 case 0x1: 23 case 0x1: {
25 if (!fd_to_id.contains(fd)) { 24 auto& host1x_file = core.Host1xDeviceFile();
26 fd_to_id[fd] = next_id++; 25 if (!host1x_file.fd_to_id.contains(fd)) {
26 host1x_file.fd_to_id[fd] = host1x_file.vic_next_id++;
27 } 27 }
28 return Submit(fd, input, output); 28 return Submit(fd, input, output);
29 }
29 case 0x2: 30 case 0x2:
30 return GetSyncpoint(input, output); 31 return GetSyncpoint(input, output);
31 case 0x3: 32 case 0x3:
@@ -69,8 +70,9 @@ NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, const std::vector<u8>& i
69void nvhost_vic::OnOpen(DeviceFD fd) {} 70void nvhost_vic::OnOpen(DeviceFD fd) {}
70 71
71void nvhost_vic::OnClose(DeviceFD fd) { 72void nvhost_vic::OnClose(DeviceFD fd) {
72 const auto iter = fd_to_id.find(fd); 73 auto& host1x_file = core.Host1xDeviceFile();
73 if (iter != fd_to_id.end()) { 74 const auto iter = host1x_file.fd_to_id.find(fd);
75 if (iter != host1x_file.fd_to_id.end()) {
74 system.GPU().ClearCdmaInstance(iter->second); 76 system.GPU().ClearCdmaInstance(iter->second);
75 } 77 }
76} 78}
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.h b/src/core/hle/service/nvdrv/devices/nvhost_vic.h
index 59e23b41e..f164caafb 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_vic.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.h
@@ -21,8 +21,5 @@ public:
21 21
22 void OnOpen(DeviceFD fd) override; 22 void OnOpen(DeviceFD fd) override;
23 void OnClose(DeviceFD fd) override; 23 void OnClose(DeviceFD fd) override;
24
25private:
26 static u32 next_id;
27}; 24};
28} // namespace Service::Nvidia::Devices 25} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h
index 52e1d7cff..e9bfd0358 100644
--- a/src/core/hle/service/nvdrv/devices/nvmap.h
+++ b/src/core/hle/service/nvdrv/devices/nvmap.h
@@ -23,8 +23,8 @@ public:
23 explicit nvmap(Core::System& system_, NvCore::Container& container); 23 explicit nvmap(Core::System& system_, NvCore::Container& container);
24 ~nvmap() override; 24 ~nvmap() override;
25 25
26 nvmap(nvmap const&) = delete; 26 nvmap(const nvmap&) = delete;
27 nvmap& operator=(nvmap const&) = delete; 27 nvmap& operator=(const nvmap&) = delete;
28 28
29 NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input, 29 NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
30 std::vector<u8>& output) override; 30 std::vector<u8>& output) override;
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index 7929443d2..5e7b7468f 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -101,9 +101,7 @@ Module::Module(Core::System& system)
101 }; 101 };
102} 102}
103 103
104Module::~Module() { 104Module::~Module() {}
105 Devices::nvhost_nvdec_common::Reset();
106}
107 105
108NvResult Module::VerifyFD(DeviceFD fd) const { 106NvResult Module::VerifyFD(DeviceFD fd) const {
109 if (fd < 0) { 107 if (fd < 0) {
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index a2aeb80b4..146d046a9 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -46,7 +46,7 @@ class Module;
46 46
47class EventInterface { 47class EventInterface {
48public: 48public:
49 EventInterface(Module& module_); 49 explicit EventInterface(Module& module_);
50 ~EventInterface(); 50 ~EventInterface();
51 51
52 Kernel::KEvent* CreateEvent(std::string name); 52 Kernel::KEvent* CreateEvent(std::string name);