Skip to content

Commit 5600146

Browse files
committed
Select the audio/video backend with the best match of caps
1 parent 4c03b28 commit 5600146

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/svr_common/svr_common.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <assert.h>
88
#include <mfapi.h>
99
#include <strsafe.h>
10+
#include <intrin.h>
1011

1112
// Prefer to use this instead of calling Release yourself since you can use this to see the actual reference count.
1213
void svr_release(struct IUnknown* p)
@@ -442,6 +443,12 @@ s32 svr_count_num_true(bool* opts, s32 num)
442443
return ret;
443444
}
444445

446+
s32 svr_count_set_bits(u32 bits)
447+
{
448+
s32 ret = __popcnt(bits);
449+
return ret;
450+
}
451+
445452
bool svr_does_file_exist(const char* path)
446453
{
447454
WIN32_FILE_ATTRIBUTE_DATA attr;

src/svr_common/svr_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ s64 svr_rescale(s64 a, s64 b, s64 c);
186186
bool svr_check_all_true(bool* opts, s32 num);
187187
bool svr_check_one_true(bool* opts, s32 num);
188188
s32 svr_count_num_true(bool* opts, s32 num);
189+
s32 svr_count_set_bits(u32 bits);
189190

190191
bool svr_does_file_exist(const char* path);
191192

src/svr_standalone/game_audio.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ GameAudioSearch GAME_AUDIO_BACKENDS[] =
1515

1616
void game_audio_init()
1717
{
18+
GameAudioDesc* best_desc = NULL;
19+
s32 best_match = 0;
20+
1821
for (s32 i = 0; i < SVR_ARRAY_SIZE(GAME_AUDIO_BACKENDS); i++)
1922
{
2023
GameAudioSearch* s = &GAME_AUDIO_BACKENDS[i];
2124

22-
if (game_state.search_desc.caps & s->caps)
25+
s32 num_match = svr_count_set_bits(game_state.search_desc.caps & s->caps);
26+
27+
if (num_match > best_match)
2328
{
24-
game_state.audio_desc = s->desc;
25-
break;
29+
best_desc = s->desc;
30+
best_match = num_match;
2631
}
2732
}
2833

34+
game_state.audio_desc = best_desc;
35+
2936
if (game_state.audio_desc)
3037
{
3138
svr_log("Using game audio backend %s\n", game_state.audio_desc->name);

src/svr_standalone/game_video.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@ GameVideoSearch GAME_VIDEO_BACKENDS[] =
1414
// Find the right video backend from the search description.
1515
void game_video_init()
1616
{
17+
GameVideoDesc* best_desc = NULL;
18+
s32 best_match = 0;
19+
1720
for (s32 i = 0; i < SVR_ARRAY_SIZE(GAME_VIDEO_BACKENDS); i++)
1821
{
1922
GameVideoSearch* s = &GAME_VIDEO_BACKENDS[i];
2023

21-
if (game_state.search_desc.caps & s->caps)
24+
s32 num_match = svr_count_set_bits(game_state.search_desc.caps & s->caps);
25+
26+
if (num_match > best_match)
2227
{
23-
game_state.video_desc = s->desc;
24-
break;
28+
best_desc = s->desc;
29+
best_match = num_match;
2530
}
2631
}
2732

33+
game_state.video_desc = best_desc;
34+
2835
if (game_state.video_desc == NULL)
2936
{
3037
game_init_error("No video backend available.");

0 commit comments

Comments
 (0)