5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_CONTEXT_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_CONTEXT_VK_H_
10 #include "flutter/fml/concurrent_message_loop.h"
11 #include "flutter/fml/mapping.h"
12 #include "flutter/fml/unique_fd.h"
34 class CommandEncoderFactoryVK;
35 class CommandEncoderVK;
36 class CommandPoolRecyclerVK;
39 class ResourceManagerVK;
40 class SurfaceContextVK;
42 class DescriptorPoolRecyclerVK;
44 class DescriptorPoolVK;
49 : device_holder_(
std::move(device_holder)) {}
52 std::shared_ptr<DeviceHolderVK> strong_device_holder_ =
53 device_holder_.lock();
54 if (strong_device_holder_ && strong_device_holder_->GetDevice()) {
55 [[maybe_unused]]
auto result =
56 strong_device_holder_->GetDevice().waitIdle();
61 std::weak_ptr<DeviceHolderVK> device_holder_;
66 public std::enable_shared_from_this<ContextVK> {
134 const std::shared_ptr<const Capabilities>&
GetCapabilities()
const override;
138 std::shared_ptr<CommandBuffer> cmd_buffer)
override;
150 template <
typename T>
155 template <
typename T>
157 std::string_view label,
158 std::string_view trailing)
const {
163 std::string combined =
SPrintF(
"%s %s", label.data(), trailing.data());
167 template <
typename T>
170 std::string_view label) {
176 auto c_handle =
static_cast<typename T::CType
>(handle);
178 vk::DebugUtilsObjectNameInfoEXT info;
179 info.objectType = T::objectType;
180 info.pObjectName = label.data();
181 info.objectHandle =
reinterpret_cast<decltype(info.objectHandle)
>(c_handle);
183 if (device.setDebugUtilsObjectNameEXT(info) != vk::Result::eSuccess) {
192 return device_holder_;
201 const std::shared_ptr<fml::ConcurrentTaskRunner>
236 std::shared_ptr<CommandBuffer> command_buffer)
override;
244 return idle_waiter_vk_;
250 const vk::Device&
GetDevice()
const override {
return device.get(); }
253 return physical_device;
256 ~DeviceHolderImpl() {
263 vk::UniqueInstance instance;
264 vk::PhysicalDevice physical_device;
265 vk::UniqueDevice device;
269 std::shared_ptr<DeviceHolderImpl> device_holder_;
270 std::unique_ptr<DriverInfoVK> driver_info_;
271 std::unique_ptr<DebugReportVK> debug_report_;
272 std::shared_ptr<Allocator> allocator_;
273 std::shared_ptr<ShaderLibraryVK> shader_library_;
274 std::shared_ptr<SamplerLibraryVK> sampler_library_;
275 std::shared_ptr<PipelineLibraryVK> pipeline_library_;
276 std::shared_ptr<YUVConversionLibraryVK> yuv_conversion_library_;
278 std::shared_ptr<const Capabilities> device_capabilities_;
279 std::shared_ptr<FenceWaiterVK> fence_waiter_;
280 std::shared_ptr<ResourceManagerVK> resource_manager_;
281 std::shared_ptr<DescriptorPoolRecyclerVK> descriptor_pool_recycler_;
282 std::shared_ptr<CommandPoolRecyclerVK> command_pool_recycler_;
283 std::string device_name_;
284 std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
285 std::shared_ptr<GPUTracerVK> gpu_tracer_;
286 std::shared_ptr<CommandQueue> command_queue_vk_;
287 std::shared_ptr<const IdleWaiter> idle_waiter_vk_;
288 WorkaroundsVK workarounds_;
290 using DescriptorPoolMap =
291 std::unordered_map<std::thread::id, std::shared_ptr<DescriptorPoolVK>>;
293 mutable Mutex desc_pool_mutex_;
294 mutable DescriptorPoolMap IPLR_GUARDED_BY(desc_pool_mutex_)
295 cached_descriptor_pool_;
296 bool should_enable_surface_control_ =
false;
297 bool should_batch_cmd_buffers_ =
false;
298 std::vector<std::shared_ptr<CommandBuffer>> pending_command_buffers_;
300 const uint64_t hash_;
302 bool is_valid_ =
false;
304 explicit ContextVK(
const Flags& flags);
306 void Setup(Settings settings);
308 ContextVK(
const ContextVK&) =
delete;
310 ContextVK& operator=(
const ContextVK&) =
delete;
To do anything rendering related with Impeller, you need a context.
void SetOffscreenFormat(PixelFormat pixel_format)
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
std::shared_ptr< ResourceManagerVK > GetResourceManager() const
vk::PhysicalDevice GetPhysicalDevice() const
const std::shared_ptr< YUVConversionLibraryVK > & GetYUVConversionLibrary() const
bool SetDebugName(T handle, std::string_view label) const
std::shared_ptr< const IdleWaiter > GetIdleWaiter() const override
bool EnqueueCommandBuffer(std::shared_ptr< CommandBuffer > command_buffer) override
Enqueue command_buffer for submission by the end of the frame.
void RecordFrameEndTime() const
const vk::Device & GetDevice() const
bool FlushCommandBuffers() override
Flush all pending command buffers.
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
const std::unique_ptr< DriverInfoVK > & GetDriverInfo() const
void DisposeThreadLocalCachedResources() override
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
virtual bool SubmitOnscreen(std::shared_ptr< CommandBuffer > cmd_buffer) override
Submit the command buffer that renders to the onscreen surface.
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
static std::shared_ptr< ContextVK > Create(Settings settings)
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
const std::shared_ptr< QueueVK > & GetGraphicsQueue() const
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
RuntimeStageBackend GetRuntimeStageBackend() const override
Retrieve the runtime stage for this context type.
std::shared_ptr< CommandPoolRecyclerVK > GetCommandPoolRecycler() const
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
void InitializeCommonlyUsedShadersIfNeeded() const override
std::shared_ptr< FenceWaiterVK > GetFenceWaiter() const
bool GetShouldEnableSurfaceControlSwapchain() const
Whether the Android Surface control based swapchain should be enabled.
std::shared_ptr< GPUTracerVK > GetGPUTracer() const
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
std::string DescribeGpuModel() const override
static bool SetDebugName(const vk::Device &device, T handle, std::string_view label)
const WorkaroundsVK & GetWorkarounds() const
const std::shared_ptr< fml::ConcurrentTaskRunner > GetConcurrentWorkerTaskRunner() const
static size_t ChooseThreadCountForWorkers(size_t hardware_concurrency)
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
vk::Instance GetInstance() const
std::shared_ptr< DeviceHolderVK > GetDeviceHolder() const
bool SetDebugName(T handle, std::string_view label, std::string_view trailing) const
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< DescriptorPoolRecyclerVK > GetDescriptorPoolRecycler() const
std::shared_ptr< SurfaceContextVK > CreateSurfaceContext()
Holds a strong reference to the underlying logical Vulkan device. This comes in handy when the contex...
IdleWaiterVK(std::weak_ptr< DeviceHolderVK > device_holder)
void WaitIdle() const override
bool HasValidationLayers()
std::string SPrintF(const char *format,...)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
std::vector< std::string > device_extensions
VkPhysicalDevice physical_device
uint32_t queue_family_index
std::vector< std::string > instance_extensions
Settings(Settings &&)=default
bool enable_surface_control
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
PFN_vkGetInstanceProcAddr proc_address_callback
bool fatal_missing_validations
If validations are requested but cannot be enabled, log a fatal error.
std::optional< EmbedderData > embedder_data
fml::UniqueFD cache_directory
A non-exhaustive set of driver specific workarounds.