Skip to content

Commit

Permalink
Merge branch 'rc/1.51.3' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
z3moon committed Apr 8, 2024
2 parents d0eb56f + de1edbd commit b89a017
Show file tree
Hide file tree
Showing 34 changed files with 322 additions and 72 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.51.2'
implementation 'com.google.android.filament:filament-android:1.51.3'
}
```

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.51.2'
pod 'Filament', '~> 1.51.3'
```

### Snapshots
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.51.3


## v1.51.2

- engine: Add experimental APIs `Engine::builder::paused()` and `Engine::setPaused()`
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.51.2
VERSION_NAME=1.51.3

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

Expand Down
33 changes: 32 additions & 1 deletion docs/Materials.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@
: `string`

Value
: Any of `opaque`, `transparent`, `fade`, `add`, `masked`, `multiply`, `screen`. Defaults to `opaque`.
: Any of `opaque`, `transparent`, `fade`, `add`, `masked`, `multiply`, `screen`, `custom`. Defaults to `opaque`.

Description
: Defines how/if the rendered object is blended with the content of the render target.
Expand All @@ -1420,6 +1420,7 @@
of the material's output defines whether a fragment is discarded or not. Additionally,
ALPHA_TO_COVERAGE is enabled for non-translucent views. See the maskThreshold section for more
information.
- **Custom**: blending is enabled. But the blending function is user specified. See `blendFunction`.

!!! Note
When `blending` is set to `masked`, alpha to coverage is automatically enabled for the material.
Expand All @@ -1432,6 +1433,36 @@
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Blending and transparency: blendFunction

Type
: `object`

Fields
: `srcRGB`, `srcA`, `dstRGB`, `dstA`

Description
: - *srcRGB*: source function applied to the RGB channels
- *srcA*: source function applied to the alpha channel
- *srcRGB*: destination function applied to the RGB channels
- *srcRGB*: destination function applied to the alpha channel
The values possible for each functions are one of `zero`, `one`, `srcColor`, `oneMinusSrcColor`,
`dstColor`, `oneMinusDstColor`, `srcAlpha`, `oneMinusSrcAlpha`, `dstAlpha`,
`oneMinusDstAlpha`, `srcAlphaSaturate`

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JSON
material {
blending : custom,
blendFunction :
{
srcRGB: one,
srcA: one,
dstRGB: oneMinusSrcColor,
dstA: oneMinusSrcAlpha
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Blending and transparency: postLightingBlending

Type
Expand Down
4 changes: 2 additions & 2 deletions filament/backend/include/private/backend/CommandStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct CommandType<void (Driver::*)(ARGS...)> {

public:
template<typename M, typename D>
static inline void execute(M&& method, D&& driver, CommandBase* base, intptr_t* next) noexcept {
static inline void execute(M&& method, D&& driver, CommandBase* base, intptr_t* next) {
Command* self = static_cast<Command*>(base);
*next = align(sizeof(Command));
#if DEBUG_COMMAND_STREAM
Expand Down Expand Up @@ -168,7 +168,7 @@ struct CommandType<void (Driver::*)(ARGS...)> {

class CustomCommand : public CommandBase {
std::function<void()> mCommand;
static void execute(Driver&, CommandBase* base, intptr_t* next) noexcept;
static void execute(Driver&, CommandBase* base, intptr_t* next);
public:
inline CustomCommand(CustomCommand&& rhs) = default;
inline explicit CustomCommand(std::function<void()> cmd)
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/include/private/backend/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Driver {
// the fn function will execute a batch of driver commands
// this gives the driver a chance to wrap their execution in a meaningful manner
// the default implementation simply calls fn
virtual void execute(std::function<void(void)> const& fn) noexcept;
virtual void execute(std::function<void(void)> const& fn);

// This is called on debug build, or when enabled manually on the backend thread side.
virtual void debugCommandBegin(CommandStream* cmds,
Expand Down
10 changes: 5 additions & 5 deletions filament/backend/include/private/backend/HandleAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HandleAllocator {
*
*/
template<typename D, typename ... ARGS>
Handle<D> allocateAndConstruct(ARGS&& ... args) noexcept {
Handle<D> allocateAndConstruct(ARGS&& ... args) {
Handle<D> h{ allocateHandle<D>() };
D* addr = handle_cast<D*>(h);
new(addr) D(std::forward<ARGS>(args)...);
Expand Down Expand Up @@ -97,7 +97,7 @@ class HandleAllocator {
*/
template<typename D, typename B, typename ... ARGS>
typename std::enable_if_t<std::is_base_of_v<B, D>, D>*
destroyAndConstruct(Handle<B> const& handle, ARGS&& ... args) noexcept {
destroyAndConstruct(Handle<B> const& handle, ARGS&& ... args) {
assert_invariant(handle);
D* addr = handle_cast<D*>(const_cast<Handle<B>&>(handle));
assert_invariant(addr);
Expand Down Expand Up @@ -163,7 +163,7 @@ class HandleAllocator {
inline typename std::enable_if_t<
std::is_pointer_v<Dp> &&
std::is_base_of_v<B, typename std::remove_pointer_t<Dp>>, Dp>
handle_cast(Handle<B>& handle) noexcept {
handle_cast(Handle<B>& handle) {
assert_invariant(handle);
auto [p, tag] = handleToPointer(handle.getId());

Expand All @@ -185,7 +185,7 @@ class HandleAllocator {
inline typename std::enable_if_t<
std::is_pointer_v<Dp> &&
std::is_base_of_v<B, typename std::remove_pointer_t<Dp>>, Dp>
handle_cast(Handle<B> const& handle) noexcept {
handle_cast(Handle<B> const& handle) {
return handle_cast<Dp>(const_cast<Handle<B>&>(handle));
}

Expand Down Expand Up @@ -317,7 +317,7 @@ class HandleAllocator {
return (id & HANDLE_HEAP_FLAG) == 0u;
}

HandleBase::HandleId allocateHandleSlow(size_t size) noexcept;
HandleBase::HandleId allocateHandleSlow(size_t size);
void deallocateHandleSlow(HandleBase::HandleId id, size_t size) noexcept;

// We inline this because it's just 4 instructions in the fast case
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/CommandStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void CommandType<void (Driver::*)(ARGS...)>::Command<METHOD>::log() noexcept {

// ------------------------------------------------------------------------------------------------

void CustomCommand::execute(Driver&, CommandBase* base, intptr_t* next) noexcept {
void CustomCommand::execute(Driver&, CommandBase* base, intptr_t* next) {
*next = CustomCommand::align(sizeof(CustomCommand));
static_cast<CustomCommand*>(base)->mCommand();
static_cast<CustomCommand*>(base)->~CustomCommand();
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ size_t Driver::getElementTypeSize(ElementType type) noexcept {

Driver::~Driver() noexcept = default;

void Driver::execute(std::function<void(void)> const& fn) noexcept {
void Driver::execute(std::function<void(void)> const& fn) {
fn();
}

Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/HandleAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void* HandleAllocator<P0, P1, P2>::handleToPointerSlow(HandleBase::HandleId id)
}

template <size_t P0, size_t P1, size_t P2>
HandleBase::HandleId HandleAllocator<P0, P1, P2>::allocateHandleSlow(size_t size) noexcept {
HandleBase::HandleId HandleAllocator<P0, P1, P2>::allocateHandleSlow(size_t size) {
void* p = ::malloc(size);
std::unique_lock lock(mLock);

Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@
return;
}

ASSERT_PRECONDITION(bool(functions), "Attempting to bind an invalid Metal program.");
functions.validate();

auto [fragment, vertex] = functions.getRasterFunctions();

Expand Down
18 changes: 10 additions & 8 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,19 @@ void OpenGLDriver::createTextureR(Handle<HwTexture> th, SamplerType target, uint
GLenum internalFormat = getInternalFormat(format);
assert_invariant(internalFormat);

if (UTILS_UNLIKELY(usage & TextureUsage::PROTECTED)) {
if (any(usage & TextureUsage::PROTECTED)) {
// renderbuffers don't have a protected mode, so we need to use a texture
// because protected textures are only supported on GLES 3.2, MSAA will be available.
usage |= TextureUsage::SAMPLEABLE;
} else if (any(usage & TextureUsage::UPLOADABLE)) {
// if we have the uploadable flag, we also need to use a texture
usage |= TextureUsage::SAMPLEABLE;
} else if (target != SamplerType::SAMPLER_2D) {
// renderbuffers can only be 2D
usage |= TextureUsage::SAMPLEABLE;
} else if (levels > 1) {
// renderbuffers can't have mip levels
usage |= TextureUsage::SAMPLEABLE;
}

auto& gl = mContext;
Expand Down Expand Up @@ -803,13 +812,6 @@ void OpenGLDriver::createTextureR(Handle<HwTexture> th, SamplerType target, uint
textureStorage(t, w, h, depth, bool(usage & TextureUsage::PROTECTED));
}
} else {
assert_invariant(any(usage & (
TextureUsage::COLOR_ATTACHMENT |
TextureUsage::DEPTH_ATTACHMENT |
TextureUsage::STENCIL_ATTACHMENT)));
assert_invariant(levels == 1);
assert_invariant(target == SamplerType::SAMPLER_2D);
assert_invariant(none(usage & TextureUsage::PROTECTED));
t->gl.internalFormat = internalFormat;
t->gl.target = GL_RENDERBUFFER;
glGenRenderbuffers(1, &t->gl.id);
Expand Down
8 changes: 4 additions & 4 deletions filament/backend/src/opengl/OpenGLDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ class OpenGLDriver final : public DriverBase {
HandleAllocatorGL mHandleAllocator;

template<typename D, typename ... ARGS>
Handle<D> initHandle(ARGS&& ... args) noexcept {
Handle<D> initHandle(ARGS&& ... args) {
return mHandleAllocator.allocateAndConstruct<D>(std::forward<ARGS>(args) ...);
}

template<typename D, typename B, typename ... ARGS>
typename std::enable_if<std::is_base_of<B, D>::value, D>::type*
construct(Handle<B> const& handle, ARGS&& ... args) noexcept {
construct(Handle<B> const& handle, ARGS&& ... args) {
return mHandleAllocator.destroyAndConstruct<D, B>(handle, std::forward<ARGS>(args) ...);
}

Expand All @@ -288,15 +288,15 @@ class OpenGLDriver final : public DriverBase {
typename std::enable_if_t<
std::is_pointer_v<Dp> &&
std::is_base_of_v<B, typename std::remove_pointer_t<Dp>>, Dp>
handle_cast(Handle<B>& handle) noexcept {
handle_cast(Handle<B>& handle) {
return mHandleAllocator.handle_cast<Dp, B>(handle);
}

template<typename Dp, typename B>
inline typename std::enable_if_t<
std::is_pointer_v<Dp> &&
std::is_base_of_v<B, typename std::remove_pointer_t<Dp>>, Dp>
handle_cast(Handle<B> const& handle) noexcept {
handle_cast(Handle<B> const& handle) {
return mHandleAllocator.handle_cast<Dp, B>(handle);
}

Expand Down
10 changes: 10 additions & 0 deletions filament/src/MaterialParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ bool MaterialParser::getBlendingMode(BlendingMode* value) const noexcept {
return mImpl.getFromSimpleChunk(ChunkType::MaterialBlendingMode, reinterpret_cast<uint8_t*>(value));
}

bool MaterialParser::getCustomBlendFunction(std::array<BlendFunction, 4>* value) const noexcept {
uint32_t blendFunctions = 0;
bool const result = mImpl.getFromSimpleChunk(ChunkType::MaterialBlendFunction, &blendFunctions);
(*value)[0] = BlendFunction((blendFunctions >> 24) & 0xFF);
(*value)[1] = BlendFunction((blendFunctions >> 16) & 0xFF);
(*value)[2] = BlendFunction((blendFunctions >> 8) & 0xFF);
(*value)[3] = BlendFunction((blendFunctions >> 0) & 0xFF);
return result;
}

bool MaterialParser::getMaskThreshold(float* value) const noexcept {
return mImpl.getFromSimpleChunk(ChunkType::MaterialMaskThreshold, value);
}
Expand Down
1 change: 1 addition & 0 deletions filament/src/MaterialParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class MaterialParser {

bool getShading(Shading*) const noexcept;
bool getBlendingMode(BlendingMode*) const noexcept;
bool getCustomBlendFunction(std::array<backend::BlendFunction, 4>*) const noexcept;
bool getMaskThreshold(float*) const noexcept;
bool getAlphaToCoverageSet(bool*) const noexcept;
bool getAlphaToCoverage(bool*) const noexcept;
Expand Down
5 changes: 1 addition & 4 deletions filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,8 @@ PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph
.levels = uint8_t(levelCount),
.format = isES2 ? TextureFormat::DEPTH24 : TextureFormat::DEPTH32F });

// workaround: since we have levels, this implies SAMPLEABLE (because of the gl
// backend, which implements non-sampleables with renderbuffers, which don't have levels).
// (should the gl driver revert to textures, in that case?)
data.depth = builder.write(data.depth,
FrameGraphTexture::Usage::DEPTH_ATTACHMENT | FrameGraphTexture::Usage::SAMPLEABLE);
FrameGraphTexture::Usage::DEPTH_ATTACHMENT);

if (config.picking) {
data.picking = builder.createTexture("Picking Buffer", {
Expand Down
27 changes: 19 additions & 8 deletions filament/src/RendererUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,35 @@

#include "RendererUtils.h"

#include "PostProcessManager.h"

#include "details/Engine.h"
#include "details/View.h"

#include "fg/FrameGraph.h"
#include "fg/FrameGraphId.h"
#include "fg/FrameGraphResources.h"
#include "fg/FrameGraphTexture.h"

#include <filament/Options.h>
#include <filament/RenderableManager.h>
#include <filament/Viewport.h>

#include <backend/DriverEnums.h>
#include <backend/Handle.h>
#include <backend/PixelBufferDescriptor.h>

#include <utils/BitmaskEnum.h>
#include <utils/compiler.h>
#include <utils/debug.h>
#include <utils/Panic.h>

#include <algorithm>
#include <utility>

#include <stddef.h>
#include <stdint.h>

namespace filament {

using namespace backend;
Expand Down Expand Up @@ -153,16 +171,9 @@ FrameGraphId<FrameGraphTexture> RendererUtils::colorPass(
data.depth = builder.read(data.depth, FrameGraphTexture::Usage::DEPTH_ATTACHMENT);

data.color = builder.write(data.color, FrameGraphTexture::Usage::COLOR_ATTACHMENT);
data.depth = builder.write(data.depth, FrameGraphTexture::Usage::DEPTH_ATTACHMENT);
if (engine.getConfig().stereoscopicType == StereoscopicType::MULTIVIEW) {
// Add sampleable usage flag for depth in multiview rendering, othewise it's
// treated as renderbuffer in the backend and crashed.
data.depth = builder.write(data.depth,
FrameGraphTexture::Usage::DEPTH_ATTACHMENT |
FrameGraphTexture::Usage::SAMPLEABLE);
layerCount = engine.getConfig().stereoscopicEyeCount;
} else {
data.depth = builder.write(data.depth,
FrameGraphTexture::Usage::DEPTH_ATTACHMENT);
}

/*
Expand Down
14 changes: 8 additions & 6 deletions filament/src/details/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,8 @@ FMaterial::FMaterial(FEngine& engine, const Material::Builder& builder)
parser->getMaskThreshold(&mMaskThreshold);
}

// The fade blending mode only affects shading. For proper sorting we need to
// treat this blending mode as a regular transparent blending operation.
if (UTILS_UNLIKELY(mBlendingMode == BlendingMode::FADE)) {
mRenderBlendingMode = BlendingMode::TRANSPARENT;
} else {
mRenderBlendingMode = mBlendingMode;
if (mBlendingMode == BlendingMode::CUSTOM) {
parser->getCustomBlendFunction(&mCustomBlendFunctions);
}

if (mShading == Shading::UNLIT) {
Expand Down Expand Up @@ -381,6 +377,12 @@ FMaterial::FMaterial(FEngine& engine, const Material::Builder& builder)
mRasterState.blendFunctionDstAlpha = BlendFunction::ONE_MINUS_SRC_COLOR;
mRasterState.depthWrite = false;
break;
case BlendingMode::CUSTOM:
mRasterState.blendFunctionSrcRGB = mCustomBlendFunctions[0];
mRasterState.blendFunctionSrcAlpha = mCustomBlendFunctions[1];
mRasterState.blendFunctionDstRGB = mCustomBlendFunctions[2];
mRasterState.blendFunctionDstAlpha = mCustomBlendFunctions[3];
mRasterState.depthWrite = false;
}

bool depthWriteSet = false;
Expand Down
Loading

0 comments on commit b89a017

Please sign in to comment.