Skip to content

Commit b85d61f

Browse files
committed
Added CompilerOptions, bunch of renames and Interface for HLSL Compiler
1 parent a9dabaa commit b85d61f

36 files changed

+478
-300
lines changed

include/nbl/asset/IAssetManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "nbl/asset/interchange/IAssetLoader.h"
1818
#include "nbl/asset/interchange/IAssetWriter.h"
1919

20-
#include "nbl/asset/utils/IGLSLCompiler.h"
20+
#include "nbl/asset/utils/CGLSLCompiler.h"
2121
#include "nbl/asset/utils/IGeometryCreator.h"
2222

2323

@@ -119,7 +119,7 @@ class NBL_API IAssetManager : public core::IReferenceCounted, public core::QuitS
119119

120120
core::smart_refctd_ptr<IGeometryCreator> m_geometryCreator;
121121
core::smart_refctd_ptr<IMeshManipulator> m_meshManipulator;
122-
core::smart_refctd_ptr<IGLSLCompiler> m_glslCompiler;
122+
core::smart_refctd_ptr<CGLSLCompiler> m_glslCompiler;
123123
// called as a part of constructor only
124124
void initializeMeshTools();
125125

@@ -144,7 +144,7 @@ class NBL_API IAssetManager : public core::IReferenceCounted, public core::QuitS
144144

145145
const IGeometryCreator* getGeometryCreator() const;
146146
IMeshManipulator* getMeshManipulator();
147-
IGLSLCompiler* getGLSLCompiler() const { return m_glslCompiler.get(); }
147+
CGLSLCompiler* getGLSLCompiler() const { return m_glslCompiler.get(); }
148148

149149
protected:
150150
virtual ~IAssetManager()

include/nbl/asset/asset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "nbl/asset/ICPUSpecializedShader.h"
4444
#include "nbl/asset/utils/ShaderRes.h"
4545
#include "nbl/asset/utils/IShaderCompiler.h"
46-
#include "nbl/asset/utils/IGLSLCompiler.h"
46+
#include "nbl/asset/utils/CGLSLCompiler.h"
4747
#include "nbl/asset/utils/CShaderIntrospector.h"
4848

4949
// pipelines

include/nbl/asset/utils/IGLSLCompiler.h renamed to include/nbl/asset/utils/CGLSLCompiler.h

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,29 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef __NBL_ASSET_I_GLSL_COMPILER_H_INCLUDED__
6-
#define __NBL_ASSET_I_GLSL_COMPILER_H_INCLUDED__
5+
#ifndef _NBL_ASSET_C_GLSL_COMPILER_H_INCLUDED_
6+
#define _NBL_ASSET_C_GLSL_COMPILER_H_INCLUDED_
77

88
#include "nbl/asset/utils/ISPIRVOptimizer.h"
99
#include "nbl/asset/utils/IShaderCompiler.h"
1010

1111
namespace nbl::asset
1212
{
1313

14-
//! Will be derivative of IShaderGenerator, but we have to establish interface first
15-
class NBL_API IGLSLCompiler final : public IShaderCompiler
14+
class NBL_API CGLSLCompiler final : public IShaderCompiler
1615
{
1716
public:
18-
enum E_SPIRV_VERSION
19-
{
20-
ESV_1_0 = 0x010000u,
21-
ESV_1_1 = 0x010100u,
22-
ESV_1_2 = 0x010200u,
23-
ESV_1_3 = 0x010300u,
24-
ESV_1_4 = 0x010400u,
25-
ESV_1_5 = 0x010500u,
26-
ESV_1_6 = 0x010600u,
27-
ESV_COUNT = 0x7FFFFFFFu
28-
};
17+
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_GLSL; };
2918

30-
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_GLSL; };
19+
CGLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system);
3120

32-
IGLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system);
33-
34-
core::smart_refctd_ptr<ICPUBuffer> compileSPIRVFromGLSL(
35-
const char* _glslCode,
36-
IShader::E_SHADER_STAGE _stage,
37-
const char* _entryPoint,
38-
const char* _compilationId,
39-
bool _genDebugInfo = true,
40-
std::string* _outAssembly = nullptr,
41-
system::logger_opt_ptr logger = nullptr,
42-
const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const;
21+
struct SOptions : IShaderCompiler::SOptions
22+
{
23+
virtual IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_GLSL; };
24+
};
4325

4426
/**
45-
If _stage is ESS_UNKNOWN, then compiler will try to deduce shader stage from #pragma annotation, i.e.:
27+
If options.stage is ESS_UNKNOWN, then compiler will try to deduce shader stage from #pragma annotation, i.e.:
4628
#pragma shader_stage(vertex), or
4729
#pragma shader_stage(tesscontrol), or
4830
#pragma shader_stage(tesseval), or
@@ -54,14 +36,34 @@ class NBL_API IGLSLCompiler final : public IShaderCompiler
5436
5537
This function does NOT process #include directives! Use resolveIncludeDirectives() first.
5638
57-
@param _entryPoint Must be "main" since shaderc does not allow other entry points for GLSL. Kept with hope that shaderc will drop that requirement.
58-
@param _compilationId String that will be printed along with possible errors as source identifier.
59-
@param _genDebugInfo Requests compiler to generate debug info (most importantly objects' names).
60-
The engine, while running on OpenGL, won't be able to set push constants for shaders loaded as SPIR-V without debug info.
61-
@param _outAssembly Optional parameter; if not nullptr, SPIR-V assembly is saved in there.
39+
@params code high level code
40+
@param options
41+
entryPoint Must be "main" since shaderc does not allow other entry points for GLSL. Kept with hope that shaderc will drop that requirement.
42+
compilationId String that will be printed along with possible errors as source identifier.
43+
genDebugInfo Requests compiler to generate debug info (most importantly objects' names).
44+
The engine, while running on OpenGL, won't be able to set push constants for shaders loaded as SPIR-V without debug info.
45+
outAssembly Optional parameter; if not nullptr, SPIR-V assembly is saved in there.
6246
6347
@returns Shader containing SPIR-V bytecode.
6448
*/
49+
core::smart_refctd_ptr<ICPUBuffer> compileToSPIRV(const char* code, const CGLSLCompiler::SOptions& options) const;
50+
51+
core::smart_refctd_ptr<ICPUShader> createSPIRVShader(const char* code, const CGLSLCompiler::SOptions& options) const;
52+
53+
core::smart_refctd_ptr<ICPUShader> createSPIRVShader(system::IFile* sourceFile, const CGLSLCompiler::SOptions& options) const;
54+
55+
// TODO: REMOVE
56+
core::smart_refctd_ptr<ICPUBuffer> compileSPIRVFromGLSL(
57+
const char* _glslCode,
58+
IShader::E_SHADER_STAGE _stage,
59+
const char* _entryPoint,
60+
const char* _compilationId,
61+
bool _genDebugInfo = true,
62+
std::string* _outAssembly = nullptr,
63+
system::logger_opt_ptr logger = nullptr,
64+
const E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6) const;
65+
66+
// TODO: REMOVE
6567
core::smart_refctd_ptr<ICPUShader> createSPIRVFromGLSL(
6668
const char* _glslCode,
6769
IShader::E_SHADER_STAGE _stage,
@@ -71,8 +73,9 @@ class NBL_API IGLSLCompiler final : public IShaderCompiler
7173
bool _genDebugInfo = true,
7274
std::string* _outAssembly = nullptr,
7375
system::logger_opt_ptr logger = nullptr,
74-
const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const;
76+
const E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6) const;
7577

78+
// TODO: REMOVE
7679
core::smart_refctd_ptr<ICPUShader> createSPIRVFromGLSL(
7780
system::IFile* _sourcefile,
7881
IShader::E_SHADER_STAGE _stage,
@@ -82,7 +85,7 @@ class NBL_API IGLSLCompiler final : public IShaderCompiler
8285
bool _genDebugInfo = true,
8386
std::string* _outAssembly = nullptr,
8487
system::logger_opt_ptr logger = nullptr,
85-
const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const;
88+
const E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6) const;
8689

8790
/*
8891
If original code contains #version specifier,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (C) 2018-2022 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#ifndef _NBL_ASSET_C_HLSL_COMPILER_H_INCLUDED_
6+
#define _NBL_ASSET_C_HLSL_COMPILER_H_INCLUDED_
7+
8+
#include "nbl/asset/utils/ISPIRVOptimizer.h"
9+
#include "nbl/asset/utils/IShaderCompiler.h"
10+
11+
namespace nbl::asset
12+
{
13+
14+
class NBL_API CHLSLCompiler final : public IShaderCompiler
15+
{
16+
public:
17+
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_HLSL; };
18+
19+
CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system);
20+
21+
struct SOptions : IShaderCompiler::SOptions
22+
{
23+
// TODO: Add extra dxc options
24+
virtual IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_HLSL; };
25+
};
26+
27+
/**
28+
If options.stage is ESS_UNKNOWN, then compiler will try to deduce shader stage from #pragma annotation, i.e.:
29+
#pragma shader_stage(vertex), or
30+
#pragma shader_stage(tesscontrol), or
31+
#pragma shader_stage(tesseval), or
32+
#pragma shader_stage(geometry), or
33+
#pragma shader_stage(fragment), or
34+
#pragma shader_stage(compute)
35+
36+
Such annotation should be placed right after #version directive.
37+
38+
This function does NOT process #include directives! Use resolveIncludeDirectives() first.
39+
40+
@params code high level code
41+
@param options
42+
entryPoint Must be "main" since shaderc does not allow other entry points for HLSL. Kept with hope that shaderc will drop that requirement.
43+
compilationId String that will be printed along with possible errors as source identifier.
44+
genDebugInfo Requests compiler to generate debug info (most importantly objects' names).
45+
The engine, while running on OpenGL, won't be able to set push constants for shaders loaded as SPIR-V without debug info.
46+
outAssembly Optional parameter; if not nullptr, SPIR-V assembly is saved in there.
47+
48+
@returns Shader containing SPIR-V bytecode.
49+
*/
50+
core::smart_refctd_ptr<ICPUBuffer> compileToSPIRV(const char* code, const CHLSLCompiler::SOptions& options) const;
51+
52+
core::smart_refctd_ptr<ICPUShader> createSPIRVShader(const char* code, const CHLSLCompiler::SOptions& options) const;
53+
54+
core::smart_refctd_ptr<ICPUShader> createSPIRVShader(system::IFile* sourceFile, const CHLSLCompiler::SOptions& options) const;
55+
56+
/*
57+
If original code contains #version specifier,
58+
then the filled fmt will be placed onto the next line after #version in the output buffer. If not, fmt will be placed into the
59+
beginning of the output buffer.
60+
*/
61+
template<typename... Args>
62+
static core::smart_refctd_ptr<ICPUShader> createOverridenCopy(const ICPUShader* original, const char* fmt, Args... args)
63+
{
64+
return IShaderCompiler::createOverridenCopy(original, 0u, fmt, args...);
65+
}
66+
67+
static inline const char* getStorageImageFormatQualifier(const asset::E_FORMAT format)
68+
{
69+
// TODO
70+
return "";
71+
}
72+
};
73+
74+
}
75+
76+
#endif

include/nbl/asset/utils/CShaderIntrospector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "nbl/asset/ICPUComputePipeline.h"
1616
#include "nbl/asset/ICPURenderpassIndependentPipeline.h"
1717
#include "nbl/asset/utils/ShaderRes.h"
18-
#include "nbl/asset/utils/IGLSLCompiler.h"
18+
#include "nbl/asset/utils/CGLSLCompiler.h"
1919

2020

2121
#include "nbl/core/definitions.h"
@@ -89,7 +89,7 @@ class NBL_API CShaderIntrospector : public core::Uncopyable
8989
};
9090

9191
//In the future there's also going list of enabled extensions
92-
CShaderIntrospector(const IGLSLCompiler* _glslcomp) : m_glslCompiler(_glslcomp) {}
92+
CShaderIntrospector(const CGLSLCompiler* _glslcomp) : m_glslCompiler(_glslcomp) {}
9393

9494
//
9595
const CIntrospectionData* introspect(const ICPUShader* _shader, const SIntrospectionParams& _params);
@@ -156,7 +156,7 @@ class NBL_API CShaderIntrospector : public core::Uncopyable
156156
size_t calcBytesizeforType(spirv_cross::Compiler& _comp, const spirv_cross::SPIRType& _type) const;
157157

158158
private:
159-
const IGLSLCompiler* m_glslCompiler;
159+
const CGLSLCompiler* m_glslCompiler;
160160

161161

162162
struct Key

0 commit comments

Comments
 (0)