Blender V5.3
intern/engine.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstddef>
10#include <cstdlib>
11#include <cstring>
12
13#include "BKE_compositor.hh"
14#include "MEM_guardedalloc.h"
15
16#include "BLI_listbase.hh"
17#include "BLI_math_bits.hh"
18#include "BLI_string.hh"
19#include "BLI_utildefines.hh"
20
21#include "DNA_layer_types.h"
22#include "DNA_object_types.h"
23
24#include "BKE_camera.h"
25#include "BKE_compositor.hh"
26#include "BKE_global.hh"
27#include "BKE_node.hh"
28#include "BKE_report.hh"
29#include "BKE_scene.hh"
30
31#include "DEG_depsgraph.hh"
34
35#include "GPU_context.hh"
36
37#ifdef WITH_PYTHON
38# include "BPY_extern.hh"
39#endif
40
41#include "IMB_imbuf_types.hh"
42
43#include "RE_bake.h"
44#include "RE_engine.h"
45#include "RE_pipeline.h"
46
47#include "DRW_engine.hh"
48
49#include "WM_api.hh"
50
51#include "CLG_log.h"
52
53#include "pipeline.hh"
54#include "render_result.h"
55#include "render_types.h"
56
57namespace blender {
58
59/* Render Engine Types */
60
61ListBaseT<RenderEngineType> R_engines = {nullptr, nullptr};
62
63static CLG_LogRef LOG = {"render"};
64
70
72{
73 RenderEngineType *type, *next;
74
76 /* Clean resources if the DRW context exists.
77 * We need a context bound even when dealing with non context dependent GPU resources,
78 * since GL functions may be null otherwise (See #141233). */
82 }
83
84 for (type = R_engines.first(); type; type = next) {
85 next = type->next;
86
87 BLI_remlink(&R_engines, type);
88
89 if (!(type->flag & RE_INTERNAL)) {
90 if (type->rna_ext.free) {
91 type->rna_ext.free(type->rna_ext.data);
92 }
93
94 MEM_delete(type);
95 }
96 }
97}
98
100{
101 BLI_addtail(&R_engines, render_type);
102}
103
105{
106 RenderEngineType *type = static_cast<RenderEngineType *>(
108 if (!type) {
109 type = static_cast<RenderEngineType *>(
110 BLI_findstring(&R_engines, "BLENDER_EEVEE", offsetof(RenderEngineType, idname)));
111 }
112
113 return type;
114}
115
116bool RE_engines_is_registered(const char *idname)
117{
118 return BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname)) != nullptr;
119}
120
122{
123 return (re->engine && re->engine->type && re->engine->type->render);
124}
125
126/* Create, Free */
127
129{
130 RenderEngine *engine = MEM_new_zeroed<RenderEngine>("RenderEngine");
131 engine->type = type;
132
135
136 return engine;
137}
138
140{
141 if (engine->depsgraph) {
142 /* Need GPU context since this might free GPU buffers. */
143 const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT);
144 if (use_gpu_context) {
145 /* This function can be called on the main thread before RenderEngine is destroyed.
146 * In this case, just bind the main draw context to gather the deleted GPU buffers.
147 * Binding the same GPU context as the render engine is not needed (see #129019). */
148 if (BLI_thread_is_main()) {
150 }
151 else {
153 }
154 }
155
156 DEG_graph_free(engine->depsgraph);
157 engine->depsgraph = nullptr;
158
159 if (use_gpu_context) {
160 if (BLI_thread_is_main()) {
162 }
163 else {
165 }
166 }
167 }
168}
169
171{
172#ifdef WITH_PYTHON
173 if (engine->py_instance) {
175 }
176#endif
177
178 engine_depsgraph_free(engine);
179
182
183 MEM_delete(engine);
184}
185
186/* Bake Render Results */
187
189 RenderEngine *engine, int x, int y, int w, int h, const char *layername)
190{
191 BakeImage *image = &engine->bake.targets->images[engine->bake.image_id];
192 const BakePixel *pixels = engine->bake.pixels + image->offset;
193 const size_t channels_num = engine->bake.targets->channels_num;
194
195 /* Remember layer name for to match images in render_frame_finish. */
196 if (image->render_layer_name[0] == '\0') {
197 STRNCPY(image->render_layer_name, layername);
198 }
199
200 /* Create render result with specified size. */
201 RenderResult *rr = MEM_new<RenderResult>(__func__);
202
203 rr->rectx = w;
204 rr->recty = h;
205 rr->tilerect.xmin = x;
206 rr->tilerect.ymin = y;
207 rr->tilerect.xmax = x + w;
208 rr->tilerect.ymax = y + h;
209
210 BKE_scene_ppm_get(&engine->re->r, rr->ppm);
211
212 /* Add single baking render layer. */
213 RenderLayer *rl = MEM_new<RenderLayer>("bake render layer");
214 STRNCPY(rl->name, layername);
215 rl->rectx = w;
216 rl->recty = h;
217 BLI_addtail(&rr->layers, rl);
218
219 /* Add render passes. */
220 render_layer_add_pass(rr, rl, channels_num, RE_PASSNAME_COMBINED, "", "RGBA", true);
221
222 RenderPass *primitive_pass = render_layer_add_pass(rr, rl, 3, "BakePrimitive", "", "RGB", true);
223 RenderPass *differential_pass = render_layer_add_pass(
224 rr, rl, 4, "BakeDifferential", "", "RGBA", true);
225
226 /* Per-pixel seeds are only needed for baking to vertex colors, see
227 * bake_targets_populate_pixels_color_attributes for more details. */
228 RenderPass *seed_pass = (image->image == nullptr) ?
229 render_layer_add_pass(rr, rl, 1, "BakeSeed", "", "X", true) :
230 nullptr;
231
232 /* Fill render passes from bake pixel array, to be read by the render engine. */
233 for (int ty = 0; ty < h; ty++) {
234 size_t offset = ty * w;
235 float *primitive = primitive_pass->ibuf->float_data_for_write() + 3 * offset;
236 float *seed = (seed_pass != nullptr) ? (seed_pass->ibuf->float_data_for_write() + offset) :
237 nullptr;
238 float *differential = differential_pass->ibuf->float_data_for_write() + 4 * offset;
239
240 size_t bake_offset = (y + ty) * image->width + x;
241 const BakePixel *bake_pixel = pixels + bake_offset;
242
243 for (int tx = 0; tx < w; tx++) {
244 if (bake_pixel->object_id != engine->bake.object_id) {
245 primitive[0] = int_as_float(-1);
246 primitive[1] = int_as_float(-1);
247 primitive[2] = int_as_float(-1);
248 }
249 else {
250 primitive[0] = bake_pixel->uv[0];
251 primitive[1] = bake_pixel->uv[1];
252 primitive[2] = int_as_float(bake_pixel->primitive_id);
253
254 differential[0] = bake_pixel->du_dx;
255 differential[1] = bake_pixel->du_dy;
256 differential[2] = bake_pixel->dv_dx;
257 differential[3] = bake_pixel->dv_dy;
258 }
259
260 if (seed_pass != nullptr) {
261 *seed = int_as_float(bake_pixel->seed);
262 seed += 1;
263 }
264
265 primitive += 3;
266 differential += 4;
267 bake_pixel++;
268 }
269 }
270
271 return rr;
272}
273
275{
276 RenderLayer *rl = rr->layers.first();
278 if (!rpass) {
279 return;
280 }
281
282 /* Find bake image corresponding to layer. */
283 int image_id = 0;
284 for (; image_id < engine->bake.targets->images_num; image_id++) {
285 if (STREQ(engine->bake.targets->images[image_id].render_layer_name, rl->name)) {
286 break;
287 }
288 }
289 if (image_id == engine->bake.targets->images_num) {
290 return;
291 }
292
293 const BakeImage *image = &engine->bake.targets->images[image_id];
294 const BakePixel *pixels = engine->bake.pixels + image->offset;
295 const size_t channels_num = engine->bake.targets->channels_num;
296 const size_t channels_size = channels_num * sizeof(float);
297 float *result = engine->bake.result + image->offset * channels_num;
298
299 /* Copy from tile render result to full image bake result. Just the pixels for the
300 * object currently being baked, to preserve other objects when baking multiple. */
301 const int x = rr->tilerect.xmin;
302 const int y = rr->tilerect.ymin;
303 const int w = rr->tilerect.xmax - rr->tilerect.xmin;
304 const int h = rr->tilerect.ymax - rr->tilerect.ymin;
305
306 for (int ty = 0; ty < h; ty++) {
307 const size_t offset = ty * w;
308 const size_t bake_offset = (y + ty) * image->width + x;
309
310 const float *pass_rect = rpass->ibuf->float_data() + offset * channels_num;
311 const BakePixel *bake_pixel = pixels + bake_offset;
312 float *bake_result = result + bake_offset * channels_num;
313
314 for (int tx = 0; tx < w; tx++) {
315 if (bake_pixel->object_id == engine->bake.object_id && bake_pixel->primitive_id != -1 &&
316 !bake_pixel->is_margin)
317 {
318 memcpy(bake_result, pass_rect, channels_size);
319 }
320 pass_rect += channels_num;
321 bake_result += channels_num;
322 bake_pixel++;
323 }
324 }
325}
326
327/* Render Results */
328
330 RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname)
331{
332 if (engine->bake.targets) {
333 RenderResult *result = render_result_from_bake(engine, x, y, w, h, layername);
334 BLI_addtail(&engine->fullresult, result);
335 return result;
336 }
337
338 Render *re = engine->re;
340 rcti disprect;
341
342 /* ensure the coordinates are within the right limits */
343 CLAMP(x, 0, re->result->rectx);
344 CLAMP(y, 0, re->result->recty);
345 CLAMP(w, 0, re->result->rectx);
346 CLAMP(h, 0, re->result->recty);
347
348 if (x + w > re->result->rectx) {
349 w = re->result->rectx - x;
350 }
351 if (y + h > re->result->recty) {
352 h = re->result->recty - y;
353 }
354
355 /* allocate a render result */
356 disprect.xmin = x;
357 disprect.xmax = x + w;
358 disprect.ymin = y;
359 disprect.ymax = y + h;
360
361 result = render_result_new(re, &disprect, layername, viewname);
362
363 /* TODO: make this thread safe. */
364
365 /* can be nullptr if we CLAMP the width or height to 0 */
366 if (result) {
367 render_result_clone_passes(re, result, viewname);
369
370 BLI_addtail(&engine->fullresult, result);
371
372 result->tilerect.xmin += re->disprect.xmin;
373 result->tilerect.xmax += re->disprect.xmin;
374 result->tilerect.ymin += re->disprect.ymin;
375 result->tilerect.ymax += re->disprect.ymin;
376 }
377
378 return result;
379}
380
391
393{
394 if (engine->bake.targets) {
395 /* No interactive baking updates for now. */
396 return;
397 }
398
399 Render *re = engine->re;
400
401 if (result) {
404 result->renlay = static_cast<RenderLayer *>(
405 result->layers.first()); /* weak, draws first layer always */
406 re->display->display_update(result);
407 }
408}
409
411 const char *name,
412 int channels,
413 const char *chan_id,
414 const char *layername)
415{
416 Render *re = engine->re;
417
418 if (!re || !re->result) {
419 return;
420 }
421
422 RE_create_render_pass(re->result, name, channels, chan_id, layername, nullptr, false);
423}
424
426 RenderEngine *engine, RenderResult *result, bool cancel, bool highlight, bool merge_results)
427{
428 Render *re = engine->re;
429
430 if (!result) {
431 return;
432 }
433
434 if (engine->bake.targets) {
435 if (!cancel || merge_results) {
437 }
438 BLI_remlink(&engine->fullresult, result);
440 return;
441 }
442
443 if (re->engine && (re->engine->flag & RE_ENGINE_HIGHLIGHT_TILES)) {
444 render::TilesHighlight *tile_highlight = re->get_tile_highlight();
445
446 if (tile_highlight) {
447 if (highlight) {
448 tile_highlight->highlight_tile_for_result(result);
449 }
450 else {
451 tile_highlight->unhighlight_tile_for_result(result);
452 }
453 }
454 }
455
456 if (!cancel || merge_results) {
457 if (!(re->display->test_break() && (re->r.scemode & R_BUTS_PREVIEW))) {
460 }
461
462 /* draw */
463 if (!re->display->test_break()) {
464 result->renlay = static_cast<RenderLayer *>(
465 result->layers.first()); /* weak, draws first layer always */
466 re->display->display_update(result);
467 }
468 }
469
470 /* free */
471 BLI_remlink(&engine->fullresult, result);
473}
474
476{
477 return engine->re->result;
478}
479
480/* Cancel */
481
483{
484 Render *re = engine->re;
485
486 if (re) {
487 return re->display->test_break();
488 }
489
490 return false;
491}
492
493/* Statistics */
494
495void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
496{
497 Render *re = engine->re;
498
499 /* stats draw callback */
500 if (re) {
501 re->i.statstr = stats;
502 re->i.infostr = info;
503 re->display->stats_draw(&re->i);
504 re->i.infostr = nullptr;
505 re->i.statstr = nullptr;
506 }
507
508 /* set engine text */
509 engine->text[0] = '\0';
510
511 if (stats && stats[0] && info && info[0]) {
512 SNPRINTF(engine->text, "%s | %s", stats, info);
513 }
514 else if (info && info[0]) {
515 STRNCPY(engine->text, info);
516 }
517 else if (stats && stats[0]) {
518 STRNCPY(engine->text, stats);
519 }
520}
521
522void RE_engine_update_progress(RenderEngine *engine, float progress)
523{
524 Render *re = engine->re;
525
526 if (re && !re->display_shared) {
527 CLAMP(progress, 0.0f, 1.0f);
528 re->display->progress(progress);
529 }
530}
531
532void RE_engine_update_memory_stats(RenderEngine *engine, float mem_used, float mem_peak)
533{
534 Render *re = engine->re;
535
536 if (re) {
537 re->i.mem_used = int(ceilf(mem_used));
538 re->i.mem_peak = int(ceilf(mem_peak));
539 }
540}
541
542void RE_engine_report(RenderEngine *engine, int type, const char *msg)
543{
544 Render *re = engine->re;
545
546 if (re) {
547 BKE_report(engine->re->reports, eReportType(type), msg);
548 }
549 else if (engine->reports) {
550 BKE_report(engine->reports, eReportType(type), msg);
551 }
552}
553
554void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
555{
556 Render *re = engine->re;
557 if (re != nullptr) {
559 if (rr) {
560 if (rr->error != nullptr) {
561 MEM_delete(rr->error);
562 }
563 rr->error = BLI_strdup(msg);
564 }
566 }
567}
568
569RenderPass *RE_engine_pass_by_index_get(RenderEngine *engine, const char *layer_name, int index)
570{
571 Render *re = engine->re;
572 if (re == nullptr) {
573 return nullptr;
574 }
575
576 RenderPass *pass = nullptr;
577
579 if (rr != nullptr) {
580 const RenderLayer *layer = RE_GetRenderLayer(rr, layer_name);
581 if (layer != nullptr) {
582 pass = static_cast<RenderPass *>(BLI_findlink(&layer->passes, index));
583 }
584 }
586
587 return pass;
588}
589
591{
592 Render *re = engine->re;
593 return RE_GetActiveRenderView(re);
594}
595
596void RE_engine_active_view_set(RenderEngine *engine, const char *viewname)
597{
598 Render *re = engine->re;
599 RE_SetActiveRenderView(re, viewname);
600}
601
602float RE_engine_get_camera_shift_x(RenderEngine *engine, Object *camera, bool use_spherical_stereo)
603{
604 /* When using spherical stereo, get camera shift without multiview,
605 * leaving stereo to be handled by the engine. */
606 Render *re = engine->re;
607 if (use_spherical_stereo || re == nullptr) {
608 return BKE_camera_multiview_shift_x(nullptr, camera, nullptr);
609 }
610
612}
613
615 Object *camera,
616 bool use_spherical_stereo,
617 float r_modelmat[16])
618{
619 /* When using spherical stereo, get model matrix without multiview,
620 * leaving stereo to be handled by the engine. */
621 Render *re = engine->re;
622 if (use_spherical_stereo || re == nullptr) {
624 nullptr, camera, nullptr, reinterpret_cast<float (*)[4]>(r_modelmat));
625 }
626 else {
628 &re->r, camera, re->viewname, reinterpret_cast<float (*)[4]>(r_modelmat));
629 }
630}
631
633{
634 Render *re = engine->re;
635 return BKE_camera_multiview_spherical_stereo(re ? &re->r : nullptr, camera) ? true : false;
636}
637
638const rcti *RE_engine_get_current_tiles(Render *re, int *r_total_tiles)
639{
640 render::TilesHighlight *tiles_highlight = re->get_tile_highlight();
641 if (!tiles_highlight) {
642 *r_total_tiles = 0;
643 return nullptr;
644 };
645
646 Span<rcti> highlighted_tiles = tiles_highlight->get_all_highlighted_tiles();
647
648 *r_total_tiles = highlighted_tiles.size();
649 return highlighted_tiles.data();
650}
651
653{
654 return &re->r;
655}
656
658{
659 /* Re-rendering is not supported with GPU contexts, since the GPU context
660 * is destroyed when the render thread exists. */
661 return (engine->re->r.mode & R_PERSISTENT_DATA) && !(engine->type->flag & RE_USE_GPU_CONTEXT);
662}
663
665{
666 /* For persistent data or GPU engines like Eevee, reuse the depsgraph between
667 * view layers and animation frames. For renderers like Cycles that create
668 * their own copy of the scene, persistent data must be explicitly enabled to
669 * keep memory usage low by default. */
670 return (engine->re->r.mode & R_PERSISTENT_DATA) || (engine->type->flag & RE_USE_GPU_CONTEXT);
671}
672
673/* Depsgraph */
674static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
675{
676 Main *bmain = engine->re->main;
677 Scene *scene = engine->re->scene;
678 bool reuse_depsgraph = false;
679
680 /* Reuse depsgraph from persistent data if possible. */
681 if (engine->depsgraph) {
682 if (DEG_get_bmain(engine->depsgraph) != bmain ||
683 DEG_get_input_scene(engine->depsgraph) != scene)
684 {
685 /* If bmain or scene changes, we need a completely new graph. */
686 engine_depsgraph_free(engine);
687 }
688 else if (DEG_get_input_view_layer(engine->depsgraph) != view_layer) {
689 /* If only view layer changed, reuse depsgraph in the hope of reusing
690 * objects shared between view layers. */
691 DEG_graph_replace_owners(engine->depsgraph, bmain, scene, view_layer);
693 }
694
695 reuse_depsgraph = true;
696 }
697
698 if (!engine->depsgraph) {
699 /* Ensure we only use persistent data for one scene / view layer at a time,
700 * to avoid excessive memory usage. */
701 RE_FreePersistentData(nullptr);
702
703 /* Create new depsgraph if not cached with persistent data. */
704 engine->depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
705 DEG_debug_name_set(engine->depsgraph, "RENDER");
706 }
707
708 if (engine->re->r.scemode & R_BUTS_PREVIEW) {
709 /* Update for preview render. */
710 Depsgraph *depsgraph = engine->depsgraph;
712
713 /* Need GPU context since this might free GPU buffers. */
714 const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT) && reuse_depsgraph;
715 if (use_gpu_context) {
717 }
718
720
721 if (use_gpu_context) {
723 }
724 }
725 else {
726 /* Go through update with full Python callbacks for regular render. */
728 }
729
731}
732
734{
735 if (engine->depsgraph) {
736 if (engine_keep_depsgraph(engine)) {
737 /* Clear recalc flags since the engine should have handled the updates for the currently
738 * rendered framed by now. */
739 DEG_ids_clear_recalc(engine->depsgraph, false);
740 }
741 else {
742 /* Free immediately to save memory. */
743 engine_depsgraph_free(engine);
744 }
745 }
746}
747
748void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
749{
750 if (!engine->depsgraph) {
751 return;
752 }
753
754 /* Clear recalc flags before update so engine can detect what changed. */
755 DEG_ids_clear_recalc(engine->depsgraph, false);
756
757 Render *re = engine->re;
758 double cfra = double(frame) + double(subframe);
759
760 CLAMP(cfra, MINAFRAME, MAXFRAME);
761 BKE_scene_frame_set(re->scene, cfra);
763
765}
766
767/* Bake */
768
770{
771 re->scene = scene;
772 re->main = bmain;
773 render_copy_renderdata(&re->r, &scene->r);
774}
775
777{
778 const RenderEngineType *type = RE_engines_find(re->r.engine);
779 return (type->bake != nullptr);
780}
781
783 Depsgraph *depsgraph,
784 Object *object,
785 const int object_id,
786 const BakePixel pixel_array[],
787 const BakeTargets *targets,
788 const eScenePassType pass_type,
789 const int pass_filter,
790 float result[])
791{
793 RenderEngine *engine;
794
795 /* set render info */
796 re->i.cfra = re->scene->r.cfra;
797 STRNCPY(re->i.scene_name, re->scene->id.name + 2);
798
799 /* render */
800 engine = re->engine;
801
802 if (!engine) {
803 engine = RE_engine_create(type);
804 re->engine = engine;
805 }
806
807 engine->flag |= RE_ENGINE_RENDERING;
808
809 /* TODO: actually link to a parent which shouldn't happen */
810 engine->re = re;
811
812 engine->resolution_x = re->winx;
813 engine->resolution_y = re->winy;
814
815 if (type->bake) {
816 engine->depsgraph = depsgraph;
817
818 /* update is only called so we create the engine.session */
819 if (type->update) {
820 type->update(engine, re->main, engine->depsgraph);
821 }
822
823 /* Bake all images. */
824 engine->bake.targets = targets;
825 engine->bake.pixels = pixel_array;
826 engine->bake.result = result;
827 engine->bake.object_id = object_id;
828
829 for (int i = 0; i < targets->images_num; i++) {
830 const BakeImage *image = &targets->images[i];
831 engine->bake.image_id = i;
832
833 type->bake(
834 engine, engine->depsgraph, object, pass_type, pass_filter, image->width, image->height);
835 }
836
837 /* Optionally let render images read bake images from disk delayed. */
838 if (type->render_frame_finish) {
839 engine->bake.image_id = 0;
840 type->render_frame_finish(engine);
841 }
842
843 memset(&engine->bake, 0, sizeof(engine->bake));
844
845 engine->depsgraph = nullptr;
846 }
847
848 engine->flag &= ~RE_ENGINE_RENDERING;
849
850 engine_depsgraph_free(engine);
851
852 RE_engine_free(engine);
853 re->engine = nullptr;
854
855 return true;
856}
857
858/* Render */
859
861{
863 return false;
864 }
865
866 /* Note a secondary Render instance from a Render Layers node has a null pipeline scene,
867 * but no compositing is performed for it so we can return false. */
868 const Scene *scene = re->pipeline_scene_eval;
869 if (!scene) {
870 return false;
871 }
872
874}
875
877 RenderEngine *engine,
878 ViewLayer *view_layer_iter,
879 const bool use_engine,
880 const bool use_grease_pencil)
881{
882 /* Lock UI so scene can't be edited while we read from it in this render thread. */
883 re->display->draw_lock();
884
885 /* Create depsgraph with scene evaluated at render resolution. */
886 ViewLayer *view_layer = static_cast<ViewLayer *>(
887 BLI_findstring(&re->scene->view_layers, view_layer_iter->name, offsetof(ViewLayer, name)));
888 if (!re->prepare_viewlayer(view_layer, engine->depsgraph)) {
889 re->display->draw_unlock();
890 return;
891 }
892 engine_depsgraph_init(engine, view_layer);
893
894 /* Sync data to engine, within draw lock so scene data can be accessed safely. */
895 if (use_engine) {
896 const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT);
897 if (use_gpu_context) {
899 }
900 else if (G.background && ((engine->has_grease_pencil && use_grease_pencil) ||
902 {
903 /* Workaround for specific NVidia drivers which crash on Linux when OptiX context is
904 * initialized prior to OpenGL context. This affects driver versions 545.29.06, 550.54.14,
905 * and 550.67 running on kernel 6.8.
906 *
907 * The idea here is to initialize GPU context before giving control to the render engine in
908 * cases when we know that the GPU context will definitely be needed later on.
909 *
910 * Only do it for background renders to avoid possible extra global locking during the
911 * context initialization. For the non-background renders the GPU context is already
912 * initialized for the Blender interface and no workaround is needed.
913 *
914 * Technically it is enough to only call WM_init_gpu_offscreen() here, but it expects
915 * to only be called once, and from here it is not possible to know whether GPU
916 * sub-system is initialized or not. So instead temporarily enable the render context,
917 * which will take care of the GPU context initialization.
918 *
919 * For demo file and tracking progress of possible fixes on driver side refer to #120007. */
922 }
923
924 if (engine->type->update) {
925 engine->type->update(engine, re->main, engine->depsgraph);
926 }
927 if (use_gpu_context) {
929 }
930 }
931
932 re->display->draw_unlock();
933
934 /* Perform render with engine. */
935 if (use_engine) {
936 const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT);
937 if (use_gpu_context) {
939 }
940
944
945 engine->type->render(engine, engine->depsgraph);
946
950
951 if (use_gpu_context) {
953 }
954 }
955
956 /* Optionally composite grease pencil over render result.
957 * Only do it if the passes are allocated (and the engine will not override the grease pencil
958 * when reading its result from EXR file and writing to the Blender side). */
959 if (engine->has_grease_pencil && use_grease_pencil && re->result->passes_allocated) {
960 /* NOTE: External engine might have been requested to free its
961 * dependency graph, which is only allowed if there is no grease
962 * pencil (pipeline is taking care of that). */
963 if (!RE_engine_test_break(engine) && engine->depsgraph != nullptr) {
964 CLOG_INFO(&LOG, "Rendering grease pencil");
965 DRW_render_gpencil(engine, engine->depsgraph);
966 }
967 }
968
969 /* Free dependency graph, if engine has not done it already. */
970 engine_depsgraph_exit(engine);
971}
972
973/* Callback function for engine_render_create_result to add all render passes to the result. */
974static void engine_render_add_result_pass_cb(void *user_data,
975 Scene * /*scene*/,
976 ViewLayer *view_layer,
977 const char *name,
978 int channels,
979 const char *chanid,
980 eNodeSocketDatatype /*type*/)
981{
982 RenderResult *rr = static_cast<RenderResult *>(user_data);
983 RE_create_render_pass(rr, name, channels, chanid, view_layer->name, RR_ALL_VIEWS, false);
984}
985
987{
989 if (rr == nullptr) {
990 return nullptr;
991 }
992
993 FOREACH_VIEW_LAYER_TO_RENDER_BEGIN (re, view_layer) {
995 re->engine, re->scene, view_layer, engine_render_add_result_pass_cb, rr);
996 }
998
999 /* Preview does not support deferred render result allocation. */
1000 if (re->r.scemode & R_BUTS_PREVIEW) {
1002 }
1003
1004 return rr;
1005}
1006
1007bool RE_engine_render(Render *re, bool do_all)
1008{
1010
1011 /* verify if we can render */
1012 if (!type->render) {
1013 return false;
1014 }
1015 if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW)) {
1016 return false;
1017 }
1018 if (do_all && !(type->flag & RE_USE_POSTPROCESS)) {
1019 return false;
1020 }
1021 if (!do_all && (type->flag & RE_USE_POSTPROCESS)) {
1022 return false;
1023 }
1024
1025 /* Lock drawing in UI during data phase. */
1026 re->display->draw_lock();
1027
1028 if (type->flag & RE_USE_GPU_CONTEXT) {
1030 if (!GPU_backend_supported()) {
1031 /* Clear UI drawing locks. */
1032 re->display->draw_unlock();
1033 BKE_report(re->reports, RPT_ERROR, "Cannot initialize the GPU");
1034 G.is_break = true;
1035 return true;
1036 }
1037 }
1038
1039 /* Create engine. */
1040 RenderEngine *engine = re->engine;
1041
1042 if (!engine) {
1043 engine = RE_engine_create(type);
1044 re->engine = engine;
1045 }
1046
1047 /* Create render result. Do this before acquiring lock, to avoid lock
1048 * inversion as this calls python to get the render passes, while python UI
1049 * code can also hold a lock on the render result. */
1050 const bool create_new_result = (re->result == nullptr || !(re->r.scemode & R_BUTS_PREVIEW));
1051 RenderResult *new_result = (create_new_result) ? engine_render_create_result(re) : nullptr;
1052
1054 if (create_new_result) {
1055 if (re->result) {
1057 }
1058
1059 re->result = new_result;
1060 }
1062
1063 if (re->result == nullptr) {
1064 /* Clear UI drawing locks. */
1065 re->display->draw_unlock();
1066 /* Free engine. */
1067 RE_engine_free(engine);
1068 re->engine = nullptr;
1069 /* Too small image is handled earlier, here it could only happen if
1070 * there was no sufficient memory to allocate all passes.
1071 */
1072 BKE_report(re->reports, RPT_ERROR, "Failed allocate render result, out of memory");
1073 G.is_break = true;
1074 return true;
1075 }
1076
1077 /* set render info */
1078 re->i.cfra = re->scene->r.cfra;
1079 STRNCPY(re->i.scene_name, re->scene->id.name + 2);
1080
1081 engine->flag |= RE_ENGINE_RENDERING;
1082
1083 /* TODO: actually link to a parent which shouldn't happen */
1084 engine->re = re;
1085
1086 if (re->flag & R_ANIMATION) {
1087 engine->flag |= RE_ENGINE_ANIMATION;
1088 }
1089 if (re->r.scemode & R_BUTS_PREVIEW) {
1090 engine->flag |= RE_ENGINE_PREVIEW;
1091 }
1092 engine->camera_override = re->camera_override;
1093
1094 engine->resolution_x = re->winx;
1095 engine->resolution_y = re->winy;
1096
1097 /* Clear UI drawing locks. */
1098 re->display->draw_unlock();
1099
1100 /* Render view layers. */
1101 bool delay_grease_pencil = false;
1102
1103 if (type->render) {
1104 FOREACH_VIEW_LAYER_TO_RENDER_BEGIN (re, view_layer_iter) {
1105 CLOG_INFO(&LOG, "Start rendering: %s, %s", re->scene->id.name + 2, view_layer_iter->name);
1106 CLOG_INFO(&LOG, "Engine: %s", engine->type->name);
1107 const bool use_grease_pencil = (view_layer_iter->layflag & SCE_LAY_GREASE_PENCIL) != 0;
1108 engine_render_view_layer(re, engine, view_layer_iter, true, use_grease_pencil);
1109
1110 /* If render passes are not allocated the render engine deferred final pixels write for
1111 * later. Need to defer the grease pencil for until after the engine has written the
1112 * render result to Blender. */
1113 delay_grease_pencil = use_grease_pencil && engine->has_grease_pencil &&
1115
1116 if (RE_engine_test_break(engine)) {
1117 break;
1118 }
1119 }
1121 }
1122
1123 if (type->render_frame_finish) {
1124 type->render_frame_finish(engine);
1125 }
1126
1127 /* Perform delayed grease pencil rendering. */
1128 if (delay_grease_pencil) {
1129 FOREACH_VIEW_LAYER_TO_RENDER_BEGIN (re, view_layer_iter) {
1130 const bool use_grease_pencil = (view_layer_iter->layflag & SCE_LAY_GREASE_PENCIL) != 0;
1131 if (!use_grease_pencil) {
1132 continue;
1133 }
1134 engine_render_view_layer(re, engine, view_layer_iter, false, true);
1135 if (RE_engine_test_break(engine)) {
1136 break;
1137 }
1138 }
1140 }
1141
1142 /* Clear tile data */
1143 engine->flag &= ~RE_ENGINE_RENDERING;
1144
1145 render_result_free_list(&engine->fullresult, engine->fullresult.first());
1146
1147 /* re->engine becomes zero if user changed active render engine during render */
1148 if (!engine_keep_depsgraph(engine) || !re->engine) {
1149 engine_depsgraph_free(engine);
1150
1151 RE_engine_free(engine);
1152 re->engine = nullptr;
1153 }
1154
1155 if (re->r.scemode & R_EXR_CACHE_FILE) {
1159 }
1160
1162 G.is_break = true;
1163 }
1164
1165#ifdef WITH_FREESTYLE
1166 if (re->r.mode & R_EDGE_FRS) {
1167 CLOG_INFO(&LOG, "Rendering freestyle");
1168 RE_RenderFreestyleExternal(re);
1169 }
1170#endif
1171
1172 return true;
1173}
1174
1176 Scene *scene,
1177 ViewLayer *view_layer,
1179 void *callback_data)
1180{
1181 if (!(scene && view_layer && engine && callback && engine->type->update_render_passes)) {
1182 return;
1183 }
1184
1186
1187 engine->update_render_passes_cb = callback;
1188 engine->update_render_passes_data = callback_data;
1189 engine->type->update_render_passes(engine, scene, view_layer);
1190 engine->update_render_passes_cb = nullptr;
1191 engine->update_render_passes_data = nullptr;
1192
1194}
1195
1197 Scene *scene,
1198 ViewLayer *view_layer,
1199 const char *name,
1200 int channels,
1201 const char *chanid,
1203{
1204 if (!(scene && view_layer && engine && engine->update_render_passes_cb)) {
1205 return;
1206 }
1207
1209 engine->update_render_passes_data, scene, view_layer, name, channels, chanid, type);
1210}
1211
1213{
1214 /* Weak way to save memory, but not crash grease pencil.
1215 *
1216 * TODO(sergey): Find better solution for this.
1217 */
1218 if (engine->has_grease_pencil || engine_keep_depsgraph(engine)) {
1219 return;
1220 }
1221 engine_depsgraph_free(engine);
1222}
1223
1225{
1226 return re->engine;
1227}
1228
1230{
1231 return view_render->engine;
1232}
1233
1235{
1236 RenderEngine *engine = re->engine;
1237
1238 if (!engine) {
1239 /* No engine-side drawing if the engine does not exist. */
1240 return false;
1241 }
1242
1243 if (!engine->type->draw) {
1244 /* Required callbacks are not implemented on the engine side. */
1245 return false;
1246 }
1247
1248 /* Lock before checking the flag, to avoid possible conflicts with the render thread. */
1250
1251 if ((engine->flag & RE_ENGINE_CAN_DRAW) == 0) {
1252 /* The rendering is not started yet, or has finished.
1253 *
1254 * In the former case there will nothing to be drawn, so can simply use RenderResult drawing
1255 * pipeline. In the latter case the engine has destroyed its display-only resources (textures,
1256 * graphics interops, etc..) so need to use the #RenderResult drawing pipeline. */
1258 return false;
1259 }
1260
1261 return true;
1262}
1263
1268
1270 RenderEngine *engine, int x, int y, int width, int height, bool highlight)
1271{
1272 if (!engine->re) {
1273 /* No render on the engine, so nowhere to store the highlighted tiles information. */
1274 return;
1275 }
1276 if ((engine->flag & RE_ENGINE_HIGHLIGHT_TILES) == 0) {
1277 /* Engine reported it does not support tiles highlight, but attempted to set the highlight.
1278 * Technically it is a logic error, but there is no good way to inform an external engine about
1279 * it. */
1280 return;
1281 }
1282
1283 render::TilesHighlight *tile_highlight = engine->re->get_tile_highlight();
1284 if (!tile_highlight) {
1285 /* The renderer itself does not support tiles highlight. */
1286 return;
1287 }
1288
1289 if (highlight) {
1290 tile_highlight->highlight_tile(x, y, width, height);
1291 }
1292 else {
1293 tile_highlight->unhighlight_tile(x, y, width, height);
1294 }
1295}
1296
1298{
1299 if (!engine->re) {
1300 /* No render on the engine, so nowhere to store the highlighted tiles information. */
1301 return;
1302 }
1303 if ((engine->flag & RE_ENGINE_HIGHLIGHT_TILES) == 0) {
1304 /* Engine reported it does not support tiles highlight, but attempted to set the highlight.
1305 * Technically it is a logic error, but there is no good way to inform an external engine about
1306 * it. */
1307 return;
1308 }
1309
1310 render::TilesHighlight *tile_highlight = engine->re->get_tile_highlight();
1311 if (!tile_highlight) {
1312 /* The renderer itself does not support tiles highlight. */
1313 return;
1314 }
1315
1316 tile_highlight->clear();
1317}
1318
1319/* -------------------------------------------------------------------- */
1327
1329{
1330 /* If there already is a draw manager render context available, reuse it. */
1331 engine->use_drw_render_context = (engine->re && RE_system_gpu_context_get(engine->re));
1332 if (engine->use_drw_render_context) {
1333 return true;
1334 }
1335
1336 /* Viewport render case where no render context is available. We are expected to be on
1337 * the main thread here to safely create a context. */
1339
1340 const bool drw_state = DRW_gpu_context_release();
1342
1343 if (engine->system_gpu_context) {
1344 /* Activate new GPU Context for GPUContext creation. */
1346 /* Requires GPUContext for usage of GPU Module for displaying results. */
1347 engine->blender_gpu_context = GPU_context_create(nullptr, engine->system_gpu_context);
1348 GPU_context_active_set(nullptr);
1349 /* Deactivate newly created GPU Context, as it is not needed until
1350 * `RE_engine_gpu_context_enable` is called. */
1352 }
1353 else {
1354 engine->blender_gpu_context = nullptr;
1355 }
1356
1357 DRW_gpu_context_activate(drw_state);
1358
1359 return engine->system_gpu_context != nullptr;
1360}
1361
1363{
1364 if (!engine->system_gpu_context) {
1365 return;
1366 }
1367
1368 const bool drw_state = DRW_gpu_context_release();
1369
1371 if (engine->blender_gpu_context) {
1372 GPUContext *restore_context = GPU_context_active_get();
1375 if (restore_context != engine->blender_gpu_context) {
1376 GPU_context_active_set(restore_context);
1377 }
1378 engine->blender_gpu_context = nullptr;
1379 }
1381 engine->system_gpu_context = nullptr;
1382
1383 DRW_gpu_context_activate(drw_state);
1384}
1385
1387{
1388 engine->gpu_restore_context = false;
1389 if (engine->use_drw_render_context) {
1391 return true;
1392 }
1393 if (engine->system_gpu_context) {
1395 /* If a previous GPU/GPUContext was active (DST.blender_gpu_context), we should later
1396 * restore this when disabling the RenderEngine context. */
1398
1399 /* Activate RenderEngine System and Blender GPU Context. */
1401 if (engine->blender_gpu_context) {
1404 }
1405 return true;
1406 }
1407 return false;
1408}
1409
1411{
1412 if (engine->use_drw_render_context) {
1414 }
1415 else {
1416 if (engine->system_gpu_context) {
1417 if (engine->blender_gpu_context) {
1418 GPU_context_active_set(nullptr);
1420 }
1422 /* Restore DRW state context if previously active. */
1425 }
1426 }
1427}
1428
1430{
1431 if (engine->use_drw_render_context) {
1432 /* Locking already handled by the draw manager. */
1433 }
1434 else {
1435 if (engine->system_gpu_context) {
1437 }
1438 }
1439}
1440
1442{
1443 if (engine->use_drw_render_context) {
1444 /* Locking already handled by the draw manager. */
1445 }
1446 else {
1447 if (engine->system_gpu_context) {
1449 }
1450 }
1451}
1452
1453void RE_engine_view_pause_set(RenderEngine *engine, const bool pause)
1454{
1456}
1457
1459{
1460 return (engine->flag & RE_ENGINE_VIEW_PAUSED) != 0;
1461}
1462
1463void RE_engine_view_auto_pause_set(RenderEngine *engine, const bool pause)
1464{
1466}
1467
1469{
1470 const bool is_paused = (engine->flag & (RE_ENGINE_VIEW_PAUSED | RE_ENGINE_VIEW_PAUSED_AUTO)) !=
1471 0;
1472 const bool was_paused = (engine->flag & RE_ENGINE_VIEW_PAUSED_NOTIFIED) != 0;
1473
1474 if (is_paused == was_paused) {
1475 return false;
1476 }
1477
1479
1480 if (is_paused) {
1481 if (engine->type->view_pause) {
1482 engine->type->view_pause(engine, context);
1483 }
1484 }
1485 else {
1486 if (engine->type->view_resume) {
1487 engine->type->view_resume(engine, context);
1488 }
1489 }
1490
1491 return true;
1492}
1493
1495
1496} // namespace blender
Camera data-block and utility functions.
#define SNPRINTF(dst, format,...)
#define THREAD_LOCK_WRITE
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
Object is a sort of wrapper for general info.
#define RE_PASSNAME_COMBINED
#define MINAFRAME
#define MAXFRAME
Read Blender memory allocation and freeing.
#define CLAMP(a, b, c)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define STREQ(a, b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t size() const
Definition BLI_span.hh:256
void highlight_tile_for_result(const RenderResult *result)
void unhighlight_tile(int x, int y, int width, int height)
void unhighlight_tile_for_result(const RenderResult *result)
Span< rcti > get_all_highlighted_tiles() const
void highlight_tile(int x, int y, int width, int height)
#define offsetof(t, d)
#define layer
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
bool is_enabled(const Scene &scene, ExecutionMode mode)
BMesh Iterators.
void DRW_gpu_context_enable()
void RE_engine_view_pause_set(RenderEngine *engine, const bool pause)
void RE_SetActiveRenderView(Render *re, const char *viewname)
void DEG_graph_tag_relations_update(Depsgraph *graph)
void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
void RE_engine_tile_highlight_set(RenderEngine *engine, int x, int y, int width, int height, bool highlight)
void DRW_render_context_enable(Render *render)
char * STRNCPY(char(&dst)[N], const char *src)
static void engine_render_add_result_pass_cb(void *user_data, Scene *, ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype)
RenderEngine * RE_engine_get(const Render *re)
void DRW_render_context_disable(Render *render)
bool RE_engine_gpu_context_create(RenderEngine *engine)
void RE_engine_view_auto_pause_set(RenderEngine *engine, const bool pause)
void RE_engine_gpu_context_unlock(RenderEngine *engine)
bool RE_engines_is_registered(const char *idname)
void RE_engine_update_result(RenderEngine *engine, RenderResult *result)
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
static bool engine_keep_depsgraph(RenderEngine *engine)
GPUContext * GPU_context_create(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)
void RE_engine_report(RenderEngine *engine, int type, const char *msg)
bool RE_engine_use_persistent_data(RenderEngine *engine)
void DRW_engines_free()
void RE_engine_gpu_context_disable(RenderEngine *engine)
RenderLayer * RE_GetRenderLayer(RenderResult *rr, const char *name)
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition threads.cc:353
bool RE_bake_has_engine(const Render *re)
bool RE_engine_gpu_context_enable(RenderEngine *engine)
@ RE_USE_GPU_CONTEXT
Definition RE_engine.h:52
@ RE_INTERNAL
Definition RE_engine.h:45
@ RE_USE_POSTPROCESS
Definition RE_engine.h:47
@ RE_USE_PREVIEW
Definition RE_engine.h:46
bool GPU_backend_supported()
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void BKE_camera_multiview_model_matrix(const struct RenderData *rd, const struct Object *camera, const char *viewname, float r_modelmat[4][4])
void WM_system_gpu_context_release(GHOST_IContext *context)
void RE_engine_update_render_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer, update_render_passes_cb_t callback, void *callback_data)
float RE_engine_get_camera_shift_x(RenderEngine *engine, Object *camera, bool use_spherical_stereo)
void RE_FreePersistentData(const Scene *scene)
void GPU_render_begin()
void GPU_context_active_set(GPUContext *)
void RE_engines_exit()
GHOST_IContext * WM_system_gpu_context_create()
void DEG_ids_clear_recalc(Depsgraph *depsgraph, bool backup)
void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode)
Definition threads.cc:470
void DRW_module_init()
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2600
RenderResult * RE_engine_get_result(RenderEngine *engine)
RenderPass * render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channels, const char *name, const char *viewname, const char *chan_id, const bool allocate)
bool RE_engine_get_spherical_stereo(RenderEngine *engine, Object *camera)
void RE_engine_gpu_context_destroy(RenderEngine *engine)
void RE_engine_free(RenderEngine *engine)
Global G
Definition blender.cc:57
void BKE_scene_ppm_get(const RenderData *rd, double r_ppm[2])
Definition scene.cc:3487
void render_result_free_list(ListBaseT< RenderResult > *lb, RenderResult *rr)
const char * RE_GetActiveRenderView(Render *re)
float BKE_camera_multiview_shift_x(const struct RenderData *rd, const struct Object *camera, const char *viewname)
void RE_engine_add_pass(RenderEngine *engine, const char *name, int channels, const char *chan_id, const char *layername)
void RE_engine_update_progress(RenderEngine *engine, float progress)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void DRW_gpu_context_disable()
RenderData * RE_engine_get_render_data(Render *re)
void WM_system_gpu_context_dispose(GHOST_IContext *context)
void RE_engine_end_result(RenderEngine *engine, RenderResult *result, bool cancel, bool highlight, bool merge_results)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
void BLI_mutex_lock(ThreadMutex *mutex)
Definition threads.cc:348
@ SCE_LAY_GREASE_PENCIL
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void render_result_passes_allocated_ensure(RenderResult *rr)
void RE_engine_register_pass(RenderEngine *engine, Scene *scene, ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype type)
void GPU_render_end()
void BLI_rw_mutex_unlock(ThreadRWMutex *mutex)
Definition threads.cc:480
void RE_engines_register(RenderEngineType *render_type)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
@ SCE_COMPOSITOR_DEVICE_GPU
Main * DEG_get_bmain(const Depsgraph *graph)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void render_result_to_bake(RenderEngine *engine, RenderResult *rr)
bool RE_engine_test_break(RenderEngine *engine)
void RE_engines_init()
bool BKE_reports_contain(ReportList *reports, eReportType level)
Definition report.cc:394
void DEG_graph_replace_owners(Depsgraph *depsgraph, Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition depsgraph.cc:286
void DRW_module_exit()
RenderPass * RE_engine_pass_by_index_get(RenderEngine *engine, const char *layer_name, int index)
void render_result_free(RenderResult *rr)
void DEG_debug_name_set(Depsgraph *depsgraph, const char *name)
MINLINE float int_as_float(int i)
int BLI_thread_is_main()
Definition threads.cc:184
static RenderResult * render_result_from_bake(RenderEngine *engine, int x, int y, int w, int h, const char *layername)
bool BKE_camera_multiview_spherical_stereo(const struct RenderData *rd, const struct Object *camera)
bool RE_engine_view_pause_get(const RenderEngine *engine)
const char * RE_engine_active_view_get(RenderEngine *engine)
ListBaseT< RenderEngineType > R_engines
bool RE_engine_is_external(const Render *re)
void WM_system_gpu_context_activate(GHOST_IContext *context)
static RenderResult * engine_render_create_result(Render *re)
bool DRW_render_check_grease_pencil(Depsgraph *depsgraph, View3D *v3d=nullptr)
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
const rcti * RE_engine_get_current_tiles(Render *re, int *r_total_tiles)
void RE_engine_draw_release(Render *re)
void BLI_mutex_end(ThreadMutex *mutex)
Definition threads.cc:363
void render_result_exr_file_cache_write(Render *re)
RenderEngineType * RE_engines_find(const char *idname)
bool RE_bake_engine(Render *re, Depsgraph *depsgraph, Object *object, const int object_id, const BakePixel pixel_array[], const BakeTargets *targets, const eScenePassType pass_type, const int pass_filter, float result[])
void RE_engine_get_camera_model_matrix(RenderEngine *engine, Object *camera, bool use_spherical_stereo, float r_modelmat[16])
bool RE_engine_draw_acquire(Render *re)
static void re_ensure_passes_allocated_thread_safe(Render *re)
RenderResult * RE_AcquireResultRead(Render *re)
RenderPass * RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname)
bool RE_engine_render(Render *re, bool do_all)
void render_result_clone_passes(Render *re, RenderResult *rr, const char *viewname)
void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
void RE_engine_update_memory_stats(RenderEngine *engine, float mem_used, float mem_peak)
RenderEngine * RE_engine_create(RenderEngineType *type)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void DRW_render_gpencil(RenderEngine *engine, Depsgraph *depsgraph)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bool DRW_gpu_context_release()
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2480
void RE_engine_free_blender_memory(RenderEngine *engine)
void RE_bake_engine_set_engine_parameters(Render *re, Main *bmain, Scene *scene)
void RE_engine_gpu_context_lock(RenderEngine *engine)
Scene * DEG_get_input_scene(const Depsgraph *graph)
void RE_create_render_pass(RenderResult *rr, const char *name, int channels, const char *chan_id, const char *layername, const char *viewname, const bool allocate)
void DEG_graph_relations_update(Depsgraph *graph)
void DEG_evaluate_on_framechange(Depsgraph *graph, float frame, DepsgraphEvaluateSyncWriteback sync_writeback=DEG_EVALUATE_SYNC_WRITEBACK_NO)
static CLG_LogRef LOG
Definition logging.cpp:12
static void engine_depsgraph_free(RenderEngine *engine)
bool DRW_gpu_context_try_enable()
RenderEngine * RE_view_engine_get(const ViewRender *view_render)
@ RE_ENGINE_ANIMATION
Definition RE_engine.h:63
@ RE_ENGINE_VIEW_PAUSED
Definition RE_engine.h:71
@ RE_ENGINE_RENDERING
Definition RE_engine.h:67
@ RE_ENGINE_HIGHLIGHT_TILES
Definition RE_engine.h:68
@ RE_ENGINE_VIEW_PAUSED_AUTO
Definition RE_engine.h:73
@ RE_ENGINE_CAN_DRAW
Definition RE_engine.h:69
@ RE_ENGINE_VIEW_PAUSED_NOTIFIED
Definition RE_engine.h:75
@ RE_ENGINE_PREVIEW
Definition RE_engine.h:64
bool RE_engine_view_pause_notify(RenderEngine *engine, const bContext *context)
static bool possibly_using_gpu_compositor(const Render *re)
void(*)(void *userdata, struct Scene *scene, struct ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype type) update_render_passes_cb_t
Definition RE_engine.h:132
void DRW_engines_register()
void BKE_scene_graph_update_for_newframe_ex(Depsgraph *depsgraph, bool clear_recalc)
Definition scene.cc:2877
static void engine_depsgraph_exit(RenderEngine *engine)
void DRW_gpu_context_activate(bool drw_state)
void render_result_merge(RenderResult *rr, RenderResult *rrpart)
RenderResult * render_result_new(Render *re, const rcti *partrct, const char *layername, const char *viewname)
void BLI_mutex_init(ThreadMutex *mutex)
Definition threads.cc:343
GHOST_IContext * RE_system_gpu_context_get(Render *re)
void RE_engine_tile_highlight_clear_all(RenderEngine *engine)
void render_copy_renderdata(RenderData *to, const RenderData *from)
GPUContext * GPU_context_active_get()
void WM_init_gpu_backend()
void RE_engine_active_view_set(RenderEngine *engine, const char *viewname)
void GPU_context_discard(GPUContext *)
static void engine_render_view_layer(Render *re, RenderEngine *engine, ViewLayer *view_layer_iter, const bool use_engine, const bool use_grease_pencil)
static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
RenderResult * RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname)
#define ceilf
#define FOREACH_VIEW_LAYER_TO_RENDER_END
#define RR_ALL_VIEWS
#define RR_ALL_LAYERS
#define FOREACH_VIEW_LAYER_TO_RENDER_BEGIN(re_, iter_)
#define R_ANIMATION
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
BakeImage * images
Definition RE_bake.h:38
std::shared_ptr< RenderDisplay > display
ThreadMutex engine_draw_mutex
ThreadRWMutex resultmutex
RenderResult * result
struct RenderEngine * engine
StructFreeFunc free
char name[258]
Definition DNA_ID.h:433
const float * float_data() const
float * float_data_for_write()
Definition allocimbuf.cc:79
eCompositorDevice compositor_device
struct RenderEngineType * next
Definition RE_engine.h:81
void(*) view_resume(struct RenderEngine *engine, const struct bContext *context)
Definition RE_engine.h:118
void(*) view_pause(struct RenderEngine *engine, const struct bContext *context)
Definition RE_engine.h:117
void(*) update_render_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer)
Definition RE_engine.h:123
void(*) update(struct RenderEngine *engine, struct Main *bmain, struct Depsgraph *depsgraph)
Definition RE_engine.h:88
void(*) render(struct RenderEngine *engine, struct Depsgraph *depsgraph)
Definition RE_engine.h:90
void(*) bake(struct RenderEngine *engine, struct Depsgraph *depsgraph, struct Object *object, int pass_type, int pass_filter, int width, int height)
Definition RE_engine.h:103
void(*) render_frame_finish(struct RenderEngine *engine)
Definition RE_engine.h:97
void(*) draw(struct RenderEngine *engine, const struct bContext *context, struct Depsgraph *depsgraph)
Definition RE_engine.h:99
ListBaseT< RenderResult > fullresult
Definition RE_engine.h:149
ThreadMutex update_render_passes_mutex
Definition RE_engine.h:169
void * update_render_passes_data
Definition RE_engine.h:171
ThreadMutex blender_gpu_context_mutex
Definition RE_engine.h:175
GHOST_IContext * system_gpu_context
Definition RE_engine.h:174
struct Depsgraph * depsgraph
Definition RE_engine.h:165
RenderEngineType * type
Definition RE_engine.h:141
struct ReportList * reports
Definition RE_engine.h:154
struct GPUContext * blender_gpu_context
Definition RE_engine.h:177
update_render_passes_cb_t update_render_passes_cb
Definition RE_engine.h:170
struct blender::RenderEngine::@346336373372233225050340234234072273127364302102 bake
struct Render * re
Definition RE_engine.h:148
struct Object * camera_override
Definition RE_engine.h:145
char name[RE_MAXNAME]
Definition RE_pipeline.h:94
struct ImBuf * ibuf
Definition RE_pipeline.h:72
ListBaseT< RenderLayer > layers
char scene_name[MAX_ID_NAME - 2]
const char * statstr
const char * infostr
struct Object * camera_override
bool prepare_viewlayer(struct ViewLayer *view_layer, struct Depsgraph *depsgraph) override
render::TilesHighlight * get_tile_highlight() override
struct ReportList * reports
RenderStats i
struct Main * main
Scene * pipeline_scene_eval
char viewname[MAX_NAME]
ListBaseT< ViewLayer > view_layers
struct RenderData r