mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 06:42:46 +01:00
metal: create basic graphics pipeline
This commit is contained in:
parent
bc25c8831d
commit
c8a717651c
3 changed files with 234 additions and 0 deletions
|
@ -379,6 +379,7 @@ if (APPLE)
|
|||
renderer_metal/mtl_buffer_cache_base.cpp
|
||||
renderer_metal/mtl_command_recorder.cpp
|
||||
renderer_metal/mtl_device.cpp
|
||||
renderer_metal/mtl_graphics_pipeline.cpp
|
||||
renderer_metal/mtl_rasterizer.cpp
|
||||
renderer_metal/mtl_staging_buffer_pool.cpp
|
||||
renderer_metal/mtl_swap_chain.cpp
|
||||
|
|
98
src/video_core/renderer_metal/mtl_graphics_pipeline.cpp
Normal file
98
src/video_core/renderer_metal/mtl_graphics_pipeline.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <span>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/container/static_vector.hpp>
|
||||
|
||||
#include "video_core/renderer_metal/mtl_graphics_pipeline.h"
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "video_core/buffer_cache/buffer_cache_base.h"
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_metal/mtl_command_recorder.h"
|
||||
#include "video_core/renderer_metal/mtl_device.h"
|
||||
#include "video_core/shader_notify.h"
|
||||
#include "video_core/texture_cache/texture_cache_base.h"
|
||||
|
||||
namespace Metal {
|
||||
namespace {
|
||||
using Tegra::Texture::TexturePair;
|
||||
using VideoCommon::NUM_RT;
|
||||
using VideoCore::Surface::PixelFormat;
|
||||
using VideoCore::Surface::PixelFormatFromDepthFormat;
|
||||
using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
|
||||
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
||||
} // Anonymous namespace
|
||||
|
||||
GraphicsPipeline::GraphicsPipeline(const Device& device_, CommandRecorder& command_recorder_,
|
||||
const GraphicsPipelineCacheKey& key_, BufferCache& buffer_cache_,
|
||||
TextureCache& texture_cache_,
|
||||
VideoCore::ShaderNotify* shader_notify,
|
||||
std::array<MTL::Function*, NUM_STAGES> functions_,
|
||||
const std::array<const Shader::Info*, NUM_STAGES>& infos)
|
||||
: device{device_}, command_recorder{command_recorder_}, key{key_}, buffer_cache{buffer_cache_},
|
||||
texture_cache{texture_cache_}, functions{functions_} {
|
||||
if (shader_notify) {
|
||||
shader_notify->MarkShaderBuilding();
|
||||
}
|
||||
for (size_t stage = 0; stage < NUM_STAGES; ++stage) {
|
||||
const Shader::Info* const info{infos[stage]};
|
||||
if (!info) {
|
||||
continue;
|
||||
}
|
||||
stage_infos[stage] = *info;
|
||||
}
|
||||
Validate();
|
||||
// TODO: is the framebuffer available by this time?
|
||||
Framebuffer* framebuffer = texture_cache.GetFramebuffer();
|
||||
if (!framebuffer) {
|
||||
LOG_DEBUG(Render_Metal, "framebuffer not available");
|
||||
return;
|
||||
}
|
||||
MakePipeline(framebuffer->GetHandle());
|
||||
// configure_func = ConfigureFunc(functions, stage_infos);
|
||||
}
|
||||
|
||||
template <typename Spec>
|
||||
void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
void GraphicsPipeline::ConfigureDraw() {
|
||||
Framebuffer* framebuffer = texture_cache.GetFramebuffer();
|
||||
if (!framebuffer) {
|
||||
return;
|
||||
}
|
||||
// MTL::RenderPassDescriptor* render_pass = framebuffer->GetHandle();
|
||||
|
||||
// TODO: bind resources
|
||||
}
|
||||
|
||||
void GraphicsPipeline::MakePipeline(MTL::RenderPassDescriptor* render_pass) {
|
||||
MTL::RenderPipelineDescriptor* pipeline_descriptor =
|
||||
MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
pipeline_descriptor->setVertexFunction(functions[0]);
|
||||
pipeline_descriptor->setFragmentFunction(functions[1]);
|
||||
// pipeline_descriptor->setVertexDescriptor(vertex_descriptor);
|
||||
// TODO: get the attachment count from render pass descriptor
|
||||
for (u32 index = 0; index < NUM_RT; index++) {
|
||||
auto* render_pass_attachment = render_pass->colorAttachments()->object(index);
|
||||
// TODO: is this the correct way to check if the attachment is valid?
|
||||
if (!render_pass_attachment->texture()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* color_attachment = pipeline_descriptor->colorAttachments()->object(index);
|
||||
color_attachment->setPixelFormat(render_pass_attachment->texture()->pixelFormat());
|
||||
// TODO: provide blend information
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsPipeline::Validate() {
|
||||
// TODO: validate pipeline
|
||||
}
|
||||
|
||||
} // namespace Metal
|
135
src/video_core/renderer_metal/mtl_graphics_pipeline.h
Normal file
135
src/video_core/renderer_metal/mtl_graphics_pipeline.h
Normal file
|
@ -0,0 +1,135 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <type_traits>
|
||||
|
||||
#include <Metal/Metal.hpp>
|
||||
|
||||
#include "common/thread_worker.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_metal/mtl_buffer_cache.h"
|
||||
#include "video_core/renderer_metal/mtl_texture_cache.h"
|
||||
|
||||
namespace VideoCore {
|
||||
class ShaderNotify;
|
||||
}
|
||||
|
||||
namespace Metal {
|
||||
|
||||
struct GraphicsPipelineCacheKey {
|
||||
std::array<u64, 6> unique_hashes;
|
||||
// TODO: include fixed state
|
||||
|
||||
size_t Hash() const noexcept;
|
||||
|
||||
bool operator==(const GraphicsPipelineCacheKey& rhs) const noexcept;
|
||||
|
||||
bool operator!=(const GraphicsPipelineCacheKey& rhs) const noexcept {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
size_t Size() const noexcept {
|
||||
return sizeof(unique_hashes);
|
||||
}
|
||||
};
|
||||
static_assert(std::has_unique_object_representations_v<GraphicsPipelineCacheKey>);
|
||||
static_assert(std::is_trivially_copyable_v<GraphicsPipelineCacheKey>);
|
||||
static_assert(std::is_trivially_constructible_v<GraphicsPipelineCacheKey>);
|
||||
|
||||
} // namespace Metal
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<Metal::GraphicsPipelineCacheKey> {
|
||||
size_t operator()(const Metal::GraphicsPipelineCacheKey& k) const noexcept {
|
||||
return k.Hash();
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
namespace Metal {
|
||||
|
||||
class Device;
|
||||
class CommandRecorder;
|
||||
|
||||
class GraphicsPipeline {
|
||||
static constexpr size_t NUM_STAGES = Tegra::Engines::Maxwell3D::Regs::MaxShaderStage;
|
||||
|
||||
public:
|
||||
// TODO: accept render pass cache as an argument to provide info on color and depth attachments
|
||||
explicit GraphicsPipeline(const Device& device_, CommandRecorder& command_recorder_,
|
||||
const GraphicsPipelineCacheKey& key_, BufferCache& buffer_cache_,
|
||||
TextureCache& texture_cache_, VideoCore::ShaderNotify* shader_notify,
|
||||
std::array<MTL::Function*, NUM_STAGES> functions_,
|
||||
const std::array<const Shader::Info*, NUM_STAGES>& infos);
|
||||
|
||||
GraphicsPipeline& operator=(GraphicsPipeline&&) noexcept = delete;
|
||||
GraphicsPipeline(GraphicsPipeline&&) noexcept = delete;
|
||||
|
||||
GraphicsPipeline& operator=(const GraphicsPipeline&) = delete;
|
||||
GraphicsPipeline(const GraphicsPipeline&) = delete;
|
||||
|
||||
// TODO: implement
|
||||
void AddTransition(GraphicsPipeline* transition) {}
|
||||
|
||||
void Configure(bool is_indexed) {
|
||||
// configure_func(this, is_indexed);
|
||||
}
|
||||
|
||||
[[nodiscard]] GraphicsPipeline* Next(const GraphicsPipelineCacheKey& current_key) noexcept {
|
||||
// TODO: implement
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsBuilt() const noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Spec>
|
||||
static auto MakeConfigureSpecFunc() {
|
||||
return [](GraphicsPipeline* pl, bool is_indexed) { pl->ConfigureImpl<Spec>(is_indexed); };
|
||||
}
|
||||
|
||||
void SetEngine(Tegra::Engines::Maxwell3D* maxwell3d_, Tegra::MemoryManager* gpu_memory_) {
|
||||
maxwell3d = maxwell3d_;
|
||||
gpu_memory = gpu_memory_;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Spec>
|
||||
void ConfigureImpl(bool is_indexed);
|
||||
|
||||
void ConfigureDraw();
|
||||
|
||||
void MakePipeline(MTL::RenderPassDescriptor* render_pass);
|
||||
|
||||
void Validate();
|
||||
|
||||
const Device& device;
|
||||
CommandRecorder& command_recorder;
|
||||
const GraphicsPipelineCacheKey key;
|
||||
Tegra::Engines::Maxwell3D* maxwell3d;
|
||||
Tegra::MemoryManager* gpu_memory;
|
||||
BufferCache& buffer_cache;
|
||||
TextureCache& texture_cache;
|
||||
|
||||
void (*configure_func)(GraphicsPipeline*, bool){};
|
||||
|
||||
std::array<MTL::Function*, NUM_STAGES> functions;
|
||||
|
||||
std::array<Shader::Info, NUM_STAGES> stage_infos;
|
||||
// VideoCommon::UniformBufferSizes uniform_buffer_sizes{};
|
||||
// u32 num_textures{};
|
||||
|
||||
MTL::RenderPipelineState* pipeline_state{nullptr};
|
||||
};
|
||||
|
||||
} // namespace Metal
|
Loading…
Reference in a new issue