Blender V5.3
eevee_instance.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include <fmt/format.h>
14
15#include "CLG_log.h"
16
17#include "BLI_string.hh"
18
19#include "BLT_translation.hh"
20
21#include "BKE_object.hh"
22
23#include "DEG_depsgraph.hh"
24
26
27#include "DRW_render.hh"
28
29#include "GPU_work_in_flight.hh"
30
32#include "eevee_camera.hh"
33#include "eevee_cryptomatte.hh"
34#include "eevee_debug_shared.hh"
36#include "eevee_film.hh"
37#include "eevee_gbuffer.hh"
38#include "eevee_hizbuffer.hh"
39#include "eevee_light.hh"
40#include "eevee_lightprobe.hh"
44#include "eevee_lookdev.hh"
45#include "eevee_material.hh"
46#include "eevee_motion_blur.hh"
47#include "eevee_pipeline.hh"
48#include "eevee_raytrace.hh"
50#include "eevee_sampling.hh"
51#include "eevee_shader.hh"
52#include "eevee_shadow.hh"
53#include "eevee_subsurface.hh"
54#include "eevee_sync.hh"
55#include "eevee_view.hh"
56#include "eevee_volume.hh"
57#include "eevee_world.hh"
58
59namespace blender::gpu {
60class WorkInFlight;
61} // namespace blender::gpu
62
63namespace blender::eevee {
64
68
69/* Combines data from several modules to avoid wasting binding slots. */
71 UniformDataBuf data{"UniformDataBuf"};
72 PipelineInfoBuf pipeline{"PipelineInfoBuf"};
73 RaytraceDataBuf raytrace{"RaytraceDataBuf"};
74
76 {
77 data.push_update();
78 pipeline.push_update();
79 raytrace.push_update();
80 }
81
82 template<typename PassType> void bind_resources(PassType &pass)
83 {
84 pass.bind_ubo(UNIFORM_BUF_SLOT, &data);
85 pass.bind_ubo(PIPELINE_BUF_SLOT, &pipeline);
86 pass.bind_ubo(RAYTRACE_BUF_SLOT, &raytrace);
87 }
88};
89
94class Instance : public DrawEngine {
95 friend VelocityModule;
96 friend MotionBlurModule;
97
99 static void *debug_scope_render_frame;
100 static void *debug_scope_render_sample;
101 static void *debug_scope_irradiance_setup;
102 static void *debug_scope_irradiance_sample;
103
104 uint64_t depsgraph_last_update_ = 0;
105 bool overlays_enabled_ = false;
106 bool skip_render_ = false;
107
109 std::string info_ = "";
110
111 public:
122 VelocityModule velocity;
123 MotionBlurModule motion_blur;
142
144
146 Depsgraph *depsgraph;
158 const View *drw_view = nullptr;
159 const View3D *v3d;
161
162 const DRWContext *draw_ctx = nullptr;
163
165 bool is_light_bake = false;
167 bool is_image_render = false;
171 bool is_playback = false;
173 bool is_navigating = false;
175 bool is_painting = false;
177 bool is_transforming = false;
181 bool draw_overlays = false;
182
185
187 bool use_surfaces = true;
188 bool use_curves = true;
189 bool use_volumes = true;
190
192
195
198
199 public:
201 : shaders(*ShaderModule::module_get()),
202 sync(*this),
203 materials(*this),
204 subsurface(*this),
205 pipelines(*this, uniform_data.pipeline),
206 shadows(*this, uniform_data.data.shadow),
207 lights(*this),
209 raytracing(*this, uniform_data.raytrace),
210 velocity(*this),
211 motion_blur(*this),
212 depth_of_field(*this),
213 cryptomatte(*this),
214 hiz_buffer(*this, uniform_data.data.hiz),
217 film(*this, uniform_data.data.film),
218 render_buffers(*this, uniform_data.data.render_pass),
219 main_view(*this),
220 capture_view(*this),
221 world(*this),
222 lookdev_view(*this),
223 lookdev(*this),
224 sphere_probes(*this),
225 planar_probes(*this),
226 volume_probes(*this),
227 light_probes(*this),
228 volume(*this, uniform_data.data.volumes) {};
229 ~Instance() override {};
230
232 {
233 return "EEVEE";
234 }
235
237 {
238 return true;
239 }
240
241 /* Render & Viewport. */
242 /* TODO(fclem): Split for clarity. */
243 void init(const int2 &output_res,
244 const rcti *output_rect,
245 const rcti *visible_rect,
247 Depsgraph *depsgraph,
248 Object *camera_object = nullptr,
249 const RenderLayer *render_layer = nullptr,
250 View *drw_view_ = nullptr,
251 const View3D *v3d = nullptr,
252 const RegionView3D *rv3d = nullptr);
253
254 void init() final;
255
256 void begin_sync() final;
257 void object_sync(ObjectRef &ob_ref, Manager &manager) final;
258 void end_sync() final;
259
260 bool is_loaded(ShaderGroups groups) const
261 {
262 return (loaded_shaders & groups) == groups;
263 }
264
268 bool do_lightprobe_sphere_sync() const;
269 bool do_planar_probe_sync() const;
270
276 bool needs_planar_probe_passes() const;
277
278 /* Render. */
279
280 void render_sync();
281 void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name);
282 void store_metadata(RenderResult *render_result);
283
284 /* Viewport. */
285
286 void draw_viewport();
288
289 void draw(Manager &manager) final;
290
291 /* Light bake. */
292
295 Object &probe,
296 FunctionRef<void()> context_enable,
297 FunctionRef<void()> context_disable,
298 FunctionRef<bool()> stop,
299 FunctionRef<void(LightProbeGridCacheFrame *, float progress)> result_update);
300
301 static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer);
302
303 /* Append a new line to the info string. */
304 template<typename... Args> void info_append(const char *msg, Args &&...args)
305 {
306 std::string fmt_msg = fmt::format(fmt::runtime(msg), args...) + "\n";
307 /* Don't print the same error twice. */
308 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
309 info_ += fmt_msg;
310 }
311 }
312
313 /* The same as `info_append`, but `msg` will be translated.
314 * NOTE: When calling this function, `msg` should be a string literal. */
315 template<typename... Args> void info_append_i18n(const char *msg, Args &&...args)
316 {
317 std::string fmt_msg = fmt::format(fmt::runtime(RPT_(msg)), args...) + "\n";
318 /* Don't print the same error twice. */
319 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
320 info_ += fmt_msg;
321 }
322 }
323
324 const char *info_get()
325 {
326 return info_.c_str();
327 }
328
329 bool is_viewport() const
330 {
331 return render == nullptr && !is_baking();
332 }
333
334 bool is_baking() const
335 {
336 return is_light_bake;
337 }
338
339 bool overlays_enabled() const
340 {
341 return overlays_enabled_;
342 }
343
346 {
348 }
349
350 bool use_scene_lights() const
351 {
352 return (!v3d) ||
353 ((v3d->shading.type == OB_MATERIAL) &&
355 ((v3d->shading.type == OB_RENDER) &&
357 }
358
359 /* Light the scene using the selected HDRI in the viewport shading pop-over. */
360 bool use_studio_light() const
361 {
362 return (v3d) && (((v3d->shading.type == OB_MATERIAL) &&
364 ((v3d->shading.type == OB_RENDER) &&
366 }
367
369 {
370 return (v3d) &&
372 }
373
375 {
376 return ob_ref.recalc_flags(depsgraph_last_update_);
377 }
378
380 {
381 return world.last_update > depsgraph_last_update_ ? uint(ID_RECALC_SHADING) : 0;
382 }
383
384 private:
389 void render_sample();
390 void render_read_result(RenderLayer *render_layer, const char *view_name);
391
392 void update_eval_members();
393
394 void set_time(float time);
395
396 struct DebugScope {
397 void *scope;
398
399 DebugScope(void *&scope_p, const char *name)
400 {
401 if (scope_p == nullptr) {
402 scope_p = GPU_debug_capture_scope_create(name);
403 }
404 scope = scope_p;
406 }
407
408 ~DebugScope()
409 {
411 }
412 };
413};
414
415} // namespace blender::eevee
General operations, lookup, etc. for blender objects.
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define RPT_(msgid)
uint recalc_flags(uint64_t last_update) const
VolumeProbeModule volume_probes
void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name)
SphereProbeModule sphere_probes
AmbientOcclusion ambient_occlusion
void info_append_i18n(const char *msg, Args &&...args)
bool gpencil_engine_enabled() const
SubsurfaceModule subsurface
StringRefNull name_get() final
bool uses_render_border() const final
void light_bake_irradiance(Object &probe, FunctionRef< void()> context_enable, FunctionRef< void()> context_disable, FunctionRef< bool()> stop, FunctionRef< void(LightProbeGridCacheFrame *, float progress)> result_update)
bool needs_lightprobe_sphere_passes() const
bool needs_planar_probe_passes() const
gpu::WorkInFlightPtr samples_in_flight
void object_sync(ObjectRef &ob_ref, Manager &manager) final
const RenderLayer * render_layer
const DRWContext * draw_ctx
GPUSamplerFiltering anisotropic_filtering
uint get_recalc_flags(const ObjectRef &ob_ref)
uint get_recalc_flags(const blender::World &world)
const RegionView3D * rv3d
void store_metadata(RenderResult *render_result)
void info_append(const char *msg, Args &&...args)
PlanarProbeModule planar_probes
static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
bool is_loaded(ShaderGroups groups) const
bool do_lightprobe_sphere_sync() const
UniformDataModule uniform_data
LightProbeModule light_probes
MotionBlurModule motion_blur
void init_light_bake(Depsgraph *depsgraph, draw::Manager *manager)
#define RAYTRACE_BUF_SLOT
#define PIPELINE_BUF_SLOT
#define UNIFORM_BUF_SLOT
constexpr T clamp(T, U, U) RET
PassType
draw::UniformBuffer< RayTraceData > RaytraceDataBuf
draw::UniformBuffer< UniformData > UniformDataBuf
draw::UniformBuffer< PipelineInfoData > PipelineInfoBuf
std::unique_ptr< gpu::WorkInFlight, gpu::WorkInFlightDeleter > WorkInFlightPtr
unsigned __int64 uint64_t
Definition BKE_text.h:91
void * GPU_debug_capture_scope_create(const char *name)
Definition gpu_debug.cc:132
unsigned int uint
Definition BKE_text.h:55
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
@ GPU_SAMPLER_FILTERING_DEFAULT
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_SCENE_LIGHTS
@ V3D_SHADING_SCENE_LIGHTS_RENDER
@ V3D_SHADING_SCENE_WORLD_RENDER
bool DEG_id_type_any_exists(const Depsgraph *depsgraph, short id_type)
VecBase< int32_t, 2 > int2
BMesh const char void * data
void GPU_debug_capture_scope_end(void *scope)
Definition gpu_debug.cc:168
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
bool GPU_debug_capture_scope_begin(void *scope)
Definition gpu_debug.cc:146
eView3DOverlay_Flag flag
eView3DShading_Flag flag
View3DOverlay overlay
View3DShading shading
void bind_resources(PassType &pass)