2
2
// This file is part of the "Nabla Engine".
3
3
// For conditions of distribution and use, see copyright notice in nabla.h
4
4
5
- #ifndef __NBL_ASSET_C_SHADER_INTROSPECTOR_H_INCLUDED__
6
- #define __NBL_ASSET_C_SHADER_INTROSPECTOR_H_INCLUDED__
5
+ #ifndef __NBL_ASSET_C_SPIRV_INTROSPECTOR_H_INCLUDED__
6
+ #define __NBL_ASSET_C_SPIRV_INTROSPECTOR_H_INCLUDED__
7
7
8
8
#include " nbl/core/declarations.h"
9
9
@@ -30,94 +30,92 @@ namespace spirv_cross
30
30
31
31
namespace nbl ::asset
32
32
{
33
-
34
- class NBL_API CIntrospectionData : public core::IReferenceCounted
33
+ class NBL_API2 CSPIRVIntrospector : public core::Uncopyable
35
34
{
36
- protected:
37
- ~CIntrospectionData ();
38
-
39
35
public:
40
- struct SSpecConstant
41
- {
42
- uint32_t id;
43
- size_t byteSize;
44
- E_GLSL_VAR_TYPE type;
45
- std::string name;
46
- union {
47
- uint64_t u64 ;
48
- int64_t i64 ;
49
- uint32_t u32 ;
50
- int32_t i32 ;
51
- double f64 ;
52
- float f32 ;
53
- } defaultValue;
54
- };
55
- // ! Sorted by `id`
56
- core::vector<SSpecConstant> specConstants;
57
- // ! Each vector is sorted by `binding`
58
- core::vector<SShaderResourceVariant> descriptorSetBindings[4 ];
59
- // ! Sorted by `location`
60
- core::vector<SShaderInfoVariant> inputOutput;
61
-
62
- struct {
63
- bool present;
64
- SShaderPushConstant info;
65
- } pushConstant;
66
-
67
- bool canSpecializationlesslyCreateDescSetFrom () const
36
+
37
+ class NBL_API2 CIntrospectionData : public core::IReferenceCounted
68
38
{
69
- for (const auto & descSet : descriptorSetBindings)
39
+ protected:
40
+ ~CIntrospectionData ();
41
+
42
+ public:
43
+ struct SSpecConstant
70
44
{
71
- auto found = std::find_if (descSet.begin (), descSet.end (), [](const SShaderResourceVariant& bnd) { return bnd.descCountIsSpecConstant ; });
72
- if (found != descSet.end ())
73
- return false ;
45
+ uint32_t id;
46
+ size_t byteSize;
47
+ E_GLSL_VAR_TYPE type;
48
+ std::string name;
49
+ union {
50
+ uint64_t u64 ;
51
+ int64_t i64 ;
52
+ uint32_t u32 ;
53
+ int32_t i32 ;
54
+ double f64 ;
55
+ float f32 ;
56
+ } defaultValue;
57
+ };
58
+ // ! Sorted by `id`
59
+ core::vector<SSpecConstant> specConstants;
60
+ // ! Each vector is sorted by `binding`
61
+ core::vector<SShaderResourceVariant> descriptorSetBindings[4 ];
62
+ // ! Sorted by `location`
63
+ core::vector<SShaderInfoVariant> inputOutput;
64
+
65
+ struct {
66
+ bool present;
67
+ SShaderPushConstant info;
68
+ } pushConstant;
69
+
70
+ bool canSpecializationlesslyCreateDescSetFrom () const
71
+ {
72
+ for (const auto & descSet : descriptorSetBindings)
73
+ {
74
+ auto found = std::find_if (descSet.begin (), descSet.end (), [](const SShaderResourceVariant& bnd) { return bnd.descCountIsSpecConstant ; });
75
+ if (found != descSet.end ())
76
+ return false ;
77
+ }
78
+ return true ;
74
79
}
75
- return true ;
76
- }
77
- };
78
-
79
- class NBL_API CSPIRVIntrospector : public core::Uncopyable
80
- {
81
- using mapId2SpecConst_t = core::unordered_map<uint32_t , const CIntrospectionData::SSpecConstant*>;
80
+ };
82
81
83
- public:
84
82
struct SIntrospectionParams
85
83
{
86
84
std::string entryPoint;
87
85
core::smart_refctd_ptr<const ICPUShader> cpuShader;
88
86
89
- bool operator ==(const SIntrospectionParams& rhs) const { return false ; /* TODO*/ }
87
+ bool operator ==(const SIntrospectionParams& rhs) const { return true ; /* TODO*/ }
90
88
};
91
89
92
90
// In the future there's also going list of enabled extensions
93
91
CSPIRVIntrospector () = default ;
94
92
95
93
// ! params.cpuShader.contentType should be ECT_SPIRV
96
- // ! the compiled SPIRV must be compiled with IShaderCompiler::SCompilerOptions::genDebugInfo in order to include names in introspection data
97
- const core::smart_refctd_ptr<CIntrospectionData> introspect (const SIntrospectionParams& params, bool insertToCache = true );
94
+ // ! the compiled SPIRV must be compiled with IShaderCompiler::SCompilerOptions::genDebugInfo with no `spirvOptimizer` used in order to include names in introspection data
95
+ core::smart_refctd_ptr<const CIntrospectionData> introspect (const SIntrospectionParams& params, bool insertToCache = true );
98
96
99
97
//
100
98
std::pair<bool /* is shadow sampler*/ , IImageView<ICPUImage>::E_TYPE> getImageInfoFromIntrospection (uint32_t set, uint32_t binding, const core::SRange<const ICPUSpecializedShader* const >& _shaders);
101
99
102
100
inline core::smart_refctd_dynamic_array<SPushConstantRange> createPushConstantRangesFromIntrospection (const core::SRange<const ICPUSpecializedShader* const >& _shaders)
103
101
{
104
- core::smart_refctd_ptr<CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
102
+ core::smart_refctd_ptr<const CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
105
103
if (!introspectAllShaders (introspections,_shaders))
106
104
return nullptr ;
107
105
108
106
return createPushConstantRangesFromIntrospection_impl (introspections,_shaders);
109
107
}
110
108
inline core::smart_refctd_ptr<ICPUDescriptorSetLayout> createApproximateDescriptorSetLayoutFromIntrospection (uint32_t set, const core::SRange<const ICPUSpecializedShader* const >& _shaders)
111
109
{
112
- core::smart_refctd_ptr<CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
110
+ core::smart_refctd_ptr<const CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
113
111
if (!introspectAllShaders (introspections,_shaders))
114
112
return nullptr ;
115
113
116
114
return createApproximateDescriptorSetLayoutFromIntrospection_impl (set,introspections,_shaders);
117
115
}
118
116
inline core::smart_refctd_ptr<ICPUPipelineLayout> createApproximatePipelineLayoutFromIntrospection (const core::SRange<const ICPUSpecializedShader* const >& _shaders)
119
117
{
120
- core::smart_refctd_ptr<CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
118
+ core::smart_refctd_ptr<const CIntrospectionData> introspections[MAX_STAGE_COUNT] = { nullptr };
121
119
if (!introspectAllShaders (introspections,_shaders))
122
120
return nullptr ;
123
121
@@ -131,7 +129,7 @@ class NBL_API CSPIRVIntrospector : public core::Uncopyable
131
129
return nullptr ;
132
130
133
131
const core::SRange<const ICPUSpecializedShader* const > shaders = {&shader,&shader+1 };
134
- core::smart_refctd_ptr<CIntrospectionData> introspection = nullptr ;
132
+ core::smart_refctd_ptr<const CIntrospectionData> introspection = nullptr ;
135
133
if (!introspectAllShaders (&introspection,shaders))
136
134
return nullptr ;
137
135
@@ -146,14 +144,16 @@ class NBL_API CSPIRVIntrospector : public core::Uncopyable
146
144
core::smart_refctd_ptr<ICPURenderpassIndependentPipeline> createApproximateRenderpassIndependentPipelineFromIntrospection (const core::SRange<ICPUSpecializedShader* const >& _shaders);
147
145
148
146
private:
149
- core::smart_refctd_dynamic_array<SPushConstantRange> createPushConstantRangesFromIntrospection_impl (core::smart_refctd_ptr<CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
150
- core::smart_refctd_ptr<ICPUDescriptorSetLayout> createApproximateDescriptorSetLayoutFromIntrospection_impl (uint32_t _set, core::smart_refctd_ptr<CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
151
- core::smart_refctd_ptr<ICPUPipelineLayout> createApproximatePipelineLayoutFromIntrospection_impl (core::smart_refctd_ptr<CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
147
+ using mapId2SpecConst_t = core::unordered_map<uint32_t , const CIntrospectionData::SSpecConstant*>;
148
+
149
+ core::smart_refctd_dynamic_array<SPushConstantRange> createPushConstantRangesFromIntrospection_impl (core::smart_refctd_ptr<const CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
150
+ core::smart_refctd_ptr<ICPUDescriptorSetLayout> createApproximateDescriptorSetLayoutFromIntrospection_impl (uint32_t _set, core::smart_refctd_ptr<const CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
151
+ core::smart_refctd_ptr<ICPUPipelineLayout> createApproximatePipelineLayoutFromIntrospection_impl (core::smart_refctd_ptr<const CIntrospectionData>* const introspections, const core::SRange<const ICPUSpecializedShader* const >& shaders);
152
152
153
153
_NBL_STATIC_INLINE_CONSTEXPR size_t MAX_STAGE_COUNT = 14ull ;
154
- bool introspectAllShaders (core::smart_refctd_ptr<CIntrospectionData>* introspection, const core::SRange<const ICPUSpecializedShader* const >& _shaders);
154
+ bool introspectAllShaders (core::smart_refctd_ptr<const CIntrospectionData>* introspection, const core::SRange<const ICPUSpecializedShader* const >& _shaders);
155
155
156
- core::smart_refctd_ptr<CIntrospectionData> doIntrospection (spirv_cross::Compiler& _comp, const std::string& entryPoint, const IShader::E_SHADER_STAGE stage) const ;
156
+ core::smart_refctd_ptr<const CIntrospectionData> doIntrospection (spirv_cross::Compiler& _comp, const std::string& entryPoint, const IShader::E_SHADER_STAGE stage) const ;
157
157
void shaderMemBlockIntrospection (spirv_cross::Compiler& _comp, impl::SShaderMemoryBlock& _res, uint32_t _blockBaseTypeID, uint32_t _varID, const mapId2SpecConst_t& _sortedId2sconst) const ;
158
158
size_t calcBytesizeforType (spirv_cross::Compiler& _comp, const spirv_cross::SPIRType& _type) const ;
159
159
@@ -164,7 +164,7 @@ class NBL_API CSPIRVIntrospector : public core::Uncopyable
164
164
std::size_t operator ()(const SIntrospectionParams& t) const { return 0 ; /* TODO*/ }
165
165
};
166
166
167
- using ParamsToDataMap = core::unordered_map<SIntrospectionParams,core::smart_refctd_ptr<CIntrospectionData>, KeyHasher>;
167
+ using ParamsToDataMap = core::unordered_map<SIntrospectionParams,core::smart_refctd_ptr<const CIntrospectionData>, KeyHasher>;
168
168
ParamsToDataMap m_introspectionCache;
169
169
};
170
170
0 commit comments