17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 16:49:21 +02:00
Files
maszyna/betterRenderer/mashadercompiler/src/shader_compiler.hpp
combolek 1d08198d22 mashadercompiler: Add support for UNC paths
MS DXC on Windows (at least IDxcUtils::BuildArguments) does not support forward slashes in UNC paths. This change feeds it native format with backslashes.

This makes it possible to build Linux and Windows binaries from a single source on a network share.
2026-07-28 18:51:10 -07:00

52 lines
1.6 KiB
C++

#pragma once
#include <nvrhi/nvrhi.h>
#include <yaml-cpp/yaml.h>
#include <filesystem>
#ifndef _WIN32
#include <WinAdapter.h>
#else
#include <Windows.h>
#endif
#include <dxcapi.h>
template <typename T>
using RefCountPtr = nvrhi::RefCountPtr<T>;
enum class MaterialRenderPass : int { Deferred, Forward, CubeMap, Count };
enum class ShaderPlatform { D3D12, Vulkan };
class MaShaderCompiler {
public:
int Run();
std::filesystem::path m_project_path;
std::filesystem::path m_output_path;
private:
// Stored in the native format, since DXC does not accept forward
// slashes in UNC paths. Use wstring() to retrieve it in native
// format or generic_wstring() to get the canonical forward slash
// format.
std::filesystem::path m_shader_path;
bool m_generate_debug = false;
void ParseOptions();
void Init();
YAML::Binary CompileShaderToBlob(
std::filesystem::path file_name, std::wstring entry_name,
std::vector<std::tuple<std::wstring, std::wstring>> defines,
std::string target, ShaderPlatform platform);
bool CompileUtilityShader(YAML::Node& dest, const YAML::Node& src,
const YAML::Node& templates,
ShaderPlatform platform);
bool CompileMaterial(YAML::Node& dest, const YAML::Node& src,
const YAML::Node& templates, ShaderPlatform platform);
bool CompileProject(YAML::Node& dest, const YAML::Node& src,
const YAML::Node& templates, ShaderPlatform platform);
RefCountPtr<IDxcUtils> m_dxc_utils;
RefCountPtr<IDxcCompiler3> m_dxc_compiler;
RefCountPtr<IDxcIncludeHandler> m_dxc_include_handler;
};