Skip to content

Camera#1815

Draft
capitalistspz wants to merge 35 commits into
cemu-project:mainfrom
capitalistspz:camera2
Draft

Camera#1815
capitalistspz wants to merge 35 commits into
cemu-project:mainfrom
capitalistspz:camera2

Conversation

@capitalistspz

Copy link
Copy Markdown
Contributor

Couldn't merge properly, so here's a new branch.
Mostly the same as the other one.

@capitalistspz
capitalistspz marked this pull request as draft February 26, 2026 12:07
@capitalistspz
capitalistspz marked this pull request as ready for review February 28, 2026 14:01

@Exzap Exzap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std mutex will clash with Cafe OS primitives.
Any function that can block or resume a thread (OSJoinThread, OSSignalEvent, OSResumeThread, OSSleepTicks, OSLockMutex..) can yield the current fiber and start running other PPC threads.

Take this example:

// part of a HLE function
OSSleepTicks(ONE_SECOND);

Instead of blocking the host thread for one second, coreinit threading will instead suspend the host fiber (or ucontext in posix terms) assigned to the current PPC thread. Then the PPC scheduler picks the next PPC thread to run and continues doing work. Eventually after the sleep timeout occurs the scheduler will switch back and resume the fiber from within OSSleepTicks. From the code's perspective the 1 second delay happened, but the actual CPU emulation thread never actually slept. In multicore emulation it can even be a different host thread that returned from OSSleepTicks.

I hope this explanation makes sense. What currently happens is that you carry the std mutex into other PPC threads because you are calling OS functions which can context switch. It can easily lead to deadlocks or race conditions.

The solution is to use OSMutex over std::mutex in HLE code. OSMutex cannot be used outside of PPC contexts, so in that case you have to use std::mutex but need to make sure that you are not holding the lock while calling any OS* functions.

Comment thread src/camera/CameraManager.cpp Outdated
Comment thread src/camera/CMakeLists.txt Outdated
@capitalistspz
capitalistspz marked this pull request as draft April 15, 2026 01:22
@Exzap

Exzap commented Apr 15, 2026

Copy link
Copy Markdown
Member

Add:
cemu_use_precompiled_header(CemuCamera)
After add_library

Ah nvm you are behind too many commits for that. But this should work:
target_precompile_headers(CemuCamera PRIVATE precompiled.h)

@capitalistspz

Copy link
Copy Markdown
Contributor Author

Add: cemu_use_precompiled_header(CemuCamera) After add_library

Ah nvm you are behind too many commits for that. But this should work: target_precompile_headers(CemuCamera PRIVATE precompiled.h)

Maybe I should rebase then

I know it doesn't match the rest of the `CMakeLists`
I'm using it after all
Also ensures a lock is released
Unique IDs vary across restarts and re-plugs, which isn't really suitable for being saved to config
Compiling the precompiled headers for `CemuCamera` took longer than compiling `CemuCamera` itself, so it just ends up being noticeably faster to just add it to one of the existing sublibs. It probably wasn't a problem for MSVC because precompiled header reuse works there, but I'm not using MSVC
For some reason `wxChoice` on GTK frequently produces
```
*** BUG ***
In pixman_region32_init_rect: Invalid rectangle passed
Set a breakpoint on '_pixman_log_error' to debug
```
and displays incorrectly
- Call `CAMClose` instead of `CAMExit` on unload
- Add OSDriver registration
- Never join the worker thread.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants