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
qrhimetal_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QRHIMETAL_P_H
5#define QRHIMETAL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qrhi_p.h"
19#include <QWindow>
20
22
23static const int QMTL_FRAMES_IN_FLIGHT = 2;
24
25// have to hide the ObjC stuff, this header cannot contain MTL* at all
26struct QMetalBufferData;
27
28struct QMetalBuffer : public QRhiBuffer
29{
30 QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
31 ~QMetalBuffer();
32 void destroy() override;
33 bool create() override;
37
41 friend class QRhiMetal;
43
44 static constexpr int WorkBufPoolUsage = 1 << 8;
46};
47
49
51{
52 QMetalRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
53 int sampleCount, QRhiRenderBuffer::Flags flags,
54 QRhiTexture::Format backingFormatHint);
56 void destroy() override;
57 bool create() override;
58 QRhiTexture::Format backingFormat() const override;
59
61 int samples = 1;
64 friend class QRhiMetal;
65};
66
68
70{
71 QMetalTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth,
72 int arraySize, int sampleCount, Flags flags);
74 void destroy() override;
75 bool create() override;
76 bool createFrom(NativeTexture src) override;
78
79 bool prepareCreate(QSize *adjustedSize = nullptr);
80
83 int samples = 1;
86 friend class QRhiMetal;
88 friend struct QMetalTextureData;
89};
90
92
94{
95 QMetalSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
96 AddressMode u, AddressMode v, AddressMode w);
98 void destroy() override;
99 bool create() override;
100
104 friend class QRhiMetal;
106};
107
109
111{
112 QMetalShadingRateMap(QRhiImplementation *rhi);
114 void destroy() override;
115 bool createFrom(NativeShadingRateMap src) override;
116
120 friend class QRhiMetal;
121};
122
124{
125 QMetalRenderPassDescriptor(QRhiImplementation *rhi);
127 void destroy() override;
128 bool isCompatible(const QRhiRenderPassDescriptor *other) const override;
130 QVector<quint32> serializedFormat() const override;
131
133
134 // there is no MTLRenderPassDescriptor here as one will be created for each pass in beginPass()
135
136 // but the things needed for the render pipeline descriptor have to be provided
137 static const int MAX_COLOR_ATTACHMENTS = 8;
139 bool hasDepthStencil = false;
142 bool hasShadingRateMap = false;
144};
145
147
149{
150 QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
152 void destroy() override;
153
154 QSize pixelSize() const override;
155 float devicePixelRatio() const override;
156 int sampleCount() const override;
157
159};
160
162{
163 QMetalTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags);
165 void destroy() override;
166
167 QSize pixelSize() const override;
168 float devicePixelRatio() const override;
169 int sampleCount() const override;
170
172 bool create() override;
173
175 friend class QRhiMetal;
176};
177
180
228
231
233{
234 QMetalGraphicsPipeline(QRhiImplementation *rhi);
236 void destroy() override;
237 bool create() override;
238
241 void setupMetalDepthStencilDescriptor(void *metalDsDesc);
242 void mapStates();
244 bool createTessellationPipelines(const QShader &tessVert, const QShader &tesc, const QShader &tese, const QShader &tessFrag);
245
249 friend class QRhiMetal;
250};
251
253
255{
256 QMetalComputePipeline(QRhiImplementation *rhi);
258 void destroy() override;
259 bool create() override;
260
264 friend class QRhiMetal;
265};
266
268struct QMetalSwapChain;
269
310
312
314{
315 QMetalSwapChain(QRhiImplementation *rhi);
317 void destroy() override;
318
319 QRhiCommandBuffer *currentFrameCommandBuffer() override;
321 QSize surfacePixelSize() override;
322 bool isFormatSupported(Format f) override;
323
325
327
328 virtual QRhiSwapChainHdrInfo hdrInfo() override;
329
330 void chooseFormats();
331 void waitUntilCompleted(int slot);
332
333 QWindow *window = nullptr;
335 int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
336 int frameCount = 0;
337 int samples = 1;
342};
343
344struct QRhiMetalData;
345
347{
348public:
349 QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice = nullptr);
350 ~QRhiMetal();
351
352 static bool probe(QRhiMetalInitParams *params);
353 static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window);
354
355 bool create(QRhi::Flags flags) override;
356 void destroy() override;
357
361 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
362 QRhiBuffer::UsageFlags usage,
363 quint32 size) override;
364 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
365 const QSize &pixelSize,
366 int sampleCount,
367 QRhiRenderBuffer::Flags flags,
368 QRhiTexture::Format backingFormatHint) override;
369 QRhiTexture *createTexture(QRhiTexture::Format format,
370 const QSize &pixelSize,
371 int depth,
372 int arraySize,
373 int sampleCount,
374 QRhiTexture::Flags flags) override;
375 QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
376 QRhiSampler::Filter minFilter,
377 QRhiSampler::Filter mipmapMode,
378 QRhiSampler:: AddressMode u,
379 QRhiSampler::AddressMode v,
380 QRhiSampler::AddressMode w) override;
381
382 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
383 QRhiTextureRenderTarget::Flags flags) override;
384
385 QRhiShadingRateMap *createShadingRateMap() override;
386
387 QRhiSwapChain *createSwapChain() override;
388 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
389 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
390 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override;
391 QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override;
392 QRhi::FrameOpResult finish() override;
393
394 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
395
396 void beginPass(QRhiCommandBuffer *cb,
397 QRhiRenderTarget *rt,
398 const QColor &colorClearValue,
399 const QRhiDepthStencilClearValue &depthStencilClearValue,
400 QRhiResourceUpdateBatch *resourceUpdates,
401 QRhiCommandBuffer::BeginPassFlags flags) override;
402 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
403
404 void setGraphicsPipeline(QRhiCommandBuffer *cb,
405 QRhiGraphicsPipeline *ps) override;
406
407 void setShaderResources(QRhiCommandBuffer *cb,
408 QRhiShaderResourceBindings *srb,
409 int dynamicOffsetCount,
410 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
411
412 void setVertexInput(QRhiCommandBuffer *cb,
413 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
414 QRhiBuffer *indexBuf, quint32 indexOffset,
415 QRhiCommandBuffer::IndexFormat indexFormat) override;
416
417 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
418 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
419 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
420 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
421 void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override;
422
423 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
424 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
425
426 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
427 quint32 instanceCount, quint32 firstIndex,
428 qint32 vertexOffset, quint32 firstInstance) override;
429
430 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
431 void debugMarkEnd(QRhiCommandBuffer *cb) override;
432 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
433
434 void beginComputePass(QRhiCommandBuffer *cb,
435 QRhiResourceUpdateBatch *resourceUpdates,
436 QRhiCommandBuffer::BeginPassFlags flags) override;
437 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
438 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
439 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
440
441 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
442 void beginExternal(QRhiCommandBuffer *cb) override;
443 void endExternal(QRhiCommandBuffer *cb) override;
444 double lastCompletedGpuTime(QRhiCommandBuffer *cb) override;
445
446 QList<int> supportedSampleCounts() const override;
447 QList<QSize> supportedShadingRates(int sampleCount) const override;
448 int ubufAlignment() const override;
449 bool isYUpInFramebuffer() const override;
450 bool isYUpInNDC() const override;
451 bool isClipDepthZeroToOne() const override;
452 QMatrix4x4 clipSpaceCorrMatrix() const override;
453 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
454 bool isFeatureSupported(QRhi::Feature feature) const override;
455 int resourceLimit(QRhi::ResourceLimit limit) const override;
456 const QRhiNativeHandles *nativeHandles() override;
457 QRhiDriverInfo driverInfo() const override;
458 QRhiStats statistics() override;
460 void setQueueSubmitParams(QRhiNativeHandles *params) override;
462 bool isDeviceLost() const override;
463
464 QByteArray pipelineCacheData() override;
465 void setPipelineCacheData(const QByteArray &data) override;
466
467 void executeDeferredReleases(bool forced = false);
468 void finishActiveReadbacks(bool forced = false);
469 qsizetype subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const;
470 void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr,
471 int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc,
472 qsizetype *curOfs);
473 void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
474 void executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot);
476 static const int SUPPORTED_STAGES = 5;
479 int dynamicOffsetCount,
480 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets,
481 bool offsetOnlyChange,
482 const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[SUPPORTED_STAGES]);
509 void tessellatedDraw(const TessDrawArgs &args);
510 void adjustForMultiViewDraw(quint32 *instanceCount, QRhiCommandBuffer *cb);
511
513 bool importedDevice = false;
514 bool importedCmdQueue = false;
521
522 struct {
523 int maxTextureSize = 4096;
526 bool isAppleGPU = false;
528 bool multiView = false;
529 bool shadingRateMap = false;
530 } caps;
531
532 QRhiMetalData *d = nullptr;
533};
534
535QT_END_NAMESPACE
536
537#endif
bool shadingRateMap
static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window)
QMetalSwapChain * currentSwapChain
bool isDeviceLost() const override
Definition qrhimetal.mm:957
QRhiMetalNativeHandles nativeHandlesStruct
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
QRhiStats statistics() override
Definition qrhimetal.mm:931
void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance) override
void executeBufferHostWritesForCurrentFrame(QMetalBuffer *bufD)
int ubufAlignment() const override
Definition qrhimetal.mm:709
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
Definition qrhimetal.mm:743
void endExternal(QRhiCommandBuffer *cb) override
QRhiMetalData * d
QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice=nullptr)
Definition qrhimetal.mm:482
void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
qsizetype subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const
void beginExternal(QRhiCommandBuffer *cb) override
quint32 osMajor
void adjustForMultiViewDraw(quint32 *instanceCount, QRhiCommandBuffer *cb)
QRhiSwapChain * createSwapChain() override
Definition qrhimetal.mm:699
QRhiGraphicsPipeline * createGraphicsPipeline() override
bool create(QRhi::Flags flags) override
Definition qrhimetal.mm:556
QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override
QRhi::Flags rhiFlags
void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override
void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override
static const int SUPPORTED_STAGES
bool multiView
void enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD, QMetalCommandBuffer *cbD, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets, bool offsetOnlyChange, const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[SUPPORTED_STAGES])
QRhiRenderBuffer * createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint) override
void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps) override
bool isYUpInNDC() const override
Definition qrhimetal.mm:719
int resourceLimit(QRhi::ResourceLimit limit) const override
Definition qrhimetal.mm:882
QRhiShaderResourceBindings * createShaderResourceBindings() override
void executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot)
QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override
QMatrix4x4 clipSpaceCorrMatrix() const override
Definition qrhimetal.mm:729
int maxTextureSize
void setQueueSubmitParams(QRhiNativeHandles *params) override
Definition qrhimetal.mm:944
const QRhiNativeHandles * nativeHandles() override
Definition qrhimetal.mm:921
void executeDeferredReleases(bool forced=false)
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiComputePipeline * createComputePipeline() override
bool isClipDepthZeroToOne() const override
Definition qrhimetal.mm:724
QVector< int > supportedSampleCounts
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
int maxThreadGroupSize
bool isYUpInFramebuffer() const override
Definition qrhimetal.mm:714
QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override
quint32 osMinor
const QRhiNativeHandles * nativeHandles(QRhiCommandBuffer *cb) override
void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
void setPipelineCacheData(const QByteArray &data) override
bool isAppleGPU
QByteArray pipelineCacheData() override
Definition qrhimetal.mm:972
void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override
void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override
void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat) override
void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override
bool importedDevice
void tessellatedDraw(const TessDrawArgs &args)
void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override
void debugMarkEnd(QRhiCommandBuffer *cb) override
QRhi::FrameOpResult finish() override
QSet< QMetalSwapChain * > swapchains
bool baseVertexAndInstance
QRhiShadingRateMap * createShadingRateMap() override
bool importedCmdQueue
QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override
bool makeThreadLocalNativeContextCurrent() override
Definition qrhimetal.mm:938
QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags) override
QRhiBuffer * createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size) override
Definition qrhimetal.mm:704
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
void releaseCachedResources() override
Definition qrhimetal.mm:949
QRhiDriverInfo driverInfoStruct
void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override
void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override
void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiDriverInfo driverInfo() const override
Definition qrhimetal.mm:926
double lastCompletedGpuTime(QRhiCommandBuffer *cb) override
QList< int > supportedSampleCounts() const override
void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override
void finishActiveReadbacks(bool forced=false)
static bool probe(QRhiMetalInitParams *params)
Definition qrhimetal.mm:513
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
bool isFeatureSupported(QRhi::Feature feature) const override
Definition qrhimetal.mm:776
void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc, qsizetype *curOfs)
void destroy() override
Definition qrhimetal.mm:664
QList< QSize > supportedShadingRates(int sampleCount) const override
Definition qrhimetal.mm:693
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
Definition qrhi_p.h:590
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:322
\inmodule QtGui
Definition qshader.h:81
#define __has_feature(x)
@ UnBounded
Definition qrhi_p.h:278
@ Bounded
Definition qrhi_p.h:279
#define QRHI_RES_RHI(t)
Definition qrhi_p.h:30
#define QRHI_RES(t, x)
Definition qrhi_p.h:29
Int aligned(Int v, Int byteAlign)
\variable QRhiVulkanQueueSubmitParams::waitSemaphoreCount
static id< MTLComputeCommandEncoder > tessellationComputeEncoder(QMetalCommandBuffer *cbD)
static MTLStencilOperation toMetalStencilOp(QRhiGraphicsPipeline::StencilOp op)
static MTLLanguageVersion toMetalLanguageVersion(const QShaderVersion &version)
static MTLPrimitiveTopologyClass toMetalPrimitiveTopologyClass(QRhiGraphicsPipeline::Topology t)
static CAMetalLayer * layerForWindow(QWindow *window)
static void addVertexAttribute(const T &variable, int binding, QRhiMetal *rhiD, int &index, quint32 &offset, MTLVertexAttributeDescriptorArray *attributes, quint64 &indices, quint32 &vertexAlignment)
static void qrhimtl_releaseRenderBuffer(const QRhiMetalData::DeferredReleaseEntry &e)
static bool matches(const QList< QShaderDescription::BlockVariable > &a, const QList< QShaderDescription::BlockVariable > &b)
Q_DECLARE_TYPEINFO(QRhiMetalData::TextureReadback, Q_RELOCATABLE_TYPE)
static MTLBlendOperation toMetalBlendOp(QRhiGraphicsPipeline::BlendOp op)
static MTLBlendFactor toMetalBlendFactor(QRhiGraphicsPipeline::BlendFactor f)
static MTLWinding toMetalTessellationWindingOrder(QShaderDescription::TessellationWindingOrder w)
static MTLPrimitiveType toMetalPrimitiveType(QRhiGraphicsPipeline::Topology t)
static MTLCompareFunction toMetalCompareOp(QRhiGraphicsPipeline::CompareOp op)
static MTLVertexFormat toMetalAttributeFormat(QRhiVertexInputAttribute::Format format)
static void endTessellationComputeEncoding(QMetalCommandBuffer *cbD)
BindingType
static MTLTriangleFillMode toMetalTriangleFillMode(QRhiGraphicsPipeline::PolygonMode mode)
static MTLSamplerMinMagFilter toMetalFilter(QRhiSampler::Filter f)
static MTLCullMode toMetalCullMode(QRhiGraphicsPipeline::CullMode c)
static void qrhimtl_releaseBuffer(const QRhiMetalData::DeferredReleaseEntry &e)
static void takeIndex(quint32 index, quint64 &indices)
static int mapBinding(int binding, int stageIndex, const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[], BindingType type)
static void rebindShaderResources(QMetalCommandBuffer *cbD, int resourceStage, int encoderStage, const QMetalShaderResourceBindingsData *customBindingState=nullptr)
static void qrhimtl_releaseSampler(const QRhiMetalData::DeferredReleaseEntry &e)
static MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QRhiTexture::Flags flags, const QRhiMetal *d)
static QRhiShaderResourceBinding::StageFlag toRhiSrbStage(int stage)
static void addUnusedVertexAttribute(const T &variable, QRhiMetal *rhiD, quint32 &offset, quint32 &vertexAlignment)
static uint toMetalColorWriteMask(QRhiGraphicsPipeline::ColorMask c)
#define QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES
Definition qrhimetal.mm:57
static MTLSamplerMipFilter toMetalMipmapMode(QRhiSampler::Filter f)
static MTLTessellationPartitionMode toMetalTessellationPartitionMode(QShaderDescription::TessellationPartitioning p)
static MTLCompareFunction toMetalTextureCompareFunction(QRhiSampler::CompareOp op)
static int aligned(quint32 offset, quint32 alignment)
Q_DECLARE_TYPEINFO(QRhiMetalData::DeferredReleaseEntry, Q_RELOCATABLE_TYPE)
static MTLSamplerAddressMode toMetalAddressMode(QRhiSampler::AddressMode m)
static void bindStageBuffers(QMetalCommandBuffer *cbD, int stage, const QRhiBatchedBindings< id< MTLBuffer > >::Batch &bufferBatch, const QRhiBatchedBindings< NSUInteger >::Batch &offsetBatch)
static void qrhimtl_releaseTexture(const QRhiMetalData::DeferredReleaseEntry &e)
static bool indexTaken(quint32 index, quint64 indices)
static void bindStageTextures(QMetalCommandBuffer *cbD, int stage, const QRhiBatchedBindings< id< MTLTexture > >::Batch &textureBatch)
#define QRHI_METAL_DISABLE_BINARY_ARCHIVE
Definition qrhimetal.mm:52
static void bindStageSamplers(QMetalCommandBuffer *cbD, int encoderStage, const QRhiBatchedBindings< id< MTLSamplerState > >::Batch &samplerBatch)
static int nextAttributeIndex(quint64 indices)
static QT_BEGIN_NAMESPACE const int QMTL_FRAMES_IN_FLIGHT
Definition qrhimetal_p.h:23
void f(int c)
[26]
QVarLengthArray< BufferUpdate, 16 > pendingUpdates[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:290
id< MTLBuffer > buf[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:285
char * beginFullDynamicBufferUpdateForCurrentFrame() override
QMetalBufferData * d
Definition qrhimetal_p.h:38
QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
static constexpr int WorkBufPoolUsage
Definition qrhimetal_p.h:44
int lastActiveFrameSlot
Definition qrhimetal_p.h:40
QRhiBuffer::NativeBuffer nativeBuffer() override
void endFullDynamicBufferUpdateForCurrentFrame() override
To be called when the entire contents of the buffer data has been updated in the memory block returne...
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool create() override
Creates the corresponding native graphics resources.
MTLRenderPassDescriptor * currentPassRpDesc
Definition qrhimetal.mm:356
id< MTLDepthStencilState > currentDepthStencilState
Definition qrhimetal.mm:360
QMetalShaderResourceBindingsData currentShaderResourceBindingState
Definition qrhimetal.mm:361
id< MTLComputeCommandEncoder > tessellationComputeEncoder
Definition qrhimetal.mm:355
QRhiBatchedBindings< id< MTLBuffer > > currentVertexInputsBuffers
Definition qrhimetal.mm:358
id< MTLRenderCommandEncoder > currentRenderPassEncoder
Definition qrhimetal.mm:353
id< MTLCommandBuffer > cb
Definition qrhimetal.mm:351
QRhiBatchedBindings< NSUInteger > currentVertexInputOffsets
Definition qrhimetal.mm:359
id< MTLComputeCommandEncoder > currentComputePassEncoder
Definition qrhimetal.mm:354
QMetalBuffer * currentIndexBuffer
std::pair< float, float > currentDepthBiasValues
QRhiCommandBuffer::IndexFormat currentIndexFormat
QRhiMetalCommandBufferNativeHandles nativeHandlesStruct
const QRhiNativeHandles * nativeHandles()
QMetalShaderResourceBindings * currentComputeSrb
QMetalComputePipeline * currentComputePipeline
QMetalShaderResourceBindings * currentGraphicsSrb
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalCommandBuffer(QRhiImplementation *rhi)
void resetPerPassCachedState()
QMetalCommandBufferData * d
QRhiRenderTarget * currentTarget
QMetalGraphicsPipeline * currentGraphicsPipeline
void resetState(double lastGpuTime=0)
id< MTLComputePipelineState > ps
Definition qrhimetal.mm:462
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:467
QMetalComputePipeline(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalComputePipelineData * d
bool create() override
QVector< QMetalBuffer * > deviceLocalWorkBuffers
Definition qrhimetal.mm:416
QMetalBuffer * acquireWorkBuffer(QRhiMetal *rhiD, quint32 size, WorkBufType type=WorkBufType::DeviceLocal)
QVector< QMetalBuffer * > hostVisibleWorkBuffers
Definition qrhimetal.mm:417
quint32 tescCompOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:435
std::array< id< MTLComputePipelineState >, 3 > vertexComputeState
Definition qrhimetal.mm:426
quint32 tescCompPatchOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:439
static int vsCompVariantToIndex(QShader::Variant vertexCompVariant)
id< MTLComputePipelineState > tescCompPipeline(QRhiMetal *rhiD)
id< MTLRenderPipelineState > teseFragRenderPipeline(QRhiMetal *rhiD, QMetalGraphicsPipeline *pipeline)
QMetalGraphicsPipelineData * q
Definition qrhimetal.mm:420
id< MTLComputePipelineState > vsCompPipeline(QRhiMetal *rhiD, QShader::Variant vertexCompVariant)
quint32 patchCountForDrawCall(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:444
quint32 vsCompOutputBufferSize(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:430
id< MTLComputePipelineState > tessControlComputeState
Definition qrhimetal.mm:427
QMetalGraphicsPipeline * q
Definition qrhimetal.mm:399
MTLPrimitiveType primitiveType
Definition qrhimetal.mm:402
id< MTLRenderPipelineState > ps
Definition qrhimetal.mm:400
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:457
void setupVertexInputDescriptor(MTLVertexDescriptor *desc)
void setupStageInputDescriptor(MTLStageInputOutputDescriptor *desc)
id< MTLDepthStencilState > ds
Definition qrhimetal.mm:401
MTLTriangleFillMode triangleFillMode
Definition qrhimetal.mm:405
QMetalGraphicsPipelineData * d
bool createVertexFragmentPipeline()
QMetalGraphicsPipeline(QRhiImplementation *rhi)
void setupAttachmentsInMetalRenderPassDescriptor(void *metalRpDesc, QMetalRenderPassDescriptor *rpD)
void makeActiveForCurrentRenderPassEncoder(QMetalCommandBuffer *cbD)
bool create() override
Creates the corresponding native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void setupMetalDepthStencilDescriptor(void *metalDsDesc)
bool createTessellationPipelines(const QShader &tessVert, const QShader &tesc, const QShader &tese, const QShader &tessFrag)
id< MTLTexture > tex
Definition qrhimetal.mm:296
MTLPixelFormat format
Definition qrhimetal.mm:295
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalRenderBufferData * d
Definition qrhimetal_p.h:60
QRhiTexture::Format backingFormat() const override
bool create() override
Creates the corresponding native graphics resources.
QMetalRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)
QMetalRenderPassDescriptor(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QVector< quint32 > serializedFormatData
QVector< quint32 > serializedFormat() const override
bool isCompatible(const QRhiRenderPassDescriptor *other) const override
int colorFormat[MAX_COLOR_ATTACHMENTS]
static const int MAX_COLOR_ATTACHMENTS
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() const override
ColorAtt colorAtt[QMetalRenderPassDescriptor::MAX_COLOR_ATTACHMENTS]
Definition qrhimetal.mm:385
id< MTLTexture > dsResolveTex
Definition qrhimetal.mm:387
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList
Definition qrhimetal.mm:394
id< MTLTexture > dsTex
Definition qrhimetal.mm:386
id< MTLSamplerState > samplerState
Definition qrhimetal.mm:315
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, AddressMode u, AddressMode v, AddressMode w)
QMetalSamplerData * d
int lastActiveFrameSlot
bool create() override
QVarLengthArray< Buffer, 8 > buffers
Definition qrhimetal.mm:338
QVarLengthArray< Sampler, 8 > samplers
Definition qrhimetal.mm:340
QRhiBatchedBindings< NSUInteger > bufferOffsetBatches
Definition qrhimetal.mm:342
QVarLengthArray< Texture, 8 > textures
Definition qrhimetal.mm:339
QRhiBatchedBindings< id< MTLSamplerState > > samplerBatches
Definition qrhimetal.mm:344
QRhiBatchedBindings< id< MTLTexture > > textureBatches
Definition qrhimetal.mm:343
QRhiBatchedBindings< id< MTLBuffer > > bufferBatches
Definition qrhimetal.mm:341
bool create() override
Creates the corresponding resource binding set.
QMetalComputePipeline * lastUsedComputePipeline
QMetalShaderResourceBindings(QRhiImplementation *rhi)
QMetalGraphicsPipeline * lastUsedGraphicsPipeline
QVarLengthArray< QRhiShaderResourceBinding, 8 > sortedBindings
QVarLengthArray< BoundResourceData, 8 > boundResourceData
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void updateResources(UpdateFlags flags) override
\variable QRhiMetalCommandBufferNativeHandles::commandBuffer
Definition qrhimetal.mm:152
void destroy()
Definition qrhimetal.mm:161
id< MTLLibrary > lib
Definition qrhimetal.mm:153
uint outputVertexCount
Definition qrhimetal.mm:156
std::array< uint, 3 > localSize
Definition qrhimetal.mm:155
QShaderDescription desc
Definition qrhimetal.mm:157
id< MTLFunction > func
Definition qrhimetal.mm:154
id< MTLRasterizationRateMap > rateMap
Definition qrhimetal.mm:320
QMetalShadingRateMapData * d
QMetalShadingRateMap(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool createFrom(NativeShadingRateMap src) override
Sets up the shading rate map to use a native 3D API shading rate object src.
id< CAMetalDrawable > curDrawable
Definition qrhimetal.mm:473
dispatch_semaphore_t sem[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:474
MTLPixelFormat colorFormat
Definition qrhimetal.mm:479
MTLRenderPassDescriptor * rp
Definition qrhimetal.mm:476
CAMetalLayer * layer
Definition qrhimetal.mm:472
double lastGpuTime[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:475
id< MTLTexture > msaaTex[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:477
QRhiTexture::Format rhiColorFormat
Definition qrhimetal.mm:478
QMetalRenderTargetData * d
QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
QSize pixelSize() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
float devicePixelRatio() const override
int sampleCount() const override
QWindow * window
void waitUntilCompleted(int slot)
bool createOrResize() override
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QRhiCommandBuffer * currentFrameCommandBuffer() override
QMetalSwapChain(QRhiImplementation *rhi)
QMetalCommandBuffer cbWrapper
virtual QRhiSwapChainHdrInfo hdrInfo() override
\variable QRhiSwapChainHdrInfo::limitsType
QMetalRenderBuffer * ds
QMetalSwapChainRenderTarget rtWrapper
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
QMetalSwapChainData * d
bool isFormatSupported(Format f) override
QSize surfacePixelSize() override
QRhiRenderTarget * currentFrameRenderTarget() override
id< MTLTexture > tex
Definition qrhimetal.mm:305
id< MTLTexture > viewForLevel(int level)
QMetalTexture * q
Definition qrhimetal.mm:303
id< MTLTexture > perLevelViews[QRhi::MAX_MIP_LEVELS]
Definition qrhimetal.mm:308
id< MTLBuffer > stagingBuf[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:306
QMetalTextureData(QMetalTexture *t)
Definition qrhimetal.mm:301
MTLPixelFormat format
Definition qrhimetal.mm:304
float devicePixelRatio() const override
QMetalRenderTargetData * d
QMetalTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
bool create() override
Creates the corresponding native graphics resources.
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
int sampleCount() const override
QSize pixelSize() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
bool prepareCreate(QSize *adjustedSize=nullptr)
NativeTexture nativeTexture() override
QMetalTextureData * d
Definition qrhimetal_p.h:81
bool create() override
Creates the corresponding native graphics resources.
int lastActiveFrameSlot
Definition qrhimetal_p.h:85
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
QRhiReadbackResult * result
Definition qrhimetal.mm:262
id< MTLComputePipelineState > pipelineState
Definition qrhimetal.mm:232
id< MTLDepthStencilState > depthStencilState
Definition qrhimetal.mm:227
std::array< id< MTLComputePipelineState >, 3 > tessVertexComputeState
Definition qrhimetal.mm:228
id< MTLRasterizationRateMap > rateMap
Definition qrhimetal.mm:235
id< MTLSamplerState > samplerState
Definition qrhimetal.mm:220
id< MTLBuffer > stagingBuffers[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:216
id< MTLComputePipelineState > tessTessControlComputeState
Definition qrhimetal.mm:229
id< MTLRenderPipelineState > pipelineState
Definition qrhimetal.mm:226
id< MTLBuffer > buffers[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:209
id< MTLTexture > views[QRhi::MAX_MIP_LEVELS]
Definition qrhimetal.mm:217
QMetalCommandBuffer cbWrapper
Definition qrhimetal.mm:245
OffscreenFrame(QRhiImplementation *rhi)
Definition qrhimetal.mm:242
QRhiReadbackDescription desc
Definition qrhimetal.mm:250
QRhiReadbackResult * result
Definition qrhimetal.mm:251
QRhiTexture::Format format
Definition qrhimetal.mm:255
void trySeedingRenderPipelineFromBinaryArchive(MTLRenderPipelineDescriptor *rpDesc)
QRhiMetalData(QRhiMetal *rhi)
Definition qrhimetal.mm:172
QVarLengthArray< BufferReadback, 2 > activeBufferReadbacks
Definition qrhimetal.mm:268
QHash< QRhiShaderStage, QMetalShader > shaderCache
Definition qrhimetal.mm:275
bool setupBinaryArchive(NSURL *sourceFileUrl=nil)
Definition qrhimetal.mm:536
void addRenderPipelineToBinaryArchive(MTLRenderPipelineDescriptor *rpDesc)
MTLCaptureManager * captureMgr
Definition qrhimetal.mm:270
void trySeedingComputePipelineFromBinaryArchive(MTLComputePipelineDescriptor *cpDesc)
id< MTLLibrary > createMetalLib(const QShader &shader, QShader::Variant shaderVariant, QString *error, QByteArray *entryPoint, QShaderKey *activeKey)
QVector< DeferredReleaseEntry > releaseQueue
Definition qrhimetal.mm:239
id< MTLFunction > createMSLShaderFunction(id< MTLLibrary > lib, const QByteArray &entryPoint)
id< MTLCaptureScope > captureScope
Definition qrhimetal.mm:271
MTLRenderPassDescriptor * createDefaultRenderPass(bool hasDepthStencil, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, int colorAttCount, QRhiShadingRateMap *shadingRateMap)
QRhiMetal * q
Definition qrhimetal.mm:174
static const int TEXBUF_ALIGN
Definition qrhimetal.mm:273
API_AVAILABLE(macosx(11.0), ios(14.0)) id< MTLBinaryArchive > binArch
id< MTLCommandBuffer > newCommandBuffer()
Definition qrhimetal.mm:524
QVarLengthArray< TextureReadback, 2 > activeTextureReadbacks
Definition qrhimetal.mm:257
id< MTLDevice > dev
Definition qrhimetal.mm:175
void addComputePipelineToBinaryArchive(MTLComputePipelineDescriptor *cpDesc)
id< MTLCommandQueue > cmdQueue
Definition qrhimetal.mm:176
QMetalCommandBuffer * cbD
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1830
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1551
LimitsType limitsType
Definition qrhi.h:1562
float maxPotentialColorComponentValue
Definition qrhi.h:1570
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1573
float maxColorComponentValue
Definition qrhi.h:1569
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1584