diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-05-27 17:44:49 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-05-28 17:53:32 +0200 |
commit | 56977990e04efa051b1ebd4ce9274d6b69c7bd0c (patch) | |
tree | eaa66635b67faaf94df7b0670fa9e0971268a936 /src/gui/rhi/qrhimetal.mm | |
parent | c991d87ee2c239fedb77f76f25936dddf5eb5982 (diff) |
rhi: Harmonize create-destroy API pattern with the rest of Qt
For historical reasons we use build and release instead of create and
destroy. This becomes confusing now that more modules in Qt start taking
QRhi into use. Migrate to the more familiar naming, so those who have
used QWindow or QOpenGLContext before will find it natural.
Change-Id: I05eb2243ce274c59b03a5f8bcbb2792a4f37120f
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhimetal.mm')
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index a003d4815d..b249dc55cc 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -136,7 +136,7 @@ struct QMetalShader std::array<uint, 3> localSize; QShader::NativeResourceBindingMap nativeResourceBindingMap; - void release() { + void destroy() { nativeResourceBindingMap.clear(); [lib release]; lib = nil; @@ -425,7 +425,7 @@ void QRhiMetal::destroy() finishActiveReadbacks(true); for (QMetalShader &s : d->shaderCache) - s.release(); + s.destroy(); d->shaderCache.clear(); if (@available(macOS 10.13, iOS 11.0, *)) { @@ -612,7 +612,7 @@ bool QRhiMetal::makeThreadLocalNativeContextCurrent() void QRhiMetal::releaseCachedResources() { for (QMetalShader &s : d->shaderCache) - s.release(); + s.destroy(); d->shaderCache.clear(); } @@ -2141,11 +2141,11 @@ QMetalBuffer::QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, QMetalBuffer::~QMetalBuffer() { - release(); + destroy(); delete d; } -void QMetalBuffer::release() +void QMetalBuffer::destroy() { if (!d->buf[0]) return; @@ -2167,10 +2167,10 @@ void QMetalBuffer::release() rhiD->unregisterResource(this); } -bool QMetalBuffer::build() +bool QMetalBuffer::create() { if (d->buf[0]) - release(); + destroy(); if (m_usage.testFlag(QRhiBuffer::StorageBuffer) && m_type == Dynamic) { qWarning("StorageBuffer cannot be combined with Dynamic"); @@ -2383,11 +2383,11 @@ QMetalRenderBuffer::QMetalRenderBuffer(QRhiImplementation *rhi, Type type, const QMetalRenderBuffer::~QMetalRenderBuffer() { - release(); + destroy(); delete d; } -void QMetalRenderBuffer::release() +void QMetalRenderBuffer::destroy() { if (!d->tex) return; @@ -2406,10 +2406,10 @@ void QMetalRenderBuffer::release() rhiD->unregisterResource(this); } -bool QMetalRenderBuffer::build() +bool QMetalRenderBuffer::create() { if (d->tex) - release(); + destroy(); if (m_pixelSize.isEmpty()) return false; @@ -2490,11 +2490,11 @@ QMetalTexture::QMetalTexture(QRhiImplementation *rhi, Format format, const QSize QMetalTexture::~QMetalTexture() { - release(); + destroy(); delete d; } -void QMetalTexture::release() +void QMetalTexture::destroy() { if (!d->tex) return; @@ -2523,10 +2523,10 @@ void QMetalTexture::release() rhiD->unregisterResource(this); } -bool QMetalTexture::prepareBuild(QSize *adjustedSize) +bool QMetalTexture::prepareCreate(QSize *adjustedSize) { if (d->tex) - release(); + destroy(); const QSize size = m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize; const bool isCube = m_flags.testFlag(CubeMap); @@ -2553,10 +2553,10 @@ bool QMetalTexture::prepareBuild(QSize *adjustedSize) return true; } -bool QMetalTexture::build() +bool QMetalTexture::create() { QSize size; - if (!prepareBuild(&size)) + if (!prepareCreate(&size)) return false; MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init]; @@ -2598,13 +2598,13 @@ bool QMetalTexture::build() return true; } -bool QMetalTexture::buildFrom(QRhiTexture::NativeTexture src) +bool QMetalTexture::createFrom(QRhiTexture::NativeTexture src) { id<MTLTexture> tex = id<MTLTexture>(src.object); if (tex == 0) return false; - if (!prepareBuild()) + if (!prepareCreate()) return false; d->tex = tex; @@ -2650,11 +2650,11 @@ QMetalSampler::QMetalSampler(QRhiImplementation *rhi, Filter magFilter, Filter m QMetalSampler::~QMetalSampler() { - release(); + destroy(); delete d; } -void QMetalSampler::release() +void QMetalSampler::destroy() { if (!d->samplerState) return; @@ -2739,10 +2739,10 @@ static inline MTLCompareFunction toMetalTextureCompareFunction(QRhiSampler::Comp } } -bool QMetalSampler::build() +bool QMetalSampler::create() { if (d->samplerState) - release(); + destroy(); MTLSamplerDescriptor *desc = [[MTLSamplerDescriptor alloc] init]; desc.minFilter = toMetalFilter(m_minFilter); @@ -2772,10 +2772,10 @@ QMetalRenderPassDescriptor::QMetalRenderPassDescriptor(QRhiImplementation *rhi) QMetalRenderPassDescriptor::~QMetalRenderPassDescriptor() { - release(); + destroy(); } -void QMetalRenderPassDescriptor::release() +void QMetalRenderPassDescriptor::destroy() { // nothing to do here } @@ -2814,11 +2814,11 @@ QMetalReferenceRenderTarget::QMetalReferenceRenderTarget(QRhiImplementation *rhi QMetalReferenceRenderTarget::~QMetalReferenceRenderTarget() { - release(); + destroy(); delete d; } -void QMetalReferenceRenderTarget::release() +void QMetalReferenceRenderTarget::destroy() { // nothing to do here } @@ -2848,11 +2848,11 @@ QMetalTextureRenderTarget::QMetalTextureRenderTarget(QRhiImplementation *rhi, QMetalTextureRenderTarget::~QMetalTextureRenderTarget() { - release(); + destroy(); delete d; } -void QMetalTextureRenderTarget::release() +void QMetalTextureRenderTarget::destroy() { // nothing to do here } @@ -2879,7 +2879,7 @@ QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDesc return rpD; } -bool QMetalTextureRenderTarget::build() +bool QMetalTextureRenderTarget::create() { QRHI_RES_RHI(QRhiMetal); const bool hasColorAttachments = m_desc.cbeginColorAttachments() != m_desc.cendColorAttachments(); @@ -2970,19 +2970,19 @@ QMetalShaderResourceBindings::QMetalShaderResourceBindings(QRhiImplementation *r QMetalShaderResourceBindings::~QMetalShaderResourceBindings() { - release(); + destroy(); } -void QMetalShaderResourceBindings::release() +void QMetalShaderResourceBindings::destroy() { sortedBindings.clear(); maxBinding = -1; } -bool QMetalShaderResourceBindings::build() +bool QMetalShaderResourceBindings::create() { if (!sortedBindings.isEmpty()) - release(); + destroy(); std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); std::sort(sortedBindings.begin(), sortedBindings.end(), @@ -3058,16 +3058,16 @@ QMetalGraphicsPipeline::QMetalGraphicsPipeline(QRhiImplementation *rhi) QMetalGraphicsPipeline::~QMetalGraphicsPipeline() { - release(); + destroy(); delete d; } -void QMetalGraphicsPipeline::release() +void QMetalGraphicsPipeline::destroy() { QRHI_RES_RHI(QRhiMetal); - d->vs.release(); - d->fs.release(); + d->vs.destroy(); + d->fs.destroy(); [d->ds release]; d->ds = nil; @@ -3347,10 +3347,10 @@ id<MTLFunction> QRhiMetalData::createMSLShaderFunction(id<MTLLibrary> lib, const return f; } -bool QMetalGraphicsPipeline::build() +bool QMetalGraphicsPipeline::create() { if (d->ps) - release(); + destroy(); QRHI_RES_RHI(QRhiMetal); if (!rhiD->sanityCheckGraphicsPipeline(this)) @@ -3428,7 +3428,7 @@ bool QMetalGraphicsPipeline::build() if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) { // Use the simplest strategy: too many cached shaders -> drop them all. for (QMetalShader &s : rhiD->d->shaderCache) - s.release(); + s.destroy(); rhiD->d->shaderCache.clear(); } switch (shaderStage.type()) { @@ -3554,15 +3554,15 @@ QMetalComputePipeline::QMetalComputePipeline(QRhiImplementation *rhi) QMetalComputePipeline::~QMetalComputePipeline() { - release(); + destroy(); delete d; } -void QMetalComputePipeline::release() +void QMetalComputePipeline::destroy() { QRHI_RES_RHI(QRhiMetal); - d->cs.release(); + d->cs.destroy(); if (!d->ps) return; @@ -3573,10 +3573,10 @@ void QMetalComputePipeline::release() rhiD->unregisterResource(this); } -bool QMetalComputePipeline::build() +bool QMetalComputePipeline::create() { if (d->ps) - release(); + destroy(); QRHI_RES_RHI(QRhiMetal); @@ -3608,7 +3608,7 @@ bool QMetalComputePipeline::build() if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) { for (QMetalShader &s : rhiD->d->shaderCache) - s.release(); + s.destroy(); rhiD->d->shaderCache.clear(); } rhiD->d->shaderCache.insert(m_shaderStage, d->cs); @@ -3642,11 +3642,11 @@ QMetalCommandBuffer::QMetalCommandBuffer(QRhiImplementation *rhi) QMetalCommandBuffer::~QMetalCommandBuffer() { - release(); + destroy(); delete d; } -void QMetalCommandBuffer::release() +void QMetalCommandBuffer::destroy() { // nothing to do here, we do not own the MTL cb object } @@ -3708,11 +3708,11 @@ QMetalSwapChain::QMetalSwapChain(QRhiImplementation *rhi) QMetalSwapChain::~QMetalSwapChain() { - release(); + destroy(); delete d; } -void QMetalSwapChain::release() +void QMetalSwapChain::destroy() { #ifdef TARGET_IPHONE_SIMULATOR if (@available(ios 13.0, *)) { @@ -3799,7 +3799,7 @@ void QMetalSwapChain::chooseFormats() d->rhiColorFormat = QRhiTexture::BGRA8; } -bool QMetalSwapChain::buildOrResize() +bool QMetalSwapChain::createOrResize() { #ifdef TARGET_IPHONE_SIMULATOR if (@available(ios 13.0, *)) { @@ -3810,8 +3810,8 @@ bool QMetalSwapChain::buildOrResize() const bool needsRegistration = !window || window != m_window; if (window && window != m_window) - release(); - // else no release(), this is intentional + destroy(); + // else no destroy(), this is intentional QRHI_RES_RHI(QRhiMetal); if (needsRegistration) @@ -3860,7 +3860,7 @@ bool QMetalSwapChain::buildOrResize() } // Now set the layer's drawableSize which will stay set to the same value - // until the next buildOrResize(), thus ensuring atomicity with regards to + // until the next createOrResize(), thus ensuring atomicity with regards to // the drawable size in frames. CGSize layerSize = d->layer.bounds.size; layerSize.width *= d->layer.contentsScale; @@ -3890,7 +3890,7 @@ bool QMetalSwapChain::buildOrResize() if (m_depthStencil && m_depthStencil->pixelSize() != pixelSize) { if (m_depthStencil->flags().testFlag(QRhiRenderBuffer::UsedWithSwapChainOnly)) { m_depthStencil->setPixelSize(pixelSize); - if (!m_depthStencil->build()) + if (!m_depthStencil->create()) qWarning("Failed to rebuild swapchain's associated depth-stencil buffer for size %dx%d", pixelSize.width(), pixelSize.height()); } else { |