[Chore] (MG_Util/Program): use SPIRV-Cross C++ API instead of C ones

This commit is contained in:
2025-08-02 12:25:08 +08:00
parent 26a9cafcb8
commit 8e0284faec
6 changed files with 83 additions and 57 deletions
+1 -3
View File
@@ -27,10 +27,8 @@ namespace MobileGL {
WideCharToMultiByte(CP_UTF8, 0, desc, -1, buffer, sizeof(buffer), nullptr, nullptr);
LocalFree(desc);
}
#elif defined(__ANDROID__) || defined(__linux__)
#elif defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
#elif defined(__APPLE__)
pthread_getname_np(buffer, sizeof(buffer));
#endif
return buffer[0] ? buffer : "UnknownThread";
}
@@ -207,18 +207,37 @@ namespace MobileGL {
const char *result = nullptr;
session.Compile(&result);
if (!result) {
ResultInfo r;
r.log += "Failed to compile the shader to GLSL: \n";
r.log += session.GetLastErrorString();
r.errc = -5;
return std::unexpected(r);
}
// if (!result) {
// ResultInfo r;
// r.log += "Failed to compile the shader to GLSL: \n";
// r.log += session.GetLastErrorString();
// r.errc = -5;
// return std::unexpected(r);
// }
std::string glsl = result;
return glsl;
}
Result<String> ShaderCompiler::DecompileShader(spirv_cross::CompilerGLSL& compiler) {
try {
spirv_cross::CompilerGLSL::Options options;
options.version = 450;
options.es = false;
options.vulkan_semantics = true;
compiler.set_common_options(options);
auto result = compiler.compile();
return result;
} catch (const spirv_cross::CompilerError& e) {
ResultInfo r;
r.log += "Failed to compile the shader to GLSL: \n";
r.log += e.what();
r.errc = -5;
return std::unexpected(r);
}
}
}
}
}
@@ -8,6 +8,7 @@ namespace ShaderTranspiler {
static Result<SharedPtr<glslang::TShader>> CompileShader(const ShaderAttrib& attrib);
static Result<Vector<Vector<unsigned>>> LinkProgram(const ProgramAttrib& attrib);
static Result<String> DecompileShader(SpvcSession& session);
static Result<String> DecompileShader(spirv_cross::CompilerGLSL& compiler);
};
}
}