Skip to content

Commit

Permalink
Merge branch 'rc/1.42.1' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado committed Sep 8, 2023
2 parents fe2bb3d + d01b29f commit de310ed
Show file tree
Hide file tree
Showing 57 changed files with 1,121 additions and 756 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repositories {
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.42.0'
implementation 'com.google.android.filament:filament-android:1.42.1'
}
```

Expand All @@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
iOS projects can use CocoaPods to install the latest release:

```
pod 'Filament', '~> 1.42.0'
pod 'Filament', '~> 1.42.1'
```

### Snapshots
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ A new header is inserted each time a *tag* is created.
Instead, if you are authoring a PR for the main branch, add your release note to
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).

## v1.42.1

- Fix potential `EXC_BAD_ACCESS` with Metal backend: b/297059776
- `setFrameCompletedCallback` now takes a `backend::CallbackHandler`.

## v1.42.0

- engine: add preliminary support for instanced stereoscopic rendering [⚠️ **Recompile materials**]
Expand Down
7 changes: 3 additions & 4 deletions android/filament-android/src/main/cpp/SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SwapChain_nSetFrameCompletedCallback(JNIEnv* env, jclass,
jlong nativeSwapChain, jobject handler, jobject runnable) {
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
auto *callback = JniCallback::make(env, handler, runnable);
swapChain->setFrameCompletedCallback([](void* user) {
JniCallback* callback = (JniCallback*)user;
auto* callback = JniCallback::make(env, handler, runnable);
swapChain->setFrameCompletedCallback(nullptr, [callback](SwapChain* swapChain) {
JniCallback::postToJavaAndDestroy(callback);
}, callback);
});
}

extern "C" JNIEXPORT jboolean JNICALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ public Object getNativeWindow() {
* </p>
*
* <p>
* The FrameCompletedCallback is guaranteed to be called on the main Filament thread.
* </p>
*
* <p>
* Warning: Only Filament's Metal backend supports frame callbacks. Other backends ignore the
* callback (which will never be called) and proceed normally.
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import static com.google.android.filament.Asserts.assertFloat4In;
import static com.google.android.filament.Colors.LinearColor;

import com.google.android.filament.proguard.UsedByNative;

/**
* Encompasses all the state needed for rendering a {@link Scene}.
*
Expand Down Expand Up @@ -1095,10 +1097,29 @@ public void pick(int x, int y,
nPick(getNativeObject(), x, y, handler, internalCallback);
}

@UsedByNative("View.cpp")
private static class InternalOnPickCallback implements Runnable {
private final OnPickCallback mUserCallback;
private final PickingQueryResult mPickingQueryResult = new PickingQueryResult();

@UsedByNative("View.cpp")
@Entity
int mRenderable;

@UsedByNative("View.cpp")
float mDepth;

@UsedByNative("View.cpp")
float mFragCoordsX;
@UsedByNative("View.cpp")
float mFragCoordsY;
@UsedByNative("View.cpp")
float mFragCoordsZ;

public InternalOnPickCallback(OnPickCallback mUserCallback) {
this.mUserCallback = mUserCallback;
}

@Override
public void run() {
mPickingQueryResult.renderable = mRenderable;
Expand All @@ -1108,13 +1129,6 @@ public void run() {
mPickingQueryResult.fragCoords[2] = mFragCoordsZ;
mUserCallback.onPick(mPickingQueryResult);
}
private final OnPickCallback mUserCallback;
private final PickingQueryResult mPickingQueryResult = new PickingQueryResult();
@Entity int mRenderable;
float mDepth;
float mFragCoordsX;
float mFragCoordsY;
float mFragCoordsZ;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.google.android.filament
VERSION_NAME=1.42.0
VERSION_NAME=1.42.1

POM_DESCRIPTION=Real-time physically based rendering engine for Android.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ class MainActivity : Activity() {
}

private fun setupView() {
val ssaoOptions = view.ambientOcclusionOptions
ssaoOptions.enabled = true
view.ambientOcclusionOptions = ssaoOptions
// ambient occlusion is the cheapest effect that adds a lot of quality
view.ambientOcclusionOptions = view.ambientOcclusionOptions.apply {
enabled = true
}

// NOTE: Try to disable post-processing (tone-mapping, etc.) to see the difference
// view.isPostProcessingEnabled = false
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(SRCS
src/BackendUtils.cpp
src/BlobCacheKey.cpp
src/Callable.cpp
src/CallbackHandler.cpp
src/CircularBuffer.cpp
src/CommandBufferQueue.cpp
src/CommandStream.cpp
Expand Down Expand Up @@ -68,6 +67,8 @@ set(PRIVATE_HDRS
if (FILAMENT_SUPPORTS_OPENGL AND NOT FILAMENT_USE_EXTERNAL_GLES3 AND NOT FILAMENT_USE_SWIFTSHADER)
list(APPEND SRCS
include/backend/platforms/OpenGLPlatform.h
src/opengl/CallbackManager.h
src/opengl/CallbackManager.cpp
src/opengl/gl_headers.cpp
src/opengl/gl_headers.h
src/opengl/GLUtils.cpp
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/include/backend/CallbackHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CallbackHandler {
virtual void post(void* user, Callback callback) = 0;

protected:
virtual ~CallbackHandler();
virtual ~CallbackHandler() = default;
};

} // namespace filament::backend
Expand Down
2 changes: 0 additions & 2 deletions filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,6 @@ static_assert(sizeof(StencilState) == 12u,

using FrameScheduledCallback = void(*)(PresentCallable callable, void* user);

using FrameCompletedCallback = void(*)(void* user);

enum class Workaround : uint16_t {
// The EASU pass must split because shader compiler flattens early-exit branch
SPLIT_EASU,
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/include/backend/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class Program {
Sampler const* samplers, size_t count) noexcept;

struct SpecializationConstant {
using Type = std::variant<int32_t, float, bool>;
uint32_t id; // id set in glsl
std::variant<int32_t, float, bool> value; // value and type
Type value; // value and type
};

Program& specializationConstants(
Expand Down
6 changes: 6 additions & 0 deletions filament/backend/include/backend/platforms/OpenGLPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ class OpenGLPlatform : public Platform {
* @see terminate()
*/
virtual void createContext(bool shared);

/**
* Detach and destroy the current context if any and releases all resources associated to
* this thread.
*/
virtual void releaseContext() noexcept;
};

} // namespace filament
Expand Down
2 changes: 2 additions & 0 deletions filament/backend/include/backend/platforms/PlatformEGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PlatformEGL : public OpenGLPlatform {
PlatformEGL() noexcept;
bool isExtraContextSupported() const noexcept override;
void createContext(bool shared) override;
void releaseContext() noexcept override;

protected:

Expand Down Expand Up @@ -139,6 +140,7 @@ class PlatformEGL : public OpenGLPlatform {
bool KHR_create_context = false;
bool KHR_gl_colorspace = false;
bool KHR_no_config_context = false;
bool KHR_surfaceless_context = false;
} egl;
} ext;

Expand Down
7 changes: 5 additions & 2 deletions filament/backend/include/private/backend/DriverAPI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ DECL_DRIVER_API_N(setFrameScheduledCallback,

DECL_DRIVER_API_N(setFrameCompletedCallback,
backend::SwapChainHandle, sch,
backend::FrameCompletedCallback, callback,
backend::CallbackHandler*, handler,
backend::CallbackHandler::Callback, callback,
void*, user)

DECL_DRIVER_API_N(setPresentationTime,
Expand Down Expand Up @@ -273,6 +274,7 @@ DECL_DRIVER_API_N(destroyRenderTarget, backend::RenderTargetHandle, rth)
DECL_DRIVER_API_N(destroySwapChain, backend::SwapChainHandle, sch)
DECL_DRIVER_API_N(destroyStream, backend::StreamHandle, sh)
DECL_DRIVER_API_N(destroyTimerQuery, backend::TimerQueryHandle, sh)
DECL_DRIVER_API_N(destroyFence, backend::FenceHandle, fh)

/*
* Synchronous APIs
Expand All @@ -286,7 +288,6 @@ DECL_DRIVER_API_SYNCHRONOUS_N(void, setAcquiredImage, backend::StreamHandle, str
DECL_DRIVER_API_SYNCHRONOUS_N(void, setStreamDimensions, backend::StreamHandle, stream, uint32_t, width, uint32_t, height)
DECL_DRIVER_API_SYNCHRONOUS_N(int64_t, getStreamTimestamp, backend::StreamHandle, stream)
DECL_DRIVER_API_SYNCHRONOUS_N(void, updateStreams, backend::DriverApi*, driver)
DECL_DRIVER_API_SYNCHRONOUS_N(void, destroyFence, backend::FenceHandle, fh)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::FenceStatus, getFenceStatus, backend::FenceHandle, fh)
DECL_DRIVER_API_SYNCHRONOUS_N(bool, isTextureFormatSupported, backend::TextureFormat, format)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isTextureSwizzleSupported)
Expand All @@ -297,6 +298,8 @@ DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameBufferFetchMultiSampleSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameTimeSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isAutoDepthResolveSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isSRGBSwapChainSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isStereoSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isParallelShaderCompileSupported)
DECL_DRIVER_API_SYNCHRONOUS_0(uint8_t, getMaxDrawBuffers)
DECL_DRIVER_API_SYNCHRONOUS_0(size_t, getMaxUniformBufferSize)
DECL_DRIVER_API_SYNCHRONOUS_0(math::float2, getClipSpaceParams)
Expand Down
23 changes: 0 additions & 23 deletions filament/backend/src/CallbackHandler.cpp

This file was deleted.

22 changes: 14 additions & 8 deletions filament/backend/src/CompilerThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "CompilerThreadPool.h"

#include <utils/Systrace.h>

#include <memory>

namespace filament::backend {
Expand All @@ -32,16 +34,14 @@ CompilerThreadPool::~CompilerThreadPool() noexcept {
assert_invariant(mQueues[1].empty());
}

void CompilerThreadPool::init(uint32_t threadCount, JobSystem::Priority priority,
ThreadSetup&& threadSetup) noexcept {
void CompilerThreadPool::init(uint32_t threadCount,
ThreadSetup&& threadSetup, ThreadCleanup&& threadCleanup) noexcept {
auto setup = std::make_shared<ThreadSetup>(std::move(threadSetup));
auto cleanup = std::make_shared<ThreadCleanup>(std::move(threadCleanup));

for (size_t i = 0; i < threadCount; i++) {
mCompilerThreads.emplace_back([this, priority, setup]() {
// give the thread a name
JobSystem::setThreadName("CompilerThreadPool");
// run at a slightly lower priority than other filament threads
JobSystem::setThreadPriority(priority);
mCompilerThreads.emplace_back([this, setup, cleanup]() {
SYSTRACE_CONTEXT();

(*setup)();

Expand All @@ -53,7 +53,11 @@ void CompilerThreadPool::init(uint32_t threadCount, JobSystem::Priority priority
(!std::all_of( std::begin(mQueues), std::end(mQueues),
[](auto&& q) { return q.empty(); }));
});
if (!mExitRequested) {

SYSTRACE_VALUE32("CompilerThreadPool Jobs",
mQueues[0].size() + mQueues[1].size());

if (UTILS_LIKELY(!mExitRequested)) {
Job job;
// use the first queue that's not empty
auto& queue = [this]() -> auto& {
Expand All @@ -73,6 +77,8 @@ void CompilerThreadPool::init(uint32_t threadCount, JobSystem::Priority priority
job();
}
}

(*cleanup)();
});

}
Expand Down
16 changes: 9 additions & 7 deletions filament/backend/src/CompilerThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#include <backend/DriverEnums.h>

#include <utils/Invocable.h>
#include <utils/JobSystem.h>
#include <utils/Mutex.h>
#include <utils/Condition.h>

#include <array>
#include <atomic>
#include <deque>
#include <memory>
#include <thread>
#include <utility>
#include <vector>

Expand All @@ -45,18 +46,19 @@ class CompilerThreadPool {
~CompilerThreadPool() noexcept;
using Job = utils::Invocable<void()>;
using ThreadSetup = utils::Invocable<void()>;
void init(uint32_t threadCount, utils::JobSystem::Priority priority,
ThreadSetup&& threadSetup) noexcept;
using ThreadCleanup = utils::Invocable<void()>;
void init(uint32_t threadCount,
ThreadSetup&& threadSetup, ThreadCleanup&& threadCleanup) noexcept;
void terminate() noexcept;
void queue(CompilerPriorityQueue priorityQueue, program_token_t const& token, Job&& job);
Job dequeue(program_token_t const& token);

private:
using Queue = std::deque<std::pair<program_token_t, Job>>;
std::vector<std::thread> mCompilerThreads;
std::atomic_bool mExitRequested{false};
std::mutex mQueueLock;
std::condition_variable mQueueCondition;
bool mExitRequested{ false };
utils::Mutex mQueueLock;
utils::Condition mQueueCondition;
std::array<Queue, 2> mQueues;
// lock must be held for methods below
std::pair<Queue&, Queue::iterator> find(program_token_t const& token);
Expand Down
14 changes: 7 additions & 7 deletions filament/backend/src/DriverBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ class DriverBase : public Driver {

void purge() noexcept final;

// --------------------------------------------------------------------------------------------
// Privates
// --------------------------------------------------------------------------------------------

protected:
class CallbackDataDetails;

// Helpers...
struct CallbackData {
CallbackData(CallbackData const &) = delete;
Expand Down Expand Up @@ -202,6 +195,13 @@ class DriverBase : public Driver {

void scheduleCallback(CallbackHandler* handler, void* user, CallbackHandler::Callback callback);

// --------------------------------------------------------------------------------------------
// Privates
// --------------------------------------------------------------------------------------------

protected:
class CallbackDataDetails;

inline void scheduleDestroy(BufferDescriptor&& buffer) noexcept {
if (buffer.hasCallback()) {
scheduleDestroySlow(std::move(buffer));
Expand Down
Loading

0 comments on commit de310ed

Please sign in to comment.