Blender V5.3
eevee_lightprobe_volume.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BKE_global.hh"
12#include "BKE_lightprobe.h"
13
14#include "GPU_capabilities.hh"
15
16#include "GPU_debug.hh"
17
18#include "eevee_debug_shared.hh"
19#include "eevee_instance.hh"
21
22#include <cstdio>
23
24namespace blender::eevee {
25
26/* -------------------------------------------------------------------- */
29
31{
32 display_grids_enabled_ = inst_.draw_overlays;
33
34 /* This might become an option in the future. */
35 bool use_l2_band = false;
36 int sh_coef_len = use_l2_band ? 9 : 4;
37 BLI_assert(gpu::TextureFormat::VOLUME_PROBE_FORMAT == gpu::TextureFormat::SFLOAT_16_16_16_16);
38 int texel_byte_size = 8; /* Assumes gpu::TextureFormat::SFLOAT_16_16_16_16. */
39 uint atlas_col_count = 0;
40 uint atlas_row_count = 0;
41
42 if (assign_if_different(irradiance_pool_size_,
43 uint(inst_.scene->eevee.gi_irradiance_pool_size)) ||
44 !irradiance_atlas_tx_.is_valid())
45 {
46 irradiance_atlas_tx_.free();
47 /* Find highest pool size within device limits. */
48 for (uint irradiance_pool_size = irradiance_pool_size_;
49 irradiance_pool_size >= 16 && !irradiance_atlas_tx_.is_valid();
50 irradiance_pool_size >>= 1)
51 {
52 int atlas_byte_size = 1024 * 1024 * irradiance_pool_size;
53 /* Reshape texture to improve grid occupancy within device limits. */
54 constexpr uint atlas_col_count_min = 16;
55 constexpr uint atlas_col_count_max = 16384;
56 for (uint atlas_col_count_try = atlas_col_count_min;
57 atlas_col_count_try <= atlas_col_count_max && !irradiance_atlas_tx_.is_valid();
58 atlas_col_count_try <<= 1)
59 {
60 int3 atlas_extent(IRRADIANCE_GRID_BRICK_SIZE);
61 atlas_extent.z *= sh_coef_len;
62 /* Add space for validity bits. */
63 atlas_extent.z += IRRADIANCE_GRID_BRICK_SIZE / 4;
64 atlas_extent.x *= atlas_col_count_try;
65
66 /* Determine the row count depending on the scene settings. */
67 int row_byte_size = math::reduce_mul(atlas_extent) * texel_byte_size;
68 atlas_row_count = divide_ceil_u(atlas_byte_size, row_byte_size);
69 atlas_extent.y *= atlas_row_count;
70
74 irradiance_atlas_tx_.ensure_3d(
75 gpu::TextureFormat::VOLUME_PROBE_FORMAT, atlas_extent, usage);
76 if (irradiance_atlas_tx_.is_valid()) {
77 do_full_update_ = true;
78 irradiance_pool_size_alloc_ = irradiance_pool_size;
79 atlas_col_count = atlas_col_count_try;
80 }
81 }
82 }
83 }
84 if (irradiance_pool_size_alloc_ != irradiance_pool_size_) {
85 inst_.info_append_i18n(
86 "Warning: Could not allocate light probes volume pool of {} MB, using {} MB instead.",
87 irradiance_pool_size_,
88 irradiance_pool_size_alloc_);
89 }
90
91 if (do_full_update_) {
92 do_full_update_ = false;
93 do_update_world_ = true;
94
95 /* Delete all references to existing bricks. */
96 for (VolumeProbe &grid : inst_.light_probes.volume_map_.values()) {
97 grid.bricks.clear();
98 }
99 brick_pool_.clear();
100 /* Fill with all the available bricks. */
101 for (auto i : IndexRange(atlas_row_count * atlas_col_count)) {
102 if (i == 0) {
103 /* Reserve one brick for the world. */
104 world_brick_index_ = 0;
105 }
106 else {
107 IrradianceBrick brick;
108 brick.atlas_coord = uint2(i % atlas_col_count, i / atlas_col_count) *
110 brick_pool_.append(irradiance_brick_pack(brick));
111 }
112 }
113
114 if (irradiance_atlas_tx_.is_valid()) {
115 /* Clear the pool to avoid any interpolation to undefined values. */
116 irradiance_atlas_tx_.clear(float4(0.0f));
117 }
118 }
119
120 if (irradiance_atlas_tx_.is_valid() == false) {
121 inst_.info_append_i18n("Irradiance Atlas texture could not be created");
122 }
123}
124
126{
127 if (inst_.is_baking()) {
128 bake.sync();
129 }
130}
131
133{
134 if (brick_pool_.size() < brick_len) {
135 /* Fail allocation. Not enough brick in the atlas. */
136 return {};
137 }
138 Vector<IrradianceBrickPacked> allocated(brick_len);
139 /* Copy bricks to return vector. */
140 allocated.as_mutable_span().copy_from(brick_pool_.as_span().take_back(brick_len));
141 /* Remove bricks from the pool. */
142 brick_pool_.resize(brick_pool_.size() - brick_len);
143
144 return allocated;
145}
146
148{
149 brick_pool_.extend(bricks.as_span());
150 bricks.clear();
151}
152
154{
155 Vector<VolumeProbe *> grid_loaded;
156
157 bool any_update = false;
158 /* First allocate the needed bricks and populate the brick buffer. */
159 bricks_infos_buf_.clear();
160 for (VolumeProbe &grid : inst_.light_probes.volume_map_.values()) {
161 LightProbeGridCacheFrame *cache = grid.cache ? grid.cache->grid_static_cache : nullptr;
162 if (cache == nullptr) {
163 continue;
164 }
165
166 if (cache->baking.L0 == nullptr && cache->irradiance.L0 == nullptr) {
167 /* No data. */
168 continue;
169 }
170
171 int3 grid_size = int3(cache->size);
172 if (grid_size.x <= 0 || grid_size.y <= 0 || grid_size.z <= 0) {
173 inst_.info_append_i18n("Error: Malformed irradiance grid data");
174 continue;
175 }
176
177 /* TODO frustum cull and only load visible grids. */
178
179 /* Note that we reserve 1 slot for the world irradiance. */
180 if (grid_loaded.size() >= IRRADIANCE_GRID_MAX - 1) {
181 inst_.info_append_i18n("Error: Too many irradiance grids in the scene");
182 /* TODO frustum cull and only load visible grids. */
183 // inst_.info_append_i18n("Error: Too many grid visible");
184 continue;
185 }
186
187 int3 grid_size_with_padding = grid_size + 2;
188 if (grid.bricks.is_empty()) {
189 int3 grid_size_in_bricks = math::divide_ceil(grid_size_with_padding,
191 int brick_len = grid_size_in_bricks.x * grid_size_in_bricks.y * grid_size_in_bricks.z;
192 grid.bricks = bricks_alloc(brick_len);
193
194 if (grid.bricks.is_empty()) {
195 inst_.info_append_i18n("Error: Irradiance grid allocation failed");
196 continue;
197 }
198 grid.do_update = true;
199 }
200
201 if (do_update_world_) {
202 /* Update grid composition if world changed. */
203 grid.do_update = true;
204 }
205
206 any_update = any_update || grid.do_update;
207
208 grid.brick_offset = bricks_infos_buf_.size();
209 bricks_infos_buf_.extend(grid.bricks);
210
211 float4x4 grid_to_world = grid.object_to_world * math::from_location<float4x4>(float3(-1.0f)) *
213 float3(2.0f / float3(grid_size_with_padding - 1))) *
215
216 grid.world_to_grid_transposed = float3x4(math::transpose(math::invert(grid_to_world)));
217 grid.grid_size_padded = grid_size_with_padding;
218 grid_loaded.append(&grid);
219 }
220
221 /* TODO: This is greedy update detection. We should check if a change can influence each grid
222 * before tagging update. But this is a bit too complex and update is quite cheap. So we update
223 * everything if there is any update on any grid. */
224 if (any_update) {
225 for (VolumeProbe *grid : grid_loaded) {
226 grid->do_update = true;
227 }
228 }
229
230 /* Then create brick & grid infos UBOs content. */
231 int world_grid_index = 0;
232 {
233 /* Stable sorting of grids. */
234 std::ranges::sort(grid_loaded, [](const VolumeProbe *a, const VolumeProbe *b) {
235 float volume_a = math::determinant(float3x3(a->object_to_world));
236 float volume_b = math::determinant(float3x3(b->object_to_world));
237 if (volume_a != volume_b) {
238 /* Smallest first. */
239 return volume_a < volume_b;
240 }
241 /* Volumes are identical. Any arbitrary criteria can be used to sort them.
242 * Use position to avoid unstable result caused by depsgraph non deterministic eval
243 * order. This could also become a priority parameter. */
245 float3 _b = b->object_to_world.location();
246 if (_a.x != _b.x) {
247 return _a.x < _b.x;
248 }
249 if (_a.y != _b.y) {
250 return _a.y < _b.y;
251 }
252 if (_a.z != _b.z) {
253 return _a.z < _b.z;
254 }
255 /* Fallback to memory address, since there's no good alternative. */
256 return a < b;
257 });
258
259 /* Insert grids in UBO in sorted order. */
260 int grids_len = 0;
261 for (VolumeProbe *grid : grid_loaded) {
262 grid->grid_index = grids_len;
263 grids_infos_buf_[grids_len++] = *grid;
264 }
265
266 /* Insert world grid last. */
267 world_grid_index = grids_len++;
268
269 VolumeProbeData grid;
271 grid.grid_size_padded = int3(1);
272 grid.brick_offset = bricks_infos_buf_.size();
273 grid.normal_bias = 0.0f;
274 grid.view_bias = 0.0f;
275 grid.facing_bias = 0.0f;
276 grids_infos_buf_[world_grid_index] = grid;
277
278 bricks_infos_buf_.append(world_brick_index_);
279
280 if (grids_len < IRRADIANCE_GRID_MAX) {
281 /* Tag last grid as invalid to stop the iteration. */
282 grids_infos_buf_[grids_len].grid_size_padded = int3(-1);
283 }
284
285 bricks_infos_buf_.push_update();
286 grids_infos_buf_.push_update();
287 }
288
289 /* Upload data for world. */
290 if (do_update_world_) {
291 grid_upload_ps_.init();
292 grid_upload_ps_.shader_set(inst_.shaders.static_shader_get(LIGHTPROBE_IRRADIANCE_WORLD));
293 grid_upload_ps_.bind_resources(inst_.uniform_data);
294 grid_upload_ps_.bind_ssbo("harmonic_buf", &inst_.sphere_probes.spherical_harmonics_buf());
295 grid_upload_ps_.bind_ubo("grids_infos_buf", &grids_infos_buf_);
296 grid_upload_ps_.bind_ssbo("bricks_infos_buf", &bricks_infos_buf_);
297 grid_upload_ps_.push_constant("grid_index", world_grid_index);
298 grid_upload_ps_.bind_image("irradiance_atlas_img", &irradiance_atlas_tx_);
299 grid_upload_ps_.bind_texture("irradiance_atlas_tx", &irradiance_atlas_tx_);
300 /* Sync with extraction. */
301 grid_upload_ps_.barrier(GPU_BARRIER_SHADER_STORAGE);
302 /* Only upload one brick. */
303 grid_upload_ps_.dispatch(int3(1));
304 /* Sync with next load. */
305 grid_upload_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
306
307 inst_.manager->submit(grid_upload_ps_);
308 }
309
310 /* Upload data for each grid that need to be inserted in the atlas.
311 * Upload by order of dependency. */
312 /* Start at world index to not load any other grid (+1 because we decrement at loop start). */
313 int grid_start_index = grid_loaded.size() + 1;
314 for (auto it = grid_loaded.rbegin(); it != grid_loaded.rend(); ++it) {
315 grid_start_index--;
316
317 VolumeProbe *grid = *it;
318 if (!grid->do_update) {
319 continue;
320 }
321
322 grid->do_update = false;
323
325
326 /* Staging textures are recreated for each light grid to avoid increasing VRAM usage. */
327 draw::Texture irradiance_a_tx = {"irradiance_a_tx"};
328 draw::Texture irradiance_b_tx = {"irradiance_b_tx"};
329 draw::Texture irradiance_c_tx = {"irradiance_c_tx"};
330 draw::Texture irradiance_d_tx = {"irradiance_d_tx"};
331 draw::Texture validity_tx = {"validity_tx"};
332
334 int3 grid_size = int3(cache->size);
335 if (cache->baking.L0) {
336 irradiance_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
337 grid_size,
338 usage,
339 reinterpret_cast<const float *>(cache->baking.L0));
340 irradiance_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
341 grid_size,
342 usage,
343 reinterpret_cast<const float *>(cache->baking.L1_a));
344 irradiance_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
345 grid_size,
346 usage,
347 reinterpret_cast<const float *>(cache->baking.L1_b));
348 irradiance_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
349 grid_size,
350 usage,
351 reinterpret_cast<const float *>(cache->baking.L1_c));
352 validity_tx.ensure_3d(
353 gpu::TextureFormat::SFLOAT_16, grid_size, usage, cache->baking.validity);
354 if (cache->baking.validity == nullptr) {
355 /* Avoid displaying garbage data. */
356 validity_tx.clear(float4(0.0));
357 }
358 }
359 else if (cache->irradiance.L0) {
360 irradiance_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
361 grid_size,
362 usage,
363 reinterpret_cast<const float *>(cache->irradiance.L0));
364 irradiance_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
365 grid_size,
366 usage,
367 reinterpret_cast<const float *>(cache->irradiance.L1_a));
368 irradiance_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
369 grid_size,
370 usage,
371 reinterpret_cast<const float *>(cache->irradiance.L1_b));
372 irradiance_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
373 grid_size,
374 usage,
375 reinterpret_cast<const float *>(cache->irradiance.L1_c));
376 validity_tx.ensure_3d(gpu::TextureFormat::UNORM_8, grid_size, usage);
377 if (cache->connectivity.validity) {
378 /* TODO(fclem): Make texture creation API work with different data types. */
379 GPU_texture_update_sub(validity_tx,
381 cache->connectivity.validity,
382 0,
383 0,
384 0,
385 UNPACK3(grid_size));
386 }
387 else {
388 /* Avoid displaying garbage data. */
389 validity_tx.clear(float4(0.0));
390 }
391 }
392 else {
393 continue;
394 }
395
396 if (irradiance_a_tx.is_valid() == false) {
397 inst_.info_append_i18n("Error: Could not allocate irradiance staging texture");
398 /* Avoid undefined behavior with uninitialized values. Still load a clear texture. */
399 const float4 zero(0.0f);
400 irradiance_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16, int3(1), usage, zero);
401 irradiance_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16, int3(1), usage, zero);
402 irradiance_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16, int3(1), usage, zero);
403 irradiance_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16, int3(1), usage, zero);
404 validity_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16, int3(1), usage, zero);
405 }
406
407 bool visibility_available = cache->visibility.L0 != nullptr;
408 bool is_baking = cache->irradiance.L0 == nullptr;
409
410 draw::Texture visibility_a_tx = {"visibility_a_tx"};
411 draw::Texture visibility_b_tx = {"visibility_b_tx"};
412 draw::Texture visibility_c_tx = {"visibility_c_tx"};
413 draw::Texture visibility_d_tx = {"visibility_d_tx"};
414 if (visibility_available) {
415 visibility_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16,
416 grid_size,
417 usage,
418 const_cast<const float *>(cache->visibility.L0));
419 visibility_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16,
420 grid_size,
421 usage,
422 const_cast<const float *>(cache->visibility.L1_a));
423 visibility_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16,
424 grid_size,
425 usage,
426 const_cast<const float *>(cache->visibility.L1_b));
427 visibility_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16,
428 grid_size,
429 usage,
430 const_cast<const float *>(cache->visibility.L1_c));
431
432 GPU_texture_swizzle_set(visibility_a_tx, "111r");
433 GPU_texture_swizzle_set(visibility_b_tx, "111r");
434 GPU_texture_swizzle_set(visibility_c_tx, "111r");
435 GPU_texture_swizzle_set(visibility_d_tx, "111r");
436 }
437 else if (!is_baking) {
438 /* Missing visibility. Load default visibility L0 = 1, L1 = (0, 0, 0). */
439 GPU_texture_swizzle_set(irradiance_a_tx, "rgb1");
440 GPU_texture_swizzle_set(irradiance_b_tx, "rgb0");
441 GPU_texture_swizzle_set(irradiance_c_tx, "rgb0");
442 GPU_texture_swizzle_set(irradiance_d_tx, "rgb0");
443 }
444
445 grid_upload_ps_.init();
446 grid_upload_ps_.shader_set(inst_.shaders.static_shader_get(LIGHTPROBE_IRRADIANCE_LOAD));
447
448 grid_upload_ps_.bind_resources(inst_.uniform_data);
449 grid_upload_ps_.push_constant("validity_threshold", grid->validity_threshold);
450 grid_upload_ps_.push_constant("dilation_threshold", grid->dilation_threshold);
451 grid_upload_ps_.push_constant("dilation_radius", grid->dilation_radius);
452 grid_upload_ps_.push_constant("grid_index", grid->grid_index);
453 grid_upload_ps_.push_constant("grid_start_index", grid_start_index);
454 grid_upload_ps_.push_constant("grid_local_to_world", grid->object_to_world);
455 grid_upload_ps_.push_constant("grid_intensity_factor", grid->intensity);
456 grid_upload_ps_.bind_ubo("grids_infos_buf", &grids_infos_buf_);
457 grid_upload_ps_.bind_ssbo("bricks_infos_buf", &bricks_infos_buf_);
458 grid_upload_ps_.bind_texture("irradiance_a_tx", &irradiance_a_tx);
459 grid_upload_ps_.bind_texture("irradiance_b_tx", &irradiance_b_tx);
460 grid_upload_ps_.bind_texture("irradiance_c_tx", &irradiance_c_tx);
461 grid_upload_ps_.bind_texture("irradiance_d_tx", &irradiance_d_tx);
462 grid_upload_ps_.bind_texture("validity_tx", &validity_tx);
463 grid_upload_ps_.bind_image("irradiance_atlas_img", &irradiance_atlas_tx_);
464 /* NOTE: We are read and writing the same texture that we are sampling from. If that causes an
465 * issue, we should revert to manual trilinear interpolation. */
466 grid_upload_ps_.bind_texture("irradiance_atlas_tx", &irradiance_atlas_tx_);
467 /* If visibility is invalid, either it is still baking and visibility is stored with
468 * irradiance, or it is missing and we sample a completely uniform visibility. */
469 bool use_vis = visibility_available;
470 grid_upload_ps_.bind_texture("visibility_a_tx", use_vis ? &visibility_a_tx : &irradiance_a_tx);
471 grid_upload_ps_.bind_texture("visibility_b_tx", use_vis ? &visibility_b_tx : &irradiance_b_tx);
472 grid_upload_ps_.bind_texture("visibility_c_tx", use_vis ? &visibility_c_tx : &irradiance_c_tx);
473 grid_upload_ps_.bind_texture("visibility_d_tx", use_vis ? &visibility_d_tx : &irradiance_d_tx);
474
475 /* Runtime grid is padded for blending with surrounding probes. */
476 int3 grid_size_with_padding = grid_size + 2;
477 /* Note that we take into account the padding border of each brick. */
478 int3 grid_size_in_bricks = math::divide_ceil(grid_size_with_padding,
480 grid_upload_ps_.dispatch(grid_size_in_bricks);
481 /* Sync with next load. */
482 grid_upload_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
483
484 inst_.manager->submit(grid_upload_ps_);
485
486 irradiance_a_tx.free();
487 irradiance_b_tx.free();
488 irradiance_c_tx.free();
489 irradiance_d_tx.free();
490 }
491
492 do_update_world_ = false;
493}
494
496{
497 if (!inst_.is_baking()) {
498 debug_pass_draw(view, view_fb);
499 display_pass_draw(view, view_fb);
500 }
501}
502
503void VolumeProbeModule::debug_pass_draw(View &view, gpu::FrameBuffer *view_fb)
504{
505 switch (inst_.debug_mode) {
507 inst_.info_append("Debug Mode: Surfels Normal");
508 break;
510 inst_.info_append("Debug Mode: Surfels Cluster");
511 break;
513 inst_.info_append("Debug Mode: Surfels Irradiance");
514 break;
516 inst_.info_append("Debug Mode: Surfels Visibility");
517 break;
519 inst_.info_append("Debug Mode: Irradiance Validity");
520 break;
522 inst_.info_append("Debug Mode: Virtual Offset");
523 break;
524 default:
525 /* Nothing to display. */
526 return;
527 }
528
529 for (const VolumeProbe &grid : inst_.light_probes.volume_map_.values()) {
530 if (grid.cache == nullptr) {
531 continue;
532 }
533
534 LightProbeGridCacheFrame *cache = grid.cache->grid_static_cache;
535
536 if (cache == nullptr) {
537 continue;
538 }
539
540 switch (inst_.debug_mode) {
545 if (cache->surfels == nullptr || cache->surfels_len == 0) {
546 continue;
547 }
548 float max_axis_len = math::reduce_max(math::to_scale(grid.object_to_world));
549 debug_ps_.init();
550 debug_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
551 DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state);
552 debug_ps_.framebuffer_set(&view_fb);
553 debug_ps_.shader_set(inst_.shaders.static_shader_get(DEBUG_SURFELS));
554 debug_ps_.push_constant("debug_surfel_radius", 0.5f * max_axis_len / grid.surfel_density);
555 debug_ps_.push_constant("debug_mode", int(inst_.debug_mode));
556
557 debug_surfels_buf_.resize(cache->surfels_len);
558 /* TODO(fclem): Cleanup: Could have a function in draw::StorageArrayBuffer that takes an
559 * input data. */
560 Span<Surfel> grid_surfels(static_cast<Surfel *>(cache->surfels), cache->surfels_len);
561 MutableSpan<Surfel>(debug_surfels_buf_.data(), cache->surfels_len).copy_from(grid_surfels);
562 debug_surfels_buf_.push_update();
563
564 debug_ps_.bind_ssbo("surfels_buf", debug_surfels_buf_);
565 debug_ps_.draw_procedural(GPU_PRIM_TRI_STRIP, cache->surfels_len, 4);
566
567 inst_.manager->submit(debug_ps_, view);
568 break;
569 }
570
573 int3 grid_size = int3(cache->size);
574 debug_ps_.init();
575 debug_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
576 DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state);
577 debug_ps_.framebuffer_set(&view_fb);
578 debug_ps_.shader_set(inst_.shaders.static_shader_get(DEBUG_IRRADIANCE_GRID));
579 debug_ps_.push_constant("debug_mode", int(inst_.debug_mode));
580 debug_ps_.push_constant("grid_mat", grid.object_to_world);
581
583 Texture debug_data_tx = {"debug_data_tx"};
584
585 if (inst_.debug_mode == eDebugMode::DEBUG_IRRADIANCE_CACHE_VALIDITY) {
586 const float *data;
587 if (cache->baking.validity) {
588 data = cache->baking.validity;
589 debug_data_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16, grid_size, usage, data);
590 }
591 else if (cache->connectivity.validity) {
592 debug_data_tx.ensure_3d(gpu::TextureFormat::UNORM_8, grid_size, usage);
593 /* TODO(fclem): Make texture creation API work with different data types. */
594 GPU_texture_update_sub(debug_data_tx,
596 cache->connectivity.validity,
597 0,
598 0,
599 0,
600 UNPACK3(grid_size));
601 }
602 else {
603 continue;
604 }
605 debug_ps_.push_constant("debug_value", grid.validity_threshold);
606 debug_ps_.bind_texture("debug_data_tx", debug_data_tx);
607 debug_ps_.draw_procedural(GPU_PRIM_POINTS, 1, grid_size.x * grid_size.y * grid_size.z);
608 }
609 else {
610 if (cache->baking.virtual_offset) {
611 const float *data = reinterpret_cast<const float *>(cache->baking.virtual_offset);
612 debug_data_tx.ensure_3d(
613 gpu::TextureFormat::SFLOAT_16_16_16_16, grid_size, usage, data);
614 }
615 else {
616 continue;
617 }
618 debug_ps_.bind_texture("debug_data_tx", debug_data_tx);
619 debug_ps_.draw_procedural(
620 GPU_PRIM_LINES, 1, grid_size.x * grid_size.y * grid_size.z * 2);
621 }
622
623 inst_.manager->submit(debug_ps_, view);
624 break;
625 }
626
627 default:
628 break;
629 }
630 }
631}
632
633void VolumeProbeModule::display_pass_draw(View &view, gpu::FrameBuffer *view_fb)
634{
635 if (!display_grids_enabled_) {
636 return;
637 }
638
639 for (const VolumeProbe &grid : inst_.light_probes.volume_map_.values()) {
640 if (!grid.viewport_display || grid.viewport_display_size == 0.0f || !grid.cache ||
641 !grid.cache->grid_static_cache)
642 {
643 continue;
644 }
645
646 LightProbeGridCacheFrame *cache = grid.cache->grid_static_cache;
647
648 /* Display texture. Updated for each individual light grid to avoid increasing VRAM usage. */
649 draw::Texture irradiance_a_tx = {"irradiance_a_tx"};
650 draw::Texture irradiance_b_tx = {"irradiance_b_tx"};
651 draw::Texture irradiance_c_tx = {"irradiance_c_tx"};
652 draw::Texture irradiance_d_tx = {"irradiance_d_tx"};
653 draw::Texture validity_tx = {"validity_tx"};
654
656 int3 grid_size = int3(cache->size);
657 if (cache->baking.L0) {
658 irradiance_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
659 grid_size,
660 usage,
661 reinterpret_cast<const float *>(cache->baking.L0));
662 irradiance_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
663 grid_size,
664 usage,
665 reinterpret_cast<const float *>(cache->baking.L1_a));
666 irradiance_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
667 grid_size,
668 usage,
669 reinterpret_cast<const float *>(cache->baking.L1_b));
670 irradiance_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16_16,
671 grid_size,
672 usage,
673 reinterpret_cast<const float *>(cache->baking.L1_c));
674 validity_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16,
675 grid_size,
676 usage,
677 const_cast<const float *>(cache->baking.validity));
678 if (cache->baking.validity == nullptr) {
679 /* Avoid displaying garbage data. */
680 validity_tx.clear(float4(0.0));
681 }
682 }
683 else if (cache->irradiance.L0) {
684 irradiance_a_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
685 grid_size,
686 usage,
687 reinterpret_cast<const float *>(cache->irradiance.L0));
688 irradiance_b_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
689 grid_size,
690 usage,
691 reinterpret_cast<const float *>(cache->irradiance.L1_a));
692 irradiance_c_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
693 grid_size,
694 usage,
695 reinterpret_cast<const float *>(cache->irradiance.L1_b));
696 irradiance_d_tx.ensure_3d(gpu::TextureFormat::SFLOAT_16_16_16,
697 grid_size,
698 usage,
699 reinterpret_cast<const float *>(cache->irradiance.L1_c));
700 validity_tx.ensure_3d(gpu::TextureFormat::UNORM_8, grid_size, usage);
701 if (cache->connectivity.validity) {
702 /* TODO(fclem): Make texture creation API work with different data types. */
703 GPU_texture_update_sub(validity_tx,
705 cache->connectivity.validity,
706 0,
707 0,
708 0,
709 UNPACK3(grid_size));
710 }
711 else {
712 /* Avoid displaying garbage data. */
713 validity_tx.clear(float4(0.0));
714 }
715 }
716 else {
717 continue;
718 }
719
720 display_grids_ps_.init();
721 display_grids_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
722 DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state |
724 display_grids_ps_.framebuffer_set(&view_fb);
725 display_grids_ps_.shader_set(inst_.shaders.static_shader_get(DISPLAY_PROBE_VOLUME));
726
727 display_grids_ps_.push_constant("sphere_radius", grid.viewport_display_size);
728 display_grids_ps_.push_constant("grid_resolution", grid_size);
729 display_grids_ps_.push_constant("grid_to_world", grid.object_to_world);
730 display_grids_ps_.push_constant("world_to_grid", grid.world_to_object);
731 /* TODO(fclem): Make it an option when display options are moved to probe DNA. */
732 display_grids_ps_.push_constant("display_validity", false);
733
734 display_grids_ps_.bind_texture("irradiance_a_tx", &irradiance_a_tx);
735 display_grids_ps_.bind_texture("irradiance_b_tx", &irradiance_b_tx);
736 display_grids_ps_.bind_texture("irradiance_c_tx", &irradiance_c_tx);
737 display_grids_ps_.bind_texture("irradiance_d_tx", &irradiance_d_tx);
738 display_grids_ps_.bind_texture("validity_tx", &validity_tx);
739
740 int sample_count = int(BKE_lightprobe_grid_cache_frame_sample_count(cache));
741 int triangle_count = sample_count * 2;
742 display_grids_ps_.draw_procedural(GPU_PRIM_TRIS, 1, triangle_count * 3);
743
744 inst_.manager->submit(display_grids_ps_, view);
745
746 irradiance_a_tx.free();
747 irradiance_b_tx.free();
748 irradiance_c_tx.free();
749 irradiance_d_tx.free();
750 }
751}
752
754
755/* -------------------------------------------------------------------- */
758
759void IrradianceBake::init(const Object &probe_object)
760{
761 float max_axis_len = math::reduce_max(math::to_scale(probe_object.object_to_world()));
762
764 probe_object);
765 surfel_density_ = lightprobe.grid_surfel_density / max_axis_len;
766 min_distance_to_surface_ = lightprobe.grid_surface_bias;
767 max_virtual_offset_ = lightprobe.grid_escape_bias;
768 clip_distance_ = lightprobe.clipend;
769 capture_world_ = (lightprobe.grid_flag & LIGHTPROBE_GRID_CAPTURE_WORLD);
770 capture_indirect_ = (lightprobe.grid_flag & LIGHTPROBE_GRID_CAPTURE_INDIRECT);
771 capture_emission_ = (lightprobe.grid_flag & LIGHTPROBE_GRID_CAPTURE_EMISSION);
772
773 /* Initialize views data, since they're used by other modules. */
775}
776
778{
779 {
780 PassSimple &pass = surfel_light_eval_ps_;
781 pass.init();
782 /* Apply lights contribution to scene surfel representation. */
783 pass.shader_set(inst_.shaders.static_shader_get(SURFEL_LIGHT));
784 pass.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
785 pass.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
786 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
787 pass.bind_resources(inst_.uniform_data);
788 pass.bind_resources(inst_.lights);
789 pass.bind_resources(inst_.shadows);
790 /* Sync with the surfel creation stage. */
794 pass.dispatch(&dispatch_per_surfel_);
795 }
796 {
797 PassSimple &pass = surfel_cluster_build_ps_;
798 pass.init();
799 pass.shader_set(inst_.shaders.static_shader_get(SURFEL_CLUSTER_BUILD));
800 pass.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
801 pass.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
802 pass.bind_image("cluster_list_img", &cluster_list_tx_);
804 pass.dispatch(&dispatch_per_surfel_);
806 }
807 {
808 PassSimple &pass = surfel_ray_build_ps_;
809 pass.init();
810 {
811 /* Count number of surfel per list. */
812 PassSimple::Sub &sub = pass.sub("ListPrepare");
813 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_LIST_PREPARE));
814 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
815 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
816 sub.bind_ssbo("list_counter_buf", &list_counter_buf_);
817 sub.bind_ssbo("list_info_buf", &list_info_buf_);
819 sub.dispatch(&dispatch_per_surfel_);
820 }
821 {
822 /* Prefix sum of list sizes. Outputs an IndexRange per list. */
823 PassSimple::Sub &sub = pass.sub("ListPrefix");
824 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_LIST_PREFIX));
825 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
826 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
827 sub.bind_ssbo("list_counter_buf", &list_counter_buf_);
828 sub.bind_ssbo("list_range_buf", &list_range_buf_);
829 sub.bind_ssbo("list_info_buf", &list_info_buf_);
831 sub.dispatch(&dispatch_per_list_);
832 }
833 {
834 /* Copy surfel list sorting data into a flat array.
835 * All lists data are contiguous in memory using the IndexRange from previous pass. */
836 PassSimple::Sub &sub = pass.sub("ListFlatten");
837 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_LIST_FLATTEN));
838 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
839 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
840 sub.bind_ssbo("list_counter_buf", &list_counter_buf_);
841 sub.bind_ssbo("list_range_buf", &list_range_buf_);
842 sub.bind_ssbo("list_item_distance_buf", &list_item_distance_buf_);
843 sub.bind_ssbo("list_item_surfel_id_buf", &list_item_surfel_id_buf_);
844 sub.bind_ssbo("list_info_buf", &list_info_buf_);
846 sub.dispatch(&dispatch_per_surfel_);
847 }
848 {
849 /* Radix sort of the list. Output surfel index in the sorted list. */
850 PassSimple::Sub &sub = pass.sub("ListSort");
851 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_LIST_SORT));
852 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
853 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
854 sub.bind_ssbo("list_range_buf", &list_range_buf_);
855 sub.bind_ssbo("list_item_surfel_id_buf", &list_item_surfel_id_buf_);
856 sub.bind_ssbo("list_item_distance_buf", &list_item_distance_buf_);
857 sub.bind_ssbo("sorted_surfel_id_buf", &sorted_surfel_id_buf_);
858 sub.bind_ssbo("list_info_buf", &list_info_buf_);
860 sub.dispatch(&dispatch_per_surfel_);
861 }
862 {
863 /* Take the sorted lists array and copy adjacent surfel indices back to the Surfels.
864 * Also relink coplanar surfels to avoid over shadowing. */
865 PassSimple::Sub &sub = pass.sub("ListBuild");
866 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_LIST_BUILD));
867 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
868 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
869 sub.bind_ssbo("list_start_buf", &list_start_buf_);
870 sub.bind_ssbo("list_range_buf", &list_range_buf_);
871 sub.bind_ssbo("sorted_surfel_id_buf", &sorted_surfel_id_buf_);
872 sub.bind_ssbo("list_info_buf", &list_info_buf_);
874 sub.dispatch(&dispatch_per_list_);
875 }
876 }
877 {
878 PassSimple &pass = surfel_light_propagate_ps_;
879 pass.init();
880 {
881 PassSimple::Sub &sub = pass.sub("RayEval");
882 sub.shader_set(inst_.shaders.static_shader_get(SURFEL_RAY));
883 sub.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
884 sub.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
885 sub.bind_resources(inst_.sphere_probes);
886 sub.push_constant("radiance_src", &radiance_src_);
887 sub.push_constant("radiance_dst", &radiance_dst_);
889 sub.dispatch(&dispatch_per_surfel_);
890 }
891 }
892 {
893 PassSimple &pass = irradiance_capture_ps_;
894 pass.init();
895 pass.shader_set(inst_.shaders.static_shader_get(LIGHTPROBE_IRRADIANCE_RAY));
896 pass.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
897 pass.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
898 pass.bind_resources(inst_.sphere_probes);
899 pass.bind_ssbo("list_start_buf", &list_start_buf_);
900 pass.bind_ssbo("list_info_buf", &list_info_buf_);
901 pass.push_constant("radiance_src", &radiance_src_);
902 pass.bind_image("irradiance_L0_img", &irradiance_L0_tx_);
903 pass.bind_image("irradiance_L1_a_img", &irradiance_L1_a_tx_);
904 pass.bind_image("irradiance_L1_b_img", &irradiance_L1_b_tx_);
905 pass.bind_image("irradiance_L1_c_img", &irradiance_L1_c_tx_);
906 pass.bind_image("validity_img", &validity_tx_);
907 pass.bind_image("virtual_offset_img", &virtual_offset_tx_);
909 pass.dispatch(&dispatch_per_grid_sample_);
910 }
911 {
912 PassSimple &pass = irradiance_offset_ps_;
913 pass.init();
914 pass.shader_set(inst_.shaders.static_shader_get(LIGHTPROBE_IRRADIANCE_OFFSET));
915 pass.bind_ssbo(SURFEL_BUF_SLOT, &surfels_buf_);
916 pass.bind_ssbo(CAPTURE_BUF_SLOT, &capture_info_buf_);
917 pass.bind_ssbo("list_start_buf", &list_start_buf_);
918 pass.bind_ssbo("list_info_buf", &list_info_buf_);
919 pass.bind_image("cluster_list_img", &cluster_list_tx_);
920 pass.bind_image("virtual_offset_img", &virtual_offset_tx_);
922 pass.dispatch(&dispatch_per_grid_sample_);
923 }
924}
925
927 const float3 &scene_max,
928 const float4x4 &probe_to_world)
929{
930 using namespace blender::math;
931
932 float3 location, scale;
933 Quaternion rotation;
934 to_loc_rot_scale(probe_to_world, location, rotation, scale);
935 /* Remove scale from view matrix. */
936 float4x4 viewinv = from_loc_rot_scale<float4x4>(location, rotation, float3(1.0f));
937 float4x4 viewmat = invert(viewinv);
938
939 /* Compute the intersection between the grid and the scene extents. */
940 float3 extent_min = float3(FLT_MAX);
941 float3 extent_max = float3(-FLT_MAX);
942 for (int x : {0, 1}) {
943 for (int y : {0, 1}) {
944 for (int z : {0, 1}) {
945 float3 ws_corner = scene_min + ((scene_max - scene_min) * float3(x, y, z));
946 float3 ls_corner = transform_point(viewmat, ws_corner);
947 extent_min = min(extent_min, ls_corner);
948 extent_max = max(extent_max, ls_corner);
949 }
950 }
951 }
952 /* Clip distance is added to every axis in both directions, not just Z. */
953 float3 target_extent = scale + clip_distance_;
954 extent_min = max(extent_min, -target_extent);
955 extent_max = min(extent_max, target_extent);
956
957 grid_pixel_extent_ = max(int3(1), int3(surfel_density_ * (extent_max - extent_min)));
958 grid_pixel_extent_ = min(grid_pixel_extent_, int3(16384));
959
960 float3 ls_midpoint = midpoint(extent_min, extent_max);
961 scene_bound_sphere_ = float4(transform_point(viewinv, ls_midpoint),
962 distance(extent_min, extent_max) / 2.0f);
963
964 /* We could use multi-view rendering here to avoid multiple submissions but it is unlikely to
965 * make any difference. The bottleneck is still the light propagation loop. */
966 auto sync_view = [&](View &view, CartesianBasis basis) {
967 float4x4 capture_viewinv = viewinv * from_rotation<float4x4>(basis);
968
969 float3 capture_extent_min = transform_point(invert(basis), extent_min);
970 float3 capture_extent_max = transform_point(invert(basis), extent_max);
971
972 float4x4 capture_winmat = projection::orthographic(capture_extent_min.x,
973 capture_extent_max.x,
974 capture_extent_min.y,
975 capture_extent_max.y,
976 -capture_extent_min.z,
977 -capture_extent_max.z);
978
979 view.visibility_test(false);
980 view.sync(invert(capture_viewinv), capture_winmat);
981 };
982
983 sync_view(view_x_, basis_x_);
984 sync_view(view_y_, basis_y_);
985 sync_view(view_z_, basis_z_);
986}
987
988void IrradianceBake::surfels_create(const Object &probe_object)
989{
995 using namespace blender::math;
996
998 probe_object);
999
1000 int3 grid_resolution = int3(&lightprobe.grid_resolution_x);
1001 float4x4 grid_local_to_world = invert(probe_object.world_to_object());
1002 float3 grid_scale = math::to_scale(probe_object.object_to_world());
1003
1004 /* TODO(fclem): Options. */
1005 capture_info_buf_.capture_world_direct = capture_world_;
1006 capture_info_buf_.capture_world_indirect = capture_world_ && capture_indirect_;
1007 capture_info_buf_.capture_visibility_direct = !capture_world_;
1008 capture_info_buf_.capture_visibility_indirect = !(capture_world_ && capture_indirect_);
1009 capture_info_buf_.capture_indirect = capture_indirect_;
1010 capture_info_buf_.capture_emission = capture_emission_;
1011
1012 LightProbeModule &light_probes = inst_.light_probes;
1013 SphereProbeData &world_data = *static_cast<SphereProbeData *>(&light_probes.world_sphere_);
1014 capture_info_buf_.world_atlas_coord = world_data.atlas_coord;
1015
1016 dispatch_per_grid_sample_ = math::divide_ceil(grid_resolution, int3(IRRADIANCE_GRID_GROUP_SIZE));
1017 capture_info_buf_.irradiance_grid_size = grid_resolution;
1018 capture_info_buf_.irradiance_grid_local_to_world = grid_local_to_world;
1019 capture_info_buf_.irradiance_grid_world_to_local = probe_object.world_to_object();
1020 capture_info_buf_.irradiance_grid_world_to_local_rotation = float4x4(
1021 invert(normalize(float3x3(grid_local_to_world))));
1022
1023 capture_info_buf_.min_distance_to_surface = min_distance_to_surface_;
1024 capture_info_buf_.max_virtual_offset = max_virtual_offset_;
1025 capture_info_buf_.surfel_radius = 0.5f / surfel_density_;
1026 /* Make virtual offset distances scale relative. */
1027 float min_distance_between_grid_samples = math::reduce_min(grid_scale / float3(grid_resolution));
1028 capture_info_buf_.min_distance_to_surface *= min_distance_between_grid_samples;
1029 capture_info_buf_.max_virtual_offset *= min_distance_between_grid_samples;
1030 capture_info_buf_.clamp_direct = (lightprobe.grid_clamp_direct > 0.0) ?
1031 lightprobe.grid_clamp_direct :
1032 1e20f;
1033 capture_info_buf_.clamp_indirect = (lightprobe.grid_clamp_indirect > 0.0) ?
1034 lightprobe.grid_clamp_indirect :
1035 1e20f;
1036
1039
1040 /* 32bit float is needed here otherwise we loose too much energy from rounding error during the
1041 * accumulation when the sample count is above 500. */
1042 irradiance_L0_tx_.ensure_3d(
1043 gpu::TextureFormat::SFLOAT_32_32_32_32, grid_resolution, texture_usage);
1044 irradiance_L1_a_tx_.ensure_3d(
1045 gpu::TextureFormat::SFLOAT_32_32_32_32, grid_resolution, texture_usage);
1046 irradiance_L1_b_tx_.ensure_3d(
1047 gpu::TextureFormat::SFLOAT_32_32_32_32, grid_resolution, texture_usage);
1048 irradiance_L1_c_tx_.ensure_3d(
1049 gpu::TextureFormat::SFLOAT_32_32_32_32, grid_resolution, texture_usage);
1050 validity_tx_.ensure_3d(gpu::TextureFormat::SFLOAT_32, grid_resolution, texture_usage);
1051 virtual_offset_tx_.ensure_3d(
1052 gpu::TextureFormat::SFLOAT_16_16_16_16, grid_resolution, texture_usage);
1053
1054 if (!irradiance_L0_tx_.is_valid() || !irradiance_L1_a_tx_.is_valid() ||
1055 !irradiance_L1_b_tx_.is_valid() || !irradiance_L1_c_tx_.is_valid() ||
1056 !validity_tx_.is_valid() || !virtual_offset_tx_.is_valid())
1057 {
1058 inst_.info_append_i18n("Error: Not enough memory to bake {}.", probe_object.id.name);
1059 do_break_ = true;
1060 return;
1061 }
1062
1063 irradiance_L0_tx_.clear(float4(0.0f));
1064 irradiance_L1_a_tx_.clear(float4(0.0f));
1065 irradiance_L1_b_tx_.clear(float4(0.0f));
1066 irradiance_L1_c_tx_.clear(float4(0.0f));
1067 validity_tx_.clear(float4(0.0f));
1068 virtual_offset_tx_.clear(float4(0.0f));
1069
1070 GPU_debug_group_begin("IrradianceBake.SceneBounds");
1071
1072 {
1073 draw::Manager &manager = *inst_.manager;
1074 PassSimple &pass = irradiance_bounds_ps_;
1075 pass.init();
1076 pass.shader_set(inst_.shaders.static_shader_get(LIGHTPROBE_IRRADIANCE_BOUNDS));
1077 pass.bind_ssbo("capture_info_buf", &capture_info_buf_);
1078 pass.bind_ssbo("bounds_buf", &manager.bounds_buf.current());
1079 pass.push_constant("resource_len", int(manager.resource_handle_count()));
1080 pass.dispatch(
1082 }
1083
1084 /* Raster the scene to query the number of surfel needed. */
1085 capture_info_buf_.do_surfel_count = false;
1086 capture_info_buf_.do_surfel_output = false;
1087
1088 const int neg_flt_max = int(0xFF7FFFFFu ^ 0x7FFFFFFFu); /* floatBitsToOrderedInt(-FLT_MAX) */
1089 const int pos_flt_max = 0x7F7FFFFF; /* floatBitsToOrderedInt(FLT_MAX) */
1090 capture_info_buf_.scene_bound_x_min = pos_flt_max;
1091 capture_info_buf_.scene_bound_y_min = pos_flt_max;
1092 capture_info_buf_.scene_bound_z_min = pos_flt_max;
1093 capture_info_buf_.scene_bound_x_max = neg_flt_max;
1094 capture_info_buf_.scene_bound_y_max = neg_flt_max;
1095 capture_info_buf_.scene_bound_z_max = neg_flt_max;
1096
1097 capture_info_buf_.push_update();
1098
1099 inst_.manager->submit(irradiance_bounds_ps_);
1100
1102 capture_info_buf_.read();
1103
1104 if (capture_info_buf_.scene_bound_x_min == pos_flt_max) {
1105 /* No valid object has been found. */
1106 do_break_ = true;
1107 return;
1108 }
1109
1110 auto ordered_int_bits_to_float = [](int32_t int_value) -> float {
1111 int32_t float_bits = (int_value < 0) ? (int_value ^ 0x7FFFFFFF) : int_value;
1112 return *reinterpret_cast<float *>(&float_bits);
1113 };
1114
1115 float3 scene_min = float3(ordered_int_bits_to_float(capture_info_buf_.scene_bound_x_min),
1116 ordered_int_bits_to_float(capture_info_buf_.scene_bound_y_min),
1117 ordered_int_bits_to_float(capture_info_buf_.scene_bound_z_min));
1118 float3 scene_max = float3(ordered_int_bits_to_float(capture_info_buf_.scene_bound_x_max),
1119 ordered_int_bits_to_float(capture_info_buf_.scene_bound_y_max),
1120 ordered_int_bits_to_float(capture_info_buf_.scene_bound_z_max));
1121 /* To avoid loosing any surface to the clipping planes, add some padding. */
1122 float epsilon = 1.0f / surfel_density_;
1123 scene_min -= epsilon;
1124 scene_max += epsilon;
1125 surfel_raster_views_sync(scene_min, scene_max, probe_object.object_to_world());
1126
1128
1129 /* WORKAROUND: Sync camera with correct bounds for light culling. */
1130 inst_.camera.sync();
1131 /* WORKAROUND: Sync shadows tile-maps count again with new camera bounds. Fixes issues with sun
1132 * lights. */
1133 inst_.shadows.end_sync();
1134 inst_.lights.end_sync();
1135
1136 GPU_debug_group_begin("IrradianceBake.SurfelsCount");
1137
1138 /* Raster the scene to query the number of surfel needed. */
1139 capture_info_buf_.do_surfel_count = true;
1140 capture_info_buf_.do_surfel_output = false;
1141 capture_info_buf_.surfel_len = 0u;
1142 capture_info_buf_.push_update();
1143
1144 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_x_), grid_pixel_extent_).xy()));
1145 inst_.pipelines.capture.render(view_x_);
1146 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_y_), grid_pixel_extent_).xy()));
1147 inst_.pipelines.capture.render(view_y_);
1148 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_z_), grid_pixel_extent_).xy()));
1149 inst_.pipelines.capture.render(view_z_);
1150
1152
1153 /* Allocate surfel pool. */
1155 capture_info_buf_.read();
1156 if (capture_info_buf_.surfel_len == 0) {
1157 /* No surfel to allocate. */
1158 return;
1159 }
1160
1161 if (capture_info_buf_.surfel_len > surfels_buf_.size()) {
1162 CLOG_INFO(
1163 &Instance::log, "IrradianceBake: Allocating %u surfels.", capture_info_buf_.surfel_len);
1164
1165 size_t max_size = GPU_max_storage_buffer_size();
1167 int total_mem_kb, free_mem_kb;
1168 GPU_mem_stats_get(&total_mem_kb, &free_mem_kb);
1169 /* Leave at least 128MByte for OS and stuffs.
1170 * Try to avoid crashes because of OUT_OF_MEMORY errors. */
1171 size_t max_alloc = (size_t(total_mem_kb) - 128 * 1024) * 1024;
1172 /* Cap to 95% of available memory. */
1173 size_t max_free = size_t((size_t(free_mem_kb) * 1024) * 0.95f);
1174
1175 max_size = min(max_size, min(max_alloc, max_free));
1176 }
1177
1178 size_t required_mem = sizeof(Surfel) * (capture_info_buf_.surfel_len - surfels_buf_.size());
1179 if (required_mem > max_size) {
1180 const bool is_ssbo_bound = (max_size == GPU_max_storage_buffer_size());
1181 const uint req_mb = required_mem / (1024 * 1024);
1182 const uint max_mb = max_size / (1024 * 1024);
1183
1184 if (is_ssbo_bound) {
1185 inst_.info_append_i18n(
1186 "Cannot allocate enough video memory to bake \"{}\" ({} / {} MBytes).\n"
1187 "Try reducing surfel resolution or capture distance to lower the size of the "
1188 "allocation.",
1189 probe_object.id.name,
1190 req_mb,
1191 max_mb);
1192 }
1193 else {
1194 inst_.info_append_i18n(
1195 "Not enough available video memory to bake \"{}\" ({} / {} MBytes).\n"
1196 "Try reducing surfel resolution or capture distance to lower the size of the "
1197 "allocation.",
1198 probe_object.id.name,
1199 req_mb,
1200 max_mb);
1201 }
1202
1203 if (G.background) {
1204 /* Print something in background mode instead of failing silently. */
1205 fprintf(stderr, "%s", inst_.info_get());
1206 }
1207
1208 do_break_ = true;
1209 return;
1210 }
1211 }
1212
1213 surfels_buf_.resize(capture_info_buf_.surfel_len);
1214 surfels_buf_.clear_to_zero();
1215
1216 dispatch_per_surfel_.x = divide_ceil_u(surfels_buf_.size(), SURFEL_GROUP_SIZE);
1217
1218 GPU_debug_group_begin("IrradianceBake.SurfelsCreate");
1219
1220 /* Raster the scene to generate the surfels. */
1221 capture_info_buf_.do_surfel_count = true;
1222 capture_info_buf_.do_surfel_output = true;
1223 capture_info_buf_.surfel_len = 0u;
1224 capture_info_buf_.push_update();
1225
1226 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_x_), grid_pixel_extent_).xy()));
1227 inst_.pipelines.capture.render(view_x_);
1228 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_y_), grid_pixel_extent_).xy()));
1229 inst_.pipelines.capture.render(view_y_);
1230 empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_z_), grid_pixel_extent_).xy()));
1231 inst_.pipelines.capture.render(view_z_);
1232
1233 /* Sync with any other following pass using the surfel buffer. */
1235 /* Read back so that following push_update will contain correct surfel count. */
1236 capture_info_buf_.read();
1237
1239}
1240
1242{
1243 /* Use the last setup view. This should work since the view is orthographic. */
1244 /* TODO(fclem): Remove this. It is only present to avoid crash inside `shadows.render` */
1245 inst_.render_buffers.acquire(int2(1));
1246 inst_.hiz_buffer.set_source(&inst_.render_buffers.depth_tx);
1247 inst_.shadows.set_view(view_z_, grid_pixel_extent_.xy());
1248 inst_.uniform_data.data.push_update();
1249 inst_.lights.set_view(view_z_, grid_pixel_extent_.xy());
1250 inst_.shadows.render(view_z_, grid_pixel_extent_.xy());
1252 /* There seems to be a synchronization issue with shadow rendering pass. If not waiting, the
1253 * surfels are lit without shadows. Waiting for sync here shouldn't be a huge bottleneck
1254 * anyway. */
1255 GPU_finish();
1256 }
1257 inst_.render_buffers.release();
1258
1259 inst_.manager->submit(surfel_light_eval_ps_, view_z_);
1260}
1261
1263{
1264 if (max_virtual_offset_ == 0.0f) {
1265 return;
1266 }
1269
1270 cluster_list_tx_.ensure_3d(
1271 gpu::TextureFormat::SINT_32, capture_info_buf_.irradiance_grid_size, texture_usage);
1272 cluster_list_tx_.clear(int4(-1));
1273 /* View is not important here. It is only for validation. */
1274 inst_.manager->submit(surfel_cluster_build_ps_, view_z_);
1275}
1276
1278{
1279 if (max_virtual_offset_ == 0.0f) {
1280 /* NOTE: Virtual offset texture should already have been cleared to 0. */
1281 return;
1282 }
1283
1284 inst_.manager->submit(irradiance_offset_ps_, view_z_);
1285
1286 /* Not needed after this point. */
1287 cluster_list_tx_.free();
1288}
1289
1291{
1292 using namespace blender::math;
1293
1294 float2 rand_uv = inst_.sampling.rng_2d_get(eSamplingDimension::SAMPLING_LENS_U);
1295 const float3 ray_direction = Sampling::sample_sphere(rand_uv);
1296 const float3 up = ray_direction;
1297 const float3 forward = cross(up, normalize(orthogonal(up)));
1298 const float4x4 viewinv = from_orthonormal_axes<float4x4>(float3(0.0f), forward, up);
1299 const float4x4 viewmat = invert(viewinv);
1300
1301 /* Compute projection bounds. */
1302 float2 min, max;
1303 min = max = transform_point(viewmat, scene_bound_sphere_.xyz()).xy();
1304 min -= scene_bound_sphere_.w;
1305 max += scene_bound_sphere_.w;
1306
1307 /* This avoid light leaking by making sure that for one surface there will always be at least 1
1308 * surfel capture inside a ray list. Since the surface with the maximum distance (after
1309 * projection) between adjacent surfels is a slope that goes through 3 corners of a cube,
1310 * the distance the grid needs to cover is the diagonal of a cube face.
1311 *
1312 * The lower the number the more surfels it clumps together in the same surfel-list.
1313 * Biasing the grid_density like that will create many invalid link between coplanar surfels.
1314 * These are dealt with during the list sorting pass.
1315 *
1316 * This has a side effect of inflating shadows and emissive surfaces.
1317 *
1318 * We add an extra epsilon just in case. We really need this step to be leak free. */
1319 const float max_distance_between_neighbor_surfels_inv = M_SQRT1_2 - 1e-4;
1320 /* Surfel list per unit distance. */
1321 const float ray_grid_density = surfel_density_ * max_distance_between_neighbor_surfels_inv;
1322 /* Surfel list size in unit distance. */
1323 const float pixel_size = 1.0f / ray_grid_density;
1324 list_info_buf_.ray_grid_size = math::max(int2(1), int2(ray_grid_density * (max - min)));
1325
1326 /* Add a 2 pixels margin to have empty lists for irradiance grid samples to fall into (as they
1327 * are not considered by the scene bounds). The first pixel margin is because we are jittering
1328 * the grid position. */
1329 list_info_buf_.ray_grid_size += int2(4);
1330 min -= pixel_size * 2.0f;
1331 max += pixel_size * 2.0f;
1332
1333 /* Randomize grid center to avoid uneven inflating of corners in some directions. */
1334 const float2 aa_rand = inst_.sampling.rng_2d_get(eSamplingDimension::SAMPLING_FILTER_U);
1335 /* Offset in surfel list "pixel". */
1336 const float2 aa_offset = (aa_rand - 0.5f) * 0.499f;
1337 min += pixel_size * aa_offset;
1338
1339 list_info_buf_.list_max = list_info_buf_.ray_grid_size.x * list_info_buf_.ray_grid_size.y;
1340 list_info_buf_.push_update();
1341
1342 /* NOTE: Z values do not really matter since we are not doing any rasterization. */
1343 const float4x4 winmat = projection::orthographic<float>(min.x, max.x, min.y, max.y, 0, 1);
1344
1345 ray_view_.sync(viewmat, winmat);
1346
1347 dispatch_per_list_.x = divide_ceil_u(list_info_buf_.list_max, SURFEL_LIST_GROUP_SIZE);
1348
1349 list_start_buf_.resize(ceil_to_multiple_u(list_info_buf_.list_max, 4));
1350 list_counter_buf_.resize(ceil_to_multiple_u(list_info_buf_.list_max, 4));
1351 list_range_buf_.resize(ceil_to_multiple_u(list_info_buf_.list_max * 2, 4));
1352
1353 list_item_distance_buf_.resize(ceil_to_multiple_u(max_ii(1, capture_info_buf_.surfel_len), 4));
1354 list_item_surfel_id_buf_.resize(ceil_to_multiple_u(max_ii(1, capture_info_buf_.surfel_len), 4));
1355 sorted_surfel_id_buf_.resize(ceil_to_multiple_u(max_ii(1, capture_info_buf_.surfel_len), 4));
1356
1357 GPU_storagebuf_clear(list_counter_buf_, 0);
1358 /* Clear for the case where there are no list or no surfel.
1359 * Otherwise the irradiance_capture stage will have broken lists. */
1360 GPU_storagebuf_clear(list_start_buf_, -1);
1361 inst_.manager->submit(surfel_ray_build_ps_, ray_view_);
1362}
1363
1365{
1366 /* NOTE: Subtract 1 because after `sampling.step()`. */
1367 capture_info_buf_.sample_index = inst_.sampling.sample_index() - 1;
1368 capture_info_buf_.sample_count = inst_.sampling.sample_count();
1369 capture_info_buf_.push_update();
1370
1371 inst_.manager->submit(surfel_light_propagate_ps_, ray_view_);
1372
1373 std::swap(radiance_src_, radiance_dst_);
1374}
1375
1377{
1378 inst_.manager->submit(irradiance_capture_ps_, ray_view_);
1379}
1380
1381void IrradianceBake::read_surfels(LightProbeGridCacheFrame *cache_frame)
1382{
1383 if (!ELEM(inst_.debug_mode,
1388 {
1389 return;
1390 }
1391
1393 capture_info_buf_.read();
1394 surfels_buf_.read();
1395
1396 cache_frame->surfels_len = capture_info_buf_.surfel_len;
1397 cache_frame->surfels = MEM_new_array_uninitialized<Surfel>(cache_frame->surfels_len, __func__);
1398
1399 MutableSpan<Surfel> surfels_dst(static_cast<Surfel *>(cache_frame->surfels),
1400 cache_frame->surfels_len);
1401 Span<Surfel> surfels_src(surfels_buf_.data(), cache_frame->surfels_len);
1402 surfels_dst.copy_from(surfels_src);
1403}
1404
1405void IrradianceBake::read_virtual_offset(LightProbeGridCacheFrame *cache_frame)
1406{
1408 return;
1409 }
1410
1412
1413 cache_frame->baking.virtual_offset = reinterpret_cast<float (*)[4]>(
1414 virtual_offset_tx_.read<float4>(GPU_DATA_FLOAT));
1415}
1416
1418{
1420
1421 read_surfels(cache_frame);
1422 read_virtual_offset(cache_frame);
1423
1424 cache_frame->size[0] = irradiance_L0_tx_.width();
1425 cache_frame->size[1] = irradiance_L0_tx_.height();
1426 cache_frame->size[2] = irradiance_L0_tx_.depth();
1427
1429
1430 cache_frame->baking.L0 = reinterpret_cast<float (*)[4]>(
1431 irradiance_L0_tx_.read<float4>(GPU_DATA_FLOAT));
1432 cache_frame->baking.L1_a = reinterpret_cast<float (*)[4]>(
1433 irradiance_L1_a_tx_.read<float4>(GPU_DATA_FLOAT));
1434 cache_frame->baking.L1_b = reinterpret_cast<float (*)[4]>(
1435 irradiance_L1_b_tx_.read<float4>(GPU_DATA_FLOAT));
1436 cache_frame->baking.L1_c = reinterpret_cast<float (*)[4]>(
1437 irradiance_L1_c_tx_.read<float4>(GPU_DATA_FLOAT));
1438 cache_frame->baking.validity = static_cast<float *>(validity_tx_.read<float>(GPU_DATA_FLOAT));
1439
1440 return cache_frame;
1441}
1442
1444{
1446
1447 read_surfels(cache_frame);
1448 read_virtual_offset(cache_frame);
1449
1450 cache_frame->size[0] = irradiance_L0_tx_.width();
1451 cache_frame->size[1] = irradiance_L0_tx_.height();
1452 cache_frame->size[2] = irradiance_L0_tx_.depth();
1453
1455
1456 cache_frame->baking.L0 = reinterpret_cast<float (*)[4]>(
1457 irradiance_L0_tx_.read<float4>(GPU_DATA_FLOAT));
1458 cache_frame->baking.L1_a = reinterpret_cast<float (*)[4]>(
1459 irradiance_L1_a_tx_.read<float4>(GPU_DATA_FLOAT));
1460 cache_frame->baking.L1_b = reinterpret_cast<float (*)[4]>(
1461 irradiance_L1_b_tx_.read<float4>(GPU_DATA_FLOAT));
1462 cache_frame->baking.L1_c = reinterpret_cast<float (*)[4]>(
1463 irradiance_L1_c_tx_.read<float4>(GPU_DATA_FLOAT));
1464 cache_frame->baking.validity = static_cast<float *>(validity_tx_.read<float>(GPU_DATA_FLOAT));
1465
1466 int64_t sample_count = int64_t(irradiance_L0_tx_.width()) * irradiance_L0_tx_.height() *
1467 irradiance_L0_tx_.depth();
1468 cache_frame->irradiance.L0 = MEM_new_array_uninitialized<float[3]>(sample_count, __func__);
1469 cache_frame->irradiance.L1_a = MEM_new_array_uninitialized<float[3]>(sample_count, __func__);
1470 cache_frame->irradiance.L1_b = MEM_new_array_uninitialized<float[3]>(sample_count, __func__);
1471 cache_frame->irradiance.L1_c = MEM_new_array_uninitialized<float[3]>(sample_count, __func__);
1473 __func__);
1474
1475 cache_frame->visibility.L0 = MEM_new_array_uninitialized<float>(sample_count, __func__);
1476 cache_frame->visibility.L1_a = MEM_new_array_uninitialized<float>(sample_count, __func__);
1477 cache_frame->visibility.L1_b = MEM_new_array_uninitialized<float>(sample_count, __func__);
1478 cache_frame->visibility.L1_c = MEM_new_array_uninitialized<float>(sample_count, __func__);
1479
1480 /* TODO(fclem): This could be done on GPU if that's faster. */
1481 for (auto i : IndexRange(sample_count)) {
1482 copy_v3_v3(cache_frame->irradiance.L0[i], cache_frame->baking.L0[i]);
1483 copy_v3_v3(cache_frame->irradiance.L1_a[i], cache_frame->baking.L1_a[i]);
1484 copy_v3_v3(cache_frame->irradiance.L1_b[i], cache_frame->baking.L1_b[i]);
1485 copy_v3_v3(cache_frame->irradiance.L1_c[i], cache_frame->baking.L1_c[i]);
1486
1487 cache_frame->visibility.L0[i] = cache_frame->baking.L0[i][3];
1488 cache_frame->visibility.L1_a[i] = cache_frame->baking.L1_a[i][3];
1489 cache_frame->visibility.L1_b[i] = cache_frame->baking.L1_b[i][3];
1490 cache_frame->visibility.L1_c[i] = cache_frame->baking.L1_c[i][3];
1492 cache_frame->baking.validity[i]);
1493 }
1494
1495 MEM_SAFE_DELETE(cache_frame->baking.L0);
1496 MEM_SAFE_DELETE(cache_frame->baking.L1_a);
1497 MEM_SAFE_DELETE(cache_frame->baking.L1_b);
1498 MEM_SAFE_DELETE(cache_frame->baking.L1_c);
1499 MEM_SAFE_DELETE(cache_frame->baking.validity);
1500
1501 return cache_frame;
1502}
1503
1505
1506} // namespace blender::eevee
General operations for probes.
#define M_SQRT1_2
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
#define UNPACK3(a)
#define ELEM(...)
btScalar max
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
constexpr IndexRange()=default
constexpr MutableSpan()=default
int64_t size() const
std::reverse_iterator< T * > rbegin()
void append(const T &value)
MutableSpan< T > as_mutable_span()
std::reverse_iterator< T * > rend()
void extend(Span< T > array)
Span< T > as_span() const
SwapChain< ObjectBoundsBuf, 2 > bounds_buf
uint resource_handle_count() const
bool ensure_3d(gpu::TextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
void clear(float4 values)
void visibility_test(bool enable)
Definition draw_view.hh:81
void sync(const float4x4 &view_mat, const float4x4 &win_mat, int view_id=0)
Definition draw_view.cc:27
void bind_resources(U &resources)
Definition draw_pass.hh:459
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, gpu::Texture *image)
PassBase< DrawCommandBufType > & sub(const char *name)
Definition draw_pass.hh:701
void dispatch(int group_len)
void barrier(GPUBarrier type)
void push_constant(const char *name, const float &data)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:509
void info_append(const char *msg, Args &&...args)
LightProbeModule light_probes
void init(const Object &probe_object)
LightProbeGridCacheFrame * read_result_packed()
LightProbeGridCacheFrame * read_result_unpacked()
void surfels_create(const Object &probe_object)
void surfel_raster_views_sync(const float3 &scene_min, const float3 &scene_max, const float4x4 &probe_to_world)
static float3 sample_sphere(const float2 &rand)
Vector< IrradianceBrickPacked > bricks_alloc(int brick_len)
void bricks_free(Vector< IrradianceBrickPacked > &bricks)
void viewport_draw(View &view, gpu::FrameBuffer *view_fb)
#define SURFEL_GROUP_SIZE
#define IRRADIANCE_BOUNDS_GROUP_SIZE
#define RBUFS_UTILITY_TEX_SLOT
#define CAPTURE_BUF_SLOT
#define SURFEL_LIST_GROUP_SIZE
#define IRRADIANCE_GRID_BRICK_SIZE
#define IRRADIANCE_GRID_GROUP_SIZE
#define SURFEL_BUF_SLOT
#define FLT_MAX
VecBase< float, D > normalize(VecOp< float, D >) RET
float distance(float, float) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
int midpoint(int a, int b)
float2x2 invert(float2x2 mat)
float3x3 scale(float3x3 mat, float2 scale)
float2x2 from_rotation(AngleRadian rotation)
float4x4 from_loc_rot_scale(float3 location, EulerXYZ rotation, float3 scale)
float3 transform_point(float3x3 mat, float3 point)
void to_loc_rot_scale(float4x4 mat, float3 &r_location, EulerXYZ &r_rotation, float3 &r_scale)
VecT orthogonal(VecT v)
detail::Pass< command::DrawCommandBuf > PassSimple
@ DEBUG_IRRADIANCE_CACHE_SURFELS_VISIBILITY
@ DEBUG_IRRADIANCE_CACHE_SURFELS_IRRADIANCE
MatBase< T, 4, 4 > orthographic(T left, T right, T bottom, T top, T near_clip, T far_clip)
Create an orthographic projection matrix using OpenGL coordinate convention: Maps each axis range to ...
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
T reduce_max(const VecBase< T, Size > &a)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T reduce_min(const VecBase< T, Size > &a)
CartesianBasis invert(const CartesianBasis &basis)
MatT from_scale(const VecBase< typename MatT::base_type, ScaleDim > &scale)
T reduce_mul(const VecBase< T, Size > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
T max(const T &a, const T &b)
T abs(const T &a)
MatT from_location(const typename MatT::loc_type &location)
CartesianBasis from_orthonormal_axes(const AxisSigned forward, const AxisSigned up)
T determinant(const MatBase< T, Size, Size > &mat)
VecBase< uint32_t, 2 > uint2
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
struct LightProbeGridCacheFrame * BKE_lightprobe_grid_cache_frame_create()
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
VecBase< int32_t, 4 > int4
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool assign_if_different(T &old_value, T &&new_value)
@ GPU_PRIM_TRI_STRIP
MINLINE int max_ii(int a, int b)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
void GPU_mem_stats_get(int *r_totalmem, int *r_freemem)
void GPU_storagebuf_clear(gpu::StorageBuf *ssbo, uint32_t clear_value)
bool GPU_mem_stats_supported()
Global G
Definition blender.cc:57
VecBase< float, 4 > float4
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATOMIC
@ GPU_TEXTURE_USAGE_ATTACHMENT
T & DRW_object_get_data_for_drawing(const Object &object)
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
BMesh const char void * data
size_t GPU_max_storage_buffer_size()
void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
@ GPU_BARRIER_BUFFER_UPDATE
Definition GPU_state.hh:59
@ GPU_BARRIER_TEXTURE_FETCH
Definition GPU_state.hh:40
@ GPU_BARRIER_SHADER_STORAGE
Definition GPU_state.hh:51
@ GPU_BARRIER_TEXTURE_UPDATE
Definition GPU_state.hh:42
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:38
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:45
@ DRW_STATE_CLIP_CONTROL_UNIT_RANGE
Definition draw_state.hh:71
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
MatBase< float, 3, 3 > float3x3
void GPU_debug_group_end()
Definition gpu_debug.cc:34
@ LIGHTPROBE_GRID_CAPTURE_INDIRECT
@ LIGHTPROBE_GRID_CAPTURE_EMISSION
@ LIGHTPROBE_GRID_CAPTURE_WORLD
int64_t BKE_lightprobe_grid_cache_frame_sample_count(const struct LightProbeGridCacheFrame *cache)
MINLINE uint divide_ceil_u(uint a, uint b)
signed int int32_t
Definition BKE_text.h:78
MINLINE uint ceil_to_multiple_u(uint a, uint b)
VecBase< float, 3 > float3
BLI_INLINE void grid_to_world(HairGrid *grid, float vecw[3], const float vec[3])
void GPU_finish()
Definition gpu_state.cc:289
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
#define min(a, b)
Definition sort.cc:38
char name[258]
Definition DNA_ID.h:433
LightProbeConnectivityData connectivity
struct LightProbeGridCacheFrame * grid_static_cache
const LightProbeObjectCache * cache