[Fix] (MG/GLSLTool): Finally fixing blur shader!

- use glslang mapIO() function to correctly link shader in/out varyings
- no need to flip y (already using VK_KHR_maintenance1 to specify negative viewport height)
- use pointers to avoid unnecessary copying
This commit is contained in:
2025-06-24 16:33:16 +08:00
parent 20a945c6f0
commit 0c031d3e0b
4 changed files with 18 additions and 21 deletions
+6 -6
View File
@@ -422,26 +422,26 @@ GLuint ProgramState::GetCurrentProgram() const {
return currentProgram_;
}
ShaderObject ProgramState::GetShaderObject(GLuint shader) const {
const ShaderObject* ProgramState::GetShaderObject(GLuint shader) const {
MG_Util::Debug::LogD("MG_State: Program: GetShaderObject called, shader=%u", shader);
auto it = shaders_.find(shader);
if (it == shaders_.end()) {
MG_Util::Debug::LogW("MG_State: Program: GetShaderObject warning: invalid shader id %u", shader);
return ShaderObject();
return nullptr;
}
MG_Util::Debug::LogD("MG_State: Program: GetShaderObject success, returning object");
return it->second;
return &(it->second);
}
ProgramObject ProgramState::GetProgramObject(GLuint program) const {
const ProgramObject* ProgramState::GetProgramObject(GLuint program) const {
MG_Util::Debug::LogD("MG_State: Program: GetProgramObject called, program=%u", program);
auto it = programs_.find(program);
if (it == programs_.end()) {
MG_Util::Debug::LogW("MG_State: Program: GetProgramObject warning: invalid program id %u", program);
return ProgramObject();
return nullptr;
}
MG_Util::Debug::LogD("MG_State: Program: GetProgramObject success, returning object");
return it->second;
return &(it->second);
}
bool ProgramState::ValidateProgram_(GLuint program) {
+2 -2
View File
@@ -110,8 +110,8 @@ public:
DECLARE_MATRIX_FUNCTIONS(4x3, GL_FLOAT_MAT4x3)
#undef DECLARE_MATRIX_FUNCTIONS
ProgramObject GetProgramObject(GLuint program) const;
ShaderObject GetShaderObject(GLuint program) const;
const ProgramObject* GetProgramObject(GLuint program) const;
const ShaderObject* GetShaderObject(GLuint program) const;
GLuint GetCurrentProgram() const;
bool SetProgramStatus(GLuint program, GLboolean status);
bool SetShaderStatus(GLuint shader, GLboolean status);
+4 -4
View File
@@ -119,14 +119,14 @@ namespace MG_Util::Program {
if (MG_Global::Common::LogLevel > MG_Constants::Common::LOG_LEVEL_DEBUG)
return;
auto prog = (ProgramObject)state.GetProgramObject(program);
if (!prog.linked.toBool()) {
auto* prog = state.GetProgramObject(program);
if (!prog->linked.toBool()) {
MG_Util::Debug::LogE("Program %u not linked", program);
return;
}
MG_Util::Debug::LogD("=== Dumping uniforms for program %u ===", program);
for(const auto& [name, loc] : prog.uniformLocations) {
const auto& value = prog.uniformValues.at(name);
for(const auto& [name, loc] : prog->uniformLocations) {
const auto& value = prog->uniformValues.at(name);
MG_Util::Debug::LogD("Uniform: %-24s Location: %-4d Type: %-16s Count: %-3d Value: %s",
name.c_str(),
loc,
+6 -9
View File
@@ -111,12 +111,8 @@ namespace MG_Util::Program {
// TODO: Use other methods to implement clip space fixing.
size_t pos = output_glsl.find("\n gl_Position.y = -gl_Position.y;\n}");
size_t blur_pos = output_glsl.find("BlurDir"); // TODO: Fix this really hacky way of fixing blur shader...
if (pos != std::string::npos) {
if (blur_pos != std::string::npos) {
output_glsl.replace(pos, strlen("\n gl_Position.y = -gl_Position.y;\n}"), "\n}");
} else
output_glsl.replace(pos, strlen("\n gl_Position.y = -gl_Position.y;\n}"), "\n gl_Position.y = -gl_Position.y;\n gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n}");
output_glsl.replace(pos, strlen("\n gl_Position.y = -gl_Position.y;\n}"), "\n gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n}");
}
return output_glsl;
}
@@ -645,12 +641,12 @@ namespace MG_Util::Program {
std::vector<EShLanguage> usedShaderTypes;
TProgram program;
for (GLuint shaderId : prog.attachedShaders) {
auto shaderObject = state.GetShaderObject(shaderId);
EShLanguage shLanguage = GetEShLanguageByShaderType(shaderObject.type);
auto* shaderObject = state.GetShaderObject(shaderId);
EShLanguage shLanguage = GetEShLanguageByShaderType(shaderObject->type);
TShader* shader = nullptr;
std::string infoLogOfShader = CompileGLSLToTShader(shaderObject.type, shaderObject.source, shader);
std::string infoLogOfShader = CompileGLSLToTShader(shaderObject->type, shaderObject->source, shader);
if (!infoLogOfShader.empty()) {
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderObject.type) +
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderObject->type) +
" :\n" + infoLogOfShader;
return {};
}
@@ -691,6 +687,7 @@ namespace MG_Util::Program {
infoLog = "Error: [glslang] Cannot link the program of the single shader:\n" + std::to_string(program.getInfoLog());
return {};
}
program.mapIO();
std::vector<unsigned> spirv;
SpvOptions spvOptions;