Comments (10)
I've looked at it a bit, and found an interesting oddity. In graphene_ray_intersect_box()
, at line 492, the inv_dir.value = graphene_simd4f_reciprocal (r->direction.value)
call results in a vec3 containing: -nan
, 2.0194845200
, -1.1510224342
. Everything else derails from there.
from graphene.
I think the bug here is that inv_dir.x
should have resulted in +∞ instead of NaN
from graphene.
Indeed. I spent some time trying to work around that, and come up with a SSE 4.1 implementation that turned that -nan
into FLT_MAX
, which made it work on my CPU; but it wasn't very portable, and my aarch64 board isn't booting so I didn't look further into the neon variant.
Also, not sure requiring SSE4.1 is an option.
from graphene.
Fwiw, here is the SSE4.1 variant:
# define graphene_simd4f_reciprocal(v) \
(__extension__ ({ \
const graphene_simd4f_t __two = graphene_simd4f_init (2.0f, 2.0f, 2.0f, 2.0f); \
const graphene_simd4f_t __inf = graphene_simd4f_init (FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); \
graphene_simd4f_t __mask = _mm_cmpeq_ps(_mm_set1_ps(0.0), (v)); \
graphene_simd4f_t __s = _mm_andnot_ps (__mask, _mm_rcp_ps ((v))); \
graphene_simd4f_t __r = _mm_blendv_ps (__s, __inf, __mask); \
graphene_simd4f_mul (__r, graphene_simd4f_sub (__two, graphene_simd4f_mul ((v), __r))); \
}))
from graphene.
Also not sure if graphene_simd4f_t __mask = _mm_cmpeq_ps(_mm_set1_ps(0.0), (v));
is enough; as it does == 0.0
and not withit FLT_EPSILON * 2
which was needed in my tests to make all paths pass (SIMD & non-SIMD).
from graphene.
So, based on your code for Mutter, this seems to work here:
@@ -485,27 +486,46 @@ graphene_ray_intersect_box (const graphene_ray_t *r,
const graphene_box_t *b,
float *t_out)
{
+ graphene_vec3_t safe_direction;
graphene_vec3_t inv_dir;
+ float d[3];
+
+#define V(v) (graphene_approx_val (d[v], 0.f) ? 2 * FLT_EPSILON : d[v])
+ graphene_vec3_to_float (&r->direction, d);
+ graphene_vec3_init (&safe_direction, V (0), V (1), V (2));
+#undef V
/* FIXME: Needs a graphene_vec3_reciprocal() */
- inv_dir.value = graphene_simd4f_reciprocal (r->direction.value);
+ inv_dir.value = graphene_simd4f_reciprocal (safe_direction.value);
from graphene.
Here seems like a better place for this code than in mutter.
from graphene.
Ping @ebassi .
from graphene.
The solution from @GeorgesStavracas looks good to me. I wonder if he wants to open a PR, or if I should do that.
from graphene.
I went and created #217 that works slightly the same, except it uses a static inline function and makes sure the direction stays on the correct side of the axis.
from graphene.
Related Issues (20)
- Documentation of graphene_simd4x4f_vec4_mul() has notation issues
- Explore the idea of peeking SIMD data
- 1.10.4: installed_tests=true tests=true does not build, execute and install any tests HOT 5
- GIR XML is architecture-dependent, perhaps unnecessarily?
- Alignement fault for graphene_vec3_dot with neon HOT 23
- 1.10.4: installed_tests=true and tests=true and tests are not installed HOT 3
- Option to specify custom allocators HOT 2
- Wrong results for ray/box intersection on systems without isnanf
- Introspection build issue HOT 9
- Link in sidebar should go to github.io not github.com HOT 1
- graphene_rect_contains_point() is wrong about points above the rect HOT 6
- Dead link in graphene_matrix_decompose doc HOT 1
- Support the RISC-V Vector extension HOT 3
- ray: Intersect triangle does not work
- ray and simd tests fail on i686 HOT 1
- installed_tests=false still installs introspection file
- error when enabling -Werror=double-promotion on software using this library HOT 4
- Identity matrix is treated as 2d, decomposing only xy scale
- build: error with meson 0.60: "../meson.build:277:2: ERROR: Function accepts only strings, integers, lists, dictionaries and lists thereof." HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene.