Skip to content

Conversation

rafadevai
Copy link
Contributor

Allow returning a list of supported shader languages instead of only one.

Notify the backend which is the preferred language. In the case of metal, the preferred language will be the first element in the list.

This change will allow a backend to support multiple languages as needed, in the case of the noop driver, it will support a material with any shader languages.

Comment on lines 216 to 230
/*
* Sets a preferred shader language for Filament to use.
*
* The Metal backend supports two shader languages: MSL (Metal Shading Language) and
* METAL_LIBRARY (precompiled .metallib). This option controls which shader language is
* used when materials contain both.
*
* By default, when preferredShaderLanguage is unset, Filament will prefer METAL_LIBRARY
* shaders if present within a material, falling back to MSL. Setting
* preferredShaderLanguage to ShaderLanguage::MSL will instead instruct Filament to check
* for the presence of MSL in a material first, falling back to METAL_LIBRARY if MSL is not
* present.
*
* When using a non-Metal backend, setting this has no effect.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment should still go into Engine::Config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we still include this from the Driver.h files? I think that's the part I wasnt sure about or will it introduce some weird dependency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other enums in Engine::Config like this one. So it should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed mathias suggestion and just did a conversion between both types

@poweifeng poweifeng added the internal Issue/PR does not affect clients label Sep 11, 2025
Comment on lines 231 to 236
enum class PreferredShaderLanguage {
DEFAULT = 0,
MSL = 1,
METAL_LIBRARY = 2,
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, just use ShaderLanguage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then should I add a convert function from the Config::ShaderLanguage to the backend one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// interface with MSL.
virtual ShaderLanguage getShaderLanguage() const noexcept = 0;
virtual utils::FixedCapacityVector<ShaderLanguage> getShaderLanguage(
PreferredShaderLanguage preferredLanguage) const noexcept = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ShaderLanguage here, and document that's only hint. If the backend supports the asked prefered language, it must appear first in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 52 to 57
ShaderLanguage::ESSL1,
ShaderLanguage::ESSL3,
ShaderLanguage::SPIRV,
ShaderLanguage::MSL,
ShaderLanguage::METAL_LIBRARY,
ShaderLanguage::WGSL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ESSL3 should appear first to keep the old behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

size_t getMaxShadowMapCount() const noexcept;

// Return a vector of shader languages, in order of preference.
utils::FixedCapacityVector<backend::ShaderLanguage> getShaderLanguage() const noexcept {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since getShaderLanguage returns a vector, I think we should rename it and the new Driver method to getShaderLanguages (plural).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 378 to 398
/*
* Sets a preferred shader language for Filament to use.
*
* The Metal backend supports two shader languages: MSL (Metal Shading Language) and
* METAL_LIBRARY (precompiled .metallib). This option controls which shader language is
* used when materials contain both.
*
* By default, when preferredShaderLanguage is unset, Filament will prefer METAL_LIBRARY
* shaders if present within a material, falling back to MSL. Setting
* preferredShaderLanguage to ShaderLanguage::MSL will instead instruct Filament to check
* for the presence of MSL in a material first, falling back to METAL_LIBRARY if MSL is not
* present.
*
* When using a non-Metal backend, setting this has no effect.
*/
enum class ShaderLanguage {
DEFAULT = 0,
MSL = 1,
METAL_LIBRARY = 2,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this at all? why not just use backend::ShaderLanguage ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we currently have right now, I reverted back what I changed. This is comparings against my other commits of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we allowed to change it since its a public api?

@rafadevai rafadevai force-pushed the shader_languages branch 2 times, most recently from 6eb62bf to 4369356 Compare September 24, 2025 00:20
Allow returning a list of supported shader languages
instead of only one.

Notify the backend which is the preferred language.
In the case of metal, the preferred language will be
the first element in the list.

This change will allow a backend to support multiple
languages as needed, in the case of the noop driver,
it will support a material with any shader languages.
Address comment on keeping the Config::ShaderLanguage and
passing down a backend::ShaderLanguage as a parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants