Open Bug 902169 Opened 13 years ago Updated 4 years ago

Add proper locking for MemoryImage/Shmem

Categories

(Core :: Graphics: Layers, defect)

x86
macOS
defect

Tracking

()

People

(Reporter: mattwoodrow, Unassigned)

Details

Attachments

(2 files)

Attached patch locking — — Splinter Review
If we support real locking, then we can avoid uploading during a transaction, or requiring immutable textures. The main problem is the change to CanvasClient. We don't have any obvious way to check if the texture will support locking, so we're just using knowledge that not-cross-process textures will support locking. Ideas? This improves our fps on FishIE (with 10 fish) from 57 -> 60.
Attachment #786499 - Flags: review?(nical.bugzilla)
Comment on attachment 786499 [details] [diff] [review] locking Review of attachment 786499 [details] [diff] [review]: ----------------------------------------------------------------- ::: gfx/layers/client/TextureClient.h @@ +290,3 @@ > protected: > uint8_t* mBuffer; > + mozilla::Mutex* mMutex; mMutex should be in the base class (TextureClient/TextureHost) because it is independent of the memory type. ::: gfx/layers/ipc/LayersSurfaces.ipdlh @@ +122,5 @@ > * Used for "raw memory"-backed YCbCr and (flavors of) RGBA textures > */ > struct SurfaceDescriptorMemory { > uintptr_t data; > + uintptr_t mutex; I would much prefer to put the mutex in OpAddTexture because locking is not specific to the memory type. Also, wrapping the mutex into a enum MaybeMutex { uintptr_t mutex; null_t none; }; would make it easier to understand and also easier for us to replace this by a proper cross-process mutexes which is not going to be represented as a pointer (so the logic of testing whether we do have a mutex would be clearer and not dependent on the mutex being a pointer or a FD or whatnot).
This is what I have in my patch queue, and then I found out CrossProcessMutex was windows only so I didn't submit it. I don't mean to replace your patch by this (especially since it is not very useful working only on windows), but it is more what I had in mind in term of at which level of abstraction sits the locking feature.
(In reply to Nicolas Silva [:nical] from comment #1) > Comment on attachment 786499 [details] [diff] [review] > locking > > Review of attachment 786499 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: gfx/layers/client/TextureClient.h > @@ +290,3 @@ > > protected: > > uint8_t* mBuffer; > > + mozilla::Mutex* mMutex; > > mMutex should be in the base class (TextureClient/TextureHost) because it is > independent of the memory type. I don't really agree. mozilla::Mutex only works cross-thread, so I think it's only useful for MemoryImage. Shmem needs a cross-process mutex, gralloc has this built in etc. What other texture types would want to use this mutex?
SharedTextureClientOGL? To me using a non-cross-process mutex is just a temporary solution, because we want the infrastructure that this patch adds to work with B2G too (as soon as we have a b2g-friendly mutex), so even if in the short term we'd use it only with MemoryImage, I would like to not have to move everything when we get a mutex that works for B2G.
I don't think we'd want the extra overhead of cross-process mutexes (assuming that there is one) for cross-thread.
Agreed, when building the TextureClient you chosse which locking strategy is best: CROSS_PROCESS_LOCK, CROSS_THREAD_LOCK or NO_LOCK. Sometimes we don't need to lock at all because we'd use exclusively immutable textures (like for video). we just need an interface for mutexes that can be either cross-process or cross-thread, let the base class do the locking logic, and decide which mutex to use when building the TextureClient. TextureClientShmem can definitely assert that its mutex is not cross-thread to ensure we are not making something dangerous. Otherwise I fear we'll end up reimplementing the same stuff into several texture client, even though the semantic is the same for all of them. It opena the door for bugs caused by two TextureClient having slightly different behaviours, which is already tempting because some TextureClients are used specifically with some layer types.
Attachment #786499 - Flags: review?(nical.bugzilla)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: