From 3b65dd847f521774904736eda32910a4872f3522 Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Thu, 25 Apr 2024 10:19:51 +0300 Subject: [PATCH] Fix mac --- .github/workflows/build.yml | 4 ++-- pkg/worker/caged/libretro/nanoarch/nanoarch.go | 3 +++ pkg/worker/thread/mainthread_darwin.go | 11 +++++++++++ pkg/worker/thread/thread.go | 5 +++-- pkg/worker/thread/thread_darwin.go | 2 ++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89e423e86..3ea02f4cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: build: strategy: matrix: - os: [ ubuntu-latest, macos-13, windows-latest ] + os: [ ubuntu-latest, macos-12, windows-latest ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -42,7 +42,7 @@ jobs: xvfb-run --auto-servernum make test verify-cores - name: macOS - if: matrix.os == 'macos-13' + if: matrix.os == 'macos-12' run: | brew install pkg-config libvpx x264 opus sdl2 jpeg-turbo make build test verify-cores diff --git a/pkg/worker/caged/libretro/nanoarch/nanoarch.go b/pkg/worker/caged/libretro/nanoarch/nanoarch.go index 2e0570dc8..44669cfdb 100644 --- a/pkg/worker/caged/libretro/nanoarch/nanoarch.go +++ b/pkg/worker/caged/libretro/nanoarch/nanoarch.go @@ -166,6 +166,8 @@ func (n *Nanoarch) CoreLoad(meta Metadata) { n.Video.gl.autoCtx = meta.AutoGlContext n.Video.gl.enabled = meta.IsGlAllowed + thread.SwitchGraphics(n.Video.gl.enabled) + // hacks Nan0.hackSkipHwContextDestroy = meta.HasHack("skip_hw_context_destroy") @@ -934,6 +936,7 @@ func deinitVideo() { Nan0.Video.gl.enabled = false Nan0.Video.gl.autoCtx = false Nan0.hackSkipHwContextDestroy = false + thread.SwitchGraphics(false) } type limit struct { diff --git a/pkg/worker/thread/mainthread_darwin.go b/pkg/worker/thread/mainthread_darwin.go index 730a3f272..53ac75858 100644 --- a/pkg/worker/thread/mainthread_darwin.go +++ b/pkg/worker/thread/mainthread_darwin.go @@ -13,6 +13,8 @@ type fun struct { var dPool = sync.Pool{New: func() any { return make(chan struct{}) }} var fq = make(chan fun, runtime.GOMAXPROCS(0)) +var isGraphics = false + func init() { runtime.LockOSThread() } @@ -38,8 +40,17 @@ func Run(run func()) { // Call queues function f on the main thread and blocks until the function f finishes. func Call(f func()) { + if !isGraphics { + f() + return + } + done := dPool.Get().(chan struct{}) defer dPool.Put(done) fq <- fun{fn: f, done: done} <-done } + +func Switch(s bool) { + isGraphics = s +} diff --git a/pkg/worker/thread/thread.go b/pkg/worker/thread/thread.go index 20582a85a..3cd824ab3 100644 --- a/pkg/worker/thread/thread.go +++ b/pkg/worker/thread/thread.go @@ -2,5 +2,6 @@ package thread -func Wrap(f func()) { f() } -func Main(f func()) { f() } +func Wrap(f func()) { f() } +func Main(f func()) { f() } +func SwitchGraphics(s bool) {} diff --git a/pkg/worker/thread/thread_darwin.go b/pkg/worker/thread/thread_darwin.go index bee4f73e9..120c7af16 100644 --- a/pkg/worker/thread/thread_darwin.go +++ b/pkg/worker/thread/thread_darwin.go @@ -8,3 +8,5 @@ func Wrap(f func()) { Run(f) } // Main calls a function on the main thread. func Main(f func()) { Call(f) } + +func SwitchGraphics(s bool) { Switch(s) }