Skip to content

OpenEXRCore Deep pixel unpacking optimisation#2049

Merged
cary-ilm merged 4 commits into
AcademySoftwareFoundation:mainfrom
nikos-foundry:exrcore-unpack-optimisation
Jun 13, 2025
Merged

OpenEXRCore Deep pixel unpacking optimisation#2049
cary-ilm merged 4 commits into
AcademySoftwareFoundation:mainfrom
nikos-foundry:exrcore-unpack-optimisation

Conversation

@nikos-foundry
Copy link
Copy Markdown
Contributor

The functions for doing Deep pixel unpacking, had two branch checks (switch statements) for checking the pixel and requested data type within the inner most loop that goes over the pixels of each line. This is definitely unnecessary, since the data types remain the same. However the compiler is not able to optimise this, and the generated assembly for the pixel for loop is massive since it contains all these branch checks.
This PR fixes this issue by moving the two switch statements outside of the pixel for loop, which makes the compiler able to generate much more efficient assembly for the pixel unpacking operations.

Breaking each case of the UNPACK_SAMPLES macro into seperate smaller macros
that can be reused to avoid code duplication.

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>
Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>
The functions for doing Deep pixel unpacking, had two branch checks (switch
statements) for checking the pixel and requested data type within the inner
most loop that goes over the pixels of each line. This is definitely
unnecessary, since the data types remain the same. However the compiler
is not able to optimise this, and the generated assembly for the pixel
for loop is massive since it contains all these branch checks.
This commit fixes this issue by moving the two switch statements outside
of the pixel for loop, which makes the compiler able to generate much more
efficient assembly for the pixel unpacking operations.

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>
@nikos-foundry nikos-foundry force-pushed the exrcore-unpack-optimisation branch from 5f1056b to d513716 Compare May 23, 2025 14:21
@kdt3rd
Copy link
Copy Markdown
Contributor

kdt3rd commented Jun 10, 2025

@nikos-foundry - this looks largely fine - but did you experiment with splitting out entirely to separate C functions instead of the various switch statements? Might need a different inverted type of macro / boilerplate to make that easier, but wonder if the compiler does a bit better without the other switch statements in each functional unit...

Copy link
Copy Markdown
Member

@cary-ilm cary-ilm left a comment

Choose a reason for hiding this comment

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

We discussed this in the OpenEXR TSC meeting yesterday, good to go as is. Thanks!

@cary-ilm cary-ilm merged commit 9bf37a3 into AcademySoftwareFoundation:main Jun 13, 2025
41 checks passed
cary-ilm added a commit that referenced this pull request Jul 23, 2025
* Refactor UNPACK_SAMPLES macro to allow code reuse.

Breaking each case of the UNPACK_SAMPLES macro into seperate smaller macros
that can be reused to avoid code duplication.

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>

* Refactor some common code out in a macro

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>

* Optimise EXRCore Deep pixel unpacking

The functions for doing Deep pixel unpacking, had two branch checks (switch
statements) for checking the pixel and requested data type within the inner
most loop that goes over the pixels of each line. This is definitely
unnecessary, since the data types remain the same. However the compiler
is not able to optimise this, and the generated assembly for the pixel
for loop is massive since it contains all these branch checks.
This commit fixes this issue by moving the two switch statements outside
of the pixel for loop, which makes the compiler able to generate much more
efficient assembly for the pixel unpacking operations.

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>

---------

Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>
Co-authored-by: Cary Phillips <cary@ilm.com>
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