Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QVkTexture Struct Reference

#include <qrhivulkan_p.h>

Inheritance diagram for QVkTexture:
Collaboration diagram for QVkTexture:

Classes

struct  UsageState

Public Member Functions

 QVkTexture (QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
 ~QVkTexture ()
void destroy () override
 Releases (or requests deferred releasing of) the underlying native graphics resources.
bool create () override
 Creates the corresponding native graphics resources.
bool createFrom (NativeTexture src) override
 Similar to create(), except that no new native textures are created.
NativeTexture nativeTexture () override
void setNativeLayout (int layout) override
 With some graphics APIs, such as Vulkan, integrating custom rendering code that uses the graphics API directly needs special care when it comes to image layouts.
bool prepareCreate (QSize *adjustedSize=nullptr)
bool finishCreate ()
VkImageView perLevelImageViewForLoadStore (int level)
Public Member Functions inherited from QRhiTexture
QRhiResource::Type resourceType () const override
Format format () const
void setFormat (Format fmt)
 Sets the requested texture format to fmt.
QSize pixelSize () const
void setPixelSize (const QSize &sz)
 Sets the texture size, specified in pixels, to sz.
int depth () const
void setDepth (int depth)
 Sets the depth for a 3D texture.
int arraySize () const
void setArraySize (int arraySize)
 Sets the texture arraySize.
int arrayRangeStart () const
int arrayRangeLength () const
void setArrayRange (int startIndex, int count)
 Normally all array layers are exposed and it is up to the shader to select the layer via the third coordinate passed to the {texture()} GLSL function when sampling the sampler2DArray.
Flags flags () const
void setFlags (Flags f)
 Sets the texture flags to f.
int sampleCount () const
void setSampleCount (int s)
 Sets the sample count to s.
ViewFormat readViewFormat () const
 \variable QRhiTexture::ViewFormat::format
void setReadViewFormat (const ViewFormat &fmt)
ViewFormat writeViewFormat () const
void setWriteViewFormat (const ViewFormat &fmt)
Public Member Functions inherited from QRhiResource
virtual ~QRhiResource ()
 Destructor.
void deleteLater ()
 When called without a frame being recorded, this function is equivalent to deleting the object.
QByteArray name () const
void setName (const QByteArray &name)
 Sets a name for the object.
quint64 globalResourceId () const
QRhirhi () const

Public Attributes

VkImage image = VK_NULL_HANDLE
VkImageView imageView = VK_NULL_HANDLE
QVkAlloc imageAlloc = nullptr
VkBuffer stagingBuffers [QVK_FRAMES_IN_FLIGHT]
QVkAlloc stagingAllocations [QVK_FRAMES_IN_FLIGHT]
VkImageView perLevelImageViews [QRhi::MAX_MIP_LEVELS]
bool owns = true
UsageState usageState
VkFormat vkformat
uint mipLevelCount = 0
VkSampleCountFlagBits samples
VkFormat viewFormat
VkFormat viewFormatForSampling
int lastActiveFrameSlot = -1
uint generation = 0

Friends

class QRhiVulkan

Additional Inherited Members

Public Types inherited from QRhiTexture
enum  Flag {
  RenderTarget = 1 << 0 , CubeMap = 1 << 2 , MipMapped = 1 << 3 , sRGB = 1 << 4 ,
  UsedAsTransferSource = 1 << 5 , UsedWithGenerateMips = 1 << 6 , UsedWithLoadStore = 1 << 7 , UsedAsCompressedAtlas = 1 << 8 ,
  ExternalOES = 1 << 9 , ThreeDimensional = 1 << 10 , TextureRectangleGL = 1 << 11 , TextureArray = 1 << 12 ,
  OneDimensional = 1 << 13 , UsedAsShadingRateMap = 1 << 14
}
 Flag values to specify how the texture is going to be used. More...
enum  Format {
  UnknownFormat , RGBA8 , BGRA8 , R8 ,
  RG8 , R16 , RG16 , RED_OR_ALPHA8 ,
  RGBA16F , RGBA32F , R16F , R32F ,
  RGB10A2 , R8SI , R32SI , RG32SI ,
  RGBA32SI , R8UI , R32UI , RG32UI ,
  RGBA32UI , D16 , D24 , D24S8 ,
  D32F , D32FS8 , BC1 , BC2 ,
  BC3 , BC4 , BC5 , BC6H ,
  BC7 , ETC2_RGB8 , ETC2_RGB8A1 , ETC2_RGBA8 ,
  ASTC_4x4 , ASTC_5x4 , ASTC_5x5 , ASTC_6x5 ,
  ASTC_6x6 , ASTC_8x5 , ASTC_8x6 , ASTC_8x8 ,
  ASTC_10x5 , ASTC_10x6 , ASTC_10x8 , ASTC_10x10 ,
  ASTC_12x10 , ASTC_12x12
}
 Specifies the texture format. More...
Public Types inherited from QRhiResource
enum  Type {
  Buffer , Texture , Sampler , RenderBuffer ,
  RenderPassDescriptor , SwapChainRenderTarget , TextureRenderTarget , ShaderResourceBindings ,
  GraphicsPipeline , SwapChain , ComputePipeline , CommandBuffer ,
  ShadingRateMap
}
 Specifies type of the resource. More...
Protected Member Functions inherited from QRhiTexture
 QRhiTexture (QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, int depth_, int arraySize_, int sampleCount_, Flags flags_)
 \variable QRhiTexture::NativeTexture::object
Protected Member Functions inherited from QRhiResource
 QRhiResource (QRhiImplementation *rhi)
Protected Attributes inherited from QRhiTexture
Format m_format
QSize m_pixelSize
int m_depth
int m_arraySize
int m_sampleCount
Flags m_flags
int m_arrayRangeStart = -1
int m_arrayRangeLength = -1
ViewFormat m_readViewFormat = { UnknownFormat, false }
ViewFormat m_writeViewFormat = { UnknownFormat, false }
Protected Attributes inherited from QRhiResource
QRhiImplementationm_rhi = nullptr
quint64 m_id
QByteArray m_objectName

Detailed Description

Definition at line 97 of file qrhivulkan_p.h.

Constructor & Destructor Documentation

◆ QVkTexture()

QVkTexture::QVkTexture ( QRhiImplementation * rhi,
Format format,
const QSize & pixelSize,
int depth,
int arraySize,
int sampleCount,
Flags flags )

Definition at line 7027 of file qrhivulkan.cpp.

References QVkTexture(), QVK_FRAMES_IN_FLIGHT, and stagingAllocations.

Referenced by QVkTexture().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~QVkTexture()

QVkTexture::~QVkTexture ( )

Definition at line 7039 of file qrhivulkan.cpp.

References destroy().

Here is the call graph for this function:

Member Function Documentation

◆ create()

bool QVkTexture::create ( )
overridevirtual

Creates the corresponding native graphics resources.

If there are already resources present due to an earlier create() with no corresponding destroy(), then destroy() is called implicitly first.

Returns
true when successful, false when a graphics operation failed. Regardless of the return value, calling destroy() is always safe.

Implements QRhiTexture.

Definition at line 7221 of file qrhivulkan.cpp.

References finishCreate(), imageAlloc, and owns.

Referenced by QVkRenderBuffer::create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createFrom()

bool QVkTexture::createFrom ( QRhiTexture::NativeTexture src)
overridevirtual

Similar to create(), except that no new native textures are created.

Instead, the native texture resources specified by src is used.

This allows importing an existing native texture object (which must belong to the same device or sharing context, depending on the graphics API) from an external graphics engine.

Returns
true if the specified existing native texture object has been successfully wrapped as a non-owning QRhiTexture.
Note
format(), pixelSize(), sampleCount(), and flags() must still be set correctly. Passing incorrect sizes and other values to QRhi::newTexture() and then following it with a createFrom() expecting that the native texture object alone is sufficient to deduce such values is wrong and will lead to problems.
QRhiTexture does not take ownership of the texture object. destroy() does not free the object or any associated memory.

The opposite of this operation, exposing a QRhiTexture-created native texture object to a foreign engine, is possible via nativeTexture().

Note
When importing a 3D texture, or a texture array object, or, with OpenGL ES, an external texture, it is then especially important to set the corresponding flags (ThreeDimensional, TextureArray, ExternalOES) via setFlags() before calling this function.

Reimplemented from QRhiTexture.

Definition at line 7314 of file qrhivulkan.cpp.

References finishCreate(), and owns.

Here is the call graph for this function:

◆ destroy()

void QVkTexture::destroy ( )
overridevirtual

Releases (or requests deferred releasing of) the underlying native graphics resources.

Safe to call multiple times, subsequent invocations will be a no-op then.

Once destroy() is called, the QRhiResource instance can be reused, by calling create() again. That will then result in creating new native graphics resources underneath.

Note
Resources referenced by commands for the current frame should not be released until the frame is submitted by QRhi::endFrame().

The QRhiResource destructor also performs the same task, so calling this function is not necessary before deleting a QRhiResource.

See also
deleteLater()

Implements QRhiResource.

Definition at line 7044 of file qrhivulkan.cpp.

References imageAlloc, QRhiVulkan::DeferredReleaseEntry::lastActiveFrameSlot, lastActiveFrameSlot, owns, QVK_FRAMES_IN_FLIGHT, stagingAllocations, QRhiVulkan::DeferredReleaseEntry::Texture, and QRhiVulkan::DeferredReleaseEntry::type.

Referenced by ~QVkTexture(), QVkRenderBuffer::destroy(), and prepareCreate().

Here is the caller graph for this function:

◆ finishCreate()

bool QVkTexture::finishCreate ( )

Definition at line 7174 of file qrhivulkan.cpp.

References lastActiveFrameSlot.

Referenced by create(), and createFrom().

Here is the caller graph for this function:

◆ nativeTexture()

QRhiTexture::NativeTexture QVkTexture::nativeTexture ( )
overridevirtual
Returns
the underlying native resources for this texture. The returned value will be empty if exposing the underlying native resources is not supported by the backend.
See also
createFrom()

Reimplemented from QRhiTexture.

Definition at line 7336 of file qrhivulkan.cpp.

◆ perLevelImageViewForLoadStore()

VkImageView QVkTexture::perLevelImageViewForLoadStore ( int level)

Definition at line 7346 of file qrhivulkan.cpp.

References QRhiVulkan::df.

◆ prepareCreate()

bool QVkTexture::prepareCreate ( QSize * adjustedSize = nullptr)

Definition at line 7081 of file qrhivulkan.cpp.

References destroy().

Here is the call graph for this function:

◆ setNativeLayout()

void QVkTexture::setNativeLayout ( int layout)
overridevirtual

With some graphics APIs, such as Vulkan, integrating custom rendering code that uses the graphics API directly needs special care when it comes to image layouts.

This function allows communicating the expected layout the image backing the QRhiTexture is in after the native rendering commands.

For example, consider rendering into a QRhiTexture's VkImage directly with Vulkan in a code block enclosed by QRhiCommandBuffer::beginExternal() and QRhiCommandBuffer::endExternal(), followed by using the image for texture sampling in a QRhi-based render pass. To avoid potentially incorrect image layout transitions, this function can be used to indicate what the image layout will be once the commands recorded in said code block complete.

Calling this function makes sense only after QRhiCommandBuffer::endExternal() and before a subsequent QRhiCommandBuffer::beginPass().

This function has no effect with QRhi backends where the underlying graphics API does not expose a concept of image layouts.

Note
With Vulkan layout is a VkImageLayout. With Direct 3D 12 layout is a value composed of the bits from D3D12_RESOURCE_STATES.

Reimplemented from QRhiTexture.

Definition at line 7341 of file qrhivulkan.cpp.

◆ QRhiVulkan

friend class QRhiVulkan
friend

Definition at line 135 of file qrhivulkan_p.h.

Member Data Documentation

◆ generation

uint QVkTexture::generation = 0

Definition at line 134 of file qrhivulkan_p.h.

◆ image

VkImage QVkTexture::image = VK_NULL_HANDLE

Definition at line 112 of file qrhivulkan_p.h.

◆ imageAlloc

QVkAlloc QVkTexture::imageAlloc = nullptr

Definition at line 114 of file qrhivulkan_p.h.

Referenced by create(), and destroy().

◆ imageView

VkImageView QVkTexture::imageView = VK_NULL_HANDLE

Definition at line 113 of file qrhivulkan_p.h.

◆ lastActiveFrameSlot

int QVkTexture::lastActiveFrameSlot = -1

Definition at line 133 of file qrhivulkan_p.h.

Referenced by QVkRenderBuffer::destroy(), destroy(), and finishCreate().

◆ mipLevelCount

uint QVkTexture::mipLevelCount = 0

Definition at line 129 of file qrhivulkan_p.h.

◆ owns

bool QVkTexture::owns = true

Definition at line 118 of file qrhivulkan_p.h.

Referenced by create(), createFrom(), and destroy().

◆ perLevelImageViews

VkImageView QVkTexture::perLevelImageViews[QRhi::MAX_MIP_LEVELS]

Definition at line 117 of file qrhivulkan_p.h.

◆ samples

VkSampleCountFlagBits QVkTexture::samples

Definition at line 130 of file qrhivulkan_p.h.

◆ stagingAllocations

QVkAlloc QVkTexture::stagingAllocations[QVK_FRAMES_IN_FLIGHT]

Definition at line 116 of file qrhivulkan_p.h.

Referenced by QVkTexture(), and destroy().

◆ stagingBuffers

VkBuffer QVkTexture::stagingBuffers[QVK_FRAMES_IN_FLIGHT]

Definition at line 115 of file qrhivulkan_p.h.

◆ usageState

UsageState QVkTexture::usageState

Definition at line 127 of file qrhivulkan_p.h.

◆ viewFormat

VkFormat QVkTexture::viewFormat

Definition at line 131 of file qrhivulkan_p.h.

◆ viewFormatForSampling

VkFormat QVkTexture::viewFormatForSampling

Definition at line 132 of file qrhivulkan_p.h.

◆ vkformat

VkFormat QVkTexture::vkformat

Definition at line 128 of file qrhivulkan_p.h.


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