device/kernels/shared.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #ifdef __SLANG__ | ||
| 5 | |||
| 6 | #define CHRONO_BATCH_RENDER_SHARED | ||
| 7 | #define CHRONO_BATCH_RENDER_CHECK_SIZE(type, bytes) | ||
| 8 | #define CHRONO_BATCH_RENDER_ENUM(name) enum class name : uint | ||
| 9 | |||
| 10 | #else | ||
| 11 | |||
| 12 | #include <algorithm> | ||
| 13 | #include <cmath> | ||
| 14 | #include <cstdint> | ||
| 15 | #include <cstring> | ||
| 16 | |||
| 17 | #define CHRONO_BATCH_RENDER_SHARED inline | ||
| 18 | #define CHRONO_BATCH_RENDER_CHECK_SIZE(type, bytes) \ | ||
| 19 | static_assert(sizeof(type) == (bytes), #type " keeps its shared layout") | ||
| 20 | #define CHRONO_BATCH_RENDER_ENUM(name) enum class name : uint32_t | ||
| 21 | |||
| 22 | namespace chrono::batch_render { | ||
| 23 | |||
| 24 | using uint = uint32_t; | ||
| 25 | |||
| 26 | 1142737 | constexpr uint64_t RoundUp(uint64_t value, uint64_t multiple) { | |
| 27 | 1105373 | return (value + multiple - 1) / multiple * multiple; | |
| 28 | } | ||
| 29 | |||
| 30 | using std::ceil; | ||
| 31 | using std::clamp; | ||
| 32 | using std::floor; | ||
| 33 | using std::log2; | ||
| 34 | using std::max; | ||
| 35 | using std::min; | ||
| 36 | using std::pow; | ||
| 37 | |||
| 38 | template <class T> struct Ptr { | ||
| 39 | uint64_t address = 0; | ||
| 40 | }; | ||
| 41 | |||
| 42 | 111292 | inline float asfloat(uint bits) { | |
| 43 | 111292 | float value; | |
| 44 | 109240 | std::memcpy(&value, &bits, sizeof(value)); | |
| 45 | 109240 | return value; | |
| 46 | } | ||
| 47 | |||
| 48 | 65825 | inline uint asuint(float value) { | |
| 49 | 65825 | uint bits; | |
| 50 | 65826 | std::memcpy(&bits, &value, sizeof(bits)); | |
| 51 | 65825 | return bits; | |
| 52 | } | ||
| 53 | |||
| 54 | } | ||
| 55 | |||
| 56 | #endif | ||
| 57 |