Comparer les révisions

...

8 Révisions

Auteur SHA1 Message Date
Samuliak bc25c8831d
metal: test buffer creation 2024-04-07 09:25:03 +02:00
Samuliak b3e8d8d11f
metal: create buffer cache on startup 2024-04-07 09:06:15 +02:00
AMA2581 d33d50780e
adding swiftUI notice 2024-04-07 08:12:08 +03:30
Exverge 0feb0aa7a1
metal: todo a fix for NULL images 2024-04-06 23:15:48 -04:00
Exverge 32c49173ad
fix: clang format 2024-04-06 22:00:34 -04:00
Exverge c3584e6c39
metal: make metal-cpp a proper external 2024-04-06 21:55:33 -04:00
Exverge 76009b05a8
temp CI fix 2024-04-06 20:52:29 -04:00
Exverge 3f76e5b8d7
metal: logging 2024-04-06 20:51:23 -04:00
13 fichiers modifiés avec 88 ajouts et 77 suppressions

Voir le fichier

@ -19,7 +19,7 @@ on:
# paths-ignore:
# - 'src/android/**'
push:
branches: [ "dev" ]
branches: [ "dev", "metal-dev" ]
paths:
- 'src/**'
- 'CMakeModules/**'

Voir le fichier

@ -320,3 +320,9 @@ if (ARCHITECTURE_arm64 AND NOT TARGET sse2neon)
add_library(sse2neon INTERFACE)
target_include_directories(sse2neon INTERFACE sse2neon)
endif()
# metal-cpp
if (APPLE)
add_library(metal-cpp INTERFACE)
target_include_directories(metal-cpp INTERFACE metal-cpp)
endif()

Voir le fichier

@ -255,7 +255,7 @@ printf( "string = \"%s\"\n", [string cStringUsingEncoding: NSASCIIStringEncoding
```objc
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString* string = [NSString stringWithCString: "Hello World" encoding: NSASCIIStringEncoding];
printf( "string = \"%s\"\n", [string cStringUsingEncoding: NSASCIIStringEncoding] );
[pool release];

Voir le fichier

@ -184,11 +184,6 @@ else()
endif()
endif()
if (APPLE)
# TODO: use target_link_libraries
include_directories(${CMAKE_SOURCE_DIR}/externals/metal-cpp)
endif()
add_subdirectory(common)
add_subdirectory(core)
add_subdirectory(audio_core)

Voir le fichier

@ -292,8 +292,8 @@ struct NullRenderWidget : public RenderWidget {
GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
Core::System& system_)
: QWidget(parent), emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)},
system{system_} {
: QWidget(parent),
emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)}, system{system_} {
setWindowTitle(QStringLiteral("suyu %1 | %2-%3")
.arg(QString::fromUtf8(Common::g_build_name),
QString::fromUtf8(Common::g_scm_branch),

Voir le fichier

@ -42,8 +42,12 @@ target_include_directories(suyu-cmd PRIVATE ${RESOURCES_DIR})
target_link_libraries(suyu-cmd PRIVATE SDL2::SDL2 Vulkan::Headers)
if(UNIX AND NOT APPLE)
install(TARGETS suyu-cmd)
if(UNIX)
if (APPLE)
target_link_libraries(suyu-cmd PRIVATE metal-cpp)
else()
install(TARGETS suyu-cmd)
endif()
endif()
if(WIN32)

Voir le fichier

@ -17,7 +17,7 @@
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,
const std::string window_title = fmt::format("suyu {} | {}-{} (Metal)", 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,
@ -39,18 +39,8 @@ EmuWindow_SDL2_MTL::EmuWindow_SDL2_MTL(InputCommon::InputSubsystem* input_subsys
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;
}
window_info.type = Core::Frontend::WindowSystemType::Cocoa;
window_info.render_surface = SDL_Metal_CreateView(render_window);
OnResize();
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);

Voir le fichier

@ -405,6 +405,10 @@ add_dependencies(video_core host_shaders)
target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE})
target_link_libraries(video_core PRIVATE sirit Vulkan::Headers Vulkan::UtilityHeaders GPUOpen::VulkanMemoryAllocator)
if (APPLE)
target_link_libraries(video_core PRIVATE metal-cpp)
endif()
if (ENABLE_NSIGHT_AFTERMATH)
if (NOT DEFINED ENV{NSIGHT_AFTERMATH_SDK})
message(FATAL_ERROR "Environment variable NSIGHT_AFTERMATH_SDK has to be provided")

Voir le fichier

@ -39,12 +39,12 @@ BufferView::~BufferView() {
}
Buffer::Buffer(BufferCacheRuntime& runtime, VideoCommon::NullBufferParams null_params)
: VideoCommon::BufferBase(null_params), buffer{runtime.CreateNullBuffer()}, is_null{true},
: BufferBase(null_params), buffer{runtime.CreateNullBuffer()}, is_null{true},
view(buffer, 0, BufferCacheRuntime::NULL_BUFFER_SIZE) {}
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
: VideoCommon::BufferBase(cpu_addr_, size_bytes_),
buffer{CreatePrivateBuffer(runtime.device, size_bytes_)}, view(buffer, 0, size_bytes_) {}
: BufferBase(cpu_addr_, size_bytes_), buffer{CreatePrivateBuffer(runtime.device, size_bytes_)},
view(buffer, 0, size_bytes_) {}
BufferView Buffer::View(u32 offset, u32 size, VideoCore::Surface::PixelFormat format) {
return BufferView(buffer, offset, size, format);

Voir le fichier

@ -2,20 +2,18 @@
// 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/buffer_cache/buffer_cache.h"
#include "video_core/control/channel_state.h"
#include "video_core/engines/draw_manager.h"
#include "video_core/engines/kepler_compute.h"
#include "video_core/engines/maxwell_3d.h"
#include "video_core/host1x/host1x.h"
#include "video_core/memory_manager.h"
#include "video_core/renderer_metal/mtl_command_recorder.h"
#include "video_core/renderer_metal/mtl_device.h"
#include "video_core/renderer_metal/mtl_rasterizer.h"
#include "video_core/texture_cache/texture_cache_base.h"
#include <iostream>
namespace Metal {
AccelerateDMA::AccelerateDMA() = default;
@ -34,16 +32,18 @@ RasterizerMetal::RasterizerMetal(Tegra::GPU& gpu_,
: gpu{gpu_}, device_memory{device_memory_}, device{device_},
command_recorder{command_recorder_}, swap_chain{swap_chain_},
staging_buffer_pool(device, command_recorder),
buffer_cache_runtime(device, command_recorder, staging_buffer_pool),
buffer_cache(device_memory, buffer_cache_runtime),
texture_cache_runtime(device, command_recorder, staging_buffer_pool),
texture_cache(texture_cache_runtime, device_memory) {}
RasterizerMetal::~RasterizerMetal() = default;
void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
// TODO: uncomment
//command_recorder.CheckIfRenderPassIsActive();
//const auto& draw_state = maxwell3d->draw_manager->GetDrawState();
// command_recorder.CheckIfRenderPassIsActive();
// const auto& draw_state = maxwell3d->draw_manager->GetDrawState();
if (is_indexed) {
std::cout << "Draw indexed" << std::endl;
LOG_DEBUG(Render_Metal, "indexed");
/*[command_buffer drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexCount:draw_params.num_indices
indexType:MTLIndexTypeUInt32
@ -52,22 +52,26 @@ void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
instanceCount:draw_params.num_instances
baseVertex:draw_params.base_vertex
baseInstance:draw_params.base_instance];*/
//cmdbuf.DrawIndexed(draw_params.num_vertices, draw_params.num_instances,
// draw_params.first_index, draw_params.base_vertex,
// draw_params.base_instance);
// cmdbuf.DrawIndexed(draw_params.num_vertices, draw_params.num_instances,
// draw_params.first_index, draw_params.base_vertex,
// draw_params.base_instance);
} else {
std::cout << "Draw" << std::endl;
//cmdbuf.Draw(draw_params.num_vertices, draw_params.num_instances,
// draw_params.base_vertex, draw_params.base_instance);
LOG_DEBUG(Render_Metal, "not indexed");
// cmdbuf.Draw(draw_params.num_vertices, draw_params.num_instances,
// draw_params.base_vertex, draw_params.base_instance);
}
// HACK: test is buffers are being correctly created
buffer_cache.UpdateGraphicsBuffers(is_indexed);
buffer_cache.BindHostGeometryBuffers(is_indexed);
}
void RasterizerMetal::DrawTexture() {
std::cout << "Draw texture" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::Clear(u32 layer_count) {
std::cout << "Clear" << std::endl;
LOG_DEBUG(Render_Metal, "called");
texture_cache.UpdateRenderTargets(true);
const Framebuffer* const framebuffer = texture_cache.GetFramebuffer();
@ -80,16 +84,16 @@ void RasterizerMetal::Clear(u32 layer_count) {
}
void RasterizerMetal::DispatchCompute() {
std::cout << "Dispatch compute" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::ResetCounter(VideoCommon::QueryType type) {
std::cout << "Reset counter" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
VideoCommon::QueryPropertiesFlags flags, u32 payload, u32 subreport) {
std::cout << "Query" << std::endl;
LOG_DEBUG(Render_Metal, "called");
// TODO: remove this
if (!gpu_memory) {
@ -106,19 +110,19 @@ void RasterizerMetal::Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
void RasterizerMetal::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
u32 size) {
std::cout << "Bind graphics uniform buffer" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::DisableGraphicsUniformBuffer(size_t stage, u32 index) {
std::cout << "Disable graphics uniform buffer" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::FlushAll() {
std::cout << "Flush all" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::FlushRegion(DAddr addr, u64 size, VideoCommon::CacheType) {
std::cout << "Flush region" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
bool RasterizerMetal::MustFlushRegion(DAddr addr, u64 size, VideoCommon::CacheType) {
@ -126,7 +130,7 @@ bool RasterizerMetal::MustFlushRegion(DAddr addr, u64 size, VideoCommon::CacheTy
}
void RasterizerMetal::InvalidateRegion(DAddr addr, u64 size, VideoCommon::CacheType) {
std::cout << "Invalidate region" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
bool RasterizerMetal::OnCPUWrite(PAddr addr, u64 size) {
@ -134,11 +138,11 @@ bool RasterizerMetal::OnCPUWrite(PAddr addr, u64 size) {
}
void RasterizerMetal::OnCacheInvalidation(PAddr addr, u64 size) {
std::cout << "On cache invalidation" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
VideoCore::RasterizerDownloadArea RasterizerMetal::GetFlushArea(PAddr addr, u64 size) {
std::cout << "Get flush area" << std::endl;
LOG_DEBUG(Render_Metal, "called");
VideoCore::RasterizerDownloadArea new_area{
.start_address = Common::AlignDown(addr, Core::DEVICE_PAGESIZE),
@ -149,31 +153,31 @@ VideoCore::RasterizerDownloadArea RasterizerMetal::GetFlushArea(PAddr addr, u64
}
void RasterizerMetal::InvalidateGPUCache() {
std::cout << "Invalidate GPU cache" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::UnmapMemory(DAddr addr, u64 size) {
std::cout << "Unmap memory" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) {
std::cout << "Modify GPU memory" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::SignalFence(std::function<void()>&& func) {
std::cout << "Signal fence" << std::endl;
LOG_DEBUG(Render_Metal, "called");
func();
}
void RasterizerMetal::SyncOperation(std::function<void()>&& func) {
std::cout << "Sync operation" << std::endl;
LOG_DEBUG(Render_Metal, "called");
func();
}
void RasterizerMetal::SignalSyncPoint(u32 value) {
std::cout << "Signal sync point" << std::endl;
LOG_DEBUG(Render_Metal, "called");
auto& syncpoint_manager = gpu.Host1x().GetSyncpointManager();
syncpoint_manager.IncrementGuest(value);
@ -181,35 +185,35 @@ void RasterizerMetal::SignalSyncPoint(u32 value) {
}
void RasterizerMetal::SignalReference() {
std::cout << "Signal reference" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::ReleaseFences(bool) {
std::cout << "Release fences" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::FlushAndInvalidateRegion(DAddr addr, u64 size, VideoCommon::CacheType) {
std::cout << "Flush and invalidate region" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::WaitForIdle() {
std::cout << "Wait for idle" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::FragmentBarrier() {
std::cout << "Fragment barrier" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::TiledCacheBarrier() {
std::cout << "Tiled cache barrier" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::FlushCommands() {
std::cout << "Flush commands" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::TickFrame() {
std::cout << "Tick frame" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
Tegra::Engines::AccelerateDMAInterface& RasterizerMetal::AccessAccelerateDMA() {
@ -219,39 +223,42 @@ Tegra::Engines::AccelerateDMAInterface& RasterizerMetal::AccessAccelerateDMA() {
bool RasterizerMetal::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
const Tegra::Engines::Fermi2D::Surface& dst,
const Tegra::Engines::Fermi2D::Config& copy_config) {
std::cout << "Accelerate surface copy" << std::endl;
LOG_DEBUG(Render_Metal, "called");
return true;
}
void RasterizerMetal::AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
std::span<const u8> memory) {
std::cout << "Accelerate inline to memory" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
const VideoCore::DiskResourceLoadCallback& callback) {
std::cout << "Load disk resources" << std::endl;
LOG_DEBUG(Render_Metal, "called");
}
void RasterizerMetal::InitializeChannel(Tegra::Control::ChannelState& channel) {
std::cout << "Initialize channel" << std::endl;
LOG_DEBUG(Render_Metal, "called");
CreateChannel(channel);
buffer_cache.CreateChannel(channel);
texture_cache.CreateChannel(channel);
}
void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) {
std::cout << "Bind channel" << std::endl;
LOG_DEBUG(Render_Metal, "called");
BindToChannel(channel.bind_id);
buffer_cache.BindToChannel(channel.bind_id);
texture_cache.BindToChannel(channel.bind_id);
}
void RasterizerMetal::ReleaseChannel(s32 channel_id) {
std::cout << "Release channel" << std::endl;
LOG_DEBUG(Render_Metal, "called");
EraseChannel(channel_id);
buffer_cache.EraseChannel(channel_id);
texture_cache.EraseChannel(channel_id);
}

Voir le fichier

@ -4,10 +4,11 @@
#pragma once
#include "common/common_types.h"
#include "mtl_texture_cache.h"
#include "mtl_buffer_cache.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/mtl_buffer_cache.h"
#include "video_core/renderer_metal/mtl_texture_cache.h"
namespace Core {
@ -102,6 +103,8 @@ private:
const SwapChain& swap_chain;
StagingBufferPool staging_buffer_pool;
BufferCacheRuntime buffer_cache_runtime;
BufferCache buffer_cache;
TextureCacheRuntime texture_cache_runtime;
TextureCache texture_cache;
};

Voir le fichier

@ -103,7 +103,7 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI
ImageId image_id_, Image& image)
: VideoCommon::ImageViewBase{info, image.info, image_id_, image.gpu_addr} {
using Shader::TextureType;
// TODO: For whatever reason, some images's internal objc objects is NULL, metal-cpp provides no method to check for this
texture = image.GetHandle()->retain();
// TODO: create texture view

Voir le fichier

@ -7,13 +7,15 @@
#include "video_core/renderer_metal/mtl_device.h"
#include "video_core/renderer_metal/renderer_metal.h"
// TODO: Make it the way that we can make a swiftUI for the macOS app instead of qt
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{}, command_recorder(device),
: RendererBase(emu_window, std::move(context_)),
device_memory{device_memory_}, gpu{gpu_}, device{}, command_recorder(device),
swap_chain(device, command_recorder,
static_cast<CA::MetalLayer*>(render_window.GetWindowInfo().render_surface)),
rasterizer(gpu_, device_memory, device, command_recorder, swap_chain) {}