Ream v0.1.0-1
C++ graphics library for Linux
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
RVKImage Class Referencefinal

Vulkan implementation of RImage, obtained via RImage::asVK(). More...

#include <RVKImage.h>

+ Inheritance diagram for RVKImage:

Public Member Functions

std::shared_ptr< RGBMBogbmBo (RDevice *device=nullptr) const noexcept override
 Returns the GBM buffer object backing this image, if any.
 
std::shared_ptr< RDRMFramebufferdrmFb (RDevice *device=nullptr) const noexcept override
 Returns a DRM framebuffer for this image, if supported.
 
sk_sp< SkImage > skImage (RDevice *device=nullptr) const noexcept override
 Returns an SkImage view of this image, if supported (RImageCap_SkImage).
 
sk_sp< SkSurface > skSurface (RDevice *device=nullptr) const noexcept override
 Returns an SkSurface targeting this image, if supported (RImageCap_SkSurface).
 
CZBitset< RImageCap > checkDeviceCaps (CZBitset< RImageCap > caps, RDevice *device=nullptr) const noexcept override
 Checks which of the given capabilities are supported on a device.
 
bool writePixels (const RPixelBufferRegion &region) noexcept override
 Uploads pixel data into a region of the image.
 
bool readPixels (const RPixelBufferRegion &region) noexcept override
 Downloads pixel data from a region of the image.
 
RVKDeviceallocatorVK () const noexcept
 The device that allocated this image (owner of the primary VkImage).
 
VkImage vkImage () const noexcept
 The primary VkImage (on the allocator device).
 
VkImageView vkImageView () const noexcept
 The primary VkImageView (on the allocator device).
 
VkImage vkImage (RVKDevice *device) const noexcept
 The VkImage for device: the primary image on the allocator, else the per-device cross-device import (VK_NULL_HANDLE if not imported).
 
VkImageView vkImageView (RVKDevice *device) const noexcept
 The VkImageView for device (see vkImage(RVKDevice*)).
 
VkFormat vkFormat () const noexcept
 The image's VkFormat.
 
VkImageUsageFlags vkUsage () const noexcept
 The image's VkImageUsageFlags.
 
VkImageTiling vkTiling () const noexcept
 The image's VkImageTiling (OPTIMAL for native storage, DRM_FORMAT_MODIFIER for dma-buf).
 
std::optional< RDMABufferInfodmaExport () const noexcept
 dma-buf export of this image (single plane), for cross-device sharing / scanout.
 
bool ensureCrossDevice (RVKDevice *device) const noexcept
 Ensures this image is sampleable on device by importing its dma-buf there.
 
void transitionLayout (VkCommandBuffer cmd, VkImageLayout newLayout, VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage, VkAccessFlags srcAccess, VkAccessFlags dstAccess) const noexcept
 Records a layout transition barrier on the given command buffer.
 
VkImageLayout layout () const noexcept
 The tracked VkImageLayout of the primary image.
 
VkImageLayout layout (RVKDevice *device) const noexcept
 The tracked VkImageLayout for device (primary image on the allocator, else the per-device cross-device import).
 
void syncLayoutFromSkia () const noexcept
 Reconciles the tracked layout with Skia's after Skia rendered into this image.
 
- Public Member Functions inherited from RImage
SkISize size () const noexcept
 Returns the image size in pixels.
 
const RFormatInfoformatInfo () const noexcept
 Returns information about the image's pixel format.
 
const std::unordered_set< RFormat > & readFormats () const noexcept
 Returns the set of formats the image can be read/sampled as.
 
const std::unordered_set< RFormat > & writeFormats () const noexcept
 Returns the set of formats the image can be written to.
 
SkAlphaType alphaType () const noexcept
 Returns the image's alpha type.
 
RModifier modifier () const noexcept
 Returns the DRM format modifier of the image's storage.
 
RDeviceallocator () const noexcept
 Returns the device that allocated this image.
 
std::shared_ptr< RCorecore () const noexcept
 Returns the RCore instance that owns this image.
 
std::shared_ptr< RSyncreadSync () noexcept
 Returns the read sync fence.
 
void setReadSync (std::shared_ptr< RSync > sync) noexcept
 Sets the read sync fence.
 
std::shared_ptr< RSyncwriteSync () noexcept
 Returns the write sync fence.
 
void setWriteSync (std::shared_ptr< RSync > sync) noexcept
 Sets the write sync fence.
 
UInt32 writeSerial () const noexcept
 Returns the write serial.
 
std::shared_ptr< RGLImageasGL () const noexcept
 Attempts to cast this image to an RGLImage.
 
std::shared_ptr< RRSImageasRS () const noexcept
 Attempts to cast this image to an RRSImage.
 
std::shared_ptr< RVKImageasVK () const noexcept
 Attempts to cast this image to an RVKImage.
 
 ~RImage () noexcept
 Destructor.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Static Public Member Functions

static std::shared_ptr< RVKImageMake (SkISize size, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Creates a Vulkan-backed image of the given size and DRM format.
 
static std::shared_ptr< RVKImageFromDMA (const RDMABufferInfo &info, CZOwn ownership, const RImageConstraints *constraints=nullptr) noexcept
 Imports an existing dma-buf as a Vulkan-backed image.
 
- Static Public Member Functions inherited from RImage
static std::shared_ptr< RImageMake (SkISize size, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Allocates a new empty image.
 
static std::shared_ptr< RImageMakeFromPixels (const RPixelBufferInfo &info, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Allocates a new image and uploads pixel data into it.
 
static std::shared_ptr< RImageLoadFile (const std::filesystem::path &path, const RDRMFormat &format, SkISize size={0, 0}, const RImageConstraints *constraints=nullptr) noexcept
 Loads an image from a file.
 
static std::shared_ptr< RImageFromDMA (const RDMABufferInfo &info, CZOwn ownership, const RImageConstraints *constraints=nullptr) noexcept
 Imports an image from a DMA-buf.
 

Detailed Description

Vulkan implementation of RImage, obtained via RImage::asVK().

Backs the image with either native (VK_IMAGE_TILING_OPTIMAL, device-local) storage or GBM/dma-buf storage imported via VK_EXT_image_drm_format_modifier + external memory (for scanout and cross-device sharing). Explicit DRM format modifiers are used; multi-plane buffers are only supported when all planes reside in a single dma-buf memory object.

The tracked VkImageLayout is kept in sync with Skia's backend texture/render target so manual barriers and Skia rendering can interoperate. For cross-device sampling (SRM Prime) the image is lazily re-imported on the sampling device, keyed per device.

Member Function Documentation

◆ Make()

static std::shared_ptr< RVKImage > Make ( SkISize  size,
const RDRMFormat format,
const RImageConstraints constraints = nullptr 
)
staticnoexcept

Creates a Vulkan-backed image of the given size and DRM format.

Uses GBM/dma-buf storage when scanout (DRMFb/GBMBo) or cross-device caps are requested and the required DMA extensions are available; otherwise native optimal storage. Returns nullptr if the format is unsupported or the constraints cannot be satisfied.

◆ FromDMA()

static std::shared_ptr< RVKImage > FromDMA ( const RDMABufferInfo info,
CZOwn  ownership,
const RImageConstraints constraints = nullptr 
)
staticnoexcept

Imports an existing dma-buf as a Vulkan-backed image.

Requires VK_EXT_image_drm_format_modifier and VK_EXT_external_memory_dma_buf. When ownership is CZOwn::Own the source fds are closed before returning (on success or failure).

◆ gbmBo()

std::shared_ptr< RGBMBo > gbmBo ( RDevice device = nullptr) const
overridevirtualnoexcept

Returns the GBM buffer object backing this image, if any.

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The GBM buffer object, or nullptr if unavailable.

Implements RImage.

◆ drmFb()

std::shared_ptr< RDRMFramebuffer > drmFb ( RDevice device = nullptr) const
overridevirtualnoexcept

Returns a DRM framebuffer for this image, if supported.

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The DRM framebuffer, or nullptr if unavailable.

Implements RImage.

◆ skImage()

sk_sp< SkImage > skImage ( RDevice device = nullptr) const
overridevirtualnoexcept

Returns an SkImage view of this image, if supported (RImageCap_SkImage).

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The SkImage, or nullptr if unavailable.

Implements RImage.

◆ skSurface()

sk_sp< SkSurface > skSurface ( RDevice device = nullptr) const
overridevirtualnoexcept

Returns an SkSurface targeting this image, if supported (RImageCap_SkSurface).

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The SkSurface, or nullptr if unavailable.

Implements RImage.

◆ checkDeviceCaps()

CZBitset< RImageCap > checkDeviceCaps ( CZBitset< RImageCap >  caps,
RDevice device = nullptr 
) const
overridevirtualnoexcept

Checks which of the given capabilities are supported on a device.

Parameters
capsThe capabilities to test.
deviceDevice to query. If nullptr, the main device is used.
Returns
The subset of caps that is supported; equals caps when all are supported.

Implements RImage.

◆ writePixels()

bool writePixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Uploads pixel data into a region of the image.

Increments writeSerial() on success.

Parameters
regionSource buffer and set of rectangles to copy.
Returns
true on success, false otherwise.

Implements RImage.

◆ readPixels()

bool readPixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Downloads pixel data from a region of the image.

Parameters
regionDestination buffer and set of rectangles to copy.
Returns
true on success, false otherwise.

Implements RImage.

◆ allocatorVK()

RVKDevice * allocatorVK ( ) const
inlinenoexcept

The device that allocated this image (owner of the primary VkImage).

◆ vkImage() [1/2]

VkImage vkImage ( ) const
inlinenoexcept

The primary VkImage (on the allocator device).

◆ vkImageView() [1/2]

VkImageView vkImageView ( ) const
inlinenoexcept

The primary VkImageView (on the allocator device).

◆ vkImage() [2/2]

VkImage vkImage ( RVKDevice device) const
noexcept

The VkImage for device: the primary image on the allocator, else the per-device cross-device import (VK_NULL_HANDLE if not imported).

◆ vkImageView() [2/2]

VkImageView vkImageView ( RVKDevice device) const
noexcept

The VkImageView for device (see vkImage(RVKDevice*)).

◆ vkFormat()

VkFormat vkFormat ( ) const
inlinenoexcept

The image's VkFormat.

◆ vkUsage()

VkImageUsageFlags vkUsage ( ) const
inlinenoexcept

The image's VkImageUsageFlags.

◆ vkTiling()

VkImageTiling vkTiling ( ) const
inlinenoexcept

The image's VkImageTiling (OPTIMAL for native storage, DRM_FORMAT_MODIFIER for dma-buf).

◆ dmaExport()

std::optional< RDMABufferInfo > dmaExport ( ) const
noexcept

dma-buf export of this image (single plane), for cross-device sharing / scanout.

Only available for dma-shareable storage (GBM-backed). The caller must close the returned fds.

◆ ensureCrossDevice()

bool ensureCrossDevice ( RVKDevice device) const
noexcept

Ensures this image is sampleable on device by importing its dma-buf there.

Returns
true if the image is (now) usable as a source on device, false if it is not dma-shareable or the import failed. Enables SRM's multi-GPU Prime path.

◆ transitionLayout()

void transitionLayout ( VkCommandBuffer  cmd,
VkImageLayout  newLayout,
VkPipelineStageFlags  srcStage,
VkPipelineStageFlags  dstStage,
VkAccessFlags  srcAccess,
VkAccessFlags  dstAccess 
) const
noexcept

Records a layout transition barrier on the given command buffer.

Updates the tracked layout and, if the image is wrapped by Skia, informs Skia of the new layout so both stay consistent. The device-taking variant transitions the per-device shared image instead of the allocator's.

◆ layout() [1/2]

VkImageLayout layout ( ) const
inlinenoexcept

The tracked VkImageLayout of the primary image.

◆ layout() [2/2]

VkImageLayout layout ( RVKDevice device) const
noexcept

The tracked VkImageLayout for device (primary image on the allocator, else the per-device cross-device import).

◆ syncLayoutFromSkia()

void syncLayoutFromSkia ( ) const
noexcept

Reconciles the tracked layout with Skia's after Skia rendered into this image.

Skia mutates the wrapped image's layout internally; call this after flushing a Skia pass so subsequent manual barriers (pixel transfers, scanout) use the correct old layout.