37 public std::enable_shared_from_this<ContextMTL> {
39 static std::shared_ptr<ContextMTL>
Create(
40 const std::vector<std::string>& shader_library_paths,
41 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
43 static std::shared_ptr<ContextMTL>
Create(
44 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
45 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
46 const std::string& label,
47 std::optional<PixelFormat> pixel_format_override = std::nullopt);
49 static std::shared_ptr<ContextMTL>
Create(
51 id<MTLCommandQueue> command_queue,
52 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
53 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
54 const std::string& label);
89 const std::shared_ptr<const Capabilities>&
GetCapabilities()
const override;
91 void SetCapabilities(
const std::shared_ptr<const Capabilities>& capabilities);
104 std::shared_ptr<GPUTracerMTL> GetGPUTracer()
const;
113 explicit SyncSwitchObserver(
ContextMTL& parent);
114 virtual ~SyncSwitchObserver() =
default;
115 void OnSyncSwitchUpdate(
bool new_value)
override;
121 id<MTLDevice> device_ =
nullptr;
122 id<MTLCommandQueue> command_queue_ =
nullptr;
123 std::shared_ptr<ShaderLibraryMTL> shader_library_;
124 std::shared_ptr<PipelineLibraryMTL> pipeline_library_;
125 std::shared_ptr<SamplerLibrary> sampler_library_;
126 std::shared_ptr<AllocatorMTL> resource_allocator_;
127 std::shared_ptr<const Capabilities> device_capabilities_;
128 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
130 std::shared_ptr<GPUTracerMTL> gpu_tracer_;
132 std::deque<std::function<void()>> tasks_awaiting_gpu_;
133 std::unique_ptr<SyncSwitchObserver> sync_switch_observer_;
134 std::shared_ptr<CommandQueue> command_queue_ip_;
135 bool is_valid_ =
false;
138 id<MTLCommandQueue> command_queue,
139 NSArray<id<MTLLibrary>>* shader_libraries,
140 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
141 std::optional<PixelFormat> pixel_format_override = std::nullopt);
143 std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
144 id<MTLCommandQueue>
queue)
const;
146 void FlushTasksAwaitingGPU();
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
id< MTLCommandBuffer > CreateMTLCommandBuffer(const std::string &label) const
void SetCapabilities(const std::shared_ptr< const Capabilities > &capabilities)
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
std::string DescribeGpuModel() const override
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
void StoreTaskForGPU(const std::function< void()> &task) override
bool UpdateOffscreenLayerPixelFormat(PixelFormat format) override
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
id< MTLDevice > GetMTLDevice() const
std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() const
To do anything rendering related with Impeller, you need a context.
uint32_t uint32_t * format