Blender V5.0
tables.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "scene/tables.h"
6#include "device/device.h"
7#include "scene/scene.h"
8#include "scene/stats.h"
9
10#include "util/log.h"
11#include "util/time.h"
12
14
15/* Lookup Tables */
16
18{
19 need_update_ = true;
20}
21
26
27void LookupTables::device_update(Device * /*unused*/, DeviceScene *dscene, Scene *scene)
28{
29 if (!need_update()) {
30 return;
31 }
32
33 const scoped_callback_timer timer([scene](double time) {
34 if (scene->update_stats) {
35 scene->update_stats->tables.times.add_entry({"device_update", time});
36 }
37 });
38
39 LOG_INFO << "Total " << lookup_tables.size() << " lookup tables.";
40
41 if (!lookup_tables.empty()) {
43 }
44
45 need_update_ = false;
46}
47
48void LookupTables::device_free(Device * /*unused*/, DeviceScene *dscene)
49{
50 dscene->lookup_table.free();
51}
52
54{
55 return need_update_;
56}
57
58static size_t round_up_to_multiple(const size_t size, const size_t chunk)
59{
60 return ((size + chunk - 1) / chunk) * chunk;
61}
62
64{
65 assert(!data.empty());
66
67 need_update_ = true;
68
69 Table new_table;
70 new_table.offset = 0;
72
73 /* find space to put lookup table */
74 list<Table>::iterator table;
75
76 for (table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
77 if (new_table.offset + new_table.size <= table->offset) {
78 lookup_tables.insert(table, new_table);
79 break;
80 }
81 new_table.offset = table->offset + table->size;
82 }
83
84 if (table == lookup_tables.end()) {
85 /* add at the end */
86 lookup_tables.push_back(new_table);
87 dscene->lookup_table.resize(new_table.offset + new_table.size);
88 }
89
90 /* copy table data and return offset */
91 float *dtable = dscene->lookup_table.data();
92 memcpy(dtable + new_table.offset, data.data(), sizeof(float) * data.size());
93
94 return new_table.offset;
95}
96
97void LookupTables::remove_table(size_t *offset)
98{
99 if (*offset == TABLE_OFFSET_INVALID) {
100 /* The table isn't even allocated, so just return here. */
101 return;
102 }
103
104 need_update_ = true;
105
106 list<Table>::iterator table;
107
108 for (table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
109 if (table->offset == *offset) {
110 lookup_tables.erase(table);
111 *offset = TABLE_OFFSET_INVALID;
112 return;
113 }
114 }
115
116 assert(table != lookup_tables.end());
117}
118
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
device_vector< float > lookup_table
Definition devicescene.h:80
void device_free(Device *device, DeviceScene *dscene)
Definition tables.cpp:48
size_t add_table(DeviceScene *dscene, vector< float > &data)
Definition tables.cpp:63
void remove_table(size_t *offset)
Definition tables.cpp:97
list< Table > lookup_tables
void device_update(Device *device, DeviceScene *dscene, Scene *scene)
Definition tables.cpp:27
bool need_update() const
Definition tables.cpp:53
T * resize(const size_t width, const size_t height=0)
#define CCL_NAMESPACE_END
#define assert(assertion)
#define LOG_INFO
Definition log.h:106
@ TABLE_CHUNK_SIZE
@ TABLE_OFFSET_INVALID
unique_ptr< SceneUpdateStats > update_stats
Definition scene.h:175
static size_t round_up_to_multiple(const size_t size, const size_t chunk)
Definition tables.cpp:58
wmTimer * timer