1// Copyright 2009-2020 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "common/OSPCommon.ih"
7#include "rkcommon/math/box.ih"
8
9/*! a screen tile. the memory layout of this class has to _exactly_
10  match the (C++-)one in tile.h */
11struct Tile
12{
13  uniform range2i region;
14  uniform vec2i fbSize;
15  uniform vec2f rcp_fbSize;
16  uniform int32 generation;
17  uniform int32 children;
18  uniform int32 sortOrder;
19  uniform int32 accumID;
20  uniform float pad[4]; // padding to match the varying tile layout
21  uniform float r[TILE_SIZE * TILE_SIZE]; // red
22  uniform float g[TILE_SIZE * TILE_SIZE]; // green
23  uniform float b[TILE_SIZE * TILE_SIZE]; // blue
24  uniform float a[TILE_SIZE * TILE_SIZE]; // alpha
25  uniform float z[TILE_SIZE * TILE_SIZE]; // depth
26  uniform float nx[TILE_SIZE * TILE_SIZE]; // normal x
27  uniform float ny[TILE_SIZE * TILE_SIZE]; // normal y
28  uniform float nz[TILE_SIZE * TILE_SIZE]; // normal z
29  uniform float ar[TILE_SIZE * TILE_SIZE]; // albedo red
30  uniform float ag[TILE_SIZE * TILE_SIZE]; // albedo green
31  uniform float ab[TILE_SIZE * TILE_SIZE]; // albedo blue
32};
33
34struct VaryingTile
35{
36  uniform range2i region; // 4 ints
37  uniform vec2i fbSize; // 2 ints
38  uniform vec2f rcp_fbSize; // 2 floats
39  uniform int32 generation;
40  uniform int32 children;
41  uniform int32 sortOrder;
42  uniform int32 accumID;
43  uniform float pad[4]; // explicit padding to match on SSE, this padding is
44                        // implicitly added on AVX and AVX512 to align the
45                        // vectors though. We need it here to match on SSE
46  varying float r[TILE_SIZE * TILE_SIZE / programCount];
47  varying float g[TILE_SIZE * TILE_SIZE / programCount];
48  varying float b[TILE_SIZE * TILE_SIZE / programCount];
49  varying float a[TILE_SIZE * TILE_SIZE / programCount];
50  varying float z[TILE_SIZE * TILE_SIZE / programCount];
51  varying float nx[TILE_SIZE * TILE_SIZE / programCount];
52  varying float ny[TILE_SIZE * TILE_SIZE / programCount];
53  varying float nz[TILE_SIZE * TILE_SIZE / programCount];
54  varying float ar[TILE_SIZE * TILE_SIZE / programCount];
55  varying float ag[TILE_SIZE * TILE_SIZE / programCount];
56  varying float ab[TILE_SIZE * TILE_SIZE / programCount];
57};
58
59inline void setRGBA(uniform Tile &tile,
60    const varying uint32 i,
61    const varying vec3f rgb,
62    const varying float alpha = 0.f)
63{
64  tile.r[i] = rgb.x;
65  tile.g[i] = rgb.y;
66  tile.b[i] = rgb.z;
67  tile.a[i] = alpha;
68}
69
70inline void setRGBAZ(uniform Tile &tile,
71    const varying uint32 i,
72    const varying vec3f rgb,
73    const varying float alpha,
74    const varying float z)
75{
76  tile.r[i] = rgb.x;
77  tile.g[i] = rgb.y;
78  tile.b[i] = rgb.z;
79  tile.a[i] = alpha;
80  tile.z[i] = z;
81}
82
83inline void setRGBA(
84    uniform Tile &tile, const varying uint32 i, const varying vec4f rgba)
85{
86  tile.r[i] = rgba.x;
87  tile.g[i] = rgba.y;
88  tile.b[i] = rgba.z;
89  tile.a[i] = rgba.w;
90}
91
92inline void setNormalAlbedo(
93    uniform Tile &tile, const uint32 i, const vec3f normal, const vec3f albedo)
94{
95  tile.nx[i] = normal.x;
96  tile.ny[i] = normal.y;
97  tile.nz[i] = normal.z;
98  tile.ar[i] = albedo.x;
99  tile.ag[i] = albedo.y;
100  tile.ab[i] = albedo.z;
101}
102