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< 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...
 
bool FinishQueue () override
 Wait until all previously submitted command buffers are processed and displayed by the GPU. 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 }
std::shared_ptr< ContextGLES > context

References context, and 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 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  std::move(tracked_objects) //
584  ));
585 }
const std::shared_ptr< QueueVK > & GetGraphicsQueue() const
Definition: context_vk.cc:620
std::shared_ptr< CommandPoolRecyclerVK > GetCommandPoolRecycler() const
Definition: context_vk.cc:636
std::shared_ptr< GPUTracerVK > GetGPUTracer() const
Definition: context_vk.cc:641
#define VALIDATION_LOG
Definition: validation.h:91

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

◆ 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
overridevirtual

Implements impeller::Context.

Definition at line 515 of file context_vk.cc.

515  {
516  return device_name_;
517 }

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

726  {
727  {
728  Lock lock(desc_pool_mutex_);
729  cached_descriptor_pool_.erase(std::this_thread::get_id());
730  }
731  command_pool_recycler_->Dispose();
732 }

◆ 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 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 }
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
Definition: context_vk.cc:650
std::shared_ptr< CommandBuffer > command_buffer

References command_buffer, and GetCommandQueue().

Referenced by SubmitOnscreen().

◆ FinishQueue()

bool impeller::ContextVK::FinishQueue ( )
overridevirtual

Wait until all previously submitted command buffers are processed and displayed by the GPU.

WARNING: This method call is unnecessary for nearly all use cases since asynchronous workloads are the expected norm and calling this method can negatively affect application performance. Its only use is for cases like benchmarking where proper performance metrics can only be collected by including all background processing of the GPU.

Outstanding unflushed command buffers are not committed, submitted, or enqueued by this method and such buffers should have already been flushed before this method is called. The method will only wait for work to be done that has already been submitted to the GPU.

Returns
True if the queue was successfully processed, otherwise false if there was an error or if the backend does not support synchronous reporting of completion. Implementations intended entirely for testing might simply return false, but they would not be used for benchmarking or other situations where we might measure GPU performance.

Implements impeller::Context.

Definition at line 678 of file context_vk.cc.

678  {
679  GetIdleWaiter()->WaitIdle();
680  return true;
681 }
std::shared_ptr< const IdleWaiter > GetIdleWaiter() const override
Definition: context_vk.h:246

References GetIdleWaiter().

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

616  {
617  return device_capabilities_;
618 }

◆ 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
overridevirtual

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(), and FlushCommandBuffers().

◆ 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(), 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  }

◆ GetDriverInfo()

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

Definition at line 739 of file context_vk.cc.

739  {
740  return driver_info_;
741 }

◆ 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 }
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_; }

◆ GetIdleWaiter()

std::shared_ptr<const IdleWaiter> impeller::ContextVK::GetIdleWaiter ( ) const
inlineoverridevirtual

Reimplemented from impeller::Context.

Definition at line 246 of file context_vk.h.

246  {
247  return idle_waiter_vk_;
248  }

Referenced by FinishQueue().

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

535  {
536  return pipeline_library_;
537 }

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

523  {
524  return allocator_;
525 }

Referenced by 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
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 749 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 531 of file context_vk.cc.

531  {
532  return sampler_library_;
533 }

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

743  {
744  return should_enable_surface_control_ &&
745  CapabilitiesVK::Cast(*device_capabilities_)
747 }
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 757 of file context_vk.cc.

757  {
758  return workarounds_;
759 }

◆ GetYUVConversionLibrary()

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

Definition at line 735 of file context_vk.cc.

735  {
736  return yuv_conversion_library_;
737 }

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

686  {
687  RenderTargetAllocator rt_allocator(GetResourceAllocator());
688  RenderTarget render_target =
689  rt_allocator.CreateOffscreenMSAA(*this, {1, 1}, 1);
690 
691  RenderPassBuilderVK builder;
692 
693  render_target.IterateAllColorAttachments(
694  [&builder](size_t index, const ColorAttachment& attachment) -> bool {
695  builder.SetColorAttachment(
696  index, //
697  attachment.texture->GetTextureDescriptor().format, //
698  attachment.texture->GetTextureDescriptor().sample_count, //
699  attachment.load_action, //
700  attachment.store_action //
701  );
702  return true;
703  });
704 
705  if (const auto& depth = render_target.GetDepthAttachment();
706  depth.has_value()) {
707  builder.SetDepthStencilAttachment(
708  depth->texture->GetTextureDescriptor().format, //
709  depth->texture->GetTextureDescriptor().sample_count, //
710  depth->load_action, //
711  depth->store_action //
712  );
713  } else if (const auto& stencil = render_target.GetStencilAttachment();
714  stencil.has_value()) {
715  builder.SetStencilAttachment(
716  stencil->texture->GetTextureDescriptor().format, //
717  stencil->texture->GetTextureDescriptor().sample_count, //
718  stencil->load_action, //
719  stencil->store_action //
720  );
721  }
722 
723  auto pass = builder.Build(GetDevice());
724 }
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
Definition: context_vk.cc:523
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
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 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 
)
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 ( 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  }
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 }
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 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_->Terminate();
607  resource_manager_.reset();
608 
609  raster_message_loop_->Terminate();
610 }

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

753  {
754  return EnqueueCommandBuffer(std::move(cmd_buffer));
755 }
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: