mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-20 23:19:44 +00:00
Shareable Vulkan image allocation on Linux relies on the dma-buf interface, which is a Linux-specific thing. Therefore, we should only be compiling it (and any code that uses it) on Linux. This change adds preprocessor guards to do that. Enabling similar functionality on other operating systems will need to leverage analogous interfaces on those platforms, e.g. win32 handles on Windows. All Vulkan image code will now be guarded by the USE_VULKAN_IMAGES preprocessor definition, currently enabled on Linux if Vulkan is available. Additionally, we shuffle around some code in OpenGLContext.cpp to simplify the preprocessor conditionals.
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef USE_VULKAN
|
|
|
|
# include <AK/Assertions.h>
|
|
# include <AK/NonnullRefPtr.h>
|
|
# include <AK/RefCounted.h>
|
|
# include <vulkan/vulkan.h>
|
|
# ifdef AK_OS_LINUX
|
|
# include <libdrm/drm_fourcc.h>
|
|
// Sharable Vulkan images are currently only implemented on Linux
|
|
# define USE_VULKAN_IMAGES 1
|
|
# endif
|
|
|
|
namespace Gfx {
|
|
|
|
struct VulkanContext {
|
|
uint32_t api_version { VK_API_VERSION_1_0 };
|
|
VkInstance instance { VK_NULL_HANDLE };
|
|
VkPhysicalDevice physical_device { VK_NULL_HANDLE };
|
|
VkDevice logical_device { VK_NULL_HANDLE };
|
|
VkQueue graphics_queue { VK_NULL_HANDLE };
|
|
uint32_t graphics_queue_family { 0 };
|
|
# ifdef USE_VULKAN_IMAGES
|
|
VkCommandPool command_pool { VK_NULL_HANDLE };
|
|
VkCommandBuffer command_buffer { VK_NULL_HANDLE };
|
|
struct
|
|
{
|
|
PFN_vkGetMemoryFdKHR get_memory_fd { nullptr };
|
|
PFN_vkGetImageDrmFormatModifierPropertiesEXT get_image_drm_format_modifier_properties { nullptr };
|
|
} ext_procs;
|
|
# endif
|
|
};
|
|
|
|
ErrorOr<VulkanContext> create_vulkan_context();
|
|
|
|
# ifdef USE_VULKAN_IMAGES
|
|
struct VulkanImage : public RefCounted<VulkanImage> {
|
|
VkImage image { VK_NULL_HANDLE };
|
|
VkDeviceMemory memory { VK_NULL_HANDLE };
|
|
struct {
|
|
VkFormat format;
|
|
VkExtent3D extent;
|
|
VkImageTiling tiling;
|
|
VkImageUsageFlags usage;
|
|
VkSharingMode sharing_mode;
|
|
VkImageLayout layout;
|
|
VkDeviceSize row_pitch; // for tiled images this is some implementation-specific value
|
|
uint64_t modifier { DRM_FORMAT_MOD_INVALID };
|
|
} info;
|
|
VulkanContext const& context;
|
|
|
|
int get_dma_buf_fd();
|
|
void transition_layout(VkImageLayout old_layout, VkImageLayout new_layout);
|
|
VulkanImage(VulkanContext const& context)
|
|
: context(context)
|
|
{
|
|
}
|
|
~VulkanImage();
|
|
};
|
|
|
|
static inline uint32_t vk_format_to_drm_format(VkFormat format)
|
|
{
|
|
switch (format) {
|
|
case VK_FORMAT_B8G8R8A8_UNORM:
|
|
return DRM_FORMAT_ARGB8888;
|
|
// add more as needed
|
|
default:
|
|
VERIFY_NOT_REACHED();
|
|
return DRM_FORMAT_INVALID;
|
|
}
|
|
}
|
|
|
|
ErrorOr<NonnullRefPtr<VulkanImage>> create_shared_vulkan_image(VulkanContext const& context, uint32_t width, uint32_t height, VkFormat format, uint32_t num_modifiers, uint64_t const* modifiers);
|
|
# endif
|
|
|
|
}
|
|
|
|
#endif
|