Commit Graph

57 Commits

Author SHA1 Message Date
Philip Rideout
b4b12914a1 Add bitcast to utils. 2018-12-04 17:56:37 -08:00
Mathias Agopian
6d68a4a4c6 libmath benchmarks 2018-12-03 11:58:30 -08:00
Mathias Agopian
e8895fee11 Add a binary search benchmark
this one basically shows that the stl is is a good as our "branch less"
versions. this is because clang generate branchless code in the end.
2018-11-29 11:44:52 -08:00
Mathias Agopian
42a3d5ea33 use utils::Mutex instead of std::mutex for Allocators locking policy
on Android it's about 2x faster and uses much less instructions, which
is better for i-cache pressure.
2018-11-29 11:44:52 -08:00
Mathias Agopian
785ce645e2 pool allocators benchmark
this benchmark shows that, as we expected, on Android mutexes,
spinlocks and lock-free algorithms are running at similar performance.
2018-11-29 11:44:52 -08:00
Ben Doherty
fe4907d0ff Remove use of iostream in filamat (#549) 2018-11-29 10:35:37 -08:00
Mathias Agopian
cf5606e940 Fix another bug in AtomicFreeList
An assert checking invariants would sometime trigger, the problem
was a logic error that would be exposed by a race when running out
of space in the list.

The root of the problem is that in one place we were not remapping the 
-1 offset to nullptr, storing a pointer violating our invariants.

Also added more asserts!!!
2018-11-28 12:10:23 -08:00
Mathias Agopian
05854e0d05 port the "filament_calls" benchmark to google benchmark 2018-11-27 15:07:45 -08:00
Sebastian Hartte
6b030c9694 More documentation of the free list 2018-11-27 11:44:32 -08:00
Sebastian Hartte
df4a2bb86e Fixes #542 by moving the assert to after checking for a possible race condition 2018-11-27 11:44:32 -08:00
Pixelflinger
cf4410f656 Add some libutils benchmarks 2018-11-26 11:51:17 -08:00
Pixelflinger
bc0f2f26f2 Tweak Profiler API so it works in multithread
Instead of using a singleton, Profiler has to be instantiated in the
scope/thread it is used.
2018-11-26 11:51:17 -08:00
shartte
9ab9333fa5 Fixes various MSVC issues in public headers (#523) 2018-11-26 09:17:19 -08:00
Mathias Agopian
9e39004b1f Add wait_for and wait_until to our Condition implementation
We're using timed condition variable in one place, but the STL version
pulls in a lot of code because it does clock calculations in 
"long double" (!!!!). Since we already had an implementation
of condition_variable, we just add the timed version.
This saves several KiB of code.

Also don't use unique_lock() lock/unlock because it can throw exceptions.
2018-11-21 13:46:07 -08:00
Mathias Agopian
1212728e45 get rid of std::string in OpenGLProgram
This was generating tons of code.
2018-11-21 13:46:07 -08:00
Mathias Agopian
815fb36b98 code size optimizations
- prevent unrolling of some loops. e.g. one loop generated more than
  1 KB of code!
2018-11-21 13:46:07 -08:00
Mathias Agopian
5bcc4cfff1 Improve the slow-path of creating a program
This removes a lot of heap allocations/deallocations, and reduces
code size. Most improvements come from using CString and
StaticString instead of std::string and better using move
semantics.
2018-11-21 13:46:07 -08:00
Mathias Agopian
c1a7164084 Improve usage of CString
This cuts down 7 calls to free() to 1, when
instantiating a new program. There are still many low-hanging fruits
there.
2018-11-21 13:46:07 -08:00
Philip Rideout
0d476b9f6d Fix debug builds. 2018-11-19 15:45:40 -08:00
prideout
694eab703c Remove usage of std::string in VulkanDriver. 2018-11-19 14:18:39 -08:00
Mathias Agopian
f011a212bd Minor clean-ups of Program 2018-11-13 16:02:44 -08:00
Mathias Agopian
bc3aee118a code size and performance optimizations (#472)
* Clean-up EntityManager a bit

- use tsl::robin_set instead of std::set (which should have been unordered::set
  anyways).

- getListeners() now returns a vector which avoids to traverse a set twice.
  Turns out that copying the set wasn't as efficient as I thought.

* Improve jobsystem a bit

We recently added a job reference counting mechanism, but we were a bit
too aggressive about taking/release references.

Also make the API more complete by adding explicit retain/release,
which is needed to allow several threads to wait on the same job.

Also improve futex code by inlining it.
2018-11-12 14:11:31 -08:00
Mathias Agopian
f8f24f492f minor typo / spelling / clang-tidy fixes (#468)
* Minor clean-ups

- fix a couple usage of std::function
- fix a couple usage of std::string
- remove ALIGN_LOOP, which didn't work
- fix a couple explicit/noexcept
- virtual -> override

* Fix spelling typos and other minor clang-tidy
2018-11-08 11:50:00 -08:00
Mathias Agopian
591c9f2454 Fix a crasher when allocating the last Job
Instead of returning nullptr, the pool allocator returned an
invalid pointer.
2018-11-06 13:44:35 -08:00
Mathias Agopian
e580bfed56 Fix allocator test when --gtest_repeat is used 2018-11-06 13:21:33 -08:00
Mathias Agopian
e2896f4632 Set cache size to 64 bytes on all platforms
We used to assume 32-bytes cache lines when running on ARM 32-bit mode,
however, that was wrong because 32-bit mode doesn't change the cpu's
cache line. On all modern platforms we support, the cache line
is 64 bytes.

Set Job storage to 48 bytes on all platforms.
2018-11-06 13:21:09 -08:00
Mathias Agopian
8c6cfdba67 Fix erroneous assert 2018-11-06 11:01:08 -08:00
Mathias Agopian
e5cfbeff4d Attempt to fix windows build
Align atomic HeadPtr to 64-bits.
2018-11-05 19:37:31 -08:00
Mathias Agopian
68c6afa72e Fix reuse after free and API inconsistency in job system (#446)
* Fix a reuse after free in the job system

Jobs were destroyed and recycled while still in use
by wait() or run(). To fix this we introduce reference-counting of
jobs.

Jobs start with a ref-count of 1, which is decremented when a job
naturally finishes. Additionally, all user-facing methods acquire
a reference for the duration of the call.

* Fix an API inconsistency with JobSystem

JobSystem's API lets the user create jobs but not destroy them.
Jobs are destroyed automatically, without a way for the caller to
know when that happens.

We now explicitly enforce that jobs are no longer valid when
wait() returns. Multiple concurrent wait() are allowed however.

This is enforced by clearing the job pointer upon returning
from JobSystem::wait(Job* job).

* Rename linked-list put/get to push/pop

* Better fix for Job use after free

There was still a race condition where a run()'ed
job could be destroyed before wait() was called,
wait would then use a destroyed object.

The available APIs now are:

run() - runs and destroys a job
runAndWait() - run, then waits for and destroys a job
runAndRetain() - runs and keep a reference to the job
wait() - waits and destroys a job

wait() can only be used with a job obtained with runAndRetain().

* Get rid of unused code

This version of parallel_for has use-after-free issues anyways,
since we changed the semantics of run/wait/etc...

* Fix decRef() memory order

decRef() must ensure that all access to the 
object have happened before destroying it.

* Fix memory order in atomic linked list's pop()

It needs acquire semantic, since we want to make
sure that no read/write are reordered before the
pop() -- which returns an object to the caller.

* Fix memory order on runningJobCount

we needed acquire semantic when about to destroy
the last job -- it's similar to decRef.

* Comment usages of std::memory_order_*

* Fix AtomicFreeList A-B-A bug

Turns out AtomicFreeList was not immune to the ABA bug. W're fixing
it here by using a 64-bits CAS, which is available on aarch64 and armv7.
2018-11-05 19:12:13 -08:00
Mathias Agopian
d9df864de4 Get rid of RangeSet. 2018-10-24 15:11:54 -07:00
Mathias Agopian
e96f982c9f Fix typo in RangeSet
Fixes #407
2018-10-19 11:42:39 -07:00
prideout
e74a306df2 Fix utils::Path concat for relative paths.
Concating with an empty path should not prepend a slash since doing so
implies that the user wants to access the system's root folder.

Fixes #332
2018-10-04 07:31:25 -07:00
Mathias Agopian
4302d9dcc3 reduce our dependency to the STL in public headers 2018-10-03 20:13:17 -07:00
Mathias Agopian
69bdb6d1c9 don’t use stderr, this causes some linking problems on Android. 2018-10-02 14:45:06 -07:00
prideout
3a7d80f29b Restore "Add single-threaded config to Filament. (#130)"
This reverts commit 24022010f9.
2018-08-27 08:51:46 -07:00
Philip Rideout
24022010f9 Revert "Add single-threaded config to Filament. (#130)" (#152)
This reverts commit e3457aa0a7.
2018-08-26 18:40:49 -07:00
Philip Rideout
446959042f Make code friendly to WebAssembly. (#140)
This does not add any build stuff or new sample code yet, it just does
some prep to our C++ codebase:

- Similar to Android, WebAssembly will not be using BlueGL. We were
  using a mixture of #if and #ifdef when checking for the existence of
  certain GL prototypes, but the latter is what we want in order to
  build robustly with any GL headers. (We still perform run-time checks
  for extensions, this doesn't change that.)

- Add a trivial ContextManager, does a bit more than Dummy since it
  needs to create an actual driver. This doesn't get compiled yet, it
  just adds files to the tree.

- WebAssembly does not support mmap, execinfo, or asm volatile.
2018-08-24 17:17:40 -07:00
Philip Rideout
e3457aa0a7 Add single-threaded config to Filament. (#130)
* Add single-threaded config to Filament.

This adds a tick method to Engine and disables a couple components
in Renderer (FrameSkipper and FrameInfoManager).

This will make it easier to support WebGL, and will allow us to remove
some of the command buffer debugging stuff that we added for Vulkan.

* tick => execute, and other review feedback

* Restore the ASSERT for FFence::wait.
2018-08-24 16:37:12 -07:00
Philip Rideout
099738e545 Try to clean up asset folders for sample apps. (#128)
* Try to clean up asset folders for sample apps.

This removes the build step where we copy a subset of assets, and makes
it so that FilamentApp hands out a "root path" for assets. For now this
is determined based on the location of the executable. This allows
developers to launch samples from any CWD.

Closes #11

* Restore asset copy to build.
2018-08-23 12:46:45 -07:00
Mathias Agopian
9a129dca1e improve BinaryTreeArray unit test
make sure we visit children before the parents.
2018-08-22 14:55:17 -07:00
Mathias Agopian
1f3dad48b6 Improve Binary Tree Array by getting rid of the recursion
We use a stack instead, it’s not terribly different
from the recursion but it saves function calls
which use a lot more stack than needed.
2018-08-22 14:55:17 -07:00
Mathias Agopian
38de58007c checkpoint: ground work for calculating binary light trees
computeLightTree() takes a list of light as
a bitfield and produces a depth-first 
binary tree array that can be used to efficiently
check which lights volumes contain a given z
coordinate in screen space.

Currently computeLightTree() produces the array
locally on the stack, which isn’t useful, but
before we can make use of it, a lot of other
things have to happen.
2018-08-22 14:55:17 -07:00
Mathias Agopian
c8c61fdb8a more froxel optimizations (#118)
* better froxel records compression

We used to compress froxel records by reusing the
previous record on the left if it was identical,
now we additionally check the record above if
that fails.

In practice this saves 10% to 30% space in the
froxel record buffer, which is a scarce resource 
for us.

e.g. if a light occupied 3x3 froxels in a given 
z-slice, without compression 9 records would be
used, with left-only compression, only 3, 
and with left+above compression, only 1.

* use size_t for in and out parameters

this helps the compiler in many places, not
having to cast from 64 to 32 bits.

* implement bitset’s any() and all() operations with NEON

* empty froxels are a common case, handle it first
2018-08-20 16:45:16 -07:00
Mathias Agopian
5ed80bc616 Add ctz to utils::algorithm
Use CTZ in bitset.forEachBitSet() so we can
efficiently go through them in order instead of
reverse order.
2018-08-17 19:48:23 -07:00
Mathias Agopian
2bdf4c7911 use pointers instead of std::array<>::iterator (#100)
some STL implementations assert when iterators are
out of range (even without dereferencing).
2018-08-15 12:59:28 -07:00
Mathias Agopian
3d3f169a63 MSVC's STL doesn't let iterators go before begin() (#98)
* MSVC's STL doesn't let iterators go before begin()

This is the case even of the iterator is not
dereferenced. Fix #94.

* cleanup
2018-08-14 22:26:39 -07:00
Mathias Agopian
d9ba3998d2 JobSystem now automatically free Jobs (#91)
* JobSystem now automatically free Jobs

Until now Job allocation used a linear allocator
strategy which required to “reset” the JobSystem
periodically — typically once per frame in
filament.

This is no longer required. We use a pool allocator
now, which doesn’t add much overhead. It does
use a spin-lock for thread-safety though, since
we assume very little contention, this shouldn’t
be a problem.

* Thread Safe Object Pool Allocator

A lock-less, thread-safe object pool allocator,
now used for storing JobSystem’s jobs allocations.
This gets rid of the spin-lock introduced in the
previous cl.
2018-08-13 22:25:15 -07:00
Mathias Agopian
c91d2aedd8 per-light multithreading works again for froxelization
We spawn MAX_LIGHTS/32 (currently 8) jobs and
multi-threading is active as soon as we have more
than one light. All jobs work on disjoint buffers
to avoid false sharing between threads.

It’s possible to adjust roughly the number of jobs
by changing the group size (currently 32). However
this also affects vectorization.

With the current parameters, with 256 lights max
we get 8 jobs, and 4 spot-light test / froxel.
2018-08-13 11:36:24 -07:00
Mathias Agopian
7b7bd85def New froxelization algorithm that uses much less memory
Instead of building a list of froxel per light,
we now build a bitfield of lights per froxel.
To keep the code efficient we have to split
the bitfield array in 4, so that we can use
multiple threads without having them or’ing
each other’s cache-lines.

This data structure is also what we want in 
froxelizeAssignRecords(), and the conversion from
one format to the other is much faster.

Our internal data structure is now 256 KiB
instead of 2 MiB. It would be 1 MiB for 1024 lights
(down from 16 MiB)

Additionally, because the code is simpler, we get
more vectorization, especially with spot-lights.

One draw-back of the current version is that
multi-threading happens only every 64 lights.
This will be fixed later.
2018-08-13 11:36:24 -07:00
Mathias Agopian
a4851ed835 fix a bunch of clang-tidy warnings
fixed a couple actual real bugs (missing returns 
in operator=, wrong implicit bool conversion).

mostly added a bunch of explicit ctor.
2018-08-10 20:53:58 -07:00