update Filament headers to v1.58.0
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_ACQUIREDIMAGE_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <math/mat3.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_BUFFEROBJECTSTREAMDESCRIPTOR_H
|
||||
#define TNT_FILAMENT_BACKEND_BUFFEROBJECTSTREAMDESCRIPTOR_H
|
||||
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* The type of association between a buffer object and a stream.
|
||||
*/
|
||||
enum class BufferObjectStreamAssociationType { TRANSFORM_MATRIX };
|
||||
|
||||
/**
|
||||
* A descriptor for a buffer object to stream association.
|
||||
*/
|
||||
class UTILS_PUBLIC BufferObjectStreamDescriptor {
|
||||
public:
|
||||
//! creates an empty descriptor
|
||||
BufferObjectStreamDescriptor() noexcept = default;
|
||||
|
||||
BufferObjectStreamDescriptor(const BufferObjectStreamDescriptor& rhs) = delete;
|
||||
BufferObjectStreamDescriptor& operator=(const BufferObjectStreamDescriptor& rhs) = delete;
|
||||
|
||||
BufferObjectStreamDescriptor(BufferObjectStreamDescriptor&& rhs) = default;
|
||||
BufferObjectStreamDescriptor& operator=(BufferObjectStreamDescriptor&& rhs) = default;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
struct StreamDataDescriptor {
|
||||
uint32_t offset;
|
||||
Handle<HwStream> stream;
|
||||
BufferObjectStreamAssociationType associationType;
|
||||
};
|
||||
|
||||
std::vector<StreamDataDescriptor> mStreams;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_BUFFEROBJECTSTREAMDESCRIPTOR_H
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include <backend/DriverApiForward.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
@@ -98,4 +100,8 @@ private:
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::DescriptorSetOffsetArray& rhs);
|
||||
#endif
|
||||
|
||||
#endif //TNT_FILAMENT_BACKEND_COMMANDSTREAMVECTOR_H
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <array> // FIXME: STL headers are not allowed in public headers
|
||||
#include <type_traits> // FIXME: STL headers are not allowed in public headers
|
||||
#include <variant> // FIXME: STL headers are not allowed in public headers
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -144,7 +144,8 @@ enum class Backend : uint8_t {
|
||||
OPENGL = 1, //!< Selects the OpenGL/ES driver (default on Android)
|
||||
VULKAN = 2, //!< Selects the Vulkan driver if the platform supports it (default on Linux/Windows)
|
||||
METAL = 3, //!< Selects the Metal driver if the platform supports it (default on MacOS/iOS).
|
||||
NOOP = 4, //!< Selects the no-op driver for testing purposes.
|
||||
WEBGPU = 4, //!< Selects the Webgpu driver if the platform supports webgpu.
|
||||
NOOP = 5, //!< Selects the no-op driver for testing purposes.
|
||||
};
|
||||
|
||||
enum class TimerQueryResult : int8_t {
|
||||
@@ -163,6 +164,8 @@ static constexpr const char* backendToString(Backend backend) {
|
||||
return "Vulkan";
|
||||
case Backend::METAL:
|
||||
return "Metal";
|
||||
case Backend::WEBGPU:
|
||||
return "WebGPU";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
@@ -440,18 +443,6 @@ enum class SamplerType : uint8_t {
|
||||
SAMPLER_CUBEMAP_ARRAY, //!< Cube map array texture (feature level 2)
|
||||
};
|
||||
|
||||
inline const char* stringify(SamplerType samplerType) {
|
||||
switch (samplerType) {
|
||||
case SamplerType::SAMPLER_2D: return "SAMPLER_2D";
|
||||
case SamplerType::SAMPLER_2D_ARRAY: return "SAMPLER_2D_ARRAY";
|
||||
case SamplerType::SAMPLER_CUBEMAP: return "SAMPLER_CUBEMAP";
|
||||
case SamplerType::SAMPLER_EXTERNAL: return "SAMPLER_EXTERNAL";
|
||||
case SamplerType::SAMPLER_3D: return "SAMPLER_3D";
|
||||
case SamplerType::SAMPLER_CUBEMAP_ARRAY: return "SAMPLER_CUBEMAP_ARRAY";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
//! Subpass type
|
||||
enum class SubpassType : uint8_t {
|
||||
SUBPASS_INPUT
|
||||
@@ -781,23 +772,6 @@ enum class TextureUsage : uint16_t {
|
||||
ALL_ATTACHMENTS = COLOR_ATTACHMENT | DEPTH_ATTACHMENT | STENCIL_ATTACHMENT | SUBPASS_INPUT, //!< Mask of all attachments
|
||||
};
|
||||
|
||||
inline const char* stringify(TextureUsage usage) {
|
||||
switch (usage) {
|
||||
case TextureUsage::NONE: return "NONE";
|
||||
case TextureUsage::COLOR_ATTACHMENT: return "COLOR_ATTACHMENT";
|
||||
case TextureUsage::DEPTH_ATTACHMENT: return "DEPTH_ATTACHMENT";
|
||||
case TextureUsage::STENCIL_ATTACHMENT: return "STENCIL_ATTACHMENT";
|
||||
case TextureUsage::UPLOADABLE: return "UPLOADABLE";
|
||||
case TextureUsage::SAMPLEABLE: return "SAMPLEABLE";
|
||||
case TextureUsage::SUBPASS_INPUT: return "SUBPASS_INPUT";
|
||||
case TextureUsage::BLIT_SRC: return "BLIT_SRC";
|
||||
case TextureUsage::BLIT_DST: return "BLIT_DST";
|
||||
case TextureUsage::PROTECTED: return "PROTECTED";
|
||||
case TextureUsage::DEFAULT: return "DEFAULT";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
//! Texture swizzle
|
||||
enum class TextureSwizzle : uint8_t {
|
||||
SUBSTITUTE_ZERO,
|
||||
@@ -1331,7 +1305,7 @@ enum class Workaround : uint16_t {
|
||||
// for some uniform arrays, it's needed to do an initialization to avoid crash on adreno gpu
|
||||
ADRENO_UNIFORM_ARRAY_CRASH,
|
||||
// Workaround a Metal pipeline compilation error with the message:
|
||||
// "Could not statically determine the target of a texture". See light_indirect.fs
|
||||
// "Could not statically determine the target of a texture". See surface_light_indirect.fs
|
||||
METAL_STATIC_TEXTURE_TARGET_ERROR,
|
||||
// Adreno drivers sometimes aren't able to blit into a layer of a texture array.
|
||||
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
||||
@@ -1381,12 +1355,16 @@ utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::Textu
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::TextureUsage usage);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::BufferObjectBinding binding);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::TextureSwizzle swizzle);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStage shaderStage);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStageFlags stageFlags);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::CompilerPriorityQueue compilerPriorityQueue);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::PushConstantVariant pushConstantVariant);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::AttributeArray& type);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::DescriptorSetLayout& dsl);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::PolygonOffset& po);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::RasterState& rs);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::RenderPassParams& b);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::Viewport& v);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStageFlags stageFlags);
|
||||
#endif
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_DRIVERENUMS_H
|
||||
|
||||
@@ -35,7 +35,6 @@ struct HwIndexBuffer;
|
||||
struct HwProgram;
|
||||
struct HwRenderPrimitive;
|
||||
struct HwRenderTarget;
|
||||
struct HwSamplerGroup;
|
||||
struct HwStream;
|
||||
struct HwSwapChain;
|
||||
struct HwTexture;
|
||||
@@ -131,7 +130,7 @@ struct Handle : public HandleBase {
|
||||
bool operator>=(const Handle& rhs) const noexcept { return getId() >= rhs.getId(); }
|
||||
|
||||
// type-safe Handle cast
|
||||
template<typename B, typename = std::enable_if_t<std::is_base_of<T, B>::value> >
|
||||
template<typename B, typename = std::enable_if_t<std::is_base_of_v<T, B>> >
|
||||
Handle(Handle<B> const& base) noexcept : HandleBase(base) { } // NOLINT(hicpp-explicit-conversions,google-explicit-constructor)
|
||||
|
||||
private:
|
||||
@@ -149,7 +148,6 @@ using IndexBufferHandle = Handle<HwIndexBuffer>;
|
||||
using ProgramHandle = Handle<HwProgram>;
|
||||
using RenderPrimitiveHandle = Handle<HwRenderPrimitive>;
|
||||
using RenderTargetHandle = Handle<HwRenderTarget>;
|
||||
using SamplerGroupHandle = Handle<HwSamplerGroup>;
|
||||
using StreamHandle = Handle<HwStream>;
|
||||
using SwapChainHandle = Handle<HwSwapChain>;
|
||||
using TextureHandle = Handle<HwTexture>;
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Driver;
|
||||
@@ -41,6 +43,50 @@ public:
|
||||
struct Fence {};
|
||||
struct Stream {};
|
||||
|
||||
class ExternalImageHandle;
|
||||
|
||||
class ExternalImage {
|
||||
friend class ExternalImageHandle;
|
||||
std::atomic_uint32_t mRefCount{0};
|
||||
protected:
|
||||
virtual ~ExternalImage() noexcept;
|
||||
};
|
||||
|
||||
class ExternalImageHandle {
|
||||
ExternalImage* UTILS_NULLABLE mTarget = nullptr;
|
||||
static void incref(ExternalImage* UTILS_NULLABLE p) noexcept;
|
||||
static void decref(ExternalImage* UTILS_NULLABLE p) noexcept;
|
||||
|
||||
public:
|
||||
ExternalImageHandle() noexcept;
|
||||
~ExternalImageHandle() noexcept;
|
||||
explicit ExternalImageHandle(ExternalImage* UTILS_NULLABLE p) noexcept;
|
||||
ExternalImageHandle(ExternalImageHandle const& rhs) noexcept;
|
||||
ExternalImageHandle(ExternalImageHandle&& rhs) noexcept;
|
||||
ExternalImageHandle& operator=(ExternalImageHandle const& rhs) noexcept;
|
||||
ExternalImageHandle& operator=(ExternalImageHandle&& rhs) noexcept;
|
||||
|
||||
explicit operator bool() const noexcept { return mTarget != nullptr; }
|
||||
|
||||
ExternalImage* UTILS_NULLABLE get() noexcept { return mTarget; }
|
||||
ExternalImage const* UTILS_NULLABLE get() const noexcept { return mTarget; }
|
||||
|
||||
ExternalImage* UTILS_NULLABLE operator->() noexcept { return mTarget; }
|
||||
ExternalImage const* UTILS_NULLABLE operator->() const noexcept { return mTarget; }
|
||||
|
||||
ExternalImage& operator*() noexcept { return *mTarget; }
|
||||
ExternalImage const& operator*() const noexcept { return *mTarget; }
|
||||
|
||||
void clear() noexcept;
|
||||
void reset(ExternalImage* UTILS_NULLABLE p) noexcept;
|
||||
|
||||
private:
|
||||
friend utils::io::ostream& operator<<(utils::io::ostream& out,
|
||||
ExternalImageHandle const& handle);
|
||||
};
|
||||
|
||||
using ExternalImageHandleRef = ExternalImageHandle const&;
|
||||
|
||||
/**
|
||||
* The type of technique for stereoscopic rendering. (Note that the materials used will need to
|
||||
* be compatible with the chosen technique.)
|
||||
@@ -81,6 +127,11 @@ public:
|
||||
*/
|
||||
bool disableHandleUseAfterFreeCheck = false;
|
||||
|
||||
/**
|
||||
* Disable backend handles tags for heap allocated (fallback) handles
|
||||
*/
|
||||
bool disableHeapHandleTags = false;
|
||||
|
||||
/**
|
||||
* Force GLES2 context if supported, or pretend the context is ES2. Only meaningful on
|
||||
* GLES 3.x backends.
|
||||
@@ -123,7 +174,7 @@ public:
|
||||
*
|
||||
* @return nullptr on failure, or a pointer to the newly created driver.
|
||||
*/
|
||||
virtual backend::Driver* UTILS_NULLABLE createDriver(void* UTILS_NULLABLE sharedContext,
|
||||
virtual Driver* UTILS_NULLABLE createDriver(void* UTILS_NULLABLE sharedContext,
|
||||
const DriverConfig& driverConfig) noexcept = 0;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/CString.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <math/mat3.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
@@ -51,12 +53,23 @@ protected:
|
||||
~OpenGLPlatform() noexcept override;
|
||||
|
||||
public:
|
||||
|
||||
struct ExternalTexture {
|
||||
unsigned int target; // GLenum target
|
||||
unsigned int id; // GLuint id
|
||||
unsigned int target; // GLenum target
|
||||
unsigned int id; // GLuint id
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the OpenGL vendor string of the specified Driver instance.
|
||||
* @return The GL_VENDOR string
|
||||
*/
|
||||
static utils::CString getVendorString(Driver const* UTILS_NONNULL driver);
|
||||
|
||||
/**
|
||||
* Return the OpenGL vendor string of the specified Driver instance
|
||||
* @return The GL_RENDERER string
|
||||
*/
|
||||
static utils::CString getRendererString(Driver const* UTILS_NONNULL driver);
|
||||
|
||||
/**
|
||||
* Called by the driver to destroy the OpenGL context. This should clean up any windows
|
||||
* or buffers from initialization. This is for instance where `eglDestroyContext` would be
|
||||
@@ -307,6 +320,13 @@ public:
|
||||
virtual void updateTexImage(Stream* UTILS_NONNULL stream,
|
||||
int64_t* UTILS_NONNULL timestamp) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the transform matrix of the texture attached to the stream.
|
||||
* @param stream Stream to get the transform matrix from
|
||||
* @param uvTransform Output parameter: Transform matrix of the image bound to the texture. Returns identity if not supported.
|
||||
*/
|
||||
virtual math::mat3f getTransformMatrix(Stream* UTILS_NONNULL stream) noexcept;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// External Image support
|
||||
@@ -324,36 +344,45 @@ public:
|
||||
* Destroys an external texture handle and associated data.
|
||||
* @param texture a pointer to the handle to destroy.
|
||||
*/
|
||||
virtual void destroyExternalImage(ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
virtual void destroyExternalImageTexture(ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
|
||||
// called on the application thread to allow Filament to take ownership of the image
|
||||
|
||||
/**
|
||||
* Takes ownership of the externalImage. The externalImage parameter depends on the Platform's
|
||||
* concrete implementation. Ownership is released when destroyExternalImage() is called.
|
||||
* concrete implementation. Ownership is released when destroyExternalImageTexture() is called.
|
||||
*
|
||||
* WARNING: This is called synchronously from the application thread (NOT the Driver thread)
|
||||
*
|
||||
* @param externalImage A token representing the platform's external image.
|
||||
* @see destroyExternalImage
|
||||
* @{
|
||||
*/
|
||||
virtual void retainExternalImage(void* UTILS_NONNULL externalImage) noexcept;
|
||||
|
||||
virtual void retainExternalImage(ExternalImageHandleRef externalImage) noexcept;
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
* Called to bind the platform-specific externalImage to an ExternalTexture.
|
||||
* ExternalTexture::id is guaranteed to be bound when this method is called and ExternalTexture
|
||||
* is updated with new values for id/target if necessary.
|
||||
*
|
||||
* WARNING: this method is not allowed to change the bound texture, or must restore the previous
|
||||
* binding upon return. This is to avoid problem with a backend doing state caching.
|
||||
* binding upon return. This is to avoid a problem with a backend doing state caching.
|
||||
*
|
||||
* @param externalImage The platform-specific external image.
|
||||
* @param texture an in/out pointer to ExternalTexture, id and target can be updated if necessary.
|
||||
* @return true on success, false on error.
|
||||
* @{
|
||||
*/
|
||||
virtual bool setExternalImage(void* UTILS_NONNULL externalImage,
|
||||
ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
|
||||
virtual bool setExternalImage(ExternalImageHandleRef externalImage,
|
||||
ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
* The method allows platforms to convert a user-supplied external image object into a new type
|
||||
* (e.g. HardwareBuffer => EGLImage). The default implementation returns source.
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_GL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_GL_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -34,12 +33,14 @@ public:
|
||||
PlatformCocoaGL();
|
||||
~PlatformCocoaGL() noexcept override;
|
||||
|
||||
ExternalImageHandle createExternalImage(void* cvPixelBuffer) noexcept;
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
const DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
// Currently returns 0
|
||||
int getOSVersion() const noexcept override;
|
||||
@@ -59,10 +60,12 @@ protected:
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImageTexture(ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(void* externalImage) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(ExternalImageHandleRef externalImage) noexcept override;
|
||||
bool setExternalImage(ExternalImageHandleRef externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
private:
|
||||
PlatformCocoaGLImpl* pImpl = nullptr;
|
||||
|
||||
@@ -32,11 +32,13 @@ public:
|
||||
PlatformCocoaTouchGL();
|
||||
~PlatformCocoaTouchGL() noexcept override;
|
||||
|
||||
ExternalImageHandle createExternalImage(void* cvPixelBuffer) noexcept;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedGLContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
const DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept final { return 0; }
|
||||
|
||||
@@ -56,10 +58,12 @@ public:
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImageTexture(ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(void* externalImage) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(ExternalImageHandleRef externalImage) noexcept override;
|
||||
bool setExternalImage(ExternalImageHandleRef externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
private:
|
||||
PlatformCocoaTouchGLImpl* pImpl = nullptr;
|
||||
|
||||
@@ -47,6 +47,11 @@ public:
|
||||
// Return true if we're on an OpenGL platform (as opposed to OpenGL ES). false by default.
|
||||
virtual bool isOpenGL() const noexcept;
|
||||
|
||||
/**
|
||||
* Creates an ExternalImage from a EGLImageKHR
|
||||
*/
|
||||
ExternalImageHandle createExternalImage(EGLImageKHR eglImage) noexcept;
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Helper for EGL configs and attributes parameters
|
||||
@@ -75,8 +80,7 @@ protected:
|
||||
* Initializes EGL, creates the OpenGL context and returns a concrete Driver implementation
|
||||
* that supports OpenGL/OpenGL ES.
|
||||
*/
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
Driver* createDriver(void* sharedContext, const DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
/**
|
||||
* This returns zero. This method can be overridden to return something more useful.
|
||||
@@ -118,9 +122,10 @@ protected:
|
||||
void destroyFence(Fence* fence) noexcept override;
|
||||
FenceStatus waitFence(Fence* fence, uint64_t timeout) noexcept override;
|
||||
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImageTexture(ExternalTexture* texture) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
bool setExternalImage(ExternalImageHandleRef externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
/**
|
||||
* Logs glGetError() to slog.e
|
||||
@@ -188,6 +193,12 @@ protected:
|
||||
|
||||
void initializeGlExtensions() noexcept;
|
||||
|
||||
struct ExternalImageEGL : public ExternalImage {
|
||||
EGLImageKHR eglImage = EGL_NO_IMAGE;
|
||||
protected:
|
||||
~ExternalImageEGL() override;
|
||||
};
|
||||
|
||||
protected:
|
||||
EGLConfig findSwapChainConfig(uint64_t flags, bool window, bool pbuffer) const;
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ protected:
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
/**
|
||||
* Creates an ExternalImage from a EGLImageKHR
|
||||
*/
|
||||
ExternalImageHandle createExternalImage(AHardwareBuffer const *buffer, bool sRGB) noexcept;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
@@ -81,6 +86,7 @@ protected:
|
||||
void attach(Stream* stream, intptr_t tname) noexcept override;
|
||||
void detach(Stream* stream) noexcept override;
|
||||
void updateTexImage(Stream* stream, int64_t* timestamp) noexcept override;
|
||||
math::mat3f getTransformMatrix(Stream* stream) noexcept override;
|
||||
|
||||
/**
|
||||
* Converts a AHardwareBuffer to EGLImage
|
||||
@@ -89,6 +95,15 @@ protected:
|
||||
*/
|
||||
AcquiredImage transformAcquiredImage(AcquiredImage source) noexcept override;
|
||||
|
||||
bool setExternalImage(ExternalImageHandleRef externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
struct ExternalImageEGLAndroid : public ExternalImageEGL {
|
||||
AHardwareBuffer* aHardwareBuffer = nullptr;
|
||||
bool sRGB = false;
|
||||
protected:
|
||||
~ExternalImageEGLAndroid() override;
|
||||
};
|
||||
|
||||
protected:
|
||||
bool makeCurrent(ContextType type,
|
||||
SwapChain* drawSwapChain,
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_H
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_PLATFORMMETAL_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Platform.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();
|
||||
~PlatformMetal() noexcept override;
|
||||
|
||||
Driver* createDriver(void* sharedContext, const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
int getOSVersion() const noexcept override { return 0; }
|
||||
|
||||
/**
|
||||
* Obtain the preferred Metal device object for the backend to use.
|
||||
*
|
||||
* On desktop platforms, there may be multiple GPUs suitable for rendering, and this method is
|
||||
* free to decide which one to use. On mobile systems with a single GPU, implementations should
|
||||
* simply return the result of MTLCreateSystemDefaultDevice();
|
||||
*/
|
||||
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 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.
|
||||
*/
|
||||
void createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept;
|
||||
|
||||
/**
|
||||
* The action to take if a Drawable cannot be acquired.
|
||||
*
|
||||
* Each frame rendered requires a CAMetalDrawable texture, which is presented on-screen at the
|
||||
* completion of each frame. These are limited and provided round-robin style by the system.
|
||||
*/
|
||||
enum class DrawableFailureBehavior : uint8_t {
|
||||
/**
|
||||
* Terminates the application and reports an error message (default).
|
||||
*/
|
||||
PANIC,
|
||||
/*
|
||||
* Aborts execution of the current frame. The Metal backend will attempt to acquire a new
|
||||
* drawable at the next frame.
|
||||
*/
|
||||
ABORT_FRAME
|
||||
};
|
||||
void setDrawableFailureBehavior(DrawableFailureBehavior behavior) noexcept;
|
||||
DrawableFailureBehavior getDrawableFailureBehavior() const noexcept;
|
||||
|
||||
private:
|
||||
PlatformMetalImpl* pImpl = nullptr;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRIVATE_PLATFORMMETAL_H
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
// 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;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -88,6 +91,7 @@ public:
|
||||
VkFormat colorFormat = VK_FORMAT_UNDEFINED;
|
||||
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
||||
VkExtent2D extent = {0, 0};
|
||||
uint32_t layerCount = 1;
|
||||
bool isProtected = false;
|
||||
};
|
||||
|
||||
@@ -292,8 +296,69 @@ public:
|
||||
*/
|
||||
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 layerCount of the external image
|
||||
*/
|
||||
uint32_t layerCount;
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
|
||||
@@ -80,7 +80,8 @@ public:
|
||||
OPENGL = 0x01u,
|
||||
VULKAN = 0x02u,
|
||||
METAL = 0x04u,
|
||||
ALL = OPENGL | VULKAN | METAL
|
||||
WEBGPU = 0x08u,
|
||||
ALL = OPENGL | VULKAN | METAL | WEBGPU
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -163,6 +164,7 @@ inline constexpr MaterialBuilderBase::TargetApi targetApiFromBackend(
|
||||
case Backend::OPENGL: return TargetApi::OPENGL;
|
||||
case Backend::VULKAN: return TargetApi::VULKAN;
|
||||
case Backend::METAL: return TargetApi::METAL;
|
||||
case Backend::WEBGPU: return TargetApi::WEBGPU;
|
||||
case Backend::NOOP: return TargetApi::OPENGL;
|
||||
}
|
||||
}
|
||||
@@ -316,7 +318,8 @@ public:
|
||||
MaterialBuilder& parameter(const char* name, SamplerType samplerType,
|
||||
SamplerFormat format = SamplerFormat::FLOAT,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT,
|
||||
bool multisample = false) noexcept;
|
||||
bool multisample = false,
|
||||
const char* transformName = "") noexcept;
|
||||
|
||||
MaterialBuilder& buffer(filament::BufferInterfaceBlock bib) noexcept;
|
||||
|
||||
@@ -585,8 +588,7 @@ public:
|
||||
*/
|
||||
MaterialBuilder& optimization(Optimization optimization) noexcept;
|
||||
|
||||
// TODO: this is present here for matc's "--print" flag, but ideally does not belong inside
|
||||
// MaterialBuilder.
|
||||
// TODO: this is present here for matc's "--print" flag, but ideally does not belong inside MaterialBuilder.
|
||||
//! If true, will output the generated GLSL shader code to stdout.
|
||||
MaterialBuilder& printShaders(bool printShaders) noexcept;
|
||||
|
||||
@@ -649,8 +651,8 @@ public:
|
||||
Parameter() noexcept: parameterType(INVALID) {}
|
||||
|
||||
// Sampler
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p, bool ms)
|
||||
: name(paramName), size(1), precision(p), samplerType(t), format(f), parameterType(SAMPLER), multisample(ms) { }
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p, bool ms, const char* tn)
|
||||
: name(paramName), size(1), precision(p), samplerType(t), format(f), parameterType(SAMPLER), multisample(ms), transformName(tn) { }
|
||||
|
||||
// Uniform
|
||||
Parameter(const char* paramName, UniformType t, size_t typeSize, ParameterPrecision p)
|
||||
@@ -668,6 +670,7 @@ public:
|
||||
SubpassType subpassType;
|
||||
SamplerFormat format;
|
||||
bool multisample;
|
||||
utils::CString transformName;
|
||||
enum {
|
||||
INVALID,
|
||||
UNIFORM,
|
||||
@@ -728,7 +731,7 @@ public:
|
||||
static constexpr size_t MAX_DEPTH_OUTPUT = 1;
|
||||
static_assert(MAX_COLOR_OUTPUT == 8,
|
||||
"When updating MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT, manually update post_process_inputs.fs"
|
||||
" and post_process.fs");
|
||||
" and post_process_main.fs");
|
||||
|
||||
// Preview the first shader generated by the given CodeGenParams.
|
||||
// This is used to run Static Code Analysis before generating a package.
|
||||
|
||||
@@ -183,7 +183,7 @@ struct UTILS_PUBLIC Aabb {
|
||||
* Returns the 8 corner vertices of the AABB.
|
||||
*/
|
||||
Corners getCorners() const {
|
||||
return Aabb::Corners{ .vertices = {
|
||||
return Corners{ .vertices = {
|
||||
{ min.x, min.y, min.z },
|
||||
{ max.x, min.y, min.z },
|
||||
{ min.x, max.y, min.z },
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
/**
|
||||
* The binding type for this buffer object. (defaults to VERTEX)
|
||||
* @param BindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
|
||||
* @param bindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& bindingType(BindingType bindingType) noexcept;
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the BufferObject and returns a pointer to it. After creation, the buffer
|
||||
|
||||
@@ -400,14 +400,14 @@ public:
|
||||
* engine.getTransformManager().getInstance(camera->getEntity()), model);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* @param model The camera position and orientation provided as a rigid transform matrix.
|
||||
* @param modelMatrix The camera position and orientation provided as a rigid transform matrix.
|
||||
*
|
||||
* @note The Camera "looks" towards its -z axis
|
||||
*
|
||||
* @warning \p model must be a rigid transform
|
||||
*/
|
||||
void setModelMatrix(const math::mat4& model) noexcept;
|
||||
void setModelMatrix(const math::mat4f& model) noexcept; //!< @overload
|
||||
void setModelMatrix(const math::mat4& modelMatrix) noexcept;
|
||||
void setModelMatrix(const math::mat4f& modelMatrix) noexcept; //!< @overload
|
||||
|
||||
/** Set the position of an eye relative to this Camera (head).
|
||||
*
|
||||
|
||||
@@ -194,7 +194,7 @@ inline sRGBColorA Color::toSRGB<ACCURATE>(LinearColorA const& color) {
|
||||
}
|
||||
|
||||
inline LinearColor Color::toLinear(RgbType type, math::float3 color) {
|
||||
return (type == RgbType::LINEAR) ? color : Color::toLinear<ACCURATE>(color);
|
||||
return (type == RgbType::LINEAR) ? color : toLinear<ACCURATE>(color);
|
||||
}
|
||||
|
||||
// converts an RGBA color to linear space
|
||||
@@ -202,11 +202,11 @@ inline LinearColor Color::toLinear(RgbType type, math::float3 color) {
|
||||
inline LinearColorA Color::toLinear(RgbaType type, math::float4 color) {
|
||||
switch (type) {
|
||||
case RgbaType::sRGB:
|
||||
return Color::toLinear<ACCURATE>(color) * math::float4{color.a, color.a, color.a, 1.0f};
|
||||
return toLinear<ACCURATE>(color) * math::float4{color.a, color.a, color.a, 1.0f};
|
||||
case RgbaType::LINEAR:
|
||||
return color * math::float4{color.a, color.a, color.a, 1.0f};
|
||||
case RgbaType::PREMULTIPLIED_sRGB:
|
||||
return Color::toLinear<ACCURATE>(color);
|
||||
return toLinear<ACCURATE>(color);
|
||||
case RgbaType::PREMULTIPLIED_LINEAR:
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef TNT_FILAMENT_ENGINE_H
|
||||
#define TNT_FILAMENT_ENGINE_H
|
||||
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
@@ -32,6 +33,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
class EntityManager;
|
||||
@@ -40,6 +42,10 @@ class JobSystem;
|
||||
|
||||
namespace filament {
|
||||
|
||||
namespace backend {
|
||||
class Driver;
|
||||
} // backend
|
||||
|
||||
class BufferObject;
|
||||
class Camera;
|
||||
class ColorGrading;
|
||||
@@ -183,6 +189,7 @@ public:
|
||||
using DriverConfig = backend::Platform::DriverConfig;
|
||||
using FeatureLevel = backend::FeatureLevel;
|
||||
using StereoscopicType = backend::StereoscopicType;
|
||||
using Driver = backend::Driver;
|
||||
|
||||
/**
|
||||
* Config is used to define the memory footprint used by the engine, such as the
|
||||
@@ -537,7 +544,7 @@ public:
|
||||
Platform* UTILS_NULLABLE platform = nullptr,
|
||||
void* UTILS_NULLABLE sharedContext = nullptr,
|
||||
const Config* UTILS_NULLABLE config = nullptr) {
|
||||
return Engine::Builder()
|
||||
return Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
@@ -557,7 +564,7 @@ public:
|
||||
Platform* UTILS_NULLABLE platform = nullptr,
|
||||
void* UTILS_NULLABLE sharedContext = nullptr,
|
||||
const Config* UTILS_NULLABLE config = nullptr) {
|
||||
Engine::Builder()
|
||||
Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
@@ -582,6 +589,11 @@ public:
|
||||
static Engine* UTILS_NULLABLE getEngine(void* UTILS_NONNULL token);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @return the Driver instance used by this Engine.
|
||||
* @see OpenGLPlatform
|
||||
*/
|
||||
backend::Driver const* UTILS_NONNULL getDriver() const noexcept;
|
||||
|
||||
/**
|
||||
* Destroy the Engine instance and all associated resources.
|
||||
@@ -970,6 +982,25 @@ public:
|
||||
*/
|
||||
void flushAndWait();
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) and blocks until
|
||||
* all commands to this point are executed. Note that does guarantee that the
|
||||
* hardware is actually finished.
|
||||
*
|
||||
* A timeout can be specified, if for some reason this flushAndWait doesn't complete before the timeout, it will
|
||||
* return false, true otherwise.
|
||||
*
|
||||
* <p>This is typically used right after destroying the <code>SwapChain</code>,
|
||||
* in cases where a guarantee about the <code>SwapChain</code> destruction is needed in a
|
||||
* timely fashion, such as when responding to Android's
|
||||
* <code>android.view.SurfaceHolder.Callback.surfaceDestroyed</code></p>
|
||||
*
|
||||
* @param timeout A timeout in nanoseconds
|
||||
* @return true if successful, false if flushAndWait timed out, in which case it wasn't successful and commands
|
||||
* might still be executing on both the CPU and GPU sides.
|
||||
*/
|
||||
bool flushAndWait(uint64_t timeout);
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) but does not wait
|
||||
* for commands to be either executed or the hardware finished.
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the IndexBuffer object and returns a pointer to it. After creation, the index
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the InstanceBuffer object and returns a pointer to it.
|
||||
|
||||
@@ -103,6 +103,11 @@ public:
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
enum class ShadowSamplingQuality : uint8_t {
|
||||
HARD, // 2x2 PCF
|
||||
LOW // 3x3 gaussian filter
|
||||
};
|
||||
|
||||
/**
|
||||
* Specifies the material data. The material data is a binary blob produced by
|
||||
* libfilamat or by matc.
|
||||
@@ -113,10 +118,10 @@ public:
|
||||
Builder& package(const void* UTILS_NONNULL payload, size_t size);
|
||||
|
||||
template<typename T>
|
||||
using is_supported_constant_parameter_t = typename std::enable_if<
|
||||
std::is_same<int32_t, T>::value ||
|
||||
std::is_same<float, T>::value ||
|
||||
std::is_same<bool, T>::value>::type;
|
||||
using is_supported_constant_parameter_t = std::enable_if_t<
|
||||
std::is_same_v<int32_t, T> ||
|
||||
std::is_same_v<float, T> ||
|
||||
std::is_same_v<bool, T>>;
|
||||
|
||||
/**
|
||||
* Specialize a constant parameter specified in the material definition with a concrete
|
||||
@@ -152,6 +157,14 @@ public:
|
||||
*/
|
||||
Builder& sphericalHarmonicsBandCount(size_t shBandCount) noexcept;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Builder& shadowSamplingQuality(ShadowSamplingQuality quality) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the Material object and returns a pointer to it.
|
||||
*
|
||||
@@ -164,7 +177,7 @@ public:
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*/
|
||||
Material* UTILS_NULLABLE build(Engine& engine);
|
||||
Material* UTILS_NULLABLE build(Engine& engine) const;
|
||||
private:
|
||||
friend class FMaterial;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
namespace filament {
|
||||
|
||||
// update this when a new version of filament wouldn't work with older materials
|
||||
static constexpr size_t MATERIAL_VERSION = 56;
|
||||
static constexpr size_t MATERIAL_VERSION = 58;
|
||||
|
||||
/**
|
||||
* Supported shading models
|
||||
|
||||
@@ -56,35 +56,35 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
|
||||
};
|
||||
|
||||
public:
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
using DepthFunc = filament::backend::SamplerCompareFunc;
|
||||
using StencilCompareFunc = filament::backend::SamplerCompareFunc;
|
||||
using StencilOperation = filament::backend::StencilOperation;
|
||||
using StencilFace = filament::backend::StencilFace;
|
||||
using CullingMode = backend::CullingMode;
|
||||
using TransparencyMode = TransparencyMode;
|
||||
using DepthFunc = backend::SamplerCompareFunc;
|
||||
using StencilCompareFunc = backend::SamplerCompareFunc;
|
||||
using StencilOperation = backend::StencilOperation;
|
||||
using StencilFace = backend::StencilFace;
|
||||
|
||||
template<typename T>
|
||||
using is_supported_parameter_t = typename std::enable_if<
|
||||
std::is_same<float, T>::value ||
|
||||
std::is_same<int32_t, T>::value ||
|
||||
std::is_same<uint32_t, T>::value ||
|
||||
std::is_same<math::int2, T>::value ||
|
||||
std::is_same<math::int3, T>::value ||
|
||||
std::is_same<math::int4, T>::value ||
|
||||
std::is_same<math::uint2, T>::value ||
|
||||
std::is_same<math::uint3, T>::value ||
|
||||
std::is_same<math::uint4, T>::value ||
|
||||
std::is_same<math::float2, T>::value ||
|
||||
std::is_same<math::float3, T>::value ||
|
||||
std::is_same<math::float4, T>::value ||
|
||||
std::is_same<math::mat4f, T>::value ||
|
||||
using is_supported_parameter_t = std::enable_if_t<
|
||||
std::is_same_v<float, T> ||
|
||||
std::is_same_v<int32_t, T> ||
|
||||
std::is_same_v<uint32_t, T> ||
|
||||
std::is_same_v<math::int2, T> ||
|
||||
std::is_same_v<math::int3, T> ||
|
||||
std::is_same_v<math::int4, T> ||
|
||||
std::is_same_v<math::uint2, T> ||
|
||||
std::is_same_v<math::uint3, T> ||
|
||||
std::is_same_v<math::uint4, T> ||
|
||||
std::is_same_v<math::float2, T> ||
|
||||
std::is_same_v<math::float3, T> ||
|
||||
std::is_same_v<math::float4, T> ||
|
||||
std::is_same_v<math::mat4f, T> ||
|
||||
// these types are slower as they need a layout conversion
|
||||
std::is_same<bool, T>::value ||
|
||||
std::is_same<math::bool2, T>::value ||
|
||||
std::is_same<math::bool3, T>::value ||
|
||||
std::is_same<math::bool4, T>::value ||
|
||||
std::is_same<math::mat3f, T>::value
|
||||
>::type;
|
||||
std::is_same_v<bool, T> ||
|
||||
std::is_same_v<math::bool2, T> ||
|
||||
std::is_same_v<math::bool3, T> ||
|
||||
std::is_same_v<math::bool4, T> ||
|
||||
std::is_same_v<math::mat3f, T>
|
||||
>;
|
||||
|
||||
/**
|
||||
* Creates a new MaterialInstance using another MaterialInstance as a template for initialization.
|
||||
@@ -121,13 +121,13 @@ public:
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(StringLiteral name, T const& value) {
|
||||
void setParameter(StringLiteral const name, T const& value) {
|
||||
setParameter<T>(name.data, name.size, value);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(const char* UTILS_NONNULL name, T const& value) {
|
||||
void setParameter(const char* UTILS_NONNULL name, T const& value) {
|
||||
setParameter<T>(name, strlen(name), value);
|
||||
}
|
||||
|
||||
@@ -148,14 +148,14 @@ public:
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(StringLiteral name, const T* UTILS_NONNULL values, size_t count) {
|
||||
void setParameter(StringLiteral const name, const T* UTILS_NONNULL values, size_t const count) {
|
||||
setParameter<T>(name.data, name.size, values, count);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(const char* UTILS_NONNULL name,
|
||||
const T* UTILS_NONNULL values, size_t count) {
|
||||
void setParameter(const char* UTILS_NONNULL name,
|
||||
const T* UTILS_NONNULL values, size_t const count) {
|
||||
setParameter<T>(name, strlen(name), values, count);
|
||||
}
|
||||
|
||||
@@ -176,14 +176,14 @@ public:
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
void setParameter(StringLiteral const name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
setParameter(name.data, name.size, texture, sampler);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
void setParameter(const char* UTILS_NONNULL name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
setParameter(name, strlen(name), texture, sampler);
|
||||
}
|
||||
|
||||
@@ -202,12 +202,12 @@ public:
|
||||
RgbType type, math::float3 color);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name, RgbType type, math::float3 color) {
|
||||
void setParameter(StringLiteral const name, RgbType const type, math::float3 const color) {
|
||||
setParameter(name.data, name.size, type, color);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) {
|
||||
void setParameter(const char* UTILS_NONNULL name, RgbType const type, math::float3 const color) {
|
||||
setParameter(name, strlen(name), type, color);
|
||||
}
|
||||
|
||||
@@ -226,12 +226,12 @@ public:
|
||||
RgbaType type, math::float4 color);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name, RgbaType type, math::float4 color) {
|
||||
void setParameter(StringLiteral const name, RgbaType const type, math::float4 const color) {
|
||||
setParameter(name.data, name.size, type, color);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) {
|
||||
void setParameter(const char* UTILS_NONNULL name, RgbaType const type, math::float4 const color) {
|
||||
setParameter(name, strlen(name), type, color);
|
||||
}
|
||||
|
||||
@@ -251,13 +251,13 @@ public:
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline T getParameter(StringLiteral name) const {
|
||||
T getParameter(StringLiteral const name) const {
|
||||
return getParameter<T>(name.data, name.size);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline T getParameter(const char* UTILS_NONNULL name) const {
|
||||
T getParameter(const char* UTILS_NONNULL name) const {
|
||||
return getParameter<T>(name, strlen(name));
|
||||
}
|
||||
|
||||
@@ -376,11 +376,22 @@ public:
|
||||
*/
|
||||
void setCullingMode(CullingMode culling) noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default triangle culling state that was set on the material separately for the
|
||||
* color and shadow passes
|
||||
*/
|
||||
void setCullingMode(CullingMode colorPassCullingMode, CullingMode shadowPassCullingMode) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the face culling mode.
|
||||
*/
|
||||
CullingMode getCullingMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the face culling mode for the shadow passes.
|
||||
*/
|
||||
CullingMode getShadowCullingMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default color-buffer write state that was set on the material.
|
||||
*/
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the MorphTargetBuffer object and returns a pointer to it.
|
||||
|
||||
@@ -86,10 +86,10 @@ struct DynamicResolutionOptions {
|
||||
/**
|
||||
* Upscaling quality
|
||||
* LOW: bilinear filtered blit. Fastest, poor quality
|
||||
* MEDIUM: AMD FidelityFX FSR1 w/ mobile optimizations
|
||||
* MEDIUM: Qualcomm Snapdragon Game Super Resolution (SGSR) 1.0
|
||||
* HIGH: AMD FidelityFX FSR1 w/ mobile optimizations
|
||||
* ULTRA: AMD FidelityFX FSR1
|
||||
* FSR1 require a well anti-aliased (MSAA or TAA), noise free scene.
|
||||
* FSR1 and SGSR require a well anti-aliased (MSAA or TAA), noise free scene. Avoid FXAA and dithering.
|
||||
*
|
||||
* The default upscaling quality is set to LOW.
|
||||
*/
|
||||
@@ -438,7 +438,7 @@ struct MultiSampleAntiAliasingOptions {
|
||||
* @see setTemporalAntiAliasingOptions()
|
||||
*/
|
||||
struct TemporalAntiAliasingOptions {
|
||||
float filterWidth = 1.0f; //!< reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
|
||||
float filterWidth = 1.0f; //!< reconstruction filter width typically between 1 (sharper) and 2 (smoother)
|
||||
float feedback = 0.12f; //!< history feedback, between 0 (maximum temporal AA) and 1 (no temporal AA).
|
||||
float lodBias = -1.0f; //!< texturing lod bias (typically -1 or -2)
|
||||
float sharpness = 0.0f; //!< post-TAA sharpen, especially useful when upscaling is true.
|
||||
|
||||
@@ -220,7 +220,7 @@ public:
|
||||
* the renderable are immutable.
|
||||
* STATIC geometry has the same restrictions as STATIC_BOUNDS, but in addition disallows
|
||||
* skinning, morphing and changing the VertexBuffer or IndexBuffer in any way.
|
||||
* @param enable whether this renderable has static bounds. false by default.
|
||||
* @param type type of geometry.
|
||||
*/
|
||||
Builder& geometryType(GeometryType type) noexcept;
|
||||
|
||||
@@ -454,7 +454,7 @@ public:
|
||||
*
|
||||
* @param primitiveIndex zero-based index of the primitive, must be less than the primitive
|
||||
* count passed to Builder constructor
|
||||
* @param indicesAndWeightsVectors pairs of bone index and bone weight for all vertices of
|
||||
* @param indicesAndWeightsVector pairs of bone index and bone weight for all vertices of
|
||||
* the primitive sequentially
|
||||
*
|
||||
* @return Builder reference for chaining calls.
|
||||
@@ -501,7 +501,7 @@ public:
|
||||
* @param primitiveIndex zero-based index of the primitive, must be less than the count passed to Builder constructor
|
||||
* @param offset specifies where in the morph target buffer to start reading (expressed as a number of vertices)
|
||||
*/
|
||||
RenderableManager::Builder& morphing(uint8_t level,
|
||||
Builder& morphing(uint8_t level,
|
||||
size_t primitiveIndex, size_t offset) noexcept;
|
||||
|
||||
|
||||
@@ -798,6 +798,13 @@ public:
|
||||
void setMaterialInstanceAt(Instance instance,
|
||||
size_t primitiveIndex, MaterialInstance const* UTILS_NONNULL materialInstance);
|
||||
|
||||
/**
|
||||
* Clear the MaterialInstance for the given primitive.
|
||||
* @param instance Renderable's instance
|
||||
* @param primitiveIndex Primitive index
|
||||
*/
|
||||
void clearMaterialInstanceAt(Instance instance, size_t primitiveIndex);
|
||||
|
||||
/**
|
||||
* Retrieves the material instance that is bound to the given primitive.
|
||||
*/
|
||||
@@ -845,20 +852,20 @@ public:
|
||||
/*! \cond PRIVATE */
|
||||
template<typename T>
|
||||
struct is_supported_vector_type {
|
||||
using type = typename std::enable_if<
|
||||
std::is_same<math::float4, T>::value ||
|
||||
std::is_same<math::half4, T>::value ||
|
||||
std::is_same<math::float3, T>::value ||
|
||||
std::is_same<math::half3, T>::value
|
||||
>::type;
|
||||
using type = std::enable_if_t<
|
||||
std::is_same_v<math::float4, T> ||
|
||||
std::is_same_v<math::half4, T> ||
|
||||
std::is_same_v<math::float3, T> ||
|
||||
std::is_same_v<math::half3, T>
|
||||
>;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_supported_index_type {
|
||||
using type = typename std::enable_if<
|
||||
std::is_same<uint16_t, T>::value ||
|
||||
std::is_same<uint32_t, T>::value
|
||||
>::type;
|
||||
using type = std::enable_if_t<
|
||||
std::is_same_v<uint16_t, T> ||
|
||||
std::is_same_v<uint32_t, T>
|
||||
>;
|
||||
};
|
||||
/*! \endcond */
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
* @param historySize requested history size. The returned vector could be smaller.
|
||||
* @return A vector of FrameInfo.
|
||||
*/
|
||||
utils::FixedCapacityVector<Renderer::FrameInfo> getFrameInfoHistory(
|
||||
utils::FixedCapacityVector<FrameInfo> getFrameInfoHistory(
|
||||
size_t historySize = 1) const noexcept;
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,11 @@ public:
|
||||
*/
|
||||
void removeEntities(const utils::Entity* UTILS_NONNULL entities, size_t count);
|
||||
|
||||
/**
|
||||
* Remove all entities to the Scene.
|
||||
*/
|
||||
void removeAllEntities() noexcept;
|
||||
|
||||
/**
|
||||
* Returns the total number of Entities in the Scene, whether alive or not.
|
||||
* @return Total number of Entities in the Scene.
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the SkinningBuffer object and returns a pointer to it.
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mat3.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
@@ -149,7 +151,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the Stream object and returns a pointer to it.
|
||||
@@ -189,9 +191,10 @@ public:
|
||||
* The callback tales two arguments: the AHardwareBuffer and the userdata.
|
||||
* @param userdata Optional closure data. Filament will pass this into the callback when it
|
||||
* releases the image.
|
||||
* @param transform Optional transform matrix to apply to the image.
|
||||
*/
|
||||
void setAcquiredImage(void* UTILS_NONNULL image,
|
||||
Callback UTILS_NONNULL callback, void* UTILS_NULLABLE userdata) noexcept;
|
||||
Callback UTILS_NONNULL callback, void* UTILS_NULLABLE userdata, math::mat3f const& transform = math::mat3f()) noexcept;
|
||||
|
||||
/**
|
||||
* @see setAcquiredImage(void*, Callback, void*)
|
||||
@@ -202,10 +205,11 @@ public:
|
||||
* It callback tales two arguments: the AHardwareBuffer and the userdata.
|
||||
* @param userdata Optional closure data. Filament will pass this into the callback when it
|
||||
* releases the image.
|
||||
* @param transform Optional transform matrix to apply to the image.
|
||||
*/
|
||||
void setAcquiredImage(void* UTILS_NONNULL image,
|
||||
backend::CallbackHandler* UTILS_NULLABLE handler,
|
||||
Callback UTILS_NONNULL callback, void* UTILS_NULLABLE userdata) noexcept;
|
||||
Callback UTILS_NONNULL callback, void* UTILS_NULLABLE userdata, math::mat3f const& transform = math::mat3f()) noexcept;
|
||||
|
||||
/**
|
||||
* Updates the size of the incoming stream. Whether this value is used is
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/PixelBufferDescriptor.h>
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
@@ -70,7 +71,7 @@ class UTILS_PUBLIC Texture : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
static constexpr const size_t BASE_LEVEL = 0;
|
||||
static constexpr size_t BASE_LEVEL = 0;
|
||||
|
||||
//! Face offsets for all faces of a cubemap
|
||||
struct FaceOffsets;
|
||||
@@ -84,19 +85,26 @@ public:
|
||||
using CompressedType = backend::CompressedPixelDataType; //!< Compressed pixel data format
|
||||
using Usage = backend::TextureUsage; //!< Usage affects texel layout
|
||||
using Swizzle = backend::TextureSwizzle; //!< Texture swizzle
|
||||
using ExternalImageHandle = backend::Platform::ExternalImageHandle;
|
||||
using ExternalImageHandleRef = backend::Platform::ExternalImageHandleRef;
|
||||
|
||||
/** @return whether a backend supports a particular format. */
|
||||
/** @return Whether a backend supports a particular format. */
|
||||
static bool isTextureFormatSupported(Engine& engine, InternalFormat format) noexcept;
|
||||
|
||||
/** @return whether this backend supports protected textures. */
|
||||
/** @return Whether a backend supports mipmapping of a particular format. */
|
||||
static bool isTextureFormatMipmappable(Engine& engine, InternalFormat format) noexcept;
|
||||
|
||||
/** @return Whether this backend supports protected textures. */
|
||||
static bool isProtectedTexturesSupported(Engine& engine) noexcept;
|
||||
|
||||
/** @return whether a backend supports texture swizzling. */
|
||||
/** @return Whether a backend supports texture swizzling. */
|
||||
static bool isTextureSwizzleSupported(Engine& engine) noexcept;
|
||||
|
||||
static size_t computeTextureDataSize(Texture::Format format, Texture::Type type,
|
||||
static size_t computeTextureDataSize(Format format, Type type,
|
||||
size_t stride, size_t height, size_t alignment) noexcept;
|
||||
|
||||
/** @return Whether a combination of texture format, pixel format and type is valid. */
|
||||
static bool validatePixelFormatAndType(InternalFormat internalFormat, Format format, Type type) noexcept;
|
||||
|
||||
/**
|
||||
* Options for environment prefiltering into reflection map
|
||||
@@ -215,7 +223,19 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates an external texture. The content must be set using setExternalImage().
|
||||
* The sampler can be SAMPLER_EXTERNAL or SAMPLER_2D depending on the format. Generally
|
||||
* YUV formats must use SAMPLER_EXTERNAL. This depends on the backend features and is not
|
||||
* validated.
|
||||
*
|
||||
* If the Sampler is set to SAMPLER_EXTERNAL, external() is implied.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Builder& external() noexcept;
|
||||
|
||||
/**
|
||||
* Creates the Texture object and returns a pointer to it.
|
||||
@@ -347,7 +367,7 @@ public:
|
||||
* uint32_t width, uint32_t height, uint32_t depth,
|
||||
* PixelBufferDescriptor&& buffer)
|
||||
*/
|
||||
inline void setImage(Engine& engine, size_t level, PixelBufferDescriptor&& buffer) const {
|
||||
void setImage(Engine& engine, size_t level, PixelBufferDescriptor&& buffer) const {
|
||||
setImage(engine, level, 0, 0, 0,
|
||||
uint32_t(getWidth(level)), uint32_t(getHeight(level)), 1, std::move(buffer));
|
||||
}
|
||||
@@ -360,7 +380,7 @@ public:
|
||||
* uint32_t width, uint32_t height, uint32_t depth,
|
||||
* PixelBufferDescriptor&& buffer)
|
||||
*/
|
||||
inline void setImage(Engine& engine, size_t level,
|
||||
void setImage(Engine& engine, size_t level,
|
||||
uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height,
|
||||
PixelBufferDescriptor&& buffer) const {
|
||||
setImage(engine, level, xoffset, yoffset, 0, width, height, 1, std::move(buffer));
|
||||
@@ -395,7 +415,27 @@ public:
|
||||
|
||||
|
||||
/**
|
||||
* Specify the external image to associate with this Texture. Typically the external
|
||||
* Specify the external image to associate with this Texture. Typically, the external
|
||||
* image is OS specific, and can be a video or camera frame.
|
||||
* There are many restrictions when using an external image as a texture, such as:
|
||||
* - only the level of detail (lod) 0 can be specified
|
||||
* - only nearest or linear filtering is supported
|
||||
* - the size and format of the texture is defined by the external image
|
||||
* - only the CLAMP_TO_EDGE wrap mode is supported
|
||||
*
|
||||
* @param engine Engine this texture is associated to.
|
||||
* @param image An opaque handle to a platform specific image. It must be created using Platform
|
||||
* specific APIs. For example PlatformEGL::createExternalImage(EGLImageKHR eglImage)
|
||||
*
|
||||
* @see PlatformEGL::createExternalImage
|
||||
* @see PlatformEGLAndroid::createExternalImage
|
||||
* @see PlatformCocoaGL::createExternalImage
|
||||
* @see PlatformCocoaTouchGL::createExternalImage
|
||||
*/
|
||||
void setExternalImage(Engine& engine, ExternalImageHandleRef image) noexcept;
|
||||
|
||||
/**
|
||||
* Specify the external image to associate with this Texture. Typically, the external
|
||||
* image is OS specific, and can be a video or camera frame.
|
||||
* There are many restrictions when using an external image as a texture, such as:
|
||||
* - only the level of detail (lod) 0 can be specified
|
||||
@@ -416,11 +456,13 @@ public:
|
||||
*
|
||||
* @see Builder::sampler()
|
||||
*
|
||||
* @deprecated Instead, use setExternalImage(Engine& engine, ExternalImageHandleRef image)
|
||||
*/
|
||||
UTILS_DEPRECATED
|
||||
void setExternalImage(Engine& engine, void* UTILS_NONNULL image) noexcept;
|
||||
|
||||
/**
|
||||
* Specify the external image and plane to associate with this Texture. Typically the external
|
||||
* Specify the external image and plane to associate with this Texture. Typically, the external
|
||||
* image is OS specific, and can be a video or camera frame. When using this method, the
|
||||
* external image must be a planar type (such as a YUV camera frame). The plane parameter
|
||||
* selects which image plane is bound to this texture.
|
||||
@@ -451,7 +493,7 @@ public:
|
||||
void setExternalImage(Engine& engine, void* UTILS_NONNULL image, size_t plane) noexcept;
|
||||
|
||||
/**
|
||||
* Specify the external stream to associate with this Texture. Typically the external
|
||||
* Specify the external stream to associate with this Texture. Typically, the external
|
||||
* stream is OS specific, and can be a video or camera stream.
|
||||
* There are many restrictions when using an external stream as a texture, such as:
|
||||
* - only the level of detail (lod) 0 can be specified
|
||||
@@ -462,7 +504,7 @@ public:
|
||||
* @param stream A Stream object
|
||||
*
|
||||
* @attention \p engine must be the instance passed to Builder::build()
|
||||
* @attention This Texture instance must use Sampler::SAMPLER_EXTERNAL or it has no effect
|
||||
* @attention This Texture instance must use Sampler::SAMPLER_EXTERNAL, or it has no effect
|
||||
*
|
||||
* @see Builder::sampler(), Stream
|
||||
*
|
||||
@@ -510,9 +552,9 @@ public:
|
||||
* @param buffer Client-side buffer containing the images to set.
|
||||
* @param faceOffsets Offsets in bytes into \p buffer for all six images. The offsets
|
||||
* are specified in the following order: +x, -x, +y, -y, +z, -z
|
||||
* @param options Optional parameter to controlling user-specified quality and options.
|
||||
* @param options Optional parameter controlling user-specified quality and options.
|
||||
*
|
||||
* @exception utils::PreConditionPanic if the source data constraints are not respected.
|
||||
* @exception utils::PreConditionPanic If the source data constraints are not respected.
|
||||
*
|
||||
*/
|
||||
void generatePrefilterMipmap(Engine& engine,
|
||||
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
* @param len Length of name, should be less than or equal to 128
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
|
||||
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the VertexBuffer object and returns a pointer to it.
|
||||
|
||||
@@ -259,7 +259,7 @@ public:
|
||||
return normalize(lerp(d < 0 ? -p : p, q, t));
|
||||
}
|
||||
const T npq = std::sqrt(dot(p, p) * dot(q, q)); // ||p|| * ||q||
|
||||
const T a = std::acos(filament::math::clamp(absd / npq, T(-1), T(1)));
|
||||
const T a = std::acos(math::clamp(absd / npq, T(-1), T(1)));
|
||||
const T a0 = a * (1 - t);
|
||||
const T a1 = a * t;
|
||||
const T sina = sin(a);
|
||||
|
||||
@@ -50,7 +50,7 @@ constexpr T MATH_PURE cos(T x) noexcept {
|
||||
// x between -pi and pi
|
||||
template<typename T, typename = std::enable_if_t<std::is_floating_point<T>::value>>
|
||||
constexpr T MATH_PURE sin(T x) noexcept {
|
||||
return filament::math::fast::cos<T>(x - T(F_PI_2));
|
||||
return fast::cos<T>(x - T(F_PI_2));
|
||||
}
|
||||
|
||||
constexpr inline float MATH_PURE ilog2(float x) noexcept {
|
||||
|
||||
@@ -164,7 +164,7 @@ inline constexpr half operator""_h(long double v) {
|
||||
return half( static_cast<float>(v) );
|
||||
}
|
||||
|
||||
template<> struct is_arithmetic<filament::math::half> : public std::true_type {};
|
||||
template<> struct is_arithmetic<half> : public std::true_type {};
|
||||
|
||||
} // namespace math
|
||||
} // namespace filament
|
||||
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
* Rotate by radians in the 2D plane
|
||||
*/
|
||||
static TMat22<T> rotate(T radian) noexcept {
|
||||
TMat22<T> r(TMat22<T>::NO_INIT);
|
||||
TMat22<T> r(NO_INIT);
|
||||
T c = std::cos(radian);
|
||||
T s = std::sin(radian);
|
||||
r[0][0] = c;
|
||||
|
||||
@@ -256,7 +256,7 @@ public:
|
||||
*/
|
||||
friend inline
|
||||
constexpr TMat33 orthogonalize(const TMat33& m) noexcept {
|
||||
TMat33 ret(TMat33::NO_INIT);
|
||||
TMat33 ret(NO_INIT);
|
||||
ret[0] = normalize(m[0]);
|
||||
ret[2] = normalize(cross(ret[0], m[1]));
|
||||
ret[1] = normalize(cross(ret[2], ret[0]));
|
||||
|
||||
@@ -498,10 +498,10 @@ constexpr TMat44<T> TMat44<T>::frustum(T left, T right, T bottom, T top, T near,
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
TMat44<T> TMat44<T>::perspective(T fov, T aspect, T near, T far, TMat44::Fov direction) noexcept {
|
||||
TMat44<T> TMat44<T>::perspective(T fov, T aspect, T near, T far, Fov direction) noexcept {
|
||||
T h, w;
|
||||
|
||||
if (direction == TMat44::Fov::VERTICAL) {
|
||||
if (direction == Fov::VERTICAL) {
|
||||
h = std::tan(fov * F_PI / 360.0f) * near;
|
||||
w = h * aspect;
|
||||
} else {
|
||||
|
||||
1041
thermion_dart/native/include/filament/spirv-tools/libspirv.h
Normal file
1041
thermion_dart/native/include/filament/spirv-tools/libspirv.h
Normal file
File diff suppressed because it is too large
Load Diff
404
thermion_dart/native/include/filament/spirv-tools/libspirv.hpp
Normal file
404
thermion_dart/native/include/filament/spirv-tools/libspirv.hpp
Normal file
@@ -0,0 +1,404 @@
|
||||
// Copyright (c) 2016 Google Inc.
|
||||
//
|
||||
// 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 INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "libspirv.h"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
// Message consumer. The C strings for source and message are only alive for the
|
||||
// specific invocation.
|
||||
using MessageConsumer = std::function<void(
|
||||
spv_message_level_t /* level */, const char* /* source */,
|
||||
const spv_position_t& /* position */, const char* /* message */
|
||||
)>;
|
||||
|
||||
using HeaderParser = std::function<spv_result_t(
|
||||
const spv_endianness_t endianess, const spv_parsed_header_t& instruction)>;
|
||||
using InstructionParser =
|
||||
std::function<spv_result_t(const spv_parsed_instruction_t& instruction)>;
|
||||
|
||||
// C++ RAII wrapper around the C context object spv_context.
|
||||
class SPIRV_TOOLS_EXPORT Context {
|
||||
public:
|
||||
// Constructs a context targeting the given environment |env|.
|
||||
//
|
||||
// See specific API calls for how the target environment is interpreted
|
||||
// (particularly assembly and validation).
|
||||
//
|
||||
// The constructed instance will have an empty message consumer, which just
|
||||
// ignores all messages from the library. Use SetMessageConsumer() to supply
|
||||
// one if messages are of concern.
|
||||
explicit Context(spv_target_env env);
|
||||
|
||||
// Enables move constructor/assignment operations.
|
||||
Context(Context&& other);
|
||||
Context& operator=(Context&& other);
|
||||
|
||||
// Disables copy constructor/assignment operations.
|
||||
Context(const Context&) = delete;
|
||||
Context& operator=(const Context&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~Context();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Returns the underlying spv_context.
|
||||
spv_context& CContext();
|
||||
const spv_context& CContext() const;
|
||||
|
||||
private:
|
||||
spv_context context_;
|
||||
};
|
||||
|
||||
// A RAII wrapper around a validator options object.
|
||||
class SPIRV_TOOLS_EXPORT ValidatorOptions {
|
||||
public:
|
||||
ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
|
||||
~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_validator_options() const { return options_; }
|
||||
|
||||
// Sets a limit.
|
||||
void SetUniversalLimit(spv_validator_limit limit_type, uint32_t limit) {
|
||||
spvValidatorOptionsSetUniversalLimit(options_, limit_type, limit);
|
||||
}
|
||||
|
||||
void SetRelaxStructStore(bool val) {
|
||||
spvValidatorOptionsSetRelaxStoreStruct(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_KHR_relaxed_block_layout when validating standard
|
||||
// uniform/storage buffer/push-constant layout. If true, disables
|
||||
// scalar block layout rules.
|
||||
void SetRelaxBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetRelaxBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_KHR_uniform_buffer_standard_layout when validating standard
|
||||
// uniform layout. If true, disables scalar block layout rules.
|
||||
void SetUniformBufferStandardLayout(bool val) {
|
||||
spvValidatorOptionsSetUniformBufferStandardLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_EXT_scalar_block_layout when validating standard
|
||||
// uniform/storage buffer/push-constant layout. If true, disables
|
||||
// relaxed block layout rules.
|
||||
void SetScalarBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetScalarBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables scalar layout when validating Workgroup blocks. See
|
||||
// VK_KHR_workgroup_memory_explicit_layout.
|
||||
void SetWorkgroupScalarBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetWorkgroupScalarBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Skips validating standard uniform/storage buffer/push-constant layout.
|
||||
void SetSkipBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetSkipBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables LocalSizeId decorations where the environment would not otherwise
|
||||
// allow them.
|
||||
void SetAllowLocalSizeId(bool val) {
|
||||
spvValidatorOptionsSetAllowLocalSizeId(options_, val);
|
||||
}
|
||||
|
||||
// Allow Offset (in addition to ConstOffset) for texture
|
||||
// operations. Was added for VK_KHR_maintenance8
|
||||
void SetAllowOffsetTextureOperand(bool val) {
|
||||
spvValidatorOptionsSetAllowOffsetTextureOperand(options_, val);
|
||||
}
|
||||
|
||||
// Records whether or not the validator should relax the rules on pointer
|
||||
// usage in logical addressing mode.
|
||||
//
|
||||
// When relaxed, it will allow the following usage cases of pointers:
|
||||
// 1) OpVariable allocating an object whose type is a pointer type
|
||||
// 2) OpReturnValue returning a pointer value
|
||||
void SetRelaxLogicalPointer(bool val) {
|
||||
spvValidatorOptionsSetRelaxLogicalPointer(options_, val);
|
||||
}
|
||||
|
||||
// Records whether or not the validator should relax the rules because it is
|
||||
// expected that the optimizations will make the code legal.
|
||||
//
|
||||
// When relaxed, it will allow the following:
|
||||
// 1) It will allow relaxed logical pointers. Setting this option will also
|
||||
// set that option.
|
||||
// 2) Pointers that are pass as parameters to function calls do not have to
|
||||
// match the storage class of the formal parameter.
|
||||
// 3) Pointers that are actual parameters on function calls do not have to
|
||||
// point to the same type pointed as the formal parameter. The types just
|
||||
// need to logically match.
|
||||
// 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
|
||||
// for a first argument.
|
||||
void SetBeforeHlslLegalization(bool val) {
|
||||
spvValidatorOptionsSetBeforeHlslLegalization(options_, val);
|
||||
}
|
||||
|
||||
// Whether friendly names should be used in validation error messages.
|
||||
void SetFriendlyNames(bool val) {
|
||||
spvValidatorOptionsSetFriendlyNames(options_, val);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_validator_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around an optimization options object.
|
||||
class SPIRV_TOOLS_EXPORT OptimizerOptions {
|
||||
public:
|
||||
OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
|
||||
~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_optimizer_options() const { return options_; }
|
||||
|
||||
// Records whether or not the optimizer should run the validator before
|
||||
// optimizing. If |run| is true, the validator will be run.
|
||||
void set_run_validator(bool run) {
|
||||
spvOptimizerOptionsSetRunValidator(options_, run);
|
||||
}
|
||||
|
||||
// Records the validator options that should be passed to the validator if it
|
||||
// is run.
|
||||
void set_validator_options(const ValidatorOptions& val_options) {
|
||||
spvOptimizerOptionsSetValidatorOptions(options_, val_options);
|
||||
}
|
||||
|
||||
// Records the maximum possible value for the id bound.
|
||||
void set_max_id_bound(uint32_t new_bound) {
|
||||
spvOptimizerOptionsSetMaxIdBound(options_, new_bound);
|
||||
}
|
||||
|
||||
// Records whether all bindings within the module should be preserved.
|
||||
void set_preserve_bindings(bool preserve_bindings) {
|
||||
spvOptimizerOptionsSetPreserveBindings(options_, preserve_bindings);
|
||||
}
|
||||
|
||||
// Records whether all specialization constants within the module
|
||||
// should be preserved.
|
||||
void set_preserve_spec_constants(bool preserve_spec_constants) {
|
||||
spvOptimizerOptionsSetPreserveSpecConstants(options_,
|
||||
preserve_spec_constants);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_optimizer_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around a reducer options object.
|
||||
class SPIRV_TOOLS_EXPORT ReducerOptions {
|
||||
public:
|
||||
ReducerOptions() : options_(spvReducerOptionsCreate()) {}
|
||||
~ReducerOptions() { spvReducerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_reducer_options() const { // NOLINT(google-explicit-constructor)
|
||||
return options_;
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetStepLimit.
|
||||
void set_step_limit(uint32_t step_limit) {
|
||||
spvReducerOptionsSetStepLimit(options_, step_limit);
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetFailOnValidationError.
|
||||
void set_fail_on_validation_error(bool fail_on_validation_error) {
|
||||
spvReducerOptionsSetFailOnValidationError(options_,
|
||||
fail_on_validation_error);
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetTargetFunction.
|
||||
void set_target_function(uint32_t target_function) {
|
||||
spvReducerOptionsSetTargetFunction(options_, target_function);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_reducer_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around a fuzzer options object.
|
||||
class SPIRV_TOOLS_EXPORT FuzzerOptions {
|
||||
public:
|
||||
FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
|
||||
~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_fuzzer_options() const { // NOLINT(google-explicit-constructor)
|
||||
return options_;
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableReplayValidation.
|
||||
void enable_replay_validation() {
|
||||
spvFuzzerOptionsEnableReplayValidation(options_);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetRandomSeed.
|
||||
void set_random_seed(uint32_t seed) {
|
||||
spvFuzzerOptionsSetRandomSeed(options_, seed);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetReplayRange.
|
||||
void set_replay_range(int32_t replay_range) {
|
||||
spvFuzzerOptionsSetReplayRange(options_, replay_range);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetShrinkerStepLimit.
|
||||
void set_shrinker_step_limit(uint32_t shrinker_step_limit) {
|
||||
spvFuzzerOptionsSetShrinkerStepLimit(options_, shrinker_step_limit);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableFuzzerPassValidation.
|
||||
void enable_fuzzer_pass_validation() {
|
||||
spvFuzzerOptionsEnableFuzzerPassValidation(options_);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableAllPasses.
|
||||
void enable_all_passes() { spvFuzzerOptionsEnableAllPasses(options_); }
|
||||
|
||||
private:
|
||||
spv_fuzzer_options options_;
|
||||
};
|
||||
|
||||
// C++ interface for SPIRV-Tools functionalities. It wraps the context
|
||||
// (including target environment and the corresponding SPIR-V grammar) and
|
||||
// provides methods for assembling, disassembling, and validating.
|
||||
//
|
||||
// Instances of this class provide basic thread-safety guarantee.
|
||||
class SPIRV_TOOLS_EXPORT SpirvTools {
|
||||
public:
|
||||
enum {
|
||||
// Default assembling option used by assemble():
|
||||
kDefaultAssembleOption = SPV_TEXT_TO_BINARY_OPTION_NONE,
|
||||
|
||||
// Default disassembling option used by Disassemble():
|
||||
// * Avoid prefix comments from decoding the SPIR-V module header, and
|
||||
// * Use friendly names for variables.
|
||||
kDefaultDisassembleOption = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES
|
||||
};
|
||||
|
||||
// Constructs an instance targeting the given environment |env|.
|
||||
//
|
||||
// The constructed instance will have an empty message consumer, which just
|
||||
// ignores all messages from the library. Use SetMessageConsumer() to supply
|
||||
// one if messages are of concern.
|
||||
explicit SpirvTools(spv_target_env env);
|
||||
|
||||
// Disables copy/move constructor/assignment operations.
|
||||
SpirvTools(const SpirvTools&) = delete;
|
||||
SpirvTools(SpirvTools&&) = delete;
|
||||
SpirvTools& operator=(const SpirvTools&) = delete;
|
||||
SpirvTools& operator=(SpirvTools&&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~SpirvTools();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Assembles the given assembly |text| and writes the result to |binary|.
|
||||
// Returns true on successful assembling. |binary| will be kept untouched if
|
||||
// assembling is unsuccessful.
|
||||
// The SPIR-V binary version is set to the highest version of SPIR-V supported
|
||||
// by the target environment with which this SpirvTools object was created.
|
||||
bool Assemble(const std::string& text, std::vector<uint32_t>* binary,
|
||||
uint32_t options = kDefaultAssembleOption) const;
|
||||
// |text_size| specifies the number of bytes in |text|. A terminating null
|
||||
// character is not required to present in |text| as long as |text| is valid.
|
||||
// The SPIR-V binary version is set to the highest version of SPIR-V supported
|
||||
// by the target environment with which this SpirvTools object was created.
|
||||
bool Assemble(const char* text, size_t text_size,
|
||||
std::vector<uint32_t>* binary,
|
||||
uint32_t options = kDefaultAssembleOption) const;
|
||||
|
||||
// Disassembles the given SPIR-V |binary| with the given |options| and writes
|
||||
// the assembly to |text|. Returns true on successful disassembling. |text|
|
||||
// will be kept untouched if diassembling is unsuccessful.
|
||||
bool Disassemble(const std::vector<uint32_t>& binary, std::string* text,
|
||||
uint32_t options = kDefaultDisassembleOption) const;
|
||||
// |binary_size| specifies the number of words in |binary|.
|
||||
bool Disassemble(const uint32_t* binary, size_t binary_size,
|
||||
std::string* text,
|
||||
uint32_t options = kDefaultDisassembleOption) const;
|
||||
|
||||
// Parses a SPIR-V binary, specified as counted sequence of 32-bit words.
|
||||
// Parsing feedback is provided via two callbacks provided as std::function.
|
||||
// In a valid parse the parsed-header callback is called once, and
|
||||
// then the parsed-instruction callback is called once for each instruction
|
||||
// in the stream.
|
||||
// Returns true on successful parsing.
|
||||
// If diagnostic is non-null, a diagnostic is emitted on failed parsing.
|
||||
// If diagnostic is null the context's message consumer
|
||||
// will be used to emit any errors. If a callback returns anything other than
|
||||
// SPV_SUCCESS, then that status code is returned, no further callbacks are
|
||||
// issued, and no additional diagnostics are emitted.
|
||||
// This is a wrapper around the C API spvBinaryParse.
|
||||
bool Parse(const std::vector<uint32_t>& binary,
|
||||
const HeaderParser& header_parser,
|
||||
const InstructionParser& instruction_parser,
|
||||
spv_diagnostic* diagnostic = nullptr);
|
||||
|
||||
// Validates the given SPIR-V |binary|. Returns true if no issues are found.
|
||||
// Otherwise, returns false and communicates issues via the message consumer
|
||||
// registered.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself.
|
||||
bool Validate(const std::vector<uint32_t>& binary) const;
|
||||
// Like the previous overload, but provides the binary as a pointer and size:
|
||||
// |binary_size| specifies the number of words in |binary|.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself.
|
||||
bool Validate(const uint32_t* binary, size_t binary_size) const;
|
||||
// Like the previous overload, but takes an options object.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself, or in the validator options.
|
||||
bool Validate(const uint32_t* binary, size_t binary_size,
|
||||
spv_validator_options options) const;
|
||||
|
||||
// Was this object successfully constructed.
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
struct SPIRV_TOOLS_LOCAL
|
||||
Impl; // Opaque struct for holding the data fields used by this class.
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to implementation data.
|
||||
};
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
104
thermion_dart/native/include/filament/spirv-tools/linker.hpp
Normal file
104
thermion_dart/native/include/filament/spirv-tools/linker.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
// Copyright (c) 2017 Pierre Moreau
|
||||
//
|
||||
// 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 INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "libspirv.hpp"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
class SPIRV_TOOLS_EXPORT LinkerOptions {
|
||||
public:
|
||||
// Returns whether a library or an executable should be produced by the
|
||||
// linking phase.
|
||||
//
|
||||
// All exported symbols are kept when creating a library, whereas they will
|
||||
// be removed when creating an executable.
|
||||
// The returned value will be true if creating a library, and false if
|
||||
// creating an executable.
|
||||
bool GetCreateLibrary() const { return create_library_; }
|
||||
|
||||
// Sets whether a library or an executable should be produced.
|
||||
void SetCreateLibrary(bool create_library) {
|
||||
create_library_ = create_library;
|
||||
}
|
||||
|
||||
// Returns whether to verify the uniqueness of the unique ids in the merged
|
||||
// context.
|
||||
bool GetVerifyIds() const { return verify_ids_; }
|
||||
|
||||
// Sets whether to verify the uniqueness of the unique ids in the merged
|
||||
// context.
|
||||
void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
|
||||
|
||||
// Returns whether to allow for imported symbols to have no corresponding
|
||||
// exported symbols
|
||||
bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
|
||||
|
||||
// Sets whether to allow for imported symbols to have no corresponding
|
||||
// exported symbols
|
||||
void SetAllowPartialLinkage(bool allow_partial_linkage) {
|
||||
allow_partial_linkage_ = allow_partial_linkage;
|
||||
}
|
||||
|
||||
bool GetUseHighestVersion() const { return use_highest_version_; }
|
||||
void SetUseHighestVersion(bool use_highest_vers) {
|
||||
use_highest_version_ = use_highest_vers;
|
||||
}
|
||||
|
||||
bool GetAllowPtrTypeMismatch() const { return allow_ptr_type_mismatch_; }
|
||||
void SetAllowPtrTypeMismatch(bool allow_ptr_type_mismatch) {
|
||||
allow_ptr_type_mismatch_ = allow_ptr_type_mismatch;
|
||||
}
|
||||
|
||||
private:
|
||||
bool create_library_{false};
|
||||
bool verify_ids_{false};
|
||||
bool allow_partial_linkage_{false};
|
||||
bool use_highest_version_{false};
|
||||
bool allow_ptr_type_mismatch_{false};
|
||||
};
|
||||
|
||||
// Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
|
||||
// several SPIR-V modules into one, resolving link dependencies between them.
|
||||
//
|
||||
// At least one binary has to be provided in |binaries|. Those binaries do not
|
||||
// have to be valid, but they should be at least parseable.
|
||||
// The functions can fail due to the following:
|
||||
// * The given context was not initialised using `spvContextCreate()`;
|
||||
// * No input modules were given;
|
||||
// * One or more of those modules were not parseable;
|
||||
// * The input modules used different addressing or memory models;
|
||||
// * The ID or global variable number limit were exceeded;
|
||||
// * Some entry points were defined multiple times;
|
||||
// * Some imported symbols did not have an exported counterpart;
|
||||
// * Possibly other reasons.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t
|
||||
Link(const Context& context, const std::vector<std::vector<uint32_t>>& binaries,
|
||||
std::vector<uint32_t>* linked_binary,
|
||||
const LinkerOptions& options = LinkerOptions());
|
||||
SPIRV_TOOLS_EXPORT spv_result_t
|
||||
Link(const Context& context, const uint32_t* const* binaries,
|
||||
const size_t* binary_sizes, size_t num_binaries,
|
||||
std::vector<uint32_t>* linked_binary,
|
||||
const LinkerOptions& options = LinkerOptions());
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
973
thermion_dart/native/include/filament/spirv-tools/optimizer.hpp
Normal file
973
thermion_dart/native/include/filament/spirv-tools/optimizer.hpp
Normal file
@@ -0,0 +1,973 @@
|
||||
// Copyright (c) 2016 Google Inc.
|
||||
//
|
||||
// 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 INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "libspirv.hpp"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
namespace opt {
|
||||
class Pass;
|
||||
struct DescriptorSetAndBinding;
|
||||
} // namespace opt
|
||||
|
||||
// C++ interface for SPIR-V optimization functionalities. It wraps the context
|
||||
// (including target environment and the corresponding SPIR-V grammar) and
|
||||
// provides methods for registering optimization passes and optimizing.
|
||||
//
|
||||
// Instances of this class provides basic thread-safety guarantee.
|
||||
class SPIRV_TOOLS_EXPORT Optimizer {
|
||||
public:
|
||||
// The token for an optimization pass. It is returned via one of the
|
||||
// Create*Pass() standalone functions at the end of this header file and
|
||||
// consumed by the RegisterPass() method. Tokens are one-time objects that
|
||||
// only support move; copying is not allowed.
|
||||
struct PassToken {
|
||||
struct SPIRV_TOOLS_LOCAL Impl; // Opaque struct for holding internal data.
|
||||
|
||||
PassToken(std::unique_ptr<Impl>);
|
||||
|
||||
// Tokens for built-in passes should be created using Create*Pass functions
|
||||
// below; for out-of-tree passes, use this constructor instead.
|
||||
// Note that this API isn't guaranteed to be stable and may change without
|
||||
// preserving source or binary compatibility in the future.
|
||||
PassToken(std::unique_ptr<opt::Pass>&& pass);
|
||||
|
||||
// Tokens can only be moved. Copying is disabled.
|
||||
PassToken(const PassToken&) = delete;
|
||||
PassToken(PassToken&&);
|
||||
PassToken& operator=(const PassToken&) = delete;
|
||||
PassToken& operator=(PassToken&&);
|
||||
|
||||
~PassToken();
|
||||
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
|
||||
};
|
||||
|
||||
// Constructs an instance with the given target |env|, which is used to decode
|
||||
// the binaries to be optimized later.
|
||||
//
|
||||
// The instance will have an empty message consumer, which ignores all
|
||||
// messages from the library. Use SetMessageConsumer() to supply a consumer
|
||||
// if messages are of concern.
|
||||
explicit Optimizer(spv_target_env env);
|
||||
|
||||
// Disables copy/move constructor/assignment operations.
|
||||
Optimizer(const Optimizer&) = delete;
|
||||
Optimizer(Optimizer&&) = delete;
|
||||
Optimizer& operator=(const Optimizer&) = delete;
|
||||
Optimizer& operator=(Optimizer&&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~Optimizer();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Returns a reference to the registered message consumer.
|
||||
const MessageConsumer& consumer() const;
|
||||
|
||||
// Registers the given |pass| to this optimizer. Passes will be run in the
|
||||
// exact order of registration. The token passed in will be consumed by this
|
||||
// method.
|
||||
Optimizer& RegisterPass(PassToken&& pass);
|
||||
|
||||
// Registers passes that attempt to improve performance of generated code.
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated.
|
||||
Optimizer& RegisterPerformancePasses();
|
||||
Optimizer& RegisterPerformancePasses(bool preserve_interface);
|
||||
|
||||
// Registers passes that attempt to improve the size of generated code.
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated.
|
||||
Optimizer& RegisterSizePasses();
|
||||
Optimizer& RegisterSizePasses(bool preserve_interface);
|
||||
|
||||
// Registers passes that attempt to legalize the generated code.
|
||||
//
|
||||
// Note: this recipe is specially designed for legalizing SPIR-V. It should be
|
||||
// used by compilers after translating HLSL source code literally. It should
|
||||
// *not* be used by general workloads for performance or size improvement.
|
||||
//
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated.
|
||||
Optimizer& RegisterLegalizationPasses();
|
||||
Optimizer& RegisterLegalizationPasses(bool preserve_interface);
|
||||
|
||||
// Register passes specified in the list of |flags|. Each flag must be a
|
||||
// string of a form accepted by Optimizer::FlagHasValidForm().
|
||||
//
|
||||
// If the list of flags contains an invalid entry, it returns false and an
|
||||
// error message is emitted to the MessageConsumer object (use
|
||||
// Optimizer::SetMessageConsumer to define a message consumer, if needed).
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated.
|
||||
//
|
||||
// If all the passes are registered successfully, it returns true.
|
||||
bool RegisterPassesFromFlags(const std::vector<std::string>& flags);
|
||||
bool RegisterPassesFromFlags(const std::vector<std::string>& flags,
|
||||
bool preserve_interface);
|
||||
|
||||
// Registers the optimization pass associated with |flag|. This only accepts
|
||||
// |flag| values of the form "--pass_name[=pass_args]". If no such pass
|
||||
// exists, it returns false. Otherwise, the pass is registered and it returns
|
||||
// true.
|
||||
//
|
||||
// The following flags have special meaning:
|
||||
//
|
||||
// -O: Registers all performance optimization passes
|
||||
// (Optimizer::RegisterPerformancePasses)
|
||||
//
|
||||
// -Os: Registers all size optimization passes
|
||||
// (Optimizer::RegisterSizePasses).
|
||||
//
|
||||
// --legalize-hlsl: Registers all passes that legalize SPIR-V generated by an
|
||||
// HLSL front-end.
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated.
|
||||
bool RegisterPassFromFlag(const std::string& flag);
|
||||
bool RegisterPassFromFlag(const std::string& flag, bool preserve_interface);
|
||||
|
||||
// Validates that |flag| has a valid format. Strings accepted:
|
||||
//
|
||||
// --pass_name[=pass_args]
|
||||
// -O
|
||||
// -Os
|
||||
//
|
||||
// If |flag| takes one of the forms above, it returns true. Otherwise, it
|
||||
// returns false.
|
||||
bool FlagHasValidForm(const std::string& flag) const;
|
||||
|
||||
// Allows changing, after creation time, the target environment to be
|
||||
// optimized for and validated. Should be called before calling Run().
|
||||
void SetTargetEnv(const spv_target_env env);
|
||||
|
||||
// Optimizes the given SPIR-V module |original_binary| and writes the
|
||||
// optimized binary into |optimized_binary|. The optimized binary uses
|
||||
// the same SPIR-V version as the original binary.
|
||||
//
|
||||
// Returns true on successful optimization, whether or not the module is
|
||||
// modified. Returns false if |original_binary| fails to validate or if errors
|
||||
// occur when processing |original_binary| using any of the registered passes.
|
||||
// In that case, no further passes are executed and the contents in
|
||||
// |optimized_binary| may be invalid.
|
||||
//
|
||||
// By default, the binary is validated before any transforms are performed,
|
||||
// and optionally after each transform. Validation uses SPIR-V spec rules
|
||||
// for the SPIR-V version named in the binary's header (at word offset 1).
|
||||
// Additionally, if the target environment is a client API (such as
|
||||
// Vulkan 1.1), then validate for that client API version, to the extent
|
||||
// that it is verifiable from data in the binary itself.
|
||||
//
|
||||
// It's allowed to alias |original_binary| to the start of |optimized_binary|.
|
||||
bool Run(const uint32_t* original_binary, size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary) const;
|
||||
|
||||
// DEPRECATED: Same as above, except passes |options| to the validator when
|
||||
// trying to validate the binary. If |skip_validation| is true, then the
|
||||
// caller is guaranteeing that |original_binary| is valid, and the validator
|
||||
// will not be run. The |max_id_bound| is the limit on the max id in the
|
||||
// module.
|
||||
bool Run(const uint32_t* original_binary, const size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary,
|
||||
const ValidatorOptions& options, bool skip_validation) const;
|
||||
|
||||
// Same as above, except it takes an options object. See the documentation
|
||||
// for |OptimizerOptions| to see which options can be set.
|
||||
//
|
||||
// By default, the binary is validated before any transforms are performed,
|
||||
// and optionally after each transform. Validation uses SPIR-V spec rules
|
||||
// for the SPIR-V version named in the binary's header (at word offset 1).
|
||||
// Additionally, if the target environment is a client API (such as
|
||||
// Vulkan 1.1), then validate for that client API version, to the extent
|
||||
// that it is verifiable from data in the binary itself, or from the
|
||||
// validator options set on the optimizer options.
|
||||
bool Run(const uint32_t* original_binary, const size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary,
|
||||
const spv_optimizer_options opt_options) const;
|
||||
|
||||
// Returns a vector of strings with all the pass names added to this
|
||||
// optimizer's pass manager. These strings are valid until the associated
|
||||
// pass manager is destroyed.
|
||||
std::vector<const char*> GetPassNames() const;
|
||||
|
||||
// Sets the option to print the disassembly before each pass and after the
|
||||
// last pass. If |out| is null, then no output is generated. Otherwise,
|
||||
// output is sent to the |out| output stream.
|
||||
Optimizer& SetPrintAll(std::ostream* out);
|
||||
|
||||
// Sets the option to print the resource utilization of each pass. If |out|
|
||||
// is null, then no output is generated. Otherwise, output is sent to the
|
||||
// |out| output stream.
|
||||
Optimizer& SetTimeReport(std::ostream* out);
|
||||
|
||||
// Sets the option to validate the module after each pass.
|
||||
Optimizer& SetValidateAfterAll(bool validate);
|
||||
|
||||
private:
|
||||
struct SPIRV_TOOLS_LOCAL Impl; // Opaque struct for holding internal data.
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
|
||||
};
|
||||
|
||||
// Creates a null pass.
|
||||
// A null pass does nothing to the SPIR-V module to be optimized.
|
||||
Optimizer::PassToken CreateNullPass();
|
||||
|
||||
// Creates a strip-debug-info pass.
|
||||
// A strip-debug-info pass removes all debug instructions (as documented in
|
||||
// Section 3.42.2 of the SPIR-V spec) of the SPIR-V module to be optimized.
|
||||
Optimizer::PassToken CreateStripDebugInfoPass();
|
||||
|
||||
// [Deprecated] This will create a strip-nonsemantic-info pass. See below.
|
||||
Optimizer::PassToken CreateStripReflectInfoPass();
|
||||
|
||||
// Creates a strip-nonsemantic-info pass.
|
||||
// A strip-nonsemantic-info pass removes all reflections and explicitly
|
||||
// non-semantic instructions.
|
||||
Optimizer::PassToken CreateStripNonSemanticInfoPass();
|
||||
|
||||
// Creates an eliminate-dead-functions pass.
|
||||
// An eliminate-dead-functions pass will remove all functions that are not in
|
||||
// the call trees rooted at entry points and exported functions. These
|
||||
// functions are not needed because they will never be called.
|
||||
Optimizer::PassToken CreateEliminateDeadFunctionsPass();
|
||||
|
||||
// Creates an eliminate-dead-members pass.
|
||||
// An eliminate-dead-members pass will remove all unused members of structures.
|
||||
// This will not affect the data layout of the remaining members.
|
||||
Optimizer::PassToken CreateEliminateDeadMembersPass();
|
||||
|
||||
// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
|
||||
// to the default values in the form of string.
|
||||
// A set-spec-constant-default-value pass sets the default values for the
|
||||
// spec constants that have SpecId decorations (i.e., those defined by
|
||||
// OpSpecConstant{|True|False} instructions).
|
||||
Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
|
||||
const std::unordered_map<uint32_t, std::string>& id_value_map);
|
||||
|
||||
// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
|
||||
// to the default values in the form of bit pattern.
|
||||
// A set-spec-constant-default-value pass sets the default values for the
|
||||
// spec constants that have SpecId decorations (i.e., those defined by
|
||||
// OpSpecConstant{|True|False} instructions).
|
||||
Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
|
||||
const std::unordered_map<uint32_t, std::vector<uint32_t>>& id_value_map);
|
||||
|
||||
// Creates a flatten-decoration pass.
|
||||
// A flatten-decoration pass replaces grouped decorations with equivalent
|
||||
// ungrouped decorations. That is, it replaces each OpDecorationGroup
|
||||
// instruction and associated OpGroupDecorate and OpGroupMemberDecorate
|
||||
// instructions with equivalent OpDecorate and OpMemberDecorate instructions.
|
||||
// The pass does not attempt to preserve debug information for instructions
|
||||
// it removes.
|
||||
Optimizer::PassToken CreateFlattenDecorationPass();
|
||||
|
||||
// Creates a freeze-spec-constant-value pass.
|
||||
// A freeze-spec-constant pass specializes the value of spec constants to
|
||||
// their default values. This pass only processes the spec constants that have
|
||||
// SpecId decorations (defined by OpSpecConstant, OpSpecConstantTrue, or
|
||||
// OpSpecConstantFalse instructions) and replaces them with their normal
|
||||
// counterparts (OpConstant, OpConstantTrue, or OpConstantFalse). The
|
||||
// corresponding SpecId annotation instructions will also be removed. This
|
||||
// pass does not fold the newly added normal constants and does not process
|
||||
// other spec constants defined by OpSpecConstantComposite or
|
||||
// OpSpecConstantOp.
|
||||
Optimizer::PassToken CreateFreezeSpecConstantValuePass();
|
||||
|
||||
// Creates a fold-spec-constant-op-and-composite pass.
|
||||
// A fold-spec-constant-op-and-composite pass folds spec constants defined by
|
||||
// OpSpecConstantOp or OpSpecConstantComposite instruction, to normal Constants
|
||||
// defined by OpConstantTrue, OpConstantFalse, OpConstant, OpConstantNull, or
|
||||
// OpConstantComposite instructions. Note that spec constants defined with
|
||||
// OpSpecConstant, OpSpecConstantTrue, or OpSpecConstantFalse instructions are
|
||||
// not handled, as these instructions indicate their value are not determined
|
||||
// and can be changed in future. A spec constant is foldable if all of its
|
||||
// value(s) can be determined from the module. E.g., an integer spec constant
|
||||
// defined with OpSpecConstantOp instruction can be folded if its value won't
|
||||
// change later. This pass will replace the original OpSpecConstantOp
|
||||
// instruction with an OpConstant instruction. When folding composite spec
|
||||
// constants, new instructions may be inserted to define the components of the
|
||||
// composite constant first, then the original spec constants will be replaced
|
||||
// by OpConstantComposite instructions.
|
||||
//
|
||||
// There are some operations not supported yet:
|
||||
// OpSConvert, OpFConvert, OpQuantizeToF16 and
|
||||
// all the operations under Kernel capability.
|
||||
// TODO(qining): Add support for the operations listed above.
|
||||
Optimizer::PassToken CreateFoldSpecConstantOpAndCompositePass();
|
||||
|
||||
// Creates a unify-constant pass.
|
||||
// A unify-constant pass de-duplicates the constants. Constants with the exact
|
||||
// same value and identical form will be unified and only one constant will
|
||||
// be kept for each unique pair of type and value.
|
||||
// There are several cases not handled by this pass:
|
||||
// 1) Constants defined by OpConstantNull instructions (null constants) and
|
||||
// constants defined by OpConstantFalse, OpConstant or OpConstantComposite
|
||||
// with value 0 (zero-valued normal constants) are not considered equivalent.
|
||||
// So null constants won't be used to replace zero-valued normal constants,
|
||||
// vice versa.
|
||||
// 2) Whenever there are decorations to the constant's result id id, the
|
||||
// constant won't be handled, which means, it won't be used to replace any
|
||||
// other constants, neither can other constants replace it.
|
||||
// 3) NaN in float point format with different bit patterns are not unified.
|
||||
Optimizer::PassToken CreateUnifyConstantPass();
|
||||
|
||||
// Creates a eliminate-dead-constant pass.
|
||||
// A eliminate-dead-constant pass removes dead constants, including normal
|
||||
// constants defined by OpConstant, OpConstantComposite, OpConstantTrue, or
|
||||
// OpConstantFalse and spec constants defined by OpSpecConstant,
|
||||
// OpSpecConstantComposite, OpSpecConstantTrue, OpSpecConstantFalse or
|
||||
// OpSpecConstantOp.
|
||||
Optimizer::PassToken CreateEliminateDeadConstantPass();
|
||||
|
||||
// Creates a strength-reduction pass.
|
||||
// A strength-reduction pass will look for opportunities to replace an
|
||||
// instruction with an equivalent and less expensive one. For example,
|
||||
// multiplying by a power of 2 can be replaced by a bit shift.
|
||||
Optimizer::PassToken CreateStrengthReductionPass();
|
||||
|
||||
// Creates a block merge pass.
|
||||
// This pass searches for blocks with a single Branch to a block with no
|
||||
// other predecessors and merges the blocks into a single block. Continue
|
||||
// blocks and Merge blocks are not candidates for the second block.
|
||||
//
|
||||
// The pass is most useful after Dead Branch Elimination, which can leave
|
||||
// such sequences of blocks. Merging them makes subsequent passes more
|
||||
// effective, such as single block local store-load elimination.
|
||||
//
|
||||
// While this pass reduces the number of occurrences of this sequence, at
|
||||
// this time it does not guarantee all such sequences are eliminated.
|
||||
//
|
||||
// Presence of phi instructions can inhibit this optimization. Handling
|
||||
// these is left for future improvements.
|
||||
Optimizer::PassToken CreateBlockMergePass();
|
||||
|
||||
// Creates an exhaustive inline pass.
|
||||
// An exhaustive inline pass attempts to exhaustively inline all function
|
||||
// calls in all functions in an entry point call tree. The intent is to enable,
|
||||
// albeit through brute force, analysis and optimization across function
|
||||
// calls by subsequent optimization passes. As the inlining is exhaustive,
|
||||
// there is no attempt to optimize for size or runtime performance. Functions
|
||||
// that are not in the call tree of an entry point are not changed.
|
||||
Optimizer::PassToken CreateInlineExhaustivePass();
|
||||
|
||||
// Creates an opaque inline pass.
|
||||
// An opaque inline pass inlines all function calls in all functions in all
|
||||
// entry point call trees where the called function contains an opaque type
|
||||
// in either its parameter types or return type. An opaque type is currently
|
||||
// defined as Image, Sampler or SampledImage. The intent is to enable, albeit
|
||||
// through brute force, analysis and optimization across these function calls
|
||||
// by subsequent passes in order to remove the storing of opaque types which is
|
||||
// not legal in Vulkan. Functions that are not in the call tree of an entry
|
||||
// point are not changed.
|
||||
Optimizer::PassToken CreateInlineOpaquePass();
|
||||
|
||||
// Creates a single-block local variable load/store elimination pass.
|
||||
// For every entry point function, do single block memory optimization of
|
||||
// function variables referenced only with non-access-chain loads and stores.
|
||||
// For each targeted variable load, if previous store to that variable in the
|
||||
// block, replace the load's result id with the value id of the store.
|
||||
// If previous load within the block, replace the current load's result id
|
||||
// with the previous load's result id. In either case, delete the current
|
||||
// load. Finally, check if any remaining stores are useless, and delete store
|
||||
// and variable if possible.
|
||||
//
|
||||
// The presence of access chain references and function calls can inhibit
|
||||
// the above optimization.
|
||||
//
|
||||
// Only modules with relaxed logical addressing (see opt/instruction.h) are
|
||||
// currently processed.
|
||||
//
|
||||
// This pass is most effective if preceded by Inlining and
|
||||
// LocalAccessChainConvert. This pass will reduce the work needed to be done
|
||||
// by LocalSingleStoreElim and LocalMultiStoreElim.
|
||||
//
|
||||
// Only functions in the call tree of an entry point are processed.
|
||||
Optimizer::PassToken CreateLocalSingleBlockLoadStoreElimPass();
|
||||
|
||||
// Create dead branch elimination pass.
|
||||
// For each entry point function, this pass will look for SelectionMerge
|
||||
// BranchConditionals with constant condition and convert to a Branch to
|
||||
// the indicated label. It will delete resulting dead blocks.
|
||||
//
|
||||
// For all phi functions in merge block, replace all uses with the id
|
||||
// corresponding to the living predecessor.
|
||||
//
|
||||
// Note that some branches and blocks may be left to avoid creating invalid
|
||||
// control flow. Improving this is left to future work.
|
||||
//
|
||||
// This pass is most effective when preceded by passes which eliminate
|
||||
// local loads and stores, effectively propagating constant values where
|
||||
// possible.
|
||||
Optimizer::PassToken CreateDeadBranchElimPass();
|
||||
|
||||
// Creates an SSA local variable load/store elimination pass.
|
||||
// For every entry point function, eliminate all loads and stores of function
|
||||
// scope variables only referenced with non-access-chain loads and stores.
|
||||
// Eliminate the variables as well.
|
||||
//
|
||||
// The presence of access chain references and function calls can inhibit
|
||||
// the above optimization.
|
||||
//
|
||||
// Only shader modules with relaxed logical addressing (see opt/instruction.h)
|
||||
// are currently processed. Currently modules with any extensions enabled are
|
||||
// not processed. This is left for future work.
|
||||
//
|
||||
// This pass is most effective if preceded by Inlining and
|
||||
// LocalAccessChainConvert. LocalSingleStoreElim and LocalSingleBlockElim
|
||||
// will reduce the work that this pass has to do.
|
||||
Optimizer::PassToken CreateLocalMultiStoreElimPass();
|
||||
|
||||
// Creates a local access chain conversion pass.
|
||||
// A local access chain conversion pass identifies all function scope
|
||||
// variables which are accessed only with loads, stores and access chains
|
||||
// with constant indices. It then converts all loads and stores of such
|
||||
// variables into equivalent sequences of loads, stores, extracts and inserts.
|
||||
//
|
||||
// This pass only processes entry point functions. It currently only converts
|
||||
// non-nested, non-ptr access chains. It does not process modules with
|
||||
// non-32-bit integer types present. Optional memory access options on loads
|
||||
// and stores are ignored as we are only processing function scope variables.
|
||||
//
|
||||
// This pass unifies access to these variables to a single mode and simplifies
|
||||
// subsequent analysis and elimination of these variables along with their
|
||||
// loads and stores allowing values to propagate to their points of use where
|
||||
// possible.
|
||||
Optimizer::PassToken CreateLocalAccessChainConvertPass();
|
||||
|
||||
// Creates a local single store elimination pass.
|
||||
// For each entry point function, this pass eliminates loads and stores for
|
||||
// function scope variable that are stored to only once, where possible. Only
|
||||
// whole variable loads and stores are eliminated; access-chain references are
|
||||
// not optimized. Replace all loads of such variables with the value that is
|
||||
// stored and eliminate any resulting dead code.
|
||||
//
|
||||
// Currently, the presence of access chains and function calls can inhibit this
|
||||
// pass, however the Inlining and LocalAccessChainConvert passes can make it
|
||||
// more effective. In additional, many non-load/store memory operations are
|
||||
// not supported and will prohibit optimization of a function. Support of
|
||||
// these operations are future work.
|
||||
//
|
||||
// Only shader modules with relaxed logical addressing (see opt/instruction.h)
|
||||
// are currently processed.
|
||||
//
|
||||
// This pass will reduce the work needed to be done by LocalSingleBlockElim
|
||||
// and LocalMultiStoreElim and can improve the effectiveness of other passes
|
||||
// such as DeadBranchElimination which depend on values for their analysis.
|
||||
Optimizer::PassToken CreateLocalSingleStoreElimPass();
|
||||
|
||||
// Creates an insert/extract elimination pass.
|
||||
// This pass processes each entry point function in the module, searching for
|
||||
// extracts on a sequence of inserts. It further searches the sequence for an
|
||||
// insert with indices identical to the extract. If such an insert can be
|
||||
// found before hitting a conflicting insert, the extract's result id is
|
||||
// replaced with the id of the values from the insert.
|
||||
//
|
||||
// Besides removing extracts this pass enables subsequent dead code elimination
|
||||
// passes to delete the inserts. This pass performs best after access chains are
|
||||
// converted to inserts and extracts and local loads and stores are eliminated.
|
||||
Optimizer::PassToken CreateInsertExtractElimPass();
|
||||
|
||||
// Creates a dead insert elimination pass.
|
||||
// This pass processes each entry point function in the module, searching for
|
||||
// unreferenced inserts into composite types. These are most often unused
|
||||
// stores to vector components. They are unused because they are never
|
||||
// referenced, or because there is another insert to the same component between
|
||||
// the insert and the reference. After removing the inserts, dead code
|
||||
// elimination is attempted on the inserted values.
|
||||
//
|
||||
// This pass performs best after access chains are converted to inserts and
|
||||
// extracts and local loads and stores are eliminated. While executing this
|
||||
// pass can be advantageous on its own, it is also advantageous to execute
|
||||
// this pass after CreateInsertExtractPass() as it will remove any unused
|
||||
// inserts created by that pass.
|
||||
Optimizer::PassToken CreateDeadInsertElimPass();
|
||||
|
||||
// Create aggressive dead code elimination pass
|
||||
// This pass eliminates unused code from the module. In addition,
|
||||
// it detects and eliminates code which may have spurious uses but which do
|
||||
// not contribute to the output of the function. The most common cause of
|
||||
// such code sequences is summations in loops whose result is no longer used
|
||||
// due to dead code elimination. This optimization has additional compile
|
||||
// time cost over standard dead code elimination.
|
||||
//
|
||||
// This pass only processes entry point functions. It also only processes
|
||||
// shaders with relaxed logical addressing (see opt/instruction.h). It
|
||||
// currently will not process functions with function calls. Unreachable
|
||||
// functions are deleted.
|
||||
//
|
||||
// This pass will be made more effective by first running passes that remove
|
||||
// dead control flow and inlines function calls.
|
||||
//
|
||||
// This pass can be especially useful after running Local Access Chain
|
||||
// Conversion, which tends to cause cycles of dead code to be left after
|
||||
// Store/Load elimination passes are completed. These cycles cannot be
|
||||
// eliminated with standard dead code elimination.
|
||||
//
|
||||
// If |preserve_interface| is true, all non-io variables in the entry point
|
||||
// interface are considered live and are not eliminated. This mode is needed
|
||||
// by GPU-Assisted validation instrumentation, where a change in the interface
|
||||
// is not allowed.
|
||||
//
|
||||
// If |remove_outputs| is true, allow outputs to be removed from the interface.
|
||||
// This is only safe if the caller knows that there is no corresponding input
|
||||
// variable in the following shader. It is false by default.
|
||||
Optimizer::PassToken CreateAggressiveDCEPass();
|
||||
Optimizer::PassToken CreateAggressiveDCEPass(bool preserve_interface);
|
||||
Optimizer::PassToken CreateAggressiveDCEPass(bool preserve_interface,
|
||||
bool remove_outputs);
|
||||
|
||||
// Creates a remove-unused-interface-variables pass.
|
||||
// Removes variables referenced on the |OpEntryPoint| instruction that are not
|
||||
// referenced in the entry point function or any function in its call tree. Note
|
||||
// that this could cause the shader interface to no longer match other shader
|
||||
// stages.
|
||||
Optimizer::PassToken CreateRemoveUnusedInterfaceVariablesPass();
|
||||
|
||||
// Creates an empty pass.
|
||||
// This is deprecated and will be removed.
|
||||
// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
|
||||
// https://github.com/KhronosGroup/glslang/pull/2440
|
||||
Optimizer::PassToken CreatePropagateLineInfoPass();
|
||||
|
||||
// Creates an empty pass.
|
||||
// This is deprecated and will be removed.
|
||||
// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
|
||||
// https://github.com/KhronosGroup/glslang/pull/2440
|
||||
Optimizer::PassToken CreateRedundantLineInfoElimPass();
|
||||
|
||||
// Creates a compact ids pass.
|
||||
// The pass remaps result ids to a compact and gapless range starting from %1.
|
||||
Optimizer::PassToken CreateCompactIdsPass();
|
||||
|
||||
// Creates a remove duplicate pass.
|
||||
// This pass removes various duplicates:
|
||||
// * duplicate capabilities;
|
||||
// * duplicate extended instruction imports;
|
||||
// * duplicate types;
|
||||
// * duplicate decorations.
|
||||
Optimizer::PassToken CreateRemoveDuplicatesPass();
|
||||
|
||||
// Creates a CFG cleanup pass.
|
||||
// This pass removes cruft from the control flow graph of functions that are
|
||||
// reachable from entry points and exported functions. It currently includes the
|
||||
// following functionality:
|
||||
//
|
||||
// - Removal of unreachable basic blocks.
|
||||
Optimizer::PassToken CreateCFGCleanupPass();
|
||||
|
||||
// Create dead variable elimination pass.
|
||||
// This pass will delete module scope variables, along with their decorations,
|
||||
// that are not referenced.
|
||||
Optimizer::PassToken CreateDeadVariableEliminationPass();
|
||||
|
||||
// create merge return pass.
|
||||
// changes functions that have multiple return statements so they have a single
|
||||
// return statement.
|
||||
//
|
||||
// for structured control flow it is assumed that the only unreachable blocks in
|
||||
// the function are trivial merge and continue blocks.
|
||||
//
|
||||
// a trivial merge block contains the label and an opunreachable instructions,
|
||||
// nothing else. a trivial continue block contain a label and an opbranch to
|
||||
// the header, nothing else.
|
||||
//
|
||||
// these conditions are guaranteed to be met after running dead-branch
|
||||
// elimination.
|
||||
Optimizer::PassToken CreateMergeReturnPass();
|
||||
|
||||
// Create value numbering pass.
|
||||
// This pass will look for instructions in the same basic block that compute the
|
||||
// same value, and remove the redundant ones.
|
||||
Optimizer::PassToken CreateLocalRedundancyEliminationPass();
|
||||
|
||||
// Create LICM pass.
|
||||
// This pass will look for invariant instructions inside loops and hoist them to
|
||||
// the loops preheader.
|
||||
Optimizer::PassToken CreateLoopInvariantCodeMotionPass();
|
||||
|
||||
// Creates a loop fission pass.
|
||||
// This pass will split all top level loops whose register pressure exceedes the
|
||||
// given |threshold|.
|
||||
Optimizer::PassToken CreateLoopFissionPass(size_t threshold);
|
||||
|
||||
// Creates a loop fusion pass.
|
||||
// This pass will look for adjacent loops that are compatible and legal to be
|
||||
// fused. The fuse all such loops as long as the register usage for the fused
|
||||
// loop stays under the threshold defined by |max_registers_per_loop|.
|
||||
Optimizer::PassToken CreateLoopFusionPass(size_t max_registers_per_loop);
|
||||
|
||||
// Creates a loop peeling pass.
|
||||
// This pass will look for conditions inside a loop that are true or false only
|
||||
// for the N first or last iteration. For loop with such condition, those N
|
||||
// iterations of the loop will be executed outside of the main loop.
|
||||
// To limit code size explosion, the loop peeling can only happen if the code
|
||||
// size growth for each loop is under |code_growth_threshold|.
|
||||
Optimizer::PassToken CreateLoopPeelingPass();
|
||||
|
||||
// Creates a loop unswitch pass.
|
||||
// This pass will look for loop independent branch conditions and move the
|
||||
// condition out of the loop and version the loop based on the taken branch.
|
||||
// Works best after LICM and local multi store elimination pass.
|
||||
Optimizer::PassToken CreateLoopUnswitchPass();
|
||||
|
||||
// Create global value numbering pass.
|
||||
// This pass will look for instructions where the same value is computed on all
|
||||
// paths leading to the instruction. Those instructions are deleted.
|
||||
Optimizer::PassToken CreateRedundancyEliminationPass();
|
||||
|
||||
// Create scalar replacement pass.
|
||||
// This pass replaces composite function scope variables with variables for each
|
||||
// element if those elements are accessed individually. The parameter is a
|
||||
// limit on the number of members in the composite variable that the pass will
|
||||
// consider replacing.
|
||||
Optimizer::PassToken CreateScalarReplacementPass(uint32_t size_limit = 100);
|
||||
|
||||
// Create a private to local pass.
|
||||
// This pass looks for variables declared in the private storage class that are
|
||||
// used in only one function. Those variables are moved to the function storage
|
||||
// class in the function that they are used.
|
||||
Optimizer::PassToken CreatePrivateToLocalPass();
|
||||
|
||||
// Creates a conditional constant propagation (CCP) pass.
|
||||
// This pass implements the SSA-CCP algorithm in
|
||||
//
|
||||
// Constant propagation with conditional branches,
|
||||
// Wegman and Zadeck, ACM TOPLAS 13(2):181-210.
|
||||
//
|
||||
// Constant values in expressions and conditional jumps are folded and
|
||||
// simplified. This may reduce code size by removing never executed jump targets
|
||||
// and computations with constant operands.
|
||||
Optimizer::PassToken CreateCCPPass();
|
||||
|
||||
// Creates a workaround driver bugs pass. This pass attempts to work around
|
||||
// a known driver bug (issue #1209) by identifying the bad code sequences and
|
||||
// rewriting them.
|
||||
//
|
||||
// Current workaround: Avoid OpUnreachable instructions in loops.
|
||||
Optimizer::PassToken CreateWorkaround1209Pass();
|
||||
|
||||
// Creates a pass that converts if-then-else like assignments into OpSelect.
|
||||
Optimizer::PassToken CreateIfConversionPass();
|
||||
|
||||
// Creates a pass that will replace instructions that are not valid for the
|
||||
// current shader stage by constants. Has no effect on non-shader modules.
|
||||
Optimizer::PassToken CreateReplaceInvalidOpcodePass();
|
||||
|
||||
// Creates a pass that simplifies instructions using the instruction folder.
|
||||
Optimizer::PassToken CreateSimplificationPass();
|
||||
|
||||
// Create loop unroller pass.
|
||||
// Creates a pass to unroll loops which have the "Unroll" loop control
|
||||
// mask set. The loops must meet a specific criteria in order to be unrolled
|
||||
// safely this criteria is checked before doing the unroll by the
|
||||
// LoopUtils::CanPerformUnroll method. Any loop that does not meet the criteria
|
||||
// won't be unrolled. See CanPerformUnroll LoopUtils.h for more information.
|
||||
Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
|
||||
|
||||
// Create the SSA rewrite pass.
|
||||
// This pass converts load/store operations on function local variables into
|
||||
// operations on SSA IDs. This allows SSA optimizers to act on these variables.
|
||||
// Only variables that are local to the function and of supported types are
|
||||
// processed (see IsSSATargetVar for details).
|
||||
Optimizer::PassToken CreateSSARewritePass();
|
||||
|
||||
// Create pass to convert relaxed precision instructions to half precision.
|
||||
// This pass converts as many relaxed float32 arithmetic operations to half as
|
||||
// possible. It converts any float32 operands to half if needed. It converts
|
||||
// any resulting half precision values back to float32 as needed. No variables
|
||||
// are changed. No image operations are changed.
|
||||
//
|
||||
// Best if run after function scope store/load and composite operation
|
||||
// eliminations are run. Also best if followed by instruction simplification,
|
||||
// redundancy elimination and DCE.
|
||||
Optimizer::PassToken CreateConvertRelaxedToHalfPass();
|
||||
|
||||
// Create relax float ops pass.
|
||||
// This pass decorates all float32 result instructions with RelaxedPrecision
|
||||
// if not already so decorated.
|
||||
Optimizer::PassToken CreateRelaxFloatOpsPass();
|
||||
|
||||
// Create copy propagate arrays pass.
|
||||
// This pass looks to copy propagate memory references for arrays. It looks
|
||||
// for specific code patterns to recognize array copies.
|
||||
Optimizer::PassToken CreateCopyPropagateArraysPass();
|
||||
|
||||
// Create a vector dce pass.
|
||||
// This pass looks for components of vectors that are unused, and removes them
|
||||
// from the vector. Note this would still leave around lots of dead code that
|
||||
// a pass of ADCE will be able to remove.
|
||||
Optimizer::PassToken CreateVectorDCEPass();
|
||||
|
||||
// Create a pass to reduce the size of loads.
|
||||
// This pass looks for loads of structures where only a few of its members are
|
||||
// used. It replaces the loads feeding an OpExtract with an OpAccessChain and
|
||||
// a load of the specific elements. The parameter is a threshold to determine
|
||||
// whether we have to replace the load or not. If the ratio of the used
|
||||
// components of the load is less than the threshold, we replace the load.
|
||||
Optimizer::PassToken CreateReduceLoadSizePass(
|
||||
double load_replacement_threshold = 0.9);
|
||||
|
||||
// Create a pass to combine chained access chains.
|
||||
// This pass looks for access chains fed by other access chains and combines
|
||||
// them into a single instruction where possible.
|
||||
Optimizer::PassToken CreateCombineAccessChainsPass();
|
||||
|
||||
// Create a pass to upgrade to the VulkanKHR memory model.
|
||||
// This pass upgrades the Logical GLSL450 memory model to Logical VulkanKHR.
|
||||
// Additionally, it modifies memory, image, atomic and barrier operations to
|
||||
// conform to that model's requirements.
|
||||
Optimizer::PassToken CreateUpgradeMemoryModelPass();
|
||||
|
||||
// Create a pass to do code sinking. Code sinking is a transformation
|
||||
// where an instruction is moved into a more deeply nested construct.
|
||||
Optimizer::PassToken CreateCodeSinkingPass();
|
||||
|
||||
// Create a pass to fix incorrect storage classes. In order to make code
|
||||
// generation simpler, DXC may generate code where the storage classes do not
|
||||
// match up correctly. This pass will fix the errors that it can.
|
||||
Optimizer::PassToken CreateFixStorageClassPass();
|
||||
|
||||
// Creates a graphics robust access pass.
|
||||
//
|
||||
// This pass injects code to clamp indexed accesses to buffers and internal
|
||||
// arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
|
||||
//
|
||||
// TODO(dneto): Clamps coordinates and sample index for pointer calculations
|
||||
// into storage images (OpImageTexelPointer). For an cube array image, it
|
||||
// assumes the maximum layer count times 6 is at most 0xffffffff.
|
||||
//
|
||||
// NOTE: This pass will fail with a message if:
|
||||
// - The module is not a Shader module.
|
||||
// - The module declares VariablePointers, VariablePointersStorageBuffer, or
|
||||
// RuntimeDescriptorArrayEXT capabilities.
|
||||
// - The module uses an addressing model other than Logical
|
||||
// - Access chain indices are wider than 64 bits.
|
||||
// - Access chain index for a struct is not an OpConstant integer or is out
|
||||
// of range. (The module is already invalid if that is the case.)
|
||||
// - TODO(dneto): The OpImageTexelPointer coordinate component is not 32-bits
|
||||
// wide.
|
||||
//
|
||||
// NOTE: Access chain indices are always treated as signed integers. So
|
||||
// if an array has a fixed size of more than 2^31 elements, then elements
|
||||
// from 2^31 and above are never accessible with a 32-bit index,
|
||||
// signed or unsigned. For this case, this pass will clamp the index
|
||||
// between 0 and at 2^31-1, inclusive.
|
||||
// Similarly, if an array has more then 2^15 element and is accessed with
|
||||
// a 16-bit index, then elements from 2^15 and above are not accessible.
|
||||
// In this case, the pass will clamp the index between 0 and 2^15-1
|
||||
// inclusive.
|
||||
Optimizer::PassToken CreateGraphicsRobustAccessPass();
|
||||
|
||||
// Create a pass to spread Volatile semantics to variables with SMIDNV,
|
||||
// WarpIDNV, SubgroupSize, SubgroupLocalInvocationId, SubgroupEqMask,
|
||||
// SubgroupGeMask, SubgroupGtMask, SubgroupLeMask, or SubgroupLtMask BuiltIn
|
||||
// decorations or OpLoad for them when the shader model is the ray generation,
|
||||
// closest hit, miss, intersection, or callable. This pass can be used for
|
||||
// VUID-StandaloneSpirv-VulkanMemoryModel-04678 and
|
||||
// VUID-StandaloneSpirv-VulkanMemoryModel-04679 (See "Standalone SPIR-V
|
||||
// Validation" section of Vulkan spec "Appendix A: Vulkan Environment for
|
||||
// SPIR-V"). When the SPIR-V version is 1.6 or above, the pass also spreads
|
||||
// the Volatile semantics to a variable with HelperInvocation BuiltIn decoration
|
||||
// in the fragement shader.
|
||||
Optimizer::PassToken CreateSpreadVolatileSemanticsPass();
|
||||
|
||||
// Create a pass to replace a descriptor access using variable index.
|
||||
// This pass replaces every access using a variable index to array variable
|
||||
// |desc| that has a DescriptorSet and Binding decorations with a constant
|
||||
// element of the array. In order to replace the access using a variable index
|
||||
// with the constant element, it uses a switch statement.
|
||||
Optimizer::PassToken CreateReplaceDescArrayAccessUsingVarIndexPass();
|
||||
|
||||
// Create descriptor scalar replacement pass.
|
||||
// This pass replaces every array variable |desc| that has a DescriptorSet and
|
||||
// Binding decorations with a new variable for each element of the
|
||||
// array/composite. Suppose |desc| was bound at binding |b|. Then the variable
|
||||
// corresponding to |desc[i]| will have binding |b+i|. The descriptor set will
|
||||
// be the same. It is assumed that no other variable already has a binding that
|
||||
// will used by one of the new variables. If not, the pass will generate
|
||||
// invalid Spir-V. All accesses to |desc| must be OpAccessChain instructions
|
||||
// with a literal index for the first index. This variant flattens both
|
||||
// composites and arrays.
|
||||
Optimizer::PassToken CreateDescriptorScalarReplacementPass();
|
||||
// This variant flattens only composites.
|
||||
Optimizer::PassToken CreateDescriptorCompositeScalarReplacementPass();
|
||||
// This variant flattens only arrays.
|
||||
Optimizer::PassToken CreateDescriptorArrayScalarReplacementPass();
|
||||
|
||||
// Create a pass to replace each OpKill instruction with a function call to a
|
||||
// function that has a single OpKill. Also replace each OpTerminateInvocation
|
||||
// instruction with a function call to a function that has a single
|
||||
// OpTerminateInvocation. This allows more code to be inlined.
|
||||
Optimizer::PassToken CreateWrapOpKillPass();
|
||||
|
||||
// Replaces the extensions VK_AMD_shader_ballot,VK_AMD_gcn_shader, and
|
||||
// VK_AMD_shader_trinary_minmax with equivalent code using core instructions and
|
||||
// capabilities.
|
||||
Optimizer::PassToken CreateAmdExtToKhrPass();
|
||||
|
||||
// Replaces the internal version of GLSLstd450 InterpolateAt* extended
|
||||
// instructions with the externally valid version. The internal version allows
|
||||
// an OpLoad of the interpolant for the first argument. This pass removes the
|
||||
// OpLoad and replaces it with its pointer. glslang and possibly other
|
||||
// frontends will create the internal version for HLSL. This pass will be part
|
||||
// of HLSL legalization and should be called after interpolants have been
|
||||
// propagated into their final positions.
|
||||
Optimizer::PassToken CreateInterpolateFixupPass();
|
||||
|
||||
// Replace OpExtInst instructions with OpExtInstWithForwardRefsKHR when
|
||||
// the instruction contains a forward reference to another debug instuction.
|
||||
// Replace OpExtInstWithForwardRefsKHR with OpExtInst when there are no forward
|
||||
// reference to another debug instruction.
|
||||
Optimizer::PassToken CreateOpExtInstWithForwardReferenceFixupPass();
|
||||
|
||||
// Removes unused components from composite input variables. Current
|
||||
// implementation just removes trailing unused components from input arrays
|
||||
// and structs. The pass performs best after maximizing dead code removal.
|
||||
// A subsequent dead code elimination pass would be beneficial in removing
|
||||
// newly unused component types.
|
||||
//
|
||||
// WARNING: This pass can only be safely applied standalone to vertex shaders
|
||||
// as it can otherwise cause interface incompatibilities with the preceding
|
||||
// shader in the pipeline. If applied to non-vertex shaders, the user should
|
||||
// follow by applying EliminateDeadOutputStores and
|
||||
// EliminateDeadOutputComponents to the preceding shader.
|
||||
Optimizer::PassToken CreateEliminateDeadInputComponentsPass();
|
||||
|
||||
// Removes unused components from composite output variables. Current
|
||||
// implementation just removes trailing unused components from output arrays
|
||||
// and structs. The pass performs best after eliminating dead output stores.
|
||||
// A subsequent dead code elimination pass would be beneficial in removing
|
||||
// newly unused component types. Currently only supports vertex and fragment
|
||||
// shaders.
|
||||
//
|
||||
// WARNING: This pass cannot be safely applied standalone as it can cause
|
||||
// interface incompatibility with the following shader in the pipeline. The
|
||||
// user should first apply EliminateDeadInputComponents to the following
|
||||
// shader, then apply EliminateDeadOutputStores to this shader.
|
||||
Optimizer::PassToken CreateEliminateDeadOutputComponentsPass();
|
||||
|
||||
// Removes unused components from composite input variables. This safe
|
||||
// version will not cause interface incompatibilities since it only changes
|
||||
// vertex shaders. The current implementation just removes trailing unused
|
||||
// components from input structs and input arrays. The pass performs best
|
||||
// after maximizing dead code removal. A subsequent dead code elimination
|
||||
// pass would be beneficial in removing newly unused component types.
|
||||
Optimizer::PassToken CreateEliminateDeadInputComponentsSafePass();
|
||||
|
||||
// Analyzes shader and populates |live_locs| and |live_builtins|. Best results
|
||||
// will be obtained if shader has all dead code eliminated first. |live_locs|
|
||||
// and |live_builtins| are subsequently used when calling
|
||||
// CreateEliminateDeadOutputStoresPass on the preceding shader. Currently only
|
||||
// supports tesc, tese, geom, and frag shaders.
|
||||
Optimizer::PassToken CreateAnalyzeLiveInputPass(
|
||||
std::unordered_set<uint32_t>* live_locs,
|
||||
std::unordered_set<uint32_t>* live_builtins);
|
||||
|
||||
// Removes stores to output locations not listed in |live_locs| or
|
||||
// |live_builtins|. Best results are obtained if constant propagation is
|
||||
// performed first. A subsequent call to ADCE will eliminate any dead code
|
||||
// created by the removal of the stores. A subsequent call to
|
||||
// CreateEliminateDeadOutputComponentsPass will eliminate any dead output
|
||||
// components created by the elimination of the stores. Currently only supports
|
||||
// vert, tesc, tese, and geom shaders.
|
||||
Optimizer::PassToken CreateEliminateDeadOutputStoresPass(
|
||||
std::unordered_set<uint32_t>* live_locs,
|
||||
std::unordered_set<uint32_t>* live_builtins);
|
||||
|
||||
// Creates a convert-to-sampled-image pass to convert images and/or
|
||||
// samplers with given pairs of descriptor set and binding to sampled image.
|
||||
// If a pair of an image and a sampler have the same pair of descriptor set and
|
||||
// binding that is one of the given pairs, they will be converted to a sampled
|
||||
// image. In addition, if only an image has the descriptor set and binding that
|
||||
// is one of the given pairs, it will be converted to a sampled image as well.
|
||||
Optimizer::PassToken CreateConvertToSampledImagePass(
|
||||
const std::vector<opt::DescriptorSetAndBinding>&
|
||||
descriptor_set_binding_pairs);
|
||||
|
||||
// Create an interface-variable-scalar-replacement pass that replaces array or
|
||||
// matrix interface variables with a series of scalar or vector interface
|
||||
// variables. For example, it replaces `float3 foo[2]` with `float3 foo0, foo1`.
|
||||
Optimizer::PassToken CreateInterfaceVariableScalarReplacementPass();
|
||||
|
||||
// Creates a remove-dont-inline pass to remove the |DontInline| function control
|
||||
// from every function in the module. This is useful if you want the inliner to
|
||||
// inline these functions some reason.
|
||||
Optimizer::PassToken CreateRemoveDontInlinePass();
|
||||
// Create a fix-func-call-param pass to fix non memory argument for the function
|
||||
// call, as spirv-validation requires function parameters to be an memory
|
||||
// object, currently the pass would remove accesschain pointer argument passed
|
||||
// to the function
|
||||
Optimizer::PassToken CreateFixFuncCallArgumentsPass();
|
||||
|
||||
// Creates a trim-capabilities pass.
|
||||
// This pass removes unused capabilities for a given module, and if possible,
|
||||
// associated extensions.
|
||||
// See `trim_capabilities.h` for the list of supported capabilities.
|
||||
//
|
||||
// If the module contains unsupported capabilities, this pass will ignore them.
|
||||
// This should be fine in most cases, but could yield to incorrect results if
|
||||
// the unknown capability interacts with one of the trimmed capabilities.
|
||||
Optimizer::PassToken CreateTrimCapabilitiesPass();
|
||||
|
||||
// Creates a struct-packing pass.
|
||||
// This pass re-assigns all offset layout decorators to tightly pack
|
||||
// the struct with OpName matching `structToPack` according to the given packing
|
||||
// rule. Accepted packing rules are: std140, std140EnhancedLayout, std430,
|
||||
// std430EnhancedLayout, hlslCbuffer, hlslCbufferPackOffset, scalar,
|
||||
// scalarEnhancedLayout.
|
||||
Optimizer::PassToken CreateStructPackingPass(const char* structToPack,
|
||||
const char* packingRule);
|
||||
|
||||
// Creates a switch-descriptorset pass.
|
||||
// This pass changes any DescriptorSet decorations with the value |ds_from| to
|
||||
// use the new value |ds_to|.
|
||||
Optimizer::PassToken CreateSwitchDescriptorSetPass(uint32_t ds_from,
|
||||
uint32_t ds_to);
|
||||
|
||||
// Creates an invocation interlock placement pass.
|
||||
// This pass ensures that an entry point will have at most one
|
||||
// OpBeginInterlockInvocationEXT and one OpEndInterlockInvocationEXT, in that
|
||||
// order.
|
||||
Optimizer::PassToken CreateInvocationInterlockPlacementPass();
|
||||
|
||||
// Creates a pass to add/remove maximal reconvergence execution mode.
|
||||
// This pass either adds or removes maximal reconvergence from all entry points.
|
||||
Optimizer::PassToken CreateModifyMaximalReconvergencePass(bool add);
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
}
|
||||
|
||||
~LinearAllocatorWithFallback() noexcept {
|
||||
LinearAllocatorWithFallback::reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void* alloc(size_t size, size_t alignment = alignof(std::max_align_t));
|
||||
@@ -204,7 +204,7 @@ public:
|
||||
}
|
||||
|
||||
void rewind(void* p) noexcept {
|
||||
if (p >= LinearAllocator::base() && p < LinearAllocator::end()) {
|
||||
if (p >= base() && p < end()) {
|
||||
LinearAllocator::rewind(p);
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ public:
|
||||
void free(void*, size_t) noexcept { }
|
||||
|
||||
bool isHeapAllocation(void* p) const noexcept {
|
||||
return p < LinearAllocator::base() || p >= LinearAllocator::end();
|
||||
return p < base() || p >= end();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -240,7 +240,6 @@ public:
|
||||
void push(void* p) noexcept {
|
||||
assert_invariant(p);
|
||||
assert_invariant(p >= mBegin && p < mEnd);
|
||||
// TODO: assert this is one of our pointer (i.e.: it's address match one of ours)
|
||||
Node* const head = static_cast<Node*>(p);
|
||||
head->next = mHead;
|
||||
mHead = head;
|
||||
@@ -718,13 +717,13 @@ public:
|
||||
// trivially destructible, since free() won't call the destructor and this is allocating
|
||||
// an array.
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_trivially_destructible<T>::value>::type>
|
||||
typename = std::enable_if_t<std::is_trivially_destructible_v<T>>>
|
||||
T* alloc(size_t count, size_t alignment, size_t extra) noexcept {
|
||||
return (T*)alloc(count * sizeof(T), alignment, extra);
|
||||
}
|
||||
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_trivially_destructible<T>::value>::type>
|
||||
typename = std::enable_if_t<std::is_trivially_destructible_v<T>>>
|
||||
T* alloc(size_t count, size_t alignment = alignof(T)) noexcept {
|
||||
return (T*)alloc(count * sizeof(T), alignment);
|
||||
}
|
||||
@@ -880,7 +879,7 @@ public:
|
||||
template<typename T, size_t ALIGN = alignof(T), typename... ARGS>
|
||||
T* make(ARGS&& ... args) noexcept {
|
||||
T* o = nullptr;
|
||||
if (std::is_trivially_destructible<T>::value) {
|
||||
if (std::is_trivially_destructible_v<T>) {
|
||||
o = mArena.template make<T, ALIGN>(std::forward<ARGS>(args)...);
|
||||
} else {
|
||||
void* const p = (Finalizer*)mArena.alloc(sizeof(T), ALIGN, sizeof(Finalizer));
|
||||
|
||||
@@ -41,32 +41,32 @@ size_t count();
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
inline constexpr int operator+(Enum value) noexcept {
|
||||
return int(value);
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool operator==(Enum lhs, size_t rhs) noexcept {
|
||||
using underlying_t = std::underlying_type_t<Enum>;
|
||||
return underlying_t(lhs) == rhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool operator==(size_t lhs, Enum rhs) noexcept {
|
||||
return rhs == lhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool operator!=(Enum lhs, size_t rhs) noexcept {
|
||||
return !(rhs == lhs);
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableIntegerOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool operator!=(size_t lhs, Enum rhs) noexcept {
|
||||
return rhs != lhs;
|
||||
}
|
||||
@@ -74,66 +74,66 @@ inline constexpr bool operator!=(size_t lhs, Enum rhs) noexcept {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool operator!(Enum rhs) noexcept {
|
||||
using underlying = std::underlying_type_t<Enum>;
|
||||
return underlying(rhs) == 0;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator~(Enum rhs) noexcept {
|
||||
using underlying = std::underlying_type_t<Enum>;
|
||||
return Enum(~underlying(rhs));
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator|(Enum lhs, Enum rhs) noexcept {
|
||||
using underlying = std::underlying_type_t<Enum>;
|
||||
return Enum(underlying(lhs) | underlying(rhs));
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator&(Enum lhs, Enum rhs) noexcept {
|
||||
using underlying = std::underlying_type_t<Enum>;
|
||||
return Enum(underlying(lhs) & underlying(rhs));
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator^(Enum lhs, Enum rhs) noexcept {
|
||||
using underlying = std::underlying_type_t<Enum>;
|
||||
return Enum(underlying(lhs) ^ underlying(rhs));
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator|=(Enum& lhs, Enum rhs) noexcept {
|
||||
return lhs = lhs | rhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator&=(Enum& lhs, Enum rhs) noexcept {
|
||||
return lhs = lhs & rhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr Enum operator^=(Enum& lhs, Enum rhs) noexcept {
|
||||
return lhs = lhs ^ rhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool none(Enum lhs) noexcept {
|
||||
return !lhs;
|
||||
}
|
||||
|
||||
template<typename Enum, typename std::enable_if_t<
|
||||
std::is_enum<Enum>::value && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
std::is_enum_v<Enum> && utils::EnableBitMaskOperators<Enum>::value, int> = 0>
|
||||
inline constexpr bool any(Enum lhs) noexcept {
|
||||
return !none(lhs);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// NOTE: this header should not include STL headers
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
@@ -181,6 +182,10 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
#if !defined(NDEBUG)
|
||||
friend io::ostream& operator<<(io::ostream& out, const CString& rhs);
|
||||
#endif
|
||||
|
||||
struct Data {
|
||||
size_type length;
|
||||
};
|
||||
|
||||
@@ -68,10 +68,10 @@ public:
|
||||
intptr_t operator [](size_t index) const;
|
||||
|
||||
/** Demangles a C++ type name */
|
||||
static utils::CString demangleTypeName(const char* mangled);
|
||||
static CString demangleTypeName(const char* mangled);
|
||||
|
||||
template<typename T>
|
||||
static utils::CString typeName() {
|
||||
static CString typeName() {
|
||||
#if UTILS_HAS_RTTI
|
||||
return demangleTypeName(typeid(T).name());
|
||||
#else
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
* This will print, when possible, the demangled names of functions corresponding to the
|
||||
* program-counter recorded.
|
||||
*/
|
||||
friend utils::io::ostream& operator <<(utils::io::ostream& stream, const CallStack& callstack);
|
||||
friend io::ostream& operator <<(io::ostream& stream, const CallStack& callstack);
|
||||
|
||||
bool operator <(const CallStack& rhs) const;
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
private:
|
||||
void update_gcc(size_t ignore) noexcept;
|
||||
|
||||
static utils::CString demangle(const char* mangled);
|
||||
static CString demangle(const char* mangled);
|
||||
|
||||
static constexpr size_t NUM_FRAMES = 20;
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef TNT_UTILS_INVOKABLE_H
|
||||
#define TNT_UTILS_INVOKABLE_H
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -81,6 +83,11 @@ public:
|
||||
explicit operator bool() const noexcept;
|
||||
|
||||
private:
|
||||
#if !defined(NDEBUG)
|
||||
friend io::ostream& operator<<(io::ostream& out, const Invocable&) {
|
||||
return out << "Invocable<>"; // TODO: is there a way to do better here?
|
||||
}
|
||||
#endif
|
||||
void* mInvocable = nullptr;
|
||||
void (*mDeleter)(void*) = nullptr;
|
||||
R (* mInvoker)(void*, Args...) = nullptr;
|
||||
|
||||
@@ -47,7 +47,7 @@ class EntityManager;
|
||||
* printf("%s\n", names->getName(names->getInstance(myEntity));
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
class UTILS_PUBLIC NameComponentManager : private SingleInstanceComponentManager<utils::CString> {
|
||||
class UTILS_PUBLIC NameComponentManager : private SingleInstanceComponentManager<CString> {
|
||||
public:
|
||||
using Instance = EntityInstance<NameComponentManager>;
|
||||
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
const char* getName(Instance instance) const noexcept;
|
||||
|
||||
void gc(EntityManager& em) noexcept {
|
||||
SingleInstanceComponentManager<utils::CString>::gc(em, [this](Entity e) {
|
||||
SingleInstanceComponentManager<CString>::gc(em, [this](Entity e) {
|
||||
removeComponent(e);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
return getComponentCount() == 0;
|
||||
}
|
||||
|
||||
utils::Entity const* getEntities() const noexcept {
|
||||
Entity const* getEntities() const noexcept {
|
||||
return data<ENTITY_INDEX>() + 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
friend class IteratorValueRef;
|
||||
friend iterator;
|
||||
friend const_iterator;
|
||||
using Type = std::tuple<typename std::decay<Elements>::type...>;
|
||||
using Type = std::tuple<std::decay_t<Elements>...>;
|
||||
Type elements;
|
||||
|
||||
template<size_t ... Is>
|
||||
@@ -535,22 +535,22 @@ public:
|
||||
|
||||
private:
|
||||
template<std::size_t I = 0, typename FuncT, typename... Tp>
|
||||
inline typename std::enable_if<I == sizeof...(Tp), void>::type
|
||||
inline std::enable_if_t<I == sizeof...(Tp), void>
|
||||
for_each(std::tuple<Tp...>&, FuncT) {}
|
||||
|
||||
template<std::size_t I = 0, typename FuncT, typename... Tp>
|
||||
inline typename std::enable_if<I < sizeof...(Tp), void>::type
|
||||
inline std::enable_if_t<I < sizeof...(Tp), void>
|
||||
for_each(std::tuple<Tp...>& t, FuncT f) {
|
||||
f(I, std::get<I>(t));
|
||||
for_each<I + 1, FuncT, Tp...>(t, f);
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename FuncT, typename... Tp>
|
||||
inline typename std::enable_if<I == sizeof...(Tp), void>::type
|
||||
inline std::enable_if_t<I == sizeof...(Tp), void>
|
||||
for_each_index(std::tuple<Tp...>&, FuncT) {}
|
||||
|
||||
template<std::size_t I = 0, typename FuncT, typename... Tp>
|
||||
inline typename std::enable_if<I < sizeof...(Tp), void>::type
|
||||
inline std::enable_if_t<I < sizeof...(Tp), void>
|
||||
for_each_index(std::tuple<Tp...>& t, FuncT f) {
|
||||
f.template operator()<I>(std::get<I>(t));
|
||||
for_each_index<I + 1, FuncT, Tp...>(t, f);
|
||||
@@ -597,7 +597,7 @@ private:
|
||||
|
||||
void construct_each(size_t from, size_t to) noexcept {
|
||||
forEach([from, to](auto p) {
|
||||
using T = typename std::decay<decltype(*p)>::type;
|
||||
using T = std::decay_t<decltype(*p)>;
|
||||
// note: scalar types like int/float get initialized to zero
|
||||
if constexpr (!std::is_trivially_default_constructible_v<T>) {
|
||||
for (size_t i = from; i < to; i++) {
|
||||
@@ -609,7 +609,7 @@ private:
|
||||
|
||||
void destroy_each(size_t from, size_t to) noexcept {
|
||||
forEach([from, to](auto p) {
|
||||
using T = typename std::decay<decltype(*p)>::type;
|
||||
using T = std::decay_t<decltype(*p)>;
|
||||
if constexpr (!std::is_trivially_destructible_v<T>) {
|
||||
for (size_t i = from; i < to; i++) {
|
||||
p[i].~T();
|
||||
@@ -624,7 +624,7 @@ private:
|
||||
if (mSize) {
|
||||
auto size = mSize; // placate a compiler warning
|
||||
forEach([buffer, &index, &offsets, size](auto p) {
|
||||
using T = typename std::decay<decltype(*p)>::type;
|
||||
using T = std::decay_t<decltype(*p)>;
|
||||
T* UTILS_RESTRICT b = static_cast<T*>(buffer);
|
||||
|
||||
// go through each element and move them from the old array to the new
|
||||
@@ -671,7 +671,7 @@ template<typename Allocator, typename... Elements>
|
||||
inline
|
||||
typename StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef&
|
||||
StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef::operator=(
|
||||
StructureOfArraysBase::IteratorValueRef const& rhs) {
|
||||
IteratorValueRef const& rhs) {
|
||||
return operator=(IteratorValue(rhs));
|
||||
}
|
||||
|
||||
@@ -679,7 +679,7 @@ template<typename Allocator, typename... Elements>
|
||||
inline
|
||||
typename StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef&
|
||||
StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef::operator=(
|
||||
StructureOfArraysBase::IteratorValueRef&& rhs) noexcept {
|
||||
IteratorValueRef&& rhs) noexcept {
|
||||
return operator=(IteratorValue(rhs));
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ template<size_t... Is>
|
||||
inline
|
||||
typename StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef&
|
||||
StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef::assign(
|
||||
StructureOfArraysBase::IteratorValue const& rhs, std::index_sequence<Is...>) {
|
||||
IteratorValue const& rhs, std::index_sequence<Is...>) {
|
||||
// implements IteratorValueRef& IteratorValueRef::operator=(IteratorValue const& rhs)
|
||||
auto UTILS_UNUSED l = { (soa->elementAt<Is>(index) = std::get<Is>(rhs.elements), 0)... };
|
||||
return *this;
|
||||
@@ -699,7 +699,7 @@ template<size_t... Is>
|
||||
inline
|
||||
typename StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef&
|
||||
StructureOfArraysBase<Allocator, Elements...>::IteratorValueRef::assign(
|
||||
StructureOfArraysBase::IteratorValue&& rhs, std::index_sequence<Is...>) noexcept {
|
||||
IteratorValue&& rhs, std::index_sequence<Is...>) noexcept {
|
||||
// implements IteratorValueRef& IteratorValueRef::operator=(IteratorValue&& rhs) noexcept
|
||||
auto UTILS_UNUSED l = {
|
||||
(soa->elementAt<Is>(index) = std::move(std::get<Is>(rhs.elements)), 0)... };
|
||||
|
||||
@@ -39,7 +39,7 @@ constexpr inline T popcount(T v) noexcept {
|
||||
return (T) (v * (ONES / 255)) >> (sizeof(T) - 1) * CHAR_BIT;
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned<T>::value>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||
constexpr inline T clz(T x) noexcept {
|
||||
static_assert(sizeof(T) * CHAR_BIT <= 128, "details::clz() only support up to 128 bits");
|
||||
x |= (x >> 1u);
|
||||
@@ -62,7 +62,7 @@ constexpr inline T clz(T x) noexcept {
|
||||
return T(sizeof(T) * CHAR_BIT) - details::popcount(x);
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned<T>::value>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||
constexpr inline T ctz(T x) noexcept {
|
||||
static_assert(sizeof(T) * CHAR_BIT <= 64, "details::ctz() only support up to 64 bits");
|
||||
T c = sizeof(T) * CHAR_BIT;
|
||||
@@ -227,7 +227,7 @@ unsigned long long UTILS_ALWAYS_INLINE popcount(unsigned long long x) noexcept {
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
typename = std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value>>
|
||||
typename = std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>>>
|
||||
constexpr inline UTILS_PUBLIC UTILS_PURE
|
||||
T log2i(T x) noexcept {
|
||||
return (sizeof(x) * 8 - 1u) - clz(x);
|
||||
|
||||
@@ -45,8 +45,8 @@ namespace utils {
|
||||
*/
|
||||
|
||||
template<typename T, size_t N = 1,
|
||||
typename = typename std::enable_if<std::is_integral<T>::value &&
|
||||
std::is_unsigned<T>::value>::type>
|
||||
typename = std::enable_if_t<std::is_integral_v<T> &&
|
||||
std::is_unsigned_v<T>>>
|
||||
class UTILS_PUBLIC bitset {
|
||||
T storage[N];
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace utils::io {
|
||||
|
||||
struct ostream_;
|
||||
|
||||
class UTILS_PUBLIC ostream : protected utils::PrivateImplementation<ostream_> {
|
||||
class UTILS_PUBLIC ostream : protected PrivateImplementation<ostream_> {
|
||||
friend struct ostream_;
|
||||
|
||||
public:
|
||||
@@ -123,7 +123,7 @@ private:
|
||||
};
|
||||
|
||||
// handles utils::bitset
|
||||
inline ostream& operator << (ostream& o, utils::bitset32 const& s) noexcept {
|
||||
inline ostream& operator << (ostream& o, bitset32 const& s) noexcept {
|
||||
return o << (void*)uintptr_t(s.getValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,22 @@ public:
|
||||
* Allows users to toggle screenshots, change the sleep duration between tests, etc.
|
||||
*/
|
||||
struct Options {
|
||||
|
||||
/**
|
||||
* Formats that could be used for exporting the screenshots.
|
||||
*/
|
||||
enum class ExportFormat : uint8_t {
|
||||
/**
|
||||
* Tagged Image File Format (TIFF)
|
||||
*/
|
||||
TIFF = 0,
|
||||
|
||||
/**
|
||||
* Netpbm color image format (Portable Pixel Map)
|
||||
*/
|
||||
PPM = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Minimum time that automation waits between applying a settings object and advancing
|
||||
* to the next test case. Specified in seconds.
|
||||
@@ -82,6 +98,11 @@ public:
|
||||
* If true, the tick function writes out a settings JSON file before advancing.
|
||||
*/
|
||||
bool exportSettings = false;
|
||||
|
||||
/**
|
||||
* Which image format will be used for exporting screenshots.
|
||||
*/
|
||||
ExportFormat exportFormat = ExportFormat::TIFF;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user