To do anything rendering related with Impeller, you need a context. More...
#include <context.h>
Public Types | |
| enum | BackendType { BackendType::kMetal, BackendType::kOpenGLES, BackendType::kVulkan } |
Public Member Functions | |
| virtual | ~Context () |
| Destroys an Impeller context. More... | |
| virtual BackendType | GetBackendType () const =0 |
| Get the graphics backend of an Impeller context. More... | |
| virtual std::string | DescribeGpuModel () const =0 |
| virtual bool | IsValid () const =0 |
| Determines if a context is valid. If the caller ever receives an invalid context, they must discard it and construct a new context. There is no recovery mechanism to repair a bad context. More... | |
| virtual const std::shared_ptr< const Capabilities > & | GetCapabilities () const =0 |
Get the capabilities of Impeller context. All optionally supported feature of the platform, client-rendering API, and device can be queried using the Capabilities. More... | |
| virtual bool | UpdateOffscreenLayerPixelFormat (PixelFormat format) |
| virtual std::shared_ptr< Allocator > | GetResourceAllocator () const =0 |
| Returns the allocator used to create textures and buffers on the device. More... | |
| virtual std::shared_ptr< ShaderLibrary > | GetShaderLibrary () const =0 |
| Returns the library of shaders used to specify the programmable stages of a pipeline. More... | |
| virtual std::shared_ptr< SamplerLibrary > | GetSamplerLibrary () const =0 |
| Returns the library of combined image samplers used in shaders. More... | |
| virtual std::shared_ptr< PipelineLibrary > | GetPipelineLibrary () const =0 |
| Returns the library of pipelines used by render or compute commands. More... | |
| virtual std::shared_ptr< CommandBuffer > | CreateCommandBuffer () const =0 |
| Create a new command buffer. Command buffers can be used to encode graphics, blit, or compute commands to be submitted to the device. More... | |
| virtual std::shared_ptr< CommandQueue > | GetCommandQueue () const =0 |
| Return the graphics queue for submitting command buffers. More... | |
| virtual void | Shutdown ()=0 |
| Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops. More... | |
| virtual void | StoreTaskForGPU (const fml::closure &task, const fml::closure &failure) |
| virtual void | InitializeCommonlyUsedShadersIfNeeded () const |
| virtual void | DisposeThreadLocalCachedResources () |
Static Public Attributes | |
| static constexpr int32_t | kMaxTasksAwaitingGPU = 10 |
Protected Member Functions | |
| Context () | |
Protected Attributes | |
| std::vector< std::function< void()> > | per_frame_task_ |
To do anything rendering related with Impeller, you need a context.
Contexts are expensive to construct and typically you only need one in the process. The context represents a connection to a graphics or compute accelerator on the device.
If there are multiple context in a process, it would typically be for separation of concerns (say, use with multiple engines in Flutter), talking to multiple accelerators, or talking to the same accelerator using different client APIs (Metal, Vulkan, OpenGL ES, etc..).
Contexts are thread-safe. They may be created, used, and collected (though not from a thread used by an internal pool) on any thread. They may also be accessed simultaneously from multiple threads.
Contexts are abstract and a concrete instance must be created using one of the subclasses of Context in //impeller/renderer/backend.
|
strong |
|
virtualdefault |
Destroys an Impeller context.
|
protecteddefault |
|
pure virtual |
Create a new command buffer. Command buffers can be used to encode graphics, blit, or compute commands to be submitted to the device.
A command buffer can only be used on a single thread. Multi-threaded render, blit, or compute passes must create a new command buffer on each thread.
Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::TypographerContextSTB::CreateGlyphAtlas(), and impeller::testing::CreateTestYUVTextures().
|
pure virtual |
Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
|
inlinevirtual |
Dispose resources that are cached on behalf of the current thread.
Some backends such as Vulkan may cache resources that can be reused while executing a rendering operation. This API can be called after the operation completes in order to clear the cache.
Reimplemented in impeller::ContextVK, and impeller::SurfaceContextVK.
|
pure virtual |
Get the graphics backend of an Impeller context.
This is useful for cases where a renderer needs to track and
lookup backend-specific resources, like shaders or uniform
layout information.
It's not recommended to use this as a substitute for
per-backend capability checking. Instead, check for specific
capabilities via `GetCapabilities()`.
Context. Implemented in impeller::ContextMTL, impeller::ContextVK, impeller::SurfaceContextVK, and impeller::ContextGLES.
Referenced by impeller::TypographerContextSkia::CreateGlyphAtlas().
|
pure virtual |
Get the capabilities of Impeller context. All optionally supported feature of the platform, client-rendering API, and device can be queried using the Capabilities.
nullptr for a valid context. Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::CreateDefaultPipeline(), impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::TypographerContextSTB::CreateGlyphAtlas(), impeller::RenderTargetAllocator::CreateOffscreen(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults(), and impeller::RenderTarget::SetupDepthStencilAttachments().
|
pure virtual |
Return the graphics queue for submitting command buffers.
Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.
Referenced by impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::TypographerContextSTB::CreateGlyphAtlas(), and impeller::testing::CreateTestYUVTextures().
|
pure virtual |
Returns the library of pipelines used by render or compute commands.
nullptr for a valid context. Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::CreatePipelineFuture().
|
pure virtual |
Returns the allocator used to create textures and buffers on the device.
nullptr for a valid context. Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::TypographerContextSTB::CreateGlyphAtlas(), and impeller::testing::CreateTestYUVTextures().
|
pure virtual |
Returns the library of combined image samplers used in shaders.
nullptr for a valid context. Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
|
pure virtual |
Returns the library of shaders used to specify the programmable stages of a pipeline.
nullptr for a valid context. Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::ComputePipelineBuilder< ComputeShader_ >::InitializePipelineDescriptorDefaults(), and impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults().
|
inlinevirtual |
Run backend specific additional setup and create common shader variants.
This bootstrap is intended to improve the performance of several first frame benchmarks that are tracked in the flutter device lab. The workload includes initializing commonly used but not default shader variants, as well as forcing driver initialization.
Reimplemented in impeller::ContextVK, and impeller::SurfaceContextVK.
|
pure virtual |
Determines if a context is valid. If the caller ever receives an invalid context, they must discard it and construct a new context. There is no recovery mechanism to repair a bad context.
It is convention in Impeller to never return an invalid context from a call that returns an pointer to a context. The call implementation performs validity checks itself and return a null context instead of a pointer to an invalid context.
How a context goes invalid is backend specific. It could happen due to device loss, or any other unrecoverable error.
Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
Referenced by impeller::CreatePipelineFuture().
|
pure virtual |
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops.
Implemented in impeller::ContextMTL, impeller::ContextVK, and impeller::SurfaceContextVK.
|
inlinevirtual |
Stores a task on the ContextMTL that is awaiting access for the GPU.
The task will be executed in the event that the GPU access has changed to being available or that the task has been canceled. The task should operate with the SyncSwitch to make sure the GPU is accessible.
If the queue of pending tasks is cleared without GPU access, then the failure callback will be invoked and the primary task function will not
Threadsafe.
task will be executed on the platform thread.
Reimplemented in impeller::ContextMTL.
|
virtual |
Reimplemented in impeller::ContextMTL.
Definition at line 13 of file context.cc.
|
staticconstexpr |
The maximum number of tasks that should ever be stored for StoreTaskForGPU.
This number was arbitrarily chosen. The idea is that this is a somewhat rare situation where tasks happen to get executed in that tiny amount of time while an app is being backgrounded but still executing.
|
protected |