Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Apr 25, 2024
1 parent fdbfcf7 commit e3c15bb
Show file tree
Hide file tree
Showing 44 changed files with 130 additions and 174 deletions.
8 changes: 2 additions & 6 deletions internal/CoreRef.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <vector>
#include <cfloat>
#include <vector>

#include "Core.h"

Expand Down Expand Up @@ -191,11 +191,7 @@ force_inline float safe_div_neg(const float a, const float b) {

force_inline void safe_invert(const float v[3], float out_v[3]) {
for (int i = 0; i < 3; ++i) {
if (fabsf(v[i]) > FLT_EPS) {
out_v[i] = 1.0f / v[i];
} else {
out_v[i] = (v[i] >= 0.0f) ? FLT_MAX : -FLT_MAX;
}
out_v[i] = (fabsf(v[i]) > FLT_EPS) ? (1.0f / v[i]) : copysignf(FLT_MAX, v[i]);
}
}

Expand Down
50 changes: 7 additions & 43 deletions internal/CoreSIMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ template <int S> force_inline fvec<S> safe_inv_pos(const fvec<S> &a) {

template <int S> force_inline fvec<S> safe_div(const fvec<S> &a, const fvec<S> &b) {
#if USE_SAFE_MATH
const fvec<S> denom = select(b != 0.0f, b, fvec<S>{FLT_EPS});
const fvec<S> denom = select(b != 0.0f, b, copysign(fvec<S>{FLT_EPS}, b));
return a / denom;
#else
return a / b;
Expand Down Expand Up @@ -1426,55 +1426,19 @@ template <int StackSize, typename T = stack_entry_t> class TraversalStateStack_S
};

template <int S>
force_inline void comp_aux_inv_values(const fvec<S> o[3], const fvec<S> d[3], fvec<S> inv_d[3], fvec<S> inv_d_o[3]) {
void comp_aux_inv_values(const fvec<S> o[3], const fvec<S> d[3], fvec<S> inv_d[3], fvec<S> inv_d_o[3]) {
for (int i = 0; i < 3; i++) {
const fvec<S> denom = select(d[i] != 0.0f, d[i], fvec<S>{FLT_EPS});
const fvec<S> denom = select(abs(d[i]) > FLT_EPS, d[i], copysign(fvec<S>{FLT_EPS}, d[i]));

inv_d[i] = 1.0f / denom;
inv_d_o[i] = o[i] * inv_d[i];

const fvec<S> d_is_plus_zero = (d[i] <= FLT_EPS) & (d[i] >= 0.0f);
where(d_is_plus_zero, inv_d[i]) = MAX_DIST;
where(d_is_plus_zero, inv_d_o[i]) = MAX_DIST;

const fvec<S> d_is_minus_zero = (d[i] >= -FLT_EPS) & (d[i] < 0.0f);
where(d_is_minus_zero, inv_d[i]) = -MAX_DIST;
where(d_is_minus_zero, inv_d_o[i]) = -MAX_DIST;
}
}

force_inline void comp_aux_inv_values(const float o[3], const float d[3], float inv_d[3], float inv_d_o[3]) {
if (d[0] <= FLT_EPS && d[0] >= 0) {
inv_d[0] = MAX_DIST;
inv_d_o[0] = MAX_DIST;
} else if (d[0] >= -FLT_EPS && d[0] < 0) {
inv_d[0] = -MAX_DIST;
inv_d_o[0] = -MAX_DIST;
} else {
inv_d[0] = 1.0f / d[0];
inv_d_o[0] = inv_d[0] * o[0];
}

if (d[1] <= FLT_EPS && d[1] >= 0) {
inv_d[1] = MAX_DIST;
inv_d_o[1] = MAX_DIST;
} else if (d[1] >= -FLT_EPS && d[1] < 0) {
inv_d[1] = -MAX_DIST;
inv_d_o[1] = -MAX_DIST;
} else {
inv_d[1] = 1.0f / d[1];
inv_d_o[1] = inv_d[1] * o[1];
}

if (d[2] <= FLT_EPS && d[2] >= 0) {
inv_d[2] = MAX_DIST;
inv_d_o[2] = MAX_DIST;
} else if (d[2] >= -FLT_EPS && d[2] < 0) {
inv_d[2] = -MAX_DIST;
inv_d_o[2] = -MAX_DIST;
} else {
inv_d[2] = 1.0f / d[2];
inv_d_o[2] = inv_d[2] * o[2];
void comp_aux_inv_values(const float o[3], const float d[3], float inv_d[3], float inv_d_o[3]) {
for (int i = 0; i < 3; ++i) {
inv_d[i] = (fabsf(d[i]) > FLT_EPS) ? (1.0f / d[i]) : copysignf(FLT_MAX, d[i]);
inv_d_o[i] = (fabsf(d[i]) > FLT_EPS) ? (inv_d[i] * o[i]) : copysignf(FLT_MAX, d[i]);
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/shaders/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ vec3 normalize_len(const vec3 v, out float len) {
return v / (len = length(v));
}

float _copysign(const float val, const float sign) {
return sign < 0.0 ? -abs(val) : abs(val);
}

vec3 safe_invert(vec3 v) {
vec3 ret;
[[unroll]] for (int i = 0; i < 3; ++i) {
[[flatten]] if (abs(v[i]) > FLT_EPS) {
ret[i] = 1.0 / v[i];
} else {
ret[i] = (v[i] >= 0.0) ? FLT_MAX : -FLT_MAX;
}
ret[i] = (abs(v[i]) > FLT_EPS) ? (1.0 / v[i]) : _copysign(FLT_MAX, v[i]);
}
return ret;
}
Expand Down
4 changes: 0 additions & 4 deletions internal/shaders/light_bvh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ float sin_sub_clamped(const float sin_omega_a, const float cos_omega_a, const fl
return sin_omega_a * cos_omega_b - cos_omega_a * sin_omega_b;
}

float _copysign(const float val, const float sign) {
return sign < 0.0 ? -abs(val) : abs(val);
}

vec3 decode_oct_dir(const uint oct) {
vec3 ret;
ret.x = -1.0 + 2.0 * float((oct >> 16) & 0x0000ffff) / 65535.0;
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene_indirect.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_atlas.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_bindless.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_atlas.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_bindless.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit e3c15bb

Please sign in to comment.