This commit is contained in:
parent
988c1821af
commit
df9436c51d
3 changed files with 67 additions and 31 deletions
|
|
@ -417,6 +417,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
|
|
||||||
std::string files;
|
std::string files;
|
||||||
std::unordered_set<std::string> libSet;
|
std::unordered_set<std::string> libSet;
|
||||||
|
std::unordered_set<std::string> publicFlagSet;
|
||||||
std::mutex fileMutex;
|
std::mutex fileMutex;
|
||||||
std::vector<std::thread> depThreads;
|
std::vector<std::thread> depThreads;
|
||||||
depThreads.reserve(config.dependencies.size());
|
depThreads.reserve(config.dependencies.size());
|
||||||
|
|
@ -477,6 +478,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
const BuildResult& result = resultFuture.get();
|
const BuildResult& result = resultFuture.get();
|
||||||
fileMutex.lock();
|
fileMutex.lock();
|
||||||
for (const std::string& lib : result.libs) libSet.insert(lib);
|
for (const std::string& lib : result.libs) libSet.insert(lib);
|
||||||
|
for (const std::string& f : result.publicCompileFlags) publicFlagSet.insert(f);
|
||||||
fileMutex.unlock();
|
fileMutex.unlock();
|
||||||
if (!result.result.empty()) {
|
if (!result.result.empty()) {
|
||||||
bool expected = false;
|
bool expected = false;
|
||||||
|
|
@ -577,10 +579,19 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
for(const std::string& flag : config.linkFlags) {
|
for(const std::string& flag : config.linkFlags) {
|
||||||
buildResult.libs.insert(flag);
|
buildResult.libs.insert(flag);
|
||||||
}
|
}
|
||||||
|
// Public compile flags propagated from sub-deps. Add them to this build's
|
||||||
|
// command so config sees the headers its deps expose, and re-publish them
|
||||||
|
// so config's own consumers see them transitively.
|
||||||
|
for (const std::string& flag : publicFlagSet) command += " " + flag;
|
||||||
|
buildResult.publicCompileFlags = std::move(publicFlagSet);
|
||||||
fs::file_time_type externalFloor = fs::file_time_type::min();
|
fs::file_time_type externalFloor = fs::file_time_type::min();
|
||||||
for(const ExternalBuildResult& ext : externalResults) {
|
for(const ExternalBuildResult& ext : externalResults) {
|
||||||
for(const std::string& flag : ext.compileFlags) {
|
for(const std::string& flag : ext.compileFlags) {
|
||||||
command += " " + flag;
|
command += " " + flag;
|
||||||
|
// Headers a dep links via ExternalDependency are part of its
|
||||||
|
// public surface (its modules can include them in declarations
|
||||||
|
// visible to consumers), so propagate the -I to consumers.
|
||||||
|
buildResult.publicCompileFlags.insert(flag);
|
||||||
}
|
}
|
||||||
for(const std::string& flag : ext.linkFlags) {
|
for(const std::string& flag : ext.linkFlags) {
|
||||||
buildResult.libs.insert(flag);
|
buildResult.libs.insert(flag);
|
||||||
|
|
@ -1047,6 +1058,11 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
// through cmd /c, so the relative-prefixed path makes cmd error
|
// through cmd /c, so the relative-prefixed path makes cmd error
|
||||||
// with "'.' is not recognized as an internal or external command".
|
// with "'.' is not recognized as an internal or external command".
|
||||||
artifact = fs::absolute(artifact);
|
artifact = fs::absolute(artifact);
|
||||||
|
// Run from the artifact's own directory so relative file opens
|
||||||
|
// (shaders, assets copied alongside the exe via cfg.files) resolve
|
||||||
|
// against the bin dir rather than the user's cwd. We exit the
|
||||||
|
// process immediately after, so no cwd restore needed.
|
||||||
|
fs::current_path(dir);
|
||||||
return std::system(artifact.string().c_str()) == 0 ? 0 : 1;
|
return std::system(artifact.string().c_str()) == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,65 +59,80 @@ namespace Crafter {
|
||||||
std::string Shader::Compile(const fs::path& outputDir) const {
|
std::string Shader::Compile(const fs::path& outputDir) const {
|
||||||
EShLanguage glslangType = ToEShLanguage(type);
|
EShLanguage glslangType = ToEShLanguage(type);
|
||||||
glslang::InitializeProcess();
|
glslang::InitializeProcess();
|
||||||
|
|
||||||
|
// Every error path returns a non-empty string; the caller treats
|
||||||
|
// empty as success (see Crafter.Build-Clang.cpp BuildOnce shader
|
||||||
|
// worker). Prefixing with the source path is what tells the user
|
||||||
|
// which shader actually failed when several compile in parallel.
|
||||||
|
auto fail = [&](std::string_view stage, std::string log) {
|
||||||
|
glslang::FinalizeProcess();
|
||||||
|
std::string out = path.string();
|
||||||
|
out += ": ";
|
||||||
|
out += stage;
|
||||||
|
if (!log.empty()) {
|
||||||
|
out += '\n';
|
||||||
|
out += log;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
EShMessages messages = static_cast<EShMessages>(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
|
EShMessages messages = static_cast<EShMessages>(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
|
||||||
std::ifstream fileStream(path, std::ios::in | std::ios::binary);
|
std::ifstream fileStream(path, std::ios::in | std::ios::binary);
|
||||||
if (!fileStream) {
|
if (!fileStream) {
|
||||||
throw std::ios_base::failure("Failed to open file: " + path.string());
|
return fail("failed to open shader source", {});
|
||||||
}
|
}
|
||||||
std::ostringstream contents;
|
std::ostringstream contents;
|
||||||
contents << fileStream.rdbuf();
|
contents << fileStream.rdbuf();
|
||||||
std::string src = contents.str();
|
std::string src = contents.str();
|
||||||
|
|
||||||
const char *file_name_list[1] = {""};
|
std::string pathStr = path.string();
|
||||||
const char *shader_source = reinterpret_cast<const char *>(src.data());
|
const char* file_name_list[1] = { pathStr.c_str() };
|
||||||
|
const char* shader_source = src.data();
|
||||||
|
const int shader_source_len = static_cast<int>(src.size());
|
||||||
|
|
||||||
glslang::TShader shader(glslangType);
|
glslang::TShader shader(glslangType);
|
||||||
shader.setStringsWithLengthsAndNames(&shader_source, nullptr, file_name_list, 1);
|
shader.setStringsWithLengthsAndNames(&shader_source, &shader_source_len, file_name_list, 1);
|
||||||
shader.setEntryPoint(entrypoint.c_str());
|
shader.setEntryPoint(entrypoint.c_str());
|
||||||
shader.setSourceEntryPoint(entrypoint.c_str());
|
shader.setSourceEntryPoint(entrypoint.c_str());
|
||||||
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
|
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
|
||||||
DirStackFileIncluder includeDir;
|
DirStackFileIncluder includeDir;
|
||||||
includeDir.pushExternalLocalDirectory(path.parent_path().generic_string());
|
includeDir.pushExternalLocalDirectory(path.parent_path().generic_string());
|
||||||
std::string info_log;
|
|
||||||
if (!shader.parse(GetDefaultResources(), 100, false, messages, includeDir))
|
if (!shader.parse(GetDefaultResources(), 100, false, messages, includeDir)) {
|
||||||
{
|
return fail("GLSL parse failed", std::string(shader.getInfoLog()) + shader.getInfoDebugLog());
|
||||||
info_log = std::string(shader.getInfoLog()) + std::string(shader.getInfoDebugLog());
|
|
||||||
}
|
}
|
||||||
// Add shader to new program object.
|
|
||||||
glslang::TProgram program;
|
glslang::TProgram program;
|
||||||
program.addShader(&shader);
|
program.addShader(&shader);
|
||||||
|
if (!program.link(messages)) {
|
||||||
// Link program.
|
return fail("GLSL link failed", std::string(program.getInfoLog()) + program.getInfoDebugLog());
|
||||||
if (!program.link(messages))
|
|
||||||
{
|
|
||||||
info_log = std::string(program.getInfoLog()) + std::string(program.getInfoDebugLog());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save any info log that was generated.
|
|
||||||
if (shader.getInfoLog())
|
|
||||||
{
|
|
||||||
info_log += std::string(shader.getInfoLog()) + std::string(shader.getInfoDebugLog());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (program.getInfoLog())
|
|
||||||
{
|
|
||||||
info_log += std::string(program.getInfoLog()) + std::string(program.getInfoDebugLog());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glslang::TIntermediate* intermediate = program.getIntermediate(glslangType);
|
glslang::TIntermediate* intermediate = program.getIntermediate(glslangType);
|
||||||
if (!intermediate)
|
if (!intermediate) {
|
||||||
{
|
// Defensive: parse+link succeeded above, so this should be
|
||||||
info_log += "Failed to get shared intermediate code.";
|
// unreachable. If glslang ever changes that contract we'd
|
||||||
|
// rather surface a clear error than dereference null (the
|
||||||
|
// pre-fix bug that masqueraded as a silent SIGSEGV).
|
||||||
|
return fail("glslang produced no intermediate code", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
spv::SpvBuildLogger logger;
|
spv::SpvBuildLogger logger;
|
||||||
std::vector<std::uint32_t> spirv;
|
std::vector<std::uint32_t> spirv;
|
||||||
glslang::GlslangToSpv(*intermediate, spirv, &logger);
|
glslang::GlslangToSpv(*intermediate, spirv, &logger);
|
||||||
std::string errorLog = logger.getAllMessages();
|
std::string spvLog = logger.getAllMessages();
|
||||||
glslang::FinalizeProcess();
|
|
||||||
fs::path filename = path.filename().replace_extension("spv");
|
fs::path filename = path.filename().replace_extension("spv");
|
||||||
std::ofstream file(outputDir/filename, std::ios::binary);
|
std::ofstream file(outputDir/filename, std::ios::binary);
|
||||||
|
if (!file) {
|
||||||
|
return fail("failed to open SPIR-V output", (outputDir/filename).string());
|
||||||
|
}
|
||||||
file.write(reinterpret_cast<const char*>(spirv.data()), spirv.size() * sizeof(std::uint32_t));
|
file.write(reinterpret_cast<const char*>(spirv.data()), spirv.size() * sizeof(std::uint32_t));
|
||||||
return errorLog;
|
|
||||||
|
if (!spvLog.empty()) {
|
||||||
|
return fail("SPIR-V codegen reported issues", std::move(spvLog));
|
||||||
|
}
|
||||||
|
glslang::FinalizeProcess();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ export namespace Crafter {
|
||||||
std::string result;
|
std::string result;
|
||||||
bool repack;
|
bool repack;
|
||||||
std::unordered_set<std::string> libs;
|
std::unordered_set<std::string> libs;
|
||||||
|
// Compile flags (typically -I include paths) the dep wants its
|
||||||
|
// consumers to see — sourced from its external dependencies' include
|
||||||
|
// dirs so headers a dep exposes in its public modules are reachable
|
||||||
|
// when a consumer #includes them directly. Propagates transitively.
|
||||||
|
std::unordered_set<std::string> publicCompileFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Define {
|
struct Define {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue