Add profiling with Remotery

This commit is contained in:
David 2021-08-24 20:55:39 +02:00
commit 6331a2bf79
50 changed files with 16864 additions and 11 deletions

View file

@ -2,8 +2,17 @@
#include <stdint.h>
#include <stdlib.h>
#include "rtweekend.hpp"
// Lib includes
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <Remotery.c>
#pragma GCC diagnostic pop
// Internal includes
#include "rtweekend.hpp"
#include "color.hpp"
#include "hittable_list.hpp"
#include "sphere.hpp"
@ -69,6 +78,7 @@ hittable_list random_scene() {
color ray_color(const ray& r, const hittable& world, int32_t depth)
{
rmt_ScopedCPUSample(Scatter, RMTSF_Aggregate | RMTSF_Recursive);
if (depth <= 0)
{
return color(0,0,0);
@ -79,7 +89,10 @@ color ray_color(const ray& r, const hittable& world, int32_t depth)
{
ray scattered;
color attenuation;
if (rec.mat_ptr->scatter(r, rec, attenuation, scattered))
rmt_BeginCPUSample(Scatter, RMTSF_Aggregate);
bool visible = rec.mat_ptr->scatter(r, rec, attenuation, scattered);
rmt_EndCPUSample();
if (visible)
{
return attenuation * ray_color(scattered, world, depth-1);
}
@ -94,7 +107,7 @@ color ray_color(const ray& r, const hittable& world, int32_t depth)
}
double hit_sphere(const point3& center, double radius, const ray& r)
{
{
vec3 oc = r.origin - center;
double a = r.direction.length_squared();
double half_b = dot(oc, r.direction);
@ -107,8 +120,14 @@ double hit_sphere(const point3& center, double radius, const ray& r)
return (-half_b - sqrt(discriminant)) / a;
}
int32_t main()
{
{
/* Profiling library initialization */
Remotery *rmt;
if (RMT_ERROR_NONE != rmt_CreateGlobalInstance(&rmt))
{
fprintf(stderr, "Error starting Remotery\n");
}
// Image
const double aspect_ratio = 3.0 / 2.0;
@ -139,14 +158,17 @@ int32_t main()
// Render
printf("P3\n%d %d\n255\n", image_width, image_height);
for (int32_t j = image_height - 1; j >= 0; --j)
{
rmt_ScopedCPUSample(OuterLoop, RMTSF_Aggregate);
fprintf(stderr, "\rScanlines remaining: %d ", j);
fflush(stderr);
for (int32_t i = 0; i < image_width; ++i)
{
{
rmt_ScopedCPUSample(InnerLoop, RMTSF_Aggregate);
color pixel_color = color(0,0,0);
for (int32_t s = 0; s < samples_per_pixel; ++s)
{
double u = ((i + random_double()) / (image_width-1));
@ -158,5 +180,7 @@ int32_t main()
write_color(stdout, pixel_color, samples_per_pixel);
}
}
fprintf(stderr, "\nDone\n");
rmt_DestroyGlobalInstance(rmt);
}