diff --git a/src/main/cpp/gl/drawing.cpp b/src/main/cpp/gl/drawing.cpp index f76529f..b1c54b9 100644 --- a/src/main/cpp/gl/drawing.cpp +++ b/src/main/cpp/gl/drawing.cpp @@ -182,6 +182,7 @@ void glMultiDrawElements(GLenum mode, const GLsizei* count, GLenum type, const v //_Thread_local static bool unexpected_error = false; void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) { + LOG() LOG_D("glDrawElements, mode: %d, count: %d, type: %d, indices: %p", mode, count, type, indices) //LOAD_GLES_FUNC(glGetError) //GLenum pre_err = GLES.glGetError(); @@ -199,6 +200,8 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices } void glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format) { + + LOG() LOG_D("glBindImageTexture, unit: %d, texture: %d, level: %d, layered: %d, layer: %d, access: %d, format: %d", unit, texture, level, layered, layer, access, format) //LOAD_GLES_FUNC(glGetError) @@ -212,6 +215,7 @@ void glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean laye } void glUniform1i(GLint location, GLint v0) { + LOG() LOG_D("glUniform1i, location: %d, v0: %d", location, v0) //LOAD_GLES_FUNC(glGetError) GLES.glUniform1i(location, v0); @@ -224,6 +228,7 @@ void glUniform1i(GLint location, GLint v0) { } void glDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z) { + LOG() LOG_D("glDispatchCompute, num_groups_x: %d, num_groups_y: %d, num_groups_z: %d", num_groups_x, num_groups_y, num_groups_z) //LOAD_GLES_FUNC(glGetError) diff --git a/src/main/cpp/gl/log.cpp b/src/main/cpp/gl/log.cpp index 4c6b867..34bfb09 100644 --- a/src/main/cpp/gl/log.cpp +++ b/src/main/cpp/gl/log.cpp @@ -1,7 +1,12 @@ // // Created by BZLZHH on 2025/1/26. // + #include "log.h" +#include +#include +#include +#include #include "gl.h" @@ -1085,4 +1090,30 @@ const char* glEnumToString(GLenum e) { sprintf(str, "0x%x", e); return str; } -} \ No newline at end of file +} + +#if LOG_CALLED_FUNCS + +void log_unique_function(const char* func_name) { + if (!func_name || strlen(func_name) < 2 || strncmp(func_name, "gl", 2) != 0) { + return; + } + static std::unordered_set logged_functions; + static std::mutex log_mutex; + std::string func_str(func_name); + + std::lock_guard guard(log_mutex); + + if (logged_functions.find(func_str) != logged_functions.end()) { + return; + } + + static FILE* fp = fopen("/sdcard/MG/glcalls.txt", "a"); + if (fp) { + fprintf(fp, "%s\n", func_name); + fflush(fp); + } + + logged_functions.insert(func_str); +} +#endif \ No newline at end of file diff --git a/src/main/cpp/gl/log.h b/src/main/cpp/gl/log.h index 7e5fcb7..8f8b12f 100644 --- a/src/main/cpp/gl/log.h +++ b/src/main/cpp/gl/log.h @@ -10,6 +10,8 @@ #define GLOBAL_DEBUG 0 +#define LOG_CALLED_FUNCS 0 + #ifdef __cplusplus extern "C" { #endif @@ -31,6 +33,15 @@ const char *glEnumToString(GLenum e); #define LOG() \ perfetto::StaticString _FUNC_NAME_ = __func__; \ TRACE_EVENT("glcalls", _FUNC_NAME_); +#elif LOG_CALLED_FUNCS +#define LOG() \ + if(DEBUG||GLOBAL_DEBUG) { \ + __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, "Use function: %s", __FUNCTION__); \ + printf("Use function: %s\n", __FUNCTION__); \ + write_log("Use function: %s\n", __FUNCTION__); \ + } \ + log_unique_function(__FUNCTION__); +void log_unique_function(const char* func_name); #else #define LOG() \ if(DEBUG||GLOBAL_DEBUG) {__android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, "Use function: %s", __FUNCTION__);printf("Use function: %s\n", __FUNCTION__);write_log("Use function: %s\n", __FUNCTION__);} diff --git a/src/main/cpp/gles/loader.h b/src/main/cpp/gles/loader.h index b05cf41..e00d733 100644 --- a/src/main/cpp/gles/loader.h +++ b/src/main/cpp/gles/loader.h @@ -89,7 +89,8 @@ static name##_PTR egl_##name = NULL; \ #define NATIVE_FUNCTION_HEAD(type,name,...) \ extern "C" GLAPI GLAPIENTRY type name##ARB(__VA_ARGS__) __attribute__((alias(#name))); \ -extern "C" GLAPI GLAPIENTRY type name(__VA_ARGS__) { +extern "C" GLAPI GLAPIENTRY type name(__VA_ARGS__) { \ + LOG() #if GLOBAL_DEBUG #define NATIVE_FUNCTION_END(type,name,...) \ @@ -123,7 +124,8 @@ extern "C" GLAPI GLAPIENTRY type name(__VA_ARGS__) { #endif #define STUB_FUNCTION_HEAD(type,name,...) \ -extern "C" GLAPI GLAPIENTRY type name(__VA_ARGS__) { +extern "C" GLAPI GLAPIENTRY type name(__VA_ARGS__) { \ + LOG() #define STUB_FUNCTION_END(type,name,...) \ LOG_W("Stub function: %s @ %s(...)", RENDERERNAME, __FUNCTION__); \