diff --git a/intern/cycles/app/cycles_precompute.cpp b/intern/cycles/app/cycles_precompute.cpp index bcdb9b7b89f..192da787122 100644 --- a/intern/cycles/app/cycles_precompute.cpp +++ b/intern/cycles/app/cycles_precompute.cpp @@ -2,6 +2,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include + #include "util/string.h" #include "util/array.h" diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp index 325ad15a6fc..5ec06718c5c 100644 --- a/intern/cycles/app/cycles_standalone.cpp +++ b/intern/cycles/app/cycles_standalone.cpp @@ -2,7 +2,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include "device/device.h" #include "scene/camera.h" @@ -13,13 +13,14 @@ #include "util/args.h" #include "util/foreach.h" -#include "util/image.h" #include "util/log.h" #include "util/path.h" #include "util/progress.h" #include "util/string.h" -#include "util/time.h" -#include "util/transform.h" +#ifdef WITH_CYCLES_STANDALONE_GUI +# include "util/time.h" +# include "util/transform.h" +#endif #include "util/unique_ptr.h" #include "util/version.h" @@ -76,12 +77,12 @@ static void session_print_status() double progress = options.session->progress.get_progress(); options.session->progress.get_status(status, substatus); - if (substatus != "") { + if (!substatus.empty()) { status += ": " + substatus; } /* print status */ - status = string_printf("Progress %05.2f %s", (double)progress * 100, status.c_str()); + status = string_printf("Progress %05.2f %s", progress * 100, status.c_str()); session_print(status); } @@ -194,8 +195,9 @@ static void display_info(Progress &progress) progress.get_status(status, substatus); double progress_val = progress.get_progress(); - if (substatus != "") + if (!substatus.empty()) { status += ": " + substatus; + } interactive = options.interactive ? "On" : "Off"; @@ -209,14 +211,15 @@ static void display_info(Progress &progress) status.c_str(), total_time, latency, - (double)progress_val * 100, + progress_val * 100, sample_time, interactive.c_str()); window_display_info(str.c_str()); - if (options.show_help) + if (options.show_help) { window_display_help(); + } } static void display() @@ -275,40 +278,48 @@ static void resize(int width, int height) static void keyboard(unsigned char key) { /* Toggle help */ - if (key == 'h') + if (key == 'h') { options.show_help = !(options.show_help); - /* Reset */ - else if (key == 'r') + /* Reset */ + } + else if (key == 'r') { options.session->reset(options.session_params, session_buffer_params()); - /* Cancel */ - else if (key == 27) // escape + /* Cancel */ + } + else if (key == 27) { // escape options.session->progress.set_cancel("Canceled"); - /* Pause */ + /* Pause */ + } else if (key == 'p') { options.pause = !options.pause; options.session->set_pause(options.pause); } /* Interactive Mode */ - else if (key == 'i') + else if (key == 'i') { options.interactive = !(options.interactive); - /* Navigation */ + /* Navigation */ + } else if (options.interactive && (key == 'w' || key == 'a' || key == 's' || key == 'd')) { Transform matrix = options.session->scene->camera->get_matrix(); float3 translate; - if (key == 'w') + if (key == 'w') { translate = make_float3(0.0f, 0.0f, 0.1f); - else if (key == 's') + } + else if (key == 's') { translate = make_float3(0.0f, 0.0f, -0.1f); - else if (key == 'a') + } + else if (key == 'a') { translate = make_float3(-0.1f, 0.0f, 0.0f); - else if (key == 'd') + } + else if (key == 'd') { translate = make_float3(0.1f, 0.0f, 0.0f); + } matrix = matrix * transform_translate(translate); @@ -368,14 +379,14 @@ static void options_parse(int argc, const char **argv) options.session_params.tile_size = 0; /* device names */ - string device_names = ""; + string device_names; string devicename = "CPU"; bool list = false; /* List devices for which support is compiled in. */ vector types = Device::available_types(); foreach (DeviceType type, types) { - if (device_names != "") { + if (!device_names.empty()) { device_names += ", "; } @@ -476,7 +487,7 @@ static void options_parse(int argc, const char **argv) printf("%s\n", CYCLES_VERSION_STRING); exit(EXIT_SUCCESS); } - else if (help || options.filepath == "") { + else if (help || options.filepath.empty()) { ap.usage(); exit(EXIT_SUCCESS); } @@ -529,7 +540,7 @@ static void options_parse(int argc, const char **argv) fprintf(stderr, "Invalid number of samples: %d\n", options.session_params.samples); exit(EXIT_FAILURE); } - else if (options.filepath == "") { + else if (options.filepath.empty()) { fprintf(stderr, "No file path specified\n"); exit(EXIT_FAILURE); } diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index a69cd62f0dd..19b7ec7d4ed 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -2,11 +2,9 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include -#include -#include #include "graph/node_xml.h" @@ -37,16 +35,15 @@ CCL_NAMESPACE_BEGIN /* XML reading state */ struct XMLReadState : public XMLReader { - Scene *scene; /* Scene pointer. */ - Transform tfm; /* Current transform state. */ - bool smooth; /* Smooth normal state. */ - Shader *shader; /* Current shader. */ - string base; /* Base path to current file. */ - float dicing_rate; /* Current dicing rate. */ - Object *object; /* Current object. */ + Scene *scene = nullptr; /* Scene pointer. */ + Transform tfm; /* Current transform state. */ + bool smooth = false; /* Smooth normal state. */ + Shader *shader = nullptr; /* Current shader. */ + string base; /* Base path to current file. */ + float dicing_rate = 1.0f; /* Current dicing rate. */ + Object *object = nullptr; /* Current object. */ XMLReadState() - : scene(nullptr), smooth(false), shader(nullptr), dicing_rate(1.0f), object(nullptr) { tfm = transform_identity(); } @@ -208,8 +205,7 @@ static void xml_read_alembic(XMLReadState &state, xml_node graph_node) string path; if (xml_read_string(&path, node, "path")) { ustring object_path(path, 0); - AlembicObject *object = static_cast( - proc->get_or_create_object(object_path)); + AlembicObject *object = proc->get_or_create_object(object_path); array used_shaders = object->get_used_shaders(); used_shaders.push_back_slow(state.shader); @@ -347,11 +343,11 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, xml_node fprintf(stderr, "Unknown shader node \"%s\".\n", node.name()); continue; } - else if (node_type->type != NodeType::SHADER) { + if (node_type->type != NodeType::SHADER) { fprintf(stderr, "Node type \"%s\" is not a shader node.\n", node_type->name.c_str()); continue; } - else if (node_type->create == nullptr) { + if (node_type->create == nullptr) { fprintf(stderr, "Can't create abstract node type \"%s\".\n", node_type->name.c_str()); continue; } @@ -412,19 +408,18 @@ static Mesh *xml_add_mesh(Scene *scene, const Transform &tfm, Object *object) Geometry *geometry = object->get_geometry(); return static_cast(geometry); } - else { - /* Create mesh */ - Mesh *mesh = new Mesh(); - scene->geometry.push_back(mesh); - /* Create object. */ - Object *object = new Object(); - object->set_geometry(mesh); - object->set_tfm(tfm); - scene->objects.push_back(object); + /* Create mesh */ + Mesh *mesh = new Mesh(); + scene->geometry.push_back(mesh); - return mesh; - } + /* Create object. */ + object = new Object(); + object->set_geometry(mesh); + object->set_tfm(tfm); + scene->objects.push_back(object); + + return mesh; } static void xml_read_mesh(const XMLReadState &state, xml_node node) @@ -662,7 +657,7 @@ static void xml_read_transform(xml_node node, Transform &tfm) if (node.attribute("matrix")) { vector matrix; if (xml_read_float_array(matrix, node, "matrix") && matrix.size() == 16) { - ProjectionTransform projection = *(ProjectionTransform *)&matrix[0]; + ProjectionTransform projection = *(ProjectionTransform *)matrix.data(); tfm = tfm * projection_to_transform(projection_transpose(projection)); } } diff --git a/intern/cycles/app/oiio_output_driver.cpp b/intern/cycles/app/oiio_output_driver.cpp index 58c0fee343a..6a304473efb 100644 --- a/intern/cycles/app/oiio_output_driver.cpp +++ b/intern/cycles/app/oiio_output_driver.cpp @@ -6,6 +6,9 @@ #include "scene/colorspace.h" +#include "util/image.h" +#include "util/unique_ptr.h" + #include #include @@ -18,7 +21,7 @@ OIIOOutputDriver::OIIOOutputDriver(const string_view filepath, { } -OIIOOutputDriver::~OIIOOutputDriver() {} +OIIOOutputDriver::~OIIOOutputDriver() = default; void OIIOOutputDriver::write_render_tile(const Tile &tile) { diff --git a/intern/cycles/app/oiio_output_driver.h b/intern/cycles/app/oiio_output_driver.h index f7d4f98379a..311b8d02735 100644 --- a/intern/cycles/app/oiio_output_driver.h +++ b/intern/cycles/app/oiio_output_driver.h @@ -6,10 +6,7 @@ #include "session/output_driver.h" -#include "util/image.h" #include "util/string.h" -#include "util/unique_ptr.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -18,7 +15,7 @@ class OIIOOutputDriver : public OutputDriver { using LogFunction = std::function; OIIOOutputDriver(const string_view filepath, const string_view pass, LogFunction log); - virtual ~OIIOOutputDriver(); + ~OIIOOutputDriver() override; void write_render_tile(const Tile &tile) override; diff --git a/intern/cycles/app/opengl/display_driver.cpp b/intern/cycles/app/opengl/display_driver.cpp index e4a4fc8c0ef..692dc22b9e5 100644 --- a/intern/cycles/app/opengl/display_driver.cpp +++ b/intern/cycles/app/opengl/display_driver.cpp @@ -6,7 +6,6 @@ #include "app/opengl/shader.h" #include "util/log.h" -#include "util/string.h" #include #include @@ -23,7 +22,7 @@ OpenGLDisplayDriver::OpenGLDisplayDriver(const std::function &gl_context { } -OpenGLDisplayDriver::~OpenGLDisplayDriver() {} +OpenGLDisplayDriver::~OpenGLDisplayDriver() = default; /* -------------------------------------------------------------------- * Update procedure. @@ -61,8 +60,15 @@ bool OpenGLDisplayDriver::update_begin(const Params ¶ms, int texture_width, if (texture_.width != texture_width || texture_.height != texture_height) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_.gl_id); - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGBA16F, texture_width, texture_height, 0, GL_RGBA, GL_HALF_FLOAT, 0); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA16F, + texture_width, + texture_height, + 0, + GL_RGBA, + GL_HALF_FLOAT, + nullptr); texture_.width = texture_width; texture_.height = texture_height; glBindTexture(GL_TEXTURE_2D, 0); @@ -84,7 +90,7 @@ bool OpenGLDisplayDriver::update_begin(const Params ¶ms, int texture_width, if (texture_.buffer_width != buffer_width || texture_.buffer_height != buffer_height) { const size_t size_in_bytes = sizeof(half4) * buffer_width * buffer_height; glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture_.gl_pbo_id); - glBufferData(GL_PIXEL_UNPACK_BUFFER, size_in_bytes, 0, GL_DYNAMIC_DRAW); + glBufferData(GL_PIXEL_UNPACK_BUFFER, size_in_bytes, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); texture_.buffer_width = buffer_width; @@ -225,7 +231,7 @@ void OpenGLDisplayDriver::draw(const Params ¶ms) glEnableVertexAttribArray(position_attribute); glVertexAttribPointer( - texcoord_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)0); + texcoord_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)nullptr); glVertexAttribPointer(position_attribute, 2, GL_FLOAT, @@ -341,7 +347,7 @@ void OpenGLDisplayDriver::texture_update_if_needed() glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture_.gl_pbo_id); glTexSubImage2D( - GL_TEXTURE_2D, 0, 0, 0, texture_.width, texture_.height, GL_RGBA, GL_HALF_FLOAT, 0); + GL_TEXTURE_2D, 0, 0, 0, texture_.width, texture_.height, GL_RGBA, GL_HALF_FLOAT, nullptr); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); texture_.need_update = false; diff --git a/intern/cycles/app/opengl/display_driver.h b/intern/cycles/app/opengl/display_driver.h index 333171334fc..96b7ad7d590 100644 --- a/intern/cycles/app/opengl/display_driver.h +++ b/intern/cycles/app/opengl/display_driver.h @@ -11,8 +11,6 @@ #include "session/display_driver.h" -#include "util/unique_ptr.h" - CCL_NAMESPACE_BEGIN class OpenGLDisplayDriver : public DisplayDriver { @@ -21,27 +19,27 @@ class OpenGLDisplayDriver : public DisplayDriver { * the context on the Cycles render thread independent of the main thread. */ OpenGLDisplayDriver(const std::function &gl_context_enable, const std::function &gl_context_disable); - ~OpenGLDisplayDriver(); + ~OpenGLDisplayDriver() override; - virtual void graphics_interop_activate() override; - virtual void graphics_interop_deactivate() override; + void graphics_interop_activate() override; + void graphics_interop_deactivate() override; - virtual void clear() override; + void clear() override; void set_zoom(float zoom_x, float zoom_y); protected: - virtual void next_tile_begin() override; + void next_tile_begin() override; - virtual bool update_begin(const Params ¶ms, int texture_width, int texture_height) override; - virtual void update_end() override; + bool update_begin(const Params ¶ms, int texture_width, int texture_height) override; + void update_end() override; - virtual half4 *map_texture_buffer() override; - virtual void unmap_texture_buffer() override; + half4 *map_texture_buffer() override; + void unmap_texture_buffer() override; - virtual GraphicsInterop graphics_interop_get() override; + GraphicsInterop graphics_interop_get() override; - virtual void draw(const Params ¶ms) override; + void draw(const Params ¶ms) override; /* Make sure texture is allocated and its initial configuration is performed. */ bool gl_texture_resources_ensure(); diff --git a/intern/cycles/app/opengl/shader.cpp b/intern/cycles/app/opengl/shader.cpp index 5d74dc0f8cb..a0d02292335 100644 --- a/intern/cycles/app/opengl/shader.cpp +++ b/intern/cycles/app/opengl/shader.cpp @@ -67,7 +67,7 @@ static void shader_print_errors(const char *task, const char *log, const char *c LOG(ERROR) << log; } -static int compile_shader_program(void) +static int compile_shader_program() { const struct Shader { const char *source; diff --git a/intern/cycles/app/opengl/window.cpp b/intern/cycles/app/opengl/window.cpp index 09a0ebfe4bf..f59f7c087b0 100644 --- a/intern/cycles/app/opengl/window.cpp +++ b/intern/cycles/app/opengl/window.cpp @@ -2,14 +2,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include #include "app/opengl/window.h" #include "util/string.h" #include "util/thread.h" -#include "util/time.h" #include "util/version.h" #include @@ -42,7 +41,7 @@ struct Window { /* public */ -static void window_display_text(int x, int y, const char *text) +static void window_display_text(int /*x*/, int /*y*/, const char *text) { /* Not currently supported, need to add text rendering support. */ #if 0 @@ -64,7 +63,7 @@ static void window_display_text(int x, int y, const char *text) bitmap + 1); } #else - static string last_text = ""; + static string last_text; if (text != last_text) { printf("%s\n", text); diff --git a/intern/cycles/app/opengl/window.h b/intern/cycles/app/opengl/window.h index 446f9f4845d..6ea827bcef0 100644 --- a/intern/cycles/app/opengl/window.h +++ b/intern/cycles/app/opengl/window.h @@ -9,12 +9,12 @@ CCL_NAMESPACE_BEGIN -typedef void (*WindowInitFunc)(); -typedef void (*WindowExitFunc)(); -typedef void (*WindowResizeFunc)(int width, int height); -typedef void (*WindowDisplayFunc)(); -typedef void (*WindowKeyboardFunc)(unsigned char key); -typedef void (*WindowMotionFunc)(int x, int y, int button); +using WindowInitFunc = void (*)(); +using WindowExitFunc = void (*)(); +using WindowResizeFunc = void (*)(int, int); +using WindowDisplayFunc = void (*)(); +using WindowKeyboardFunc = void (*)(unsigned char); +using WindowMotionFunc = void (*)(int, int, int); void window_main_loop(const char *title, int width, diff --git a/intern/cycles/blender/attribute_convert.h b/intern/cycles/blender/attribute_convert.h index f8e47d6b997..d36413fd731 100644 --- a/intern/cycles/blender/attribute_convert.h +++ b/intern/cycles/blender/attribute_convert.h @@ -4,12 +4,11 @@ #pragma once -#include "util/array.h" #include "util/color.h" #include "util/param.h" #include "util/types.h" -#include "BLI_math_color.hh" +#include "BLI_color.hh" #include "BLI_math_quaternion_types.hh" #include "BLI_math_vector_types.hh" diff --git a/intern/cycles/blender/camera.cpp b/intern/cycles/blender/camera.cpp index af3f16454c4..264bdac4630 100644 --- a/intern/cycles/blender/camera.cpp +++ b/intern/cycles/blender/camera.cpp @@ -762,7 +762,7 @@ static void blender_camera_from_view(BlenderCamera *bcam, } else { /* magic zoom formula */ - bcam->zoom = (float)b_rv3d.view_camera_zoom(); + bcam->zoom = b_rv3d.view_camera_zoom(); bcam->zoom = (1.41421f + bcam->zoom / 50.0f); bcam->zoom *= bcam->zoom; bcam->zoom = 2.0f / bcam->zoom; diff --git a/intern/cycles/blender/curves.cpp b/intern/cycles/blender/curves.cpp index 083caff16f9..184e6455896 100644 --- a/intern/cycles/blender/curves.cpp +++ b/intern/cycles/blender/curves.cpp @@ -25,9 +25,9 @@ CCL_NAMESPACE_BEGIN -ParticleCurveData::ParticleCurveData() {} +ParticleCurveData::ParticleCurveData() = default; -ParticleCurveData::~ParticleCurveData() {} +ParticleCurveData::~ParticleCurveData() = default; static float shaperadius(float shape, float root, float tip, float time) { @@ -62,7 +62,7 @@ static bool ObtainCacheParticleData( Transform itfm = transform_inverse(tfm); for (BL::Modifier &b_mod : b_ob->modifiers) { - if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + if ((b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) && (background ? b_mod.show_render() : b_mod.show_viewport())) { BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); @@ -80,15 +80,18 @@ static bool ObtainCacheParticleData( (float)b_part.display_percentage() / 100.0f); int totcurves = totchild; - if (b_part.child_type() == 0 || totchild == 0) + if (b_part.child_type() == 0 || totchild == 0) { totcurves += totparts; + } - if (totcurves == 0) + if (totcurves == 0) { continue; + } int ren_step = (1 << display_step) + 1; - if (b_part.kink() == BL::ParticleSettings::kink_SPIRAL) + if (b_part.kink() == BL::ParticleSettings::kink_SPIRAL) { ren_step += b_part.kink_extra_steps(); + } CData->psys_firstcurve.push_back_slow(curvenum); CData->psys_curvenum.push_back_slow(totcurves); @@ -102,8 +105,9 @@ static bool ObtainCacheParticleData( CData->psys_closetip.push_back_slow(b_part.use_close_tip()); int pa_no = 0; - if (!(b_part.child_type() == 0) && totchild != 0) + if (!(b_part.child_type() == 0) && totchild != 0) { pa_no = totparts; + } int num_add = (totparts + totchild - pa_no); CData->curve_firstkey.reserve(CData->curve_firstkey.size() + num_add); @@ -160,7 +164,7 @@ static bool ObtainCacheParticleUV(Hair *hair, CData->curve_uv.clear(); for (BL::Modifier &b_mod : b_ob->modifiers) { - if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + if ((b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) && (background ? b_mod.show_render() : b_mod.show_viewport())) { BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); @@ -176,15 +180,18 @@ static bool ObtainCacheParticleUV(Hair *hair, (float)b_part.display_percentage() / 100.0f); int totcurves = totchild; - if (b_part.child_type() == 0 || totchild == 0) + if (b_part.child_type() == 0 || totchild == 0) { totcurves += totparts; + } - if (totcurves == 0) + if (totcurves == 0) { continue; + } int pa_no = 0; - if (!(b_part.child_type() == 0) && totchild != 0) + if (!(b_part.child_type() == 0) && totchild != 0) { pa_no = totparts; + } int num_add = (totparts + totchild - pa_no); CData->curve_uv.reserve(CData->curve_uv.size() + num_add); @@ -197,12 +204,14 @@ static bool ObtainCacheParticleUV(Hair *hair, b_mesh->uv_layers.begin(l); float2 uv = zero_float2(); - if (!b_mesh->uv_layers.empty()) + if (!b_mesh->uv_layers.empty()) { b_psys.uv_on_emitter(psmd, *b_pa, pa_no, uv_num, &uv.x); + } CData->curve_uv.push_back_slow(uv); - if (pa_no < totparts && b_pa != b_psys.particles.end()) + if (pa_no < totparts && b_pa != b_psys.particles.end()) { ++b_pa; + } } } } @@ -225,7 +234,7 @@ static bool ObtainCacheParticleVcol(Hair *hair, CData->curve_vcol.clear(); for (BL::Modifier &b_mod : b_ob->modifiers) { - if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + if ((b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) && (background ? b_mod.show_render() : b_mod.show_viewport())) { BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); @@ -241,15 +250,18 @@ static bool ObtainCacheParticleVcol(Hair *hair, (float)b_part.display_percentage() / 100.0f); int totcurves = totchild; - if (b_part.child_type() == 0 || totchild == 0) + if (b_part.child_type() == 0 || totchild == 0) { totcurves += totparts; + } - if (totcurves == 0) + if (totcurves == 0) { continue; + } int pa_no = 0; - if (!(b_part.child_type() == 0) && totchild != 0) + if (!(b_part.child_type() == 0) && totchild != 0) { pa_no = totparts; + } int num_add = (totparts + totchild - pa_no); CData->curve_vcol.reserve(CData->curve_vcol.size() + num_add); @@ -262,12 +274,14 @@ static bool ObtainCacheParticleVcol(Hair *hair, b_mesh->vertex_colors.begin(l); float4 vcol = make_float4(0.0f, 0.0f, 0.0f, 1.0f); - if (!b_mesh->vertex_colors.empty()) + if (!b_mesh->vertex_colors.empty()) { b_psys.mcol_on_emitter(psmd, *b_pa, pa_no, vcol_num, &vcol.x); + } CData->curve_vcol.push_back_slow(vcol); - if (pa_no < totparts && b_pa != b_psys.particles.end()) + if (pa_no < totparts && b_pa != b_psys.particles.end()) { ++b_pa; + } } } } @@ -528,7 +542,7 @@ bool BlenderSync::object_has_particle_hair(BL::Object b_ob) { /* Test if the object has a particle modifier with hair. */ for (BL::Modifier &b_mod : b_ob.modifiers) { - if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + if ((b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) && (preview ? b_mod.show_viewport() : b_mod.show_render())) { BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); @@ -556,7 +570,7 @@ void BlenderSync::sync_particle_hair( BL::Object b_ob = b_ob_info.real_object; /* obtain general settings */ - if (b_ob.mode() == b_ob.mode_PARTICLE_EDIT || b_ob.mode() == b_ob.mode_EDIT) { + if (b_ob.mode() == BL::Object::mode_PARTICLE_EDIT || b_ob.mode() == BL::Object::mode_EDIT) { return; } @@ -693,7 +707,7 @@ static void attr_create_motion_from_velocity(Hair *hair, hair->set_motion_steps(3); /* Find or add attribute */ - float3 *P = &hair->get_curve_keys()[0]; + float3 *P = hair->get_curve_keys().data(); Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if (!attr_mP) { @@ -1077,15 +1091,14 @@ void BlenderSync::sync_hair_motion(BL::Depsgraph b_depsgraph, sync_hair(hair, b_ob_info, true, motion_step); return; } - else { - /* Particle hair. */ - BL::Mesh b_mesh = object_to_mesh( - b_data, b_ob_info, b_depsgraph, false, Mesh::SUBDIVISION_NONE); - if (b_mesh) { - sync_particle_hair(hair, b_mesh, b_ob_info, true, motion_step); - free_object_to_mesh(b_data, b_ob_info, b_mesh); - return; - } + + /* Particle hair. */ + BL::Mesh b_mesh = object_to_mesh( + b_data, b_ob_info, b_depsgraph, false, Mesh::SUBDIVISION_NONE); + if (b_mesh) { + sync_particle_hair(hair, b_mesh, b_ob_info, true, motion_step); + free_object_to_mesh(b_data, b_ob_info, b_mesh); + return; } } diff --git a/intern/cycles/blender/device.cpp b/intern/cycles/blender/device.cpp index 95ae225daed..b3bd146daab 100644 --- a/intern/cycles/blender/device.cpp +++ b/intern/cycles/blender/device.cpp @@ -28,9 +28,8 @@ int blender_device_threads(BL::Scene &b_scene) if (b_r.threads_mode() == BL::RenderSettings::threads_mode_FIXED) { return b_r.threads(); } - else { - return 0; - } + + return 0; } void static adjust_device_info_from_preferences(DeviceInfo &info, PointerRNA cpreferences) diff --git a/intern/cycles/blender/device.h b/intern/cycles/blender/device.h index 2e50a882c5d..9c2af268da8 100644 --- a/intern/cycles/blender/device.h +++ b/intern/cycles/blender/device.h @@ -4,10 +4,7 @@ #pragma once -#include "MEM_guardedalloc.h" -#include "RNA_access.hh" #include "RNA_blender_cpp.hh" -#include "RNA_types.hh" #include "device/device.h" diff --git a/intern/cycles/blender/display_driver.cpp b/intern/cycles/blender/display_driver.cpp index 3be95d188d4..86c9fdb4940 100644 --- a/intern/cycles/blender/display_driver.cpp +++ b/intern/cycles/blender/display_driver.cpp @@ -2,8 +2,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "GPU_context.hh" #include "GPU_immediate.hh" +#include "GPU_platform.hh" #include "GPU_shader.hh" #include "GPU_state.hh" #include "GPU_texture.hh" @@ -12,9 +12,9 @@ #include "blender/display_driver.h" -#include "device/device.h" #include "util/log.h" #include "util/math.h" +#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -55,7 +55,7 @@ int BlenderDisplayShader::get_tex_coord_attrib_location() /* -------------------------------------------------------------------- * BlenderFallbackDisplayShader. */ -static GPUShader *compile_fallback_shader(void) +static GPUShader *compile_fallback_shader() { /* NOTE: Compilation errors are logged to console. */ GPUShader *shader = GPU_shader_create_from_info_name("gpu_shader_cycles_display_fallback"); @@ -364,7 +364,7 @@ class DisplayGPUPixelBuffer { protected: void reset() { - gpu_pixel_buffer = 0; + gpu_pixel_buffer = nullptr; width = 0; height = 0; } @@ -387,9 +387,9 @@ class DrawTile { texture.gpu_resources_destroy(); } - inline bool ready_to_draw() const + bool ready_to_draw() const { - return texture.gpu_texture != 0; + return texture.gpu_texture != nullptr; } /* Texture which contains pixels of the tile. */ @@ -771,9 +771,17 @@ void BlenderDisplayDriver::draw(const Params ¶ms) GPUVertFormat *format = immVertexFormat(); const int texcoord_attribute = GPU_vertformat_attr_add( - format, display_shader_->tex_coord_attribute_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + format, + ccl::BlenderDisplayShader::tex_coord_attribute_name, + GPU_COMP_F32, + 2, + GPU_FETCH_FLOAT); const int position_attribute = GPU_vertformat_attr_add( - format, display_shader_->position_attribute_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + format, + ccl::BlenderDisplayShader::position_attribute_name, + GPU_COMP_F32, + 2, + GPU_FETCH_FLOAT); /* NOTE: Shader is bound again through IMM to register this shader with the IMM module * and perform required setup for IMM rendering. This is required as the IMM module diff --git a/intern/cycles/blender/display_driver.h b/intern/cycles/blender/display_driver.h index f2b67180758..b6f56d3aade 100644 --- a/intern/cycles/blender/display_driver.h +++ b/intern/cycles/blender/display_driver.h @@ -6,19 +6,15 @@ #include -#include "MEM_guardedalloc.h" - #include "RNA_blender_cpp.hh" #include "session/display_driver.h" -#include "util/thread.h" #include "util/unique_ptr.h" -#include "util/vector.h" -typedef struct GPUContext GPUContext; -typedef struct GPUFence GPUFence; -typedef struct GPUShader GPUShader; +struct GPUContext; +struct GPUFence; +struct GPUShader; CCL_NAMESPACE_BEGIN @@ -56,16 +52,16 @@ class BlenderDisplayShader { * display space shader. */ class BlenderFallbackDisplayShader : public BlenderDisplayShader { public: - virtual GPUShader *bind(int width, int height) override; - virtual void unbind() override; + GPUShader *bind(int width, int height) override; + void unbind() override; protected: - virtual GPUShader *get_shader_program() override; + GPUShader *get_shader_program() override; void create_shader_if_needed(); void destroy_shader(); - GPUShader *shader_program_ = 0; + GPUShader *shader_program_ = nullptr; int image_texture_location_ = -1; int fullscreen_location_ = -1; @@ -78,11 +74,11 @@ class BlenderDisplaySpaceShader : public BlenderDisplayShader { public: BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene); - virtual GPUShader *bind(int width, int height) override; - virtual void unbind() override; + GPUShader *bind(int width, int height) override; + void unbind() override; protected: - virtual GPUShader *get_shader_program() override; + GPUShader *get_shader_program() override; BL::RenderEngine b_engine_; BL::Scene &b_scene_; @@ -95,29 +91,29 @@ class BlenderDisplaySpaceShader : public BlenderDisplayShader { class BlenderDisplayDriver : public DisplayDriver { public: BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background); - ~BlenderDisplayDriver(); + ~BlenderDisplayDriver() override; - virtual void graphics_interop_activate() override; - virtual void graphics_interop_deactivate() override; + void graphics_interop_activate() override; + void graphics_interop_deactivate() override; - virtual void clear() override; + void clear() override; void set_zoom(float zoom_x, float zoom_y); protected: - virtual void next_tile_begin() override; + void next_tile_begin() override; - virtual bool update_begin(const Params ¶ms, int texture_width, int texture_height) override; - virtual void update_end() override; + bool update_begin(const Params ¶ms, int texture_width, int texture_height) override; + void update_end() override; - virtual half4 *map_texture_buffer() override; - virtual void unmap_texture_buffer() override; + half4 *map_texture_buffer() override; + void unmap_texture_buffer() override; - virtual GraphicsInterop graphics_interop_get() override; + GraphicsInterop graphics_interop_get() override; - virtual void draw(const Params ¶ms) override; + void draw(const Params ¶ms) override; - virtual void flush() override; + void flush() override; /* Helper function which allocates new GPU context. */ void gpu_context_create(); diff --git a/intern/cycles/blender/id_map.h b/intern/cycles/blender/id_map.h index bff32fb909e..c7842a5d662 100644 --- a/intern/cycles/blender/id_map.h +++ b/intern/cycles/blender/id_map.h @@ -4,7 +4,7 @@ #pragma once -#include +#include #include "scene/geometry.h" #include "scene/scene.h" @@ -12,6 +12,8 @@ #include "util/map.h" #include "util/set.h" +#include "RNA_blender_cpp.hh" + CCL_NAMESPACE_BEGIN /* ID Map @@ -149,7 +151,7 @@ template class id_map { void post_sync(bool do_delete = true) { map new_map; - typedef pair TMapPair; + using TMapPair = pair; typename map::iterator jt; for (jt = b_map.begin(); jt != b_map.end(); jt++) { @@ -234,15 +236,15 @@ struct ObjectKey { if (ob < k.ob) { return true; } - else if (ob == k.ob) { + if (ob == k.ob) { if (parent < k.parent) { return true; } - else if (parent == k.parent) { + if (parent == k.parent) { if (use_particle_hair < k.use_particle_hair) { return true; } - else if (use_particle_hair == k.use_particle_hair) { + if (use_particle_hair == k.use_particle_hair) { return memcmp(id, k.id, sizeof(id)) < 0; } } @@ -268,7 +270,7 @@ struct GeometryKey { if (id < k.id) { return true; } - else if (id == k.id) { + if (id == k.id) { if (geometry_type < k.geometry_type) { return true; } @@ -300,7 +302,7 @@ struct ParticleSystemKey { if (ob < k.ob) { return true; } - else if (ob == k.ob) { + if (ob == k.ob) { return memcmp(id + 1, k.id + 1, sizeof(int) * (OBJECT_PERSISTENT_ID_SIZE - 1)) < 0; } diff --git a/intern/cycles/blender/image.cpp b/intern/cycles/blender/image.cpp index 5d647e6e271..29a9dc82e49 100644 --- a/intern/cycles/blender/image.cpp +++ b/intern/cycles/blender/image.cpp @@ -27,7 +27,8 @@ BlenderImageLoader::BlenderImageLoader(BL::Image b_image, { } -bool BlenderImageLoader::load_metadata(const ImageDeviceFeatures &, ImageMetaData &metadata) +bool BlenderImageLoader::load_metadata(const ImageDeviceFeatures & /*features*/, + ImageMetaData &metadata) { if (b_image.source() != BL::Image::source_TILED) { /* Image sequence might have different dimensions, and hence needs to be handled in a special @@ -256,7 +257,8 @@ BlenderPointDensityLoader::BlenderPointDensityLoader(BL::Depsgraph b_depsgraph, { } -bool BlenderPointDensityLoader::load_metadata(const ImageDeviceFeatures &, ImageMetaData &metadata) +bool BlenderPointDensityLoader::load_metadata(const ImageDeviceFeatures & /*features*/, + ImageMetaData &metadata) { metadata.channels = 4; metadata.width = b_node.resolution(); @@ -266,10 +268,10 @@ bool BlenderPointDensityLoader::load_metadata(const ImageDeviceFeatures &, Image return true; } -bool BlenderPointDensityLoader::load_pixels(const ImageMetaData &, +bool BlenderPointDensityLoader::load_pixels(const ImageMetaData & /*metadata*/, void *pixels, - const size_t, - const bool) + const size_t /*pixels_size*/, + const bool /*associate_alpha*/) { int length; b_node.calc_point_density(b_depsgraph, &length, (float **)&pixels); diff --git a/intern/cycles/blender/light.cpp b/intern/cycles/blender/light.cpp index 0dc9d6c4369..3d1c709729e 100644 --- a/intern/cycles/blender/light.cpp +++ b/intern/cycles/blender/light.cpp @@ -178,7 +178,7 @@ void BlenderSync::sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal) if (sample_as_light || use_portal) { /* test if we need to sync */ Light *light; - ObjectKey key(b_world, 0, b_world, false); + ObjectKey key(b_world, nullptr, b_world, false); if (light_map.add_or_update(&light, b_world, b_world, key) || world_recalc || b_world.ptr.data != world_map) diff --git a/intern/cycles/blender/light_linking.cpp b/intern/cycles/blender/light_linking.cpp index 55854b80e1e..f5f028dacef 100644 --- a/intern/cycles/blender/light_linking.cpp +++ b/intern/cycles/blender/light_linking.cpp @@ -4,10 +4,10 @@ #include "blender/light_linking.h" -#include "scene/object.h" - #include "DNA_object_types.h" +#include "kernel/types.h" + CCL_NAMESPACE_BEGIN static const ::Object *get_blender_object(const BL::Object &object) diff --git a/intern/cycles/blender/light_linking.h b/intern/cycles/blender/light_linking.h index 3acc8320da8..147464c1fec 100644 --- a/intern/cycles/blender/light_linking.h +++ b/intern/cycles/blender/light_linking.h @@ -6,7 +6,6 @@ #include -#include "MEM_guardedalloc.h" #include "RNA_blender_cpp.hh" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp index edb58aa78d4..af59b67d101 100644 --- a/intern/cycles/blender/mesh.cpp +++ b/intern/cycles/blender/mesh.cpp @@ -9,17 +9,15 @@ #include "blender/sync.h" #include "blender/util.h" +#include "scene/bake.h" #include "scene/camera.h" -#include "scene/colorspace.h" #include "scene/mesh.h" #include "scene/object.h" #include "scene/scene.h" -#include "subd/patch.h" #include "subd/split.h" #include "util/algorithm.h" -#include "util/color.h" #include "util/disjoint_set.h" #include "util/foreach.h" #include "util/hash.h" @@ -43,7 +41,7 @@ template struct MikkMeshWrapper { const Mesh *mesh, float3 *tangent, float *tangent_sign) - : mesh(mesh), uv(nullptr), orco(nullptr), tangent(tangent), tangent_sign(tangent_sign) + : mesh(mesh), tangent(tangent), tangent_sign(tangent_sign) { const AttributeSet &attributes = is_subd ? mesh->subd_attributes : mesh->attributes; @@ -125,14 +123,12 @@ template struct MikkMeshWrapper { float2 tfuv = uv[corner_index]; return mikk::float3(tfuv.x, tfuv.y, 1.0f); } - else if (orco != nullptr) { + if (orco != nullptr) { const int vertex_index = VertexIndex(face_num, vert_num); const float2 uv = map_to_sphere((orco[vertex_index] + orco_loc) * inv_orco_size); return mikk::float3(uv.x, uv.y, 1.0f); } - else { - return mikk::float3(0.0f, 0.0f, 1.0f); - } + return mikk::float3(0.0f, 0.0f, 1.0f); } mikk::float3 GetNormal(const int face_num, const int vert_num) @@ -155,7 +151,7 @@ template struct MikkMeshWrapper { } else { const Mesh::Triangle tri = mesh->get_triangle(face_num); - vN = tri.compute_normal(&mesh->get_verts()[0]); + vN = tri.compute_normal(mesh->get_verts().data()); } } return mikk::float3(vN.x, vN.y, vN.z); @@ -175,8 +171,8 @@ template struct MikkMeshWrapper { float3 *vertex_normal; float2 *texface; - float2 *uv; - float3 *orco; + float2 *uv = nullptr; + float3 *orco = nullptr; float3 orco_loc, inv_orco_size; float3 *tangent; @@ -248,7 +244,7 @@ static void attr_create_motion_from_velocity(Mesh *mesh, mesh->set_motion_steps(3); /* Find or add attribute */ - float3 *P = &mesh->get_verts()[0]; + float3 *P = mesh->get_verts().data(); Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if (!attr_mP) { @@ -685,7 +681,7 @@ static void attr_create_pointiness(Mesh *mesh, vector raw_data(num_verts, 0.0f); vector edge_accum(num_verts, zero_float3()); EdgeMap visited_edges; - memset(&counter[0], 0, sizeof(int) * counter.size()); + memset(counter.data(), 0, sizeof(int) * counter.size()); for (const int i : edges.index_range()) { const blender::int2 b_edge = edges[i]; @@ -722,8 +718,8 @@ static void attr_create_pointiness(Mesh *mesh, AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes; Attribute *attr = attributes.add(ATTR_STD_POINTINESS); float *data = attr->data_float(); - memcpy(data, &raw_data[0], sizeof(float) * raw_data.size()); - memset(&counter[0], 0, sizeof(int) * counter.size()); + memcpy(data, raw_data.data(), sizeof(float) * raw_data.size()); + memset(counter.data(), 0, sizeof(int) * counter.size()); visited_edges.clear(); for (const int i : edges.index_range()) { const blender::int2 b_edge = edges[i]; @@ -1251,7 +1247,7 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, if (new_attribute) { /* In case of new attribute, we verify if there really was any motion. */ if (b_verts_num != numverts || - memcmp(mP, &mesh->get_verts()[0], sizeof(float3) * numverts) == 0) + memcmp(mP, mesh->get_verts().data(), sizeof(float3) * numverts) == 0) { /* no motion, remove attributes again */ if (b_verts_num != numverts) { @@ -1269,7 +1265,7 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, VLOG_DEBUG << "Filling deformation motion for object " << ob_name; /* motion, fill up previous steps that we might have skipped because * they had no motion, but we need them anyway now */ - float3 *P = &mesh->get_verts()[0]; + float3 *P = mesh->get_verts().data(); float3 *N = (attr_N) ? attr_N->data_float3() : nullptr; for (int step = 0; step < motion_step; step++) { memcpy(attr_mP->data_float3() + step * numverts, P, sizeof(float3) * numverts); @@ -1283,7 +1279,7 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, if (b_verts_num != numverts) { VLOG_WARNING << "Topology differs, discarding motion blur for object " << ob_name << " at time " << motion_step; - memcpy(mP, &mesh->get_verts()[0], sizeof(float3) * numverts); + memcpy(mP, mesh->get_verts().data(), sizeof(float3) * numverts); if (mN != nullptr) { memcpy(mN, attr_N->data_float3(), sizeof(float3) * numverts); } diff --git a/intern/cycles/blender/object.cpp b/intern/cycles/blender/object.cpp index d47f01b1868..dcd345a7d76 100644 --- a/intern/cycles/blender/object.cpp +++ b/intern/cycles/blender/object.cpp @@ -18,7 +18,6 @@ #include "scene/shader.h" #include "scene/shader_graph.h" #include "scene/shader_nodes.h" -#include "scene/volume.h" #include "util/foreach.h" #include "util/hash.h" @@ -38,16 +37,15 @@ bool BlenderSync::BKE_object_is_modified(BL::Object &b_ob) /* multi-user and dupli metaballs are fused, can't instance */ return true; } - else if (ccl::BKE_object_is_modified(b_ob, b_scene, preview)) { + if (ccl::BKE_object_is_modified(b_ob, b_scene, preview)) { /* modifiers */ return true; } - else { - /* object level material links */ - for (BL::MaterialSlot &b_slot : b_ob.material_slots) { - if (b_slot.link() == BL::MaterialSlot::link_OBJECT) { - return true; - } + + /* object level material links */ + for (BL::MaterialSlot &b_slot : b_ob.material_slots) { + if (b_slot.link() == BL::MaterialSlot::link_OBJECT) { + return true; } } @@ -665,8 +663,9 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, procedural_map.post_sync(); } - if (motion) + if (motion) { geometry_motion_synced.clear(); + } } void BlenderSync::sync_motion(BL::RenderSettings &b_render, diff --git a/intern/cycles/blender/output_driver.cpp b/intern/cycles/blender/output_driver.cpp index ce86885d813..1b79e34f432 100644 --- a/intern/cycles/blender/output_driver.cpp +++ b/intern/cycles/blender/output_driver.cpp @@ -8,7 +8,7 @@ CCL_NAMESPACE_BEGIN BlenderOutputDriver::BlenderOutputDriver(BL::RenderEngine &b_engine) : b_engine_(b_engine) {} -BlenderOutputDriver::~BlenderOutputDriver() {} +BlenderOutputDriver::~BlenderOutputDriver() = default; bool BlenderOutputDriver::read_render_tile(const Tile &tile) { @@ -95,11 +95,11 @@ void BlenderOutputDriver::write_render_tile(const Tile &tile) /* Copy each pass. */ for (BL::RenderPass &b_pass : b_rlay.passes) { - if (!tile.get_pass_pixels(b_pass.name(), b_pass.channels(), &pixels[0])) { - memset(&pixels[0], 0, pixels.size() * sizeof(float)); + if (!tile.get_pass_pixels(b_pass.name(), b_pass.channels(), pixels.data())) { + memset(pixels.data(), 0, pixels.size() * sizeof(float)); } - b_pass.rect(&pixels[0]); + b_pass.rect(pixels.data()); } b_engine_.end_result(b_rr, false, false, true); diff --git a/intern/cycles/blender/output_driver.h b/intern/cycles/blender/output_driver.h index 00b8c3dec34..118cfa9c5da 100644 --- a/intern/cycles/blender/output_driver.h +++ b/intern/cycles/blender/output_driver.h @@ -4,8 +4,6 @@ #pragma once -#include "MEM_guardedalloc.h" - #include "RNA_blender_cpp.hh" #include "session/output_driver.h" @@ -15,11 +13,11 @@ CCL_NAMESPACE_BEGIN class BlenderOutputDriver : public OutputDriver { public: explicit BlenderOutputDriver(BL::RenderEngine &b_engine); - ~BlenderOutputDriver(); + ~BlenderOutputDriver() override; - virtual void write_render_tile(const Tile &tile) override; - virtual bool update_render_tile(const Tile &tile) override; - virtual bool read_render_tile(const Tile &tile) override; + void write_render_tile(const Tile &tile) override; + bool update_render_tile(const Tile &tile) override; + bool read_render_tile(const Tile &tile) override; protected: BL::RenderEngine b_engine_; diff --git a/intern/cycles/blender/pointcloud.cpp b/intern/cycles/blender/pointcloud.cpp index 677999bac5e..f22159d3384 100644 --- a/intern/cycles/blender/pointcloud.cpp +++ b/intern/cycles/blender/pointcloud.cpp @@ -2,23 +2,22 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include - -#include "scene/attribute.h" #include "scene/pointcloud.h" +#include "scene/attribute.h" #include "scene/scene.h" +#include "util/hash.h" + #include "blender/attribute_convert.h" #include "blender/sync.h" #include "blender/util.h" -#include "util/color.h" #include "util/foreach.h" -#include "util/hash.h" + +#include "DNA_pointcloud_types.h" #include "BKE_attribute.hh" #include "BKE_attribute_math.hh" -#include "BKE_pointcloud.hh" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/blender/python.cpp b/intern/cycles/blender/python.cpp index dd73b48d13d..801f303ca4d 100644 --- a/intern/cycles/blender/python.cpp +++ b/intern/cycles/blender/python.cpp @@ -17,13 +17,11 @@ #include "util/debug.h" #include "util/foreach.h" #include "util/guiding.h" -#include "util/log.h" #include "util/md5.h" #include "util/openimagedenoise.h" #include "util/path.h" #include "util/string.h" #include "util/task.h" -#include "util/tbb.h" #include "util/types.h" #include "GPU_state.hh" @@ -63,7 +61,7 @@ PyObject *pyunicode_from_string(const char *str) /* Synchronize debug flags from a given Blender scene. * Return truth when device list needs invalidation. */ -static void debug_flags_sync_from_scene(BL::Scene b_scene) +void debug_flags_sync_from_scene(BL::Scene b_scene) { DebugFlagsRef flags = DebugFlags(); PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); @@ -82,7 +80,7 @@ static void debug_flags_sync_from_scene(BL::Scene b_scene) /* Reset debug flags to default values. * Return truth when device list needs invalidation. */ -static void debug_flags_reset() +void debug_flags_reset() { DebugFlagsRef flags = DebugFlags(); flags.reset(); @@ -110,22 +108,20 @@ static const char *PyC_UnicodeAsBytes(PyObject *py_str, PyObject **coerce) */ return result; } - else { - PyErr_Clear(); - if (PyBytes_Check(py_str)) { - return PyBytes_AS_STRING(py_str); - } - else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { - return PyBytes_AS_STRING(*coerce); - } - else { - /* Clear the error, so Cycles can be at least used without - * GPU and OSL support, - */ - PyErr_Clear(); - return ""; - } + PyErr_Clear(); + if (PyBytes_Check(py_str)) { + return PyBytes_AS_STRING(py_str); } + + *coerce = PyUnicode_EncodeFSDefault(py_str); + if (*coerce) { + return PyBytes_AS_STRING(*coerce); + } + /* Clear the error, so Cycles can be at least used without + * GPU and OSL support, + */ + PyErr_Clear(); + return ""; } static PyObject *init_func(PyObject * /*self*/, PyObject *args) @@ -183,11 +179,11 @@ static PyObject *create_func(PyObject * /*self*/, PyObject *args) ID *bScreen = (ID *)PyLong_AsVoidPtr(pyscreen); PointerRNA engineptr = RNA_pointer_create( - nullptr, &RNA_RenderEngine, (void *)PyLong_AsVoidPtr(pyengine)); + nullptr, &RNA_RenderEngine, PyLong_AsVoidPtr(pyengine)); BL::RenderEngine engine(engineptr); PointerRNA preferencesptr = RNA_pointer_create( - nullptr, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences)); + nullptr, &RNA_Preferences, PyLong_AsVoidPtr(pypreferences)); BL::Preferences preferences(preferencesptr); PointerRNA dataptr = RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata)); @@ -448,16 +444,16 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) PyObject *pydata, *pynodegroup, *pynode; const char *filepath = nullptr; - if (!PyArg_ParseTuple(args, "OOOs", &pydata, &pynodegroup, &pynode, &filepath)) + if (!PyArg_ParseTuple(args, "OOOs", &pydata, &pynodegroup, &pynode, &filepath)) { return nullptr; + } /* RNA */ PointerRNA dataptr = RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata)); BL::BlendData b_data(dataptr); - PointerRNA nodeptr = RNA_pointer_create((ID *)PyLong_AsVoidPtr(pynodegroup), - &RNA_ShaderNodeScript, - (void *)PyLong_AsVoidPtr(pynode)); + PointerRNA nodeptr = RNA_pointer_create( + (ID *)PyLong_AsVoidPtr(pynodegroup), &RNA_ShaderNodeScript, PyLong_AsVoidPtr(pynode)); BL::ShaderNodeScript b_node(nodeptr); /* update bytecode hash */ @@ -466,16 +462,18 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) if (!bytecode.empty()) { MD5Hash md5; md5.append((const uint8_t *)bytecode.c_str(), bytecode.size()); - b_node.bytecode_hash(md5.get_hex().c_str()); + b_node.bytecode_hash(md5.get_hex()); } - else + else { b_node.bytecode_hash(""); + } /* query from file path */ OSL::OSLQuery query; - if (!OSLShaderManager::osl_query(query, filepath)) + if (!OSLShaderManager::osl_query(query, filepath)) { Py_RETURN_FALSE; + } /* add new sockets from parameters */ set used_sockets; @@ -484,8 +482,9 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) const OSL::OSLQuery::Parameter *param = query.getparam(i); /* skip unsupported types */ - if (param->varlenarray || param->isstruct || param->type.arraylen > 1) + if (param->varlenarray || param->isstruct || param->type.arraylen > 1) { continue; + } /* Read metadata. */ bool is_bool_param = false; @@ -515,7 +514,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) float4 default_float4 = make_float4(0.0f, 0.0f, 0.0f, 1.0f); float default_float = 0.0f; int default_int = 0; - string default_string = ""; + string default_string; bool default_boolean = false; if (param->isclosure) { @@ -557,27 +556,32 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) else { socket_type = "NodeSocketInt"; data_type = BL::NodeSocket::type_INT; - if (param->validdefault) + if (param->validdefault) { default_int = param->idefault[0]; + } } } else if (param->type.basetype == TypeDesc::FLOAT) { socket_type = "NodeSocketFloat"; data_type = BL::NodeSocket::type_VALUE; - if (param->validdefault) + if (param->validdefault) { default_float = param->fdefault[0]; + } } else if (param->type.basetype == TypeDesc::STRING) { socket_type = "NodeSocketString"; data_type = BL::NodeSocket::type_STRING; - if (param->validdefault) + if (param->validdefault) { default_string = param->sdefault[0].string(); + } } - else + else { continue; + } } - else + else { continue; + } /* Update existing socket. */ bool found_existing = false; @@ -688,12 +692,14 @@ static PyObject *osl_compile_func(PyObject * /*self*/, PyObject *args) { const char *inputfile = nullptr, *outputfile = nullptr; - if (!PyArg_ParseTuple(args, "ss", &inputfile, &outputfile)) + if (!PyArg_ParseTuple(args, "ss", &inputfile, &outputfile)) { return nullptr; + } /* return */ - if (!OSLShaderManager::osl_compile(inputfile, outputfile)) + if (!OSLShaderManager::osl_compile(inputfile, outputfile)) { Py_RETURN_FALSE; + } Py_RETURN_TRUE; } @@ -756,7 +762,7 @@ static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *key /* Get device specification from preferences and scene. */ PointerRNA preferencesptr = RNA_pointer_create( - nullptr, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences)); + nullptr, &RNA_Preferences, PyLong_AsVoidPtr(pypreferences)); BL::Preferences b_preferences(preferencesptr); PointerRNA sceneptr = RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyscene)); diff --git a/intern/cycles/blender/session.cpp b/intern/cycles/blender/session.cpp index e6a7afbc80a..ed66fd480e1 100644 --- a/intern/cycles/blender/session.cpp +++ b/intern/cycles/blender/session.cpp @@ -2,12 +2,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include "device/device.h" + #include "scene/background.h" +#include "scene/bake.h" #include "scene/camera.h" -#include "scene/colorspace.h" #include "scene/film.h" #include "scene/integrator.h" #include "scene/light.h" @@ -16,11 +17,10 @@ #include "scene/scene.h" #include "scene/shader.h" #include "scene/stats.h" + #include "session/buffers.h" #include "session/session.h" -#include "util/algorithm.h" -#include "util/color.h" #include "util/foreach.h" #include "util/hash.h" #include "util/log.h" @@ -991,7 +991,7 @@ void BlenderSession::update_bake_progress() void BlenderSession::update_status_progress() { string timestatus, status, substatus; - string scene_status = ""; + string scene_status; double progress; double total_time, remaining_time = 0, render_time; float mem_used = (float)session->stats.mem_used / 1024.0f / 1024.0f; @@ -1008,11 +1008,11 @@ void BlenderSession::update_status_progress() if (scene) { scene_status += " | " + scene->name; } - if (b_rlay_name != "") { + if (!b_rlay_name.empty()) { scene_status += ", " + b_rlay_name; } - if (b_rview_name != "") { + if (!b_rview_name.empty()) { scene_status += ", " + b_rview_name; } @@ -1022,10 +1022,10 @@ void BlenderSession::update_status_progress() timestatus += string_printf("Mem:%.2fM, Peak:%.2fM", (double)mem_used, (double)mem_peak); - if (status.size() > 0) { + if (!status.empty()) { status = " | " + status; } - if (substatus.size() > 0) { + if (!substatus.empty()) { status += " | " + substatus; } } diff --git a/intern/cycles/blender/session.h b/intern/cycles/blender/session.h index 7ba4e5428ad..6415dd03761 100644 --- a/intern/cycles/blender/session.h +++ b/intern/cycles/blender/session.h @@ -4,13 +4,10 @@ #pragma once -#include "MEM_guardedalloc.h" - #include "RNA_blender_cpp.hh" #include "device/device.h" -#include "scene/bake.h" #include "scene/scene.h" #include "session/session.h" @@ -52,10 +49,10 @@ class BlenderSession { void render_frame_finish(); - void bake(BL::Depsgraph &b_depsgrah, + void bake(BL::Depsgraph &b_depsgraph_, BL::Object &b_object, - const string &pass_type, - const int custom_flag, + const string &bake_type, + const int bake_filter, const int bake_width, const int bake_height); diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp index 7d1cf08f92f..1907f035381 100644 --- a/intern/cycles/blender/shader.cpp +++ b/intern/cycles/blender/shader.cpp @@ -4,7 +4,6 @@ #include "scene/shader.h" #include "scene/background.h" -#include "scene/colorspace.h" #include "scene/integrator.h" #include "scene/light.h" #include "scene/osl.h" @@ -17,7 +16,6 @@ #include "blender/texture.h" #include "blender/util.h" -#include "util/debug.h" #include "util/foreach.h" #include "util/set.h" #include "util/string.h" @@ -27,9 +25,9 @@ CCL_NAMESPACE_BEGIN -typedef unordered_multimap PtrInputMap; -typedef map PtrOutputMap; -typedef map ProxyMap; +using PtrInputMap = unordered_multimap; +using PtrOutputMap = map; +using ProxyMap = map; /* Find */ @@ -299,7 +297,7 @@ static ShaderNode *add_node(Scene *scene, curves->set_min_x(min_x); curves->set_max_x(max_x); curves->set_curves(curve_mapping_curves); - curves->set_extrapolate(mapping.extend() == mapping.extend_EXTRAPOLATED); + curves->set_extrapolate(mapping.extend() == BL::CurveMapping::extend_EXTRAPOLATED); node = curves; } if (b_node.is_a(&RNA_ShaderNodeVectorCurve)) { @@ -313,7 +311,7 @@ static ShaderNode *add_node(Scene *scene, curves->set_min_x(min_x); curves->set_max_x(max_x); curves->set_curves(curve_mapping_curves); - curves->set_extrapolate(mapping.extend() == mapping.extend_EXTRAPOLATED); + curves->set_extrapolate(mapping.extend() == BL::CurveMapping::extend_EXTRAPOLATED); node = curves; } else if (b_node.is_a(&RNA_ShaderNodeFloatCurve)) { @@ -327,7 +325,7 @@ static ShaderNode *add_node(Scene *scene, curve->set_min_x(min_x); curve->set_max_x(max_x); curve->set_curve(curve_mapping_curve); - curve->set_extrapolate(mapping.extend() == mapping.extend_EXTRAPOLATED); + curve->set_extrapolate(mapping.extend() == BL::CurveMapping::extend_EXTRAPOLATED); node = curve; } else if (b_node.is_a(&RNA_ShaderNodeValToRGB)) { @@ -1284,12 +1282,15 @@ static void add_nodes(Scene *scene, { BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL); - if (b_node.is_a(&RNA_ShaderNodeGroup)) + if (b_node.is_a(&RNA_ShaderNodeGroup)) { b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(b_node)).node_tree()); - else if (b_node.is_a(&RNA_NodeCustomGroup)) + } + else if (b_node.is_a(&RNA_NodeCustomGroup)) { b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(b_node)).node_tree()); - else + } + else { b_group_ntree = BL::ShaderNodeTree(((BL::ShaderNodeCustomGroup)(b_node)).node_tree()); + } ProxyMap group_proxy_input_map, group_proxy_output_map; @@ -1427,8 +1428,9 @@ static void add_nodes(Scene *scene, ShaderOutput *output = nullptr; PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data); - if (output_it != output_map.end()) + if (output_it != output_map.end()) { output = output_it->second; + } /* either socket may be nullptr when the node was not exported, typically * because the node type is not supported */ diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp index b508a37fcbe..6a96c856e39 100644 --- a/intern/cycles/blender/sync.cpp +++ b/intern/cycles/blender/sync.cpp @@ -4,6 +4,7 @@ #include "RNA_types.hh" #include "scene/background.h" +#include "scene/bake.h" #include "scene/camera.h" #include "scene/curves.h" #include "scene/film.h" @@ -62,8 +63,8 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine, use_developer_ui(use_developer_ui), dicing_rate(1.0f), max_subdivisions(12), - progress(progress), - has_updates_(true) + progress(progress) + { PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate") : @@ -71,7 +72,7 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine, max_subdivisions = RNA_int_get(&cscene, "max_subdivisions"); } -BlenderSync::~BlenderSync() {} +BlenderSync::~BlenderSync() = default; void BlenderSync::reset(BL::BlendData &b_data, BL::Scene &b_scene) { diff --git a/intern/cycles/blender/sync.h b/intern/cycles/blender/sync.h index d800052ff1d..e5cd3ecadb1 100644 --- a/intern/cycles/blender/sync.h +++ b/intern/cycles/blender/sync.h @@ -4,10 +4,7 @@ #pragma once -#include "MEM_guardedalloc.h" -#include "RNA_access.hh" #include "RNA_blender_cpp.hh" -#include "RNA_path.hh" #include "RNA_types.hh" #include "blender/id_map.h" @@ -20,7 +17,6 @@ #include "util/map.h" #include "util/set.h" #include "util/transform.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -35,10 +31,8 @@ class Mesh; class Object; class ParticleSystem; class Scene; -class ViewLayer; class Shader; class ShaderGraph; -class ShaderNode; class TaskPool; class BlenderSync { @@ -69,7 +63,7 @@ class BlenderSync { void **python_thread_state, const DeviceInfo &denoise_device_info); void sync_view_layer(BL::ViewLayer &b_view_layer); - void sync_render_passes(BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer); + void sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_view_layer); void sync_integrator(BL::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device_info); @@ -79,11 +73,11 @@ class BlenderSync { int height, const char *viewname); void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height); - inline int get_layer_samples() + int get_layer_samples() { return view_layer.samples; } - inline int get_layer_bound_samples() + int get_layer_bound_samples() { return view_layer.bound_samples; } @@ -96,7 +90,7 @@ class BlenderSync { const bool background, const bool use_developer_ui); static SessionParams get_session_params(BL::RenderEngine &b_engine, - BL::Preferences &b_userpref, + BL::Preferences &b_preferences, BL::Scene &b_scene, bool background); static bool get_session_pause(BL::Scene &b_scene, bool background); @@ -253,29 +247,18 @@ class BlenderSync { int max_subdivisions; struct RenderLayerInfo { - RenderLayerInfo() - : material_override(PointerRNA_NULL), - world_override(PointerRNA_NULL), - use_background_shader(true), - use_surfaces(true), - use_hair(true), - use_volumes(true), - use_motion_blur(true), - samples(0), - bound_samples(false) - { - } + RenderLayerInfo() : material_override(PointerRNA_NULL), world_override(PointerRNA_NULL) {} string name; BL::Material material_override; BL::World world_override; - bool use_background_shader; - bool use_surfaces; - bool use_hair; - bool use_volumes; - bool use_motion_blur; - int samples; - bool bound_samples; + bool use_background_shader = true; + bool use_surfaces = true; + bool use_hair = true; + bool use_volumes = true; + bool use_motion_blur = true; + int samples = 0; + bool bound_samples = false; } view_layer; Progress &progress; diff --git a/intern/cycles/blender/texture.cpp b/intern/cycles/blender/texture.cpp index bde393a0570..621a7768ae6 100644 --- a/intern/cycles/blender/texture.cpp +++ b/intern/cycles/blender/texture.cpp @@ -4,6 +4,8 @@ #include "blender/texture.h" +#include "util/math.h" + CCL_NAMESPACE_BEGIN namespace { diff --git a/intern/cycles/blender/texture.h b/intern/cycles/blender/texture.h index 58acadb04f3..5388eef7f36 100644 --- a/intern/cycles/blender/texture.h +++ b/intern/cycles/blender/texture.h @@ -4,8 +4,9 @@ #pragma once -#include "blender/sync.h" -#include +#include "RNA_blender_cpp.hh" + +#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/blender/util.h b/intern/cycles/blender/util.h index efa14cf3f8e..12133299fab 100644 --- a/intern/cycles/blender/util.h +++ b/intern/cycles/blender/util.h @@ -9,15 +9,18 @@ #include "util/algorithm.h" #include "util/array.h" -#include "util/map.h" #include "util/path.h" #include "util/set.h" #include "util/transform.h" #include "util/types.h" -#include "util/vector.h" + +#include "RNA_blender_cpp.hh" + +#include "DNA_mesh_types.h" #include "BKE_image.hh" -#include "BKE_mesh.hh" +#include "BKE_mesh.h" +#include "BKE_mesh_types.hh" CCL_NAMESPACE_BEGIN @@ -43,7 +46,7 @@ struct BObjectInfo { } }; -typedef BL::ShaderNodeAttribute::attribute_type_enum BlenderAttributeType; +using BlenderAttributeType = BL::ShaderNodeAttribute::attribute_type_enum; BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_real_name); void python_thread_state_save(void **python_thread_state); @@ -688,9 +691,7 @@ static inline Mesh::SubdivisionType object_subdivision_type(BL::Object &b_ob, if (subsurf.subdivision_type() == BL::SubsurfModifier::subdivision_type_CATMULL_CLARK) { return Mesh::SUBDIVISION_CATMULL_CLARK; } - else { - return Mesh::SUBDIVISION_LINEAR; - } + return Mesh::SUBDIVISION_LINEAR; } } @@ -747,7 +748,7 @@ static inline bool object_need_motion_attribute(BObjectInfo &b_ob_info, Scene *s class EdgeMap { public: - EdgeMap() {} + EdgeMap() = default; void clear() { diff --git a/intern/cycles/blender/viewport.cpp b/intern/cycles/blender/viewport.cpp index fbade46724b..f832fbfc2ff 100644 --- a/intern/cycles/blender/viewport.cpp +++ b/intern/cycles/blender/viewport.cpp @@ -7,8 +7,6 @@ #include "scene/pass.h" -#include "util/log.h" - CCL_NAMESPACE_BEGIN BlenderViewportParameters::BlenderViewportParameters() diff --git a/intern/cycles/blender/viewport.h b/intern/cycles/blender/viewport.h index 257562ab6d6..beb62024f9a 100644 --- a/intern/cycles/blender/viewport.h +++ b/intern/cycles/blender/viewport.h @@ -4,13 +4,11 @@ #pragma once -#include "MEM_guardedalloc.h" - -#include "RNA_access.hh" #include "RNA_blender_cpp.hh" -#include "RNA_types.hh" -#include "scene/film.h" +#include "kernel/types.h" + +#include "util/param.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/blender/volume.cpp b/intern/cycles/blender/volume.cpp index db9fc826fb9..973b80379b4 100644 --- a/intern/cycles/blender/volume.cpp +++ b/intern/cycles/blender/volume.cpp @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "scene/volume.h" -#include "scene/colorspace.h" #include "scene/image.h" #include "scene/image_vdb.h" #include "scene/object.h" @@ -11,7 +10,6 @@ #include "blender/sync.h" #include "blender/util.h" -#include "BKE_volume.hh" #include "BKE_volume_grid.hh" CCL_NAMESPACE_BEGIN @@ -26,7 +24,7 @@ class BlenderSmokeLoader : public ImageLoader { *static_cast(b_ob.data().ptr.data), texspace_loc, texspace_size); } - bool load_metadata(const ImageDeviceFeatures &, ImageMetaData &metadata) override + bool load_metadata(const ImageDeviceFeatures & /*features*/, ImageMetaData &metadata) override { if (!b_domain) { return false; @@ -71,7 +69,10 @@ class BlenderSmokeLoader : public ImageLoader { return true; } - bool load_pixels(const ImageMetaData &, void *pixels, const size_t, const bool) override + bool load_pixels(const ImageMetaData & /*metadata*/, + void *pixels, + const size_t /*pixels_size*/, + const bool /*associate_alpha*/) override { if (!b_domain) { return false; diff --git a/intern/cycles/bvh/binning.cpp b/intern/cycles/bvh/binning.cpp index 567a7137c5e..3a8a0ff05c2 100644 --- a/intern/cycles/bvh/binning.cpp +++ b/intern/cycles/bvh/binning.cpp @@ -9,7 +9,7 @@ #include "bvh/binning.h" -#include +#include #include "util/algorithm.h" #include "util/boundbox.h" @@ -44,12 +44,10 @@ __forceinline int get_best_dimension(const float4 &bestSAH) if (bestSAH.x == minSAH) { return 0; } - else if (bestSAH.y == minSAH) { + if (bestSAH.y == minSAH) { return 1; } - else { - return 2; - } + return 2; } /* BVH Object Binning */ diff --git a/intern/cycles/bvh/binning.h b/intern/cycles/bvh/binning.h index 8c9d2a49ed4..86f10a0e30b 100644 --- a/intern/cycles/bvh/binning.h +++ b/intern/cycles/bvh/binning.h @@ -91,9 +91,7 @@ class BVHObjectBinning : public BVHRange { if (aligned_space_ == nullptr) { return prim.bounds(); } - else { - return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); - } + return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); } }; diff --git a/intern/cycles/bvh/build.cpp b/intern/cycles/bvh/build.cpp index 36ff054bb0d..244e37a8169 100644 --- a/intern/cycles/bvh/build.cpp +++ b/intern/cycles/bvh/build.cpp @@ -23,8 +23,6 @@ #include "util/foreach.h" #include "util/log.h" #include "util/progress.h" -#include "util/queue.h" -#include "util/simd.h" #include "util/stack_allocator.h" #include "util/time.h" @@ -52,7 +50,7 @@ BVHBuild::BVHBuild(const vector &objects_, spatial_min_overlap = 0.0f; } -BVHBuild::~BVHBuild() {} +BVHBuild::~BVHBuild() = default; /* Adding References */ @@ -69,7 +67,7 @@ void BVHBuild::add_reference_triangles(BoundBox &root, const size_t num_triangles = mesh->num_triangles(); for (uint j = 0; j < num_triangles; j++) { Mesh::Triangle t = mesh->get_triangle(j); - const float3 *verts = &mesh->verts[0]; + const float3 *verts = mesh->verts.data(); if (attr_mP == nullptr) { BoundBox bounds = BoundBox::empty; t.bounds_grow(verts, bounds); @@ -158,12 +156,12 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair const size_t num_curves = hair->num_curves(); for (uint j = 0; j < num_curves; j++) { const Hair::Curve curve = hair->get_curve(j); - const float *curve_radius = &hair->get_curve_radius()[0]; + const float *curve_radius = hair->get_curve_radius().data(); for (int k = 0; k < curve.num_keys - 1; k++) { if (curve_attr_mP == nullptr) { /* Really simple logic for static hair. */ BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &hair->get_curve_keys()[0], curve_radius, bounds); + curve.bounds_grow(k, hair->get_curve_keys().data(), curve_radius, bounds); if (bounds.valid()) { int packed_type = PRIMITIVE_PACK_SEGMENT(primitive_type, k); references.push_back(BVHReference(bounds, j, object_index, packed_type)); @@ -178,7 +176,7 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair */ /* TODO(sergey): Support motion steps for spatially split BVH. */ BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &hair->get_curve_keys()[0], curve_radius, bounds); + curve.bounds_grow(k, hair->get_curve_keys().data(), curve_radius, bounds); const size_t num_keys = hair->get_curve_keys().size(); const size_t num_steps = hair->get_motion_steps(); const float4 *key_steps = curve_attr_mP->data_float4(); @@ -200,7 +198,7 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair const int num_bvh_steps = params.num_motion_curve_steps * 2 + 1; const float num_bvh_steps_inv_1 = 1.0f / (num_bvh_steps - 1); const size_t num_steps = hair->get_motion_steps(); - const float3 *curve_keys = &hair->get_curve_keys()[0]; + const float3 *curve_keys = hair->get_curve_keys().data(); const float4 *key_steps = curve_attr_mP->data_float4(); const size_t num_keys = hair->get_curve_keys().size(); /* Calculate bounding box of the previous time step. @@ -268,8 +266,8 @@ void BVHBuild::add_reference_points(BoundBox &root, point_attr_mP = pointcloud->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); } - const float3 *points_data = &pointcloud->points[0]; - const float *radius_data = &pointcloud->radius[0]; + const float3 *points_data = pointcloud->points.data(); + const float *radius_data = pointcloud->radius.data(); const size_t num_points = pointcloud->num_points(); const float4 *motion_data = (point_attr_mP) ? point_attr_mP->data_float4() : nullptr; const size_t num_steps = pointcloud->get_motion_steps(); @@ -396,11 +394,11 @@ static size_t count_primitives(Geometry *geom) Mesh *mesh = static_cast(geom); return mesh->num_triangles(); } - else if (geom->is_hair()) { + if (geom->is_hair()) { Hair *hair = static_cast(geom); return count_curve_segments(hair); } - else if (geom->is_pointcloud()) { + if (geom->is_pointcloud()) { PointCloud *pointcloud = static_cast(geom); return pointcloud->num_points(); } @@ -524,7 +522,7 @@ BVHNode *BVHBuild::run() } else { /* Perform multithreaded binning build. */ - BVHObjectBinning rootbin(root, (references.size()) ? &references[0] : nullptr); + BVHObjectBinning rootbin(root, (!references.empty()) ? references.data() : nullptr); rootnode = build_node(rootbin, 0); task_pool.wait_work(); } @@ -714,9 +712,9 @@ BVHNode *BVHBuild::build_node(const BVHObjectBinning &range, int level) Transform aligned_space; bool do_unalinged_split = false; if (params.use_unaligned_nodes && splitSAH > params.unaligned_split_threshold * leafSAH) { - aligned_space = unaligned_heuristic.compute_aligned_space(range, &references[0]); + aligned_space = unaligned_heuristic.compute_aligned_space(range, references.data()); unaligned_range = BVHObjectBinning( - range, &references[0], &unaligned_heuristic, &aligned_space); + range, references.data(), &unaligned_heuristic, &aligned_space); unalignedSplitSAH = params.sah_node_cost * unaligned_range.unaligned_bounds().half_area() + params.sah_primitive_cost * unaligned_range.splitSAH; unalignedLeafSAH = params.sah_primitive_cost * unaligned_range.leafSAH; @@ -736,15 +734,15 @@ BVHNode *BVHBuild::build_node(const BVHObjectBinning &range, int level) /* Perform split. */ BVHObjectBinning left, right; if (do_unalinged_split) { - unaligned_range.split(&references[0], left, right); + unaligned_range.split(references.data(), left, right); } else { - range.split(&references[0], left, right); + range.split(references.data(), left, right); } BoundBox bounds; if (do_unalinged_split) { - bounds = unaligned_heuristic.compute_aligned_boundbox(range, &references[0], aligned_space); + bounds = unaligned_heuristic.compute_aligned_boundbox(range, references.data(), aligned_space); } else { bounds = range.bounds(); @@ -902,7 +900,7 @@ BVHNode *BVHBuild::create_object_leaf_nodes(const BVHReference *ref, int start, BoundBox bounds = BoundBox::empty; return new LeafNode(bounds, 0, 0, 0); } - else if (num == 1) { + if (num == 1) { assert(start < prim_type.size()); prim_type[start] = ref->prim_type(); prim_index[start] = ref->prim_index(); @@ -917,20 +915,19 @@ BVHNode *BVHBuild::create_object_leaf_nodes(const BVHReference *ref, int start, leaf_node->time_to = ref->time_to(); return leaf_node; } - else { - int mid = num / 2; - BVHNode *leaf0 = create_object_leaf_nodes(ref, start, mid); - BVHNode *leaf1 = create_object_leaf_nodes(ref + mid, start + mid, num - mid); - BoundBox bounds = BoundBox::empty; - bounds.grow(leaf0->bounds); - bounds.grow(leaf1->bounds); + int mid = num / 2; + BVHNode *leaf0 = create_object_leaf_nodes(ref, start, mid); + BVHNode *leaf1 = create_object_leaf_nodes(ref + mid, start + mid, num - mid); - BVHNode *inner_node = new InnerNode(bounds, leaf0, leaf1); - inner_node->time_from = min(leaf0->time_from, leaf1->time_from); - inner_node->time_to = max(leaf0->time_to, leaf1->time_to); - return inner_node; - } + BoundBox bounds = BoundBox::empty; + bounds.grow(leaf0->bounds); + bounds.grow(leaf1->bounds); + + BVHNode *inner_node = new InnerNode(bounds, leaf0, leaf1); + inner_node->time_from = min(leaf0->time_from, leaf1->time_from); + inner_node->time_to = max(leaf0->time_to, leaf1->time_to); + return inner_node; } BVHNode *BVHBuild::create_leaf_node(const BVHRange &range, const vector &references) @@ -950,9 +947,9 @@ BVHNode *BVHBuild::create_leaf_node(const BVHRange &range, const vector LeafStackAllocator; - typedef StackAllocator<256, float2> LeafTimeStackAllocator; - typedef StackAllocator<256, BVHReference> LeafReferenceStackAllocator; + using LeafStackAllocator = StackAllocator<256, int>; + using LeafTimeStackAllocator = StackAllocator<256, float2>; + using LeafReferenceStackAllocator = StackAllocator<256, BVHReference>; vector p_type[PRIMITIVE_NUM]; vector p_index[PRIMITIVE_NUM]; @@ -1097,11 +1094,12 @@ BVHNode *BVHBuild::create_leaf_node(const BVHRange &range, const vector 0) { - memcpy(&prim_type[start_index], &local_prim_type[0], new_leaf_data_size); - memcpy(&prim_index[start_index], &local_prim_index[0], new_leaf_data_size); - memcpy(&prim_object[start_index], &local_prim_object[0], new_leaf_data_size); + memcpy(&prim_type[start_index], local_prim_type.data(), new_leaf_data_size); + memcpy(&prim_index[start_index], local_prim_index.data(), new_leaf_data_size); + memcpy(&prim_object[start_index], local_prim_object.data(), new_leaf_data_size); if (need_prim_time) { - memcpy(&prim_time[start_index], &local_prim_time[0], sizeof(float2) * num_new_leaf_data); + memcpy( + &prim_time[start_index], local_prim_time.data(), sizeof(float2) * num_new_leaf_data); } } spatial_spin_lock.unlock(); @@ -1113,11 +1111,12 @@ BVHNode *BVHBuild::create_leaf_node(const BVHRange &range, const vector 0) { - memcpy(&prim_type[start_index], &local_prim_type[0], new_leaf_data_size); - memcpy(&prim_index[start_index], &local_prim_index[0], new_leaf_data_size); - memcpy(&prim_object[start_index], &local_prim_object[0], new_leaf_data_size); + memcpy(&prim_type[start_index], local_prim_type.data(), new_leaf_data_size); + memcpy(&prim_index[start_index], local_prim_index.data(), new_leaf_data_size); + memcpy(&prim_object[start_index], local_prim_object.data(), new_leaf_data_size); if (need_prim_time) { - memcpy(&prim_time[start_index], &local_prim_time[0], sizeof(float2) * num_new_leaf_data); + memcpy( + &prim_time[start_index], local_prim_time.data(), sizeof(float2) * num_new_leaf_data); } } } @@ -1137,7 +1136,7 @@ BVHNode *BVHBuild::create_leaf_node(const BVHRange &range, const vectorbounds, leaves[2]->bounds); BVHNode *inner = new InnerNode(inner_bounds, leaves[1], leaves[2]); return new InnerNode(range.bounds(), leaves[0], inner); } - else { - /* Should be doing more branches if more primitive types added. */ - assert(num_leaves <= 5); - BoundBox inner_bounds_a = merge(leaves[0]->bounds, leaves[1]->bounds); - BoundBox inner_bounds_b = merge(leaves[2]->bounds, leaves[3]->bounds); - BVHNode *inner_a = new InnerNode(inner_bounds_a, leaves[0], leaves[1]); - BVHNode *inner_b = new InnerNode(inner_bounds_b, leaves[2], leaves[3]); - BoundBox inner_bounds_c = merge(inner_a->bounds, inner_b->bounds); - BVHNode *inner_c = new InnerNode(inner_bounds_c, inner_a, inner_b); - if (num_leaves == 5) { - return new InnerNode(range.bounds(), inner_c, leaves[4]); - } - return inner_c; + + /* Should be doing more branches if more primitive types added. */ + assert(num_leaves <= 5); + BoundBox inner_bounds_a = merge(leaves[0]->bounds, leaves[1]->bounds); + BoundBox inner_bounds_b = merge(leaves[2]->bounds, leaves[3]->bounds); + BVHNode *inner_a = new InnerNode(inner_bounds_a, leaves[0], leaves[1]); + BVHNode *inner_b = new InnerNode(inner_bounds_b, leaves[2], leaves[3]); + BoundBox inner_bounds_c = merge(inner_a->bounds, inner_b->bounds); + BVHNode *inner_c = new InnerNode(inner_bounds_c, inner_a, inner_b); + if (num_leaves == 5) { + return new InnerNode(range.bounds(), inner_c, leaves[4]); } + return inner_c; #undef MAX_ITEMS_PER_LEAF } diff --git a/intern/cycles/bvh/build.h b/intern/cycles/bvh/build.h index eeeddf710f9..f696e74f5b4 100644 --- a/intern/cycles/bvh/build.h +++ b/intern/cycles/bvh/build.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "bvh/params.h" #include "bvh/unaligned.h" @@ -56,10 +56,10 @@ class BVHBuild { friend class BVHObjectBinning; /* Adding references. */ - void add_reference_triangles(BoundBox &root, BoundBox ¢er, Mesh *mesh, int i); - void add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair, int i); + void add_reference_triangles(BoundBox &root, BoundBox ¢er, Mesh *mesh, int object_index); + void add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair, int object_index); void add_reference_points(BoundBox &root, BoundBox ¢er, PointCloud *pointcloud, int i); - void add_reference_geometry(BoundBox &root, BoundBox ¢er, Geometry *geom, int i); + void add_reference_geometry(BoundBox &root, BoundBox ¢er, Geometry *geom, int object_index); void add_reference_object(BoundBox &root, BoundBox ¢er, Object *ob, int i); void add_references(BVHRange &root); @@ -77,8 +77,8 @@ class BVHBuild { /* Threads. */ enum { THREAD_TASK_SIZE = 4096 }; - void thread_build_node(InnerNode *node, int child, const BVHObjectBinning &range, int level); - void thread_build_spatial_split_node(InnerNode *node, + void thread_build_node(InnerNode *inner, int child, const BVHObjectBinning &range, int level); + void thread_build_spatial_split_node(InnerNode *inner, int child, const BVHRange &range, vector &references, diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 910c8dff6dd..bf9510a133e 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -8,14 +8,22 @@ #include "bvh/bvh.h" #include "bvh/bvh2.h" -#include "bvh/embree.h" -#include "bvh/hiprt.h" -#include "bvh/metal.h" #include "bvh/multi.h" -#include "bvh/optix.h" + +#ifdef WITH_EMBREE +# include "bvh/embree.h" +#endif +#ifdef WITH_HIPRT +# include "bvh/hiprt.h" +#endif +#ifdef WITH_METAL +# include "bvh/metal.h" +#endif +#ifdef WITH_OPTIX +# include "bvh/optix.h" +#endif #include "util/log.h" -#include "util/progress.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h index a247471ce7c..36374f01d93 100644 --- a/intern/cycles/bvh/bvh.h +++ b/intern/cycles/bvh/bvh.h @@ -25,8 +25,9 @@ class Object; class Progress; class Stats; -#define BVH_ALIGN 4096 -#define TRI_NODE_SIZE 3 +#define BVH_ALIGN 4096 // NOLINT +#define TRI_NODE_SIZE 3 // NOLINT + /* Packed BVH * * BVH stored as it will be used for traversal on the rendering device. */ @@ -72,7 +73,7 @@ class BVH { const vector &geometry, const vector &objects, Device *device); - virtual ~BVH() {} + virtual ~BVH() = default; virtual void replace_geometry(const vector &geometry, const vector &objects) diff --git a/intern/cycles/bvh/bvh2.cpp b/intern/cycles/bvh/bvh2.cpp index 386b168a910..b5c6f68efe2 100644 --- a/intern/cycles/bvh/bvh2.cpp +++ b/intern/cycles/bvh/bvh2.cpp @@ -35,7 +35,7 @@ BVH2::BVH2(const BVHParams ¶ms_, { } -void BVH2::build(Progress &progress, Stats *) +void BVH2::build(Progress &progress, Stats * /*unused*/) { progress.set_substatus("Building BVH"); @@ -201,8 +201,8 @@ void BVH2::pack_unaligned_inner(const BVHStackEntry &e, void BVH2::pack_unaligned_node(int idx, const Transform &aligned_space0, const Transform &aligned_space1, - const BoundBox &bounds0, - const BoundBox &bounds1, + const BoundBox &b0, + const BoundBox &b1, int c0, int c1, uint visibility0, @@ -213,8 +213,8 @@ void BVH2::pack_unaligned_node(int idx, assert(c1 < 0 || c1 < pack.nodes.size()); float4 data[BVH_UNALIGNED_NODE_SIZE]; - Transform space0 = BVHUnaligned::compute_node_transform(bounds0, aligned_space0); - Transform space1 = BVHUnaligned::compute_node_transform(bounds1, aligned_space1); + Transform space0 = BVHUnaligned::compute_node_transform(b0, aligned_space0); + Transform space1 = BVHUnaligned::compute_node_transform(b1, aligned_space1); data[0] = make_float4(__int_as_float(visibility0 | PATH_RAY_NODE_UNALIGNED), __int_as_float(visibility1 | PATH_RAY_NODE_UNALIGNED), __int_as_float(c0), @@ -269,7 +269,7 @@ void BVH2::pack_nodes(const BVHNode *root) nextNodeIdx += root->has_unaligned() ? BVH_UNALIGNED_NODE_SIZE : BVH_NODE_SIZE; } - while (stack.size()) { + while (!stack.empty()) { BVHStackEntry e = stack.back(); stack.pop_back(); @@ -383,7 +383,7 @@ void BVH2::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility Hair::Curve curve = hair->get_curve(pidx - prim_offset); int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]); - curve.bounds_grow(k, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], bbox); + curve.bounds_grow(k, hair->get_curve_keys().data(), hair->get_curve_radius().data(), bbox); /* Motion curves. */ if (hair->get_use_motion_blur()) { @@ -395,7 +395,8 @@ void BVH2::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility float3 *key_steps = attr->data_float3(); for (size_t i = 0; i < steps; i++) { - curve.bounds_grow(k, key_steps + i * hair_size, &hair->get_curve_radius()[0], bbox); + curve.bounds_grow( + k, key_steps + i * hair_size, hair->get_curve_radius().data(), bbox); } } } @@ -404,8 +405,8 @@ void BVH2::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility /* Points. */ const PointCloud *pointcloud = static_cast(ob->get_geometry()); int prim_offset = (params.top_level) ? pointcloud->prim_offset : 0; - const float3 *points = &pointcloud->points[0]; - const float *radius = &pointcloud->radius[0]; + const float3 *points = pointcloud->points.data(); + const float *radius = pointcloud->radius.data(); PointCloud::Point point = pointcloud->get_point(pidx - prim_offset); point.bounds_grow(points, radius, bbox); @@ -430,7 +431,7 @@ void BVH2::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility const Mesh *mesh = static_cast(ob->get_geometry()); int prim_offset = (params.top_level) ? mesh->prim_offset : 0; Mesh::Triangle triangle = mesh->get_triangle(pidx - prim_offset); - const float3 *vpos = &mesh->verts[0]; + const float3 *vpos = mesh->verts.data(); triangle.bounds_grow(vpos, bbox); @@ -528,13 +529,14 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size) pack.prim_time.resize(prim_index_size); } - int *pack_prim_index = (pack.prim_index.size()) ? &pack.prim_index[0] : nullptr; - int *pack_prim_type = (pack.prim_type.size()) ? &pack.prim_type[0] : nullptr; - int *pack_prim_object = (pack.prim_object.size()) ? &pack.prim_object[0] : nullptr; - uint *pack_prim_visibility = (pack.prim_visibility.size()) ? &pack.prim_visibility[0] : nullptr; - int4 *pack_nodes = (pack.nodes.size()) ? &pack.nodes[0] : nullptr; - int4 *pack_leaf_nodes = (pack.leaf_nodes.size()) ? &pack.leaf_nodes[0] : nullptr; - float2 *pack_prim_time = (pack.prim_time.size()) ? &pack.prim_time[0] : nullptr; + int *pack_prim_index = (pack.prim_index.size()) ? pack.prim_index.data() : nullptr; + int *pack_prim_type = (pack.prim_type.size()) ? pack.prim_type.data() : nullptr; + int *pack_prim_object = (pack.prim_object.size()) ? pack.prim_object.data() : nullptr; + uint *pack_prim_visibility = (pack.prim_visibility.size()) ? pack.prim_visibility.data() : + nullptr; + int4 *pack_nodes = (pack.nodes.size()) ? pack.nodes.data() : nullptr; + int4 *pack_leaf_nodes = (pack.leaf_nodes.size()) ? pack.leaf_nodes.data() : nullptr; + float2 *pack_prim_time = (pack.prim_time.size()) ? pack.prim_time.data() : nullptr; unordered_map geometry_map; @@ -579,10 +581,10 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size) /* merge primitive, object and triangle indexes */ if (bvh->pack.prim_index.size()) { size_t bvh_prim_index_size = bvh->pack.prim_index.size(); - int *bvh_prim_index = &bvh->pack.prim_index[0]; - int *bvh_prim_type = &bvh->pack.prim_type[0]; - uint *bvh_prim_visibility = &bvh->pack.prim_visibility[0]; - float2 *bvh_prim_time = bvh->pack.prim_time.size() ? &bvh->pack.prim_time[0] : nullptr; + int *bvh_prim_index = bvh->pack.prim_index.data(); + int *bvh_prim_type = bvh->pack.prim_type.data(); + uint *bvh_prim_visibility = bvh->pack.prim_visibility.data(); + float2 *bvh_prim_time = bvh->pack.prim_time.size() ? bvh->pack.prim_time.data() : nullptr; for (size_t i = 0; i < bvh_prim_index_size; i++) { pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset; @@ -598,7 +600,7 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size) /* merge nodes */ if (bvh->pack.leaf_nodes.size()) { - int4 *leaf_nodes_offset = &bvh->pack.leaf_nodes[0]; + int4 *leaf_nodes_offset = bvh->pack.leaf_nodes.data(); size_t leaf_nodes_offset_size = bvh->pack.leaf_nodes.size(); for (size_t i = 0, j = 0; i < leaf_nodes_offset_size; i += BVH_NODE_LEAF_SIZE, j++) { int4 data = leaf_nodes_offset[i]; @@ -613,7 +615,7 @@ void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size) } if (bvh->pack.nodes.size()) { - int4 *bvh_nodes = &bvh->pack.nodes[0]; + int4 *bvh_nodes = bvh->pack.nodes.data(); size_t bvh_nodes_size = bvh->pack.nodes.size(); for (size_t i = 0; i < bvh_nodes_size;) { diff --git a/intern/cycles/bvh/bvh2.h b/intern/cycles/bvh/bvh2.h index d0d5006cda5..18b006e4a07 100644 --- a/intern/cycles/bvh/bvh2.h +++ b/intern/cycles/bvh/bvh2.h @@ -15,16 +15,18 @@ CCL_NAMESPACE_BEGIN +// NOLINTBEGIN #define BVH_NODE_SIZE 4 #define BVH_NODE_LEAF_SIZE 1 #define BVH_UNALIGNED_NODE_SIZE 7 +// NOLINTEND /* Pack Utility */ struct BVHStackEntry { const BVHNode *node; int idx; - BVHStackEntry(const BVHNode *n = 0, int i = 0); + BVHStackEntry(const BVHNode *n = nullptr, int i = 0); int encodeIdx() const; }; diff --git a/intern/cycles/bvh/embree.cpp b/intern/cycles/bvh/embree.cpp index 17448715b5e..af19eade597 100644 --- a/intern/cycles/bvh/embree.cpp +++ b/intern/cycles/bvh/embree.cpp @@ -26,9 +26,6 @@ # include "bvh/embree.h" -# include "kernel/device/cpu/bvh.h" -# include "kernel/globals.h" - # include "scene/hair.h" # include "scene/mesh.h" # include "scene/object.h" @@ -48,7 +45,7 @@ static_assert(Object::MAX_MOTION_STEPS == Geometry::MAX_MOTION_STEPS, static size_t unaccounted_mem = 0; -static bool rtc_memory_monitor_func(void *userPtr, const ssize_t bytes, const bool) +static bool rtc_memory_monitor_func(void *userPtr, const ssize_t bytes, const bool /*unused*/) { Stats *stats = (Stats *)userPtr; if (stats) { @@ -71,7 +68,7 @@ static bool rtc_memory_monitor_func(void *userPtr, const ssize_t bytes, const bo return true; } -static void rtc_error_func(void *, enum RTCError, const char *str) +static void rtc_error_func(void * /*unused*/, enum RTCError /*unused*/, const char *str) { VLOG_WARNING << str; } @@ -165,8 +162,9 @@ void BVHEmbree::build(Progress &progress, add_object(ob, i); } ++i; - if (progress.get_cancel()) + if (progress.get_cancel()) { return; + } } if (progress.get_cancel()) { @@ -221,8 +219,9 @@ RTCError BVHEmbree::offload_scenes_to_gpu(const vector &scenes) /* In case of any errors from Embree, we should stop * the execution and propagate the error. */ RTCError error_code = rtcGetDeviceError(rtc_device); - if (error_code != RTC_ERROR_NONE) + if (error_code != RTC_ERROR_NONE) { return error_code; + } } return RTC_ERROR_NONE; } @@ -484,7 +483,7 @@ void BVHEmbree::set_curve_vertex_buffer(RTCGeometry geom_id, const Hair *hair, c /* Copy the CV data to Embree */ const int t_mid = (num_motion_steps - 1) / 2; - const float *curve_radius = &hair->get_curve_radius()[0]; + const float *curve_radius = hair->get_curve_radius().data(); for (int t = 0; t < num_motion_steps; ++t) { // As float4 and float3 are no longer interchangeable the 2 types need to be // handled separately. Attributes are float4s where the radius is stored in w and @@ -503,7 +502,7 @@ void BVHEmbree::set_curve_vertex_buffer(RTCGeometry geom_id, const Hair *hair, c if (rtc_verts) { const size_t num_curves = hair->num_curves(); if (t == t_mid || attr_mP == nullptr) { - const float3 *verts = &hair->get_curve_keys()[0]; + const float3 *verts = hair->get_curve_keys().data(); pack_motion_verts(num_curves, hair, verts, curve_radius, rtc_verts); } else { diff --git a/intern/cycles/bvh/embree.h b/intern/cycles/bvh/embree.h index 4fb53206cfb..bedbbb78eca 100644 --- a/intern/cycles/bvh/embree.h +++ b/intern/cycles/bvh/embree.h @@ -17,9 +17,6 @@ # include "bvh/bvh.h" # include "bvh/params.h" -# include "util/string.h" -# include "util/thread.h" -# include "util/types.h" # include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -33,7 +30,7 @@ class BVHEmbree : public BVH { void build(Progress &progress, Stats *stats, RTCDevice rtc_device, - const bool isSyclEmbreeDevice = false); + const bool rtc_device_is_sycl_ = false); void refit(Progress &progress); # if defined(WITH_EMBREE_GPU) && RTC_VERSION >= 40302 @@ -49,7 +46,7 @@ class BVHEmbree : public BVH { BVHEmbree(const BVHParams ¶ms, const vector &geometry, const vector &objects); - virtual ~BVHEmbree(); + ~BVHEmbree() override; void add_object(Object *ob, int i); void add_instance(Object *ob, int i); diff --git a/intern/cycles/bvh/hiprt.cpp b/intern/cycles/bvh/hiprt.cpp index c1daf2e4e89..363d53b3a8a 100644 --- a/intern/cycles/bvh/hiprt.cpp +++ b/intern/cycles/bvh/hiprt.cpp @@ -9,9 +9,6 @@ # include "scene/mesh.h" # include "scene/object.h" -# include "util/foreach.h" -# include "util/progress.h" - # include "device/hiprt/device_impl.h" CCL_NAMESPACE_BEGIN @@ -21,14 +18,14 @@ BVHHIPRT::BVHHIPRT(const BVHParams ¶ms, const vector &objects, Device *in_device) : BVH(params, geometry, objects), - hiprt_geom(0), + hiprt_geom(nullptr), custom_primitive_bound(in_device, "Custom Primitive Bound", MEM_READ_ONLY), triangle_index(in_device, "HIPRT Triangle Index", MEM_READ_ONLY), vertex_data(in_device, "vertex_data", MEM_READ_ONLY), device(in_device) { - triangle_mesh = {0}; - custom_prim_aabb = {0}; + triangle_mesh = {nullptr}; + custom_prim_aabb = {nullptr}; } BVHHIPRT::~BVHHIPRT() diff --git a/intern/cycles/bvh/hiprt.h b/intern/cycles/bvh/hiprt.h index b9954fb88b7..44e7e518f8b 100644 --- a/intern/cycles/bvh/hiprt.h +++ b/intern/cycles/bvh/hiprt.h @@ -10,7 +10,7 @@ # include "bvh/params.h" # ifdef WITH_HIP_DYNLOAD -# include "hiprtew.h" +# include # else # include # endif @@ -48,7 +48,7 @@ class BVHHIPRT : public BVH { const vector &objects, Device *in_device); - virtual ~BVHHIPRT(); + ~BVHHIPRT() override; private: Device *device; diff --git a/intern/cycles/bvh/multi.h b/intern/cycles/bvh/multi.h index 44ef92cb21b..5036f987bf5 100644 --- a/intern/cycles/bvh/multi.h +++ b/intern/cycles/bvh/multi.h @@ -18,10 +18,10 @@ class BVHMulti : public BVH { BVHMulti(const BVHParams ¶ms, const vector &geometry, const vector &objects); - virtual ~BVHMulti(); + ~BVHMulti() override; - virtual void replace_geometry(const vector &geometry, - const vector &objects); + void replace_geometry(const vector &geometry, + const vector &objects) override; }; CCL_NAMESPACE_END diff --git a/intern/cycles/bvh/node.cpp b/intern/cycles/bvh/node.cpp index 1ff4dff2941..e45879ccb1a 100644 --- a/intern/cycles/bvh/node.cpp +++ b/intern/cycles/bvh/node.cpp @@ -10,8 +10,6 @@ #include "bvh/build.h" #include "bvh/bvh.h" -#include "util/vector.h" - CCL_NAMESPACE_BEGIN /* BVH Node */ diff --git a/intern/cycles/bvh/node.h b/intern/cycles/bvh/node.h index a84a26b755f..c28579137a7 100644 --- a/intern/cycles/bvh/node.h +++ b/intern/cycles/bvh/node.h @@ -45,7 +45,7 @@ class BVHNode { } virtual void print(int depth = 0) const = 0; - inline void set_aligned_space(const Transform &aligned_space) + void set_aligned_space(const Transform &aligned_space) { is_unaligned = true; if (this->aligned_space == nullptr) { @@ -56,7 +56,7 @@ class BVHNode { } } - inline Transform get_aligned_space() const + Transform get_aligned_space() const { if (aligned_space == nullptr) { return transform_identity(); @@ -64,7 +64,7 @@ class BVHNode { return *aligned_space; } - inline bool has_unaligned() const + bool has_unaligned() const { if (is_leaf()) { return false; @@ -90,33 +90,25 @@ class BVHNode { // Properties. BoundBox bounds; - uint visibility; + uint visibility = 0; - bool is_unaligned; + bool is_unaligned = false; /* TODO(sergey): Can be stored as 3x3 matrix, but better to have some * utilities and type defines in util_transform first. */ - Transform *aligned_space; + Transform *aligned_space = nullptr; - float time_from, time_to; + float time_from = 0.0f, time_to = 1.0f; protected: - explicit BVHNode(const BoundBox &bounds) - : bounds(bounds), - visibility(0), - is_unaligned(false), - aligned_space(nullptr), - time_from(0.0f), - time_to(1.0f) - { - } + explicit BVHNode(const BoundBox &bounds) : bounds(bounds) {} explicit BVHNode(const BVHNode &other) : bounds(other.bounds), visibility(other.visibility), is_unaligned(other.is_unaligned), - aligned_space(nullptr), + time_from(other.time_from), time_to(other.time_to) { @@ -177,20 +169,20 @@ class InnerNode : public BVHNode { num_children_ = 2; } - bool is_leaf() const + bool is_leaf() const override { return false; } - int num_children() const + int num_children() const override { return num_children_; } - BVHNode *get_child(int i) const + BVHNode *get_child(int i) const override { assert(i >= 0 && i < num_children_); return children[i]; } - void print(int depth) const; + void print(int depth) const override; int num_children_; BVHNode *children[kNumMaxChildren]; @@ -213,25 +205,25 @@ class LeafNode : public BVHNode { this->visibility = visibility; } - LeafNode(const LeafNode &other) : BVHNode(other), lo(other.lo), hi(other.hi) {} + LeafNode(const LeafNode &other) = default; - bool is_leaf() const + bool is_leaf() const override { return true; } - int num_children() const + int num_children() const override { return 0; } - BVHNode *get_child(int) const + BVHNode *get_child(int /*i*/) const override { return nullptr; } - int num_triangles() const + int num_triangles() const override { return hi - lo; } - void print(int depth) const; + void print(int depth) const override; int lo; int hi; diff --git a/intern/cycles/bvh/optix.h b/intern/cycles/bvh/optix.h index b6871ab1066..2de45020582 100644 --- a/intern/cycles/bvh/optix.h +++ b/intern/cycles/bvh/optix.h @@ -29,7 +29,7 @@ class BVHOptiX : public BVH { const vector &geometry, const vector &objects, Device *device); - virtual ~BVHOptiX(); + ~BVHOptiX() override; }; CCL_NAMESPACE_END diff --git a/intern/cycles/bvh/params.h b/intern/cycles/bvh/params.h index 0939c4b4006..8d395f8046b 100644 --- a/intern/cycles/bvh/params.h +++ b/intern/cycles/bvh/params.h @@ -19,7 +19,7 @@ CCL_NAMESPACE_BEGIN * For example, how wide BVH tree is, in terms of number of children * per node. */ -typedef KernelBVHLayout BVHLayout; +using BVHLayout = KernelBVHLayout; /* Type of BVH, in terms whether it is supported dynamic updates of meshes * or whether modifying geometry requires full BVH rebuild. @@ -47,7 +47,7 @@ enum BVHType { * * Bit-flags are the BVH_LAYOUT_* values. */ -typedef int BVHLayoutMask; +using BVHLayoutMask = int; /* Get human readable name of BVH layout. */ const char *bvh_layout_name(BVHLayout layout); @@ -186,7 +186,7 @@ class BVHParams { class BVHReference { public: - __forceinline BVHReference() {} + __forceinline BVHReference() = default; __forceinline BVHReference(const BoundBox &bounds_, int prim_index_, @@ -308,7 +308,7 @@ struct BVHSpatialBin { int enter; int exit; - __forceinline BVHSpatialBin() {} + __forceinline BVHSpatialBin() = default; }; /* BVH Spatial Storage diff --git a/intern/cycles/bvh/sort.cpp b/intern/cycles/bvh/sort.cpp index a5c4e03c698..abcb86fe64d 100644 --- a/intern/cycles/bvh/sort.cpp +++ b/intern/cycles/bvh/sort.cpp @@ -7,7 +7,8 @@ #include "bvh/sort.h" -#include "bvh/build.h" +#include "bvh/params.h" +#include "bvh/unaligned.h" #include "util/algorithm.h" #include "util/task.h" @@ -49,25 +50,25 @@ struct BVHReferenceCompare { if (ca < cb) { return -1; } - else if (ca > cb) { + if (ca > cb) { return 1; } - else if (ra.prim_object() < rb.prim_object()) { + if (ra.prim_object() < rb.prim_object()) { return -1; } - else if (ra.prim_object() > rb.prim_object()) { + if (ra.prim_object() > rb.prim_object()) { return 1; } - else if (ra.prim_index() < rb.prim_index()) { + if (ra.prim_index() < rb.prim_index()) { return -1; } - else if (ra.prim_index() > rb.prim_index()) { + if (ra.prim_index() > rb.prim_index()) { return 1; } - else if (ra.prim_type() < rb.prim_type()) { + if (ra.prim_type() < rb.prim_type()) { return -1; } - else if (ra.prim_type() > rb.prim_type()) { + if (ra.prim_type() > rb.prim_type()) { return 1; } diff --git a/intern/cycles/bvh/sort.h b/intern/cycles/bvh/sort.h index 6c2c150dafb..edb7d80056b 100644 --- a/intern/cycles/bvh/sort.h +++ b/intern/cycles/bvh/sort.h @@ -7,8 +7,6 @@ #pragma once -#include - CCL_NAMESPACE_BEGIN class BVHReference; diff --git a/intern/cycles/bvh/split.cpp b/intern/cycles/bvh/split.cpp index 4856b4c72e1..d9324be58b5 100644 --- a/intern/cycles/bvh/split.cpp +++ b/intern/cycles/bvh/split.cpp @@ -89,7 +89,7 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder, void BVHObjectSplit::split(BVHRange &left, BVHRange &right, const BVHRange &range) { - assert(references_->size() > 0); + assert(!references_->empty()); /* sort references according to split */ bvh_reference_sort(range.start(), range.end(), @@ -318,7 +318,7 @@ void BVHSpatialSplit::split(BVHBuild *builder, } } /* Insert duplicated references into actual array in one go. */ - if (new_refs.size() != 0) { + if (!new_refs.empty()) { refs.insert(refs.begin() + (right_end - new_refs.size()), new_refs.begin(), new_refs.end()); } if (aligned_space_ != nullptr) { @@ -345,7 +345,7 @@ void BVHSpatialSplit::split_triangle_primitive(const Mesh *mesh, BoundBox &right_bounds) { Mesh::Triangle t = mesh->get_triangle(prim_index); - const float3 *verts = &mesh->verts[0]; + const float3 *verts = mesh->verts.data(); float3 v1 = tfm ? transform_point(tfm, verts[t.v[2]]) : verts[t.v[2]]; v1 = get_unaligned_point(v1); diff --git a/intern/cycles/bvh/split.h b/intern/cycles/bvh/split.h index 51418b03520..1d781094c12 100644 --- a/intern/cycles/bvh/split.h +++ b/intern/cycles/bvh/split.h @@ -28,7 +28,7 @@ class BVHObjectSplit { BoundBox left_bounds; BoundBox right_bounds; - BVHObjectSplit() {} + BVHObjectSplit() = default; BVHObjectSplit(BVHBuild *builder, BVHSpatialStorage *storage, const BVHRange &range, @@ -50,9 +50,7 @@ class BVHObjectSplit { if (aligned_space_ == nullptr) { return prim.bounds(); } - else { - return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); - } + return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); } }; @@ -148,9 +146,7 @@ class BVHSpatialSplit { if (aligned_space_ == nullptr) { return prim.bounds(); } - else { - return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); - } + return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_); } __forceinline float3 get_unaligned_point(const float3 &point) const @@ -158,9 +154,7 @@ class BVHSpatialSplit { if (aligned_space_ == nullptr) { return point; } - else { - return transform_point(aligned_space_, point); - } + return transform_point(aligned_space_, point); } }; @@ -179,7 +173,7 @@ class BVHMixedSplit { BoundBox bounds; - BVHMixedSplit() {} + BVHMixedSplit() = default; __forceinline BVHMixedSplit(BVHBuild *builder, BVHSpatialStorage *storage, @@ -225,10 +219,12 @@ class BVHMixedSplit { BVHRange &right, const BVHRange &range) { - if (builder->params.use_spatial_split && minSAH == spatial.sah) + if (builder->params.use_spatial_split && minSAH == spatial.sah) { spatial.split(builder, left, right, range); - if (!left.size() || !right.size()) + } + if (!left.size() || !right.size()) { object.split(left, right, range); + } } }; diff --git a/intern/cycles/bvh/unaligned.cpp b/intern/cycles/bvh/unaligned.cpp index 6daec999847..61122974f64 100644 --- a/intern/cycles/bvh/unaligned.cpp +++ b/intern/cycles/bvh/unaligned.cpp @@ -86,8 +86,11 @@ BoundBox BVHUnaligned::compute_aligned_prim_boundbox(const BVHReference &prim, const int segment = PRIMITIVE_UNPACK_SEGMENT(packed_type); const Hair *hair = static_cast(object->get_geometry()); const Hair::Curve &curve = hair->get_curve(curve_index); - curve.bounds_grow( - segment, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], aligned_space, bounds); + curve.bounds_grow(segment, + hair->get_curve_keys().data(), + hair->get_curve_radius().data(), + aligned_space, + bounds); } else { bounds = prim.bounds().transformed(&aligned_space); diff --git a/intern/cycles/device/cpu/device.cpp b/intern/cycles/device/cpu/device.cpp index 9c79df3c473..b26cf98944f 100644 --- a/intern/cycles/device/cpu/device.cpp +++ b/intern/cycles/device/cpu/device.cpp @@ -4,7 +4,6 @@ #include "device/cpu/device.h" #include "device/cpu/device_impl.h" -#include "integrator/denoiser_oidn.h" /* Used for `info.denoisers`. */ /* TODO(sergey): The denoisers are probably to be moved completely out of the device into their @@ -45,7 +44,7 @@ void device_cpu_info(vector &devices) string device_cpu_capabilities() { - string capabilities = ""; + string capabilities; capabilities += system_cpu_support_sse42() ? "SSE42 " : ""; capabilities += system_cpu_support_avx2() ? "AVX2" : ""; if (capabilities[capabilities.size() - 1] == ' ') { diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp index 0de6940438a..8730682a766 100644 --- a/intern/cycles/device/cpu/device_impl.cpp +++ b/intern/cycles/device/cpu/device_impl.cpp @@ -4,13 +4,15 @@ #include "device/cpu/device_impl.h" -#include -#include +#include +#include /* So ImathMath is included before our kernel_cpu_compat. */ #ifdef WITH_OSL /* So no context pollution happens from indirectly included windows.h */ -# include "util/windows.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif # include #endif @@ -27,29 +29,19 @@ #include "device/device.h" -// clang-format off -#include "kernel/globals.h" #include "kernel/device/cpu/kernel.h" +#include "kernel/globals.h" #include "kernel/types.h" -#include "kernel/osl/globals.h" -// clang-format on - #include "bvh/embree.h" #include "session/buffers.h" -#include "util/debug.h" #include "util/foreach.h" #include "util/guiding.h" #include "util/log.h" -#include "util/map.h" -#include "util/openimagedenoise.h" -#include "util/optimization.h" #include "util/progress.h" -#include "util/system.h" #include "util/task.h" -#include "util/thread.h" CCL_NAMESPACE_BEGIN @@ -282,7 +274,9 @@ void CPUDevice::build_bvh(BVH *bvh, Progress &progress, bool refit) } else #endif + { Device::build_bvh(bvh, progress, refit); + } } void *CPUDevice::get_guiding_device() const diff --git a/intern/cycles/device/cpu/device_impl.h b/intern/cycles/device/cpu/device_impl.h index dc7d338cb53..56eb3ab08ee 100644 --- a/intern/cycles/device/cpu/device_impl.h +++ b/intern/cycles/device/cpu/device_impl.h @@ -7,7 +7,9 @@ /* So ImathMath is included before our kernel_cpu_compat. */ #ifdef WITH_OSL /* So no context pollution happens from indirectly included windows.h */ -# include "util/windows.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif # include #endif @@ -54,25 +56,22 @@ class CPUDevice : public Device { #endif CPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_, bool headless_); - ~CPUDevice(); + ~CPUDevice() override; - virtual BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; + BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; /* Returns true if the texture info was copied to the device (meaning, some more * re-initialization might be needed). */ bool load_texture_info(); - virtual void mem_alloc(device_memory &mem) override; - virtual void mem_copy_to(device_memory &mem) override; - virtual void mem_copy_from( - device_memory &mem, size_t y, size_t w, size_t h, size_t elem) override; - virtual void mem_zero(device_memory &mem) override; - virtual void mem_free(device_memory &mem) override; - virtual device_ptr mem_alloc_sub_ptr(device_memory &mem, - size_t offset, - size_t /*size*/) override; + void mem_alloc(device_memory &mem) override; + void mem_copy_to(device_memory &mem) override; + void mem_copy_from(device_memory &mem, size_t y, size_t w, size_t h, size_t elem) override; + void mem_zero(device_memory &mem) override; + void mem_free(device_memory &mem) override; + device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, size_t size) override; void global_alloc(device_memory &mem); void global_free(device_memory &mem); @@ -84,12 +83,12 @@ class CPUDevice : public Device { void *get_guiding_device() const override; - virtual void get_cpu_kernel_thread_globals( + void get_cpu_kernel_thread_globals( vector &kernel_thread_globals) override; - virtual void *get_cpu_osl_memory() override; + void *get_cpu_osl_memory() override; protected: - virtual bool load_kernels(uint /*kernel_features*/) override; + bool load_kernels(uint /*kernel_features*/) override; }; CCL_NAMESPACE_END diff --git a/intern/cycles/device/cpu/kernel.h b/intern/cycles/device/cpu/kernel.h index a69f4b906e4..7dfc18d992a 100644 --- a/intern/cycles/device/cpu/kernel.h +++ b/intern/cycles/device/cpu/kernel.h @@ -6,7 +6,6 @@ #include "device/cpu/kernel_function.h" #include "util/half.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/device/cpu/kernel_function.h b/intern/cycles/device/cpu/kernel_function.h index edd920e40b8..126b9cd7cdf 100644 --- a/intern/cycles/device/cpu/kernel_function.h +++ b/intern/cycles/device/cpu/kernel_function.h @@ -4,8 +4,8 @@ #pragma once -#include "util/debug.h" -#include "util/system.h" +#include "util/debug.h" // IWYU pragma: keep +#include "util/system.h" // IWYU pragma: keep CCL_NAMESPACE_BEGIN @@ -23,7 +23,7 @@ template class CPUKernelFunction { kernel_info_ = get_best_kernel_info(kernel_default, kernel_sse42, kernel_avx2); } - template inline auto operator()(Args... args) const + template auto operator()(Args... args) const { assert(kernel_info_.kernel); diff --git a/intern/cycles/device/cuda/device.cpp b/intern/cycles/device/cuda/device.cpp index bcd287a4107..0de0f14b9bf 100644 --- a/intern/cycles/device/cuda/device.cpp +++ b/intern/cycles/device/cuda/device.cpp @@ -10,10 +10,12 @@ # include "device/cuda/device_impl.h" # include "device/device.h" -# include "integrator/denoiser_oidn_gpu.h" +# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep # include "util/string.h" -# include "util/windows.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif #endif /* WITH_CUDA */ CCL_NAMESPACE_BEGIN @@ -182,6 +184,7 @@ void device_cuda_info(vector &devices) cuDeviceGetAttribute(&timeout_attr, CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT, num); cuDeviceGetAttribute(&preempt_attr, CU_DEVICE_ATTRIBUTE_COMPUTE_PREEMPTION_SUPPORTED, num); +# ifdef _WIN32 /* The CUDA driver reports compute preemption as not being available on * Windows 10 even when it is, due to an issue in application profiles. * Detect case where we expect it to be available and override. */ @@ -189,6 +192,7 @@ void device_cuda_info(vector &devices) VLOG_INFO << "Assuming device has compute preemption on Windows 10."; preempt_attr = 1; } +# endif if (timeout_attr && !preempt_attr) { VLOG_INFO << "Device is recognized as display."; @@ -202,9 +206,10 @@ void device_cuda_info(vector &devices) } VLOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\"."; - if (info.denoisers & DENOISER_OPENIMAGEDENOISE) + if (info.denoisers & DENOISER_OPENIMAGEDENOISE) { VLOG_INFO << "Device with id \"" << info.id << "\" supports " << denoiserTypeToHumanReadable(DENOISER_OPENIMAGEDENOISE) << "."; + } } if (!display_devices.empty()) { @@ -232,7 +237,7 @@ string device_cuda_capabilities() return string("Error getting devices: ") + cuewErrorString(result); } - string capabilities = ""; + string capabilities; for (int num = 0; num < count; num++) { char name[256]; if (cuDeviceGetName(name, 256, num) != CUDA_SUCCESS) { diff --git a/intern/cycles/device/cuda/device_impl.cpp b/intern/cycles/device/cuda/device_impl.cpp index 65d37f0c903..0092f9f54b1 100644 --- a/intern/cycles/device/cuda/device_impl.cpp +++ b/intern/cycles/device/cuda/device_impl.cpp @@ -5,24 +5,25 @@ #ifdef WITH_CUDA # include -# include -# include -# include -# include +# include +# include +# include # include "device/cuda/device_impl.h" # include "util/debug.h" # include "util/foreach.h" # include "util/log.h" -# include "util/map.h" # include "util/md5.h" # include "util/path.h" # include "util/string.h" # include "util/system.h" # include "util/time.h" # include "util/types.h" -# include "util/windows.h" + +# ifdef _WIN32 +# include "util/windows.h" +# endif # include "kernel/device/cuda/globals.h" @@ -64,9 +65,9 @@ CUDADevice::CUDADevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, cuDevId = info.num; cuDevice = 0; - cuContext = 0; + cuContext = nullptr; - cuModule = 0; + cuModule = nullptr; need_texture_info = false; @@ -344,7 +345,7 @@ string CUDADevice::compile_kernel(const string &common_cflags, nvcc_cuda_version % 10); return string(); } - else if (!(nvcc_cuda_version >= 102 && nvcc_cuda_version < 130)) { + if (!(nvcc_cuda_version >= 102 && nvcc_cuda_version < 130)) { printf( "CUDA version %d.%d detected, build may succeed but only " "CUDA 10.1 to 12 are officially supported.\n", @@ -417,7 +418,7 @@ bool CUDADevice::load_kernels(const uint kernel_features) } /* check if cuda init succeeded */ - if (cuContext == 0) { + if (cuContext == nullptr) { return false; } diff --git a/intern/cycles/device/cuda/device_impl.h b/intern/cycles/device/cuda/device_impl.h index 8d729dce818..a383f514608 100644 --- a/intern/cycles/device/cuda/device_impl.h +++ b/intern/cycles/device/cuda/device_impl.h @@ -9,8 +9,6 @@ # include "device/cuda/util.h" # include "device/device.h" -# include "util/map.h" - # ifdef WITH_CUDA_DYNLOAD # include "cuew.h" # else @@ -39,13 +37,13 @@ class CUDADevice : public GPUDevice { static bool have_precompiled_kernels(); - virtual BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; + BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; void set_error(const string &error) override; CUDADevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - virtual ~CUDADevice(); + ~CUDADevice() override; bool support_device(const uint /*kernel_features*/); @@ -60,17 +58,17 @@ class CUDADevice : public GPUDevice { const char *base = "cuda", bool force_ptx = false); - virtual bool load_kernels(const uint kernel_features) override; + bool load_kernels(const uint kernel_features) override; void reserve_local_memory(const uint kernel_features); - virtual void get_device_memory_info(size_t &total, size_t &free) override; - virtual bool alloc_device(void *&device_pointer, size_t size) override; - virtual void free_device(void *device_pointer) override; - virtual bool alloc_host(void *&shared_pointer, size_t size) override; - virtual void free_host(void *shared_pointer) override; - virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; - virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size) override; + void get_device_memory_info(size_t &total, size_t &free) override; + bool alloc_device(void *&device_pointer, const size_t size) override; + void free_device(void *device_pointer) override; + bool alloc_host(void *&shared_pointer, const size_t size) override; + void free_host(void *shared_pointer) override; + void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; + void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override; void mem_alloc(device_memory &mem) override; @@ -84,7 +82,7 @@ class CUDADevice : public GPUDevice { device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, const size_t size) override; void global_alloc(device_memory &mem); @@ -94,9 +92,9 @@ class CUDADevice : public GPUDevice { void tex_free(device_texture &mem); - virtual bool should_use_graphics_interop() override; + bool should_use_graphics_interop() override; - virtual unique_ptr gpu_queue_create() override; + unique_ptr gpu_queue_create() override; int get_num_multiprocessors(); int get_max_num_threads_per_multiprocessor(); diff --git a/intern/cycles/device/cuda/graphics_interop.h b/intern/cycles/device/cuda/graphics_interop.h index c50f449df6b..b86d2b9117d 100644 --- a/intern/cycles/device/cuda/graphics_interop.h +++ b/intern/cycles/device/cuda/graphics_interop.h @@ -24,15 +24,15 @@ class CUDADeviceGraphicsInterop : public DeviceGraphicsInterop { CUDADeviceGraphicsInterop(const CUDADeviceGraphicsInterop &other) = delete; CUDADeviceGraphicsInterop(CUDADeviceGraphicsInterop &&other) noexcept = delete; - ~CUDADeviceGraphicsInterop(); + ~CUDADeviceGraphicsInterop() override; CUDADeviceGraphicsInterop &operator=(const CUDADeviceGraphicsInterop &other) = delete; CUDADeviceGraphicsInterop &operator=(CUDADeviceGraphicsInterop &&other) = delete; - virtual void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) override; + void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) override; - virtual device_ptr map() override; - virtual void unmap() override; + device_ptr map() override; + void unmap() override; protected: CUDADeviceQueue *queue_ = nullptr; diff --git a/intern/cycles/device/cuda/queue.cpp b/intern/cycles/device/cuda/queue.cpp index 0a28ddc6bb1..642d8154fa8 100644 --- a/intern/cycles/device/cuda/queue.cpp +++ b/intern/cycles/device/cuda/queue.cpp @@ -119,7 +119,7 @@ bool CUDADeviceQueue::enqueue(DeviceKernel kernel, shared_mem_bytes, cuda_stream_, const_cast(args.values), - 0), + nullptr), "enqueue"); debug_enqueue_end(); diff --git a/intern/cycles/device/cuda/queue.h b/intern/cycles/device/cuda/queue.h index f7edfee2e51..46cf7391ed7 100644 --- a/intern/cycles/device/cuda/queue.h +++ b/intern/cycles/device/cuda/queue.h @@ -6,7 +6,6 @@ #ifdef WITH_CUDA -# include "device/kernel.h" # include "device/memory.h" # include "device/queue.h" @@ -21,29 +20,29 @@ class device_memory; class CUDADeviceQueue : public DeviceQueue { public: CUDADeviceQueue(CUDADevice *device); - ~CUDADeviceQueue(); + ~CUDADeviceQueue() override; - virtual int num_concurrent_states(const size_t state_size) const override; - virtual int num_concurrent_busy_states(const size_t state_size) const override; + int num_concurrent_states(const size_t state_size) const override; + int num_concurrent_busy_states(const size_t state_size) const override; - virtual void init_execution() override; + void init_execution() override; - virtual bool enqueue(DeviceKernel kernel, - const int work_size, - DeviceKernelArguments const &args) override; + bool enqueue(DeviceKernel kernel, + const int work_size, + const DeviceKernelArguments &args) override; - virtual bool synchronize() override; + bool synchronize() override; - virtual void zero_to_device(device_memory &mem) override; - virtual void copy_to_device(device_memory &mem) override; - virtual void copy_from_device(device_memory &mem) override; + void zero_to_device(device_memory &mem) override; + void copy_to_device(device_memory &mem) override; + void copy_from_device(device_memory &mem) override; virtual CUstream stream() { return cuda_stream_; } - virtual unique_ptr graphics_interop_create() override; + unique_ptr graphics_interop_create() override; protected: CUDADevice *cuda_device_; diff --git a/intern/cycles/device/cuda/util.h b/intern/cycles/device/cuda/util.h index 3521e425d2f..90491bf86e5 100644 --- a/intern/cycles/device/cuda/util.h +++ b/intern/cycles/device/cuda/util.h @@ -7,7 +7,7 @@ #ifdef WITH_CUDA # ifdef WITH_CUDA_DYNLOAD -# include "cuew.h" +# include # else # include # endif diff --git a/intern/cycles/device/denoise.h b/intern/cycles/device/denoise.h index 73ad9890566..e907b8af4f9 100644 --- a/intern/cycles/device/denoise.h +++ b/intern/cycles/device/denoise.h @@ -4,9 +4,7 @@ #pragma once -#include "device/memory.h" #include "graph/node.h" -#include "session/buffers.h" CCL_NAMESPACE_BEGIN @@ -22,7 +20,7 @@ enum DenoiserType { /* COnstruct human-readable string which denotes the denoiser type. */ const char *denoiserTypeToHumanReadable(DenoiserType type); -typedef int DenoiserTypeMask; +using DenoiserTypeMask = int; enum DenoiserPrefilter { /* Best quality of the result without extra processing time, but requires guiding passes to be diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 0fe99338cdc..50dde669ccb 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -2,8 +2,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include #include "bvh/bvh2.h" @@ -15,20 +15,21 @@ #include "device/cuda/device.h" #include "device/dummy/device.h" #include "device/hip/device.h" -#include "device/hiprt/device_impl.h" #include "device/metal/device.h" #include "device/multi/device.h" #include "device/oneapi/device.h" #include "device/optix/device.h" +#ifdef WITH_HIPRT +# include +#endif + #include "util/foreach.h" -#include "util/half.h" #include "util/log.h" #include "util/math.h" #include "util/string.h" #include "util/system.h" #include "util/task.h" -#include "util/time.h" #include "util/types.h" #include "util/vector.h" @@ -47,7 +48,7 @@ uint Device::devices_initialized_mask = 0; /* Device */ -Device::~Device() noexcept(false) {} +Device::~Device() noexcept(false) = default; void Device::build_bvh(BVH *bvh, Progress &progress, bool refit) { @@ -86,22 +87,25 @@ Device *Device::create(const DeviceInfo &info, Stats &stats, Profiler &profiler, #endif #ifdef WITH_OPTIX case DEVICE_OPTIX: - if (device_optix_init()) + if (device_optix_init()) { device = device_optix_create(info, stats, profiler, headless); + } break; #endif #ifdef WITH_HIP case DEVICE_HIP: - if (device_hip_init()) + if (device_hip_init()) { device = device_hip_create(info, stats, profiler, headless); + } break; #endif #ifdef WITH_METAL case DEVICE_METAL: - if (device_metal_init()) + if (device_metal_init()) { device = device_metal_create(info, stats, profiler, headless); + } break; #endif @@ -127,25 +131,25 @@ DeviceType Device::type_from_string(const char *name) if (strcmp(name, "CPU") == 0) { return DEVICE_CPU; } - else if (strcmp(name, "CUDA") == 0) { + if (strcmp(name, "CUDA") == 0) { return DEVICE_CUDA; } - else if (strcmp(name, "OPTIX") == 0) { + if (strcmp(name, "OPTIX") == 0) { return DEVICE_OPTIX; } - else if (strcmp(name, "MULTI") == 0) { + if (strcmp(name, "MULTI") == 0) { return DEVICE_MULTI; } - else if (strcmp(name, "HIP") == 0) { + if (strcmp(name, "HIP") == 0) { return DEVICE_HIP; } - else if (strcmp(name, "METAL") == 0) { + if (strcmp(name, "METAL") == 0) { return DEVICE_METAL; } - else if (strcmp(name, "ONEAPI") == 0) { + if (strcmp(name, "ONEAPI") == 0) { return DEVICE_ONEAPI; } - else if (strcmp(name, "HIPRT") == 0) { + if (strcmp(name, "HIPRT") == 0) { return DEVICE_HIPRT; } @@ -157,25 +161,25 @@ string Device::string_from_type(DeviceType type) if (type == DEVICE_CPU) { return "CPU"; } - else if (type == DEVICE_CUDA) { + if (type == DEVICE_CUDA) { return "CUDA"; } - else if (type == DEVICE_OPTIX) { + if (type == DEVICE_OPTIX) { return "OPTIX"; } - else if (type == DEVICE_MULTI) { + if (type == DEVICE_MULTI) { return "MULTI"; } - else if (type == DEVICE_HIP) { + if (type == DEVICE_HIP) { return "HIP"; } - else if (type == DEVICE_METAL) { + if (type == DEVICE_METAL) { return "METAL"; } - else if (type == DEVICE_ONEAPI) { + if (type == DEVICE_ONEAPI) { return "ONEAPI"; } - else if (type == DEVICE_HIPRT) { + if (type == DEVICE_HIPRT) { return "HIPRT"; } @@ -202,8 +206,9 @@ vector Device::available_types() types.push_back(DEVICE_ONEAPI); #endif #ifdef WITH_HIPRT - if (hiprtewInit()) + if (hiprtewInit()) { types.push_back(DEVICE_HIPRT); + } #endif return types; } @@ -312,7 +317,7 @@ DeviceInfo Device::dummy_device(const string &error_msg) string Device::device_capabilities(uint mask) { thread_scoped_lock lock(device_mutex); - string capabilities = ""; + string capabilities; if (mask & DEVICE_MASK_CPU) { capabilities += "\nCPU device capabilities: "; @@ -374,7 +379,7 @@ DeviceInfo Device::get_multi_device(const vector &subdevices, int threads, bool background) { - assert(subdevices.size() > 0); + assert(!subdevices.empty()); if (subdevices.size() == 1) { /* No multi device needed. */ @@ -489,7 +494,7 @@ void *Device::get_cpu_osl_memory() return nullptr; } -GPUDevice::~GPUDevice() noexcept(false) {} +GPUDevice::~GPUDevice() noexcept(false) = default; bool GPUDevice::load_texture_info() { @@ -500,9 +505,7 @@ bool GPUDevice::load_texture_info() texture_info.copy_to_device(); return true; } - else { - return false; - } + return false; } void GPUDevice::init_host_memory(size_t preferred_texture_headroom, @@ -628,7 +631,7 @@ void GPUDevice::move_textures_to_host(size_t size, bool for_texture) GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, size_t pitch_padding) { - void *device_pointer = 0; + void *device_pointer = nullptr; size_t size = mem.memory_size() + pitch_padding; bool mem_alloc_result = false; @@ -666,7 +669,7 @@ GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, size_t pitch_paddin /* Fall back to mapped host memory if needed and possible. */ - void *shared_pointer = 0; + void *shared_pointer = nullptr; if (!mem_alloc_result && can_map_host && mem.type != MEM_DEVICE_ONLY) { if (mem.shared_pointer) { @@ -678,8 +681,8 @@ GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, size_t pitch_paddin /* Allocate host memory ourselves. */ mem_alloc_result = alloc_host(shared_pointer, size); - assert((mem_alloc_result && shared_pointer != 0) || - (!mem_alloc_result && shared_pointer == 0)); + assert((mem_alloc_result && shared_pointer != nullptr) || + (!mem_alloc_result && shared_pointer == nullptr)); } if (mem_alloc_result) { @@ -717,7 +720,7 @@ GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, size_t pitch_paddin /* Insert into map of allocations. */ thread_scoped_lock lock(device_mem_map_mutex); Mem *cmem = &device_mem_map[&mem]; - if (shared_pointer != 0) { + if (shared_pointer != nullptr) { /* Replace host pointer with our host allocation. Only works if * memory layout is the same and has no pitch padding. Also * does not work if we move textures to host during a render, @@ -765,10 +768,10 @@ void GPUDevice::generic_free(device_memory &mem) assert(mem.shared_counter > 0); if (--mem.shared_counter == 0) { if (mem.host_pointer == mem.shared_pointer) { - mem.host_pointer = 0; + mem.host_pointer = nullptr; } free_host(mem.shared_pointer); - mem.shared_pointer = 0; + mem.shared_pointer = nullptr; } } map_host_used -= mem.device_size; diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index af96ed1e1fa..6d63b15e04d 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -12,8 +12,8 @@ #include "device/denoise.h" #include "device/memory.h" -#include "util/list.h" #include "util/log.h" +#include "util/profiling.h" #include "util/stats.h" #include "util/string.h" #include "util/texture.h" @@ -333,25 +333,19 @@ class GPUDevice : public Device { GPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_, bool headless_) : Device(info_, stats_, profiler_, headless_), texture_info(this, "texture_info", MEM_GLOBAL), - need_texture_info(false), - can_map_host(false), - map_host_used(0), - map_host_limit(0), - device_texture_headroom(0), - device_working_headroom(0), + device_mem_map(), - device_mem_map_mutex(), - move_texture_to_host(false), - device_mem_in_use(0) + device_mem_map_mutex() + { } public: - virtual ~GPUDevice() noexcept(false); + ~GPUDevice() noexcept(false) override; /* For GPUs that can use bindless textures in some way or another. */ device_vector texture_info; - bool need_texture_info; + bool need_texture_info = false; /* Returns true if the texture info was copied to the device (meaning, some more * re-initialization might be needed). */ virtual bool load_texture_info(); @@ -360,28 +354,28 @@ class GPUDevice : public Device { /* Memory allocation, only accessed through device_memory. */ friend class device_memory; - bool can_map_host; - size_t map_host_used; - size_t map_host_limit; - size_t device_texture_headroom; - size_t device_working_headroom; - typedef unsigned long long texMemObject; - typedef unsigned long long arrayMemObject; + bool can_map_host = false; + size_t map_host_used = 0; + size_t map_host_limit = 0; + size_t device_texture_headroom = 0; + size_t device_working_headroom = 0; + using texMemObject = unsigned long long; + using arrayMemObject = unsigned long long; struct Mem { - Mem() : texobject(0), array(0), use_mapped_host(false) {} + Mem() = default; - texMemObject texobject; - arrayMemObject array; + texMemObject texobject = 0; + arrayMemObject array = 0; /* If true, a mapped host memory in shared_pointer is being used. */ - bool use_mapped_host; + bool use_mapped_host = false; }; - typedef map MemMap; + using MemMap = map; MemMap device_mem_map; thread_mutex device_mem_map_mutex; - bool move_texture_to_host; + bool move_texture_to_host = false; /* Simple counter which will try to track amount of used device memory */ - size_t device_mem_in_use; + size_t device_mem_in_use = 0; virtual void init_host_memory(size_t preferred_texture_headroom = 0, size_t preferred_working_headroom = 0); diff --git a/intern/cycles/device/dummy/device.cpp b/intern/cycles/device/dummy/device.cpp index ca34e76b84e..3ae1fd30e4e 100644 --- a/intern/cycles/device/dummy/device.cpp +++ b/intern/cycles/device/dummy/device.cpp @@ -19,24 +19,27 @@ class DummyDevice : public Device { error_msg = info.error_msg; } - ~DummyDevice() {} + ~DummyDevice() override = default; - virtual BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override + BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override { return 0; } - virtual void mem_alloc(device_memory &) override {} + void mem_alloc(device_memory & /*mem*/) override {} - virtual void mem_copy_to(device_memory &) override {} + void mem_copy_to(device_memory & /*mem*/) override {} - virtual void mem_copy_from(device_memory &, size_t, size_t, size_t, size_t) override {} + void mem_copy_from( + device_memory & /*mem*/, size_t /*y*/, size_t /*w*/, size_t /*h*/, size_t /*elem*/) override + { + } - virtual void mem_zero(device_memory &) override {} + void mem_zero(device_memory & /*mem*/) override {} - virtual void mem_free(device_memory &) override {} + void mem_free(device_memory & /*mem*/) override {} - virtual void const_copy_to(const char *, void *, size_t) override {} + void const_copy_to(const char * /*name*/, void * /*host*/, size_t /*size*/) override {} }; Device *device_dummy_create(const DeviceInfo &info, diff --git a/intern/cycles/device/dummy/device.h b/intern/cycles/device/dummy/device.h index 35545aeca1c..fabbf8557fd 100644 --- a/intern/cycles/device/dummy/device.h +++ b/intern/cycles/device/dummy/device.h @@ -4,9 +4,6 @@ #pragma once -#include "util/string.h" -#include "util/vector.h" - CCL_NAMESPACE_BEGIN class Device; diff --git a/intern/cycles/device/hip/device.cpp b/intern/cycles/device/hip/device.cpp index d09a4530bb5..abfdaefa266 100644 --- a/intern/cycles/device/hip/device.cpp +++ b/intern/cycles/device/hip/device.cpp @@ -10,10 +10,12 @@ # include "device/device.h" # include "device/hip/device_impl.h" -# include "integrator/denoiser_oidn_gpu.h" +# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep # include "util/string.h" -# include "util/windows.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif #endif /* WITH_HIP */ #ifdef WITH_HIPRT @@ -30,8 +32,9 @@ bool device_hip_init() static bool initialized = false; static bool result = false; - if (initialized) + if (initialized) { return result; + } initialized = true; int hipew_result = hipewInit(HIPEW_INIT_HIP); @@ -73,10 +76,10 @@ bool device_hip_init() Device *device_hip_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless) { #ifdef WITH_HIPRT - if (info.use_hardware_raytracing) + if (info.use_hardware_raytracing) { return new HIPRTDevice(info, stats, profiler, headless); - else - return new HIPDevice(info, stats, profiler, headless); + } + return new HIPDevice(info, stats, profiler, headless); #elif defined(WITH_HIP) return new HIPDevice(info, stats, profiler, headless); #else @@ -118,8 +121,9 @@ void device_hip_info(vector &devices) #ifdef WITH_HIP hipError_t result = device_hip_safe_init(); if (result != hipSuccess) { - if (result != hipErrorNoDevice) + if (result != hipErrorNoDevice) { fprintf(stderr, "HIP hipInit: %s\n", hipewErrorString(result)); + } return; } @@ -214,13 +218,15 @@ void device_hip_info(vector &devices) VLOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\"."; - if (info.denoisers & DENOISER_OPENIMAGEDENOISE) + if (info.denoisers & DENOISER_OPENIMAGEDENOISE) { VLOG_INFO << "Device with id \"" << info.id << "\" supports " << denoiserTypeToHumanReadable(DENOISER_OPENIMAGEDENOISE) << "."; + } } - if (!display_devices.empty()) + if (!display_devices.empty()) { devices.insert(devices.end(), display_devices.begin(), display_devices.end()); + } #else /* WITH_HIP */ (void)devices; #endif /* WITH_HIP */ @@ -243,7 +249,7 @@ string device_hip_capabilities() return string("Error getting devices: ") + hipewErrorString(result); } - string capabilities = ""; + string capabilities; for (int num = 0; num < count; num++) { char name[256]; if (hipDeviceGetName(name, 256, num) != hipSuccess) { diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index a1cf9d5d287..fcaedf23070 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -5,24 +5,25 @@ #ifdef WITH_HIP # include -# include -# include -# include -# include +# include +# include +# include # include "device/hip/device_impl.h" # include "util/debug.h" # include "util/foreach.h" # include "util/log.h" -# include "util/map.h" # include "util/md5.h" # include "util/path.h" # include "util/string.h" # include "util/system.h" # include "util/time.h" # include "util/types.h" -# include "util/windows.h" + +# ifdef _WIN32 +# include "util/windows.h" +# endif # include "kernel/device/hip/globals.h" @@ -64,9 +65,9 @@ HIPDevice::HIPDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, b hipDevId = info.num; hipDevice = 0; - hipContext = 0; + hipContext = nullptr; - hipModule = 0; + hipModule = nullptr; need_texture_info = false; @@ -137,15 +138,13 @@ bool HIPDevice::support_device(const uint /*kernel_features*/) if (hipSupportsDevice(hipDevId)) { return true; } - else { - /* We only support Navi and above. */ - hipDeviceProp_t props; - hipGetDeviceProperties(&props, hipDevId); + /* We only support Navi and above. */ + hipDeviceProp_t props; + hipGetDeviceProperties(&props, hipDevId); - set_error(string_printf("HIP backend requires AMD RDNA graphics card or up, but found %s.", - props.name)); - return false; - } + set_error(string_printf("HIP backend requires AMD RDNA graphics card or up, but found %s.", + props.name)); + return false; } bool HIPDevice::check_peer_access(Device *peer_device) @@ -272,7 +271,7 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c /* Reduce optimization level on VEGA GPUs to avoid some rendering artifacts */ options.append(" -O1"); } - options.append(" --offload-arch=").append(arch.c_str()); + options.append(" --offload-arch=").append(arch); const string include_path = source_path; const string fatbin_file = string_printf( @@ -382,8 +381,9 @@ bool HIPDevice::load_kernels(const uint kernel_features) } /* check if hip init succeeded */ - if (hipContext == 0) + if (hipContext == nullptr) { return false; + } /* check if GPU is supported */ if (!support_device(kernel_features)) { @@ -393,8 +393,9 @@ bool HIPDevice::load_kernels(const uint kernel_features) /* get kernel */ const char *kernel_name = "kernel"; string fatbin = compile_kernel(kernel_features, kernel_name); - if (fatbin.empty()) + if (fatbin.empty()) { return false; + } /* open module */ HIPContextScope scope(this); @@ -402,14 +403,17 @@ bool HIPDevice::load_kernels(const uint kernel_features) string fatbin_data; hipError_t result; - if (path_read_compressed_text(fatbin, fatbin_data)) + if (path_read_compressed_text(fatbin, fatbin_data)) { result = hipModuleLoadData(&hipModule, fatbin_data.c_str()); - else + } + else { result = hipErrorFileNotFound; + } - if (result != hipSuccess) + if (result != hipSuccess) { set_error(string_printf( "Failed to load HIP kernel from '%s' (%s)", fatbin.c_str(), hipewErrorString(result))); + } if (result == hipSuccess) { kernels.load(this); diff --git a/intern/cycles/device/hip/device_impl.h b/intern/cycles/device/hip/device_impl.h index b230ff12d3c..8f82311b421 100644 --- a/intern/cycles/device/hip/device_impl.h +++ b/intern/cycles/device/hip/device_impl.h @@ -11,8 +11,6 @@ # include "device/hip/queue.h" # include "device/hip/util.h" -# include "util/map.h" - # ifdef WITH_HIP_DYNLOAD # include "hipew.h" # endif @@ -39,13 +37,13 @@ class HIPDevice : public GPUDevice { static bool have_precompiled_kernels(); - virtual BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; + BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; void set_error(const string &error) override; HIPDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - virtual ~HIPDevice(); + ~HIPDevice() override; bool support_device(const uint /*kernel_features*/); @@ -59,16 +57,16 @@ class HIPDevice : public GPUDevice { const char *name, const char *base = "hip"); - virtual bool load_kernels(const uint kernel_features) override; + bool load_kernels(const uint kernel_features) override; void reserve_local_memory(const uint kernel_features); - virtual void get_device_memory_info(size_t &total, size_t &free) override; - virtual bool alloc_device(void *&device_pointer, size_t size) override; - virtual void free_device(void *device_pointer) override; - virtual bool alloc_host(void *&shared_pointer, size_t size) override; - virtual void free_host(void *shared_pointer) override; - virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; - virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size) override; + void get_device_memory_info(size_t &total, size_t &free) override; + bool alloc_device(void *&device_pointer, const size_t size) override; + void free_device(void *device_pointer) override; + bool alloc_host(void *&shared_pointer, const size_t size) override; + void free_host(void *shared_pointer) override; + void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; + void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override; void mem_alloc(device_memory &mem) override; @@ -82,7 +80,7 @@ class HIPDevice : public GPUDevice { device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, const size_t size) override; void global_alloc(device_memory &mem); @@ -93,9 +91,9 @@ class HIPDevice : public GPUDevice { void tex_free(device_texture &mem); /* Graphics resources interoperability. */ - virtual bool should_use_graphics_interop() override; + bool should_use_graphics_interop() override; - virtual unique_ptr gpu_queue_create() override; + unique_ptr gpu_queue_create() override; int get_num_multiprocessors(); int get_max_num_threads_per_multiprocessor(); diff --git a/intern/cycles/device/hip/graphics_interop.h b/intern/cycles/device/hip/graphics_interop.h index c43d4f54fef..dfe606f0305 100644 --- a/intern/cycles/device/hip/graphics_interop.h +++ b/intern/cycles/device/hip/graphics_interop.h @@ -22,15 +22,15 @@ class HIPDeviceGraphicsInterop : public DeviceGraphicsInterop { HIPDeviceGraphicsInterop(const HIPDeviceGraphicsInterop &other) = delete; HIPDeviceGraphicsInterop(HIPDeviceGraphicsInterop &&other) noexcept = delete; - ~HIPDeviceGraphicsInterop(); + ~HIPDeviceGraphicsInterop() override; HIPDeviceGraphicsInterop &operator=(const HIPDeviceGraphicsInterop &other) = delete; HIPDeviceGraphicsInterop &operator=(HIPDeviceGraphicsInterop &&other) = delete; - virtual void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) override; + void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) override; - virtual device_ptr map() override; - virtual void unmap() override; + device_ptr map() override; + void unmap() override; protected: HIPDeviceQueue *queue_ = nullptr; diff --git a/intern/cycles/device/hip/queue.cpp b/intern/cycles/device/hip/queue.cpp index 9f06f01cb14..840eba795e0 100644 --- a/intern/cycles/device/hip/queue.cpp +++ b/intern/cycles/device/hip/queue.cpp @@ -118,7 +118,7 @@ bool HIPDeviceQueue::enqueue(DeviceKernel kernel, shared_mem_bytes, hip_stream_, const_cast(args.values), - 0), + nullptr), "enqueue"); debug_enqueue_end(); diff --git a/intern/cycles/device/hip/queue.h b/intern/cycles/device/hip/queue.h index 47ff40423d2..834cb698702 100644 --- a/intern/cycles/device/hip/queue.h +++ b/intern/cycles/device/hip/queue.h @@ -6,7 +6,6 @@ #ifdef WITH_HIP -# include "device/kernel.h" # include "device/memory.h" # include "device/queue.h" @@ -21,29 +20,29 @@ class device_memory; class HIPDeviceQueue : public DeviceQueue { public: HIPDeviceQueue(HIPDevice *device); - ~HIPDeviceQueue(); + ~HIPDeviceQueue() override; - virtual int num_concurrent_states(const size_t state_size) const override; - virtual int num_concurrent_busy_states(const size_t state_size) const override; + int num_concurrent_states(const size_t state_size) const override; + int num_concurrent_busy_states(const size_t state_size) const override; - virtual void init_execution() override; + void init_execution() override; - virtual bool enqueue(DeviceKernel kernel, - const int work_size, - DeviceKernelArguments const &args) override; + bool enqueue(DeviceKernel kernel, + const int work_size, + const DeviceKernelArguments &args) override; - virtual bool synchronize() override; + bool synchronize() override; - virtual void zero_to_device(device_memory &mem) override; - virtual void copy_to_device(device_memory &mem) override; - virtual void copy_from_device(device_memory &mem) override; + void zero_to_device(device_memory &mem) override; + void copy_to_device(device_memory &mem) override; + void copy_from_device(device_memory &mem) override; virtual hipStream_t stream() { return hip_stream_; } - virtual unique_ptr graphics_interop_create() override; + unique_ptr graphics_interop_create() override; protected: HIPDevice *hip_device_; diff --git a/intern/cycles/device/hip/util.h b/intern/cycles/device/hip/util.h index 1e4e29163dc..29a024bfc09 100644 --- a/intern/cycles/device/hip/util.h +++ b/intern/cycles/device/hip/util.h @@ -4,11 +4,11 @@ #pragma once -#include -#include - #ifdef WITH_HIP +# include +# include + # ifdef WITH_HIP_DYNLOAD # include "hipew.h" # endif diff --git a/intern/cycles/device/hiprt/device_impl.cpp b/intern/cycles/device/hiprt/device_impl.cpp index 01505b58e7f..6a3eb209316 100644 --- a/intern/cycles/device/hiprt/device_impl.cpp +++ b/intern/cycles/device/hiprt/device_impl.cpp @@ -5,19 +5,20 @@ #ifdef WITH_HIPRT # include "device/hiprt/device_impl.h" +# include "kernel/device/hiprt/globals.h" -# include "util/debug.h" # include "util/foreach.h" # include "util/log.h" -# include "util/map.h" # include "util/md5.h" # include "util/path.h" # include "util/progress.h" # include "util/string.h" -# include "util/system.h" # include "util/time.h" # include "util/types.h" -# include "util/windows.h" + +# ifdef _WIN32 +# include "util/windows.h" +# endif # include "bvh/hiprt.h" @@ -77,7 +78,7 @@ HIPRTDevice::HIPRTDevice(const DeviceInfo &info, Stats &stats, Profiler &profile { HIPContextScope scope(this); global_stack_buffer = {0}; - hiprtContextCreationInput hiprt_context_input = {0}; + hiprtContextCreationInput hiprt_context_input = {nullptr}; hiprt_context_input.ctxt = hipContext; hiprt_context_input.device = hipDevice; hiprt_context_input.deviceType = hiprtDeviceAMD; @@ -217,7 +218,7 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, path_create_directories(fatbin); string rtc_options; - rtc_options.append(" --offload-arch=").append(arch.c_str()); + rtc_options.append(" --offload-arch=").append(arch); rtc_options.append(" -D __HIPRT__"); rtc_options.append(" -ffast-math -O3 -std=c++17"); rtc_options.append(" -fgpu-rdc -c --gpu-bundle-output -c -emit-llvm"); @@ -286,7 +287,7 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, // After compilation, the bitcode produced is linked with HIP RT bitcode (containing // implementations of HIP RT functions, e.g. traversal, to produce the final executable code string linker_options; - linker_options.append(" --offload-arch=").append(arch.c_str()); + linker_options.append(" --offload-arch=").append(arch); linker_options.append(" -fgpu-rdc --hip-link --cuda-device-only "); string linker_command = string_printf("clang++ %s \"%s\" \"%s\" -o \"%s\"", @@ -319,8 +320,9 @@ bool HIPRTDevice::load_kernels(const uint kernel_features) return true; } - if (hipContext == 0) + if (hipContext == nullptr) { return false; + } if (!support_device(kernel_features)) { return false; @@ -329,8 +331,9 @@ bool HIPRTDevice::load_kernels(const uint kernel_features) /* get kernel */ const char *kernel_name = "kernel"; string fatbin = compile_kernel(kernel_features, kernel_name); - if (fatbin.empty()) + if (fatbin.empty()) { return false; + } /* open module */ HIPContextScope scope(this); @@ -341,12 +344,14 @@ bool HIPRTDevice::load_kernels(const uint kernel_features) if (path_read_compressed_text(fatbin, fatbin_data)) { result = hipModuleLoadData(&hipModule, fatbin_data.c_str()); } - else + else { result = hipErrorFileNotFound; + } - if (result != hipSuccess) + if (result != hipSuccess) { set_error(string_printf( "Failed to load HIP kernel from '%s' (%s)", fatbin.c_str(), hipewErrorString(result))); + } if (result == hipSuccess) { kernels.load(this); @@ -509,14 +514,14 @@ hiprtGeometryBuildInput HIPRTDevice::prepare_triangle_blas(BVHHIPRT *bvh, Mesh * bvh->triangle_index.copy_to_device(); bvh->triangle_mesh.triangleIndices = (void *)(bvh->triangle_index.device_pointer); // either has to set the host pointer to zero, or increment the refcount on triangle_data - bvh->triangle_index.host_pointer = 0; + bvh->triangle_index.host_pointer = nullptr; bvh->vertex_data.host_pointer = vertex_data; bvh->vertex_data.data_elements = 4; bvh->vertex_data.data_type = TYPE_FLOAT; bvh->vertex_data.data_size = vertex_size; bvh->vertex_data.copy_to_device(); bvh->triangle_mesh.vertices = (void *)(bvh->vertex_data.device_pointer); - bvh->vertex_data.host_pointer = 0; + bvh->vertex_data.host_pointer = nullptr; geom_input.type = hiprtPrimitiveTypeTriangleMesh; geom_input.primitive.triangleMesh = bvh->triangle_mesh; @@ -552,7 +557,7 @@ hiprtGeometryBuildInput HIPRTDevice::prepare_curve_blas(BVHHIPRT *bvh, Hair *hai for (uint j = 0; j < num_curves; j++) { const Hair::Curve curve = hair->get_curve(j); - const float *curve_radius = &hair->get_curve_radius()[0]; + const float *curve_radius = hair->get_curve_radius().data(); int first_key = curve.first_key; for (int k = 0; k < curve.num_keys - 1; k++) { if (curve_attr_mP == nullptr) { @@ -567,10 +572,12 @@ hiprtGeometryBuildInput HIPRTDevice::prepare_curve_blas(BVHHIPRT *bvh, Hair *hai current_keys[1].y == current_keys[2].y && current_keys[2].y == current_keys[3].y && current_keys[0].z == current_keys[1].z && current_keys[1].z == current_keys[2].z && current_keys[2].z == current_keys[3].z) + { continue; + } BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &hair->get_curve_keys()[0], curve_radius, bounds); + curve.bounds_grow(k, hair->get_curve_keys().data(), curve_radius, bounds); if (bounds.valid()) { int type = PRIMITIVE_PACK_SEGMENT(primitive_type, k); bvh->custom_prim_info[num_bounds].x = j; @@ -586,7 +593,7 @@ hiprtGeometryBuildInput HIPRTDevice::prepare_curve_blas(BVHHIPRT *bvh, Hair *hai if (bvh->params.num_motion_curve_steps == 0 || bvh->params.use_spatial_split) { BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &hair->get_curve_keys()[0], curve_radius, bounds); + curve.bounds_grow(k, hair->get_curve_keys().data(), curve_radius, bounds); for (size_t step = 0; step < num_steps - 1; step++) { curve.bounds_grow(k, key_steps + step * num_keys, bounds); } @@ -776,8 +783,9 @@ void HIPRTDevice::build_blas(BVHHIPRT *bvh, Geometry *geom, hiprtBuildOptions op case Geometry::VOLUME: { Mesh *mesh = static_cast(geom); - if (mesh->num_triangles() == 0) + if (mesh->num_triangles() == 0) { return; + } geom_input = prepare_triangle_blas(bvh, mesh); break; @@ -786,8 +794,9 @@ void HIPRTDevice::build_blas(BVHHIPRT *bvh, Geometry *geom, hiprtBuildOptions op case Geometry::HAIR: { Hair *const hair = static_cast(geom); - if (hair->num_segments() == 0) + if (hair->num_segments() == 0) { return; + } geom_input = prepare_curve_blas(bvh, hair); break; @@ -795,8 +804,9 @@ void HIPRTDevice::build_blas(BVHHIPRT *bvh, Geometry *geom, hiprtBuildOptions op case Geometry::POINTCLOUD: { PointCloud *pointcloud = static_cast(geom); - if (pointcloud->num_points() == 0) + if (pointcloud->num_points() == 0) { return; + } geom_input = prepare_point_blas(bvh, pointcloud); break; @@ -832,7 +842,7 @@ void HIPRTDevice::build_blas(BVHHIPRT *bvh, Geometry *geom, hiprtBuildOptions op bvh->geom_input, options, (void *)(scratch_buffer.device_pointer), - 0, + nullptr, bvh->hiprt_geom); } if (rt_err != hiprtSuccess) { @@ -848,7 +858,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, size_t num_object = objects.size(); if (num_object == 0) { - return 0; + return nullptr; } hiprtBuildOperation build_operation = refit ? hiprtBuildOperationUpdate : @@ -943,12 +953,14 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, prim_time_offset[blender_instance_id] = time_offset; } - else + else { prim_time_offset[blender_instance_id] = -1; + } } } - else + else { custom_prim_info_offset[blender_instance_id] = {-1, -1}; + } hiprtTransformHeader current_header = {0}; current_header.frameCount = 1; @@ -970,8 +982,9 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, } } else { - if (transform_applied) + if (transform_applied) { current_transform = identity_matrix; + } get_hiprt_transform(hiprt_transform_matrix.matrix, current_transform); transform_matrix.push_back_slow(hiprt_transform_matrix); } @@ -989,7 +1002,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, } int frame_count = transform_matrix.size(); - hiprtSceneBuildInput scene_input_ptr = {0}; + hiprtSceneBuildInput scene_input_ptr = {nullptr}; scene_input_ptr.instanceCount = num_instances; scene_input_ptr.frameCount = frame_count; scene_input_ptr.frameType = hiprtFrameTypeMatrix; @@ -1007,7 +1020,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, instance_transform_matrix.data_type = TYPE_UCHAR; instance_transform_matrix.data_size = frame_count; instance_transform_matrix.copy_to_device(); - instance_transform_matrix.host_pointer = 0; + instance_transform_matrix.host_pointer = nullptr; } scene_input_ptr.instanceMasks = (void *)prim_visibility.device_pointer; @@ -1015,7 +1028,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, scene_input_ptr.instanceTransformHeaders = (void *)transform_headers.device_pointer; scene_input_ptr.instanceFrames = (void *)instance_transform_matrix.device_pointer; - hiprtScene scene = 0; + hiprtScene scene = nullptr; hiprtError rt_err = hiprtCreateScene(hiprt_context, scene_input_ptr, options, scene); @@ -1041,7 +1054,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, scene_input_ptr, options, (void *)scratch_buffer.device_pointer, - 0, + nullptr, scene); if (rt_err != hiprtSuccess) { @@ -1060,7 +1073,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, custom_prim_info.data_type = TYPE_INT; custom_prim_info.data_size = data_size; custom_prim_info.copy_to_device(); - custom_prim_info.host_pointer = 0; + custom_prim_info.host_pointer = nullptr; custom_prim_info_offset.copy_to_device(); } @@ -1074,7 +1087,7 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, prims_time.data_type = TYPE_FLOAT; prims_time.data_size = data_size; prims_time.copy_to_device(); - prims_time.host_pointer = 0; + prims_time.host_pointer = nullptr; prim_time_offset.copy_to_device(); } @@ -1093,8 +1106,9 @@ hiprtScene HIPRTDevice::build_tlas(BVHHIPRT *bvh, for (int index = 0; index < table_index; index++) { - hip_assert(hipMemcpyHtoD( - table_device_ptr + kernel_param_offset[index], &functions_table, sizeof(device_ptr))); + hip_assert(hipMemcpyHtoD(table_device_ptr + kernel_param_offset[index], + (void *)&functions_table, + sizeof(device_ptr))); } return scene; diff --git a/intern/cycles/device/hiprt/device_impl.h b/intern/cycles/device/hiprt/device_impl.h index 0f87791ee0c..452d7f7feee 100644 --- a/intern/cycles/device/hiprt/device_impl.h +++ b/intern/cycles/device/hiprt/device_impl.h @@ -12,13 +12,11 @@ # include "device/hiprt/queue.h" # ifdef WITH_HIP_DYNLOAD -# include "hiprtew.h" +# include # else # include # endif -# include "kernel/device/hiprt/globals.h" - CCL_NAMESPACE_BEGIN class Mesh; @@ -31,22 +29,22 @@ class BVHHIPRT; class HIPRTDevice : public HIPDevice { public: - virtual BVHLayoutMask get_bvh_layout_mask(const uint kernel_features) const override; + BVHLayoutMask get_bvh_layout_mask(const uint kernel_features) const override; HIPRTDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - virtual ~HIPRTDevice(); - virtual unique_ptr gpu_queue_create() override; + ~HIPRTDevice() override; + unique_ptr gpu_queue_create() override; string compile_kernel_get_common_cflags(const uint kernel_features) override; - virtual string compile_kernel(const uint kernel_features, - const char *name, - const char *base = "hiprt") override; + string compile_kernel(const uint kernel_features, + const char *name, + const char *base = "hiprt") override; - virtual bool load_kernels(const uint kernel_features) override; + bool load_kernels(const uint kernel_features) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, const size_t size) override; - virtual void build_bvh(BVH *bvh, Progress &progress, bool refit) override; + void build_bvh(BVH *bvh, Progress &progress, bool refit) override; hiprtContext get_hiprt_context() { diff --git a/intern/cycles/device/hiprt/queue.cpp b/intern/cycles/device/hiprt/queue.cpp index befb0a263f6..16e1f736125 100644 --- a/intern/cycles/device/hiprt/queue.cpp +++ b/intern/cycles/device/hiprt/queue.cpp @@ -10,6 +10,8 @@ # include "device/hip/kernel.h" # include "device/hiprt/device_impl.h" +# include "kernel/device/hiprt/globals.h" + CCL_NAMESPACE_BEGIN HIPRTDeviceQueue::HIPRTDeviceQueue(HIPRTDevice *device) @@ -69,7 +71,7 @@ bool HIPRTDeviceQueue::enqueue(DeviceKernel kernel, shared_mem_bytes, hip_stream_, const_cast(args_copy.values), - 0), + nullptr), "enqueue"); debug_enqueue_end(); diff --git a/intern/cycles/device/hiprt/queue.h b/intern/cycles/device/hiprt/queue.h index ec02cf81cf9..ca147d46b60 100644 --- a/intern/cycles/device/hiprt/queue.h +++ b/intern/cycles/device/hiprt/queue.h @@ -6,12 +6,10 @@ #ifdef WITH_HIPRT -# include "device/kernel.h" # include "device/memory.h" # include "device/queue.h" # include "device/hip/queue.h" -# include "device/hip/util.h" CCL_NAMESPACE_BEGIN @@ -20,10 +18,10 @@ class HIPRTDevice; class HIPRTDeviceQueue : public HIPDeviceQueue { public: HIPRTDeviceQueue(HIPRTDevice *device); - ~HIPRTDeviceQueue() {} - virtual bool enqueue(DeviceKernel kernel, - const int work_size, - DeviceKernelArguments const &args) override; + ~HIPRTDeviceQueue() override = default; + bool enqueue(DeviceKernel kernel, + const int work_size, + const DeviceKernelArguments &args) override; protected: HIPRTDevice *hiprt_device_; diff --git a/intern/cycles/device/kernel.h b/intern/cycles/device/kernel.h index ae3fd5e75bf..999172aee60 100644 --- a/intern/cycles/device/kernel.h +++ b/intern/cycles/device/kernel.h @@ -22,7 +22,7 @@ const char *device_kernel_as_string(DeviceKernel kernel); #ifndef __KERNEL_ONEAPI__ std::ostream &operator<<(std::ostream &os, DeviceKernel kernel); -typedef uint64_t DeviceKernelMask; +using DeviceKernelMask = uint64_t; string device_kernel_mask_as_string(DeviceKernelMask mask); #endif diff --git a/intern/cycles/device/memory.cpp b/intern/cycles/device/memory.cpp index 0c446b1d75b..a0df3ac128b 100644 --- a/intern/cycles/device/memory.cpp +++ b/intern/cycles/device/memory.cpp @@ -21,12 +21,12 @@ device_memory::device_memory(Device *device, const char *_name, MemoryType type) name_storage(_name), device(device), device_pointer(0), - host_pointer(0), - shared_pointer(0), + host_pointer(nullptr), + shared_pointer(nullptr), shared_counter(0), original_device_ptr(0), original_device_size(0), - original_device(0), + original_device(nullptr), need_realloc_(false), modified(false) { @@ -35,14 +35,14 @@ device_memory::device_memory(Device *device, const char *_name, MemoryType type) device_memory::~device_memory() { - assert(shared_pointer == 0); + assert(shared_pointer == nullptr); assert(shared_counter == 0); } void *device_memory::host_alloc(size_t size) { if (!size) { - return 0; + return nullptr; } void *ptr = util_aligned_malloc(size, MIN_ALIGNMENT_CPU_DATA_TYPES); @@ -61,8 +61,8 @@ void device_memory::host_free() { if (host_pointer) { util_guarded_mem_free(memory_size()); - util_aligned_free((void *)host_pointer); - host_pointer = 0; + util_aligned_free(host_pointer); + host_pointer = nullptr; } } diff --git a/intern/cycles/device/memory.h b/intern/cycles/device/memory.h index 65d3dcdb81e..03f719ebd8a 100644 --- a/intern/cycles/device/memory.h +++ b/intern/cycles/device/memory.h @@ -13,7 +13,6 @@ #include "util/string.h" #include "util/texture.h" #include "util/types.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -239,7 +238,7 @@ class device_memory { size_t data_depth; MemoryType type; const char *name; - std::string name_storage; + string name_storage; /* Pointers. */ Device *device; @@ -256,6 +255,16 @@ class device_memory { bool is_resident(Device *sub_device) const; + /* No copying and allowed. + * + * This is because device implementation might need to register device memory in an allocation + * map of some sort and use pointer as a key to identify blocks. Moving data from one place to + * another bypassing device allocation routines will make those maps hard to maintain. */ + device_memory(const device_memory &) = delete; + device_memory(device_memory &&other) noexcept = delete; + device_memory &operator=(const device_memory &) = delete; + device_memory &operator=(device_memory &&) = delete; + protected: friend class Device; friend class GPUDevice; @@ -269,16 +278,6 @@ class device_memory { /* Only create through subclasses. */ device_memory(Device *device, const char *name, MemoryType type); - /* No copying and allowed. - * - * This is because device implementation might need to register device memory in an allocation - * map of some sort and use pointer as a key to identify blocks. Moving data from one place to - * another bypassing device allocation routines will make those maps hard to maintain. */ - device_memory(const device_memory &) = delete; - device_memory(device_memory &&other) noexcept = delete; - device_memory &operator=(const device_memory &) = delete; - device_memory &operator=(device_memory &&) = delete; - /* Host allocation on the device. All host_pointer memory should be * allocated with these functions, for devices that support using * the same pointer for host and device. */ @@ -317,7 +316,7 @@ template class device_only_memory : public device_memory { device_only_memory(device_only_memory &&other) noexcept : device_memory(std::move(other)) {} - virtual ~device_only_memory() + ~device_only_memory() override { free(); } @@ -377,7 +376,7 @@ template class device_vector : public device_memory { assert(data_elements > 0); } - virtual ~device_vector() + ~device_vector() override { free(); } @@ -614,7 +613,7 @@ class device_texture : public device_memory { ImageDataType image_data_type, InterpolationType interpolation, ExtensionType extension); - ~device_texture(); + ~device_texture() override; void *alloc(const size_t width, const size_t height, const size_t depth = 0); void copy_to_device(); diff --git a/intern/cycles/device/metal/bvh.h b/intern/cycles/device/metal/bvh.h index 854ae588aff..ac206ba6d72 100644 --- a/intern/cycles/device/metal/bvh.h +++ b/intern/cycles/device/metal/bvh.h @@ -38,7 +38,7 @@ class BVHMetal : public BVH { const vector &geometry, const vector &objects, Device *device); - virtual ~BVHMetal(); + ~BVHMetal() override; bool build_BLAS(Progress &progress, id device, id queue, bool refit); bool build_BLAS_mesh(Progress &progress, diff --git a/intern/cycles/device/metal/bvh.mm b/intern/cycles/device/metal/bvh.mm index a261eef2c01..ffcd9df3b81 100644 --- a/intern/cycles/device/metal/bvh.mm +++ b/intern/cycles/device/metal/bvh.mm @@ -4,6 +4,10 @@ #ifdef WITH_METAL +# include +# include +# include + # include "scene/hair.h" # include "scene/mesh.h" # include "scene/object.h" @@ -1058,14 +1062,12 @@ bool BVHMetal::build_TLAS(Progress &progress, if (it != instance_mapping.end()) { return it->second; } - else { - int blas_index = (int)[all_blas count]; - instance_mapping[blas] = blas_index; - if (@available(macos 12.0, *)) { - [all_blas addObject:(blas ? blas->accel_struct : null_BLAS)]; - } - return blas_index; + int blas_index = (int)[all_blas count]; + instance_mapping[blas] = blas_index; + if (@available(macos 12.0, *)) { + [all_blas addObject:(blas ? blas->accel_struct : null_BLAS)]; } + return blas_index; }; MTLResourceOptions storage_mode; @@ -1180,7 +1182,7 @@ bool BVHMetal::build_TLAS(Progress &progress, for (int i = 0; i < key_count; i++) { float *t = (float *)&motion_transforms[motion_transform_index++]; /* Transpose transform */ - auto src = (float const *)&keys[i]; + const auto *src = (float const *)&keys[i]; for (int i = 0; i < 12; i++) { t[i] = src[(i / 3) + 4 * (i % 3)]; } @@ -1192,7 +1194,7 @@ bool BVHMetal::build_TLAS(Progress &progress, float *t = (float *)&motion_transforms[motion_transform_index++]; if (ob->get_geometry()->is_instanced()) { /* Transpose transform */ - auto src = (float const *)&ob->get_tfm(); + const auto *src = (float const *)&ob->get_tfm(); for (int i = 0; i < 12; i++) { t[i] = src[(i / 3) + 4 * (i % 3)]; } @@ -1217,7 +1219,7 @@ bool BVHMetal::build_TLAS(Progress &progress, float *t = (float *)&desc.transformationMatrix; if (ob->get_geometry()->is_instanced()) { /* Transpose transform */ - auto src = (float const *)&ob->get_tfm(); + const auto *src = (float const *)&ob->get_tfm(); for (int i = 0; i < 12; i++) { t[i] = src[(i / 3) + 4 * (i % 3)]; } @@ -1328,9 +1330,7 @@ bool BVHMetal::build(Progress &progress, if (!params.top_level) { return build_BLAS(progress, mtl_device, queue, refit); } - else { - return build_TLAS(progress, mtl_device, queue, refit); - } + return build_TLAS(progress, mtl_device, queue, refit); } } diff --git a/intern/cycles/device/metal/device.mm b/intern/cycles/device/metal/device.mm index 7228f966855..afa830d52ea 100644 --- a/intern/cycles/device/metal/device.mm +++ b/intern/cycles/device/metal/device.mm @@ -2,6 +2,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "device/device.h" + #ifdef WITH_METAL # include "device/metal/device.h" @@ -102,15 +104,16 @@ void device_metal_info(vector &devices) VLOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\"."; - if (info.denoisers & DENOISER_OPENIMAGEDENOISE) + if (info.denoisers & DENOISER_OPENIMAGEDENOISE) { VLOG_INFO << "Device with id \"" << info.id << "\" supports " << denoiserTypeToHumanReadable(DENOISER_OPENIMAGEDENOISE) << "."; + } } } string device_metal_capabilities() { - string result = ""; + string result; auto allDevices = MTLCopyAllDevices(); uint32_t num_devices = (uint32_t)allDevices.count; if (num_devices == 0) { @@ -128,7 +131,9 @@ string device_metal_capabilities() #else -Device *device_metal_create(const DeviceInfo &info, Stats &stats, Profiler &profiler) +Device *device_metal_create(const DeviceInfo & /*info*/, + Stats & /*stats*/, + Profiler & /*profiler*/) { return nullptr; } @@ -138,7 +143,7 @@ bool device_metal_init() return false; } -void device_metal_info(vector &devices) {} +void device_metal_info(vector & /*devices*/) {} string device_metal_capabilities() { diff --git a/intern/cycles/device/metal/device_impl.h b/intern/cycles/device/metal/device_impl.h index 8e267dc4f34..02eb03b7280 100644 --- a/intern/cycles/device/metal/device_impl.h +++ b/intern/cycles/device/metal/device_impl.h @@ -36,7 +36,7 @@ class MetalDevice : public Device { bool capture_enabled = false; - KernelParamsMetal launch_params = {0}; + KernelParamsMetal launch_params = {nullptr}; /* MetalRT members ----------------------------------*/ bool use_metalrt = false; @@ -72,7 +72,7 @@ class MetalDevice : public Device { void *hostPtr = nullptr; bool use_UMA = false; /* If true, UMA memory in shared_pointer is being used. */ }; - typedef map> MetalMemMap; + using MetalMemMap = map>; MetalMemMap metal_mem_map; std::vector> delayed_free_list; std::recursive_mutex metal_mem_map_mutex; @@ -100,17 +100,17 @@ class MetalDevice : public Device { static MetalDevice *get_device_by_ID(int device_idID, thread_scoped_lock &existing_devices_mutex_lock); - virtual bool is_ready(string &status) const override; + bool is_ready(string &status) const override; - virtual void cancel() override; + void cancel() override; - virtual BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; + BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; void set_error(const string &error) override; MetalDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - virtual ~MetalDevice(); + ~MetalDevice() override; bool support_device(const uint /*kernel_features*/); @@ -128,21 +128,21 @@ class MetalDevice : public Device { void make_source(MetalPipelineType pso_type, const uint kernel_features); - virtual bool load_kernels(const uint kernel_features) override; + bool load_kernels(const uint kernel_features) override; void load_texture_info(); void erase_allocation(device_memory &mem); - virtual bool should_use_graphics_interop() override; + bool should_use_graphics_interop() override; - virtual void *get_native_buffer(device_ptr ptr) override; + void *get_native_buffer(device_ptr ptr) override; - virtual unique_ptr gpu_queue_create() override; + unique_ptr gpu_queue_create() override; - virtual void build_bvh(BVH *bvh, Progress &progress, bool refit) override; + void build_bvh(BVH *bvh, Progress &progress, bool refit) override; - virtual void optimize_for_scene(Scene *scene) override; + void optimize_for_scene(Scene *scene) override; static void compile_and_load(int device_id, MetalPipelineType pso_type); @@ -173,7 +173,7 @@ class MetalDevice : public Device { device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, size_t size) override; void global_alloc(device_memory &mem); diff --git a/intern/cycles/device/metal/device_impl.mm b/intern/cycles/device/metal/device_impl.mm index 29794d89469..470e1f251df 100644 --- a/intern/cycles/device/metal/device_impl.mm +++ b/intern/cycles/device/metal/device_impl.mm @@ -4,8 +4,11 @@ #ifdef WITH_METAL -# include "device/metal/device_impl.h" +# include +# include + # include "device/metal/device.h" +# include "device/metal/device_impl.h" # include "scene/scene.h" @@ -96,7 +99,7 @@ MetalDevice::MetalDevice(const DeviceInfo &info, Stats &stats, Profiler &profile max_threads_per_threadgroup = 512; use_metalrt = info.use_hardware_raytracing; - if (auto metalrt = getenv("CYCLES_METALRT")) { + if (auto *metalrt = getenv("CYCLES_METALRT")) { use_metalrt = (atoi(metalrt) != 0); } @@ -118,7 +121,7 @@ MetalDevice::MetalDevice(const DeviceInfo &info, Stats &stats, Profiler &profile break; } - if (auto envstr = getenv("CYCLES_METAL_SPECIALIZATION_LEVEL")) { + if (auto *envstr = getenv("CYCLES_METAL_SPECIALIZATION_LEVEL")) { kernel_specialization_level = (MetalPipelineType)atoi(envstr); } metal_printf("kernel_specialization_level = %s\n", @@ -429,8 +432,9 @@ bool MetalDevice::load_kernels(const uint _kernel_features) kernel_features |= _kernel_features; /* check if GPU is supported */ - if (!support_device(kernel_features)) + if (!support_device(kernel_features)) { return false; + } /* Keep track of whether motion blur is enabled, so to enable/disable motion in BVH builds * This is necessary since objects may be reported to have motion if the Vector pass is @@ -807,7 +811,7 @@ void MetalDevice::generic_free(device_memory &mem) mmem.use_UMA = false; } - mem.shared_pointer = 0; + mem.shared_pointer = nullptr; /* Free device memory. */ delayed_free_list.push_back(mmem.mtlBuffer); @@ -1119,7 +1123,6 @@ void MetalDevice::tex_alloc(device_texture &mem) } /* General variables for both architectures */ - string bind_name = mem.name; size_t dsize = datatype_size(mem.data_type); size_t size = mem.memory_size(); @@ -1325,8 +1328,9 @@ void MetalDevice::tex_free(device_texture &mem) MetalMem &mmem = *metal_mem_map.at(&mem); assert(texture_slot_map[mem.slot] == mmem.mtlTexture); - if (texture_slot_map[mem.slot] == mmem.mtlTexture) + if (texture_slot_map[mem.slot] == mmem.mtlTexture) { texture_slot_map[mem.slot] = nil; + } if (mmem.mtlTexture) { /* Free bindless texture. */ diff --git a/intern/cycles/device/metal/kernel.h b/intern/cycles/device/metal/kernel.h index 4fcf97b2da2..45d861d4ab5 100644 --- a/intern/cycles/device/metal/kernel.h +++ b/intern/cycles/device/metal/kernel.h @@ -7,6 +7,7 @@ #ifdef WITH_METAL # include "device/kernel.h" + # include CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/device/metal/kernel.mm b/intern/cycles/device/metal/kernel.mm index ee3540f9326..0683f0e0b93 100644 --- a/intern/cycles/device/metal/kernel.mm +++ b/intern/cycles/device/metal/kernel.mm @@ -4,9 +4,19 @@ #ifdef WITH_METAL -# include "device/metal/kernel.h" +# include +# include +# include +# include +# include +# include + # include "device/metal/device_impl.h" +# include "device/metal/kernel.h" + # include "kernel/device/metal/function_constants.h" + +# include "util/debug.h" # include "util/md5.h" # include "util/path.h" # include "util/tbb.h" @@ -310,7 +320,7 @@ void ShaderCache::load_kernel(DeviceKernel device_kernel, metal_printf("Spawning %d Cycles kernel compilation threads\n", max_mtlcompiler_threads); for (int i = 0; i < max_mtlcompiler_threads; i++) { - compile_threads.push_back(std::thread([this] { this->compile_thread_func(); })); + compile_threads.emplace_back([this] { this->compile_thread_func(); }); } } } @@ -393,7 +403,7 @@ bool MetalKernelPipeline::should_use_binary_archive() const { /* Issues with binary archives in older macOS versions. */ if (@available(macOS 13.0, *)) { - if (auto str = getenv("CYCLES_METAL_DISABLE_BINARY_ARCHIVES")) { + if (auto *str = getenv("CYCLES_METAL_DISABLE_BINARY_ARCHIVES")) { if (atoi(str) != 0) { /* Don't archive if we have opted out by env var. */ return false; @@ -758,7 +768,7 @@ void MetalKernelPipeline::compile() metal_printf( "newComputePipelineStateWithDescriptor failed for \"%s\"%s. " "Error:\n%s\n", - device_kernel_as_string((DeviceKernel)device_kernel), + device_kernel_as_string(device_kernel), (archive && !recreate_archive) ? " Archive may be incomplete or corrupt - attempting " "recreation.." : "", @@ -786,7 +796,7 @@ void MetalKernelPipeline::compile() metal_printf("%16s | %2d | %-55s | %7.2fs | FAILED!\n", kernel_type_as_string(pso_type), device_kernel, - device_kernel_as_string((DeviceKernel)device_kernel), + device_kernel_as_string(device_kernel), duration); return; } @@ -826,7 +836,7 @@ void MetalKernelPipeline::compile() metal_printf("%16s | %2d | %-55s | %7.2fs | %s: %s\n", kernel_type_as_string(pso_type), device_kernel, - device_kernel_as_string((DeviceKernel)device_kernel), + device_kernel_as_string(device_kernel), duration, creating_new_archive ? " new" : "load", metalbin_name.c_str()); @@ -835,7 +845,7 @@ void MetalKernelPipeline::compile() bool MetalDeviceKernels::load(MetalDevice *device, MetalPipelineType pso_type) { - auto shader_cache = get_shader_cache(device->mtlDevice); + auto *shader_cache = get_shader_cache(device->mtlDevice); for (int i = 0; i < DEVICE_KERNEL_NUM; i++) { shader_cache->load_kernel((DeviceKernel)i, device, pso_type); } @@ -863,7 +873,7 @@ int MetalDeviceKernels::num_incomplete_specialization_requests() int MetalDeviceKernels::get_loaded_kernel_count(MetalDevice const *device, MetalPipelineType pso_type) { - auto shader_cache = get_shader_cache(device->mtlDevice); + auto *shader_cache = get_shader_cache(device->mtlDevice); int loaded_count = DEVICE_KERNEL_NUM; for (int i = 0; i < DEVICE_KERNEL_NUM; i++) { if (shader_cache->should_load_kernel((DeviceKernel)i, device, pso_type)) { diff --git a/intern/cycles/device/metal/queue.h b/intern/cycles/device/metal/queue.h index 3c8c138075c..e9f82977b2f 100644 --- a/intern/cycles/device/metal/queue.h +++ b/intern/cycles/device/metal/queue.h @@ -21,26 +21,26 @@ class MetalDevice; class MetalDeviceQueue : public DeviceQueue { public: MetalDeviceQueue(MetalDevice *device); - ~MetalDeviceQueue(); + ~MetalDeviceQueue() override; - virtual int num_concurrent_states(const size_t) const override; - virtual int num_concurrent_busy_states(const size_t) const override; - virtual int num_sort_partition_elements() const override; - virtual bool supports_local_atomic_sort() const override; + int num_concurrent_states(const size_t /*state_size*/) const override; + int num_concurrent_busy_states(const size_t /*state_size*/) const override; + int num_sort_partition_elements() const override; + bool supports_local_atomic_sort() const override; - virtual void init_execution() override; + void init_execution() override; - virtual bool enqueue(DeviceKernel kernel, - const int work_size, - DeviceKernelArguments const &args) override; + bool enqueue(DeviceKernel kernel, + const int work_size, + DeviceKernelArguments const &args) override; - virtual bool synchronize() override; + bool synchronize() override; - virtual void zero_to_device(device_memory &mem) override; - virtual void copy_to_device(device_memory &mem) override; - virtual void copy_from_device(device_memory &mem) override; + void zero_to_device(device_memory &mem) override; + void copy_to_device(device_memory &mem) override; + void copy_from_device(device_memory &mem) override; - virtual void *native_queue() override; + void *native_queue() override; protected: void setup_capture(); diff --git a/intern/cycles/device/metal/queue.mm b/intern/cycles/device/metal/queue.mm index a79a619019a..9bb280acb76 100644 --- a/intern/cycles/device/metal/queue.mm +++ b/intern/cycles/device/metal/queue.mm @@ -4,6 +4,9 @@ #ifdef WITH_METAL +# include +# include + # include "device/metal/queue.h" # include "device/metal/device_impl.h" @@ -38,7 +41,7 @@ MetalDeviceQueue::MetalDeviceQueue(MetalDevice *device) wait_semaphore_ = dispatch_semaphore_create(0); - if (auto str = getenv("CYCLES_METAL_PROFILING")) { + if (auto *str = getenv("CYCLES_METAL_PROFILING")) { if (atoi(str) && [mtlDevice_ supportsCounterSampling:MTLCounterSamplingPointAtStageBoundary]) { /* Enable per-kernel timing breakdown (shown at end of render). */ @@ -73,26 +76,26 @@ void MetalDeviceQueue::setup_capture() { capture_kernel_ = DeviceKernel(-1); - if (auto capture_kernel_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_KERNEL")) { + if (auto *capture_kernel_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_KERNEL")) { /* CYCLES_DEBUG_METAL_CAPTURE_KERNEL captures a single dispatch of the specified kernel. */ capture_kernel_ = DeviceKernel(atoi(capture_kernel_str)); printf("Capture kernel: %d = %s\n", capture_kernel_, device_kernel_as_string(capture_kernel_)); capture_dispatch_counter_ = 0; - if (auto capture_dispatch_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_DISPATCH")) { + if (auto *capture_dispatch_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_DISPATCH")) { capture_dispatch_counter_ = atoi(capture_dispatch_str); printf("Capture dispatch number %d\n", capture_dispatch_counter_); } } - else if (auto capture_samples_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_SAMPLES")) { + else if (auto *capture_samples_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_SAMPLES")) { /* CYCLES_DEBUG_METAL_CAPTURE_SAMPLES captures a block of dispatches from reset#(N) to * reset#(N+1). */ capture_samples_ = true; capture_reset_counter_ = atoi(capture_samples_str); capture_dispatch_counter_ = INT_MAX; - if (auto capture_limit_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_LIMIT")) { + if (auto *capture_limit_str = getenv("CYCLES_DEBUG_METAL_CAPTURE_LIMIT")) { /* CYCLES_DEBUG_METAL_CAPTURE_LIMIT sets the maximum number of dispatches to capture. */ capture_dispatch_counter_ = atoi(capture_limit_str); } @@ -114,7 +117,7 @@ void MetalDeviceQueue::setup_capture() label_command_encoders_ = true; - if (auto capture_url = getenv("CYCLES_DEBUG_METAL_CAPTURE_URL")) { + if (auto *capture_url = getenv("CYCLES_DEBUG_METAL_CAPTURE_URL")) { if ([captureManager supportsDestination:MTLCaptureDestinationGPUTraceDocument]) { MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init]; @@ -633,8 +636,9 @@ bool MetalDeviceQueue::enqueue(DeviceKernel kernel, if (IntegratorQueueCounter *queue_counter = (IntegratorQueueCounter *) it.first->host_pointer) { - for (int i = 0; i < DEVICE_KERNEL_INTEGRATOR_NUM; i++) - printf("%s%d", i == 0 ? "" : ",", int(queue_counter->num_queued[i])); + for (int i = 0; i < DEVICE_KERNEL_INTEGRATOR_NUM; i++) { + printf("%s%d", i == 0 ? "" : ",", queue_counter->num_queued[i]); + } } break; } diff --git a/intern/cycles/device/metal/util.mm b/intern/cycles/device/metal/util.mm index 2cf73a2ae61..7861fccd38f 100644 --- a/intern/cycles/device/metal/util.mm +++ b/intern/cycles/device/metal/util.mm @@ -12,9 +12,9 @@ # include "util/time.h" # include +# include # include # include -# include CCL_NAMESPACE_BEGIN @@ -36,7 +36,7 @@ int MetalInfo::get_apple_gpu_core_count(id device) io_service_t gpu_service = IOServiceGetMatchingService( kIOMainPortDefault, IORegistryEntryIDMatching(device.registryID)); if (CFNumberRef numberRef = (CFNumberRef)IORegistryEntryCreateCFProperty( - gpu_service, CFSTR("gpu-core-count"), 0, 0)) + gpu_service, CFSTR("gpu-core-count"), nullptr, 0)) { if (CFGetTypeID(numberRef) == CFNumberGetTypeID()) { CFNumberGetValue(numberRef, kCFNumberSInt32Type, &core_count); @@ -53,10 +53,10 @@ AppleGPUArchitecture MetalInfo::get_apple_gpu_architecture(id device) if (strstr(device_name, "M1")) { return APPLE_M1; } - else if (strstr(device_name, "M2")) { + if (strstr(device_name, "M2")) { return get_apple_gpu_core_count(device) <= 10 ? APPLE_M2 : APPLE_M2_BIG; } - else if (strstr(device_name, "M3")) { + if (strstr(device_name, "M3")) { return APPLE_M3; } return APPLE_UNKNOWN; @@ -64,7 +64,7 @@ AppleGPUArchitecture MetalInfo::get_apple_gpu_architecture(id device) int MetalInfo::optimal_sort_partition_elements() { - if (auto str = getenv("CYCLES_METAL_SORT_PARTITION_ELEMENTS")) { + if (auto *str = getenv("CYCLES_METAL_SORT_PARTITION_ELEMENTS")) { return atoi(str); } diff --git a/intern/cycles/device/multi/device.cpp b/intern/cycles/device/multi/device.cpp index d0bc3d0bc5b..d381738587c 100644 --- a/intern/cycles/device/multi/device.cpp +++ b/intern/cycles/device/multi/device.cpp @@ -16,9 +16,7 @@ #include "util/foreach.h" #include "util/list.h" -#include "util/log.h" #include "util/map.h" -#include "util/time.h" CCL_NAMESPACE_BEGIN @@ -32,11 +30,11 @@ class MultiDevice : public Device { }; list devices; - device_ptr unique_key; + device_ptr unique_key = 1; vector> peer_islands; MultiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless) - : Device(info, stats, profiler, headless), unique_key(1) + : Device(info, stats, profiler, headless) { foreach (const DeviceInfo &subinfo, info.multi_devices) { /* Always add CPU devices at the back since GPU devices can change @@ -82,7 +80,7 @@ class MultiDevice : public Device { } } - ~MultiDevice() + ~MultiDevice() override { foreach (SubDevice &sub, devices) delete sub.device; @@ -98,7 +96,7 @@ class MultiDevice : public Device { return error_msg; } - virtual BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const override + BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const override { BVHLayoutMask bvh_layout_mask = BVH_LAYOUT_ALL; BVHLayoutMask bvh_layout_mask_all = BVH_LAYOUT_NONE; @@ -256,7 +254,7 @@ class MultiDevice : public Device { } } - virtual void *get_cpu_osl_memory() override + void *get_cpu_osl_memory() override { /* Always return the OSL memory of the CPU device (this works since the constructor above * guarantees that CPU devices are always added to the back). */ diff --git a/intern/cycles/device/multi/device.h b/intern/cycles/device/multi/device.h index c788a56db58..a1aca0b1576 100644 --- a/intern/cycles/device/multi/device.h +++ b/intern/cycles/device/multi/device.h @@ -4,9 +4,6 @@ #pragma once -#include "util/string.h" -#include "util/vector.h" - CCL_NAMESPACE_BEGIN class Device; diff --git a/intern/cycles/device/oneapi/device.cpp b/intern/cycles/device/oneapi/device.cpp index 5c33b77ecec..dd363f3d168 100644 --- a/intern/cycles/device/oneapi/device.cpp +++ b/intern/cycles/device/oneapi/device.cpp @@ -9,9 +9,8 @@ #ifdef WITH_ONEAPI # include "device/device.h" # include "device/oneapi/device_impl.h" -# include "integrator/denoiser_oidn_gpu.h" +# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep -# include "util/path.h" # include "util/string.h" # ifdef __linux__ @@ -87,6 +86,7 @@ Device *device_oneapi_create(const DeviceInfo &info, (void)info; (void)stats; (void)profiler; + (void)headless; LOG(FATAL) << "Requested to create oneAPI device while not enabled for this build."; @@ -144,9 +144,10 @@ static void device_iterator_cb(const char *id, devices->push_back(info); VLOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\"."; - if (info.denoisers & DENOISER_OPENIMAGEDENOISE) + if (info.denoisers & DENOISER_OPENIMAGEDENOISE) { VLOG_INFO << "Device with id \"" << info.id << "\" supports " << denoiserTypeToHumanReadable(DENOISER_OPENIMAGEDENOISE) << "."; + } } #endif diff --git a/intern/cycles/device/oneapi/device_impl.cpp b/intern/cycles/device/oneapi/device_impl.cpp index 5c5919c6b09..00c6fae54eb 100644 --- a/intern/cycles/device/oneapi/device_impl.cpp +++ b/intern/cycles/device/oneapi/device_impl.cpp @@ -10,7 +10,6 @@ # include "device/oneapi/device_impl.h" -# include "util/debug.h" # include "util/foreach.h" # include "util/log.h" @@ -21,7 +20,7 @@ # if defined(WITH_OPENIMAGEDENOISE) # include # if OIDN_VERSION >= 20300 -# include "util/openimagedenoise.h" +# include "util/openimagedenoise.h" // IWYU pragma: keep # endif # endif @@ -69,7 +68,7 @@ OneapiDevice::OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profi bool is_finished_ok = create_queue(device_queue_, info.num, # ifdef WITH_EMBREE_GPU - use_hardware_raytracing ? &embree_device : nullptr + use_hardware_raytracing ? (void *)&embree_device : nullptr # else nullptr # endif @@ -130,8 +129,9 @@ OneapiDevice::OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profi OneapiDevice::~OneapiDevice() { # ifdef WITH_EMBREE_GPU - if (embree_device) + if (embree_device) { rtcReleaseDevice(embree_device); + } # endif texture_info.free(); @@ -141,8 +141,9 @@ OneapiDevice::~OneapiDevice() for (ConstMemMap::iterator mt = const_mem_map_.begin(); mt != const_mem_map_.end(); mt++) delete mt->second; - if (device_queue_) + if (device_queue_) { free_queue(device_queue_); + } } bool OneapiDevice::check_peer_access(Device * /*peer_device*/) @@ -218,12 +219,10 @@ size_t OneapiDevice::get_free_mem() const return device.get_info(); } /* Estimate: Capacity - in use. */ - else if (device_mem_in_use < max_memory_on_device_) { + if (device_mem_in_use < max_memory_on_device_) { return max_memory_on_device_ - device_mem_in_use; } - else { - return 0; - } + return 0; } bool OneapiDevice::load_kernels(const uint requested_features) @@ -244,10 +243,8 @@ bool OneapiDevice::load_kernels(const uint requested_features) "\""); return false; } - else { - VLOG_INFO << "Test kernel has been executed successfully for \"" << info.description << "\""; - assert(device_queue_); - } + VLOG_INFO << "Test kernel has been executed successfully for \"" << info.description << "\""; + assert(device_queue_); if (use_hardware_raytracing && !can_use_hardware_raytracing_for_features(requested_features)) { VLOG_INFO @@ -423,8 +420,9 @@ void OneapiDevice::mem_copy_to(device_memory &mem) tex_alloc((device_texture &)mem); } else { - if (!mem.device_pointer) + if (!mem.device_pointer) { generic_alloc(mem); + } generic_copy_to(mem); } @@ -634,7 +632,7 @@ void *OneapiDevice::usm_aligned_alloc_host(size_t memory_size, size_t alignment) void OneapiDevice::usm_free(void *usm_ptr) { assert(device_queue_); - return usm_free(device_queue_, usm_ptr); + usm_free(device_queue_, usm_ptr); } void OneapiDevice::check_usm(SyclQueue *queue_, const void *usm_ptr, bool allow_host = false) @@ -746,8 +744,9 @@ bool OneapiDevice::usm_memcpy(SyclQueue *queue_, void *dest, void *src, size_t n /* sycl::queue::memcpy may crash if the queue is in an invalid state due to previous * runtime errors. It's better to avoid running memory operations in that case. * The render will be canceled and the queue will be destroyed anyway. */ - if (have_error()) + if (have_error()) { return false; + } sycl::queue *queue = reinterpret_cast(queue_); OneapiDevice::check_usm(queue_, dest, true); @@ -779,8 +778,9 @@ bool OneapiDevice::usm_memcpy(SyclQueue *queue_, void *dest, void *src, size_t n /* NOTE(@sirgienko) Host-side blocking wait on this operation is mandatory, otherwise the host * may not wait until the end of the transfer before using the memory. */ - if (from_device_to_host || host_or_device_memop_with_offset) + if (from_device_to_host || host_or_device_memop_with_offset) { mem_event.wait(); + } return true; # endif } @@ -799,8 +799,9 @@ bool OneapiDevice::usm_memset(SyclQueue *queue_, /* sycl::queue::memset may crash if the queue is in an invalid state due to previous * runtime errors. It's better to avoid running memory operations in that case. * The render will be canceled and the queue will be destroyed anyway. */ - if (have_error()) + if (have_error()) { return false; + } sycl::queue *queue = reinterpret_cast(queue_); OneapiDevice::check_usm(queue_, usm_ptr, true); @@ -1020,9 +1021,10 @@ int parse_driver_build_version(const sycl::device &device) const std::string &third_number_substr = driver_version.substr( second_dot_position + 1, third_dot_position - second_dot_position - 1); const std::string &forth_number_substr = driver_version.substr(third_dot_position + 1); - if (third_number_substr.length() == 3 && forth_number_substr.length() == 4) + if (third_number_substr.length() == 3 && forth_number_substr.length() == 4) { driver_build_version = std::stoi(third_number_substr) * 10000 + std::stoi(forth_number_substr); + } } else { const std::string &third_number_substr = driver_version.substr(second_dot_position + 1); @@ -1280,8 +1282,7 @@ int OneapiDevice::get_num_multiprocessors() if (device.has(sycl::aspect::ext_intel_gpu_eu_count)) { return device.get_info(); } - else - return 0; + return 0; } int OneapiDevice::get_max_num_threads_per_multiprocessor() @@ -1293,8 +1294,7 @@ int OneapiDevice::get_max_num_threads_per_multiprocessor() return device.get_info() * device.get_info(); } - else - return 0; + return 0; } CCL_NAMESPACE_END diff --git a/intern/cycles/device/oneapi/device_impl.h b/intern/cycles/device/oneapi/device_impl.h index 23d8994e6d8..e32040450ec 100644 --- a/intern/cycles/device/oneapi/device_impl.h +++ b/intern/cycles/device/oneapi/device_impl.h @@ -14,12 +14,8 @@ CCL_NAMESPACE_BEGIN class DeviceQueue; -typedef void (*OneAPIDeviceIteratorCallback)(const char *id, - const char *name, - int num, - bool hwrt_support, - bool oidn_support, - void *user_ptr); +using OneAPIDeviceIteratorCallback = + void (*)(const char *, const char *, const int, bool, bool, void *); class OneapiDevice : public GPUDevice { private: @@ -46,27 +42,27 @@ class OneapiDevice : public GPUDevice { size_t get_free_mem() const; public: - virtual BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const override; + BVHLayoutMask get_bvh_layout_mask(const uint requested_features) const override; OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - virtual ~OneapiDevice(); + ~OneapiDevice() override; # ifdef WITH_EMBREE_GPU void build_bvh(BVH *bvh, Progress &progress, bool refit) override; # endif bool check_peer_access(Device *peer_device) override; - bool load_kernels(const uint kernel_features) override; + bool load_kernels(const uint requested_features) override; void reserve_private_memory(const uint kernel_features); - virtual void get_device_memory_info(size_t &total, size_t &free) override; - virtual bool alloc_device(void *&device_pointer, size_t size) override; - virtual void free_device(void *device_pointer) override; - virtual bool alloc_host(void *&shared_pointer, size_t size) override; - virtual void free_host(void *shared_pointer) override; - virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; - virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size) override; + void get_device_memory_info(size_t &total, size_t &free) override; + bool alloc_device(void *&device_pointer, const size_t size) override; + void free_device(void *device_pointer) override; + bool alloc_host(void *&shared_pointer, const size_t size) override; + void free_host(void *shared_pointer) override; + void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override; + void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override; string oneapi_error_message(); @@ -91,7 +87,7 @@ class OneapiDevice : public GPUDevice { device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override; - virtual void const_copy_to(const char *name, void *host, size_t size) override; + void const_copy_to(const char *name, void *host, const size_t size) override; void global_alloc(device_memory &mem); @@ -102,9 +98,9 @@ class OneapiDevice : public GPUDevice { void tex_free(device_texture &mem); /* Graphics resources interoperability. */ - virtual bool should_use_graphics_interop() override; + bool should_use_graphics_interop() override; - virtual unique_ptr gpu_queue_create() override; + unique_ptr gpu_queue_create() override; /* NOTE(@nsirgien): Create this methods to avoid some compilation problems on Windows with host * side compilation (MSVC). */ @@ -135,7 +131,7 @@ class OneapiDevice : public GPUDevice { SyclQueue *sycl_queue(); protected: - bool can_use_hardware_raytracing_for_features(uint kernel_features) const; + bool can_use_hardware_raytracing_for_features(const uint requested_features) const; void check_usm(SyclQueue *queue, const void *usm_ptr, bool allow_host); bool create_queue(SyclQueue *&external_queue, int device_index, void *embree_device); void free_queue(SyclQueue *queue); diff --git a/intern/cycles/device/oneapi/queue.cpp b/intern/cycles/device/oneapi/queue.cpp index 9c563457ed8..bec0eac7aff 100644 --- a/intern/cycles/device/oneapi/queue.cpp +++ b/intern/cycles/device/oneapi/queue.cpp @@ -7,9 +7,6 @@ # include "device/oneapi/queue.h" # include "device/oneapi/device_impl.h" # include "util/log.h" -# include "util/time.h" -# include -# include # include "kernel/device/oneapi/kernel.h" @@ -60,7 +57,7 @@ void OneapiDeviceQueue::init_execution() oneapi_device_->load_texture_info(); SyclQueue *device_queue = oneapi_device_->sycl_queue(); - void *kg_dptr = (void *)oneapi_device_->kernel_globals_device_pointer(); + void *kg_dptr = oneapi_device_->kernel_globals_device_pointer(); assert(device_queue); assert(kg_dptr); kernel_context_ = new KernelContext{device_queue, kg_dptr, 0}; @@ -111,9 +108,10 @@ bool OneapiDeviceQueue::synchronize() } bool is_finished_ok = oneapi_device_->queue_synchronize(oneapi_device_->sycl_queue()); - if (is_finished_ok == false) + if (is_finished_ok == false) { oneapi_device_->set_error("oneAPI unknown kernel execution error: got runtime exception \"" + oneapi_device_->oneapi_error_message() + "\""); + } debug_synchronize(); diff --git a/intern/cycles/device/oneapi/queue.h b/intern/cycles/device/oneapi/queue.h index d2f4eaa8851..41a5f572500 100644 --- a/intern/cycles/device/oneapi/queue.h +++ b/intern/cycles/device/oneapi/queue.h @@ -6,11 +6,9 @@ #ifdef WITH_ONEAPI -# include "device/kernel.h" # include "device/memory.h" # include "device/queue.h" -# include "device/oneapi/device.h" # include "kernel/device/oneapi/kernel.h" CCL_NAMESPACE_BEGIN @@ -24,25 +22,25 @@ class OneapiDeviceQueue : public DeviceQueue { explicit OneapiDeviceQueue(OneapiDevice *device); ~OneapiDeviceQueue(); - virtual int num_concurrent_states(const size_t state_size) const override; + int num_concurrent_states(const size_t state_size) const override; - virtual int num_concurrent_busy_states(const size_t state_size) const override; + int num_concurrent_busy_states(const size_t state_size) const override; - virtual int num_sort_partition_elements() const override; + int num_sort_partition_elements() const override; - virtual void init_execution() override; + void init_execution() override; - virtual bool enqueue(DeviceKernel kernel, - const int kernel_work_size, - DeviceKernelArguments const &args) override; + bool enqueue(DeviceKernel kernel, + const int kernel_work_size, + const DeviceKernelArguments &args) override; - virtual bool synchronize() override; + bool synchronize() override; - virtual void zero_to_device(device_memory &mem) override; - virtual void copy_to_device(device_memory &mem) override; - virtual void copy_from_device(device_memory &mem) override; + void zero_to_device(device_memory &mem) override; + void copy_to_device(device_memory &mem) override; + void copy_from_device(device_memory &mem) override; - virtual bool supports_local_atomic_sort() const override + bool supports_local_atomic_sort() const override { return true; } diff --git a/intern/cycles/device/optix/device.cpp b/intern/cycles/device/optix/device.cpp index a2dde6e4cef..a2dff0767b7 100644 --- a/intern/cycles/device/optix/device.cpp +++ b/intern/cycles/device/optix/device.cpp @@ -6,11 +6,6 @@ #include "device/optix/device.h" #include "device/cuda/device.h" -#include "device/optix/device_impl.h" - -#include "integrator/denoiser_oidn_gpu.h" - -#include "util/log.h" #ifdef WITH_OSL # include @@ -18,9 +13,15 @@ #endif #ifdef WITH_OPTIX +# include "device/optix/device_impl.h" + +# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep + # include #endif +#include "util/log.h" + #ifndef OPTIX_FUNCTION_TABLE_SYMBOL # define OPTIX_FUNCTION_TABLE_SYMBOL g_optixFunctionTable #endif @@ -47,7 +48,7 @@ bool device_optix_init() "Please update to the latest driver first!"; return false; } - else if (result != OPTIX_SUCCESS) { + if (result != OPTIX_SUCCESS) { VLOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result; return false; } diff --git a/intern/cycles/device/optix/device.h b/intern/cycles/device/optix/device.h index fafb8450473..b81dc2cc356 100644 --- a/intern/cycles/device/optix/device.h +++ b/intern/cycles/device/optix/device.h @@ -4,7 +4,6 @@ #pragma once -#include "util/string.h" #include "util/vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp index fe163d03039..f0826e6b75b 100644 --- a/intern/cycles/device/optix/device_impl.cpp +++ b/intern/cycles/device/optix/device_impl.cpp @@ -14,17 +14,14 @@ # include "scene/hair.h" # include "scene/mesh.h" # include "scene/object.h" -# include "scene/pass.h" # include "scene/pointcloud.h" # include "scene/scene.h" # include "util/debug.h" # include "util/log.h" -# include "util/md5.h" # include "util/path.h" # include "util/progress.h" # include "util/task.h" -# include "util/time.h" # define __KERNEL_OPTIX__ # include "kernel/device/optix/globals.h" @@ -81,6 +78,8 @@ OptiXDevice::OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profile case 4: LOG_IF(INFO, VLOG_IS_ON(1)) << message; break; + default: + break; } }; # endif @@ -168,7 +167,7 @@ static string get_optix_include_dir() const string env_include_dir = path_join(env_dir, "include"); return env_include_dir; } - else if (default_dir[0]) { + if (default_dir[0]) { const string default_include_dir = path_join(default_dir, "include"); return default_include_dir; } @@ -226,7 +225,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) "to a directory containing the OptiX SDK."); return false; } - else if (!path_is_directory(optix_include_dir)) { + if (!path_is_directory(optix_include_dir)) { set_error(string_printf( "OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install " "OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a " @@ -326,8 +325,9 @@ bool OptiXDevice::load_kernels(const uint kernel_features) pipeline_options.usesPrimitiveTypeFlags |= OPTIX_PRIMITIVE_TYPE_FLAGS_ROUND_CUBIC_BSPLINE; # endif } - else + else { pipeline_options.usesPrimitiveTypeFlags |= OPTIX_PRIMITIVE_TYPE_FLAGS_CUSTOM; + } } if (kernel_features & KERNEL_FEATURE_POINTCLOUD) { pipeline_options.usesPrimitiveTypeFlags |= OPTIX_PRIMITIVE_TYPE_FLAGS_CUSTOM; @@ -393,7 +393,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) ptx_data.data(), ptx_data.size(), nullptr, - 0, + nullptr, &optix_module); # endif if (result != OPTIX_SUCCESS) { @@ -573,7 +573,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) } optix_assert(optixProgramGroupCreate( - context, group_descs, NUM_PROGRAM_GROUPS, &group_options, nullptr, 0, groups)); + context, group_descs, NUM_PROGRAM_GROUPS, &group_options, nullptr, nullptr, groups)); /* Get program stack sizes. */ OptixStackSizes stack_size[NUM_PROGRAM_GROUPS] = {}; @@ -648,7 +648,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) pipeline_groups.data(), pipeline_groups.size(), nullptr, - 0, + nullptr, &pipelines[PIP_SHADE])); /* Combine ray generation and trace continuation stack size. */ @@ -691,7 +691,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) pipeline_groups.data(), pipeline_groups.size(), nullptr, - 0, + nullptr, &pipelines[PIP_INTERSECT])); /* Calculate continuation stack size based on the maximum of all ray generation stack sizes. */ @@ -812,7 +812,8 @@ bool OptiXDevice::load_osl_kernels() ptx_data.data(), ptx_data.size(), nullptr, - 0, + nullptr, + , &osl_modules.back()); # else const OptixResult result = optixModuleCreateFromPTX(context, @@ -821,7 +822,7 @@ bool OptiXDevice::load_osl_kernels() ptx_data.data(), ptx_data.size(), nullptr, - 0, + nullptr, &osl_modules.back()); # endif if (result != OPTIX_SUCCESS) { @@ -837,7 +838,7 @@ bool OptiXDevice::load_osl_kernels() group_desc.callables.moduleDC = osl_modules.back(); optix_assert(optixProgramGroupCreate( - context, &group_desc, 1, &group_options, nullptr, 0, &osl_groups.back())); + context, &group_desc, 1, &group_options, nullptr, nullptr, &osl_groups.back())); } TaskPool pool; @@ -884,7 +885,7 @@ bool OptiXDevice::load_osl_kernels() osl_kernels[i].ptx.data(), osl_kernels[i].ptx.size(), nullptr, - 0, + nullptr, &osl_modules[i]); }); # endif @@ -910,7 +911,7 @@ bool OptiXDevice::load_osl_kernels() group_desc.callables.moduleDC = osl_modules[i]; optix_assert(optixProgramGroupCreate( - context, &group_desc, 1, &group_options, nullptr, 0, &osl_groups[i])); + context, &group_desc, 1, &group_options, nullptr, nullptr, &osl_groups[i])); } /* Update SBT with new entries. */ @@ -963,7 +964,7 @@ bool OptiXDevice::load_osl_kernels() pipeline_groups.data(), pipeline_groups.size(), nullptr, - 0, + nullptr, &pipelines[PIP_SHADE])); /* Get program stack sizes. */ diff --git a/intern/cycles/device/optix/device_impl.h b/intern/cycles/device/optix/device_impl.h index 8edf9e1cdb2..8e5388667d1 100644 --- a/intern/cycles/device/optix/device_impl.h +++ b/intern/cycles/device/optix/device_impl.h @@ -8,7 +8,7 @@ #ifdef WITH_OPTIX # include "device/cuda/device_impl.h" -# include "device/optix/util.h" +# include "device/optix/util.h" // IWYU pragma: keep # include "kernel/osl/globals.h" CCL_NAMESPACE_BEGIN @@ -89,7 +89,7 @@ class OptiXDevice : public CUDADevice { public: OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless); - ~OptiXDevice(); + ~OptiXDevice() override; BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override; @@ -113,7 +113,7 @@ class OptiXDevice : public CUDADevice { void update_launch_params(size_t offset, void *data, size_t data_size); - virtual unique_ptr gpu_queue_create() override; + unique_ptr gpu_queue_create() override; void *get_cpu_osl_memory() override; }; diff --git a/intern/cycles/device/optix/queue.cpp b/intern/cycles/device/optix/queue.cpp index ba35072979a..b8c5a85f8d7 100644 --- a/intern/cycles/device/optix/queue.cpp +++ b/intern/cycles/device/optix/queue.cpp @@ -7,8 +7,6 @@ # include "device/optix/queue.h" # include "device/optix/device_impl.h" -# include "util/time.h" - # define __KERNEL_OPTIX__ # include "kernel/device/optix/globals.h" diff --git a/intern/cycles/device/optix/queue.h b/intern/cycles/device/optix/queue.h index 5e1b9af238f..74b18fde290 100644 --- a/intern/cycles/device/optix/queue.h +++ b/intern/cycles/device/optix/queue.h @@ -17,11 +17,11 @@ class OptiXDeviceQueue : public CUDADeviceQueue { public: OptiXDeviceQueue(OptiXDevice *device); - virtual void init_execution() override; + void init_execution() override; - virtual bool enqueue(DeviceKernel kernel, - const int work_size, - DeviceKernelArguments const &args) override; + bool enqueue(DeviceKernel kernel, + const int work_size, + const DeviceKernelArguments &args) override; }; CCL_NAMESPACE_END diff --git a/intern/cycles/device/optix/util.h b/intern/cycles/device/optix/util.h index af8e57a9467..3fd66cc25b1 100644 --- a/intern/cycles/device/optix/util.h +++ b/intern/cycles/device/optix/util.h @@ -9,12 +9,12 @@ # include "device/cuda/util.h" # ifdef WITH_CUDA_DYNLOAD -# include +# include // IWYU pragma: export // Do not use CUDA SDK headers when using CUEW # define OPTIX_DONT_INCLUDE_CUDA # endif -# include +# include // IWYU pragma: export /* Utility for checking return values of OptiX function calls. */ # define optix_device_assert(optix_device, stmt) \ diff --git a/intern/cycles/device/queue.h b/intern/cycles/device/queue.h index 6751efe28c2..e2497f2321b 100644 --- a/intern/cycles/device/queue.h +++ b/intern/cycles/device/queue.h @@ -7,7 +7,6 @@ #include "device/kernel.h" #include "device/graphics_interop.h" -#include "util/debug.h" #include "util/log.h" #include "util/map.h" #include "util/string.h" @@ -37,7 +36,7 @@ struct DeviceKernelArguments { size_t sizes[MAX_ARGS]; size_t count = 0; - DeviceKernelArguments() {} + DeviceKernelArguments() = default; template DeviceKernelArguments(const T *arg) { diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp index 0282fd2e42a..598bc3c69f8 100644 --- a/intern/cycles/graph/node.cpp +++ b/intern/cycles/graph/node.cpp @@ -14,7 +14,7 @@ CCL_NAMESPACE_BEGIN /* Node Type */ -NodeOwner::~NodeOwner() {} +NodeOwner::~NodeOwner() = default; Node::Node(const NodeType *type_, ustring name_) : name(name_), type(type_) { @@ -226,15 +226,13 @@ ustring Node::get_string(const SocketType &input) const if (input.type == SocketType::STRING) { return get_socket_value(this, input); } - else if (input.type == SocketType::ENUM) { + if (input.type == SocketType::ENUM) { const NodeEnum &enm = *input.enum_values; int intvalue = get_socket_value(this, input); return (enm.exists(intvalue)) ? enm[intvalue] : ustring(); } - else { - assert(0); - return ustring(); - } + assert(0); + return ustring(); } Transform Node::get_transform(const SocketType &input) const @@ -307,12 +305,12 @@ bool Node::has_default_value(const SocketType &input) const return memcmp(dst, src, input.size()) == 0; } -void Node::set_default_value(const SocketType &socket) +void Node::set_default_value(const SocketType &input) { - const void *src = socket.default_value; - void *dst = ((char *)this) + socket.struct_offset; - if (socket.size() > 0) { - memcpy(dst, src, socket.size()); + const void *src = input.default_value; + void *dst = ((char *)this) + input.struct_offset; + if (input.size() > 0) { + memcpy(dst, src, input.size()); } } @@ -903,7 +901,7 @@ void Node::set_if_different(const SocketType &input, array &value) void Node::print_modified_sockets() const { printf("Node : %s\n", name.c_str()); - for (auto &socket : type->inputs) { + for (const auto &socket : type->inputs) { if (socket_is_modified(socket)) { printf("-- socket modified : %s\n", socket.name.c_str()); } diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h index 2e5492d5900..d055eabb5bb 100644 --- a/intern/cycles/graph/node.h +++ b/intern/cycles/graph/node.h @@ -9,8 +9,8 @@ #include "graph/node_type.h" #include "util/array.h" -#include "util/map.h" #include "util/param.h" +#include "util/types.h" CCL_NAMESPACE_BEGIN @@ -150,9 +150,9 @@ struct Node { /* generic values operations */ bool has_default_value(const SocketType &input) const; void set_default_value(const SocketType &input); - bool equals_value(const Node &other, const SocketType &input) const; - void copy_value(const SocketType &input, const Node &other, const SocketType &other_input); - void set_value(const SocketType &input, const Node &other, const SocketType &other_input); + bool equals_value(const Node &other, const SocketType &socket) const; + void copy_value(const SocketType &socket, const Node &other, const SocketType &other_socket); + void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket); /* equals */ bool equals(const Node &other) const; diff --git a/intern/cycles/graph/node_type.cpp b/intern/cycles/graph/node_type.cpp index fb87ea4c183..f225a47cfa0 100644 --- a/intern/cycles/graph/node_type.cpp +++ b/intern/cycles/graph/node_type.cpp @@ -139,7 +139,7 @@ NodeType::NodeType(Type type, const NodeType *base) : type(type), base(base) } } -NodeType::~NodeType() {} +NodeType::~NodeType() = default; void NodeType::register_input(ustring name, ustring ui_name, diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h index 1b9f2324dc7..f6d942acccb 100644 --- a/intern/cycles/graph/node_type.h +++ b/intern/cycles/graph/node_type.h @@ -5,10 +5,9 @@ #pragma once #include "graph/node_enum.h" -#include "util/array.h" +#include "util/array.h" // IWYU pragma: keep #include "util/map.h" #include "util/param.h" -#include "util/string.h" #include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -16,7 +15,7 @@ CCL_NAMESPACE_BEGIN struct Node; struct NodeType; -typedef uint64_t SocketModifiedFlags; +using SocketModifiedFlags = uint64_t; /* Socket Type */ @@ -117,7 +116,7 @@ struct NodeType { const SocketType *find_input(ustring name) const; const SocketType *find_output(ustring name) const; - typedef Node *(*CreateFunc)(const NodeType *type); + using CreateFunc = Node *(*)(const NodeType *); ustring name; Type type; @@ -235,7 +234,7 @@ struct NodeType { ustring(ui_name), \ SocketType::NODE, \ SOCKET_OFFSETOF(T, name), \ - &defval, \ + (const void *)&defval, \ nullptr, \ node_type, \ ##__VA_ARGS__); \ diff --git a/intern/cycles/graph/node_xml.cpp b/intern/cycles/graph/node_xml.cpp index 63ae4e1ac6c..6446c64dd07 100644 --- a/intern/cycles/graph/node_xml.cpp +++ b/intern/cycles/graph/node_xml.cpp @@ -92,7 +92,7 @@ void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node) break; } case SocketType::INT: { - node->set(socket, (int)atoi(attr.value())); + node->set(socket, atoi(attr.value())); break; } case SocketType::UINT: { @@ -110,7 +110,7 @@ void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node) array value; value.resize(tokens.size()); for (size_t i = 0; i < value.size(); i++) { - value[i] = (int)atoi(attr.value()); + value[i] = atoi(attr.value()); } node->set(socket, value); break; diff --git a/intern/cycles/hydra/CMakeLists.txt b/intern/cycles/hydra/CMakeLists.txt index d8ccaff3061..c4cfd09c6a9 100644 --- a/intern/cycles/hydra/CMakeLists.txt +++ b/intern/cycles/hydra/CMakeLists.txt @@ -53,6 +53,7 @@ set(SRC_HD_CYCLES camera.cpp field.cpp file_reader.cpp + geometry.cpp instancer.cpp light.cpp material.cpp diff --git a/intern/cycles/hydra/attribute.cpp b/intern/cycles/hydra/attribute.cpp index 6d81d62cbbb..df9a088ea22 100644 --- a/intern/cycles/hydra/attribute.cpp +++ b/intern/cycles/hydra/attribute.cpp @@ -5,8 +5,6 @@ #include "hydra/attribute.h" #include "scene/attribute.h" -#include "scene/geometry.h" -#include "scene/scene.h" #include #include diff --git a/intern/cycles/hydra/camera.cpp b/intern/cycles/hydra/camera.cpp index 09d769f7cd1..28a0206bcdb 100644 --- a/intern/cycles/hydra/camera.cpp +++ b/intern/cycles/hydra/camera.cpp @@ -52,7 +52,7 @@ HdCyclesCamera::HdCyclesCamera(const SdfPath &sprimId) : HdCamera(sprimId) #endif } -HdCyclesCamera::~HdCyclesCamera() {} +HdCyclesCamera::~HdCyclesCamera() = default; HdDirtyBits HdCyclesCamera::GetInitialDirtyBitsMask() const { diff --git a/intern/cycles/hydra/camera.h b/intern/cycles/hydra/camera.h index ecbcc316b48..f46fdbd1b80 100644 --- a/intern/cycles/hydra/camera.h +++ b/intern/cycles/hydra/camera.h @@ -18,17 +18,17 @@ class HdCyclesCamera final : public PXR_NS::HdCamera { HdCyclesCamera(const PXR_NS::SdfPath &sprimId); ~HdCyclesCamera() override; - void ApplyCameraSettings(PXR_NS::HdRenderParam *renderParam, CCL_NS::Camera *targetCamera) const; + void ApplyCameraSettings(PXR_NS::HdRenderParam *renderParam, CCL_NS::Camera *cam) const; static void ApplyCameraSettings(PXR_NS::HdRenderParam *renderParam, - const PXR_NS::GfCamera &cameraData, + const PXR_NS::GfCamera &dataUnconformedWindow, PXR_NS::CameraUtilConformWindowPolicy windowPolicy, - CCL_NS::Camera *targetCamera); + CCL_NS::Camera *cam); static void ApplyCameraSettings(PXR_NS::HdRenderParam *renderParam, const PXR_NS::GfMatrix4d &worldToViewMatrix, const PXR_NS::GfMatrix4d &projectionMatrix, const std::vector &clipPlanes, - CCL_NS::Camera *targetCamera); + CCL_NS::Camera *cam); PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; diff --git a/intern/cycles/hydra/config.h b/intern/cycles/hydra/config.h index 3a2fa1bd74c..893cb74c707 100644 --- a/intern/cycles/hydra/config.h +++ b/intern/cycles/hydra/config.h @@ -5,7 +5,7 @@ #pragma once -#include +#include // IWYU pragma: export #define CCL_NS ccl #define CCL_NAMESPACE_USING_DIRECTIVE using namespace CCL_NS; diff --git a/intern/cycles/hydra/curves.cpp b/intern/cycles/hydra/curves.cpp index 4dd83047151..cf3b3c1b000 100644 --- a/intern/cycles/hydra/curves.cpp +++ b/intern/cycles/hydra/curves.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "hydra/curves.h" +#include "hydra/attribute.h" #include "hydra/geometry.inl" #include "scene/hair.h" @@ -26,7 +27,7 @@ HdCyclesCurves::HdCyclesCurves(const SdfPath &rprimId { } -HdCyclesCurves::~HdCyclesCurves() {} +HdCyclesCurves::~HdCyclesCurves() = default; HdDirtyBits HdCyclesCurves::GetInitialDirtyBitsMask() const { diff --git a/intern/cycles/hydra/display_driver.cpp b/intern/cycles/hydra/display_driver.cpp index f79af648661..b616d44ad77 100644 --- a/intern/cycles/hydra/display_driver.cpp +++ b/intern/cycles/hydra/display_driver.cpp @@ -137,7 +137,7 @@ bool HdCyclesDisplayDriver::update_begin(const Params ¶ms, glBindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_pbo_id_); glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(half4) * params.full_size.x * params.full_size.y, - 0, + nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); @@ -176,7 +176,7 @@ half4 *HdCyclesDisplayDriver::map_texture_buffer() { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_pbo_id_); - const auto mapped_rgba_pixels = static_cast( + auto *const mapped_rgba_pixels = static_cast( glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY)); if (need_clear_ && mapped_rgba_pixels) { @@ -224,7 +224,7 @@ void HdCyclesDisplayDriver::clear() void HdCyclesDisplayDriver::draw(const Params ¶ms) { - const auto renderBuffer = static_cast( + auto *const renderBuffer = static_cast( _renderParam->GetDisplayAovBinding().renderBuffer); if (!renderBuffer || // Ensure this render buffer matches the texture dimensions (renderBuffer->GetWidth() != params.size.x || renderBuffer->GetHeight() != params.size.y)) @@ -272,7 +272,8 @@ void HdCyclesDisplayDriver::draw(const Params ¶ms) glBindTexture(GL_TEXTURE_2D, texture->GetTextureId()); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_pbo_id_); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pbo_size_.x, pbo_size_.y, GL_RGBA, GL_HALF_FLOAT, 0); + glTexSubImage2D( + GL_TEXTURE_2D, 0, 0, 0, pbo_size_.x, pbo_size_.y, GL_RGBA, GL_HALF_FLOAT, nullptr); glBindTexture(GL_TEXTURE_2D, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); diff --git a/intern/cycles/hydra/display_driver.h b/intern/cycles/hydra/display_driver.h index 953eac0633c..f864363b3da 100644 --- a/intern/cycles/hydra/display_driver.h +++ b/intern/cycles/hydra/display_driver.h @@ -17,7 +17,7 @@ HDCYCLES_NAMESPACE_OPEN_SCOPE class HdCyclesDisplayDriver final : public CCL_NS::DisplayDriver { public: HdCyclesDisplayDriver(HdCyclesSession *renderParam, Hgi *hgi); - ~HdCyclesDisplayDriver(); + ~HdCyclesDisplayDriver() override; private: void next_tile_begin() override; diff --git a/intern/cycles/hydra/field.cpp b/intern/cycles/hydra/field.cpp index 20fb650fadf..617f6c24216 100644 --- a/intern/cycles/hydra/field.cpp +++ b/intern/cycles/hydra/field.cpp @@ -50,7 +50,7 @@ HdCyclesField::HdCyclesField(const SdfPath &bprimId, const TfToken & /*typeId*/) { } -HdCyclesField::~HdCyclesField() {} +HdCyclesField::~HdCyclesField() = default; HdDirtyBits HdCyclesField::GetInitialDirtyBitsMask() const { diff --git a/intern/cycles/hydra/geometry.cpp b/intern/cycles/hydra/geometry.cpp new file mode 100644 index 00000000000..14bddc607fa --- /dev/null +++ b/intern/cycles/hydra/geometry.cpp @@ -0,0 +1,9 @@ +/* SPDX-FileCopyrightText: 2022 NVIDIA Corporation + * SPDX-FileCopyrightText: 2022 Blender Foundation + * + * SPDX-License-Identifier: Apache-2.0 */ + +/* Dummy file to make clangd happy. */ + +#include "hydra/geometry.h" +#include "hydra/geometry.inl" diff --git a/intern/cycles/hydra/geometry.h b/intern/cycles/hydra/geometry.h index 2c52c39588e..a991bf42b8a 100644 --- a/intern/cycles/hydra/geometry.h +++ b/intern/cycles/hydra/geometry.h @@ -27,7 +27,7 @@ template class HdCyclesGeometry : public Bas PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; - virtual void Finalize(PXR_NS::HdRenderParam *renderParam) override; + void Finalize(PXR_NS::HdRenderParam *renderParam) override; protected: void _InitRepr(const PXR_NS::TfToken &reprToken, PXR_NS::HdDirtyBits *dirtyBits) override; diff --git a/intern/cycles/hydra/geometry.inl b/intern/cycles/hydra/geometry.inl index 95b5fd8a46a..8fd11fa0429 100644 --- a/intern/cycles/hydra/geometry.inl +++ b/intern/cycles/hydra/geometry.inl @@ -3,7 +3,6 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "hydra/attribute.h" #include "hydra/geometry.h" #include "hydra/instancer.h" #include "hydra/material.h" @@ -89,7 +88,7 @@ void HdCyclesGeometry::Sync(HdSceneDelegate *sceneDelegate, sceneDelegate->GetMaterialId(Base::GetId())); #endif - const auto material = static_cast( + const auto *const material = static_cast( sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material, Base::GetMaterialId())); @@ -120,8 +119,9 @@ void HdCyclesGeometry::Sync(HdSceneDelegate *sceneDelegate, } if (HdChangeTracker::IsTransformDirty(*dirtyBits, id) || - HdChangeTracker::IsInstancerDirty(*dirtyBits, id)) { - const auto instancer = static_cast( + HdChangeTracker::IsInstancerDirty(*dirtyBits, id)) + { + auto *const instancer = static_cast( sceneDelegate->GetRenderIndex().GetInstancer(Base::GetInstancerId())); // Make sure the first object attribute is the instanceId @@ -244,7 +244,8 @@ HdInterpolation HdCyclesGeometry::GetPrimvarInterpolation( { for (int i = 0; i < HdInterpolationCount; ++i) { for (const HdPrimvarDescriptor &desc : - Base::GetPrimvarDescriptors(sceneDelegate, static_cast(i))) { + Base::GetPrimvarDescriptors(sceneDelegate, static_cast(i))) + { if (desc.name == name) { return static_cast(i); } diff --git a/intern/cycles/hydra/instancer.cpp b/intern/cycles/hydra/instancer.cpp index ae7ced42ea7..dd19ee86c2e 100644 --- a/intern/cycles/hydra/instancer.cpp +++ b/intern/cycles/hydra/instancer.cpp @@ -135,7 +135,7 @@ VtMatrix4dArray HdCyclesInstancer::ComputeInstanceTransforms(const SdfPath &prot VtMatrix4dArray resultTransforms; - if (const auto instancer = static_cast( + if (auto *const instancer = static_cast( GetDelegate()->GetRenderIndex().GetInstancer(GetParentId()))) { for (const GfMatrix4d &parentTransform : instancer->ComputeInstanceTransforms(GetId())) { diff --git a/intern/cycles/hydra/light.cpp b/intern/cycles/hydra/light.cpp index d07fe47f5ef..6ef1999ab46 100644 --- a/intern/cycles/hydra/light.cpp +++ b/intern/cycles/hydra/light.cpp @@ -30,7 +30,7 @@ HdCyclesLight::HdCyclesLight(const SdfPath &sprimId, const TfToken &lightType) { } -HdCyclesLight::~HdCyclesLight() {} +HdCyclesLight::~HdCyclesLight() = default; HdDirtyBits HdCyclesLight::GetInitialDirtyBitsMask() const { @@ -190,7 +190,7 @@ void HdCyclesLight::Sync(HdSceneDelegate *sceneDelegate, void HdCyclesLight::PopulateShaderGraph(HdSceneDelegate *sceneDelegate) { - auto graph = new ShaderGraph(); + auto *graph = new ShaderGraph(); ShaderNode *outputNode = nullptr; if (_lightType == HdPrimTypeTokens->domeLight) { diff --git a/intern/cycles/hydra/material.cpp b/intern/cycles/hydra/material.cpp index 22077fc5063..dbfeccf469a 100644 --- a/intern/cycles/hydra/material.cpp +++ b/intern/cycles/hydra/material.cpp @@ -188,7 +188,7 @@ TfStaticData sUsdToCyles; HdCyclesMaterial::HdCyclesMaterial(const SdfPath &sprimId) : HdMaterial(sprimId) {} -HdCyclesMaterial::~HdCyclesMaterial() {} +HdCyclesMaterial::~HdCyclesMaterial() = default; HdDirtyBits HdCyclesMaterial::GetInitialDirtyBitsMask() const { @@ -417,7 +417,7 @@ void HdCyclesMaterial::PopulateShaderGraph(const HdMaterialNetwork2 &networkMap) { _nodes.clear(); - auto graph = new ShaderGraph(); + auto *graph = new ShaderGraph(); // Iterate all the nodes first and build a complete but unconnected graph with parameters set for (const auto &nodeEntry : networkMap.nodes) { diff --git a/intern/cycles/hydra/mesh.cpp b/intern/cycles/hydra/mesh.cpp index 5ceaea1c7e9..4c061e5bd76 100644 --- a/intern/cycles/hydra/mesh.cpp +++ b/intern/cycles/hydra/mesh.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "hydra/mesh.h" +#include "hydra/attribute.h" #include "hydra/geometry.inl" #include "scene/mesh.h" @@ -96,7 +97,7 @@ HdCyclesMesh::HdCyclesMesh(const SdfPath &rprimId { } -HdCyclesMesh::~HdCyclesMesh() {} +HdCyclesMesh::~HdCyclesMesh() = default; HdDirtyBits HdCyclesMesh::GetInitialDirtyBitsMask() const { @@ -416,7 +417,7 @@ void HdCyclesMesh::PopulateTopology(HdSceneDelegate *sceneDelegate) shader = it->second; } else { - const auto material = static_cast( + const auto *const material = static_cast( sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material, geomSubset.materialId)); diff --git a/intern/cycles/hydra/output_driver.cpp b/intern/cycles/hydra/output_driver.cpp index 4204730e9d7..9fedf7901dc 100644 --- a/intern/cycles/hydra/output_driver.cpp +++ b/intern/cycles/hydra/output_driver.cpp @@ -20,7 +20,7 @@ void HdCyclesOutputDriver::write_render_tile(const Tile &tile) // Update convergence state of all render buffers for (const HdRenderPassAovBinding &aovBinding : _renderParam->GetAovBindings()) { - if (const auto renderBuffer = static_cast(aovBinding.renderBuffer)) { + if (auto *const renderBuffer = static_cast(aovBinding.renderBuffer)) { renderBuffer->SetConverged(true); } } @@ -31,7 +31,7 @@ bool HdCyclesOutputDriver::update_render_tile(const Tile &tile) std::vector pixels; for (const HdRenderPassAovBinding &aovBinding : _renderParam->GetAovBindings()) { - if (const auto renderBuffer = static_cast(aovBinding.renderBuffer)) { + if (auto *const renderBuffer = static_cast(aovBinding.renderBuffer)) { if (aovBinding == _renderParam->GetDisplayAovBinding() && renderBuffer->IsResourceUsed()) { continue; // Display AOV binding is already updated by Cycles display driver } diff --git a/intern/cycles/hydra/plugin.h b/intern/cycles/hydra/plugin.h index 5c9e00fa4dc..6a79ade9c80 100644 --- a/intern/cycles/hydra/plugin.h +++ b/intern/cycles/hydra/plugin.h @@ -22,7 +22,8 @@ class HdCyclesPlugin final : public PXR_NS::HdRendererPlugin { #endif PXR_NS::HdRenderDelegate *CreateRenderDelegate() override; - PXR_NS::HdRenderDelegate *CreateRenderDelegate(const PXR_NS::HdRenderSettingsMap &) override; + PXR_NS::HdRenderDelegate *CreateRenderDelegate( + const PXR_NS::HdRenderSettingsMap & /*settingsMap*/) override; void DeleteRenderDelegate(PXR_NS::HdRenderDelegate *) override; }; diff --git a/intern/cycles/hydra/pointcloud.cpp b/intern/cycles/hydra/pointcloud.cpp index 17e2283cd96..3deee4eb8e3 100644 --- a/intern/cycles/hydra/pointcloud.cpp +++ b/intern/cycles/hydra/pointcloud.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "hydra/pointcloud.h" +#include "hydra/attribute.h" #include "hydra/geometry.inl" #include "scene/pointcloud.h" @@ -26,7 +27,7 @@ HdCyclesPoints::HdCyclesPoints(const SdfPath &rprimId { } -HdCyclesPoints::~HdCyclesPoints() {} +HdCyclesPoints::~HdCyclesPoints() = default; HdDirtyBits HdCyclesPoints::GetInitialDirtyBitsMask() const { diff --git a/intern/cycles/hydra/render_buffer.cpp b/intern/cycles/hydra/render_buffer.cpp index fb5cef3c54a..abb374add82 100644 --- a/intern/cycles/hydra/render_buffer.cpp +++ b/intern/cycles/hydra/render_buffer.cpp @@ -14,7 +14,7 @@ HDCYCLES_NAMESPACE_OPEN_SCOPE HdCyclesRenderBuffer::HdCyclesRenderBuffer(const SdfPath &bprimId) : HdRenderBuffer(bprimId) {} -HdCyclesRenderBuffer::~HdCyclesRenderBuffer() {} +HdCyclesRenderBuffer::~HdCyclesRenderBuffer() = default; void HdCyclesRenderBuffer::Finalize(HdRenderParam *renderParam) { diff --git a/intern/cycles/hydra/render_delegate.cpp b/intern/cycles/hydra/render_delegate.cpp index d475e64ecc5..329c4087179 100644 --- a/intern/cycles/hydra/render_delegate.cpp +++ b/intern/cycles/hydra/render_delegate.cpp @@ -133,7 +133,7 @@ HdCyclesDelegate::HdCyclesDelegate(const HdRenderSettingsMap &settingsMap, } } -HdCyclesDelegate::~HdCyclesDelegate() {} +HdCyclesDelegate::~HdCyclesDelegate() = default; void HdCyclesDelegate::SetDrivers(const HdDriverVector &drivers) { @@ -486,28 +486,27 @@ VtValue HdCyclesDelegate::GetRenderSetting(const TfToken &key) const if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) { return VtValue(_renderParam->GetStageMetersPerUnit()); } - else if (key == HdCyclesRenderSettingsTokens->device) { + if (key == HdCyclesRenderSettingsTokens->device) { return VtValue(TfToken(Device::string_from_type(session->params.device.type))); } - else if (key == HdCyclesRenderSettingsTokens->threads) { + if (key == HdCyclesRenderSettingsTokens->threads) { return VtValue(session->params.threads); } - else if (key == HdCyclesRenderSettingsTokens->timeLimit) { + if (key == HdCyclesRenderSettingsTokens->timeLimit) { return VtValue(session->params.time_limit); } - else if (key == HdCyclesRenderSettingsTokens->samples) { + if (key == HdCyclesRenderSettingsTokens->samples) { return VtValue(session->params.samples); } - else if (key == HdCyclesRenderSettingsTokens->sampleOffset) { + if (key == HdCyclesRenderSettingsTokens->sampleOffset) { return VtValue(session->params.sample_offset); } - else { - const std::string &keyString = key.GetString(); - if (keyString.rfind("cycles:integrator:", 0) == 0) { - ustring socketName(keyString, sizeof("cycles:integrator:") - 1); - if (const SocketType *socket = scene->integrator->type->find_input(socketName)) { - return GetNodeValue(scene->integrator, *socket); - } + + const std::string &keyString = key.GetString(); + if (keyString.rfind("cycles:integrator:", 0) == 0) { + ustring socketName(keyString, sizeof("cycles:integrator:") - 1); + if (const SocketType *socket = scene->integrator->type->find_input(socketName)) { + return GetNodeValue(scene->integrator, *socket); } } diff --git a/intern/cycles/hydra/render_pass.cpp b/intern/cycles/hydra/render_pass.cpp index 64fccd1f409..d5ce9c6baf9 100644 --- a/intern/cycles/hydra/render_pass.cpp +++ b/intern/cycles/hydra/render_pass.cpp @@ -35,7 +35,7 @@ HdCyclesRenderPass::HdCyclesRenderPass(HdRenderIndex *index, session->set_output_driver(make_unique(renderParam)); - const auto renderDelegate = static_cast( + const auto *const renderDelegate = static_cast( GetRenderIndex()->GetRenderDelegate()); if (renderDelegate->IsDisplaySupported()) { #ifdef WITH_HYDRA_DISPLAY_DRIVER @@ -65,7 +65,7 @@ bool HdCyclesRenderPass::IsConverged() const void HdCyclesRenderPass::ResetConverged() { for (const HdRenderPassAovBinding &aovBinding : _renderParam->GetAovBindings()) { - if (const auto renderBuffer = static_cast(aovBinding.renderBuffer)) { + if (auto *const renderBuffer = static_cast(aovBinding.renderBuffer)) { renderBuffer->SetConverged(false); } } @@ -82,7 +82,7 @@ void HdCyclesRenderPass::_Execute(const HdRenderPassStateSharedPtr &renderPassSt } if (scene->mutex.try_lock()) { - const auto renderDelegate = static_cast( + auto *const renderDelegate = static_cast( GetRenderIndex()->GetRenderDelegate()); const unsigned int settingsVersion = renderDelegate->GetRenderSettingsVersion(); @@ -124,7 +124,9 @@ void HdCyclesRenderPass::_Execute(const HdRenderPassStateSharedPtr &renderPassSt scene->camera->set_full_height(int(vp[3])); #endif - if (const auto camera = static_cast(renderPassState->GetCamera())) { + if (const auto *const camera = static_cast( + renderPassState->GetCamera())) + { camera->ApplyCameraSettings(_renderParam, scene->camera); } else { diff --git a/intern/cycles/hydra/session.cpp b/intern/cycles/hydra/session.cpp index d4424b91edd..5a247c19a8e 100644 --- a/intern/cycles/hydra/session.cpp +++ b/intern/cycles/hydra/session.cpp @@ -33,7 +33,7 @@ SceneLock::SceneLock(const HdRenderParam *renderParam) { } -SceneLock::~SceneLock() {} +SceneLock::~SceneLock() = default; HdCyclesSession::HdCyclesSession(Session *session_, const bool keep_nodes) : session(session_), keep_nodes(keep_nodes), _ownCyclesSession(false) @@ -122,7 +122,7 @@ void HdCyclesSession::UpdateScene() for (ShaderNode *node : scene->default_background->graph->nodes) { if (node->is_a(BackgroundNode::get_node_type())) { BackgroundNode *bgNode = static_cast(node); - bgNode->set_color((scene->lights.size() == 0) ? make_float3(0.5f) : zero_float3()); + bgNode->set_color((scene->lights.empty()) ? make_float3(0.5f) : zero_float3()); } } } diff --git a/intern/cycles/hydra/volume.cpp b/intern/cycles/hydra/volume.cpp index 0cac0dc21d4..c9c37578807 100644 --- a/intern/cycles/hydra/volume.cpp +++ b/intern/cycles/hydra/volume.cpp @@ -31,7 +31,7 @@ HdCyclesVolume::HdCyclesVolume(const SdfPath &rprimId { } -HdCyclesVolume::~HdCyclesVolume() {} +HdCyclesVolume::~HdCyclesVolume() = default; HdDirtyBits HdCyclesVolume::GetInitialDirtyBitsMask() const { @@ -47,7 +47,7 @@ void HdCyclesVolume::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyB if (dirtyBits & HdChangeTracker::DirtyVolumeField) { for (const HdVolumeFieldDescriptor &field : sceneDelegate->GetVolumeFieldDescriptors(GetId())) { - if (const auto openvdbAsset = static_cast( + if (auto *const openvdbAsset = static_cast( sceneDelegate->GetRenderIndex().GetBprim(_tokens->openvdbAsset, field.fieldId))) { const ustring name(field.fieldName.GetString()); diff --git a/intern/cycles/integrator/adaptive_sampling.cpp b/intern/cycles/integrator/adaptive_sampling.cpp index 67a3f097334..f74c156d16c 100644 --- a/intern/cycles/integrator/adaptive_sampling.cpp +++ b/intern/cycles/integrator/adaptive_sampling.cpp @@ -8,7 +8,7 @@ CCL_NAMESPACE_BEGIN -AdaptiveSampling::AdaptiveSampling() {} +AdaptiveSampling::AdaptiveSampling() = default; int AdaptiveSampling::align_samples(int start_sample, int num_samples) const { diff --git a/intern/cycles/integrator/denoiser.cpp b/intern/cycles/integrator/denoiser.cpp index 7e36005b060..fcf93546ff6 100644 --- a/intern/cycles/integrator/denoiser.cpp +++ b/intern/cycles/integrator/denoiser.cpp @@ -10,7 +10,9 @@ #ifdef WITH_OPENIMAGEDENOISE # include "integrator/denoiser_oidn_gpu.h" #endif -#include "integrator/denoiser_optix.h" +#ifdef WITH_OPTIX +# include "integrator/denoiser_optix.h" +#endif #include "session/buffers.h" #include "util/log.h" diff --git a/intern/cycles/integrator/denoiser.h b/intern/cycles/integrator/denoiser.h index f93f864f406..e116d85612e 100644 --- a/intern/cycles/integrator/denoiser.h +++ b/intern/cycles/integrator/denoiser.h @@ -45,7 +45,7 @@ class Denoiser { * - The device might be MultiDevice. * - If Denoiser from params is not supported by provided denoise device, then Blender will * fallback on the OIDN CPU denoising and use provided cpu_fallback_device. */ - static unique_ptr create(Device *denoise_device, + static unique_ptr create(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams ¶ms); diff --git a/intern/cycles/integrator/denoiser_gpu.cpp b/intern/cycles/integrator/denoiser_gpu.cpp index 6c3a2f18a0d..4b1f0563c2a 100644 --- a/intern/cycles/integrator/denoiser_gpu.cpp +++ b/intern/cycles/integrator/denoiser_gpu.cpp @@ -8,10 +8,12 @@ #include "device/device.h" #include "device/memory.h" #include "device/queue.h" + #include "integrator/pass_accessor_gpu.h" + #include "session/buffers.h" + #include "util/log.h" -#include "util/progress.h" CCL_NAMESPACE_BEGIN @@ -22,7 +24,7 @@ DenoiserGPU::DenoiserGPU(Device *denoiser_device, const DenoiseParams ¶ms) DCHECK(denoiser_queue_); } -DenoiserGPU::~DenoiserGPU() +DenoiserGPU::~DenoiserGPU() // NOLINT { /* Explicit implementation, to allow forward declaration of Device in the header. */ } diff --git a/intern/cycles/integrator/denoiser_gpu.h b/intern/cycles/integrator/denoiser_gpu.h index 6e4f62a4089..db52ea16d18 100644 --- a/intern/cycles/integrator/denoiser_gpu.h +++ b/intern/cycles/integrator/denoiser_gpu.h @@ -6,6 +6,8 @@ #include "integrator/denoiser.h" +#include "session/buffers.h" + CCL_NAMESPACE_BEGIN /* Implementation of Denoiser which uses a device-specific denoising implementation, running on a @@ -14,12 +16,12 @@ CCL_NAMESPACE_BEGIN class DenoiserGPU : public Denoiser { public: DenoiserGPU(Device *denoiser_device, const DenoiseParams ¶ms); - ~DenoiserGPU(); + ~DenoiserGPU() override; - virtual bool denoise_buffer(const BufferParams &buffer_params, - RenderBuffers *render_buffers, - const int num_samples, - bool allow_inplace_modification) override; + bool denoise_buffer(const BufferParams &buffer_params, + RenderBuffers *render_buffers, + const int num_samples, + bool allow_inplace_modification) override; protected: class DenoisePass; diff --git a/intern/cycles/integrator/denoiser_oidn.cpp b/intern/cycles/integrator/denoiser_oidn.cpp index 0e994a76f75..61c5293327c 100644 --- a/intern/cycles/integrator/denoiser_oidn.cpp +++ b/intern/cycles/integrator/denoiser_oidn.cpp @@ -15,9 +15,6 @@ #include "util/openimagedenoise.h" #include "util/path.h" -#include "kernel/device/cpu/compat.h" -#include "kernel/device/cpu/kernel.h" - CCL_NAMESPACE_BEGIN thread_mutex OIDNDenoiser::mutex_; @@ -62,7 +59,7 @@ class OIDNPass { use_denoising_albedo = pass_info.use_denoising_albedo; } - inline operator bool() const + operator bool() const { return name[0] != '\0'; } @@ -180,7 +177,7 @@ class OIDNDenoiseContext { oidn_filter.setProgressMonitorFunction(oidn_progress_monitor_function, denoiser_); oidn_filter.set("hdr", true); oidn_filter.set("srgb", false); - if (custom_weights.size()) { + if (!custom_weights.empty()) { oidn_filter.setData("weights", custom_weights.data(), custom_weights.size()); } set_quality(oidn_filter); diff --git a/intern/cycles/integrator/denoiser_oidn.h b/intern/cycles/integrator/denoiser_oidn.h index 9f11b0f1d8f..27c452c9d49 100644 --- a/intern/cycles/integrator/denoiser_oidn.h +++ b/intern/cycles/integrator/denoiser_oidn.h @@ -6,7 +6,6 @@ #include "integrator/denoiser.h" #include "util/thread.h" -#include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN @@ -19,13 +18,13 @@ class OIDNDenoiser : public Denoiser { OIDNDenoiser(Device *denoiser_device, const DenoiseParams ¶ms); - virtual bool denoise_buffer(const BufferParams &buffer_params, - RenderBuffers *render_buffers, - const int num_samples, - bool allow_inplace_modification) override; + bool denoise_buffer(const BufferParams &buffer_params, + RenderBuffers *render_buffers, + const int num_samples, + bool allow_inplace_modification) override; protected: - virtual uint get_device_type_mask() const override; + uint get_device_type_mask() const override; /* We only perform one denoising at a time, since OpenImageDenoise itself is multithreaded. * Use this mutex whenever images are passed to the OIDN and needs to be denoised. */ diff --git a/intern/cycles/integrator/denoiser_oidn_gpu.cpp b/intern/cycles/integrator/denoiser_oidn_gpu.cpp index 4b756913363..789ef7173c5 100644 --- a/intern/cycles/integrator/denoiser_oidn_gpu.cpp +++ b/intern/cycles/integrator/denoiser_oidn_gpu.cpp @@ -6,20 +6,15 @@ # include "integrator/denoiser_oidn_gpu.h" -# include - # include "device/device.h" # include "device/oneapi/device_impl.h" # include "device/queue.h" -# include "integrator/pass_accessor_cpu.h" + # include "session/buffers.h" -# include "util/array.h" + # include "util/log.h" # include "util/path.h" -# include "kernel/device/cpu/compat.h" -# include "kernel/device/cpu/kernel.h" - # if OIDN_VERSION_MAJOR < 2 # define oidnSetFilterBool oidnSetFilter1b # define oidnSetFilterInt oidnSetFilter1i @@ -204,7 +199,7 @@ OIDNFilter OIDNDenoiserGPU::create_filter() const char *error_message = nullptr; OIDNFilter filter = oidnNewFilter(oidn_device_, "RT"); if (filter == nullptr) { - OIDNError err = oidnGetDeviceError(oidn_device_, (const char **)&error_message); + OIDNError err = oidnGetDeviceError(oidn_device_, &error_message); if (OIDN_ERROR_NONE != err) { LOG(ERROR) << "OIDN error: " << error_message; set_error(error_message); @@ -245,7 +240,7 @@ bool OIDNDenoiserGPU::commit_and_execute_filter(OIDNFilter filter, ExecMode mode } /* If OIDN runs out of memory, reduce mem limit and retry */ - err = oidnGetDeviceError(oidn_device_, (const char **)&error_message); + err = oidnGetDeviceError(oidn_device_, &error_message); if (err != OIDN_ERROR_OUT_OF_MEMORY || max_mem_ < 200) { break; } diff --git a/intern/cycles/integrator/denoiser_oidn_gpu.h b/intern/cycles/integrator/denoiser_oidn_gpu.h index 868dc2463b7..1b5903231b1 100644 --- a/intern/cycles/integrator/denoiser_oidn_gpu.h +++ b/intern/cycles/integrator/denoiser_oidn_gpu.h @@ -21,12 +21,12 @@ class OIDNDenoiserGPU : public DenoiserGPU { class State; OIDNDenoiserGPU(Device *denoiser_device, const DenoiseParams ¶ms); - ~OIDNDenoiserGPU(); + ~OIDNDenoiserGPU() override; - virtual bool denoise_buffer(const BufferParams &buffer_params, - RenderBuffers *render_buffers, - const int num_samples, - bool allow_inplace_modification) override; + bool denoise_buffer(const BufferParams &buffer_params, + RenderBuffers *render_buffers, + const int num_samples, + bool allow_inplace_modification) override; static bool is_device_supported(const DeviceInfo &device); @@ -36,18 +36,18 @@ class OIDNDenoiserGPU : public DenoiserGPU { ASYNC, }; - virtual uint get_device_type_mask() const override; + uint get_device_type_mask() const override; /* Create OIDN denoiser descriptor if needed. * Will do nothing if the current OIDN descriptor is usable for the given parameters. * If the OIDN denoiser descriptor did re-allocate here it is left unconfigured. */ - virtual bool denoise_create_if_needed(DenoiseContext &context) override; + bool denoise_create_if_needed(DenoiseContext &context) override; /* Configure existing OIDN denoiser descriptor for the use for the given task. */ - virtual bool denoise_configure_if_needed(DenoiseContext &context) override; + bool denoise_configure_if_needed(DenoiseContext &context) override; /* Run configured denoiser. */ - virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass) override; + bool denoise_run(const DenoiseContext &context, const DenoisePass &pass) override; OIDNFilter create_filter(); bool commit_and_execute_filter(OIDNFilter filter, ExecMode mode = ExecMode::SYNC); diff --git a/intern/cycles/integrator/pass_accessor.cpp b/intern/cycles/integrator/pass_accessor.cpp index ba41d10ad87..e2f3631f552 100644 --- a/intern/cycles/integrator/pass_accessor.cpp +++ b/intern/cycles/integrator/pass_accessor.cpp @@ -5,12 +5,8 @@ #include "integrator/pass_accessor.h" #include "session/buffers.h" -#include "util/log.h" -// clang-format off -#include "kernel/device/cpu/compat.h" -#include "kernel/types.h" -// clang-format on +#include "util/log.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/pass_accessor.h b/intern/cycles/integrator/pass_accessor.h index a839d6a1933..429976835aa 100644 --- a/intern/cycles/integrator/pass_accessor.h +++ b/intern/cycles/integrator/pass_accessor.h @@ -6,8 +6,6 @@ #include "scene/pass.h" #include "util/half.h" -#include "util/string.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/pass_accessor_cpu.cpp b/intern/cycles/integrator/pass_accessor_cpu.cpp index b890bedce34..5b7103be2d3 100644 --- a/intern/cycles/integrator/pass_accessor_cpu.cpp +++ b/intern/cycles/integrator/pass_accessor_cpu.cpp @@ -8,15 +8,9 @@ #include "session/buffers.h" -#include "util/log.h" #include "util/tbb.h" -// clang-format off -#include "kernel/device/cpu/compat.h" -#include "kernel/device/cpu/globals.h" #include "kernel/types.h" -#include "kernel/film/read.h" -// clang-format on CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/pass_accessor_gpu.cpp b/intern/cycles/integrator/pass_accessor_gpu.cpp index 42b5003e99a..11cc403aaf2 100644 --- a/intern/cycles/integrator/pass_accessor_gpu.cpp +++ b/intern/cycles/integrator/pass_accessor_gpu.cpp @@ -2,11 +2,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "device/queue.h" + #include "integrator/pass_accessor_gpu.h" -#include "device/queue.h" #include "session/buffers.h" -#include "util/log.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/pass_accessor_gpu.h b/intern/cycles/integrator/pass_accessor_gpu.h index 731d553fd52..749b4323953 100644 --- a/intern/cycles/integrator/pass_accessor_gpu.h +++ b/intern/cycles/integrator/pass_accessor_gpu.h @@ -5,6 +5,7 @@ #pragma once #include "integrator/pass_accessor.h" + #include "kernel/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp index e0543ed78c3..e30e27d02c5 100644 --- a/intern/cycles/integrator/path_trace.cpp +++ b/intern/cycles/integrator/path_trace.cpp @@ -6,16 +6,18 @@ #include "device/cpu/device.h" #include "device/device.h" + #include "integrator/pass_accessor.h" #include "integrator/path_trace_display.h" #include "integrator/path_trace_tile.h" #include "integrator/render_scheduler.h" + #include "scene/pass.h" #include "scene/scene.h" + #include "session/tile.h" -#include "util/algorithm.h" + #include "util/log.h" -#include "util/math.h" #include "util/progress.h" #include "util/tbb.h" #include "util/time.h" @@ -1006,11 +1008,11 @@ static string get_layer_view_name(const RenderBuffers &buffers) { string result; - if (buffers.params.layer.size()) { + if (!buffers.params.layer.empty()) { result += string(buffers.params.layer); } - if (buffers.params.view.size()) { + if (!buffers.params.view.empty()) { if (!result.empty()) { result += ", "; } diff --git a/intern/cycles/integrator/path_trace.h b/intern/cycles/integrator/path_trace.h index bdacbd83ec9..eeb46007542 100644 --- a/intern/cycles/integrator/path_trace.h +++ b/intern/cycles/integrator/path_trace.h @@ -46,7 +46,7 @@ class PathTrace { /* Render scheduler is used to report timing information and access things like start/finish * sample. */ PathTrace(Device *device, - Device *denoiser_device, + Device *denoise_device, Film *film, DeviceScene *device_scene, RenderScheduler &render_scheduler, diff --git a/intern/cycles/integrator/path_trace_display.h b/intern/cycles/integrator/path_trace_display.h index 0eaa83be524..ca9a6544262 100644 --- a/intern/cycles/integrator/path_trace_display.h +++ b/intern/cycles/integrator/path_trace_display.h @@ -8,7 +8,6 @@ #include "util/half.h" #include "util/thread.h" -#include "util/types.h" #include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/path_trace_tile.cpp b/intern/cycles/integrator/path_trace_tile.cpp index 7707b0c45b0..f2beb49e863 100644 --- a/intern/cycles/integrator/path_trace_tile.cpp +++ b/intern/cycles/integrator/path_trace_tile.cpp @@ -6,9 +6,7 @@ #include "integrator/pass_accessor_cpu.h" #include "integrator/path_trace.h" -#include "scene/film.h" #include "scene/pass.h" -#include "scene/scene.h" #include "session/buffers.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/path_trace_tile.h b/intern/cycles/integrator/path_trace_tile.h index 9c999f35898..5247e89ba1c 100644 --- a/intern/cycles/integrator/path_trace_tile.h +++ b/intern/cycles/integrator/path_trace_tile.h @@ -18,10 +18,12 @@ class PathTraceTile : public OutputDriver::Tile { public: PathTraceTile(PathTrace &path_trace); - bool get_pass_pixels(const string_view pass_name, const int num_channels, float *pixels) const; + bool get_pass_pixels(const string_view pass_name, + const int num_channels, + float *pixels) const override; bool set_pass_pixels(const string_view pass_name, const int num_channels, - const float *pixels) const; + const float *pixels) const override; private: PathTrace &path_trace_; diff --git a/intern/cycles/integrator/path_trace_work.cpp b/intern/cycles/integrator/path_trace_work.cpp index 98ea5cbea3a..3774577b659 100644 --- a/intern/cycles/integrator/path_trace_work.cpp +++ b/intern/cycles/integrator/path_trace_work.cpp @@ -8,8 +8,10 @@ #include "integrator/path_trace_work.h" #include "integrator/path_trace_work_cpu.h" #include "integrator/path_trace_work_gpu.h" + #include "scene/film.h" #include "scene/scene.h" + #include "session/buffers.h" #include "kernel/types.h" @@ -19,7 +21,7 @@ CCL_NAMESPACE_BEGIN unique_ptr PathTraceWork::create(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag) + const bool *cancel_requested_flag) { if (device->info.type == DEVICE_CPU) { return make_unique(device, film, device_scene, cancel_requested_flag); @@ -35,7 +37,7 @@ unique_ptr PathTraceWork::create(Device *device, PathTraceWork::PathTraceWork(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag) + const bool *cancel_requested_flag) : device_(device), film_(film), device_scene_(device_scene), @@ -45,7 +47,7 @@ PathTraceWork::PathTraceWork(Device *device, { } -PathTraceWork::~PathTraceWork() {} +PathTraceWork::~PathTraceWork() = default; RenderBuffers *PathTraceWork::get_render_buffers() { diff --git a/intern/cycles/integrator/path_trace_work.h b/intern/cycles/integrator/path_trace_work.h index ea7423dc1f2..27470e8642b 100644 --- a/intern/cycles/integrator/path_trace_work.h +++ b/intern/cycles/integrator/path_trace_work.h @@ -7,7 +7,6 @@ #include "integrator/pass_accessor.h" #include "scene/pass.h" #include "session/buffers.h" -#include "util/types.h" #include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN @@ -33,7 +32,7 @@ class PathTraceWork { static unique_ptr create(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag); + const bool *cancel_requested_flag); virtual ~PathTraceWork(); @@ -128,7 +127,7 @@ class PathTraceWork { /* Cheap-ish request to see whether rendering is requested and is to be stopped as soon as * possible, without waiting for any samples to be finished. */ - inline bool is_cancel_requested() const + bool is_cancel_requested() const { /* NOTE: Rely on the fact that on x86 CPU reading scalar can happen without atomic even in * threaded environment. */ @@ -143,14 +142,18 @@ class PathTraceWork { #ifdef WITH_PATH_GUIDING /* Initializes the per-thread guiding kernel data. */ - virtual void guiding_init_kernel_globals(void *, void *, const bool) {} + virtual void guiding_init_kernel_globals(void * /*unused*/, + void * /*unused*/, + const bool /*unused*/) + { + } #endif protected: PathTraceWork(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag); + const bool *cancel_requested_flag); PassAccessor::PassAccessInfo get_display_pass_access_info(PassMode pass_mode) const; @@ -182,7 +185,7 @@ class PathTraceWork { BufferParams effective_big_tile_params_; BufferParams effective_buffer_params_; - bool *cancel_requested_flag_ = nullptr; + const bool *cancel_requested_flag_ = nullptr; }; CCL_NAMESPACE_END diff --git a/intern/cycles/integrator/path_trace_work_cpu.cpp b/intern/cycles/integrator/path_trace_work_cpu.cpp index 60f555ede37..00ec28be13e 100644 --- a/intern/cycles/integrator/path_trace_work_cpu.cpp +++ b/intern/cycles/integrator/path_trace_work_cpu.cpp @@ -7,7 +7,6 @@ #include "device/cpu/kernel.h" #include "device/device.h" -#include "kernel/film/write.h" #include "kernel/integrator/path_state.h" #include "integrator/pass_accessor_cpu.h" @@ -16,8 +15,6 @@ #include "scene/scene.h" #include "session/buffers.h" -#include "util/atomic.h" -#include "util/log.h" #include "util/tbb.h" CCL_NAMESPACE_BEGIN @@ -45,7 +42,7 @@ static inline CPUKernelThreadGlobals *kernel_thread_globals_get( PathTraceWorkCPU::PathTraceWorkCPU(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag) + const bool *cancel_requested_flag) : PathTraceWork(device, film, device_scene, cancel_requested_flag), kernels_(Device::get_cpu_kernels()) { @@ -232,7 +229,7 @@ int PathTraceWorkCPU::adaptive_sampling_converge_filter_count_active(float thres /* Check convergency and do x-filter in a single `parallel_for`, to reduce threading overhead. */ local_arena.execute([&]() { parallel_for(full_y, full_y + height, [&](int y) { - CPUKernelThreadGlobals *kernel_globals = &kernel_thread_globals_[0]; + CPUKernelThreadGlobals *kernel_globals = kernel_thread_globals_.data(); bool row_converged = true; uint num_row_pixels_active = 0; @@ -257,7 +254,7 @@ int PathTraceWorkCPU::adaptive_sampling_converge_filter_count_active(float thres if (num_active_pixels) { local_arena.execute([&]() { parallel_for(full_x, full_x + width, [&](int x) { - CPUKernelThreadGlobals *kernel_globals = &kernel_thread_globals_[0]; + CPUKernelThreadGlobals *kernel_globals = kernel_thread_globals_.data(); kernels_.adaptive_sampling_filter_y( kernel_globals, render_buffer, x, full_y, height, offset, stride); }); @@ -279,7 +276,7 @@ void PathTraceWorkCPU::cryptomatte_postproces() /* Check convergency and do x-filter in a single `parallel_for`, to reduce threading overhead. */ local_arena.execute([&]() { parallel_for(0, height, [&](int y) { - CPUKernelThreadGlobals *kernel_globals = &kernel_thread_globals_[0]; + CPUKernelThreadGlobals *kernel_globals = kernel_thread_globals_.data(); int pixel_index = y * width; for (int x = 0; x < width; ++x, ++pixel_index) { @@ -334,7 +331,9 @@ void PathTraceWorkCPU::guiding_init_kernel_globals(void *guiding_field, } void PathTraceWorkCPU::guiding_push_sample_data_to_global_storage( - KernelGlobalsCPU *kg, IntegratorStateCPU *state, ccl_global float *ccl_restrict render_buffer) + KernelGlobalsCPU *kg, + IntegratorStateCPU *state, + ccl_global const float *ccl_restrict render_buffer) { # ifdef WITH_CYCLES_DEBUG if (VLOG_WORK_IS_ON) { diff --git a/intern/cycles/integrator/path_trace_work_cpu.h b/intern/cycles/integrator/path_trace_work_cpu.h index 97f3e734276..310b43b20b4 100644 --- a/intern/cycles/integrator/path_trace_work_cpu.h +++ b/intern/cycles/integrator/path_trace_work_cpu.h @@ -31,26 +31,24 @@ class PathTraceWorkCPU : public PathTraceWork { PathTraceWorkCPU(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag); + const bool *cancel_requested_flag); - virtual void init_execution() override; + void init_execution() override; - virtual void render_samples(RenderStatistics &statistics, - int start_sample, - int samples_num, - int sample_offset) override; + void render_samples(RenderStatistics &statistics, + int start_sample, + int samples_num, + int sample_offset) override; - virtual void copy_to_display(PathTraceDisplay *display, - PassMode pass_mode, - int num_samples) override; - virtual void destroy_gpu_resources(PathTraceDisplay *display) override; + void copy_to_display(PathTraceDisplay *display, PassMode pass_mode, int num_samples) override; + void destroy_gpu_resources(PathTraceDisplay *display) override; - virtual bool copy_render_buffers_from_device() override; - virtual bool copy_render_buffers_to_device() override; - virtual bool zero_render_buffers() override; + bool copy_render_buffers_from_device() override; + bool copy_render_buffers_to_device() override; + bool zero_render_buffers() override; - virtual int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override; - virtual void cryptomatte_postproces() override; + int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override; + void cryptomatte_postproces() override; #ifdef WITH_PATH_GUIDING /* Initializes the per-thread guiding kernel data. The function sets the pointers to the @@ -63,9 +61,10 @@ class PathTraceWorkCPU : public PathTraceWork { /* Pushes the collected training data/samples of a path to the global sample storage. * This function is called at the end of a random walk/path generation. */ - void guiding_push_sample_data_to_global_storage(KernelGlobalsCPU *kernel_globals, + void guiding_push_sample_data_to_global_storage(KernelGlobalsCPU *kg, IntegratorStateCPU *state, - ccl_global float *ccl_restrict render_buffer); + ccl_global const float *ccl_restrict + render_buffer); #endif protected: diff --git a/intern/cycles/integrator/path_trace_work_gpu.cpp b/intern/cycles/integrator/path_trace_work_gpu.cpp index a0732d9ec39..d8c9a3d556b 100644 --- a/intern/cycles/integrator/path_trace_work_gpu.cpp +++ b/intern/cycles/integrator/path_trace_work_gpu.cpp @@ -3,17 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "integrator/path_trace_work_gpu.h" -#include "integrator/path_trace_display.h" #include "device/device.h" #include "integrator/pass_accessor_gpu.h" +#include "integrator/path_trace_display.h" + #include "scene/scene.h" #include "session/buffers.h" + #include "util/log.h" #include "util/string.h" -#include "util/tbb.h" -#include "util/time.h" #include "kernel/types.h" @@ -77,7 +77,7 @@ static size_t estimate_single_state_size(const uint kernel_features) PathTraceWorkGPU::PathTraceWorkGPU(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag) + const bool *cancel_requested_flag) : PathTraceWork(device, film, device_scene, cancel_requested_flag), queue_(device->gpu_queue_create()), integrator_state_soa_kernel_features_(0), @@ -486,7 +486,7 @@ bool PathTraceWorkGPU::enqueue_path_iteration() enqueue_path_iteration(DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW); return true; } - else if (queue_counter->num_queued[DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW]) { + if (queue_counter->num_queued[DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW]) { enqueue_path_iteration(DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW); return true; } @@ -842,14 +842,14 @@ bool PathTraceWorkGPU::enqueue_work_tiles(bool &finished) } /* If we couldn't get any more tiles, we're done. */ - if (work_tiles.size() == 0 && num_paths == 0) { + if (work_tiles.empty() && num_paths == 0) { finished = true; return false; } } /* Initialize paths from work tiles. */ - if (work_tiles.size() == 0) { + if (work_tiles.empty()) { return false; } diff --git a/intern/cycles/integrator/path_trace_work_gpu.h b/intern/cycles/integrator/path_trace_work_gpu.h index a0cac1c71f8..88d5a439ac8 100644 --- a/intern/cycles/integrator/path_trace_work_gpu.h +++ b/intern/cycles/integrator/path_trace_work_gpu.h @@ -27,27 +27,25 @@ class PathTraceWorkGPU : public PathTraceWork { PathTraceWorkGPU(Device *device, Film *film, DeviceScene *device_scene, - bool *cancel_requested_flag); + const bool *cancel_requested_flag); - virtual void alloc_work_memory() override; - virtual void init_execution() override; + void alloc_work_memory() override; + void init_execution() override; - virtual void render_samples(RenderStatistics &statistics, - int start_sample, - int samples_num, - int sample_offset) override; + void render_samples(RenderStatistics &statistics, + int start_sample, + int samples_num, + int sample_offset) override; - virtual void copy_to_display(PathTraceDisplay *display, - PassMode pass_mode, - int num_samples) override; - virtual void destroy_gpu_resources(PathTraceDisplay *display) override; + void copy_to_display(PathTraceDisplay *display, PassMode pass_mode, int num_samples) override; + void destroy_gpu_resources(PathTraceDisplay *display) override; - virtual bool copy_render_buffers_from_device() override; - virtual bool copy_render_buffers_to_device() override; - virtual bool zero_render_buffers() override; + bool copy_render_buffers_from_device() override; + bool copy_render_buffers_to_device() override; + bool zero_render_buffers() override; - virtual int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override; - virtual void cryptomatte_postproces() override; + int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override; + void cryptomatte_postproces() override; protected: void alloc_integrator_soa(); diff --git a/intern/cycles/integrator/render_scheduler.cpp b/intern/cycles/integrator/render_scheduler.cpp index 7f72fe458e2..79d4a34a6b5 100644 --- a/intern/cycles/integrator/render_scheduler.cpp +++ b/intern/cycles/integrator/render_scheduler.cpp @@ -6,8 +6,8 @@ #include "session/session.h" #include "session/tile.h" + #include "util/log.h" -#include "util/math.h" #include "util/time.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/integrator/render_scheduler.h b/intern/cycles/integrator/render_scheduler.h index dfa8976414e..8b6819c28df 100644 --- a/intern/cycles/integrator/render_scheduler.h +++ b/intern/cycles/integrator/render_scheduler.h @@ -5,8 +5,10 @@ #pragma once #include "integrator/adaptive_sampling.h" -#include "integrator/denoiser.h" /* For DenoiseParams. */ +#include "integrator/denoiser.h" + #include "session/buffers.h" + #include "util/string.h" CCL_NAMESPACE_BEGIN @@ -78,7 +80,7 @@ class RenderWork { /* Conversion to bool, to simplify checks about whether there is anything to be done for this * work. */ - inline operator bool() const + operator bool() const { return path_trace.num_samples || adaptive_sampling.filter || display.update || tile.denoise || tile.write || full.write; @@ -240,7 +242,7 @@ class RenderScheduler { /* Calculate how many samples there are to be rendered for the very first path trace after reset. */ - int get_num_samples_during_navigation(int resolution_divier) const; + int get_num_samples_during_navigation(int resolution_divider) const; /* Whether adaptive sampling convergence check and filter is to happen. */ bool work_need_adaptive_filter() const; @@ -288,7 +290,7 @@ class RenderScheduler { * takes to perform task on the final resolution. */ class TimeWithAverage { public: - inline void reset() + void reset() { total_wall_time_ = 0.0; @@ -298,24 +300,24 @@ class RenderScheduler { last_sample_time_ = 0.0; } - inline void add_wall(double time) + void add_wall(double time) { total_wall_time_ += time; } - inline void add_average(double time, int num_measurements = 1) + void add_average(double time, int num_measurements = 1) { average_time_accumulator_ += time; num_average_times_ += num_measurements; last_sample_time_ = time / num_measurements; } - inline double get_wall() const + double get_wall() const { return total_wall_time_; } - inline double get_average() const + double get_average() const { if (num_average_times_ == 0) { return 0; @@ -323,12 +325,12 @@ class RenderScheduler { return average_time_accumulator_ / num_average_times_; } - inline double get_last_sample_time() const + double get_last_sample_time() const { return last_sample_time_; } - inline void reset_average() + void reset_average() { average_time_accumulator_ = 0.0; num_average_times_ = 0; diff --git a/intern/cycles/integrator/tile.cpp b/intern/cycles/integrator/tile.cpp index b930ce59aac..1cefaf133eb 100644 --- a/intern/cycles/integrator/tile.cpp +++ b/intern/cycles/integrator/tile.cpp @@ -5,7 +5,7 @@ #include "integrator/tile.h" #include "util/log.h" -#include "util/math.h" +#include "util/math_base.h" #include diff --git a/intern/cycles/integrator/tile.h b/intern/cycles/integrator/tile.h index 607caa2b6aa..dc56f540ea1 100644 --- a/intern/cycles/integrator/tile.h +++ b/intern/cycles/integrator/tile.h @@ -6,23 +6,23 @@ #include -#include "util/types.h" +#include "util/types_int2.h" CCL_NAMESPACE_BEGIN struct TileSize { TileSize() = default; - inline TileSize(int width, int height, int num_samples) + TileSize(int width, int height, int num_samples) : width(width), height(height), num_samples(num_samples) { } - inline bool operator==(const TileSize &other) const + bool operator==(const TileSize &other) const { return width == other.width && height == other.height && num_samples == other.num_samples; } - inline bool operator!=(const TileSize &other) const + bool operator!=(const TileSize &other) const { return !(*this == other); } diff --git a/intern/cycles/integrator/work_balancer.cpp b/intern/cycles/integrator/work_balancer.cpp index d00008ea490..83f914c14bb 100644 --- a/intern/cycles/integrator/work_balancer.cpp +++ b/intern/cycles/integrator/work_balancer.cpp @@ -4,9 +4,7 @@ #include "integrator/work_balancer.h" -#include "util/math.h" - -#include "util/log.h" +#include "util/math_base.h" CCL_NAMESPACE_BEGIN @@ -18,7 +16,7 @@ void work_balance_do_initial(vector &work_balance_infos) work_balance_infos[0].weight = 1.0; return; } - else if (num_infos == 0) { + if (num_infos == 0) { return; } diff --git a/intern/cycles/integrator/work_tile_scheduler.cpp b/intern/cycles/integrator/work_tile_scheduler.cpp index ef2374d01eb..74c3e5ea11f 100644 --- a/intern/cycles/integrator/work_tile_scheduler.cpp +++ b/intern/cycles/integrator/work_tile_scheduler.cpp @@ -7,12 +7,11 @@ #include "device/queue.h" #include "integrator/tile.h" #include "session/buffers.h" -#include "util/atomic.h" #include "util/log.h" CCL_NAMESPACE_BEGIN -WorkTileScheduler::WorkTileScheduler() {} +WorkTileScheduler::WorkTileScheduler() = default; void WorkTileScheduler::set_accelerated_rt(bool accelerated_rt) { diff --git a/intern/cycles/integrator/work_tile_scheduler.h b/intern/cycles/integrator/work_tile_scheduler.h index f06f41c0dac..7df80817cab 100644 --- a/intern/cycles/integrator/work_tile_scheduler.h +++ b/intern/cycles/integrator/work_tile_scheduler.h @@ -5,7 +5,8 @@ #pragma once #include "integrator/tile.h" -#include "util/types.h" + +#include "util/types_int2.h" CCL_NAMESPACE_BEGIN @@ -20,7 +21,7 @@ class WorkTileScheduler { WorkTileScheduler(); /* To indicate if there is accelerated RT support. */ - void set_accelerated_rt(bool state); + void set_accelerated_rt(bool accelerated_rt); /* MAximum path states which are allowed to be used by a single scheduled work tile. * diff --git a/intern/cycles/kernel/bake/bake.h b/intern/cycles/kernel/bake/bake.h index 4fb353ae013..9689fa761ca 100644 --- a/intern/cycles/kernel/bake/bake.h +++ b/intern/cycles/kernel/bake/bake.h @@ -11,6 +11,7 @@ #include "kernel/integrator/surface_shader.h" #include "kernel/geom/object.h" +#include "kernel/geom/shader_data.h" #include "kernel/util/colorspace.h" diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h index 5c94121e33a..7334c795d91 100644 --- a/intern/cycles/kernel/bvh/bvh.h +++ b/intern/cycles/kernel/bvh/bvh.h @@ -4,6 +4,7 @@ #pragma once +#include "kernel/bvh/nodes.h" #include "kernel/bvh/types.h" #include "kernel/bvh/util.h" @@ -67,8 +68,6 @@ CCL_NAMESPACE_BEGIN * the code has been extended and modified to support more primitives and work * with CPU and various GPU kernel languages. */ -# include "kernel/bvh/nodes.h" - /* Regular BVH traversal */ # define BVH_FUNCTION_NAME bvh_intersect diff --git a/intern/cycles/kernel/bvh/nodes.h b/intern/cycles/kernel/bvh/nodes.h index beeb4cc11f4..6d0ac621f69 100644 --- a/intern/cycles/kernel/bvh/nodes.h +++ b/intern/cycles/kernel/bvh/nodes.h @@ -2,6 +2,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "kernel/geom/object.h" +#include "kernel/globals.h" + +CCL_NAMESPACE_BEGIN + // TODO(sergey): Look into avoid use of full Transform and use 3x3 matrix and // 3-vector which might be faster. ccl_device_forceinline Transform bvh_unaligned_node_fetch_space(KernelGlobals kg, @@ -139,7 +144,7 @@ ccl_device_forceinline int bvh_node_intersect(KernelGlobals kg, if (__float_as_uint(node.x) & PATH_RAY_NODE_UNALIGNED) { return bvh_unaligned_node_intersect(kg, P, dir, idir, tmin, tmax, node_addr, visibility, dist); } - else { - return bvh_aligned_node_intersect(kg, P, idir, tmin, tmax, node_addr, visibility, dist); - } + return bvh_aligned_node_intersect(kg, P, idir, tmin, tmax, node_addr, visibility, dist); } + +CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/bvh/shadow_all.h b/intern/cycles/kernel/bvh/shadow_all.h index 13754a62a99..a78f7eb259c 100644 --- a/intern/cycles/kernel/bvh/shadow_all.h +++ b/intern/cycles/kernel/bvh/shadow_all.h @@ -257,7 +257,7 @@ ccl_device_inline * so that we can detect this and trace another ray if needed. */ ++(*r_num_recorded_hits); - const uint max_record_hits = min(max_hits, INTEGRATOR_SHADOW_ISECT_SIZE); + const uint max_record_hits = min(max_hits, (uint)INTEGRATOR_SHADOW_ISECT_SIZE); if (*r_num_recorded_hits <= max_record_hits || isect.t < tmax_hits) { integrator_state_write_shadow_isect(state, &isect, isect_index); diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h index 369db6dfbc5..7572b0a4009 100644 --- a/intern/cycles/kernel/bvh/util.h +++ b/intern/cycles/kernel/bvh/util.h @@ -88,12 +88,13 @@ ccl_device int intersections_compare(const void *a, const void *b) const Intersection *isect_a = (const Intersection *)a; const Intersection *isect_b = (const Intersection *)b; - if (isect_a->t < isect_b->t) + if (isect_a->t < isect_b->t) { return -1; - else if (isect_a->t > isect_b->t) + } + if (isect_a->t > isect_b->t) { return 1; - else - return 0; + } + return 0; } #endif @@ -195,10 +196,8 @@ ccl_device_inline int intersection_find_attribute(KernelGlobals kg, if (UNLIKELY(attr_map.element == 0)) { return (int)ATTR_STD_NOT_FOUND; } - else { - /* Chain jump to a different part of the table. */ - attr_offset = attr_map.offset; - } + /* Chain jump to a different part of the table. */ + attr_offset = attr_map.offset; } else { attr_offset += ATTR_PRIM_TYPES; @@ -207,7 +206,7 @@ ccl_device_inline int intersection_find_attribute(KernelGlobals kg, } /* return result */ - return (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.offset; + return (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.offset; } /* Transparent Shadows */ diff --git a/intern/cycles/kernel/camera/camera.h b/intern/cycles/kernel/camera/camera.h index acdd5437e3e..ef1339a3a02 100644 --- a/intern/cycles/kernel/camera/camera.h +++ b/intern/cycles/kernel/camera/camera.h @@ -425,9 +425,7 @@ ccl_device_inline float camera_distance(KernelGlobals kg, float3 P) float3 camD = make_float3(cameratoworld.x.z, cameratoworld.y.z, cameratoworld.z.z); return fabsf(dot((P - camP), camD)); } - else { - return len(P - camP); - } + return len(P - camP); } ccl_device_inline float camera_z_depth(KernelGlobals kg, float3 P) @@ -436,11 +434,9 @@ ccl_device_inline float camera_z_depth(KernelGlobals kg, float3 P) Transform worldtocamera = kernel_data.cam.worldtocamera; return transform_point(&worldtocamera, P).z; } - else { - Transform cameratoworld = kernel_data.cam.cameratoworld; - float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w); - return len(P - camP); - } + Transform cameratoworld = kernel_data.cam.cameratoworld; + float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w); + return len(P - camP); } ccl_device_inline float3 camera_direction_from_point(KernelGlobals kg, float3 P) @@ -451,10 +447,8 @@ ccl_device_inline float3 camera_direction_from_point(KernelGlobals kg, float3 P) float3 camD = make_float3(cameratoworld.x.z, cameratoworld.y.z, cameratoworld.z.z); return -camD; } - else { - float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w); - return normalize(camP - P); - } + float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w); + return normalize(camP - P); } ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, @@ -463,25 +457,26 @@ ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, { if (kernel_data.cam.type != CAMERA_PANORAMA) { /* perspective / ortho */ - if (sd->object == PRIM_NONE && kernel_data.cam.type == CAMERA_PERSPECTIVE) + if (sd->object == PRIM_NONE && kernel_data.cam.type == CAMERA_PERSPECTIVE) { P += camera_position(kg); + } ProjectionTransform tfm = kernel_data.cam.worldtondc; return transform_perspective(&tfm, P); } - else { - /* panorama */ - Transform tfm = kernel_data.cam.worldtocamera; + /* panorama */ + Transform tfm = kernel_data.cam.worldtocamera; - if (sd->object != OBJECT_NONE) - P = normalize(transform_point(&tfm, P)); - else - P = normalize(transform_direction(&tfm, P)); - - float2 uv = direction_to_panorama(&kernel_data.cam, P); - - return make_float3(uv.x, uv.y, 0.0f); + if (sd->object != OBJECT_NONE) { + P = normalize(transform_point(&tfm, P)); } + else { + P = normalize(transform_direction(&tfm, P)); + } + + float2 uv = direction_to_panorama(&kernel_data.cam, P); + + return make_float3(uv.x, uv.y, 0.0f); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/camera/projection.h b/intern/cycles/kernel/camera/projection.h index cc5ee98c586..d05ecf2a0d7 100644 --- a/intern/cycles/kernel/camera/projection.h +++ b/intern/cycles/kernel/camera/projection.h @@ -18,8 +18,9 @@ CCL_NAMESPACE_BEGIN ccl_device float2 direction_to_equirectangular_range(float3 dir, float4 range) { - if (is_zero(dir)) + if (is_zero(dir)) { return zero_float2(); + } float u = (atan2f(dir.y, dir.x) - range.y) / range.x; float v = (acosf(dir.z / len(dir)) - range.w) / range.z; @@ -86,8 +87,9 @@ ccl_device float3 fisheye_equidistant_to_direction(float u, float v, float fov) float r = sqrtf(u * u + v * v); - if (r > 1.0f) + if (r > 1.0f) { return zero_float3(); + } float theta = r * fov * 0.5f; @@ -112,8 +114,9 @@ fisheye_equisolid_to_direction(float u, float v, float lens, float fov, float wi float rmax = 2.0f * lens * sinf(fov * 0.25f); float r = sqrtf(u * u + v * v); - if (r > rmax) + if (r > rmax) { return zero_float3(); + } float theta = 2.0f * asinf(r / (2.0f * lens)); @@ -131,8 +134,9 @@ ccl_device_inline float3 fisheye_lens_polynomial_to_direction( float4 rr = make_float4(r, r2, r2 * r, r2 * r2); float theta = -(coeff0 + dot(coeffs, rr)); - if (fabsf(theta) > 0.5f * fov) + if (fabsf(theta) > 0.5f * fov) { return zero_float3(); + } return fisheye_to_direction(theta, u, v, r); } @@ -186,8 +190,9 @@ ccl_device float3 mirrorball_to_direction(float u, float v) dir.x = 2.0f * u - 1.0f; dir.z = 2.0f * v - 1.0f; - if (dir.x * dir.x + dir.z * dir.z > 1.0f) + if (dir.x * dir.x + dir.z * dir.z > 1.0f) { return zero_float3(); + } dir.y = -sqrtf(max(1.0f - dir.x * dir.x - dir.z * dir.z, 0.0f)); @@ -203,8 +208,9 @@ ccl_device float2 direction_to_mirrorball(float3 dir) dir.y -= 1.0f; float div = 2.0f * sqrtf(max(-0.5f * dir.y, 0.0f)); - if (div > 0.0f) + if (div > 0.0f) { dir /= div; + } float u = 0.5f * (dir.x + 1.0f); float v = 0.5f * (dir.z + 1.0f); diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h index 87fcd2490e8..5357bf7f0e3 100644 --- a/intern/cycles/kernel/closure/bsdf.h +++ b/intern/cycles/kernel/closure/bsdf.h @@ -19,8 +19,6 @@ #include "kernel/closure/bsdf_hair.h" #include "kernel/closure/bsdf_principled_hair_chiang.h" #include "kernel/closure/bsdf_principled_hair_huang.h" -#include "kernel/closure/bssrdf.h" -#include "kernel/closure/volume.h" // clang-format on CCL_NAMESPACE_BEGIN @@ -429,10 +427,12 @@ ccl_device_inline int bsdf_label(const KernelGlobals kg, break; # ifdef __PRINCIPLED_HAIR__ case CLOSURE_BSDF_HAIR_CHIANG_ID: - if (bsdf_is_transmission(sc, wo)) + if (bsdf_is_transmission(sc, wo)) { label = LABEL_TRANSMIT | LABEL_GLOSSY; - else + } + else { label = LABEL_REFLECT | LABEL_GLOSSY; + } break; case CLOSURE_BSDF_HAIR_HUANG_ID: label = LABEL_REFLECT | LABEL_GLOSSY; diff --git a/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h b/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h index f8096702a70..2c4c0e8981d 100644 --- a/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h +++ b/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h @@ -152,10 +152,12 @@ ccl_device int bsdf_ashikhmin_shirley_sample(ccl_private const ShaderClosure *sc /* get x,y basis on the surface for anisotropy */ float3 X, Y; - if (n_x == n_y) + if (n_x == n_y) { make_orthonormals(N, &X, &Y); - else + } + else { make_orthonormals_tangent(N, bsdf->T, &X, &Y); + } /* sample spherical coords for h in tangent space */ float phi; @@ -194,8 +196,9 @@ ccl_device int bsdf_ashikhmin_shirley_sample(ccl_private const ShaderClosure *sc /* half vector to world space */ float3 H = to_global(h, X, Y, N); float HdotI = dot(H, wi); - if (HdotI < 0.0f) + if (HdotI < 0.0f) { H = -H; + } /* reflect wi on H to get wo */ *wo = -wi + (2.0f * HdotI) * H; diff --git a/intern/cycles/kernel/closure/bsdf_ashikhmin_velvet.h b/intern/cycles/kernel/closure/bsdf_ashikhmin_velvet.h index 71250a0c840..173e873601b 100644 --- a/intern/cycles/kernel/closure/bsdf_ashikhmin_velvet.h +++ b/intern/cycles/kernel/closure/bsdf_ashikhmin_velvet.h @@ -13,12 +13,12 @@ CCL_NAMESPACE_BEGIN -typedef struct VelvetBsdf { +struct VelvetBsdf { SHADER_CLOSURE_BASE; float sigma; float invsigma2; -} VelvetBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(VelvetBsdf), "VelvetBsdf is too large!"); diff --git a/intern/cycles/kernel/closure/bsdf_diffuse.h b/intern/cycles/kernel/closure/bsdf_diffuse.h index dc57f7917d2..77d3ea55dd4 100644 --- a/intern/cycles/kernel/closure/bsdf_diffuse.h +++ b/intern/cycles/kernel/closure/bsdf_diffuse.h @@ -13,9 +13,9 @@ CCL_NAMESPACE_BEGIN -typedef struct DiffuseBsdf { +struct DiffuseBsdf { SHADER_CLOSURE_BASE; -} DiffuseBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(DiffuseBsdf), "DiffuseBsdf is too large!"); diff --git a/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h b/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h index 9ac338c5605..4c0e1298c6d 100644 --- a/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h +++ b/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h @@ -16,11 +16,11 @@ CCL_NAMESPACE_BEGIN #ifdef __OSL__ -typedef struct DiffuseRampBsdf { +struct DiffuseRampBsdf { SHADER_CLOSURE_BASE; ccl_private float3 *colors; -} DiffuseRampBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(DiffuseRampBsdf), "DiffuseRampBsdf is too large!"); @@ -30,10 +30,12 @@ ccl_device float3 bsdf_diffuse_ramp_get_color(const float3 colors[8], float pos) float npos = pos * (float)(MAXCOLORS - 1); int ipos = float_to_int(npos); - if (ipos < 0) + if (ipos < 0) { return colors[0]; - if (ipos >= (MAXCOLORS - 1)) + } + if (ipos >= (MAXCOLORS - 1)) { return colors[MAXCOLORS - 1]; + } float offset = npos - (float)ipos; return colors[ipos] * (1.0f - offset) + colors[ipos + 1] * offset; } @@ -59,10 +61,8 @@ ccl_device Spectrum bsdf_diffuse_ramp_eval(ccl_private const ShaderClosure *sc, *pdf = cosNO * M_1_PI_F; return rgb_to_spectrum(bsdf_diffuse_ramp_get_color(bsdf->colors, cosNO) * M_1_PI_F); } - else { - *pdf = 0.0f; - return zero_spectrum(); - } + *pdf = 0.0f; + return zero_spectrum(); } ccl_device int bsdf_diffuse_ramp_sample(ccl_private const ShaderClosure *sc, diff --git a/intern/cycles/kernel/closure/bsdf_hair.h b/intern/cycles/kernel/closure/bsdf_hair.h index b07faf94206..3cb2c627d9b 100644 --- a/intern/cycles/kernel/closure/bsdf_hair.h +++ b/intern/cycles/kernel/closure/bsdf_hair.h @@ -13,14 +13,14 @@ CCL_NAMESPACE_BEGIN -typedef struct HairBsdf { +struct HairBsdf { SHADER_CLOSURE_BASE; float3 T; float roughness1; float roughness2; float offset; -} HairBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(HairBsdf), "HairBsdf is too large!"); @@ -187,8 +187,9 @@ ccl_device int bsdf_hair_reflection_sample(ccl_private const ShaderClosure *sc, *wo = (cosphi * costheta_i) * locy - (sinphi * costheta_i) * locx + (sintheta_i)*Tg; *pdf = fabsf(phi_pdf * theta_pdf); - if (M_PI_2_F - fabsf(theta_i) < 0.001f) + if (M_PI_2_F - fabsf(theta_i) < 0.001f) { *pdf = 0.0f; + } *eval = make_spectrum(*pdf); diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h index f44d7f7b80a..9c2da36dbc5 100644 --- a/intern/cycles/kernel/closure/bsdf_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_microfacet.h @@ -29,23 +29,23 @@ enum MicrofacetFresnel { F82_TINT, }; -typedef struct FresnelThinFilm { +struct FresnelThinFilm { float thickness; float ior; -} FresnelThinFilm; +}; -typedef struct FresnelDielectricTint { +struct FresnelDielectricTint { FresnelThinFilm thin_film; Spectrum reflection_tint; Spectrum transmission_tint; -} FresnelDielectricTint; +}; -typedef struct FresnelConductor { +struct FresnelConductor { Spectrum n, k; -} FresnelConductor; +}; -typedef struct FresnelGeneralizedSchlick { +struct FresnelGeneralizedSchlick { FresnelThinFilm thin_film; Spectrum reflection_tint; @@ -54,16 +54,16 @@ typedef struct FresnelGeneralizedSchlick { Spectrum f0, f90; /* Negative exponent signals a special case where the real Fresnel is remapped to F0...F90. */ float exponent; -} FresnelGeneralizedSchlick; +}; -typedef struct FresnelF82Tint { +struct FresnelF82Tint { /* Perpendicular reflectivity. */ Spectrum f0; /* Precomputed (1-cos)^6 factor for edge tint. */ Spectrum b; -} FresnelF82Tint; +}; -typedef struct MicrofacetBsdf { +struct MicrofacetBsdf { SHADER_CLOSURE_BASE; float alpha_x, alpha_y, ior; @@ -80,7 +80,7 @@ typedef struct MicrofacetBsdf { ccl_private void *fresnel; float3 T; -} MicrofacetBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(MicrofacetBsdf), "MicrofacetBsdf is too large!"); @@ -464,17 +464,15 @@ ccl_device_inline float bsdf_lambda_from_sqr_alpha_tan_n(float sqr_alpha_tan_n) /* Equation 72. */ return 0.5f * (sqrtf(1.0f + sqr_alpha_tan_n) - 1.0f); } - else { - kernel_assert(m_type == MicrofacetType::BECKMANN); - /* Approximation from below Equation 69. */ - if (sqr_alpha_tan_n < 0.39f) { - /* Equivalent to a >= 1.6f, but also handles sqr_alpha_tan_n == 0.0f cleanly. */ - return 0.0f; - } - - const float a = inversesqrtf(sqr_alpha_tan_n); - return ((0.396f * a - 1.259f) * a + 1.0f) / ((2.181f * a + 3.535f) * a); + kernel_assert(m_type == MicrofacetType::BECKMANN); + /* Approximation from below Equation 69. */ + if (sqr_alpha_tan_n < 0.39f) { + /* Equivalent to a >= 1.6f, but also handles sqr_alpha_tan_n == 0.0f cleanly. */ + return 0.0f; } + + const float a = inversesqrtf(sqr_alpha_tan_n); + return ((0.396f * a - 1.259f) * a + 1.0f) / ((2.181f * a + 3.535f) * a); } template ccl_device_inline float bsdf_lambda(float alpha2, float cos_N) @@ -511,10 +509,8 @@ template ccl_device_inline float bsdf_D(float alpha2, flo if (m_type == MicrofacetType::BECKMANN) { return 1.0f / (expf(one_minus_cos_NH2 / (cos_NH2 * alpha2)) * M_PI_F * alpha2 * sqr(cos_NH2)); } - else { - kernel_assert(m_type == MicrofacetType::GGX); - return alpha2 / (M_PI_F * sqr(one_minus_cos_NH2 + alpha2 * cos_NH2)); - } + kernel_assert(m_type == MicrofacetType::GGX); + return alpha2 / (M_PI_F * sqr(one_minus_cos_NH2 + alpha2 * cos_NH2)); } template @@ -528,10 +524,8 @@ ccl_device_inline float bsdf_aniso_D(float alpha_x, float alpha_y, float3 H) if (m_type == MicrofacetType::BECKMANN) { return expf(-(sqr(H.x) + sqr(H.y)) / cos_NH2) / (M_PI_F * alpha2 * sqr(cos_NH2)); } - else { - kernel_assert(m_type == MicrofacetType::GGX); - return M_1_PI_F / (alpha2 * sqr(len_squared(H))); - } + kernel_assert(m_type == MicrofacetType::GGX); + return M_1_PI_F / (alpha2 * sqr(len_squared(H))); } /* Do not set `SD_BSDF_HAS_EVAL` flag if the squared roughness is below a certain threshold. */ diff --git a/intern/cycles/kernel/closure/bsdf_oren_nayar.h b/intern/cycles/kernel/closure/bsdf_oren_nayar.h index 7a438f77dfe..50cc8f79145 100644 --- a/intern/cycles/kernel/closure/bsdf_oren_nayar.h +++ b/intern/cycles/kernel/closure/bsdf_oren_nayar.h @@ -10,14 +10,14 @@ CCL_NAMESPACE_BEGIN -typedef struct OrenNayarBsdf { +struct OrenNayarBsdf { SHADER_CLOSURE_BASE; float roughness; float a; float b; Spectrum multiscatter_term; -} OrenNayarBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(OrenNayarBsdf), "OrenNayarBsdf is too large!"); @@ -48,8 +48,9 @@ ccl_device Spectrum bsdf_oren_nayar_get_intensity(ccl_private const ShaderClosur float nv = max(dot(n, v), 0.0f); float t = dot(l, v) - nl * nv; - if (t > 0.0f) + if (t > 0.0f) { t /= max(nl, nv) + FLT_MIN; + } const float single_scatter = bsdf->a + bsdf->b * t; @@ -92,10 +93,8 @@ ccl_device Spectrum bsdf_oren_nayar_eval(ccl_private const ShaderClosure *sc, *pdf = cosNO * M_1_PI_F; return bsdf_oren_nayar_get_intensity(sc, bsdf->N, wi, wo); } - else { - *pdf = 0.0f; - return zero_spectrum(); - } + *pdf = 0.0f; + return zero_spectrum(); } ccl_device int bsdf_oren_nayar_sample(ccl_private const ShaderClosure *sc, diff --git a/intern/cycles/kernel/closure/bsdf_phong_ramp.h b/intern/cycles/kernel/closure/bsdf_phong_ramp.h index e455437f6d8..cb532b2378c 100644 --- a/intern/cycles/kernel/closure/bsdf_phong_ramp.h +++ b/intern/cycles/kernel/closure/bsdf_phong_ramp.h @@ -15,12 +15,12 @@ CCL_NAMESPACE_BEGIN #ifdef __OSL__ -typedef struct PhongRampBsdf { +struct PhongRampBsdf { SHADER_CLOSURE_BASE; float exponent; ccl_private float3 *colors; -} PhongRampBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(PhongRampBsdf), "PhongRampBsdf is too large!"); @@ -30,10 +30,12 @@ ccl_device float3 bsdf_phong_ramp_get_color(const float3 colors[8], float pos) float npos = pos * (float)(MAXCOLORS - 1); int ipos = float_to_int(npos); - if (ipos < 0) + if (ipos < 0) { return colors[0]; - if (ipos >= (MAXCOLORS - 1)) + } + if (ipos >= (MAXCOLORS - 1)) { return colors[MAXCOLORS - 1]; + } float offset = npos - (float)ipos; return colors[ipos] * (1.0f - offset) + colors[ipos + 1] * offset; } diff --git a/intern/cycles/kernel/closure/bsdf_principled_hair_chiang.h b/intern/cycles/kernel/closure/bsdf_principled_hair_chiang.h index b0f2e64890d..5f2d2e8c1cc 100644 --- a/intern/cycles/kernel/closure/bsdf_principled_hair_chiang.h +++ b/intern/cycles/kernel/closure/bsdf_principled_hair_chiang.h @@ -19,7 +19,7 @@ CCL_NAMESPACE_BEGIN -typedef struct ChiangHairBSDF { +struct ChiangHairBSDF { SHADER_CLOSURE_BASE; /* Absorption coefficient. */ @@ -37,7 +37,7 @@ typedef struct ChiangHairBSDF { /* Azimuthal offset. */ float h; -} ChiangHairBSDF; +}; static_assert(sizeof(ShaderClosure) >= sizeof(ChiangHairBSDF), "ChiangHairBSDF is too large!"); @@ -69,9 +69,7 @@ ccl_device_inline float logistic_cdf(float x, float s) if (arg > 88.0f) { return 0.0f; } - else { - return 1.0f / (1.0f + expf(arg)); - } + return 1.0f / (1.0f + expf(arg)); } /* Numerical approximation to the Bessel function of the first kind. */ @@ -103,9 +101,7 @@ ccl_device_inline float log_bessel_I0(float x) * This is only used with positive cosines. */ return x + 0.5f * (1.f / (8.0f * x) - M_LN_2PI_F - logf(x)); } - else { - return logf(bessel_I0(x)); - } + return logf(bessel_I0(x)); } /* Logistic distribution limited to the interval [-pi, pi]. */ @@ -149,12 +145,10 @@ ccl_device_inline float longitudinal_scattering( kernel_assert(isfinite_safe(val)); return val; } - else { - float i0 = bessel_I0(cos_arg); - float val = (expf(-sin_arg) * i0) / (sinhf(inv_v) * 2.0f * v); - kernel_assert(isfinite_safe(val)); - return val; - } + float i0 = bessel_I0(cos_arg); + float val = (expf(-sin_arg) * i0) / (sinhf(inv_v) * 2.0f * v); + kernel_assert(isfinite_safe(val)); + return val; } #ifdef __HAIR__ diff --git a/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h b/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h index 9f712200d00..0681d8c6751 100644 --- a/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h +++ b/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h @@ -18,7 +18,7 @@ CCL_NAMESPACE_BEGIN -typedef struct HuangHairExtra { +struct HuangHairExtra { /* Optional modulation factors. */ float R, TT, TRT; @@ -39,9 +39,9 @@ typedef struct HuangHairExtra { /* Valid integration interval. */ float gamma_m_min, gamma_m_max; -} HuangHairExtra; +}; -typedef struct HuangHairBSDF { +struct HuangHairBSDF { SHADER_CLOSURE_BASE; /* Absorption coefficient. */ @@ -64,7 +64,7 @@ typedef struct HuangHairBSDF { /* Extra closure for optional modulation factors and local coordinate system. */ ccl_private HuangHairExtra *extra; -} HuangHairBSDF; +}; static_assert(sizeof(ShaderClosure) >= sizeof(HuangHairBSDF), "HuangHairBSDF is too large!"); static_assert(sizeof(ShaderClosure) >= sizeof(HuangHairExtra), "HuangHairExtra is too large!"); diff --git a/intern/cycles/kernel/closure/bsdf_ray_portal.h b/intern/cycles/kernel/closure/bsdf_ray_portal.h index 61875bca211..ae80470b0e4 100644 --- a/intern/cycles/kernel/closure/bsdf_ray_portal.h +++ b/intern/cycles/kernel/closure/bsdf_ray_portal.h @@ -10,12 +10,12 @@ CCL_NAMESPACE_BEGIN -typedef struct RayPortalClosure { +struct RayPortalClosure { SHADER_CLOSURE_BASE; float3 P; float3 D; -} RayPortalClosure; +}; static_assert(sizeof(ShaderClosure) >= sizeof(RayPortalClosure), "RayPortalClosure is too large!"); diff --git a/intern/cycles/kernel/closure/bsdf_sheen.h b/intern/cycles/kernel/closure/bsdf_sheen.h index 80424b6c34f..ce02f62e5b2 100644 --- a/intern/cycles/kernel/closure/bsdf_sheen.h +++ b/intern/cycles/kernel/closure/bsdf_sheen.h @@ -15,12 +15,12 @@ CCL_NAMESPACE_BEGIN -typedef struct SheenBsdf { +struct SheenBsdf { SHADER_CLOSURE_BASE; float roughness; float transformA, transformB; float3 T, B; -} SheenBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(SheenBsdf), "SheenBsdf is too large!"); diff --git a/intern/cycles/kernel/closure/bsdf_toon.h b/intern/cycles/kernel/closure/bsdf_toon.h index 0a7040e4d57..8824a5e3573 100644 --- a/intern/cycles/kernel/closure/bsdf_toon.h +++ b/intern/cycles/kernel/closure/bsdf_toon.h @@ -13,12 +13,12 @@ CCL_NAMESPACE_BEGIN -typedef struct ToonBsdf { +struct ToonBsdf { SHADER_CLOSURE_BASE; float size; float smooth; -} ToonBsdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(ToonBsdf), "ToonBsdf is too large!"); diff --git a/intern/cycles/kernel/closure/bssrdf.h b/intern/cycles/kernel/closure/bssrdf.h index 1a13ed3d74b..988ed691c81 100644 --- a/intern/cycles/kernel/closure/bssrdf.h +++ b/intern/cycles/kernel/closure/bssrdf.h @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN -typedef struct Bssrdf { +struct Bssrdf { SHADER_CLOSURE_BASE; Spectrum radius; @@ -21,7 +21,7 @@ typedef struct Bssrdf { /* Parameters for refractive entry bounce. */ float ior; float alpha; -} Bssrdf; +}; static_assert(sizeof(ShaderClosure) >= sizeof(Bssrdf), "Bssrdf is too large!"); @@ -129,8 +129,9 @@ ccl_device float bssrdf_burley_eval(const float d, float r) { const float Rm = BURLEY_TRUNCATE * d; - if (r >= Rm) + if (r >= Rm) { return 0.0f; + } /* Burley reflectance profile, equation (3). * @@ -187,9 +188,7 @@ ccl_device_forceinline float bssrdf_burley_root_find(float xi) } r = r - f / f_; - if (r < 0.0f) { - r = 0.0f; - } + r = fmaxf(r, 0.0f); } return r; } diff --git a/intern/cycles/kernel/closure/volume.h b/intern/cycles/kernel/closure/volume.h index 608991db9b6..f55003c5c37 100644 --- a/intern/cycles/kernel/closure/volume.h +++ b/intern/cycles/kernel/closure/volume.h @@ -6,8 +6,6 @@ #include "kernel/types.h" -#include "kernel/closure/volume_util.h" - #include "kernel/closure/volume_draine.h" #include "kernel/closure/volume_fournier_forand.h" #include "kernel/closure/volume_henyey_greenstein.h" diff --git a/intern/cycles/kernel/closure/volume_draine.h b/intern/cycles/kernel/closure/volume_draine.h index 94bbdd0ab80..5f05b44efa0 100644 --- a/intern/cycles/kernel/closure/volume_draine.h +++ b/intern/cycles/kernel/closure/volume_draine.h @@ -12,12 +12,12 @@ CCL_NAMESPACE_BEGIN /* DRAINE CLOSURE */ -typedef struct DraineVolume { +struct DraineVolume { SHADER_CLOSURE_VOLUME_BASE; float g; float alpha; -} DraineVolume; +}; static_assert(sizeof(ShaderVolumeClosure) >= sizeof(DraineVolume), "DraineVolume is too large!"); ccl_device int volume_draine_setup(ccl_private DraineVolume *volume) diff --git a/intern/cycles/kernel/closure/volume_fournier_forand.h b/intern/cycles/kernel/closure/volume_fournier_forand.h index 18cee86dcd4..ed353c9131a 100644 --- a/intern/cycles/kernel/closure/volume_fournier_forand.h +++ b/intern/cycles/kernel/closure/volume_fournier_forand.h @@ -12,12 +12,12 @@ CCL_NAMESPACE_BEGIN /* FOURNIER-FORAND CLOSURE */ -typedef struct FournierForandVolume { +struct FournierForandVolume { SHADER_CLOSURE_VOLUME_BASE; /* Precomputed coefficients, based on B and IOR */ float c1, c2, c3; -} FournierForandVolume; +}; static_assert(sizeof(ShaderVolumeClosure) >= sizeof(FournierForandVolume), "FournierForandVolume is too large!"); diff --git a/intern/cycles/kernel/closure/volume_henyey_greenstein.h b/intern/cycles/kernel/closure/volume_henyey_greenstein.h index 8391d4734f9..fe45467bd1d 100644 --- a/intern/cycles/kernel/closure/volume_henyey_greenstein.h +++ b/intern/cycles/kernel/closure/volume_henyey_greenstein.h @@ -12,11 +12,11 @@ CCL_NAMESPACE_BEGIN /* HENYEY-GREENSTEIN CLOSURE */ -typedef struct HenyeyGreensteinVolume { +struct HenyeyGreensteinVolume { SHADER_CLOSURE_VOLUME_BASE; float g; -} HenyeyGreensteinVolume; +}; static_assert(sizeof(ShaderVolumeClosure) >= sizeof(HenyeyGreensteinVolume), "HenyeyGreensteinVolume is too large!"); diff --git a/intern/cycles/kernel/closure/volume_rayleigh.h b/intern/cycles/kernel/closure/volume_rayleigh.h index 7288e82c2bd..70af27ed4e1 100644 --- a/intern/cycles/kernel/closure/volume_rayleigh.h +++ b/intern/cycles/kernel/closure/volume_rayleigh.h @@ -12,9 +12,9 @@ CCL_NAMESPACE_BEGIN /* RAYLEIGH CLOSURE */ -typedef struct RayleighVolume { +struct RayleighVolume { SHADER_CLOSURE_VOLUME_BASE; -} RayleighVolume; +}; static_assert(sizeof(ShaderVolumeClosure) >= sizeof(RayleighVolume), "RayleighVolume is too large!"); diff --git a/intern/cycles/kernel/closure/volume_util.h b/intern/cycles/kernel/closure/volume_util.h index 9b62a771409..e5d4896a043 100644 --- a/intern/cycles/kernel/closure/volume_util.h +++ b/intern/cycles/kernel/closure/volume_util.h @@ -81,7 +81,7 @@ ccl_device float phase_draine(float cos_theta, float g, float alpha) if (fabsf(g) < 1e-3f && alpha > 0.999f) { return phase_rayleigh(cos_theta); } - else if (fabsf(alpha) < 1e-3f) { + if (fabsf(alpha) < 1e-3f) { return phase_henyey_greenstein(cos_theta, g); } @@ -127,7 +127,7 @@ phase_draine_sample(float3 D, float g, float alpha, float2 rand, ccl_private flo if (fabsf(g) < 1e-3f && alpha > 0.999f) { return phase_rayleigh_sample(D, rand, pdf); } - else if (fabsf(alpha) < 1e-3f) { + if (fabsf(alpha) < 1e-3f) { return phase_henyey_greenstein_sample(D, g, rand, pdf); } diff --git a/intern/cycles/kernel/device/cpu/bvh.h b/intern/cycles/kernel/device/cpu/bvh.h index 640382ede88..04422d56d16 100644 --- a/intern/cycles/kernel/device/cpu/bvh.h +++ b/intern/cycles/kernel/device/cpu/bvh.h @@ -123,13 +123,13 @@ struct CCLIntersectContext : public RTCIntersectContext, public CCLShadowContext, public CCLLocalContext, public CCLVolumeContext { - typedef enum { + enum RayType { RAY_REGULAR = 0, RAY_SHADOW_ALL = 1, RAY_LOCAL = 2, RAY_SSS = 3, RAY_VOLUME_ALL = 4, - } RayType; + }; RayType type; diff --git a/intern/cycles/kernel/device/cpu/globals.h b/intern/cycles/kernel/device/cpu/globals.h index ac8e44b6e6d..ef00f482273 100644 --- a/intern/cycles/kernel/device/cpu/globals.h +++ b/intern/cycles/kernel/device/cpu/globals.h @@ -37,7 +37,7 @@ template struct kernel_array { int width = 0; }; -typedef struct KernelGlobalsCPU { +struct KernelGlobalsCPU { #define KERNEL_DATA_ARRAY(type, name) kernel_array name; #include "kernel/data_arrays.h" @@ -66,9 +66,9 @@ typedef struct KernelGlobalsCPU { /* **** Run-time data **** */ ProfilingState profiler; -} KernelGlobalsCPU; +}; -typedef const KernelGlobalsCPU *ccl_restrict KernelGlobals; +using KernelGlobals = const KernelGlobalsCPU *; /* Abstraction macros */ #define kernel_data_fetch(name, index) (kg->name.fetch(index)) diff --git a/intern/cycles/kernel/device/cpu/image.h b/intern/cycles/kernel/device/cpu/image.h index 0a41fa277f7..8edb5a9fdd3 100644 --- a/intern/cycles/kernel/device/cpu/image.h +++ b/intern/cycles/kernel/device/cpu/image.h @@ -39,7 +39,7 @@ template struct TextureInterpolator { static ccl_always_inline OutT zero() { - if constexpr (std::is_same::value) { + if constexpr (std::is_same_v) { return zero_float4(); } else { @@ -209,8 +209,9 @@ template struct TextureInterpolator { static ccl_always_inline int wrap_mirror(int x, int width) { const int m = abs(x + (x < 0)) % (2 * width); - if (m >= width) + if (m >= width) { return 2 * width - m - 1; + } return m; } @@ -248,7 +249,7 @@ template struct TextureInterpolator { } const TexT *data = (const TexT *)info.data; - return read((const TexT *)data, ix, iy, width, height); + return read(data, ix, iy, width, height); } static ccl_always_inline OutT interp_linear(const TextureInfo &info, float x, float y) diff --git a/intern/cycles/kernel/device/cpu/kernel.cpp b/intern/cycles/kernel/device/cpu/kernel.cpp index 22d4507327c..cddf90ac2ad 100644 --- a/intern/cycles/kernel/device/cpu/kernel.cpp +++ b/intern/cycles/kernel/device/cpu/kernel.cpp @@ -51,7 +51,7 @@ CCL_NAMESPACE_BEGIN /* Memory Copy */ -void kernel_const_copy(KernelGlobalsCPU *kg, const char *name, void *host, size_t) +void kernel_const_copy(KernelGlobalsCPU *kg, const char *name, void *host, size_t /*unused*/) { if (strcmp(name, "data") == 0) { kg->data = *(KernelData *)host; @@ -63,7 +63,7 @@ void kernel_const_copy(KernelGlobalsCPU *kg, const char *name, void *host, size_ void kernel_global_memory_copy(KernelGlobalsCPU *kg, const char *name, void *mem, size_t size) { - if (0) { + if (false) { } #define KERNEL_DATA_ARRAY(type, tname) \ diff --git a/intern/cycles/kernel/device/cuda/globals.h b/intern/cycles/kernel/device/cuda/globals.h index eb138604187..fb80083e06a 100644 --- a/intern/cycles/kernel/device/cuda/globals.h +++ b/intern/cycles/kernel/device/cuda/globals.h @@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN struct KernelGlobalsGPU { int unused[1]; }; -typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global const KernelGlobalsGPU *ccl_restrict; struct KernelParamsCUDA { /* Global scene data and textures */ diff --git a/intern/cycles/kernel/device/hip/globals.h b/intern/cycles/kernel/device/hip/globals.h index 957250b632b..490c5df2c9a 100644 --- a/intern/cycles/kernel/device/hip/globals.h +++ b/intern/cycles/kernel/device/hip/globals.h @@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN struct KernelGlobalsGPU { int unused[1]; }; -typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global const KernelGlobalsGPU *ccl_restrict; struct KernelParamsHIP { /* Global scene data and textures */ diff --git a/intern/cycles/kernel/device/hiprt/globals.h b/intern/cycles/kernel/device/hiprt/globals.h index cc995453e63..bb4a644e10f 100644 --- a/intern/cycles/kernel/device/hiprt/globals.h +++ b/intern/cycles/kernel/device/hiprt/globals.h @@ -9,10 +9,10 @@ #include "kernel/types.h" #include "kernel/integrator/state.h" -#include "kernel/util/profiler.h" +#include "kernel/util/profiler.h" // IWYU pragma: export -#include "util/color.h" -#include "util/texture.h" +#include "util/color.h" // IWYU pragma: export +#include "util/texture.h" // IWYU pragma: export #define HIPRT_SHARED_STACK @@ -41,7 +41,7 @@ struct KernelGlobalsGPU { #endif }; -typedef ccl_global KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global KernelGlobalsGPU *ccl_restrict; #if defined(HIPRT_SHARED_STACK) diff --git a/intern/cycles/kernel/device/metal/context_begin.h b/intern/cycles/kernel/device/metal/context_begin.h index d2f68ae901c..2e3c0a78592 100644 --- a/intern/cycles/kernel/device/metal/context_begin.h +++ b/intern/cycles/kernel/device/metal/context_begin.h @@ -24,8 +24,8 @@ class MetalKernelContext { {} /* texture fetch adapter functions */ - typedef uint64_t ccl_gpu_tex_object_2D; - typedef uint64_t ccl_gpu_tex_object_3D; + using ccl_gpu_tex_object_2D = uint64_t; + using ccl_gpu_tex_object_3D = uint64_t; template inline __attribute__((__always_inline__)) diff --git a/intern/cycles/kernel/device/metal/globals.h b/intern/cycles/kernel/device/metal/globals.h index 43c1166185f..03f5c319c91 100644 --- a/intern/cycles/kernel/device/metal/globals.h +++ b/intern/cycles/kernel/device/metal/globals.h @@ -14,7 +14,7 @@ CCL_NAMESPACE_BEGIN -typedef struct KernelParamsMetal { +struct KernelParamsMetal { #define KERNEL_DATA_ARRAY(type, name) ccl_global const type *name; #include "kernel/data_arrays.h" @@ -22,14 +22,13 @@ typedef struct KernelParamsMetal { const IntegratorStateGPU integrator_state; const KernelData data; +}; -} KernelParamsMetal; - -typedef struct KernelGlobalsGPU { +struct KernelGlobalsGPU { int unused[1]; -} KernelGlobalsGPU; +}; -typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global const KernelGlobalsGPU *ccl_restrict; /* Abstraction macros */ #define kernel_data launch_params_metal.data diff --git a/intern/cycles/kernel/device/oneapi/context_begin.h b/intern/cycles/kernel/device/oneapi/context_begin.h index a332b90a18d..86532635f2c 100644 --- a/intern/cycles/kernel/device/oneapi/context_begin.h +++ b/intern/cycles/kernel/device/oneapi/context_begin.h @@ -10,7 +10,7 @@ * (which rules out trick like using `uint64_t` as a drop-in replacement for double). * - Padding rules are matching exactly `double` * (which rules out array of `uint8_t`). */ -typedef struct ccl_vdb_double_t { +struct ccl_vdb_double_t { union ccl_vdb_helper_t { double d; uint64_t i; @@ -31,7 +31,7 @@ typedef struct ccl_vdb_double_t { helper.i = i; return (float)helper.d; } -} ccl_vdb_double_t; +}; # define double ccl_vdb_double_t # include "kernel/util/nanovdb.h" diff --git a/intern/cycles/kernel/device/oneapi/globals.h b/intern/cycles/kernel/device/oneapi/globals.h index 026185ce154..e15cddf09bb 100644 --- a/intern/cycles/kernel/device/oneapi/globals.h +++ b/intern/cycles/kernel/device/oneapi/globals.h @@ -23,7 +23,7 @@ CCL_NAMESPACE_BEGIN struct IntegratorStateGPU; struct IntegratorQueueCounter; -typedef struct KernelGlobalsGPU { +struct KernelGlobalsGPU { #define KERNEL_DATA_ARRAY(type, name) const type *__##name = nullptr; #include "kernel/data_arrays.h" @@ -41,9 +41,9 @@ typedef struct KernelGlobalsGPU { #else sycl::kernel_handler kernel_handler; #endif -} KernelGlobalsGPU; +}; -typedef ccl_global KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global KernelGlobalsGPU *ccl_restrict; #define kernel_data (*(__data)) #define kernel_integrator_state (*(integrator_state)) diff --git a/intern/cycles/kernel/device/oneapi/image.h b/intern/cycles/kernel/device/oneapi/image.h index a50b4cad414..4098db1f95c 100644 --- a/intern/cycles/kernel/device/oneapi/image.h +++ b/intern/cycles/kernel/device/oneapi/image.h @@ -45,42 +45,40 @@ ccl_device_inline float4 svm_image_texture_read(const TextureInfo &info, int x, return tex_fetch(info, data_offset); } /* Byte4 */ - else if (texture_type == IMAGE_DATA_TYPE_BYTE4) { + if (texture_type == IMAGE_DATA_TYPE_BYTE4) { uchar4 r = tex_fetch(info, data_offset); float f = 1.0f / 255.0f; return make_float4(r.x * f, r.y * f, r.z * f, r.w * f); } /* Ushort4 */ - else if (texture_type == IMAGE_DATA_TYPE_USHORT4) { + if (texture_type == IMAGE_DATA_TYPE_USHORT4) { ushort4 r = tex_fetch(info, data_offset); float f = 1.0f / 65535.f; return make_float4(r.x * f, r.y * f, r.z * f, r.w * f); } /* Float */ - else if (texture_type == IMAGE_DATA_TYPE_FLOAT) { + if (texture_type == IMAGE_DATA_TYPE_FLOAT) { float f = tex_fetch(info, data_offset); return make_float4(f, f, f, 1.0f); } /* UShort */ - else if (texture_type == IMAGE_DATA_TYPE_USHORT) { + if (texture_type == IMAGE_DATA_TYPE_USHORT) { ushort r = tex_fetch(info, data_offset); float f = r * (1.0f / 65535.0f); return make_float4(f, f, f, 1.0f); } - else if (texture_type == IMAGE_DATA_TYPE_HALF) { + if (texture_type == IMAGE_DATA_TYPE_HALF) { float f = tex_fetch(info, data_offset); return make_float4(f, f, f, 1.0f); } - else if (texture_type == IMAGE_DATA_TYPE_HALF4) { + if (texture_type == IMAGE_DATA_TYPE_HALF4) { half4 r = tex_fetch(info, data_offset); return make_float4(r.x, r.y, r.z, r.w); } /* Byte */ - else { - uchar r = tex_fetch(info, data_offset); - float f = r * (1.0f / 255.0f); - return make_float4(f, f, f, 1.0f); - } + uchar r = tex_fetch(info, data_offset); + float f = r * (1.0f / 255.0f); + return make_float4(f, f, f, 1.0f); } ccl_device_inline float4 svm_image_texture_read_2d(int id, int x, int y) @@ -154,7 +152,7 @@ static float svm_image_texture_frac(float x, int *ix) } \ (void)0 -ccl_device float4 kernel_tex_image_interp(KernelGlobals, int id, float x, float y) +ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, int id, float x, float y) { const TextureInfo &info = kernel_data_fetch(texture_info, id); @@ -166,7 +164,7 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals, int id, float x, float return svm_image_texture_read_2d(id, ix, iy); } - else if (info.interpolation == INTERPOLATION_LINEAR) { + if (info.interpolation == INTERPOLATION_LINEAR) { /* Bilinear interpolation. */ int ix, iy; float tx = svm_image_texture_frac(x * info.width - 0.5f, &ix); @@ -179,26 +177,24 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals, int id, float x, float r += ty * tx * svm_image_texture_read_2d(id, ix + 1, iy + 1); return r; } - else { - /* Bicubic interpolation. */ - int ix, iy; - float tx = svm_image_texture_frac(x * info.width - 0.5f, &ix); - float ty = svm_image_texture_frac(y * info.height - 0.5f, &iy); + /* Bicubic interpolation. */ + int ix, iy; + float tx = svm_image_texture_frac(x * info.width - 0.5f, &ix); + float ty = svm_image_texture_frac(y * info.height - 0.5f, &iy); - float u[4], v[4]; - SET_CUBIC_SPLINE_WEIGHTS(u, tx); - SET_CUBIC_SPLINE_WEIGHTS(v, ty); + float u[4], v[4]; + SET_CUBIC_SPLINE_WEIGHTS(u, tx); + SET_CUBIC_SPLINE_WEIGHTS(v, ty); - float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 4; x++) { - float weight = u[x] * v[y]; - r += weight * svm_image_texture_read_2d(id, ix + x - 1, iy + y - 1); - } + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 4; x++) { + float weight = u[x] * v[y]; + r += weight * svm_image_texture_read_2d(id, ix + x - 1, iy + y - 1); } - return r; } + return r; } #ifdef WITH_NANOVDB @@ -322,7 +318,7 @@ template struct NanoVDBInterpolator { }; #endif /* WITH_NANOVDB */ -ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals, int id, float3 P, int interp) +ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals kg, int id, float3 P, int interp) { const TextureInfo &info = kernel_data_fetch(texture_info, id); @@ -342,15 +338,15 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals, int id, float3 P, in const float f = NanoVDBInterpolator::interp_3d(info, x, y, z, interpolation); return make_float4(f, f, f, 1.0f); } - else if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { + if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { return NanoVDBInterpolator::interp_3d(info, x, y, z, interpolation); } - else if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FPN) { + if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FPN) { const float f = NanoVDBInterpolator::interp_3d( info, x, y, z, interpolation); return make_float4(f, f, f, 1.0f); } - else if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FP16) { + if (info.data_type == IMAGE_DATA_TYPE_NANOVDB_FP16) { const float f = NanoVDBInterpolator::interp_3d( info, x, y, z, interpolation); return make_float4(f, f, f, 1.0f); @@ -380,7 +376,7 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals, int id, float3 P, in return svm_image_texture_read_3d(id, ix, iy, iz); } - else if (interpolation == INTERPOLATION_LINEAR) { + if (interpolation == INTERPOLATION_LINEAR) { /* Trilinear interpolation. */ int ix, iy, iz; float tx = svm_image_texture_frac(x - 0.5f, &ix); @@ -399,30 +395,28 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals, int id, float3 P, in r += tz * ty * tx * svm_image_texture_read_3d(id, ix + 1, iy + 1, iz + 1); return r; } - else { - /* Tri-cubic interpolation. */ - int ix, iy, iz; - float tx = svm_image_texture_frac(x - 0.5f, &ix); - float ty = svm_image_texture_frac(y - 0.5f, &iy); - float tz = svm_image_texture_frac(z - 0.5f, &iz); + /* Tri-cubic interpolation. */ + int ix, iy, iz; + float tx = svm_image_texture_frac(x - 0.5f, &ix); + float ty = svm_image_texture_frac(y - 0.5f, &iy); + float tz = svm_image_texture_frac(z - 0.5f, &iz); - float u[4], v[4], w[4]; - SET_CUBIC_SPLINE_WEIGHTS(u, tx); - SET_CUBIC_SPLINE_WEIGHTS(v, ty); - SET_CUBIC_SPLINE_WEIGHTS(w, tz); + float u[4], v[4], w[4]; + SET_CUBIC_SPLINE_WEIGHTS(u, tx); + SET_CUBIC_SPLINE_WEIGHTS(v, ty); + SET_CUBIC_SPLINE_WEIGHTS(w, tz); - float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - for (int z = 0; z < 4; z++) { - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 4; x++) { - float weight = u[x] * v[y] * w[z]; - r += weight * svm_image_texture_read_3d(id, ix + x - 1, iy + y - 1, iz + z - 1); - } + for (int z = 0; z < 4; z++) { + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 4; x++) { + float weight = u[x] * v[y] * w[z]; + r += weight * svm_image_texture_read_3d(id, ix + x - 1, iy + y - 1, iz + z - 1); } } - return r; } + return r; } #undef SET_CUBIC_SPLINE_WEIGHTS diff --git a/intern/cycles/kernel/device/optix/globals.h b/intern/cycles/kernel/device/optix/globals.h index 4a7a5f87a8a..1ad0a6cafb8 100644 --- a/intern/cycles/kernel/device/optix/globals.h +++ b/intern/cycles/kernel/device/optix/globals.h @@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN struct KernelGlobalsGPU { int unused[1]; }; -typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; +using KernelGlobals = ccl_global const KernelGlobalsGPU *ccl_restrict; /* Launch parameters */ struct KernelParamsOptiX { diff --git a/intern/cycles/kernel/film/cryptomatte_passes.h b/intern/cycles/kernel/film/cryptomatte_passes.h index d7528f5d168..a777563a566 100644 --- a/intern/cycles/kernel/film/cryptomatte_passes.h +++ b/intern/cycles/kernel/film/cryptomatte_passes.h @@ -11,10 +11,10 @@ CCL_NAMESPACE_BEGIN /* Element of ID pass stored in the render buffers. * It is `float2` semantically, but it must be unaligned since the offset of ID passes in the * render buffers might not meet expected by compiler alignment. */ -typedef struct CryptoPassBufferElement { +struct CryptoPassBufferElement { float x; float y; -} CryptoPassBufferElement; +}; ccl_device_inline void film_write_cryptomatte_slots(ccl_global float *buffer, int num_slots, @@ -55,7 +55,7 @@ ccl_device_inline void film_write_cryptomatte_slots(ccl_global float *buffer, } /* If there already is a slot for that ID, add the weight. * If no slot was found, add it to the last. */ - else if (id_buffer[slot].x == id || slot == num_slots - 1) { + if (id_buffer[slot].x == id || slot == num_slots - 1) { id_buffer[slot].y += weight; break; } diff --git a/intern/cycles/kernel/film/data_passes.h b/intern/cycles/kernel/film/data_passes.h index 942e729ad13..5922091e452 100644 --- a/intern/cycles/kernel/film/data_passes.h +++ b/intern/cycles/kernel/film/data_passes.h @@ -146,14 +146,18 @@ ccl_device_inline void film_write_data_passes(KernelGlobals kg, /* Falloff */ const float mist_falloff = kernel_data.film.mist_falloff; - if (mist_falloff == 1.0f) + if (mist_falloff == 1.0f) { ; - else if (mist_falloff == 2.0f) + } + else if (mist_falloff == 2.0f) { mist = mist * mist; - else if (mist_falloff == 0.5f) + } + else if (mist_falloff == 0.5f) { mist = sqrtf(mist); - else + } + else { mist = powf(mist, mist_falloff); + } /* Modulate by transparency */ const Spectrum throughput = INTEGRATOR_STATE(state, path, throughput); diff --git a/intern/cycles/kernel/film/light_passes.h b/intern/cycles/kernel/film/light_passes.h index 830fc563d93..8141c6aef98 100644 --- a/intern/cycles/kernel/film/light_passes.h +++ b/intern/cycles/kernel/film/light_passes.h @@ -4,11 +4,11 @@ #pragma once -#include "kernel/film/adaptive_sampling.h" #include "kernel/film/write.h" #include "kernel/integrator/shadow_catcher.h" +#include "kernel/sample/pattern.h" #include "util/atomic.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/film/write.h b/intern/cycles/kernel/film/write.h index 1d42ee00218..36b7bf39e01 100644 --- a/intern/cycles/kernel/film/write.h +++ b/intern/cycles/kernel/film/write.h @@ -111,7 +111,7 @@ ccl_device_inline void film_overwrite_pass_float3(ccl_global float *ccl_restrict /* Read back from passes. */ -ccl_device_inline float kernel_read_pass_float(ccl_global float *ccl_restrict buffer) +ccl_device_inline float kernel_read_pass_float(ccl_global const float *ccl_restrict buffer) { return *buffer; } diff --git a/intern/cycles/kernel/geom/attribute.h b/intern/cycles/kernel/geom/attribute.h index 924fc59d2f3..7809197707c 100644 --- a/intern/cycles/kernel/geom/attribute.h +++ b/intern/cycles/kernel/geom/attribute.h @@ -30,9 +30,7 @@ ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, int prim, int if ((type & PRIMITIVE_TRIANGLE) && subd_triangle_patch(kg, prim) != ~0) { return ATTR_PRIM_SUBD; } - else { - return ATTR_PRIM_GEOMETRY; - } + return ATTR_PRIM_GEOMETRY; } ccl_device_inline AttributeDescriptor attribute_not_found() @@ -66,10 +64,8 @@ find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id) if (UNLIKELY(attr_map.element == 0)) { return attribute_not_found(); } - else { - /* Chain jump to a different part of the table. */ - attr_offset = attr_map.offset; - } + /* Chain jump to a different part of the table. */ + attr_offset = attr_map.offset; } else { attr_offset += ATTR_PRIM_TYPES; @@ -88,7 +84,7 @@ find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id) /* return result */ desc.offset = (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : - (int)attr_map.offset; + attr_map.offset; desc.type = (NodeAttributeType)attr_map.type; desc.flags = (AttributeFlag)attr_map.flags; diff --git a/intern/cycles/kernel/geom/curve.h b/intern/cycles/kernel/geom/curve.h index 77350b94df4..93e3964ef89 100644 --- a/intern/cycles/kernel/geom/curve.h +++ b/intern/cycles/kernel/geom/curve.h @@ -37,31 +37,30 @@ ccl_device float curve_attribute_float(KernelGlobals kg, float f1 = kernel_data_fetch(attributes_float, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * (f1 - f0); - if (dy) + } + if (dy) { *dy = 0.0f; + } # endif return (1.0f - sd->u) * f0 + sd->u * f1; } - else { # ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; + if (dx) { + *dx = 0.0f; + } + if (dy) { + *dy = 0.0f; + } # endif - if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float, offset); - } - else { - return 0.0f; - } + if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float, offset); } + return 0.0f; } ccl_device float2 curve_attribute_float2(KernelGlobals kg, @@ -79,35 +78,35 @@ ccl_device float2 curve_attribute_float2(KernelGlobals kg, float2 f1 = kernel_data_fetch(attributes_float2, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * (f1 - f0); - if (dy) + } + if (dy) { *dy = make_float2(0.0f, 0.0f); + } # endif return (1.0f - sd->u) * f0 + sd->u * f1; } - else { - /* idea: we can't derive any useful differentials here, but for tiled - * mipmap image caching it would be useful to avoid reading the highest - * detail level always. maybe a derivative based on the hair density - * could be computed somehow? */ + + /* idea: we can't derive any useful differentials here, but for tiled + * mipmap image caching it would be useful to avoid reading the highest + * detail level always. maybe a derivative based on the hair density + * could be computed somehow? */ # ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); + if (dx) { + *dx = make_float2(0.0f, 0.0f); + } + if (dy) { + *dy = make_float2(0.0f, 0.0f); + } # endif - if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float2, offset); - } - else { - return make_float2(0.0f, 0.0f); - } + if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float2, offset); } + return make_float2(0.0f, 0.0f); } ccl_device float3 curve_attribute_float3(KernelGlobals kg, @@ -125,31 +124,31 @@ ccl_device float3 curve_attribute_float3(KernelGlobals kg, float3 f1 = kernel_data_fetch(attributes_float3, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * (f1 - f0); - if (dy) + } + if (dy) { *dy = make_float3(0.0f, 0.0f, 0.0f); + } # endif return (1.0f - sd->u) * f0 + sd->u * f1; } - else { + # ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); + if (dx) { + *dx = make_float3(0.0f, 0.0f, 0.0f); + } + if (dy) { + *dy = make_float3(0.0f, 0.0f, 0.0f); + } # endif - if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float3, offset); - } - else { - return make_float3(0.0f, 0.0f, 0.0f); - } + if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float3, offset); } + return make_float3(0.0f, 0.0f, 0.0f); } ccl_device float4 curve_attribute_float4(KernelGlobals kg, @@ -167,31 +166,31 @@ ccl_device float4 curve_attribute_float4(KernelGlobals kg, float4 f1 = kernel_data_fetch(attributes_float4, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * (f1 - f0); - if (dy) + } + if (dy) { *dy = zero_float4(); + } # endif return (1.0f - sd->u) * f0 + sd->u * f1; } - else { + # ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = zero_float4(); - if (dy) - *dy = zero_float4(); + if (dx) { + *dx = zero_float4(); + } + if (dy) { + *dy = zero_float4(); + } # endif - if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float4, offset); - } - else { - return zero_float4(); - } + if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float4, offset); } + return zero_float4(); } /* Curve thickness */ diff --git a/intern/cycles/kernel/geom/curve_intersect.h b/intern/cycles/kernel/geom/curve_intersect.h index e88dd1412fe..c647376751b 100644 --- a/intern/cycles/kernel/geom/curve_intersect.h +++ b/intern/cycles/kernel/geom/curve_intersect.h @@ -6,7 +6,6 @@ #pragma once -#include "kernel/geom/curve.h" #include "kernel/geom/motion_curve.h" #include "kernel/geom/object.h" @@ -17,10 +16,12 @@ CCL_NAMESPACE_BEGIN * The code here was adapted from curve_intersector_sweep.h in Embree, to get * an exact match between Embree CPU ray-tracing and our GPU ray-tracing. */ +// NOLINTBEGIN #define CURVE_NUM_BEZIER_SUBDIVISIONS 3 #define CURVE_NUM_BEZIER_SUBDIVISIONS_UNSTABLE (CURVE_NUM_BEZIER_SUBDIVISIONS + 1) #define CURVE_NUM_BEZIER_STEPS 2 #define CURVE_NUM_JACOBIAN_ITERATIONS 5 +// NOLINTEND #ifdef __HAIR__ @@ -114,10 +115,8 @@ ccl_device_inline bool cylinder_intersect(const float3 cylinder_start, *t_o = make_float2(-FLT_MAX, FLT_MAX); return true; } - else { - *t_o = make_float2(-FLT_MAX, FLT_MAX); - return false; - } + *t_o = make_float2(-FLT_MAX, FLT_MAX); + return false; } /* Standard case for rays that are not parallel to the cylinder. */ @@ -290,7 +289,7 @@ ccl_device bool curve_intersect_recursive(const float3 ray_P, float u1 = 1.0f; int i = 0; - while (1) { + while (true) { for (; i < CURVE_NUM_BEZIER_STEPS; i++) { const float step = i * step_size; @@ -670,16 +669,15 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals kg, return false; } - else { - if (curve_intersect_recursive(ray_P, ray_D, tmin, tmax, curve, isect)) { - isect->prim = prim; - isect->object = object; - isect->type = type; - return true; - } - return false; + if (curve_intersect_recursive(ray_P, ray_D, tmin, tmax, curve, isect)) { + isect->prim = prim; + isect->object = object; + isect->type = type; + return true; } + + return false; } ccl_device_inline void curve_shader_setup(KernelGlobals kg, diff --git a/intern/cycles/kernel/geom/motion_curve.h b/intern/cycles/kernel/geom/motion_curve.h index 0406df0f80a..4eae070f164 100644 --- a/intern/cycles/kernel/geom/motion_curve.h +++ b/intern/cycles/kernel/geom/motion_curve.h @@ -37,8 +37,9 @@ ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg, } else { /* center step is not stored in this array */ - if (step > numsteps) + if (step > numsteps) { step--; + } offset += step * numverts; @@ -95,8 +96,9 @@ ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg, } else { /* center step is not stored in this array */ - if (step > numsteps) + if (step > numsteps) { step--; + } offset += step * numverts; diff --git a/intern/cycles/kernel/geom/motion_point.h b/intern/cycles/kernel/geom/motion_point.h index 8b54abaf8ac..ec3109271eb 100644 --- a/intern/cycles/kernel/geom/motion_point.h +++ b/intern/cycles/kernel/geom/motion_point.h @@ -28,15 +28,14 @@ motion_point_for_step(KernelGlobals kg, int offset, int numverts, int numsteps, /* center step: regular key location */ return kernel_data_fetch(points, prim); } - else { - /* center step is not stored in this array */ - if (step > numsteps) - step--; - - offset += step * numverts; - - return kernel_data_fetch(attributes_float4, offset + prim); + /* center step is not stored in this array */ + if (step > numsteps) { + step--; } + + offset += step * numverts; + + return kernel_data_fetch(attributes_float4, offset + prim); } /* return 2 point key locations */ diff --git a/intern/cycles/kernel/geom/motion_triangle_intersect.h b/intern/cycles/kernel/geom/motion_triangle_intersect.h index 8d6b97b55a0..297d8b41b0c 100644 --- a/intern/cycles/kernel/geom/motion_triangle_intersect.h +++ b/intern/cycles/kernel/geom/motion_triangle_intersect.h @@ -138,8 +138,9 @@ ccl_device_inline bool motion_triangle_intersect_local(KernelGlobals kg, */ hit = lcg_step_uint(lcg_state) % local_isect->num_hits; - if (hit >= max_hits) + if (hit >= max_hits) { return false; + } } } else { diff --git a/intern/cycles/kernel/geom/object.h b/intern/cycles/kernel/geom/object.h index fc242dacddf..7d17fedb0a5 100644 --- a/intern/cycles/kernel/geom/object.h +++ b/intern/cycles/kernel/geom/object.h @@ -37,9 +37,7 @@ ccl_device_inline Transform object_fetch_transform(KernelGlobals kg, if (type == OBJECT_INVERSE_TRANSFORM) { return kernel_data_fetch(objects, object).itfm; } - else { - return kernel_data_fetch(objects, object).tfm; - } + return kernel_data_fetch(objects, object).tfm; } /* Lamp to world space transformation */ @@ -49,9 +47,7 @@ ccl_device_inline Transform lamp_fetch_transform(KernelGlobals kg, int lamp, boo if (inverse) { return kernel_data_fetch(lights, lamp).itfm; } - else { - return kernel_data_fetch(lights, lamp).tfm; - } + return kernel_data_fetch(lights, lamp).tfm; } /* Object to world space transformation for motion vectors */ @@ -91,20 +87,21 @@ ccl_device_inline Transform object_fetch_transform_motion_test(KernelGlobals kg, /* if we do motion blur */ Transform tfm = object_fetch_transform_motion(kg, object, time); - if (itfm) + if (itfm) { *itfm = transform_inverse(tfm); + } return tfm; } - else + #endif /* __OBJECT_MOTION__ */ - { - Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); - if (itfm) - *itfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM); - return tfm; + Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); + if (itfm) { + *itfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM); } + + return tfm; } /* Get transform matrix for shading point. */ @@ -257,8 +254,9 @@ ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, ccl_device_inline float3 object_location(KernelGlobals kg, ccl_private const ShaderData *sd) { - if (sd->object == OBJECT_NONE) + if (sd->object == OBJECT_NONE) { return make_float3(0.0f, 0.0f, 0.0f); + } #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -274,8 +272,9 @@ ccl_device_inline float3 object_location(KernelGlobals kg, ccl_private const Sha ccl_device_inline float3 object_color(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return make_float3(0.0f, 0.0f, 0.0f); + } ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3(kobject->color[0], kobject->color[1], kobject->color[2]); @@ -285,8 +284,9 @@ ccl_device_inline float3 object_color(KernelGlobals kg, int object) ccl_device_inline float object_alpha(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0.0f; + } return kernel_data_fetch(objects, object).alpha; } @@ -295,8 +295,9 @@ ccl_device_inline float object_alpha(KernelGlobals kg, int object) ccl_device_inline float object_pass_id(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0.0f; + } return kernel_data_fetch(objects, object).pass_id; } @@ -305,8 +306,9 @@ ccl_device_inline float object_pass_id(KernelGlobals kg, int object) ccl_device_inline int lamp_lightgroup(KernelGlobals kg, int lamp) { - if (lamp == LAMP_NONE) + if (lamp == LAMP_NONE) { return LIGHTGROUP_NONE; + } return kernel_data_fetch(lights, lamp).lightgroup; } @@ -315,8 +317,9 @@ ccl_device_inline int lamp_lightgroup(KernelGlobals kg, int lamp) ccl_device_inline int object_lightgroup(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return LIGHTGROUP_NONE; + } return kernel_data_fetch(objects, object).lightgroup; } @@ -325,8 +328,9 @@ ccl_device_inline int object_lightgroup(KernelGlobals kg, int object) ccl_device_inline float lamp_random_number(KernelGlobals kg, int lamp) { - if (lamp == LAMP_NONE) + if (lamp == LAMP_NONE) { return 0.0f; + } return kernel_data_fetch(lights, lamp).random; } @@ -335,8 +339,9 @@ ccl_device_inline float lamp_random_number(KernelGlobals kg, int lamp) ccl_device_inline float object_random_number(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0.0f; + } return kernel_data_fetch(objects, object).random_number; } @@ -345,8 +350,9 @@ ccl_device_inline float object_random_number(KernelGlobals kg, int object) ccl_device_inline int object_particle_id(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0; + } return kernel_data_fetch(objects, object).particle_index; } @@ -355,8 +361,9 @@ ccl_device_inline int object_particle_id(KernelGlobals kg, int object) ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return make_float3(0.0f, 0.0f, 0.0f); + } ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3( @@ -367,8 +374,9 @@ ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, int object) ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return make_float3(0.0f, 0.0f, 0.0f); + } ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3(kobject->dupli_uv[0], kobject->dupli_uv[1], 0.0f); @@ -378,8 +386,9 @@ ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, int object) ccl_device_inline uint object_patch_map_offset(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0; + } return kernel_data_fetch(objects, object).patch_map_offset; } @@ -415,16 +424,18 @@ ccl_device int shader_pass_id(KernelGlobals kg, ccl_private const ShaderData *sd ccl_device_inline float object_cryptomatte_id(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0.0f; + } return kernel_data_fetch(objects, object).cryptomatte_object; } ccl_device_inline float object_cryptomatte_asset_id(KernelGlobals kg, int object) { - if (object == OBJECT_NONE) + if (object == OBJECT_NONE) { return 0; + } return kernel_data_fetch(objects, object).cryptomatte_asset; } diff --git a/intern/cycles/kernel/geom/patch.h b/intern/cycles/kernel/geom/patch.h index cea1128737f..2e851597682 100644 --- a/intern/cycles/kernel/geom/patch.h +++ b/intern/cycles/kernel/geom/patch.h @@ -12,15 +12,13 @@ #include "kernel/geom/object.h" -#include "kernel/util/colorspace.h" - #include "util/color.h" CCL_NAMESPACE_BEGIN -typedef struct PatchHandle { +struct PatchHandle { int array_index, patch_index, vert_index; -} PatchHandle; +}; ccl_device_inline int patch_map_resolve_quadrant(float median, ccl_private float *u, @@ -87,9 +85,7 @@ patch_map_find_patch(KernelGlobals kg, int object, int patch, float u, float v) return handle; } - else { - node = index; - } + node = index; median = delta; } @@ -167,9 +163,7 @@ ccl_device_inline float patch_eval_param_fraction(uint patch_bits) if (non_quad_root) { return 1.0f / (float)(1 << (depth - 1)); } - else { - return 1.0f / (float)(1 << depth); - } + return 1.0f / (float)(1 << depth); } ccl_device_inline void patch_eval_normalize_coords(uint patch_bits, @@ -194,7 +188,7 @@ ccl_device_inline void patch_eval_normalize_coords(uint patch_bits, ccl_device_inline int patch_eval_indices(KernelGlobals kg, ccl_private const PatchHandle *handle, - int channel, + int /*channel*/, int indices[PATCH_MAX_CONTROL_VERTS]) { int index_base = kernel_data_fetch(patches, handle->array_index + 2) + handle->vert_index; @@ -330,10 +324,12 @@ ccl_device float2 patch_eval_float2(KernelGlobals kg, kg, sd->object, patch, u, v, channel, indices, weights, weights_du, weights_dv); float2 val = make_float2(0.0f, 0.0f); - if (du) + if (du) { *du = make_float2(0.0f, 0.0f); - if (dv) + } + if (dv) { *dv = make_float2(0.0f, 0.0f); + } for (int i = 0; i < num_control; i++) { float2 v = kernel_data_fetch(attributes_float2, offset + indices[i]); @@ -410,10 +406,12 @@ ccl_device float4 patch_eval_float4(KernelGlobals kg, kg, sd->object, patch, u, v, channel, indices, weights, weights_du, weights_dv); float4 val = zero_float4(); - if (du) + if (du) { *du = zero_float4(); - if (dv) + } + if (dv) { *dv = zero_float4(); + } for (int i = 0; i < num_control; i++) { float4 v = kernel_data_fetch(attributes_float4, offset + indices[i]); @@ -449,10 +447,12 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals kg, kg, sd->object, patch, u, v, channel, indices, weights, weights_du, weights_dv); float4 val = zero_float4(); - if (du) + if (du) { *du = zero_float4(); - if (dv) + } + if (dv) { *dv = zero_float4(); + } for (int i = 0; i < num_control; i++) { float4 v = color_srgb_to_linear_v4( diff --git a/intern/cycles/kernel/geom/point.h b/intern/cycles/kernel/geom/point.h index 1cc2a6b721b..7814c3046f9 100644 --- a/intern/cycles/kernel/geom/point.h +++ b/intern/cycles/kernel/geom/point.h @@ -28,18 +28,18 @@ ccl_device float point_attribute_float(KernelGlobals kg, ccl_private float *dy) { # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = 0.0f; - if (dy) + } + if (dy) { *dy = 0.0f; + } # endif if (desc.element == ATTR_ELEMENT_VERTEX) { return kernel_data_fetch(attributes_float, desc.offset + sd->prim); } - else { - return 0.0f; - } + return 0.0f; } ccl_device float2 point_attribute_float2(KernelGlobals kg, @@ -49,18 +49,18 @@ ccl_device float2 point_attribute_float2(KernelGlobals kg, ccl_private float2 *dy) { # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = make_float2(0.0f, 0.0f); - if (dy) + } + if (dy) { *dy = make_float2(0.0f, 0.0f); + } # endif if (desc.element == ATTR_ELEMENT_VERTEX) { return kernel_data_fetch(attributes_float2, desc.offset + sd->prim); } - else { - return make_float2(0.0f, 0.0f); - } + return make_float2(0.0f, 0.0f); } ccl_device float3 point_attribute_float3(KernelGlobals kg, @@ -70,18 +70,18 @@ ccl_device float3 point_attribute_float3(KernelGlobals kg, ccl_private float3 *dy) { # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) + } + if (dy) { *dy = make_float3(0.0f, 0.0f, 0.0f); + } # endif if (desc.element == ATTR_ELEMENT_VERTEX) { return kernel_data_fetch(attributes_float3, desc.offset + sd->prim); } - else { - return make_float3(0.0f, 0.0f, 0.0f); - } + return make_float3(0.0f, 0.0f, 0.0f); } ccl_device float4 point_attribute_float4(KernelGlobals kg, @@ -91,18 +91,18 @@ ccl_device float4 point_attribute_float4(KernelGlobals kg, ccl_private float4 *dy) { # ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = zero_float4(); - if (dy) + } + if (dy) { *dy = zero_float4(); + } # endif if (desc.element == ATTR_ELEMENT_VERTEX) { return kernel_data_fetch(attributes_float4, desc.offset + sd->prim); } - else { - return zero_float4(); - } + return zero_float4(); } /* Point position */ @@ -136,12 +136,11 @@ ccl_device float point_radius(KernelGlobals kg, ccl_private const ShaderData *sd if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) { return r; } - else { - const float normalized_r = r * (1.0f / M_SQRT3_F); - float3 dir = make_float3(normalized_r, normalized_r, normalized_r); - object_dir_transform(kg, sd, &dir); - return len(dir); - } + + const float normalized_r = r * (1.0f / M_SQRT3_F); + float3 dir = make_float3(normalized_r, normalized_r, normalized_r); + object_dir_transform(kg, sd, &dir); + return len(dir); } return 0.0f; diff --git a/intern/cycles/kernel/geom/primitive.h b/intern/cycles/kernel/geom/primitive.h index a168746ffb7..ac8cc34a1ff 100644 --- a/intern/cycles/kernel/geom/primitive.h +++ b/intern/cycles/kernel/geom/primitive.h @@ -36,13 +36,13 @@ ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg, ccl_private float *dy) { if (sd->type & PRIMITIVE_TRIANGLE) { - if (subd_triangle_patch(kg, sd->prim) == ~0) + if (subd_triangle_patch(kg, sd->prim) == ~0) { return triangle_attribute_float(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float(kg, sd, desc, dx, dy); + } + return subd_triangle_attribute_float(kg, sd, desc, dx, dy); } #ifdef __HAIR__ - else if (sd->type & PRIMITIVE_CURVE) { + if (sd->type & PRIMITIVE_CURVE) { return curve_attribute_float(kg, sd, desc, dx, dy); } #endif @@ -52,10 +52,12 @@ ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg, } #endif else { - if (dx) + if (dx) { *dx = 0.0f; - if (dy) + } + if (dy) { *dy = 0.0f; + } return 0.0f; } } @@ -67,13 +69,13 @@ ccl_device_forceinline float2 primitive_surface_attribute_float2(KernelGlobals k ccl_private float2 *dy) { if (sd->type & PRIMITIVE_TRIANGLE) { - if (subd_triangle_patch(kg, sd->prim) == ~0) + if (subd_triangle_patch(kg, sd->prim) == ~0) { return triangle_attribute_float2(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float2(kg, sd, desc, dx, dy); + } + return subd_triangle_attribute_float2(kg, sd, desc, dx, dy); } #ifdef __HAIR__ - else if (sd->type & PRIMITIVE_CURVE) { + if (sd->type & PRIMITIVE_CURVE) { return curve_attribute_float2(kg, sd, desc, dx, dy); } #endif @@ -83,10 +85,12 @@ ccl_device_forceinline float2 primitive_surface_attribute_float2(KernelGlobals k } #endif else { - if (dx) + if (dx) { *dx = make_float2(0.0f, 0.0f); - if (dy) + } + if (dy) { *dy = make_float2(0.0f, 0.0f); + } return make_float2(0.0f, 0.0f); } } @@ -98,13 +102,13 @@ ccl_device_forceinline float3 primitive_surface_attribute_float3(KernelGlobals k ccl_private float3 *dy) { if (sd->type & PRIMITIVE_TRIANGLE) { - if (subd_triangle_patch(kg, sd->prim) == ~0) + if (subd_triangle_patch(kg, sd->prim) == ~0) { return triangle_attribute_float3(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float3(kg, sd, desc, dx, dy); + } + return subd_triangle_attribute_float3(kg, sd, desc, dx, dy); } #ifdef __HAIR__ - else if (sd->type & PRIMITIVE_CURVE) { + if (sd->type & PRIMITIVE_CURVE) { return curve_attribute_float3(kg, sd, desc, dx, dy); } #endif @@ -114,10 +118,12 @@ ccl_device_forceinline float3 primitive_surface_attribute_float3(KernelGlobals k } #endif else { - if (dx) + if (dx) { *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) + } + if (dy) { *dy = make_float3(0.0f, 0.0f, 0.0f); + } return make_float3(0.0f, 0.0f, 0.0f); } } @@ -129,13 +135,13 @@ ccl_device_forceinline float4 primitive_surface_attribute_float4(KernelGlobals k ccl_private float4 *dy) { if (sd->type & PRIMITIVE_TRIANGLE) { - if (subd_triangle_patch(kg, sd->prim) == ~0) + if (subd_triangle_patch(kg, sd->prim) == ~0) { return triangle_attribute_float4(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float4(kg, sd, desc, dx, dy); + } + return subd_triangle_attribute_float4(kg, sd, desc, dx, dy); } #ifdef __HAIR__ - else if (sd->type & PRIMITIVE_CURVE) { + if (sd->type & PRIMITIVE_CURVE) { return curve_attribute_float4(kg, sd, desc, dx, dy); } #endif @@ -145,10 +151,12 @@ ccl_device_forceinline float4 primitive_surface_attribute_float4(KernelGlobals k } #endif else { - if (dx) + if (dx) { *dx = zero_float4(); - if (dy) + } + if (dy) { *dy = zero_float4(); + } return zero_float4(); } } @@ -173,9 +181,7 @@ ccl_device_forceinline float primitive_volume_attribute_float(KernelGlobals kg, if (primitive_is_volume_attribute(sd, desc)) { return volume_attribute_value_to_float(volume_attribute_float4(kg, sd, desc)); } - else { - return 0.0f; - } + return 0.0f; } ccl_device_forceinline float3 primitive_volume_attribute_float3(KernelGlobals kg, @@ -185,9 +191,7 @@ ccl_device_forceinline float3 primitive_volume_attribute_float3(KernelGlobals kg if (primitive_is_volume_attribute(sd, desc)) { return volume_attribute_value_to_float3(volume_attribute_float4(kg, sd, desc)); } - else { - return make_float3(0.0f, 0.0f, 0.0f); - } + return make_float3(0.0f, 0.0f, 0.0f); } ccl_device_forceinline float4 primitive_volume_attribute_float4(KernelGlobals kg, @@ -197,9 +201,7 @@ ccl_device_forceinline float4 primitive_volume_attribute_float4(KernelGlobals kg if (primitive_is_volume_attribute(sd, desc)) { return volume_attribute_float4(kg, sd, desc); } - else { - return zero_float4(); - } + return zero_float4(); } #endif @@ -209,8 +211,9 @@ ccl_device_forceinline float3 primitive_uv(KernelGlobals kg, ccl_private const S { const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_UV); - if (desc.offset == ATTR_STD_NOT_FOUND) + if (desc.offset == ATTR_STD_NOT_FOUND) { return make_float3(0.0f, 0.0f, 0.0f); + } float2 uv = primitive_surface_attribute_float2(kg, sd, desc, nullptr, nullptr); return make_float3(uv.x, uv.y, 1.0f); @@ -227,8 +230,9 @@ ccl_device bool primitive_ptex(KernelGlobals kg, const AttributeDescriptor desc_face_id = find_attribute(kg, sd, ATTR_STD_PTEX_FACE_ID); const AttributeDescriptor desc_uv = find_attribute(kg, sd, ATTR_STD_PTEX_UV); - if (desc_face_id.offset == ATTR_STD_NOT_FOUND || desc_uv.offset == ATTR_STD_NOT_FOUND) + if (desc_face_id.offset == ATTR_STD_NOT_FOUND || desc_uv.offset == ATTR_STD_NOT_FOUND) { return false; + } float3 uv3 = primitive_surface_attribute_float3(kg, sd, desc_uv, nullptr, nullptr); float face_id_f = primitive_surface_attribute_float(kg, sd, desc_face_id, nullptr, nullptr); @@ -244,9 +248,10 @@ ccl_device bool primitive_ptex(KernelGlobals kg, ccl_device float3 primitive_tangent(KernelGlobals kg, ccl_private ShaderData *sd) { #if defined(__HAIR__) || defined(__POINTCLOUD__) - if (sd->type & (PRIMITIVE_CURVE | PRIMITIVE_POINT)) + if (sd->type & (PRIMITIVE_CURVE | PRIMITIVE_POINT)) { # ifdef __DPDU__ return normalize(sd->dPdu); + } # else return make_float3(0.0f, 0.0f, 0.0f); # endif @@ -261,14 +266,12 @@ ccl_device float3 primitive_tangent(KernelGlobals kg, ccl_private ShaderData *sd object_normal_transform(kg, sd, &data); return cross(sd->N, normalize(cross(data, sd->N))); } - else { - /* otherwise use surface derivatives */ + /* otherwise use surface derivatives */ #ifdef __DPDU__ - return normalize(sd->dPdu); + return normalize(sd->dPdu); #else - return make_float3(0.0f, 0.0f, 0.0f); + return make_float3(0.0f, 0.0f, 0.0f); #endif - } } /* Motion vector for motion pass */ diff --git a/intern/cycles/kernel/geom/subd_triangle.h b/intern/cycles/kernel/geom/subd_triangle.h index 71565d8cc5c..c5a217cf4eb 100644 --- a/intern/cycles/kernel/geom/subd_triangle.h +++ b/intern/cycles/kernel/geom/subd_triangle.h @@ -12,8 +12,6 @@ #include "kernel/geom/attribute.h" #include "kernel/geom/patch.h" -#include "kernel/util/colorspace.h" - CCL_NAMESPACE_BEGIN /* UV coords of triangle within patch */ @@ -142,92 +140,98 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg, return a; } - else #endif /* __PATCH_EVAL__ */ - if (desc.element == ATTR_ELEMENT_FACE) { - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; - - return kernel_data_fetch(attributes_float, - desc.offset + subd_triangle_patch_face(kg, patch)); + if (desc.element == ATTR_ELEMENT_FACE) { + if (dx) { + *dx = 0.0f; + } + if (dy) { + *dy = 0.0f; } - else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - uint4 v = subd_triangle_patch_indices(kg, patch); + return kernel_data_fetch(attributes_float, desc.offset + subd_triangle_patch_face(kg, patch)); + } + if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); - float f0 = kernel_data_fetch(attributes_float, desc.offset + v.x); - float f1 = kernel_data_fetch(attributes_float, desc.offset + v.y); - float f2 = kernel_data_fetch(attributes_float, desc.offset + v.z); - float f3 = kernel_data_fetch(attributes_float, desc.offset + v.w); + uint4 v = subd_triangle_patch_indices(kg, patch); - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } + float f0 = kernel_data_fetch(attributes_float, desc.offset + v.x); + float f1 = kernel_data_fetch(attributes_float, desc.offset + v.y); + float f2 = kernel_data_fetch(attributes_float, desc.offset + v.z); + float f3 = kernel_data_fetch(attributes_float, desc.offset + v.w); - float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; + } + + float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_CORNER) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); + + int corners[4]; + subd_triangle_patch_corners(kg, patch, corners); + + float f0 = kernel_data_fetch(attributes_float, corners[0] + desc.offset); + float f1 = kernel_data_fetch(attributes_float, corners[1] + desc.offset); + float f2 = kernel_data_fetch(attributes_float, corners[2] + desc.offset); + float f3 = kernel_data_fetch(attributes_float, corners[3] + desc.offset); + + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; } - else if (desc.element == ATTR_ELEMENT_CORNER) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - int corners[4]; - subd_triangle_patch_corners(kg, patch, corners); - - float f0 = kernel_data_fetch(attributes_float, corners[0] + desc.offset); - float f1 = kernel_data_fetch(attributes_float, corners[1] + desc.offset); - float f2 = kernel_data_fetch(attributes_float, corners[2] + desc.offset); - float f3 = kernel_data_fetch(attributes_float, corners[3] + desc.offset); - - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } - - float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { + if (dx) { + *dx = 0.0f; + } + if (dy) { + *dy = 0.0f; } - else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; - return kernel_data_fetch(attributes_float, desc.offset); - } - else { - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; + return kernel_data_fetch(attributes_float, desc.offset); + } - return 0.0f; - } + if (dx) { + *dx = 0.0f; + } + if (dy) { + *dy = 0.0f; + } + return 0.0f; } ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, @@ -283,94 +287,101 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, return a; } - else #endif /* __PATCH_EVAL__ */ - if (desc.element == ATTR_ELEMENT_FACE) { - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); - - return kernel_data_fetch(attributes_float2, - desc.offset + subd_triangle_patch_face(kg, patch)); + if (desc.element == ATTR_ELEMENT_FACE) { + if (dx) { + *dx = make_float2(0.0f, 0.0f); + } + if (dy) { + *dy = make_float2(0.0f, 0.0f); } - else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - uint4 v = subd_triangle_patch_indices(kg, patch); + return kernel_data_fetch(attributes_float2, desc.offset + subd_triangle_patch_face(kg, patch)); + } + if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); - float2 f0 = kernel_data_fetch(attributes_float2, desc.offset + v.x); - float2 f1 = kernel_data_fetch(attributes_float2, desc.offset + v.y); - float2 f2 = kernel_data_fetch(attributes_float2, desc.offset + v.z); - float2 f3 = kernel_data_fetch(attributes_float2, desc.offset + v.w); + uint4 v = subd_triangle_patch_indices(kg, patch); - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } + float2 f0 = kernel_data_fetch(attributes_float2, desc.offset + v.x); + float2 f1 = kernel_data_fetch(attributes_float2, desc.offset + v.y); + float2 f2 = kernel_data_fetch(attributes_float2, desc.offset + v.z); + float2 f3 = kernel_data_fetch(attributes_float2, desc.offset + v.w); - float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; + } + + float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_CORNER) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); + + int corners[4]; + subd_triangle_patch_corners(kg, patch, corners); + + float2 f0, f1, f2, f3; + + f0 = kernel_data_fetch(attributes_float2, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float2, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float2, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float2, corners[3] + desc.offset); + + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; } - else if (desc.element == ATTR_ELEMENT_CORNER) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - int corners[4]; - subd_triangle_patch_corners(kg, patch, corners); - - float2 f0, f1, f2, f3; - - f0 = kernel_data_fetch(attributes_float2, corners[0] + desc.offset); - f1 = kernel_data_fetch(attributes_float2, corners[1] + desc.offset); - f2 = kernel_data_fetch(attributes_float2, corners[2] + desc.offset); - f3 = kernel_data_fetch(attributes_float2, corners[3] + desc.offset); - - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } - - float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { + if (dx) { + *dx = make_float2(0.0f, 0.0f); + } + if (dy) { + *dy = make_float2(0.0f, 0.0f); } - else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); - return kernel_data_fetch(attributes_float2, desc.offset); - } - else { - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); + return kernel_data_fetch(attributes_float2, desc.offset); + } - return make_float2(0.0f, 0.0f); - } + if (dx) { + *dx = make_float2(0.0f, 0.0f); + } + if (dy) { + *dy = make_float2(0.0f, 0.0f); + } + + return make_float2(0.0f, 0.0f); } ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, @@ -425,94 +436,100 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, return a; } - else #endif /* __PATCH_EVAL__ */ - if (desc.element == ATTR_ELEMENT_FACE) { - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); - - return kernel_data_fetch(attributes_float3, - desc.offset + subd_triangle_patch_face(kg, patch)); + if (desc.element == ATTR_ELEMENT_FACE) { + if (dx) { + *dx = make_float3(0.0f, 0.0f, 0.0f); + } + if (dy) { + *dy = make_float3(0.0f, 0.0f, 0.0f); } - else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - uint4 v = subd_triangle_patch_indices(kg, patch); + return kernel_data_fetch(attributes_float3, desc.offset + subd_triangle_patch_face(kg, patch)); + } + if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); - float3 f0 = kernel_data_fetch(attributes_float3, desc.offset + v.x); - float3 f1 = kernel_data_fetch(attributes_float3, desc.offset + v.y); - float3 f2 = kernel_data_fetch(attributes_float3, desc.offset + v.z); - float3 f3 = kernel_data_fetch(attributes_float3, desc.offset + v.w); + uint4 v = subd_triangle_patch_indices(kg, patch); - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } + float3 f0 = kernel_data_fetch(attributes_float3, desc.offset + v.x); + float3 f1 = kernel_data_fetch(attributes_float3, desc.offset + v.y); + float3 f2 = kernel_data_fetch(attributes_float3, desc.offset + v.z); + float3 f3 = kernel_data_fetch(attributes_float3, desc.offset + v.w); - float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; + } + + float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_CORNER) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); + + int corners[4]; + subd_triangle_patch_corners(kg, patch, corners); + + float3 f0, f1, f2, f3; + + f0 = kernel_data_fetch(attributes_float3, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float3, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float3, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float3, corners[3] + desc.offset); + + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; } - else if (desc.element == ATTR_ELEMENT_CORNER) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - int corners[4]; - subd_triangle_patch_corners(kg, patch, corners); - - float3 f0, f1, f2, f3; - - f0 = kernel_data_fetch(attributes_float3, corners[0] + desc.offset); - f1 = kernel_data_fetch(attributes_float3, corners[1] + desc.offset); - f2 = kernel_data_fetch(attributes_float3, corners[2] + desc.offset); - f3 = kernel_data_fetch(attributes_float3, corners[3] + desc.offset); - - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } - - float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { + if (dx) { + *dx = make_float3(0.0f, 0.0f, 0.0f); + } + if (dy) { + *dy = make_float3(0.0f, 0.0f, 0.0f); } - else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); - return kernel_data_fetch(attributes_float3, desc.offset); - } - else { - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); + return kernel_data_fetch(attributes_float3, desc.offset); + } - return make_float3(0.0f, 0.0f, 0.0f); - } + if (dx) { + *dx = make_float3(0.0f, 0.0f, 0.0f); + } + if (dy) { + *dy = make_float3(0.0f, 0.0f, 0.0f); + } + return make_float3(0.0f, 0.0f, 0.0f); } ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, @@ -572,106 +589,112 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, return a; } - else #endif /* __PATCH_EVAL__ */ - if (desc.element == ATTR_ELEMENT_FACE) { - if (dx) - *dx = zero_float4(); - if (dy) - *dy = zero_float4(); - - return kernel_data_fetch(attributes_float4, - desc.offset + subd_triangle_patch_face(kg, patch)); + if (desc.element == ATTR_ELEMENT_FACE) { + if (dx) { + *dx = zero_float4(); + } + if (dy) { + *dy = zero_float4(); } - else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); - uint4 v = subd_triangle_patch_indices(kg, patch); + return kernel_data_fetch(attributes_float4, desc.offset + subd_triangle_patch_face(kg, patch)); + } + if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); - float4 f0 = kernel_data_fetch(attributes_float4, desc.offset + v.x); - float4 f1 = kernel_data_fetch(attributes_float4, desc.offset + v.y); - float4 f2 = kernel_data_fetch(attributes_float4, desc.offset + v.z); - float4 f3 = kernel_data_fetch(attributes_float4, desc.offset + v.w); + uint4 v = subd_triangle_patch_indices(kg, patch); - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } + float4 f0 = kernel_data_fetch(attributes_float4, desc.offset + v.x); + float4 f1 = kernel_data_fetch(attributes_float4, desc.offset + v.y); + float4 f2 = kernel_data_fetch(attributes_float4, desc.offset + v.z); + float4 f3 = kernel_data_fetch(attributes_float4, desc.offset + v.w); - float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; + } + + float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } #endif - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; - } - else if (desc.element == ATTR_ELEMENT_CORNER || desc.element == ATTR_ELEMENT_CORNER_BYTE) { - float2 uv[3]; - subd_triangle_patch_uv(kg, sd, uv); + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_CORNER || desc.element == ATTR_ELEMENT_CORNER_BYTE) { + float2 uv[3]; + subd_triangle_patch_uv(kg, sd, uv); - int corners[4]; - subd_triangle_patch_corners(kg, patch, corners); + int corners[4]; + subd_triangle_patch_corners(kg, patch, corners); - float4 f0, f1, f2, f3; + float4 f0, f1, f2, f3; - if (desc.element == ATTR_ELEMENT_CORNER_BYTE) { - f0 = color_srgb_to_linear_v4(color_uchar4_to_float4( - kernel_data_fetch(attributes_uchar4, corners[0] + desc.offset))); - f1 = color_srgb_to_linear_v4(color_uchar4_to_float4( - kernel_data_fetch(attributes_uchar4, corners[1] + desc.offset))); - f2 = color_srgb_to_linear_v4(color_uchar4_to_float4( - kernel_data_fetch(attributes_uchar4, corners[2] + desc.offset))); - f3 = color_srgb_to_linear_v4(color_uchar4_to_float4( - kernel_data_fetch(attributes_uchar4, corners[3] + desc.offset))); - } - else { - f0 = kernel_data_fetch(attributes_float4, corners[0] + desc.offset); - f1 = kernel_data_fetch(attributes_float4, corners[1] + desc.offset); - f2 = kernel_data_fetch(attributes_float4, corners[2] + desc.offset); - f3 = kernel_data_fetch(attributes_float4, corners[3] + desc.offset); - } - - if (subd_triangle_patch_num_corners(kg, patch) != 4) { - f1 = (f1 + f0) * 0.5f; - f3 = (f3 + f0) * 0.5f; - } - - float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); - float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); - float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); - -#ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; - if (dy) - *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; -#endif - - return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; - } - else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { - if (dx) - *dx = zero_float4(); - if (dy) - *dy = zero_float4(); - - return kernel_data_fetch(attributes_float4, desc.offset); + if (desc.element == ATTR_ELEMENT_CORNER_BYTE) { + f0 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[0] + desc.offset))); + f1 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[1] + desc.offset))); + f2 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[2] + desc.offset))); + f3 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[3] + desc.offset))); } else { - if (dx) - *dx = zero_float4(); - if (dy) - *dy = zero_float4(); - - return zero_float4(); + f0 = kernel_data_fetch(attributes_float4, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float4, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float4, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float4, corners[3] + desc.offset); } + + if (subd_triangle_patch_num_corners(kg, patch) != 4) { + f1 = (f1 + f0) * 0.5f; + f3 = (f3 + f0) * 0.5f; + } + + float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y); + float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y); + float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y); + +#ifdef __RAY_DIFFERENTIALS__ + if (dx) { + *dx = sd->du.dx * b + sd->dv.dx * c - (sd->du.dx + sd->dv.dx) * a; + } + if (dy) { + *dy = sd->du.dy * b + sd->dv.dy * c - (sd->du.dy + sd->dv.dy) * a; + } +#endif + + return sd->u * b + sd->v * c + (1.0f - sd->u - sd->v) * a; + } + if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) { + if (dx) { + *dx = zero_float4(); + } + if (dy) { + *dy = zero_float4(); + } + + return kernel_data_fetch(attributes_float4, desc.offset); + } + + if (dx) { + *dx = zero_float4(); + } + if (dy) { + *dy = zero_float4(); + } + return zero_float4(); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/geom/triangle.h b/intern/cycles/kernel/geom/triangle.h index 2c235eef590..3628e9f517f 100644 --- a/intern/cycles/kernel/geom/triangle.h +++ b/intern/cycles/kernel/geom/triangle.h @@ -31,9 +31,7 @@ ccl_device_inline float3 triangle_normal(KernelGlobals kg, ccl_private ShaderDat if (object_negative_scale_applied(sd->object_flag)) { return normalize(cross(v2 - v0, v1 - v0)); } - else { - return normalize(cross(v1 - v0, v2 - v0)); - } + return normalize(cross(v1 - v0, v2 - v0)); } /* Point and normal on triangle. */ @@ -178,31 +176,30 @@ ccl_device float triangle_attribute_float(KernelGlobals kg, } #ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * f1 + sd->dv.dx * f2 - (sd->du.dx + sd->dv.dx) * f0; - if (dy) + } + if (dy) { *dy = sd->du.dy * f1 + sd->dv.dy * f2 - (sd->du.dy + sd->dv.dy) * f0; + } #endif return sd->u * f1 + sd->v * f2 + (1.0f - sd->u - sd->v) * f0; } - else { #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; + if (dx) { + *dx = 0.0f; + } + if (dy) { + *dy = 0.0f; + } #endif - if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float, offset); - } - else { - return 0.0f; - } + if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float, offset); } + return 0.0f; } ccl_device float2 triangle_attribute_float2(KernelGlobals kg, @@ -229,31 +226,30 @@ ccl_device float2 triangle_attribute_float2(KernelGlobals kg, } #ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * f1 + sd->dv.dx * f2 - (sd->du.dx + sd->dv.dx) * f0; - if (dy) + } + if (dy) { *dy = sd->du.dy * f1 + sd->dv.dy * f2 - (sd->du.dy + sd->dv.dy) * f0; + } #endif return sd->u * f1 + sd->v * f2 + (1.0f - sd->u - sd->v) * f0; } - else { #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); + if (dx) { + *dx = make_float2(0.0f, 0.0f); + } + if (dy) { + *dy = make_float2(0.0f, 0.0f); + } #endif - if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float2, offset); - } - else { - return make_float2(0.0f, 0.0f); - } + if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float2, offset); } + return make_float2(0.0f, 0.0f); } ccl_device float3 triangle_attribute_float3(KernelGlobals kg, @@ -280,31 +276,30 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals kg, } #ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * f1 + sd->dv.dx * f2 - (sd->du.dx + sd->dv.dx) * f0; - if (dy) + } + if (dy) { *dy = sd->du.dy * f1 + sd->dv.dy * f2 - (sd->du.dy + sd->dv.dy) * f0; + } #endif return sd->u * f1 + sd->v * f2 + (1.0f - sd->u - sd->v) * f0; } - else { #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); + if (dx) { + *dx = make_float3(0.0f, 0.0f, 0.0f); + } + if (dy) { + *dy = make_float3(0.0f, 0.0f, 0.0f); + } #endif - if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float3, offset); - } - else { - return make_float3(0.0f, 0.0f, 0.0f); - } + if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float3, offset); } + return make_float3(0.0f, 0.0f, 0.0f); } ccl_device float4 triangle_attribute_float4(KernelGlobals kg, @@ -343,31 +338,30 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals kg, } #ifdef __RAY_DIFFERENTIALS__ - if (dx) + if (dx) { *dx = sd->du.dx * f1 + sd->dv.dx * f2 - (sd->du.dx + sd->dv.dx) * f0; - if (dy) + } + if (dy) { *dy = sd->du.dy * f1 + sd->dv.dy * f2 - (sd->du.dy + sd->dv.dy) * f0; + } #endif return sd->u * f1 + sd->v * f2 + (1.0f - sd->u - sd->v) * f0; } - else { #ifdef __RAY_DIFFERENTIALS__ - if (dx) - *dx = zero_float4(); - if (dy) - *dy = zero_float4(); + if (dx) { + *dx = zero_float4(); + } + if (dy) { + *dy = zero_float4(); + } #endif - if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : - desc.offset; - return kernel_data_fetch(attributes_float4, offset); - } - else { - return zero_float4(); - } + if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { + const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; + return kernel_data_fetch(attributes_float4, offset); } + return zero_float4(); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/geom/triangle_intersect.h b/intern/cycles/kernel/geom/triangle_intersect.h index a3c8df31e02..6571e79f15f 100644 --- a/intern/cycles/kernel/geom/triangle_intersect.h +++ b/intern/cycles/kernel/geom/triangle_intersect.h @@ -111,8 +111,9 @@ ccl_device_inline bool triangle_intersect_local(KernelGlobals kg, * hits, randomly replace element or skip it */ hit = lcg_step_uint(lcg_state) % local_isect->num_hits; - if (hit >= max_hits) + if (hit >= max_hits) { return false; + } } } else { diff --git a/intern/cycles/kernel/geom/volume.h b/intern/cycles/kernel/geom/volume.h index 91e09cb528a..23f656e00d1 100644 --- a/intern/cycles/kernel/geom/volume.h +++ b/intern/cycles/kernel/geom/volume.h @@ -59,9 +59,7 @@ ccl_device float3 volume_attribute_value_to_float3(const float4 value) /* For RGBA colors, unpremultiply after interpolation. */ return make_float3(value) / value.w; } - else { - return make_float3(value); - } + return make_float3(value); } ccl_device float4 volume_attribute_float4(KernelGlobals kg, @@ -71,7 +69,7 @@ ccl_device float4 volume_attribute_float4(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { return kernel_data_fetch(attributes_float4, desc.offset); } - else if (desc.element == ATTR_ELEMENT_VOXEL) { + if (desc.element == ATTR_ELEMENT_VOXEL) { /* todo: optimize this so we don't have to transform both here and in * kernel_tex_image_interp_3d when possible. Also could optimize for the * common case where transform is translation/scale only. */ @@ -81,9 +79,7 @@ ccl_device float4 volume_attribute_float4(KernelGlobals kg, INTERPOLATION_NONE; return kernel_tex_image_interp_3d(kg, desc.offset, P, interp); } - else { - return zero_float4(); - } + return zero_float4(); } #endif diff --git a/intern/cycles/kernel/integrator/guiding.h b/intern/cycles/kernel/integrator/guiding.h index 590bdc25942..1413617b4ca 100644 --- a/intern/cycles/kernel/integrator/guiding.h +++ b/intern/cycles/kernel/integrator/guiding.h @@ -7,9 +7,8 @@ #include "kernel/globals.h" #include "kernel/types.h" -#include "kernel/closure/alloc.h" -#include "kernel/closure/bsdf.h" -#include "kernel/film/write.h" +#include "kernel/integrator/state.h" +#include "kernel/util/colorspace.h" #include "util/color.h" diff --git a/intern/cycles/kernel/integrator/init_from_bake.h b/intern/cycles/kernel/integrator/init_from_bake.h index e7cc78a88c3..040c8bd8b50 100644 --- a/intern/cycles/kernel/integrator/init_from_bake.h +++ b/intern/cycles/kernel/integrator/init_from_bake.h @@ -49,7 +49,6 @@ ccl_device_inline void bake_jitter_barycentric(ccl_private float &u, rand_filter = hash_float2_to_float2(rand_filter); } /* Retries exceeded, give up and just use center value. */ - return; } /* Offset towards center of triangle to avoid ray-tracing precision issues. */ @@ -231,7 +230,7 @@ ccl_device bool integrator_init_from_bake(KernelGlobals kg, film_write_pass_float3(buffer + kernel_data.film.pass_position, P); return true; } - else if (kernel_data.film.pass_normal != PASS_UNUSED && !(shader_flags & SD_HAS_BUMP)) { + if (kernel_data.film.pass_normal != PASS_UNUSED && !(shader_flags & SD_HAS_BUMP)) { film_write_pass_float3(buffer + kernel_data.film.pass_normal, N); return true; } diff --git a/intern/cycles/kernel/integrator/init_from_camera.h b/intern/cycles/kernel/integrator/init_from_camera.h index 524da472b0a..c4555b0631d 100644 --- a/intern/cycles/kernel/integrator/init_from_camera.h +++ b/intern/cycles/kernel/integrator/init_from_camera.h @@ -10,8 +10,8 @@ #include "kernel/film/light_passes.h" #include "kernel/integrator/path_state.h" -#include "kernel/integrator/shadow_catcher.h" +#include "kernel/integrator/state_util.h" #include "kernel/sample/pattern.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/integrator/intersect_closest.h b/intern/cycles/kernel/integrator/intersect_closest.h index 4cf913266ec..b91b34e1557 100644 --- a/intern/cycles/kernel/integrator/intersect_closest.h +++ b/intern/cycles/kernel/integrator/intersect_closest.h @@ -302,43 +302,40 @@ ccl_device_forceinline void integrator_intersect_next_kernel_after_volume( integrator_path_next(kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT); return; } - else { - /* Hit a surface, continue with surface kernel unless terminated. */ - const int shader = intersection_get_shader(kg, isect); - const int flags = kernel_data_fetch(shaders, shader).flags; - const int object_flags = intersection_get_object_flags(kg, isect); - const bool use_caustics = kernel_data.integrator.use_caustics && - (object_flags & SD_OBJECT_CAUSTICS); - const bool use_raytrace_kernel = (flags & SD_HAS_RAYTRACE); - if (use_caustics) { - integrator_path_next_sorted( - kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_MNEE, shader); - } - else if (use_raytrace_kernel) { - integrator_path_next_sorted( - kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE, shader); - } - else { - integrator_path_next_sorted( - kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE, shader); - } + /* Hit a surface, continue with surface kernel unless terminated. */ + const int shader = intersection_get_shader(kg, isect); + const int flags = kernel_data_fetch(shaders, shader).flags; + const int object_flags = intersection_get_object_flags(kg, isect); + const bool use_caustics = kernel_data.integrator.use_caustics && + (object_flags & SD_OBJECT_CAUSTICS); + const bool use_raytrace_kernel = (flags & SD_HAS_RAYTRACE); + + if (use_caustics) { + integrator_path_next_sorted( + kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_MNEE, shader); + } + else if (use_raytrace_kernel) { + integrator_path_next_sorted( + kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE, shader); + } + else { + integrator_path_next_sorted( + kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE, shader); + } #ifdef __SHADOW_CATCHER__ - /* Handle shadow catcher. */ - integrator_split_shadow_catcher(kg, state, isect, render_buffer); + /* Handle shadow catcher. */ + integrator_split_shadow_catcher(kg, state, isect, render_buffer); #endif - return; - } + return; + } + /* Nothing hit, continue with background kernel. */ + if (integrator_intersect_skip_lights(kg, state)) { + integrator_path_terminate(kg, state, current_kernel); } else { - /* Nothing hit, continue with background kernel. */ - if (integrator_intersect_skip_lights(kg, state)) { - integrator_path_terminate(kg, state, current_kernel); - } - else { - integrator_path_next(kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_BACKGROUND); - } + integrator_path_next(kg, state, current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_BACKGROUND); } } diff --git a/intern/cycles/kernel/integrator/intersect_shadow.h b/intern/cycles/kernel/integrator/intersect_shadow.h index 7646579a4c3..30819e47fc2 100644 --- a/intern/cycles/kernel/integrator/intersect_shadow.h +++ b/intern/cycles/kernel/integrator/intersect_shadow.h @@ -69,12 +69,13 @@ ccl_device int shadow_intersections_compare(const void *a, const void *b) const Intersection *isect_a = (const Intersection *)a; const Intersection *isect_b = (const Intersection *)b; - if (isect_a->t < isect_b->t) + if (isect_a->t < isect_b->t) { return -1; - else if (isect_a->t > isect_b->t) + } + if (isect_a->t > isect_b->t) { return 1; - else - return 0; + } + return 0; } # endif @@ -133,7 +134,8 @@ ccl_device bool integrate_intersect_shadow_transparent(KernelGlobals kg, } if (!opaque_hit) { - const uint num_recorded_hits = min(num_hits, min(max_hits, INTEGRATOR_SHADOW_ISECT_SIZE)); + const uint num_recorded_hits = min(num_hits, + min(max_hits, (uint)INTEGRATOR_SHADOW_ISECT_SIZE)); if (num_recorded_hits > 0) { sort_shadow_intersections(state, num_recorded_hits); @@ -175,18 +177,14 @@ ccl_device void integrator_intersect_shadow(KernelGlobals kg, IntegratorShadowSt integrator_shadow_path_terminate(kg, state, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW); return; } - else { - /* Hit nothing or transparent surfaces, continue to shadow kernel - * for shading and render buffer output. - * - * TODO: could also write to render buffer directly if no transparent shadows? - * Could save a kernel execution for the common case. */ - integrator_shadow_path_next(kg, - state, - DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW, - DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW); - return; - } + + /* Hit nothing or transparent surfaces, continue to shadow kernel + * for shading and render buffer output. + * + * TODO: could also write to render buffer directly if no transparent shadows? + * Could save a kernel execution for the common case. */ + integrator_shadow_path_next( + kg, state, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW, DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/integrator/megakernel.h b/intern/cycles/kernel/integrator/megakernel.h index 6465b7e5c83..3e843cb0172 100644 --- a/intern/cycles/kernel/integrator/megakernel.h +++ b/intern/cycles/kernel/integrator/megakernel.h @@ -4,7 +4,6 @@ #pragma once -#include "kernel/integrator/init_from_camera.h" #include "kernel/integrator/intersect_closest.h" #include "kernel/integrator/intersect_dedicated_light.h" #include "kernel/integrator/intersect_shadow.h" diff --git a/intern/cycles/kernel/integrator/mnee.h b/intern/cycles/kernel/integrator/mnee.h index cc3bc29609c..9adc5433ec6 100644 --- a/intern/cycles/kernel/integrator/mnee.h +++ b/intern/cycles/kernel/integrator/mnee.h @@ -41,6 +41,7 @@ * https://cg.ivd.kit.edu/english/HSLT.php */ +// NOLINTBEGIN #define MNEE_MAX_ITERATIONS 64 #define MNEE_MAX_INTERSECTION_COUNT 10 #define MNEE_SOLVER_THRESHOLD 0.001f @@ -50,11 +51,12 @@ #define MNEE_MIN_PROGRESS_DISTANCE 0.0001f #define MNEE_MIN_DETERMINANT 0.0001f #define MNEE_PROJECTION_DISTANCE_MULTIPLIER 2.f +// NOLINTEND CCL_NAMESPACE_BEGIN /* Manifold struct containing the local differential geometry quantity */ -typedef ccl_private struct ManifoldVertex { +struct ManifoldVertex { /* Position and partials */ float3 p; float3 dp_du; @@ -82,7 +84,7 @@ typedef ccl_private struct ManifoldVertex { float4 a; float4 b; float4 c; -} ManifoldVertex; +}; /* Multiplication of a 2x2 matrix encoded in a row-major order float4 by a vector */ ccl_device_inline float2 mat22_mult(const float4 a, const float2 b) @@ -107,8 +109,9 @@ ccl_device_inline float mat22_determinant(const float4 m) ccl_device_inline float mat22_inverse(const float4 m, ccl_private float4 &m_inverse) { float det = mat22_determinant(m); - if (fabsf(det) < MNEE_MIN_DETERMINANT) + if (fabsf(det) < MNEE_MIN_DETERMINANT) { return 0.f; + } m_inverse = make_float4(m.w, -m.y, -m.z, m.x) / det; return det; } @@ -263,8 +266,9 @@ bool mnee_compute_constraint_derivatives( /* Direction toward surface sample. */ float3 wi = (vi == 0) ? surface_sample_pos - v.p : vertices[vi - 1].p - v.p; float ili = len(wi); - if (ili < MNEE_MIN_DISTANCE) + if (ili < MNEE_MIN_DISTANCE) { return false; + } ili = 1.f / ili; wi *= ili; @@ -273,15 +277,17 @@ bool mnee_compute_constraint_derivatives( (light_fixed_direction ? light_sample : light_sample - v.p) : vertices[vi + 1].p - v.p; float ilo = len(wo); - if (ilo < MNEE_MIN_DISTANCE) + if (ilo < MNEE_MIN_DISTANCE) { return false; + } ilo = 1.f / ilo; wo *= ilo; /* Invert ior if coming from inside. */ float eta = v.eta; - if (dot(wi, v.ng) < .0f) + if (dot(wi, v.ng) < .0f) { eta = 1.f / eta; + } /* Half vector. */ float3 H = -(wi + eta * wo); @@ -375,8 +381,9 @@ ccl_device_forceinline bool mnee_solve_matrix_h_to_x(int vertex_count, /* Block tridiagonal LU factorization. */ float4 Lk = vertices[0].b; - if (mat22_inverse(Lk, Li[0]) == 0.f) + if (mat22_inverse(Lk, Li[0]) == 0.f) { return false; + } C[0] = vertices[0].constraint; @@ -384,15 +391,17 @@ ccl_device_forceinline bool mnee_solve_matrix_h_to_x(int vertex_count, float4 A = mat22_mult(vertices[k].a, Li[k - 1]); Lk = vertices[k].b - mat22_mult(A, vertices[k - 1].c); - if (mat22_inverse(Lk, Li[k]) == 0.f) + if (mat22_inverse(Lk, Li[k]) == 0.f) { return false; + } C[k] = vertices[k].constraint - mat22_mult(A, C[k - 1]); } dx[vertex_count - 1] = mat22_mult(Li[vertex_count - 1], C[vertex_count - 1]); - for (int k = vertex_count - 2; k > -1; k--) + for (int k = vertex_count - 2; k > -1; k--) { dx[k] = mat22_mult(Li[k], C[k] - mat22_mult(vertices[k].c, dx[k + 1])); + } return true; } @@ -432,20 +441,25 @@ ccl_device_forceinline bool mnee_newton_solver(KernelGlobals kg, /* Calculate constraint and its derivatives for vertices. */ if (!mnee_compute_constraint_derivatives( vertex_count, vertices, sd->P, light_fixed_direction, light_sample)) + { return false; + } /* Calculate constraint norm. */ float constraint_norm = 0.f; - for (int vi = 0; vi < vertex_count; vi++) + for (int vi = 0; vi < vertex_count; vi++) { constraint_norm = fmaxf(constraint_norm, len(vertices[vi].constraint)); + } /* Return if solve successful. */ - if (constraint_norm < MNEE_SOLVER_THRESHOLD) + if (constraint_norm < MNEE_SOLVER_THRESHOLD) { return true; + } /* Invert derivative matrix. */ - if (!mnee_solve_matrix_h_to_x(vertex_count, vertices, dx)) + if (!mnee_solve_matrix_h_to_x(vertex_count, vertices, dx)) { return false; + } } /* Construct tentative new vertices and project back onto surface. */ @@ -484,8 +498,9 @@ ccl_device_forceinline bool mnee_newton_solver(KernelGlobals kg, bool projection_success = false; for (int isect_count = 0; isect_count < MNEE_MAX_INTERSECTION_COUNT; isect_count++) { bool hit = scene_intersect(kg, &projection_ray, PATH_RAY_TRANSMIT, &projection_isect); - if (!hit) + if (!hit) { break; + } if (projection_isect.object == mv.object) { projection_success = true; @@ -514,8 +529,9 @@ ccl_device_forceinline bool mnee_newton_solver(KernelGlobals kg, /* Fail newton solve if we are not making progress, probably stuck trying to move off the * edge of the mesh. */ const float distance = len(tv.p - mv.p); - if (distance < MNEE_MIN_PROGRESS_DISTANCE) + if (distance < MNEE_MIN_PROGRESS_DISTANCE) { return false; + } } /* Check that tentative path is still transmissive. */ @@ -543,15 +559,17 @@ ccl_device_forceinline bool mnee_newton_solver(KernelGlobals kg, beta *= .5f; /* Fail newton solve if the stepsize is too small. */ - if (beta < MNEE_MINIMUM_STEP_SIZE) + if (beta < MNEE_MINIMUM_STEP_SIZE) { return false; + } continue; } /* Copy tentative vertices to main vertex list. */ - for (int vi = 0; vi < vertex_count; vi++) + for (int vi = 0; vi < vertex_count; vi++) { vertices[vi] = tentative[vi]; + } /* Increase the step to get back to 1. */ resolve_constraint = true; @@ -575,8 +593,9 @@ mnee_sample_bsdf_dh(ClosureType type, float alpha_x, float alpha_y, float sample } else { float phi = atanf(alpha_y / alpha_x * tanf(M_2PI_F * sample_v + M_PI_2_F)); - if (sample_v > .5f) + if (sample_v > .5f) { phi += M_PI_F; + } fast_sincosf(phi, &sin_phi, &cos_phi); float alpha_x2 = alpha_x * alpha_x; float alpha_y2 = alpha_y * alpha_y; @@ -657,8 +676,9 @@ ccl_device_forceinline bool mnee_compute_transfer_matrix(ccl_private const Shade float4 Lk = vertices[0].b; float Lk_det = mat22_inverse(Lk, Li); - if (Lk_det == 0.f) + if (Lk_det == 0.f) { return false; + } float det_dh_dx = Lk_det; @@ -667,8 +687,9 @@ ccl_device_forceinline bool mnee_compute_transfer_matrix(ccl_private const Shade Lk = vertices[k].b - mat22_mult(vertices[k].a, U[k - 1]); Lk_det = mat22_inverse(Lk, Li); - if (Lk_det == 0.f) + if (Lk_det == 0.f) { return false; + } det_dh_dx *= Lk_det; } @@ -693,8 +714,9 @@ ccl_device_forceinline bool mnee_compute_transfer_matrix(ccl_private const Shade /* Invert ior if coming from inside. */ float eta = m.eta; - if (dot(wi, m.ng) < .0f) + if (dot(wi, m.ng) < .0f) { eta = 1.f / eta; + } float dxn_dwn; float4 dc_dlight; @@ -757,8 +779,9 @@ ccl_device_forceinline bool mnee_compute_transfer_matrix(ccl_private const Shade /* Compute transfer matrix. */ float4 Tp = -mat22_mult(Li, dc_dlight); - for (int k = vertex_count - 2; k > -1; k--) + for (int k = vertex_count - 2; k > -1; k--) { Tp = -mat22_mult(U[k], Tp); + } *dx1_dxlight = fabsf(mat22_determinant(Tp)) * dxn_dwn; *dh_dx = fabsf(det_dh_dx); @@ -818,7 +841,9 @@ ccl_device_forceinline bool mnee_path_contribution(KernelGlobals kg, float dx1_dxlight; if (!mnee_compute_transfer_matrix( sd, ls, light_fixed_direction, vertex_count, vertices, &dx1_dxlight, &dh_dx)) + { return false; + } /* Receiver bsdf eval above already contains |n.wo|. */ const float dw0_dx1 = fabsf(dot(wo, vertices[0].n)) / sqr(wo_len); @@ -856,8 +881,9 @@ ccl_device_forceinline bool mnee_path_contribution(KernelGlobals kg, kernel_data_fetch(prim_object, probe_isect.prim) : probe_isect.object; /* Test whether the ray hit the appropriate object at its intended location. */ - if (hit_object != v.object || fabsf(probe_ray.tmax - probe_isect.t) > MNEE_MIN_DISTANCE) + if (hit_object != v.object || fabsf(probe_ray.tmax - probe_isect.t) > MNEE_MIN_DISTANCE) { return false; + } } probe_ray.self.object = v.object; probe_ray.self.prim = v.prim; @@ -957,19 +983,22 @@ ccl_device_forceinline int kernel_path_mnee_sample(KernelGlobals kg, int vertex_count = 0; for (int isect_count = 0; isect_count < MNEE_MAX_INTERSECTION_COUNT; isect_count++) { bool hit = scene_intersect(kg, &probe_ray, PATH_RAY_TRANSMIT, &probe_isect); - if (!hit) + if (!hit) { break; + } const int object_flags = intersection_get_object_flags(kg, &probe_isect); if (object_flags & SD_OBJECT_CAUSTICS_CASTER) { /* Do we have enough slots. */ - if (vertex_count >= MNEE_MAX_CAUSTIC_CASTERS) + if (vertex_count >= MNEE_MAX_CAUSTIC_CASTERS) { return 0; + } /* Reject caster if it is not a triangles mesh. */ - if (!(probe_isect.type & PRIMITIVE_TRIANGLE)) + if (!(probe_isect.type & PRIMITIVE_TRIANGLE)) { return 0; + } ccl_private ManifoldVertex &mv = vertices[vertex_count++]; @@ -979,8 +1008,9 @@ ccl_device_forceinline int kernel_path_mnee_sample(KernelGlobals kg, /* Reject caster if smooth normals are not available: Manifold exploration assumes local * differential geometry can be created at any point on the surface which is not possible if * normals are not smooth. */ - if (!(sd_mnee->shader & SHADER_SMOOTH_NORMAL)) + if (!(sd_mnee->shader & SHADER_SMOOTH_NORMAL)) { return 0; + } /* Last bool argument is the MNEE flag (for TINY_MAX_CLOSURE cap in kernel_shader.h). */ surface_shader_eval( @@ -1016,8 +1046,9 @@ ccl_device_forceinline int kernel_path_mnee_sample(KernelGlobals kg, break; } } - if (!found_refractive_microfacet_bsdf) + if (!found_refractive_microfacet_bsdf) { return 0; + } } probe_ray.self.object = probe_isect.object; @@ -1028,22 +1059,29 @@ ccl_device_forceinline int kernel_path_mnee_sample(KernelGlobals kg, /* Mark the manifold walk invalid to keep mollification on by default. */ INTEGRATOR_STATE_WRITE(state, path, mnee) &= ~PATH_MNEE_VALID; - if (vertex_count == 0) + if (vertex_count == 0) { return 0; + } /* Check whether the transmission depth limit is reached before continuing. */ if ((INTEGRATOR_STATE(state, path, transmission_bounce) + vertex_count - 1) >= kernel_data.integrator.max_transmission_bounce) + { return 0; + } /* Check whether the diffuse depth limit is reached before continuing. */ if ((INTEGRATOR_STATE(state, path, diffuse_bounce) + 1) >= kernel_data.integrator.max_diffuse_bounce) + { return 0; + } /* Check whether the overall depth limit is reached before continuing. */ if ((INTEGRATOR_STATE(state, path, bounce) + vertex_count) >= kernel_data.integrator.max_bounce) + { return 0; + } /* Mark the manifold walk valid to turn off mollification regardless of how successful the walk * is: this is noticeable when another mnee is performed deeper in the path, for an internally @@ -1067,7 +1105,9 @@ ccl_device_forceinline int kernel_path_mnee_sample(KernelGlobals kg, /* 3. If a solution exists, calculate contribution of the corresponding path */ if (!mnee_path_contribution( kg, state, sd, sd_mnee, ls, light_fixed_direction, vertex_count, vertices, throughput)) + { return 0; + } return vertex_count; } diff --git a/intern/cycles/kernel/integrator/path_state.h b/intern/cycles/kernel/integrator/path_state.h index 60eb1586864..9b30ca86413 100644 --- a/intern/cycles/kernel/integrator/path_state.h +++ b/intern/cycles/kernel/integrator/path_state.h @@ -309,11 +309,11 @@ ccl_device_inline bool path_state_ao_bounce(KernelGlobals kg, ConstIntegratorSta */ /* RNG State loaded onto stack. */ -typedef struct RNGState { +struct RNGState { uint rng_pixel; uint rng_offset; int sample; -} RNGState; +}; ccl_device_inline void path_state_rng_load(ConstIntegratorState state, ccl_private RNGState *rng_state) diff --git a/intern/cycles/kernel/integrator/shade_background.h b/intern/cycles/kernel/integrator/shade_background.h index 6021c4402d3..6b5bf0421ee 100644 --- a/intern/cycles/kernel/integrator/shade_background.h +++ b/intern/cycles/kernel/integrator/shade_background.h @@ -156,8 +156,9 @@ ccl_device_inline void integrate_distant_lights(KernelGlobals kg, /* This path should have been resolved with mnee, it will * generate a firefly for small lights since it is improbable. */ const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); - if (klight->use_caustics) + if (klight->use_caustics) { continue; + } } #endif /* __MNEE__ */ diff --git a/intern/cycles/kernel/integrator/shade_light.h b/intern/cycles/kernel/integrator/shade_light.h index 5f7c62aefed..d3fb99790e2 100644 --- a/intern/cycles/kernel/integrator/shade_light.h +++ b/intern/cycles/kernel/integrator/shade_light.h @@ -83,13 +83,9 @@ ccl_device void integrator_shade_light(KernelGlobals kg, integrator_path_terminate(kg, state, DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT); return; } - else { - integrator_path_next(kg, - state, - DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT, - DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST); - return; - } + + integrator_path_next( + kg, state, DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT, DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST); /* TODO: in some cases we could continue directly to SHADE_BACKGROUND, but * probably that optimization is probably not practical if we add lights to diff --git a/intern/cycles/kernel/integrator/shade_shadow.h b/intern/cycles/kernel/integrator/shade_shadow.h index b9fb9dbeebc..f4039785d72 100644 --- a/intern/cycles/kernel/integrator/shade_shadow.h +++ b/intern/cycles/kernel/integrator/shade_shadow.h @@ -104,7 +104,7 @@ ccl_device_inline bool integrate_transparent_shadow(KernelGlobals kg, const uint num_hits) { /* Accumulate shadow for transparent surfaces. */ - const uint num_recorded_hits = min(num_hits, INTEGRATOR_SHADOW_ISECT_SIZE); + const uint num_recorded_hits = min(num_hits, (uint)INTEGRATOR_SHADOW_ISECT_SIZE); /* Plus one to account for world volume, which has no boundary to hit but casts shadows. */ for (uint hit = 0; hit < num_recorded_hits + 1; hit++) { @@ -176,12 +176,10 @@ ccl_device void integrator_shade_shadow(KernelGlobals kg, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW); return; } - else { - guiding_record_direct_light(kg, state); - film_write_direct_light(kg, state, render_buffer); - integrator_shadow_path_terminate(kg, state, DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW); - return; - } + + guiding_record_direct_light(kg, state); + film_write_direct_light(kg, state, render_buffer); + integrator_shadow_path_terminate(kg, state, DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h index 60be8f79a7e..41da202f7c6 100644 --- a/intern/cycles/kernel/integrator/shade_surface.h +++ b/intern/cycles/kernel/integrator/shade_surface.h @@ -594,7 +594,7 @@ ccl_device_forceinline bool integrate_surface_terminate(IntegratorState state, if (continuation_probability == 0.0f) { return true; } - else if (continuation_probability != 1.0f) { + if (continuation_probability != 1.0f) { INTEGRATOR_STATE_WRITE(state, path, throughput) /= continuation_probability; } diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h index 5f505cba2c7..5e9d0ebf41d 100644 --- a/intern/cycles/kernel/integrator/shade_volume.h +++ b/intern/cycles/kernel/integrator/shade_volume.h @@ -4,6 +4,8 @@ #pragma once +#include "kernel/closure/volume.h" + #include "kernel/film/denoising_passes.h" #include "kernel/film/light_passes.h" @@ -25,13 +27,13 @@ CCL_NAMESPACE_BEGIN /* Events for probabilistic scattering. */ -typedef enum VolumeIntegrateEvent { +enum VolumeIntegrateEvent { VOLUME_PATH_SCATTERED = 0, VOLUME_PATH_ATTENUATED = 1, VOLUME_PATH_MISSED = 2 -} VolumeIntegrateEvent; +}; -typedef struct VolumeIntegrateResult { +struct VolumeIntegrateResult { /* Throughput and offset for direct light scattering. */ bool direct_scatter; Spectrum direct_throughput; @@ -46,7 +48,7 @@ typedef struct VolumeIntegrateResult { Spectrum indirect_throughput; float indirect_t; ShaderVolumePhases indirect_phases; -} VolumeIntegrateResult; +}; /* Ignore paths that have volume throughput below this value, to avoid unnecessary work * and precision issues. @@ -59,16 +61,16 @@ typedef struct VolumeIntegrateResult { * extinction coefficient = absorption coefficient + scattering coefficient * sigma_t = sigma_a + sigma_s */ -typedef struct VolumeShaderCoefficients { +struct VolumeShaderCoefficients { Spectrum sigma_t; Spectrum sigma_s; Spectrum emission; -} VolumeShaderCoefficients; +}; -typedef struct EquiangularCoefficients { +struct EquiangularCoefficients { float3 P; Interval t_range; -} EquiangularCoefficients; +}; /* Evaluate shader to get extinction coefficient at P. */ ccl_device_inline bool shadow_volume_shader_sample(KernelGlobals kg, @@ -383,7 +385,7 @@ ccl_device Spectrum volume_emission_integrate(ccl_private VolumeShaderCoefficien /* Volume Integration */ -typedef struct VolumeIntegrateState { +struct VolumeIntegrateState { /* Random numbers for scattering. */ float rscatter; float rchannel; @@ -393,7 +395,7 @@ typedef struct VolumeIntegrateState { bool use_mis; float distance_pdf; float equiangular_pdf; -} VolumeIntegrateState; +}; ccl_device bool volume_integrate_should_stop(ccl_private VolumeIntegrateResult &result) { @@ -1144,17 +1146,13 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg, if (integrate_volume_phase_scatter(kg, state, &sd, ray, &rng_state, &result.indirect_phases)) { return VOLUME_PATH_SCATTERED; } - else { - return VOLUME_PATH_MISSED; - } + return VOLUME_PATH_MISSED; } - else { # if defined(__PATH_GUIDING__) - /* No guiding if we don't scatter. */ - state->guiding.use_volume_guiding = false; + /* No guiding if we don't scatter. */ + state->guiding.use_volume_guiding = false; # endif - return VOLUME_PATH_ATTENUATED; - } + return VOLUME_PATH_ATTENUATED; } #endif diff --git a/intern/cycles/kernel/integrator/shadow_catcher.h b/intern/cycles/kernel/integrator/shadow_catcher.h index d6726728b85..566b6f3154f 100644 --- a/intern/cycles/kernel/integrator/shadow_catcher.h +++ b/intern/cycles/kernel/integrator/shadow_catcher.h @@ -4,9 +4,7 @@ #pragma once -#include "kernel/integrator/path_state.h" #include "kernel/integrator/state_flow.h" -#include "kernel/integrator/state_util.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/integrator/shadow_linking.h b/intern/cycles/kernel/integrator/shadow_linking.h index 3d159973f05..ea3ec7aac41 100644 --- a/intern/cycles/kernel/integrator/shadow_linking.h +++ b/intern/cycles/kernel/integrator/shadow_linking.h @@ -4,9 +4,7 @@ #pragma once -#include "kernel/integrator/path_state.h" #include "kernel/integrator/state_flow.h" -#include "kernel/integrator/state_util.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/integrator/state.h b/intern/cycles/kernel/integrator/state.h index 5f477a187b5..3d1938f8a3d 100644 --- a/intern/cycles/kernel/integrator/state.h +++ b/intern/cycles/kernel/integrator/state.h @@ -45,7 +45,7 @@ CCL_NAMESPACE_BEGIN /* Integrator State * * CPU rendering path state with AoS layout. */ -typedef struct IntegratorShadowStateCPU { +struct IntegratorShadowStateCPU { #define KERNEL_STRUCT_BEGIN(name) struct { #define KERNEL_STRUCT_BEGIN_PACKED(parent_struct, feature) struct { #define KERNEL_STRUCT_MEMBER(parent_struct, type, name, feature) type name; @@ -66,9 +66,9 @@ typedef struct IntegratorShadowStateCPU { #undef KERNEL_STRUCT_ARRAY_MEMBER #undef KERNEL_STRUCT_END #undef KERNEL_STRUCT_END_ARRAY -} IntegratorShadowStateCPU; +}; -typedef struct IntegratorStateCPU { +struct IntegratorStateCPU { #define KERNEL_STRUCT_BEGIN(name) struct { #define KERNEL_STRUCT_BEGIN_PACKED(parent_struct, feature) struct { #define KERNEL_STRUCT_MEMBER(parent_struct, type, name, feature) type name; @@ -93,15 +93,15 @@ typedef struct IntegratorStateCPU { IntegratorShadowStateCPU shadow; IntegratorShadowStateCPU ao; -} IntegratorStateCPU; +}; /* Path Queue * * Keep track of which kernels are queued to be executed next in the path * for GPU rendering. */ -typedef struct IntegratorQueueCounter { +struct IntegratorQueueCounter { int num_queued[DEVICE_KERNEL_INTEGRATOR_NUM]; -} IntegratorQueueCounter; +}; #if defined(__INTEGRATOR_GPU_PACKED_STATE__) && defined(__KERNEL_GPU__) @@ -138,7 +138,7 @@ typedef struct IntegratorQueueCounter { /* Integrator State GPU * * GPU rendering path state with SoA layout. */ -typedef struct IntegratorStateGPU { +struct IntegratorStateGPU { #define KERNEL_STRUCT_BEGIN(name) struct { #ifdef __INTEGRATOR_GPU_PACKED_STATE__ @@ -211,7 +211,7 @@ typedef struct IntegratorStateGPU { /* Divisor used to partition active indices by locality when sorting by material. */ uint sort_partition_divisor; -} IntegratorStateGPU; +}; /* Abstraction * @@ -225,10 +225,10 @@ typedef struct IntegratorStateGPU { /* Scalar access on CPU. */ -typedef IntegratorStateCPU *ccl_restrict IntegratorState; -typedef const IntegratorStateCPU *ccl_restrict ConstIntegratorState; -typedef IntegratorShadowStateCPU *ccl_restrict IntegratorShadowState; -typedef const IntegratorShadowStateCPU *ccl_restrict ConstIntegratorShadowState; +using IntegratorState = IntegratorStateCPU *; +using ConstIntegratorState = const IntegratorStateCPU *; +using IntegratorShadowState = IntegratorShadowStateCPU *; +using ConstIntegratorShadowState = const IntegratorShadowStateCPU *; # define INTEGRATOR_STATE_NULL nullptr @@ -244,10 +244,10 @@ typedef const IntegratorShadowStateCPU *ccl_restrict ConstIntegratorShadowState; /* Array access on GPU with Structure-of-Arrays. */ -typedef int IntegratorState; -typedef int ConstIntegratorState; -typedef int IntegratorShadowState; -typedef int ConstIntegratorShadowState; +using IntegratorState = int; +using ConstIntegratorState = int; +using IntegratorShadowState = int; +using ConstIntegratorShadowState = int; # define INTEGRATOR_STATE_NULL -1 diff --git a/intern/cycles/kernel/integrator/state_util.h b/intern/cycles/kernel/integrator/state_util.h index 6e6f99457f3..f63f3903052 100644 --- a/intern/cycles/kernel/integrator/state_util.h +++ b/intern/cycles/kernel/integrator/state_util.h @@ -453,54 +453,61 @@ ccl_device_inline IntegratorState integrator_state_shadow_catcher_split(KernelGl } #ifndef __KERNEL_GPU__ -ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const int) +ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const int /*unused*/) { return INTEGRATOR_STATE(state, path, bounce); } -ccl_device_inline int integrator_state_bounce(ConstIntegratorShadowState state, const int) +ccl_device_inline int integrator_state_bounce(ConstIntegratorShadowState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, shadow_path, bounce); } -ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, const int) +ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, path, diffuse_bounce); } -ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorShadowState state, const int) +ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorShadowState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, shadow_path, diffuse_bounce); } -ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, const int) +ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, path, glossy_bounce); } -ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorShadowState state, const int) +ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorShadowState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, shadow_path, glossy_bounce); } -ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, const int) +ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, path, transmission_bounce); } ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorShadowState state, - const int) + const int /*unused*/) { return INTEGRATOR_STATE(state, shadow_path, transmission_bounce); } -ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, const int) +ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, + const int /*unused*/) { return INTEGRATOR_STATE(state, path, transparent_bounce); } ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorShadowState state, - const int) + const int /*unused*/) { return INTEGRATOR_STATE(state, shadow_path, transparent_bounce); } diff --git a/intern/cycles/kernel/integrator/subsurface.h b/intern/cycles/kernel/integrator/subsurface.h index 2d6b5750699..6840a5a5194 100644 --- a/intern/cycles/kernel/integrator/subsurface.h +++ b/intern/cycles/kernel/integrator/subsurface.h @@ -4,14 +4,9 @@ #pragma once -#include "kernel/camera/projection.h" - -#include "kernel/bvh/bvh.h" - #include "kernel/closure/alloc.h" #include "kernel/closure/bsdf_diffuse.h" #include "kernel/closure/bssrdf.h" -#include "kernel/closure/volume.h" #include "kernel/integrator/intersect_volume_stack.h" #include "kernel/integrator/path_state.h" diff --git a/intern/cycles/kernel/integrator/subsurface_disk.h b/intern/cycles/kernel/integrator/subsurface_disk.h index fbad7388239..5b879bc2963 100644 --- a/intern/cycles/kernel/integrator/subsurface_disk.h +++ b/intern/cycles/kernel/integrator/subsurface_disk.h @@ -4,6 +4,8 @@ #include "kernel/bvh/bvh.h" +#include "kernel/closure/bssrdf.h" + #include "kernel/geom/object.h" #include "kernel/integrator/guiding.h" diff --git a/intern/cycles/kernel/integrator/subsurface_random_walk.h b/intern/cycles/kernel/integrator/subsurface_random_walk.h index 62ecd75430d..d87789cbfcc 100644 --- a/intern/cycles/kernel/integrator/subsurface_random_walk.h +++ b/intern/cycles/kernel/integrator/subsurface_random_walk.h @@ -4,6 +4,8 @@ #include "kernel/bvh/bvh.h" +#include "kernel/closure/volume.h" + #include "kernel/integrator/guiding.h" #include "kernel/integrator/path_state.h" @@ -420,7 +422,7 @@ ccl_device_inline bool subsurface_random_walk(KernelGlobals kg, /* If we hit the surface, we are done. */ break; } - else if (reduce_max(throughput) < VOLUME_THROUGHPUT_EPSILON) { + if (reduce_max(throughput) < VOLUME_THROUGHPUT_EPSILON) { /* Avoid unnecessary work and precision issue when throughput gets really small. */ break; } diff --git a/intern/cycles/kernel/integrator/surface_shader.h b/intern/cycles/kernel/integrator/surface_shader.h index 829ad24d67d..44b3a8cfaa7 100644 --- a/intern/cycles/kernel/integrator/surface_shader.h +++ b/intern/cycles/kernel/integrator/surface_shader.h @@ -953,12 +953,10 @@ ccl_device Spectrum surface_shader_transparency(KernelGlobals kg, ccl_private co if (sd->flag & SD_HAS_ONLY_VOLUME) { return one_spectrum(); } - else if (sd->flag & (SD_TRANSPARENT | SD_RAY_PORTAL)) { + if (sd->flag & (SD_TRANSPARENT | SD_RAY_PORTAL)) { return sd->closure_transparent_extinction; } - else { - return zero_spectrum(); - } + return zero_spectrum(); } ccl_device Spectrum surface_shader_alpha(KernelGlobals kg, ccl_private const ShaderData *sd) @@ -977,8 +975,9 @@ ccl_device Spectrum surface_shader_diffuse(KernelGlobals kg, ccl_private const S for (int i = 0; i < sd->num_closure; i++) { ccl_private const ShaderClosure *sc = &sd->closure[i]; - if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSSRDF(sc->type)) + if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSSRDF(sc->type)) { eval += bsdf_albedo(kg, sd, sc, true, true); + } } return eval; @@ -991,8 +990,9 @@ ccl_device Spectrum surface_shader_glossy(KernelGlobals kg, ccl_private const Sh for (int i = 0; i < sd->num_closure; i++) { ccl_private const ShaderClosure *sc = &sd->closure[i]; - if (CLOSURE_IS_BSDF_GLOSSY(sc->type) || CLOSURE_IS_GLASS(sc->type)) + if (CLOSURE_IS_BSDF_GLOSSY(sc->type) || CLOSURE_IS_GLASS(sc->type)) { eval += bsdf_albedo(kg, sd, sc, true, false); + } } return eval; @@ -1005,8 +1005,9 @@ ccl_device Spectrum surface_shader_transmission(KernelGlobals kg, ccl_private co for (int i = 0; i < sd->num_closure; i++) { ccl_private const ShaderClosure *sc = &sd->closure[i]; - if (CLOSURE_IS_BSDF_TRANSMISSION(sc->type) || CLOSURE_IS_GLASS(sc->type)) + if (CLOSURE_IS_BSDF_TRANSMISSION(sc->type) || CLOSURE_IS_GLASS(sc->type)) { eval += bsdf_albedo(kg, sd, sc, false, true); + } } return eval; @@ -1097,9 +1098,7 @@ ccl_device Spectrum surface_shader_background(ccl_private const ShaderData *sd) if (sd->flag & SD_EMISSION) { return sd->closure_emission_background; } - else { - return zero_spectrum(); - } + return zero_spectrum(); } /* Emission */ @@ -1109,9 +1108,7 @@ ccl_device Spectrum surface_shader_emission(ccl_private const ShaderData *sd) if (sd->flag & SD_EMISSION) { return emissive_simple_eval(sd->Ng, sd->wi) * sd->closure_emission_background; } - else { - return zero_spectrum(); - } + return zero_spectrum(); } /* Holdout */ diff --git a/intern/cycles/kernel/integrator/volume_shader.h b/intern/cycles/kernel/integrator/volume_shader.h index 7cb95670ced..b64b6aaef2c 100644 --- a/intern/cycles/kernel/integrator/volume_shader.h +++ b/intern/cycles/kernel/integrator/volume_shader.h @@ -6,6 +6,8 @@ #pragma once +#include "kernel/closure/volume.h" + #include "kernel/geom/attribute.h" #include "kernel/geom/shader_data.h" diff --git a/intern/cycles/kernel/integrator/volume_stack.h b/intern/cycles/kernel/integrator/volume_stack.h index 92482a93972..25b3663b67f 100644 --- a/intern/cycles/kernel/integrator/volume_stack.h +++ b/intern/cycles/kernel/integrator/volume_stack.h @@ -174,12 +174,12 @@ ccl_device float volume_stack_step_size(KernelGlobals kg, StackReadOp stack_read return step_size; } -typedef enum VolumeSampleMethod { +enum VolumeSampleMethod { VOLUME_SAMPLE_NONE = 0, VOLUME_SAMPLE_DISTANCE = (1 << 0), VOLUME_SAMPLE_EQUIANGULAR = (1 << 1), VOLUME_SAMPLE_MIS = (VOLUME_SAMPLE_DISTANCE | VOLUME_SAMPLE_EQUIANGULAR), -} VolumeSampleMethod; +}; ccl_device VolumeSampleMethod volume_stack_sample_method(KernelGlobals kg, IntegratorState state) { diff --git a/intern/cycles/kernel/light/area.h b/intern/cycles/kernel/light/area.h index f47213b5e82..22d4f88d748 100644 --- a/intern/cycles/kernel/light/area.h +++ b/intern/cycles/kernel/light/area.h @@ -94,9 +94,7 @@ ccl_device_inline float area_light_rect_sample(float3 P, const float t = len(dir); return -t * t * t / (z0 * len_u * len_v); } - else { - return 1.0f / S; - } + return 1.0f / S; } /* Light spread. */ diff --git a/intern/cycles/kernel/light/background.h b/intern/cycles/kernel/light/background.h index 97c957c5532..2ad2d514ec6 100644 --- a/intern/cycles/kernel/light/background.h +++ b/intern/cycles/kernel/light/background.h @@ -38,8 +38,9 @@ ccl_device float3 background_map_sample(KernelGlobals kg, float2 rand, ccl_priva first = middle + 1; count -= step + 1; } - else + else { count = step; + } } int index_v = max(0, first - 1); @@ -66,8 +67,9 @@ ccl_device float3 background_map_sample(KernelGlobals kg, float2 rand, ccl_priva first = middle + 1; count -= step + 1; } - else + else { count = step; + } } int index_u = max(0, first - 1); @@ -88,10 +90,12 @@ ccl_device float3 background_map_sample(KernelGlobals kg, float2 rand, ccl_priva float sin_theta = sinf(M_PI_F * v); float denom = (M_2PI_F * M_PI_F * sin_theta) * cdf_last_u.x * cdf_last_v.x; - if (sin_theta == 0.0f || denom == 0.0f) + if (sin_theta == 0.0f || denom == 0.0f) { *pdf = 0.0f; - else + } + else { *pdf = (cdf_u.x * cdf_v.x) / denom; + } /* compute direction */ return equirectangular_to_direction(u, v); @@ -109,8 +113,9 @@ ccl_device float background_map_pdf(KernelGlobals kg, float3 direction) float sin_theta = sinf(uv.y * M_PI_F); - if (sin_theta == 0.0f) + if (sin_theta == 0.0f) { return 0.0f; + } int index_u = clamp(float_to_int(uv.x * res_x), 0, res_x - 1); int index_v = clamp(float_to_int(uv.y * res_y), 0, res_y - 1); @@ -122,8 +127,9 @@ ccl_device float background_map_pdf(KernelGlobals kg, float3 direction) float denom = (M_2PI_F * M_PI_F * sin_theta) * cdf_last_u.x * cdf_last_v.x; - if (denom == 0.0f) + if (denom == 0.0f) { return 0.0f; + } /* pdfs in U direction */ float2 cdf_u = kernel_data_fetch(light_background_conditional_cdf, @@ -143,8 +149,9 @@ ccl_device_inline bool background_portal_data_fetch_and_check_side( *dir = klight->area.dir; /* Check whether portal is on the right side. */ - if (dot(*dir, P - *lightpos) > 1e-4f) + if (dot(*dir, P - *lightpos) > 1e-4f) { return true; + } return false; } @@ -156,12 +163,14 @@ ccl_device_inline float background_portal_pdf( int num_possible = 0; for (int p = 0; p < kernel_data.integrator.num_portals; p++) { - if (p == ignore_portal) + if (p == ignore_portal) { continue; + } float3 lightpos, dir; - if (!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) + if (!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) { continue; + } /* There's a portal that could be sampled from this position. */ if (is_possible) { @@ -194,7 +203,9 @@ ccl_device_inline float background_portal_pdf( nullptr, nullptr, is_round)) + { continue; + } if (is_round) { float t; @@ -220,8 +231,9 @@ ccl_device int background_num_possible_portals(KernelGlobals kg, float3 P) int num_possible_portals = 0; for (int p = 0; p < kernel_data.integrator.num_portals; p++) { float3 lightpos, dir; - if (background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) + if (background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) { num_possible_portals++; + } } return num_possible_portals; } @@ -244,8 +256,9 @@ ccl_device float3 background_portal_sample(KernelGlobals kg, for (int p = 0; p < kernel_data.integrator.num_portals; p++) { /* Search for the sampled portal. */ float3 lightpos, dir; - if (!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) + if (!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir)) { continue; + } if (portal == 0) { /* p is the portal to be sampled. */ diff --git a/intern/cycles/kernel/light/common.h b/intern/cycles/kernel/light/common.h index 46227154b0b..7f4d04fc73b 100644 --- a/intern/cycles/kernel/light/common.h +++ b/intern/cycles/kernel/light/common.h @@ -12,7 +12,7 @@ CCL_NAMESPACE_BEGIN /* Light Sample Result */ -typedef struct LightSample { +struct LightSample { float3 P; /* position on light, or direction for distant light */ packed_float3 Ng; /* normal on light */ float t; /* distance to light (FLT_MAX for distant light) */ @@ -28,7 +28,7 @@ typedef struct LightSample { int group; /* lightgroup */ LightType type; /* type of light */ int emitter_id; /* index in the emitter array */ -} LightSample; +}; /* Utilities */ @@ -56,8 +56,9 @@ ccl_device float light_pdf_area_to_solid_angle(const float3 Ng, const float3 I, { float cos_pi = dot(Ng, I); - if (cos_pi <= 0.0f) + if (cos_pi <= 0.0f) { return 0.0f; + } return t * t / cos_pi; } diff --git a/intern/cycles/kernel/light/distribution.h b/intern/cycles/kernel/light/distribution.h index d2547bad104..92808bdfcb3 100644 --- a/intern/cycles/kernel/light/distribution.h +++ b/intern/cycles/kernel/light/distribution.h @@ -6,8 +6,7 @@ #include "kernel/globals.h" -#include "kernel/light/light.h" -#include "kernel/light/triangle.h" +#include "kernel/light/common.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h index 2c5c1240a93..4595c4877ac 100644 --- a/intern/cycles/kernel/light/light.h +++ b/intern/cycles/kernel/light/light.h @@ -16,8 +16,6 @@ #include "kernel/light/triangle.h" #include "kernel/sample/lcg.h" -#include "kernel/sample/mapping.h" - CCL_NAMESPACE_BEGIN /* Light info. */ diff --git a/intern/cycles/kernel/light/point.h b/intern/cycles/kernel/light/point.h index 5ed5b2b7ee0..1f9a80f447c 100644 --- a/intern/cycles/kernel/light/point.h +++ b/intern/cycles/kernel/light/point.h @@ -142,12 +142,11 @@ ccl_device_inline bool point_light_intersect(const ccl_global KernelLight *kligh float3 P; return ray_sphere_intersect(ray->P, ray->D, ray->tmin, ray->tmax, klight->co, radius, &P, t); } - else { - float3 P; - const float3 diskN = normalize(ray->P - klight->co); - return ray_disk_intersect( - ray->P, ray->D, ray->tmin, ray->tmax, klight->co, diskN, radius, &P, t); - } + + float3 P; + const float3 diskN = normalize(ray->P - klight->co); + return ray_disk_intersect( + ray->P, ray->D, ray->tmin, ray->tmax, klight->co, diskN, radius, &P, t); } ccl_device_inline bool point_light_sample_from_intersection(const ccl_global KernelLight *klight, diff --git a/intern/cycles/kernel/light/spot.h b/intern/cycles/kernel/light/spot.h index 1d062e7e409..5c3340eba0e 100644 --- a/intern/cycles/kernel/light/spot.h +++ b/intern/cycles/kernel/light/spot.h @@ -5,7 +5,9 @@ #pragma once #include "kernel/light/common.h" +#include "kernel/light/point.h" +#include "util/math_fast.h" #include "util/math_intersect.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/light/tree.h b/intern/cycles/kernel/light/tree.h index 52a1af8b821..d4fa7ae9034 100644 --- a/intern/cycles/kernel/light/tree.h +++ b/intern/cycles/kernel/light/tree.h @@ -866,9 +866,7 @@ ccl_device float light_tree_pdf(KernelGlobals kg, bit_trail = kemitter->bit_trail; continue; } - else { - return pdf; - } + return pdf; } /* Inner node. */ diff --git a/intern/cycles/kernel/light/triangle.h b/intern/cycles/kernel/light/triangle.h index 897a73144e4..f66f9bc7c48 100644 --- a/intern/cycles/kernel/light/triangle.h +++ b/intern/cycles/kernel/light/triangle.h @@ -96,9 +96,7 @@ ccl_device_forceinline float triangle_light_pdf(KernelGlobals kg, if (UNLIKELY(solid_angle == 0.0f)) { return 0.0f; } - else { - pdf = 1.0f / solid_angle; - } + pdf = 1.0f / solid_angle; } else { if (UNLIKELY(area == 0.0f)) { @@ -231,9 +229,7 @@ ccl_device_forceinline bool triangle_light_sample(KernelGlobals kg, ls->pdf = 0.0f; return false; } - else { - ls->pdf = 1.0f / solid_angle; - } + ls->pdf = 1.0f / solid_angle; } else { if (UNLIKELY(area == 0.0f)) { diff --git a/intern/cycles/kernel/osl/closures_setup.h b/intern/cycles/kernel/osl/closures_setup.h index 195b2c97a7a..6019b5d2adb 100644 --- a/intern/cycles/kernel/osl/closures_setup.h +++ b/intern/cycles/kernel/osl/closures_setup.h @@ -9,7 +9,9 @@ #include "kernel/closure/alloc.h" #include "kernel/closure/bsdf.h" +#include "kernel/closure/bssrdf.h" #include "kernel/closure/emissive.h" +#include "kernel/closure/volume.h" #include "kernel/geom/object.h" diff --git a/intern/cycles/kernel/osl/compat.h b/intern/cycles/kernel/osl/compat.h index beeddd14370..a9fc52e8570 100644 --- a/intern/cycles/kernel/osl/compat.h +++ b/intern/cycles/kernel/osl/compat.h @@ -18,8 +18,8 @@ static inline OSL::ustring to_ustring(OSLUStringHash h) } #else -typedef OSL::ustring OSLUStringHash; -typedef OSL::ustring OSLUStringRep; +using OSLUStringHash = OSL::ustring; +using OSLUStringRep = OSL::ustring; static inline OSL::ustring to_ustring(OSLUStringHash h) { diff --git a/intern/cycles/kernel/osl/globals.cpp b/intern/cycles/kernel/osl/globals.cpp index 6f310e417ee..626036eb27d 100644 --- a/intern/cycles/kernel/osl/globals.cpp +++ b/intern/cycles/kernel/osl/globals.cpp @@ -40,8 +40,9 @@ void OSLGlobals::thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals, cons void OSLGlobals::thread_free(KernelGlobalsCPU *kg) { - if (!kg->osl) + if (!kg->osl) { return; + } OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss; OSLThreadData *tdata = kg->osl_tdata; diff --git a/intern/cycles/kernel/osl/globals.h b/intern/cycles/kernel/osl/globals.h index 363418f970e..3308603642c 100644 --- a/intern/cycles/kernel/osl/globals.h +++ b/intern/cycles/kernel/osl/globals.h @@ -42,7 +42,7 @@ struct OSLGlobals { /* per thread data */ static void thread_init(struct KernelGlobalsCPU *kg, OSLGlobals *osl_globals, - const int thread_init); + const int thread_index); static void thread_free(struct KernelGlobalsCPU *kg); bool use; @@ -60,7 +60,7 @@ struct OSLGlobals { OSL::ShaderGroupRef background_state; /* attributes */ - typedef unordered_map ObjectNameMap; + using ObjectNameMap = unordered_map; ObjectNameMap object_name_map; vector object_names; diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp index 6628ed3c7c9..e69d7b736b2 100644 --- a/intern/cycles/kernel/osl/services.cpp +++ b/intern/cycles/kernel/osl/services.cpp @@ -168,7 +168,7 @@ bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, return true; } - else if (sd->type == PRIMITIVE_LAMP) { + if (sd->type == PRIMITIVE_LAMP) { const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false); copy_matrix(result, tfm); @@ -208,7 +208,7 @@ bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, return true; } - else if (sd->type == PRIMITIVE_LAMP) { + if (sd->type == PRIMITIVE_LAMP) { const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true); copy_matrix(result, itfm); @@ -231,19 +231,19 @@ bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, copy_matrix(result, kernel_data.cam.ndctoworld); return true; } - else if (from == u_raster) { + if (from == u_raster) { copy_matrix(result, kernel_data.cam.rastertoworld); return true; } - else if (from == u_screen) { + if (from == u_screen) { copy_matrix(result, kernel_data.cam.screentoworld); return true; } - else if (from == u_camera) { + if (from == u_camera) { copy_matrix(result, kernel_data.cam.cameratoworld); return true; } - else if (from == u_world) { + if (from == u_world) { result.makeIdentity(); return true; } @@ -263,19 +263,19 @@ bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, copy_matrix(result, kernel_data.cam.worldtondc); return true; } - else if (to == u_raster) { + if (to == u_raster) { copy_matrix(result, kernel_data.cam.worldtoraster); return true; } - else if (to == u_screen) { + if (to == u_screen) { copy_matrix(result, kernel_data.cam.worldtoscreen); return true; } - else if (to == u_camera) { + if (to == u_camera) { copy_matrix(result, kernel_data.cam.worldtocamera); return true; } - else if (to == u_world) { + if (to == u_world) { result.makeIdentity(); return true; } @@ -300,7 +300,7 @@ bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, return true; } - else if (sd->type == PRIMITIVE_LAMP) { + if (sd->type == PRIMITIVE_LAMP) { const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false); copy_matrix(result, tfm); @@ -328,7 +328,7 @@ bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, return true; } - else if (sd->type == PRIMITIVE_LAMP) { + if (sd->type == PRIMITIVE_LAMP) { const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true); copy_matrix(result, itfm); @@ -350,15 +350,15 @@ bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, copy_matrix(result, kernel_data.cam.ndctoworld); return true; } - else if (from == u_raster) { + if (from == u_raster) { copy_matrix(result, kernel_data.cam.rastertoworld); return true; } - else if (from == u_screen) { + if (from == u_screen) { copy_matrix(result, kernel_data.cam.screentoworld); return true; } - else if (from == u_camera) { + if (from == u_camera) { copy_matrix(result, kernel_data.cam.cameratoworld); return true; } @@ -377,15 +377,15 @@ bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, copy_matrix(result, kernel_data.cam.worldtondc); return true; } - else if (to == u_raster) { + if (to == u_raster) { copy_matrix(result, kernel_data.cam.worldtoraster); return true; } - else if (to == u_screen) { + if (to == u_screen) { copy_matrix(result, kernel_data.cam.worldtoscreen); return true; } - else if (to == u_camera) { + if (to == u_camera) { copy_matrix(result, kernel_data.cam.worldtocamera); return true; } @@ -426,7 +426,7 @@ static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, v } return true; } - else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { + if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { float *fval = (float *)val; fval[0] = f[0].x; @@ -445,7 +445,7 @@ static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, v return true; } - else if (type == TypeFloat) { + if (type == TypeFloat) { float *fval = (float *)val; fval[0] = average(f[0]); @@ -495,7 +495,7 @@ static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, v } return true; } - else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { + if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { float *fval = (float *)val; fval[0] = f[0].x; @@ -514,7 +514,7 @@ static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, v return true; } - else if (type == TypeFloat) { + if (type == TypeFloat) { float *fval = (float *)val; fval[0] = average(f[0]); @@ -570,7 +570,7 @@ static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, v } return true; } - else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { + if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { fval[0] = f[0].x; fval[1] = f[0].y; fval[2] = f[0].z; @@ -586,7 +586,7 @@ static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, v } return true; } - else if (type == TypeFloat) { + if (type == TypeFloat) { fval[0] = average(make_float3(f[0])); if (derivatives) { @@ -611,7 +611,7 @@ static bool set_attribute_float4(float4 f, TypeDesc type, bool derivatives, void } #endif -static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val) +static bool set_attribute_float(const float f[3], TypeDesc type, bool derivatives, void *val) { if (type == TypeFloatArray4) { float *fval = (float *)val; @@ -633,7 +633,7 @@ static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, voi } return true; } - else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { + if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) { float *fval = (float *)val; fval[0] = f[0]; fval[1] = f[0]; @@ -651,7 +651,7 @@ static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, voi return true; } - else if (type == TypeFloat) { + if (type == TypeFloat) { float *fval = (float *)val; fval[0] = f[0]; @@ -775,22 +775,20 @@ static bool get_object_attribute(const KernelGlobalsCPU *kg, } return set_attribute_float3(fval, type, derivatives, val); } - else if (desc.type == NODE_ATTR_FLOAT2) { + if (desc.type == NODE_ATTR_FLOAT2) { #ifdef __VOLUME__ if (primitive_is_volume_attribute(sd, desc)) { assert(!"Float2 attribute not support for volumes"); return false; } - else + #endif - { - float2 fval[3]; - fval[0] = primitive_surface_attribute_float2( - kg, sd, desc, (derivatives) ? &fval[1] : nullptr, (derivatives) ? &fval[2] : nullptr); - return set_attribute_float2(fval, type, derivatives, val); - } + float2 fval[3]; + fval[0] = primitive_surface_attribute_float2( + kg, sd, desc, (derivatives) ? &fval[1] : nullptr, (derivatives) ? &fval[2] : nullptr); + return set_attribute_float2(fval, type, derivatives, val); } - else if (desc.type == NODE_ATTR_FLOAT) { + if (desc.type == NODE_ATTR_FLOAT) { float fval[3]; #ifdef __VOLUME__ if (primitive_is_volume_attribute(sd, desc)) { @@ -805,7 +803,7 @@ static bool get_object_attribute(const KernelGlobalsCPU *kg, } return set_attribute_float(fval, type, derivatives, val); } - else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) { + if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) { float4 fval[3]; #ifdef __VOLUME__ if (primitive_is_volume_attribute(sd, desc)) { @@ -820,13 +818,11 @@ static bool get_object_attribute(const KernelGlobalsCPU *kg, } return set_attribute_float4(fval, type, derivatives, val); } - else if (desc.type == NODE_ATTR_MATRIX) { + if (desc.type == NODE_ATTR_MATRIX) { Transform tfm = primitive_attribute_matrix(kg, desc); return set_attribute_matrix(tfm, type, val); } - else { - return false; - } + return false; } bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg, @@ -843,95 +839,94 @@ bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg float3 f = object_location(kg, sd); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_object_color) { + if (name == u_object_color) { float3 f = object_color(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_object_alpha) { + if (name == u_object_alpha) { float f = object_alpha(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_object_index) { + if (name == u_object_index) { float f = object_pass_id(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_object_is_light) { + if (name == u_object_is_light) { float f = (sd->type & PRIMITIVE_LAMP) != 0; return set_attribute_float(f, type, derivatives, val); } - else if (name == u_geom_dupli_generated) { + if (name == u_geom_dupli_generated) { float3 f = object_dupli_generated(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_geom_dupli_uv) { + if (name == u_geom_dupli_uv) { float3 f = object_dupli_uv(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_material_index) { + if (name == u_material_index) { float f = shader_pass_id(kg, sd); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_object_random) { + if (name == u_object_random) { float f = object_random_number(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } /* Particle Attributes */ - else if (name == u_particle_index) { + if (name == u_particle_index) { int particle_id = object_particle_id(kg, sd->object); float f = particle_index(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_particle_random) { + if (name == u_particle_random) { int particle_id = object_particle_id(kg, sd->object); float f = hash_uint2_to_float(particle_index(kg, particle_id), 0); return set_attribute_float(f, type, derivatives, val); } - - else if (name == u_particle_age) { + if (name == u_particle_age) { int particle_id = object_particle_id(kg, sd->object); float f = particle_age(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_particle_lifetime) { + if (name == u_particle_lifetime) { int particle_id = object_particle_id(kg, sd->object); float f = particle_lifetime(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_particle_location) { + if (name == u_particle_location) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_location(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } #if 0 /* unsupported */ - else if (name == u_particle_rotation) { + if (name == u_particle_rotation) { int particle_id = object_particle_id(kg, sd->object); float4 f = particle_rotation(kg, particle_id); return set_attribute_float4(f, type, derivatives, val); } #endif - else if (name == u_particle_size) { + if (name == u_particle_size) { int particle_id = object_particle_id(kg, sd->object); float f = particle_size(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_particle_velocity) { + if (name == u_particle_velocity) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_particle_angular_velocity) { + if (name == u_particle_angular_velocity) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_angular_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } /* Geometry Attributes */ - else if (name == u_geom_numpolyvertices) { + if (name == u_geom_numpolyvertices) { return set_attribute_int(3, type, derivatives, val); } - else if ((name == u_geom_trianglevertices || name == u_geom_polyvertices) && - sd->type & PRIMITIVE_TRIANGLE) + if ((name == u_geom_trianglevertices || name == u_geom_polyvertices) && + sd->type & PRIMITIVE_TRIANGLE) { float3 P[3]; @@ -950,64 +945,60 @@ bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg return set_attribute_float3_3(P, type, derivatives, val); } - else if (name == u_geom_name) { + if (name == u_geom_name) { ustring object_name = kg->osl->object_names[sd->object]; return set_attribute_string(object_name, type, derivatives, val); } - else if (name == u_is_smooth) { + if (name == u_is_smooth) { float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0); return set_attribute_float(f, type, derivatives, val); } #ifdef __HAIR__ /* Hair Attributes */ - else if (name == u_is_curve) { + if (name == u_is_curve) { float f = (sd->type & PRIMITIVE_CURVE) != 0; return set_attribute_float(f, type, derivatives, val); } - else if (name == u_curve_thickness) { + if (name == u_curve_thickness) { float f = curve_thickness(kg, sd); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_curve_tangent_normal) { + if (name == u_curve_tangent_normal) { float3 f = curve_tangent_normal(kg, sd); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_curve_random) { + if (name == u_curve_random) { float f = curve_random(kg, sd); return set_attribute_float(f, type, derivatives, val); } #endif #ifdef __POINTCLOUD__ /* point attributes */ - else if (name == u_is_point) { + if (name == u_is_point) { float f = (sd->type & PRIMITIVE_POINT) != 0; return set_attribute_float(f, type, derivatives, val); } - else if (name == u_point_radius) { + if (name == u_point_radius) { float f = point_radius(kg, sd); return set_attribute_float(f, type, derivatives, val); } - else if (name == u_point_position) { + if (name == u_point_position) { float3 f = point_position(kg, sd); return set_attribute_float3(f, type, derivatives, val); } - else if (name == u_point_random) { + if (name == u_point_random) { float f = point_random(kg, sd); return set_attribute_float(f, type, derivatives, val); } #endif - else if (name == u_normal_map_normal) { + if (name == u_normal_map_normal) { if (sd->type & PRIMITIVE_TRIANGLE) { float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v); return set_attribute_float3(f, type, derivatives, val); } - else { - return false; - } - } - else { - return get_background_attribute(kg, sd, name, type, derivatives, val); + return false; } + return get_background_attribute(kg, sd, name, type, derivatives, val); } bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, @@ -1022,14 +1013,14 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, float f = sd->ray_length; return set_attribute_float(f, type, derivatives, val); } - else if (name == u_path_ray_depth) { + if (name == u_path_ray_depth) { /* Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; int f = (state) ? state->path.bounce : (shadow_state) ? shadow_state->shadow_path.bounce : 0; return set_attribute_int(f, type, derivatives, val); } - else if (name == u_path_diffuse_depth) { + if (name == u_path_diffuse_depth) { /* Diffuse Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; @@ -1038,7 +1029,7 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, 0; return set_attribute_int(f, type, derivatives, val); } - else if (name == u_path_glossy_depth) { + if (name == u_path_glossy_depth) { /* Glossy Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; @@ -1047,7 +1038,7 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, 0; return set_attribute_int(f, type, derivatives, val); } - else if (name == u_path_transmission_depth) { + if (name == u_path_transmission_depth) { /* Transmission Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; @@ -1056,7 +1047,7 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, 0; return set_attribute_int(f, type, derivatives, val); } - else if (name == u_path_transparent_depth) { + if (name == u_path_transparent_depth) { /* Transparent Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; @@ -1065,7 +1056,7 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, 0; return set_attribute_int(f, type, derivatives, val); } - else if (name == u_ndc) { + if (name == u_ndc) { /* NDC coordinates with special exception for orthographic projection. */ OSLThreadData *tdata = kg->osl_tdata; OSL::ShaderGlobals *globals = &tdata->globals; @@ -1093,9 +1084,8 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, return set_attribute_float3(ndc, type, derivatives, val); } - else { - return false; - } + + return false; } bool OSLRenderServices::get_attribute(OSL::ShaderGlobals *sg, @@ -1143,10 +1133,9 @@ bool OSLRenderServices::get_attribute(ShaderData *sd, if (desc.offset != ATTR_STD_NOT_FOUND) { return get_object_attribute(kg, sd, desc, type, derivatives, val); } - else { - /* not found in attribute, check standard object info */ - return get_object_standard_attribute(kg, sd, name, type, derivatives, val); - } + + /* not found in attribute, check standard object info */ + return get_object_standard_attribute(kg, sd, name, type, derivatives, val); } bool OSLRenderServices::get_userdata( @@ -1254,9 +1243,7 @@ bool OSLRenderServices::good(OSL::TextureSystem::TextureHandle *texture_handle) OSL::TextureSystem *ts = m_texturesys; return ts->good(handle->oiio_handle); } - else { - return true; - } + return true; } bool OSLRenderServices::texture(OSLUStringHash filename, @@ -1622,12 +1609,12 @@ bool OSLRenderServices::environment(OSLUStringHash filename, bool OSLRenderServices::get_texture_info(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - OSL::ShaderGlobals *, + OSL::ShaderGlobals * /*sg*/, int subimage, OSLUStringHash dataname, TypeDesc datatype, void *data, - OSLUStringHash *) + OSLUStringHash * /*errormessage*/) #elif OSL_LIBRARY_VERSION_CODE >= 11100 bool OSLRenderServices::get_texture_info(OSLUStringHash filename, TextureHandle *texture_handle, @@ -1662,12 +1649,10 @@ bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *, return ts->get_texture_info( handle->oiio_handle, texture_thread_info, subimage, to_ustring(dataname), datatype, data); } - else + #endif - { - return ts->get_texture_info( - to_ustring(filename), subimage, to_ustring(dataname), datatype, data); - } + return ts->get_texture_info( + to_ustring(filename), subimage, to_ustring(dataname), datatype, data); } int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, @@ -1787,48 +1772,47 @@ bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg, if (name == u_hit) { return set_attribute_int(tracedata->hit, type, derivatives, val); } - else if (tracedata->hit) { + if (tracedata->hit) { if (name == u_hitdist) { float f[3] = {tracedata->isect.t, 0.0f, 0.0f}; return set_attribute_float(f, type, derivatives, val); } - else { - ShaderData *sd = &tracedata->sd; - const KernelGlobalsCPU *kg = sd->osl_globals; - if (!tracedata->setup) { - /* lazy shader data setup */ - shader_setup_from_ray(kg, sd, &tracedata->ray, &tracedata->isect); - tracedata->setup = true; - } + ShaderData *sd = &tracedata->sd; + const KernelGlobalsCPU *kg = sd->osl_globals; - if (name == u_N) { - return set_attribute_float3(sd->N, type, derivatives, val); - } - else if (name == u_Ng) { - return set_attribute_float3(sd->Ng, type, derivatives, val); - } - else if (name == u_P) { - const differential3 dP = differential_from_compact(sd->Ng, sd->dP); - float3 f[3] = {sd->P, dP.dx, dP.dy}; - return set_attribute_float3(f, type, derivatives, val); - } - else if (name == u_I) { - const differential3 dI = differential_from_compact(sd->wi, sd->dI); - float3 f[3] = {sd->wi, dI.dx, dI.dy}; - return set_attribute_float3(f, type, derivatives, val); - } - else if (name == u_u) { - float f[3] = {sd->u, sd->du.dx, sd->du.dy}; - return set_attribute_float(f, type, derivatives, val); - } - else if (name == u_v) { - float f[3] = {sd->v, sd->dv.dx, sd->dv.dy}; - return set_attribute_float(f, type, derivatives, val); - } - - return get_attribute(sd, derivatives, u_empty, type, name, val); + if (!tracedata->setup) { + /* lazy shader data setup */ + shader_setup_from_ray(kg, sd, &tracedata->ray, &tracedata->isect); + tracedata->setup = true; } + + if (name == u_N) { + return set_attribute_float3(sd->N, type, derivatives, val); + } + if (name == u_Ng) { + return set_attribute_float3(sd->Ng, type, derivatives, val); + } + if (name == u_P) { + const differential3 dP = differential_from_compact(sd->Ng, sd->dP); + float3 f[3] = {sd->P, dP.dx, dP.dy}; + return set_attribute_float3(f, type, derivatives, val); + } + if (name == u_I) { + const differential3 dI = differential_from_compact(sd->wi, sd->dI); + float3 f[3] = {sd->wi, dI.dx, dI.dy}; + return set_attribute_float3(f, type, derivatives, val); + } + if (name == u_u) { + float f[3] = {sd->u, sd->du.dx, sd->du.dy}; + return set_attribute_float(f, type, derivatives, val); + } + if (name == u_v) { + float f[3] = {sd->v, sd->dv.dx, sd->dv.dy}; + return set_attribute_float(f, type, derivatives, val); + } + + return get_attribute(sd, derivatives, u_empty, type, name, val); } } diff --git a/intern/cycles/kernel/osl/services.h b/intern/cycles/kernel/osl/services.h index 2b6ee1d705a..25cf98c07e6 100644 --- a/intern/cycles/kernel/osl/services.h +++ b/intern/cycles/kernel/osl/services.h @@ -50,10 +50,7 @@ struct KernelGlobalsCPU; struct OSLTextureHandle : public OIIO::RefCnt { enum Type { OIIO, SVM, IES, BEVEL, AO }; - OSLTextureHandle(Type type, const vector &svm_slots) - : type(type), svm_slots(svm_slots), oiio_handle(nullptr), processor(nullptr) - { - } + OSLTextureHandle(Type type, const vector &svm_slots) : type(type), svm_slots(svm_slots) {} OSLTextureHandle(Type type = OIIO, int svm_slot = -1) : OSLTextureHandle(type, {make_int4(0, svm_slot, -1, -1)}) @@ -61,23 +58,19 @@ struct OSLTextureHandle : public OIIO::RefCnt { } OSLTextureHandle(const ImageHandle &handle) - : type(SVM), - svm_slots(handle.get_svm_slots()), - oiio_handle(nullptr), - processor(nullptr), - handle(handle) + : type(SVM), svm_slots(handle.get_svm_slots()), handle(handle) { } Type type; vector svm_slots; - OSL::TextureSystem::TextureHandle *oiio_handle; - ColorSpaceProcessor *processor; + OSL::TextureSystem::TextureHandle *oiio_handle = nullptr; + ColorSpaceProcessor *processor = nullptr; ImageHandle handle; }; -typedef OIIO::intrusive_ptr OSLTextureHandleRef; -typedef OIIO::unordered_map_concurrent OSLTextureHandleMap; +using OSLTextureHandleRef = OIIO::intrusive_ptr; +using OSLTextureHandleMap = OIIO::unordered_map_concurrent; /* OSL Render Services * @@ -86,7 +79,7 @@ typedef OIIO::unordered_map_concurrent OSLT class OSLRenderServices : public OSL::RendererServices { public: OSLRenderServices(OSL::TextureSystem *texture_system, int device_type); - ~OSLRenderServices(); + ~OSLRenderServices() override; static void register_closures(OSL::ShadingSystem *ss); @@ -120,7 +113,7 @@ class OSLRenderServices : public OSL::RendererServices { bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSLUStringHash from) override; bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, - OSLUStringHash from) override; + OSLUStringHash to) override; bool get_array_attribute(OSL::ShaderGlobals *sg, bool derivatives, diff --git a/intern/cycles/kernel/osl/types.h b/intern/cycles/kernel/osl/types.h index 64dbf516f4e..58ac53f96bb 100644 --- a/intern/cycles/kernel/osl/types.h +++ b/intern/cycles/kernel/osl/types.h @@ -15,11 +15,11 @@ CCL_NAMESPACE_BEGIN #if defined(__KERNEL_GPU__) /* Strings are represented by their hashes on the GPU. */ -typedef size_t DeviceString; +using DeviceString = size_t; #elif defined(OPENIMAGEIO_USTRING_H) -typedef ustring DeviceString; +using DeviceString = ustring; #else -typedef const char *DeviceString; +using DeviceString = const char *; #endif ccl_device_inline DeviceString make_string(const char *str, size_t hash) diff --git a/intern/cycles/kernel/sample/mapping.h b/intern/cycles/kernel/sample/mapping.h index 52b4561150b..fe95c3ec07a 100644 --- a/intern/cycles/kernel/sample/mapping.h +++ b/intern/cycles/kernel/sample/mapping.h @@ -23,7 +23,8 @@ ccl_device float2 sample_uniform_disk(const float2 rand) if (a == 0.0f && b == 0.0f) { return zero_float2(); } - else if (a * a > b * b) { + + if (a * a > b * b) { r = a; phi = M_PI_4_F * (b / a); } diff --git a/intern/cycles/kernel/sample/pattern.h b/intern/cycles/kernel/sample/pattern.h index d8790ae9a3d..3e51f168311 100644 --- a/intern/cycles/kernel/sample/pattern.h +++ b/intern/cycles/kernel/sample/pattern.h @@ -5,7 +5,6 @@ #pragma once #include "kernel/globals.h" -#include "kernel/tables.h" #include "kernel/sample/sobol_burley.h" #include "kernel/sample/tabulated_sobol.h" @@ -38,7 +37,7 @@ ccl_device_forceinline uint3 blue_noise_indexing(KernelGlobals kg, uint pixel_in /* One sequence per pixel, using the length mask optimization. */ return make_uint3(sample, pixel_index, kernel_data.integrator.sobol_index_mask); } - else if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_BLUE_NOISE_PURE) { + if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_BLUE_NOISE_PURE) { /* For blue-noise samples, we use a single sequence (seed 0) with each pixel receiving * a section of it. * The total length is expected to get very large (effectively pixel count times sample count), @@ -46,7 +45,7 @@ ccl_device_forceinline uint3 blue_noise_indexing(KernelGlobals kg, uint pixel_in pixel_index *= kernel_data.integrator.blue_noise_sequence_length; return make_uint3(sample + pixel_index, 0, 0xffffffff); } - else if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_BLUE_NOISE_FIRST) { + if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_BLUE_NOISE_FIRST) { /* The "first" pattern uses a 1SPP blue-noise sequence for the first sample, and a separate * N-1 SPP sequence for the remaining pixels. The purpose of this is to get blue-noise * properties during viewport navigation, which will generally use 1 SPP. @@ -55,15 +54,11 @@ ccl_device_forceinline uint3 blue_noise_indexing(KernelGlobals kg, uint pixel_in if (sample == 0) { return make_uint3(pixel_index, 0x0cd0519f, 0xffffffff); } - else { - pixel_index *= kernel_data.integrator.blue_noise_sequence_length; - return make_uint3((sample - 1) + pixel_index, 0, 0xffffffff); - } - } - else { - kernel_assert(false); - return make_uint3(0, 0, 0); + pixel_index *= kernel_data.integrator.blue_noise_sequence_length; + return make_uint3((sample - 1) + pixel_index, 0, 0xffffffff); } + kernel_assert(false); + return make_uint3(0, 0, 0); } ccl_device_forceinline float path_rng_1D(KernelGlobals kg, @@ -150,19 +145,18 @@ ccl_device_inline uint path_rng_pixel_init(KernelGlobals kg, /* The white-noise samplers use a random per-pixel hash to generate independent sequences. */ return hash_iqnt2d(x, y) ^ kernel_data.integrator.seed; } - else { - /* The blue-noise samplers use a single sequence for all pixels, but offset the index within - * the sequence for each pixel. We use a hierarchically shuffled 2D morton curve to determine - * each pixel's offset along the sequence. - * - * Based on: - * https://psychopath.io/post/2022_07_24_owen_scrambling_based_dithered_blue_noise_sampling. - * - * TODO(lukas): Use a precomputed Hilbert curve to avoid directionality bias in the noise - * distribution. We can just precompute a small-ish tile and repeat it in morton code order. - */ - return nested_uniform_scramble_base4(morton2d(x, y), kernel_data.integrator.seed); - } + + /* The blue-noise samplers use a single sequence for all pixels, but offset the index within + * the sequence for each pixel. We use a hierarchically shuffled 2D morton curve to determine + * each pixel's offset along the sequence. + * + * Based on: + * https://psychopath.io/post/2022_07_24_owen_scrambling_based_dithered_blue_noise_sampling. + * + * TODO(lukas): Use a precomputed Hilbert curve to avoid directionality bias in the noise + * distribution. We can just precompute a small-ish tile and repeat it in morton code order. + */ + return nested_uniform_scramble_base4(morton2d(x, y), kernel_data.integrator.seed); } /** diff --git a/intern/cycles/kernel/svm/aov.h b/intern/cycles/kernel/svm/aov.h index 31b232b0672..5901e4a6275 100644 --- a/intern/cycles/kernel/svm/aov.h +++ b/intern/cycles/kernel/svm/aov.h @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN ccl_device_inline bool svm_node_aov_check(const uint32_t path_flag, - ccl_global float *render_buffer) + ccl_global const float *render_buffer) { bool is_primary = (path_flag & PATH_RAY_TRANSPARENT_BACKGROUND) && (!(path_flag & PATH_RAY_SINGLE_PASS_DONE)); diff --git a/intern/cycles/kernel/svm/bevel.h b/intern/cycles/kernel/svm/bevel.h index ce8e9eaf33e..380f409682f 100644 --- a/intern/cycles/kernel/svm/bevel.h +++ b/intern/cycles/kernel/svm/bevel.h @@ -7,15 +7,11 @@ #include "kernel/bvh/bvh.h" #include "kernel/geom/motion_triangle.h" -#include "kernel/geom/motion_triangle_shader.h" #include "kernel/geom/triangle.h" #include "kernel/geom/triangle_intersect.h" #include "kernel/integrator/path_state.h" -#include "kernel/sample/mapping.h" -#include "kernel/sample/pattern.h" - #include "kernel/svm/util.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/svm/brick.h b/intern/cycles/kernel/svm/brick.h index 892e9e41801..75cb5ad38b8 100644 --- a/intern/cycles/kernel/svm/brick.h +++ b/intern/cycles/kernel/svm/brick.h @@ -121,10 +121,12 @@ ccl_device_noinline int svm_node_tex_brick( color1 = facm * color1 + tint * color2; } - if (stack_valid(color_offset)) + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, color1 * (1.0f - f) + mortar * f); - if (stack_valid(fac_offset)) + } + if (stack_valid(fac_offset)) { stack_store_float(stack, fac_offset, f); + } return offset; } diff --git a/intern/cycles/kernel/svm/brightness.h b/intern/cycles/kernel/svm/brightness.h index d3d532c5972..35b03f49d29 100644 --- a/intern/cycles/kernel/svm/brightness.h +++ b/intern/cycles/kernel/svm/brightness.h @@ -21,8 +21,9 @@ ccl_device_noinline void svm_node_brightness( color = svm_brightness_contrast(color, brightness, contrast); - if (stack_valid(out_color)) + if (stack_valid(out_color)) { stack_store_float3(stack, out_color, color); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/checker.h b/intern/cycles/kernel/svm/checker.h index 78230c381bd..96daad175fe 100644 --- a/intern/cycles/kernel/svm/checker.h +++ b/intern/cycles/kernel/svm/checker.h @@ -42,10 +42,12 @@ ccl_device_noinline void svm_node_tex_checker(KernelGlobals kg, float f = svm_checker(co * scale); - if (stack_valid(color_offset)) + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, (f == 1.0f) ? color1 : color2); - if (stack_valid(fac_offset)) + } + if (stack_valid(fac_offset)) { stack_store_float(stack, fac_offset, f); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h index 97393660d81..93d4c9ce133 100644 --- a/intern/cycles/kernel/svm/closure.h +++ b/intern/cycles/kernel/svm/closure.h @@ -7,7 +7,9 @@ #include "kernel/closure/alloc.h" #include "kernel/closure/bsdf.h" #include "kernel/closure/bsdf_util.h" +#include "kernel/closure/bssrdf.h" #include "kernel/closure/emissive.h" +#include "kernel/closure/volume.h" #include "kernel/geom/curve.h" #include "kernel/geom/object.h" @@ -185,8 +187,9 @@ ccl_device float aspect = sqrtf(1.0f - anisotropic * 0.9f); alpha_x /= aspect; alpha_y *= aspect; - if (anisotropic_rotation != 0.0f) + if (anisotropic_rotation != 0.0f) { T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F); + } } #ifdef __CAUSTICS_TRICKS__ @@ -488,8 +491,9 @@ ccl_device case CLOSURE_BSDF_PHYSICAL_CONDUCTOR: case CLOSURE_BSDF_F82_CONDUCTOR: { #ifdef __CAUSTICS_TRICKS__ - if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) + if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) { break; + } #endif ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc( sd, sizeof(MicrofacetBsdf), rgb_to_spectrum(make_float3(mix_weight))); @@ -568,8 +572,9 @@ ccl_device case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID: case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: { #ifdef __CAUSTICS_TRICKS__ - if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) + if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) { break; + } #endif Spectrum weight = closure_weight * mix_weight; ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc( @@ -633,8 +638,9 @@ ccl_device case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID: case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID: { #ifdef __CAUSTICS_TRICKS__ - if (!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE)) + if (!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE)) { break; + } #endif Spectrum weight = closure_weight * mix_weight; ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc( @@ -671,8 +677,9 @@ ccl_device (path_flag & PATH_RAY_DIFFUSE) == 0); const bool refractive_caustics = (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0); - if (!(reflective_caustics || refractive_caustics)) + if (!(reflective_caustics || refractive_caustics)) { break; + } #else const bool reflective_caustics = true; const bool refractive_caustics = true; @@ -742,8 +749,9 @@ ccl_device } case CLOSURE_BSDF_GLOSSY_TOON_ID: #ifdef __CAUSTICS_TRICKS__ - if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) + if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) { break; + } ATTR_FALLTHROUGH; #endif case CLOSURE_BSDF_DIFFUSE_TOON_ID: { @@ -955,8 +963,9 @@ ccl_device bsdf->T = normalize(sd->dPdv); bsdf->offset = 0.0f; } - else + else { bsdf->T = normalize(sd->dPdu); + } if (type == CLOSURE_BSDF_HAIR_REFLECTION_ID) { sd->flag |= bsdf_hair_reflection_setup(bsdf); @@ -1336,10 +1345,12 @@ ccl_device_noinline void svm_node_mix_closure(ccl_private ShaderData *sd, float in_weight = (stack_valid(in_weight_offset)) ? stack_load_float(stack, in_weight_offset) : 1.0f; - if (stack_valid(weight1_offset)) + if (stack_valid(weight1_offset)) { stack_store_float(stack, weight1_offset, in_weight * (1.0f - weight)); - if (stack_valid(weight2_offset)) + } + if (stack_valid(weight2_offset)) { stack_store_float(stack, weight2_offset, in_weight * weight); + } } /* (Bump) normal */ diff --git a/intern/cycles/kernel/svm/color_util.h b/intern/cycles/kernel/svm/color_util.h index e46b02cb63c..80728343fe5 100644 --- a/intern/cycles/kernel/svm/color_util.h +++ b/intern/cycles/kernel/svm/color_util.h @@ -40,20 +40,26 @@ ccl_device float3 svm_mix_overlay(float t, float3 col1, float3 col2) float3 outcol = col1; - if (outcol.x < 0.5f) + if (outcol.x < 0.5f) { outcol.x *= tm + 2.0f * t * col2.x; - else + } + else { outcol.x = 1.0f - (tm + 2.0f * t * (1.0f - col2.x)) * (1.0f - outcol.x); + } - if (outcol.y < 0.5f) + if (outcol.y < 0.5f) { outcol.y *= tm + 2.0f * t * col2.y; - else + } + else { outcol.y = 1.0f - (tm + 2.0f * t * (1.0f - col2.y)) * (1.0f - outcol.y); + } - if (outcol.z < 0.5f) + if (outcol.z < 0.5f) { outcol.z *= tm + 2.0f * t * col2.z; - else + } + else { outcol.z = 1.0f - (tm + 2.0f * t * (1.0f - col2.z)) * (1.0f - outcol.z); + } return outcol; } @@ -69,12 +75,15 @@ ccl_device float3 svm_mix_div(float t, float3 col1, float3 col2) float3 outcol = col1; - if (col2.x != 0.0f) + if (col2.x != 0.0f) { outcol.x = tm * outcol.x + t * outcol.x / col2.x; - if (col2.y != 0.0f) + } + if (col2.y != 0.0f) { outcol.y = tm * outcol.y + t * outcol.y / col2.y; - if (col2.z != 0.0f) + } + if (col2.z != 0.0f) { outcol.z = tm * outcol.z + t * outcol.z / col2.z; + } return outcol; } @@ -105,30 +114,48 @@ ccl_device float3 svm_mix_dodge(float t, float3 col1, float3 col2) if (outcol.x != 0.0f) { float tmp = 1.0f - t * col2.x; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.x = 1.0f; - else if ((tmp = outcol.x / tmp) > 1.0f) - outcol.x = 1.0f; - else - outcol.x = tmp; + } + else { + tmp = outcol.x / tmp; + if (tmp > 1.0f) { + outcol.x = 1.0f; + } + else { + outcol.x = tmp; + } + } } if (outcol.y != 0.0f) { float tmp = 1.0f - t * col2.y; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.y = 1.0f; - else if ((tmp = outcol.y / tmp) > 1.0f) - outcol.y = 1.0f; - else - outcol.y = tmp; + } + else { + tmp = outcol.y / tmp; + if (tmp > 1.0f) { + outcol.y = 1.0f; + } + else { + outcol.y = tmp; + } + } } if (outcol.z != 0.0f) { float tmp = 1.0f - t * col2.z; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.z = 1.0f; - else if ((tmp = outcol.z / tmp) > 1.0f) - outcol.z = 1.0f; - else - outcol.z = tmp; + } + else { + tmp = outcol.z / tmp; + if (tmp > 1.0f) { + outcol.z = 1.0f; + } + else { + outcol.z = tmp; + } + } } return outcol; @@ -141,34 +168,55 @@ ccl_device float3 svm_mix_burn(float t, float3 col1, float3 col2) float3 outcol = col1; tmp = tm + t * col2.x; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.x = 0.0f; - else if ((tmp = (1.0f - (1.0f - outcol.x) / tmp)) < 0.0f) - outcol.x = 0.0f; - else if (tmp > 1.0f) - outcol.x = 1.0f; - else - outcol.x = tmp; + } + else { + tmp = (1.0f - (1.0f - outcol.x) / tmp); + if (tmp < 0.0f) { + outcol.x = 0.0f; + } + else if (tmp > 1.0f) { + outcol.x = 1.0f; + } + else { + outcol.x = tmp; + } + } tmp = tm + t * col2.y; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.y = 0.0f; - else if ((tmp = (1.0f - (1.0f - outcol.y) / tmp)) < 0.0f) - outcol.y = 0.0f; - else if (tmp > 1.0f) - outcol.y = 1.0f; - else - outcol.y = tmp; + } + else { + tmp = (1.0f - (1.0f - outcol.y) / tmp); + if (tmp < 0.0f) { + outcol.y = 0.0f; + } + else if (tmp > 1.0f) { + outcol.y = 1.0f; + } + else { + outcol.y = tmp; + } + } tmp = tm + t * col2.z; - if (tmp <= 0.0f) + if (tmp <= 0.0f) { outcol.z = 0.0f; - else if ((tmp = (1.0f - (1.0f - outcol.z) / tmp)) < 0.0f) - outcol.z = 0.0f; - else if (tmp > 1.0f) - outcol.z = 1.0f; - else - outcol.z = tmp; + } + else { + tmp = (1.0f - (1.0f - outcol.z) / tmp); + if (tmp < 0.0f) { + outcol.z = 0.0f; + } + else if (tmp > 1.0f) { + outcol.z = 1.0f; + } + else { + outcol.z = tmp; + } + } return outcol; } diff --git a/intern/cycles/kernel/svm/displace.h b/intern/cycles/kernel/svm/displace.h index c9dcc2675e4..8ecd817b175 100644 --- a/intern/cycles/kernel/svm/displace.h +++ b/intern/cycles/kernel/svm/displace.h @@ -72,8 +72,9 @@ ccl_device_noinline void svm_node_set_bump(KernelGlobals kg, float strength = stack_load_float(stack, strength_offset); float scale = stack_load_float(stack, scale_offset); - if (invert) + if (invert) { scale *= -1.0f; + } strength = max(strength, 0.0f); diff --git a/intern/cycles/kernel/svm/fractal_noise.h b/intern/cycles/kernel/svm/fractal_noise.h index 4699038c920..99502b826ab 100644 --- a/intern/cycles/kernel/svm/fractal_noise.h +++ b/intern/cycles/kernel/svm/fractal_noise.h @@ -5,7 +5,6 @@ #pragma once #include "kernel/svm/noise.h" -#include "kernel/svm/util.h" CCL_NAMESPACE_BEGIN @@ -33,9 +32,7 @@ ccl_device_noinline float noise_fbm( return normalize ? mix(0.5f * sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) : mix(sum, sum2, rmd); } - else { - return normalize ? 0.5f * sum / maxamp + 0.5f : sum; - } + return normalize ? 0.5f * sum / maxamp + 0.5f : sum; } ccl_device_noinline float noise_fbm( @@ -60,9 +57,7 @@ ccl_device_noinline float noise_fbm( return normalize ? mix(0.5f * sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) : mix(sum, sum2, rmd); } - else { - return normalize ? 0.5f * sum / maxamp + 0.5f : sum; - } + return normalize ? 0.5f * sum / maxamp + 0.5f : sum; } ccl_device_noinline float noise_fbm( @@ -87,9 +82,7 @@ ccl_device_noinline float noise_fbm( return normalize ? mix(0.5f * sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) : mix(sum, sum2, rmd); } - else { - return normalize ? 0.5f * sum / maxamp + 0.5f : sum; - } + return normalize ? 0.5f * sum / maxamp + 0.5f : sum; } ccl_device_noinline float noise_fbm( @@ -114,9 +107,7 @@ ccl_device_noinline float noise_fbm( return normalize ? mix(0.5f * sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) : mix(sum, sum2, rmd); } - else { - return normalize ? 0.5f * sum / maxamp + 0.5f : sum; - } + return normalize ? 0.5f * sum / maxamp + 0.5f : sum; } /* Multifractal */ @@ -321,9 +312,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float weight = 1.0f; for (int i = 0; (weight > 0.001f) && (i <= float_to_int(detail)); i++) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_1d(p) + offset) * pwr; pwr *= roughness; @@ -334,9 +323,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float rmd = detail - floorf(detail); if ((rmd != 0.0f) && (weight > 0.001f)) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_1d(p) + offset) * pwr; value += rmd * weight * signal; } @@ -352,9 +339,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float weight = 1.0f; for (int i = 0; (weight > 0.001f) && (i <= float_to_int(detail)); i++) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_2d(p) + offset) * pwr; pwr *= roughness; @@ -365,9 +350,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float rmd = detail - floorf(detail); if ((rmd != 0.0f) && (weight > 0.001f)) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_2d(p) + offset) * pwr; value += rmd * weight * signal; } @@ -383,9 +366,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float weight = 1.0f; for (int i = 0; (weight > 0.001f) && (i <= float_to_int(detail)); i++) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_3d(p) + offset) * pwr; pwr *= roughness; @@ -396,9 +377,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float rmd = detail - floorf(detail); if ((rmd != 0.0f) && (weight > 0.001f)) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_3d(p) + offset) * pwr; value += rmd * weight * signal; } @@ -414,9 +393,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float weight = 1.0f; for (int i = 0; (weight > 0.001f) && (i <= float_to_int(detail)); i++) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_4d(p) + offset) * pwr; pwr *= roughness; @@ -427,9 +404,7 @@ ccl_device_noinline float noise_hybrid_multi_fractal( float rmd = detail - floorf(detail); if ((rmd != 0.0f) && (weight > 0.001f)) { - if (weight > 1.0f) { - weight = 1.0f; - } + weight = fminf(weight, 1.0f); float signal = (snoise_4d(p) + offset) * pwr; value += rmd * weight * signal; } diff --git a/intern/cycles/kernel/svm/gabor.h b/intern/cycles/kernel/svm/gabor.h index 1b2772b375c..c36dba2b55a 100644 --- a/intern/cycles/kernel/svm/gabor.h +++ b/intern/cycles/kernel/svm/gabor.h @@ -32,7 +32,7 @@ CCL_NAMESPACE_BEGIN * are sampled using a Bernoulli distribution, as shown in Figure (3). By stratified sampling, they * mean a constant number of impulses per cell, so the stratification is the grid itself in that * sense, as described in the supplementary material of the paper. */ -#define IMPULSES_COUNT 8 +#define IMPULSES_COUNT 8 // NOLINT /* Computes a 2D Gabor kernel based on Equation (6) in the original Gabor noise paper. Where the * frequency argument is the F_0 parameter and the orientation argument is the w_0 parameter. We diff --git a/intern/cycles/kernel/svm/gradient.h b/intern/cycles/kernel/svm/gradient.h index bcc6e62c10b..792b8238990 100644 --- a/intern/cycles/kernel/svm/gradient.h +++ b/intern/cycles/kernel/svm/gradient.h @@ -21,34 +21,33 @@ ccl_device float svm_gradient(float3 p, NodeGradientType type) if (type == NODE_BLEND_LINEAR) { return x; } - else if (type == NODE_BLEND_QUADRATIC) { + if (type == NODE_BLEND_QUADRATIC) { float r = fmaxf(x, 0.0f); return r * r; } - else if (type == NODE_BLEND_EASING) { + if (type == NODE_BLEND_EASING) { float r = fminf(fmaxf(x, 0.0f), 1.0f); float t = r * r; return (3.0f * t - 2.0f * t * r); } - else if (type == NODE_BLEND_DIAGONAL) { + if (type == NODE_BLEND_DIAGONAL) { return (x + y) * 0.5f; } - else if (type == NODE_BLEND_RADIAL) { + if (type == NODE_BLEND_RADIAL) { return atan2f(y, x) / M_2PI_F + 0.5f; } - else { - /* Bias a little bit for the case where p is a unit length vector, - * to get exactly zero instead of a small random value depending - * on float precision. */ - float r = fmaxf(0.999999f - sqrtf(x * x + y * y + z * z), 0.0f); - if (type == NODE_BLEND_QUADRATIC_SPHERE) { - return r * r; - } - else if (type == NODE_BLEND_SPHERICAL) { - return r; - } + /* Bias a little bit for the case where p is a unit length vector, + * to get exactly zero instead of a small random value depending + * on float precision. */ + float r = fmaxf(0.999999f - sqrtf(x * x + y * y + z * z), 0.0f); + + if (type == NODE_BLEND_QUADRATIC_SPHERE) { + return r * r; + } + if (type == NODE_BLEND_SPHERICAL) { + return r; } return 0.0f; @@ -67,10 +66,12 @@ ccl_device_noinline void svm_node_tex_gradient(ccl_private ShaderData *sd, float f = svm_gradient(co, (NodeGradientType)type); f = saturatef(f); - if (stack_valid(fac_offset)) + if (stack_valid(fac_offset)) { stack_store_float(stack, fac_offset, f); - if (stack_valid(color_offset)) + } + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, make_float3(f, f, f)); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/hsv.h b/intern/cycles/kernel/svm/hsv.h index 2d85bc294e5..fc6f2646a82 100644 --- a/intern/cycles/kernel/svm/hsv.h +++ b/intern/cycles/kernel/svm/hsv.h @@ -45,8 +45,9 @@ ccl_device_noinline void svm_node_hsv(KernelGlobals kg, color.y = max(color.y, 0.0f); color.z = max(color.z, 0.0f); - if (stack_valid(out_color_offset)) + if (stack_valid(out_color_offset)) { stack_store_float3(stack, out_color_offset, color); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/ies.h b/intern/cycles/kernel/svm/ies.h index c15fa0bbedf..c03edded271 100644 --- a/intern/cycles/kernel/svm/ies.h +++ b/intern/cycles/kernel/svm/ies.h @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_ies(KernelGlobals kg, - ccl_private ShaderData *sd, + ccl_private ShaderData * /*sd*/, ccl_private float *stack, uint4 node) { diff --git a/intern/cycles/kernel/svm/image.h b/intern/cycles/kernel/svm/image.h index aa0929c0f0c..7c45c0dc387 100644 --- a/intern/cycles/kernel/svm/image.h +++ b/intern/cycles/kernel/svm/image.h @@ -45,8 +45,11 @@ ccl_device_inline float3 texco_remap_square(float3 co) return (co - make_float3(0.5f, 0.5f, 0.5f)) * 2.0f; } -ccl_device_noinline int svm_node_tex_image( - KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset) +ccl_device_noinline int svm_node_tex_image(KernelGlobals kg, + ccl_private ShaderData * /*sd*/, + ccl_private float *stack, + uint4 node, + int offset) { uint co_offset, out_offset, alpha_offset, flags; @@ -111,10 +114,12 @@ ccl_device_noinline int svm_node_tex_image( float4 f = svm_image_texture(kg, id, tex_co.x, tex_co.y, flags); - if (stack_valid(out_offset)) + if (stack_valid(out_offset)) { stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); - if (stack_valid(alpha_offset)) + } + if (stack_valid(alpha_offset)) { stack_store_float(stack, alpha_offset, f.w); + } return offset; } @@ -214,14 +219,16 @@ ccl_device_noinline void svm_node_tex_image_box(KernelGlobals kg, f += weight.z * svm_image_texture(kg, id, uv.x, uv.y, flags); } - if (stack_valid(out_offset)) + if (stack_valid(out_offset)) { stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); - if (stack_valid(alpha_offset)) + } + if (stack_valid(alpha_offset)) { stack_store_float(stack, alpha_offset, f.w); + } } ccl_device_noinline void svm_node_tex_environment(KernelGlobals kg, - ccl_private ShaderData *sd, + ccl_private ShaderData * /*sd*/, ccl_private float *stack, uint4 node) { @@ -236,17 +243,21 @@ ccl_device_noinline void svm_node_tex_environment(KernelGlobals kg, co = safe_normalize(co); - if (projection == 0) + if (projection == 0) { uv = direction_to_equirectangular(co); - else + } + else { uv = direction_to_mirrorball(co); + } float4 f = svm_image_texture(kg, id, uv.x, uv.y, flags); - if (stack_valid(out_offset)) + if (stack_valid(out_offset)) { stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); - if (stack_valid(alpha_offset)) + } + if (stack_valid(alpha_offset)) { stack_store_float(stack, alpha_offset, f.w); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/magic.h b/intern/cycles/kernel/svm/magic.h index c094726f143..1598ef57086 100644 --- a/intern/cycles/kernel/svm/magic.h +++ b/intern/cycles/kernel/svm/magic.h @@ -111,10 +111,12 @@ ccl_device_noinline int svm_node_tex_magic( float3 color = svm_magic(co, scale, depth, distortion); - if (stack_valid(fac_offset)) + if (stack_valid(fac_offset)) { stack_store_float(stack, fac_offset, average(color)); - if (stack_valid(color_offset)) + } + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, color); + } return offset; } diff --git a/intern/cycles/kernel/svm/mapping_util.h b/intern/cycles/kernel/svm/mapping_util.h index 050f1294469..54395909905 100644 --- a/intern/cycles/kernel/svm/mapping_util.h +++ b/intern/cycles/kernel/svm/mapping_util.h @@ -4,7 +4,11 @@ #pragma once -#include "kernel/svm/util.h" +#include "kernel/svm/types.h" + +#include "util/math.h" +#include "util/transform.h" +#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/svm/math.h b/intern/cycles/kernel/svm/math.h index c616187754a..ff979850fc9 100644 --- a/intern/cycles/kernel/svm/math.h +++ b/intern/cycles/kernel/svm/math.h @@ -59,10 +59,12 @@ ccl_device_noinline int svm_node_vector_math(KernelGlobals kg, svm_vector_math(&value, &vector, (NodeVectorMathType)type, a, b, c, param1); - if (stack_valid(value_stack_offset)) + if (stack_valid(value_stack_offset)) { stack_store_float(stack, value_stack_offset, value); - if (stack_valid(vector_stack_offset)) + } + if (stack_valid(vector_stack_offset)) { stack_store_float3(stack, vector_stack_offset, vector); + } return offset; } diff --git a/intern/cycles/kernel/svm/math_util.h b/intern/cycles/kernel/svm/math_util.h index 692c6383270..06145dc16bd 100644 --- a/intern/cycles/kernel/svm/math_util.h +++ b/intern/cycles/kernel/svm/math_util.h @@ -4,10 +4,11 @@ #pragma once -#include "kernel/tables.h" -#include "kernel/types.h" - #include "kernel/svm/types.h" +#include "kernel/tables.h" + +#include "util/math.h" +#include "util/types.h" CCL_NAMESPACE_BEGIN @@ -208,7 +209,7 @@ ccl_device float3 svm_math_blackbody_color_rec709(float t) if (t >= 12000.0f) { return make_float3(0.8262954810464208f, 0.9945080501520986f, 1.566307710274283f); } - else if (t < 800.0f) { + if (t < 800.0f) { /* Arbitrary lower limit where light is very dim, matching OSL. */ return make_float3(5.413294490189271f, -0.20319390035873933f, -0.0822535242887164f); } @@ -233,15 +234,19 @@ ccl_device float3 svm_math_blackbody_color_rec709(float t) ccl_device_inline float3 svm_math_gamma_color(float3 color, float gamma) { - if (gamma == 0.0f) + if (gamma == 0.0f) { return make_float3(1.0f, 1.0f, 1.0f); + } - if (color.x > 0.0f) + if (color.x > 0.0f) { color.x = powf(color.x, gamma); - if (color.y > 0.0f) + } + if (color.y > 0.0f) { color.y = powf(color.y, gamma); - if (color.z > 0.0f) + } + if (color.z > 0.0f) { color.z = powf(color.z, gamma); + } return color; } diff --git a/intern/cycles/kernel/svm/noise.h b/intern/cycles/kernel/svm/noise.h index 8617ad3374d..431c1536b34 100644 --- a/intern/cycles/kernel/svm/noise.h +++ b/intern/cycles/kernel/svm/noise.h @@ -7,9 +7,9 @@ #pragma once -#include "kernel/types.h" - #include "util/hash.h" +#include "util/math.h" +#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/svm/ramp.h b/intern/cycles/kernel/svm/ramp.h index d95f523efd8..d542ac8428a 100644 --- a/intern/cycles/kernel/svm/ramp.h +++ b/intern/cycles/kernel/svm/ramp.h @@ -42,8 +42,9 @@ ccl_device_inline float float_ramp_lookup( float a = fetch_float(kg, offset + i); - if (interpolate && t > 0.0f) + if (interpolate && t > 0.0f) { a = (1.0f - t) * a + t * fetch_float(kg, offset + i + 1); + } return a; } @@ -74,8 +75,9 @@ ccl_device_inline float4 rgb_ramp_lookup( float4 a = fetch_node_float(kg, offset + i); - if (interpolate && t > 0.0f) + if (interpolate && t > 0.0f) { a = (1.0f - t) * a + t * fetch_node_float(kg, offset + i + 1); + } return a; } @@ -93,10 +95,12 @@ ccl_device_noinline int svm_node_rgb_ramp( float fac = stack_load_float(stack, fac_offset); float4 color = rgb_ramp_lookup(kg, offset, fac, interpolate, false, table_size); - if (stack_valid(color_offset)) + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, make_float3(color)); - if (stack_valid(alpha_offset)) + } + if (stack_valid(alpha_offset)) { stack_store_float(stack, alpha_offset, color.w); + } offset += table_size; return offset; diff --git a/intern/cycles/kernel/svm/ramp_util.h b/intern/cycles/kernel/svm/ramp_util.h index 76d58ecebf4..56c51f995a6 100644 --- a/intern/cycles/kernel/svm/ramp_util.h +++ b/intern/cycles/kernel/svm/ramp_util.h @@ -4,7 +4,8 @@ #pragma once -#include "kernel/types.h" +#include "util/math.h" +#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/svm/sepcomb_color.h b/intern/cycles/kernel/svm/sepcomb_color.h index 22652340a7d..e99a6283056 100644 --- a/intern/cycles/kernel/svm/sepcomb_color.h +++ b/intern/cycles/kernel/svm/sepcomb_color.h @@ -48,12 +48,15 @@ ccl_device_noinline void svm_node_separate_color(KernelGlobals kg, svm_unpack_node_uchar3( results_stack_offsets, &red_stack_offset, &green_stack_offset, &blue_stack_offset); - if (stack_valid(red_stack_offset)) + if (stack_valid(red_stack_offset)) { stack_store_float(stack, red_stack_offset, color.x); - if (stack_valid(green_stack_offset)) + } + if (stack_valid(green_stack_offset)) { stack_store_float(stack, green_stack_offset, color.y); - if (stack_valid(blue_stack_offset)) + } + if (stack_valid(blue_stack_offset)) { stack_store_float(stack, blue_stack_offset, color.z); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/sepcomb_hsv.h b/intern/cycles/kernel/svm/sepcomb_hsv.h index 1afe6d281c6..053537d8c16 100644 --- a/intern/cycles/kernel/svm/sepcomb_hsv.h +++ b/intern/cycles/kernel/svm/sepcomb_hsv.h @@ -50,12 +50,15 @@ ccl_device_noinline int svm_node_separate_hsv(KernelGlobals kg, /* Convert to HSV */ color = rgb_to_hsv(color); - if (stack_valid(hue_out)) + if (stack_valid(hue_out)) { stack_store_float(stack, hue_out, color.x); - if (stack_valid(saturation_out)) + } + if (stack_valid(saturation_out)) { stack_store_float(stack, saturation_out, color.y); - if (stack_valid(value_out)) + } + if (stack_valid(value_out)) { stack_store_float(stack, value_out, color.z); + } return offset; } diff --git a/intern/cycles/kernel/svm/sky.h b/intern/cycles/kernel/svm/sky.h index 97b02ee6aed..16b2cadffcb 100644 --- a/intern/cycles/kernel/svm/sky.h +++ b/intern/cycles/kernel/svm/sky.h @@ -26,7 +26,7 @@ ccl_device float sky_angle_between(float thetav, float phiv, float theta, float * "A Practical Analytic Model for Daylight" * A. J. Preetham, Peter Shirley, Brian Smits */ -ccl_device float sky_perez_function(ccl_private float *lam, float theta, float gamma) +ccl_device float sky_perez_function(ccl_private const float *lam, float theta, float gamma) { float ctheta = cosf(theta); float cgamma = cosf(gamma); @@ -71,7 +71,9 @@ ccl_device float3 sky_radiance_preetham(KernelGlobals kg, * "An Analytic Model for Full Spectral Sky-Dome Radiance" * Lukas Hosek, Alexander Wilkie */ -ccl_device float sky_radiance_internal(ccl_private float *configuration, float theta, float gamma) +ccl_device float sky_radiance_internal(ccl_private const float *configuration, + float theta, + float gamma) { float ctheta = cosf(theta); float cgamma = cosf(gamma); @@ -130,7 +132,7 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals kg, uint32_t path_flag, float3 pixel_bottom, float3 pixel_top, - ccl_private float *nishita_data, + ccl_private const float *nishita_data, uint texture_id) { /* definitions */ diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 8a4f149c9ac..997705cbc01 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -107,7 +107,7 @@ ccl_device void svm_eval_nodes(KernelGlobals kg, Spectrum closure_weight; int offset = sd->shader & SHADER_MASK; - while (1) { + while (true) { uint4 node = read_node(kg, &offset); switch (node.x) { diff --git a/intern/cycles/kernel/svm/tex_coord.h b/intern/cycles/kernel/svm/tex_coord.h index d884b6cb229..7effb8190f8 100644 --- a/intern/cycles/kernel/svm/tex_coord.h +++ b/intern/cycles/kernel/svm/tex_coord.h @@ -52,26 +52,33 @@ ccl_device_noinline int svm_node_tex_coord(KernelGlobals kg, case NODE_TEXCO_CAMERA: { Transform tfm = kernel_data.cam.worldtocamera; - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = transform_point(&tfm, sd->P); - else + } + else { data = transform_point(&tfm, sd->P + camera_position(kg)); + } break; } case NODE_TEXCO_WINDOW: { if ((path_flag & PATH_RAY_CAMERA) && sd->object == OBJECT_NONE && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) + { data = camera_world_to_ndc(kg, sd, sd->ray_P); - else + } + else { data = camera_world_to_ndc(kg, sd, sd->P); + } data.z = 0.0f; break; } case NODE_TEXCO_REFLECTION: { - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = 2.0f * dot(sd->N, sd->wi) * sd->N - sd->wi; - else + } + else { data = sd->wi; + } break; } case NODE_TEXCO_DUPLI_GENERATED: { @@ -86,8 +93,9 @@ ccl_device_noinline int svm_node_tex_coord(KernelGlobals kg, data = sd->P; #ifdef __VOLUME__ - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = volume_normalized_position(kg, sd, data); + } #endif break; } @@ -134,26 +142,33 @@ ccl_device_noinline int svm_node_tex_coord_bump_dx(KernelGlobals kg, case NODE_TEXCO_CAMERA: { Transform tfm = kernel_data.cam.worldtocamera; - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = transform_point(&tfm, svm_node_bump_P_dx(sd)); - else + } + else { data = transform_point(&tfm, svm_node_bump_P_dx(sd) + camera_position(kg)); + } break; } case NODE_TEXCO_WINDOW: { if ((path_flag & PATH_RAY_CAMERA) && sd->object == OBJECT_NONE && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) + { data = camera_world_to_ndc(kg, sd, sd->ray_P); - else + } + else { data = camera_world_to_ndc(kg, sd, svm_node_bump_P_dx(sd)); + } data.z = 0.0f; break; } case NODE_TEXCO_REFLECTION: { - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = 2.0f * dot(sd->N, sd->wi) * sd->N - sd->wi; - else + } + else { data = sd->wi; + } break; } case NODE_TEXCO_DUPLI_GENERATED: { @@ -168,8 +183,9 @@ ccl_device_noinline int svm_node_tex_coord_bump_dx(KernelGlobals kg, data = svm_node_bump_P_dx(sd); # ifdef __VOLUME__ - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = volume_normalized_position(kg, sd, data); + } # endif break; } @@ -219,26 +235,33 @@ ccl_device_noinline int svm_node_tex_coord_bump_dy(KernelGlobals kg, case NODE_TEXCO_CAMERA: { Transform tfm = kernel_data.cam.worldtocamera; - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = transform_point(&tfm, svm_node_bump_P_dy(sd)); - else + } + else { data = transform_point(&tfm, svm_node_bump_P_dy(sd) + camera_position(kg)); + } break; } case NODE_TEXCO_WINDOW: { if ((path_flag & PATH_RAY_CAMERA) && sd->object == OBJECT_NONE && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) + { data = camera_world_to_ndc(kg, sd, sd->ray_P); - else + } + else { data = camera_world_to_ndc(kg, sd, svm_node_bump_P_dy(sd)); + } data.z = 0.0f; break; } case NODE_TEXCO_REFLECTION: { - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = 2.0f * dot(sd->N, sd->wi) * sd->N - sd->wi; - else + } + else { data = sd->wi; + } break; } case NODE_TEXCO_DUPLI_GENERATED: { @@ -253,8 +276,9 @@ ccl_device_noinline int svm_node_tex_coord_bump_dy(KernelGlobals kg, data = svm_node_bump_P_dy(sd); # ifdef __VOLUME__ - if (sd->object != OBJECT_NONE) + if (sd->object != OBJECT_NONE) { data = volume_normalized_position(kg, sd, data); + } # endif break; } @@ -399,25 +423,28 @@ ccl_device_noinline void svm_node_tangent(KernelGlobals kg, stack_store_float3(stack, tangent_offset, zero_float3()); return; } - else { - tangent = attribute_value; - } + tangent = attribute_value; } else { /* radial */ float3 generated; - if (desc.offset == ATTR_STD_NOT_FOUND) + if (desc.offset == ATTR_STD_NOT_FOUND) { generated = sd->P; - else + } + else { generated = attribute_value; + } - if (axis == NODE_TANGENT_AXIS_X) + if (axis == NODE_TANGENT_AXIS_X) { tangent = make_float3(0.0f, -(generated.z - 0.5f), (generated.y - 0.5f)); - else if (axis == NODE_TANGENT_AXIS_Y) + } + else if (axis == NODE_TANGENT_AXIS_Y) { tangent = make_float3(-(generated.z - 0.5f), 0.0f, (generated.x - 0.5f)); - else + } + else { tangent = make_float3(-(generated.y - 0.5f), (generated.x - 0.5f), 0.0f); + } } object_normal_transform(kg, sd, &tangent); diff --git a/intern/cycles/kernel/svm/types.h b/intern/cycles/kernel/svm/types.h index 271afbc8251..fec90fbd9ae 100644 --- a/intern/cycles/kernel/svm/types.h +++ b/intern/cycles/kernel/svm/types.h @@ -8,82 +8,84 @@ CCL_NAMESPACE_BEGIN /* Stack */ +// NOLINTBEGIN /* SVM stack has a fixed size */ #define SVM_STACK_SIZE 255 /* SVM stack offsets with this value indicate that it's not on the stack */ #define SVM_STACK_INVALID 255 #define SVM_BUMP_EVAL_STATE_SIZE 10 +// NOLINTEND /* Nodes */ -typedef enum ShaderNodeType { +enum ShaderNodeType { #define SHADER_NODE_TYPE(name) name, #include "node_types_template.h" NODE_NUM -} ShaderNodeType; +}; -typedef enum NodeAttributeOutputType { +enum NodeAttributeOutputType { NODE_ATTR_OUTPUT_FLOAT3 = 0, NODE_ATTR_OUTPUT_FLOAT, NODE_ATTR_OUTPUT_FLOAT_ALPHA, -} NodeAttributeOutputType; +}; -typedef enum NodeAttributeType { +enum NodeAttributeType { NODE_ATTR_FLOAT = 0, NODE_ATTR_FLOAT2, NODE_ATTR_FLOAT3, NODE_ATTR_FLOAT4, NODE_ATTR_RGBA, NODE_ATTR_MATRIX -} NodeAttributeType; +}; -typedef enum NodeGeometry { +enum NodeGeometry { NODE_GEOM_P = 0, NODE_GEOM_N, NODE_GEOM_T, NODE_GEOM_I, NODE_GEOM_Ng, NODE_GEOM_uv -} NodeGeometry; +}; -typedef enum NodeObjectInfo { +enum NodeObjectInfo { NODE_INFO_OB_LOCATION, NODE_INFO_OB_COLOR, NODE_INFO_OB_ALPHA, NODE_INFO_OB_INDEX, NODE_INFO_MAT_INDEX, NODE_INFO_OB_RANDOM -} NodeObjectInfo; +}; -typedef enum NodeParticleInfo { +enum NodeParticleInfo { NODE_INFO_PAR_INDEX, NODE_INFO_PAR_RANDOM, NODE_INFO_PAR_AGE, NODE_INFO_PAR_LIFETIME, NODE_INFO_PAR_LOCATION, - NODE_INFO_PAR_ROTATION, + // NODE_INFO_PAR_ROTATION, NODE_INFO_PAR_SIZE, NODE_INFO_PAR_VELOCITY, NODE_INFO_PAR_ANGULAR_VELOCITY -} NodeParticleInfo; +}; -typedef enum NodeHairInfo { +enum NodeHairInfo { NODE_INFO_CURVE_IS_STRAND, NODE_INFO_CURVE_INTERCEPT, NODE_INFO_CURVE_LENGTH, NODE_INFO_CURVE_THICKNESS, NODE_INFO_CURVE_TANGENT_NORMAL, NODE_INFO_CURVE_RANDOM, -} NodeHairInfo; +}; -typedef enum NodePointInfo { +enum NodePointInfo { NODE_INFO_POINT_POSITION, NODE_INFO_POINT_RADIUS, NODE_INFO_POINT_RANDOM, -} NodePointInfo; +}; -typedef enum NodeLightPath { +enum NodeLightPath { NODE_LP_camera = 0, NODE_LP_shadow, NODE_LP_diffuse, @@ -99,15 +101,15 @@ typedef enum NodeLightPath { NODE_LP_ray_glossy, NODE_LP_ray_transparent, NODE_LP_ray_transmission, -} NodeLightPath; +}; -typedef enum NodeLightFalloff { +enum NodeLightFalloff { NODE_LIGHT_FALLOFF_QUADRATIC, NODE_LIGHT_FALLOFF_LINEAR, NODE_LIGHT_FALLOFF_CONSTANT -} NodeLightFalloff; +}; -typedef enum NodeTexCoord { +enum NodeTexCoord { NODE_TEXCO_NORMAL, NODE_TEXCO_OBJECT, NODE_TEXCO_CAMERA, @@ -116,9 +118,9 @@ typedef enum NodeTexCoord { NODE_TEXCO_DUPLI_GENERATED, NODE_TEXCO_DUPLI_UV, NODE_TEXCO_VOLUME_GENERATED -} NodeTexCoord; +}; -typedef enum NodeMix { +enum NodeMix { NODE_MIX_BLEND = 0, NODE_MIX_ADD, NODE_MIX_MUL, @@ -139,9 +141,9 @@ typedef enum NodeMix { NODE_MIX_LINEAR, NODE_MIX_EXCLUSION, NODE_MIX_CLAMP /* used for the clamp UI option */ -} NodeMix; +}; -typedef enum NodeMathType { +enum NodeMathType { NODE_MATH_ADD, NODE_MATH_SUBTRACT, NODE_MATH_MULTIPLY, @@ -183,9 +185,9 @@ typedef enum NodeMathType { NODE_MATH_SMOOTH_MIN, NODE_MATH_SMOOTH_MAX, NODE_MATH_FLOORED_MODULO, -} NodeMathType; +}; -typedef enum NodeVectorMathType { +enum NodeVectorMathType { NODE_VECTOR_MATH_ADD, NODE_VECTOR_MATH_SUBTRACT, NODE_VECTOR_MATH_MULTIPLY, @@ -216,48 +218,48 @@ typedef enum NodeVectorMathType { NODE_VECTOR_MATH_REFRACT, NODE_VECTOR_MATH_FACEFORWARD, NODE_VECTOR_MATH_MULTIPLY_ADD, -} NodeVectorMathType; +}; -typedef enum NodeClampType { +enum NodeClampType { NODE_CLAMP_MINMAX, NODE_CLAMP_RANGE, -} NodeClampType; +}; -typedef enum NodeMapRangeType { +enum NodeMapRangeType { NODE_MAP_RANGE_LINEAR, NODE_MAP_RANGE_STEPPED, NODE_MAP_RANGE_SMOOTHSTEP, NODE_MAP_RANGE_SMOOTHERSTEP, -} NodeMapRangeType; +}; -typedef enum NodeMappingType { +enum NodeMappingType { NODE_MAPPING_TYPE_POINT, NODE_MAPPING_TYPE_TEXTURE, NODE_MAPPING_TYPE_VECTOR, NODE_MAPPING_TYPE_NORMAL -} NodeMappingType; +}; -typedef enum NodeVectorRotateType { +enum NodeVectorRotateType { NODE_VECTOR_ROTATE_TYPE_AXIS, NODE_VECTOR_ROTATE_TYPE_AXIS_X, NODE_VECTOR_ROTATE_TYPE_AXIS_Y, NODE_VECTOR_ROTATE_TYPE_AXIS_Z, NODE_VECTOR_ROTATE_TYPE_EULER_XYZ, -} NodeVectorRotateType; +}; -typedef enum NodeVectorTransformType { +enum NodeVectorTransformType { NODE_VECTOR_TRANSFORM_TYPE_VECTOR, NODE_VECTOR_TRANSFORM_TYPE_POINT, NODE_VECTOR_TRANSFORM_TYPE_NORMAL -} NodeVectorTransformType; +}; -typedef enum NodeVectorTransformConvertSpace { +enum NodeVectorTransformConvertSpace { NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA -} NodeVectorTransformConvertSpace; +}; -typedef enum NodeConvert { +enum NodeConvert { NODE_CONVERT_FV, NODE_CONVERT_FI, NODE_CONVERT_CF, @@ -266,46 +268,46 @@ typedef enum NodeConvert { NODE_CONVERT_VI, NODE_CONVERT_IF, NODE_CONVERT_IV -} NodeConvert; +}; -typedef enum NodeNoiseType { +enum NodeNoiseType { NODE_NOISE_MULTIFRACTAL, NODE_NOISE_FBM, NODE_NOISE_HYBRID_MULTIFRACTAL, NODE_NOISE_RIDGED_MULTIFRACTAL, NODE_NOISE_HETERO_TERRAIN -} NodeNoiseType; +}; -typedef enum NodeGaborType { +enum NodeGaborType { NODE_GABOR_TYPE_2D, NODE_GABOR_TYPE_3D, -} NodeGaborType; +}; -typedef enum NodeWaveType { NODE_WAVE_BANDS, NODE_WAVE_RINGS } NodeWaveType; +enum NodeWaveType { NODE_WAVE_BANDS, NODE_WAVE_RINGS }; -typedef enum NodeWaveBandsDirection { +enum NodeWaveBandsDirection { NODE_WAVE_BANDS_DIRECTION_X, NODE_WAVE_BANDS_DIRECTION_Y, NODE_WAVE_BANDS_DIRECTION_Z, NODE_WAVE_BANDS_DIRECTION_DIAGONAL -} NodeWaveBandsDirection; +}; -typedef enum NodeWaveRingsDirection { +enum NodeWaveRingsDirection { NODE_WAVE_RINGS_DIRECTION_X, NODE_WAVE_RINGS_DIRECTION_Y, NODE_WAVE_RINGS_DIRECTION_Z, NODE_WAVE_RINGS_DIRECTION_SPHERICAL -} NodeWaveRingsDirection; +}; -typedef enum NodeWaveProfile { +enum NodeWaveProfile { NODE_WAVE_PROFILE_SIN, NODE_WAVE_PROFILE_SAW, NODE_WAVE_PROFILE_TRI, -} NodeWaveProfile; +}; -typedef enum NodeSkyType { NODE_SKY_PREETHAM, NODE_SKY_HOSEK, NODE_SKY_NISHITA } NodeSkyType; +enum NodeSkyType { NODE_SKY_PREETHAM, NODE_SKY_HOSEK, NODE_SKY_NISHITA }; -typedef enum NodeGradientType { +enum NodeGradientType { NODE_BLEND_LINEAR, NODE_BLEND_QUADRATIC, NODE_BLEND_EASING, @@ -313,110 +315,100 @@ typedef enum NodeGradientType { NODE_BLEND_RADIAL, NODE_BLEND_QUADRATIC_SPHERE, NODE_BLEND_SPHERICAL -} NodeGradientType; +}; -typedef enum NodeVoronoiDistanceMetric { +enum NodeVoronoiDistanceMetric { NODE_VORONOI_EUCLIDEAN, NODE_VORONOI_MANHATTAN, NODE_VORONOI_CHEBYCHEV, NODE_VORONOI_MINKOWSKI, -} NodeVoronoiDistanceMetric; +}; -typedef enum NodeVoronoiFeature { +enum NodeVoronoiFeature { NODE_VORONOI_F1, NODE_VORONOI_F2, NODE_VORONOI_SMOOTH_F1, NODE_VORONOI_DISTANCE_TO_EDGE, NODE_VORONOI_N_SPHERE_RADIUS, -} NodeVoronoiFeature; +}; -typedef enum NodeBlendWeightType { - NODE_LAYER_WEIGHT_FRESNEL, - NODE_LAYER_WEIGHT_FACING -} NodeBlendWeightType; +enum NodeBlendWeightType { NODE_LAYER_WEIGHT_FRESNEL, NODE_LAYER_WEIGHT_FACING }; -typedef enum NodeTangentDirectionType { - NODE_TANGENT_RADIAL, - NODE_TANGENT_UVMAP -} NodeTangentDirectionType; +enum NodeTangentDirectionType { NODE_TANGENT_RADIAL, NODE_TANGENT_UVMAP }; -typedef enum NodeTangentAxis { - NODE_TANGENT_AXIS_X, - NODE_TANGENT_AXIS_Y, - NODE_TANGENT_AXIS_Z -} NodeTangentAxis; +enum NodeTangentAxis { NODE_TANGENT_AXIS_X, NODE_TANGENT_AXIS_Y, NODE_TANGENT_AXIS_Z }; -typedef enum NodeNormalMapSpace { +enum NodeNormalMapSpace { NODE_NORMAL_MAP_TANGENT, NODE_NORMAL_MAP_OBJECT, NODE_NORMAL_MAP_WORLD, NODE_NORMAL_MAP_BLENDER_OBJECT, NODE_NORMAL_MAP_BLENDER_WORLD, -} NodeNormalMapSpace; +}; -typedef enum NodeImageProjection { +enum NodeImageProjection { NODE_IMAGE_PROJ_FLAT = 0, NODE_IMAGE_PROJ_BOX = 1, NODE_IMAGE_PROJ_SPHERE = 2, NODE_IMAGE_PROJ_TUBE = 3, -} NodeImageProjection; +}; -typedef enum NodeImageFlags { +enum NodeImageFlags { NODE_IMAGE_COMPRESS_AS_SRGB = 1, NODE_IMAGE_ALPHA_UNASSOCIATE = 2, -} NodeImageFlags; +}; -typedef enum NodeEnvironmentProjection { +enum NodeEnvironmentProjection { NODE_ENVIRONMENT_EQUIRECTANGULAR = 0, NODE_ENVIRONMENT_MIRROR_BALL = 1, -} NodeEnvironmentProjection; +}; -typedef enum NodeBumpOffset { +enum NodeBumpOffset { NODE_BUMP_OFFSET_CENTER, NODE_BUMP_OFFSET_DX, NODE_BUMP_OFFSET_DY, -} NodeBumpOffset; +}; -typedef enum NodeTexVoxelSpace { +enum NodeTexVoxelSpace { NODE_TEX_VOXEL_SPACE_OBJECT = 0, NODE_TEX_VOXEL_SPACE_WORLD = 1, -} NodeTexVoxelSpace; +}; -typedef enum NodeAO { +enum NodeAO { NODE_AO_ONLY_LOCAL = (1 << 0), NODE_AO_INSIDE = (1 << 1), NODE_AO_GLOBAL_RADIUS = (1 << 2), -} NodeAO; +}; -typedef enum ShaderType { +enum ShaderType { SHADER_TYPE_SURFACE, SHADER_TYPE_VOLUME, SHADER_TYPE_DISPLACEMENT, SHADER_TYPE_BUMP, -} ShaderType; +}; -typedef enum NodePrincipledHairModel { +enum NodePrincipledHairModel { NODE_PRINCIPLED_HAIR_CHIANG = 0, NODE_PRINCIPLED_HAIR_HUANG = 1, NODE_PRINCIPLED_HAIR_MODEL_NUM, -} NodePrincipledHairModel; +}; -typedef enum NodePrincipledHairParametrization { +enum NodePrincipledHairParametrization { NODE_PRINCIPLED_HAIR_REFLECTANCE = 0, NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION = 1, NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION = 2, NODE_PRINCIPLED_HAIR_PARAMETRIZATION_NUM, -} NodePrincipledHairParametrization; +}; -typedef enum NodeCombSepColorType { +enum NodeCombSepColorType { NODE_COMBSEP_COLOR_RGB, NODE_COMBSEP_COLOR_HSV, NODE_COMBSEP_COLOR_HSL, -} NodeCombSepColorType; +}; /* Closure */ -typedef enum ClosureType { +enum ClosureType { /* Special type, flags generic node as a non-BSDF. */ CLOSURE_NONE_ID, @@ -478,7 +470,7 @@ typedef enum ClosureType { CLOSURE_BSDF_PRINCIPLED_ID, NBUILTIN_CLOSURES -} ClosureType; +}; /* watch this, being lazy with memory usage */ #define CLOSURE_IS_BSDF(type) (type != CLOSURE_NONE_ID && type <= CLOSURE_BSDF_TRANSPARENT_ID) diff --git a/intern/cycles/kernel/svm/voronoi.h b/intern/cycles/kernel/svm/voronoi.h index e208f9a04f5..b77628d5029 100644 --- a/intern/cycles/kernel/svm/voronoi.h +++ b/intern/cycles/kernel/svm/voronoi.h @@ -59,18 +59,16 @@ ccl_device float voronoi_distance(const T a, const T b, ccl_private const Vorono if (params.metric == NODE_VORONOI_EUCLIDEAN) { return distance(a, b); } - else if (params.metric == NODE_VORONOI_MANHATTAN) { + if (params.metric == NODE_VORONOI_MANHATTAN) { return reduce_add(fabs(a - b)); } - else if (params.metric == NODE_VORONOI_CHEBYCHEV) { + if (params.metric == NODE_VORONOI_CHEBYCHEV) { return reduce_max(fabs(a - b)); } - else if (params.metric == NODE_VORONOI_MINKOWSKI) { + if (params.metric == NODE_VORONOI_MINKOWSKI) { return powf(reduce_add(power(fabs(a - b), params.exponent)), 1.0f / params.exponent); } - else { - return 0.0f; - } + return 0.0f; } /* **** 1D Voronoi **** */ @@ -902,7 +900,7 @@ ccl_device VoronoiOutput fractal_voronoi_x_fx(ccl_private const VoronoiParams &p output = octave; break; } - else if (i <= params.detail) { + if (i <= params.detail) { max_amplitude += amplitude; output.distance += octave.distance * amplitude; output.color += octave.color * amplitude; @@ -953,7 +951,7 @@ ccl_device float fractal_voronoi_distance_to_edge(ccl_private const VoronoiParam distance = octave_distance; break; } - else if (i <= params.detail) { + if (i <= params.detail) { max_amplitude = mix(max_amplitude, params.max_distance / scale, amplitude); distance = mix(distance, min(distance, octave_distance / scale), amplitude); scale *= params.lacunarity; @@ -993,16 +991,21 @@ ccl_device void svm_voronoi_output(const uint4 stack_offsets, svm_unpack_node_uchar3( stack_offsets.w, &position_stack_offset, &w_out_stack_offset, &radius_stack_offset); - if (stack_valid(distance_stack_offset)) + if (stack_valid(distance_stack_offset)) { stack_store_float(stack, distance_stack_offset, distance); - if (stack_valid(color_stack_offset)) + } + if (stack_valid(color_stack_offset)) { stack_store_float3(stack, color_stack_offset, color); - if (stack_valid(position_stack_offset)) + } + if (stack_valid(position_stack_offset)) { stack_store_float3(stack, position_stack_offset, position); - if (stack_valid(w_out_stack_offset)) + } + if (stack_valid(w_out_stack_offset)) { stack_store_float(stack, w_out_stack_offset, w); - if (stack_valid(radius_stack_offset)) + } + if (stack_valid(radius_stack_offset)) { stack_store_float(stack, radius_stack_offset, radius); + } } template diff --git a/intern/cycles/kernel/svm/wave.h b/intern/cycles/kernel/svm/wave.h index 1f408f6fca9..694a5899838 100644 --- a/intern/cycles/kernel/svm/wave.h +++ b/intern/cycles/kernel/svm/wave.h @@ -66,14 +66,13 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type, if (profile == NODE_WAVE_PROFILE_SIN) { return 0.5f + 0.5f * sinf(n - M_PI_2_F); } - else if (profile == NODE_WAVE_PROFILE_SAW) { + if (profile == NODE_WAVE_PROFILE_SAW) { n /= M_2PI_F; return n - floorf(n); } - else { /* NODE_WAVE_PROFILE_TRI */ - n /= M_2PI_F; - return fabsf(n - floorf(n + 0.5f)) * 2.0f; - } + /* NODE_WAVE_PROFILE_TRI */ + n /= M_2PI_F; + return fabsf(n - floorf(n + 0.5f)) * 2.0f; } ccl_device_noinline int svm_node_tex_wave( @@ -115,10 +114,12 @@ ccl_device_noinline int svm_node_tex_wave( droughness, phase); - if (stack_valid(fac_offset)) + if (stack_valid(fac_offset)) { stack_store_float(stack, fac_offset, f); - if (stack_valid(color_offset)) + } + if (stack_valid(color_offset)) { stack_store_float3(stack, color_offset, make_float3(f, f, f)); + } return offset; } diff --git a/intern/cycles/kernel/svm/wireframe.h b/intern/cycles/kernel/svm/wireframe.h index 7998025bc7f..1768d35c2b1 100644 --- a/intern/cycles/kernel/svm/wireframe.h +++ b/intern/cycles/kernel/svm/wireframe.h @@ -106,8 +106,9 @@ ccl_device_noinline void svm_node_wireframe(KernelGlobals kg, f += (f - wireframe(kg, sd, dP, size, pixel_size, &Py)) / len(dP.dy); } - if (stack_valid(out_fac)) + if (stack_valid(out_fac)) { stack_store_float(stack, out_fac, f); + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h index 7d5d12cfa14..5d7064f4987 100644 --- a/intern/cycles/kernel/types.h +++ b/intern/cycles/kernel/types.h @@ -31,6 +31,8 @@ CCL_NAMESPACE_BEGIN +// NOLINTBEGIN + /* Constants */ #define OBJECT_MOTION_PASS_SIZE 2 #define FILTER_TABLE_SIZE 1024 @@ -65,74 +67,79 @@ CCL_NAMESPACE_BEGIN # define INTEGRATOR_SHADOW_ISECT_SIZE INTEGRATOR_SHADOW_ISECT_SIZE_CPU #endif +// NOLINTEND + /* Kernel Features */ /* Shader nodes. */ -#define KERNEL_FEATURE_NODE_BSDF (1U << 0U) -#define KERNEL_FEATURE_NODE_EMISSION (1U << 1U) -#define KERNEL_FEATURE_NODE_VOLUME (1U << 2U) -#define KERNEL_FEATURE_NODE_BUMP (1U << 3U) -#define KERNEL_FEATURE_NODE_BUMP_STATE (1U << 4U) -#define KERNEL_FEATURE_NODE_VORONOI_EXTRA (1U << 5U) -#define KERNEL_FEATURE_NODE_RAYTRACE (1U << 6U) -#define KERNEL_FEATURE_NODE_AOV (1U << 7U) -#define KERNEL_FEATURE_NODE_LIGHT_PATH (1U << 8U) -#define KERNEL_FEATURE_NODE_PRINCIPLED_HAIR (1U << 9U) +enum { + KERNEL_FEATURE_NODE_BSDF = (1U << 0U), + KERNEL_FEATURE_NODE_EMISSION = (1U << 1U), + KERNEL_FEATURE_NODE_VOLUME = (1U << 2U), + KERNEL_FEATURE_NODE_BUMP = (1U << 3U), + KERNEL_FEATURE_NODE_BUMP_STATE = (1U << 4U), + KERNEL_FEATURE_NODE_VORONOI_EXTRA = (1U << 5U), + KERNEL_FEATURE_NODE_RAYTRACE = (1U << 6U), + KERNEL_FEATURE_NODE_AOV = (1U << 7U), + KERNEL_FEATURE_NODE_LIGHT_PATH = (1U << 8U), + KERNEL_FEATURE_NODE_PRINCIPLED_HAIR = (1U << 9U), -/* Use path tracing kernels. */ -#define KERNEL_FEATURE_PATH_TRACING (1U << 10U) + /* Use path tracing kernels. */ + KERNEL_FEATURE_PATH_TRACING = (1U << 10U), -/* BVH/sampling kernel features. */ -#define KERNEL_FEATURE_POINTCLOUD (1U << 11U) -#define KERNEL_FEATURE_HAIR (1U << 12U) -#define KERNEL_FEATURE_HAIR_THICK (1U << 13U) -#define KERNEL_FEATURE_OBJECT_MOTION (1U << 14U) + /* BVH/sampling kernel features. */ + KERNEL_FEATURE_POINTCLOUD = (1U << 11U), + KERNEL_FEATURE_HAIR = (1U << 12U), + KERNEL_FEATURE_HAIR_THICK = (1U << 13U), + KERNEL_FEATURE_OBJECT_MOTION = (1U << 14U), -/* Denotes whether baking functionality is needed. */ -#define KERNEL_FEATURE_BAKING (1U << 15U) + /* Denotes whether baking functionality is needed. */ + KERNEL_FEATURE_BAKING = (1U << 15U), -/* Use subsurface scattering materials. */ -#define KERNEL_FEATURE_SUBSURFACE (1U << 16U) + /* Use subsurface scattering materials. */ + KERNEL_FEATURE_SUBSURFACE = (1U << 16U), -/* Use volume materials. */ -#define KERNEL_FEATURE_VOLUME (1U << 17U) + /* Use volume materials. */ + KERNEL_FEATURE_VOLUME = (1U << 17U), -/* Use OpenSubdiv patch evaluation */ -#define KERNEL_FEATURE_PATCH_EVALUATION (1U << 18U) + /* Use OpenSubdiv patch evaluation */ + KERNEL_FEATURE_PATCH_EVALUATION = (1U << 18U), -/* Use Transparent shadows */ -#define KERNEL_FEATURE_TRANSPARENT (1U << 19U) + /* Use Transparent shadows */ + KERNEL_FEATURE_TRANSPARENT = (1U << 19U), -/* Use shadow catcher. */ -#define KERNEL_FEATURE_SHADOW_CATCHER (1U << 20U) + /* Use shadow catcher. */ + KERNEL_FEATURE_SHADOW_CATCHER = (1U << 20U), -/* Light render passes. */ -#define KERNEL_FEATURE_LIGHT_PASSES (1U << 21U) + /* Light render passes. */ + KERNEL_FEATURE_LIGHT_PASSES = (1U << 21U), + + /* AO. */ + KERNEL_FEATURE_AO_PASS = (1U << 22U), + KERNEL_FEATURE_AO_ADDITIVE = (1U << 23U), + + /* MNEE. */ + KERNEL_FEATURE_MNEE = (1U << 24U), + + /* Path guiding. */ + KERNEL_FEATURE_PATH_GUIDING = (1U << 25U), + + /* OSL. */ + KERNEL_FEATURE_OSL = (1U << 26U), + + /* Light and shadow linking. */ + KERNEL_FEATURE_LIGHT_LINKING = (1U << 27U), + KERNEL_FEATURE_SHADOW_LINKING = (1U << 28U), + + /* Use denoising kernels and output denoising passes. */ + KERNEL_FEATURE_DENOISING = (1U << 29U), + + /* Light tree. */ + KERNEL_FEATURE_LIGHT_TREE = (1U << 30U) +}; -/* AO. */ -#define KERNEL_FEATURE_AO_PASS (1U << 22U) -#define KERNEL_FEATURE_AO_ADDITIVE (1U << 23U) #define KERNEL_FEATURE_AO (KERNEL_FEATURE_AO_PASS | KERNEL_FEATURE_AO_ADDITIVE) -/* MNEE. */ -#define KERNEL_FEATURE_MNEE (1U << 24U) - -/* Path guiding. */ -#define KERNEL_FEATURE_PATH_GUIDING (1U << 25U) - -/* OSL. */ -#define KERNEL_FEATURE_OSL (1U << 26U) - -/* Light and shadow linking. */ -#define KERNEL_FEATURE_LIGHT_LINKING (1U << 27U) -#define KERNEL_FEATURE_SHADOW_LINKING (1U << 28U) - -/* Use denoising kernels and output denoising passes. */ -#define KERNEL_FEATURE_DENOISING (1U << 29U) - -/* Light tree. */ -#define KERNEL_FEATURE_LIGHT_TREE (1U << 30U) - /* Shader node feature mask, to specialize shader evaluation for kernels. */ #define KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT \ @@ -471,7 +478,7 @@ enum PathRayMNEE { /* Closure Label */ -typedef enum ClosureLabel { +enum ClosureLabel { LABEL_NONE = 0, LABEL_TRANSMIT = 1, LABEL_REFLECT = 2, @@ -483,7 +490,7 @@ typedef enum ClosureLabel { LABEL_TRANSMIT_TRANSPARENT = 128, LABEL_SUBSURFACE_SCATTER = 256, LABEL_RAY_PORTAL = 512, -} ClosureLabel; +}; /* Render Passes */ @@ -491,7 +498,7 @@ typedef enum ClosureLabel { #define PASSMASK(pass) (1 << ((PASS_NAME_JOIN(PASS, pass)) % 32)) // NOTE: Keep in sync with `Pass::get_type_enum()`. -typedef enum PassType { +enum PassType { PASS_NONE = 0, /* Light Passes */ @@ -568,38 +575,38 @@ typedef enum PassType { PASS_CATEGORY_BAKE_END = 95, PASS_NUM, -} PassType; +}; -#define PASS_ANY (~0) +#define PASS_ANY (~0) // NOLINT -typedef enum CryptomatteType { +enum CryptomatteType { CRYPT_NONE = 0, CRYPT_OBJECT = (1 << 0), CRYPT_MATERIAL = (1 << 1), CRYPT_ASSET = (1 << 2), CRYPT_ACCURATE = (1 << 3), -} CryptomatteType; +}; -typedef struct BsdfEval { +struct BsdfEval { Spectrum diffuse; Spectrum glossy; Spectrum sum; -} BsdfEval; +}; /* Closure Filter */ -typedef enum FilterClosures { +enum FilterClosures { FILTER_CLOSURE_EMISSION = (1 << 0), FILTER_CLOSURE_DIFFUSE = (1 << 1), FILTER_CLOSURE_GLOSSY = (1 << 2), FILTER_CLOSURE_TRANSMISSION = (1 << 3), FILTER_CLOSURE_TRANSPARENT = (1 << 4), FILTER_CLOSURE_DIRECT_LIGHT = (1 << 5), -} FilterClosures; +}; /* Shader Flag */ -typedef enum ShaderFlag { +enum ShaderFlag { SHADER_SMOOTH_NORMAL = (1 << 31), SHADER_CAST_SHADOW = (1 << 30), SHADER_AREA_LIGHT = (1 << 29), @@ -616,7 +623,7 @@ typedef enum ShaderFlag { SHADER_MASK = ~(SHADER_SMOOTH_NORMAL | SHADER_CAST_SHADOW | SHADER_AREA_LIGHT | SHADER_USE_MIS | SHADER_EXCLUDE_ANY) -} ShaderFlag; +}; enum EmissionSampling { EMISSION_SAMPLING_NONE = 0, @@ -630,34 +637,34 @@ enum EmissionSampling { /* Light Type */ -typedef enum LightType { +enum LightType { LIGHT_POINT, LIGHT_DISTANT, LIGHT_BACKGROUND, LIGHT_AREA, LIGHT_SPOT, LIGHT_TRIANGLE -} LightType; +}; /* Guiding Distribution Type */ -typedef enum GuidingDistributionType { +enum GuidingDistributionType { GUIDING_TYPE_PARALLAX_AWARE_VMM = 0, GUIDING_TYPE_DIRECTIONAL_QUAD_TREE = 1, GUIDING_TYPE_VMM = 2, GUIDING_NUM_TYPES, -} GuidingDistributionType; +}; /* Guiding Directional Sampling Type */ -typedef enum GuidingDirectionalSamplingType { +enum GuidingDirectionalSamplingType { GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT_MIS = 0, GUIDING_DIRECTIONAL_SAMPLING_TYPE_RIS = 1, GUIDING_DIRECTIONAL_SAMPLING_TYPE_ROUGHNESS = 2, GUIDING_DIRECTIONAL_SAMPLING_NUM_TYPES, -} GuidingDirectionalSamplingType; +}; /* Camera Type */ @@ -700,27 +707,27 @@ enum DirectLightSamplingType { /* Differential */ -typedef struct differential3 { +struct differential3 { float3 dx; float3 dy; -} differential3; +}; -typedef struct differential { +struct differential { float dx; float dy; -} differential; +}; /* Ray */ -typedef struct RaySelfPrimitives { +struct RaySelfPrimitives { int prim; /* Primitive the ray is starting from */ int object; /* Instance prim is a part of */ int light_prim; /* Light primitive */ int light_object; /* Light object */ int light; /* Light ID (the light the shadow ray is traced towards to) */ -} RaySelfPrimitives; +}; -typedef struct Ray { +struct Ray { float3 P; /* origin */ float3 D; /* direction */ float tmin; /* start distance */ @@ -733,16 +740,16 @@ typedef struct Ray { #endif RaySelfPrimitives self; -} Ray; +}; /* Intersection */ -typedef struct Intersection { +struct Intersection { float t, u, v; int prim; int object; int type; -} Intersection; +}; /* On certain GPUs (Apple Silicon), splitting every integrator state field into its own separate * array can be detrimental for cache utilization. By enabling __INTEGRATOR_GPU_PACKED_STATE__, we @@ -808,7 +815,7 @@ typedef struct Intersection { /* Primitives */ -typedef enum PrimitiveType { +enum PrimitiveType { PRIMITIVE_NONE = 0, PRIMITIVE_TRIANGLE = (1 << 0), PRIMITIVE_CURVE_THICK = (1 << 1), @@ -831,7 +838,7 @@ typedef enum PrimitiveType { PRIMITIVE_NUM_SHAPES = 6, PRIMITIVE_NUM_BITS = PRIMITIVE_NUM_SHAPES + 1, /* All shapes + motion bit. */ PRIMITIVE_NUM = PRIMITIVE_NUM_SHAPES * 2, /* With and without motion. */ -} PrimitiveType; +}; /* Convert type to index in range 0..PRIMITIVE_NUM-1. */ #define PRIMITIVE_INDEX(type) \ @@ -841,23 +848,23 @@ typedef enum PrimitiveType { #define PRIMITIVE_PACK_SEGMENT(type, segment) ((segment << PRIMITIVE_NUM_BITS) | (type)) #define PRIMITIVE_UNPACK_SEGMENT(type) (type >> PRIMITIVE_NUM_BITS) -typedef enum CurveShapeType { +enum CurveShapeType { CURVE_RIBBON = 0, CURVE_THICK = 1, CURVE_NUM_SHAPE_TYPES, -} CurveShapeType; +}; /* Attributes */ -typedef enum AttributePrimitive { +enum AttributePrimitive { ATTR_PRIM_GEOMETRY = 0, ATTR_PRIM_SUBD, ATTR_PRIM_TYPES -} AttributePrimitive; +}; -typedef enum AttributeElement { +enum AttributeElement { ATTR_ELEMENT_NONE = 0, ATTR_ELEMENT_OBJECT = (1 << 0), ATTR_ELEMENT_MESH = (1 << 1), @@ -870,9 +877,9 @@ typedef enum AttributeElement { ATTR_ELEMENT_CURVE_KEY = (1 << 8), ATTR_ELEMENT_CURVE_KEY_MOTION = (1 << 9), ATTR_ELEMENT_VOXEL = (1 << 10) -} AttributeElement; +}; -typedef enum AttributeStandard { +enum AttributeStandard { ATTR_STD_NONE = 0, ATTR_STD_VERTEX_NORMAL, ATTR_STD_FACE_NORMAL, @@ -908,28 +915,28 @@ typedef enum AttributeStandard { ATTR_STD_NUM, ATTR_STD_NOT_FOUND = ~0 -} AttributeStandard; +}; -typedef enum AttributeFlag { +enum AttributeFlag { ATTR_FINAL_SIZE = (1 << 0), ATTR_SUBDIVIDED = (1 << 1), -} AttributeFlag; +}; -typedef struct AttributeDescriptor { +struct AttributeDescriptor { AttributeElement element; NodeAttributeType type; uint flags; /* see enum AttributeFlag */ int offset; -} AttributeDescriptor; +}; /* For looking up attributes on objects and geometry. */ -typedef struct AttributeMap { +struct AttributeMap { uint64_t id; /* Global unique identifier. */ int offset; /* Offset into __attributes global arrays. */ uint16_t element; /* AttributeElement. */ uint8_t type; /* NodeAttributeType. */ uint8_t flags; /* AttributeFlag. */ -} AttributeMap; +}; /* Closure data */ @@ -956,7 +963,7 @@ typedef struct AttributeMap { # define MAX_VOLUME_STACK_SIZE __MAX_VOLUME_STACK_SIZE__ #endif -#define MAX_VOLUME_CLOSURE 8 +#define MAX_VOLUME_CLOSURE 8 // NOLINT /* This struct is the base class for all closures. The common members are * duplicated in all derived classes since we don't have C++ in the kernel @@ -985,15 +992,14 @@ typedef struct AttributeMap { ClosureType type; \ float sample_weight -typedef struct ccl_align(16) ShaderClosure +struct ccl_align(16) ShaderClosure { SHADER_CLOSURE_BASE; /* Extra space for closures to store data, somewhat arbitrary but closures * assert that their size fits. */ char pad[sizeof(Spectrum) * 2 + sizeof(float) * 4]; -} -ShaderClosure; +}; /* Shader Data * @@ -1116,7 +1122,7 @@ enum ShaderDataObjectFlag { SD_OBJECT_HAS_VOLUME_MOTION) }; -typedef struct ccl_align(16) ShaderData +struct ccl_align(16) ShaderData { /* position */ float3 P; @@ -1205,24 +1211,21 @@ typedef struct ccl_align(16) ShaderData /* At the end so we can adjust size in ShaderDataTinyStorage. */ struct ShaderClosure closure[MAX_CLOSURE]; -} -ShaderData; +}; /* ShaderDataTinyStorage needs the same alignment as ShaderData, or else * the pointer cast in AS_SHADER_DATA invokes undefined behavior. */ -typedef struct ccl_align(16) ShaderDataTinyStorage +struct ccl_align(16) ShaderDataTinyStorage { char pad[sizeof(ShaderData) - sizeof(ShaderClosure) * MAX_CLOSURE]; -} -ShaderDataTinyStorage; +}; /* ShaderDataCausticsStorage needs the same alignment as ShaderData, or else * the pointer cast in AS_SHADER_DATA invokes undefined behavior. */ -typedef struct ccl_align(16) ShaderDataCausticsStorage +struct ccl_align(16) ShaderDataCausticsStorage { char pad[sizeof(ShaderData) - sizeof(ShaderClosure) * (MAX_CLOSURE - CAUSTICS_MAX_CLOSURE)]; -} -ShaderDataCausticsStorage; +}; #define AS_SHADER_DATA(shader_data_tiny_storage) \ ((ccl_private ShaderData *)shader_data_tiny_storage) @@ -1235,34 +1238,34 @@ ShaderDataCausticsStorage; * just without the normal and with less space for closure-specific parameters. * That way, we can just cast ShaderClosure* to ShaderVolumeClosure* and assign it. */ -typedef struct ShaderVolumeClosure { +struct ShaderVolumeClosure { Spectrum weight; ClosureType type; float sample_weight; /* Space for closure-specific parameters. */ float param[3]; -} ShaderVolumeClosure; +}; -typedef struct ShaderVolumePhases { +struct ShaderVolumePhases { ShaderVolumeClosure closure[MAX_VOLUME_CLOSURE]; int num_closure; -} ShaderVolumePhases; +}; /* Volume Stack */ #ifdef __VOLUME__ -typedef struct VolumeStack { +struct VolumeStack { int object; int shader; -} VolumeStack; +}; #endif /* Struct to gather multiple nearby intersections. */ -typedef struct LocalIntersection { +struct LocalIntersection { int num_hits; struct Intersection hits[LOCAL_MAX_HITS]; float3 Ng[LOCAL_MAX_HITS]; -} LocalIntersection; +}; /* Constant Kernel Data * @@ -1270,7 +1273,7 @@ typedef struct LocalIntersection { * must match exactly. Structs are padded to ensure 16 byte alignment, and we * do not use float3 because its size may not be the same on all devices. */ -typedef struct KernelCamera { +struct KernelCamera { /* type */ int type; int use_dof_or_motion_blur; @@ -1353,10 +1356,10 @@ typedef struct KernelCamera { float rolling_shutter_duration; int motion_position; -} KernelCamera; +}; static_assert_align(KernelCamera, 16); -typedef struct KernelFilmConvert { +struct KernelFilmConvert { int pass_offset; int pass_stride; @@ -1394,10 +1397,10 @@ typedef struct KernelFilmConvert { /* Padding. */ int pad1; -} KernelFilmConvert; +}; static_assert_align(KernelFilmConvert, 16); -typedef enum KernelBVHLayout { +enum KernelBVHLayout { BVH_LAYOUT_NONE = 0, BVH_LAYOUT_BVH2 = (1 << 0), @@ -1421,7 +1424,7 @@ typedef enum KernelBVHLayout { BVH_LAYOUT_HIPRT | BVH_LAYOUT_MULTI_HIPRT | BVH_LAYOUT_MULTI_HIPRT_EMBREE | BVH_LAYOUT_EMBREEGPU | BVH_LAYOUT_MULTI_EMBREEGPU | BVH_LAYOUT_MULTI_EMBREEGPU_EMBREE, -} KernelBVHLayout; +}; /* Specialized struct that can become constants in dynamic compilation. */ #define KERNEL_STRUCT_BEGIN(name, parent) \ @@ -1440,7 +1443,7 @@ typedef enum KernelBVHLayout { #include "kernel/data_template.h" -typedef struct KernelTables { +struct KernelTables { int filter_table_offset; int ggx_E; int ggx_Eavg; @@ -1453,22 +1456,22 @@ typedef struct KernelTables { int ggx_gen_schlick_s; int pad1; int pad2; -} KernelTables; +}; static_assert_align(KernelTables, 16); -typedef struct KernelBake { +struct KernelBake { int use; int object_index; int tri_offset; int use_camera; -} KernelBake; +}; static_assert_align(KernelBake, 16); -typedef struct KernelLightLinkSet { +struct KernelLightLinkSet { uint light_tree_root; -} KernelLightLinkSet; +}; -typedef struct ccl_align(16) KernelData +struct ccl_align(16) KernelData { /* Features and limits. */ uint kernel_features; @@ -1504,13 +1507,12 @@ typedef struct ccl_align(16) KernelData # endif #endif int pad2, pad3; -} -KernelData; +}; static_assert_align(KernelData, 16); /* Kernel data structures. */ -typedef struct KernelObject { +struct KernelObject { Transform tfm; Transform itfm; @@ -1553,24 +1555,24 @@ typedef struct KernelObject { uint receiver_light_set; uint64_t shadow_set_membership; uint blocker_shadow_set; -} KernelObject; +}; static_assert_align(KernelObject, 16); -typedef struct KernelCurve { +struct KernelCurve { int shader_id; int first_key; int num_keys; int type; -} KernelCurve; +}; static_assert_align(KernelCurve, 16); -typedef struct KernelCurveSegment { +struct KernelCurveSegment { int prim; int type; -} KernelCurveSegment; +}; static_assert_align(KernelCurveSegment, 8); -typedef struct KernelSpotLight { +struct KernelSpotLight { packed_float3 dir; float radius; float eval_fac; @@ -1582,11 +1584,11 @@ typedef struct KernelSpotLight { float cos_half_larger_spread; /* Distance from the apex of the smallest enclosing cone of the light spread to light center. */ float ray_segment_dp; -} KernelSpotLight; +}; /* PointLight is SpotLight with only radius and invarea being used. */ -typedef struct KernelAreaLight { +struct KernelAreaLight { packed_float3 axis_u; float len_u; packed_float3 axis_v; @@ -1596,18 +1598,18 @@ typedef struct KernelAreaLight { float tan_half_spread; float normalize_spread; float pad[2]; -} KernelAreaLight; +}; -typedef struct KernelDistantLight { +struct KernelDistantLight { float angle; float one_minus_cosangle; float half_inv_sin_half_angle; float pdf; float eval_fac; float pad[3]; -} KernelDistantLight; +}; -typedef struct KernelLight { +struct KernelLight { int type; packed_float3 co; int shader_id; @@ -1625,19 +1627,19 @@ typedef struct KernelLight { }; uint64_t light_set_membership; uint64_t shadow_set_membership; -} KernelLight; +}; static_assert_align(KernelLight, 16); -using MeshLight = struct MeshLight { +struct MeshLight { int shader_flag; int object_id; }; -typedef struct KernelLightDistribution { +struct KernelLightDistribution { float totarea; int prim; MeshLight mesh_light; -} KernelLightDistribution; +}; static_assert_align(KernelLightDistribution, 16); /* Bounding box. */ @@ -1659,7 +1661,7 @@ enum LightTreeNodeType : uint8_t { LIGHT_TREE_DISTANT = (1 << 3), }; -typedef struct KernelLightTreeNode { +struct KernelLightTreeNode { /* Bounding box. */ KernelBoundingBox bbox; @@ -1696,10 +1698,10 @@ typedef struct KernelLightTreeNode { /* Padding. */ uint8_t pad[11]; -} KernelLightTreeNode; +}; static_assert_align(KernelLightTreeNode, 16); -typedef struct KernelLightTreeEmitter { +struct KernelLightTreeEmitter { /* Bounding cone. */ float theta_o; float theta_e; @@ -1727,10 +1729,10 @@ typedef struct KernelLightTreeEmitter { /* Bit trail from root node to leaf node containing emitter. */ int bit_trail; -} KernelLightTreeEmitter; +}; static_assert_align(KernelLightTreeEmitter, 16); -typedef struct KernelParticle { +struct KernelParticle { int index; float age; float lifetime; @@ -1741,20 +1743,21 @@ typedef struct KernelParticle { float4 location; float4 velocity; float4 angular_velocity; -} KernelParticle; +}; static_assert_align(KernelParticle, 16); -typedef struct KernelShader { +struct KernelShader { float constant_emission[3]; float cryptomatte_id; int flags; int pass_id; int pad2, pad3; -} KernelShader; +}; static_assert_align(KernelShader, 16); /* Patches */ +// NOLINTBEGIN #define PATCH_MAX_CONTROL_VERTS 16 /* Patch map node flags */ @@ -1762,10 +1765,11 @@ static_assert_align(KernelShader, 16); #define PATCH_MAP_NODE_IS_SET (1 << 30) #define PATCH_MAP_NODE_IS_LEAF (1u << 31) #define PATCH_MAP_NODE_INDEX_MASK (~(PATCH_MAP_NODE_IS_SET | PATCH_MAP_NODE_IS_LEAF)) +// NOLINTEND /* Work Tiles */ -typedef struct KernelWorkTile { +struct KernelWorkTile { uint x, y, w, h; uint start_sample; @@ -1778,18 +1782,18 @@ typedef struct KernelWorkTile { /* Precalculated parameters used by init_from_camera kernel on GPU. */ int path_index_offset; int work_size; -} KernelWorkTile; +}; /* Shader Evaluation. * * Position on a primitive on an object at which we want to evaluate the * shader for e.g. mesh displacement or light importance map. */ -typedef struct KernelShaderEvalInput { +struct KernelShaderEvalInput { int object; int prim; float u, v; -} KernelShaderEvalInput; +}; static_assert_align(KernelShaderEvalInput, 16); /* Pre-computed sample table sizes for the tabulated Sobol sampler. @@ -1797,10 +1801,12 @@ static_assert_align(KernelShaderEvalInput, 16); * NOTE: min and max samples *must* be a power of two, and patterns * ideally should be as well. */ +// NOLINTBEGIN #define MIN_TAB_SOBOL_SAMPLES 256 #define MAX_TAB_SOBOL_SAMPLES 8192 #define NUM_TAB_SOBOL_DIMENSIONS 4 #define NUM_TAB_SOBOL_PATTERNS 256 +// NOLINTEND /* Device kernels. * @@ -1811,7 +1817,7 @@ static_assert_align(KernelShaderEvalInput, 16); * If the kernel uses shared CUDA memory, `CUDADeviceQueue::enqueue` is to be modified. * The path iteration kernels are handled in `PathTraceWorkGPU::enqueue_path_iteration`. */ -typedef enum DeviceKernel : int { +enum DeviceKernel : int { DEVICE_KERNEL_INTEGRATOR_INIT_FROM_CAMERA = 0, DEVICE_KERNEL_INTEGRATOR_INIT_FROM_BAKE, DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST, @@ -1880,7 +1886,7 @@ typedef enum DeviceKernel : int { DEVICE_KERNEL_PREFIX_SUM, DEVICE_KERNEL_NUM, -} DeviceKernel; +}; enum { DEVICE_KERNEL_INTEGRATOR_NUM = DEVICE_KERNEL_INTEGRATOR_MEGAKERNEL + 1, diff --git a/intern/cycles/kernel/util/nanovdb.h b/intern/cycles/kernel/util/nanovdb.h index 11f7a117cd2..b164573258c 100644 --- a/intern/cycles/kernel/util/nanovdb.h +++ b/intern/cycles/kernel/util/nanovdb.h @@ -7,12 +7,17 @@ #pragma once -#include "util/types.h" +#include "util/defines.h" +#include "util/types_base.h" + +#ifndef __KERNEL_GPU__ +# include +#endif CCL_NAMESPACE_BEGIN #define NANOVDB_USE_SINGLE_ROOT_KEY -#define NANOVDB_DATA_ALIGNMENT 32 +#define NANOVDB_DATA_ALIGNMENT 32 // NOLINT namespace nanovdb { @@ -360,19 +365,14 @@ template class CachedReadAccessor { using LowerT = NanoLower; using LeafT = NanoLeaf; - mutable Coord mKeys[3]; - mutable ccl_global const RootT *mRoot; - mutable ccl_global const void *mNode[3]; + mutable Coord mKeys[3] = {Coord(INT_MAX), Coord(INT_MAX), Coord(INT_MAX)}; + mutable ccl_global const RootT *mRoot = nullptr; + mutable ccl_global const void *mNode[3] = {nullptr, nullptr, nullptr}; public: using ValueType = typename RootT::ValueType; - ccl_device_inline_method CachedReadAccessor(ccl_global const RootT &root) - : mKeys{Coord(INT_MAX), Coord(INT_MAX), Coord(INT_MAX)}, - mRoot(&root), - mNode{nullptr, nullptr, nullptr} - { - } + ccl_device_inline_method CachedReadAccessor(ccl_global const RootT &root) : mRoot(&root) {} template ccl_device_inline_method bool isCached(const Coord ijk) const { @@ -419,10 +419,10 @@ template class CachedReadAccessor { if (isCached(ijk)) { return getValueAndCache(*((ccl_global const LeafT *)mNode[0]), ijk); } - else if (isCached(ijk)) { + if (isCached(ijk)) { return getValueAndCache(*((ccl_global const LowerT *)mNode[1]), ijk); } - else if (isCached(ijk)) { + if (isCached(ijk)) { return getValueAndCache(*((ccl_global const UpperT *)mNode[2]), ijk); } return getValueAndCache(*mRoot, ijk); diff --git a/intern/cycles/kernel/util/profiler.h b/intern/cycles/kernel/util/profiler.h index 54a90e836da..341e3199382 100644 --- a/intern/cycles/kernel/util/profiler.h +++ b/intern/cycles/kernel/util/profiler.h @@ -5,7 +5,7 @@ #pragma once #ifndef __KERNEL_GPU__ -# include "util/profiling.h" +# include "util/profiling.h" // IWYU pragma: export #endif CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/scene/alembic.cpp b/intern/cycles/scene/alembic.cpp index cd643611070..d06d72b642e 100644 --- a/intern/cycles/scene/alembic.cpp +++ b/intern/cycles/scene/alembic.cpp @@ -7,6 +7,7 @@ #include "scene/alembic_read.h" #include "scene/camera.h" #include "scene/curves.h" +#include "scene/hair.h" #include "scene/mesh.h" #include "scene/object.h" #include "scene/pointcloud.h" @@ -438,7 +439,7 @@ AlembicObject::AlembicObject() : Node(get_node_type()) schema_type = INVALID; } -AlembicObject::~AlembicObject() {} +AlembicObject::~AlembicObject() = default; void AlembicObject::set_object(Object *object_) { @@ -660,7 +661,7 @@ void AlembicObject::setup_transform_cache(CachedData &cached_data, float scale) cached_data.transforms.set_time_sampling(*xform_time_sampling); } - if (xform_samples.size() == 0) { + if (xform_samples.empty()) { Transform tfm = transform_scale(make_float3(scale)); cached_data.transforms.add_data(tfm, 0.0); } @@ -701,7 +702,7 @@ AttributeRequestSet AlembicObject::get_requested_attributes() Shader *shader = static_cast(node); foreach (const AttributeRequest &attr, shader->attributes.requests) { - if (attr.name != "") { + if (!attr.name.empty()) { requested_attributes.add(attr.name); } } @@ -871,10 +872,10 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress) factory.setPolicy(Alembic::Abc::ErrorHandler::kQuietNoopPolicy); std::vector filenames; - filenames.push_back(filepath.c_str()); + filenames.emplace_back(filepath.c_str()); for (const ustring &layer : layers) { - filenames.push_back(layer.c_str()); + filenames.emplace_back(layer.c_str()); } /* We need to reverse the order as overriding archives should come first. */ @@ -1110,7 +1111,7 @@ void AlembicProcedural::read_mesh(AlembicObject *abc_object, Abc::chrono_t frame triangles.push_back_reserved(tri.x); triangles.push_back_reserved(tri.y); triangles.push_back_reserved(tri.z); - smooth.push_back_reserved(1); + smooth.push_back_reserved(true); } mesh->set_triangles(triangles); diff --git a/intern/cycles/scene/alembic.h b/intern/cycles/scene/alembic.h index 1234df8f9fd..35979deb9e8 100644 --- a/intern/cycles/scene/alembic.h +++ b/intern/cycles/scene/alembic.h @@ -7,7 +7,6 @@ #include "graph/node.h" #include "scene/attribute.h" #include "scene/procedural.h" -#include "util/set.h" #include "util/transform.h" #include "util/vector.h" @@ -377,7 +376,7 @@ class AlembicObject : public Node { NODE_SOCKET_API(float, radius_scale) AlembicObject(); - ~AlembicObject(); + ~AlembicObject() override; private: friend class AlembicProcedural; @@ -509,11 +508,11 @@ class AlembicProcedural : public Procedural { NODE_SOCKET_API(int, prefetch_cache_size) AlembicProcedural(); - ~AlembicProcedural(); + ~AlembicProcedural() override; /* Populates the Cycles scene with Nodes for every contained AlembicObject on the first * invocation, and updates the data on subsequent invocations if the frame changed. */ - void generate(Scene *scene, Progress &progress); + void generate(Scene *scene, Progress &progress) override; /* Tag for an update only if something was modified. */ void tag_update(Scene *scene); @@ -539,7 +538,7 @@ class AlembicProcedural : public Procedural { * specified in our objects socket, and accumulate all of the transformations samples along the * way for each IObject. */ void walk_hierarchy(Alembic::AbcGeom::IObject parent, - const Alembic::AbcGeom::ObjectHeader &ohead, + const Alembic::AbcGeom::ObjectHeader &header, MatrixSamplesData matrix_samples_data, const unordered_map &object_map, Progress &progress); diff --git a/intern/cycles/scene/alembic_read.cpp b/intern/cycles/scene/alembic_read.cpp index 267c7644dc0..b37be00fe21 100644 --- a/intern/cycles/scene/alembic_read.cpp +++ b/intern/cycles/scene/alembic_read.cpp @@ -448,7 +448,7 @@ static void add_subd_polygons(CachedData &cached_data, const SubDSchemaData &dat } shader.push_back_reserved(current_shader); - subd_smooth.push_back_reserved(1); + subd_smooth.push_back_reserved(true); subd_ptex_offset.push_back_reserved(ptex_offset); ptex_offset += (num_corners == 4 ? 1 : num_corners); @@ -667,7 +667,7 @@ static void read_points_data(CachedData &cached_data, const PointsSchemaData &da } a_radius.push_back_slow(radius * data.radius_scale); - a_shader.push_back_slow((int)0); + a_shader.push_back_slow(0); } cached_data.points.add_data(a_positions, time); diff --git a/intern/cycles/scene/attribute.cpp b/intern/cycles/scene/attribute.cpp index 5c96130d998..84a4e9f23d2 100644 --- a/intern/cycles/scene/attribute.cpp +++ b/intern/cycles/scene/attribute.cpp @@ -37,7 +37,7 @@ Attribute::Attribute( Attribute::~Attribute() { /* For voxel data, we need to free the image handle. */ - if (element == ATTR_ELEMENT_VOXEL && buffer.size()) { + if (element == ATTR_ELEMENT_VOXEL && !buffer.empty()) { ImageHandle &handle = data_voxel(); handle.~ImageHandle(); } @@ -166,29 +166,27 @@ size_t Attribute::data_sizeof() const if (element == ATTR_ELEMENT_VOXEL) { return sizeof(ImageHandle); } - else if (element == ATTR_ELEMENT_CORNER_BYTE) { + if (element == ATTR_ELEMENT_CORNER_BYTE) { return sizeof(uchar4); } - else if (type == TypeFloat) { + if (type == TypeFloat) { return sizeof(float); } - else if (type == TypeFloat2) { + if (type == TypeFloat2) { return sizeof(float2); } - else if (type == TypeMatrix) { + if (type == TypeMatrix) { return sizeof(Transform); // The float3 type is not interchangeable with float4 // as it is now a packed type. } - else if (type == TypeFloat4) { + if (type == TypeFloat4) { return sizeof(float4); } - else if (type == TypeRGBA) { + if (type == TypeRGBA) { return sizeof(float4); } - else { - return sizeof(float3); - } + return sizeof(float3); } size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const @@ -473,7 +471,7 @@ AttributeSet::AttributeSet(Geometry *geometry, AttributePrimitive prim) { } -AttributeSet::~AttributeSet() {} +AttributeSet::~AttributeSet() = default; Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element) { @@ -525,7 +523,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name) { Attribute *attr = nullptr; - if (name == ustring()) { + if (name.empty()) { name = Attribute::standard_name(std); } @@ -727,9 +725,7 @@ Attribute *AttributeSet::find(AttributeRequest &req) if (req.std == ATTR_STD_NONE) { return find(req.name); } - else { - return find(req.std); - } + return find(req.std); } void AttributeSet::remove(Attribute *attribute) @@ -862,9 +858,9 @@ AttributeRequest::AttributeRequest(AttributeStandard std_) /* AttributeRequestSet */ -AttributeRequestSet::AttributeRequestSet() {} +AttributeRequestSet::AttributeRequestSet() = default; -AttributeRequestSet::~AttributeRequestSet() {} +AttributeRequestSet::~AttributeRequestSet() = default; bool AttributeRequestSet::modified(const AttributeRequestSet &other) { diff --git a/intern/cycles/scene/attribute.h b/intern/cycles/scene/attribute.h index 57e3b0787f5..143e5e167d2 100644 --- a/intern/cycles/scene/attribute.h +++ b/intern/cycles/scene/attribute.h @@ -73,7 +73,7 @@ class Attribute { char *data() { - return (buffer.size()) ? &buffer[0] : nullptr; + return (!buffer.empty()) ? buffer.data() : nullptr; } float2 *data_float2() { @@ -115,7 +115,7 @@ class Attribute { const char *data() const { - return (buffer.size()) ? &buffer[0] : nullptr; + return (!buffer.empty()) ? buffer.data() : nullptr; } const float2 *data_float2() const { @@ -155,7 +155,7 @@ class Attribute { void add(const float2 &f); void add(const float3 &f); void add(const uchar4 &f); - void add(const Transform &tfm); + void add(const Transform &f); void add(const char *data); void set_data_from(Attribute &&other); diff --git a/intern/cycles/scene/background.cpp b/intern/cycles/scene/background.cpp index 99d206fa5f3..42a9e5d9105 100644 --- a/intern/cycles/scene/background.cpp +++ b/intern/cycles/scene/background.cpp @@ -15,7 +15,6 @@ #include "util/foreach.h" #include "util/math.h" #include "util/time.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/scene/background.h b/intern/cycles/scene/background.h index f79b2c1ba88..af3d297a4ee 100644 --- a/intern/cycles/scene/background.h +++ b/intern/cycles/scene/background.h @@ -33,7 +33,7 @@ class Background : public Node { NODE_SOCKET_API(ustring, lightgroup) Background(); - ~Background(); + ~Background() override; void device_update(Device *device, DeviceScene *dscene, Scene *scene); void device_free(Device *device, DeviceScene *dscene); diff --git a/intern/cycles/scene/bake.h b/intern/cycles/scene/bake.h index c72b87c1d19..58cff0136e5 100644 --- a/intern/cycles/scene/bake.h +++ b/intern/cycles/scene/bake.h @@ -8,7 +8,6 @@ #include "scene/scene.h" #include "util/progress.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/scene/camera.cpp b/intern/cycles/scene/camera.cpp index 87e253b7366..ddc88f0cb68 100644 --- a/intern/cycles/scene/camera.cpp +++ b/intern/cycles/scene/camera.cpp @@ -14,7 +14,7 @@ #include "util/foreach.h" #include "util/log.h" #include "util/math_cdf.h" -#include "util/task.h" +#include "util/tbb.h" #include "util/time.h" #include "util/vector.h" @@ -34,9 +34,7 @@ static float shutter_curve_eval(float x, array &shutter_curve) if (index < shutter_curve.size() - 1) { return mix(shutter_curve[index], shutter_curve[index + 1], frac); } - else { - return shutter_curve[shutter_curve.size() - 1]; - } + return shutter_curve[shutter_curve.size() - 1]; } NODE_DEFINE(Camera) @@ -190,7 +188,7 @@ Camera::Camera() : Node(get_node_type()) memset((void *)&kernel_camera, 0, sizeof(kernel_camera)); } -Camera::~Camera() {} +Camera::~Camera() = default; void Camera::compute_auto_viewplane() { diff --git a/intern/cycles/scene/camera.h b/intern/cycles/scene/camera.h index 5490accdec2..c87142f1e4c 100644 --- a/intern/cycles/scene/camera.h +++ b/intern/cycles/scene/camera.h @@ -188,7 +188,7 @@ class Camera : public Node { public: /* functions */ Camera(); - ~Camera(); + ~Camera() override; void compute_auto_viewplane(); diff --git a/intern/cycles/scene/colorspace.cpp b/intern/cycles/scene/colorspace.cpp index a0eaea5b003..cdefb554812 100644 --- a/intern/cycles/scene/colorspace.cpp +++ b/intern/cycles/scene/colorspace.cpp @@ -5,9 +5,9 @@ #include "scene/colorspace.h" #include "util/color.h" -#include "util/half.h" #include "util/image.h" #include "util/log.h" +#include "util/map.h" #include "util/math.h" #include "util/thread.h" #include "util/vector.h" @@ -46,7 +46,7 @@ ColorSpaceProcessor *ColorSpaceManager::get_processor(ustring colorspace) try { config = OCIO::GetCurrentConfig(); } - catch (OCIO::Exception &exception) { + catch (const OCIO::Exception &exception) { VLOG_WARNING << "OCIO config error: " << exception.what(); return nullptr; } @@ -62,7 +62,7 @@ ColorSpaceProcessor *ColorSpaceManager::get_processor(ustring colorspace) try { cached_processors[colorspace] = config->getProcessor(colorspace.c_str(), "scene_linear"); } - catch (OCIO::Exception &exception) { + catch (const OCIO::Exception &exception) { cached_processors[colorspace] = OCIO::ConstProcessorRcPtr(); VLOG_WARNING << "Colorspace " << colorspace.c_str() << " can't be converted to scene_linear: " << exception.what(); @@ -91,7 +91,7 @@ bool ColorSpaceManager::colorspace_is_data(ustring colorspace) try { config = OCIO::GetCurrentConfig(); } - catch (OCIO::Exception &exception) { + catch (const OCIO::Exception &exception) { VLOG_WARNING << "OCIO config error: " << exception.what(); return false; } @@ -104,7 +104,7 @@ bool ColorSpaceManager::colorspace_is_data(ustring colorspace) OCIO::ConstColorSpaceRcPtr space = config->getColorSpace(colorspace.c_str()); return space && space->isData(); } - catch (OCIO::Exception &) { + catch (const OCIO::Exception &) { return false; } #else @@ -120,81 +120,79 @@ ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace, if (colorspace == u_colorspace_auto) { /* Auto detect sRGB or raw if none specified. */ if (is_float) { - bool srgb = (strcmp(file_colorspace, "sRGB") == 0 || - strcmp(file_colorspace, "GammaCorrected") == 0 || - (file_colorspace[0] == '\0' && - (strcmp(file_format, "png") == 0 || strcmp(file_format, "jpeg") == 0 || - strcmp(file_format, "tiff") == 0 || strcmp(file_format, "dpx") == 0 || - strcmp(file_format, "jpeg2000") == 0))); + const bool srgb = (strcmp(file_colorspace, "sRGB") == 0 || + strcmp(file_colorspace, "GammaCorrected") == 0 || + (file_colorspace[0] == '\0' && + (strcmp(file_format, "png") == 0 || strcmp(file_format, "jpeg") == 0 || + strcmp(file_format, "tiff") == 0 || strcmp(file_format, "dpx") == 0 || + strcmp(file_format, "jpeg2000") == 0))); return srgb ? u_colorspace_srgb : u_colorspace_raw; } - else { - return u_colorspace_srgb; - } + return u_colorspace_srgb; } - else if (colorspace == u_colorspace_srgb || colorspace == u_colorspace_raw) { - /* Builtin colorspaces. */ + + /* Builtin colorspaces. */ + if (colorspace == u_colorspace_srgb || colorspace == u_colorspace_raw) { return colorspace; } - else { - /* Use OpenColorIO. */ + + /* Use OpenColorIO. */ #ifdef WITH_OCIO - { - thread_scoped_lock cache_lock(cache_colorspaces_mutex); - /* Cached lookup. */ - if (cached_colorspaces.find(colorspace) != cached_colorspaces.end()) { - return cached_colorspaces[colorspace]; - } - } - - /* Detect if it matches a simple builtin colorspace. */ - bool is_scene_linear, is_srgb; - is_builtin_colorspace(colorspace, is_scene_linear, is_srgb); - + { thread_scoped_lock cache_lock(cache_colorspaces_mutex); - if (is_scene_linear) { - VLOG_INFO << "Colorspace " << colorspace.string() << " is no-op"; - cached_colorspaces[colorspace] = u_colorspace_raw; - return u_colorspace_raw; + /* Cached lookup. */ + if (cached_colorspaces.find(colorspace) != cached_colorspaces.end()) { + return cached_colorspaces[colorspace]; } - else if (is_srgb) { - VLOG_INFO << "Colorspace " << colorspace.string() << " is sRGB"; - cached_colorspaces[colorspace] = u_colorspace_srgb; - return u_colorspace_srgb; - } - - /* Verify if we can convert from the requested color space. */ - if (!get_processor(colorspace)) { - OCIO::ConstConfigRcPtr config = nullptr; - try { - config = OCIO::GetCurrentConfig(); - } - catch (OCIO::Exception &exception) { - VLOG_WARNING << "OCIO config error: " << exception.what(); - return u_colorspace_raw; - } - - if (!config || !config->getColorSpace(colorspace.c_str())) { - VLOG_WARNING << "Colorspace " << colorspace.c_str() << " not found, using raw instead"; - } - else { - VLOG_WARNING << "Colorspace " << colorspace.c_str() - << " can't be converted to scene_linear, using raw instead"; - } - cached_colorspaces[colorspace] = u_colorspace_raw; - return u_colorspace_raw; - } - - /* Convert to/from colorspace with OpenColorIO. */ - VLOG_INFO << "Colorspace " << colorspace.string() << " handled through OpenColorIO"; - cached_colorspaces[colorspace] = colorspace; - return colorspace; -#else - VLOG_WARNING << "Colorspace " << colorspace.c_str() - << " not available, built without OpenColorIO"; - return u_colorspace_raw; -#endif } + + /* Detect if it matches a simple builtin colorspace. */ + bool is_scene_linear, is_srgb; + is_builtin_colorspace(colorspace, is_scene_linear, is_srgb); + + thread_scoped_lock cache_lock(cache_colorspaces_mutex); + if (is_scene_linear) { + VLOG_INFO << "Colorspace " << colorspace.string() << " is no-op"; + cached_colorspaces[colorspace] = u_colorspace_raw; + return u_colorspace_raw; + } + if (is_srgb) { + VLOG_INFO << "Colorspace " << colorspace.string() << " is sRGB"; + cached_colorspaces[colorspace] = u_colorspace_srgb; + return u_colorspace_srgb; + } + + /* Verify if we can convert from the requested color space. */ + if (!get_processor(colorspace)) { + OCIO::ConstConfigRcPtr config = nullptr; + try { + config = OCIO::GetCurrentConfig(); + } + catch (const OCIO::Exception &exception) { + VLOG_WARNING << "OCIO config error: " << exception.what(); + return u_colorspace_raw; + } + + if (!config || !config->getColorSpace(colorspace.c_str())) { + VLOG_WARNING << "Colorspace " << colorspace.c_str() << " not found, using raw instead"; + } + else { + VLOG_WARNING << "Colorspace " << colorspace.c_str() + << " can't be converted to scene_linear, using raw instead"; + } + cached_colorspaces[colorspace] = u_colorspace_raw; + return u_colorspace_raw; + } + + /* Convert to/from colorspace with OpenColorIO. */ + VLOG_INFO << "Colorspace " << colorspace.string() << " handled through OpenColorIO"; + cached_colorspaces[colorspace] = colorspace; + return colorspace; +#else + VLOG_WARNING << "Colorspace " << colorspace.c_str() + << " not available, built without OpenColorIO"; + return u_colorspace_raw; +#endif } void ColorSpaceManager::is_builtin_colorspace(ustring colorspace, diff --git a/intern/cycles/scene/colorspace.h b/intern/cycles/scene/colorspace.h index c475990905e..4cc2893b882 100644 --- a/intern/cycles/scene/colorspace.h +++ b/intern/cycles/scene/colorspace.h @@ -4,7 +4,6 @@ #pragma once -#include "util/map.h" #include "util/param.h" CCL_NAMESPACE_BEGIN @@ -50,7 +49,7 @@ class ColorSpaceManager { static void init_fallback_config(); private: - static void is_builtin_colorspace(ustring colorspace, bool &is_no_op, bool &is_srgb); + static void is_builtin_colorspace(ustring colorspace, bool &is_scene_linear, bool &is_srgb); }; CCL_NAMESPACE_END diff --git a/intern/cycles/scene/constant_fold.cpp b/intern/cycles/scene/constant_fold.cpp index 0be3a23ab1c..c753fe66ba0 100644 --- a/intern/cycles/scene/constant_fold.cpp +++ b/intern/cycles/scene/constant_fold.cpp @@ -155,12 +155,12 @@ bool ConstantFolder::try_bypass_or_make_constant(ShaderInput *input, bool clamp) if (input->type() != output->type()) { return false; } - else if (!input->link) { + if (!input->link) { if (input->type() == SocketType::FLOAT) { make_constant_clamp(node->get_float(input->socket_type), clamp); return true; } - else if (SocketType::is_float3(input->type())) { + if (SocketType::is_float3(input->type())) { make_constant_clamp(node->get_float3(input->socket_type), clamp); return true; } @@ -187,7 +187,7 @@ bool ConstantFolder::is_zero(ShaderInput *input) const if (input->type() == SocketType::FLOAT) { return node->get_float(input->socket_type) == 0.0f; } - else if (SocketType::is_float3(input->type())) { + if (SocketType::is_float3(input->type())) { return node->get_float3(input->socket_type) == zero_float3(); } } @@ -201,7 +201,7 @@ bool ConstantFolder::is_one(ShaderInput *input) const if (input->type() == SocketType::FLOAT) { return node->get_float(input->socket_type) == 1.0f; } - else if (SocketType::is_float3(input->type())) { + if (SocketType::is_float3(input->type())) { return node->get_float3(input->socket_type) == one_float3(); } } diff --git a/intern/cycles/scene/curves.cpp b/intern/cycles/scene/curves.cpp index d5f5aca9730..79c1efd0a4f 100644 --- a/intern/cycles/scene/curves.cpp +++ b/intern/cycles/scene/curves.cpp @@ -3,15 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "scene/curves.h" -#include "device/device.h" -#include "scene/mesh.h" -#include "scene/object.h" -#include "scene/scene.h" #include "util/foreach.h" -#include "util/map.h" -#include "util/progress.h" -#include "util/vector.h" +#include "util/math.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/scene/curves.h b/intern/cycles/scene/curves.h index 283e22b5b7c..65100aacb4a 100644 --- a/intern/cycles/scene/curves.h +++ b/intern/cycles/scene/curves.h @@ -7,8 +7,6 @@ #include "util/array.h" #include "util/types.h" -#include "scene/hair.h" - CCL_NAMESPACE_BEGIN class Device; diff --git a/intern/cycles/scene/film.cpp b/intern/cycles/scene/film.cpp index 8c151018fa8..30a8589755f 100644 --- a/intern/cycles/scene/film.cpp +++ b/intern/cycles/scene/film.cpp @@ -127,7 +127,7 @@ NODE_DEFINE(Film) Film::Film() : Node(get_node_type()), filter_table_offset_(TABLE_OFFSET_INVALID) {} -Film::~Film() {} +Film::~Film() = default; void Film::add_default(Scene *scene) { @@ -240,7 +240,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene) assert(pass->get_type() <= PASS_CATEGORY_BAKE_END); } - if (pass->get_lightgroup() != ustring()) { + if (!pass->get_lightgroup().empty()) { if (!have_lightgroup) { kfilm->pass_lightgroup = kfilm->pass_stride; have_lightgroup = true; @@ -432,7 +432,7 @@ int Film::get_aov_offset(Scene *scene, string name, bool &is_color) is_color = false; return offset_value; } - else if (pass->get_type() == PASS_AOV_COLOR) { + if (pass->get_type() == PASS_AOV_COLOR) { is_color = true; return offset_color; } diff --git a/intern/cycles/scene/film.h b/intern/cycles/scene/film.h index 15f8367e5b4..a94148a09ee 100644 --- a/intern/cycles/scene/film.h +++ b/intern/cycles/scene/film.h @@ -6,7 +6,6 @@ #include "scene/pass.h" #include "util/string.h" -#include "util/vector.h" #include "kernel/types.h" @@ -18,13 +17,13 @@ class Device; class DeviceScene; class Scene; -typedef enum FilterType { +enum FilterType { FILTER_BOX, FILTER_GAUSSIAN, FILTER_BLACKMAN_HARRIS, FILTER_NUM_TYPES, -} FilterType; +}; class Film : public Node { public: @@ -58,7 +57,7 @@ class Film : public Node { public: Film(); - ~Film(); + ~Film() override; /* add default passes to scene */ static void add_default(Scene *scene); diff --git a/intern/cycles/scene/geometry.cpp b/intern/cycles/scene/geometry.cpp index e9d7f183592..40e391624db 100644 --- a/intern/cycles/scene/geometry.cpp +++ b/intern/cycles/scene/geometry.cpp @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "bvh/bvh.h" -#include "bvh/bvh2.h" #include "device/device.h" @@ -185,7 +184,7 @@ GeometryManager::GeometryManager() need_flags_update = true; } -GeometryManager::~GeometryManager() {} +GeometryManager::~GeometryManager() = default; void GeometryManager::update_osl_globals(Device *device, Scene *scene) { @@ -804,7 +803,7 @@ void GeometryManager::device_update(Device *device, Mesh *mesh = static_cast(geom); if (mesh->need_tesselation()) { string msg = "Tessellating "; - if (mesh->name == "") { + if (mesh->name.empty()) { msg += string_printf("%u/%u", (uint)(i + 1), (uint)total_tess_needed); } else { diff --git a/intern/cycles/scene/geometry.h b/intern/cycles/scene/geometry.h index a5eff25089d..bf69f3b6616 100644 --- a/intern/cycles/scene/geometry.h +++ b/intern/cycles/scene/geometry.h @@ -116,7 +116,7 @@ class Geometry : public Node { /* Constructor/Destructor */ explicit Geometry(const NodeType *node_type, const Type type); - virtual ~Geometry(); + ~Geometry() override; /* Geometry */ virtual void clear(bool preserve_shaders = false); diff --git a/intern/cycles/scene/geometry_attributes.cpp b/intern/cycles/scene/geometry_attributes.cpp index d92169d349d..18640522212 100644 --- a/intern/cycles/scene/geometry_attributes.cpp +++ b/intern/cycles/scene/geometry_attributes.cpp @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "bvh/bvh.h" -#include "bvh/bvh2.h" #include "device/device.h" @@ -14,22 +13,15 @@ #include "scene/light.h" #include "scene/mesh.h" #include "scene/object.h" -#include "scene/pointcloud.h" #include "scene/scene.h" #include "scene/shader.h" #include "scene/shader_nodes.h" -#include "scene/stats.h" -#include "scene/volume.h" -#include "subd/patch_table.h" #include "subd/split.h" -#include "kernel/osl/globals.h" - #include "util/foreach.h" #include "util/log.h" #include "util/progress.h" -#include "util/task.h" CCL_NAMESPACE_BEGIN @@ -55,7 +47,7 @@ bool Geometry::need_attribute(Scene *scene, AttributeStandard std) bool Geometry::need_attribute(Scene * /*scene*/, ustring name) { - if (name == ustring()) { + if (name.empty()) { return false; } @@ -155,7 +147,7 @@ static void emit_attribute_mapping( } } -void GeometryManager::update_svm_attributes(Device *, +void GeometryManager::update_svm_attributes(Device * /*unused*/, DeviceScene *dscene, Scene *scene, vector &geom_attributes, @@ -176,9 +168,12 @@ void GeometryManager::update_svm_attributes(Device *, foreach (AttributeRequest &req, geom_attributes[i].requests) { if (req.std != ATTR_STD_NONE && scene->shader_manager->get_attribute_id(req.std) != (uint64_t)req.std) + { attr_count += 2; - else + } + else { attr_count += 1; + } } #else const size_t attr_count = geom_attributes[i].size(); diff --git a/intern/cycles/scene/geometry_bvh.cpp b/intern/cycles/scene/geometry_bvh.cpp index a3900a2ed33..768c0e92e0a 100644 --- a/intern/cycles/scene/geometry_bvh.cpp +++ b/intern/cycles/scene/geometry_bvh.cpp @@ -10,26 +10,16 @@ #include "scene/attribute.h" #include "scene/camera.h" #include "scene/geometry.h" -#include "scene/hair.h" #include "scene/light.h" #include "scene/mesh.h" #include "scene/object.h" -#include "scene/pointcloud.h" #include "scene/scene.h" #include "scene/shader.h" #include "scene/shader_nodes.h" -#include "scene/stats.h" -#include "scene/volume.h" - -#include "subd/patch_table.h" -#include "subd/split.h" - -#include "kernel/osl/globals.h" #include "util/foreach.h" #include "util/log.h" #include "util/progress.h" -#include "util/task.h" CCL_NAMESPACE_BEGIN @@ -193,8 +183,13 @@ void GeometryManager::device_update_bvh(Device *device, dscene->data.bvh.root = pack.root_index; dscene->data.bvh.use_bvh_steps = (scene->params.num_bvh_time_steps != 0); dscene->data.bvh.curve_subdivisions = scene->params.curve_subdivisions(); + +#ifdef WITH_EMBREE /* The scene handle is set in 'CPUDevice::const_copy_to' and 'OptiXDevice::const_copy_to' */ + dscene->data.device_bvh = nullptr; +#else dscene->data.device_bvh = 0; +#endif } CCL_NAMESPACE_END diff --git a/intern/cycles/scene/geometry_mesh.cpp b/intern/cycles/scene/geometry_mesh.cpp index 0dcd5031486..c4311846113 100644 --- a/intern/cycles/scene/geometry_mesh.cpp +++ b/intern/cycles/scene/geometry_mesh.cpp @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "bvh/bvh.h" -#include "bvh/bvh2.h" #include "device/device.h" @@ -19,24 +18,16 @@ #include "scene/scene.h" #include "scene/shader.h" #include "scene/shader_nodes.h" -#include "scene/stats.h" -#include "scene/volume.h" #include "subd/patch_table.h" #include "subd/split.h" -#ifdef WITH_OSL -# include "kernel/osl/globals.h" -#endif - #include "util/foreach.h" -#include "util/log.h" #include "util/progress.h" -#include "util/task.h" CCL_NAMESPACE_BEGIN -void GeometryManager::device_update_mesh(Device *, +void GeometryManager::device_update_mesh(Device * /*unused*/, DeviceScene *dscene, Scene *scene, Progress &progress) diff --git a/intern/cycles/scene/hair.cpp b/intern/cycles/scene/hair.cpp index e1b2fe3408c..7f6680aefd0 100644 --- a/intern/cycles/scene/hair.cpp +++ b/intern/cycles/scene/hair.cpp @@ -294,7 +294,7 @@ Hair::Hair() : Geometry(get_node_type(), Geometry::HAIR) curve_shape = CURVE_RIBBON; } -Hair::~Hair() {} +Hair::~Hair() = default; void Hair::resize_curves(int numcurves, int numkeys) { @@ -350,7 +350,7 @@ void Hair::copy_center_to_motion_step(const int motion_step) { Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if (attr_mP) { - float3 *keys = &curve_keys[0]; + float3 *keys = curve_keys.data(); size_t numkeys = curve_keys.size(); memcpy(attr_mP->data_float3() + motion_step * numkeys, keys, sizeof(float3) * numkeys); } @@ -598,9 +598,7 @@ bool Hair::update_shadow_transparency(Device *device, Scene *scene, Progress &pr attributes.remove(attr); return true; } - else { - return false; - } + return false; } string msg = string_printf("Computing Shadow Transparency %s", name.c_str()); diff --git a/intern/cycles/scene/hair.h b/intern/cycles/scene/hair.h index 2cb367e61f4..48b59e75849 100644 --- a/intern/cycles/scene/hair.h +++ b/intern/cycles/scene/hair.h @@ -92,14 +92,14 @@ class Hair : public Geometry { /* Constructor/Destructor */ Hair(); - ~Hair(); + ~Hair() override; /* Geometry */ void clear(bool preserve_shaders = false) override; void resize_curves(int numcurves, int numkeys); void reserve_curves(int numcurves, int numkeys); - void add_curve_key(float3 loc, float radius); + void add_curve_key(float3 co, float radius); void add_curve(int first_key, int shader); void copy_center_to_motion_step(const int motion_step); diff --git a/intern/cycles/scene/image.cpp b/intern/cycles/scene/image.cpp index c27b5bd914a..366fca77062 100644 --- a/intern/cycles/scene/image.cpp +++ b/intern/cycles/scene/image.cpp @@ -273,7 +273,7 @@ void ImageMetaData::detect_colorspace() /* Image Loader */ -ImageLoader::ImageLoader() {} +ImageLoader::ImageLoader() = default; ustring ImageLoader::osl_filepath() const { @@ -290,9 +290,7 @@ bool ImageLoader::equals(const ImageLoader *a, const ImageLoader *b) if (a == nullptr && b == nullptr) { return true; } - else { - return (a && b && typeid(*a) == typeid(*b) && a->equals(*b)); - } + return (a && b && typeid(*a) == typeid(*b) && a->equals(*b)); } bool ImageLoader::is_vdb_loader() const @@ -395,7 +393,7 @@ ImageHandle ImageManager::add_image(const string &filename, /* Since we don't have information about the exact tile format used in this code location, * just attempt all replacement patterns that Blender supports. */ if (tile != 0) { - string_replace(tile_filename, "", string_printf("%04d", (int)tile)); + string_replace(tile_filename, "", string_printf("%04d", tile)); int u = ((tile - 1001) % 10); int v = ((tile - 1001) / 10); @@ -640,7 +638,7 @@ bool ImageManager::file_load_image(Image *img, int texture_limit) } /* Scale image down if needed. */ - if (pixels_storage.size() > 0) { + if (!pixels_storage.empty()) { float scale_factor = 1.0f; while (max_size * scale_factor > texture_limit) { scale_factor *= 0.5f; @@ -811,7 +809,7 @@ void ImageManager::device_load_image(Device *device, Scene *scene, size_t slot, img->need_load = false; } -void ImageManager::device_free_image(Device *, size_t slot) +void ImageManager::device_free_image(Device * /*unused*/, size_t slot) { Image *img = images[slot]; if (img == nullptr) { diff --git a/intern/cycles/scene/image.h b/intern/cycles/scene/image.h index e6ad580fa58..eab1e887fd5 100644 --- a/intern/cycles/scene/image.h +++ b/intern/cycles/scene/image.h @@ -11,7 +11,6 @@ #include "util/string.h" #include "util/thread.h" #include "util/transform.h" -#include "util/unique_ptr.h" #include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -31,22 +30,14 @@ class VDBImageLoader; /* Image Parameters */ class ImageParams { public: - bool animated; - InterpolationType interpolation; - ExtensionType extension; - ImageAlphaType alpha_type; + bool animated = false; + InterpolationType interpolation = INTERPOLATION_LINEAR; + ExtensionType extension = EXTENSION_CLIP; + ImageAlphaType alpha_type = IMAGE_ALPHA_AUTO; ustring colorspace; - float frame; + float frame = 0.0f; - ImageParams() - : animated(false), - interpolation(INTERPOLATION_LINEAR), - extension(EXTENSION_CLIP), - alpha_type(IMAGE_ALPHA_AUTO), - colorspace(u_colorspace_raw), - frame(0.0f) - { - } + ImageParams() : colorspace(u_colorspace_raw) {} bool operator==(const ImageParams &other) const { @@ -96,7 +87,7 @@ class ImageDeviceFeatures { class ImageLoader { public: ImageLoader(); - virtual ~ImageLoader(){}; + virtual ~ImageLoader() = default; /* Load metadata without actual image yet, should be fast. */ virtual bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) = 0; diff --git a/intern/cycles/scene/image_oiio.cpp b/intern/cycles/scene/image_oiio.cpp index bc354e800b9..ed4aa22b640 100644 --- a/intern/cycles/scene/image_oiio.cpp +++ b/intern/cycles/scene/image_oiio.cpp @@ -7,12 +7,13 @@ #include "util/image.h" #include "util/log.h" #include "util/path.h" +#include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN OIIOImageLoader::OIIOImageLoader(const string &filepath) : filepath(filepath) {} -OIIOImageLoader::~OIIOImageLoader() {} +OIIOImageLoader::~OIIOImageLoader() = default; bool OIIOImageLoader::load_metadata(const ImageDeviceFeatures & /*features*/, ImageMetaData &metadata) @@ -166,7 +167,7 @@ static void oiio_load_pixels(const ImageMetaData &metadata, bool OIIOImageLoader::load_pixels(const ImageMetaData &metadata, void *pixels, - const size_t, + const size_t /*pixels_size*/, const bool associate_alpha) { unique_ptr in = nullptr; diff --git a/intern/cycles/scene/image_oiio.h b/intern/cycles/scene/image_oiio.h index 145bdb42a65..362354778b9 100644 --- a/intern/cycles/scene/image_oiio.h +++ b/intern/cycles/scene/image_oiio.h @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN class OIIOImageLoader : public ImageLoader { public: OIIOImageLoader(const string &filepath); - ~OIIOImageLoader(); + ~OIIOImageLoader() override; bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override; diff --git a/intern/cycles/scene/image_sky.cpp b/intern/cycles/scene/image_sky.cpp index 3082f864090..97e41a466cc 100644 --- a/intern/cycles/scene/image_sky.cpp +++ b/intern/cycles/scene/image_sky.cpp @@ -4,12 +4,9 @@ #include "scene/image_sky.h" -#include "sky_model.h" +#include "util/tbb.h" -#include "util/image.h" -#include "util/log.h" -#include "util/path.h" -#include "util/task.h" +#include "sky_model.h" CCL_NAMESPACE_BEGIN @@ -26,9 +23,9 @@ SkyLoader::SkyLoader(float sun_elevation, { } -SkyLoader::~SkyLoader(){}; +SkyLoader::~SkyLoader() = default; -bool SkyLoader::load_metadata(const ImageDeviceFeatures &, ImageMetaData &metadata) +bool SkyLoader::load_metadata(const ImageDeviceFeatures & /*features*/, ImageMetaData &metadata) { metadata.width = 512; metadata.height = 128; diff --git a/intern/cycles/scene/image_sky.h b/intern/cycles/scene/image_sky.h index 05d91982555..dc0b41166ce 100644 --- a/intern/cycles/scene/image_sky.h +++ b/intern/cycles/scene/image_sky.h @@ -20,7 +20,7 @@ class SkyLoader : public ImageLoader { float air_density, float dust_density, float ozone_density); - ~SkyLoader(); + ~SkyLoader() override; bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override; diff --git a/intern/cycles/scene/image_vdb.cpp b/intern/cycles/scene/image_vdb.cpp index 57efc6178be..61b79a9e2d6 100644 --- a/intern/cycles/scene/image_vdb.cpp +++ b/intern/cycles/scene/image_vdb.cpp @@ -28,7 +28,7 @@ struct NumChannelsOp { int num_channels = 0; template - bool operator()(const openvdb::GridBase::ConstPtr &) + bool operator()(const openvdb::GridBase::ConstPtr & /*unused*/) { num_channels = channels; return true; @@ -136,7 +136,7 @@ VDBImageLoader::VDBImageLoader(openvdb::GridBase::ConstPtr grid_, const string & VDBImageLoader::VDBImageLoader(const string &grid_name) : grid_name(grid_name) {} -VDBImageLoader::~VDBImageLoader() {} +VDBImageLoader::~VDBImageLoader() = default; bool VDBImageLoader::load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) { @@ -247,7 +247,10 @@ bool VDBImageLoader::load_metadata(const ImageDeviceFeatures &features, ImageMet #endif } -bool VDBImageLoader::load_pixels(const ImageMetaData &, void *pixels, const size_t, const bool) +bool VDBImageLoader::load_pixels(const ImageMetaData & /*metadata*/, + void *pixels, + const size_t /*pixels_size*/, + const bool /*associate_alpha*/) { #ifdef WITH_OPENVDB # ifdef WITH_NANOVDB diff --git a/intern/cycles/scene/image_vdb.h b/intern/cycles/scene/image_vdb.h index 08a025c9aad..e516febf9ab 100644 --- a/intern/cycles/scene/image_vdb.h +++ b/intern/cycles/scene/image_vdb.h @@ -27,23 +27,22 @@ class VDBImageLoader : public ImageLoader { VDBImageLoader(openvdb::GridBase::ConstPtr grid_, const string &grid_name); #endif VDBImageLoader(const string &grid_name); - ~VDBImageLoader(); + ~VDBImageLoader() override; - virtual bool load_metadata(const ImageDeviceFeatures &features, - ImageMetaData &metadata) override; + bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override; - virtual bool load_pixels(const ImageMetaData &metadata, - void *pixels, - const size_t pixels_size, - const bool associate_alpha) override; + bool load_pixels(const ImageMetaData &metadata, + void *pixels, + const size_t pixels_size, + const bool associate_alpha) override; - virtual string name() const override; + string name() const override; - virtual bool equals(const ImageLoader &other) const override; + bool equals(const ImageLoader &other) const override; - virtual void cleanup() override; + void cleanup() override; - virtual bool is_vdb_loader() const override; + bool is_vdb_loader() const override; #ifdef WITH_OPENVDB openvdb::GridBase::ConstPtr get_grid(); diff --git a/intern/cycles/scene/integrator.cpp b/intern/cycles/scene/integrator.cpp index 98bf7e90182..8279bd4912a 100644 --- a/intern/cycles/scene/integrator.cpp +++ b/intern/cycles/scene/integrator.cpp @@ -164,7 +164,7 @@ NODE_DEFINE(Integrator) Integrator::Integrator() : Node(get_node_type()) {} -Integrator::~Integrator() {} +Integrator::~Integrator() = default; void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene) { @@ -338,7 +338,7 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene clear_modified(); } -void Integrator::device_free(Device *, DeviceScene *dscene, bool force_free) +void Integrator::device_free(Device * /*unused*/, DeviceScene *dscene, bool force_free) { dscene->sample_pattern_lut.free_if_need_realloc(force_free); } diff --git a/intern/cycles/scene/integrator.h b/intern/cycles/scene/integrator.h index 952f620bb67..685eead4c72 100644 --- a/intern/cycles/scene/integrator.h +++ b/intern/cycles/scene/integrator.h @@ -111,7 +111,7 @@ class Integrator : public Node { }; Integrator(); - ~Integrator(); + ~Integrator() override; void device_update(Device *device, DeviceScene *dscene, Scene *scene); void device_free(Device *device, DeviceScene *dscene, bool force_free = false); diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp index 53d1fd989e6..9a70b1dd119 100644 --- a/intern/cycles/scene/light.cpp +++ b/intern/cycles/scene/light.cpp @@ -24,8 +24,6 @@ #include "util/log.h" #include "util/path.h" #include "util/progress.h" -#include "util/task.h" -#include CCL_NAMESPACE_BEGIN @@ -281,7 +279,7 @@ void LightManager::test_enabled_lights(Scene *scene) } } -void LightManager::device_update_distribution(Device *, +void LightManager::device_update_distribution(Device * /*unused*/, DeviceScene *dscene, Scene *scene, Progress &progress) @@ -396,7 +394,7 @@ void LightManager::device_update_distribution(Device *, offset++; Mesh::Triangle t = mesh->get_triangle(i); - if (!t.valid(&mesh->get_verts()[0])) { + if (!t.valid(mesh->get_verts().data())) { continue; } float3 p1 = mesh->get_verts()[t.v[0]]; @@ -797,7 +795,7 @@ static std::pair light_tree_specialize_nodes_flatten( return std::make_pair(node_index, new_node.measure); } -void LightManager::device_update_tree(Device *, +void LightManager::device_update_tree(Device * /*unused*/, DeviceScene *dscene, Scene *scene, Progress &progress) @@ -1461,7 +1459,9 @@ void LightManager::device_update(Device *device, need_update_background = false; } -void LightManager::device_free(Device *, DeviceScene *dscene, const bool free_background) +void LightManager::device_free(Device * /*unused*/, + DeviceScene *dscene, + const bool free_background) { dscene->light_tree_nodes.free(); dscene->light_tree_emitters.free(); @@ -1494,7 +1494,7 @@ int LightManager::add_ies_from_file(const string &filename) string content; /* If the file can't be opened, call with an empty line */ - if (filename.empty() || !path_read_text(filename.c_str(), content)) { + if (filename.empty() || !path_read_text(filename, content)) { content = "\n"; } @@ -1574,14 +1574,12 @@ void LightManager::device_update_ies(DeviceScene *dscene) /* If the preceding slot has users, we found the new end of the table. */ break; } - else { - /* The slot will be past the new end of the table, so free it. */ - delete ies_slots[slot_end - 1]; - } + /* The slot will be past the new end of the table, so free it. */ + delete ies_slots[slot_end - 1]; } ies_slots.resize(slot_end); - if (ies_slots.size() > 0) { + if (!ies_slots.empty()) { int packed_size = 0; foreach (IESSlot *slot, ies_slots) { packed_size += slot->ies.packed_size(); diff --git a/intern/cycles/scene/light.h b/intern/cycles/scene/light.h index b9776152083..abae510a299 100644 --- a/intern/cycles/scene/light.h +++ b/intern/cycles/scene/light.h @@ -120,7 +120,7 @@ class LightManager { ~LightManager(); /* IES texture management */ - int add_ies(const string &ies); + int add_ies(const string &content); int add_ies_from_file(const string &filename); void remove_ies(int slot); diff --git a/intern/cycles/scene/light_tree.h b/intern/cycles/scene/light_tree.h index 57f65792c40..195618a25e3 100644 --- a/intern/cycles/scene/light_tree.h +++ b/intern/cycles/scene/light_tree.h @@ -25,7 +25,7 @@ struct OrientationBounds { float theta_o; /* angle bounding the normals */ float theta_e; /* angle bounding the light emissions */ - __forceinline OrientationBounds() {} + __forceinline OrientationBounds() = default; __forceinline OrientationBounds(const float3 &axis_, float theta_o_, float theta_e_) : axis(axis_), theta_o(theta_o_), theta_e(theta_e_) @@ -37,7 +37,7 @@ struct OrientationBounds { /* If the orientation bound is set to empty, the values are set to minimums * so that merging it with another non-empty orientation bound guarantees that * the return value is equal to non-empty orientation bound. */ - __forceinline OrientationBounds(empty_t) + __forceinline OrientationBounds(empty_t /*unused*/) : axis(make_float3(0, 0, 0)), theta_o(FLT_MIN), theta_e(FLT_MIN) { } @@ -69,7 +69,7 @@ struct LightTreeMeasure { __forceinline LightTreeMeasure() = default; - __forceinline LightTreeMeasure(empty_t) {} + __forceinline LightTreeMeasure(empty_t /*unused*/) {} __forceinline LightTreeMeasure(const BoundBox &bbox, const OrientationBounds &bcone, @@ -79,9 +79,8 @@ struct LightTreeMeasure { } __forceinline LightTreeMeasure(const LightTreeMeasure &other) - : bbox(other.bbox), bcone(other.bcone), energy(other.energy) - { - } + + = default; __forceinline bool is_zero() const { @@ -191,7 +190,7 @@ struct LightTreeEmitter { LightTreeMeasure measure; LightTreeEmitter(Object *object, int object_id); /* Mesh emitter. */ - LightTreeEmitter(Scene *scene, int prim_id, int object_id, bool with_transformation = false); + LightTreeEmitter(Scene *scene, int prim_id, int object_id, bool need_transformation = false); __forceinline bool is_mesh() const { diff --git a/intern/cycles/scene/mesh.cpp b/intern/cycles/scene/mesh.cpp index 6f2f3555492..5fd517cd2c9 100644 --- a/intern/cycles/scene/mesh.cpp +++ b/intern/cycles/scene/mesh.cpp @@ -7,7 +7,6 @@ #include "device/device.h" -#include "scene/hair.h" #include "scene/mesh.h" #include "scene/object.h" #include "scene/scene.h" @@ -18,7 +17,6 @@ #include "util/foreach.h" #include "util/log.h" -#include "util/progress.h" #include "util/set.h" CCL_NAMESPACE_BEGIN @@ -424,7 +422,7 @@ void Mesh::copy_center_to_motion_step(const int motion_step) if (attr_mP) { Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL); Attribute *attr_N = attributes.find(ATTR_STD_VERTEX_NORMAL); - float3 *P = &verts[0]; + float3 *P = verts.data(); float3 *N = (attr_N) ? attr_N->data_float3() : nullptr; size_t numverts = verts.size(); diff --git a/intern/cycles/scene/mesh.h b/intern/cycles/scene/mesh.h index edf4810dd82..a0f04a55069 100644 --- a/intern/cycles/scene/mesh.h +++ b/intern/cycles/scene/mesh.h @@ -6,19 +6,16 @@ #include "graph/node.h" -#include "bvh/params.h" #include "scene/attribute.h" #include "scene/geometry.h" #include "scene/shader.h" #include "util/array.h" #include "util/boundbox.h" -#include "util/list.h" #include "util/map.h" #include "util/param.h" #include "util/set.h" #include "util/types.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -187,10 +184,10 @@ class Mesh : public Geometry { public: /* Functions */ Mesh(); - ~Mesh(); + ~Mesh() override; - void resize_mesh(int numverts, int numfaces); - void reserve_mesh(int numverts, int numfaces); + void resize_mesh(int numverts, int numtris); + void reserve_mesh(int numverts, int numtris); void resize_subd_faces(int numfaces, int num_ngons, int numcorners); void reserve_subd_faces(int numfaces, int num_ngons, int numcorners); void reserve_subd_creases(size_t num_creases); diff --git a/intern/cycles/scene/mesh_displace.cpp b/intern/cycles/scene/mesh_displace.cpp index f15414d3c0c..0c72d5cf55b 100644 --- a/intern/cycles/scene/mesh_displace.cpp +++ b/intern/cycles/scene/mesh_displace.cpp @@ -202,7 +202,7 @@ bool GeometryManager::displace(Device *device, Scene *scene, Mesh *mesh, Progres stitch_keys.insert(i.second); /* stitching index */ } - typedef unordered_multimap::iterator map_it_t; + using map_it_t = unordered_multimap::iterator; for (int key : stitch_keys) { pair verts = mesh->vert_stitching_map.equal_range(key); @@ -287,7 +287,7 @@ bool GeometryManager::displace(Device *device, Scene *scene, Mesh *mesh, Progres vN[vert] += fN[i]; /* add face normals to stitched vertices */ - if (stitch_keys.size()) { + if (!stitch_keys.empty()) { map_it_t key = mesh->vert_to_stitching_key_map.find(vert); if (key != mesh->vert_to_stitching_key_map.end()) { @@ -357,7 +357,7 @@ bool GeometryManager::displace(Device *device, Scene *scene, Mesh *mesh, Progres mN[vert] += fN; /* add face normals to stitched vertices */ - if (stitch_keys.size()) { + if (!stitch_keys.empty()) { map_it_t key = mesh->vert_to_stitching_key_map.find(vert); if (key != mesh->vert_to_stitching_key_map.end()) { diff --git a/intern/cycles/scene/mesh_subdivision.cpp b/intern/cycles/scene/mesh_subdivision.cpp index b1e996993c9..7469c0efcec 100644 --- a/intern/cycles/scene/mesh_subdivision.cpp +++ b/intern/cycles/scene/mesh_subdivision.cpp @@ -12,7 +12,6 @@ #include "util/algorithm.h" #include "util/foreach.h" -#include "util/hash.h" CCL_NAMESPACE_BEGIN @@ -27,9 +26,7 @@ CCL_NAMESPACE_END /* specializations of TopologyRefinerFactory for ccl::Mesh */ -namespace OpenSubdiv { -namespace OPENSUBDIV_VERSION { -namespace Far { +namespace OpenSubdiv::v3_6_0::Far { template<> bool TopologyRefinerFactory::resizeComponentTopology(TopologyRefiner &refiner, ccl::Mesh const &mesh) @@ -138,9 +135,7 @@ void TopologyRefinerFactory::reportInvalidTopology(TopologyError /*er ccl::Mesh const & /*mesh*/) { } -} /* namespace Far */ -} /* namespace OPENSUBDIV_VERSION */ -} /* namespace OpenSubdiv */ +} // namespace OpenSubdiv::v3_6_0::Far CCL_NAMESPACE_BEGIN @@ -151,9 +146,9 @@ using namespace OpenSubdiv; template struct OsdValue { T value; - OsdValue() {} + OsdValue() = default; - void Clear(void * = 0) + void Clear(void * /*unused*/ = nullptr) { memset(&value, 0, sizeof(T)); } @@ -174,14 +169,14 @@ template<> void OsdValue::AddWithWeight(OsdValue const &src, flo /* class for holding OpenSubdiv data used during tessellation */ class OsdData { - Mesh *mesh; + Mesh *mesh = nullptr; vector> verts; - Far::TopologyRefiner *refiner; - Far::PatchTable *patch_table; - Far::PatchMap *patch_map; + Far::TopologyRefiner *refiner = nullptr; + Far::PatchTable *patch_table = nullptr; + Far::PatchMap *patch_map = nullptr; public: - OsdData() : mesh(nullptr), refiner(nullptr), patch_table(nullptr), patch_map(nullptr) {} + OsdData() = default; ~OsdData() { @@ -231,7 +226,7 @@ class OsdData { } if (num_local_points) { - patch_table->ComputeLocalPointValues(&verts[0], &verts[num_refiner_verts]); + patch_table->ComputeLocalPointValues(verts.data(), &verts[num_refiner_verts]); } /* create patch map */ @@ -254,15 +249,15 @@ class OsdData { for (int i = 0; i < refiner->GetMaxLevel(); i++) { char *dest = src + refiner->GetLevel(i).GetNumVertices() * attr.data_sizeof(); - if (attr.same_storage(attr.type, TypeFloat)) { + if (ccl::Attribute::same_storage(attr.type, TypeFloat)) { primvar_refiner.Interpolate(i + 1, (OsdValue *)src, (OsdValue *&)dest); } - else if (attr.same_storage(attr.type, TypeFloat2)) { + else if (ccl::Attribute::same_storage(attr.type, TypeFloat2)) { primvar_refiner.Interpolate(i + 1, (OsdValue *)src, (OsdValue *&)dest); // float3 is not interchangeable with float4 and so needs to be handled // separately } - else if (attr.same_storage(attr.type, TypeFloat4)) { + else if (ccl::Attribute::same_storage(attr.type, TypeFloat4)) { primvar_refiner.Interpolate(i + 1, (OsdValue *)src, (OsdValue *&)dest); } else { @@ -273,28 +268,28 @@ class OsdData { } if (num_local_points) { - if (attr.same_storage(attr.type, TypeFloat)) { + if (ccl::Attribute::same_storage(attr.type, TypeFloat)) { patch_table->ComputeLocalPointValues( - (OsdValue *)&attr.buffer[0], + (OsdValue *)attr.buffer.data(), (OsdValue *)&attr.buffer[num_refiner_verts * attr.data_sizeof()]); } - else if (attr.same_storage(attr.type, TypeFloat2)) { + else if (ccl::Attribute::same_storage(attr.type, TypeFloat2)) { patch_table->ComputeLocalPointValues( - (OsdValue *)&attr.buffer[0], + (OsdValue *)attr.buffer.data(), (OsdValue *)&attr.buffer[num_refiner_verts * attr.data_sizeof()]); } - else if (attr.same_storage(attr.type, TypeFloat4)) { + else if (ccl::Attribute::same_storage(attr.type, TypeFloat4)) { // float3 is not interchangeable with float4 and so needs to be handled // separately patch_table->ComputeLocalPointValues( - (OsdValue *)&attr.buffer[0], + (OsdValue *)attr.buffer.data(), (OsdValue *)&attr.buffer[num_refiner_verts * attr.data_sizeof()]); } else { // float3 is not interchangeable with float4 and so needs to be handled // separately patch_table->ComputeLocalPointValues( - (OsdValue *)&attr.buffer[0], + (OsdValue *)attr.buffer.data(), (OsdValue *)&attr.buffer[num_refiner_verts * attr.data_sizeof()]); } } @@ -350,10 +345,10 @@ class OsdData { struct OsdPatch : Patch { OsdData *osd_data; - OsdPatch() {} + OsdPatch() = default; OsdPatch(OsdData *data) : osd_data(data) {} - void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) + void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) override { const Far::PatchTable::PatchHandle *handle = osd_data->patch_map->FindPatch( patch_index, (double)u, (double)v); @@ -365,24 +360,28 @@ struct OsdPatch : Patch { Far::ConstIndexArray cv = osd_data->patch_table->GetPatchVertices(*handle); float3 du, dv; - if (P) + if (P) { *P = zero_float3(); + } du = zero_float3(); dv = zero_float3(); for (int i = 0; i < cv.size(); i++) { float3 p = osd_data->verts[cv[i]].value; - if (P) + if (P) { *P += p * p_weights[i]; + } du += p * du_weights[i]; dv += p * dv_weights[i]; } - if (dPdu) + if (dPdu) { *dPdu = du; - if (dPdv) + } + if (dPdv) { *dPdv = dv; + } if (N) { *N = cross(du, dv); diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp index 21a86758665..cf501f2852b 100644 --- a/intern/cycles/scene/object.cpp +++ b/intern/cycles/scene/object.cpp @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "scene/object.h" + #include "device/device.h" #include "scene/camera.h" #include "scene/curves.h" @@ -22,7 +23,7 @@ #include "util/murmurhash.h" #include "util/progress.h" #include "util/set.h" -#include "util/task.h" +#include "util/tbb.h" #include "util/vector.h" #include "subd/patch_table.h" @@ -120,7 +121,7 @@ Object::Object() : Node(get_node_type()) intersects_volume = false; } -Object::~Object() {} +Object::~Object() = default; void Object::update_motion() { @@ -141,10 +142,8 @@ void Object::update_motion() motion.clear(); return; } - else { - /* Otherwise just copy center motion. */ - motion[i] = tfm; - } + /* Otherwise just copy center motion. */ + motion[i] = tfm; } /* Test if any of the transforms are actually different. */ @@ -344,7 +343,9 @@ float Object::compute_volume_step_size() const metadata.type != IMAGE_DATA_TYPE_NANOVDB_FPN && metadata.type != IMAGE_DATA_TYPE_NANOVDB_FP16) #endif + { size /= make_float3(metadata.width, metadata.height, metadata.depth); + } /* Step size is transformed from voxel to world space. */ Transform voxel_tfm = tfm; @@ -446,7 +447,7 @@ ObjectManager::ObjectManager() need_flags_update = true; } -ObjectManager::~ObjectManager() {} +ObjectManager::~ObjectManager() = default; static float object_volume_density(const Transform &tfm, Geometry *geom) { @@ -780,7 +781,7 @@ void ObjectManager::device_update(Device *device, device_free(device, dscene, false); - if (scene->objects.size() == 0) { + if (scene->objects.empty()) { return; } @@ -844,8 +845,11 @@ void ObjectManager::device_update(Device *device, } } -void ObjectManager::device_update_flags( - Device *, DeviceScene *dscene, Scene *scene, Progress & /*progress*/, bool bounds_valid) +void ObjectManager::device_update_flags(Device * /*unused*/, + DeviceScene *dscene, + Scene *scene, + Progress & /*progress*/, + bool bounds_valid) { if (!need_update() && !need_flags_update) { return; @@ -867,7 +871,7 @@ void ObjectManager::device_update_flags( need_flags_update = false; } - if (scene->objects.size() == 0) { + if (scene->objects.empty()) { return; } @@ -948,7 +952,9 @@ void ObjectManager::device_update_flags( dscene->object_volume_step.clear_modified(); } -void ObjectManager::device_update_geom_offsets(Device *, DeviceScene *dscene, Scene *scene) +void ObjectManager::device_update_geom_offsets(Device * /*unused*/, + DeviceScene *dscene, + Scene *scene) { if (dscene->objects.size() == 0) { return; @@ -993,7 +999,7 @@ void ObjectManager::device_update_geom_offsets(Device *, DeviceScene *dscene, Sc } } -void ObjectManager::device_free(Device *, DeviceScene *dscene, bool force_free) +void ObjectManager::device_free(Device * /*unused*/, DeviceScene *dscene, bool force_free) { dscene->objects.free_if_need_realloc(force_free); dscene->object_motion_pass.free_if_need_realloc(force_free); diff --git a/intern/cycles/scene/object.h b/intern/cycles/scene/object.h index 98139378a7e..895afafd4ea 100644 --- a/intern/cycles/scene/object.h +++ b/intern/cycles/scene/object.h @@ -16,7 +16,6 @@ #include "util/array.h" #include "util/boundbox.h" #include "util/param.h" -#include "util/thread.h" #include "util/transform.h" #include "util/types.h" #include "util/vector.h" @@ -79,7 +78,7 @@ class Object : public Node { bool intersects_volume; Object(); - ~Object(); + ~Object() override; void tag_update(Scene *scene); diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp index 6d788795754..eced41c45a9 100644 --- a/intern/cycles/scene/osl.cpp +++ b/intern/cycles/scene/osl.cpp @@ -96,8 +96,9 @@ void OSLShaderManager::device_update_specific(Device *device, Scene *scene, Progress &progress) { - if (!need_update()) + if (!need_update()) { return; + } scoped_callback_timer timer([scene](double time) { if (scene->update_stats) { @@ -154,8 +155,9 @@ void OSLShaderManager::device_update_specific(Device *device, } }); - if (shader->emission_sampling != EMISSION_SAMPLING_NONE) + if (shader->emission_sampling != EMISSION_SAMPLING_NONE) { scene->light_manager->tag_update(scene, LightManager::SHADER_COMPILED); + } } /* setup shader engine */ @@ -368,7 +370,7 @@ void OSLShaderManager::shading_system_init() }; const int nraytypes = sizeof(raytypes) / sizeof(raytypes[0]); - ss->attribute("raytypes", TypeDesc(TypeDesc::STRING, nraytypes), raytypes); + ss->attribute("raytypes", TypeDesc(TypeDesc::STRING, nraytypes), (const void *)raytypes); OSLRenderServices::register_closures(ss); @@ -471,8 +473,9 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) if (oso_modified_time != 0) { const char *hash = shader_test_loaded(shader_filepath_hash(osopath, oso_modified_time)); - if (hash) + if (hash) { return hash; + } } /* Auto-compile .OSL to .OSO if needed. */ @@ -480,8 +483,9 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) OSLShaderManager::osl_compile(filepath, osopath); modified_time = path_modified_time(osopath); } - else + else { modified_time = oso_modified_time; + } filepath = osopath; } @@ -489,7 +493,7 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) if (extension == ".oso") { /* .OSO File, nothing to do */ } - else if (path_dirname(filepath) == "") { + else if (path_dirname(filepath).empty()) { /* .OSO File in search path */ filepath = path_join(path_user_get("shaders"), filepath + ".oso"); } @@ -501,8 +505,9 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) /* test if we have loaded this .OSO already */ const char *hash = shader_test_loaded(shader_filepath_hash(filepath, modified_time)); - if (hash) + if (hash) { return hash; + } } /* read oso bytecode from file */ @@ -522,7 +527,7 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) const char *OSLShaderManager::shader_load_bytecode(const string &hash, const string &bytecode) { for (const auto &[device_type, ss] : ss_shared) { - ss->LoadMemoryCompiledShader(hash.c_str(), bytecode.c_str()); + ss->LoadMemoryCompiledShader(hash, bytecode); } OSLShaderInfo info; @@ -562,8 +567,9 @@ OSLNode *OSLShaderManager::osl_node(ShaderGraph *graph, } else { hash = osl_manager->shader_test_loaded(bytecode_hash); - if (!hash) + if (!hash) { hash = osl_manager->shader_load_bytecode(bytecode_hash, bytecode); + } } if (!hash) { @@ -579,11 +585,13 @@ OSLNode *OSLShaderManager::osl_node(ShaderGraph *graph, const OSL::OSLQuery::Parameter *param = info->query.getparam(i); /* skip unsupported types */ - if (param->varlenarray || param->isstruct || param->type.arraylen > 1) + if (param->varlenarray || param->isstruct || param->type.arraylen > 1) { continue; + } - if (!param->isoutput) + if (!param->isoutput) { num_inputs++; + } } /* create node */ @@ -596,8 +604,9 @@ OSLNode *OSLShaderManager::osl_node(ShaderGraph *graph, const OSL::OSLQuery::Parameter *param = info->query.getparam(i); /* skip unsupported types */ - if (param->varlenarray || param->isstruct || param->type.arraylen > 1) + if (param->varlenarray || param->isstruct || param->type.arraylen > 1) { continue; + } SocketType::Type socket_type; @@ -606,16 +615,21 @@ OSLNode *OSLShaderManager::osl_node(ShaderGraph *graph, socket_type = SocketType::CLOSURE; } else if (param->type.vecsemantics != TypeDesc::NOSEMANTICS) { - if (param->type.vecsemantics == TypeDesc::COLOR) + if (param->type.vecsemantics == TypeDesc::COLOR) { socket_type = SocketType::COLOR; - else if (param->type.vecsemantics == TypeDesc::POINT) + } + else if (param->type.vecsemantics == TypeDesc::POINT) { socket_type = SocketType::POINT; - else if (param->type.vecsemantics == TypeDesc::VECTOR) + } + else if (param->type.vecsemantics == TypeDesc::VECTOR) { socket_type = SocketType::VECTOR; - else if (param->type.vecsemantics == TypeDesc::NORMAL) + } + else if (param->type.vecsemantics == TypeDesc::NORMAL) { socket_type = SocketType::NORMAL; - else + } + else { continue; + } if (!param->isoutput && param->validdefault) { float3 *default_value = (float3 *)node->input_default_value(); @@ -646,11 +660,13 @@ OSLNode *OSLShaderManager::osl_node(ShaderGraph *graph, *(ustring *)node->input_default_value() = param->sdefault[0]; } } - else + else { continue; + } } - else + else { continue; + } if (param->isoutput) { node->add_output(param->name, socket_type); @@ -742,8 +758,9 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input) size_t i; /* Strip white-space. */ - while ((i = sname.find(" ")) != string::npos) + while ((i = sname.find(" ")) != string::npos) { sname.replace(i, 1, ""); + } /* if output exists with the same name, add "In" suffix */ foreach (ShaderOutput *output, node->outputs) { @@ -762,8 +779,9 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output) size_t i; /* Strip white-space. */ - while ((i = sname.find(" ")) != string::npos) + while ((i = sname.find(" ")) != string::npos) { sname.replace(i, 1, ""); + } /* if input exists with the same name, add "Out" suffix */ foreach (ShaderInput *input, node->inputs) { @@ -781,26 +799,34 @@ bool OSLCompiler::node_skip_input(ShaderNode *node, ShaderInput *input) /* exception for output node, only one input is actually used * depending on the current shader type */ - if (input->flags() & SocketType::SVM_INTERNAL) + if (input->flags() & SocketType::SVM_INTERNAL) { return true; + } if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT) { - if (input->name() == "Surface" && current_type != SHADER_TYPE_SURFACE) + if (input->name() == "Surface" && current_type != SHADER_TYPE_SURFACE) { return true; - if (input->name() == "Volume" && current_type != SHADER_TYPE_VOLUME) + } + if (input->name() == "Volume" && current_type != SHADER_TYPE_VOLUME) { return true; - if (input->name() == "Displacement" && current_type != SHADER_TYPE_DISPLACEMENT) + } + if (input->name() == "Displacement" && current_type != SHADER_TYPE_DISPLACEMENT) { return true; - if (input->name() == "Normal" && current_type != SHADER_TYPE_BUMP) + } + if (input->name() == "Normal" && current_type != SHADER_TYPE_BUMP) { return true; + } } else if (node->special_type == SHADER_SPECIAL_TYPE_BUMP) { - if (input->name() == "Height") + if (input->name() == "Height") { return true; + } } else if (current_type == SHADER_TYPE_DISPLACEMENT && input->link && input->link->parent->special_type == SHADER_SPECIAL_TYPE_BUMP) + { return true; + } return false; } @@ -811,8 +837,9 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath) if (isfilepath) { name = manager->shader_load_filepath(name); - if (name == nullptr) + if (name == nullptr) { return; + } } /* pass in fixed parameter values */ @@ -860,22 +887,28 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath) /* Create shader of the appropriate type. OSL only distinguishes between "surface" * and "displacement" at the moment. */ - if (current_type == SHADER_TYPE_SURFACE) - ss->Shader(*current_group, "surface", name, id(node).c_str()); - else if (current_type == SHADER_TYPE_VOLUME) - ss->Shader(*current_group, "surface", name, id(node).c_str()); - else if (current_type == SHADER_TYPE_DISPLACEMENT) - ss->Shader(*current_group, "displacement", name, id(node).c_str()); - else if (current_type == SHADER_TYPE_BUMP) - ss->Shader(*current_group, "displacement", name, id(node).c_str()); - else + if (current_type == SHADER_TYPE_SURFACE) { + ss->Shader(*current_group, "surface", name, id(node)); + } + else if (current_type == SHADER_TYPE_VOLUME) { + ss->Shader(*current_group, "surface", name, id(node)); + } + else if (current_type == SHADER_TYPE_DISPLACEMENT) { + ss->Shader(*current_group, "displacement", name, id(node)); + } + else if (current_type == SHADER_TYPE_BUMP) { + ss->Shader(*current_group, "displacement", name, id(node)); + } + else { assert(0); + } /* link inputs to other nodes */ foreach (ShaderInput *input, node->inputs) { if (input->link) { - if (node_skip_input(node, input)) + if (node_skip_input(node, input)) { continue; + } /* connect shaders */ string id_from = id(input->link->parent); @@ -883,8 +916,7 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath) string param_from = compatible_name(input->link->parent, input->link); string param_to = compatible_name(node, input); - ss->ConnectShaders( - *current_group, id_from.c_str(), param_from.c_str(), id_to.c_str(), param_to.c_str()); + ss->ConnectShaders(*current_group, id_from, param_from, id_to, param_to); } } @@ -898,8 +930,9 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath) OSLNode *oslnode = static_cast(node); oslnode->has_emission = true; } - if (info->has_surface_transparent) + if (info->has_surface_transparent) { current_shader->has_surface_transparent = true; + } if (info->has_surface_bssrdf) { current_shader->has_surface_bssrdf = true; current_shader->has_bssrdf_bump = true; /* can't detect yet */ @@ -913,10 +946,12 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath) } } else if (current_type == SHADER_TYPE_VOLUME) { - if (node->has_spatial_varying()) + if (node->has_spatial_varying()) { current_shader->has_volume_spatial_varying = true; - if (node->has_attribute_dependency()) + } + if (node->has_attribute_dependency()) { current_shader->has_volume_attribute_dependency = true; + } } } @@ -998,8 +1033,9 @@ void OSLCompiler::parameter(ShaderNode *node, const char *name) // OSL does not support booleans, so convert to int const array &value = node->get_bool_array(socket); array intvalue(value.size()); - for (size_t i = 0; i < value.size(); i++) + for (size_t i = 0; i < value.size(); i++) { intvalue[i] = value[i]; + } ss->Parameter(*current_group, uname, array_typedesc(TypeInt, value.size()), intvalue.data()); break; } @@ -1118,13 +1154,13 @@ void OSLCompiler::parameter(const char *name, int f) void OSLCompiler::parameter(const char *name, const char *s) { - ss->Parameter(*current_group, name, TypeString, &s); + ss->Parameter(*current_group, name, TypeString, (const void *)&s); } void OSLCompiler::parameter(const char *name, ustring s) { const char *str = s.c_str(); - ss->Parameter(*current_group, name, TypeString, &str); + ss->Parameter(*current_group, name, TypeString, (const void *)&str); } void OSLCompiler::parameter(const char *name, const Transform &tfm) @@ -1159,10 +1195,12 @@ void OSLCompiler::parameter_color_array(const char *name, const array &f void OSLCompiler::parameter_attribute(const char *name, ustring s) { - if (Attribute::name_standard(s.c_str())) + if (Attribute::name_standard(s.c_str())) { parameter(name, (string("geom:") + s.c_str()).c_str()); - else + } + else { parameter(name, s.c_str()); + } } void OSLCompiler::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *input) @@ -1171,8 +1209,9 @@ void OSLCompiler::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *in if (node != nullptr && dependencies.find(node) == dependencies.end()) { foreach (ShaderInput *in, node->inputs) - if (!node_skip_input(node, in)) + if (!node_skip_input(node, in)) { find_dependencies(dependencies, in); + } dependencies.insert(node); } @@ -1191,37 +1230,45 @@ void OSLCompiler::generate_nodes(const ShaderNodeSet &nodes) bool inputs_done = true; foreach (ShaderInput *input, node->inputs) - if (!node_skip_input(node, input)) - if (input->link && done.find(input->link->parent) == done.end()) + 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); done.insert(node); if (current_type == SHADER_TYPE_SURFACE) { - if (node->has_surface_transparent()) + if (node->has_surface_transparent()) { current_shader->has_surface_transparent = true; - if (node->get_feature() & KERNEL_FEATURE_NODE_RAYTRACE) + } + if (node->get_feature() & KERNEL_FEATURE_NODE_RAYTRACE) { current_shader->has_surface_raytrace = true; - if (node->has_spatial_varying()) + } + if (node->has_spatial_varying()) { current_shader->has_surface_spatial_varying = true; + } if (node->has_surface_bssrdf()) { current_shader->has_surface_bssrdf = true; - if (node->has_bssrdf_bump()) + if (node->has_bssrdf_bump()) { current_shader->has_bssrdf_bump = true; + } } if (node->has_bump()) { current_shader->has_bump = true; } } else if (current_type == SHADER_TYPE_VOLUME) { - if (node->has_spatial_varying()) + if (node->has_spatial_varying()) { current_shader->has_volume_spatial_varying = true; + } } } - else + else { nodes_done = false; + } } } } while (!nodes_done); @@ -1265,8 +1312,9 @@ OSL::ShaderGroupRef OSLCompiler::compile_type(Shader *shader, ShaderGraph *graph generate_nodes(dependencies); output->compile(*this); } - else + else { assert(0); + } ss->ShaderGroupEnd(*current_group); @@ -1303,10 +1351,12 @@ void OSLCompiler::compile(Shader *shader) if (shader->reference_count() && graph && output->input("Surface")->link) { shader->osl_surface_ref = compile_type(shader, shader->graph, SHADER_TYPE_SURFACE); - if (has_bump) + if (has_bump) { shader->osl_surface_bump_ref = compile_type(shader, shader->graph, SHADER_TYPE_BUMP); - else + } + else { shader->osl_surface_bump_ref = OSL::ShaderGroupRef(); + } shader->has_surface = true; } @@ -1320,16 +1370,18 @@ void OSLCompiler::compile(Shader *shader) shader->osl_volume_ref = compile_type(shader, shader->graph, SHADER_TYPE_VOLUME); shader->has_volume = true; } - else + else { shader->osl_volume_ref = OSL::ShaderGroupRef(); + } /* generate displacement shader */ if (shader->reference_count() && graph && output->input("Displacement")->link) { shader->osl_displacement_ref = compile_type(shader, shader->graph, SHADER_TYPE_DISPLACEMENT); shader->has_displacement = true; } - else + else { shader->osl_displacement_ref = OSL::ShaderGroupRef(); + } /* Estimate emission for MIS. */ shader->estimate_emission(); diff --git a/intern/cycles/scene/osl.h b/intern/cycles/scene/osl.h index 0b8f2060af7..004e475ac34 100644 --- a/intern/cycles/scene/osl.h +++ b/intern/cycles/scene/osl.h @@ -39,15 +39,12 @@ class ShaderOutput; * to auto detect closures in the shader for MIS and transparent shadows */ struct OSLShaderInfo { - OSLShaderInfo() - : has_surface_emission(false), has_surface_transparent(false), has_surface_bssrdf(false) - { - } + OSLShaderInfo() = default; OSL::OSLQuery query; - bool has_surface_emission; - bool has_surface_transparent; - bool has_surface_bssrdf; + bool has_surface_emission = false; + bool has_surface_transparent = false; + bool has_surface_bssrdf = false; }; /* Shader Manage */ @@ -55,7 +52,7 @@ struct OSLShaderInfo { class OSLShaderManager : public ShaderManager { public: OSLShaderManager(Device *device); - ~OSLShaderManager(); + ~OSLShaderManager() override; static void free_memory(); @@ -123,7 +120,7 @@ class OSLShaderManager : public ShaderManager { class OSLCompiler { public: #ifdef WITH_OSL - OSLCompiler(OSLShaderManager *manager, OSL::ShadingSystem *shadingsys, Scene *scene); + OSLCompiler(OSLShaderManager *manager, OSL::ShadingSystem *ss, Scene *scene); #endif void compile(Shader *shader); diff --git a/intern/cycles/scene/particles.cpp b/intern/cycles/scene/particles.cpp index acd04655742..a1c3b6d73ef 100644 --- a/intern/cycles/scene/particles.cpp +++ b/intern/cycles/scene/particles.cpp @@ -8,11 +8,8 @@ #include "scene/stats.h" #include "util/foreach.h" -#include "util/hash.h" #include "util/log.h" -#include "util/map.h" #include "util/progress.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -26,7 +23,7 @@ NODE_DEFINE(ParticleSystem) ParticleSystem::ParticleSystem() : Node(get_node_type()) {} -ParticleSystem::~ParticleSystem() {} +ParticleSystem::~ParticleSystem() = default; void ParticleSystem::tag_update(Scene *scene) { @@ -40,9 +37,9 @@ ParticleSystemManager::ParticleSystemManager() need_update_ = true; } -ParticleSystemManager::~ParticleSystemManager() {} +ParticleSystemManager::~ParticleSystemManager() = default; -void ParticleSystemManager::device_update_particles(Device *, +void ParticleSystemManager::device_update_particles(Device * /*unused*/, DeviceScene *dscene, Scene *scene, Progress &progress) @@ -117,7 +114,7 @@ void ParticleSystemManager::device_update(Device *device, need_update_ = false; } -void ParticleSystemManager::device_free(Device *, DeviceScene *dscene) +void ParticleSystemManager::device_free(Device * /*unused*/, DeviceScene *dscene) { dscene->particles.free(); } diff --git a/intern/cycles/scene/particles.h b/intern/cycles/scene/particles.h index 540f569e195..9075404f1f6 100644 --- a/intern/cycles/scene/particles.h +++ b/intern/cycles/scene/particles.h @@ -34,7 +34,7 @@ class ParticleSystem : public Node { NODE_DECLARE ParticleSystem(); - ~ParticleSystem(); + ~ParticleSystem() override; void tag_update(Scene *scene); diff --git a/intern/cycles/scene/pass.cpp b/intern/cycles/scene/pass.cpp index d1faa7dbbf2..a6817ece714 100644 --- a/intern/cycles/scene/pass.cpp +++ b/intern/cycles/scene/pass.cpp @@ -4,7 +4,6 @@ #include "scene/pass.h" -#include "util/algorithm.h" #include "util/log.h" CCL_NAMESPACE_BEGIN @@ -419,9 +418,7 @@ int Pass::get_offset(const vector &passes, const Pass *pass) if (current_pass->is_written()) { return pass_offset; } - else { - return PASS_UNUSED; - } + return PASS_UNUSED; } if (current_pass->is_written()) { pass_offset += current_pass->get_info().num_components; diff --git a/intern/cycles/scene/pointcloud.cpp b/intern/cycles/scene/pointcloud.cpp index f0352f971ba..41d9347ab66 100644 --- a/intern/cycles/scene/pointcloud.cpp +++ b/intern/cycles/scene/pointcloud.cpp @@ -67,14 +67,12 @@ float4 PointCloud::Point::point_for_step(const float3 *points, /* Center step: regular key location. */ return make_float4(points[p], radius[p]); } - else { - /* Center step is not stored in this array. */ - if (step > center_step) { - step--; - } - const size_t offset = step * num_points; - return point_steps[offset + p]; + /* Center step is not stored in this array. */ + if (step > center_step) { + step--; } + const size_t offset = step * num_points; + return point_steps[offset + p]; } /* PointCloud */ @@ -93,7 +91,7 @@ NODE_DEFINE(PointCloud) PointCloud::PointCloud() : Geometry(node_type, Geometry::POINTCLOUD) {} -PointCloud::~PointCloud() {} +PointCloud::~PointCloud() = default; void PointCloud::resize(int numpoints) { diff --git a/intern/cycles/scene/pointcloud.h b/intern/cycles/scene/pointcloud.h index 76d07fd5cab..62148305b56 100644 --- a/intern/cycles/scene/pointcloud.h +++ b/intern/cycles/scene/pointcloud.h @@ -45,14 +45,14 @@ class PointCloud : public Geometry { /* Constructor/Destructor */ PointCloud(); - ~PointCloud(); + ~PointCloud() override; /* Geometry */ - void clear(const bool preserver_shaders = false) override; + void clear(const bool preserve_shaders = false) override; void resize(int numpoints); void reserve(int numpoints); - void add_point(float3 loc, float radius, int shader = 0); + void add_point(float3 co, float radius, int shader = 0); void copy_center_to_motion_step(const int motion_step); diff --git a/intern/cycles/scene/procedural.cpp b/intern/cycles/scene/procedural.cpp index 6fe23c4336b..5ee3cf27356 100644 --- a/intern/cycles/scene/procedural.cpp +++ b/intern/cycles/scene/procedural.cpp @@ -19,14 +19,14 @@ NODE_ABSTRACT_DEFINE(Procedural) Procedural::Procedural(const NodeType *type) : Node(type) {} -Procedural::~Procedural() {} +Procedural::~Procedural() = default; ProceduralManager::ProceduralManager() { need_update_ = true; } -ProceduralManager::~ProceduralManager() {} +ProceduralManager::~ProceduralManager() = default; void ProceduralManager::update(Scene *scene, Progress &progress) { diff --git a/intern/cycles/scene/procedural.h b/intern/cycles/scene/procedural.h index 886bd00394a..448f7b23bab 100644 --- a/intern/cycles/scene/procedural.h +++ b/intern/cycles/scene/procedural.h @@ -22,7 +22,7 @@ class Procedural : public Node, public NodeOwner { NODE_ABSTRACT_DECLARE explicit Procedural(const NodeType *type); - virtual ~Procedural(); + ~Procedural() override; /* Called each time the ProceduralManager is tagged for an update, this function is the entry * point for the data generated by this Procedural. */ diff --git a/intern/cycles/scene/scene.cpp b/intern/cycles/scene/scene.cpp index 0f0363f2dfc..45ee2fd10e9 100644 --- a/intern/cycles/scene/scene.cpp +++ b/intern/cycles/scene/scene.cpp @@ -13,6 +13,7 @@ #include "scene/curves.h" #include "scene/devicescene.h" #include "scene/film.h" +#include "scene/hair.h" #include "scene/integrator.h" #include "scene/light.h" #include "scene/mesh.h" @@ -72,8 +73,8 @@ Scene::Scene(const SceneParams ¶ms_, Device *device) background = create_node(); integrator = create_node(); - film->add_default(this); - shader_manager->add_default(this); + ccl::Film::add_default(this); + ccl::ShaderManager::add_default(this); } Scene::~Scene() @@ -364,12 +365,10 @@ Scene::MotionType Scene::need_motion() const if (integrator->get_motion_blur()) { return MOTION_BLUR; } - else if (Pass::contains(passes, PASS_MOTION)) { + if (Pass::contains(passes, PASS_MOTION)) { return MOTION_PASS; } - else { - return MOTION_NONE; - } + return MOTION_NONE; } float Scene::motion_shutter_time() @@ -377,9 +376,7 @@ float Scene::motion_shutter_time() if (need_motion() == Scene::MOTION_PASS) { return 2.0f; } - else { - return camera->get_shuttertime(); - } + return camera->get_shuttertime(); } bool Scene::need_global_attribute(AttributeStandard std) @@ -387,14 +384,14 @@ bool Scene::need_global_attribute(AttributeStandard std) if (std == ATTR_STD_UV) { return Pass::contains(passes, PASS_UV); } - else if (std == ATTR_STD_MOTION_VERTEX_POSITION) { + if (std == ATTR_STD_MOTION_VERTEX_POSITION) { return need_motion() != MOTION_NONE; } - else if (std == ATTR_STD_MOTION_VERTEX_NORMAL) { + if (std == ATTR_STD_MOTION_VERTEX_NORMAL) { return need_motion() == MOTION_BLUR; } - else if (std == ATTR_STD_VOLUME_VELOCITY || std == ATTR_STD_VOLUME_VELOCITY_X || - std == ATTR_STD_VOLUME_VELOCITY_Y || std == ATTR_STD_VOLUME_VELOCITY_Z) + if (std == ATTR_STD_VOLUME_VELOCITY || std == ATTR_STD_VOLUME_VELOCITY_X || + std == ATTR_STD_VOLUME_VELOCITY_Y || std == ATTR_STD_VOLUME_VELOCITY_Z) { return need_motion() != MOTION_NONE; } @@ -434,7 +431,7 @@ bool Scene::need_reset(const bool check_camera) void Scene::reset() { shader_manager->reset(this); - shader_manager->add_default(this); + ccl::ShaderManager::add_default(this); /* ensure all objects are updated */ camera->tag_modified(); @@ -909,10 +906,10 @@ template<> void Scene::delete_node_impl(ParticleSystem *node) particle_system_manager->tag_update(this); } -template<> void Scene::delete_node_impl(Shader *shader) +template<> void Scene::delete_node_impl(Shader *node) { /* don't delete unused shaders, not supported */ - shader->clear_reference_count(); + node->clear_reference_count(); } template<> void Scene::delete_node_impl(Procedural *node) diff --git a/intern/cycles/scene/scene.h b/intern/cycles/scene/scene.h index 87c9f01b1b6..454347177ed 100644 --- a/intern/cycles/scene/scene.h +++ b/intern/cycles/scene/scene.h @@ -13,7 +13,6 @@ #include "util/param.h" #include "util/string.h" -#include "util/texture.h" #include "util/thread.h" CCL_NAMESPACE_BEGIN @@ -166,7 +165,7 @@ class Scene : public NodeOwner { SceneUpdateStats *update_stats; Scene(const SceneParams ¶ms, Device *device); - ~Scene(); + ~Scene() override; void device_update(Device *device, Progress &progress); diff --git a/intern/cycles/scene/shader.cpp b/intern/cycles/scene/shader.cpp index 275a9006943..4f53b542686 100644 --- a/intern/cycles/scene/shader.cpp +++ b/intern/cycles/scene/shader.cpp @@ -133,9 +133,9 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) if (node == nullptr) { return zero_float3(); } - else if (node->type == EmissionNode::get_node_type() || - node->type == BackgroundNode::get_node_type() || - node->type == PrincipledBsdfNode::get_node_type()) + if (node->type == EmissionNode::get_node_type() || + node->type == BackgroundNode::get_node_type() || + node->type == PrincipledBsdfNode::get_node_type()) { const bool is_principled = (node->type == PrincipledBsdfNode::get_node_type()); /* Emission and Background node. */ @@ -176,8 +176,8 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) return estimate; } - else if (node->type == LightFalloffNode::get_node_type() || - node->type == IESLightNode::get_node_type()) + if (node->type == LightFalloffNode::get_node_type() || + node->type == IESLightNode::get_node_type()) { /* Get strength from Light Falloff and IES texture node. */ ShaderInput *strength_in = node->input("Strength"); @@ -186,7 +186,7 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) return (strength_in->link) ? output_estimate_emission(strength_in->link, is_constant) : make_float3(node->get_float(strength_in->socket_type)); } - else if (node->type == AddClosureNode::get_node_type()) { + if (node->type == AddClosureNode::get_node_type()) { /* Add Closure. */ ShaderInput *closure1_in = node->input("Closure1"); ShaderInput *closure2_in = node->input("Closure2"); @@ -200,7 +200,7 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) return estimate1 + estimate2; } - else if (node->type == MixClosureNode::get_node_type()) { + if (node->type == MixClosureNode::get_node_type()) { /* Mix Closure. */ ShaderInput *fac_in = node->input("Fac"); ShaderInput *closure1_in = node->input("Closure1"); @@ -217,39 +217,37 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) is_constant = false; return estimate1 + estimate2; } - else { - const float fac = node->get_float(fac_in->socket_type); - return (1.0f - fac) * estimate1 + fac * estimate2; - } + + const float fac = node->get_float(fac_in->socket_type); + return (1.0f - fac) * estimate1 + fac * estimate2; } - else { - /* Other nodes, potentially OSL nodes with arbitrary code for which all we can - * determine is if it has emission or not. */ - const bool has_emission = node->has_surface_emission(); - float3 estimate; - if (output->type() == SocketType::CLOSURE) { - if (has_emission) { - estimate = one_float3(); - is_constant = false; - } - else { - estimate = zero_float3(); - } + /* Other nodes, potentially OSL nodes with arbitrary code for which all we can + * determine is if it has emission or not. */ + const bool has_emission = node->has_surface_emission(); + float3 estimate; - foreach (const ShaderInput *in, node->inputs) { - if (in->type() == SocketType::CLOSURE && in->link) { - estimate += output_estimate_emission(in->link, is_constant); - } - } - } - else { + if (output->type() == SocketType::CLOSURE) { + if (has_emission) { estimate = one_float3(); is_constant = false; } + else { + estimate = zero_float3(); + } - return estimate; + foreach (const ShaderInput *in, node->inputs) { + if (in->type() == SocketType::CLOSURE && in->link) { + estimate += output_estimate_emission(in->link, is_constant); + } + } } + else { + estimate = one_float3(); + is_constant = false; + } + + return estimate; } void Shader::estimate_emission() @@ -433,7 +431,7 @@ ShaderManager::ShaderManager() init_xyz_transforms(); } -ShaderManager::~ShaderManager() {} +ShaderManager::~ShaderManager() = default; ShaderManager *ShaderManager::create(int shadingsystem, Device *device) { @@ -523,7 +521,7 @@ void ShaderManager::device_update_common(Device * /*device*/, { dscene->shaders.free(); - if (scene->shaders.size() == 0) { + if (scene->shaders.empty()) { return; } diff --git a/intern/cycles/scene/shader.h b/intern/cycles/scene/shader.h index 485ce0a6dcd..7fe6fe51551 100644 --- a/intern/cycles/scene/shader.h +++ b/intern/cycles/scene/shader.h @@ -6,7 +6,9 @@ #ifdef WITH_OSL /* So no context pollution happens from indirectly included windows.h */ -# include "util/windows.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif # include #endif @@ -133,7 +135,7 @@ class Shader : public Node { #endif Shader(); - ~Shader(); + ~Shader() override; /* Estimate emission of this shader based on the shader graph. This works only in very simple * cases. But it helps improve light importance sampling in common cases. @@ -227,7 +229,7 @@ class ShaderManager { uint32_t update_flags; - typedef unordered_map AttributeIDMap; + using AttributeIDMap = unordered_map; AttributeIDMap unique_attribute_id; static thread_mutex lookup_table_mutex; diff --git a/intern/cycles/scene/shader_graph.cpp b/intern/cycles/scene/shader_graph.cpp index 6f567741f63..ac8cdfdbeb6 100644 --- a/intern/cycles/scene/shader_graph.cpp +++ b/intern/cycles/scene/shader_graph.cpp @@ -559,7 +559,7 @@ void ShaderGraph::constant_fold(Scene *scene) traverse_queue.pop(); done.insert(node); foreach (ShaderOutput *output, node->outputs) { - if (output->links.size() == 0) { + if (output->links.empty()) { continue; } /* Schedule node which was depending on the value, @@ -1184,7 +1184,7 @@ int ShaderGraph::get_num_closures() if (closure_type == CLOSURE_NONE_ID) { continue; } - else if (CLOSURE_IS_BSSRDF(closure_type)) { + if (CLOSURE_IS_BSSRDF(closure_type)) { num_closures += 3; } else if (CLOSURE_IS_BSDF_MULTISCATTER(closure_type)) { @@ -1231,7 +1231,7 @@ void ShaderGraph::dump_graph(const char *filename) foreach (ShaderNode *node, nodes) { fprintf(fd, "// NODE: %p\n", node); fprintf(fd, "\"%p\" [shape=record,label=\"{", node); - if (node->inputs.size()) { + if (!node->inputs.empty()) { fprintf(fd, "{"); foreach (ShaderInput *socket, node->inputs) { if (socket != node->inputs[0]) { @@ -1251,7 +1251,7 @@ void ShaderGraph::dump_graph(const char *filename) else if (node->bump == SHADER_BUMP_DY) { fprintf(fd, " (bump:dy)"); } - if (node->outputs.size()) { + if (!node->outputs.empty()) { fprintf(fd, "|{"); foreach (ShaderOutput *socket, node->outputs) { if (socket != node->outputs[0]) { diff --git a/intern/cycles/scene/shader_graph.h b/intern/cycles/scene/shader_graph.h index 28b00349e0b..3b80b72b3a7 100644 --- a/intern/cycles/scene/shader_graph.h +++ b/intern/cycles/scene/shader_graph.h @@ -13,6 +13,7 @@ #include "util/map.h" #include "util/param.h" #include "util/set.h" +#include "util/string.h" #include "util/types.h" #include "util/vector.h" @@ -66,11 +67,8 @@ enum ShaderNodeSpecialType { class ShaderInput { public: ShaderInput(const SocketType &socket_type_, ShaderNode *parent_) - : socket_type(socket_type_), - parent(parent_), - link(nullptr), - stack_offset(SVM_STACK_INVALID), - constant_folded_in(false) + : socket_type(socket_type_), parent(parent_) + { } @@ -104,12 +102,12 @@ class ShaderInput { const SocketType &socket_type; ShaderNode *parent; - ShaderOutput *link; - int stack_offset; /* for SVM compiler */ + ShaderOutput *link = nullptr; + int stack_offset = SVM_STACK_INVALID; /* for SVM compiler */ /* Keeps track of whether a constant was folded in this socket, to avoid over-optimizing when the * link is null. */ - bool constant_folded_in; + bool constant_folded_in = false; }; /* Output @@ -119,7 +117,7 @@ class ShaderInput { class ShaderOutput { public: ShaderOutput(const SocketType &socket_type_, ShaderNode *parent_) - : socket_type(socket_type_), parent(parent_), stack_offset(SVM_STACK_INVALID) + : socket_type(socket_type_), parent(parent_) { } @@ -137,7 +135,7 @@ class ShaderOutput { const SocketType &socket_type; ShaderNode *parent; vector links; - int stack_offset; /* for SVM compiler */ + int stack_offset = SVM_STACK_INVALID; /* for SVM compiler */ }; /* Node @@ -148,7 +146,7 @@ class ShaderOutput { class ShaderNode : public Node { public: explicit ShaderNode(const NodeType *type); - virtual ~ShaderNode(); + ~ShaderNode() override; void create_inputs_outputs(const NodeType *type); void remove_input(ShaderInput *input); @@ -253,26 +251,26 @@ class ShaderNode : public Node { #define SHADER_NODE_CLASS(type) \ NODE_DECLARE \ type(); \ - virtual ShaderNode *clone(ShaderGraph *graph) const \ + ShaderNode *clone(ShaderGraph *graph) const override \ { \ return graph->create_node(*this); \ } \ - virtual void compile(SVMCompiler &compiler); \ - virtual void compile(OSLCompiler &compiler); + void compile(SVMCompiler &compiler) override; \ + void compile(OSLCompiler &compiler) override; #define SHADER_NODE_NO_CLONE_CLASS(type) \ NODE_DECLARE \ type(); \ - virtual void compile(SVMCompiler &compiler); \ - virtual void compile(OSLCompiler &compiler); + void compile(SVMCompiler &compiler) override; \ + void compile(OSLCompiler &compiler) override; #define SHADER_NODE_BASE_CLASS(type) \ - virtual ShaderNode *clone(ShaderGraph *graph) const \ + ShaderNode *clone(ShaderGraph *graph) const override \ { \ return graph->create_node(*this); \ } \ - virtual void compile(SVMCompiler &compiler); \ - virtual void compile(OSLCompiler &compiler); + void compile(SVMCompiler &compiler) override; \ + void compile(OSLCompiler &compiler) override; class ShaderNodeIDComparator { public: @@ -282,8 +280,8 @@ class ShaderNodeIDComparator { } }; -typedef set ShaderNodeSet; -typedef map ShaderNodeMap; +using ShaderNodeSet = set; +using ShaderNodeMap = map; /* Graph * @@ -299,7 +297,7 @@ class ShaderGraph : public NodeOwner { string displacement_hash; ShaderGraph(); - ~ShaderGraph(); + ~ShaderGraph() override; ShaderNode *add(ShaderNode *node); OutputNode *output(); @@ -330,8 +328,7 @@ class ShaderGraph : public NodeOwner { return node; } - /* This function is used to delete a node created and owned by the graph. - */ + /* This function is used to delete a node created and owned by the graph. */ template void delete_node(T *node) { assert(node->get_owner() == this); @@ -339,7 +336,7 @@ class ShaderGraph : public NodeOwner { } protected: - typedef pair NodePair; + using NodePair = pair; void find_dependencies(ShaderNodeSet &dependencies, ShaderInput *input); void clear_nodes(); diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index c267c88711a..2279b4414ad 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -22,8 +22,6 @@ #include "util/log.h" #include "util/transform.h" -#include "kernel/tables.h" - #include "kernel/svm/color_util.h" #include "kernel/svm/mapping_util.h" #include "kernel/svm/math_util.h" @@ -65,7 +63,7 @@ CCL_NAMESPACE_BEGIN mapping_projection_enum.insert("sphere", TextureMapping::SPHERE); \ SOCKET_ENUM(tex_mapping.projection, "Projection", mapping_projection_enum, TextureMapping::FLAT); -TextureMapping::TextureMapping() {} +TextureMapping::TextureMapping() = default; Transform TextureMapping::compute_transform() { @@ -635,17 +633,17 @@ static float2 sky_spherical_coordinates(float3 dir) return make_float2(acosf(dir.z), atan2f(dir.x, dir.y)); } -typedef struct SunSky { +struct SunSky { /* sun direction in spherical and cartesian */ float theta, phi; /* Parameter */ float radiance_x, radiance_y, radiance_z; float config_x[9], config_y[9], config_z[9], nishita_data[10]; -} SunSky; +}; /* Preetham model */ -static float sky_perez_function(float lam[6], float theta, float gamma) +static float sky_perez_function(const float lam[6], float theta, float gamma) { return (1.0f + lam[0] * expf(lam[1] / cosf(theta))) * (1.0f + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * cosf(gamma)); @@ -1885,7 +1883,7 @@ NODE_DEFINE(PointDensityTextureNode) PointDensityTextureNode::PointDensityTextureNode() : ShaderNode(get_node_type()) {} -PointDensityTextureNode::~PointDensityTextureNode() {} +PointDensityTextureNode::~PointDensityTextureNode() = default; ShaderNode *PointDensityTextureNode::clone(ShaderGraph *graph) const { @@ -2069,11 +2067,11 @@ MappingNode::MappingNode() : ShaderNode(get_node_type()) {} void MappingNode::constant_fold(const ConstantFolder &folder) { if (folder.all_inputs_constant()) { - float3 result = svm_mapping((NodeMappingType)mapping_type, vector, location, rotation, scale); + float3 result = svm_mapping(mapping_type, vector, location, rotation, scale); folder.make_constant(result); } else { - folder.fold_mapping((NodeMappingType)mapping_type); + folder.fold_mapping(mapping_type); } } @@ -4198,7 +4196,7 @@ void UVMapNode::attributes(Shader *shader, AttributeRequestSet *attributes) if (shader->has_surface) { if (!from_dupli) { if (!output("UV")->links.empty()) { - if (attribute != "") { + if (!attribute.empty()) { attributes->add(attribute); } else { @@ -4232,7 +4230,7 @@ void UVMapNode::compile(SVMCompiler &compiler) compiler.add_node(texco_node, NODE_TEXCO_DUPLI_UV, compiler.stack_assign(out)); } else { - if (attribute != "") { + if (!attribute.empty()) { attr = compiler.attribute(attribute); } else { @@ -4803,9 +4801,9 @@ void VolumeInfoNode::expand(ShaderGraph *graph) } } -void VolumeInfoNode::compile(SVMCompiler &) {} +void VolumeInfoNode::compile(SVMCompiler & /*compiler*/) {} -void VolumeInfoNode::compile(OSLCompiler &) {} +void VolumeInfoNode::compile(OSLCompiler & /*compiler*/) {} NODE_DEFINE(VertexColorNode) { @@ -4823,7 +4821,7 @@ VertexColorNode::VertexColorNode() : ShaderNode(get_node_type()) {} void VertexColorNode::attributes(Shader *shader, AttributeRequestSet *attributes) { if (!(output("Color")->links.empty() && output("Alpha")->links.empty())) { - if (layer_name != "") { + if (!layer_name.empty()) { attributes->add_standard(layer_name); } else { @@ -4839,7 +4837,7 @@ void VertexColorNode::compile(SVMCompiler &compiler) ShaderOutput *alpha_out = output("Alpha"); int layer_id = 0; - if (layer_name != "") { + if (!layer_name.empty()) { layer_id = compiler.attribute(layer_name); } else { @@ -7414,15 +7412,13 @@ OSLNode *OSLNode::create(ShaderGraph *graph, size_t num_inputs, const OSLNode *f node->set_owner(graph); return node; } - else { - /* copy input default values and node type for cloning */ - memcpy(node_memory + node_size, (char *)from + node_size, inputs_size); + /* copy input default values and node type for cloning */ + memcpy(node_memory + node_size, (char *)from + node_size, inputs_size); - OSLNode *node = new (node_memory) OSLNode(*from); - node->type = new NodeType(*(from->type)); - node->set_owner(from->owner); - return node; - } + OSLNode *node = new (node_memory) OSLNode(*from); + node->type = new NodeType(*(from->type)); + node->set_owner(from->owner); + return node; } char *OSLNode::input_default_value() @@ -7446,7 +7442,7 @@ void OSLNode::add_output(ustring name, SocketType::Type socket_type) const_cast(type)->register_output(name, name, socket_type); } -void OSLNode::compile(SVMCompiler &) +void OSLNode::compile(SVMCompiler & /*compiler*/) { /* doesn't work for SVM, obviously ... */ } diff --git a/intern/cycles/scene/shader_nodes.h b/intern/cycles/scene/shader_nodes.h index edbafcd930c..a5ba6929ed8 100644 --- a/intern/cycles/scene/shader_nodes.h +++ b/intern/cycles/scene/shader_nodes.h @@ -76,7 +76,7 @@ class ImageSlotTextureNode : public TextureNode { special_type = SHADER_SPECIAL_TYPE_IMAGE_SLOT; } - virtual bool equals(const ShaderNode &other) + bool equals(const ShaderNode &other) override { const ImageSlotTextureNode &other_node = (const ImageSlotTextureNode &)other; return TextureNode::equals(other) && handle == other_node.handle; @@ -88,14 +88,14 @@ class ImageSlotTextureNode : public TextureNode { class ImageTextureNode : public ImageSlotTextureNode { public: SHADER_NODE_NO_CLONE_CLASS(ImageTextureNode) - ShaderNode *clone(ShaderGraph *graph) const; - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + ShaderNode *clone(ShaderGraph *graph) const override; + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - virtual bool equals(const ShaderNode &other) + bool equals(const ShaderNode &other) override { const ImageTextureNode &other_node = (const ImageTextureNode &)other; return ImageSlotTextureNode::equals(other) && animated == other_node.animated; @@ -122,14 +122,14 @@ class ImageTextureNode : public ImageSlotTextureNode { class EnvironmentTextureNode : public ImageSlotTextureNode { public: SHADER_NODE_NO_CLONE_CLASS(EnvironmentTextureNode) - ShaderNode *clone(ShaderGraph *graph) const; - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + ShaderNode *clone(ShaderGraph *graph) const override; + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - virtual bool equals(const ShaderNode &other) + bool equals(const ShaderNode &other) override { const EnvironmentTextureNode &other_node = (const EnvironmentTextureNode &)other; return ImageSlotTextureNode::equals(other) && animated == other_node.animated; @@ -167,7 +167,7 @@ class SkyTextureNode : public TextureNode { NODE_SOCKET_API(float3, vector) ImageHandle handle; - void simplify_settings(Scene *scene); + void simplify_settings(Scene *scene) override; float get_sun_size() { @@ -188,7 +188,7 @@ class OutputNode : public ShaderNode { NODE_SOCKET_API(float3, normal) /* Don't allow output node de-duplication. */ - virtual bool equals(const ShaderNode & /*other*/) + bool equals(const ShaderNode & /*other*/) override { return false; } @@ -197,7 +197,7 @@ class OutputNode : public ShaderNode { class OutputAOVNode : public ShaderNode { public: SHADER_NODE_CLASS(OutputAOVNode) - virtual void simplify_settings(Scene *scene); + void simplify_settings(Scene *scene) override; NODE_SOCKET_API(float, value) NODE_SOCKET_API(float3, color) @@ -205,7 +205,7 @@ class OutputAOVNode : public ShaderNode { NODE_SOCKET_API(ustring, name) /* Don't allow output node de-duplication. */ - virtual bool equals(const ShaderNode & /*other*/) + bool equals(const ShaderNode & /*other*/) override { return false; } @@ -257,7 +257,7 @@ class VoronoiTextureNode : public TextureNode { public: SHADER_NODE_CLASS(VoronoiTextureNode) - virtual int get_feature() + int get_feature() override { int result = ShaderNode::get_feature(); if (dimensions == 4) { @@ -347,15 +347,15 @@ class PointDensityTextureNode : public ShaderNode { public: SHADER_NODE_NO_CLONE_CLASS(PointDensityTextureNode) - ~PointDensityTextureNode(); - ShaderNode *clone(ShaderGraph *graph) const; - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + ~PointDensityTextureNode() override; + ShaderNode *clone(ShaderGraph *graph) const override; + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -372,7 +372,7 @@ class PointDensityTextureNode : public ShaderNode { ImageParams image_params() const; - virtual bool equals(const ShaderNode &other) + bool equals(const ShaderNode &other) override { const PointDensityTextureNode &other_node = (const PointDensityTextureNode &)other; return ShaderNode::equals(other) && handle == other_node.handle; @@ -383,8 +383,8 @@ class IESLightNode : public TextureNode { public: SHADER_NODE_NO_CLONE_CLASS(IESLightNode) - ~IESLightNode(); - ShaderNode *clone(ShaderGraph *graph) const; + ~IESLightNode() override; + ShaderNode *clone(ShaderGraph *graph) const override; NODE_SOCKET_API(ustring, filename) NODE_SOCKET_API(ustring, ies) @@ -411,7 +411,7 @@ class WhiteNoiseTextureNode : public ShaderNode { class MappingNode : public ShaderNode { public: SHADER_NODE_CLASS(MappingNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, vector) NODE_SOCKET_API(float3, location) @@ -423,7 +423,7 @@ class MappingNode : public ShaderNode { class RGBToBWNode : public ShaderNode { public: SHADER_NODE_CLASS(RGBToBWNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, color) }; @@ -434,7 +434,7 @@ class ConvertNode : public ShaderNode { ConvertNode(const ConvertNode &other); SHADER_NODE_BASE_CLASS(ConvertNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; private: SocketType::Type from, to; @@ -460,23 +460,23 @@ class BsdfBaseNode : public ShaderNode { public: BsdfBaseNode(const NodeType *node_type); - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } - virtual ClosureType get_closure_type() + ClosureType get_closure_type() override { return closure; } - virtual bool has_bump(); + bool has_bump() override; - virtual bool equals(const ShaderNode & /*other*/) + bool equals(const ShaderNode & /*other*/) override { /* TODO(sergey): With some care BSDF nodes can be de-duplicated. */ return false; } - virtual int get_feature() + int get_feature() override { return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_BSDF; } @@ -514,9 +514,9 @@ class PrincipledBsdfNode : public BsdfBaseNode { public: SHADER_NODE_CLASS(PrincipledBsdfNode) - bool has_surface_bssrdf(); - bool has_bssrdf_bump(); - void simplify_settings(Scene *scene); + bool has_surface_bssrdf() override; + bool has_bssrdf_bump() override; + void simplify_settings(Scene *scene) override; NODE_SOCKET_API(float3, base_color) NODE_SOCKET_API(float, metallic) @@ -553,13 +553,13 @@ class PrincipledBsdfNode : public BsdfBaseNode { NODE_SOCKET_API(float, thin_film_ior) public: - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_surface_transparent(); - bool has_surface_emission(); + bool has_surface_transparent() override; + bool has_surface_emission() override; }; class TranslucentBsdfNode : public BsdfNode { @@ -571,7 +571,7 @@ class TransparentBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(TransparentBsdfNode) - bool has_surface_transparent() + bool has_surface_transparent() override { return true; } @@ -584,7 +584,7 @@ class RayPortalBsdfNode : public BsdfNode { NODE_SOCKET_API(float3, position) NODE_SOCKET_API(float3, direction) - bool has_surface_transparent() + bool has_surface_transparent() override { return true; } @@ -597,7 +597,7 @@ class SheenBsdfNode : public BsdfNode { NODE_SOCKET_API(float, roughness) NODE_SOCKET_API(ClosureType, distribution) - ClosureType get_closure_type() + ClosureType get_closure_type() override { return distribution; } @@ -607,8 +607,8 @@ class MetallicBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(MetallicBsdfNode) - void simplify_settings(Scene *scene); - ClosureType get_closure_type() + void simplify_settings(Scene *scene) override; + ClosureType get_closure_type() override { return closure; } @@ -623,8 +623,8 @@ class MetallicBsdfNode : public BsdfNode { NODE_SOCKET_API(ClosureType, distribution) NODE_SOCKET_API(ClosureType, fresnel_type) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } @@ -636,8 +636,8 @@ class GlossyBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(GlossyBsdfNode) - void simplify_settings(Scene *scene); - ClosureType get_closure_type() + void simplify_settings(Scene *scene) override; + ClosureType get_closure_type() override { return distribution; } @@ -648,8 +648,8 @@ class GlossyBsdfNode : public BsdfNode { NODE_SOCKET_API(float, rotation) NODE_SOCKET_API(ClosureType, distribution) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } @@ -661,7 +661,7 @@ class GlassBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(GlassBsdfNode) - ClosureType get_closure_type() + ClosureType get_closure_type() override { return distribution; } @@ -675,7 +675,7 @@ class RefractionBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(RefractionBsdfNode) - ClosureType get_closure_type() + ClosureType get_closure_type() override { return distribution; } @@ -697,12 +697,12 @@ class ToonBsdfNode : public BsdfNode { class SubsurfaceScatteringNode : public BsdfNode { public: SHADER_NODE_CLASS(SubsurfaceScatteringNode) - bool has_surface_bssrdf() + bool has_surface_bssrdf() override { return true; } - bool has_bssrdf_bump(); - ClosureType get_closure_type() + bool has_bssrdf_bump() override; + ClosureType get_closure_type() override { return method; } @@ -718,18 +718,18 @@ class SubsurfaceScatteringNode : public BsdfNode { class EmissionNode : public ShaderNode { public: SHADER_NODE_CLASS(EmissionNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; - bool has_surface_emission() + bool has_surface_emission() override { return true; } - bool has_volume_support() + bool has_volume_support() override { return true; } - virtual int get_feature() + int get_feature() override { return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_EMISSION; } @@ -744,9 +744,9 @@ class EmissionNode : public ShaderNode { class BackgroundNode : public ShaderNode { public: SHADER_NODE_CLASS(BackgroundNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; - virtual int get_feature() + int get_feature() override { return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_EMISSION; } @@ -759,7 +759,7 @@ class BackgroundNode : public ShaderNode { class HoldoutNode : public ShaderNode { public: SHADER_NODE_CLASS(HoldoutNode) - virtual ClosureType get_closure_type() + ClosureType get_closure_type() override { return CLOSURE_HOLDOUT_ID; } @@ -772,11 +772,11 @@ class AmbientOcclusionNode : public ShaderNode { public: SHADER_NODE_CLASS(AmbientOcclusionNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } - virtual int get_feature() + int get_feature() override { return KERNEL_FEATURE_NODE_RAYTRACE; } @@ -799,15 +799,15 @@ class VolumeNode : public ShaderNode { ShaderInput *density, ShaderInput *param1 = nullptr, ShaderInput *param2 = nullptr); - virtual int get_feature() + int get_feature() override { return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_VOLUME; } - virtual ClosureType get_closure_type() + ClosureType get_closure_type() override { return closure; } - virtual bool has_volume_support() + bool has_volume_support() override { return true; } @@ -820,7 +820,7 @@ class VolumeNode : public ShaderNode { ClosureType closure; public: - virtual bool equals(const ShaderNode & /*other*/) + bool equals(const ShaderNode & /*other*/) override { /* TODO(sergey): With some care Volume nodes can be de-duplicated. */ return false; @@ -847,8 +847,8 @@ class ScatterVolumeNode : public VolumeNode { class PrincipledVolumeNode : public VolumeNode { public: SHADER_NODE_CLASS(PrincipledVolumeNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } @@ -870,7 +870,7 @@ class PrincipledVolumeNode : public VolumeNode { class PrincipledHairBsdfNode : public BsdfBaseNode { public: SHADER_NODE_CLASS(PrincipledHairBsdfNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); + void attributes(Shader *shader, AttributeRequestSet *attributes) override; /* Longitudinal roughness. */ NODE_SOCKET_API(float, roughness) @@ -914,18 +914,18 @@ class PrincipledHairBsdfNode : public BsdfBaseNode { /* Selected scattering model (chiang/huang). */ NODE_SOCKET_API(NodePrincipledHairModel, model) - virtual int get_feature() + int get_feature() override { - return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_PRINCIPLED_HAIR; + return ccl::BsdfBaseNode::get_feature() | KERNEL_FEATURE_NODE_PRINCIPLED_HAIR; } - bool has_surface_transparent(); + bool has_surface_transparent() override; }; class HairBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(HairBsdfNode) - ClosureType get_closure_type() + ClosureType get_closure_type() override { return component; } @@ -940,12 +940,12 @@ class HairBsdfNode : public BsdfNode { class GeometryNode : public ShaderNode { public: SHADER_NODE_CLASS(GeometryNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -955,12 +955,12 @@ class GeometryNode : public ShaderNode { class TextureCoordinateNode : public ShaderNode { public: SHADER_NODE_CLASS(TextureCoordinateNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -973,12 +973,12 @@ class TextureCoordinateNode : public ShaderNode { class UVMapNode : public ShaderNode { public: SHADER_NODE_CLASS(UVMapNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -995,7 +995,7 @@ class LightPathNode : public ShaderNode { class LightFalloffNode : public ShaderNode { public: SHADER_NODE_CLASS(LightFalloffNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1012,8 +1012,8 @@ class ObjectInfoNode : public ShaderNode { class ParticleInfoNode : public ShaderNode { public: SHADER_NODE_CLASS(ParticleInfoNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } @@ -1023,12 +1023,12 @@ class HairInfoNode : public ShaderNode { public: SHADER_NODE_CLASS(HairInfoNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1038,12 +1038,12 @@ class PointInfoNode : public ShaderNode { public: SHADER_NODE_CLASS(PointInfoNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1052,27 +1052,27 @@ class PointInfoNode : public ShaderNode { class VolumeInfoNode : public ShaderNode { public: SHADER_NODE_CLASS(VolumeInfoNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } - void expand(ShaderGraph *graph); + void expand(ShaderGraph *graph) override; }; class VertexColorNode : public ShaderNode { public: SHADER_NODE_CLASS(VertexColorNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1084,7 +1084,7 @@ class ValueNode : public ShaderNode { public: SHADER_NODE_CLASS(ValueNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, value) }; @@ -1093,7 +1093,7 @@ class ColorNode : public ShaderNode { public: SHADER_NODE_CLASS(ColorNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, value) }; @@ -1101,13 +1101,13 @@ class ColorNode : public ShaderNode { class AddClosureNode : public ShaderNode { public: SHADER_NODE_CLASS(AddClosureNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; }; class MixClosureNode : public ShaderNode { public: SHADER_NODE_CLASS(MixClosureNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, fac) }; @@ -1123,7 +1123,7 @@ class MixClosureWeightNode : public ShaderNode { class InvertNode : public ShaderNode { public: SHADER_NODE_CLASS(InvertNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, fac) NODE_SOCKET_API(float3, color) @@ -1132,7 +1132,7 @@ class InvertNode : public ShaderNode { class MixNode : public ShaderNode { public: SHADER_NODE_CLASS(MixNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(NodeMix, mix_type) NODE_SOCKET_API(bool, use_clamp) @@ -1144,7 +1144,7 @@ class MixNode : public ShaderNode { class MixColorNode : public ShaderNode { public: SHADER_NODE_CLASS(MixColorNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, a) NODE_SOCKET_API(float3, b) @@ -1157,7 +1157,7 @@ class MixColorNode : public ShaderNode { class MixFloatNode : public ShaderNode { public: SHADER_NODE_CLASS(MixFloatNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, a) NODE_SOCKET_API(float, b) @@ -1168,7 +1168,7 @@ class MixFloatNode : public ShaderNode { class MixVectorNode : public ShaderNode { public: SHADER_NODE_CLASS(MixVectorNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, a) NODE_SOCKET_API(float3, b) @@ -1179,7 +1179,7 @@ class MixVectorNode : public ShaderNode { class MixVectorNonUniformNode : public ShaderNode { public: SHADER_NODE_CLASS(MixVectorNonUniformNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, a) NODE_SOCKET_API(float3, b) @@ -1190,7 +1190,7 @@ class MixVectorNonUniformNode : public ShaderNode { class CombineColorNode : public ShaderNode { public: SHADER_NODE_CLASS(CombineColorNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(NodeCombSepColorType, color_type) NODE_SOCKET_API(float, r) @@ -1201,7 +1201,7 @@ class CombineColorNode : public ShaderNode { class CombineRGBNode : public ShaderNode { public: SHADER_NODE_CLASS(CombineRGBNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, r) NODE_SOCKET_API(float, g) @@ -1211,7 +1211,7 @@ class CombineRGBNode : public ShaderNode { class CombineHSVNode : public ShaderNode { public: SHADER_NODE_CLASS(CombineHSVNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, h) NODE_SOCKET_API(float, s) @@ -1221,7 +1221,7 @@ class CombineHSVNode : public ShaderNode { class CombineXYZNode : public ShaderNode { public: SHADER_NODE_CLASS(CombineXYZNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, x) NODE_SOCKET_API(float, y) @@ -1231,7 +1231,7 @@ class CombineXYZNode : public ShaderNode { class GammaNode : public ShaderNode { public: SHADER_NODE_CLASS(GammaNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, color) NODE_SOCKET_API(float, gamma) @@ -1240,7 +1240,7 @@ class GammaNode : public ShaderNode { class BrightContrastNode : public ShaderNode { public: SHADER_NODE_CLASS(BrightContrastNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, color) NODE_SOCKET_API(float, bright) @@ -1250,7 +1250,7 @@ class BrightContrastNode : public ShaderNode { class SeparateColorNode : public ShaderNode { public: SHADER_NODE_CLASS(SeparateColorNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(NodeCombSepColorType, color_type) NODE_SOCKET_API(float3, color) @@ -1259,7 +1259,7 @@ class SeparateColorNode : public ShaderNode { class SeparateRGBNode : public ShaderNode { public: SHADER_NODE_CLASS(SeparateRGBNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, color) }; @@ -1267,7 +1267,7 @@ class SeparateRGBNode : public ShaderNode { class SeparateHSVNode : public ShaderNode { public: SHADER_NODE_CLASS(SeparateHSVNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, color) }; @@ -1275,7 +1275,7 @@ class SeparateHSVNode : public ShaderNode { class SeparateXYZNode : public ShaderNode { public: SHADER_NODE_CLASS(SeparateXYZNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, vector) }; @@ -1294,12 +1294,12 @@ class HSVNode : public ShaderNode { class AttributeNode : public ShaderNode { public: SHADER_NODE_CLASS(AttributeNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1310,7 +1310,7 @@ class AttributeNode : public ShaderNode { class CameraNode : public ShaderNode { public: SHADER_NODE_CLASS(CameraNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1319,7 +1319,7 @@ class CameraNode : public ShaderNode { class FresnelNode : public ShaderNode { public: SHADER_NODE_CLASS(FresnelNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1331,7 +1331,7 @@ class FresnelNode : public ShaderNode { class LayerWeightNode : public ShaderNode { public: SHADER_NODE_CLASS(LayerWeightNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1343,7 +1343,7 @@ class LayerWeightNode : public ShaderNode { class WireframeNode : public ShaderNode { public: SHADER_NODE_CLASS(WireframeNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1362,7 +1362,7 @@ class WavelengthNode : public ShaderNode { class BlackbodyNode : public ShaderNode { public: SHADER_NODE_CLASS(BlackbodyNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, temperature) }; @@ -1370,7 +1370,7 @@ class BlackbodyNode : public ShaderNode { class VectorMapRangeNode : public ShaderNode { public: SHADER_NODE_CLASS(VectorMapRangeNode) - void expand(ShaderGraph *graph); + void expand(ShaderGraph *graph) override; NODE_SOCKET_API(float3, vector) NODE_SOCKET_API(float3, from_min) @@ -1385,7 +1385,7 @@ class VectorMapRangeNode : public ShaderNode { class MapRangeNode : public ShaderNode { public: SHADER_NODE_CLASS(MapRangeNode) - void expand(ShaderGraph *graph); + void expand(ShaderGraph *graph) override; NODE_SOCKET_API(float, value) NODE_SOCKET_API(float, from_min) @@ -1400,7 +1400,7 @@ class MapRangeNode : public ShaderNode { class ClampNode : public ShaderNode { public: SHADER_NODE_CLASS(ClampNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, value) NODE_SOCKET_API(float, min) NODE_SOCKET_API(float, max) @@ -1410,8 +1410,8 @@ class ClampNode : public ShaderNode { class MathNode : public ShaderNode { public: SHADER_NODE_CLASS(MathNode) - void expand(ShaderGraph *graph); - void constant_fold(const ConstantFolder &folder); + void expand(ShaderGraph *graph) override; + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float, value1) NODE_SOCKET_API(float, value2) @@ -1431,7 +1431,7 @@ class NormalNode : public ShaderNode { class VectorMathNode : public ShaderNode { public: SHADER_NODE_CLASS(VectorMathNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API(float3, vector1) NODE_SOCKET_API(float3, vector2) @@ -1466,12 +1466,12 @@ class VectorTransformNode : public ShaderNode { class BumpNode : public ShaderNode { public: SHADER_NODE_CLASS(BumpNode) - void constant_fold(const ConstantFolder &folder); - bool has_spatial_varying() + void constant_fold(const ConstantFolder &folder) override; + bool has_spatial_varying() override { return true; } - virtual int get_feature() + int get_feature() override { return KERNEL_FEATURE_NODE_BUMP; } @@ -1509,19 +1509,19 @@ class CurvesNode : public ShaderNode { class RGBCurvesNode : public CurvesNode { public: SHADER_NODE_CLASS(RGBCurvesNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; }; class VectorCurvesNode : public CurvesNode { public: SHADER_NODE_CLASS(VectorCurvesNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; }; class FloatCurveNode : public ShaderNode { public: SHADER_NODE_CLASS(FloatCurveNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API_ARRAY(array, curve) NODE_SOCKET_API(float, min_x) @@ -1534,7 +1534,7 @@ class FloatCurveNode : public ShaderNode { class RGBRampNode : public ShaderNode { public: SHADER_NODE_CLASS(RGBRampNode) - void constant_fold(const ConstantFolder &folder); + void constant_fold(const ConstantFolder &folder) override; NODE_SOCKET_API_ARRAY(array, ramp) NODE_SOCKET_API_ARRAY(array, ramp_alpha) @@ -1551,7 +1551,7 @@ class SetNormalNode : public ShaderNode { class OSLNode final : public ShaderNode { public: static OSLNode *create(ShaderGraph *graph, size_t num_inputs, const OSLNode *from = nullptr); - ~OSLNode(); + ~OSLNode() override; static void operator delete(void *ptr) { @@ -1560,12 +1560,12 @@ class OSLNode final : public ShaderNode { * extra space at the end of the node. */ ::operator delete(ptr); } - static void operator delete(void *, void *) + static void operator delete(void * /*unused*/, void * /*unused*/) { /* Deliberately empty placement delete operator, to avoid MSVC warning C4291. */ } - ShaderNode *clone(ShaderGraph *graph) const; + ShaderNode *clone(ShaderGraph *graph) const override; char *input_default_value(); void add_input(ustring name, SocketType::Type type, const int flags = 0); @@ -1573,26 +1573,26 @@ class OSLNode final : public ShaderNode { SHADER_NODE_NO_CLONE_CLASS(OSLNode) - bool has_surface_emission() + bool has_surface_emission() override { return has_emission; } /* Ideally we could better detect this, but we can't query this now. */ - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } - bool has_volume_support() + bool has_volume_support() override { return true; } - virtual int get_feature() + int get_feature() override { return ShaderNode::get_feature() | KERNEL_FEATURE_NODE_RAYTRACE; } - virtual bool equals(const ShaderNode & /*other*/) + bool equals(const ShaderNode & /*other*/) override { return false; } @@ -1605,12 +1605,12 @@ class OSLNode final : public ShaderNode { class NormalMapNode : public ShaderNode { public: SHADER_NODE_CLASS(NormalMapNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1624,12 +1624,12 @@ class NormalMapNode : public ShaderNode { class TangentNode : public ShaderNode { public: SHADER_NODE_CLASS(TangentNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } @@ -1642,11 +1642,11 @@ class TangentNode : public ShaderNode { class BevelNode : public ShaderNode { public: SHADER_NODE_CLASS(BevelNode) - bool has_spatial_varying() + bool has_spatial_varying() override { return true; } - virtual int get_feature() + int get_feature() override { return KERNEL_FEATURE_NODE_RAYTRACE; } @@ -1659,8 +1659,8 @@ class BevelNode : public ShaderNode { class DisplacementNode : public ShaderNode { public: SHADER_NODE_CLASS(DisplacementNode) - void constant_fold(const ConstantFolder &folder); - virtual int get_feature() + void constant_fold(const ConstantFolder &folder) override; + int get_feature() override { return KERNEL_FEATURE_NODE_BUMP; } @@ -1675,13 +1675,13 @@ class DisplacementNode : public ShaderNode { class VectorDisplacementNode : public ShaderNode { public: SHADER_NODE_CLASS(VectorDisplacementNode) - void attributes(Shader *shader, AttributeRequestSet *attributes); - bool has_attribute_dependency() + void attributes(Shader *shader, AttributeRequestSet *attributes) override; + bool has_attribute_dependency() override { return true; } - void constant_fold(const ConstantFolder &folder); - virtual int get_feature() + void constant_fold(const ConstantFolder &folder) override; + int get_feature() override { return KERNEL_FEATURE_NODE_BUMP; } diff --git a/intern/cycles/scene/stats.cpp b/intern/cycles/scene/stats.cpp index edc921cca16..f6ba48d39fe 100644 --- a/intern/cycles/scene/stats.cpp +++ b/intern/cycles/scene/stats.cpp @@ -41,11 +41,11 @@ bool namedSampleCountPairComparator(const NamedSampleCountPair &a, const NamedSa } // namespace -NamedSizeEntry::NamedSizeEntry() : name(""), size(0) {} +NamedSizeEntry::NamedSizeEntry() : size(0) {} NamedSizeEntry::NamedSizeEntry(const string &name, size_t size) : name(name), size(size) {} -NamedTimeEntry::NamedTimeEntry() : name(""), time(0) {} +NamedTimeEntry::NamedTimeEntry() : time(0) {} NamedTimeEntry::NamedTimeEntry(const string &name, double time) : name(name), time(time) {} @@ -63,7 +63,7 @@ string NamedSizeStats::full_report(int indent_level) { const string indent(indent_level * kIndentNumSpaces, ' '); const string double_indent = indent + indent; - string result = ""; + string result; result += string_printf("%sTotal memory: %s (%s)\n", indent.c_str(), string_human_readable_size(total_size).c_str(), @@ -83,7 +83,7 @@ string NamedTimeStats::full_report(int indent_level) { const string indent(indent_level * kIndentNumSpaces, ' '); const string double_indent = indent + indent; - string result = ""; + 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) { @@ -95,7 +95,7 @@ string NamedTimeStats::full_report(int indent_level) /* Named time sample statistics. */ -NamedNestedSampleStats::NamedNestedSampleStats() : name(""), self_samples(0), sum_samples(0) {} +NamedNestedSampleStats::NamedNestedSampleStats() : self_samples(0), sum_samples(0) {} NamedNestedSampleStats::NamedNestedSampleStats(const string &name, uint64_t samples) : name(name), self_samples(samples), sum_samples(samples) @@ -153,7 +153,7 @@ NamedSampleCountPair::NamedSampleCountPair(const ustring &name, uint64_t samples { } -NamedSampleCountStats::NamedSampleCountStats() {} +NamedSampleCountStats::NamedSampleCountStats() = default; void NamedSampleCountStats::add(const ustring &name, uint64_t samples, uint64_t hits) { @@ -186,7 +186,7 @@ string NamedSampleCountStats::full_report(int indent_level) sort(sorted_entries.begin(), sorted_entries.end(), namedSampleCountPairComparator); - string result = ""; + string result; foreach (const NamedSampleCountPair &entry, sorted_entries) { const double seconds = entry.samples * 0.001; const double relative = ((double)entry.samples) / (entry.hits * avg_samples_per_hit); @@ -200,24 +200,24 @@ string NamedSampleCountStats::full_report(int indent_level) /* Mesh statistics. */ -MeshStats::MeshStats() {} +MeshStats::MeshStats() = default; string MeshStats::full_report(int indent_level) { const string indent(indent_level * kIndentNumSpaces, ' '); - string result = ""; + string result; result += indent + "Geometry:\n" + geometry.full_report(indent_level + 1); return result; } /* Image statistics. */ -ImageStats::ImageStats() {} +ImageStats::ImageStats() = default; string ImageStats::full_report(int indent_level) { const string indent(indent_level * kIndentNumSpaces, ' '); - string result = ""; + string result; result += indent + "Textures:\n" + textures.full_report(indent_level + 1); return result; } @@ -284,7 +284,7 @@ void RenderStats::collect_profiling(Scene *scene, Profiler &prof) string RenderStats::full_report() { - string result = ""; + string result; result += "Mesh statistics:\n" + mesh.full_report(1); result += "Image statistics:\n" + image.full_report(1); if (has_profiling) { @@ -305,11 +305,11 @@ string UpdateTimeStats::full_report(int indent_level) return times.full_report(indent_level + 1); } -SceneUpdateStats::SceneUpdateStats() {} +SceneUpdateStats::SceneUpdateStats() = default; string SceneUpdateStats::full_report() { - string result = ""; + string result; result += "Scene:\n" + scene.full_report(1); result += "Geometry:\n" + geometry.full_report(1); result += "Light:\n" + light.full_report(1); diff --git a/intern/cycles/scene/stats.h b/intern/cycles/scene/stats.h index 04b5449560d..a7cdac0c8c4 100644 --- a/intern/cycles/scene/stats.h +++ b/intern/cycles/scene/stats.h @@ -6,7 +6,6 @@ #include "scene/scene.h" -#include "util/stats.h" #include "util/string.h" #include "util/vector.h" @@ -130,7 +129,7 @@ class NamedSampleCountStats { string full_report(int indent_level = 0); void add(const ustring &name, uint64_t samples, uint64_t hits); - typedef unordered_map entry_map; + using entry_map = unordered_map; entry_map entries; }; diff --git a/intern/cycles/scene/svm.cpp b/intern/cycles/scene/svm.cpp index f55eab52616..651e996da61 100644 --- a/intern/cycles/scene/svm.cpp +++ b/intern/cycles/scene/svm.cpp @@ -23,9 +23,9 @@ CCL_NAMESPACE_BEGIN /* Shader Manager */ -SVMShaderManager::SVMShaderManager() {} +SVMShaderManager::SVMShaderManager() = default; -SVMShaderManager::~SVMShaderManager() {} +SVMShaderManager::~SVMShaderManager() = default; void SVMShaderManager::reset(Scene * /*scene*/) {} @@ -651,7 +651,7 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node, * as exclusive deps of one or the other closure, since the need to * execute them for AOV writing is not dependent on the closure * weights. */ - if (state->aov_nodes.size()) { + if (!state->aov_nodes.empty()) { set_intersection(state->aov_nodes.begin(), state->aov_nodes.end(), cl1deps.begin(), @@ -961,7 +961,7 @@ SVMCompiler::Summary::Summary() string SVMCompiler::Summary::full_report() const { - string report = ""; + string report; report += string_printf("Number of SVM nodes: %d\n", num_svm_nodes); report += string_printf("Peak stack usage: %d\n", peak_stack_usage); diff --git a/intern/cycles/scene/svm.h b/intern/cycles/scene/svm.h index d1b6ac8b528..29685cee748 100644 --- a/intern/cycles/scene/svm.h +++ b/intern/cycles/scene/svm.h @@ -4,14 +4,11 @@ #pragma once -#include "scene/attribute.h" #include "scene/shader.h" #include "scene/shader_graph.h" #include "util/array.h" -#include "util/set.h" #include "util/string.h" -#include "util/thread.h" CCL_NAMESPACE_BEGIN @@ -29,7 +26,7 @@ class ShaderOutput; class SVMShaderManager : public ShaderManager { public: SVMShaderManager(); - ~SVMShaderManager(); + ~SVMShaderManager() override; void reset(Scene *scene) override; diff --git a/intern/cycles/scene/tables.cpp b/intern/cycles/scene/tables.cpp index 75de3cd0d70..9b8028c687c 100644 --- a/intern/cycles/scene/tables.cpp +++ b/intern/cycles/scene/tables.cpp @@ -21,10 +21,10 @@ LookupTables::LookupTables() LookupTables::~LookupTables() { - assert(lookup_tables.size() == 0); + assert(lookup_tables.empty()); } -void LookupTables::device_update(Device *, DeviceScene *dscene, Scene *scene) +void LookupTables::device_update(Device * /*unused*/, DeviceScene *dscene, Scene *scene) { if (!need_update()) { return; @@ -38,14 +38,14 @@ void LookupTables::device_update(Device *, DeviceScene *dscene, Scene *scene) VLOG_INFO << "Total " << lookup_tables.size() << " lookup tables."; - if (lookup_tables.size() > 0) { + if (!lookup_tables.empty()) { dscene->lookup_table.copy_to_device(); } need_update_ = false; } -void LookupTables::device_free(Device *, DeviceScene *dscene) +void LookupTables::device_free(Device * /*unused*/, DeviceScene *dscene) { dscene->lookup_table.free(); } @@ -62,7 +62,7 @@ static size_t round_up_to_multiple(size_t size, size_t chunk) size_t LookupTables::add_table(DeviceScene *dscene, vector &data) { - assert(data.size() > 0); + assert(!data.empty()); need_update_ = true; @@ -78,9 +78,7 @@ size_t LookupTables::add_table(DeviceScene *dscene, vector &data) lookup_tables.insert(table, new_table); break; } - else { - new_table.offset = table->offset + table->size; - } + new_table.offset = table->offset + table->size; } if (table == lookup_tables.end()) { @@ -91,7 +89,7 @@ size_t LookupTables::add_table(DeviceScene *dscene, vector &data) /* copy table data and return offset */ float *dtable = dscene->lookup_table.data(); - memcpy(dtable + new_table.offset, &data[0], sizeof(float) * data.size()); + memcpy(dtable + new_table.offset, data.data(), sizeof(float) * data.size()); return new_table.offset; } diff --git a/intern/cycles/scene/tabulated_sobol.cpp b/intern/cycles/scene/tabulated_sobol.cpp index 05d4ffb4807..2419bbb1ffd 100644 --- a/intern/cycles/scene/tabulated_sobol.cpp +++ b/intern/cycles/scene/tabulated_sobol.cpp @@ -9,9 +9,6 @@ #include "scene/tabulated_sobol.h" #include "util/hash.h" -#include -#include - CCL_NAMESPACE_BEGIN void tabulated_sobol_generate_4D(float4 points[], int size, int rng_seed) diff --git a/intern/cycles/scene/volume.cpp b/intern/cycles/scene/volume.cpp index 3c7381825b1..0d192c328c0 100644 --- a/intern/cycles/scene/volume.cpp +++ b/intern/cycles/scene/volume.cpp @@ -298,7 +298,7 @@ void VolumeMeshBuilder::create_mesh(vector &vertices, #ifdef WITH_OPENVDB static bool is_non_empty_leaf(const openvdb::MaskGrid::TreeType &tree, const openvdb::Coord coord) { - auto *leaf_node = tree.probeLeaf(coord); + const auto *leaf_node = tree.probeLeaf(coord); return (leaf_node && !leaf_node->isEmpty()); } #endif @@ -561,7 +561,7 @@ static openvdb::FloatGrid::ConstPtr get_vdb_for_attribute(Volume *volume, Attrib } class MergeScalarGrids { - typedef openvdb::FloatTree ScalarTree; + using ScalarTree = openvdb::FloatTree; openvdb::tree::ValueAccessor m_acc_x, m_acc_y, m_acc_z; @@ -572,9 +572,8 @@ class MergeScalarGrids { } MergeScalarGrids(const MergeScalarGrids &other) - : m_acc_x(other.m_acc_x), m_acc_y(other.m_acc_y), m_acc_z(other.m_acc_z) - { - } + + = default; void operator()(const openvdb::Vec3STree::ValueOnIter &it) const { diff --git a/intern/cycles/scene/volume.h b/intern/cycles/scene/volume.h index 6955f3f33de..1d15d14a3e0 100644 --- a/intern/cycles/scene/volume.h +++ b/intern/cycles/scene/volume.h @@ -21,7 +21,7 @@ class Volume : public Mesh { NODE_SOCKET_API(bool, object_space) NODE_SOCKET_API(float, velocity_scale) - virtual void clear(bool preserve_shaders = false) override; + void clear(bool preserve_shaders = false) override; }; CCL_NAMESPACE_END diff --git a/intern/cycles/session/buffers.cpp b/intern/cycles/session/buffers.cpp index 18b19ee5280..7b6c5b9ebcc 100644 --- a/intern/cycles/session/buffers.cpp +++ b/intern/cycles/session/buffers.cpp @@ -2,16 +2,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include "device/device.h" #include "session/buffers.h" #include "util/foreach.h" -#include "util/hash.h" -#include "util/math.h" -#include "util/time.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/session/buffers.h b/intern/cycles/session/buffers.h index 8f0dcd90b58..010879bed27 100644 --- a/intern/cycles/session/buffers.h +++ b/intern/cycles/session/buffers.h @@ -10,10 +10,7 @@ #include "kernel/types.h" -#include "util/half.h" #include "util/string.h" -#include "util/thread.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN @@ -43,17 +40,17 @@ class BufferPass : public Node { BufferPass &operator=(BufferPass &&other) = default; BufferPass &operator=(const BufferPass &other) = default; - ~BufferPass() = default; + ~BufferPass() override = default; PassInfo get_info() const; - inline bool operator==(const BufferPass &other) const + bool operator==(const BufferPass &other) const { return type == other.type && mode == other.mode && name == other.name && include_albedo == other.include_albedo && lightgroup == other.lightgroup && offset == other.offset; } - inline bool operator!=(const BufferPass &other) const + bool operator!=(const BufferPass &other) const { return !(*this == other); } @@ -109,7 +106,7 @@ class BufferParams : public Node { BufferParams &operator=(BufferParams &&other) = default; BufferParams &operator=(const BufferParams &other) = default; - ~BufferParams() = default; + ~BufferParams() override = default; /* Pre-calculate all fields which depends on the passes. * diff --git a/intern/cycles/session/denoising.cpp b/intern/cycles/session/denoising.cpp index 97b1368e1dc..eeb359fe1d0 100644 --- a/intern/cycles/session/denoising.cpp +++ b/intern/cycles/session/denoising.cpp @@ -6,9 +6,7 @@ #include "device/cpu/device.h" #include "util/map.h" -#include "util/system.h" #include "util/task.h" -#include "util/time.h" #include @@ -142,7 +140,7 @@ bool DenoiseImageLayer::match_channels(const std::vector &channelnames, { vector &mapping = previous_output_to_image_channel; - assert(mapping.size() == 0); + assert(mapping.empty()); mapping.resize(output_to_image_channel.size(), -1); for (int i = 0; i < output_to_image_channel.size(); i++) { @@ -379,7 +377,7 @@ bool DenoiseImage::parse_channels(const ImageSpec &in_spec, string &error) */ if (layer.samples < 1) { string sample_string = in_spec.get_string_attribute("cycles." + name + ".samples", ""); - if (sample_string != "") { + if (!sample_string.empty()) { if (!sscanf(sample_string.c_str(), "%d", &layer.samples)) { error = "Failed to parse samples metadata: " + sample_string; return false; diff --git a/intern/cycles/session/denoising.h b/intern/cycles/session/denoising.h index 2a8eec7bbd9..8058a7781b2 100644 --- a/intern/cycles/session/denoising.h +++ b/intern/cycles/session/denoising.h @@ -8,8 +8,11 @@ * parameters. Currently it is an annoying mixture of terms used interchangeably. */ #include "device/device.h" + #include "integrator/denoiser.h" +#include "session/buffers.h" + #include "util/string.h" #include "util/unique_ptr.h" #include "util/vector.h" diff --git a/intern/cycles/session/merge.cpp b/intern/cycles/session/merge.cpp index e4837714366..e447cc70b79 100644 --- a/intern/cycles/session/merge.cpp +++ b/intern/cycles/session/merge.cpp @@ -6,7 +6,6 @@ #include "util/array.h" #include "util/map.h" -#include "util/system.h" #include "util/time.h" #include "util/unique_ptr.h" @@ -82,18 +81,15 @@ static MergeChannelOp parse_channel_operation(const string &pass_name) { return MERGE_CHANNEL_COPY; } - else if (string_startswith(pass_name, "Debug BVH") || - string_startswith(pass_name, "Debug Ray") || - string_startswith(pass_name, "Debug Render Time")) + if (string_startswith(pass_name, "Debug BVH") || string_startswith(pass_name, "Debug Ray") || + string_startswith(pass_name, "Debug Render Time")) { return MERGE_CHANNEL_SUM; } - else if (string_startswith(pass_name, "Debug Sample Count")) { + if (string_startswith(pass_name, "Debug Sample Count")) { return MERGE_CHANNEL_SAMPLES; } - else { - return MERGE_CHANNEL_AVERAGE; - } + return MERGE_CHANNEL_AVERAGE; } /* Splits in at its last dot, setting suffix to the part after the dot and @@ -151,7 +147,7 @@ static bool parse_channels(const ImageSpec &in_spec, for (int i = 0; i < in_spec.nchannels; i++) { MergeImagePass pass; pass.channel_name = in_spec.channelnames[i]; - pass.format = (in_spec.channelformats.size() > 0) ? in_spec.channelformats[i] : in_spec.format; + pass.format = (!in_spec.channelformats.empty()) ? in_spec.channelformats[i] : in_spec.format; pass.offset = i; pass.merge_offset = i; @@ -196,12 +192,12 @@ static bool parse_channels(const ImageSpec &in_spec, layer.samples = 0; /* Determine number of samples from metadata. */ - if (layer.name == "") { + if (layer.name.empty()) { layer.samples = 1; } else if (layer.samples < 1) { string sample_string = in_spec.get_string_attribute("cycles." + name + ".samples", ""); - if (sample_string != "") { + if (!sample_string.empty()) { if (!sscanf(sample_string.c_str(), "%d", &layer.samples)) { error = "Failed to parse samples metadata: " + sample_string; return false; @@ -251,7 +247,7 @@ static bool open_images(const vector &filepaths, vector &ima return false; } - if (image.layers.size() == 0) { + if (image.layers.empty()) { error = "Could not find a render layer for merging"; return false; } @@ -261,7 +257,7 @@ static bool open_images(const vector &filepaths, vector &ima return false; } - if (images.size() > 0) { + if (!images.empty()) { const ImageSpec &base_spec = images[0].in->spec(); const ImageSpec &spec = image.in->spec(); @@ -366,7 +362,7 @@ static void merge_channels_metadata(vector &images, ImageSpec &out_s map layer_num_samples; for (MergeImage &image : images) { for (MergeImageLayer &layer : image.layers) { - if (layer.name != "") { + if (!layer.name.empty()) { layer_num_samples[layer.name] += layer.samples; } } @@ -570,7 +566,7 @@ static void read_layer_samples(vector &images, } /* Image Merger */ -ImageMerger::ImageMerger() {} +ImageMerger::ImageMerger() = default; bool ImageMerger::run() { diff --git a/intern/cycles/session/session.cpp b/intern/cycles/session/session.cpp index 422159a7bcf..3c3b3494f83 100644 --- a/intern/cycles/session/session.cpp +++ b/intern/cycles/session/session.cpp @@ -2,15 +2,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include #include "device/cpu/device.h" #include "device/device.h" -#include "integrator/pass_accessor_cpu.h" #include "integrator/path_trace.h" #include "scene/background.h" -#include "scene/bake.h" #include "scene/camera.h" #include "scene/integrator.h" #include "scene/light.h" @@ -240,7 +237,7 @@ void Session::thread_run() session_thread_cond_.wait(session_thread_lock); continue; } - else if (session_thread_state_ == SESSION_THREAD_END) { + if (session_thread_state_ == SESSION_THREAD_END) { /* End thread immediately. */ break; } diff --git a/intern/cycles/session/session.h b/intern/cycles/session/session.h index 3b32b6b0cbc..af3b908b92b 100644 --- a/intern/cycles/session/session.h +++ b/intern/cycles/session/session.h @@ -17,7 +17,6 @@ #include "util/stats.h" #include "util/thread.h" #include "util/unique_ptr.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/session/tile.cpp b/intern/cycles/session/tile.cpp index 8a617b48125..4273e6bbad8 100644 --- a/intern/cycles/session/tile.cpp +++ b/intern/cycles/session/tile.cpp @@ -13,7 +13,7 @@ #include "scene/integrator.h" #include "scene/scene.h" #include "session/session.h" -#include "util/algorithm.h" + #include "util/foreach.h" #include "util/log.h" #include "util/path.h" @@ -320,7 +320,7 @@ TileManager::TileManager() to_string(tile_manager_id); } -TileManager::~TileManager() {} +TileManager::~TileManager() = default; int TileManager::compute_render_tile_size(const int suggested_tile_size) const { @@ -438,7 +438,7 @@ const Tile &TileManager::get_current_tile() const return tile_state_.current_tile; } -const int2 TileManager::get_size() const +int2 TileManager::get_size() const { return make_int2(buffer_params_.width, buffer_params_.height); } diff --git a/intern/cycles/session/tile.h b/intern/cycles/session/tile.h index a5015a09ab7..00b992ff7e7 100644 --- a/intern/cycles/session/tile.h +++ b/intern/cycles/session/tile.h @@ -29,7 +29,7 @@ class Tile { int window_x = 0, window_y = 0; int window_width = 0, window_height = 0; - Tile() {} + Tile() = default; }; /* -------------------------------------------------------------------- @@ -62,17 +62,17 @@ class TileManager { void set_temp_dir(const string &temp_dir); - inline int get_num_tiles() const + int get_num_tiles() const { return tile_state_.num_tiles; } - inline bool has_multiple_tiles() const + bool has_multiple_tiles() const { return tile_state_.num_tiles > 1; } - inline int get_tile_overscan() const + int get_tile_overscan() const { return overscan_; } @@ -81,7 +81,7 @@ class TileManager { bool done(); const Tile &get_current_tile() const; - const int2 get_size() const; + int2 get_size() const; /* Write render buffer of a tile to a file on disk. * @@ -95,7 +95,7 @@ class TileManager { void finish_write_tiles(); /* Check whether any tile has been written to disk. */ - inline bool has_written_tiles() const + bool has_written_tiles() const { return write_state_.num_tiles_written != 0; } diff --git a/intern/cycles/subd/dice.h b/intern/cycles/subd/dice.h index 551c6c7c550..fb7b258f2c1 100644 --- a/intern/cycles/subd/dice.h +++ b/intern/cycles/subd/dice.h @@ -9,8 +9,7 @@ * DiagSplit. For more algorithm details, see the DiagSplit paper or the * ARB_tessellation_shader OpenGL extension, Section 2.X.2. */ -#include "util/types.h" -#include "util/vector.h" +#include "util/transform.h" #include "subd/subpatch.h" diff --git a/intern/cycles/subd/patch.cpp b/intern/cycles/subd/patch.cpp index b28c64c6c9d..8750e219703 100644 --- a/intern/cycles/subd/patch.cpp +++ b/intern/cycles/subd/patch.cpp @@ -4,8 +4,6 @@ /* Parts adapted from code in the public domain in NVidia Mesh Tools. */ -#include "scene/mesh.h" - #include "subd/patch.h" #include "util/math.h" diff --git a/intern/cycles/subd/patch.h b/intern/cycles/subd/patch.h index b3c781399b9..8b65840bf38 100644 --- a/intern/cycles/subd/patch.h +++ b/intern/cycles/subd/patch.h @@ -11,15 +11,15 @@ CCL_NAMESPACE_BEGIN class Patch { public: - Patch() : patch_index(0), shader(0), from_ngon(false) {} + Patch() = default; virtual ~Patch() = default; virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) = 0; - int patch_index; - int shader; - bool from_ngon; + int patch_index = 0; + int shader = 0; + bool from_ngon = false; }; /* Linear Quad Patch */ @@ -29,7 +29,7 @@ class LinearQuadPatch : public Patch { float3 hull[4]; float3 normals[4]; - void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v); + void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) override; BoundBox bound(); }; @@ -39,7 +39,7 @@ class BicubicPatch : public Patch { public: float3 hull[16]; - void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v); + void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) override; BoundBox bound(); }; diff --git a/intern/cycles/subd/patch_table.cpp b/intern/cycles/subd/patch_table.cpp index 212ed0aadb7..b545b4ebe55 100644 --- a/intern/cycles/subd/patch_table.cpp +++ b/intern/cycles/subd/patch_table.cpp @@ -128,22 +128,20 @@ static void build_patch_map(PackedPatchTable &table, node->set_child(quadrant, handle_index + offset, true); break; } + /* travel down the child node of the corresponding quadrant */ + if (!(node->children[quadrant] & PATCH_MAP_NODE_IS_SET)) { + /* create a new branch in the quadrant */ + quadtree.push_back(PatchMapQuadNode()); + + int idx = (int)quadtree.size() - 1; + node->set_child(quadrant, idx * 4 + offset, false); + + node = &quadtree[idx]; + } else { - /* travel down the child node of the corresponding quadrant */ - if (!(node->children[quadrant] & PATCH_MAP_NODE_IS_SET)) { - /* create a new branch in the quadrant */ - quadtree.push_back(PatchMapQuadNode()); - - int idx = (int)quadtree.size() - 1; - node->set_child(quadrant, idx * 4 + offset, false); - - node = &quadtree[idx]; - } - else { - /* travel down an existing branch */ - uint idx = node->children[quadrant] & PATCH_MAP_NODE_INDEX_MASK; - node = &(quadtree[(idx - offset) / 4]); - } + /* travel down an existing branch */ + uint idx = node->children[quadrant] & PATCH_MAP_NODE_INDEX_MASK; + node = &(quadtree[(idx - offset) / 4]); } } } diff --git a/intern/cycles/subd/patch_table.h b/intern/cycles/subd/patch_table.h index 7c8992a6b8f..d44cce12eae 100644 --- a/intern/cycles/subd/patch_table.h +++ b/intern/cycles/subd/patch_table.h @@ -26,10 +26,12 @@ struct PatchTable; } #endif +// NOLINTBEGIN #define PATCH_ARRAY_SIZE 4 #define PATCH_PARAM_SIZE 2 #define PATCH_HANDLE_SIZE 3 #define PATCH_NODE_SIZE 1 +// NOLINTEND struct PackedPatchTable { array table; diff --git a/intern/cycles/subd/split.cpp b/intern/cycles/subd/split.cpp index be52a302d9c..0b580cdecbd 100644 --- a/intern/cycles/subd/split.cpp +++ b/intern/cycles/subd/split.cpp @@ -19,9 +19,11 @@ CCL_NAMESPACE_BEGIN /* DiagSplit */ -#define DSPLIT_NON_UNIFORM -1 -#define STITCH_NGON_CENTER_VERT_INDEX_OFFSET 0x60000000 -#define STITCH_NGON_SPLIT_EDGE_CENTER_VERT_TAG (0x60000000 - 1) +enum { + DSPLIT_NON_UNIFORM = -1, + STITCH_NGON_CENTER_VERT_INDEX_OFFSET = 0x60000000, + STITCH_NGON_SPLIT_EDGE_CENTER_VERT_TAG = (0x60000000 - 1) +}; DiagSplit::DiagSplit(const SubdParams ¶ms_) : params(params_) {} @@ -614,7 +616,7 @@ void DiagSplit::post_split() return hash_uint2(k.first, k.second); } }; - typedef unordered_map, int, pair_hasher> edge_stitch_verts_map_t; + using edge_stitch_verts_map_t = unordered_map, int, pair_hasher>; edge_stitch_verts_map_t edge_stitch_verts_map; foreach (Edge &edge, edges) { diff --git a/intern/cycles/subd/split.h b/intern/cycles/subd/split.h index 974aa891f2e..bb872376698 100644 --- a/intern/cycles/subd/split.h +++ b/intern/cycles/subd/split.h @@ -9,6 +9,8 @@ * evaluation at arbitrary points is required for this to work. See the paper * for more details. */ +#include "scene/mesh.h" + #include "subd/dice.h" #include "subd/subpatch.h" @@ -16,8 +18,6 @@ #include "util/types.h" #include "util/vector.h" -#include - CCL_NAMESPACE_BEGIN class Mesh; diff --git a/intern/cycles/subd/subpatch.h b/intern/cycles/subd/subpatch.h index bec44879f94..3838bcbe500 100644 --- a/intern/cycles/subd/subpatch.h +++ b/intern/cycles/subd/subpatch.h @@ -5,7 +5,7 @@ #pragma once #include "util/map.h" -#include "util/types.h" +#include "util/math_float2.h" CCL_NAMESPACE_BEGIN @@ -69,19 +69,19 @@ class Subpatch { int calc_num_inner_verts() const { - int Mu = max(edge_u0.T, edge_u1.T); - int Mv = max(edge_v0.T, edge_v1.T); - Mu = max(Mu, 2); - Mv = max(Mv, 2); + int Mu = fmax(edge_u0.T, edge_u1.T); + int Mv = fmax(edge_v0.T, edge_v1.T); + Mu = fmax(Mu, 2); + Mv = fmax(Mv, 2); return (Mu - 1) * (Mv - 1); } int calc_num_triangles() const { - int Mu = max(edge_u0.T, edge_u1.T); - int Mv = max(edge_v0.T, edge_v1.T); - Mu = max(Mu, 2); - Mv = max(Mv, 2); + int Mu = fmax(edge_u0.T, edge_u1.T); + int Mv = fmax(edge_v0.T, edge_v1.T); + Mu = fmax(Mu, 2); + Mv = fmax(Mv, 2); int inner_triangles = (Mu - 2) * (Mv - 2) * 2; int edge_triangles = edge_u0.T + edge_u1.T + edge_v0.T + edge_v1.T + (Mu - 2) * 2 + @@ -94,10 +94,10 @@ class Subpatch { int get_vert_along_grid_edge(int edge, int n) const { - int Mu = max(edge_u0.T, edge_u1.T); - int Mv = max(edge_v0.T, edge_v1.T); - Mu = max(Mu, 2); - Mv = max(Mv, 2); + int Mu = fmax(edge_u0.T, edge_u1.T); + int Mv = fmax(edge_v0.T, edge_v1.T); + Mu = fmax(Mu, 2); + Mv = fmax(Mv, 2); switch (edge) { case 0: @@ -116,50 +116,35 @@ class Subpatch { struct Edge { /* Number of segments the edge will be diced into, see DiagSplit paper. */ - int T; + int T = 0; /* top is edge adjacent to start, bottom is adjacent to end. */ - Edge *top, *bottom; + Edge *top = nullptr, *bottom = nullptr; - int top_offset, bottom_offset; - bool top_indices_decrease, bottom_indices_decrease; + int top_offset = -1, bottom_offset = -1; + bool top_indices_decrease = false, bottom_indices_decrease = false; - int start_vert_index; - int end_vert_index; + int start_vert_index = -1; + int end_vert_index = -1; /* Index of the second vert from this edges corner along the edge towards the next corner. */ - int second_vert_index; + int second_vert_index = -1; /* Vertices on edge are to be stitched. */ - bool is_stitch_edge; + bool is_stitch_edge = false; /* Key to match this edge with others to be stitched with. * The ints in the pair are ordered stitching indices */ pair stitch_edge_key; /* Full T along edge (may be larger than T for edges split from ngon edges) */ - int stitch_edge_T; - int stitch_offset; + int stitch_edge_T = 0; + int stitch_offset = 0; int stitch_top_offset; int stitch_start_vert_index; int stitch_end_vert_index; - Edge() - : T(0), - top(nullptr), - bottom(nullptr), - top_offset(-1), - bottom_offset(-1), - top_indices_decrease(false), - bottom_indices_decrease(false), - start_vert_index(-1), - end_vert_index(-1), - second_vert_index(-1), - is_stitch_edge(false), - stitch_edge_T(0), - stitch_offset(0) - { - } + Edge() = default; int get_vert_along_edge(int n) const { @@ -168,7 +153,7 @@ struct Edge { if (n == 0) { return start_vert_index; } - else if (n == T) { + if (n == T) { return end_vert_index; } diff --git a/intern/cycles/test/kernel_camera_projection_test.cpp b/intern/cycles/test/kernel_camera_projection_test.cpp index a8842b91913..ed712f7329d 100644 --- a/intern/cycles/test/kernel_camera_projection_test.cpp +++ b/intern/cycles/test/kernel_camera_projection_test.cpp @@ -7,9 +7,6 @@ #include "util/math.h" #include "util/types.h" -#include "kernel/globals.h" -#include "kernel/types.h" - #include "kernel/camera/projection.h" CCL_NAMESPACE_BEGIN @@ -293,7 +290,7 @@ struct FisheyeEquidistant : public CommonValues { }; struct FisheyeEquisolid : public CommonValues { - bool skip_invalid() const + bool skip_invalid() const override { return true; } diff --git a/intern/cycles/test/render_graph_finalize_test.cpp b/intern/cycles/test/render_graph_finalize_test.cpp index e07b13fe3f6..67a678f0741 100644 --- a/intern/cycles/test/render_graph_finalize_test.cpp +++ b/intern/cycles/test/render_graph_finalize_test.cpp @@ -163,7 +163,7 @@ class RenderGraph : public testing::Test { RenderGraph() : testing::Test(), builder(&graph) {} - virtual void SetUp() + void SetUp() override { /* The test is running outside of the typical application configuration when the OCIO is * initialized prior to Cycles. Explicitly create the raw configuration to avoid the warning @@ -182,7 +182,7 @@ class RenderGraph : public testing::Test { util_logging_verbosity_set(5); } - virtual void TearDown() + void TearDown() override { /* Effectively disable logging, so that the next test suit starts in an environment which is * not logging by default. */ diff --git a/intern/cycles/test/util_string_test.cpp b/intern/cycles/test/util_string_test.cpp index 3f5842096c2..d5bb3341f93 100644 --- a/intern/cycles/test/util_string_test.cpp +++ b/intern/cycles/test/util_string_test.cpp @@ -110,14 +110,14 @@ TEST(util_string_split, multiple_spaces) TEST(util_string_replace, empty_haystack_and_other) { - string str = ""; + string str; string_replace(str, "x", ""); EXPECT_EQ(str, ""); } TEST(util_string_replace, empty_haystack) { - string str = ""; + string str; string_replace(str, "x", "y"); EXPECT_EQ(str, ""); } diff --git a/intern/cycles/test/util_task_test.cpp b/intern/cycles/test/util_task_test.cpp index 1bc6021738a..f1437a74b38 100644 --- a/intern/cycles/test/util_task_test.cpp +++ b/intern/cycles/test/util_task_test.cpp @@ -19,7 +19,7 @@ TEST(util_task, basic) TaskScheduler::init(0); TaskPool pool; for (int i = 0; i < 100; ++i) { - pool.push([] { return task_run(); }); + pool.push([] { task_run(); }); } TaskPool::Summary summary; pool.wait_work(&summary); @@ -33,7 +33,7 @@ TEST(util_task, multiple_times) TaskScheduler::init(0); TaskPool pool; for (int i = 0; i < 100; ++i) { - pool.push([] { return task_run(); }); + pool.push([] { task_run(); }); } TaskPool::Summary summary; pool.wait_work(&summary); diff --git a/intern/cycles/test/util_transform_test.cpp b/intern/cycles/test/util_transform_test.cpp index 78741008af4..e384845cf0d 100644 --- a/intern/cycles/test/util_transform_test.cpp +++ b/intern/cycles/test/util_transform_test.cpp @@ -16,7 +16,7 @@ TEST(transform_motion_decompose, Degenerated) vector motion = {transform_scale(0.0f, 0.0f, 0.0f)}; vector decomp(motion.size()); transform_motion_decompose(decomp.data(), motion.data(), motion.size()); - EXPECT_TRUE(transform_decomposed_isfinite_safe(&decomp[0])); + EXPECT_TRUE(transform_decomposed_isfinite_safe(decomp.data())); } // Copy from previous to current. diff --git a/intern/cycles/util/aligned_malloc.cpp b/intern/cycles/util/aligned_malloc.cpp index 100040999af..67f56b7aec7 100644 --- a/intern/cycles/util/aligned_malloc.cpp +++ b/intern/cycles/util/aligned_malloc.cpp @@ -3,7 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "util/aligned_malloc.h" -#include "util/guarded_allocator.h" + +#ifdef WITH_BLENDER_GUARDEDALLOC +# include "../../guardedalloc/MEM_guardedalloc.h" +#endif #include diff --git a/intern/cycles/util/aligned_malloc.h b/intern/cycles/util/aligned_malloc.h index 002f435e1c7..cded043f83a 100644 --- a/intern/cycles/util/aligned_malloc.h +++ b/intern/cycles/util/aligned_malloc.h @@ -4,12 +4,12 @@ #pragma once -#include "util/types.h" +#include CCL_NAMESPACE_BEGIN /* Minimum alignment needed by all CPU native data types (SSE, AVX). */ -#define MIN_ALIGNMENT_CPU_DATA_TYPES 16 +#define MIN_ALIGNMENT_CPU_DATA_TYPES 16 // NOLINT /* Allocate block of size bytes at least aligned to a given value. */ void *util_aligned_malloc(size_t size, int alignment); diff --git a/intern/cycles/util/array.h b/intern/cycles/util/array.h index 0156e1b1ee5..c948e2dbcb8 100644 --- a/intern/cycles/util/array.h +++ b/intern/cycles/util/array.h @@ -9,7 +9,6 @@ #include "util/aligned_malloc.h" #include "util/guarded_allocator.h" -#include "util/types.h" #include "util/vector.h" CCL_NAMESPACE_BEGIN @@ -145,7 +144,7 @@ template class arra clear(); return nullptr; } - else if (data_ != nullptr) { + if (data_ != nullptr) { mem_copy(newdata, data_, ((datasize_ < newsize) ? datasize_ : newsize)); mem_free(data_, capacity_); } @@ -269,7 +268,7 @@ template class arra } protected: - inline T *mem_allocate(size_t N) + T *mem_allocate(size_t N) { if (N == 0) { return nullptr; @@ -284,7 +283,7 @@ template class arra return mem; } - inline void mem_free(T *mem, size_t N) + void mem_free(T *mem, size_t N) { if (mem != nullptr) { util_guarded_mem_free(sizeof(T) * N); @@ -292,7 +291,7 @@ template class arra } } - inline void mem_copy(T *mem_to, const T *mem_from, const size_t N) + void mem_copy(T *mem_to, const T *mem_from, const size_t N) { memcpy((void *)mem_to, mem_from, sizeof(T) * N); } diff --git a/intern/cycles/util/atomic.h b/intern/cycles/util/atomic.h index 83357691f34..561da568b16 100644 --- a/intern/cycles/util/atomic.h +++ b/intern/cycles/util/atomic.h @@ -7,7 +7,7 @@ #ifndef __KERNEL_GPU__ /* Using atomic ops header from Blender. */ -# include "atomic_ops.h" +# include "atomic_ops.h" // IWYU pragma: export # define atomic_add_and_fetch_float(p, x) atomic_add_and_fetch_fl((p), (x)) # define atomic_compare_and_swap_float(p, old_val, new_val) \ diff --git a/intern/cycles/util/boundbox.h b/intern/cycles/util/boundbox.h index f6443129572..71a74ef4f79 100644 --- a/intern/cycles/util/boundbox.h +++ b/intern/cycles/util/boundbox.h @@ -4,8 +4,8 @@ #pragma once -#include -#include +#include +#include #include "util/math.h" #include "util/transform.h" @@ -19,7 +19,7 @@ class BoundBox { public: float3 min, max; - __forceinline BoundBox() {} + __forceinline BoundBox() = default; __forceinline BoundBox(const float3 &pt) : min(pt), max(pt) {} @@ -27,7 +27,7 @@ class BoundBox { enum empty_t { empty = 0 }; - __forceinline BoundBox(empty_t) + __forceinline BoundBox(empty_t /*unused*/) : min(make_float3(FLT_MAX, FLT_MAX, FLT_MAX)), max(make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX)) { } @@ -188,12 +188,12 @@ __forceinline BoundBox intersect(const BoundBox &a, const BoundBox &b, const Bou class BoundBox2D { public: - float left; - float right; - float bottom; - float top; + float left = 0.0f; + float right = 1.0f; + float bottom = 0.0f; + float top = 1.0f; - BoundBox2D() : left(0.0f), right(1.0f), bottom(0.0f), top(1.0f) {} + BoundBox2D() = default; bool operator==(const BoundBox2D &other) const { diff --git a/intern/cycles/util/color.h b/intern/cycles/util/color.h index ce121f8c472..3bdfc209452 100644 --- a/intern/cycles/util/color.h +++ b/intern/cycles/util/color.h @@ -7,16 +7,13 @@ #include "util/math.h" #include "util/types.h" -#if !defined(__KERNEL_GPU__) && defined(__KERNEL_SSE2__) -# include "util/simd.h" -#endif - CCL_NAMESPACE_BEGIN ccl_device uchar float_to_byte(float val) { - return ((val <= 0.0f) ? 0 : - ((val > (1.0f - 0.5f / 255.0f)) ? 255 : (uchar)((255.0f * val) + 0.5f))); + return ((val <= 0.0f) ? + 0 : + ((val > (1.0f - 0.5f / 255.0f)) ? 255 : (uchar)((255.0f * val) + 0.5f))); // NOLINT } ccl_device float byte_to_float(uchar val) @@ -63,9 +60,7 @@ ccl_device float color_srgb_to_linear(float c) if (c < 0.04045f) { return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f); } - else { - return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f); - } + return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f); } ccl_device float color_linear_to_srgb(float c) @@ -73,9 +68,7 @@ ccl_device float color_linear_to_srgb(float c) if (c < 0.0031308f) { return (c < 0.0f) ? 0.0f : c * 12.92f; } - else { - return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f; - } + return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f; } ccl_device float3 rgb_to_hsv(float3 rgb) diff --git a/intern/cycles/util/debug.cpp b/intern/cycles/util/debug.cpp index 747042af426..664f3df0aae 100644 --- a/intern/cycles/util/debug.cpp +++ b/intern/cycles/util/debug.cpp @@ -4,12 +4,9 @@ #include "util/debug.h" -#include - -#include "bvh/params.h" +#include #include "util/log.h" -#include "util/string.h" CCL_NAMESPACE_BEGIN @@ -73,15 +70,15 @@ void DebugFlags::Metal::reset() adaptive_compile = true; } - if (auto str = getenv("CYCLES_METAL_LOCAL_ATOMIC_SORT")) { + if (auto *str = getenv("CYCLES_METAL_LOCAL_ATOMIC_SORT")) { use_local_atomic_sort = (atoi(str) != 0); } - if (auto str = getenv("CYCLES_METAL_NANOVDB")) { + if (auto *str = getenv("CYCLES_METAL_NANOVDB")) { use_nanovdb = (atoi(str) != 0); } - if (auto str = getenv("CYCLES_METAL_ASYNC_PSO_CREATION")) { + if (auto *str = getenv("CYCLES_METAL_ASYNC_PSO_CREATION")) { use_async_pso_creation = (atoi(str) != 0); } } @@ -96,11 +93,6 @@ void DebugFlags::OptiX::reset() use_debug = false; } -DebugFlags::DebugFlags() -{ - /* Nothing for now. */ -} - void DebugFlags::reset() { cpu.reset(); diff --git a/intern/cycles/util/debug.h b/intern/cycles/util/debug.h index 35b54c92cc8..d2bf4352cf5 100644 --- a/intern/cycles/util/debug.h +++ b/intern/cycles/util/debug.h @@ -128,15 +128,15 @@ class DebugFlags { Metal metal; private: - DebugFlags(); + DebugFlags() = default; public: explicit DebugFlags(DebugFlags const & /*other*/) = delete; void operator=(DebugFlags const & /*other*/) = delete; }; -typedef DebugFlags &DebugFlagsRef; -typedef const DebugFlags &DebugFlagsConstRef; +using DebugFlagsRef = DebugFlags &; +using DebugFlagsConstRef = const DebugFlags &; inline DebugFlags &DebugFlags() { diff --git a/intern/cycles/util/guarded_allocator.h b/intern/cycles/util/guarded_allocator.h index dfaabcf0fa8..bb5c5bbc887 100644 --- a/intern/cycles/util/guarded_allocator.h +++ b/intern/cycles/util/guarded_allocator.h @@ -6,7 +6,6 @@ #include #include -#include #ifdef WITH_BLENDER_GUARDEDALLOC # include "../../guardedalloc/MEM_guardedalloc.h" @@ -21,18 +20,18 @@ void util_guarded_mem_free(size_t n); /* Guarded allocator for the use with STL. */ template class GuardedAllocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef T *pointer; - typedef const T *const_pointer; - typedef T &reference; - typedef const T &const_reference; - typedef T value_type; + using size_type = size_t; + using difference_type = ptrdiff_t; + using pointer = T *; + using const_pointer = const T *; + using reference = T &; + using const_reference = const T &; + using value_type = T; - GuardedAllocator() {} - GuardedAllocator(const GuardedAllocator &) {} + GuardedAllocator() = default; + GuardedAllocator(const GuardedAllocator & /*unused*/) = default; - T *allocate(size_t n, const void *hint = 0) + T *allocate(size_t n, const void *hint = nullptr) { (void)hint; size_t size = n * sizeof(T); @@ -79,10 +78,7 @@ template class GuardedAllocator { return &x; } - GuardedAllocator &operator=(const GuardedAllocator &) - { - return *this; - } + GuardedAllocator &operator=(const GuardedAllocator & /*unused*/) = default; size_t max_size() const { @@ -90,21 +86,21 @@ template class GuardedAllocator { } template struct rebind { - typedef GuardedAllocator other; + using other = GuardedAllocator; }; - template GuardedAllocator(const GuardedAllocator &) {} + template GuardedAllocator(const GuardedAllocator & /*unused*/) {} - template GuardedAllocator &operator=(const GuardedAllocator &) + template GuardedAllocator &operator=(const GuardedAllocator & /*unused*/) { return *this; } - inline bool operator==(GuardedAllocator const & /*other*/) const + bool operator==(GuardedAllocator const & /*other*/) const { return true; } - inline bool operator!=(GuardedAllocator const &other) const + bool operator!=(GuardedAllocator const &other) const { return !operator==(other); } diff --git a/intern/cycles/util/guiding.h b/intern/cycles/util/guiding.h index 1c5dbb24814..de0416d445d 100644 --- a/intern/cycles/util/guiding.h +++ b/intern/cycles/util/guiding.h @@ -5,11 +5,11 @@ #pragma once #ifdef WITH_PATH_GUIDING -# include -# include +# include // IWYU pragma: export +# include // IWYU pragma: export #endif -#include "util/system.h" +#include "util/system.h" // IWYU pragma: keep CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/half.h b/intern/cycles/util/half.h index 286ecbd3149..63d24e77620 100644 --- a/intern/cycles/util/half.h +++ b/intern/cycles/util/half.h @@ -8,7 +8,7 @@ #include "util/types.h" #if !defined(__KERNEL_GPU__) && defined(__KERNEL_SSE2__) -# include "util/simd.h" +# include "util/simd.h" // IWYU pragma: keep #endif CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/ies.cpp b/intern/cycles/util/ies.cpp index 82f0ca662a4..dbfec004921 100644 --- a/intern/cycles/util/ies.cpp +++ b/intern/cycles/util/ies.cpp @@ -37,7 +37,7 @@ void IESFile::clear() int IESFile::packed_size() { - if (v_angles.size() && h_angles.size() > 0) { + if (!v_angles.empty() && !h_angles.empty()) { return 2 + h_angles.size() + v_angles.size() + h_angles.size() * v_angles.size(); } return 0; @@ -45,17 +45,17 @@ int IESFile::packed_size() void IESFile::pack(float *data) { - if (v_angles.size() && h_angles.size()) { + if (!v_angles.empty() && !h_angles.empty()) { *(data++) = __int_as_float(h_angles.size()); *(data++) = __int_as_float(v_angles.size()); - memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); + memcpy(data, h_angles.data(), h_angles.size() * sizeof(float)); data += h_angles.size(); - memcpy(data, &v_angles[0], v_angles.size() * sizeof(float)); + memcpy(data, v_angles.data(), v_angles.size() * sizeof(float)); data += v_angles.size(); for (int h = 0; h < intensity.size(); h++) { - memcpy(data, &intensity[h][0], v_angles.size() * sizeof(float)); + memcpy(data, intensity[h].data(), v_angles.size() * sizeof(float)); data += v_angles.size(); } } @@ -65,12 +65,12 @@ class IESTextParser { public: string text; char *data; - bool error; + bool error = false; - IESTextParser(const string &str) : text(str), error(false) + IESTextParser(const string &str) : text(str) { std::replace(text.begin(), text.end(), ',', ' '); - data = strstr(&text[0], "\nTILT="); + data = strstr(text.data(), "\nTILT="); } bool eof() @@ -374,7 +374,7 @@ void IESFile::process_type_c() bool IESFile::process() { - if (h_angles.size() == 0 || v_angles.size() == 0) { + if (h_angles.empty() || v_angles.empty()) { return false; } diff --git a/intern/cycles/util/ies.h b/intern/cycles/util/ies.h index 169c7cb4a1f..0c620f5989d 100644 --- a/intern/cycles/util/ies.h +++ b/intern/cycles/util/ies.h @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN class IESFile { public: - IESFile() {} + IESFile() = default; ~IESFile(); int packed_size(); diff --git a/intern/cycles/util/image.h b/intern/cycles/util/image.h index c8fd4a2bb3c..3e56b3b6211 100644 --- a/intern/cycles/util/image.h +++ b/intern/cycles/util/image.h @@ -61,20 +61,20 @@ template<> inline uchar util_image_cast_from_float(float value) if (value < 0.0f) { return 0; } - else if (value > (1.0f - 0.5f / 255.0f)) { + if (value > (1.0f - 0.5f / 255.0f)) { return 255; } - return (uchar)((255.0f * value) + 0.5f); + return (uchar)((255.0f * value) + 0.5f); // NOLINT } template<> inline uint16_t util_image_cast_from_float(float value) { if (value < 0.0f) { return 0; } - else if (value > (1.0f - 0.5f / 65535.0f)) { + if (value > (1.0f - 0.5f / 65535.0f)) { return 65535; } - return (uint16_t)((65535.0f * value) + 0.5f); + return (uint16_t)((65535.0f * value) + 0.5f); // NOLINT } template<> inline half util_image_cast_from_float(float value) { diff --git a/intern/cycles/util/log.cpp b/intern/cycles/util/log.cpp index 4a77c674935..abb6ca4d07d 100644 --- a/intern/cycles/util/log.cpp +++ b/intern/cycles/util/log.cpp @@ -7,7 +7,7 @@ #include "util/math.h" #include "util/string.h" -#include +#include #ifdef _MSC_VER # define snprintf _snprintf #endif @@ -19,7 +19,7 @@ static bool is_verbosity_set() { using CYCLES_GFLAGS_NAMESPACE::GetCommandLineOption; - std::string verbosity; + string verbosity; if (!GetCommandLineOption("v", &verbosity)) { return false; } diff --git a/intern/cycles/util/log.h b/intern/cycles/util/log.h index 7a075f07461..6cb35aef468 100644 --- a/intern/cycles/util/log.h +++ b/intern/cycles/util/log.h @@ -5,8 +5,8 @@ #pragma once #if defined(WITH_CYCLES_LOGGING) && !defined(__KERNEL_GPU__) -# include -# include +# include // IWYU pragma: export +# include // IWYU pragma: export #endif #include diff --git a/intern/cycles/util/math_fast.h b/intern/cycles/util/math_fast.h index 7d94f877114..682298ed503 100644 --- a/intern/cycles/util/math_fast.h +++ b/intern/cycles/util/math_fast.h @@ -599,10 +599,7 @@ ccl_device_inline float fast_ierff(float x) { /* From: Approximating the `erfinv` function by Mike Giles. */ /* To avoid trouble at the limit, clamp input to 1-epsilon. */ - float a = fabsf(x); - if (a > 0.99999994f) { - a = 0.99999994f; - } + float a = min(fabsf(x), 0.99999994f); float w = -fast_logf((1.0f - a) * (1.0f + a)), p; if (w < 5.0f) { w = w - 2.5f; diff --git a/intern/cycles/util/md5.cpp b/intern/cycles/util/md5.cpp index 9c4326580fa..0a5ce5bf557 100644 --- a/intern/cycles/util/md5.cpp +++ b/intern/cycles/util/md5.cpp @@ -9,11 +9,12 @@ #include "util/md5.h" #include "util/path.h" -#include -#include +#include +#include CCL_NAMESPACE_BEGIN +// NOLINTBEGIN #define T_MASK ((uint32_t)~0) #define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) #define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) @@ -79,6 +80,7 @@ CCL_NAMESPACE_BEGIN #define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) #define T63 0x2ad7d2bb #define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) +// NOLINTEND void MD5Hash::process(const uint8_t *data /*[64]*/) { @@ -101,7 +103,7 @@ void MD5Hash::process(const uint8_t *data /*[64]*/) * On little-endian machines, we can process properly aligned * data without copying it. */ - if (!((data - (const uint8_t *)0) & 3)) { + if (!((data - (const uint8_t *)nullptr) & 3)) { /* data are properly aligned */ X = (const uint32_t *)data; } @@ -250,7 +252,7 @@ MD5Hash::MD5Hash() abcd[3] = 0x10325476; } -MD5Hash::~MD5Hash() {} +MD5Hash::~MD5Hash() = default; void MD5Hash::append(const uint8_t *data, int nbytes) { @@ -296,7 +298,7 @@ void MD5Hash::append(const uint8_t *data, int nbytes) void MD5Hash::append(const string &str) { - if (str.size()) { + if (!str.empty()) { append((const uint8_t *)str.c_str(), str.size()); } } diff --git a/intern/cycles/util/md5.h b/intern/cycles/util/md5.h index 0fef9d0088d..d80251e32cd 100644 --- a/intern/cycles/util/md5.h +++ b/intern/cycles/util/md5.h @@ -13,7 +13,6 @@ #pragma once #include "util/string.h" -#include "util/types.h" CCL_NAMESPACE_BEGIN @@ -22,7 +21,7 @@ class MD5Hash { MD5Hash(); ~MD5Hash(); - void append(const uint8_t *data, int size); + void append(const uint8_t *data, int nbytes); void append(const string &str); bool append_file(const string &filepath); string get_hex(); diff --git a/intern/cycles/util/murmurhash.cpp b/intern/cycles/util/murmurhash.cpp index d16651d8918..e64dd95140c 100644 --- a/intern/cycles/util/murmurhash.cpp +++ b/intern/cycles/util/murmurhash.cpp @@ -8,8 +8,8 @@ * domain. The author hereby disclaims copyright to this source code. */ -#include -#include +#include +#include #include "util/math.h" #include "util/murmurhash.h" @@ -88,6 +88,9 @@ uint32_t util_murmur_hash3(const void *key, int len, uint32_t seed) k1 = ROTL32(k1, 15); k1 *= c2; h1 ^= k1; + ATTR_FALLTHROUGH; + default: + break; } h1 ^= len; diff --git a/intern/cycles/util/murmurhash.h b/intern/cycles/util/murmurhash.h index 6581ee9b966..1d85b4f1180 100644 --- a/intern/cycles/util/murmurhash.h +++ b/intern/cycles/util/murmurhash.h @@ -4,7 +4,7 @@ #pragma once -#include "util/types.h" +#include CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/openimagedenoise.h b/intern/cycles/util/openimagedenoise.h index 65413baff00..c69d28b8ca3 100644 --- a/intern/cycles/util/openimagedenoise.h +++ b/intern/cycles/util/openimagedenoise.h @@ -5,10 +5,10 @@ #pragma once #ifdef WITH_OPENIMAGEDENOISE -# include +# include // IWYU pragma: export #endif -#include "util/system.h" +#include "util/system.h" // IWYU pragma: keep CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/openvdb.h b/intern/cycles/util/openvdb.h index e462c2fb510..a13833cdc68 100644 --- a/intern/cycles/util/openvdb.h +++ b/intern/cycles/util/openvdb.h @@ -19,33 +19,31 @@ bool grid_type_operation(const openvdb::GridBase::ConstPtr &grid, OpType &&op) if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else if (grid->isType()) { + if (grid->isType()) { return op.template operator()(grid); } - else { - return false; - } + return false; } }; // namespace openvdb diff --git a/intern/cycles/util/path.cpp b/intern/cycles/util/path.cpp index c45f7098dc3..e392fc9309f 100644 --- a/intern/cycles/util/path.cpp +++ b/intern/cycles/util/path.cpp @@ -36,7 +36,9 @@ # include #endif -#include "util/windows.h" +#ifdef _WIN32 +# include "util/windows.h" +#endif CCL_NAMESPACE_BEGIN @@ -55,9 +57,9 @@ typedef struct _stat path_stat_t; typedef struct stat path_stat_t; #endif -static string cached_path = ""; -static string cached_user_path = ""; -static string cached_xdg_cache_path = ""; +static string cached_path; +static string cached_user_path; +static string cached_xdg_cache_path; namespace { @@ -162,7 +164,7 @@ class directory_iterator { public: class path_info { public: - explicit path_info(const string &path) : path_(path), entry_(nullptr) {} + explicit path_info(const string &path) : path_(path) {} string path() { @@ -176,7 +178,7 @@ class directory_iterator { protected: const string &path_; - const struct dirent *entry_; + const struct dirent *entry_ = nullptr; }; directory_iterator() : path_info_(""), name_list_(nullptr), num_entries_(-1), cur_entry_(-1) {} @@ -254,7 +256,7 @@ class directory_iterator { for (int i = 0; i < num_entries_; ++i) { free(name_list_[i]); } - free(name_list_); + free((void *)name_list_); name_list_ = nullptr; } @@ -298,7 +300,7 @@ static char *path_specials(const string &sub) if (env_shader_path != nullptr && sub == "shader") { return env_shader_path; } - else if (env_source_path != nullptr && sub == "source") { + if (env_source_path != nullptr && sub == "source") { return env_source_path; } return nullptr; @@ -311,13 +313,11 @@ static string path_xdg_cache_get() if (home) { return string(home); } - else { - home = getenv("HOME"); - if (home == nullptr) { - home = getpwuid(getuid())->pw_dir; - } - return path_join(string(home), ".cache"); + home = getenv("HOME"); + if (home == nullptr) { + home = getpwuid(getuid())->pw_dir; } + return path_join(string(home), ".cache"); } #endif @@ -360,7 +360,7 @@ string path_user_get(const string &sub) string path_cache_get(const string &sub) { #if defined(__linux__) || defined(__APPLE__) - if (cached_xdg_cache_path == "") { + if (cached_xdg_cache_path.empty()) { cached_xdg_cache_path = path_xdg_cache_get(); } string result = path_join(cached_xdg_cache_path, "cycles"); @@ -414,10 +414,10 @@ string path_dirname(const string &path) string path_join(const string &dir, const string &file) { - if (dir.size() == 0) { + if (dir.empty()) { return file; } - if (file.size() == 0) { + if (file.empty()) { return dir; } string result = dir; @@ -454,8 +454,8 @@ bool path_is_relative(const string &path) return true; # endif /* HAVE_SHLWAPI_H */ #else /* _WIN32 */ - if (path.size() == 0) { - return 1; + if (path.empty()) { + return true; } return path[0] != DIR_SEP; #endif /* _WIN32 */ @@ -573,7 +573,7 @@ bool path_exists(const string &path) #else /* _WIN32 */ struct stat st; if (stat(path.c_str(), &st) != 0) { - return 0; + return false; } return st.st_mode != 0; #endif /* _WIN32 */ @@ -629,7 +629,7 @@ static bool create_directories_recursivey(const string &path) } string parent = path_dirname(path); - if (parent.size() > 0 && parent != path) { + if (!parent.empty() && parent != path) { if (!create_directories_recursivey(parent)) { return false; } @@ -660,8 +660,8 @@ bool path_write_binary(const string &path, const vector &binary) return false; } - if (binary.size() > 0) { - fwrite(&binary[0], sizeof(uint8_t), binary.size(), f); + if (!binary.empty()) { + fwrite(binary.data(), sizeof(uint8_t), binary.size(), f); } fclose(f); @@ -689,12 +689,12 @@ bool path_read_binary(const string &path, vector &binary) binary.resize(path_file_size(path)); - if (binary.size() == 0) { + if (binary.empty()) { fclose(f); return false; } - if (fread(&binary[0], sizeof(uint8_t), binary.size(), f) != binary.size()) { + if (fread(binary.data(), sizeof(uint8_t), binary.size(), f) != binary.size()) { fclose(f); return false; } @@ -742,7 +742,7 @@ bool path_read_text(const string &path, string &text) return false; } - const char *str = (const char *)&binary[0]; + const char *str = (const char *)binary.data(); size_t size = binary.size(); text = string(str, size); @@ -757,7 +757,7 @@ bool path_read_compressed_text(const string &path, string &text) return false; } - const char *str = (const char *)&binary[0]; + const char *str = (const char *)binary.data(); size_t size = binary.size(); text = string(str, size); @@ -779,7 +779,7 @@ bool path_remove(const string &path) } struct SourceReplaceState { - typedef map ProcessedMapping; + using ProcessedMapping = map; /* Base director for all relative include headers. */ string base; /* Result of processed files. */ @@ -798,7 +798,7 @@ static string line_directive(const SourceReplaceState &state, { string unescaped_path = path; /* First we make path relative. */ - if (string_startswith(unescaped_path, state.base.c_str())) { + if (string_startswith(unescaped_path, state.base)) { const string base_file = path_filename(state.base); const size_t base_len = state.base.length(); unescaped_path = base_file + @@ -806,7 +806,7 @@ static string line_directive(const SourceReplaceState &state, } /* Second, we replace all unsafe characters. */ const size_t length = unescaped_path.length(); - string escaped_path = ""; + string escaped_path; for (size_t i = 0; i < length; ++i) { const char ch = unescaped_path[i]; if (strchr("\"\'\?\\", ch) != nullptr) { @@ -887,7 +887,7 @@ static string path_source_replace_includes_recursive(const string &_source, const string &source = *psource; /* Perform full file processing. */ - string result = ""; + string result; const size_t source_length = source.length(); size_t index = 0; /* Information about where we are in the source. */ @@ -904,7 +904,7 @@ static string path_source_replace_includes_recursive(const string &_source, * gives measurable speedup. */ bool inside_preprocessor = false; - string preprocessor_line = ""; + string preprocessor_line; /* Actual loop over the whole source. */ while (index < source_length) { char ch = source[index]; @@ -993,9 +993,7 @@ bool path_cache_kernel_exists_and_mark_used(const string &path) path_cache_kernel_mark_used(path); return true; } - else { - return false; - } + return false; } void path_cache_kernel_mark_added_and_clear_old(const string &new_path, diff --git a/intern/cycles/util/path.h b/intern/cycles/util/path.h index af142311483..2cb4e0b968a 100644 --- a/intern/cycles/util/path.h +++ b/intern/cycles/util/path.h @@ -9,10 +9,9 @@ * linked libraries, the path to the library may be set with path_init, which * then makes all paths relative to that. */ -#include +#include #include "util/string.h" -#include "util/types.h" #include "util/vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/profiling.cpp b/intern/cycles/util/profiling.cpp index 62de81249b9..7426a622365 100644 --- a/intern/cycles/util/profiling.cpp +++ b/intern/cycles/util/profiling.cpp @@ -2,10 +2,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "util/profiling.h" -#include "util/algorithm.h" +#include +#include + #include "util/foreach.h" -#include "util/set.h" +#include "util/profiling.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/profiling.h b/intern/cycles/util/profiling.h index 715a32ba380..4758d61a92c 100644 --- a/intern/cycles/util/profiling.h +++ b/intern/cycles/util/profiling.h @@ -4,9 +4,8 @@ #pragma once -#include +#include -#include "util/map.h" #include "util/thread.h" #include "util/vector.h" @@ -124,7 +123,7 @@ class ProfilingHelper { state->event = previous_event; } - inline void set_event(ProfilingEvent event) + void set_event(ProfilingEvent event) { state->event = event; } @@ -147,7 +146,7 @@ class ProfilingWithShaderHelper : public ProfilingHelper { state->shader = -1; } - inline void set_shader(int object, int shader) + void set_shader(int object, int shader) { if (state->active) { state->shader = shader; diff --git a/intern/cycles/util/progress.h b/intern/cycles/util/progress.h index 46c033aea6e..6368efb40da 100644 --- a/intern/cycles/util/progress.h +++ b/intern/cycles/util/progress.h @@ -22,25 +22,9 @@ class Progress { public: Progress() { - pixel_samples = 0; - total_pixel_samples = 0; - current_tile_sample = 0; - rendered_tiles = 0; - denoised_tiles = 0; start_time = time_dt(); render_start_time = time_dt(); - time_limit = 0.0; - end_time = 0.0; status = "Initializing"; - substatus = ""; - sync_status = ""; - sync_substatus = ""; - update_cb = nullptr; - cancel = false; - cancel_message = ""; - error = false; - error_message = ""; - cancel_cb = nullptr; } Progress(Progress &progress) @@ -92,8 +76,9 @@ class Progress { bool get_cancel() const { - if (!cancel && cancel_cb) + if (!cancel && cancel_cb) { cancel_cb(); + } return cancel; } @@ -205,9 +190,9 @@ class Progress { double progress_percent = (double)pixel_samples / (double)total_pixel_samples; if (time_limit != 0.0) { double time_since_render_start = time_dt() - render_start_time; - progress_percent = max(progress_percent, time_since_render_start / time_limit); + progress_percent = fmax(progress_percent, time_since_render_start / time_limit); } - return min(1.0, progress_percent); + return fmin(1.0, progress_percent); } return 0.0; } @@ -306,7 +291,7 @@ class Progress { { thread_scoped_lock lock(progress_mutex); - if (sync_status != "") { + if (!sync_status.empty()) { status_ = sync_status; substatus_ = sync_substatus; } @@ -341,18 +326,18 @@ class Progress { * This makes the progress estimate more accurate when tiles with different sizes are used. * * total_pixel_samples is the total amount of pixel samples that will be rendered. */ - uint64_t pixel_samples, total_pixel_samples; + uint64_t pixel_samples = 0, total_pixel_samples = 0; /* Stores the current sample count of the last tile that called the update function. * It's used to display the sample count if only one tile is active. */ - int current_tile_sample; + int current_tile_sample = 0; /* Stores the number of tiles that's already finished. * Used to determine whether all but the last tile are finished rendering, * in which case the current_tile_sample is displayed. */ - int rendered_tiles, denoised_tiles; + int rendered_tiles = 0, denoised_tiles = 0; - double start_time, render_start_time, time_limit; + double start_time = 0.0, render_start_time = 0.0, time_limit = 0.0; /* End time written when render is done, so it doesn't keep increasing on redraws. */ - double end_time; + double end_time = 0.0; string status; string substatus; @@ -360,10 +345,10 @@ class Progress { string sync_status; string sync_substatus; - volatile bool cancel; + volatile bool cancel = false; string cancel_message; - volatile bool error; + volatile bool error = false; string error_message; }; diff --git a/intern/cycles/util/projection.h b/intern/cycles/util/projection.h index ba61646170b..67f18481662 100644 --- a/intern/cycles/util/projection.h +++ b/intern/cycles/util/projection.h @@ -63,23 +63,23 @@ ccl_device_inline float3 disk_to_hemisphere(const float2 p) /* 4x4 projection matrix, perspective or orthographic. */ -typedef struct ProjectionTransform { +struct ProjectionTransform { float4 x, y, z, w; /* rows */ #ifndef __KERNEL_GPU__ - ProjectionTransform() {} + ProjectionTransform() = default; explicit ProjectionTransform(const Transform &tfm) : x(tfm.x), y(tfm.y), z(tfm.z), w(make_float4(0.0f, 0.0f, 0.0f, 1.0f)) { } #endif -} ProjectionTransform; +}; -typedef struct PerspectiveMotionTransform { +struct PerspectiveMotionTransform { ProjectionTransform pre; ProjectionTransform post; -} PerspectiveMotionTransform; +}; CCL_NAMESPACE_END diff --git a/intern/cycles/util/projection_inverse.h b/intern/cycles/util/projection_inverse.h index e588d98b206..ccd974ffdca 100644 --- a/intern/cycles/util/projection_inverse.h +++ b/intern/cycles/util/projection_inverse.h @@ -68,9 +68,9 @@ ccl_device_forceinline bool projection_inverse_impl(ccl_private float R[4][4], /* backward substitution */ for (int i = 3; i >= 0; --i) { - float f; + float f = M[i][i]; - if (UNLIKELY((f = M[i][i]) == 0.0f)) { + if (UNLIKELY(f == 0.0f)) { return false; } diff --git a/intern/cycles/util/simd.h b/intern/cycles/util/simd.h index 47a05bd7f28..51b5ee92a49 100644 --- a/intern/cycles/util/simd.h +++ b/intern/cycles/util/simd.h @@ -5,8 +5,8 @@ #pragma once +#include #include -#include #include "util/defines.h" diff --git a/intern/cycles/util/stack_allocator.h b/intern/cycles/util/stack_allocator.h index ad12aebb4ab..087cafa7b40 100644 --- a/intern/cycles/util/stack_allocator.h +++ b/intern/cycles/util/stack_allocator.h @@ -5,7 +5,9 @@ #pragma once #include -#include + +#include "util/defines.h" +#include "util/guarded_allocator.h" CCL_NAMESPACE_BEGIN @@ -13,28 +15,28 @@ CCL_NAMESPACE_BEGIN template class ccl_try_align(16) StackAllocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef T *pointer; - typedef const T *const_pointer; - typedef T &reference; - typedef const T &const_reference; - typedef T value_type; + using size_type = size_t; + using difference_type = ptrdiff_t; + using pointer = T *; + using const_pointer = const T *; + using reference = T &; + using const_reference = const T &; + using value_type = T; /* Allocator construction/destruction. */ StackAllocator() : pointer_(0), use_stack_(true) {} - StackAllocator(const StackAllocator &) : pointer_(0), use_stack_(true) {} + StackAllocator(const StackAllocator & /*unused*/) : pointer_(0), use_stack_(true) {} template - StackAllocator(const StackAllocator &) : pointer_(0), use_stack_(false) + StackAllocator(const StackAllocator & /*unused*/) : pointer_(0), use_stack_(false) { } /* Memory allocation/deallocation. */ - T *allocate(size_t n, const void *hint = 0) + T *allocate(size_t n, const void *hint = nullptr) { (void)hint; if (n == 0) { @@ -93,7 +95,7 @@ template class ccl_try_align(16) StackAllocator void construct(T * p, const T &val) { if (p != nullptr) { - new ((T *)p) T(val); + new (p) T(val); } } @@ -112,27 +114,27 @@ template class ccl_try_align(16) StackAllocator /* Rebind to other type of allocator. */ template struct rebind { - typedef StackAllocator other; + using other = StackAllocator; }; /* Operators */ - template inline StackAllocator &operator=(const StackAllocator &) + template StackAllocator &operator=(const StackAllocator & /*unused*/) { return *this; } - StackAllocator &operator=(const StackAllocator &) + StackAllocator &operator=(const StackAllocator & /*unused*/) { return *this; } - inline bool operator==(StackAllocator const & /*other*/) const + bool operator==(StackAllocator const & /*other*/) const { return true; } - inline bool operator!=(StackAllocator const &other) const + bool operator!=(StackAllocator const &other) const { return !operator==(other); } diff --git a/intern/cycles/util/stats.h b/intern/cycles/util/stats.h index 76efb4dd46f..23e01acd688 100644 --- a/intern/cycles/util/stats.h +++ b/intern/cycles/util/stats.h @@ -5,7 +5,6 @@ #pragma once #include "util/atomic.h" -#include "util/profiling.h" CCL_NAMESPACE_BEGIN @@ -14,7 +13,7 @@ class Stats { enum static_init_t { static_init = 0 }; Stats() : mem_used(0), mem_peak(0) {} - explicit Stats(static_init_t) {} + explicit Stats(static_init_t /*unused*/) {} void mem_alloc(size_t size) { diff --git a/intern/cycles/util/string.cpp b/intern/cycles/util/string.cpp index b0842c372b3..ca37913a92c 100644 --- a/intern/cycles/util/string.cpp +++ b/intern/cycles/util/string.cpp @@ -2,17 +2,18 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include #include #include #include "util/foreach.h" #include "util/string.h" -#include "util/windows.h" +#include "util/types_float4.h" #ifdef _WIN32 +# include "util/windows.h" # ifndef vsnprintf # define vsnprintf _vsnprintf # endif @@ -24,12 +25,12 @@ string string_printf(const char *format, ...) { vector str(128, 0); - while (1) { + while (true) { va_list args; int result; va_start(args, format); - result = vsnprintf(&str[0], str.size(), format, args); + result = vsnprintf(str.data(), str.size(), format, args); va_end(args); if (result == -1) { @@ -42,13 +43,13 @@ string string_printf(const char *format, ...) str.resize(str.size() * 2, 0); continue; } - else if (result >= (int)str.size()) { + if (result >= (int)str.size()) { /* not enough space */ str.resize(result + 1, 0); continue; } - return string(&str[0]); + return string(str.data()); } } @@ -172,9 +173,7 @@ string string_from_bool(bool var) if (var) { return "True"; } - else { - return "False"; - } + return "False"; } string to_string(const char *str) @@ -250,9 +249,7 @@ string string_human_readable_size(size_t size) if (*suffix != 'B') { return string_printf("%.2f%c", double(size * 1024 + r) / 1024.0, *suffix); } - else { - return string_printf("%zu", size); - } + return string_printf("%zu", size); } string string_human_readable_number(size_t num) @@ -269,7 +266,8 @@ string string_human_readable_number(size_t num) int i = -1; while (num) { - if (++i && i % 3 == 0) { + i++; + if (i && i % 3 == 0) { *(--p) = ','; } diff --git a/intern/cycles/util/string.h b/intern/cycles/util/string.h index cedbceaeba7..441505f1b68 100644 --- a/intern/cycles/util/string.h +++ b/intern/cycles/util/string.h @@ -4,7 +4,7 @@ #pragma once -#include +#include #include /* Use string view implementation from OIIO. @@ -16,6 +16,8 @@ CCL_NAMESPACE_BEGIN +struct float4; + using std::string; using std::to_string; diff --git a/intern/cycles/util/system.h b/intern/cycles/util/system.h index 49f20c2f482..45c453127ff 100644 --- a/intern/cycles/util/system.h +++ b/intern/cycles/util/system.h @@ -4,8 +4,8 @@ #pragma once -#include -#include +#include +#include #include diff --git a/intern/cycles/util/task.cpp b/intern/cycles/util/task.cpp index 7d836c8913d..4064dc71b4a 100644 --- a/intern/cycles/util/task.cpp +++ b/intern/cycles/util/task.cpp @@ -5,7 +5,6 @@ #include "util/task.h" #include "util/foreach.h" #include "util/log.h" -#include "util/system.h" #include "util/time.h" CCL_NAMESPACE_BEGIN @@ -123,17 +122,17 @@ DedicatedTaskPool::~DedicatedTaskPool() delete worker_thread; } -void DedicatedTaskPool::push(TaskRunFunction &&task, bool front) +void DedicatedTaskPool::push(TaskRunFunction &&run, bool front) { num_increase(); /* add task to queue */ queue_mutex.lock(); if (front) { - queue.emplace_front(std::move(task)); + queue.emplace_front(std::move(run)); } else { - queue.emplace_back(std::move(task)); + queue.emplace_back(std::move(run)); } queue_cond.notify_one(); @@ -234,7 +233,7 @@ void DedicatedTaskPool::clear() string TaskPool::Summary::full_report() const { - string report = ""; + string report; report += string_printf("Total time: %f\n", time_total); report += string_printf("Tasks handled: %d\n", num_tasks_handled); return report; diff --git a/intern/cycles/util/task.h b/intern/cycles/util/task.h index feeab803d2f..f907604bfe2 100644 --- a/intern/cycles/util/task.h +++ b/intern/cycles/util/task.h @@ -8,7 +8,6 @@ #include "util/string.h" #include "util/tbb.h" #include "util/thread.h" -#include "util/vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/tbb.h b/intern/cycles/util/tbb.h index 0065844aeeb..f220b0a25a2 100644 --- a/intern/cycles/util/tbb.h +++ b/intern/cycles/util/tbb.h @@ -6,7 +6,9 @@ /* TBB includes , do it ourselves first so we are sure * WIN32_LEAN_AND_MEAN and similar are defined beforehand. */ -#include "util/windows.h" +#ifdef _WIN32 +# include "util/windows.h" +#endif #include #include diff --git a/intern/cycles/util/texture.h b/intern/cycles/util/texture.h index f8260c84abc..6c0ce05b9e4 100644 --- a/intern/cycles/util/texture.h +++ b/intern/cycles/util/texture.h @@ -9,14 +9,16 @@ CCL_NAMESPACE_BEGIN /* Color to use when textures are not found. */ -#define TEX_IMAGE_MISSING_R 1 -#define TEX_IMAGE_MISSING_G 0 -#define TEX_IMAGE_MISSING_B 1 -#define TEX_IMAGE_MISSING_A 1 +enum { + TEX_IMAGE_MISSING_R = 1, + TEX_IMAGE_MISSING_G = 0, + TEX_IMAGE_MISSING_B = 1, + TEX_IMAGE_MISSING_A = 1 +}; /* Interpolation types for textures * CUDA also use texture space to store other objects. */ -typedef enum InterpolationType { +enum InterpolationType { INTERPOLATION_NONE = -1, INTERPOLATION_LINEAR = 0, INTERPOLATION_CLOSEST = 1, @@ -24,9 +26,9 @@ typedef enum InterpolationType { INTERPOLATION_SMART = 3, INTERPOLATION_NUM_TYPES, -} InterpolationType; +}; -typedef enum ImageDataType { +enum ImageDataType { IMAGE_DATA_TYPE_FLOAT4 = 0, IMAGE_DATA_TYPE_BYTE4 = 1, IMAGE_DATA_TYPE_HALF4 = 2, @@ -41,11 +43,11 @@ typedef enum ImageDataType { IMAGE_DATA_TYPE_NANOVDB_FP16 = 11, IMAGE_DATA_NUM_TYPES -} ImageDataType; +}; /* Alpha types * How to treat alpha in images. */ -typedef enum ImageAlphaType { +enum ImageAlphaType { IMAGE_ALPHA_UNASSOCIATED = 0, IMAGE_ALPHA_ASSOCIATED = 1, IMAGE_ALPHA_CHANNEL_PACKED = 2, @@ -53,12 +55,12 @@ typedef enum ImageAlphaType { IMAGE_ALPHA_AUTO = 4, IMAGE_ALPHA_NUM_TYPES, -} ImageAlphaType; +}; /* Extension types for textures. * * Defines how the image is extrapolated past its original bounds. */ -typedef enum ExtensionType { +enum ExtensionType { /* Cause the image to repeat horizontally and vertically. */ EXTENSION_REPEAT = 0, /* Extend by repeating edge pixels of the image. */ @@ -69,9 +71,9 @@ typedef enum ExtensionType { EXTENSION_MIRROR = 3, EXTENSION_NUM_TYPES, -} ExtensionType; +}; -typedef struct TextureInfo { +struct TextureInfo { /* Pointer, offset or texture depending on device. */ uint64_t data; /* Data Type */ @@ -83,6 +85,6 @@ typedef struct TextureInfo { /* Transform for 3D textures. */ uint use_transform_3d; Transform transform_3d; -} TextureInfo; +}; CCL_NAMESPACE_END diff --git a/intern/cycles/util/thread.cpp b/intern/cycles/util/thread.cpp index aa6b5fa5c6f..e01c40298dc 100644 --- a/intern/cycles/util/thread.cpp +++ b/intern/cycles/util/thread.cpp @@ -4,10 +4,15 @@ #include "util/thread.h" -#include "util/system.h" -#include "util/windows.h" +#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__) +#else +# include "util/system.h" +# ifdef _WIN32 +# include "util/windows.h" +# endif -#include +# include +#endif CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/thread.h b/intern/cycles/util/thread.h index f258a3793a7..be44bed354a 100644 --- a/intern/cycles/util/thread.h +++ b/intern/cycles/util/thread.h @@ -7,13 +7,15 @@ #include #include #include -#include -#include + +#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__) +# include +#else +# include +#endif #ifdef _WIN32 # include "util/windows.h" -#else -# include #endif /* NOTE: Use tbb/spin_mutex.h instead of util_tbb.h because some of the TBB @@ -22,9 +24,9 @@ CCL_NAMESPACE_BEGIN -typedef std::mutex thread_mutex; -typedef std::unique_lock thread_scoped_lock; -typedef std::condition_variable thread_condition_variable; +using thread_mutex = std::mutex; +using thread_scoped_lock = std::unique_lock; +using thread_condition_variable = std::condition_variable; /** * Own thread implementation similar to std::thread, so we can set a diff --git a/intern/cycles/util/time.cpp b/intern/cycles/util/time.cpp index 6c34bd0833c..042a13a7eb1 100644 --- a/intern/cycles/util/time.cpp +++ b/intern/cycles/util/time.cpp @@ -4,16 +4,18 @@ #include "util/time.h" -#include +#include #if !defined(_WIN32) # include # include #endif -#include "util/math.h" #include "util/string.h" -#include "util/windows.h" + +#ifdef _WIN32 +# include "util/windows.h" +#endif CCL_NAMESPACE_BEGIN @@ -74,9 +76,7 @@ string time_human_readable_from_seconds(const double seconds) if (h > 0) { return string_printf("%.2d:%.2d:%.2d.%.2d", h, m, s, r); } - else { - return string_printf("%.2d:%.2d.%.2d", m, s, r); - } + return string_printf("%.2d:%.2d.%.2d", m, s, r); } double time_human_readable_to_seconds(const string &time_string) @@ -98,7 +98,7 @@ double time_human_readable_to_seconds(const string &time_string) /* Time string is malformed. */ return 0.0; } - else if (fraction_tokens.size() == 1) { + if (fraction_tokens.size() == 1) { /* There is no fraction of a second specified, the rest of the code * handles this normally. */ } diff --git a/intern/cycles/util/time.h b/intern/cycles/util/time.h index b616a719c49..c9cfe2b843a 100644 --- a/intern/cycles/util/time.h +++ b/intern/cycles/util/time.h @@ -70,6 +70,6 @@ class scoped_callback_timer { /* Make human readable string from time, compatible with Blender metadata. */ string time_human_readable_from_seconds(const double seconds); -double time_human_readable_to_seconds(const string &str); +double time_human_readable_to_seconds(const string &time_string); CCL_NAMESPACE_END diff --git a/intern/cycles/util/transform.h b/intern/cycles/util/transform.h index ed617b98892..c0839c40fee 100644 --- a/intern/cycles/util/transform.h +++ b/intern/cycles/util/transform.h @@ -5,7 +5,7 @@ #pragma once #ifndef __KERNEL_GPU__ -# include +# include #endif #include "util/math.h" @@ -19,7 +19,7 @@ CCL_NAMESPACE_BEGIN /* Affine transformation, stored as 4x3 matrix. */ -typedef struct Transform { +struct Transform { float4 x, y, z; #ifndef __KERNEL_GPU__ @@ -32,15 +32,15 @@ typedef struct Transform { return *(&x + i); } #endif -} Transform; +}; /* Transform decomposed in rotation/translation/scale. we use the same data * structure as Transform, and tightly pack decomposition into it. first the * rotation (4), then translation (3), then 3x3 scale matrix (9). */ -typedef struct DecomposedTransform { +struct DecomposedTransform { float4 x, y, z, w; -} DecomposedTransform; +}; CCL_NAMESPACE_END @@ -334,7 +334,7 @@ ccl_device_inline void transform_set_column(Transform *t, int column, float3 val t->z[column] = value.z; } -Transform transform_transposed_inverse(const Transform &a); +Transform transform_transposed_inverse(const Transform &tfm); ccl_device_inline bool transform_uniform_scale(const Transform &tfm, float &scale) { @@ -393,7 +393,7 @@ ccl_device_inline float4 quat_interpolate(float4 q1, float4 q2, float t) /* Optix and MetalRT are using linear interpolation to interpolate motion transformations. */ #if defined(__KERNEL_GPU_RAYTRACING__) return normalize((1.0f - t) * q1 + t * q2); -#else /* defined(__KERNEL_GPU_RAYTRACING__) */ +#else /* defined(__KERNEL_GPU_RAYTRACING__) */ /* NOTE: this does not ensure rotation around shortest angle, q1 and q2 * are assumed to be matched already in transform_motion_decompose */ float costheta = dot(q1, q2); @@ -404,13 +404,12 @@ ccl_device_inline float4 quat_interpolate(float4 q1, float4 q2, float t) /* linear interpolation in degenerate case */ return normalize((1.0f - t) * q1 + t * q2); } - else { - /* slerp */ - float theta = acosf(clamp(costheta, -1.0f, 1.0f)); - float4 qperp = normalize(q2 - q1 * costheta); - float thetap = theta * t; - return q1 * cosf(thetap) + qperp * sinf(thetap); - } + /* slerp */ + float theta = acosf(clamp(costheta, -1.0f, 1.0f)); + float4 qperp = normalize(q2 - q1 * costheta); + float thetap = theta * t; + return q1 * cosf(thetap) + qperp * sinf(thetap); + #endif /* defined(__KERNEL_GPU_RAYTRACING__) */ } @@ -428,7 +427,7 @@ ccl_device_inline Transform transform_inverse(const Transform tfm) transform_inverse_cpu_avx2(tfm, itfm); return itfm; } - else if (system_cpu_support_sse42()) { + if (system_cpu_support_sse42()) { Transform itfm; transform_inverse_cpu_sse42(tfm, itfm); return itfm; diff --git a/intern/cycles/util/transform_inverse.h b/intern/cycles/util/transform_inverse.h index b2d0e7e1307..ff781c94b76 100644 --- a/intern/cycles/util/transform_inverse.h +++ b/intern/cycles/util/transform_inverse.h @@ -4,6 +4,9 @@ #pragma once +#include "util/defines.h" +#include "util/transform.h" + CCL_NAMESPACE_BEGIN /* Custom cross and dot implementations that match Embree bit for bit. @@ -39,7 +42,7 @@ ccl_device_forceinline float transform_inverse_dot(const float3 a_, const float3 return dot(a_, b_); } -ccl_device_forceinline Transform transform_inverse_impl(const Transform tfm) +ccl_device_forceinline struct Transform transform_inverse_impl(const struct Transform tfm) { /* This implementation matches the one in Embree exactly, to ensure consistent * results with the ray intersection of instances. */ @@ -74,7 +77,7 @@ ccl_device_forceinline Transform transform_inverse_impl(const Transform tfm) const float3 inverse_z = transform_inverse_cross(x, y) / det; /* Compute translation and fill transform. */ - Transform itfm; + struct Transform itfm; itfm.x = make_float4(inverse_x, -transform_inverse_dot(inverse_x, w)); itfm.y = make_float4(inverse_y, -transform_inverse_dot(inverse_y, w)); itfm.z = make_float4(inverse_z, -transform_inverse_dot(inverse_z, w)); diff --git a/intern/cycles/util/types_base.h b/intern/cycles/util/types_base.h index ab466a873cd..4cc438dcf78 100644 --- a/intern/cycles/util/types_base.h +++ b/intern/cycles/util/types_base.h @@ -11,15 +11,15 @@ /* Standard Integer Types */ #if !defined(__KERNEL_GPU__) -# include +# include // IWYU pragma: export # include #endif #include "util/defines.h" #ifndef __KERNEL_GPU__ -# include "util/optimization.h" -# include "util/simd.h" +# include "util/optimization.h" // IWYU pragma: export +# include "util/simd.h" // IWYU pragma: export #endif CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/types_float3.h b/intern/cycles/util/types_float3.h index 78ad86b406d..fb91ab1a032 100644 --- a/intern/cycles/util/types_float3.h +++ b/intern/cycles/util/types_float3.h @@ -142,7 +142,7 @@ ccl_device_inline int4 make_int4(const float3 f) /* Metal has native packed_float3. */ #elif defined(__KERNEL_CUDA__) || defined(__KERNEL_HIP__) || defined(__KERNEL_ONEAPI__) /* CUDA, HIP and oneAPI float3 are already packed. */ -typedef float3 packed_float3; +using packed_float3 = float3; #else struct packed_float3 { ccl_device_inline_method packed_float3() = default; diff --git a/intern/cycles/util/types_uint3.h b/intern/cycles/util/types_uint3.h index 905ff8e9a93..0eec36d826b 100644 --- a/intern/cycles/util/types_uint3.h +++ b/intern/cycles/util/types_uint3.h @@ -38,7 +38,7 @@ ccl_device_inline uint3 make_uint3(uint x, uint y, uint z) /* Metal has native packed_float3. */ #elif defined(__KERNEL_CUDA__) || defined(__KERNEL_ONEAPI__) /* CUDA and oneAPI uint3 are already packed. */ -typedef uint3 packed_uint3; +using packed_uint3 = uint3; #else /* HIP uint3 is not packed (https://github.com/ROCm-Developer-Tools/HIP/issues/706). */ struct packed_uint3 { diff --git a/intern/cycles/util/types_ushort4.h b/intern/cycles/util/types_ushort4.h index 65c8e315766..4aa0dc66bbe 100644 --- a/intern/cycles/util/types_ushort4.h +++ b/intern/cycles/util/types_ushort4.h @@ -4,7 +4,7 @@ #pragma once -#include "util/defines.h" +#include "util/types_base.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/vector.h b/intern/cycles/util/vector.h index 57dd5ba2f30..69eabd0aef9 100644 --- a/intern/cycles/util/vector.h +++ b/intern/cycles/util/vector.h @@ -7,7 +7,6 @@ #include #include -#include "util/aligned_malloc.h" #include "util/guarded_allocator.h" CCL_NAMESPACE_BEGIN @@ -20,7 +19,7 @@ CCL_NAMESPACE_BEGIN template> class vector : public std::vector { public: - typedef std::vector BaseClass; + using BaseClass = std::vector; /* Inherit all constructors from base class. */ using BaseClass::vector; diff --git a/intern/cycles/util/version.h b/intern/cycles/util/version.h index 94b27067a4d..d178b3b4d08 100644 --- a/intern/cycles/util/version.h +++ b/intern/cycles/util/version.h @@ -8,9 +8,11 @@ CCL_NAMESPACE_BEGIN +// NOLINTBEGIN #define CYCLES_VERSION_MAJOR 4 #define CYCLES_VERSION_MINOR 2 #define CYCLES_VERSION_PATCH 0 +// NOLINTEND #define CYCLES_MAKE_VERSION_STRING2(a, b, c) #a "." #b "." #c #define CYCLES_MAKE_VERSION_STRING(a, b, c) CYCLES_MAKE_VERSION_STRING2(a, b, c) diff --git a/tests/gtests/testing/testing.h b/tests/gtests/testing/testing.h index 8142bebec03..2b87d77034c 100644 --- a/tests/gtests/testing/testing.h +++ b/tests/gtests/testing/testing.h @@ -6,9 +6,9 @@ #include -#include "gflags/gflags.h" -#include "glog/logging.h" -#include "gtest/gtest.h" +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export namespace blender::tests {