diff --git a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp index be7ac186..b009ac08 100644 --- a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp +++ b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp @@ -494,6 +494,10 @@ namespace MG_Diligent { } MG_Util::Program::GenerateDefaultUBOForGLSL_Multi(shaderSourcesMap, programInfo.uniformBufferNames); + MG_Util::Debug::LogD("ConfigureResourceLayout: uniformBufferNames for %u:", programInfo.id); + for (auto& name: programInfo.uniformBufferNames) { + MG_Util::Debug::LogD(" %s", name.c_str()); + } for (auto shaderId : programInfo.AttachedShadersID) { auto shader = MG_Diligent::g_ShaderMap[shaderId]; diff --git a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp index c49f9884..0f30121a 100644 --- a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp +++ b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp @@ -268,6 +268,7 @@ namespace MG_GL::GL { auto* uboData = static_cast(mapped); for (auto& name: programInfo.uniformBufferNames) { + MG_Util::Debug::LogW("Attempting to update uniform '%s' for program %u", name.c_str(), program); auto& uniform = programObj.uniformValues[name]; if (IsSamplerType(uniform.type)) continue; @@ -330,6 +331,8 @@ namespace MG_GL::GL { break; } } + } else { + MG_Util::Debug::LogW("Cannot update uniform '%s' for program %u, offset not found", name.c_str(), program); } } MG_Util::Debug::LogD("Finished updating uniform values in UBO for program %u.", program); diff --git a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp index 72a2995a..c740d10e 100644 --- a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp +++ b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp @@ -303,6 +303,10 @@ namespace MG_GL::GL { } MG_Util::Program::GenerateDefaultUBOForGLSL_Multi(shaderSources, programInfo.uniformBufferNames); + MG_Util::Debug::LogD("LinkProgram: uniformBufferNames for %u:", program); + for (auto& name: programInfo.uniformBufferNames) { + MG_Util::Debug::LogD(" %s", name.c_str()); + } for (GLuint shaderId : programObj.attachedShaders) { auto it = MG_State_T::programState->shaders_.find(shaderId); @@ -374,6 +378,7 @@ namespace MG_GL::GL { if (MG_Diligent::g_ShaderMap.find(shaderId) == MG_Diligent::g_ShaderMap.end() || MG_Diligent::g_ShaderMap[shaderId] == nullptr) { GLenum shaderType = shaderObj.type; std::string sourceStr = finalShaderSources[shaderId]; + MG_Util::Program::RenameGLSLBuiltinsForVulkan(sourceStr); MG_Util::Debug::LogD("Shader ID: %u, type: %s\nConverted source:\n%s", shaderId, MG_Util::Debug::GLEnumToString(shaderType), sourceStr.c_str()); diff --git a/MG/MG_UTIL/Program/GLSLTool.cpp b/MG/MG_UTIL/Program/GLSLTool.cpp index beb44e09..576243e1 100644 --- a/MG/MG_UTIL/Program/GLSLTool.cpp +++ b/MG/MG_UTIL/Program/GLSLTool.cpp @@ -6,13 +6,22 @@ namespace MG_Util::Program { void RenameGLSLBuiltinsForVulkan(std::string &src) { - static const std::vector> rules = { - { std::regex(R"(gl_VertexID)"), "gl_VertexIndex" }, - { std::regex(R"(gl_InstanceID)"), "gl_InstanceIndex" } - }; +// static const std::vector> rules = { +// { std::regex(R"(gl_VertexID)"), "gl_VertexIndex" }, +// { std::regex(R"(gl_InstanceID)"), "gl_InstanceIndex" } +// }; +// +// for (auto &rule : rules) { +// src = std::regex_replace(src, rule.first, rule.second); +// } + size_t pos = src.find("gl_VertexID"); + if (pos != std::string::npos) { + src.replace(pos, strlen("gl_VertexID"), "gl_VertexIndex"); + } - for (auto &rule : rules) { - src = std::regex_replace(src, rule.first, rule.second); + pos = src.find("gl_InstanceID"); + if (pos != std::string::npos) { + src.replace(pos, strlen("gl_InstanceID"), "gl_InstanceIndex"); } } @@ -94,14 +103,13 @@ namespace MG_Util::Program { spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, 450); spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_FALSE); spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_FLIP_VERTEX_Y, SPVC_TRUE); - spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS, SPVC_TRUE); +// spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS, SPVC_TRUE); spvc_compiler_install_compiler_options(compiler, options); if ((result = spvc_compiler_compile(compiler, &glsl_source)) != SPVC_SUCCESS) { + MG_Util::Debug::LogD("[SPIRV-Cross] Failed to compile to GLSL at BindInputLayoutLocation: %s", spvc_context_get_last_error_string(context)); spvc_context_destroy(context); - MG_Util::Debug::LogE("[SPIRV-Cross] Failed to compile to GLSL: %s", - spvc_context_get_last_error_string(context)); return {}; } @@ -573,6 +581,8 @@ namespace MG_Util::Program { } uboBlock += "};\n"; + MG_Util::Debug::LogD("UBO Generated:\n%s", uboBlock.c_str()); + for (auto& [id, source] : shaderSources) { size_t insertPos = 0, lastDirectivePos = 0; size_t searchPos = 0;