67 public std::enable_shared_from_this<ContextMTL> {
69 static std::shared_ptr<ContextMTL>
Create(
71 const std::vector<std::string>& shader_library_paths,
72 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
74 static std::shared_ptr<ContextMTL>
Create(
76 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
77 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
78 const std::string& label,
79 std::optional<PixelFormat> pixel_format_override = std::nullopt);
81 static std::shared_ptr<ContextMTL>
Create(
84 id<MTLCommandQueue> command_queue,
85 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
86 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
87 const std::string& label);
130 const std::shared_ptr<const Capabilities>&
GetCapabilities()
const override;
135 void SetCapabilities(
const std::shared_ptr<const Capabilities>& capabilities);
148 std::shared_ptr<GPUTracerMTL> GetGPUTracer()
const;
150 const std::shared_ptr<ImpellerMetalCaptureManager> GetCaptureManager()
const;
166 explicit SyncSwitchObserver(
ContextMTL& parent);
167 virtual ~SyncSwitchObserver() =
default;
168 void OnSyncSwitchUpdate(
bool new_value)
override;
174 struct PendingTasks {
179 id<MTLDevice> device_ =
nullptr;
180 id<MTLCommandQueue> command_queue_ =
nullptr;
181 std::shared_ptr<ShaderLibraryMTL> shader_library_;
182 std::shared_ptr<PipelineLibraryMTL> pipeline_library_;
183 std::shared_ptr<SamplerLibrary> sampler_library_;
184 std::shared_ptr<AllocatorMTL> resource_allocator_;
185 std::shared_ptr<const Capabilities> device_capabilities_;
186 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
187 std::shared_ptr<GpuSubmissionTracker> submission_tracker_ =
188 std::make_shared<GpuSubmissionTracker>();
189 Mutex tasks_awaiting_gpu_mutex_;
190 std::deque<PendingTasks> tasks_awaiting_gpu_
192 std::unique_ptr<SyncSwitchObserver> sync_switch_observer_;
193 std::shared_ptr<CommandQueue> command_queue_ip_;
195 std::shared_ptr<GPUTracerMTL> gpu_tracer_;
196 std::shared_ptr<ImpellerMetalCaptureManager> capture_manager_;
198 bool is_valid_ =
false;
202 id<MTLCommandQueue> command_queue,
203 NSArray<id<MTLLibrary>>* shader_libraries,
204 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
205 std::optional<PixelFormat> pixel_format_override = std::nullopt);
207 std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
208 id<MTLCommandQueue>
queue)
const;
To do anything rendering related with Impeller, you need a context.
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
void FlushTasksAwaitingGPU()
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,...
static std::shared_ptr< ContextMTL > Create(const Flags &flags, const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
std::string DescribeGpuModel() const override
RuntimeStageBackend GetRuntimeStageBackend() const override
Retrieve the runtime stage for this context type.
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
bool FinishQueue() override
Wait until all previously submitted command buffers are processed and displayed by the GPU.
std::shared_ptr< const GpuSubmissionTracker > GetSubmissionTracker() const override
Returns the tracker recording GPU completion of command buffer submissions, or nullptr if the backend...
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
void StoreTaskForGPU(const fml::closure &task, const fml::closure &failure) override
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
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...
const std::shared_ptr< GpuSubmissionTracker > & GetMutableSubmissionTracker() const
id< MTLDevice > GetMTLDevice() const
std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() const
uint32_t uint32_t * format