stage/schema/types.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include "chrono_batch_render/stage/columns/kernels/paged.h" | ||
| 5 | |||
| 6 | #ifndef __SLANG__ | ||
| 7 | #include <cstdint> | ||
| 8 | #include <functional> | ||
| 9 | #include <map> | ||
| 10 | #include <string> | ||
| 11 | #include <vector> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | namespace chrono::batch_render { | ||
| 15 | |||
| 16 | #ifdef __SLANG__ | ||
| 17 | |||
| 18 | struct Float2 { | ||
| 19 | float x; | ||
| 20 | float y; | ||
| 21 | |||
| 22 | __init() { | ||
| 23 | x = 0; | ||
| 24 | y = 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | __init(float2 v) { | ||
| 28 | x = v.x; | ||
| 29 | y = v.y; | ||
| 30 | } | ||
| 31 | |||
| 32 | float2 Vector() { | ||
| 33 | return float2(x, y); | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct Uint2 { | ||
| 38 | uint x; | ||
| 39 | uint y; | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct Float3 { | ||
| 43 | float x; | ||
| 44 | float y; | ||
| 45 | float z; | ||
| 46 | |||
| 47 | __init() { | ||
| 48 | x = 0; | ||
| 49 | y = 0; | ||
| 50 | z = 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | __init(float3 v) { | ||
| 54 | x = v.x; | ||
| 55 | y = v.y; | ||
| 56 | z = v.z; | ||
| 57 | } | ||
| 58 | |||
| 59 | float3 Vector() { | ||
| 60 | return float3(x, y, z); | ||
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct Float4 { | ||
| 65 | float x; | ||
| 66 | float y; | ||
| 67 | float z; | ||
| 68 | float w; | ||
| 69 | |||
| 70 | __init() { | ||
| 71 | x = 0; | ||
| 72 | y = 0; | ||
| 73 | z = 0; | ||
| 74 | w = 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | __init(float4 v) { | ||
| 78 | x = v.x; | ||
| 79 | y = v.y; | ||
| 80 | z = v.z; | ||
| 81 | w = v.w; | ||
| 82 | } | ||
| 83 | |||
| 84 | float4 Vector() { | ||
| 85 | return float4(x, y, z, w); | ||
| 86 | } | ||
| 87 | }; | ||
| 88 | |||
| 89 | struct Double3 { | ||
| 90 | uint x[2]; | ||
| 91 | uint y[2]; | ||
| 92 | uint z[2]; | ||
| 93 | }; | ||
| 94 | |||
| 95 | struct Quatd { | ||
| 96 | uint x[2]; | ||
| 97 | uint y[2]; | ||
| 98 | uint z[2]; | ||
| 99 | uint w[2]; | ||
| 100 | }; | ||
| 101 | |||
| 102 | #else | ||
| 103 | |||
| 104 | 1005 | struct Float2 { | |
| 105 | float x = 0, y = 0; | ||
| 106 | |||
| 107 | 7 | bool operator==(const Float2& other) const { | |
| 108 | 7 | return x == other.x && y == other.y; | |
| 109 | } | ||
| 110 | |||
| 111 | ✗ | bool operator!=(const Float2& other) const { | |
| 112 | ✗ | return !(*this == other); | |
| 113 | } | ||
| 114 | }; | ||
| 115 | |||
| 116 | 915 | struct Uint2 { | |
| 117 | uint32_t x = 0, y = 0; | ||
| 118 | |||
| 119 | 441 | bool operator==(const Uint2& other) const { | |
| 120 | 441 | return x == other.x && y == other.y; | |
| 121 | } | ||
| 122 | |||
| 123 | bool operator!=(const Uint2& other) const { | ||
| 124 | return !(*this == other); | ||
| 125 | } | ||
| 126 | }; | ||
| 127 | |||
| 128 | 2307 | struct Float3 { | |
| 129 | float x = 0, y = 0, z = 0; | ||
| 130 | |||
| 131 | 63 | bool operator==(const Float3& other) const { | |
| 132 | 62 | return x == other.x && y == other.y && z == other.z; | |
| 133 | } | ||
| 134 | |||
| 135 | 5 | bool operator!=(const Float3& other) const { | |
| 136 | 9 | return !(*this == other); | |
| 137 | } | ||
| 138 | }; | ||
| 139 | |||
| 140 | 9591 | struct Float4 { | |
| 141 | float x = 0, y = 0, z = 0, w = 0; | ||
| 142 | |||
| 143 | ✗ | bool operator==(const Float4& other) const { | |
| 144 | ✗ | return x == other.x && y == other.y && z == other.z && w == other.w; | |
| 145 | } | ||
| 146 | |||
| 147 | ✗ | bool operator!=(const Float4& other) const { | |
| 148 | ✗ | return !(*this == other); | |
| 149 | } | ||
| 150 | }; | ||
| 151 | |||
| 152 | 375 | struct Double3 { | |
| 153 | double x = 0, y = 0, z = 0; | ||
| 154 | |||
| 155 | 106 | bool operator==(const Double3& other) const { | |
| 156 | 106 | return x == other.x && y == other.y && z == other.z; | |
| 157 | } | ||
| 158 | |||
| 159 | bool operator!=(const Double3& other) const { | ||
| 160 | return !(*this == other); | ||
| 161 | } | ||
| 162 | }; | ||
| 163 | |||
| 164 | 10 | struct Quatd { | |
| 165 | double x = 0, y = 0, z = 0, w = 1; | ||
| 166 | |||
| 167 | 3 | bool operator==(const Quatd& other) const { | |
| 168 | 3 | return x == other.x && y == other.y && z == other.z && w == other.w; | |
| 169 | } | ||
| 170 | |||
| 171 | bool operator!=(const Quatd& other) const { | ||
| 172 | return !(*this == other); | ||
| 173 | } | ||
| 174 | }; | ||
| 175 | |||
| 176 | using InstancedTokens = std::map<std::string, std::vector<std::string>, std::less<>>; | ||
| 177 | |||
| 178 | #endif | ||
| 179 | |||
| 180 | CHRONO_BATCH_RENDER_CHECK_SIZE(Float2, 8); | ||
| 181 | CHRONO_BATCH_RENDER_CHECK_SIZE(Uint2, 8); | ||
| 182 | CHRONO_BATCH_RENDER_CHECK_SIZE(Float3, 12); | ||
| 183 | CHRONO_BATCH_RENDER_CHECK_SIZE(Float4, 16); | ||
| 184 | CHRONO_BATCH_RENDER_CHECK_SIZE(Double3, 24); | ||
| 185 | CHRONO_BATCH_RENDER_CHECK_SIZE(Quatd, 32); | ||
| 186 | |||
| 187 | struct ArrayRef { | ||
| 188 | uint64_t address; | ||
| 189 | uint count; | ||
| 190 | uint capacity; | ||
| 191 | }; | ||
| 192 | |||
| 193 | CHRONO_BATCH_RENDER_CHECK_SIZE(ArrayRef, 16); | ||
| 194 | |||
| 195 | 57 | struct WorldTransform { | |
| 196 | Float3 x; | ||
| 197 | Float3 y; | ||
| 198 | Float3 z; | ||
| 199 | Float3 high; | ||
| 200 | Float3 low; | ||
| 201 | |||
| 202 | #ifdef __SLANG__ | ||
| 203 | float3 Translation() { | ||
| 204 | return high.Vector() + low.Vector(); | ||
| 205 | } | ||
| 206 | |||
| 207 | float3 TranslationFrom(WorldTransform origin) { | ||
| 208 | return (high.Vector() - origin.high.Vector()) + (low.Vector() - origin.low.Vector()); | ||
| 209 | } | ||
| 210 | |||
| 211 | float3 Apply(float3 v) { | ||
| 212 | return x.Vector() * v.x + y.Vector() * v.y + z.Vector() * v.z; | ||
| 213 | } | ||
| 214 | |||
| 215 | float3 ApplyToNormal(float3 n) { | ||
| 216 | return cross(y.Vector(), z.Vector()) * n.x + cross(z.Vector(), x.Vector()) * n.y + | ||
| 217 | cross(x.Vector(), y.Vector()) * n.z; | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | }; | ||
| 221 | |||
| 222 | CHRONO_BATCH_RENDER_CHECK_SIZE(WorldTransform, 60); | ||
| 223 | |||
| 224 | } | ||
| 225 |