video_core: Remove usages of System::GetInstance() within the engines

Avoids the use of the global accessor in favor of explicitly making the
system a dependency within the interface.
This commit is contained in:
Lioncash 2019-02-15 22:05:17 -05:00
parent 99da6362c4
commit a8fa5019b5
9 changed files with 49 additions and 23 deletions

View File

@ -128,7 +128,7 @@ struct System::Impl {
return ResultStatus::ErrorVideoCore; return ResultStatus::ErrorVideoCore;
} }
gpu_core = std::make_unique<Tegra::GPU>(renderer->Rasterizer()); gpu_core = std::make_unique<Tegra::GPU>(system, renderer->Rasterizer());
cpu_core_manager.Initialize(system); cpu_core_manager.Initialize(system);
is_powered_on = true; is_powered_on = true;

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/assert.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core.h" #include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
@ -11,9 +12,9 @@
namespace Tegra::Engines { namespace Tegra::Engines {
KeplerMemory::KeplerMemory(VideoCore::RasterizerInterface& rasterizer, KeplerMemory::KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
MemoryManager& memory_manager) MemoryManager& memory_manager)
: memory_manager(memory_manager), rasterizer{rasterizer} {} : system{system}, memory_manager(memory_manager), rasterizer{rasterizer} {}
KeplerMemory::~KeplerMemory() = default; KeplerMemory::~KeplerMemory() = default;
@ -50,7 +51,7 @@ void KeplerMemory::ProcessData(u32 data) {
rasterizer.InvalidateRegion(*dest_address, sizeof(u32)); rasterizer.InvalidateRegion(*dest_address, sizeof(u32));
Memory::Write32(*dest_address, data); Memory::Write32(*dest_address, data);
Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.OnMemoryWrite(); system.GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
state.write_offset++; state.write_offset++;
} }

View File

@ -5,13 +5,16 @@
#pragma once #pragma once
#include <array> #include <array>
#include "common/assert.h"
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/gpu.h" #include "video_core/gpu.h"
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
namespace Core {
class System;
}
namespace VideoCore { namespace VideoCore {
class RasterizerInterface; class RasterizerInterface;
} }
@ -23,7 +26,8 @@ namespace Tegra::Engines {
class KeplerMemory final { class KeplerMemory final {
public: public:
KeplerMemory(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager); KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
MemoryManager& memory_manager);
~KeplerMemory(); ~KeplerMemory();
/// Write the value to the register identified by method. /// Write the value to the register identified by method.
@ -76,6 +80,7 @@ public:
} state{}; } state{};
private: private:
Core::System& system;
MemoryManager& memory_manager; MemoryManager& memory_manager;
VideoCore::RasterizerInterface& rasterizer; VideoCore::RasterizerInterface& rasterizer;

View File

@ -19,8 +19,10 @@ namespace Tegra::Engines {
/// First register id that is actually a Macro call. /// First register id that is actually a Macro call.
constexpr u32 MacroRegistersStart = 0xE00; constexpr u32 MacroRegistersStart = 0xE00;
Maxwell3D::Maxwell3D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) Maxwell3D::Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
: memory_manager(memory_manager), rasterizer{rasterizer}, macro_interpreter(*this) { MemoryManager& memory_manager)
: memory_manager(memory_manager), system{system}, rasterizer{rasterizer},
macro_interpreter(*this) {
InitializeRegisterDefaults(); InitializeRegisterDefaults();
} }
@ -103,7 +105,7 @@ void Maxwell3D::CallMacroMethod(u32 method, std::vector<u32> parameters) {
} }
void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
auto debug_context = Core::System::GetInstance().GetGPUDebugContext(); auto debug_context = system.GetGPUDebugContext();
// It is an error to write to a register other than the current macro's ARG register before it // It is an error to write to a register other than the current macro's ARG register before it
// has finished execution. // has finished execution.
@ -317,7 +319,7 @@ void Maxwell3D::ProcessQueryGet() {
LongQueryResult query_result{}; LongQueryResult query_result{};
query_result.value = result; query_result.value = result;
// TODO(Subv): Generate a real GPU timestamp and write it here instead of CoreTiming // TODO(Subv): Generate a real GPU timestamp and write it here instead of CoreTiming
query_result.timestamp = Core::System::GetInstance().CoreTiming().GetTicks(); query_result.timestamp = system.CoreTiming().GetTicks();
Memory::WriteBlock(*address, &query_result, sizeof(query_result)); Memory::WriteBlock(*address, &query_result, sizeof(query_result));
} }
dirty_flags.OnMemoryWrite(); dirty_flags.OnMemoryWrite();
@ -334,7 +336,7 @@ void Maxwell3D::DrawArrays() {
regs.vertex_buffer.count); regs.vertex_buffer.count);
ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?"); ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
auto debug_context = Core::System::GetInstance().GetGPUDebugContext(); auto debug_context = system.GetGPUDebugContext();
if (debug_context) { if (debug_context) {
debug_context->OnEvent(Tegra::DebugContext::Event::IncomingPrimitiveBatch, nullptr); debug_context->OnEvent(Tegra::DebugContext::Event::IncomingPrimitiveBatch, nullptr);

View File

@ -17,6 +17,10 @@
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
#include "video_core/textures/texture.h" #include "video_core/textures/texture.h"
namespace Core {
class System;
}
namespace VideoCore { namespace VideoCore {
class RasterizerInterface; class RasterizerInterface;
} }
@ -28,7 +32,8 @@ namespace Tegra::Engines {
class Maxwell3D final { class Maxwell3D final {
public: public:
explicit Maxwell3D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager); explicit Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
MemoryManager& memory_manager);
~Maxwell3D() = default; ~Maxwell3D() = default;
/// Register structure of the Maxwell3D engine. /// Register structure of the Maxwell3D engine.
@ -1131,6 +1136,8 @@ public:
private: private:
void InitializeRegisterDefaults(); void InitializeRegisterDefaults();
Core::System& system;
VideoCore::RasterizerInterface& rasterizer; VideoCore::RasterizerInterface& rasterizer;
/// Start offsets of each macro in macro_memory /// Start offsets of each macro in macro_memory

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/assert.h"
#include "core/core.h" #include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
@ -11,8 +12,9 @@
namespace Tegra::Engines { namespace Tegra::Engines {
MaxwellDMA::MaxwellDMA(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) MaxwellDMA::MaxwellDMA(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
: memory_manager(memory_manager), rasterizer{rasterizer} {} MemoryManager& memory_manager)
: memory_manager(memory_manager), system{system}, rasterizer{rasterizer} {}
void MaxwellDMA::CallMethod(const GPU::MethodCall& method_call) { void MaxwellDMA::CallMethod(const GPU::MethodCall& method_call) {
ASSERT_MSG(method_call.method < Regs::NUM_REGS, ASSERT_MSG(method_call.method < Regs::NUM_REGS,
@ -59,7 +61,7 @@ void MaxwellDMA::HandleCopy() {
} }
// All copies here update the main memory, so mark all rasterizer states as invalid. // All copies here update the main memory, so mark all rasterizer states as invalid.
Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.OnMemoryWrite(); system.GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
if (regs.exec.is_dst_linear && regs.exec.is_src_linear) { if (regs.exec.is_dst_linear && regs.exec.is_src_linear) {
// When the enable_2d bit is disabled, the copy is performed as if we were copying a 1D // When the enable_2d bit is disabled, the copy is performed as if we were copying a 1D

View File

@ -5,13 +5,16 @@
#pragma once #pragma once
#include <array> #include <array>
#include "common/assert.h"
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/gpu.h" #include "video_core/gpu.h"
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
namespace Core {
class System;
}
namespace VideoCore { namespace VideoCore {
class RasterizerInterface; class RasterizerInterface;
} }
@ -20,7 +23,8 @@ namespace Tegra::Engines {
class MaxwellDMA final { class MaxwellDMA final {
public: public:
explicit MaxwellDMA(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager); explicit MaxwellDMA(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
MemoryManager& memory_manager);
~MaxwellDMA() = default; ~MaxwellDMA() = default;
/// Write the value to the register identified by method. /// Write the value to the register identified by method.
@ -137,6 +141,8 @@ public:
MemoryManager& memory_manager; MemoryManager& memory_manager;
private: private:
Core::System& system;
VideoCore::RasterizerInterface& rasterizer; VideoCore::RasterizerInterface& rasterizer;
/// Performs the copy from the source buffer to the destination buffer as configured in the /// Performs the copy from the source buffer to the destination buffer as configured in the

View File

@ -28,14 +28,14 @@ u32 FramebufferConfig::BytesPerPixel(PixelFormat format) {
UNREACHABLE(); UNREACHABLE();
} }
GPU::GPU(VideoCore::RasterizerInterface& rasterizer) { GPU::GPU(Core::System& system, VideoCore::RasterizerInterface& rasterizer) {
memory_manager = std::make_unique<Tegra::MemoryManager>(); memory_manager = std::make_unique<Tegra::MemoryManager>();
dma_pusher = std::make_unique<Tegra::DmaPusher>(*this); dma_pusher = std::make_unique<Tegra::DmaPusher>(*this);
maxwell_3d = std::make_unique<Engines::Maxwell3D>(rasterizer, *memory_manager); maxwell_3d = std::make_unique<Engines::Maxwell3D>(system, rasterizer, *memory_manager);
fermi_2d = std::make_unique<Engines::Fermi2D>(rasterizer, *memory_manager); fermi_2d = std::make_unique<Engines::Fermi2D>(rasterizer, *memory_manager);
kepler_compute = std::make_unique<Engines::KeplerCompute>(*memory_manager); kepler_compute = std::make_unique<Engines::KeplerCompute>(*memory_manager);
maxwell_dma = std::make_unique<Engines::MaxwellDMA>(rasterizer, *memory_manager); maxwell_dma = std::make_unique<Engines::MaxwellDMA>(system, rasterizer, *memory_manager);
kepler_memory = std::make_unique<Engines::KeplerMemory>(rasterizer, *memory_manager); kepler_memory = std::make_unique<Engines::KeplerMemory>(system, rasterizer, *memory_manager);
} }
GPU::~GPU() = default; GPU::~GPU() = default;

View File

@ -6,12 +6,15 @@
#include <array> #include <array>
#include <memory> #include <memory>
#include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/service/nvflinger/buffer_queue.h" #include "core/hle/service/nvflinger/buffer_queue.h"
#include "video_core/dma_pusher.h" #include "video_core/dma_pusher.h"
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
namespace Core {
class System;
}
namespace VideoCore { namespace VideoCore {
class RasterizerInterface; class RasterizerInterface;
} }
@ -118,7 +121,7 @@ enum class EngineID {
class GPU final { class GPU final {
public: public:
explicit GPU(VideoCore::RasterizerInterface& rasterizer); explicit GPU(Core::System& system, VideoCore::RasterizerInterface& rasterizer);
~GPU(); ~GPU();
struct MethodCall { struct MethodCall {