Skip to content

Commit bfc4eba

Browse files
Added more clear render target tests
1 parent 8350e3e commit bfc4eba

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

Graphics/GraphicsEngine/include/DeviceContextBase.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,10 +1608,10 @@ inline void DeviceContextBase<ImplementationTraits>::ClearDepthStencil(ITextureV
16081608
}
16091609
else
16101610
{
1611-
LOG_WARNING_MESSAGE("Depth-stencil view '", ViewDesc.Name,
1612-
"' is not bound to the device context. "
1613-
"ClearDepthStencil command is more efficient when depth-stencil "
1614-
"view is bound to the context. In OpenGL backend this is a requirement.");
1611+
LOG_DVP_WARNING_MESSAGE("Depth-stencil view '", ViewDesc.Name,
1612+
"' is not bound to the device context. "
1613+
"ClearDepthStencil command is more efficient when depth-stencil "
1614+
"view is bound to the context. In OpenGL, Metal and WebGPU backends this is required.");
16151615
}
16161616
}
16171617
}
@@ -1654,9 +1654,9 @@ inline void DeviceContextBase<ImplementationTraits>::ClearRenderTarget(ITextureV
16541654
}
16551655
else
16561656
{
1657-
LOG_WARNING_MESSAGE("Render target view '", ViewDesc.Name,
1658-
"' is not bound to the device context. ClearRenderTarget command is more efficient "
1659-
"if render target view is bound to the device context. In OpenGL backend this is a requirement.");
1657+
LOG_DVP_WARNING_MESSAGE("Render target view '", ViewDesc.Name,
1658+
"' is not bound to the device context. ClearRenderTarget command is more efficient "
1659+
"if render target view is bound to the device context. In OpenGL, Metal and WebGPU backends this is required.");
16601660
}
16611661
}
16621662
}

Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const void* RGB
13251325
ClearRect.baseArrayLayer = 0;
13261326
ClearRect.layerCount = ViewDesc.NumArraySlices;
13271327
// No memory barriers are needed between vkCmdClearAttachments and preceding or
1328-
// subsequent draw or attachment clear commands in the same subpass (17.2)
1328+
// subsequent draw or attachment clear commands in the same subpass
13291329
m_CommandBuffer.ClearAttachment(ClearAttachment, ClearRect);
13301330
}
13311331
}
@@ -1339,7 +1339,7 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const void* RGB
13391339
ITexture* pTexture = pVkRTV->GetTexture();
13401340
TextureVkImpl* pTextureVk = ClassPtrCast<TextureVkImpl>(pTexture);
13411341

1342-
// Image layout must be VK_IMAGE_LAYOUT_GENERAL or VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL (17.1)
1342+
// Image layout must be VK_IMAGE_LAYOUT_GENERAL or VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
13431343
TransitionOrVerifyTextureState(*pTextureVk, StateTransitionMode, RESOURCE_STATE_COPY_DEST, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
13441344
"Clearing render target outside of render pass (DeviceContextVkImpl::ClearRenderTarget)");
13451345

Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ TEST(ClearRenderTargetTest, AsRenderTarget)
163163
}
164164

165165

166+
TEST(ClearRenderTargetTest, AsUnboundRenderTarget)
167+
{
168+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
169+
IRenderDevice* pDevice = pEnv->GetDevice();
170+
const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo();
171+
if (!(DeviceInfo.IsD3DDevice() || DeviceInfo.IsVulkanDevice()))
172+
{
173+
GTEST_SKIP() << "Clearing unbound render target is only supported in Direct3D and Vulkan";
174+
}
175+
176+
ISwapChain* pSwapChain = pEnv->GetSwapChain();
177+
IDeviceContext* pContext = pEnv->GetDeviceContext();
178+
179+
GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
180+
181+
constexpr float ClearColor[] = {0.25f, 0.5f, 0.75f, 1.0f};
182+
ReferenceClear(ClearColor);
183+
184+
pContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
185+
pContext->ClearRenderTarget(pSwapChain->GetCurrentBackBufferRTV(), ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
186+
187+
pSwapChain->Present();
188+
189+
TestSwapChainCInterface(pSwapChain);
190+
}
191+
192+
193+
166194
TEST(ClearRenderTargetTest, ClearAfterClear)
167195
{
168196
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
@@ -184,6 +212,46 @@ TEST(ClearRenderTargetTest, ClearAfterClear)
184212
}
185213

186214

215+
216+
TEST(ClearRenderTargetTest, UnboundClearAfterClear)
217+
{
218+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
219+
IRenderDevice* pDevice = pEnv->GetDevice();
220+
const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo();
221+
if (!(DeviceInfo.IsD3DDevice() || DeviceInfo.IsVulkanDevice()))
222+
{
223+
GTEST_SKIP() << "Clearing unbound render target is only supported in Direct3D and Vulkan";
224+
}
225+
226+
ISwapChain* pSwapChain = pEnv->GetSwapChain();
227+
IDeviceContext* pContext = pEnv->GetDeviceContext();
228+
229+
GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
230+
231+
constexpr float ClearColor0[] = {0.125f, 0.5f, 0.75f, 1.0f};
232+
constexpr float ClearColor1[] = {0.25f, 0.75f, 0.875f, 1.0f};
233+
ReferenceClear(ClearColor0);
234+
235+
ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()};
236+
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
237+
pContext->ClearRenderTarget(pRTVs[0], ClearColor0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
238+
239+
TextureDesc TexDesc;
240+
TexDesc.Name = "ClearRenderTargetTest.UnboundClearAfterClear";
241+
TexDesc.Type = RESOURCE_DIM_TEX_2D;
242+
TexDesc.Width = 512;
243+
TexDesc.Height = 512;
244+
TexDesc.Format = TEX_FORMAT_RGBA8_UNORM;
245+
TexDesc.BindFlags = BIND_RENDER_TARGET;
246+
RefCntAutoPtr<ITexture> pTex;
247+
pEnv->GetDevice()->CreateTexture(TexDesc, nullptr, &pTex);
248+
ASSERT_NE(pTex, nullptr);
249+
pContext->ClearRenderTarget(pTex->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET), ClearColor1, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
250+
251+
pSwapChain->Present();
252+
}
253+
254+
187255
TEST(ClearRenderTargetTest, ResetRTsAfterClear)
188256
{
189257
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();

0 commit comments

Comments
 (0)