Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable optimizations for ESSL 1.0 code #7358

Merged
merged 1 commit into from
Nov 16, 2023
Merged

Conversation

elizagamedev
Copy link
Contributor

@elizagamedev elizagamedev commented Nov 13, 2023

The CL introducing the ESSL 1.0 chunk in materials inadvertently disabled optimizations for said code. This commit reintroduces those optimizations and fixes associated bugs which manifested. In particular, spirv-cross was generating uints for bools; this has been fixed with a hack. Additionally, spirv-cross is now compiled with exceptions enabled so that matc can gracefully fail and show the code which failed to compile rather than abruptly aborting.

Upstream issue for spirv-cross.

Upstream PR for spirv-cross.

Copy link

Please add a release note line to NEW_RELEASE_NOTES.md. If this PR does not warrant a release note, add the 'internal' label to this PR.

@elizagamedev elizagamedev force-pushed the exv/essl1-optimizations branch 2 times, most recently from b370128 to 0d0ef80 Compare November 13, 2023 23:12
libs/filamat/src/shaders/CodeGenerator.cpp Outdated Show resolved Hide resolved
@@ -14977,7 +14977,11 @@ string CompilerGLSL::flags_to_qualifiers_glsl(const SPIRType &type, const Bitset
{
auto &execution = get_entry_point();

if (flags.get(DecorationRelaxedPrecision))
if (type.basetype == SPIRType::UInt && is_legacy()) {
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes submitted to spirv-cross upstream? Otherwise, we'll lose these patches when building inside of G3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted an upstream PR, but I'm not sure they'll like it since it doesn't fix the root of the problem.

filament/src/materials/blitLow.mat Outdated Show resolved Hide resolved
@@ -460,19 +491,22 @@ io::sstream& CodeGenerator::generateOutput(io::sstream& out, ShaderStage type,
const char* materialTypeString = getOutputTypeName(materialOutputType);
const char* typeString = getOutputTypeName(outputType);

bool generate_essl3_code = mTargetLanguage == TargetLanguage::SPIRV
Copy link
Collaborator

Choose a reason for hiding this comment

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

why can't we generate essl1 with target lang spirv?

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 described it a bit above in a comment elsewhere in this file:

// During compilation and optimization, __VERSION__ reflects the shader language version of the
// intermediate code, not the version of the final code. spirv-cross automatically adapts
// certain language features (e.g. fragment output) but leaves others untouched (e.g. sampler
// functions, bit shift operations). Client code may have to make decisions based on this
// information, so define a FILAMENT_EFFECTIVE_VERSION constant.

Since the intermediate code is always ESSL 3.0 even if it eventually becomes ESSL 1.0, we have to sometimes generate ESSL 3.0 stuff like this.

@elizagamedev elizagamedev force-pushed the exv/essl1-optimizations branch from a6f1206 to 85f145e Compare November 14, 2023 19:42
@elizagamedev elizagamedev force-pushed the exv/essl1-optimizations branch 3 times, most recently from e4fd636 to 29eb09a Compare November 15, 2023 22:38
elizagamedev added a commit that referenced this pull request Nov 15, 2023
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
elizagamedev added a commit that referenced this pull request Nov 16, 2023
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
elizagamedev added a commit that referenced this pull request Nov 16, 2023
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
@elizagamedev elizagamedev force-pushed the exv/essl1-optimizations branch 2 times, most recently from a9a6915 to d064a67 Compare November 16, 2023 20:55
The CL introducing the ESSL 1.0 chunk in materials inadvertently disabled
optimizations for said code. This commit reintroduces those optimizations and
fixes associated bugs which manifested. In particular, spirv-cross was
generating uints for bools; this has been fixed with a hack. Additionally,
spirv-cross is now compiled with exceptions enabled so that matc can gracefully
fail and show the code which failed to compile rather than abruptly aborting.
@elizagamedev elizagamedev force-pushed the exv/essl1-optimizations branch from d064a67 to dedaba3 Compare November 16, 2023 20:58
@elizagamedev elizagamedev merged commit 2bd48f5 into main Nov 16, 2023
11 checks passed
@elizagamedev elizagamedev deleted the exv/essl1-optimizations branch November 16, 2023 22:59
poweifeng pushed a commit that referenced this pull request Nov 27, 2023
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
plepers pushed a commit to plepers/filament that referenced this pull request Dec 9, 2023
Since google#7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants