update headers
This commit is contained in:
@@ -19,29 +19,37 @@
|
||||
#ifndef TNT_FILAMAT_MATERIAL_PACKAGE_BUILDER_H
|
||||
#define TNT_FILAMAT_MATERIAL_PACKAGE_BUILDER_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/TargetBufferInfo.h>
|
||||
#include <filament/MaterialEnums.h>
|
||||
|
||||
#include <filamat/IncludeCallback.h>
|
||||
#include <filamat/Package.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/TargetBufferInfo.h>
|
||||
|
||||
#include <utils/BitmaskEnum.h>
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/CString.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils {
|
||||
class JobSystem;
|
||||
}
|
||||
|
||||
namespace filament {
|
||||
class BufferInterfaceBlock;
|
||||
}
|
||||
|
||||
namespace filamat {
|
||||
|
||||
struct MaterialInfo;
|
||||
@@ -53,6 +61,8 @@ public:
|
||||
/**
|
||||
* High-level hint that works in concert with TargetApi to determine the shader models (used to
|
||||
* generate GLSL) and final output representations (spirv and/or text).
|
||||
* When generating the GLSL this is used to differentiate OpenGL from OpenGLES, it is also
|
||||
* used to make some performance adjustments.
|
||||
*/
|
||||
enum class Platform {
|
||||
DESKTOP,
|
||||
@@ -60,6 +70,10 @@ public:
|
||||
ALL
|
||||
};
|
||||
|
||||
/**
|
||||
* TargetApi defines which language after transpilation will be used, it is used to
|
||||
* account for some differences between these languages when generating the GLSL.
|
||||
*/
|
||||
enum class TargetApi : uint8_t {
|
||||
OPENGL = 0x01u,
|
||||
VULKAN = 0x02u,
|
||||
@@ -67,8 +81,23 @@ public:
|
||||
ALL = OPENGL | VULKAN | METAL
|
||||
};
|
||||
|
||||
/*
|
||||
* Generally we generate GLSL that will be converted to SPIRV, optimized and then
|
||||
* transpiled to the backend's language such as MSL, ESSL300, GLSL410 or SPIRV, in this
|
||||
* case the generated GLSL uses ESSL310 or GLSL450 and has Vulkan semantics and
|
||||
* TargetLanguage::SPIRV must be used.
|
||||
*
|
||||
* However, in some cases (e.g. when no optimization is asked) we generate the *final* GLSL
|
||||
* directly, this GLSL must be ESSL300 or GLSL410 and cannot use any Vulkan syntax, for this
|
||||
* situation we use TargetLanguage::GLSL. In this case TargetApi is guaranteed to be OPENGL.
|
||||
*
|
||||
* Note that TargetLanguage::GLSL is not the common case, as it is generally not used in
|
||||
* release builds.
|
||||
*
|
||||
* Also note that glslang performs semantics analysis on whichever GLSL ends up being generated.
|
||||
*/
|
||||
enum class TargetLanguage {
|
||||
GLSL, // GLSL with OpenGL semantics
|
||||
GLSL, // GLSL with OpenGL 4.1 / OpenGL ES 3.0 semantics
|
||||
SPIRV // GLSL with Vulkan semantics
|
||||
};
|
||||
|
||||
@@ -106,29 +135,29 @@ protected:
|
||||
bool mGenerateDebugInfo = false;
|
||||
utils::bitset32 mShaderModels;
|
||||
struct CodeGenParams {
|
||||
int shaderModel;
|
||||
ShaderModel shaderModel;
|
||||
TargetApi targetApi;
|
||||
TargetLanguage targetLanguage;
|
||||
};
|
||||
std::vector<CodeGenParams> mCodeGenPermutations;
|
||||
// For finding properties and running semantic analysis, we always use the same code gen
|
||||
// permutation. This is the first permutation generated with default arguments passed to matc.
|
||||
const CodeGenParams mSemanticCodeGenParams = {
|
||||
.shaderModel = (int) ShaderModel::GL_ES_30,
|
||||
.targetApi = TargetApi::OPENGL,
|
||||
.targetLanguage = TargetLanguage::SPIRV
|
||||
static constexpr const CodeGenParams mSemanticCodeGenParams = {
|
||||
.shaderModel = ShaderModel::MOBILE,
|
||||
.targetApi = TargetApi::OPENGL,
|
||||
.targetLanguage = TargetLanguage::SPIRV
|
||||
};
|
||||
|
||||
// Keeps track of how many times MaterialBuilder::init() has been called without a call to
|
||||
// MaterialBuilder::shutdown(). Internally, glslang does something similar. We keep track for
|
||||
// ourselves so we can inform the user if MaterialBuilder::init() hasn't been called before
|
||||
// ourselves, so we can inform the user if MaterialBuilder::init() hasn't been called before
|
||||
// attempting to build a material.
|
||||
static std::atomic<int> materialBuilderClients;
|
||||
};
|
||||
|
||||
// Utility function that looks at an Engine backend to determine TargetApi
|
||||
inline constexpr MaterialBuilderBase::TargetApi targetApiFromBackend(
|
||||
filament::backend::Backend backend) noexcept {
|
||||
filament::backend::Backend backend) noexcept {
|
||||
using filament::backend::Backend;
|
||||
using TargetApi = MaterialBuilderBase::TargetApi;
|
||||
switch (backend) {
|
||||
@@ -176,6 +205,13 @@ inline constexpr MaterialBuilderBase::TargetApi targetApiFromBackend(
|
||||
class UTILS_PUBLIC MaterialBuilder : public MaterialBuilderBase {
|
||||
public:
|
||||
MaterialBuilder();
|
||||
~MaterialBuilder();
|
||||
|
||||
MaterialBuilder(const MaterialBuilder& rhs) = delete;
|
||||
MaterialBuilder& operator=(const MaterialBuilder& rhs) = delete;
|
||||
|
||||
MaterialBuilder(MaterialBuilder&& rhs) noexcept = default;
|
||||
MaterialBuilder& operator=(MaterialBuilder&& rhs) noexcept = default;
|
||||
|
||||
static constexpr size_t MATERIAL_VARIABLES_COUNT = 4;
|
||||
enum class Variable : uint8_t {
|
||||
@@ -206,6 +242,7 @@ public:
|
||||
using SamplerFormat = filament::backend::SamplerFormat;
|
||||
using ParameterPrecision = filament::backend::Precision;
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using FeatureLevel = filament::backend::FeatureLevel;
|
||||
|
||||
enum class VariableQualifier : uint8_t {
|
||||
OUT
|
||||
@@ -227,8 +264,8 @@ public:
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
PreprocessorDefine(const std::string& name, const std::string& value) :
|
||||
name(name), value(value) {}
|
||||
PreprocessorDefine(std::string name, std::string value) :
|
||||
name(std::move(name)), value(std::move(value)) {}
|
||||
};
|
||||
using PreprocessorDefineList = std::vector<PreprocessorDefine>;
|
||||
|
||||
@@ -245,38 +282,28 @@ public:
|
||||
MaterialBuilder& interpolation(Interpolation interpolation) noexcept;
|
||||
|
||||
//! Add a parameter (i.e., a uniform) to this material.
|
||||
MaterialBuilder& parameter(UniformType type, ParameterPrecision precision,
|
||||
const char* name) noexcept;
|
||||
|
||||
//! Add a parameter (i.e., a uniform) to this material.
|
||||
MaterialBuilder& parameter(UniformType type, const char* name) noexcept {
|
||||
return parameter(type, ParameterPrecision::DEFAULT, name);
|
||||
}
|
||||
MaterialBuilder& parameter(const char* name, UniformType type,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT) noexcept;
|
||||
|
||||
//! Add a parameter array to this material.
|
||||
MaterialBuilder& parameter(UniformType type, size_t size,
|
||||
ParameterPrecision precision, const char* name) noexcept;
|
||||
|
||||
//! Add a parameter array to this material.
|
||||
MaterialBuilder& parameter(UniformType type, size_t size, const char* name) noexcept {
|
||||
return parameter(type, size, ParameterPrecision::DEFAULT, name);
|
||||
}
|
||||
MaterialBuilder& parameter(const char* name, size_t size, UniformType type,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT) noexcept;
|
||||
|
||||
/**
|
||||
* Add a sampler parameter to this material.
|
||||
*
|
||||
* When SamplerType::SAMPLER_EXTERNAL is specifed, format and precision are ignored.
|
||||
* When SamplerType::SAMPLER_EXTERNAL is specified, format and precision are ignored.
|
||||
*/
|
||||
MaterialBuilder& parameter(SamplerType samplerType, SamplerFormat format,
|
||||
ParameterPrecision precision, const char* name) noexcept;
|
||||
MaterialBuilder& parameter(const char* name, SamplerType samplerType,
|
||||
SamplerFormat format = SamplerFormat::FLOAT,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT) noexcept;
|
||||
|
||||
/// @copydoc parameter(SamplerType, SamplerFormat, ParameterPrecision, const char*)
|
||||
MaterialBuilder& parameter(SamplerType samplerType, SamplerFormat format,
|
||||
const char* name) noexcept;
|
||||
/// @copydoc parameter(SamplerType, SamplerFormat, ParameterPrecision, const char*)
|
||||
MaterialBuilder& parameter(SamplerType samplerType, ParameterPrecision precision,
|
||||
const char* name) noexcept;
|
||||
/// @copydoc parameter(SamplerType, SamplerFormat, ParameterPrecision, const char*)
|
||||
MaterialBuilder& parameter(SamplerType samplerType, const char* name) noexcept;
|
||||
MaterialBuilder& parameter(const char* name, SamplerType samplerType,
|
||||
ParameterPrecision precision) noexcept;
|
||||
|
||||
|
||||
MaterialBuilder& buffer(filament::BufferInterfaceBlock bib) noexcept;
|
||||
|
||||
//! Custom variables (all float4).
|
||||
MaterialBuilder& variable(Variable v, const char* name) noexcept;
|
||||
@@ -289,7 +316,7 @@ public:
|
||||
MaterialBuilder& require(VertexAttribute attribute) noexcept;
|
||||
|
||||
//! Specify the domain that this material will operate in.
|
||||
MaterialBuilder& materialDomain(filament::MaterialDomain materialDomain) noexcept;
|
||||
MaterialBuilder& materialDomain(MaterialBuilder::MaterialDomain materialDomain) noexcept;
|
||||
|
||||
/**
|
||||
* Set the code content of this material.
|
||||
@@ -360,6 +387,8 @@ public:
|
||||
|
||||
MaterialBuilder& quality(ShaderQuality quality) noexcept;
|
||||
|
||||
MaterialBuilder& featureLevel(FeatureLevel featureLevel) noexcept;
|
||||
|
||||
//! Set the blending mode for this material.
|
||||
MaterialBuilder& blending(BlendingMode blending) noexcept;
|
||||
|
||||
@@ -531,12 +560,17 @@ public:
|
||||
|
||||
MaterialBuilder& enableFramebufferFetch() noexcept;
|
||||
|
||||
MaterialBuilder& vertexDomainDeviceJittered(bool enabled) noexcept;
|
||||
|
||||
/**
|
||||
* Legacy morphing uses the data in the VertexAttribute slots (\c MORPH_POSITION_0, etc) and is
|
||||
* limited to 4 morph targets. See filament::RenderableManager::Builder::morphing().
|
||||
*/
|
||||
MaterialBuilder& useLegacyMorphing() noexcept;
|
||||
|
||||
//! specify compute kernel group size
|
||||
MaterialBuilder& groupSize(filament::math::uint3 groupSize) noexcept;
|
||||
|
||||
/**
|
||||
* Build the material. If you are using the Filament engine with this library, you should use
|
||||
* the job system provided by Engine.
|
||||
@@ -550,16 +584,16 @@ public:
|
||||
/**
|
||||
* Add a subpass parameter to this material.
|
||||
*/
|
||||
MaterialBuilder& parameter(SubpassType subpassType, SamplerFormat format, ParameterPrecision
|
||||
precision, const char* name) noexcept;
|
||||
MaterialBuilder& parameter(SubpassType subpassType, SamplerFormat format, const char* name)
|
||||
noexcept;
|
||||
MaterialBuilder& parameter(SubpassType subpassType, ParameterPrecision precision,
|
||||
const char* name) noexcept;
|
||||
MaterialBuilder& parameter(SubpassType subpassType, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
SamplerFormat format, ParameterPrecision precision, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
SamplerFormat format, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
ParameterPrecision precision, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType, const char* name) noexcept;
|
||||
|
||||
struct Parameter {
|
||||
Parameter() noexcept : parameterType(INVALID) {}
|
||||
Parameter() noexcept: parameterType(INVALID) {}
|
||||
|
||||
// Sampler
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p)
|
||||
@@ -596,8 +630,8 @@ public:
|
||||
Output() noexcept = default;
|
||||
Output(const char* outputName, VariableQualifier qualifier, OutputTarget target,
|
||||
OutputType type, int location) noexcept
|
||||
: name(outputName), qualifier(qualifier), target(target), type(type),
|
||||
location(location) { }
|
||||
: name(outputName), qualifier(qualifier), target(target), type(type),
|
||||
location(location) { }
|
||||
|
||||
utils::CString name;
|
||||
VariableQualifier qualifier;
|
||||
@@ -621,7 +655,7 @@ public:
|
||||
|
||||
// Preview the first shader generated by the given CodeGenParams.
|
||||
// This is used to run Static Code Analysis before generating a package.
|
||||
std::string peek(filament::backend::ShaderType type,
|
||||
std::string peek(filament::backend::ShaderStage type,
|
||||
const CodeGenParams& params, const PropertyList& properties) noexcept;
|
||||
|
||||
// Returns true if any of the parameter samplers is of type samplerExternal
|
||||
@@ -629,7 +663,10 @@ public:
|
||||
|
||||
static constexpr size_t MAX_PARAMETERS_COUNT = 48;
|
||||
static constexpr size_t MAX_SUBPASS_COUNT = 1;
|
||||
static constexpr size_t MAX_BUFFERS_COUNT = 4;
|
||||
using ParameterList = Parameter[MAX_PARAMETERS_COUNT];
|
||||
using SubpassList = Parameter[MAX_SUBPASS_COUNT];
|
||||
using BufferList = std::vector<std::unique_ptr<filament::BufferInterfaceBlock>>;
|
||||
|
||||
// returns the number of parameters declared in this material
|
||||
uint8_t getParameterCount() const noexcept { return mParameterCount; }
|
||||
@@ -637,6 +674,12 @@ public:
|
||||
// returns a list of at least getParameterCount() parameters
|
||||
const ParameterList& getParameters() const noexcept { return mParameters; }
|
||||
|
||||
// returns the number of parameters declared in this material
|
||||
uint8_t getSubpassCount() const noexcept { return mSubpassCount; }
|
||||
|
||||
// returns a list of at least getParameterCount() parameters
|
||||
const SubpassList& getSubPasses() const noexcept { return mSubpasses; }
|
||||
|
||||
filament::UserVariantFilterMask getVariantFilter() const { return mVariantFilter; }
|
||||
|
||||
/// @endcond
|
||||
@@ -648,14 +691,18 @@ private:
|
||||
// This method finds all the properties defined in the fragment and
|
||||
// vertex shaders of the material.
|
||||
bool findAllProperties() noexcept;
|
||||
|
||||
// Multiple calls to findProperties accumulate the property sets across fragment
|
||||
// and vertex shaders in mProperties.
|
||||
bool findProperties(filament::backend::ShaderType type,
|
||||
bool findProperties(filament::backend::ShaderStage type,
|
||||
MaterialBuilder::PropertyList& p) noexcept;
|
||||
bool runSemanticAnalysis() noexcept;
|
||||
|
||||
bool runSemanticAnalysis(MaterialInfo const& info) noexcept;
|
||||
|
||||
bool checkLiteRequirements() noexcept;
|
||||
|
||||
bool checkMaterialLevelFeatures(MaterialInfo const& info) const noexcept;
|
||||
|
||||
void writeCommonChunks(ChunkContainer& container, MaterialInfo& info) const noexcept;
|
||||
void writeSurfaceChunks(ChunkContainer& container) const noexcept;
|
||||
|
||||
@@ -703,10 +750,13 @@ private:
|
||||
|
||||
PropertyList mProperties;
|
||||
ParameterList mParameters;
|
||||
SubpassList mSubpasses;
|
||||
VariableList mVariables;
|
||||
OutputList mOutputs;
|
||||
BufferList mBuffers;
|
||||
|
||||
ShaderQuality mShaderQuality = ShaderQuality::DEFAULT;
|
||||
FeatureLevel mFeatureLevel = FeatureLevel::FEATURE_LEVEL_1;
|
||||
BlendingMode mBlendingMode = BlendingMode::OPAQUE;
|
||||
BlendingMode mPostLightingBlendingMode = BlendingMode::TRANSPARENT;
|
||||
CullingMode mCullingMode = CullingMode::BACK;
|
||||
@@ -725,16 +775,19 @@ private:
|
||||
float mSpecularAntiAliasingVariance = 0.15f;
|
||||
float mSpecularAntiAliasingThreshold = 0.2f;
|
||||
|
||||
filament::math::uint3 mGroupSize = { 1, 1, 1 };
|
||||
|
||||
bool mShadowMultiplier = false;
|
||||
bool mTransparentShadow = false;
|
||||
|
||||
uint8_t mParameterCount = 0;
|
||||
uint8_t mSubpassCount = 0;
|
||||
|
||||
bool mDoubleSided = false;
|
||||
bool mDoubleSidedCapability = false;
|
||||
bool mColorWrite = true;
|
||||
bool mDepthTest = true;
|
||||
bool mInstanced = true;
|
||||
bool mInstanced = false;
|
||||
bool mDepthWrite = true;
|
||||
bool mDepthWriteSet = false;
|
||||
|
||||
@@ -753,6 +806,8 @@ private:
|
||||
|
||||
bool mEnableFramebufferFetch = false;
|
||||
|
||||
bool mVertexDomainDeviceJittered = false;
|
||||
|
||||
bool mUseLegacyMorphing = false;
|
||||
|
||||
PreprocessorDefineList mDefines;
|
||||
|
||||
Reference in New Issue
Block a user