-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
libobs: Add Metal renderer for Apple Silicon Macs #12306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a5bc8a
CI: Update swift-format configuration with more explicit rules
PatTheMav 5660e54
cmake: Enable DEBUG flag for Swift
PatTheMav 64fb95e
libobs: Add prerequisites for Metal and Swift support
PatTheMav ba8bfbc
CI: Update macOS runner for building to use Xcode 16.4
PatTheMav fc9e079
libobs-metal: Add Metal renderer
PatTheMav a3bdae7
frontend: Add Metal to available list of renderers in basic settings
PatTheMav 9f1841e
libobs: Update default draw effect to also provide D65P3 conversion
PatTheMav cd480f5
libobs-metal: Added README file for current state of implementation
PatTheMav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| cmake_minimum_required(VERSION 3.28...3.30) | ||
|
|
||
| add_library(libobs-metal SHARED) | ||
| add_library(OBS::libobs-metal ALIAS libobs-metal) | ||
|
|
||
| target_sources( | ||
| libobs-metal | ||
| PRIVATE | ||
| CVPixelFormat+Extensions.swift | ||
| MTLCullMode+Extensions.swift | ||
| MTLOrigin+Extensions.swift | ||
| MTLPixelFormat+Extensions.swift | ||
| MTLRegion+Extensions.swift | ||
| MTLSize+Extensions.swift | ||
| MTLTexture+Extensions.swift | ||
| MTLTextureDescriptor+Extensions.swift | ||
| MTLTextureType+Extensions.swift | ||
| MTLViewport+Extensions.swift | ||
| MetalBuffer.swift | ||
| MetalDevice.swift | ||
| MetalError.swift | ||
| MetalRenderState.swift | ||
| MetalShader+Extensions.swift | ||
| MetalShader.swift | ||
| MetalStageBuffer.swift | ||
| MetalTexture.swift | ||
| OBSShader.swift | ||
| OBSSwapChain.swift | ||
| Sequence+Hashable.swift | ||
| libobs+Extensions.swift | ||
| libobs+SignalHandlers.swift | ||
| libobs-metal-Bridging-Header.h | ||
| metal-indexbuffer.swift | ||
| metal-samplerstate.swift | ||
| metal-shader.swift | ||
| metal-stagesurf.swift | ||
| metal-subsystem.swift | ||
| metal-swapchain.swift | ||
| metal-texture2d.swift | ||
| metal-texture3d.swift | ||
| metal-unimplemented.swift | ||
| metal-vertexbuffer.swift | ||
| metal-zstencilbuffer.swift | ||
| ) | ||
|
|
||
| target_link_libraries(libobs-metal PRIVATE OBS::libobs) | ||
|
|
||
| target_enable_feature(libobs "Metal renderer") | ||
|
|
||
| set_property(SOURCE OBSMetalRenderer.swift APPEND PROPERTY COMPILE_FLAGS -emit-objc-header) | ||
|
|
||
| set_target_properties_obs( | ||
| libobs-metal | ||
| PROPERTIES FOLDER core | ||
| VERSION 0 | ||
| PREFIX "" | ||
| ) | ||
|
|
||
| set_target_xcode_properties( | ||
| libobs-metal | ||
| PROPERTIES SWIFT_VERSION 6.0 | ||
| CLANG_ENABLE_OBJC_ARC YES | ||
| CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION YES | ||
| GCC_WARN_SHADOW YES | ||
| CLANG_ENABLE_MODULES YES | ||
| CLANG_MODULES_AUTOLINK YES | ||
| GCC_STRICT_ALIASING YES | ||
| DEFINES_MODULE YES | ||
| SWIFT_OBJC_BRIDGING_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libobs-metal-Bridging-Header.h" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /****************************************************************************** | ||
| Copyright (C) 2024 by Patrick Heyer <PatTheMav@users.noreply.github.com> | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| ******************************************************************************/ | ||
|
|
||
| import CoreVideo | ||
| import Metal | ||
|
|
||
| extension OSType { | ||
| /// Conversion of CoreVideo pixel formats into corresponding Metal pixel formats | ||
| var mtlFormat: MTLPixelFormat? { | ||
| switch self { | ||
| case kCVPixelFormatType_OneComponent8: | ||
| return .r8Unorm | ||
| case kCVPixelFormatType_OneComponent16Half: | ||
| return .r16Float | ||
| case kCVPixelFormatType_OneComponent32Float: | ||
| return .r32Float | ||
| case kCVPixelFormatType_TwoComponent8: | ||
| return .rg8Unorm | ||
| case kCVPixelFormatType_TwoComponent16Half: | ||
| return .rg16Float | ||
| case kCVPixelFormatType_TwoComponent32Float: | ||
| return .rg32Float | ||
| case kCVPixelFormatType_32BGRA: | ||
| return .bgra8Unorm | ||
| case kCVPixelFormatType_32RGBA: | ||
| return .rgba8Unorm | ||
| case kCVPixelFormatType_64RGBAHalf: | ||
| return .rgba16Float | ||
| case kCVPixelFormatType_128RGBAFloat: | ||
| return .rgba32Float | ||
| case kCVPixelFormatType_ARGB2101010LEPacked: | ||
| return .bgr10a2Unorm | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /****************************************************************************** | ||
| Copyright (C) 2024 by Patrick Heyer <PatTheMav@users.noreply.github.com> | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| ******************************************************************************/ | ||
|
|
||
| import Foundation | ||
| import Metal | ||
|
|
||
| extension MTLCullMode { | ||
| /// Conversion of the cull mode into its corresponding `libobs` type | ||
| var obsMode: gs_cull_mode { | ||
| switch self { | ||
| case .back: | ||
| return GS_BACK | ||
| case .front: | ||
| return GS_FRONT | ||
| default: | ||
| return GS_NEITHER | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /****************************************************************************** | ||
| Copyright (C) 2024 by Patrick Heyer <PatTheMav@users.noreply.github.com> | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| ******************************************************************************/ | ||
|
|
||
| import Foundation | ||
| import Metal | ||
|
|
||
| extension MTLOrigin: @retroactive Equatable { | ||
| public static func == (lhs: MTLOrigin, rhs: MTLOrigin) -> Bool { | ||
| lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.