1
1
// Copyright (C) 2018-2022 - DevSH Graphics Programming Sp. z O.O.
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
-
5
4
#ifndef _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_
6
5
#define _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_
7
6
@@ -25,115 +24,115 @@ namespace nbl::asset
25
24
@see IDescriptorSet
26
25
*/
27
26
28
- class ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
27
+ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
29
28
{
30
- using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;
31
-
32
- public:
33
- // ! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
34
- // ! @see getDescriptorInfos()
35
- ICPUDescriptorSet (core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t (std::move(_layout)), IAsset()
36
- {
37
- for (uint32_t t = 0u ; t < static_cast <uint32_t >(IDescriptor::E_TYPE::ET_COUNT); ++t)
29
+ using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;
30
+
31
+ public:
32
+ // ! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
33
+ // ! @see getDescriptorInfos()
34
+ inline ICPUDescriptorSet (core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t(std::move(_layout)), IAsset()
35
+ {
36
+ for (uint32_t t = 0u ; t < static_cast <uint32_t >(IDescriptor::E_TYPE::ET_COUNT); ++t)
37
+ {
38
+ const auto type = static_cast <IDescriptor::E_TYPE>(t);
39
+ const uint32_t count = m_layout->getTotalDescriptorCount (type);
40
+ if (count == 0u )
41
+ continue ;
42
+
43
+ m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
44
+ }
45
+ }
46
+
47
+ _NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
48
+ inline E_TYPE getAssetType () const override { return AssetType; }
49
+
50
+ inline ICPUDescriptorSetLayout* getLayout ()
38
51
{
39
- const auto type = static_cast <IDescriptor::E_TYPE>(t);
40
- const uint32_t count = m_layout->getTotalDescriptorCount (type);
41
- if (count == 0u )
42
- continue ;
52
+ assert (!isImmutable_debug ());
53
+ return m_layout.get ();
54
+ }
55
+
56
+ inline const ICPUDescriptorSetLayout* getLayout () const { return m_layout.get (); }
43
57
44
- m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
58
+ inline bool canBeRestoredFrom (const IAsset* _other) const override
59
+ {
60
+ auto * other = static_cast <const ICPUDescriptorSet*>(_other);
61
+ return m_layout->canBeRestoredFrom (other->m_layout .get ());
45
62
}
46
- }
47
-
48
- _NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
49
- inline E_TYPE getAssetType () const override { return AssetType; }
50
-
51
- inline ICPUDescriptorSetLayout* getLayout ()
52
- {
53
- assert (!isImmutable_debug ());
54
- return m_layout.get ();
55
- }
56
-
57
- inline const ICPUDescriptorSetLayout* getLayout () const { return m_layout.get (); }
58
-
59
- inline bool canBeRestoredFrom (const IAsset* _other) const override
60
- {
61
- auto * other = static_cast <const ICPUDescriptorSet*>(_other);
62
- return m_layout->canBeRestoredFrom (other->m_layout .get ());
63
- }
64
-
65
- inline size_t conservativeSizeEstimate () const override
66
- {
67
- assert (!" Invalid code path." );
68
- return 0xdeadbeefull ;
69
- }
70
-
71
- inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage (const IDescriptor::E_TYPE type) const
72
- {
73
- // TODO: @Hazardu
74
- // Cannot do the mutability check here because it requires the function to be non-const, but the function cannot be non-const because it's called
75
- // from const functions in the asset converter.
76
- // Relevant comments/conversations:
77
- // https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
78
- // https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
79
- //
80
- // assert(!isImmutable_debug());
81
- if (!m_descriptorInfos[static_cast <uint32_t >(type)])
82
- return { nullptr , nullptr };
83
- else
84
- return { m_descriptorInfos[static_cast <uint32_t >(type)]->begin (), m_descriptorInfos[static_cast <uint32_t >(type)]->end () };
85
- }
86
-
87
- core::SRange<SDescriptorInfo> getDescriptorInfos (const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
88
-
89
- core::SRange<const SDescriptorInfo> getDescriptorInfos (const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const ;
90
-
91
- core::smart_refctd_ptr<IAsset> clone (uint32_t _depth = ~0u ) const override ;
92
-
93
- void convertToDummyObject (uint32_t referenceLevelsBelowToConvert = 0u ) override ;
94
-
95
- protected:
96
- void restoreFromDummy_impl (IAsset* _other, uint32_t _levelsBelow) override ;
97
-
98
- bool isAnyDependencyDummy_impl (uint32_t _levelsBelow) const override ;
99
-
100
- virtual ~ICPUDescriptorSet () = default ;
101
-
102
- private:
103
- static inline IDescriptor::E_CATEGORY getCategoryFromType (const IDescriptor::E_TYPE type)
104
- {
105
- auto category = IDescriptor::E_CATEGORY::EC_COUNT;
106
- switch (type)
63
+
64
+ inline size_t conservativeSizeEstimate () const override
107
65
{
108
- case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
109
- case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
110
- case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
111
- category = IDescriptor::E_CATEGORY::EC_IMAGE;
112
- break ;
113
-
114
- case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
115
- case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
116
- case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
117
- case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
118
- category = IDescriptor::E_CATEGORY::EC_BUFFER;
119
- break ;
120
-
121
- case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
122
- case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
123
- category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
124
- break ;
125
-
126
- case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
127
- category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
128
- break ;
129
-
130
- default :
131
66
assert (!" Invalid code path." );
67
+ return 0xdeadbeefull ;
68
+ }
69
+
70
+ inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage (const IDescriptor::E_TYPE type) const
71
+ {
72
+ // TODO: @Hazardu
73
+ // Cannot do the mutability check here because it requires the function to be non-const, but the function cannot be non-const because it's called
74
+ // from const functions in the asset converter.
75
+ // Relevant comments/conversations:
76
+ // https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
77
+ // https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
78
+ //
79
+ // assert(!isImmutable_debug());
80
+ if (!m_descriptorInfos[static_cast <uint32_t >(type)])
81
+ return { nullptr , nullptr };
82
+ else
83
+ return { m_descriptorInfos[static_cast <uint32_t >(type)]->begin (), m_descriptorInfos[static_cast <uint32_t >(type)]->end () };
84
+ }
85
+
86
+ core::SRange<SDescriptorInfo> getDescriptorInfos (const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
87
+
88
+ core::SRange<const SDescriptorInfo> getDescriptorInfos (const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const ;
89
+
90
+ core::smart_refctd_ptr<IAsset> clone (uint32_t _depth = ~0u ) const override ;
91
+
92
+ void convertToDummyObject (uint32_t referenceLevelsBelowToConvert = 0u ) override ;
93
+
94
+ protected:
95
+ void restoreFromDummy_impl (IAsset* _other, uint32_t _levelsBelow) override ;
96
+
97
+ bool isAnyDependencyDummy_impl (uint32_t _levelsBelow) const override ;
98
+
99
+ virtual ~ICPUDescriptorSet () = default ;
100
+
101
+ private:
102
+ static inline IDescriptor::E_CATEGORY getCategoryFromType (const IDescriptor::E_TYPE type)
103
+ {
104
+ auto category = IDescriptor::E_CATEGORY::EC_COUNT;
105
+ switch (type)
106
+ {
107
+ case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
108
+ case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
109
+ case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
110
+ category = IDescriptor::E_CATEGORY::EC_IMAGE;
111
+ break ;
112
+
113
+ case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
114
+ case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
115
+ case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
116
+ case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
117
+ category = IDescriptor::E_CATEGORY::EC_BUFFER;
118
+ break ;
119
+
120
+ case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
121
+ case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
122
+ category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
123
+ break ;
124
+
125
+ case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
126
+ category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
127
+ break ;
128
+
129
+ default :
130
+ assert (!" Invalid code path." );
131
+ }
132
+ return category;
132
133
}
133
- return category;
134
- }
135
134
136
- core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast <uint32_t >(IDescriptor::E_TYPE::ET_COUNT)];
135
+ core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast <uint32_t >(IDescriptor::E_TYPE::ET_COUNT)];
137
136
};
138
137
139
138
}
0 commit comments