Skip to content

Commit 5f7a014

Browse files
Added SerializationDeviceGLInfo struct (API254005)
1 parent b03810c commit 5f7a014

7 files changed

Lines changed: 71 additions & 23 deletions

File tree

Graphics/Archiver/include/SerializationDeviceImpl.hpp

Lines changed: 8 additions & 1 deletion
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.
@@ -143,6 +143,11 @@ class SerializationDeviceImpl final : public RenderDeviceBase<SerializationEngin
143143
Version ShaderVersion;
144144
};
145145

146+
struct GLProperties
147+
{
148+
bool ValidateShaders = false;
149+
};
150+
146151
struct VkProperties
147152
{
148153
IDXCompiler* pDxCompiler = nullptr;
@@ -162,6 +167,7 @@ class SerializationDeviceImpl final : public RenderDeviceBase<SerializationEngin
162167

163168
const D3D11Properties& GetD3D11Properties() const { return m_D3D11Props; }
164169
const D3D12Properties& GetD3D12Properties() const { return m_D3D12Props; }
170+
const GLProperties& GetGLProperties() const { return m_GLProps; }
165171
const VkProperties& GetVkProperties() const { return m_VkProps; }
166172
const MtlProperties& GetMtlProperties() const { return m_MtlProps; }
167173

@@ -198,6 +204,7 @@ class SerializationDeviceImpl final : public RenderDeviceBase<SerializationEngin
198204

199205
D3D11Properties m_D3D11Props;
200206
D3D12Properties m_D3D12Props;
207+
GLProperties m_GLProps;
201208
VkProperties m_VkProps;
202209
MtlProperties m_MtlProps;
203210

Graphics/Archiver/interface/ArchiverFactory.h

Lines changed: 31 additions & 1 deletion
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.
@@ -95,6 +95,33 @@ struct SerializationDeviceD3D12Info
9595
typedef struct SerializationDeviceD3D12Info SerializationDeviceD3D12Info;
9696

9797

98+
/// Serialization device attributes for OpenGL backend
99+
struct SerializationDeviceGLInfo
100+
{
101+
/// Whether to validate OpenGL shaders.
102+
103+
/// \remarks In OpenGL backend, shaders are converted from HLSL to GLSL
104+
/// (if necessary) and packed into an archive as source code.
105+
/// When this flag is set to True, the archiver will compile
106+
/// the source code to validate it is correct.
107+
/// This may be time-consuming and could be disabled to speed up
108+
/// the archiving process.
109+
Bool ValidateShaders DEFAULT_INITIALIZER(True);
110+
111+
#if DILIGENT_CPP_INTERFACE
112+
bool operator==(const SerializationDeviceGLInfo& RHS) const noexcept
113+
{
114+
return ValidateShaders == RHS.ValidateShaders;
115+
}
116+
bool operator!=(const SerializationDeviceGLInfo& RHS) const noexcept
117+
{
118+
return !(*this == RHS);
119+
}
120+
#endif
121+
};
122+
typedef struct SerializationDeviceGLInfo SerializationDeviceGLInfo;
123+
124+
98125
/// Serialization device attributes for Vulkan backend
99126
struct SerializationDeviceVkInfo
100127
{
@@ -176,6 +203,9 @@ struct SerializationDeviceCreateInfo
176203
/// Direct3D12 attributes, see Diligent::SerializationDeviceD3D12Info.
177204
SerializationDeviceD3D12Info D3D12;
178205

206+
/// OpenGL attributes, see Diligent::SerializationDeviceGLInfo.
207+
SerializationDeviceGLInfo GL;
208+
179209
/// Vulkan attributes, see Diligent::SerializationDeviceVkInfo.
180210
SerializationDeviceVkInfo Vulkan;
181211

Graphics/Archiver/src/Archiver_GL.cpp

Lines changed: 20 additions & 17 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.
@@ -239,27 +239,30 @@ void SerializedShaderImpl::CreateShaderGL(IReferenceCounters* pRefCounters,
239239
CreateShader<CompiledShaderGL>(DeviceType::OpenGL, pRefCounters, ShaderCI, GLShaderCI, m_pDevice->GetRenderDevice(RENDER_DEVICE_TYPE_GL));
240240

241241
#if !DILIGENT_NO_GLSLANG
242-
const auto* pCompiledShaderGL = GetShader<CompiledShaderGL>(DeviceObjectArchive::DeviceType::OpenGL);
243-
VERIFY_EXPR(pCompiledShaderGL != nullptr);
242+
if (m_pDevice->GetGLProperties().ValidateShaders)
243+
{
244+
const auto* pCompiledShaderGL = GetShader<CompiledShaderGL>(DeviceObjectArchive::DeviceType::OpenGL);
245+
VERIFY_EXPR(pCompiledShaderGL != nullptr);
244246

245-
const void* Source = nullptr;
246-
Uint64 SourceLen = 0;
247-
// For OpenGL, GetBytecode returns the full GLSL source
248-
pCompiledShaderGL->pShaderGL->GetBytecode(&Source, SourceLen);
249-
VERIFY_EXPR(Source != nullptr && SourceLen != 0);
247+
const void* Source = nullptr;
248+
Uint64 SourceLen = 0;
249+
// For OpenGL, GetBytecode returns the full GLSL source
250+
pCompiledShaderGL->pShaderGL->GetBytecode(&Source, SourceLen);
251+
VERIFY_EXPR(Source != nullptr && SourceLen != 0);
250252

251-
GLSLangUtils::GLSLtoSPIRVAttribs Attribs;
253+
GLSLangUtils::GLSLtoSPIRVAttribs Attribs;
252254

253-
Attribs.ShaderType = ShaderCI.Desc.ShaderType;
254-
VERIFY_EXPR(DeviceType == RENDER_DEVICE_TYPE_GL || DeviceType == RENDER_DEVICE_TYPE_GLES);
255-
Attribs.Version = DeviceType == RENDER_DEVICE_TYPE_GL ? GLSLangUtils::SpirvVersion::GL : GLSLangUtils::SpirvVersion::GLES;
255+
Attribs.ShaderType = ShaderCI.Desc.ShaderType;
256+
VERIFY_EXPR(DeviceType == RENDER_DEVICE_TYPE_GL || DeviceType == RENDER_DEVICE_TYPE_GLES);
257+
Attribs.Version = DeviceType == RENDER_DEVICE_TYPE_GL ? GLSLangUtils::SpirvVersion::GL : GLSLangUtils::SpirvVersion::GLES;
256258

257-
Attribs.ppCompilerOutput = ppCompilerOutput;
258-
Attribs.ShaderSource = static_cast<const char*>(Source);
259-
Attribs.SourceCodeLen = static_cast<int>(SourceLen);
259+
Attribs.ppCompilerOutput = ppCompilerOutput;
260+
Attribs.ShaderSource = static_cast<const char*>(Source);
261+
Attribs.SourceCodeLen = static_cast<int>(SourceLen);
260262

261-
if (GLSLangUtils::GLSLtoSPIRV(Attribs).empty())
262-
LOG_ERROR_AND_THROW("Failed to compile shader '", ShaderCI.Desc.Name, "'");
263+
if (GLSLangUtils::GLSLtoSPIRV(Attribs).empty())
264+
LOG_ERROR_AND_THROW("Failed to compile shader '", ShaderCI.Desc.Name, "'");
265+
}
263266
#endif
264267
}
265268

Graphics/Archiver/src/SerializationDeviceImpl.cpp

Lines changed: 6 additions & 1 deletion
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.
@@ -81,6 +81,11 @@ SerializationDeviceImpl::SerializationDeviceImpl(IReferenceCounters* pRefCounter
8181
m_D3D12Props.ShaderVersion = CreateInfo.D3D12.ShaderVersion;
8282
}
8383

84+
if (m_ValidDeviceFlags & (ARCHIVE_DEVICE_DATA_FLAG_GL | ARCHIVE_DEVICE_DATA_FLAG_GLES))
85+
{
86+
m_GLProps.ValidateShaders = CreateInfo.GL.ValidateShaders;
87+
}
88+
8489
if (m_ValidDeviceFlags & ARCHIVE_DEVICE_DATA_FLAG_VULKAN)
8590
{
8691
const auto& ApiVersion = CreateInfo.Vulkan.ApiVersion;

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 254004
33+
#define DILIGENT_API_VERSION 254005
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsTools/src/RenderStateCache.cpp

Lines changed: 3 additions & 2 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.
@@ -506,7 +506,8 @@ RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRe
506506

507507
case RENDER_DEVICE_TYPE_GL:
508508
case RENDER_DEVICE_TYPE_GLES:
509-
// Nothing to do
509+
// Do not validate shaders as compiling them is time-consuming
510+
SerializationDeviceCI.GL.ValidateShaders = false;
510511
break;
511512

512513
case RENDER_DEVICE_TYPE_VULKAN:

ReleaseHistory.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Current progress
22

3+
* Added `SerializationDeviceGLInfo` struct (API254005)
4+
* The `ValidateShaders` member allows disabling time-consuming shader compilation
35
* Replaced `AnisotropicFilteringSupported` member of `SamplerProperties` struct with `MaxAnisotropy` (API254004)
46
* Added `TextureSubresourceViews` device feature (API254003)
57
* Added device context rendering statistics (API254002)

0 commit comments

Comments
 (0)