Refactor: Cycles: Replace foreach() by range based for loops

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
This commit is contained in:
Brecht Van Lommel
2024-12-26 19:41:25 +01:00
parent 71b8ecdd84
commit 60bec183cb
65 changed files with 359 additions and 380 deletions

View File

@@ -12,7 +12,6 @@
#include "session/session.h"
#include "util/args.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/path.h"
#include "util/progress.h"
@@ -385,7 +384,7 @@ static void options_parse(int argc, const char **argv)
/* List devices for which support is compiled in. */
vector<DeviceType> types = Device::available_types();
foreach (DeviceType type, types) {
for (DeviceType type : types) {
if (!device_names.empty()) {
device_names += ", ";
}
@@ -474,7 +473,7 @@ static void options_parse(int argc, const char **argv)
vector<DeviceInfo> devices = Device::available_devices();
printf("Devices:\n");
foreach (DeviceInfo &info, devices) {
for (DeviceInfo &info : devices) {
printf(" %-10s%s%s\n",
Device::string_from_type(info.type).c_str(),
info.description.c_str(),

View File

@@ -22,7 +22,6 @@
#include "scene/shader_graph.h"
#include "scene/shader_nodes.h"
#include "util/foreach.h"
#include "util/path.h"
#include "util/projection.h"
#include "util/transform.h"
@@ -71,8 +70,9 @@ static bool xml_read_int_array(vector<int> &value, xml_node node, const char *na
vector<string> tokens;
string_split(tokens, attr.value());
foreach (const string &token, tokens)
for (const string &token : tokens) {
value.push_back(atoi(token.c_str()));
}
return true;
}
@@ -100,8 +100,9 @@ static bool xml_read_float_array(vector<float> &value, xml_node node, const char
vector<string> tokens;
string_split(tokens, attr.value());
foreach (const string &token, tokens)
for (const string &token : tokens) {
value.push_back((float)atof(token.c_str()));
}
return true;
}
@@ -251,10 +252,11 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, xml_node
if (graph_reader.node_map.find(from_node_name) != graph_reader.node_map.end()) {
ShaderNode *fromnode = (ShaderNode *)graph_reader.node_map[from_node_name];
foreach (ShaderOutput *out, fromnode->outputs)
for (ShaderOutput *out : fromnode->outputs) {
if (string_iequals(out->socket_type.name.string(), from_socket_name.string())) {
output = out;
}
}
if (!output) {
fprintf(stderr,
@@ -270,10 +272,11 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, xml_node
if (graph_reader.node_map.find(to_node_name) != graph_reader.node_map.end()) {
ShaderNode *tonode = (ShaderNode *)graph_reader.node_map[to_node_name];
foreach (ShaderInput *in, tonode->inputs)
for (ShaderInput *in : tonode->inputs) {
if (string_iequals(in->socket_type.name.string(), to_socket_name.string())) {
input = in;
}
}
if (!input) {
fprintf(stderr,
@@ -691,7 +694,7 @@ static void xml_read_state(XMLReadState &state, xml_node node)
if (xml_read_string(&shadername, node, "shader")) {
bool found = false;
foreach (Shader *shader, state.scene->shaders) {
for (Shader *shader : state.scene->shaders) {
if (shader->name == shadername) {
state.shader = shader;
found = true;
@@ -710,7 +713,7 @@ static void xml_read_state(XMLReadState &state, xml_node node)
if (xml_read_string(&objectname, node, "object")) {
bool found = false;
foreach (Object *object, state.scene->objects) {
for (Object *object : state.scene->objects) {
if (object->name == objectname) {
state.object = object;
found = true;

View File

@@ -16,7 +16,7 @@
#include "scene/scene.h"
#include "util/color.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"

View File

@@ -6,8 +6,6 @@
#include "blender/session.h"
#include "blender/util.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
enum ComputeDevice {
@@ -63,7 +61,7 @@ void static adjust_device_info_from_preferences(DeviceInfo &info, PointerRNA cpr
void static adjust_device_info(DeviceInfo &device, PointerRNA cpreferences, bool preview)
{
adjust_device_info_from_preferences(device, cpreferences);
foreach (DeviceInfo &info, device.multi_devices) {
for (DeviceInfo &info : device.multi_devices) {
adjust_device_info_from_preferences(info, cpreferences);
/* There is an accumulative logic here, because Multi-devices are supported only for
@@ -139,7 +137,7 @@ DeviceInfo blender_device_info(BL::Preferences &b_preferences,
RNA_BEGIN (&cpreferences, device, "devices") {
if (get_boolean(device, "use")) {
string id = get_string(device, "id");
foreach (DeviceInfo &info, devices) {
for (DeviceInfo &info : devices) {
if (info.id == id) {
used_devices.push_back(info);
break;

View File

@@ -12,7 +12,6 @@
#include "blender/sync.h"
#include "blender/util.h"
#include "util/foreach.h"
#include "util/task.h"
CCL_NAMESPACE_BEGIN
@@ -130,7 +129,7 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
* because the shader needs different geometry attributes. */
bool attribute_recalc = false;
foreach (Node *node, geom->get_used_shaders()) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->need_update_geometry()) {
attribute_recalc = true;

View File

@@ -19,7 +19,7 @@
#include "util/algorithm.h"
#include "util/disjoint_set.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"
#include "util/math.h"

View File

@@ -19,7 +19,6 @@
#include "scene/shader_graph.h"
#include "scene/shader_nodes.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"
#include "util/task.h"
@@ -420,7 +419,7 @@ bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance
}
/* Update attribute values. */
foreach (AttributeRequest &req, requests.requests) {
for (AttributeRequest &req : requests.requests) {
ustring name = req.name;
std::string real_name;
@@ -732,7 +731,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render,
}
/* note iteration over motion_times set happens in sorted order */
foreach (float relative_time, motion_times) {
for (float relative_time : motion_times) {
/* center time is already handled. */
if (relative_time == 0.0f) {
continue;

View File

@@ -9,8 +9,6 @@
#include "blender/sync.h"
#include "blender/util.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
/* Utilities */

View File

@@ -12,8 +12,6 @@
#include "blender/sync.h"
#include "blender/util.h"
#include "util/foreach.h"
#include "DNA_pointcloud_types.h"
#include "BKE_attribute.hh"
@@ -220,7 +218,7 @@ void BlenderSync::sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info
}
pointcloud->attributes.clear();
foreach (Attribute &attr, new_pointcloud.attributes.attributes) {
for (Attribute &attr : new_pointcloud.attributes.attributes) {
pointcloud->attributes.attributes.push_back(std::move(attr));
}

View File

@@ -15,7 +15,7 @@
#include "session/merge.h"
#include "util/debug.h"
#include "util/foreach.h"
#include "util/guiding.h"
#include "util/md5.h"
#include "util/openimagedenoise.h"
@@ -897,7 +897,7 @@ static PyObject *get_device_types_func(PyObject * /*self*/, PyObject * /*args*/)
vector<DeviceType> device_types = Device::available_types();
bool has_cuda = false, has_optix = false, has_hip = false, has_metal = false, has_oneapi = false,
has_hiprt = false;
foreach (DeviceType device_type, device_types) {
for (DeviceType device_type : device_types) {
has_cuda |= (device_type == DEVICE_CUDA);
has_optix |= (device_type == DEVICE_OPTIX);
has_hip |= (device_type == DEVICE_HIP);

View File

@@ -21,7 +21,6 @@
#include "session/buffers.h"
#include "session/session.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"
#include "util/murmurhash.h"

View File

@@ -16,7 +16,6 @@
#include "blender/texture.h"
#include "blender/util.h"
#include "util/foreach.h"
#include "util/set.h"
#include "util/string.h"
#include "util/task.h"
@@ -1474,7 +1473,7 @@ void BlenderSync::resolve_view_layer_attributes(Shader *shader,
{
bool updated = false;
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
if (node->is_a(AttributeNode::node_type)) {
AttributeNode *attr_node = static_cast<AttributeNode *>(node);
@@ -1496,7 +1495,7 @@ void BlenderSync::resolve_view_layer_attributes(Shader *shader,
/* Replace all outgoing links, using appropriate output types. */
float val_avg = (value.x + value.y + value.z) / 3.0f;
foreach (ShaderOutput *output, node->outputs) {
for (ShaderOutput *output : node->outputs) {
float val_float;
float3 val_float3;
@@ -1509,7 +1508,7 @@ void BlenderSync::resolve_view_layer_attributes(Shader *shader,
val_float3 = make_float3(value);
}
foreach (ShaderInput *sock, output->links) {
for (ShaderInput *sock : output->links) {
if (sock->type() == SocketType::FLOAT) {
sock->set(val_float);
}
@@ -1633,7 +1632,7 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
pool.wait_work();
foreach (Shader *shader, updated_shaders) {
for (Shader *shader : updated_shaders) {
shader->tag_update(scene);
}
}

View File

@@ -28,7 +28,7 @@
#include "integrator/denoiser.h"
#include "util/debug.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"

View File

@@ -20,7 +20,7 @@
#include "scene/scene.h"
#include "util/algorithm.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
#include "util/stack_allocator.h"
@@ -411,7 +411,7 @@ void BVHBuild::add_references(BVHRange &root)
/* reserve space for references */
size_t num_alloc_references = 0;
foreach (Object *ob, objects) {
for (Object *ob : objects) {
if (params.top_level) {
if (!ob->is_traceable()) {
continue;
@@ -434,7 +434,7 @@ void BVHBuild::add_references(BVHRange &root)
BoundBox bounds = BoundBox::empty, center = BoundBox::empty;
int i = 0;
foreach (Object *ob, objects) {
for (Object *ob : objects) {
if (params.top_level) {
if (!ob->is_traceable()) {
++i;

View File

@@ -16,7 +16,6 @@
#include "bvh/node.h"
#include "bvh/unaligned.h"
#include "util/foreach.h"
#include "util/progress.h"
CCL_NAMESPACE_BEGIN
@@ -505,7 +504,7 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
size_t pack_leaf_nodes_offset = leaf_nodes_size;
size_t object_offset = 0;
foreach (Geometry *geom, geometry) {
for (Geometry *geom : geometry) {
BVH2 *bvh = static_cast<BVH2 *>(geom->bvh);
if (geom->need_build_bvh(params.bvh_layout)) {
@@ -541,7 +540,7 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
unordered_map<Geometry *, int> geometry_map;
/* merge */
foreach (Object *ob, objects) {
for (Object *ob : objects) {
Geometry *geom = ob->get_geometry();
/* We assume that if mesh doesn't need own BVH it was already included

View File

@@ -31,7 +31,6 @@
# include "scene/object.h"
# include "scene/pointcloud.h"
# include "util/foreach.h"
# include "util/log.h"
# include "util/progress.h"
# include "util/stats.h"
@@ -145,7 +144,7 @@ void BVHEmbree::build(Progress &progress,
rtcSetSceneBuildQuality(scene, build_quality);
int i = 0;
foreach (Object *ob, objects) {
for (Object *ob : objects) {
if (params.top_level) {
if (!ob->is_traceable()) {
++i;
@@ -688,7 +687,7 @@ void BVHEmbree::refit(Progress &progress)
/* Update all vertex buffers, then tell Embree to rebuild/-fit the BVHs. */
unsigned geom_id = 0;
foreach (Object *ob, objects) {
for (Object *ob : objects) {
if (!params.top_level || (ob->is_traceable() && !ob->get_geometry()->is_instanced())) {
Geometry *geom = ob->get_geometry();

View File

@@ -4,8 +4,6 @@
#include "bvh/multi.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
BVHMulti::BVHMulti(const BVHParams &params_,
@@ -17,7 +15,7 @@ BVHMulti::BVHMulti(const BVHParams &params_,
BVHMulti::~BVHMulti()
{
foreach (BVH *bvh, sub_bvhs) {
for (BVH *bvh : sub_bvhs) {
delete bvh;
}
}
@@ -25,7 +23,7 @@ BVHMulti::~BVHMulti()
void BVHMulti::replace_geometry(const vector<Geometry *> &geometry,
const vector<Object *> &objects)
{
foreach (BVH *bvh, sub_bvhs) {
for (BVH *bvh : sub_bvhs) {
bvh->replace_geometry(geometry, objects);
}
}

View File

@@ -37,7 +37,6 @@
#include "session/buffers.h"
#include "util/foreach.h"
#include "util/guiding.h"
#include "util/log.h"
#include "util/progress.h"

View File

@@ -12,7 +12,6 @@
# include "device/cuda/device_impl.h"
# include "util/debug.h"
# include "util/foreach.h"
# include "util/log.h"
# include "util/md5.h"
# include "util/path.h"

View File

@@ -24,7 +24,6 @@
# include <hiprtew.h>
#endif
#include "util/foreach.h"
#include "util/log.h"
#include "util/math.h"
#include "util/string.h"
@@ -230,7 +229,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
devices_initialized_mask |= DEVICE_MASK_CUDA;
}
if (mask & DEVICE_MASK_CUDA) {
foreach (DeviceInfo &info, cuda_devices) {
for (DeviceInfo &info : cuda_devices) {
devices.push_back(info);
}
}
@@ -245,7 +244,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
}
devices_initialized_mask |= DEVICE_MASK_OPTIX;
}
foreach (DeviceInfo &info, optix_devices) {
for (DeviceInfo &info : optix_devices) {
devices.push_back(info);
}
}
@@ -259,7 +258,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
}
devices_initialized_mask |= DEVICE_MASK_HIP;
}
foreach (DeviceInfo &info, hip_devices) {
for (DeviceInfo &info : hip_devices) {
devices.push_back(info);
}
}
@@ -273,7 +272,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
}
devices_initialized_mask |= DEVICE_MASK_ONEAPI;
}
foreach (DeviceInfo &info, oneapi_devices) {
for (DeviceInfo &info : oneapi_devices) {
devices.push_back(info);
}
}
@@ -284,7 +283,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
device_cpu_info(cpu_devices);
devices_initialized_mask |= DEVICE_MASK_CPU;
}
foreach (DeviceInfo &info, cpu_devices) {
for (DeviceInfo &info : cpu_devices) {
devices.push_back(info);
}
}
@@ -297,7 +296,7 @@ vector<DeviceInfo> Device::available_devices(uint mask)
}
devices_initialized_mask |= DEVICE_MASK_METAL;
}
foreach (DeviceInfo &info, metal_devices) {
for (DeviceInfo &info : metal_devices) {
devices.push_back(info);
}
}
@@ -401,7 +400,7 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices,
info.use_hardware_raytracing = false;
info.denoisers = DENOISER_ALL;
foreach (const DeviceInfo &device, subdevices) {
for (const DeviceInfo &device : subdevices) {
/* Ensure CPU device does not slow down GPU. */
if (device.type == DEVICE_CPU && subdevices.size() > 1) {
if (background) {
@@ -561,7 +560,7 @@ void GPUDevice::move_textures_to_host(size_t size, bool for_texture)
bool max_is_image = false;
thread_scoped_lock lock(device_mem_map_mutex);
foreach (MemMap::value_type &pair, device_mem_map) {
for (MemMap::value_type &pair : device_mem_map) {
device_memory &mem = *pair.first;
Mem *cmem = &pair.second;

View File

@@ -12,7 +12,6 @@
# include "device/hip/device_impl.h"
# include "util/debug.h"
# include "util/foreach.h"
# include "util/log.h"
# include "util/md5.h"
# include "util/path.h"

View File

@@ -7,7 +7,6 @@
# include "device/hiprt/device_impl.h"
# include "kernel/device/hiprt/globals.h"
# include "util/foreach.h"
# include "util/log.h"
# include "util/md5.h"
# include "util/path.h"
@@ -882,7 +881,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh,
custom_prim_info_offset.alloc(num_object);
prim_time_offset.alloc(num_object);
foreach (Object *ob, objects) {
for (Object *ob : objects) {
uint32_t mask = 0;
if (ob->is_traceable()) {
mask = ob->visibility_for_tracing();

View File

@@ -14,7 +14,6 @@
#include "scene/geometry.h"
#include "util/foreach.h"
#include "util/list.h"
#include "util/map.h"
@@ -36,7 +35,7 @@ class MultiDevice : public Device {
MultiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
: Device(info, stats, profiler, headless)
{
foreach (const DeviceInfo &subinfo, info.multi_devices) {
for (const DeviceInfo &subinfo : info.multi_devices) {
/* Always add CPU devices at the back since GPU devices can change
* host memory pointers, which CPU uses as device pointer. */
SubDevice *sub;
@@ -55,7 +54,7 @@ class MultiDevice : public Device {
}
/* Build a list of peer islands for the available render devices */
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
/* First ensure that every device is in at least once peer island */
if (sub.peer_island_index < 0) {
peer_islands.emplace_back();
@@ -68,7 +67,7 @@ class MultiDevice : public Device {
}
/* Second check peer access between devices and fill up the islands accordingly */
foreach (SubDevice &peer_sub, devices) {
for (SubDevice &peer_sub : devices) {
if (peer_sub.peer_island_index < 0 &&
peer_sub.device->info.type == sub.device->info.type &&
peer_sub.device->check_peer_access(sub.device))
@@ -82,16 +81,18 @@ class MultiDevice : public Device {
~MultiDevice() override
{
foreach (SubDevice &sub, devices)
for (SubDevice &sub : devices) {
delete sub.device;
}
}
const string &error_message() override
{
error_msg.clear();
foreach (SubDevice &sub, devices)
for (SubDevice &sub : devices) {
error_msg += sub.device->error_message();
}
return error_msg;
}
@@ -100,7 +101,7 @@ class MultiDevice : public Device {
{
BVHLayoutMask bvh_layout_mask = BVH_LAYOUT_ALL;
BVHLayoutMask bvh_layout_mask_all = BVH_LAYOUT_NONE;
foreach (const SubDevice &sub_device, devices) {
for (const SubDevice &sub_device : devices) {
BVHLayoutMask device_bvh_layout_mask = sub_device.device->get_bvh_layout_mask(
kernel_features);
bvh_layout_mask &= device_bvh_layout_mask;
@@ -150,20 +151,22 @@ class MultiDevice : public Device {
bool load_kernels(const uint kernel_features) override
{
foreach (SubDevice &sub, devices)
for (SubDevice &sub : devices) {
if (!sub.device->load_kernels(kernel_features)) {
return false;
}
}
return true;
}
bool load_osl_kernels() override
{
foreach (SubDevice &sub, devices)
for (SubDevice &sub : devices) {
if (!sub.device->load_osl_kernels()) {
return false;
}
}
return true;
}
@@ -190,13 +193,13 @@ class MultiDevice : public Device {
vector<BVHMulti *> geom_bvhs;
geom_bvhs.reserve(bvh->geometry.size());
foreach (Geometry *geom, bvh->geometry) {
for (Geometry *geom : bvh->geometry) {
geom_bvhs.push_back(static_cast<BVHMulti *>(geom->bvh));
}
/* Broadcast acceleration structure build to all render devices */
size_t i = 0;
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
/* Change geometry BVH pointers to the sub BVH */
for (size_t k = 0; k < bvh->geometry.size(); ++k) {
bvh->geometry[k]->bvh = geom_bvhs[k]->sub_bvhs[i];
@@ -266,7 +269,7 @@ class MultiDevice : public Device {
bool is_resident(device_ptr key, Device *sub_device) override
{
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
if (sub.device == sub_device) {
return find_matching_mem_device(key, sub)->device == sub_device;
}
@@ -281,7 +284,7 @@ class MultiDevice : public Device {
/* Get the memory owner of this key (first try current device, then peer devices) */
SubDevice *owner_sub = &sub;
if (owner_sub->ptr_map.find(key) == owner_sub->ptr_map.end()) {
foreach (SubDevice *island_sub, peer_islands[sub.peer_island_index]) {
for (SubDevice *island_sub : peer_islands[sub.peer_island_index]) {
if (island_sub != owner_sub && island_sub->ptr_map.find(key) != island_sub->ptr_map.end())
{
owner_sub = island_sub;
@@ -297,7 +300,7 @@ class MultiDevice : public Device {
/* Get the memory owner of this key or the device with the lowest memory usage when new */
SubDevice *owner_sub = island.front();
foreach (SubDevice *island_sub, island) {
for (SubDevice *island_sub : island) {
if (key ? (island_sub->ptr_map.find(key) != island_sub->ptr_map.end()) :
(island_sub->device->stats.mem_used < owner_sub->device->stats.mem_used))
{
@@ -307,7 +310,7 @@ class MultiDevice : public Device {
return owner_sub;
}
inline device_ptr find_matching_mem(device_ptr key, SubDevice &sub)
device_ptr find_matching_mem(device_ptr key, SubDevice &sub)
{
return find_matching_mem_device(key, sub)->ptr_map[key];
}
@@ -318,7 +321,7 @@ class MultiDevice : public Device {
assert(mem.type == MEM_READ_ONLY || mem.type == MEM_READ_WRITE || mem.type == MEM_DEVICE_ONLY);
/* The remaining memory types can be distributed across devices */
foreach (const vector<SubDevice *> &island, peer_islands) {
for (const vector<SubDevice *> &island : peer_islands) {
SubDevice *owner_sub = find_suitable_mem_device(key, island);
mem.device = owner_sub->device;
mem.device_pointer = 0;
@@ -340,7 +343,7 @@ class MultiDevice : public Device {
size_t existing_size = mem.device_size;
/* The tile buffers are allocated on each device (see below), so copy to all of them */
foreach (const vector<SubDevice *> &island, peer_islands) {
for (const vector<SubDevice *> &island : peer_islands) {
SubDevice *owner_sub = find_suitable_mem_device(existing_key, island);
mem.device = owner_sub->device;
mem.device_pointer = (existing_key) ? owner_sub->ptr_map[existing_key] : 0;
@@ -351,7 +354,7 @@ class MultiDevice : public Device {
if (mem.type == MEM_GLOBAL || mem.type == MEM_TEXTURE) {
/* Need to create texture objects and update pointer in kernel globals on all devices */
foreach (SubDevice *island_sub, island) {
for (SubDevice *island_sub : island) {
if (island_sub != owner_sub) {
island_sub->device->mem_copy_to(mem);
}
@@ -369,7 +372,7 @@ class MultiDevice : public Device {
device_ptr key = mem.device_pointer;
size_t i = 0, sub_h = h / devices.size();
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
size_t sy = y + i * sub_h;
size_t sh = (i == (size_t)devices.size() - 1) ? h - sub_h * i : sub_h;
@@ -391,7 +394,7 @@ class MultiDevice : public Device {
device_ptr key = (existing_key) ? existing_key : unique_key++;
size_t existing_size = mem.device_size;
foreach (const vector<SubDevice *> &island, peer_islands) {
for (const vector<SubDevice *> &island : peer_islands) {
SubDevice *owner_sub = find_suitable_mem_device(existing_key, island);
mem.device = owner_sub->device;
mem.device_pointer = (existing_key) ? owner_sub->ptr_map[existing_key] : 0;
@@ -412,7 +415,7 @@ class MultiDevice : public Device {
size_t existing_size = mem.device_size;
/* Free memory that was allocated for all devices (see above) on each device */
foreach (const vector<SubDevice *> &island, peer_islands) {
for (const vector<SubDevice *> &island : peer_islands) {
SubDevice *owner_sub = find_matching_mem_device(key, *island.front());
mem.device = owner_sub->device;
mem.device_pointer = owner_sub->ptr_map[key];
@@ -423,7 +426,7 @@ class MultiDevice : public Device {
if (mem.type == MEM_TEXTURE) {
/* Free texture objects on all devices */
foreach (SubDevice *island_sub, island) {
for (SubDevice *island_sub : island) {
if (island_sub != owner_sub) {
island_sub->device->mem_free(mem);
}
@@ -439,15 +442,16 @@ class MultiDevice : public Device {
void const_copy_to(const char *name, void *host, size_t size) override
{
foreach (SubDevice &sub, devices)
for (SubDevice &sub : devices) {
sub.device->const_copy_to(name, host, size);
}
}
int device_number(Device *sub_device) override
{
int i = 0;
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
if (sub.device == sub_device) {
return i;
}
@@ -459,7 +463,7 @@ class MultiDevice : public Device {
void foreach_device(const std::function<void(Device *)> &callback) override
{
foreach (SubDevice &sub, devices) {
for (SubDevice &sub : devices) {
sub.device->foreach_device(callback);
}
}

View File

@@ -10,7 +10,6 @@
# include "device/oneapi/device_impl.h"
# include "util/foreach.h"
# include "util/log.h"
# ifdef WITH_EMBREE_GPU
@@ -138,8 +137,9 @@ OneapiDevice::~OneapiDevice()
usm_free(device_queue_, kg_memory_);
usm_free(device_queue_, kg_memory_device_);
for (ConstMemMap::iterator mt = const_mem_map_.begin(); mt != const_mem_map_.end(); mt++)
for (ConstMemMap::iterator mt = const_mem_map_.begin(); mt != const_mem_map_.end(); mt++) {
delete mt->second;
}
if (device_queue_) {
free_queue(device_queue_);

View File

@@ -5,7 +5,6 @@
#include "graph/node.h"
#include "graph/node_type.h"
#include "util/foreach.h"
#include "util/md5.h"
#include "util/param.h"
#include "util/transform.h"
@@ -29,7 +28,7 @@ Node::Node(const NodeType *type_, ustring name_) : name(name_), type(type_)
}
/* initialize default values */
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
set_default_value(socket);
}
}
@@ -563,7 +562,7 @@ bool Node::equals(const Node &other) const
{
assert(type == other.type);
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
if (!equals_value(other, socket)) {
return false;
}
@@ -610,7 +609,7 @@ void Node::hash(MD5Hash &md5)
{
md5.append(type->name.string());
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
md5.append(socket.name.string());
switch (socket.type) {
@@ -713,7 +712,7 @@ template<typename T> size_t array_size_in_bytes(const Node *node, const SocketTy
size_t Node::get_total_size_in_bytes() const
{
size_t total_size = 0;
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
switch (socket.type) {
case SocketType::BOOLEAN:
case SocketType::FLOAT:
@@ -798,7 +797,7 @@ void Node::set_owner(const NodeOwner *owner_)
void Node::dereference_all_used_nodes()
{
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
if (socket.type == SocketType::NODE) {
Node *node = get_socket_value<Node *>(this, socket);

View File

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 */
#include "graph/node_type.h"
#include "util/foreach.h"
#include "util/transform.h"
CCL_NAMESPACE_BEGIN
@@ -181,7 +181,7 @@ void NodeType::register_output(ustring name, ustring ui_name, SocketType::Type t
const SocketType *NodeType::find_input(ustring name) const
{
foreach (const SocketType &socket, inputs) {
for (const SocketType &socket : inputs) {
if (socket.name == name) {
return &socket;
}
@@ -192,7 +192,7 @@ const SocketType *NodeType::find_input(ustring name) const
const SocketType *NodeType::find_output(ustring name) const
{
foreach (const SocketType &socket, outputs) {
for (const SocketType &socket : outputs) {
if (socket.name == name) {
return &socket;
}

View File

@@ -7,7 +7,6 @@
# include "graph/node_xml.h"
# include "graph/node.h"
# include "util/foreach.h"
# include "util/string.h"
# include "util/transform.h"
@@ -50,7 +49,7 @@ void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node)
node->name = ustring(name_attr.value());
}
foreach (const SocketType &socket, node->type->inputs) {
for (const SocketType &socket : node->type->inputs) {
if (socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) {
continue;
}
@@ -240,7 +239,7 @@ xml_node xml_write_node(Node *node, xml_node xml_root)
xml_node.append_attribute("name") = node->name.c_str();
foreach (const SocketType &socket, node->type->inputs) {
for (const SocketType &socket : node->type->inputs) {
if (socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) {
continue;
}

View File

@@ -14,7 +14,6 @@
#include "scene/scene.h"
#include "scene/shader.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
#include "util/transform.h"
@@ -397,7 +396,7 @@ static void concatenate_xform_samples(const MatrixSampleMap &parent_samples,
union_of_samples.insert(pair.first);
}
foreach (chrono_t time, union_of_samples) {
for (chrono_t time : union_of_samples) {
M44d parent_matrix = get_interpolated_matrix_for_time(parent_samples, time);
M44d local_matrix = get_interpolated_matrix_for_time(local_samples, time);
@@ -698,10 +697,10 @@ AttributeRequestSet AlembicObject::get_requested_attributes()
Geometry *geometry = object->get_geometry();
assert(geometry);
foreach (Node *node, geometry->get_used_shaders()) {
for (Node *node : geometry->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
foreach (const AttributeRequest &attr, shader->attributes.requests) {
for (const AttributeRequest &attr : shader->attributes.requests) {
if (!attr.name.empty()) {
requested_attributes.add(attr.name);
}
@@ -797,7 +796,7 @@ AlembicProcedural::~AlembicProcedural()
ccl::set<Object *> objects_set;
ccl::set<AlembicObject *> abc_objects_set;
foreach (Node *node, objects) {
for (Node *node : objects) {
AlembicObject *abc_object = static_cast<AlembicObject *>(node);
if (abc_object->get_object()) {
@@ -835,7 +834,7 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress)
bool need_shader_updates = false;
bool need_data_updates = false;
foreach (Node *object_node, objects) {
for (Node *object_node : objects) {
AlembicObject *object = static_cast<AlembicObject *>(object_node);
if (object->is_modified()) {
@@ -853,7 +852,7 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress)
}
/* Check for changes in shaders (e.g. newly requested attributes). */
foreach (Node *shader_node, object->get_used_shaders()) {
for (Node *shader_node : object->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(shader_node);
if (shader->need_update_geometry()) {
@@ -938,7 +937,7 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress)
build_caches(progress);
foreach (Node *node, objects) {
for (Node *node : objects) {
AlembicObject *object = static_cast<AlembicObject *>(node);
if (progress.get_cancel()) {
@@ -985,7 +984,7 @@ void AlembicProcedural::tag_update(Scene *scene)
AlembicObject *AlembicProcedural::get_or_create_object(const ustring &path)
{
foreach (Node *node, objects) {
for (Node *node : objects) {
AlembicObject *object = static_cast<AlembicObject *>(node);
if (object->get_path() == path) {
@@ -1005,7 +1004,7 @@ void AlembicProcedural::load_objects(Progress &progress)
{
unordered_map<string, AlembicObject *> object_map;
foreach (Node *node, objects) {
for (Node *node : objects) {
AlembicObject *object = static_cast<AlembicObject *>(node);
/* only consider newly added objects */
@@ -1058,7 +1057,7 @@ void AlembicProcedural::load_objects(Progress &progress)
}
/* Share geometries between instances. */
foreach (Node *node, objects) {
for (Node *node : objects) {
AlembicObject *abc_object = static_cast<AlembicObject *>(node);
if (abc_object->instance_of) {

View File

@@ -8,7 +8,6 @@
#include "scene/mesh.h"
#include "scene/pointcloud.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/transform.h"
@@ -495,10 +494,11 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme
Attribute *AttributeSet::find(ustring name) const
{
foreach (const Attribute &attr, attributes)
for (const Attribute &attr : attributes) {
if (attr.name == name) {
return (Attribute *)&attr;
}
}
return nullptr;
}
@@ -676,10 +676,11 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
Attribute *AttributeSet::find(AttributeStandard std) const
{
foreach (const Attribute &attr, attributes)
for (const Attribute &attr : attributes) {
if (attr.std == std) {
return (Attribute *)&attr;
}
}
return nullptr;
}
@@ -746,7 +747,7 @@ void AttributeSet::remove(list<Attribute>::iterator it)
void AttributeSet::resize(bool reserve_only)
{
foreach (Attribute &attr, attributes) {
for (Attribute &attr : attributes) {
attr.resize(geometry, prim, reserve_only);
}
}
@@ -784,7 +785,7 @@ void AttributeSet::update(AttributeSet &&new_attributes)
}
/* Add or update old_attributes based on the new_attributes. */
foreach (Attribute &attr, new_attributes.attributes) {
for (Attribute &attr : new_attributes.attributes) {
Attribute *nattr = add(attr.name, attr.type, attr.element);
nattr->std = attr.std;
nattr->set_data_from(std::move(attr));
@@ -796,7 +797,7 @@ void AttributeSet::update(AttributeSet &&new_attributes)
void AttributeSet::clear_modified()
{
foreach (Attribute &attr, attributes) {
for (Attribute &attr : attributes) {
attr.modified = false;
}
@@ -887,7 +888,7 @@ bool AttributeRequestSet::modified(const AttributeRequestSet &other)
void AttributeRequestSet::add(ustring name)
{
foreach (AttributeRequest &req, requests) {
for (AttributeRequest &req : requests) {
if (req.name == name) {
return;
}
@@ -898,17 +899,18 @@ void AttributeRequestSet::add(ustring name)
void AttributeRequestSet::add(AttributeStandard std)
{
foreach (AttributeRequest &req, requests)
for (AttributeRequest &req : requests) {
if (req.std == std) {
return;
}
}
requests.push_back(AttributeRequest(std));
}
void AttributeRequestSet::add(AttributeRequestSet &reqs)
{
foreach (AttributeRequest &req, reqs.requests) {
for (AttributeRequest &req : reqs.requests) {
if (req.std == ATTR_STD_NONE) {
add(req.name);
}
@@ -936,20 +938,22 @@ void AttributeRequestSet::add_standard(ustring name)
bool AttributeRequestSet::find(ustring name)
{
foreach (AttributeRequest &req, requests)
for (AttributeRequest &req : requests) {
if (req.name == name) {
return true;
}
}
return false;
}
bool AttributeRequestSet::find(AttributeStandard std)
{
foreach (AttributeRequest &req, requests)
for (AttributeRequest &req : requests) {
if (req.std == std) {
return true;
}
}
return false;
}

View File

@@ -12,7 +12,6 @@
#include "scene/shader_nodes.h"
#include "scene/stats.h"
#include "util/foreach.h"
#include "util/math.h"
#include "util/time.h"

View File

@@ -10,8 +10,6 @@
#include "scene/stats.h"
#include "session/buffers.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
bool BakeManager::get_baking() const

View File

@@ -11,7 +11,6 @@
#include "device/device.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/math_cdf.h"
#include "util/tbb.h"

View File

@@ -5,7 +5,6 @@
#include "scene/constant_fold.h"
#include "scene/shader_graph.h"
#include "util/foreach.h"
#include "util/log.h"
CCL_NAMESPACE_BEGIN
@@ -20,7 +19,7 @@ ConstantFolder::ConstantFolder(ShaderGraph *graph,
bool ConstantFolder::all_inputs_constant() const
{
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->link) {
return false;
}
@@ -34,7 +33,7 @@ void ConstantFolder::make_constant(float value) const
VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to constant (" << value
<< ").";
foreach (ShaderInput *sock, output->links) {
for (ShaderInput *sock : output->links) {
sock->set(value);
sock->constant_folded_in = true;
}
@@ -47,7 +46,7 @@ void ConstantFolder::make_constant(float3 value) const
VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to constant " << value
<< ".";
foreach (ShaderInput *sock, output->links) {
for (ShaderInput *sock : output->links) {
sock->set(value);
sock->constant_folded_in = true;
}
@@ -60,7 +59,7 @@ void ConstantFolder::make_constant(int value) const
VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to constant (" << value
<< ").";
foreach (ShaderInput *sock, output->links) {
for (ShaderInput *sock : output->links) {
sock->set(value);
sock->constant_folded_in = true;
}
@@ -124,7 +123,7 @@ void ConstantFolder::bypass(ShaderOutput *new_output) const
graph->disconnect(output);
foreach (ShaderInput *sock, outputs) {
for (ShaderInput *sock : outputs) {
graph->connect(new_output, sock);
}
}
@@ -171,7 +170,7 @@ bool ConstantFolder::try_bypass_or_make_constant(ShaderInput *input, bool clamp)
}
else {
/* disconnect other inputs if we can't fully bypass due to clamp */
foreach (ShaderInput *other, node->inputs) {
for (ShaderInput *other : node->inputs) {
if (other != input && other->link) {
graph->disconnect(other);
}

View File

@@ -4,7 +4,6 @@
#include "scene/curves.h"
#include "util/foreach.h"
#include "util/math.h"
CCL_NAMESPACE_BEGIN

View File

@@ -15,7 +15,7 @@
#include "scene/tables.h"
#include "util/algorithm.h"
#include "util/foreach.h"
#include "util/math.h"
#include "util/math_cdf.h"
#include "util/time.h"
@@ -426,7 +426,7 @@ void Film::device_free(Device * /*device*/, DeviceScene * /*dscene*/, Scene *sce
int Film::get_aov_offset(Scene *scene, string name, bool &is_color)
{
int offset_color = 0, offset_value = 0;
foreach (const Pass *pass, scene->passes) {
for (const Pass *pass : scene->passes) {
if (pass->get_name() == name) {
if (pass->get_type() == PASS_AOV_VALUE) {
is_color = false;
@@ -453,7 +453,7 @@ bool Film::update_lightgroups(Scene *scene)
{
map<ustring, int> lightgroups;
int i = 0;
foreach (const Pass *pass, scene->passes) {
for (const Pass *pass : scene->passes) {
ustring lightgroup = pass->get_lightgroup();
if (!lightgroup.empty()) {
if (!lightgroups.count(lightgroup)) {
@@ -578,9 +578,10 @@ void Film::update_passes(Scene *scene, bool add_sample_count_pass)
if (have_uv_pass != prev_have_uv_pass) {
scene->geometry_manager->tag_update(scene, GeometryManager::UV_PASS_NEEDED);
foreach (Shader *shader, scene->shaders)
for (Shader *shader : scene->shaders) {
shader->need_update_uvs = true;
}
}
if (have_motion_pass != prev_have_motion_pass) {
scene->geometry_manager->tag_update(scene, GeometryManager::MOTION_PASS_NEEDED);
}

View File

@@ -28,7 +28,6 @@
# include "kernel/osl/globals.h"
#endif
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
#include "util/task.h"
@@ -133,7 +132,7 @@ bool Geometry::is_instanced() const
bool Geometry::has_true_displacement() const
{
foreach (Node *node, used_shaders) {
for (Node *node : used_shaders) {
Shader *shader = static_cast<Shader *>(node);
if (shader->has_displacement && shader->get_displacement_method() != DISPLACE_BUMP) {
return true;
@@ -155,7 +154,7 @@ void Geometry::tag_update(Scene *scene, bool rebuild)
scene->light_manager->tag_update(scene, LightManager::MESH_NEED_REBUILD);
}
else {
foreach (Node *node, used_shaders) {
for (Node *node : used_shaders) {
Shader *shader = static_cast<Shader *>(node);
if (shader->emission_sampling != EMISSION_SAMPLING_NONE) {
scene->light_manager->tag_update(scene, LightManager::EMISSIVE_MESH_MODIFIED);
@@ -214,7 +213,7 @@ void GeometryManager::update_osl_globals(Device *device, Scene *scene)
static void update_device_flags_attribute(uint32_t &device_update_flags,
const AttributeSet &attributes)
{
foreach (const Attribute &attr, attributes.attributes) {
for (const Attribute &attr : attributes.attributes) {
if (!attr.modified) {
continue;
}
@@ -284,7 +283,7 @@ void GeometryManager::geom_calc_offset(Scene *scene, BVHLayout bvh_layout)
size_t face_size = 0;
size_t corner_size = 0;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
bool prim_offset_changed = false;
if (geom->is_mesh() || geom->is_volume()) {
@@ -367,7 +366,7 @@ void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Pro
/* Update flags. */
bool volume_images_updated = false;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
geom->has_volume = false;
update_attribute_realloc_flags(device_update_flags, geom->attributes);
@@ -377,7 +376,7 @@ void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Pro
update_attribute_realloc_flags(device_update_flags, mesh->subd_attributes);
}
foreach (Node *node, geom->get_used_shaders()) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->has_volume) {
geom->has_volume = true;
@@ -615,7 +614,7 @@ void GeometryManager::device_update_displacement_images(Device *device,
#ifdef WITH_OSL
bool has_osl_node = false;
#endif
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_modified()) {
/* Geometry-level check for hair shadow transparency.
* This matches the logic in the `Hair::update_shadow_transparency()`, avoiding access to
@@ -626,14 +625,14 @@ void GeometryManager::device_update_displacement_images(Device *device,
need_shadow_transparency = hair->need_shadow_transparency();
}
foreach (Node *node, geom->get_used_shaders()) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
const bool is_true_displacement = (shader->has_displacement &&
shader->get_displacement_method() != DISPLACE_BUMP);
if (!is_true_displacement && !need_shadow_transparency) {
continue;
}
foreach (ShaderNode *node, shader->graph->nodes) {
for (ShaderNode *node : shader->graph->nodes) {
#ifdef WITH_OSL
if (node->special_type == SHADER_SPECIAL_TYPE_OSL) {
has_osl_node = true;
@@ -663,7 +662,7 @@ void GeometryManager::device_update_displacement_images(Device *device,
}
#endif
foreach (int slot, bump_images) {
for (int slot : bump_images) {
pool.push([image_manager, device, scene, slot, &progress] {
image_manager->device_update_slot(device, scene, slot, progress);
});
@@ -678,12 +677,12 @@ void GeometryManager::device_update_volume_images(Device *device, Scene *scene,
ImageManager *image_manager = scene->image_manager;
set<int> volume_images;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (!geom->is_modified()) {
continue;
}
foreach (Attribute &attr, geom->attributes.attributes) {
for (Attribute &attr : geom->attributes.attributes) {
if (attr.element != ATTR_ELEMENT_VOXEL) {
continue;
}
@@ -700,7 +699,7 @@ void GeometryManager::device_update_volume_images(Device *device, Scene *scene,
}
}
foreach (int slot, volume_images) {
for (int slot : volume_images) {
pool.push([image_manager, device, scene, slot, &progress] {
image_manager->device_update_slot(device, scene, slot, progress);
});
@@ -730,7 +729,7 @@ void GeometryManager::device_update(Device *device,
}
});
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_modified()) {
if (geom->is_mesh() || geom->is_volume()) {
Mesh *mesh = static_cast<Mesh *>(geom);
@@ -795,7 +794,7 @@ void GeometryManager::device_update(Device *device,
dicing_camera->update(scene);
size_t i = 0;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (!(geom->is_modified() && geom->is_mesh())) {
continue;
}
@@ -888,7 +887,7 @@ void GeometryManager::device_update(Device *device,
}
});
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_modified()) {
if (geom->is_mesh()) {
Mesh *mesh = static_cast<Mesh *>(geom);
@@ -952,7 +951,7 @@ void GeometryManager::device_update(Device *device,
TaskPool pool;
size_t i = 0;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_modified() || geom->need_update_bvh_for_offset) {
need_update_scene_bvh = true;
pool.push([geom, device, dscene, scene, &progress, i, num_bvh] {
@@ -969,7 +968,7 @@ void GeometryManager::device_update(Device *device,
VLOG_WORK << "Objects BVH build pool statistics:\n" << summary.full_report();
}
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
shader->need_update_uvs = false;
shader->need_update_attribute = false;
shader->need_update_displacement = false;
@@ -985,7 +984,7 @@ void GeometryManager::device_update(Device *device,
scene->update_stats->geometry.times.add_entry({"device_update (compute bounds)", time});
}
});
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
object->compute_bounds(motion_blur);
}
}
@@ -1026,7 +1025,7 @@ void GeometryManager::device_update(Device *device,
/* unset flags */
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
geom->clear_modified();
geom->attributes.clear_modified();
@@ -1127,7 +1126,7 @@ bool GeometryManager::need_update() const
void GeometryManager::collect_statistics(const Scene *scene, RenderStats *stats)
{
foreach (Geometry *geometry, scene->geometry) {
for (Geometry *geometry : scene->geometry) {
stats->mesh.geometry.add_entry(
NamedSizeEntry(string(geometry->name.c_str()), geometry->get_total_size_in_bytes()));
}

View File

@@ -19,7 +19,6 @@
#include "subd/split.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
@@ -35,7 +34,7 @@ bool Geometry::need_attribute(Scene *scene, AttributeStandard std)
return true;
}
foreach (Node *node, used_shaders) {
for (Node *node : used_shaders) {
Shader *shader = static_cast<Shader *>(node);
if (shader->attributes.find(std)) {
return true;
@@ -51,7 +50,7 @@ bool Geometry::need_attribute(Scene * /*scene*/, ustring name)
return false;
}
foreach (Node *node, used_shaders) {
for (Node *node : used_shaders) {
Shader *shader = static_cast<Shader *>(node);
if (shader->attributes.find(name)) {
return true;
@@ -65,7 +64,7 @@ AttributeRequestSet Geometry::needed_attributes()
{
AttributeRequestSet result;
foreach (Node *node, used_shaders) {
for (Node *node : used_shaders) {
Shader *shader = static_cast<Shader *>(node);
result.add(shader->attributes);
}
@@ -75,7 +74,7 @@ AttributeRequestSet Geometry::needed_attributes()
bool Geometry::has_voxel_attributes() const
{
foreach (const Attribute &attr, attributes.attributes) {
for (const Attribute &attr : attributes.attributes) {
if (attr.element == ATTR_ELEMENT_VOXEL) {
return true;
}
@@ -165,7 +164,7 @@ void GeometryManager::update_svm_attributes(Device * /*unused*/,
#ifdef WITH_OSL
size_t attr_count = 0;
foreach (AttributeRequest &req, geom_attributes[i].requests) {
for (AttributeRequest &req : geom_attributes[i].requests) {
if (req.std != ATTR_STD_NONE &&
scene->shader_manager->get_attribute_id(req.std) != (uint64_t)req.std)
{
@@ -214,7 +213,7 @@ void GeometryManager::update_svm_attributes(Device * /*unused*/,
/* set geometry attributes */
size_t index = geom->attr_map_offset;
foreach (AttributeRequest &req, attributes.requests) {
for (AttributeRequest &req : attributes.requests) {
uint64_t id;
if (req.std == ATTR_STD_NONE) {
id = scene->shader_manager->get_attribute_id(req.name);
@@ -247,7 +246,7 @@ void GeometryManager::update_svm_attributes(Device * /*unused*/,
if (attributes.size() > 0) {
size_t index = object->attr_map_offset;
foreach (AttributeRequest &req, attributes.requests) {
for (AttributeRequest &req : attributes.requests) {
uint64_t id;
if (req.std == ATTR_STD_NONE) {
id = scene->shader_manager->get_attribute_id(req.name);
@@ -495,7 +494,7 @@ void GeometryManager::device_update_attributes(Device *device,
geom->index = i;
scene->need_global_attributes(geom_attributes[i]);
foreach (Node *node, geom->get_used_shaders()) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
geom_attributes[i].add(shader->attributes);
}
@@ -554,7 +553,7 @@ void GeometryManager::device_update_attributes(Device *device,
for (size_t i = 0; i < scene->geometry.size(); i++) {
Geometry *geom = scene->geometry[i];
AttributeRequestSet &attributes = geom_attributes[i];
foreach (AttributeRequest &req, attributes.requests) {
for (AttributeRequest &req : attributes.requests) {
Attribute *attr = geom->attributes.find(req);
update_attribute_element_size(geom,
@@ -585,7 +584,7 @@ void GeometryManager::device_update_attributes(Device *device,
for (size_t i = 0; i < scene->objects.size(); i++) {
Object *object = scene->objects[i];
foreach (Attribute &attr, object_attribute_values[i].attributes) {
for (Attribute &attr : object_attribute_values[i].attributes) {
update_attribute_element_size(object->geometry,
&attr,
ATTR_PRIM_GEOMETRY,
@@ -625,7 +624,7 @@ void GeometryManager::device_update_attributes(Device *device,
/* todo: we now store std and name attributes from requests even if
* they actually refer to the same mesh attributes, optimize */
foreach (AttributeRequest &req, attributes.requests) {
for (AttributeRequest &req : attributes.requests) {
Attribute *attr = geom->attributes.find(req);
if (attr) {
@@ -686,7 +685,7 @@ void GeometryManager::device_update_attributes(Device *device,
AttributeRequestSet &attributes = object_attributes[i];
AttributeSet &values = object_attribute_values[i];
foreach (AttributeRequest &req, attributes.requests) {
for (AttributeRequest &req : attributes.requests) {
Attribute *attr = values.find(req);
if (attr) {

View File

@@ -17,7 +17,6 @@
#include "scene/shader.h"
#include "scene/shader_nodes.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"

View File

@@ -22,7 +22,6 @@
#include "subd/patch_table.h"
#include "subd/split.h"
#include "util/foreach.h"
#include "util/progress.h"
CCL_NAMESPACE_BEGIN
@@ -44,7 +43,7 @@ void GeometryManager::device_update_mesh(Device * /*unused*/,
size_t patch_size = 0;
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_mesh() || geom->is_volume()) {
Mesh *mesh = static_cast<Mesh *>(geom);
@@ -93,7 +92,7 @@ void GeometryManager::device_update_mesh(Device * /*unused*/,
dscene->tri_patch.need_realloc() ||
dscene->tri_patch_uv.need_realloc();
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_mesh() || geom->is_volume()) {
Mesh *mesh = static_cast<Mesh *>(geom);
@@ -144,7 +143,7 @@ void GeometryManager::device_update_mesh(Device * /*unused*/,
dscene->curves.need_realloc() ||
dscene->curve_segments.need_realloc();
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_hair()) {
Hair *hair = static_cast<Hair *>(geom);
@@ -178,7 +177,7 @@ void GeometryManager::device_update_mesh(Device * /*unused*/,
float4 *points = dscene->points.alloc(point_size);
uint *points_shader = dscene->points_shader.alloc(point_size);
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_pointcloud()) {
PointCloud *pointcloud = static_cast<PointCloud *>(geom);
pointcloud->pack(
@@ -198,7 +197,7 @@ void GeometryManager::device_update_mesh(Device * /*unused*/,
uint *patch_data = dscene->patches.alloc(patch_size);
foreach (Geometry *geom, scene->geometry) {
for (Geometry *geom : scene->geometry) {
if (geom->is_mesh()) {
Mesh *mesh = static_cast<Mesh *>(geom);
mesh->pack_patches(&patch_data[mesh->patch_offset]);

View File

@@ -10,7 +10,6 @@
#include "scene/scene.h"
#include "scene/stats.h"
#include "util/foreach.h"
#include "util/image.h"
#include "util/image_impl.h"
#include "util/log.h"
@@ -71,7 +70,7 @@ ImageHandle::ImageHandle(const ImageHandle &other)
: tile_slots(other.tile_slots), manager(other.manager)
{
/* Increase image user count. */
foreach (const size_t slot, tile_slots) {
for (const size_t slot : tile_slots) {
manager->add_image_user(slot);
}
}
@@ -82,7 +81,7 @@ ImageHandle &ImageHandle::operator=(const ImageHandle &other)
manager = other.manager;
tile_slots = other.tile_slots;
foreach (const size_t slot, tile_slots) {
for (const size_t slot : tile_slots) {
manager->add_image_user(slot);
}
@@ -96,7 +95,7 @@ ImageHandle::~ImageHandle()
void ImageHandle::clear()
{
foreach (const size_t slot, tile_slots) {
for (const size_t slot : tile_slots) {
manager->remove_image_user(slot);
}
@@ -387,7 +386,7 @@ ImageHandle ImageManager::add_image(const string &filename,
ImageHandle handle;
handle.manager = this;
foreach (int tile, tiles) {
for (int tile : tiles) {
string tile_filename = filename;
/* Since we don't have information about the exact tile format used in this code location,
@@ -922,7 +921,7 @@ void ImageManager::device_free(Device *device)
void ImageManager::collect_statistics(RenderStats *stats)
{
foreach (const Image *image, images) {
for (const Image *image : images) {
if (!image) {
/* Image may have been freed due to lack of users. */
continue;

View File

@@ -18,7 +18,6 @@
#include "kernel/types.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"
#include "util/task.h"
@@ -210,7 +209,7 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene
* transparent shaders in the scene. Otherwise we can disable it
* to improve performance a bit. */
kintegrator->transparent_shadows = false;
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
/* keep this in sync with SD_HAS_TRANSPARENT_SHADOW in shader.cpp */
if ((shader->has_surface_transparent && shader->get_use_transparent_shadow()) ||
shader->has_volume)

View File

@@ -19,7 +19,6 @@
#include "integrator/shader_eval.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/log.h"
#include "util/path.h"
@@ -220,14 +219,14 @@ LightManager::LightManager()
LightManager::~LightManager()
{
foreach (IESSlot *slot, ies_slots) {
for (IESSlot *slot : ies_slots) {
delete slot;
}
}
bool LightManager::has_background_light(Scene *scene)
{
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
if (light->light_type == LIGHT_BACKGROUND && light->is_enabled) {
return true;
}
@@ -242,7 +241,7 @@ void LightManager::test_enabled_lights(Scene *scene)
* got portals or not).
*/
bool has_portal = false, has_background = false;
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
light->is_enabled = light->has_contribution(scene);
has_portal |= light->is_portal;
has_background |= light->light_type == LIGHT_BACKGROUND;
@@ -261,7 +260,7 @@ void LightManager::test_enabled_lights(Scene *scene)
if (disable_mis) {
VLOG_INFO << "Background MIS has been disabled.\n";
}
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
if (light->light_type == LIGHT_BACKGROUND) {
light->is_enabled = !disable_mis;
background_enabled = !disable_mis;
@@ -298,7 +297,7 @@ void LightManager::device_update_distribution(Device * /*unused*/,
const int num_lights = kintegrator->num_lights;
const size_t max_num_triangles = std::numeric_limits<int>::max() - 1 - kintegrator->num_lights;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
if (progress.get_cancel()) {
return;
}
@@ -344,7 +343,7 @@ void LightManager::device_update_distribution(Device * /*unused*/,
size_t offset = 0;
int j = 0;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
if (progress.get_cancel()) {
return;
}
@@ -421,7 +420,7 @@ void LightManager::device_update_distribution(Device * /*unused*/,
if (num_lights > 0) {
float lightarea = (totarea > 0.0f) ? totarea / num_lights : 1.0f;
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
if (!light->is_enabled) {
continue;
}
@@ -951,7 +950,7 @@ void LightManager::device_update_background(Device *device,
bool background_mis = false;
/* find background light */
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
if (light->light_type == LIGHT_BACKGROUND && light->is_enabled) {
background_light = light;
background_mis |= light->use_mis;
@@ -976,7 +975,7 @@ void LightManager::device_update_background(Device *device,
Shader *shader = scene->background->get_shader(scene);
int num_suns = 0;
float sun_average_radiance = 0.0f;
foreach (ShaderNode *node, shader->graph->nodes) {
for (ShaderNode *node : shader->graph->nodes) {
if (node->type == EnvironmentTextureNode::get_node_type()) {
EnvironmentTextureNode *env = (EnvironmentTextureNode *)node;
if (!env->handle.empty()) {
@@ -1125,7 +1124,7 @@ void LightManager::device_update_lights(DeviceScene *dscene, Scene *scene)
size_t num_distant_lights = 0;
bool use_light_mis = false;
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
if (light->is_enabled) {
num_lights++;
@@ -1165,7 +1164,7 @@ void LightManager::device_update_lights(DeviceScene *dscene, Scene *scene)
int light_index = 0;
int portal_index = num_lights;
foreach (Light *light, scene->lights) {
for (Light *light : scene->lights) {
/* Consider moving portals update to their own function
* keeping this one more manageable. */
if (light->is_portal) {
@@ -1560,7 +1559,7 @@ void LightManager::remove_ies(int slot)
void LightManager::device_update_ies(DeviceScene *dscene)
{
/* Clear empty slots. */
foreach (IESSlot *slot, ies_slots) {
for (IESSlot *slot : ies_slots) {
if (slot->users == 0) {
slot->hash = 0;
slot->ies.clear();
@@ -1581,7 +1580,7 @@ void LightManager::device_update_ies(DeviceScene *dscene)
if (!ies_slots.empty()) {
int packed_size = 0;
foreach (IESSlot *slot, ies_slots) {
for (IESSlot *slot : ies_slots) {
packed_size += slot->ies.packed_size();
}

View File

@@ -15,7 +15,6 @@
#include "subd/patch_table.h"
#include "subd/split.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/set.h"

View File

@@ -11,7 +11,6 @@
#include "scene/scene.h"
#include "scene/shader.h"
#include "util/foreach.h"
#include "util/map.h"
#include "util/progress.h"
#include "util/set.h"
@@ -237,7 +236,7 @@ bool GeometryManager::displace(Device *device, Scene *scene, Mesh *mesh, Progres
bool need_recompute_vertex_normals = false;
foreach (Node *node, mesh->get_used_shaders()) {
for (Node *node : mesh->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->has_displacement && shader->get_displacement_method() == DISPLACE_TRUE) {
need_recompute_vertex_normals = true;

View File

@@ -11,7 +11,6 @@
#include "subd/split.h"
#include "util/algorithm.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
@@ -417,7 +416,7 @@ void Mesh::tessellate(DiagSplit *split)
subdivision_type = SUBDIVISION_LINEAR;
/* force disable attribute subdivision for same reason as above */
foreach (Attribute &attr, subd_attributes.attributes) {
for (Attribute &attr : subd_attributes.attributes) {
attr.flags &= ~ATTR_SUBDIVIDED;
}
}
@@ -566,7 +565,7 @@ void Mesh::tessellate(DiagSplit *split)
}
/* interpolate center points for attributes */
foreach (Attribute &attr, subd_attributes.attributes) {
for (Attribute &attr : subd_attributes.attributes) {
#ifdef WITH_OPENSUBDIV
if (subdivision_type == SUBDIVISION_CATMULL_CLARK && attr.flags & ATTR_SUBDIVIDED) {
if (attr.element == ATTR_ELEMENT_CORNER || attr.element == ATTR_ELEMENT_CORNER_BYTE) {

View File

@@ -17,7 +17,6 @@
#include "scene/stats.h"
#include "scene/volume.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/map.h"
#include "util/murmurhash.h"
@@ -236,7 +235,7 @@ void Object::tag_update(Scene *scene)
flag |= ObjectManager::VISIBILITY_MODIFIED;
}
foreach (Node *node, geometry->get_used_shaders()) {
for (Node *node : geometry->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->emission_sampling != EMISSION_SAMPLING_NONE) {
scene->light_manager->tag_update(scene, LightManager::EMISSIVE_MESH_MODIFIED);
@@ -301,7 +300,7 @@ float Object::compute_volume_step_size() const
/* Compute step rate from shaders. */
float step_rate = FLT_MAX;
foreach (Node *node, mesh->get_used_shaders()) {
for (Node *node : mesh->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->has_volume) {
if ((shader->get_heterogeneous_volume() && shader->has_volume_spatial_varying) ||
@@ -322,7 +321,7 @@ float Object::compute_volume_step_size() const
if (geometry->is_volume()) {
Volume *volume = static_cast<Volume *>(geometry);
foreach (Attribute &attr, volume->attributes.attributes) {
for (Attribute &attr : volume->attributes.attributes) {
if (attr.element == ATTR_ELEMENT_VOXEL) {
ImageHandle &handle = attr.data_voxel();
const ImageMetaData &metadata = handle.metadata();
@@ -404,7 +403,7 @@ bool Object::usable_as_light() const
* iterate all geometry shaders twice (when counting and when calculating
* triangle area.
*/
foreach (Node *node, geom->get_used_shaders()) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->emission_sampling != EMISSION_SAMPLING_NONE) {
return true;
@@ -651,7 +650,7 @@ void ObjectManager::device_update_prim_offsets(Device *device, DeviceScene *dsce
/* On MetalRT, primitive / curve segment offsets can't be baked at BVH build time. Intersection
* handlers need to apply the offset manually. */
uint *object_prim_offset = dscene->object_prim_offset.alloc(scene->objects.size());
foreach (Object *ob, scene->objects) {
for (Object *ob : scene->objects) {
uint32_t prim_offset = 0;
if (Geometry *const geom = ob->geometry) {
if (geom->is_hair()) {
@@ -695,7 +694,7 @@ void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene,
uint *motion_offsets = state.motion_offset.resize(scene->objects.size());
uint motion_offset = 0;
foreach (Object *ob, scene->objects) {
for (Object *ob : scene->objects) {
*motion_offsets = motion_offset;
motion_offsets++;
@@ -711,7 +710,7 @@ void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene,
* 0 is dummy particle, index starts at 1.
*/
int numparticles = 1;
foreach (ParticleSystem *psys, scene->particle_systems) {
for (ParticleSystem *psys : scene->particle_systems) {
state.particle_offset[psys] = numparticles;
numparticles += psys->particles.size();
}
@@ -794,7 +793,7 @@ void ObjectManager::device_update(Device *device,
});
int index = 0;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
object->index = index++;
/* this is a bit too broad, however a bigger refactor might be needed to properly separate
@@ -840,7 +839,7 @@ void ObjectManager::device_update(Device *device,
apply_static_transforms(dscene, scene, progress);
}
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
object->clear_modified();
}
}
@@ -882,7 +881,7 @@ void ObjectManager::device_update_flags(Device * /*unused*/,
/* Object volume intersection. */
vector<Object *> volume_objects;
bool has_volume_objects = false;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
if (object->geometry->has_volume) {
/* If the bounds are not valid it is not always possible to calculate the volume step, and
* the step size is not needed for the displacement. So, delay calculation of the volume
@@ -901,12 +900,12 @@ void ObjectManager::device_update_flags(Device * /*unused*/,
}
}
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
if (object->geometry->has_volume) {
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME;
object_flag[object->index] &= ~SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
foreach (Attribute &attr, object->geometry->attributes.attributes) {
for (Attribute &attr : object->geometry->attributes.attributes) {
if (attr.element == ATTR_ELEMENT_VOXEL) {
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
}
@@ -925,7 +924,7 @@ void ObjectManager::device_update_flags(Device * /*unused*/,
if (bounds_valid) {
object->intersects_volume = false;
foreach (Object *volume_object, volume_objects) {
for (Object *volume_object : volume_objects) {
if (object == volume_object) {
continue;
}
@@ -964,7 +963,7 @@ void ObjectManager::device_update_geom_offsets(Device * /*unused*/,
bool update = false;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
Geometry *geom = object->geometry;
if (geom->is_mesh()) {
@@ -1021,7 +1020,7 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, P
bool apply_to_motion = need_motion != Scene::MOTION_PASS;
int i = 0;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
map<Geometry *, int>::iterator it = geometry_users.find(object->geometry);
if (it == geometry_users.end()) {
@@ -1039,7 +1038,7 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, P
uint *object_flag = dscene->object_flag.data();
/* apply transforms for objects with single user geometry */
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
/* Annoying feedback loop here: we can't use is_instanced() because
* it'll use uninitialized transform_applied flag.
*
@@ -1122,7 +1121,7 @@ string ObjectManager::get_cryptomatte_objects(Scene *scene)
string manifest = "{";
unordered_set<ustring> objects;
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
if (objects.count(object->name)) {
continue;
}
@@ -1138,7 +1137,7 @@ string ObjectManager::get_cryptomatte_assets(Scene *scene)
{
string manifest = "{";
unordered_set<ustring> assets;
foreach (Object *ob, scene->objects) {
for (Object *ob : scene->objects) {
if (assets.count(ob->asset_name)) {
continue;
}

View File

@@ -20,7 +20,6 @@
# include "kernel/osl/services.h"
# include "util/aligned_malloc.h"
# include "util/foreach.h"
# include "util/log.h"
# include "util/md5.h"
# include "util/path.h"
@@ -120,7 +119,7 @@ void OSLShaderManager::device_update_specific(Device *device,
/* compile each shader to OSL shader groups */
TaskPool task_pool;
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
assert(shader->graph);
auto compile = [this, scene, shader, background_shader](Device *sub_device) {
@@ -140,7 +139,7 @@ void OSLShaderManager::device_update_specific(Device *device,
}
/* collect shader groups from all shaders */
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
device->foreach_device([shader, background_shader](Device *sub_device) {
OSLGlobals *og = (OSLGlobals *)sub_device->get_cpu_osl_memory();
@@ -172,8 +171,9 @@ void OSLShaderManager::device_update_specific(Device *device,
og->use = true;
});
foreach (Shader *shader, scene->shaders)
for (Shader *shader : scene->shaders) {
shader->clear_modified();
}
update_flags = UPDATE_NONE;
@@ -763,7 +763,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input)
}
/* if output exists with the same name, add "In" suffix */
foreach (ShaderOutput *output, node->outputs) {
for (ShaderOutput *output : node->outputs) {
if (input->name() == output->name()) {
sname += "In";
break;
@@ -784,7 +784,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output)
}
/* if input exists with the same name, add "Out" suffix */
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->name() == output->name()) {
sname += "Out";
break;
@@ -843,7 +843,7 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath)
}
/* pass in fixed parameter values */
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (!input->link) {
/* checks to untangle graphs */
if (node_skip_input(node, input)) {
@@ -904,7 +904,7 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath)
}
/* link inputs to other nodes */
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->link) {
if (node_skip_input(node, input)) {
continue;
@@ -1208,10 +1208,11 @@ void OSLCompiler::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *in
ShaderNode *node = (input->link) ? input->link->parent : nullptr;
if (node != nullptr && dependencies.find(node) == dependencies.end()) {
foreach (ShaderInput *in, node->inputs)
for (ShaderInput *in : node->inputs) {
if (!node_skip_input(node, in)) {
find_dependencies(dependencies, in);
}
}
dependencies.insert(node);
}
@@ -1225,16 +1226,17 @@ void OSLCompiler::generate_nodes(const ShaderNodeSet &nodes)
do {
nodes_done = true;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (done.find(node) == done.end()) {
bool inputs_done = true;
foreach (ShaderInput *input, node->inputs)
for (ShaderInput *input : node->inputs) {
if (!node_skip_input(node, input)) {
if (input->link && done.find(input->link->parent) == done.end()) {
inputs_done = false;
}
}
}
if (inputs_done) {
node->compile(*this);

View File

@@ -7,7 +7,6 @@
#include "scene/scene.h"
#include "scene/stats.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"

View File

@@ -6,7 +6,6 @@
#include "scene/scene.h"
#include "scene/stats.h"
#include "util/foreach.h"
#include "util/progress.h"
CCL_NAMESPACE_BEGIN
@@ -42,7 +41,7 @@ void ProceduralManager::update(Scene *scene, Progress &progress)
}
});
foreach (Procedural *procedural, scene->procedurals) {
for (Procedural *procedural : scene->procedurals) {
if (progress.get_cancel()) {
return;
}

View File

@@ -29,7 +29,6 @@
#include "scene/volume.h"
#include "session/session.h"
#include "util/foreach.h"
#include "util/guarded_allocator.h"
#include "util/log.h"
#include "util/progress.h"
@@ -97,18 +96,24 @@ void Scene::free_memory(bool final)
* Similarly, we first delete all nodes and their associated device data, and then the managers
* and their associated device data.
*/
foreach (Procedural *p, procedurals)
for (Procedural *p : procedurals) {
delete p;
foreach (Object *o, objects)
}
for (Object *o : objects) {
delete o;
foreach (Geometry *g, geometry)
}
for (Geometry *g : geometry) {
delete g;
foreach (ParticleSystem *p, particle_systems)
}
for (ParticleSystem *p : particle_systems) {
delete p;
foreach (Light *l, lights)
}
for (Light *l : lights) {
delete l;
foreach (Pass *p, passes)
}
for (Pass *p : passes) {
delete p;
}
geometry.clear();
objects.clear();
@@ -134,8 +139,9 @@ void Scene::free_memory(bool final)
/* Delete Shaders after every other nodes to ensure that we do not try to decrement the reference
* count on some dangling pointer. */
foreach (Shader *s, shaders)
for (Shader *s : shaders) {
delete s;
}
shaders.clear();
@@ -491,7 +497,7 @@ void Scene::update_kernel_features()
bool has_caustics_caster = false;
bool has_caustics_light = false;
foreach (Object *object, objects) {
for (Object *object : objects) {
if (object->get_is_caustics_caster()) {
has_caustics_caster = true;
}
@@ -529,7 +535,7 @@ void Scene::update_kernel_features()
}
}
foreach (Light *light, lights) {
for (Light *light : lights) {
if (light->get_use_caustics()) {
has_caustics_light = true;
}

View File

@@ -20,7 +20,6 @@
#include "scene/svm.h"
#include "scene/tables.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/murmurhash.h"
#include "util/transform.h"
@@ -236,7 +235,7 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant)
estimate = zero_float3();
}
foreach (const ShaderInput *in, node->inputs) {
for (const ShaderInput *in : node->inputs) {
if (in->type() == SocketType::CLOSURE && in->link) {
estimate += output_estimate_emission(in->link, is_constant);
}
@@ -255,7 +254,7 @@ void Shader::estimate_emission()
/* If the shader has AOVs, they need to be evaluated, so we can't skip the shader. */
emission_is_constant = true;
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
emission_is_constant = false;
}
@@ -350,9 +349,9 @@ void Shader::tag_update(Scene *scene)
if (!has_surface && !has_volume) {
/* If we need to output surface AOVs, add a Transparent BSDF so that the
* surface shader runs. */
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
foreach (const ShaderInput *in, node->inputs) {
for (const ShaderInput *in : node->inputs) {
if (in->link) {
TransparentBsdfNode *transparent = graph->create_node<TransparentBsdfNode>();
graph->add(transparent);
@@ -376,7 +375,7 @@ void Shader::tag_update(Scene *scene)
AttributeRequestSet prev_attributes = attributes;
attributes.clear();
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
node->attributes(this, &attributes);
}
@@ -500,7 +499,7 @@ void ShaderManager::device_update(Device *device,
}
uint id = 0;
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
shader->id = id++;
}
@@ -529,7 +528,7 @@ void ShaderManager::device_update_common(Device * /*device*/,
bool has_volumes = false;
bool has_transparent_shadow = false;
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
uint flag = 0;
if (shader->emission_sampling == EMISSION_SAMPLING_FRONT) {
@@ -743,7 +742,7 @@ uint ShaderManager::get_graph_kernel_features(ShaderGraph *graph)
{
uint kernel_features = 0;
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
kernel_features |= node->get_feature();
if (node->special_type == SHADER_SPECIAL_TYPE_CLOSURE) {
BsdfBaseNode *bsdf_node = static_cast<BsdfBaseNode *>(node);
@@ -818,7 +817,7 @@ string ShaderManager::get_cryptomatte_materials(Scene *scene)
{
string manifest = "{";
unordered_set<ustring> materials;
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
if (materials.count(shader->name)) {
continue;
}

View File

@@ -10,7 +10,7 @@
#include "scene/shader_nodes.h"
#include "util/algorithm.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/md5.h"
#include "util/queue.h"
@@ -21,7 +21,7 @@ namespace {
bool check_node_inputs_has_links(const ShaderNode *node)
{
foreach (const ShaderInput *in, node->inputs) {
for (const ShaderInput *in : node->inputs) {
if (in->link) {
return true;
}
@@ -31,7 +31,7 @@ bool check_node_inputs_has_links(const ShaderNode *node)
bool check_node_inputs_traversed(const ShaderNode *node, const ShaderNodeSet &done)
{
foreach (const ShaderInput *in, node->inputs) {
for (const ShaderInput *in : node->inputs) {
if (in->link) {
if (done.find(in->link->parent) == done.end()) {
return false;
@@ -55,7 +55,7 @@ void ShaderInput::disconnect()
void ShaderOutput::disconnect()
{
foreach (ShaderInput *sock, links) {
for (ShaderInput *sock : links) {
sock->link = nullptr;
}
@@ -76,29 +76,31 @@ ShaderNode::ShaderNode(const NodeType *type) : Node(type)
ShaderNode::~ShaderNode()
{
foreach (ShaderInput *socket, inputs)
for (ShaderInput *socket : inputs) {
delete socket;
}
foreach (ShaderOutput *socket, outputs)
for (ShaderOutput *socket : outputs) {
delete socket;
}
}
void ShaderNode::create_inputs_outputs(const NodeType *type)
{
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
if (socket.flags & SocketType::LINKABLE) {
inputs.push_back(new ShaderInput(socket, this));
}
}
foreach (const SocketType &socket, type->outputs) {
for (const SocketType &socket : type->outputs) {
outputs.push_back(new ShaderOutput(socket, this));
}
}
ShaderInput *ShaderNode::input(const char *name)
{
foreach (ShaderInput *socket, inputs) {
for (ShaderInput *socket : inputs) {
if (socket->name() == name) {
return socket;
}
@@ -109,17 +111,18 @@ ShaderInput *ShaderNode::input(const char *name)
ShaderOutput *ShaderNode::output(const char *name)
{
foreach (ShaderOutput *socket, outputs)
for (ShaderOutput *socket : outputs) {
if (socket->name() == name) {
return socket;
}
}
return nullptr;
}
ShaderInput *ShaderNode::input(ustring name)
{
foreach (ShaderInput *socket, inputs) {
for (ShaderInput *socket : inputs) {
if (socket->name() == name) {
return socket;
}
@@ -130,10 +133,11 @@ ShaderInput *ShaderNode::input(ustring name)
ShaderOutput *ShaderNode::output(ustring name)
{
foreach (ShaderOutput *socket, outputs)
for (ShaderOutput *socket : outputs) {
if (socket->name() == name) {
return socket;
}
}
return nullptr;
}
@@ -147,7 +151,7 @@ void ShaderNode::remove_input(ShaderInput *input)
void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
foreach (ShaderInput *input, inputs) {
for (ShaderInput *input : inputs) {
if (!input->link) {
if (input->flags() & SocketType::LINK_TEXTURE_GENERATED) {
if (shader->has_surface_link()) {
@@ -175,7 +179,7 @@ bool ShaderNode::equals(const ShaderNode &other)
assert(inputs.size() == other.inputs.size());
/* Compare unlinkable sockets */
foreach (const SocketType &socket, type->inputs) {
for (const SocketType &socket : type->inputs) {
if (!(socket.flags & SocketType::LINKABLE)) {
if (!Node::equals_value(other, socket)) {
return false;
@@ -327,7 +331,7 @@ void ShaderGraph::relink(ShaderOutput *from, ShaderOutput *to)
/* Copy because disconnect modifies this list. */
vector<ShaderInput *> outputs = from->links;
foreach (ShaderInput *sock, outputs) {
for (ShaderInput *sock : outputs) {
disconnect(sock);
if (to) {
connect(to, sock);
@@ -343,13 +347,13 @@ void ShaderGraph::relink(ShaderNode *node, ShaderOutput *from, ShaderOutput *to)
vector<ShaderInput *> outputs = from->links;
/* Bypass node by moving all links from "from" to "to" */
foreach (ShaderInput *sock, node->inputs) {
for (ShaderInput *sock : node->inputs) {
if (sock->link) {
disconnect(sock);
}
}
foreach (ShaderInput *sock, outputs) {
for (ShaderInput *sock : outputs) {
disconnect(sock);
if (to) {
connect(to, sock);
@@ -405,8 +409,9 @@ void ShaderGraph::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *in
ShaderNode *node = (input->link) ? input->link->parent : nullptr;
if (node != nullptr && dependencies.find(node) == dependencies.end()) {
foreach (ShaderInput *in, node->inputs)
for (ShaderInput *in : node->inputs) {
find_dependencies(dependencies, in);
}
dependencies.insert(node);
}
@@ -414,7 +419,7 @@ void ShaderGraph::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *in
void ShaderGraph::clear_nodes()
{
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
delete_node(node);
}
nodes.clear();
@@ -426,7 +431,7 @@ void ShaderGraph::copy_nodes(ShaderNodeSet &nodes, ShaderNodeMap &nnodemap)
* made that all nodes that inputs are linked to are in the set too. */
/* copy nodes */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
ShaderNode *nnode = node->clone(this);
nnodemap[node] = nnode;
@@ -439,8 +444,8 @@ void ShaderGraph::copy_nodes(ShaderNodeSet &nodes, ShaderNodeMap &nnodemap)
}
/* recreate links */
foreach (ShaderNode *node, nodes) {
foreach (ShaderInput *input, node->inputs) {
for (ShaderNode *node : nodes) {
for (ShaderInput *input : node->inputs) {
if (input->link) {
/* find new input and output */
ShaderNode *nfrom = nnodemap[input->link->parent];
@@ -468,7 +473,7 @@ void ShaderGraph::remove_proxy_nodes()
vector<bool> removed(num_node_ids, false);
bool any_node_removed = false;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_PROXY) {
ConvertNode *proxy = static_cast<ConvertNode *>(node);
ShaderInput *input = proxy->inputs[0];
@@ -482,7 +487,7 @@ void ShaderGraph::remove_proxy_nodes()
/* Copy because disconnect modifies this list */
vector<ShaderInput *> links(output->links);
foreach (ShaderInput *to, links) {
for (ShaderInput *to : links) {
/* Remove any auto-convert nodes too if they lead to
* sockets with an automatically set default value. */
ShaderNode *tonode = to->parent;
@@ -491,7 +496,7 @@ void ShaderGraph::remove_proxy_nodes()
bool all_links_removed = true;
vector<ShaderInput *> links = tonode->outputs[0]->links;
foreach (ShaderInput *autoin, links) {
for (ShaderInput *autoin : links) {
if (autoin->flags() & SocketType::DEFAULT_LINK_MASK) {
disconnect(autoin);
}
@@ -521,7 +526,7 @@ void ShaderGraph::remove_proxy_nodes()
if (any_node_removed) {
list<ShaderNode *> newnodes;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (!removed[node->id]) {
newnodes.push_back(node);
}
@@ -547,7 +552,7 @@ void ShaderGraph::constant_fold(Scene *scene)
bool has_displacement = (output()->input("Displacement")->link != nullptr);
/* Schedule nodes which doesn't have any dependencies. */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (!check_node_inputs_has_links(node)) {
traverse_queue.push(node);
scheduled.insert(node);
@@ -558,14 +563,14 @@ void ShaderGraph::constant_fold(Scene *scene)
ShaderNode *node = traverse_queue.front();
traverse_queue.pop();
done.insert(node);
foreach (ShaderOutput *output, node->outputs) {
for (ShaderOutput *output : node->outputs) {
if (output->links.empty()) {
continue;
}
/* Schedule node which was depending on the value,
* when possible. Do it before disconnect.
*/
foreach (ShaderInput *input, output->links) {
for (ShaderInput *input : output->links) {
if (scheduled.find(input->parent) != scheduled.end()) {
/* Node might not be optimized yet but scheduled already
* by other dependencies. No need to re-schedule it.
@@ -599,7 +604,7 @@ void ShaderGraph::constant_fold(Scene *scene)
/* Simplification. */
void ShaderGraph::simplify_settings(Scene *scene)
{
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
node->simplify_settings(scene);
}
}
@@ -622,7 +627,7 @@ void ShaderGraph::deduplicate_nodes()
int num_deduplicated = 0;
/* Schedule nodes which doesn't have any dependencies. */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (!check_node_inputs_has_links(node)) {
traverse_queue.push(node);
scheduled.insert(node);
@@ -635,8 +640,8 @@ void ShaderGraph::deduplicate_nodes()
done.insert(node);
/* Schedule the nodes which were depending on the current node. */
bool has_output_links = false;
foreach (ShaderOutput *output, node->outputs) {
foreach (ShaderInput *input, output->links) {
for (ShaderOutput *output : node->outputs) {
for (ShaderInput *input : output->links) {
has_output_links = true;
if (scheduled.find(input->parent) != scheduled.end()) {
/* Node might not be optimized yet but scheduled already
@@ -657,7 +662,7 @@ void ShaderGraph::deduplicate_nodes()
}
/* Try to merge this node with another one. */
ShaderNode *merge_with = nullptr;
foreach (ShaderNode *other_node, candidates[node->type->name]) {
for (ShaderNode *other_node : candidates[node->type->name]) {
if (node != other_node && node->equals(*other_node)) {
merge_with = other_node;
break;
@@ -705,7 +710,7 @@ void ShaderGraph::verify_volume_output()
has_valid_volume = true;
break;
}
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->link == nullptr) {
continue;
}
@@ -727,7 +732,7 @@ void ShaderGraph::break_cycles(ShaderNode *node, vector<bool> &visited, vector<b
visited[node->id] = true;
on_stack[node->id] = true;
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->link) {
ShaderNode *depnode = input->link->parent;
@@ -761,9 +766,9 @@ void ShaderGraph::compute_displacement_hash()
find_dependencies(nodes_displace, displacement_in);
MD5Hash md5;
foreach (ShaderNode *node, nodes_displace) {
for (ShaderNode *node : nodes_displace) {
node->hash(md5);
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
int link_id = (input->link) ? input->link->parent->id : 0;
md5.append((uint8_t *)&link_id, sizeof(link_id));
md5.append((input->link) ? input->link->name().c_str() : "");
@@ -799,16 +804,16 @@ void ShaderGraph::clean(Scene *scene)
/* break cycles */
break_cycles(output(), visited, on_stack);
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
break_cycles(node, visited, on_stack);
}
}
/* disconnect unused nodes */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (!visited[node->id]) {
foreach (ShaderInput *to, node->inputs) {
for (ShaderInput *to : node->inputs) {
ShaderOutput *from = to->link;
if (from) {
@@ -822,7 +827,7 @@ void ShaderGraph::clean(Scene *scene)
/* remove unused nodes */
list<ShaderNode *> newnodes;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (visited[node->id]) {
newnodes.push_back(node);
}
@@ -837,7 +842,7 @@ void ShaderGraph::clean(Scene *scene)
void ShaderGraph::expand()
{
/* Call expand on all nodes, to generate additional nodes. */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
node->expand(this);
}
}
@@ -851,8 +856,8 @@ void ShaderGraph::default_inputs(bool do_osl)
TextureCoordinateNode *texco = nullptr;
VectorTransformNode *normal_transform = nullptr;
foreach (ShaderNode *node, nodes) {
foreach (ShaderInput *input, node->inputs) {
for (ShaderNode *node : nodes) {
for (ShaderInput *input : node->inputs) {
if (!input->link && (!(input->flags() & SocketType::OSL_INTERNAL) || do_osl)) {
if (input->flags() & SocketType::LINK_TEXTURE_GENERATED) {
if (!texco) {
@@ -939,7 +944,7 @@ void ShaderGraph::refine_bump_nodes()
* input to the inputs "center","dx" and "dy" What is in "bump" input is moved
* to "center" input. */
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_BUMP && node->input("Height")->link) {
ShaderInput *bump_input = node->input("Height");
ShaderNodeSet nodes_bump;
@@ -956,12 +961,15 @@ void ShaderGraph::refine_bump_nodes()
/* Mark nodes to indicate they are use for bump computation, so
* that any texture coordinates are shifted by dx/dy when sampling. */
foreach (ShaderNode *node, nodes_bump)
for (ShaderNode *node : nodes_bump) {
node->bump = SHADER_BUMP_CENTER;
foreach (NodePair &pair, nodes_dx)
}
for (NodePair &pair : nodes_dx) {
pair.second->bump = SHADER_BUMP_DX;
foreach (NodePair &pair, nodes_dy)
}
for (NodePair &pair : nodes_dy) {
pair.second->bump = SHADER_BUMP_DY;
}
ShaderOutput *out = bump_input->link;
ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name());
@@ -971,10 +979,12 @@ void ShaderGraph::refine_bump_nodes()
connect(out_dy, node->input("SampleY"));
/* Add generated nodes. */
foreach (NodePair &pair, nodes_dx)
for (NodePair &pair : nodes_dx) {
add(pair.second);
foreach (NodePair &pair, nodes_dy)
}
for (NodePair &pair : nodes_dy) {
add(pair.second);
}
/* Connect what is connected is bump to sample-center input. */
connect(out, node->input("SampleCenter"));
@@ -1023,12 +1033,15 @@ void ShaderGraph::bump_from_displacement(bool use_object_space)
/* mark nodes to indicate they are use for bump computation, so
* that any texture coordinates are shifted by dx/dy when sampling */
foreach (NodePair &pair, nodes_center)
for (NodePair &pair : nodes_center) {
pair.second->bump = SHADER_BUMP_CENTER;
foreach (NodePair &pair, nodes_dx)
}
for (NodePair &pair : nodes_dx) {
pair.second->bump = SHADER_BUMP_DX;
foreach (NodePair &pair, nodes_dy)
}
for (NodePair &pair : nodes_dy) {
pair.second->bump = SHADER_BUMP_DY;
}
/* add set normal node and connect the bump normal output to the set normal
* output, so it can finally set the shader normal, note we are only doing
@@ -1077,12 +1090,15 @@ void ShaderGraph::bump_from_displacement(bool use_object_space)
/* finally, add the copied nodes to the graph. we can't do this earlier
* because we would create dependency cycles in the above loop */
foreach (NodePair &pair, nodes_center)
for (NodePair &pair : nodes_center) {
add(pair.second);
foreach (NodePair &pair, nodes_dx)
}
for (NodePair &pair : nodes_dx) {
add(pair.second);
foreach (NodePair &pair, nodes_dy)
}
for (NodePair &pair : nodes_dy) {
add(pair.second);
}
}
void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight_out, bool volume)
@@ -1179,7 +1195,7 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
int ShaderGraph::get_num_closures()
{
int num_closures = 0;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
ClosureType closure_type = node->get_closure_type();
if (closure_type == CLOSURE_NONE_ID) {
continue;
@@ -1228,12 +1244,12 @@ void ShaderGraph::dump_graph(const char *filename)
fprintf(fd, "rankdir=LR\n");
fprintf(fd, "splines=false\n");
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
fprintf(fd, "// NODE: %p\n", node);
fprintf(fd, "\"%p\" [shape=record,label=\"{", node);
if (!node->inputs.empty()) {
fprintf(fd, "{");
foreach (ShaderInput *socket, node->inputs) {
for (ShaderInput *socket : node->inputs) {
if (socket != node->inputs[0]) {
fprintf(fd, "|");
}
@@ -1253,7 +1269,7 @@ void ShaderGraph::dump_graph(const char *filename)
}
if (!node->outputs.empty()) {
fprintf(fd, "|{");
foreach (ShaderOutput *socket, node->outputs) {
for (ShaderOutput *socket : node->outputs) {
if (socket != node->outputs[0]) {
fprintf(fd, "|");
}
@@ -1264,9 +1280,9 @@ void ShaderGraph::dump_graph(const char *filename)
fprintf(fd, "}\"]");
}
foreach (ShaderNode *node, nodes) {
foreach (ShaderOutput *output, node->outputs) {
foreach (ShaderInput *input, output->links) {
for (ShaderNode *node : nodes) {
for (ShaderOutput *output : node->outputs) {
for (ShaderInput *input : output->links) {
fprintf(fd,
"// CONNECTION: OUT_%p->IN_%p (%s:%s)\n",
output,

View File

@@ -18,7 +18,7 @@
#include "sky_model.h"
#include "util/color.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/transform.h"
@@ -326,8 +326,8 @@ void ImageTextureNode::cull_tiles(Scene *scene, ShaderGraph *graph)
/* TODO(lukas): This is quite inefficient. A fairly simple improvement would
* be to have a cache in each mesh that is indexed by attribute.
* Additionally, building a graph-to-meshes list once could help. */
foreach (Geometry *geom, scene->geometry) {
foreach (Node *node, geom->get_used_shaders()) {
for (Geometry *geom : scene->geometry) {
for (Node *node : geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->graph == graph) {
geom->get_uv_tiles(attribute, used_tiles);
@@ -336,7 +336,7 @@ void ImageTextureNode::cull_tiles(Scene *scene, ShaderGraph *graph)
}
array<int> new_tiles;
foreach (int tile, tiles) {
for (int tile : tiles) {
if (used_tiles.count(tile)) {
new_tiles.push_back_slow(tile);
}

View File

@@ -5,7 +5,7 @@
#include "scene/stats.h"
#include "scene/object.h"
#include "util/algorithm.h"
#include "util/foreach.h"
#include "util/string.h"
CCL_NAMESPACE_BEGIN
@@ -69,7 +69,7 @@ string NamedSizeStats::full_report(int indent_level)
string_human_readable_size(total_size).c_str(),
string_human_readable_number(total_size).c_str());
sort(entries.begin(), entries.end(), namedSizeEntryComparator);
foreach (const NamedSizeEntry &entry, entries) {
for (const NamedSizeEntry &entry : entries) {
result += string_printf("%s%-32s %s (%s)\n",
double_indent.c_str(),
entry.name.c_str(),
@@ -86,7 +86,7 @@ string NamedTimeStats::full_report(int indent_level)
string result;
result += string_printf("%sTotal time: %fs\n", indent.c_str(), total_time);
sort(entries.begin(), entries.end(), namedTimeEntryComparator);
foreach (const NamedTimeEntry &entry, entries) {
for (const NamedTimeEntry &entry : entries) {
result += string_printf(
"%s%-40s %fs\n", double_indent.c_str(), entry.name.c_str(), entry.time);
}
@@ -111,7 +111,7 @@ NamedNestedSampleStats &NamedNestedSampleStats::add_entry(const string &name_, u
void NamedNestedSampleStats::update_sum()
{
sum_samples = self_samples;
foreach (NamedNestedSampleStats &entry, entries) {
for (NamedNestedSampleStats &entry : entries) {
entry.update_sum();
sum_samples += entry.sum_samples;
}
@@ -140,7 +140,7 @@ string NamedNestedSampleStats::full_report(int indent_level, uint64_t total_samp
string result = indent + info;
sort(entries.begin(), entries.end(), namedTimeSampleEntryComparator);
foreach (NamedNestedSampleStats &entry, entries) {
for (NamedNestedSampleStats &entry : entries) {
result += entry.full_report(indent_level + 1, total_samples);
}
return result;
@@ -174,7 +174,7 @@ string NamedSampleCountStats::full_report(int indent_level)
sorted_entries.reserve(entries.size());
uint64_t total_hits = 0, total_samples = 0;
foreach (entry_map::const_reference entry, entries) {
for (entry_map::const_reference entry : entries) {
const NamedSampleCountPair &pair = entry.second;
total_hits += pair.hits;
@@ -187,7 +187,7 @@ string NamedSampleCountStats::full_report(int indent_level)
sort(sorted_entries.begin(), sorted_entries.end(), namedSampleCountPairComparator);
string result;
foreach (const NamedSampleCountPair &entry, sorted_entries) {
for (const NamedSampleCountPair &entry : sorted_entries) {
const double seconds = entry.samples * 0.001;
const double relative = ((double)entry.samples) / (entry.hits * avg_samples_per_hit);
@@ -266,7 +266,7 @@ void RenderStats::collect_profiling(Scene *scene, Profiler &prof)
light.add_entry("Shader Evaluation", prof.get_event(PROFILING_SHADE_LIGHT_EVAL));
shaders.entries.clear();
foreach (Shader *shader, scene->shaders) {
for (Shader *shader : scene->shaders) {
uint64_t samples, hits;
if (prof.get_shader(shader->id, samples, hits)) {
shaders.add(shader->name, samples, hits);
@@ -274,7 +274,7 @@ void RenderStats::collect_profiling(Scene *scene, Profiler &prof)
}
objects.entries.clear();
foreach (Object *object, scene->objects) {
for (Object *object : scene->objects) {
uint64_t samples, hits;
if (prof.get_object(object->get_device_index(), samples, hits)) {
objects.add(object->name, samples, hits);

View File

@@ -14,7 +14,6 @@
#include "scene/stats.h"
#include "scene/svm.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
#include "util/task.h"
@@ -339,32 +338,34 @@ void SVMCompiler::stack_clear_users(ShaderNode *node, ShaderNodeSet &done)
* outputs. this used to work, but was disabled because it gave trouble
* with inputs getting stack positions assigned */
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
ShaderOutput *output = input->link;
if (output && output->stack_offset != SVM_STACK_INVALID) {
bool all_done = true;
/* optimization we should add: verify if in->parent is actually used */
foreach (ShaderInput *in, output->links)
for (ShaderInput *in : output->links) {
if (in->parent != node && done.find(in->parent) == done.end()) {
all_done = false;
}
}
if (all_done) {
stack_clear_offset(output->type(), output->stack_offset);
output->stack_offset = SVM_STACK_INVALID;
foreach (ShaderInput *in, output->links)
for (ShaderInput *in : output->links) {
in->stack_offset = SVM_STACK_INVALID;
}
}
}
}
}
void SVMCompiler::stack_clear_temporary(ShaderNode *node)
{
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (!input->link && input->stack_offset != SVM_STACK_INVALID) {
stack_clear_offset(input->type(), input->stack_offset);
input->stack_offset = SVM_STACK_INVALID;
@@ -431,7 +432,7 @@ void SVMCompiler::find_dependencies(ShaderNodeSet &dependencies,
if (node != nullptr && done.find(node) == done.end() && node != skip_node &&
dependencies.find(node) == dependencies.end())
{
foreach (ShaderInput *in, node->inputs) {
for (ShaderInput *in : node->inputs) {
find_dependencies(dependencies, done, in, skip_node);
}
dependencies.insert(node);
@@ -471,11 +472,11 @@ void SVMCompiler::generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *
do {
nodes_done = true;
foreach (ShaderNode *node, nodes) {
for (ShaderNode *node : nodes) {
if (!done_flag[node->id]) {
bool inputs_done = true;
foreach (ShaderInput *input, node->inputs) {
for (ShaderInput *input : node->inputs) {
if (input->link && !done_flag[input->link->parent->id]) {
inputs_done = false;
}
@@ -503,7 +504,7 @@ void SVMCompiler::generate_closure_node(ShaderNode *node, CompilerState *state)
}
/* execute dependencies for closure */
foreach (ShaderInput *in, node->inputs) {
for (ShaderInput *in : node->inputs) {
if (in->link != nullptr) {
ShaderNodeSet dependencies;
find_dependencies(dependencies, state->nodes_done, in);
@@ -553,7 +554,7 @@ void SVMCompiler::generated_shared_closure_nodes(ShaderNode *root_node,
generate_multi_closure(root_node, node, state);
}
else {
foreach (ShaderInput *in, node->inputs) {
for (ShaderInput *in : node->inputs) {
if (in->type() == SocketType::CLOSURE && in->link) {
generated_shared_closure_nodes(root_node, in->link->parent, state, shared);
}
@@ -565,12 +566,12 @@ void SVMCompiler::find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes,
ShaderGraph *graph,
CompilerState *state)
{
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
OutputAOVNode *aov_node = static_cast<OutputAOVNode *>(node);
if (aov_node->offset >= 0) {
aov_nodes.insert(aov_node);
foreach (ShaderInput *in, node->inputs) {
for (ShaderInput *in : node->inputs) {
if (in->link != nullptr) {
find_dependencies(aov_nodes, state->nodes_done, in);
}
@@ -629,7 +630,7 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
* happens when a node of current subbranch is used by a parent
* node or so */
if (root_node != node) {
foreach (ShaderInput *in, root_node->inputs) {
for (ShaderInput *in : root_node->inputs) {
ShaderNodeSet rootdeps;
find_dependencies(rootdeps, state->nodes_done, in, node);
set_intersection(rootdeps.begin(),
@@ -779,12 +780,14 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
memset((void *)&active_stack, 0, sizeof(active_stack));
current_svm_nodes.clear();
foreach (ShaderNode *node, graph->nodes) {
foreach (ShaderInput *input, node->inputs)
for (ShaderNode *node : graph->nodes) {
for (ShaderInput *input : node->inputs) {
input->stack_offset = SVM_STACK_INVALID;
foreach (ShaderOutput *output, node->outputs)
}
for (ShaderOutput *output : node->outputs) {
output->stack_offset = SVM_STACK_INVALID;
}
}
/* for the bump shader we need add a node to store the shader state */
const bool need_bump_state = (type == SHADER_TYPE_BUMP) &&
@@ -984,7 +987,7 @@ string SVMCompiler::Summary::full_report() const
SVMCompiler::CompilerState::CompilerState(ShaderGraph *graph)
{
int max_id = 0;
foreach (ShaderNode *node, graph->nodes) {
for (ShaderNode *node : graph->nodes) {
max_id = max(node->id, max_id);
}
nodes_done_flag.resize(max_id + 1, false);

View File

@@ -7,8 +7,6 @@
#include "device/device.h"
#include "session/buffers.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
/* --------------------------------------------------------------------

View File

@@ -20,7 +20,6 @@
#include "session/output_driver.h"
#include "session/session.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/math.h"
#include "util/task.h"

View File

@@ -14,7 +14,6 @@
#include "scene/scene.h"
#include "session/session.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/path.h"
#include "util/string.h"

View File

@@ -10,7 +10,7 @@
#include "subd/split.h"
#include "util/algorithm.h"
#include "util/foreach.h"
#include "util/hash.h"
#include "util/math.h"
#include "util/types.h"
@@ -596,7 +596,7 @@ void DiagSplit::post_split()
/* All patches are now split, and all T values known. */
foreach (Edge &edge, edges) {
for (Edge &edge : edges) {
if (edge.second_vert_index < 0) {
edge.second_vert_index = alloc_verts(edge.T - 1);
}
@@ -619,7 +619,7 @@ void DiagSplit::post_split()
using edge_stitch_verts_map_t = unordered_map<pair<int, int>, int, pair_hasher>;
edge_stitch_verts_map_t edge_stitch_verts_map;
foreach (Edge &edge, edges) {
for (Edge &edge : edges) {
if (edge.is_stitch_edge) {
if (edge.stitch_edge_T == 0) {
edge.stitch_edge_T = edge.T;
@@ -633,7 +633,7 @@ void DiagSplit::post_split()
}
/* Set start and end indices for edges generated from a split. */
foreach (Edge &edge, edges) {
for (Edge &edge : edges) {
if (edge.start_vert_index < 0) {
/* Fix up offsets. */
if (edge.top_indices_decrease) {
@@ -655,7 +655,7 @@ void DiagSplit::post_split()
int vert_offset = params.mesh->verts.size();
/* Add verts to stitching map. */
foreach (const Edge &edge, edges) {
for (const Edge &edge : edges) {
if (edge.is_stitch_edge) {
int second_stitch_vert_index = edge_stitch_verts_map[edge.stitch_edge_key];

View File

@@ -49,7 +49,6 @@ set(SRC_HEADERS
deque.h
disjoint_set.h
guarded_allocator.cpp
foreach.h
guarded_allocator.h
guiding.h
half.h

View File

@@ -1,9 +0,0 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#pragma once
/* Nice foreach() loops for STL data structures. */
#define foreach(x, y) for (x : y)

View File

@@ -4,7 +4,6 @@
#include <algorithm>
#include "util/foreach.h"
#include "util/ies.h"
#include "util/math.h"
#include "util/string.h"

View File

@@ -5,7 +5,6 @@
#include <cassert>
#include <thread>
#include "util/foreach.h"
#include "util/profiling.h"
CCL_NAMESPACE_BEGIN
@@ -23,7 +22,7 @@ void Profiler::run()
auto start_time = std::chrono::system_clock::now();
while (!do_stop_worker) {
thread_scoped_lock lock(mutex);
foreach (ProfilingState *state, states) {
for (ProfilingState *state : states) {
uint32_t cur_event = state->event;
int32_t cur_shader = state->shader;
int32_t cur_object = state->object;

View File

@@ -8,7 +8,6 @@
#include <algorithm>
#include <cctype>
#include "util/foreach.h"
#include "util/string.h"
#include "util/types_float4.h"

View File

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 */
#include "util/task.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/time.h"