16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-09-01 09:19:19 +02:00

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.
This commit is contained in:
combolek
2026-07-24 20:54:12 -07:00
parent d9eb705d4a
commit 1d08198d22
2 changed files with 13 additions and 3 deletions

View File

@@ -9,6 +9,8 @@ int MaShaderCompiler::Run() {
ParseOptions(); ParseOptions();
Init(); Init();
m_shader_path = m_project_path.parent_path(); m_shader_path = m_project_path.parent_path();
m_shader_path.make_preferred();
YAML::Node src = YAML::LoadFile((m_project_path).generic_string()); YAML::Node src = YAML::LoadFile((m_project_path).generic_string());
create_directories(m_output_path); create_directories(m_output_path);
@@ -47,6 +49,7 @@ void MaShaderCompiler::Init() {
const char *shader_path = getenv("shader_path"); const char *shader_path = getenv("shader_path");
if (shader_path) { if (shader_path) {
m_shader_path = shader_path; m_shader_path = shader_path;
m_shader_path.make_preferred();
std::cout << "shader path: " << m_shader_path.generic_string() << std::endl; std::cout << "shader path: " << m_shader_path.generic_string() << std::endl;
} else { } else {
m_shader_path = ""; m_shader_path = "";
@@ -62,6 +65,9 @@ YAML::Binary MaShaderCompiler::CompileShaderToBlob(
std::vector<std::tuple<std::wstring, std::wstring>> defines, std::vector<std::tuple<std::wstring, std::wstring>> defines,
std::string target, ShaderPlatform platform) { std::string target, ShaderPlatform platform) {
file_name.replace_extension(".hlsl"); file_name.replace_extension(".hlsl");
// Convert to native format since the name comes from the project
// file with forward slashes
file_name.make_preferred();
static std::unordered_map<std::string, std::wstring> targets{ static std::unordered_map<std::string, std::wstring> targets{
{"compute", L"cs_6_0"}, {"vertex", L"vs_6_0"}, {"hull", L"hs_6_0"}, {"compute", L"cs_6_0"}, {"vertex", L"vs_6_0"}, {"hull", L"hs_6_0"},
{"domain", L"ds_6_0"}, {"geometry", L"gs_6_0"}, {"pixel", L"ps_6_0"}}; {"domain", L"ds_6_0"}, {"geometry", L"gs_6_0"}, {"pixel", L"ps_6_0"}};
@@ -74,7 +80,7 @@ YAML::Binary MaShaderCompiler::CompileShaderToBlob(
} }
RefCountPtr<IDxcBlobEncoding> source_blob; RefCountPtr<IDxcBlobEncoding> source_blob;
if (FAILED(m_dxc_utils->LoadFile(file_name.generic_wstring().c_str(), nullptr, if (FAILED(m_dxc_utils->LoadFile(file_name.wstring().c_str(), nullptr,
&source_blob))) { &source_blob))) {
return {}; return {};
} }
@@ -84,8 +90,8 @@ YAML::Binary MaShaderCompiler::CompileShaderToBlob(
Source.Encoding = DXC_CP_ACP; Source.Encoding = DXC_CP_ACP;
std::vector<std::wstring> include_paths{ std::vector<std::wstring> include_paths{
m_shader_path.generic_wstring(), m_shader_path.wstring(),
file_name.parent_path().generic_wstring()}; file_name.parent_path().wstring()};
std::vector<const wchar_t *> args; std::vector<const wchar_t *> args;

View File

@@ -26,6 +26,10 @@ class MaShaderCompiler {
std::filesystem::path m_output_path; std::filesystem::path m_output_path;
private: 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; std::filesystem::path m_shader_path;
bool m_generate_debug = false; bool m_generate_debug = false;
void ParseOptions(); void ParseOptions();