-
Notifications
You must be signed in to change notification settings - Fork 3.6k
CopyTexture Native rendering command #16497
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
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/16497/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/16497/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/16497/merge#BCU1XR#0 |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
@@ -1635,9 +1635,14 @@ export class NativeEngine extends Engine { | |||
} | |||
|
|||
if (!!texture && !!texture._hardwareTexture) { | |||
const context = canvas.getContext(); | |||
context.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really ok to do this synchronously right here? Couldn't queued commands still alter the state of the canvas/context? Should the flush itself be queued, even if the flush has to be a blocking operation on the native side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the flush (and nanovg rendering) happens before the copy, it will be fine. The queue is managed by NativeEngine so, the context/canvas won't be aware of the flush command in the queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't queued commands still alter the state of the canvas/context?
I don't think so. Canvas and nanovg have their own queue that do not share objects with the engine. Main contact point is texture copy.
revert protocol increment introduced with #16497 use with BabylonJS/BabylonNative#1503
BJS PR ( ~~BabylonJS/Babylon.js#16497 BabylonJS/Babylon.js#16502 )needs to be merged before and a new NPM needs to be generated. Copy texture is now a queued command (see BJS PR), protocol changed. Before: - canvas rendering was done with a task, in sync with frame rendering. Now: - canvas rendering is done when when copying texture. Browser HTML Canvas rendering happens when rendering commands are issued. With Native, nanovg keeps its own queue that needs to be actually done before the copy. This is done with the `flush` command. - Because of this 'flush when needed', no need to keep a dirty flag in the context. - In order to always get the same context with `Canvas.getContext` some code from `CanvasTest` branch has been integrated in this PR ### Test add this to experience.js. Quad gets black when texture is disposed. ``` var ground = BABYLON.MeshBuilder.CreateGround("ground1", { width: 0.5, height: 0.5, subdivisions: 2 }, scene); ground.rotation.x = -Math.PI * 0.5; ground.rotation.y = Math.PI; var texSize = 512; var dynamicTexture = new BABYLON.DynamicTexture("dynamic texture", texSize, scene); dynamicTexture.clear(); var context = dynamicTexture.getContext(); var materialGround = new BABYLON.StandardMaterial("Mat", scene); materialGround.diffuseTexture = dynamicTexture; ground.material = materialGround; materialGround.backFaceCulling = false; context.save(); context.fillStyle = "DarkRed"; context.fillRect(0, 0, texSize, texSize); context.restore(); dynamicTexture.update(); setTimeout(() => { console.log("update-dispose"); dynamicTexture.update(); dynamicTexture.dispose(); }, 5000); ``` ### Testing Issues - [x] `Dynamic Texture context clip` : race condition. shape is rendered when using a breakpoint ~~- [ ] `GLTF Extension KHR_materials_volume with attenuation` : rendering is a bit different but it doesn't seem to be related to Canvas/copytexture. To confirm~~ wrong material.js - [x] `GLTF Material Alpha Mask`: inconsistent result. Might be related to race condition mentioned above. --------- Co-authored-by: Ryan Tremblay <[email protected]>
Copy texture as a rendering command. More explanations in BN PR.