Diligent Engine  v.2.4.g
ShaderBase.hpp
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 <vector>
34 
35 #include "Shader.h"
36 #include "DeviceObjectBase.hpp"
37 #include "STDAllocator.hpp"
38 #include "PlatformMisc.hpp"
39 #include "EngineMemory.h"
40 #include "Align.hpp"
41 
42 namespace Diligent
43 {
44 
46 
48 template <typename EngineImplTraits>
49 class ShaderBase : public DeviceObjectBase<typename EngineImplTraits::ShaderInterface, typename EngineImplTraits::RenderDeviceImplType, ShaderDesc>
50 {
51 public:
52  // Base interface this class inherits (IShaderD3D12, IShaderVk, etc.)
53  using BaseInterface = typename EngineImplTraits::ShaderInterface;
54 
55  // Render device implementation type (RenderDeviceD3D12Impl, RenderDeviceVkImpl, etc.).
56  using RenderDeviceImplType = typename EngineImplTraits::RenderDeviceImplType;
57 
59 
66  RenderDeviceImplType* pDevice,
67  const ShaderDesc& ShdrDesc,
68  bool bIsDeviceInternal = false) :
69  TDeviceObjectBase{pRefCounters, pDevice, ShdrDesc, bIsDeviceInternal}
70  {
71  const auto& deviceFeatures = pDevice->GetDeviceCaps().Features;
72  if (ShdrDesc.ShaderType == SHADER_TYPE_GEOMETRY && !deviceFeatures.GeometryShaders)
73  LOG_ERROR_AND_THROW("Geometry shaders are not supported by this device.");
74 
75  if ((ShdrDesc.ShaderType == SHADER_TYPE_DOMAIN || ShdrDesc.ShaderType == SHADER_TYPE_HULL) && !deviceFeatures.Tessellation)
76  LOG_ERROR_AND_THROW("Tessellation shaders are not supported by this device.");
77 
78  if (ShdrDesc.ShaderType == SHADER_TYPE_COMPUTE && !deviceFeatures.ComputeShaders)
79  LOG_ERROR_AND_THROW("Compute shaders are not supported by this device.");
80 
81  if ((ShdrDesc.ShaderType == SHADER_TYPE_AMPLIFICATION || ShdrDesc.ShaderType == SHADER_TYPE_MESH) && !deviceFeatures.MeshShaders)
82  LOG_ERROR_AND_THROW("Mesh shaders are not supported by this device.");
83 
84  if ((ShdrDesc.ShaderType >= SHADER_TYPE_RAY_GEN && ShdrDesc.ShaderType <= SHADER_TYPE_CALLABLE) && !deviceFeatures.RayTracing)
85  LOG_ERROR_AND_THROW("Ray tracing shaders are not supported by this device.");
86  }
87 
89 };
90 
91 } // namespace Diligent
Diligent::SHADER_TYPE_AMPLIFICATION
@ SHADER_TYPE_AMPLIFICATION
Amplification (task) shader.
Definition: GraphicsTypes.h:74
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::SHADER_TYPE_RAY_GEN
@ SHADER_TYPE_RAY_GEN
Ray generation shader.
Definition: GraphicsTypes.h:76
Align.hpp
LOG_ERROR_AND_THROW
#define LOG_ERROR_AND_THROW(...)
Definition: Errors.hpp:101
DeviceObjectBase.hpp
Diligent::SHADER_TYPE_DOMAIN
@ SHADER_TYPE_DOMAIN
Domain (tessellation evaluation) shader.
Definition: GraphicsTypes.h:72
STDAllocator.hpp
Shader.h
Diligent::SHADER_TYPE_COMPUTE
@ SHADER_TYPE_COMPUTE
Compute shader.
Definition: GraphicsTypes.h:73
Diligent::ShaderBase
Template class implementing base functionality of the shader object.
Definition: ShaderBase.hpp:49
EngineMemory.h
Diligent::ShaderDesc
Shader description.
Definition: Shader.h:110
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
Diligent::ShaderBase::TDeviceObjectBase
DeviceObjectBase< BaseInterface, RenderDeviceImplType, ShaderDesc > TDeviceObjectBase
Definition: ShaderBase.hpp:58
Diligent::ShaderBase::ShaderBase
ShaderBase(IReferenceCounters *pRefCounters, RenderDeviceImplType *pDevice, const ShaderDesc &ShdrDesc, bool bIsDeviceInternal=false)
Definition: ShaderBase.hpp:65
Diligent::SHADER_TYPE_HULL
@ SHADER_TYPE_HULL
Hull (tessellation control) shader.
Definition: GraphicsTypes.h:71
Diligent::ShaderBase< EngineGLImplTraits >::BaseInterface
typename EngineGLImplTraits ::ShaderInterface BaseInterface
Definition: ShaderBase.hpp:53
Diligent::SHADER_TYPE_GEOMETRY
@ SHADER_TYPE_GEOMETRY
Geometry shader.
Definition: GraphicsTypes.h:70
Diligent::SHADER_TYPE_CALLABLE
@ SHADER_TYPE_CALLABLE
Callable shader.
Definition: GraphicsTypes.h:81
Diligent::ShaderBase< EngineGLImplTraits >::RenderDeviceImplType
typename EngineGLImplTraits ::RenderDeviceImplType RenderDeviceImplType
Definition: ShaderBase.hpp:56
Diligent::SHADER_TYPE_MESH
@ SHADER_TYPE_MESH
Mesh shader.
Definition: GraphicsTypes.h:75
Diligent::DeviceObjectBase
Template class implementing base functionality of the device object.
Definition: DeviceObjectBase.hpp:45
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
PlatformMisc.hpp