Diligent Engine  v.2.4.g
Shader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
32 
33 #include "../../../Primitives/interface/FileStream.h"
34 #include "../../../Primitives/interface/FlagEnum.h"
35 #include "DeviceObject.h"
36 
38 
39 // {2989B45C-143D-4886-B89C-C3271C2DCC5D}
40 static const INTERFACE_ID IID_Shader =
41  {0x2989b45c, 0x143d, 0x4886, {0xb8, 0x9c, 0xc3, 0x27, 0x1c, 0x2d, 0xcc, 0x5d}};
42 
43 // clang-format off
44 
47 {
50 
53 
56 
59 
61 
69 };
70 
71 
74 {
83 
86 
89 
92 
94 };
95 
96 
99 {
102 
106 };
108 
111 
114 };
115 typedef struct ShaderDesc ShaderDesc;
116 
117 // clang-format on
118 
119 // {3EA98781-082F-4413-8C30-B9BA6D82DBB7}
120 static const INTERFACE_ID IID_IShaderSourceInputStreamFactory =
121  {0x3ea98781, 0x82f, 0x4413, {0x8c, 0x30, 0xb9, 0xba, 0x6d, 0x82, 0xdb, 0xb7}};
122 
123 
124 // clang-format off
125 
126 #define DILIGENT_INTERFACE_NAME IShaderSourceInputStreamFactory
127 #include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
128 
129 #define IShaderSourceInputStreamFactoryInclusiveMethods \
130  IObjectInclusiveMethods; \
131  IShaderSourceInputStreamFactoryMethods ShaderSourceInputStreamFactory
132 
135 {
136  VIRTUAL void METHOD(CreateInputStream)(THIS_
137  const Char* Name,
138  IFileStream** ppStream) PURE;
139 
140  VIRTUAL void METHOD(CreateInputStream2)(THIS_
141  const Char* Name,
143  IFileStream** ppStream) PURE;
144 };
146 
147 #include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
148 
149 #if DILIGENT_C_INTERFACE
150 
151 // clang-format on
152 
153 # define IShaderSourceInputStreamFactory_CreateInputStream(This, ...) CALL_IFACE_METHOD(ShaderSourceInputStreamFactory, CreateInputStream, This, __VA_ARGS__)
154 # define IShaderSourceInputStreamFactory_CreateInputStream2(This, ...) CALL_IFACE_METHOD(ShaderSourceInputStreamFactory, CreateInputStream2, This, __VA_ARGS__)
155 
156 #endif
157 
158 
160 {
161  const Char* Name DEFAULT_INITIALIZER(nullptr);
162  const Char* Definition DEFAULT_INITIALIZER(nullptr);
163 
164 #if DILIGENT_CPP_INTERFACE
165  ShaderMacro() noexcept
166  {}
167  ShaderMacro(const Char* _Name,
168  const Char* _Def) noexcept :
169  Name{_Name},
170  Definition{_Def}
171  {}
172 #endif
173 };
174 typedef struct ShaderMacro ShaderMacro;
175 
178 {
181 
184 
185 #if DILIGENT_CPP_INTERFACE
186  ShaderVersion() noexcept
187  {}
188  ShaderVersion(Uint8 _Major, Uint8 _Minor) noexcept :
189  Major{_Major},
190  Minor{_Minor}
191  {}
192 
193  bool operator==(const ShaderVersion& rhs) const
194  {
195  return Major == rhs.Major && Minor == rhs.Minor;
196  }
197 
198  bool operator>(const ShaderVersion& rhs) const
199  {
200  return Major == rhs.Major ? Minor > rhs.Minor : Major > rhs.Major;
201  }
202 
203  bool operator>=(const ShaderVersion& rhs) const
204  {
205  return Major == rhs.Major ? Minor >= rhs.Minor : Major >= rhs.Major;
206  }
207 
208  bool operator<(const ShaderVersion& rhs) const
209  {
210  return Major == rhs.Major ? Minor < rhs.Minor : Major < rhs.Major;
211  }
212 
213  bool operator<=(const ShaderVersion& rhs) const
214  {
215  return Major == rhs.Major ? Minor <= rhs.Minor : Major <= rhs.Major;
216  }
217 #endif
218 };
220 
221 
222 // clang-format off
223 
226 {
229 
232 
234 };
236 
237 // clang-format on
238 
239 
242 {
244 
246  const Char* FilePath DEFAULT_INITIALIZER(nullptr);
247 
249 
252  IShaderSourceInputStreamFactory* pShaderSourceStreamFactory DEFAULT_INITIALIZER(nullptr);
253 
255 
265  struct IHLSL2GLSLConversionStream** ppConversionStream DEFAULT_INITIALIZER(nullptr);
266 
268 
270  const Char* Source DEFAULT_INITIALIZER(nullptr);
271 
273 
281  const void* ByteCode DEFAULT_INITIALIZER(nullptr);
282 
284 
286  size_t ByteCodeSize DEFAULT_INITIALIZER(0);
287 
289 
291  const Char* EntryPoint DEFAULT_INITIALIZER("main");
292 
294 
296  const ShaderMacro* Macros DEFAULT_INITIALIZER(nullptr);
297 
305  bool UseCombinedTextureSamplers DEFAULT_INITIALIZER(false);
306 
313  const Char* CombinedSamplerSuffix DEFAULT_INITIALIZER("_sampler");
314 
317 
320 
323 
331 
336 
341 
344 
346 
350  IDataBlob** ppCompilerOutput DEFAULT_INITIALIZER(nullptr);
351 };
353 
354 // clang-format off
357 {
360 
363 
366 
369 
372 
375 
378 
381 
384 
386 };
387 // clang-format on
388 
391 {
392 #if DILIGENT_CPP_INTERFACE
394  {}
395 
396  ShaderResourceDesc(const char* _Name,
397  SHADER_RESOURCE_TYPE _Type,
398  Uint32 _ArraySize) noexcept :
399  Name{_Name},
400  Type{_Type},
401  ArraySize{_ArraySize}
402  {}
403 #endif
404 
405  // clang-format off
407  const char* Name DEFAULT_INITIALIZER(nullptr);
408 
411 
414  // clang-format on
415 };
417 
418 #define DILIGENT_INTERFACE_NAME IShader
419 #include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
420 
421 #define IShaderInclusiveMethods \
422  IDeviceObjectInclusiveMethods; \
423  IShaderMethods Shader
424 
425 // clang-format off
426 
429 {
430 #if DILIGENT_CPP_INTERFACE
431  virtual const ShaderDesc& METHOD(GetDesc)() const override = 0;
433 #endif
434 
436  VIRTUAL Uint32 METHOD(GetResourceCount)(THIS) CONST PURE;
437 
439  VIRTUAL void METHOD(GetResourceDesc)(THIS_
440  Uint32 Index,
441  ShaderResourceDesc REF ResourceDesc) CONST PURE;
442 };
444 
445 #include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
446 
447 #if DILIGENT_C_INTERFACE
448 
449 // clang-format off
450 
451 # define IShader_GetDesc(This) (const struct ShaderDesc*)IDeviceObject_GetDesc(This)
452 
453 # define IShader_GetResourceCount(This) CALL_IFACE_METHOD(Shader, GetResourceCount, This)
454 # define IShader_GetResourceDesc(This, ...) CALL_IFACE_METHOD(Shader, GetResourceDesc, This, __VA_ARGS__)
455 
456 // clang-format on
457 
458 #endif
459 
460 DILIGENT_END_NAMESPACE // namespace Diligent
Diligent::ShaderVersion::ShaderVersion
ShaderVersion(Uint8 _Major, Uint8 _Minor) noexcept
Definition: Shader.h:188
Diligent::IShaderSourceInputStreamFactory
Shader source stream factory interface.
Definition: Shader.h:134
Diligent::SHADER_COMPILER_DEFAULT
@ SHADER_COMPILER_DEFAULT
Default compiler for specific language and API that is selected as follows:
Definition: Shader.h:82
Diligent::ShaderVersion::operator<=
bool operator<=(const ShaderVersion &rhs) const
Definition: Shader.h:213
DILIGENT_END_INTERFACE
#define DILIGENT_END_INTERFACE
Definition: DefineInterfaceHelperMacros.h:88
Diligent::SHADER_RESOURCE_TYPE_CONSTANT_BUFFER
@ SHADER_RESOURCE_TYPE_CONSTANT_BUFFER
Constant (uniform) buffer.
Definition: Shader.h:362
Diligent::INTERFACE_ID
struct INTERFACE_ID INTERFACE_ID
Definition: InterfaceID.h:54
Diligent::SHADER_COMPILER_DXC
@ SHADER_COMPILER_DXC
Modern HLSL compiler (DXC) for Direct3D12 and Vulkan with Shader Model 6.x support.
Definition: Shader.h:88
VIRTUAL
#define VIRTUAL
Definition: DefineInterfaceHelperMacros.h:83
Diligent::SHADER_SOURCE_LANGUAGE
SHADER_SOURCE_LANGUAGE
Describes the shader source code language.
Definition: Shader.h:46
Diligent::Char
char Char
Definition: BasicTypes.h:64
Diligent::SHADER_SOURCE_LANGUAGE_HLSL
@ SHADER_SOURCE_LANGUAGE_HLSL
The source language is HLSL.
Definition: Shader.h:52
Diligent::SHADER_COMPILE_FLAG_NONE
@ SHADER_COMPILE_FLAG_NONE
No flags.
Definition: Shader.h:228
Diligent::ShaderMacro::ShaderMacro
ShaderMacro(const Char *_Name, const Char *_Def) noexcept
Definition: Shader.h:167
Diligent::IDataBlob
Base interface for a file stream.
Definition: DataBlob.h:52
Diligent::SHADER_TYPE
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
Diligent::SHADER_RESOURCE_TYPE
SHADER_RESOURCE_TYPE
Describes shader resource type.
Definition: Shader.h:356
Diligent::ShaderVersion
Shader version.
Definition: Shader.h:177
DILIGENT_BEGIN_INTERFACE
#define DILIGENT_BEGIN_INTERFACE(Name, Base)
Definition: CommonDefinitions.h:97
Diligent::SHADER_RESOURCE_TYPE_TEXTURE_SRV
@ SHADER_RESOURCE_TYPE_TEXTURE_SRV
Shader resource view of a texture (sampled image)
Definition: Shader.h:365
Diligent::ShaderVersion::ShaderVersion
ShaderVersion() noexcept
Definition: Shader.h:186
Flags
Uint32 Flags
Definition: DXBCUtils.cpp:71
Diligent::SHADER_RESOURCE_TYPE_BUFFER_UAV
@ SHADER_RESOURCE_TYPE_BUFFER_UAV
Unordered access view of a buffer (storage buffer)
Definition: Shader.h:374
Diligent::IShader
Shader interface.
Definition: Shader.h:428
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Diligent::SHADER_RESOURCE_TYPE_SAMPLER
@ SHADER_RESOURCE_TYPE_SAMPLER
Sampler (separate sampler)
Definition: Shader.h:377
Diligent::CREATE_SHADER_SOURCE_INPUT_STREAM_FLAG_NONE
@ CREATE_SHADER_SOURCE_INPUT_STREAM_FLAG_NONE
No flag.
Definition: Shader.h:101
Diligent::IHLSL2GLSLConversionStream
Definition: HLSL2GLSLConverter.h:52
Diligent::SHADER_SOURCE_LANGUAGE_GLSL_VERBATIM
@ SHADER_SOURCE_LANGUAGE_GLSL_VERBATIM
The source language is GLSL that should be compiled verbatim.
Definition: Shader.h:68
Diligent::ShaderVersion::Major
Uint8 Major
Major revision.
Definition: Shader.h:180
Diligent::SHADER_COMPILE_FLAG_LAST
@ SHADER_COMPILE_FLAG_LAST
Definition: Shader.h:233
Diligent::CREATE_SHADER_SOURCE_INPUT_STREAM_FLAG_SILENT
@ CREATE_SHADER_SOURCE_INPUT_STREAM_FLAG_SILENT
Do not output any messages if the file is not found or other errors occur.
Definition: Shader.h:105
Diligent::ShaderMacro
Definition: Shader.h:159
Diligent::SHADER_COMPILE_FLAGS
SHADER_COMPILE_FLAGS
Shader compilation flags.
Definition: Shader.h:225
Diligent::IDeviceObject
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:52
THIS
#define THIS
Definition: DefineInterfaceHelperMacros.h:81
Diligent::ShaderResourceDesc::ShaderResourceDesc
ShaderResourceDesc() noexcept
Definition: Shader.h:393
Diligent::ShaderCreateInfo
Shader creation attributes.
Definition: Shader.h:241
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT
@ SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT
Input attachment in a render pass.
Definition: Shader.h:380
Diligent::ShaderVersion::operator>=
bool operator>=(const ShaderVersion &rhs) const
Definition: Shader.h:203
Diligent::SHADER_RESOURCE_TYPE_BUFFER_SRV
@ SHADER_RESOURCE_TYPE_BUFFER_SRV
Shader resource view of a buffer (read-only storage image)
Definition: Shader.h:368
PURE
#define PURE
Definition: DefineInterfaceHelperMacros.h:85
Diligent::SHADER_SOURCE_LANGUAGE_DEFAULT
@ SHADER_SOURCE_LANGUAGE_DEFAULT
Default language (GLSL for OpenGL/OpenGLES/Vulkan devices, HLSL for Direct3D11/Direct3D12 devices)
Definition: Shader.h:49
Diligent::ShaderMacro::ShaderMacro
ShaderMacro() noexcept
Definition: Shader.h:165
Diligent::SHADER_RESOURCE_TYPE_LAST
@ SHADER_RESOURCE_TYPE_LAST
Definition: Shader.h:385
Diligent::SHADER_SOURCE_LANGUAGE_MSL
@ SHADER_SOURCE_LANGUAGE_MSL
The source language is Metal shading language (MSL)
Definition: Shader.h:58
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:1196
Diligent::SHADER_COMPILER_GLSLANG
@ SHADER_COMPILER_GLSLANG
Built-in glslang compiler for GLSL and HLSL.
Definition: Shader.h:85
DILIGENT_END_NAMESPACE
#define DILIGENT_END_NAMESPACE
Definition: CommonDefinitions.h:86
Diligent::ShaderDesc
Shader description.
Definition: Shader.h:110
Diligent::SHADER_SOURCE_LANGUAGE_GLSL
@ SHADER_SOURCE_LANGUAGE_GLSL
The source language is GLSL.
Definition: Shader.h:55
CONST
#define CONST
Definition: DefineInterfaceHelperMacros.h:84
Diligent::SHADER_RESOURCE_TYPE_ACCEL_STRUCT
@ SHADER_RESOURCE_TYPE_ACCEL_STRUCT
Acceleration structure.
Definition: Shader.h:383
Diligent::CREATE_SHADER_SOURCE_INPUT_STREAM_FLAGS
CREATE_SHADER_SOURCE_INPUT_STREAM_FLAGS
Describes the flags that can be passed over to IShaderSourceInputStreamFactory::CreateInputStream2() ...
Definition: Shader.h:98
DILIGENT_DERIVE
#define DILIGENT_DERIVE(TypeName)
Definition: CommonDefinitions.h:90
Type
const D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type
Definition: PipelineStateD3D12Impl.cpp:69
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS
@ SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS
Enable unbounded resource arrays (e.g. Texture2D g_Texture[]).
Definition: Shader.h:231
DEFAULT_INITIALIZER
#define DEFAULT_INITIALIZER(x)
Definition: CommonDefinitions.h:93
Diligent::IFileStream
Base interface for a file stream.
Definition: FileStream.h:53
Diligent::ShaderVersion::operator>
bool operator>(const ShaderVersion &rhs) const
Definition: Shader.h:198
Diligent::SHADER_TYPE_UNKNOWN
@ SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: GraphicsTypes.h:67
Diligent::SHADER_RESOURCE_TYPE_TEXTURE_UAV
@ SHADER_RESOURCE_TYPE_TEXTURE_UAV
Unordered access view of a texture (sotrage image)
Definition: Shader.h:371
Diligent::ShaderResourceDesc::ShaderResourceDesc
ShaderResourceDesc(const char *_Name, SHADER_RESOURCE_TYPE _Type, Uint32 _ArraySize) noexcept
Definition: Shader.h:396
DeviceObject.h
REF
#define REF
Definition: DefineGlobalFuncHelperMacros.h:39
Diligent::SHADER_COMPILER_LAST
@ SHADER_COMPILER_LAST
Definition: Shader.h:93
METHOD
#define METHOD(Name)
Definition: DefineInterfaceHelperMacros.h:87
DILIGENT_TYPED_ENUM
#define DILIGENT_TYPED_ENUM(EnumName, EnumType)
Definition: CommonDefinitions.h:88
Diligent::SHADER_COMPILER
SHADER_COMPILER
Describes the shader compiler that will be used to compile the shader source code.
Definition: Shader.h:73
Diligent::ShaderVersion::operator==
bool operator==(const ShaderVersion &rhs) const
Definition: Shader.h:193
Diligent::ShaderResourceDesc
Shader resource description.
Definition: Shader.h:390
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
Diligent::SHADER_COMPILER_FXC
@ SHADER_COMPILER_FXC
Legacy HLSL compiler (FXC) for Direct3D11 and Direct3D12 supporting shader models up to 5....
Definition: Shader.h:91
DILIGENT_BEGIN_NAMESPACE
#define DILIGENT_BEGIN_NAMESPACE(Name)
Definition: CommonDefinitions.h:82
Diligent::ShaderVersion::Minor
Uint8 Minor
Minor revision.
Definition: Shader.h:183
DEFINE_FLAG_ENUM_OPERATORS
DEFINE_FLAG_ENUM_OPERATORS(FILE_DIALOG_FLAGS)
Diligent::ShaderVersion::operator<
bool operator<(const ShaderVersion &rhs) const
Definition: Shader.h:208
ShaderType
Uint16 ShaderType
Definition: DXBCUtils.cpp:70
Diligent::SHADER_RESOURCE_TYPE_UNKNOWN
@ SHADER_RESOURCE_TYPE_UNKNOWN
Shader resource type is unknown.
Definition: Shader.h:359
Diligent::ShaderCreateInfo::Desc
ShaderDesc Desc
Shader description. See Diligent::ShaderDesc.
Definition: Shader.h:316
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
THIS_
#define THIS_
Definition: DefineInterfaceHelperMacros.h:82