@@ -23,6 +23,7 @@ class CLumaMeter : public core::TotalInterface
23
23
public:
24
24
_NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_BIN_COUNT = 256u ;
25
25
_NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_BIN_GLOBAL_REPLICATION = 4u ;
26
+ _NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_DESCRIPTOR_COUNT = 3u ;
26
27
27
28
enum E_METERING_MODE
28
29
{
@@ -90,7 +91,18 @@ class CLumaMeter : public core::TotalInterface
90
91
static core::SRange<const asset::SPushConstantRange> getDefaultPushConstantRanges ();
91
92
92
93
//
93
- static core::SRange<const video::IGPUDescriptorSetLayout::SBinding> getDefaultBindings (video::IVideoDriver* driver);
94
+ static core::SRange<const video::IGPUDescriptorSetLayout::SBinding> getDefaultBindings (video::ILogicalDevice* device);
95
+
96
+ //
97
+ static inline core::smart_refctd_ptr<video::IGPUPipelineLayout> getDefaultPipelineLayout (video::ILogicalDevice* device)
98
+ {
99
+ auto pcRange = getDefaultPushConstantRanges ();
100
+ auto bindings = getDefaultBindings (device);
101
+ return device->createGPUPipelineLayout (
102
+ pcRange.begin (), pcRange.end (),
103
+ device->createGPUDescriptorSetLayout (bindings.begin (), bindings.end ()), nullptr , nullptr , nullptr
104
+ );
105
+ }
94
106
95
107
//
96
108
static inline size_t getOutputBufferSize (E_METERING_MODE meterMode, uint32_t arrayLayers=1u )
@@ -118,13 +130,67 @@ class CLumaMeter : public core::TotalInterface
118
130
E_METERING_MODE meterMode, float minLuma=1 .f/2048 .f, float maxLuma=65536 .f
119
131
);
120
132
121
- // we expect user binds correct pipeline, descriptor sets and pushes the push constants by themselves
122
- static inline void dispatchHelper (video::IVideoDriver* driver, const DispatchInfo_t& dispatchInfo, bool issueDefaultBarrier=true )
133
+ template <E_METERING_MODE mode>
134
+ static inline void updateDescriptorSet (
135
+ video::IGPUDescriptorSet* ds,
136
+ const core::smart_refctd_ptr<video::IGPUBuffer> paramUbo,
137
+ const asset::SBufferRange<video::IGPUBuffer>& outputSSBORange,
138
+ const core::smart_refctd_ptr<video::IGPUImageView> inputImageView,
139
+ video::ILogicalDevice* logicalDevice)
123
140
{
124
- driver->dispatch (dispatchInfo.workGroupCount [0 ], dispatchInfo.workGroupCount [1 ], dispatchInfo.workGroupCount [2 ]);
141
+ static_assert (mode < EMM_COUNT, " Invalide meter mode!" );
142
+
143
+ video::IGPUDescriptorSet::SWriteDescriptorSet writes[DEFAULT_DESCRIPTOR_COUNT] = {};
144
+ video::IGPUDescriptorSet::SDescriptorInfo infos[DEFAULT_DESCRIPTOR_COUNT] = {};
145
+
146
+ const asset::E_DESCRIPTOR_TYPE descriptorTypes[DEFAULT_DESCRIPTOR_COUNT] =
147
+ {
148
+ asset::EDT_UNIFORM_BUFFER, // luma input params
149
+ asset::EDT_STORAGE_BUFFER, // luma output buffer
150
+ asset::EDT_COMBINED_IMAGE_SAMPLER // input image
151
+ };
152
+
153
+ infos[0 ].desc = paramUbo;
154
+ infos[0 ].buffer .offset = 0ull ;
155
+ infos[0 ].buffer .size = sizeof (Uniforms_t<mode>);
156
+
157
+ infos[1 ].desc = outputSSBORange.buffer ;
158
+ infos[1 ].buffer .offset = outputSSBORange.offset ;
159
+ infos[1 ].buffer .size = outputSSBORange.size - infos[1 ].buffer .offset ;
125
160
126
- if (issueDefaultBarrier)
127
- defaultBarrier ();
161
+ infos[2 ].desc = inputImageView;
162
+ infos[2 ].image .sampler = nullptr ;
163
+ infos[2 ].image .imageLayout = asset::EIL_SHADER_READ_ONLY_OPTIMAL;
164
+
165
+ for (uint32_t binding = 0u ; binding < DEFAULT_DESCRIPTOR_COUNT; ++binding)
166
+ {
167
+ writes[binding].dstSet = ds;
168
+ writes[binding].binding = binding;
169
+ writes[binding].arrayElement = 0u ;
170
+ writes[binding].count = 1u ;
171
+ writes[binding].descriptorType = descriptorTypes[binding];
172
+ writes[binding].info = infos + binding;
173
+ }
174
+
175
+ logicalDevice->updateDescriptorSets (DEFAULT_DESCRIPTOR_COUNT, writes, 0u , nullptr );
176
+ }
177
+
178
+ // we expect user binds correct pipeline, descriptor sets and pushes the push constants by themselves
179
+ static inline void dispatchHelper (
180
+ video::IGPUCommandBuffer* cmdbuf,
181
+ const DispatchInfo_t& dispatchInfo,
182
+ const asset::E_PIPELINE_STAGE_FLAGS srcStageMask,
183
+ const uint32_t srcBarrierCount,
184
+ const video::IGPUCommandBuffer::SBufferMemoryBarrier* srcBarriers,
185
+ const asset::E_PIPELINE_STAGE_FLAGS dstStageMask,
186
+ const uint32_t dstBarrierCount,
187
+ const video::IGPUCommandBuffer::SBufferMemoryBarrier* dstBarriers)
188
+ {
189
+ if (srcStageMask != asset::E_PIPELINE_STAGE_FLAGS::EPSF_TOP_OF_PIPE_BIT && srcBarrierCount)
190
+ cmdbuf->pipelineBarrier (srcStageMask, asset::EPSF_COMPUTE_SHADER_BIT, asset::EDF_NONE, 0u , nullptr , srcBarrierCount, srcBarriers, 0u , nullptr );
191
+ cmdbuf->dispatch (dispatchInfo.workGroupCount [0 ], dispatchInfo.workGroupCount [1 ], dispatchInfo.workGroupCount [2 ]);
192
+ if (dstStageMask != asset::E_PIPELINE_STAGE_FLAGS::EPSF_BOTTOM_OF_PIPE_BIT && dstBarrierCount)
193
+ cmdbuf->pipelineBarrier (asset::EPSF_COMPUTE_SHADER_BIT, dstStageMask, asset::EDF_NONE, 0u , nullptr , dstBarrierCount, dstBarriers, 0u , nullptr );
128
194
}
129
195
130
196
private:
@@ -155,8 +221,6 @@ class CLumaMeter : public core::TotalInterface
155
221
}
156
222
return retval;
157
223
}
158
-
159
- static void defaultBarrier ();
160
224
};
161
225
162
226
0 commit comments