From 7fa6f72084b1364cddfbef4f06bbb244210d6967 Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Thu, 29 Nov 2018 02:06:30 +0100 Subject: Cycles: Add sample-based runtime profiler that measures time spent in various parts of the CPU kernel This commit adds a sample-based profiler that runs during CPU rendering and collects statistics on time spent in different parts of the kernel (ray intersection, shader evaluation etc.) as well as time spent per material and object. The results are currently not exposed in the user interface or per Python yet, to see the stats on the console pass the "--cycles-print-stats" argument to Cycles (e.g. "./blender -- --cycles-print-stats"). Unfortunately, there is no clear way to extend this functionality to CUDA or OpenCL, so it is CPU-only for now. Reviewers: brecht, sergey, swerner Reviewed By: brecht, swerner Differential Revision: https://developer.blender.org/D3892 --- intern/cycles/device/device_cpu.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'intern/cycles/device/device_cpu.cpp') diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 36fe9bfc92b..f0a6fd6e3f4 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -477,6 +477,8 @@ public: bool denoising_non_local_means(device_ptr image_ptr, device_ptr guide_ptr, device_ptr variance_ptr, device_ptr out_ptr, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_NON_LOCAL_MEANS); + int4 rect = task->rect; int r = task->nlm_state.r; int f = task->nlm_state.f; @@ -529,6 +531,8 @@ public: bool denoising_construct_transform(DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_CONSTRUCT_TRANSFORM); + for(int y = 0; y < task->filter_area.w; y++) { for(int x = 0; x < task->filter_area.z; x++) { filter_construct_transform_kernel()((float*) task->buffer.mem.device_pointer, @@ -551,6 +555,8 @@ public: device_ptr output_ptr, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_RECONSTRUCT); + mem_zero(task->storage.XtWX); mem_zero(task->storage.XtWY); @@ -609,8 +615,10 @@ public: bool denoising_combine_halves(device_ptr a_ptr, device_ptr b_ptr, device_ptr mean_ptr, device_ptr variance_ptr, - int r, int4 rect, DenoisingTask * /*task*/) + int r, int4 rect, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_COMBINE_HALVES); + for(int y = rect.y; y < rect.w; y++) { for(int x = rect.x; x < rect.z; x++) { filter_combine_halves_kernel()(x, y, @@ -629,6 +637,8 @@ public: device_ptr sample_variance_ptr, device_ptr sv_variance_ptr, device_ptr buffer_variance_ptr, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_DIVIDE_SHADOW); + for(int y = task->rect.y; y < task->rect.w; y++) { for(int x = task->rect.x; x < task->rect.z; x++) { filter_divide_shadow_kernel()(task->render_buffer.samples, @@ -653,6 +663,8 @@ public: device_ptr variance_ptr, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_GET_FEATURE); + for(int y = task->rect.y; y < task->rect.w; y++) { for(int x = task->rect.x; x < task->rect.z; x++) { filter_get_feature_kernel()(task->render_buffer.samples, @@ -676,6 +688,8 @@ public: device_ptr output_ptr, DenoisingTask *task) { + ProfilingHelper profiling(task->profiler, PROFILING_DENOISING_DETECT_OUTLIERS); + for(int y = task->rect.y; y < task->rect.w; y++) { for(int x = task->rect.x; x < task->rect.z; x++) { filter_detect_outliers_kernel()(x, y, @@ -735,6 +749,8 @@ public: void denoise(DenoisingTask& denoising, RenderTile &tile) { + ProfilingHelper profiling(denoising.profiler, PROFILING_DENOISING); + tile.sample = tile.start_sample + tile.num_samples; denoising.functions.construct_transform = function_bind(&CPUDevice::denoising_construct_transform, this, &denoising); @@ -765,6 +781,8 @@ public: KernelGlobals *kg = new ((void*) kgbuffer.device_pointer) KernelGlobals(thread_kernel_globals_init()); + stats.profiler.add_state(&kg->profiler); + CPUSplitKernel *split_kernel = NULL; if(use_split_kernel) { split_kernel = new CPUSplitKernel(this); @@ -778,6 +796,7 @@ public: RenderTile tile; DenoisingTask denoising(this, task); + denoising.profiler = &kg->profiler; while(task.acquire_tile(this, tile)) { if(tile.task == RenderTile::PATH_TRACE) { @@ -802,6 +821,8 @@ public: } } + stats.profiler.remove_state(&kg->profiler); + thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer); kg->~KernelGlobals(); kgbuffer.free(); @@ -1061,6 +1082,7 @@ void device_cpu_info(vector& devices) info.has_volume_decoupled = true; info.has_osl = true; info.has_half_images = true; + info.has_profiling = true; devices.insert(devices.begin(), info); } -- cgit v1.2.3