Compare commits
1 Commits
ry/wgpuFix
...
exv/color-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab552d3619 |
@@ -356,6 +356,13 @@ enum class SamplerFormat : uint8_t {
|
||||
SHADOW = 3 //!< shadow sampler (PCF)
|
||||
};
|
||||
|
||||
//! Texture color space
|
||||
enum class SamplerTransferFunction : uint8_t {
|
||||
UNDEFINED = 0, //!< don't care
|
||||
IDENTITY = 1, //!< sampled as-is
|
||||
SRGB_TO_LINEAR = 2, //!< sampled as sRGB and converted to linear
|
||||
};
|
||||
|
||||
/**
|
||||
* Supported element types
|
||||
*/
|
||||
|
||||
@@ -426,6 +426,7 @@ bool ChunkSamplerInterfaceBlock::unflatten(Unflattener& unflattener,
|
||||
uint8_t fieldFormat = 0;
|
||||
uint8_t fieldPrecision = 0;
|
||||
bool fieldMultisample = false;
|
||||
uint8_t fieldTransferFunction = 0;
|
||||
|
||||
if (!unflattener.read(&fieldName)) {
|
||||
return false;
|
||||
@@ -447,10 +448,15 @@ bool ChunkSamplerInterfaceBlock::unflatten(Unflattener& unflattener,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!unflattener.read(&fieldTransferFunction)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
builder.add({ fieldName.data(), fieldName.size() }, SamplerInterfaceBlock::Type(fieldType),
|
||||
SamplerInterfaceBlock::Format(fieldFormat),
|
||||
SamplerInterfaceBlock::Precision(fieldPrecision),
|
||||
fieldMultisample);
|
||||
fieldMultisample,
|
||||
SamplerInterfaceBlock::SamplerTransferFunction(fieldTransferFunction));
|
||||
}
|
||||
|
||||
*sib = builder.build();
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
using Format = backend::SamplerFormat;
|
||||
using Precision = backend::Precision;
|
||||
using SamplerParams = backend::SamplerParams;
|
||||
using SamplerTransferFunction = backend::SamplerTransferFunction;
|
||||
|
||||
struct SamplerInfo { // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
utils::CString name; // name of this sampler
|
||||
@@ -55,6 +56,7 @@ public:
|
||||
Format format; // format of this sampler
|
||||
Precision precision; // precision of this sampler
|
||||
bool multisample; // multisample capable
|
||||
SamplerTransferFunction transferFunction;
|
||||
};
|
||||
|
||||
class Builder {
|
||||
@@ -73,6 +75,7 @@ public:
|
||||
Format format; // format of this sampler
|
||||
Precision precision; // precision of this sampler
|
||||
bool multisample = false; // multisample capable
|
||||
SamplerTransferFunction transferFunction;
|
||||
};
|
||||
|
||||
// Give a name to this sampler interface block
|
||||
@@ -83,7 +86,8 @@ public:
|
||||
// Add a sampler
|
||||
Builder& add(std::string_view samplerName, Type type, Format format,
|
||||
Precision precision = Precision::MEDIUM,
|
||||
bool multisample = false) noexcept;
|
||||
bool multisample = false,
|
||||
SamplerTransferFunction transferFunction = SamplerTransferFunction::UNDEFINED) noexcept;
|
||||
|
||||
// Add multiple samplers
|
||||
Builder& add(std::initializer_list<ListEntry> list) noexcept;
|
||||
|
||||
@@ -44,10 +44,10 @@ SamplerInterfaceBlock::Builder::stageFlags(backend::ShaderStageFlags stageFlags)
|
||||
|
||||
SamplerInterfaceBlock::Builder& SamplerInterfaceBlock::Builder::add(
|
||||
std::string_view samplerName, Type type, Format format,
|
||||
Precision precision, bool multisample) noexcept {
|
||||
Precision precision, bool multisample, SamplerTransferFunction transferFunction) noexcept {
|
||||
mEntries.push_back({
|
||||
{ samplerName.data(), samplerName.size() }, { },
|
||||
uint8_t(mEntries.size()), type, format, precision, multisample });
|
||||
uint8_t(mEntries.size()), type, format, precision, multisample, transferFunction });
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ SamplerInterfaceBlock SamplerInterfaceBlock::Builder::build() {
|
||||
SamplerInterfaceBlock::Builder& SamplerInterfaceBlock::Builder::add(
|
||||
std::initializer_list<ListEntry> list) noexcept {
|
||||
for (auto& e : list) {
|
||||
add(e.name, e.type, e.format, e.precision, e.multisample);
|
||||
add(e.name, e.type, e.format, e.precision, e.multisample, e.transferFunction);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ using SamplerType = MaterialBuilder::SamplerType;
|
||||
using SubpassType = MaterialBuilder::SubpassType;
|
||||
using SamplerFormat = MaterialBuilder::SamplerFormat;
|
||||
using ParameterPrecision = MaterialBuilder::ParameterPrecision;
|
||||
using SamplerTransferFunction = MaterialBuilder::SamplerTransferFunction;
|
||||
using OutputTarget = MaterialBuilder::OutputTarget;
|
||||
using OutputQualifier = MaterialBuilder::VariableQualifier;
|
||||
using OutputType = MaterialBuilder::OutputType;
|
||||
@@ -75,6 +76,7 @@ private:
|
||||
static std::unordered_map<std::string, SubpassType> mStringToSubpassType;
|
||||
static std::unordered_map<std::string, SamplerFormat> mStringToSamplerFormat;
|
||||
static std::unordered_map<std::string, ParameterPrecision> mStringToSamplerPrecision;
|
||||
static std::unordered_map<std::string, SamplerTransferFunction> mStringToSamplerTransferFunction;
|
||||
static std::unordered_map<std::string, OutputTarget> mStringToOutputTarget;
|
||||
static std::unordered_map<std::string, OutputQualifier> mStringToOutputQualifier;
|
||||
static std::unordered_map<std::string, OutputType> mStringToOutputType;
|
||||
|
||||
@@ -239,6 +239,7 @@ public:
|
||||
using SubpassType = filament::backend::SubpassType;
|
||||
using SamplerFormat = filament::backend::SamplerFormat;
|
||||
using ParameterPrecision = filament::backend::Precision;
|
||||
using SamplerTransferFunction = filament::backend::SamplerTransferFunction;
|
||||
using Precision = filament::backend::Precision;
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using FeatureLevel = filament::backend::FeatureLevel;
|
||||
@@ -307,11 +308,8 @@ public:
|
||||
*/
|
||||
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(const char* name, SamplerType samplerType,
|
||||
ParameterPrecision precision) noexcept;
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT,
|
||||
SamplerTransferFunction transferFunction = SamplerTransferFunction::UNDEFINED) noexcept;
|
||||
|
||||
|
||||
MaterialBuilder& buffer(filament::BufferInterfaceBlock bib) noexcept;
|
||||
@@ -618,16 +616,20 @@ public:
|
||||
Parameter() noexcept: parameterType(INVALID) {}
|
||||
|
||||
// Sampler
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p)
|
||||
: name(paramName), size(1), precision(p), samplerType(t), format(f), parameterType(SAMPLER) { }
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p,
|
||||
SamplerTransferFunction tf)
|
||||
: name(paramName), size(1), precision(p), samplerType(t), format(f),
|
||||
parameterType(SAMPLER), transferFunction(tf) { }
|
||||
|
||||
// Uniform
|
||||
Parameter(const char* paramName, UniformType t, size_t typeSize, ParameterPrecision p)
|
||||
: name(paramName), size(typeSize), uniformType(t), precision(p), parameterType(UNIFORM) { }
|
||||
: name(paramName), size(typeSize), uniformType(t), precision(p),
|
||||
parameterType(UNIFORM) { }
|
||||
|
||||
// Subpass
|
||||
Parameter(const char* paramName, SubpassType t, SamplerFormat f, ParameterPrecision p)
|
||||
: name(paramName), size(1), precision(p), subpassType(t), format(f), parameterType(SUBPASS) { }
|
||||
: name(paramName), size(1), precision(p), subpassType(t), format(f),
|
||||
parameterType(SUBPASS) { }
|
||||
|
||||
utils::CString name;
|
||||
size_t size;
|
||||
@@ -636,6 +638,7 @@ public:
|
||||
SamplerType samplerType;
|
||||
SubpassType subpassType;
|
||||
SamplerFormat format;
|
||||
SamplerTransferFunction transferFunction;
|
||||
enum {
|
||||
INVALID,
|
||||
UNIFORM,
|
||||
|
||||
@@ -117,6 +117,17 @@ std::unordered_map<std::string, ParameterPrecision>& Enums::getMap<ParameterPrec
|
||||
return mStringToSamplerPrecision;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, SamplerTransferFunction> Enums::mStringToSamplerTransferFunction = {
|
||||
{ "undefined", SamplerTransferFunction::UNDEFINED },
|
||||
{ "identity", SamplerTransferFunction::IDENTITY },
|
||||
{ "srgbToLinear", SamplerTransferFunction::SRGB_TO_LINEAR },
|
||||
};
|
||||
|
||||
template <>
|
||||
std::unordered_map<std::string, SamplerTransferFunction>& Enums::getMap<SamplerTransferFunction>() noexcept {
|
||||
return mStringToSamplerTransferFunction;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, OutputTarget> Enums::mStringToOutputTarget = {
|
||||
{ "color", OutputTarget::COLOR },
|
||||
{ "depth", OutputTarget::DEPTH }
|
||||
|
||||
@@ -248,19 +248,14 @@ MaterialBuilder& MaterialBuilder::parameter(const char* name, UniformType type,
|
||||
return parameter(name, 1, type, precision);
|
||||
}
|
||||
|
||||
|
||||
MaterialBuilder& MaterialBuilder::parameter(const char* name, SamplerType samplerType,
|
||||
SamplerFormat format, ParameterPrecision precision) noexcept {
|
||||
SamplerFormat format, ParameterPrecision precision,
|
||||
SamplerTransferFunction transferFunction) noexcept {
|
||||
ASSERT_POSTCONDITION(mParameterCount < MAX_PARAMETERS_COUNT, "Too many parameters");
|
||||
mParameters[mParameterCount++] = { name, samplerType, format, precision };
|
||||
mParameters[mParameterCount++] = { name, samplerType, format, precision, transferFunction };
|
||||
return *this;
|
||||
}
|
||||
|
||||
MaterialBuilder& MaterialBuilder::parameter(const char* name, SamplerType samplerType,
|
||||
ParameterPrecision precision) noexcept {
|
||||
return parameter(name, samplerType, SamplerFormat::FLOAT, precision);
|
||||
}
|
||||
|
||||
template<typename T, typename>
|
||||
MaterialBuilder& MaterialBuilder::constant(const char* name, ConstantType type, T defaultValue) {
|
||||
auto result = std::find_if(mConstants.begin(), mConstants.end(), [name](const Constant& c) {
|
||||
@@ -556,7 +551,8 @@ void MaterialBuilder::prepareToBuild(MaterialInfo& info) noexcept {
|
||||
assert_invariant(!param.isSubpass());
|
||||
if (param.isSampler()) {
|
||||
sbb.add({ param.name.data(), param.name.size() },
|
||||
param.samplerType, param.format, param.precision);
|
||||
param.samplerType, param.format, param.precision, /*multisample=*/false,
|
||||
param.transferFunction);
|
||||
} else if (param.isUniform()) {
|
||||
ibb.add({{{ param.name.data(), param.name.size() },
|
||||
uint32_t(param.size == 1u ? 0u : param.size), param.uniformType,
|
||||
|
||||
@@ -65,6 +65,7 @@ void MaterialSamplerInterfaceBlockChunk::flatten(Flattener& f) {
|
||||
f.writeUint8(static_cast<uint8_t>(sInfo.format));
|
||||
f.writeUint8(static_cast<uint8_t>(sInfo.precision));
|
||||
f.writeBool(sInfo.multisample);
|
||||
f.writeUint8(static_cast<uint8_t>(sInfo.transferFunction));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +180,19 @@ static bool processParameter(MaterialBuilder& builder, const JsonishObject& json
|
||||
}
|
||||
}
|
||||
|
||||
const JsonishValue* transferFunctionValue = jsonObject.getValue("transferFunction");
|
||||
if (transferFunctionValue) {
|
||||
if (transferFunctionValue->getType() != JsonishValue::STRING) {
|
||||
std::cerr << "parameters: transferFunction must be a STRING." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto transferFunctionString = formatValue->toJsonString();
|
||||
if (!Enums::isValid<SamplerTransferFunction>(transferFunctionString->getString())){
|
||||
return logEnumIssue("parameters", *transferFunctionString, Enums::map<SamplerTransferFunction>());
|
||||
}
|
||||
}
|
||||
|
||||
auto typeString = typeValue->toJsonString()->getString();
|
||||
auto nameString = nameValue->toJsonString()->getString();
|
||||
|
||||
@@ -205,22 +218,22 @@ static bool processParameter(MaterialBuilder& builder, const JsonishObject& json
|
||||
return false;
|
||||
}
|
||||
|
||||
MaterialBuilder::SamplerType type = Enums::toEnum<SamplerType>(typeString);
|
||||
if (precisionValue && formatValue) {
|
||||
auto format = Enums::toEnum<SamplerFormat>(formatValue->toJsonString()->getString());
|
||||
auto precision =
|
||||
Enums::toEnum<ParameterPrecision>(precisionValue->toJsonString()->getString());
|
||||
builder.parameter(nameString.c_str(), type, format, precision);
|
||||
} else if (formatValue) {
|
||||
auto format = Enums::toEnum<SamplerFormat>(formatValue->toJsonString()->getString());
|
||||
builder.parameter(nameString.c_str(), type, format);
|
||||
} else if (precisionValue) {
|
||||
auto precision =
|
||||
Enums::toEnum<ParameterPrecision>(precisionValue->toJsonString()->getString());
|
||||
builder.parameter(nameString.c_str(), type, precision);
|
||||
} else {
|
||||
builder.parameter(nameString.c_str(), type);
|
||||
SamplerType type = Enums::toEnum<SamplerType>(typeString);
|
||||
SamplerFormat format = SamplerFormat::FLOAT;
|
||||
if (formatValue) {
|
||||
format = Enums::toEnum<SamplerFormat>(formatValue->toJsonString()->getString());
|
||||
}
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT;
|
||||
if (precisionValue) {
|
||||
precision =
|
||||
Enums::toEnum<ParameterPrecision>(precisionValue->toJsonString()->getString());
|
||||
}
|
||||
SamplerTransferFunction transferFunction = SamplerTransferFunction::UNDEFINED;
|
||||
if (transferFunctionValue) {
|
||||
transferFunction =
|
||||
Enums::toEnum<SamplerTransferFunction>(transferFunctionValue->toJsonString()->getString());
|
||||
}
|
||||
builder.parameter(nameString.c_str(), type, format, precision, transferFunction);
|
||||
} else {
|
||||
std::cerr << "parameters: the type '" << typeString
|
||||
<< "' for parameter with name '" << nameString << "' is neither a valid uniform "
|
||||
|
||||
Reference in New Issue
Block a user