Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngine/interface/Shader.h Source File

Diligent Engine API Reference

Shader.h
1 /* Copyright 2015-2018 Egor Yusov
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12 *
13 * In no event and under no legal theory, whether in tort (including negligence),
14 * contract, or otherwise, unless required by applicable law (such as deliberate
15 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16 * liable for any damages, including any direct, indirect, special, incidental,
17 * or consequential damages of any character arising as a result of this License or
18 * out of the use or inability to use the software (including but not limited to damages
19 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20 * all other commercial damages or losses), even if such Contributor has been advised
21 * of the possibility of such damages.
22 */
23
24 #pragma once
25
28
29 #include "DeviceObject.h"
30 #include "ResourceMapping.h"
31 #include "FileStream.h"
32 #include "Sampler.h"
33
34 namespace Diligent
35 {
36
37 // {2989B45C-143D-4886-B89C-C3271C2DCC5D}
38 static constexpr INTERFACE_ID IID_Shader =
39 { 0x2989b45c, 0x143d, 0x4886, { 0xb8, 0x9c, 0xc3, 0x27, 0x1c, 0x2d, 0xcc, 0x5d } };
40
41 // {0D57DF3F-977D-4C8F-B64C-6675814BC80C}
42 static constexpr INTERFACE_ID IID_ShaderVariable =
43 { 0xd57df3f, 0x977d, 0x4c8f, { 0xb6, 0x4c, 0x66, 0x75, 0x81, 0x4b, 0xc8, 0xc } };
44
46 enum SHADER_TYPE : Int32
47 {
48 SHADER_TYPE_UNKNOWN = 0x000,
49 SHADER_TYPE_VERTEX = 0x001,
50 SHADER_TYPE_PIXEL = 0x002,
51 SHADER_TYPE_GEOMETRY = 0x004,
52 SHADER_TYPE_HULL = 0x008,
53 SHADER_TYPE_DOMAIN = 0x010,
54 SHADER_TYPE_COMPUTE = 0x020
55 };
56
57 enum SHADER_PROFILE : Int32
58 {
59 SHADER_PROFILE_DEFAULT = 0,
60 SHADER_PROFILE_DX_4_0,
61 SHADER_PROFILE_DX_5_0,
62 SHADER_PROFILE_DX_5_1,
63 SHADER_PROFILE_GL_4_2
64 };
65
67 enum SHADER_SOURCE_LANGUAGE : Int32
68 {
70 SHADER_SOURCE_LANGUAGE_DEFAULT = 0,
71
73 SHADER_SOURCE_LANGUAGE_HLSL,
74
76 SHADER_SOURCE_LANGUAGE_GLSL
77 };
78
81 enum BIND_SHADER_RESOURCES_FLAGS : Int32
82 {
85 BIND_SHADER_RESOURCES_RESET_BINDINGS = 0x01,
86
91 BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED = 0x02,
92
96 BIND_SHADER_RESOURCES_ALL_RESOLVED = 0x04
97 };
98
100 enum SHADER_VARIABLE_TYPE : Int32
101 {
105 SHADER_VARIABLE_TYPE_STATIC = 0,
106
110 SHADER_VARIABLE_TYPE_MUTABLE,
111
114 SHADER_VARIABLE_TYPE_DYNAMIC,
115
117 SHADER_VARIABLE_TYPE_NUM_TYPES
118 };
119
121 struct ShaderVariableDesc
122 {
124 const Char *Name;
125
127 SHADER_VARIABLE_TYPE Type;
128 ShaderVariableDesc(const Char *_Name = nullptr, SHADER_VARIABLE_TYPE _Type = SHADER_VARIABLE_TYPE_STATIC) :
129 Name(_Name),
130 Type(_Type)
131 {}
132 };
133
134
136 struct StaticSamplerDesc
137 {
139 const Char* TextureName = nullptr;
140
142 SamplerDesc Desc;
143
144 StaticSamplerDesc(){};
145 StaticSamplerDesc(const Char* _TexName, const SamplerDesc &_Desc) :
146 TextureName(_TexName),
147 Desc(_Desc)
148 {}
149 };
150
152 struct ShaderDesc : DeviceObjectAttribs
153 {
155 SHADER_TYPE ShaderType;
156
157 Bool bCacheCompiledShader;
158 SHADER_PROFILE TargetProfile;
159
163 SHADER_VARIABLE_TYPE DefaultVariableType;
164
166 const ShaderVariableDesc *VariableDesc;
167
169 Uint32 NumVariables;
170
172 Uint32 NumStaticSamplers;
173
175 const StaticSamplerDesc *StaticSamplers;
176
177 ShaderDesc() :
178 ShaderType(SHADER_TYPE_VERTEX),
179 bCacheCompiledShader(False),
180 TargetProfile(SHADER_PROFILE_DEFAULT),
181 DefaultVariableType(SHADER_VARIABLE_TYPE_STATIC),
182 VariableDesc(nullptr),
183 NumVariables(0),
184 NumStaticSamplers(0),
185 StaticSamplers(nullptr)
186 {}
187 };
188
190 class IShaderSourceInputStreamFactory
191 {
192 public:
193 virtual void CreateInputStream(const Diligent::Char *Name, IFileStream **ppStream) = 0;
194 };
195
196 struct ShaderMacro
197 {
198 const Char* Name;
199 const Char* Definition;
200 ShaderMacro(const Char* _Name, const Char* _Def) : Name( _Name ), Definition( _Def ) {}
201 };
202
204 struct ShaderCreationAttribs
205 {
207
209 const Char* FilePath = nullptr;
210
212
215 IShaderSourceInputStreamFactory *pShaderSourceStreamFactory = nullptr;
216
218
228 class IHLSL2GLSLConversionStream **ppConversionStream = nullptr;
229
231
233 const Char* Source = nullptr;
234
236
239 const void *ByteCode = nullptr;
240
242
244 size_t ByteCodeSize = 0;
245
247
249 const Char* EntryPoint = "main";
250
252
254 const ShaderMacro *Macros = nullptr;
255
257 ShaderDesc Desc;
258
260 SHADER_SOURCE_LANGUAGE SourceLanguage = SHADER_SOURCE_LANGUAGE_DEFAULT;
261 };
262
263
265 class IShaderVariable : public IObject
266 {
267 public:
269
273 virtual void Set(IDeviceObject *pObject) = 0;
274
276
284 virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) = 0;
285 };
286
288 class IShader : public IDeviceObject
289 {
290 public:
292 virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
293
295 virtual const ShaderDesc &GetDesc()const = 0;
296
303 virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags ) = 0;
304
307
311 virtual IShaderVariable* GetShaderVariable(const Char* Name) = 0;
312 };
313
314 }
Diligent::ShaderCreationAttribs::Source
const Char * Source
Shader source.
Definition: Shader.h:233
Diligent::IShaderSourceInputStreamFactory
Shader source stream factory interface.
Definition: Shader.h:190
Diligent::ShaderCreationAttribs::EntryPoint
const Char * EntryPoint
Shader entry point.
Definition: Shader.h:249
Diligent::IShader
Shader interface.
Definition: Shader.h:288
Diligent::IDeviceObject
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
Diligent::IShaderVariable
Shader resource variable.
Definition: Shader.h:265
Diligent::ShaderDesc::StaticSamplers
const StaticSamplerDesc * StaticSamplers
Array of static sampler descriptions.
Definition: Shader.h:175
Diligent::BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED
If this flag is specified, only unresolved bindings will be updated. All resolved bindings will keep ...
Definition: Shader.h:91
Diligent::ShaderDesc
Shader description.
Definition: Shader.h:152
Diligent::SHADER_TYPE
SHADER_TYPE
Describes the shader type.
Definition: Shader.h:46
Diligent::ShaderDesc::ShaderType
SHADER_TYPE ShaderType
Shader type. See Diligent::SHADER_TYPE.
Definition: Shader.h:155
Diligent
Graphics engine namespace.
Definition: AdaptiveFixedBlockAllocator.h:30
Diligent::BIND_SHADER_RESOURCES_ALL_RESOLVED
If this flag is specified, all shader bindings are expected to be resolved after the call...
Definition: Shader.h:96
Diligent::ShaderVariableDesc::Type
SHADER_VARIABLE_TYPE Type
Shader variable type. See Diligent::SHADER_VARIABLE_TYPE for a list of allowed types.
Definition: Shader.h:127
Diligent::ShaderDesc::DefaultVariableType
SHADER_VARIABLE_TYPE DefaultVariableType
Default shader variable type. This type will be used if shader variable description is not found in a...
Definition: Shader.h:163
Diligent::SHADER_TYPE_PIXEL
Pixel (fragment) shader.
Definition: Shader.h:50
Diligent::ShaderCreationAttribs::pShaderSourceStreamFactory
IShaderSourceInputStreamFactory * pShaderSourceStreamFactory
Pointer to the shader source input stream factory.
Definition: Shader.h:215
Diligent::StaticSamplerDesc
Static sampler description.
Definition: Shader.h:136
Diligent::SHADER_TYPE_HULL
Hull (tessellation control) shader.
Definition: Shader.h:52
Diligent::IResourceMapping
Resouce mapping.
Definition: ResourceMapping.h:80
Diligent::SHADER_TYPE_DOMAIN
Domain (tessellation evaluation) shader.
Definition: Shader.h:53
Diligent::SHADER_SOURCE_LANGUAGE_GLSL
The source language is GLSL.
Definition: Shader.h:76
Diligent::BIND_SHADER_RESOURCES_RESET_BINDINGS
Reset all bindings. If this flag is specified, all existing bindings will be broken. By default all existing bindings are preserved.
Definition: Shader.h:85
Diligent::ShaderVariableDesc::Name
const Char * Name
Shader variable name.
Definition: Shader.h:124
Diligent::ShaderCreationAttribs::ppConversionStream
class IHLSL2GLSLConversionStream ** ppConversionStream
HLSL->GLSL conversion stream.
Definition: Shader.h:228
Diligent::SHADER_SOURCE_LANGUAGE_DEFAULT
Default language (GLSL for OpenGL/OpenGLES devices, HLSL for Direct3D11/Direct3D12 devices) ...
Definition: Shader.h:70
Diligent::SamplerDesc
Sampler description.
Definition: Sampler.h:52
Diligent::ShaderVariableDesc
Describes shader variable.
Definition: Shader.h:121
Diligent::IShader::GetDesc
virtual const ShaderDesc & GetDesc() const =0
Returns the shader description.
Diligent::SHADER_VARIABLE_TYPE
SHADER_VARIABLE_TYPE
Describes shader variable type that is used by ShaderVariableDesc.
Definition: Shader.h:100
Diligent::Bool
bool Bool
Boolean.
Definition: BasicTypes.h:46
Diligent::StaticSamplerDesc::Desc
SamplerDesc Desc
Sampler description.
Definition: Shader.h:142
Diligent::SHADER_TYPE_VERTEX
Vertex shader.
Definition: Shader.h:49
Diligent::SHADER_SOURCE_LANGUAGE_HLSL
The source language is HLSL.
Definition: Shader.h:73
Diligent::ShaderCreationAttribs::FilePath
const Char * FilePath
Source file path.
Definition: Shader.h:209
Diligent::IShader::GetShaderVariable
virtual IShaderVariable * GetShaderVariable(const Char *Name)=0
Returns an interface to a shader variable. If the shader variable is not found, an interface to a dum...
Diligent::ShaderCreationAttribs::SourceLanguage
SHADER_SOURCE_LANGUAGE SourceLanguage
Shader source language. See Diligent::SHADER_SOURCE_LANGUAGE.
Definition: Shader.h:260
Diligent::IFileStream
Base interface for a file stream.
Definition: FileStream.h:41
Diligent::SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: Shader.h:48
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:36
Diligent::IShader::QueryInterface
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:39
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:900
Diligent::IShaderVariable::Set
virtual void Set(IDeviceObject *pObject)=0
Sets the variable to the given value.
Diligent::SHADER_VARIABLE_TYPE_STATIC
Shader variable is constant across all shader instances. It must be set once directly through IShader...
Definition: Shader.h:105
Diligent::ShaderDesc::VariableDesc
const ShaderVariableDesc * VariableDesc
Array of shader variable descriptions.
Definition: Shader.h:166
Diligent::IShader::BindResources
virtual void BindResources(IResourceMapping *pResourceMapping, Uint32 Flags)=0
Binds shader resources.
Diligent::SHADER_VARIABLE_TYPE_DYNAMIC
Shader variable is dynamic. It can be set multiple times for every instance of shader resource bindin...
Definition: Shader.h:114
Diligent::INTERFACE_ID
Describes unique identifier.
Definition: InterfaceID.h:33
Diligent::ShaderCreationAttribs::Macros
const ShaderMacro * Macros
Shader macros.
Definition: Shader.h:254
Diligent::SHADER_VARIABLE_TYPE_MUTABLE
Shader variable is constant across shader resource bindings instance (see IShaderResourceBinding). It must be set once through IShaderResourceBinding::BindResources() or through the shader variable. It cannot be set through IShader interface.
Definition: Shader.h:110
Diligent::SHADER_VARIABLE_TYPE_NUM_TYPES
Total number of shader variable types.
Definition: Shader.h:117
Diligent::Int32
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:34
Diligent::ShaderDesc::NumVariables
Uint32 NumVariables
Number of elements in VariableDesc array.
Definition: Shader.h:169
Diligent::SHADER_TYPE_COMPUTE
Compute shader.
Definition: Shader.h:54
Diligent::IShaderVariable::SetArray
virtual void SetArray(IDeviceObject *const *ppObjects, Uint32 FirstElement, Uint32 NumElements)=0
Sets the variable array.
Diligent::ShaderCreationAttribs::Desc
ShaderDesc Desc
Shader description. See Diligent::ShaderDesc.
Definition: Shader.h:257
Diligent::ShaderDesc::NumStaticSamplers
Uint32 NumStaticSamplers
Number of static samplers in StaticSamplers array.
Definition: Shader.h:172
Diligent::StaticSamplerDesc::TextureName
const Char * TextureName
Name of the texture variable that static sampler will be assigned to.
Definition: Shader.h:139
Diligent::ShaderCreationAttribs::ByteCode
const void * ByteCode
Compiled shader bytecode.
Definition: Shader.h:239
Diligent::ShaderCreationAttribs
Shader creation attributes.
Definition: Shader.h:204
Diligent::SHADER_TYPE_GEOMETRY
Geometry shader.
Definition: Shader.h:51
Diligent::ShaderCreationAttribs::ByteCodeSize
size_t ByteCodeSize
Size of the compiled shader bytecode.
Definition: Shader.h:244
Diligent::SHADER_SOURCE_LANGUAGE
SHADER_SOURCE_LANGUAGE
Describes shader source code language.
Definition: Shader.h:67
Diligent::BIND_SHADER_RESOURCES_FLAGS
BIND_SHADER_RESOURCES_FLAGS
Describes flags that can be supplied to IShader::BindResources() and IDeviceContext::BindShaderResour...
Definition: Shader.h:81