| 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 = 1024
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 131 of file context_vk.cc.

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

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

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

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

## ◆ DescribeGpuModel()

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

Implements impeller::Context.

Definition at line 515 of file context_vk.cc.

515 {
516 return device_name_;
517 }

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

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

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

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

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

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

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

140 {
141 return Context::BackendType::kVulkan;
142 }
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 617 of file context_vk.cc.

617 {
618 return device_capabilities_;
619 }

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

## ◆ GetCommandPoolRecycler()

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

Definition at line 637 of file context_vk.cc.

638 {
639 return command_pool_recycler_;
640 }

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

651 {
652 return command_queue_vk_;
653 }

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

## ◆ GetConcurrentWorkerTaskRunner()

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

Definition at line 597 of file context_vk.cc.

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

## ◆ GetDescriptorPoolRecycler()

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

Definition at line 646 of file context_vk.cc.

647 {
648 return descriptor_pool_recycler_;
649 }

## ◆ GetDevice()

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

Definition at line 592 of file context_vk.cc.

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

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

735 {
736 return driver_info_;
737 }

## ◆ GetFenceWaiter()

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

Definition at line 629 of file context_vk.cc.

629 {
630 return fence_waiter_;
631 }

## ◆ GetGPUTracer()

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

Definition at line 642 of file context_vk.cc.

642 {
643 return gpu_tracer_;
644 }

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

## ◆ GetGraphicsQueue()

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

Definition at line 621 of file context_vk.cc.

621 {
622 return queues_.graphics_queue;
623 }
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 588 of file context_vk.cc.

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

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

## ◆ GetPhysicalDevice()

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

Definition at line 625 of file context_vk.cc.

625 {
626 return device_holder_->physical_device;
627 }

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

535 {
536 return pipeline_library_;
537 }

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

523 {
524 return allocator_;
525 }

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

## ◆ GetResourceManager()

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

Definition at line 633 of file context_vk.cc.

633 {
634 return resource_manager_;
635 }

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

745 {
746 return RuntimeStageBackend::kVulkan;
747 }
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 531 of file context_vk.cc.

531 {
532 return sampler_library_;
533 }

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

527 {
528 return shader_library_;
529 }

## ◆ GetShouldEnableSurfaceControlSwapchain()

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

Whether the Android Surface control based swapchain should be enabled.

Definition at line 739 of file context_vk.cc.

739 {
740 return should_enable_surface_control_ &&
741 CapabilitiesVK::Cast(*device_capabilities_)
742 .SupportsExternalSemaphoreExtensions();
743 }
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:837

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

## ◆ GetWorkarounds()

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

Definition at line 753 of file context_vk.cc.

753 {
754 return workarounds_;
755 }

## ◆ GetYUVConversionLibrary()

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

Definition at line 731 of file context_vk.cc.

731 {
732 return yuv_conversion_library_;
733 }

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

682 {
683 RenderTargetAllocator rt_allocator(GetResourceAllocator());
684 RenderTarget render_target =
685 rt_allocator.CreateOffscreenMSAA(*this, {1, 1}, 1);
686
687 RenderPassBuilderVK builder;
688
689 render_target.IterateAllColorAttachments(
690 [&builder](size_t index, const ColorAttachment& attachment) -> bool {
691 builder.SetColorAttachment(
692 index, //
693 attachment.texture->GetTextureDescriptor().format, //
694 attachment.texture->GetTextureDescriptor().sample_count, //
695 attachment.load_action, //
696 attachment.store_action //
697 );
698 return true;
699 });
700
701 if (const auto& depth = render_target.GetDepthAttachment();
702 depth.has_value()) {
703 builder.SetDepthStencilAttachment(
704 depth->texture->GetTextureDescriptor().format, //
705 depth->texture->GetTextureDescriptor().sample_count, //
706 depth->load_action, //
707 depth->store_action //
708 );
709 } else if (const auto& stencil = render_target.GetStencilAttachment();
710 stencil.has_value()) {
711 builder.SetStencilAttachment(
712 stencil->texture->GetTextureDescriptor().format, //
713 stencil->texture->GetTextureDescriptor().sample_count, //
714 stencil->load_action, //
715 stencil->store_action //
716 );
717 }
718
719 auto pass = builder.Build(GetDevice());
720 }
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:523
impeller::ContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: context_vk.cc:592

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

519 {
520 return is_valid_;
521 }

## ◆ 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 = std::format("{} {}", label, trailing);
164 return SetDebugName(GetDevice(), handle, combined);
165 }

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

## ◆ SetOffscreenFormat()

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

Definition at line 510 of file context_vk.cc.

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

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

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

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

749 {
750 return EnqueueCommandBuffer(std::move(cmd_buffer));
751 }
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:655

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