@@ -376,9 +376,7 @@ TEST(ClearRenderTargetTest, AsAttachment)
376376 pSwapChain->Present ();
377377}
378378
379-
380-
381- TEST (ClearRenderTargetTest, LoadOpClear)
379+ void TestClearWithLoadOp (const float4& ClearColor, Uint32 Subpass)
382380{
383381 GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance ();
384382 IRenderDevice* pDevice = pEnv->GetDevice ();
@@ -387,43 +385,72 @@ TEST(ClearRenderTargetTest, LoadOpClear)
387385
388386 GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
389387
390- constexpr float ClearColor[] = {0 .875f , 0.3125 , 0.4375 , 1 .0f };
391- ReferenceClear (ClearColor);
388+ ReferenceClear (ClearColor.Data ());
392389
393- RenderPassAttachmentDesc Attachments[1 ];
394- ITextureView* pRTV = pSwapChain->GetCurrentBackBufferRTV ();
390+ ITextureView* pRTV = pSwapChain->GetCurrentBackBufferRTV ();
395391 ASSERT_NE (pRTV, nullptr );
396392 const TextureDesc& BackBufferDesc = pRTV->GetTexture ()->GetDesc ();
397- Attachments[0 ].Format = BackBufferDesc.Format ;
398- Attachments[0 ].SampleCount = static_cast <Uint8>(BackBufferDesc.SampleCount );
399- Attachments[0 ].InitialState = RESOURCE_STATE_RENDER_TARGET;
400- Attachments[0 ].FinalState = RESOURCE_STATE_RENDER_TARGET;
401- Attachments[0 ].LoadOp = ATTACHMENT_LOAD_OP_CLEAR;
402- Attachments[0 ].StoreOp = ATTACHMENT_STORE_OP_STORE;
403393
404- SubpassDesc Subpasses[1 ] = {};
394+ // One attachment per subpass
395+ const Uint32 NumAttachments = Subpass + 1 ;
396+ const Uint32 NumSubpasses = Subpass + 1 ;
405397
406- Subpasses[0 ].RenderTargetAttachmentCount = 1 ;
407- AttachmentReference RTAttachmentRef{0 , RESOURCE_STATE_RENDER_TARGET};
408- Subpasses[0 ].pRenderTargetAttachments = &RTAttachmentRef;
398+ std::vector<RenderPassAttachmentDesc> Attachments (NumAttachments);
399+ std::vector<RefCntAutoPtr<ITextureView>> pRTVs (NumAttachments);
400+ for (Uint32 i = 0 ; i < NumAttachments; ++i)
401+ {
402+ if (i == Subpass)
403+ {
404+ pRTVs[i] = pSwapChain->GetCurrentBackBufferRTV ();
405+ }
406+ else
407+ {
408+ TextureDesc TexDesc = BackBufferDesc;
409+ TexDesc.Name = " Load op clear test texture" ;
410+ RefCntAutoPtr<ITexture> pTex = pEnv->CreateTexture (TexDesc);
411+ ASSERT_NE (pTex, nullptr );
412+ pRTVs[i] = pTex->GetDefaultView (TEXTURE_VIEW_RENDER_TARGET);
413+ }
414+
415+ Attachments[i].Format = BackBufferDesc.Format ;
416+ Attachments[i].SampleCount = static_cast <Uint8>(BackBufferDesc.SampleCount );
417+ Attachments[i].InitialState = RESOURCE_STATE_RENDER_TARGET;
418+ Attachments[i].FinalState = RESOURCE_STATE_RENDER_TARGET;
419+ Attachments[i].LoadOp = ATTACHMENT_LOAD_OP_CLEAR;
420+ Attachments[i].StoreOp = ATTACHMENT_STORE_OP_STORE;
421+ }
422+
423+ std::vector<SubpassDesc> Subpasses (NumSubpasses);
424+ std::vector<AttachmentReference> RTAttachmentRefs (NumSubpasses);
425+ for (Uint32 i = 0 ; i < NumSubpasses; ++i)
426+ {
427+ RTAttachmentRefs[i] = {i, RESOURCE_STATE_RENDER_TARGET};
428+
429+ Subpasses[i].RenderTargetAttachmentCount = 1 ;
430+ Subpasses[i].pRenderTargetAttachments = &RTAttachmentRefs[i];
431+ }
409432
410433 RenderPassDesc RPDesc;
411434 RPDesc.Name = " Load op clear test render pass" ;
412- RPDesc.AttachmentCount = _countof (Attachments) ;
413- RPDesc.pAttachments = Attachments;
414- RPDesc.SubpassCount = _countof (Subpasses) ;
415- RPDesc.pSubpasses = Subpasses;
435+ RPDesc.AttachmentCount = NumAttachments ;
436+ RPDesc.pAttachments = Attachments. data () ;
437+ RPDesc.SubpassCount = NumSubpasses ;
438+ RPDesc.pSubpasses = Subpasses. data () ;
416439
417440 RefCntAutoPtr<IRenderPass> pRenderPass;
418441 pDevice->CreateRenderPass (RPDesc, &pRenderPass);
419442 ASSERT_NE (pRenderPass, nullptr );
420443
421444 FramebufferDesc FBDesc;
422- FBDesc.Name = " Load op clear test framebuffer" ;
423- FBDesc.pRenderPass = pRenderPass;
424- FBDesc.AttachmentCount = _countof (Attachments);
425- ITextureView* pTexViews[] = {pRTV};
426- FBDesc.ppAttachments = pTexViews;
445+ FBDesc.Name = " Load op clear test framebuffer" ;
446+ FBDesc.pRenderPass = pRenderPass;
447+ FBDesc.AttachmentCount = RPDesc.AttachmentCount ;
448+
449+ std::vector<ITextureView*> pTexViews (pRTVs.size ());
450+ for (Uint32 i = 0 ; i < pTexViews.size (); ++i)
451+ pTexViews[i] = pRTVs[i];
452+
453+ FBDesc.ppAttachments = pTexViews.data ();
427454 RefCntAutoPtr<IFramebuffer> pFramebuffer;
428455 pDevice->CreateFramebuffer (FBDesc, &pFramebuffer);
429456 ASSERT_TRUE (pFramebuffer);
@@ -432,20 +459,36 @@ TEST(ClearRenderTargetTest, LoadOpClear)
432459 BeginRPInfo.pRenderPass = pRenderPass;
433460 BeginRPInfo.pFramebuffer = pFramebuffer;
434461 BeginRPInfo.StateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION;
435- OptimizedClearValue ClearValue;
436- ClearValue.Color [0 ] = ClearColor[0 ];
437- ClearValue.Color [1 ] = ClearColor[1 ];
438- ClearValue.Color [2 ] = ClearColor[2 ];
439- ClearValue.Color [3 ] = ClearColor[3 ];
462+ std::vector< OptimizedClearValue> ClearValue (NumAttachments) ;
463+ ClearValue[Subpass] .Color [0 ] = ClearColor[0 ];
464+ ClearValue[Subpass] .Color [1 ] = ClearColor[1 ];
465+ ClearValue[Subpass] .Color [2 ] = ClearColor[2 ];
466+ ClearValue[Subpass] .Color [3 ] = ClearColor[3 ];
440467
441- BeginRPInfo.ClearValueCount = 1 ;
442- BeginRPInfo.pClearValues = & ClearValue;
468+ BeginRPInfo.ClearValueCount = NumAttachments ;
469+ BeginRPInfo.pClearValues = ClearValue. data () ;
443470
444471 pContext->BeginRenderPass (BeginRPInfo);
445472
473+ for (Uint32 i = 1 ; i <= Subpass; ++i)
474+ {
475+ pContext->NextSubpass ();
476+ }
477+
446478 pContext->EndRenderPass ();
447479
448480 pSwapChain->Present ();
449481}
450482
483+
484+ TEST (ClearRenderTargetTest, LoadOpClear)
485+ {
486+ TestClearWithLoadOp ({0 .875f , 0.3125 , 0.4375 , 1 .0f }, 0 );
487+ }
488+
489+ TEST (ClearRenderTargetTest, LoadOpClear2)
490+ {
491+ TestClearWithLoadOp ({0 .375f , 0.75 , 0.125 , 1 .0f }, 2 );
492+ }
493+
451494} // namespace
0 commit comments