Commit Graph

74 Commits

Author SHA1 Message Date
Bill Currie 778c07e91f [util] Get vectors working for non-SSE archs
GCC does a fairly nice job of producing code for vector types when the
hardware doesn't support SIMD, but it seems to break certain math
optimization rules due to excess precision (?). Still, it works well
enough for the core engine, but may not be well suited to the tools.
However, so far, only qfvis uses vector types (and it's not tested yet),
and tools should probably be used on suitable machines anyway (not
forces, of course).
2021-06-01 18:53:53 +09:00
Bill Currie a461c09586 [util] Make cmem consistent on 32 and 64 bit systems
I don't know that the cache line size is 64 bytes on 32 bit systems, but
it should be ok to assume that 64-byte alignment behaves well on systems
with smaller cache lines so long as they are powers of two. This does
mean there is some waste on 32-bit systems, but it should be fairly
minimal (32 bytes per memblock, which manages page sized regions).
2021-06-01 18:53:52 +09:00
Bill Currie 9dca47c0e1 Make the set tests word size agnostic. 2021-06-01 18:53:52 +09:00
Bill Currie b6ab832ed4 [simd] Add vabsf and some more tests 2021-03-28 19:49:43 +09:00
Bill Currie 29e029c792 [util] Add float a simd version of the SEB
And its support functions. I can't tell if it's any faster (mtwist_rand
is a significant chunk of the benchmark timings, oops), but it's nice to
have.
2021-03-27 23:38:10 +09:00
Bill Currie a3c1b2e992 [util] Rename qfplist.[ch]
The name is a hold-over from before the current quakeforge tree and the
QF include directory.
2021-03-21 16:13:03 +09:00
Bill Currie 4a97bc3ba5 [util] Create simd quaternion to matrix function
This seems to be pretty close to as fast as it gets (might be able to do
better with some shuffles of the negation constants instead of loading
separate constants).
2021-03-04 17:45:10 +09:00
Bill Currie 45c0255643 [util] Add simd 4x4 matrix functions
Currently just add, subtract, multiply (m m and m v).
2021-03-03 16:34:16 +09:00
Bill Currie 407ea15e35 [util] Fix some test bitrot 2021-03-02 15:05:19 +09:00
Bill Currie 55445a25f2 [util] Add some tests for the new cexpr work 2021-01-04 00:23:48 +09:00
Bill Currie 015cee7b6f [util] Add vector-quaternion shortcut functions
Care needs to be taken to ensure the right function is used with the
right arguments, but with these, the need to use qconj(d|f) for a
one-off inverse rotation is removed.
2021-01-02 10:44:45 +09:00
Bill Currie 7bf90e5f4a [util] Sort out implementation issues for simd 2021-01-02 09:55:59 +09:00
Bill Currie 1fd02322f4 [util] Clean up some minor issues in cmem
I forgot to remove the noinline attribute and do a check with
optimization (to catch the "pure" recommendation).
2021-01-01 22:29:31 +09:00
Bill Currie 9090c53519 [util] Add failing sub-line allocator tests
I think the sub-line allocator falling over is the final source of
qfvis's leaks. It certainly causes a mess of the sub-lines. But having
some tests to get working sure beats scratching my head over qfvis :)
2020-12-30 18:20:11 +09:00
Bill Currie d12abc5132 [util] Relink grown free line block
This fixes one source of memory leaks, but it seems some are still
lurking as qfvis still leaks like a sieve.
2020-12-30 18:20:11 +09:00
Bill Currie 4039075f41 [util] Use a linked list of free cache lines
The idea is to not search through blocks for an available allocation.
While the goal was to speed up allocation of cache lines of varying
cluster sizes, it's not enough due to fragmentation.
2020-12-30 18:20:11 +09:00
Bill Currie 1ddd57b09e [util] Add qconj, vtrunc, vceil and vfloor functions
I had forgotten these rather critical functions. Both double and float
versions are included.
2020-12-30 18:20:11 +09:00
Bill Currie 03fcb530c7 [util] Make quat test failure prints clearer 2020-12-30 18:20:11 +09:00
Bill Currie 09a10f80e1 [util] Add basic SIMD implemented vector functions
They take advantage of gcc's vector_size attribute and so only cross,
dot, qmul, qvmul and qrot (create rotation quaternion from two vectors)
are needed at this stage as basic (per-component) math is supported
natively by gcc.

The provided functions work on horizontal (array-of-structs) data, ie a
vec4d_t or vec4f_t represents a single vector, or traditional vector
layout. Vertical layout (struct-of-arrays) does not need any special
functions as the regular math can be used to operate on four vectors at
a time.

Functions are provided for loading a vec4 from a vec3 (4th element set
to 0) and storing a vec4 into a vec3 (discarding the 4th element).

With this, QF will require AVX2 support (needed for vec4d_t). Without
support for doubles, SSE is possible, but may not be worthwhile for
horizontal data.

Fused-multiply-add is NOT used because it alters the results between
unoptimized and optimized code, resulting in -mfma really meaning
-mfast-math-anyway. I really do not want to have to debug issues that
occur only in optimized code.
2020-12-30 18:20:11 +09:00
Bill Currie f3682638d4 [util] Add a mini expression parser
It is capable of parsing single expressions with fairly simple
operations. It current supports ints, enums, cvars and (external) data
structs. It is also thread-safe (in theory, needs proper testing) and
the memory it uses can be mass-freed.
2020-12-21 14:22:42 +09:00
Bill Currie ebcef5c8a4 [util] Deal with gcc optimizing out isnan checks
This occurs because of -ffast-math, but I need to investigate how much
of an impact disabling it has on QF's performance.
2020-12-21 14:14:38 +09:00
Bill Currie af814ff9a8 [util] Add a cache-line aligned memory allocator
This was inspired by
Hoard: A Scalable Memory Allocator
  for Multithreaded Applications

 Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, Paul R.
 Wilson,

It's not anywhere near the same implementation, but it did take a few
basic concepts. The idea is twofold:
1) A pool of memory from which blocks can be allocated and then freed
en-mass and is fairly efficient for small (4-16 byte) blocks
2) Tread safety for use with the Vulkan renderer (and any other
multi-threaded tasks).

However, based on the Hoard paper, small allocations are cache-line
aligned. On top of that, larger allocations are page aligned.

I suspect it would help qfvis somewhat if I ever get around to tweaking
qfvis to use cmem.
2020-12-21 14:14:29 +09:00
Bill Currie 62f3e1f428 [util] Calculate quaternion to rotate between two vectors
The calculation fails (produces NaN) if the vectors are anti-parallel,
but works for all other combinations. I came up with this implementation
when I discovered Unity's Quaternion.FromToRotation could did not work
with very small angles. This implementation will produce a usable
quaternion below 0.00255 degrees (though it will be slightly larger than
unit). Unity's failed such that I could see KSP's skybox snap while it
rotated around my test vessel.
2020-12-21 14:14:10 +09:00
Bill Currie e991c44232 [util] Make a minor improvement to QuatMultVec
Switch from using addition to multiplication for doubling the value.

Also, fix lib/util/test Makemodule to actually work (too much c&p
coding).
2020-12-21 14:13:57 +09:00
Bill Currie 86b5b30b45 Merge branch 'master' into vulkan 2020-06-25 14:03:52 +09:00
Bill Currie 6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie 7ae047654b [util] Rework SEB affine/convex testing
When I ported SEB to python, I discovered that I apparently didn't
really understand the paper's description of the end condition and the
usage of the affine and convex sets for center testing. This cleans up
the test and makes SEB more correct for the cases that have less than 4
supporting points (especially when there are less than 4 points total).
2020-06-21 17:07:54 +09:00
Bill Currie 1a7add3f6d Merge branch 'master' into vulkan 2020-03-20 13:04:41 +09:00
Bill Currie d2f03e8a64 [util] Fix darray test for gcc purity 2020-03-20 12:59:25 +09:00
Bill Currie 966bd267c5 Add a set of macros for dynamic arrays
Includes docs and test cases.
2020-03-20 12:59:25 +09:00
Bill Currie 79719babda [util] Fix darray test for gcc purity 2020-03-20 12:56:09 +09:00
Bill Currie f7493fe8fb Add a buffer-gap text buffer
This should be good for text editing and working with text files in
general.
2020-02-24 17:30:33 +09:00
Bill Currie 0cb04dc490 Add a set of macros for dynamic arrays
Includes docs and test cases.
2020-02-17 16:17:21 +09:00
Bill Currie e37aba364a Correct an apparent typo
Black makes much more sense than Slack, especially if the text is from a
quake mod (no idea where, though).
2020-02-17 12:58:23 +09:00
Bill Currie e164002050 Make QuatToMat faster and more accurate
The better accuracy is for specific cases (90 degree rotations around a
main axis: the matrix element for that axis is now 1 instead of
0.99999994). The speedup comes from doing fewer additions (multiply
seems to be faster than add for fp, at least in this situation).
2019-07-23 08:52:15 +09:00
Bill Currie f58c2fef5a Switch QF's quaterions from wxyz to xyzw.
After messing with SIMD stuff for a little, I think I now understand why
the industry went with xyzw instead of the mathematical wxyz. Anyway, this
will make for less pain in the future (assuming I got everything).
2018-10-12 14:33:55 +09:00
Bill Currie 6f28ab2a68 Add basic quaternion multiplication tests. 2018-10-09 12:44:46 +09:00
Bill Currie 34bcf7faab Do a pure/const/noreturn/format attribute pass.
I always wanted these, but as gcc now provides warnings for functions that
could do with such attributes, finding all the functions is much easier.
2018-10-09 12:42:21 +09:00
Bill Currie 575a67b2a1 mat4 test case fixes.
The tests cases themselves were buggy.
2018-08-26 15:06:08 +09:00
Bill Currie d1848a93c8 Add tests for chunk line numbers.
Which happen to find errors :P
2014-01-28 16:22:03 +09:00
Bill Currie d912970cd3 Add support for segmented text files.
The idea comes from The OpenGL Shader Wrangler
(http://prideout.net/blog/?p=11). Text files are broken up into chunks via
lines beginning with -- (^-- in regex). The chunks are optionally named
with tags of the form: [0-9A-Za-z._]+. Unnamed chunks cannot be found.
Searching for chunks looks for the longest tag that matches the beginning
of the search tag (eg, a chunk named "Vertex" will be found with a search
tag of "Vertex.foo"). Note that '.' forms the units for the searc
("Vertex.foo" will not find "Vertex.f").

Unlike glsw, this implementation does not have the concept of effects keys
as that will be separate. Also, this implementation takes strings rather
than file names (thus is more generally useful).
2014-01-28 16:22:03 +09:00
Bill Currie f5501fbf24 Fix a pile of automake deprecation warnings.
s/INCLUDES/AM_CPPFLAGS/g

I <3 sed :)
2013-11-24 13:11:50 +09:00
Bill Currie 27bb337a60 Use set_bits_t for holding set elements.
set_bits_t is now 64 bits for x86_64 machines (in linux, anyway). This gave
qfvis a huge speed boost: from ~815s to ~720s.

Also, expose some of the set internals so custom set operators can be
created.
2013-03-16 21:26:49 +09:00
Bill Currie 7753583bfd Catch accuracy errors.
I'd forgotten to set the result flag. Unfortunately, the errors can get
very bad (1e-3) it seems :(
2013-03-13 17:16:34 +09:00
Bill Currie 6eec76dd49 Implement Fischer's SEB algorithm (for 3d).
Now we can get tight (<1e-6 * radius_squared error) bounding spheres. More
importantly (for qfvis, anyway) very quickly: 1.7Mspheres/second for a 5
point cloud on my 2.33GHz Core 2 :)
2013-03-13 17:10:55 +09:00
Bill Currie 9bbf1a9110 test the right cs function (oops) 2013-03-13 16:38:56 +09:00
Bill Currie 3193ffd9cc Better (-1..1) random numbers.
Now the distribution should be more even as the rng doesn't affect the
exponent.
2013-03-13 14:41:04 +09:00
Bill Currie b6d4766201 Add a function to find the circumsphere of up to 4 points.
It seems to be a little sloppy (an error of a bit less than 1e-4). This
might be why I'm having trouble with my SEB code.
2013-03-13 14:35:30 +09:00
Bill Currie 0cd6d93030 Add a function to get the barycentric coords of a point.
It "works" for lines, triangles and tetrahedrons. For lines and triangles,
it gives the barycentric coordinates of the perpendicular projection of the
point onto to features. Only tetrahedrons are guaranteed to reproduce the
original point.
2013-03-12 14:16:42 +09:00
Bill Currie febb615580 Create a test for octal chars in plist strings.
Both reading and writing.
2013-01-08 16:32:57 +09:00