| 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 | EmbedderData
| Embedder Stuff. More...
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...
virtual bool | SubmitOnscreen (std::shared_ptr< CommandBuffer > cmd_buffer) override
| Submit the command buffer that renders to the onscreen surface. More...
const std::shared_ptr< YUVConversionLibraryVK > & | GetYUVConversionLibrary () const
void | Shutdown () override
| Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent message loops. More...
const WorkaroundsVK & | GetWorkarounds () const
void | SetOffscreenFormat (PixelFormat pixel_format)
template<typename T >
bool | SetDebugName (T handle, std::string_view label) const
template<typename T >
bool | SetDebugName (T handle, std::string_view label, std::string_view trailing) const
std::shared_ptr< DeviceHolderVK > | GetDeviceHolder () const
vk::Instance | GetInstance () const
const vk::Device & | GetDevice () const
const std::unique_ptr< DriverInfoVK > & | GetDriverInfo () const
const std::shared_ptr< fml::ConcurrentTaskRunner > | GetConcurrentWorkerTaskRunner () const
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< CommandQueue > | GetCommandQueue () const override
| Return the graphics queue for submitting command buffers. More...
std::shared_ptr< GPUTracerVK > | GetGPUTracer () const
void | RecordFrameEndTime () const
void | InitializeCommonlyUsedShadersIfNeeded () const override
void | DisposeThreadLocalCachedResources () override
bool | GetShouldEnableSurfaceControlSwapchain () const
| Whether the Android Surface control based swapchain should be enabled. More...
bool | EnqueueCommandBuffer (std::shared_ptr< CommandBuffer > command_buffer) override
| Enqueue command_buffer for submission by the end of the frame. More...
bool | FlushCommandBuffers () override
| Flush all pending command buffers. More...
RuntimeStageBackend | GetRuntimeStageBackend () const override
| Retrieve the runtime stage for this context type. More...
std::shared_ptr< const IdleWaiter > | GetIdleWaiter () const override
Public Member Functions inherited from impeller::Context
virtual | ~Context ()
| Destroys an Impeller context. More...
virtual bool | UpdateOffscreenLayerPixelFormat (PixelFormat format)
virtual void | StoreTaskForGPU (const fml::closure &task, const fml::closure &failure)
virtual bool | AddTrackingFence (const std::shared_ptr< Texture > &texture) const
virtual void | ResetThreadLocalState () const
const Flags & | GetFlags () const

## Static Public Member Functions
static size_t | ChooseThreadCountForWorkers (size_t hardware_concurrency)
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 class | BackendType { kMetal , kOpenGLES , kVulkan }
Static Public Attributes inherited from impeller::Context
static constexpr int32_t | kMaxTasksAwaitingGPU = 64
Protected Member Functions inherited from impeller::Context
| Context (const Flags &flags)
Protected Attributes inherited from impeller::Context
Flags | flags_
std::vector< std::function< void()> > | per_frame_task_

## Detailed Description

Definition at line 64 of file context_vk.h.

## Constructor & Destructor Documentation

## ◆ ~ContextVK()

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

Definition at line 133 of file context_vk.cc.

133 {
134 if (device_holder_ && device_holder_->device) {
135 [[maybe_unused]] auto result = device_holder_->device->waitIdle();
136 }
137 if (command_pool_recycler_) {
138 command_pool_recycler_->DestroyThreadLocalPools();
139 }
140 }

## Member Function Documentation

## ◆ ChooseThreadCountForWorkers()

size_t impeller::ContextVK::ChooseThreadCountForWorkers | ( | size_t | hardware_concurrency | ) |
| static

Choose the number of worker threads the context_vk will create.

Visible for testing.

Definition at line 115 of file context_vk.cc.

115 {
116 // Never create more than 4 worker threads. Attempt to use up to
117 // half of the available concurrency.
118 return std::clamp(hardware_concurrency / 2ull, /*lo=*/1ull, /*hi=*/4ull);
119 }

Referenced by impeller::testing::TEST().

## ◆ Create()

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

Definition at line 105 of file context_vk.cc.

105 {
106 auto context = std::shared_ptr<ContextVK>(new ContextVK(settings.flags));
107 context->Setup(std::move(settings));
108 if (!context->IsValid()) {
109 return nullptr;
110 }
111 return context;
112 }

References impeller::ContextVK::Settings::flags.

Referenced by impeller::interop::ContextVK::Create(), impeller::android::testing::CreateContext(), and 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 538 of file context_vk.cc.

538 {
539 const auto& recycler = GetCommandPoolRecycler();
540 auto tls_pool = recycler->Get();
541 if (!tls_pool) {
542 return nullptr;
543 }
544
545 // look up a cached descriptor pool for the current frame and reuse it
546 // if it exists, otherwise create a new pool.
547 std::shared_ptr<DescriptorPoolVK> descriptor_pool;
548 {
549 Lock lock(desc_pool_mutex_);
550 DescriptorPoolMap::iterator current_pool =
551 cached_descriptor_pool_.find(std::this_thread::get_id());
552 if (current_pool == cached_descriptor_pool_.end()) {
553 descriptor_pool = (cached_descriptor_pool_[std::this_thread::get_id()] =
554 descriptor_pool_recycler_->GetDescriptorPool());
555 } else {
556 descriptor_pool = current_pool->second;
557 }
558 }
559
560 auto tracked_objects = std::make_shared<TrackedObjectsVK>(
561 weak_from_this(), std::move(tls_pool), std::move(descriptor_pool),
562 GetGPUTracer()->CreateGPUProbe());
563 auto queue = GetGraphicsQueue();
564
565 if (!tracked_objects || !tracked_objects->IsValid() || !queue) {
566 return nullptr;
567 }
568
569 vk::CommandBufferBeginInfo begin_info;
570 begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
571 if (tracked_objects->GetCommandBuffer().begin(begin_info) !=
572 vk::Result::eSuccess) {
573 VALIDATION_LOG << "Could not begin command buffer.";
574 return nullptr;
575 }
576
577 tracked_objects->GetGPUProbe().RecordCmdBufferStart(
578 tracked_objects->GetCommandBuffer());
579
580 return std::shared_ptr<CommandBufferVK>(new CommandBufferVK(
581 shared_from_this(), //
582 GetDeviceHolder(), //
583 std::move(tracked_objects) //
584 ));
585 }
impeller::ContextVK::GetGraphicsQueue
const std::shared_ptr< QueueVK > & GetGraphicsQueue() const
Definition: context_vk.cc:620
impeller::ContextVK::GetCommandPoolRecycler
std::shared_ptr< CommandPoolRecyclerVK > GetCommandPoolRecycler() const
Definition: context_vk.cc:636
impeller::ContextVK::GetGPUTracer
std::shared_ptr< GPUTracerVK > GetGPUTracer() const
Definition: context_vk.cc:641
impeller::ContextVK::GetDeviceHolder
std::shared_ptr< DeviceHolderVK > GetDeviceHolder() const
Definition: context_vk.h:191
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References GetCommandPoolRecycler(), GetDeviceHolder(), GetGPUTracer(), GetGraphicsQueue(), and VALIDATION_LOG.

Referenced by impeller::GPUTracerVK::InitializeQueryPool().

## ◆ CreateSurfaceContext()

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

Definition at line 612 of file context_vk.cc.

612 {
613 return std::make_shared<SurfaceContextVK>(shared_from_this());
614 }

## ◆ DescribeGpuModel()

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

Implements impeller::Context.

Definition at line 514 of file context_vk.cc.

514 {
515 return device_name_;
516 }

## ◆ DisposeThreadLocalCachedResources()

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

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 from impeller::Context.

Definition at line 720 of file context_vk.cc.

720 {
721 {
722 Lock lock(desc_pool_mutex_);
723 cached_descriptor_pool_.erase(std::this_thread::get_id());
724 }
725 command_pool_recycler_->Dispose();
726 }

## ◆ EnqueueCommandBuffer()

bool impeller::ContextVK::EnqueueCommandBuffer | ( | std::shared_ptr< CommandBuffer > | command_buffer | ) |
| override virtual

Enqueue command_buffer for submission by the end of the frame.

Certain backends may immediately flush the command buffer if batch submission is not supported. This functionality is not thread safe and should only be used via the ContentContext for rendering a 2D workload.

Returns true if submission has succeeded. If the buffer is enqueued then no error may be returned until FlushCommandBuffers is called.

Reimplemented from impeller::Context.

Definition at line 654 of file context_vk.cc.

655 {
656 if (should_batch_cmd_buffers_) {
657 pending_command_buffers_.push_back(std::move(command_buffer));
658 return true;
659 } else {
660 return GetCommandQueue()->Submit({command_buffer}).ok();
661 }
662 }
impeller::ContextVK::GetCommandQueue
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
Definition: context_vk.cc:650

References GetCommandQueue().

Referenced by SubmitOnscreen().

## ◆ FlushCommandBuffers()

bool impeller::ContextVK::FlushCommandBuffers | ( |  | ) |
| override virtual

Flush all pending command buffers.

Returns whether or not submission was successful. This functionality is not threadsafe and should only be used via the ContentContext for rendering a 2D workload.

Reimplemented from impeller::Context.

Definition at line 664 of file context_vk.cc.

664 {
665 if (pending_command_buffers_.empty()) {
666 return true;
667 }
668
669 if (should_batch_cmd_buffers_) {
670 bool result = GetCommandQueue()->Submit(pending_command_buffers_).ok();
671 pending_command_buffers_.clear();
672 return result;
673 } else {
674 return true;
675 }
676 }

References GetCommandQueue().

## ◆ 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 142 of file context_vk.cc.

142 {
143 return Context::BackendType::kVulkan;
144 }
impeller::Context::BackendType::kVulkan
@ kVulkan

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 616 of file context_vk.cc.

616 {
617 return device_capabilities_;
618 }

Referenced by impeller::AllocatedTextureSourceVK::AllocatedTextureSourceVK().

## ◆ GetCommandPoolRecycler()

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

Definition at line 636 of file context_vk.cc.

637 {
638 return command_pool_recycler_;
639 }

Referenced by CreateCommandBuffer().

## ◆ GetCommandQueue()

std::shared_ptr< CommandQueue > impeller::ContextVK::GetCommandQueue | ( |  | ) | const
| override virtual

Return the graphics queue for submitting command buffers.

Implements impeller::Context.

Definition at line 650 of file context_vk.cc.

650 {
651 return command_queue_vk_;
652 }

Referenced by EnqueueCommandBuffer(), FlushCommandBuffers(), and impeller::GPUTracerVK::InitializeQueryPool().

## ◆ GetConcurrentWorkerTaskRunner()

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

Definition at line 596 of file context_vk.cc.

596 {
597 return raster_message_loop_->GetTaskRunner();
598 }

## ◆ GetDescriptorPoolRecycler()

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

Definition at line 645 of file context_vk.cc.

646 {
647 return descriptor_pool_recycler_;
648 }

## ◆ GetDevice()

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

Definition at line 591 of file context_vk.cc.

591 {
592 return device_holder_->device.get();
593 }

Referenced by impeller::AHBSwapchainImplVK::AcquireNextDrawable(), impeller::DescriptorPoolVK::AllocateDescriptorSets(), InitializeCommonlyUsedShadersIfNeeded(), impeller::GPUTracerVK::InitializeQueryPool(), and SetDebugName().

## ◆ GetDeviceHolder()

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

Definition at line 191 of file context_vk.h.

191 {
192 return device_holder_;
193 }

Referenced by impeller::AllocatedTextureSourceVK::AllocatedTextureSourceVK(), and CreateCommandBuffer().

## ◆ GetDriverInfo()

const std::unique_ptr< DriverInfoVK > & impeller::ContextVK::GetDriverInfo | ( |  | ) | const

Definition at line 733 of file context_vk.cc.

733 {
734 return driver_info_;
735 }

## ◆ GetFenceWaiter()

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

Definition at line 628 of file context_vk.cc.

628 {
629 return fence_waiter_;
630 }

## ◆ GetGPUTracer()

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

Definition at line 641 of file context_vk.cc.

641 {
642 return gpu_tracer_;
643 }

Referenced by impeller::AHBSwapchainImplVK::AcquireNextDrawable(), and CreateCommandBuffer().

## ◆ GetGraphicsQueue()

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

Definition at line 620 of file context_vk.cc.

620 {
621 return queues_.graphics_queue;
622 }
impeller::QueuesVK::graphics_queue
std::shared_ptr< QueueVK > graphics_queue
Definition: queue_vk.h:64

References impeller::QueuesVK::graphics_queue.

Referenced by CreateCommandBuffer().

## ◆ GetHash()

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

Definition at line 104 of file context_vk.h.

104 { return hash_; }

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

## ◆ GetIdleWaiter()

std::shared_ptr<const IdleWaiter> impeller::ContextVK::GetIdleWaiter | ( |  | ) | const
| inline override virtual

Reimplemented from impeller::Context.

Definition at line 243 of file context_vk.h.

243 {
244 return idle_waiter_vk_;
245 }

## ◆ GetInstance()

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

Definition at line 587 of file context_vk.cc.

587 {
588 return *device_holder_->instance;
589 }

Referenced by impeller::interop::SwapchainVK::SwapchainVK().

## ◆ GetPhysicalDevice()

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

Definition at line 624 of file context_vk.cc.

624 {
625 return device_holder_->physical_device;
626 }

## ◆ 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 534 of file context_vk.cc.

534 {
535 return pipeline_library_;
536 }

## ◆ 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 522 of file context_vk.cc.

522 {
523 return allocator_;
524 }

Referenced by impeller::AllocatedTextureSourceVK::AllocatedTextureSourceVK(), and InitializeCommonlyUsedShadersIfNeeded().

## ◆ GetResourceManager()

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

Definition at line 632 of file context_vk.cc.

632 {
633 return resource_manager_;
634 }

## ◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::ContextVK::GetRuntimeStageBackend | ( |  | ) | const
| override virtual

Retrieve the runtime stage for this context type.

This is used by the engine shell and other subsystems for loading the correct shader types.

Implements impeller::Context.

Definition at line 743 of file context_vk.cc.

743 {
744 return RuntimeStageBackend::kVulkan;
745 }
impeller::RuntimeStageBackend::kVulkan
@ kVulkan

References impeller::kVulkan.

## ◆ 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 530 of file context_vk.cc.

530 {
531 return sampler_library_;
532 }

## ◆ 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 526 of file context_vk.cc.

526 {
527 return shader_library_;
528 }

## ◆ GetShouldEnableSurfaceControlSwapchain()

bool impeller::ContextVK::GetShouldEnableSurfaceControlSwapchain | ( |  | ) | const

Whether the Android Surface control based swapchain should be enabled.

Definition at line 737 of file context_vk.cc.

737 {
738 return should_enable_surface_control_ &&
739 CapabilitiesVK::Cast(*device_capabilities_)
740 .SupportsExternalSemaphoreExtensions();
741 }
impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:13
impeller::CapabilitiesVK::SupportsExternalSemaphoreExtensions
bool SupportsExternalSemaphoreExtensions() const
Definition: capabilities_vk.cc:811

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

## ◆ GetWorkarounds()

const WorkaroundsVK & impeller::ContextVK::GetWorkarounds | ( |  | ) | const

Definition at line 751 of file context_vk.cc.

751 {
752 return workarounds_;
753 }

## ◆ GetYUVConversionLibrary()

const std::shared_ptr< YUVConversionLibraryVK > & impeller::ContextVK::GetYUVConversionLibrary | ( |  | ) | const

Definition at line 729 of file context_vk.cc.

729 {
730 return yuv_conversion_library_;
731 }

## ◆ InitializeCommonlyUsedShadersIfNeeded()

void impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded | ( |  | ) | const
| override virtual

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 from impeller::Context.

Definition at line 681 of file context_vk.cc.

681 {
682 RenderTargetAllocator rt_allocator(GetResourceAllocator());
683 RenderTarget render_target =
684 rt_allocator.CreateOffscreenMSAA(*this, {1, 1}, 1);
685
686 RenderPassBuilderVK builder;
687
688 render_target.IterateAllColorAttachments(
689 [&builder](size_t index, const ColorAttachment& attachment) -> bool {
690 builder.SetColorAttachment(
691 index, //
692 attachment.texture->GetTextureDescriptor().format, //
693 attachment.texture->GetTextureDescriptor().sample_count, //
694 attachment.load_action, //
695 attachment.store_action //
696 );
697 return true;
698 });
699
700 if (auto depth = render_target.GetDepthAttachment(); depth.has_value()) {
701 builder.SetDepthStencilAttachment(
702 depth->texture->GetTextureDescriptor().format, //
703 depth->texture->GetTextureDescriptor().sample_count, //
704 depth->load_action, //
705 depth->store_action //
706 );
707 } else if (auto stencil = render_target.GetStencilAttachment();
708 stencil.has_value()) {
709 builder.SetStencilAttachment(
710 stencil->texture->GetTextureDescriptor().format, //
711 stencil->texture->GetTextureDescriptor().sample_count, //
712 stencil->load_action, //
713 stencil->store_action //
714 );
715 }
716
717 auto pass = builder.Build(GetDevice());
718 }
impeller::ContextVK::GetResourceAllocator
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
Definition: context_vk.cc:522
impeller::ContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: context_vk.cc:591

References impeller::RenderPassBuilderVK::Build(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::RenderTarget::GetDepthAttachment(), GetDevice(), GetResourceAllocator(), impeller::RenderTarget::GetStencilAttachment(), impeller::RenderTarget::IterateAllColorAttachments(), impeller::Attachment::load_action, impeller::RenderPassBuilderVK::SetColorAttachment(), impeller::RenderPassBuilderVK::SetDepthStencilAttachment(), impeller::RenderPassBuilderVK::SetStencilAttachment(), impeller::Attachment::store_action, and impeller::Attachment::texture.

## ◆ 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 518 of file context_vk.cc.

518 {
519 return is_valid_;
520 }

## ◆ RecordFrameEndTime()

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

## ◆ SetDebugName() [1/3]

template<typename T >

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

Definition at line 168 of file context_vk.h.

170 {
171 if (!HasValidationLayers()) {
172 // No-op if validation layers are not enabled.
173 return true;
174 }
175
176 auto c_handle = static_cast<typename T::CType>(handle);
177
178 vk::DebugUtilsObjectNameInfoEXT info;
179 info.objectType = T::objectType;
180 info.pObjectName = label.data();
181 info.objectHandle = reinterpret_cast<decltype(info.objectHandle)>(c_handle);
182
183 if (device.setDebugUtilsObjectNameEXT(info) != vk::Result::eSuccess) {
184 VALIDATION_LOG << "Unable to set debug name: " << label;
185 return false;
186 }
187
188 return true;
189 }
impeller::HasValidationLayers
bool HasValidationLayers()
Definition: context_vk.cc:53

References impeller::HasValidationLayers(), and VALIDATION_LOG.

## ◆ SetDebugName() [2/3]

template<typename T >

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

Definition at line 151 of file context_vk.h.

151 {
152 return SetDebugName(GetDevice(), handle, label);
153 }
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:151

References GetDevice().

Referenced by impeller::CreateCompatRenderPassForPipeline(), impeller::CreateSampler(), impeller::QueuesVK::FromQueueIndices(), and SetDebugName().

## ◆ SetDebugName() [3/3]

template<typename T >

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

Definition at line 156 of file context_vk.h.

158 {
159 if (!HasValidationLayers()) {
160 // No-op if validation layers are not enabled.
161 return true;
162 }
163 std::string combined = SPrintF("%s %s", label.data(), trailing.data());
164 return SetDebugName(GetDevice(), handle, combined);
165 }
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12

References GetDevice(), impeller::HasValidationLayers(), SetDebugName(), and impeller::SPrintF().

## ◆ SetOffscreenFormat()

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

Definition at line 509 of file context_vk.cc.

509 {
510 CapabilitiesVK::Cast(*device_capabilities_).SetOffscreenFormat(pixel_format);
511 }
impeller::CapabilitiesVK::SetOffscreenFormat
void SetOffscreenFormat(PixelFormat pixel_format) const
Definition: capabilities_vk.cc:510

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

## ◆ 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 600 of file context_vk.cc.

600 {
601 // There are multiple objects, for example |CommandPoolVK|, that in their
602 // destructors make a strong reference to |ContextVK|. Resetting these shared
603 // pointers ensures that cleanup happens in a correct order.
604 //
605 // tl;dr: Without it, we get thread::join failures on shutdown.
606 fence_waiter_.reset();
607 resource_manager_.reset();
608
609 raster_message_loop_->Terminate();
610 }

## ◆ SubmitOnscreen()

bool impeller::ContextVK::SubmitOnscreen | ( | std::shared_ptr< CommandBuffer > | cmd_buffer | ) |
| override virtual

Submit the command buffer that renders to the onscreen surface.

Reimplemented from impeller::Context.

Definition at line 747 of file context_vk.cc.

747 {
748 return EnqueueCommandBuffer(std::move(cmd_buffer));
749 }
impeller::ContextVK::EnqueueCommandBuffer
bool EnqueueCommandBuffer(std::shared_ptr< CommandBuffer > command_buffer) override
Enqueue command_buffer for submission by the end of the frame.
Definition: context_vk.cc:654

References EnqueueCommandBuffer().

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