@@ -188,8 +188,38 @@ namespace Falcor
188188 }
189189 }
190190 }
191+ ID3D12GraphicsCommandList* pCmdList = pCtx->getLowLevelData ()->getCommandList ().GetInterfacePtr ();
192+ pCmdList->OMSetRenderTargets (colorTargets, pRTV.data (), FALSE , &pDSV);
193+ }
194+
195+ static void D3D12SetSamplePositions (ID3D12GraphicsCommandList* pList, const Fbo* pFbo)
196+ {
197+ if (!pFbo) return ;
198+ ID3D12GraphicsCommandList1* pList1;
199+ pList->QueryInterface (IID_PPV_ARGS (&pList1));
200+ const auto & samplePos = pFbo->getSamplePositions ();
201+
202+ if (!pList1)
203+ {
204+ if (samplePos.size ())
205+ {
206+ logError (" The FBO specifies programmable sample positions, but the hardware doesn't support it" );
207+ }
208+ }
209+ else
210+ {
211+ static_assert (offsetof (Fbo::SamplePosition, xOffset) == offsetof (D3D12_SAMPLE_POSITION, X), " SamplePosition.X" );
212+ static_assert (offsetof (Fbo::SamplePosition, yOffset) == offsetof (D3D12_SAMPLE_POSITION, Y), " SamplePosition.Y" );
191213
192- pCtx->getLowLevelData ()->getCommandList ()->OMSetRenderTargets (colorTargets, pRTV.data (), FALSE , &pDSV);
214+ if (samplePos.size ())
215+ {
216+ pList1->SetSamplePositions (pFbo->getSampleCount (), pFbo->getSamplePositionsPixelCount (), (D3D12_SAMPLE_POSITION*)samplePos.data ());
217+ }
218+ else
219+ {
220+ pList1->SetSamplePositions (0 , 0 , nullptr );
221+ }
222+ }
193223 }
194224
195225 static void D3D12SetViewports (ID3D12GraphicsCommandList* pList, const GraphicsState::Viewport* vp)
@@ -258,6 +288,10 @@ namespace Falcor
258288 {
259289 D3D12SetFbo (this , mpGraphicsState->getFbo ().get ());
260290 }
291+ if (is_set (StateBindFlags::SamplePositions, mBindFlags ))
292+ {
293+ D3D12SetSamplePositions (pList, mpGraphicsState->getFbo ().get ());
294+ }
261295 if (is_set (StateBindFlags::Viewports, mBindFlags ))
262296 {
263297 D3D12SetViewports (pList, &mpGraphicsState->getViewport (0 ));
@@ -270,6 +304,13 @@ namespace Falcor
270304 {
271305 pList->SetPipelineState (mpGraphicsState->getGSO (mpGraphicsVars.get ())->getApiHandle ());
272306 }
307+ if (is_set (StateBindFlags::SamplePositions, mBindFlags ))
308+ {
309+ if (mpGraphicsState->getFbo () && mpGraphicsState->getFbo ()->getSamplePositions ().size ())
310+ {
311+ logWarning (" The Vulkan backend doesn't support programmable sample positions" );
312+ }
313+ }
273314
274315 BlendState::SharedPtr blendState = mpGraphicsState->getBlendState ();
275316 if (blendState != nullptr )
@@ -419,4 +460,31 @@ namespace Falcor
419460 popGraphicsState ();
420461 popGraphicsVars ();
421462 }
463+
464+ void RenderContext::resolveSubresource (const Texture* pSrc, uint32_t srcSubresource, const Texture* pDst, uint32_t dstSubresource)
465+ {
466+ DXGI_FORMAT format = getDxgiFormat (pDst->getFormat ());
467+ mpLowLevelData->getCommandList ()->ResolveSubresource (pDst->getApiHandle (), dstSubresource, pSrc->getApiHandle (), srcSubresource, format);
468+ mCommandsPending = true ;
469+ }
470+
471+ void RenderContext::resolveResource (const Texture* pSrc, const Texture* pDst)
472+ {
473+ bool match = true ;
474+ match = match && (pSrc->getMipCount () == pDst->getMipCount ());
475+ match = match && (pSrc->getArraySize () == pDst->getArraySize ());
476+ if (!match)
477+ {
478+ logWarning (" Can't resolve a resource. The src and dst textures have a different array-size or mip-count" );
479+ }
480+
481+ resourceBarrier (pSrc, Resource::State::ResolveSource);
482+ resourceBarrier (pDst, Resource::State::ResolveDest);
483+
484+ uint32_t subresourceCount = pSrc->getMipCount () * pSrc->getArraySize ();
485+ for (uint32_t s = 0 ; s < subresourceCount; s++)
486+ {
487+ resolveSubresource (pSrc, s, pDst, s);
488+ }
489+ }
422490}
0 commit comments