forked from ShuriZma/suyu
metal: initial support
This commit is contained in:
parent
77e9b7b59b
commit
7ea460a800
|
@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.22)
|
||||||
set(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT OFF)
|
set(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT OFF)
|
||||||
set(CMAKE_XCODE_EMIT_RELATIVE_PATH YES)
|
set(CMAKE_XCODE_EMIT_RELATIVE_PATH YES)
|
||||||
|
|
||||||
project(suyu)
|
project(suyu LANGUAGES C CXX OBJC OBJCXX)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
|
||||||
|
|
|
@ -124,7 +124,7 @@ ENUM(VSyncMode, Immediate, Mailbox, Fifo, FifoRelaxed);
|
||||||
|
|
||||||
ENUM(VramUsageMode, Conservative, Aggressive);
|
ENUM(VramUsageMode, Conservative, Aggressive);
|
||||||
|
|
||||||
ENUM(RendererBackend, OpenGL, Vulkan, Null);
|
ENUM(RendererBackend, OpenGL, Vulkan, Metal, Null);
|
||||||
|
|
||||||
ENUM(ShaderBackend, Glsl, Glasm, SpirV);
|
ENUM(ShaderBackend, Glsl, Glasm, SpirV);
|
||||||
|
|
||||||
|
|
|
@ -284,8 +284,8 @@ struct NullRenderWidget : public RenderWidget {
|
||||||
GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
|
GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
|
||||||
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
|
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
|
||||||
Core::System& system_)
|
Core::System& system_)
|
||||||
: QWidget(parent),
|
: QWidget(parent), emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)},
|
||||||
emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)}, system{system_} {
|
system{system_} {
|
||||||
setWindowTitle(QStringLiteral("suyu %1 | %2-%3")
|
setWindowTitle(QStringLiteral("suyu %1 | %2-%3")
|
||||||
.arg(QString::fromUtf8(Common::g_build_name),
|
.arg(QString::fromUtf8(Common::g_build_name),
|
||||||
QString::fromUtf8(Common::g_scm_branch),
|
QString::fromUtf8(Common::g_scm_branch),
|
||||||
|
@ -933,6 +933,13 @@ bool GRenderWindow::InitRenderTarget() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
case Settings::RendererBackend::Metal:
|
||||||
|
if (!InitializeMetal()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case Settings::RendererBackend::Null:
|
case Settings::RendererBackend::Null:
|
||||||
InitializeNull();
|
InitializeNull();
|
||||||
break;
|
break;
|
||||||
|
@ -1048,6 +1055,14 @@ bool GRenderWindow::InitializeVulkan() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GRenderWindow::InitializeMetal() {
|
||||||
|
// TODO: initialize Metal
|
||||||
|
child_widget = new NullRenderWidget(this);
|
||||||
|
main_context = std::make_unique<DummyContext>();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GRenderWindow::InitializeNull() {
|
void GRenderWindow::InitializeNull() {
|
||||||
child_widget = new NullRenderWidget(this);
|
child_widget = new NullRenderWidget(this);
|
||||||
main_context = std::make_unique<DummyContext>();
|
main_context = std::make_unique<DummyContext>();
|
||||||
|
|
|
@ -239,6 +239,7 @@ private:
|
||||||
|
|
||||||
bool InitializeOpenGL();
|
bool InitializeOpenGL();
|
||||||
bool InitializeVulkan();
|
bool InitializeVulkan();
|
||||||
|
bool InitializeMetal();
|
||||||
void InitializeNull();
|
void InitializeNull();
|
||||||
bool LoadOpenGL();
|
bool LoadOpenGL();
|
||||||
QStringList GetUnsupportedGLExtensions() const;
|
QStringList GetUnsupportedGLExtensions() const;
|
||||||
|
|
|
@ -466,6 +466,9 @@ void ConfigureGraphics::ApplyConfiguration() {
|
||||||
Settings::values.vulkan_device.SetGlobal(Settings::IsConfiguringGlobal());
|
Settings::values.vulkan_device.SetGlobal(Settings::IsConfiguringGlobal());
|
||||||
Settings::values.vulkan_device.SetValue(vulkan_device_combobox->currentIndex());
|
Settings::values.vulkan_device.SetValue(vulkan_device_combobox->currentIndex());
|
||||||
break;
|
break;
|
||||||
|
case Settings::RendererBackend::Metal:
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
case Settings::RendererBackend::Null:
|
case Settings::RendererBackend::Null:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,6 +331,9 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QWidget* parent) {
|
||||||
PAIR(RendererBackend, OpenGL, tr("OpenGL")),
|
PAIR(RendererBackend, OpenGL, tr("OpenGL")),
|
||||||
#endif
|
#endif
|
||||||
PAIR(RendererBackend, Vulkan, tr("Vulkan")),
|
PAIR(RendererBackend, Vulkan, tr("Vulkan")),
|
||||||
|
#ifdef __APPLE__
|
||||||
|
PAIR(RendererBackend, Metal, tr("Metal")),
|
||||||
|
#endif
|
||||||
PAIR(RendererBackend, Null, tr("Null")),
|
PAIR(RendererBackend, Null, tr("Null")),
|
||||||
}});
|
}});
|
||||||
translations->insert(
|
translations->insert(
|
||||||
|
|
|
@ -56,6 +56,9 @@ static const std::map<Settings::GpuAccuracy, QString> gpu_accuracy_texts_map = {
|
||||||
static const std::map<Settings::RendererBackend, QString> renderer_backend_texts_map = {
|
static const std::map<Settings::RendererBackend, QString> renderer_backend_texts_map = {
|
||||||
{Settings::RendererBackend::Vulkan, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Vulkan"))},
|
{Settings::RendererBackend::Vulkan, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Vulkan"))},
|
||||||
{Settings::RendererBackend::OpenGL, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "OpenGL"))},
|
{Settings::RendererBackend::OpenGL, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "OpenGL"))},
|
||||||
|
#ifdef __APPLE__
|
||||||
|
{Settings::RendererBackend::Metal, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Metal"))},
|
||||||
|
#endif
|
||||||
{Settings::RendererBackend::Null, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Null"))},
|
{Settings::RendererBackend::Null, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Null"))},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3800,6 +3800,8 @@ void GMainWindow::OnToggleGraphicsAPI() {
|
||||||
} else {
|
} else {
|
||||||
#ifdef HAS_OPENGL
|
#ifdef HAS_OPENGL
|
||||||
api = Settings::RendererBackend::OpenGL;
|
api = Settings::RendererBackend::OpenGL;
|
||||||
|
#elif __APPLE__
|
||||||
|
api = Settings::RendererBackend::Metal;
|
||||||
#else
|
#else
|
||||||
api = Settings::RendererBackend::Null;
|
api = Settings::RendererBackend::Null;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,6 +21,8 @@ add_executable(suyu-cmd
|
||||||
emu_window/emu_window_sdl2_null.h
|
emu_window/emu_window_sdl2_null.h
|
||||||
emu_window/emu_window_sdl2_vk.cpp
|
emu_window/emu_window_sdl2_vk.cpp
|
||||||
emu_window/emu_window_sdl2_vk.h
|
emu_window/emu_window_sdl2_vk.h
|
||||||
|
emu_window/emu_window_sdl2_mtl.cpp
|
||||||
|
emu_window/emu_window_sdl2_mtl.h
|
||||||
precompiled_headers.h
|
precompiled_headers.h
|
||||||
sdl_config.cpp
|
sdl_config.cpp
|
||||||
sdl_config.h
|
sdl_config.h
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
#include "common/scm_rev.h"
|
||||||
|
#include "suyu_cmd/emu_window/emu_window_sdl2_mtl.h"
|
||||||
|
#include "video_core/renderer_metal/renderer_metal.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <SDL_syswm.h>
|
||||||
|
|
||||||
|
EmuWindow_SDL2_MTL::EmuWindow_SDL2_MTL(InputCommon::InputSubsystem* input_subsystem_,
|
||||||
|
Core::System& system_, bool fullscreen)
|
||||||
|
: EmuWindow_SDL2{input_subsystem_, system_} {
|
||||||
|
const std::string window_title = fmt::format("suyu {} | {}-{} (Vulkan)", Common::g_build_name,
|
||||||
|
Common::g_scm_branch, Common::g_scm_desc);
|
||||||
|
render_window =
|
||||||
|
SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
|
||||||
|
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
|
|
||||||
|
SDL_SysWMinfo wm;
|
||||||
|
SDL_VERSION(&wm.version);
|
||||||
|
if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) {
|
||||||
|
LOG_CRITICAL(Frontend, "Failed to get information from the window manager: {}",
|
||||||
|
SDL_GetError());
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWindowIcon();
|
||||||
|
|
||||||
|
if (fullscreen) {
|
||||||
|
Fullscreen();
|
||||||
|
ShowCursor(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (wm.subsystem) {
|
||||||
|
#ifdef SDL_VIDEO_DRIVER_COCOA
|
||||||
|
case SDL_SYSWM_TYPE::SDL_SYSWM_COCOA:
|
||||||
|
window_info.type = Core::Frontend::WindowSystemType::Cocoa;
|
||||||
|
window_info.render_surface = SDL_Metal_CreateView(render_window);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
LOG_CRITICAL(Frontend, "Window manager subsystem {} not implemented", wm.subsystem);
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnResize();
|
||||||
|
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
||||||
|
SDL_PumpEvents();
|
||||||
|
LOG_INFO(Frontend, "suyu Version: {} | {}-{} (Vulkan)", Common::g_build_name,
|
||||||
|
Common::g_scm_branch, Common::g_scm_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmuWindow_SDL2_MTL::~EmuWindow_SDL2_MTL() = default;
|
||||||
|
|
||||||
|
std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_MTL::CreateSharedContext() const {
|
||||||
|
return std::make_unique<DummyContext>();
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "core/frontend/emu_window.h"
|
||||||
|
#include "suyu_cmd/emu_window/emu_window_sdl2.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace InputCommon {
|
||||||
|
class InputSubsystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmuWindow_SDL2_MTL final : public EmuWindow_SDL2 {
|
||||||
|
public:
|
||||||
|
explicit EmuWindow_SDL2_MTL(InputCommon::InputSubsystem* input_subsystem_, Core::System& system,
|
||||||
|
bool fullscreen);
|
||||||
|
~EmuWindow_SDL2_MTL() override;
|
||||||
|
|
||||||
|
std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override;
|
||||||
|
};
|
|
@ -38,6 +38,7 @@
|
||||||
#include "sdl_config.h"
|
#include "sdl_config.h"
|
||||||
#include "suyu_cmd/emu_window/emu_window_sdl2.h"
|
#include "suyu_cmd/emu_window/emu_window_sdl2.h"
|
||||||
#include "suyu_cmd/emu_window/emu_window_sdl2_gl.h"
|
#include "suyu_cmd/emu_window/emu_window_sdl2_gl.h"
|
||||||
|
#include "suyu_cmd/emu_window/emu_window_sdl2_mtl.h"
|
||||||
#include "suyu_cmd/emu_window/emu_window_sdl2_null.h"
|
#include "suyu_cmd/emu_window/emu_window_sdl2_null.h"
|
||||||
#include "suyu_cmd/emu_window/emu_window_sdl2_vk.h"
|
#include "suyu_cmd/emu_window/emu_window_sdl2_vk.h"
|
||||||
#include "video_core/renderer_base.h"
|
#include "video_core/renderer_base.h"
|
||||||
|
@ -385,6 +386,9 @@ int main(int argc, char** argv) {
|
||||||
case Settings::RendererBackend::Vulkan:
|
case Settings::RendererBackend::Vulkan:
|
||||||
emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem, system, fullscreen);
|
emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem, system, fullscreen);
|
||||||
break;
|
break;
|
||||||
|
case Settings::RendererBackend::Metal:
|
||||||
|
emu_window = std::make_unique<EmuWindow_SDL2_MTL>(&input_subsystem, system, fullscreen);
|
||||||
|
break;
|
||||||
case Settings::RendererBackend::Null:
|
case Settings::RendererBackend::Null:
|
||||||
emu_window = std::make_unique<EmuWindow_SDL2_Null>(&input_subsystem, system, fullscreen);
|
emu_window = std::make_unique<EmuWindow_SDL2_Null>(&input_subsystem, system, fullscreen);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -372,6 +372,12 @@ if (APPLE)
|
||||||
renderer_opengl/util_shaders.cpp
|
renderer_opengl/util_shaders.cpp
|
||||||
renderer_opengl/util_shaders.h
|
renderer_opengl/util_shaders.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND sources
|
||||||
|
renderer_metal/mtl_device.mm
|
||||||
|
renderer_metal/mtl_rasterizer.mm
|
||||||
|
renderer_metal/renderer_metal.mm
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(video_core STATIC ${sources})
|
add_library(video_core STATIC ${sources})
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "video_core/renderer_metal/objc_bridge.h"
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
class Device {
|
||||||
|
public:
|
||||||
|
explicit Device();
|
||||||
|
~Device();
|
||||||
|
|
||||||
|
MTLDevice_t GetDevice() const {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
MTLCommandQueue_t GetCommandQueue() const {
|
||||||
|
return command_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
MTLDevice_t device;
|
||||||
|
MTLCommandQueue_t command_queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -0,0 +1,23 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "video_core/renderer_metal/mtl_device.h"
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
Device::Device() {
|
||||||
|
device = MTLCreateSystemDefaultDevice();
|
||||||
|
if (!device) {
|
||||||
|
throw std::runtime_error("Failed to create Metal device");
|
||||||
|
}
|
||||||
|
command_queue = [device newCommandQueue];
|
||||||
|
if (!command_queue) {
|
||||||
|
throw std::runtime_error("Failed to create Metal command queue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Device::~Device() {
|
||||||
|
[command_queue release];
|
||||||
|
[device release];
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -0,0 +1,96 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "video_core/control/channel_state_cache.h"
|
||||||
|
#include "video_core/engines/maxwell_dma.h"
|
||||||
|
#include "video_core/rasterizer_interface.h"
|
||||||
|
#include "video_core/renderer_metal/objc_bridge.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
|
class RasterizerMetal;
|
||||||
|
|
||||||
|
class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
|
||||||
|
public:
|
||||||
|
explicit AccelerateDMA();
|
||||||
|
bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override;
|
||||||
|
bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
|
||||||
|
bool ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::ImageOperand& src,
|
||||||
|
const Tegra::DMA::BufferOperand& dst) override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool BufferToImage(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& src,
|
||||||
|
const Tegra::DMA::ImageOperand& dst) override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class RasterizerMetal final : public VideoCore::RasterizerInterface,
|
||||||
|
protected VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo> {
|
||||||
|
public:
|
||||||
|
explicit RasterizerMetal(Tegra::GPU& gpu_, const Device& device_, const CAMetalLayer* layer_);
|
||||||
|
~RasterizerMetal() override;
|
||||||
|
|
||||||
|
void Draw(bool is_indexed, u32 instance_count) override;
|
||||||
|
void DrawTexture() override;
|
||||||
|
void Clear(u32 layer_count) override;
|
||||||
|
void DispatchCompute() override;
|
||||||
|
void ResetCounter(VideoCommon::QueryType type) override;
|
||||||
|
void Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
|
||||||
|
VideoCommon::QueryPropertiesFlags flags, u32 payload, u32 subreport) override;
|
||||||
|
void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override;
|
||||||
|
void DisableGraphicsUniformBuffer(size_t stage, u32 index) override;
|
||||||
|
void FlushAll() override;
|
||||||
|
void FlushRegion(DAddr addr, u64 size,
|
||||||
|
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||||
|
bool MustFlushRegion(DAddr addr, u64 size,
|
||||||
|
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||||
|
void InvalidateRegion(DAddr addr, u64 size,
|
||||||
|
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||||
|
void OnCacheInvalidation(DAddr addr, u64 size) override;
|
||||||
|
bool OnCPUWrite(DAddr addr, u64 size) override;
|
||||||
|
VideoCore::RasterizerDownloadArea GetFlushArea(DAddr addr, u64 size) override;
|
||||||
|
void InvalidateGPUCache() override;
|
||||||
|
void UnmapMemory(DAddr addr, u64 size) override;
|
||||||
|
void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) override;
|
||||||
|
void SignalFence(std::function<void()>&& func) override;
|
||||||
|
void SyncOperation(std::function<void()>&& func) override;
|
||||||
|
void SignalSyncPoint(u32 value) override;
|
||||||
|
void SignalReference() override;
|
||||||
|
void ReleaseFences(bool force) override;
|
||||||
|
void FlushAndInvalidateRegion(
|
||||||
|
DAddr addr, u64 size, VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||||
|
void WaitForIdle() override;
|
||||||
|
void FragmentBarrier() override;
|
||||||
|
void TiledCacheBarrier() override;
|
||||||
|
void FlushCommands() override;
|
||||||
|
void TickFrame() override;
|
||||||
|
bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
|
||||||
|
const Tegra::Engines::Fermi2D::Surface& dst,
|
||||||
|
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
||||||
|
Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
|
||||||
|
void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||||
|
std::span<const u8> memory) override;
|
||||||
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||||
|
void InitializeChannel(Tegra::Control::ChannelState& channel) override;
|
||||||
|
void BindChannel(Tegra::Control::ChannelState& channel) override;
|
||||||
|
void ReleaseChannel(s32 channel_id) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tegra::GPU& gpu;
|
||||||
|
AccelerateDMA accelerate_dma;
|
||||||
|
|
||||||
|
const Device& device;
|
||||||
|
const CAMetalLayer* layer;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -0,0 +1,110 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "common/alignment.h"
|
||||||
|
#include "video_core/control/channel_state.h"
|
||||||
|
#include "video_core/host1x/host1x.h"
|
||||||
|
#include "video_core/memory_manager.h"
|
||||||
|
#include "video_core/renderer_metal/mtl_rasterizer.h"
|
||||||
|
#include "video_core/renderer_metal/mtl_device.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
AccelerateDMA::AccelerateDMA() = default;
|
||||||
|
|
||||||
|
bool AccelerateDMA::BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
RasterizerMetal::RasterizerMetal(Tegra::GPU& gpu_, const Device& device_, const CAMetalLayer* layer_)
|
||||||
|
: gpu{gpu_}, device{device_}, layer{layer_} {}
|
||||||
|
RasterizerMetal::~RasterizerMetal() = default;
|
||||||
|
|
||||||
|
void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {}
|
||||||
|
void RasterizerMetal::DrawTexture() {}
|
||||||
|
void RasterizerMetal::Clear(u32 layer_count) {}
|
||||||
|
void RasterizerMetal::DispatchCompute() {}
|
||||||
|
void RasterizerMetal::ResetCounter(VideoCommon::QueryType type) {}
|
||||||
|
void RasterizerMetal::Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
|
||||||
|
VideoCommon::QueryPropertiesFlags flags, u32 payload, u32 subreport) {
|
||||||
|
if (!gpu_memory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (True(flags & VideoCommon::QueryPropertiesFlags::HasTimeout)) {
|
||||||
|
u64 ticks = gpu.GetTicks();
|
||||||
|
gpu_memory->Write<u64>(gpu_addr + 8, ticks);
|
||||||
|
gpu_memory->Write<u64>(gpu_addr, static_cast<u64>(payload));
|
||||||
|
} else {
|
||||||
|
gpu_memory->Write<u32>(gpu_addr, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void RasterizerMetal::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
|
||||||
|
u32 size) {}
|
||||||
|
void RasterizerMetal::DisableGraphicsUniformBuffer(size_t stage, u32 index) {}
|
||||||
|
void RasterizerMetal::FlushAll() {}
|
||||||
|
void RasterizerMetal::FlushRegion(DAddr addr, u64 size, VideoCommon::CacheType) {}
|
||||||
|
bool RasterizerMetal::MustFlushRegion(DAddr addr, u64 size, VideoCommon::CacheType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void RasterizerMetal::InvalidateRegion(DAddr addr, u64 size, VideoCommon::CacheType) {}
|
||||||
|
bool RasterizerMetal::OnCPUWrite(PAddr addr, u64 size) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void RasterizerMetal::OnCacheInvalidation(PAddr addr, u64 size) {}
|
||||||
|
VideoCore::RasterizerDownloadArea RasterizerMetal::GetFlushArea(PAddr addr, u64 size) {
|
||||||
|
VideoCore::RasterizerDownloadArea new_area{
|
||||||
|
.start_address = Common::AlignDown(addr, Core::DEVICE_PAGESIZE),
|
||||||
|
.end_address = Common::AlignUp(addr + size, Core::DEVICE_PAGESIZE),
|
||||||
|
.preemtive = true,
|
||||||
|
};
|
||||||
|
return new_area;
|
||||||
|
}
|
||||||
|
void RasterizerMetal::InvalidateGPUCache() {}
|
||||||
|
void RasterizerMetal::UnmapMemory(DAddr addr, u64 size) {}
|
||||||
|
void RasterizerMetal::ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) {}
|
||||||
|
void RasterizerMetal::SignalFence(std::function<void()>&& func) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
void RasterizerMetal::SyncOperation(std::function<void()>&& func) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
void RasterizerMetal::SignalSyncPoint(u32 value) {
|
||||||
|
auto& syncpoint_manager = gpu.Host1x().GetSyncpointManager();
|
||||||
|
syncpoint_manager.IncrementGuest(value);
|
||||||
|
syncpoint_manager.IncrementHost(value);
|
||||||
|
}
|
||||||
|
void RasterizerMetal::SignalReference() {}
|
||||||
|
void RasterizerMetal::ReleaseFences(bool) {}
|
||||||
|
void RasterizerMetal::FlushAndInvalidateRegion(DAddr addr, u64 size, VideoCommon::CacheType) {}
|
||||||
|
void RasterizerMetal::WaitForIdle() {}
|
||||||
|
void RasterizerMetal::FragmentBarrier() {}
|
||||||
|
void RasterizerMetal::TiledCacheBarrier() {}
|
||||||
|
void RasterizerMetal::FlushCommands() {}
|
||||||
|
void RasterizerMetal::TickFrame() {}
|
||||||
|
Tegra::Engines::AccelerateDMAInterface& RasterizerMetal::AccessAccelerateDMA() {
|
||||||
|
return accelerate_dma;
|
||||||
|
}
|
||||||
|
bool RasterizerMetal::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
|
||||||
|
const Tegra::Engines::Fermi2D::Surface& dst,
|
||||||
|
const Tegra::Engines::Fermi2D::Config& copy_config) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void RasterizerMetal::AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||||
|
std::span<const u8> memory) {}
|
||||||
|
void RasterizerMetal::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
|
const VideoCore::DiskResourceLoadCallback& callback) {}
|
||||||
|
void RasterizerMetal::InitializeChannel(Tegra::Control::ChannelState& channel) {
|
||||||
|
CreateChannel(channel);
|
||||||
|
}
|
||||||
|
void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) {
|
||||||
|
BindToChannel(channel.bind_id);
|
||||||
|
}
|
||||||
|
void RasterizerMetal::ReleaseChannel(s32 channel_id) {
|
||||||
|
EraseChannel(channel_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -0,0 +1,16 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
#import <Metal/Metal.h>
|
||||||
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
typedef id<MTLDevice> MTLDevice_t;
|
||||||
|
typedef id<MTLCommandQueue> MTLCommandQueue_t;
|
||||||
|
typedef id<MTLTexture> MTLTexture_t;
|
||||||
|
#else
|
||||||
|
typedef void* MTLDevice_t;
|
||||||
|
typedef void* MTLCommandQueue_t;
|
||||||
|
typedef void* MTLTexture_t;
|
||||||
|
typedef void CAMetalLayer;
|
||||||
|
#endif
|
|
@ -0,0 +1,61 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "objc_bridge.h"
|
||||||
|
#include "video_core/host1x/gpu_device_memory_manager.h"
|
||||||
|
#include "video_core/renderer_base.h"
|
||||||
|
#include "video_core/renderer_metal/mtl_device.h"
|
||||||
|
#include "video_core/renderer_metal/mtl_rasterizer.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class TelemetrySession;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Core::Memory {
|
||||||
|
class Memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Tegra {
|
||||||
|
class GPU;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
class RendererMetal final : public VideoCore::RendererBase {
|
||||||
|
public:
|
||||||
|
explicit RendererMetal(Core::Frontend::EmuWindow& emu_window,
|
||||||
|
Tegra::MaxwellDeviceMemoryManager& device_memory_, Tegra::GPU& gpu_,
|
||||||
|
std::unique_ptr<Core::Frontend::GraphicsContext> context);
|
||||||
|
~RendererMetal() override;
|
||||||
|
|
||||||
|
void Composite(std::span<const Tegra::FramebufferConfig> framebuffer) override;
|
||||||
|
|
||||||
|
std::vector<u8> GetAppletCaptureBuffer() override;
|
||||||
|
|
||||||
|
VideoCore::RasterizerInterface* ReadRasterizer() override {
|
||||||
|
return &rasterizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string GetDeviceVendor() const override {
|
||||||
|
return "Apple";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||||
|
Tegra::GPU& gpu;
|
||||||
|
|
||||||
|
Device device;
|
||||||
|
// TODO: use the layer to get the drawable when drawing directly to the screen
|
||||||
|
const CAMetalLayer* layer;
|
||||||
|
|
||||||
|
RasterizerMetal rasterizer;
|
||||||
|
|
||||||
|
// HACK
|
||||||
|
MTLTexture_t renderTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -0,0 +1,60 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/frontend/emu_window.h"
|
||||||
|
#include "core/frontend/graphics_context.h"
|
||||||
|
#include "video_core/capture.h"
|
||||||
|
#include "video_core/renderer_metal/renderer_metal.h"
|
||||||
|
#include "video_core/renderer_metal/mtl_device.h"
|
||||||
|
|
||||||
|
namespace Metal {
|
||||||
|
|
||||||
|
RendererMetal::RendererMetal(Core::Frontend::EmuWindow& emu_window,
|
||||||
|
Tegra::MaxwellDeviceMemoryManager& device_memory_, Tegra::GPU& gpu_,
|
||||||
|
std::unique_ptr<Core::Frontend::GraphicsContext> context_)
|
||||||
|
: RendererBase(emu_window, std::move(context_)), device_memory{device_memory_},
|
||||||
|
gpu{gpu_}, device{},
|
||||||
|
layer(static_cast<const CAMetalLayer*>(render_window.GetWindowInfo().render_surface)),
|
||||||
|
rasterizer(gpu_, device, layer) {
|
||||||
|
// HACK
|
||||||
|
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm_sRGB
|
||||||
|
width:1280
|
||||||
|
height:720
|
||||||
|
mipmapped:NO];
|
||||||
|
renderTexture = [device.GetDevice() newTextureWithDescriptor:textureDescriptor];
|
||||||
|
}
|
||||||
|
|
||||||
|
RendererMetal::~RendererMetal() = default;
|
||||||
|
|
||||||
|
void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
|
||||||
|
if (framebuffers.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK
|
||||||
|
@autoreleasepool {
|
||||||
|
//id<CAMetalDrawable> drawable = [layer nextDrawable];
|
||||||
|
|
||||||
|
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||||
|
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0);
|
||||||
|
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||||
|
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||||
|
renderPassDescriptor.colorAttachments[0].texture = renderTexture;//drawable.texture;
|
||||||
|
|
||||||
|
id<MTLCommandBuffer> commandBuffer = [device.GetCommandQueue() commandBuffer];
|
||||||
|
id<MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
||||||
|
[renderEncoder endEncoding];
|
||||||
|
//[commandBuffer presentDrawable:drawable];
|
||||||
|
[commandBuffer commit];
|
||||||
|
}
|
||||||
|
|
||||||
|
gpu.RendererFrameEndNotify();
|
||||||
|
rasterizer.TickFrame();
|
||||||
|
|
||||||
|
render_window.OnFrameDisplayed();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<u8> RendererMetal::GetAppletCaptureBuffer() {
|
||||||
|
return std::vector<u8>(VideoCore::Capture::TiledSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Metal
|
|
@ -11,6 +11,9 @@
|
||||||
#include "video_core/renderer_null/renderer_null.h"
|
#include "video_core/renderer_null/renderer_null.h"
|
||||||
#include "video_core/renderer_opengl/renderer_opengl.h"
|
#include "video_core/renderer_opengl/renderer_opengl.h"
|
||||||
#include "video_core/renderer_vulkan/renderer_vulkan.h"
|
#include "video_core/renderer_vulkan/renderer_vulkan.h"
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include "video_core/renderer_metal/renderer_metal.h"
|
||||||
|
#endif
|
||||||
#include "video_core/video_core.h"
|
#include "video_core/video_core.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -22,7 +25,9 @@ std::unique_ptr<VideoCore::RendererBase> CreateRenderer(
|
||||||
|
|
||||||
switch (Settings::values.renderer_backend.GetValue()) {
|
switch (Settings::values.renderer_backend.GetValue()) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// do nothing for now, include metal in here at later date.
|
case Settings::RendererBackend::Metal:
|
||||||
|
return std::make_unique<Metal::RendererMetal>(emu_window, device_memory, gpu,
|
||||||
|
std::move(context));
|
||||||
#else
|
#else
|
||||||
// openGL, not supported on Apple so not bothering to include if macos
|
// openGL, not supported on Apple so not bothering to include if macos
|
||||||
case Settings::RendererBackend::OpenGL:
|
case Settings::RendererBackend::OpenGL:
|
||||||
|
|
Loading…
Reference in New Issue