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

Refactored external image handling in PlatformEGLAndroid #8512

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

alizahlalani
Copy link
Contributor

No description provided.

@pixelflinger pixelflinger self-requested a review March 10, 2025 21:15
@@ -187,6 +184,9 @@ Texture* Texture::Builder::build(Engine& engine) {
// SAMPLER_EXTERNAL implies imported.
if (mImpl->mTarget == SamplerType::SAMPLER_EXTERNAL) {
mImpl->mExternal = true;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: keep this up top and just condition on non-external, but maybe the real fix.

Also I wonder if the format here has to match the format we'd get from ahardwarebuffer.

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 re: nit

re: " if the format here has to match the format we'd get from ahardwarebuffer" - the format that was passed in via impress was directly derived from the hardwarebuffer via PlatformEGLAndroid::createExternalImage via ExternalImageEGLAndroid

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but I mean in the general case; not every client is impress.

Copy link
Contributor Author

@alizahlalani alizahlalani Mar 12, 2025

Choose a reason for hiding this comment

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

Given that this whole model relies on the client registering an image or ahardwarebuffer via platform directly, I'm not sure an extra check is needed, but I will defer to FIlament team on if you want this added. We don't currently retain MBuffer on engine in this implementation, but I'm sure there's some way to derive it from the image handle.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, i'm not sure about this. This code has existed before for other (non AHB) external samplers. I wonder if skipping it entirely is ok. I'll leave this one to Mathias to comment.

@alizahlalani alizahlalani force-pushed the externalImageRefactor branch from 2d9d4ba to be2c767 Compare March 11, 2025 21:37
@alizahlalani alizahlalani force-pushed the externalImageRefactor branch from be2c767 to c2afe9b Compare March 11, 2025 21:39
Comment on lines 51 to 60
struct ExternalImageEGLAndroid : public ExternalImageEGL {
AHardwareBuffer* aHardwareBuffer = nullptr;
bool sRGB = false;
unsigned int width; // Texture width
unsigned int height; // Texture height
TextureFormat format;// Texture format
TextureUsage usage; // Texture usage flags
protected:
~ExternalImageEGLAndroid() override;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

that definitely should not be public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved as discussed offline - I left the fields in ExternalImageEGLAndroid and made an extra metadata struct thats public to avoid additional AHardwareBufferDescribe calls in PlatformEGLAndroid::setImage which relies on the correct texture format and usage

Comment on lines 312 to 314
// Create and bind the OpenGL texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you change ANY GL state, you must restore it upon returning -- because the backend caches the state and the cache would become out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to understand the lifecycle of this - where would I restore the state? In PlatformEGLAndroid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved as discussed offline

return false;
}
glBindTexture(GL_TEXTURE_2D, prevTexture);
Copy link
Contributor

Choose a reason for hiding this comment

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

IRC the orders of the calls have to be in the opposite order, glActiveTexture first
Second, better restore the state before checking glEGLImageTargetTexture2DOES error so its properly restored also in the case of an error.

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.

4 participants