Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Friends | List of all members
impeller::DeviceBufferMTL Class Referencefinal

#include <device_buffer_mtl.h>

Inheritance diagram for impeller::DeviceBufferMTL:
impeller::DeviceBuffer impeller::BackendCast< DeviceBufferMTL, DeviceBuffer >

Public Member Functions

 DeviceBufferMTL ()
 
 ~DeviceBufferMTL () override
 
id< MTLBuffer > GetMTLBuffer () const
 
- Public Member Functions inherited from impeller::DeviceBuffer
virtual ~DeviceBuffer ()
 
bool CopyHostBuffer (const uint8_t *source, Range source_range, size_t offset=0u)
 
const DeviceBufferDescriptorGetDeviceBufferDescriptor () const
 
virtual void Invalidate (std::optional< Range > range=std::nullopt) const
 

Private Member Functions

uint8_t * OnGetContents () const override
 
std::shared_ptr< TextureAsTexture (Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const override
 
bool OnCopyHostBuffer (const uint8_t *source, Range source_range, size_t offset) override
 
bool SetLabel (const std::string &label) override
 
bool SetLabel (const std::string &label, Range range) override
 
void Flush (std::optional< Range > range) const override
 

Friends

class AllocatorMTL
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::DeviceBuffer
static BufferView AsBufferView (std::shared_ptr< DeviceBuffer > buffer)
 Create a buffer view of this entire buffer.
 
- Static Public Member Functions inherited from impeller::BackendCast< DeviceBufferMTL, DeviceBuffer >
static DeviceBufferMTLCast (DeviceBuffer &base)
 
static const DeviceBufferMTLCast (const DeviceBuffer &base)
 
static DeviceBufferMTLCast (DeviceBuffer *base)
 
static const DeviceBufferMTLCast (const DeviceBuffer *base)
 
- Protected Member Functions inherited from impeller::DeviceBuffer
 DeviceBuffer (DeviceBufferDescriptor desc)
 
- Protected Attributes inherited from impeller::DeviceBuffer
const DeviceBufferDescriptor desc_
 

Detailed Description

Definition at line 16 of file device_buffer_mtl.h.

Constructor & Destructor Documentation

◆ DeviceBufferMTL()

impeller::DeviceBufferMTL::DeviceBufferMTL ( )

◆ ~DeviceBufferMTL()

impeller::DeviceBufferMTL::~DeviceBufferMTL ( )
overridedefault

Member Function Documentation

◆ AsTexture()

std::shared_ptr< Texture > impeller::DeviceBufferMTL::AsTexture ( Allocator allocator,
const TextureDescriptor descriptor,
uint16_t  row_bytes 
) const
overrideprivatevirtual

Reimplemented from impeller::DeviceBuffer.

Definition at line 32 of file device_buffer_mtl.mm.

35 {
36 auto mtl_texture_desc = ToMTLTextureDescriptor(descriptor);
37
38 if (!mtl_texture_desc) {
39 VALIDATION_LOG << "Texture descriptor was invalid.";
40 return nullptr;
41 }
42
43 if (@available(iOS 13.0, macos 10.15, *)) {
44 mtl_texture_desc.resourceOptions = buffer_.resourceOptions;
45 }
46
47 auto texture = [buffer_ newTextureWithDescriptor:mtl_texture_desc
48 offset:0
49 bytesPerRow:row_bytes];
50 if (!texture) {
51 return nullptr;
52 }
53 return TextureMTL::Create(descriptor, texture);
54}
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
FlTexture * texture
MTLTextureDescriptor * ToMTLTextureDescriptor(const TextureDescriptor &desc)
Point offset
#define VALIDATION_LOG
Definition validation.h:73

◆ Flush()

void impeller::DeviceBufferMTL::Flush ( std::optional< Range range) const
overrideprivatevirtual

Make any pending writes visible to the GPU.

This method must be called if the device pointer provided by [OnGetContents] is written to without using [CopyHostBuffer]. On Devices with coherent host memory, this method will not perform extra work.

If the range is not provided, the entire buffer is flushed.

Reimplemented from impeller::DeviceBuffer.

Definition at line 81 of file device_buffer_mtl.mm.

81 {
82#if !FML_OS_IOS
83 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
84 if (storage_mode_ == MTLStorageModeManaged) {
85 [buffer_
86 didModifyRange:NSMakeRange(flush_range.offset, flush_range.length)];
87 }
88#endif
89}
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const

◆ GetMTLBuffer()

id< MTLBuffer > impeller::DeviceBufferMTL::GetMTLBuffer ( ) const

Definition at line 21 of file device_buffer_mtl.mm.

21 {
22 return buffer_;
23}

◆ OnCopyHostBuffer()

bool impeller::DeviceBufferMTL::OnCopyHostBuffer ( const uint8_t *  source,
Range  source_range,
size_t  offset 
)
overrideprivatevirtual

Implements impeller::DeviceBuffer.

Definition at line 56 of file device_buffer_mtl.mm.

58 {
59 auto dest = static_cast<uint8_t*>(buffer_.contents);
60
61 if (!dest) {
62 return false;
63 }
64
65 if (source) {
66 ::memmove(dest + offset, source + source_range.offset, source_range.length);
67 }
68
69// MTLStorageModeManaged is never present on always returns false on iOS. But
70// the compiler is mad that `didModifyRange:` appears in a TU meant for iOS. So,
71// just compile it away.
72#if !FML_OS_IOS
73 if (storage_mode_ == MTLStorageModeManaged) {
74 [buffer_ didModifyRange:NSMakeRange(offset, source_range.length)];
75 }
76#endif
77
78 return true;
79}
SkBitmap source
Definition examples.cpp:28
dest
Definition zip.py:79

◆ OnGetContents()

uint8_t * impeller::DeviceBufferMTL::OnGetContents ( ) const
overrideprivatevirtual

Implements impeller::DeviceBuffer.

Definition at line 25 of file device_buffer_mtl.mm.

25 {
26 if (storage_mode_ != MTLStorageModeShared) {
27 return nullptr;
28 }
29 return reinterpret_cast<uint8_t*>(buffer_.contents);
30}

◆ SetLabel() [1/2]

bool impeller::DeviceBufferMTL::SetLabel ( const std::string &  label)
overrideprivatevirtual

Implements impeller::DeviceBuffer.

Definition at line 91 of file device_buffer_mtl.mm.

91 {
92 if (label.empty()) {
93 return false;
94 }
95 [buffer_ setLabel:@(label.c_str())];
96 return true;
97}

◆ SetLabel() [2/2]

bool impeller::DeviceBufferMTL::SetLabel ( const std::string &  label,
Range  range 
)
overrideprivatevirtual

Implements impeller::DeviceBuffer.

Definition at line 99 of file device_buffer_mtl.mm.

99 {
100 if (label.empty()) {
101 return false;
102 }
103 [buffer_ addDebugMarker:@(label.c_str())
104 range:NSMakeRange(range.offset, range.length)];
105 return true;
106}
size_t length

Friends And Related Symbol Documentation

◆ AllocatorMTL

friend class AllocatorMTL
friend

Definition at line 28 of file device_buffer_mtl.h.


The documentation for this class was generated from the following files: