Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qrhimetal.mm File Reference

(f16036fc18804b19ecded11f43a154659e7f2b60)

#include "qrhimetal_p.h"
#include "qshader_p.h"
#include <QGuiApplication>
#include <QWindow>
#include <QUrl>
#include <QFile>
#include <QTemporaryFile>
#include <QFileInfo>
#include <qmath.h>
#include <QOperatingSystemVersion>
#include <QtCore/private/qcore_mac_p.h>
#include <UIKit/UIKit.h>
#include <Metal/Metal.h>
#include <QuartzCore/CAMetalLayer.h>
+ Include dependency graph for qrhimetal.mm:

Go to the source code of this file.

Classes

struct  QMetalShader
 \variable QRhiMetalCommandBufferNativeHandles::commandBuffer More...
 
struct  QRhiMetalData
 
struct  QRhiMetalData::DeferredReleaseEntry
 
struct  QRhiMetalData::OffscreenFrame
 
struct  QRhiMetalData::TextureReadback
 
struct  QRhiMetalData::BufferReadback
 
struct  QMetalBufferData
 
struct  QMetalBufferData::BufferUpdate
 
struct  QMetalRenderBufferData
 
struct  QMetalTextureData
 
struct  QMetalSamplerData
 
struct  QMetalShaderResourceBindingsData
 
struct  QMetalShaderResourceBindingsData::Stage
 
struct  QMetalShaderResourceBindingsData::Stage::Buffer
 
struct  QMetalShaderResourceBindingsData::Stage::Texture
 
struct  QMetalShaderResourceBindingsData::Stage::Sampler
 
struct  QMetalCommandBufferData
 
struct  QMetalRenderTargetData
 
struct  QMetalRenderTargetData::ColorAtt
 
struct  QMetalGraphicsPipelineData
 
struct  QMetalGraphicsPipelineData::ExtraBufferManager
 
struct  QMetalGraphicsPipelineData::Tessellation
 
struct  QMetalComputePipelineData
 
struct  QMetalSwapChainData
 
struct  QMetalPipelineCacheDataHeader
 

Macros

#define QRHI_METAL_DISABLE_BINARY_ARCHIVE
 
#define QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES
 

Enumerations

enum class  BindingType { Buffer , Texture , Sampler }
 

Functions

 Q_DECLARE_TYPEINFO (QRhiMetalData::DeferredReleaseEntry, Q_RELOCATABLE_TYPE)
 
 Q_DECLARE_TYPEINFO (QRhiMetalData::TextureReadback, Q_RELOCATABLE_TYPE)
 
template<class Int >
Int aligned (Int v, Int byteAlign)
 
static int mapBinding (int binding, int stageIndex, const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[], BindingType type)
 
static void bindStageBuffers (QMetalCommandBuffer *cbD, int stage, const QRhiBatchedBindings< id< MTLBuffer > >::Batch &bufferBatch, const QRhiBatchedBindings< NSUInteger >::Batch &offsetBatch)
 
static void bindStageTextures (QMetalCommandBuffer *cbD, int stage, const QRhiBatchedBindings< id< MTLTexture > >::Batch &textureBatch)
 
static void bindStageSamplers (QMetalCommandBuffer *cbD, int encoderStage, const QRhiBatchedBindings< id< MTLSamplerState > >::Batch &samplerBatch)
 
static void rebindShaderResources (QMetalCommandBuffer *cbD, int resourceStage, int encoderStage, const QMetalShaderResourceBindingsData *customBindingState=nullptr)
 
static QRhiShaderResourceBinding::StageFlag toRhiSrbStage (int stage)
 
static id< MTLComputeCommandEncoder > tessellationComputeEncoder (QMetalCommandBuffer *cbD)
 
static void endTessellationComputeEncoding (QMetalCommandBuffer *cbD)
 
static void qrhimtl_releaseBuffer (const QRhiMetalData::DeferredReleaseEntry &e)
 
static void qrhimtl_releaseRenderBuffer (const QRhiMetalData::DeferredReleaseEntry &e)
 
static void qrhimtl_releaseTexture (const QRhiMetalData::DeferredReleaseEntry &e)
 
static void qrhimtl_releaseSampler (const QRhiMetalData::DeferredReleaseEntry &e)
 
static MTLPixelFormat toMetalTextureFormat (QRhiTexture::Format format, QRhiTexture::Flags flags, const QRhiMetal *d)
 
static MTLSamplerMinMagFilter toMetalFilter (QRhiSampler::Filter f)
 
static MTLSamplerMipFilter toMetalMipmapMode (QRhiSampler::Filter f)
 
static MTLSamplerAddressMode toMetalAddressMode (QRhiSampler::AddressMode m)
 
static MTLCompareFunction toMetalTextureCompareFunction (QRhiSampler::CompareOp op)
 
static MTLVertexFormat toMetalAttributeFormat (QRhiVertexInputAttribute::Format format)
 
static MTLBlendFactor toMetalBlendFactor (QRhiGraphicsPipeline::BlendFactor f)
 
static MTLBlendOperation toMetalBlendOp (QRhiGraphicsPipeline::BlendOp op)
 
static uint toMetalColorWriteMask (QRhiGraphicsPipeline::ColorMask c)
 
static MTLCompareFunction toMetalCompareOp (QRhiGraphicsPipeline::CompareOp op)
 
static MTLStencilOperation toMetalStencilOp (QRhiGraphicsPipeline::StencilOp op)
 
static MTLPrimitiveType toMetalPrimitiveType (QRhiGraphicsPipeline::Topology t)
 
static MTLPrimitiveTopologyClass toMetalPrimitiveTopologyClass (QRhiGraphicsPipeline::Topology t)
 
static MTLCullMode toMetalCullMode (QRhiGraphicsPipeline::CullMode c)
 
static MTLTriangleFillMode toMetalTriangleFillMode (QRhiGraphicsPipeline::PolygonMode mode)
 
static MTLWinding toMetalTessellationWindingOrder (QShaderDescription::TessellationWindingOrder w)
 
static MTLTessellationPartitionMode toMetalTessellationPartitionMode (QShaderDescription::TessellationPartitioning p)
 
static MTLLanguageVersion toMetalLanguageVersion (const QShaderVersion &version)
 
static bool indexTaken (quint32 index, quint64 indices)
 
static void takeIndex (quint32 index, quint64 &indices)
 
static int nextAttributeIndex (quint64 indices)
 
static int aligned (quint32 offset, quint32 alignment)
 
template<typename T >
static void addUnusedVertexAttribute (const T &variable, QRhiMetal *rhiD, quint32 &offset, quint32 &vertexAlignment)
 
template<typename T >
static void addVertexAttribute (const T &variable, int binding, QRhiMetal *rhiD, int &index, quint32 &offset, MTLVertexAttributeDescriptorArray *attributes, quint64 &indices, quint32 &vertexAlignment)
 
static bool matches (const QList< QShaderDescription::BlockVariable > &a, const QList< QShaderDescription::BlockVariable > &b)
 
static bool matches (const QShaderDescription::InOutVariable &a, const QShaderDescription::InOutVariable &b)
 
static CAMetalLayer * layerForWindow (QWindow *window)
 

Macro Definition Documentation

◆ QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES

#define QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES

Definition at line 54 of file qrhimetal.mm.

◆ QRHI_METAL_DISABLE_BINARY_ARCHIVE

#define QRHI_METAL_DISABLE_BINARY_ARCHIVE

Definition at line 49 of file qrhimetal.mm.

Enumeration Type Documentation

◆ BindingType

enum class BindingType
strong
Enumerator
Buffer 
Texture 
Sampler 

Definition at line 1115 of file qrhimetal.mm.

Function Documentation

◆ addUnusedVertexAttribute()

template<typename T >
static void addUnusedVertexAttribute ( const T & variable,
QRhiMetal * rhiD,
quint32 & offset,
quint32 & vertexAlignment )
static

Definition at line 5235 of file qrhimetal.mm.

References addUnusedVertexAttribute(), aligned(), alignment, elements, and QShaderDescription::Struct.

Referenced by addUnusedVertexAttribute(), and QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

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

◆ addVertexAttribute()

template<typename T >
static void addVertexAttribute ( const T & variable,
int binding,
QRhiMetal * rhiD,
int & index,
quint32 & offset,
MTLVertexAttributeDescriptorArray * attributes,
quint64 & indices,
quint32 & vertexAlignment )
static

Definition at line 5265 of file qrhimetal.mm.

References addVertexAttribute(), aligned(), alignment, elements, indexTaken(), nextAttributeIndex(), Q_ASSERT, QShaderDescription::Struct, takeIndex(), and toMetalAttributeFormat().

Referenced by addVertexAttribute(), and QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

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

◆ aligned() [1/2]

template<class Int >
Int aligned ( Int v,
Int byteAlign )
inline

Definition at line 497 of file qrhimetal.mm.

Referenced by addUnusedVertexAttribute(), addVertexAttribute(), and QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

+ Here is the caller graph for this function:

◆ aligned() [2/2]

static int aligned ( quint32 offset,
quint32 alignment )
inlinestatic

Definition at line 5229 of file qrhimetal.mm.

References alignment.

◆ bindStageBuffers()

static void bindStageBuffers ( QMetalCommandBuffer * cbD,
int stage,
const QRhiBatchedBindings< id< MTLBuffer > >::Batch & bufferBatch,
const QRhiBatchedBindings< NSUInteger >::Batch & offsetBatch )
inlinestatic

◆ bindStageSamplers()

static void bindStageSamplers ( QMetalCommandBuffer * cbD,
int encoderStage,
const QRhiBatchedBindings< id< MTLSamplerState > >::Batch & samplerBatch )
inlinestatic

◆ bindStageTextures()

static void bindStageTextures ( QMetalCommandBuffer * cbD,
int stage,
const QRhiBatchedBindings< id< MTLTexture > >::Batch & textureBatch )
inlinestatic

◆ endTessellationComputeEncoding()

static void endTessellationComputeEncoding ( QMetalCommandBuffer * cbD)
static

Definition at line 1930 of file qrhimetal.mm.

References QMetalCommandBufferData::cb, QMetalCommandBufferData::currentPassRpDesc, QMetalCommandBufferData::currentRenderPassEncoder, QMetalCommandBuffer::currentTarget, QMetalCommandBuffer::d, i, Q_ASSERT, QRHI_RES, QMetalCommandBuffer::resetPerPassCachedState(), QRhiResource::resourceType(), QRhiResource::SwapChainRenderTarget, QMetalCommandBufferData::tessellationComputeEncoder, and QRhiResource::TextureRenderTarget.

Referenced by QRhiMetal::tessellatedDraw().

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

◆ indexTaken()

static bool indexTaken ( quint32 index,
quint64 indices )
inlinestatic

Definition at line 5203 of file qrhimetal.mm.

Referenced by addVertexAttribute(), and nextAttributeIndex().

+ Here is the caller graph for this function:

◆ layerForWindow()

static CAMetalLayer * layerForWindow ( QWindow * window)
inlinestatic

Definition at line 6203 of file qrhimetal.mm.

References Q_ASSERT, view, and window().

Referenced by QRhiMetal::updateSwapChainProxyData().

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

◆ mapBinding()

static int mapBinding ( int binding,
int stageIndex,
const QShader::NativeResourceBindingMap * nativeResourceBindingMaps[],
BindingType type )
inlinestatic

Definition at line 1121 of file qrhimetal.mm.

References QMap< Key, T >::cend(), QMap< Key, T >::constFind(), QMap< Key, T >::isEmpty(), it, map, and Sampler.

+ Here is the call graph for this function:

◆ matches() [1/2]

static bool matches ( const QList< QShaderDescription::BlockVariable > & a,
const QList< QShaderDescription::BlockVariable > & b )
inlinestatic

Definition at line 5306 of file qrhimetal.mm.

References i, match(), and matches().

Referenced by matches(), matches(), and QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

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

◆ matches() [2/2]

static bool matches ( const QShaderDescription::InOutVariable & a,
const QShaderDescription::InOutVariable & b )
inlinestatic

Definition at line 5321 of file qrhimetal.mm.

References matches().

+ Here is the call graph for this function:

◆ nextAttributeIndex()

static int nextAttributeIndex ( quint64 indices)
inlinestatic

Definition at line 5213 of file qrhimetal.mm.

References indexTaken().

Referenced by addVertexAttribute(), and QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

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

◆ Q_DECLARE_TYPEINFO() [1/2]

◆ Q_DECLARE_TYPEINFO() [2/2]

◆ qrhimtl_releaseBuffer()

static void qrhimtl_releaseBuffer ( const QRhiMetalData::DeferredReleaseEntry & e)
static

Definition at line 3124 of file qrhimetal.mm.

References QRhiMetalData::DeferredReleaseEntry::buffer, i, QMTL_FRAMES_IN_FLIGHT, and release().

Referenced by QRhiMetal::executeDeferredReleases().

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

◆ qrhimtl_releaseRenderBuffer()

static void qrhimtl_releaseRenderBuffer ( const QRhiMetalData::DeferredReleaseEntry & e)
static

Definition at line 3130 of file qrhimetal.mm.

References release(), and QRhiMetalData::DeferredReleaseEntry::renderbuffer.

Referenced by QRhiMetal::executeDeferredReleases().

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

◆ qrhimtl_releaseSampler()

static void qrhimtl_releaseSampler ( const QRhiMetalData::DeferredReleaseEntry & e)
static

Definition at line 3144 of file qrhimetal.mm.

References release(), and QRhiMetalData::DeferredReleaseEntry::sampler.

Referenced by QRhiMetal::executeDeferredReleases().

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

◆ qrhimtl_releaseTexture()

static void qrhimtl_releaseTexture ( const QRhiMetalData::DeferredReleaseEntry & e)
static

Definition at line 3135 of file qrhimetal.mm.

References i, QRhi::MAX_MIP_LEVELS, QMTL_FRAMES_IN_FLIGHT, release(), and QRhiMetalData::DeferredReleaseEntry::texture.

Referenced by QRhiMetal::executeDeferredReleases().

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

◆ rebindShaderResources()

static void rebindShaderResources ( QMetalCommandBuffer * cbD,
int resourceStage,
int encoderStage,
const QMetalShaderResourceBindingsData * customBindingState = nullptr )
inlinestatic

Definition at line 1230 of file qrhimetal.mm.

References bindStageBuffers(), bindStageSamplers(), bindStageTextures(), QMetalCommandBufferData::currentShaderResourceBindingState, QMetalCommandBuffer::d, i, and QMetalShaderResourceBindingsData::res.

Referenced by QRhiMetal::tessellatedDraw().

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

◆ takeIndex()

static void takeIndex ( quint32 index,
quint64 & indices )
inlinestatic

Definition at line 5208 of file qrhimetal.mm.

Referenced by addVertexAttribute().

+ Here is the caller graph for this function:

◆ tessellationComputeEncoder()

static id< MTLComputeCommandEncoder > tessellationComputeEncoder ( QMetalCommandBuffer * cbD)
static

Definition at line 1917 of file qrhimetal.mm.

References QMetalCommandBufferData::cb, QMetalCommandBufferData::currentRenderPassEncoder, QMetalCommandBuffer::d, and QMetalCommandBufferData::tessellationComputeEncoder.

Referenced by QRhiMetal::tessellatedDraw().

+ Here is the caller graph for this function:

◆ toMetalAddressMode()

static MTLSamplerAddressMode toMetalAddressMode ( QRhiSampler::AddressMode m)
inlinestatic

Definition at line 4000 of file qrhimetal.mm.

References QRhiSampler::ClampToEdge, QRhiSampler::Mirror, and QRhiSampler::Repeat.

Referenced by QMetalSampler::create().

+ Here is the caller graph for this function:

◆ toMetalAttributeFormat()

◆ toMetalBlendFactor()

◆ toMetalBlendOp()

static MTLBlendOperation toMetalBlendOp ( QRhiGraphicsPipeline::BlendOp op)
inlinestatic

Definition at line 4553 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Add, QRhiGraphicsPipeline::Max, QRhiGraphicsPipeline::Min, QRhiGraphicsPipeline::ReverseSubtract, and QRhiGraphicsPipeline::Subtract.

Referenced by QMetalGraphicsPipeline::setupAttachmentsInMetalRenderPassDescriptor().

+ Here is the caller graph for this function:

◆ toMetalColorWriteMask()

static uint toMetalColorWriteMask ( QRhiGraphicsPipeline::ColorMask c)
inlinestatic

Definition at line 4572 of file qrhimetal.mm.

References QRhiGraphicsPipeline::A, QRhiGraphicsPipeline::B, QRhiGraphicsPipeline::G, and QRhiGraphicsPipeline::R.

Referenced by QMetalGraphicsPipeline::setupAttachmentsInMetalRenderPassDescriptor().

+ Here is the caller graph for this function:

◆ toMetalCompareOp()

static MTLCompareFunction toMetalCompareOp ( QRhiGraphicsPipeline::CompareOp op)
inlinestatic

Definition at line 4586 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Always, QRhiGraphicsPipeline::Equal, QRhiGraphicsPipeline::Greater, QRhiGraphicsPipeline::GreaterOrEqual, QRhiGraphicsPipeline::Less, QRhiGraphicsPipeline::LessOrEqual, QRhiGraphicsPipeline::Never, and QRhiGraphicsPipeline::NotEqual.

Referenced by QMetalGraphicsPipeline::setupMetalDepthStencilDescriptor().

+ Here is the caller graph for this function:

◆ toMetalCullMode()

static MTLCullMode toMetalCullMode ( QRhiGraphicsPipeline::CullMode c)
inlinestatic

Definition at line 4673 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Back, QRhiGraphicsPipeline::Front, and QRhiGraphicsPipeline::None.

Referenced by QMetalGraphicsPipeline::mapStates().

+ Here is the caller graph for this function:

◆ toMetalFilter()

static MTLSamplerMinMagFilter toMetalFilter ( QRhiSampler::Filter f)
inlinestatic

Definition at line 3972 of file qrhimetal.mm.

References QRhiSampler::Linear, and QRhiSampler::Nearest.

Referenced by QMetalSampler::create().

+ Here is the caller graph for this function:

◆ toMetalLanguageVersion()

static MTLLanguageVersion toMetalLanguageVersion ( const QShaderVersion & version)
inlinestatic

Definition at line 4729 of file qrhimetal.mm.

References QShaderVersion::version().

Referenced by QRhiMetalData::createMetalLib().

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

◆ toMetalMipmapMode()

static MTLSamplerMipFilter toMetalMipmapMode ( QRhiSampler::Filter f)
inlinestatic

Definition at line 3985 of file qrhimetal.mm.

References QRhiSampler::Linear, QRhiSampler::Nearest, and QRhiSampler::None.

Referenced by QMetalSampler::create().

+ Here is the caller graph for this function:

◆ toMetalPrimitiveTopologyClass()

static MTLPrimitiveTopologyClass toMetalPrimitiveTopologyClass ( QRhiGraphicsPipeline::Topology t)
inlinestatic

Definition at line 4655 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Lines, QRhiGraphicsPipeline::LineStrip, QRhiGraphicsPipeline::Points, QRhiGraphicsPipeline::TriangleFan, QRhiGraphicsPipeline::Triangles, and QRhiGraphicsPipeline::TriangleStrip.

Referenced by QMetalGraphicsPipeline::createVertexFragmentPipeline().

+ Here is the caller graph for this function:

◆ toMetalPrimitiveType()

static MTLPrimitiveType toMetalPrimitiveType ( QRhiGraphicsPipeline::Topology t)
inlinestatic

Definition at line 4636 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Lines, QRhiGraphicsPipeline::LineStrip, QRhiGraphicsPipeline::Points, QRhiGraphicsPipeline::Triangles, and QRhiGraphicsPipeline::TriangleStrip.

Referenced by QMetalGraphicsPipeline::createVertexFragmentPipeline().

+ Here is the caller graph for this function:

◆ toMetalStencilOp()

static MTLStencilOperation toMetalStencilOp ( QRhiGraphicsPipeline::StencilOp op)
inlinestatic

◆ toMetalTessellationPartitionMode()

static MTLTessellationPartitionMode toMetalTessellationPartitionMode ( QShaderDescription::TessellationPartitioning p)
inlinestatic

Definition at line 4714 of file qrhimetal.mm.

References QShaderDescription::EqualTessellationPartitioning, QShaderDescription::FractionalEvenTessellationPartitioning, and QShaderDescription::FractionalOddTessellationPartitioning.

Referenced by QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

+ Here is the caller graph for this function:

◆ toMetalTessellationWindingOrder()

static MTLWinding toMetalTessellationWindingOrder ( QShaderDescription::TessellationWindingOrder w)
inlinestatic

Definition at line 4701 of file qrhimetal.mm.

References QShaderDescription::CcwTessellationWindingOrder, and QShaderDescription::CwTessellationWindingOrder.

Referenced by QMetalGraphicsPipelineData::Tessellation::teseFragRenderPipeline().

+ Here is the caller graph for this function:

◆ toMetalTextureCompareFunction()

static MTLCompareFunction toMetalTextureCompareFunction ( QRhiSampler::CompareOp op)
inlinestatic

Definition at line 4015 of file qrhimetal.mm.

References QRhiSampler::Always, QRhiSampler::Equal, QRhiSampler::Greater, QRhiSampler::GreaterOrEqual, QRhiSampler::Less, QRhiSampler::LessOrEqual, QRhiSampler::Never, and QRhiSampler::NotEqual.

Referenced by QMetalSampler::create().

+ Here is the caller graph for this function:

◆ toMetalTextureFormat()

◆ toMetalTriangleFillMode()

static MTLTriangleFillMode toMetalTriangleFillMode ( QRhiGraphicsPipeline::PolygonMode mode)
inlinestatic

Definition at line 4688 of file qrhimetal.mm.

References QRhiGraphicsPipeline::Fill, and QRhiGraphicsPipeline::Line.

Referenced by QMetalGraphicsPipeline::mapStates().

+ Here is the caller graph for this function:

◆ toRhiSrbStage()