-
Notifications
You must be signed in to change notification settings - Fork 3k
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
video/out/vulkan: add MoltenVK context #7857
Closed
Closed
Changes from all commits
Commits
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 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 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 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 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,96 @@ | ||
/* | ||
* This file is part of mpv. | ||
* | ||
* mpv is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* mpv 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with mpv. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <CoreGraphics/CoreGraphics.h> | ||
#include <QuartzCore/CAMetalLayer.h> | ||
#include <MoltenVK/mvk_vulkan.h> | ||
|
||
#include "common.h" | ||
#include "context.h" | ||
#include "utils.h" | ||
|
||
struct priv { | ||
struct mpvk_ctx vk; | ||
CAMetalLayer *layer; | ||
}; | ||
|
||
static void moltenvk_uninit(struct ra_ctx *ctx) | ||
{ | ||
struct priv *p = ctx->priv; | ||
ra_vk_ctx_uninit(ctx); | ||
mpvk_uninit(&p->vk); | ||
} | ||
|
||
static bool moltenvk_init(struct ra_ctx *ctx) | ||
{ | ||
struct priv *p = ctx->priv = talloc_zero(ctx, struct priv); | ||
struct mpvk_ctx *vk = &p->vk; | ||
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR; | ||
|
||
if (ctx->vo->opts->WinID == -1) { | ||
MP_MSG(ctx, msgl, "WinID missing\n"); | ||
goto fail; | ||
} | ||
|
||
if (!mpvk_init(vk, ctx, VK_EXT_METAL_SURFACE_EXTENSION_NAME)) | ||
goto fail; | ||
|
||
p->layer = (__bridge CAMetalLayer *)(intptr_t)ctx->vo->opts->WinID; | ||
VkMetalSurfaceCreateInfoEXT info = { | ||
.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT, | ||
.pLayer = p->layer, | ||
}; | ||
|
||
struct ra_vk_ctx_params params = {0}; | ||
|
||
VkInstance inst = vk->vkinst->instance; | ||
VkResult res = vkCreateMetalSurfaceEXT(inst, &info, NULL, &vk->surface); | ||
if (res != VK_SUCCESS) { | ||
MP_MSG(ctx, msgl, "Failed creating MoltenVK surface\n"); | ||
goto fail; | ||
} | ||
|
||
if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_FIFO_KHR)) | ||
goto fail; | ||
|
||
return true; | ||
fail: | ||
moltenvk_uninit(ctx); | ||
return false; | ||
} | ||
|
||
static bool moltenvk_reconfig(struct ra_ctx *ctx) | ||
{ | ||
struct priv *p = ctx->priv; | ||
CGSize s = p->layer.drawableSize; | ||
ra_vk_ctx_resize(ctx, s.height, s.height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. //should pass width here not height |
||
return true; | ||
} | ||
|
||
static int moltenvk_control(struct ra_ctx *ctx, int *events, int request, void *arg) | ||
{ | ||
return VO_NOTIMPL; | ||
} | ||
|
||
const struct ra_ctx_fns ra_ctx_vulkan_moltenvk = { | ||
.type = "vulkan", | ||
.name = "moltenvk", | ||
.reconfig = moltenvk_reconfig, | ||
.control = moltenvk_control, | ||
.init = moltenvk_init, | ||
.uninit = moltenvk_uninit, | ||
}; |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying
--gpu-api=vulkan
here is redundant.