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

macOS --metal backwards compatibility regarding primitives 126, 127, 231 #627

Open
marceltaeumel opened this issue Apr 28, 2022 · 16 comments

Comments

@marceltaeumel
Copy link
Contributor

As of 2d7105d, there can be flickering or invisible Morphic dragging if no image-side composition buffer is used.

In Squeak, that composition buffer is either already used or can be activated for older images by hand via:

PasteUpMorph disableDeferredUpdates: true.
Project allMorphicProjects do: [:ea | ea world canvas: nil].

Also see:

For the macOS --metal backend, one might actually implement that extra video buffer here:

- (void) drawImageUsingClip: (CGRect) clip {

And then read from that buffer and not the displayBits here:

// NO: if (!deferDisplayUpdates && syncNeeded) { [self draw]; }

...but only if the deferDisplayUpdates flag is false again.

NOTE THAT the old approach to always commit content from displayBits to the graphics backend entailed a serious performance regression as it slows down the interpreter loop to a maximum of 60 FPS, regardless of other stuff waiting in the image side. That is, primitives 127 and 231 were awfully slow and blocking on macOS. At least that got better in 2d7105d


Another, more flexible, approach would be to fix primitive 126 to actually fail if a certain graphics backend does not support deferred updates. This might work if platform-specific code would be able to let that primitive fail. See:

  • StackInterpreterPrimitives >> primitiveDeferDisplayUpdates in VMMaker

This would work for recent versions of Cuis. However, the existing code in older Squeak images did not correctly invalidate the canvas and thus was not even able to flip between image-side and vm-side composition buffer for different results of primitive 126. Thus, such a fix would also only work from here on for future versions of Squeak and Cuis.

@marceltaeumel
Copy link
Contributor Author

http://lists.squeakfoundation.org/pipermail/vm-dev/2022-April/037922.html

As I said before, this is also a good solution for Cuis. So, my
suggestion, is to simply make primitive 126 fail on MacOs.

This wouldn't affect older images checking for the platform (as you say,
for a performance improvement), but would fix older "untweaked" images,
solving any concern about strict back compatibility for the VM.

@eliotmiranda
Copy link
Contributor

eliotmiranda commented Apr 30, 2022

Well, this would be trivial to make backwards compatible were the necessary old image fix only
PasteUpMorph disableDeferredUpdates: true.
Here's how.

  1. introduce a new flag bit in the image flags (alongside full screen, preemption yields, send wheel events, do mixed arithmetic, et al). This bit is unset in old images
  2. have the beDIsplay primitive 102 interrogate this bit and if unset invoke primitiveDeferDisplayUpdates's innards with false as the effective argument
  3. set the flag bit in new images

Now if there's a way of side effecting the canvas in old images we have a solution, no?

@krono
Copy link
Member

krono commented Apr 30, 2022

I don't really agree that having a flag bit because of Morphic is not overkill.
Letting 126 fail on OS X makes more sense to me…

@krono
Copy link
Member

krono commented Apr 30, 2022

So, if I see that correctly, this is the table of affected user bases

Win Mac Linux
Squeak <=5.3, disableDeferredUpdates: true
Squeak <=5.3, disableDeferredUpdates: false
Squeak <=5.3, updated via update map
Squeak 6 alpha, not updated do not use do not use do not use
Squeak 6 alpha, updated

Please note that the Mac user base is by far the smallest nowadays.

@marceltaeumel
Copy link
Contributor Author

Well, this would be trivial to make backwards compatible were the necessary old image fix only
PasteUpMorph disableDeferredUpdates: true.

I think it might already be since the morphic canvas is set to nil when shutting down the image.

introduce a new flag bit in the image flags

Wouldn't this decrease compatibility of newer images with older VMs?

@marceltaeumel
Copy link
Contributor Author

Note that the very mechanism of "deferring display updates" and thus relying on a VM-side composition buffer could actually be a feature with a larger impact. However, I am not aware of a single project that relies on this other than Morphic window dragging. Many graphics-related Smalltalk projects are rather fiddling around with hardware acceleration via FFI or custom VM plugins. That is, the primitives 126, 127, and 231 are not that useful outside Morphic and MVC. And for those projects, BitBLT (i.e., #copyBits onto Form) might only be a fail-safe if anything.

Looking backwards at older images, macOS users can still (a) enable fast/ST80 window dragging or (b) manually enable the image-side composition buffer as described above. That is, if the users are even able to open their older at all, which is tricky for 32-bit images on a modern macOS version.

@OpenSmalltalk-Bot
Copy link

OpenSmalltalk-Bot commented May 5, 2022 via email

@marceltaeumel
Copy link
Contributor Author

marceltaeumel commented May 6, 2022

If the VM is hardware, then Squeak is not an application but an operating system. And not all operating systems run on new hardware. Or do they? They might need patches. And that's okay. They need patches to make the actual applications in them work.

I think that your current perspective on compatibility between VM and Image is unnecessarily restrictive. The image is not an application but more like an operating system.

@marceltaeumel
Copy link
Contributor Author

The issue is to not break older images.

We do not do that. They just open fine. They run just fine. You can do 99.9999% of what you could do before. Please argue at the level of Morphic window dragging. Otherwise we cannot make any progress on this matter. You are way too generic for this matter here.


On a different matter, the way somebody introduced OS event pumping during regular method invocation is a much more serious deal breaker. (I think that only the image should do that.) It was pure luck that that has worked until recently. Just take a look at the fix in DisplayScreen >> #restore and then tell me again that we have to go back to the seriously slow --metal backend from before just to make the calls to ioProcessEvents in checkForEventsMayContextSwitch work.


You should but you cannot always change the VM in isolation. It will work 99.999% of the time. But not always.

@marceltaeumel
Copy link
Contributor Author

Well, this would be trivial to make backwards compatible were the necessary old image fix only
PasteUpMorph disableDeferredUpdates: true.

I have no idea how you mean by that. Are you okay with running some code in an image to make it compatible or are you not okay with that?

@marceltaeumel
Copy link
Contributor Author

For the sake of piece, I will invest some more time and look into how difficult it would be to let primitive 126 fail for platform-specific graphics backends.

@eliotmiranda
Copy link
Contributor

eliotmiranda commented May 6, 2022 via email

@edoneel
Copy link
Collaborator

edoneel commented May 7, 2022 via email

@marceltaeumel
Copy link
Contributor Author

Done. See PR #631. If there are no objections, I will merge it and finish the OSVM release.

@dtlewis290
Copy link
Contributor

This along with VMMaker.oscog-mt.3184 looks like a straighforward solution to the problem.

@eliotmiranda
Copy link
Contributor

eliotmiranda commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants