Skip to content

Commit

Permalink
Miscellaneous feature level 0 fixes
Browse files Browse the repository at this point in the history
Fix edge case where an empty struct could be generated in an ESSL 1.0 shader.

Include _maskThreshold and _doubleSided in ESSL 1.0 shaders.

Add GL_OES_standard_derivatives extension to ESSL 1.0 shaders. According to
gpuinfo.org, this has 96% device coverage and supports both Mali-400 and Adreno
(TM) 304.

Remove 3D sampler support from ESSL 1.0 shaders. This extension is only
supported by 62% of devices.

Change filagui material to a FL0 material.
  • Loading branch information
elizagamedev committed Oct 24, 2023
1 parent d3016ad commit a5a9c91
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
- matinfo: Add support for viewing ESSL 1.0 shaders
- engine: Add `Renderer::getClearOptions()` [b/243846268]
- engine: Fix stable shadows (again) when an IBL rotation is used
- matc: Enable `GL_OES_standard_derivatives` extension in ESSL 1.0 shaders
- matc: Fix code generation of double sided and masked materials in ESSL 1.0 shaders
- filagui: Add support for feature level 0
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class BufferInterfaceBlock {

bool isEmpty() const noexcept { return mFieldInfoList.empty(); }

bool isEmptyForFeatureLevel(backend::FeatureLevel featureLevel) const noexcept;

Alignment getAlignment() const noexcept { return mAlignment; }

Target getTarget() const noexcept { return mTarget; }
Expand Down
9 changes: 8 additions & 1 deletion libs/filabridge/src/BufferInterfaceBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ BufferInterfaceBlock::FieldInfo const* BufferInterfaceBlock::getFieldInfo(
return &mFieldInfoList[pos->second];
}

bool BufferInterfaceBlock::isEmptyForFeatureLevel(
backend::FeatureLevel featureLevel) const noexcept {
return std::all_of(mFieldInfoList.begin(), mFieldInfoList.end(),
[featureLevel](auto const &info) {
return featureLevel < info.minFeatureLevel;
});
}

uint8_t UTILS_NOINLINE BufferInterfaceBlock::baseAlignmentForType(BufferInterfaceBlock::Type type) noexcept {
switch (type) {
case Type::BOOL:
Expand Down Expand Up @@ -230,4 +238,3 @@ uint8_t UTILS_NOINLINE BufferInterfaceBlock::strideForType(BufferInterfaceBlock:
}

} // namespace filament

5 changes: 3 additions & 2 deletions libs/filagui/src/materials/uiBlit.mat
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ material {
shadingModel : unlit,
culling : none,
depthCulling: false,
blending : transparent
blending : transparent,
featureLevel : 0
}

fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
vec2 uv = getUV0();
uv.y = 1.0 - uv.y;
vec4 albedo = texture(materialParams_albedo, uv);
vec4 albedo = texture2D(materialParams_albedo, uv);
material.baseColor = getColor() * albedo;
material.baseColor.rgb *= material.baseColor.a;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/filamat/src/MaterialBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ void MaterialBuilder::prepareToBuild(MaterialInfo& info) noexcept {
}

if (mBlendingMode == BlendingMode::MASKED) {
ibb.add({{ "_maskThreshold", 0, UniformType::FLOAT }});
ibb.add({{ "_maskThreshold", 0, UniformType::FLOAT, Precision::DEFAULT, FeatureLevel::FEATURE_LEVEL_0 }});
}

if (mDoubleSidedCapability) {
ibb.add({{ "_doubleSided", 0, UniformType::BOOL }});
ibb.add({{ "_doubleSided", 0, UniformType::BOOL, Precision::DEFAULT, FeatureLevel::FEATURE_LEVEL_0 }});
}

mRequiredAttributes.set(VertexAttribute::POSITION);
Expand Down
12 changes: 7 additions & 5 deletions libs/filamat/src/shaders/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade
out << "#extension GL_OES_EGL_image_external : require\n\n";
}
}
if (material.has3dSamplers && mFeatureLevel == FeatureLevel::FEATURE_LEVEL_0) {
out << "#extension GL_OES_texture_3D : require\n\n";
}
if (v.hasInstancedStereo() && stage == ShaderStage::VERTEX) {
// If we're not processing the shader through glslang (in the case of unoptimized
// OpenGL shaders), then we need to add the #extension string ourselves.
Expand All @@ -89,6 +86,10 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade
break;
}

if (mFeatureLevel == FeatureLevel::FEATURE_LEVEL_0) {
out << "#extension GL_OES_standard_derivatives : require\n\n";
}

// This allows our includer system to use the #line directive to denote the source file for
// #included code. This way, glslang reports errors more accurately.
out << "#extension GL_GOOGLE_cpp_style_line_directive : enable\n\n";
Expand Down Expand Up @@ -554,11 +555,12 @@ io::sstream& CodeGenerator::generateUboAsPlainUniforms(io::sstream& out, ShaderS

io::sstream& CodeGenerator::generateBufferInterfaceBlock(io::sstream& out, ShaderStage stage,
uint32_t binding, const BufferInterfaceBlock& uib) const {
auto const& infos = uib.getFieldInfoList();
if (infos.empty()) {
if (uib.isEmptyForFeatureLevel(mFeatureLevel)) {
return out;
}

auto const& infos = uib.getFieldInfoList();

if (mTargetLanguage == TargetLanguage::GLSL &&
mFeatureLevel == FeatureLevel::FEATURE_LEVEL_0) {
// we need to generate a structure instead
Expand Down

0 comments on commit a5a9c91

Please sign in to comment.