Skip to content

Commit 6abc3de

Browse files
Enabled ComputeShaderTest.FillTexturePS on WebGPU
1 parent 5e2f2e7 commit 6abc3de

File tree

2 files changed

+82
-31
lines changed

2 files changed

+82
-31
lines changed

Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ struct RenderPassDescX
277277
RenderPassDescX{static_cast<const RenderPassDesc&>(_DescX)}
278278
{}
279279

280+
explicit RenderPassDescX(const char* Name)
281+
{
282+
SetName(Name);
283+
}
284+
280285
RenderPassDescX& operator=(const RenderPassDescX& _DescX)
281286
{
282287
RenderPassDescX Copy{_DescX};
@@ -287,6 +292,13 @@ struct RenderPassDescX
287292
RenderPassDescX(RenderPassDescX&&) noexcept = default;
288293
RenderPassDescX& operator=(RenderPassDescX&&) noexcept = default;
289294

295+
RenderPassDescX& SetName(const char* Name)
296+
{
297+
m_Name = Name != nullptr ? Name : "";
298+
Desc.Name = Name != nullptr ? m_Name.c_str() : nullptr;
299+
return *this;
300+
}
301+
290302
RenderPassDescX& AddAttachment(const RenderPassAttachmentDesc& Attachment)
291303
{
292304
Attachments.push_back(Attachment);
@@ -375,6 +387,7 @@ struct RenderPassDescX
375387
}
376388

377389
RenderPassDesc Desc;
390+
std::string m_Name;
378391

379392
std::vector<RenderPassAttachmentDesc> Attachments;
380393
std::vector<SubpassDesc> Subpasses;

Tests/DiligentCoreAPITest/src/ComputeShaderTest.cpp

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +27,7 @@
2727

2828
#include "GPUTestingEnvironment.hpp"
2929
#include "TestingSwapChainBase.hpp"
30+
#include "GraphicsTypesX.hpp"
3031

3132
#include "gtest/gtest.h"
3233

@@ -65,10 +66,10 @@ void ComputeShaderReferenceWebGPU(ISwapChain* pSwapChain);
6566

6667
void ComputeShaderReference(ISwapChain* pSwapChain)
6768
{
68-
auto* pEnv = GPUTestingEnvironment::GetInstance();
69-
auto* pDevice = pEnv->GetDevice();
69+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
70+
IRenderDevice* pDevice = pEnv->GetDevice();
7071

71-
auto deviceType = pDevice->GetDeviceInfo().Type;
72+
RENDER_DEVICE_TYPE deviceType = pDevice->GetDeviceInfo().Type;
7273
switch (deviceType)
7374
{
7475
#if D3D11_SUPPORTED
@@ -130,15 +131,15 @@ namespace
130131

131132
TEST(ComputeShaderTest, FillTexture)
132133
{
133-
auto* pEnv = GPUTestingEnvironment::GetInstance();
134-
auto* pDevice = pEnv->GetDevice();
134+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
135+
IRenderDevice* pDevice = pEnv->GetDevice();
135136
if (!pDevice->GetDeviceInfo().Features.ComputeShaders)
136137
{
137138
GTEST_SKIP() << "Compute shaders are not supported by this device";
138139
}
139140

140-
auto* pSwapChain = pEnv->GetSwapChain();
141-
auto* pContext = pEnv->GetDeviceContext();
141+
ISwapChain* pSwapChain = pEnv->GetSwapChain();
142+
IDeviceContext* pContext = pEnv->GetDeviceContext();
142143

143144
GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
144145

@@ -173,7 +174,7 @@ TEST(ComputeShaderTest, FillTexture)
173174
pDevice->CreateComputePipelineState(PSOCreateInfo, &pPSO);
174175
ASSERT_NE(pPSO, nullptr);
175176

176-
const auto& SCDesc = pSwapChain->GetDesc();
177+
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
177178

178179
pPSO->GetStaticVariableByName(SHADER_TYPE_COMPUTE, "g_tex2DUAV")->Set(pTestingSwapChain->GetCurrentBackBufferUAV());
179180

@@ -195,15 +196,15 @@ TEST(ComputeShaderTest, FillTexture)
195196
// Test that GenerateMips does not mess up compute pipeline in D3D12
196197
TEST(ComputeShaderTest, GenerateMips_CSInterference)
197198
{
198-
auto* pEnv = GPUTestingEnvironment::GetInstance();
199-
auto* pDevice = pEnv->GetDevice();
199+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
200+
IRenderDevice* pDevice = pEnv->GetDevice();
200201
if (!pDevice->GetDeviceInfo().Features.ComputeShaders)
201202
{
202203
GTEST_SKIP() << "Compute shaders are not supported by this device";
203204
}
204205

205-
auto* pSwapChain = pEnv->GetSwapChain();
206-
auto* pContext = pEnv->GetDeviceContext();
206+
ISwapChain* pSwapChain = pEnv->GetSwapChain();
207+
IDeviceContext* pContext = pEnv->GetDeviceContext();
207208

208209
GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
209210

@@ -240,7 +241,7 @@ TEST(ComputeShaderTest, GenerateMips_CSInterference)
240241
pDevice->CreateComputePipelineState(PSOCreateInfo, &pPSO);
241242
ASSERT_NE(pPSO, nullptr);
242243

243-
const auto& SCDesc = pSwapChain->GetDesc();
244+
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
244245

245246
RefCntAutoPtr<ITexture> pWhiteTex;
246247
{
@@ -294,21 +295,18 @@ TEST(ComputeShaderTest, GenerateMips_CSInterference)
294295

295296
static void TestFillTexturePS(bool UseRenderPass)
296297
{
297-
auto* pEnv = GPUTestingEnvironment::GetInstance();
298-
auto* pDevice = pEnv->GetDevice();
299-
if (!pDevice->GetDeviceInfo().Features.ComputeShaders)
298+
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
299+
IRenderDevice* pDevice = pEnv->GetDevice();
300+
const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo();
301+
if (!DeviceInfo.Features.ComputeShaders)
300302
{
301303
GTEST_SKIP() << "Compute shaders are not supported by this device";
302304
}
303-
if (pDevice->GetDeviceInfo().IsWebGPUDevice())
304-
{
305-
GTEST_SKIP() << "WebGPU does not support render passes without attachments (https://github.com/gpuweb/gpuweb/issues/503)";
306-
}
307305

308-
auto* pSwapChain = pEnv->GetSwapChain();
309-
auto* pContext = pEnv->GetDeviceContext();
306+
ISwapChain* pSwapChain = pEnv->GetSwapChain();
307+
IDeviceContext* pContext = pEnv->GetDeviceContext();
310308

311-
const auto& SCDesc = pSwapChain->GetDesc();
309+
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
312310

313311
GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;
314312

@@ -318,6 +316,15 @@ static void TestFillTexturePS(bool UseRenderPass)
318316
GTEST_SKIP() << "Compute shader test requires testing swap chain";
319317
}
320318

319+
RefCntAutoPtr<ITextureView> pDummyRTV;
320+
if (DeviceInfo.IsWebGPUDevice())
321+
{
322+
// WebGPU does not support render passes without attachments (https://github.com/gpuweb/gpuweb/issues/503)
323+
RefCntAutoPtr<ITexture> pDummyTex = pEnv->CreateTexture("Dummy render target", SCDesc.ColorBufferFormat, BIND_RENDER_TARGET, SCDesc.Width, SCDesc.Height);
324+
ASSERT_TRUE(pDummyTex != nullptr);
325+
pDummyRTV = pDummyTex->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET);
326+
}
327+
321328
pContext->Flush();
322329
pContext->InvalidateState();
323330

@@ -354,25 +361,48 @@ static void TestFillTexturePS(bool UseRenderPass)
354361
RefCntAutoPtr<IFramebuffer> pFramebuffer;
355362
if (UseRenderPass)
356363
{
357-
SubpassDesc Subpass;
358-
RenderPassDesc RPDesc;
359-
RPDesc.Name = "Compute shader test - render pass";
360-
RPDesc.pSubpasses = &Subpass;
361-
RPDesc.SubpassCount = 1;
364+
RenderPassDescX RPDesc{"Compute shader test - render pass"};
365+
SubpassDescX Subpass;
366+
if (DeviceInfo.IsWebGPUDevice())
367+
{
368+
RenderPassAttachmentDesc RTAttachment;
369+
RTAttachment.Format = SCDesc.ColorBufferFormat;
370+
RTAttachment.InitialState = RESOURCE_STATE_RENDER_TARGET;
371+
RTAttachment.FinalState = RESOURCE_STATE_RENDER_TARGET;
372+
RPDesc.AddAttachment(RTAttachment);
373+
Subpass.AddRenderTarget({0, RESOURCE_STATE_RENDER_TARGET});
374+
}
375+
RPDesc.AddSubpass(Subpass);
362376
pDevice->CreateRenderPass(RPDesc, &pRenderPass);
363377
ASSERT_TRUE(pRenderPass != nullptr);
364378

365379
PSOCreateInfo.GraphicsPipeline.pRenderPass = pRenderPass;
366380

367-
FramebufferDesc FBDesc;
381+
FramebufferDescX FBDesc;
368382
FBDesc.Name = "Compute shader test - framebuffer";
369383
FBDesc.pRenderPass = pRenderPass;
370384
FBDesc.Width = SCDesc.Width;
371385
FBDesc.Height = SCDesc.Height;
372386
FBDesc.NumArraySlices = 1;
387+
if (DeviceInfo.IsWebGPUDevice())
388+
{
389+
FBDesc.AddAttachment(pDummyRTV);
390+
}
373391
pDevice->CreateFramebuffer(FBDesc, &pFramebuffer);
374392
ASSERT_TRUE(pFramebuffer != nullptr);
375393
}
394+
else
395+
{
396+
if (DeviceInfo.IsWebGPUDevice())
397+
{
398+
PSOCreateInfo.GraphicsPipeline.NumRenderTargets = 1;
399+
PSOCreateInfo.GraphicsPipeline.RTVFormats[0] = SCDesc.ColorBufferFormat;
400+
}
401+
}
402+
if (DeviceInfo.IsWebGPUDevice())
403+
{
404+
PSOCreateInfo.GraphicsPipeline.BlendDesc.RenderTargets[0].RenderTargetWriteMask = COLOR_MASK_NONE;
405+
}
376406

377407
RefCntAutoPtr<IPipelineState> pPSO;
378408
pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &pPSO);
@@ -399,7 +429,15 @@ static void TestFillTexturePS(bool UseRenderPass)
399429
}
400430
else
401431
{
402-
pContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_NONE);
432+
if (DeviceInfo.IsWebGPUDevice())
433+
{
434+
ITextureView* pDummyRTVs[] = {pDummyRTV};
435+
pContext->SetRenderTargets(1, pDummyRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
436+
}
437+
else
438+
{
439+
pContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_NONE);
440+
}
403441
}
404442

405443
Viewport VP{SCDesc};

0 commit comments

Comments
 (0)