Flutter Impeller
impeller::Context Class Referenceabstract

To do anything rendering related with Impeller, you need a context. More...

#include <context.h>

Inheritance diagram for impeller::Context:
impeller::ContextGLES impeller::ContextMTL impeller::ContextVK impeller::SurfaceContextVK

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< AllocatorGetResourceAllocator () const =0
 Returns the allocator used to create textures and buffers on the device. More...
 
virtual std::shared_ptr< ShaderLibraryGetShaderLibrary () const =0
 Returns the library of shaders used to specify the programmable stages of a pipeline. More...
 
virtual std::shared_ptr< SamplerLibraryGetSamplerLibrary () const =0
 Returns the library of combined image samplers used in shaders. More...
 
virtual std::shared_ptr< PipelineLibraryGetPipelineLibrary () const =0
 Returns the library of pipelines used by render or compute commands. More...
 
virtual std::shared_ptr< CommandBufferCreateCommandBuffer () 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 void Shutdown ()=0
 Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops. More...
 
virtual void SetSyncPresentation (bool value)
 Force the Vulkan presentation (submitKHR) to be performed on the raster task runner. More...
 
Pool< HostBuffer > & GetHostBufferPool () const
 Accessor for a pool of HostBuffers. More...
 

Public Attributes

CaptureContext capture
 

Protected Member Functions

 Context ()
 

Detailed Description

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.

Definition at line 47 of file context.h.

Member Enumeration Documentation

◆ BackendType

Enumerator
kMetal 
kOpenGLES 
kVulkan 

Definition at line 49 of file context.h.

49  {
50  kMetal,
51  kOpenGLES,
52  kVulkan,
53  };

Constructor & Destructor Documentation

◆ ~Context()

impeller::Context::~Context ( )
virtualdefault

Destroys an Impeller context.

◆ Context()

impeller::Context::Context ( )
protected

Definition at line 13 of file context.cc.

Member Function Documentation

◆ CreateCommandBuffer()

virtual std::shared_ptr<CommandBuffer> impeller::Context::CreateCommandBuffer ( ) const
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.

Returns
A new command buffer.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

◆ DescribeGpuModel()

virtual std::string impeller::Context::DescribeGpuModel ( ) const
pure virtual

◆ GetBackendType()

virtual BackendType impeller::Context::GetBackendType ( ) const
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()`.
Returns
The graphics backend of the Context.

Implemented in impeller::ContextVK, impeller::ContextMTL, impeller::ContextGLES, and impeller::SurfaceContextVK.

◆ GetCapabilities()

virtual const std::shared_ptr<const Capabilities>& impeller::Context::GetCapabilities ( ) const
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.

Returns
The capabilities. Can never be nullptr for a valid context.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

Referenced by impeller::CreateDefaultPipeline(), impeller::RenderTarget::CreateOffscreen(), impeller::RenderTarget::CreateOffscreenMSAA(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults(), and impeller::RenderTarget::SetupStencilAttachment().

◆ GetHostBufferPool()

Pool<HostBuffer>& impeller::Context::GetHostBufferPool ( ) const
inline

Accessor for a pool of HostBuffers.

Definition at line 175 of file context.h.

175 { return host_buffer_pool_; }

◆ GetPipelineLibrary()

virtual std::shared_ptr<PipelineLibrary> impeller::Context::GetPipelineLibrary ( ) const
pure virtual

Returns the library of pipelines used by render or compute commands.

Returns
The pipeline library. Can never be nullptr for a valid context.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

Referenced by impeller::CreatePipelineFuture().

◆ GetResourceAllocator()

virtual std::shared_ptr<Allocator> impeller::Context::GetResourceAllocator ( ) const
pure virtual

Returns the allocator used to create textures and buffers on the device.

Returns
The resource allocator. Can never be nullptr for a valid context.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

Referenced by impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::TypographerContextSTB::CreateGlyphAtlas(), impeller::testing::CreateTestYUVTextures(), impeller::EncodeCommand(), and impeller::EncodeCommandsInReactor().

◆ GetSamplerLibrary()

virtual std::shared_ptr<SamplerLibrary> impeller::Context::GetSamplerLibrary ( ) const
pure virtual

Returns the library of combined image samplers used in shaders.

Returns
The sampler library. Can never be nullptr for a valid context.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

◆ GetShaderLibrary()

virtual std::shared_ptr<ShaderLibrary> impeller::Context::GetShaderLibrary ( ) const
pure virtual

Returns the library of shaders used to specify the programmable stages of a pipeline.

Returns
The shader library. Can never be nullptr for a valid context.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

Referenced by impeller::ComputePipelineBuilder< ComputeShader_ >::InitializePipelineDescriptorDefaults(), and impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults().

◆ IsValid()

virtual bool impeller::Context::IsValid ( ) const
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.

Returns
If the context is valid.

Implemented in impeller::ContextVK, impeller::ContextMTL, and impeller::SurfaceContextVK.

Referenced by impeller::CreatePipelineFuture().

◆ SetSyncPresentation()

virtual void impeller::Context::SetSyncPresentation ( bool  value)
inlinevirtual

Force the Vulkan presentation (submitKHR) to be performed on the raster task runner.

This is required for correct rendering on Android when using the hybrid composition mode. This has no effect on other backends.

Reimplemented in impeller::ContextVK, and impeller::SurfaceContextVK.

Definition at line 171 of file context.h.

171 {}

◆ Shutdown()

virtual void impeller::Context::Shutdown ( )
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.

◆ UpdateOffscreenLayerPixelFormat()

bool impeller::Context::UpdateOffscreenLayerPixelFormat ( PixelFormat  format)
virtual

Reimplemented in impeller::ContextMTL.

Definition at line 15 of file context.cc.

15  {
16  return false;
17 }

Member Data Documentation

◆ capture

CaptureContext impeller::Context::capture

Definition at line 177 of file context.h.


The documentation for this class was generated from the following files:
impeller::Context::capture
CaptureContext capture
Definition: context.h:177
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::compiler::TargetPlatform::kVulkan
@ kVulkan
impeller::CaptureContext::MakeInactive
static CaptureContext MakeInactive()
Definition: capture.cc:155
impeller::compiler::TargetPlatform::kOpenGLES
@ kOpenGLES