File: forest.cpp

package info (click to toggle)
embree 4.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 100,656 kB
  • sloc: cpp: 228,918; xml: 40,944; ansic: 2,685; python: 812; sh: 635; makefile: 228; csh: 42
file content (151 lines) | stat: -rw-r--r-- 5,613 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../common/tutorial/tutorial.h"
#include "../common/tutorial/benchmark_render.h"

#if defined(EMBREE_SYCL_TUTORIAL)
#  define NAME "forest_sycl"
#  define FEATURES FEATURE_RTCORE | FEATURE_SYCL
#else
#  define NAME "forest"
#  define FEATURES FEATURE_RTCORE
#endif

namespace embree
{
  typedef void (*DrawGUI)(void);

  extern "C" {
    #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
    bool g_use_instance_array = true;
    #else
    bool g_use_instance_array = false;
    #endif
    int  g_complexity = 2;
    bool g_rebuild = true;
    bool g_animate = true;
    bool g_trees_changed = false;
    bool g_trees_moved = false;
    size_t g_memory_consumed = 0;
    size_t g_cycles_cleanup = 0;
    size_t g_cycles_objects = 0;
    size_t g_cycles_embree_objects = 0;
    size_t g_cycles_embree_bvh_build = 0;
    size_t g_cycles_total = 0;
    int g_build_quality = g_animate ? 0 : 1; // low = 0, med = 1, high = 2, refit = 3
    int g_spp = 2; // will be squared in device
    int mode = g_animate ? 1 : 0; // rebuild = 0, update = 1
    int g_trees[] = { 0, 1, 2, 3, 4, 5 };
    int focal_length = 24;

    /*
     * a very simple time stamp with microsecond resolution that can also be
     * used from the ISPC side
     */
    int64_t get_clock()
    {
#if defined(__MACOSX__)
      // oh apple
      return 0;
#else
      struct timespec now;
      timespec_get(&now, TIME_UTC);
      return ((int64_t) now.tv_sec) * 1000000 + ((int64_t) now.tv_nsec) / 1000;
#endif
    }

    /*
     * returns the elapsed time in full milliseconds for a time stamp delta has
     * enough accuracy for a couple of seconds
     */
    uint32_t get_milliseconds(int64_t diff) {
      return uint32_t(((double)diff)/1000);
    }
  }

  struct Tutorial : public TutorialApplication
  {
    Tutorial()
      : TutorialApplication(NAME,FEATURES,1280,720)
    {
      /* set default camera */
      camera.from = Vec3fa(507.72, 109.37, 1173.20);
      camera.to   = Vec3fa(504.62, 108.63, 1161.37);
    }

#if defined(USE_GLFW)

    void drawGUI() override
    {
      if (ImGui::Button("Rebuild")) {
        mode = 0;
        g_rebuild = true;
      }
    #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
      if (ImGui::Checkbox("Use instance arrays", &g_use_instance_array)) {
        mode = 0;
        g_rebuild = true;
      }
    #endif
      mode = g_animate ? 1 : 0;
      ImGui::Checkbox("Animate", &g_animate);

      if (ImGui::SliderInt("Zoom", &focal_length, 24, 120)) {
        camera.fov = 90.f / std::pow(((float)focal_length) / 24.f, 2.f);
      }

      ImGui::Text("Build quality:");
      if (ImGui::RadioButton("Low",    &g_build_quality, 0)) { g_build_quality = 0; g_rebuild = true; mode = 0; };
      ImGui::SameLine();
      if (ImGui::RadioButton("Medium", &g_build_quality, 1)) { g_build_quality = 1; g_rebuild = true; mode = 0; };
      ImGui::SameLine();
      if (ImGui::RadioButton("High",   &g_build_quality, 2)) { g_build_quality = 2; g_rebuild = true; mode = 0; };

      ImGui::Text("Samples per pixel:");
      if (ImGui::RadioButton("1", &g_spp, 1)) { g_spp = 1; };
      ImGui::SameLine();
      if (ImGui::RadioButton("4", &g_spp, 2)) { g_spp = 2; };
      ImGui::SameLine();
      if (ImGui::RadioButton("9", &g_spp, 3)) { g_spp = 3; };

      ImGui::Text("Number of trees/instances:");
      if (ImGui::RadioButton("250k",  &g_complexity, 0)) { g_complexity = 0; g_rebuild = true; mode = 0; };
      ImGui::SameLine();
      if (ImGui::RadioButton("500k",  &g_complexity, 1)) { g_complexity = 1; g_rebuild = true; mode = 0; };
      ImGui::SameLine();
      if (ImGui::RadioButton("1000k", &g_complexity, 2)) { g_complexity = 2; g_rebuild = true; mode = 0; };
      ImGui::SameLine();
      if (ImGui::RadioButton("4000k", &g_complexity, 3)) { g_complexity = 3; g_rebuild = true; mode = 0; };

      const char* types[] = { "Tree1", "Tree2", "Tree3", "Tree4", "Tree5", "Tree6" };
      ImGui::Text("Trees:");
      if (ImGui::Combo("Slot 1", &g_trees[0], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };
      if (ImGui::Combo("Slot 2", &g_trees[1], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };
      if (ImGui::Combo("Slot 3", &g_trees[2], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };
      if (ImGui::Combo("Slot 4", &g_trees[3], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };
      if (ImGui::Combo("Slot 5", &g_trees[4], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };
      if (ImGui::Combo("Slot 6", &g_trees[5], types, IM_ARRAYSIZE(types))) { g_trees_changed = true; mode = 1; };

      ImGui::Text("%s", ("Memory consumption: " + std::to_string(g_memory_consumed/1024/1024) + " MB").c_str());
      if (mode == 0) ImGui::Text("Build timings:");
      else           ImGui::Text("Update timings:");
      ImGui::Text("  Scene Data %d ms", get_milliseconds(g_cycles_objects));
      ImGui::Text("  Embree Data %d ms", get_milliseconds(g_cycles_embree_objects));
      ImGui::Text("  Embree BVH %d ms", get_milliseconds(g_cycles_embree_bvh_build));
      if (mode == 0) ImGui::Text("  Cleanup old scene data %d ms", get_milliseconds(g_cycles_cleanup));
      ImGui::Text("  Total %d ms", get_milliseconds(g_cycles_total));
    }

#endif

  };

}

int main(int argc, char** argv) {
  if (embree::TutorialBenchmark::benchmark(argc, argv)) {
    return embree::TutorialBenchmark(embree::renderBenchFunc<embree::Tutorial>).main(argc, argv, "forest");
  }
  return embree::Tutorial().main(argc,argv);
}