Skip to content

Commit 904ff1c

Browse files
committed
header updates after updating filament
1 parent 9009c35 commit 904ff1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1410
-312
lines changed

package/android/libs/filament/include/backend/DriverEnums.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
#include <utils/BitmaskEnum.h>
2323
#include <utils/unwindows.h> // Because we define ERROR in the FenceStatus enum.
2424

25+
#include <backend/Platform.h>
2526
#include <backend/PresentCallable.h>
2627

28+
#include <utils/Invocable.h>
2729
#include <utils/ostream.h>
2830

2931
#include <math/vec4.h>
3032

3133
#include <array> // FIXME: STL headers are not allowed in public headers
3234
#include <type_traits> // FIXME: STL headers are not allowed in public headers
35+
#include <variant> // FIXME: STL headers are not allowed in public headers
3336

3437
#include <stddef.h>
3538
#include <stdint.h>
@@ -90,12 +93,15 @@ static constexpr uint64_t SWAP_CHAIN_HAS_STENCIL_BUFFER = SWAP_CHAIN_CON
9093
*/
9194
static constexpr uint64_t SWAP_CHAIN_CONFIG_PROTECTED_CONTENT = 0x40;
9295

93-
9496
static constexpr size_t MAX_VERTEX_ATTRIBUTE_COUNT = 16; // This is guaranteed by OpenGL ES.
9597
static constexpr size_t MAX_SAMPLER_COUNT = 62; // Maximum needed at feature level 3.
9698
static constexpr size_t MAX_VERTEX_BUFFER_COUNT = 16; // Max number of bound buffer objects.
9799
static constexpr size_t MAX_SSBO_COUNT = 4; // This is guaranteed by OpenGL ES.
98100

101+
static constexpr size_t MAX_PUSH_CONSTANT_COUNT = 32; // Vulkan 1.1 spec allows for 128-byte
102+
// of push constant (we assume 4-byte
103+
// types).
104+
99105
// Per feature level caps
100106
// Use (int)FeatureLevel to index this array
101107
static constexpr struct {
@@ -112,7 +118,7 @@ static_assert(MAX_VERTEX_BUFFER_COUNT <= MAX_VERTEX_ATTRIBUTE_COUNT,
112118
"The number of buffer objects that can be attached to a VertexBuffer must be "
113119
"less than or equal to the maximum number of vertex attributes.");
114120

115-
static constexpr size_t CONFIG_UNIFORM_BINDING_COUNT = 10; // This is guaranteed by OpenGL ES.
121+
static constexpr size_t CONFIG_UNIFORM_BINDING_COUNT = 9; // This is guaranteed by OpenGL ES.
116122
static constexpr size_t CONFIG_SAMPLER_BINDING_COUNT = 4; // This is guaranteed by OpenGL ES.
117123

118124
/**
@@ -331,7 +337,7 @@ enum class UniformType : uint8_t {
331337
/**
332338
* Supported constant parameter types
333339
*/
334-
enum class ConstantType : uint8_t {
340+
enum class ConstantType : uint8_t {
335341
INT,
336342
FLOAT,
337343
BOOL
@@ -686,7 +692,7 @@ enum class TextureUsage : uint16_t {
686692
SUBPASS_INPUT = 0x0020, //!< Texture can be used as a subpass input
687693
BLIT_SRC = 0x0040, //!< Texture can be used the source of a blit()
688694
BLIT_DST = 0x0080, //!< Texture can be used the destination of a blit()
689-
PROTECTED = 0x0100, //!< Texture can be used the destination of a blit()
695+
PROTECTED = 0x0100, //!< Texture can be used for protected content
690696
DEFAULT = UPLOADABLE | SAMPLEABLE //!< Default texture usage
691697
};
692698

@@ -1218,13 +1224,15 @@ struct StencilState {
12181224
uint8_t padding = 0;
12191225
};
12201226

1227+
using PushConstantVariant = std::variant<int32_t, float, bool>;
1228+
12211229
static_assert(sizeof(StencilState::StencilOperations) == 5u,
12221230
"StencilOperations size not what was intended");
12231231

12241232
static_assert(sizeof(StencilState) == 12u,
12251233
"StencilState size not what was intended");
12261234

1227-
using FrameScheduledCallback = void(*)(PresentCallable callable, void* user);
1235+
using FrameScheduledCallback = utils::Invocable<void(backend::PresentCallable)>;
12281236

12291237
enum class Workaround : uint16_t {
12301238
// The EASU pass must split because shader compiler flattens early-exit branch
@@ -1243,13 +1251,7 @@ enum class Workaround : uint16_t {
12431251
POWER_VR_SHADER_WORKAROUNDS,
12441252
};
12451253

1246-
//! The type of technique for stereoscopic rendering
1247-
enum class StereoscopicType : uint8_t {
1248-
// Stereoscopic rendering is performed using instanced rendering technique.
1249-
INSTANCED,
1250-
// Stereoscopic rendering is performed using the multiview feature from the graphics backend.
1251-
MULTIVIEW,
1252-
};
1254+
using StereoscopicType = backend::Platform::StereoscopicType;
12531255

12541256
} // namespace filament::backend
12551257

package/android/libs/filament/include/backend/Handle.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ class HandleBase {
7575
HandleBase(HandleBase const& rhs) noexcept = default;
7676
HandleBase& operator=(HandleBase const& rhs) noexcept = default;
7777

78+
HandleBase(HandleBase&& rhs) noexcept
79+
: object(rhs.object) {
80+
rhs.object = nullid;
81+
}
82+
83+
HandleBase& operator=(HandleBase&& rhs) noexcept {
84+
if (this != &rhs) {
85+
object = rhs.object;
86+
rhs.object = nullid;
87+
}
88+
return *this;
89+
}
90+
7891
private:
7992
HandleId object;
8093
};
@@ -89,8 +102,10 @@ struct Handle : public HandleBase {
89102
Handle() noexcept = default;
90103

91104
Handle(Handle const& rhs) noexcept = default;
105+
Handle(Handle&& rhs) noexcept = default;
92106

93107
Handle& operator=(Handle const& rhs) noexcept = default;
108+
Handle& operator=(Handle&& rhs) noexcept = default;
94109

95110
explicit Handle(HandleId id) noexcept : HandleBase(id) { }
96111

package/android/libs/filament/include/backend/Platform.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ class UTILS_PUBLIC Platform {
4141
struct Fence {};
4242
struct Stream {};
4343

44+
/**
45+
* The type of technique for stereoscopic rendering. (Note that the materials used will need to
46+
* be compatible with the chosen technique.)
47+
*/
48+
enum class StereoscopicType : uint8_t {
49+
/**
50+
* No stereoscopic rendering
51+
*/
52+
NONE,
53+
/**
54+
* Stereoscopic rendering is performed using instanced rendering technique.
55+
*/
56+
INSTANCED,
57+
/**
58+
* Stereoscopic rendering is performed using the multiview feature from the graphics
59+
* backend.
60+
*/
61+
MULTIVIEW,
62+
};
63+
4464
struct DriverConfig {
4565
/**
4666
* Size of handle arena in bytes. Setting to 0 indicates default value is to be used.
@@ -65,6 +85,17 @@ class UTILS_PUBLIC Platform {
6585
* Disable backend handles use-after-free checks.
6686
*/
6787
bool disableHandleUseAfterFreeCheck = false;
88+
89+
/**
90+
* Force GLES2 context if supported, or pretend the context is ES2. Only meaningful on
91+
* GLES 3.x backends.
92+
*/
93+
bool forceGLES2Context = false;
94+
95+
/**
96+
* Sets the technique for stereoscopic rendering.
97+
*/
98+
StereoscopicType stereoscopicType = StereoscopicType::NONE;
6899
};
69100

70101
Platform() noexcept;

package/android/libs/filament/include/backend/PresentCallable.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace filament::backend {
4848
* and optional user data:
4949
*
5050
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51-
* swapChain->setFrameScheduledCallback(myFrameScheduledCallback, nullptr);
51+
* swapChain->setFrameScheduledCallback(nullptr, myFrameScheduledCallback);
5252
* if (renderer->beginFrame(swapChain)) {
5353
* renderer->render(view);
5454
* renderer->endFrame();
@@ -58,8 +58,6 @@ namespace filament::backend {
5858
* @remark Only Filament's Metal backend supports PresentCallables and frame callbacks. Other
5959
* backends ignore the callback (which will never be called) and proceed normally.
6060
*
61-
* @remark The SwapChain::FrameScheduledCallback is called on an arbitrary thread.
62-
*
6361
* Applications *must* call each PresentCallable they receive. Each PresentCallable represents a
6462
* frame that is waiting to be presented. If an application fails to call a PresentCallable, a
6563
* memory leak could occur. To "cancel" the presentation of a frame, pass false to the

package/android/libs/filament/include/backend/Program.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class Program {
8484
// null terminating character.
8585
Program& shader(ShaderStage shader, void const* data, size_t size);
8686

87+
// sets the language of the shader sources provided with shader() (defaults to ESSL3)
88+
Program& shaderLanguage(ShaderLanguage shaderLanguage);
89+
8790
// Note: This is only needed for GLES3.0 backends, because the layout(binding=) syntax is
8891
// not permitted in glsl. The backend needs a way to associate a uniform block
8992
// to a binding point.
@@ -114,6 +117,14 @@ class Program {
114117
Program& specializationConstants(
115118
utils::FixedCapacityVector<SpecializationConstant> specConstants) noexcept;
116119

120+
struct PushConstant {
121+
utils::CString name;
122+
ConstantType type;
123+
};
124+
125+
Program& pushConstants(ShaderStage stage,
126+
utils::FixedCapacityVector<PushConstant> constants) noexcept;
127+
117128
Program& cacheId(uint64_t cacheId) noexcept;
118129

119130
Program& multiview(bool multiview) noexcept;
@@ -136,13 +147,24 @@ class Program {
136147
utils::CString const& getName() const noexcept { return mName; }
137148
utils::CString& getName() noexcept { return mName; }
138149

150+
auto const& getShaderLanguage() const { return mShaderLanguage; }
151+
139152
utils::FixedCapacityVector<SpecializationConstant> const& getSpecializationConstants() const noexcept {
140153
return mSpecializationConstants;
141154
}
142155
utils::FixedCapacityVector<SpecializationConstant>& getSpecializationConstants() noexcept {
143156
return mSpecializationConstants;
144157
}
145158

159+
utils::FixedCapacityVector<PushConstant> const& getPushConstants(
160+
ShaderStage stage) const noexcept {
161+
return mPushConstants[static_cast<uint8_t>(stage)];
162+
}
163+
164+
utils::FixedCapacityVector<PushConstant>& getPushConstants(ShaderStage stage) noexcept {
165+
return mPushConstants[static_cast<uint8_t>(stage)];
166+
}
167+
146168
uint64_t getCacheId() const noexcept { return mCacheId; }
147169

148170
bool isMultiview() const noexcept { return mMultiview; }
@@ -155,10 +177,12 @@ class Program {
155177
UniformBlockInfo mUniformBlocks = {};
156178
SamplerGroupInfo mSamplerGroups = {};
157179
ShaderSource mShadersSource;
180+
ShaderLanguage mShaderLanguage = ShaderLanguage::ESSL3;
158181
utils::CString mName;
159182
uint64_t mCacheId{};
160183
utils::Invocable<utils::io::ostream&(utils::io::ostream& out)> mLogger;
161184
utils::FixedCapacityVector<SpecializationConstant> mSpecializationConstants;
185+
std::array<utils::FixedCapacityVector<PushConstant>, SHADER_TYPE_COUNT> mPushConstants;
162186
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> mAttributes;
163187
std::array<UniformInfo, Program::UNIFORM_BINDING_COUNT> mBindingUniformInfo;
164188
CompilerPriorityQueue mPriorityQueue = CompilerPriorityQueue::HIGH;

package/android/libs/filament/include/backend/TargetBufferInfo.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,36 @@ namespace filament::backend {
2929
//! \privatesection
3030

3131
struct TargetBufferInfo {
32+
// note: the parameters of this constructor are not in the order of this structure's fields
33+
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level, uint16_t layer, uint8_t baseViewIndex) noexcept
34+
: handle(handle), baseViewIndex(baseViewIndex), level(level), layer(layer) {
35+
}
36+
37+
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level, uint16_t layer) noexcept
38+
: handle(handle), level(level), layer(layer) {
39+
}
40+
41+
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level) noexcept
42+
: handle(handle), level(level) {
43+
}
44+
45+
TargetBufferInfo(Handle<HwTexture> handle) noexcept // NOLINT(*-explicit-constructor)
46+
: handle(handle) {
47+
}
48+
49+
TargetBufferInfo() noexcept = default;
50+
3251
// texture to be used as render target
3352
Handle<HwTexture> handle;
3453

35-
// starting layer index for multiview. This value is only used when the `layerCount` for the
54+
// Starting layer index for multiview. This value is only used when the `layerCount` for the
3655
// render target is greater than 1.
3756
uint8_t baseViewIndex = 0;
3857

3958
// level to be used
4059
uint8_t level = 0;
4160

42-
// for cubemaps and 3D textures. See TextureCubemapFace for the face->layer mapping
61+
// For cubemaps and 3D textures. See TextureCubemapFace for the face->layer mapping
4362
uint16_t layer = 0;
4463
};
4564

@@ -64,7 +83,7 @@ class MRT {
6483

6584
MRT() noexcept = default;
6685

67-
MRT(TargetBufferInfo const& color) noexcept // NOLINT(hicpp-explicit-conversions)
86+
MRT(TargetBufferInfo const& color) noexcept // NOLINT(hicpp-explicit-conversions, *-explicit-constructor)
6887
: mInfos{ color } {
6988
}
7089

@@ -84,7 +103,7 @@ class MRT {
84103

85104
// this is here for backward compatibility
86105
MRT(Handle<HwTexture> handle, uint8_t level, uint16_t layer) noexcept
87-
: mInfos{{ handle, 0, level, layer }} {
106+
: mInfos{{ handle, level, layer, 0 }} {
88107
}
89108
};
90109

package/android/libs/filament/include/backend/platforms/OpenGLPlatform.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ class OpenGLPlatform : public Platform {
140140
*/
141141
virtual uint32_t getDefaultFramebufferObject() noexcept;
142142

143+
/**
144+
* Called by the backend when a frame starts.
145+
* @param steady_clock_ns vsync time point on the monotonic clock
146+
* @param refreshIntervalNs refresh interval in nanosecond
147+
* @param frameId a frame id
148+
*/
149+
virtual void beginFrame(
150+
int64_t monotonic_clock_ns,
151+
int64_t refreshIntervalNs,
152+
uint32_t frameId) noexcept;
153+
154+
/**
155+
* Called by the backend when a frame ends.
156+
* @param frameId the frame id used in beginFrame
157+
*/
158+
virtual void endFrame(
159+
uint32_t frameId) noexcept;
143160

144161
/**
145162
* Type of contexts available
@@ -191,6 +208,12 @@ class OpenGLPlatform : public Platform {
191208
utils::Invocable<void()> preContextChange,
192209
utils::Invocable<void(size_t index)> postContextChange) noexcept;
193210

211+
/**
212+
* Called by the backend just before calling commit()
213+
* @see commit()
214+
*/
215+
virtual void preCommit() noexcept;
216+
194217
/**
195218
* Called by the driver once the current frame finishes drawing. Typically, this should present
196219
* the drawSwapChain. This is for example where `eglMakeCurrent()` would be called.

package/android/libs/filament/include/backend/platforms/PlatformEGLAndroid.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <backend/platforms/OpenGLPlatform.h>
2323
#include <backend/platforms/PlatformEGL.h>
2424

25+
#include <utils/android/PerformanceHintManager.h>
26+
27+
#include <chrono>
28+
2529
#include <stddef.h>
2630
#include <stdint.h>
2731

@@ -58,6 +62,13 @@ class PlatformEGLAndroid : public PlatformEGL {
5862

5963
void terminate() noexcept override;
6064

65+
void beginFrame(
66+
int64_t monotonic_clock_ns,
67+
int64_t refreshIntervalNs,
68+
uint32_t frameId) noexcept override;
69+
70+
void preCommit() noexcept override;
71+
6172
/**
6273
* Set the presentation time using `eglPresentationTimeANDROID`
6374
* @param presentationTimeInNanosecond
@@ -79,8 +90,18 @@ class PlatformEGLAndroid : public PlatformEGL {
7990
AcquiredImage transformAcquiredImage(AcquiredImage source) noexcept override;
8091

8192
private:
93+
struct InitializeJvmForPerformanceManagerIfNeeded {
94+
InitializeJvmForPerformanceManagerIfNeeded();
95+
};
96+
8297
int mOSVersion;
8398
ExternalStreamManagerAndroid& mExternalStreamManager;
99+
InitializeJvmForPerformanceManagerIfNeeded const mInitializeJvmForPerformanceManagerIfNeeded;
100+
utils::PerformanceHintManager mPerformanceHintManager;
101+
utils::PerformanceHintManager::Session mPerformanceHintSession;
102+
103+
using clock = std::chrono::high_resolution_clock;
104+
clock::time_point mStartTimeOfActualWork;
84105
};
85106

86107
} // namespace filament::backend

0 commit comments

Comments
 (0)