16#ifndef ACMXVK_BUILD_RESOURCE_DIRECTORY
17#define ACMXVK_BUILD_RESOURCE_DIRECTORY "."
20#ifndef ACMXVK_INSTALL_RESOURCE_DIRECTORY
21#define ACMXVK_INSTALL_RESOURCE_DIRECTORY "."
24#ifndef ACMXVK_BUILD_SPRITE_VERTEX_SHADER
25#define ACMXVK_BUILD_SPRITE_VERTEX_SHADER "sprite.vert.spv"
28#ifndef ACMXVK_INSTALL_SPRITE_VERTEX_SHADER
29#define ACMXVK_INSTALL_SPRITE_VERTEX_SHADER "sprite.vert.spv"
32#ifndef ACMXVK_BUILD_ECHO_CACHE_SHADER
33#define ACMXVK_BUILD_ECHO_CACHE_SHADER "echo_cache.frag.spv"
36#ifndef ACMXVK_INSTALL_ECHO_CACHE_SHADER
37#define ACMXVK_INSTALL_ECHO_CACHE_SHADER "echo_cache.frag.spv"
40#ifndef ACMXVK_BUILD_FLIP_SHADER
41#define ACMXVK_BUILD_FLIP_SHADER "flip.frag.spv"
44#ifndef ACMXVK_INSTALL_FLIP_SHADER
45#define ACMXVK_INSTALL_FLIP_SHADER "flip.frag.spv"
48#ifndef ACMXVK_BUILD_PASSTHROUGH_SHADER
49#define ACMXVK_BUILD_PASSTHROUGH_SHADER "passthrough.frag.spv"
52#ifndef ACMXVK_INSTALL_PASSTHROUGH_SHADER
53#define ACMXVK_INSTALL_PASSTHROUGH_SHADER "passthrough.frag.spv"
56#ifndef ACMXVK_BUILD_STABLE_DIFFUSION_UPSCALE_SHADER
57#define ACMXVK_BUILD_STABLE_DIFFUSION_UPSCALE_SHADER "sd_upscale.comp.spv"
60#ifndef ACMXVK_INSTALL_STABLE_DIFFUSION_UPSCALE_SHADER
61#define ACMXVK_INSTALL_STABLE_DIFFUSION_UPSCALE_SHADER "sd_upscale.comp.spv"
64#ifndef ACMXVK_BUILD_HDR_TRANSFER_DIRECTORY
65#define ACMXVK_BUILD_HDR_TRANSFER_DIRECTORY "."
68#ifndef ACMXVK_INSTALL_HDR_TRANSFER_DIRECTORY
69#define ACMXVK_INSTALL_HDR_TRANSFER_DIRECTORY "."
72#ifndef ACMXVK_BUILD_HUMAN_COMPOSITE_SHADER
73#define ACMXVK_BUILD_HUMAN_COMPOSITE_SHADER "human_composite.frag.spv"
76#ifndef ACMXVK_INSTALL_HUMAN_COMPOSITE_SHADER
77#define ACMXVK_INSTALL_HUMAN_COMPOSITE_SHADER "human_composite.frag.spv"
80#ifndef ACMXVK_BUILD_MODEL_VERTEX_SHADER
81#define ACMXVK_BUILD_MODEL_VERTEX_SHADER "model.vert.spv"
84#ifndef ACMXVK_INSTALL_MODEL_VERTEX_SHADER
85#define ACMXVK_INSTALL_MODEL_VERTEX_SHADER "model.vert.spv"
88#ifndef ACMXVK_BUILD_MODEL_FRAGMENT_SHADER
89#define ACMXVK_BUILD_MODEL_FRAGMENT_SHADER "model.frag.spv"
92#ifndef ACMXVK_INSTALL_MODEL_FRAGMENT_SHADER
93#define ACMXVK_INSTALL_MODEL_FRAGMENT_SHADER "model.frag.spv"
96#ifndef ACMXVK_BUILD_DEFAULT_MODEL
97#define ACMXVK_BUILD_DEFAULT_MODEL "cube.obj"
100#ifndef ACMXVK_INSTALL_DEFAULT_MODEL
101#define ACMXVK_INSTALL_DEFAULT_MODEL "cube.obj"
104#ifndef ACMXVK_BUILD_OVERLAY_FONT
105#define ACMXVK_BUILD_OVERLAY_FONT "font.ttf"
108#ifndef ACMXVK_INSTALL_OVERLAY_FONT
109#define ACMXVK_INSTALL_OVERLAY_FONT "font.ttf"
112#ifndef ACMXVK_BUILD_CROSSFADE_DIRECTORY
113#define ACMXVK_BUILD_CROSSFADE_DIRECTORY "shaders/xfade"
116#ifndef ACMXVK_INSTALL_CROSSFADE_DIRECTORY
117#define ACMXVK_INSTALL_CROSSFADE_DIRECTORY "shaders/xfade"
123 [[nodiscard]] fs::path executable_resource_directory() {
124 std::vector<wchar_t> buffer(MAX_PATH);
126 const DWORD
length = GetModuleFileNameW(
nullptr, buffer.data(),
static_cast<DWORD
>(buffer.size()));
130 if (
length < buffer.size() - 1U) {
131 const std::wstring executable_name(buffer.data(),
length);
132 const fs::path executable(executable_name);
133 return executable.parent_path().parent_path() /
"share" /
"acmxvk";
135 if (buffer.size() >= 32768U) {
138 buffer.resize(buffer.size() * 2U);
143 [[nodiscard]] fs::path
resolve_resource(
const Options &options,
const fs::path &relative_path,
const fs::path &installed_path,
const fs::path &built_path) {
144 const fs::path resource =
find_resource(options, relative_path);
145 if (!resource.empty()) {
148 if (fs::is_regular_file(installed_path)) {
149 return installed_path;
156 std::vector<fs::path> directories;
157 const auto append = [&](
const fs::path &directory) {
158 if (directory.empty()) {
161 const fs::path normalized = fs::absolute(directory).lexically_normal();
162 if (std::find(directories.begin(), directories.end(), normalized) == directories.end()) {
163 directories.push_back(normalized);
170 append(executable_resource_directory());
172 append(fs::current_path());
177 if (relative_path.empty() || relative_path.is_absolute()) {
180 const fs::path normalized_relative = relative_path.lexically_normal();
181 const std::string relative_text = normalized_relative.generic_string();
182 if (relative_text ==
".." || relative_text.starts_with(
"../") || relative_text.find(
"/../") != std::string::npos) {
186 const fs::path candidate = (directory / normalized_relative).lexically_normal();
187 if (fs::is_regular_file(candidate)) {
196 const fs::path candidate = resource_directory.parent_path() /
"mxvk" /
"shaders";
197 if (fs::is_directory(candidate)) {
215 const std::string filename = std::string(
"hdr_") + (hlg ?
"hlg_" :
"pq_") + (encode ?
"encode.frag.spv" :
"decode.frag.spv");
220 const std::string filename = std::string(
"hdr_preview_") + (hlg ?
"hlg" :
"pq") +
".frag.spv";
228 throw std::out_of_range(
"crossfade shader index is out of range");
230 const std::string filename = std::string(
CROSSFADE_NAMES[shader_index]) +
".frag.spv";
231 const fs::path resource =
find_resource(options, fs::path(
"shaders/xfade") / filename);
232 if (!resource.empty()) {
236 if (fs::is_regular_file(installed)) {
240 if (fs::is_regular_file(built)) {
243 throw std::runtime_error(
"crossfade shader was not found: " + filename);
fs::path resolve_resource(const Options &options, const fs::path &relative_path, const fs::path &installed_path, const fs::path &built_path)
fs::path default_model_path(const Options &options)
fs::path echo_cache_shader_path(const Options &options)
fs::path human_composite_shader_path(const Options &options)
std::vector< fs::path > resource_directories(const Options &options)
fs::path model_fragment_shader_path(const Options &options)
fs::path model_vertex_shader_path(const Options &options)
fs::path passthrough_shader_path(const Options &options)
fs::path hdr_preview_shader_path(const Options &options, bool hlg)
fs::path crossfade_shader_path(const Options &options, std::size_t shader_index)
fs::path stable_diffusion_upscale_shader_path(const Options &options)
fs::path sprite_vertex_shader_path(const Options &options)
fs::path hdr_transfer_shader_path(const Options &options, bool hlg, bool encode)
fs::path mxvk_shader_directory(const Options &options)
constexpr std::array< std::string_view, 35 > CROSSFADE_NAMES
fs::path overlay_font_path(const Options &options)
fs::path flip_shader_path(const Options &options)
fs::path find_resource(const Options &options, const fs::path &relative_path)
#define ACMXVK_BUILD_MODEL_VERTEX_SHADER
#define ACMXVK_INSTALL_HDR_TRANSFER_DIRECTORY
#define ACMXVK_INSTALL_PASSTHROUGH_SHADER
#define ACMXVK_INSTALL_OVERLAY_FONT
#define ACMXVK_BUILD_HUMAN_COMPOSITE_SHADER
#define ACMXVK_BUILD_CROSSFADE_DIRECTORY
#define ACMXVK_BUILD_PASSTHROUGH_SHADER
#define ACMXVK_BUILD_ECHO_CACHE_SHADER
#define ACMXVK_BUILD_RESOURCE_DIRECTORY
#define ACMXVK_INSTALL_MODEL_VERTEX_SHADER
#define ACMXVK_INSTALL_RESOURCE_DIRECTORY
#define ACMXVK_INSTALL_STABLE_DIFFUSION_UPSCALE_SHADER
#define ACMXVK_INSTALL_SPRITE_VERTEX_SHADER
#define ACMXVK_BUILD_DEFAULT_MODEL
#define ACMXVK_INSTALL_HUMAN_COMPOSITE_SHADER
#define ACMXVK_INSTALL_MODEL_FRAGMENT_SHADER
#define ACMXVK_BUILD_FLIP_SHADER
#define ACMXVK_INSTALL_ECHO_CACHE_SHADER
#define ACMXVK_BUILD_SPRITE_VERTEX_SHADER
#define ACMXVK_INSTALL_FLIP_SHADER
#define ACMXVK_BUILD_STABLE_DIFFUSION_UPSCALE_SHADER
#define ACMXVK_BUILD_OVERLAY_FONT
#define ACMXVK_INSTALL_CROSSFADE_DIRECTORY
#define ACMXVK_BUILD_MODEL_FRAGMENT_SHADER
#define ACMXVK_INSTALL_DEFAULT_MODEL
#define ACMXVK_BUILD_HDR_TRANSFER_DIRECTORY
std::string resource_directory