1 // Copyright 2009-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "common/OSPCommon.h"
7 
8 namespace ospray {
9 
10 static_assert(TILE_SIZE > 0 && (TILE_SIZE & (TILE_SIZE - 1)) == 0,
11     "OSPRay config error: TILE_SIZE must be a positive power of two.");
12 
13 //! a tile of pixels used by any tile-based renderer
14 /*! pixels in the tile are in a row-major TILE_SIZE x TILE_SIZE
15     pattern. the 'region' specifies which part of the screen this
16     tile belongs to: tile.lower is the lower-left coordinate of this
17     tile (and a multiple of TILE_SIZE); the 'upper' value may be
18     smaller than the upper-right edge of the "full" tile.
19 
20     note that a tile contains "all" of the values a renderer might
21     want to use. not all renderers nor all frame buffers will use
22     all those values; it's up to the renderer and frame buffer to
23     agree on which fields will be set. Similarly, the frame buffer
24     may actually use uchars, but the tile will always store
25     floats. */
26 struct OSPRAY_SDK_INTERFACE __aligned(64) Tile
27 {
28   region2i region; // screen region that this corresponds to
29   vec2i fbSize; // total frame buffer size, for the camera
30   vec2f rcp_fbSize;
31   int32 generation{0};
32   int32 children{0};
33   int32 sortOrder{0};
34   int32 accumID; //!< how often has been accumulated into this tile
35   float pad[4]; //!< padding to match the ISPC-side layout
36   float r[TILE_SIZE * TILE_SIZE]; // 'red' component
37   float g[TILE_SIZE * TILE_SIZE]; // 'green' component
38   float b[TILE_SIZE * TILE_SIZE]; // 'blue' component
39   float a[TILE_SIZE * TILE_SIZE]; // 'alpha' component
40   float z[TILE_SIZE * TILE_SIZE]; // 'depth' component
41   float nx[TILE_SIZE * TILE_SIZE]; // normal x
42   float ny[TILE_SIZE * TILE_SIZE]; // normal y
43   float nz[TILE_SIZE * TILE_SIZE]; // normal z
44   float ar[TILE_SIZE * TILE_SIZE]; // albedo red
45   float ag[TILE_SIZE * TILE_SIZE]; // albedo green
46   float ab[TILE_SIZE * TILE_SIZE]; // albedo blue
47 
48   Tile() = default;
TileTile49   Tile(const vec2i &tile, const vec2i &fbsize, const int32 accumId)
50       : fbSize(fbsize),
51         rcp_fbSize(rcp(vec2f(fbsize))),
52         accumID(accumId)
53   {
54     region.lower = tile * TILE_SIZE;
55     region.upper = min(region.lower + TILE_SIZE, fbsize);
56   }
57 };
58 
59 } // namespace ospray
60