├── .gitignore ├── IconsFontAwesome4.h ├── ImGui ├── LICENSE.txt ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui.ini ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_dx12.cpp ├── imgui_impl_dx12.h ├── imgui_impl_win32.cpp ├── imgui_impl_win32.h ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h ├── ImGuiProfiler.sln ├── ImGuiProfiler.vcxproj ├── ImGuiProfiler.vcxproj.filters ├── ImGuiProfiler.vcxproj.user ├── Image.jpg ├── LICENSE ├── Profiler.cpp ├── Profiler.h ├── ProfilerWindow.cpp ├── README.md ├── fontawesome-webfont.ttf ├── imgui.ini └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | x64 3 | -------------------------------------------------------------------------------- /IconsFontAwesome4.h: -------------------------------------------------------------------------------- 1 | // Generated by https://github.com/juliettef/IconFontCppHeaders script GenerateIconFontCppHeaders.py for languages C and C++ 2 | // from https://github.com/FortAwesome/Font-Awesome/raw/4.x/src/icons.yml 3 | // for use with https://github.com/FortAwesome/Font-Awesome/blob/4.x/fonts/fontawesome-webfont.ttf 4 | #pragma once 5 | 6 | #define FONT_ICON_FILE_NAME_FA "fontawesome-webfont.ttf" 7 | 8 | #define ICON_MIN_FA 0xf000 9 | #define ICON_MAX_16_FA 0xf2e0 10 | #define ICON_MAX_FA 0xf2e0 11 | #define ICON_FA_GLASS "\xef\x80\x80" // U+f000 12 | #define ICON_FA_MUSIC "\xef\x80\x81" // U+f001 13 | #define ICON_FA_SEARCH "\xef\x80\x82" // U+f002 14 | #define ICON_FA_ENVELOPE_O "\xef\x80\x83" // U+f003 15 | #define ICON_FA_HEART "\xef\x80\x84" // U+f004 16 | #define ICON_FA_STAR "\xef\x80\x85" // U+f005 17 | #define ICON_FA_STAR_O "\xef\x80\x86" // U+f006 18 | #define ICON_FA_USER "\xef\x80\x87" // U+f007 19 | #define ICON_FA_FILM "\xef\x80\x88" // U+f008 20 | #define ICON_FA_TH_LARGE "\xef\x80\x89" // U+f009 21 | #define ICON_FA_TH "\xef\x80\x8a" // U+f00a 22 | #define ICON_FA_TH_LIST "\xef\x80\x8b" // U+f00b 23 | #define ICON_FA_CHECK "\xef\x80\x8c" // U+f00c 24 | #define ICON_FA_TIMES "\xef\x80\x8d" // U+f00d 25 | #define ICON_FA_SEARCH_PLUS "\xef\x80\x8e" // U+f00e 26 | #define ICON_FA_SEARCH_MINUS "\xef\x80\x90" // U+f010 27 | #define ICON_FA_POWER_OFF "\xef\x80\x91" // U+f011 28 | #define ICON_FA_SIGNAL "\xef\x80\x92" // U+f012 29 | #define ICON_FA_COG "\xef\x80\x93" // U+f013 30 | #define ICON_FA_TRASH_O "\xef\x80\x94" // U+f014 31 | #define ICON_FA_HOME "\xef\x80\x95" // U+f015 32 | #define ICON_FA_FILE_O "\xef\x80\x96" // U+f016 33 | #define ICON_FA_CLOCK_O "\xef\x80\x97" // U+f017 34 | #define ICON_FA_ROAD "\xef\x80\x98" // U+f018 35 | #define ICON_FA_DOWNLOAD "\xef\x80\x99" // U+f019 36 | #define ICON_FA_ARROW_CIRCLE_O_DOWN "\xef\x80\x9a" // U+f01a 37 | #define ICON_FA_ARROW_CIRCLE_O_UP "\xef\x80\x9b" // U+f01b 38 | #define ICON_FA_INBOX "\xef\x80\x9c" // U+f01c 39 | #define ICON_FA_PLAY_CIRCLE_O "\xef\x80\x9d" // U+f01d 40 | #define ICON_FA_REPEAT "\xef\x80\x9e" // U+f01e 41 | #define ICON_FA_REFRESH "\xef\x80\xa1" // U+f021 42 | #define ICON_FA_LIST_ALT "\xef\x80\xa2" // U+f022 43 | #define ICON_FA_LOCK "\xef\x80\xa3" // U+f023 44 | #define ICON_FA_FLAG "\xef\x80\xa4" // U+f024 45 | #define ICON_FA_HEADPHONES "\xef\x80\xa5" // U+f025 46 | #define ICON_FA_VOLUME_OFF "\xef\x80\xa6" // U+f026 47 | #define ICON_FA_VOLUME_DOWN "\xef\x80\xa7" // U+f027 48 | #define ICON_FA_VOLUME_UP "\xef\x80\xa8" // U+f028 49 | #define ICON_FA_QRCODE "\xef\x80\xa9" // U+f029 50 | #define ICON_FA_BARCODE "\xef\x80\xaa" // U+f02a 51 | #define ICON_FA_TAG "\xef\x80\xab" // U+f02b 52 | #define ICON_FA_TAGS "\xef\x80\xac" // U+f02c 53 | #define ICON_FA_BOOK "\xef\x80\xad" // U+f02d 54 | #define ICON_FA_BOOKMARK "\xef\x80\xae" // U+f02e 55 | #define ICON_FA_PRINT "\xef\x80\xaf" // U+f02f 56 | #define ICON_FA_CAMERA "\xef\x80\xb0" // U+f030 57 | #define ICON_FA_FONT "\xef\x80\xb1" // U+f031 58 | #define ICON_FA_BOLD "\xef\x80\xb2" // U+f032 59 | #define ICON_FA_ITALIC "\xef\x80\xb3" // U+f033 60 | #define ICON_FA_TEXT_HEIGHT "\xef\x80\xb4" // U+f034 61 | #define ICON_FA_TEXT_WIDTH "\xef\x80\xb5" // U+f035 62 | #define ICON_FA_ALIGN_LEFT "\xef\x80\xb6" // U+f036 63 | #define ICON_FA_ALIGN_CENTER "\xef\x80\xb7" // U+f037 64 | #define ICON_FA_ALIGN_RIGHT "\xef\x80\xb8" // U+f038 65 | #define ICON_FA_ALIGN_JUSTIFY "\xef\x80\xb9" // U+f039 66 | #define ICON_FA_LIST "\xef\x80\xba" // U+f03a 67 | #define ICON_FA_OUTDENT "\xef\x80\xbb" // U+f03b 68 | #define ICON_FA_INDENT "\xef\x80\xbc" // U+f03c 69 | #define ICON_FA_VIDEO_CAMERA "\xef\x80\xbd" // U+f03d 70 | #define ICON_FA_PICTURE_O "\xef\x80\xbe" // U+f03e 71 | #define ICON_FA_PENCIL "\xef\x81\x80" // U+f040 72 | #define ICON_FA_MAP_MARKER "\xef\x81\x81" // U+f041 73 | #define ICON_FA_ADJUST "\xef\x81\x82" // U+f042 74 | #define ICON_FA_TINT "\xef\x81\x83" // U+f043 75 | #define ICON_FA_PENCIL_SQUARE_O "\xef\x81\x84" // U+f044 76 | #define ICON_FA_SHARE_SQUARE_O "\xef\x81\x85" // U+f045 77 | #define ICON_FA_CHECK_SQUARE_O "\xef\x81\x86" // U+f046 78 | #define ICON_FA_ARROWS "\xef\x81\x87" // U+f047 79 | #define ICON_FA_STEP_BACKWARD "\xef\x81\x88" // U+f048 80 | #define ICON_FA_FAST_BACKWARD "\xef\x81\x89" // U+f049 81 | #define ICON_FA_BACKWARD "\xef\x81\x8a" // U+f04a 82 | #define ICON_FA_PLAY "\xef\x81\x8b" // U+f04b 83 | #define ICON_FA_PAUSE "\xef\x81\x8c" // U+f04c 84 | #define ICON_FA_STOP "\xef\x81\x8d" // U+f04d 85 | #define ICON_FA_FORWARD "\xef\x81\x8e" // U+f04e 86 | #define ICON_FA_FAST_FORWARD "\xef\x81\x90" // U+f050 87 | #define ICON_FA_STEP_FORWARD "\xef\x81\x91" // U+f051 88 | #define ICON_FA_EJECT "\xef\x81\x92" // U+f052 89 | #define ICON_FA_CHEVRON_LEFT "\xef\x81\x93" // U+f053 90 | #define ICON_FA_CHEVRON_RIGHT "\xef\x81\x94" // U+f054 91 | #define ICON_FA_PLUS_CIRCLE "\xef\x81\x95" // U+f055 92 | #define ICON_FA_MINUS_CIRCLE "\xef\x81\x96" // U+f056 93 | #define ICON_FA_TIMES_CIRCLE "\xef\x81\x97" // U+f057 94 | #define ICON_FA_CHECK_CIRCLE "\xef\x81\x98" // U+f058 95 | #define ICON_FA_QUESTION_CIRCLE "\xef\x81\x99" // U+f059 96 | #define ICON_FA_INFO_CIRCLE "\xef\x81\x9a" // U+f05a 97 | #define ICON_FA_CROSSHAIRS "\xef\x81\x9b" // U+f05b 98 | #define ICON_FA_TIMES_CIRCLE_O "\xef\x81\x9c" // U+f05c 99 | #define ICON_FA_CHECK_CIRCLE_O "\xef\x81\x9d" // U+f05d 100 | #define ICON_FA_BAN "\xef\x81\x9e" // U+f05e 101 | #define ICON_FA_ARROW_LEFT "\xef\x81\xa0" // U+f060 102 | #define ICON_FA_ARROW_RIGHT "\xef\x81\xa1" // U+f061 103 | #define ICON_FA_ARROW_UP "\xef\x81\xa2" // U+f062 104 | #define ICON_FA_ARROW_DOWN "\xef\x81\xa3" // U+f063 105 | #define ICON_FA_SHARE "\xef\x81\xa4" // U+f064 106 | #define ICON_FA_EXPAND "\xef\x81\xa5" // U+f065 107 | #define ICON_FA_COMPRESS "\xef\x81\xa6" // U+f066 108 | #define ICON_FA_PLUS "\xef\x81\xa7" // U+f067 109 | #define ICON_FA_MINUS "\xef\x81\xa8" // U+f068 110 | #define ICON_FA_ASTERISK "\xef\x81\xa9" // U+f069 111 | #define ICON_FA_EXCLAMATION_CIRCLE "\xef\x81\xaa" // U+f06a 112 | #define ICON_FA_GIFT "\xef\x81\xab" // U+f06b 113 | #define ICON_FA_LEAF "\xef\x81\xac" // U+f06c 114 | #define ICON_FA_FIRE "\xef\x81\xad" // U+f06d 115 | #define ICON_FA_EYE "\xef\x81\xae" // U+f06e 116 | #define ICON_FA_EYE_SLASH "\xef\x81\xb0" // U+f070 117 | #define ICON_FA_EXCLAMATION_TRIANGLE "\xef\x81\xb1" // U+f071 118 | #define ICON_FA_PLANE "\xef\x81\xb2" // U+f072 119 | #define ICON_FA_CALENDAR "\xef\x81\xb3" // U+f073 120 | #define ICON_FA_RANDOM "\xef\x81\xb4" // U+f074 121 | #define ICON_FA_COMMENT "\xef\x81\xb5" // U+f075 122 | #define ICON_FA_MAGNET "\xef\x81\xb6" // U+f076 123 | #define ICON_FA_CHEVRON_UP "\xef\x81\xb7" // U+f077 124 | #define ICON_FA_CHEVRON_DOWN "\xef\x81\xb8" // U+f078 125 | #define ICON_FA_RETWEET "\xef\x81\xb9" // U+f079 126 | #define ICON_FA_SHOPPING_CART "\xef\x81\xba" // U+f07a 127 | #define ICON_FA_FOLDER "\xef\x81\xbb" // U+f07b 128 | #define ICON_FA_FOLDER_OPEN "\xef\x81\xbc" // U+f07c 129 | #define ICON_FA_ARROWS_V "\xef\x81\xbd" // U+f07d 130 | #define ICON_FA_ARROWS_H "\xef\x81\xbe" // U+f07e 131 | #define ICON_FA_BAR_CHART "\xef\x82\x80" // U+f080 132 | #define ICON_FA_TWITTER_SQUARE "\xef\x82\x81" // U+f081 133 | #define ICON_FA_FACEBOOK_SQUARE "\xef\x82\x82" // U+f082 134 | #define ICON_FA_CAMERA_RETRO "\xef\x82\x83" // U+f083 135 | #define ICON_FA_KEY "\xef\x82\x84" // U+f084 136 | #define ICON_FA_COGS "\xef\x82\x85" // U+f085 137 | #define ICON_FA_COMMENTS "\xef\x82\x86" // U+f086 138 | #define ICON_FA_THUMBS_O_UP "\xef\x82\x87" // U+f087 139 | #define ICON_FA_THUMBS_O_DOWN "\xef\x82\x88" // U+f088 140 | #define ICON_FA_STAR_HALF "\xef\x82\x89" // U+f089 141 | #define ICON_FA_HEART_O "\xef\x82\x8a" // U+f08a 142 | #define ICON_FA_SIGN_OUT "\xef\x82\x8b" // U+f08b 143 | #define ICON_FA_LINKEDIN_SQUARE "\xef\x82\x8c" // U+f08c 144 | #define ICON_FA_THUMB_TACK "\xef\x82\x8d" // U+f08d 145 | #define ICON_FA_EXTERNAL_LINK "\xef\x82\x8e" // U+f08e 146 | #define ICON_FA_SIGN_IN "\xef\x82\x90" // U+f090 147 | #define ICON_FA_TROPHY "\xef\x82\x91" // U+f091 148 | #define ICON_FA_GITHUB_SQUARE "\xef\x82\x92" // U+f092 149 | #define ICON_FA_UPLOAD "\xef\x82\x93" // U+f093 150 | #define ICON_FA_LEMON_O "\xef\x82\x94" // U+f094 151 | #define ICON_FA_PHONE "\xef\x82\x95" // U+f095 152 | #define ICON_FA_SQUARE_O "\xef\x82\x96" // U+f096 153 | #define ICON_FA_BOOKMARK_O "\xef\x82\x97" // U+f097 154 | #define ICON_FA_PHONE_SQUARE "\xef\x82\x98" // U+f098 155 | #define ICON_FA_TWITTER "\xef\x82\x99" // U+f099 156 | #define ICON_FA_FACEBOOK "\xef\x82\x9a" // U+f09a 157 | #define ICON_FA_GITHUB "\xef\x82\x9b" // U+f09b 158 | #define ICON_FA_UNLOCK "\xef\x82\x9c" // U+f09c 159 | #define ICON_FA_CREDIT_CARD "\xef\x82\x9d" // U+f09d 160 | #define ICON_FA_RSS "\xef\x82\x9e" // U+f09e 161 | #define ICON_FA_HDD_O "\xef\x82\xa0" // U+f0a0 162 | #define ICON_FA_BULLHORN "\xef\x82\xa1" // U+f0a1 163 | #define ICON_FA_BELL "\xef\x83\xb3" // U+f0f3 164 | #define ICON_FA_CERTIFICATE "\xef\x82\xa3" // U+f0a3 165 | #define ICON_FA_HAND_O_RIGHT "\xef\x82\xa4" // U+f0a4 166 | #define ICON_FA_HAND_O_LEFT "\xef\x82\xa5" // U+f0a5 167 | #define ICON_FA_HAND_O_UP "\xef\x82\xa6" // U+f0a6 168 | #define ICON_FA_HAND_O_DOWN "\xef\x82\xa7" // U+f0a7 169 | #define ICON_FA_ARROW_CIRCLE_LEFT "\xef\x82\xa8" // U+f0a8 170 | #define ICON_FA_ARROW_CIRCLE_RIGHT "\xef\x82\xa9" // U+f0a9 171 | #define ICON_FA_ARROW_CIRCLE_UP "\xef\x82\xaa" // U+f0aa 172 | #define ICON_FA_ARROW_CIRCLE_DOWN "\xef\x82\xab" // U+f0ab 173 | #define ICON_FA_GLOBE "\xef\x82\xac" // U+f0ac 174 | #define ICON_FA_WRENCH "\xef\x82\xad" // U+f0ad 175 | #define ICON_FA_TASKS "\xef\x82\xae" // U+f0ae 176 | #define ICON_FA_FILTER "\xef\x82\xb0" // U+f0b0 177 | #define ICON_FA_BRIEFCASE "\xef\x82\xb1" // U+f0b1 178 | #define ICON_FA_ARROWS_ALT "\xef\x82\xb2" // U+f0b2 179 | #define ICON_FA_USERS "\xef\x83\x80" // U+f0c0 180 | #define ICON_FA_LINK "\xef\x83\x81" // U+f0c1 181 | #define ICON_FA_CLOUD "\xef\x83\x82" // U+f0c2 182 | #define ICON_FA_FLASK "\xef\x83\x83" // U+f0c3 183 | #define ICON_FA_SCISSORS "\xef\x83\x84" // U+f0c4 184 | #define ICON_FA_FILES_O "\xef\x83\x85" // U+f0c5 185 | #define ICON_FA_PAPERCLIP "\xef\x83\x86" // U+f0c6 186 | #define ICON_FA_FLOPPY_O "\xef\x83\x87" // U+f0c7 187 | #define ICON_FA_SQUARE "\xef\x83\x88" // U+f0c8 188 | #define ICON_FA_BARS "\xef\x83\x89" // U+f0c9 189 | #define ICON_FA_LIST_UL "\xef\x83\x8a" // U+f0ca 190 | #define ICON_FA_LIST_OL "\xef\x83\x8b" // U+f0cb 191 | #define ICON_FA_STRIKETHROUGH "\xef\x83\x8c" // U+f0cc 192 | #define ICON_FA_UNDERLINE "\xef\x83\x8d" // U+f0cd 193 | #define ICON_FA_TABLE "\xef\x83\x8e" // U+f0ce 194 | #define ICON_FA_MAGIC "\xef\x83\x90" // U+f0d0 195 | #define ICON_FA_TRUCK "\xef\x83\x91" // U+f0d1 196 | #define ICON_FA_PINTEREST "\xef\x83\x92" // U+f0d2 197 | #define ICON_FA_PINTEREST_SQUARE "\xef\x83\x93" // U+f0d3 198 | #define ICON_FA_GOOGLE_PLUS_SQUARE "\xef\x83\x94" // U+f0d4 199 | #define ICON_FA_GOOGLE_PLUS "\xef\x83\x95" // U+f0d5 200 | #define ICON_FA_MONEY "\xef\x83\x96" // U+f0d6 201 | #define ICON_FA_CARET_DOWN "\xef\x83\x97" // U+f0d7 202 | #define ICON_FA_CARET_UP "\xef\x83\x98" // U+f0d8 203 | #define ICON_FA_CARET_LEFT "\xef\x83\x99" // U+f0d9 204 | #define ICON_FA_CARET_RIGHT "\xef\x83\x9a" // U+f0da 205 | #define ICON_FA_COLUMNS "\xef\x83\x9b" // U+f0db 206 | #define ICON_FA_SORT "\xef\x83\x9c" // U+f0dc 207 | #define ICON_FA_SORT_DESC "\xef\x83\x9d" // U+f0dd 208 | #define ICON_FA_SORT_ASC "\xef\x83\x9e" // U+f0de 209 | #define ICON_FA_ENVELOPE "\xef\x83\xa0" // U+f0e0 210 | #define ICON_FA_LINKEDIN "\xef\x83\xa1" // U+f0e1 211 | #define ICON_FA_UNDO "\xef\x83\xa2" // U+f0e2 212 | #define ICON_FA_GAVEL "\xef\x83\xa3" // U+f0e3 213 | #define ICON_FA_TACHOMETER "\xef\x83\xa4" // U+f0e4 214 | #define ICON_FA_COMMENT_O "\xef\x83\xa5" // U+f0e5 215 | #define ICON_FA_COMMENTS_O "\xef\x83\xa6" // U+f0e6 216 | #define ICON_FA_BOLT "\xef\x83\xa7" // U+f0e7 217 | #define ICON_FA_SITEMAP "\xef\x83\xa8" // U+f0e8 218 | #define ICON_FA_UMBRELLA "\xef\x83\xa9" // U+f0e9 219 | #define ICON_FA_CLIPBOARD "\xef\x83\xaa" // U+f0ea 220 | #define ICON_FA_LIGHTBULB_O "\xef\x83\xab" // U+f0eb 221 | #define ICON_FA_EXCHANGE "\xef\x83\xac" // U+f0ec 222 | #define ICON_FA_CLOUD_DOWNLOAD "\xef\x83\xad" // U+f0ed 223 | #define ICON_FA_CLOUD_UPLOAD "\xef\x83\xae" // U+f0ee 224 | #define ICON_FA_USER_MD "\xef\x83\xb0" // U+f0f0 225 | #define ICON_FA_STETHOSCOPE "\xef\x83\xb1" // U+f0f1 226 | #define ICON_FA_SUITCASE "\xef\x83\xb2" // U+f0f2 227 | #define ICON_FA_BELL_O "\xef\x82\xa2" // U+f0a2 228 | #define ICON_FA_COFFEE "\xef\x83\xb4" // U+f0f4 229 | #define ICON_FA_CUTLERY "\xef\x83\xb5" // U+f0f5 230 | #define ICON_FA_FILE_TEXT_O "\xef\x83\xb6" // U+f0f6 231 | #define ICON_FA_BUILDING_O "\xef\x83\xb7" // U+f0f7 232 | #define ICON_FA_HOSPITAL_O "\xef\x83\xb8" // U+f0f8 233 | #define ICON_FA_AMBULANCE "\xef\x83\xb9" // U+f0f9 234 | #define ICON_FA_MEDKIT "\xef\x83\xba" // U+f0fa 235 | #define ICON_FA_FIGHTER_JET "\xef\x83\xbb" // U+f0fb 236 | #define ICON_FA_BEER "\xef\x83\xbc" // U+f0fc 237 | #define ICON_FA_H_SQUARE "\xef\x83\xbd" // U+f0fd 238 | #define ICON_FA_PLUS_SQUARE "\xef\x83\xbe" // U+f0fe 239 | #define ICON_FA_ANGLE_DOUBLE_LEFT "\xef\x84\x80" // U+f100 240 | #define ICON_FA_ANGLE_DOUBLE_RIGHT "\xef\x84\x81" // U+f101 241 | #define ICON_FA_ANGLE_DOUBLE_UP "\xef\x84\x82" // U+f102 242 | #define ICON_FA_ANGLE_DOUBLE_DOWN "\xef\x84\x83" // U+f103 243 | #define ICON_FA_ANGLE_LEFT "\xef\x84\x84" // U+f104 244 | #define ICON_FA_ANGLE_RIGHT "\xef\x84\x85" // U+f105 245 | #define ICON_FA_ANGLE_UP "\xef\x84\x86" // U+f106 246 | #define ICON_FA_ANGLE_DOWN "\xef\x84\x87" // U+f107 247 | #define ICON_FA_DESKTOP "\xef\x84\x88" // U+f108 248 | #define ICON_FA_LAPTOP "\xef\x84\x89" // U+f109 249 | #define ICON_FA_TABLET "\xef\x84\x8a" // U+f10a 250 | #define ICON_FA_MOBILE "\xef\x84\x8b" // U+f10b 251 | #define ICON_FA_CIRCLE_O "\xef\x84\x8c" // U+f10c 252 | #define ICON_FA_QUOTE_LEFT "\xef\x84\x8d" // U+f10d 253 | #define ICON_FA_QUOTE_RIGHT "\xef\x84\x8e" // U+f10e 254 | #define ICON_FA_SPINNER "\xef\x84\x90" // U+f110 255 | #define ICON_FA_CIRCLE "\xef\x84\x91" // U+f111 256 | #define ICON_FA_REPLY "\xef\x84\x92" // U+f112 257 | #define ICON_FA_GITHUB_ALT "\xef\x84\x93" // U+f113 258 | #define ICON_FA_FOLDER_O "\xef\x84\x94" // U+f114 259 | #define ICON_FA_FOLDER_OPEN_O "\xef\x84\x95" // U+f115 260 | #define ICON_FA_SMILE_O "\xef\x84\x98" // U+f118 261 | #define ICON_FA_FROWN_O "\xef\x84\x99" // U+f119 262 | #define ICON_FA_MEH_O "\xef\x84\x9a" // U+f11a 263 | #define ICON_FA_GAMEPAD "\xef\x84\x9b" // U+f11b 264 | #define ICON_FA_KEYBOARD_O "\xef\x84\x9c" // U+f11c 265 | #define ICON_FA_FLAG_O "\xef\x84\x9d" // U+f11d 266 | #define ICON_FA_FLAG_CHECKERED "\xef\x84\x9e" // U+f11e 267 | #define ICON_FA_TERMINAL "\xef\x84\xa0" // U+f120 268 | #define ICON_FA_CODE "\xef\x84\xa1" // U+f121 269 | #define ICON_FA_REPLY_ALL "\xef\x84\xa2" // U+f122 270 | #define ICON_FA_STAR_HALF_O "\xef\x84\xa3" // U+f123 271 | #define ICON_FA_LOCATION_ARROW "\xef\x84\xa4" // U+f124 272 | #define ICON_FA_CROP "\xef\x84\xa5" // U+f125 273 | #define ICON_FA_CODE_FORK "\xef\x84\xa6" // U+f126 274 | #define ICON_FA_CHAIN_BROKEN "\xef\x84\xa7" // U+f127 275 | #define ICON_FA_QUESTION "\xef\x84\xa8" // U+f128 276 | #define ICON_FA_INFO "\xef\x84\xa9" // U+f129 277 | #define ICON_FA_EXCLAMATION "\xef\x84\xaa" // U+f12a 278 | #define ICON_FA_SUPERSCRIPT "\xef\x84\xab" // U+f12b 279 | #define ICON_FA_SUBSCRIPT "\xef\x84\xac" // U+f12c 280 | #define ICON_FA_ERASER "\xef\x84\xad" // U+f12d 281 | #define ICON_FA_PUZZLE_PIECE "\xef\x84\xae" // U+f12e 282 | #define ICON_FA_MICROPHONE "\xef\x84\xb0" // U+f130 283 | #define ICON_FA_MICROPHONE_SLASH "\xef\x84\xb1" // U+f131 284 | #define ICON_FA_SHIELD "\xef\x84\xb2" // U+f132 285 | #define ICON_FA_CALENDAR_O "\xef\x84\xb3" // U+f133 286 | #define ICON_FA_FIRE_EXTINGUISHER "\xef\x84\xb4" // U+f134 287 | #define ICON_FA_ROCKET "\xef\x84\xb5" // U+f135 288 | #define ICON_FA_MAXCDN "\xef\x84\xb6" // U+f136 289 | #define ICON_FA_CHEVRON_CIRCLE_LEFT "\xef\x84\xb7" // U+f137 290 | #define ICON_FA_CHEVRON_CIRCLE_RIGHT "\xef\x84\xb8" // U+f138 291 | #define ICON_FA_CHEVRON_CIRCLE_UP "\xef\x84\xb9" // U+f139 292 | #define ICON_FA_CHEVRON_CIRCLE_DOWN "\xef\x84\xba" // U+f13a 293 | #define ICON_FA_HTML5 "\xef\x84\xbb" // U+f13b 294 | #define ICON_FA_CSS3 "\xef\x84\xbc" // U+f13c 295 | #define ICON_FA_ANCHOR "\xef\x84\xbd" // U+f13d 296 | #define ICON_FA_UNLOCK_ALT "\xef\x84\xbe" // U+f13e 297 | #define ICON_FA_BULLSEYE "\xef\x85\x80" // U+f140 298 | #define ICON_FA_ELLIPSIS_H "\xef\x85\x81" // U+f141 299 | #define ICON_FA_ELLIPSIS_V "\xef\x85\x82" // U+f142 300 | #define ICON_FA_RSS_SQUARE "\xef\x85\x83" // U+f143 301 | #define ICON_FA_PLAY_CIRCLE "\xef\x85\x84" // U+f144 302 | #define ICON_FA_TICKET "\xef\x85\x85" // U+f145 303 | #define ICON_FA_MINUS_SQUARE "\xef\x85\x86" // U+f146 304 | #define ICON_FA_MINUS_SQUARE_O "\xef\x85\x87" // U+f147 305 | #define ICON_FA_LEVEL_UP "\xef\x85\x88" // U+f148 306 | #define ICON_FA_LEVEL_DOWN "\xef\x85\x89" // U+f149 307 | #define ICON_FA_CHECK_SQUARE "\xef\x85\x8a" // U+f14a 308 | #define ICON_FA_PENCIL_SQUARE "\xef\x85\x8b" // U+f14b 309 | #define ICON_FA_EXTERNAL_LINK_SQUARE "\xef\x85\x8c" // U+f14c 310 | #define ICON_FA_SHARE_SQUARE "\xef\x85\x8d" // U+f14d 311 | #define ICON_FA_COMPASS "\xef\x85\x8e" // U+f14e 312 | #define ICON_FA_CARET_SQUARE_O_DOWN "\xef\x85\x90" // U+f150 313 | #define ICON_FA_CARET_SQUARE_O_UP "\xef\x85\x91" // U+f151 314 | #define ICON_FA_CARET_SQUARE_O_RIGHT "\xef\x85\x92" // U+f152 315 | #define ICON_FA_EUR "\xef\x85\x93" // U+f153 316 | #define ICON_FA_GBP "\xef\x85\x94" // U+f154 317 | #define ICON_FA_USD "\xef\x85\x95" // U+f155 318 | #define ICON_FA_INR "\xef\x85\x96" // U+f156 319 | #define ICON_FA_JPY "\xef\x85\x97" // U+f157 320 | #define ICON_FA_RUB "\xef\x85\x98" // U+f158 321 | #define ICON_FA_KRW "\xef\x85\x99" // U+f159 322 | #define ICON_FA_BTC "\xef\x85\x9a" // U+f15a 323 | #define ICON_FA_FILE "\xef\x85\x9b" // U+f15b 324 | #define ICON_FA_FILE_TEXT "\xef\x85\x9c" // U+f15c 325 | #define ICON_FA_SORT_ALPHA_ASC "\xef\x85\x9d" // U+f15d 326 | #define ICON_FA_SORT_ALPHA_DESC "\xef\x85\x9e" // U+f15e 327 | #define ICON_FA_SORT_AMOUNT_ASC "\xef\x85\xa0" // U+f160 328 | #define ICON_FA_SORT_AMOUNT_DESC "\xef\x85\xa1" // U+f161 329 | #define ICON_FA_SORT_NUMERIC_ASC "\xef\x85\xa2" // U+f162 330 | #define ICON_FA_SORT_NUMERIC_DESC "\xef\x85\xa3" // U+f163 331 | #define ICON_FA_THUMBS_UP "\xef\x85\xa4" // U+f164 332 | #define ICON_FA_THUMBS_DOWN "\xef\x85\xa5" // U+f165 333 | #define ICON_FA_YOUTUBE_SQUARE "\xef\x85\xa6" // U+f166 334 | #define ICON_FA_YOUTUBE "\xef\x85\xa7" // U+f167 335 | #define ICON_FA_XING "\xef\x85\xa8" // U+f168 336 | #define ICON_FA_XING_SQUARE "\xef\x85\xa9" // U+f169 337 | #define ICON_FA_YOUTUBE_PLAY "\xef\x85\xaa" // U+f16a 338 | #define ICON_FA_DROPBOX "\xef\x85\xab" // U+f16b 339 | #define ICON_FA_STACK_OVERFLOW "\xef\x85\xac" // U+f16c 340 | #define ICON_FA_INSTAGRAM "\xef\x85\xad" // U+f16d 341 | #define ICON_FA_FLICKR "\xef\x85\xae" // U+f16e 342 | #define ICON_FA_ADN "\xef\x85\xb0" // U+f170 343 | #define ICON_FA_BITBUCKET "\xef\x85\xb1" // U+f171 344 | #define ICON_FA_BITBUCKET_SQUARE "\xef\x85\xb2" // U+f172 345 | #define ICON_FA_TUMBLR "\xef\x85\xb3" // U+f173 346 | #define ICON_FA_TUMBLR_SQUARE "\xef\x85\xb4" // U+f174 347 | #define ICON_FA_LONG_ARROW_DOWN "\xef\x85\xb5" // U+f175 348 | #define ICON_FA_LONG_ARROW_UP "\xef\x85\xb6" // U+f176 349 | #define ICON_FA_LONG_ARROW_LEFT "\xef\x85\xb7" // U+f177 350 | #define ICON_FA_LONG_ARROW_RIGHT "\xef\x85\xb8" // U+f178 351 | #define ICON_FA_APPLE "\xef\x85\xb9" // U+f179 352 | #define ICON_FA_WINDOWS "\xef\x85\xba" // U+f17a 353 | #define ICON_FA_ANDROID "\xef\x85\xbb" // U+f17b 354 | #define ICON_FA_LINUX "\xef\x85\xbc" // U+f17c 355 | #define ICON_FA_DRIBBBLE "\xef\x85\xbd" // U+f17d 356 | #define ICON_FA_SKYPE "\xef\x85\xbe" // U+f17e 357 | #define ICON_FA_FOURSQUARE "\xef\x86\x80" // U+f180 358 | #define ICON_FA_TRELLO "\xef\x86\x81" // U+f181 359 | #define ICON_FA_FEMALE "\xef\x86\x82" // U+f182 360 | #define ICON_FA_MALE "\xef\x86\x83" // U+f183 361 | #define ICON_FA_GRATIPAY "\xef\x86\x84" // U+f184 362 | #define ICON_FA_SUN_O "\xef\x86\x85" // U+f185 363 | #define ICON_FA_MOON_O "\xef\x86\x86" // U+f186 364 | #define ICON_FA_ARCHIVE "\xef\x86\x87" // U+f187 365 | #define ICON_FA_BUG "\xef\x86\x88" // U+f188 366 | #define ICON_FA_VK "\xef\x86\x89" // U+f189 367 | #define ICON_FA_WEIBO "\xef\x86\x8a" // U+f18a 368 | #define ICON_FA_RENREN "\xef\x86\x8b" // U+f18b 369 | #define ICON_FA_PAGELINES "\xef\x86\x8c" // U+f18c 370 | #define ICON_FA_STACK_EXCHANGE "\xef\x86\x8d" // U+f18d 371 | #define ICON_FA_ARROW_CIRCLE_O_RIGHT "\xef\x86\x8e" // U+f18e 372 | #define ICON_FA_ARROW_CIRCLE_O_LEFT "\xef\x86\x90" // U+f190 373 | #define ICON_FA_CARET_SQUARE_O_LEFT "\xef\x86\x91" // U+f191 374 | #define ICON_FA_DOT_CIRCLE_O "\xef\x86\x92" // U+f192 375 | #define ICON_FA_WHEELCHAIR "\xef\x86\x93" // U+f193 376 | #define ICON_FA_VIMEO_SQUARE "\xef\x86\x94" // U+f194 377 | #define ICON_FA_TRY "\xef\x86\x95" // U+f195 378 | #define ICON_FA_PLUS_SQUARE_O "\xef\x86\x96" // U+f196 379 | #define ICON_FA_SPACE_SHUTTLE "\xef\x86\x97" // U+f197 380 | #define ICON_FA_SLACK "\xef\x86\x98" // U+f198 381 | #define ICON_FA_ENVELOPE_SQUARE "\xef\x86\x99" // U+f199 382 | #define ICON_FA_WORDPRESS "\xef\x86\x9a" // U+f19a 383 | #define ICON_FA_OPENID "\xef\x86\x9b" // U+f19b 384 | #define ICON_FA_UNIVERSITY "\xef\x86\x9c" // U+f19c 385 | #define ICON_FA_GRADUATION_CAP "\xef\x86\x9d" // U+f19d 386 | #define ICON_FA_YAHOO "\xef\x86\x9e" // U+f19e 387 | #define ICON_FA_GOOGLE "\xef\x86\xa0" // U+f1a0 388 | #define ICON_FA_REDDIT "\xef\x86\xa1" // U+f1a1 389 | #define ICON_FA_REDDIT_SQUARE "\xef\x86\xa2" // U+f1a2 390 | #define ICON_FA_STUMBLEUPON_CIRCLE "\xef\x86\xa3" // U+f1a3 391 | #define ICON_FA_STUMBLEUPON "\xef\x86\xa4" // U+f1a4 392 | #define ICON_FA_DELICIOUS "\xef\x86\xa5" // U+f1a5 393 | #define ICON_FA_DIGG "\xef\x86\xa6" // U+f1a6 394 | #define ICON_FA_PIED_PIPER_PP "\xef\x86\xa7" // U+f1a7 395 | #define ICON_FA_PIED_PIPER_ALT "\xef\x86\xa8" // U+f1a8 396 | #define ICON_FA_DRUPAL "\xef\x86\xa9" // U+f1a9 397 | #define ICON_FA_JOOMLA "\xef\x86\xaa" // U+f1aa 398 | #define ICON_FA_LANGUAGE "\xef\x86\xab" // U+f1ab 399 | #define ICON_FA_FAX "\xef\x86\xac" // U+f1ac 400 | #define ICON_FA_BUILDING "\xef\x86\xad" // U+f1ad 401 | #define ICON_FA_CHILD "\xef\x86\xae" // U+f1ae 402 | #define ICON_FA_PAW "\xef\x86\xb0" // U+f1b0 403 | #define ICON_FA_SPOON "\xef\x86\xb1" // U+f1b1 404 | #define ICON_FA_CUBE "\xef\x86\xb2" // U+f1b2 405 | #define ICON_FA_CUBES "\xef\x86\xb3" // U+f1b3 406 | #define ICON_FA_BEHANCE "\xef\x86\xb4" // U+f1b4 407 | #define ICON_FA_BEHANCE_SQUARE "\xef\x86\xb5" // U+f1b5 408 | #define ICON_FA_STEAM "\xef\x86\xb6" // U+f1b6 409 | #define ICON_FA_STEAM_SQUARE "\xef\x86\xb7" // U+f1b7 410 | #define ICON_FA_RECYCLE "\xef\x86\xb8" // U+f1b8 411 | #define ICON_FA_CAR "\xef\x86\xb9" // U+f1b9 412 | #define ICON_FA_TAXI "\xef\x86\xba" // U+f1ba 413 | #define ICON_FA_TREE "\xef\x86\xbb" // U+f1bb 414 | #define ICON_FA_SPOTIFY "\xef\x86\xbc" // U+f1bc 415 | #define ICON_FA_DEVIANTART "\xef\x86\xbd" // U+f1bd 416 | #define ICON_FA_SOUNDCLOUD "\xef\x86\xbe" // U+f1be 417 | #define ICON_FA_DATABASE "\xef\x87\x80" // U+f1c0 418 | #define ICON_FA_FILE_PDF_O "\xef\x87\x81" // U+f1c1 419 | #define ICON_FA_FILE_WORD_O "\xef\x87\x82" // U+f1c2 420 | #define ICON_FA_FILE_EXCEL_O "\xef\x87\x83" // U+f1c3 421 | #define ICON_FA_FILE_POWERPOINT_O "\xef\x87\x84" // U+f1c4 422 | #define ICON_FA_FILE_IMAGE_O "\xef\x87\x85" // U+f1c5 423 | #define ICON_FA_FILE_ARCHIVE_O "\xef\x87\x86" // U+f1c6 424 | #define ICON_FA_FILE_AUDIO_O "\xef\x87\x87" // U+f1c7 425 | #define ICON_FA_FILE_VIDEO_O "\xef\x87\x88" // U+f1c8 426 | #define ICON_FA_FILE_CODE_O "\xef\x87\x89" // U+f1c9 427 | #define ICON_FA_VINE "\xef\x87\x8a" // U+f1ca 428 | #define ICON_FA_CODEPEN "\xef\x87\x8b" // U+f1cb 429 | #define ICON_FA_JSFIDDLE "\xef\x87\x8c" // U+f1cc 430 | #define ICON_FA_LIFE_RING "\xef\x87\x8d" // U+f1cd 431 | #define ICON_FA_CIRCLE_O_NOTCH "\xef\x87\x8e" // U+f1ce 432 | #define ICON_FA_REBEL "\xef\x87\x90" // U+f1d0 433 | #define ICON_FA_EMPIRE "\xef\x87\x91" // U+f1d1 434 | #define ICON_FA_GIT_SQUARE "\xef\x87\x92" // U+f1d2 435 | #define ICON_FA_GIT "\xef\x87\x93" // U+f1d3 436 | #define ICON_FA_HACKER_NEWS "\xef\x87\x94" // U+f1d4 437 | #define ICON_FA_TENCENT_WEIBO "\xef\x87\x95" // U+f1d5 438 | #define ICON_FA_QQ "\xef\x87\x96" // U+f1d6 439 | #define ICON_FA_WEIXIN "\xef\x87\x97" // U+f1d7 440 | #define ICON_FA_PAPER_PLANE "\xef\x87\x98" // U+f1d8 441 | #define ICON_FA_PAPER_PLANE_O "\xef\x87\x99" // U+f1d9 442 | #define ICON_FA_HISTORY "\xef\x87\x9a" // U+f1da 443 | #define ICON_FA_CIRCLE_THIN "\xef\x87\x9b" // U+f1db 444 | #define ICON_FA_HEADER "\xef\x87\x9c" // U+f1dc 445 | #define ICON_FA_PARAGRAPH "\xef\x87\x9d" // U+f1dd 446 | #define ICON_FA_SLIDERS "\xef\x87\x9e" // U+f1de 447 | #define ICON_FA_SHARE_ALT "\xef\x87\xa0" // U+f1e0 448 | #define ICON_FA_SHARE_ALT_SQUARE "\xef\x87\xa1" // U+f1e1 449 | #define ICON_FA_BOMB "\xef\x87\xa2" // U+f1e2 450 | #define ICON_FA_FUTBOL_O "\xef\x87\xa3" // U+f1e3 451 | #define ICON_FA_TTY "\xef\x87\xa4" // U+f1e4 452 | #define ICON_FA_BINOCULARS "\xef\x87\xa5" // U+f1e5 453 | #define ICON_FA_PLUG "\xef\x87\xa6" // U+f1e6 454 | #define ICON_FA_SLIDESHARE "\xef\x87\xa7" // U+f1e7 455 | #define ICON_FA_TWITCH "\xef\x87\xa8" // U+f1e8 456 | #define ICON_FA_YELP "\xef\x87\xa9" // U+f1e9 457 | #define ICON_FA_NEWSPAPER_O "\xef\x87\xaa" // U+f1ea 458 | #define ICON_FA_WIFI "\xef\x87\xab" // U+f1eb 459 | #define ICON_FA_CALCULATOR "\xef\x87\xac" // U+f1ec 460 | #define ICON_FA_PAYPAL "\xef\x87\xad" // U+f1ed 461 | #define ICON_FA_GOOGLE_WALLET "\xef\x87\xae" // U+f1ee 462 | #define ICON_FA_CC_VISA "\xef\x87\xb0" // U+f1f0 463 | #define ICON_FA_CC_MASTERCARD "\xef\x87\xb1" // U+f1f1 464 | #define ICON_FA_CC_DISCOVER "\xef\x87\xb2" // U+f1f2 465 | #define ICON_FA_CC_AMEX "\xef\x87\xb3" // U+f1f3 466 | #define ICON_FA_CC_PAYPAL "\xef\x87\xb4" // U+f1f4 467 | #define ICON_FA_CC_STRIPE "\xef\x87\xb5" // U+f1f5 468 | #define ICON_FA_BELL_SLASH "\xef\x87\xb6" // U+f1f6 469 | #define ICON_FA_BELL_SLASH_O "\xef\x87\xb7" // U+f1f7 470 | #define ICON_FA_TRASH "\xef\x87\xb8" // U+f1f8 471 | #define ICON_FA_COPYRIGHT "\xef\x87\xb9" // U+f1f9 472 | #define ICON_FA_AT "\xef\x87\xba" // U+f1fa 473 | #define ICON_FA_EYEDROPPER "\xef\x87\xbb" // U+f1fb 474 | #define ICON_FA_PAINT_BRUSH "\xef\x87\xbc" // U+f1fc 475 | #define ICON_FA_BIRTHDAY_CAKE "\xef\x87\xbd" // U+f1fd 476 | #define ICON_FA_AREA_CHART "\xef\x87\xbe" // U+f1fe 477 | #define ICON_FA_PIE_CHART "\xef\x88\x80" // U+f200 478 | #define ICON_FA_LINE_CHART "\xef\x88\x81" // U+f201 479 | #define ICON_FA_LASTFM "\xef\x88\x82" // U+f202 480 | #define ICON_FA_LASTFM_SQUARE "\xef\x88\x83" // U+f203 481 | #define ICON_FA_TOGGLE_OFF "\xef\x88\x84" // U+f204 482 | #define ICON_FA_TOGGLE_ON "\xef\x88\x85" // U+f205 483 | #define ICON_FA_BICYCLE "\xef\x88\x86" // U+f206 484 | #define ICON_FA_BUS "\xef\x88\x87" // U+f207 485 | #define ICON_FA_IOXHOST "\xef\x88\x88" // U+f208 486 | #define ICON_FA_ANGELLIST "\xef\x88\x89" // U+f209 487 | #define ICON_FA_CC "\xef\x88\x8a" // U+f20a 488 | #define ICON_FA_ILS "\xef\x88\x8b" // U+f20b 489 | #define ICON_FA_MEANPATH "\xef\x88\x8c" // U+f20c 490 | #define ICON_FA_BUYSELLADS "\xef\x88\x8d" // U+f20d 491 | #define ICON_FA_CONNECTDEVELOP "\xef\x88\x8e" // U+f20e 492 | #define ICON_FA_DASHCUBE "\xef\x88\x90" // U+f210 493 | #define ICON_FA_FORUMBEE "\xef\x88\x91" // U+f211 494 | #define ICON_FA_LEANPUB "\xef\x88\x92" // U+f212 495 | #define ICON_FA_SELLSY "\xef\x88\x93" // U+f213 496 | #define ICON_FA_SHIRTSINBULK "\xef\x88\x94" // U+f214 497 | #define ICON_FA_SIMPLYBUILT "\xef\x88\x95" // U+f215 498 | #define ICON_FA_SKYATLAS "\xef\x88\x96" // U+f216 499 | #define ICON_FA_CART_PLUS "\xef\x88\x97" // U+f217 500 | #define ICON_FA_CART_ARROW_DOWN "\xef\x88\x98" // U+f218 501 | #define ICON_FA_DIAMOND "\xef\x88\x99" // U+f219 502 | #define ICON_FA_SHIP "\xef\x88\x9a" // U+f21a 503 | #define ICON_FA_USER_SECRET "\xef\x88\x9b" // U+f21b 504 | #define ICON_FA_MOTORCYCLE "\xef\x88\x9c" // U+f21c 505 | #define ICON_FA_STREET_VIEW "\xef\x88\x9d" // U+f21d 506 | #define ICON_FA_HEARTBEAT "\xef\x88\x9e" // U+f21e 507 | #define ICON_FA_VENUS "\xef\x88\xa1" // U+f221 508 | #define ICON_FA_MARS "\xef\x88\xa2" // U+f222 509 | #define ICON_FA_MERCURY "\xef\x88\xa3" // U+f223 510 | #define ICON_FA_TRANSGENDER "\xef\x88\xa4" // U+f224 511 | #define ICON_FA_TRANSGENDER_ALT "\xef\x88\xa5" // U+f225 512 | #define ICON_FA_VENUS_DOUBLE "\xef\x88\xa6" // U+f226 513 | #define ICON_FA_MARS_DOUBLE "\xef\x88\xa7" // U+f227 514 | #define ICON_FA_VENUS_MARS "\xef\x88\xa8" // U+f228 515 | #define ICON_FA_MARS_STROKE "\xef\x88\xa9" // U+f229 516 | #define ICON_FA_MARS_STROKE_V "\xef\x88\xaa" // U+f22a 517 | #define ICON_FA_MARS_STROKE_H "\xef\x88\xab" // U+f22b 518 | #define ICON_FA_NEUTER "\xef\x88\xac" // U+f22c 519 | #define ICON_FA_GENDERLESS "\xef\x88\xad" // U+f22d 520 | #define ICON_FA_FACEBOOK_OFFICIAL "\xef\x88\xb0" // U+f230 521 | #define ICON_FA_PINTEREST_P "\xef\x88\xb1" // U+f231 522 | #define ICON_FA_WHATSAPP "\xef\x88\xb2" // U+f232 523 | #define ICON_FA_SERVER "\xef\x88\xb3" // U+f233 524 | #define ICON_FA_USER_PLUS "\xef\x88\xb4" // U+f234 525 | #define ICON_FA_USER_TIMES "\xef\x88\xb5" // U+f235 526 | #define ICON_FA_BED "\xef\x88\xb6" // U+f236 527 | #define ICON_FA_VIACOIN "\xef\x88\xb7" // U+f237 528 | #define ICON_FA_TRAIN "\xef\x88\xb8" // U+f238 529 | #define ICON_FA_SUBWAY "\xef\x88\xb9" // U+f239 530 | #define ICON_FA_MEDIUM "\xef\x88\xba" // U+f23a 531 | #define ICON_FA_Y_COMBINATOR "\xef\x88\xbb" // U+f23b 532 | #define ICON_FA_OPTIN_MONSTER "\xef\x88\xbc" // U+f23c 533 | #define ICON_FA_OPENCART "\xef\x88\xbd" // U+f23d 534 | #define ICON_FA_EXPEDITEDSSL "\xef\x88\xbe" // U+f23e 535 | #define ICON_FA_BATTERY_FULL "\xef\x89\x80" // U+f240 536 | #define ICON_FA_BATTERY_THREE_QUARTERS "\xef\x89\x81" // U+f241 537 | #define ICON_FA_BATTERY_HALF "\xef\x89\x82" // U+f242 538 | #define ICON_FA_BATTERY_QUARTER "\xef\x89\x83" // U+f243 539 | #define ICON_FA_BATTERY_EMPTY "\xef\x89\x84" // U+f244 540 | #define ICON_FA_MOUSE_POINTER "\xef\x89\x85" // U+f245 541 | #define ICON_FA_I_CURSOR "\xef\x89\x86" // U+f246 542 | #define ICON_FA_OBJECT_GROUP "\xef\x89\x87" // U+f247 543 | #define ICON_FA_OBJECT_UNGROUP "\xef\x89\x88" // U+f248 544 | #define ICON_FA_STICKY_NOTE "\xef\x89\x89" // U+f249 545 | #define ICON_FA_STICKY_NOTE_O "\xef\x89\x8a" // U+f24a 546 | #define ICON_FA_CC_JCB "\xef\x89\x8b" // U+f24b 547 | #define ICON_FA_CC_DINERS_CLUB "\xef\x89\x8c" // U+f24c 548 | #define ICON_FA_CLONE "\xef\x89\x8d" // U+f24d 549 | #define ICON_FA_BALANCE_SCALE "\xef\x89\x8e" // U+f24e 550 | #define ICON_FA_HOURGLASS_O "\xef\x89\x90" // U+f250 551 | #define ICON_FA_HOURGLASS_START "\xef\x89\x91" // U+f251 552 | #define ICON_FA_HOURGLASS_HALF "\xef\x89\x92" // U+f252 553 | #define ICON_FA_HOURGLASS_END "\xef\x89\x93" // U+f253 554 | #define ICON_FA_HOURGLASS "\xef\x89\x94" // U+f254 555 | #define ICON_FA_HAND_ROCK_O "\xef\x89\x95" // U+f255 556 | #define ICON_FA_HAND_PAPER_O "\xef\x89\x96" // U+f256 557 | #define ICON_FA_HAND_SCISSORS_O "\xef\x89\x97" // U+f257 558 | #define ICON_FA_HAND_LIZARD_O "\xef\x89\x98" // U+f258 559 | #define ICON_FA_HAND_SPOCK_O "\xef\x89\x99" // U+f259 560 | #define ICON_FA_HAND_POINTER_O "\xef\x89\x9a" // U+f25a 561 | #define ICON_FA_HAND_PEACE_O "\xef\x89\x9b" // U+f25b 562 | #define ICON_FA_TRADEMARK "\xef\x89\x9c" // U+f25c 563 | #define ICON_FA_REGISTERED "\xef\x89\x9d" // U+f25d 564 | #define ICON_FA_CREATIVE_COMMONS "\xef\x89\x9e" // U+f25e 565 | #define ICON_FA_GG "\xef\x89\xa0" // U+f260 566 | #define ICON_FA_GG_CIRCLE "\xef\x89\xa1" // U+f261 567 | #define ICON_FA_TRIPADVISOR "\xef\x89\xa2" // U+f262 568 | #define ICON_FA_ODNOKLASSNIKI "\xef\x89\xa3" // U+f263 569 | #define ICON_FA_ODNOKLASSNIKI_SQUARE "\xef\x89\xa4" // U+f264 570 | #define ICON_FA_GET_POCKET "\xef\x89\xa5" // U+f265 571 | #define ICON_FA_WIKIPEDIA_W "\xef\x89\xa6" // U+f266 572 | #define ICON_FA_SAFARI "\xef\x89\xa7" // U+f267 573 | #define ICON_FA_CHROME "\xef\x89\xa8" // U+f268 574 | #define ICON_FA_FIREFOX "\xef\x89\xa9" // U+f269 575 | #define ICON_FA_OPERA "\xef\x89\xaa" // U+f26a 576 | #define ICON_FA_INTERNET_EXPLORER "\xef\x89\xab" // U+f26b 577 | #define ICON_FA_TELEVISION "\xef\x89\xac" // U+f26c 578 | #define ICON_FA_CONTAO "\xef\x89\xad" // U+f26d 579 | #define ICON_FA_500PX "\xef\x89\xae" // U+f26e 580 | #define ICON_FA_AMAZON "\xef\x89\xb0" // U+f270 581 | #define ICON_FA_CALENDAR_PLUS_O "\xef\x89\xb1" // U+f271 582 | #define ICON_FA_CALENDAR_MINUS_O "\xef\x89\xb2" // U+f272 583 | #define ICON_FA_CALENDAR_TIMES_O "\xef\x89\xb3" // U+f273 584 | #define ICON_FA_CALENDAR_CHECK_O "\xef\x89\xb4" // U+f274 585 | #define ICON_FA_INDUSTRY "\xef\x89\xb5" // U+f275 586 | #define ICON_FA_MAP_PIN "\xef\x89\xb6" // U+f276 587 | #define ICON_FA_MAP_SIGNS "\xef\x89\xb7" // U+f277 588 | #define ICON_FA_MAP_O "\xef\x89\xb8" // U+f278 589 | #define ICON_FA_MAP "\xef\x89\xb9" // U+f279 590 | #define ICON_FA_COMMENTING "\xef\x89\xba" // U+f27a 591 | #define ICON_FA_COMMENTING_O "\xef\x89\xbb" // U+f27b 592 | #define ICON_FA_HOUZZ "\xef\x89\xbc" // U+f27c 593 | #define ICON_FA_VIMEO "\xef\x89\xbd" // U+f27d 594 | #define ICON_FA_BLACK_TIE "\xef\x89\xbe" // U+f27e 595 | #define ICON_FA_FONTICONS "\xef\x8a\x80" // U+f280 596 | #define ICON_FA_REDDIT_ALIEN "\xef\x8a\x81" // U+f281 597 | #define ICON_FA_EDGE "\xef\x8a\x82" // U+f282 598 | #define ICON_FA_CREDIT_CARD_ALT "\xef\x8a\x83" // U+f283 599 | #define ICON_FA_CODIEPIE "\xef\x8a\x84" // U+f284 600 | #define ICON_FA_MODX "\xef\x8a\x85" // U+f285 601 | #define ICON_FA_FORT_AWESOME "\xef\x8a\x86" // U+f286 602 | #define ICON_FA_USB "\xef\x8a\x87" // U+f287 603 | #define ICON_FA_PRODUCT_HUNT "\xef\x8a\x88" // U+f288 604 | #define ICON_FA_MIXCLOUD "\xef\x8a\x89" // U+f289 605 | #define ICON_FA_SCRIBD "\xef\x8a\x8a" // U+f28a 606 | #define ICON_FA_PAUSE_CIRCLE "\xef\x8a\x8b" // U+f28b 607 | #define ICON_FA_PAUSE_CIRCLE_O "\xef\x8a\x8c" // U+f28c 608 | #define ICON_FA_STOP_CIRCLE "\xef\x8a\x8d" // U+f28d 609 | #define ICON_FA_STOP_CIRCLE_O "\xef\x8a\x8e" // U+f28e 610 | #define ICON_FA_SHOPPING_BAG "\xef\x8a\x90" // U+f290 611 | #define ICON_FA_SHOPPING_BASKET "\xef\x8a\x91" // U+f291 612 | #define ICON_FA_HASHTAG "\xef\x8a\x92" // U+f292 613 | #define ICON_FA_BLUETOOTH "\xef\x8a\x93" // U+f293 614 | #define ICON_FA_BLUETOOTH_B "\xef\x8a\x94" // U+f294 615 | #define ICON_FA_PERCENT "\xef\x8a\x95" // U+f295 616 | #define ICON_FA_GITLAB "\xef\x8a\x96" // U+f296 617 | #define ICON_FA_WPBEGINNER "\xef\x8a\x97" // U+f297 618 | #define ICON_FA_WPFORMS "\xef\x8a\x98" // U+f298 619 | #define ICON_FA_ENVIRA "\xef\x8a\x99" // U+f299 620 | #define ICON_FA_UNIVERSAL_ACCESS "\xef\x8a\x9a" // U+f29a 621 | #define ICON_FA_WHEELCHAIR_ALT "\xef\x8a\x9b" // U+f29b 622 | #define ICON_FA_QUESTION_CIRCLE_O "\xef\x8a\x9c" // U+f29c 623 | #define ICON_FA_BLIND "\xef\x8a\x9d" // U+f29d 624 | #define ICON_FA_AUDIO_DESCRIPTION "\xef\x8a\x9e" // U+f29e 625 | #define ICON_FA_VOLUME_CONTROL_PHONE "\xef\x8a\xa0" // U+f2a0 626 | #define ICON_FA_BRAILLE "\xef\x8a\xa1" // U+f2a1 627 | #define ICON_FA_ASSISTIVE_LISTENING_SYSTEMS "\xef\x8a\xa2" // U+f2a2 628 | #define ICON_FA_AMERICAN_SIGN_LANGUAGE_INTERPRETING "\xef\x8a\xa3" // U+f2a3 629 | #define ICON_FA_DEAF "\xef\x8a\xa4" // U+f2a4 630 | #define ICON_FA_GLIDE "\xef\x8a\xa5" // U+f2a5 631 | #define ICON_FA_GLIDE_G "\xef\x8a\xa6" // U+f2a6 632 | #define ICON_FA_SIGN_LANGUAGE "\xef\x8a\xa7" // U+f2a7 633 | #define ICON_FA_LOW_VISION "\xef\x8a\xa8" // U+f2a8 634 | #define ICON_FA_VIADEO "\xef\x8a\xa9" // U+f2a9 635 | #define ICON_FA_VIADEO_SQUARE "\xef\x8a\xaa" // U+f2aa 636 | #define ICON_FA_SNAPCHAT "\xef\x8a\xab" // U+f2ab 637 | #define ICON_FA_SNAPCHAT_GHOST "\xef\x8a\xac" // U+f2ac 638 | #define ICON_FA_SNAPCHAT_SQUARE "\xef\x8a\xad" // U+f2ad 639 | #define ICON_FA_PIED_PIPER "\xef\x8a\xae" // U+f2ae 640 | #define ICON_FA_FIRST_ORDER "\xef\x8a\xb0" // U+f2b0 641 | #define ICON_FA_YOAST "\xef\x8a\xb1" // U+f2b1 642 | #define ICON_FA_THEMEISLE "\xef\x8a\xb2" // U+f2b2 643 | #define ICON_FA_GOOGLE_PLUS_OFFICIAL "\xef\x8a\xb3" // U+f2b3 644 | #define ICON_FA_FONT_AWESOME "\xef\x8a\xb4" // U+f2b4 645 | #define ICON_FA_HANDSHAKE_O "\xef\x8a\xb5" // U+f2b5 646 | #define ICON_FA_ENVELOPE_OPEN "\xef\x8a\xb6" // U+f2b6 647 | #define ICON_FA_ENVELOPE_OPEN_O "\xef\x8a\xb7" // U+f2b7 648 | #define ICON_FA_LINODE "\xef\x8a\xb8" // U+f2b8 649 | #define ICON_FA_ADDRESS_BOOK "\xef\x8a\xb9" // U+f2b9 650 | #define ICON_FA_ADDRESS_BOOK_O "\xef\x8a\xba" // U+f2ba 651 | #define ICON_FA_ADDRESS_CARD "\xef\x8a\xbb" // U+f2bb 652 | #define ICON_FA_ADDRESS_CARD_O "\xef\x8a\xbc" // U+f2bc 653 | #define ICON_FA_USER_CIRCLE "\xef\x8a\xbd" // U+f2bd 654 | #define ICON_FA_USER_CIRCLE_O "\xef\x8a\xbe" // U+f2be 655 | #define ICON_FA_USER_O "\xef\x8b\x80" // U+f2c0 656 | #define ICON_FA_ID_BADGE "\xef\x8b\x81" // U+f2c1 657 | #define ICON_FA_ID_CARD "\xef\x8b\x82" // U+f2c2 658 | #define ICON_FA_ID_CARD_O "\xef\x8b\x83" // U+f2c3 659 | #define ICON_FA_QUORA "\xef\x8b\x84" // U+f2c4 660 | #define ICON_FA_FREE_CODE_CAMP "\xef\x8b\x85" // U+f2c5 661 | #define ICON_FA_TELEGRAM "\xef\x8b\x86" // U+f2c6 662 | #define ICON_FA_THERMOMETER_FULL "\xef\x8b\x87" // U+f2c7 663 | #define ICON_FA_THERMOMETER_THREE_QUARTERS "\xef\x8b\x88" // U+f2c8 664 | #define ICON_FA_THERMOMETER_HALF "\xef\x8b\x89" // U+f2c9 665 | #define ICON_FA_THERMOMETER_QUARTER "\xef\x8b\x8a" // U+f2ca 666 | #define ICON_FA_THERMOMETER_EMPTY "\xef\x8b\x8b" // U+f2cb 667 | #define ICON_FA_SHOWER "\xef\x8b\x8c" // U+f2cc 668 | #define ICON_FA_BATH "\xef\x8b\x8d" // U+f2cd 669 | #define ICON_FA_PODCAST "\xef\x8b\x8e" // U+f2ce 670 | #define ICON_FA_WINDOW_MAXIMIZE "\xef\x8b\x90" // U+f2d0 671 | #define ICON_FA_WINDOW_MINIMIZE "\xef\x8b\x91" // U+f2d1 672 | #define ICON_FA_WINDOW_RESTORE "\xef\x8b\x92" // U+f2d2 673 | #define ICON_FA_WINDOW_CLOSE "\xef\x8b\x93" // U+f2d3 674 | #define ICON_FA_WINDOW_CLOSE_O "\xef\x8b\x94" // U+f2d4 675 | #define ICON_FA_BANDCAMP "\xef\x8b\x95" // U+f2d5 676 | #define ICON_FA_GRAV "\xef\x8b\x96" // U+f2d6 677 | #define ICON_FA_ETSY "\xef\x8b\x97" // U+f2d7 678 | #define ICON_FA_IMDB "\xef\x8b\x98" // U+f2d8 679 | #define ICON_FA_RAVELRY "\xef\x8b\x99" // U+f2d9 680 | #define ICON_FA_EERCAST "\xef\x8b\x9a" // U+f2da 681 | #define ICON_FA_MICROCHIP "\xef\x8b\x9b" // U+f2db 682 | #define ICON_FA_SNOWFLAKE_O "\xef\x8b\x9c" // U+f2dc 683 | #define ICON_FA_SUPERPOWERS "\xef\x8b\x9d" // U+f2dd 684 | #define ICON_FA_WPEXPLORER "\xef\x8b\x9e" // U+f2de 685 | #define ICON_FA_MEETUP "\xef\x8b\xa0" // U+f2e0 686 | -------------------------------------------------------------------------------- /ImGui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2023 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ImGui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | //#define IMGUI_INCLUDE_IMGUI_USER_H 54 | 55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 56 | //#define IMGUI_USE_BGRA_PACKED_COLOR 57 | 58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 59 | //#define IMGUI_USE_WCHAR32 60 | 61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 69 | 70 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 71 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 72 | //#define IMGUI_USE_STB_SPRINTF 73 | 74 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 75 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 76 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 77 | //#define IMGUI_ENABLE_FREETYPE 78 | 79 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 80 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 81 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 82 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 83 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 84 | 85 | //---- Use stb_truetype to build and rasterize the font atlas (default) 86 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 87 | //#define IMGUI_ENABLE_STB_TRUETYPE 88 | 89 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 90 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 91 | /* 92 | #define IM_VEC2_CLASS_EXTRA \ 93 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 94 | operator MyVec2() const { return MyVec2(x,y); } 95 | 96 | #define IM_VEC4_CLASS_EXTRA \ 97 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 98 | operator MyVec4() const { return MyVec4(x,y,z,w); } 99 | */ 100 | //---- ...Or use Dear ImGui's own very basic math operators. 101 | #define IMGUI_DEFINE_MATH_OPERATORS 102 | 103 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 104 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 105 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 106 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 107 | //#define ImDrawIdx unsigned int 108 | 109 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 110 | //struct ImDrawList; 111 | //struct ImDrawCmd; 112 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 113 | //#define ImDrawCallback MyImDrawCallback 114 | 115 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 116 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 117 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 118 | //#define IM_DEBUG_BREAK __debugbreak() 119 | 120 | //---- Debug Tools: Enable slower asserts 121 | //#define IMGUI_DEBUG_PARANOID 122 | 123 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 124 | /* 125 | namespace ImGui 126 | { 127 | void MyFunction(const char* name, MyMatrix44* mtx); 128 | } 129 | */ 130 | -------------------------------------------------------------------------------- /ImGui/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Dear ImGui Demo] 2 | ViewportPos=710,89 3 | ViewportId=0xE927CF2F 4 | Size=550,680 5 | Collapsed=0 6 | 7 | [Window][Hello, world!] 8 | Pos=60,60 9 | Size=339,180 10 | Collapsed=0 11 | 12 | [Window][Debug##Default] 13 | Pos=65,154 14 | Size=930,437 15 | Collapsed=0 16 | 17 | [Docking][Data] 18 | 19 | -------------------------------------------------------------------------------- /ImGui/imgui_impl_dx12.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX12 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 8 | 9 | // Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'. 10 | // See imgui_impl_dx12.cpp file for details. 11 | 12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 14 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 15 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | #ifndef IMGUI_DISABLE 20 | #include // DXGI_FORMAT 21 | 22 | struct ID3D12Device; 23 | struct ID3D12DescriptorHeap; 24 | struct ID3D12GraphicsCommandList; 25 | struct D3D12_CPU_DESCRIPTOR_HANDLE; 26 | struct D3D12_GPU_DESCRIPTOR_HANDLE; 27 | 28 | // cmd_list is the command list that the implementation will use to render imgui draw lists. 29 | // Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate 30 | // render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. 31 | // font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. 32 | IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, 33 | D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); 34 | IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); 35 | IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); 36 | IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list); 37 | 38 | // Use if you want to reset your rendering device without losing Dear ImGui state. 39 | IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); 40 | IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(); 41 | 42 | #endif // #ifndef IMGUI_DISABLE 43 | -------------------------------------------------------------------------------- /ImGui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 11 | 12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 14 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 15 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | #ifndef IMGUI_DISABLE 20 | 21 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 22 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); 23 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 24 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 25 | 26 | // Win32 message handler your application need to call. 27 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 28 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 29 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 30 | 31 | #if 0 32 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 33 | #endif 34 | 35 | // DPI-related helpers (optional) 36 | // - Use to enable DPI awareness without having to create an application manifest. 37 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 38 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 39 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 40 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 41 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 42 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 43 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 44 | 45 | // Transparency related helpers (optional) [experimental] 46 | // - Use to enable alpha compositing transparency with the desktop. 47 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 48 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 49 | 50 | #endif // #ifndef IMGUI_DISABLE 51 | -------------------------------------------------------------------------------- /ImGui/imstb_rectpack.h: -------------------------------------------------------------------------------- 1 | // [DEAR IMGUI] 2 | // This is a slightly modified version of stb_rect_pack.h 1.01. 3 | // Grep for [DEAR IMGUI] to find the changes. 4 | // 5 | // stb_rect_pack.h - v1.01 - public domain - rectangle packing 6 | // Sean Barrett 2014 7 | // 8 | // Useful for e.g. packing rectangular textures into an atlas. 9 | // Does not do rotation. 10 | // 11 | // Before #including, 12 | // 13 | // #define STB_RECT_PACK_IMPLEMENTATION 14 | // 15 | // in the file that you want to have the implementation. 16 | // 17 | // Not necessarily the awesomest packing method, but better than 18 | // the totally naive one in stb_truetype (which is primarily what 19 | // this is meant to replace). 20 | // 21 | // Has only had a few tests run, may have issues. 22 | // 23 | // More docs to come. 24 | // 25 | // No memory allocations; uses qsort() and assert() from stdlib. 26 | // Can override those by defining STBRP_SORT and STBRP_ASSERT. 27 | // 28 | // This library currently uses the Skyline Bottom-Left algorithm. 29 | // 30 | // Please note: better rectangle packers are welcome! Please 31 | // implement them to the same API, but with a different init 32 | // function. 33 | // 34 | // Credits 35 | // 36 | // Library 37 | // Sean Barrett 38 | // Minor features 39 | // Martins Mozeiko 40 | // github:IntellectualKitty 41 | // 42 | // Bugfixes / warning fixes 43 | // Jeremy Jaussaud 44 | // Fabian Giesen 45 | // 46 | // Version history: 47 | // 48 | // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section 49 | // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles 50 | // 0.99 (2019-02-07) warning fixes 51 | // 0.11 (2017-03-03) return packing success/fail result 52 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings 53 | // 0.09 (2016-08-27) fix compiler warnings 54 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) 55 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) 56 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort 57 | // 0.05: added STBRP_ASSERT to allow replacing assert 58 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support 59 | // 0.01: initial release 60 | // 61 | // LICENSE 62 | // 63 | // See end of file for license information. 64 | 65 | ////////////////////////////////////////////////////////////////////////////// 66 | // 67 | // INCLUDE SECTION 68 | // 69 | 70 | #ifndef STB_INCLUDE_STB_RECT_PACK_H 71 | #define STB_INCLUDE_STB_RECT_PACK_H 72 | 73 | #define STB_RECT_PACK_VERSION 1 74 | 75 | #ifdef STBRP_STATIC 76 | #define STBRP_DEF static 77 | #else 78 | #define STBRP_DEF extern 79 | #endif 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | 85 | typedef struct stbrp_context stbrp_context; 86 | typedef struct stbrp_node stbrp_node; 87 | typedef struct stbrp_rect stbrp_rect; 88 | 89 | typedef int stbrp_coord; 90 | 91 | #define STBRP__MAXVAL 0x7fffffff 92 | // Mostly for internal use, but this is the maximum supported coordinate value. 93 | 94 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); 95 | // Assign packed locations to rectangles. The rectangles are of type 96 | // 'stbrp_rect' defined below, stored in the array 'rects', and there 97 | // are 'num_rects' many of them. 98 | // 99 | // Rectangles which are successfully packed have the 'was_packed' flag 100 | // set to a non-zero value and 'x' and 'y' store the minimum location 101 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left 102 | // if you imagine y increasing downwards). Rectangles which do not fit 103 | // have the 'was_packed' flag set to 0. 104 | // 105 | // You should not try to access the 'rects' array from another thread 106 | // while this function is running, as the function temporarily reorders 107 | // the array while it executes. 108 | // 109 | // To pack into another rectangle, you need to call stbrp_init_target 110 | // again. To continue packing into the same rectangle, you can call 111 | // this function again. Calling this multiple times with multiple rect 112 | // arrays will probably produce worse packing results than calling it 113 | // a single time with the full rectangle array, but the option is 114 | // available. 115 | // 116 | // The function returns 1 if all of the rectangles were successfully 117 | // packed and 0 otherwise. 118 | 119 | struct stbrp_rect 120 | { 121 | // reserved for your use: 122 | int id; 123 | 124 | // input: 125 | stbrp_coord w, h; 126 | 127 | // output: 128 | stbrp_coord x, y; 129 | int was_packed; // non-zero if valid packing 130 | 131 | }; // 16 bytes, nominally 132 | 133 | 134 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); 135 | // Initialize a rectangle packer to: 136 | // pack a rectangle that is 'width' by 'height' in dimensions 137 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long 138 | // 139 | // You must call this function every time you start packing into a new target. 140 | // 141 | // There is no "shutdown" function. The 'nodes' memory must stay valid for 142 | // the following stbrp_pack_rects() call (or calls), but can be freed after 143 | // the call (or calls) finish. 144 | // 145 | // Note: to guarantee best results, either: 146 | // 1. make sure 'num_nodes' >= 'width' 147 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' 148 | // 149 | // If you don't do either of the above things, widths will be quantized to multiples 150 | // of small integers to guarantee the algorithm doesn't run out of temporary storage. 151 | // 152 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm 153 | // may run out of temporary storage and be unable to pack some rectangles. 154 | 155 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); 156 | // Optionally call this function after init but before doing any packing to 157 | // change the handling of the out-of-temp-memory scenario, described above. 158 | // If you call init again, this will be reset to the default (false). 159 | 160 | 161 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); 162 | // Optionally select which packing heuristic the library should use. Different 163 | // heuristics will produce better/worse results for different data sets. 164 | // If you call init again, this will be reset to the default. 165 | 166 | enum 167 | { 168 | STBRP_HEURISTIC_Skyline_default=0, 169 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, 170 | STBRP_HEURISTIC_Skyline_BF_sortHeight 171 | }; 172 | 173 | 174 | ////////////////////////////////////////////////////////////////////////////// 175 | // 176 | // the details of the following structures don't matter to you, but they must 177 | // be visible so you can handle the memory allocations for them 178 | 179 | struct stbrp_node 180 | { 181 | stbrp_coord x,y; 182 | stbrp_node *next; 183 | }; 184 | 185 | struct stbrp_context 186 | { 187 | int width; 188 | int height; 189 | int align; 190 | int init_mode; 191 | int heuristic; 192 | int num_nodes; 193 | stbrp_node *active_head; 194 | stbrp_node *free_head; 195 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' 196 | }; 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif 203 | 204 | ////////////////////////////////////////////////////////////////////////////// 205 | // 206 | // IMPLEMENTATION SECTION 207 | // 208 | 209 | #ifdef STB_RECT_PACK_IMPLEMENTATION 210 | #ifndef STBRP_SORT 211 | #include 212 | #define STBRP_SORT qsort 213 | #endif 214 | 215 | #ifndef STBRP_ASSERT 216 | #include 217 | #define STBRP_ASSERT assert 218 | #endif 219 | 220 | #ifdef _MSC_VER 221 | #define STBRP__NOTUSED(v) (void)(v) 222 | #define STBRP__CDECL __cdecl 223 | #else 224 | #define STBRP__NOTUSED(v) (void)sizeof(v) 225 | #define STBRP__CDECL 226 | #endif 227 | 228 | enum 229 | { 230 | STBRP__INIT_skyline = 1 231 | }; 232 | 233 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) 234 | { 235 | switch (context->init_mode) { 236 | case STBRP__INIT_skyline: 237 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); 238 | context->heuristic = heuristic; 239 | break; 240 | default: 241 | STBRP_ASSERT(0); 242 | } 243 | } 244 | 245 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) 246 | { 247 | if (allow_out_of_mem) 248 | // if it's ok to run out of memory, then don't bother aligning them; 249 | // this gives better packing, but may fail due to OOM (even though 250 | // the rectangles easily fit). @TODO a smarter approach would be to only 251 | // quantize once we've hit OOM, then we could get rid of this parameter. 252 | context->align = 1; 253 | else { 254 | // if it's not ok to run out of memory, then quantize the widths 255 | // so that num_nodes is always enough nodes. 256 | // 257 | // I.e. num_nodes * align >= width 258 | // align >= width / num_nodes 259 | // align = ceil(width/num_nodes) 260 | 261 | context->align = (context->width + context->num_nodes-1) / context->num_nodes; 262 | } 263 | } 264 | 265 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) 266 | { 267 | int i; 268 | 269 | for (i=0; i < num_nodes-1; ++i) 270 | nodes[i].next = &nodes[i+1]; 271 | nodes[i].next = NULL; 272 | context->init_mode = STBRP__INIT_skyline; 273 | context->heuristic = STBRP_HEURISTIC_Skyline_default; 274 | context->free_head = &nodes[0]; 275 | context->active_head = &context->extra[0]; 276 | context->width = width; 277 | context->height = height; 278 | context->num_nodes = num_nodes; 279 | stbrp_setup_allow_out_of_mem(context, 0); 280 | 281 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) 282 | context->extra[0].x = 0; 283 | context->extra[0].y = 0; 284 | context->extra[0].next = &context->extra[1]; 285 | context->extra[1].x = (stbrp_coord) width; 286 | context->extra[1].y = (1<<30); 287 | context->extra[1].next = NULL; 288 | } 289 | 290 | // find minimum y position if it starts at x1 291 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) 292 | { 293 | stbrp_node *node = first; 294 | int x1 = x0 + width; 295 | int min_y, visited_width, waste_area; 296 | 297 | STBRP__NOTUSED(c); 298 | 299 | STBRP_ASSERT(first->x <= x0); 300 | 301 | #if 0 302 | // skip in case we're past the node 303 | while (node->next->x <= x0) 304 | ++node; 305 | #else 306 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency 307 | #endif 308 | 309 | STBRP_ASSERT(node->x <= x0); 310 | 311 | min_y = 0; 312 | waste_area = 0; 313 | visited_width = 0; 314 | while (node->x < x1) { 315 | if (node->y > min_y) { 316 | // raise min_y higher. 317 | // we've accounted for all waste up to min_y, 318 | // but we'll now add more waste for everything we've visted 319 | waste_area += visited_width * (node->y - min_y); 320 | min_y = node->y; 321 | // the first time through, visited_width might be reduced 322 | if (node->x < x0) 323 | visited_width += node->next->x - x0; 324 | else 325 | visited_width += node->next->x - node->x; 326 | } else { 327 | // add waste area 328 | int under_width = node->next->x - node->x; 329 | if (under_width + visited_width > width) 330 | under_width = width - visited_width; 331 | waste_area += under_width * (min_y - node->y); 332 | visited_width += under_width; 333 | } 334 | node = node->next; 335 | } 336 | 337 | *pwaste = waste_area; 338 | return min_y; 339 | } 340 | 341 | typedef struct 342 | { 343 | int x,y; 344 | stbrp_node **prev_link; 345 | } stbrp__findresult; 346 | 347 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) 348 | { 349 | int best_waste = (1<<30), best_x, best_y = (1 << 30); 350 | stbrp__findresult fr; 351 | stbrp_node **prev, *node, *tail, **best = NULL; 352 | 353 | // align to multiple of c->align 354 | width = (width + c->align - 1); 355 | width -= width % c->align; 356 | STBRP_ASSERT(width % c->align == 0); 357 | 358 | // if it can't possibly fit, bail immediately 359 | if (width > c->width || height > c->height) { 360 | fr.prev_link = NULL; 361 | fr.x = fr.y = 0; 362 | return fr; 363 | } 364 | 365 | node = c->active_head; 366 | prev = &c->active_head; 367 | while (node->x + width <= c->width) { 368 | int y,waste; 369 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); 370 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL 371 | // bottom left 372 | if (y < best_y) { 373 | best_y = y; 374 | best = prev; 375 | } 376 | } else { 377 | // best-fit 378 | if (y + height <= c->height) { 379 | // can only use it if it first vertically 380 | if (y < best_y || (y == best_y && waste < best_waste)) { 381 | best_y = y; 382 | best_waste = waste; 383 | best = prev; 384 | } 385 | } 386 | } 387 | prev = &node->next; 388 | node = node->next; 389 | } 390 | 391 | best_x = (best == NULL) ? 0 : (*best)->x; 392 | 393 | // if doing best-fit (BF), we also have to try aligning right edge to each node position 394 | // 395 | // e.g, if fitting 396 | // 397 | // ____________________ 398 | // |____________________| 399 | // 400 | // into 401 | // 402 | // | | 403 | // | ____________| 404 | // |____________| 405 | // 406 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned 407 | // 408 | // This makes BF take about 2x the time 409 | 410 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { 411 | tail = c->active_head; 412 | node = c->active_head; 413 | prev = &c->active_head; 414 | // find first node that's admissible 415 | while (tail->x < width) 416 | tail = tail->next; 417 | while (tail) { 418 | int xpos = tail->x - width; 419 | int y,waste; 420 | STBRP_ASSERT(xpos >= 0); 421 | // find the left position that matches this 422 | while (node->next->x <= xpos) { 423 | prev = &node->next; 424 | node = node->next; 425 | } 426 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); 427 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); 428 | if (y + height <= c->height) { 429 | if (y <= best_y) { 430 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { 431 | best_x = xpos; 432 | //STBRP_ASSERT(y <= best_y); [DEAR IMGUI] 433 | best_y = y; 434 | best_waste = waste; 435 | best = prev; 436 | } 437 | } 438 | } 439 | tail = tail->next; 440 | } 441 | } 442 | 443 | fr.prev_link = best; 444 | fr.x = best_x; 445 | fr.y = best_y; 446 | return fr; 447 | } 448 | 449 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) 450 | { 451 | // find best position according to heuristic 452 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); 453 | stbrp_node *node, *cur; 454 | 455 | // bail if: 456 | // 1. it failed 457 | // 2. the best node doesn't fit (we don't always check this) 458 | // 3. we're out of memory 459 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { 460 | res.prev_link = NULL; 461 | return res; 462 | } 463 | 464 | // on success, create new node 465 | node = context->free_head; 466 | node->x = (stbrp_coord) res.x; 467 | node->y = (stbrp_coord) (res.y + height); 468 | 469 | context->free_head = node->next; 470 | 471 | // insert the new node into the right starting point, and 472 | // let 'cur' point to the remaining nodes needing to be 473 | // stiched back in 474 | 475 | cur = *res.prev_link; 476 | if (cur->x < res.x) { 477 | // preserve the existing one, so start testing with the next one 478 | stbrp_node *next = cur->next; 479 | cur->next = node; 480 | cur = next; 481 | } else { 482 | *res.prev_link = node; 483 | } 484 | 485 | // from here, traverse cur and free the nodes, until we get to one 486 | // that shouldn't be freed 487 | while (cur->next && cur->next->x <= res.x + width) { 488 | stbrp_node *next = cur->next; 489 | // move the current node to the free list 490 | cur->next = context->free_head; 491 | context->free_head = cur; 492 | cur = next; 493 | } 494 | 495 | // stitch the list back in 496 | node->next = cur; 497 | 498 | if (cur->x < res.x + width) 499 | cur->x = (stbrp_coord) (res.x + width); 500 | 501 | #ifdef _DEBUG 502 | cur = context->active_head; 503 | while (cur->x < context->width) { 504 | STBRP_ASSERT(cur->x < cur->next->x); 505 | cur = cur->next; 506 | } 507 | STBRP_ASSERT(cur->next == NULL); 508 | 509 | { 510 | int count=0; 511 | cur = context->active_head; 512 | while (cur) { 513 | cur = cur->next; 514 | ++count; 515 | } 516 | cur = context->free_head; 517 | while (cur) { 518 | cur = cur->next; 519 | ++count; 520 | } 521 | STBRP_ASSERT(count == context->num_nodes+2); 522 | } 523 | #endif 524 | 525 | return res; 526 | } 527 | 528 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b) 529 | { 530 | const stbrp_rect *p = (const stbrp_rect *) a; 531 | const stbrp_rect *q = (const stbrp_rect *) b; 532 | if (p->h > q->h) 533 | return -1; 534 | if (p->h < q->h) 535 | return 1; 536 | return (p->w > q->w) ? -1 : (p->w < q->w); 537 | } 538 | 539 | static int STBRP__CDECL rect_original_order(const void *a, const void *b) 540 | { 541 | const stbrp_rect *p = (const stbrp_rect *) a; 542 | const stbrp_rect *q = (const stbrp_rect *) b; 543 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); 544 | } 545 | 546 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) 547 | { 548 | int i, all_rects_packed = 1; 549 | 550 | // we use the 'was_packed' field internally to allow sorting/unsorting 551 | for (i=0; i < num_rects; ++i) { 552 | rects[i].was_packed = i; 553 | } 554 | 555 | // sort according to heuristic 556 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); 557 | 558 | for (i=0; i < num_rects; ++i) { 559 | if (rects[i].w == 0 || rects[i].h == 0) { 560 | rects[i].x = rects[i].y = 0; // empty rect needs no space 561 | } else { 562 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); 563 | if (fr.prev_link) { 564 | rects[i].x = (stbrp_coord) fr.x; 565 | rects[i].y = (stbrp_coord) fr.y; 566 | } else { 567 | rects[i].x = rects[i].y = STBRP__MAXVAL; 568 | } 569 | } 570 | } 571 | 572 | // unsort 573 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); 574 | 575 | // set was_packed flags and all_rects_packed status 576 | for (i=0; i < num_rects; ++i) { 577 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); 578 | if (!rects[i].was_packed) 579 | all_rects_packed = 0; 580 | } 581 | 582 | // return the all_rects_packed status 583 | return all_rects_packed; 584 | } 585 | #endif 586 | 587 | /* 588 | ------------------------------------------------------------------------------ 589 | This software is available under 2 licenses -- choose whichever you prefer. 590 | ------------------------------------------------------------------------------ 591 | ALTERNATIVE A - MIT License 592 | Copyright (c) 2017 Sean Barrett 593 | Permission is hereby granted, free of charge, to any person obtaining a copy of 594 | this software and associated documentation files (the "Software"), to deal in 595 | the Software without restriction, including without limitation the rights to 596 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 597 | of the Software, and to permit persons to whom the Software is furnished to do 598 | so, subject to the following conditions: 599 | The above copyright notice and this permission notice shall be included in all 600 | copies or substantial portions of the Software. 601 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 602 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 603 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 604 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 605 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 606 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 607 | SOFTWARE. 608 | ------------------------------------------------------------------------------ 609 | ALTERNATIVE B - Public Domain (www.unlicense.org) 610 | This is free and unencumbered software released into the public domain. 611 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 612 | software, either in source code form or as a compiled binary, for any purpose, 613 | commercial or non-commercial, and by any means. 614 | In jurisdictions that recognize copyright laws, the author or authors of this 615 | software dedicate any and all copyright interest in the software to the public 616 | domain. We make this dedication for the benefit of the public at large and to 617 | the detriment of our heirs and successors. We intend this dedication to be an 618 | overt act of relinquishment in perpetuity of all present and future rights to 619 | this software under copyright law. 620 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 621 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 622 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 623 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 624 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 625 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 626 | ------------------------------------------------------------------------------ 627 | */ 628 | -------------------------------------------------------------------------------- /ImGuiProfiler.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiProfiler", "ImGuiProfiler.vcxproj", "{C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Debug|x64.ActiveCfg = Debug|x64 17 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Debug|x64.Build.0 = Debug|x64 18 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Debug|x86.Build.0 = Debug|Win32 20 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Release|x64.ActiveCfg = Release|x64 21 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Release|x64.Build.0 = Release|x64 22 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Release|x86.ActiveCfg = Release|Win32 23 | {C89A478E-D4D0-4A65-8D3E-98AE7BD4929C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {77272787-8C32-4F17-B9A0-C7FA5D1D7D25} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ImGuiProfiler.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 16.0 47 | Win32Proj 48 | {c89a478e-d4d0-4a65-8d3e-98ae7bd4929c} 49 | ImGuiProfiler 50 | 10.0 51 | 52 | 53 | 54 | Application 55 | true 56 | v143 57 | Unicode 58 | 59 | 60 | Application 61 | false 62 | v143 63 | true 64 | Unicode 65 | 66 | 67 | Application 68 | true 69 | v143 70 | Unicode 71 | 72 | 73 | Application 74 | false 75 | v143 76 | true 77 | Unicode 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 102 | true 103 | 104 | 105 | Console 106 | true 107 | dxgi.lib;d3d12.lib;%(AdditionalDependencies) 108 | 109 | 110 | 111 | 112 | Level3 113 | true 114 | true 115 | true 116 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 117 | true 118 | 119 | 120 | Console 121 | true 122 | true 123 | true 124 | dxgi.lib;d3d12.lib;%(AdditionalDependencies) 125 | 126 | 127 | 128 | 129 | Level3 130 | true 131 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | stdcpp20 134 | 135 | 136 | Console 137 | true 138 | dxgi.lib;d3d12.lib;%(AdditionalDependencies) 139 | 140 | 141 | 142 | 143 | Level3 144 | true 145 | true 146 | true 147 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 148 | true 149 | 150 | 151 | Console 152 | true 153 | true 154 | true 155 | dxgi.lib;d3d12.lib;%(AdditionalDependencies) 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /ImGuiProfiler.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | -------------------------------------------------------------------------------- /ImGuiProfiler.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simco50/TimelineProfiler/f8ffd365226e2bbce74db1a6b024c8681ae85f33/Image.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Simon Coenen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------------------- 24 | 25 | 26 | FontAwesomeCpp License 27 | 28 | Copyright (c) 2017 Juliette Foucaut and Doug Binks 29 | 30 | This software is provided 'as-is', without any express or implied 31 | warranty. In no event will the authors be held liable for any damages 32 | arising from the use of this software. 33 | 34 | Permission is granted to anyone to use this software for any purpose, 35 | including commercial applications, and to alter it and redistribute it 36 | freely, subject to the following restrictions: 37 | 38 | 1. The origin of this software must not be misrepresented; you must not 39 | claim that you wrote the original software. If you use this software 40 | in a product, an acknowledgment in the product documentation would be 41 | appreciated but is not required. 42 | 2. Altered source versions must be plainly marked as such, and must not be 43 | misrepresented as being the original software. 44 | 3. This notice may not be removed or altered from any source distribution.{\rtf1} -------------------------------------------------------------------------------- /Profiler.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Profiler.h" 3 | 4 | #if WITH_PROFILING 5 | 6 | CPUProfiler gCPUProfiler; 7 | GPUProfiler gGPUProfiler; 8 | 9 | //----------------------------------------------------------------------------- 10 | // [SECTION] GPU Profiler 11 | //----------------------------------------------------------------------------- 12 | 13 | void GPUProfiler::Initialize( 14 | ID3D12Device* pDevice, 15 | Span queues, 16 | uint32 sampleHistory, 17 | uint32 frameLatency, 18 | uint32 maxNumEvents, 19 | uint32 maxNumCopyEvents, 20 | uint32 maxNumActiveCommandLists) 21 | { 22 | m_FrameLatency = frameLatency; 23 | m_EventHistorySize = sampleHistory; 24 | 25 | m_CommandListData.Setup(maxNumActiveCommandLists); 26 | 27 | for (uint16 queueIndex = 0; queueIndex < queues.size(); ++queueIndex) 28 | { 29 | ID3D12CommandQueue* pQueue = queues[queueIndex]; 30 | D3D12_COMMAND_QUEUE_DESC desc = pQueue->GetDesc(); 31 | 32 | m_QueueIndexMap[pQueue] = (uint32)m_Queues.size(); 33 | QueueInfo& queueInfo = m_Queues.emplace_back(); 34 | uint32 size = ARRAYSIZE(queueInfo.Name); 35 | pQueue->GetPrivateData(WKPDID_D3DDebugObjectName, &size, queueInfo.Name); 36 | queueInfo.pQueue = pQueue; 37 | queueInfo.InitCalibration(); 38 | 39 | if (desc.Type == D3D12_COMMAND_LIST_TYPE_COPY && !m_CopyHeap.IsInitialized()) 40 | m_CopyHeap.Initialize(pDevice, pQueue, 2 * maxNumCopyEvents, frameLatency); 41 | else if (desc.Type != D3D12_COMMAND_LIST_TYPE_COPY && !m_MainHeap.IsInitialized()) 42 | m_MainHeap.Initialize(pDevice, pQueue, 2 * maxNumEvents, frameLatency); 43 | } 44 | 45 | m_pEventData = new EventData[sampleHistory]; 46 | for (uint32 i = 0; i < sampleHistory; ++i) 47 | { 48 | EventData& eventData = m_pEventData[i]; 49 | eventData.Events.resize(maxNumEvents + maxNumCopyEvents); 50 | eventData.EventsPerQueue.resize(queues.size()); 51 | } 52 | 53 | m_pQueryData = new QueryData[frameLatency]; 54 | for (uint32 i = 0; i < frameLatency; ++i) 55 | { 56 | QueryData& queryData = m_pQueryData[i]; 57 | queryData.Ranges.resize(maxNumEvents + maxNumCopyEvents); 58 | } 59 | } 60 | 61 | void GPUProfiler::Shutdown() 62 | { 63 | delete[] m_pEventData; 64 | delete[] m_pQueryData; 65 | 66 | m_CopyHeap.Shutdown(); 67 | m_MainHeap.Shutdown(); 68 | } 69 | 70 | 71 | void GPUProfiler::BeginEvent(ID3D12GraphicsCommandList* pCmd, const char* pName, const char* pFilePath, uint32 lineNumber) 72 | { 73 | if (m_EventCallback.OnEventBegin) 74 | m_EventCallback.OnEventBegin(pName, pCmd, m_EventCallback.pUserData); 75 | 76 | if (m_IsPaused) 77 | return; 78 | 79 | QueryData& queryData = GetQueryData(); 80 | EventData& eventData = GetSampleFrame(); 81 | CommandListData::Data* pCmdData = m_CommandListData.Get(pCmd, true); 82 | 83 | // Allocate a query range. This stores a begin/end query index pair. (Also event index) 84 | uint32 eventIndex = m_EventIndex.fetch_add(1); 85 | check(eventIndex < eventData.Events.size()); 86 | 87 | // Record a timestamp query 88 | uint32 queryIndex = GetHeap(pCmd->GetType()).RecordQuery(pCmd); 89 | 90 | // Assign the query to the commandlist 91 | CommandListData::Data::Query& cmdListQuery = pCmdData->Queries.emplace_back(); 92 | cmdListQuery.QueryIndex = queryIndex; 93 | cmdListQuery.RangeIndex = eventIndex; 94 | cmdListQuery.IsBegin = true; 95 | 96 | // Allocate a query range in the query frame 97 | QueryData::QueryRange& range = queryData.Ranges[eventIndex]; 98 | range.QueryIndexBegin = queryIndex; 99 | range.IsCopyQuery = pCmd->GetType() == D3D12_COMMAND_LIST_TYPE_COPY; 100 | 101 | // Allocate an event in the sample history 102 | EventData::Event& event = eventData.Events[eventIndex]; 103 | event.Index = eventIndex; 104 | event.pName = eventData.Allocator.String(pName); 105 | event.pFilePath = pFilePath; 106 | event.LineNumber = lineNumber; 107 | } 108 | 109 | 110 | void GPUProfiler::EndEvent(ID3D12GraphicsCommandList* pCmd) 111 | { 112 | if (m_EventCallback.OnEventEnd) 113 | m_EventCallback.OnEventEnd(pCmd, m_EventCallback.pUserData); 114 | 115 | if (m_IsPaused) 116 | return; 117 | 118 | // Record a query in the commandlist 119 | CommandListData::Data* pCmdData = m_CommandListData.Get(pCmd, true); 120 | CommandListData::Data::Query& query = pCmdData->Queries.emplace_back(); 121 | query.QueryIndex = GetHeap(pCmd->GetType()).RecordQuery(pCmd); 122 | query.RangeIndex = 0x7FFF; // Range index is only required for 'Begin' events 123 | query.IsBegin = false; 124 | } 125 | 126 | void GPUProfiler::Tick() 127 | { 128 | // If the next frame is not finished resolving, wait for it here so the data can be read from before it's being reset 129 | m_CopyHeap.WaitFrame(m_FrameIndex); 130 | m_MainHeap.WaitFrame(m_FrameIndex); 131 | 132 | GetSampleFrame(m_FrameIndex).NumEvents = m_EventIndex; 133 | m_EventIndex = 0; 134 | 135 | while (m_FrameToReadback < m_FrameIndex) 136 | { 137 | QueryData& queryData = GetQueryData(m_FrameToReadback); 138 | EventData& eventData = GetSampleFrame(m_FrameToReadback); 139 | if (!m_MainHeap.IsFrameComplete(m_FrameToReadback) || !m_CopyHeap.IsFrameComplete(m_FrameToReadback)) 140 | break; 141 | 142 | uint32 numEvents = eventData.NumEvents; 143 | Span mainQueries = m_MainHeap.GetQueryData(m_FrameToReadback); 144 | Span copyQueries = m_CopyHeap.GetQueryData(m_FrameToReadback); 145 | 146 | for (uint32 i = 0; i < numEvents; ++i) 147 | { 148 | QueryData::QueryRange& queryRange = queryData.Ranges[i]; 149 | EventData::Event& event = eventData.Events[i]; 150 | event.TicksBegin = queryRange.IsCopyQuery ? copyQueries[queryRange.QueryIndexBegin] : mainQueries[queryRange.QueryIndexBegin]; 151 | event.TicksEnd = queryRange.IsCopyQuery ? copyQueries[queryRange.QueryIndexEnd] : mainQueries[queryRange.QueryIndexEnd]; 152 | } 153 | 154 | // Sort events by queue 155 | std::vector& events = eventData.Events; 156 | std::sort(events.begin(), events.begin() + numEvents, [](const EventData::Event& a, const EventData::Event& b) 157 | { 158 | return a.QueueIndex < b.QueueIndex; 159 | }); 160 | 161 | URange eventRange(0, 0); 162 | for (uint32 queueIndex = 0; queueIndex < (uint32)m_Queues.size(); ++queueIndex) 163 | { 164 | while (queueIndex < events[eventRange.Begin].QueueIndex) 165 | eventRange.Begin++; 166 | eventRange.End = eventRange.Begin; 167 | while (events[eventRange.End].QueueIndex == queueIndex && eventRange.End < numEvents) 168 | ++eventRange.End; 169 | 170 | eventData.EventsPerQueue[queueIndex] = Span(&events[eventRange.Begin], eventRange.End - eventRange.Begin); 171 | eventRange.Begin = eventRange.End; 172 | } 173 | 174 | ++m_FrameToReadback; 175 | } 176 | 177 | m_IsPaused = m_PauseQueued; 178 | if (m_IsPaused) 179 | return; 180 | 181 | m_CommandListData.Reset(); 182 | 183 | { 184 | m_MainHeap.Resolve(m_FrameIndex); 185 | m_CopyHeap.Resolve(m_FrameIndex); 186 | } 187 | 188 | ++m_FrameIndex; 189 | 190 | { 191 | m_MainHeap.Reset(m_FrameIndex); 192 | m_CopyHeap.Reset(m_FrameIndex); 193 | 194 | EventData& eventFrame = GetSampleFrame(); 195 | eventFrame.NumEvents = 0; 196 | eventFrame.Allocator.Reset(); 197 | for (uint32 i = 0; i < (uint32)m_Queues.size(); ++i) 198 | eventFrame.EventsPerQueue[i] = {}; 199 | } 200 | } 201 | 202 | void GPUProfiler::ExecuteCommandLists(ID3D12CommandQueue* pQueue, Span commandLists) 203 | { 204 | if (m_IsPaused) 205 | return; 206 | 207 | QueryData& queryData = GetQueryData(); 208 | EventData& sampleFrame = GetSampleFrame(); 209 | 210 | std::vector queryRangeStack; 211 | for (ID3D12CommandList* pCmd : commandLists) 212 | { 213 | CommandListData::Data* pEventData = m_CommandListData.Get(pCmd, false); 214 | if (pEventData) 215 | { 216 | for (CommandListData::Data::Query& query : pEventData->Queries) 217 | { 218 | if (query.IsBegin) 219 | { 220 | queryRangeStack.push_back(query.RangeIndex); 221 | } 222 | else 223 | { 224 | check(!queryRangeStack.empty(), "Event Begin/End mismatch"); 225 | check(query.RangeIndex == 0x7FFF); 226 | uint32 queryRangeIndex = queryRangeStack.back(); 227 | queryRangeStack.pop_back(); 228 | 229 | QueryData::QueryRange& queryRange = queryData.Ranges[queryRangeIndex]; 230 | EventData::Event& sampleEvent = sampleFrame.Events[queryRangeIndex]; 231 | 232 | queryRange.QueryIndexEnd = query.QueryIndex; 233 | sampleEvent.QueueIndex = m_QueueIndexMap[pQueue]; 234 | sampleEvent.Depth = (uint32)queryRangeStack.size(); 235 | } 236 | } 237 | pEventData->Queries.clear(); 238 | } 239 | } 240 | check(queryRangeStack.empty(), "Forgot to End %d Events", queryRangeStack.size()); 241 | } 242 | 243 | 244 | void GPUProfiler::QueryHeap::Initialize(ID3D12Device* pDevice, ID3D12CommandQueue* pResolveQueue, uint32 maxNumQueries, uint32 frameLatency) 245 | { 246 | m_pResolveQueue = pResolveQueue; 247 | m_FrameLatency = frameLatency; 248 | m_MaxNumQueries = maxNumQueries; 249 | 250 | D3D12_COMMAND_QUEUE_DESC queueDesc = pResolveQueue->GetDesc(); 251 | 252 | D3D12_QUERY_HEAP_DESC heapDesc{}; 253 | heapDesc.Count = maxNumQueries; 254 | heapDesc.NodeMask = 0x1; 255 | heapDesc.Type = queueDesc.Type == D3D12_COMMAND_LIST_TYPE_COPY ? D3D12_QUERY_HEAP_TYPE_COPY_QUEUE_TIMESTAMP : D3D12_QUERY_HEAP_TYPE_TIMESTAMP; 256 | pDevice->CreateQueryHeap(&heapDesc, IID_PPV_ARGS(&m_pQueryHeap)); 257 | 258 | for (uint32 i = 0; i < frameLatency; ++i) 259 | pDevice->CreateCommandAllocator(queueDesc.Type, IID_PPV_ARGS(&m_CommandAllocators.emplace_back())); 260 | pDevice->CreateCommandList(0x1, queueDesc.Type, m_CommandAllocators[0], nullptr, IID_PPV_ARGS(&m_pCommandList)); 261 | 262 | D3D12_RESOURCE_DESC readbackDesc{}; 263 | readbackDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; 264 | readbackDesc.Width = (uint64)maxNumQueries * sizeof(uint64) * frameLatency; 265 | readbackDesc.Height = 1; 266 | readbackDesc.DepthOrArraySize = 1; 267 | readbackDesc.MipLevels = 1; 268 | readbackDesc.SampleDesc.Count = 1; 269 | readbackDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; 270 | 271 | D3D12_HEAP_PROPERTIES heapProps{}; 272 | heapProps.Type = D3D12_HEAP_TYPE_READBACK; 273 | 274 | pDevice->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE, &readbackDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&m_pReadbackResource)); 275 | void* pReadbackData = nullptr; 276 | m_pReadbackResource->Map(0, nullptr, &pReadbackData); 277 | m_pReadbackData = (uint64*)pReadbackData; 278 | 279 | pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_pResolveFence)); 280 | m_ResolveWaitHandle = CreateEventExA(nullptr, "Fence Event", 0, EVENT_ALL_ACCESS); 281 | } 282 | 283 | void GPUProfiler::QueryHeap::Shutdown() 284 | { 285 | if (!IsInitialized()) 286 | return; 287 | 288 | for (ID3D12CommandAllocator* pAllocator : m_CommandAllocators) 289 | pAllocator->Release(); 290 | m_pCommandList->Release(); 291 | m_pQueryHeap->Release(); 292 | m_pReadbackResource->Release(); 293 | m_pResolveFence->Release(); 294 | CloseHandle(m_ResolveWaitHandle); 295 | } 296 | 297 | uint32 GPUProfiler::QueryHeap::RecordQuery(ID3D12GraphicsCommandList* pCmd) 298 | { 299 | uint32 index = m_QueryIndex.fetch_add(1); 300 | pCmd->EndQuery(m_pQueryHeap, D3D12_QUERY_TYPE_TIMESTAMP, index); 301 | return index; 302 | } 303 | 304 | uint32 GPUProfiler::QueryHeap::Resolve(uint32 frameIndex) 305 | { 306 | if (!IsInitialized()) 307 | return 0; 308 | 309 | uint32 frameBit = frameIndex % m_FrameLatency; 310 | uint32 queryStart = frameBit * m_MaxNumQueries; 311 | uint32 numQueries = m_QueryIndex; 312 | m_pCommandList->ResolveQueryData(m_pQueryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0, numQueries, m_pReadbackResource, queryStart * sizeof(uint64)); 313 | m_pCommandList->Close(); 314 | ID3D12CommandList* pCmdLists[] = { m_pCommandList }; 315 | m_pResolveQueue->ExecuteCommandLists(1, pCmdLists); 316 | m_pResolveQueue->Signal(m_pResolveFence, frameIndex + 1); 317 | return numQueries; 318 | } 319 | 320 | void GPUProfiler::QueryHeap::Reset(uint32 frameIndex) 321 | { 322 | if (!IsInitialized()) 323 | return; 324 | 325 | m_QueryIndex = 0; 326 | ID3D12CommandAllocator* pAllocator = m_CommandAllocators[frameIndex % m_FrameLatency]; 327 | pAllocator->Reset(); 328 | m_pCommandList->Reset(pAllocator, nullptr); 329 | } 330 | 331 | 332 | 333 | //----------------------------------------------------------------------------- 334 | // [SECTION] CPU Profiler 335 | //----------------------------------------------------------------------------- 336 | 337 | 338 | void CPUProfiler::Initialize(uint32 historySize, uint32 maxEvents) 339 | { 340 | Shutdown(); 341 | 342 | m_pEventData = new EventData[historySize]; 343 | m_HistorySize = historySize; 344 | 345 | for (uint32 i = 0; i < historySize; ++i) 346 | m_pEventData[i].Events.resize(maxEvents); 347 | } 348 | 349 | 350 | void CPUProfiler::Shutdown() 351 | { 352 | delete[] m_pEventData; 353 | } 354 | 355 | 356 | void CPUProfiler::BeginEvent(const char* pName, const char* pFilePath, uint32 lineNumber) 357 | { 358 | if (m_EventCallback.OnEventBegin) 359 | m_EventCallback.OnEventBegin(pName, m_EventCallback.pUserData); 360 | 361 | if (m_Paused) 362 | return; 363 | 364 | EventData& data = GetData(); 365 | uint32 newIndex = data.NumEvents.fetch_add(1); 366 | check(newIndex < data.Events.size()); 367 | 368 | TLS& tls = GetTLS(); 369 | 370 | EventData::Event& newEvent = data.Events[newIndex]; 371 | newEvent.Depth = tls.EventStack.GetSize(); 372 | newEvent.ThreadIndex = tls.ThreadIndex; 373 | newEvent.pName = data.Allocator.String(pName); 374 | newEvent.pFilePath = pFilePath; 375 | newEvent.LineNumber = lineNumber; 376 | QueryPerformanceCounter((LARGE_INTEGER*)(&newEvent.TicksBegin)); 377 | 378 | tls.EventStack.Push() = newIndex; 379 | } 380 | 381 | 382 | // End and pop the last pushed event on the current thread 383 | void CPUProfiler::EndEvent() 384 | { 385 | if (m_EventCallback.OnEventEnd) 386 | m_EventCallback.OnEventEnd(m_EventCallback.pUserData); 387 | 388 | if (m_Paused) 389 | return; 390 | 391 | EventData::Event& event = GetData().Events[GetTLS().EventStack.Pop()]; 392 | QueryPerformanceCounter((LARGE_INTEGER*)(&event.TicksEnd)); 393 | } 394 | 395 | 396 | void CPUProfiler::Tick() 397 | { 398 | m_Paused = m_QueuedPaused; 399 | if (m_Paused) 400 | return; 401 | 402 | if (m_FrameIndex) 403 | EndEvent(); 404 | 405 | // Check if all threads have ended all open sample events 406 | for (auto& threadData : m_ThreadData) 407 | check(threadData.pTLS->EventStack.GetSize() == 0); 408 | 409 | // Sort the events by thread and group by thread 410 | EventData& frame = GetData(); 411 | std::vector& events = frame.Events; 412 | std::sort(events.begin(), events.begin() + frame.NumEvents, [](const EventData::Event& a, const EventData::Event& b) 413 | { 414 | return a.ThreadIndex < b.ThreadIndex; 415 | }); 416 | 417 | URange eventRange(0, 0); 418 | for (uint32 threadIndex = 0; threadIndex < (uint32)m_ThreadData.size(); ++threadIndex) 419 | { 420 | while (threadIndex < events[eventRange.Begin].ThreadIndex) 421 | eventRange.Begin++; 422 | eventRange.End = eventRange.Begin; 423 | while (events[eventRange.End].ThreadIndex == threadIndex && eventRange.End < frame.NumEvents) 424 | ++eventRange.End; 425 | 426 | frame.EventsPerThread[threadIndex] = Span(&events[eventRange.Begin], eventRange.End - eventRange.Begin); 427 | eventRange.Begin = eventRange.End; 428 | } 429 | 430 | ++m_FrameIndex; 431 | 432 | EventData& newData = GetData(); 433 | newData.Allocator.Reset(); 434 | newData.NumEvents = 0; 435 | 436 | BeginEvent("CPU Frame"); 437 | } 438 | 439 | 440 | void CPUProfiler::RegisterThread(const char* pName) 441 | { 442 | TLS& tls = GetTLSUnsafe(); 443 | check(!tls.IsInitialized); 444 | tls.IsInitialized = true; 445 | std::scoped_lock lock(m_ThreadDataLock); 446 | tls.ThreadIndex = (uint32)m_ThreadData.size(); 447 | ThreadData& data = m_ThreadData.emplace_back(); 448 | 449 | // If the name is not provided, retrieve it using GetThreadDescription() 450 | if (pName) 451 | { 452 | strcpy_s(data.Name, ARRAYSIZE(data.Name), pName); 453 | } 454 | else 455 | { 456 | PWSTR pDescription = nullptr; 457 | VERIFY_HR(::GetThreadDescription(GetCurrentThread(), &pDescription)); 458 | size_t converted = 0; 459 | check(wcstombs_s(&converted, data.Name, ARRAYSIZE(data.Name), pDescription, ARRAYSIZE(data.Name)) == 0); 460 | } 461 | data.ThreadID = GetCurrentThreadId(); 462 | data.pTLS = &tls; 463 | data.Index = (uint32)m_ThreadData.size() - 1; 464 | 465 | for (uint32 i = 0; i < m_HistorySize; ++i) 466 | m_pEventData[i].EventsPerThread.resize(m_ThreadData.size()); 467 | } 468 | 469 | #endif 470 | -------------------------------------------------------------------------------- /Profiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define check(op, ...) assert(op) 15 | #define checkf(op, ...) assert(op) 16 | #define VERIFY_HR(op) assert(SUCCEEDED(op)) 17 | 18 | #define _STRINGIFY(a) #a 19 | #define STRINGIFY(a) _STRINGIFY(a) 20 | #define CONCAT_IMPL( x, y ) x##y 21 | #define MACRO_CONCAT( x, y ) CONCAT_IMPL( x, y ) 22 | 23 | using uint64 = uint64_t; 24 | using uint32 = uint32_t; 25 | using uint16 = uint16_t; 26 | template 27 | using Span = std::span; 28 | 29 | struct URange 30 | { 31 | uint32 Begin; 32 | uint32 End; 33 | }; 34 | 35 | 36 | #ifndef WITH_PROFILING 37 | #define WITH_PROFILING 1 38 | #endif 39 | 40 | #if WITH_PROFILING 41 | 42 | /* 43 | General 44 | */ 45 | 46 | // Usage: 47 | // PROFILE_REGISTER_THREAD(const char* pName) 48 | // PROFILE_REGISTER_THREAD() 49 | #define PROFILE_REGISTER_THREAD(...) gCPUProfiler.RegisterThread(__VA_ARGS__) 50 | 51 | /// Usage: 52 | // PROFILE_FRAME() 53 | #define PROFILE_FRAME() gCPUProfiler.Tick(); gGPUProfiler.Tick() 54 | 55 | /// Usage: 56 | /// PROFILE_EXECUTE_COMMANDLISTS(ID3D12CommandQueue* pQueue, Span commandLists) 57 | #define PROFILE_EXECUTE_COMMANDLISTS(queue, cmdlists) gGPUProfiler.ExecuteCommandLists(queue, cmdlists) 58 | 59 | /* 60 | CPU Profiling 61 | */ 62 | 63 | // Usage: 64 | // PROFILE_CPU_SCOPE(const char* pName) 65 | // PROFILE_CPU_SCOPE() 66 | #define PROFILE_CPU_SCOPE(...) CPUProfileScope MACRO_CONCAT(profiler, __COUNTER__)(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 67 | 68 | // Usage: 69 | // PROFILE_CPU_BEGIN(const char* pName) 70 | // PROFILE_CPU_BEGIN() 71 | #define PROFILE_CPU_BEGIN(...) gCPUProfiler.BeginEvent(__VA_ARGS__) 72 | // Usage: 73 | // PROFILE_CPU_END() 74 | #define PROFILE_CPU_END() gCPUProfiler.EndEvent() 75 | 76 | /* 77 | GPU Profiling 78 | */ 79 | 80 | // Usage: 81 | // PROFILE_GPU_SCOPE(ID3D12GraphicsCommandList* pCommandList, const char* pName) 82 | // PROFILE_GPU_SCOPE(ID3D12GraphicsCommandList* pCommandList) 83 | #define PROFILE_GPU_SCOPE(cmdlist, ...) GPUProfileScope MACRO_CONCAT(gpu_profiler, __COUNTER__)(__FUNCTION__, __FILE__, __LINE__, cmdlist, __VA_ARGS__) 84 | 85 | // Usage: 86 | // PROFILE_GPU_BEGIN(const char* pName, ID3D12GraphicsCommandList* pCommandList) 87 | #define PROFILE_GPU_BEGIN(cmdlist, name) gGPUProfiler.BeginEvent(name, cmdlist, __FILE__, __LINE__) 88 | 89 | // Usage: 90 | // PROFILE_GPU_END(ID3D12GraphicsCommandList* pCommandList) 91 | #define PROFILE_GPU_END(cmdlist) gGPUProfiler.EndEvent(cmdlist) 92 | 93 | 94 | #else 95 | 96 | #define PROFILE_REGISTER_THREAD(...) 97 | #define PROFILE_FRAME() 98 | #define PROFILE_EXECUTE_COMMANDLISTS(...) 99 | 100 | #define PROFILE_CPU_SCOPE(...) 101 | #define PROFILE_CPU_BEGIN(...) 102 | #define PROFILE_CPU_END() 103 | 104 | #define PROFILE_GPU_SCOPE(...) 105 | #define PROFILE_GPU_BEGIN(...) 106 | #define PROFILE_GPU_END() 107 | 108 | #endif 109 | 110 | // Simple Linear Allocator 111 | class LinearAllocator 112 | { 113 | public: 114 | explicit LinearAllocator(uint32 size) 115 | : m_pData(new char[size]), m_Size(size), m_Offset(0) 116 | { 117 | } 118 | 119 | ~LinearAllocator() 120 | { 121 | delete[] m_pData; 122 | } 123 | 124 | LinearAllocator(LinearAllocator&) = delete; 125 | LinearAllocator& operator=(LinearAllocator&) = delete; 126 | 127 | void Reset() 128 | { 129 | m_Offset = 0; 130 | } 131 | 132 | template 133 | T* Allocate(Args... args) 134 | { 135 | void* pData = Allocate(sizeof(T)); 136 | T* pValue = new (pData) T(std::forward(args)...); 137 | return pValue; 138 | } 139 | 140 | void* Allocate(uint32 size) 141 | { 142 | uint32 offset = m_Offset.fetch_add(size); 143 | check(offset + size <= m_Size); 144 | return m_pData + offset; 145 | } 146 | 147 | const char* String(const char* pStr) 148 | { 149 | uint32 len = (uint32)strlen(pStr) + 1; 150 | char* pData = (char*)Allocate(len); 151 | strcpy_s(pData, len, pStr); 152 | return pData; 153 | } 154 | 155 | private: 156 | char* m_pData; 157 | uint32 m_Size; 158 | std::atomic m_Offset; 159 | }; 160 | 161 | void DrawProfilerHUD(); 162 | 163 | //----------------------------------------------------------------------------- 164 | // [SECTION] GPU Profiler 165 | //----------------------------------------------------------------------------- 166 | 167 | extern class GPUProfiler gGPUProfiler; 168 | 169 | struct GPUProfilerCallbacks 170 | { 171 | using EventBeginFn = void(*)(const char* /*pName*/, ID3D12GraphicsCommandList* /*CommandList*/, void* /*pUserData*/); 172 | using EventEndFn = void(*)(ID3D12GraphicsCommandList* /*CommandList*/, void* /*pUserData*/); 173 | 174 | EventBeginFn OnEventBegin = nullptr; 175 | EventEndFn OnEventEnd = nullptr; 176 | void* pUserData = nullptr; 177 | }; 178 | 179 | 180 | class GPUProfiler 181 | { 182 | public: 183 | void Initialize( 184 | ID3D12Device* pDevice, 185 | Span queues, 186 | uint32 sampleHistory, 187 | uint32 frameLatency, 188 | uint32 maxNumEvents, 189 | uint32 maxNumCopyEvents, 190 | uint32 maxNumActiveCommandLists); 191 | 192 | void Shutdown(); 193 | 194 | // Allocate and record a GPU event on the commandlist 195 | void BeginEvent(ID3D12GraphicsCommandList* pCmd, const char* pName, const char* pFilePath = "", uint32 lineNumber = 0); 196 | 197 | // Record a GPU event end on the commandlist 198 | void EndEvent(ID3D12GraphicsCommandList* pCmd); 199 | 200 | // Resolve the last frame and advance to the next frame. 201 | // Call at the START of the frame. 202 | void Tick(); 203 | 204 | // Notify profiler that these commandlists are executed on a particular queue 205 | void ExecuteCommandLists(ID3D12CommandQueue* pQueue, Span commandLists); 206 | 207 | void SetPaused(bool paused) { m_PauseQueued = paused; } 208 | 209 | // Data for a single frame of profiling events. On for each history frame 210 | struct EventData 211 | { 212 | EventData() 213 | : Allocator(1 << 14) 214 | {} 215 | 216 | struct Event 217 | { 218 | const char* pName = ""; // Name of event 219 | const char* pFilePath = ""; // File path of location where event was started 220 | uint64 TicksBegin = 0; // Begin GPU ticks 221 | uint64 TicksEnd = 0; // End GPU ticks 222 | uint32 LineNumber : 16; // Line number of file where event was started 223 | uint32 Index : 16; // Index of event, to ensure stable sort when ordering 224 | uint32 Depth : 8; // Stack depth of event 225 | uint32 QueueIndex : 8; // Index of QueueInfo 226 | uint32 padding : 16; 227 | }; 228 | static_assert(sizeof(Event) == sizeof(uint32) * 10); 229 | 230 | LinearAllocator Allocator; // Scratch allocator for frame 231 | std::vector> EventsPerQueue; // Span of events for each queue 232 | std::vector Events; // Event storage for frame 233 | uint32 NumEvents = 0; // Total number of recorded events 234 | }; 235 | 236 | // Data of a single GPU queue. Allows converting GPU timestamps to CPU timestamps 237 | class QueueInfo 238 | { 239 | public: 240 | void InitCalibration() 241 | { 242 | pQueue->GetClockCalibration(&GPUCalibrationTicks, &CPUCalibrationTicks); 243 | pQueue->GetTimestampFrequency(&GPUFrequency); 244 | QueryPerformanceFrequency((LARGE_INTEGER*)&CPUFrequency); 245 | } 246 | 247 | uint64 GpuToCpuTicks(uint64 gpuTicks) const 248 | { 249 | check(gpuTicks >= GPUCalibrationTicks); 250 | return CPUCalibrationTicks + (gpuTicks - GPUCalibrationTicks) * CPUFrequency / GPUFrequency; 251 | } 252 | 253 | float TicksToMS(uint64 ticks) const 254 | { 255 | return (float)ticks / GPUFrequency * 1000.0f; 256 | } 257 | 258 | ID3D12CommandQueue* pQueue = nullptr; // The D3D queue object 259 | char Name[128]; // Name of the queue 260 | 261 | private: 262 | uint64 GPUCalibrationTicks = 0; // The number of GPU ticks when the calibration was done 263 | uint64 CPUCalibrationTicks = 0; // The number of CPU ticks when the calibration was done 264 | uint64 GPUFrequency = 0; // The GPU tick frequency 265 | uint64 CPUFrequency = 0; // The CPU tick frequency 266 | }; 267 | 268 | Span GetQueues() const { return m_Queues; } 269 | 270 | URange GetFrameRange() const 271 | { 272 | uint32 end = m_FrameToReadback; 273 | uint32 begin = m_FrameIndex < m_EventHistorySize ? 0 : m_FrameIndex - (uint32)m_EventHistorySize; 274 | return URange(begin, end); 275 | } 276 | 277 | Span GetEventsForQueue(const QueueInfo& queue, uint32 frame) const 278 | { 279 | check(frame >= GetFrameRange().Begin && frame < GetFrameRange().End); 280 | uint32 queueIndex = m_QueueIndexMap.at(queue.pQueue); 281 | const EventData& eventData = GetSampleFrame(frame); 282 | return eventData.EventsPerQueue[queueIndex]; 283 | } 284 | 285 | void SetEventCallback(const GPUProfilerCallbacks& inCallbacks) { m_EventCallback = inCallbacks; } 286 | 287 | private: 288 | struct QueryHeap 289 | { 290 | public: 291 | void Initialize(ID3D12Device* pDevice, ID3D12CommandQueue* pResolveQueue, uint32 maxNumQueries, uint32 frameLatency); 292 | void Shutdown(); 293 | 294 | uint32 RecordQuery(ID3D12GraphicsCommandList* pCmd); 295 | uint32 Resolve(uint32 frameIndex); 296 | void Reset(uint32 frameIndex); 297 | 298 | Span GetQueryData(uint32 frameIndex) const 299 | { 300 | if (!IsInitialized()) 301 | return {}; 302 | 303 | uint32 frameBit = frameIndex % m_FrameLatency; 304 | return Span(m_pReadbackData + frameBit * m_MaxNumQueries, m_MaxNumQueries); 305 | } 306 | 307 | bool IsFrameComplete(uint64 frameIndex) 308 | { 309 | if (!IsInitialized()) 310 | return true; 311 | 312 | uint64 fenceValue = frameIndex; 313 | if (fenceValue <= m_LastCompletedFence) 314 | return true; 315 | m_LastCompletedFence = max(m_pResolveFence->GetCompletedValue(), m_LastCompletedFence); 316 | return fenceValue <= m_LastCompletedFence; 317 | } 318 | 319 | void WaitFrame(uint32 frameIndex) 320 | { 321 | if (!IsInitialized()) 322 | return; 323 | 324 | if (!IsFrameComplete(frameIndex)) 325 | { 326 | m_pResolveFence->SetEventOnCompletion(frameIndex, m_ResolveWaitHandle); 327 | WaitForSingleObject(m_ResolveWaitHandle, INFINITE); 328 | } 329 | } 330 | 331 | bool IsInitialized() const { return m_pQueryHeap != nullptr; } 332 | ID3D12QueryHeap* GetHeap() const { return m_pQueryHeap; } 333 | 334 | private: 335 | std::vector m_CommandAllocators; 336 | uint32 m_MaxNumQueries = 0; 337 | uint32 m_FrameLatency = 0; 338 | std::atomic m_QueryIndex = 0; 339 | ID3D12GraphicsCommandList* m_pCommandList = nullptr; 340 | ID3D12QueryHeap* m_pQueryHeap = nullptr; 341 | ID3D12Resource* m_pReadbackResource = nullptr; 342 | const uint64* m_pReadbackData = nullptr; 343 | ID3D12CommandQueue* m_pResolveQueue = nullptr; 344 | ID3D12Fence* m_pResolveFence = nullptr; 345 | HANDLE m_ResolveWaitHandle = nullptr; 346 | uint64 m_LastCompletedFence = 0; 347 | }; 348 | 349 | 350 | const EventData& GetSampleFrame(uint32 frameIndex) const { return m_pEventData[frameIndex % m_EventHistorySize]; } 351 | EventData& GetSampleFrame(uint32 frameIndex) { return m_pEventData[frameIndex % m_EventHistorySize]; } 352 | EventData& GetSampleFrame() { return GetSampleFrame(m_FrameIndex); } 353 | 354 | // Data for a single frame of GPU queries. One for each frame latency 355 | struct QueryData 356 | { 357 | struct QueryRange 358 | { 359 | uint32 QueryIndexBegin : 15; 360 | uint32 QueryIndexEnd : 15; 361 | uint32 IsCopyQuery : 1; 362 | }; 363 | static_assert(sizeof(QueryRange) == sizeof(uint32)); 364 | std::vector Ranges; 365 | }; 366 | QueryData& GetQueryData(uint32 frameIndex) { return m_pQueryData[frameIndex % m_FrameLatency]; } 367 | QueryData& GetQueryData() { return GetQueryData(m_FrameIndex); } 368 | 369 | // Query data for each commandlist 370 | class CommandListData 371 | { 372 | public: 373 | struct Data 374 | { 375 | struct Query 376 | { 377 | uint32 QueryIndex : 16; 378 | uint32 RangeIndex : 15; 379 | uint32 IsBegin : 1; 380 | }; 381 | static_assert(sizeof(Query) == sizeof(uint32)); 382 | std::vector Queries; 383 | }; 384 | 385 | void Setup(uint32 maxCommandLists) 386 | { 387 | InitializeSRWLock(&m_CommandListMapLock); 388 | m_CommandListData.resize(maxCommandLists); 389 | } 390 | 391 | Data* Get(ID3D12CommandList* pCmd, bool createIfNotFound) 392 | { 393 | static constexpr uint32 InvalidIndex = 0xFFFFFFFF; 394 | AcquireSRWLockShared(&m_CommandListMapLock); 395 | auto it = m_CommandListMap.find(pCmd); 396 | uint32 index = InvalidIndex; 397 | if (it != m_CommandListMap.end()) 398 | index = it->second; 399 | ReleaseSRWLockShared(&m_CommandListMapLock); 400 | if (createIfNotFound && index == InvalidIndex) 401 | { 402 | AcquireSRWLockExclusive(&m_CommandListMapLock); 403 | index = (uint32)m_CommandListMap.size(); 404 | m_CommandListMap[pCmd] = index; 405 | ReleaseSRWLockExclusive(&m_CommandListMapLock); 406 | } 407 | if (index == InvalidIndex) 408 | return nullptr; 409 | check(index < m_CommandListData.size()); 410 | return &m_CommandListData[index]; 411 | } 412 | 413 | void Reset() 414 | { 415 | for (Data& data : m_CommandListData) 416 | check(data.Queries.empty(), "The Queries inside the commandlist is not empty. This is because ExecuteCommandLists was not called with this commandlist."); 417 | m_CommandListMap.clear(); 418 | } 419 | 420 | private: 421 | SRWLOCK m_CommandListMapLock{}; 422 | std::unordered_map m_CommandListMap; 423 | std::vector m_CommandListData; 424 | }; 425 | 426 | QueryHeap& GetHeap(D3D12_COMMAND_LIST_TYPE type) { return type == D3D12_COMMAND_LIST_TYPE_COPY ? m_CopyHeap : m_MainHeap; } 427 | 428 | CommandListData m_CommandListData{}; 429 | 430 | EventData* m_pEventData = nullptr; 431 | uint32 m_EventHistorySize = 0; 432 | std::atomic m_EventIndex = 0; 433 | 434 | QueryData* m_pQueryData = nullptr; 435 | uint32 m_FrameLatency = 0; 436 | 437 | uint32 m_FrameToReadback = 0; 438 | uint32 m_FrameIndex = 0; 439 | 440 | QueryHeap m_MainHeap; 441 | QueryHeap m_CopyHeap; 442 | 443 | std::vector m_Queues; 444 | std::unordered_map m_QueueIndexMap; 445 | GPUProfilerCallbacks m_EventCallback; 446 | 447 | bool m_IsPaused = false; 448 | bool m_PauseQueued = false; 449 | }; 450 | 451 | 452 | // Helper RAII-style structure to push and pop a GPU sample event 453 | struct GPUProfileScope 454 | { 455 | GPUProfileScope(const char* pFunction, const char* pFilePath, uint32 lineNumber, ID3D12GraphicsCommandList* pCmd, const char* pName) 456 | : pCmd(pCmd) 457 | { 458 | gGPUProfiler.BeginEvent(pCmd, pName, pFilePath, lineNumber); 459 | } 460 | 461 | GPUProfileScope(const char* pFunction, const char* pFilePath, uint32 lineNumber, ID3D12GraphicsCommandList* pCmd) 462 | : pCmd(pCmd) 463 | { 464 | gGPUProfiler.BeginEvent(pCmd, pFunction, pFilePath, lineNumber); 465 | } 466 | 467 | ~GPUProfileScope() 468 | { 469 | gGPUProfiler.EndEvent(pCmd); 470 | } 471 | 472 | GPUProfileScope(const GPUProfileScope&) = delete; 473 | GPUProfileScope& operator=(const GPUProfileScope&) = delete; 474 | 475 | private: 476 | ID3D12GraphicsCommandList* pCmd; 477 | }; 478 | 479 | 480 | //----------------------------------------------------------------------------- 481 | // [SECTION] CPU Profiler 482 | //----------------------------------------------------------------------------- 483 | 484 | // Global CPU Profiler 485 | extern class CPUProfiler gCPUProfiler; 486 | 487 | struct CPUProfilerCallbacks 488 | { 489 | using EventBeginFn = void(*)(const char* /*pName*/, void* /*pUserData*/); 490 | using EventEndFn = void(*)(void* /*pUserData*/); 491 | 492 | EventBeginFn OnEventBegin = nullptr; 493 | EventEndFn OnEventEnd = nullptr; 494 | void* pUserData = nullptr; 495 | }; 496 | 497 | // CPU Profiler 498 | // Also responsible for updating GPU profiler 499 | // Also responsible for drawing HUD 500 | class CPUProfiler 501 | { 502 | public: 503 | void Initialize(uint32 historySize, uint32 maxEvents); 504 | void Shutdown(); 505 | 506 | // Start and push an event on the current thread 507 | void BeginEvent(const char* pName, const char* pFilePath = nullptr, uint32 lineNumber = 0); 508 | 509 | // End and pop the last pushed event on the current thread 510 | void EndEvent(); 511 | 512 | // Resolve the last frame and advance to the next frame. 513 | // Call at the START of the frame. 514 | void Tick(); 515 | 516 | // Initialize a thread with an optional name 517 | void RegisterThread(const char* pName = nullptr); 518 | 519 | // Struct containing all sampling data of a single frame 520 | struct EventData 521 | { 522 | static constexpr uint32 ALLOCATOR_SIZE = 1 << 14; 523 | 524 | EventData() 525 | : Allocator(ALLOCATOR_SIZE) 526 | {} 527 | 528 | // Structure representating a single event 529 | struct Event 530 | { 531 | const char* pName = ""; // Name of the event 532 | const char* pFilePath = nullptr; // File path of file in which this event is recorded 533 | uint64 TicksBegin = 0; // The ticks at the start of this event 534 | uint64 TicksEnd = 0; // The ticks at the end of this event 535 | uint32 LineNumber : 16; // Line number of file in which this event is recorded 536 | uint32 ThreadIndex : 11; // Thread Index of the thread that recorderd this event 537 | uint32 Depth : 5; // Depth of the event 538 | }; 539 | 540 | std::vector> EventsPerThread; // Events per thread of the frame 541 | std::vector Events; // All events of the frame 542 | LinearAllocator Allocator; // Scratch allocator storing all dynamic allocations of the frame 543 | std::atomic NumEvents = 0; // The number of events 544 | }; 545 | 546 | // Thread-local storage to keep track of current depth and event stack 547 | struct TLS 548 | { 549 | static constexpr int MAX_STACK_DEPTH = 32; 550 | 551 | template 552 | struct FixedStack 553 | { 554 | public: 555 | T& Pop() 556 | { 557 | check(Depth > 0); 558 | --Depth; 559 | return StackData[Depth]; 560 | } 561 | 562 | T& Push() 563 | { 564 | Depth++; 565 | check(Depth < ARRAYSIZE(StackData)); 566 | return StackData[Depth - 1]; 567 | } 568 | 569 | T& Top() 570 | { 571 | check(Depth > 0); 572 | return StackData[Depth - 1]; 573 | } 574 | 575 | uint32 GetSize() const { return Depth; } 576 | 577 | private: 578 | uint32 Depth = 0; 579 | T StackData[N]{}; 580 | }; 581 | 582 | 583 | FixedStack EventStack; 584 | uint32 ThreadIndex = 0; 585 | bool IsInitialized = false; 586 | }; 587 | 588 | // Structure describing a registered thread 589 | struct ThreadData 590 | { 591 | char Name[128]{}; 592 | uint32 ThreadID = 0; 593 | uint32 Index = 0; 594 | const TLS* pTLS = nullptr; 595 | }; 596 | 597 | URange GetFrameRange() const 598 | { 599 | uint32 begin = m_FrameIndex - min(m_FrameIndex, m_HistorySize) + 1; 600 | uint32 end = m_FrameIndex; 601 | return URange(begin, end); 602 | } 603 | 604 | Span GetEventsForThread(const ThreadData& thread, uint32 frame) const 605 | { 606 | check(frame >= GetFrameRange().Begin && frame < GetFrameRange().End); 607 | const EventData& data = m_pEventData[frame % m_HistorySize]; 608 | if (thread.Index < data.EventsPerThread.size()) 609 | return data.EventsPerThread[thread.Index]; 610 | return {}; 611 | } 612 | 613 | // Get the ticks range of the history 614 | void GetHistoryRange(uint64& ticksMin, uint64& ticksMax) const 615 | { 616 | URange range = GetFrameRange(); 617 | ticksMin = GetData(range.Begin).Events[0].TicksBegin; 618 | ticksMax = GetData(range.End).Events[0].TicksEnd; 619 | } 620 | 621 | Span GetThreads() const { return m_ThreadData; } 622 | 623 | void SetEventCallback(const CPUProfilerCallbacks& inCallbacks) { m_EventCallback = inCallbacks; } 624 | void SetPaused(bool paused) { m_QueuedPaused = paused; } 625 | bool IsPaused() const { return m_Paused; } 626 | 627 | private: 628 | // Retrieve thread-local storage without initialization 629 | static TLS& GetTLSUnsafe() 630 | { 631 | static thread_local TLS tls; 632 | return tls; 633 | } 634 | 635 | // Retrieve the thread-local storage 636 | TLS& GetTLS() 637 | { 638 | TLS& tls = GetTLSUnsafe(); 639 | if (!tls.IsInitialized) 640 | RegisterThread(); 641 | return tls; 642 | } 643 | 644 | // Return the sample data of the current frame 645 | EventData& GetData() { return GetData(m_FrameIndex); } 646 | EventData& GetData(uint32 frameIndex) { return m_pEventData[frameIndex % m_HistorySize]; } 647 | const EventData& GetData(uint32 frameIndex) const { return m_pEventData[frameIndex % m_HistorySize]; } 648 | 649 | CPUProfilerCallbacks m_EventCallback; 650 | 651 | std::mutex m_ThreadDataLock; // Mutex for accesing thread data 652 | std::vector m_ThreadData; // Data describing each registered thread 653 | 654 | EventData* m_pEventData = nullptr; // Per-frame data 655 | uint32 m_HistorySize = 0; // History size 656 | uint32 m_FrameIndex = 0; // The current frame index 657 | bool m_Paused = false; // The current pause state 658 | bool m_QueuedPaused = false; // The queued pause state 659 | }; 660 | 661 | 662 | // Helper RAII-style structure to push and pop a CPU sample region 663 | struct CPUProfileScope 664 | { 665 | CPUProfileScope(const char* pFunctionName, const char* pFilePath, uint32 lineNumber, const char* pName) 666 | { 667 | gCPUProfiler.BeginEvent(pName, pFilePath, lineNumber); 668 | } 669 | 670 | CPUProfileScope(const char* pFunctionName, const char* pFilePath, uint32 lineNumber) 671 | { 672 | gCPUProfiler.BeginEvent(pFunctionName, pFilePath, lineNumber); 673 | } 674 | 675 | ~CPUProfileScope() 676 | { 677 | gCPUProfiler.EndEvent(); 678 | } 679 | 680 | CPUProfileScope(const CPUProfileScope&) = delete; 681 | CPUProfileScope& operator=(const CPUProfileScope&) = delete; 682 | }; 683 | -------------------------------------------------------------------------------- /ProfilerWindow.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Profiler.h" 3 | #include "ImGui/imgui.h" 4 | #include "ImGui/imgui_internal.h" 5 | #include "IconsFontAwesome4.h" 6 | 7 | struct StyleOptions 8 | { 9 | int MaxDepth = 10; 10 | int MaxTime = 80; 11 | 12 | float BarHeight = 25; 13 | float BarPadding = 2; 14 | float ScrollBarSize = 15.0f; 15 | 16 | ImVec4 BarColorMultiplier = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); 17 | ImVec4 BGTextColor = ImVec4(0.5f, 0.5f, 0.5f, 1.0f); 18 | ImVec4 FGTextColor = ImVec4(0.9f, 0.9f, 0.9f, 1.0f); 19 | ImVec4 BarHighlightColor = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); 20 | 21 | bool DebugMode = false; 22 | }; 23 | 24 | struct HUDContext 25 | { 26 | StyleOptions Style; 27 | 28 | float TimelineScale = 5.0f; 29 | ImVec2 TimelineOffset = ImVec2(0.0f, 0.0f); 30 | 31 | bool IsSelectingRange = false; 32 | float RangeSelectionStart = 0.0f; 33 | char SearchString[128]{}; 34 | bool PauseThreshold = false; 35 | float PauseThresholdTime = 100.0f; 36 | bool IsPaused = false; 37 | }; 38 | 39 | static HUDContext gHUDContext; 40 | static HUDContext& Context() 41 | { 42 | return gHUDContext; 43 | } 44 | 45 | static void EditStyle(StyleOptions& style) 46 | { 47 | ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.7f); 48 | ImGui::SliderInt("Depth", &style.MaxDepth, 1, 12); 49 | ImGui::SliderInt("Max Time", &style.MaxTime, 8, 66); 50 | ImGui::SliderFloat("Bar Height", &style.BarHeight, 8, 33); 51 | ImGui::SliderFloat("Bar Padding", &style.BarPadding, 0, 5); 52 | ImGui::SliderFloat("Scroll Bar Size", &style.ScrollBarSize, 1.0f, 40.0f); 53 | ImGui::ColorEdit4("Bar Color Multiplier", &style.BarColorMultiplier.x); 54 | ImGui::ColorEdit4("Background Text Color", &style.BGTextColor.x); 55 | ImGui::ColorEdit4("Foreground Text Color", &style.FGTextColor.x); 56 | ImGui::ColorEdit4("Bar Highlight Color", &style.BarHighlightColor.x); 57 | ImGui::Separator(); 58 | ImGui::Checkbox("Debug Mode", &style.DebugMode); 59 | ImGui::PopItemWidth(); 60 | } 61 | 62 | // 32-bit FNV hash 63 | static uint32 HashString(const char* pStr) 64 | { 65 | uint32 result = 0x811c9dc5; 66 | while (*pStr) 67 | { 68 | result ^= *pStr++; 69 | result *= 0x1000193; 70 | } 71 | return result; 72 | } 73 | 74 | // From https://github.com/stolk/hsvbench 75 | static ImVec4 HSVtoRGB(float h, float s, float v) 76 | { 77 | const float h6 = 6.0f * h; 78 | const float r = fabsf(h6 - 3.0f) - 1.0f; 79 | const float g = 2.0f - fabsf(h6 - 2.0f); 80 | const float b = 2.0f - fabsf(h6 - 4.0f); 81 | 82 | const float is = 1.0f - s; 83 | ImVec4 rgba; 84 | rgba.x = v * (s * ImClamp(r, 0.0f, 1.0f) + is); 85 | rgba.y = v * (s * ImClamp(g, 0.0f, 1.0f) + is); 86 | rgba.z = v * (s * ImClamp(b, 0.0f, 1.0f) + is); 87 | rgba.w = 1.0f; 88 | return rgba; 89 | } 90 | 91 | // Generate a color from a string. Used to color bars 92 | static ImColor ColorFromString(const char* pName) 93 | { 94 | uint32 hash = HashString(pName); 95 | float hashF = (float)hash / UINT32_MAX; 96 | return ImColor(HSVtoRGB(hashF, 0.5f, 0.6f)); 97 | } 98 | 99 | static void DrawProfilerTimeline(const ImVec2& size = ImVec2(0, 0)) 100 | { 101 | HUDContext& context = gHUDContext; 102 | StyleOptions& style = context.Style; 103 | 104 | ImVec2 sizeActual = ImGui::CalcItemSize(size, ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y); 105 | 106 | ImRect timelineRect(ImGui::GetCursorScreenPos(), ImGui::GetCursorScreenPos() + sizeActual); 107 | ImGui::ItemSize(timelineRect.GetSize()); 108 | 109 | // The current (scaled) size of the timeline 110 | float timelineWidth = timelineRect.GetWidth() * context.TimelineScale; 111 | 112 | ImVec2 cursor = timelineRect.Min + context.TimelineOffset; 113 | ImVec2 cursorStart = cursor; 114 | ImDrawList* pDraw = ImGui::GetWindowDrawList(); 115 | 116 | ImGuiID timelineID = ImGui::GetID("Timeline"); 117 | timelineRect.Max -= ImVec2(style.ScrollBarSize, style.ScrollBarSize); 118 | if (ImGui::ItemAdd(timelineRect, timelineID)) 119 | { 120 | ImGui::PushClipRect(timelineRect.Min, timelineRect.Max, true); 121 | 122 | // How many ticks per ms 123 | uint64 frequency = 0; 124 | QueryPerformanceFrequency((LARGE_INTEGER*)&frequency); 125 | const float MsToTicks = (float)frequency / 1000.0f; 126 | const float TicksToMs = 1000.0f / frequency; 127 | 128 | // How many ticks are in the timeline 129 | float ticksInTimeline = MsToTicks * style.MaxTime; 130 | 131 | uint64 timelineTicksBegin, timelineTicksEnd; 132 | gCPUProfiler.GetHistoryRange(timelineTicksBegin, timelineTicksEnd); 133 | uint64 beginAnchor = timelineTicksBegin; 134 | 135 | // How many pixels is one tick 136 | const float TicksToPixels = timelineWidth / ticksInTimeline; 137 | 138 | // Add vertical bars for each ms interval 139 | /* 140 | 0 1 2 3 141 | | | | | 142 | | | | | 143 | | | | | 144 | */ 145 | pDraw->AddRectFilled(timelineRect.Min, ImVec2(timelineRect.Max.x, timelineRect.Min.y + style.BarHeight), ImColor(0.0f, 0.0f, 0.0f, 0.1f)); 146 | pDraw->AddRect(timelineRect.Min - ImVec2(10, 0), ImVec2(timelineRect.Max.x + 10, timelineRect.Min.y + style.BarHeight), ImColor(1.0f, 1.0f, 1.0f, 0.4f)); 147 | for (int i = 0; i < style.MaxTime; ++i) 148 | { 149 | float x0 = (float)i * MsToTicks * TicksToPixels; 150 | float msWidth = 1.0f * MsToTicks * TicksToPixels; 151 | ImVec2 tickPos = ImVec2(cursor.x + x0, timelineRect.Min.y); 152 | pDraw->AddLine(tickPos + ImVec2(0, style.BarHeight * 0.5f), tickPos + ImVec2(0, style.BarHeight), ImColor(style.BGTextColor)); 153 | 154 | if (i % 2 == 0) 155 | { 156 | pDraw->AddRectFilled(tickPos + ImVec2(0, style.BarHeight), tickPos + ImVec2(msWidth, timelineRect.Max.y), ImColor(1.0f, 1.0f, 1.0f, 0.02f)); 157 | const char* pBarText; 158 | ImFormatStringToTempBuffer(&pBarText, nullptr, "%d ms", i); 159 | pDraw->AddText(tickPos + ImVec2(5, 0), ImColor(style.BGTextColor), pBarText); 160 | } 161 | } 162 | 163 | cursor.y += style.BarHeight; 164 | 165 | // Add dark shade background for every even frame 166 | int frameNr = 0; 167 | URange cpuRange = gCPUProfiler.GetFrameRange(); 168 | for(uint32 i = cpuRange.Begin; i < cpuRange.End; ++i) 169 | { 170 | Span events = gCPUProfiler.GetEventsForThread(gCPUProfiler.GetThreads()[0], i); 171 | if (events.size() > 0 && frameNr++ % 2 == 0) 172 | { 173 | float beginOffset = (events[0].TicksBegin - beginAnchor) * TicksToPixels; 174 | float endOffset = (events[0].TicksEnd - beginAnchor) * TicksToPixels; 175 | pDraw->AddRectFilled(ImVec2(cursor.x + beginOffset, timelineRect.Min.y), ImVec2(cursor.x + endOffset, timelineRect.Max.y), ImColor(1.0f, 1.0f, 1.0f, 0.05f)); 176 | } 177 | } 178 | 179 | ImGui::PushClipRect(timelineRect.Min + ImVec2(0, style.BarHeight), timelineRect.Max, true); 180 | 181 | // Common function to draw a single bar 182 | /* 183 | [=== SomeFunction (1.2 ms) ===] 184 | */ 185 | bool anyHovered = false; 186 | auto DrawBar = [&](uint32 id, uint64 beginTicks, uint64 endTicks, uint32 depth, const char* pName, bool* pOutHovered = nullptr) 187 | { 188 | bool hovered = false; 189 | if (endTicks > beginAnchor) 190 | { 191 | float startPos = (beginTicks < beginAnchor ? 0 : beginTicks - beginAnchor) * TicksToPixels; 192 | float endPos = (endTicks - beginAnchor) * TicksToPixels; 193 | float y = depth * style.BarHeight; 194 | ImRect itemRect = ImRect(cursor + ImVec2(startPos, y), cursor + ImVec2(endPos, y + style.BarHeight)); 195 | 196 | // Ensure a bar always has a width 197 | itemRect.Max.x = ImMax(itemRect.Max.x, itemRect.Min.x + 1); 198 | if (ImGui::ItemAdd(itemRect, id, 0)) 199 | { 200 | float ms = TicksToMs * (float)(endTicks - beginTicks); 201 | 202 | ImColor color = ColorFromString(pName) * style.BarColorMultiplier; 203 | ImColor textColor = style.FGTextColor; 204 | // Fade out the bars that don't match the filter 205 | if (context.SearchString[0] != 0 && !strstr(pName, context.SearchString)) 206 | { 207 | color.Value.w *= 0.3f; 208 | textColor.Value.w *= 0.5f; 209 | } 210 | else if (context.PauseThreshold && ms >= context.PauseThresholdTime) 211 | { 212 | gCPUProfiler.SetPaused(true); 213 | gGPUProfiler.SetPaused(true); 214 | } 215 | 216 | // Darken the bottom 217 | ImColor colorBottom = color.Value * ImVec4(0.8f, 0.8f, 0.8f, 1.0f); 218 | 219 | hovered = ImGui::IsItemHovered() && !anyHovered; 220 | anyHovered |= hovered; 221 | 222 | // If the bar is double-clicked, zoom in to make the bar fill the entire window 223 | if (ImGui::ButtonBehavior(itemRect, ImGui::GetItemID(), nullptr, nullptr, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnDoubleClick)) 224 | { 225 | // Zoom ration to make the bar fit the entire window 226 | float zoom = timelineWidth / itemRect.GetWidth(); 227 | context.TimelineScale = zoom; 228 | 229 | // Recompute the timeline size with new zoom 230 | float newTimelineWidth = timelineRect.GetWidth() * context.TimelineScale; 231 | float newTickScale = newTimelineWidth / ticksInTimeline; 232 | float newStartPos = newTickScale * (beginTicks - beginAnchor); 233 | 234 | context.TimelineOffset.x = -newStartPos; 235 | } 236 | 237 | // Draw the bar rect and outline if hovered 238 | 239 | // Only pad if bar is large enough 240 | float maxPaddingX = ImMax(itemRect.GetWidth() * 0.5f - 1.0f, 0.0f); 241 | const ImVec2 padding(ImMin(style.BarPadding, maxPaddingX), style.BarPadding); 242 | if (hovered) 243 | { 244 | ImColor highlightColor = color.Value * ImVec4(1.5f, 1.5f, 1.5f, 1.0f); 245 | color.Value = color.Value * ImVec4(1.2f, 1.2f, 1.2f, 1.0f); 246 | colorBottom.Value = colorBottom.Value * ImVec4(1.2f, 1.2f, 1.2f, 1.0f); 247 | pDraw->AddRectFilledMultiColor(itemRect.Min + padding, itemRect.Max - padding, color, color, colorBottom, colorBottom); 248 | pDraw->AddRect(itemRect.Min, itemRect.Max, highlightColor, 0.0f, ImDrawFlags_None, 3.0f); 249 | } 250 | else 251 | { 252 | pDraw->AddRectFilledMultiColor(itemRect.Min + padding, itemRect.Max - padding, color, color, colorBottom, colorBottom); 253 | } 254 | 255 | // If the bar size is large enough, draw the name of the bar on top 256 | if (itemRect.GetWidth() > 10.0f) 257 | { 258 | const char* pBarText; 259 | ImFormatStringToTempBuffer(&pBarText, nullptr, "%s (%.2f ms)", pName, ms); 260 | 261 | ImVec2 textSize = ImGui::CalcTextSize(pBarText); 262 | const char* pEtc = "..."; 263 | float etcWidth = 20.0f; 264 | if (textSize.x < itemRect.GetWidth() * 0.9f) 265 | { 266 | pDraw->AddText(itemRect.Min + (ImVec2(itemRect.GetWidth(), style.BarHeight) - textSize) * 0.5f, textColor, pBarText); 267 | } 268 | else if (itemRect.GetWidth() > etcWidth + 10) 269 | { 270 | const char* pChar = pBarText; 271 | float currentOffset = 10; 272 | while (*pChar++) 273 | { 274 | float width = ImGui::CalcTextSize(pChar, pChar + 1).x; 275 | if (currentOffset + width + etcWidth > itemRect.GetWidth()) 276 | break; 277 | currentOffset += width; 278 | } 279 | 280 | float textWidth = ImGui::CalcTextSize(pBarText, pChar).x; 281 | 282 | ImVec2 textPos = itemRect.Min + ImVec2(4, (style.BarHeight - textSize.y) * 0.5f); 283 | pDraw->AddText(textPos, textColor, pBarText, pChar); 284 | pDraw->AddText(textPos + ImVec2(textWidth, 0), textColor, pEtc); 285 | } 286 | } 287 | } 288 | } 289 | if (pOutHovered) 290 | *pOutHovered = hovered; 291 | }; 292 | 293 | // Add track name and expander 294 | /* 295 | (>) Main Thread [1234] 296 | */ 297 | auto TrackHeader = [&](const char* pName, uint32 id) 298 | { 299 | pDraw->AddRectFilled(ImVec2(timelineRect.Min.x, cursor.y), ImVec2(timelineRect.Max.x, cursor.y + style.BarHeight), ImColor(0.0f, 0.0f, 0.0f, 0.3f)); 300 | 301 | bool isOpen = ImGui::GetCurrentWindow()->StateStorage.GetBool(id, true); 302 | ImVec2 trackTextCursor = ImVec2(timelineRect.Min.x, cursor.y); 303 | 304 | float caretSize = ImGui::GetTextLineHeight(); 305 | if (ImGui::ItemAdd(ImRect(trackTextCursor, trackTextCursor + ImVec2(caretSize, caretSize)), id)) 306 | { 307 | if (ImGui::IsItemHovered()) 308 | pDraw->AddRect(ImGui::GetItemRectMin() + ImVec2(2, 2), ImGui::GetItemRectMax() - ImVec2(2, 2), ImColor(style.BGTextColor), 3.0f); 309 | pDraw->AddText(ImGui::GetItemRectMin() + ImVec2(2, 2), ImColor(style.BGTextColor), isOpen ? ICON_FA_CARET_DOWN : ICON_FA_CARET_RIGHT); 310 | if (ImGui::ButtonBehavior(ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()), id, nullptr, nullptr, ImGuiButtonFlags_MouseButtonLeft)) 311 | { 312 | isOpen = !isOpen; 313 | ImGui::GetCurrentWindow()->StateStorage.SetBool(id, isOpen); 314 | } 315 | } 316 | 317 | trackTextCursor.x += caretSize; 318 | pDraw->AddText(trackTextCursor, ImColor(style.BGTextColor), pName); 319 | return isOpen; 320 | }; 321 | 322 | { 323 | URange gpuRange = gGPUProfiler.GetFrameRange(); 324 | for (const GPUProfiler::QueueInfo& queue : gGPUProfiler.GetQueues()) 325 | { 326 | // Add thread name for track 327 | bool isOpen = TrackHeader(queue.Name, ImGui::GetID(&queue)); 328 | uint32 maxDepth = isOpen ? style.MaxDepth : 1; 329 | uint32 trackDepth = 1; 330 | cursor.y += style.BarHeight; 331 | 332 | for (uint32 i = gpuRange.Begin; i < gpuRange.End; ++i) 333 | { 334 | // Add a bar in the right place for each event 335 | /* 336 | |[=============] | 337 | | [======] | 338 | */ 339 | Span events = gGPUProfiler.GetEventsForQueue(queue, i); 340 | for (const GPUProfiler::EventData::Event& event : events) 341 | { 342 | // Skip events above the max depth 343 | if ((int)event.Depth >= maxDepth) 344 | continue; 345 | 346 | trackDepth = ImMax(trackDepth, (uint32)event.Depth + 1); 347 | 348 | uint64 cpuBeginTicks = queue.GpuToCpuTicks(event.TicksBegin); 349 | uint64 cpuEndTicks = queue.GpuToCpuTicks(event.TicksEnd); 350 | 351 | bool hovered; 352 | DrawBar(ImGui::GetID(&event), cpuBeginTicks, cpuEndTicks, event.Depth, event.pName, &hovered); 353 | if (hovered) 354 | { 355 | if (ImGui::BeginTooltip()) 356 | { 357 | ImGui::Text("%s | %.3f ms", event.pName, TicksToMs * (float)(cpuEndTicks - cpuBeginTicks)); 358 | ImGui::Text("Frame %d", i); 359 | if (event.pFilePath) 360 | ImGui::Text("%s:%d", event.pFilePath, event.LineNumber); 361 | ImGui::EndTooltip(); 362 | } 363 | } 364 | } 365 | } 366 | 367 | // Add vertical line to end track 368 | cursor.y += trackDepth * style.BarHeight; 369 | pDraw->AddLine(ImVec2(timelineRect.Min.x, cursor.y), ImVec2(timelineRect.Max.x, cursor.y), ImColor(style.BGTextColor)); 370 | } 371 | } 372 | 373 | // Split between GPU and CPU tracks 374 | pDraw->AddLine(ImVec2(timelineRect.Min.x, cursor.y), ImVec2(timelineRect.Max.x, cursor.y), ImColor(style.BGTextColor), 4); 375 | 376 | // Draw each CPU thread track 377 | Span threads = gCPUProfiler.GetThreads(); 378 | for (uint32 threadIndex = 0; threadIndex < (uint32)threads.size(); ++threadIndex) 379 | { 380 | // Add thread name for track 381 | const CPUProfiler::ThreadData& thread = threads[threadIndex]; 382 | const char* pHeaderText; 383 | ImFormatStringToTempBuffer(&pHeaderText, nullptr, "%s [%d]", thread.Name, thread.ThreadID); 384 | bool isOpen = TrackHeader(pHeaderText, ImGui::GetID(&thread)); 385 | 386 | uint32 maxDepth = isOpen ? style.MaxDepth : 1; 387 | uint32 trackDepth = 1; 388 | cursor.y += style.BarHeight; 389 | 390 | // Add a bar in the right place for each event 391 | /* 392 | |[=============] | 393 | | [======] | 394 | */ 395 | for (uint32 frameIndex = cpuRange.Begin; frameIndex < cpuRange.End; ++frameIndex) 396 | { 397 | Span events = gCPUProfiler.GetEventsForThread(thread, frameIndex); 398 | for (const CPUProfiler::EventData::Event& event : events) 399 | { 400 | // Skip events above the max depth 401 | if (event.Depth >= maxDepth) 402 | continue; 403 | 404 | trackDepth = ImMax(trackDepth, (uint32)event.Depth + 1); 405 | 406 | bool hovered; 407 | DrawBar(ImGui::GetID(&event), event.TicksBegin, event.TicksEnd, event.Depth, event.pName, &hovered); 408 | if (hovered) 409 | { 410 | if (ImGui::BeginTooltip()) 411 | { 412 | ImGui::Text("%s | %.3f ms", event.pName, TicksToMs * (float)(event.TicksEnd - event.TicksBegin)); 413 | ImGui::Text("Frame %d", frameIndex); 414 | if (event.pFilePath) 415 | ImGui::Text("%s:%d", event.pFilePath, event.LineNumber); 416 | ImGui::EndTooltip(); 417 | } 418 | } 419 | } 420 | } 421 | 422 | // Add vertical line to end track 423 | cursor.y += trackDepth * style.BarHeight; 424 | pDraw->AddLine(ImVec2(timelineRect.Min.x, cursor.y), ImVec2(timelineRect.Max.x, cursor.y), ImColor(style.BGTextColor)); 425 | } 426 | 427 | // The final height of the timeline 428 | float timelineHeight = cursor.y - cursorStart.y; 429 | 430 | if (ImGui::IsWindowFocused()) 431 | { 432 | // Profile range 433 | // If not currently in selection, start selection when left mouse button is pressed 434 | if (!context.IsSelectingRange && ImGui::IsMouseHoveringRect(timelineRect.Min, timelineRect.Max)) 435 | { 436 | if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) 437 | { 438 | context.RangeSelectionStart = ImGui::GetMousePos().x; 439 | context.IsSelectingRange = true; 440 | } 441 | } 442 | else if (context.IsSelectingRange) 443 | { 444 | // If mouse button is released, exit measuring mode 445 | if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) 446 | { 447 | context.IsSelectingRange = false; 448 | } 449 | else 450 | { 451 | // Distance between mouse cursor and measuring start 452 | float distance = fabs(ImGui::GetMousePos().x - context.RangeSelectionStart); 453 | 454 | // Fade in based on distance 455 | float opacity = ImClamp(distance / 30.0f, 0.0f, 1.0f); 456 | if (opacity > 0.0f) 457 | { 458 | float time = (distance / TicksToPixels) * TicksToMs; 459 | 460 | // Draw measure region 461 | pDraw->AddRectFilled(ImVec2(context.RangeSelectionStart, timelineRect.Min.y), ImVec2(ImGui::GetMousePos().x, timelineRect.Max.y), ImColor(1.0f, 1.0f, 1.0f, 0.1f)); 462 | pDraw->AddLine(ImVec2(context.RangeSelectionStart, timelineRect.Min.y), ImVec2(context.RangeSelectionStart, timelineRect.Max.y), ImColor(1.0f, 1.0f, 1.0f, 0.3f), 3.0f); 463 | pDraw->AddLine(ImVec2(ImGui::GetMousePos().x, timelineRect.Min.y), ImVec2(ImGui::GetMousePos().x, timelineRect.Max.y), ImColor(1.0f, 1.0f, 1.0f, 0.3f), 3.0f); 464 | 465 | // Add line and arrows 466 | ImColor measureColor = style.FGTextColor; 467 | measureColor.Value.w *= opacity; 468 | ImVec2 lineStart = ImVec2(context.RangeSelectionStart, ImGui::GetMousePos().y); 469 | ImVec2 lineEnd = ImGui::GetMousePos(); 470 | if (lineStart.x > lineEnd.x) 471 | std::swap(lineStart.x, lineEnd.x); 472 | pDraw->AddLine(lineStart, lineEnd, measureColor); 473 | pDraw->AddLine(lineStart, lineStart + ImVec2(5, 5), measureColor); 474 | pDraw->AddLine(lineStart, lineStart + ImVec2(5, -5), measureColor); 475 | pDraw->AddLine(lineEnd, lineEnd + ImVec2(-5, 5), measureColor); 476 | pDraw->AddLine(lineEnd, lineEnd + ImVec2(-5, -5), measureColor); 477 | 478 | // Add text in the middle 479 | const char* pTimeText; 480 | ImFormatStringToTempBuffer(&pTimeText, nullptr, "Time: %.3f ms", time); 481 | ImVec2 textSize = ImGui::CalcTextSize(pTimeText); 482 | pDraw->AddText((lineEnd + lineStart) / 2 - ImVec2(textSize.x * 0.5f, textSize.y), measureColor, pTimeText); 483 | } 484 | } 485 | } 486 | 487 | // Zoom behavior 488 | float zoomDelta = 0.0f; 489 | if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) 490 | zoomDelta += ImGui::GetIO().MouseWheel / 5.0f; 491 | 492 | if (zoomDelta != 0) 493 | { 494 | // Logarithmic scale 495 | float logScale = logf(context.TimelineScale); 496 | logScale += zoomDelta; 497 | float newScale = ImClamp(expf(logScale), 1.0f, 100.0f); 498 | 499 | float scaleFactor = newScale / context.TimelineScale; 500 | context.TimelineScale *= scaleFactor; 501 | ImVec2 mousePos = ImGui::GetMousePos() - timelineRect.Min; 502 | context.TimelineOffset.x = mousePos.x - (mousePos.x - context.TimelineOffset.x) * scaleFactor; 503 | } 504 | } 505 | 506 | // Panning behavior 507 | bool held; 508 | ImGui::ButtonBehavior(timelineRect, timelineID, nullptr, &held, ImGuiButtonFlags_MouseButtonRight); 509 | if (held) 510 | context.TimelineOffset += ImGui::GetIO().MouseDelta; 511 | 512 | // Compute the new timeline size to correctly clamp the offset 513 | timelineWidth = timelineRect.GetWidth() * context.TimelineScale; 514 | context.TimelineOffset = ImClamp(context.TimelineOffset, ImMin(ImVec2(0.0f, 0.0f), timelineRect.GetSize() - ImVec2(timelineWidth, timelineHeight)), ImVec2(0.0f, 0.0f)); 515 | 516 | ImGui::PopClipRect(); 517 | ImGui::PopClipRect(); 518 | 519 | // Draw a debug rect around the timeline item and the whole (unclipped) timeline rect 520 | if (style.DebugMode) 521 | { 522 | pDraw->PushClipRectFullScreen(); 523 | pDraw->AddRect(cursorStart, cursorStart + ImVec2(timelineWidth, timelineHeight), ImColor(1.0f, 0.0f, 0.0f), 0.0f, ImDrawFlags_None, 3.0f); 524 | pDraw->AddRect(timelineRect.Min, timelineRect.Max, ImColor(0.0f, 1.0f, 0.0f), 0.0f, ImDrawFlags_None, 2.0f); 525 | pDraw->PopClipRect(); 526 | } 527 | 528 | // Horizontal scroll bar 529 | ImS64 scrollH = -(ImS64)context.TimelineOffset.x; 530 | ImGui::ScrollbarEx(ImRect(ImVec2(timelineRect.Min.x, timelineRect.Max.y), ImVec2(timelineRect.Max.x + style.ScrollBarSize, timelineRect.Max.y + style.ScrollBarSize)), ImGui::GetID("ScrollH"), ImGuiAxis_X, &scrollH, (ImS64)timelineRect.GetSize().x, (ImS64)timelineWidth, ImDrawFlags_None); 531 | context.TimelineOffset.x = -(float)scrollH; 532 | 533 | // Vertical scroll bar 534 | ImS64 scrollV = -(ImS64)context.TimelineOffset.y; 535 | ImGui::ScrollbarEx(ImRect(ImVec2(timelineRect.Max.x, timelineRect.Min.y), ImVec2(timelineRect.Max.x + style.ScrollBarSize, timelineRect.Max.y)), ImGui::GetID("ScrollV"), ImGuiAxis_Y, &scrollV, (ImS64)timelineRect.GetSize().y, (ImS64)timelineHeight, ImDrawFlags_None); 536 | context.TimelineOffset.y = -(float)scrollV; 537 | } 538 | } 539 | 540 | void DrawProfilerHUD() 541 | { 542 | HUDContext& context = Context(); 543 | StyleOptions& style = context.Style; 544 | 545 | if (gCPUProfiler.IsPaused()) 546 | ImGui::Text("Paused"); 547 | else 548 | ImGui::Text("Press Space to pause"); 549 | 550 | ImGui::SameLine(ImGui::GetWindowWidth() - 620); 551 | 552 | ImGui::Checkbox("Pause threshold", &Context().PauseThreshold); 553 | ImGui::SameLine(); 554 | ImGui::SetNextItemWidth(150); 555 | ImGui::SliderFloat("##Treshold", &context.PauseThresholdTime, 0.0f, 16.0f, "%.3f", ImGuiSliderFlags_Logarithmic); 556 | ImGui::SameLine(); 557 | 558 | ImGui::Dummy(ImVec2(30, 0)); 559 | ImGui::SameLine(); 560 | 561 | ImGui::Text("Filter"); 562 | ImGui::SetNextItemWidth(150); 563 | ImGui::SameLine(); 564 | ImGui::InputText("##Search", context.SearchString, ARRAYSIZE(context.SearchString)); 565 | ImGui::SameLine(); 566 | if (ImGui::Button(ICON_FA_TIMES "##clearfilter")) 567 | context.SearchString[0] = 0; 568 | ImGui::SameLine(); 569 | if (ImGui::Button(ICON_FA_PAINT_BRUSH "##styleeditor")) 570 | ImGui::OpenPopup("Style Editor"); 571 | 572 | if (ImGui::BeginPopup("Style Editor")) 573 | { 574 | EditStyle(style); 575 | ImGui::EndPopup(); 576 | } 577 | 578 | if (ImGui::IsKeyPressed(ImGuiKey_Space)) 579 | { 580 | context.IsPaused = !context.IsPaused; 581 | } 582 | 583 | gCPUProfiler.SetPaused(context.IsPaused); 584 | gGPUProfiler.SetPaused(context.IsPaused); 585 | 586 | DrawProfilerTimeline(ImVec2(0, 0)); 587 | } 588 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TimelineProfiler 2 | Simple CPU/GPU profiler with ImGui HUD 3 | GPU profiler only supports D3D12 4 | 5 | ![](Image.jpg) 6 | 7 | ## Usage 8 | 9 | ### Setup 10 | 11 | Add files to project: 12 | - Profiler.h 13 | - Profiler.cpp 14 | - ProfilerWindow.cpp 15 | - IconsFontAwesome4.h 16 | - fontawesome-webfont.ttf 17 | 18 | Add the icon font and merge it with your main font 19 | ```c++ 20 | ImFontConfig fontConfig; 21 | fontConfig.MergeMode = true; 22 | fontConfig.GlyphMinAdvanceX = 15.0f 23 | static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; 24 | io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FA, 15.0f, &fontConfig, icon_ranges); 25 | ``` 26 | 27 | ### CPU Profiler 28 | 29 | #### Initialize 30 | 31 | ```c++ 32 | // Initialize 33 | gCPUProfiler.Initialize(historySize, maxNumEvents); 34 | ``` 35 | 36 | #### Shutdown 37 | 38 | ```c++ 39 | // Shutdown 40 | gCPUProfiler.Shutdown(); 41 | ``` 42 | 43 | #### Each frame 44 | ```c++ 45 | // Call at the start of each frame 46 | PROFILE_FRAME() 47 | ``` 48 | 49 | **CPU Event** 50 | 51 | `PROFILE_CPU_SCOPE()` to add a CPU event. Optionally specify a custom name 52 | 53 | 54 | **Registering a thread (optional)** 55 | 56 | `PROFILE_REGISTER_THREAD(name)` to register a thread. 57 | 58 | The registration order of threads will define the order in the timeline 59 | If a thread is not registered, it will lazy-register when an event is created first. 60 | 61 | 62 | ### GPU Profiler 63 | 64 | If you want to use the GPU profiler, initialize and shutdown as following, providing your command queues. 65 | 66 | #### Initialize 67 | 68 | ```c++ 69 | // Initialize 70 | Span queues; 71 | gGPUProfiler.Initialize(d3dDevice, queues, historySize, frameLatency, maxNumEvents, maxActiveCommandLists); 72 | ``` 73 | 74 | #### Shutdown 75 | 76 | ```c++ 77 | // Shutdown 78 | gGPUProfiler.Shutdown(); 79 | ``` 80 | 81 | #### Each frame 82 | ```c++ 83 | // Call at the start of each frame 84 | PROFILE_FRAME() 85 | ``` 86 | 87 | #### Each `ExecuteCommandLists` (not optional!) 88 | 89 | ```c++ 90 | ID3D12CommandQueue* queue = ...; 91 | Span cmdlists = ...; 92 | PROFILE_EXECUTE_COMMANDLISTS(queue, cmdlists); 93 | queue->ExecuteCommandLists(cmdlists.data(), cmdlists.size()); 94 | ``` 95 | 96 | #### Adding events 97 | 98 | `PROFILE_GPU_SCOPE(commandlist, name)` to add a GPU event. 99 | 100 | Specify the ID3D12GraphicsCommandList, and optionally a name. -------------------------------------------------------------------------------- /fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simco50/TimelineProfiler/f8ffd365226e2bbce74db1a6b024c8681ae85f33/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Dear ImGui Demo] 2 | Pos=650,19 3 | Size=550,680 4 | Collapsed=0 5 | 6 | [Window][Hello, world!] 7 | Pos=60,60 8 | Size=339,180 9 | Collapsed=0 10 | 11 | [Window][Debug##Default] 12 | Pos=134,120 13 | Size=1012,545 14 | Collapsed=0 15 | 16 | [Docking][Data] 17 | 18 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // Dear ImGui: standalone example application for DirectX 12 2 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 3 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 4 | 5 | // Important: to compile on 32-bit systems, the DirectX12 backend requires code to be compiled with '#define ImTextureID ImU64'. 6 | // This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*. 7 | // This define is set in the example .vcxproj file and need to be replicated in your app or by adding it to your imconfig.h file. 8 | 9 | #include "ImGui/imgui.h" 10 | #include "ImGui/imgui_impl_win32.h" 11 | #include "ImGui/imgui_impl_dx12.h" 12 | #include 13 | #include 14 | #include 15 | 16 | #include "Profiler.h" 17 | #include "IconsFontAwesome4.h" 18 | 19 | #ifdef _DEBUG 20 | #define DX12_ENABLE_DEBUG_LAYER 21 | #endif 22 | 23 | #ifdef DX12_ENABLE_DEBUG_LAYER 24 | #include 25 | #pragma comment(lib, "dxguid.lib") 26 | #endif 27 | 28 | struct FrameContext 29 | { 30 | ID3D12CommandAllocator* CommandAllocator; 31 | UINT64 FenceValue; 32 | }; 33 | 34 | // Data 35 | static int const NUM_FRAMES_IN_FLIGHT = 2; 36 | static FrameContext g_frameContext[NUM_FRAMES_IN_FLIGHT] = {}; 37 | static UINT g_frameIndex = 0; 38 | 39 | static int const NUM_BACK_BUFFERS = 2; 40 | static ID3D12Device* g_pd3dDevice = nullptr; 41 | static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = nullptr; 42 | static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = nullptr; 43 | static ID3D12CommandQueue* g_pd3dCommandQueue = nullptr; 44 | static ID3D12GraphicsCommandList* g_pd3dCommandList = nullptr; 45 | static ID3D12Fence* g_fence = nullptr; 46 | static HANDLE g_fenceEvent = nullptr; 47 | static UINT64 g_fenceLastSignaledValue = 0; 48 | static IDXGISwapChain3* g_pSwapChain = nullptr; 49 | static HANDLE g_hSwapChainWaitableObject = nullptr; 50 | static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {}; 51 | static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {}; 52 | 53 | // Forward declarations of helper functions 54 | bool CreateDeviceD3D(HWND hWnd); 55 | void CleanupDeviceD3D(); 56 | void CreateRenderTarget(); 57 | void CleanupRenderTarget(); 58 | void WaitForLastSubmittedFrame(); 59 | FrameContext* WaitForNextFrameResources(); 60 | LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 61 | 62 | // Main code 63 | int main(int, char**) 64 | { 65 | // Create application window 66 | //ImGui_ImplWin32_EnableDpiAwareness(); 67 | WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; 68 | ::RegisterClassExW(&wc); 69 | HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX12 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); 70 | 71 | // Initialize Direct3D 72 | if (!CreateDeviceD3D(hwnd)) 73 | { 74 | CleanupDeviceD3D(); 75 | ::UnregisterClassW(wc.lpszClassName, wc.hInstance); 76 | return 1; 77 | } 78 | 79 | // Show the window 80 | ::ShowWindow(hwnd, SW_SHOWDEFAULT); 81 | ::UpdateWindow(hwnd); 82 | 83 | // Setup Dear ImGui context 84 | IMGUI_CHECKVERSION(); 85 | ImGui::CreateContext(); 86 | ImGuiIO& io = ImGui::GetIO(); (void)io; 87 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 88 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 89 | io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking 90 | io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows 91 | //io.ConfigViewportsNoAutoMerge = true; 92 | //io.ConfigViewportsNoTaskBarIcon = true; 93 | 94 | // Setup Dear ImGui style 95 | ImGui::StyleColorsDark(); 96 | //ImGui::StyleColorsLight(); 97 | 98 | // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. 99 | ImGuiStyle& style = ImGui::GetStyle(); 100 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 101 | { 102 | style.WindowRounding = 0.0f; 103 | style.Colors[ImGuiCol_WindowBg].w = 1.0f; 104 | } 105 | 106 | // Setup Platform/Renderer backends 107 | ImGui_ImplWin32_Init(hwnd); 108 | ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT, 109 | DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap, 110 | g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), 111 | g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); 112 | 113 | // Load Fonts 114 | // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. 115 | // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. 116 | // - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). 117 | // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. 118 | // - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering. 119 | // - Read 'docs/FONTS.md' for more instructions and details. 120 | // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! 121 | { 122 | io.Fonts->AddFontDefault(); 123 | } 124 | //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); 125 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); 126 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); 127 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); 128 | //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); 129 | //IM_ASSERT(font != nullptr); 130 | 131 | { 132 | ImFontConfig fontConfig; 133 | fontConfig.MergeMode = true; 134 | fontConfig.GlyphMinAdvanceX = 15.0f; // Use if you want to make the icon monospaced 135 | fontConfig.PixelSnapH = true; 136 | fontConfig.GlyphOffset.y -= 2.5f; 137 | static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; 138 | io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FA, 15.0f, &fontConfig, icon_ranges); 139 | } 140 | 141 | gCPUProfiler.Initialize(5, 1024); 142 | Span queues(&g_pd3dCommandQueue, 1); 143 | gGPUProfiler.Initialize(g_pd3dDevice, queues, 5, 3, 1024, 128, 32); 144 | 145 | // Our state 146 | bool show_demo_window = true; 147 | bool show_another_window = false; 148 | ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 149 | 150 | // Main loop 151 | bool done = false; 152 | while (!done) 153 | { 154 | PROFILE_FRAME(); 155 | 156 | // Poll and handle messages (inputs, window resize, etc.) 157 | // See the WndProc() function below for our to dispatch events to the Win32 backend. 158 | MSG msg; 159 | while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE)) 160 | { 161 | ::TranslateMessage(&msg); 162 | ::DispatchMessage(&msg); 163 | if (msg.message == WM_QUIT) 164 | done = true; 165 | } 166 | if (done) 167 | break; 168 | 169 | // Start the Dear ImGui frame 170 | ImGui_ImplDX12_NewFrame(); 171 | ImGui_ImplWin32_NewFrame(); 172 | ImGui::NewFrame(); 173 | 174 | DrawProfilerHUD(); 175 | 176 | // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). 177 | if (show_demo_window) 178 | { 179 | PROFILE_CPU_SCOPE("Demo"); 180 | ImGui::ShowDemoWindow(&show_demo_window); 181 | } 182 | 183 | // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. 184 | { 185 | PROFILE_CPU_SCOPE("Simple Window"); 186 | static float f = 0.0f; 187 | static int counter = 0; 188 | 189 | ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. 190 | 191 | ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) 192 | ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state 193 | ImGui::Checkbox("Another Window", &show_another_window); 194 | 195 | ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f 196 | ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color 197 | 198 | if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) 199 | counter++; 200 | ImGui::SameLine(); 201 | ImGui::Text("counter = %d", counter); 202 | 203 | ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); 204 | ImGui::End(); 205 | } 206 | 207 | // 3. Show another simple window. 208 | if (show_another_window) 209 | { 210 | PROFILE_CPU_SCOPE("Another Window"); 211 | ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) 212 | ImGui::Text("Hello from another window!"); 213 | if (ImGui::Button("Close Me")) 214 | show_another_window = false; 215 | ImGui::End(); 216 | } 217 | 218 | // Rendering 219 | { 220 | PROFILE_CPU_SCOPE("ImGui Render"); 221 | ImGui::Render(); 222 | } 223 | 224 | FrameContext* frameCtx = WaitForNextFrameResources(); 225 | UINT backBufferIdx = g_pSwapChain->GetCurrentBackBufferIndex(); 226 | frameCtx->CommandAllocator->Reset(); 227 | 228 | D3D12_RESOURCE_BARRIER barrier = {}; 229 | barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; 230 | barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; 231 | barrier.Transition.pResource = g_mainRenderTargetResource[backBufferIdx]; 232 | barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; 233 | barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; 234 | barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; 235 | g_pd3dCommandList->Reset(frameCtx->CommandAllocator, nullptr); 236 | 237 | { 238 | PROFILE_GPU_SCOPE(g_pd3dCommandList, "Render"); 239 | g_pd3dCommandList->ResourceBarrier(1, &barrier); 240 | 241 | // Render Dear ImGui graphics 242 | const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w }; 243 | g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], clear_color_with_alpha, 0, nullptr); 244 | g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, nullptr); 245 | g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap); 246 | ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), g_pd3dCommandList); 247 | barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; 248 | barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; 249 | g_pd3dCommandList->ResourceBarrier(1, &barrier); 250 | 251 | } 252 | g_pd3dCommandList->Close(); 253 | 254 | Span cmdlists((ID3D12CommandList**)&g_pd3dCommandList, 1); 255 | PROFILE_EXECUTE_COMMANDLISTS(g_pd3dCommandQueue, cmdlists); 256 | g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList); 257 | 258 | // Update and Render additional Platform Windows 259 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 260 | { 261 | ImGui::UpdatePlatformWindows(); 262 | ImGui::RenderPlatformWindowsDefault(nullptr, (void*)g_pd3dCommandList); 263 | } 264 | 265 | g_pSwapChain->Present(1, 0); // Present with vsync 266 | //g_pSwapChain->Present(0, 0); // Present without vsync 267 | 268 | UINT64 fenceValue = g_fenceLastSignaledValue + 1; 269 | g_pd3dCommandQueue->Signal(g_fence, fenceValue); 270 | g_fenceLastSignaledValue = fenceValue; 271 | frameCtx->FenceValue = fenceValue; 272 | } 273 | 274 | WaitForLastSubmittedFrame(); 275 | 276 | // Cleanup 277 | ImGui_ImplDX12_Shutdown(); 278 | ImGui_ImplWin32_Shutdown(); 279 | ImGui::DestroyContext(); 280 | 281 | gGPUProfiler.Shutdown(); 282 | gCPUProfiler.Shutdown(); 283 | 284 | CleanupDeviceD3D(); 285 | ::DestroyWindow(hwnd); 286 | ::UnregisterClassW(wc.lpszClassName, wc.hInstance); 287 | 288 | return 0; 289 | } 290 | 291 | // Helper functions 292 | bool CreateDeviceD3D(HWND hWnd) 293 | { 294 | // Setup swap chain 295 | DXGI_SWAP_CHAIN_DESC1 sd; 296 | { 297 | ZeroMemory(&sd, sizeof(sd)); 298 | sd.BufferCount = NUM_BACK_BUFFERS; 299 | sd.Width = 0; 300 | sd.Height = 0; 301 | sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 302 | sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; 303 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 304 | sd.SampleDesc.Count = 1; 305 | sd.SampleDesc.Quality = 0; 306 | sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; 307 | sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; 308 | sd.Scaling = DXGI_SCALING_STRETCH; 309 | sd.Stereo = FALSE; 310 | } 311 | 312 | // [DEBUG] Enable debug interface 313 | #ifdef DX12_ENABLE_DEBUG_LAYER 314 | ID3D12Debug* pdx12Debug = nullptr; 315 | if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pdx12Debug)))) 316 | pdx12Debug->EnableDebugLayer(); 317 | #endif 318 | 319 | // Create device 320 | D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0; 321 | if (D3D12CreateDevice(nullptr, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK) 322 | return false; 323 | 324 | // [DEBUG] Setup debug interface to break on any warnings/errors 325 | #ifdef DX12_ENABLE_DEBUG_LAYER 326 | if (pdx12Debug != nullptr) 327 | { 328 | ID3D12InfoQueue* pInfoQueue = nullptr; 329 | g_pd3dDevice->QueryInterface(IID_PPV_ARGS(&pInfoQueue)); 330 | pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, true); 331 | pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, true); 332 | pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, true); 333 | pInfoQueue->Release(); 334 | pdx12Debug->Release(); 335 | } 336 | #endif 337 | 338 | { 339 | D3D12_DESCRIPTOR_HEAP_DESC desc = {}; 340 | desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; 341 | desc.NumDescriptors = NUM_BACK_BUFFERS; 342 | desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; 343 | desc.NodeMask = 1; 344 | if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK) 345 | return false; 346 | 347 | SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); 348 | D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart(); 349 | for (UINT i = 0; i < NUM_BACK_BUFFERS; i++) 350 | { 351 | g_mainRenderTargetDescriptor[i] = rtvHandle; 352 | rtvHandle.ptr += rtvDescriptorSize; 353 | } 354 | } 355 | 356 | { 357 | D3D12_DESCRIPTOR_HEAP_DESC desc = {}; 358 | desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; 359 | desc.NumDescriptors = 1; 360 | desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; 361 | if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK) 362 | return false; 363 | } 364 | 365 | { 366 | D3D12_COMMAND_QUEUE_DESC desc = {}; 367 | desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; 368 | desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; 369 | desc.NodeMask = 1; 370 | if (g_pd3dDevice->CreateCommandQueue(&desc, IID_PPV_ARGS(&g_pd3dCommandQueue)) != S_OK) 371 | return false; 372 | } 373 | 374 | for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++) 375 | if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK) 376 | return false; 377 | 378 | if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, nullptr, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK || 379 | g_pd3dCommandList->Close() != S_OK) 380 | return false; 381 | 382 | if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK) 383 | return false; 384 | 385 | g_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); 386 | if (g_fenceEvent == nullptr) 387 | return false; 388 | 389 | { 390 | IDXGIFactory4* dxgiFactory = nullptr; 391 | IDXGISwapChain1* swapChain1 = nullptr; 392 | if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK) 393 | return false; 394 | if (dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, nullptr, nullptr, &swapChain1) != S_OK) 395 | return false; 396 | if (swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK) 397 | return false; 398 | swapChain1->Release(); 399 | dxgiFactory->Release(); 400 | g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS); 401 | g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject(); 402 | } 403 | 404 | CreateRenderTarget(); 405 | return true; 406 | } 407 | 408 | void CleanupDeviceD3D() 409 | { 410 | CleanupRenderTarget(); 411 | if (g_pSwapChain) { g_pSwapChain->SetFullscreenState(false, nullptr); g_pSwapChain->Release(); g_pSwapChain = nullptr; } 412 | if (g_hSwapChainWaitableObject != nullptr) { CloseHandle(g_hSwapChainWaitableObject); } 413 | for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++) 414 | if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = nullptr; } 415 | if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = nullptr; } 416 | if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = nullptr; } 417 | if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = nullptr; } 418 | if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = nullptr; } 419 | if (g_fence) { g_fence->Release(); g_fence = nullptr; } 420 | if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = nullptr; } 421 | if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; } 422 | 423 | #ifdef DX12_ENABLE_DEBUG_LAYER 424 | IDXGIDebug1* pDebug = nullptr; 425 | if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)))) 426 | { 427 | pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_SUMMARY); 428 | pDebug->Release(); 429 | } 430 | #endif 431 | } 432 | 433 | void CreateRenderTarget() 434 | { 435 | for (UINT i = 0; i < NUM_BACK_BUFFERS; i++) 436 | { 437 | ID3D12Resource* pBackBuffer = nullptr; 438 | g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer)); 439 | g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, g_mainRenderTargetDescriptor[i]); 440 | g_mainRenderTargetResource[i] = pBackBuffer; 441 | } 442 | } 443 | 444 | void CleanupRenderTarget() 445 | { 446 | WaitForLastSubmittedFrame(); 447 | 448 | for (UINT i = 0; i < NUM_BACK_BUFFERS; i++) 449 | if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = nullptr; } 450 | } 451 | 452 | void WaitForLastSubmittedFrame() 453 | { 454 | FrameContext* frameCtx = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT]; 455 | 456 | UINT64 fenceValue = frameCtx->FenceValue; 457 | if (fenceValue == 0) 458 | return; // No fence was signaled 459 | 460 | frameCtx->FenceValue = 0; 461 | if (g_fence->GetCompletedValue() >= fenceValue) 462 | return; 463 | 464 | g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent); 465 | WaitForSingleObject(g_fenceEvent, INFINITE); 466 | } 467 | 468 | FrameContext* WaitForNextFrameResources() 469 | { 470 | UINT nextFrameIndex = g_frameIndex + 1; 471 | g_frameIndex = nextFrameIndex; 472 | 473 | HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, nullptr }; 474 | DWORD numWaitableObjects = 1; 475 | 476 | FrameContext* frameCtx = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT]; 477 | UINT64 fenceValue = frameCtx->FenceValue; 478 | if (fenceValue != 0) // means no fence was signaled 479 | { 480 | frameCtx->FenceValue = 0; 481 | g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent); 482 | waitableObjects[1] = g_fenceEvent; 483 | numWaitableObjects = 2; 484 | } 485 | 486 | WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE); 487 | 488 | return frameCtx; 489 | } 490 | 491 | // Forward declare message handler from imgui_impl_win32.cpp 492 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 493 | 494 | // Win32 message handler 495 | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. 496 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. 497 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. 498 | // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. 499 | LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 500 | { 501 | if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) 502 | return true; 503 | 504 | switch (msg) 505 | { 506 | case WM_SIZE: 507 | if (g_pd3dDevice != nullptr && wParam != SIZE_MINIMIZED) 508 | { 509 | WaitForLastSubmittedFrame(); 510 | CleanupRenderTarget(); 511 | HRESULT result = g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT); 512 | assert(SUCCEEDED(result) && "Failed to resize swapchain."); 513 | CreateRenderTarget(); 514 | } 515 | return 0; 516 | case WM_SYSCOMMAND: 517 | if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu 518 | return 0; 519 | break; 520 | case WM_DESTROY: 521 | ::PostQuitMessage(0); 522 | return 0; 523 | } 524 | return ::DefWindowProcW(hWnd, msg, wParam, lParam); 525 | } 526 | --------------------------------------------------------------------------------