Flutter Impeller
impeller::ContextVK Class Referencefinal

#include <context_vk.h>

Inheritance diagram for impeller::ContextVK:
impeller::Context impeller::BackendCast< ContextVK, Context >

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< AllocatorGetResourceAllocator () const override
 Returns the allocator used to create textures and buffers on the device. More...
 
std::shared_ptr< ShaderLibraryGetShaderLibrary () const override
 Returns the library of shaders used to specify the programmable stages of a pipeline. More...
 
std::shared_ptr< SamplerLibraryGetSamplerLibrary () const override
 Returns the library of combined image samplers used in shaders. More...
 
std::shared_ptr< PipelineLibraryGetPipelineLibrary () const override
 Returns the library of pipelines used by render or compute commands. More...
 
std::shared_ptr< CommandBufferCreateCommandBuffer () 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 WorkaroundsVKGetWorkarounds () 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< DeviceHolderVKGetDeviceHolder () 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< SurfaceContextVKCreateSurfaceContext ()
 
const std::shared_ptr< QueueVK > & GetGraphicsQueue () const
 
vk::PhysicalDevice GetPhysicalDevice () const
 
std::shared_ptr< FenceWaiterVKGetFenceWaiter () const
 
std::shared_ptr< ResourceManagerVKGetResourceManager () const
 
std::shared_ptr< CommandPoolRecyclerVKGetCommandPoolRecycler () const
 
std::shared_ptr< DescriptorPoolRecyclerVKGetDescriptorPoolRecycler () const
 
std::shared_ptr< CommandQueueGetCommandQueue () const override
 Return the graphics queue for submitting command buffers. More...
 
std::shared_ptr< GPUTracerVKGetGPUTracer () 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 IdleWaiterGetIdleWaiter () 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 FlagsGetFlags () const
 

Static Public Member Functions

static size_t ChooseThreadCountForWorkers (size_t hardware_concurrency)
 
static std::shared_ptr< ContextVKCreate (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 ContextVKCast (Context &base)
 
static const ContextVKCast (const Context &base)
 
static ContextVKCast (Context *base)
 
static const ContextVKCast (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
overridevirtual

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

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

610  {
611  return std::make_shared<SurfaceContextVK>(shared_from_this());
612 }

◆ DescribeGpuModel()

std::string impeller::ContextVK::DescribeGpuModel ( ) const
overridevirtual

Implements impeller::Context.

Definition at line 512 of file context_vk.cc.

512  {
513  return device_name_;
514 }

◆ DisposeThreadLocalCachedResources()

void impeller::ContextVK::DisposeThreadLocalCachedResources ( )
overridevirtual

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

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

◆ EnqueueCommandBuffer()

bool impeller::ContextVK::EnqueueCommandBuffer ( std::shared_ptr< CommandBuffer command_buffer)
overridevirtual

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

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

References GetCommandQueue().

Referenced by SubmitOnscreen().

◆ FlushCommandBuffers()

bool impeller::ContextVK::FlushCommandBuffers ( )
overridevirtual

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

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

References GetCommandQueue().

◆ GetBackendType()

Context::BackendType impeller::ContextVK::GetBackendType ( ) const
overridevirtual

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.

References impeller::Context::kVulkan.

◆ GetCapabilities()

const std::shared_ptr< const Capabilities > & impeller::ContextVK::GetCapabilities ( ) const
overridevirtual

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

614  {
615  return device_capabilities_;
616 }

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

◆ GetCommandPoolRecycler()

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

Definition at line 634 of file context_vk.cc.

635  {
636  return command_pool_recycler_;
637 }

Referenced by CreateCommandBuffer().

◆ GetCommandQueue()

std::shared_ptr< CommandQueue > impeller::ContextVK::GetCommandQueue ( ) const
overridevirtual

Return the graphics queue for submitting command buffers.

Implements impeller::Context.

Definition at line 648 of file context_vk.cc.

648  {
649  return command_queue_vk_;
650 }

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

◆ GetConcurrentWorkerTaskRunner()

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

Definition at line 594 of file context_vk.cc.

594  {
595  return raster_message_loop_->GetTaskRunner();
596 }

◆ GetDescriptorPoolRecycler()

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

Definition at line 643 of file context_vk.cc.

644  {
645  return descriptor_pool_recycler_;
646 }

◆ GetDevice()

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

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

731  {
732  return driver_info_;
733 }

◆ GetFenceWaiter()

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

Definition at line 626 of file context_vk.cc.

626  {
627  return fence_waiter_;
628 }

◆ GetGPUTracer()

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

Definition at line 639 of file context_vk.cc.

639  {
640  return gpu_tracer_;
641 }

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

◆ GetGraphicsQueue()

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

Definition at line 618 of file context_vk.cc.

618  {
619  return queues_.graphics_queue;
620 }
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
inlineoverridevirtual

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

585  {
586  return *device_holder_->instance;
587 }

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

◆ GetPhysicalDevice()

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

Definition at line 622 of file context_vk.cc.

622  {
623  return device_holder_->physical_device;
624 }

◆ GetPipelineLibrary()

std::shared_ptr< PipelineLibrary > impeller::ContextVK::GetPipelineLibrary ( ) const
overridevirtual

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

532  {
533  return pipeline_library_;
534 }

◆ GetResourceAllocator()

std::shared_ptr< Allocator > impeller::ContextVK::GetResourceAllocator ( ) const
overridevirtual

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

520  {
521  return allocator_;
522 }

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

◆ GetResourceManager()

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

Definition at line 630 of file context_vk.cc.

630  {
631  return resource_manager_;
632 }

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::ContextVK::GetRuntimeStageBackend ( ) const
overridevirtual

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

References impeller::kVulkan.

◆ GetSamplerLibrary()

std::shared_ptr< SamplerLibrary > impeller::ContextVK::GetSamplerLibrary ( ) const
overridevirtual

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

528  {
529  return sampler_library_;
530 }

◆ GetShaderLibrary()

std::shared_ptr< ShaderLibrary > impeller::ContextVK::GetShaderLibrary ( ) const
overridevirtual

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

524  {
525  return shader_library_;
526 }

◆ GetShouldEnableSurfaceControlSwapchain()

bool impeller::ContextVK::GetShouldEnableSurfaceControlSwapchain ( ) const

Whether the Android Surface control based swapchain should be enabled.

Definition at line 735 of file context_vk.cc.

735  {
736  return should_enable_surface_control_ &&
737  CapabilitiesVK::Cast(*device_capabilities_)
739 }
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:13
bool SupportsExternalSemaphoreExtensions() const

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

◆ GetWorkarounds()

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

Definition at line 749 of file context_vk.cc.

749  {
750  return workarounds_;
751 }

◆ GetYUVConversionLibrary()

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

Definition at line 727 of file context_vk.cc.

727  {
728  return yuv_conversion_library_;
729 }

◆ InitializeCommonlyUsedShadersIfNeeded()

void impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded ( ) const
overridevirtual

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

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

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
overridevirtual

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

516  {
517  return is_valid_;
518 }

◆ RecordFrameEndTime()

void impeller::ContextVK::RecordFrameEndTime ( ) const

◆ SetDebugName() [1/3]

template<typename T >
static bool impeller::ContextVK::SetDebugName ( const vk::Device &  device,
handle,
std::string_view  label 
)
inlinestatic

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  }
bool HasValidationLayers()
Definition: context_vk.cc:53

References impeller::HasValidationLayers(), and VALIDATION_LOG.

◆ SetDebugName() [2/3]

template<typename T >
bool impeller::ContextVK::SetDebugName ( handle,
std::string_view  label 
) const
inline

Definition at line 151 of file context_vk.h.

151  {
152  return SetDebugName(GetDevice(), handle, label);
153  }
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 ( 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  }
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 507 of file context_vk.cc.

507  {
508  CapabilitiesVK::Cast(*device_capabilities_).SetOffscreenFormat(pixel_format);
509 }
void SetOffscreenFormat(PixelFormat pixel_format) const

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

◆ Shutdown()

void impeller::ContextVK::Shutdown ( )
overridevirtual

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

Implements impeller::Context.

Definition at line 598 of file context_vk.cc.

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

◆ SubmitOnscreen()

bool impeller::ContextVK::SubmitOnscreen ( std::shared_ptr< CommandBuffer cmd_buffer)
overridevirtual

Submit the command buffer that renders to the onscreen surface.

Reimplemented from impeller::Context.

Definition at line 745 of file context_vk.cc.

745  {
746  return EnqueueCommandBuffer(std::move(cmd_buffer));
747 }
bool EnqueueCommandBuffer(std::shared_ptr< CommandBuffer > command_buffer) override
Enqueue command_buffer for submission by the end of the frame.
Definition: context_vk.cc:652

References EnqueueCommandBuffer().


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