Skip to content

Commit

Permalink
Merge branch 'rc/1.57.2' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
poweifeng committed Mar 5, 2025
2 parents e96a302 + d6338fd commit be0b737
Show file tree
Hide file tree
Showing 61 changed files with 1,538 additions and 337 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ if (FILAMENT_SUPPORTS_METAL)
endif()

# Building filamat increases build times and isn't required for web, so turn it off by default.
if (NOT WEBGL)
if (NOT WEBGL AND NOT IOS)
option(FILAMENT_BUILD_FILAMAT "Build filamat and JNI buildings" ON)
else()
option(FILAMENT_BUILD_FILAMAT "Build filamat and JNI buildings" OFF)
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.57.1'
implementation 'com.google.android.filament:filament-android:1.57.2'
}
```

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:

```shell
pod 'Filament', '~> 1.57.1'
pod 'Filament', '~> 1.57.2'
```

## Documentation
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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.57.2

- Support including PlatformMetal.h in C++ files.

## v1.57.1


Expand Down
18 changes: 18 additions & 0 deletions android/filament-android/src/main/cpp/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,31 @@ Java_com_google_android_filament_Texture_nIsTextureFormatSupported(JNIEnv*, jcla
(Texture::InternalFormat) internalFormat);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Texture_nIsTextureFormatMipmappable(JNIEnv*, jclass,
jlong nativeEngine, jint internalFormat) {
Engine *engine = (Engine *) nativeEngine;
return (jboolean) Texture::isTextureFormatMipmappable(*engine,
(Texture::InternalFormat) internalFormat);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Texture_nIsTextureSwizzleSupported(JNIEnv*, jclass,
jlong nativeEngine) {
Engine *engine = (Engine *) nativeEngine;
return (jboolean) Texture::isTextureSwizzleSupported(*engine);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Texture_nValidatePixelFormatAndType(JNIEnv*, jclass,
jint internalFormat, jint pixelDataFormat, jint pixelDataType) {
return (jboolean) Texture::validatePixelFormatAndType(
(Texture::InternalFormat) internalFormat,
(Texture::Format) pixelDataFormat,
(Texture::Type) pixelDataType
);
}

// Texture::Builder...

extern "C" JNIEXPORT jlong JNICALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ public static boolean isTextureFormatSupported(@NonNull Engine engine,
return nIsTextureFormatSupported(engine.getNativeObject(), format.ordinal());
}

/**
* Checks whether a given texture format is supported for mipmapping in this {@link Engine}.
* This depends on the selected backend.
*
* @param engine {@link Engine} to test the {@link InternalFormat InternalFormat} against
* @param format format to check
* @return <code>true</code> if this format is supported for texturing.
*/
public static boolean isTextureFormatMipmappable(@NonNull Engine engine,
@NonNull InternalFormat format) {
return nIsTextureFormatMipmappable(engine.getNativeObject(), format.ordinal());
}

/**
* Checks whether texture swizzling is supported in this {@link Engine}.
* This depends on the selected backend.
Expand All @@ -664,6 +677,20 @@ public static boolean isTextureSwizzleSupported(@NonNull Engine engine) {
return nIsTextureSwizzleSupported(engine.getNativeObject());
}

/**
* Checks whether a given combination of texture format, pixel data and type is valid.
*
* @param internalFormat texture format
* @param pixelDataFormat pixel data format
* @param pixelDataType pixel data type
* @return <code>true</code> if the combination is valid
*/
public static boolean validatePixelFormatAndType(@NonNull InternalFormat internalFormat,
@NonNull Format pixelDataFormat, @NonNull Type pixelDataType) {
return nValidatePixelFormatAndType(internalFormat.ordinal(), pixelDataFormat.ordinal(),
pixelDataType.ordinal());
}

/**
* Use <code>Builder</code> to construct a <code>Texture</code> object instance.
*/
Expand Down Expand Up @@ -1260,8 +1287,12 @@ void clearNativeObject() {
}

private static native boolean nIsTextureFormatSupported(long nativeEngine, int internalFormat);
private static native boolean nIsTextureFormatMipmappable(long nativeEngine, int internalFormat);
private static native boolean nIsTextureSwizzleSupported(long nativeEngine);

private static native boolean nValidatePixelFormatAndType(int internalFormat, int pixelDataFormat,
int pixelDataType);

private static native long nCreateBuilder();
private static native void nDestroyBuilder(long nativeBuilder);

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.57.1
VERSION_NAME=1.57.2

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

Expand Down
3 changes: 2 additions & 1 deletion filament/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ if (APPLE OR LINUX)
spirv-cross-glsl)
endif()

if (APPLE)
# TODO: Disabling IOS test due to breakage wrt glslang update
if (APPLE AND NOT IOS)
# TODO: we should expand this test to Linux and other platforms.
list(APPEND BACKEND_TEST_SRC
test/test_RenderExternalImage.cpp)
Expand Down
7 changes: 7 additions & 0 deletions filament/backend/include/backend/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class UTILS_PUBLIC Platform {
* - PlatformEGLAndroid
*/
bool assertNativeWindowIsValid = false;

/**
* The action to take if a Drawable cannot be acquired. If true, the
* frame is aborted instead of panic. This is only supported for:
* - PlatformMetal
*/
bool metalDisablePanicOnDrawableFailure = false;
};

Platform() noexcept;
Expand Down
38 changes: 38 additions & 0 deletions filament/backend/include/backend/platforms/PlatformMetal-ObjC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TNT_FILAMENT_BACKEND_PRIVATE_PLATFORMMETAL_OBJC_H
#define TNT_FILAMENT_BACKEND_PRIVATE_PLATFORMMETAL_OBJC_H

#import <Metal/Metal.h>

namespace filament::backend {

struct MetalDevice {
id<MTLDevice> device;
};

struct MetalCommandQueue {
id<MTLCommandQueue> commandQueue;
};

struct MetalCommandBuffer {
id<MTLCommandBuffer> commandBuffer;
};

} // namespace filament::backend

#endif // TNT_FILAMENT_BACKEND_PRIVATE_PLATFORMMETAL_OBJC_H
16 changes: 11 additions & 5 deletions filament/backend/include/backend/platforms/PlatformMetal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
#include <backend/DriverEnums.h>
#include <backend/Platform.h>

#import <Metal/Metal.h>

namespace filament::backend {

struct PlatformMetalImpl;

// In order for this header to be compatible with Objective-C and C++, we use these wrappers around
// id<MTL*> objects.
// See PlatformMetal-Objc.h.
struct MetalDevice;
struct MetalCommandQueue;
struct MetalCommandBuffer;

class PlatformMetal final : public Platform {
public:
PlatformMetal();
Expand All @@ -41,21 +46,22 @@ class PlatformMetal final : public Platform {
* free to decide which one to use. On mobile systems with a single GPU, implementations should
* simply return the result of MTLCreateSystemDefaultDevice();
*/
virtual id<MTLDevice> createDevice() noexcept;
virtual void createDevice(MetalDevice& outDevice) noexcept;

/**
* Create a command submission queue on the Metal device object.
*
* @param device The device which was returned from createDevice()
*/
virtual id<MTLCommandQueue> createCommandQueue(id<MTLDevice> device) noexcept;
virtual void createCommandQueue(
MetalDevice& device, MetalCommandQueue& outCommandQueue) noexcept;

/**
* Obtain a MTLCommandBuffer enqueued on this Platform's MTLCommandQueue. The command buffer is
* guaranteed to execute before all subsequent command buffers created either by Filament, or
* further calls to this method.
*/
id<MTLCommandBuffer> createAndEnqueueCommandBuffer() noexcept;
void createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept;

/**
* The action to take if a Drawable cannot be acquired.
Expand Down
9 changes: 9 additions & 0 deletions filament/backend/include/backend/platforms/VulkanPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatf
// where the gpu only has one graphics queue. Then the client needs to ensure that no
// concurrent access can occur.
uint32_t graphicsQueueIndex = 0xFFFFFFFF;
bool debugUtilsSupported = false;
bool debugMarkersSupported = false;
bool multiviewSupported = false;
};

/**
Expand All @@ -88,6 +91,7 @@ class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatf
VkFormat colorFormat = VK_FORMAT_UNDEFINED;
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
VkExtent2D extent = {0, 0};
uint32_t layerCount = 1;
bool isProtected = false;
};

Expand Down Expand Up @@ -303,6 +307,11 @@ class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatf
*/
uint32_t height;

/**
* The layerCount of the external image
*/
uint32_t layerCount;

/**
* The layer count of the external image
*/
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/include/private/backend/HandleAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <tsl/robin_map.h>

#include <atomic>
#include <cstddef>
#include <exception>
#include <mutex>
Expand Down Expand Up @@ -426,7 +427,7 @@ class HandleAllocator : public DebugTag {
// Below is only used when running out of space in the HandleArena
mutable utils::Mutex mLock;
tsl::robin_map<HandleBase::HandleId, void*> mOverflowMap;
HandleBase::HandleId mId = 0;
std::atomic<HandleBase::HandleId> mId = 0;
bool mUseAfterFreeCheckDisabled = false;
};

Expand Down
25 changes: 22 additions & 3 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "MetalTimerQuery.h"

#include <backend/platforms/PlatformMetal.h>
#include <backend/platforms/PlatformMetal-ObjC.h>

#include <CoreVideo/CVMetalTexture.h>
#include <CoreVideo/CVPixelBuffer.h>
Expand Down Expand Up @@ -120,8 +121,11 @@
TrackedMetalBuffer::setPlatform(platform);
ScopedAllocationTimer::setPlatform(platform);

mContext->device = mPlatform.createDevice();
assert_invariant(mContext->device);
MetalDevice device;
device.device = nil;
mPlatform.createDevice(device);
mContext->device = device.device;
FILAMENT_CHECK_POSTCONDITION(mContext->device) << "Could not obtain Metal device.";

mContext->emptyBuffer = [mContext->device newBufferWithLength:16
options:MTLResourceStorageModePrivate];
Expand Down Expand Up @@ -186,7 +190,13 @@
[mContext->device.name containsString:@"Apple A8 GPU"] ||
[mContext->device.name containsString:@"Apple A7 GPU"];

mContext->commandQueue = mPlatform.createCommandQueue(mContext->device);
MetalCommandQueue commandQueue;
commandQueue.commandQueue = nil;
mPlatform.createCommandQueue(device, commandQueue);
FILAMENT_CHECK_POSTCONDITION(commandQueue.commandQueue)
<< "Could not create Metal command queue.";

mContext->commandQueue = commandQueue.commandQueue;
mContext->pipelineStateCache.setDevice(mContext->device);
mContext->depthStencilStateCache.setDevice(mContext->device);
mContext->samplerStateCache.setDevice(mContext->device);
Expand Down Expand Up @@ -1398,6 +1408,9 @@

void MetalDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,
backend::PushConstantVariant value) {
if (UTILS_UNLIKELY(mContext->currentRenderPassAbandoned)) {
return;
}
FILAMENT_CHECK_PRECONDITION(isInRenderPass(mContext))
<< "setPushConstant must be called inside a render pass.";
assert_invariant(static_cast<size_t>(stage) < mContext->currentPushConstants.size());
Expand Down Expand Up @@ -1705,6 +1718,9 @@
}

void MetalDriver::bindPipeline(PipelineState const& ps) {
if (UTILS_UNLIKELY(mContext->currentRenderPassAbandoned)) {
return;
}
FILAMENT_CHECK_PRECONDITION(mContext->currentRenderPassEncoder != nullptr)
<< "bindPipeline() without a valid command encoder.";
DEBUG_LOG("bindPipeline(ps = { program = %d }))\n", ps.program.getId());
Expand Down Expand Up @@ -1860,6 +1876,9 @@
}

void MetalDriver::bindRenderPrimitive(Handle<HwRenderPrimitive> rph) {
if (UTILS_UNLIKELY(mContext->currentRenderPassAbandoned)) {
return;
}
FILAMENT_CHECK_PRECONDITION(mContext->currentRenderPassEncoder != nullptr)
<< "bindRenderPrimitive() without a valid command encoder.";

Expand Down
Loading

0 comments on commit be0b737

Please sign in to comment.