33#ifndef OPTIX_DENOISER_TILING_H
34#define OPTIX_DENOISER_TILING_H
76 if( pixelStrideInBytes == 0 )
81 pixelStrideInBytes = 1 *
sizeof( short );
84 pixelStrideInBytes = 2 *
sizeof( short );
87 pixelStrideInBytes = 3 *
sizeof( short );
90 pixelStrideInBytes = 4 *
sizeof( short );
93 pixelStrideInBytes = 1 *
sizeof( float );
96 pixelStrideInBytes = 2 *
sizeof( float );
99 pixelStrideInBytes = 3 *
sizeof( float );
102 pixelStrideInBytes = 4 *
sizeof( float );
105 pixelStrideInBytes = 3 *
sizeof( char );
108 pixelStrideInBytes = 4 *
sizeof( char );
130 unsigned int overlapWindowSizeInPixels,
131 unsigned int tileWidth,
132 unsigned int tileHeight,
133 std::vector<OptixUtilDenoiserImageTile>& tiles )
135 if( tileWidth == 0 || tileHeight == 0 )
138 unsigned int inPixelStride, outPixelStride;
144 int inp_w = std::min( tileWidth + 2 * overlapWindowSizeInPixels, input.
width );
145 int inp_h = std::min( tileHeight + 2 * overlapWindowSizeInPixels, input.
height );
146 int inp_y = 0, copied_y = 0;
153 int inputOffsetY = inp_y == 0 ? 0 : std::max( (
int)overlapWindowSizeInPixels, inp_h - ( (
int)input.
height - inp_y ) );
154 int copy_y = inp_y == 0 ? std::min( input.
height, tileHeight + overlapWindowSizeInPixels ) :
155 std::min( tileHeight, input.
height - copied_y );
157 int inp_x = 0, copied_x = 0;
160 int inputOffsetX = inp_x == 0 ? 0 : std::max( (
int)overlapWindowSizeInPixels, inp_w - ( (
int)input.
width - inp_x ) );
161 int copy_x = inp_x == 0 ? std::min( input.
width, tileWidth + overlapWindowSizeInPixels ) :
162 std::min( tileWidth, input.
width - copied_x );
166 + (size_t)( inp_x - inputOffsetX ) * inPixelStride;
174 + (size_t)( upscaleX * inp_x ) * outPixelStride;
184 tiles.push_back( tile );
186 inp_x += inp_x == 0 ? tileWidth + overlapWindowSizeInPixels : tileWidth;
188 }
while( inp_x <
static_cast<int>( input.
width ) );
190 inp_y += inp_y == 0 ? tileHeight + overlapWindowSizeInPixels : tileHeight;
192 }
while( inp_y <
static_cast<int>( input.
height ) );
228 size_t denoiserStateSizeInBytes,
231 unsigned int numLayers,
233 size_t scratchSizeInBytes,
234 unsigned int overlapWindowSizeInPixels,
235 unsigned int tileWidth,
236 unsigned int tileHeight )
238 if( !guideLayer || !layers )
243 std::vector<std::vector<OptixUtilDenoiserImageTile>> tiles( numLayers );
244 std::vector<std::vector<OptixUtilDenoiserImageTile>> prevTiles( numLayers );
245 for(
unsigned int l = 0; l < numLayers; l++ )
248 overlapWindowSizeInPixels,
249 tileWidth, tileHeight, tiles[l] ) )
252 if( layers[l].previousOutput.data )
256 upscale * overlapWindowSizeInPixels,
257 upscale * tileWidth, upscale * tileHeight, prevTiles[l] ) )
262 std::vector<OptixUtilDenoiserImageTile> albedoTiles;
267 overlapWindowSizeInPixels,
268 tileWidth, tileHeight, albedoTiles ) )
272 std::vector<OptixUtilDenoiserImageTile> normalTiles;
277 overlapWindowSizeInPixels,
278 tileWidth, tileHeight, normalTiles ) )
282 std::vector<OptixUtilDenoiserImageTile> flowTiles;
287 overlapWindowSizeInPixels,
288 tileWidth, tileHeight, flowTiles ) )
292 std::vector<OptixUtilDenoiserImageTile> flowTrustTiles;
297 overlapWindowSizeInPixels,
298 tileWidth, tileHeight, flowTrustTiles ) )
302 std::vector<OptixUtilDenoiserImageTile> internalGuideLayerTiles;
307 upscale * overlapWindowSizeInPixels,
308 upscale * tileWidth, upscale * tileHeight, internalGuideLayerTiles ) )
312 for(
size_t t = 0; t < tiles[0].size(); t++ )
314 std::vector<OptixDenoiserLayer> tlayers;
315 for(
unsigned int l = 0; l < numLayers; l++ )
318 layer.
input = ( tiles[l] )[t].input;
319 layer.
output = ( tiles[l] )[t].output;
320 if( layers[l].previousOutput.data )
323 tlayers.push_back( layer );
328 gl.
albedo = albedoTiles[t].input;
331 gl.
normal = normalTiles[t].input;
334 gl.
flow = flowTiles[t].input;
347 &gl, &tlayers[0], numLayers,
348 ( tiles[0] )[t].inputOffsetX, ( tiles[0] )[t].inputOffsetY,
349 scratch, scratchSizeInBytes ) )
struct OptixDenoiser_t * OptixDenoiser
Opaque type representing a denoiser instance.
Definition: optix_types.h:71
unsigned long long CUdeviceptr
CUDA device pointer.
Definition: optix_types.h:52
OptixResult
Result codes returned from API functions.
Definition: optix_types.h:152
@ OPTIX_SUCCESS
Definition: optix_types.h:153
@ OPTIX_ERROR_INVALID_VALUE
Definition: optix_types.h:154
@ OPTIX_PIXEL_FORMAT_HALF4
four halfs, RGBA
Definition: optix_types.h:1559
@ OPTIX_PIXEL_FORMAT_FLOAT2
two floats, XY
Definition: optix_types.h:1561
@ OPTIX_PIXEL_FORMAT_FLOAT4
four floats, RGBA
Definition: optix_types.h:1563
@ OPTIX_PIXEL_FORMAT_UCHAR4
four unsigned chars, RGBA
Definition: optix_types.h:1565
@ OPTIX_PIXEL_FORMAT_HALF3
three halfs, RGB
Definition: optix_types.h:1558
@ OPTIX_PIXEL_FORMAT_FLOAT3
three floats, RGB
Definition: optix_types.h:1562
@ OPTIX_PIXEL_FORMAT_UCHAR3
three unsigned chars, RGB
Definition: optix_types.h:1564
@ OPTIX_PIXEL_FORMAT_HALF1
one half
Definition: optix_types.h:1556
@ OPTIX_PIXEL_FORMAT_INTERNAL_GUIDE_LAYER
internal format
Definition: optix_types.h:1566
@ OPTIX_PIXEL_FORMAT_FLOAT1
one float
Definition: optix_types.h:1560
@ OPTIX_PIXEL_FORMAT_HALF2
two halfs, XY
Definition: optix_types.h:1557
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:223
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:127
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:73
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:1635
OptixImage2D normal
Definition: optix_types.h:1640
OptixImage2D flowTrustworthiness
Definition: optix_types.h:1653
OptixImage2D flow
Definition: optix_types.h:1643
OptixImage2D previousOutputInternalGuideLayer
Definition: optix_types.h:1647
OptixImage2D albedo
Definition: optix_types.h:1637
OptixImage2D outputInternalGuideLayer
Definition: optix_types.h:1648
Input/Output layers for the denoiser.
Definition: optix_types.h:1676
OptixImage2D output
Definition: optix_types.h:1684
OptixImage2D input
Definition: optix_types.h:1678
OptixDenoiserAOVType type
Definition: optix_types.h:1687
OptixImage2D previousOutput
Definition: optix_types.h:1681
Definition: optix_types.h:1708
Image descriptor used by the denoiser.
Definition: optix_types.h:1573
unsigned int rowStrideInBytes
Stride between subsequent rows of the image (in bytes).
Definition: optix_types.h:1581
CUdeviceptr data
Pointer to the actual pixel data.
Definition: optix_types.h:1575
OptixPixelFormat format
Pixel format.
Definition: optix_types.h:1588
unsigned int width
Width of the image (in pixels)
Definition: optix_types.h:1577
unsigned int height
Height of the image (in pixels)
Definition: optix_types.h:1579
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:1586
Tile definition.
Definition: optix_denoiser_tiling.h:54
unsigned int inputOffsetY
Definition: optix_denoiser_tiling.h:63
OptixImage2D output
Definition: optix_denoiser_tiling.h:59
unsigned int inputOffsetX
Definition: optix_denoiser_tiling.h:62
OptixImage2D input
Definition: optix_denoiser_tiling.h:56