| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <Metal/Metal.h> |
| 7 |
#include <QuartzCore/QuartzCore.h> |
| 8 |
|
| 9 |
#include "VideoCommon/AbstractGfx.h" |
| 10 |
|
| 11 |
#include "VideoBackends/Metal/MRCHelpers.h" |
| 12 |
|
| 13 |
namespace Metal |
| 14 |
{ |
| 15 |
class Framebuffer; |
| 16 |
class Texture; |
| 17 |
|
| 18 |
class Gfx final : public ::AbstractGfx |
| 19 |
{ |
| 20 |
public: |
| 21 |
Gfx(MRCOwned<CAMetalLayer*> layer); |
| 22 |
~Gfx() override; |
| 23 |
|
| 24 |
bool IsHeadless() const override; |
| 25 |
|
| 26 |
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config, |
| 27 |
std::string_view name) override; |
| 28 |
std::unique_ptr<AbstractStagingTexture> |
| 29 |
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; |
| 30 |
std::unique_ptr<AbstractFramebuffer> |
| 31 |
CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment, |
| 32 |
std::vector<AbstractTexture*> additional_color_attachments) override; |
| 33 |
|
| 34 |
std::unique_ptr<AbstractShader> |
| 35 |
CreateShaderFromSource(ShaderStage stage, std::string_view source, |
| 36 |
VideoCommon::ShaderIncluder* shader_includer, |
| 37 |
std::string_view name) override; |
| 38 |
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data, |
| 39 |
size_t length, |
| 40 |
std::string_view name) override; |
| 41 |
std::unique_ptr<AbstractShader> CreateShaderFromMSL(ShaderStage stage, std::string msl, |
| 42 |
std::string_view glsl, std::string_view name); |
| 43 |
std::unique_ptr<NativeVertexFormat> |
| 44 |
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; |
| 45 |
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config, |
| 46 |
const void* cache_data = nullptr, |
| 47 |
size_t cache_data_length = 0) override; |
| 48 |
|
| 49 |
void Flush() override; |
| 50 |
void WaitForGPUIdle() override; |
| 51 |
void OnConfigChanged(u32 bits) override; |
| 52 |
|
| 53 |
void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool color_enable, bool alpha_enable, |
| 54 |
bool z_enable, u32 color, u32 z) override; |
| 55 |
|
| 56 |
void SetPipeline(const AbstractPipeline* pipeline) override; |
| 57 |
void SetFramebuffer(AbstractFramebuffer* framebuffer) override; |
| 58 |
void SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer) override; |
| 59 |
void SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, const ClearColor& color_value = {}, |
| 60 |
float depth_value = 0.0f) override; |
| 61 |
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override; |
| 62 |
void SetTexture(u32 index, const AbstractTexture* texture) override; |
| 63 |
void SetSamplerState(u32 index, const SamplerState& state) override; |
| 64 |
void SetComputeImageTexture(u32 index, AbstractTexture* texture, bool read, bool write) override; |
| 65 |
void UnbindTexture(const AbstractTexture* texture) override; |
| 66 |
void SetViewport(float x, float y, float width, float height, float near_depth, |
| 67 |
float far_depth) override; |
| 68 |
void Draw(u32 base_vertex, u32 num_vertices) override; |
| 69 |
void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override; |
| 70 |
void DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y, |
| 71 |
u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z) override; |
| 72 |
bool BindBackbuffer(const ClearColor& clear_color = {}) override; |
| 73 |
void PresentBackbuffer() override; |
| 74 |
|
| 75 |
SurfaceInfo GetSurfaceInfo() const override; |
| 76 |
|
| 77 |
private: |
| 78 |
MRCOwned<CAMetalLayer*> m_layer; |
| 79 |
MRCOwned<id<CAMetalDrawable>> m_drawable; |
| 80 |
std::unique_ptr<Texture> m_bb_texture; |
| 81 |
std::unique_ptr<Framebuffer> m_backbuffer; |
| 82 |
u32 m_texture_counter = 0; |
| 83 |
u32 m_staging_texture_counter = 0; |
| 84 |
std::array<u32, 4> m_shader_counter = {}; |
| 85 |
|
| 86 |
void CheckForSurfaceChange(); |
| 87 |
void CheckForSurfaceResize(); |
| 88 |
void SetupSurface(); |
| 89 |
}; |
| 90 |
} |