Skip to content

Commit

Permalink
Fix ESSL 1.0 external samplers
Browse files Browse the repository at this point in the history
matc was re-introducing the incorrect extension for external samplers in ESSL
1.0 code after spirv optimizations.
  • Loading branch information
elizagamedev committed Nov 30, 2023
1 parent 06bae26 commit b007e91
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ for next branch cut* header.
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).

## Release notes for next branch cut

- matc: Fix ESSL 1.0 codegen when using external samplers [⚠️ **Recompile materials**]
3 changes: 2 additions & 1 deletion libs/filamat/src/MaterialBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ bool MaterialBuilder::generateShaders(JobSystem& jobSystem, const std::vector<Va

if (targetApi == TargetApi::OPENGL) {
if (targetLanguage == TargetLanguage::SPIRV) {
ShaderGenerator::fixupExternalSamplers(shaderModel, shader, info);
ShaderGenerator::fixupExternalSamplers(shaderModel, shader, featureLevel,
info);
}
}

Expand Down
7 changes: 5 additions & 2 deletions libs/filamat/src/shaders/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ io::sstream& CodeGenerator::generateSubpass(io::sstream& out, SubpassInfo subpas
}

void CodeGenerator::fixupExternalSamplers(
std::string& shader, SamplerInterfaceBlock const& sib) noexcept {
std::string& shader, SamplerInterfaceBlock const& sib, FeatureLevel featureLevel) noexcept {
auto const& infos = sib.getSamplerInfoList();
if (infos.empty()) {
return;
Expand Down Expand Up @@ -813,7 +813,10 @@ void CodeGenerator::fixupExternalSamplers(
while (shader[index] != '\n') index++;
index++;

shader.insert(index, "#extension GL_OES_EGL_image_external_essl3 : require\n");
const char *extensionLine = (featureLevel >= FeatureLevel::FEATURE_LEVEL_1)
? "#extension GL_OES_EGL_image_external_essl3 : require\n\n"
: "#extension GL_OES_EGL_image_external : require\n\n";
shader.insert(index, extensionLine);
}
}

Expand Down
3 changes: 2 additions & 1 deletion libs/filamat/src/shaders/CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class UTILS_PRIVATE CodeGenerator {
static utils::io::sstream& generateParameters(utils::io::sstream& out, ShaderStage type);

static void fixupExternalSamplers(
std::string& shader, filament::SamplerInterfaceBlock const& sib) noexcept;
std::string& shader, filament::SamplerInterfaceBlock const& sib,
FeatureLevel featureLevel) noexcept;

// These constants must match the equivalent in MetalState.h.
// These values represent the starting index for uniform, ssbo, and sampler group [[buffer(n)]]
Expand Down
7 changes: 4 additions & 3 deletions libs/filamat/src/shaders/ShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,13 @@ ShaderGenerator::ShaderGenerator(
}
}

void ShaderGenerator::fixupExternalSamplers(ShaderModel sm,
std::string& shader, MaterialInfo const& material) noexcept {
void ShaderGenerator::fixupExternalSamplers(ShaderModel sm, std::string& shader,
MaterialBuilder::FeatureLevel featureLevel,
MaterialInfo const& material) noexcept {
// External samplers are only supported on GL ES at the moment, we must
// skip the fixup on desktop targets
if (material.hasExternalSamplers && sm == ShaderModel::MOBILE) {
CodeGenerator::fixupExternalSamplers(shader, material.sib);
CodeGenerator::fixupExternalSamplers(shader, material.sib, featureLevel);
}
}

Expand Down
1 change: 1 addition & 0 deletions libs/filamat/src/shaders/ShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ShaderGenerator {
* the optimizations have been applied.
*/
static void fixupExternalSamplers(filament::backend::ShaderModel sm, std::string& shader,
MaterialBuilder::FeatureLevel featureLevel,
MaterialInfo const& material) noexcept;

private:
Expand Down

0 comments on commit b007e91

Please sign in to comment.