aboutsummaryrefslogtreecommitdiff
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-08-03 12:55:58 -0400
committerLioncash <mathew1800@gmail.com>2018-08-04 02:36:57 -0400
commit6030c5ce412e44ddcfe0a31c6747a017166bf33d (patch)
tree2b79fa019f07e601b5170e92e93b69788ffde949 /src/core/memory.cpp
parent762fcaf5dec6ab6de92cb2481ae0d1392bc3482a (diff)
video_core: Eliminate the g_renderer global variable
We move the initialization of the renderer to the core class, while keeping the creation of it and any other specifics in video_core. This way we can ensure that the renderer is initialized and doesn't give unfettered access to the renderer. This also makes dependencies on types more explicit. For example, the GPU class doesn't need to depend on the existence of a renderer, it only needs to care about whether or not it has a rasterizer, but since it was accessing the global variable, it was also making the renderer a part of its dependency chain. By adjusting the interface, we can get rid of this dependency.
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r--src/core/memory.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 4b3bb7b31a..a8f08e1da5 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -326,34 +326,36 @@ void RasterizerMarkRegionCached(Tegra::GPUVAddr gpu_addr, u64 size, bool cached)
}
void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) {
+ auto& system_instance = Core::System::GetInstance();
+
// Since pages are unmapped on shutdown after video core is shutdown, the renderer may be
// null here
- if (VideoCore::g_renderer == nullptr) {
+ if (!system_instance.IsPoweredOn()) {
return;
}
VAddr end = start + size;
- auto CheckRegion = [&](VAddr region_start, VAddr region_end) {
+ const auto CheckRegion = [&](VAddr region_start, VAddr region_end) {
if (start >= region_end || end <= region_start) {
// No overlap with region
return;
}
- VAddr overlap_start = std::max(start, region_start);
- VAddr overlap_end = std::min(end, region_end);
+ const VAddr overlap_start = std::max(start, region_start);
+ const VAddr overlap_end = std::min(end, region_end);
- std::vector<Tegra::GPUVAddr> gpu_addresses =
- Core::System::GetInstance().GPU().memory_manager->CpuToGpuAddress(overlap_start);
+ const std::vector<Tegra::GPUVAddr> gpu_addresses =
+ system_instance.GPU().memory_manager->CpuToGpuAddress(overlap_start);
if (gpu_addresses.empty()) {
return;
}
- u64 overlap_size = overlap_end - overlap_start;
+ const u64 overlap_size = overlap_end - overlap_start;
for (const auto& gpu_address : gpu_addresses) {
- auto* rasterizer = VideoCore::g_renderer->Rasterizer();
+ auto* rasterizer = system_instance.Renderer().Rasterizer();
switch (mode) {
case FlushMode::Flush:
rasterizer->FlushRegion(gpu_address, overlap_size);