Cleanup: Cycles: Fix various compiler warnings

* Uninitialized variable warning in oneAPI.
* Use std::copy_n instead of memcpy.
* Use simpler bit packing for normal map convention that avoids
  signed/unsigned warning.
* Unnecessary device keyword for default constructor.
* Unused variables in Principled BSDF due to constexpr.
* Hydra function that should be static.

Pull Request: https://projects.blender.org/blender/blender/pulls/154430
This commit is contained in:
Brecht Van Lommel 2026-02-16 12:57:53 +01:00 • committed by Brecht Van Lommel
parent 09a0616213
commit ab0cb89d89
8 changed files with 53 additions and 20 deletions

View file

@ -689,7 +689,9 @@ static sycl::ext::oneapi::experimental::image_descriptor image_desc(const device
channel_type = sycl::image_channel_type::fp16;
break;
default:
channel_type = sycl::image_channel_type::unorm_int8;
assert(0);
break;
}
sycl::ext::oneapi::experimental::image_descriptor param;

View file

@ -17,6 +17,7 @@
# include "scene/pointcloud.h"
# include "scene/scene.h"
# include "util/algorithm.h"
# include "util/debug.h"
# include "util/log.h"
# include "util/path.h"
@ -1541,7 +1542,10 @@ void OptiXDevice::build_bvh(BVH *bvh, Progress &progress, bool refit)
verts = motion_keys->data_float3() + (step > center_step ? step - 1 : step) * num_verts;
}
memcpy(vertex_data.data() + num_verts * step, verts, num_verts * sizeof(float3));
/* Direct copy from Cycles padded float3, needs to match float4 size. */
static_assert(sizeof(float3) == sizeof(float4));
std::copy_n(
verts, num_verts, reinterpret_cast<float3 *>(vertex_data.data() + num_verts * step));
}
/* Upload triangle data to GPU. */

View file

@ -14,7 +14,7 @@
HDCYCLES_NAMESPACE_OPEN_SCOPE
extern Transform convert_transform(const GfMatrix4d &matrix);
Transform convert_camera_transform(const GfMatrix4d &matrix, const float metersPerUnit)
static Transform convert_camera_transform(const GfMatrix4d &matrix, const float metersPerUnit)
{
Transform t = convert_transform(matrix);
// Flip Z axis

View file

@ -74,7 +74,7 @@ ccl_device
}
}
else IF_KERNEL_NODES_FEATURE(EMISSION) {
if (type != CLOSURE_BSDF_PRINCIPLED_ID) {
if (mix_weight == 0.0f || type != CLOSURE_BSDF_PRINCIPLED_ID) {
/* Only principled BSDF can have emission. */
return svm_node_closure_bsdf_skip(kg, offset, type);
}
@ -125,7 +125,6 @@ ccl_device
uint anisotropic_rotation_offset;
uint tangent_offset;
uint thin_film_ior_offset;
ClosureType distribution;
const uint4 data_node2 = read_node(kg, &offset);
const uint4 data_node3 = read_node(kg, &offset);
@ -179,7 +178,7 @@ ccl_device
const float3 coat_normal = safe_normalize_fallback(
stack_load_float3_default(stack, coat_normal_offset, N), sd->N);
distribution = (ClosureType)distribution_uint;
const ClosureType distribution = (ClosureType)distribution_uint;
const float diffuse_roughness = saturatef(
stack_load_float_default(stack, diffuse_roughness_offset, 0.0f));
@ -209,10 +208,9 @@ ccl_device
const float transmission_weight = saturatef(
stack_load_float_default(stack, transmission_weight_offset, 0.0f));
float thinfilm_ior = 0.0f;
if (thinfilm_thickness > THINFILM_THICKNESS_CUTOFF) {
thinfilm_ior = fmaxf(stack_load_float(stack, thin_film_ior_offset), 1e-5f);
}
const float thinfilm_ior = (thinfilm_thickness > THINFILM_THICKNESS_CUTOFF) ?
fmaxf(stack_load_float(stack, thin_film_ior_offset), 1e-5f) :
0.0f;
/* We're ignoring closure_weight here since it's always 1 for the Principled BSDF, so there's
* no point in setting it. */
@ -510,6 +508,22 @@ ccl_device
}
}
}
else {
(void)distribution;
(void)clamped_base_color;
(void)ior;
(void)metallic;
(void)valid_reflection_N;
(void)diffuse_roughness;
(void)specular_ior_level;
(void)specular_tint;
(void)subsurface_weight;
(void)transmission_weight;
(void)thinfilm_ior;
(void)alpha_x;
(void)alpha_y;
(void)refractive_caustics;
}
break;
}

View file

@ -329,13 +329,15 @@ ccl_device_noinline void svm_node_normal_map(KernelGlobals kg,
uint color_offset;
uint strength_offset;
uint normal_offset;
uint space;
svm_unpack_node_uchar4(node.y, &color_offset, &strength_offset, &normal_offset, &space);
uint flags;
svm_unpack_node_uchar4(node.y, &color_offset, &strength_offset, &normal_offset, &flags);
const uint space = flags & NODE_NORMAL_MAP_FLAG_SPACE_MASK;
const bool invert_green = (flags & NODE_NORMAL_MAP_FLAG_DIRECTX) != 0;
float3 color = stack_load_float3(stack, color_offset);
color = 2.0f * make_float3(color.x - 0.5f, color.y - 0.5f, color.z - 0.5f);
const bool invert_green = (node.w & NODE_NORMAL_MAP_CONVENTION_DIRECTX) != 0;
if (invert_green) {
color.y = -color.y;
}
@ -355,8 +357,7 @@ ccl_device_noinline void svm_node_normal_map(KernelGlobals kg,
/* first try to get tangent attribute */
const AttributeDescriptor attr = find_attribute(kg, sd, node.z);
const AttributeDescriptor attr_sign = find_attribute(
kg, sd, node.w & ~NODE_NORMAL_MAP_CONVENTION_DIRECTX);
const AttributeDescriptor attr_sign = find_attribute(kg, sd, node.w);
if (attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND) {
/* Fall back to unperturbed normal. */

View file

@ -359,7 +359,13 @@ enum NodeNormalMapSpace {
enum NodeNormalMapConvention {
NODE_NORMAL_MAP_CONVENTION_OPENGL = 0,
NODE_NORMAL_MAP_CONVENTION_DIRECTX = (1U << 31),
NODE_NORMAL_MAP_CONVENTION_DIRECTX = 1,
};
/* Flags for SVM node encoding, packing space and convention into one byte. */
enum NodeNormalMapFlags {
NODE_NORMAL_MAP_FLAG_SPACE_MASK = 0x7,
NODE_NORMAL_MAP_FLAG_DIRECTX = (1 << 3),
};
enum NodeImageProjection {

View file

@ -7596,8 +7596,8 @@ NODE_DEFINE(NormalMapNode)
SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT);
static NodeEnum convention_enum;
convention_enum.insert("opengl", 0);
convention_enum.insert("directx", 1);
convention_enum.insert("opengl", NODE_NORMAL_MAP_CONVENTION_OPENGL);
convention_enum.insert("directx", NODE_NORMAL_MAP_CONVENTION_DIRECTX);
SOCKET_ENUM(convention, "Convention", convention_enum, NODE_NORMAL_MAP_CONVENTION_OPENGL);
SOCKET_STRING(attribute, "Attribute", ustring());
@ -7654,13 +7654,19 @@ void NormalMapNode::compile(SVMCompiler &compiler)
}
}
/* Pack space and convention into byte. */
int flags = space;
if (convention == NODE_NORMAL_MAP_CONVENTION_DIRECTX) {
flags |= NODE_NORMAL_MAP_FLAG_DIRECTX;
}
compiler.add_node(NODE_NORMAL_MAP,
compiler.encode_uchar4(compiler.stack_assign(color_in),
compiler.stack_assign(strength_in),
compiler.stack_assign(normal_out),
space),
flags),
attr,
attr_sign | (convention == 1 ? NODE_NORMAL_MAP_CONVENTION_DIRECTX : 0));
attr_sign);
}
void NormalMapNode::compile(OSLCompiler &compiler)

View file

@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN
struct packed_normal {
uint value;
ccl_device_inline_method packed_normal() = default;
packed_normal() = default;
ccl_device_inline_method packed_normal(const float3 in)
{