Skip to content

Commit 4806d47

Browse files
Archiver: allow adding serialized shaders in compiling state to the archive
1 parent 0aab310 commit 4806d47

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

Graphics/Archiver/src/ArchiverImpl.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -169,7 +169,17 @@ Bool ArchiverImpl::SerializeToBlob(Uint32 ContentVersion, IDataBlob** ppBlob)
169169
for (const auto& shader_it : m_Shaders)
170170
{
171171
const auto* Name = shader_it.first.GetStr();
172-
const auto& SrcShader = *shader_it.second;
172+
auto& SrcShader = *shader_it.second;
173+
{
174+
const SHADER_STATUS Status = SrcShader.GetStatus(/*WaitForCompletion = */ false);
175+
if (Status != SHADER_STATUS_READY)
176+
{
177+
LOG_ERROR_MESSAGE("Shader '", Name, "' is in ", GetShaderStatusString(Status),
178+
" state and cannot be serialized. Only ready shaders can be serialized."
179+
" Use GetStatus() to check the shader status before calling SerializeToBlob().");
180+
continue;
181+
}
182+
}
173183
VERIFY_EXPR(SafeStrEqual(Name, SrcShader.GetDesc().Name));
174184

175185
auto& DstData = Archive.GetResourceData(ResourceType::StandaloneShader, Name);
@@ -262,13 +272,6 @@ Bool ArchiverImpl::AddShader(IShader* pShader)
262272
if (pShader == nullptr)
263273
return false;
264274

265-
const SHADER_STATUS Status = pShader->GetStatus();
266-
if (Status != SHADER_STATUS_READY)
267-
{
268-
LOG_ERROR_MESSAGE("Shader '", pShader->GetDesc().Name, "' is not ready. Only ready shaders can be added to the archive. Use GetStatus() to check the shader status.");
269-
return False;
270-
}
271-
272275
return AddObjectToArchive<SerializedShaderImpl>(pShader, "Shader", IID_SerializedShader, m_ShadersMtx, m_Shaders);
273276
}
274277

Tests/DiligentCoreAPITest/src/ArchiveTest.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,38 +1251,6 @@ void ArchiveGraphicsShaders(bool CompileAsync)
12511251
CreateGraphicsShaders(pDevice, pSerializationDevice, VertexShaderCI, nullptr, &pSerializedVS, PixelShaderCI, nullptr, &pSerializedPS);
12521252
CreateGraphicsShaders(pDevice, pSerializationDevice, VertexShaderCI, nullptr, &pSerializedVS2, PixelShaderCI, nullptr, &pSerializedPS2);
12531253

1254-
if (CompileAsync)
1255-
{
1256-
Timer T;
1257-
auto StartTime = T.GetElapsedTime();
1258-
1259-
SHADER_STATUS OverallStatus = SHADER_STATUS_UNINITIALIZED;
1260-
while (true)
1261-
{
1262-
OverallStatus = SHADER_STATUS_READY;
1263-
1264-
Uint32 NumShadersReady = 0;
1265-
for (auto& pShader : {pSerializedVS, pSerializedVS2, pSerializedPS, pSerializedPS2})
1266-
{
1267-
SHADER_STATUS Status = pShader->GetStatus();
1268-
if (Status == SHADER_STATUS_READY)
1269-
++NumShadersReady;
1270-
else if (Status == SHADER_STATUS_FAILED)
1271-
{
1272-
OverallStatus = SHADER_STATUS_FAILED;
1273-
break;
1274-
}
1275-
}
1276-
if (NumShadersReady == 4 || OverallStatus == SHADER_STATUS_FAILED)
1277-
break;
1278-
std::this_thread::yield();
1279-
std::this_thread::sleep_for(std::chrono::milliseconds{10});
1280-
}
1281-
ASSERT_EQ(OverallStatus, SHADER_STATUS_READY);
1282-
1283-
LOG_INFO_MESSAGE("Shaders were compiled asynchronously in ", (T.GetElapsedTime() - StartTime) * 1000, " ms");
1284-
}
1285-
12861254
EXPECT_TRUE(pArchiver->AddShader(pSerializedVS));
12871255
EXPECT_TRUE(pArchiver->AddShader(pSerializedPS));
12881256
EXPECT_TRUE(pArchiver->AddShader(pSerializedVS));

0 commit comments

Comments
 (0)