Skip to content

Commit 04b09f9

Browse files
GLSL Utils: made parameters of BuildGLSLSourceString more flexible
1 parent 4bf8e76 commit 04b09f9

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

Graphics/Archiver/src/Archiver_GL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ struct CompiledShaderGL final : SerializedShaderImpl::CompiledShader
179179
const std::string GLSLSourceString = BuildGLSLSourceString(
180180
{
181181
ShaderCI,
182-
GLShaderCI.DeviceInfo,
183182
GLShaderCI.AdapterInfo,
183+
GLShaderCI.DeviceInfo.Features,
184+
GLShaderCI.DeviceInfo.Type,
185+
GLShaderCI.DeviceInfo.MaxShaderVersion,
184186
TargetGLSLCompiler::glslang,
185187
GLProps.ZeroToOneClipZ, // Note that this is not the same as GLShaderCI.DeviceInfo.NDC.MinZ == 0
186188
});

Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters,
7272

7373
// Build the full source code string that will contain GLSL version declaration,
7474
// platform definitions, user-provided shader macros, etc.
75-
m_GLSLSourceString = BuildGLSLSourceString({ShaderCI, DeviceInfo, AdapterInfo, TargetGLSLCompiler::driver, DeviceInfo.NDC.MinZ == 0});
75+
m_GLSLSourceString = BuildGLSLSourceString(
76+
{
77+
ShaderCI,
78+
AdapterInfo,
79+
DeviceInfo.Features,
80+
DeviceInfo.Type,
81+
DeviceInfo.MaxShaderVersion,
82+
TargetGLSLCompiler::driver,
83+
DeviceInfo.NDC.MinZ == 0,
84+
});
7685

7786
const SHADER_SOURCE_LANGUAGE SourceLang = ParseShaderSourceLanguageDefinition(m_GLSLSourceString);
7887
if (SourceLang != SHADER_SOURCE_LANGUAGE_DEFAULT)

Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,17 @@ std::vector<uint32_t> CompileShaderGLSLang(const ShaderCreateInfo& Shade
118118
{
119119
// Build the full source code string that will contain GLSL version declaration,
120120
// platform definitions, user-provided shader macros, etc.
121-
GLSLSourceString = BuildGLSLSourceString({ShaderCI, VkShaderCI.DeviceInfo, VkShaderCI.AdapterInfo, TargetGLSLCompiler::glslang, true, VulkanDefine});
121+
GLSLSourceString = BuildGLSLSourceString(
122+
{
123+
ShaderCI,
124+
VkShaderCI.AdapterInfo,
125+
VkShaderCI.DeviceInfo.Features,
126+
VkShaderCI.DeviceInfo.Type,
127+
VkShaderCI.DeviceInfo.MaxShaderVersion,
128+
TargetGLSLCompiler::glslang,
129+
true, // ZeroToOneClipZ
130+
VulkanDefine,
131+
});
122132
SourceData.Source = GLSLSourceString.c_str();
123133
SourceData.SourceLength = StaticCast<Uint32>(GLSLSourceString.length());
124134
}

Graphics/ShaderTools/include/GLSLUtils.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ struct IHLSL2GLSLConversionStream;
5353
// new stream will be created and warning message will be displayed.
5454
struct BuildGLSLSourceStringAttribs
5555
{
56-
const ShaderCreateInfo& ShaderCI;
57-
const RenderDeviceInfo& DeviceInfo;
58-
const GraphicsAdapterInfo& AdapterInfo;
59-
TargetGLSLCompiler TargetCompiler;
60-
bool ZeroToOneClipZ = false;
61-
const char* ExtraDefinitions = nullptr;
62-
IHLSL2GLSLConversionStream** ppConversionStream = nullptr;
56+
const ShaderCreateInfo& ShaderCI;
57+
const GraphicsAdapterInfo& AdapterInfo;
58+
const DeviceFeatures& Features;
59+
RENDER_DEVICE_TYPE DeviceType = RENDER_DEVICE_TYPE_UNDEFINED;
60+
RenderDeviceShaderVersionInfo MaxShaderVersion = {};
61+
TargetGLSLCompiler TargetCompiler = TargetGLSLCompiler::glslang;
62+
bool ZeroToOneClipZ = false;
63+
const char* ExtraDefinitions = nullptr;
64+
IHLSL2GLSLConversionStream** ppConversionStream = nullptr;
6365
};
6466

6567
String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexcept(false);

Graphics/ShaderTools/src/GLSLUtils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexce
269269

270270
ShaderVersion GLSLVer;
271271
bool IsES = false;
272-
GetGLSLVersion(ShaderCI, Attribs.TargetCompiler, Attribs.DeviceInfo.Type, Attribs.DeviceInfo.MaxShaderVersion, GLSLVer, IsES);
272+
GetGLSLVersion(ShaderCI, Attribs.TargetCompiler, Attribs.DeviceType, Attribs.MaxShaderVersion, GLSLVer, IsES);
273273

274274
const auto ShaderType = ShaderCI.Desc.ShaderType;
275275

@@ -283,7 +283,7 @@ String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexce
283283
// All extensions must go right after the version directive
284284
if (IsES)
285285
{
286-
AppendGLESExtensions(ShaderType, Attribs.DeviceInfo.Features, Attribs.AdapterInfo.Texture, GLSLVer, GLSLSource);
286+
AppendGLESExtensions(ShaderType, Attribs.Features, Attribs.AdapterInfo.Texture, GLSLVer, GLSLSource);
287287
}
288288

289289
if (ShaderCI.GLSLExtensions != nullptr && ShaderCI.GLSLExtensions[0] != '\0')
@@ -318,7 +318,7 @@ String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexce
318318

319319
if (IsES)
320320
{
321-
AppendPrecisionQualifiers(Attribs.DeviceInfo.Features, Attribs.AdapterInfo.Texture, GLSLVer, GLSLSource);
321+
AppendPrecisionQualifiers(Attribs.Features, Attribs.AdapterInfo.Texture, GLSLVer, GLSLSource);
322322
}
323323

324324
// It would be much more convenient to use row_major matrices.
@@ -331,7 +331,7 @@ String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexce
331331

332332
AppendShaderMacros(GLSLSource, ShaderCI.Macros);
333333

334-
if (IsES && GLSLVer == ShaderVersion{3, 0} && Attribs.DeviceInfo.Features.SeparablePrograms && ShaderType == SHADER_TYPE_VERTEX)
334+
if (IsES && GLSLVer == ShaderVersion{3, 0} && Attribs.Features.SeparablePrograms && ShaderType == SHADER_TYPE_VERTEX)
335335
{
336336
// From https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_separate_shader_objects.gles.txt:
337337
//
@@ -386,7 +386,7 @@ String BuildGLSLSourceString(const BuildGLSLSourceStringAttribs& Attribs) noexce
386386
// all shader stages.
387387
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_separate_shader_objects.txt
388388
// (search for "Input Layout Qualifiers" and "Output Layout Qualifiers").
389-
ConvertAttribs.UseInOutLocationQualifiers = Attribs.DeviceInfo.Features.SeparablePrograms;
389+
ConvertAttribs.UseInOutLocationQualifiers = Attribs.Features.SeparablePrograms;
390390
auto ConvertedSource = Converter.Convert(ConvertAttribs);
391391
if (ConvertedSource.empty())
392392
{

0 commit comments

Comments
 (0)