Skip to content

Commit 8966232

Browse files
committed
GPU Wayland Display: fix should not attach wayland SHM buffer to the swapchain of Vulkan (thx to claude)
1 parent 7bf2651 commit 8966232

2 files changed

Lines changed: 8 additions & 56 deletions

File tree

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.cxx‎

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,6 @@ int32_t GPUDisplayFrontendWayland::GetKey(uint32_t key, uint32_t state)
143143
return retVal;
144144
}
145145

146-
void GPUDisplayFrontendWayland::createBuffer(uint32_t width, uint32_t height)
147-
{
148-
const uint32_t stride = width * 4;
149-
const uint32_t size = stride * height;
150-
if (ftruncate(mFd, size) < 0) {
151-
throw std::runtime_error("Error setting waysland shm file size");
152-
}
153-
void* shm_data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, mFd, 0);
154-
if (shm_data == MAP_FAILED) {
155-
throw std::runtime_error("wayland mmap failed");
156-
}
157-
memset(shm_data, 0, size);
158-
munmap(shm_data, size);
159-
160-
mPool = wl_shm_create_pool(mShm, mFd, size);
161-
mBuffer = wl_shm_pool_create_buffer(mPool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888);
162-
mDisplayWidth = width;
163-
mDisplayHeight = height;
164-
wl_surface_attach(mSurface, mBuffer, 0, 0);
165-
wl_surface_commit(mSurface);
166-
}
167-
168-
void GPUDisplayFrontendWayland::recreateBuffer(uint32_t width, uint32_t height)
169-
{
170-
wl_surface_attach(mSurface, nullptr, 0, 0);
171-
wl_surface_commit(mSurface);
172-
wl_buffer_destroy(mBuffer);
173-
wl_shm_pool_destroy(mPool);
174-
createBuffer(width, height);
175-
}
176-
177146
int32_t GPUDisplayFrontendWayland::FrontendMain()
178147
{
179148
if (backend()->backendType() != GPUDisplayBackend::TYPE_VULKAN) {
@@ -195,11 +164,6 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
195164
throw std::runtime_error("Could not create wayland registry");
196165
}
197166

198-
mFd = memfd_create("/tmp/ca-gpu-display-wayland-memfile", 0);
199-
if (mFd < 0) {
200-
throw std::runtime_error("Error creating wayland shm segment file descriptor");
201-
}
202-
203167
auto pointer_enter = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
204168
};
205169
auto pointer_leave = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* wl_surface) {
@@ -309,8 +273,6 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
309273
// wl_output_add_listener(mOutput, &output_listener, this);
310274
} else if (strcmp(interface, wl_compositor_interface.name) == 0) {
311275
mCompositor = (wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 1);
312-
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
313-
mShm = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, 1);
314276
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
315277
mXdgBase = (xdg_wm_base*)wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
316278
xdg_wm_base_add_listener(mXdgBase, &xdg_wm_base_listener, this);
@@ -329,7 +291,7 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
329291
wl_registry_add_listener(mRegistry, &registry_listener, &registry_global_c);
330292
wl_display_roundtrip(mWayland);
331293

332-
if (mCompositor == nullptr || mShm == nullptr || mXdgBase == nullptr || mSeat == nullptr || mOutput == nullptr) {
294+
if (mCompositor == nullptr || mXdgBase == nullptr || mSeat == nullptr || mOutput == nullptr) {
333295
throw std::runtime_error("Error getting wayland objects");
334296
}
335297

@@ -356,10 +318,12 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
356318
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
357319
xdg_surface_ack_configure(me->mXdgSurface, serial);
358320
if (me->mWidthRequested && me->mHeightRequested && (me->mWidthRequested != me->mDisplayWidth || me->mHeightRequested != me->mDisplayHeight)) {
359-
me->recreateBuffer(me->mWidthRequested, me->mHeightRequested);
360-
me->ResizeScene(me->mDisplayWidth, me->mDisplayHeight);
361-
} else {
362-
wl_surface_commit(((GPUDisplayFrontendWayland*)data)->mSurface);
321+
if (me->mDisplayRunning) {
322+
me->ResizeScene(me->mWidthRequested, me->mHeightRequested); // Swapchain is recreated by the backend, Vulkan WSI commits the new buffer
323+
} else {
324+
me->mDisplayWidth = me->mWidthRequested; // Initial size, used by InitDisplay via getSize()
325+
me->mDisplayHeight = me->mHeightRequested;
326+
}
363327
}
364328
me->mWidthRequested = me->mHeightRequested = 0;
365329
};
@@ -389,11 +353,9 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
389353
printf("Enabling decoration\n");
390354
}
391355

392-
wl_surface_commit(mSurface);
356+
wl_surface_commit(mSurface); // Initial commit without buffer, the compositor answers with the first configure
393357
wl_display_roundtrip(mWayland);
394358

395-
createBuffer(INIT_WIDTH, INIT_HEIGHT);
396-
397359
if (InitDisplay()) {
398360
return (1);
399361
}
@@ -421,7 +383,6 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
421383
HandleSendKeys();
422384
DrawGLScene();
423385
waitForFPSLimit();
424-
wl_surface_damage(mSurface, 0, 0, mDisplayWidth, mDisplayHeight);
425386
}
426387

427388
ExitDisplay();
@@ -448,11 +409,8 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
448409
xdg_toplevel_destroy(mXdgToplevel);
449410
xdg_surface_destroy(mXdgSurface);
450411
wl_surface_destroy(mSurface);
451-
wl_buffer_destroy(mBuffer);
452-
wl_shm_pool_destroy(mPool);
453412
wl_registry_destroy(mRegistry);
454413
wl_display_disconnect(mWayland);
455-
close(mFd);
456414

457415
return (0);
458416
}

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class GPUDisplayFrontendWayland : public GPUDisplayFrontend
4848
private:
4949
int32_t FrontendMain() override;
5050
int32_t GetKey(uint32_t key, uint32_t state);
51-
void createBuffer(uint32_t width, uint32_t height);
52-
void recreateBuffer(uint32_t width, uint32_t height);
5351

5452
pthread_mutex_t mSemLockExit = PTHREAD_MUTEX_INITIALIZER;
5553

@@ -61,17 +59,13 @@ class GPUDisplayFrontendWayland : public GPUDisplayFrontend
6159
wl_pointer* mPointer = nullptr;
6260
wl_keyboard* mKeyboard = nullptr;
6361
xdg_wm_base* mXdgBase = nullptr;
64-
wl_shm* mShm = nullptr;
6562

6663
wl_surface* mSurface = nullptr;
6764
xdg_surface* mXdgSurface = nullptr;
6865
xdg_toplevel* mXdgToplevel = nullptr;
6966

7067
wl_output* mOutput = nullptr;
7168

72-
int32_t mFd = 0;
73-
wl_shm_pool* mPool;
74-
wl_buffer* mBuffer;
7569

7670
xkb_context* mXKBcontext = nullptr;
7771
xkb_keymap* mXKBkeymap = nullptr;

0 commit comments

Comments
 (0)