| Flutter Impeller |

Classes | Public Member Functions | Static Public Member Functions | List of all members
impeller::ContextVK Class Referencefinal

`#include <context_vk.h>`

Inheritance diagram for impeller::ContextVK:

## Classes
struct | Settings

## Public Member Functions
uint64_t | GetHash () const
| ~ContextVK () override
BackendType | GetBackendType () const override
| Get the graphics backend of an Impeller context. More...
std::string | DescribeGpuModel () const override
bool | IsValid () const override
| 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...
std::shared_ptr< Allocator > | GetResourceAllocator () const override
| Returns the allocator used to create textures and buffers on the device. More...
std::shared_ptr< ShaderLibrary > | GetShaderLibrary () const override
| Returns the library of shaders used to specify the programmable stages of a pipeline. More...
std::shared_ptr< SamplerLibrary > | GetSamplerLibrary () const override
| Returns the library of combined image samplers used in shaders. More...
std::shared_ptr< PipelineLibrary > | GetPipelineLibrary () const override
| Returns the library of pipelines used by render or compute commands. More...
std::shared_ptr< CommandBuffer > | CreateCommandBuffer () const override
| Create a new command buffer. Command buffers can be used to encode graphics, blit, or compute commands to be submitted to the device. More...
const std::shared_ptr< const Capabilities > & | GetCapabilities () const override
| 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...
void | Shutdown () override
| Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops. More...
void | SetSyncPresentation (bool value) override
| Force the Vulkan presentation (submitKHR) to be performed on the raster task runner. More...
bool | GetSyncPresentation () const
void | SetOffscreenFormat (PixelFormat pixel_format)
template<typename T >
bool | SetDebugName (T handle, std::string_view label) const
std::shared_ptr< DeviceHolder > | GetDeviceHolder () const
vk::Instance | GetInstance () const
const vk::Device & | GetDevice () const
const std::shared_ptr< fml::ConcurrentTaskRunner > | GetConcurrentWorkerTaskRunner () const
const fml::RefPtr< fml::TaskRunner > | GetQueueSubmitRunner () const
| A single-threaded task runner that should only be used for submitKHR. More...
std::shared_ptr< SurfaceContextVK > | CreateSurfaceContext ()
const std::shared_ptr< QueueVK > & | GetGraphicsQueue () const
vk::PhysicalDevice | GetPhysicalDevice () const
std::shared_ptr< FenceWaiterVK > | GetFenceWaiter () const
std::shared_ptr< ResourceManagerVK > | GetResourceManager () const
std::shared_ptr< CommandPoolRecyclerVK > | GetCommandPoolRecycler () const
std::shared_ptr< DescriptorPoolRecyclerVK > | GetDescriptorPoolRecycler () const
std::shared_ptr< GPUTracerVK > | GetGPUTracer () const
void | RecordFrameEndTime () const
Public Member Functions inherited from impeller::Context
virtual | ~Context ()
| Destroys an Impeller context. More...
virtual bool | UpdateOffscreenLayerPixelFormat (PixelFormat format)
Pool< HostBuffer > & | GetHostBufferPool () const
| Accessor for a pool of HostBuffers. More...
virtual void | StoreTaskForGPU (const std::function< void()> &task)

## Static Public Member Functions
static std::shared_ptr< ContextVK > | Create (Settings settings)
template<typename T >
static bool | SetDebugName (const vk::Device &device, T handle, std::string_view label)
Static Public Member Functions inherited from impeller::BackendCast< ContextVK, Context >
static ContextVK & | Cast (Context &base)
static const ContextVK & | Cast (const Context &base)
static ContextVK * | Cast (Context *base)
static const ContextVK * | Cast (const Context *base)

## Additional Inherited Members
Public Types inherited from impeller::Context
enum | BackendType { BackendType::kMetal, BackendType::kOpenGLES, BackendType::kVulkan }
Public Attributes inherited from impeller::Context
CaptureContext | capture
Static Public Attributes inherited from impeller::Context
static constexpr int32_t | kMaxTasksAwaitingGPU = 10
Protected Member Functions inherited from impeller::Context
| Context ()

## Detailed Description

Definition at line 40 of file context_vk.h.

## Constructor & Destructor Documentation

## ◆ ~ContextVK()

impeller::ContextVK::~ContextVK | ( |  | ) |
| override

Definition at line 115 of file context_vk.cc.

115 {
116 if (device_holder_ && device_holder_->device) {
117 [[maybe_unused]] auto result = device_holder_->device->waitIdle();
118 }
119 CommandPoolRecyclerVK::DestroyThreadLocalPools(this);
120 }

References impeller::CommandPoolRecyclerVK::DestroyThreadLocalPools().

## Member Function Documentation

## ◆ Create()

std::shared_ptr< ContextVK > impeller::ContextVK::Create | ( | Settings | settings | ) |
| static

Definition at line 95 of file context_vk.cc.

95 {
96 auto context = std::shared_ptr<ContextVK>(new ContextVK());
97 context->Setup(std::move(settings));
98 if (!context->IsValid()) {
99 return nullptr;
100 }
101 return context;
102 }

Referenced by impeller::PlaygroundImplVK::PlaygroundImplVK().

## ◆ CreateCommandBuffer()

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

Implements impeller::Context.

Definition at line 490 of file context_vk.cc.

490 {
491 return std::shared_ptr<CommandBufferVK>(
492 new CommandBufferVK(shared_from_this(), //
493 CreateGraphicsCommandEncoderFactory()) //
494 );
495 }

## ◆ CreateSurfaceContext()

std::shared_ptr< SurfaceContextVK > impeller::ContextVK::CreateSurfaceContext | ( |  | ) |

Definition at line 527 of file context_vk.cc.

527 {
528 return std::make_shared<SurfaceContextVK>(shared_from_this());
529 }

## ◆ DescribeGpuModel()

std::string impeller::ContextVK::DescribeGpuModel | ( |  | ) | const
| override virtual

Implements impeller::Context.

Definition at line 466 of file context_vk.cc.

466 {
467 return device_name_;
468 }

## ◆ GetBackendType()

Context::BackendType impeller::ContextVK::GetBackendType | ( |  | ) | const
| override 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`.

Implements impeller::Context.

Definition at line 122 of file context_vk.cc.

122 {
123 return Context::BackendType::kVulkan;
124 }

References impeller::Context::kVulkan.

## ◆ GetCapabilities()

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

Implements impeller::Context.

Definition at line 531 of file context_vk.cc.

531 {
532 return device_capabilities_;
533 }

## ◆ GetCommandPoolRecycler()

std::shared_ptr< CommandPoolRecyclerVK > impeller::ContextVK::GetCommandPoolRecycler | ( |  | ) | const

Definition at line 551 of file context_vk.cc.

552 {
553 return command_pool_recycler_;
554 }

## ◆ GetConcurrentWorkerTaskRunner()

const std::shared_ptr< fml::ConcurrentTaskRunner > impeller::ContextVK::GetConcurrentWorkerTaskRunner | ( |  | ) | const

Definition at line 510 of file context_vk.cc.

510 {
511 return raster_message_loop_->GetTaskRunner();
512 }

## ◆ GetDescriptorPoolRecycler()

std::shared_ptr<DescriptorPoolRecyclerVK> impeller::ContextVK::GetDescriptorPoolRecycler | ( |  | ) | const
| inline

Definition at line 163 of file context_vk.h.

163 {
164 return descriptor_pool_recycler_;
165 }

## ◆ GetDevice()

const vk::Device & impeller::ContextVK::GetDevice | ( |  | ) | const

Definition at line 501 of file context_vk.cc.

501 {
502 return device_holder_->device.get();
503 }

Referenced by impeller::AllocateAndBindDescriptorSets(), and SetDebugName().

## ◆ GetDeviceHolder()

std::shared_ptr<DeviceHolder> impeller::ContextVK::GetDeviceHolder | ( |  | ) | const
| inline

Definition at line 128 of file context_vk.h.

128 {
129 return device_holder_;
130 }

## ◆ GetFenceWaiter()

std::shared_ptr< FenceWaiterVK > impeller::ContextVK::GetFenceWaiter | ( |  | ) | const

Definition at line 543 of file context_vk.cc.

543 {
544 return fence_waiter_;
545 }

## ◆ GetGPUTracer()

std::shared_ptr< GPUTracerVK > impeller::ContextVK::GetGPUTracer | ( |  | ) | const

Definition at line 561 of file context_vk.cc.

561 {
562 return gpu_tracer_;
563 }

## ◆ GetGraphicsQueue()

const std::shared_ptr< QueueVK > & impeller::ContextVK::GetGraphicsQueue | ( |  | ) | const

Definition at line 535 of file context_vk.cc.

535 {
536 return queues_.graphics_queue;
537 }

References impeller::QueuesVK::graphics_queue.

## ◆ GetHash()

uint64_t impeller::ContextVK::GetHash | ( |  | ) | const
| inline

Definition at line 57 of file context_vk.h.

57 { return hash_; }

Referenced by impeller::CommandPoolRecyclerVK::DestroyThreadLocalPools().

## ◆ GetInstance()

vk::Instance impeller::ContextVK::GetInstance | ( |  | ) | const

Definition at line 497 of file context_vk.cc.

497 {
498 return *device_holder_->instance;
499 }

## ◆ GetPhysicalDevice()

vk::PhysicalDevice impeller::ContextVK::GetPhysicalDevice | ( |  | ) | const

Definition at line 539 of file context_vk.cc.

539 {
540 return device_holder_->physical_device;
541 }

## ◆ GetPipelineLibrary()

std::shared_ptr< PipelineLibrary > impeller::ContextVK::GetPipelineLibrary | ( |  | ) | const
| override virtual

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

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

Implements impeller::Context.

Definition at line 486 of file context_vk.cc.

486 {
487 return pipeline_library_;
488 }

## ◆ GetQueueSubmitRunner()

const fml::RefPtr< fml::TaskRunner > impeller::ContextVK::GetQueueSubmitRunner | ( |  | ) | const

A single-threaded task runner that should only be used for submitKHR.

SubmitKHR will block until all previously submitted command buffers have been scheduled. If there are no platform views in the scene (excluding texture backed platform views). Then it is safe for SwapchainImpl::Present to return before submit has completed. To do so, we offload the submit command to a specialized single threaded task runner. The single thread ensures that we do not queue up too much work and that the submissions proceed in order.

Definition at line 505 of file context_vk.cc.

505 {
506 return queue_submit_thread_->GetTaskRunner();
507 }

## ◆ GetResourceAllocator()

std::shared_ptr< Allocator > impeller::ContextVK::GetResourceAllocator | ( |  | ) | const
| override 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.

Implements impeller::Context.

Definition at line 474 of file context_vk.cc.

474 {
475 return allocator_;
476 }

Referenced by impeller::AllocateAndBindDescriptorSets().

## ◆ GetResourceManager()

std::shared_ptr< ResourceManagerVK > impeller::ContextVK::GetResourceManager | ( |  | ) | const

Definition at line 547 of file context_vk.cc.

547 {
548 return resource_manager_;
549 }

## ◆ GetSamplerLibrary()

std::shared_ptr< SamplerLibrary > impeller::ContextVK::GetSamplerLibrary | ( |  | ) | const
| override virtual

Returns the library of combined image samplers used in shaders.

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

Implements impeller::Context.

Definition at line 482 of file context_vk.cc.

482 {
483 return sampler_library_;
484 }

## ◆ GetShaderLibrary()

std::shared_ptr< ShaderLibrary > impeller::ContextVK::GetShaderLibrary | ( |  | ) | const
| override 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.

Implements impeller::Context.

Definition at line 478 of file context_vk.cc.

478 {
479 return shader_library_;
480 }

## ◆ GetSyncPresentation()

bool impeller::ContextVK::GetSyncPresentation | ( |  | ) | const
| inline

Definition at line 95 of file context_vk.h.

95 { return sync_presentation_; }

## ◆ IsValid()

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

Implements impeller::Context.

Definition at line 470 of file context_vk.cc.

470 {
471 return is_valid_;
472 }

## ◆ RecordFrameEndTime()

void impeller::ContextVK::RecordFrameEndTime | ( |  | ) | const

## ◆ SetDebugName() [1/2]

template<typename T >

static bool impeller::ContextVK::SetDebugName | ( | const vk::Device & | device,
|  | T | handle,
|  | std::string_view | label
| ) |  |
| inline static

Definition at line 105 of file context_vk.h.

107 {
108 if (!HasValidationLayers()) {
109 // No-op if validation layers are not enabled.
110 return true;
111 }
112
113 auto c_handle = static_cast<typename T::CType>(handle);
114
115 vk::DebugUtilsObjectNameInfoEXT info;
116 info.objectType = T::objectType;
117 info.pObjectName = label.data();
118 info.objectHandle = reinterpret_cast<decltype(info.objectHandle)>(c_handle);
119
120 if (device.setDebugUtilsObjectNameEXT(info) != vk::Result::eSuccess) {
121 VALIDATION_LOG << "Unable to set debug name: " << label;
122 return false;
123 }
124
125 return true;
126 }

References impeller::HasValidationLayers(), and VALIDATION_LOG.

## ◆ SetDebugName() [2/2]

template<typename T >

bool impeller::ContextVK::SetDebugName | ( | T | handle,
|  | std::string_view | label
| ) |  | const
| inline

Definition at line 100 of file context_vk.h.

100 {
101 return SetDebugName(GetDevice(), handle, label);
102 }

References GetDevice().

Referenced by impeller::CreateCompatRenderPassForPipeline(), and impeller::QueuesVK::QueuesVK().

## ◆ SetOffscreenFormat()

void impeller::ContextVK::SetOffscreenFormat | ( | PixelFormat | pixel_format | ) |

Definition at line 461 of file context_vk.cc.

461 {
462 CapabilitiesVK::Cast(*device_capabilities_).SetOffscreenFormat(pixel_format);
463 }

References impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast(), and impeller::CapabilitiesVK::SetOffscreenFormat().

## ◆ SetSyncPresentation()

void impeller::ContextVK::SetSyncPresentation | ( | bool | value | ) |
| inline override virtual

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. This is analogous to the check for isMainThread in surface_mtl.mm to block presentation on scheduling of all pending work.

Reimplemented from impeller::Context.

Definition at line 93 of file context_vk.h.

93 { sync_presentation_ = value; }

## ◆ Shutdown()

void impeller::ContextVK::Shutdown | ( |  | ) |
| override virtual

Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops.

Implements impeller::Context.

Definition at line 514 of file context_vk.cc.

514 {
515 // There are multiple objects, for example |CommandPoolVK|, that in their
516 // destructors make a strong reference to |ContextVK|. Resetting these shared
517 // pointers ensures that cleanup happens in a correct order.
518 //
519 // tl;dr: Without it, we get thread::join failures on shutdown.
520 fence_waiter_.reset();
521 resource_manager_.reset();
522
523 queue_submit_thread_->Join();
524 raster_message_loop_->Terminate();
525 }

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

- impeller/renderer/backend/vulkan/context_vk.h
- impeller/renderer/backend/vulkan/context_vk.cc

impeller::CapabilitiesVK::SetOffscreenFormat
void SetOffscreenFormat(PixelFormat pixel_format) const
Definition: capabilities_vk.cc:342
impeller::CommandPoolRecyclerVK::DestroyThreadLocalPools
static void DestroyThreadLocalPools(const ContextVK *context)
Clean up resources held by all per-thread command pools associated with the given context.
Definition: command_pool_vk.cc:240
impeller::QueuesVK::graphics_queue
std::shared_ptr< QueueVK > graphics_queue
Definition: queue_vk.h:61
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:100
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::Context::BackendType::kVulkan
@ kVulkan
impeller::ContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: context_vk.cc:501
impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:15
impeller::HasValidationLayers
bool HasValidationLayers()
Definition: context_vk.cc:43