| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <Metal/Metal.h> |
| 7 |
|
| 8 |
#include "VideoCommon/AbstractFramebuffer.h" |
| 9 |
#include "VideoCommon/AbstractStagingTexture.h" |
| 10 |
#include "VideoCommon/AbstractTexture.h" |
| 11 |
|
| 12 |
#include "VideoBackends/Metal/MRCHelpers.h" |
| 13 |
|
| 14 |
namespace Metal |
| 15 |
{ |
| 16 |
class Texture final : public AbstractTexture |
| 17 |
{ |
| 18 |
public: |
| 19 |
explicit Texture(MRCOwned<id<MTLTexture>> tex, const TextureConfig& config); |
| 20 |
~Texture(); |
| 21 |
|
| 22 |
void CopyRectangleFromTexture(const AbstractTexture* src, |
| 23 |
const MathUtil::Rectangle<int>& src_rect, u32 src_layer, |
| 24 |
u32 src_level, const MathUtil::Rectangle<int>& dst_rect, |
| 25 |
u32 dst_layer, u32 dst_level) override; |
| 26 |
void ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect, |
| 27 |
u32 layer, u32 level) override; |
| 28 |
void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer, size_t buffer_size, |
| 29 |
u32 layer) override; |
| 30 |
|
| 31 |
id<MTLTexture> GetMTLTexture() const { return m_tex; } |
| 32 |
|
| 33 |
private: |
| 34 |
MRCOwned<id<MTLTexture>> m_tex; |
| 35 |
}; |
| 36 |
|
| 37 |
class StagingTexture final : public AbstractStagingTexture |
| 38 |
{ |
| 39 |
public: |
| 40 |
StagingTexture(MRCOwned<id<MTLBuffer>> buffer, StagingTextureType type, |
| 41 |
const TextureConfig& config); |
| 42 |
~StagingTexture(); |
| 43 |
|
| 44 |
void CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& src_rect, |
| 45 |
u32 src_layer, u32 src_level, |
| 46 |
const MathUtil::Rectangle<int>& dst_rect) override; |
| 47 |
void CopyToTexture(const MathUtil::Rectangle<int>& src_rect, AbstractTexture* dst, |
| 48 |
const MathUtil::Rectangle<int>& dst_rect, u32 dst_layer, |
| 49 |
u32 dst_level) override; |
| 50 |
|
| 51 |
bool Map() override; |
| 52 |
void Unmap() override; |
| 53 |
void Flush() override; |
| 54 |
|
| 55 |
private: |
| 56 |
MRCOwned<id<MTLBuffer>> m_buffer; |
| 57 |
MRCOwned<id<MTLCommandBuffer>> m_wait_buffer; |
| 58 |
}; |
| 59 |
|
| 60 |
class Framebuffer final : public AbstractFramebuffer |
| 61 |
{ |
| 62 |
public: |
| 63 |
Framebuffer(AbstractTexture* color, AbstractTexture* depth, |
| 64 |
std::vector<AbstractTexture*> additonal_color_textures, |
| 65 |
u32 width, u32 height, u32 layers, u32 samples); |
| 66 |
~Framebuffer(); |
| 67 |
|
| 68 |
MTLRenderPassDescriptor* PassDesc() const { return m_pass_descriptor; } |
| 69 |
|
| 70 |
size_t NumAdditionalColorTextures() const { return m_additional_color_textures.size(); } |
| 71 |
|
| 72 |
void SetLoadAction(MTLLoadAction action) |
| 73 |
{ |
| 74 |
if (m_current_load_action != action) |
| 75 |
ActualSetLoadAction(action); |
| 76 |
} |
| 77 |
|
| 78 |
void UpdateBackbufferTexture(id<MTLTexture> tex) |
| 79 |
{ |
| 80 |
[m_pass_descriptor colorAttachments][0].texture = tex; |
| 81 |
} |
| 82 |
|
| 83 |
private: |
| 84 |
MRCOwned<MTLRenderPassDescriptor*> m_pass_descriptor; |
| 85 |
std::vector<AbstractTexture*> m_additional_color_textures; |
| 86 |
MTLLoadAction m_current_load_action = MTLLoadActionLoad; |
| 87 |
void ActualSetLoadAction(MTLLoadAction action); |
| 88 |
}; |
| 89 |
} |