@@ -49,10 +49,13 @@ bool check_error(bool cond, const char* message)
49
49
os::Printer::log (message, ELL_ERROR);
50
50
return cond;
51
51
}
52
- /*
53
- if (check_error(,"!"))
54
- return error_code;
55
- */
52
+
53
+ constexpr uint32_t overlap = 64 ;
54
+ // constexpr uint32_t tileWidth = 1920/2, tileHeight = 1080/2;
55
+ constexpr uint32_t tileWidth = 1024 , tileHeight = 1024 ;
56
+ constexpr uint32_t tileWidthWithOverlap = tileWidth + overlap * 2 ;
57
+ constexpr uint32_t tileHeightWithOverlap = tileHeight + overlap * 2 ;
58
+ constexpr uint32_t outputDimensions[] = { tileWidth ,tileHeight };
56
59
57
60
int main (int argc, char * argv[])
58
61
{
@@ -94,8 +97,8 @@ int main(int argc, char* argv[])
94
97
95
98
return arguments;
96
99
};
97
-
98
- auto cmdHandler = CommandLineHandler (getArgvFetchedList (), am);
100
+
101
+ auto cmdHandler = CommandLineHandler (getArgvFetchedList (), am, device-> getFileSystem () );
99
102
100
103
if (check_error (!cmdHandler.getStatus ()," Could not parse input commands!" ))
101
104
return error_code;
@@ -136,7 +139,7 @@ int main(int argc, char* argv[])
136
139
constexpr auto forcedOptiXFormatPixelStride = 6u ;
137
140
DenoiserToUse denoisers[EII_COUNT];
138
141
{
139
- OptixDenoiserOptions opts = { OPTIX_DENOISER_INPUT_RGB,forcedOptiXFormat };
142
+ OptixDenoiserOptions opts = { OPTIX_DENOISER_INPUT_RGB };
140
143
denoisers[EII_COLOR].m_denoiser = m_optixContext->createDenoiser (&opts);
141
144
if (check_error (!denoisers[EII_COLOR].m_denoiser , " Could not create Optix Color Denoiser!" ))
142
145
return error_code;
@@ -428,7 +431,7 @@ void main()
428
431
429
432
core::vector<ImageToDenoise> images (inputFilesAmount);
430
433
// load images
431
- uint32_t maxResolution[EII_COUNT][ 2 ] = { 0 };
434
+ uint32_t maxResolution[2 ] = { 0 , 0 };
432
435
{
433
436
asset::IAssetLoader::SAssetLoadParams lp (0ull ,nullptr );
434
437
@@ -458,24 +461,24 @@ void main()
458
461
uint32_t pickedChannel = 0u ;
459
462
auto contents = assetBundle.getContents ();
460
463
if (channelName.has_value ())
461
- for (auto & asset : contents)
462
- {
463
- assert (asset);
464
-
465
- auto metadata = asset->getMetadata ();
466
- auto exrmeta = static_cast <COpenEXRImageMetadata*>(metadata);
467
- if (strcmp (metadata->getLoaderName (),COpenEXRImageMetadata::LoaderName)!=0 )
468
- continue ;
469
- else
464
+ for (auto & asset : contents)
470
465
{
471
- const auto & assetMetaChannelName = exrmeta->getName ();
472
- auto found = assetMetaChannelName.find (channelName.value ());
473
- if (found>=firstChannelNameOccurence)
466
+ assert (asset);
467
+
468
+ auto metadata = asset->getMetadata ();
469
+ const auto exrmeta = static_cast <const COpenEXRImageMetadata*>(metadata);
470
+ if (strcmp (metadata->getLoaderName (), COpenEXRImageMetadata::LoaderName) != 0 )
474
471
continue ;
475
- firstChannelNameOccurence = found;
476
- pickedChannel = std::distance (contents.begin (), &asset);
472
+ else
473
+ {
474
+ const auto & assetMetaChannelName = exrmeta->getName ();
475
+ auto found = assetMetaChannelName.find (channelName.value ());
476
+ if (found >= firstChannelNameOccurence)
477
+ continue ;
478
+ firstChannelNameOccurence = found;
479
+ pickedChannel = std::distance (contents.begin (), &asset);
480
+ }
477
481
}
478
- }
479
482
480
483
return asset::IAsset::castDown<ICPUImage>(contents.begin ()[pickedChannel]);
481
484
};
@@ -545,19 +548,15 @@ void main()
545
548
const auto & region = regions.begin ()[0 ];
546
549
assert (region.bufferRowLength );
547
550
outParam.colorTexelSize = asset::getTexelOrBlockBytesize (colorCreationParams.format );
548
- uint32_t bytesize = extent.height *region.bufferRowLength *outParam.colorTexelSize ;
549
- if (bytesize>params.StreamingDownloadBufferSize )
550
- {
551
- os::Printer::log (imageIDString + " Image too large to download from GPU in one piece!" , ELL_ERROR);
552
- outParam = {};
553
- continue ;
554
- }
555
551
}
556
552
557
553
outParam.denoiserType = EII_COLOR;
558
554
559
555
outParam.width = extent.width ;
560
556
outParam.height = extent.height ;
557
+
558
+ maxResolution[0 ] = core::max (maxResolution[0 ], outParam.width );
559
+ maxResolution[1 ] = core::max (maxResolution[1 ], outParam.height );
561
560
}
562
561
563
562
auto & albedoImage = outParam.image [EII_ALBEDO];
@@ -590,9 +589,6 @@ void main()
590
589
else
591
590
outParam.denoiserType = EII_NORMAL;
592
591
}
593
-
594
- maxResolution[outParam.denoiserType ][0 ] = core::max (maxResolution[outParam.denoiserType ][0 ],outParam.width );
595
- maxResolution[outParam.denoiserType ][1 ] = core::max (maxResolution[outParam.denoiserType ][1 ],outParam.height );
596
592
}
597
593
}
598
594
@@ -606,22 +602,17 @@ void main()
606
602
auto & intensityBuffer = bufferLinks[0 ];
607
603
auto & denoiserState = bufferLinks[0 ];
608
604
auto & temporaryPixelBuffer = bufferLinks[1 ];
609
- auto & imagePixelBuffer = bufferLinks[2 ];
605
+ auto & imagePixelBuffer = bufferLinks[2 ]; // buffer to store result of denoising of a tile/image
610
606
size_t denoiserStateBufferSize = 0ull ;
611
607
{
612
608
size_t scratchBufferSize = 0ull ;
613
609
size_t pixelBufferSize = 0ull ;
614
610
for (uint32_t i=0u ; i<EII_COUNT; i++)
615
611
{
616
612
auto & denoiser = denoisers[i].m_denoiser ;
617
- if (maxResolution[i][0 ]==0u || maxResolution[i][1 ]==0u )
618
- {
619
- denoiser = nullptr ;
620
- continue ;
621
- }
622
613
623
614
OptixDenoiserSizes m_denoiserMemReqs;
624
- if (denoiser->computeMemoryResources (&m_denoiserMemReqs, maxResolution[i] )!=OPTIX_SUCCESS)
615
+ if (denoiser->computeMemoryResources (&m_denoiserMemReqs, outputDimensions )!=OPTIX_SUCCESS)
625
616
{
626
617
static const char * errorMsgs[EII_COUNT] = { " Failed to compute Color-Denoiser Memory Requirements!" ,
627
618
" Failed to compute Color-Albedo-Denoiser Memory Requirements!" ,
@@ -633,8 +624,9 @@ void main()
633
624
634
625
denoisers[i].stateOffset = denoiserStateBufferSize;
635
626
denoiserStateBufferSize += denoisers[i].stateSize = m_denoiserMemReqs.stateSizeInBytes ;
636
- scratchBufferSize = core::max (scratchBufferSize,denoisers[i].scratchSize = m_denoiserMemReqs.recommendedScratchSizeInBytes );
637
- pixelBufferSize = core::max (pixelBufferSize,core::max (asset::getTexelOrBlockBytesize (EF_R32G32B32A32_SFLOAT),(i+1u )*forcedOptiXFormatPixelStride)*maxResolution[i][0 ]*maxResolution[i][1 ]);
627
+ scratchBufferSize = core::max (scratchBufferSize, denoisers[i].scratchSize = m_denoiserMemReqs.withOverlapScratchSizeInBytes );
628
+ pixelBufferSize = core::max (pixelBufferSize, core::max (asset::getTexelOrBlockBytesize (EF_R32G32B32A32_SFLOAT), (i + 1u ) * forcedOptiXFormatPixelStride) * maxResolution[0 ] * maxResolution[1 ]);
629
+
638
630
}
639
631
std::string message = " Total VRAM consumption for Denoiser algorithm: " ;
640
632
os::Printer::log (message+std::to_string (denoiserStateBufferSize+scratchBufferSize+pixelBufferSize), ELL_INFORMATION);
@@ -698,14 +690,14 @@ void main()
698
690
{
699
691
case ToneMapperClass::EO_REINHARD:
700
692
{
701
- auto tp = ToneMapperClass::Params_t<ToneMapperClass::EO_REINHARD>(optiXIntensityKeyCompensation,key,extraParam);
693
+ auto tp = ToneMapperClass::Params_t<ToneMapperClass::EO_REINHARD>(optiXIntensityKeyCompensation, key, extraParam);
702
694
shaderConstants.tonemapperParams [0 ] = tp.keyAndLinearExposure ;
703
695
shaderConstants.tonemapperParams [1 ] = tp.rcpWhite2 ;
704
696
break ;
705
697
}
706
698
case ToneMapperClass::EO_ACES:
707
699
{
708
- auto tp = ToneMapperClass::Params_t<ToneMapperClass::EO_ACES>(optiXIntensityKeyCompensation,key,extraParam);
700
+ auto tp = ToneMapperClass::Params_t<ToneMapperClass::EO_ACES>(optiXIntensityKeyCompensation, key, extraParam);
709
701
shaderConstants.tonemapperParams [0 ] = tp.gamma ;
710
702
shaderConstants.tonemapperParams [1 ] = (&tp.gamma )[1 ];
711
703
break ;
@@ -724,9 +716,9 @@ void main()
724
716
break ;
725
717
}
726
718
}
727
- auto totalSampleCount = param.width * param.height ;
728
- shaderConstants.percentileRange [0 ] = lowerPercentile* float (totalSampleCount);
729
- shaderConstants.percentileRange [1 ] = upperPercentile* float (totalSampleCount);
719
+ auto totalSampleCount = param.width * param.height ;
720
+ shaderConstants.percentileRange [0 ] = lowerPercentile * float (totalSampleCount);
721
+ shaderConstants.percentileRange [1 ] = upperPercentile * float (totalSampleCount);
730
722
shaderConstants.normalMatrix = cameraTransformBundle[i].value ();
731
723
}
732
724
@@ -822,52 +814,62 @@ void main()
822
814
#undef DENOISER_BUFFER_COUNT
823
815
core::SRAIIBasedExiter<decltype (unmapBuffers)> exitRoutine (unmapBuffers);
824
816
825
- // set up optix image
826
- OptixImage2D denoiserInputs[EII_COUNT];
827
- for (uint32_t j=0u ; j<denoiserInputCount; j++)
828
- {
829
- denoiserInputs[j].data = temporaryPixelBuffer.asBuffer .pointer +shaderConstants.outImageOffset [j]*sizeof (uint16_t ); // sizeof(float16_t)
830
- denoiserInputs[j].width = param.width ;
831
- denoiserInputs[j].height = param.height ;
832
- denoiserInputs[j].rowStrideInBytes = param.width *forcedOptiXFormatPixelStride;
833
- denoiserInputs[j].pixelStrideInBytes = 0u ;
834
- denoiserInputs[j].format = forcedOptiXFormat;
835
- }
836
- //
817
+ cuda::CCUDAHandler::GraphicsAPIObjLink<video::IGPUBuffer> fakeScratchLink;
818
+ fakeScratchLink.asBuffer .pointer = denoiserScratch;
819
+
820
+ // set up denoiser
821
+ auto & denoiser = denoisers[param.denoiserType ];
822
+ if (denoiser.m_denoiser ->setup (m_cudaStream, outputDimensions, denoiserState, denoiser.stateSize , fakeScratchLink, denoiser.scratchSize , denoiser.stateOffset ) != OPTIX_SUCCESS)
837
823
{
838
- cuda::CCUDAHandler::GraphicsAPIObjLink<video::IGPUBuffer> fakeScratchLink;
839
- fakeScratchLink.asBuffer .pointer = denoiserScratch;
824
+ os::Printer::log (makeImageIDString (i) + " Could not setup the denoiser for the image resolution and denoiser buffers, skipping image!" , ELL_ERROR);
825
+ continue ;
826
+ }
827
+
828
+ // invocation params
829
+ OptixDenoiserParams denoiserParams = {};
830
+ denoiserParams.blendFactor = denoiserBlendFactorBundle[i].value ();
831
+ denoiserParams.denoiseAlpha = 0u ;
832
+ denoiserParams.hdrIntensity = intensityBuffer.asBuffer .pointer + intensityBufferOffset;
833
+
834
+ // input with RGB, Albedo, Normals
835
+ OptixImage2D denoiserInputs[EII_COUNT];
836
+ OptixImage2D denoiserOutput;
840
837
841
- // set up denoiser
842
- auto & denoiser = denoisers[param.denoiserType ];
843
- if (denoiser.m_denoiser ->setup (m_cudaStream,¶m.width ,denoiserState,denoiser.stateSize ,fakeScratchLink,denoiser.scratchSize ,denoiser.stateOffset )!=OPTIX_SUCCESS)
844
- {
845
- os::Printer::log (makeImageIDString (i) + " Could not setup the denoiser for the image resolution and denoiser buffers, skipping image!" , ELL_ERROR);
846
- continue ;
847
- }
838
+ for (size_t k = 0 ; k < denoiserInputCount; k++)
839
+ {
840
+ denoiserInputs[k].data = temporaryPixelBuffer.asBuffer .pointer + shaderConstants.outImageOffset [k] * sizeof (uint16_t );
841
+ denoiserInputs[k].width = param.width ;
842
+ denoiserInputs[k].height = param.height ;
843
+ denoiserInputs[k].rowStrideInBytes = param.width * forcedOptiXFormatPixelStride;
844
+ denoiserInputs[k].format = forcedOptiXFormat;
845
+ denoiserInputs[k].pixelStrideInBytes = forcedOptiXFormatPixelStride;
848
846
849
- // invoke
850
- {
851
- OptixDenoiserParams denoiserParams = {};
852
- denoiserParams.blendFactor = denoiserBlendFactorBundle[i].value ();
853
- denoiserParams.denoiseAlpha = 0u ;
854
- denoiserParams.hdrIntensity = intensityBuffer.asBuffer .pointer +intensityBufferOffset;
855
- OptixImage2D denoiserOutput;
856
- denoiserOutput.data = imagePixelBuffer.asBuffer .pointer +shaderConstants.inImageTexelOffset [EII_COLOR];
857
- denoiserOutput.width = param.width ;
858
- denoiserOutput.height = param.height ;
859
- denoiserOutput.rowStrideInBytes = param.width *forcedOptiXFormatPixelStride;
860
- denoiserOutput.pixelStrideInBytes = 0u ;
861
- denoiserOutput.format = forcedOptiXFormat;
862
- if (denoiser.m_denoiser ->invoke (m_cudaStream,&denoiserParams,denoiserInputs,denoiserInputs+denoiserInputCount,&denoiserOutput,fakeScratchLink,denoiser.scratchSize )!=OPTIX_SUCCESS)
863
- {
864
- os::Printer::log (makeImageIDString (i) + " Could not invoke the denoiser sucessfully, skipping image!" , ELL_ERROR);
865
- continue ;
866
- }
867
- }
868
847
}
869
848
870
- // unmap buffer (implicit from the SRAIIExiter destructor)
849
+ denoiserOutput.data = imagePixelBuffer.asBuffer .pointer + shaderConstants.inImageTexelOffset [EII_COLOR];
850
+ denoiserOutput.width = param.width ;
851
+ denoiserOutput.height = param.height ;
852
+ denoiserOutput.rowStrideInBytes = param.width * forcedOptiXFormatPixelStride;
853
+ denoiserOutput.format = forcedOptiXFormat;
854
+ denoiserOutput.pixelStrideInBytes = forcedOptiXFormatPixelStride;
855
+
856
+ // invoke
857
+ if (denoiser.m_denoiser ->tileAndInvoke (
858
+ m_cudaStream,
859
+ &denoiserParams,
860
+ denoiserInputs,
861
+ denoiserInputCount,
862
+ &denoiserOutput,
863
+ fakeScratchLink,
864
+ denoiser.scratchSize ,
865
+ overlap,
866
+ tileWidth,
867
+ tileHeight
868
+ ) != OPTIX_SUCCESS)
869
+ {
870
+ os::Printer::log (makeImageIDString (i) + " Could not invoke the denoiser sucessfully, skipping image!" , ELL_ERROR);
871
+ continue ;
872
+ }
871
873
}
872
874
873
875
// compute post-processing
0 commit comments