35#ifndef OPTIX_DENOISER_TILING_H
36#define OPTIX_DENOISER_TILING_H
78 if( pixelStrideInBytes == 0 )
83 pixelStrideInBytes = 1 *
sizeof( short );
86 pixelStrideInBytes = 2 *
sizeof( short );
89 pixelStrideInBytes = 3 *
sizeof( short );
92 pixelStrideInBytes = 4 *
sizeof( short );
95 pixelStrideInBytes = 1 *
sizeof( float );
98 pixelStrideInBytes = 2 *
sizeof( float );
101 pixelStrideInBytes = 3 *
sizeof( float );
104 pixelStrideInBytes = 4 *
sizeof( float );
107 pixelStrideInBytes = 3 *
sizeof( char );
110 pixelStrideInBytes = 4 *
sizeof( char );
132 unsigned int overlapWindowSizeInPixels,
133 unsigned int tileWidth,
134 unsigned int tileHeight,
135 std::vector<OptixUtilDenoiserImageTile>& tiles )
137 if( tileWidth == 0 || tileHeight == 0 )
140 unsigned int inPixelStride, outPixelStride;
146 int inp_w = std::min( tileWidth + 2 * overlapWindowSizeInPixels, input.
width );
147 int inp_h = std::min( tileHeight + 2 * overlapWindowSizeInPixels, input.
height );
148 int inp_y = 0, copied_y = 0;
155 int inputOffsetY = inp_y == 0 ? 0 : std::max( (
int)overlapWindowSizeInPixels, inp_h - ( (
int)input.
height - inp_y ) );
156 int copy_y = inp_y == 0 ? std::min( input.
height, tileHeight + overlapWindowSizeInPixels ) :
157 std::min( tileHeight, input.
height - copied_y );
159 int inp_x = 0, copied_x = 0;
162 int inputOffsetX = inp_x == 0 ? 0 : std::max( (
int)overlapWindowSizeInPixels, inp_w - ( (
int)input.
width - inp_x ) );
163 int copy_x = inp_x == 0 ? std::min( input.
width, tileWidth + overlapWindowSizeInPixels ) :
164 std::min( tileWidth, input.
width - copied_x );
168 + (size_t)( inp_x - inputOffsetX ) * inPixelStride;
176 + (size_t)( upscaleX * inp_x ) * outPixelStride;
186 tiles.push_back( tile );
188 inp_x += inp_x == 0 ? tileWidth + overlapWindowSizeInPixels : tileWidth;
190 }
while( inp_x <
static_cast<int>( input.
width ) );
192 inp_y += inp_y == 0 ? tileHeight + overlapWindowSizeInPixels : tileHeight;
194 }
while( inp_y <
static_cast<int>( input.
height ) );
230 size_t denoiserStateSizeInBytes,
233 unsigned int numLayers,
235 size_t scratchSizeInBytes,
236 unsigned int overlapWindowSizeInPixels,
237 unsigned int tileWidth,
238 unsigned int tileHeight )
240 if( !guideLayer || !layers )
245 std::vector<std::vector<OptixUtilDenoiserImageTile>> tiles( numLayers );
246 std::vector<std::vector<OptixUtilDenoiserImageTile>> prevTiles( numLayers );
247 for(
unsigned int l = 0; l < numLayers; l++ )
250 overlapWindowSizeInPixels,
251 tileWidth, tileHeight, tiles[l] ) )
254 if( layers[l].previousOutput.data )
258 upscale * overlapWindowSizeInPixels,
259 upscale * tileWidth, upscale * tileHeight, prevTiles[l] ) )
264 std::vector<OptixUtilDenoiserImageTile> albedoTiles;
269 overlapWindowSizeInPixels,
270 tileWidth, tileHeight, albedoTiles ) )
274 std::vector<OptixUtilDenoiserImageTile> normalTiles;
279 overlapWindowSizeInPixels,
280 tileWidth, tileHeight, normalTiles ) )
284 std::vector<OptixUtilDenoiserImageTile> flowTiles;
289 overlapWindowSizeInPixels,
290 tileWidth, tileHeight, flowTiles ) )
294 std::vector<OptixUtilDenoiserImageTile> flowTrustTiles;
299 overlapWindowSizeInPixels,
300 tileWidth, tileHeight, flowTrustTiles ) )
304 std::vector<OptixUtilDenoiserImageTile> internalGuideLayerTiles;
309 upscale * overlapWindowSizeInPixels,
310 upscale * tileWidth, upscale * tileHeight, internalGuideLayerTiles ) )
314 for(
size_t t = 0; t < tiles[0].size(); t++ )
316 std::vector<OptixDenoiserLayer> tlayers;
317 for(
unsigned int l = 0; l < numLayers; l++ )
320 layer.
input = ( tiles[l] )[t].input;
321 layer.
output = ( tiles[l] )[t].output;
322 if( layers[l].previousOutput.data )
325 tlayers.push_back( layer );
330 gl.
albedo = albedoTiles[t].input;
333 gl.
normal = normalTiles[t].input;
336 gl.
flow = flowTiles[t].input;
349 &gl, &tlayers[0], numLayers,
350 ( tiles[0] )[t].inputOffsetX, ( tiles[0] )[t].inputOffsetY,
351 scratch, scratchSizeInBytes ) )
struct OptixDenoiser_t * OptixDenoiser
Opaque type representing a denoiser instance.
Definition: optix_types.h:62
unsigned long long CUdeviceptr
CUDA device pointer.
Definition: optix_types.h:43
OptixResult
Result codes returned from API functions.
Definition: optix_types.h:143
@ OPTIX_SUCCESS
Definition: optix_types.h:144
@ OPTIX_ERROR_INVALID_VALUE
Definition: optix_types.h:145
@ OPTIX_PIXEL_FORMAT_HALF4
four halfs, RGBA
Definition: optix_types.h:1572
@ OPTIX_PIXEL_FORMAT_FLOAT2
two floats, XY
Definition: optix_types.h:1574
@ OPTIX_PIXEL_FORMAT_FLOAT4
four floats, RGBA
Definition: optix_types.h:1576
@ OPTIX_PIXEL_FORMAT_UCHAR4
four unsigned chars, RGBA
Definition: optix_types.h:1578
@ OPTIX_PIXEL_FORMAT_HALF3
three halfs, RGB
Definition: optix_types.h:1571
@ OPTIX_PIXEL_FORMAT_FLOAT3
three floats, RGB
Definition: optix_types.h:1575
@ OPTIX_PIXEL_FORMAT_UCHAR3
three unsigned chars, RGB
Definition: optix_types.h:1577
@ OPTIX_PIXEL_FORMAT_HALF1
one half
Definition: optix_types.h:1569
@ OPTIX_PIXEL_FORMAT_INTERNAL_GUIDE_LAYER
internal format
Definition: optix_types.h:1579
@ OPTIX_PIXEL_FORMAT_FLOAT1
one float
Definition: optix_types.h:1573
@ OPTIX_PIXEL_FORMAT_HALF2
two halfs, XY
Definition: optix_types.h:1570
OptixResult optixUtilDenoiserInvokeTiled(OptixDenoiser denoiser, CUstream stream, const OptixDenoiserParams *params, CUdeviceptr denoiserState, size_t denoiserStateSizeInBytes, const OptixDenoiserGuideLayer *guideLayer, const OptixDenoiserLayer *layers, unsigned int numLayers, CUdeviceptr scratch, size_t scratchSizeInBytes, unsigned int overlapWindowSizeInPixels, unsigned int tileWidth, unsigned int tileHeight)
Run denoiser on input layers see optixDenoiserInvoke additional parameters:
Definition: optix_denoiser_tiling.h:225
OptixResult optixUtilDenoiserSplitImage(const OptixImage2D &input, const OptixImage2D &output, unsigned int overlapWindowSizeInPixels, unsigned int tileWidth, unsigned int tileHeight, std::vector<OptixUtilDenoiserImageTile> &tiles)
Split image into 2D tiles given horizontal and vertical tile size.
Definition: optix_denoiser_tiling.h:129
OptixResult optixUtilGetPixelStride(const OptixImage2D &image, unsigned int &pixelStrideInBytes)
Return pixel stride in bytes for the given pixel format if the pixelStrideInBytes member of the image...
Definition: optix_denoiser_tiling.h:75
OPTIXAPI OptixResult optixDenoiserInvoke(OptixDenoiser denoiser, CUstream stream, const OptixDenoiserParams *params, CUdeviceptr denoiserState, size_t denoiserStateSizeInBytes, const OptixDenoiserGuideLayer *guideLayer, const OptixDenoiserLayer *layers, unsigned int numLayers, unsigned int inputOffsetX, unsigned int inputOffsetY, CUdeviceptr scratch, size_t scratchSizeInBytes)
Invokes denoiser on a set of input data and produces at least one output image. State memory must be ...
Guide layer for the denoiser.
Definition: optix_types.h:1663
OptixImage2D normal
Definition: optix_types.h:1670
OptixImage2D flowTrustworthiness
Definition: optix_types.h:1684
OptixImage2D flow
Definition: optix_types.h:1674
OptixImage2D previousOutputInternalGuideLayer
Definition: optix_types.h:1678
OptixImage2D albedo
Definition: optix_types.h:1665
OptixImage2D outputInternalGuideLayer
Definition: optix_types.h:1679
Input/Output layers for the denoiser.
Definition: optix_types.h:1707
OptixImage2D output
Definition: optix_types.h:1715
OptixImage2D input
Definition: optix_types.h:1709
OptixDenoiserAOVType type
Definition: optix_types.h:1718
OptixImage2D previousOutput
Definition: optix_types.h:1712
Various parameters used by the denoiser.
Definition: optix_types.h:1728
Image descriptor used by the denoiser.
Definition: optix_types.h:1586
unsigned int rowStrideInBytes
Stride between subsequent rows of the image (in bytes).
Definition: optix_types.h:1594
CUdeviceptr data
Pointer to the actual pixel data.
Definition: optix_types.h:1588
OptixPixelFormat format
Pixel format.
Definition: optix_types.h:1601
unsigned int width
Width of the image (in pixels)
Definition: optix_types.h:1590
unsigned int height
Height of the image (in pixels)
Definition: optix_types.h:1592
unsigned int pixelStrideInBytes
Stride between subsequent pixels of the image (in bytes). If set to 0, dense packing (no gaps) is ass...
Definition: optix_types.h:1599
Tile definition.
Definition: optix_denoiser_tiling.h:56
unsigned int inputOffsetY
Definition: optix_denoiser_tiling.h:65
OptixImage2D output
Definition: optix_denoiser_tiling.h:61
unsigned int inputOffsetX
Definition: optix_denoiser_tiling.h:64
OptixImage2D input
Definition: optix_denoiser_tiling.h:58