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
311
313
315{
316 QMetalSwapChain(QRhiImplementation *rhi);
318 void destroy() override;
319
320 QRhiCommandBuffer *currentFrameCommandBuffer() override;
322 QSize surfacePixelSize() override;
323 bool isFormatSupported(Format f) override;
324
326
328
329 virtual QRhiSwapChainHdrInfo hdrInfo() override;
330
331 void chooseFormats();
332 void waitUntilCompleted(int slot);
333
334 QWindow *window = nullptr;
336 int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
337 int frameCount = 0;
338 int samples = 1;
343};
344
345struct QRhiMetalData;
346
348{
349public:
350 QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice = nullptr);
351 ~QRhiMetal();
352
353 static bool probe(QRhiMetalInitParams *params);
354 static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window);
355
356 bool create(QRhi::Flags flags) override;
357 void destroy() override;
358
362 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
363 QRhiBuffer::UsageFlags usage,
364 quint32 size) override;
365 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
366 const QSize &pixelSize,
367 int sampleCount,
368 QRhiRenderBuffer::Flags flags,
369 QRhiTexture::Format backingFormatHint) override;
370 QRhiTexture *createTexture(QRhiTexture::Format format,
371 const QSize &pixelSize,
372 int depth,
373 int arraySize,
374 int sampleCount,
375 QRhiTexture::Flags flags) override;
376 QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
377 QRhiSampler::Filter minFilter,
378 QRhiSampler::Filter mipmapMode,
379 QRhiSampler:: AddressMode u,
380 QRhiSampler::AddressMode v,
381 QRhiSampler::AddressMode w) override;
382
383 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
384 QRhiTextureRenderTarget::Flags flags) override;
385
386 QRhiShadingRateMap *createShadingRateMap() override;
387
388 QRhiSwapChain *createSwapChain() override;
389 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
390 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
391 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override;
392 QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override;
393 QRhi::FrameOpResult finish() override;
394
395 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
396
397 void beginPass(QRhiCommandBuffer *cb,
398 QRhiRenderTarget *rt,
399 const QColor &colorClearValue,
400 const QRhiDepthStencilClearValue &depthStencilClearValue,
401 QRhiResourceUpdateBatch *resourceUpdates,
402 QRhiCommandBuffer::BeginPassFlags flags) override;
403 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
404
405 void setGraphicsPipeline(QRhiCommandBuffer *cb,
406 QRhiGraphicsPipeline *ps) override;
407
408 void setShaderResources(QRhiCommandBuffer *cb,
409 QRhiShaderResourceBindings *srb,
410 int dynamicOffsetCount,
411 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
412
413 void setVertexInput(QRhiCommandBuffer *cb,
414 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
415 QRhiBuffer *indexBuf, quint32 indexOffset,
416 QRhiCommandBuffer::IndexFormat indexFormat) override;
417
418 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
419 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
420 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
421 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
422 void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override;
423
424 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
425 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
426
427 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
428 quint32 instanceCount, quint32 firstIndex,
429 qint32 vertexOffset, quint32 firstInstance) override;
430
431 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
432 void debugMarkEnd(QRhiCommandBuffer *cb) override;
433 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
434
435 void beginComputePass(QRhiCommandBuffer *cb,
436 QRhiResourceUpdateBatch *resourceUpdates,
437 QRhiCommandBuffer::BeginPassFlags flags) override;
438 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
439 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
440 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
441
442 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
443 void beginExternal(QRhiCommandBuffer *cb) override;
444 void endExternal(QRhiCommandBuffer *cb) override;
445 double lastCompletedGpuTime(QRhiCommandBuffer *cb) override;
446
447 QList<int> supportedSampleCounts() const override;
448 QList<QSize> supportedShadingRates(int sampleCount) const override;
449 int ubufAlignment() const override;
450 bool isYUpInFramebuffer() const override;
451 bool isYUpInNDC() const override;
452 bool isClipDepthZeroToOne() const override;
453 QMatrix4x4 clipSpaceCorrMatrix() const override;
454 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
455 bool isFeatureSupported(QRhi::Feature feature) const override;
456 int resourceLimit(QRhi::ResourceLimit limit) const override;
457 const QRhiNativeHandles *nativeHandles() override;
458 QRhiDriverInfo driverInfo() const override;
459 QRhiStats statistics() override;
461 void setQueueSubmitParams(QRhiNativeHandles *params) override;
463 bool isDeviceLost() const override;
464
465 QByteArray pipelineCacheData() override;
466 void setPipelineCacheData(const QByteArray &data) override;
467
468 void executeDeferredReleases(bool forced = false);
469 void finishActiveReadbacks(bool forced = false);
470 qsizetype subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const;
471 void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr,
472 int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc,
473 qsizetype *curOfs);
474 void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
475 void executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot);
477 static const int SUPPORTED_STAGES = 5;
480 int dynamicOffsetCount,
481 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets,
482 bool offsetOnlyChange,
483 const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[SUPPORTED_STAGES]);
510 void tessellatedDraw(const TessDrawArgs &args);
511 void adjustForMultiViewDraw(quint32 *instanceCount, QRhiCommandBuffer *cb);
512
514 bool importedDevice = false;
515 bool importedCmdQueue = false;
522
523 struct {
524 int maxTextureSize = 4096;
527 bool isAppleGPU = false;
529 bool multiView = false;
530 bool shadingRateMap = false;
531 } caps;
532
533 QRhiMetalData *d = nullptr;
534};
535
536QT_END_NAMESPACE
537
538#endif
bool shadingRateMap
static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window)
QMetalSwapChain * currentSwapChain
bool isDeviceLost() const override
Definition qrhimetal.mm:958
QRhiMetalNativeHandles nativeHandlesStruct
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
QRhiStats statistics() override
Definition qrhimetal.mm:932
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:710
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
Definition qrhimetal.mm:744
void endExternal(QRhiCommandBuffer *cb) override
QRhiMetalData * d
QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice=nullptr)
Definition qrhimetal.mm:483
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:700
QRhiGraphicsPipeline * createGraphicsPipeline() override
bool create(QRhi::Flags flags) override
Definition qrhimetal.mm:557
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:720
int resourceLimit(QRhi::ResourceLimit limit) const override
Definition qrhimetal.mm:883
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:730
int maxTextureSize
void setQueueSubmitParams(QRhiNativeHandles *params) override
Definition qrhimetal.mm:945
const QRhiNativeHandles * nativeHandles() override
Definition qrhimetal.mm:922
void executeDeferredReleases(bool forced=false)
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiComputePipeline * createComputePipeline() override
bool isClipDepthZeroToOne() const override
Definition qrhimetal.mm:725
QVector< int > supportedSampleCounts
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
int maxThreadGroupSize
bool isYUpInFramebuffer() const override
Definition qrhimetal.mm:715
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:973
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:939
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:705
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
void releaseCachedResources() override
Definition qrhimetal.mm:950
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:927
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:514
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
bool isFeatureSupported(QRhi::Feature feature) const override
Definition qrhimetal.mm:777
void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc, qsizetype *curOfs)
void destroy() override
Definition qrhimetal.mm:665
QList< QSize > supportedShadingRates(int sampleCount) const override
Definition qrhimetal.mm:694
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
Combined button and popup list for selecting options.
#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:463
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:468
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:417
QMetalBuffer * acquireWorkBuffer(QRhiMetal *rhiD, quint32 size, WorkBufType type=WorkBufType::DeviceLocal)
QVector< QMetalBuffer * > hostVisibleWorkBuffers
Definition qrhimetal.mm:418
quint32 tescCompOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:436
std::array< id< MTLComputePipelineState >, 3 > vertexComputeState
Definition qrhimetal.mm:427
quint32 tescCompPatchOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:440
static int vsCompVariantToIndex(QShader::Variant vertexCompVariant)
id< MTLComputePipelineState > tescCompPipeline(QRhiMetal *rhiD)
id< MTLRenderPipelineState > teseFragRenderPipeline(QRhiMetal *rhiD, QMetalGraphicsPipeline *pipeline)
QMetalGraphicsPipelineData * q
Definition qrhimetal.mm:421
id< MTLComputePipelineState > vsCompPipeline(QRhiMetal *rhiD, QShader::Variant vertexCompVariant)
quint32 patchCountForDrawCall(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:445
quint32 vsCompOutputBufferSize(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:431
id< MTLComputePipelineState > tessControlComputeState
Definition qrhimetal.mm:428
QMetalGraphicsPipeline * q
Definition qrhimetal.mm:399
MTLDepthClipMode depthClipMode
Definition qrhimetal.mm:406
MTLPrimitiveType primitiveType
Definition qrhimetal.mm:402
id< MTLRenderPipelineState > ps
Definition qrhimetal.mm:400
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:458
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:474
dispatch_semaphore_t sem[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:475
MTLPixelFormat colorFormat
Definition qrhimetal.mm:480
MTLRenderPassDescriptor * rp
Definition qrhimetal.mm:477
CAMetalLayer * layer
Definition qrhimetal.mm:473
double lastGpuTime[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:476
id< MTLTexture > msaaTex[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:478
QRhiTexture::Format rhiColorFormat
Definition qrhimetal.mm:479
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:537
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:525
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:1834
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1555
LimitsType limitsType
Definition qrhi.h:1566
float maxPotentialColorComponentValue
Definition qrhi.h:1574
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1577
float maxColorComponentValue
Definition qrhi.h:1573
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1588