Skip to content

Commit d124e5b

Browse files
authored
Remove redundant wp.static wrappers and fix a uint32 overflow (#3657)
1 parent bd44951 commit d124e5b

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
- Report malformed MJCF free-joint and inertial inputs with deterministic validation errors, and ignore MJCF mesh geom `size` lengths consistently.
105105
- Fix MJCF imports ignoring material and inline RGBA colors on primitive geoms.
106106
- Fix Style3D solver divergence caused by isolated vertices.
107-
- Fix compiler warnings about overflowing int32 constants when compiling SDF texture and `SensorTiledCamera` render kernels.
107+
- Fix compiler warnings about overflowing int32 constants when compiling SDF texture and `SensorTiledCamera` kernels.
108108
- Fix USD site import to discover sites beneath non-visual containers, collider prims, and instanceable rigid-body prims independently of `load_visual_shapes`; the reworked traversal also speeds up import of scenes with many nested `Xform` or instance prims.
109109
- Fix `SolverFeatherstone` BALL joints to apply passive `joint_damping` on all three angular DOFs.
110110
- Fix excessive memory usage when importing MJCF or URDF models containing many visual-only shapes with self-collisions disabled.

newton/_src/geometry/sdf_hydroelastic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def mc_calc_face_texture(
171171
p_0 = wp.vec3f(corner_offsets_table[v_idx_from])
172172
p_1 = wp.vec3f(corner_offsets_table[v_idx_to])
173173
val_diff = wp.float32(val_1 - val_0)
174-
if wp.abs(val_diff) < wp.static(MC_EDGE_VAL_DIFF_EPS):
174+
if wp.abs(val_diff) < MC_EDGE_VAL_DIFF_EPS:
175175
t = float(0.5)
176176
else:
177177
# Clamp t away from cube corners to prevent vertex collapse when
@@ -194,7 +194,7 @@ def mc_calc_face_texture(
194194

195195
n = wp.cross(face_verts[1] - face_verts[0], face_verts[2] - face_verts[0])
196196
n_sq = wp.dot(n, n)
197-
if n_sq < wp.static(MC_DEGENERATE_N_SQ_EPS):
197+
if n_sq < MC_DEGENERATE_N_SQ_EPS:
198198
# Degenerate triangle — return zero area with a valid (non-NaN) normal.
199199
area = 0.0
200200
normal = wp.vec3(0.0, 0.0, 1.0)

newton/_src/geometry/sdf_mc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ def mc_calc_face(
195195
p_0 = wp.vec3f(corner_offsets_table[v_idx_from])
196196
p_1 = wp.vec3f(corner_offsets_table[v_idx_to])
197197
val_diff = wp.float32(val_1 - val_0)
198-
if wp.abs(val_diff) < wp.static(MC_EDGE_VAL_DIFF_EPS):
198+
if wp.abs(val_diff) < MC_EDGE_VAL_DIFF_EPS:
199199
p = 0.5 * (p_0 + p_1)
200200
else:
201201
# Clamp t away from cube corners to prevent vertex collapse when
202202
# corner values are near zero (e.g. at SDF ridge boundaries).
203203
# Without the clamp, t close to 0 or 1 places multiple vertices
204204
# at the same corner, producing degenerate (zero-area) triangles.
205-
t = wp.clamp((isovalue - val_0) / val_diff, wp.static(MC_EDGE_CLAMP_MIN), wp.static(MC_EDGE_CLAMP_MAX))
205+
t = wp.clamp((isovalue - val_0) / val_diff, MC_EDGE_CLAMP_MIN, MC_EDGE_CLAMP_MAX)
206206
p = p_0 + t * (p_1 - p_0)
207207
vol_idx = p + int_to_vec3f(x_id, y_id, z_id)
208208
p_scaled = wp.volume_index_to_world(sdf_a, vol_idx)
@@ -216,7 +216,7 @@ def mc_calc_face(
216216

217217
n = wp.cross(face_verts[1] - face_verts[0], face_verts[2] - face_verts[0])
218218
n_sq = wp.dot(n, n)
219-
if n_sq < wp.static(MC_DEGENERATE_N_SQ_EPS):
219+
if n_sq < MC_DEGENERATE_N_SQ_EPS:
220220
# Degenerate triangle — return zero area with a valid (non-NaN) normal.
221221
area = 0.0
222222
normal = wp.vec3(0.0, 0.0, 1.0)

newton/_src/geometry/sdf_texture.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ def _read_cell_corners(
856856
ty = loc.ty
857857
tz = loc.tz
858858

859-
if loc.start_slot >= wp.static(SLOT_LINEAR):
859+
if loc.start_slot >= SLOT_LINEAR:
860860
cx = float(loc.x_base)
861861
cy = float(loc.y_base)
862862
cz = float(loc.z_base)
@@ -951,7 +951,7 @@ def texture_sample_sdf_at_voxel(
951951

952952
start_slot = sdf.subgrid_start_slots[x_base, y_base, z_base]
953953

954-
if start_slot < wp.static(SLOT_LINEAR):
954+
if start_slot < SLOT_LINEAR:
955955
block_x = float(start_slot & wp.uint32(0x3FF))
956956
block_y = float((start_slot >> wp.uint32(10)) & wp.uint32(0x3FF))
957957
block_z = float((start_slot >> wp.uint32(20)) & wp.uint32(0x3FF))
@@ -1023,7 +1023,7 @@ def texture_sample_sdf(
10231023
ty = loc.ty
10241024
tz = loc.tz
10251025

1026-
if loc.start_slot >= wp.static(SLOT_LINEAR):
1026+
if loc.start_slot >= SLOT_LINEAR:
10271027
cx = float(loc.x_base)
10281028
cy = float(loc.y_base)
10291029
cz = float(loc.z_base)
@@ -1107,7 +1107,7 @@ def texture_sample_sdf_hw(
11071107

11081108
sdf_val = float(0.0)
11091109

1110-
if loc.start_slot >= wp.static(SLOT_LINEAR):
1110+
if loc.start_slot >= SLOT_LINEAR:
11111111
# ``cx + tx + 0.5`` lands at the centre of voxel (cx, cy, cz) and
11121112
# ``+tx`` walks toward (cx+1, ...). The HW filter returns the
11131113
# interpolated value in one fetch.
@@ -2526,10 +2526,10 @@ def _generate_isomesh_texture_kernel(
25262526
p_0 = wp.vec3f(corner_offsets_table[v_from])
25272527
p_1 = wp.vec3f(corner_offsets_table[v_to])
25282528
val_diff = val_1 - val_0
2529-
if wp.abs(val_diff) < wp.static(MC_EDGE_VAL_DIFF_EPS):
2529+
if wp.abs(val_diff) < MC_EDGE_VAL_DIFF_EPS:
25302530
p = 0.5 * (p_0 + p_1)
25312531
else:
2532-
t = wp.clamp((isovalue - val_0) / val_diff, wp.static(MC_EDGE_CLAMP_MIN), wp.static(MC_EDGE_CLAMP_MAX))
2532+
t = wp.clamp((isovalue - val_0) / val_diff, MC_EDGE_CLAMP_MIN, MC_EDGE_CLAMP_MAX)
25332533
p = p_0 + t * (p_1 - p_0)
25342534
vol_idx = p + wp.vec3(float(x_id), float(y_id), float(z_id))
25352535
local_pos = sdf.sdf_box_lower + wp.cw_mul(vol_idx, sdf.voxel_size)

newton/_src/geometry/sdf_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,10 @@ def _generate_dense_mc_kernel(
15211521
p_0 = wp.vec3f(corner_offsets_table[ev[0]])
15221522
p_1 = wp.vec3f(corner_offsets_table[ev[1]])
15231523
val_diff = val_1 - val_0
1524-
if wp.abs(val_diff) < wp.static(MC_EDGE_VAL_DIFF_EPS):
1524+
if wp.abs(val_diff) < MC_EDGE_VAL_DIFF_EPS:
15251525
p = 0.5 * (p_0 + p_1)
15261526
else:
1527-
t = wp.clamp((0.0 - val_0) / val_diff, wp.static(MC_EDGE_CLAMP_MIN), wp.static(MC_EDGE_CLAMP_MAX))
1527+
t = wp.clamp((0.0 - val_0) / val_diff, MC_EDGE_CLAMP_MIN, MC_EDGE_CLAMP_MAX)
15281528
p = p_0 + t * (p_1 - p_0)
15291529
local = base + p
15301530
face_verts[vi] = wp.vec3(
@@ -1534,7 +1534,7 @@ def _generate_dense_mc_kernel(
15341534
)
15351535
n = wp.cross(face_verts[1] - face_verts[0], face_verts[2] - face_verts[0])
15361536
n_sq = wp.dot(n, n)
1537-
if n_sq < wp.static(MC_DEGENERATE_N_SQ_EPS):
1537+
if n_sq < MC_DEGENERATE_N_SQ_EPS:
15381538
normal = wp.vec3(0.0, 0.0, 1.0)
15391539
else:
15401540
normal = n / wp.sqrt(n_sq)

newton/_src/sensors/warp_raytrace/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
if TYPE_CHECKING:
1919
from .render_context import RenderContext
2020

21+
# Knuth multiplicative hash constant (2^32 / golden ratio).
22+
# Typed uint32 so kernel codegen doesn't overflow an int32 constant.
23+
HASH_MULTIPLIER = wp.uint32(2654435761)
24+
2125

2226
def _resolve_fisheye_image_size(
2327
axis: str,
@@ -225,7 +229,7 @@ def unpack_shape_index_hash_to_rgba_kernel(
225229
# Knuth multiplicative hash, masked to 24 bits. ``idx + 1`` keeps shape 0
226230
# away from the all-zero hash that collides with the miss color; the
227231
# miss sentinel ``0xFFFFFFFF`` wraps back to 0 and intentionally renders black.
228-
h = ((idx + wp.uint32(1)) * wp.uint32(2654435761)) & wp.uint32(0xFFFFFF)
232+
h = ((idx + wp.uint32(1)) * HASH_MULTIPLIER) & wp.uint32(0xFFFFFF)
229233
out[n, y, x, 0] = wp.uint8((h >> wp.uint32(16)) & wp.uint32(0xFF))
230234
out[n, y, x, 1] = wp.uint8((h >> wp.uint32(8)) & wp.uint32(0xFF))
231235
out[n, y, x, 2] = wp.uint8(h & wp.uint32(0xFF))

0 commit comments

Comments
 (0)