This repository was archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathVPipelineCompiler.h
104 lines (76 loc) · 3.44 KB
/
VPipelineCompiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2018-2020, Zhirnov Andrey. For more information see 'LICENSE'
#pragma once
#include "EShaderCompilationFlags.h"
#include "framegraph/Shared/HashCollisionCheck.h"
#include "framegraph/Public/VulkanTypes.h"
#include <mutex>
namespace FG
{
//
// Vulkan Pipeline Compiler
//
class VPipelineCompiler final : public IPipelineCompiler
{
// types
private:
using StringShaderData = PipelineDescription::ShaderSourcePtr;
using BinaryShaderData = PipelineDescription::SpirvShaderPtr;
using VkShaderPtr = PipelineDescription::VkShaderPtr;
struct BinaryShaderDataHash {
ND_ size_t operator () (const BinaryShaderData &value) const {
return value->GetHashOfData();
}
};
using ShaderCache_t = HashMap< BinaryShaderData, VkShaderPtr >;
using ShaderDataMap_t = PipelineDescription::ShaderDataMap_t;
// variables
private:
Mutex _lock;
Array< String > _directories;
UniquePtr< class SpirvCompiler > _spirvCompiler;
ShaderCache_t _shaderCache;
EShaderCompilationFlags _compilerFlags = Default;
DEBUG_ONLY(
HashCollisionCheck<> _hashCollisionCheck; // for uniforms and descriptor sets
)
// immutable:
InstanceVk_t _vkInstance = Zero;
PhysicalDeviceVk_t _vkPhysicalDevice = Zero;
DeviceVk_t _vkLogicalDevice = Zero;
void * _fpCreateShaderModule = null;
void * _fpDestroyShaderModule = null;
// methods
public:
VPipelineCompiler ();
VPipelineCompiler (InstanceVk_t instance, PhysicalDeviceVk_t physicalDevice, DeviceVk_t device);
~VPipelineCompiler ();
bool SetCompilationFlags (EShaderCompilationFlags flags);
void AddDirectory (StringView path);
// set debug flags for all shaders
void SetDebugFlags (EShaderLangFormat flags);
ND_ EShaderCompilationFlags GetCompilationFlags () { EXLOCK( _lock ); return _compilerFlags; }
void ReleaseUnusedShaders ();
void ReleaseShaderCache ();
bool IsSupported (const MeshPipelineDesc &ppln, EShaderLangFormat dstFormat) const override;
bool IsSupported (const RayTracingPipelineDesc &ppln, EShaderLangFormat dstFormat) const override;
bool IsSupported (const GraphicsPipelineDesc &ppln, EShaderLangFormat dstFormat) const override;
bool IsSupported (const ComputePipelineDesc &ppln, EShaderLangFormat dstFormat) const override;
bool Compile (INOUT MeshPipelineDesc &ppln, EShaderLangFormat dstFormat) override;
bool Compile (INOUT RayTracingPipelineDesc &ppln, EShaderLangFormat dstFormat) override;
bool Compile (INOUT GraphicsPipelineDesc &ppln, EShaderLangFormat dstFormat) override;
bool Compile (INOUT ComputePipelineDesc &ppln, EShaderLangFormat dstFormat) override;
private:
bool _MergePipelineResources (const PipelineDescription::PipelineLayout &srcLayout,
INOUT PipelineDescription::PipelineLayout &dstLayout) const;
bool _MergeUniforms (const PipelineDescription::UniformMap_t &srcUniforms,
INOUT PipelineDescription::UniformMap_t &dstUniforms) const;
bool _CreateVulkanShader (INOUT PipelineDescription::Shader &shader);
static bool _IsSupported (const ShaderDataMap_t &data);
void _CheckHashCollision (const MeshPipelineDesc &);
void _CheckHashCollision (const RayTracingPipelineDesc &);
void _CheckHashCollision (const GraphicsPipelineDesc &);
void _CheckHashCollision (const ComputePipelineDesc &);
void _CheckHashCollision2 (const PipelineDescription &);
bool _CheckDescriptorBindings (const PipelineDescription &) const;
};
} // FG