summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-28 10:57:56 -0400
committerGravatar Lioncash2018-08-28 11:11:50 -0400
commit45fb74d2623182b38af422bc6c8a51040860143f (patch)
treead65e21b3984d876241fc478d7624abfceb55e86 /src
parentMerge pull request #1165 from bunnei/shader-cache (diff)
downloadyuzu-45fb74d2623182b38af422bc6c8a51040860143f.tar.gz
yuzu-45fb74d2623182b38af422bc6c8a51040860143f.tar.xz
yuzu-45fb74d2623182b38af422bc6c8a51040860143f.zip
gpu: Make memory_manager private
Makes the class interface consistent and provides accessors for obtaining a reference to the memory manager instance. Given we also return references, this makes our more flimsy uses of const apparent, given const doesn't propagate through pointers in the way one would typically expect. This makes our mutable state more apparent in some places.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp12
-rw-r--r--src/core/memory.cpp4
-rw-r--r--src/video_core/gpu.cpp14
-rw-r--r--src/video_core/gpu.h12
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp16
-rw-r--r--src/yuzu/debugger/graphics/graphics_surface.cpp4
7 files changed, 40 insertions, 26 deletions
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 be2b79256..75487c4e8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -56,9 +56,9 @@ u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>&
56 auto& gpu = Core::System::GetInstance().GPU(); 56 auto& gpu = Core::System::GetInstance().GPU();
57 const u64 size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)}; 57 const u64 size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)};
58 if (params.flags & 1) { 58 if (params.flags & 1) {
59 params.offset = gpu.memory_manager->AllocateSpace(params.offset, size, 1); 59 params.offset = gpu.MemoryManager().AllocateSpace(params.offset, size, 1);
60 } else { 60 } else {
61 params.offset = gpu.memory_manager->AllocateSpace(size, params.align); 61 params.offset = gpu.MemoryManager().AllocateSpace(size, params.align);
62 } 62 }
63 63
64 std::memcpy(output.data(), &params, output.size()); 64 std::memcpy(output.data(), &params, output.size());
@@ -88,7 +88,7 @@ u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output)
88 u64 size = static_cast<u64>(entry.pages) << 0x10; 88 u64 size = static_cast<u64>(entry.pages) << 0x10;
89 ASSERT(size <= object->size); 89 ASSERT(size <= object->size);
90 90
91 Tegra::GPUVAddr returned = gpu.memory_manager->MapBufferEx(object->addr, offset, size); 91 Tegra::GPUVAddr returned = gpu.MemoryManager().MapBufferEx(object->addr, offset, size);
92 ASSERT(returned == offset); 92 ASSERT(returned == offset);
93 } 93 }
94 std::memcpy(output.data(), entries.data(), output.size()); 94 std::memcpy(output.data(), entries.data(), output.size());
@@ -125,9 +125,9 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
125 auto& gpu = Core::System::GetInstance().GPU(); 125 auto& gpu = Core::System::GetInstance().GPU();
126 126
127 if (params.flags & 1) { 127 if (params.flags & 1) {
128 params.offset = gpu.memory_manager->MapBufferEx(object->addr, params.offset, object->size); 128 params.offset = gpu.MemoryManager().MapBufferEx(object->addr, params.offset, object->size);
129 } else { 129 } else {
130 params.offset = gpu.memory_manager->MapBufferEx(object->addr, object->size); 130 params.offset = gpu.MemoryManager().MapBufferEx(object->addr, object->size);
131 } 131 }
132 132
133 // Create a new mapping entry for this operation. 133 // Create a new mapping entry for this operation.
@@ -161,7 +161,7 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou
161 itr->second.size); 161 itr->second.size);
162 162
163 auto& gpu = system_instance.GPU(); 163 auto& gpu = system_instance.GPU();
164 params.offset = gpu.memory_manager->UnmapBuffer(params.offset, itr->second.size); 164 params.offset = gpu.MemoryManager().UnmapBuffer(params.offset, itr->second.size);
165 165
166 buffer_mappings.erase(itr->second.offset); 166 buffer_mappings.erase(itr->second.offset);
167 167
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 1133bcbaf..bc34bfd6d 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -264,7 +264,7 @@ void RasterizerMarkRegionCached(Tegra::GPUVAddr gpu_addr, u64 size, bool cached)
264 u64 num_pages = ((gpu_addr + size - 1) >> PAGE_BITS) - (gpu_addr >> PAGE_BITS) + 1; 264 u64 num_pages = ((gpu_addr + size - 1) >> PAGE_BITS) - (gpu_addr >> PAGE_BITS) + 1;
265 for (unsigned i = 0; i < num_pages; ++i, gpu_addr += PAGE_SIZE) { 265 for (unsigned i = 0; i < num_pages; ++i, gpu_addr += PAGE_SIZE) {
266 boost::optional<VAddr> maybe_vaddr = 266 boost::optional<VAddr> maybe_vaddr =
267 Core::System::GetInstance().GPU().memory_manager->GpuToCpuAddress(gpu_addr); 267 Core::System::GetInstance().GPU().MemoryManager().GpuToCpuAddress(gpu_addr);
268 // The GPU <-> CPU virtual memory mapping is not 1:1 268 // The GPU <-> CPU virtual memory mapping is not 1:1
269 if (!maybe_vaddr) { 269 if (!maybe_vaddr) {
270 LOG_ERROR(HW_Memory, 270 LOG_ERROR(HW_Memory,
@@ -346,7 +346,7 @@ void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) {
346 const VAddr overlap_end = std::min(end, region_end); 346 const VAddr overlap_end = std::min(end, region_end);
347 347
348 const std::vector<Tegra::GPUVAddr> gpu_addresses = 348 const std::vector<Tegra::GPUVAddr> gpu_addresses =
349 system_instance.GPU().memory_manager->CpuToGpuAddress(overlap_start); 349 system_instance.GPU().MemoryManager().CpuToGpuAddress(overlap_start);
350 350
351 if (gpu_addresses.empty()) { 351 if (gpu_addresses.empty()) {
352 return; 352 return;
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 9758adcfd..e6d8e65c6 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -22,7 +22,7 @@ u32 FramebufferConfig::BytesPerPixel(PixelFormat format) {
22} 22}
23 23
24GPU::GPU(VideoCore::RasterizerInterface& rasterizer) { 24GPU::GPU(VideoCore::RasterizerInterface& rasterizer) {
25 memory_manager = std::make_unique<MemoryManager>(); 25 memory_manager = std::make_unique<Tegra::MemoryManager>();
26 maxwell_3d = std::make_unique<Engines::Maxwell3D>(rasterizer, *memory_manager); 26 maxwell_3d = std::make_unique<Engines::Maxwell3D>(rasterizer, *memory_manager);
27 fermi_2d = std::make_unique<Engines::Fermi2D>(*memory_manager); 27 fermi_2d = std::make_unique<Engines::Fermi2D>(*memory_manager);
28 maxwell_compute = std::make_unique<Engines::MaxwellCompute>(); 28 maxwell_compute = std::make_unique<Engines::MaxwellCompute>();
@@ -31,14 +31,22 @@ GPU::GPU(VideoCore::RasterizerInterface& rasterizer) {
31 31
32GPU::~GPU() = default; 32GPU::~GPU() = default;
33 33
34const Engines::Maxwell3D& GPU::Maxwell3D() const { 34Engines::Maxwell3D& GPU::Maxwell3D() {
35 return *maxwell_3d; 35 return *maxwell_3d;
36} 36}
37 37
38Engines::Maxwell3D& GPU::Maxwell3D() { 38const Engines::Maxwell3D& GPU::Maxwell3D() const {
39 return *maxwell_3d; 39 return *maxwell_3d;
40} 40}
41 41
42MemoryManager& GPU::MemoryManager() {
43 return *memory_manager;
44}
45
46const MemoryManager& GPU::MemoryManager() const {
47 return *memory_manager;
48}
49
42u32 RenderTargetBytesPerPixel(RenderTargetFormat format) { 50u32 RenderTargetBytesPerPixel(RenderTargetFormat format) {
43 ASSERT(format != RenderTargetFormat::NONE); 51 ASSERT(format != RenderTargetFormat::NONE);
44 52
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index 2697e1c27..2c3dbd97b 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -117,18 +117,24 @@ public:
117 /// Processes a command list stored at the specified address in GPU memory. 117 /// Processes a command list stored at the specified address in GPU memory.
118 void ProcessCommandList(GPUVAddr address, u32 size); 118 void ProcessCommandList(GPUVAddr address, u32 size);
119 119
120 /// Returns a reference to the Maxwell3D GPU engine.
121 Engines::Maxwell3D& Maxwell3D();
122
120 /// Returns a const reference to the Maxwell3D GPU engine. 123 /// Returns a const reference to the Maxwell3D GPU engine.
121 const Engines::Maxwell3D& Maxwell3D() const; 124 const Engines::Maxwell3D& Maxwell3D() const;
122 125
123 /// Returns a reference to the Maxwell3D GPU engine. 126 /// Returns a reference to the GPU memory manager.
124 Engines::Maxwell3D& Maxwell3D(); 127 Tegra::MemoryManager& MemoryManager();
125 128
126 std::unique_ptr<MemoryManager> memory_manager; 129 /// Returns a const reference to the GPU memory manager.
130 const Tegra::MemoryManager& MemoryManager() const;
127 131
128private: 132private:
129 /// Writes a single register in the engine bound to the specified subchannel 133 /// Writes a single register in the engine bound to the specified subchannel
130 void WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params); 134 void WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params);
131 135
136 std::unique_ptr<Tegra::MemoryManager> memory_manager;
137
132 /// Mapping of command subchannels to their bound engine ids. 138 /// Mapping of command subchannels to their bound engine ids.
133 std::unordered_map<u32, EngineID> bound_engines; 139 std::unordered_map<u32, EngineID> bound_engines;
134 140
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 9951d8178..fddfb2d83 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -425,8 +425,8 @@ std::tuple<u8*, GLintptr, GLintptr> RasterizerOpenGL::UploadMemory(u8* buffer_pt
425 std::tie(buffer_ptr, buffer_offset) = AlignBuffer(buffer_ptr, buffer_offset, alignment); 425 std::tie(buffer_ptr, buffer_offset) = AlignBuffer(buffer_ptr, buffer_offset, alignment);
426 GLintptr uploaded_offset = buffer_offset; 426 GLintptr uploaded_offset = buffer_offset;
427 427
428 const auto& memory_manager = Core::System::GetInstance().GPU().memory_manager; 428 auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager();
429 const boost::optional<VAddr> cpu_addr{memory_manager->GpuToCpuAddress(gpu_addr)}; 429 const boost::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)};
430 Memory::ReadBlock(*cpu_addr, buffer_ptr, size); 430 Memory::ReadBlock(*cpu_addr, buffer_ptr, size);
431 431
432 buffer_ptr += size; 432 buffer_ptr += size;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 65305000c..d87f90a62 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -168,8 +168,8 @@ static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType
168} 168}
169 169
170VAddr SurfaceParams::GetCpuAddr() const { 170VAddr SurfaceParams::GetCpuAddr() const {
171 const auto& gpu = Core::System::GetInstance().GPU(); 171 auto& gpu = Core::System::GetInstance().GPU();
172 return *gpu.memory_manager->GpuToCpuAddress(addr); 172 return *gpu.MemoryManager().GpuToCpuAddress(addr);
173} 173}
174 174
175static bool IsPixelFormatASTC(PixelFormat format) { 175static bool IsPixelFormatASTC(PixelFormat format) {
@@ -220,14 +220,14 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, std::vector<u8>& gl_bu
220 Tegra::GPUVAddr addr) { 220 Tegra::GPUVAddr addr) {
221 constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / CHAR_BIT; 221 constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / CHAR_BIT;
222 constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format); 222 constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format);
223 const auto& gpu = Core::System::GetInstance().GPU(); 223 auto& gpu = Core::System::GetInstance().GPU();
224 224
225 if (morton_to_gl) { 225 if (morton_to_gl) {
226 // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual 226 // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual
227 // pixel values. 227 // pixel values.
228 const u32 tile_size{IsFormatBCn(format) ? 4U : 1U}; 228 const u32 tile_size{IsFormatBCn(format) ? 4U : 1U};
229 const std::vector<u8> data = 229 const std::vector<u8> data =
230 Tegra::Texture::UnswizzleTexture(*gpu.memory_manager->GpuToCpuAddress(addr), tile_size, 230 Tegra::Texture::UnswizzleTexture(*gpu.MemoryManager().GpuToCpuAddress(addr), tile_size,
231 bytes_per_pixel, stride, height, block_height); 231 bytes_per_pixel, stride, height, block_height);
232 const size_t size_to_copy{std::min(gl_buffer.size(), data.size())}; 232 const size_t size_to_copy{std::min(gl_buffer.size(), data.size())};
233 gl_buffer.assign(data.begin(), data.begin() + size_to_copy); 233 gl_buffer.assign(data.begin(), data.begin() + size_to_copy);
@@ -237,7 +237,7 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, std::vector<u8>& gl_bu
237 LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!"); 237 LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!");
238 VideoCore::MortonCopyPixels128( 238 VideoCore::MortonCopyPixels128(
239 stride, height, bytes_per_pixel, gl_bytes_per_pixel, 239 stride, height, bytes_per_pixel, gl_bytes_per_pixel,
240 Memory::GetPointer(*gpu.memory_manager->GpuToCpuAddress(addr)), gl_buffer.data(), 240 Memory::GetPointer(*gpu.MemoryManager().GpuToCpuAddress(addr)), gl_buffer.data(),
241 morton_to_gl); 241 morton_to_gl);
242 } 242 }
243} 243}
@@ -754,9 +754,9 @@ Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params, bool pres
754 return {}; 754 return {};
755 } 755 }
756 756
757 const auto& gpu = Core::System::GetInstance().GPU(); 757 auto& gpu = Core::System::GetInstance().GPU();
758 // Don't try to create any entries in the cache if the address of the texture is invalid. 758 // Don't try to create any entries in the cache if the address of the texture is invalid.
759 if (gpu.memory_manager->GpuToCpuAddress(params.addr) == boost::none) 759 if (gpu.MemoryManager().GpuToCpuAddress(params.addr) == boost::none)
760 return {}; 760 return {};
761 761
762 // Look up surface in the cache based on address 762 // Look up surface in the cache based on address
@@ -848,7 +848,7 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& surface,
848 "reinterpretation but the texture is tiled."); 848 "reinterpretation but the texture is tiled.");
849 } 849 }
850 size_t remaining_size = new_params.SizeInBytes() - params.SizeInBytes(); 850 size_t remaining_size = new_params.SizeInBytes() - params.SizeInBytes();
851 auto address = Core::System::GetInstance().GPU().memory_manager->GpuToCpuAddress( 851 auto address = Core::System::GetInstance().GPU().MemoryManager().GpuToCpuAddress(
852 new_params.addr + params.SizeInBytes()); 852 new_params.addr + params.SizeInBytes());
853 std::vector<u8> data(remaining_size); 853 std::vector<u8> data(remaining_size);
854 Memory::ReadBlock(*address, data.data(), data.size()); 854 Memory::ReadBlock(*address, data.data(), data.size());
diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp
index 2b20cf5b9..7e37962d5 100644
--- a/src/yuzu/debugger/graphics/graphics_surface.cpp
+++ b/src/yuzu/debugger/graphics/graphics_surface.cpp
@@ -382,7 +382,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
382 // TODO: Implement a good way to visualize alpha components! 382 // TODO: Implement a good way to visualize alpha components!
383 383
384 QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32); 384 QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32);
385 boost::optional<VAddr> address = gpu.memory_manager->GpuToCpuAddress(surface_address); 385 boost::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
386 386
387 // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles. 387 // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles.
388 // Needs to be fixed if we plan to use this feature more, otherwise we may remove it. 388 // Needs to be fixed if we plan to use this feature more, otherwise we may remove it.
@@ -443,7 +443,7 @@ void GraphicsSurfaceWidget::SaveSurface() {
443 pixmap->save(&file, "PNG"); 443 pixmap->save(&file, "PNG");
444 } else if (selectedFilter == bin_filter) { 444 } else if (selectedFilter == bin_filter) {
445 auto& gpu = Core::System::GetInstance().GPU(); 445 auto& gpu = Core::System::GetInstance().GPU();
446 boost::optional<VAddr> address = gpu.memory_manager->GpuToCpuAddress(surface_address); 446 boost::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
447 447
448 const u8* buffer = Memory::GetPointer(*address); 448 const u8* buffer = Memory::GetPointer(*address);
449 ASSERT_MSG(buffer != nullptr, "Memory not accessible"); 449 ASSERT_MSG(buffer != nullptr, "Memory not accessible");