2023-06-14 06:52:36 +00:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2018-11-29 01:06:30 +00:00
|
|
|
|
|
|
|
#ifndef __UTIL_PROFILING_H__
|
|
|
|
#define __UTIL_PROFILING_H__
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/map.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/vector.h"
|
2018-11-29 01:06:30 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2018-11-29 15:41:10 +00:00
|
|
|
enum ProfilingEvent : uint32_t {
|
2018-11-29 01:06:30 +00:00
|
|
|
PROFILING_UNKNOWN,
|
|
|
|
PROFILING_RAY_SETUP,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
|
|
|
PROFILING_INTERSECT_CLOSEST,
|
|
|
|
PROFILING_INTERSECT_SUBSURFACE,
|
|
|
|
PROFILING_INTERSECT_SHADOW,
|
|
|
|
PROFILING_INTERSECT_VOLUME_STACK,
|
2023-05-24 11:36:13 +00:00
|
|
|
PROFILING_INTERSECT_DEDICATED_LIGHT,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
|
|
|
PROFILING_SHADE_SURFACE_SETUP,
|
|
|
|
PROFILING_SHADE_SURFACE_EVAL,
|
|
|
|
PROFILING_SHADE_SURFACE_DIRECT_LIGHT,
|
|
|
|
PROFILING_SHADE_SURFACE_INDIRECT_LIGHT,
|
|
|
|
PROFILING_SHADE_SURFACE_AO,
|
|
|
|
PROFILING_SHADE_SURFACE_PASSES,
|
2023-05-24 11:36:13 +00:00
|
|
|
PROFILING_SHADE_DEDICATED_LIGHT,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
|
|
|
PROFILING_SHADE_VOLUME_SETUP,
|
|
|
|
PROFILING_SHADE_VOLUME_INTEGRATE,
|
|
|
|
PROFILING_SHADE_VOLUME_DIRECT_LIGHT,
|
|
|
|
PROFILING_SHADE_VOLUME_INDIRECT_LIGHT,
|
|
|
|
|
|
|
|
PROFILING_SHADE_SHADOW_SETUP,
|
|
|
|
PROFILING_SHADE_SHADOW_SURFACE,
|
|
|
|
PROFILING_SHADE_SHADOW_VOLUME,
|
|
|
|
|
|
|
|
PROFILING_SHADE_LIGHT_SETUP,
|
|
|
|
PROFILING_SHADE_LIGHT_EVAL,
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-11-29 01:06:30 +00:00
|
|
|
PROFILING_NUM_EVENTS,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Contains the current execution state of a worker thread.
|
|
|
|
* These values are constantly updated by the worker.
|
|
|
|
* Periodically the profiler thread will wake up, read them
|
|
|
|
* and update its internal counters based on it.
|
|
|
|
*
|
|
|
|
* Atomics aren't needed here since we're only doing direct
|
|
|
|
* writes and reads to (4-byte-aligned) uint32_t, which is
|
|
|
|
* guaranteed to be atomic on x86 since the 486.
|
|
|
|
* Memory ordering is not guaranteed but does not matter.
|
|
|
|
*
|
|
|
|
* And even on other architectures, the extremely rare corner
|
|
|
|
* case of reading an intermediate state could at worst result
|
|
|
|
* in a single incorrect sample. */
|
|
|
|
struct ProfilingState {
|
|
|
|
volatile uint32_t event = PROFILING_UNKNOWN;
|
|
|
|
volatile int32_t shader = -1;
|
|
|
|
volatile int32_t object = -1;
|
|
|
|
volatile bool active = false;
|
|
|
|
|
|
|
|
vector<uint64_t> shader_hits;
|
|
|
|
vector<uint64_t> object_hits;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Profiler {
|
|
|
|
public:
|
|
|
|
Profiler();
|
|
|
|
~Profiler();
|
|
|
|
|
|
|
|
void reset(int num_shaders, int num_objects);
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
void add_state(ProfilingState *state);
|
|
|
|
void remove_state(ProfilingState *state);
|
|
|
|
|
|
|
|
uint64_t get_event(ProfilingEvent event);
|
|
|
|
bool get_shader(int shader, uint64_t &samples, uint64_t &hits);
|
|
|
|
bool get_object(int object, uint64_t &samples, uint64_t &hits);
|
|
|
|
|
2021-11-12 09:01:23 +00:00
|
|
|
bool active() const;
|
|
|
|
|
2018-11-29 01:06:30 +00:00
|
|
|
protected:
|
|
|
|
void run();
|
|
|
|
|
|
|
|
/* Tracks how often the worker was in each ProfilingEvent while sampling,
|
|
|
|
* so multiplying the values by the sample frequency (currently 1ms)
|
|
|
|
* gives the approximate time spent in each state. */
|
|
|
|
vector<uint64_t> event_samples;
|
|
|
|
vector<uint64_t> shader_samples;
|
|
|
|
vector<uint64_t> object_samples;
|
|
|
|
|
|
|
|
/* Tracks the total amounts every object/shader was hit.
|
|
|
|
* Used to evaluate relative cost, written by the render thread.
|
|
|
|
* Indexed by the shader and object IDs that the kernel also uses
|
|
|
|
* to index __object_flag and __shaders. */
|
|
|
|
vector<uint64_t> shader_hits;
|
|
|
|
vector<uint64_t> object_hits;
|
|
|
|
|
|
|
|
volatile bool do_stop_worker;
|
|
|
|
thread *worker;
|
|
|
|
|
|
|
|
thread_mutex mutex;
|
|
|
|
vector<ProfilingState *> states;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProfilingHelper {
|
|
|
|
public:
|
|
|
|
ProfilingHelper(ProfilingState *state, ProfilingEvent event) : state(state)
|
|
|
|
{
|
|
|
|
previous_event = state->event;
|
|
|
|
state->event = event;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
~ProfilingHelper()
|
|
|
|
{
|
|
|
|
state->event = previous_event;
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:06:30 +00:00
|
|
|
inline void set_event(ProfilingEvent event)
|
|
|
|
{
|
|
|
|
state->event = event;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
protected:
|
|
|
|
ProfilingState *state;
|
|
|
|
uint32_t previous_event;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProfilingWithShaderHelper : public ProfilingHelper {
|
|
|
|
public:
|
|
|
|
ProfilingWithShaderHelper(ProfilingState *state, ProfilingEvent event)
|
|
|
|
: ProfilingHelper(state, event)
|
2018-11-29 01:06:30 +00:00
|
|
|
{
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
~ProfilingWithShaderHelper()
|
2018-11-29 01:06:30 +00:00
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
state->object = -1;
|
|
|
|
state->shader = -1;
|
2018-11-29 01:06:30 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
inline void set_shader(int object, int shader)
|
2018-11-29 01:06:30 +00:00
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
if (state->active) {
|
|
|
|
state->shader = shader;
|
|
|
|
state->object = object;
|
|
|
|
|
|
|
|
if (shader >= 0) {
|
|
|
|
assert(shader < state->shader_hits.size());
|
|
|
|
state->shader_hits[shader]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object >= 0) {
|
|
|
|
assert(object < state->object_hits.size());
|
|
|
|
state->object_hits[object]++;
|
|
|
|
}
|
|
|
|
}
|
2018-11-29 01:06:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __UTIL_PROFILING_H__ */
|