Skip to content

Commit

Permalink
Merge branch 'rc/1.56.5' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
z3moon committed Jan 8, 2025
2 parents 4695e93 + b332bf3 commit d5bcc31
Show file tree
Hide file tree
Showing 37 changed files with 516 additions and 80 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.56.4'
implementation 'com.google.android.filament:filament-android:1.56.5'
}
```

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.56.4'
pod 'Filament', '~> 1.56.5'
```

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


## v1.56.4


Expand Down
3 changes: 2 additions & 1 deletion android/filament-android/src/main/cpp/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ using namespace filament;

extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Material_nBuilderBuild(JNIEnv *env, jclass,
jlong nativeEngine, jobject buffer_, jint size, jint shBandCount) {
jlong nativeEngine, jobject buffer_, jint size, jint shBandCount, jint shadowQuality) {
Engine* engine = (Engine*) nativeEngine;
AutoBuffer buffer(env, buffer_, size);
auto builder = Material::Builder();
if (shBandCount) {
builder.sphericalHarmonicsBandCount(shBandCount);
}
builder.shadowSamplingQuality((Material::Builder::ShadowSamplingQuality)shadowQuality);
Material* material = builder
.package(buffer.getData(), buffer.getSize())
.build(*engine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,18 @@ public Material(long nativeMaterial) {
}

public static class Builder {
public enum ShadowSamplingQuality {
/** 2x2 PCF */
HARD,
/** 3x3 gaussian filter */
LOW,
}

private Buffer mBuffer;
private int mSize;
private int mShBandCount = 0;
private ShadowSamplingQuality mShadowSamplingQuality = ShadowSamplingQuality.LOW;


/**
* Specifies the material data. The material data is a binary blob produced by
Expand Down Expand Up @@ -378,6 +387,18 @@ public Builder sphericalHarmonicsBandCount(@IntRange(from = 0) int shBandCount)
return this;
}

/**
* Set the quality of shadow sampling. This is only taken into account
* if this material is lit and in the surface domain.
* @param quality
* @return Reference to this Builder for chaining calls.
*/
@NonNull
public Builder shadowSamplingQuality(ShadowSamplingQuality quality) {
mShadowSamplingQuality = quality;
return this;
}

/**
* Creates and returns the Material object.
*
Expand All @@ -390,7 +411,7 @@ public Builder sphericalHarmonicsBandCount(@IntRange(from = 0) int shBandCount)
@NonNull
public Material build(@NonNull Engine engine) {
long nativeMaterial = nBuilderBuild(engine.getNativeObject(),
mBuffer, mSize, mShBandCount);
mBuffer, mSize, mShBandCount, mShadowSamplingQuality.ordinal());
if (nativeMaterial == 0) throw new IllegalStateException("Couldn't create Material");
return new Material(nativeMaterial);
}
Expand Down Expand Up @@ -1041,7 +1062,7 @@ void clearNativeObject() {
mNativeObject = 0;
}

private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size, int shBandCount);
private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size, int shBandCount, int shadowQuality);
private static native long nCreateInstance(long nativeMaterial);
private static native long nCreateInstanceWithName(long nativeMaterial, @NonNull String name);
private static native long nGetDefaultInstance(long nativeMaterial);
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.56.4
VERSION_NAME=1.56.5

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

Expand Down
2 changes: 1 addition & 1 deletion docs/Filament.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/remote/filament.js

Large diffs are not rendered by default.

Binary file modified docs/remote/filament.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/webgl/filament.js

Large diffs are not rendered by default.

Binary file modified docs/webgl/filament.wasm
Binary file not shown.
Binary file modified docs/webgl/triangle.filamat
Binary file not shown.
6 changes: 4 additions & 2 deletions filament/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ if (FILAMENT_SUPPORTS_VULKAN)
src/vulkan/VulkanUtility.cpp
src/vulkan/VulkanUtility.h
)
if (ANDROID OR LINUX OR WIN32)
list(APPEND SRCS src/vulkan/platform/VulkanPlatformAndroidLinuxWindows.cpp)
if (LINUX OR WIN32)
list(APPEND SRCS src/vulkan/platform/VulkanPlatformLinuxWindows.cpp)
elseif (APPLE OR IOS)
list(APPEND SRCS src/vulkan/platform/VulkanPlatformApple.mm)
elseif (ANDROID)
list(APPEND SRCS src/vulkan/platform/VulkanPlatformAndroid.cpp)
endif()
endif()

Expand Down
56 changes: 56 additions & 0 deletions filament/backend/include/backend/platforms/VulkanPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,64 @@ class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatf
*/
VkQueue getProtectedGraphicsQueue() const noexcept;

struct ExternalImageMetadata {
/**
* The width of the external image
*/
uint32_t width;

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

/**
* The layer count of the external image
*/
uint32_t layers;

/**
* The format of the external image
*/
VkFormat format;

/**
* An external buffer can be protected. This tells you if it is.
*/
bool isProtected;

/**
* The type of external format (opaque int) if used.
*/
uint64_t externalFormat;

/**
* Image usage
*/
VkImageUsageFlags usage;

/**
* Allocation size
*/
VkDeviceSize allocationSize;

/**
* Heap information
*/
uint32_t memoryTypeBits;
};
virtual ExternalImageMetadata getExternalImageMetadata(void* externalImage);

using ImageData = std::pair<VkImage, VkDeviceMemory>;
virtual ImageData createExternalImage(void* externalImage,
const ExternalImageMetadata& metadata);

private:
static ExtensionSet getSwapchainInstanceExtensions();
static ExternalImageMetadata getExternalImageMetadataImpl(void* externalImage,
VkDevice device);
static ImageData createExternalImageImpl(void* externalImage, VkDevice device,
const VkAllocationCallbacks* allocator, const ExternalImageMetadata& metadata);

// Platform dependent helper methods
using SurfaceBundle = std::tuple<VkSurfaceKHR, VkExtent2D>;
Expand Down
21 changes: 20 additions & 1 deletion filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,25 @@ void VulkanDriver::createTextureViewSwizzleR(Handle<HwTexture> th, Handle<HwText
}

void VulkanDriver::createTextureExternalImageR(Handle<HwTexture> th, backend::TextureFormat format,
uint32_t width, uint32_t height, backend::TextureUsage usage, void* image) {
uint32_t width, uint32_t height, backend::TextureUsage usage, void* externalImage) {
FVK_SYSTRACE_SCOPE();

const auto& metadata = mPlatform->getExternalImageMetadata(externalImage);
if (metadata.isProtected) {
usage |= backend::TextureUsage::PROTECTED;
}

assert_invariant(width == metadata.width);
assert_invariant(height == metadata.height);
assert_invariant(getVkFormat(format) == metadata.format);

const auto& data = mPlatform->createExternalImage(externalImage, metadata);

auto texture = resource_ptr<VulkanTexture>::make(&mResourceManager, th, mPlatform->getDevice(),
mAllocator, &mResourceManager, &mCommands, data.first, data.second, metadata.format,
1, metadata.width, metadata.height, usage, mStagePool);

texture.inc();
}

void VulkanDriver::createTextureExternalImagePlaneR(Handle<HwTexture> th,
Expand Down Expand Up @@ -1172,6 +1190,7 @@ TimerQueryResult VulkanDriver::getTimerQueryValue(Handle<HwTimerQuery> tqh, uint
}

void VulkanDriver::setExternalImage(Handle<HwTexture> th, void* image) {

}

void VulkanDriver::setExternalImagePlane(Handle<HwTexture> th, void* image, uint32_t plane) {
Expand Down
11 changes: 6 additions & 5 deletions filament/backend/src/vulkan/VulkanSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ void VulkanSwapChain::update() {
}
for (auto const color: bundle.colors) {
auto colorTexture = fvkmemory::resource_ptr<VulkanTexture>::construct(mResourceManager,
device, mAllocator, mResourceManager, mCommands, color, bundle.colorFormat, 1,
bundle.extent.width, bundle.extent.height, TextureUsage::COLOR_ATTACHMENT,
device, mAllocator, mResourceManager, mCommands, color, VK_NULL_HANDLE,
bundle.colorFormat, 1, bundle.extent.width, bundle.extent.height, colorUsage,
mStagePool);
mColors.push_back(colorTexture);
}

mDepth = fvkmemory::resource_ptr<VulkanTexture>::construct(mResourceManager, device, mAllocator,
mResourceManager, mCommands, bundle.depth, bundle.depthFormat, 1, bundle.extent.width,
bundle.extent.height, TextureUsage::DEPTH_ATTACHMENT, mStagePool);
mDepth = fvkmemory::resource_ptr<VulkanTexture>::construct(mResourceManager, device,
mAllocator, mResourceManager, mCommands, bundle.depth, VK_NULL_HANDLE,
bundle.depthFormat, 1, bundle.extent.width, bundle.extent.height, depthUsage,
mStagePool);

mExtent = bundle.extent;
}
Expand Down
5 changes: 3 additions & 2 deletions filament/backend/src/vulkan/VulkanTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ VulkanTextureState::VulkanTextureState(VkDevice device, VmaAllocator allocator,
// Constructor for internally passed VkImage
VulkanTexture::VulkanTexture(VkDevice device, VmaAllocator allocator,
fvkmemory::ResourceManager* resourceManager, VulkanCommands* commands, VkImage image,
VkFormat format, uint8_t samples, uint32_t width, uint32_t height, TextureUsage tusage,
VulkanStagePool& stagePool)
VkDeviceMemory memory, VkFormat format, uint8_t samples, uint32_t width,
uint32_t height, TextureUsage tusage, VulkanStagePool& stagePool)
: HwTexture(SamplerType::SAMPLER_2D, 1, samples, width, height, 1, TextureFormat::UNUSED,
tusage),
mState(fvkmemory::resource_ptr<VulkanTextureState>::construct(resourceManager, device,
allocator, commands, stagePool, format, imgutil::getViewType(SamplerType::SAMPLER_2D),
1, 1, getDefaultLayoutImpl(tusage), any(usage & TextureUsage::PROTECTED))) {
mState->mTextureImage = image;
mState->mTextureImageMemory = memory;
mPrimaryViewRange = mState->mFullViewRange;
}

Expand Down
4 changes: 2 additions & 2 deletions filament/backend/src/vulkan/VulkanTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ struct VulkanTexture : public HwTexture, fvkmemory::Resource {
// The texture will never destroy the given VkImage, but it does manages its subresources.
VulkanTexture(VkDevice device, VmaAllocator allocator,
fvkmemory::ResourceManager* resourceManager, VulkanCommands* commands, VkImage image,
VkFormat format, uint8_t samples, uint32_t width, uint32_t height, TextureUsage tusage,
VulkanStagePool& stagePool);
VkDeviceMemory memory, VkFormat format, uint8_t samples, uint32_t width, uint32_t height,
TextureUsage tusage, VulkanStagePool& stagePool);

// Constructor for creating a texture view for wrt specific mip range
VulkanTexture(VkDevice device, VkPhysicalDevice physicalDevice, VulkanContext const& context,
Expand Down
33 changes: 29 additions & 4 deletions filament/backend/src/vulkan/memory/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ struct Resource {
: resManager(nullptr),
id(HandleBase::nullid),
mCount(0),
restype(ResourceType::UNDEFINED_TYPE) {}
restype(ResourceType::UNDEFINED_TYPE),
mHandleConsideredDestroyed(false) {}

private:
inline void inc() noexcept {
Expand All @@ -80,6 +81,16 @@ struct Resource {
}
}

// To be able to detect use-after-free, we need a bit to signify if the handle should be
// consider destroyed (from Filament's perspective).
inline void setHandleConsiderDestroyed() noexcept {
mHandleConsideredDestroyed = true;
}

inline bool isHandleConsideredDestroyed() const {
return mHandleConsideredDestroyed;
}

template <typename T>
inline void init(HandleId id, ResourceManager* resManager) {
this->id = id;
Expand All @@ -92,7 +103,9 @@ struct Resource {
ResourceManager* resManager; // 8
HandleId id; // 4
uint32_t mCount : 24;
ResourceType restype : 6; // restype + mCount is 4 bytes.
ResourceType restype : 7;
bool mHandleConsideredDestroyed : 1; // restype + mCount + mHandleConsideredDestroyed
// is 4 bytes.

friend class ResourceManager;

Expand All @@ -105,7 +118,8 @@ struct ThreadSafeResource {
: resManager(nullptr),
id(HandleBase::nullid),
mCount(0),
restype(ResourceType::UNDEFINED_TYPE) {}
restype(ResourceType::UNDEFINED_TYPE),
mHandleConsideredDestroyed(false) {}

private:
inline void inc() noexcept {
Expand All @@ -118,6 +132,16 @@ struct ThreadSafeResource {
}
}

// To be able to detect use-after-free, we need a bit to signify if the handle should be
// consider destroyed (from Filament's perspective).
inline void setHandleConsiderDestroyed() noexcept {
mHandleConsideredDestroyed = true;
}

inline bool isHandleConsideredDestroyed() const {
return mHandleConsideredDestroyed;
}

template <typename T>
inline void init(HandleId id, ResourceManager* resManager) {
this->id = id;
Expand All @@ -130,7 +154,8 @@ struct ThreadSafeResource {
ResourceManager* resManager; // 8
HandleId id; // 4
std::atomic<uint32_t> mCount; // 4
ResourceType restype; // 1
ResourceType restype : 7;
bool mHandleConsideredDestroyed : 1; // restype + mHandleConsideredDestroyed is 1 byte

friend class ResourceManager;

Expand Down
7 changes: 7 additions & 0 deletions filament/backend/src/vulkan/memory/ResourcePointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "vulkan/memory/ResourceManager.h"

#include <backend/Handle.h>
#include <utils/compiler.h>

#include <utility>

Expand Down Expand Up @@ -59,6 +60,10 @@ struct resource_ptr {
static enabled_resource_ptr<B> cast(ResourceManager* resManager,
Handle<B> const& handle) noexcept {
D* ptr = resManager->handle_cast<D*, B>(handle);
FILAMENT_CHECK_PRECONDITION(!ptr->isHandleConsideredDestroyed())
<< "Handle id=" << ptr->id << " (" << getTypeStr(ptr->restype)
<< ") is being used after it has been freed";

return {ptr};
}

Expand Down Expand Up @@ -156,6 +161,8 @@ struct resource_ptr {
// only be used from VulkanDriver.
inline void dec() {
assert_invariant(mRef);
assert_invariant(!mRef->isHandleConsideredDestroyed());
mRef->setHandleConsiderDestroyed();
mRef->dec();
}

Expand Down
Loading

0 comments on commit d5bcc31

Please sign in to comment.