-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
GBM/X11/Wayland: Implement asynchronous texture uploads #25139
Changes from all commits
162bf61
3bb94d0
b96997d
8722b68
1b4d3ce
b818c0a
84625af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,6 +428,12 @@ bool CEGLContextUtils::CreateContext(CEGLAttributesVec contextAttribs) | |
return false; | ||
} | ||
|
||
m_eglUploadContext = | ||
eglCreateContext(m_eglDisplay, m_eglConfig, m_eglContext, contextAttribs.Get()); | ||
|
||
if (m_eglUploadContext == EGL_NO_CONTEXT) | ||
CLog::Log(LOGWARNING, "Failed to create EGL upload context"); | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -565,6 +571,12 @@ void CEGLContextUtils::DestroyContext() | |
eglDestroyContext(m_eglDisplay, m_eglContext); | ||
m_eglContext = EGL_NO_CONTEXT; | ||
} | ||
|
||
if (m_eglUploadContext) | ||
{ | ||
eglDestroyContext(m_eglDisplay, m_eglUploadContext); | ||
m_eglUploadContext = EGL_NO_CONTEXT; | ||
} | ||
} | ||
|
||
void CEGLContextUtils::DestroySurface() | ||
|
@@ -597,3 +609,49 @@ bool CEGLContextUtils::TrySwapBuffers() | |
|
||
return (eglSwapBuffers(m_eglDisplay, m_eglSurface) == EGL_TRUE); | ||
} | ||
|
||
bool CEGLContextUtils::BindTextureUploadContext() | ||
{ | ||
if (m_eglDisplay == EGL_NO_DISPLAY || m_eglUploadContext == EGL_NO_CONTEXT) | ||
{ | ||
CLog::LogF(LOGERROR, "No texture upload context found."); | ||
return false; | ||
} | ||
|
||
m_textureUploadLock.lock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love the fact of locking in the middle of these functions. I assume because the texture uploads may happen from other threads? It would be nice if there was the ability to add texture uploads to a queue to avoid needing the lock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there can be multiple jobs in parallel. Only one can have the upload context. |
||
|
||
if (!eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, m_eglUploadContext)) | ||
{ | ||
m_textureUploadLock.unlock(); | ||
CLog::LogF(LOGERROR, "Couldn't bind texture upload context."); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool CEGLContextUtils::UnbindTextureUploadContext() | ||
{ | ||
if (m_eglDisplay == EGL_NO_DISPLAY || m_eglUploadContext == EGL_NO_CONTEXT) | ||
{ | ||
CLog::LogF(LOGERROR, "No texture upload context found."); | ||
m_textureUploadLock.unlock(); | ||
return false; | ||
} | ||
|
||
if (!eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) | ||
{ | ||
CLog::LogF(LOGERROR, "Couldn't release texture upload context"); | ||
m_textureUploadLock.unlock(); | ||
return false; | ||
} | ||
|
||
m_textureUploadLock.unlock(); | ||
|
||
return true; | ||
} | ||
|
||
bool CEGLContextUtils::HasContext() | ||
{ | ||
return eglGetCurrentContext() != EGL_NO_CONTEXT; | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -260,6 +260,24 @@ class CWinSystemBase | |||
*/ | ||||
std::pair<bool, int> GetDitherSettings(); | ||||
|
||||
/*! | ||||
* \brief Binds a shared context to the current thread, in order to upload textures asynchronously. | ||||
* \return Return true if a texture upload context exists and the binding succeeds. | ||||
*/ | ||||
virtual bool BindTextureUploadContext() { return false; } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to avoid polluting CWinSystemBase with more stuff. Can this be moved somewhere else? Possibly the caller can cast the window system to the EGL intermediate class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've experimented with that, but I couldn't come up with an universal solution which does not look hacky. If you could give me some pointers, I'd appreciate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here:
The problem is that x11 uses a different EGL context class so that might be annoying. It was always the intention to get x11 to use the same EGL class that wayland and gbm are using, it just hasn't happened yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's why I shelved the branch for a long time. I'm still running X11. I'll see what I can do. On the flip side, I believe that GLX and DX11 can have a very similar implementations. It is not EGL specific, if that's your concern. |
||||
|
||||
/*! | ||||
* \brief Unbinds the shared context. | ||||
* \return Return true if the texture upload context has been unbound. | ||||
*/ | ||||
virtual bool UnbindTextureUploadContext() { return false; } | ||||
|
||||
/*! | ||||
* \brief Checks if a graphics context is already bound to the current thread. | ||||
* \return Return true if so. | ||||
*/ | ||||
virtual bool HasContext() { return false; } | ||||
|
||||
protected: | ||||
void UpdateDesktopResolution(RESOLUTION_INFO& newRes, const std::string &output, int width, int height, float refreshRate, uint32_t dwFlags); | ||||
void UpdateDesktopResolution(RESOLUTION_INFO& newRes, | ||||
|
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.
This effectively blocks no?
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.
Yes, that's desired. It blocks the upload thread, and waits until the texture is visible for the GPU.