mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 21:28:32 +09:00
[Fix] (MG_Util/Program): Allow GLSL For Vulkan to be converted into spirv.
This commit is contained in:
@@ -592,7 +592,8 @@ namespace MG_Util::Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CompileGLSLToTShader(GLenum shaderType, const std::string& source, glslang::TShader *&shader) {
|
std::string CompileGLSLToTShader(GLenum shaderType, const std::string& source,
|
||||||
|
glslang::TShader *&shader, bool isVkGLSL) {
|
||||||
std::string infoLog;
|
std::string infoLog;
|
||||||
using namespace glslang;
|
using namespace glslang;
|
||||||
|
|
||||||
@@ -609,7 +610,7 @@ namespace MG_Util::Program {
|
|||||||
const char *src = source.c_str();
|
const char *src = source.c_str();
|
||||||
shader->setStrings(&src, 1);
|
shader->setStrings(&src, 1);
|
||||||
shader->setEnvInput(EShSourceGlsl, language, EShClientVulkan, glslVersion);
|
shader->setEnvInput(EShSourceGlsl, language, EShClientVulkan, glslVersion);
|
||||||
shader->setEnvClient(EShClientOpenGL, EShTargetOpenGL_450);
|
shader->setEnvClient(EShClientOpenGL, isVkGLSL ? EShTargetVulkan_1_3 : EShTargetOpenGL_450);
|
||||||
shader->setEnvTarget(EShTargetSpv, EShTargetSpv_1_6);
|
shader->setEnvTarget(EShTargetSpv, EShTargetSpv_1_6);
|
||||||
shader->setAutoMapLocations(true);
|
shader->setAutoMapLocations(true);
|
||||||
shader->setAutoMapBindings(true);
|
shader->setAutoMapBindings(true);
|
||||||
@@ -617,7 +618,7 @@ namespace MG_Util::Program {
|
|||||||
// Is InitResources() really correct?
|
// Is InitResources() really correct?
|
||||||
TBuiltInResource resources = InitResources();
|
TBuiltInResource resources = InitResources();
|
||||||
|
|
||||||
if (!shader->parse(&resources, glslVersion, true, EShMsgDefault)) {
|
if (!shader->parse(&resources, glslVersion, true, isVkGLSL ? EShMsgVulkanRules : EShMsgDefault)) {
|
||||||
infoLog += "Error: [glslang] Cannot compile the " + GetShaderTypeName(shaderType) + ":\n"
|
infoLog += "Error: [glslang] Cannot compile the " + GetShaderTypeName(shaderType) + ":\n"
|
||||||
+ std::to_string(shader->getInfoLog());
|
+ std::to_string(shader->getInfoLog());
|
||||||
return infoLog;
|
return infoLog;
|
||||||
@@ -662,18 +663,19 @@ namespace MG_Util::Program {
|
|||||||
return allSpirv;
|
return allSpirv;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned> CompileGLSLToSPIRV(GLenum shaderType, const std::string &source, std::string &infoLog) {
|
std::vector<unsigned> CompileGLSLToSPIRV(GLenum shaderType, const std::string &source,
|
||||||
|
std::string &infoLog, bool isVkGLSL) {
|
||||||
using namespace glslang;
|
using namespace glslang;
|
||||||
|
|
||||||
TShader* shader = nullptr;
|
TShader* shader = nullptr;
|
||||||
std::string infoLogOfShader = CompileGLSLToTShader(shaderType, source, shader);
|
std::string infoLogOfShader = CompileGLSLToTShader(shaderType, source, shader, isVkGLSL);
|
||||||
if (!infoLogOfShader.empty()) {
|
if (!infoLogOfShader.empty()) {
|
||||||
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderType) + ":\n" + infoLogOfShader;
|
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderType) + ":\n" + infoLogOfShader;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
TProgram program;
|
TProgram program;
|
||||||
program.addShader(shader);
|
program.addShader(shader);
|
||||||
if (!program.link(EShMsgDefault)) {
|
if (!program.link(isVkGLSL ? EShMsgVulkanRules : EShMsgDefault)) {
|
||||||
infoLog = "Error: [glslang] Cannot link the program of the single shader:\n" + std::to_string(program.getInfoLog());
|
infoLog = "Error: [glslang] Cannot link the program of the single shader:\n" + std::to_string(program.getInfoLog());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,8 +173,10 @@ namespace MG_Util::Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned> CompileGLSLToSPIRV(GLenum shaderType, const std::string& source, std::string& infoLog);
|
std::vector<unsigned> CompileGLSLToSPIRV(GLenum shaderType, const std::string& source,
|
||||||
std::string CompileGLSLToTShader(GLenum shaderType, const std::string& source, glslang::TShader *&shader);
|
std::string& infoLog, bool isVkGLSL = false);
|
||||||
|
std::string CompileGLSLToTShader(GLenum shaderType, const std::string& source,
|
||||||
|
glslang::TShader *&shader, bool isVkGLSL = false);
|
||||||
std::vector<std::vector<unsigned>> CompileMultipleShadersToSPIRV(const ProgramState& state, ProgramObject& prog, std::string& infoLog);
|
std::vector<std::vector<unsigned>> CompileMultipleShadersToSPIRV(const ProgramState& state, ProgramObject& prog, std::string& infoLog);
|
||||||
void ReflectSPIRVUniforms(const std::vector<std::vector<unsigned>>& allSpirv, ProgramObject& prog, std::string& infoLog);
|
void ReflectSPIRVUniforms(const std::vector<std::vector<unsigned>>& allSpirv, ProgramObject& prog, std::string& infoLog);
|
||||||
std::string CompileSPIRVToGLSL(std::vector<unsigned int> spirv, uint glslVersion, bool isES);
|
std::string CompileSPIRVToGLSL(std::vector<unsigned int> spirv, uint glslVersion, bool isES);
|
||||||
|
|||||||
Reference in New Issue
Block a user