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
312
314
316{
317 QMetalSwapChain(QRhiImplementation *rhi);
319 void destroy() override;
320
321 QRhiCommandBuffer *currentFrameCommandBuffer() override;
323 QSize surfacePixelSize() override;
324 bool isFormatSupported(Format f) override;
325
327
329
330 virtual QRhiSwapChainHdrInfo hdrInfo() override;
331
332 void chooseFormats();
333 void waitUntilCompleted(int slot);
334
335 QWindow *window = nullptr;
337 int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
338 int frameCount = 0;
339 int samples = 1;
344};
345
346struct QRhiMetalData;
347
349{
350public:
351 QRhiMetal(QRhiMetalInitParams *params, QRhiMetalNativeHandles *importDevice = nullptr);
352 ~QRhiMetal();
353
354 static bool probe(QRhiMetalInitParams *params);
355 static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window);
356
357 bool create(QRhi::Flags flags) override;
358 void destroy() override;
359
363 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
364 QRhiBuffer::UsageFlags usage,
365 quint32 size) override;
366 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
367 const QSize &pixelSize,
368 int sampleCount,
369 QRhiRenderBuffer::Flags flags,
370 QRhiTexture::Format backingFormatHint) override;
371 QRhiTexture *createTexture(QRhiTexture::Format format,
372 const QSize &pixelSize,
373 int depth,
374 int arraySize,
375 int sampleCount,
376 QRhiTexture::Flags flags) override;
377 QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
378 QRhiSampler::Filter minFilter,
379 QRhiSampler::Filter mipmapMode,
380 QRhiSampler:: AddressMode u,
381 QRhiSampler::AddressMode v,
382 QRhiSampler::AddressMode w) override;
383
384 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
385 QRhiTextureRenderTarget::Flags flags) override;
386
387 QRhiShadingRateMap *createShadingRateMap() override;
388
389 QRhiSwapChain *createSwapChain() override;
390 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
391 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
392 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override;
393 QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override;
394 QRhi::FrameOpResult finish() override;
395
396 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
397
398 void beginPass(QRhiCommandBuffer *cb,
399 QRhiRenderTarget *rt,
400 const QColor &colorClearValue,
401 const QRhiDepthStencilClearValue &depthStencilClearValue,
402 QRhiResourceUpdateBatch *resourceUpdates,
403 QRhiCommandBuffer::BeginPassFlags flags) override;
404 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
405
406 void setGraphicsPipeline(QRhiCommandBuffer *cb,
407 QRhiGraphicsPipeline *ps) override;
408
409 void setShaderResources(QRhiCommandBuffer *cb,
410 QRhiShaderResourceBindings *srb,
411 int dynamicOffsetCount,
412 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
413
414 void setVertexInput(QRhiCommandBuffer *cb,
415 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
416 QRhiBuffer *indexBuf, quint32 indexOffset,
417 QRhiCommandBuffer::IndexFormat indexFormat) override;
418
419 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
420 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
421 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
422 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
423 void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override;
424
425 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
426 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
427
428 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
429 quint32 instanceCount, quint32 firstIndex,
430 qint32 vertexOffset, quint32 firstInstance) override;
431
432 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
433 void debugMarkEnd(QRhiCommandBuffer *cb) override;
434 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
435
436 void beginComputePass(QRhiCommandBuffer *cb,
437 QRhiResourceUpdateBatch *resourceUpdates,
438 QRhiCommandBuffer::BeginPassFlags flags) override;
439 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
440 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
441 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
442
443 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
444 void beginExternal(QRhiCommandBuffer *cb) override;
445 void endExternal(QRhiCommandBuffer *cb) override;
446 double lastCompletedGpuTime(QRhiCommandBuffer *cb) override;
447
448 QList<int> supportedSampleCounts() const override;
449 QList<QSize> supportedShadingRates(int sampleCount) const override;
450 int ubufAlignment() const override;
451 bool isYUpInFramebuffer() const override;
452 bool isYUpInNDC() const override;
453 bool isClipDepthZeroToOne() const override;
454 QMatrix4x4 clipSpaceCorrMatrix() const override;
455 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
456 bool isFeatureSupported(QRhi::Feature feature) const override;
457 int resourceLimit(QRhi::ResourceLimit limit) const override;
458 const QRhiNativeHandles *nativeHandles() override;
459 QRhiDriverInfo driverInfo() const override;
460 QRhiStats statistics() override;
462 void setQueueSubmitParams(QRhiNativeHandles *params) override;
464 bool isDeviceLost() const override;
465
466 QByteArray pipelineCacheData() override;
467 void setPipelineCacheData(const QByteArray &data) override;
468
469 void executeDeferredReleases(bool forced = false);
470 void finishActiveReadbacks(bool forced = false);
471 qsizetype subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const;
472 void enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEncPtr,
473 int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc,
474 qsizetype *curOfs);
475 void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
476 void executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot);
478 static const int SUPPORTED_STAGES = 5;
481 int dynamicOffsetCount,
482 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets,
483 bool offsetOnlyChange,
484 const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[SUPPORTED_STAGES]);
511 void tessellatedDraw(const TessDrawArgs &args);
512 void adjustForMultiViewDraw(quint32 *instanceCount, QRhiCommandBuffer *cb);
513
515 bool importedDevice = false;
516 bool importedCmdQueue = false;
523
524 struct {
525 int maxTextureSize = 4096;
528 bool isAppleGPU = false;
530 bool multiView = false;
531 bool shadingRateMap = false;
532 bool depthClamp = true;
533 } caps;
534
535 QRhiMetalData *d = nullptr;
536};
537
538QT_END_NAMESPACE
539
540#endif
bool shadingRateMap
static QRhiSwapChainProxyData updateSwapChainProxyData(QWindow *window)
QMetalSwapChain * currentSwapChain
bool isDeviceLost() const override
Definition qrhimetal.mm:968
QRhiMetalNativeHandles nativeHandlesStruct
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
QRhiStats statistics() override
Definition qrhimetal.mm:942
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
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)
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:893
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:955
const QRhiNativeHandles * nativeHandles() override
Definition qrhimetal.mm:932
void executeDeferredReleases(bool forced=false)
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiComputePipeline * createComputePipeline() 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:983
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:949
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:960
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:937
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:592
\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:280
@ Bounded
Definition qrhi_p.h:281
#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
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
API_AVAILABLE(macosx(11.0), ios(14.0)) id< MTLBinaryArchive > binArch
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:1835
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1556
LimitsType limitsType
Definition qrhi.h:1567
float maxPotentialColorComponentValue
Definition qrhi.h:1575
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1578
float maxColorComponentValue
Definition qrhi.h:1574
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1589