comment shader
This commit is contained in:
parent
be18fb8568
commit
d13bf354ab
2 changed files with 55 additions and 55 deletions
|
|
@ -35,65 +35,65 @@ Shader::Shader(fs::path path, std::string entrypoint, EShLanguage type): path(pa
|
|||
}
|
||||
|
||||
void Shader::Compile(fs::path outputDir) {
|
||||
glslang::InitializeProcess();
|
||||
EShMessages messages = static_cast<EShMessages>(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
|
||||
std::ifstream fileStream(path, std::ios::in | std::ios::binary);
|
||||
if (!fileStream) {
|
||||
throw std::ios_base::failure("Failed to open file: " + path.string());
|
||||
}
|
||||
std::ostringstream contents;
|
||||
contents << fileStream.rdbuf();
|
||||
std::string src = contents.str();
|
||||
// glslang::InitializeProcess();
|
||||
// EShMessages messages = static_cast<EShMessages>(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
|
||||
// std::ifstream fileStream(path, std::ios::in | std::ios::binary);
|
||||
// if (!fileStream) {
|
||||
// throw std::ios_base::failure("Failed to open file: " + path.string());
|
||||
// }
|
||||
// std::ostringstream contents;
|
||||
// contents << fileStream.rdbuf();
|
||||
// std::string src = contents.str();
|
||||
|
||||
const char *file_name_list[1] = {""};
|
||||
const char *shader_source = reinterpret_cast<const char *>(src.data());
|
||||
// const char *file_name_list[1] = {""};
|
||||
// const char *shader_source = reinterpret_cast<const char *>(src.data());
|
||||
|
||||
glslang::TShader shader(type);
|
||||
shader.setStringsWithLengthsAndNames(&shader_source, nullptr, file_name_list, 1);
|
||||
shader.setEntryPoint(entrypoint.c_str());
|
||||
shader.setSourceEntryPoint(entrypoint.c_str());
|
||||
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
|
||||
DirStackFileIncluder includeDir;
|
||||
includeDir.pushExternalLocalDirectory(path.parent_path().generic_string());
|
||||
std::string info_log;
|
||||
if (!shader.parse(GetDefaultResources(), 100, false, messages, includeDir))
|
||||
{
|
||||
info_log = std::string(shader.getInfoLog()) + std::string(shader.getInfoDebugLog());
|
||||
}
|
||||
// Add shader to new program object.
|
||||
glslang::TProgram program;
|
||||
program.addShader(&shader);
|
||||
// glslang::TShader shader(type);
|
||||
// shader.setStringsWithLengthsAndNames(&shader_source, nullptr, file_name_list, 1);
|
||||
// shader.setEntryPoint(entrypoint.c_str());
|
||||
// shader.setSourceEntryPoint(entrypoint.c_str());
|
||||
// shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
|
||||
// DirStackFileIncluder includeDir;
|
||||
// includeDir.pushExternalLocalDirectory(path.parent_path().generic_string());
|
||||
// std::string info_log;
|
||||
// if (!shader.parse(GetDefaultResources(), 100, false, messages, includeDir))
|
||||
// {
|
||||
// info_log = std::string(shader.getInfoLog()) + std::string(shader.getInfoDebugLog());
|
||||
// }
|
||||
// // Add shader to new program object.
|
||||
// glslang::TProgram program;
|
||||
// program.addShader(&shader);
|
||||
|
||||
// Link program.
|
||||
if (!program.link(messages))
|
||||
{
|
||||
info_log = std::string(program.getInfoLog()) + std::string(program.getInfoDebugLog());
|
||||
}
|
||||
// // Link program.
|
||||
// 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());
|
||||
}
|
||||
// // 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());
|
||||
}
|
||||
// if (program.getInfoLog())
|
||||
// {
|
||||
// info_log += std::string(program.getInfoLog()) + std::string(program.getInfoDebugLog());
|
||||
// }
|
||||
|
||||
glslang::TIntermediate* intermediate = program.getIntermediate(type);
|
||||
if (!intermediate)
|
||||
{
|
||||
info_log += "Failed to get shared intermediate code.";
|
||||
}
|
||||
// glslang::TIntermediate* intermediate = program.getIntermediate(type);
|
||||
// if (!intermediate)
|
||||
// {
|
||||
// info_log += "Failed to get shared intermediate code.";
|
||||
// }
|
||||
|
||||
spv::SpvBuildLogger logger;
|
||||
std::vector<std::uint32_t> spirv;
|
||||
std::cout << info_log;
|
||||
glslang::GlslangToSpv(*intermediate, spirv, &logger);
|
||||
std::cout << logger.getAllMessages();
|
||||
glslang::FinalizeProcess();
|
||||
path.replace_extension("spirv");
|
||||
std::ofstream file(outputDir/path, std::ios::binary);
|
||||
file.write(reinterpret_cast<const char*>(spirv.data()), spirv.size() * sizeof(std::uint32_t));
|
||||
// spv::SpvBuildLogger logger;
|
||||
// std::vector<std::uint32_t> spirv;
|
||||
// std::cout << info_log;
|
||||
// glslang::GlslangToSpv(*intermediate, spirv, &logger);
|
||||
// std::cout << logger.getAllMessages();
|
||||
// glslang::FinalizeProcess();
|
||||
// path.replace_extension("spirv");
|
||||
// std::ofstream file(outputDir/path, std::ios::binary);
|
||||
// file.write(reinterpret_cast<const char*>(spirv.data()), spirv.size() * sizeof(std::uint32_t));
|
||||
}
|
||||
|
|
|
|||
2
build.sh
2
build.sh
|
|
@ -1,11 +1,11 @@
|
|||
mkdir build
|
||||
mkdir bin
|
||||
|
||||
clang++ -std=c++26 Crafter.Build-Shader.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Shader.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Dependency.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Dependency.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Configuration.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Configuration.pcm
|
||||
clang++ -std=c++26 Crafter.Build-ModuleFile.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-ModuleFile.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Project.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Project.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Shader.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Shader.pcm
|
||||
clang++ -std=c++26 Crafter.Build.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build.pcm
|
||||
|
||||
clang++ -std=c++26 Crafter.Build-Dependency.cpp -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Dependency_source.o
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue