mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[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:
@@ -422,26 +422,26 @@ GLuint ProgramState::GetCurrentProgram() const {
|
|||||||
return currentProgram_;
|
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);
|
MG_Util::Debug::LogD("MG_State: Program: GetShaderObject called, shader=%u", shader);
|
||||||
auto it = shaders_.find(shader);
|
auto it = shaders_.find(shader);
|
||||||
if (it == shaders_.end()) {
|
if (it == shaders_.end()) {
|
||||||
MG_Util::Debug::LogW("MG_State: Program: GetShaderObject warning: invalid shader id %u", shader);
|
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");
|
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);
|
MG_Util::Debug::LogD("MG_State: Program: GetProgramObject called, program=%u", program);
|
||||||
auto it = programs_.find(program);
|
auto it = programs_.find(program);
|
||||||
if (it == programs_.end()) {
|
if (it == programs_.end()) {
|
||||||
MG_Util::Debug::LogW("MG_State: Program: GetProgramObject warning: invalid program id %u", program);
|
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");
|
MG_Util::Debug::LogD("MG_State: Program: GetProgramObject success, returning object");
|
||||||
return it->second;
|
return &(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProgramState::ValidateProgram_(GLuint program) {
|
bool ProgramState::ValidateProgram_(GLuint program) {
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ public:
|
|||||||
DECLARE_MATRIX_FUNCTIONS(4x3, GL_FLOAT_MAT4x3)
|
DECLARE_MATRIX_FUNCTIONS(4x3, GL_FLOAT_MAT4x3)
|
||||||
#undef DECLARE_MATRIX_FUNCTIONS
|
#undef DECLARE_MATRIX_FUNCTIONS
|
||||||
|
|
||||||
ProgramObject GetProgramObject(GLuint program) const;
|
const ProgramObject* GetProgramObject(GLuint program) const;
|
||||||
ShaderObject GetShaderObject(GLuint program) const;
|
const ShaderObject* GetShaderObject(GLuint program) const;
|
||||||
GLuint GetCurrentProgram() const;
|
GLuint GetCurrentProgram() const;
|
||||||
bool SetProgramStatus(GLuint program, GLboolean status);
|
bool SetProgramStatus(GLuint program, GLboolean status);
|
||||||
bool SetShaderStatus(GLuint shader, GLboolean status);
|
bool SetShaderStatus(GLuint shader, GLboolean status);
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ namespace MG_Util::Program {
|
|||||||
if (MG_Global::Common::LogLevel > MG_Constants::Common::LOG_LEVEL_DEBUG)
|
if (MG_Global::Common::LogLevel > MG_Constants::Common::LOG_LEVEL_DEBUG)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto prog = (ProgramObject)state.GetProgramObject(program);
|
auto* prog = state.GetProgramObject(program);
|
||||||
if (!prog.linked.toBool()) {
|
if (!prog->linked.toBool()) {
|
||||||
MG_Util::Debug::LogE("Program %u not linked", program);
|
MG_Util::Debug::LogE("Program %u not linked", program);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MG_Util::Debug::LogD("=== Dumping uniforms for program %u ===", program);
|
MG_Util::Debug::LogD("=== Dumping uniforms for program %u ===", program);
|
||||||
for(const auto& [name, loc] : prog.uniformLocations) {
|
for(const auto& [name, loc] : prog->uniformLocations) {
|
||||||
const auto& value = prog.uniformValues.at(name);
|
const auto& value = prog->uniformValues.at(name);
|
||||||
MG_Util::Debug::LogD("Uniform: %-24s Location: %-4d Type: %-16s Count: %-3d Value: %s",
|
MG_Util::Debug::LogD("Uniform: %-24s Location: %-4d Type: %-16s Count: %-3d Value: %s",
|
||||||
name.c_str(),
|
name.c_str(),
|
||||||
loc,
|
loc,
|
||||||
|
|||||||
@@ -111,12 +111,8 @@ namespace MG_Util::Program {
|
|||||||
|
|
||||||
// TODO: Use other methods to implement clip space fixing.
|
// 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 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 (pos != std::string::npos) {
|
||||||
if (blur_pos != std::string::npos) {
|
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}");
|
||||||
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}");
|
|
||||||
}
|
}
|
||||||
return output_glsl;
|
return output_glsl;
|
||||||
}
|
}
|
||||||
@@ -645,12 +641,12 @@ namespace MG_Util::Program {
|
|||||||
std::vector<EShLanguage> usedShaderTypes;
|
std::vector<EShLanguage> usedShaderTypes;
|
||||||
TProgram program;
|
TProgram program;
|
||||||
for (GLuint shaderId : prog.attachedShaders) {
|
for (GLuint shaderId : prog.attachedShaders) {
|
||||||
auto shaderObject = state.GetShaderObject(shaderId);
|
auto* shaderObject = state.GetShaderObject(shaderId);
|
||||||
EShLanguage shLanguage = GetEShLanguageByShaderType(shaderObject.type);
|
EShLanguage shLanguage = GetEShLanguageByShaderType(shaderObject->type);
|
||||||
TShader* shader = nullptr;
|
TShader* shader = nullptr;
|
||||||
std::string infoLogOfShader = CompileGLSLToTShader(shaderObject.type, shaderObject.source, shader);
|
std::string infoLogOfShader = CompileGLSLToTShader(shaderObject->type, shaderObject->source, shader);
|
||||||
if (!infoLogOfShader.empty()) {
|
if (!infoLogOfShader.empty()) {
|
||||||
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderObject.type) +
|
infoLog = "Error: [glslang] Cannot compile " + GetShaderTypeName(shaderObject->type) +
|
||||||
" :\n" + infoLogOfShader;
|
" :\n" + infoLogOfShader;
|
||||||
return {};
|
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());
|
infoLog = "Error: [glslang] Cannot link the program of the single shader:\n" + std::to_string(program.getInfoLog());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
program.mapIO();
|
||||||
std::vector<unsigned> spirv;
|
std::vector<unsigned> spirv;
|
||||||
|
|
||||||
SpvOptions spvOptions;
|
SpvOptions spvOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user