Commit Graph
189 Commits
Author SHA1 Message Date
Ben Doherty 594f1abbbc Rename GlslChunk to TextChunk (#527)
* Rename Glsl -> Text

* Make MaterialTextChunk and DictionaryTextChunk more generic
2018-11-26 14:02:04 -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
Ben Doherty 6d158bbc80 Remove codeGenTargetApi (#511) 2018-11-26 10:51:34 -08:00
shartte 9ab9333fa5 Fixes various MSVC issues in public headers (#523) 2018-11-26 09:17:19 -08:00
Mathias Agopian d1b19efa55 a fast approximation of pow() and pow(x, 2.2f)
fast::pow(x, 2.2f) is about 100x faster than std::pow.
std::pow(x, 2.2f) takes roughly 1000 cycles.
2018-11-21 13:46:56 -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
prideout 776284b2b5 Raise sampler limit to 16.
In practice this limits materials to 10 samplers since Filament uses 5
for lights and skips 1 slot for the post-process sampler. This can
probably be optimized.
2018-11-20 16:05:16 -08:00
prideout cfa9895b96 Improve error reporting for bindings overflow.
We now check for sampler overflow during material compilation rather
than waiting for run-time checks. This allows for Kokoro-based
validation of sample materials, and allows developers to catch this
issue in their asset pipeline.

We should also probably raise the upper limit (Qualcomm allows up to 16
samplers in their Vulkan implementation) but that can be a separate PR.

Fixes #507
2018-11-20 15:28:02 -08:00
Ben Doherty b5fa822e86 Move GLSLPostProcessor and dependencies into filamat (#500)
* Move GLSLPostProcessor into filamat
2018-11-20 12:30:26 -08:00
Philip Rideout aa0090a85b Fix build warnings. 2018-11-19 15:59:31 -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
Philip Rideout edb545919a Fix regression with non-Vulkan backends.
This fixes the "shader is not ASCII" error seen with GL backend,
introduced when we changed blob ownership semantics to accommodate
shader compression. It was due to missing null terminators.

We actually never bothered including the trailing null in blob length,
which was wrong but happened to work because the BlobDictionary held a
weak reference to chunk data. SInce it now holds an actual copy, the
lack of null caused our strings to contain garbage memory.
2018-11-16 15:43:41 -08:00
Philip Rideout b2a2da532a Fix Android-with-Vulkan build. 2018-11-16 12:07:23 -08:00
Philip Rideout b83c82ea9b Enable SMOLV compression. 2018-11-16 12:07:23 -08:00
Philip Rideout e0fd196530 Exclude SMOL from Vulkan-free builds. 2018-11-15 16:55:40 -08:00
Philip Rideout 55eaad9450 Add smol-v to third_party.
Since we use this for decoding, this adds a dependency to the core
filament renderer which in practice is only used for Vulkan. However
this is a tiny library, so it's simplest just to always include it.

The next PR will add the actual compression / decompression code to
filaflat and filamat. Here are the preliminary results.

   102K =>  29K  aiDefaultMat.filamat
   102K =>  29K  aiDefaultTrans.filamat
    21K => 5.0K  bakedColor.filamat
    22K => 5.2K  bakedTexture.filamat
    21K => 5.0K  depthVisualizer.filamat
    40K =>  10K  groundShadow.filamat
   102K =>  29K  sandboxCloth.filamat
   125K =>  36K  sandboxLit.filamat
   126K =>  36K  sandboxLitFade.filamat
   126K =>  36K  sandboxLitTransparent.filamat
   109K =>  31K  sandboxSubsurface.filamat
    21K => 4.9K  sandboxUnlit.filamat
    21K => 4.9K  transparentColor.filamat

Both the "before" and "after" numbers are excluding non-Vulkan targets,
and I also changed our CMakeLists to build filamat instead of inc.
2018-11-15 16:55:40 -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
Philip Rideout ee5b0268fd Introduce KtxUtility to make it easier to translate enum values. 2018-11-07 16:12:55 -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
Philip Rideout a42dcd2291 JavaScript code re-org (#443)
This removes the old CPP-based web samples in favor of the new JS API.

The `web/samples` folder will be added in a subsequent commit.
2018-11-01 17:05:30 -07:00
Romain Guy 4e3a88bbab Cleanup and documentation (#445) 2018-11-01 16:36:52 -07:00
Mathias Agopian f52087ec1e Attempt to upload streaming ubo data more efficiently
IF an UBO is marked as STREAM, meaning that data will
change every frame and the buffer content is invalidated
as well, then we use map/unmap buffer in asynchronous
mode to copy the data into the buffer.

This assumes the buffer is sized to be significantly
larger than the average amount of data used every
frame.
2018-11-01 11:30:38 -07:00
Philip Rideout 522a8bedb8 Update filamentjs test runner. 2018-10-30 16:50:24 -07:00
Philip Rideout 8ad655766b JavaScript: concise setBuffer API 2018-10-29 18:09:45 -07:00
Philip Rideout 5da454f652 JavaScript: concise texture creation functions
This makes our createTexture* helpers more consistent with the
createMaterial helper, and extends the wrapped Engine class with new
methods.

Before, clients did something like this:

    const ao = Filament.createTextureFromPng(Filament.assets['foo.png'], engine);
    ...
    engine.destroyTexture(ao);

Now, they can do:

    const ao = engine.createTextureFromPng('foo.png');
    ...
    engine.destroyTexture(ao);

This is more symmetric and concise. In general the JS API now supports a
class of "buffer-like" objects which exploit dynamic typing in order to
accept any of the following: BufferDescriptor, asset string, or
Uint8Array.
2018-10-29 18:09:45 -07:00
Philip Rideout 0deafea0da Add requirements.txt for Python scripts. 2018-10-29 17:53:09 -07:00
Philip Rideout 69e379cf90 Test for JS leaks using emcc --memoryprofiler. 2018-10-29 17:53:09 -07:00
Philip Rideout e8fddba494 New JS test for memory leaks.
This test recreates a renderable every few frames and dumps the heap
pointer to the console so we can check if it increases over time.

Also simplified the personal web server script so that it uses twisted
and avoid doing a chdir, seems to be more reliable this way.
2018-10-29 17:53:09 -07:00
Philip Rideout 4860ff816f JavaScript PNG utility now has SRGB flag. 2018-10-29 17:38:02 -07:00
Philip Rideout 82e61ddc88 Fix the JS IcoSphere tangents.
We were not normalizing one of the orthonormal basis vectors, causing
the visual aberration reported in #423.

This CL also add a "back light" to the redball demo to lighten up the
dark area in the IBL.

Fixes #423
2018-10-29 17:37:42 -07:00
Philip Rideout 3b793a7994 Fix bad memory access in JS wood demo. 2018-10-26 16:29:26 -07:00
Ben Dohertyandprideout e2777b9100 Update libs/filamentjs/tests/test_parquet.js
Co-Authored-By: prideout <philiprideout@gmail.com>
2018-10-26 10:30:44 -07:00
Ben Dohertyandprideout 96cb5d5951 Update libs/filamentjs/tests/test_parquet.js
Co-Authored-By: prideout <philiprideout@gmail.com>
2018-10-26 10:30:44 -07:00
Ben Dohertyandprideout e6bb8a6235 Update libs/filamentjs/tests/test_parquet.js
Co-Authored-By: prideout <philiprideout@gmail.com>
2018-10-26 10:30:44 -07:00
Ben Dohertyandprideout 934b75e68b Update libs/filamentjs/tests/test_parquet.js
Co-Authored-By: prideout <philiprideout@gmail.com>
2018-10-26 10:30:44 -07:00
Philip Rideout 58f36d1a7f New JS test: draw shaderball with parquet wood texture.
Shameless recreation of the Android `textured-android` sample. I will
make this into a tutorial soon.

Also made some improvements to the test-builder Python script. Really,
this script exists only to make iteration easier; we need a better
solution for automated tests...
2018-10-26 10:30:44 -07:00
Philip Rideout 83e4402e90 JS: fix use-before-free for PNG data. 2018-10-26 10:05:18 -07:00