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// Qt-Security score:significant reason:default
4
5#ifndef QRHIMETAL_P_H
6#define QRHIMETAL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qrhi_p.h"
20#include <QWindow>
21
23
24static const int QMTL_FRAMES_IN_FLIGHT = 2;
25
26// have to hide the ObjC stuff, this header cannot contain MTL* at all
27struct QMetalBufferData;
28
29struct QMetalBuffer : public QRhiBuffer
30{
31 QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
32 ~QMetalBuffer();
33 void destroy() override;
34 bool create() override;
38
42 friend class QRhiMetal;
44
45 static constexpr int WorkBufPoolUsage = 1 << 8;
47};
48
50
52{
53 QMetalRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
54 int sampleCount, QRhiRenderBuffer::Flags flags,
55 QRhiTexture::Format backingFormatHint);
57 void destroy() override;
58 bool create() override;
59 QRhiTexture::Format backingFormat() const override;
60
62 int samples = 1;
65 friend class QRhiMetal;
66};
67
69
71{
72 QMetalTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth,
73 int arraySize, int sampleCount, Flags flags);
75 void destroy() override;
76 bool create() override;
77 bool createFrom(NativeTexture src) override;
79
80 bool prepareCreate(QSize *adjustedSize = nullptr);
81
84 int samples = 1;
87 friend class QRhiMetal;
89 friend struct QMetalTextureData;
90};
91
93
95{
96 QMetalSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
97 AddressMode u, AddressMode v, AddressMode w);
99 void destroy() override;
100 bool create() override;
101
105 friend class QRhiMetal;
107};
108
110
112{
113 QMetalShadingRateMap(QRhiImplementation *rhi);
115 void destroy() override;
116 bool createFrom(NativeShadingRateMap src) override;
117
121 friend class QRhiMetal;
122};
123
125{
126 QMetalRenderPassDescriptor(QRhiImplementation *rhi);
128 void destroy() override;
129 bool isCompatible(const QRhiRenderPassDescriptor *other) const override;
131 QVector<quint32> serializedFormat() const override;
132
134
135 // there is no MTLRenderPassDescriptor here as one will be created for each pass in beginPass()
136
137 // but the things needed for the render pipeline descriptor have to be provided
138 static const int MAX_COLOR_ATTACHMENTS = 8;
140 bool hasDepthStencil = false;
143 bool hasShadingRateMap = false;
145};
146
148
150{
151 QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
153 void destroy() override;
154
155 QSize pixelSize() const override;
156 float devicePixelRatio() const override;
157 int sampleCount() const override;
158
160};
161
163{
164 QMetalTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags);
166 void destroy() override;
167
168 QSize pixelSize() const override;
169 float devicePixelRatio() const override;
170 int sampleCount() const override;
171
173 bool create() override;
174
176 friend class QRhiMetal;
177};
178
181
229
232
234{
235 QMetalGraphicsPipeline(QRhiImplementation *rhi);
237 void destroy() override;
238 bool create() override;
239
242 void setupMetalDepthStencilDescriptor(void *metalDsDesc);
243 void mapStates();
245 bool createTessellationPipelines(const QShader &tessVert, const QShader &tesc, const QShader &tese, const QShader &tessFrag);
246
250 friend class QRhiMetal;
251};
252
254
256{
257 QMetalComputePipeline(QRhiImplementation *rhi);
259 void destroy() override;
260 bool create() override;
261
265 friend class QRhiMetal;
266};
267
269struct QMetalSwapChain;
270
314
316
318{
319 QMetalSwapChain(QRhiImplementation *rhi);
321 void destroy() override;
322
323 QRhiCommandBuffer *currentFrameCommandBuffer() override;
325 QSize surfacePixelSize() override;
326 bool isFormatSupported(Format f) override;
327
329
331
332 virtual QRhiSwapChainHdrInfo hdrInfo() override;
333
334 void chooseFormats();
335 void waitUntilCompleted(int slot);
336
337 QWindow *window = nullptr;
339 int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
340 int frameCount = 0;
341 int samples = 1;
346};
347
348struct QRhiMetalData;
349
351{
352public:
353 QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice = nullptr);
354 ~QRhiMetal();
355
356 static bool probe(QRhiMetalInitParams *params);
357 static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window);
358
359 bool create(QRhi::Flags flags) override;
360 void destroy() override;
361
365 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
366 QRhiBuffer::UsageFlags usage,
367 quint32 size) override;
368 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
369 const QSize &pixelSize,
370 int sampleCount,
371 QRhiRenderBuffer::Flags flags,
372 QRhiTexture::Format backingFormatHint) override;
373 QRhiTexture *createTexture(QRhiTexture::Format format,
374 const QSize &pixelSize,
375 int depth,
376 int arraySize,
377 int sampleCount,
378 QRhiTexture::Flags flags) override;
379 QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
380 QRhiSampler::Filter minFilter,
381 QRhiSampler::Filter mipmapMode,
382 QRhiSampler:: AddressMode u,
383 QRhiSampler::AddressMode v,
384 QRhiSampler::AddressMode w) override;
385
386 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
387 QRhiTextureRenderTarget::Flags flags) override;
388
389 QRhiShadingRateMap *createShadingRateMap() override;
390
391 QRhiSwapChain *createSwapChain() override;
392 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
393 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
394 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override;
395 QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override;
396 QRhi::FrameOpResult finish() override;
397
398 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
399
400 void beginPass(QRhiCommandBuffer *cb,
401 QRhiRenderTarget *rt,
402 const QColor &colorClearValue,
403 const QRhiDepthStencilClearValue &depthStencilClearValue,
404 QRhiResourceUpdateBatch *resourceUpdates,
405 QRhiCommandBuffer::BeginPassFlags flags) override;
406 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
407
408 void setGraphicsPipeline(QRhiCommandBuffer *cb,
409 QRhiGraphicsPipeline *ps) override;
410
411 void setShaderResources(QRhiCommandBuffer *cb,
412 QRhiShaderResourceBindings *srb,
413 int dynamicOffsetCount,
414 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
415
416 void setVertexInput(QRhiCommandBuffer *cb,
417 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
418 QRhiBuffer *indexBuf, quint32 indexOffset,
419 QRhiCommandBuffer::IndexFormat indexFormat) override;
420
421 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
422 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
423 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
424 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
425 void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override;
426
427 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
428 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
429
430 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
431 quint32 instanceCount, quint32 firstIndex,
432 qint32 vertexOffset, quint32 firstInstance) override;
433
434 void drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
435 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override;
436
437 void drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
438 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override;
439
440 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
441 void debugMarkEnd(QRhiCommandBuffer *cb) override;
442 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
443
444 void beginComputePass(QRhiCommandBuffer *cb,
445 QRhiResourceUpdateBatch *resourceUpdates,
446 QRhiCommandBuffer::BeginPassFlags flags) override;
447 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
448 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
449 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
450
451 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
452 void beginExternal(QRhiCommandBuffer *cb) override;
453 void endExternal(QRhiCommandBuffer *cb) override;
454 double lastCompletedGpuTime(QRhiCommandBuffer *cb) override;
455
456 QList<int> supportedSampleCounts() const override;
457 QList<QSize> supportedShadingRates(int sampleCount) const override;
458 int ubufAlignment() const override;
459 bool isYUpInFramebuffer() const override;
460 bool isYUpInNDC() const override;
461 bool isClipDepthZeroToOne() const override;
462 QMatrix4x4 clipSpaceCorrMatrix() const override;
463 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
464 bool isFeatureSupported(QRhi::Feature feature) const override;
465 int resourceLimit(QRhi::ResourceLimit limit) const override;
466 const QRhiNativeHandles *nativeHandles() override;
467 QRhiDriverInfo driverInfo() const override;
468 QRhiStats statistics() override;
470 void setQueueSubmitParams(QRhiNativeHandles *params) override;
472 bool isDeviceLost() const override;
473
474 QByteArray pipelineCacheData() override;
475 void setPipelineCacheData(const QByteArray &data) override;
476
477 void executeDeferredReleases(bool forced = false);
478 void finishActiveReadbacks(bool forced = false);
479 qsizetype subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const;
480 void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr,
481 int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc,
482 qsizetype *curOfs);
483 void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
484 void executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot);
486 static const int SUPPORTED_STAGES = 5;
489 int dynamicOffsetCount,
490 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets,
491 bool offsetOnlyChange,
492 const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[SUPPORTED_STAGES]);
494
521 void tessellatedDraw(const TessDrawArgs &args);
522 void adjustForMultiViewDraw(quint32 *instanceCount, QRhiCommandBuffer *cb);
523
525 bool importedDevice = false;
526 bool importedCmdQueue = false;
533
534 struct {
535 int maxTextureSize = 4096;
538 bool isAppleGPU = false;
540 bool multiView = false;
541 bool shadingRateMap = false;
542 bool depthClamp = true;
543 } caps;
544
545 QRhiMetalData *d = nullptr;
546};
547
548QT_END_NAMESPACE
549
550#endif
bool shadingRateMap
static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window)
QMetalSwapChain * currentSwapChain
bool isDeviceLost() const override
Definition qrhimetal.mm:972
QRhiMetalNativeHandles nativeHandlesStruct
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
QRhiStats statistics() override
Definition qrhimetal.mm:946
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:718
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
Definition qrhimetal.mm:752
void endExternal(QRhiCommandBuffer *cb) override
QRhiMetalData * d
void drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice=nullptr)
Definition qrhimetal.mm:486
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)
void setDefaultScissor(QMetalCommandBuffer *cbD)
QRhiSwapChain * createSwapChain() override
Definition qrhimetal.mm:708
QRhiGraphicsPipeline * createGraphicsPipeline() override
bool create(QRhi::Flags flags) override
Definition qrhimetal.mm:562
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:728
int resourceLimit(QRhi::ResourceLimit limit) const override
Definition qrhimetal.mm:897
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:738
int maxTextureSize
void setQueueSubmitParams(QRhiNativeHandles *params) override
Definition qrhimetal.mm:959
const QRhiNativeHandles * nativeHandles() override
Definition qrhimetal.mm:936
void executeDeferredReleases(bool forced=false)
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiComputePipeline * createComputePipeline() override
void drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
bool isClipDepthZeroToOne() const override
Definition qrhimetal.mm:733
QVector< int > supportedSampleCounts
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
int maxThreadGroupSize
bool isYUpInFramebuffer() const override
Definition qrhimetal.mm:723
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:987
void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override
bool depthClamp
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:953
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:713
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
void releaseCachedResources() override
Definition qrhimetal.mm:964
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:941
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:517
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
bool isFeatureSupported(QRhi::Feature feature) const override
Definition qrhimetal.mm:785
void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc, qsizetype *curOfs)
void destroy() override
Definition qrhimetal.mm:673
QList< QSize > supportedShadingRates(int sampleCount) const override
Definition qrhimetal.mm:702
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
Definition qrhi_p.h:597
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:323
\inmodule QtGui
Definition qshader.h:82
Combined button and popup list for selecting options.
#define __has_feature(x)
@ UnBounded
Definition qrhi_p.h:285
@ Bounded
Definition qrhi_p.h:286
#define QRHI_RES_RHI(t)
Definition qrhi_p.h:31
#define QRHI_RES(t, x)
Definition qrhi_p.h:30
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:60
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:55
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:24
void f(int c)
[26]
QVarLengthArray< BufferUpdate, 16 > pendingUpdates[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:293
id< MTLBuffer > buf[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:288
char * beginFullDynamicBufferUpdateForCurrentFrame() override
QMetalBufferData * d
Definition qrhimetal_p.h:39
QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
static constexpr int WorkBufPoolUsage
Definition qrhimetal_p.h:45
int lastActiveFrameSlot
Definition qrhimetal_p.h:41
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:359
id< MTLDepthStencilState > currentDepthStencilState
Definition qrhimetal.mm:363
QMetalShaderResourceBindingsData currentShaderResourceBindingState
Definition qrhimetal.mm:364
id< MTLComputeCommandEncoder > tessellationComputeEncoder
Definition qrhimetal.mm:358
QRhiBatchedBindings< id< MTLBuffer > > currentVertexInputsBuffers
Definition qrhimetal.mm:361
id< MTLRenderCommandEncoder > currentRenderPassEncoder
Definition qrhimetal.mm:356
id< MTLCommandBuffer > cb
Definition qrhimetal.mm:354
QRhiBatchedBindings< NSUInteger > currentVertexInputOffsets
Definition qrhimetal.mm:362
id< MTLComputeCommandEncoder > currentComputePassEncoder
Definition qrhimetal.mm:357
QMetalBuffer * currentIndexBuffer
std::pair< float, float > currentDepthBiasValues
QRhiCommandBuffer::IndexFormat currentIndexFormat
QRhiMetalCommandBufferNativeHandles nativeHandlesStruct
QRhiViewport currentViewport
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:466
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:471
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:420
QMetalBuffer * acquireWorkBuffer(QRhiMetal *rhiD, quint32 size, WorkBufType type=WorkBufType::DeviceLocal)
QVector< QMetalBuffer * > hostVisibleWorkBuffers
Definition qrhimetal.mm:421
quint32 tescCompOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:439
std::array< id< MTLComputePipelineState >, 3 > vertexComputeState
Definition qrhimetal.mm:430
quint32 tescCompPatchOutputBufferSize(quint32 patchCount) const
Definition qrhimetal.mm:443
static int vsCompVariantToIndex(QShader::Variant vertexCompVariant)
id< MTLComputePipelineState > tescCompPipeline(QRhiMetal *rhiD)
id< MTLRenderPipelineState > teseFragRenderPipeline(QRhiMetal *rhiD, QMetalGraphicsPipeline *pipeline)
QMetalGraphicsPipelineData * q
Definition qrhimetal.mm:424
id< MTLComputePipelineState > vsCompPipeline(QRhiMetal *rhiD, QShader::Variant vertexCompVariant)
quint32 patchCountForDrawCall(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:448
quint32 vsCompOutputBufferSize(quint32 vertexOrIndexCount, quint32 instanceCount) const
Definition qrhimetal.mm:434
id< MTLComputePipelineState > tessControlComputeState
Definition qrhimetal.mm:431
QMetalGraphicsPipeline * q
Definition qrhimetal.mm:402
MTLDepthClipMode depthClipMode
Definition qrhimetal.mm:409
MTLPrimitiveType primitiveType
Definition qrhimetal.mm:405
id< MTLRenderPipelineState > ps
Definition qrhimetal.mm:403
QMetalBuffer * bufferSizeBuffer
Definition qrhimetal.mm:461
void setupVertexInputDescriptor(MTLVertexDescriptor *desc)
void setupStageInputDescriptor(MTLStageInputOutputDescriptor *desc)
id< MTLDepthStencilState > ds
Definition qrhimetal.mm:404
MTLTriangleFillMode triangleFillMode
Definition qrhimetal.mm:408
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:299
MTLPixelFormat format
Definition qrhimetal.mm:298
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalRenderBufferData * d
Definition qrhimetal_p.h:61
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:388
id< MTLTexture > dsResolveTex
Definition qrhimetal.mm:390
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList
Definition qrhimetal.mm:397
id< MTLTexture > dsTex
Definition qrhimetal.mm:389
id< MTLSamplerState > samplerState
Definition qrhimetal.mm:318
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:341
QVarLengthArray< Sampler, 8 > samplers
Definition qrhimetal.mm:343
QRhiBatchedBindings< NSUInteger > bufferOffsetBatches
Definition qrhimetal.mm:345
QVarLengthArray< Texture, 8 > textures
Definition qrhimetal.mm:342
QRhiBatchedBindings< id< MTLSamplerState > > samplerBatches
Definition qrhimetal.mm:347
QRhiBatchedBindings< id< MTLTexture > > textureBatches
Definition qrhimetal.mm:346
QRhiBatchedBindings< id< MTLBuffer > > bufferBatches
Definition qrhimetal.mm:344
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
id< MTLRasterizationRateMap > rateMap
Definition qrhimetal.mm:323
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:477
dispatch_semaphore_t sem[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:478
MTLPixelFormat colorFormat
Definition qrhimetal.mm:483
MTLRenderPassDescriptor * rp
Definition qrhimetal.mm:480
CAMetalLayer * layer
Definition qrhimetal.mm:476
double lastGpuTime[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:479
id< MTLTexture > msaaTex[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:481
QRhiTexture::Format rhiColorFormat
Definition qrhimetal.mm:482
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:308
id< MTLTexture > viewForLevel(int level)
QMetalTexture * q
Definition qrhimetal.mm:306
id< MTLTexture > perLevelViews[QRhi::MAX_MIP_LEVELS]
Definition qrhimetal.mm:311
id< MTLBuffer > stagingBuf[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:309
QMetalTextureData(QMetalTexture *t)
Definition qrhimetal.mm:304
MTLPixelFormat format
Definition qrhimetal.mm:307
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:82
bool create() override
Creates the corresponding native graphics resources.
int lastActiveFrameSlot
Definition qrhimetal_p.h:86
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:265
id< MTLComputePipelineState > pipelineState
Definition qrhimetal.mm:235
id< MTLDepthStencilState > depthStencilState
Definition qrhimetal.mm:230
std::array< id< MTLComputePipelineState >, 3 > tessVertexComputeState
Definition qrhimetal.mm:231
id< MTLRasterizationRateMap > rateMap
Definition qrhimetal.mm:238
id< MTLSamplerState > samplerState
Definition qrhimetal.mm:223
id< MTLBuffer > stagingBuffers[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:219
id< MTLComputePipelineState > tessTessControlComputeState
Definition qrhimetal.mm:232
id< MTLRenderPipelineState > pipelineState
Definition qrhimetal.mm:229
id< MTLBuffer > buffers[QMTL_FRAMES_IN_FLIGHT]
Definition qrhimetal.mm:212
id< MTLTexture > views[QRhi::MAX_MIP_LEVELS]
Definition qrhimetal.mm:220
QMetalCommandBuffer cbWrapper
Definition qrhimetal.mm:248
OffscreenFrame(QRhiImplementation *rhi)
Definition qrhimetal.mm:245
QRhiReadbackDescription desc
Definition qrhimetal.mm:253
QRhiReadbackResult * result
Definition qrhimetal.mm:254
QRhiTexture::Format format
Definition qrhimetal.mm:258
void trySeedingRenderPipelineFromBinaryArchive(MTLRenderPipelineDescriptor *rpDesc)
QRhiMetalData(QRhiMetal *rhi)
Definition qrhimetal.mm:175
QVarLengthArray< BufferReadback, 2 > activeBufferReadbacks
Definition qrhimetal.mm:271
QHash< QRhiShaderStage, QMetalShader > shaderCache
Definition qrhimetal.mm:278
bool setupBinaryArchive(NSURL *sourceFileUrl=nil)
Definition qrhimetal.mm:542
void addRenderPipelineToBinaryArchive(MTLRenderPipelineDescriptor *rpDesc)
MTLCaptureManager * captureMgr
Definition qrhimetal.mm:273
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:242
id< MTLFunction > createMSLShaderFunction(id< MTLLibrary > lib, const QByteArray &entryPoint)
id< MTLCaptureScope > captureScope
Definition qrhimetal.mm:274
MTLRenderPassDescriptor * createDefaultRenderPass(bool hasDepthStencil, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, int colorAttCount, QRhiShadingRateMap *shadingRateMap)
QRhiMetal * q
Definition qrhimetal.mm:177
static const int TEXBUF_ALIGN
Definition qrhimetal.mm:276
id< MTLBinaryArchive > binArch
Definition qrhimetal.mm:180
id< MTLCommandBuffer > newCommandBuffer()
Definition qrhimetal.mm:530
QVarLengthArray< TextureReadback, 2 > activeTextureReadbacks
Definition qrhimetal.mm:260
id< MTLDevice > dev
Definition qrhimetal.mm:178
void addComputePipelineToBinaryArchive(MTLComputePipelineDescriptor *cpDesc)
id< MTLCommandQueue > cmdQueue
Definition qrhimetal.mm:179
QMetalCommandBuffer * cbD
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1867
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1557
LimitsType limitsType
Definition qrhi.h:1568
float maxPotentialColorComponentValue
Definition qrhi.h:1576
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1579
float maxColorComponentValue
Definition qrhi.h:1575
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1590