From 3e0763077a5ce420f42606418917ab7d87b6b763 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 1 Jul 2016 12:58:33 +0200 Subject: D3D12: Fix the rendernode example for multisampling Show how this can be handled in the custom QSGRenderNode implementation. Change-Id: Id6f18ca568a4850060f957998532815bce5c4ac5 Reviewed-by: Andy Nichols --- examples/quick/scenegraph/rendernode/d3d12renderer.cpp | 15 ++++++++++++++- examples/quick/scenegraph/rendernode/main.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp index bc03720407..b7dc62fe86 100644 --- a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp +++ b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp @@ -153,7 +153,20 @@ void D3D12RenderNode::init() psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT; // not in use due to !DepthEnable, but this would be the correct format otherwise - psoDesc.SampleDesc.Count = 1; + // We are rendering on the default render target so if the QuickWindow/View + // has requested samples > 0 then we have to follow suit. + const uint samples = qMax(1, m_item->window()->format().samples()); + psoDesc.SampleDesc.Count = samples; + if (samples > 1) { + D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaInfo = {}; + msaaInfo.Format = psoDesc.RTVFormats[0]; + msaaInfo.SampleCount = samples; + if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaInfo, sizeof(msaaInfo)))) { + if (msaaInfo.NumQualityLevels > 0) + psoDesc.SampleDesc.Quality = msaaInfo.NumQualityLevels - 1; + } + } + if (FAILED(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)))) { qWarning("Failed to create graphics pipeline state"); return; diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp index 9128cdc5be..3e1714313e 100644 --- a/examples/quick/scenegraph/rendernode/main.cpp +++ b/examples/quick/scenegraph/rendernode/main.cpp @@ -49,6 +49,13 @@ int main(int argc, char **argv) qmlRegisterType("SceneGraphRendering", 2, 0, "CustomRenderItem"); QQuickView view; + + if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) { + QSurfaceFormat fmt; + fmt.setSamples(4); + view.setFormat(fmt); + } + view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/rendernode/main.qml")); view.resize(1024, 768); -- cgit v1.2.3