Skip to content

Commit f7a1504

Browse files
committed
vulkan: locate shaders in srcdir
If running from inside out-of-tree build, the shaders were not located - now look them up in srcdir (if the the formerly looked shader directory doesn't exist).
1 parent fb15e67 commit f7a1504

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3528,7 +3528,8 @@ AC_SUBST(TEST_OBJS)
35283528
AC_SUBST(TOREMOVE)
35293529

35303530
# -------------------------------------------------------------------------------------------------
3531-
# Finally, substitute things into the Makefile and config.h
3531+
# Print summary + set it to AUTOCONF_RESULT
3532+
# -------------------------------------------------------------------------------------------------
35323533

35333534
start_section() {
35343535
printf "$1\n$2:"
@@ -3664,6 +3665,12 @@ RES_STR=`printf "$RESULT" | sed 's/$/\\\\n/' | tr -d '\n'`
36643665

36653666
AC_DEFINE_UNQUOTED([AUTOCONF_RESULT], "$RES_STR", [Autoconf result])
36663667

3668+
# -------------------------------------------------------------------------------------------------
3669+
# Finally, substitute things into the Makefile and config.h
3670+
# -------------------------------------------------------------------------------------------------
3671+
3672+
AC_DEFINE_UNQUOTED([SRCDIR], "$srcdir", [path to src directory])
3673+
36673674
AC_CONFIG_HEADERS([src/config.h])
36683675
AC_CONFIG_FILES([Makefile])
36693676
AC_OUTPUT

src/video_display/vulkan/vulkan_display.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Bela <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2021-2023 CESNET, z. s. p. o.
6+
* Copyright (c) 2021-2025 CESNET
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -41,13 +41,21 @@
4141
#include <cmath>
4242
#include <cstdint>
4343
#include <cstring>
44+
#include <filesystem>
4445
#include <fstream>
4546
#include <iostream>
4647
#include <memory>
4748
#include <tuple>
4849
#include <utility>
4950
#include <vector>
5051
#include "debug.h"
52+
#include "utils/fs.h"
53+
54+
#ifdef HAVE_CONFIG_H
55+
#include "config.h" // for SRCDIR
56+
#else
57+
#define SRCDIR ".."
58+
#endif // HAVE_CONFIG_H
5159

5260
#define MOD_NAME "[vulkan] "
5361

@@ -652,4 +660,22 @@ void VulkanDisplay::window_parameters_changed(WindowParameters new_parameters) {
652660
}
653661
}
654662

663+
std::string
664+
get_shader_path()
665+
{
666+
constexpr char suffix[] = "/share/ultragrid/vulkan_shaders";
667+
// note that get_install_root returns bin/.. if run from build,
668+
// which will not contain the shaders for out-of-tree builds
669+
const char *path = get_install_root();
670+
if (path != nullptr) {
671+
std::string path_to_shaders = std::string(path) + suffix;
672+
std::filesystem::directory_entry dir{ std::filesystem::path(
673+
path_to_shaders) };
674+
if (dir.exists()) {
675+
return path_to_shaders;
676+
}
677+
}
678+
return std::string(SRCDIR) + suffix;
679+
}
680+
655681
} //namespace vulkan_display

src/video_display/vulkan/vulkan_display.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Bela <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2021-2023 CESNET, z. s. p. o.
6+
* Copyright (c) 2021-2025 CESNET
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -201,4 +201,6 @@ class VulkanDisplay {
201201
bool destroyed = false;
202202
};
203203

204+
std::string get_shader_path();
205+
204206
} //vulkan_display

src/video_display/vulkan/vulkan_sdl2.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include "video_display.h"
6161
#include "video_display/splashscreen.h"
6262
#include "video.h"
63-
#include "utils/fs.h"
6463
//remove leaking macros
6564
#undef min
6665
#undef max
@@ -776,9 +775,7 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
776775
SDL_Vulkan_GetInstanceExtensions(s->window, &extension_count, required_extensions.data());
777776
assert(extension_count > 0);
778777

779-
const char *path = get_install_root();
780-
std::string path_to_shaders{ path ? path : ".." };
781-
path_to_shaders = path_to_shaders + "/share/ultragrid/vulkan_shaders";
778+
std::string path_to_shaders = vkd::get_shader_path();
782779
LOG(LOG_LEVEL_INFO) << MOD_NAME "Path to shaders: " << path_to_shaders << '\n';
783780
try {
784781
vkd::VulkanInstance instance;

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include "video_display.h"
6060
#include "video_display/splashscreen.h"
6161
#include "video.h"
62-
#include "utils/fs.h"
6362
//remove leaking macros
6463
#undef min
6564
#undef max
@@ -805,9 +804,7 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
805804
std::vector<const char*> required_extensions(extensions, extensions + extension_count);
806805
assert(extension_count > 0);
807806

808-
const char *path = get_install_root();
809-
std::string path_to_shaders{ path ? path : ".." };
810-
path_to_shaders = path_to_shaders + "/share/ultragrid/vulkan_shaders";
807+
std::string path_to_shaders = vkd::get_shader_path();
811808
LOG(LOG_LEVEL_INFO) << MOD_NAME "Path to shaders: " << path_to_shaders << '\n';
812809
try {
813810
vkd::VulkanInstance instance;

0 commit comments

Comments
 (0)