diff options
| author | 2018-08-03 12:55:58 -0400 | |
|---|---|---|
| committer | 2018-08-04 02:36:57 -0400 | |
| commit | 6030c5ce412e44ddcfe0a31c6747a017166bf33d (patch) | |
| tree | 2b79fa019f07e601b5170e92e93b69788ffde949 /src/core | |
| parent | Merge pull request #911 from lioncash/prototype (diff) | |
| download | yuzu-6030c5ce412e44ddcfe0a31c6747a017166bf33d.tar.gz yuzu-6030c5ce412e44ddcfe0a31c6747a017166bf33d.tar.xz yuzu-6030c5ce412e44ddcfe0a31c6747a017166bf33d.zip | |
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')
| -rw-r--r-- | src/core/core.cpp | 9 | ||||
| -rw-r--r-- | src/core/core.h | 22 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/nvflinger.cpp | 6 | ||||
| -rw-r--r-- | src/core/memory.cpp | 18 | ||||
| -rw-r--r-- | src/core/settings.cpp | 6 |
7 files changed, 54 insertions, 24 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 9824769cf..29222baba 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "core/loader/loader.h" | 18 | #include "core/loader/loader.h" |
| 19 | #include "core/settings.h" | 19 | #include "core/settings.h" |
| 20 | #include "file_sys/vfs_real.h" | 20 | #include "file_sys/vfs_real.h" |
| 21 | #include "video_core/renderer_base.h" | ||
| 21 | #include "video_core/video_core.h" | 22 | #include "video_core/video_core.h" |
| 22 | 23 | ||
| 23 | namespace Core { | 24 | namespace Core { |
| @@ -174,7 +175,6 @@ System::ResultStatus System::Init(EmuWindow& emu_window) { | |||
| 174 | cpu_cores[index] = std::make_shared<Cpu>(cpu_exclusive_monitor, cpu_barrier, index); | 175 | cpu_cores[index] = std::make_shared<Cpu>(cpu_exclusive_monitor, cpu_barrier, index); |
| 175 | } | 176 | } |
| 176 | 177 | ||
| 177 | gpu_core = std::make_unique<Tegra::GPU>(); | ||
| 178 | telemetry_session = std::make_unique<Core::TelemetrySession>(); | 178 | telemetry_session = std::make_unique<Core::TelemetrySession>(); |
| 179 | service_manager = std::make_shared<Service::SM::ServiceManager>(); | 179 | service_manager = std::make_shared<Service::SM::ServiceManager>(); |
| 180 | 180 | ||
| @@ -182,10 +182,13 @@ System::ResultStatus System::Init(EmuWindow& emu_window) { | |||
| 182 | Service::Init(service_manager); | 182 | Service::Init(service_manager); |
| 183 | GDBStub::Init(); | 183 | GDBStub::Init(); |
| 184 | 184 | ||
| 185 | if (!VideoCore::Init(emu_window)) { | 185 | renderer = VideoCore::CreateRenderer(emu_window); |
| 186 | if (!renderer->Init()) { | ||
| 186 | return ResultStatus::ErrorVideoCore; | 187 | return ResultStatus::ErrorVideoCore; |
| 187 | } | 188 | } |
| 188 | 189 | ||
| 190 | gpu_core = std::make_unique<Tegra::GPU>(*renderer->Rasterizer()); | ||
| 191 | |||
| 189 | // Create threads for CPU cores 1-3, and build thread_to_cpu map | 192 | // Create threads for CPU cores 1-3, and build thread_to_cpu map |
| 190 | // CPU core 0 is run on the main thread | 193 | // CPU core 0 is run on the main thread |
| 191 | thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0]; | 194 | thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0]; |
| @@ -217,7 +220,7 @@ void System::Shutdown() { | |||
| 217 | perf_results.frametime * 1000.0); | 220 | perf_results.frametime * 1000.0); |
| 218 | 221 | ||
| 219 | // Shutdown emulation session | 222 | // Shutdown emulation session |
| 220 | VideoCore::Shutdown(); | 223 | renderer.reset(); |
| 221 | GDBStub::Shutdown(); | 224 | GDBStub::Shutdown(); |
| 222 | Service::Shutdown(); | 225 | Service::Shutdown(); |
| 223 | Kernel::Shutdown(); | 226 | Kernel::Shutdown(); |
diff --git a/src/core/core.h b/src/core/core.h index ed475ac4e..059db4262 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -27,6 +27,10 @@ namespace Service::SM { | |||
| 27 | class ServiceManager; | 27 | class ServiceManager; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | namespace VideoCore { | ||
| 31 | class RendererBase; | ||
| 32 | } | ||
| 33 | |||
| 30 | namespace Core { | 34 | namespace Core { |
| 31 | 35 | ||
| 32 | class System { | 36 | class System { |
| @@ -127,11 +131,26 @@ public: | |||
| 127 | /// Gets a CPU interface to the CPU core with the specified index | 131 | /// Gets a CPU interface to the CPU core with the specified index |
| 128 | Cpu& CpuCore(size_t core_index); | 132 | Cpu& CpuCore(size_t core_index); |
| 129 | 133 | ||
| 130 | /// Gets the GPU interface | 134 | /// Gets a mutable reference to the GPU interface |
| 131 | Tegra::GPU& GPU() { | 135 | Tegra::GPU& GPU() { |
| 132 | return *gpu_core; | 136 | return *gpu_core; |
| 133 | } | 137 | } |
| 134 | 138 | ||
| 139 | /// Gets an immutable reference to the GPU interface. | ||
| 140 | const Tegra::GPU& GPU() const { | ||
| 141 | return *gpu_core; | ||
| 142 | } | ||
| 143 | |||
| 144 | /// Gets a mutable reference to the renderer. | ||
| 145 | VideoCore::RendererBase& Renderer() { | ||
| 146 | return *renderer; | ||
| 147 | } | ||
| 148 | |||
| 149 | /// Gets an immutable reference to the renderer. | ||
| 150 | const VideoCore::RendererBase& Renderer() const { | ||
| 151 | return *renderer; | ||
| 152 | } | ||
| 153 | |||
| 135 | /// Gets the scheduler for the CPU core that is currently running | 154 | /// Gets the scheduler for the CPU core that is currently running |
| 136 | Kernel::Scheduler& CurrentScheduler() { | 155 | Kernel::Scheduler& CurrentScheduler() { |
| 137 | return *CurrentCpuCore().Scheduler(); | 156 | return *CurrentCpuCore().Scheduler(); |
| @@ -195,6 +214,7 @@ private: | |||
| 195 | 214 | ||
| 196 | /// AppLoader used to load the current executing application | 215 | /// AppLoader used to load the current executing application |
| 197 | std::unique_ptr<Loader::AppLoader> app_loader; | 216 | std::unique_ptr<Loader::AppLoader> app_loader; |
| 217 | std::unique_ptr<VideoCore::RendererBase> renderer; | ||
| 198 | std::unique_ptr<Tegra::GPU> gpu_core; | 218 | std::unique_ptr<Tegra::GPU> gpu_core; |
| 199 | std::shared_ptr<Tegra::DebugContext> debug_context; | 219 | std::shared_ptr<Tegra::DebugContext> debug_context; |
| 200 | Kernel::SharedPtr<Kernel::Process> current_process; | 220 | Kernel::SharedPtr<Kernel::Process> current_process; |
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index ed69a4325..2b74e6a33 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | |||
| @@ -30,9 +30,9 @@ void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u3 | |||
| 30 | addr, offset, width, height, stride, static_cast<PixelFormat>(format), | 30 | addr, offset, width, height, stride, static_cast<PixelFormat>(format), |
| 31 | transform, crop_rect}; | 31 | transform, crop_rect}; |
| 32 | 32 | ||
| 33 | Core::System::GetInstance().perf_stats.EndGameFrame(); | 33 | auto& instance = Core::System::GetInstance(); |
| 34 | 34 | instance.perf_stats.EndGameFrame(); | |
| 35 | VideoCore::g_renderer->SwapBuffers(framebuffer); | 35 | instance.Renderer().SwapBuffers(framebuffer); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | } // namespace Service::Nvidia::Devices | 38 | } // namespace Service::Nvidia::Devices |
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 57b128b40..06151a1ea 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | |||
| @@ -150,15 +150,16 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 150 | 150 | ||
| 151 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); | 151 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); |
| 152 | 152 | ||
| 153 | auto& gpu = Core::System::GetInstance().GPU(); | 153 | const auto itr = buffer_mappings.find(params.offset); |
| 154 | |||
| 155 | auto itr = buffer_mappings.find(params.offset); | ||
| 156 | |||
| 157 | ASSERT_MSG(itr != buffer_mappings.end(), "Tried to unmap invalid mapping"); | 154 | ASSERT_MSG(itr != buffer_mappings.end(), "Tried to unmap invalid mapping"); |
| 158 | 155 | ||
| 156 | auto& system_instance = Core::System::GetInstance(); | ||
| 157 | |||
| 159 | // Remove this memory region from the rasterizer cache. | 158 | // Remove this memory region from the rasterizer cache. |
| 160 | VideoCore::g_renderer->Rasterizer()->FlushAndInvalidateRegion(params.offset, itr->second.size); | 159 | system_instance.Renderer().Rasterizer()->FlushAndInvalidateRegion(params.offset, |
| 160 | itr->second.size); | ||
| 161 | 161 | ||
| 162 | auto& gpu = system_instance.GPU(); | ||
| 162 | params.offset = gpu.memory_manager->UnmapBuffer(params.offset, itr->second.size); | 163 | params.offset = gpu.memory_manager->UnmapBuffer(params.offset, itr->second.size); |
| 163 | 164 | ||
| 164 | buffer_mappings.erase(itr->second.offset); | 165 | buffer_mappings.erase(itr->second.offset); |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 5344441e1..0bf51062c 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -127,9 +127,11 @@ void NVFlinger::Compose() { | |||
| 127 | MicroProfileFlip(); | 127 | MicroProfileFlip(); |
| 128 | 128 | ||
| 129 | if (buffer == boost::none) { | 129 | if (buffer == boost::none) { |
| 130 | auto& system_instance = Core::System::GetInstance(); | ||
| 131 | |||
| 130 | // There was no queued buffer to draw, render previous frame | 132 | // There was no queued buffer to draw, render previous frame |
| 131 | Core::System::GetInstance().perf_stats.EndGameFrame(); | 133 | system_instance.perf_stats.EndGameFrame(); |
| 132 | VideoCore::g_renderer->SwapBuffers({}); | 134 | system_instance.Renderer().SwapBuffers({}); |
| 133 | continue; | 135 | continue; |
| 134 | } | 136 | } |
| 135 | 137 | ||
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 4b3bb7b31..a8f08e1da 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) | |||
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) { | 328 | void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) { |
| 329 | auto& system_instance = Core::System::GetInstance(); | ||
| 330 | |||
| 329 | // Since pages are unmapped on shutdown after video core is shutdown, the renderer may be | 331 | // Since pages are unmapped on shutdown after video core is shutdown, the renderer may be |
| 330 | // null here | 332 | // null here |
| 331 | if (VideoCore::g_renderer == nullptr) { | 333 | if (!system_instance.IsPoweredOn()) { |
| 332 | return; | 334 | return; |
| 333 | } | 335 | } |
| 334 | 336 | ||
| 335 | VAddr end = start + size; | 337 | VAddr end = start + size; |
| 336 | 338 | ||
| 337 | auto CheckRegion = [&](VAddr region_start, VAddr region_end) { | 339 | const auto CheckRegion = [&](VAddr region_start, VAddr region_end) { |
| 338 | if (start >= region_end || end <= region_start) { | 340 | if (start >= region_end || end <= region_start) { |
| 339 | // No overlap with region | 341 | // No overlap with region |
| 340 | return; | 342 | return; |
| 341 | } | 343 | } |
| 342 | 344 | ||
| 343 | VAddr overlap_start = std::max(start, region_start); | 345 | const VAddr overlap_start = std::max(start, region_start); |
| 344 | VAddr overlap_end = std::min(end, region_end); | 346 | const VAddr overlap_end = std::min(end, region_end); |
| 345 | 347 | ||
| 346 | std::vector<Tegra::GPUVAddr> gpu_addresses = | 348 | const std::vector<Tegra::GPUVAddr> gpu_addresses = |
| 347 | Core::System::GetInstance().GPU().memory_manager->CpuToGpuAddress(overlap_start); | 349 | system_instance.GPU().memory_manager->CpuToGpuAddress(overlap_start); |
| 348 | 350 | ||
| 349 | if (gpu_addresses.empty()) { | 351 | if (gpu_addresses.empty()) { |
| 350 | return; | 352 | return; |
| 351 | } | 353 | } |
| 352 | 354 | ||
| 353 | u64 overlap_size = overlap_end - overlap_start; | 355 | const u64 overlap_size = overlap_end - overlap_start; |
| 354 | 356 | ||
| 355 | for (const auto& gpu_address : gpu_addresses) { | 357 | for (const auto& gpu_address : gpu_addresses) { |
| 356 | auto* rasterizer = VideoCore::g_renderer->Rasterizer(); | 358 | auto* rasterizer = system_instance.Renderer().Rasterizer(); |
| 357 | switch (mode) { | 359 | switch (mode) { |
| 358 | case FlushMode::Flush: | 360 | case FlushMode::Flush: |
| 359 | rasterizer->FlushRegion(gpu_address, overlap_size); | 361 | rasterizer->FlushRegion(gpu_address, overlap_size); |
diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 79e0b347b..a4623223d 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "core/core.h" | ||
| 5 | #include "core/gdbstub/gdbstub.h" | 6 | #include "core/gdbstub/gdbstub.h" |
| 6 | #include "core/hle/service/hid/hid.h" | 7 | #include "core/hle/service/hid/hid.h" |
| 7 | #include "core/settings.h" | 8 | #include "core/settings.h" |
| @@ -19,8 +20,9 @@ void Apply() { | |||
| 19 | 20 | ||
| 20 | VideoCore::g_toggle_framelimit_enabled = values.toggle_framelimit; | 21 | VideoCore::g_toggle_framelimit_enabled = values.toggle_framelimit; |
| 21 | 22 | ||
| 22 | if (VideoCore::g_renderer) { | 23 | auto& system_instance = Core::System::GetInstance(); |
| 23 | VideoCore::g_renderer->UpdateCurrentFramebufferLayout(); | 24 | if (system_instance.IsPoweredOn()) { |
| 25 | system_instance.Renderer().UpdateCurrentFramebufferLayout(); | ||
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | Service::HID::ReloadInputDevices(); | 28 | Service::HID::ReloadInputDevices(); |