Revert "CameraView: sync pbo with glFence instead of calling glFinish (#23293)"

This reverts commit 7fcde6809582c5b8ddfe5a60723d70f9eae1d5de.

old-commit-hash: 25f51470fc
commatwo_master
Adeeb Shihadeh 3 years ago
parent 7c960e6a94
commit 097110ba41
  1. 35
      selfdrive/ui/qt/widgets/cameraview.cc
  2. 12
      selfdrive/ui/qt/widgets/cameraview.h

@ -202,15 +202,9 @@ void CameraViewWidget::paintGL() {
glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF()); glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
std::lock_guard lk(lock);
if (latest_texture_id == -1) return; if (latest_texture_id == -1) return;
glViewport(0, 0, width(), height()); glViewport(0, 0, width(), height());
// sync with the PBO
if (wait_fence) {
wait_fence->wait();
}
glBindVertexArray(frame_vao); glBindVertexArray(frame_vao);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@ -295,23 +289,20 @@ void CameraViewWidget::vipcThread() {
} }
if (VisionBuf *buf = vipc_client->recv(nullptr, 1000)) { if (VisionBuf *buf = vipc_client->recv(nullptr, 1000)) {
{ if (!Hardware::EON()) {
std::lock_guard lk(lock); void *texture_buffer = gl_buffer->map(QOpenGLBuffer::WriteOnly);
if (!Hardware::EON()) { memcpy(texture_buffer, buf->addr, buf->len);
void *texture_buffer = gl_buffer->map(QOpenGLBuffer::WriteOnly); gl_buffer->unmap();
memcpy(texture_buffer, buf->addr, buf->len);
gl_buffer->unmap(); // copy pixels from PBO to texture object
glBindTexture(GL_TEXTURE_2D, texture[buf->idx]->frame_tex);
// copy pixels from PBO to texture object glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, buf->width, buf->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, texture[buf->idx]->frame_tex); glBindTexture(GL_TEXTURE_2D, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, buf->width, buf->height, GL_RGB, GL_UNSIGNED_BYTE, 0); assert(glGetError() == GL_NO_ERROR);
glBindTexture(GL_TEXTURE_2D, 0); // use glFinish to ensure that the texture has been uploaded.
assert(glGetError() == GL_NO_ERROR); glFinish();
wait_fence.reset(new WaitFence());
}
latest_texture_id = buf->idx;
} }
latest_texture_id = buf->idx;
// Schedule update. update() will be invoked on the gui thread. // Schedule update. update() will be invoked on the gui thread.
QMetaObject::invokeMethod(this, "update"); QMetaObject::invokeMethod(this, "update");

@ -36,20 +36,11 @@ protected:
virtual void updateFrameMat(int w, int h); virtual void updateFrameMat(int w, int h);
void vipcThread(); void vipcThread();
struct WaitFence {
WaitFence() { sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); }
~WaitFence() { glDeleteSync(sync); }
void wait() { glWaitSync(sync, 0, GL_TIMEOUT_IGNORED); }
GLsync sync = 0;
};
bool zoomed_view; bool zoomed_view;
std::mutex lock; std::atomic<int> latest_texture_id = -1;
int latest_texture_id = -1;
GLuint frame_vao, frame_vbo, frame_ibo; GLuint frame_vao, frame_vbo, frame_ibo;
mat4 frame_mat; mat4 frame_mat;
std::unique_ptr<EGLImageTexture> texture[UI_BUF_COUNT]; std::unique_ptr<EGLImageTexture> texture[UI_BUF_COUNT];
std::unique_ptr<WaitFence> wait_fence;
std::unique_ptr<QOpenGLShaderProgram> program; std::unique_ptr<QOpenGLShaderProgram> program;
QColor bg = QColor("#000000"); QColor bg = QColor("#000000");
@ -59,6 +50,7 @@ protected:
std::atomic<VisionStreamType> stream_type; std::atomic<VisionStreamType> stream_type;
QThread *vipc_thread = nullptr; QThread *vipc_thread = nullptr;
protected slots: protected slots:
void vipcConnected(VisionIpcClient *vipc_client); void vipcConnected(VisionIpcClient *vipc_client);
}; };

Loading…
Cancel
Save