Skip to content

Commit 3090037

Browse files
committed
Fix firefox memory issue
Synchronize geckoGeneration flags in VRShMem to avoid a bug that locks up render thread. geckoGeneration flags are probably not even needed after this but I'll leave them in just to be on the safe side. Rest of the diffs are just changes made to mozilla central branch over the years.
1 parent aa41e9f commit 3090037

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

gecko/webxr-linux-dmabuf.patch

+54-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp
2020
MOZ_ASSERT(mBrowserState.layerState[0].type ==
2121
VRLayerType::LayerType_Stereo_Immersive);
2222
VRLayer_Stereo_Immersive& layer =
23-
@@ -1426,6 +1429,16 @@ bool VRManager::SubmitFrame(const layers
23+
@@ -1427,6 +1430,16 @@ bool VRManager::SubmitFrame(const layers
2424
layer.textureSize.width = desc.size().width;
2525
layer.textureSize.height = desc.size().height;
2626
} break;
@@ -37,7 +37,7 @@ diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp
3737
# endif
3838
default: {
3939
MOZ_ASSERT(false);
40-
@@ -1488,7 +1501,7 @@ void VRManager::SubmitFrameInternal(cons
40+
@@ -1489,7 +1502,7 @@ void VRManager::SubmitFrameInternal(cons
4141
mCurrentSubmitTask = nullptr;
4242
}
4343

@@ -70,10 +70,46 @@ diff --git a/gfx/vr/VRShMem.cpp b/gfx/vr/VRShMem.cpp
7070
}
7171
}
7272

73+
@@ -418,11 +426,12 @@ void VRShMem::PushBrowserState(VRBrowser
74+
status = lock.GetStatus();
75+
# endif // defined(XP_WIN)
76+
77+
- if (status) {
78+
+ if (status && pthread_mutex_lock((pthread_mutex_t*)&(mExternalShmem->geckoMutex)) == 0) {
79+
mExternalShmem->geckoGenerationA = mExternalShmem->geckoGenerationA + 1;
80+
memcpy((void*)&(mExternalShmem->geckoState), (void*)&aBrowserState,
81+
sizeof(VRBrowserState));
82+
mExternalShmem->geckoGenerationB = mExternalShmem->geckoGenerationB + 1;
83+
+ pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->geckoMutex));
84+
}
85+
#endif // defined(MOZ_WIDGET_ANDROID)
86+
}
87+
@@ -462,17 +471,15 @@ void VRShMem::PullBrowserState(mozilla::
88+
}
89+
# endif // defined(XP_WIN)
90+
if (status) {
91+
- VRExternalShmem tmp;
92+
if (mExternalShmem->geckoGenerationA != mBrowserGeneration) {
93+
// TODO - (void *) cast removes volatile semantics.
94+
// The memcpy is not likely to be optimized out, but is theoretically
95+
// possible. Suggest refactoring to either explicitly enforce memory
96+
// order or to use locks.
97+
- memcpy(&tmp, (void*)mExternalShmem, sizeof(VRExternalShmem));
98+
- if (tmp.geckoGenerationA == tmp.geckoGenerationB &&
99+
- tmp.geckoGenerationA != 0) {
100+
- memcpy(&aState, &tmp.geckoState, sizeof(VRBrowserState));
101+
- mBrowserGeneration = tmp.geckoGenerationA;
102+
+ if (pthread_mutex_lock((pthread_mutex_t*)&(mExternalShmem->geckoMutex)) == 0) {
103+
+ memcpy(&aState, (void*)&(mExternalShmem->geckoState), sizeof(VRBrowserState));
104+
+ mBrowserGeneration = mExternalShmem->geckoGenerationA;
105+
+ pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->geckoMutex));
106+
}
107+
}
108+
}
73109
diff --git a/gfx/vr/external_api/moz_external_vr.h b/gfx/vr/external_api/moz_external_vr.h
74110
--- a/gfx/vr/external_api/moz_external_vr.h
75111
+++ b/gfx/vr/external_api/moz_external_vr.h
76-
@@ -451,7 +451,8 @@ enum class VRLayerTextureType : uint16_t
112+
@@ -452,7 +452,8 @@ enum class VRLayerTextureType : uint16_t
77113
LayerTextureType_None = 0,
78114
LayerTextureType_D3D10SurfaceDescriptor = 1,
79115
LayerTextureType_MacIOSurface = 2,
@@ -83,6 +119,14 @@ diff --git a/gfx/vr/external_api/moz_external_vr.h b/gfx/vr/external_api/moz_ext
83119
};
84120

85121
struct VRLayer_2D_Content {
122+
@@ -619,6 +620,7 @@ struct VRExternalShmem {
123+
pthread_cond_t servoCond;
124+
#else
125+
int64_t generationA;
126+
+ pthread_mutex_t geckoMutex;
127+
#endif // defined(__ANDROID__)
128+
VRSystemState state;
129+
#if !defined(__ANDROID__)
86130
diff --git a/gfx/vr/ipc/VRLayerChild.cpp b/gfx/vr/ipc/VRLayerChild.cpp
87131
--- a/gfx/vr/ipc/VRLayerChild.cpp
88132
+++ b/gfx/vr/ipc/VRLayerChild.cpp
@@ -111,7 +155,7 @@ diff --git a/gfx/vr/moz.build b/gfx/vr/moz.build
111155
diff --git a/gfx/vr/service/OSVRSession.cpp b/gfx/vr/service/OSVRSession.cpp
112156
--- a/gfx/vr/service/OSVRSession.cpp
113157
+++ b/gfx/vr/service/OSVRSession.cpp
114-
@@ -497,7 +497,7 @@ bool OSVRSession::SubmitFrame(
158+
@@ -496,7 +496,7 @@ bool OSVRSession::SubmitFrame(
115159
return false;
116160
// TODO Implement
117161
}
@@ -135,7 +179,7 @@ diff --git a/gfx/vr/service/OSVRSession.h b/gfx/vr/service/OSVRSession.h
135179
diff --git a/gfx/vr/service/OpenVRSession.cpp b/gfx/vr/service/OpenVRSession.cpp
136180
--- a/gfx/vr/service/OpenVRSession.cpp
137181
+++ b/gfx/vr/service/OpenVRSession.cpp
138-
@@ -1284,6 +1284,13 @@ bool OpenVRSession::SubmitFrame(
182+
@@ -1273,6 +1273,13 @@ bool OpenVRSession::SubmitFrame(
139183
return SubmitFrame(aTexture, ::vr::ETextureType::TextureType_IOSurface,
140184
aLayer.leftEyeRect, aLayer.rightEyeRect);
141185
}
@@ -149,7 +193,7 @@ diff --git a/gfx/vr/service/OpenVRSession.cpp b/gfx/vr/service/OpenVRSession.cpp
149193
#endif
150194

151195
bool OpenVRSession::SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
152-
@@ -1303,32 +1310,32 @@ bool OpenVRSession::SubmitFrame(const VR
196+
@@ -1292,32 +1299,32 @@ bool OpenVRSession::SubmitFrame(const VR
153197

154198
CFTypeRefPtr<IOSurfaceRef> ioSurface = surf->GetIOSurfaceRef();
155199
tex.handle = (void*)ioSurface.get();
@@ -232,7 +276,7 @@ diff --git a/gfx/vr/service/PuppetSession.h b/gfx/vr/service/PuppetSession.h
232276
diff --git a/gfx/vr/service/VRSession.cpp b/gfx/vr/service/VRSession.cpp
233277
--- a/gfx/vr/service/VRSession.cpp
234278
+++ b/gfx/vr/service/VRSession.cpp
235-
@@ -12,6 +12,10 @@
279+
@@ -14,6 +14,10 @@
236280
# include <d3d11.h>
237281
#endif // defined(XP_WIN)
238282

@@ -243,7 +287,7 @@ diff --git a/gfx/vr/service/VRSession.cpp b/gfx/vr/service/VRSession.cpp
243287
#if defined(MOZILLA_INTERNAL_API)
244288
# if defined(XP_WIN)
245289
# include "mozilla/gfx/Logging.h"
246-
@@ -148,6 +152,30 @@ bool VRSession::SubmitFrame(
290+
@@ -152,6 +156,30 @@ bool VRSession::SubmitFrame(
247291
return SubmitFrame(aLayer, aLayer.textureHandle);
248292
}
249293

@@ -305,7 +349,7 @@ diff --git a/gfx/vr/service/VRSession.h b/gfx/vr/service/VRSession.h
305349
diff --git a/gfx/vr/service/moz.build b/gfx/vr/service/moz.build
306350
--- a/gfx/vr/service/moz.build
307351
+++ b/gfx/vr/service/moz.build
308-
@@ -32,6 +32,8 @@ if CONFIG["OS_TARGET"] in ("WINNT", "Lin
352+
@@ -35,6 +35,8 @@ if CONFIG["TARGET_OS"] in ("WINNT", "OSX
309353
"openvr",
310354
]
311355
LOCAL_INCLUDES += ["/dom/base", "/gfx/layers/d3d11"]
@@ -314,7 +358,7 @@ diff --git a/gfx/vr/service/moz.build b/gfx/vr/service/moz.build
314358

315359
# OpenVRSession includes MacIOSurface.h which includes Mac headers
316360
# which define Size and Points types in the root namespace that
317-
@@ -45,4 +47,8 @@ if CONFIG["OS_TARGET"] in ("WINNT", "Lin
361+
@@ -48,4 +50,8 @@ if CONFIG["TARGET_OS"] in ("WINNT", "OSX
318362
"OpenVRViveMapper.cpp",
319363
]
320364

0 commit comments

Comments
 (0)