summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2023-12-31 20:55:15 +0100
committerGravatar Liam2024-01-18 21:12:30 -0500
commit590d9b7e1d875e0403fb87cfcd4a8d52c50e2b81 (patch)
treeb9eb43c5a4af892d5fda77fac241099c166c2380 /src/core
parentSMMU: Fix software rendering and cleanup (diff)
downloadyuzu-590d9b7e1d875e0403fb87cfcd4a8d52c50e2b81.tar.gz
yuzu-590d9b7e1d875e0403fb87cfcd4a8d52c50e2b81.tar.xz
yuzu-590d9b7e1d875e0403fb87cfcd4a8d52c50e2b81.zip
Core: Clang format and other small issues.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device_memory_manager.h7
-rw-r--r--src/core/device_memory_manager.inc50
-rw-r--r--src/core/guest_memory.h5
-rw-r--r--src/core/hle/service/hle_ipc.cpp2
-rw-r--r--src/core/hle/service/nvdrv/core/container.cpp8
-rw-r--r--src/core/hle/service/nvdrv/core/container.h8
-rw-r--r--src/core/hle/service/nvdrv/core/heap_mapper.cpp25
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.cpp8
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.h11
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_vic.cpp2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvmap.cpp4
-rw-r--r--src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp10
-rw-r--r--src/core/hle/service/nvnflinger/fb_share_buffer_manager.h3
-rw-r--r--src/core/memory.h2
15 files changed, 95 insertions, 52 deletions
diff --git a/src/core/device_memory_manager.h b/src/core/device_memory_manager.h
index 0f6599cfe..f9cb13a7a 100644
--- a/src/core/device_memory_manager.h
+++ b/src/core/device_memory_manager.h
@@ -27,13 +27,13 @@ struct DeviceMemoryManagerAllocator;
27template <typename Traits> 27template <typename Traits>
28class DeviceMemoryManager { 28class DeviceMemoryManager {
29 using DeviceInterface = typename Traits::DeviceInterface; 29 using DeviceInterface = typename Traits::DeviceInterface;
30 using DeviceMethods = Traits::DeviceMethods; 30 using DeviceMethods = typename Traits::DeviceMethods;
31 31
32public: 32public:
33 DeviceMemoryManager(const DeviceMemory& device_memory); 33 DeviceMemoryManager(const DeviceMemory& device_memory);
34 ~DeviceMemoryManager(); 34 ~DeviceMemoryManager();
35 35
36 void BindInterface(DeviceInterface* interface); 36 void BindInterface(DeviceInterface* device_inter);
37 37
38 DAddr Allocate(size_t size); 38 DAddr Allocate(size_t size);
39 void AllocateFixed(DAddr start, size_t size); 39 void AllocateFixed(DAddr start, size_t size);
@@ -111,6 +111,7 @@ public:
111private: 111private:
112 static constexpr size_t device_virtual_bits = Traits::device_virtual_bits; 112 static constexpr size_t device_virtual_bits = Traits::device_virtual_bits;
113 static constexpr size_t device_as_size = 1ULL << device_virtual_bits; 113 static constexpr size_t device_as_size = 1ULL << device_virtual_bits;
114 static constexpr size_t physical_min_bits = 32;
114 static constexpr size_t physical_max_bits = 33; 115 static constexpr size_t physical_max_bits = 33;
115 static constexpr size_t page_bits = 12; 116 static constexpr size_t page_bits = 12;
116 static constexpr size_t page_size = 1ULL << page_bits; 117 static constexpr size_t page_size = 1ULL << page_bits;
@@ -143,7 +144,7 @@ private:
143 std::unique_ptr<DeviceMemoryManagerAllocator<Traits>> impl; 144 std::unique_ptr<DeviceMemoryManagerAllocator<Traits>> impl;
144 145
145 const uintptr_t physical_base; 146 const uintptr_t physical_base;
146 DeviceInterface* interface; 147 DeviceInterface* device_inter;
147 Common::VirtualBuffer<u32> compressed_physical_ptr; 148 Common::VirtualBuffer<u32> compressed_physical_ptr;
148 Common::VirtualBuffer<u32> compressed_device_addr; 149 Common::VirtualBuffer<u32> compressed_device_addr;
149 Common::VirtualBuffer<u32> continuity_tracker; 150 Common::VirtualBuffer<u32> continuity_tracker;
diff --git a/src/core/device_memory_manager.inc b/src/core/device_memory_manager.inc
index 175f0cd5f..a0eb4214e 100644
--- a/src/core/device_memory_manager.inc
+++ b/src/core/device_memory_manager.inc
@@ -12,6 +12,7 @@
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/div_ceil.h" 13#include "common/div_ceil.h"
14#include "common/scope_exit.h" 14#include "common/scope_exit.h"
15#include "common/settings.h"
15#include "core/device_memory.h" 16#include "core/device_memory.h"
16#include "core/device_memory_manager.h" 17#include "core/device_memory_manager.h"
17#include "core/memory.h" 18#include "core/memory.h"
@@ -162,20 +163,39 @@ struct DeviceMemoryManagerAllocator {
162template <typename Traits> 163template <typename Traits>
163DeviceMemoryManager<Traits>::DeviceMemoryManager(const DeviceMemory& device_memory_) 164DeviceMemoryManager<Traits>::DeviceMemoryManager(const DeviceMemory& device_memory_)
164 : physical_base{reinterpret_cast<const uintptr_t>(device_memory_.buffer.BackingBasePointer())}, 165 : physical_base{reinterpret_cast<const uintptr_t>(device_memory_.buffer.BackingBasePointer())},
165 interface{nullptr}, compressed_physical_ptr(device_as_size >> Memory::YUZU_PAGEBITS), 166 device_inter{nullptr}, compressed_physical_ptr(device_as_size >> Memory::YUZU_PAGEBITS),
166 compressed_device_addr(1ULL << (physical_max_bits - Memory::YUZU_PAGEBITS)), 167 compressed_device_addr(1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
168 Settings::MemoryLayout::Memory_4Gb
169 ? physical_min_bits
170 : physical_max_bits) -
171 Memory::YUZU_PAGEBITS)),
167 continuity_tracker(device_as_size >> Memory::YUZU_PAGEBITS), 172 continuity_tracker(device_as_size >> Memory::YUZU_PAGEBITS),
168 cpu_backing_address(device_as_size >> Memory::YUZU_PAGEBITS) { 173 cpu_backing_address(device_as_size >> Memory::YUZU_PAGEBITS) {
169 impl = std::make_unique<DeviceMemoryManagerAllocator<Traits>>(); 174 impl = std::make_unique<DeviceMemoryManagerAllocator<Traits>>();
170 cached_pages = std::make_unique<CachedPages>(); 175 cached_pages = std::make_unique<CachedPages>();
176
177 const size_t total_virtual = device_as_size >> Memory::YUZU_PAGEBITS;
178 for (size_t i = 0; i < total_virtual; i++) {
179 compressed_physical_ptr[i] = 0;
180 continuity_tracker[i] = 1;
181 cpu_backing_address[i] = 0;
182 }
183 const size_t total_phys = 1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
184 Settings::MemoryLayout::Memory_4Gb
185 ? physical_min_bits
186 : physical_max_bits) -
187 Memory::YUZU_PAGEBITS);
188 for (size_t i = 0; i < total_phys; i++) {
189 compressed_device_addr[i] = 0;
190 }
171} 191}
172 192
173template <typename Traits> 193template <typename Traits>
174DeviceMemoryManager<Traits>::~DeviceMemoryManager() = default; 194DeviceMemoryManager<Traits>::~DeviceMemoryManager() = default;
175 195
176template <typename Traits> 196template <typename Traits>
177void DeviceMemoryManager<Traits>::BindInterface(DeviceInterface* interface_) { 197void DeviceMemoryManager<Traits>::BindInterface(DeviceInterface* device_inter_) {
178 interface = interface_; 198 device_inter = device_inter_;
179} 199}
180 200
181template <typename Traits> 201template <typename Traits>
@@ -232,7 +252,7 @@ template <typename Traits>
232void DeviceMemoryManager<Traits>::Unmap(DAddr address, size_t size) { 252void DeviceMemoryManager<Traits>::Unmap(DAddr address, size_t size) {
233 size_t start_page_d = address >> Memory::YUZU_PAGEBITS; 253 size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
234 size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS; 254 size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
235 interface->InvalidateRegion(address, size); 255 device_inter->InvalidateRegion(address, size);
236 std::scoped_lock lk(mapping_guard); 256 std::scoped_lock lk(mapping_guard);
237 for (size_t i = 0; i < num_pages; i++) { 257 for (size_t i = 0; i < num_pages; i++) {
238 auto phys_addr = compressed_physical_ptr[start_page_d + i]; 258 auto phys_addr = compressed_physical_ptr[start_page_d + i];
@@ -392,7 +412,7 @@ void DeviceMemoryManager<Traits>::WalkBlock(DAddr addr, std::size_t size, auto o
392 412
393template <typename Traits> 413template <typename Traits>
394void DeviceMemoryManager<Traits>::ReadBlock(DAddr address, void* dest_pointer, size_t size) { 414void DeviceMemoryManager<Traits>::ReadBlock(DAddr address, void* dest_pointer, size_t size) {
395 interface->FlushRegion(address, size); 415 device_inter->FlushRegion(address, size);
396 WalkBlock( 416 WalkBlock(
397 address, size, 417 address, size,
398 [&](size_t copy_amount, DAddr current_vaddr) { 418 [&](size_t copy_amount, DAddr current_vaddr) {
@@ -426,7 +446,7 @@ void DeviceMemoryManager<Traits>::WriteBlock(DAddr address, const void* src_poin
426 [&](const std::size_t copy_amount) { 446 [&](const std::size_t copy_amount) {
427 src_pointer = static_cast<const u8*>(src_pointer) + copy_amount; 447 src_pointer = static_cast<const u8*>(src_pointer) + copy_amount;
428 }); 448 });
429 interface->InvalidateRegion(address, size); 449 device_inter->InvalidateRegion(address, size);
430} 450}
431 451
432template <typename Traits> 452template <typename Traits>
@@ -468,14 +488,14 @@ void DeviceMemoryManager<Traits>::WriteBlockUnsafe(DAddr address, const void* sr
468} 488}
469 489
470template <typename Traits> 490template <typename Traits>
471size_t DeviceMemoryManager<Traits>::RegisterProcess(Memory::Memory* memory_interface) { 491size_t DeviceMemoryManager<Traits>::RegisterProcess(Memory::Memory* memory_device_inter) {
472 size_t new_id; 492 size_t new_id;
473 if (!id_pool.empty()) { 493 if (!id_pool.empty()) {
474 new_id = id_pool.front(); 494 new_id = id_pool.front();
475 id_pool.pop_front(); 495 id_pool.pop_front();
476 registered_processes[new_id] = memory_interface; 496 registered_processes[new_id] = memory_device_inter;
477 } else { 497 } else {
478 registered_processes.emplace_back(memory_interface); 498 registered_processes.emplace_back(memory_device_inter);
479 new_id = registered_processes.size() - 1U; 499 new_id = registered_processes.size() - 1U;
480 } 500 }
481 return new_id; 501 return new_id;
@@ -512,7 +532,7 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
512 size_t page = addr >> Memory::YUZU_PAGEBITS; 532 size_t page = addr >> Memory::YUZU_PAGEBITS;
513 auto [process_id, base_vaddress] = ExtractCPUBacking(page); 533 auto [process_id, base_vaddress] = ExtractCPUBacking(page);
514 size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS; 534 size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS;
515 auto* memory_interface = registered_processes[process_id]; 535 auto* memory_device_inter = registered_processes[process_id];
516 for (; page != page_end; ++page) { 536 for (; page != page_end; ++page) {
517 std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page); 537 std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page);
518 538
@@ -536,7 +556,7 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
536 uncache_bytes += Memory::YUZU_PAGESIZE; 556 uncache_bytes += Memory::YUZU_PAGESIZE;
537 } else if (uncache_bytes > 0) { 557 } else if (uncache_bytes > 0) {
538 lock(); 558 lock();
539 MarkRegionCaching(memory_interface, uncache_begin << Memory::YUZU_PAGEBITS, 559 MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS,
540 uncache_bytes, false); 560 uncache_bytes, false);
541 uncache_bytes = 0; 561 uncache_bytes = 0;
542 } 562 }
@@ -547,7 +567,7 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
547 cache_bytes += Memory::YUZU_PAGESIZE; 567 cache_bytes += Memory::YUZU_PAGESIZE;
548 } else if (cache_bytes > 0) { 568 } else if (cache_bytes > 0) {
549 lock(); 569 lock();
550 MarkRegionCaching(memory_interface, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes, 570 MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
551 true); 571 true);
552 cache_bytes = 0; 572 cache_bytes = 0;
553 } 573 }
@@ -555,12 +575,12 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
555 } 575 }
556 if (uncache_bytes > 0) { 576 if (uncache_bytes > 0) {
557 lock(); 577 lock();
558 MarkRegionCaching(memory_interface, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes, 578 MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes,
559 false); 579 false);
560 } 580 }
561 if (cache_bytes > 0) { 581 if (cache_bytes > 0) {
562 lock(); 582 lock();
563 MarkRegionCaching(memory_interface, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes, 583 MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
564 true); 584 true);
565 } 585 }
566} 586}
diff --git a/src/core/guest_memory.h b/src/core/guest_memory.h
index 0b349cc17..8030df73a 100644
--- a/src/core/guest_memory.h
+++ b/src/core/guest_memory.h
@@ -202,7 +202,8 @@ public:
202 } else { 202 } else {
203 this->m_memory.WriteBlockUnsafe(this->m_addr, this->data(), this->size_bytes()); 203 this->m_memory.WriteBlockUnsafe(this->m_addr, this->data(), this->size_bytes());
204 } 204 }
205 } else if constexpr ((FLAGS & GuestMemoryFlags::Safe) || (FLAGS & GuestMemoryFlags::Cached)) { 205 } else if constexpr ((FLAGS & GuestMemoryFlags::Safe) ||
206 (FLAGS & GuestMemoryFlags::Cached)) {
206 this->m_memory.InvalidateRegion(this->m_addr, this->size_bytes()); 207 this->m_memory.InvalidateRegion(this->m_addr, this->size_bytes());
207 } 208 }
208 } 209 }
@@ -215,4 +216,4 @@ using CpuGuestMemory = GuestMemory<Core::Memory::Memory, T, FLAGS>;
215template <typename T, GuestMemoryFlags FLAGS> 216template <typename T, GuestMemoryFlags FLAGS>
216using CpuGuestMemoryScoped = GuestMemoryScoped<Core::Memory::Memory, T, FLAGS>; 217using CpuGuestMemoryScoped = GuestMemoryScoped<Core::Memory::Memory, T, FLAGS>;
217 218
218} // namespace Tegra::Memory 219} // namespace Core::Memory
diff --git a/src/core/hle/service/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp
index 9f6274c7d..e491dd260 100644
--- a/src/core/hle/service/hle_ipc.cpp
+++ b/src/core/hle/service/hle_ipc.cpp
@@ -12,6 +12,7 @@
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14#include "common/scratch_buffer.h" 14#include "common/scratch_buffer.h"
15#include "core/guest_memory.h"
15#include "core/hle/kernel/k_auto_object.h" 16#include "core/hle/kernel/k_auto_object.h"
16#include "core/hle/kernel/k_handle_table.h" 17#include "core/hle/kernel/k_handle_table.h"
17#include "core/hle/kernel/k_process.h" 18#include "core/hle/kernel/k_process.h"
@@ -22,7 +23,6 @@
22#include "core/hle/service/hle_ipc.h" 23#include "core/hle/service/hle_ipc.h"
23#include "core/hle/service/ipc_helpers.h" 24#include "core/hle/service/ipc_helpers.h"
24#include "core/memory.h" 25#include "core/memory.h"
25#include "core/guest_memory.h"
26 26
27namespace Service { 27namespace Service {
28 28
diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp
index 4d3a9d696..d04b7f5ff 100644
--- a/src/core/hle/service/nvdrv/core/container.cpp
+++ b/src/core/hle/service/nvdrv/core/container.cpp
@@ -16,6 +16,12 @@
16 16
17namespace Service::Nvidia::NvCore { 17namespace Service::Nvidia::NvCore {
18 18
19Session::Session(size_t id_, Kernel::KProcess* process_, size_t smmu_id_)
20 : id{id_}, process{process_}, smmu_id{smmu_id_},
21 has_preallocated_area{}, mapper{}, is_active{} {}
22
23Session::~Session() = default;
24
19struct ContainerImpl { 25struct ContainerImpl {
20 explicit ContainerImpl(Container& core, Tegra::Host1x::Host1x& host1x_) 26 explicit ContainerImpl(Container& core, Tegra::Host1x::Host1x& host1x_)
21 : host1x{host1x_}, file{core, host1x_}, manager{host1x_}, device_file_data{} {} 27 : host1x{host1x_}, file{core, host1x_}, manager{host1x_}, device_file_data{} {}
@@ -54,8 +60,8 @@ size_t Container::OpenSession(Kernel::KProcess* process) {
54 impl->id_pool.pop_front(); 60 impl->id_pool.pop_front();
55 impl->sessions[new_id] = Session{new_id, process, smmu_id}; 61 impl->sessions[new_id] = Session{new_id, process, smmu_id};
56 } else { 62 } else {
57 impl->sessions.emplace_back(new_id, process, smmu_id);
58 new_id = impl->new_ids++; 63 new_id = impl->new_ids++;
64 impl->sessions.emplace_back(new_id, process, smmu_id);
59 } 65 }
60 auto& session = impl->sessions[new_id]; 66 auto& session = impl->sessions[new_id];
61 session.is_active = true; 67 session.is_active = true;
diff --git a/src/core/hle/service/nvdrv/core/container.h b/src/core/hle/service/nvdrv/core/container.h
index 86705cbc8..4b8452844 100644
--- a/src/core/hle/service/nvdrv/core/container.h
+++ b/src/core/hle/service/nvdrv/core/container.h
@@ -27,6 +27,14 @@ class SyncpointManager;
27struct ContainerImpl; 27struct ContainerImpl;
28 28
29struct Session { 29struct Session {
30 Session(size_t id_, Kernel::KProcess* process_, size_t smmu_id_);
31 ~Session();
32
33 Session(const Session&) = delete;
34 Session& operator=(const Session&) = delete;
35 Session(Session&&) = default;
36 Session& operator=(Session&&) = default;
37
30 size_t id; 38 size_t id;
31 Kernel::KProcess* process; 39 Kernel::KProcess* process;
32 size_t smmu_id; 40 size_t smmu_id;
diff --git a/src/core/hle/service/nvdrv/core/heap_mapper.cpp b/src/core/hle/service/nvdrv/core/heap_mapper.cpp
index 59d993bc6..c29191b92 100644
--- a/src/core/hle/service/nvdrv/core/heap_mapper.cpp
+++ b/src/core/hle/service/nvdrv/core/heap_mapper.cpp
@@ -124,10 +124,11 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
124 m_internal->base_set.clear(); 124 m_internal->base_set.clear();
125 const IntervalType interval{start, start + size}; 125 const IntervalType interval{start, start + size};
126 m_internal->base_set.insert(interval); 126 m_internal->base_set.insert(interval);
127 m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size, [this](VAddr start_addr, VAddr end_addr, int){ 127 m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size,
128 const IntervalType other{start_addr, end_addr}; 128 [this](VAddr start_addr, VAddr end_addr, int) {
129 m_internal->base_set.subtract(other); 129 const IntervalType other{start_addr, end_addr};
130 }); 130 m_internal->base_set.subtract(other);
131 });
131 if (!m_internal->base_set.empty()) { 132 if (!m_internal->base_set.empty()) {
132 auto it = m_internal->base_set.begin(); 133 auto it = m_internal->base_set.begin();
133 auto end_it = m_internal->base_set.end(); 134 auto end_it = m_internal->base_set.end();
@@ -136,7 +137,8 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
136 const VAddr inter_addr = it->lower(); 137 const VAddr inter_addr = it->lower();
137 const size_t offset = inter_addr - m_vaddress; 138 const size_t offset = inter_addr - m_vaddress;
138 const size_t sub_size = inter_addr_end - inter_addr; 139 const size_t sub_size = inter_addr_end - inter_addr;
139 m_internal->device_memory.Map(m_daddress + offset, m_vaddress + offset, sub_size, m_smmu_id); 140 m_internal->device_memory.Map(m_daddress + offset, m_vaddress + offset, sub_size,
141 m_smmu_id);
140 } 142 }
141 } 143 }
142 m_internal->mapping_overlaps += std::make_pair(interval, 1); 144 m_internal->mapping_overlaps += std::make_pair(interval, 1);
@@ -147,12 +149,13 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
147void HeapMapper::Unmap(VAddr start, size_t size) { 149void HeapMapper::Unmap(VAddr start, size_t size) {
148 std::scoped_lock lk(m_internal->guard); 150 std::scoped_lock lk(m_internal->guard);
149 m_internal->base_set.clear(); 151 m_internal->base_set.clear();
150 m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size, [this](VAddr start_addr, VAddr end_addr, int value) { 152 m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size,
151 if (value <= 1) { 153 [this](VAddr start_addr, VAddr end_addr, int value) {
152 const IntervalType other{start_addr, end_addr}; 154 if (value <= 1) {
153 m_internal->base_set.insert(other); 155 const IntervalType other{start_addr, end_addr};
154 } 156 m_internal->base_set.insert(other);
155 }); 157 }
158 });
156 if (!m_internal->base_set.empty()) { 159 if (!m_internal->base_set.empty()) {
157 auto it = m_internal->base_set.begin(); 160 auto it = m_internal->base_set.begin();
158 auto end_it = m_internal->base_set.end(); 161 auto end_it = m_internal->base_set.end();
diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp
index 296b4d8d2..6e59d4fe1 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/core/nvmap.cpp
@@ -13,8 +13,8 @@
13#include "core/memory.h" 13#include "core/memory.h"
14#include "video_core/host1x/host1x.h" 14#include "video_core/host1x/host1x.h"
15 15
16
17using Core::Memory::YUZU_PAGESIZE; 16using Core::Memory::YUZU_PAGESIZE;
17constexpr size_t BIG_PAGE_SIZE = YUZU_PAGESIZE * 16;
18 18
19namespace Service::Nvidia::NvCore { 19namespace Service::Nvidia::NvCore {
20NvMap::Handle::Handle(u64 size_, Id id_) 20NvMap::Handle::Handle(u64 size_, Id id_)
@@ -96,8 +96,9 @@ void NvMap::UnmapHandle(Handle& handle_description) {
96 const size_t map_size = handle_description.aligned_size; 96 const size_t map_size = handle_description.aligned_size;
97 if (!handle_description.in_heap) { 97 if (!handle_description.in_heap) {
98 auto& smmu = host1x.MemoryManager(); 98 auto& smmu = host1x.MemoryManager();
99 size_t aligned_up = Common::AlignUp(map_size, BIG_PAGE_SIZE);
99 smmu.Unmap(handle_description.d_address, map_size); 100 smmu.Unmap(handle_description.d_address, map_size);
100 smmu.Free(handle_description.d_address, static_cast<size_t>(map_size)); 101 smmu.Free(handle_description.d_address, static_cast<size_t>(aligned_up));
101 handle_description.d_address = 0; 102 handle_description.d_address = 0;
102 return; 103 return;
103 } 104 }
@@ -206,7 +207,8 @@ DAddr NvMap::PinHandle(NvMap::Handle::Id handle, bool low_area_pin) {
206 handle_description->d_address = session->mapper->Map(vaddress, map_size); 207 handle_description->d_address = session->mapper->Map(vaddress, map_size);
207 handle_description->in_heap = true; 208 handle_description->in_heap = true;
208 } else { 209 } else {
209 while ((address = smmu.Allocate(map_size)) == 0) { 210 size_t aligned_up = Common::AlignUp(map_size, BIG_PAGE_SIZE);
211 while ((address = smmu.Allocate(aligned_up)) == 0) {
210 // Free handles until the allocation succeeds 212 // Free handles until the allocation succeeds
211 std::scoped_lock queueLock(unmap_queue_lock); 213 std::scoped_lock queueLock(unmap_queue_lock);
212 if (auto freeHandleDesc{unmap_queue.front()}) { 214 if (auto freeHandleDesc{unmap_queue.front()}) {
diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h
index 119efc38d..aa5cd21ec 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.h
+++ b/src/core/hle/service/nvdrv/core/nvmap.h
@@ -63,8 +63,8 @@ public:
63 } flags{}; 63 } flags{};
64 static_assert(sizeof(Flags) == sizeof(u32)); 64 static_assert(sizeof(Flags) == sizeof(u32));
65 65
66 VAddr address{}; //!< The memory location in the guest's AS that this handle corresponds to, 66 VAddr address{}; //!< The memory location in the guest's AS that this handle corresponds to,
67 //!< this can also be in the nvdrv tmem 67 //!< this can also be in the nvdrv tmem
68 bool is_shared_mem_mapped{}; //!< If this nvmap has been mapped with the MapSharedMem IPC 68 bool is_shared_mem_mapped{}; //!< If this nvmap has been mapped with the MapSharedMem IPC
69 //!< call 69 //!< call
70 70
@@ -73,8 +73,8 @@ public:
73 bool in_heap{}; 73 bool in_heap{};
74 size_t session_id{}; 74 size_t session_id{};
75 75
76 DAddr d_address{}; //!< The memory location in the device's AS that this handle corresponds to, 76 DAddr d_address{}; //!< The memory location in the device's AS that this handle corresponds
77 //!< this can also be in the nvdrv tmem 77 //!< to, this can also be in the nvdrv tmem
78 78
79 Handle(u64 size, Id id); 79 Handle(u64 size, Id id);
80 80
@@ -82,7 +82,8 @@ public:
82 * @brief Sets up the handle with the given memory config, can allocate memory from the tmem 82 * @brief Sets up the handle with the given memory config, can allocate memory from the tmem
83 * if a 0 address is passed 83 * if a 0 address is passed
84 */ 84 */
85 [[nodiscard]] NvResult Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress, size_t pSessionId); 85 [[nodiscard]] NvResult Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress,
86 size_t pSessionId);
86 87
87 /** 88 /**
88 * @brief Increases the dupe counter of the handle for the given session 89 * @brief Increases the dupe counter of the handle for the given session
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 b44b17a82..718e0fecd 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h
@@ -4,8 +4,8 @@
4#pragma once 4#pragma once
5 5
6#include <deque> 6#include <deque>
7#include <vector>
8#include <unordered_map> 7#include <unordered_map>
8#include <vector>
9 9
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/swap.h" 11#include "common/swap.h"
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
index d4c93ea5d..a27bed29b 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp
@@ -69,7 +69,7 @@ NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, std::span<const u8> inpu
69} 69}
70 70
71void nvhost_vic::OnOpen(size_t session_id, DeviceFD fd) { 71void nvhost_vic::OnOpen(size_t session_id, DeviceFD fd) {
72 sessions[fd] = session_id; 72 sessions[fd] = session_id;
73} 73}
74 74
75void nvhost_vic::OnClose(DeviceFD fd) { 75void nvhost_vic::OnClose(DeviceFD fd) {
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp
index 24f49ddcd..08ee8ec24 100644
--- a/src/core/hle/service/nvdrv/devices/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp
@@ -123,8 +123,8 @@ NvResult nvmap::IocAlloc(IocAllocParams& params, DeviceFD fd) {
123 return NvResult::InsufficientMemory; 123 return NvResult::InsufficientMemory;
124 } 124 }
125 125
126 const auto result = 126 const auto result = handle_description->Alloc(params.flags, params.align, params.kind,
127 handle_description->Alloc(params.flags, params.align, params.kind, params.address, sessions[fd]); 127 params.address, sessions[fd]);
128 if (result != NvResult::Success) { 128 if (result != NvResult::Success) {
129 LOG_CRITICAL(Service_NVDRV, "Object failed to allocate, handle={:08X}", params.handle); 129 LOG_CRITICAL(Service_NVDRV, "Object failed to allocate, handle={:08X}", params.handle);
130 return result; 130 return result;
diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp
index d36eff4ec..86e272b41 100644
--- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp
+++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp
@@ -92,7 +92,8 @@ Result FreeNvMapHandle(Nvidia::Devices::nvmap& nvmap, u32 handle, Nvidia::Device
92 Nvidia::Devices::nvmap::IocFreeParams free_params{ 92 Nvidia::Devices::nvmap::IocFreeParams free_params{
93 .handle = handle, 93 .handle = handle,
94 }; 94 };
95 R_UNLESS(nvmap.IocFree(free_params, nvmap_fd) == Nvidia::NvResult::Success, VI::ResultOperationFailed); 95 R_UNLESS(nvmap.IocFree(free_params, nvmap_fd) == Nvidia::NvResult::Success,
96 VI::ResultOperationFailed);
96 97
97 // We succeeded. 98 // We succeeded.
98 R_SUCCEED(); 99 R_SUCCEED();
@@ -109,7 +110,8 @@ Result AllocNvMapHandle(Nvidia::Devices::nvmap& nvmap, u32 handle, Common::Proce
109 .kind = 0, 110 .kind = 0,
110 .address = GetInteger(buffer), 111 .address = GetInteger(buffer),
111 }; 112 };
112 R_UNLESS(nvmap.IocAlloc(alloc_params, nvmap_fd) == Nvidia::NvResult::Success, VI::ResultOperationFailed); 113 R_UNLESS(nvmap.IocAlloc(alloc_params, nvmap_fd) == Nvidia::NvResult::Success,
114 VI::ResultOperationFailed);
113 115
114 // We succeeded. 116 // We succeeded.
115 R_SUCCEED(); 117 R_SUCCEED();
@@ -201,8 +203,8 @@ Result FbShareBufferManager::Initialize(u64* out_buffer_id, u64* out_layer_id, u
201 m_nvmap_fd = m_nvdrv->Open("/dev/nvmap", m_session_id); 203 m_nvmap_fd = m_nvdrv->Open("/dev/nvmap", m_session_id);
202 204
203 // Create an nvmap handle for the buffer and assign the memory to it. 205 // Create an nvmap handle for the buffer and assign the memory to it.
204 R_TRY(AllocateHandleForBuffer(std::addressof(m_buffer_nvmap_handle), *m_nvdrv, m_nvmap_fd, map_address, 206 R_TRY(AllocateHandleForBuffer(std::addressof(m_buffer_nvmap_handle), *m_nvdrv, m_nvmap_fd,
205 SharedBufferSize)); 207 map_address, SharedBufferSize));
206 208
207 // Record the display id. 209 // Record the display id.
208 m_display_id = display_id; 210 m_display_id = display_id;
diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h
index 4b1a3d430..d2ec7a9b9 100644
--- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h
+++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h
@@ -4,9 +4,9 @@
4#pragma once 4#pragma once
5 5
6#include "common/math_util.h" 6#include "common/math_util.h"
7#include "core/hle/service/nvdrv/nvdata.h"
7#include "core/hle/service/nvnflinger/nvnflinger.h" 8#include "core/hle/service/nvnflinger/nvnflinger.h"
8#include "core/hle/service/nvnflinger/ui/fence.h" 9#include "core/hle/service/nvnflinger/ui/fence.h"
9#include "core/hle/service/nvdrv/nvdata.h"
10 10
11namespace Kernel { 11namespace Kernel {
12class KPageGroup; 12class KPageGroup;
@@ -62,7 +62,6 @@ private:
62 Core::System& m_system; 62 Core::System& m_system;
63 Nvnflinger& m_flinger; 63 Nvnflinger& m_flinger;
64 std::shared_ptr<Nvidia::Module> m_nvdrv; 64 std::shared_ptr<Nvidia::Module> m_nvdrv;
65
66}; 65};
67 66
68} // namespace Service::Nvnflinger 67} // namespace Service::Nvnflinger
diff --git a/src/core/memory.h b/src/core/memory.h
index 9d29cfd3f..552fd585f 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -488,7 +488,7 @@ public:
488 void SetGPUDirtyManagers(std::span<Core::GPUDirtyMemoryManager> managers); 488 void SetGPUDirtyManagers(std::span<Core::GPUDirtyMemoryManager> managers);
489 489
490 bool InvalidateNCE(Common::ProcessAddress vaddr, size_t size); 490 bool InvalidateNCE(Common::ProcessAddress vaddr, size_t size);
491 491
492 bool InvalidateSeparateHeap(void* fault_address); 492 bool InvalidateSeparateHeap(void* fault_address);
493 493
494private: 494private: