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 
47 {
52  SHADER_TYPE_HULL = 0x008,
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 
68 {
71 
74 
77 };
78 
82 {
86 
92 
97 };
98 
101 {
106 
111 
115 
118 };
119 
122 {
124  const Char *Name;
125 
128  ShaderVariableDesc(const Char *_Name = nullptr, SHADER_VARIABLE_TYPE _Type = SHADER_VARIABLE_TYPE_STATIC) :
129  Name(_Name),
130  Type(_Type)
131  {}
132 };
133 
134 
137 {
139  const Char* TextureName = nullptr;
140 
143 
144  StaticSamplerDesc(){};
145  StaticSamplerDesc(const Char* _TexName, const SamplerDesc &_Desc) :
146  TextureName(_TexName),
147  Desc(_Desc)
148  {}
149 };
150 
153 {
156 
157  Bool bCacheCompiledShader;
158  SHADER_PROFILE TargetProfile;
159 
164 
167 
170 
173 
176 
177  ShaderDesc() :
179  bCacheCompiledShader(False),
180  TargetProfile(SHADER_PROFILE_DEFAULT),
182  VariableDesc(nullptr),
183  NumVariables(0),
185  StaticSamplers(nullptr)
186  {}
187 };
188 
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 
205 {
207 
209  const Char* FilePath = nullptr;
210 
212 
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 
258 
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 }
const Char * Source
Shader source.
Definition: Shader.h:233
Shader source stream factory interface.
Definition: Shader.h:190
const Char * EntryPoint
Shader entry point.
Definition: Shader.h:249
Shader interface.
Definition: Shader.h:288
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
Shader resource variable.
Definition: Shader.h:265
const StaticSamplerDesc * StaticSamplers
Array of static sampler descriptions.
Definition: Shader.h:175
If this flag is specified, only unresolved bindings will be updated. All resolved bindings will keep ...
Definition: Shader.h:91
Shader description.
Definition: Shader.h:152
SHADER_TYPE
Describes the shader type.
Definition: Shader.h:46
SHADER_TYPE ShaderType
Shader type. See Diligent::SHADER_TYPE.
Definition: Shader.h:155
Graphics engine namespace.
Definition: AdaptiveFixedBlockAllocator.h:30
If this flag is specified, all shader bindings are expected to be resolved after the call...
Definition: Shader.h:96
SHADER_VARIABLE_TYPE Type
Shader variable type. See Diligent::SHADER_VARIABLE_TYPE for a list of allowed types.
Definition: Shader.h:127
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
Pixel (fragment) shader.
Definition: Shader.h:50
IShaderSourceInputStreamFactory * pShaderSourceStreamFactory
Pointer to the shader source input stream factory.
Definition: Shader.h:215
Static sampler description.
Definition: Shader.h:136
Hull (tessellation control) shader.
Definition: Shader.h:52
Resouce mapping.
Definition: ResourceMapping.h:80
Domain (tessellation evaluation) shader.
Definition: Shader.h:53
The source language is GLSL.
Definition: Shader.h:76
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
const Char * Name
Shader variable name.
Definition: Shader.h:124
class IHLSL2GLSLConversionStream ** ppConversionStream
HLSL->GLSL conversion stream.
Definition: Shader.h:228
Default language (GLSL for OpenGL/OpenGLES devices, HLSL for Direct3D11/Direct3D12 devices) ...
Definition: Shader.h:70
Sampler description.
Definition: Sampler.h:52
Describes shader variable.
Definition: Shader.h:121
virtual const ShaderDesc & GetDesc() const =0
Returns the shader description.
SHADER_VARIABLE_TYPE
Describes shader variable type that is used by ShaderVariableDesc.
Definition: Shader.h:100
bool Bool
Boolean.
Definition: BasicTypes.h:46
SamplerDesc Desc
Sampler description.
Definition: Shader.h:142
Vertex shader.
Definition: Shader.h:49
The source language is HLSL.
Definition: Shader.h:73
const Char * FilePath
Source file path.
Definition: Shader.h:209
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...
SHADER_SOURCE_LANGUAGE SourceLanguage
Shader source language. See Diligent::SHADER_SOURCE_LANGUAGE.
Definition: Shader.h:260
Base interface for a file stream.
Definition: FileStream.h:41
Unknown shader type.
Definition: Shader.h:48
Base interface for all dynamic objects in the engine.
Definition: Object.h:36
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:39
Describes common device object attributes.
Definition: GraphicsTypes.h:900
virtual void Set(IDeviceObject *pObject)=0
Sets the variable to the given value.
Shader variable is constant across all shader instances. It must be set once directly through IShader...
Definition: Shader.h:105
const ShaderVariableDesc * VariableDesc
Array of shader variable descriptions.
Definition: Shader.h:166
virtual void BindResources(IResourceMapping *pResourceMapping, Uint32 Flags)=0
Binds shader resources.
Shader variable is dynamic. It can be set multiple times for every instance of shader resource bindin...
Definition: Shader.h:114
Describes unique identifier.
Definition: InterfaceID.h:33
const ShaderMacro * Macros
Shader macros.
Definition: Shader.h:254
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
Total number of shader variable types.
Definition: Shader.h:117
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:34
Uint32 NumVariables
Number of elements in VariableDesc array.
Definition: Shader.h:169
Compute shader.
Definition: Shader.h:54
virtual void SetArray(IDeviceObject *const *ppObjects, Uint32 FirstElement, Uint32 NumElements)=0
Sets the variable array.
ShaderDesc Desc
Shader description. See Diligent::ShaderDesc.
Definition: Shader.h:257
Uint32 NumStaticSamplers
Number of static samplers in StaticSamplers array.
Definition: Shader.h:172
const Char * TextureName
Name of the texture variable that static sampler will be assigned to.
Definition: Shader.h:139
const void * ByteCode
Compiled shader bytecode.
Definition: Shader.h:239
Shader creation attributes.
Definition: Shader.h:204
Geometry shader.
Definition: Shader.h:51
size_t ByteCodeSize
Size of the compiled shader bytecode.
Definition: Shader.h:244
SHADER_SOURCE_LANGUAGE
Describes shader source code language.
Definition: Shader.h:67
BIND_SHADER_RESOURCES_FLAGS
Describes flags that can be supplied to IShader::BindResources() and IDeviceContext::BindShaderResour...
Definition: Shader.h:81