Skip to content

Commit 002ebb7

Browse files
committed
win64 gpu support
1 parent 70ca00a commit 002ebb7

File tree

5 files changed

+278
-56
lines changed

5 files changed

+278
-56
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
cmake_minimum_required(VERSION 3.10)
22

3+
include(external/MunkeiVersionFromGit.cmake)
4+
version_from_git()
5+
36
# Change obs-plugintemplate to your plugin's name in a machine-readable format
47
# (e.g.: obs-myawesomeplugin) and set
5-
project(obs-backgroundremoval VERSION 1.0.0)
8+
project(obs-backgroundremoval VERSION ${VERSION})
69

710
# Replace `Your Name Here` with the name (yours or your organization's) you want
811
# to see as the author of the plugin (in the plugin's metadata itself and in the installers)

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,20 @@ $ .\bootstrap-vcpkg.bat
104104
$ .\vcpkg.exe install opencv[core]:x64-windows-static
105105
```
106106

107-
Unzip an ONNX runtime release: https://github.com/microsoft/onnxruntime/releases to e.g. Downloads.
108-
You should have a directory like `<Downloads>\Microsoft.AI.MachineLearning.1.7.2\`.
107+
Install Onnxruntime with NuGet:
108+
```
109+
$ cd build
110+
$ mkdir nuget
111+
$ Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -UseBasicParsing -OutFile nuget.exe
112+
$ nuget.exe install Microsoft.ML.OnnxRuntime.DirectML
113+
```
109114

110115
Clone the OBS repo, `Downloads\ $ git clone --single-branch -b 26.1.2 [email protected]:obsproject/obs-studio.git`, to e.g. Downloads.
111116

112-
Build the plugin:
117+
Build and install the plugin:
113118
```
114-
$ cmake .. -DobsPath="<Downloads>\obs-studio\" -DOnnxruntime_INCLUDE_HINT=<Downloads>\Microsoft.AI.MachineLearning.1.7.2\build\native\include -DOnnxruntime_DIR=<Downloads>\Microsoft.AI.MachineLearning.1.7.2\runtimes\win-x64\_native\static
119+
$ cmake .. -DobsPath="$HOME\Downloads\obs-studio\"
115120
$ cmake --build . --config Release
121+
$ cpack
122+
$ Expand-Archive .\obs-backgroundremoval-win64.zip -DestinationPath 'C:\Program Files\obs-studio\' -Force
116123
```
117-
(replace `<downloads>` with the actuals downloads directory path)

external/FindOnnxruntime.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ else()
1616
onnxruntime
1717
PATHS
1818
${Onnxruntime_DIR}
19+
${CMAKE_BINARY_DIR}/nuget/Microsoft.ML.OnnxRuntime.DirectML.1.7.0/runtimes/win-x64/native
1920
DOC "Onnxruntime library")
2021

2122
find_path(Onnxruntime_INCLUDE_DIR
@@ -24,6 +25,7 @@ else()
2425
"onnxruntime/core/session/onnxruntime_cxx_api.h"
2526
PATHS
2627
${Onnxruntime_INCLUDE_HINT}
28+
${CMAKE_BINARY_DIR}/nuget/Microsoft.ML.OnnxRuntime.DirectML.1.7.0/build/native/include
2729
DOC "Onnxruntime include directory")
2830
endif()
2931

external/MunkeiVersionFromGit.cmake

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016-2017 Theo Willows
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
cmake_minimum_required( VERSION 3.0.0 )
24+
25+
include( CMakeParseArguments )
26+
27+
function( version_from_git )
28+
# Parse arguments
29+
set( options OPTIONAL FAST )
30+
set( oneValueArgs
31+
GIT_EXECUTABLE
32+
INCLUDE_HASH
33+
LOG
34+
TIMESTAMP
35+
)
36+
set( multiValueArgs )
37+
cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
38+
39+
# Defaults
40+
if( NOT DEFINED ARG_INCLUDE_HASH )
41+
set( ARG_INCLUDE_HASH ON )
42+
endif()
43+
44+
if( DEFINED ARG_GIT_EXECUTABLE )
45+
set( GIT_EXECUTABLE "${ARG_GIT_EXECUTABLE}" )
46+
else ()
47+
# Find Git or bail out
48+
find_package( Git )
49+
if( NOT GIT_FOUND )
50+
message( FATAL_ERROR "[MunkeiVersionFromGit] Git not found" )
51+
endif( NOT GIT_FOUND )
52+
endif()
53+
54+
# Git describe
55+
execute_process(
56+
COMMAND "${GIT_EXECUTABLE}" describe --tags
57+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
58+
RESULT_VARIABLE git_result
59+
OUTPUT_VARIABLE git_describe
60+
ERROR_VARIABLE git_error
61+
OUTPUT_STRIP_TRAILING_WHITESPACE
62+
ERROR_STRIP_TRAILING_WHITESPACE
63+
)
64+
if( NOT git_result EQUAL 0 )
65+
message( FATAL_ERROR
66+
"[MunkeiVersionFromGit] Failed to execute Git: ${git_error}"
67+
)
68+
endif()
69+
70+
# Get Git tag
71+
execute_process(
72+
COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=0
73+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
74+
RESULT_VARIABLE git_result
75+
OUTPUT_VARIABLE git_tag
76+
ERROR_VARIABLE git_error
77+
OUTPUT_STRIP_TRAILING_WHITESPACE
78+
ERROR_STRIP_TRAILING_WHITESPACE
79+
)
80+
if( NOT git_result EQUAL 0 )
81+
message( FATAL_ERROR
82+
"[MunkeiVersionFromGit] Failed to execute Git: ${git_error}"
83+
)
84+
endif()
85+
86+
if( git_tag MATCHES "^v(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" )
87+
set( version_major "${CMAKE_MATCH_1}" )
88+
set( version_minor "${CMAKE_MATCH_2}" )
89+
set( version_patch "${CMAKE_MATCH_3}" )
90+
set( identifiers "${CMAKE_MATCH_4}" )
91+
set( metadata "${CMAKE_MATCH_5}" )
92+
else()
93+
message( FATAL_ERROR
94+
"[MunkeiVersionFromGit] Git tag isn't valid semantic version: [${git_tag}]"
95+
)
96+
endif()
97+
98+
if( "${git_tag}" STREQUAL "${git_describe}" )
99+
set( git_at_a_tag ON )
100+
endif()
101+
102+
if( NOT git_at_a_tag )
103+
# Extract the Git hash (if one exists)
104+
string( REGEX MATCH "g[0-9a-f]+$" git_hash "${git_describe}" )
105+
endif()
106+
107+
# Construct the version variables
108+
set( version ${version_major}.${version_minor}.${version_patch} )
109+
set( semver ${version} )
110+
111+
# Identifiers
112+
if( identifiers MATCHES ".+" )
113+
string( SUBSTRING "${identifiers}" 1 -1 identifiers )
114+
set( semver "${semver}-${identifiers}")
115+
endif()
116+
117+
# Metadata
118+
# TODO Split and join (add Git hash inbetween)
119+
if( metadata MATCHES ".+" )
120+
string( SUBSTRING "${metadata}" 1 -1 metadata )
121+
# Split
122+
string( REPLACE "." ";" metadata "${metadata}" )
123+
endif()
124+
125+
if( NOT git_at_a_tag )
126+
127+
if( ARG_INCLUDE_HASH )
128+
list( APPEND metadata "${git_hash}" )
129+
endif( ARG_INCLUDE_HASH )
130+
131+
# Timestamp
132+
if( DEFINED ARG_TIMESTAMP )
133+
string( TIMESTAMP timestamp "${ARG_TIMESTAMP}" ${ARG_UTC} )
134+
list( APPEND metadata "${timestamp}" )
135+
endif( DEFINED ARG_TIMESTAMP )
136+
137+
endif()
138+
139+
# Join
140+
string( REPLACE ";" "." metadata "${metadata}" )
141+
142+
if( metadata MATCHES ".+" )
143+
set( semver "${semver}+${metadata}")
144+
endif()
145+
146+
# Log the results
147+
if( ARG_LOG )
148+
message( STATUS
149+
"[MunkeiVersionFromGit] Version: ${version}
150+
Git tag: [${git_tag}]
151+
Git hash: [${git_hash}]
152+
Decorated: [${git_describe}]
153+
Identifiers: [${identifiers}]
154+
Metadata: [${metadata}]
155+
SemVer: [${semver}]"
156+
)
157+
endif( ARG_LOG )
158+
159+
# Set parent scope variables
160+
set( GIT_TAG ${git_tag} PARENT_SCOPE )
161+
set( SEMVER ${semver} PARENT_SCOPE )
162+
set( VERSION ${version} PARENT_SCOPE )
163+
set( VERSION_MAJOR ${version_major} PARENT_SCOPE )
164+
set( VERSION_MINOR ${version_minor} PARENT_SCOPE )
165+
set( VERSION_PATCH ${version_patch} PARENT_SCOPE )
166+
167+
endfunction( version_from_git )

0 commit comments

Comments
 (0)