Skip to content

Commit 207daec

Browse files
fix bugs introduced by previous change
1 parent 6064a9d commit 207daec

File tree

3 files changed

+65
-90
lines changed

3 files changed

+65
-90
lines changed

examples_tests/49.ComputeFFT/main.cpp

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -267,31 +267,14 @@ int main()
267267
// input pipeline
268268
auto imageFirstFFTPipelineLayout = [driver]() -> auto
269269
{
270-
IGPUSampler::SParams params =
271-
{
272-
{
273-
ISampler::ETC_REPEAT,
274-
ISampler::ETC_REPEAT,
275-
ISampler::ETC_REPEAT,
276-
ISampler::ETBC_FLOAT_OPAQUE_BLACK,
277-
ISampler::ETF_LINEAR, // is it needed?
278-
ISampler::ETF_LINEAR,
279-
ISampler::ESMM_NEAREST,
280-
0u,
281-
0u,
282-
ISampler::ECO_ALWAYS
283-
}
284-
};
285-
auto sampler = driver->createGPUSampler(std::move(params));
286-
287270
IGPUDescriptorSetLayout::SBinding bnd[] =
288271
{
289272
{
290273
0u,
291274
EDT_COMBINED_IMAGE_SAMPLER,
292275
1u,
293276
ISpecializedShader::ESS_COMPUTE,
294-
&sampler
277+
nullptr
295278
},
296279
{
297280
1u,
@@ -361,15 +344,61 @@ int main()
361344
}();
362345

363346
const VkExtent3D paddedDim = FFTClass::padDimensionToNextPOT(srcDim);
364-
auto fftPipeline_ImageInput = driver->createGPUComputePipeline(nullptr,core::smart_refctd_ptr(imageFirstFFTPipelineLayout),createShader(driver, paddedDim.height, "../image_first_fft.comp"));
365-
auto convolvePipeline = driver->createGPUComputePipeline(nullptr, core::smart_refctd_ptr(convolvePipelineLayout), createShader(driver, paddedDim.height, "../fft_convolve_ifft.comp"));
366-
auto lastFFTPipeline = driver->createGPUComputePipeline(nullptr, getPipelineLayout_LastFFT(driver), createShader(driver, paddedDim.width, "../last_fft.comp"));
367-
368347
// Allocate Output Buffer
369348
auto fftOutputBuffer_0 = driver->createDeviceLocalGPUBufferOnDedMem(FFTClass::getOutputBufferSize(paddedDim, srcNumChannels)); // result of: srcFFTX and kerFFTX and Convolution and IFFTY
370349
auto fftOutputBuffer_1 = driver->createDeviceLocalGPUBufferOnDedMem(FFTClass::getOutputBufferSize(paddedDim, srcNumChannels)); // result of: srcFFTY and IFFTX
371350
core::smart_refctd_ptr<IGPUImageView> kernelNormalizedSpectrums[channelCountOverride];
372351

352+
auto updateDescriptorSet = [driver](video::IGPUDescriptorSet* set, core::smart_refctd_ptr<IGPUImageView> inputImageDescriptor, asset::ISampler::E_TEXTURE_CLAMP textureWrap, core::smart_refctd_ptr<IGPUBuffer> outputBufferDescriptor) -> void
353+
{
354+
IGPUSampler::SParams params =
355+
{
356+
{
357+
textureWrap,
358+
textureWrap,
359+
textureWrap,
360+
ISampler::ETBC_FLOAT_OPAQUE_BLACK,
361+
ISampler::ETF_LINEAR,
362+
ISampler::ETF_LINEAR,
363+
ISampler::ESMM_LINEAR,
364+
8u,
365+
0u,
366+
ISampler::ECO_ALWAYS
367+
}
368+
};
369+
auto sampler = driver->createGPUSampler(std::move(params));
370+
371+
constexpr auto kDescriptorCount = 2u;
372+
video::IGPUDescriptorSet::SDescriptorInfo pInfos[kDescriptorCount];
373+
video::IGPUDescriptorSet::SWriteDescriptorSet pWrites[kDescriptorCount];
374+
375+
for (auto i=0; i<kDescriptorCount; i++)
376+
{
377+
pWrites[i].dstSet = set;
378+
pWrites[i].arrayElement = 0u;
379+
pWrites[i].count = 1u;
380+
pWrites[i].info = pInfos+i;
381+
}
382+
383+
// Input Buffer
384+
pWrites[0].binding = 0;
385+
pWrites[0].descriptorType = asset::EDT_COMBINED_IMAGE_SAMPLER;
386+
pWrites[0].count = 1;
387+
pInfos[0].desc = inputImageDescriptor;
388+
pInfos[0].image.sampler = sampler;
389+
pInfos[0].image.imageLayout = static_cast<asset::E_IMAGE_LAYOUT>(0u);
390+
391+
// Output Buffer
392+
pWrites[1].binding = 1;
393+
pWrites[1].descriptorType = asset::EDT_STORAGE_BUFFER;
394+
pWrites[1].count = 1;
395+
pInfos[1].desc = outputBufferDescriptor;
396+
pInfos[1].buffer.size = outputBufferDescriptor->getSize();
397+
pInfos[1].buffer.offset = 0u;
398+
399+
driver->updateDescriptorSets(2u, pWrites, 0u, nullptr);
400+
};
401+
373402
// Precompute Kernel FFT
374403
{
375404
const auto kerDim = kerImageView->getCreationParameters().image->getCreationParameters().extent;
@@ -403,7 +432,7 @@ int main()
403432

404433
// Ker FFT X
405434
auto fftDescriptorSet_Ker_FFT_X = driver->createGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(imageFirstFFTPipelineLayout->getDescriptorSetLayout(0u)));
406-
FFTClass::updateDescriptorSet(driver, fftDescriptorSet_Ker_FFT_X.get(), kerImageView, fftOutputBuffer_0, ISampler::ETC_CLAMP_TO_BORDER);
435+
updateDescriptorSet(fftDescriptorSet_Ker_FFT_X.get(), kerImageView, ISampler::ETC_CLAMP_TO_BORDER, fftOutputBuffer_0);
407436

408437
// Ker FFT Y
409438
auto fftPipeline_SSBOInput = FFTClass::getDefaultPipeline(driver,kerDim.height);
@@ -487,10 +516,13 @@ int main()
487516
auto fftDispatchInfo_Vertical = FFTClass::buildParameters(paddedKerDim, FFTClass::Direction::Y);
488517

489518
// Ker Image FFT X
490-
driver->bindComputePipeline(fftPipeline_ImageInput.get());
491-
driver->bindDescriptorSets(EPBP_COMPUTE, imageFirstFFTPipelineLayout.get(), 0u, 1u, &fftDescriptorSet_Ker_FFT_X.get(), nullptr);
492-
FFTClass::pushConstants(driver, imageFirstFFTPipelineLayout.get(), kerDim, paddedKerDim, FFTClass::Direction::X, false, srcNumChannels, FFTClass::PaddingType::FILL_WITH_ZERO);
493-
FFTClass::dispatchHelper(driver, fftDispatchInfo_Horizontal);
519+
{
520+
auto fftPipeline_ImageInput = driver->createGPUComputePipeline(nullptr,core::smart_refctd_ptr(imageFirstFFTPipelineLayout),createShader(driver, paddedKerDim.width, "../image_first_fft.comp"));
521+
driver->bindComputePipeline(fftPipeline_ImageInput.get());
522+
driver->bindDescriptorSets(EPBP_COMPUTE, imageFirstFFTPipelineLayout.get(), 0u, 1u, &fftDescriptorSet_Ker_FFT_X.get(), nullptr);
523+
FFTClass::pushConstants(driver, imageFirstFFTPipelineLayout.get(), kerDim, paddedKerDim, FFTClass::Direction::X, false, srcNumChannels, FFTClass::PaddingType::FILL_WITH_ZERO);
524+
FFTClass::dispatchHelper(driver, fftDispatchInfo_Horizontal);
525+
}
494526

495527
// Ker Image FFT Y
496528
driver->bindComputePipeline(fftPipeline_SSBOInput.get());
@@ -525,10 +557,15 @@ int main()
525557
FFTClass::defaultBarrier();
526558
}
527559
}
560+
561+
// pipelines
562+
auto fftPipeline_ImageInput = driver->createGPUComputePipeline(nullptr,core::smart_refctd_ptr(imageFirstFFTPipelineLayout),createShader(driver, paddedDim.width, "../image_first_fft.comp"));
563+
auto convolvePipeline = driver->createGPUComputePipeline(nullptr, core::smart_refctd_ptr(convolvePipelineLayout), createShader(driver, paddedDim.height, "../fft_convolve_ifft.comp"));
564+
auto lastFFTPipeline = driver->createGPUComputePipeline(nullptr, getPipelineLayout_LastFFT(driver), createShader(driver, paddedDim.width, "../last_fft.comp"));
528565

529566
// Src FFT X
530567
auto fftDescriptorSet_Src_FFT_X = driver->createGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(imageFirstFFTPipelineLayout->getDescriptorSetLayout(0u)));
531-
FFTClass::updateDescriptorSet(driver, fftDescriptorSet_Src_FFT_X.get(), srcImageView, fftOutputBuffer_0, ISampler::ETC_MIRROR);
568+
updateDescriptorSet(fftDescriptorSet_Src_FFT_X.get(), srcImageView, ISampler::ETC_MIRROR, fftOutputBuffer_0);
532569

533570
// Convolution
534571
auto convolveDescriptorSet = driver->createGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(convolvePipeline->getLayout()->getDescriptorSetLayout(0u)));

include/nbl/ext/FFT/FFT.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -157,45 +157,6 @@ class FFT : public core::TotalInterface
157157
driver->updateDescriptorSets(2u, pWrites, 0u, nullptr);
158158
}
159159

160-
static inline void updateDescriptorSet(
161-
video::IVideoDriver * driver,
162-
video::IGPUDescriptorSet * set,
163-
core::smart_refctd_ptr<video::IGPUImageView> inputImageDescriptor,
164-
core::smart_refctd_ptr<video::IGPUBuffer> outputBufferDescriptor,
165-
asset::ISampler::E_TEXTURE_CLAMP textureWrap)
166-
{
167-
auto sampler = getSampler(driver,textureWrap);
168-
169-
video::IGPUDescriptorSet::SDescriptorInfo pInfos[MAX_DESCRIPTOR_COUNT];
170-
video::IGPUDescriptorSet::SWriteDescriptorSet pWrites[MAX_DESCRIPTOR_COUNT];
171-
172-
for (auto i = 0; i < MAX_DESCRIPTOR_COUNT; i++)
173-
{
174-
pWrites[i].dstSet = set;
175-
pWrites[i].arrayElement = 0u;
176-
pWrites[i].count = 1u;
177-
pWrites[i].info = pInfos+i;
178-
}
179-
180-
// Input Buffer
181-
pWrites[0].binding = 0;
182-
pWrites[0].descriptorType = asset::EDT_COMBINED_IMAGE_SAMPLER;
183-
pWrites[0].count = 1;
184-
pInfos[0].desc = inputImageDescriptor;
185-
pInfos[0].image.sampler = sampler;
186-
pInfos[0].image.imageLayout = static_cast<asset::E_IMAGE_LAYOUT>(0u);;
187-
188-
// Output Buffer
189-
pWrites[1].binding = 1;
190-
pWrites[1].descriptorType = asset::EDT_STORAGE_BUFFER;
191-
pWrites[1].count = 1;
192-
pInfos[1].desc = outputBufferDescriptor;
193-
pInfos[1].buffer.size = outputBufferDescriptor->getSize();
194-
pInfos[1].buffer.offset = 0u;
195-
196-
driver->updateDescriptorSets(2u, pWrites, 0u, nullptr);
197-
}
198-
199160
static inline void dispatchHelper(
200161
video::IVideoDriver* driver,
201162
const DispatchInfo_t& dispatchInfo,
@@ -242,8 +203,6 @@ class FFT : public core::TotalInterface
242203
private:
243204
FFT() = delete;
244205
//~FFT() = delete;
245-
246-
static core::smart_refctd_ptr<video::IGPUSampler> getSampler(video::IVideoDriver* driver, asset::ISampler::E_TEXTURE_CLAMP textureWrap);
247206
};
248207

249208

src/nbl/ext/FFT/FFT.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@ core::SRange<const SPushConstantRange> FFT::getDefaultPushConstantRanges()
2525
return {ranges, ranges+1};
2626
}
2727

28-
core::smart_refctd_ptr<IGPUSampler> FFT::getSampler(IVideoDriver* driver,ISampler::E_TEXTURE_CLAMP textureWrap)
29-
{
30-
IGPUSampler::SParams params =
31-
{
32-
{
33-
textureWrap,
34-
textureWrap,
35-
textureWrap,
36-
ISampler::ETBC_FLOAT_TRANSPARENT_BLACK,
37-
ISampler::ETF_NEAREST,
38-
ISampler::ETF_NEAREST,
39-
ISampler::ESMM_NEAREST,
40-
0u,
41-
0u,
42-
ISampler::ECO_ALWAYS
43-
}
44-
};
45-
// TODO: cache using the asset manager's caches
46-
return driver->createGPUSampler(params);
47-
}
48-
4928
core::smart_refctd_ptr<IGPUDescriptorSetLayout> FFT::getDefaultDescriptorSetLayout(IVideoDriver* driver)
5029
{
5130
static IGPUDescriptorSetLayout::SBinding bnd[] =

0 commit comments

Comments
 (0)