Commit d7508e37 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

metal: start adding depth-stencil buffer support

parent 2d26d5d0
......@@ -45,6 +45,10 @@ QT_BEGIN_NAMESPACE
struct Q_RHI_EXPORT QRhiMetalInitParams : public QRhiInitParams
{
// Not sure how validation could be enabled from here. Instead, do qmake
// -spec macx-xcode and run the project (debug build) in XCode to get Metal
// API validation.
bool importExistingDevice = false;
void *dev = nullptr;
};
......
......@@ -729,7 +729,9 @@ void QMetalTextureRenderTarget::release()
QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDescriptor()
{
return new QMetalRenderPassDescriptor(rhi);
QMetalRenderPassDescriptor *rpD = new QMetalRenderPassDescriptor(rhi);
rpD->hasDepthStencil = m_desc.depthStencilBuffer || m_desc.depthTexture;
return rpD;
}
bool QMetalTextureRenderTarget::build()
......@@ -1134,16 +1136,20 @@ bool QMetalGraphicsPipeline::build()
rpDesc.colorAttachments[i].writeMask = toMetalColorWriteMask(b.colorWrite);
}
// ### can be set only when a depth-stencil buffer will actually be bound
// if (rhiD->d->dev.depth24Stencil8PixelFormatSupported) {
// rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
// rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
// } else {
// rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
// rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
// }
QMetalRenderPassDescriptor *rpD = QRHI_RES(QMetalRenderPassDescriptor, m_renderPassDesc);
if (rpD->hasDepthStencil) {
// Must only be set when a depth-stencil buffer will actually be bound,
// validation blows up otherwise.
if (rhiD->d->dev.depth24Stencil8PixelFormatSupported) {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
} else {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}
}
rpDesc.sampleCount = 1; // ###
rpDesc.sampleCount = 1;
NSError *err = nil;
d->ps = [rhiD->d->dev newRenderPipelineStateWithDescriptor: rpDesc error: &err];
......@@ -1245,7 +1251,9 @@ QSize QMetalSwapChain::effectivePixelSize() const
QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor()
{
return new QMetalRenderPassDescriptor(rhi);
QMetalRenderPassDescriptor *rpD = new QMetalRenderPassDescriptor(rhi);
rpD->hasDepthStencil = m_depthStencil != nullptr;
return rpD;
}
bool QMetalSwapChain::buildOrResize()
......@@ -1275,7 +1283,8 @@ bool QMetalSwapChain::buildOrResize()
ds = m_depthStencil ? QRHI_RES(QMetalRenderBuffer, m_depthStencil) : nullptr;
rtWrapper.d.pixelSize = pixelSize;
rtWrapper.d.attCount = 1;
rtWrapper.d.colorAttCount = 1;
rtWrapper.d.dsAttCount = ds ? 1 : 0;
qDebug("got CAMetalLayer, size %dx%d", pixelSize.width(), pixelSize.height());
......
......@@ -105,6 +105,8 @@ struct QMetalRenderPassDescriptor : public QRhiRenderPassDescriptor
void release() override;
// there is no MTLRenderPassDescriptor here as one will be created for each pass in beginPass()
bool hasDepthStencil = false;
};
struct QMetalBasicRenderTargetData
......@@ -112,7 +114,8 @@ struct QMetalBasicRenderTargetData
QMetalBasicRenderTargetData(QRhiImplementation *) { }
QSize pixelSize;
int attCount = 0;
int colorAttCount = 0;
int dsAttCount = 0;
};
struct QMetalReferenceRenderTarget : public QRhiReferenceRenderTarget
......
......@@ -2799,6 +2799,8 @@ void QVkTextureRenderTarget::release()
QRhiRenderPassDescriptor *QVkTextureRenderTarget::newCompatibleRenderPassDescriptor()
{
// not yet built so cannot rely on data computed in build()
QRHI_RES_RHI(QRhiVulkan);
QVkRenderPassDescriptor *rp = new QVkRenderPassDescriptor(rhi);
const VkFormat dsFormat = m_desc.depthTexture ? toVkTextureFormat(m_desc.depthTexture->format())
......@@ -2806,7 +2808,7 @@ QRhiRenderPassDescriptor *QVkTextureRenderTarget::newCompatibleRenderPassDescrip
if (!rhiD->createOffscreenRenderPass(&rp->rp,
m_desc.colorAttachments,
m_flags.testFlag(QRhiTextureRenderTarget::PreserveColorContents),
d.dsAttCount > 0,
m_desc.depthStencilBuffer || m_desc.depthTexture,
dsFormat,
m_desc.depthTexture != nullptr))
{
......@@ -3242,9 +3244,15 @@ QSize QVkSwapChain::effectivePixelSize() const
QRhiRenderPassDescriptor *QVkSwapChain::newCompatibleRenderPassDescriptor()
{
// not yet built so cannot rely on data computed in buildOrResize()
QRHI_RES_RHI(QRhiVulkan);
QVkRenderPassDescriptor *rp = new QVkRenderPassDescriptor(rhi);
if (!rhiD->createDefaultRenderPass(&rp->rp, m_depthStencil != nullptr, sampleCount, colorFormat)) {
if (!rhiD->createDefaultRenderPass(&rp->rp,
m_depthStencil != nullptr,
rhiD->effectiveSampleCount(m_sampleCount),
colorFormat))
{
delete rp;
return nullptr;
}
......
mtl: depth-stencil
mtl: buffer logic is borked
mtl: fix Dynamic for non-uniform buffers
mtl: forcing immut. to Shared should not need multiple backing buffers
mtl: textures
mtl: mrt
what's up with instance step rate
d3d: show something about adapter or such when starting up
test cubemap
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment