| 1 | // Copyright 2009-2021 Intel Corporation | 
|---|
| 2 | // SPDX-License-Identifier: Apache-2.0 | 
|---|
| 3 |  | 
|---|
| 4 | #pragma once | 
|---|
| 5 |  | 
|---|
| 6 | #include "default.h" | 
|---|
| 7 |  | 
|---|
| 8 | /* Macros to gather statistics */ | 
|---|
| 9 | #ifdef EMBREE_STAT_COUNTERS | 
|---|
| 10 | #  define STAT(x) x | 
|---|
| 11 | #  define STAT3(s,x,y,z) \ | 
|---|
| 12 | STAT(Stat::get().code  .s+=x);               \ | 
|---|
| 13 | STAT(Stat::get().active.s+=y);               \ | 
|---|
| 14 | STAT(Stat::get().all   .s+=z); | 
|---|
| 15 | #  define STAT_USER(i,x) Stat::get().user[i]+=x; | 
|---|
| 16 | #else | 
|---|
| 17 | #  define STAT(x) | 
|---|
| 18 | #  define STAT3(s,x,y,z) | 
|---|
| 19 | #  define STAT_USER(i,x) | 
|---|
| 20 | #endif | 
|---|
| 21 |  | 
|---|
| 22 | namespace embree | 
|---|
| 23 | { | 
|---|
| 24 | /*! Gathers ray tracing statistics. We count 1) how often a code | 
|---|
| 25 | *  location is reached, 2) how many SIMD lanes are active, 3) how | 
|---|
| 26 | *  many SIMD lanes reach the code location */ | 
|---|
| 27 | class Stat | 
|---|
| 28 | { | 
|---|
| 29 | public: | 
|---|
| 30 |  | 
|---|
| 31 | static const size_t SIZE_HISTOGRAM = 64+1; | 
|---|
| 32 |  | 
|---|
| 33 | /*! constructs stat counter class */ | 
|---|
| 34 | Stat (); | 
|---|
| 35 |  | 
|---|
| 36 | /*! destructs stat counter class */ | 
|---|
| 37 | ~Stat (); | 
|---|
| 38 |  | 
|---|
| 39 | class Counters | 
|---|
| 40 | { | 
|---|
| 41 | public: | 
|---|
| 42 | Counters () { | 
|---|
| 43 | clear(); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | void clear() | 
|---|
| 47 | { | 
|---|
| 48 | all.clear(); | 
|---|
| 49 | active.clear(); | 
|---|
| 50 | code.clear(); | 
|---|
| 51 | for (auto& u : user) u.store(0); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | public: | 
|---|
| 55 |  | 
|---|
| 56 | /* per packet and per ray stastics */ | 
|---|
| 57 | struct Data | 
|---|
| 58 | { | 
|---|
| 59 | void clear () { | 
|---|
| 60 | normal.clear(); | 
|---|
| 61 | shadow.clear(); | 
|---|
| 62 | point_query.clear(); | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | /* normal and shadow ray statistics */ | 
|---|
| 66 | struct | 
|---|
| 67 | { | 
|---|
| 68 | void clear() | 
|---|
| 69 | { | 
|---|
| 70 | travs.store(0); | 
|---|
| 71 | trav_nodes.store(0); | 
|---|
| 72 | trav_leaves.store(0); | 
|---|
| 73 | trav_prims.store(0); | 
|---|
| 74 | trav_prim_hits.store(0); | 
|---|
| 75 | for (auto& v : trav_hit_boxes) v.store(0); | 
|---|
| 76 | trav_stack_pop.store(0); | 
|---|
| 77 | trav_stack_nodes.store(0); | 
|---|
| 78 | trav_xfm_nodes.store(0); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | public: | 
|---|
| 82 | std::atomic<size_t> travs; | 
|---|
| 83 | std::atomic<size_t> trav_nodes; | 
|---|
| 84 | std::atomic<size_t> trav_leaves; | 
|---|
| 85 | std::atomic<size_t> trav_prims; | 
|---|
| 86 | std::atomic<size_t> trav_prim_hits; | 
|---|
| 87 | std::atomic<size_t> trav_hit_boxes[SIZE_HISTOGRAM+1]; | 
|---|
| 88 | std::atomic<size_t> trav_stack_pop; | 
|---|
| 89 | std::atomic<size_t> trav_stack_nodes; | 
|---|
| 90 | std::atomic<size_t> trav_xfm_nodes; | 
|---|
| 91 |  | 
|---|
| 92 | } normal, shadow, point_query; | 
|---|
| 93 | } all, active, code; | 
|---|
| 94 |  | 
|---|
| 95 | std::atomic<size_t> user[10]; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | public: | 
|---|
| 99 |  | 
|---|
| 100 | static __forceinline Counters& get() { | 
|---|
| 101 | return instance.cntrs; | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | static void clear() { | 
|---|
| 105 | instance.cntrs.clear(); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | static void print(embree_ostream cout); | 
|---|
| 109 |  | 
|---|
| 110 | private: | 
|---|
| 111 | Counters cntrs; | 
|---|
| 112 |  | 
|---|
| 113 | private: | 
|---|
| 114 | static Stat instance; | 
|---|
| 115 | }; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|