From 5c58146a95a30774a7801ebf23327201bdc4e89f Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 15 Aug 2018 16:28:40 +0100 Subject: [PATCH] Try to protect against crashes if injecting into a GL program on windows * As the large red warning says, this still won't work, but at least it shouldn't crash. --- renderdoc/driver/gl/gen_dispatch_table.py | 2 ++ renderdoc/driver/gl/gl_dispatch_table.h | 8 +++++ renderdoc/driver/gl/gl_dispatch_table_defs.h | 36 ++++++++++++++++++++ renderdoc/driver/gl/gl_hooks.cpp | 29 ++++++++++++++-- renderdoc/driver/gl/wgl_hooks.cpp | 7 ++-- 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/renderdoc/driver/gl/gen_dispatch_table.py b/renderdoc/driver/gl/gen_dispatch_table.py index b445fa5d7..0afe53c5d 100644 --- a/renderdoc/driver/gl/gen_dispatch_table.py +++ b/renderdoc/driver/gl/gen_dispatch_table.py @@ -221,6 +221,7 @@ template = ''' ret HOOK_CC CONCAT(function, _renderdoc_hooked)({argdecl}) \\ {{ \\ SCOPED_GLCALL(function); \\ + UNINIT_CALL(function, {argpass}); \\ return glhook.driver->function({argpass}); \\ }} \\ HOOK_EXPORT ret HOOK_CC function({argdecl}) \\ @@ -232,6 +233,7 @@ template = ''' ret HOOK_CC CONCAT(function, _renderdoc_hooked)({argdecl}) \\ {{ \\ SCOPED_GLCALL(function); \\ + UNINIT_CALL(realfunc, {argpass}); \\ return glhook.driver->realfunc({argpass}); \\ }} \\ HOOK_EXPORT ret HOOK_CC function({argdecl}) \\ diff --git a/renderdoc/driver/gl/gl_dispatch_table.h b/renderdoc/driver/gl/gl_dispatch_table.h index 62258b463..8da99fd91 100644 --- a/renderdoc/driver/gl/gl_dispatch_table.h +++ b/renderdoc/driver/gl/gl_dispatch_table.h @@ -962,6 +962,14 @@ class WrappedOpenGL; // wgl or glX and EGL together in the same application. void SetDriverForHooks(WrappedOpenGL *driver); +// On windows we support injecting into the program at runtime, so we need to only enable hooks when +// we see context creation, to prevent crashes trying to handle function calls having seen no +// intialisation. This can have false positives if the program creates a context late, but it's the +// best we can do. +#if ENABLED(RDOC_WIN32) +void EnableHooks(); +#endif + // this function looks up our list of hook entry points and returns our hook entry point instead of // the real function, if it exists, or the real function if not. It's used in the platform-specific // implementations of GetProcAddress to look up the shared list of hooks. diff --git a/renderdoc/driver/gl/gl_dispatch_table_defs.h b/renderdoc/driver/gl/gl_dispatch_table_defs.h index 7251ffe24..bf2439496 100644 --- a/renderdoc/driver/gl/gl_dispatch_table_defs.h +++ b/renderdoc/driver/gl/gl_dispatch_table_defs.h @@ -6389,6 +6389,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)() \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, ); \ return glhook.driver->function(); \ } \ HOOK_EXPORT ret HOOK_CC function() \ @@ -6400,6 +6401,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)() \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, ); \ return glhook.driver->realfunc(); \ } \ HOOK_EXPORT ret HOOK_CC function() \ @@ -6433,6 +6435,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1); \ return glhook.driver->function(p1); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1) \ @@ -6444,6 +6447,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1); \ return glhook.driver->realfunc(p1); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1) \ @@ -6477,6 +6481,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2); \ return glhook.driver->function(p1, p2); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2) \ @@ -6488,6 +6493,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2); \ return glhook.driver->realfunc(p1, p2); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2) \ @@ -6521,6 +6527,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3); \ return glhook.driver->function(p1, p2, p3); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3) \ @@ -6532,6 +6539,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3); \ return glhook.driver->realfunc(p1, p2, p3); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3) \ @@ -6565,6 +6573,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4); \ return glhook.driver->function(p1, p2, p3, p4); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4) \ @@ -6576,6 +6585,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4); \ return glhook.driver->realfunc(p1, p2, p3, p4); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4) \ @@ -6609,6 +6619,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5); \ return glhook.driver->function(p1, p2, p3, p4, p5); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5) \ @@ -6620,6 +6631,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5) \ @@ -6653,6 +6665,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6) \ @@ -6664,6 +6677,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6) \ @@ -6697,6 +6711,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7) \ @@ -6708,6 +6723,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7) \ @@ -6741,6 +6757,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8) \ @@ -6752,6 +6769,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8) \ @@ -6785,6 +6803,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9) \ @@ -6796,6 +6815,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9) \ @@ -6829,6 +6849,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10) \ @@ -6840,6 +6861,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10) \ @@ -6873,6 +6895,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11) \ @@ -6884,6 +6907,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11) \ @@ -6917,6 +6941,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12) \ @@ -6928,6 +6953,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12) \ @@ -6961,6 +6987,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13) \ @@ -6972,6 +6999,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13) \ @@ -7005,6 +7033,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14) \ @@ -7016,6 +7045,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14) \ @@ -7049,6 +7079,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15) \ @@ -7060,6 +7091,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15) \ @@ -7093,6 +7125,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16) \ @@ -7104,6 +7137,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16) \ @@ -7137,6 +7171,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16, t17 p17) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(function, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17); \ return glhook.driver->function(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16, t17 p17) \ @@ -7148,6 +7183,7 @@ ret HOOK_CC CONCAT(function, _renderdoc_hooked)(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16, t17 p17) \ { \ SCOPED_GLCALL(function); \ + UNINIT_CALL(realfunc, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17); \ return glhook.driver->realfunc(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17); \ } \ HOOK_EXPORT ret HOOK_CC function(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11, t12 p12, t13 p13, t14 p14, t15 p15, t16 p16, t17 p17) \ diff --git a/renderdoc/driver/gl/gl_hooks.cpp b/renderdoc/driver/gl/gl_hooks.cpp index 1e1c43603..c51daeacb 100644 --- a/renderdoc/driver/gl/gl_hooks.cpp +++ b/renderdoc/driver/gl/gl_hooks.cpp @@ -58,6 +58,7 @@ public: void *handle = NULL; WrappedOpenGL *driver = NULL; + bool enabled = false; } glhook; #if ENABLED(RDOC_DEVEL) @@ -98,14 +99,36 @@ int ScopedPrinter::depth = 0; #endif -DefineSupportedHooks(); -DefineUnsupportedHooks(); - void SetDriverForHooks(WrappedOpenGL *driver) { glhook.driver = driver; } +#if ENABLED(RDOC_WIN32) +void EnableHooks() +{ + glhook.enabled = true; +} + +// if we were injected and aren't ready to capture, skip out and call the real function +#define UNINIT_CALL(function, ...) \ + if(!glhook.enabled) \ + { \ + if(GL.function == NULL) \ + RDCERR("No function pointer for '%s' while uninitialised!", STRINGIZE(function)); \ + return GL.function(__VA_ARGS__); \ + } + +#else + +// nothing to do - we always assume we are ready to capture +#define UNINIT_CALL(function, ...) + +#endif + +DefineSupportedHooks(); +DefineUnsupportedHooks(); + void *HookedGetProcAddress(const char *func, void *realFunc) { #define CheckFunction(function, name) \ diff --git a/renderdoc/driver/gl/wgl_hooks.cpp b/renderdoc/driver/gl/wgl_hooks.cpp index 51ab1b799..4f60d895e 100644 --- a/renderdoc/driver/gl/wgl_hooks.cpp +++ b/renderdoc/driver/gl/wgl_hooks.cpp @@ -54,6 +54,9 @@ public: void WGLHook::PopulateFromContext(HDC dc, HGLRC rc) { + SetDriverForHooks(&driver); + EnableHooks(); + // called from wglCreate*Context*, to populate GL functions as soon as possible by making a new // context current and fetching our function pointers { @@ -169,8 +172,6 @@ static HGLRC WINAPI wglCreateContext_hooked(HDC dc) { DWORD err = GetLastError(); - SetDriverForHooks(&wglhook.driver); - wglhook.PopulateFromContext(dc, ret); GLWindowingData data; @@ -326,8 +327,6 @@ static HGLRC WINAPI wglCreateContextAttribsARB_hooked(HDC dc, HGLRC hShareContex return ret; } - SetDriverForHooks(&wglhook.driver); - wglhook.PopulateFromContext(dc, ret); GLWindowingData data;