Commit 48807db0 authored by Johannes Braun's avatar Johannes Braun
Browse files

Added sys info window

parent 118706f3
......@@ -4,12 +4,22 @@ Size=353,64
Collapsed=0
[Scene]
Pos=29,64
Size=312,787
Pos=1,0
Size=302,900
Collapsed=0
[Settings]
Pos=1117,12
Size=311,899
Pos=1145,2
Size=295,531
Collapsed=0
[GPU MEM]
Pos=617,39
Size=172,86
Collapsed=0
[System]
Pos=1145,532
Size=295,368
Collapsed=0
<linespace version="1.0">
<item name="subdivisions" value="8"/>
<item name="grid-subdivisions" value="4"/>
<item name="grid-subdivisions" value="10"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -122,6 +122,9 @@ bool traverseObjects(const in Scene scene, const in Ray ray, const in bool use_f
{
int ls_index = index.x + index.y * mesh.grid_linespace.grid_resolution.x + index.z * mesh.grid_linespace.grid_resolution.x * mesh.grid_linespace.grid_resolution.y;
if(ls_index >= mesh.grid_linespace.num_linespaces)
break;
int axis = smallestAxis(tnext);
float mint = t_min;
......
......@@ -138,7 +138,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
if (mesh.grid_linespace.linespaces[index].line_count == 0) return false;
Ray loc = local_ray;
loc.origin += 1e-4f * loc.direction;
loc.origin += 0.08f * loc.direction;
if(!loc.intersectsBounds(mesh.grid_linespace.linespaces[index].bounds, tmin, tmax, face_tmin, face_tmax) || t_min <= tmin || tmin > max_distance)
{
......@@ -148,6 +148,9 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
bool swapped = false;
uint line_id = lineIndex(loc, mesh, index, tmin, tmax, face_tmin, face_tmax, swapped);
if(line_id * 2 + 1 > mesh.grid_linespace.linespaces[index].line_count)
return false;
Line line_near = mesh.grid_linespace.linespaces[index].lines[line_id * 2];
Line line_far = mesh.grid_linespace.linespaces[index].lines[line_id * 2 + 1];
......
......@@ -141,7 +141,7 @@ bool shade(inout Bounce bounce)
const vec2 base_random = vec2(bounce.ray.px, bounce.ray.py) - ivec2(floor(bounce.ray.px), floor(bounce.ray.py));
const ivec2 img_size = render_target.imageSize();
const int img_dimen = img_size.x * img_size.y;
const vec2 random_sample = rand2D((random_seed + int(gl_GlobalInvocationID.y * uint(img_size.x) + gl_GlobalInvocationID.x))%img_dimen, img_size.x * img_size.y);
const vec2 random_sample = rand2D((random_seed + int(gl_GlobalInvocationID.y * uint(img_size.x) + gl_GlobalInvocationID.x)), img_size.x * img_size.y);
BSDFResult bsdf_result = material.computeBSDF(random_sample, vertex, bounce.ray);
......
#include <array>
#include <sstream>
#include <algorithm>
#include <imgui/imgui_glfw.h>
......@@ -12,7 +14,6 @@
#include <raytrace/tracer/pathtracer.h>
#include <components/FramerateCounter.h>
#include <components/PlayerController.h>
#include "core/res/collada.h"
#include "components/transformator.h"
......@@ -45,6 +46,7 @@ RenderMode render_mode = RenderMode::eGBuffer;
// All functions used in here
void keyPress(controls::Key key, controls::KeyMods mods);
void loadScene(const fs::path& path, float scale = 1.f);
void drawSystemWindow();
void drawSettingsWindow();
void drawSceneWindow();
......@@ -72,9 +74,6 @@ int main(int argc, char* argv[])
pathtracer = std::make_unique<raytrace::Pathtracer>();
pathtracer->loadSettings(pathtracer_settings_path);
// For debug purposes, add a frame rate counter to the root node, which will never be deleted/removed on runtime if not explicitly told so.
core::Context::current().graph()->makeComponent<component::FramerateCounter>();
core::Context::current().loop([&]()
{
switch (render_mode)
......@@ -95,6 +94,7 @@ int main(int argc, char* argv[])
drawSceneWindow();
drawSettingsWindow();
drawSystemWindow();
});
}
......@@ -150,6 +150,79 @@ void loadScene(const fs::path& path, float scale)
ImGui::ClearSelectableTreeData("tree_scene_graph");
}
void drawSystemWindow()
{
ImGui::Begin("System");
static int mem;
static int left;
static int frame = 0;
static double time = 0;
static float frametime = 0;
static float fps = 0;
static int ft_count = 0;
const static int size = 50;
static std::vector<float> frametimes(size);
static std::vector<float> mem_fills(size);
frame++;
time += core::Time::deltaTime();
if (time >= 1)
{
frametime = static_cast<float>(1000 * time / frame);
fps = 1000.f / frametime;
Log_Debug << std::to_string(frame) << " FPS | " << std::to_string(1000 * time / frame) << "ms/Frame";
time = 0;
frame = 0;
gl::getIntegerv(gl::GetParameter::eGpuMemoryDedicatedVidmemMax, &mem);
gl::getIntegerv(gl::GetParameter::eGpuMemoryCurrentAvailableVidmem, &left);
if (ft_count > frametimes.size()-1)
{
std::rotate(frametimes.begin(), frametimes.begin() + 1, frametimes.end());
frametimes[frametimes.size()-1] = frametime;
std::rotate(mem_fills.begin(), mem_fills.begin() + 1, mem_fills.end());
mem_fills[mem_fills.size() - 1] = static_cast<float>(mem-left) / 1'000'000.f;
}
else
{
frametimes[ft_count] = frametime;
mem_fills[ft_count] = static_cast<float>(mem - left) / 1'000'000.f;
}
++ft_count;
}
const auto format_float = [](float f, int prec) {
std::stringstream ss;
ss << std::fixed << std::setprecision(prec) << f;
return ss.str();
};
#if _DEBUG
const std::string build_type = "Debug build";
#elif NDEBUG
const std::string build_type = "Release build";
#endif
ImGui::Text(build_type.c_str());
ImGui::Spacing();
ImGui::Title("Memory");
ImGui::ProgressBar((mem - left) / static_cast<float>(mem), ImVec2(-1, 0), (format_float(static_cast<float>(mem - left) / 1'000'000, 2) + "GB used").c_str());
ImGui::Text(("Total memory: " + format_float(static_cast<float>(mem) / 1'000'000, 2) + "GB").c_str());
ImGui::Text(("Available memory: " + format_float(static_cast<float>(left) / 1'000'000, 2) + "GB").c_str());
ImGui::PlotLines("", mem_fills.data(), mem_fills.size(), 0, "Filled Memory", 0, mem / 1'000'000.f, ImVec2(ImGui::GetContentRegionAvailWidth(), 64));
ImGui::Spacing();
ImGui::Title("Performance");
ImGui::Value("Frames per second", fps);
ImGui::Text(("Frame time: " + format_float(frametime, 3) + "ms").c_str());
ImGui::PlotLines("", frametimes.data(), frametimes.size(), 0, "Frame times", 0, 100, ImVec2(ImGui::GetContentRegionAvailWidth(), 64));
ImGui::End();
}
void drawSceneWindow()
{
static int current_tab = 0;
......@@ -392,12 +465,6 @@ void drawSceneWindow()
selected_node->makeComponent<component::Transformator>();
}
if (ImGui::Button("Framerate Counter", ImVec2(180, 24)))
{
if (selected_node)
selected_node->makeComponent<component::FramerateCounter>();
}
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
......
#include "util/files.h"
#include <string>
#include "core/base/glsl.h"
#include <mcpp_glsl/mcpp_glsl.h>
#include <core/state.h>
std::string preprocessGlsl(const fs::path& shader, const std::vector<std::string>& include_paths)
{
mcpp::mcpp_use_mem_buffers(1);
std::vector<const char*> args;
args.push_back("mcpp");
auto path = shader.string();
args.push_back(path.c_str());
for (const auto& inc : include_paths)
{
args.push_back("-I");
args.push_back(inc.c_str());
}
mcpp::mcpp_lib_main(static_cast<int>(args.size()), const_cast<char**>(args.data()));
char* result = mcpp::mcpp_get_mem_buffer(mcpp::OUT);
// Now we just have to revert the order of #version and the first #line
std::string line;
bool ln_name = false;
while (*(++result) != '\n')
{
if (*result == '"')
ln_name = true;
if (ln_name)
line += *result;
}
std::string src(result + 1);
auto it = src.begin();
for (; *it != '\n'; ++it)
{
}
line = "\n#line 2 " + line;
src.insert(it, line.begin(), line.end());
glare::core::GLSLParser::format(src);
return src;
}
int main(int argc, char* argv[])
{
glare::core::Context::createAsCurrent(files::asset("/preferences/default.xml"));
auto src = preprocessGlsl(files::asset("shaders/pathtracer/pathtracer.comp"), std::vector<std::string>{ files::asset("shaders").string() });
int mem;
glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &mem);
int left;
glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &left);
Log_Info << mem << ", " << left << '\n';
auto sh = std::make_shared<glare::core::Shader>(gl::ShaderType::eCompute, src, "aosidjsdi");
glare::core::Program program(sh);
system("pause");
return 0;
}
#include "FramerateCounter.h"
#include <core/time.h>
#include <util/log.h>
#include <imgui/imgui_glfw.h>
#include <string>
namespace glare::component
{
FramerateCounter::FramerateCounter()
: SceneComponent("Framerate Counter")
{
}
void FramerateCounter::onUpdate()
{
frame++;
time += core::Time::deltaTime();
if (time >= 1)
{
fps = static_cast<float>(frame);
frametime = static_cast<float>(1000 * time / frame);
Log_Debug << std::to_string(frame) << " FPS | " << std::to_string(1000 * time / frame) << "ms/Frame";
time = 0;
frame = 0;
}
#if _DEBUG
const std::string build_type = "Debug build | ";
#elif NDEBUG
const std::string build_type = "Release build | ";
#else
const std::string build_type = "UNKNOWN build | ";
#endif
ImGui::Begin("Debug");
ImGui::Text((build_type + std::to_string(fps) + "fps | " + std::to_string(frametime) + "ms/Frame").c_str());
ImGui::End();
}
}
#ifndef __FRAMERATECOUNTER_H
#define __FRAMERATECOUNTER_H
#include <core/graph/component.h>
namespace glare::component
{
class FramerateCounter : public core::SceneComponent
{
public:
FramerateCounter();
protected:
void onUpdate() override;
private:
float fps = 0;
float frametime = 0;
double time = 0;
int frame = 0;
};
}
#endif //__FRAMERATECOUNTER_H
......@@ -96,16 +96,30 @@ namespace glare::raytrace
m_trace_buffer.reserve<Trace>(width * height, gl::BufferUsage::eDynamicCopy);
m_render_target = std::make_unique<core::Texture>(core::Image<float>({ static_cast<int>(width), static_cast<int>(height) }, 4));
m_render_shader->uniform("render_target", m_render_target->imageAddress(gl::Access::eReadWrite));
m_render_shader->storageBuffer("trace_buffer", m_trace_buffer);
m_samples_current = 0;
}
if (m_samples_current == 0)
{
m_collector->collect();
m_render_shader->uniform("render_target", m_render_target->imageAddress(gl::Access::eReadWrite));
m_render_shader->storageBuffer("trace_buffer", m_trace_buffer);
m_collector->apply(*m_render_shader, "scene");
m_render_shader->uniform("bounce_count", m_bounce_count);
m_render_shader->uniform("clamp_direct", m_clamp_direct);
m_render_shader->uniform("clamp_indirect", m_clamp_indirect);
for (int i = 0; i < 4; ++i)
{
const std::string idx = "[" + std::to_string(i) + "]";
m_render_shader->uniform("bounce_thresholds" + idx, m_bounce_thresholds[i]);
m_render_shader->uniform("linespace_bounces" + idx, m_linespace_bounces[i]);
}
m_render_shader->uniform("linespace_accuracy", m_linespace_accuracy);
m_render_shader->uniform("linespace_shadow", m_linespace_shadow);
m_render_shader->uniform("linespace_distance", m_linespace_distance);
}
for (int sample = 0; sample < m_samples_per_frame; sample++) {
......
......@@ -206,6 +206,8 @@ namespace gl
eMaxTextureMaxAnisotropy = GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
eNumBinaryFormats = GL_NUM_SHADER_BINARY_FORMATS,
eBinaryFormats = GL_SHADER_BINARY_FORMATS,
eGpuMemoryDedicatedVidmemMax = GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX,
eGpuMemoryCurrentAvailableVidmem = GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
};
enum class GetShaderParameter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment