Skip to content

Commit

Permalink
Merge branch 'rc/1.10.4' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado committed Jun 21, 2021
2 parents 0bf02b7 + 1fd5d9d commit e8877ff
Show file tree
Hide file tree
Showing 54 changed files with 486 additions and 481 deletions.
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ same version that our continuous builds use.

```
cd <your chosen parent folder for the emscripten SDK>
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.17.zip > emsdk.zip
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.23.zip > emsdk.zip
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
python ./emsdk.py install latest
python ./emsdk.py activate latest
Expand Down
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.10.3'
implementation 'com.google.android.filament:filament-android:1.10.4'
}
```

Expand Down Expand Up @@ -63,7 +63,7 @@ A much smaller alternative to `filamat-android` that can only generate OpenGL sh
iOS projects can use CocoaPods to install the latest release:

```
pod 'Filament', '~> 1.10.3'
pod 'Filament', '~> 1.10.4'
```

### Snapshots
Expand Down
9 changes: 8 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
This file contains one line summaries of commits that are worthy of mentioning in release notes.
A new header is inserted each time a *tag* is created.

## v1.10.4 (currently main branch)
## v1.10.5 (currently main branch)

## v1.10.4

- engine: improvements to internal job system.
- Vulkan: performance improvements on Mali.
- gltfio: improvements to load time for large models.
- WebGL: remove bogus stride argument, fix `BindingType` TypeScript definition.

## v1.10.3

Expand Down
10 changes: 5 additions & 5 deletions android/filament-utils-android/src/main/cpp/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
jclass ktxloaderClass = env->FindClass("com/google/android/filament/utils/KTXLoader");
if (ktxloaderClass == nullptr) return JNI_ERR;
static const JNINativeMethod ktxMethods[] = {
{"nCreateKTXTexture", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateKTXTexture)},
{"nCreateIndirectLight", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateIndirectLight)},
{"nCreateSkybox", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateSkybox)},
{"nGetSphericalHarmonics", "(Ljava/nio/Buffer;I[F)Z", reinterpret_cast<void*>(nGetSphericalHarmonics)},
{(char*)"nCreateKTXTexture", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateKTXTexture)},
{(char*)"nCreateIndirectLight", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateIndirectLight)},
{(char*)"nCreateSkybox", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateSkybox)},
{(char*)"nGetSphericalHarmonics", (char*)"(Ljava/nio/Buffer;I[F)Z", reinterpret_cast<void*>(nGetSphericalHarmonics)},
};
rc = env->RegisterNatives(ktxloaderClass, ktxMethods, sizeof(ktxMethods) / sizeof(JNINativeMethod));
if (rc != JNI_OK) return rc;
Expand All @@ -114,7 +114,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
jclass hdrloaderClass = env->FindClass("com/google/android/filament/utils/HDRLoader");
if (hdrloaderClass == nullptr) return JNI_ERR;
static const JNINativeMethod hdrMethods[] = {
{"nCreateHDRTexture", "(JLjava/nio/Buffer;II)J", reinterpret_cast<void*>(nCreateHDRTexture)},
{(char*)"nCreateHDRTexture", (char*)"(JLjava/nio/Buffer;II)J", reinterpret_cast<void*>(nCreateHDRTexture)},
};
rc = env->RegisterNatives(hdrloaderClass, hdrMethods, sizeof(hdrMethods) / sizeof(JNINativeMethod));
if (rc != JNI_OK) return rc;
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.10.3
VERSION_NAME=1.10.4

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.view.*
import android.view.GestureDetector
import android.widget.TextView
import android.widget.Toast
import com.google.android.filament.Fence
import com.google.android.filament.IndirectLight
import com.google.android.filament.Skybox
import com.google.android.filament.utils.*
Expand Down Expand Up @@ -59,6 +60,8 @@ class MainActivity : Activity() {
private var statusText: String? = null
private var latestDownload: String? = null
private val automation = AutomationEngine()
private var loadStartTime = 0L
private var loadStartFence: Fence? = null

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -80,7 +83,7 @@ class MainActivity : Activity() {
true
}

createRenderables()
createDefaultRenderables()
createIndirectLight()

setStatusText("To load a new model, go to the above URL on your host machine.")
Expand All @@ -101,7 +104,7 @@ class MainActivity : Activity() {
remoteServer = RemoteServer(8082)
}

private fun createRenderables() {
private fun createDefaultRenderables() {
val buffer = assets.open("models/scene.gltf").use { input ->
val bytes = ByteArray(input.available())
input.read(bytes)
Expand Down Expand Up @@ -155,6 +158,8 @@ class MainActivity : Activity() {
modelViewer.destroyModel()
modelViewer.loadModelGlb(message.buffer)
modelViewer.transformToUnitCube()
loadStartTime = System.nanoTime()
loadStartFence = modelViewer.engine.createFence()
}
}

Expand Down Expand Up @@ -273,6 +278,8 @@ class MainActivity : Activity() {
}
}
modelViewer.transformToUnitCube()
loadStartTime = System.nanoTime()
loadStartFence = modelViewer.engine.createFence()
}
}

Expand Down Expand Up @@ -321,6 +328,16 @@ class MainActivity : Activity() {
override fun doFrame(frameTimeNanos: Long) {
choreographer.postFrameCallback(this)

loadStartFence?.let {
if (it.wait(Fence.Mode.FLUSH, 0) == Fence.FenceStatus.CONDITION_SATISFIED) {
val end = System.nanoTime()
val total = (end - loadStartTime) / 1_000_000
Log.i(TAG, "The Filament backend took ${total} ms to load the model geometry.")
modelViewer.engine.destroyFence(it)
loadStartFence = null
}
}

modelViewer.animator?.apply {
if (animationCount > 0) {
val elapsedTimeSeconds = (frameTimeNanos - startTime).toDouble() / 1_000_000_000
Expand Down Expand Up @@ -354,11 +371,11 @@ class MainActivity : Activity() {
}
}

// Just for testing purposes, this releases the model and reloads it.
// Just for testing purposes, this releases the current model and reloads the default model.
inner class DoubleTapListener : GestureDetector.SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent?): Boolean {
modelViewer.destroyModel()
createRenderables()
createDefaultRenderables()
return super.onDoubleTap(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/web/ci-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export PATH="$PWD:$PATH"
# npm install -g typescript

# Install emscripten.
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.17.zip > emsdk.zip
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.23.zip > emsdk.zip
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
./emsdk install latest
./emsdk activate latest
Expand Down
4 changes: 4 additions & 0 deletions filament/backend/include/private/backend/BackendUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#include <stddef.h>

#ifndef FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB
# define FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB 1
#endif

namespace filament {
namespace backend {

Expand Down
18 changes: 6 additions & 12 deletions filament/backend/src/CommandBufferQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <utils/Panic.h>
#include <utils/debug.h>

#include "private/backend/BackendUtils.h"
#include "private/backend/CommandStream.h"

using namespace utils;
Expand All @@ -40,13 +41,13 @@ CommandBufferQueue::~CommandBufferQueue() {
}

void CommandBufferQueue::requestExit() {
std::unique_lock<utils::Mutex> lock(mLock);
std::lock_guard<utils::Mutex> lock(mLock);
mExitRequested = EXIT_REQUESTED;
mCondition.notify_one();
}

bool CommandBufferQueue::isExitRequested() const {
std::unique_lock<utils::Mutex> lock(mLock);
std::lock_guard<utils::Mutex> lock(mLock);
ASSERT_PRECONDITION( mExitRequested == 0 || mExitRequested == EXIT_REQUESTED,
"mExitRequested is corrupted (value = 0x%08x)!", mExitRequested);
return (bool)mExitRequested;
Expand Down Expand Up @@ -99,14 +100,8 @@ void CommandBufferQueue::flush() noexcept {
}
#endif

if (UTILS_LIKELY(mFreeSpace >= requiredSize)) {
// ideally (and usually) we don't have to wait, this is the common case, so special case
// the unlock-before-notify, optimization.
lock.unlock();
mCondition.notify_one();
} else {
// unfortunately, there is not enough space left, we'll have to wait.
mCondition.notify_one(); // too bad there isn't a notify-and-wait
mCondition.notify_one();
if (UTILS_LIKELY(mFreeSpace < requiredSize)) {
SYSTRACE_NAME("waiting: CircularBuffer::flush()");
mCondition.wait(lock, [this, requiredSize]() -> bool {
return mFreeSpace >= requiredSize;
Expand All @@ -130,9 +125,8 @@ std::vector<CommandBufferQueue::Slice> CommandBufferQueue::waitForCommands() con
}

void CommandBufferQueue::releaseBuffer(CommandBufferQueue::Slice const& buffer) {
std::unique_lock<utils::Mutex> lock(mLock);
std::lock_guard<utils::Mutex> lock(mLock);
mFreeSpace += uintptr_t(buffer.end) - uintptr_t(buffer.begin);
lock.unlock();
mCondition.notify_one();
}

Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/metal/MetalHandles.mm
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ static MTLPixelFormat decidePixelFormat(id<MTLDevice> device, TextureFormat form
[event notifyListener:context.eventListener atValue:value block:^(id <MTLSharedEvent> o,
uint64_t value) {
if (auto s = weakState.lock()) {
std::unique_lock<std::mutex> guard(s->mutex);
std::lock_guard<std::mutex> guard(s->mutex);
s->status = FenceStatus::CONDITION_SATISFIED;
s->cv.notify_all();
}
Expand Down
3 changes: 1 addition & 2 deletions filament/backend/src/opengl/TimerQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,15 @@ TimerQueryFence::~TimerQueryFence() {
if (mThread.joinable()) {
std::unique_lock<utils::Mutex> lock(mLock);
mExitRequested = true;
lock.unlock();
mCondition.notify_one();
lock.unlock();
mThread.join();
}
}

void TimerQueryFence::enqueue(TimerQueryFence::Job&& job) {
std::unique_lock<utils::Mutex> lock(mLock);
mQueue.push_back(std::forward<Job>(job));
lock.unlock();
mCondition.notify_one();
}

Expand Down
7 changes: 4 additions & 3 deletions filament/backend/src/vulkan/VulkanBlitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void VulkanBlitter::blitFast(VkImageAspectFlags aspect, VkFilter filter,
transitionImageLayout(cmdbuffer, transitionHelper({
.image = src.image,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = getTextureLayout(src.texture->usage),
.newLayout = mContext.getTextureLayout(src.texture->usage),
.subresources = srcRange
}));
} else if (!mContext.currentSurface->headlessQueue) {
Expand All @@ -184,8 +184,9 @@ void VulkanBlitter::blitFast(VkImageAspectFlags aspect, VkFilter filter,

// Determine the desired texture layout for the destination while ensuring that the default
// render target is supported, which has no associated texture.
const VkImageLayout desiredLayout = dst.texture ? getTextureLayout(dst.texture->usage) :
getSwapChainAttachment(mContext).layout;
const VkImageLayout desiredLayout = dst.texture ?
mContext.getTextureLayout(dst.texture->usage) :
mContext.currentSurface->getColor().layout;

transitionImageLayout(cmdbuffer, transitionHelper({
.image = dst.image,
Expand Down
10 changes: 3 additions & 7 deletions filament/backend/src/vulkan/VulkanBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ namespace filament {
namespace backend {

VulkanBuffer::VulkanBuffer(VulkanContext& context, VulkanStagePool& stagePool,
VulkanDisposer& disposer, VulkanDisposer::Key key, VkBufferUsageFlags usage,
uint32_t numBytes) : mContext(context), mStagePool(stagePool), mDisposer(disposer),
mDisposerKey(key) {
VkBufferUsageFlags usage, uint32_t numBytes) : mContext(context), mStagePool(stagePool) {
// Create the VkBuffer.
VkBufferCreateInfo bufferInfo {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = numBytes,
.usage = usage | VK_BUFFER_USAGE_TRANSFER_DST_BIT
};
VmaAllocationCreateInfo allocInfo {
.usage = VMA_MEMORY_USAGE_GPU_ONLY
};

VmaAllocationCreateInfo allocInfo { .pool = context.vmaPoolGPU };
vmaCreateBuffer(context.allocator, &bufferInfo, &allocInfo, &mGpuBuffer, &mGpuMemory, nullptr);
}

Expand All @@ -56,7 +53,6 @@ void VulkanBuffer::loadFromCpu(const void* cpuData, uint32_t byteOffset, uint32_

VkBufferCopy region { .size = numBytes };
vkCmdCopyBuffer(cmdbuffer, stage->buffer, mGpuBuffer, 1, &region);
mDisposer.acquire(mDisposerKey);

// Firstly, ensure that the copy finishes before the next draw call.
// Secondly, in case the user decides to upload another chunk (without ever using the first one)
Expand Down
6 changes: 2 additions & 4 deletions filament/backend/src/vulkan/VulkanBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ namespace backend {
// Encapsulates a Vulkan buffer, its attached DeviceMemory and a staging area.
class VulkanBuffer {
public:
VulkanBuffer(VulkanContext& context, VulkanStagePool& stagePool, VulkanDisposer& disposer,
VulkanDisposer::Key mDisposerKey, VkBufferUsageFlags usage, uint32_t numBytes);
VulkanBuffer(VulkanContext& context, VulkanStagePool& stagePool, VkBufferUsageFlags usage,
uint32_t numBytes);
~VulkanBuffer();
void loadFromCpu(const void* cpuData, uint32_t byteOffset, uint32_t numBytes);
VkBuffer getGpuBuffer() const { return mGpuBuffer; }
private:
VulkanContext& mContext;
VulkanStagePool& mStagePool;
VulkanDisposer& mDisposer;
VulkanDisposer::Key mDisposerKey;
VmaAllocation mGpuMemory = VK_NULL_HANDLE;
VkBuffer mGpuBuffer = VK_NULL_HANDLE;
};
Expand Down
7 changes: 6 additions & 1 deletion filament/backend/src/vulkan/VulkanCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ VulkanCommandBuffer const& VulkanCommands::get() {
// It occurs only when Filament invokes commit() or endFrame() a large number of times without
// presenting the swap chain or waiting on a fence.
while (mAvailableCount == 0) {
#if VK_REPORT_STALLS
slog.i << "VulkanCommands has stalled. "
<< "If this occurs frequently, consider increasing VK_MAX_COMMAND_BUFFERS."
<< io::endl;
#endif
wait();
gc();
}
Expand Down Expand Up @@ -190,8 +195,8 @@ bool VulkanCommands::flush() {
std::unique_lock<utils::Mutex> lock(cmdfence->mutex);
cmdfence->status.store(VK_NOT_READY);
UTILS_UNUSED_IN_RELEASE VkResult result = vkQueueSubmit(mQueue, 1, &submitInfo, cmdfence->fence);
lock.unlock();
cmdfence->condition.notify_all();
lock.unlock();

assert_invariant(result == VK_SUCCESS);

Expand Down
27 changes: 22 additions & 5 deletions filament/backend/src/vulkan/VulkanConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define VK_ENABLE_VALIDATION 1
#endif

#define VK_REPORT_STALLS 0

// All vkCreate* functions take an optional allocator. For now we select the default allocator by
// passing in a null pointer, and we highlight the argument by using the VKALLOC constant.
constexpr struct VkAllocationCallbacks* VKALLOC = nullptr;
Expand All @@ -45,12 +47,27 @@ constexpr struct VkAllocationCallbacks* VKALLOC = nullptr;
constexpr static const int VK_REQUIRED_VERSION_MAJOR = 1;
constexpr static const int VK_REQUIRED_VERSION_MINOR = 0;

// We choose a capacity of 3 because this matches the needs of triple-buffering.
constexpr static const int VK_MAX_COMMAND_BUFFERS = 3;
// Controls the block size for the VkBuffer pools that we use for vertex buffers.
constexpr static const uint64_t VMA_BUFFER_POOL_BLOCK_SIZE_IN_MB = 128;

// Maximum number of VkCommandBuffer handles managed simultaneously by VulkanCommands.
//
// This includes the "current" command buffer that is being written into, as well as any command
// buffers that have been submitted but have not yet finished rendering. Note that Filament can
// issue multiple commit calls in a single frame, and that we use a triple buffered swap chain on
// some platforms.
constexpr static const int VK_MAX_COMMAND_BUFFERS = 10;

// Maximum number of command buffer flush events that can occur before an unused pipeline is removed
// from the cache. If this number is low, VkPipeline construction will occur frequently, which can
// Number of command buffer submissions that should occur before an unused pipeline is removed
// from the cache.
//
// If this number is low, VkPipeline construction will occur frequently, which can
// be extremely slow. If this number is high, the memory footprint will be large.
constexpr static const int VK_MAX_PIPELINE_AGE = 5;
constexpr static const int VK_MAX_PIPELINE_AGE = 10;

// VulkanPipelineCache does not track which command buffers contain references to which pipelines,
// instead it simply waits for at least VK_MAX_COMMAND_BUFFERS submissions to occur before
// destroying any unused pipeline object.
static_assert(VK_MAX_PIPELINE_AGE >= VK_MAX_COMMAND_BUFFERS);

#endif
Loading

0 comments on commit e8877ff

Please sign in to comment.