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

Fix Firefox console warnings. #5939

Merged
merged 12 commits into from
Mar 1, 2018
Merged

Fix Firefox console warnings. #5939

merged 12 commits into from
Mar 1, 2018

Conversation

bagnell
Copy link
Contributor

@bagnell bagnell commented Oct 26, 2017

  • Only use pre-multiply alpha and y flip for DOM sources.
  • Initialized textures before using texSubImage2D.
    • Use texImage2D when the sub image is the same size as the texture
    • Use texImage2D to initialize to zero when the sub image is smaller.

Fixes #5912

@cesium-concierge
Copy link

@bagnell, thanks for the pull request! Maintainers, we have a signed CLA from @bagnell, so you can review this at any time.

I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Thanks again.

@@ -121,25 +120,30 @@ define([
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(textureTarget, texture);

function createFace(target, sourceFace) {
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to leave this TODO in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was in the original code. I just moved it.

function createFace(target, sourceFace) {
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there duplicate pixelStorei calls if sourceFace.arrayBufferView below is not defined? If so, can we move these to the first if block?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bump - I was about to leave this comment and then noticed @pjcozzi already mentioned it.

gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView);
} else {
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source);
var uploaded = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below seems more complicated than it needs to be; I will not have the time to dive deep for awhile.

@lilleyse can you take a look?

@mramato
Copy link
Contributor

mramato commented Oct 31, 2017

@bagnell should we get this into tomorrow's release? Seems like we would want to (especially if it's a speed improvement).

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 31, 2017

Please do not rush the review - would rather see this go into the following release.

@mramato
Copy link
Contributor

mramato commented Nov 1, 2017

Do you think this will help with #3888? The Firefox tab now crashes if you run the tests with WebGL validation.

@bagnell
Copy link
Contributor Author

bagnell commented Nov 9, 2017

No, the tab still crashes for me.

@thw0rted
Copy link
Contributor

Hey all, just curious if this fell off somebody's plate -- I'm still seeing the warnings I mentioned in #5912 .

@hpinkos
Copy link
Contributor

hpinkos commented Feb 16, 2018

Thanks for the reminder @thw0rted

@bagnell what's the status of this PR?

@bagnell
Copy link
Contributor Author

bagnell commented Feb 16, 2018

Waiting for a review from @lilleyse.

function createFace(target, sourceFace) {
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Bump - I was about to leave this comment and then noticed @pjcozzi already mentioned it.

gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here - there are some situations where gl.pixelStorei gets called twice.

}

var size = PixelFormat.componentsLength(this._pixelFormat) * this._size * this._size;
var bufferView = new constructor(size);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could maybe be simplified with PixelFormat.textureSizeInBytes. And to round it out PixelFormat could have a function like PixelFormat.createTypedArray, like how we have ComponentDatatype.createTypedArray

createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY, preMultiplyAlpha, flipY);
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY, preMultiplyAlpha, flipY);
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ, preMultiplyAlpha, flipY);
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ, preMultiplyAlpha, flipY);
} else {
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it valid to pass in null? If the value is null does the texture still require another texImage2D call with an empty typed array? Could that step go here instead? If so, then I think all the initialized checks in CubeMapFace may not be needed.

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 did it this way for the case where you create a texture and upload the entire texture later. This avoids creating an array buffer of all zeroes. The only time the array buffer of zeroes would be created would be when a texture is created and then a bunch of texSubImage2D's are called to fill out an atlas. If we don't care about that case or optimization, then Ill change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, a texture that is going to be rendered to cannot be set.

// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
gl.texImage2D(textureTarget, 0, internalFormat, pixelFormat, pixelDatatype, source);
}
} else {
gl.texImage2D(textureTarget, 0, internalFormat, width, height, 0, pixelFormat, pixelDatatype, null);
initialized = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Basically the same note as above, can we initialize the texture with an empty typed array now to avoid the initialized check in copyFrom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment here.

@bagnell
Copy link
Contributor Author

bagnell commented Feb 28, 2018

@lilleyse This is ready for another look.

gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the same changes as CubeMapFace so that pixelStorei isn't called multiple times in some cases

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.

@lilleyse
Copy link
Contributor

Tests pass and the Sandcastle demos I tried still work.

Here and below seems more complicated than it needs to be; I will not have the time to dive deep for awhile. @lilleyse can you take a look?

It seems mostly unavoidable to me based on this discussion #5939 (comment).

Do we want to release this with 1.43? @pjcozzi did you want to take a look?

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 28, 2018

I don't have bandwidth to look at this for 1.43, but please merge if you are confident.

@lilleyse lilleyse merged commit 0f92a1b into master Mar 1, 2018
@lilleyse lilleyse deleted the firefox-warnings branch March 1, 2018 15:28
hpinkos pushed a commit that referenced this pull request Mar 1, 2018
@hpinkos hpinkos mentioned this pull request Mar 1, 2018
lilleyse added a commit that referenced this pull request Mar 1, 2018
@bagnell bagnell mentioned this pull request Mar 1, 2018
1 task
@markerikson
Copy link
Contributor

I'm still seeing a related warning with Cesium 1.45 and Firefox 52 (which we are unfortunately stuck on for our application):

Error: WebGL: texSubImage2D: Conversion requires pixel reformatting.

Was that supposed to be resolved by this PR?

@hpinkos
Copy link
Contributor

hpinkos commented May 11, 2018

Hi @markerikson, do you see that error in Cesium 1.44 as well? This PR was added in 1.43 so if you're seeing the error in 1.45 but not 1.44 it means that we might have introduced something in 1.45

@markerikson
Copy link
Contributor

Loading up our app with 1.44, I actually see considerably more warnings:

Error: WebGL: texImage2D: Alpha-premult and y-flip are deprecated for non-DOM-Element uploads.
Error: WebGL: texImage2D: Conversion requires y-flip.
Error: WebGL: texSubImage2D: Texture has not been initialized prior to a partial upload, forcing the browser to clear it. This may be slow.
Error: WebGL: texSubImage2D: This operation requires zeroing texture data. This is slow.
Error: WebGL: texSubImage2D: Conversion requires pixel reformatting.

(All repeated quite a few times, just isolating the unique messages.)

In 1.45, I only see the "pixel formatting" message.

@bagnell
Copy link
Contributor Author

bagnell commented May 11, 2018

I haven't seen that error, but I'm using Firefox 60. Do you see that in the Viewer or any Sandcastle example? If not, can you post an example so I can take a look?

@markerikson
Copy link
Contributor

Yes, just loading up the main Sandcastle page in FF52 immediately shows the "pixel reformatting" warning in the console.

@hpinkos
Copy link
Contributor

hpinkos commented May 11, 2018

Hmm, I don't see it on FF59 either. It's unfortunate you're unable to upgrade

@markerikson
Copy link
Contributor

Yeah, we have an internal app that targets a specific Firefox ESR version at a time, so we're still targeting FF52 for this dev cycle. We'll live with it, just was wanting to see if it was supposed to have been resolved already (and at least there's fewer warnings).

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.

8 participants