Last active
August 19, 2025 18:49
-
-
Save Pikachuxxxx/20825d1dff8b24f663ff9972c1b5dc9b to your computer and use it in GitHub Desktop.
Razix RHI C macro magic for clean Jumptables based API and support C++ style with profiling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Why I love C and Jumptables: | |
| #define rzRHI_DestroyDescriptorHeap g_RHI.DestroyDescriptorHeap | |
| #define rzRHI_CreateDescriptorTable g_RHI.CreateDescriptorTable | |
| #define rzRHI_DestroyDescriptorTable g_RHI.DestroyDescriptorTable | |
| #if !RZ_PROFILER_ENABLED | |
| #if defined(RAZIX_RHI_USE_RESOURCE_MANAGER_HANDLES) && defined(__cplusplus) | |
| #define rzRHI_BeginCmdBuf(cb) g_RHI.BeginCmdBuf(RZResourceManager::Get().getCommandBufferResource(cb)) | |
| #define rzRHI_EndCmdBuf(cb) g_RHI.EndCmdBuf(RZResourceManager::Get().getCommandBufferResource(cb)) | |
| #else | |
| #define rzRHI_BeginCmdBuf g_RHI.BeginCmdBuf | |
| #define rzRHI_EndCmdBuf g_RHI.EndCmdBuf | |
| #else | |
| #if defined(RAZIX_RHI_USE_RESOURCE_MANAGER_HANDLES) && defined(__cplusplus) | |
| #define rzRHI_BeginCmdBuf(cb) \ | |
| do { \ | |
| RAZIX_PROFILE_SCOPEC("rzRHI_BeginCmdBuf", RZ_PROFILE_COLOR_RHI_COMMAND_BUFFERS); \ | |
| g_RHI.BeginCmdBuf(RZResourceManager::Get().getCommandBufferResource(cb)); \ | |
| } while (0) | |
| #define rzRHI_EndCmdBuf(cb) \ | |
| do { \ | |
| RAZIX_PROFILE_SCOPEC("rzRHI_EndCmdBuf", RZ_PROFILE_COLOR_RHI_COMMAND_BUFFERS); \ | |
| g_RHI.EndCmdBuf(RZResourceManager::Get().getCommandBufferResource(cb)); \ | |
| } while (0) | |
| #endif | |
| #else | |
| // C mode or direct handles mode with profiling support where available | |
| #define rzRHI_BeginCmdBuf(cb) \ | |
| do { \ | |
| RAZIX_PROFILE_SCOPEC("rzRHI_BeginCmdBuf", RZ_PROFILE_COLOR_RHI_COMMAND_BUFFERS); \ | |
| g_RHI.BeginCmdBuf(cb); \ | |
| RAZIX_PROFILE_SCOPEC_END(); \ | |
| } while (0) | |
| #define rzRHI_EndCmdBuf(cb) \ | |
| do { \ | |
| RAZIX_PROFILE_SCOPEC("rzRHI_EndCmdBuf", RZ_PROFILE_COLOR_RHI_COMMAND_BUFFERS); \ | |
| g_RHI.EndCmdBuf(cb); \ | |
| RAZIX_PROFILE_SCOPEC_END(); \ | |
| } while (0) | |
| #endif // defined(RAZIX_RHI_USE_RESOURCE_MANAGER_HANDLES) && defined(__cplusplus) | |
| #endif // !defined(RZ_PROFILER_ENABLED) | |
| // Macro magic to the rescue! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment