@@ -34,9 +34,9 @@ inline smart_refctd_ptr<IGPUPipelineLayout> getPipelineLayout_Convolution(IVideo
34
34
IGPUSampler::SParams params =
35
35
{
36
36
{
37
- ISampler::ETC_CLAMP_TO_BORDER ,
38
- ISampler::ETC_CLAMP_TO_BORDER ,
39
- ISampler::ETC_CLAMP_TO_BORDER ,
37
+ ISampler::ETC_REPEAT ,
38
+ ISampler::ETC_REPEAT ,
39
+ ISampler::ETC_REPEAT ,
40
40
ISampler::ETBC_FLOAT_OPAQUE_BLACK,
41
41
ISampler::ETF_LINEAR, // is it needed?
42
42
ISampler::ETF_LINEAR,
@@ -350,45 +350,9 @@ int main()
350
350
// TODO: re-examine
351
351
const VkExtent3D paddedDim = FFTClass::padDimensionToNextPOT (srcDim);
352
352
auto fftGPUSpecializedShader_ImageInput = FFTClass::createShader (driver, FFTClass::DataType::TEXTURE2D, paddedDim.width );
353
- auto fftGPUSpecializedShader_KernelNormalization = [&]() -> auto
354
- {
355
- IAssetLoader::SAssetLoadParams lp;
356
- auto shaderAsset = am->getAsset (" ../normalization.comp" , lp);
357
- auto stuff = driver->getGPUObjectsFromAssets <asset::ICPUSpecializedShader>(shaderAsset.getContents (),nullptr );
358
- return *stuff->begin ();
359
- }();
360
353
361
354
auto fftPipelineLayout_ImageInput = FFTClass::getDefaultPipelineLayout (driver, FFTClass::DataType::TEXTURE2D);
362
- auto fftPipelineLayout_KernelNormalization = [&]() -> auto
363
- {
364
- IGPUDescriptorSetLayout::SBinding bnd[] =
365
- {
366
- {
367
- 0u ,
368
- EDT_STORAGE_BUFFER,
369
- 1u ,
370
- ISpecializedShader::ESS_COMPUTE,
371
- nullptr
372
- },
373
- {
374
- 1u ,
375
- EDT_STORAGE_IMAGE,
376
- channelCountOverride,
377
- ISpecializedShader::ESS_COMPUTE,
378
- nullptr
379
- },
380
- };
381
- return driver->createGPUPipelineLayout (
382
- nullptr ,nullptr ,
383
- driver->createGPUDescriptorSetLayout (bnd,bnd+2 ),nullptr ,nullptr ,nullptr
384
- );
385
- }();
386
-
387
355
auto fftPipeline_ImageInput = driver->createGPUComputePipeline (nullptr , core::smart_refctd_ptr (fftPipelineLayout_ImageInput), std::move (fftGPUSpecializedShader_ImageInput));
388
- auto fftPipeline_KernelNormalization = driver->createGPUComputePipeline (nullptr , core::smart_refctd_ptr (fftPipelineLayout_KernelNormalization), std::move (fftGPUSpecializedShader_KernelNormalization));
389
-
390
- auto fftDispatchInfo_Horizontal = FFTClass::buildParameters (paddedDim, FFTClass::Direction::X);
391
- auto fftDispatchInfo_Vertical = FFTClass::buildParameters (paddedDim, FFTClass::Direction::Y);
392
356
393
357
auto convolveShader = createShader_Convolution (driver, am, paddedDim.height );
394
358
auto convolvePipelineLayout = getPipelineLayout_Convolution (driver);
@@ -401,35 +365,39 @@ int main()
401
365
// Allocate Output Buffer
402
366
auto fftOutputBuffer_0 = driver->createDeviceLocalGPUBufferOnDedMem (FFTClass::getOutputBufferSize (paddedDim, srcNumChannels)); // result of: srcFFTX and kerFFTX and Convolution and IFFTY
403
367
auto fftOutputBuffer_1 = driver->createDeviceLocalGPUBufferOnDedMem (FFTClass::getOutputBufferSize (paddedDim, srcNumChannels)); // result of: srcFFTY and IFFTX
404
- auto createKernelSpectrum = [&]() -> auto
405
- {
406
- video::IGPUImage::SCreationParams imageParams;
407
- imageParams.flags = static_cast <asset::IImage::E_CREATE_FLAGS>(0u );
408
- imageParams.type = asset::IImage::ET_2D;
409
- imageParams.format = asset::EF_R16G16_SFLOAT;
410
- imageParams.extent = {paddedDim.width ,paddedDim.height ,1u };
411
- imageParams.mipLevels = 1u ;
412
- imageParams.arrayLayers = 1u ;
413
- imageParams.samples = asset::IImage::ESCF_1_BIT;
414
-
415
- video::IGPUImageView::SCreationParams viewParams;
416
- viewParams.flags = static_cast <video::IGPUImageView::E_CREATE_FLAGS>(0u );
417
- viewParams.image = driver->createGPUImageOnDedMem (std::move (imageParams),driver->getDeviceLocalGPUMemoryReqs ());
418
- viewParams.viewType = video::IGPUImageView::ET_2D;
419
- viewParams.format = asset::EF_R16G16_SFLOAT;
420
- viewParams.components = {};
421
- viewParams.subresourceRange = {};
422
- viewParams.subresourceRange .levelCount = 1u ;
423
- viewParams.subresourceRange .layerCount = 1u ;
424
- return driver->createGPUImageView (std::move (viewParams));
425
- };
426
368
core::smart_refctd_ptr<IGPUImageView> kernelNormalizedSpectrums[channelCountOverride];
427
- for (uint32_t i=0u ; i<channelCountOverride; i++)
428
- kernelNormalizedSpectrums[i] = createKernelSpectrum ();
429
369
430
370
// Precompute Kernel FFT
431
- const auto kerDim = kerImageView->getCreationParameters ().image ->getCreationParameters ().extent ;
432
371
{
372
+ const auto kerDim = kerImageView->getCreationParameters ().image ->getCreationParameters ().extent ;
373
+ const VkExtent3D paddedKerDim = FFTClass::padDimensionToNextPOT (kerDim);
374
+
375
+ // create kernel spectrums
376
+ auto createKernelSpectrum = [&]() -> auto
377
+ {
378
+ video::IGPUImage::SCreationParams imageParams;
379
+ imageParams.flags = static_cast <asset::IImage::E_CREATE_FLAGS>(0u );
380
+ imageParams.type = asset::IImage::ET_2D;
381
+ imageParams.format = asset::EF_R16G16_SFLOAT;
382
+ imageParams.extent = { paddedKerDim.width ,paddedKerDim.height ,1u };
383
+ imageParams.mipLevels = 1u ;
384
+ imageParams.arrayLayers = 1u ;
385
+ imageParams.samples = asset::IImage::ESCF_1_BIT;
386
+
387
+ video::IGPUImageView::SCreationParams viewParams;
388
+ viewParams.flags = static_cast <video::IGPUImageView::E_CREATE_FLAGS>(0u );
389
+ viewParams.image = driver->createGPUImageOnDedMem (std::move (imageParams),driver->getDeviceLocalGPUMemoryReqs ());
390
+ viewParams.viewType = video::IGPUImageView::ET_2D;
391
+ viewParams.format = asset::EF_R16G16_SFLOAT;
392
+ viewParams.components = {};
393
+ viewParams.subresourceRange = {};
394
+ viewParams.subresourceRange .levelCount = 1u ;
395
+ viewParams.subresourceRange .layerCount = 1u ;
396
+ return driver->createGPUImageView (std::move (viewParams));
397
+ };
398
+ for (uint32_t i=0u ; i<channelCountOverride; i++)
399
+ kernelNormalizedSpectrums[i] = createKernelSpectrum ();
400
+
433
401
// Ker FFT X
434
402
auto fftDescriptorSet_Ker_FFT_X = driver->createGPUDescriptorSet (core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(fftPipelineLayout_ImageInput->getDescriptorSetLayout (0u )));
435
403
FFTClass::updateDescriptorSet (driver, fftDescriptorSet_Ker_FFT_X.get (), kerImageView, fftOutputBuffer_0, ISampler::ETC_CLAMP_TO_BORDER);
@@ -440,6 +408,30 @@ int main()
440
408
FFTClass::updateDescriptorSet (driver, fftDescriptorSet_Ker_FFT_Y.get (), fftOutputBuffer_0, fftOutputBuffer_1);
441
409
442
410
// Normalization of FFT Y result
411
+ auto fftPipelineLayout_KernelNormalization = [&]() -> auto
412
+ {
413
+ IGPUDescriptorSetLayout::SBinding bnd[] =
414
+ {
415
+ {
416
+ 0u ,
417
+ EDT_STORAGE_BUFFER,
418
+ 1u ,
419
+ ISpecializedShader::ESS_COMPUTE,
420
+ nullptr
421
+ },
422
+ {
423
+ 1u ,
424
+ EDT_STORAGE_IMAGE,
425
+ channelCountOverride,
426
+ ISpecializedShader::ESS_COMPUTE,
427
+ nullptr
428
+ },
429
+ };
430
+ return driver->createGPUPipelineLayout (
431
+ nullptr ,nullptr ,
432
+ driver->createGPUDescriptorSetLayout (bnd,bnd+2 ),nullptr ,nullptr ,nullptr
433
+ );
434
+ }();
443
435
auto fftDescriptorSet_KernelNormalization = [&]() -> auto
444
436
{
445
437
auto dset = driver->createGPUDescriptorSet (core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(fftPipelineLayout_KernelNormalization->getDescriptorSetLayout (0u )));
@@ -479,25 +471,37 @@ int main()
479
471
return dset;
480
472
}();
481
473
474
+ auto fftDispatchInfo_Horizontal = FFTClass::buildParameters (paddedKerDim, FFTClass::Direction::X);
475
+ auto fftDispatchInfo_Vertical = FFTClass::buildParameters (paddedKerDim, FFTClass::Direction::Y);
476
+
482
477
// Ker Image FFT X
483
478
driver->bindComputePipeline (fftPipeline_ImageInput.get ());
484
479
driver->bindDescriptorSets (EPBP_COMPUTE, fftPipelineLayout_ImageInput.get (), 0u , 1u , &fftDescriptorSet_Ker_FFT_X.get (), nullptr );
485
- FFTClass::pushConstants (driver, fftPipelineLayout_ImageInput.get (), kerDim, paddedDim , FFTClass::Direction::X, false , srcNumChannels, FFTClass::PaddingType::FILL_WITH_ZERO);
480
+ FFTClass::pushConstants (driver, fftPipelineLayout_ImageInput.get (), kerDim, paddedKerDim , FFTClass::Direction::X, false , srcNumChannels, FFTClass::PaddingType::FILL_WITH_ZERO);
486
481
FFTClass::dispatchHelper (driver, fftDispatchInfo_Horizontal);
487
482
488
483
// Ker Image FFT Y
489
- auto fftPipeline_SSBOInput = driver->createGPUComputePipeline (nullptr , core::smart_refctd_ptr (fftPipelineLayout_SSBOInput), FFTClass::createShader (driver,FFTClass::DataType::SSBO,paddedDim .height ));
484
+ auto fftPipeline_SSBOInput = driver->createGPUComputePipeline (nullptr , core::smart_refctd_ptr (fftPipelineLayout_SSBOInput), FFTClass::createShader (driver,FFTClass::DataType::SSBO,paddedKerDim .height ));
490
485
driver->bindComputePipeline (fftPipeline_SSBOInput.get ());
491
486
driver->bindDescriptorSets (EPBP_COMPUTE, fftPipelineLayout_SSBOInput.get (), 0u , 1u , &fftDescriptorSet_Ker_FFT_Y.get (), nullptr );
492
- FFTClass::pushConstants (driver, fftPipelineLayout_SSBOInput.get (), paddedDim, paddedDim , FFTClass::Direction::Y, false , srcNumChannels);
487
+ FFTClass::pushConstants (driver, fftPipelineLayout_SSBOInput.get (), paddedKerDim, paddedKerDim , FFTClass::Direction::Y, false , srcNumChannels);
493
488
FFTClass::dispatchHelper (driver, fftDispatchInfo_Vertical);
494
489
495
490
// Ker Normalization
491
+ auto fftPipeline_KernelNormalization = driver->createGPUComputePipeline (nullptr , core::smart_refctd_ptr (fftPipelineLayout_KernelNormalization),
492
+ [&]() -> auto
493
+ {
494
+ IAssetLoader::SAssetLoadParams lp;
495
+ auto shaderAsset = am->getAsset (" ../normalization.comp" , lp);
496
+ auto stuff = driver->getGPUObjectsFromAssets <asset::ICPUSpecializedShader>(shaderAsset.getContents (),nullptr );
497
+ return *stuff->begin ();
498
+ }()
499
+ );
496
500
driver->bindComputePipeline (fftPipeline_KernelNormalization.get ());
497
501
driver->bindDescriptorSets (EPBP_COMPUTE, fftPipelineLayout_KernelNormalization.get (), 0u , 1u , &fftDescriptorSet_KernelNormalization.get (), nullptr );
498
502
{
499
- const uint32_t dispatchSizeX = (paddedDim .width -1u )/16u +1u ;
500
- const uint32_t dispatchSizeY = (paddedDim .height -1u )/16u +1u ;
503
+ const uint32_t dispatchSizeX = (paddedKerDim .width -1u )/16u +1u ;
504
+ const uint32_t dispatchSizeY = (paddedKerDim .height -1u )/16u +1u ;
501
505
driver->dispatch (dispatchSizeX,dispatchSizeY,kerNumChannels);
502
506
FFTClass::defaultBarrier ();
503
507
}
@@ -524,6 +528,9 @@ int main()
524
528
auto blitFBO = driver->addFrameBuffer ();
525
529
blitFBO->attach (video::EFAP_COLOR_ATTACHMENT0, std::move (outImgView));
526
530
531
+
532
+ auto fftDispatchInfo_Horizontal = FFTClass::buildParameters (paddedDim, FFTClass::Direction::X);
533
+ auto fftDispatchInfo_Vertical = FFTClass::buildParameters (paddedDim, FFTClass::Direction::Y);
527
534
while (device->run () && receiver.keepOpen ())
528
535
{
529
536
driver->beginScene (false , false );
0 commit comments