Skip to content

Commit

Permalink
Updated serialization of the ShaderCreateInfo struct
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Apr 19, 2024
1 parent 08fca45 commit 02fa0a0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngine/include/DeviceObjectArchive.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,7 +127,7 @@ class DeviceObjectArchive
};

static constexpr Uint32 HeaderMagicNumber = 0xDE00000A;
static constexpr Uint32 ArchiveVersion = 6;
static constexpr Uint32 ArchiveVersion = 7;

struct ArchiveHeader
{
Expand Down
3 changes: 2 additions & 1 deletion Graphics/GraphicsEngine/include/PSOSerializer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -131,5 +131,6 @@ DECL_TRIVIALLY_SERIALIZABLE(RasterizerStateDesc);
DECL_TRIVIALLY_SERIALIZABLE(DepthStencilStateDesc);
DECL_TRIVIALLY_SERIALIZABLE(SampleDesc);
DECL_TRIVIALLY_SERIALIZABLE(ShaderCreateInfo);
DECL_TRIVIALLY_SERIALIZABLE(Version);

} // namespace Diligent
13 changes: 11 additions & 2 deletions Graphics/GraphicsEngine/src/PSOSerializer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -507,10 +507,19 @@ bool ShaderSerializer<Mode>::SerializeCI(Serializer<Mode>& Ser,
CI.Desc.CombinedSamplerSuffix,
CI.EntryPoint,
CI.SourceLanguage,
CI.ShaderCompiler))
CI.ShaderCompiler,
CI.HLSLVersion,
CI.GLSLVersion,
CI.GLESSLVersion,
CI.MSLVersion,
CI.CompileFlags,
CI.LoadConstantBufferReflection,
CI.GLSLExtensions))
return false;

return SerializeBytecodeOrSource(Ser, CI);

ASSERT_SIZEOF64(ShaderCreateInfo, 144, "Did you add a new member to ShaderCreateInfo? Please add serialization here.");
}

template struct PSOSerializer<SerializerMode::Read>;
Expand Down
2 changes: 1 addition & 1 deletion Graphics/ShaderTools/src/GLSLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ String BuildGLSLSourceString(const ShaderCreateInfo& ShaderCI,

auto AppendGLSLExtensions = [&GLSLSource, &ShaderCI]() //
{
if (ShaderCI.GLSLExtensions != nullptr)
if (ShaderCI.GLSLExtensions != nullptr && ShaderCI.GLSLExtensions[0] != '\0')
{
GLSLSource.append(ShaderCI.GLSLExtensions);
GLSLSource.push_back('\n');
Expand Down
17 changes: 12 additions & 5 deletions Tests/DiligentCoreTest/src/GraphicsEngine/PSOSerializerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -701,10 +701,17 @@ TEST(PSOSerializerTest, SerializeRenderPassDesc)
void SerializeShaderCreateInfo(bool UseBytecode)
{
ShaderCreateInfo RefCI;
RefCI.Desc = {"Serialized Shader", SHADER_TYPE_COMPUTE, true, "suff"};
RefCI.EntryPoint = "Entry_Point";
RefCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
RefCI.ShaderCompiler = SHADER_COMPILER_GLSLANG;
RefCI.Desc = {"Serialized Shader", SHADER_TYPE_COMPUTE, true, "suff"};
RefCI.EntryPoint = "Entry_Point";
RefCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
RefCI.ShaderCompiler = SHADER_COMPILER_GLSLANG;
RefCI.HLSLVersion = {1, 2};
RefCI.GLSLVersion = {3, 4};
RefCI.GLESSLVersion = {5, 6};
RefCI.MSLVersion = {7, 8};
RefCI.CompileFlags = SHADER_COMPILE_FLAG_SKIP_REFLECTION;
RefCI.LoadConstantBufferReflection = true;
RefCI.GLSLExtensions = "My extension";

constexpr size_t RefBytecodeSize = 7;
const Uint8 RefBytecode[RefBytecodeSize] = {42, 13, 179, 211, 97, 65, 71};
Expand Down

0 comments on commit 02fa0a0

Please sign in to comment.