Skip to content

Commit 1859711

Browse files
committed
apple: provide option to disable metal argument buffers
1 parent c27e815 commit 1859711

File tree

10 files changed

+54
-0
lines changed

10 files changed

+54
-0
lines changed

config.def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@
489489
/* Choose if the screen will be able to write around the notch or not */
490490
#define DEFAULT_NOTCH_WRITE_OVER_ENABLE false
491491

492+
#ifdef __APPLE__
493+
#define DEFAULT_USE_METAL_ARG_BUFFERS (!!__builtin_available(macOS 12, iOS 13, tvOS 12, *))
494+
#endif
495+
492496
/* Enable use of shaders. */
493497
#ifdef RARCH_CONSOLE
494498
#define DEFAULT_SHADER_ENABLE true

configuration.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,9 @@ static struct config_bool_setting *populate_settings_bool(
19201920
SETTING_BOOL("video_gpu_screenshot", &settings->bools.video_gpu_screenshot, true, DEFAULT_GPU_SCREENSHOT, false);
19211921
SETTING_BOOL("video_post_filter_record", &settings->bools.video_post_filter_record, true, DEFAULT_POST_FILTER_RECORD, false);
19221922
SETTING_BOOL("video_notch_write_over_enable", &settings->bools.video_notch_write_over_enable, true, DEFAULT_NOTCH_WRITE_OVER_ENABLE, false);
1923+
#if defined(__APPLE__) && defined(HAVE_VULKAN)
1924+
SETTING_BOOL("video_use_metal_arg_buffers", &settings->bools.video_use_metal_arg_buffers, true, DEFAULT_USE_METAL_ARG_BUFFERS, false);
1925+
#endif
19231926
SETTING_BOOL("video_msg_bgcolor_enable", &settings->bools.video_msg_bgcolor_enable, true, DEFAULT_MESSAGE_BGCOLOR_ENABLE, false);
19241927
SETTING_BOOL("video_window_show_decorations", &settings->bools.video_window_show_decorations, true, DEFAULT_WINDOW_DECORATIONS, false);
19251928
SETTING_BOOL("video_window_save_positions", &settings->bools.video_window_save_positions, true, DEFAULT_WINDOW_SAVE_POSITIONS, false);

configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ typedef struct settings
660660
bool video_notch_write_over_enable;
661661
bool video_hdr_enable;
662662
bool video_hdr_expand_gamut;
663+
bool video_use_metal_arg_buffers;
663664

664665
/* Accessibility */
665666
bool accessibility_enable;

gfx/common/vulkan_common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,13 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
23702370
#ifdef _WIN32
23712371
vulkan_library = dylib_load("vulkan-1.dll");
23722372
#elif __APPLE__
2373+
/* allow overriding by environment variable; this means restart is required to change */
2374+
if (!getenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS"))
2375+
{
2376+
settings_t *settings = config_get_ptr();
2377+
int use_mab = settings->bools.video_use_metal_arg_buffers;
2378+
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", use_mab ? "1" : "0", 1);
2379+
}
23732380
if (__builtin_available(macOS 10.15, iOS 13, tvOS 12, *))
23742381
vulkan_library = dylib_load("MoltenVK");
23752382
if (!vulkan_library)

intl/msg_hash_lbl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4576,6 +4576,10 @@ MSG_HASH(
45764576
MENU_ENUM_LABEL_VIDEO_NOTCH_WRITE_OVER,
45774577
"video_notch_write_over"
45784578
)
4579+
MSG_HASH(
4580+
MENU_ENUM_LABEL_VIDEO_USE_METAL_ARG_BUFFERS,
4581+
"video_use_metal_arg_buffers"
4582+
)
45794583
MSG_HASH(
45804584
MENU_ENUM_LABEL_VIDEO_OUTPUT_SETTINGS,
45814585
"video_output_settings"

intl/msg_hash_us.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,14 @@ MSG_HASH(
21742174
MENU_ENUM_LABEL_VALUE_VIDEO_NOTCH_WRITE_OVER,
21752175
"Enable fullscreen over notch in Android and iOS devices"
21762176
)
2177+
MSG_HASH(
2178+
MENU_ENUM_LABEL_VALUE_VIDEO_USE_METAL_ARG_BUFFERS,
2179+
"Use Metal Argument Buffers (Restart required)"
2180+
)
2181+
MSG_HASH(
2182+
MENU_ENUM_SUBLABEL_VIDEO_USE_METAL_ARG_BUFFERS,
2183+
"Try to improve performance by using Metal argument buffers. Some cores may require this. This may break some shaders, particularly on old hardware or OS versions."
2184+
)
21772185

21782186
/* Settings > Video > CRT SwitchRes */
21792187

menu/cbs/menu_cbs_sublabel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_dingux_rs90_softfilter_type,
12841284
#endif
12851285
#endif
12861286
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_screen_resolution, MENU_ENUM_SUBLABEL_SCREEN_RESOLUTION)
1287+
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_use_metal_arg_buffers, MENU_ENUM_SUBLABEL_VIDEO_USE_METAL_ARG_BUFFERS)
12871288
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_gpu_index, MENU_ENUM_SUBLABEL_VIDEO_GPU_INDEX)
12881289
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_vp_custom_height, MENU_ENUM_SUBLABEL_VIDEO_VIEWPORT_CUSTOM_HEIGHT)
12891290
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_vp_custom_width, MENU_ENUM_SUBLABEL_VIDEO_VIEWPORT_CUSTOM_WIDTH)
@@ -2621,6 +2622,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
26212622
case MENU_ENUM_LABEL_SCREEN_RESOLUTION:
26222623
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_screen_resolution);
26232624
break;
2625+
case MENU_ENUM_LABEL_VIDEO_USE_METAL_ARG_BUFFERS:
2626+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_use_metal_arg_buffers);
2627+
break;
26242628
case MENU_ENUM_LABEL_VIDEO_GPU_INDEX:
26252629
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_gpu_index);
26262630
break;

menu/menu_displaylist.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8082,6 +8082,11 @@ unsigned menu_displaylist_build_list(
80828082
MENU_ENUM_LABEL_VIDEO_NOTCH_WRITE_OVER,
80838083
PARSE_ONLY_BOOL, false) == 0)
80848084
count++;
8085+
8086+
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
8087+
MENU_ENUM_LABEL_VIDEO_USE_METAL_ARG_BUFFERS,
8088+
PARSE_ONLY_BOOL, false) == 0)
8089+
count++;
80858090
}
80868091
break;
80878092
case DISPLAYLIST_OPTIONS_REMAPPINGS:

menu/menu_setting.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12540,6 +12540,23 @@ static bool setting_append_list(
1254012540
#ifdef HAVE_VULKAN
1254112541
if (string_is_equal(video_driver_get_ident(), "vulkan"))
1254212542
{
12543+
#ifdef __APPLE__
12544+
CONFIG_BOOL(
12545+
list, list_info,
12546+
&settings->bools.video_use_metal_arg_buffers,
12547+
MENU_ENUM_LABEL_VIDEO_USE_METAL_ARG_BUFFERS,
12548+
MENU_ENUM_LABEL_VALUE_VIDEO_USE_METAL_ARG_BUFFERS,
12549+
DEFAULT_USE_METAL_ARG_BUFFERS,
12550+
MENU_ENUM_LABEL_VALUE_OFF,
12551+
MENU_ENUM_LABEL_VALUE_ON,
12552+
&group_info,
12553+
&subgroup_info,
12554+
parent_group,
12555+
general_write_handler,
12556+
general_read_handler,
12557+
SD_FLAG_NONE);
12558+
#endif
12559+
1254312560
CONFIG_INT(
1254412561
list, list_info,
1254512562
&settings->ints.vulkan_gpu_index,

msg_hash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ enum msg_hash_enums
14661466
MENU_LABEL(VIDEO_CROP_OVERSCAN),
14671467

14681468
MENU_LABEL(VIDEO_NOTCH_WRITE_OVER),
1469+
MENU_LABEL(VIDEO_USE_METAL_ARG_BUFFERS),
14691470

14701471
MENU_LABEL(VIDEO_SCALE_INTEGER),
14711472
MENU_LABEL(VIDEO_SCALE_INTEGER_AXIS),

0 commit comments

Comments
 (0)