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 pathVCachedDebuggableShaderData.h
144 lines (113 loc) · 3.43 KB
/
VCachedDebuggableShaderData.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (c) 2018-2020, Zhirnov Andrey. For more information see 'LICENSE'
#pragma once
#ifdef FG_ENABLE_GLSL_TRACE
# include "ShaderTrace.h"
#endif
#ifdef FG_ENABLE_VULKAN
# include "extensions/vulkan_loader/VulkanLoader.h"
#endif
namespace FG
{
template <typename T>
class VCachedDebuggableShaderData;
using VCachedDebuggableShaderModule = VCachedDebuggableShaderData< ShaderModuleVk_t >;
using VCachedDebuggableSpirv = VCachedDebuggableShaderData< Array<uint> >;
//
// Vulkan Cached Shader Data (with debug info)
//
template <typename T>
class VCachedDebuggableShaderData final : public PipelineDescription::IShaderData<T>
{
template <typename B> friend class VCachedDebuggableShaderData;
// types
public:
#ifdef FG_ENABLE_GLSL_TRACE
using ShaderDebugUtils_t = Union< NullUnion, ShaderTrace >;
using ShaderDebugUtilsPtr = UniquePtr< ShaderDebugUtils_t >;
#endif
// variables
private:
T _data;
StaticString<64> _entry;
StaticString<64> _debugName;
#ifdef FG_ENABLE_GLSL_TRACE
ShaderDebugUtilsPtr _debugInfo;
#endif
// methods
public:
VCachedDebuggableShaderData (StringView entry, T &&data, StringView dbgName) :
_data{std::move(data)}, _entry{entry}, _debugName{dbgName}
{}
#ifdef FG_ENABLE_GLSL_TRACE
VCachedDebuggableShaderData (StringView entry, T &&data, StringView dbgName, ShaderDebugUtilsPtr &&debugUtilsPtr) :
_data{std::move(data)}, _entry{entry}, _debugName{dbgName}, _debugInfo{std::move(debugUtilsPtr)}
{}
#endif
#ifdef FG_ENABLE_VULKAN
VCachedDebuggableShaderData (VkShaderModule module, const PipelineDescription::SpirvShaderPtr &spirvCache)
{
if constexpr( IsSameTypes< T, ShaderModuleVk_t > )
{
_data = BitCast<ShaderModuleVk_t>( module );
_entry = spirvCache->GetEntry();
_debugName = spirvCache->GetDebugName();
#ifdef FG_ENABLE_GLSL_TRACE
if ( auto other = DynCast<VCachedDebuggableSpirv>( spirvCache ))
_debugInfo = std::move(other->_debugInfo);
#endif
}
}
#endif
~VCachedDebuggableShaderData ()
{
if constexpr( IsSameTypes< T, ShaderModuleVk_t > )
{
CHECK( _data == VK_NULL_HANDLE );
}
}
#ifdef FG_ENABLE_VULKAN
void Destroy (PFN_vkDestroyShaderModule fpDestroyShaderModule, VkDevice dev)
{
if constexpr( IsSameTypes< T, ShaderModuleVk_t > )
{
if ( _data )
{
fpDestroyShaderModule( dev, BitCast<VkShaderModule>(_data), null );
_data = ShaderModuleVk_t(0);
}
}
}
#endif
bool ParseDebugOutput (EShaderDebugMode mode, ArrayView<uint8_t> debugOutput, OUT Array<String> &result) const override
{
#ifdef FG_ENABLE_GLSL_TRACE
CHECK_ERR( mode == EShaderDebugMode::Trace or
mode == EShaderDebugMode::Profiling );
if ( not _debugInfo )
return false;
return Visit( *_debugInfo,
[&] (const ShaderTrace &trace) { return trace.ParseShaderTrace( debugOutput.data(), debugOutput.size(), OUT result ); },
[] (const NullUnion &) { return false; }
);
#else
Unused( mode, debugOutput, result );
return false;
#endif
}
T const& GetData () const override { return _data; }
StringView GetEntry () const override { return _entry; }
StringView GetDebugName () const override { return _debugName; }
size_t GetHashOfData () const override
{
if constexpr( IsSameTypes< T, ShaderModuleVk_t > )
{
ASSERT(!"not supported");
return 0;
}
else
{
return size_t(HashOf( _data ));
}
}
};
} // FG