Skip to content

Commit 98fc4cd

Browse files
Render state cache: added test for pipeline reload
1 parent e7060d8 commit 98fc4cd

File tree

7 files changed

+120
-5
lines changed

7 files changed

+120
-5
lines changed

Graphics/Archiver/src/ArchiverFactory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ void ArchiverFactoryImpl::CreateSerializationDevice(const SerializationDeviceCre
195195

196196
void ArchiverFactoryImpl::CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories, struct IShaderSourceInputStreamFactory** ppShaderSourceFactory) const
197197
{
198-
DEV_CHECK_ERR(ppShaderSourceFactory != nullptr, "ppShaderSourceFactory must not be null");
198+
DEV_CHECK_ERR(ppShaderSourceFactory != nullptr, "ppShaderSourceFactory must not be null.");
199+
DEV_CHECK_ERR(*ppShaderSourceFactory == nullptr, "*ppShaderSourceFactory is not null. Make sure the pointer is null to avoid memory leaks.");
199200
if (!ppShaderSourceFactory)
200201
return;
201202

Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ void DefaultShaderSourceStreamFactory::CreateInputStream2(const Char*
123123
void CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories,
124124
IShaderSourceInputStreamFactory** ppShaderSourceStreamFactory)
125125
{
126+
DEV_CHECK_ERR(ppShaderSourceStreamFactory != nullptr, "ppShaderSourceStreamFactory must not be null.");
127+
DEV_CHECK_ERR(*ppShaderSourceStreamFactory == nullptr, "*ppShaderSourceStreamFactory is not null. Make sure the pointer is null to avoid memory leaks.");
126128

127-
auto& Allocator = GetRawAllocator();
128-
DefaultShaderSourceStreamFactory* pStreamFactory =
129+
auto& Allocator = GetRawAllocator();
130+
auto* pStreamFactory =
129131
NEW_RC_OBJ(Allocator, "DefaultShaderSourceStreamFactory instance", DefaultShaderSourceStreamFactory)(SearchDirectories);
130132
pStreamFactory->QueryInterface(IID_IShaderSourceInputStreamFactory, reinterpret_cast<IObject**>(ppShaderSourceStreamFactory));
131133
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "GraphicsCommon.h"
2+
3+
float4 main(in PSInput PSIn) : SV_Target
4+
{
5+
return float4(0.0, 0.0, 0.0, PSIn.Color.r);
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "GraphicsCommon.h"
2+
3+
float4 main(in PSInput PSIn) : SV_Target
4+
{
5+
return float4(PSIn.Color.rgb, 1.0);
6+
// NB: no new line at the end of file!
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "GraphicsCommon.h"
2+
3+
#if INTERNAL_MACROS == 1 && EXTERNAL_MACROS == 2
4+
void main(in uint VertId : SV_VertexID,
5+
out PSInput PSIn)
6+
{
7+
float4 Pos[6];
8+
Pos[0] = float4(-1.0, -0.5, 0.0, 1.0);
9+
Pos[1] = float4(-0.5, +0.5, 0.0, 1.0);
10+
Pos[2] = float4( 0.0, -0.5, 0.0, 1.0);
11+
12+
Pos[3] = float4(+0.0, -0.5, 0.0, 1.0);
13+
Pos[4] = float4(+0.5, +0.5, 0.0, 1.0);
14+
Pos[5] = float4(+1.0, -0.5, 0.0, 1.0);
15+
16+
float3 Col[6];
17+
Col[0] = float3(1.0, 0.0, 0.0);
18+
Col[1] = float3(0.0, 1.0, 0.0);
19+
Col[2] = float3(0.0, 0.0, 1.0);
20+
21+
Col[3] = float3(1.0, 0.0, 0.0);
22+
Col[4] = float3(0.0, 1.0, 0.0);
23+
Col[5] = float3(0.0, 0.0, 1.0);
24+
25+
PSIn.Pos = Pos[VertId];
26+
PSIn.Color = Col[VertId];
27+
}
28+
// NB: no new line at the end of file!
29+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "GraphicsCommon.h"
2+
3+
#if INTERNAL_MACROS == 1 && EXTERNAL_MACROS == 2
4+
void main(in uint VertId : SV_VertexID,
5+
out PSInput PSIn)
6+
{
7+
PSIn.Pos = float4(0.0, 0.0, 0.0, 0.0);
8+
PSIn.Color = float3(0.0, 0.0, 0.0);
9+
}
10+
// NB: no new line at the end of file!
11+
#endif

Tests/DiligentCoreAPITest/src/RenderStateCacheTest.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ void VerifyComputePSO(IPipelineState* pPSO, bool UseSignature = false)
183183
pSwapChain->Present();
184184
}
185185

186-
RefCntAutoPtr<IRenderStateCache> CreateCache(IRenderDevice* pDevice, bool HotReload, IDataBlob* pCacheData = nullptr)
186+
RefCntAutoPtr<IRenderStateCache> CreateCache(IRenderDevice* pDevice,
187+
bool HotReload,
188+
IDataBlob* pCacheData = nullptr,
189+
IShaderSourceInputStreamFactory* pShaderReloadFactory = nullptr)
187190
{
188-
RenderStateCacheCreateInfo CacheCI{pDevice, true, HotReload};
191+
RenderStateCacheCreateInfo CacheCI{pDevice, true, HotReload, pShaderReloadFactory};
189192

190193
RefCntAutoPtr<IRenderStateCache> pCache;
191194
CreateRenderStateCache(CacheCI, &pCache);
@@ -885,4 +888,60 @@ TEST(RenderStateCacheTest, RenderDeviceWithCache)
885888
}
886889
}
887890

891+
892+
void TestPipelineReload(bool UseRenderPass)
893+
{
894+
auto* pEnv = GPUTestingEnvironment::GetInstance();
895+
auto* pDevice = pEnv->GetDevice();
896+
897+
GPUTestingEnvironment::ScopedReset AutoReset;
898+
899+
RefCntAutoPtr<IShaderSourceInputStreamFactory> pShaderSourceFactory;
900+
pDevice->GetEngineFactory()->CreateDefaultShaderSourceStreamFactory("shaders/RenderStateCache", &pShaderSourceFactory);
901+
ASSERT_TRUE(pShaderSourceFactory);
902+
903+
RefCntAutoPtr<IShaderSourceInputStreamFactory> pShaderReloadFactory;
904+
pDevice->GetEngineFactory()->CreateDefaultShaderSourceStreamFactory("shaders/RenderStateCache/Reload;shaders/RenderStateCache", &pShaderReloadFactory);
905+
ASSERT_TRUE(pShaderSourceFactory);
906+
907+
constexpr auto HotReload = true;
908+
909+
RefCntAutoPtr<IDataBlob> pData;
910+
for (Uint32 pass = 0; pass < 3; ++pass)
911+
{
912+
// 0: empty cache
913+
// 1: loaded cache
914+
// 2: reloaded cache (loaded -> stored -> loaded)
915+
916+
auto pCache = CreateCache(pDevice, HotReload, pData, pShaderReloadFactory);
917+
ASSERT_TRUE(pCache);
918+
919+
RefCntAutoPtr<IShader> pVS, pPS;
920+
CreateGraphicsShaders(pCache, pShaderSourceFactory, pVS, pPS, pData != nullptr, "VertexShaderRld.vsh", "PixelShaderRld.psh");
921+
ASSERT_NE(pVS, nullptr);
922+
ASSERT_NE(pPS, nullptr);
923+
924+
RefCntAutoPtr<IPipelineState> pPSO;
925+
CreateGraphicsPSO(pCache, pData != nullptr, pVS, pPS, UseRenderPass, &pPSO);
926+
ASSERT_NE(pPSO, nullptr);
927+
928+
EXPECT_EQ(pCache->Reload(), pass == 0 ? 3u : 0u);
929+
930+
VerifyGraphicsPSO(pPSO, UseRenderPass);
931+
932+
pData.Release();
933+
pCache->WriteToBlob(&pData);
934+
}
935+
}
936+
937+
TEST(RenderStateCacheTest, Reload)
938+
{
939+
TestPipelineReload(/*UseRenderPass = */ false);
940+
}
941+
942+
TEST(RenderStateCacheTest, Reload_RenderPass)
943+
{
944+
TestPipelineReload(/*UseRenderPass = */ true);
945+
}
946+
888947
} // namespace

0 commit comments

Comments
 (0)