| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef AMD_VULKAN_MEMORY_ALLOCATOR_H |
| 24 |
#define AMD_VULKAN_MEMORY_ALLOCATOR_H |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#include "drivers/vulkan/godot_vulkan.h" |
| 126 |
|
| 127 |
#ifdef __cplusplus |
| 128 |
extern "C" { |
| 129 |
#endif |
| 130 |
|
| 131 |
|
| 132 |
#if !defined(VMA_VULKAN_VERSION) |
| 133 |
#if defined(VK_VERSION_1_3) |
| 134 |
#define VMA_VULKAN_VERSION 1003000 |
| 135 |
#elif defined(VK_VERSION_1_2) |
| 136 |
#define VMA_VULKAN_VERSION 1002000 |
| 137 |
#elif defined(VK_VERSION_1_1) |
| 138 |
#define VMA_VULKAN_VERSION 1001000 |
| 139 |
#else |
| 140 |
#define VMA_VULKAN_VERSION 1000000 |
| 141 |
#endif |
| 142 |
#endif |
| 143 |
|
| 144 |
#if defined(__ANDROID__) && defined(VK_NO_PROTOTYPES) && VMA_STATIC_VULKAN_FUNCTIONS |
| 145 |
extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; |
| 146 |
extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; |
| 147 |
extern PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties; |
| 148 |
extern PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties; |
| 149 |
extern PFN_vkAllocateMemory vkAllocateMemory; |
| 150 |
extern PFN_vkFreeMemory vkFreeMemory; |
| 151 |
extern PFN_vkMapMemory vkMapMemory; |
| 152 |
extern PFN_vkUnmapMemory vkUnmapMemory; |
| 153 |
extern PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges; |
| 154 |
extern PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges; |
| 155 |
extern PFN_vkBindBufferMemory vkBindBufferMemory; |
| 156 |
extern PFN_vkBindImageMemory vkBindImageMemory; |
| 157 |
extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements; |
| 158 |
extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; |
| 159 |
extern PFN_vkCreateBuffer vkCreateBuffer; |
| 160 |
extern PFN_vkDestroyBuffer vkDestroyBuffer; |
| 161 |
extern PFN_vkCreateImage vkCreateImage; |
| 162 |
extern PFN_vkDestroyImage vkDestroyImage; |
| 163 |
extern PFN_vkCmdCopyBuffer vkCmdCopyBuffer; |
| 164 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 165 |
extern PFN_vkGetBufferMemoryRequirements2 vkGetBufferMemoryRequirements2; |
| 166 |
extern PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2; |
| 167 |
extern PFN_vkBindBufferMemory2 vkBindBufferMemory2; |
| 168 |
extern PFN_vkBindImageMemory2 vkBindImageMemory2; |
| 169 |
extern PFN_vkGetPhysicalDeviceMemoryProperties2 vkGetPhysicalDeviceMemoryProperties2; |
| 170 |
#endif |
| 171 |
#endif |
| 172 |
|
| 173 |
#if !defined(VMA_DEDICATED_ALLOCATION) |
| 174 |
#if VK_KHR_get_memory_requirements2 && VK_KHR_dedicated_allocation |
| 175 |
#define VMA_DEDICATED_ALLOCATION 1 |
| 176 |
#else |
| 177 |
#define VMA_DEDICATED_ALLOCATION 0 |
| 178 |
#endif |
| 179 |
#endif |
| 180 |
|
| 181 |
#if !defined(VMA_BIND_MEMORY2) |
| 182 |
#if VK_KHR_bind_memory2 |
| 183 |
#define VMA_BIND_MEMORY2 1 |
| 184 |
#else |
| 185 |
#define VMA_BIND_MEMORY2 0 |
| 186 |
#endif |
| 187 |
#endif |
| 188 |
|
| 189 |
#if !defined(VMA_MEMORY_BUDGET) |
| 190 |
#if VK_EXT_memory_budget && (VK_KHR_get_physical_device_properties2 || VMA_VULKAN_VERSION >= 1001000) |
| 191 |
#define VMA_MEMORY_BUDGET 1 |
| 192 |
#else |
| 193 |
#define VMA_MEMORY_BUDGET 0 |
| 194 |
#endif |
| 195 |
#endif |
| 196 |
|
| 197 |
|
| 198 |
#if !defined(VMA_BUFFER_DEVICE_ADDRESS) |
| 199 |
#if VK_KHR_buffer_device_address || VMA_VULKAN_VERSION >= 1002000 |
| 200 |
#define VMA_BUFFER_DEVICE_ADDRESS 1 |
| 201 |
#else |
| 202 |
#define VMA_BUFFER_DEVICE_ADDRESS 0 |
| 203 |
#endif |
| 204 |
#endif |
| 205 |
|
| 206 |
|
| 207 |
#if !defined(VMA_MEMORY_PRIORITY) |
| 208 |
#if VK_EXT_memory_priority |
| 209 |
#define VMA_MEMORY_PRIORITY 1 |
| 210 |
#else |
| 211 |
#define VMA_MEMORY_PRIORITY 0 |
| 212 |
#endif |
| 213 |
#endif |
| 214 |
|
| 215 |
|
| 216 |
#if !defined(VMA_KHR_MAINTENANCE4) |
| 217 |
#if VK_KHR_maintenance4 |
| 218 |
#define VMA_KHR_MAINTENANCE4 1 |
| 219 |
#else |
| 220 |
#define VMA_KHR_MAINTENANCE4 0 |
| 221 |
#endif |
| 222 |
#endif |
| 223 |
|
| 224 |
|
| 225 |
#if !defined(VMA_KHR_MAINTENANCE5) |
| 226 |
#if VK_KHR_maintenance5 |
| 227 |
#define VMA_KHR_MAINTENANCE5 1 |
| 228 |
#else |
| 229 |
#define VMA_KHR_MAINTENANCE5 0 |
| 230 |
#endif |
| 231 |
#endif |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
#if !defined(VMA_EXTERNAL_MEMORY) |
| 236 |
#if VK_KHR_external_memory |
| 237 |
#define VMA_EXTERNAL_MEMORY 1 |
| 238 |
#else |
| 239 |
#define VMA_EXTERNAL_MEMORY 0 |
| 240 |
#endif |
| 241 |
#endif |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
#ifndef VMA_CALL_PRE |
| 249 |
#define VMA_CALL_PRE |
| 250 |
#endif |
| 251 |
#ifndef VMA_CALL_POST |
| 252 |
#define VMA_CALL_POST |
| 253 |
#endif |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
#ifndef VMA_EXTENDS_VK_STRUCT |
| 258 |
#define VMA_EXTENDS_VK_STRUCT(vkStruct) |
| 259 |
#endif |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
#ifndef VMA_LEN_IF_NOT_NULL |
| 273 |
#define VMA_LEN_IF_NOT_NULL(len) |
| 274 |
#endif |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
#ifndef VMA_NULLABLE |
| 279 |
#ifdef __clang__ |
| 280 |
#define VMA_NULLABLE _Nullable |
| 281 |
#else |
| 282 |
#define VMA_NULLABLE |
| 283 |
#endif |
| 284 |
#endif |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
#ifndef VMA_NOT_NULL |
| 289 |
#ifdef __clang__ |
| 290 |
#define VMA_NOT_NULL _Nonnull |
| 291 |
#else |
| 292 |
#define VMA_NOT_NULL |
| 293 |
#endif |
| 294 |
#endif |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
#ifndef VMA_NOT_NULL_NON_DISPATCHABLE |
| 299 |
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) |
| 300 |
#define VMA_NOT_NULL_NON_DISPATCHABLE VMA_NOT_NULL |
| 301 |
#else |
| 302 |
#define VMA_NOT_NULL_NON_DISPATCHABLE |
| 303 |
#endif |
| 304 |
#endif |
| 305 |
|
| 306 |
#ifndef VMA_NULLABLE_NON_DISPATCHABLE |
| 307 |
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) |
| 308 |
#define VMA_NULLABLE_NON_DISPATCHABLE VMA_NULLABLE |
| 309 |
#else |
| 310 |
#define VMA_NULLABLE_NON_DISPATCHABLE |
| 311 |
#endif |
| 312 |
#endif |
| 313 |
|
| 314 |
#ifndef VMA_STATS_STRING_ENABLED |
| 315 |
#define VMA_STATS_STRING_ENABLED 1 |
| 316 |
#endif |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
#ifndef _VMA_ENUM_DECLARATIONS |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
typedef enum VmaAllocatorCreateFlagBits |
| 336 |
{ |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT = 0x00000001, |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT = 0x00000002, |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT = 0x00000004, |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT = 0x00000008, |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT = 0x00000010, |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT = 0x00000020, |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT = 0x00000040, |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT = 0x00000080, |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT = 0x00000100, |
| 461 |
|
| 462 |
VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 463 |
} VmaAllocatorCreateFlagBits; |
| 464 |
|
| 465 |
typedef VkFlags VmaAllocatorCreateFlags; |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
typedef enum VmaMemoryUsage |
| 476 |
{ |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
VMA_MEMORY_USAGE_UNKNOWN = 0, |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
VMA_MEMORY_USAGE_GPU_ONLY = 1, |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
VMA_MEMORY_USAGE_CPU_ONLY = 2, |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
VMA_MEMORY_USAGE_CPU_TO_GPU = 3, |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
VMA_MEMORY_USAGE_GPU_TO_CPU = 4, |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
VMA_MEMORY_USAGE_CPU_COPY = 5, |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED = 6, |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
VMA_MEMORY_USAGE_AUTO = 7, |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE = 8, |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
VMA_MEMORY_USAGE_AUTO_PREFER_HOST = 9, |
| 552 |
|
| 553 |
VMA_MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF |
| 554 |
} VmaMemoryUsage; |
| 555 |
|
| 556 |
|
| 557 |
typedef enum VmaAllocationCreateFlagBits |
| 558 |
{ |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT = 0x00000001, |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT = 0x00000002, |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
VMA_ALLOCATION_CREATE_MAPPED_BIT = 0x00000004, |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT = 0x00000020, |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT = 0x00000040, |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
VMA_ALLOCATION_CREATE_DONT_BIND_BIT = 0x00000080, |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT = 0x00000100, |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT = 0x00000200, |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT = 0x00000400, |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT = 0x00000800, |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT = 0x00001000, |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = 0x00010000, |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = 0x00020000, |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT = 0x00040000, |
| 675 |
|
| 676 |
|
| 677 |
VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT, |
| 678 |
|
| 679 |
|
| 680 |
VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT, |
| 681 |
|
| 682 |
|
| 683 |
VMA_ALLOCATION_CREATE_STRATEGY_MASK = |
| 684 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT | |
| 685 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT | |
| 686 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT, |
| 687 |
|
| 688 |
VMA_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 689 |
} VmaAllocationCreateFlagBits; |
| 690 |
|
| 691 |
typedef VkFlags VmaAllocationCreateFlags; |
| 692 |
|
| 693 |
|
| 694 |
typedef enum VmaPoolCreateFlagBits |
| 695 |
{ |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT = 0x00000002, |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT = 0x00000004, |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
VMA_POOL_CREATE_ALGORITHM_MASK = |
| 731 |
VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT, |
| 732 |
|
| 733 |
VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 734 |
} VmaPoolCreateFlagBits; |
| 735 |
|
| 736 |
typedef VkFlags VmaPoolCreateFlags; |
| 737 |
|
| 738 |
|
| 739 |
typedef enum VmaDefragmentationFlagBits |
| 740 |
{ |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT = 0x1, |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT = 0x2, |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT = 0x4, |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT = 0x8, |
| 759 |
|
| 760 |
|
| 761 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_MASK = |
| 762 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT | |
| 763 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT | |
| 764 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT | |
| 765 |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT, |
| 766 |
|
| 767 |
VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 768 |
} VmaDefragmentationFlagBits; |
| 769 |
|
| 770 |
typedef VkFlags VmaDefragmentationFlags; |
| 771 |
|
| 772 |
|
| 773 |
typedef enum VmaDefragmentationMoveOperation |
| 774 |
{ |
| 775 |
|
| 776 |
VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY = 0, |
| 777 |
|
| 778 |
VMA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE = 1, |
| 779 |
|
| 780 |
VMA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY = 2, |
| 781 |
} VmaDefragmentationMoveOperation; |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
typedef enum VmaVirtualBlockCreateFlagBits |
| 792 |
{ |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT = 0x00000001, |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
VMA_VIRTUAL_BLOCK_CREATE_ALGORITHM_MASK = |
| 809 |
VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT, |
| 810 |
|
| 811 |
VMA_VIRTUAL_BLOCK_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 812 |
} VmaVirtualBlockCreateFlagBits; |
| 813 |
|
| 814 |
typedef VkFlags VmaVirtualBlockCreateFlags; |
| 815 |
|
| 816 |
|
| 817 |
typedef enum VmaVirtualAllocationCreateFlagBits |
| 818 |
{ |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
VMA_VIRTUAL_ALLOCATION_CREATE_UPPER_ADDRESS_BIT = VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT, |
| 824 |
|
| 825 |
|
| 826 |
VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT, |
| 827 |
|
| 828 |
|
| 829 |
VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT, |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT, |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MASK = VMA_ALLOCATION_CREATE_STRATEGY_MASK, |
| 839 |
|
| 840 |
VMA_VIRTUAL_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF |
| 841 |
} VmaVirtualAllocationCreateFlagBits; |
| 842 |
|
| 843 |
typedef VkFlags VmaVirtualAllocationCreateFlags; |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
#endif |
| 848 |
|
| 849 |
#ifndef _VMA_DATA_TYPES_DECLARATIONS |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
VK_DEFINE_HANDLE(VmaAllocator) |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
VK_DEFINE_HANDLE(VmaPool) |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
VK_DEFINE_HANDLE(VmaAllocation) |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
VK_DEFINE_HANDLE(VmaDefragmentationContext) |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VmaVirtualAllocation) |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
VK_DEFINE_HANDLE(VmaVirtualBlock) |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
typedef void (VKAPI_PTR* PFN_vmaAllocateDeviceMemoryFunction)( |
| 956 |
VmaAllocator VMA_NOT_NULL allocator, |
| 957 |
uint32_t memoryType, |
| 958 |
VkDeviceMemory VMA_NOT_NULL_NON_DISPATCHABLE memory, |
| 959 |
VkDeviceSize size, |
| 960 |
void* VMA_NULLABLE pUserData); |
| 961 |
|
| 962 |
|
| 963 |
typedef void (VKAPI_PTR* PFN_vmaFreeDeviceMemoryFunction)( |
| 964 |
VmaAllocator VMA_NOT_NULL allocator, |
| 965 |
uint32_t memoryType, |
| 966 |
VkDeviceMemory VMA_NOT_NULL_NON_DISPATCHABLE memory, |
| 967 |
VkDeviceSize size, |
| 968 |
void* VMA_NULLABLE pUserData); |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
typedef struct VmaDeviceMemoryCallbacks |
| 978 |
{ |
| 979 |
|
| 980 |
PFN_vmaAllocateDeviceMemoryFunction VMA_NULLABLE pfnAllocate; |
| 981 |
|
| 982 |
PFN_vmaFreeDeviceMemoryFunction VMA_NULLABLE pfnFree; |
| 983 |
|
| 984 |
void* VMA_NULLABLE pUserData; |
| 985 |
} VmaDeviceMemoryCallbacks; |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
typedef struct VmaVulkanFunctions |
| 992 |
{ |
| 993 |
|
| 994 |
PFN_vkGetInstanceProcAddr VMA_NULLABLE vkGetInstanceProcAddr; |
| 995 |
|
| 996 |
PFN_vkGetDeviceProcAddr VMA_NULLABLE vkGetDeviceProcAddr; |
| 997 |
PFN_vkGetPhysicalDeviceProperties VMA_NULLABLE vkGetPhysicalDeviceProperties; |
| 998 |
PFN_vkGetPhysicalDeviceMemoryProperties VMA_NULLABLE vkGetPhysicalDeviceMemoryProperties; |
| 999 |
PFN_vkAllocateMemory VMA_NULLABLE vkAllocateMemory; |
| 1000 |
PFN_vkFreeMemory VMA_NULLABLE vkFreeMemory; |
| 1001 |
PFN_vkMapMemory VMA_NULLABLE vkMapMemory; |
| 1002 |
PFN_vkUnmapMemory VMA_NULLABLE vkUnmapMemory; |
| 1003 |
PFN_vkFlushMappedMemoryRanges VMA_NULLABLE vkFlushMappedMemoryRanges; |
| 1004 |
PFN_vkInvalidateMappedMemoryRanges VMA_NULLABLE vkInvalidateMappedMemoryRanges; |
| 1005 |
PFN_vkBindBufferMemory VMA_NULLABLE vkBindBufferMemory; |
| 1006 |
PFN_vkBindImageMemory VMA_NULLABLE vkBindImageMemory; |
| 1007 |
PFN_vkGetBufferMemoryRequirements VMA_NULLABLE vkGetBufferMemoryRequirements; |
| 1008 |
PFN_vkGetImageMemoryRequirements VMA_NULLABLE vkGetImageMemoryRequirements; |
| 1009 |
PFN_vkCreateBuffer VMA_NULLABLE vkCreateBuffer; |
| 1010 |
PFN_vkDestroyBuffer VMA_NULLABLE vkDestroyBuffer; |
| 1011 |
PFN_vkCreateImage VMA_NULLABLE vkCreateImage; |
| 1012 |
PFN_vkDestroyImage VMA_NULLABLE vkDestroyImage; |
| 1013 |
PFN_vkCmdCopyBuffer VMA_NULLABLE vkCmdCopyBuffer; |
| 1014 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 1015 |
|
| 1016 |
PFN_vkGetBufferMemoryRequirements2KHR VMA_NULLABLE vkGetBufferMemoryRequirements2KHR; |
| 1017 |
|
| 1018 |
PFN_vkGetImageMemoryRequirements2KHR VMA_NULLABLE vkGetImageMemoryRequirements2KHR; |
| 1019 |
#endif |
| 1020 |
#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000 |
| 1021 |
|
| 1022 |
PFN_vkBindBufferMemory2KHR VMA_NULLABLE vkBindBufferMemory2KHR; |
| 1023 |
|
| 1024 |
PFN_vkBindImageMemory2KHR VMA_NULLABLE vkBindImageMemory2KHR; |
| 1025 |
#endif |
| 1026 |
#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000 |
| 1027 |
|
| 1028 |
PFN_vkGetPhysicalDeviceMemoryProperties2KHR VMA_NULLABLE vkGetPhysicalDeviceMemoryProperties2KHR; |
| 1029 |
#endif |
| 1030 |
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 |
| 1031 |
|
| 1032 |
PFN_vkGetDeviceBufferMemoryRequirementsKHR VMA_NULLABLE vkGetDeviceBufferMemoryRequirements; |
| 1033 |
|
| 1034 |
PFN_vkGetDeviceImageMemoryRequirementsKHR VMA_NULLABLE vkGetDeviceImageMemoryRequirements; |
| 1035 |
#endif |
| 1036 |
} VmaVulkanFunctions; |
| 1037 |
|
| 1038 |
|
| 1039 |
typedef struct VmaAllocatorCreateInfo |
| 1040 |
{ |
| 1041 |
|
| 1042 |
VmaAllocatorCreateFlags flags; |
| 1043 |
|
| 1044 |
|
| 1045 |
VkPhysicalDevice VMA_NOT_NULL physicalDevice; |
| 1046 |
|
| 1047 |
|
| 1048 |
VkDevice VMA_NOT_NULL device; |
| 1049 |
|
| 1050 |
|
| 1051 |
VkDeviceSize preferredLargeHeapBlockSize; |
| 1052 |
|
| 1053 |
|
| 1054 |
const VkAllocationCallbacks* VMA_NULLABLE pAllocationCallbacks; |
| 1055 |
|
| 1056 |
|
| 1057 |
const VmaDeviceMemoryCallbacks* VMA_NULLABLE pDeviceMemoryCallbacks; |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
const VkDeviceSize* VMA_NULLABLE VMA_LEN_IF_NOT_NULL("VkPhysicalDeviceMemoryProperties::memoryHeapCount") pHeapSizeLimit; |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
const VmaVulkanFunctions* VMA_NULLABLE pVulkanFunctions; |
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
VkInstance VMA_NOT_NULL instance; |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
uint32_t vulkanApiVersion; |
| 1105 |
#if VMA_EXTERNAL_MEMORY |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
const VkExternalMemoryHandleTypeFlagsKHR* VMA_NULLABLE VMA_LEN_IF_NOT_NULL("VkPhysicalDeviceMemoryProperties::memoryTypeCount") pTypeExternalMemoryHandleTypes; |
| 1116 |
#endif |
| 1117 |
} VmaAllocatorCreateInfo; |
| 1118 |
|
| 1119 |
|
| 1120 |
typedef struct VmaAllocatorInfo |
| 1121 |
{ |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
VkInstance VMA_NOT_NULL instance; |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
VkPhysicalDevice VMA_NOT_NULL physicalDevice; |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
VkDevice VMA_NOT_NULL device; |
| 1137 |
} VmaAllocatorInfo; |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
typedef struct VmaStatistics |
| 1152 |
{ |
| 1153 |
|
| 1154 |
|
| 1155 |
uint32_t blockCount; |
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
uint32_t allocationCount; |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
VkDeviceSize blockBytes; |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
VkDeviceSize allocationBytes; |
| 1175 |
} VmaStatistics; |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
typedef struct VmaDetailedStatistics |
| 1192 |
{ |
| 1193 |
|
| 1194 |
VmaStatistics statistics; |
| 1195 |
|
| 1196 |
uint32_t unusedRangeCount; |
| 1197 |
|
| 1198 |
VkDeviceSize allocationSizeMin; |
| 1199 |
|
| 1200 |
VkDeviceSize allocationSizeMax; |
| 1201 |
|
| 1202 |
VkDeviceSize unusedRangeSizeMin; |
| 1203 |
|
| 1204 |
VkDeviceSize unusedRangeSizeMax; |
| 1205 |
} VmaDetailedStatistics; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
typedef struct VmaTotalStatistics |
| 1214 |
{ |
| 1215 |
VmaDetailedStatistics memoryType[VK_MAX_MEMORY_TYPES]; |
| 1216 |
VmaDetailedStatistics memoryHeap[VK_MAX_MEMORY_HEAPS]; |
| 1217 |
VmaDetailedStatistics total; |
| 1218 |
} VmaTotalStatistics; |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
typedef struct VmaBudget |
| 1226 |
{ |
| 1227 |
|
| 1228 |
|
| 1229 |
VmaStatistics statistics; |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
VkDeviceSize usage; |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
VkDeviceSize budget; |
| 1249 |
} VmaBudget; |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
typedef struct VmaAllocationCreateInfo |
| 1263 |
{ |
| 1264 |
|
| 1265 |
VmaAllocationCreateFlags flags; |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
VmaMemoryUsage usage; |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
VkMemoryPropertyFlags requiredFlags; |
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
VkMemoryPropertyFlags preferredFlags; |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
uint32_t memoryTypeBits; |
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
VmaPool VMA_NULLABLE pool; |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
void* VMA_NULLABLE pUserData; |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
float priority; |
| 1310 |
} VmaAllocationCreateInfo; |
| 1311 |
|
| 1312 |
|
| 1313 |
typedef struct VmaPoolCreateInfo |
| 1314 |
{ |
| 1315 |
|
| 1316 |
|
| 1317 |
uint32_t memoryTypeIndex; |
| 1318 |
|
| 1319 |
|
| 1320 |
VmaPoolCreateFlags flags; |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
VkDeviceSize blockSize; |
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
size_t minBlockCount; |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
size_t maxBlockCount; |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
float priority; |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
VkDeviceSize minAllocationAlignment; |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
void* VMA_NULLABLE VMA_EXTENDS_VK_STRUCT(VkMemoryAllocateInfo) pMemoryAllocateNext; |
| 1367 |
} VmaPoolCreateInfo; |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
typedef struct VmaAllocationInfo |
| 1382 |
{ |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
uint32_t memoryType; |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
VkDeviceMemory VMA_NULLABLE_NON_DISPATCHABLE deviceMemory; |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
VkDeviceSize offset; |
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
VkDeviceSize size; |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
void* VMA_NULLABLE pMappedData; |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
void* VMA_NULLABLE pUserData; |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
const char* VMA_NULLABLE pName; |
| 1438 |
} VmaAllocationInfo; |
| 1439 |
|
| 1440 |
|
| 1441 |
typedef struct VmaAllocationInfo2 |
| 1442 |
{ |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
VmaAllocationInfo allocationInfo; |
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
VkDeviceSize blockSize; |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
VkBool32 dedicatedMemory; |
| 1459 |
} VmaAllocationInfo2; |
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
typedef VkBool32 (VKAPI_PTR* PFN_vmaCheckDefragmentationBreakFunction)(void* VMA_NULLABLE pUserData); |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
typedef struct VmaDefragmentationInfo |
| 1472 |
{ |
| 1473 |
|
| 1474 |
VmaDefragmentationFlags flags; |
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
VmaPool VMA_NULLABLE pool; |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
VkDeviceSize maxBytesPerPass; |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
uint32_t maxAllocationsPerPass; |
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
PFN_vmaCheckDefragmentationBreakFunction VMA_NULLABLE pfnBreakCallback; |
| 1495 |
|
| 1496 |
void* VMA_NULLABLE pBreakCallbackUserData; |
| 1497 |
} VmaDefragmentationInfo; |
| 1498 |
|
| 1499 |
|
| 1500 |
typedef struct VmaDefragmentationMove |
| 1501 |
{ |
| 1502 |
|
| 1503 |
VmaDefragmentationMoveOperation operation; |
| 1504 |
|
| 1505 |
VmaAllocation VMA_NOT_NULL srcAllocation; |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
VmaAllocation VMA_NOT_NULL dstTmpAllocation; |
| 1513 |
} VmaDefragmentationMove; |
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
typedef struct VmaDefragmentationPassMoveInfo |
| 1520 |
{ |
| 1521 |
|
| 1522 |
uint32_t moveCount; |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
VmaDefragmentationMove* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(moveCount) pMoves; |
| 1547 |
} VmaDefragmentationPassMoveInfo; |
| 1548 |
|
| 1549 |
|
| 1550 |
typedef struct VmaDefragmentationStats |
| 1551 |
{ |
| 1552 |
|
| 1553 |
VkDeviceSize bytesMoved; |
| 1554 |
|
| 1555 |
VkDeviceSize bytesFreed; |
| 1556 |
|
| 1557 |
uint32_t allocationsMoved; |
| 1558 |
|
| 1559 |
uint32_t deviceMemoryBlocksFreed; |
| 1560 |
} VmaDefragmentationStats; |
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
typedef struct VmaVirtualBlockCreateInfo |
| 1571 |
{ |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
VkDeviceSize size; |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
VmaVirtualBlockCreateFlags flags; |
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
const VkAllocationCallbacks* VMA_NULLABLE pAllocationCallbacks; |
| 1588 |
} VmaVirtualBlockCreateInfo; |
| 1589 |
|
| 1590 |
|
| 1591 |
typedef struct VmaVirtualAllocationCreateInfo |
| 1592 |
{ |
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
VkDeviceSize size; |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
VkDeviceSize alignment; |
| 1603 |
|
| 1604 |
|
| 1605 |
VmaVirtualAllocationCreateFlags flags; |
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
void* VMA_NULLABLE pUserData; |
| 1611 |
} VmaVirtualAllocationCreateInfo; |
| 1612 |
|
| 1613 |
|
| 1614 |
typedef struct VmaVirtualAllocationInfo |
| 1615 |
{ |
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
VkDeviceSize offset; |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
VkDeviceSize size; |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
void* VMA_NULLABLE pUserData; |
| 1631 |
} VmaVirtualAllocationInfo; |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
#endif |
| 1636 |
|
| 1637 |
#ifndef _VMA_FUNCTION_HEADERS |
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator( |
| 1646 |
const VmaAllocatorCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 1647 |
VmaAllocator VMA_NULLABLE* VMA_NOT_NULL pAllocator); |
| 1648 |
|
| 1649 |
|
| 1650 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyAllocator( |
| 1651 |
VmaAllocator VMA_NULLABLE allocator); |
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocatorInfo( |
| 1659 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1660 |
VmaAllocatorInfo* VMA_NOT_NULL pAllocatorInfo); |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPhysicalDeviceProperties( |
| 1667 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1668 |
const VkPhysicalDeviceProperties* VMA_NULLABLE* VMA_NOT_NULL ppPhysicalDeviceProperties); |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryProperties( |
| 1675 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1676 |
const VkPhysicalDeviceMemoryProperties* VMA_NULLABLE* VMA_NOT_NULL ppPhysicalDeviceMemoryProperties); |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryTypeProperties( |
| 1685 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1686 |
uint32_t memoryTypeIndex, |
| 1687 |
VkMemoryPropertyFlags* VMA_NOT_NULL pFlags); |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetCurrentFrameIndex( |
| 1692 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1693 |
uint32_t frameIndex); |
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStatistics( |
| 1713 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1714 |
VmaTotalStatistics* VMA_NOT_NULL pStats); |
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
VMA_CALL_PRE uint64_t VMA_CALL_POST vmaCalculateLazilyAllocatedBytes( |
| 1727 |
VmaAllocator VMA_NOT_NULL allocator); |
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetHeapBudgets( |
| 1741 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1742 |
VmaBudget* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL("VkPhysicalDeviceMemoryProperties::memoryHeapCount") pBudgets); |
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndex( |
| 1768 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1769 |
uint32_t memoryTypeBits, |
| 1770 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 1771 |
uint32_t* VMA_NOT_NULL pMemoryTypeIndex); |
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo( |
| 1780 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1781 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 1782 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 1783 |
uint32_t* VMA_NOT_NULL pMemoryTypeIndex); |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo( |
| 1792 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1793 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 1794 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 1795 |
uint32_t* VMA_NOT_NULL pMemoryTypeIndex); |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreatePool( |
| 1804 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1805 |
const VmaPoolCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 1806 |
VmaPool VMA_NULLABLE* VMA_NOT_NULL pPool); |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool( |
| 1811 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1812 |
VmaPool VMA_NULLABLE pool); |
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolStatistics( |
| 1828 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1829 |
VmaPool VMA_NOT_NULL pool, |
| 1830 |
VmaStatistics* VMA_NOT_NULL pPoolStats); |
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculatePoolStatistics( |
| 1839 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1840 |
VmaPool VMA_NOT_NULL pool, |
| 1841 |
VmaDetailedStatistics* VMA_NOT_NULL pPoolStats); |
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption( |
| 1865 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1866 |
VmaPool VMA_NOT_NULL pool); |
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName( |
| 1875 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1876 |
VmaPool VMA_NOT_NULL pool, |
| 1877 |
const char* VMA_NULLABLE* VMA_NOT_NULL ppName); |
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName( |
| 1885 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1886 |
VmaPool VMA_NOT_NULL pool, |
| 1887 |
const char* VMA_NULLABLE pName); |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory( |
| 1903 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1904 |
const VkMemoryRequirements* VMA_NOT_NULL pVkMemoryRequirements, |
| 1905 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 1906 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 1907 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryPages( |
| 1929 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1930 |
const VkMemoryRequirements* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(allocationCount) pVkMemoryRequirements, |
| 1931 |
const VmaAllocationCreateInfo* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(allocationCount) pCreateInfo, |
| 1932 |
size_t allocationCount, |
| 1933 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(allocationCount) pAllocations, |
| 1934 |
VmaAllocationInfo* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) pAllocationInfo); |
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForBuffer( |
| 1951 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1952 |
VkBuffer VMA_NOT_NULL_NON_DISPATCHABLE buffer, |
| 1953 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 1954 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 1955 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForImage( |
| 1972 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1973 |
VkImage VMA_NOT_NULL_NON_DISPATCHABLE image, |
| 1974 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 1975 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 1976 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory( |
| 1983 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1984 |
const VmaAllocation VMA_NULLABLE allocation); |
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages( |
| 1997 |
VmaAllocator VMA_NOT_NULL allocator, |
| 1998 |
size_t allocationCount, |
| 1999 |
const VmaAllocation VMA_NULLABLE* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(allocationCount) pAllocations); |
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo( |
| 2015 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2016 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2017 |
VmaAllocationInfo* VMA_NOT_NULL pAllocationInfo); |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo2( |
| 2027 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2028 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2029 |
VmaAllocationInfo2* VMA_NOT_NULL pAllocationInfo); |
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationUserData( |
| 2038 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2039 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2040 |
void* VMA_NULLABLE pUserData); |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationName( |
| 2051 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2052 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2053 |
const char* VMA_NULLABLE pName); |
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationMemoryProperties( |
| 2062 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2063 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2064 |
VkMemoryPropertyFlags* VMA_NOT_NULL pFlags); |
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaMapMemory( |
| 2104 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2105 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2106 |
void* VMA_NULLABLE* VMA_NOT_NULL ppData); |
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
VMA_CALL_PRE void VMA_CALL_POST vmaUnmapMemory( |
| 2117 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2118 |
VmaAllocation VMA_NOT_NULL allocation); |
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFlushAllocation( |
| 2142 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2143 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2144 |
VkDeviceSize offset, |
| 2145 |
VkDeviceSize size); |
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaInvalidateAllocation( |
| 2169 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2170 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2171 |
VkDeviceSize offset, |
| 2172 |
VkDeviceSize size); |
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFlushAllocations( |
| 2189 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2190 |
uint32_t allocationCount, |
| 2191 |
const VmaAllocation VMA_NOT_NULL* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) allocations, |
| 2192 |
const VkDeviceSize* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) offsets, |
| 2193 |
const VkDeviceSize* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) sizes); |
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaInvalidateAllocations( |
| 2210 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2211 |
uint32_t allocationCount, |
| 2212 |
const VmaAllocation VMA_NOT_NULL* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) allocations, |
| 2213 |
const VkDeviceSize* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) offsets, |
| 2214 |
const VkDeviceSize* VMA_NULLABLE VMA_LEN_IF_NOT_NULL(allocationCount) sizes); |
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCopyMemoryToAllocation( |
| 2237 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2238 |
const void* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(size) pSrcHostPointer, |
| 2239 |
VmaAllocation VMA_NOT_NULL dstAllocation, |
| 2240 |
VkDeviceSize dstAllocationLocalOffset, |
| 2241 |
VkDeviceSize size); |
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCopyAllocationToMemory( |
| 2265 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2266 |
VmaAllocation VMA_NOT_NULL srcAllocation, |
| 2267 |
VkDeviceSize srcAllocationLocalOffset, |
| 2268 |
void* VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(size) pDstHostPointer, |
| 2269 |
VkDeviceSize size); |
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckCorruption( |
| 2289 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2290 |
uint32_t memoryTypeBits); |
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentation( |
| 2305 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2306 |
const VmaDefragmentationInfo* VMA_NOT_NULL pInfo, |
| 2307 |
VmaDefragmentationContext VMA_NULLABLE* VMA_NOT_NULL pContext); |
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
VMA_CALL_PRE void VMA_CALL_POST vmaEndDefragmentation( |
| 2318 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2319 |
VmaDefragmentationContext VMA_NOT_NULL context, |
| 2320 |
VmaDefragmentationStats* VMA_NULLABLE pStats); |
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentationPass( |
| 2333 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2334 |
VmaDefragmentationContext VMA_NOT_NULL context, |
| 2335 |
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo); |
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaEndDefragmentationPass( |
| 2356 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2357 |
VmaDefragmentationContext VMA_NOT_NULL context, |
| 2358 |
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo); |
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory( |
| 2373 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2374 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2375 |
VkBuffer VMA_NOT_NULL_NON_DISPATCHABLE buffer); |
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory2( |
| 2391 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2392 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2393 |
VkDeviceSize allocationLocalOffset, |
| 2394 |
VkBuffer VMA_NOT_NULL_NON_DISPATCHABLE buffer, |
| 2395 |
const void* VMA_NULLABLE VMA_EXTENDS_VK_STRUCT(VkBindBufferMemoryInfoKHR) pNext); |
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory( |
| 2410 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2411 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2412 |
VkImage VMA_NOT_NULL_NON_DISPATCHABLE image); |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory2( |
| 2428 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2429 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2430 |
VkDeviceSize allocationLocalOffset, |
| 2431 |
VkImage VMA_NOT_NULL_NON_DISPATCHABLE image, |
| 2432 |
const void* VMA_NULLABLE VMA_EXTENDS_VK_STRUCT(VkBindImageMemoryInfoKHR) pNext); |
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer( |
| 2469 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2470 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 2471 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 2472 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer, |
| 2473 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 2474 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBufferWithAlignment( |
| 2483 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2484 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 2485 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 2486 |
VkDeviceSize minAlignment, |
| 2487 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer, |
| 2488 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 2489 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingBuffer( |
| 2513 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2514 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2515 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 2516 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer); |
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingBuffer2( |
| 2541 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2542 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2543 |
VkDeviceSize allocationLocalOffset, |
| 2544 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 2545 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer); |
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyBuffer( |
| 2559 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2560 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE buffer, |
| 2561 |
VmaAllocation VMA_NULLABLE allocation); |
| 2562 |
|
| 2563 |
|
| 2564 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage( |
| 2565 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2566 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 2567 |
const VmaAllocationCreateInfo* VMA_NOT_NULL pAllocationCreateInfo, |
| 2568 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pImage, |
| 2569 |
VmaAllocation VMA_NULLABLE* VMA_NOT_NULL pAllocation, |
| 2570 |
VmaAllocationInfo* VMA_NULLABLE pAllocationInfo); |
| 2571 |
|
| 2572 |
|
| 2573 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingImage( |
| 2574 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2575 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2576 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 2577 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pImage); |
| 2578 |
|
| 2579 |
|
| 2580 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingImage2( |
| 2581 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2582 |
VmaAllocation VMA_NOT_NULL allocation, |
| 2583 |
VkDeviceSize allocationLocalOffset, |
| 2584 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 2585 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pImage); |
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyImage( |
| 2599 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2600 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE image, |
| 2601 |
VmaAllocation VMA_NULLABLE allocation); |
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateVirtualBlock( |
| 2616 |
const VmaVirtualBlockCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 2617 |
VmaVirtualBlock VMA_NULLABLE* VMA_NOT_NULL pVirtualBlock); |
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyVirtualBlock( |
| 2629 |
VmaVirtualBlock VMA_NULLABLE virtualBlock); |
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
VMA_CALL_PRE VkBool32 VMA_CALL_POST vmaIsVirtualBlockEmpty( |
| 2634 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock); |
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetVirtualAllocationInfo( |
| 2639 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2640 |
VmaVirtualAllocation VMA_NOT_NULL_NON_DISPATCHABLE allocation, VmaVirtualAllocationInfo* VMA_NOT_NULL pVirtualAllocInfo); |
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaVirtualAllocate( |
| 2654 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2655 |
const VmaVirtualAllocationCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 2656 |
VmaVirtualAllocation VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pAllocation, |
| 2657 |
VkDeviceSize* VMA_NULLABLE pOffset); |
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
VMA_CALL_PRE void VMA_CALL_POST vmaVirtualFree( |
| 2664 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2665 |
VmaVirtualAllocation VMA_NULLABLE_NON_DISPATCHABLE allocation); |
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
VMA_CALL_PRE void VMA_CALL_POST vmaClearVirtualBlock( |
| 2676 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock); |
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetVirtualAllocationUserData( |
| 2681 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2682 |
VmaVirtualAllocation VMA_NOT_NULL_NON_DISPATCHABLE allocation, |
| 2683 |
void* VMA_NULLABLE pUserData); |
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetVirtualBlockStatistics( |
| 2690 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2691 |
VmaStatistics* VMA_NOT_NULL pStats); |
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculateVirtualBlockStatistics( |
| 2699 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2700 |
VmaDetailedStatistics* VMA_NOT_NULL pStats); |
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
#if VMA_STATS_STRING_ENABLED |
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
VMA_CALL_PRE void VMA_CALL_POST vmaBuildVirtualBlockStatsString( |
| 2718 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2719 |
char* VMA_NULLABLE* VMA_NOT_NULL ppStatsString, |
| 2720 |
VkBool32 detailedMap); |
| 2721 |
|
| 2722 |
|
| 2723 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeVirtualBlockStatsString( |
| 2724 |
VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 2725 |
char* VMA_NULLABLE pStatsString); |
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString( |
| 2733 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2734 |
char* VMA_NULLABLE* VMA_NOT_NULL ppStatsString, |
| 2735 |
VkBool32 detailedMap); |
| 2736 |
|
| 2737 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString( |
| 2738 |
VmaAllocator VMA_NOT_NULL allocator, |
| 2739 |
char* VMA_NULLABLE pStatsString); |
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
#endif |
| 2744 |
|
| 2745 |
#endif |
| 2746 |
|
| 2747 |
#ifdef __cplusplus |
| 2748 |
} |
| 2749 |
#endif |
| 2750 |
|
| 2751 |
#endif |
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
#if defined(__cplusplus) && defined(__INTELLISENSE__) |
| 2763 |
#define VMA_IMPLEMENTATION |
| 2764 |
#endif |
| 2765 |
|
| 2766 |
#ifdef VMA_IMPLEMENTATION |
| 2767 |
#undef VMA_IMPLEMENTATION |
| 2768 |
|
| 2769 |
#include <cstdint> |
| 2770 |
#include <cstdlib> |
| 2771 |
#include <cstring> |
| 2772 |
#include <cinttypes> |
| 2773 |
#include <utility> |
| 2774 |
#include <type_traits> |
| 2775 |
|
| 2776 |
#if !defined(VMA_CPP20) |
| 2777 |
#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L |
| 2778 |
#define VMA_CPP20 1 |
| 2779 |
#else |
| 2780 |
#define VMA_CPP20 0 |
| 2781 |
#endif |
| 2782 |
#endif |
| 2783 |
|
| 2784 |
#ifdef _MSC_VER |
| 2785 |
#include <intrin.h> |
| 2786 |
#endif |
| 2787 |
#if VMA_CPP20 |
| 2788 |
#include <bit> |
| 2789 |
#endif |
| 2790 |
|
| 2791 |
#if VMA_STATS_STRING_ENABLED |
| 2792 |
#include <cstdio> |
| 2793 |
#endif |
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
#ifndef _VMA_CONFIGURATION |
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
#if !defined(VMA_STATIC_VULKAN_FUNCTIONS) && !defined(VK_NO_PROTOTYPES) |
| 2810 |
#define VMA_STATIC_VULKAN_FUNCTIONS 1 |
| 2811 |
#endif |
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
#if !defined(VMA_DYNAMIC_VULKAN_FUNCTIONS) |
| 2824 |
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 |
| 2825 |
#endif |
| 2826 |
|
| 2827 |
#ifndef VMA_USE_STL_SHARED_MUTEX |
| 2828 |
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L |
| 2829 |
#define VMA_USE_STL_SHARED_MUTEX 1 |
| 2830 |
|
| 2831 |
|
| 2832 |
#elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918 && __cplusplus == 199711L && _MSVC_LANG >= 201703L |
| 2833 |
#define VMA_USE_STL_SHARED_MUTEX 1 |
| 2834 |
#else |
| 2835 |
#define VMA_USE_STL_SHARED_MUTEX 0 |
| 2836 |
#endif |
| 2837 |
#endif |
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
#if !defined(VMA_CONFIGURATION_USER_INCLUDES_H) |
| 2861 |
#include <cassert> |
| 2862 |
#include <algorithm> |
| 2863 |
#include <mutex> |
| 2864 |
#else |
| 2865 |
#include VMA_CONFIGURATION_USER_INCLUDES_H |
| 2866 |
#endif |
| 2867 |
|
| 2868 |
#ifndef VMA_NULL |
| 2869 |
|
| 2870 |
#define VMA_NULL nullptr |
| 2871 |
#endif |
| 2872 |
|
| 2873 |
#ifndef VMA_FALLTHROUGH |
| 2874 |
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L |
| 2875 |
#define VMA_FALLTHROUGH [[fallthrough]] |
| 2876 |
#else |
| 2877 |
#define VMA_FALLTHROUGH |
| 2878 |
#endif |
| 2879 |
#endif |
| 2880 |
|
| 2881 |
|
| 2882 |
#ifndef VMA_ASSERT |
| 2883 |
#ifdef NDEBUG |
| 2884 |
#define VMA_ASSERT(expr) |
| 2885 |
#else |
| 2886 |
#define VMA_ASSERT(expr) assert(expr) |
| 2887 |
#endif |
| 2888 |
#endif |
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
#ifndef VMA_HEAVY_ASSERT |
| 2893 |
#ifdef NDEBUG |
| 2894 |
#define VMA_HEAVY_ASSERT(expr) |
| 2895 |
#else |
| 2896 |
#define VMA_HEAVY_ASSERT(expr) |
| 2897 |
#endif |
| 2898 |
#endif |
| 2899 |
|
| 2900 |
|
| 2901 |
#ifndef VMA_ASSERT_LEAK |
| 2902 |
#define VMA_ASSERT_LEAK(expr) VMA_ASSERT(expr) |
| 2903 |
#endif |
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 16) |
| 2911 |
#include <cstdlib> |
| 2912 |
static void* vma_aligned_alloc(size_t alignment, size_t size) |
| 2913 |
{ |
| 2914 |
|
| 2915 |
if(alignment < sizeof(void*)) |
| 2916 |
{ |
| 2917 |
alignment = sizeof(void*); |
| 2918 |
} |
| 2919 |
|
| 2920 |
return memalign(alignment, size); |
| 2921 |
} |
| 2922 |
#elif defined(__APPLE__) || defined(__ANDROID__) || (defined(__linux__) && defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)) |
| 2923 |
#include <cstdlib> |
| 2924 |
|
| 2925 |
#if defined(__APPLE__) |
| 2926 |
#include <AvailabilityMacros.h> |
| 2927 |
#endif |
| 2928 |
|
| 2929 |
static void* vma_aligned_alloc(size_t alignment, size_t size) |
| 2930 |
{ |
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
if(alignment < sizeof(void*)) |
| 2948 |
{ |
| 2949 |
alignment = sizeof(void*); |
| 2950 |
} |
| 2951 |
|
| 2952 |
void *pointer; |
| 2953 |
if(posix_memalign(&pointer, alignment, size) == 0) |
| 2954 |
return pointer; |
| 2955 |
return VMA_NULL; |
| 2956 |
} |
| 2957 |
#elif defined(_WIN32) |
| 2958 |
static void* vma_aligned_alloc(size_t alignment, size_t size) |
| 2959 |
{ |
| 2960 |
return _aligned_malloc(size, alignment); |
| 2961 |
} |
| 2962 |
#elif __cplusplus >= 201703L || _MSVC_LANG >= 201703L |
| 2963 |
static void* vma_aligned_alloc(size_t alignment, size_t size) |
| 2964 |
{ |
| 2965 |
return aligned_alloc(alignment, size); |
| 2966 |
} |
| 2967 |
#else |
| 2968 |
static void* vma_aligned_alloc(size_t alignment, size_t size) |
| 2969 |
{ |
| 2970 |
VMA_ASSERT(0 && "Could not implement aligned_alloc automatically. Please enable C++17 or later in your compiler or provide custom implementation of macro VMA_SYSTEM_ALIGNED_MALLOC (and VMA_SYSTEM_ALIGNED_FREE if needed) using the API of your system."); |
| 2971 |
return VMA_NULL; |
| 2972 |
} |
| 2973 |
#endif |
| 2974 |
|
| 2975 |
#if defined(_WIN32) |
| 2976 |
static void vma_aligned_free(void* ptr) |
| 2977 |
{ |
| 2978 |
_aligned_free(ptr); |
| 2979 |
} |
| 2980 |
#else |
| 2981 |
static void vma_aligned_free(void* VMA_NULLABLE ptr) |
| 2982 |
{ |
| 2983 |
free(ptr); |
| 2984 |
} |
| 2985 |
#endif |
| 2986 |
|
| 2987 |
#ifndef VMA_ALIGN_OF |
| 2988 |
#define VMA_ALIGN_OF(type) (alignof(type)) |
| 2989 |
#endif |
| 2990 |
|
| 2991 |
#ifndef VMA_SYSTEM_ALIGNED_MALLOC |
| 2992 |
#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) vma_aligned_alloc((alignment), (size)) |
| 2993 |
#endif |
| 2994 |
|
| 2995 |
#ifndef VMA_SYSTEM_ALIGNED_FREE |
| 2996 |
|
| 2997 |
#if defined(VMA_SYSTEM_FREE) |
| 2998 |
#define VMA_SYSTEM_ALIGNED_FREE(ptr) VMA_SYSTEM_FREE(ptr) |
| 2999 |
#else |
| 3000 |
#define VMA_SYSTEM_ALIGNED_FREE(ptr) vma_aligned_free(ptr) |
| 3001 |
#endif |
| 3002 |
#endif |
| 3003 |
|
| 3004 |
#ifndef VMA_COUNT_BITS_SET |
| 3005 |
|
| 3006 |
#define VMA_COUNT_BITS_SET(v) VmaCountBitsSet(v) |
| 3007 |
#endif |
| 3008 |
|
| 3009 |
#ifndef VMA_BITSCAN_LSB |
| 3010 |
|
| 3011 |
#define VMA_BITSCAN_LSB(mask) VmaBitScanLSB(mask) |
| 3012 |
#endif |
| 3013 |
|
| 3014 |
#ifndef VMA_BITSCAN_MSB |
| 3015 |
|
| 3016 |
#define VMA_BITSCAN_MSB(mask) VmaBitScanMSB(mask) |
| 3017 |
#endif |
| 3018 |
|
| 3019 |
#ifndef VMA_MIN |
| 3020 |
#define VMA_MIN(v1, v2) ((std::min)((v1), (v2))) |
| 3021 |
#endif |
| 3022 |
|
| 3023 |
#ifndef VMA_MAX |
| 3024 |
#define VMA_MAX(v1, v2) ((std::max)((v1), (v2))) |
| 3025 |
#endif |
| 3026 |
|
| 3027 |
#ifndef VMA_SORT |
| 3028 |
#define VMA_SORT(beg, end, cmp) std::sort(beg, end, cmp) |
| 3029 |
#endif |
| 3030 |
|
| 3031 |
#ifndef VMA_DEBUG_LOG_FORMAT |
| 3032 |
#define VMA_DEBUG_LOG_FORMAT(format, ...) |
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
#endif |
| 3040 |
|
| 3041 |
#ifndef VMA_DEBUG_LOG |
| 3042 |
#define VMA_DEBUG_LOG(str) VMA_DEBUG_LOG_FORMAT("%s", (str)) |
| 3043 |
#endif |
| 3044 |
|
| 3045 |
#ifndef VMA_LEAK_LOG_FORMAT |
| 3046 |
#define VMA_LEAK_LOG_FORMAT(format, ...) VMA_DEBUG_LOG_FORMAT(format, __VA_ARGS__) |
| 3047 |
#endif |
| 3048 |
|
| 3049 |
#ifndef VMA_CLASS_NO_COPY |
| 3050 |
#define VMA_CLASS_NO_COPY(className) \ |
| 3051 |
private: \ |
| 3052 |
className(const className&) = delete; \ |
| 3053 |
className& operator=(const className&) = delete; |
| 3054 |
#endif |
| 3055 |
#ifndef VMA_CLASS_NO_COPY_NO_MOVE |
| 3056 |
#define VMA_CLASS_NO_COPY_NO_MOVE(className) \ |
| 3057 |
private: \ |
| 3058 |
className(const className&) = delete; \ |
| 3059 |
className(className&&) = delete; \ |
| 3060 |
className& operator=(const className&) = delete; \ |
| 3061 |
className& operator=(className&&) = delete; |
| 3062 |
#endif |
| 3063 |
|
| 3064 |
|
| 3065 |
#if VMA_STATS_STRING_ENABLED |
| 3066 |
static inline void VmaUint32ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint32_t num) |
| 3067 |
{ |
| 3068 |
snprintf(outStr, strLen, "%" PRIu32, num); |
| 3069 |
} |
| 3070 |
static inline void VmaUint64ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint64_t num) |
| 3071 |
{ |
| 3072 |
snprintf(outStr, strLen, "%" PRIu64, num); |
| 3073 |
} |
| 3074 |
static inline void VmaPtrToStr(char* VMA_NOT_NULL outStr, size_t strLen, const void* ptr) |
| 3075 |
{ |
| 3076 |
snprintf(outStr, strLen, "%p", ptr); |
| 3077 |
} |
| 3078 |
#endif |
| 3079 |
|
| 3080 |
#ifndef VMA_MUTEX |
| 3081 |
class VmaMutex |
| 3082 |
{ |
| 3083 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaMutex) |
| 3084 |
public: |
| 3085 |
VmaMutex() { } |
| 3086 |
void Lock() { m_Mutex.lock(); } |
| 3087 |
void Unlock() { m_Mutex.unlock(); } |
| 3088 |
bool TryLock() { return m_Mutex.try_lock(); } |
| 3089 |
private: |
| 3090 |
std::mutex m_Mutex; |
| 3091 |
}; |
| 3092 |
#define VMA_MUTEX VmaMutex |
| 3093 |
#endif |
| 3094 |
|
| 3095 |
|
| 3096 |
#ifndef VMA_RW_MUTEX |
| 3097 |
#if VMA_USE_STL_SHARED_MUTEX |
| 3098 |
|
| 3099 |
#include <shared_mutex> |
| 3100 |
class VmaRWMutex |
| 3101 |
{ |
| 3102 |
public: |
| 3103 |
void LockRead() { m_Mutex.lock_shared(); } |
| 3104 |
void UnlockRead() { m_Mutex.unlock_shared(); } |
| 3105 |
bool TryLockRead() { return m_Mutex.try_lock_shared(); } |
| 3106 |
void LockWrite() { m_Mutex.lock(); } |
| 3107 |
void UnlockWrite() { m_Mutex.unlock(); } |
| 3108 |
bool TryLockWrite() { return m_Mutex.try_lock(); } |
| 3109 |
private: |
| 3110 |
std::shared_mutex m_Mutex; |
| 3111 |
}; |
| 3112 |
#define VMA_RW_MUTEX VmaRWMutex |
| 3113 |
#elif defined(_WIN32) && defined(WINVER) && WINVER >= 0x0600 |
| 3114 |
|
| 3115 |
|
| 3116 |
class VmaRWMutex |
| 3117 |
{ |
| 3118 |
public: |
| 3119 |
VmaRWMutex() { InitializeSRWLock(&m_Lock); } |
| 3120 |
void LockRead() { AcquireSRWLockShared(&m_Lock); } |
| 3121 |
void UnlockRead() { ReleaseSRWLockShared(&m_Lock); } |
| 3122 |
bool TryLockRead() { return TryAcquireSRWLockShared(&m_Lock) != FALSE; } |
| 3123 |
void LockWrite() { AcquireSRWLockExclusive(&m_Lock); } |
| 3124 |
void UnlockWrite() { ReleaseSRWLockExclusive(&m_Lock); } |
| 3125 |
bool TryLockWrite() { return TryAcquireSRWLockExclusive(&m_Lock) != FALSE; } |
| 3126 |
private: |
| 3127 |
SRWLOCK m_Lock; |
| 3128 |
}; |
| 3129 |
#define VMA_RW_MUTEX VmaRWMutex |
| 3130 |
#else |
| 3131 |
|
| 3132 |
class VmaRWMutex |
| 3133 |
{ |
| 3134 |
public: |
| 3135 |
void LockRead() { m_Mutex.Lock(); } |
| 3136 |
void UnlockRead() { m_Mutex.Unlock(); } |
| 3137 |
bool TryLockRead() { return m_Mutex.TryLock(); } |
| 3138 |
void LockWrite() { m_Mutex.Lock(); } |
| 3139 |
void UnlockWrite() { m_Mutex.Unlock(); } |
| 3140 |
bool TryLockWrite() { return m_Mutex.TryLock(); } |
| 3141 |
private: |
| 3142 |
VMA_MUTEX m_Mutex; |
| 3143 |
}; |
| 3144 |
#define VMA_RW_MUTEX VmaRWMutex |
| 3145 |
#endif |
| 3146 |
#endif |
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
|
| 3151 |
#ifndef VMA_ATOMIC_UINT32 |
| 3152 |
#include <atomic> |
| 3153 |
#define VMA_ATOMIC_UINT32 std::atomic<uint32_t> |
| 3154 |
#endif |
| 3155 |
|
| 3156 |
#ifndef VMA_ATOMIC_UINT64 |
| 3157 |
#include <atomic> |
| 3158 |
#define VMA_ATOMIC_UINT64 std::atomic<uint64_t> |
| 3159 |
#endif |
| 3160 |
|
| 3161 |
#ifndef VMA_DEBUG_ALWAYS_DEDICATED_MEMORY |
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
#define VMA_DEBUG_ALWAYS_DEDICATED_MEMORY (0) |
| 3167 |
#endif |
| 3168 |
|
| 3169 |
#ifndef VMA_MIN_ALIGNMENT |
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
#ifdef VMA_DEBUG_ALIGNMENT |
| 3175 |
#define VMA_MIN_ALIGNMENT VMA_DEBUG_ALIGNMENT |
| 3176 |
#else |
| 3177 |
#define VMA_MIN_ALIGNMENT (1) |
| 3178 |
#endif |
| 3179 |
#endif |
| 3180 |
|
| 3181 |
#ifndef VMA_DEBUG_MARGIN |
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
#define VMA_DEBUG_MARGIN (0) |
| 3187 |
#endif |
| 3188 |
|
| 3189 |
#ifndef VMA_DEBUG_INITIALIZE_ALLOCATIONS |
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
#define VMA_DEBUG_INITIALIZE_ALLOCATIONS (0) |
| 3195 |
#endif |
| 3196 |
|
| 3197 |
#ifndef VMA_DEBUG_DETECT_CORRUPTION |
| 3198 |
|
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
#define VMA_DEBUG_DETECT_CORRUPTION (0) |
| 3204 |
#endif |
| 3205 |
|
| 3206 |
#ifndef VMA_DEBUG_GLOBAL_MUTEX |
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
#define VMA_DEBUG_GLOBAL_MUTEX (0) |
| 3212 |
#endif |
| 3213 |
|
| 3214 |
#ifndef VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY |
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
#define VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY (1) |
| 3220 |
#endif |
| 3221 |
|
| 3222 |
#ifndef VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT |
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
#define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (0) |
| 3228 |
#endif |
| 3229 |
|
| 3230 |
#ifndef VMA_SMALL_HEAP_MAX_SIZE |
| 3231 |
|
| 3232 |
#define VMA_SMALL_HEAP_MAX_SIZE (1024ull * 1024 * 1024) |
| 3233 |
#endif |
| 3234 |
|
| 3235 |
#ifndef VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE |
| 3236 |
|
| 3237 |
#define VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE (256ull * 1024 * 1024) |
| 3238 |
#endif |
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
#ifndef VMA_MAPPING_HYSTERESIS_ENABLED |
| 3248 |
#define VMA_MAPPING_HYSTERESIS_ENABLED 1 |
| 3249 |
#endif |
| 3250 |
|
| 3251 |
#define VMA_VALIDATE(cond) do { if(!(cond)) { \ |
| 3252 |
VMA_ASSERT(0 && "Validation failed: " #cond); \ |
| 3253 |
return false; \ |
| 3254 |
} } while(false) |
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
#endif |
| 3260 |
|
| 3261 |
|
| 3262 |
static const uint8_t VMA_ALLOCATION_FILL_PATTERN_CREATED = 0xDC; |
| 3263 |
static const uint8_t VMA_ALLOCATION_FILL_PATTERN_DESTROYED = 0xEF; |
| 3264 |
|
| 3265 |
static const uint32_t VMA_CORRUPTION_DETECTION_MAGIC_VALUE = 0x7F84E666; |
| 3266 |
|
| 3267 |
|
| 3268 |
static const uint32_t VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY = 0x00000040; |
| 3269 |
static const uint32_t VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY = 0x00000080; |
| 3270 |
static const uint32_t VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_COPY = 0x00020000; |
| 3271 |
static const uint32_t VK_IMAGE_CREATE_DISJOINT_BIT_COPY = 0x00000200; |
| 3272 |
static const int32_t VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT_COPY = 1000158000; |
| 3273 |
static const uint32_t VMA_ALLOCATION_INTERNAL_STRATEGY_MIN_OFFSET = 0x10000000u; |
| 3274 |
static const uint32_t VMA_ALLOCATION_TRY_COUNT = 32; |
| 3275 |
static const uint32_t VMA_VENDOR_ID_AMD = 4098; |
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
#define VK_ERROR_UNKNOWN_COPY ((VkResult)-13) |
| 3281 |
|
| 3282 |
|
| 3283 |
#if VMA_STATS_STRING_ENABLED |
| 3284 |
|
| 3285 |
static const char* VMA_SUBALLOCATION_TYPE_NAMES[] = |
| 3286 |
{ |
| 3287 |
"FREE", |
| 3288 |
"UNKNOWN", |
| 3289 |
"BUFFER", |
| 3290 |
"IMAGE_UNKNOWN", |
| 3291 |
"IMAGE_LINEAR", |
| 3292 |
"IMAGE_OPTIMAL", |
| 3293 |
}; |
| 3294 |
#endif |
| 3295 |
|
| 3296 |
static VkAllocationCallbacks VmaEmptyAllocationCallbacks = |
| 3297 |
{ VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL }; |
| 3298 |
|
| 3299 |
|
| 3300 |
#ifndef _VMA_ENUM_DECLARATIONS |
| 3301 |
|
| 3302 |
enum VmaSuballocationType |
| 3303 |
{ |
| 3304 |
VMA_SUBALLOCATION_TYPE_FREE = 0, |
| 3305 |
VMA_SUBALLOCATION_TYPE_UNKNOWN = 1, |
| 3306 |
VMA_SUBALLOCATION_TYPE_BUFFER = 2, |
| 3307 |
VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN = 3, |
| 3308 |
VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR = 4, |
| 3309 |
VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL = 5, |
| 3310 |
VMA_SUBALLOCATION_TYPE_MAX_ENUM = 0x7FFFFFFF |
| 3311 |
}; |
| 3312 |
|
| 3313 |
enum VMA_CACHE_OPERATION |
| 3314 |
{ |
| 3315 |
VMA_CACHE_FLUSH, |
| 3316 |
VMA_CACHE_INVALIDATE |
| 3317 |
}; |
| 3318 |
|
| 3319 |
enum class VmaAllocationRequestType |
| 3320 |
{ |
| 3321 |
Normal, |
| 3322 |
TLSF, |
| 3323 |
|
| 3324 |
UpperAddress, |
| 3325 |
EndOf1st, |
| 3326 |
EndOf2nd, |
| 3327 |
}; |
| 3328 |
|
| 3329 |
#endif |
| 3330 |
|
| 3331 |
#ifndef _VMA_FORWARD_DECLARATIONS |
| 3332 |
|
| 3333 |
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VmaAllocHandle); |
| 3334 |
|
| 3335 |
struct VmaMutexLock; |
| 3336 |
struct VmaMutexLockRead; |
| 3337 |
struct VmaMutexLockWrite; |
| 3338 |
|
| 3339 |
template<typename T> |
| 3340 |
struct AtomicTransactionalIncrement; |
| 3341 |
|
| 3342 |
template<typename T> |
| 3343 |
struct VmaStlAllocator; |
| 3344 |
|
| 3345 |
template<typename T, typename AllocatorT> |
| 3346 |
class VmaVector; |
| 3347 |
|
| 3348 |
template<typename T, typename AllocatorT, size_t N> |
| 3349 |
class VmaSmallVector; |
| 3350 |
|
| 3351 |
template<typename T> |
| 3352 |
class VmaPoolAllocator; |
| 3353 |
|
| 3354 |
template<typename T> |
| 3355 |
struct VmaListItem; |
| 3356 |
|
| 3357 |
template<typename T> |
| 3358 |
class VmaRawList; |
| 3359 |
|
| 3360 |
template<typename T, typename AllocatorT> |
| 3361 |
class VmaList; |
| 3362 |
|
| 3363 |
template<typename ItemTypeTraits> |
| 3364 |
class VmaIntrusiveLinkedList; |
| 3365 |
|
| 3366 |
#if VMA_STATS_STRING_ENABLED |
| 3367 |
class VmaStringBuilder; |
| 3368 |
class VmaJsonWriter; |
| 3369 |
#endif |
| 3370 |
|
| 3371 |
class VmaDeviceMemoryBlock; |
| 3372 |
|
| 3373 |
struct VmaDedicatedAllocationListItemTraits; |
| 3374 |
class VmaDedicatedAllocationList; |
| 3375 |
|
| 3376 |
struct VmaSuballocation; |
| 3377 |
struct VmaSuballocationOffsetLess; |
| 3378 |
struct VmaSuballocationOffsetGreater; |
| 3379 |
struct VmaSuballocationItemSizeLess; |
| 3380 |
|
| 3381 |
typedef VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation>> VmaSuballocationList; |
| 3382 |
|
| 3383 |
struct VmaAllocationRequest; |
| 3384 |
|
| 3385 |
class VmaBlockMetadata; |
| 3386 |
class VmaBlockMetadata_Linear; |
| 3387 |
class VmaBlockMetadata_TLSF; |
| 3388 |
|
| 3389 |
class VmaBlockVector; |
| 3390 |
|
| 3391 |
struct VmaPoolListItemTraits; |
| 3392 |
|
| 3393 |
struct VmaCurrentBudgetData; |
| 3394 |
|
| 3395 |
class VmaAllocationObjectAllocator; |
| 3396 |
|
| 3397 |
#endif |
| 3398 |
|
| 3399 |
|
| 3400 |
#ifndef _VMA_FUNCTIONS |
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
static inline uint32_t VmaCountBitsSet(uint32_t v) |
| 3416 |
{ |
| 3417 |
#if VMA_CPP20 |
| 3418 |
return std::popcount(v); |
| 3419 |
#else |
| 3420 |
uint32_t c = v - ((v >> 1) & 0x55555555); |
| 3421 |
c = ((c >> 2) & 0x33333333) + (c & 0x33333333); |
| 3422 |
c = ((c >> 4) + c) & 0x0F0F0F0F; |
| 3423 |
c = ((c >> 8) + c) & 0x00FF00FF; |
| 3424 |
c = ((c >> 16) + c) & 0x0000FFFF; |
| 3425 |
return c; |
| 3426 |
#endif |
| 3427 |
} |
| 3428 |
|
| 3429 |
static inline uint8_t VmaBitScanLSB(uint64_t mask) |
| 3430 |
{ |
| 3431 |
#if defined(_MSC_VER) && defined(_WIN64) |
| 3432 |
unsigned long pos; |
| 3433 |
if (_BitScanForward64(&pos, mask)) |
| 3434 |
return static_cast<uint8_t>(pos); |
| 3435 |
return UINT8_MAX; |
| 3436 |
#elif VMA_CPP20 |
| 3437 |
if(mask) |
| 3438 |
return static_cast<uint8_t>(std::countr_zero(mask)); |
| 3439 |
return UINT8_MAX; |
| 3440 |
#elif defined __GNUC__ || defined __clang__ |
| 3441 |
return static_cast<uint8_t>(__builtin_ffsll(mask)) - 1U; |
| 3442 |
#else |
| 3443 |
uint8_t pos = 0; |
| 3444 |
uint64_t bit = 1; |
| 3445 |
do |
| 3446 |
{ |
| 3447 |
if (mask & bit) |
| 3448 |
return pos; |
| 3449 |
bit <<= 1; |
| 3450 |
} while (pos++ < 63); |
| 3451 |
return UINT8_MAX; |
| 3452 |
#endif |
| 3453 |
} |
| 3454 |
|
| 3455 |
static inline uint8_t VmaBitScanLSB(uint32_t mask) |
| 3456 |
{ |
| 3457 |
#ifdef _MSC_VER |
| 3458 |
unsigned long pos; |
| 3459 |
if (_BitScanForward(&pos, mask)) |
| 3460 |
return static_cast<uint8_t>(pos); |
| 3461 |
return UINT8_MAX; |
| 3462 |
#elif VMA_CPP20 |
| 3463 |
if(mask) |
| 3464 |
return static_cast<uint8_t>(std::countr_zero(mask)); |
| 3465 |
return UINT8_MAX; |
| 3466 |
#elif defined __GNUC__ || defined __clang__ |
| 3467 |
return static_cast<uint8_t>(__builtin_ffs(mask)) - 1U; |
| 3468 |
#else |
| 3469 |
uint8_t pos = 0; |
| 3470 |
uint32_t bit = 1; |
| 3471 |
do |
| 3472 |
{ |
| 3473 |
if (mask & bit) |
| 3474 |
return pos; |
| 3475 |
bit <<= 1; |
| 3476 |
} while (pos++ < 31); |
| 3477 |
return UINT8_MAX; |
| 3478 |
#endif |
| 3479 |
} |
| 3480 |
|
| 3481 |
static inline uint8_t VmaBitScanMSB(uint64_t mask) |
| 3482 |
{ |
| 3483 |
#if defined(_MSC_VER) && defined(_WIN64) |
| 3484 |
unsigned long pos; |
| 3485 |
if (_BitScanReverse64(&pos, mask)) |
| 3486 |
return static_cast<uint8_t>(pos); |
| 3487 |
#elif VMA_CPP20 |
| 3488 |
if(mask) |
| 3489 |
return 63 - static_cast<uint8_t>(std::countl_zero(mask)); |
| 3490 |
#elif defined __GNUC__ || defined __clang__ |
| 3491 |
if (mask) |
| 3492 |
return 63 - static_cast<uint8_t>(__builtin_clzll(mask)); |
| 3493 |
#else |
| 3494 |
uint8_t pos = 63; |
| 3495 |
uint64_t bit = 1ULL << 63; |
| 3496 |
do |
| 3497 |
{ |
| 3498 |
if (mask & bit) |
| 3499 |
return pos; |
| 3500 |
bit >>= 1; |
| 3501 |
} while (pos-- > 0); |
| 3502 |
#endif |
| 3503 |
return UINT8_MAX; |
| 3504 |
} |
| 3505 |
|
| 3506 |
static inline uint8_t VmaBitScanMSB(uint32_t mask) |
| 3507 |
{ |
| 3508 |
#ifdef _MSC_VER |
| 3509 |
unsigned long pos; |
| 3510 |
if (_BitScanReverse(&pos, mask)) |
| 3511 |
return static_cast<uint8_t>(pos); |
| 3512 |
#elif VMA_CPP20 |
| 3513 |
if(mask) |
| 3514 |
return 31 - static_cast<uint8_t>(std::countl_zero(mask)); |
| 3515 |
#elif defined __GNUC__ || defined __clang__ |
| 3516 |
if (mask) |
| 3517 |
return 31 - static_cast<uint8_t>(__builtin_clz(mask)); |
| 3518 |
#else |
| 3519 |
uint8_t pos = 31; |
| 3520 |
uint32_t bit = 1UL << 31; |
| 3521 |
do |
| 3522 |
{ |
| 3523 |
if (mask & bit) |
| 3524 |
return pos; |
| 3525 |
bit >>= 1; |
| 3526 |
} while (pos-- > 0); |
| 3527 |
#endif |
| 3528 |
return UINT8_MAX; |
| 3529 |
} |
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
template <typename T> |
| 3537 |
inline bool VmaIsPow2(T x) |
| 3538 |
{ |
| 3539 |
return (x & (x - 1)) == 0; |
| 3540 |
} |
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
template <typename T> |
| 3545 |
static inline T VmaAlignUp(T val, T alignment) |
| 3546 |
{ |
| 3547 |
VMA_HEAVY_ASSERT(VmaIsPow2(alignment)); |
| 3548 |
return (val + alignment - 1) & ~(alignment - 1); |
| 3549 |
} |
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
template <typename T> |
| 3554 |
static inline T VmaAlignDown(T val, T alignment) |
| 3555 |
{ |
| 3556 |
VMA_HEAVY_ASSERT(VmaIsPow2(alignment)); |
| 3557 |
return val & ~(alignment - 1); |
| 3558 |
} |
| 3559 |
|
| 3560 |
|
| 3561 |
template <typename T> |
| 3562 |
static inline T VmaRoundDiv(T x, T y) |
| 3563 |
{ |
| 3564 |
return (x + (y / (T)2)) / y; |
| 3565 |
} |
| 3566 |
|
| 3567 |
|
| 3568 |
template <typename T> |
| 3569 |
static inline T VmaDivideRoundingUp(T x, T y) |
| 3570 |
{ |
| 3571 |
return (x + y - (T)1) / y; |
| 3572 |
} |
| 3573 |
|
| 3574 |
|
| 3575 |
static inline uint32_t VmaNextPow2(uint32_t v) |
| 3576 |
{ |
| 3577 |
v--; |
| 3578 |
v |= v >> 1; |
| 3579 |
v |= v >> 2; |
| 3580 |
v |= v >> 4; |
| 3581 |
v |= v >> 8; |
| 3582 |
v |= v >> 16; |
| 3583 |
v++; |
| 3584 |
return v; |
| 3585 |
} |
| 3586 |
|
| 3587 |
static inline uint64_t VmaNextPow2(uint64_t v) |
| 3588 |
{ |
| 3589 |
v--; |
| 3590 |
v |= v >> 1; |
| 3591 |
v |= v >> 2; |
| 3592 |
v |= v >> 4; |
| 3593 |
v |= v >> 8; |
| 3594 |
v |= v >> 16; |
| 3595 |
v |= v >> 32; |
| 3596 |
v++; |
| 3597 |
return v; |
| 3598 |
} |
| 3599 |
|
| 3600 |
|
| 3601 |
static inline uint32_t VmaPrevPow2(uint32_t v) |
| 3602 |
{ |
| 3603 |
v |= v >> 1; |
| 3604 |
v |= v >> 2; |
| 3605 |
v |= v >> 4; |
| 3606 |
v |= v >> 8; |
| 3607 |
v |= v >> 16; |
| 3608 |
v = v ^ (v >> 1); |
| 3609 |
return v; |
| 3610 |
} |
| 3611 |
|
| 3612 |
static inline uint64_t VmaPrevPow2(uint64_t v) |
| 3613 |
{ |
| 3614 |
v |= v >> 1; |
| 3615 |
v |= v >> 2; |
| 3616 |
v |= v >> 4; |
| 3617 |
v |= v >> 8; |
| 3618 |
v |= v >> 16; |
| 3619 |
v |= v >> 32; |
| 3620 |
v = v ^ (v >> 1); |
| 3621 |
return v; |
| 3622 |
} |
| 3623 |
|
| 3624 |
static inline bool VmaStrIsEmpty(const char* pStr) |
| 3625 |
{ |
| 3626 |
return pStr == VMA_NULL || *pStr == '\0'; |
| 3627 |
} |
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
|
| 3635 |
|
| 3636 |
static inline bool VmaBlocksOnSamePage( |
| 3637 |
VkDeviceSize resourceAOffset, |
| 3638 |
VkDeviceSize resourceASize, |
| 3639 |
VkDeviceSize resourceBOffset, |
| 3640 |
VkDeviceSize pageSize) |
| 3641 |
{ |
| 3642 |
VMA_ASSERT(resourceAOffset + resourceASize <= resourceBOffset && resourceASize > 0 && pageSize > 0); |
| 3643 |
VkDeviceSize resourceAEnd = resourceAOffset + resourceASize - 1; |
| 3644 |
VkDeviceSize resourceAEndPage = resourceAEnd & ~(pageSize - 1); |
| 3645 |
VkDeviceSize resourceBStart = resourceBOffset; |
| 3646 |
VkDeviceSize resourceBStartPage = resourceBStart & ~(pageSize - 1); |
| 3647 |
return resourceAEndPage == resourceBStartPage; |
| 3648 |
} |
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
static inline bool VmaIsBufferImageGranularityConflict( |
| 3657 |
VmaSuballocationType suballocType1, |
| 3658 |
VmaSuballocationType suballocType2) |
| 3659 |
{ |
| 3660 |
if (suballocType1 > suballocType2) |
| 3661 |
{ |
| 3662 |
std::swap(suballocType1, suballocType2); |
| 3663 |
} |
| 3664 |
|
| 3665 |
switch (suballocType1) |
| 3666 |
{ |
| 3667 |
case VMA_SUBALLOCATION_TYPE_FREE: |
| 3668 |
return false; |
| 3669 |
case VMA_SUBALLOCATION_TYPE_UNKNOWN: |
| 3670 |
return true; |
| 3671 |
case VMA_SUBALLOCATION_TYPE_BUFFER: |
| 3672 |
return |
| 3673 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN || |
| 3674 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL; |
| 3675 |
case VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN: |
| 3676 |
return |
| 3677 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN || |
| 3678 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR || |
| 3679 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL; |
| 3680 |
case VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR: |
| 3681 |
return |
| 3682 |
suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL; |
| 3683 |
case VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL: |
| 3684 |
return false; |
| 3685 |
default: |
| 3686 |
VMA_ASSERT(0); |
| 3687 |
return true; |
| 3688 |
} |
| 3689 |
} |
| 3690 |
|
| 3691 |
static void VmaWriteMagicValue(void* pData, VkDeviceSize offset) |
| 3692 |
{ |
| 3693 |
#if VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_DETECT_CORRUPTION |
| 3694 |
uint32_t* pDst = (uint32_t*)((char*)pData + offset); |
| 3695 |
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t); |
| 3696 |
for (size_t i = 0; i < numberCount; ++i, ++pDst) |
| 3697 |
{ |
| 3698 |
*pDst = VMA_CORRUPTION_DETECTION_MAGIC_VALUE; |
| 3699 |
} |
| 3700 |
#else |
| 3701 |
|
| 3702 |
#endif |
| 3703 |
} |
| 3704 |
|
| 3705 |
static bool VmaValidateMagicValue(const void* pData, VkDeviceSize offset) |
| 3706 |
{ |
| 3707 |
#if VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_DETECT_CORRUPTION |
| 3708 |
const uint32_t* pSrc = (const uint32_t*)((const char*)pData + offset); |
| 3709 |
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t); |
| 3710 |
for (size_t i = 0; i < numberCount; ++i, ++pSrc) |
| 3711 |
{ |
| 3712 |
if (*pSrc != VMA_CORRUPTION_DETECTION_MAGIC_VALUE) |
| 3713 |
{ |
| 3714 |
return false; |
| 3715 |
} |
| 3716 |
} |
| 3717 |
#endif |
| 3718 |
return true; |
| 3719 |
} |
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
static void VmaFillGpuDefragmentationBufferCreateInfo(VkBufferCreateInfo& outBufCreateInfo) |
| 3726 |
{ |
| 3727 |
memset(&outBufCreateInfo, 0, sizeof(outBufCreateInfo)); |
| 3728 |
outBufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3729 |
outBufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3730 |
outBufCreateInfo.size = (VkDeviceSize)VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE; |
| 3731 |
} |
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
template <typename CmpLess, typename IterT, typename KeyT> |
| 3744 |
static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT& key, const CmpLess& cmp) |
| 3745 |
{ |
| 3746 |
size_t down = 0, up = size_t(end - beg); |
| 3747 |
while (down < up) |
| 3748 |
{ |
| 3749 |
const size_t mid = down + (up - down) / 2; |
| 3750 |
if (cmp(*(beg + mid), key)) |
| 3751 |
{ |
| 3752 |
down = mid + 1; |
| 3753 |
} |
| 3754 |
else |
| 3755 |
{ |
| 3756 |
up = mid; |
| 3757 |
} |
| 3758 |
} |
| 3759 |
return beg + down; |
| 3760 |
} |
| 3761 |
|
| 3762 |
template<typename CmpLess, typename IterT, typename KeyT> |
| 3763 |
IterT VmaBinaryFindSorted(const IterT& beg, const IterT& end, const KeyT& value, const CmpLess& cmp) |
| 3764 |
{ |
| 3765 |
IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>( |
| 3766 |
beg, end, value, cmp); |
| 3767 |
if (it == end || |
| 3768 |
(!cmp(*it, value) && !cmp(value, *it))) |
| 3769 |
{ |
| 3770 |
return it; |
| 3771 |
} |
| 3772 |
return end; |
| 3773 |
} |
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
template<typename T> |
| 3781 |
static bool VmaValidatePointerArray(uint32_t count, const T* arr) |
| 3782 |
{ |
| 3783 |
for (uint32_t i = 0; i < count; ++i) |
| 3784 |
{ |
| 3785 |
const T iPtr = arr[i]; |
| 3786 |
if (iPtr == VMA_NULL) |
| 3787 |
{ |
| 3788 |
return false; |
| 3789 |
} |
| 3790 |
for (uint32_t j = i + 1; j < count; ++j) |
| 3791 |
{ |
| 3792 |
if (iPtr == arr[j]) |
| 3793 |
{ |
| 3794 |
return false; |
| 3795 |
} |
| 3796 |
} |
| 3797 |
} |
| 3798 |
return true; |
| 3799 |
} |
| 3800 |
|
| 3801 |
template<typename MainT, typename NewT> |
| 3802 |
static inline void VmaPnextChainPushFront(MainT* mainStruct, NewT* newStruct) |
| 3803 |
{ |
| 3804 |
newStruct->pNext = mainStruct->pNext; |
| 3805 |
mainStruct->pNext = newStruct; |
| 3806 |
} |
| 3807 |
|
| 3808 |
|
| 3809 |
template<typename FindT, typename MainT> |
| 3810 |
static inline const FindT* VmaPnextChainFind(const MainT* mainStruct, VkStructureType sType) |
| 3811 |
{ |
| 3812 |
for(const VkBaseInStructure* s = (const VkBaseInStructure*)mainStruct->pNext; |
| 3813 |
s != VMA_NULL; s = s->pNext) |
| 3814 |
{ |
| 3815 |
if(s->sType == sType) |
| 3816 |
{ |
| 3817 |
return (const FindT*)s; |
| 3818 |
} |
| 3819 |
} |
| 3820 |
return VMA_NULL; |
| 3821 |
} |
| 3822 |
|
| 3823 |
|
| 3824 |
struct VmaBufferImageUsage |
| 3825 |
{ |
| 3826 |
#if VMA_KHR_MAINTENANCE5 |
| 3827 |
typedef uint64_t BaseType; |
| 3828 |
#else |
| 3829 |
typedef uint32_t BaseType; |
| 3830 |
#endif |
| 3831 |
|
| 3832 |
static const VmaBufferImageUsage UNKNOWN; |
| 3833 |
|
| 3834 |
BaseType Value; |
| 3835 |
|
| 3836 |
VmaBufferImageUsage() { *this = UNKNOWN; } |
| 3837 |
explicit VmaBufferImageUsage(BaseType usage) : Value(usage) { } |
| 3838 |
VmaBufferImageUsage(const VkBufferCreateInfo &createInfo, bool useKhrMaintenance5); |
| 3839 |
explicit VmaBufferImageUsage(const VkImageCreateInfo &createInfo); |
| 3840 |
|
| 3841 |
bool operator==(const VmaBufferImageUsage& rhs) const { return Value == rhs.Value; } |
| 3842 |
bool operator!=(const VmaBufferImageUsage& rhs) const { return Value != rhs.Value; } |
| 3843 |
|
| 3844 |
bool Contains(BaseType flag) const { return (Value & flag) != 0; } |
| 3845 |
bool ContainsDeviceAccess() const |
| 3846 |
{ |
| 3847 |
|
| 3848 |
return (Value & ~BaseType(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) != 0; |
| 3849 |
} |
| 3850 |
}; |
| 3851 |
|
| 3852 |
const VmaBufferImageUsage VmaBufferImageUsage::UNKNOWN = VmaBufferImageUsage(0); |
| 3853 |
|
| 3854 |
static void swap(VmaBufferImageUsage& lhs, VmaBufferImageUsage& rhs) noexcept |
| 3855 |
{ |
| 3856 |
using std::swap; |
| 3857 |
swap(lhs.Value, rhs.Value); |
| 3858 |
} |
| 3859 |
|
| 3860 |
VmaBufferImageUsage::VmaBufferImageUsage(const VkBufferCreateInfo &createInfo, |
| 3861 |
bool useKhrMaintenance5) |
| 3862 |
{ |
| 3863 |
#if VMA_KHR_MAINTENANCE5 |
| 3864 |
if(useKhrMaintenance5) |
| 3865 |
{ |
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 = |
| 3870 |
VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR); |
| 3871 |
if(usageFlags2) |
| 3872 |
{ |
| 3873 |
this->Value = usageFlags2->usage; |
| 3874 |
return; |
| 3875 |
} |
| 3876 |
} |
| 3877 |
#endif |
| 3878 |
|
| 3879 |
this->Value = (BaseType)createInfo.usage; |
| 3880 |
} |
| 3881 |
|
| 3882 |
VmaBufferImageUsage::VmaBufferImageUsage(const VkImageCreateInfo &createInfo) |
| 3883 |
{ |
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
this->Value = (BaseType)createInfo.usage; |
| 3888 |
} |
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
static bool FindMemoryPreferences( |
| 3893 |
bool isIntegratedGPU, |
| 3894 |
const VmaAllocationCreateInfo& allocCreateInfo, |
| 3895 |
VmaBufferImageUsage bufImgUsage, |
| 3896 |
VkMemoryPropertyFlags& outRequiredFlags, |
| 3897 |
VkMemoryPropertyFlags& outPreferredFlags, |
| 3898 |
VkMemoryPropertyFlags& outNotPreferredFlags) |
| 3899 |
{ |
| 3900 |
outRequiredFlags = allocCreateInfo.requiredFlags; |
| 3901 |
outPreferredFlags = allocCreateInfo.preferredFlags; |
| 3902 |
outNotPreferredFlags = 0; |
| 3903 |
|
| 3904 |
switch(allocCreateInfo.usage) |
| 3905 |
{ |
| 3906 |
case VMA_MEMORY_USAGE_UNKNOWN: |
| 3907 |
break; |
| 3908 |
case VMA_MEMORY_USAGE_GPU_ONLY: |
| 3909 |
if(!isIntegratedGPU || (outPreferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) |
| 3910 |
{ |
| 3911 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3912 |
} |
| 3913 |
break; |
| 3914 |
case VMA_MEMORY_USAGE_CPU_ONLY: |
| 3915 |
outRequiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; |
| 3916 |
break; |
| 3917 |
case VMA_MEMORY_USAGE_CPU_TO_GPU: |
| 3918 |
outRequiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 3919 |
if(!isIntegratedGPU || (outPreferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) |
| 3920 |
{ |
| 3921 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3922 |
} |
| 3923 |
break; |
| 3924 |
case VMA_MEMORY_USAGE_GPU_TO_CPU: |
| 3925 |
outRequiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 3926 |
outPreferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; |
| 3927 |
break; |
| 3928 |
case VMA_MEMORY_USAGE_CPU_COPY: |
| 3929 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3930 |
break; |
| 3931 |
case VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED: |
| 3932 |
outRequiredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; |
| 3933 |
break; |
| 3934 |
case VMA_MEMORY_USAGE_AUTO: |
| 3935 |
case VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE: |
| 3936 |
case VMA_MEMORY_USAGE_AUTO_PREFER_HOST: |
| 3937 |
{ |
| 3938 |
if(bufImgUsage == VmaBufferImageUsage::UNKNOWN) |
| 3939 |
{ |
| 3940 |
VMA_ASSERT(0 && "VMA_MEMORY_USAGE_AUTO* values can only be used with functions like vmaCreateBuffer, vmaCreateImage so that the details of the created resource are known." |
| 3941 |
" Maybe you use VkBufferUsageFlags2CreateInfoKHR but forgot to use VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT?" ); |
| 3942 |
return false; |
| 3943 |
} |
| 3944 |
|
| 3945 |
const bool deviceAccess = bufImgUsage.ContainsDeviceAccess(); |
| 3946 |
const bool hostAccessSequentialWrite = (allocCreateInfo.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT) != 0; |
| 3947 |
const bool hostAccessRandom = (allocCreateInfo.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT) != 0; |
| 3948 |
const bool hostAccessAllowTransferInstead = (allocCreateInfo.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT) != 0; |
| 3949 |
const bool preferDevice = allocCreateInfo.usage == VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; |
| 3950 |
const bool preferHost = allocCreateInfo.usage == VMA_MEMORY_USAGE_AUTO_PREFER_HOST; |
| 3951 |
|
| 3952 |
|
| 3953 |
if(hostAccessRandom) |
| 3954 |
{ |
| 3955 |
|
| 3956 |
outPreferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; |
| 3957 |
|
| 3958 |
if (!isIntegratedGPU && deviceAccess && hostAccessAllowTransferInstead && !preferHost) |
| 3959 |
{ |
| 3960 |
|
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3965 |
} |
| 3966 |
else |
| 3967 |
{ |
| 3968 |
|
| 3969 |
outRequiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 3970 |
} |
| 3971 |
} |
| 3972 |
|
| 3973 |
else if(hostAccessSequentialWrite) |
| 3974 |
{ |
| 3975 |
|
| 3976 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; |
| 3977 |
|
| 3978 |
if(!isIntegratedGPU && deviceAccess && hostAccessAllowTransferInstead && !preferHost) |
| 3979 |
{ |
| 3980 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 3981 |
} |
| 3982 |
else |
| 3983 |
{ |
| 3984 |
outRequiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 3985 |
|
| 3986 |
if(deviceAccess) |
| 3987 |
{ |
| 3988 |
|
| 3989 |
if(preferHost) |
| 3990 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3991 |
else |
| 3992 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 3993 |
} |
| 3994 |
|
| 3995 |
else |
| 3996 |
{ |
| 3997 |
|
| 3998 |
if(preferDevice) |
| 3999 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 4000 |
else |
| 4001 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 4002 |
} |
| 4003 |
} |
| 4004 |
} |
| 4005 |
|
| 4006 |
else |
| 4007 |
{ |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
if(preferHost) |
| 4021 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 4022 |
else |
| 4023 |
outPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 4024 |
} |
| 4025 |
break; |
| 4026 |
} |
| 4027 |
default: |
| 4028 |
VMA_ASSERT(0); |
| 4029 |
} |
| 4030 |
|
| 4031 |
|
| 4032 |
if(((allocCreateInfo.requiredFlags | allocCreateInfo.preferredFlags) & |
| 4033 |
(VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY)) == 0) |
| 4034 |
{ |
| 4035 |
outNotPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY; |
| 4036 |
} |
| 4037 |
|
| 4038 |
return true; |
| 4039 |
} |
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
static void* VmaMalloc(const VkAllocationCallbacks* pAllocationCallbacks, size_t size, size_t alignment) |
| 4045 |
{ |
| 4046 |
void* result = VMA_NULL; |
| 4047 |
if ((pAllocationCallbacks != VMA_NULL) && |
| 4048 |
(pAllocationCallbacks->pfnAllocation != VMA_NULL)) |
| 4049 |
{ |
| 4050 |
result = (*pAllocationCallbacks->pfnAllocation)( |
| 4051 |
pAllocationCallbacks->pUserData, |
| 4052 |
size, |
| 4053 |
alignment, |
| 4054 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 4055 |
} |
| 4056 |
else |
| 4057 |
{ |
| 4058 |
result = VMA_SYSTEM_ALIGNED_MALLOC(size, alignment); |
| 4059 |
} |
| 4060 |
VMA_ASSERT(result != VMA_NULL && "CPU memory allocation failed."); |
| 4061 |
return result; |
| 4062 |
} |
| 4063 |
|
| 4064 |
static void VmaFree(const VkAllocationCallbacks* pAllocationCallbacks, void* ptr) |
| 4065 |
{ |
| 4066 |
if ((pAllocationCallbacks != VMA_NULL) && |
| 4067 |
(pAllocationCallbacks->pfnFree != VMA_NULL)) |
| 4068 |
{ |
| 4069 |
(*pAllocationCallbacks->pfnFree)(pAllocationCallbacks->pUserData, ptr); |
| 4070 |
} |
| 4071 |
else |
| 4072 |
{ |
| 4073 |
VMA_SYSTEM_ALIGNED_FREE(ptr); |
| 4074 |
} |
| 4075 |
} |
| 4076 |
|
| 4077 |
template<typename T> |
| 4078 |
static T* VmaAllocate(const VkAllocationCallbacks* pAllocationCallbacks) |
| 4079 |
{ |
| 4080 |
return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T), VMA_ALIGN_OF(T)); |
| 4081 |
} |
| 4082 |
|
| 4083 |
template<typename T> |
| 4084 |
static T* VmaAllocateArray(const VkAllocationCallbacks* pAllocationCallbacks, size_t count) |
| 4085 |
{ |
| 4086 |
return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T) * count, VMA_ALIGN_OF(T)); |
| 4087 |
} |
| 4088 |
|
| 4089 |
#define vma_new(allocator, type) new(VmaAllocate<type>(allocator))(type) |
| 4090 |
|
| 4091 |
#define vma_new_array(allocator, type, count) new(VmaAllocateArray<type>((allocator), (count)))(type) |
| 4092 |
|
| 4093 |
template<typename T> |
| 4094 |
static void vma_delete(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr) |
| 4095 |
{ |
| 4096 |
ptr->~T(); |
| 4097 |
VmaFree(pAllocationCallbacks, ptr); |
| 4098 |
} |
| 4099 |
|
| 4100 |
template<typename T> |
| 4101 |
static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count) |
| 4102 |
{ |
| 4103 |
if (ptr != VMA_NULL) |
| 4104 |
{ |
| 4105 |
for (size_t i = count; i--; ) |
| 4106 |
{ |
| 4107 |
ptr[i].~T(); |
| 4108 |
} |
| 4109 |
VmaFree(pAllocationCallbacks, ptr); |
| 4110 |
} |
| 4111 |
} |
| 4112 |
|
| 4113 |
static char* VmaCreateStringCopy(const VkAllocationCallbacks* allocs, const char* srcStr) |
| 4114 |
{ |
| 4115 |
if (srcStr != VMA_NULL) |
| 4116 |
{ |
| 4117 |
const size_t len = strlen(srcStr); |
| 4118 |
char* const result = vma_new_array(allocs, char, len + 1); |
| 4119 |
memcpy(result, srcStr, len + 1); |
| 4120 |
return result; |
| 4121 |
} |
| 4122 |
return VMA_NULL; |
| 4123 |
} |
| 4124 |
|
| 4125 |
#if VMA_STATS_STRING_ENABLED |
| 4126 |
static char* VmaCreateStringCopy(const VkAllocationCallbacks* allocs, const char* srcStr, size_t strLen) |
| 4127 |
{ |
| 4128 |
if (srcStr != VMA_NULL) |
| 4129 |
{ |
| 4130 |
char* const result = vma_new_array(allocs, char, strLen + 1); |
| 4131 |
memcpy(result, srcStr, strLen); |
| 4132 |
result[strLen] = '\0'; |
| 4133 |
return result; |
| 4134 |
} |
| 4135 |
return VMA_NULL; |
| 4136 |
} |
| 4137 |
#endif |
| 4138 |
|
| 4139 |
static void VmaFreeString(const VkAllocationCallbacks* allocs, char* str) |
| 4140 |
{ |
| 4141 |
if (str != VMA_NULL) |
| 4142 |
{ |
| 4143 |
const size_t len = strlen(str); |
| 4144 |
vma_delete_array(allocs, str, len + 1); |
| 4145 |
} |
| 4146 |
} |
| 4147 |
|
| 4148 |
template<typename CmpLess, typename VectorT> |
| 4149 |
size_t VmaVectorInsertSorted(VectorT& vector, const typename VectorT::value_type& value) |
| 4150 |
{ |
| 4151 |
const size_t indexToInsert = VmaBinaryFindFirstNotLess( |
| 4152 |
vector.data(), |
| 4153 |
vector.data() + vector.size(), |
| 4154 |
value, |
| 4155 |
CmpLess()) - vector.data(); |
| 4156 |
VmaVectorInsert(vector, indexToInsert, value); |
| 4157 |
return indexToInsert; |
| 4158 |
} |
| 4159 |
|
| 4160 |
template<typename CmpLess, typename VectorT> |
| 4161 |
bool VmaVectorRemoveSorted(VectorT& vector, const typename VectorT::value_type& value) |
| 4162 |
{ |
| 4163 |
CmpLess comparator; |
| 4164 |
typename VectorT::iterator it = VmaBinaryFindFirstNotLess( |
| 4165 |
vector.begin(), |
| 4166 |
vector.end(), |
| 4167 |
value, |
| 4168 |
comparator); |
| 4169 |
if ((it != vector.end()) && !comparator(*it, value) && !comparator(value, *it)) |
| 4170 |
{ |
| 4171 |
size_t indexToRemove = it - vector.begin(); |
| 4172 |
VmaVectorRemove(vector, indexToRemove); |
| 4173 |
return true; |
| 4174 |
} |
| 4175 |
return false; |
| 4176 |
} |
| 4177 |
#endif |
| 4178 |
|
| 4179 |
#ifndef _VMA_STATISTICS_FUNCTIONS |
| 4180 |
|
| 4181 |
static void VmaClearStatistics(VmaStatistics& outStats) |
| 4182 |
{ |
| 4183 |
outStats.blockCount = 0; |
| 4184 |
outStats.allocationCount = 0; |
| 4185 |
outStats.blockBytes = 0; |
| 4186 |
outStats.allocationBytes = 0; |
| 4187 |
} |
| 4188 |
|
| 4189 |
static void VmaAddStatistics(VmaStatistics& inoutStats, const VmaStatistics& src) |
| 4190 |
{ |
| 4191 |
inoutStats.blockCount += src.blockCount; |
| 4192 |
inoutStats.allocationCount += src.allocationCount; |
| 4193 |
inoutStats.blockBytes += src.blockBytes; |
| 4194 |
inoutStats.allocationBytes += src.allocationBytes; |
| 4195 |
} |
| 4196 |
|
| 4197 |
static void VmaClearDetailedStatistics(VmaDetailedStatistics& outStats) |
| 4198 |
{ |
| 4199 |
VmaClearStatistics(outStats.statistics); |
| 4200 |
outStats.unusedRangeCount = 0; |
| 4201 |
outStats.allocationSizeMin = VK_WHOLE_SIZE; |
| 4202 |
outStats.allocationSizeMax = 0; |
| 4203 |
outStats.unusedRangeSizeMin = VK_WHOLE_SIZE; |
| 4204 |
outStats.unusedRangeSizeMax = 0; |
| 4205 |
} |
| 4206 |
|
| 4207 |
static void VmaAddDetailedStatisticsAllocation(VmaDetailedStatistics& inoutStats, VkDeviceSize size) |
| 4208 |
{ |
| 4209 |
inoutStats.statistics.allocationCount++; |
| 4210 |
inoutStats.statistics.allocationBytes += size; |
| 4211 |
inoutStats.allocationSizeMin = VMA_MIN(inoutStats.allocationSizeMin, size); |
| 4212 |
inoutStats.allocationSizeMax = VMA_MAX(inoutStats.allocationSizeMax, size); |
| 4213 |
} |
| 4214 |
|
| 4215 |
static void VmaAddDetailedStatisticsUnusedRange(VmaDetailedStatistics& inoutStats, VkDeviceSize size) |
| 4216 |
{ |
| 4217 |
inoutStats.unusedRangeCount++; |
| 4218 |
inoutStats.unusedRangeSizeMin = VMA_MIN(inoutStats.unusedRangeSizeMin, size); |
| 4219 |
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, size); |
| 4220 |
} |
| 4221 |
|
| 4222 |
static void VmaAddDetailedStatistics(VmaDetailedStatistics& inoutStats, const VmaDetailedStatistics& src) |
| 4223 |
{ |
| 4224 |
VmaAddStatistics(inoutStats.statistics, src.statistics); |
| 4225 |
inoutStats.unusedRangeCount += src.unusedRangeCount; |
| 4226 |
inoutStats.allocationSizeMin = VMA_MIN(inoutStats.allocationSizeMin, src.allocationSizeMin); |
| 4227 |
inoutStats.allocationSizeMax = VMA_MAX(inoutStats.allocationSizeMax, src.allocationSizeMax); |
| 4228 |
inoutStats.unusedRangeSizeMin = VMA_MIN(inoutStats.unusedRangeSizeMin, src.unusedRangeSizeMin); |
| 4229 |
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, src.unusedRangeSizeMax); |
| 4230 |
} |
| 4231 |
|
| 4232 |
#endif |
| 4233 |
|
| 4234 |
#ifndef _VMA_MUTEX_LOCK |
| 4235 |
|
| 4236 |
struct VmaMutexLock |
| 4237 |
{ |
| 4238 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLock) |
| 4239 |
public: |
| 4240 |
VmaMutexLock(VMA_MUTEX& mutex, bool useMutex = true) : |
| 4241 |
m_pMutex(useMutex ? &mutex : VMA_NULL) |
| 4242 |
{ |
| 4243 |
if (m_pMutex) { m_pMutex->Lock(); } |
| 4244 |
} |
| 4245 |
~VmaMutexLock() { if (m_pMutex) { m_pMutex->Unlock(); } } |
| 4246 |
|
| 4247 |
private: |
| 4248 |
VMA_MUTEX* m_pMutex; |
| 4249 |
}; |
| 4250 |
|
| 4251 |
|
| 4252 |
struct VmaMutexLockRead |
| 4253 |
{ |
| 4254 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLockRead) |
| 4255 |
public: |
| 4256 |
VmaMutexLockRead(VMA_RW_MUTEX& mutex, bool useMutex) : |
| 4257 |
m_pMutex(useMutex ? &mutex : VMA_NULL) |
| 4258 |
{ |
| 4259 |
if (m_pMutex) { m_pMutex->LockRead(); } |
| 4260 |
} |
| 4261 |
~VmaMutexLockRead() { if (m_pMutex) { m_pMutex->UnlockRead(); } } |
| 4262 |
|
| 4263 |
private: |
| 4264 |
VMA_RW_MUTEX* m_pMutex; |
| 4265 |
}; |
| 4266 |
|
| 4267 |
|
| 4268 |
struct VmaMutexLockWrite |
| 4269 |
{ |
| 4270 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLockWrite) |
| 4271 |
public: |
| 4272 |
VmaMutexLockWrite(VMA_RW_MUTEX& mutex, bool useMutex) |
| 4273 |
: m_pMutex(useMutex ? &mutex : VMA_NULL) |
| 4274 |
{ |
| 4275 |
if (m_pMutex) { m_pMutex->LockWrite(); } |
| 4276 |
} |
| 4277 |
~VmaMutexLockWrite() { if (m_pMutex) { m_pMutex->UnlockWrite(); } } |
| 4278 |
|
| 4279 |
private: |
| 4280 |
VMA_RW_MUTEX* m_pMutex; |
| 4281 |
}; |
| 4282 |
|
| 4283 |
#if VMA_DEBUG_GLOBAL_MUTEX |
| 4284 |
static VMA_MUTEX gDebugGlobalMutex; |
| 4285 |
#define VMA_DEBUG_GLOBAL_MUTEX_LOCK VmaMutexLock debugGlobalMutexLock(gDebugGlobalMutex, true); |
| 4286 |
#else |
| 4287 |
#define VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 4288 |
#endif |
| 4289 |
#endif |
| 4290 |
|
| 4291 |
#ifndef _VMA_ATOMIC_TRANSACTIONAL_INCREMENT |
| 4292 |
|
| 4293 |
template<typename AtomicT> |
| 4294 |
struct AtomicTransactionalIncrement |
| 4295 |
{ |
| 4296 |
public: |
| 4297 |
using T = decltype(AtomicT().load()); |
| 4298 |
|
| 4299 |
~AtomicTransactionalIncrement() |
| 4300 |
{ |
| 4301 |
if(m_Atomic) |
| 4302 |
--(*m_Atomic); |
| 4303 |
} |
| 4304 |
|
| 4305 |
void Commit() { m_Atomic = VMA_NULL; } |
| 4306 |
T Increment(AtomicT* atomic) |
| 4307 |
{ |
| 4308 |
m_Atomic = atomic; |
| 4309 |
return m_Atomic->fetch_add(1); |
| 4310 |
} |
| 4311 |
|
| 4312 |
private: |
| 4313 |
AtomicT* m_Atomic = VMA_NULL; |
| 4314 |
}; |
| 4315 |
#endif |
| 4316 |
|
| 4317 |
#ifndef _VMA_STL_ALLOCATOR |
| 4318 |
|
| 4319 |
template<typename T> |
| 4320 |
struct VmaStlAllocator |
| 4321 |
{ |
| 4322 |
const VkAllocationCallbacks* const m_pCallbacks; |
| 4323 |
typedef T value_type; |
| 4324 |
|
| 4325 |
VmaStlAllocator(const VkAllocationCallbacks* pCallbacks) : m_pCallbacks(pCallbacks) {} |
| 4326 |
template<typename U> |
| 4327 |
VmaStlAllocator(const VmaStlAllocator<U>& src) : m_pCallbacks(src.m_pCallbacks) {} |
| 4328 |
VmaStlAllocator(const VmaStlAllocator&) = default; |
| 4329 |
VmaStlAllocator& operator=(const VmaStlAllocator&) = delete; |
| 4330 |
|
| 4331 |
T* allocate(size_t n) { return VmaAllocateArray<T>(m_pCallbacks, n); } |
| 4332 |
void deallocate(T* p, size_t n) { VmaFree(m_pCallbacks, p); } |
| 4333 |
|
| 4334 |
template<typename U> |
| 4335 |
bool operator==(const VmaStlAllocator<U>& rhs) const |
| 4336 |
{ |
| 4337 |
return m_pCallbacks == rhs.m_pCallbacks; |
| 4338 |
} |
| 4339 |
template<typename U> |
| 4340 |
bool operator!=(const VmaStlAllocator<U>& rhs) const |
| 4341 |
{ |
| 4342 |
return m_pCallbacks != rhs.m_pCallbacks; |
| 4343 |
} |
| 4344 |
}; |
| 4345 |
#endif |
| 4346 |
|
| 4347 |
#ifndef _VMA_VECTOR |
| 4348 |
|
| 4349 |
|
| 4350 |
|
| 4351 |
template<typename T, typename AllocatorT> |
| 4352 |
class VmaVector |
| 4353 |
{ |
| 4354 |
public: |
| 4355 |
typedef T value_type; |
| 4356 |
typedef T* iterator; |
| 4357 |
typedef const T* const_iterator; |
| 4358 |
|
| 4359 |
VmaVector(const AllocatorT& allocator); |
| 4360 |
VmaVector(size_t count, const AllocatorT& allocator); |
| 4361 |
|
| 4362 |
|
| 4363 |
VmaVector(size_t count, const T& value, const AllocatorT& allocator) : VmaVector(count, allocator) {} |
| 4364 |
VmaVector(const VmaVector<T, AllocatorT>& src); |
| 4365 |
VmaVector& operator=(const VmaVector& rhs); |
| 4366 |
~VmaVector() { VmaFree(m_Allocator.m_pCallbacks, m_pArray); } |
| 4367 |
|
| 4368 |
bool empty() const { return m_Count == 0; } |
| 4369 |
size_t size() const { return m_Count; } |
| 4370 |
T* data() { return m_pArray; } |
| 4371 |
T& front() { VMA_HEAVY_ASSERT(m_Count > 0); return m_pArray[0]; } |
| 4372 |
T& back() { VMA_HEAVY_ASSERT(m_Count > 0); return m_pArray[m_Count - 1]; } |
| 4373 |
const T* data() const { return m_pArray; } |
| 4374 |
const T& front() const { VMA_HEAVY_ASSERT(m_Count > 0); return m_pArray[0]; } |
| 4375 |
const T& back() const { VMA_HEAVY_ASSERT(m_Count > 0); return m_pArray[m_Count - 1]; } |
| 4376 |
|
| 4377 |
iterator begin() { return m_pArray; } |
| 4378 |
iterator end() { return m_pArray + m_Count; } |
| 4379 |
const_iterator cbegin() const { return m_pArray; } |
| 4380 |
const_iterator cend() const { return m_pArray + m_Count; } |
| 4381 |
const_iterator begin() const { return cbegin(); } |
| 4382 |
const_iterator end() const { return cend(); } |
| 4383 |
|
| 4384 |
void pop_front() { VMA_HEAVY_ASSERT(m_Count > 0); remove(0); } |
| 4385 |
void pop_back() { VMA_HEAVY_ASSERT(m_Count > 0); resize(size() - 1); } |
| 4386 |
void push_front(const T& src) { insert(0, src); } |
| 4387 |
|
| 4388 |
void push_back(const T& src); |
| 4389 |
void reserve(size_t newCapacity, bool freeMemory = false); |
| 4390 |
void resize(size_t newCount); |
| 4391 |
void clear() { resize(0); } |
| 4392 |
void shrink_to_fit(); |
| 4393 |
void insert(size_t index, const T& src); |
| 4394 |
void remove(size_t index); |
| 4395 |
|
| 4396 |
T& operator[](size_t index) { VMA_HEAVY_ASSERT(index < m_Count); return m_pArray[index]; } |
| 4397 |
const T& operator[](size_t index) const { VMA_HEAVY_ASSERT(index < m_Count); return m_pArray[index]; } |
| 4398 |
|
| 4399 |
private: |
| 4400 |
AllocatorT m_Allocator; |
| 4401 |
T* m_pArray; |
| 4402 |
size_t m_Count; |
| 4403 |
size_t m_Capacity; |
| 4404 |
}; |
| 4405 |
|
| 4406 |
#ifndef _VMA_VECTOR_FUNCTIONS |
| 4407 |
template<typename T, typename AllocatorT> |
| 4408 |
VmaVector<T, AllocatorT>::VmaVector(const AllocatorT& allocator) |
| 4409 |
: m_Allocator(allocator), |
| 4410 |
m_pArray(VMA_NULL), |
| 4411 |
m_Count(0), |
| 4412 |
m_Capacity(0) {} |
| 4413 |
|
| 4414 |
template<typename T, typename AllocatorT> |
| 4415 |
VmaVector<T, AllocatorT>::VmaVector(size_t count, const AllocatorT& allocator) |
| 4416 |
: m_Allocator(allocator), |
| 4417 |
m_pArray(count ? (T*)VmaAllocateArray<T>(allocator.m_pCallbacks, count) : VMA_NULL), |
| 4418 |
m_Count(count), |
| 4419 |
m_Capacity(count) {} |
| 4420 |
|
| 4421 |
template<typename T, typename AllocatorT> |
| 4422 |
VmaVector<T, AllocatorT>::VmaVector(const VmaVector& src) |
| 4423 |
: m_Allocator(src.m_Allocator), |
| 4424 |
m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL), |
| 4425 |
m_Count(src.m_Count), |
| 4426 |
m_Capacity(src.m_Count) |
| 4427 |
{ |
| 4428 |
if (m_Count != 0) |
| 4429 |
{ |
| 4430 |
memcpy(m_pArray, src.m_pArray, m_Count * sizeof(T)); |
| 4431 |
} |
| 4432 |
} |
| 4433 |
|
| 4434 |
template<typename T, typename AllocatorT> |
| 4435 |
VmaVector<T, AllocatorT>& VmaVector<T, AllocatorT>::operator=(const VmaVector& rhs) |
| 4436 |
{ |
| 4437 |
if (&rhs != this) |
| 4438 |
{ |
| 4439 |
resize(rhs.m_Count); |
| 4440 |
if (m_Count != 0) |
| 4441 |
{ |
| 4442 |
memcpy(m_pArray, rhs.m_pArray, m_Count * sizeof(T)); |
| 4443 |
} |
| 4444 |
} |
| 4445 |
return *this; |
| 4446 |
} |
| 4447 |
|
| 4448 |
template<typename T, typename AllocatorT> |
| 4449 |
void VmaVector<T, AllocatorT>::push_back(const T& src) |
| 4450 |
{ |
| 4451 |
const size_t newIndex = size(); |
| 4452 |
resize(newIndex + 1); |
| 4453 |
m_pArray[newIndex] = src; |
| 4454 |
} |
| 4455 |
|
| 4456 |
template<typename T, typename AllocatorT> |
| 4457 |
void VmaVector<T, AllocatorT>::reserve(size_t newCapacity, bool freeMemory) |
| 4458 |
{ |
| 4459 |
newCapacity = VMA_MAX(newCapacity, m_Count); |
| 4460 |
|
| 4461 |
if ((newCapacity < m_Capacity) && !freeMemory) |
| 4462 |
{ |
| 4463 |
newCapacity = m_Capacity; |
| 4464 |
} |
| 4465 |
|
| 4466 |
if (newCapacity != m_Capacity) |
| 4467 |
{ |
| 4468 |
T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator, newCapacity) : VMA_NULL; |
| 4469 |
if (m_Count != 0) |
| 4470 |
{ |
| 4471 |
memcpy(newArray, m_pArray, m_Count * sizeof(T)); |
| 4472 |
} |
| 4473 |
VmaFree(m_Allocator.m_pCallbacks, m_pArray); |
| 4474 |
m_Capacity = newCapacity; |
| 4475 |
m_pArray = newArray; |
| 4476 |
} |
| 4477 |
} |
| 4478 |
|
| 4479 |
template<typename T, typename AllocatorT> |
| 4480 |
void VmaVector<T, AllocatorT>::resize(size_t newCount) |
| 4481 |
{ |
| 4482 |
size_t newCapacity = m_Capacity; |
| 4483 |
if (newCount > m_Capacity) |
| 4484 |
{ |
| 4485 |
newCapacity = VMA_MAX(newCount, VMA_MAX(m_Capacity * 3 / 2, (size_t)8)); |
| 4486 |
} |
| 4487 |
|
| 4488 |
if (newCapacity != m_Capacity) |
| 4489 |
{ |
| 4490 |
T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL; |
| 4491 |
const size_t elementsToCopy = VMA_MIN(m_Count, newCount); |
| 4492 |
if (elementsToCopy != 0) |
| 4493 |
{ |
| 4494 |
memcpy(newArray, m_pArray, elementsToCopy * sizeof(T)); |
| 4495 |
} |
| 4496 |
VmaFree(m_Allocator.m_pCallbacks, m_pArray); |
| 4497 |
m_Capacity = newCapacity; |
| 4498 |
m_pArray = newArray; |
| 4499 |
} |
| 4500 |
|
| 4501 |
m_Count = newCount; |
| 4502 |
} |
| 4503 |
|
| 4504 |
template<typename T, typename AllocatorT> |
| 4505 |
void VmaVector<T, AllocatorT>::shrink_to_fit() |
| 4506 |
{ |
| 4507 |
if (m_Capacity > m_Count) |
| 4508 |
{ |
| 4509 |
T* newArray = VMA_NULL; |
| 4510 |
if (m_Count > 0) |
| 4511 |
{ |
| 4512 |
newArray = VmaAllocateArray<T>(m_Allocator.m_pCallbacks, m_Count); |
| 4513 |
memcpy(newArray, m_pArray, m_Count * sizeof(T)); |
| 4514 |
} |
| 4515 |
VmaFree(m_Allocator.m_pCallbacks, m_pArray); |
| 4516 |
m_Capacity = m_Count; |
| 4517 |
m_pArray = newArray; |
| 4518 |
} |
| 4519 |
} |
| 4520 |
|
| 4521 |
template<typename T, typename AllocatorT> |
| 4522 |
void VmaVector<T, AllocatorT>::insert(size_t index, const T& src) |
| 4523 |
{ |
| 4524 |
VMA_HEAVY_ASSERT(index <= m_Count); |
| 4525 |
const size_t oldCount = size(); |
| 4526 |
resize(oldCount + 1); |
| 4527 |
if (index < oldCount) |
| 4528 |
{ |
| 4529 |
memmove(m_pArray + (index + 1), m_pArray + index, (oldCount - index) * sizeof(T)); |
| 4530 |
} |
| 4531 |
m_pArray[index] = src; |
| 4532 |
} |
| 4533 |
|
| 4534 |
template<typename T, typename AllocatorT> |
| 4535 |
void VmaVector<T, AllocatorT>::remove(size_t index) |
| 4536 |
{ |
| 4537 |
VMA_HEAVY_ASSERT(index < m_Count); |
| 4538 |
const size_t oldCount = size(); |
| 4539 |
if (index < oldCount - 1) |
| 4540 |
{ |
| 4541 |
memmove(m_pArray + index, m_pArray + (index + 1), (oldCount - index - 1) * sizeof(T)); |
| 4542 |
} |
| 4543 |
resize(oldCount - 1); |
| 4544 |
} |
| 4545 |
#endif |
| 4546 |
|
| 4547 |
template<typename T, typename allocatorT> |
| 4548 |
static void VmaVectorInsert(VmaVector<T, allocatorT>& vec, size_t index, const T& item) |
| 4549 |
{ |
| 4550 |
vec.insert(index, item); |
| 4551 |
} |
| 4552 |
|
| 4553 |
template<typename T, typename allocatorT> |
| 4554 |
static void VmaVectorRemove(VmaVector<T, allocatorT>& vec, size_t index) |
| 4555 |
{ |
| 4556 |
vec.remove(index); |
| 4557 |
} |
| 4558 |
#endif |
| 4559 |
|
| 4560 |
#ifndef _VMA_SMALL_VECTOR |
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
|
| 4567 |
|
| 4568 |
template<typename T, typename AllocatorT, size_t N> |
| 4569 |
class VmaSmallVector |
| 4570 |
{ |
| 4571 |
public: |
| 4572 |
typedef T value_type; |
| 4573 |
typedef T* iterator; |
| 4574 |
|
| 4575 |
VmaSmallVector(const AllocatorT& allocator); |
| 4576 |
VmaSmallVector(size_t count, const AllocatorT& allocator); |
| 4577 |
template<typename SrcT, typename SrcAllocatorT, size_t SrcN> |
| 4578 |
VmaSmallVector(const VmaSmallVector<SrcT, SrcAllocatorT, SrcN>&) = delete; |
| 4579 |
template<typename SrcT, typename SrcAllocatorT, size_t SrcN> |
| 4580 |
VmaSmallVector<T, AllocatorT, N>& operator=(const VmaSmallVector<SrcT, SrcAllocatorT, SrcN>&) = delete; |
| 4581 |
~VmaSmallVector() = default; |
| 4582 |
|
| 4583 |
bool empty() const { return m_Count == 0; } |
| 4584 |
size_t size() const { return m_Count; } |
| 4585 |
T* data() { return m_Count > N ? m_DynamicArray.data() : m_StaticArray; } |
| 4586 |
T& front() { VMA_HEAVY_ASSERT(m_Count > 0); return data()[0]; } |
| 4587 |
T& back() { VMA_HEAVY_ASSERT(m_Count > 0); return data()[m_Count - 1]; } |
| 4588 |
const T* data() const { return m_Count > N ? m_DynamicArray.data() : m_StaticArray; } |
| 4589 |
const T& front() const { VMA_HEAVY_ASSERT(m_Count > 0); return data()[0]; } |
| 4590 |
const T& back() const { VMA_HEAVY_ASSERT(m_Count > 0); return data()[m_Count - 1]; } |
| 4591 |
|
| 4592 |
iterator begin() { return data(); } |
| 4593 |
iterator end() { return data() + m_Count; } |
| 4594 |
|
| 4595 |
void pop_front() { VMA_HEAVY_ASSERT(m_Count > 0); remove(0); } |
| 4596 |
void pop_back() { VMA_HEAVY_ASSERT(m_Count > 0); resize(size() - 1); } |
| 4597 |
void push_front(const T& src) { insert(0, src); } |
| 4598 |
|
| 4599 |
void push_back(const T& src); |
| 4600 |
void resize(size_t newCount, bool freeMemory = false); |
| 4601 |
void clear(bool freeMemory = false); |
| 4602 |
void insert(size_t index, const T& src); |
| 4603 |
void remove(size_t index); |
| 4604 |
|
| 4605 |
T& operator[](size_t index) { VMA_HEAVY_ASSERT(index < m_Count); return data()[index]; } |
| 4606 |
const T& operator[](size_t index) const { VMA_HEAVY_ASSERT(index < m_Count); return data()[index]; } |
| 4607 |
|
| 4608 |
private: |
| 4609 |
size_t m_Count; |
| 4610 |
T m_StaticArray[N]; |
| 4611 |
VmaVector<T, AllocatorT> m_DynamicArray; |
| 4612 |
}; |
| 4613 |
|
| 4614 |
#ifndef _VMA_SMALL_VECTOR_FUNCTIONS |
| 4615 |
template<typename T, typename AllocatorT, size_t N> |
| 4616 |
VmaSmallVector<T, AllocatorT, N>::VmaSmallVector(const AllocatorT& allocator) |
| 4617 |
: m_Count(0), |
| 4618 |
m_DynamicArray(allocator) {} |
| 4619 |
|
| 4620 |
template<typename T, typename AllocatorT, size_t N> |
| 4621 |
VmaSmallVector<T, AllocatorT, N>::VmaSmallVector(size_t count, const AllocatorT& allocator) |
| 4622 |
: m_Count(count), |
| 4623 |
m_DynamicArray(count > N ? count : 0, allocator) {} |
| 4624 |
|
| 4625 |
template<typename T, typename AllocatorT, size_t N> |
| 4626 |
void VmaSmallVector<T, AllocatorT, N>::push_back(const T& src) |
| 4627 |
{ |
| 4628 |
const size_t newIndex = size(); |
| 4629 |
resize(newIndex + 1); |
| 4630 |
data()[newIndex] = src; |
| 4631 |
} |
| 4632 |
|
| 4633 |
template<typename T, typename AllocatorT, size_t N> |
| 4634 |
void VmaSmallVector<T, AllocatorT, N>::resize(size_t newCount, bool freeMemory) |
| 4635 |
{ |
| 4636 |
if (newCount > N && m_Count > N) |
| 4637 |
{ |
| 4638 |
|
| 4639 |
m_DynamicArray.resize(newCount); |
| 4640 |
if (freeMemory) |
| 4641 |
{ |
| 4642 |
m_DynamicArray.shrink_to_fit(); |
| 4643 |
} |
| 4644 |
} |
| 4645 |
else if (newCount > N && m_Count <= N) |
| 4646 |
{ |
| 4647 |
|
| 4648 |
m_DynamicArray.resize(newCount); |
| 4649 |
if (m_Count > 0) |
| 4650 |
{ |
| 4651 |
memcpy(m_DynamicArray.data(), m_StaticArray, m_Count * sizeof(T)); |
| 4652 |
} |
| 4653 |
} |
| 4654 |
else if (newCount <= N && m_Count > N) |
| 4655 |
{ |
| 4656 |
|
| 4657 |
if (newCount > 0) |
| 4658 |
{ |
| 4659 |
memcpy(m_StaticArray, m_DynamicArray.data(), newCount * sizeof(T)); |
| 4660 |
} |
| 4661 |
m_DynamicArray.resize(0); |
| 4662 |
if (freeMemory) |
| 4663 |
{ |
| 4664 |
m_DynamicArray.shrink_to_fit(); |
| 4665 |
} |
| 4666 |
} |
| 4667 |
else |
| 4668 |
{ |
| 4669 |
|
| 4670 |
} |
| 4671 |
m_Count = newCount; |
| 4672 |
} |
| 4673 |
|
| 4674 |
template<typename T, typename AllocatorT, size_t N> |
| 4675 |
void VmaSmallVector<T, AllocatorT, N>::clear(bool freeMemory) |
| 4676 |
{ |
| 4677 |
m_DynamicArray.clear(); |
| 4678 |
if (freeMemory) |
| 4679 |
{ |
| 4680 |
m_DynamicArray.shrink_to_fit(); |
| 4681 |
} |
| 4682 |
m_Count = 0; |
| 4683 |
} |
| 4684 |
|
| 4685 |
template<typename T, typename AllocatorT, size_t N> |
| 4686 |
void VmaSmallVector<T, AllocatorT, N>::insert(size_t index, const T& src) |
| 4687 |
{ |
| 4688 |
VMA_HEAVY_ASSERT(index <= m_Count); |
| 4689 |
const size_t oldCount = size(); |
| 4690 |
resize(oldCount + 1); |
| 4691 |
T* const dataPtr = data(); |
| 4692 |
if (index < oldCount) |
| 4693 |
{ |
| 4694 |
|
| 4695 |
memmove(dataPtr + (index + 1), dataPtr + index, (oldCount - index) * sizeof(T)); |
| 4696 |
} |
| 4697 |
dataPtr[index] = src; |
| 4698 |
} |
| 4699 |
|
| 4700 |
template<typename T, typename AllocatorT, size_t N> |
| 4701 |
void VmaSmallVector<T, AllocatorT, N>::remove(size_t index) |
| 4702 |
{ |
| 4703 |
VMA_HEAVY_ASSERT(index < m_Count); |
| 4704 |
const size_t oldCount = size(); |
| 4705 |
if (index < oldCount - 1) |
| 4706 |
{ |
| 4707 |
|
| 4708 |
T* const dataPtr = data(); |
| 4709 |
memmove(dataPtr + index, dataPtr + (index + 1), (oldCount - index - 1) * sizeof(T)); |
| 4710 |
} |
| 4711 |
resize(oldCount - 1); |
| 4712 |
} |
| 4713 |
#endif |
| 4714 |
#endif |
| 4715 |
|
| 4716 |
#ifndef _VMA_POOL_ALLOCATOR |
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
|
| 4721 |
|
| 4722 |
template<typename T> |
| 4723 |
class VmaPoolAllocator |
| 4724 |
{ |
| 4725 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaPoolAllocator) |
| 4726 |
public: |
| 4727 |
VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity); |
| 4728 |
~VmaPoolAllocator(); |
| 4729 |
template<typename... Types> T* Alloc(Types&&... args); |
| 4730 |
void Free(T* ptr); |
| 4731 |
|
| 4732 |
private: |
| 4733 |
union Item |
| 4734 |
{ |
| 4735 |
uint32_t NextFreeIndex; |
| 4736 |
alignas(T) char Value[sizeof(T)]; |
| 4737 |
}; |
| 4738 |
struct ItemBlock |
| 4739 |
{ |
| 4740 |
Item* pItems; |
| 4741 |
uint32_t Capacity; |
| 4742 |
uint32_t FirstFreeIndex; |
| 4743 |
}; |
| 4744 |
|
| 4745 |
const VkAllocationCallbacks* m_pAllocationCallbacks; |
| 4746 |
const uint32_t m_FirstBlockCapacity; |
| 4747 |
VmaVector<ItemBlock, VmaStlAllocator<ItemBlock>> m_ItemBlocks; |
| 4748 |
|
| 4749 |
ItemBlock& CreateNewBlock(); |
| 4750 |
}; |
| 4751 |
|
| 4752 |
#ifndef _VMA_POOL_ALLOCATOR_FUNCTIONS |
| 4753 |
template<typename T> |
| 4754 |
VmaPoolAllocator<T>::VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity) |
| 4755 |
: m_pAllocationCallbacks(pAllocationCallbacks), |
| 4756 |
m_FirstBlockCapacity(firstBlockCapacity), |
| 4757 |
m_ItemBlocks(VmaStlAllocator<ItemBlock>(pAllocationCallbacks)) |
| 4758 |
{ |
| 4759 |
VMA_ASSERT(m_FirstBlockCapacity > 1); |
| 4760 |
} |
| 4761 |
|
| 4762 |
template<typename T> |
| 4763 |
VmaPoolAllocator<T>::~VmaPoolAllocator() |
| 4764 |
{ |
| 4765 |
for (size_t i = m_ItemBlocks.size(); i--;) |
| 4766 |
vma_delete_array(m_pAllocationCallbacks, m_ItemBlocks[i].pItems, m_ItemBlocks[i].Capacity); |
| 4767 |
m_ItemBlocks.clear(); |
| 4768 |
} |
| 4769 |
|
| 4770 |
template<typename T> |
| 4771 |
template<typename... Types> T* VmaPoolAllocator<T>::Alloc(Types&&... args) |
| 4772 |
{ |
| 4773 |
for (size_t i = m_ItemBlocks.size(); i--; ) |
| 4774 |
{ |
| 4775 |
ItemBlock& block = m_ItemBlocks[i]; |
| 4776 |
|
| 4777 |
if (block.FirstFreeIndex != UINT32_MAX) |
| 4778 |
{ |
| 4779 |
Item* const pItem = &block.pItems[block.FirstFreeIndex]; |
| 4780 |
block.FirstFreeIndex = pItem->NextFreeIndex; |
| 4781 |
T* result = (T*)&pItem->Value; |
| 4782 |
new(result)T(std::forward<Types>(args)...); |
| 4783 |
return result; |
| 4784 |
} |
| 4785 |
} |
| 4786 |
|
| 4787 |
|
| 4788 |
ItemBlock& newBlock = CreateNewBlock(); |
| 4789 |
Item* const pItem = &newBlock.pItems[0]; |
| 4790 |
newBlock.FirstFreeIndex = pItem->NextFreeIndex; |
| 4791 |
T* result = (T*)&pItem->Value; |
| 4792 |
new(result) T(std::forward<Types>(args)...); |
| 4793 |
return result; |
| 4794 |
} |
| 4795 |
|
| 4796 |
template<typename T> |
| 4797 |
void VmaPoolAllocator<T>::Free(T* ptr) |
| 4798 |
{ |
| 4799 |
|
| 4800 |
for (size_t i = m_ItemBlocks.size(); i--; ) |
| 4801 |
{ |
| 4802 |
ItemBlock& block = m_ItemBlocks[i]; |
| 4803 |
|
| 4804 |
|
| 4805 |
Item* pItemPtr; |
| 4806 |
memcpy(&pItemPtr, &ptr, sizeof(pItemPtr)); |
| 4807 |
|
| 4808 |
|
| 4809 |
if ((pItemPtr >= block.pItems) && (pItemPtr < block.pItems + block.Capacity)) |
| 4810 |
{ |
| 4811 |
ptr->~T(); |
| 4812 |
const uint32_t index = static_cast<uint32_t>(pItemPtr - block.pItems); |
| 4813 |
pItemPtr->NextFreeIndex = block.FirstFreeIndex; |
| 4814 |
block.FirstFreeIndex = index; |
| 4815 |
return; |
| 4816 |
} |
| 4817 |
} |
| 4818 |
VMA_ASSERT(0 && "Pointer doesn't belong to this memory pool."); |
| 4819 |
} |
| 4820 |
|
| 4821 |
template<typename T> |
| 4822 |
typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock() |
| 4823 |
{ |
| 4824 |
const uint32_t newBlockCapacity = m_ItemBlocks.empty() ? |
| 4825 |
m_FirstBlockCapacity : m_ItemBlocks.back().Capacity * 3 / 2; |
| 4826 |
|
| 4827 |
const ItemBlock newBlock = |
| 4828 |
{ |
| 4829 |
vma_new_array(m_pAllocationCallbacks, Item, newBlockCapacity), |
| 4830 |
newBlockCapacity, |
| 4831 |
0 |
| 4832 |
}; |
| 4833 |
|
| 4834 |
m_ItemBlocks.push_back(newBlock); |
| 4835 |
|
| 4836 |
|
| 4837 |
for (uint32_t i = 0; i < newBlockCapacity - 1; ++i) |
| 4838 |
newBlock.pItems[i].NextFreeIndex = i + 1; |
| 4839 |
newBlock.pItems[newBlockCapacity - 1].NextFreeIndex = UINT32_MAX; |
| 4840 |
return m_ItemBlocks.back(); |
| 4841 |
} |
| 4842 |
#endif |
| 4843 |
#endif |
| 4844 |
|
| 4845 |
#ifndef _VMA_RAW_LIST |
| 4846 |
template<typename T> |
| 4847 |
struct VmaListItem |
| 4848 |
{ |
| 4849 |
VmaListItem* pPrev; |
| 4850 |
VmaListItem* pNext; |
| 4851 |
T Value; |
| 4852 |
}; |
| 4853 |
|
| 4854 |
|
| 4855 |
template<typename T> |
| 4856 |
class VmaRawList |
| 4857 |
{ |
| 4858 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaRawList) |
| 4859 |
public: |
| 4860 |
typedef VmaListItem<T> ItemType; |
| 4861 |
|
| 4862 |
VmaRawList(const VkAllocationCallbacks* pAllocationCallbacks); |
| 4863 |
|
| 4864 |
|
| 4865 |
~VmaRawList() = default; |
| 4866 |
|
| 4867 |
size_t GetCount() const { return m_Count; } |
| 4868 |
bool IsEmpty() const { return m_Count == 0; } |
| 4869 |
|
| 4870 |
ItemType* Front() { return m_pFront; } |
| 4871 |
ItemType* Back() { return m_pBack; } |
| 4872 |
const ItemType* Front() const { return m_pFront; } |
| 4873 |
const ItemType* Back() const { return m_pBack; } |
| 4874 |
|
| 4875 |
ItemType* PushFront(); |
| 4876 |
ItemType* PushBack(); |
| 4877 |
ItemType* PushFront(const T& value); |
| 4878 |
ItemType* PushBack(const T& value); |
| 4879 |
void PopFront(); |
| 4880 |
void PopBack(); |
| 4881 |
|
| 4882 |
|
| 4883 |
ItemType* InsertBefore(ItemType* pItem); |
| 4884 |
|
| 4885 |
ItemType* InsertAfter(ItemType* pItem); |
| 4886 |
ItemType* InsertBefore(ItemType* pItem, const T& value); |
| 4887 |
ItemType* InsertAfter(ItemType* pItem, const T& value); |
| 4888 |
|
| 4889 |
void Clear(); |
| 4890 |
void Remove(ItemType* pItem); |
| 4891 |
|
| 4892 |
private: |
| 4893 |
const VkAllocationCallbacks* const m_pAllocationCallbacks; |
| 4894 |
VmaPoolAllocator<ItemType> m_ItemAllocator; |
| 4895 |
ItemType* m_pFront; |
| 4896 |
ItemType* m_pBack; |
| 4897 |
size_t m_Count; |
| 4898 |
}; |
| 4899 |
|
| 4900 |
#ifndef _VMA_RAW_LIST_FUNCTIONS |
| 4901 |
template<typename T> |
| 4902 |
VmaRawList<T>::VmaRawList(const VkAllocationCallbacks* pAllocationCallbacks) |
| 4903 |
: m_pAllocationCallbacks(pAllocationCallbacks), |
| 4904 |
m_ItemAllocator(pAllocationCallbacks, 128), |
| 4905 |
m_pFront(VMA_NULL), |
| 4906 |
m_pBack(VMA_NULL), |
| 4907 |
m_Count(0) {} |
| 4908 |
|
| 4909 |
template<typename T> |
| 4910 |
VmaListItem<T>* VmaRawList<T>::PushFront() |
| 4911 |
{ |
| 4912 |
ItemType* const pNewItem = m_ItemAllocator.Alloc(); |
| 4913 |
pNewItem->pPrev = VMA_NULL; |
| 4914 |
if (IsEmpty()) |
| 4915 |
{ |
| 4916 |
pNewItem->pNext = VMA_NULL; |
| 4917 |
m_pFront = pNewItem; |
| 4918 |
m_pBack = pNewItem; |
| 4919 |
m_Count = 1; |
| 4920 |
} |
| 4921 |
else |
| 4922 |
{ |
| 4923 |
pNewItem->pNext = m_pFront; |
| 4924 |
m_pFront->pPrev = pNewItem; |
| 4925 |
m_pFront = pNewItem; |
| 4926 |
++m_Count; |
| 4927 |
} |
| 4928 |
return pNewItem; |
| 4929 |
} |
| 4930 |
|
| 4931 |
template<typename T> |
| 4932 |
VmaListItem<T>* VmaRawList<T>::PushBack() |
| 4933 |
{ |
| 4934 |
ItemType* const pNewItem = m_ItemAllocator.Alloc(); |
| 4935 |
pNewItem->pNext = VMA_NULL; |
| 4936 |
if(IsEmpty()) |
| 4937 |
{ |
| 4938 |
pNewItem->pPrev = VMA_NULL; |
| 4939 |
m_pFront = pNewItem; |
| 4940 |
m_pBack = pNewItem; |
| 4941 |
m_Count = 1; |
| 4942 |
} |
| 4943 |
else |
| 4944 |
{ |
| 4945 |
pNewItem->pPrev = m_pBack; |
| 4946 |
m_pBack->pNext = pNewItem; |
| 4947 |
m_pBack = pNewItem; |
| 4948 |
++m_Count; |
| 4949 |
} |
| 4950 |
return pNewItem; |
| 4951 |
} |
| 4952 |
|
| 4953 |
template<typename T> |
| 4954 |
VmaListItem<T>* VmaRawList<T>::PushFront(const T& value) |
| 4955 |
{ |
| 4956 |
ItemType* const pNewItem = PushFront(); |
| 4957 |
pNewItem->Value = value; |
| 4958 |
return pNewItem; |
| 4959 |
} |
| 4960 |
|
| 4961 |
template<typename T> |
| 4962 |
VmaListItem<T>* VmaRawList<T>::PushBack(const T& value) |
| 4963 |
{ |
| 4964 |
ItemType* const pNewItem = PushBack(); |
| 4965 |
pNewItem->Value = value; |
| 4966 |
return pNewItem; |
| 4967 |
} |
| 4968 |
|
| 4969 |
template<typename T> |
| 4970 |
void VmaRawList<T>::PopFront() |
| 4971 |
{ |
| 4972 |
VMA_HEAVY_ASSERT(m_Count > 0); |
| 4973 |
ItemType* const pFrontItem = m_pFront; |
| 4974 |
ItemType* const pNextItem = pFrontItem->pNext; |
| 4975 |
if (pNextItem != VMA_NULL) |
| 4976 |
{ |
| 4977 |
pNextItem->pPrev = VMA_NULL; |
| 4978 |
} |
| 4979 |
m_pFront = pNextItem; |
| 4980 |
m_ItemAllocator.Free(pFrontItem); |
| 4981 |
--m_Count; |
| 4982 |
} |
| 4983 |
|
| 4984 |
template<typename T> |
| 4985 |
void VmaRawList<T>::PopBack() |
| 4986 |
{ |
| 4987 |
VMA_HEAVY_ASSERT(m_Count > 0); |
| 4988 |
ItemType* const pBackItem = m_pBack; |
| 4989 |
ItemType* const pPrevItem = pBackItem->pPrev; |
| 4990 |
if(pPrevItem != VMA_NULL) |
| 4991 |
{ |
| 4992 |
pPrevItem->pNext = VMA_NULL; |
| 4993 |
} |
| 4994 |
m_pBack = pPrevItem; |
| 4995 |
m_ItemAllocator.Free(pBackItem); |
| 4996 |
--m_Count; |
| 4997 |
} |
| 4998 |
|
| 4999 |
template<typename T> |
| 5000 |
void VmaRawList<T>::Clear() |
| 5001 |
{ |
| 5002 |
if (IsEmpty() == false) |
| 5003 |
{ |
| 5004 |
ItemType* pItem = m_pBack; |
| 5005 |
while (pItem != VMA_NULL) |
| 5006 |
{ |
| 5007 |
ItemType* const pPrevItem = pItem->pPrev; |
| 5008 |
m_ItemAllocator.Free(pItem); |
| 5009 |
pItem = pPrevItem; |
| 5010 |
} |
| 5011 |
m_pFront = VMA_NULL; |
| 5012 |
m_pBack = VMA_NULL; |
| 5013 |
m_Count = 0; |
| 5014 |
} |
| 5015 |
} |
| 5016 |
|
| 5017 |
template<typename T> |
| 5018 |
void VmaRawList<T>::Remove(ItemType* pItem) |
| 5019 |
{ |
| 5020 |
VMA_HEAVY_ASSERT(pItem != VMA_NULL); |
| 5021 |
VMA_HEAVY_ASSERT(m_Count > 0); |
| 5022 |
|
| 5023 |
if(pItem->pPrev != VMA_NULL) |
| 5024 |
{ |
| 5025 |
pItem->pPrev->pNext = pItem->pNext; |
| 5026 |
} |
| 5027 |
else |
| 5028 |
{ |
| 5029 |
VMA_HEAVY_ASSERT(m_pFront == pItem); |
| 5030 |
m_pFront = pItem->pNext; |
| 5031 |
} |
| 5032 |
|
| 5033 |
if(pItem->pNext != VMA_NULL) |
| 5034 |
{ |
| 5035 |
pItem->pNext->pPrev = pItem->pPrev; |
| 5036 |
} |
| 5037 |
else |
| 5038 |
{ |
| 5039 |
VMA_HEAVY_ASSERT(m_pBack == pItem); |
| 5040 |
m_pBack = pItem->pPrev; |
| 5041 |
} |
| 5042 |
|
| 5043 |
m_ItemAllocator.Free(pItem); |
| 5044 |
--m_Count; |
| 5045 |
} |
| 5046 |
|
| 5047 |
template<typename T> |
| 5048 |
VmaListItem<T>* VmaRawList<T>::InsertBefore(ItemType* pItem) |
| 5049 |
{ |
| 5050 |
if(pItem != VMA_NULL) |
| 5051 |
{ |
| 5052 |
ItemType* const prevItem = pItem->pPrev; |
| 5053 |
ItemType* const newItem = m_ItemAllocator.Alloc(); |
| 5054 |
newItem->pPrev = prevItem; |
| 5055 |
newItem->pNext = pItem; |
| 5056 |
pItem->pPrev = newItem; |
| 5057 |
if(prevItem != VMA_NULL) |
| 5058 |
{ |
| 5059 |
prevItem->pNext = newItem; |
| 5060 |
} |
| 5061 |
else |
| 5062 |
{ |
| 5063 |
VMA_HEAVY_ASSERT(m_pFront == pItem); |
| 5064 |
m_pFront = newItem; |
| 5065 |
} |
| 5066 |
++m_Count; |
| 5067 |
return newItem; |
| 5068 |
} |
| 5069 |
else |
| 5070 |
return PushBack(); |
| 5071 |
} |
| 5072 |
|
| 5073 |
template<typename T> |
| 5074 |
VmaListItem<T>* VmaRawList<T>::InsertAfter(ItemType* pItem) |
| 5075 |
{ |
| 5076 |
if(pItem != VMA_NULL) |
| 5077 |
{ |
| 5078 |
ItemType* const nextItem = pItem->pNext; |
| 5079 |
ItemType* const newItem = m_ItemAllocator.Alloc(); |
| 5080 |
newItem->pNext = nextItem; |
| 5081 |
newItem->pPrev = pItem; |
| 5082 |
pItem->pNext = newItem; |
| 5083 |
if(nextItem != VMA_NULL) |
| 5084 |
{ |
| 5085 |
nextItem->pPrev = newItem; |
| 5086 |
} |
| 5087 |
else |
| 5088 |
{ |
| 5089 |
VMA_HEAVY_ASSERT(m_pBack == pItem); |
| 5090 |
m_pBack = newItem; |
| 5091 |
} |
| 5092 |
++m_Count; |
| 5093 |
return newItem; |
| 5094 |
} |
| 5095 |
else |
| 5096 |
return PushFront(); |
| 5097 |
} |
| 5098 |
|
| 5099 |
template<typename T> |
| 5100 |
VmaListItem<T>* VmaRawList<T>::InsertBefore(ItemType* pItem, const T& value) |
| 5101 |
{ |
| 5102 |
ItemType* const newItem = InsertBefore(pItem); |
| 5103 |
newItem->Value = value; |
| 5104 |
return newItem; |
| 5105 |
} |
| 5106 |
|
| 5107 |
template<typename T> |
| 5108 |
VmaListItem<T>* VmaRawList<T>::InsertAfter(ItemType* pItem, const T& value) |
| 5109 |
{ |
| 5110 |
ItemType* const newItem = InsertAfter(pItem); |
| 5111 |
newItem->Value = value; |
| 5112 |
return newItem; |
| 5113 |
} |
| 5114 |
#endif |
| 5115 |
#endif |
| 5116 |
|
| 5117 |
#ifndef _VMA_LIST |
| 5118 |
template<typename T, typename AllocatorT> |
| 5119 |
class VmaList |
| 5120 |
{ |
| 5121 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaList) |
| 5122 |
public: |
| 5123 |
class reverse_iterator; |
| 5124 |
class const_iterator; |
| 5125 |
class const_reverse_iterator; |
| 5126 |
|
| 5127 |
class iterator |
| 5128 |
{ |
| 5129 |
friend class const_iterator; |
| 5130 |
friend class VmaList<T, AllocatorT>; |
| 5131 |
public: |
| 5132 |
iterator() : m_pList(VMA_NULL), m_pItem(VMA_NULL) {} |
| 5133 |
iterator(const reverse_iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5134 |
|
| 5135 |
T& operator*() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return m_pItem->Value; } |
| 5136 |
T* operator->() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return &m_pItem->Value; } |
| 5137 |
|
| 5138 |
bool operator==(const iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem == rhs.m_pItem; } |
| 5139 |
bool operator!=(const iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem != rhs.m_pItem; } |
| 5140 |
|
| 5141 |
iterator operator++(int) { iterator result = *this; ++*this; return result; } |
| 5142 |
iterator operator--(int) { iterator result = *this; --*this; return result; } |
| 5143 |
|
| 5144 |
iterator& operator++() { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); m_pItem = m_pItem->pNext; return *this; } |
| 5145 |
iterator& operator--(); |
| 5146 |
|
| 5147 |
private: |
| 5148 |
VmaRawList<T>* m_pList; |
| 5149 |
VmaListItem<T>* m_pItem; |
| 5150 |
|
| 5151 |
iterator(VmaRawList<T>* pList, VmaListItem<T>* pItem) : m_pList(pList), m_pItem(pItem) {} |
| 5152 |
}; |
| 5153 |
class reverse_iterator |
| 5154 |
{ |
| 5155 |
friend class const_reverse_iterator; |
| 5156 |
friend class VmaList<T, AllocatorT>; |
| 5157 |
public: |
| 5158 |
reverse_iterator() : m_pList(VMA_NULL), m_pItem(VMA_NULL) {} |
| 5159 |
reverse_iterator(const iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5160 |
|
| 5161 |
T& operator*() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return m_pItem->Value; } |
| 5162 |
T* operator->() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return &m_pItem->Value; } |
| 5163 |
|
| 5164 |
bool operator==(const reverse_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem == rhs.m_pItem; } |
| 5165 |
bool operator!=(const reverse_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem != rhs.m_pItem; } |
| 5166 |
|
| 5167 |
reverse_iterator operator++(int) { reverse_iterator result = *this; ++* this; return result; } |
| 5168 |
reverse_iterator operator--(int) { reverse_iterator result = *this; --* this; return result; } |
| 5169 |
|
| 5170 |
reverse_iterator& operator++() { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); m_pItem = m_pItem->pPrev; return *this; } |
| 5171 |
reverse_iterator& operator--(); |
| 5172 |
|
| 5173 |
private: |
| 5174 |
VmaRawList<T>* m_pList; |
| 5175 |
VmaListItem<T>* m_pItem; |
| 5176 |
|
| 5177 |
reverse_iterator(VmaRawList<T>* pList, VmaListItem<T>* pItem) : m_pList(pList), m_pItem(pItem) {} |
| 5178 |
}; |
| 5179 |
class const_iterator |
| 5180 |
{ |
| 5181 |
friend class VmaList<T, AllocatorT>; |
| 5182 |
public: |
| 5183 |
const_iterator() : m_pList(VMA_NULL), m_pItem(VMA_NULL) {} |
| 5184 |
const_iterator(const iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5185 |
const_iterator(const reverse_iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5186 |
|
| 5187 |
iterator drop_const() { return { const_cast<VmaRawList<T>*>(m_pList), const_cast<VmaListItem<T>*>(m_pItem) }; } |
| 5188 |
|
| 5189 |
const T& operator*() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return m_pItem->Value; } |
| 5190 |
const T* operator->() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return &m_pItem->Value; } |
| 5191 |
|
| 5192 |
bool operator==(const const_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem == rhs.m_pItem; } |
| 5193 |
bool operator!=(const const_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem != rhs.m_pItem; } |
| 5194 |
|
| 5195 |
const_iterator operator++(int) { const_iterator result = *this; ++* this; return result; } |
| 5196 |
const_iterator operator--(int) { const_iterator result = *this; --* this; return result; } |
| 5197 |
|
| 5198 |
const_iterator& operator++() { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); m_pItem = m_pItem->pNext; return *this; } |
| 5199 |
const_iterator& operator--(); |
| 5200 |
|
| 5201 |
private: |
| 5202 |
const VmaRawList<T>* m_pList; |
| 5203 |
const VmaListItem<T>* m_pItem; |
| 5204 |
|
| 5205 |
const_iterator(const VmaRawList<T>* pList, const VmaListItem<T>* pItem) : m_pList(pList), m_pItem(pItem) {} |
| 5206 |
}; |
| 5207 |
class const_reverse_iterator |
| 5208 |
{ |
| 5209 |
friend class VmaList<T, AllocatorT>; |
| 5210 |
public: |
| 5211 |
const_reverse_iterator() : m_pList(VMA_NULL), m_pItem(VMA_NULL) {} |
| 5212 |
const_reverse_iterator(const reverse_iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5213 |
const_reverse_iterator(const iterator& src) : m_pList(src.m_pList), m_pItem(src.m_pItem) {} |
| 5214 |
|
| 5215 |
reverse_iterator drop_const() { return { const_cast<VmaRawList<T>*>(m_pList), const_cast<VmaListItem<T>*>(m_pItem) }; } |
| 5216 |
|
| 5217 |
const T& operator*() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return m_pItem->Value; } |
| 5218 |
const T* operator->() const { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); return &m_pItem->Value; } |
| 5219 |
|
| 5220 |
bool operator==(const const_reverse_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem == rhs.m_pItem; } |
| 5221 |
bool operator!=(const const_reverse_iterator& rhs) const { VMA_HEAVY_ASSERT(m_pList == rhs.m_pList); return m_pItem != rhs.m_pItem; } |
| 5222 |
|
| 5223 |
const_reverse_iterator operator++(int) { const_reverse_iterator result = *this; ++* this; return result; } |
| 5224 |
const_reverse_iterator operator--(int) { const_reverse_iterator result = *this; --* this; return result; } |
| 5225 |
|
| 5226 |
const_reverse_iterator& operator++() { VMA_HEAVY_ASSERT(m_pItem != VMA_NULL); m_pItem = m_pItem->pPrev; return *this; } |
| 5227 |
const_reverse_iterator& operator--(); |
| 5228 |
|
| 5229 |
private: |
| 5230 |
const VmaRawList<T>* m_pList; |
| 5231 |
const VmaListItem<T>* m_pItem; |
| 5232 |
|
| 5233 |
const_reverse_iterator(const VmaRawList<T>* pList, const VmaListItem<T>* pItem) : m_pList(pList), m_pItem(pItem) {} |
| 5234 |
}; |
| 5235 |
|
| 5236 |
VmaList(const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) {} |
| 5237 |
|
| 5238 |
bool empty() const { return m_RawList.IsEmpty(); } |
| 5239 |
size_t size() const { return m_RawList.GetCount(); } |
| 5240 |
|
| 5241 |
iterator begin() { return iterator(&m_RawList, m_RawList.Front()); } |
| 5242 |
iterator end() { return iterator(&m_RawList, VMA_NULL); } |
| 5243 |
|
| 5244 |
const_iterator cbegin() const { return const_iterator(&m_RawList, m_RawList.Front()); } |
| 5245 |
const_iterator cend() const { return const_iterator(&m_RawList, VMA_NULL); } |
| 5246 |
|
| 5247 |
const_iterator begin() const { return cbegin(); } |
| 5248 |
const_iterator end() const { return cend(); } |
| 5249 |
|
| 5250 |
reverse_iterator rbegin() { return reverse_iterator(&m_RawList, m_RawList.Back()); } |
| 5251 |
reverse_iterator rend() { return reverse_iterator(&m_RawList, VMA_NULL); } |
| 5252 |
|
| 5253 |
const_reverse_iterator crbegin() const { return const_reverse_iterator(&m_RawList, m_RawList.Back()); } |
| 5254 |
const_reverse_iterator crend() const { return const_reverse_iterator(&m_RawList, VMA_NULL); } |
| 5255 |
|
| 5256 |
const_reverse_iterator rbegin() const { return crbegin(); } |
| 5257 |
const_reverse_iterator rend() const { return crend(); } |
| 5258 |
|
| 5259 |
void push_back(const T& value) { m_RawList.PushBack(value); } |
| 5260 |
iterator insert(iterator it, const T& value) { return iterator(&m_RawList, m_RawList.InsertBefore(it.m_pItem, value)); } |
| 5261 |
|
| 5262 |
void clear() { m_RawList.Clear(); } |
| 5263 |
void erase(iterator it) { m_RawList.Remove(it.m_pItem); } |
| 5264 |
|
| 5265 |
private: |
| 5266 |
VmaRawList<T> m_RawList; |
| 5267 |
}; |
| 5268 |
|
| 5269 |
#ifndef _VMA_LIST_FUNCTIONS |
| 5270 |
template<typename T, typename AllocatorT> |
| 5271 |
typename VmaList<T, AllocatorT>::iterator& VmaList<T, AllocatorT>::iterator::operator--() |
| 5272 |
{ |
| 5273 |
if (m_pItem != VMA_NULL) |
| 5274 |
{ |
| 5275 |
m_pItem = m_pItem->pPrev; |
| 5276 |
} |
| 5277 |
else |
| 5278 |
{ |
| 5279 |
VMA_HEAVY_ASSERT(!m_pList->IsEmpty()); |
| 5280 |
m_pItem = m_pList->Back(); |
| 5281 |
} |
| 5282 |
return *this; |
| 5283 |
} |
| 5284 |
|
| 5285 |
template<typename T, typename AllocatorT> |
| 5286 |
typename VmaList<T, AllocatorT>::reverse_iterator& VmaList<T, AllocatorT>::reverse_iterator::operator--() |
| 5287 |
{ |
| 5288 |
if (m_pItem != VMA_NULL) |
| 5289 |
{ |
| 5290 |
m_pItem = m_pItem->pNext; |
| 5291 |
} |
| 5292 |
else |
| 5293 |
{ |
| 5294 |
VMA_HEAVY_ASSERT(!m_pList->IsEmpty()); |
| 5295 |
m_pItem = m_pList->Front(); |
| 5296 |
} |
| 5297 |
return *this; |
| 5298 |
} |
| 5299 |
|
| 5300 |
template<typename T, typename AllocatorT> |
| 5301 |
typename VmaList<T, AllocatorT>::const_iterator& VmaList<T, AllocatorT>::const_iterator::operator--() |
| 5302 |
{ |
| 5303 |
if (m_pItem != VMA_NULL) |
| 5304 |
{ |
| 5305 |
m_pItem = m_pItem->pPrev; |
| 5306 |
} |
| 5307 |
else |
| 5308 |
{ |
| 5309 |
VMA_HEAVY_ASSERT(!m_pList->IsEmpty()); |
| 5310 |
m_pItem = m_pList->Back(); |
| 5311 |
} |
| 5312 |
return *this; |
| 5313 |
} |
| 5314 |
|
| 5315 |
template<typename T, typename AllocatorT> |
| 5316 |
typename VmaList<T, AllocatorT>::const_reverse_iterator& VmaList<T, AllocatorT>::const_reverse_iterator::operator--() |
| 5317 |
{ |
| 5318 |
if (m_pItem != VMA_NULL) |
| 5319 |
{ |
| 5320 |
m_pItem = m_pItem->pNext; |
| 5321 |
} |
| 5322 |
else |
| 5323 |
{ |
| 5324 |
VMA_HEAVY_ASSERT(!m_pList->IsEmpty()); |
| 5325 |
m_pItem = m_pList->Back(); |
| 5326 |
} |
| 5327 |
return *this; |
| 5328 |
} |
| 5329 |
#endif |
| 5330 |
#endif |
| 5331 |
|
| 5332 |
#ifndef _VMA_INTRUSIVE_LINKED_LIST |
| 5333 |
|
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
|
| 5339 |
|
| 5340 |
|
| 5341 |
|
| 5342 |
|
| 5343 |
|
| 5344 |
template<typename ItemTypeTraits> |
| 5345 |
class VmaIntrusiveLinkedList |
| 5346 |
{ |
| 5347 |
public: |
| 5348 |
typedef typename ItemTypeTraits::ItemType ItemType; |
| 5349 |
static ItemType* GetPrev(const ItemType* item) { return ItemTypeTraits::GetPrev(item); } |
| 5350 |
static ItemType* GetNext(const ItemType* item) { return ItemTypeTraits::GetNext(item); } |
| 5351 |
|
| 5352 |
|
| 5353 |
VmaIntrusiveLinkedList() = default; |
| 5354 |
VmaIntrusiveLinkedList(VmaIntrusiveLinkedList && src); |
| 5355 |
VmaIntrusiveLinkedList(const VmaIntrusiveLinkedList&) = delete; |
| 5356 |
VmaIntrusiveLinkedList& operator=(VmaIntrusiveLinkedList&& src); |
| 5357 |
VmaIntrusiveLinkedList& operator=(const VmaIntrusiveLinkedList&) = delete; |
| 5358 |
~VmaIntrusiveLinkedList() { VMA_HEAVY_ASSERT(IsEmpty()); } |
| 5359 |
|
| 5360 |
size_t GetCount() const { return m_Count; } |
| 5361 |
bool IsEmpty() const { return m_Count == 0; } |
| 5362 |
ItemType* Front() { return m_Front; } |
| 5363 |
ItemType* Back() { return m_Back; } |
| 5364 |
const ItemType* Front() const { return m_Front; } |
| 5365 |
const ItemType* Back() const { return m_Back; } |
| 5366 |
|
| 5367 |
void PushBack(ItemType* item); |
| 5368 |
void PushFront(ItemType* item); |
| 5369 |
ItemType* PopBack(); |
| 5370 |
ItemType* PopFront(); |
| 5371 |
|
| 5372 |
|
| 5373 |
void InsertBefore(ItemType* existingItem, ItemType* newItem); |
| 5374 |
|
| 5375 |
void InsertAfter(ItemType* existingItem, ItemType* newItem); |
| 5376 |
void Remove(ItemType* item); |
| 5377 |
void RemoveAll(); |
| 5378 |
|
| 5379 |
private: |
| 5380 |
ItemType* m_Front = VMA_NULL; |
| 5381 |
ItemType* m_Back = VMA_NULL; |
| 5382 |
size_t m_Count = 0; |
| 5383 |
}; |
| 5384 |
|
| 5385 |
#ifndef _VMA_INTRUSIVE_LINKED_LIST_FUNCTIONS |
| 5386 |
template<typename ItemTypeTraits> |
| 5387 |
VmaIntrusiveLinkedList<ItemTypeTraits>::VmaIntrusiveLinkedList(VmaIntrusiveLinkedList&& src) |
| 5388 |
: m_Front(src.m_Front), m_Back(src.m_Back), m_Count(src.m_Count) |
| 5389 |
{ |
| 5390 |
src.m_Front = src.m_Back = VMA_NULL; |
| 5391 |
src.m_Count = 0; |
| 5392 |
} |
| 5393 |
|
| 5394 |
template<typename ItemTypeTraits> |
| 5395 |
VmaIntrusiveLinkedList<ItemTypeTraits>& VmaIntrusiveLinkedList<ItemTypeTraits>::operator=(VmaIntrusiveLinkedList&& src) |
| 5396 |
{ |
| 5397 |
if (&src != this) |
| 5398 |
{ |
| 5399 |
VMA_HEAVY_ASSERT(IsEmpty()); |
| 5400 |
m_Front = src.m_Front; |
| 5401 |
m_Back = src.m_Back; |
| 5402 |
m_Count = src.m_Count; |
| 5403 |
src.m_Front = src.m_Back = VMA_NULL; |
| 5404 |
src.m_Count = 0; |
| 5405 |
} |
| 5406 |
return *this; |
| 5407 |
} |
| 5408 |
|
| 5409 |
template<typename ItemTypeTraits> |
| 5410 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::PushBack(ItemType* item) |
| 5411 |
{ |
| 5412 |
VMA_HEAVY_ASSERT(ItemTypeTraits::GetPrev(item) == VMA_NULL && ItemTypeTraits::GetNext(item) == VMA_NULL); |
| 5413 |
if (IsEmpty()) |
| 5414 |
{ |
| 5415 |
m_Front = item; |
| 5416 |
m_Back = item; |
| 5417 |
m_Count = 1; |
| 5418 |
} |
| 5419 |
else |
| 5420 |
{ |
| 5421 |
ItemTypeTraits::AccessPrev(item) = m_Back; |
| 5422 |
ItemTypeTraits::AccessNext(m_Back) = item; |
| 5423 |
m_Back = item; |
| 5424 |
++m_Count; |
| 5425 |
} |
| 5426 |
} |
| 5427 |
|
| 5428 |
template<typename ItemTypeTraits> |
| 5429 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::PushFront(ItemType* item) |
| 5430 |
{ |
| 5431 |
VMA_HEAVY_ASSERT(ItemTypeTraits::GetPrev(item) == VMA_NULL && ItemTypeTraits::GetNext(item) == VMA_NULL); |
| 5432 |
if (IsEmpty()) |
| 5433 |
{ |
| 5434 |
m_Front = item; |
| 5435 |
m_Back = item; |
| 5436 |
m_Count = 1; |
| 5437 |
} |
| 5438 |
else |
| 5439 |
{ |
| 5440 |
ItemTypeTraits::AccessNext(item) = m_Front; |
| 5441 |
ItemTypeTraits::AccessPrev(m_Front) = item; |
| 5442 |
m_Front = item; |
| 5443 |
++m_Count; |
| 5444 |
} |
| 5445 |
} |
| 5446 |
|
| 5447 |
template<typename ItemTypeTraits> |
| 5448 |
typename VmaIntrusiveLinkedList<ItemTypeTraits>::ItemType* VmaIntrusiveLinkedList<ItemTypeTraits>::PopBack() |
| 5449 |
{ |
| 5450 |
VMA_HEAVY_ASSERT(m_Count > 0); |
| 5451 |
ItemType* const backItem = m_Back; |
| 5452 |
ItemType* const prevItem = ItemTypeTraits::GetPrev(backItem); |
| 5453 |
if (prevItem != VMA_NULL) |
| 5454 |
{ |
| 5455 |
ItemTypeTraits::AccessNext(prevItem) = VMA_NULL; |
| 5456 |
} |
| 5457 |
m_Back = prevItem; |
| 5458 |
--m_Count; |
| 5459 |
ItemTypeTraits::AccessPrev(backItem) = VMA_NULL; |
| 5460 |
ItemTypeTraits::AccessNext(backItem) = VMA_NULL; |
| 5461 |
return backItem; |
| 5462 |
} |
| 5463 |
|
| 5464 |
template<typename ItemTypeTraits> |
| 5465 |
typename VmaIntrusiveLinkedList<ItemTypeTraits>::ItemType* VmaIntrusiveLinkedList<ItemTypeTraits>::PopFront() |
| 5466 |
{ |
| 5467 |
VMA_HEAVY_ASSERT(m_Count > 0); |
| 5468 |
ItemType* const frontItem = m_Front; |
| 5469 |
ItemType* const nextItem = ItemTypeTraits::GetNext(frontItem); |
| 5470 |
if (nextItem != VMA_NULL) |
| 5471 |
{ |
| 5472 |
ItemTypeTraits::AccessPrev(nextItem) = VMA_NULL; |
| 5473 |
} |
| 5474 |
m_Front = nextItem; |
| 5475 |
--m_Count; |
| 5476 |
ItemTypeTraits::AccessPrev(frontItem) = VMA_NULL; |
| 5477 |
ItemTypeTraits::AccessNext(frontItem) = VMA_NULL; |
| 5478 |
return frontItem; |
| 5479 |
} |
| 5480 |
|
| 5481 |
template<typename ItemTypeTraits> |
| 5482 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::InsertBefore(ItemType* existingItem, ItemType* newItem) |
| 5483 |
{ |
| 5484 |
VMA_HEAVY_ASSERT(newItem != VMA_NULL && ItemTypeTraits::GetPrev(newItem) == VMA_NULL && ItemTypeTraits::GetNext(newItem) == VMA_NULL); |
| 5485 |
if (existingItem != VMA_NULL) |
| 5486 |
{ |
| 5487 |
ItemType* const prevItem = ItemTypeTraits::GetPrev(existingItem); |
| 5488 |
ItemTypeTraits::AccessPrev(newItem) = prevItem; |
| 5489 |
ItemTypeTraits::AccessNext(newItem) = existingItem; |
| 5490 |
ItemTypeTraits::AccessPrev(existingItem) = newItem; |
| 5491 |
if (prevItem != VMA_NULL) |
| 5492 |
{ |
| 5493 |
ItemTypeTraits::AccessNext(prevItem) = newItem; |
| 5494 |
} |
| 5495 |
else |
| 5496 |
{ |
| 5497 |
VMA_HEAVY_ASSERT(m_Front == existingItem); |
| 5498 |
m_Front = newItem; |
| 5499 |
} |
| 5500 |
++m_Count; |
| 5501 |
} |
| 5502 |
else |
| 5503 |
PushBack(newItem); |
| 5504 |
} |
| 5505 |
|
| 5506 |
template<typename ItemTypeTraits> |
| 5507 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::InsertAfter(ItemType* existingItem, ItemType* newItem) |
| 5508 |
{ |
| 5509 |
VMA_HEAVY_ASSERT(newItem != VMA_NULL && ItemTypeTraits::GetPrev(newItem) == VMA_NULL && ItemTypeTraits::GetNext(newItem) == VMA_NULL); |
| 5510 |
if (existingItem != VMA_NULL) |
| 5511 |
{ |
| 5512 |
ItemType* const nextItem = ItemTypeTraits::GetNext(existingItem); |
| 5513 |
ItemTypeTraits::AccessNext(newItem) = nextItem; |
| 5514 |
ItemTypeTraits::AccessPrev(newItem) = existingItem; |
| 5515 |
ItemTypeTraits::AccessNext(existingItem) = newItem; |
| 5516 |
if (nextItem != VMA_NULL) |
| 5517 |
{ |
| 5518 |
ItemTypeTraits::AccessPrev(nextItem) = newItem; |
| 5519 |
} |
| 5520 |
else |
| 5521 |
{ |
| 5522 |
VMA_HEAVY_ASSERT(m_Back == existingItem); |
| 5523 |
m_Back = newItem; |
| 5524 |
} |
| 5525 |
++m_Count; |
| 5526 |
} |
| 5527 |
else |
| 5528 |
return PushFront(newItem); |
| 5529 |
} |
| 5530 |
|
| 5531 |
template<typename ItemTypeTraits> |
| 5532 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::Remove(ItemType* item) |
| 5533 |
{ |
| 5534 |
VMA_HEAVY_ASSERT(item != VMA_NULL && m_Count > 0); |
| 5535 |
if (ItemTypeTraits::GetPrev(item) != VMA_NULL) |
| 5536 |
{ |
| 5537 |
ItemTypeTraits::AccessNext(ItemTypeTraits::AccessPrev(item)) = ItemTypeTraits::GetNext(item); |
| 5538 |
} |
| 5539 |
else |
| 5540 |
{ |
| 5541 |
VMA_HEAVY_ASSERT(m_Front == item); |
| 5542 |
m_Front = ItemTypeTraits::GetNext(item); |
| 5543 |
} |
| 5544 |
|
| 5545 |
if (ItemTypeTraits::GetNext(item) != VMA_NULL) |
| 5546 |
{ |
| 5547 |
ItemTypeTraits::AccessPrev(ItemTypeTraits::AccessNext(item)) = ItemTypeTraits::GetPrev(item); |
| 5548 |
} |
| 5549 |
else |
| 5550 |
{ |
| 5551 |
VMA_HEAVY_ASSERT(m_Back == item); |
| 5552 |
m_Back = ItemTypeTraits::GetPrev(item); |
| 5553 |
} |
| 5554 |
ItemTypeTraits::AccessPrev(item) = VMA_NULL; |
| 5555 |
ItemTypeTraits::AccessNext(item) = VMA_NULL; |
| 5556 |
--m_Count; |
| 5557 |
} |
| 5558 |
|
| 5559 |
template<typename ItemTypeTraits> |
| 5560 |
void VmaIntrusiveLinkedList<ItemTypeTraits>::RemoveAll() |
| 5561 |
{ |
| 5562 |
if (!IsEmpty()) |
| 5563 |
{ |
| 5564 |
ItemType* item = m_Back; |
| 5565 |
while (item != VMA_NULL) |
| 5566 |
{ |
| 5567 |
ItemType* const prevItem = ItemTypeTraits::AccessPrev(item); |
| 5568 |
ItemTypeTraits::AccessPrev(item) = VMA_NULL; |
| 5569 |
ItemTypeTraits::AccessNext(item) = VMA_NULL; |
| 5570 |
item = prevItem; |
| 5571 |
} |
| 5572 |
m_Front = VMA_NULL; |
| 5573 |
m_Back = VMA_NULL; |
| 5574 |
m_Count = 0; |
| 5575 |
} |
| 5576 |
} |
| 5577 |
#endif |
| 5578 |
#endif |
| 5579 |
|
| 5580 |
#if !defined(_VMA_STRING_BUILDER) && VMA_STATS_STRING_ENABLED |
| 5581 |
class VmaStringBuilder |
| 5582 |
{ |
| 5583 |
public: |
| 5584 |
VmaStringBuilder(const VkAllocationCallbacks* allocationCallbacks) : m_Data(VmaStlAllocator<char>(allocationCallbacks)) {} |
| 5585 |
~VmaStringBuilder() = default; |
| 5586 |
|
| 5587 |
size_t GetLength() const { return m_Data.size(); } |
| 5588 |
const char* GetData() const { return m_Data.data(); } |
| 5589 |
void AddNewLine() { Add('\n'); } |
| 5590 |
void Add(char ch) { m_Data.push_back(ch); } |
| 5591 |
|
| 5592 |
void Add(const char* pStr); |
| 5593 |
void AddNumber(uint32_t num); |
| 5594 |
void AddNumber(uint64_t num); |
| 5595 |
void AddPointer(const void* ptr); |
| 5596 |
|
| 5597 |
private: |
| 5598 |
VmaVector<char, VmaStlAllocator<char>> m_Data; |
| 5599 |
}; |
| 5600 |
|
| 5601 |
#ifndef _VMA_STRING_BUILDER_FUNCTIONS |
| 5602 |
void VmaStringBuilder::Add(const char* pStr) |
| 5603 |
{ |
| 5604 |
const size_t strLen = strlen(pStr); |
| 5605 |
if (strLen > 0) |
| 5606 |
{ |
| 5607 |
const size_t oldCount = m_Data.size(); |
| 5608 |
m_Data.resize(oldCount + strLen); |
| 5609 |
memcpy(m_Data.data() + oldCount, pStr, strLen); |
| 5610 |
} |
| 5611 |
} |
| 5612 |
|
| 5613 |
void VmaStringBuilder::AddNumber(uint32_t num) |
| 5614 |
{ |
| 5615 |
char buf[11]; |
| 5616 |
buf[10] = '\0'; |
| 5617 |
char* p = &buf[10]; |
| 5618 |
do |
| 5619 |
{ |
| 5620 |
*--p = '0' + (char)(num % 10); |
| 5621 |
num /= 10; |
| 5622 |
} while (num); |
| 5623 |
Add(p); |
| 5624 |
} |
| 5625 |
|
| 5626 |
void VmaStringBuilder::AddNumber(uint64_t num) |
| 5627 |
{ |
| 5628 |
char buf[21]; |
| 5629 |
buf[20] = '\0'; |
| 5630 |
char* p = &buf[20]; |
| 5631 |
do |
| 5632 |
{ |
| 5633 |
*--p = '0' + (char)(num % 10); |
| 5634 |
num /= 10; |
| 5635 |
} while (num); |
| 5636 |
Add(p); |
| 5637 |
} |
| 5638 |
|
| 5639 |
void VmaStringBuilder::AddPointer(const void* ptr) |
| 5640 |
{ |
| 5641 |
char buf[21]; |
| 5642 |
VmaPtrToStr(buf, sizeof(buf), ptr); |
| 5643 |
Add(buf); |
| 5644 |
} |
| 5645 |
#endif |
| 5646 |
#endif |
| 5647 |
|
| 5648 |
#if !defined(_VMA_JSON_WRITER) && VMA_STATS_STRING_ENABLED |
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
class VmaJsonWriter |
| 5654 |
{ |
| 5655 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaJsonWriter) |
| 5656 |
public: |
| 5657 |
|
| 5658 |
VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb); |
| 5659 |
~VmaJsonWriter(); |
| 5660 |
|
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
void BeginObject(bool singleLine = false); |
| 5666 |
|
| 5667 |
void EndObject(); |
| 5668 |
|
| 5669 |
|
| 5670 |
|
| 5671 |
void BeginArray(bool singleLine = false); |
| 5672 |
|
| 5673 |
void EndArray(); |
| 5674 |
|
| 5675 |
|
| 5676 |
|
| 5677 |
void WriteString(const char* pStr); |
| 5678 |
|
| 5679 |
|
| 5680 |
|
| 5681 |
|
| 5682 |
|
| 5683 |
void BeginString(const char* pStr = VMA_NULL); |
| 5684 |
|
| 5685 |
void ContinueString(const char* pStr); |
| 5686 |
|
| 5687 |
void ContinueString(uint32_t n); |
| 5688 |
void ContinueString(uint64_t n); |
| 5689 |
|
| 5690 |
|
| 5691 |
void ContinueString_Pointer(const void* ptr); |
| 5692 |
|
| 5693 |
void EndString(const char* pStr = VMA_NULL); |
| 5694 |
|
| 5695 |
|
| 5696 |
void WriteNumber(uint32_t n); |
| 5697 |
void WriteNumber(uint64_t n); |
| 5698 |
|
| 5699 |
void WriteBool(bool b); |
| 5700 |
|
| 5701 |
void WriteNull(); |
| 5702 |
|
| 5703 |
private: |
| 5704 |
enum COLLECTION_TYPE |
| 5705 |
{ |
| 5706 |
COLLECTION_TYPE_OBJECT, |
| 5707 |
COLLECTION_TYPE_ARRAY, |
| 5708 |
}; |
| 5709 |
struct StackItem |
| 5710 |
{ |
| 5711 |
COLLECTION_TYPE type; |
| 5712 |
uint32_t valueCount; |
| 5713 |
bool singleLineMode; |
| 5714 |
}; |
| 5715 |
|
| 5716 |
static const char* const INDENT; |
| 5717 |
|
| 5718 |
VmaStringBuilder& m_SB; |
| 5719 |
VmaVector< StackItem, VmaStlAllocator<StackItem> > m_Stack; |
| 5720 |
bool m_InsideString; |
| 5721 |
|
| 5722 |
void BeginValue(bool isString); |
| 5723 |
void WriteIndent(bool oneLess = false); |
| 5724 |
}; |
| 5725 |
const char* const VmaJsonWriter::INDENT = " "; |
| 5726 |
|
| 5727 |
#ifndef _VMA_JSON_WRITER_FUNCTIONS |
| 5728 |
VmaJsonWriter::VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb) |
| 5729 |
: m_SB(sb), |
| 5730 |
m_Stack(VmaStlAllocator<StackItem>(pAllocationCallbacks)), |
| 5731 |
m_InsideString(false) {} |
| 5732 |
|
| 5733 |
VmaJsonWriter::~VmaJsonWriter() |
| 5734 |
{ |
| 5735 |
VMA_ASSERT(!m_InsideString); |
| 5736 |
VMA_ASSERT(m_Stack.empty()); |
| 5737 |
} |
| 5738 |
|
| 5739 |
void VmaJsonWriter::BeginObject(bool singleLine) |
| 5740 |
{ |
| 5741 |
VMA_ASSERT(!m_InsideString); |
| 5742 |
|
| 5743 |
BeginValue(false); |
| 5744 |
m_SB.Add('{'); |
| 5745 |
|
| 5746 |
StackItem item; |
| 5747 |
item.type = COLLECTION_TYPE_OBJECT; |
| 5748 |
item.valueCount = 0; |
| 5749 |
item.singleLineMode = singleLine; |
| 5750 |
m_Stack.push_back(item); |
| 5751 |
} |
| 5752 |
|
| 5753 |
void VmaJsonWriter::EndObject() |
| 5754 |
{ |
| 5755 |
VMA_ASSERT(!m_InsideString); |
| 5756 |
|
| 5757 |
WriteIndent(true); |
| 5758 |
m_SB.Add('}'); |
| 5759 |
|
| 5760 |
VMA_ASSERT(!m_Stack.empty() && m_Stack.back().type == COLLECTION_TYPE_OBJECT); |
| 5761 |
m_Stack.pop_back(); |
| 5762 |
} |
| 5763 |
|
| 5764 |
void VmaJsonWriter::BeginArray(bool singleLine) |
| 5765 |
{ |
| 5766 |
VMA_ASSERT(!m_InsideString); |
| 5767 |
|
| 5768 |
BeginValue(false); |
| 5769 |
m_SB.Add('['); |
| 5770 |
|
| 5771 |
StackItem item; |
| 5772 |
item.type = COLLECTION_TYPE_ARRAY; |
| 5773 |
item.valueCount = 0; |
| 5774 |
item.singleLineMode = singleLine; |
| 5775 |
m_Stack.push_back(item); |
| 5776 |
} |
| 5777 |
|
| 5778 |
void VmaJsonWriter::EndArray() |
| 5779 |
{ |
| 5780 |
VMA_ASSERT(!m_InsideString); |
| 5781 |
|
| 5782 |
WriteIndent(true); |
| 5783 |
m_SB.Add(']'); |
| 5784 |
|
| 5785 |
VMA_ASSERT(!m_Stack.empty() && m_Stack.back().type == COLLECTION_TYPE_ARRAY); |
| 5786 |
m_Stack.pop_back(); |
| 5787 |
} |
| 5788 |
|
| 5789 |
void VmaJsonWriter::WriteString(const char* pStr) |
| 5790 |
{ |
| 5791 |
BeginString(pStr); |
| 5792 |
EndString(); |
| 5793 |
} |
| 5794 |
|
| 5795 |
void VmaJsonWriter::BeginString(const char* pStr) |
| 5796 |
{ |
| 5797 |
VMA_ASSERT(!m_InsideString); |
| 5798 |
|
| 5799 |
BeginValue(true); |
| 5800 |
m_SB.Add('"'); |
| 5801 |
m_InsideString = true; |
| 5802 |
if (pStr != VMA_NULL && pStr[0] != '\0') |
| 5803 |
{ |
| 5804 |
ContinueString(pStr); |
| 5805 |
} |
| 5806 |
} |
| 5807 |
|
| 5808 |
void VmaJsonWriter::ContinueString(const char* pStr) |
| 5809 |
{ |
| 5810 |
VMA_ASSERT(m_InsideString); |
| 5811 |
|
| 5812 |
const size_t strLen = strlen(pStr); |
| 5813 |
for (size_t i = 0; i < strLen; ++i) |
| 5814 |
{ |
| 5815 |
char ch = pStr[i]; |
| 5816 |
if (ch == '\\') |
| 5817 |
{ |
| 5818 |
m_SB.Add("\\\\"); |
| 5819 |
} |
| 5820 |
else if (ch == '"') |
| 5821 |
{ |
| 5822 |
m_SB.Add("\\\""); |
| 5823 |
} |
| 5824 |
else if ((uint8_t)ch >= 32) |
| 5825 |
{ |
| 5826 |
m_SB.Add(ch); |
| 5827 |
} |
| 5828 |
else switch (ch) |
| 5829 |
{ |
| 5830 |
case '\b': |
| 5831 |
m_SB.Add("\\b"); |
| 5832 |
break; |
| 5833 |
case '\f': |
| 5834 |
m_SB.Add("\\f"); |
| 5835 |
break; |
| 5836 |
case '\n': |
| 5837 |
m_SB.Add("\\n"); |
| 5838 |
break; |
| 5839 |
case '\r': |
| 5840 |
m_SB.Add("\\r"); |
| 5841 |
break; |
| 5842 |
case '\t': |
| 5843 |
m_SB.Add("\\t"); |
| 5844 |
break; |
| 5845 |
default: |
| 5846 |
VMA_ASSERT(0 && "Character not currently supported."); |
| 5847 |
} |
| 5848 |
} |
| 5849 |
} |
| 5850 |
|
| 5851 |
void VmaJsonWriter::ContinueString(uint32_t n) |
| 5852 |
{ |
| 5853 |
VMA_ASSERT(m_InsideString); |
| 5854 |
m_SB.AddNumber(n); |
| 5855 |
} |
| 5856 |
|
| 5857 |
void VmaJsonWriter::ContinueString(uint64_t n) |
| 5858 |
{ |
| 5859 |
VMA_ASSERT(m_InsideString); |
| 5860 |
m_SB.AddNumber(n); |
| 5861 |
} |
| 5862 |
|
| 5863 |
void VmaJsonWriter::ContinueString_Pointer(const void* ptr) |
| 5864 |
{ |
| 5865 |
VMA_ASSERT(m_InsideString); |
| 5866 |
m_SB.AddPointer(ptr); |
| 5867 |
} |
| 5868 |
|
| 5869 |
void VmaJsonWriter::EndString(const char* pStr) |
| 5870 |
{ |
| 5871 |
VMA_ASSERT(m_InsideString); |
| 5872 |
if (pStr != VMA_NULL && pStr[0] != '\0') |
| 5873 |
{ |
| 5874 |
ContinueString(pStr); |
| 5875 |
} |
| 5876 |
m_SB.Add('"'); |
| 5877 |
m_InsideString = false; |
| 5878 |
} |
| 5879 |
|
| 5880 |
void VmaJsonWriter::WriteNumber(uint32_t n) |
| 5881 |
{ |
| 5882 |
VMA_ASSERT(!m_InsideString); |
| 5883 |
BeginValue(false); |
| 5884 |
m_SB.AddNumber(n); |
| 5885 |
} |
| 5886 |
|
| 5887 |
void VmaJsonWriter::WriteNumber(uint64_t n) |
| 5888 |
{ |
| 5889 |
VMA_ASSERT(!m_InsideString); |
| 5890 |
BeginValue(false); |
| 5891 |
m_SB.AddNumber(n); |
| 5892 |
} |
| 5893 |
|
| 5894 |
void VmaJsonWriter::WriteBool(bool b) |
| 5895 |
{ |
| 5896 |
VMA_ASSERT(!m_InsideString); |
| 5897 |
BeginValue(false); |
| 5898 |
m_SB.Add(b ? "true" : "false"); |
| 5899 |
} |
| 5900 |
|
| 5901 |
void VmaJsonWriter::WriteNull() |
| 5902 |
{ |
| 5903 |
VMA_ASSERT(!m_InsideString); |
| 5904 |
BeginValue(false); |
| 5905 |
m_SB.Add("null"); |
| 5906 |
} |
| 5907 |
|
| 5908 |
void VmaJsonWriter::BeginValue(bool isString) |
| 5909 |
{ |
| 5910 |
if (!m_Stack.empty()) |
| 5911 |
{ |
| 5912 |
StackItem& currItem = m_Stack.back(); |
| 5913 |
if (currItem.type == COLLECTION_TYPE_OBJECT && |
| 5914 |
currItem.valueCount % 2 == 0) |
| 5915 |
{ |
| 5916 |
VMA_ASSERT(isString); |
| 5917 |
} |
| 5918 |
|
| 5919 |
if (currItem.type == COLLECTION_TYPE_OBJECT && |
| 5920 |
currItem.valueCount % 2 != 0) |
| 5921 |
{ |
| 5922 |
m_SB.Add(": "); |
| 5923 |
} |
| 5924 |
else if (currItem.valueCount > 0) |
| 5925 |
{ |
| 5926 |
m_SB.Add(", "); |
| 5927 |
WriteIndent(); |
| 5928 |
} |
| 5929 |
else |
| 5930 |
{ |
| 5931 |
WriteIndent(); |
| 5932 |
} |
| 5933 |
++currItem.valueCount; |
| 5934 |
} |
| 5935 |
} |
| 5936 |
|
| 5937 |
void VmaJsonWriter::WriteIndent(bool oneLess) |
| 5938 |
{ |
| 5939 |
if (!m_Stack.empty() && !m_Stack.back().singleLineMode) |
| 5940 |
{ |
| 5941 |
m_SB.AddNewLine(); |
| 5942 |
|
| 5943 |
size_t count = m_Stack.size(); |
| 5944 |
if (count > 0 && oneLess) |
| 5945 |
{ |
| 5946 |
--count; |
| 5947 |
} |
| 5948 |
for (size_t i = 0; i < count; ++i) |
| 5949 |
{ |
| 5950 |
m_SB.Add(INDENT); |
| 5951 |
} |
| 5952 |
} |
| 5953 |
} |
| 5954 |
#endif |
| 5955 |
|
| 5956 |
static void VmaPrintDetailedStatistics(VmaJsonWriter& json, const VmaDetailedStatistics& stat) |
| 5957 |
{ |
| 5958 |
json.BeginObject(); |
| 5959 |
|
| 5960 |
json.WriteString("BlockCount"); |
| 5961 |
json.WriteNumber(stat.statistics.blockCount); |
| 5962 |
json.WriteString("BlockBytes"); |
| 5963 |
json.WriteNumber(stat.statistics.blockBytes); |
| 5964 |
json.WriteString("AllocationCount"); |
| 5965 |
json.WriteNumber(stat.statistics.allocationCount); |
| 5966 |
json.WriteString("AllocationBytes"); |
| 5967 |
json.WriteNumber(stat.statistics.allocationBytes); |
| 5968 |
json.WriteString("UnusedRangeCount"); |
| 5969 |
json.WriteNumber(stat.unusedRangeCount); |
| 5970 |
|
| 5971 |
if (stat.statistics.allocationCount > 1) |
| 5972 |
{ |
| 5973 |
json.WriteString("AllocationSizeMin"); |
| 5974 |
json.WriteNumber(stat.allocationSizeMin); |
| 5975 |
json.WriteString("AllocationSizeMax"); |
| 5976 |
json.WriteNumber(stat.allocationSizeMax); |
| 5977 |
} |
| 5978 |
if (stat.unusedRangeCount > 1) |
| 5979 |
{ |
| 5980 |
json.WriteString("UnusedRangeSizeMin"); |
| 5981 |
json.WriteNumber(stat.unusedRangeSizeMin); |
| 5982 |
json.WriteString("UnusedRangeSizeMax"); |
| 5983 |
json.WriteNumber(stat.unusedRangeSizeMax); |
| 5984 |
} |
| 5985 |
json.EndObject(); |
| 5986 |
} |
| 5987 |
#endif |
| 5988 |
|
| 5989 |
#ifndef _VMA_MAPPING_HYSTERESIS |
| 5990 |
|
| 5991 |
class VmaMappingHysteresis |
| 5992 |
{ |
| 5993 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaMappingHysteresis) |
| 5994 |
public: |
| 5995 |
VmaMappingHysteresis() = default; |
| 5996 |
|
| 5997 |
uint32_t GetExtraMapping() const { return m_ExtraMapping; } |
| 5998 |
|
| 5999 |
|
| 6000 |
|
| 6001 |
bool PostMap() |
| 6002 |
{ |
| 6003 |
#if VMA_MAPPING_HYSTERESIS_ENABLED |
| 6004 |
if(m_ExtraMapping == 0) |
| 6005 |
{ |
| 6006 |
++m_MajorCounter; |
| 6007 |
if(m_MajorCounter >= COUNTER_MIN_EXTRA_MAPPING) |
| 6008 |
{ |
| 6009 |
m_ExtraMapping = 1; |
| 6010 |
m_MajorCounter = 0; |
| 6011 |
m_MinorCounter = 0; |
| 6012 |
return true; |
| 6013 |
} |
| 6014 |
} |
| 6015 |
else |
| 6016 |
PostMinorCounter(); |
| 6017 |
#endif |
| 6018 |
return false; |
| 6019 |
} |
| 6020 |
|
| 6021 |
|
| 6022 |
void PostUnmap() |
| 6023 |
{ |
| 6024 |
#if VMA_MAPPING_HYSTERESIS_ENABLED |
| 6025 |
if(m_ExtraMapping == 0) |
| 6026 |
++m_MajorCounter; |
| 6027 |
else |
| 6028 |
PostMinorCounter(); |
| 6029 |
#endif |
| 6030 |
} |
| 6031 |
|
| 6032 |
|
| 6033 |
void PostAlloc() |
| 6034 |
{ |
| 6035 |
#if VMA_MAPPING_HYSTERESIS_ENABLED |
| 6036 |
if(m_ExtraMapping == 1) |
| 6037 |
++m_MajorCounter; |
| 6038 |
else |
| 6039 |
PostMinorCounter(); |
| 6040 |
#endif |
| 6041 |
} |
| 6042 |
|
| 6043 |
|
| 6044 |
|
| 6045 |
bool PostFree() |
| 6046 |
{ |
| 6047 |
#if VMA_MAPPING_HYSTERESIS_ENABLED |
| 6048 |
if(m_ExtraMapping == 1) |
| 6049 |
{ |
| 6050 |
++m_MajorCounter; |
| 6051 |
if(m_MajorCounter >= COUNTER_MIN_EXTRA_MAPPING && |
| 6052 |
m_MajorCounter > m_MinorCounter + 1) |
| 6053 |
{ |
| 6054 |
m_ExtraMapping = 0; |
| 6055 |
m_MajorCounter = 0; |
| 6056 |
m_MinorCounter = 0; |
| 6057 |
return true; |
| 6058 |
} |
| 6059 |
} |
| 6060 |
else |
| 6061 |
PostMinorCounter(); |
| 6062 |
#endif |
| 6063 |
return false; |
| 6064 |
} |
| 6065 |
|
| 6066 |
private: |
| 6067 |
static const int32_t COUNTER_MIN_EXTRA_MAPPING = 7; |
| 6068 |
|
| 6069 |
uint32_t m_MinorCounter = 0; |
| 6070 |
uint32_t m_MajorCounter = 0; |
| 6071 |
uint32_t m_ExtraMapping = 0; |
| 6072 |
|
| 6073 |
void PostMinorCounter() |
| 6074 |
{ |
| 6075 |
if(m_MinorCounter < m_MajorCounter) |
| 6076 |
{ |
| 6077 |
++m_MinorCounter; |
| 6078 |
} |
| 6079 |
else if(m_MajorCounter > 0) |
| 6080 |
{ |
| 6081 |
--m_MajorCounter; |
| 6082 |
--m_MinorCounter; |
| 6083 |
} |
| 6084 |
} |
| 6085 |
}; |
| 6086 |
|
| 6087 |
#endif |
| 6088 |
|
| 6089 |
#ifndef _VMA_DEVICE_MEMORY_BLOCK |
| 6090 |
|
| 6091 |
|
| 6092 |
|
| 6093 |
|
| 6094 |
|
| 6095 |
|
| 6096 |
|
| 6097 |
|
| 6098 |
class VmaDeviceMemoryBlock |
| 6099 |
{ |
| 6100 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaDeviceMemoryBlock) |
| 6101 |
public: |
| 6102 |
VmaBlockMetadata* m_pMetadata; |
| 6103 |
|
| 6104 |
VmaDeviceMemoryBlock(VmaAllocator hAllocator); |
| 6105 |
~VmaDeviceMemoryBlock(); |
| 6106 |
|
| 6107 |
|
| 6108 |
void Init( |
| 6109 |
VmaAllocator hAllocator, |
| 6110 |
VmaPool hParentPool, |
| 6111 |
uint32_t newMemoryTypeIndex, |
| 6112 |
VkDeviceMemory newMemory, |
| 6113 |
VkDeviceSize newSize, |
| 6114 |
uint32_t id, |
| 6115 |
uint32_t algorithm, |
| 6116 |
VkDeviceSize bufferImageGranularity); |
| 6117 |
|
| 6118 |
void Destroy(VmaAllocator allocator); |
| 6119 |
|
| 6120 |
VmaPool GetParentPool() const { return m_hParentPool; } |
| 6121 |
VkDeviceMemory GetDeviceMemory() const { return m_hMemory; } |
| 6122 |
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; } |
| 6123 |
uint32_t GetId() const { return m_Id; } |
| 6124 |
void* GetMappedData() const { return m_pMappedData; } |
| 6125 |
uint32_t GetMapRefCount() const { return m_MapCount; } |
| 6126 |
|
| 6127 |
|
| 6128 |
|
| 6129 |
void PostAlloc(VmaAllocator hAllocator); |
| 6130 |
void PostFree(VmaAllocator hAllocator); |
| 6131 |
|
| 6132 |
|
| 6133 |
bool Validate() const; |
| 6134 |
VkResult CheckCorruption(VmaAllocator hAllocator); |
| 6135 |
|
| 6136 |
|
| 6137 |
VkResult Map(VmaAllocator hAllocator, uint32_t count, void** ppData); |
| 6138 |
void Unmap(VmaAllocator hAllocator, uint32_t count); |
| 6139 |
|
| 6140 |
VkResult WriteMagicValueAfterAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize); |
| 6141 |
VkResult ValidateMagicValueAfterAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize); |
| 6142 |
|
| 6143 |
VkResult BindBufferMemory( |
| 6144 |
const VmaAllocator hAllocator, |
| 6145 |
const VmaAllocation hAllocation, |
| 6146 |
VkDeviceSize allocationLocalOffset, |
| 6147 |
VkBuffer hBuffer, |
| 6148 |
const void* pNext); |
| 6149 |
VkResult BindImageMemory( |
| 6150 |
const VmaAllocator hAllocator, |
| 6151 |
const VmaAllocation hAllocation, |
| 6152 |
VkDeviceSize allocationLocalOffset, |
| 6153 |
VkImage hImage, |
| 6154 |
const void* pNext); |
| 6155 |
|
| 6156 |
private: |
| 6157 |
VmaPool m_hParentPool; |
| 6158 |
uint32_t m_MemoryTypeIndex; |
| 6159 |
uint32_t m_Id; |
| 6160 |
VkDeviceMemory m_hMemory; |
| 6161 |
|
| 6162 |
|
| 6163 |
|
| 6164 |
|
| 6165 |
|
| 6166 |
|
| 6167 |
VMA_MUTEX m_MapAndBindMutex; |
| 6168 |
VmaMappingHysteresis m_MappingHysteresis; |
| 6169 |
uint32_t m_MapCount; |
| 6170 |
void* m_pMappedData; |
| 6171 |
}; |
| 6172 |
#endif |
| 6173 |
|
| 6174 |
#ifndef _VMA_ALLOCATION_T |
| 6175 |
struct VmaAllocation_T |
| 6176 |
{ |
| 6177 |
friend struct VmaDedicatedAllocationListItemTraits; |
| 6178 |
|
| 6179 |
enum FLAGS |
| 6180 |
{ |
| 6181 |
FLAG_PERSISTENT_MAP = 0x01, |
| 6182 |
FLAG_MAPPING_ALLOWED = 0x02, |
| 6183 |
}; |
| 6184 |
|
| 6185 |
public: |
| 6186 |
enum ALLOCATION_TYPE |
| 6187 |
{ |
| 6188 |
ALLOCATION_TYPE_NONE, |
| 6189 |
ALLOCATION_TYPE_BLOCK, |
| 6190 |
ALLOCATION_TYPE_DEDICATED, |
| 6191 |
}; |
| 6192 |
|
| 6193 |
|
| 6194 |
VmaAllocation_T(bool mappingAllowed); |
| 6195 |
~VmaAllocation_T(); |
| 6196 |
|
| 6197 |
void InitBlockAllocation( |
| 6198 |
VmaDeviceMemoryBlock* block, |
| 6199 |
VmaAllocHandle allocHandle, |
| 6200 |
VkDeviceSize alignment, |
| 6201 |
VkDeviceSize size, |
| 6202 |
uint32_t memoryTypeIndex, |
| 6203 |
VmaSuballocationType suballocationType, |
| 6204 |
bool mapped); |
| 6205 |
|
| 6206 |
void InitDedicatedAllocation( |
| 6207 |
VmaPool hParentPool, |
| 6208 |
uint32_t memoryTypeIndex, |
| 6209 |
VkDeviceMemory hMemory, |
| 6210 |
VmaSuballocationType suballocationType, |
| 6211 |
void* pMappedData, |
| 6212 |
VkDeviceSize size); |
| 6213 |
|
| 6214 |
ALLOCATION_TYPE GetType() const { return (ALLOCATION_TYPE)m_Type; } |
| 6215 |
VkDeviceSize GetAlignment() const { return m_Alignment; } |
| 6216 |
VkDeviceSize GetSize() const { return m_Size; } |
| 6217 |
void* GetUserData() const { return m_pUserData; } |
| 6218 |
const char* GetName() const { return m_pName; } |
| 6219 |
VmaSuballocationType GetSuballocationType() const { return (VmaSuballocationType)m_SuballocationType; } |
| 6220 |
|
| 6221 |
VmaDeviceMemoryBlock* GetBlock() const { VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK); return m_BlockAllocation.m_Block; } |
| 6222 |
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; } |
| 6223 |
bool IsPersistentMap() const { return (m_Flags & FLAG_PERSISTENT_MAP) != 0; } |
| 6224 |
bool IsMappingAllowed() const { return (m_Flags & FLAG_MAPPING_ALLOWED) != 0; } |
| 6225 |
|
| 6226 |
void SetUserData(VmaAllocator hAllocator, void* pUserData) { m_pUserData = pUserData; } |
| 6227 |
void SetName(VmaAllocator hAllocator, const char* pName); |
| 6228 |
void FreeName(VmaAllocator hAllocator); |
| 6229 |
uint8_t SwapBlockAllocation(VmaAllocator hAllocator, VmaAllocation allocation); |
| 6230 |
VmaAllocHandle GetAllocHandle() const; |
| 6231 |
VkDeviceSize GetOffset() const; |
| 6232 |
VmaPool GetParentPool() const; |
| 6233 |
VkDeviceMemory GetMemory() const; |
| 6234 |
void* GetMappedData() const; |
| 6235 |
|
| 6236 |
void BlockAllocMap(); |
| 6237 |
void BlockAllocUnmap(); |
| 6238 |
VkResult DedicatedAllocMap(VmaAllocator hAllocator, void** ppData); |
| 6239 |
void DedicatedAllocUnmap(VmaAllocator hAllocator); |
| 6240 |
|
| 6241 |
#if VMA_STATS_STRING_ENABLED |
| 6242 |
VmaBufferImageUsage GetBufferImageUsage() const { return m_BufferImageUsage; } |
| 6243 |
void InitBufferUsage(const VkBufferCreateInfo &createInfo, bool useKhrMaintenance5) |
| 6244 |
{ |
| 6245 |
VMA_ASSERT(m_BufferImageUsage == VmaBufferImageUsage::UNKNOWN); |
| 6246 |
m_BufferImageUsage = VmaBufferImageUsage(createInfo, useKhrMaintenance5); |
| 6247 |
} |
| 6248 |
void InitImageUsage(const VkImageCreateInfo &createInfo) |
| 6249 |
{ |
| 6250 |
VMA_ASSERT(m_BufferImageUsage == VmaBufferImageUsage::UNKNOWN); |
| 6251 |
m_BufferImageUsage = VmaBufferImageUsage(createInfo); |
| 6252 |
} |
| 6253 |
void PrintParameters(class VmaJsonWriter& json) const; |
| 6254 |
#endif |
| 6255 |
|
| 6256 |
private: |
| 6257 |
|
| 6258 |
struct BlockAllocation |
| 6259 |
{ |
| 6260 |
VmaDeviceMemoryBlock* m_Block; |
| 6261 |
VmaAllocHandle m_AllocHandle; |
| 6262 |
}; |
| 6263 |
|
| 6264 |
struct DedicatedAllocation |
| 6265 |
{ |
| 6266 |
VmaPool m_hParentPool; |
| 6267 |
VkDeviceMemory m_hMemory; |
| 6268 |
void* m_pMappedData; |
| 6269 |
VmaAllocation_T* m_Prev; |
| 6270 |
VmaAllocation_T* m_Next; |
| 6271 |
}; |
| 6272 |
union |
| 6273 |
{ |
| 6274 |
|
| 6275 |
BlockAllocation m_BlockAllocation; |
| 6276 |
|
| 6277 |
DedicatedAllocation m_DedicatedAllocation; |
| 6278 |
}; |
| 6279 |
|
| 6280 |
VkDeviceSize m_Alignment; |
| 6281 |
VkDeviceSize m_Size; |
| 6282 |
void* m_pUserData; |
| 6283 |
char* m_pName; |
| 6284 |
uint32_t m_MemoryTypeIndex; |
| 6285 |
uint8_t m_Type; |
| 6286 |
uint8_t m_SuballocationType; |
| 6287 |
|
| 6288 |
uint8_t m_MapCount; |
| 6289 |
uint8_t m_Flags; |
| 6290 |
#if VMA_STATS_STRING_ENABLED |
| 6291 |
VmaBufferImageUsage m_BufferImageUsage; |
| 6292 |
#endif |
| 6293 |
}; |
| 6294 |
#endif |
| 6295 |
|
| 6296 |
#ifndef _VMA_DEDICATED_ALLOCATION_LIST_ITEM_TRAITS |
| 6297 |
struct VmaDedicatedAllocationListItemTraits |
| 6298 |
{ |
| 6299 |
typedef VmaAllocation_T ItemType; |
| 6300 |
|
| 6301 |
static ItemType* GetPrev(const ItemType* item) |
| 6302 |
{ |
| 6303 |
VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED); |
| 6304 |
return item->m_DedicatedAllocation.m_Prev; |
| 6305 |
} |
| 6306 |
static ItemType* GetNext(const ItemType* item) |
| 6307 |
{ |
| 6308 |
VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED); |
| 6309 |
return item->m_DedicatedAllocation.m_Next; |
| 6310 |
} |
| 6311 |
static ItemType*& AccessPrev(ItemType* item) |
| 6312 |
{ |
| 6313 |
VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED); |
| 6314 |
return item->m_DedicatedAllocation.m_Prev; |
| 6315 |
} |
| 6316 |
static ItemType*& AccessNext(ItemType* item) |
| 6317 |
{ |
| 6318 |
VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED); |
| 6319 |
return item->m_DedicatedAllocation.m_Next; |
| 6320 |
} |
| 6321 |
}; |
| 6322 |
#endif |
| 6323 |
|
| 6324 |
#ifndef _VMA_DEDICATED_ALLOCATION_LIST |
| 6325 |
|
| 6326 |
|
| 6327 |
|
| 6328 |
|
| 6329 |
class VmaDedicatedAllocationList |
| 6330 |
{ |
| 6331 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaDedicatedAllocationList) |
| 6332 |
public: |
| 6333 |
VmaDedicatedAllocationList() {} |
| 6334 |
~VmaDedicatedAllocationList(); |
| 6335 |
|
| 6336 |
void Init(bool useMutex) { m_UseMutex = useMutex; } |
| 6337 |
bool Validate(); |
| 6338 |
|
| 6339 |
void AddDetailedStatistics(VmaDetailedStatistics& inoutStats); |
| 6340 |
void AddStatistics(VmaStatistics& inoutStats); |
| 6341 |
#if VMA_STATS_STRING_ENABLED |
| 6342 |
|
| 6343 |
void BuildStatsString(VmaJsonWriter& json); |
| 6344 |
#endif |
| 6345 |
|
| 6346 |
bool IsEmpty(); |
| 6347 |
void Register(VmaAllocation alloc); |
| 6348 |
void Unregister(VmaAllocation alloc); |
| 6349 |
|
| 6350 |
private: |
| 6351 |
typedef VmaIntrusiveLinkedList<VmaDedicatedAllocationListItemTraits> DedicatedAllocationLinkedList; |
| 6352 |
|
| 6353 |
bool m_UseMutex = true; |
| 6354 |
VMA_RW_MUTEX m_Mutex; |
| 6355 |
DedicatedAllocationLinkedList m_AllocationList; |
| 6356 |
}; |
| 6357 |
|
| 6358 |
#ifndef _VMA_DEDICATED_ALLOCATION_LIST_FUNCTIONS |
| 6359 |
|
| 6360 |
VmaDedicatedAllocationList::~VmaDedicatedAllocationList() |
| 6361 |
{ |
| 6362 |
VMA_HEAVY_ASSERT(Validate()); |
| 6363 |
|
| 6364 |
if (!m_AllocationList.IsEmpty()) |
| 6365 |
{ |
| 6366 |
VMA_ASSERT_LEAK(false && "Unfreed dedicated allocations found!"); |
| 6367 |
} |
| 6368 |
} |
| 6369 |
|
| 6370 |
bool VmaDedicatedAllocationList::Validate() |
| 6371 |
{ |
| 6372 |
const size_t declaredCount = m_AllocationList.GetCount(); |
| 6373 |
size_t actualCount = 0; |
| 6374 |
VmaMutexLockRead lock(m_Mutex, m_UseMutex); |
| 6375 |
for (VmaAllocation alloc = m_AllocationList.Front(); |
| 6376 |
alloc != VMA_NULL; alloc = m_AllocationList.GetNext(alloc)) |
| 6377 |
{ |
| 6378 |
++actualCount; |
| 6379 |
} |
| 6380 |
VMA_VALIDATE(actualCount == declaredCount); |
| 6381 |
|
| 6382 |
return true; |
| 6383 |
} |
| 6384 |
|
| 6385 |
void VmaDedicatedAllocationList::AddDetailedStatistics(VmaDetailedStatistics& inoutStats) |
| 6386 |
{ |
| 6387 |
for(auto* item = m_AllocationList.Front(); item != VMA_NULL; item = DedicatedAllocationLinkedList::GetNext(item)) |
| 6388 |
{ |
| 6389 |
const VkDeviceSize size = item->GetSize(); |
| 6390 |
inoutStats.statistics.blockCount++; |
| 6391 |
inoutStats.statistics.blockBytes += size; |
| 6392 |
VmaAddDetailedStatisticsAllocation(inoutStats, item->GetSize()); |
| 6393 |
} |
| 6394 |
} |
| 6395 |
|
| 6396 |
void VmaDedicatedAllocationList::AddStatistics(VmaStatistics& inoutStats) |
| 6397 |
{ |
| 6398 |
VmaMutexLockRead lock(m_Mutex, m_UseMutex); |
| 6399 |
|
| 6400 |
const uint32_t allocCount = (uint32_t)m_AllocationList.GetCount(); |
| 6401 |
inoutStats.blockCount += allocCount; |
| 6402 |
inoutStats.allocationCount += allocCount; |
| 6403 |
|
| 6404 |
for(auto* item = m_AllocationList.Front(); item != VMA_NULL; item = DedicatedAllocationLinkedList::GetNext(item)) |
| 6405 |
{ |
| 6406 |
const VkDeviceSize size = item->GetSize(); |
| 6407 |
inoutStats.blockBytes += size; |
| 6408 |
inoutStats.allocationBytes += size; |
| 6409 |
} |
| 6410 |
} |
| 6411 |
|
| 6412 |
#if VMA_STATS_STRING_ENABLED |
| 6413 |
void VmaDedicatedAllocationList::BuildStatsString(VmaJsonWriter& json) |
| 6414 |
{ |
| 6415 |
VmaMutexLockRead lock(m_Mutex, m_UseMutex); |
| 6416 |
json.BeginArray(); |
| 6417 |
for (VmaAllocation alloc = m_AllocationList.Front(); |
| 6418 |
alloc != VMA_NULL; alloc = m_AllocationList.GetNext(alloc)) |
| 6419 |
{ |
| 6420 |
json.BeginObject(true); |
| 6421 |
alloc->PrintParameters(json); |
| 6422 |
json.EndObject(); |
| 6423 |
} |
| 6424 |
json.EndArray(); |
| 6425 |
} |
| 6426 |
#endif |
| 6427 |
|
| 6428 |
bool VmaDedicatedAllocationList::IsEmpty() |
| 6429 |
{ |
| 6430 |
VmaMutexLockRead lock(m_Mutex, m_UseMutex); |
| 6431 |
return m_AllocationList.IsEmpty(); |
| 6432 |
} |
| 6433 |
|
| 6434 |
void VmaDedicatedAllocationList::Register(VmaAllocation alloc) |
| 6435 |
{ |
| 6436 |
VmaMutexLockWrite lock(m_Mutex, m_UseMutex); |
| 6437 |
m_AllocationList.PushBack(alloc); |
| 6438 |
} |
| 6439 |
|
| 6440 |
void VmaDedicatedAllocationList::Unregister(VmaAllocation alloc) |
| 6441 |
{ |
| 6442 |
VmaMutexLockWrite lock(m_Mutex, m_UseMutex); |
| 6443 |
m_AllocationList.Remove(alloc); |
| 6444 |
} |
| 6445 |
#endif |
| 6446 |
#endif |
| 6447 |
|
| 6448 |
#ifndef _VMA_SUBALLOCATION |
| 6449 |
|
| 6450 |
|
| 6451 |
|
| 6452 |
|
| 6453 |
struct VmaSuballocation |
| 6454 |
{ |
| 6455 |
VkDeviceSize offset; |
| 6456 |
VkDeviceSize size; |
| 6457 |
void* userData; |
| 6458 |
VmaSuballocationType type; |
| 6459 |
}; |
| 6460 |
|
| 6461 |
|
| 6462 |
struct VmaSuballocationOffsetLess |
| 6463 |
{ |
| 6464 |
bool operator()(const VmaSuballocation& lhs, const VmaSuballocation& rhs) const |
| 6465 |
{ |
| 6466 |
return lhs.offset < rhs.offset; |
| 6467 |
} |
| 6468 |
}; |
| 6469 |
|
| 6470 |
struct VmaSuballocationOffsetGreater |
| 6471 |
{ |
| 6472 |
bool operator()(const VmaSuballocation& lhs, const VmaSuballocation& rhs) const |
| 6473 |
{ |
| 6474 |
return lhs.offset > rhs.offset; |
| 6475 |
} |
| 6476 |
}; |
| 6477 |
|
| 6478 |
struct VmaSuballocationItemSizeLess |
| 6479 |
{ |
| 6480 |
bool operator()(const VmaSuballocationList::iterator lhs, |
| 6481 |
const VmaSuballocationList::iterator rhs) const |
| 6482 |
{ |
| 6483 |
return lhs->size < rhs->size; |
| 6484 |
} |
| 6485 |
|
| 6486 |
bool operator()(const VmaSuballocationList::iterator lhs, |
| 6487 |
VkDeviceSize rhsSize) const |
| 6488 |
{ |
| 6489 |
return lhs->size < rhsSize; |
| 6490 |
} |
| 6491 |
}; |
| 6492 |
#endif |
| 6493 |
|
| 6494 |
#ifndef _VMA_ALLOCATION_REQUEST |
| 6495 |
|
| 6496 |
|
| 6497 |
|
| 6498 |
|
| 6499 |
struct VmaAllocationRequest |
| 6500 |
{ |
| 6501 |
VmaAllocHandle allocHandle; |
| 6502 |
VkDeviceSize size; |
| 6503 |
VmaSuballocationList::iterator item; |
| 6504 |
void* customData; |
| 6505 |
uint64_t algorithmData; |
| 6506 |
VmaAllocationRequestType type; |
| 6507 |
}; |
| 6508 |
#endif |
| 6509 |
|
| 6510 |
#ifndef _VMA_BLOCK_METADATA |
| 6511 |
|
| 6512 |
|
| 6513 |
|
| 6514 |
|
| 6515 |
class VmaBlockMetadata |
| 6516 |
{ |
| 6517 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata) |
| 6518 |
public: |
| 6519 |
|
| 6520 |
VmaBlockMetadata(const VkAllocationCallbacks* pAllocationCallbacks, |
| 6521 |
VkDeviceSize bufferImageGranularity, bool isVirtual); |
| 6522 |
virtual ~VmaBlockMetadata() = default; |
| 6523 |
|
| 6524 |
virtual void Init(VkDeviceSize size) { m_Size = size; } |
| 6525 |
bool IsVirtual() const { return m_IsVirtual; } |
| 6526 |
VkDeviceSize GetSize() const { return m_Size; } |
| 6527 |
|
| 6528 |
|
| 6529 |
virtual bool Validate() const = 0; |
| 6530 |
virtual size_t GetAllocationCount() const = 0; |
| 6531 |
virtual size_t GetFreeRegionsCount() const = 0; |
| 6532 |
virtual VkDeviceSize GetSumFreeSize() const = 0; |
| 6533 |
|
| 6534 |
virtual bool IsEmpty() const = 0; |
| 6535 |
virtual void GetAllocationInfo(VmaAllocHandle allocHandle, VmaVirtualAllocationInfo& outInfo) = 0; |
| 6536 |
virtual VkDeviceSize GetAllocationOffset(VmaAllocHandle allocHandle) const = 0; |
| 6537 |
virtual void* GetAllocationUserData(VmaAllocHandle allocHandle) const = 0; |
| 6538 |
|
| 6539 |
virtual VmaAllocHandle GetAllocationListBegin() const = 0; |
| 6540 |
virtual VmaAllocHandle GetNextAllocation(VmaAllocHandle prevAlloc) const = 0; |
| 6541 |
virtual VkDeviceSize GetNextFreeRegionSize(VmaAllocHandle alloc) const = 0; |
| 6542 |
|
| 6543 |
|
| 6544 |
virtual void AddDetailedStatistics(VmaDetailedStatistics& inoutStats) const = 0; |
| 6545 |
virtual void AddStatistics(VmaStatistics& inoutStats) const = 0; |
| 6546 |
|
| 6547 |
#if VMA_STATS_STRING_ENABLED |
| 6548 |
virtual void PrintDetailedMap(class VmaJsonWriter& json) const = 0; |
| 6549 |
#endif |
| 6550 |
|
| 6551 |
|
| 6552 |
|
| 6553 |
|
| 6554 |
virtual bool CreateAllocationRequest( |
| 6555 |
VkDeviceSize allocSize, |
| 6556 |
VkDeviceSize allocAlignment, |
| 6557 |
bool upperAddress, |
| 6558 |
VmaSuballocationType allocType, |
| 6559 |
|
| 6560 |
uint32_t strategy, |
| 6561 |
VmaAllocationRequest* pAllocationRequest) = 0; |
| 6562 |
|
| 6563 |
virtual VkResult CheckCorruption(const void* pBlockData) = 0; |
| 6564 |
|
| 6565 |
|
| 6566 |
virtual void Alloc( |
| 6567 |
const VmaAllocationRequest& request, |
| 6568 |
VmaSuballocationType type, |
| 6569 |
void* userData) = 0; |
| 6570 |
|
| 6571 |
|
| 6572 |
virtual void Free(VmaAllocHandle allocHandle) = 0; |
| 6573 |
|
| 6574 |
|
| 6575 |
|
| 6576 |
virtual void Clear() = 0; |
| 6577 |
|
| 6578 |
virtual void SetAllocationUserData(VmaAllocHandle allocHandle, void* userData) = 0; |
| 6579 |
virtual void DebugLogAllAllocations() const = 0; |
| 6580 |
|
| 6581 |
protected: |
| 6582 |
const VkAllocationCallbacks* GetAllocationCallbacks() const { return m_pAllocationCallbacks; } |
| 6583 |
VkDeviceSize GetBufferImageGranularity() const { return m_BufferImageGranularity; } |
| 6584 |
VkDeviceSize GetDebugMargin() const { return VkDeviceSize(IsVirtual() ? 0 : VMA_DEBUG_MARGIN); } |
| 6585 |
|
| 6586 |
void DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size, void* userData) const; |
| 6587 |
#if VMA_STATS_STRING_ENABLED |
| 6588 |
|
| 6589 |
void PrintDetailedMap_Begin(class VmaJsonWriter& json, |
| 6590 |
VkDeviceSize unusedBytes, |
| 6591 |
size_t allocationCount, |
| 6592 |
size_t unusedRangeCount) const; |
| 6593 |
void PrintDetailedMap_Allocation(class VmaJsonWriter& json, |
| 6594 |
VkDeviceSize offset, VkDeviceSize size, void* userData) const; |
| 6595 |
void PrintDetailedMap_UnusedRange(class VmaJsonWriter& json, |
| 6596 |
VkDeviceSize offset, |
| 6597 |
VkDeviceSize size) const; |
| 6598 |
void PrintDetailedMap_End(class VmaJsonWriter& json) const; |
| 6599 |
#endif |
| 6600 |
|
| 6601 |
private: |
| 6602 |
VkDeviceSize m_Size; |
| 6603 |
const VkAllocationCallbacks* m_pAllocationCallbacks; |
| 6604 |
const VkDeviceSize m_BufferImageGranularity; |
| 6605 |
const bool m_IsVirtual; |
| 6606 |
}; |
| 6607 |
|
| 6608 |
#ifndef _VMA_BLOCK_METADATA_FUNCTIONS |
| 6609 |
VmaBlockMetadata::VmaBlockMetadata(const VkAllocationCallbacks* pAllocationCallbacks, |
| 6610 |
VkDeviceSize bufferImageGranularity, bool isVirtual) |
| 6611 |
: m_Size(0), |
| 6612 |
m_pAllocationCallbacks(pAllocationCallbacks), |
| 6613 |
m_BufferImageGranularity(bufferImageGranularity), |
| 6614 |
m_IsVirtual(isVirtual) {} |
| 6615 |
|
| 6616 |
void VmaBlockMetadata::DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size, void* userData) const |
| 6617 |
{ |
| 6618 |
if (IsVirtual()) |
| 6619 |
{ |
| 6620 |
VMA_LEAK_LOG_FORMAT("UNFREED VIRTUAL ALLOCATION; Offset: %" PRIu64 "; Size: %" PRIu64 "; UserData: %p", offset, size, userData); |
| 6621 |
} |
| 6622 |
else |
| 6623 |
{ |
| 6624 |
VMA_ASSERT(userData != VMA_NULL); |
| 6625 |
VmaAllocation allocation = reinterpret_cast<VmaAllocation>(userData); |
| 6626 |
|
| 6627 |
userData = allocation->GetUserData(); |
| 6628 |
const char* name = allocation->GetName(); |
| 6629 |
|
| 6630 |
#if VMA_STATS_STRING_ENABLED |
| 6631 |
VMA_LEAK_LOG_FORMAT("UNFREED ALLOCATION; Offset: %" PRIu64 "; Size: %" PRIu64 "; UserData: %p; Name: %s; Type: %s; Usage: %" PRIu64, |
| 6632 |
offset, size, userData, name ? name : "vma_empty", |
| 6633 |
VMA_SUBALLOCATION_TYPE_NAMES[allocation->GetSuballocationType()], |
| 6634 |
(uint64_t)allocation->GetBufferImageUsage().Value); |
| 6635 |
#else |
| 6636 |
VMA_LEAK_LOG_FORMAT("UNFREED ALLOCATION; Offset: %" PRIu64 "; Size: %" PRIu64 "; UserData: %p; Name: %s; Type: %u", |
| 6637 |
offset, size, userData, name ? name : "vma_empty", |
| 6638 |
(unsigned)allocation->GetSuballocationType()); |
| 6639 |
#endif |
| 6640 |
} |
| 6641 |
|
| 6642 |
} |
| 6643 |
|
| 6644 |
#if VMA_STATS_STRING_ENABLED |
| 6645 |
void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter& json, |
| 6646 |
VkDeviceSize unusedBytes, size_t allocationCount, size_t unusedRangeCount) const |
| 6647 |
{ |
| 6648 |
json.WriteString("TotalBytes"); |
| 6649 |
json.WriteNumber(GetSize()); |
| 6650 |
|
| 6651 |
json.WriteString("UnusedBytes"); |
| 6652 |
json.WriteNumber(unusedBytes); |
| 6653 |
|
| 6654 |
json.WriteString("Allocations"); |
| 6655 |
json.WriteNumber((uint64_t)allocationCount); |
| 6656 |
|
| 6657 |
json.WriteString("UnusedRanges"); |
| 6658 |
json.WriteNumber((uint64_t)unusedRangeCount); |
| 6659 |
|
| 6660 |
json.WriteString("Suballocations"); |
| 6661 |
json.BeginArray(); |
| 6662 |
} |
| 6663 |
|
| 6664 |
void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter& json, |
| 6665 |
VkDeviceSize offset, VkDeviceSize size, void* userData) const |
| 6666 |
{ |
| 6667 |
json.BeginObject(true); |
| 6668 |
|
| 6669 |
json.WriteString("Offset"); |
| 6670 |
json.WriteNumber(offset); |
| 6671 |
|
| 6672 |
if (IsVirtual()) |
| 6673 |
{ |
| 6674 |
json.WriteString("Size"); |
| 6675 |
json.WriteNumber(size); |
| 6676 |
if (userData) |
| 6677 |
{ |
| 6678 |
json.WriteString("CustomData"); |
| 6679 |
json.BeginString(); |
| 6680 |
json.ContinueString_Pointer(userData); |
| 6681 |
json.EndString(); |
| 6682 |
} |
| 6683 |
} |
| 6684 |
else |
| 6685 |
{ |
| 6686 |
((VmaAllocation)userData)->PrintParameters(json); |
| 6687 |
} |
| 6688 |
|
| 6689 |
json.EndObject(); |
| 6690 |
} |
| 6691 |
|
| 6692 |
void VmaBlockMetadata::PrintDetailedMap_UnusedRange(class VmaJsonWriter& json, |
| 6693 |
VkDeviceSize offset, VkDeviceSize size) const |
| 6694 |
{ |
| 6695 |
json.BeginObject(true); |
| 6696 |
|
| 6697 |
json.WriteString("Offset"); |
| 6698 |
json.WriteNumber(offset); |
| 6699 |
|
| 6700 |
json.WriteString("Type"); |
| 6701 |
json.WriteString(VMA_SUBALLOCATION_TYPE_NAMES[VMA_SUBALLOCATION_TYPE_FREE]); |
| 6702 |
|
| 6703 |
json.WriteString("Size"); |
| 6704 |
json.WriteNumber(size); |
| 6705 |
|
| 6706 |
json.EndObject(); |
| 6707 |
} |
| 6708 |
|
| 6709 |
void VmaBlockMetadata::PrintDetailedMap_End(class VmaJsonWriter& json) const |
| 6710 |
{ |
| 6711 |
json.EndArray(); |
| 6712 |
} |
| 6713 |
#endif |
| 6714 |
#endif |
| 6715 |
#endif |
| 6716 |
|
| 6717 |
#ifndef _VMA_BLOCK_BUFFER_IMAGE_GRANULARITY |
| 6718 |
|
| 6719 |
class VmaBlockBufferImageGranularity final |
| 6720 |
{ |
| 6721 |
public: |
| 6722 |
struct ValidationContext |
| 6723 |
{ |
| 6724 |
const VkAllocationCallbacks* allocCallbacks; |
| 6725 |
uint16_t* pageAllocs; |
| 6726 |
}; |
| 6727 |
|
| 6728 |
VmaBlockBufferImageGranularity(VkDeviceSize bufferImageGranularity); |
| 6729 |
~VmaBlockBufferImageGranularity(); |
| 6730 |
|
| 6731 |
bool IsEnabled() const { return m_BufferImageGranularity > MAX_LOW_BUFFER_IMAGE_GRANULARITY; } |
| 6732 |
|
| 6733 |
void Init(const VkAllocationCallbacks* pAllocationCallbacks, VkDeviceSize size); |
| 6734 |
|
| 6735 |
void Destroy(const VkAllocationCallbacks* pAllocationCallbacks); |
| 6736 |
|
| 6737 |
void RoundupAllocRequest(VmaSuballocationType allocType, |
| 6738 |
VkDeviceSize& inOutAllocSize, |
| 6739 |
VkDeviceSize& inOutAllocAlignment) const; |
| 6740 |
|
| 6741 |
bool CheckConflictAndAlignUp(VkDeviceSize& inOutAllocOffset, |
| 6742 |
VkDeviceSize allocSize, |
| 6743 |
VkDeviceSize blockOffset, |
| 6744 |
VkDeviceSize blockSize, |
| 6745 |
VmaSuballocationType allocType) const; |
| 6746 |
|
| 6747 |
void AllocPages(uint8_t allocType, VkDeviceSize offset, VkDeviceSize size); |
| 6748 |
void FreePages(VkDeviceSize offset, VkDeviceSize size); |
| 6749 |
void Clear(); |
| 6750 |
|
| 6751 |
ValidationContext StartValidation(const VkAllocationCallbacks* pAllocationCallbacks, |
| 6752 |
bool isVirutal) const; |
| 6753 |
bool Validate(ValidationContext& ctx, VkDeviceSize offset, VkDeviceSize size) const; |
| 6754 |
bool FinishValidation(ValidationContext& ctx) const; |
| 6755 |
|
| 6756 |
private: |
| 6757 |
static const uint16_t MAX_LOW_BUFFER_IMAGE_GRANULARITY = 256; |
| 6758 |
|
| 6759 |
struct RegionInfo |
| 6760 |
{ |
| 6761 |
uint8_t allocType; |
| 6762 |
uint16_t allocCount; |
| 6763 |
}; |
| 6764 |
|
| 6765 |
VkDeviceSize m_BufferImageGranularity; |
| 6766 |
uint32_t m_RegionCount; |
| 6767 |
RegionInfo* m_RegionInfo; |
| 6768 |
|
| 6769 |
uint32_t GetStartPage(VkDeviceSize offset) const { return OffsetToPageIndex(offset & ~(m_BufferImageGranularity - 1)); } |
| 6770 |
uint32_t GetEndPage(VkDeviceSize offset, VkDeviceSize size) const { return OffsetToPageIndex((offset + size - 1) & ~(m_BufferImageGranularity - 1)); } |
| 6771 |
|
| 6772 |
uint32_t OffsetToPageIndex(VkDeviceSize offset) const; |
| 6773 |
void AllocPage(RegionInfo& page, uint8_t allocType); |
| 6774 |
}; |
| 6775 |
|
| 6776 |
#ifndef _VMA_BLOCK_BUFFER_IMAGE_GRANULARITY_FUNCTIONS |
| 6777 |
VmaBlockBufferImageGranularity::VmaBlockBufferImageGranularity(VkDeviceSize bufferImageGranularity) |
| 6778 |
: m_BufferImageGranularity(bufferImageGranularity), |
| 6779 |
m_RegionCount(0), |
| 6780 |
m_RegionInfo(VMA_NULL) {} |
| 6781 |
|
| 6782 |
VmaBlockBufferImageGranularity::~VmaBlockBufferImageGranularity() |
| 6783 |
{ |
| 6784 |
VMA_ASSERT(m_RegionInfo == VMA_NULL && "Free not called before destroying object!"); |
| 6785 |
} |
| 6786 |
|
| 6787 |
void VmaBlockBufferImageGranularity::Init(const VkAllocationCallbacks* pAllocationCallbacks, VkDeviceSize size) |
| 6788 |
{ |
| 6789 |
if (IsEnabled()) |
| 6790 |
{ |
| 6791 |
m_RegionCount = static_cast<uint32_t>(VmaDivideRoundingUp(size, m_BufferImageGranularity)); |
| 6792 |
m_RegionInfo = vma_new_array(pAllocationCallbacks, RegionInfo, m_RegionCount); |
| 6793 |
memset(m_RegionInfo, 0, m_RegionCount * sizeof(RegionInfo)); |
| 6794 |
} |
| 6795 |
} |
| 6796 |
|
| 6797 |
void VmaBlockBufferImageGranularity::Destroy(const VkAllocationCallbacks* pAllocationCallbacks) |
| 6798 |
{ |
| 6799 |
if (m_RegionInfo) |
| 6800 |
{ |
| 6801 |
vma_delete_array(pAllocationCallbacks, m_RegionInfo, m_RegionCount); |
| 6802 |
m_RegionInfo = VMA_NULL; |
| 6803 |
} |
| 6804 |
} |
| 6805 |
|
| 6806 |
void VmaBlockBufferImageGranularity::RoundupAllocRequest(VmaSuballocationType allocType, |
| 6807 |
VkDeviceSize& inOutAllocSize, |
| 6808 |
VkDeviceSize& inOutAllocAlignment) const |
| 6809 |
{ |
| 6810 |
if (m_BufferImageGranularity > 1 && |
| 6811 |
m_BufferImageGranularity <= MAX_LOW_BUFFER_IMAGE_GRANULARITY) |
| 6812 |
{ |
| 6813 |
if (allocType == VMA_SUBALLOCATION_TYPE_UNKNOWN || |
| 6814 |
allocType == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN || |
| 6815 |
allocType == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL) |
| 6816 |
{ |
| 6817 |
inOutAllocAlignment = VMA_MAX(inOutAllocAlignment, m_BufferImageGranularity); |
| 6818 |
inOutAllocSize = VmaAlignUp(inOutAllocSize, m_BufferImageGranularity); |
| 6819 |
} |
| 6820 |
} |
| 6821 |
} |
| 6822 |
|
| 6823 |
bool VmaBlockBufferImageGranularity::CheckConflictAndAlignUp(VkDeviceSize& inOutAllocOffset, |
| 6824 |
VkDeviceSize allocSize, |
| 6825 |
VkDeviceSize blockOffset, |
| 6826 |
VkDeviceSize blockSize, |
| 6827 |
VmaSuballocationType allocType) const |
| 6828 |
{ |
| 6829 |
if (IsEnabled()) |
| 6830 |
{ |
| 6831 |
uint32_t startPage = GetStartPage(inOutAllocOffset); |
| 6832 |
if (m_RegionInfo[startPage].allocCount > 0 && |
| 6833 |
VmaIsBufferImageGranularityConflict(static_cast<VmaSuballocationType>(m_RegionInfo[startPage].allocType), allocType)) |
| 6834 |
{ |
| 6835 |
inOutAllocOffset = VmaAlignUp(inOutAllocOffset, m_BufferImageGranularity); |
| 6836 |
if (blockSize < allocSize + inOutAllocOffset - blockOffset) |
| 6837 |
return true; |
| 6838 |
++startPage; |
| 6839 |
} |
| 6840 |
uint32_t endPage = GetEndPage(inOutAllocOffset, allocSize); |
| 6841 |
if (endPage != startPage && |
| 6842 |
m_RegionInfo[endPage].allocCount > 0 && |
| 6843 |
VmaIsBufferImageGranularityConflict(static_cast<VmaSuballocationType>(m_RegionInfo[endPage].allocType), allocType)) |
| 6844 |
{ |
| 6845 |
return true; |
| 6846 |
} |
| 6847 |
} |
| 6848 |
return false; |
| 6849 |
} |
| 6850 |
|
| 6851 |
void VmaBlockBufferImageGranularity::AllocPages(uint8_t allocType, VkDeviceSize offset, VkDeviceSize size) |
| 6852 |
{ |
| 6853 |
if (IsEnabled()) |
| 6854 |
{ |
| 6855 |
uint32_t startPage = GetStartPage(offset); |
| 6856 |
AllocPage(m_RegionInfo[startPage], allocType); |
| 6857 |
|
| 6858 |
uint32_t endPage = GetEndPage(offset, size); |
| 6859 |
if (startPage != endPage) |
| 6860 |
AllocPage(m_RegionInfo[endPage], allocType); |
| 6861 |
} |
| 6862 |
} |
| 6863 |
|
| 6864 |
void VmaBlockBufferImageGranularity::FreePages(VkDeviceSize offset, VkDeviceSize size) |
| 6865 |
{ |
| 6866 |
if (IsEnabled()) |
| 6867 |
{ |
| 6868 |
uint32_t startPage = GetStartPage(offset); |
| 6869 |
--m_RegionInfo[startPage].allocCount; |
| 6870 |
if (m_RegionInfo[startPage].allocCount == 0) |
| 6871 |
m_RegionInfo[startPage].allocType = VMA_SUBALLOCATION_TYPE_FREE; |
| 6872 |
uint32_t endPage = GetEndPage(offset, size); |
| 6873 |
if (startPage != endPage) |
| 6874 |
{ |
| 6875 |
--m_RegionInfo[endPage].allocCount; |
| 6876 |
if (m_RegionInfo[endPage].allocCount == 0) |
| 6877 |
m_RegionInfo[endPage].allocType = VMA_SUBALLOCATION_TYPE_FREE; |
| 6878 |
} |
| 6879 |
} |
| 6880 |
} |
| 6881 |
|
| 6882 |
void VmaBlockBufferImageGranularity::Clear() |
| 6883 |
{ |
| 6884 |
if (m_RegionInfo) |
| 6885 |
memset(m_RegionInfo, 0, m_RegionCount * sizeof(RegionInfo)); |
| 6886 |
} |
| 6887 |
|
| 6888 |
VmaBlockBufferImageGranularity::ValidationContext VmaBlockBufferImageGranularity::StartValidation( |
| 6889 |
const VkAllocationCallbacks* pAllocationCallbacks, bool isVirutal) const |
| 6890 |
{ |
| 6891 |
ValidationContext ctx{ pAllocationCallbacks, VMA_NULL }; |
| 6892 |
if (!isVirutal && IsEnabled()) |
| 6893 |
{ |
| 6894 |
ctx.pageAllocs = vma_new_array(pAllocationCallbacks, uint16_t, m_RegionCount); |
| 6895 |
memset(ctx.pageAllocs, 0, m_RegionCount * sizeof(uint16_t)); |
| 6896 |
} |
| 6897 |
return ctx; |
| 6898 |
} |
| 6899 |
|
| 6900 |
bool VmaBlockBufferImageGranularity::Validate(ValidationContext& ctx, |
| 6901 |
VkDeviceSize offset, VkDeviceSize size) const |
| 6902 |
{ |
| 6903 |
if (IsEnabled()) |
| 6904 |
{ |
| 6905 |
uint32_t start = GetStartPage(offset); |
| 6906 |
++ctx.pageAllocs[start]; |
| 6907 |
VMA_VALIDATE(m_RegionInfo[start].allocCount > 0); |
| 6908 |
|
| 6909 |
uint32_t end = GetEndPage(offset, size); |
| 6910 |
if (start != end) |
| 6911 |
{ |
| 6912 |
++ctx.pageAllocs[end]; |
| 6913 |
VMA_VALIDATE(m_RegionInfo[end].allocCount > 0); |
| 6914 |
} |
| 6915 |
} |
| 6916 |
return true; |
| 6917 |
} |
| 6918 |
|
| 6919 |
bool VmaBlockBufferImageGranularity::FinishValidation(ValidationContext& ctx) const |
| 6920 |
{ |
| 6921 |
|
| 6922 |
if (IsEnabled()) |
| 6923 |
{ |
| 6924 |
VMA_ASSERT(ctx.pageAllocs != VMA_NULL && "Validation context not initialized!"); |
| 6925 |
|
| 6926 |
for (uint32_t page = 0; page < m_RegionCount; ++page) |
| 6927 |
{ |
| 6928 |
VMA_VALIDATE(ctx.pageAllocs[page] == m_RegionInfo[page].allocCount); |
| 6929 |
} |
| 6930 |
vma_delete_array(ctx.allocCallbacks, ctx.pageAllocs, m_RegionCount); |
| 6931 |
ctx.pageAllocs = VMA_NULL; |
| 6932 |
} |
| 6933 |
return true; |
| 6934 |
} |
| 6935 |
|
| 6936 |
uint32_t VmaBlockBufferImageGranularity::OffsetToPageIndex(VkDeviceSize offset) const |
| 6937 |
{ |
| 6938 |
return static_cast<uint32_t>(offset >> VMA_BITSCAN_MSB(m_BufferImageGranularity)); |
| 6939 |
} |
| 6940 |
|
| 6941 |
void VmaBlockBufferImageGranularity::AllocPage(RegionInfo& page, uint8_t allocType) |
| 6942 |
{ |
| 6943 |
|
| 6944 |
if (page.allocCount == 0 || (page.allocCount > 0 && page.allocType == VMA_SUBALLOCATION_TYPE_FREE)) |
| 6945 |
page.allocType = allocType; |
| 6946 |
|
| 6947 |
++page.allocCount; |
| 6948 |
} |
| 6949 |
#endif |
| 6950 |
#endif |
| 6951 |
|
| 6952 |
#ifndef _VMA_BLOCK_METADATA_LINEAR |
| 6953 |
|
| 6954 |
|
| 6955 |
|
| 6956 |
|
| 6957 |
|
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
|
| 6962 |
|
| 6963 |
|
| 6964 |
|
| 6965 |
|
| 6966 |
|
| 6967 |
|
| 6968 |
|
| 6969 |
|
| 6970 |
|
| 6971 |
|
| 6972 |
|
| 6973 |
|
| 6974 |
|
| 6975 |
|
| 6976 |
|
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
|
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
|
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
|
| 6991 |
|
| 6992 |
|
| 6993 |
|
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
|
| 6999 |
|
| 7000 |
|
| 7001 |
|
| 7002 |
|
| 7003 |
|
| 7004 |
|
| 7005 |
|
| 7006 |
|
| 7007 |
|
| 7008 |
|
| 7009 |
|
| 7010 |
|
| 7011 |
|
| 7012 |
|
| 7013 |
|
| 7014 |
|
| 7015 |
|
| 7016 |
|
| 7017 |
|
| 7018 |
|
| 7019 |
|
| 7020 |
|
| 7021 |
|
| 7022 |
|
| 7023 |
|
| 7024 |
|
| 7025 |
|
| 7026 |
|
| 7027 |
|
| 7028 |
|
| 7029 |
|
| 7030 |
|
| 7031 |
class VmaBlockMetadata_Linear : public VmaBlockMetadata |
| 7032 |
{ |
| 7033 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_Linear) |
| 7034 |
public: |
| 7035 |
VmaBlockMetadata_Linear(const VkAllocationCallbacks* pAllocationCallbacks, |
| 7036 |
VkDeviceSize bufferImageGranularity, bool isVirtual); |
| 7037 |
virtual ~VmaBlockMetadata_Linear() = default; |
| 7038 |
|
| 7039 |
VkDeviceSize GetSumFreeSize() const override { return m_SumFreeSize; } |
| 7040 |
bool IsEmpty() const override { return GetAllocationCount() == 0; } |
| 7041 |
VkDeviceSize GetAllocationOffset(VmaAllocHandle allocHandle) const override { return (VkDeviceSize)allocHandle - 1; } |
| 7042 |
|
| 7043 |
void Init(VkDeviceSize size) override; |
| 7044 |
bool Validate() const override; |
| 7045 |
size_t GetAllocationCount() const override; |
| 7046 |
size_t GetFreeRegionsCount() const override; |
| 7047 |
|
| 7048 |
void AddDetailedStatistics(VmaDetailedStatistics& inoutStats) const override; |
| 7049 |
void AddStatistics(VmaStatistics& inoutStats) const override; |
| 7050 |
|
| 7051 |
#if VMA_STATS_STRING_ENABLED |
| 7052 |
void PrintDetailedMap(class VmaJsonWriter& json) const override; |
| 7053 |
#endif |
| 7054 |
|
| 7055 |
bool CreateAllocationRequest( |
| 7056 |
VkDeviceSize allocSize, |
| 7057 |
VkDeviceSize allocAlignment, |
| 7058 |
bool upperAddress, |
| 7059 |
VmaSuballocationType allocType, |
| 7060 |
uint32_t strategy, |
| 7061 |
VmaAllocationRequest* pAllocationRequest) override; |
| 7062 |
|
| 7063 |
VkResult CheckCorruption(const void* pBlockData) override; |
| 7064 |
|
| 7065 |
void Alloc( |
| 7066 |
const VmaAllocationRequest& request, |
| 7067 |
VmaSuballocationType type, |
| 7068 |
void* userData) override; |
| 7069 |
|
| 7070 |
void Free(VmaAllocHandle allocHandle) override; |
| 7071 |
void GetAllocationInfo(VmaAllocHandle allocHandle, VmaVirtualAllocationInfo& outInfo) override; |
| 7072 |
void* GetAllocationUserData(VmaAllocHandle allocHandle) const override; |
| 7073 |
VmaAllocHandle GetAllocationListBegin() const override; |
| 7074 |
VmaAllocHandle GetNextAllocation(VmaAllocHandle prevAlloc) const override; |
| 7075 |
VkDeviceSize GetNextFreeRegionSize(VmaAllocHandle alloc) const override; |
| 7076 |
void Clear() override; |
| 7077 |
void SetAllocationUserData(VmaAllocHandle allocHandle, void* userData) override; |
| 7078 |
void DebugLogAllAllocations() const override; |
| 7079 |
|
| 7080 |
private: |
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
|
| 7085 |
|
| 7086 |
|
| 7087 |
|
| 7088 |
typedef VmaVector<VmaSuballocation, VmaStlAllocator<VmaSuballocation>> SuballocationVectorType; |
| 7089 |
|
| 7090 |
enum SECOND_VECTOR_MODE |
| 7091 |
{ |
| 7092 |
SECOND_VECTOR_EMPTY, |
| 7093 |
|
| 7094 |
|
| 7095 |
|
| 7096 |
|
| 7097 |
SECOND_VECTOR_RING_BUFFER, |
| 7098 |
|
| 7099 |
|
| 7100 |
|
| 7101 |
|
| 7102 |
|
| 7103 |
SECOND_VECTOR_DOUBLE_STACK, |
| 7104 |
}; |
| 7105 |
|
| 7106 |
VkDeviceSize m_SumFreeSize; |
| 7107 |
SuballocationVectorType m_Suballocations0, m_Suballocations1; |
| 7108 |
uint32_t m_1stVectorIndex; |
| 7109 |
SECOND_VECTOR_MODE m_2ndVectorMode; |
| 7110 |
|
| 7111 |
size_t m_1stNullItemsBeginCount; |
| 7112 |
|
| 7113 |
size_t m_1stNullItemsMiddleCount; |
| 7114 |
|
| 7115 |
size_t m_2ndNullItemsCount; |
| 7116 |
|
| 7117 |
SuballocationVectorType& AccessSuballocations1st() { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; } |
| 7118 |
SuballocationVectorType& AccessSuballocations2nd() { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; } |
| 7119 |
const SuballocationVectorType& AccessSuballocations1st() const { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; } |
| 7120 |
const SuballocationVectorType& AccessSuballocations2nd() const { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; } |
| 7121 |
|
| 7122 |
VmaSuballocation& FindSuballocation(VkDeviceSize offset) const; |
| 7123 |
bool ShouldCompact1st() const; |
| 7124 |
void CleanupAfterFree(); |
| 7125 |
|
| 7126 |
bool CreateAllocationRequest_LowerAddress( |
| 7127 |
VkDeviceSize allocSize, |
| 7128 |
VkDeviceSize allocAlignment, |
| 7129 |
VmaSuballocationType allocType, |
| 7130 |
uint32_t strategy, |
| 7131 |
VmaAllocationRequest* pAllocationRequest); |
| 7132 |
bool CreateAllocationRequest_UpperAddress( |
| 7133 |
VkDeviceSize allocSize, |
| 7134 |
VkDeviceSize allocAlignment, |
| 7135 |
VmaSuballocationType allocType, |
| 7136 |
uint32_t strategy, |
| 7137 |
VmaAllocationRequest* pAllocationRequest); |
| 7138 |
}; |
| 7139 |
|
| 7140 |
#ifndef _VMA_BLOCK_METADATA_LINEAR_FUNCTIONS |
| 7141 |
VmaBlockMetadata_Linear::VmaBlockMetadata_Linear(const VkAllocationCallbacks* pAllocationCallbacks, |
| 7142 |
VkDeviceSize bufferImageGranularity, bool isVirtual) |
| 7143 |
: VmaBlockMetadata(pAllocationCallbacks, bufferImageGranularity, isVirtual), |
| 7144 |
m_SumFreeSize(0), |
| 7145 |
m_Suballocations0(VmaStlAllocator<VmaSuballocation>(pAllocationCallbacks)), |
| 7146 |
m_Suballocations1(VmaStlAllocator<VmaSuballocation>(pAllocationCallbacks)), |
| 7147 |
m_1stVectorIndex(0), |
| 7148 |
m_2ndVectorMode(SECOND_VECTOR_EMPTY), |
| 7149 |
m_1stNullItemsBeginCount(0), |
| 7150 |
m_1stNullItemsMiddleCount(0), |
| 7151 |
m_2ndNullItemsCount(0) {} |
| 7152 |
|
| 7153 |
void VmaBlockMetadata_Linear::Init(VkDeviceSize size) |
| 7154 |
{ |
| 7155 |
VmaBlockMetadata::Init(size); |
| 7156 |
m_SumFreeSize = size; |
| 7157 |
} |
| 7158 |
|
| 7159 |
bool VmaBlockMetadata_Linear::Validate() const |
| 7160 |
{ |
| 7161 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7162 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7163 |
|
| 7164 |
VMA_VALIDATE(suballocations2nd.empty() == (m_2ndVectorMode == SECOND_VECTOR_EMPTY)); |
| 7165 |
VMA_VALIDATE(!suballocations1st.empty() || |
| 7166 |
suballocations2nd.empty() || |
| 7167 |
m_2ndVectorMode != SECOND_VECTOR_RING_BUFFER); |
| 7168 |
|
| 7169 |
if (!suballocations1st.empty()) |
| 7170 |
{ |
| 7171 |
|
| 7172 |
VMA_VALIDATE(suballocations1st[m_1stNullItemsBeginCount].type != VMA_SUBALLOCATION_TYPE_FREE); |
| 7173 |
|
| 7174 |
VMA_VALIDATE(suballocations1st.back().type != VMA_SUBALLOCATION_TYPE_FREE); |
| 7175 |
} |
| 7176 |
if (!suballocations2nd.empty()) |
| 7177 |
{ |
| 7178 |
|
| 7179 |
VMA_VALIDATE(suballocations2nd.back().type != VMA_SUBALLOCATION_TYPE_FREE); |
| 7180 |
} |
| 7181 |
|
| 7182 |
VMA_VALIDATE(m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount <= suballocations1st.size()); |
| 7183 |
VMA_VALIDATE(m_2ndNullItemsCount <= suballocations2nd.size()); |
| 7184 |
|
| 7185 |
VkDeviceSize sumUsedSize = 0; |
| 7186 |
const size_t suballoc1stCount = suballocations1st.size(); |
| 7187 |
const VkDeviceSize debugMargin = GetDebugMargin(); |
| 7188 |
VkDeviceSize offset = 0; |
| 7189 |
|
| 7190 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 7191 |
{ |
| 7192 |
const size_t suballoc2ndCount = suballocations2nd.size(); |
| 7193 |
size_t nullItem2ndCount = 0; |
| 7194 |
for (size_t i = 0; i < suballoc2ndCount; ++i) |
| 7195 |
{ |
| 7196 |
const VmaSuballocation& suballoc = suballocations2nd[i]; |
| 7197 |
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE); |
| 7198 |
|
| 7199 |
VmaAllocation const alloc = (VmaAllocation)suballoc.userData; |
| 7200 |
if (!IsVirtual()) |
| 7201 |
{ |
| 7202 |
VMA_VALIDATE(currFree == (alloc == VK_NULL_HANDLE)); |
| 7203 |
} |
| 7204 |
VMA_VALIDATE(suballoc.offset >= offset); |
| 7205 |
|
| 7206 |
if (!currFree) |
| 7207 |
{ |
| 7208 |
if (!IsVirtual()) |
| 7209 |
{ |
| 7210 |
VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1); |
| 7211 |
VMA_VALIDATE(alloc->GetSize() == suballoc.size); |
| 7212 |
} |
| 7213 |
sumUsedSize += suballoc.size; |
| 7214 |
} |
| 7215 |
else |
| 7216 |
{ |
| 7217 |
++nullItem2ndCount; |
| 7218 |
} |
| 7219 |
|
| 7220 |
offset = suballoc.offset + suballoc.size + debugMargin; |
| 7221 |
} |
| 7222 |
|
| 7223 |
VMA_VALIDATE(nullItem2ndCount == m_2ndNullItemsCount); |
| 7224 |
} |
| 7225 |
|
| 7226 |
for (size_t i = 0; i < m_1stNullItemsBeginCount; ++i) |
| 7227 |
{ |
| 7228 |
const VmaSuballocation& suballoc = suballocations1st[i]; |
| 7229 |
VMA_VALIDATE(suballoc.type == VMA_SUBALLOCATION_TYPE_FREE && |
| 7230 |
suballoc.userData == VMA_NULL); |
| 7231 |
} |
| 7232 |
|
| 7233 |
size_t nullItem1stCount = m_1stNullItemsBeginCount; |
| 7234 |
|
| 7235 |
for (size_t i = m_1stNullItemsBeginCount; i < suballoc1stCount; ++i) |
| 7236 |
{ |
| 7237 |
const VmaSuballocation& suballoc = suballocations1st[i]; |
| 7238 |
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE); |
| 7239 |
|
| 7240 |
VmaAllocation const alloc = (VmaAllocation)suballoc.userData; |
| 7241 |
if (!IsVirtual()) |
| 7242 |
{ |
| 7243 |
VMA_VALIDATE(currFree == (alloc == VK_NULL_HANDLE)); |
| 7244 |
} |
| 7245 |
VMA_VALIDATE(suballoc.offset >= offset); |
| 7246 |
VMA_VALIDATE(i >= m_1stNullItemsBeginCount || currFree); |
| 7247 |
|
| 7248 |
if (!currFree) |
| 7249 |
{ |
| 7250 |
if (!IsVirtual()) |
| 7251 |
{ |
| 7252 |
VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1); |
| 7253 |
VMA_VALIDATE(alloc->GetSize() == suballoc.size); |
| 7254 |
} |
| 7255 |
sumUsedSize += suballoc.size; |
| 7256 |
} |
| 7257 |
else |
| 7258 |
{ |
| 7259 |
++nullItem1stCount; |
| 7260 |
} |
| 7261 |
|
| 7262 |
offset = suballoc.offset + suballoc.size + debugMargin; |
| 7263 |
} |
| 7264 |
VMA_VALIDATE(nullItem1stCount == m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount); |
| 7265 |
|
| 7266 |
if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 7267 |
{ |
| 7268 |
const size_t suballoc2ndCount = suballocations2nd.size(); |
| 7269 |
size_t nullItem2ndCount = 0; |
| 7270 |
for (size_t i = suballoc2ndCount; i--; ) |
| 7271 |
{ |
| 7272 |
const VmaSuballocation& suballoc = suballocations2nd[i]; |
| 7273 |
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE); |
| 7274 |
|
| 7275 |
VmaAllocation const alloc = (VmaAllocation)suballoc.userData; |
| 7276 |
if (!IsVirtual()) |
| 7277 |
{ |
| 7278 |
VMA_VALIDATE(currFree == (alloc == VK_NULL_HANDLE)); |
| 7279 |
} |
| 7280 |
VMA_VALIDATE(suballoc.offset >= offset); |
| 7281 |
|
| 7282 |
if (!currFree) |
| 7283 |
{ |
| 7284 |
if (!IsVirtual()) |
| 7285 |
{ |
| 7286 |
VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1); |
| 7287 |
VMA_VALIDATE(alloc->GetSize() == suballoc.size); |
| 7288 |
} |
| 7289 |
sumUsedSize += suballoc.size; |
| 7290 |
} |
| 7291 |
else |
| 7292 |
{ |
| 7293 |
++nullItem2ndCount; |
| 7294 |
} |
| 7295 |
|
| 7296 |
offset = suballoc.offset + suballoc.size + debugMargin; |
| 7297 |
} |
| 7298 |
|
| 7299 |
VMA_VALIDATE(nullItem2ndCount == m_2ndNullItemsCount); |
| 7300 |
} |
| 7301 |
|
| 7302 |
VMA_VALIDATE(offset <= GetSize()); |
| 7303 |
VMA_VALIDATE(m_SumFreeSize == GetSize() - sumUsedSize); |
| 7304 |
|
| 7305 |
return true; |
| 7306 |
} |
| 7307 |
|
| 7308 |
size_t VmaBlockMetadata_Linear::GetAllocationCount() const |
| 7309 |
{ |
| 7310 |
return AccessSuballocations1st().size() - m_1stNullItemsBeginCount - m_1stNullItemsMiddleCount + |
| 7311 |
AccessSuballocations2nd().size() - m_2ndNullItemsCount; |
| 7312 |
} |
| 7313 |
|
| 7314 |
size_t VmaBlockMetadata_Linear::GetFreeRegionsCount() const |
| 7315 |
{ |
| 7316 |
|
| 7317 |
VMA_ASSERT(0); |
| 7318 |
return SIZE_MAX; |
| 7319 |
} |
| 7320 |
|
| 7321 |
void VmaBlockMetadata_Linear::AddDetailedStatistics(VmaDetailedStatistics& inoutStats) const |
| 7322 |
{ |
| 7323 |
const VkDeviceSize size = GetSize(); |
| 7324 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7325 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7326 |
const size_t suballoc1stCount = suballocations1st.size(); |
| 7327 |
const size_t suballoc2ndCount = suballocations2nd.size(); |
| 7328 |
|
| 7329 |
inoutStats.statistics.blockCount++; |
| 7330 |
inoutStats.statistics.blockBytes += size; |
| 7331 |
|
| 7332 |
VkDeviceSize lastOffset = 0; |
| 7333 |
|
| 7334 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 7335 |
{ |
| 7336 |
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset; |
| 7337 |
size_t nextAlloc2ndIndex = 0; |
| 7338 |
while (lastOffset < freeSpace2ndTo1stEnd) |
| 7339 |
{ |
| 7340 |
|
| 7341 |
while (nextAlloc2ndIndex < suballoc2ndCount && |
| 7342 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7343 |
{ |
| 7344 |
++nextAlloc2ndIndex; |
| 7345 |
} |
| 7346 |
|
| 7347 |
|
| 7348 |
if (nextAlloc2ndIndex < suballoc2ndCount) |
| 7349 |
{ |
| 7350 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7351 |
|
| 7352 |
|
| 7353 |
if (lastOffset < suballoc.offset) |
| 7354 |
{ |
| 7355 |
|
| 7356 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7357 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7358 |
} |
| 7359 |
|
| 7360 |
|
| 7361 |
|
| 7362 |
VmaAddDetailedStatisticsAllocation(inoutStats, suballoc.size); |
| 7363 |
|
| 7364 |
|
| 7365 |
lastOffset = suballoc.offset + suballoc.size; |
| 7366 |
++nextAlloc2ndIndex; |
| 7367 |
} |
| 7368 |
|
| 7369 |
else |
| 7370 |
{ |
| 7371 |
|
| 7372 |
if (lastOffset < freeSpace2ndTo1stEnd) |
| 7373 |
{ |
| 7374 |
const VkDeviceSize unusedRangeSize = freeSpace2ndTo1stEnd - lastOffset; |
| 7375 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7376 |
} |
| 7377 |
|
| 7378 |
|
| 7379 |
lastOffset = freeSpace2ndTo1stEnd; |
| 7380 |
} |
| 7381 |
} |
| 7382 |
} |
| 7383 |
|
| 7384 |
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount; |
| 7385 |
const VkDeviceSize freeSpace1stTo2ndEnd = |
| 7386 |
m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size; |
| 7387 |
while (lastOffset < freeSpace1stTo2ndEnd) |
| 7388 |
{ |
| 7389 |
|
| 7390 |
while (nextAlloc1stIndex < suballoc1stCount && |
| 7391 |
suballocations1st[nextAlloc1stIndex].userData == VMA_NULL) |
| 7392 |
{ |
| 7393 |
++nextAlloc1stIndex; |
| 7394 |
} |
| 7395 |
|
| 7396 |
|
| 7397 |
if (nextAlloc1stIndex < suballoc1stCount) |
| 7398 |
{ |
| 7399 |
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex]; |
| 7400 |
|
| 7401 |
|
| 7402 |
if (lastOffset < suballoc.offset) |
| 7403 |
{ |
| 7404 |
|
| 7405 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7406 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7407 |
} |
| 7408 |
|
| 7409 |
|
| 7410 |
|
| 7411 |
VmaAddDetailedStatisticsAllocation(inoutStats, suballoc.size); |
| 7412 |
|
| 7413 |
|
| 7414 |
lastOffset = suballoc.offset + suballoc.size; |
| 7415 |
++nextAlloc1stIndex; |
| 7416 |
} |
| 7417 |
|
| 7418 |
else |
| 7419 |
{ |
| 7420 |
|
| 7421 |
if (lastOffset < freeSpace1stTo2ndEnd) |
| 7422 |
{ |
| 7423 |
const VkDeviceSize unusedRangeSize = freeSpace1stTo2ndEnd - lastOffset; |
| 7424 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7425 |
} |
| 7426 |
|
| 7427 |
|
| 7428 |
lastOffset = freeSpace1stTo2ndEnd; |
| 7429 |
} |
| 7430 |
} |
| 7431 |
|
| 7432 |
if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 7433 |
{ |
| 7434 |
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1; |
| 7435 |
while (lastOffset < size) |
| 7436 |
{ |
| 7437 |
|
| 7438 |
while (nextAlloc2ndIndex != SIZE_MAX && |
| 7439 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7440 |
{ |
| 7441 |
--nextAlloc2ndIndex; |
| 7442 |
} |
| 7443 |
|
| 7444 |
|
| 7445 |
if (nextAlloc2ndIndex != SIZE_MAX) |
| 7446 |
{ |
| 7447 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7448 |
|
| 7449 |
|
| 7450 |
if (lastOffset < suballoc.offset) |
| 7451 |
{ |
| 7452 |
|
| 7453 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7454 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7455 |
} |
| 7456 |
|
| 7457 |
|
| 7458 |
|
| 7459 |
VmaAddDetailedStatisticsAllocation(inoutStats, suballoc.size); |
| 7460 |
|
| 7461 |
|
| 7462 |
lastOffset = suballoc.offset + suballoc.size; |
| 7463 |
--nextAlloc2ndIndex; |
| 7464 |
} |
| 7465 |
|
| 7466 |
else |
| 7467 |
{ |
| 7468 |
|
| 7469 |
if (lastOffset < size) |
| 7470 |
{ |
| 7471 |
const VkDeviceSize unusedRangeSize = size - lastOffset; |
| 7472 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, unusedRangeSize); |
| 7473 |
} |
| 7474 |
|
| 7475 |
|
| 7476 |
lastOffset = size; |
| 7477 |
} |
| 7478 |
} |
| 7479 |
} |
| 7480 |
} |
| 7481 |
|
| 7482 |
void VmaBlockMetadata_Linear::AddStatistics(VmaStatistics& inoutStats) const |
| 7483 |
{ |
| 7484 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7485 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7486 |
const VkDeviceSize size = GetSize(); |
| 7487 |
const size_t suballoc1stCount = suballocations1st.size(); |
| 7488 |
const size_t suballoc2ndCount = suballocations2nd.size(); |
| 7489 |
|
| 7490 |
inoutStats.blockCount++; |
| 7491 |
inoutStats.blockBytes += size; |
| 7492 |
inoutStats.allocationBytes += size - m_SumFreeSize; |
| 7493 |
|
| 7494 |
VkDeviceSize lastOffset = 0; |
| 7495 |
|
| 7496 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 7497 |
{ |
| 7498 |
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset; |
| 7499 |
size_t nextAlloc2ndIndex = m_1stNullItemsBeginCount; |
| 7500 |
while (lastOffset < freeSpace2ndTo1stEnd) |
| 7501 |
{ |
| 7502 |
|
| 7503 |
while (nextAlloc2ndIndex < suballoc2ndCount && |
| 7504 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7505 |
{ |
| 7506 |
++nextAlloc2ndIndex; |
| 7507 |
} |
| 7508 |
|
| 7509 |
|
| 7510 |
if (nextAlloc2ndIndex < suballoc2ndCount) |
| 7511 |
{ |
| 7512 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7513 |
|
| 7514 |
|
| 7515 |
|
| 7516 |
++inoutStats.allocationCount; |
| 7517 |
|
| 7518 |
|
| 7519 |
lastOffset = suballoc.offset + suballoc.size; |
| 7520 |
++nextAlloc2ndIndex; |
| 7521 |
} |
| 7522 |
|
| 7523 |
else |
| 7524 |
{ |
| 7525 |
|
| 7526 |
lastOffset = freeSpace2ndTo1stEnd; |
| 7527 |
} |
| 7528 |
} |
| 7529 |
} |
| 7530 |
|
| 7531 |
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount; |
| 7532 |
const VkDeviceSize freeSpace1stTo2ndEnd = |
| 7533 |
m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size; |
| 7534 |
while (lastOffset < freeSpace1stTo2ndEnd) |
| 7535 |
{ |
| 7536 |
|
| 7537 |
while (nextAlloc1stIndex < suballoc1stCount && |
| 7538 |
suballocations1st[nextAlloc1stIndex].userData == VMA_NULL) |
| 7539 |
{ |
| 7540 |
++nextAlloc1stIndex; |
| 7541 |
} |
| 7542 |
|
| 7543 |
|
| 7544 |
if (nextAlloc1stIndex < suballoc1stCount) |
| 7545 |
{ |
| 7546 |
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex]; |
| 7547 |
|
| 7548 |
|
| 7549 |
|
| 7550 |
++inoutStats.allocationCount; |
| 7551 |
|
| 7552 |
|
| 7553 |
lastOffset = suballoc.offset + suballoc.size; |
| 7554 |
++nextAlloc1stIndex; |
| 7555 |
} |
| 7556 |
|
| 7557 |
else |
| 7558 |
{ |
| 7559 |
|
| 7560 |
lastOffset = freeSpace1stTo2ndEnd; |
| 7561 |
} |
| 7562 |
} |
| 7563 |
|
| 7564 |
if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 7565 |
{ |
| 7566 |
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1; |
| 7567 |
while (lastOffset < size) |
| 7568 |
{ |
| 7569 |
|
| 7570 |
while (nextAlloc2ndIndex != SIZE_MAX && |
| 7571 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7572 |
{ |
| 7573 |
--nextAlloc2ndIndex; |
| 7574 |
} |
| 7575 |
|
| 7576 |
|
| 7577 |
if (nextAlloc2ndIndex != SIZE_MAX) |
| 7578 |
{ |
| 7579 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7580 |
|
| 7581 |
|
| 7582 |
|
| 7583 |
++inoutStats.allocationCount; |
| 7584 |
|
| 7585 |
|
| 7586 |
lastOffset = suballoc.offset + suballoc.size; |
| 7587 |
--nextAlloc2ndIndex; |
| 7588 |
} |
| 7589 |
|
| 7590 |
else |
| 7591 |
{ |
| 7592 |
|
| 7593 |
lastOffset = size; |
| 7594 |
} |
| 7595 |
} |
| 7596 |
} |
| 7597 |
} |
| 7598 |
|
| 7599 |
#if VMA_STATS_STRING_ENABLED |
| 7600 |
void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const |
| 7601 |
{ |
| 7602 |
const VkDeviceSize size = GetSize(); |
| 7603 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7604 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7605 |
const size_t suballoc1stCount = suballocations1st.size(); |
| 7606 |
const size_t suballoc2ndCount = suballocations2nd.size(); |
| 7607 |
|
| 7608 |
|
| 7609 |
|
| 7610 |
size_t unusedRangeCount = 0; |
| 7611 |
VkDeviceSize usedBytes = 0; |
| 7612 |
|
| 7613 |
VkDeviceSize lastOffset = 0; |
| 7614 |
|
| 7615 |
size_t alloc2ndCount = 0; |
| 7616 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 7617 |
{ |
| 7618 |
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset; |
| 7619 |
size_t nextAlloc2ndIndex = 0; |
| 7620 |
while (lastOffset < freeSpace2ndTo1stEnd) |
| 7621 |
{ |
| 7622 |
|
| 7623 |
while (nextAlloc2ndIndex < suballoc2ndCount && |
| 7624 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7625 |
{ |
| 7626 |
++nextAlloc2ndIndex; |
| 7627 |
} |
| 7628 |
|
| 7629 |
|
| 7630 |
if (nextAlloc2ndIndex < suballoc2ndCount) |
| 7631 |
{ |
| 7632 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7633 |
|
| 7634 |
|
| 7635 |
if (lastOffset < suballoc.offset) |
| 7636 |
{ |
| 7637 |
|
| 7638 |
++unusedRangeCount; |
| 7639 |
} |
| 7640 |
|
| 7641 |
|
| 7642 |
|
| 7643 |
++alloc2ndCount; |
| 7644 |
usedBytes += suballoc.size; |
| 7645 |
|
| 7646 |
|
| 7647 |
lastOffset = suballoc.offset + suballoc.size; |
| 7648 |
++nextAlloc2ndIndex; |
| 7649 |
} |
| 7650 |
|
| 7651 |
else |
| 7652 |
{ |
| 7653 |
if (lastOffset < freeSpace2ndTo1stEnd) |
| 7654 |
{ |
| 7655 |
|
| 7656 |
++unusedRangeCount; |
| 7657 |
} |
| 7658 |
|
| 7659 |
|
| 7660 |
lastOffset = freeSpace2ndTo1stEnd; |
| 7661 |
} |
| 7662 |
} |
| 7663 |
} |
| 7664 |
|
| 7665 |
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount; |
| 7666 |
size_t alloc1stCount = 0; |
| 7667 |
const VkDeviceSize freeSpace1stTo2ndEnd = |
| 7668 |
m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size; |
| 7669 |
while (lastOffset < freeSpace1stTo2ndEnd) |
| 7670 |
{ |
| 7671 |
|
| 7672 |
while (nextAlloc1stIndex < suballoc1stCount && |
| 7673 |
suballocations1st[nextAlloc1stIndex].userData == VMA_NULL) |
| 7674 |
{ |
| 7675 |
++nextAlloc1stIndex; |
| 7676 |
} |
| 7677 |
|
| 7678 |
|
| 7679 |
if (nextAlloc1stIndex < suballoc1stCount) |
| 7680 |
{ |
| 7681 |
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex]; |
| 7682 |
|
| 7683 |
|
| 7684 |
if (lastOffset < suballoc.offset) |
| 7685 |
{ |
| 7686 |
|
| 7687 |
++unusedRangeCount; |
| 7688 |
} |
| 7689 |
|
| 7690 |
|
| 7691 |
|
| 7692 |
++alloc1stCount; |
| 7693 |
usedBytes += suballoc.size; |
| 7694 |
|
| 7695 |
|
| 7696 |
lastOffset = suballoc.offset + suballoc.size; |
| 7697 |
++nextAlloc1stIndex; |
| 7698 |
} |
| 7699 |
|
| 7700 |
else |
| 7701 |
{ |
| 7702 |
if (lastOffset < freeSpace1stTo2ndEnd) |
| 7703 |
{ |
| 7704 |
|
| 7705 |
++unusedRangeCount; |
| 7706 |
} |
| 7707 |
|
| 7708 |
|
| 7709 |
lastOffset = freeSpace1stTo2ndEnd; |
| 7710 |
} |
| 7711 |
} |
| 7712 |
|
| 7713 |
if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 7714 |
{ |
| 7715 |
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1; |
| 7716 |
while (lastOffset < size) |
| 7717 |
{ |
| 7718 |
|
| 7719 |
while (nextAlloc2ndIndex != SIZE_MAX && |
| 7720 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7721 |
{ |
| 7722 |
--nextAlloc2ndIndex; |
| 7723 |
} |
| 7724 |
|
| 7725 |
|
| 7726 |
if (nextAlloc2ndIndex != SIZE_MAX) |
| 7727 |
{ |
| 7728 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7729 |
|
| 7730 |
|
| 7731 |
if (lastOffset < suballoc.offset) |
| 7732 |
{ |
| 7733 |
|
| 7734 |
++unusedRangeCount; |
| 7735 |
} |
| 7736 |
|
| 7737 |
|
| 7738 |
|
| 7739 |
++alloc2ndCount; |
| 7740 |
usedBytes += suballoc.size; |
| 7741 |
|
| 7742 |
|
| 7743 |
lastOffset = suballoc.offset + suballoc.size; |
| 7744 |
--nextAlloc2ndIndex; |
| 7745 |
} |
| 7746 |
|
| 7747 |
else |
| 7748 |
{ |
| 7749 |
if (lastOffset < size) |
| 7750 |
{ |
| 7751 |
|
| 7752 |
++unusedRangeCount; |
| 7753 |
} |
| 7754 |
|
| 7755 |
|
| 7756 |
lastOffset = size; |
| 7757 |
} |
| 7758 |
} |
| 7759 |
} |
| 7760 |
|
| 7761 |
const VkDeviceSize unusedBytes = size - usedBytes; |
| 7762 |
PrintDetailedMap_Begin(json, unusedBytes, alloc1stCount + alloc2ndCount, unusedRangeCount); |
| 7763 |
|
| 7764 |
|
| 7765 |
lastOffset = 0; |
| 7766 |
|
| 7767 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 7768 |
{ |
| 7769 |
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset; |
| 7770 |
size_t nextAlloc2ndIndex = 0; |
| 7771 |
while (lastOffset < freeSpace2ndTo1stEnd) |
| 7772 |
{ |
| 7773 |
|
| 7774 |
while (nextAlloc2ndIndex < suballoc2ndCount && |
| 7775 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7776 |
{ |
| 7777 |
++nextAlloc2ndIndex; |
| 7778 |
} |
| 7779 |
|
| 7780 |
|
| 7781 |
if (nextAlloc2ndIndex < suballoc2ndCount) |
| 7782 |
{ |
| 7783 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7784 |
|
| 7785 |
|
| 7786 |
if (lastOffset < suballoc.offset) |
| 7787 |
{ |
| 7788 |
|
| 7789 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7790 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7791 |
} |
| 7792 |
|
| 7793 |
|
| 7794 |
|
| 7795 |
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.size, suballoc.userData); |
| 7796 |
|
| 7797 |
|
| 7798 |
lastOffset = suballoc.offset + suballoc.size; |
| 7799 |
++nextAlloc2ndIndex; |
| 7800 |
} |
| 7801 |
|
| 7802 |
else |
| 7803 |
{ |
| 7804 |
if (lastOffset < freeSpace2ndTo1stEnd) |
| 7805 |
{ |
| 7806 |
|
| 7807 |
const VkDeviceSize unusedRangeSize = freeSpace2ndTo1stEnd - lastOffset; |
| 7808 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7809 |
} |
| 7810 |
|
| 7811 |
|
| 7812 |
lastOffset = freeSpace2ndTo1stEnd; |
| 7813 |
} |
| 7814 |
} |
| 7815 |
} |
| 7816 |
|
| 7817 |
nextAlloc1stIndex = m_1stNullItemsBeginCount; |
| 7818 |
while (lastOffset < freeSpace1stTo2ndEnd) |
| 7819 |
{ |
| 7820 |
|
| 7821 |
while (nextAlloc1stIndex < suballoc1stCount && |
| 7822 |
suballocations1st[nextAlloc1stIndex].userData == VMA_NULL) |
| 7823 |
{ |
| 7824 |
++nextAlloc1stIndex; |
| 7825 |
} |
| 7826 |
|
| 7827 |
|
| 7828 |
if (nextAlloc1stIndex < suballoc1stCount) |
| 7829 |
{ |
| 7830 |
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex]; |
| 7831 |
|
| 7832 |
|
| 7833 |
if (lastOffset < suballoc.offset) |
| 7834 |
{ |
| 7835 |
|
| 7836 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7837 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7838 |
} |
| 7839 |
|
| 7840 |
|
| 7841 |
|
| 7842 |
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.size, suballoc.userData); |
| 7843 |
|
| 7844 |
|
| 7845 |
lastOffset = suballoc.offset + suballoc.size; |
| 7846 |
++nextAlloc1stIndex; |
| 7847 |
} |
| 7848 |
|
| 7849 |
else |
| 7850 |
{ |
| 7851 |
if (lastOffset < freeSpace1stTo2ndEnd) |
| 7852 |
{ |
| 7853 |
|
| 7854 |
const VkDeviceSize unusedRangeSize = freeSpace1stTo2ndEnd - lastOffset; |
| 7855 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7856 |
} |
| 7857 |
|
| 7858 |
|
| 7859 |
lastOffset = freeSpace1stTo2ndEnd; |
| 7860 |
} |
| 7861 |
} |
| 7862 |
|
| 7863 |
if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 7864 |
{ |
| 7865 |
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1; |
| 7866 |
while (lastOffset < size) |
| 7867 |
{ |
| 7868 |
|
| 7869 |
while (nextAlloc2ndIndex != SIZE_MAX && |
| 7870 |
suballocations2nd[nextAlloc2ndIndex].userData == VMA_NULL) |
| 7871 |
{ |
| 7872 |
--nextAlloc2ndIndex; |
| 7873 |
} |
| 7874 |
|
| 7875 |
|
| 7876 |
if (nextAlloc2ndIndex != SIZE_MAX) |
| 7877 |
{ |
| 7878 |
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex]; |
| 7879 |
|
| 7880 |
|
| 7881 |
if (lastOffset < suballoc.offset) |
| 7882 |
{ |
| 7883 |
|
| 7884 |
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset; |
| 7885 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7886 |
} |
| 7887 |
|
| 7888 |
|
| 7889 |
|
| 7890 |
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.size, suballoc.userData); |
| 7891 |
|
| 7892 |
|
| 7893 |
lastOffset = suballoc.offset + suballoc.size; |
| 7894 |
--nextAlloc2ndIndex; |
| 7895 |
} |
| 7896 |
|
| 7897 |
else |
| 7898 |
{ |
| 7899 |
if (lastOffset < size) |
| 7900 |
{ |
| 7901 |
|
| 7902 |
const VkDeviceSize unusedRangeSize = size - lastOffset; |
| 7903 |
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize); |
| 7904 |
} |
| 7905 |
|
| 7906 |
|
| 7907 |
lastOffset = size; |
| 7908 |
} |
| 7909 |
} |
| 7910 |
} |
| 7911 |
|
| 7912 |
PrintDetailedMap_End(json); |
| 7913 |
} |
| 7914 |
#endif |
| 7915 |
|
| 7916 |
bool VmaBlockMetadata_Linear::CreateAllocationRequest( |
| 7917 |
VkDeviceSize allocSize, |
| 7918 |
VkDeviceSize allocAlignment, |
| 7919 |
bool upperAddress, |
| 7920 |
VmaSuballocationType allocType, |
| 7921 |
uint32_t strategy, |
| 7922 |
VmaAllocationRequest* pAllocationRequest) |
| 7923 |
{ |
| 7924 |
VMA_ASSERT(allocSize > 0); |
| 7925 |
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE); |
| 7926 |
VMA_ASSERT(pAllocationRequest != VMA_NULL); |
| 7927 |
VMA_HEAVY_ASSERT(Validate()); |
| 7928 |
|
| 7929 |
if(allocSize > GetSize()) |
| 7930 |
return false; |
| 7931 |
|
| 7932 |
pAllocationRequest->size = allocSize; |
| 7933 |
return upperAddress ? |
| 7934 |
CreateAllocationRequest_UpperAddress( |
| 7935 |
allocSize, allocAlignment, allocType, strategy, pAllocationRequest) : |
| 7936 |
CreateAllocationRequest_LowerAddress( |
| 7937 |
allocSize, allocAlignment, allocType, strategy, pAllocationRequest); |
| 7938 |
} |
| 7939 |
|
| 7940 |
VkResult VmaBlockMetadata_Linear::CheckCorruption(const void* pBlockData) |
| 7941 |
{ |
| 7942 |
VMA_ASSERT(!IsVirtual()); |
| 7943 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7944 |
for (size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i) |
| 7945 |
{ |
| 7946 |
const VmaSuballocation& suballoc = suballocations1st[i]; |
| 7947 |
if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) |
| 7948 |
{ |
| 7949 |
if (!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size)) |
| 7950 |
{ |
| 7951 |
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!"); |
| 7952 |
return VK_ERROR_UNKNOWN_COPY; |
| 7953 |
} |
| 7954 |
} |
| 7955 |
} |
| 7956 |
|
| 7957 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7958 |
for (size_t i = 0, count = suballocations2nd.size(); i < count; ++i) |
| 7959 |
{ |
| 7960 |
const VmaSuballocation& suballoc = suballocations2nd[i]; |
| 7961 |
if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) |
| 7962 |
{ |
| 7963 |
if (!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size)) |
| 7964 |
{ |
| 7965 |
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!"); |
| 7966 |
return VK_ERROR_UNKNOWN_COPY; |
| 7967 |
} |
| 7968 |
} |
| 7969 |
} |
| 7970 |
|
| 7971 |
return VK_SUCCESS; |
| 7972 |
} |
| 7973 |
|
| 7974 |
void VmaBlockMetadata_Linear::Alloc( |
| 7975 |
const VmaAllocationRequest& request, |
| 7976 |
VmaSuballocationType type, |
| 7977 |
void* userData) |
| 7978 |
{ |
| 7979 |
const VkDeviceSize offset = (VkDeviceSize)request.allocHandle - 1; |
| 7980 |
const VmaSuballocation newSuballoc = { offset, request.size, userData, type }; |
| 7981 |
|
| 7982 |
switch (request.type) |
| 7983 |
{ |
| 7984 |
case VmaAllocationRequestType::UpperAddress: |
| 7985 |
{ |
| 7986 |
VMA_ASSERT(m_2ndVectorMode != SECOND_VECTOR_RING_BUFFER && |
| 7987 |
"CRITICAL ERROR: Trying to use linear allocator as double stack while it was already used as ring buffer."); |
| 7988 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 7989 |
suballocations2nd.push_back(newSuballoc); |
| 7990 |
m_2ndVectorMode = SECOND_VECTOR_DOUBLE_STACK; |
| 7991 |
} |
| 7992 |
break; |
| 7993 |
case VmaAllocationRequestType::EndOf1st: |
| 7994 |
{ |
| 7995 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 7996 |
|
| 7997 |
VMA_ASSERT(suballocations1st.empty() || |
| 7998 |
offset >= suballocations1st.back().offset + suballocations1st.back().size); |
| 7999 |
|
| 8000 |
VMA_ASSERT(offset + request.size <= GetSize()); |
| 8001 |
|
| 8002 |
suballocations1st.push_back(newSuballoc); |
| 8003 |
} |
| 8004 |
break; |
| 8005 |
case VmaAllocationRequestType::EndOf2nd: |
| 8006 |
{ |
| 8007 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8008 |
|
| 8009 |
VMA_ASSERT(!suballocations1st.empty() && |
| 8010 |
offset + request.size <= suballocations1st[m_1stNullItemsBeginCount].offset); |
| 8011 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8012 |
|
| 8013 |
switch (m_2ndVectorMode) |
| 8014 |
{ |
| 8015 |
case SECOND_VECTOR_EMPTY: |
| 8016 |
|
| 8017 |
VMA_ASSERT(suballocations2nd.empty()); |
| 8018 |
m_2ndVectorMode = SECOND_VECTOR_RING_BUFFER; |
| 8019 |
break; |
| 8020 |
case SECOND_VECTOR_RING_BUFFER: |
| 8021 |
|
| 8022 |
VMA_ASSERT(!suballocations2nd.empty()); |
| 8023 |
break; |
| 8024 |
case SECOND_VECTOR_DOUBLE_STACK: |
| 8025 |
VMA_ASSERT(0 && "CRITICAL ERROR: Trying to use linear allocator as ring buffer while it was already used as double stack."); |
| 8026 |
break; |
| 8027 |
default: |
| 8028 |
VMA_ASSERT(0); |
| 8029 |
} |
| 8030 |
|
| 8031 |
suballocations2nd.push_back(newSuballoc); |
| 8032 |
} |
| 8033 |
break; |
| 8034 |
default: |
| 8035 |
VMA_ASSERT(0 && "CRITICAL INTERNAL ERROR."); |
| 8036 |
} |
| 8037 |
|
| 8038 |
m_SumFreeSize -= newSuballoc.size; |
| 8039 |
} |
| 8040 |
|
| 8041 |
void VmaBlockMetadata_Linear::Free(VmaAllocHandle allocHandle) |
| 8042 |
{ |
| 8043 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8044 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8045 |
VkDeviceSize offset = (VkDeviceSize)allocHandle - 1; |
| 8046 |
|
| 8047 |
if (!suballocations1st.empty()) |
| 8048 |
{ |
| 8049 |
|
| 8050 |
VmaSuballocation& firstSuballoc = suballocations1st[m_1stNullItemsBeginCount]; |
| 8051 |
if (firstSuballoc.offset == offset) |
| 8052 |
{ |
| 8053 |
firstSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE; |
| 8054 |
firstSuballoc.userData = VMA_NULL; |
| 8055 |
m_SumFreeSize += firstSuballoc.size; |
| 8056 |
++m_1stNullItemsBeginCount; |
| 8057 |
CleanupAfterFree(); |
| 8058 |
return; |
| 8059 |
} |
| 8060 |
} |
| 8061 |
|
| 8062 |
|
| 8063 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER || |
| 8064 |
m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 8065 |
{ |
| 8066 |
VmaSuballocation& lastSuballoc = suballocations2nd.back(); |
| 8067 |
if (lastSuballoc.offset == offset) |
| 8068 |
{ |
| 8069 |
m_SumFreeSize += lastSuballoc.size; |
| 8070 |
suballocations2nd.pop_back(); |
| 8071 |
CleanupAfterFree(); |
| 8072 |
return; |
| 8073 |
} |
| 8074 |
} |
| 8075 |
|
| 8076 |
else if (m_2ndVectorMode == SECOND_VECTOR_EMPTY) |
| 8077 |
{ |
| 8078 |
VmaSuballocation& lastSuballoc = suballocations1st.back(); |
| 8079 |
if (lastSuballoc.offset == offset) |
| 8080 |
{ |
| 8081 |
m_SumFreeSize += lastSuballoc.size; |
| 8082 |
suballocations1st.pop_back(); |
| 8083 |
CleanupAfterFree(); |
| 8084 |
return; |
| 8085 |
} |
| 8086 |
} |
| 8087 |
|
| 8088 |
VmaSuballocation refSuballoc; |
| 8089 |
refSuballoc.offset = offset; |
| 8090 |
|
| 8091 |
|
| 8092 |
|
| 8093 |
{ |
| 8094 |
const SuballocationVectorType::iterator it = VmaBinaryFindSorted( |
| 8095 |
suballocations1st.begin() + m_1stNullItemsBeginCount, |
| 8096 |
suballocations1st.end(), |
| 8097 |
refSuballoc, |
| 8098 |
VmaSuballocationOffsetLess()); |
| 8099 |
if (it != suballocations1st.end()) |
| 8100 |
{ |
| 8101 |
it->type = VMA_SUBALLOCATION_TYPE_FREE; |
| 8102 |
it->userData = VMA_NULL; |
| 8103 |
++m_1stNullItemsMiddleCount; |
| 8104 |
m_SumFreeSize += it->size; |
| 8105 |
CleanupAfterFree(); |
| 8106 |
return; |
| 8107 |
} |
| 8108 |
} |
| 8109 |
|
| 8110 |
if (m_2ndVectorMode != SECOND_VECTOR_EMPTY) |
| 8111 |
{ |
| 8112 |
|
| 8113 |
const SuballocationVectorType::iterator it = m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ? |
| 8114 |
VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetLess()) : |
| 8115 |
VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetGreater()); |
| 8116 |
if (it != suballocations2nd.end()) |
| 8117 |
{ |
| 8118 |
it->type = VMA_SUBALLOCATION_TYPE_FREE; |
| 8119 |
it->userData = VMA_NULL; |
| 8120 |
++m_2ndNullItemsCount; |
| 8121 |
m_SumFreeSize += it->size; |
| 8122 |
CleanupAfterFree(); |
| 8123 |
return; |
| 8124 |
} |
| 8125 |
} |
| 8126 |
|
| 8127 |
VMA_ASSERT(0 && "Allocation to free not found in linear allocator!"); |
| 8128 |
} |
| 8129 |
|
| 8130 |
void VmaBlockMetadata_Linear::GetAllocationInfo(VmaAllocHandle allocHandle, VmaVirtualAllocationInfo& outInfo) |
| 8131 |
{ |
| 8132 |
outInfo.offset = (VkDeviceSize)allocHandle - 1; |
| 8133 |
VmaSuballocation& suballoc = FindSuballocation(outInfo.offset); |
| 8134 |
outInfo.size = suballoc.size; |
| 8135 |
outInfo.pUserData = suballoc.userData; |
| 8136 |
} |
| 8137 |
|
| 8138 |
void* VmaBlockMetadata_Linear::GetAllocationUserData(VmaAllocHandle allocHandle) const |
| 8139 |
{ |
| 8140 |
return FindSuballocation((VkDeviceSize)allocHandle - 1).userData; |
| 8141 |
} |
| 8142 |
|
| 8143 |
VmaAllocHandle VmaBlockMetadata_Linear::GetAllocationListBegin() const |
| 8144 |
{ |
| 8145 |
|
| 8146 |
VMA_ASSERT(0); |
| 8147 |
return VK_NULL_HANDLE; |
| 8148 |
} |
| 8149 |
|
| 8150 |
VmaAllocHandle VmaBlockMetadata_Linear::GetNextAllocation(VmaAllocHandle prevAlloc) const |
| 8151 |
{ |
| 8152 |
|
| 8153 |
VMA_ASSERT(0); |
| 8154 |
return VK_NULL_HANDLE; |
| 8155 |
} |
| 8156 |
|
| 8157 |
VkDeviceSize VmaBlockMetadata_Linear::GetNextFreeRegionSize(VmaAllocHandle alloc) const |
| 8158 |
{ |
| 8159 |
|
| 8160 |
VMA_ASSERT(0); |
| 8161 |
return 0; |
| 8162 |
} |
| 8163 |
|
| 8164 |
void VmaBlockMetadata_Linear::Clear() |
| 8165 |
{ |
| 8166 |
m_SumFreeSize = GetSize(); |
| 8167 |
m_Suballocations0.clear(); |
| 8168 |
m_Suballocations1.clear(); |
| 8169 |
|
| 8170 |
m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8171 |
m_1stNullItemsBeginCount = 0; |
| 8172 |
m_1stNullItemsMiddleCount = 0; |
| 8173 |
m_2ndNullItemsCount = 0; |
| 8174 |
} |
| 8175 |
|
| 8176 |
void VmaBlockMetadata_Linear::SetAllocationUserData(VmaAllocHandle allocHandle, void* userData) |
| 8177 |
{ |
| 8178 |
VmaSuballocation& suballoc = FindSuballocation((VkDeviceSize)allocHandle - 1); |
| 8179 |
suballoc.userData = userData; |
| 8180 |
} |
| 8181 |
|
| 8182 |
void VmaBlockMetadata_Linear::DebugLogAllAllocations() const |
| 8183 |
{ |
| 8184 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8185 |
for (auto it = suballocations1st.begin() + m_1stNullItemsBeginCount; it != suballocations1st.end(); ++it) |
| 8186 |
if (it->type != VMA_SUBALLOCATION_TYPE_FREE) |
| 8187 |
DebugLogAllocation(it->offset, it->size, it->userData); |
| 8188 |
|
| 8189 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8190 |
for (auto it = suballocations2nd.begin(); it != suballocations2nd.end(); ++it) |
| 8191 |
if (it->type != VMA_SUBALLOCATION_TYPE_FREE) |
| 8192 |
DebugLogAllocation(it->offset, it->size, it->userData); |
| 8193 |
} |
| 8194 |
|
| 8195 |
VmaSuballocation& VmaBlockMetadata_Linear::FindSuballocation(VkDeviceSize offset) const |
| 8196 |
{ |
| 8197 |
const SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8198 |
const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8199 |
|
| 8200 |
VmaSuballocation refSuballoc; |
| 8201 |
refSuballoc.offset = offset; |
| 8202 |
|
| 8203 |
|
| 8204 |
|
| 8205 |
{ |
| 8206 |
SuballocationVectorType::const_iterator it = VmaBinaryFindSorted( |
| 8207 |
suballocations1st.begin() + m_1stNullItemsBeginCount, |
| 8208 |
suballocations1st.end(), |
| 8209 |
refSuballoc, |
| 8210 |
VmaSuballocationOffsetLess()); |
| 8211 |
if (it != suballocations1st.end()) |
| 8212 |
{ |
| 8213 |
return const_cast<VmaSuballocation&>(*it); |
| 8214 |
} |
| 8215 |
} |
| 8216 |
|
| 8217 |
if (m_2ndVectorMode != SECOND_VECTOR_EMPTY) |
| 8218 |
{ |
| 8219 |
|
| 8220 |
SuballocationVectorType::const_iterator it = m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ? |
| 8221 |
VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetLess()) : |
| 8222 |
VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetGreater()); |
| 8223 |
if (it != suballocations2nd.end()) |
| 8224 |
{ |
| 8225 |
return const_cast<VmaSuballocation&>(*it); |
| 8226 |
} |
| 8227 |
} |
| 8228 |
|
| 8229 |
VMA_ASSERT(0 && "Allocation not found in linear allocator!"); |
| 8230 |
return const_cast<VmaSuballocation&>(suballocations1st.back()); |
| 8231 |
} |
| 8232 |
|
| 8233 |
bool VmaBlockMetadata_Linear::ShouldCompact1st() const |
| 8234 |
{ |
| 8235 |
const size_t nullItemCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount; |
| 8236 |
const size_t suballocCount = AccessSuballocations1st().size(); |
| 8237 |
return suballocCount > 32 && nullItemCount * 2 >= (suballocCount - nullItemCount) * 3; |
| 8238 |
} |
| 8239 |
|
| 8240 |
void VmaBlockMetadata_Linear::CleanupAfterFree() |
| 8241 |
{ |
| 8242 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8243 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8244 |
|
| 8245 |
if (IsEmpty()) |
| 8246 |
{ |
| 8247 |
suballocations1st.clear(); |
| 8248 |
suballocations2nd.clear(); |
| 8249 |
m_1stNullItemsBeginCount = 0; |
| 8250 |
m_1stNullItemsMiddleCount = 0; |
| 8251 |
m_2ndNullItemsCount = 0; |
| 8252 |
m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8253 |
} |
| 8254 |
else |
| 8255 |
{ |
| 8256 |
const size_t suballoc1stCount = suballocations1st.size(); |
| 8257 |
const size_t nullItem1stCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount; |
| 8258 |
VMA_ASSERT(nullItem1stCount <= suballoc1stCount); |
| 8259 |
|
| 8260 |
|
| 8261 |
while (m_1stNullItemsBeginCount < suballoc1stCount && |
| 8262 |
suballocations1st[m_1stNullItemsBeginCount].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8263 |
{ |
| 8264 |
++m_1stNullItemsBeginCount; |
| 8265 |
--m_1stNullItemsMiddleCount; |
| 8266 |
} |
| 8267 |
|
| 8268 |
|
| 8269 |
while (m_1stNullItemsMiddleCount > 0 && |
| 8270 |
suballocations1st.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8271 |
{ |
| 8272 |
--m_1stNullItemsMiddleCount; |
| 8273 |
suballocations1st.pop_back(); |
| 8274 |
} |
| 8275 |
|
| 8276 |
|
| 8277 |
while (m_2ndNullItemsCount > 0 && |
| 8278 |
suballocations2nd.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8279 |
{ |
| 8280 |
--m_2ndNullItemsCount; |
| 8281 |
suballocations2nd.pop_back(); |
| 8282 |
} |
| 8283 |
|
| 8284 |
|
| 8285 |
while (m_2ndNullItemsCount > 0 && |
| 8286 |
suballocations2nd[0].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8287 |
{ |
| 8288 |
--m_2ndNullItemsCount; |
| 8289 |
VmaVectorRemove(suballocations2nd, 0); |
| 8290 |
} |
| 8291 |
|
| 8292 |
if (ShouldCompact1st()) |
| 8293 |
{ |
| 8294 |
const size_t nonNullItemCount = suballoc1stCount - nullItem1stCount; |
| 8295 |
size_t srcIndex = m_1stNullItemsBeginCount; |
| 8296 |
for (size_t dstIndex = 0; dstIndex < nonNullItemCount; ++dstIndex) |
| 8297 |
{ |
| 8298 |
while (suballocations1st[srcIndex].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8299 |
{ |
| 8300 |
++srcIndex; |
| 8301 |
} |
| 8302 |
if (dstIndex != srcIndex) |
| 8303 |
{ |
| 8304 |
suballocations1st[dstIndex] = suballocations1st[srcIndex]; |
| 8305 |
} |
| 8306 |
++srcIndex; |
| 8307 |
} |
| 8308 |
suballocations1st.resize(nonNullItemCount); |
| 8309 |
m_1stNullItemsBeginCount = 0; |
| 8310 |
m_1stNullItemsMiddleCount = 0; |
| 8311 |
} |
| 8312 |
|
| 8313 |
|
| 8314 |
if (suballocations2nd.empty()) |
| 8315 |
{ |
| 8316 |
m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8317 |
} |
| 8318 |
|
| 8319 |
|
| 8320 |
if (suballocations1st.size() - m_1stNullItemsBeginCount == 0) |
| 8321 |
{ |
| 8322 |
suballocations1st.clear(); |
| 8323 |
m_1stNullItemsBeginCount = 0; |
| 8324 |
|
| 8325 |
if (!suballocations2nd.empty() && m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 8326 |
{ |
| 8327 |
|
| 8328 |
m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8329 |
m_1stNullItemsMiddleCount = m_2ndNullItemsCount; |
| 8330 |
while (m_1stNullItemsBeginCount < suballocations2nd.size() && |
| 8331 |
suballocations2nd[m_1stNullItemsBeginCount].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8332 |
{ |
| 8333 |
++m_1stNullItemsBeginCount; |
| 8334 |
--m_1stNullItemsMiddleCount; |
| 8335 |
} |
| 8336 |
m_2ndNullItemsCount = 0; |
| 8337 |
m_1stVectorIndex ^= 1; |
| 8338 |
} |
| 8339 |
} |
| 8340 |
} |
| 8341 |
|
| 8342 |
VMA_HEAVY_ASSERT(Validate()); |
| 8343 |
} |
| 8344 |
|
| 8345 |
bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress( |
| 8346 |
VkDeviceSize allocSize, |
| 8347 |
VkDeviceSize allocAlignment, |
| 8348 |
VmaSuballocationType allocType, |
| 8349 |
uint32_t strategy, |
| 8350 |
VmaAllocationRequest* pAllocationRequest) |
| 8351 |
{ |
| 8352 |
const VkDeviceSize blockSize = GetSize(); |
| 8353 |
const VkDeviceSize debugMargin = GetDebugMargin(); |
| 8354 |
const VkDeviceSize bufferImageGranularity = GetBufferImageGranularity(); |
| 8355 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8356 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8357 |
|
| 8358 |
if (m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 8359 |
{ |
| 8360 |
|
| 8361 |
|
| 8362 |
VkDeviceSize resultBaseOffset = 0; |
| 8363 |
if (!suballocations1st.empty()) |
| 8364 |
{ |
| 8365 |
const VmaSuballocation& lastSuballoc = suballocations1st.back(); |
| 8366 |
resultBaseOffset = lastSuballoc.offset + lastSuballoc.size + debugMargin; |
| 8367 |
} |
| 8368 |
|
| 8369 |
|
| 8370 |
VkDeviceSize resultOffset = resultBaseOffset; |
| 8371 |
|
| 8372 |
|
| 8373 |
resultOffset = VmaAlignUp(resultOffset, allocAlignment); |
| 8374 |
|
| 8375 |
|
| 8376 |
|
| 8377 |
if (bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations1st.empty()) |
| 8378 |
{ |
| 8379 |
bool bufferImageGranularityConflict = false; |
| 8380 |
for (size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--; ) |
| 8381 |
{ |
| 8382 |
const VmaSuballocation& prevSuballoc = suballocations1st[prevSuballocIndex]; |
| 8383 |
if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) |
| 8384 |
{ |
| 8385 |
if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) |
| 8386 |
{ |
| 8387 |
bufferImageGranularityConflict = true; |
| 8388 |
break; |
| 8389 |
} |
| 8390 |
} |
| 8391 |
else |
| 8392 |
|
| 8393 |
break; |
| 8394 |
} |
| 8395 |
if (bufferImageGranularityConflict) |
| 8396 |
{ |
| 8397 |
resultOffset = VmaAlignUp(resultOffset, bufferImageGranularity); |
| 8398 |
} |
| 8399 |
} |
| 8400 |
|
| 8401 |
const VkDeviceSize freeSpaceEnd = m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? |
| 8402 |
suballocations2nd.back().offset : blockSize; |
| 8403 |
|
| 8404 |
|
| 8405 |
if (resultOffset + allocSize + debugMargin <= freeSpaceEnd) |
| 8406 |
{ |
| 8407 |
|
| 8408 |
|
| 8409 |
if ((allocSize % bufferImageGranularity || resultOffset % bufferImageGranularity) && m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) |
| 8410 |
{ |
| 8411 |
for (size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; ) |
| 8412 |
{ |
| 8413 |
const VmaSuballocation& nextSuballoc = suballocations2nd[nextSuballocIndex]; |
| 8414 |
if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) |
| 8415 |
{ |
| 8416 |
if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) |
| 8417 |
{ |
| 8418 |
return false; |
| 8419 |
} |
| 8420 |
} |
| 8421 |
else |
| 8422 |
{ |
| 8423 |
|
| 8424 |
break; |
| 8425 |
} |
| 8426 |
} |
| 8427 |
} |
| 8428 |
|
| 8429 |
|
| 8430 |
pAllocationRequest->allocHandle = (VmaAllocHandle)(resultOffset + 1); |
| 8431 |
|
| 8432 |
pAllocationRequest->type = VmaAllocationRequestType::EndOf1st; |
| 8433 |
return true; |
| 8434 |
} |
| 8435 |
} |
| 8436 |
|
| 8437 |
|
| 8438 |
|
| 8439 |
if (m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 8440 |
{ |
| 8441 |
VMA_ASSERT(!suballocations1st.empty()); |
| 8442 |
|
| 8443 |
VkDeviceSize resultBaseOffset = 0; |
| 8444 |
if (!suballocations2nd.empty()) |
| 8445 |
{ |
| 8446 |
const VmaSuballocation& lastSuballoc = suballocations2nd.back(); |
| 8447 |
resultBaseOffset = lastSuballoc.offset + lastSuballoc.size + debugMargin; |
| 8448 |
} |
| 8449 |
|
| 8450 |
|
| 8451 |
VkDeviceSize resultOffset = resultBaseOffset; |
| 8452 |
|
| 8453 |
|
| 8454 |
resultOffset = VmaAlignUp(resultOffset, allocAlignment); |
| 8455 |
|
| 8456 |
|
| 8457 |
|
| 8458 |
if (bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations2nd.empty()) |
| 8459 |
{ |
| 8460 |
bool bufferImageGranularityConflict = false; |
| 8461 |
for (size_t prevSuballocIndex = suballocations2nd.size(); prevSuballocIndex--; ) |
| 8462 |
{ |
| 8463 |
const VmaSuballocation& prevSuballoc = suballocations2nd[prevSuballocIndex]; |
| 8464 |
if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) |
| 8465 |
{ |
| 8466 |
if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) |
| 8467 |
{ |
| 8468 |
bufferImageGranularityConflict = true; |
| 8469 |
break; |
| 8470 |
} |
| 8471 |
} |
| 8472 |
else |
| 8473 |
|
| 8474 |
break; |
| 8475 |
} |
| 8476 |
if (bufferImageGranularityConflict) |
| 8477 |
{ |
| 8478 |
resultOffset = VmaAlignUp(resultOffset, bufferImageGranularity); |
| 8479 |
} |
| 8480 |
} |
| 8481 |
|
| 8482 |
size_t index1st = m_1stNullItemsBeginCount; |
| 8483 |
|
| 8484 |
|
| 8485 |
if ((index1st == suballocations1st.size() && resultOffset + allocSize + debugMargin <= blockSize) || |
| 8486 |
(index1st < suballocations1st.size() && resultOffset + allocSize + debugMargin <= suballocations1st[index1st].offset)) |
| 8487 |
{ |
| 8488 |
|
| 8489 |
|
| 8490 |
if (allocSize % bufferImageGranularity || resultOffset % bufferImageGranularity) |
| 8491 |
{ |
| 8492 |
for (size_t nextSuballocIndex = index1st; |
| 8493 |
nextSuballocIndex < suballocations1st.size(); |
| 8494 |
nextSuballocIndex++) |
| 8495 |
{ |
| 8496 |
const VmaSuballocation& nextSuballoc = suballocations1st[nextSuballocIndex]; |
| 8497 |
if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) |
| 8498 |
{ |
| 8499 |
if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) |
| 8500 |
{ |
| 8501 |
return false; |
| 8502 |
} |
| 8503 |
} |
| 8504 |
else |
| 8505 |
{ |
| 8506 |
|
| 8507 |
break; |
| 8508 |
} |
| 8509 |
} |
| 8510 |
} |
| 8511 |
|
| 8512 |
|
| 8513 |
pAllocationRequest->allocHandle = (VmaAllocHandle)(resultOffset + 1); |
| 8514 |
pAllocationRequest->type = VmaAllocationRequestType::EndOf2nd; |
| 8515 |
|
| 8516 |
return true; |
| 8517 |
} |
| 8518 |
} |
| 8519 |
|
| 8520 |
return false; |
| 8521 |
} |
| 8522 |
|
| 8523 |
bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress( |
| 8524 |
VkDeviceSize allocSize, |
| 8525 |
VkDeviceSize allocAlignment, |
| 8526 |
VmaSuballocationType allocType, |
| 8527 |
uint32_t strategy, |
| 8528 |
VmaAllocationRequest* pAllocationRequest) |
| 8529 |
{ |
| 8530 |
const VkDeviceSize blockSize = GetSize(); |
| 8531 |
const VkDeviceSize bufferImageGranularity = GetBufferImageGranularity(); |
| 8532 |
SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8533 |
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8534 |
|
| 8535 |
if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 8536 |
{ |
| 8537 |
VMA_ASSERT(0 && "Trying to use pool with linear algorithm as double stack, while it is already being used as ring buffer."); |
| 8538 |
return false; |
| 8539 |
} |
| 8540 |
|
| 8541 |
|
| 8542 |
if (allocSize > blockSize) |
| 8543 |
{ |
| 8544 |
return false; |
| 8545 |
} |
| 8546 |
VkDeviceSize resultBaseOffset = blockSize - allocSize; |
| 8547 |
if (!suballocations2nd.empty()) |
| 8548 |
{ |
| 8549 |
const VmaSuballocation& lastSuballoc = suballocations2nd.back(); |
| 8550 |
resultBaseOffset = lastSuballoc.offset - allocSize; |
| 8551 |
if (allocSize > lastSuballoc.offset) |
| 8552 |
{ |
| 8553 |
return false; |
| 8554 |
} |
| 8555 |
} |
| 8556 |
|
| 8557 |
|
| 8558 |
VkDeviceSize resultOffset = resultBaseOffset; |
| 8559 |
|
| 8560 |
const VkDeviceSize debugMargin = GetDebugMargin(); |
| 8561 |
|
| 8562 |
|
| 8563 |
if (debugMargin > 0) |
| 8564 |
{ |
| 8565 |
if (resultOffset < debugMargin) |
| 8566 |
{ |
| 8567 |
return false; |
| 8568 |
} |
| 8569 |
resultOffset -= debugMargin; |
| 8570 |
} |
| 8571 |
|
| 8572 |
|
| 8573 |
resultOffset = VmaAlignDown(resultOffset, allocAlignment); |
| 8574 |
|
| 8575 |
|
| 8576 |
|
| 8577 |
if (bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations2nd.empty()) |
| 8578 |
{ |
| 8579 |
bool bufferImageGranularityConflict = false; |
| 8580 |
for (size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; ) |
| 8581 |
{ |
| 8582 |
const VmaSuballocation& nextSuballoc = suballocations2nd[nextSuballocIndex]; |
| 8583 |
if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) |
| 8584 |
{ |
| 8585 |
if (VmaIsBufferImageGranularityConflict(nextSuballoc.type, allocType)) |
| 8586 |
{ |
| 8587 |
bufferImageGranularityConflict = true; |
| 8588 |
break; |
| 8589 |
} |
| 8590 |
} |
| 8591 |
else |
| 8592 |
|
| 8593 |
break; |
| 8594 |
} |
| 8595 |
if (bufferImageGranularityConflict) |
| 8596 |
{ |
| 8597 |
resultOffset = VmaAlignDown(resultOffset, bufferImageGranularity); |
| 8598 |
} |
| 8599 |
} |
| 8600 |
|
| 8601 |
|
| 8602 |
const VkDeviceSize endOf1st = !suballocations1st.empty() ? |
| 8603 |
suballocations1st.back().offset + suballocations1st.back().size : |
| 8604 |
0; |
| 8605 |
if (endOf1st + debugMargin <= resultOffset) |
| 8606 |
{ |
| 8607 |
|
| 8608 |
|
| 8609 |
if (bufferImageGranularity > 1) |
| 8610 |
{ |
| 8611 |
for (size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--; ) |
| 8612 |
{ |
| 8613 |
const VmaSuballocation& prevSuballoc = suballocations1st[prevSuballocIndex]; |
| 8614 |
if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) |
| 8615 |
{ |
| 8616 |
if (VmaIsBufferImageGranularityConflict(allocType, prevSuballoc.type)) |
| 8617 |
{ |
| 8618 |
return false; |
| 8619 |
} |
| 8620 |
} |
| 8621 |
else |
| 8622 |
{ |
| 8623 |
|
| 8624 |
break; |
| 8625 |
} |
| 8626 |
} |
| 8627 |
} |
| 8628 |
|
| 8629 |
|
| 8630 |
pAllocationRequest->allocHandle = (VmaAllocHandle)(resultOffset + 1); |
| 8631 |
|
| 8632 |
pAllocationRequest->type = VmaAllocationRequestType::UpperAddress; |
| 8633 |
return true; |
| 8634 |
} |
| 8635 |
|
| 8636 |
return false; |
| 8637 |
} |
| 8638 |
#endif |
| 8639 |
#endif |
| 8640 |
|
| 8641 |
#ifndef _VMA_BLOCK_METADATA_TLSF |
| 8642 |
|
| 8643 |
|
| 8644 |
|
| 8645 |
|
| 8646 |
class VmaBlockMetadata_TLSF : public VmaBlockMetadata |
| 8647 |
{ |
| 8648 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_TLSF) |
| 8649 |
public: |
| 8650 |
VmaBlockMetadata_TLSF(const VkAllocationCallbacks* pAllocationCallbacks, |
| 8651 |
VkDeviceSize bufferImageGranularity, bool isVirtual); |
| 8652 |
virtual ~VmaBlockMetadata_TLSF(); |
| 8653 |
|
| 8654 |
size_t GetAllocationCount() const override { return m_AllocCount; } |
| 8655 |
size_t GetFreeRegionsCount() const override { return m_BlocksFreeCount + 1; } |
| 8656 |
VkDeviceSize GetSumFreeSize() const override { return m_BlocksFreeSize + m_NullBlock->size; } |
| 8657 |
bool IsEmpty() const override { return m_NullBlock->offset == 0; } |
| 8658 |
VkDeviceSize GetAllocationOffset(VmaAllocHandle allocHandle) const override { return ((Block*)allocHandle)->offset; } |
| 8659 |
|
| 8660 |
void Init(VkDeviceSize size) override; |
| 8661 |
bool Validate() const override; |
| 8662 |
|
| 8663 |
void AddDetailedStatistics(VmaDetailedStatistics& inoutStats) const override; |
| 8664 |
void AddStatistics(VmaStatistics& inoutStats) const override; |
| 8665 |
|
| 8666 |
#if VMA_STATS_STRING_ENABLED |
| 8667 |
void PrintDetailedMap(class VmaJsonWriter& json) const override; |
| 8668 |
#endif |
| 8669 |
|
| 8670 |
bool CreateAllocationRequest( |
| 8671 |
VkDeviceSize allocSize, |
| 8672 |
VkDeviceSize allocAlignment, |
| 8673 |
bool upperAddress, |
| 8674 |
VmaSuballocationType allocType, |
| 8675 |
uint32_t strategy, |
| 8676 |
VmaAllocationRequest* pAllocationRequest) override; |
| 8677 |
|
| 8678 |
VkResult CheckCorruption(const void* pBlockData) override; |
| 8679 |
void Alloc( |
| 8680 |
const VmaAllocationRequest& request, |
| 8681 |
VmaSuballocationType type, |
| 8682 |
void* userData) override; |
| 8683 |
|
| 8684 |
void Free(VmaAllocHandle allocHandle) override; |
| 8685 |
void GetAllocationInfo(VmaAllocHandle allocHandle, VmaVirtualAllocationInfo& outInfo) override; |
| 8686 |
void* GetAllocationUserData(VmaAllocHandle allocHandle) const override; |
| 8687 |
VmaAllocHandle GetAllocationListBegin() const override; |
| 8688 |
VmaAllocHandle GetNextAllocation(VmaAllocHandle prevAlloc) const override; |
| 8689 |
VkDeviceSize GetNextFreeRegionSize(VmaAllocHandle alloc) const override; |
| 8690 |
void Clear() override; |
| 8691 |
void SetAllocationUserData(VmaAllocHandle allocHandle, void* userData) override; |
| 8692 |
void DebugLogAllAllocations() const override; |
| 8693 |
|
| 8694 |
private: |
| 8695 |
|
| 8696 |
|
| 8697 |
|
| 8698 |
static const uint8_t SECOND_LEVEL_INDEX = 5; |
| 8699 |
static const uint16_t SMALL_BUFFER_SIZE = 256; |
| 8700 |
static const uint32_t INITIAL_BLOCK_ALLOC_COUNT = 16; |
| 8701 |
static const uint8_t MEMORY_CLASS_SHIFT = 7; |
| 8702 |
static const uint8_t MAX_MEMORY_CLASSES = 65 - MEMORY_CLASS_SHIFT; |
| 8703 |
|
| 8704 |
class Block |
| 8705 |
{ |
| 8706 |
public: |
| 8707 |
VkDeviceSize offset; |
| 8708 |
VkDeviceSize size; |
| 8709 |
Block* prevPhysical; |
| 8710 |
Block* nextPhysical; |
| 8711 |
|
| 8712 |
void MarkFree() { prevFree = VMA_NULL; } |
| 8713 |
void MarkTaken() { prevFree = this; } |
| 8714 |
bool IsFree() const { return prevFree != this; } |
| 8715 |
void*& UserData() { VMA_HEAVY_ASSERT(!IsFree()); return userData; } |
| 8716 |
Block*& PrevFree() { return prevFree; } |
| 8717 |
Block*& NextFree() { VMA_HEAVY_ASSERT(IsFree()); return nextFree; } |
| 8718 |
|
| 8719 |
private: |
| 8720 |
Block* prevFree; |
| 8721 |
union |
| 8722 |
{ |
| 8723 |
Block* nextFree; |
| 8724 |
void* userData; |
| 8725 |
}; |
| 8726 |
}; |
| 8727 |
|
| 8728 |
size_t m_AllocCount; |
| 8729 |
|
| 8730 |
size_t m_BlocksFreeCount; |
| 8731 |
|
| 8732 |
VkDeviceSize m_BlocksFreeSize; |
| 8733 |
uint32_t m_IsFreeBitmap; |
| 8734 |
uint8_t m_MemoryClasses; |
| 8735 |
uint32_t m_InnerIsFreeBitmap[MAX_MEMORY_CLASSES]; |
| 8736 |
uint32_t m_ListsCount; |
| 8737 |
|
| 8738 |
|
| 8739 |
|
| 8740 |
|
| 8741 |
Block** m_FreeList; |
| 8742 |
VmaPoolAllocator<Block> m_BlockAllocator; |
| 8743 |
Block* m_NullBlock; |
| 8744 |
VmaBlockBufferImageGranularity m_GranularityHandler; |
| 8745 |
|
| 8746 |
uint8_t SizeToMemoryClass(VkDeviceSize size) const; |
| 8747 |
uint16_t SizeToSecondIndex(VkDeviceSize size, uint8_t memoryClass) const; |
| 8748 |
uint32_t GetListIndex(uint8_t memoryClass, uint16_t secondIndex) const; |
| 8749 |
uint32_t GetListIndex(VkDeviceSize size) const; |
| 8750 |
|
| 8751 |
void RemoveFreeBlock(Block* block); |
| 8752 |
void InsertFreeBlock(Block* block); |
| 8753 |
void MergeBlock(Block* block, Block* prev); |
| 8754 |
|
| 8755 |
Block* FindFreeBlock(VkDeviceSize size, uint32_t& listIndex) const; |
| 8756 |
bool CheckBlock( |
| 8757 |
Block& block, |
| 8758 |
uint32_t listIndex, |
| 8759 |
VkDeviceSize allocSize, |
| 8760 |
VkDeviceSize allocAlignment, |
| 8761 |
VmaSuballocationType allocType, |
| 8762 |
VmaAllocationRequest* pAllocationRequest); |
| 8763 |
}; |
| 8764 |
|
| 8765 |
#ifndef _VMA_BLOCK_METADATA_TLSF_FUNCTIONS |
| 8766 |
VmaBlockMetadata_TLSF::VmaBlockMetadata_TLSF(const VkAllocationCallbacks* pAllocationCallbacks, |
| 8767 |
VkDeviceSize bufferImageGranularity, bool isVirtual) |
| 8768 |
: VmaBlockMetadata(pAllocationCallbacks, bufferImageGranularity, isVirtual), |
| 8769 |
m_AllocCount(0), |
| 8770 |
m_BlocksFreeCount(0), |
| 8771 |
m_BlocksFreeSize(0), |
| 8772 |
m_IsFreeBitmap(0), |
| 8773 |
m_MemoryClasses(0), |
| 8774 |
m_ListsCount(0), |
| 8775 |
m_FreeList(VMA_NULL), |
| 8776 |
m_BlockAllocator(pAllocationCallbacks, INITIAL_BLOCK_ALLOC_COUNT), |
| 8777 |
m_NullBlock(VMA_NULL), |
| 8778 |
m_GranularityHandler(bufferImageGranularity) {} |
| 8779 |
|
| 8780 |
VmaBlockMetadata_TLSF::~VmaBlockMetadata_TLSF() |
| 8781 |
{ |
| 8782 |
if (m_FreeList) |
| 8783 |
vma_delete_array(GetAllocationCallbacks(), m_FreeList, m_ListsCount); |
| 8784 |
m_GranularityHandler.Destroy(GetAllocationCallbacks()); |
| 8785 |
} |
| 8786 |
|
| 8787 |
void VmaBlockMetadata_TLSF::Init(VkDeviceSize size) |
| 8788 |
{ |
| 8789 |
VmaBlockMetadata::Init(size); |
| 8790 |
|
| 8791 |
if (!IsVirtual()) |
| 8792 |
m_GranularityHandler.Init(GetAllocationCallbacks(), size); |
| 8793 |
|
| 8794 |
m_NullBlock = m_BlockAllocator.Alloc(); |
| 8795 |
m_NullBlock->size = size; |
| 8796 |
m_NullBlock->offset = 0; |
| 8797 |
m_NullBlock->prevPhysical = VMA_NULL; |
| 8798 |
m_NullBlock->nextPhysical = VMA_NULL; |
| 8799 |
m_NullBlock->MarkFree(); |
| 8800 |
m_NullBlock->NextFree() = VMA_NULL; |
| 8801 |
m_NullBlock->PrevFree() = VMA_NULL; |
| 8802 |
uint8_t memoryClass = SizeToMemoryClass(size); |
| 8803 |
uint16_t sli = SizeToSecondIndex(size, memoryClass); |
| 8804 |
m_ListsCount = (memoryClass == 0 ? 0 : (memoryClass - 1) * (1UL << SECOND_LEVEL_INDEX) + sli) + 1; |
| 8805 |
if (IsVirtual()) |
| 8806 |
m_ListsCount += 1UL << SECOND_LEVEL_INDEX; |
| 8807 |
else |
| 8808 |
m_ListsCount += 4; |
| 8809 |
|
| 8810 |
m_MemoryClasses = memoryClass + uint8_t(2); |
| 8811 |
memset(m_InnerIsFreeBitmap, 0, MAX_MEMORY_CLASSES * sizeof(uint32_t)); |
| 8812 |
|
| 8813 |
m_FreeList = vma_new_array(GetAllocationCallbacks(), Block*, m_ListsCount); |
| 8814 |
memset(m_FreeList, 0, m_ListsCount * sizeof(Block*)); |
| 8815 |
} |
| 8816 |
|
| 8817 |
bool VmaBlockMetadata_TLSF::Validate() const |
| 8818 |
{ |
| 8819 |
VMA_VALIDATE(GetSumFreeSize() <= GetSize()); |
| 8820 |
|
| 8821 |
VkDeviceSize calculatedSize = m_NullBlock->size; |
| 8822 |
VkDeviceSize calculatedFreeSize = m_NullBlock->size; |
| 8823 |
size_t allocCount = 0; |
| 8824 |
size_t freeCount = 0; |
| 8825 |
|
| 8826 |
|
| 8827 |
for (uint32_t list = 0; list < m_ListsCount; ++list) |
| 8828 |
{ |
| 8829 |
Block* block = m_FreeList[list]; |
| 8830 |
if (block != VMA_NULL) |
| 8831 |
{ |
| 8832 |
VMA_VALIDATE(block->IsFree()); |
| 8833 |
VMA_VALIDATE(block->PrevFree() == VMA_NULL); |
| 8834 |
while (block->NextFree()) |
| 8835 |
{ |
| 8836 |
VMA_VALIDATE(block->NextFree()->IsFree()); |
| 8837 |
VMA_VALIDATE(block->NextFree()->PrevFree() == block); |
| 8838 |
block = block->NextFree(); |
| 8839 |
} |
| 8840 |
} |
| 8841 |
} |
| 8842 |
|
| 8843 |
VkDeviceSize nextOffset = m_NullBlock->offset; |
| 8844 |
auto validateCtx = m_GranularityHandler.StartValidation(GetAllocationCallbacks(), IsVirtual()); |
| 8845 |
|
| 8846 |
VMA_VALIDATE(m_NullBlock->nextPhysical == VMA_NULL); |
| 8847 |
if (m_NullBlock->prevPhysical) |
| 8848 |
{ |
| 8849 |
VMA_VALIDATE(m_NullBlock->prevPhysical->nextPhysical == m_NullBlock); |
| 8850 |
} |
| 8851 |
|
| 8852 |
for (Block* prev = m_NullBlock->prevPhysical; prev != VMA_NULL; prev = prev->prevPhysical) |
| 8853 |
{ |
| 8854 |
VMA_VALIDATE(prev->offset + prev->size == nextOffset); |
| 8855 |
nextOffset = prev->offset; |
| 8856 |
calculatedSize += prev->size; |
| 8857 |
|
| 8858 |
uint32_t listIndex = GetListIndex(prev->size); |
| 8859 |
if (prev->IsFree()) |
| 8860 |
{ |
| 8861 |
++freeCount; |
| 8862 |
|
| 8863 |
Block* freeBlock = m_FreeList[listIndex]; |
| 8864 |
VMA_VALIDATE(freeBlock != VMA_NULL); |
| 8865 |
|
| 8866 |
bool found = false; |
| 8867 |
do |
| 8868 |
{ |
| 8869 |
if (freeBlock == prev) |
| 8870 |
found = true; |
| 8871 |
|
| 8872 |
freeBlock = freeBlock->NextFree(); |
| 8873 |
} while (!found && freeBlock != VMA_NULL); |
| 8874 |
|
| 8875 |
VMA_VALIDATE(found); |
| 8876 |
calculatedFreeSize += prev->size; |
| 8877 |
} |
| 8878 |
else |
| 8879 |
{ |
| 8880 |
++allocCount; |
| 8881 |
|
| 8882 |
Block* freeBlock = m_FreeList[listIndex]; |
| 8883 |
while (freeBlock) |
| 8884 |
{ |
| 8885 |
VMA_VALIDATE(freeBlock != prev); |
| 8886 |
freeBlock = freeBlock->NextFree(); |
| 8887 |
} |
| 8888 |
|
| 8889 |
if (!IsVirtual()) |
| 8890 |
{ |
| 8891 |
VMA_VALIDATE(m_GranularityHandler.Validate(validateCtx, prev->offset, prev->size)); |
| 8892 |
} |
| 8893 |
} |
| 8894 |
|
| 8895 |
if (prev->prevPhysical) |
| 8896 |
{ |
| 8897 |
VMA_VALIDATE(prev->prevPhysical->nextPhysical == prev); |
| 8898 |
} |
| 8899 |
} |
| 8900 |
|
| 8901 |
if (!IsVirtual()) |
| 8902 |
{ |
| 8903 |
VMA_VALIDATE(m_GranularityHandler.FinishValidation(validateCtx)); |
| 8904 |
} |
| 8905 |
|
| 8906 |
VMA_VALIDATE(nextOffset == 0); |
| 8907 |
VMA_VALIDATE(calculatedSize == GetSize()); |
| 8908 |
VMA_VALIDATE(calculatedFreeSize == GetSumFreeSize()); |
| 8909 |
VMA_VALIDATE(allocCount == m_AllocCount); |
| 8910 |
VMA_VALIDATE(freeCount == m_BlocksFreeCount); |
| 8911 |
|
| 8912 |
return true; |
| 8913 |
} |
| 8914 |
|
| 8915 |
void VmaBlockMetadata_TLSF::AddDetailedStatistics(VmaDetailedStatistics& inoutStats) const |
| 8916 |
{ |
| 8917 |
inoutStats.statistics.blockCount++; |
| 8918 |
inoutStats.statistics.blockBytes += GetSize(); |
| 8919 |
if (m_NullBlock->size > 0) |
| 8920 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, m_NullBlock->size); |
| 8921 |
|
| 8922 |
for (Block* block = m_NullBlock->prevPhysical; block != VMA_NULL; block = block->prevPhysical) |
| 8923 |
{ |
| 8924 |
if (block->IsFree()) |
| 8925 |
VmaAddDetailedStatisticsUnusedRange(inoutStats, block->size); |
| 8926 |
else |
| 8927 |
VmaAddDetailedStatisticsAllocation(inoutStats, block->size); |
| 8928 |
} |
| 8929 |
} |
| 8930 |
|
| 8931 |
void VmaBlockMetadata_TLSF::AddStatistics(VmaStatistics& inoutStats) const |
| 8932 |
{ |
| 8933 |
inoutStats.blockCount++; |
| 8934 |
inoutStats.allocationCount += (uint32_t)m_AllocCount; |
| 8935 |
inoutStats.blockBytes += GetSize(); |
| 8936 |
inoutStats.allocationBytes += GetSize() - GetSumFreeSize(); |
| 8937 |
} |
| 8938 |
|
| 8939 |
#if VMA_STATS_STRING_ENABLED |
| 8940 |
void VmaBlockMetadata_TLSF::PrintDetailedMap(class VmaJsonWriter& json) const |
| 8941 |
{ |
| 8942 |
size_t blockCount = m_AllocCount + m_BlocksFreeCount; |
| 8943 |
VmaStlAllocator<Block*> allocator(GetAllocationCallbacks()); |
| 8944 |
VmaVector<Block*, VmaStlAllocator<Block*>> blockList(blockCount, allocator); |
| 8945 |
|
| 8946 |
size_t i = blockCount; |
| 8947 |
for (Block* block = m_NullBlock->prevPhysical; block != VMA_NULL; block = block->prevPhysical) |
| 8948 |
{ |
| 8949 |
blockList[--i] = block; |
| 8950 |
} |
| 8951 |
VMA_ASSERT(i == 0); |
| 8952 |
|
| 8953 |
VmaDetailedStatistics stats; |
| 8954 |
VmaClearDetailedStatistics(stats); |
| 8955 |
AddDetailedStatistics(stats); |
| 8956 |
|
| 8957 |
PrintDetailedMap_Begin(json, |
| 8958 |
stats.statistics.blockBytes - stats.statistics.allocationBytes, |
| 8959 |
stats.statistics.allocationCount, |
| 8960 |
stats.unusedRangeCount); |
| 8961 |
|
| 8962 |
for (; i < blockCount; ++i) |
| 8963 |
{ |
| 8964 |
Block* block = blockList[i]; |
| 8965 |
if (block->IsFree()) |
| 8966 |
PrintDetailedMap_UnusedRange(json, block->offset, block->size); |
| 8967 |
else |
| 8968 |
PrintDetailedMap_Allocation(json, block->offset, block->size, block->UserData()); |
| 8969 |
} |
| 8970 |
if (m_NullBlock->size > 0) |
| 8971 |
PrintDetailedMap_UnusedRange(json, m_NullBlock->offset, m_NullBlock->size); |
| 8972 |
|
| 8973 |
PrintDetailedMap_End(json); |
| 8974 |
} |
| 8975 |
#endif |
| 8976 |
|
| 8977 |
bool VmaBlockMetadata_TLSF::CreateAllocationRequest( |
| 8978 |
VkDeviceSize allocSize, |
| 8979 |
VkDeviceSize allocAlignment, |
| 8980 |
bool upperAddress, |
| 8981 |
VmaSuballocationType allocType, |
| 8982 |
uint32_t strategy, |
| 8983 |
VmaAllocationRequest* pAllocationRequest) |
| 8984 |
{ |
| 8985 |
VMA_ASSERT(allocSize > 0 && "Cannot allocate empty block!"); |
| 8986 |
VMA_ASSERT(!upperAddress && "VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT can be used only with linear algorithm."); |
| 8987 |
|
| 8988 |
|
| 8989 |
if (!IsVirtual()) |
| 8990 |
m_GranularityHandler.RoundupAllocRequest(allocType, allocSize, allocAlignment); |
| 8991 |
|
| 8992 |
allocSize += GetDebugMargin(); |
| 8993 |
|
| 8994 |
if (allocSize > GetSumFreeSize()) |
| 8995 |
return false; |
| 8996 |
|
| 8997 |
|
| 8998 |
if (m_BlocksFreeCount == 0) |
| 8999 |
return CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest); |
| 9000 |
|
| 9001 |
|
| 9002 |
VkDeviceSize sizeForNextList = allocSize; |
| 9003 |
VkDeviceSize smallSizeStep = VkDeviceSize(SMALL_BUFFER_SIZE / (IsVirtual() ? 1 << SECOND_LEVEL_INDEX : 4)); |
| 9004 |
if (allocSize > SMALL_BUFFER_SIZE) |
| 9005 |
{ |
| 9006 |
sizeForNextList += (1ULL << (VMA_BITSCAN_MSB(allocSize) - SECOND_LEVEL_INDEX)); |
| 9007 |
} |
| 9008 |
else if (allocSize > SMALL_BUFFER_SIZE - smallSizeStep) |
| 9009 |
sizeForNextList = SMALL_BUFFER_SIZE + 1; |
| 9010 |
else |
| 9011 |
sizeForNextList += smallSizeStep; |
| 9012 |
|
| 9013 |
uint32_t nextListIndex = m_ListsCount; |
| 9014 |
uint32_t prevListIndex = m_ListsCount; |
| 9015 |
Block* nextListBlock = VMA_NULL; |
| 9016 |
Block* prevListBlock = VMA_NULL; |
| 9017 |
|
| 9018 |
|
| 9019 |
if (strategy & VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT) |
| 9020 |
{ |
| 9021 |
|
| 9022 |
nextListBlock = FindFreeBlock(sizeForNextList, nextListIndex); |
| 9023 |
if (nextListBlock != VMA_NULL && CheckBlock(*nextListBlock, nextListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9024 |
return true; |
| 9025 |
|
| 9026 |
|
| 9027 |
if (CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9028 |
return true; |
| 9029 |
|
| 9030 |
|
| 9031 |
while (nextListBlock) |
| 9032 |
{ |
| 9033 |
if (CheckBlock(*nextListBlock, nextListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9034 |
return true; |
| 9035 |
nextListBlock = nextListBlock->NextFree(); |
| 9036 |
} |
| 9037 |
|
| 9038 |
|
| 9039 |
prevListBlock = FindFreeBlock(allocSize, prevListIndex); |
| 9040 |
while (prevListBlock) |
| 9041 |
{ |
| 9042 |
if (CheckBlock(*prevListBlock, prevListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9043 |
return true; |
| 9044 |
prevListBlock = prevListBlock->NextFree(); |
| 9045 |
} |
| 9046 |
} |
| 9047 |
else if (strategy & VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT) |
| 9048 |
{ |
| 9049 |
|
| 9050 |
prevListBlock = FindFreeBlock(allocSize, prevListIndex); |
| 9051 |
while (prevListBlock) |
| 9052 |
{ |
| 9053 |
if (CheckBlock(*prevListBlock, prevListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9054 |
return true; |
| 9055 |
prevListBlock = prevListBlock->NextFree(); |
| 9056 |
} |
| 9057 |
|
| 9058 |
|
| 9059 |
if (CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9060 |
return true; |
| 9061 |
|
| 9062 |
|
| 9063 |
nextListBlock = FindFreeBlock(sizeForNextList, nextListIndex); |
| 9064 |
while (nextListBlock) |
| 9065 |
{ |
| 9066 |
if (CheckBlock(*nextListBlock, nextListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9067 |
return true; |
| 9068 |
nextListBlock = nextListBlock->NextFree(); |
| 9069 |
} |
| 9070 |
} |
| 9071 |
else if (strategy & VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT ) |
| 9072 |
{ |
| 9073 |
|
| 9074 |
VmaStlAllocator<Block*> allocator(GetAllocationCallbacks()); |
| 9075 |
VmaVector<Block*, VmaStlAllocator<Block*>> blockList(m_BlocksFreeCount, allocator); |
| 9076 |
|
| 9077 |
size_t i = m_BlocksFreeCount; |
| 9078 |
for (Block* block = m_NullBlock->prevPhysical; block != VMA_NULL; block = block->prevPhysical) |
| 9079 |
{ |
| 9080 |
if (block->IsFree() && block->size >= allocSize) |
| 9081 |
blockList[--i] = block; |
| 9082 |
} |
| 9083 |
|
| 9084 |
for (; i < m_BlocksFreeCount; ++i) |
| 9085 |
{ |
| 9086 |
Block& block = *blockList[i]; |
| 9087 |
if (CheckBlock(block, GetListIndex(block.size), allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9088 |
return true; |
| 9089 |
} |
| 9090 |
|
| 9091 |
|
| 9092 |
if (CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9093 |
return true; |
| 9094 |
|
| 9095 |
|
| 9096 |
return false; |
| 9097 |
} |
| 9098 |
else |
| 9099 |
{ |
| 9100 |
|
| 9101 |
nextListBlock = FindFreeBlock(sizeForNextList, nextListIndex); |
| 9102 |
while (nextListBlock) |
| 9103 |
{ |
| 9104 |
if (CheckBlock(*nextListBlock, nextListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9105 |
return true; |
| 9106 |
nextListBlock = nextListBlock->NextFree(); |
| 9107 |
} |
| 9108 |
|
| 9109 |
|
| 9110 |
if (CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9111 |
return true; |
| 9112 |
|
| 9113 |
|
| 9114 |
prevListBlock = FindFreeBlock(allocSize, prevListIndex); |
| 9115 |
while (prevListBlock) |
| 9116 |
{ |
| 9117 |
if (CheckBlock(*prevListBlock, prevListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9118 |
return true; |
| 9119 |
prevListBlock = prevListBlock->NextFree(); |
| 9120 |
} |
| 9121 |
} |
| 9122 |
|
| 9123 |
|
| 9124 |
while (++nextListIndex < m_ListsCount) |
| 9125 |
{ |
| 9126 |
nextListBlock = m_FreeList[nextListIndex]; |
| 9127 |
while (nextListBlock) |
| 9128 |
{ |
| 9129 |
if (CheckBlock(*nextListBlock, nextListIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) |
| 9130 |
return true; |
| 9131 |
nextListBlock = nextListBlock->NextFree(); |
| 9132 |
} |
| 9133 |
} |
| 9134 |
|
| 9135 |
|
| 9136 |
return false; |
| 9137 |
} |
| 9138 |
|
| 9139 |
VkResult VmaBlockMetadata_TLSF::CheckCorruption(const void* pBlockData) |
| 9140 |
{ |
| 9141 |
for (Block* block = m_NullBlock->prevPhysical; block != VMA_NULL; block = block->prevPhysical) |
| 9142 |
{ |
| 9143 |
if (!block->IsFree()) |
| 9144 |
{ |
| 9145 |
if (!VmaValidateMagicValue(pBlockData, block->offset + block->size)) |
| 9146 |
{ |
| 9147 |
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!"); |
| 9148 |
return VK_ERROR_UNKNOWN_COPY; |
| 9149 |
} |
| 9150 |
} |
| 9151 |
} |
| 9152 |
|
| 9153 |
return VK_SUCCESS; |
| 9154 |
} |
| 9155 |
|
| 9156 |
void VmaBlockMetadata_TLSF::Alloc( |
| 9157 |
const VmaAllocationRequest& request, |
| 9158 |
VmaSuballocationType type, |
| 9159 |
void* userData) |
| 9160 |
{ |
| 9161 |
VMA_ASSERT(request.type == VmaAllocationRequestType::TLSF); |
| 9162 |
|
| 9163 |
|
| 9164 |
Block* currentBlock = (Block*)request.allocHandle; |
| 9165 |
VkDeviceSize offset = request.algorithmData; |
| 9166 |
VMA_ASSERT(currentBlock != VMA_NULL); |
| 9167 |
VMA_ASSERT(currentBlock->offset <= offset); |
| 9168 |
|
| 9169 |
if (currentBlock != m_NullBlock) |
| 9170 |
RemoveFreeBlock(currentBlock); |
| 9171 |
|
| 9172 |
VkDeviceSize debugMargin = GetDebugMargin(); |
| 9173 |
VkDeviceSize misssingAlignment = offset - currentBlock->offset; |
| 9174 |
|
| 9175 |
|
| 9176 |
if (misssingAlignment) |
| 9177 |
{ |
| 9178 |
Block* prevBlock = currentBlock->prevPhysical; |
| 9179 |
VMA_ASSERT(prevBlock != VMA_NULL && "There should be no missing alignment at offset 0!"); |
| 9180 |
|
| 9181 |
if (prevBlock->IsFree() && prevBlock->size != debugMargin) |
| 9182 |
{ |
| 9183 |
uint32_t oldList = GetListIndex(prevBlock->size); |
| 9184 |
prevBlock->size += misssingAlignment; |
| 9185 |
|
| 9186 |
if (oldList != GetListIndex(prevBlock->size)) |
| 9187 |
{ |
| 9188 |
prevBlock->size -= misssingAlignment; |
| 9189 |
RemoveFreeBlock(prevBlock); |
| 9190 |
prevBlock->size += misssingAlignment; |
| 9191 |
InsertFreeBlock(prevBlock); |
| 9192 |
} |
| 9193 |
else |
| 9194 |
m_BlocksFreeSize += misssingAlignment; |
| 9195 |
} |
| 9196 |
else |
| 9197 |
{ |
| 9198 |
Block* newBlock = m_BlockAllocator.Alloc(); |
| 9199 |
currentBlock->prevPhysical = newBlock; |
| 9200 |
prevBlock->nextPhysical = newBlock; |
| 9201 |
newBlock->prevPhysical = prevBlock; |
| 9202 |
newBlock->nextPhysical = currentBlock; |
| 9203 |
newBlock->size = misssingAlignment; |
| 9204 |
newBlock->offset = currentBlock->offset; |
| 9205 |
newBlock->MarkTaken(); |
| 9206 |
|
| 9207 |
InsertFreeBlock(newBlock); |
| 9208 |
} |
| 9209 |
|
| 9210 |
currentBlock->size -= misssingAlignment; |
| 9211 |
currentBlock->offset += misssingAlignment; |
| 9212 |
} |
| 9213 |
|
| 9214 |
VkDeviceSize size = request.size + debugMargin; |
| 9215 |
if (currentBlock->size == size) |
| 9216 |
{ |
| 9217 |
if (currentBlock == m_NullBlock) |
| 9218 |
{ |
| 9219 |
|
| 9220 |
m_NullBlock = m_BlockAllocator.Alloc(); |
| 9221 |
m_NullBlock->size = 0; |
| 9222 |
m_NullBlock->offset = currentBlock->offset + size; |
| 9223 |
m_NullBlock->prevPhysical = currentBlock; |
| 9224 |
m_NullBlock->nextPhysical = VMA_NULL; |
| 9225 |
m_NullBlock->MarkFree(); |
| 9226 |
m_NullBlock->PrevFree() = VMA_NULL; |
| 9227 |
m_NullBlock->NextFree() = VMA_NULL; |
| 9228 |
currentBlock->nextPhysical = m_NullBlock; |
| 9229 |
currentBlock->MarkTaken(); |
| 9230 |
} |
| 9231 |
} |
| 9232 |
else |
| 9233 |
{ |
| 9234 |
VMA_ASSERT(currentBlock->size > size && "Proper block already found, shouldn't find smaller one!"); |
| 9235 |
|
| 9236 |
|
| 9237 |
Block* newBlock = m_BlockAllocator.Alloc(); |
| 9238 |
newBlock->size = currentBlock->size - size; |
| 9239 |
newBlock->offset = currentBlock->offset + size; |
| 9240 |
newBlock->prevPhysical = currentBlock; |
| 9241 |
newBlock->nextPhysical = currentBlock->nextPhysical; |
| 9242 |
currentBlock->nextPhysical = newBlock; |
| 9243 |
currentBlock->size = size; |
| 9244 |
|
| 9245 |
if (currentBlock == m_NullBlock) |
| 9246 |
{ |
| 9247 |
m_NullBlock = newBlock; |
| 9248 |
m_NullBlock->MarkFree(); |
| 9249 |
m_NullBlock->NextFree() = VMA_NULL; |
| 9250 |
m_NullBlock->PrevFree() = VMA_NULL; |
| 9251 |
currentBlock->MarkTaken(); |
| 9252 |
} |
| 9253 |
else |
| 9254 |
{ |
| 9255 |
newBlock->nextPhysical->prevPhysical = newBlock; |
| 9256 |
newBlock->MarkTaken(); |
| 9257 |
InsertFreeBlock(newBlock); |
| 9258 |
} |
| 9259 |
} |
| 9260 |
currentBlock->UserData() = userData; |
| 9261 |
|
| 9262 |
if (debugMargin > 0) |
| 9263 |
{ |
| 9264 |
currentBlock->size -= debugMargin; |
| 9265 |
Block* newBlock = m_BlockAllocator.Alloc(); |
| 9266 |
newBlock->size = debugMargin; |
| 9267 |
newBlock->offset = currentBlock->offset + currentBlock->size; |
| 9268 |
newBlock->prevPhysical = currentBlock; |
| 9269 |
newBlock->nextPhysical = currentBlock->nextPhysical; |
| 9270 |
newBlock->MarkTaken(); |
| 9271 |
currentBlock->nextPhysical->prevPhysical = newBlock; |
| 9272 |
currentBlock->nextPhysical = newBlock; |
| 9273 |
InsertFreeBlock(newBlock); |
| 9274 |
} |
| 9275 |
|
| 9276 |
if (!IsVirtual()) |
| 9277 |
m_GranularityHandler.AllocPages((uint8_t)(uintptr_t)request.customData, |
| 9278 |
currentBlock->offset, currentBlock->size); |
| 9279 |
++m_AllocCount; |
| 9280 |
} |
| 9281 |
|
| 9282 |
void VmaBlockMetadata_TLSF::Free(VmaAllocHandle allocHandle) |
| 9283 |
{ |
| 9284 |
Block* block = (Block*)allocHandle; |
| 9285 |
Block* next = block->nextPhysical; |
| 9286 |
VMA_ASSERT(!block->IsFree() && "Block is already free!"); |
| 9287 |
|
| 9288 |
if (!IsVirtual()) |
| 9289 |
m_GranularityHandler.FreePages(block->offset, block->size); |
| 9290 |
--m_AllocCount; |
| 9291 |
|
| 9292 |
VkDeviceSize debugMargin = GetDebugMargin(); |
| 9293 |
if (debugMargin > 0) |
| 9294 |
{ |
| 9295 |
RemoveFreeBlock(next); |
| 9296 |
MergeBlock(next, block); |
| 9297 |
block = next; |
| 9298 |
next = next->nextPhysical; |
| 9299 |
} |
| 9300 |
|
| 9301 |
|
| 9302 |
Block* prev = block->prevPhysical; |
| 9303 |
if (prev != VMA_NULL && prev->IsFree() && prev->size != debugMargin) |
| 9304 |
{ |
| 9305 |
RemoveFreeBlock(prev); |
| 9306 |
MergeBlock(block, prev); |
| 9307 |
} |
| 9308 |
|
| 9309 |
if (!next->IsFree()) |
| 9310 |
InsertFreeBlock(block); |
| 9311 |
else if (next == m_NullBlock) |
| 9312 |
MergeBlock(m_NullBlock, block); |
| 9313 |
else |
| 9314 |
{ |
| 9315 |
RemoveFreeBlock(next); |
| 9316 |
MergeBlock(next, block); |
| 9317 |
InsertFreeBlock(next); |
| 9318 |
} |
| 9319 |
} |
| 9320 |
|
| 9321 |
void VmaBlockMetadata_TLSF::GetAllocationInfo(VmaAllocHandle allocHandle, VmaVirtualAllocationInfo& outInfo) |
| 9322 |
{ |
| 9323 |
Block* block = (Block*)allocHandle; |
| 9324 |
VMA_ASSERT(!block->IsFree() && "Cannot get allocation info for free block!"); |
| 9325 |
outInfo.offset = block->offset; |
| 9326 |
outInfo.size = block->size; |
| 9327 |
outInfo.pUserData = block->UserData(); |
| 9328 |
} |
| 9329 |
|
| 9330 |
void* VmaBlockMetadata_TLSF::GetAllocationUserData(VmaAllocHandle allocHandle) const |
| 9331 |
{ |
| 9332 |
Block* block = (Block*)allocHandle; |
| 9333 |
VMA_ASSERT(!block->IsFree() && "Cannot get user data for free block!"); |
| 9334 |
return block->UserData(); |
| 9335 |
} |
| 9336 |
|
| 9337 |
VmaAllocHandle VmaBlockMetadata_TLSF::GetAllocationListBegin() const |
| 9338 |
{ |
| 9339 |
if (m_AllocCount == 0) |
| 9340 |
return VK_NULL_HANDLE; |
| 9341 |
|
| 9342 |
for (Block* block = m_NullBlock->prevPhysical; block; block = block->prevPhysical) |
| 9343 |
{ |
| 9344 |
if (!block->IsFree()) |
| 9345 |
return (VmaAllocHandle)block; |
| 9346 |
} |
| 9347 |
VMA_ASSERT(false && "If m_AllocCount > 0 then should find any allocation!"); |
| 9348 |
return VK_NULL_HANDLE; |
| 9349 |
} |
| 9350 |
|
| 9351 |
VmaAllocHandle VmaBlockMetadata_TLSF::GetNextAllocation(VmaAllocHandle prevAlloc) const |
| 9352 |
{ |
| 9353 |
Block* startBlock = (Block*)prevAlloc; |
| 9354 |
VMA_ASSERT(!startBlock->IsFree() && "Incorrect block!"); |
| 9355 |
|
| 9356 |
for (Block* block = startBlock->prevPhysical; block; block = block->prevPhysical) |
| 9357 |
{ |
| 9358 |
if (!block->IsFree()) |
| 9359 |
return (VmaAllocHandle)block; |
| 9360 |
} |
| 9361 |
return VK_NULL_HANDLE; |
| 9362 |
} |
| 9363 |
|
| 9364 |
VkDeviceSize VmaBlockMetadata_TLSF::GetNextFreeRegionSize(VmaAllocHandle alloc) const |
| 9365 |
{ |
| 9366 |
Block* block = (Block*)alloc; |
| 9367 |
VMA_ASSERT(!block->IsFree() && "Incorrect block!"); |
| 9368 |
|
| 9369 |
if (block->prevPhysical) |
| 9370 |
return block->prevPhysical->IsFree() ? block->prevPhysical->size : 0; |
| 9371 |
return 0; |
| 9372 |
} |
| 9373 |
|
| 9374 |
void VmaBlockMetadata_TLSF::Clear() |
| 9375 |
{ |
| 9376 |
m_AllocCount = 0; |
| 9377 |
m_BlocksFreeCount = 0; |
| 9378 |
m_BlocksFreeSize = 0; |
| 9379 |
m_IsFreeBitmap = 0; |
| 9380 |
m_NullBlock->offset = 0; |
| 9381 |
m_NullBlock->size = GetSize(); |
| 9382 |
Block* block = m_NullBlock->prevPhysical; |
| 9383 |
m_NullBlock->prevPhysical = VMA_NULL; |
| 9384 |
while (block) |
| 9385 |
{ |
| 9386 |
Block* prev = block->prevPhysical; |
| 9387 |
m_BlockAllocator.Free(block); |
| 9388 |
block = prev; |
| 9389 |
} |
| 9390 |
memset(m_FreeList, 0, m_ListsCount * sizeof(Block*)); |
| 9391 |
memset(m_InnerIsFreeBitmap, 0, m_MemoryClasses * sizeof(uint32_t)); |
| 9392 |
m_GranularityHandler.Clear(); |
| 9393 |
} |
| 9394 |
|
| 9395 |
void VmaBlockMetadata_TLSF::SetAllocationUserData(VmaAllocHandle allocHandle, void* userData) |
| 9396 |
{ |
| 9397 |
Block* block = (Block*)allocHandle; |
| 9398 |
VMA_ASSERT(!block->IsFree() && "Trying to set user data for not allocated block!"); |
| 9399 |
block->UserData() = userData; |
| 9400 |
} |
| 9401 |
|
| 9402 |
void VmaBlockMetadata_TLSF::DebugLogAllAllocations() const |
| 9403 |
{ |
| 9404 |
for (Block* block = m_NullBlock->prevPhysical; block != VMA_NULL; block = block->prevPhysical) |
| 9405 |
if (!block->IsFree()) |
| 9406 |
DebugLogAllocation(block->offset, block->size, block->UserData()); |
| 9407 |
} |
| 9408 |
|
| 9409 |
uint8_t VmaBlockMetadata_TLSF::SizeToMemoryClass(VkDeviceSize size) const |
| 9410 |
{ |
| 9411 |
if (size > SMALL_BUFFER_SIZE) |
| 9412 |
return uint8_t(VMA_BITSCAN_MSB(size) - MEMORY_CLASS_SHIFT); |
| 9413 |
return 0; |
| 9414 |
} |
| 9415 |
|
| 9416 |
uint16_t VmaBlockMetadata_TLSF::SizeToSecondIndex(VkDeviceSize size, uint8_t memoryClass) const |
| 9417 |
{ |
| 9418 |
if (memoryClass == 0) |
| 9419 |
{ |
| 9420 |
if (IsVirtual()) |
| 9421 |
return static_cast<uint16_t>((size - 1) / 8); |
| 9422 |
else |
| 9423 |
return static_cast<uint16_t>((size - 1) / 64); |
| 9424 |
} |
| 9425 |
return static_cast<uint16_t>((size >> (memoryClass + MEMORY_CLASS_SHIFT - SECOND_LEVEL_INDEX)) ^ (1U << SECOND_LEVEL_INDEX)); |
| 9426 |
} |
| 9427 |
|
| 9428 |
uint32_t VmaBlockMetadata_TLSF::GetListIndex(uint8_t memoryClass, uint16_t secondIndex) const |
| 9429 |
{ |
| 9430 |
if (memoryClass == 0) |
| 9431 |
return secondIndex; |
| 9432 |
|
| 9433 |
const uint32_t index = static_cast<uint32_t>(memoryClass - 1) * (1 << SECOND_LEVEL_INDEX) + secondIndex; |
| 9434 |
if (IsVirtual()) |
| 9435 |
return index + (1 << SECOND_LEVEL_INDEX); |
| 9436 |
else |
| 9437 |
return index + 4; |
| 9438 |
} |
| 9439 |
|
| 9440 |
uint32_t VmaBlockMetadata_TLSF::GetListIndex(VkDeviceSize size) const |
| 9441 |
{ |
| 9442 |
uint8_t memoryClass = SizeToMemoryClass(size); |
| 9443 |
return GetListIndex(memoryClass, SizeToSecondIndex(size, memoryClass)); |
| 9444 |
} |
| 9445 |
|
| 9446 |
void VmaBlockMetadata_TLSF::RemoveFreeBlock(Block* block) |
| 9447 |
{ |
| 9448 |
VMA_ASSERT(block != m_NullBlock); |
| 9449 |
VMA_ASSERT(block->IsFree()); |
| 9450 |
|
| 9451 |
if (block->NextFree() != VMA_NULL) |
| 9452 |
block->NextFree()->PrevFree() = block->PrevFree(); |
| 9453 |
if (block->PrevFree() != VMA_NULL) |
| 9454 |
block->PrevFree()->NextFree() = block->NextFree(); |
| 9455 |
else |
| 9456 |
{ |
| 9457 |
uint8_t memClass = SizeToMemoryClass(block->size); |
| 9458 |
uint16_t secondIndex = SizeToSecondIndex(block->size, memClass); |
| 9459 |
uint32_t index = GetListIndex(memClass, secondIndex); |
| 9460 |
VMA_ASSERT(m_FreeList[index] == block); |
| 9461 |
m_FreeList[index] = block->NextFree(); |
| 9462 |
if (block->NextFree() == VMA_NULL) |
| 9463 |
{ |
| 9464 |
m_InnerIsFreeBitmap[memClass] &= ~(1U << secondIndex); |
| 9465 |
if (m_InnerIsFreeBitmap[memClass] == 0) |
| 9466 |
m_IsFreeBitmap &= ~(1UL << memClass); |
| 9467 |
} |
| 9468 |
} |
| 9469 |
block->MarkTaken(); |
| 9470 |
block->UserData() = VMA_NULL; |
| 9471 |
--m_BlocksFreeCount; |
| 9472 |
m_BlocksFreeSize -= block->size; |
| 9473 |
} |
| 9474 |
|
| 9475 |
void VmaBlockMetadata_TLSF::InsertFreeBlock(Block* block) |
| 9476 |
{ |
| 9477 |
VMA_ASSERT(block != m_NullBlock); |
| 9478 |
VMA_ASSERT(!block->IsFree() && "Cannot insert block twice!"); |
| 9479 |
|
| 9480 |
uint8_t memClass = SizeToMemoryClass(block->size); |
| 9481 |
uint16_t secondIndex = SizeToSecondIndex(block->size, memClass); |
| 9482 |
uint32_t index = GetListIndex(memClass, secondIndex); |
| 9483 |
VMA_ASSERT(index < m_ListsCount); |
| 9484 |
block->PrevFree() = VMA_NULL; |
| 9485 |
block->NextFree() = m_FreeList[index]; |
| 9486 |
m_FreeList[index] = block; |
| 9487 |
if (block->NextFree() != VMA_NULL) |
| 9488 |
block->NextFree()->PrevFree() = block; |
| 9489 |
else |
| 9490 |
{ |
| 9491 |
m_InnerIsFreeBitmap[memClass] |= 1U << secondIndex; |
| 9492 |
m_IsFreeBitmap |= 1UL << memClass; |
| 9493 |
} |
| 9494 |
++m_BlocksFreeCount; |
| 9495 |
m_BlocksFreeSize += block->size; |
| 9496 |
} |
| 9497 |
|
| 9498 |
void VmaBlockMetadata_TLSF::MergeBlock(Block* block, Block* prev) |
| 9499 |
{ |
| 9500 |
VMA_ASSERT(block->prevPhysical == prev && "Cannot merge separate physical regions!"); |
| 9501 |
VMA_ASSERT(!prev->IsFree() && "Cannot merge block that belongs to free list!"); |
| 9502 |
|
| 9503 |
block->offset = prev->offset; |
| 9504 |
block->size += prev->size; |
| 9505 |
block->prevPhysical = prev->prevPhysical; |
| 9506 |
if (block->prevPhysical) |
| 9507 |
block->prevPhysical->nextPhysical = block; |
| 9508 |
m_BlockAllocator.Free(prev); |
| 9509 |
} |
| 9510 |
|
| 9511 |
VmaBlockMetadata_TLSF::Block* VmaBlockMetadata_TLSF::FindFreeBlock(VkDeviceSize size, uint32_t& listIndex) const |
| 9512 |
{ |
| 9513 |
uint8_t memoryClass = SizeToMemoryClass(size); |
| 9514 |
uint32_t innerFreeMap = m_InnerIsFreeBitmap[memoryClass] & (~0U << SizeToSecondIndex(size, memoryClass)); |
| 9515 |
if (!innerFreeMap) |
| 9516 |
{ |
| 9517 |
|
| 9518 |
uint32_t freeMap = m_IsFreeBitmap & (~0UL << (memoryClass + 1)); |
| 9519 |
if (!freeMap) |
| 9520 |
return VMA_NULL; |
| 9521 |
|
| 9522 |
|
| 9523 |
memoryClass = VMA_BITSCAN_LSB(freeMap); |
| 9524 |
innerFreeMap = m_InnerIsFreeBitmap[memoryClass]; |
| 9525 |
VMA_ASSERT(innerFreeMap != 0); |
| 9526 |
} |
| 9527 |
|
| 9528 |
listIndex = GetListIndex(memoryClass, VMA_BITSCAN_LSB(innerFreeMap)); |
| 9529 |
VMA_ASSERT(m_FreeList[listIndex]); |
| 9530 |
return m_FreeList[listIndex]; |
| 9531 |
} |
| 9532 |
|
| 9533 |
bool VmaBlockMetadata_TLSF::CheckBlock( |
| 9534 |
Block& block, |
| 9535 |
uint32_t listIndex, |
| 9536 |
VkDeviceSize allocSize, |
| 9537 |
VkDeviceSize allocAlignment, |
| 9538 |
VmaSuballocationType allocType, |
| 9539 |
VmaAllocationRequest* pAllocationRequest) |
| 9540 |
{ |
| 9541 |
VMA_ASSERT(block.IsFree() && "Block is already taken!"); |
| 9542 |
|
| 9543 |
VkDeviceSize alignedOffset = VmaAlignUp(block.offset, allocAlignment); |
| 9544 |
if (block.size < allocSize + alignedOffset - block.offset) |
| 9545 |
return false; |
| 9546 |
|
| 9547 |
|
| 9548 |
if (!IsVirtual() && |
| 9549 |
m_GranularityHandler.CheckConflictAndAlignUp(alignedOffset, allocSize, block.offset, block.size, allocType)) |
| 9550 |
return false; |
| 9551 |
|
| 9552 |
|
| 9553 |
pAllocationRequest->type = VmaAllocationRequestType::TLSF; |
| 9554 |
pAllocationRequest->allocHandle = (VmaAllocHandle)█ |
| 9555 |
pAllocationRequest->size = allocSize - GetDebugMargin(); |
| 9556 |
pAllocationRequest->customData = (void*)allocType; |
| 9557 |
pAllocationRequest->algorithmData = alignedOffset; |
| 9558 |
|
| 9559 |
|
| 9560 |
if (listIndex != m_ListsCount && block.PrevFree()) |
| 9561 |
{ |
| 9562 |
block.PrevFree()->NextFree() = block.NextFree(); |
| 9563 |
if (block.NextFree()) |
| 9564 |
block.NextFree()->PrevFree() = block.PrevFree(); |
| 9565 |
block.PrevFree() = VMA_NULL; |
| 9566 |
block.NextFree() = m_FreeList[listIndex]; |
| 9567 |
m_FreeList[listIndex] = █ |
| 9568 |
if (block.NextFree()) |
| 9569 |
block.NextFree()->PrevFree() = █ |
| 9570 |
} |
| 9571 |
|
| 9572 |
return true; |
| 9573 |
} |
| 9574 |
#endif |
| 9575 |
#endif |
| 9576 |
|
| 9577 |
#ifndef _VMA_BLOCK_VECTOR |
| 9578 |
|
| 9579 |
|
| 9580 |
|
| 9581 |
|
| 9582 |
|
| 9583 |
|
| 9584 |
class VmaBlockVector |
| 9585 |
{ |
| 9586 |
friend struct VmaDefragmentationContext_T; |
| 9587 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockVector) |
| 9588 |
public: |
| 9589 |
VmaBlockVector( |
| 9590 |
VmaAllocator hAllocator, |
| 9591 |
VmaPool hParentPool, |
| 9592 |
uint32_t memoryTypeIndex, |
| 9593 |
VkDeviceSize preferredBlockSize, |
| 9594 |
size_t minBlockCount, |
| 9595 |
size_t maxBlockCount, |
| 9596 |
VkDeviceSize bufferImageGranularity, |
| 9597 |
bool explicitBlockSize, |
| 9598 |
uint32_t algorithm, |
| 9599 |
float priority, |
| 9600 |
VkDeviceSize minAllocationAlignment, |
| 9601 |
void* pMemoryAllocateNext); |
| 9602 |
~VmaBlockVector(); |
| 9603 |
|
| 9604 |
VmaAllocator GetAllocator() const { return m_hAllocator; } |
| 9605 |
VmaPool GetParentPool() const { return m_hParentPool; } |
| 9606 |
bool IsCustomPool() const { return m_hParentPool != VMA_NULL; } |
| 9607 |
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; } |
| 9608 |
VkDeviceSize GetPreferredBlockSize() const { return m_PreferredBlockSize; } |
| 9609 |
VkDeviceSize GetBufferImageGranularity() const { return m_BufferImageGranularity; } |
| 9610 |
uint32_t GetAlgorithm() const { return m_Algorithm; } |
| 9611 |
bool HasExplicitBlockSize() const { return m_ExplicitBlockSize; } |
| 9612 |
float GetPriority() const { return m_Priority; } |
| 9613 |
const void* GetAllocationNextPtr() const { return m_pMemoryAllocateNext; } |
| 9614 |
|
| 9615 |
size_t GetBlockCount() const { return m_Blocks.size(); } |
| 9616 |
|
| 9617 |
VmaDeviceMemoryBlock* GetBlock(size_t index) const { return m_Blocks[index]; } |
| 9618 |
VMA_RW_MUTEX &GetMutex() { return m_Mutex; } |
| 9619 |
|
| 9620 |
VkResult CreateMinBlocks(); |
| 9621 |
void AddStatistics(VmaStatistics& inoutStats); |
| 9622 |
void AddDetailedStatistics(VmaDetailedStatistics& inoutStats); |
| 9623 |
bool IsEmpty(); |
| 9624 |
bool IsCorruptionDetectionEnabled() const; |
| 9625 |
|
| 9626 |
VkResult Allocate( |
| 9627 |
VkDeviceSize size, |
| 9628 |
VkDeviceSize alignment, |
| 9629 |
const VmaAllocationCreateInfo& createInfo, |
| 9630 |
VmaSuballocationType suballocType, |
| 9631 |
size_t allocationCount, |
| 9632 |
VmaAllocation* pAllocations); |
| 9633 |
|
| 9634 |
void Free(const VmaAllocation hAllocation); |
| 9635 |
|
| 9636 |
#if VMA_STATS_STRING_ENABLED |
| 9637 |
void PrintDetailedMap(class VmaJsonWriter& json); |
| 9638 |
#endif |
| 9639 |
|
| 9640 |
VkResult CheckCorruption(); |
| 9641 |
|
| 9642 |
private: |
| 9643 |
const VmaAllocator m_hAllocator; |
| 9644 |
const VmaPool m_hParentPool; |
| 9645 |
const uint32_t m_MemoryTypeIndex; |
| 9646 |
const VkDeviceSize m_PreferredBlockSize; |
| 9647 |
const size_t m_MinBlockCount; |
| 9648 |
const size_t m_MaxBlockCount; |
| 9649 |
const VkDeviceSize m_BufferImageGranularity; |
| 9650 |
const bool m_ExplicitBlockSize; |
| 9651 |
const uint32_t m_Algorithm; |
| 9652 |
const float m_Priority; |
| 9653 |
const VkDeviceSize m_MinAllocationAlignment; |
| 9654 |
|
| 9655 |
void* const m_pMemoryAllocateNext; |
| 9656 |
VMA_RW_MUTEX m_Mutex; |
| 9657 |
|
| 9658 |
VmaVector<VmaDeviceMemoryBlock*, VmaStlAllocator<VmaDeviceMemoryBlock*>> m_Blocks; |
| 9659 |
uint32_t m_NextBlockId; |
| 9660 |
bool m_IncrementalSort = true; |
| 9661 |
|
| 9662 |
void SetIncrementalSort(bool val) { m_IncrementalSort = val; } |
| 9663 |
|
| 9664 |
VkDeviceSize CalcMaxBlockSize() const; |
| 9665 |
|
| 9666 |
void Remove(VmaDeviceMemoryBlock* pBlock); |
| 9667 |
|
| 9668 |
|
| 9669 |
void IncrementallySortBlocks(); |
| 9670 |
void SortByFreeSize(); |
| 9671 |
|
| 9672 |
VkResult AllocatePage( |
| 9673 |
VkDeviceSize size, |
| 9674 |
VkDeviceSize alignment, |
| 9675 |
const VmaAllocationCreateInfo& createInfo, |
| 9676 |
VmaSuballocationType suballocType, |
| 9677 |
VmaAllocation* pAllocation); |
| 9678 |
|
| 9679 |
VkResult AllocateFromBlock( |
| 9680 |
VmaDeviceMemoryBlock* pBlock, |
| 9681 |
VkDeviceSize size, |
| 9682 |
VkDeviceSize alignment, |
| 9683 |
VmaAllocationCreateFlags allocFlags, |
| 9684 |
void* pUserData, |
| 9685 |
VmaSuballocationType suballocType, |
| 9686 |
uint32_t strategy, |
| 9687 |
VmaAllocation* pAllocation); |
| 9688 |
|
| 9689 |
VkResult CommitAllocationRequest( |
| 9690 |
VmaAllocationRequest& allocRequest, |
| 9691 |
VmaDeviceMemoryBlock* pBlock, |
| 9692 |
VkDeviceSize alignment, |
| 9693 |
VmaAllocationCreateFlags allocFlags, |
| 9694 |
void* pUserData, |
| 9695 |
VmaSuballocationType suballocType, |
| 9696 |
VmaAllocation* pAllocation); |
| 9697 |
|
| 9698 |
VkResult CreateBlock(VkDeviceSize blockSize, size_t* pNewBlockIndex); |
| 9699 |
bool HasEmptyBlock(); |
| 9700 |
}; |
| 9701 |
#endif |
| 9702 |
|
| 9703 |
#ifndef _VMA_DEFRAGMENTATION_CONTEXT |
| 9704 |
struct VmaDefragmentationContext_T |
| 9705 |
{ |
| 9706 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaDefragmentationContext_T) |
| 9707 |
public: |
| 9708 |
VmaDefragmentationContext_T( |
| 9709 |
VmaAllocator hAllocator, |
| 9710 |
const VmaDefragmentationInfo& info); |
| 9711 |
~VmaDefragmentationContext_T(); |
| 9712 |
|
| 9713 |
void GetStats(VmaDefragmentationStats& outStats) { outStats = m_GlobalStats; } |
| 9714 |
|
| 9715 |
VkResult DefragmentPassBegin(VmaDefragmentationPassMoveInfo& moveInfo); |
| 9716 |
VkResult DefragmentPassEnd(VmaDefragmentationPassMoveInfo& moveInfo); |
| 9717 |
|
| 9718 |
private: |
| 9719 |
|
| 9720 |
static const uint8_t MAX_ALLOCS_TO_IGNORE = 16; |
| 9721 |
enum class CounterStatus { Pass, Ignore, End }; |
| 9722 |
|
| 9723 |
struct FragmentedBlock |
| 9724 |
{ |
| 9725 |
uint32_t data; |
| 9726 |
VmaDeviceMemoryBlock* block; |
| 9727 |
}; |
| 9728 |
struct StateBalanced |
| 9729 |
{ |
| 9730 |
VkDeviceSize avgFreeSize = 0; |
| 9731 |
VkDeviceSize avgAllocSize = UINT64_MAX; |
| 9732 |
}; |
| 9733 |
struct StateExtensive |
| 9734 |
{ |
| 9735 |
enum class Operation : uint8_t |
| 9736 |
{ |
| 9737 |
FindFreeBlockBuffer, FindFreeBlockTexture, FindFreeBlockAll, |
| 9738 |
MoveBuffers, MoveTextures, MoveAll, |
| 9739 |
Cleanup, Done |
| 9740 |
}; |
| 9741 |
|
| 9742 |
Operation operation = Operation::FindFreeBlockTexture; |
| 9743 |
size_t firstFreeBlock = SIZE_MAX; |
| 9744 |
}; |
| 9745 |
struct MoveAllocationData |
| 9746 |
{ |
| 9747 |
VkDeviceSize size; |
| 9748 |
VkDeviceSize alignment; |
| 9749 |
VmaSuballocationType type; |
| 9750 |
VmaAllocationCreateFlags flags; |
| 9751 |
VmaDefragmentationMove move = {}; |
| 9752 |
}; |
| 9753 |
|
| 9754 |
const VkDeviceSize m_MaxPassBytes; |
| 9755 |
const uint32_t m_MaxPassAllocations; |
| 9756 |
const PFN_vmaCheckDefragmentationBreakFunction m_BreakCallback; |
| 9757 |
void* m_BreakCallbackUserData; |
| 9758 |
|
| 9759 |
VmaStlAllocator<VmaDefragmentationMove> m_MoveAllocator; |
| 9760 |
VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove>> m_Moves; |
| 9761 |
|
| 9762 |
uint8_t m_IgnoredAllocs = 0; |
| 9763 |
uint32_t m_Algorithm; |
| 9764 |
uint32_t m_BlockVectorCount; |
| 9765 |
VmaBlockVector* m_PoolBlockVector; |
| 9766 |
VmaBlockVector** m_pBlockVectors; |
| 9767 |
size_t m_ImmovableBlockCount = 0; |
| 9768 |
VmaDefragmentationStats m_GlobalStats = { 0 }; |
| 9769 |
VmaDefragmentationStats m_PassStats = { 0 }; |
| 9770 |
void* m_AlgorithmState = VMA_NULL; |
| 9771 |
|
| 9772 |
static MoveAllocationData GetMoveData(VmaAllocHandle handle, VmaBlockMetadata* metadata); |
| 9773 |
CounterStatus CheckCounters(VkDeviceSize bytes); |
| 9774 |
bool IncrementCounters(VkDeviceSize bytes); |
| 9775 |
bool ReallocWithinBlock(VmaBlockVector& vector, VmaDeviceMemoryBlock* block); |
| 9776 |
bool AllocInOtherBlock(size_t start, size_t end, MoveAllocationData& data, VmaBlockVector& vector); |
| 9777 |
|
| 9778 |
bool ComputeDefragmentation(VmaBlockVector& vector, size_t index); |
| 9779 |
bool ComputeDefragmentation_Fast(VmaBlockVector& vector); |
| 9780 |
bool ComputeDefragmentation_Balanced(VmaBlockVector& vector, size_t index, bool update); |
| 9781 |
bool ComputeDefragmentation_Full(VmaBlockVector& vector); |
| 9782 |
bool ComputeDefragmentation_Extensive(VmaBlockVector& vector, size_t index); |
| 9783 |
|
| 9784 |
void UpdateVectorStatistics(VmaBlockVector& vector, StateBalanced& state); |
| 9785 |
bool MoveDataToFreeBlocks(VmaSuballocationType currentType, |
| 9786 |
VmaBlockVector& vector, size_t firstFreeBlock, |
| 9787 |
bool& texturePresent, bool& bufferPresent, bool& otherPresent); |
| 9788 |
}; |
| 9789 |
#endif |
| 9790 |
|
| 9791 |
#ifndef _VMA_POOL_T |
| 9792 |
struct VmaPool_T |
| 9793 |
{ |
| 9794 |
friend struct VmaPoolListItemTraits; |
| 9795 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaPool_T) |
| 9796 |
public: |
| 9797 |
VmaBlockVector m_BlockVector; |
| 9798 |
VmaDedicatedAllocationList m_DedicatedAllocations; |
| 9799 |
|
| 9800 |
VmaPool_T( |
| 9801 |
VmaAllocator hAllocator, |
| 9802 |
const VmaPoolCreateInfo& createInfo, |
| 9803 |
VkDeviceSize preferredBlockSize); |
| 9804 |
~VmaPool_T(); |
| 9805 |
|
| 9806 |
uint32_t GetId() const { return m_Id; } |
| 9807 |
void SetId(uint32_t id) { VMA_ASSERT(m_Id == 0); m_Id = id; } |
| 9808 |
|
| 9809 |
const char* GetName() const { return m_Name; } |
| 9810 |
void SetName(const char* pName); |
| 9811 |
|
| 9812 |
#if VMA_STATS_STRING_ENABLED |
| 9813 |
|
| 9814 |
#endif |
| 9815 |
|
| 9816 |
private: |
| 9817 |
uint32_t m_Id; |
| 9818 |
char* m_Name; |
| 9819 |
VmaPool_T* m_PrevPool = VMA_NULL; |
| 9820 |
VmaPool_T* m_NextPool = VMA_NULL; |
| 9821 |
}; |
| 9822 |
|
| 9823 |
struct VmaPoolListItemTraits |
| 9824 |
{ |
| 9825 |
typedef VmaPool_T ItemType; |
| 9826 |
|
| 9827 |
static ItemType* GetPrev(const ItemType* item) { return item->m_PrevPool; } |
| 9828 |
static ItemType* GetNext(const ItemType* item) { return item->m_NextPool; } |
| 9829 |
static ItemType*& AccessPrev(ItemType* item) { return item->m_PrevPool; } |
| 9830 |
static ItemType*& AccessNext(ItemType* item) { return item->m_NextPool; } |
| 9831 |
}; |
| 9832 |
#endif |
| 9833 |
|
| 9834 |
#ifndef _VMA_CURRENT_BUDGET_DATA |
| 9835 |
struct VmaCurrentBudgetData |
| 9836 |
{ |
| 9837 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaCurrentBudgetData) |
| 9838 |
public: |
| 9839 |
|
| 9840 |
VMA_ATOMIC_UINT32 m_BlockCount[VK_MAX_MEMORY_HEAPS]; |
| 9841 |
VMA_ATOMIC_UINT32 m_AllocationCount[VK_MAX_MEMORY_HEAPS]; |
| 9842 |
VMA_ATOMIC_UINT64 m_BlockBytes[VK_MAX_MEMORY_HEAPS]; |
| 9843 |
VMA_ATOMIC_UINT64 m_AllocationBytes[VK_MAX_MEMORY_HEAPS]; |
| 9844 |
|
| 9845 |
#if VMA_MEMORY_BUDGET |
| 9846 |
VMA_ATOMIC_UINT32 m_OperationsSinceBudgetFetch; |
| 9847 |
VMA_RW_MUTEX m_BudgetMutex; |
| 9848 |
uint64_t m_VulkanUsage[VK_MAX_MEMORY_HEAPS]; |
| 9849 |
uint64_t m_VulkanBudget[VK_MAX_MEMORY_HEAPS]; |
| 9850 |
uint64_t m_BlockBytesAtBudgetFetch[VK_MAX_MEMORY_HEAPS]; |
| 9851 |
#endif |
| 9852 |
|
| 9853 |
VmaCurrentBudgetData(); |
| 9854 |
|
| 9855 |
void AddAllocation(uint32_t heapIndex, VkDeviceSize allocationSize); |
| 9856 |
void RemoveAllocation(uint32_t heapIndex, VkDeviceSize allocationSize); |
| 9857 |
}; |
| 9858 |
|
| 9859 |
#ifndef _VMA_CURRENT_BUDGET_DATA_FUNCTIONS |
| 9860 |
VmaCurrentBudgetData::VmaCurrentBudgetData() |
| 9861 |
{ |
| 9862 |
for (uint32_t heapIndex = 0; heapIndex < VK_MAX_MEMORY_HEAPS; ++heapIndex) |
| 9863 |
{ |
| 9864 |
m_BlockCount[heapIndex] = 0; |
| 9865 |
m_AllocationCount[heapIndex] = 0; |
| 9866 |
m_BlockBytes[heapIndex] = 0; |
| 9867 |
m_AllocationBytes[heapIndex] = 0; |
| 9868 |
#if VMA_MEMORY_BUDGET |
| 9869 |
m_VulkanUsage[heapIndex] = 0; |
| 9870 |
m_VulkanBudget[heapIndex] = 0; |
| 9871 |
m_BlockBytesAtBudgetFetch[heapIndex] = 0; |
| 9872 |
#endif |
| 9873 |
} |
| 9874 |
|
| 9875 |
#if VMA_MEMORY_BUDGET |
| 9876 |
m_OperationsSinceBudgetFetch = 0; |
| 9877 |
#endif |
| 9878 |
} |
| 9879 |
|
| 9880 |
void VmaCurrentBudgetData::AddAllocation(uint32_t heapIndex, VkDeviceSize allocationSize) |
| 9881 |
{ |
| 9882 |
m_AllocationBytes[heapIndex] += allocationSize; |
| 9883 |
++m_AllocationCount[heapIndex]; |
| 9884 |
#if VMA_MEMORY_BUDGET |
| 9885 |
++m_OperationsSinceBudgetFetch; |
| 9886 |
#endif |
| 9887 |
} |
| 9888 |
|
| 9889 |
void VmaCurrentBudgetData::RemoveAllocation(uint32_t heapIndex, VkDeviceSize allocationSize) |
| 9890 |
{ |
| 9891 |
VMA_ASSERT(m_AllocationBytes[heapIndex] >= allocationSize); |
| 9892 |
m_AllocationBytes[heapIndex] -= allocationSize; |
| 9893 |
VMA_ASSERT(m_AllocationCount[heapIndex] > 0); |
| 9894 |
--m_AllocationCount[heapIndex]; |
| 9895 |
#if VMA_MEMORY_BUDGET |
| 9896 |
++m_OperationsSinceBudgetFetch; |
| 9897 |
#endif |
| 9898 |
} |
| 9899 |
#endif |
| 9900 |
#endif |
| 9901 |
|
| 9902 |
#ifndef _VMA_ALLOCATION_OBJECT_ALLOCATOR |
| 9903 |
|
| 9904 |
|
| 9905 |
|
| 9906 |
class VmaAllocationObjectAllocator |
| 9907 |
{ |
| 9908 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaAllocationObjectAllocator) |
| 9909 |
public: |
| 9910 |
VmaAllocationObjectAllocator(const VkAllocationCallbacks* pAllocationCallbacks) |
| 9911 |
: m_Allocator(pAllocationCallbacks, 1024) {} |
| 9912 |
|
| 9913 |
template<typename... Types> VmaAllocation Allocate(Types&&... args); |
| 9914 |
void Free(VmaAllocation hAlloc); |
| 9915 |
|
| 9916 |
private: |
| 9917 |
VMA_MUTEX m_Mutex; |
| 9918 |
VmaPoolAllocator<VmaAllocation_T> m_Allocator; |
| 9919 |
}; |
| 9920 |
|
| 9921 |
template<typename... Types> |
| 9922 |
VmaAllocation VmaAllocationObjectAllocator::Allocate(Types&&... args) |
| 9923 |
{ |
| 9924 |
VmaMutexLock mutexLock(m_Mutex); |
| 9925 |
return m_Allocator.Alloc<Types...>(std::forward<Types>(args)...); |
| 9926 |
} |
| 9927 |
|
| 9928 |
void VmaAllocationObjectAllocator::Free(VmaAllocation hAlloc) |
| 9929 |
{ |
| 9930 |
VmaMutexLock mutexLock(m_Mutex); |
| 9931 |
m_Allocator.Free(hAlloc); |
| 9932 |
} |
| 9933 |
#endif |
| 9934 |
|
| 9935 |
#ifndef _VMA_VIRTUAL_BLOCK_T |
| 9936 |
struct VmaVirtualBlock_T |
| 9937 |
{ |
| 9938 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaVirtualBlock_T) |
| 9939 |
public: |
| 9940 |
const bool m_AllocationCallbacksSpecified; |
| 9941 |
const VkAllocationCallbacks m_AllocationCallbacks; |
| 9942 |
|
| 9943 |
VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo); |
| 9944 |
~VmaVirtualBlock_T(); |
| 9945 |
|
| 9946 |
VkResult Init() { return VK_SUCCESS; } |
| 9947 |
bool IsEmpty() const { return m_Metadata->IsEmpty(); } |
| 9948 |
void Free(VmaVirtualAllocation allocation) { m_Metadata->Free((VmaAllocHandle)allocation); } |
| 9949 |
void SetAllocationUserData(VmaVirtualAllocation allocation, void* userData) { m_Metadata->SetAllocationUserData((VmaAllocHandle)allocation, userData); } |
| 9950 |
void Clear() { m_Metadata->Clear(); } |
| 9951 |
|
| 9952 |
const VkAllocationCallbacks* GetAllocationCallbacks() const; |
| 9953 |
void GetAllocationInfo(VmaVirtualAllocation allocation, VmaVirtualAllocationInfo& outInfo); |
| 9954 |
VkResult Allocate(const VmaVirtualAllocationCreateInfo& createInfo, VmaVirtualAllocation& outAllocation, |
| 9955 |
VkDeviceSize* outOffset); |
| 9956 |
void GetStatistics(VmaStatistics& outStats) const; |
| 9957 |
void CalculateDetailedStatistics(VmaDetailedStatistics& outStats) const; |
| 9958 |
#if VMA_STATS_STRING_ENABLED |
| 9959 |
void BuildStatsString(bool detailedMap, VmaStringBuilder& sb) const; |
| 9960 |
#endif |
| 9961 |
|
| 9962 |
private: |
| 9963 |
VmaBlockMetadata* m_Metadata; |
| 9964 |
}; |
| 9965 |
|
| 9966 |
#ifndef _VMA_VIRTUAL_BLOCK_T_FUNCTIONS |
| 9967 |
VmaVirtualBlock_T::VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo) |
| 9968 |
: m_AllocationCallbacksSpecified(createInfo.pAllocationCallbacks != VMA_NULL), |
| 9969 |
m_AllocationCallbacks(createInfo.pAllocationCallbacks != VMA_NULL ? *createInfo.pAllocationCallbacks : VmaEmptyAllocationCallbacks) |
| 9970 |
{ |
| 9971 |
const uint32_t algorithm = createInfo.flags & VMA_VIRTUAL_BLOCK_CREATE_ALGORITHM_MASK; |
| 9972 |
switch (algorithm) |
| 9973 |
{ |
| 9974 |
case 0: |
| 9975 |
m_Metadata = vma_new(GetAllocationCallbacks(), VmaBlockMetadata_TLSF)(VK_NULL_HANDLE, 1, true); |
| 9976 |
break; |
| 9977 |
case VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT: |
| 9978 |
m_Metadata = vma_new(GetAllocationCallbacks(), VmaBlockMetadata_Linear)(VK_NULL_HANDLE, 1, true); |
| 9979 |
break; |
| 9980 |
default: |
| 9981 |
VMA_ASSERT(0); |
| 9982 |
m_Metadata = vma_new(GetAllocationCallbacks(), VmaBlockMetadata_TLSF)(VK_NULL_HANDLE, 1, true); |
| 9983 |
} |
| 9984 |
|
| 9985 |
m_Metadata->Init(createInfo.size); |
| 9986 |
} |
| 9987 |
|
| 9988 |
VmaVirtualBlock_T::~VmaVirtualBlock_T() |
| 9989 |
{ |
| 9990 |
|
| 9991 |
|
| 9992 |
if (!m_Metadata->IsEmpty()) |
| 9993 |
m_Metadata->DebugLogAllAllocations(); |
| 9994 |
|
| 9995 |
|
| 9996 |
VMA_ASSERT_LEAK(m_Metadata->IsEmpty() && "Some virtual allocations were not freed before destruction of this virtual block!"); |
| 9997 |
|
| 9998 |
vma_delete(GetAllocationCallbacks(), m_Metadata); |
| 9999 |
} |
| 10000 |
|
| 10001 |
const VkAllocationCallbacks* VmaVirtualBlock_T::GetAllocationCallbacks() const |
| 10002 |
{ |
| 10003 |
return m_AllocationCallbacksSpecified ? &m_AllocationCallbacks : VMA_NULL; |
| 10004 |
} |
| 10005 |
|
| 10006 |
void VmaVirtualBlock_T::GetAllocationInfo(VmaVirtualAllocation allocation, VmaVirtualAllocationInfo& outInfo) |
| 10007 |
{ |
| 10008 |
m_Metadata->GetAllocationInfo((VmaAllocHandle)allocation, outInfo); |
| 10009 |
} |
| 10010 |
|
| 10011 |
VkResult VmaVirtualBlock_T::Allocate(const VmaVirtualAllocationCreateInfo& createInfo, VmaVirtualAllocation& outAllocation, |
| 10012 |
VkDeviceSize* outOffset) |
| 10013 |
{ |
| 10014 |
VmaAllocationRequest request = {}; |
| 10015 |
if (m_Metadata->CreateAllocationRequest( |
| 10016 |
createInfo.size, |
| 10017 |
VMA_MAX(createInfo.alignment, (VkDeviceSize)1), |
| 10018 |
(createInfo.flags & VMA_VIRTUAL_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0, |
| 10019 |
VMA_SUBALLOCATION_TYPE_UNKNOWN, |
| 10020 |
createInfo.flags & VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MASK, |
| 10021 |
&request)) |
| 10022 |
{ |
| 10023 |
m_Metadata->Alloc(request, |
| 10024 |
VMA_SUBALLOCATION_TYPE_UNKNOWN, |
| 10025 |
createInfo.pUserData); |
| 10026 |
outAllocation = (VmaVirtualAllocation)request.allocHandle; |
| 10027 |
if(outOffset) |
| 10028 |
*outOffset = m_Metadata->GetAllocationOffset(request.allocHandle); |
| 10029 |
return VK_SUCCESS; |
| 10030 |
} |
| 10031 |
outAllocation = (VmaVirtualAllocation)VK_NULL_HANDLE; |
| 10032 |
if (outOffset) |
| 10033 |
*outOffset = UINT64_MAX; |
| 10034 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 10035 |
} |
| 10036 |
|
| 10037 |
void VmaVirtualBlock_T::GetStatistics(VmaStatistics& outStats) const |
| 10038 |
{ |
| 10039 |
VmaClearStatistics(outStats); |
| 10040 |
m_Metadata->AddStatistics(outStats); |
| 10041 |
} |
| 10042 |
|
| 10043 |
void VmaVirtualBlock_T::CalculateDetailedStatistics(VmaDetailedStatistics& outStats) const |
| 10044 |
{ |
| 10045 |
VmaClearDetailedStatistics(outStats); |
| 10046 |
m_Metadata->AddDetailedStatistics(outStats); |
| 10047 |
} |
| 10048 |
|
| 10049 |
#if VMA_STATS_STRING_ENABLED |
| 10050 |
void VmaVirtualBlock_T::BuildStatsString(bool detailedMap, VmaStringBuilder& sb) const |
| 10051 |
{ |
| 10052 |
VmaJsonWriter json(GetAllocationCallbacks(), sb); |
| 10053 |
json.BeginObject(); |
| 10054 |
|
| 10055 |
VmaDetailedStatistics stats; |
| 10056 |
CalculateDetailedStatistics(stats); |
| 10057 |
|
| 10058 |
json.WriteString("Stats"); |
| 10059 |
VmaPrintDetailedStatistics(json, stats); |
| 10060 |
|
| 10061 |
if (detailedMap) |
| 10062 |
{ |
| 10063 |
json.WriteString("Details"); |
| 10064 |
json.BeginObject(); |
| 10065 |
m_Metadata->PrintDetailedMap(json); |
| 10066 |
json.EndObject(); |
| 10067 |
} |
| 10068 |
|
| 10069 |
json.EndObject(); |
| 10070 |
} |
| 10071 |
#endif |
| 10072 |
#endif |
| 10073 |
#endif |
| 10074 |
|
| 10075 |
|
| 10076 |
|
| 10077 |
struct VmaAllocator_T |
| 10078 |
{ |
| 10079 |
VMA_CLASS_NO_COPY_NO_MOVE(VmaAllocator_T) |
| 10080 |
public: |
| 10081 |
const bool m_UseMutex; |
| 10082 |
const uint32_t m_VulkanApiVersion; |
| 10083 |
bool m_UseKhrDedicatedAllocation; |
| 10084 |
bool m_UseKhrBindMemory2; |
| 10085 |
bool m_UseExtMemoryBudget; |
| 10086 |
bool m_UseAmdDeviceCoherentMemory; |
| 10087 |
bool m_UseKhrBufferDeviceAddress; |
| 10088 |
bool m_UseExtMemoryPriority; |
| 10089 |
bool m_UseKhrMaintenance4; |
| 10090 |
bool m_UseKhrMaintenance5; |
| 10091 |
const VkDevice m_hDevice; |
| 10092 |
const VkInstance m_hInstance; |
| 10093 |
const bool m_AllocationCallbacksSpecified; |
| 10094 |
const VkAllocationCallbacks m_AllocationCallbacks; |
| 10095 |
VmaDeviceMemoryCallbacks m_DeviceMemoryCallbacks; |
| 10096 |
VmaAllocationObjectAllocator m_AllocationObjectAllocator; |
| 10097 |
|
| 10098 |
|
| 10099 |
uint32_t m_HeapSizeLimitMask; |
| 10100 |
|
| 10101 |
VkPhysicalDeviceProperties m_PhysicalDeviceProperties; |
| 10102 |
VkPhysicalDeviceMemoryProperties m_MemProps; |
| 10103 |
|
| 10104 |
|
| 10105 |
VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES]; |
| 10106 |
VmaDedicatedAllocationList m_DedicatedAllocations[VK_MAX_MEMORY_TYPES]; |
| 10107 |
|
| 10108 |
VmaCurrentBudgetData m_Budget; |
| 10109 |
VMA_ATOMIC_UINT32 m_DeviceMemoryCount; |
| 10110 |
|
| 10111 |
VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo); |
| 10112 |
VkResult Init(const VmaAllocatorCreateInfo* pCreateInfo); |
| 10113 |
~VmaAllocator_T(); |
| 10114 |
|
| 10115 |
const VkAllocationCallbacks* GetAllocationCallbacks() const |
| 10116 |
{ |
| 10117 |
return m_AllocationCallbacksSpecified ? &m_AllocationCallbacks : VMA_NULL; |
| 10118 |
} |
| 10119 |
const VmaVulkanFunctions& GetVulkanFunctions() const |
| 10120 |
{ |
| 10121 |
return m_VulkanFunctions; |
| 10122 |
} |
| 10123 |
|
| 10124 |
VkPhysicalDevice GetPhysicalDevice() const { return m_PhysicalDevice; } |
| 10125 |
|
| 10126 |
VkDeviceSize GetBufferImageGranularity() const |
| 10127 |
{ |
| 10128 |
return VMA_MAX( |
| 10129 |
static_cast<VkDeviceSize>(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY), |
| 10130 |
m_PhysicalDeviceProperties.limits.bufferImageGranularity); |
| 10131 |
} |
| 10132 |
|
| 10133 |
uint32_t GetMemoryHeapCount() const { return m_MemProps.memoryHeapCount; } |
| 10134 |
uint32_t GetMemoryTypeCount() const { return m_MemProps.memoryTypeCount; } |
| 10135 |
|
| 10136 |
uint32_t MemoryTypeIndexToHeapIndex(uint32_t memTypeIndex) const |
| 10137 |
{ |
| 10138 |
VMA_ASSERT(memTypeIndex < m_MemProps.memoryTypeCount); |
| 10139 |
return m_MemProps.memoryTypes[memTypeIndex].heapIndex; |
| 10140 |
} |
| 10141 |
|
| 10142 |
bool IsMemoryTypeNonCoherent(uint32_t memTypeIndex) const |
| 10143 |
{ |
| 10144 |
return (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == |
| 10145 |
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 10146 |
} |
| 10147 |
|
| 10148 |
VkDeviceSize GetMemoryTypeMinAlignment(uint32_t memTypeIndex) const |
| 10149 |
{ |
| 10150 |
return IsMemoryTypeNonCoherent(memTypeIndex) ? |
| 10151 |
VMA_MAX((VkDeviceSize)VMA_MIN_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) : |
| 10152 |
(VkDeviceSize)VMA_MIN_ALIGNMENT; |
| 10153 |
} |
| 10154 |
|
| 10155 |
bool IsIntegratedGpu() const |
| 10156 |
{ |
| 10157 |
return m_PhysicalDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU; |
| 10158 |
} |
| 10159 |
|
| 10160 |
uint32_t GetGlobalMemoryTypeBits() const { return m_GlobalMemoryTypeBits; } |
| 10161 |
|
| 10162 |
void GetBufferMemoryRequirements( |
| 10163 |
VkBuffer hBuffer, |
| 10164 |
VkMemoryRequirements& memReq, |
| 10165 |
bool& requiresDedicatedAllocation, |
| 10166 |
bool& prefersDedicatedAllocation) const; |
| 10167 |
void GetImageMemoryRequirements( |
| 10168 |
VkImage hImage, |
| 10169 |
VkMemoryRequirements& memReq, |
| 10170 |
bool& requiresDedicatedAllocation, |
| 10171 |
bool& prefersDedicatedAllocation) const; |
| 10172 |
VkResult FindMemoryTypeIndex( |
| 10173 |
uint32_t memoryTypeBits, |
| 10174 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 10175 |
VmaBufferImageUsage bufImgUsage, |
| 10176 |
uint32_t* pMemoryTypeIndex) const; |
| 10177 |
|
| 10178 |
|
| 10179 |
VkResult AllocateMemory( |
| 10180 |
const VkMemoryRequirements& vkMemReq, |
| 10181 |
bool requiresDedicatedAllocation, |
| 10182 |
bool prefersDedicatedAllocation, |
| 10183 |
VkBuffer dedicatedBuffer, |
| 10184 |
VkImage dedicatedImage, |
| 10185 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 10186 |
const VmaAllocationCreateInfo& createInfo, |
| 10187 |
VmaSuballocationType suballocType, |
| 10188 |
size_t allocationCount, |
| 10189 |
VmaAllocation* pAllocations); |
| 10190 |
|
| 10191 |
|
| 10192 |
void FreeMemory( |
| 10193 |
size_t allocationCount, |
| 10194 |
const VmaAllocation* pAllocations); |
| 10195 |
|
| 10196 |
void CalculateStatistics(VmaTotalStatistics* pStats); |
| 10197 |
|
| 10198 |
void GetHeapBudgets( |
| 10199 |
VmaBudget* outBudgets, uint32_t firstHeap, uint32_t heapCount); |
| 10200 |
|
| 10201 |
#if VMA_STATS_STRING_ENABLED |
| 10202 |
void PrintDetailedMap(class VmaJsonWriter& json); |
| 10203 |
#endif |
| 10204 |
|
| 10205 |
void GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo); |
| 10206 |
void GetAllocationInfo2(VmaAllocation hAllocation, VmaAllocationInfo2* pAllocationInfo); |
| 10207 |
|
| 10208 |
VkResult CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPool* pPool); |
| 10209 |
void DestroyPool(VmaPool pool); |
| 10210 |
void GetPoolStatistics(VmaPool pool, VmaStatistics* pPoolStats); |
| 10211 |
void CalculatePoolStatistics(VmaPool pool, VmaDetailedStatistics* pPoolStats); |
| 10212 |
|
| 10213 |
void SetCurrentFrameIndex(uint32_t frameIndex); |
| 10214 |
uint32_t GetCurrentFrameIndex() const { return m_CurrentFrameIndex.load(); } |
| 10215 |
|
| 10216 |
VkResult CheckPoolCorruption(VmaPool hPool); |
| 10217 |
VkResult CheckCorruption(uint32_t memoryTypeBits); |
| 10218 |
|
| 10219 |
|
| 10220 |
VkResult AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory); |
| 10221 |
|
| 10222 |
void FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory); |
| 10223 |
|
| 10224 |
VkResult BindVulkanBuffer( |
| 10225 |
VkDeviceMemory memory, |
| 10226 |
VkDeviceSize memoryOffset, |
| 10227 |
VkBuffer buffer, |
| 10228 |
const void* pNext); |
| 10229 |
|
| 10230 |
VkResult BindVulkanImage( |
| 10231 |
VkDeviceMemory memory, |
| 10232 |
VkDeviceSize memoryOffset, |
| 10233 |
VkImage image, |
| 10234 |
const void* pNext); |
| 10235 |
|
| 10236 |
VkResult Map(VmaAllocation hAllocation, void** ppData); |
| 10237 |
void Unmap(VmaAllocation hAllocation); |
| 10238 |
|
| 10239 |
VkResult BindBufferMemory( |
| 10240 |
VmaAllocation hAllocation, |
| 10241 |
VkDeviceSize allocationLocalOffset, |
| 10242 |
VkBuffer hBuffer, |
| 10243 |
const void* pNext); |
| 10244 |
VkResult BindImageMemory( |
| 10245 |
VmaAllocation hAllocation, |
| 10246 |
VkDeviceSize allocationLocalOffset, |
| 10247 |
VkImage hImage, |
| 10248 |
const void* pNext); |
| 10249 |
|
| 10250 |
VkResult FlushOrInvalidateAllocation( |
| 10251 |
VmaAllocation hAllocation, |
| 10252 |
VkDeviceSize offset, VkDeviceSize size, |
| 10253 |
VMA_CACHE_OPERATION op); |
| 10254 |
VkResult FlushOrInvalidateAllocations( |
| 10255 |
uint32_t allocationCount, |
| 10256 |
const VmaAllocation* allocations, |
| 10257 |
const VkDeviceSize* offsets, const VkDeviceSize* sizes, |
| 10258 |
VMA_CACHE_OPERATION op); |
| 10259 |
|
| 10260 |
VkResult CopyMemoryToAllocation( |
| 10261 |
const void* pSrcHostPointer, |
| 10262 |
VmaAllocation dstAllocation, |
| 10263 |
VkDeviceSize dstAllocationLocalOffset, |
| 10264 |
VkDeviceSize size); |
| 10265 |
VkResult CopyAllocationToMemory( |
| 10266 |
VmaAllocation srcAllocation, |
| 10267 |
VkDeviceSize srcAllocationLocalOffset, |
| 10268 |
void* pDstHostPointer, |
| 10269 |
VkDeviceSize size); |
| 10270 |
|
| 10271 |
void FillAllocation(const VmaAllocation hAllocation, uint8_t pattern); |
| 10272 |
|
| 10273 |
|
| 10274 |
|
| 10275 |
|
| 10276 |
|
| 10277 |
uint32_t GetGpuDefragmentationMemoryTypeBits(); |
| 10278 |
|
| 10279 |
#if VMA_EXTERNAL_MEMORY |
| 10280 |
VkExternalMemoryHandleTypeFlagsKHR GetExternalMemoryHandleTypeFlags(uint32_t memTypeIndex) const |
| 10281 |
{ |
| 10282 |
return m_TypeExternalMemoryHandleTypes[memTypeIndex]; |
| 10283 |
} |
| 10284 |
#endif |
| 10285 |
|
| 10286 |
private: |
| 10287 |
VkDeviceSize m_PreferredLargeHeapBlockSize; |
| 10288 |
|
| 10289 |
VkPhysicalDevice m_PhysicalDevice; |
| 10290 |
VMA_ATOMIC_UINT32 m_CurrentFrameIndex; |
| 10291 |
VMA_ATOMIC_UINT32 m_GpuDefragmentationMemoryTypeBits; |
| 10292 |
#if VMA_EXTERNAL_MEMORY |
| 10293 |
VkExternalMemoryHandleTypeFlagsKHR m_TypeExternalMemoryHandleTypes[VK_MAX_MEMORY_TYPES]; |
| 10294 |
#endif |
| 10295 |
|
| 10296 |
VMA_RW_MUTEX m_PoolsMutex; |
| 10297 |
typedef VmaIntrusiveLinkedList<VmaPoolListItemTraits> PoolList; |
| 10298 |
|
| 10299 |
PoolList m_Pools; |
| 10300 |
uint32_t m_NextPoolId; |
| 10301 |
|
| 10302 |
VmaVulkanFunctions m_VulkanFunctions; |
| 10303 |
|
| 10304 |
|
| 10305 |
uint32_t m_GlobalMemoryTypeBits; |
| 10306 |
|
| 10307 |
void ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunctions); |
| 10308 |
|
| 10309 |
#if VMA_STATIC_VULKAN_FUNCTIONS == 1 |
| 10310 |
void ImportVulkanFunctions_Static(); |
| 10311 |
#endif |
| 10312 |
|
| 10313 |
void ImportVulkanFunctions_Custom(const VmaVulkanFunctions* pVulkanFunctions); |
| 10314 |
|
| 10315 |
#if VMA_DYNAMIC_VULKAN_FUNCTIONS == 1 |
| 10316 |
void ImportVulkanFunctions_Dynamic(); |
| 10317 |
#endif |
| 10318 |
|
| 10319 |
void ValidateVulkanFunctions(); |
| 10320 |
|
| 10321 |
VkDeviceSize CalcPreferredBlockSize(uint32_t memTypeIndex); |
| 10322 |
|
| 10323 |
VkResult AllocateMemoryOfType( |
| 10324 |
VmaPool pool, |
| 10325 |
VkDeviceSize size, |
| 10326 |
VkDeviceSize alignment, |
| 10327 |
bool dedicatedPreferred, |
| 10328 |
VkBuffer dedicatedBuffer, |
| 10329 |
VkImage dedicatedImage, |
| 10330 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 10331 |
const VmaAllocationCreateInfo& createInfo, |
| 10332 |
uint32_t memTypeIndex, |
| 10333 |
VmaSuballocationType suballocType, |
| 10334 |
VmaDedicatedAllocationList& dedicatedAllocations, |
| 10335 |
VmaBlockVector& blockVector, |
| 10336 |
size_t allocationCount, |
| 10337 |
VmaAllocation* pAllocations); |
| 10338 |
|
| 10339 |
|
| 10340 |
VkResult AllocateDedicatedMemoryPage( |
| 10341 |
VmaPool pool, |
| 10342 |
VkDeviceSize size, |
| 10343 |
VmaSuballocationType suballocType, |
| 10344 |
uint32_t memTypeIndex, |
| 10345 |
const VkMemoryAllocateInfo& allocInfo, |
| 10346 |
bool map, |
| 10347 |
bool isUserDataString, |
| 10348 |
bool isMappingAllowed, |
| 10349 |
void* pUserData, |
| 10350 |
VmaAllocation* pAllocation); |
| 10351 |
|
| 10352 |
|
| 10353 |
VkResult AllocateDedicatedMemory( |
| 10354 |
VmaPool pool, |
| 10355 |
VkDeviceSize size, |
| 10356 |
VmaSuballocationType suballocType, |
| 10357 |
VmaDedicatedAllocationList& dedicatedAllocations, |
| 10358 |
uint32_t memTypeIndex, |
| 10359 |
bool map, |
| 10360 |
bool isUserDataString, |
| 10361 |
bool isMappingAllowed, |
| 10362 |
bool canAliasMemory, |
| 10363 |
void* pUserData, |
| 10364 |
float priority, |
| 10365 |
VkBuffer dedicatedBuffer, |
| 10366 |
VkImage dedicatedImage, |
| 10367 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 10368 |
size_t allocationCount, |
| 10369 |
VmaAllocation* pAllocations, |
| 10370 |
const void* pNextChain = VMA_NULL); |
| 10371 |
|
| 10372 |
void FreeDedicatedMemory(const VmaAllocation allocation); |
| 10373 |
|
| 10374 |
VkResult CalcMemTypeParams( |
| 10375 |
VmaAllocationCreateInfo& outCreateInfo, |
| 10376 |
uint32_t memTypeIndex, |
| 10377 |
VkDeviceSize size, |
| 10378 |
size_t allocationCount); |
| 10379 |
VkResult CalcAllocationParams( |
| 10380 |
VmaAllocationCreateInfo& outCreateInfo, |
| 10381 |
bool dedicatedRequired, |
| 10382 |
bool dedicatedPreferred); |
| 10383 |
|
| 10384 |
|
| 10385 |
|
| 10386 |
|
| 10387 |
|
| 10388 |
uint32_t CalculateGpuDefragmentationMemoryTypeBits() const; |
| 10389 |
uint32_t CalculateGlobalMemoryTypeBits() const; |
| 10390 |
|
| 10391 |
bool GetFlushOrInvalidateRange( |
| 10392 |
VmaAllocation allocation, |
| 10393 |
VkDeviceSize offset, VkDeviceSize size, |
| 10394 |
VkMappedMemoryRange& outRange) const; |
| 10395 |
|
| 10396 |
#if VMA_MEMORY_BUDGET |
| 10397 |
void UpdateVulkanBudget(); |
| 10398 |
#endif |
| 10399 |
}; |
| 10400 |
|
| 10401 |
|
| 10402 |
#ifndef _VMA_MEMORY_FUNCTIONS |
| 10403 |
static void* VmaMalloc(VmaAllocator hAllocator, size_t size, size_t alignment) |
| 10404 |
{ |
| 10405 |
return VmaMalloc(&hAllocator->m_AllocationCallbacks, size, alignment); |
| 10406 |
} |
| 10407 |
|
| 10408 |
static void VmaFree(VmaAllocator hAllocator, void* ptr) |
| 10409 |
{ |
| 10410 |
VmaFree(&hAllocator->m_AllocationCallbacks, ptr); |
| 10411 |
} |
| 10412 |
|
| 10413 |
template<typename T> |
| 10414 |
static T* VmaAllocate(VmaAllocator hAllocator) |
| 10415 |
{ |
| 10416 |
return (T*)VmaMalloc(hAllocator, sizeof(T), VMA_ALIGN_OF(T)); |
| 10417 |
} |
| 10418 |
|
| 10419 |
template<typename T> |
| 10420 |
static T* VmaAllocateArray(VmaAllocator hAllocator, size_t count) |
| 10421 |
{ |
| 10422 |
return (T*)VmaMalloc(hAllocator, sizeof(T) * count, VMA_ALIGN_OF(T)); |
| 10423 |
} |
| 10424 |
|
| 10425 |
template<typename T> |
| 10426 |
static void vma_delete(VmaAllocator hAllocator, T* ptr) |
| 10427 |
{ |
| 10428 |
if(ptr != VMA_NULL) |
| 10429 |
{ |
| 10430 |
ptr->~T(); |
| 10431 |
VmaFree(hAllocator, ptr); |
| 10432 |
} |
| 10433 |
} |
| 10434 |
|
| 10435 |
template<typename T> |
| 10436 |
static void vma_delete_array(VmaAllocator hAllocator, T* ptr, size_t count) |
| 10437 |
{ |
| 10438 |
if(ptr != VMA_NULL) |
| 10439 |
{ |
| 10440 |
for(size_t i = count; i--; ) |
| 10441 |
ptr[i].~T(); |
| 10442 |
VmaFree(hAllocator, ptr); |
| 10443 |
} |
| 10444 |
} |
| 10445 |
#endif |
| 10446 |
|
| 10447 |
#ifndef _VMA_DEVICE_MEMORY_BLOCK_FUNCTIONS |
| 10448 |
VmaDeviceMemoryBlock::VmaDeviceMemoryBlock(VmaAllocator hAllocator) |
| 10449 |
: m_pMetadata(VMA_NULL), |
| 10450 |
m_MemoryTypeIndex(UINT32_MAX), |
| 10451 |
m_Id(0), |
| 10452 |
m_hMemory(VK_NULL_HANDLE), |
| 10453 |
m_MapCount(0), |
| 10454 |
m_pMappedData(VMA_NULL) {} |
| 10455 |
|
| 10456 |
VmaDeviceMemoryBlock::~VmaDeviceMemoryBlock() |
| 10457 |
{ |
| 10458 |
VMA_ASSERT_LEAK(m_MapCount == 0 && "VkDeviceMemory block is being destroyed while it is still mapped."); |
| 10459 |
VMA_ASSERT_LEAK(m_hMemory == VK_NULL_HANDLE); |
| 10460 |
} |
| 10461 |
|
| 10462 |
void VmaDeviceMemoryBlock::Init( |
| 10463 |
VmaAllocator hAllocator, |
| 10464 |
VmaPool hParentPool, |
| 10465 |
uint32_t newMemoryTypeIndex, |
| 10466 |
VkDeviceMemory newMemory, |
| 10467 |
VkDeviceSize newSize, |
| 10468 |
uint32_t id, |
| 10469 |
uint32_t algorithm, |
| 10470 |
VkDeviceSize bufferImageGranularity) |
| 10471 |
{ |
| 10472 |
VMA_ASSERT(m_hMemory == VK_NULL_HANDLE); |
| 10473 |
|
| 10474 |
m_hParentPool = hParentPool; |
| 10475 |
m_MemoryTypeIndex = newMemoryTypeIndex; |
| 10476 |
m_Id = id; |
| 10477 |
m_hMemory = newMemory; |
| 10478 |
|
| 10479 |
switch (algorithm) |
| 10480 |
{ |
| 10481 |
case 0: |
| 10482 |
m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_TLSF)(hAllocator->GetAllocationCallbacks(), |
| 10483 |
bufferImageGranularity, false); |
| 10484 |
break; |
| 10485 |
case VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT: |
| 10486 |
m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Linear)(hAllocator->GetAllocationCallbacks(), |
| 10487 |
bufferImageGranularity, false); |
| 10488 |
break; |
| 10489 |
default: |
| 10490 |
VMA_ASSERT(0); |
| 10491 |
m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_TLSF)(hAllocator->GetAllocationCallbacks(), |
| 10492 |
bufferImageGranularity, false); |
| 10493 |
} |
| 10494 |
m_pMetadata->Init(newSize); |
| 10495 |
} |
| 10496 |
|
| 10497 |
void VmaDeviceMemoryBlock::Destroy(VmaAllocator allocator) |
| 10498 |
{ |
| 10499 |
|
| 10500 |
|
| 10501 |
if (!m_pMetadata->IsEmpty()) |
| 10502 |
m_pMetadata->DebugLogAllAllocations(); |
| 10503 |
|
| 10504 |
|
| 10505 |
VMA_ASSERT_LEAK(m_pMetadata->IsEmpty() && "Some allocations were not freed before destruction of this memory block!"); |
| 10506 |
|
| 10507 |
VMA_ASSERT_LEAK(m_hMemory != VK_NULL_HANDLE); |
| 10508 |
allocator->FreeVulkanMemory(m_MemoryTypeIndex, m_pMetadata->GetSize(), m_hMemory); |
| 10509 |
m_hMemory = VK_NULL_HANDLE; |
| 10510 |
|
| 10511 |
vma_delete(allocator, m_pMetadata); |
| 10512 |
m_pMetadata = VMA_NULL; |
| 10513 |
} |
| 10514 |
|
| 10515 |
void VmaDeviceMemoryBlock::PostAlloc(VmaAllocator hAllocator) |
| 10516 |
{ |
| 10517 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10518 |
m_MappingHysteresis.PostAlloc(); |
| 10519 |
} |
| 10520 |
|
| 10521 |
void VmaDeviceMemoryBlock::PostFree(VmaAllocator hAllocator) |
| 10522 |
{ |
| 10523 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10524 |
if(m_MappingHysteresis.PostFree()) |
| 10525 |
{ |
| 10526 |
VMA_ASSERT(m_MappingHysteresis.GetExtraMapping() == 0); |
| 10527 |
if (m_MapCount == 0) |
| 10528 |
{ |
| 10529 |
m_pMappedData = VMA_NULL; |
| 10530 |
(*hAllocator->GetVulkanFunctions().vkUnmapMemory)(hAllocator->m_hDevice, m_hMemory); |
| 10531 |
} |
| 10532 |
} |
| 10533 |
} |
| 10534 |
|
| 10535 |
bool VmaDeviceMemoryBlock::Validate() const |
| 10536 |
{ |
| 10537 |
VMA_VALIDATE((m_hMemory != VK_NULL_HANDLE) && |
| 10538 |
(m_pMetadata->GetSize() != 0)); |
| 10539 |
|
| 10540 |
return m_pMetadata->Validate(); |
| 10541 |
} |
| 10542 |
|
| 10543 |
VkResult VmaDeviceMemoryBlock::CheckCorruption(VmaAllocator hAllocator) |
| 10544 |
{ |
| 10545 |
void* pData = VMA_NULL; |
| 10546 |
VkResult res = Map(hAllocator, 1, &pData); |
| 10547 |
if (res != VK_SUCCESS) |
| 10548 |
{ |
| 10549 |
return res; |
| 10550 |
} |
| 10551 |
|
| 10552 |
res = m_pMetadata->CheckCorruption(pData); |
| 10553 |
|
| 10554 |
Unmap(hAllocator, 1); |
| 10555 |
|
| 10556 |
return res; |
| 10557 |
} |
| 10558 |
|
| 10559 |
VkResult VmaDeviceMemoryBlock::Map(VmaAllocator hAllocator, uint32_t count, void** ppData) |
| 10560 |
{ |
| 10561 |
if (count == 0) |
| 10562 |
{ |
| 10563 |
return VK_SUCCESS; |
| 10564 |
} |
| 10565 |
|
| 10566 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10567 |
const uint32_t oldTotalMapCount = m_MapCount + m_MappingHysteresis.GetExtraMapping(); |
| 10568 |
if (oldTotalMapCount != 0) |
| 10569 |
{ |
| 10570 |
VMA_ASSERT(m_pMappedData != VMA_NULL); |
| 10571 |
m_MappingHysteresis.PostMap(); |
| 10572 |
m_MapCount += count; |
| 10573 |
if (ppData != VMA_NULL) |
| 10574 |
{ |
| 10575 |
*ppData = m_pMappedData; |
| 10576 |
} |
| 10577 |
return VK_SUCCESS; |
| 10578 |
} |
| 10579 |
else |
| 10580 |
{ |
| 10581 |
VkResult result = (*hAllocator->GetVulkanFunctions().vkMapMemory)( |
| 10582 |
hAllocator->m_hDevice, |
| 10583 |
m_hMemory, |
| 10584 |
0, |
| 10585 |
VK_WHOLE_SIZE, |
| 10586 |
0, |
| 10587 |
&m_pMappedData); |
| 10588 |
if (result == VK_SUCCESS) |
| 10589 |
{ |
| 10590 |
VMA_ASSERT(m_pMappedData != VMA_NULL); |
| 10591 |
m_MappingHysteresis.PostMap(); |
| 10592 |
m_MapCount = count; |
| 10593 |
if (ppData != VMA_NULL) |
| 10594 |
{ |
| 10595 |
*ppData = m_pMappedData; |
| 10596 |
} |
| 10597 |
} |
| 10598 |
return result; |
| 10599 |
} |
| 10600 |
} |
| 10601 |
|
| 10602 |
void VmaDeviceMemoryBlock::Unmap(VmaAllocator hAllocator, uint32_t count) |
| 10603 |
{ |
| 10604 |
if (count == 0) |
| 10605 |
{ |
| 10606 |
return; |
| 10607 |
} |
| 10608 |
|
| 10609 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10610 |
if (m_MapCount >= count) |
| 10611 |
{ |
| 10612 |
m_MapCount -= count; |
| 10613 |
const uint32_t totalMapCount = m_MapCount + m_MappingHysteresis.GetExtraMapping(); |
| 10614 |
if (totalMapCount == 0) |
| 10615 |
{ |
| 10616 |
m_pMappedData = VMA_NULL; |
| 10617 |
(*hAllocator->GetVulkanFunctions().vkUnmapMemory)(hAllocator->m_hDevice, m_hMemory); |
| 10618 |
} |
| 10619 |
m_MappingHysteresis.PostUnmap(); |
| 10620 |
} |
| 10621 |
else |
| 10622 |
{ |
| 10623 |
VMA_ASSERT(0 && "VkDeviceMemory block is being unmapped while it was not previously mapped."); |
| 10624 |
} |
| 10625 |
} |
| 10626 |
|
| 10627 |
VkResult VmaDeviceMemoryBlock::WriteMagicValueAfterAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize) |
| 10628 |
{ |
| 10629 |
VMA_ASSERT(VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_MARGIN % 4 == 0 && VMA_DEBUG_DETECT_CORRUPTION); |
| 10630 |
|
| 10631 |
void* pData; |
| 10632 |
VkResult res = Map(hAllocator, 1, &pData); |
| 10633 |
if (res != VK_SUCCESS) |
| 10634 |
{ |
| 10635 |
return res; |
| 10636 |
} |
| 10637 |
|
| 10638 |
VmaWriteMagicValue(pData, allocOffset + allocSize); |
| 10639 |
|
| 10640 |
Unmap(hAllocator, 1); |
| 10641 |
return VK_SUCCESS; |
| 10642 |
} |
| 10643 |
|
| 10644 |
VkResult VmaDeviceMemoryBlock::ValidateMagicValueAfterAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize) |
| 10645 |
{ |
| 10646 |
VMA_ASSERT(VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_MARGIN % 4 == 0 && VMA_DEBUG_DETECT_CORRUPTION); |
| 10647 |
|
| 10648 |
void* pData; |
| 10649 |
VkResult res = Map(hAllocator, 1, &pData); |
| 10650 |
if (res != VK_SUCCESS) |
| 10651 |
{ |
| 10652 |
return res; |
| 10653 |
} |
| 10654 |
|
| 10655 |
if (!VmaValidateMagicValue(pData, allocOffset + allocSize)) |
| 10656 |
{ |
| 10657 |
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER FREED ALLOCATION!"); |
| 10658 |
} |
| 10659 |
|
| 10660 |
Unmap(hAllocator, 1); |
| 10661 |
return VK_SUCCESS; |
| 10662 |
} |
| 10663 |
|
| 10664 |
VkResult VmaDeviceMemoryBlock::BindBufferMemory( |
| 10665 |
const VmaAllocator hAllocator, |
| 10666 |
const VmaAllocation hAllocation, |
| 10667 |
VkDeviceSize allocationLocalOffset, |
| 10668 |
VkBuffer hBuffer, |
| 10669 |
const void* pNext) |
| 10670 |
{ |
| 10671 |
VMA_ASSERT(hAllocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK && |
| 10672 |
hAllocation->GetBlock() == this); |
| 10673 |
VMA_ASSERT(allocationLocalOffset < hAllocation->GetSize() && |
| 10674 |
"Invalid allocationLocalOffset. Did you forget that this offset is relative to the beginning of the allocation, not the whole memory block?"); |
| 10675 |
const VkDeviceSize memoryOffset = hAllocation->GetOffset() + allocationLocalOffset; |
| 10676 |
|
| 10677 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10678 |
return hAllocator->BindVulkanBuffer(m_hMemory, memoryOffset, hBuffer, pNext); |
| 10679 |
} |
| 10680 |
|
| 10681 |
VkResult VmaDeviceMemoryBlock::BindImageMemory( |
| 10682 |
const VmaAllocator hAllocator, |
| 10683 |
const VmaAllocation hAllocation, |
| 10684 |
VkDeviceSize allocationLocalOffset, |
| 10685 |
VkImage hImage, |
| 10686 |
const void* pNext) |
| 10687 |
{ |
| 10688 |
VMA_ASSERT(hAllocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK && |
| 10689 |
hAllocation->GetBlock() == this); |
| 10690 |
VMA_ASSERT(allocationLocalOffset < hAllocation->GetSize() && |
| 10691 |
"Invalid allocationLocalOffset. Did you forget that this offset is relative to the beginning of the allocation, not the whole memory block?"); |
| 10692 |
const VkDeviceSize memoryOffset = hAllocation->GetOffset() + allocationLocalOffset; |
| 10693 |
|
| 10694 |
VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); |
| 10695 |
return hAllocator->BindVulkanImage(m_hMemory, memoryOffset, hImage, pNext); |
| 10696 |
} |
| 10697 |
#endif |
| 10698 |
|
| 10699 |
#ifndef _VMA_ALLOCATION_T_FUNCTIONS |
| 10700 |
VmaAllocation_T::VmaAllocation_T(bool mappingAllowed) |
| 10701 |
: m_Alignment{ 1 }, |
| 10702 |
m_Size{ 0 }, |
| 10703 |
m_pUserData{ VMA_NULL }, |
| 10704 |
m_pName{ VMA_NULL }, |
| 10705 |
m_MemoryTypeIndex{ 0 }, |
| 10706 |
m_Type{ (uint8_t)ALLOCATION_TYPE_NONE }, |
| 10707 |
m_SuballocationType{ (uint8_t)VMA_SUBALLOCATION_TYPE_UNKNOWN }, |
| 10708 |
m_MapCount{ 0 }, |
| 10709 |
m_Flags{ 0 } |
| 10710 |
{ |
| 10711 |
if(mappingAllowed) |
| 10712 |
m_Flags |= (uint8_t)FLAG_MAPPING_ALLOWED; |
| 10713 |
} |
| 10714 |
|
| 10715 |
VmaAllocation_T::~VmaAllocation_T() |
| 10716 |
{ |
| 10717 |
VMA_ASSERT_LEAK(m_MapCount == 0 && "Allocation was not unmapped before destruction."); |
| 10718 |
|
| 10719 |
|
| 10720 |
VMA_ASSERT(m_pName == VMA_NULL); |
| 10721 |
} |
| 10722 |
|
| 10723 |
void VmaAllocation_T::InitBlockAllocation( |
| 10724 |
VmaDeviceMemoryBlock* block, |
| 10725 |
VmaAllocHandle allocHandle, |
| 10726 |
VkDeviceSize alignment, |
| 10727 |
VkDeviceSize size, |
| 10728 |
uint32_t memoryTypeIndex, |
| 10729 |
VmaSuballocationType suballocationType, |
| 10730 |
bool mapped) |
| 10731 |
{ |
| 10732 |
VMA_ASSERT(m_Type == ALLOCATION_TYPE_NONE); |
| 10733 |
VMA_ASSERT(block != VMA_NULL); |
| 10734 |
m_Type = (uint8_t)ALLOCATION_TYPE_BLOCK; |
| 10735 |
m_Alignment = alignment; |
| 10736 |
m_Size = size; |
| 10737 |
m_MemoryTypeIndex = memoryTypeIndex; |
| 10738 |
if(mapped) |
| 10739 |
{ |
| 10740 |
VMA_ASSERT(IsMappingAllowed() && "Mapping is not allowed on this allocation! Please use one of the new VMA_ALLOCATION_CREATE_HOST_ACCESS_* flags when creating it."); |
| 10741 |
m_Flags |= (uint8_t)FLAG_PERSISTENT_MAP; |
| 10742 |
} |
| 10743 |
m_SuballocationType = (uint8_t)suballocationType; |
| 10744 |
m_BlockAllocation.m_Block = block; |
| 10745 |
m_BlockAllocation.m_AllocHandle = allocHandle; |
| 10746 |
} |
| 10747 |
|
| 10748 |
void VmaAllocation_T::InitDedicatedAllocation( |
| 10749 |
VmaPool hParentPool, |
| 10750 |
uint32_t memoryTypeIndex, |
| 10751 |
VkDeviceMemory hMemory, |
| 10752 |
VmaSuballocationType suballocationType, |
| 10753 |
void* pMappedData, |
| 10754 |
VkDeviceSize size) |
| 10755 |
{ |
| 10756 |
VMA_ASSERT(m_Type == ALLOCATION_TYPE_NONE); |
| 10757 |
VMA_ASSERT(hMemory != VK_NULL_HANDLE); |
| 10758 |
m_Type = (uint8_t)ALLOCATION_TYPE_DEDICATED; |
| 10759 |
m_Alignment = 0; |
| 10760 |
m_Size = size; |
| 10761 |
m_MemoryTypeIndex = memoryTypeIndex; |
| 10762 |
m_SuballocationType = (uint8_t)suballocationType; |
| 10763 |
if(pMappedData != VMA_NULL) |
| 10764 |
{ |
| 10765 |
VMA_ASSERT(IsMappingAllowed() && "Mapping is not allowed on this allocation! Please use one of the new VMA_ALLOCATION_CREATE_HOST_ACCESS_* flags when creating it."); |
| 10766 |
m_Flags |= (uint8_t)FLAG_PERSISTENT_MAP; |
| 10767 |
} |
| 10768 |
m_DedicatedAllocation.m_hParentPool = hParentPool; |
| 10769 |
m_DedicatedAllocation.m_hMemory = hMemory; |
| 10770 |
m_DedicatedAllocation.m_pMappedData = pMappedData; |
| 10771 |
m_DedicatedAllocation.m_Prev = VMA_NULL; |
| 10772 |
m_DedicatedAllocation.m_Next = VMA_NULL; |
| 10773 |
} |
| 10774 |
|
| 10775 |
void VmaAllocation_T::SetName(VmaAllocator hAllocator, const char* pName) |
| 10776 |
{ |
| 10777 |
VMA_ASSERT(pName == VMA_NULL || pName != m_pName); |
| 10778 |
|
| 10779 |
FreeName(hAllocator); |
| 10780 |
|
| 10781 |
if (pName != VMA_NULL) |
| 10782 |
m_pName = VmaCreateStringCopy(hAllocator->GetAllocationCallbacks(), pName); |
| 10783 |
} |
| 10784 |
|
| 10785 |
uint8_t VmaAllocation_T::SwapBlockAllocation(VmaAllocator hAllocator, VmaAllocation allocation) |
| 10786 |
{ |
| 10787 |
VMA_ASSERT(allocation != VMA_NULL); |
| 10788 |
VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK); |
| 10789 |
VMA_ASSERT(allocation->m_Type == ALLOCATION_TYPE_BLOCK); |
| 10790 |
|
| 10791 |
if (m_MapCount != 0) |
| 10792 |
m_BlockAllocation.m_Block->Unmap(hAllocator, m_MapCount); |
| 10793 |
|
| 10794 |
m_BlockAllocation.m_Block->m_pMetadata->SetAllocationUserData(m_BlockAllocation.m_AllocHandle, allocation); |
| 10795 |
std::swap(m_BlockAllocation, allocation->m_BlockAllocation); |
| 10796 |
m_BlockAllocation.m_Block->m_pMetadata->SetAllocationUserData(m_BlockAllocation.m_AllocHandle, this); |
| 10797 |
|
| 10798 |
#if VMA_STATS_STRING_ENABLED |
| 10799 |
std::swap(m_BufferImageUsage, allocation->m_BufferImageUsage); |
| 10800 |
#endif |
| 10801 |
return m_MapCount; |
| 10802 |
} |
| 10803 |
|
| 10804 |
VmaAllocHandle VmaAllocation_T::GetAllocHandle() const |
| 10805 |
{ |
| 10806 |
switch (m_Type) |
| 10807 |
{ |
| 10808 |
case ALLOCATION_TYPE_BLOCK: |
| 10809 |
return m_BlockAllocation.m_AllocHandle; |
| 10810 |
case ALLOCATION_TYPE_DEDICATED: |
| 10811 |
return VK_NULL_HANDLE; |
| 10812 |
default: |
| 10813 |
VMA_ASSERT(0); |
| 10814 |
return VK_NULL_HANDLE; |
| 10815 |
} |
| 10816 |
} |
| 10817 |
|
| 10818 |
VkDeviceSize VmaAllocation_T::GetOffset() const |
| 10819 |
{ |
| 10820 |
switch (m_Type) |
| 10821 |
{ |
| 10822 |
case ALLOCATION_TYPE_BLOCK: |
| 10823 |
return m_BlockAllocation.m_Block->m_pMetadata->GetAllocationOffset(m_BlockAllocation.m_AllocHandle); |
| 10824 |
case ALLOCATION_TYPE_DEDICATED: |
| 10825 |
return 0; |
| 10826 |
default: |
| 10827 |
VMA_ASSERT(0); |
| 10828 |
return 0; |
| 10829 |
} |
| 10830 |
} |
| 10831 |
|
| 10832 |
VmaPool VmaAllocation_T::GetParentPool() const |
| 10833 |
{ |
| 10834 |
switch (m_Type) |
| 10835 |
{ |
| 10836 |
case ALLOCATION_TYPE_BLOCK: |
| 10837 |
return m_BlockAllocation.m_Block->GetParentPool(); |
| 10838 |
case ALLOCATION_TYPE_DEDICATED: |
| 10839 |
return m_DedicatedAllocation.m_hParentPool; |
| 10840 |
default: |
| 10841 |
VMA_ASSERT(0); |
| 10842 |
return VK_NULL_HANDLE; |
| 10843 |
} |
| 10844 |
} |
| 10845 |
|
| 10846 |
VkDeviceMemory VmaAllocation_T::GetMemory() const |
| 10847 |
{ |
| 10848 |
switch (m_Type) |
| 10849 |
{ |
| 10850 |
case ALLOCATION_TYPE_BLOCK: |
| 10851 |
return m_BlockAllocation.m_Block->GetDeviceMemory(); |
| 10852 |
case ALLOCATION_TYPE_DEDICATED: |
| 10853 |
return m_DedicatedAllocation.m_hMemory; |
| 10854 |
default: |
| 10855 |
VMA_ASSERT(0); |
| 10856 |
return VK_NULL_HANDLE; |
| 10857 |
} |
| 10858 |
} |
| 10859 |
|
| 10860 |
void* VmaAllocation_T::GetMappedData() const |
| 10861 |
{ |
| 10862 |
switch (m_Type) |
| 10863 |
{ |
| 10864 |
case ALLOCATION_TYPE_BLOCK: |
| 10865 |
if (m_MapCount != 0 || IsPersistentMap()) |
| 10866 |
{ |
| 10867 |
void* pBlockData = m_BlockAllocation.m_Block->GetMappedData(); |
| 10868 |
VMA_ASSERT(pBlockData != VMA_NULL); |
| 10869 |
return (char*)pBlockData + GetOffset(); |
| 10870 |
} |
| 10871 |
else |
| 10872 |
{ |
| 10873 |
return VMA_NULL; |
| 10874 |
} |
| 10875 |
break; |
| 10876 |
case ALLOCATION_TYPE_DEDICATED: |
| 10877 |
VMA_ASSERT((m_DedicatedAllocation.m_pMappedData != VMA_NULL) == (m_MapCount != 0 || IsPersistentMap())); |
| 10878 |
return m_DedicatedAllocation.m_pMappedData; |
| 10879 |
default: |
| 10880 |
VMA_ASSERT(0); |
| 10881 |
return VMA_NULL; |
| 10882 |
} |
| 10883 |
} |
| 10884 |
|
| 10885 |
void VmaAllocation_T::BlockAllocMap() |
| 10886 |
{ |
| 10887 |
VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK); |
| 10888 |
VMA_ASSERT(IsMappingAllowed() && "Mapping is not allowed on this allocation! Please use one of the new VMA_ALLOCATION_CREATE_HOST_ACCESS_* flags when creating it."); |
| 10889 |
|
| 10890 |
if (m_MapCount < 0xFF) |
| 10891 |
{ |
| 10892 |
++m_MapCount; |
| 10893 |
} |
| 10894 |
else |
| 10895 |
{ |
| 10896 |
VMA_ASSERT(0 && "Allocation mapped too many times simultaneously."); |
| 10897 |
} |
| 10898 |
} |
| 10899 |
|
| 10900 |
void VmaAllocation_T::BlockAllocUnmap() |
| 10901 |
{ |
| 10902 |
VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK); |
| 10903 |
|
| 10904 |
if (m_MapCount > 0) |
| 10905 |
{ |
| 10906 |
--m_MapCount; |
| 10907 |
} |
| 10908 |
else |
| 10909 |
{ |
| 10910 |
VMA_ASSERT(0 && "Unmapping allocation not previously mapped."); |
| 10911 |
} |
| 10912 |
} |
| 10913 |
|
| 10914 |
VkResult VmaAllocation_T::DedicatedAllocMap(VmaAllocator hAllocator, void** ppData) |
| 10915 |
{ |
| 10916 |
VMA_ASSERT(GetType() == ALLOCATION_TYPE_DEDICATED); |
| 10917 |
VMA_ASSERT(IsMappingAllowed() && "Mapping is not allowed on this allocation! Please use one of the new VMA_ALLOCATION_CREATE_HOST_ACCESS_* flags when creating it."); |
| 10918 |
|
| 10919 |
if (m_MapCount != 0 || IsPersistentMap()) |
| 10920 |
{ |
| 10921 |
if (m_MapCount < 0xFF) |
| 10922 |
{ |
| 10923 |
VMA_ASSERT(m_DedicatedAllocation.m_pMappedData != VMA_NULL); |
| 10924 |
*ppData = m_DedicatedAllocation.m_pMappedData; |
| 10925 |
++m_MapCount; |
| 10926 |
return VK_SUCCESS; |
| 10927 |
} |
| 10928 |
else |
| 10929 |
{ |
| 10930 |
VMA_ASSERT(0 && "Dedicated allocation mapped too many times simultaneously."); |
| 10931 |
return VK_ERROR_MEMORY_MAP_FAILED; |
| 10932 |
} |
| 10933 |
} |
| 10934 |
else |
| 10935 |
{ |
| 10936 |
VkResult result = (*hAllocator->GetVulkanFunctions().vkMapMemory)( |
| 10937 |
hAllocator->m_hDevice, |
| 10938 |
m_DedicatedAllocation.m_hMemory, |
| 10939 |
0, |
| 10940 |
VK_WHOLE_SIZE, |
| 10941 |
0, |
| 10942 |
ppData); |
| 10943 |
if (result == VK_SUCCESS) |
| 10944 |
{ |
| 10945 |
m_DedicatedAllocation.m_pMappedData = *ppData; |
| 10946 |
m_MapCount = 1; |
| 10947 |
} |
| 10948 |
return result; |
| 10949 |
} |
| 10950 |
} |
| 10951 |
|
| 10952 |
void VmaAllocation_T::DedicatedAllocUnmap(VmaAllocator hAllocator) |
| 10953 |
{ |
| 10954 |
VMA_ASSERT(GetType() == ALLOCATION_TYPE_DEDICATED); |
| 10955 |
|
| 10956 |
if (m_MapCount > 0) |
| 10957 |
{ |
| 10958 |
--m_MapCount; |
| 10959 |
if (m_MapCount == 0 && !IsPersistentMap()) |
| 10960 |
{ |
| 10961 |
m_DedicatedAllocation.m_pMappedData = VMA_NULL; |
| 10962 |
(*hAllocator->GetVulkanFunctions().vkUnmapMemory)( |
| 10963 |
hAllocator->m_hDevice, |
| 10964 |
m_DedicatedAllocation.m_hMemory); |
| 10965 |
} |
| 10966 |
} |
| 10967 |
else |
| 10968 |
{ |
| 10969 |
VMA_ASSERT(0 && "Unmapping dedicated allocation not previously mapped."); |
| 10970 |
} |
| 10971 |
} |
| 10972 |
|
| 10973 |
#if VMA_STATS_STRING_ENABLED |
| 10974 |
void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const |
| 10975 |
{ |
| 10976 |
json.WriteString("Type"); |
| 10977 |
json.WriteString(VMA_SUBALLOCATION_TYPE_NAMES[m_SuballocationType]); |
| 10978 |
|
| 10979 |
json.WriteString("Size"); |
| 10980 |
json.WriteNumber(m_Size); |
| 10981 |
json.WriteString("Usage"); |
| 10982 |
json.WriteNumber(m_BufferImageUsage.Value); |
| 10983 |
|
| 10984 |
if (m_pUserData != VMA_NULL) |
| 10985 |
{ |
| 10986 |
json.WriteString("CustomData"); |
| 10987 |
json.BeginString(); |
| 10988 |
json.ContinueString_Pointer(m_pUserData); |
| 10989 |
json.EndString(); |
| 10990 |
} |
| 10991 |
if (m_pName != VMA_NULL) |
| 10992 |
{ |
| 10993 |
json.WriteString("Name"); |
| 10994 |
json.WriteString(m_pName); |
| 10995 |
} |
| 10996 |
} |
| 10997 |
#endif |
| 10998 |
|
| 10999 |
void VmaAllocation_T::FreeName(VmaAllocator hAllocator) |
| 11000 |
{ |
| 11001 |
if(m_pName) |
| 11002 |
{ |
| 11003 |
VmaFreeString(hAllocator->GetAllocationCallbacks(), m_pName); |
| 11004 |
m_pName = VMA_NULL; |
| 11005 |
} |
| 11006 |
} |
| 11007 |
#endif |
| 11008 |
|
| 11009 |
#ifndef _VMA_BLOCK_VECTOR_FUNCTIONS |
| 11010 |
VmaBlockVector::VmaBlockVector( |
| 11011 |
VmaAllocator hAllocator, |
| 11012 |
VmaPool hParentPool, |
| 11013 |
uint32_t memoryTypeIndex, |
| 11014 |
VkDeviceSize preferredBlockSize, |
| 11015 |
size_t minBlockCount, |
| 11016 |
size_t maxBlockCount, |
| 11017 |
VkDeviceSize bufferImageGranularity, |
| 11018 |
bool explicitBlockSize, |
| 11019 |
uint32_t algorithm, |
| 11020 |
float priority, |
| 11021 |
VkDeviceSize minAllocationAlignment, |
| 11022 |
void* pMemoryAllocateNext) |
| 11023 |
: m_hAllocator(hAllocator), |
| 11024 |
m_hParentPool(hParentPool), |
| 11025 |
m_MemoryTypeIndex(memoryTypeIndex), |
| 11026 |
m_PreferredBlockSize(preferredBlockSize), |
| 11027 |
m_MinBlockCount(minBlockCount), |
| 11028 |
m_MaxBlockCount(maxBlockCount), |
| 11029 |
m_BufferImageGranularity(bufferImageGranularity), |
| 11030 |
m_ExplicitBlockSize(explicitBlockSize), |
| 11031 |
m_Algorithm(algorithm), |
| 11032 |
m_Priority(priority), |
| 11033 |
m_MinAllocationAlignment(minAllocationAlignment), |
| 11034 |
m_pMemoryAllocateNext(pMemoryAllocateNext), |
| 11035 |
m_Blocks(VmaStlAllocator<VmaDeviceMemoryBlock*>(hAllocator->GetAllocationCallbacks())), |
| 11036 |
m_NextBlockId(0) {} |
| 11037 |
|
| 11038 |
VmaBlockVector::~VmaBlockVector() |
| 11039 |
{ |
| 11040 |
for (size_t i = m_Blocks.size(); i--; ) |
| 11041 |
{ |
| 11042 |
m_Blocks[i]->Destroy(m_hAllocator); |
| 11043 |
vma_delete(m_hAllocator, m_Blocks[i]); |
| 11044 |
} |
| 11045 |
} |
| 11046 |
|
| 11047 |
VkResult VmaBlockVector::CreateMinBlocks() |
| 11048 |
{ |
| 11049 |
for (size_t i = 0; i < m_MinBlockCount; ++i) |
| 11050 |
{ |
| 11051 |
VkResult res = CreateBlock(m_PreferredBlockSize, VMA_NULL); |
| 11052 |
if (res != VK_SUCCESS) |
| 11053 |
{ |
| 11054 |
return res; |
| 11055 |
} |
| 11056 |
} |
| 11057 |
return VK_SUCCESS; |
| 11058 |
} |
| 11059 |
|
| 11060 |
void VmaBlockVector::AddStatistics(VmaStatistics& inoutStats) |
| 11061 |
{ |
| 11062 |
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11063 |
|
| 11064 |
const size_t blockCount = m_Blocks.size(); |
| 11065 |
for (uint32_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) |
| 11066 |
{ |
| 11067 |
const VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex]; |
| 11068 |
VMA_ASSERT(pBlock); |
| 11069 |
VMA_HEAVY_ASSERT(pBlock->Validate()); |
| 11070 |
pBlock->m_pMetadata->AddStatistics(inoutStats); |
| 11071 |
} |
| 11072 |
} |
| 11073 |
|
| 11074 |
void VmaBlockVector::AddDetailedStatistics(VmaDetailedStatistics& inoutStats) |
| 11075 |
{ |
| 11076 |
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11077 |
|
| 11078 |
const size_t blockCount = m_Blocks.size(); |
| 11079 |
for (uint32_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) |
| 11080 |
{ |
| 11081 |
const VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex]; |
| 11082 |
VMA_ASSERT(pBlock); |
| 11083 |
VMA_HEAVY_ASSERT(pBlock->Validate()); |
| 11084 |
pBlock->m_pMetadata->AddDetailedStatistics(inoutStats); |
| 11085 |
} |
| 11086 |
} |
| 11087 |
|
| 11088 |
bool VmaBlockVector::IsEmpty() |
| 11089 |
{ |
| 11090 |
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11091 |
return m_Blocks.empty(); |
| 11092 |
} |
| 11093 |
|
| 11094 |
bool VmaBlockVector::IsCorruptionDetectionEnabled() const |
| 11095 |
{ |
| 11096 |
const uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; |
| 11097 |
return (VMA_DEBUG_DETECT_CORRUPTION != 0) && |
| 11098 |
(VMA_DEBUG_MARGIN > 0) && |
| 11099 |
(m_Algorithm == 0 || m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) && |
| 11100 |
(m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags; |
| 11101 |
} |
| 11102 |
|
| 11103 |
VkResult VmaBlockVector::Allocate( |
| 11104 |
VkDeviceSize size, |
| 11105 |
VkDeviceSize alignment, |
| 11106 |
const VmaAllocationCreateInfo& createInfo, |
| 11107 |
VmaSuballocationType suballocType, |
| 11108 |
size_t allocationCount, |
| 11109 |
VmaAllocation* pAllocations) |
| 11110 |
{ |
| 11111 |
size_t allocIndex; |
| 11112 |
VkResult res = VK_SUCCESS; |
| 11113 |
|
| 11114 |
alignment = VMA_MAX(alignment, m_MinAllocationAlignment); |
| 11115 |
|
| 11116 |
if (IsCorruptionDetectionEnabled()) |
| 11117 |
{ |
| 11118 |
size = VmaAlignUp<VkDeviceSize>(size, sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE)); |
| 11119 |
alignment = VmaAlignUp<VkDeviceSize>(alignment, sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE)); |
| 11120 |
} |
| 11121 |
|
| 11122 |
{ |
| 11123 |
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11124 |
for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex) |
| 11125 |
{ |
| 11126 |
res = AllocatePage( |
| 11127 |
size, |
| 11128 |
alignment, |
| 11129 |
createInfo, |
| 11130 |
suballocType, |
| 11131 |
pAllocations + allocIndex); |
| 11132 |
if (res != VK_SUCCESS) |
| 11133 |
{ |
| 11134 |
break; |
| 11135 |
} |
| 11136 |
} |
| 11137 |
} |
| 11138 |
|
| 11139 |
if (res != VK_SUCCESS) |
| 11140 |
{ |
| 11141 |
|
| 11142 |
while (allocIndex--) |
| 11143 |
Free(pAllocations[allocIndex]); |
| 11144 |
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount); |
| 11145 |
} |
| 11146 |
|
| 11147 |
return res; |
| 11148 |
} |
| 11149 |
|
| 11150 |
VkResult VmaBlockVector::AllocatePage( |
| 11151 |
VkDeviceSize size, |
| 11152 |
VkDeviceSize alignment, |
| 11153 |
const VmaAllocationCreateInfo& createInfo, |
| 11154 |
VmaSuballocationType suballocType, |
| 11155 |
VmaAllocation* pAllocation) |
| 11156 |
{ |
| 11157 |
const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0; |
| 11158 |
|
| 11159 |
VkDeviceSize freeMemory; |
| 11160 |
{ |
| 11161 |
const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex); |
| 11162 |
VmaBudget heapBudget = {}; |
| 11163 |
m_hAllocator->GetHeapBudgets(&heapBudget, heapIndex, 1); |
| 11164 |
freeMemory = (heapBudget.usage < heapBudget.budget) ? (heapBudget.budget - heapBudget.usage) : 0; |
| 11165 |
} |
| 11166 |
|
| 11167 |
const bool canFallbackToDedicated = !HasExplicitBlockSize() && |
| 11168 |
(createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0; |
| 11169 |
const bool canCreateNewBlock = |
| 11170 |
((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) && |
| 11171 |
(m_Blocks.size() < m_MaxBlockCount) && |
| 11172 |
(freeMemory >= size || !canFallbackToDedicated); |
| 11173 |
uint32_t strategy = createInfo.flags & VMA_ALLOCATION_CREATE_STRATEGY_MASK; |
| 11174 |
|
| 11175 |
|
| 11176 |
if (isUpperAddress && |
| 11177 |
(m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT || m_MaxBlockCount > 1)) |
| 11178 |
{ |
| 11179 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 11180 |
} |
| 11181 |
|
| 11182 |
|
| 11183 |
if (size + VMA_DEBUG_MARGIN > m_PreferredBlockSize) |
| 11184 |
{ |
| 11185 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11186 |
} |
| 11187 |
|
| 11188 |
|
| 11189 |
if (m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) |
| 11190 |
{ |
| 11191 |
|
| 11192 |
if (!m_Blocks.empty()) |
| 11193 |
{ |
| 11194 |
VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks.back(); |
| 11195 |
VMA_ASSERT(pCurrBlock); |
| 11196 |
VkResult res = AllocateFromBlock( |
| 11197 |
pCurrBlock, size, alignment, createInfo.flags, createInfo.pUserData, suballocType, strategy, pAllocation); |
| 11198 |
if (res == VK_SUCCESS) |
| 11199 |
{ |
| 11200 |
VMA_DEBUG_LOG_FORMAT(" Returned from last block #%" PRIu32, pCurrBlock->GetId()); |
| 11201 |
IncrementallySortBlocks(); |
| 11202 |
return VK_SUCCESS; |
| 11203 |
} |
| 11204 |
} |
| 11205 |
} |
| 11206 |
else |
| 11207 |
{ |
| 11208 |
if (strategy != VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT) |
| 11209 |
{ |
| 11210 |
const bool isHostVisible = |
| 11211 |
(m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0; |
| 11212 |
if(isHostVisible) |
| 11213 |
{ |
| 11214 |
const bool isMappingAllowed = (createInfo.flags & |
| 11215 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0; |
| 11216 |
|
| 11217 |
|
| 11218 |
|
| 11219 |
|
| 11220 |
|
| 11221 |
|
| 11222 |
for(size_t mappingI = 0; mappingI < 2; ++mappingI) |
| 11223 |
{ |
| 11224 |
|
| 11225 |
for (size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) |
| 11226 |
{ |
| 11227 |
VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex]; |
| 11228 |
VMA_ASSERT(pCurrBlock); |
| 11229 |
const bool isBlockMapped = pCurrBlock->GetMappedData() != VMA_NULL; |
| 11230 |
if((mappingI == 0) == (isMappingAllowed == isBlockMapped)) |
| 11231 |
{ |
| 11232 |
VkResult res = AllocateFromBlock( |
| 11233 |
pCurrBlock, size, alignment, createInfo.flags, createInfo.pUserData, suballocType, strategy, pAllocation); |
| 11234 |
if (res == VK_SUCCESS) |
| 11235 |
{ |
| 11236 |
VMA_DEBUG_LOG_FORMAT(" Returned from existing block #%" PRIu32, pCurrBlock->GetId()); |
| 11237 |
IncrementallySortBlocks(); |
| 11238 |
return VK_SUCCESS; |
| 11239 |
} |
| 11240 |
} |
| 11241 |
} |
| 11242 |
} |
| 11243 |
} |
| 11244 |
else |
| 11245 |
{ |
| 11246 |
|
| 11247 |
for (size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) |
| 11248 |
{ |
| 11249 |
VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex]; |
| 11250 |
VMA_ASSERT(pCurrBlock); |
| 11251 |
VkResult res = AllocateFromBlock( |
| 11252 |
pCurrBlock, size, alignment, createInfo.flags, createInfo.pUserData, suballocType, strategy, pAllocation); |
| 11253 |
if (res == VK_SUCCESS) |
| 11254 |
{ |
| 11255 |
VMA_DEBUG_LOG_FORMAT(" Returned from existing block #%" PRIu32, pCurrBlock->GetId()); |
| 11256 |
IncrementallySortBlocks(); |
| 11257 |
return VK_SUCCESS; |
| 11258 |
} |
| 11259 |
} |
| 11260 |
} |
| 11261 |
} |
| 11262 |
else |
| 11263 |
{ |
| 11264 |
|
| 11265 |
for (size_t blockIndex = m_Blocks.size(); blockIndex--; ) |
| 11266 |
{ |
| 11267 |
VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex]; |
| 11268 |
VMA_ASSERT(pCurrBlock); |
| 11269 |
VkResult res = AllocateFromBlock(pCurrBlock, size, alignment, createInfo.flags, createInfo.pUserData, suballocType, strategy, pAllocation); |
| 11270 |
if (res == VK_SUCCESS) |
| 11271 |
{ |
| 11272 |
VMA_DEBUG_LOG_FORMAT(" Returned from existing block #%" PRIu32, pCurrBlock->GetId()); |
| 11273 |
IncrementallySortBlocks(); |
| 11274 |
return VK_SUCCESS; |
| 11275 |
} |
| 11276 |
} |
| 11277 |
} |
| 11278 |
} |
| 11279 |
|
| 11280 |
|
| 11281 |
if (canCreateNewBlock) |
| 11282 |
{ |
| 11283 |
|
| 11284 |
VkDeviceSize newBlockSize = m_PreferredBlockSize; |
| 11285 |
uint32_t newBlockSizeShift = 0; |
| 11286 |
const uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3; |
| 11287 |
|
| 11288 |
if (!m_ExplicitBlockSize) |
| 11289 |
{ |
| 11290 |
|
| 11291 |
const VkDeviceSize maxExistingBlockSize = CalcMaxBlockSize(); |
| 11292 |
for (uint32_t i = 0; i < NEW_BLOCK_SIZE_SHIFT_MAX; ++i) |
| 11293 |
{ |
| 11294 |
const VkDeviceSize smallerNewBlockSize = newBlockSize / 2; |
| 11295 |
if (smallerNewBlockSize > maxExistingBlockSize && smallerNewBlockSize >= size * 2) |
| 11296 |
{ |
| 11297 |
newBlockSize = smallerNewBlockSize; |
| 11298 |
++newBlockSizeShift; |
| 11299 |
} |
| 11300 |
else |
| 11301 |
{ |
| 11302 |
break; |
| 11303 |
} |
| 11304 |
} |
| 11305 |
} |
| 11306 |
|
| 11307 |
size_t newBlockIndex = 0; |
| 11308 |
VkResult res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ? |
| 11309 |
CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11310 |
|
| 11311 |
if (!m_ExplicitBlockSize) |
| 11312 |
{ |
| 11313 |
while (res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX) |
| 11314 |
{ |
| 11315 |
const VkDeviceSize smallerNewBlockSize = newBlockSize / 2; |
| 11316 |
if (smallerNewBlockSize >= size) |
| 11317 |
{ |
| 11318 |
newBlockSize = smallerNewBlockSize; |
| 11319 |
++newBlockSizeShift; |
| 11320 |
res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ? |
| 11321 |
CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11322 |
} |
| 11323 |
else |
| 11324 |
{ |
| 11325 |
break; |
| 11326 |
} |
| 11327 |
} |
| 11328 |
} |
| 11329 |
|
| 11330 |
if (res == VK_SUCCESS) |
| 11331 |
{ |
| 11332 |
VmaDeviceMemoryBlock* const pBlock = m_Blocks[newBlockIndex]; |
| 11333 |
VMA_ASSERT(pBlock->m_pMetadata->GetSize() >= size); |
| 11334 |
|
| 11335 |
res = AllocateFromBlock( |
| 11336 |
pBlock, size, alignment, createInfo.flags, createInfo.pUserData, suballocType, strategy, pAllocation); |
| 11337 |
if (res == VK_SUCCESS) |
| 11338 |
{ |
| 11339 |
VMA_DEBUG_LOG_FORMAT(" Created new block #%" PRIu32 " Size=%" PRIu64, pBlock->GetId(), newBlockSize); |
| 11340 |
IncrementallySortBlocks(); |
| 11341 |
return VK_SUCCESS; |
| 11342 |
} |
| 11343 |
else |
| 11344 |
{ |
| 11345 |
|
| 11346 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11347 |
} |
| 11348 |
} |
| 11349 |
} |
| 11350 |
|
| 11351 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11352 |
} |
| 11353 |
|
| 11354 |
void VmaBlockVector::Free(const VmaAllocation hAllocation) |
| 11355 |
{ |
| 11356 |
VmaDeviceMemoryBlock* pBlockToDelete = VMA_NULL; |
| 11357 |
|
| 11358 |
bool budgetExceeded = false; |
| 11359 |
{ |
| 11360 |
const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex); |
| 11361 |
VmaBudget heapBudget = {}; |
| 11362 |
m_hAllocator->GetHeapBudgets(&heapBudget, heapIndex, 1); |
| 11363 |
budgetExceeded = heapBudget.usage >= heapBudget.budget; |
| 11364 |
} |
| 11365 |
|
| 11366 |
|
| 11367 |
{ |
| 11368 |
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11369 |
|
| 11370 |
VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock(); |
| 11371 |
|
| 11372 |
if (IsCorruptionDetectionEnabled()) |
| 11373 |
{ |
| 11374 |
VkResult res = pBlock->ValidateMagicValueAfterAllocation(m_hAllocator, hAllocation->GetOffset(), hAllocation->GetSize()); |
| 11375 |
VMA_ASSERT(res == VK_SUCCESS && "Couldn't map block memory to validate magic value."); |
| 11376 |
} |
| 11377 |
|
| 11378 |
if (hAllocation->IsPersistentMap()) |
| 11379 |
{ |
| 11380 |
pBlock->Unmap(m_hAllocator, 1); |
| 11381 |
} |
| 11382 |
|
| 11383 |
const bool hadEmptyBlockBeforeFree = HasEmptyBlock(); |
| 11384 |
pBlock->m_pMetadata->Free(hAllocation->GetAllocHandle()); |
| 11385 |
pBlock->PostFree(m_hAllocator); |
| 11386 |
VMA_HEAVY_ASSERT(pBlock->Validate()); |
| 11387 |
|
| 11388 |
VMA_DEBUG_LOG_FORMAT(" Freed from MemoryTypeIndex=%" PRIu32, m_MemoryTypeIndex); |
| 11389 |
|
| 11390 |
const bool canDeleteBlock = m_Blocks.size() > m_MinBlockCount; |
| 11391 |
|
| 11392 |
if (pBlock->m_pMetadata->IsEmpty()) |
| 11393 |
{ |
| 11394 |
|
| 11395 |
if ((hadEmptyBlockBeforeFree || budgetExceeded) && canDeleteBlock) |
| 11396 |
{ |
| 11397 |
pBlockToDelete = pBlock; |
| 11398 |
Remove(pBlock); |
| 11399 |
} |
| 11400 |
|
| 11401 |
} |
| 11402 |
|
| 11403 |
|
| 11404 |
else if (hadEmptyBlockBeforeFree && canDeleteBlock) |
| 11405 |
{ |
| 11406 |
VmaDeviceMemoryBlock* pLastBlock = m_Blocks.back(); |
| 11407 |
if (pLastBlock->m_pMetadata->IsEmpty()) |
| 11408 |
{ |
| 11409 |
pBlockToDelete = pLastBlock; |
| 11410 |
m_Blocks.pop_back(); |
| 11411 |
} |
| 11412 |
} |
| 11413 |
|
| 11414 |
IncrementallySortBlocks(); |
| 11415 |
} |
| 11416 |
|
| 11417 |
|
| 11418 |
|
| 11419 |
if (pBlockToDelete != VMA_NULL) |
| 11420 |
{ |
| 11421 |
VMA_DEBUG_LOG_FORMAT(" Deleted empty block #%" PRIu32, pBlockToDelete->GetId()); |
| 11422 |
pBlockToDelete->Destroy(m_hAllocator); |
| 11423 |
vma_delete(m_hAllocator, pBlockToDelete); |
| 11424 |
} |
| 11425 |
|
| 11426 |
m_hAllocator->m_Budget.RemoveAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), hAllocation->GetSize()); |
| 11427 |
m_hAllocator->m_AllocationObjectAllocator.Free(hAllocation); |
| 11428 |
} |
| 11429 |
|
| 11430 |
VkDeviceSize VmaBlockVector::CalcMaxBlockSize() const |
| 11431 |
{ |
| 11432 |
VkDeviceSize result = 0; |
| 11433 |
for (size_t i = m_Blocks.size(); i--; ) |
| 11434 |
{ |
| 11435 |
result = VMA_MAX(result, m_Blocks[i]->m_pMetadata->GetSize()); |
| 11436 |
if (result >= m_PreferredBlockSize) |
| 11437 |
{ |
| 11438 |
break; |
| 11439 |
} |
| 11440 |
} |
| 11441 |
return result; |
| 11442 |
} |
| 11443 |
|
| 11444 |
void VmaBlockVector::Remove(VmaDeviceMemoryBlock* pBlock) |
| 11445 |
{ |
| 11446 |
for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) |
| 11447 |
{ |
| 11448 |
if (m_Blocks[blockIndex] == pBlock) |
| 11449 |
{ |
| 11450 |
VmaVectorRemove(m_Blocks, blockIndex); |
| 11451 |
return; |
| 11452 |
} |
| 11453 |
} |
| 11454 |
VMA_ASSERT(0); |
| 11455 |
} |
| 11456 |
|
| 11457 |
void VmaBlockVector::IncrementallySortBlocks() |
| 11458 |
{ |
| 11459 |
if (!m_IncrementalSort) |
| 11460 |
return; |
| 11461 |
if (m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) |
| 11462 |
{ |
| 11463 |
|
| 11464 |
for (size_t i = 1; i < m_Blocks.size(); ++i) |
| 11465 |
{ |
| 11466 |
if (m_Blocks[i - 1]->m_pMetadata->GetSumFreeSize() > m_Blocks[i]->m_pMetadata->GetSumFreeSize()) |
| 11467 |
{ |
| 11468 |
std::swap(m_Blocks[i - 1], m_Blocks[i]); |
| 11469 |
return; |
| 11470 |
} |
| 11471 |
} |
| 11472 |
} |
| 11473 |
} |
| 11474 |
|
| 11475 |
void VmaBlockVector::SortByFreeSize() |
| 11476 |
{ |
| 11477 |
VMA_SORT(m_Blocks.begin(), m_Blocks.end(), |
| 11478 |
[](VmaDeviceMemoryBlock* b1, VmaDeviceMemoryBlock* b2) -> bool |
| 11479 |
{ |
| 11480 |
return b1->m_pMetadata->GetSumFreeSize() < b2->m_pMetadata->GetSumFreeSize(); |
| 11481 |
}); |
| 11482 |
} |
| 11483 |
|
| 11484 |
VkResult VmaBlockVector::AllocateFromBlock( |
| 11485 |
VmaDeviceMemoryBlock* pBlock, |
| 11486 |
VkDeviceSize size, |
| 11487 |
VkDeviceSize alignment, |
| 11488 |
VmaAllocationCreateFlags allocFlags, |
| 11489 |
void* pUserData, |
| 11490 |
VmaSuballocationType suballocType, |
| 11491 |
uint32_t strategy, |
| 11492 |
VmaAllocation* pAllocation) |
| 11493 |
{ |
| 11494 |
const bool isUpperAddress = (allocFlags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0; |
| 11495 |
|
| 11496 |
VmaAllocationRequest currRequest = {}; |
| 11497 |
if (pBlock->m_pMetadata->CreateAllocationRequest( |
| 11498 |
size, |
| 11499 |
alignment, |
| 11500 |
isUpperAddress, |
| 11501 |
suballocType, |
| 11502 |
strategy, |
| 11503 |
&currRequest)) |
| 11504 |
{ |
| 11505 |
return CommitAllocationRequest(currRequest, pBlock, alignment, allocFlags, pUserData, suballocType, pAllocation); |
| 11506 |
} |
| 11507 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 11508 |
} |
| 11509 |
|
| 11510 |
VkResult VmaBlockVector::CommitAllocationRequest( |
| 11511 |
VmaAllocationRequest& allocRequest, |
| 11512 |
VmaDeviceMemoryBlock* pBlock, |
| 11513 |
VkDeviceSize alignment, |
| 11514 |
VmaAllocationCreateFlags allocFlags, |
| 11515 |
void* pUserData, |
| 11516 |
VmaSuballocationType suballocType, |
| 11517 |
VmaAllocation* pAllocation) |
| 11518 |
{ |
| 11519 |
const bool mapped = (allocFlags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0; |
| 11520 |
const bool isUserDataString = (allocFlags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0; |
| 11521 |
const bool isMappingAllowed = (allocFlags & |
| 11522 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0; |
| 11523 |
|
| 11524 |
pBlock->PostAlloc(m_hAllocator); |
| 11525 |
|
| 11526 |
if (mapped) |
| 11527 |
{ |
| 11528 |
VkResult res = pBlock->Map(m_hAllocator, 1, VMA_NULL); |
| 11529 |
if (res != VK_SUCCESS) |
| 11530 |
{ |
| 11531 |
return res; |
| 11532 |
} |
| 11533 |
} |
| 11534 |
|
| 11535 |
*pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate(isMappingAllowed); |
| 11536 |
pBlock->m_pMetadata->Alloc(allocRequest, suballocType, *pAllocation); |
| 11537 |
(*pAllocation)->InitBlockAllocation( |
| 11538 |
pBlock, |
| 11539 |
allocRequest.allocHandle, |
| 11540 |
alignment, |
| 11541 |
allocRequest.size, |
| 11542 |
m_MemoryTypeIndex, |
| 11543 |
suballocType, |
| 11544 |
mapped); |
| 11545 |
VMA_HEAVY_ASSERT(pBlock->Validate()); |
| 11546 |
if (isUserDataString) |
| 11547 |
(*pAllocation)->SetName(m_hAllocator, (const char*)pUserData); |
| 11548 |
else |
| 11549 |
(*pAllocation)->SetUserData(m_hAllocator, pUserData); |
| 11550 |
m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), allocRequest.size); |
| 11551 |
if (VMA_DEBUG_INITIALIZE_ALLOCATIONS) |
| 11552 |
{ |
| 11553 |
m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED); |
| 11554 |
} |
| 11555 |
if (IsCorruptionDetectionEnabled()) |
| 11556 |
{ |
| 11557 |
VkResult res = pBlock->WriteMagicValueAfterAllocation(m_hAllocator, (*pAllocation)->GetOffset(), allocRequest.size); |
| 11558 |
VMA_ASSERT(res == VK_SUCCESS && "Couldn't map block memory to write magic value."); |
| 11559 |
} |
| 11560 |
return VK_SUCCESS; |
| 11561 |
} |
| 11562 |
|
| 11563 |
VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize, size_t* pNewBlockIndex) |
| 11564 |
{ |
| 11565 |
VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO }; |
| 11566 |
allocInfo.pNext = m_pMemoryAllocateNext; |
| 11567 |
allocInfo.memoryTypeIndex = m_MemoryTypeIndex; |
| 11568 |
allocInfo.allocationSize = blockSize; |
| 11569 |
|
| 11570 |
#if VMA_BUFFER_DEVICE_ADDRESS |
| 11571 |
|
| 11572 |
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR }; |
| 11573 |
if (m_hAllocator->m_UseKhrBufferDeviceAddress) |
| 11574 |
{ |
| 11575 |
allocFlagsInfo.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR; |
| 11576 |
VmaPnextChainPushFront(&allocInfo, &allocFlagsInfo); |
| 11577 |
} |
| 11578 |
#endif |
| 11579 |
|
| 11580 |
#if VMA_MEMORY_PRIORITY |
| 11581 |
VkMemoryPriorityAllocateInfoEXT priorityInfo = { VK_STRUCTURE_TYPE_MEMORY_PRIORITY_ALLOCATE_INFO_EXT }; |
| 11582 |
if (m_hAllocator->m_UseExtMemoryPriority) |
| 11583 |
{ |
| 11584 |
VMA_ASSERT(m_Priority >= 0.f && m_Priority <= 1.f); |
| 11585 |
priorityInfo.priority = m_Priority; |
| 11586 |
VmaPnextChainPushFront(&allocInfo, &priorityInfo); |
| 11587 |
} |
| 11588 |
#endif |
| 11589 |
|
| 11590 |
#if VMA_EXTERNAL_MEMORY |
| 11591 |
|
| 11592 |
VkExportMemoryAllocateInfoKHR exportMemoryAllocInfo = { VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR }; |
| 11593 |
exportMemoryAllocInfo.handleTypes = m_hAllocator->GetExternalMemoryHandleTypeFlags(m_MemoryTypeIndex); |
| 11594 |
if (exportMemoryAllocInfo.handleTypes != 0) |
| 11595 |
{ |
| 11596 |
VmaPnextChainPushFront(&allocInfo, &exportMemoryAllocInfo); |
| 11597 |
} |
| 11598 |
#endif |
| 11599 |
|
| 11600 |
VkDeviceMemory mem = VK_NULL_HANDLE; |
| 11601 |
VkResult res = m_hAllocator->AllocateVulkanMemory(&allocInfo, &mem); |
| 11602 |
if (res < 0) |
| 11603 |
{ |
| 11604 |
return res; |
| 11605 |
} |
| 11606 |
|
| 11607 |
|
| 11608 |
|
| 11609 |
|
| 11610 |
VmaDeviceMemoryBlock* const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator); |
| 11611 |
pBlock->Init( |
| 11612 |
m_hAllocator, |
| 11613 |
m_hParentPool, |
| 11614 |
m_MemoryTypeIndex, |
| 11615 |
mem, |
| 11616 |
allocInfo.allocationSize, |
| 11617 |
m_NextBlockId++, |
| 11618 |
m_Algorithm, |
| 11619 |
m_BufferImageGranularity); |
| 11620 |
|
| 11621 |
m_Blocks.push_back(pBlock); |
| 11622 |
if (pNewBlockIndex != VMA_NULL) |
| 11623 |
{ |
| 11624 |
*pNewBlockIndex = m_Blocks.size() - 1; |
| 11625 |
} |
| 11626 |
|
| 11627 |
return VK_SUCCESS; |
| 11628 |
} |
| 11629 |
|
| 11630 |
bool VmaBlockVector::HasEmptyBlock() |
| 11631 |
{ |
| 11632 |
for (size_t index = 0, count = m_Blocks.size(); index < count; ++index) |
| 11633 |
{ |
| 11634 |
VmaDeviceMemoryBlock* const pBlock = m_Blocks[index]; |
| 11635 |
if (pBlock->m_pMetadata->IsEmpty()) |
| 11636 |
{ |
| 11637 |
return true; |
| 11638 |
} |
| 11639 |
} |
| 11640 |
return false; |
| 11641 |
} |
| 11642 |
|
| 11643 |
#if VMA_STATS_STRING_ENABLED |
| 11644 |
void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter& json) |
| 11645 |
{ |
| 11646 |
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11647 |
|
| 11648 |
|
| 11649 |
json.BeginObject(); |
| 11650 |
for (size_t i = 0; i < m_Blocks.size(); ++i) |
| 11651 |
{ |
| 11652 |
json.BeginString(); |
| 11653 |
json.ContinueString(m_Blocks[i]->GetId()); |
| 11654 |
json.EndString(); |
| 11655 |
|
| 11656 |
json.BeginObject(); |
| 11657 |
json.WriteString("MapRefCount"); |
| 11658 |
json.WriteNumber(m_Blocks[i]->GetMapRefCount()); |
| 11659 |
|
| 11660 |
m_Blocks[i]->m_pMetadata->PrintDetailedMap(json); |
| 11661 |
json.EndObject(); |
| 11662 |
} |
| 11663 |
json.EndObject(); |
| 11664 |
} |
| 11665 |
#endif |
| 11666 |
|
| 11667 |
VkResult VmaBlockVector::CheckCorruption() |
| 11668 |
{ |
| 11669 |
if (!IsCorruptionDetectionEnabled()) |
| 11670 |
{ |
| 11671 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 11672 |
} |
| 11673 |
|
| 11674 |
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex); |
| 11675 |
for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) |
| 11676 |
{ |
| 11677 |
VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex]; |
| 11678 |
VMA_ASSERT(pBlock); |
| 11679 |
VkResult res = pBlock->CheckCorruption(m_hAllocator); |
| 11680 |
if (res != VK_SUCCESS) |
| 11681 |
{ |
| 11682 |
return res; |
| 11683 |
} |
| 11684 |
} |
| 11685 |
return VK_SUCCESS; |
| 11686 |
} |
| 11687 |
|
| 11688 |
#endif |
| 11689 |
|
| 11690 |
#ifndef _VMA_DEFRAGMENTATION_CONTEXT_FUNCTIONS |
| 11691 |
VmaDefragmentationContext_T::VmaDefragmentationContext_T( |
| 11692 |
VmaAllocator hAllocator, |
| 11693 |
const VmaDefragmentationInfo& info) |
| 11694 |
: m_MaxPassBytes(info.maxBytesPerPass == 0 ? VK_WHOLE_SIZE : info.maxBytesPerPass), |
| 11695 |
m_MaxPassAllocations(info.maxAllocationsPerPass == 0 ? UINT32_MAX : info.maxAllocationsPerPass), |
| 11696 |
m_BreakCallback(info.pfnBreakCallback), |
| 11697 |
m_BreakCallbackUserData(info.pBreakCallbackUserData), |
| 11698 |
m_MoveAllocator(hAllocator->GetAllocationCallbacks()), |
| 11699 |
m_Moves(m_MoveAllocator) |
| 11700 |
{ |
| 11701 |
m_Algorithm = info.flags & VMA_DEFRAGMENTATION_FLAG_ALGORITHM_MASK; |
| 11702 |
|
| 11703 |
if (info.pool != VMA_NULL) |
| 11704 |
{ |
| 11705 |
m_BlockVectorCount = 1; |
| 11706 |
m_PoolBlockVector = &info.pool->m_BlockVector; |
| 11707 |
m_pBlockVectors = &m_PoolBlockVector; |
| 11708 |
m_PoolBlockVector->SetIncrementalSort(false); |
| 11709 |
m_PoolBlockVector->SortByFreeSize(); |
| 11710 |
} |
| 11711 |
else |
| 11712 |
{ |
| 11713 |
m_BlockVectorCount = hAllocator->GetMemoryTypeCount(); |
| 11714 |
m_PoolBlockVector = VMA_NULL; |
| 11715 |
m_pBlockVectors = hAllocator->m_pBlockVectors; |
| 11716 |
for (uint32_t i = 0; i < m_BlockVectorCount; ++i) |
| 11717 |
{ |
| 11718 |
VmaBlockVector* vector = m_pBlockVectors[i]; |
| 11719 |
if (vector != VMA_NULL) |
| 11720 |
{ |
| 11721 |
vector->SetIncrementalSort(false); |
| 11722 |
vector->SortByFreeSize(); |
| 11723 |
} |
| 11724 |
} |
| 11725 |
} |
| 11726 |
|
| 11727 |
switch (m_Algorithm) |
| 11728 |
{ |
| 11729 |
case 0: |
| 11730 |
m_Algorithm = VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT; |
| 11731 |
m_AlgorithmState = vma_new_array(hAllocator, StateBalanced, m_BlockVectorCount); |
| 11732 |
break; |
| 11733 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT: |
| 11734 |
m_AlgorithmState = vma_new_array(hAllocator, StateBalanced, m_BlockVectorCount); |
| 11735 |
break; |
| 11736 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT: |
| 11737 |
if (hAllocator->GetBufferImageGranularity() > 1) |
| 11738 |
{ |
| 11739 |
m_AlgorithmState = vma_new_array(hAllocator, StateExtensive, m_BlockVectorCount); |
| 11740 |
} |
| 11741 |
break; |
| 11742 |
} |
| 11743 |
} |
| 11744 |
|
| 11745 |
VmaDefragmentationContext_T::~VmaDefragmentationContext_T() |
| 11746 |
{ |
| 11747 |
if (m_PoolBlockVector != VMA_NULL) |
| 11748 |
{ |
| 11749 |
m_PoolBlockVector->SetIncrementalSort(true); |
| 11750 |
} |
| 11751 |
else |
| 11752 |
{ |
| 11753 |
for (uint32_t i = 0; i < m_BlockVectorCount; ++i) |
| 11754 |
{ |
| 11755 |
VmaBlockVector* vector = m_pBlockVectors[i]; |
| 11756 |
if (vector != VMA_NULL) |
| 11757 |
vector->SetIncrementalSort(true); |
| 11758 |
} |
| 11759 |
} |
| 11760 |
|
| 11761 |
if (m_AlgorithmState) |
| 11762 |
{ |
| 11763 |
switch (m_Algorithm) |
| 11764 |
{ |
| 11765 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT: |
| 11766 |
vma_delete_array(m_MoveAllocator.m_pCallbacks, reinterpret_cast<StateBalanced*>(m_AlgorithmState), m_BlockVectorCount); |
| 11767 |
break; |
| 11768 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT: |
| 11769 |
vma_delete_array(m_MoveAllocator.m_pCallbacks, reinterpret_cast<StateExtensive*>(m_AlgorithmState), m_BlockVectorCount); |
| 11770 |
break; |
| 11771 |
default: |
| 11772 |
VMA_ASSERT(0); |
| 11773 |
} |
| 11774 |
} |
| 11775 |
} |
| 11776 |
|
| 11777 |
VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPassMoveInfo& moveInfo) |
| 11778 |
{ |
| 11779 |
if (m_PoolBlockVector != VMA_NULL) |
| 11780 |
{ |
| 11781 |
VmaMutexLockWrite lock(m_PoolBlockVector->GetMutex(), m_PoolBlockVector->GetAllocator()->m_UseMutex); |
| 11782 |
|
| 11783 |
if (m_PoolBlockVector->GetBlockCount() > 1) |
| 11784 |
ComputeDefragmentation(*m_PoolBlockVector, 0); |
| 11785 |
else if (m_PoolBlockVector->GetBlockCount() == 1) |
| 11786 |
ReallocWithinBlock(*m_PoolBlockVector, m_PoolBlockVector->GetBlock(0)); |
| 11787 |
} |
| 11788 |
else |
| 11789 |
{ |
| 11790 |
for (uint32_t i = 0; i < m_BlockVectorCount; ++i) |
| 11791 |
{ |
| 11792 |
if (m_pBlockVectors[i] != VMA_NULL) |
| 11793 |
{ |
| 11794 |
VmaMutexLockWrite lock(m_pBlockVectors[i]->GetMutex(), m_pBlockVectors[i]->GetAllocator()->m_UseMutex); |
| 11795 |
|
| 11796 |
if (m_pBlockVectors[i]->GetBlockCount() > 1) |
| 11797 |
{ |
| 11798 |
if (ComputeDefragmentation(*m_pBlockVectors[i], i)) |
| 11799 |
break; |
| 11800 |
} |
| 11801 |
else if (m_pBlockVectors[i]->GetBlockCount() == 1) |
| 11802 |
{ |
| 11803 |
if (ReallocWithinBlock(*m_pBlockVectors[i], m_pBlockVectors[i]->GetBlock(0))) |
| 11804 |
break; |
| 11805 |
} |
| 11806 |
} |
| 11807 |
} |
| 11808 |
} |
| 11809 |
|
| 11810 |
moveInfo.moveCount = static_cast<uint32_t>(m_Moves.size()); |
| 11811 |
if (moveInfo.moveCount > 0) |
| 11812 |
{ |
| 11813 |
moveInfo.pMoves = m_Moves.data(); |
| 11814 |
return VK_INCOMPLETE; |
| 11815 |
} |
| 11816 |
|
| 11817 |
moveInfo.pMoves = VMA_NULL; |
| 11818 |
return VK_SUCCESS; |
| 11819 |
} |
| 11820 |
|
| 11821 |
VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMoveInfo& moveInfo) |
| 11822 |
{ |
| 11823 |
VMA_ASSERT(moveInfo.moveCount > 0 ? moveInfo.pMoves != VMA_NULL : true); |
| 11824 |
|
| 11825 |
VkResult result = VK_SUCCESS; |
| 11826 |
VmaStlAllocator<FragmentedBlock> blockAllocator(m_MoveAllocator.m_pCallbacks); |
| 11827 |
VmaVector<FragmentedBlock, VmaStlAllocator<FragmentedBlock>> immovableBlocks(blockAllocator); |
| 11828 |
VmaVector<FragmentedBlock, VmaStlAllocator<FragmentedBlock>> mappedBlocks(blockAllocator); |
| 11829 |
|
| 11830 |
VmaAllocator allocator = VMA_NULL; |
| 11831 |
for (uint32_t i = 0; i < moveInfo.moveCount; ++i) |
| 11832 |
{ |
| 11833 |
VmaDefragmentationMove& move = moveInfo.pMoves[i]; |
| 11834 |
size_t prevCount = 0, currentCount = 0; |
| 11835 |
VkDeviceSize freedBlockSize = 0; |
| 11836 |
|
| 11837 |
uint32_t vectorIndex; |
| 11838 |
VmaBlockVector* vector; |
| 11839 |
if (m_PoolBlockVector != VMA_NULL) |
| 11840 |
{ |
| 11841 |
vectorIndex = 0; |
| 11842 |
vector = m_PoolBlockVector; |
| 11843 |
} |
| 11844 |
else |
| 11845 |
{ |
| 11846 |
vectorIndex = move.srcAllocation->GetMemoryTypeIndex(); |
| 11847 |
vector = m_pBlockVectors[vectorIndex]; |
| 11848 |
VMA_ASSERT(vector != VMA_NULL); |
| 11849 |
} |
| 11850 |
|
| 11851 |
switch (move.operation) |
| 11852 |
{ |
| 11853 |
case VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY: |
| 11854 |
{ |
| 11855 |
uint8_t mapCount = move.srcAllocation->SwapBlockAllocation(vector->m_hAllocator, move.dstTmpAllocation); |
| 11856 |
if (mapCount > 0) |
| 11857 |
{ |
| 11858 |
allocator = vector->m_hAllocator; |
| 11859 |
VmaDeviceMemoryBlock* newMapBlock = move.srcAllocation->GetBlock(); |
| 11860 |
bool notPresent = true; |
| 11861 |
for (FragmentedBlock& block : mappedBlocks) |
| 11862 |
{ |
| 11863 |
if (block.block == newMapBlock) |
| 11864 |
{ |
| 11865 |
notPresent = false; |
| 11866 |
block.data += mapCount; |
| 11867 |
break; |
| 11868 |
} |
| 11869 |
} |
| 11870 |
if (notPresent) |
| 11871 |
mappedBlocks.push_back({ mapCount, newMapBlock }); |
| 11872 |
} |
| 11873 |
|
| 11874 |
|
| 11875 |
{ |
| 11876 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11877 |
prevCount = vector->GetBlockCount(); |
| 11878 |
freedBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize(); |
| 11879 |
} |
| 11880 |
vector->Free(move.dstTmpAllocation); |
| 11881 |
{ |
| 11882 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11883 |
currentCount = vector->GetBlockCount(); |
| 11884 |
} |
| 11885 |
|
| 11886 |
result = VK_INCOMPLETE; |
| 11887 |
break; |
| 11888 |
} |
| 11889 |
case VMA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE: |
| 11890 |
{ |
| 11891 |
m_PassStats.bytesMoved -= move.srcAllocation->GetSize(); |
| 11892 |
--m_PassStats.allocationsMoved; |
| 11893 |
vector->Free(move.dstTmpAllocation); |
| 11894 |
|
| 11895 |
VmaDeviceMemoryBlock* newBlock = move.srcAllocation->GetBlock(); |
| 11896 |
bool notPresent = true; |
| 11897 |
for (const FragmentedBlock& block : immovableBlocks) |
| 11898 |
{ |
| 11899 |
if (block.block == newBlock) |
| 11900 |
{ |
| 11901 |
notPresent = false; |
| 11902 |
break; |
| 11903 |
} |
| 11904 |
} |
| 11905 |
if (notPresent) |
| 11906 |
immovableBlocks.push_back({ vectorIndex, newBlock }); |
| 11907 |
break; |
| 11908 |
} |
| 11909 |
case VMA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY: |
| 11910 |
{ |
| 11911 |
m_PassStats.bytesMoved -= move.srcAllocation->GetSize(); |
| 11912 |
--m_PassStats.allocationsMoved; |
| 11913 |
|
| 11914 |
{ |
| 11915 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11916 |
prevCount = vector->GetBlockCount(); |
| 11917 |
freedBlockSize = move.srcAllocation->GetBlock()->m_pMetadata->GetSize(); |
| 11918 |
} |
| 11919 |
vector->Free(move.srcAllocation); |
| 11920 |
{ |
| 11921 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11922 |
currentCount = vector->GetBlockCount(); |
| 11923 |
} |
| 11924 |
freedBlockSize *= prevCount - currentCount; |
| 11925 |
|
| 11926 |
VkDeviceSize dstBlockSize; |
| 11927 |
{ |
| 11928 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11929 |
dstBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize(); |
| 11930 |
} |
| 11931 |
vector->Free(move.dstTmpAllocation); |
| 11932 |
{ |
| 11933 |
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 11934 |
freedBlockSize += dstBlockSize * (currentCount - vector->GetBlockCount()); |
| 11935 |
currentCount = vector->GetBlockCount(); |
| 11936 |
} |
| 11937 |
|
| 11938 |
result = VK_INCOMPLETE; |
| 11939 |
break; |
| 11940 |
} |
| 11941 |
default: |
| 11942 |
VMA_ASSERT(0); |
| 11943 |
} |
| 11944 |
|
| 11945 |
if (prevCount > currentCount) |
| 11946 |
{ |
| 11947 |
size_t freedBlocks = prevCount - currentCount; |
| 11948 |
m_PassStats.deviceMemoryBlocksFreed += static_cast<uint32_t>(freedBlocks); |
| 11949 |
m_PassStats.bytesFreed += freedBlockSize; |
| 11950 |
} |
| 11951 |
|
| 11952 |
if(m_Algorithm == VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT && |
| 11953 |
m_AlgorithmState != VMA_NULL) |
| 11954 |
{ |
| 11955 |
|
| 11956 |
StateExtensive& state = reinterpret_cast<StateExtensive*>(m_AlgorithmState)[vectorIndex]; |
| 11957 |
if (state.firstFreeBlock != SIZE_MAX) |
| 11958 |
{ |
| 11959 |
const size_t diff = prevCount - currentCount; |
| 11960 |
if (state.firstFreeBlock >= diff) |
| 11961 |
{ |
| 11962 |
state.firstFreeBlock -= diff; |
| 11963 |
if (state.firstFreeBlock != 0) |
| 11964 |
state.firstFreeBlock -= vector->GetBlock(state.firstFreeBlock - 1)->m_pMetadata->IsEmpty(); |
| 11965 |
} |
| 11966 |
else |
| 11967 |
state.firstFreeBlock = 0; |
| 11968 |
} |
| 11969 |
} |
| 11970 |
} |
| 11971 |
moveInfo.moveCount = 0; |
| 11972 |
moveInfo.pMoves = VMA_NULL; |
| 11973 |
m_Moves.clear(); |
| 11974 |
|
| 11975 |
|
| 11976 |
m_GlobalStats.allocationsMoved += m_PassStats.allocationsMoved; |
| 11977 |
m_GlobalStats.bytesFreed += m_PassStats.bytesFreed; |
| 11978 |
m_GlobalStats.bytesMoved += m_PassStats.bytesMoved; |
| 11979 |
m_GlobalStats.deviceMemoryBlocksFreed += m_PassStats.deviceMemoryBlocksFreed; |
| 11980 |
m_PassStats = { 0 }; |
| 11981 |
|
| 11982 |
|
| 11983 |
if (immovableBlocks.size() > 0) |
| 11984 |
{ |
| 11985 |
do |
| 11986 |
{ |
| 11987 |
if(m_Algorithm == VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT) |
| 11988 |
{ |
| 11989 |
if (m_AlgorithmState != VMA_NULL) |
| 11990 |
{ |
| 11991 |
bool swapped = false; |
| 11992 |
|
| 11993 |
for (const FragmentedBlock& block : immovableBlocks) |
| 11994 |
{ |
| 11995 |
StateExtensive& state = reinterpret_cast<StateExtensive*>(m_AlgorithmState)[block.data]; |
| 11996 |
if (state.operation != StateExtensive::Operation::Cleanup) |
| 11997 |
{ |
| 11998 |
VmaBlockVector* vector = m_pBlockVectors[block.data]; |
| 11999 |
VmaMutexLockWrite lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 12000 |
|
| 12001 |
for (size_t i = 0, count = vector->GetBlockCount() - m_ImmovableBlockCount; i < count; ++i) |
| 12002 |
{ |
| 12003 |
if (vector->GetBlock(i) == block.block) |
| 12004 |
{ |
| 12005 |
std::swap(vector->m_Blocks[i], vector->m_Blocks[vector->GetBlockCount() - ++m_ImmovableBlockCount]); |
| 12006 |
if (state.firstFreeBlock != SIZE_MAX) |
| 12007 |
{ |
| 12008 |
if (i + 1 < state.firstFreeBlock) |
| 12009 |
{ |
| 12010 |
if (state.firstFreeBlock > 1) |
| 12011 |
std::swap(vector->m_Blocks[i], vector->m_Blocks[--state.firstFreeBlock]); |
| 12012 |
else |
| 12013 |
--state.firstFreeBlock; |
| 12014 |
} |
| 12015 |
} |
| 12016 |
swapped = true; |
| 12017 |
break; |
| 12018 |
} |
| 12019 |
} |
| 12020 |
} |
| 12021 |
} |
| 12022 |
if (swapped) |
| 12023 |
result = VK_INCOMPLETE; |
| 12024 |
break; |
| 12025 |
} |
| 12026 |
} |
| 12027 |
|
| 12028 |
|
| 12029 |
for (const FragmentedBlock& block : immovableBlocks) |
| 12030 |
{ |
| 12031 |
VmaBlockVector* vector = m_pBlockVectors[block.data]; |
| 12032 |
VmaMutexLockWrite lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); |
| 12033 |
|
| 12034 |
for (size_t i = m_ImmovableBlockCount; i < vector->GetBlockCount(); ++i) |
| 12035 |
{ |
| 12036 |
if (vector->GetBlock(i) == block.block) |
| 12037 |
{ |
| 12038 |
std::swap(vector->m_Blocks[i], vector->m_Blocks[m_ImmovableBlockCount++]); |
| 12039 |
break; |
| 12040 |
} |
| 12041 |
} |
| 12042 |
} |
| 12043 |
} while (false); |
| 12044 |
} |
| 12045 |
|
| 12046 |
|
| 12047 |
for (const FragmentedBlock& block : mappedBlocks) |
| 12048 |
{ |
| 12049 |
VkResult res = block.block->Map(allocator, block.data, VMA_NULL); |
| 12050 |
VMA_ASSERT(res == VK_SUCCESS); |
| 12051 |
} |
| 12052 |
return result; |
| 12053 |
} |
| 12054 |
|
| 12055 |
bool VmaDefragmentationContext_T::ComputeDefragmentation(VmaBlockVector& vector, size_t index) |
| 12056 |
{ |
| 12057 |
switch (m_Algorithm) |
| 12058 |
{ |
| 12059 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT: |
| 12060 |
return ComputeDefragmentation_Fast(vector); |
| 12061 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT: |
| 12062 |
return ComputeDefragmentation_Balanced(vector, index, true); |
| 12063 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT: |
| 12064 |
return ComputeDefragmentation_Full(vector); |
| 12065 |
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT: |
| 12066 |
return ComputeDefragmentation_Extensive(vector, index); |
| 12067 |
default: |
| 12068 |
VMA_ASSERT(0); |
| 12069 |
return ComputeDefragmentation_Balanced(vector, index, true); |
| 12070 |
} |
| 12071 |
} |
| 12072 |
|
| 12073 |
VmaDefragmentationContext_T::MoveAllocationData VmaDefragmentationContext_T::GetMoveData( |
| 12074 |
VmaAllocHandle handle, VmaBlockMetadata* metadata) |
| 12075 |
{ |
| 12076 |
MoveAllocationData moveData; |
| 12077 |
moveData.move.srcAllocation = (VmaAllocation)metadata->GetAllocationUserData(handle); |
| 12078 |
moveData.size = moveData.move.srcAllocation->GetSize(); |
| 12079 |
moveData.alignment = moveData.move.srcAllocation->GetAlignment(); |
| 12080 |
moveData.type = moveData.move.srcAllocation->GetSuballocationType(); |
| 12081 |
moveData.flags = 0; |
| 12082 |
|
| 12083 |
if (moveData.move.srcAllocation->IsPersistentMap()) |
| 12084 |
moveData.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; |
| 12085 |
if (moveData.move.srcAllocation->IsMappingAllowed()) |
| 12086 |
moveData.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; |
| 12087 |
|
| 12088 |
return moveData; |
| 12089 |
} |
| 12090 |
|
| 12091 |
VmaDefragmentationContext_T::CounterStatus VmaDefragmentationContext_T::CheckCounters(VkDeviceSize bytes) |
| 12092 |
{ |
| 12093 |
|
| 12094 |
if (m_BreakCallback && m_BreakCallback(m_BreakCallbackUserData)) |
| 12095 |
return CounterStatus::End; |
| 12096 |
|
| 12097 |
|
| 12098 |
if (m_PassStats.bytesMoved + bytes > m_MaxPassBytes) |
| 12099 |
{ |
| 12100 |
if (++m_IgnoredAllocs < MAX_ALLOCS_TO_IGNORE) |
| 12101 |
return CounterStatus::Ignore; |
| 12102 |
else |
| 12103 |
return CounterStatus::End; |
| 12104 |
} |
| 12105 |
else |
| 12106 |
m_IgnoredAllocs = 0; |
| 12107 |
return CounterStatus::Pass; |
| 12108 |
} |
| 12109 |
|
| 12110 |
bool VmaDefragmentationContext_T::IncrementCounters(VkDeviceSize bytes) |
| 12111 |
{ |
| 12112 |
m_PassStats.bytesMoved += bytes; |
| 12113 |
|
| 12114 |
if (++m_PassStats.allocationsMoved >= m_MaxPassAllocations || m_PassStats.bytesMoved >= m_MaxPassBytes) |
| 12115 |
{ |
| 12116 |
VMA_ASSERT((m_PassStats.allocationsMoved == m_MaxPassAllocations || |
| 12117 |
m_PassStats.bytesMoved == m_MaxPassBytes) && "Exceeded maximal pass threshold!"); |
| 12118 |
return true; |
| 12119 |
} |
| 12120 |
return false; |
| 12121 |
} |
| 12122 |
|
| 12123 |
bool VmaDefragmentationContext_T::ReallocWithinBlock(VmaBlockVector& vector, VmaDeviceMemoryBlock* block) |
| 12124 |
{ |
| 12125 |
VmaBlockMetadata* metadata = block->m_pMetadata; |
| 12126 |
|
| 12127 |
for (VmaAllocHandle handle = metadata->GetAllocationListBegin(); |
| 12128 |
handle != VK_NULL_HANDLE; |
| 12129 |
handle = metadata->GetNextAllocation(handle)) |
| 12130 |
{ |
| 12131 |
MoveAllocationData moveData = GetMoveData(handle, metadata); |
| 12132 |
|
| 12133 |
if (moveData.move.srcAllocation->GetUserData() == this) |
| 12134 |
continue; |
| 12135 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12136 |
{ |
| 12137 |
case CounterStatus::Ignore: |
| 12138 |
continue; |
| 12139 |
case CounterStatus::End: |
| 12140 |
return true; |
| 12141 |
case CounterStatus::Pass: |
| 12142 |
break; |
| 12143 |
default: |
| 12144 |
VMA_ASSERT(0); |
| 12145 |
} |
| 12146 |
|
| 12147 |
VkDeviceSize offset = moveData.move.srcAllocation->GetOffset(); |
| 12148 |
if (offset != 0 && metadata->GetSumFreeSize() >= moveData.size) |
| 12149 |
{ |
| 12150 |
VmaAllocationRequest request = {}; |
| 12151 |
if (metadata->CreateAllocationRequest( |
| 12152 |
moveData.size, |
| 12153 |
moveData.alignment, |
| 12154 |
false, |
| 12155 |
moveData.type, |
| 12156 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT, |
| 12157 |
&request)) |
| 12158 |
{ |
| 12159 |
if (metadata->GetAllocationOffset(request.allocHandle) < offset) |
| 12160 |
{ |
| 12161 |
if (vector.CommitAllocationRequest( |
| 12162 |
request, |
| 12163 |
block, |
| 12164 |
moveData.alignment, |
| 12165 |
moveData.flags, |
| 12166 |
this, |
| 12167 |
moveData.type, |
| 12168 |
&moveData.move.dstTmpAllocation) == VK_SUCCESS) |
| 12169 |
{ |
| 12170 |
m_Moves.push_back(moveData.move); |
| 12171 |
if (IncrementCounters(moveData.size)) |
| 12172 |
return true; |
| 12173 |
} |
| 12174 |
} |
| 12175 |
} |
| 12176 |
} |
| 12177 |
} |
| 12178 |
return false; |
| 12179 |
} |
| 12180 |
|
| 12181 |
bool VmaDefragmentationContext_T::AllocInOtherBlock(size_t start, size_t end, MoveAllocationData& data, VmaBlockVector& vector) |
| 12182 |
{ |
| 12183 |
for (; start < end; ++start) |
| 12184 |
{ |
| 12185 |
VmaDeviceMemoryBlock* dstBlock = vector.GetBlock(start); |
| 12186 |
if (dstBlock->m_pMetadata->GetSumFreeSize() >= data.size) |
| 12187 |
{ |
| 12188 |
if (vector.AllocateFromBlock(dstBlock, |
| 12189 |
data.size, |
| 12190 |
data.alignment, |
| 12191 |
data.flags, |
| 12192 |
this, |
| 12193 |
data.type, |
| 12194 |
0, |
| 12195 |
&data.move.dstTmpAllocation) == VK_SUCCESS) |
| 12196 |
{ |
| 12197 |
m_Moves.push_back(data.move); |
| 12198 |
if (IncrementCounters(data.size)) |
| 12199 |
return true; |
| 12200 |
break; |
| 12201 |
} |
| 12202 |
} |
| 12203 |
} |
| 12204 |
return false; |
| 12205 |
} |
| 12206 |
|
| 12207 |
bool VmaDefragmentationContext_T::ComputeDefragmentation_Fast(VmaBlockVector& vector) |
| 12208 |
{ |
| 12209 |
|
| 12210 |
|
| 12211 |
|
| 12212 |
for (size_t i = vector.GetBlockCount() - 1; i > m_ImmovableBlockCount; --i) |
| 12213 |
{ |
| 12214 |
VmaBlockMetadata* metadata = vector.GetBlock(i)->m_pMetadata; |
| 12215 |
|
| 12216 |
for (VmaAllocHandle handle = metadata->GetAllocationListBegin(); |
| 12217 |
handle != VK_NULL_HANDLE; |
| 12218 |
handle = metadata->GetNextAllocation(handle)) |
| 12219 |
{ |
| 12220 |
MoveAllocationData moveData = GetMoveData(handle, metadata); |
| 12221 |
|
| 12222 |
if (moveData.move.srcAllocation->GetUserData() == this) |
| 12223 |
continue; |
| 12224 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12225 |
{ |
| 12226 |
case CounterStatus::Ignore: |
| 12227 |
continue; |
| 12228 |
case CounterStatus::End: |
| 12229 |
return true; |
| 12230 |
case CounterStatus::Pass: |
| 12231 |
break; |
| 12232 |
default: |
| 12233 |
VMA_ASSERT(0); |
| 12234 |
} |
| 12235 |
|
| 12236 |
|
| 12237 |
if (AllocInOtherBlock(0, i, moveData, vector)) |
| 12238 |
return true; |
| 12239 |
} |
| 12240 |
} |
| 12241 |
return false; |
| 12242 |
} |
| 12243 |
|
| 12244 |
bool VmaDefragmentationContext_T::ComputeDefragmentation_Balanced(VmaBlockVector& vector, size_t index, bool update) |
| 12245 |
{ |
| 12246 |
|
| 12247 |
|
| 12248 |
|
| 12249 |
VMA_ASSERT(m_AlgorithmState != VMA_NULL); |
| 12250 |
|
| 12251 |
StateBalanced& vectorState = reinterpret_cast<StateBalanced*>(m_AlgorithmState)[index]; |
| 12252 |
if (update && vectorState.avgAllocSize == UINT64_MAX) |
| 12253 |
UpdateVectorStatistics(vector, vectorState); |
| 12254 |
|
| 12255 |
const size_t startMoveCount = m_Moves.size(); |
| 12256 |
VkDeviceSize minimalFreeRegion = vectorState.avgFreeSize / 2; |
| 12257 |
for (size_t i = vector.GetBlockCount() - 1; i > m_ImmovableBlockCount; --i) |
| 12258 |
{ |
| 12259 |
VmaDeviceMemoryBlock* block = vector.GetBlock(i); |
| 12260 |
VmaBlockMetadata* metadata = block->m_pMetadata; |
| 12261 |
VkDeviceSize prevFreeRegionSize = 0; |
| 12262 |
|
| 12263 |
for (VmaAllocHandle handle = metadata->GetAllocationListBegin(); |
| 12264 |
handle != VK_NULL_HANDLE; |
| 12265 |
handle = metadata->GetNextAllocation(handle)) |
| 12266 |
{ |
| 12267 |
MoveAllocationData moveData = GetMoveData(handle, metadata); |
| 12268 |
|
| 12269 |
if (moveData.move.srcAllocation->GetUserData() == this) |
| 12270 |
continue; |
| 12271 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12272 |
{ |
| 12273 |
case CounterStatus::Ignore: |
| 12274 |
continue; |
| 12275 |
case CounterStatus::End: |
| 12276 |
return true; |
| 12277 |
case CounterStatus::Pass: |
| 12278 |
break; |
| 12279 |
default: |
| 12280 |
VMA_ASSERT(0); |
| 12281 |
} |
| 12282 |
|
| 12283 |
|
| 12284 |
const size_t prevMoveCount = m_Moves.size(); |
| 12285 |
if (AllocInOtherBlock(0, i, moveData, vector)) |
| 12286 |
return true; |
| 12287 |
|
| 12288 |
VkDeviceSize nextFreeRegionSize = metadata->GetNextFreeRegionSize(handle); |
| 12289 |
|
| 12290 |
VkDeviceSize offset = moveData.move.srcAllocation->GetOffset(); |
| 12291 |
if (prevMoveCount == m_Moves.size() && offset != 0 && metadata->GetSumFreeSize() >= moveData.size) |
| 12292 |
{ |
| 12293 |
|
| 12294 |
if (prevFreeRegionSize >= minimalFreeRegion || |
| 12295 |
nextFreeRegionSize >= minimalFreeRegion || |
| 12296 |
moveData.size <= vectorState.avgFreeSize || |
| 12297 |
moveData.size <= vectorState.avgAllocSize) |
| 12298 |
{ |
| 12299 |
VmaAllocationRequest request = {}; |
| 12300 |
if (metadata->CreateAllocationRequest( |
| 12301 |
moveData.size, |
| 12302 |
moveData.alignment, |
| 12303 |
false, |
| 12304 |
moveData.type, |
| 12305 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT, |
| 12306 |
&request)) |
| 12307 |
{ |
| 12308 |
if (metadata->GetAllocationOffset(request.allocHandle) < offset) |
| 12309 |
{ |
| 12310 |
if (vector.CommitAllocationRequest( |
| 12311 |
request, |
| 12312 |
block, |
| 12313 |
moveData.alignment, |
| 12314 |
moveData.flags, |
| 12315 |
this, |
| 12316 |
moveData.type, |
| 12317 |
&moveData.move.dstTmpAllocation) == VK_SUCCESS) |
| 12318 |
{ |
| 12319 |
m_Moves.push_back(moveData.move); |
| 12320 |
if (IncrementCounters(moveData.size)) |
| 12321 |
return true; |
| 12322 |
} |
| 12323 |
} |
| 12324 |
} |
| 12325 |
} |
| 12326 |
} |
| 12327 |
prevFreeRegionSize = nextFreeRegionSize; |
| 12328 |
} |
| 12329 |
} |
| 12330 |
|
| 12331 |
|
| 12332 |
if (startMoveCount == m_Moves.size() && !update) |
| 12333 |
{ |
| 12334 |
vectorState.avgAllocSize = UINT64_MAX; |
| 12335 |
return ComputeDefragmentation_Balanced(vector, index, false); |
| 12336 |
} |
| 12337 |
return false; |
| 12338 |
} |
| 12339 |
|
| 12340 |
bool VmaDefragmentationContext_T::ComputeDefragmentation_Full(VmaBlockVector& vector) |
| 12341 |
{ |
| 12342 |
|
| 12343 |
|
| 12344 |
|
| 12345 |
for (size_t i = vector.GetBlockCount() - 1; i > m_ImmovableBlockCount; --i) |
| 12346 |
{ |
| 12347 |
VmaDeviceMemoryBlock* block = vector.GetBlock(i); |
| 12348 |
VmaBlockMetadata* metadata = block->m_pMetadata; |
| 12349 |
|
| 12350 |
for (VmaAllocHandle handle = metadata->GetAllocationListBegin(); |
| 12351 |
handle != VK_NULL_HANDLE; |
| 12352 |
handle = metadata->GetNextAllocation(handle)) |
| 12353 |
{ |
| 12354 |
MoveAllocationData moveData = GetMoveData(handle, metadata); |
| 12355 |
|
| 12356 |
if (moveData.move.srcAllocation->GetUserData() == this) |
| 12357 |
continue; |
| 12358 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12359 |
{ |
| 12360 |
case CounterStatus::Ignore: |
| 12361 |
continue; |
| 12362 |
case CounterStatus::End: |
| 12363 |
return true; |
| 12364 |
case CounterStatus::Pass: |
| 12365 |
break; |
| 12366 |
default: |
| 12367 |
VMA_ASSERT(0); |
| 12368 |
} |
| 12369 |
|
| 12370 |
|
| 12371 |
const size_t prevMoveCount = m_Moves.size(); |
| 12372 |
if (AllocInOtherBlock(0, i, moveData, vector)) |
| 12373 |
return true; |
| 12374 |
|
| 12375 |
|
| 12376 |
VkDeviceSize offset = moveData.move.srcAllocation->GetOffset(); |
| 12377 |
if (prevMoveCount == m_Moves.size() && offset != 0 && metadata->GetSumFreeSize() >= moveData.size) |
| 12378 |
{ |
| 12379 |
VmaAllocationRequest request = {}; |
| 12380 |
if (metadata->CreateAllocationRequest( |
| 12381 |
moveData.size, |
| 12382 |
moveData.alignment, |
| 12383 |
false, |
| 12384 |
moveData.type, |
| 12385 |
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT, |
| 12386 |
&request)) |
| 12387 |
{ |
| 12388 |
if (metadata->GetAllocationOffset(request.allocHandle) < offset) |
| 12389 |
{ |
| 12390 |
if (vector.CommitAllocationRequest( |
| 12391 |
request, |
| 12392 |
block, |
| 12393 |
moveData.alignment, |
| 12394 |
moveData.flags, |
| 12395 |
this, |
| 12396 |
moveData.type, |
| 12397 |
&moveData.move.dstTmpAllocation) == VK_SUCCESS) |
| 12398 |
{ |
| 12399 |
m_Moves.push_back(moveData.move); |
| 12400 |
if (IncrementCounters(moveData.size)) |
| 12401 |
return true; |
| 12402 |
} |
| 12403 |
} |
| 12404 |
} |
| 12405 |
} |
| 12406 |
} |
| 12407 |
} |
| 12408 |
return false; |
| 12409 |
} |
| 12410 |
|
| 12411 |
bool VmaDefragmentationContext_T::ComputeDefragmentation_Extensive(VmaBlockVector& vector, size_t index) |
| 12412 |
{ |
| 12413 |
|
| 12414 |
|
| 12415 |
|
| 12416 |
if (vector.m_BufferImageGranularity == 1) |
| 12417 |
return ComputeDefragmentation_Full(vector); |
| 12418 |
|
| 12419 |
VMA_ASSERT(m_AlgorithmState != VMA_NULL); |
| 12420 |
|
| 12421 |
StateExtensive& vectorState = reinterpret_cast<StateExtensive*>(m_AlgorithmState)[index]; |
| 12422 |
|
| 12423 |
bool texturePresent = false, bufferPresent = false, otherPresent = false; |
| 12424 |
switch (vectorState.operation) |
| 12425 |
{ |
| 12426 |
case StateExtensive::Operation::Done: |
| 12427 |
return false; |
| 12428 |
case StateExtensive::Operation::FindFreeBlockBuffer: |
| 12429 |
case StateExtensive::Operation::FindFreeBlockTexture: |
| 12430 |
case StateExtensive::Operation::FindFreeBlockAll: |
| 12431 |
{ |
| 12432 |
|
| 12433 |
if (vectorState.firstFreeBlock == 0) |
| 12434 |
{ |
| 12435 |
vectorState.operation = StateExtensive::Operation::Cleanup; |
| 12436 |
return ComputeDefragmentation_Fast(vector); |
| 12437 |
} |
| 12438 |
|
| 12439 |
|
| 12440 |
size_t last = (vectorState.firstFreeBlock == SIZE_MAX ? vector.GetBlockCount() : vectorState.firstFreeBlock) - 1; |
| 12441 |
VmaBlockMetadata* freeMetadata = vector.GetBlock(last)->m_pMetadata; |
| 12442 |
|
| 12443 |
const size_t prevMoveCount = m_Moves.size(); |
| 12444 |
for (VmaAllocHandle handle = freeMetadata->GetAllocationListBegin(); |
| 12445 |
handle != VK_NULL_HANDLE; |
| 12446 |
handle = freeMetadata->GetNextAllocation(handle)) |
| 12447 |
{ |
| 12448 |
MoveAllocationData moveData = GetMoveData(handle, freeMetadata); |
| 12449 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12450 |
{ |
| 12451 |
case CounterStatus::Ignore: |
| 12452 |
continue; |
| 12453 |
case CounterStatus::End: |
| 12454 |
return true; |
| 12455 |
case CounterStatus::Pass: |
| 12456 |
break; |
| 12457 |
default: |
| 12458 |
VMA_ASSERT(0); |
| 12459 |
} |
| 12460 |
|
| 12461 |
|
| 12462 |
if (AllocInOtherBlock(0, last, moveData, vector)) |
| 12463 |
{ |
| 12464 |
|
| 12465 |
if (prevMoveCount != m_Moves.size() && freeMetadata->GetNextAllocation(handle) == VK_NULL_HANDLE) |
| 12466 |
vectorState.firstFreeBlock = last; |
| 12467 |
return true; |
| 12468 |
} |
| 12469 |
} |
| 12470 |
|
| 12471 |
if (prevMoveCount == m_Moves.size()) |
| 12472 |
{ |
| 12473 |
|
| 12474 |
if (last != 0) |
| 12475 |
{ |
| 12476 |
for (size_t i = last - 1; i; --i) |
| 12477 |
{ |
| 12478 |
if (ReallocWithinBlock(vector, vector.GetBlock(i))) |
| 12479 |
return true; |
| 12480 |
} |
| 12481 |
} |
| 12482 |
|
| 12483 |
if (prevMoveCount == m_Moves.size()) |
| 12484 |
{ |
| 12485 |
|
| 12486 |
return ComputeDefragmentation_Fast(vector); |
| 12487 |
} |
| 12488 |
} |
| 12489 |
else |
| 12490 |
{ |
| 12491 |
switch (vectorState.operation) |
| 12492 |
{ |
| 12493 |
case StateExtensive::Operation::FindFreeBlockBuffer: |
| 12494 |
vectorState.operation = StateExtensive::Operation::MoveBuffers; |
| 12495 |
break; |
| 12496 |
case StateExtensive::Operation::FindFreeBlockTexture: |
| 12497 |
vectorState.operation = StateExtensive::Operation::MoveTextures; |
| 12498 |
break; |
| 12499 |
case StateExtensive::Operation::FindFreeBlockAll: |
| 12500 |
vectorState.operation = StateExtensive::Operation::MoveAll; |
| 12501 |
break; |
| 12502 |
default: |
| 12503 |
VMA_ASSERT(0); |
| 12504 |
vectorState.operation = StateExtensive::Operation::MoveTextures; |
| 12505 |
} |
| 12506 |
vectorState.firstFreeBlock = last; |
| 12507 |
|
| 12508 |
return ComputeDefragmentation_Extensive(vector, index); |
| 12509 |
} |
| 12510 |
break; |
| 12511 |
} |
| 12512 |
case StateExtensive::Operation::MoveTextures: |
| 12513 |
{ |
| 12514 |
if (MoveDataToFreeBlocks(VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL, vector, |
| 12515 |
vectorState.firstFreeBlock, texturePresent, bufferPresent, otherPresent)) |
| 12516 |
{ |
| 12517 |
if (texturePresent) |
| 12518 |
{ |
| 12519 |
vectorState.operation = StateExtensive::Operation::FindFreeBlockTexture; |
| 12520 |
return ComputeDefragmentation_Extensive(vector, index); |
| 12521 |
} |
| 12522 |
|
| 12523 |
if (!bufferPresent && !otherPresent) |
| 12524 |
{ |
| 12525 |
vectorState.operation = StateExtensive::Operation::Cleanup; |
| 12526 |
break; |
| 12527 |
} |
| 12528 |
|
| 12529 |
|
| 12530 |
vectorState.operation = StateExtensive::Operation::MoveBuffers; |
| 12531 |
bufferPresent = false; |
| 12532 |
otherPresent = false; |
| 12533 |
} |
| 12534 |
else |
| 12535 |
break; |
| 12536 |
VMA_FALLTHROUGH; |
| 12537 |
} |
| 12538 |
case StateExtensive::Operation::MoveBuffers: |
| 12539 |
{ |
| 12540 |
if (MoveDataToFreeBlocks(VMA_SUBALLOCATION_TYPE_BUFFER, vector, |
| 12541 |
vectorState.firstFreeBlock, texturePresent, bufferPresent, otherPresent)) |
| 12542 |
{ |
| 12543 |
if (bufferPresent) |
| 12544 |
{ |
| 12545 |
vectorState.operation = StateExtensive::Operation::FindFreeBlockBuffer; |
| 12546 |
return ComputeDefragmentation_Extensive(vector, index); |
| 12547 |
} |
| 12548 |
|
| 12549 |
if (!otherPresent) |
| 12550 |
{ |
| 12551 |
vectorState.operation = StateExtensive::Operation::Cleanup; |
| 12552 |
break; |
| 12553 |
} |
| 12554 |
|
| 12555 |
|
| 12556 |
vectorState.operation = StateExtensive::Operation::MoveAll; |
| 12557 |
otherPresent = false; |
| 12558 |
} |
| 12559 |
else |
| 12560 |
break; |
| 12561 |
VMA_FALLTHROUGH; |
| 12562 |
} |
| 12563 |
case StateExtensive::Operation::MoveAll: |
| 12564 |
{ |
| 12565 |
if (MoveDataToFreeBlocks(VMA_SUBALLOCATION_TYPE_FREE, vector, |
| 12566 |
vectorState.firstFreeBlock, texturePresent, bufferPresent, otherPresent)) |
| 12567 |
{ |
| 12568 |
if (otherPresent) |
| 12569 |
{ |
| 12570 |
vectorState.operation = StateExtensive::Operation::FindFreeBlockBuffer; |
| 12571 |
return ComputeDefragmentation_Extensive(vector, index); |
| 12572 |
} |
| 12573 |
|
| 12574 |
vectorState.operation = StateExtensive::Operation::Cleanup; |
| 12575 |
} |
| 12576 |
break; |
| 12577 |
} |
| 12578 |
case StateExtensive::Operation::Cleanup: |
| 12579 |
|
| 12580 |
break; |
| 12581 |
} |
| 12582 |
|
| 12583 |
if (vectorState.operation == StateExtensive::Operation::Cleanup) |
| 12584 |
{ |
| 12585 |
|
| 12586 |
const size_t prevMoveCount = m_Moves.size(); |
| 12587 |
for (size_t i = 0; i < vector.GetBlockCount(); ++i) |
| 12588 |
{ |
| 12589 |
if (ReallocWithinBlock(vector, vector.GetBlock(i))) |
| 12590 |
return true; |
| 12591 |
} |
| 12592 |
|
| 12593 |
if (prevMoveCount == m_Moves.size()) |
| 12594 |
vectorState.operation = StateExtensive::Operation::Done; |
| 12595 |
} |
| 12596 |
return false; |
| 12597 |
} |
| 12598 |
|
| 12599 |
void VmaDefragmentationContext_T::UpdateVectorStatistics(VmaBlockVector& vector, StateBalanced& state) |
| 12600 |
{ |
| 12601 |
size_t allocCount = 0; |
| 12602 |
size_t freeCount = 0; |
| 12603 |
state.avgFreeSize = 0; |
| 12604 |
state.avgAllocSize = 0; |
| 12605 |
|
| 12606 |
for (size_t i = 0; i < vector.GetBlockCount(); ++i) |
| 12607 |
{ |
| 12608 |
VmaBlockMetadata* metadata = vector.GetBlock(i)->m_pMetadata; |
| 12609 |
|
| 12610 |
allocCount += metadata->GetAllocationCount(); |
| 12611 |
freeCount += metadata->GetFreeRegionsCount(); |
| 12612 |
state.avgFreeSize += metadata->GetSumFreeSize(); |
| 12613 |
state.avgAllocSize += metadata->GetSize(); |
| 12614 |
} |
| 12615 |
|
| 12616 |
state.avgAllocSize = (state.avgAllocSize - state.avgFreeSize) / allocCount; |
| 12617 |
state.avgFreeSize /= freeCount; |
| 12618 |
} |
| 12619 |
|
| 12620 |
bool VmaDefragmentationContext_T::MoveDataToFreeBlocks(VmaSuballocationType currentType, |
| 12621 |
VmaBlockVector& vector, size_t firstFreeBlock, |
| 12622 |
bool& texturePresent, bool& bufferPresent, bool& otherPresent) |
| 12623 |
{ |
| 12624 |
const size_t prevMoveCount = m_Moves.size(); |
| 12625 |
for (size_t i = firstFreeBlock ; i;) |
| 12626 |
{ |
| 12627 |
VmaDeviceMemoryBlock* block = vector.GetBlock(--i); |
| 12628 |
VmaBlockMetadata* metadata = block->m_pMetadata; |
| 12629 |
|
| 12630 |
for (VmaAllocHandle handle = metadata->GetAllocationListBegin(); |
| 12631 |
handle != VK_NULL_HANDLE; |
| 12632 |
handle = metadata->GetNextAllocation(handle)) |
| 12633 |
{ |
| 12634 |
MoveAllocationData moveData = GetMoveData(handle, metadata); |
| 12635 |
|
| 12636 |
if (moveData.move.srcAllocation->GetUserData() == this) |
| 12637 |
continue; |
| 12638 |
switch (CheckCounters(moveData.move.srcAllocation->GetSize())) |
| 12639 |
{ |
| 12640 |
case CounterStatus::Ignore: |
| 12641 |
continue; |
| 12642 |
case CounterStatus::End: |
| 12643 |
return true; |
| 12644 |
case CounterStatus::Pass: |
| 12645 |
break; |
| 12646 |
default: |
| 12647 |
VMA_ASSERT(0); |
| 12648 |
} |
| 12649 |
|
| 12650 |
|
| 12651 |
if (!VmaIsBufferImageGranularityConflict(moveData.type, currentType)) |
| 12652 |
{ |
| 12653 |
|
| 12654 |
if (AllocInOtherBlock(firstFreeBlock, vector.GetBlockCount(), moveData, vector)) |
| 12655 |
return false; |
| 12656 |
} |
| 12657 |
|
| 12658 |
if (!VmaIsBufferImageGranularityConflict(moveData.type, VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL)) |
| 12659 |
texturePresent = true; |
| 12660 |
else if (!VmaIsBufferImageGranularityConflict(moveData.type, VMA_SUBALLOCATION_TYPE_BUFFER)) |
| 12661 |
bufferPresent = true; |
| 12662 |
else |
| 12663 |
otherPresent = true; |
| 12664 |
} |
| 12665 |
} |
| 12666 |
return prevMoveCount == m_Moves.size(); |
| 12667 |
} |
| 12668 |
#endif |
| 12669 |
|
| 12670 |
#ifndef _VMA_POOL_T_FUNCTIONS |
| 12671 |
VmaPool_T::VmaPool_T( |
| 12672 |
VmaAllocator hAllocator, |
| 12673 |
const VmaPoolCreateInfo& createInfo, |
| 12674 |
VkDeviceSize preferredBlockSize) |
| 12675 |
: m_BlockVector( |
| 12676 |
hAllocator, |
| 12677 |
this, |
| 12678 |
createInfo.memoryTypeIndex, |
| 12679 |
createInfo.blockSize != 0 ? createInfo.blockSize : preferredBlockSize, |
| 12680 |
createInfo.minBlockCount, |
| 12681 |
createInfo.maxBlockCount, |
| 12682 |
(createInfo.flags& VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(), |
| 12683 |
createInfo.blockSize != 0, |
| 12684 |
createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK, |
| 12685 |
createInfo.priority, |
| 12686 |
VMA_MAX(hAllocator->GetMemoryTypeMinAlignment(createInfo.memoryTypeIndex), createInfo.minAllocationAlignment), |
| 12687 |
createInfo.pMemoryAllocateNext), |
| 12688 |
m_Id(0), |
| 12689 |
m_Name(VMA_NULL) {} |
| 12690 |
|
| 12691 |
VmaPool_T::~VmaPool_T() |
| 12692 |
{ |
| 12693 |
VMA_ASSERT(m_PrevPool == VMA_NULL && m_NextPool == VMA_NULL); |
| 12694 |
|
| 12695 |
const VkAllocationCallbacks* allocs = m_BlockVector.GetAllocator()->GetAllocationCallbacks(); |
| 12696 |
VmaFreeString(allocs, m_Name); |
| 12697 |
} |
| 12698 |
|
| 12699 |
void VmaPool_T::SetName(const char* pName) |
| 12700 |
{ |
| 12701 |
const VkAllocationCallbacks* allocs = m_BlockVector.GetAllocator()->GetAllocationCallbacks(); |
| 12702 |
VmaFreeString(allocs, m_Name); |
| 12703 |
|
| 12704 |
if (pName != VMA_NULL) |
| 12705 |
{ |
| 12706 |
m_Name = VmaCreateStringCopy(allocs, pName); |
| 12707 |
} |
| 12708 |
else |
| 12709 |
{ |
| 12710 |
m_Name = VMA_NULL; |
| 12711 |
} |
| 12712 |
} |
| 12713 |
#endif |
| 12714 |
|
| 12715 |
#ifndef _VMA_ALLOCATOR_T_FUNCTIONS |
| 12716 |
VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) : |
| 12717 |
m_UseMutex((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT) == 0), |
| 12718 |
m_VulkanApiVersion(pCreateInfo->vulkanApiVersion != 0 ? pCreateInfo->vulkanApiVersion : VK_API_VERSION_1_0), |
| 12719 |
m_UseKhrDedicatedAllocation((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0), |
| 12720 |
m_UseKhrBindMemory2((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT) != 0), |
| 12721 |
m_UseExtMemoryBudget((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0), |
| 12722 |
m_UseAmdDeviceCoherentMemory((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT) != 0), |
| 12723 |
m_UseKhrBufferDeviceAddress((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT) != 0), |
| 12724 |
m_UseExtMemoryPriority((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT) != 0), |
| 12725 |
m_UseKhrMaintenance4((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT) != 0), |
| 12726 |
m_UseKhrMaintenance5((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT) != 0), |
| 12727 |
m_hDevice(pCreateInfo->device), |
| 12728 |
m_hInstance(pCreateInfo->instance), |
| 12729 |
m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL), |
| 12730 |
m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ? |
| 12731 |
*pCreateInfo->pAllocationCallbacks : VmaEmptyAllocationCallbacks), |
| 12732 |
m_AllocationObjectAllocator(&m_AllocationCallbacks), |
| 12733 |
m_HeapSizeLimitMask(0), |
| 12734 |
m_DeviceMemoryCount(0), |
| 12735 |
m_PreferredLargeHeapBlockSize(0), |
| 12736 |
m_PhysicalDevice(pCreateInfo->physicalDevice), |
| 12737 |
m_GpuDefragmentationMemoryTypeBits(UINT32_MAX), |
| 12738 |
m_NextPoolId(0), |
| 12739 |
m_GlobalMemoryTypeBits(UINT32_MAX) |
| 12740 |
{ |
| 12741 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 12742 |
{ |
| 12743 |
m_UseKhrDedicatedAllocation = false; |
| 12744 |
m_UseKhrBindMemory2 = false; |
| 12745 |
} |
| 12746 |
|
| 12747 |
if(VMA_DEBUG_DETECT_CORRUPTION) |
| 12748 |
{ |
| 12749 |
|
| 12750 |
VMA_ASSERT(VMA_DEBUG_MARGIN % sizeof(uint32_t) == 0); |
| 12751 |
} |
| 12752 |
|
| 12753 |
VMA_ASSERT(pCreateInfo->physicalDevice && pCreateInfo->device && pCreateInfo->instance); |
| 12754 |
|
| 12755 |
if(m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0)) |
| 12756 |
{ |
| 12757 |
#if !(VMA_DEDICATED_ALLOCATION) |
| 12758 |
if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0) |
| 12759 |
{ |
| 12760 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros."); |
| 12761 |
} |
| 12762 |
#endif |
| 12763 |
#if !(VMA_BIND_MEMORY2) |
| 12764 |
if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT) != 0) |
| 12765 |
{ |
| 12766 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT set but required extension is disabled by preprocessor macros."); |
| 12767 |
} |
| 12768 |
#endif |
| 12769 |
} |
| 12770 |
#if !(VMA_MEMORY_BUDGET) |
| 12771 |
if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0) |
| 12772 |
{ |
| 12773 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT set but required extension is disabled by preprocessor macros."); |
| 12774 |
} |
| 12775 |
#endif |
| 12776 |
#if !(VMA_BUFFER_DEVICE_ADDRESS) |
| 12777 |
if(m_UseKhrBufferDeviceAddress) |
| 12778 |
{ |
| 12779 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT is set but required extension or Vulkan 1.2 is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro."); |
| 12780 |
} |
| 12781 |
#endif |
| 12782 |
#if VMA_VULKAN_VERSION < 1003000 |
| 12783 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0)) |
| 12784 |
{ |
| 12785 |
VMA_ASSERT(0 && "vulkanApiVersion >= VK_API_VERSION_1_3 but required Vulkan version is disabled by preprocessor macros."); |
| 12786 |
} |
| 12787 |
#endif |
| 12788 |
#if VMA_VULKAN_VERSION < 1002000 |
| 12789 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 2, 0)) |
| 12790 |
{ |
| 12791 |
VMA_ASSERT(0 && "vulkanApiVersion >= VK_API_VERSION_1_2 but required Vulkan version is disabled by preprocessor macros."); |
| 12792 |
} |
| 12793 |
#endif |
| 12794 |
#if VMA_VULKAN_VERSION < 1001000 |
| 12795 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 12796 |
{ |
| 12797 |
VMA_ASSERT(0 && "vulkanApiVersion >= VK_API_VERSION_1_1 but required Vulkan version is disabled by preprocessor macros."); |
| 12798 |
} |
| 12799 |
#endif |
| 12800 |
#if !(VMA_MEMORY_PRIORITY) |
| 12801 |
if(m_UseExtMemoryPriority) |
| 12802 |
{ |
| 12803 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro."); |
| 12804 |
} |
| 12805 |
#endif |
| 12806 |
#if !(VMA_KHR_MAINTENANCE4) |
| 12807 |
if(m_UseKhrMaintenance4) |
| 12808 |
{ |
| 12809 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro."); |
| 12810 |
} |
| 12811 |
#endif |
| 12812 |
#if !(VMA_KHR_MAINTENANCE5) |
| 12813 |
if(m_UseKhrMaintenance5) |
| 12814 |
{ |
| 12815 |
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro."); |
| 12816 |
} |
| 12817 |
#endif |
| 12818 |
|
| 12819 |
memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks)); |
| 12820 |
memset(&m_PhysicalDeviceProperties, 0, sizeof(m_PhysicalDeviceProperties)); |
| 12821 |
memset(&m_MemProps, 0, sizeof(m_MemProps)); |
| 12822 |
|
| 12823 |
memset(&m_pBlockVectors, 0, sizeof(m_pBlockVectors)); |
| 12824 |
memset(&m_VulkanFunctions, 0, sizeof(m_VulkanFunctions)); |
| 12825 |
|
| 12826 |
#if VMA_EXTERNAL_MEMORY |
| 12827 |
memset(&m_TypeExternalMemoryHandleTypes, 0, sizeof(m_TypeExternalMemoryHandleTypes)); |
| 12828 |
#endif |
| 12829 |
|
| 12830 |
if(pCreateInfo->pDeviceMemoryCallbacks != VMA_NULL) |
| 12831 |
{ |
| 12832 |
m_DeviceMemoryCallbacks.pUserData = pCreateInfo->pDeviceMemoryCallbacks->pUserData; |
| 12833 |
m_DeviceMemoryCallbacks.pfnAllocate = pCreateInfo->pDeviceMemoryCallbacks->pfnAllocate; |
| 12834 |
m_DeviceMemoryCallbacks.pfnFree = pCreateInfo->pDeviceMemoryCallbacks->pfnFree; |
| 12835 |
} |
| 12836 |
|
| 12837 |
ImportVulkanFunctions(pCreateInfo->pVulkanFunctions); |
| 12838 |
|
| 12839 |
(*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties); |
| 12840 |
(*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps); |
| 12841 |
|
| 12842 |
VMA_ASSERT(VmaIsPow2(VMA_MIN_ALIGNMENT)); |
| 12843 |
VMA_ASSERT(VmaIsPow2(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY)); |
| 12844 |
VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.bufferImageGranularity)); |
| 12845 |
VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize)); |
| 12846 |
|
| 12847 |
m_PreferredLargeHeapBlockSize = (pCreateInfo->preferredLargeHeapBlockSize != 0) ? |
| 12848 |
pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE); |
| 12849 |
|
| 12850 |
m_GlobalMemoryTypeBits = CalculateGlobalMemoryTypeBits(); |
| 12851 |
|
| 12852 |
#if VMA_EXTERNAL_MEMORY |
| 12853 |
if(pCreateInfo->pTypeExternalMemoryHandleTypes != VMA_NULL) |
| 12854 |
{ |
| 12855 |
memcpy(m_TypeExternalMemoryHandleTypes, pCreateInfo->pTypeExternalMemoryHandleTypes, |
| 12856 |
sizeof(VkExternalMemoryHandleTypeFlagsKHR) * GetMemoryTypeCount()); |
| 12857 |
} |
| 12858 |
#endif |
| 12859 |
|
| 12860 |
if(pCreateInfo->pHeapSizeLimit != VMA_NULL) |
| 12861 |
{ |
| 12862 |
for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex) |
| 12863 |
{ |
| 12864 |
const VkDeviceSize limit = pCreateInfo->pHeapSizeLimit[heapIndex]; |
| 12865 |
if(limit != VK_WHOLE_SIZE) |
| 12866 |
{ |
| 12867 |
m_HeapSizeLimitMask |= 1u << heapIndex; |
| 12868 |
if(limit < m_MemProps.memoryHeaps[heapIndex].size) |
| 12869 |
{ |
| 12870 |
m_MemProps.memoryHeaps[heapIndex].size = limit; |
| 12871 |
} |
| 12872 |
} |
| 12873 |
} |
| 12874 |
} |
| 12875 |
|
| 12876 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 12877 |
{ |
| 12878 |
|
| 12879 |
if((m_GlobalMemoryTypeBits & (1u << memTypeIndex)) != 0) |
| 12880 |
{ |
| 12881 |
const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex); |
| 12882 |
m_pBlockVectors[memTypeIndex] = vma_new(this, VmaBlockVector)( |
| 12883 |
this, |
| 12884 |
VK_NULL_HANDLE, |
| 12885 |
memTypeIndex, |
| 12886 |
preferredBlockSize, |
| 12887 |
0, |
| 12888 |
SIZE_MAX, |
| 12889 |
GetBufferImageGranularity(), |
| 12890 |
false, |
| 12891 |
0, |
| 12892 |
0.5f, |
| 12893 |
GetMemoryTypeMinAlignment(memTypeIndex), |
| 12894 |
VMA_NULL); |
| 12895 |
|
| 12896 |
|
| 12897 |
} |
| 12898 |
} |
| 12899 |
} |
| 12900 |
|
| 12901 |
VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo* pCreateInfo) |
| 12902 |
{ |
| 12903 |
VkResult res = VK_SUCCESS; |
| 12904 |
|
| 12905 |
#if VMA_MEMORY_BUDGET |
| 12906 |
if(m_UseExtMemoryBudget) |
| 12907 |
{ |
| 12908 |
UpdateVulkanBudget(); |
| 12909 |
} |
| 12910 |
#endif |
| 12911 |
|
| 12912 |
return res; |
| 12913 |
} |
| 12914 |
|
| 12915 |
VmaAllocator_T::~VmaAllocator_T() |
| 12916 |
{ |
| 12917 |
VMA_ASSERT(m_Pools.IsEmpty()); |
| 12918 |
|
| 12919 |
for(size_t memTypeIndex = GetMemoryTypeCount(); memTypeIndex--; ) |
| 12920 |
{ |
| 12921 |
vma_delete(this, m_pBlockVectors[memTypeIndex]); |
| 12922 |
} |
| 12923 |
} |
| 12924 |
|
| 12925 |
void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunctions) |
| 12926 |
{ |
| 12927 |
#if VMA_STATIC_VULKAN_FUNCTIONS == 1 |
| 12928 |
ImportVulkanFunctions_Static(); |
| 12929 |
#endif |
| 12930 |
|
| 12931 |
if(pVulkanFunctions != VMA_NULL) |
| 12932 |
{ |
| 12933 |
ImportVulkanFunctions_Custom(pVulkanFunctions); |
| 12934 |
} |
| 12935 |
|
| 12936 |
#if VMA_DYNAMIC_VULKAN_FUNCTIONS == 1 |
| 12937 |
ImportVulkanFunctions_Dynamic(); |
| 12938 |
#endif |
| 12939 |
|
| 12940 |
ValidateVulkanFunctions(); |
| 12941 |
} |
| 12942 |
|
| 12943 |
#if VMA_STATIC_VULKAN_FUNCTIONS == 1 |
| 12944 |
|
| 12945 |
void VmaAllocator_T::ImportVulkanFunctions_Static() |
| 12946 |
{ |
| 12947 |
|
| 12948 |
m_VulkanFunctions.vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr; |
| 12949 |
m_VulkanFunctions.vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)vkGetDeviceProcAddr; |
| 12950 |
m_VulkanFunctions.vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)vkGetPhysicalDeviceProperties; |
| 12951 |
m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vkGetPhysicalDeviceMemoryProperties; |
| 12952 |
m_VulkanFunctions.vkAllocateMemory = (PFN_vkAllocateMemory)vkAllocateMemory; |
| 12953 |
m_VulkanFunctions.vkFreeMemory = (PFN_vkFreeMemory)vkFreeMemory; |
| 12954 |
m_VulkanFunctions.vkMapMemory = (PFN_vkMapMemory)vkMapMemory; |
| 12955 |
m_VulkanFunctions.vkUnmapMemory = (PFN_vkUnmapMemory)vkUnmapMemory; |
| 12956 |
m_VulkanFunctions.vkFlushMappedMemoryRanges = (PFN_vkFlushMappedMemoryRanges)vkFlushMappedMemoryRanges; |
| 12957 |
m_VulkanFunctions.vkInvalidateMappedMemoryRanges = (PFN_vkInvalidateMappedMemoryRanges)vkInvalidateMappedMemoryRanges; |
| 12958 |
m_VulkanFunctions.vkBindBufferMemory = (PFN_vkBindBufferMemory)vkBindBufferMemory; |
| 12959 |
m_VulkanFunctions.vkBindImageMemory = (PFN_vkBindImageMemory)vkBindImageMemory; |
| 12960 |
m_VulkanFunctions.vkGetBufferMemoryRequirements = (PFN_vkGetBufferMemoryRequirements)vkGetBufferMemoryRequirements; |
| 12961 |
m_VulkanFunctions.vkGetImageMemoryRequirements = (PFN_vkGetImageMemoryRequirements)vkGetImageMemoryRequirements; |
| 12962 |
m_VulkanFunctions.vkCreateBuffer = (PFN_vkCreateBuffer)vkCreateBuffer; |
| 12963 |
m_VulkanFunctions.vkDestroyBuffer = (PFN_vkDestroyBuffer)vkDestroyBuffer; |
| 12964 |
m_VulkanFunctions.vkCreateImage = (PFN_vkCreateImage)vkCreateImage; |
| 12965 |
m_VulkanFunctions.vkDestroyImage = (PFN_vkDestroyImage)vkDestroyImage; |
| 12966 |
m_VulkanFunctions.vkCmdCopyBuffer = (PFN_vkCmdCopyBuffer)vkCmdCopyBuffer; |
| 12967 |
|
| 12968 |
|
| 12969 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 12970 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 12971 |
{ |
| 12972 |
m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR = (PFN_vkGetBufferMemoryRequirements2)vkGetBufferMemoryRequirements2; |
| 12973 |
m_VulkanFunctions.vkGetImageMemoryRequirements2KHR = (PFN_vkGetImageMemoryRequirements2)vkGetImageMemoryRequirements2; |
| 12974 |
m_VulkanFunctions.vkBindBufferMemory2KHR = (PFN_vkBindBufferMemory2)vkBindBufferMemory2; |
| 12975 |
m_VulkanFunctions.vkBindImageMemory2KHR = (PFN_vkBindImageMemory2)vkBindImageMemory2; |
| 12976 |
} |
| 12977 |
#endif |
| 12978 |
|
| 12979 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 12980 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 12981 |
{ |
| 12982 |
m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR = (PFN_vkGetPhysicalDeviceMemoryProperties2)vkGetPhysicalDeviceMemoryProperties2; |
| 12983 |
} |
| 12984 |
#endif |
| 12985 |
|
| 12986 |
#if VMA_VULKAN_VERSION >= 1003000 |
| 12987 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0)) |
| 12988 |
{ |
| 12989 |
m_VulkanFunctions.vkGetDeviceBufferMemoryRequirements = (PFN_vkGetDeviceBufferMemoryRequirements)vkGetDeviceBufferMemoryRequirements; |
| 12990 |
m_VulkanFunctions.vkGetDeviceImageMemoryRequirements = (PFN_vkGetDeviceImageMemoryRequirements)vkGetDeviceImageMemoryRequirements; |
| 12991 |
} |
| 12992 |
#endif |
| 12993 |
} |
| 12994 |
|
| 12995 |
#endif |
| 12996 |
|
| 12997 |
void VmaAllocator_T::ImportVulkanFunctions_Custom(const VmaVulkanFunctions* pVulkanFunctions) |
| 12998 |
{ |
| 12999 |
VMA_ASSERT(pVulkanFunctions != VMA_NULL); |
| 13000 |
|
| 13001 |
#define VMA_COPY_IF_NOT_NULL(funcName) \ |
| 13002 |
if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName; |
| 13003 |
|
| 13004 |
VMA_COPY_IF_NOT_NULL(vkGetInstanceProcAddr); |
| 13005 |
VMA_COPY_IF_NOT_NULL(vkGetDeviceProcAddr); |
| 13006 |
VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceProperties); |
| 13007 |
VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties); |
| 13008 |
VMA_COPY_IF_NOT_NULL(vkAllocateMemory); |
| 13009 |
VMA_COPY_IF_NOT_NULL(vkFreeMemory); |
| 13010 |
VMA_COPY_IF_NOT_NULL(vkMapMemory); |
| 13011 |
VMA_COPY_IF_NOT_NULL(vkUnmapMemory); |
| 13012 |
VMA_COPY_IF_NOT_NULL(vkFlushMappedMemoryRanges); |
| 13013 |
VMA_COPY_IF_NOT_NULL(vkInvalidateMappedMemoryRanges); |
| 13014 |
VMA_COPY_IF_NOT_NULL(vkBindBufferMemory); |
| 13015 |
VMA_COPY_IF_NOT_NULL(vkBindImageMemory); |
| 13016 |
VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements); |
| 13017 |
VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements); |
| 13018 |
VMA_COPY_IF_NOT_NULL(vkCreateBuffer); |
| 13019 |
VMA_COPY_IF_NOT_NULL(vkDestroyBuffer); |
| 13020 |
VMA_COPY_IF_NOT_NULL(vkCreateImage); |
| 13021 |
VMA_COPY_IF_NOT_NULL(vkDestroyImage); |
| 13022 |
VMA_COPY_IF_NOT_NULL(vkCmdCopyBuffer); |
| 13023 |
|
| 13024 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 13025 |
VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements2KHR); |
| 13026 |
VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements2KHR); |
| 13027 |
#endif |
| 13028 |
|
| 13029 |
#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000 |
| 13030 |
VMA_COPY_IF_NOT_NULL(vkBindBufferMemory2KHR); |
| 13031 |
VMA_COPY_IF_NOT_NULL(vkBindImageMemory2KHR); |
| 13032 |
#endif |
| 13033 |
|
| 13034 |
#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000 |
| 13035 |
VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties2KHR); |
| 13036 |
#endif |
| 13037 |
|
| 13038 |
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 |
| 13039 |
VMA_COPY_IF_NOT_NULL(vkGetDeviceBufferMemoryRequirements); |
| 13040 |
VMA_COPY_IF_NOT_NULL(vkGetDeviceImageMemoryRequirements); |
| 13041 |
#endif |
| 13042 |
|
| 13043 |
#undef VMA_COPY_IF_NOT_NULL |
| 13044 |
} |
| 13045 |
|
| 13046 |
#if VMA_DYNAMIC_VULKAN_FUNCTIONS == 1 |
| 13047 |
|
| 13048 |
void VmaAllocator_T::ImportVulkanFunctions_Dynamic() |
| 13049 |
{ |
| 13050 |
VMA_ASSERT(m_VulkanFunctions.vkGetInstanceProcAddr && m_VulkanFunctions.vkGetDeviceProcAddr && |
| 13051 |
"To use VMA_DYNAMIC_VULKAN_FUNCTIONS in new versions of VMA you now have to pass " |
| 13052 |
"VmaVulkanFunctions::vkGetInstanceProcAddr and vkGetDeviceProcAddr as VmaAllocatorCreateInfo::pVulkanFunctions. " |
| 13053 |
"Other members can be null."); |
| 13054 |
|
| 13055 |
#define VMA_FETCH_INSTANCE_FUNC(memberName, functionPointerType, functionNameString) \ |
| 13056 |
if(m_VulkanFunctions.memberName == VMA_NULL) \ |
| 13057 |
m_VulkanFunctions.memberName = \ |
| 13058 |
(functionPointerType)m_VulkanFunctions.vkGetInstanceProcAddr(m_hInstance, functionNameString); |
| 13059 |
#define VMA_FETCH_DEVICE_FUNC(memberName, functionPointerType, functionNameString) \ |
| 13060 |
if(m_VulkanFunctions.memberName == VMA_NULL) \ |
| 13061 |
m_VulkanFunctions.memberName = \ |
| 13062 |
(functionPointerType)m_VulkanFunctions.vkGetDeviceProcAddr(m_hDevice, functionNameString); |
| 13063 |
|
| 13064 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceProperties, PFN_vkGetPhysicalDeviceProperties, "vkGetPhysicalDeviceProperties"); |
| 13065 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceMemoryProperties, PFN_vkGetPhysicalDeviceMemoryProperties, "vkGetPhysicalDeviceMemoryProperties"); |
| 13066 |
VMA_FETCH_DEVICE_FUNC(vkAllocateMemory, PFN_vkAllocateMemory, "vkAllocateMemory"); |
| 13067 |
VMA_FETCH_DEVICE_FUNC(vkFreeMemory, PFN_vkFreeMemory, "vkFreeMemory"); |
| 13068 |
VMA_FETCH_DEVICE_FUNC(vkMapMemory, PFN_vkMapMemory, "vkMapMemory"); |
| 13069 |
VMA_FETCH_DEVICE_FUNC(vkUnmapMemory, PFN_vkUnmapMemory, "vkUnmapMemory"); |
| 13070 |
VMA_FETCH_DEVICE_FUNC(vkFlushMappedMemoryRanges, PFN_vkFlushMappedMemoryRanges, "vkFlushMappedMemoryRanges"); |
| 13071 |
VMA_FETCH_DEVICE_FUNC(vkInvalidateMappedMemoryRanges, PFN_vkInvalidateMappedMemoryRanges, "vkInvalidateMappedMemoryRanges"); |
| 13072 |
VMA_FETCH_DEVICE_FUNC(vkBindBufferMemory, PFN_vkBindBufferMemory, "vkBindBufferMemory"); |
| 13073 |
VMA_FETCH_DEVICE_FUNC(vkBindImageMemory, PFN_vkBindImageMemory, "vkBindImageMemory"); |
| 13074 |
VMA_FETCH_DEVICE_FUNC(vkGetBufferMemoryRequirements, PFN_vkGetBufferMemoryRequirements, "vkGetBufferMemoryRequirements"); |
| 13075 |
VMA_FETCH_DEVICE_FUNC(vkGetImageMemoryRequirements, PFN_vkGetImageMemoryRequirements, "vkGetImageMemoryRequirements"); |
| 13076 |
VMA_FETCH_DEVICE_FUNC(vkCreateBuffer, PFN_vkCreateBuffer, "vkCreateBuffer"); |
| 13077 |
VMA_FETCH_DEVICE_FUNC(vkDestroyBuffer, PFN_vkDestroyBuffer, "vkDestroyBuffer"); |
| 13078 |
VMA_FETCH_DEVICE_FUNC(vkCreateImage, PFN_vkCreateImage, "vkCreateImage"); |
| 13079 |
VMA_FETCH_DEVICE_FUNC(vkDestroyImage, PFN_vkDestroyImage, "vkDestroyImage"); |
| 13080 |
VMA_FETCH_DEVICE_FUNC(vkCmdCopyBuffer, PFN_vkCmdCopyBuffer, "vkCmdCopyBuffer"); |
| 13081 |
|
| 13082 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 13083 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13084 |
{ |
| 13085 |
VMA_FETCH_DEVICE_FUNC(vkGetBufferMemoryRequirements2KHR, PFN_vkGetBufferMemoryRequirements2, "vkGetBufferMemoryRequirements2"); |
| 13086 |
VMA_FETCH_DEVICE_FUNC(vkGetImageMemoryRequirements2KHR, PFN_vkGetImageMemoryRequirements2, "vkGetImageMemoryRequirements2"); |
| 13087 |
VMA_FETCH_DEVICE_FUNC(vkBindBufferMemory2KHR, PFN_vkBindBufferMemory2, "vkBindBufferMemory2"); |
| 13088 |
VMA_FETCH_DEVICE_FUNC(vkBindImageMemory2KHR, PFN_vkBindImageMemory2, "vkBindImageMemory2"); |
| 13089 |
} |
| 13090 |
#endif |
| 13091 |
|
| 13092 |
#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000 |
| 13093 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13094 |
{ |
| 13095 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceMemoryProperties2KHR, PFN_vkGetPhysicalDeviceMemoryProperties2KHR, "vkGetPhysicalDeviceMemoryProperties2"); |
| 13096 |
} |
| 13097 |
else if(m_UseExtMemoryBudget) |
| 13098 |
{ |
| 13099 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceMemoryProperties2KHR, PFN_vkGetPhysicalDeviceMemoryProperties2KHR, "vkGetPhysicalDeviceMemoryProperties2KHR"); |
| 13100 |
} |
| 13101 |
#endif |
| 13102 |
|
| 13103 |
#if VMA_DEDICATED_ALLOCATION |
| 13104 |
if(m_UseKhrDedicatedAllocation) |
| 13105 |
{ |
| 13106 |
VMA_FETCH_DEVICE_FUNC(vkGetBufferMemoryRequirements2KHR, PFN_vkGetBufferMemoryRequirements2KHR, "vkGetBufferMemoryRequirements2KHR"); |
| 13107 |
VMA_FETCH_DEVICE_FUNC(vkGetImageMemoryRequirements2KHR, PFN_vkGetImageMemoryRequirements2KHR, "vkGetImageMemoryRequirements2KHR"); |
| 13108 |
} |
| 13109 |
#endif |
| 13110 |
|
| 13111 |
#if VMA_BIND_MEMORY2 |
| 13112 |
if(m_UseKhrBindMemory2) |
| 13113 |
{ |
| 13114 |
VMA_FETCH_DEVICE_FUNC(vkBindBufferMemory2KHR, PFN_vkBindBufferMemory2KHR, "vkBindBufferMemory2KHR"); |
| 13115 |
VMA_FETCH_DEVICE_FUNC(vkBindImageMemory2KHR, PFN_vkBindImageMemory2KHR, "vkBindImageMemory2KHR"); |
| 13116 |
} |
| 13117 |
#endif |
| 13118 |
|
| 13119 |
#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000 |
| 13120 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13121 |
{ |
| 13122 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceMemoryProperties2KHR, PFN_vkGetPhysicalDeviceMemoryProperties2KHR, "vkGetPhysicalDeviceMemoryProperties2"); |
| 13123 |
} |
| 13124 |
else if(m_UseExtMemoryBudget) |
| 13125 |
{ |
| 13126 |
VMA_FETCH_INSTANCE_FUNC(vkGetPhysicalDeviceMemoryProperties2KHR, PFN_vkGetPhysicalDeviceMemoryProperties2KHR, "vkGetPhysicalDeviceMemoryProperties2KHR"); |
| 13127 |
} |
| 13128 |
#endif |
| 13129 |
|
| 13130 |
#if VMA_VULKAN_VERSION >= 1003000 |
| 13131 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0)) |
| 13132 |
{ |
| 13133 |
VMA_FETCH_DEVICE_FUNC(vkGetDeviceBufferMemoryRequirements, PFN_vkGetDeviceBufferMemoryRequirements, "vkGetDeviceBufferMemoryRequirements"); |
| 13134 |
VMA_FETCH_DEVICE_FUNC(vkGetDeviceImageMemoryRequirements, PFN_vkGetDeviceImageMemoryRequirements, "vkGetDeviceImageMemoryRequirements"); |
| 13135 |
} |
| 13136 |
#endif |
| 13137 |
#if VMA_KHR_MAINTENANCE4 |
| 13138 |
if(m_UseKhrMaintenance4) |
| 13139 |
{ |
| 13140 |
VMA_FETCH_DEVICE_FUNC(vkGetDeviceBufferMemoryRequirements, PFN_vkGetDeviceBufferMemoryRequirementsKHR, "vkGetDeviceBufferMemoryRequirementsKHR"); |
| 13141 |
VMA_FETCH_DEVICE_FUNC(vkGetDeviceImageMemoryRequirements, PFN_vkGetDeviceImageMemoryRequirementsKHR, "vkGetDeviceImageMemoryRequirementsKHR"); |
| 13142 |
} |
| 13143 |
#endif |
| 13144 |
|
| 13145 |
#undef VMA_FETCH_DEVICE_FUNC |
| 13146 |
#undef VMA_FETCH_INSTANCE_FUNC |
| 13147 |
} |
| 13148 |
|
| 13149 |
#endif |
| 13150 |
|
| 13151 |
void VmaAllocator_T::ValidateVulkanFunctions() |
| 13152 |
{ |
| 13153 |
VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceProperties != VMA_NULL); |
| 13154 |
VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties != VMA_NULL); |
| 13155 |
VMA_ASSERT(m_VulkanFunctions.vkAllocateMemory != VMA_NULL); |
| 13156 |
VMA_ASSERT(m_VulkanFunctions.vkFreeMemory != VMA_NULL); |
| 13157 |
VMA_ASSERT(m_VulkanFunctions.vkMapMemory != VMA_NULL); |
| 13158 |
VMA_ASSERT(m_VulkanFunctions.vkUnmapMemory != VMA_NULL); |
| 13159 |
VMA_ASSERT(m_VulkanFunctions.vkFlushMappedMemoryRanges != VMA_NULL); |
| 13160 |
VMA_ASSERT(m_VulkanFunctions.vkInvalidateMappedMemoryRanges != VMA_NULL); |
| 13161 |
VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory != VMA_NULL); |
| 13162 |
VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory != VMA_NULL); |
| 13163 |
VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements != VMA_NULL); |
| 13164 |
VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements != VMA_NULL); |
| 13165 |
VMA_ASSERT(m_VulkanFunctions.vkCreateBuffer != VMA_NULL); |
| 13166 |
VMA_ASSERT(m_VulkanFunctions.vkDestroyBuffer != VMA_NULL); |
| 13167 |
VMA_ASSERT(m_VulkanFunctions.vkCreateImage != VMA_NULL); |
| 13168 |
VMA_ASSERT(m_VulkanFunctions.vkDestroyImage != VMA_NULL); |
| 13169 |
VMA_ASSERT(m_VulkanFunctions.vkCmdCopyBuffer != VMA_NULL); |
| 13170 |
|
| 13171 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 13172 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrDedicatedAllocation) |
| 13173 |
{ |
| 13174 |
VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR != VMA_NULL); |
| 13175 |
VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements2KHR != VMA_NULL); |
| 13176 |
} |
| 13177 |
#endif |
| 13178 |
|
| 13179 |
#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000 |
| 13180 |
if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrBindMemory2) |
| 13181 |
{ |
| 13182 |
VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL); |
| 13183 |
VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL); |
| 13184 |
} |
| 13185 |
#endif |
| 13186 |
|
| 13187 |
#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000 |
| 13188 |
if(m_UseExtMemoryBudget || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13189 |
{ |
| 13190 |
VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL); |
| 13191 |
} |
| 13192 |
#endif |
| 13193 |
|
| 13194 |
|
| 13195 |
|
| 13196 |
|
| 13197 |
|
| 13198 |
|
| 13199 |
|
| 13200 |
} |
| 13201 |
|
| 13202 |
VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex) |
| 13203 |
{ |
| 13204 |
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex); |
| 13205 |
const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size; |
| 13206 |
const bool isSmallHeap = heapSize <= VMA_SMALL_HEAP_MAX_SIZE; |
| 13207 |
return VmaAlignUp(isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize, (VkDeviceSize)32); |
| 13208 |
} |
| 13209 |
|
| 13210 |
VkResult VmaAllocator_T::AllocateMemoryOfType( |
| 13211 |
VmaPool pool, |
| 13212 |
VkDeviceSize size, |
| 13213 |
VkDeviceSize alignment, |
| 13214 |
bool dedicatedPreferred, |
| 13215 |
VkBuffer dedicatedBuffer, |
| 13216 |
VkImage dedicatedImage, |
| 13217 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 13218 |
const VmaAllocationCreateInfo& createInfo, |
| 13219 |
uint32_t memTypeIndex, |
| 13220 |
VmaSuballocationType suballocType, |
| 13221 |
VmaDedicatedAllocationList& dedicatedAllocations, |
| 13222 |
VmaBlockVector& blockVector, |
| 13223 |
size_t allocationCount, |
| 13224 |
VmaAllocation* pAllocations) |
| 13225 |
{ |
| 13226 |
VMA_ASSERT(pAllocations != VMA_NULL); |
| 13227 |
VMA_DEBUG_LOG_FORMAT(" AllocateMemory: MemoryTypeIndex=%" PRIu32 ", AllocationCount=%zu, Size=%" PRIu64, memTypeIndex, allocationCount, size); |
| 13228 |
|
| 13229 |
VmaAllocationCreateInfo finalCreateInfo = createInfo; |
| 13230 |
VkResult res = CalcMemTypeParams( |
| 13231 |
finalCreateInfo, |
| 13232 |
memTypeIndex, |
| 13233 |
size, |
| 13234 |
allocationCount); |
| 13235 |
if(res != VK_SUCCESS) |
| 13236 |
return res; |
| 13237 |
|
| 13238 |
if((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0) |
| 13239 |
{ |
| 13240 |
return AllocateDedicatedMemory( |
| 13241 |
pool, |
| 13242 |
size, |
| 13243 |
suballocType, |
| 13244 |
dedicatedAllocations, |
| 13245 |
memTypeIndex, |
| 13246 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0, |
| 13247 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0, |
| 13248 |
(finalCreateInfo.flags & |
| 13249 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0, |
| 13250 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT) != 0, |
| 13251 |
finalCreateInfo.pUserData, |
| 13252 |
finalCreateInfo.priority, |
| 13253 |
dedicatedBuffer, |
| 13254 |
dedicatedImage, |
| 13255 |
dedicatedBufferImageUsage, |
| 13256 |
allocationCount, |
| 13257 |
pAllocations, |
| 13258 |
blockVector.GetAllocationNextPtr()); |
| 13259 |
} |
| 13260 |
else |
| 13261 |
{ |
| 13262 |
const bool canAllocateDedicated = |
| 13263 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0 && |
| 13264 |
(pool == VK_NULL_HANDLE || !blockVector.HasExplicitBlockSize()); |
| 13265 |
|
| 13266 |
if(canAllocateDedicated) |
| 13267 |
{ |
| 13268 |
|
| 13269 |
if(size > blockVector.GetPreferredBlockSize() / 2) |
| 13270 |
{ |
| 13271 |
dedicatedPreferred = true; |
| 13272 |
} |
| 13273 |
|
| 13274 |
|
| 13275 |
|
| 13276 |
if(m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount < UINT32_MAX / 4 && |
| 13277 |
m_DeviceMemoryCount.load() > m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount * 3 / 4) |
| 13278 |
{ |
| 13279 |
dedicatedPreferred = false; |
| 13280 |
} |
| 13281 |
|
| 13282 |
if(dedicatedPreferred) |
| 13283 |
{ |
| 13284 |
res = AllocateDedicatedMemory( |
| 13285 |
pool, |
| 13286 |
size, |
| 13287 |
suballocType, |
| 13288 |
dedicatedAllocations, |
| 13289 |
memTypeIndex, |
| 13290 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0, |
| 13291 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0, |
| 13292 |
(finalCreateInfo.flags & |
| 13293 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0, |
| 13294 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT) != 0, |
| 13295 |
finalCreateInfo.pUserData, |
| 13296 |
finalCreateInfo.priority, |
| 13297 |
dedicatedBuffer, |
| 13298 |
dedicatedImage, |
| 13299 |
dedicatedBufferImageUsage, |
| 13300 |
allocationCount, |
| 13301 |
pAllocations, |
| 13302 |
blockVector.GetAllocationNextPtr()); |
| 13303 |
if(res == VK_SUCCESS) |
| 13304 |
{ |
| 13305 |
|
| 13306 |
VMA_DEBUG_LOG(" Allocated as DedicatedMemory"); |
| 13307 |
return VK_SUCCESS; |
| 13308 |
} |
| 13309 |
} |
| 13310 |
} |
| 13311 |
|
| 13312 |
res = blockVector.Allocate( |
| 13313 |
size, |
| 13314 |
alignment, |
| 13315 |
finalCreateInfo, |
| 13316 |
suballocType, |
| 13317 |
allocationCount, |
| 13318 |
pAllocations); |
| 13319 |
if(res == VK_SUCCESS) |
| 13320 |
return VK_SUCCESS; |
| 13321 |
|
| 13322 |
|
| 13323 |
if(canAllocateDedicated && !dedicatedPreferred) |
| 13324 |
{ |
| 13325 |
res = AllocateDedicatedMemory( |
| 13326 |
pool, |
| 13327 |
size, |
| 13328 |
suballocType, |
| 13329 |
dedicatedAllocations, |
| 13330 |
memTypeIndex, |
| 13331 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0, |
| 13332 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0, |
| 13333 |
(finalCreateInfo.flags & |
| 13334 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0, |
| 13335 |
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT) != 0, |
| 13336 |
finalCreateInfo.pUserData, |
| 13337 |
finalCreateInfo.priority, |
| 13338 |
dedicatedBuffer, |
| 13339 |
dedicatedImage, |
| 13340 |
dedicatedBufferImageUsage, |
| 13341 |
allocationCount, |
| 13342 |
pAllocations, |
| 13343 |
blockVector.GetAllocationNextPtr()); |
| 13344 |
if(res == VK_SUCCESS) |
| 13345 |
{ |
| 13346 |
|
| 13347 |
VMA_DEBUG_LOG(" Allocated as DedicatedMemory"); |
| 13348 |
return VK_SUCCESS; |
| 13349 |
} |
| 13350 |
} |
| 13351 |
|
| 13352 |
VMA_DEBUG_LOG(" vkAllocateMemory FAILED"); |
| 13353 |
return res; |
| 13354 |
} |
| 13355 |
} |
| 13356 |
|
| 13357 |
VkResult VmaAllocator_T::AllocateDedicatedMemory( |
| 13358 |
VmaPool pool, |
| 13359 |
VkDeviceSize size, |
| 13360 |
VmaSuballocationType suballocType, |
| 13361 |
VmaDedicatedAllocationList& dedicatedAllocations, |
| 13362 |
uint32_t memTypeIndex, |
| 13363 |
bool map, |
| 13364 |
bool isUserDataString, |
| 13365 |
bool isMappingAllowed, |
| 13366 |
bool canAliasMemory, |
| 13367 |
void* pUserData, |
| 13368 |
float priority, |
| 13369 |
VkBuffer dedicatedBuffer, |
| 13370 |
VkImage dedicatedImage, |
| 13371 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 13372 |
size_t allocationCount, |
| 13373 |
VmaAllocation* pAllocations, |
| 13374 |
const void* pNextChain) |
| 13375 |
{ |
| 13376 |
VMA_ASSERT(allocationCount > 0 && pAllocations); |
| 13377 |
|
| 13378 |
VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO }; |
| 13379 |
allocInfo.memoryTypeIndex = memTypeIndex; |
| 13380 |
allocInfo.allocationSize = size; |
| 13381 |
allocInfo.pNext = pNextChain; |
| 13382 |
|
| 13383 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 13384 |
VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR }; |
| 13385 |
if(!canAliasMemory) |
| 13386 |
{ |
| 13387 |
if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13388 |
{ |
| 13389 |
if(dedicatedBuffer != VK_NULL_HANDLE) |
| 13390 |
{ |
| 13391 |
VMA_ASSERT(dedicatedImage == VK_NULL_HANDLE); |
| 13392 |
dedicatedAllocInfo.buffer = dedicatedBuffer; |
| 13393 |
VmaPnextChainPushFront(&allocInfo, &dedicatedAllocInfo); |
| 13394 |
} |
| 13395 |
else if(dedicatedImage != VK_NULL_HANDLE) |
| 13396 |
{ |
| 13397 |
dedicatedAllocInfo.image = dedicatedImage; |
| 13398 |
VmaPnextChainPushFront(&allocInfo, &dedicatedAllocInfo); |
| 13399 |
} |
| 13400 |
} |
| 13401 |
} |
| 13402 |
#endif |
| 13403 |
|
| 13404 |
#if VMA_BUFFER_DEVICE_ADDRESS |
| 13405 |
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR }; |
| 13406 |
if(m_UseKhrBufferDeviceAddress) |
| 13407 |
{ |
| 13408 |
bool canContainBufferWithDeviceAddress = true; |
| 13409 |
if(dedicatedBuffer != VK_NULL_HANDLE) |
| 13410 |
{ |
| 13411 |
canContainBufferWithDeviceAddress = dedicatedBufferImageUsage == VmaBufferImageUsage::UNKNOWN || |
| 13412 |
dedicatedBufferImageUsage.Contains(VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT); |
| 13413 |
} |
| 13414 |
else if(dedicatedImage != VK_NULL_HANDLE) |
| 13415 |
{ |
| 13416 |
canContainBufferWithDeviceAddress = false; |
| 13417 |
} |
| 13418 |
if(canContainBufferWithDeviceAddress) |
| 13419 |
{ |
| 13420 |
allocFlagsInfo.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR; |
| 13421 |
VmaPnextChainPushFront(&allocInfo, &allocFlagsInfo); |
| 13422 |
} |
| 13423 |
} |
| 13424 |
#endif |
| 13425 |
|
| 13426 |
#if VMA_MEMORY_PRIORITY |
| 13427 |
VkMemoryPriorityAllocateInfoEXT priorityInfo = { VK_STRUCTURE_TYPE_MEMORY_PRIORITY_ALLOCATE_INFO_EXT }; |
| 13428 |
if(m_UseExtMemoryPriority) |
| 13429 |
{ |
| 13430 |
VMA_ASSERT(priority >= 0.f && priority <= 1.f); |
| 13431 |
priorityInfo.priority = priority; |
| 13432 |
VmaPnextChainPushFront(&allocInfo, &priorityInfo); |
| 13433 |
} |
| 13434 |
#endif |
| 13435 |
|
| 13436 |
#if VMA_EXTERNAL_MEMORY |
| 13437 |
|
| 13438 |
VkExportMemoryAllocateInfoKHR exportMemoryAllocInfo = { VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR }; |
| 13439 |
exportMemoryAllocInfo.handleTypes = GetExternalMemoryHandleTypeFlags(memTypeIndex); |
| 13440 |
if(exportMemoryAllocInfo.handleTypes != 0) |
| 13441 |
{ |
| 13442 |
VmaPnextChainPushFront(&allocInfo, &exportMemoryAllocInfo); |
| 13443 |
} |
| 13444 |
#endif |
| 13445 |
|
| 13446 |
size_t allocIndex; |
| 13447 |
VkResult res = VK_SUCCESS; |
| 13448 |
for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex) |
| 13449 |
{ |
| 13450 |
res = AllocateDedicatedMemoryPage( |
| 13451 |
pool, |
| 13452 |
size, |
| 13453 |
suballocType, |
| 13454 |
memTypeIndex, |
| 13455 |
allocInfo, |
| 13456 |
map, |
| 13457 |
isUserDataString, |
| 13458 |
isMappingAllowed, |
| 13459 |
pUserData, |
| 13460 |
pAllocations + allocIndex); |
| 13461 |
if(res != VK_SUCCESS) |
| 13462 |
{ |
| 13463 |
break; |
| 13464 |
} |
| 13465 |
} |
| 13466 |
|
| 13467 |
if(res == VK_SUCCESS) |
| 13468 |
{ |
| 13469 |
for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex) |
| 13470 |
{ |
| 13471 |
dedicatedAllocations.Register(pAllocations[allocIndex]); |
| 13472 |
} |
| 13473 |
VMA_DEBUG_LOG_FORMAT(" Allocated DedicatedMemory Count=%zu, MemoryTypeIndex=#%" PRIu32, allocationCount, memTypeIndex); |
| 13474 |
} |
| 13475 |
else |
| 13476 |
{ |
| 13477 |
|
| 13478 |
while(allocIndex--) |
| 13479 |
{ |
| 13480 |
VmaAllocation currAlloc = pAllocations[allocIndex]; |
| 13481 |
VkDeviceMemory hMemory = currAlloc->GetMemory(); |
| 13482 |
|
| 13483 |
|
| 13484 |
|
| 13485 |
|
| 13486 |
|
| 13487 |
|
| 13488 |
|
| 13489 |
|
| 13490 |
|
| 13491 |
|
| 13492 |
|
| 13493 |
FreeVulkanMemory(memTypeIndex, currAlloc->GetSize(), hMemory); |
| 13494 |
m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), currAlloc->GetSize()); |
| 13495 |
m_AllocationObjectAllocator.Free(currAlloc); |
| 13496 |
} |
| 13497 |
|
| 13498 |
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount); |
| 13499 |
} |
| 13500 |
|
| 13501 |
return res; |
| 13502 |
} |
| 13503 |
|
| 13504 |
VkResult VmaAllocator_T::AllocateDedicatedMemoryPage( |
| 13505 |
VmaPool pool, |
| 13506 |
VkDeviceSize size, |
| 13507 |
VmaSuballocationType suballocType, |
| 13508 |
uint32_t memTypeIndex, |
| 13509 |
const VkMemoryAllocateInfo& allocInfo, |
| 13510 |
bool map, |
| 13511 |
bool isUserDataString, |
| 13512 |
bool isMappingAllowed, |
| 13513 |
void* pUserData, |
| 13514 |
VmaAllocation* pAllocation) |
| 13515 |
{ |
| 13516 |
VkDeviceMemory hMemory = VK_NULL_HANDLE; |
| 13517 |
VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory); |
| 13518 |
if(res < 0) |
| 13519 |
{ |
| 13520 |
VMA_DEBUG_LOG(" vkAllocateMemory FAILED"); |
| 13521 |
return res; |
| 13522 |
} |
| 13523 |
|
| 13524 |
void* pMappedData = VMA_NULL; |
| 13525 |
if(map) |
| 13526 |
{ |
| 13527 |
res = (*m_VulkanFunctions.vkMapMemory)( |
| 13528 |
m_hDevice, |
| 13529 |
hMemory, |
| 13530 |
0, |
| 13531 |
VK_WHOLE_SIZE, |
| 13532 |
0, |
| 13533 |
&pMappedData); |
| 13534 |
if(res < 0) |
| 13535 |
{ |
| 13536 |
VMA_DEBUG_LOG(" vkMapMemory FAILED"); |
| 13537 |
FreeVulkanMemory(memTypeIndex, size, hMemory); |
| 13538 |
return res; |
| 13539 |
} |
| 13540 |
} |
| 13541 |
|
| 13542 |
*pAllocation = m_AllocationObjectAllocator.Allocate(isMappingAllowed); |
| 13543 |
(*pAllocation)->InitDedicatedAllocation(pool, memTypeIndex, hMemory, suballocType, pMappedData, size); |
| 13544 |
if (isUserDataString) |
| 13545 |
(*pAllocation)->SetName(this, (const char*)pUserData); |
| 13546 |
else |
| 13547 |
(*pAllocation)->SetUserData(this, pUserData); |
| 13548 |
m_Budget.AddAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), size); |
| 13549 |
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS) |
| 13550 |
{ |
| 13551 |
FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED); |
| 13552 |
} |
| 13553 |
|
| 13554 |
return VK_SUCCESS; |
| 13555 |
} |
| 13556 |
|
| 13557 |
void VmaAllocator_T::GetBufferMemoryRequirements( |
| 13558 |
VkBuffer hBuffer, |
| 13559 |
VkMemoryRequirements& memReq, |
| 13560 |
bool& requiresDedicatedAllocation, |
| 13561 |
bool& prefersDedicatedAllocation) const |
| 13562 |
{ |
| 13563 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 13564 |
if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13565 |
{ |
| 13566 |
VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR }; |
| 13567 |
memReqInfo.buffer = hBuffer; |
| 13568 |
|
| 13569 |
VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; |
| 13570 |
|
| 13571 |
VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR }; |
| 13572 |
VmaPnextChainPushFront(&memReq2, &memDedicatedReq); |
| 13573 |
|
| 13574 |
(*m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2); |
| 13575 |
|
| 13576 |
memReq = memReq2.memoryRequirements; |
| 13577 |
requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE); |
| 13578 |
prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE); |
| 13579 |
} |
| 13580 |
else |
| 13581 |
#endif |
| 13582 |
{ |
| 13583 |
(*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq); |
| 13584 |
requiresDedicatedAllocation = false; |
| 13585 |
prefersDedicatedAllocation = false; |
| 13586 |
} |
| 13587 |
} |
| 13588 |
|
| 13589 |
void VmaAllocator_T::GetImageMemoryRequirements( |
| 13590 |
VkImage hImage, |
| 13591 |
VkMemoryRequirements& memReq, |
| 13592 |
bool& requiresDedicatedAllocation, |
| 13593 |
bool& prefersDedicatedAllocation) const |
| 13594 |
{ |
| 13595 |
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000 |
| 13596 |
if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) |
| 13597 |
{ |
| 13598 |
VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR }; |
| 13599 |
memReqInfo.image = hImage; |
| 13600 |
|
| 13601 |
VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; |
| 13602 |
|
| 13603 |
VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR }; |
| 13604 |
VmaPnextChainPushFront(&memReq2, &memDedicatedReq); |
| 13605 |
|
| 13606 |
(*m_VulkanFunctions.vkGetImageMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2); |
| 13607 |
|
| 13608 |
memReq = memReq2.memoryRequirements; |
| 13609 |
requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE); |
| 13610 |
prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE); |
| 13611 |
} |
| 13612 |
else |
| 13613 |
#endif |
| 13614 |
{ |
| 13615 |
(*m_VulkanFunctions.vkGetImageMemoryRequirements)(m_hDevice, hImage, &memReq); |
| 13616 |
requiresDedicatedAllocation = false; |
| 13617 |
prefersDedicatedAllocation = false; |
| 13618 |
} |
| 13619 |
} |
| 13620 |
|
| 13621 |
VkResult VmaAllocator_T::FindMemoryTypeIndex( |
| 13622 |
uint32_t memoryTypeBits, |
| 13623 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 13624 |
VmaBufferImageUsage bufImgUsage, |
| 13625 |
uint32_t* pMemoryTypeIndex) const |
| 13626 |
{ |
| 13627 |
memoryTypeBits &= GetGlobalMemoryTypeBits(); |
| 13628 |
|
| 13629 |
if(pAllocationCreateInfo->memoryTypeBits != 0) |
| 13630 |
{ |
| 13631 |
memoryTypeBits &= pAllocationCreateInfo->memoryTypeBits; |
| 13632 |
} |
| 13633 |
|
| 13634 |
VkMemoryPropertyFlags requiredFlags = 0, preferredFlags = 0, notPreferredFlags = 0; |
| 13635 |
if(!FindMemoryPreferences( |
| 13636 |
IsIntegratedGpu(), |
| 13637 |
*pAllocationCreateInfo, |
| 13638 |
bufImgUsage, |
| 13639 |
requiredFlags, preferredFlags, notPreferredFlags)) |
| 13640 |
{ |
| 13641 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 13642 |
} |
| 13643 |
|
| 13644 |
*pMemoryTypeIndex = UINT32_MAX; |
| 13645 |
uint32_t minCost = UINT32_MAX; |
| 13646 |
for(uint32_t memTypeIndex = 0, memTypeBit = 1; |
| 13647 |
memTypeIndex < GetMemoryTypeCount(); |
| 13648 |
++memTypeIndex, memTypeBit <<= 1) |
| 13649 |
{ |
| 13650 |
|
| 13651 |
if((memTypeBit & memoryTypeBits) != 0) |
| 13652 |
{ |
| 13653 |
const VkMemoryPropertyFlags currFlags = |
| 13654 |
m_MemProps.memoryTypes[memTypeIndex].propertyFlags; |
| 13655 |
|
| 13656 |
if((requiredFlags & ~currFlags) == 0) |
| 13657 |
{ |
| 13658 |
|
| 13659 |
uint32_t currCost = VMA_COUNT_BITS_SET(preferredFlags & ~currFlags) + |
| 13660 |
VMA_COUNT_BITS_SET(currFlags & notPreferredFlags); |
| 13661 |
|
| 13662 |
if(currCost < minCost) |
| 13663 |
{ |
| 13664 |
*pMemoryTypeIndex = memTypeIndex; |
| 13665 |
if(currCost == 0) |
| 13666 |
{ |
| 13667 |
return VK_SUCCESS; |
| 13668 |
} |
| 13669 |
minCost = currCost; |
| 13670 |
} |
| 13671 |
} |
| 13672 |
} |
| 13673 |
} |
| 13674 |
return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT; |
| 13675 |
} |
| 13676 |
|
| 13677 |
VkResult VmaAllocator_T::CalcMemTypeParams( |
| 13678 |
VmaAllocationCreateInfo& inoutCreateInfo, |
| 13679 |
uint32_t memTypeIndex, |
| 13680 |
VkDeviceSize size, |
| 13681 |
size_t allocationCount) |
| 13682 |
{ |
| 13683 |
|
| 13684 |
if((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 && |
| 13685 |
(m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) |
| 13686 |
{ |
| 13687 |
inoutCreateInfo.flags &= ~VMA_ALLOCATION_CREATE_MAPPED_BIT; |
| 13688 |
} |
| 13689 |
|
| 13690 |
if((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 && |
| 13691 |
(inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0) |
| 13692 |
{ |
| 13693 |
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex); |
| 13694 |
VmaBudget heapBudget = {}; |
| 13695 |
GetHeapBudgets(&heapBudget, heapIndex, 1); |
| 13696 |
if(heapBudget.usage + size * allocationCount > heapBudget.budget) |
| 13697 |
{ |
| 13698 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 13699 |
} |
| 13700 |
} |
| 13701 |
return VK_SUCCESS; |
| 13702 |
} |
| 13703 |
|
| 13704 |
VkResult VmaAllocator_T::CalcAllocationParams( |
| 13705 |
VmaAllocationCreateInfo& inoutCreateInfo, |
| 13706 |
bool dedicatedRequired, |
| 13707 |
bool dedicatedPreferred) |
| 13708 |
{ |
| 13709 |
VMA_ASSERT((inoutCreateInfo.flags & |
| 13710 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != |
| 13711 |
(VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT) && |
| 13712 |
"Specifying both flags VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT and VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT is incorrect."); |
| 13713 |
VMA_ASSERT((((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT) == 0 || |
| 13714 |
(inoutCreateInfo.flags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0)) && |
| 13715 |
"Specifying VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT requires also VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT."); |
| 13716 |
if(inoutCreateInfo.usage == VMA_MEMORY_USAGE_AUTO || inoutCreateInfo.usage == VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE || inoutCreateInfo.usage == VMA_MEMORY_USAGE_AUTO_PREFER_HOST) |
| 13717 |
{ |
| 13718 |
if((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0) |
| 13719 |
{ |
| 13720 |
VMA_ASSERT((inoutCreateInfo.flags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0 && |
| 13721 |
"When using VMA_ALLOCATION_CREATE_MAPPED_BIT and usage = VMA_MEMORY_USAGE_AUTO*, you must also specify VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT."); |
| 13722 |
} |
| 13723 |
} |
| 13724 |
|
| 13725 |
|
| 13726 |
if(dedicatedRequired || |
| 13727 |
inoutCreateInfo.usage == VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED) |
| 13728 |
{ |
| 13729 |
inoutCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 13730 |
} |
| 13731 |
|
| 13732 |
if(inoutCreateInfo.pool != VK_NULL_HANDLE) |
| 13733 |
{ |
| 13734 |
if(inoutCreateInfo.pool->m_BlockVector.HasExplicitBlockSize() && |
| 13735 |
(inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0) |
| 13736 |
{ |
| 13737 |
VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT while current custom pool doesn't support dedicated allocations."); |
| 13738 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 13739 |
} |
| 13740 |
inoutCreateInfo.priority = inoutCreateInfo.pool->m_BlockVector.GetPriority(); |
| 13741 |
} |
| 13742 |
|
| 13743 |
if((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 && |
| 13744 |
(inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) |
| 13745 |
{ |
| 13746 |
VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense."); |
| 13747 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 13748 |
} |
| 13749 |
|
| 13750 |
if(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY && |
| 13751 |
(inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) |
| 13752 |
{ |
| 13753 |
inoutCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 13754 |
} |
| 13755 |
|
| 13756 |
|
| 13757 |
|
| 13758 |
|
| 13759 |
|
| 13760 |
if(inoutCreateInfo.usage != VMA_MEMORY_USAGE_AUTO && |
| 13761 |
inoutCreateInfo.usage != VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE && |
| 13762 |
inoutCreateInfo.usage != VMA_MEMORY_USAGE_AUTO_PREFER_HOST) |
| 13763 |
{ |
| 13764 |
if((inoutCreateInfo.flags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) == 0) |
| 13765 |
{ |
| 13766 |
inoutCreateInfo.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; |
| 13767 |
} |
| 13768 |
} |
| 13769 |
|
| 13770 |
return VK_SUCCESS; |
| 13771 |
} |
| 13772 |
|
| 13773 |
VkResult VmaAllocator_T::AllocateMemory( |
| 13774 |
const VkMemoryRequirements& vkMemReq, |
| 13775 |
bool requiresDedicatedAllocation, |
| 13776 |
bool prefersDedicatedAllocation, |
| 13777 |
VkBuffer dedicatedBuffer, |
| 13778 |
VkImage dedicatedImage, |
| 13779 |
VmaBufferImageUsage dedicatedBufferImageUsage, |
| 13780 |
const VmaAllocationCreateInfo& createInfo, |
| 13781 |
VmaSuballocationType suballocType, |
| 13782 |
size_t allocationCount, |
| 13783 |
VmaAllocation* pAllocations) |
| 13784 |
{ |
| 13785 |
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount); |
| 13786 |
|
| 13787 |
VMA_ASSERT(VmaIsPow2(vkMemReq.alignment)); |
| 13788 |
|
| 13789 |
if(vkMemReq.size == 0) |
| 13790 |
{ |
| 13791 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 13792 |
} |
| 13793 |
|
| 13794 |
VmaAllocationCreateInfo createInfoFinal = createInfo; |
| 13795 |
VkResult res = CalcAllocationParams(createInfoFinal, requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 13796 |
if(res != VK_SUCCESS) |
| 13797 |
return res; |
| 13798 |
|
| 13799 |
if(createInfoFinal.pool != VK_NULL_HANDLE) |
| 13800 |
{ |
| 13801 |
VmaBlockVector& blockVector = createInfoFinal.pool->m_BlockVector; |
| 13802 |
return AllocateMemoryOfType( |
| 13803 |
createInfoFinal.pool, |
| 13804 |
vkMemReq.size, |
| 13805 |
vkMemReq.alignment, |
| 13806 |
prefersDedicatedAllocation, |
| 13807 |
dedicatedBuffer, |
| 13808 |
dedicatedImage, |
| 13809 |
dedicatedBufferImageUsage, |
| 13810 |
createInfoFinal, |
| 13811 |
blockVector.GetMemoryTypeIndex(), |
| 13812 |
suballocType, |
| 13813 |
createInfoFinal.pool->m_DedicatedAllocations, |
| 13814 |
blockVector, |
| 13815 |
allocationCount, |
| 13816 |
pAllocations); |
| 13817 |
} |
| 13818 |
else |
| 13819 |
{ |
| 13820 |
|
| 13821 |
uint32_t memoryTypeBits = vkMemReq.memoryTypeBits; |
| 13822 |
uint32_t memTypeIndex = UINT32_MAX; |
| 13823 |
res = FindMemoryTypeIndex(memoryTypeBits, &createInfoFinal, dedicatedBufferImageUsage, &memTypeIndex); |
| 13824 |
|
| 13825 |
if(res != VK_SUCCESS) |
| 13826 |
return res; |
| 13827 |
do |
| 13828 |
{ |
| 13829 |
VmaBlockVector* blockVector = m_pBlockVectors[memTypeIndex]; |
| 13830 |
VMA_ASSERT(blockVector && "Trying to use unsupported memory type!"); |
| 13831 |
res = AllocateMemoryOfType( |
| 13832 |
VK_NULL_HANDLE, |
| 13833 |
vkMemReq.size, |
| 13834 |
vkMemReq.alignment, |
| 13835 |
requiresDedicatedAllocation || prefersDedicatedAllocation, |
| 13836 |
dedicatedBuffer, |
| 13837 |
dedicatedImage, |
| 13838 |
dedicatedBufferImageUsage, |
| 13839 |
createInfoFinal, |
| 13840 |
memTypeIndex, |
| 13841 |
suballocType, |
| 13842 |
m_DedicatedAllocations[memTypeIndex], |
| 13843 |
*blockVector, |
| 13844 |
allocationCount, |
| 13845 |
pAllocations); |
| 13846 |
|
| 13847 |
if(res == VK_SUCCESS) |
| 13848 |
return VK_SUCCESS; |
| 13849 |
|
| 13850 |
|
| 13851 |
memoryTypeBits &= ~(1u << memTypeIndex); |
| 13852 |
|
| 13853 |
res = FindMemoryTypeIndex(memoryTypeBits, &createInfoFinal, dedicatedBufferImageUsage, &memTypeIndex); |
| 13854 |
} while(res == VK_SUCCESS); |
| 13855 |
|
| 13856 |
|
| 13857 |
|
| 13858 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 13859 |
} |
| 13860 |
} |
| 13861 |
|
| 13862 |
void VmaAllocator_T::FreeMemory( |
| 13863 |
size_t allocationCount, |
| 13864 |
const VmaAllocation* pAllocations) |
| 13865 |
{ |
| 13866 |
VMA_ASSERT(pAllocations); |
| 13867 |
|
| 13868 |
for(size_t allocIndex = allocationCount; allocIndex--; ) |
| 13869 |
{ |
| 13870 |
VmaAllocation allocation = pAllocations[allocIndex]; |
| 13871 |
|
| 13872 |
if(allocation != VK_NULL_HANDLE) |
| 13873 |
{ |
| 13874 |
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS) |
| 13875 |
{ |
| 13876 |
FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED); |
| 13877 |
} |
| 13878 |
|
| 13879 |
allocation->FreeName(this); |
| 13880 |
|
| 13881 |
switch(allocation->GetType()) |
| 13882 |
{ |
| 13883 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 13884 |
{ |
| 13885 |
VmaBlockVector* pBlockVector = VMA_NULL; |
| 13886 |
VmaPool hPool = allocation->GetParentPool(); |
| 13887 |
if(hPool != VK_NULL_HANDLE) |
| 13888 |
{ |
| 13889 |
pBlockVector = &hPool->m_BlockVector; |
| 13890 |
} |
| 13891 |
else |
| 13892 |
{ |
| 13893 |
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex(); |
| 13894 |
pBlockVector = m_pBlockVectors[memTypeIndex]; |
| 13895 |
VMA_ASSERT(pBlockVector && "Trying to free memory of unsupported type!"); |
| 13896 |
} |
| 13897 |
pBlockVector->Free(allocation); |
| 13898 |
} |
| 13899 |
break; |
| 13900 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 13901 |
FreeDedicatedMemory(allocation); |
| 13902 |
break; |
| 13903 |
default: |
| 13904 |
VMA_ASSERT(0); |
| 13905 |
} |
| 13906 |
} |
| 13907 |
} |
| 13908 |
} |
| 13909 |
|
| 13910 |
void VmaAllocator_T::CalculateStatistics(VmaTotalStatistics* pStats) |
| 13911 |
{ |
| 13912 |
|
| 13913 |
VmaClearDetailedStatistics(pStats->total); |
| 13914 |
for(uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i) |
| 13915 |
VmaClearDetailedStatistics(pStats->memoryType[i]); |
| 13916 |
for(uint32_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i) |
| 13917 |
VmaClearDetailedStatistics(pStats->memoryHeap[i]); |
| 13918 |
|
| 13919 |
|
| 13920 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 13921 |
{ |
| 13922 |
VmaBlockVector* const pBlockVector = m_pBlockVectors[memTypeIndex]; |
| 13923 |
if (pBlockVector != VMA_NULL) |
| 13924 |
pBlockVector->AddDetailedStatistics(pStats->memoryType[memTypeIndex]); |
| 13925 |
} |
| 13926 |
|
| 13927 |
|
| 13928 |
{ |
| 13929 |
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex); |
| 13930 |
for(VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool)) |
| 13931 |
{ |
| 13932 |
VmaBlockVector& blockVector = pool->m_BlockVector; |
| 13933 |
const uint32_t memTypeIndex = blockVector.GetMemoryTypeIndex(); |
| 13934 |
blockVector.AddDetailedStatistics(pStats->memoryType[memTypeIndex]); |
| 13935 |
pool->m_DedicatedAllocations.AddDetailedStatistics(pStats->memoryType[memTypeIndex]); |
| 13936 |
} |
| 13937 |
} |
| 13938 |
|
| 13939 |
|
| 13940 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 13941 |
{ |
| 13942 |
m_DedicatedAllocations[memTypeIndex].AddDetailedStatistics(pStats->memoryType[memTypeIndex]); |
| 13943 |
} |
| 13944 |
|
| 13945 |
|
| 13946 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 13947 |
{ |
| 13948 |
const uint32_t memHeapIndex = m_MemProps.memoryTypes[memTypeIndex].heapIndex; |
| 13949 |
VmaAddDetailedStatistics(pStats->memoryHeap[memHeapIndex], pStats->memoryType[memTypeIndex]); |
| 13950 |
} |
| 13951 |
|
| 13952 |
|
| 13953 |
for(uint32_t memHeapIndex = 0; memHeapIndex < GetMemoryHeapCount(); ++memHeapIndex) |
| 13954 |
VmaAddDetailedStatistics(pStats->total, pStats->memoryHeap[memHeapIndex]); |
| 13955 |
|
| 13956 |
VMA_ASSERT(pStats->total.statistics.allocationCount == 0 || |
| 13957 |
pStats->total.allocationSizeMax >= pStats->total.allocationSizeMin); |
| 13958 |
VMA_ASSERT(pStats->total.unusedRangeCount == 0 || |
| 13959 |
pStats->total.unusedRangeSizeMax >= pStats->total.unusedRangeSizeMin); |
| 13960 |
} |
| 13961 |
|
| 13962 |
void VmaAllocator_T::GetHeapBudgets(VmaBudget* outBudgets, uint32_t firstHeap, uint32_t heapCount) |
| 13963 |
{ |
| 13964 |
#if VMA_MEMORY_BUDGET |
| 13965 |
if(m_UseExtMemoryBudget) |
| 13966 |
{ |
| 13967 |
if(m_Budget.m_OperationsSinceBudgetFetch < 30) |
| 13968 |
{ |
| 13969 |
VmaMutexLockRead lockRead(m_Budget.m_BudgetMutex, m_UseMutex); |
| 13970 |
for(uint32_t i = 0; i < heapCount; ++i, ++outBudgets) |
| 13971 |
{ |
| 13972 |
const uint32_t heapIndex = firstHeap + i; |
| 13973 |
|
| 13974 |
outBudgets->statistics.blockCount = m_Budget.m_BlockCount[heapIndex]; |
| 13975 |
outBudgets->statistics.allocationCount = m_Budget.m_AllocationCount[heapIndex]; |
| 13976 |
outBudgets->statistics.blockBytes = m_Budget.m_BlockBytes[heapIndex]; |
| 13977 |
outBudgets->statistics.allocationBytes = m_Budget.m_AllocationBytes[heapIndex]; |
| 13978 |
|
| 13979 |
if(m_Budget.m_VulkanUsage[heapIndex] + outBudgets->statistics.blockBytes > m_Budget.m_BlockBytesAtBudgetFetch[heapIndex]) |
| 13980 |
{ |
| 13981 |
outBudgets->usage = m_Budget.m_VulkanUsage[heapIndex] + |
| 13982 |
outBudgets->statistics.blockBytes - m_Budget.m_BlockBytesAtBudgetFetch[heapIndex]; |
| 13983 |
} |
| 13984 |
else |
| 13985 |
{ |
| 13986 |
outBudgets->usage = 0; |
| 13987 |
} |
| 13988 |
|
| 13989 |
|
| 13990 |
outBudgets->budget = VMA_MIN( |
| 13991 |
m_Budget.m_VulkanBudget[heapIndex], m_MemProps.memoryHeaps[heapIndex].size); |
| 13992 |
} |
| 13993 |
} |
| 13994 |
else |
| 13995 |
{ |
| 13996 |
UpdateVulkanBudget(); |
| 13997 |
GetHeapBudgets(outBudgets, firstHeap, heapCount); |
| 13998 |
} |
| 13999 |
} |
| 14000 |
else |
| 14001 |
#endif |
| 14002 |
{ |
| 14003 |
for(uint32_t i = 0; i < heapCount; ++i, ++outBudgets) |
| 14004 |
{ |
| 14005 |
const uint32_t heapIndex = firstHeap + i; |
| 14006 |
|
| 14007 |
outBudgets->statistics.blockCount = m_Budget.m_BlockCount[heapIndex]; |
| 14008 |
outBudgets->statistics.allocationCount = m_Budget.m_AllocationCount[heapIndex]; |
| 14009 |
outBudgets->statistics.blockBytes = m_Budget.m_BlockBytes[heapIndex]; |
| 14010 |
outBudgets->statistics.allocationBytes = m_Budget.m_AllocationBytes[heapIndex]; |
| 14011 |
|
| 14012 |
outBudgets->usage = outBudgets->statistics.blockBytes; |
| 14013 |
outBudgets->budget = m_MemProps.memoryHeaps[heapIndex].size * 8 / 10; |
| 14014 |
} |
| 14015 |
} |
| 14016 |
} |
| 14017 |
|
| 14018 |
void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo) |
| 14019 |
{ |
| 14020 |
pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex(); |
| 14021 |
pAllocationInfo->deviceMemory = hAllocation->GetMemory(); |
| 14022 |
pAllocationInfo->offset = hAllocation->GetOffset(); |
| 14023 |
pAllocationInfo->size = hAllocation->GetSize(); |
| 14024 |
pAllocationInfo->pMappedData = hAllocation->GetMappedData(); |
| 14025 |
pAllocationInfo->pUserData = hAllocation->GetUserData(); |
| 14026 |
pAllocationInfo->pName = hAllocation->GetName(); |
| 14027 |
} |
| 14028 |
|
| 14029 |
void VmaAllocator_T::GetAllocationInfo2(VmaAllocation hAllocation, VmaAllocationInfo2* pAllocationInfo) |
| 14030 |
{ |
| 14031 |
GetAllocationInfo(hAllocation, &pAllocationInfo->allocationInfo); |
| 14032 |
|
| 14033 |
switch (hAllocation->GetType()) |
| 14034 |
{ |
| 14035 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14036 |
pAllocationInfo->blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize(); |
| 14037 |
pAllocationInfo->dedicatedMemory = VK_FALSE; |
| 14038 |
break; |
| 14039 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14040 |
pAllocationInfo->blockSize = pAllocationInfo->allocationInfo.size; |
| 14041 |
pAllocationInfo->dedicatedMemory = VK_TRUE; |
| 14042 |
break; |
| 14043 |
default: |
| 14044 |
VMA_ASSERT(0); |
| 14045 |
} |
| 14046 |
} |
| 14047 |
|
| 14048 |
VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPool* pPool) |
| 14049 |
{ |
| 14050 |
VMA_DEBUG_LOG_FORMAT(" CreatePool: MemoryTypeIndex=%" PRIu32 ", flags=%" PRIu32, pCreateInfo->memoryTypeIndex, pCreateInfo->flags); |
| 14051 |
|
| 14052 |
VmaPoolCreateInfo newCreateInfo = *pCreateInfo; |
| 14053 |
|
| 14054 |
|
| 14055 |
if(pCreateInfo->pMemoryAllocateNext) |
| 14056 |
{ |
| 14057 |
VMA_ASSERT(((const VkBaseInStructure*)pCreateInfo->pMemoryAllocateNext)->sType != 0); |
| 14058 |
} |
| 14059 |
|
| 14060 |
if(newCreateInfo.maxBlockCount == 0) |
| 14061 |
{ |
| 14062 |
newCreateInfo.maxBlockCount = SIZE_MAX; |
| 14063 |
} |
| 14064 |
if(newCreateInfo.minBlockCount > newCreateInfo.maxBlockCount) |
| 14065 |
{ |
| 14066 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 14067 |
} |
| 14068 |
|
| 14069 |
if(pCreateInfo->memoryTypeIndex >= GetMemoryTypeCount() || |
| 14070 |
((1u << pCreateInfo->memoryTypeIndex) & m_GlobalMemoryTypeBits) == 0) |
| 14071 |
{ |
| 14072 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 14073 |
} |
| 14074 |
if(newCreateInfo.minAllocationAlignment > 0) |
| 14075 |
{ |
| 14076 |
VMA_ASSERT(VmaIsPow2(newCreateInfo.minAllocationAlignment)); |
| 14077 |
} |
| 14078 |
|
| 14079 |
const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(newCreateInfo.memoryTypeIndex); |
| 14080 |
|
| 14081 |
*pPool = vma_new(this, VmaPool_T)(this, newCreateInfo, preferredBlockSize); |
| 14082 |
|
| 14083 |
VkResult res = (*pPool)->m_BlockVector.CreateMinBlocks(); |
| 14084 |
if(res != VK_SUCCESS) |
| 14085 |
{ |
| 14086 |
vma_delete(this, *pPool); |
| 14087 |
*pPool = VMA_NULL; |
| 14088 |
return res; |
| 14089 |
} |
| 14090 |
|
| 14091 |
|
| 14092 |
{ |
| 14093 |
VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex); |
| 14094 |
(*pPool)->SetId(m_NextPoolId++); |
| 14095 |
m_Pools.PushBack(*pPool); |
| 14096 |
} |
| 14097 |
|
| 14098 |
return VK_SUCCESS; |
| 14099 |
} |
| 14100 |
|
| 14101 |
void VmaAllocator_T::DestroyPool(VmaPool pool) |
| 14102 |
{ |
| 14103 |
|
| 14104 |
{ |
| 14105 |
VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex); |
| 14106 |
m_Pools.Remove(pool); |
| 14107 |
} |
| 14108 |
|
| 14109 |
vma_delete(this, pool); |
| 14110 |
} |
| 14111 |
|
| 14112 |
void VmaAllocator_T::GetPoolStatistics(VmaPool pool, VmaStatistics* pPoolStats) |
| 14113 |
{ |
| 14114 |
VmaClearStatistics(*pPoolStats); |
| 14115 |
pool->m_BlockVector.AddStatistics(*pPoolStats); |
| 14116 |
pool->m_DedicatedAllocations.AddStatistics(*pPoolStats); |
| 14117 |
} |
| 14118 |
|
| 14119 |
void VmaAllocator_T::CalculatePoolStatistics(VmaPool pool, VmaDetailedStatistics* pPoolStats) |
| 14120 |
{ |
| 14121 |
VmaClearDetailedStatistics(*pPoolStats); |
| 14122 |
pool->m_BlockVector.AddDetailedStatistics(*pPoolStats); |
| 14123 |
pool->m_DedicatedAllocations.AddDetailedStatistics(*pPoolStats); |
| 14124 |
} |
| 14125 |
|
| 14126 |
void VmaAllocator_T::SetCurrentFrameIndex(uint32_t frameIndex) |
| 14127 |
{ |
| 14128 |
m_CurrentFrameIndex.store(frameIndex); |
| 14129 |
|
| 14130 |
#if VMA_MEMORY_BUDGET |
| 14131 |
if(m_UseExtMemoryBudget) |
| 14132 |
{ |
| 14133 |
UpdateVulkanBudget(); |
| 14134 |
} |
| 14135 |
#endif |
| 14136 |
} |
| 14137 |
|
| 14138 |
VkResult VmaAllocator_T::CheckPoolCorruption(VmaPool hPool) |
| 14139 |
{ |
| 14140 |
return hPool->m_BlockVector.CheckCorruption(); |
| 14141 |
} |
| 14142 |
|
| 14143 |
VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits) |
| 14144 |
{ |
| 14145 |
VkResult finalRes = VK_ERROR_FEATURE_NOT_PRESENT; |
| 14146 |
|
| 14147 |
|
| 14148 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 14149 |
{ |
| 14150 |
VmaBlockVector* const pBlockVector = m_pBlockVectors[memTypeIndex]; |
| 14151 |
if(pBlockVector != VMA_NULL) |
| 14152 |
{ |
| 14153 |
VkResult localRes = pBlockVector->CheckCorruption(); |
| 14154 |
switch(localRes) |
| 14155 |
{ |
| 14156 |
case VK_ERROR_FEATURE_NOT_PRESENT: |
| 14157 |
break; |
| 14158 |
case VK_SUCCESS: |
| 14159 |
finalRes = VK_SUCCESS; |
| 14160 |
break; |
| 14161 |
default: |
| 14162 |
return localRes; |
| 14163 |
} |
| 14164 |
} |
| 14165 |
} |
| 14166 |
|
| 14167 |
|
| 14168 |
{ |
| 14169 |
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex); |
| 14170 |
for(VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool)) |
| 14171 |
{ |
| 14172 |
if(((1u << pool->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0) |
| 14173 |
{ |
| 14174 |
VkResult localRes = pool->m_BlockVector.CheckCorruption(); |
| 14175 |
switch(localRes) |
| 14176 |
{ |
| 14177 |
case VK_ERROR_FEATURE_NOT_PRESENT: |
| 14178 |
break; |
| 14179 |
case VK_SUCCESS: |
| 14180 |
finalRes = VK_SUCCESS; |
| 14181 |
break; |
| 14182 |
default: |
| 14183 |
return localRes; |
| 14184 |
} |
| 14185 |
} |
| 14186 |
} |
| 14187 |
} |
| 14188 |
|
| 14189 |
return finalRes; |
| 14190 |
} |
| 14191 |
|
| 14192 |
VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory) |
| 14193 |
{ |
| 14194 |
AtomicTransactionalIncrement<VMA_ATOMIC_UINT32> deviceMemoryCountIncrement; |
| 14195 |
const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount); |
| 14196 |
#if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT |
| 14197 |
if(prevDeviceMemoryCount >= m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount) |
| 14198 |
{ |
| 14199 |
return VK_ERROR_TOO_MANY_OBJECTS; |
| 14200 |
} |
| 14201 |
#endif |
| 14202 |
|
| 14203 |
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex); |
| 14204 |
|
| 14205 |
|
| 14206 |
if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0) |
| 14207 |
{ |
| 14208 |
const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size; |
| 14209 |
VkDeviceSize blockBytes = m_Budget.m_BlockBytes[heapIndex]; |
| 14210 |
for(;;) |
| 14211 |
{ |
| 14212 |
const VkDeviceSize blockBytesAfterAllocation = blockBytes + pAllocateInfo->allocationSize; |
| 14213 |
if(blockBytesAfterAllocation > heapSize) |
| 14214 |
{ |
| 14215 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 14216 |
} |
| 14217 |
if(m_Budget.m_BlockBytes[heapIndex].compare_exchange_strong(blockBytes, blockBytesAfterAllocation)) |
| 14218 |
{ |
| 14219 |
break; |
| 14220 |
} |
| 14221 |
} |
| 14222 |
} |
| 14223 |
else |
| 14224 |
{ |
| 14225 |
m_Budget.m_BlockBytes[heapIndex] += pAllocateInfo->allocationSize; |
| 14226 |
} |
| 14227 |
++m_Budget.m_BlockCount[heapIndex]; |
| 14228 |
|
| 14229 |
|
| 14230 |
VkResult res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory); |
| 14231 |
|
| 14232 |
if(res == VK_SUCCESS) |
| 14233 |
{ |
| 14234 |
#if VMA_MEMORY_BUDGET |
| 14235 |
++m_Budget.m_OperationsSinceBudgetFetch; |
| 14236 |
#endif |
| 14237 |
|
| 14238 |
|
| 14239 |
if(m_DeviceMemoryCallbacks.pfnAllocate != VMA_NULL) |
| 14240 |
{ |
| 14241 |
(*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize, m_DeviceMemoryCallbacks.pUserData); |
| 14242 |
} |
| 14243 |
|
| 14244 |
deviceMemoryCountIncrement.Commit(); |
| 14245 |
} |
| 14246 |
else |
| 14247 |
{ |
| 14248 |
--m_Budget.m_BlockCount[heapIndex]; |
| 14249 |
m_Budget.m_BlockBytes[heapIndex] -= pAllocateInfo->allocationSize; |
| 14250 |
} |
| 14251 |
|
| 14252 |
return res; |
| 14253 |
} |
| 14254 |
|
| 14255 |
void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory) |
| 14256 |
{ |
| 14257 |
|
| 14258 |
if(m_DeviceMemoryCallbacks.pfnFree != VMA_NULL) |
| 14259 |
{ |
| 14260 |
(*m_DeviceMemoryCallbacks.pfnFree)(this, memoryType, hMemory, size, m_DeviceMemoryCallbacks.pUserData); |
| 14261 |
} |
| 14262 |
|
| 14263 |
|
| 14264 |
(*m_VulkanFunctions.vkFreeMemory)(m_hDevice, hMemory, GetAllocationCallbacks()); |
| 14265 |
|
| 14266 |
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memoryType); |
| 14267 |
--m_Budget.m_BlockCount[heapIndex]; |
| 14268 |
m_Budget.m_BlockBytes[heapIndex] -= size; |
| 14269 |
|
| 14270 |
--m_DeviceMemoryCount; |
| 14271 |
} |
| 14272 |
|
| 14273 |
VkResult VmaAllocator_T::BindVulkanBuffer( |
| 14274 |
VkDeviceMemory memory, |
| 14275 |
VkDeviceSize memoryOffset, |
| 14276 |
VkBuffer buffer, |
| 14277 |
const void* pNext) |
| 14278 |
{ |
| 14279 |
if(pNext != VMA_NULL) |
| 14280 |
{ |
| 14281 |
#if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2 |
| 14282 |
if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) && |
| 14283 |
m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL) |
| 14284 |
{ |
| 14285 |
VkBindBufferMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR }; |
| 14286 |
bindBufferMemoryInfo.pNext = pNext; |
| 14287 |
bindBufferMemoryInfo.buffer = buffer; |
| 14288 |
bindBufferMemoryInfo.memory = memory; |
| 14289 |
bindBufferMemoryInfo.memoryOffset = memoryOffset; |
| 14290 |
return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo); |
| 14291 |
} |
| 14292 |
else |
| 14293 |
#endif |
| 14294 |
{ |
| 14295 |
return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 14296 |
} |
| 14297 |
} |
| 14298 |
else |
| 14299 |
{ |
| 14300 |
return (*m_VulkanFunctions.vkBindBufferMemory)(m_hDevice, buffer, memory, memoryOffset); |
| 14301 |
} |
| 14302 |
} |
| 14303 |
|
| 14304 |
VkResult VmaAllocator_T::BindVulkanImage( |
| 14305 |
VkDeviceMemory memory, |
| 14306 |
VkDeviceSize memoryOffset, |
| 14307 |
VkImage image, |
| 14308 |
const void* pNext) |
| 14309 |
{ |
| 14310 |
if(pNext != VMA_NULL) |
| 14311 |
{ |
| 14312 |
#if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2 |
| 14313 |
if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) && |
| 14314 |
m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL) |
| 14315 |
{ |
| 14316 |
VkBindImageMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR }; |
| 14317 |
bindBufferMemoryInfo.pNext = pNext; |
| 14318 |
bindBufferMemoryInfo.image = image; |
| 14319 |
bindBufferMemoryInfo.memory = memory; |
| 14320 |
bindBufferMemoryInfo.memoryOffset = memoryOffset; |
| 14321 |
return (*m_VulkanFunctions.vkBindImageMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo); |
| 14322 |
} |
| 14323 |
else |
| 14324 |
#endif |
| 14325 |
{ |
| 14326 |
return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 14327 |
} |
| 14328 |
} |
| 14329 |
else |
| 14330 |
{ |
| 14331 |
return (*m_VulkanFunctions.vkBindImageMemory)(m_hDevice, image, memory, memoryOffset); |
| 14332 |
} |
| 14333 |
} |
| 14334 |
|
| 14335 |
VkResult VmaAllocator_T::Map(VmaAllocation hAllocation, void** ppData) |
| 14336 |
{ |
| 14337 |
switch(hAllocation->GetType()) |
| 14338 |
{ |
| 14339 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14340 |
{ |
| 14341 |
VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock(); |
| 14342 |
char *pBytes = VMA_NULL; |
| 14343 |
VkResult res = pBlock->Map(this, 1, (void**)&pBytes); |
| 14344 |
if(res == VK_SUCCESS) |
| 14345 |
{ |
| 14346 |
*ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset(); |
| 14347 |
hAllocation->BlockAllocMap(); |
| 14348 |
} |
| 14349 |
return res; |
| 14350 |
} |
| 14351 |
VMA_FALLTHROUGH; |
| 14352 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14353 |
return hAllocation->DedicatedAllocMap(this, ppData); |
| 14354 |
default: |
| 14355 |
VMA_ASSERT(0); |
| 14356 |
return VK_ERROR_MEMORY_MAP_FAILED; |
| 14357 |
} |
| 14358 |
} |
| 14359 |
|
| 14360 |
void VmaAllocator_T::Unmap(VmaAllocation hAllocation) |
| 14361 |
{ |
| 14362 |
switch(hAllocation->GetType()) |
| 14363 |
{ |
| 14364 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14365 |
{ |
| 14366 |
VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock(); |
| 14367 |
hAllocation->BlockAllocUnmap(); |
| 14368 |
pBlock->Unmap(this, 1); |
| 14369 |
} |
| 14370 |
break; |
| 14371 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14372 |
hAllocation->DedicatedAllocUnmap(this); |
| 14373 |
break; |
| 14374 |
default: |
| 14375 |
VMA_ASSERT(0); |
| 14376 |
} |
| 14377 |
} |
| 14378 |
|
| 14379 |
VkResult VmaAllocator_T::BindBufferMemory( |
| 14380 |
VmaAllocation hAllocation, |
| 14381 |
VkDeviceSize allocationLocalOffset, |
| 14382 |
VkBuffer hBuffer, |
| 14383 |
const void* pNext) |
| 14384 |
{ |
| 14385 |
VkResult res = VK_ERROR_UNKNOWN_COPY; |
| 14386 |
switch(hAllocation->GetType()) |
| 14387 |
{ |
| 14388 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14389 |
res = BindVulkanBuffer(hAllocation->GetMemory(), allocationLocalOffset, hBuffer, pNext); |
| 14390 |
break; |
| 14391 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14392 |
{ |
| 14393 |
VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock(); |
| 14394 |
VMA_ASSERT(pBlock && "Binding buffer to allocation that doesn't belong to any block."); |
| 14395 |
res = pBlock->BindBufferMemory(this, hAllocation, allocationLocalOffset, hBuffer, pNext); |
| 14396 |
break; |
| 14397 |
} |
| 14398 |
default: |
| 14399 |
VMA_ASSERT(0); |
| 14400 |
} |
| 14401 |
return res; |
| 14402 |
} |
| 14403 |
|
| 14404 |
VkResult VmaAllocator_T::BindImageMemory( |
| 14405 |
VmaAllocation hAllocation, |
| 14406 |
VkDeviceSize allocationLocalOffset, |
| 14407 |
VkImage hImage, |
| 14408 |
const void* pNext) |
| 14409 |
{ |
| 14410 |
VkResult res = VK_ERROR_UNKNOWN_COPY; |
| 14411 |
switch(hAllocation->GetType()) |
| 14412 |
{ |
| 14413 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14414 |
res = BindVulkanImage(hAllocation->GetMemory(), allocationLocalOffset, hImage, pNext); |
| 14415 |
break; |
| 14416 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14417 |
{ |
| 14418 |
VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock(); |
| 14419 |
VMA_ASSERT(pBlock && "Binding image to allocation that doesn't belong to any block."); |
| 14420 |
res = pBlock->BindImageMemory(this, hAllocation, allocationLocalOffset, hImage, pNext); |
| 14421 |
break; |
| 14422 |
} |
| 14423 |
default: |
| 14424 |
VMA_ASSERT(0); |
| 14425 |
} |
| 14426 |
return res; |
| 14427 |
} |
| 14428 |
|
| 14429 |
VkResult VmaAllocator_T::FlushOrInvalidateAllocation( |
| 14430 |
VmaAllocation hAllocation, |
| 14431 |
VkDeviceSize offset, VkDeviceSize size, |
| 14432 |
VMA_CACHE_OPERATION op) |
| 14433 |
{ |
| 14434 |
VkResult res = VK_SUCCESS; |
| 14435 |
|
| 14436 |
VkMappedMemoryRange memRange = {}; |
| 14437 |
if(GetFlushOrInvalidateRange(hAllocation, offset, size, memRange)) |
| 14438 |
{ |
| 14439 |
switch(op) |
| 14440 |
{ |
| 14441 |
case VMA_CACHE_FLUSH: |
| 14442 |
res = (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, 1, &memRange); |
| 14443 |
break; |
| 14444 |
case VMA_CACHE_INVALIDATE: |
| 14445 |
res = (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, 1, &memRange); |
| 14446 |
break; |
| 14447 |
default: |
| 14448 |
VMA_ASSERT(0); |
| 14449 |
} |
| 14450 |
} |
| 14451 |
|
| 14452 |
return res; |
| 14453 |
} |
| 14454 |
|
| 14455 |
VkResult VmaAllocator_T::FlushOrInvalidateAllocations( |
| 14456 |
uint32_t allocationCount, |
| 14457 |
const VmaAllocation* allocations, |
| 14458 |
const VkDeviceSize* offsets, const VkDeviceSize* sizes, |
| 14459 |
VMA_CACHE_OPERATION op) |
| 14460 |
{ |
| 14461 |
typedef VmaStlAllocator<VkMappedMemoryRange> RangeAllocator; |
| 14462 |
typedef VmaSmallVector<VkMappedMemoryRange, RangeAllocator, 16> RangeVector; |
| 14463 |
RangeVector ranges = RangeVector(RangeAllocator(GetAllocationCallbacks())); |
| 14464 |
|
| 14465 |
for(uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex) |
| 14466 |
{ |
| 14467 |
const VmaAllocation alloc = allocations[allocIndex]; |
| 14468 |
const VkDeviceSize offset = offsets != VMA_NULL ? offsets[allocIndex] : 0; |
| 14469 |
const VkDeviceSize size = sizes != VMA_NULL ? sizes[allocIndex] : VK_WHOLE_SIZE; |
| 14470 |
VkMappedMemoryRange newRange; |
| 14471 |
if(GetFlushOrInvalidateRange(alloc, offset, size, newRange)) |
| 14472 |
{ |
| 14473 |
ranges.push_back(newRange); |
| 14474 |
} |
| 14475 |
} |
| 14476 |
|
| 14477 |
VkResult res = VK_SUCCESS; |
| 14478 |
if(!ranges.empty()) |
| 14479 |
{ |
| 14480 |
switch(op) |
| 14481 |
{ |
| 14482 |
case VMA_CACHE_FLUSH: |
| 14483 |
res = (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, (uint32_t)ranges.size(), ranges.data()); |
| 14484 |
break; |
| 14485 |
case VMA_CACHE_INVALIDATE: |
| 14486 |
res = (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, (uint32_t)ranges.size(), ranges.data()); |
| 14487 |
break; |
| 14488 |
default: |
| 14489 |
VMA_ASSERT(0); |
| 14490 |
} |
| 14491 |
} |
| 14492 |
|
| 14493 |
return res; |
| 14494 |
} |
| 14495 |
|
| 14496 |
VkResult VmaAllocator_T::CopyMemoryToAllocation( |
| 14497 |
const void* pSrcHostPointer, |
| 14498 |
VmaAllocation dstAllocation, |
| 14499 |
VkDeviceSize dstAllocationLocalOffset, |
| 14500 |
VkDeviceSize size) |
| 14501 |
{ |
| 14502 |
void* dstMappedData = VMA_NULL; |
| 14503 |
VkResult res = Map(dstAllocation, &dstMappedData); |
| 14504 |
if(res == VK_SUCCESS) |
| 14505 |
{ |
| 14506 |
memcpy((char*)dstMappedData + dstAllocationLocalOffset, pSrcHostPointer, (size_t)size); |
| 14507 |
Unmap(dstAllocation); |
| 14508 |
res = FlushOrInvalidateAllocation(dstAllocation, dstAllocationLocalOffset, size, VMA_CACHE_FLUSH); |
| 14509 |
} |
| 14510 |
return res; |
| 14511 |
} |
| 14512 |
|
| 14513 |
VkResult VmaAllocator_T::CopyAllocationToMemory( |
| 14514 |
VmaAllocation srcAllocation, |
| 14515 |
VkDeviceSize srcAllocationLocalOffset, |
| 14516 |
void* pDstHostPointer, |
| 14517 |
VkDeviceSize size) |
| 14518 |
{ |
| 14519 |
void* srcMappedData = VMA_NULL; |
| 14520 |
VkResult res = Map(srcAllocation, &srcMappedData); |
| 14521 |
if(res == VK_SUCCESS) |
| 14522 |
{ |
| 14523 |
res = FlushOrInvalidateAllocation(srcAllocation, srcAllocationLocalOffset, size, VMA_CACHE_INVALIDATE); |
| 14524 |
if(res == VK_SUCCESS) |
| 14525 |
{ |
| 14526 |
memcpy(pDstHostPointer, (const char*)srcMappedData + srcAllocationLocalOffset, (size_t)size); |
| 14527 |
Unmap(srcAllocation); |
| 14528 |
} |
| 14529 |
} |
| 14530 |
return res; |
| 14531 |
} |
| 14532 |
|
| 14533 |
void VmaAllocator_T::FreeDedicatedMemory(const VmaAllocation allocation) |
| 14534 |
{ |
| 14535 |
VMA_ASSERT(allocation && allocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED); |
| 14536 |
|
| 14537 |
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex(); |
| 14538 |
VmaPool parentPool = allocation->GetParentPool(); |
| 14539 |
if(parentPool == VK_NULL_HANDLE) |
| 14540 |
{ |
| 14541 |
|
| 14542 |
m_DedicatedAllocations[memTypeIndex].Unregister(allocation); |
| 14543 |
} |
| 14544 |
else |
| 14545 |
{ |
| 14546 |
|
| 14547 |
parentPool->m_DedicatedAllocations.Unregister(allocation); |
| 14548 |
} |
| 14549 |
|
| 14550 |
VkDeviceMemory hMemory = allocation->GetMemory(); |
| 14551 |
|
| 14552 |
|
| 14553 |
|
| 14554 |
|
| 14555 |
|
| 14556 |
|
| 14557 |
|
| 14558 |
|
| 14559 |
|
| 14560 |
|
| 14561 |
|
| 14562 |
FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory); |
| 14563 |
|
| 14564 |
m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(allocation->GetMemoryTypeIndex()), allocation->GetSize()); |
| 14565 |
m_AllocationObjectAllocator.Free(allocation); |
| 14566 |
|
| 14567 |
VMA_DEBUG_LOG_FORMAT(" Freed DedicatedMemory MemoryTypeIndex=%" PRIu32, memTypeIndex); |
| 14568 |
} |
| 14569 |
|
| 14570 |
uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits() const |
| 14571 |
{ |
| 14572 |
VkBufferCreateInfo dummyBufCreateInfo; |
| 14573 |
VmaFillGpuDefragmentationBufferCreateInfo(dummyBufCreateInfo); |
| 14574 |
|
| 14575 |
uint32_t memoryTypeBits = 0; |
| 14576 |
|
| 14577 |
|
| 14578 |
VkBuffer buf = VK_NULL_HANDLE; |
| 14579 |
VkResult res = (*GetVulkanFunctions().vkCreateBuffer)( |
| 14580 |
m_hDevice, &dummyBufCreateInfo, GetAllocationCallbacks(), &buf); |
| 14581 |
if(res == VK_SUCCESS) |
| 14582 |
{ |
| 14583 |
|
| 14584 |
VkMemoryRequirements memReq; |
| 14585 |
(*GetVulkanFunctions().vkGetBufferMemoryRequirements)(m_hDevice, buf, &memReq); |
| 14586 |
memoryTypeBits = memReq.memoryTypeBits; |
| 14587 |
|
| 14588 |
|
| 14589 |
(*GetVulkanFunctions().vkDestroyBuffer)(m_hDevice, buf, GetAllocationCallbacks()); |
| 14590 |
} |
| 14591 |
|
| 14592 |
return memoryTypeBits; |
| 14593 |
} |
| 14594 |
|
| 14595 |
uint32_t VmaAllocator_T::CalculateGlobalMemoryTypeBits() const |
| 14596 |
{ |
| 14597 |
|
| 14598 |
VMA_ASSERT(GetMemoryTypeCount() > 0); |
| 14599 |
|
| 14600 |
uint32_t memoryTypeBits = UINT32_MAX; |
| 14601 |
|
| 14602 |
if(!m_UseAmdDeviceCoherentMemory) |
| 14603 |
{ |
| 14604 |
|
| 14605 |
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 14606 |
{ |
| 14607 |
if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY) != 0) |
| 14608 |
{ |
| 14609 |
memoryTypeBits &= ~(1u << memTypeIndex); |
| 14610 |
} |
| 14611 |
} |
| 14612 |
} |
| 14613 |
|
| 14614 |
return memoryTypeBits; |
| 14615 |
} |
| 14616 |
|
| 14617 |
bool VmaAllocator_T::GetFlushOrInvalidateRange( |
| 14618 |
VmaAllocation allocation, |
| 14619 |
VkDeviceSize offset, VkDeviceSize size, |
| 14620 |
VkMappedMemoryRange& outRange) const |
| 14621 |
{ |
| 14622 |
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex(); |
| 14623 |
if(size > 0 && IsMemoryTypeNonCoherent(memTypeIndex)) |
| 14624 |
{ |
| 14625 |
const VkDeviceSize nonCoherentAtomSize = m_PhysicalDeviceProperties.limits.nonCoherentAtomSize; |
| 14626 |
const VkDeviceSize allocationSize = allocation->GetSize(); |
| 14627 |
VMA_ASSERT(offset <= allocationSize); |
| 14628 |
|
| 14629 |
outRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
| 14630 |
outRange.pNext = VMA_NULL; |
| 14631 |
outRange.memory = allocation->GetMemory(); |
| 14632 |
|
| 14633 |
switch(allocation->GetType()) |
| 14634 |
{ |
| 14635 |
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: |
| 14636 |
outRange.offset = VmaAlignDown(offset, nonCoherentAtomSize); |
| 14637 |
if(size == VK_WHOLE_SIZE) |
| 14638 |
{ |
| 14639 |
outRange.size = allocationSize - outRange.offset; |
| 14640 |
} |
| 14641 |
else |
| 14642 |
{ |
| 14643 |
VMA_ASSERT(offset + size <= allocationSize); |
| 14644 |
outRange.size = VMA_MIN( |
| 14645 |
VmaAlignUp(size + (offset - outRange.offset), nonCoherentAtomSize), |
| 14646 |
allocationSize - outRange.offset); |
| 14647 |
} |
| 14648 |
break; |
| 14649 |
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: |
| 14650 |
{ |
| 14651 |
|
| 14652 |
outRange.offset = VmaAlignDown(offset, nonCoherentAtomSize); |
| 14653 |
if(size == VK_WHOLE_SIZE) |
| 14654 |
{ |
| 14655 |
size = allocationSize - offset; |
| 14656 |
} |
| 14657 |
else |
| 14658 |
{ |
| 14659 |
VMA_ASSERT(offset + size <= allocationSize); |
| 14660 |
} |
| 14661 |
outRange.size = VmaAlignUp(size + (offset - outRange.offset), nonCoherentAtomSize); |
| 14662 |
|
| 14663 |
|
| 14664 |
const VkDeviceSize allocationOffset = allocation->GetOffset(); |
| 14665 |
VMA_ASSERT(allocationOffset % nonCoherentAtomSize == 0); |
| 14666 |
const VkDeviceSize blockSize = allocation->GetBlock()->m_pMetadata->GetSize(); |
| 14667 |
outRange.offset += allocationOffset; |
| 14668 |
outRange.size = VMA_MIN(outRange.size, blockSize - outRange.offset); |
| 14669 |
|
| 14670 |
break; |
| 14671 |
} |
| 14672 |
default: |
| 14673 |
VMA_ASSERT(0); |
| 14674 |
} |
| 14675 |
return true; |
| 14676 |
} |
| 14677 |
return false; |
| 14678 |
} |
| 14679 |
|
| 14680 |
#if VMA_MEMORY_BUDGET |
| 14681 |
void VmaAllocator_T::UpdateVulkanBudget() |
| 14682 |
{ |
| 14683 |
VMA_ASSERT(m_UseExtMemoryBudget); |
| 14684 |
|
| 14685 |
VkPhysicalDeviceMemoryProperties2KHR memProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR }; |
| 14686 |
|
| 14687 |
VkPhysicalDeviceMemoryBudgetPropertiesEXT budgetProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT }; |
| 14688 |
VmaPnextChainPushFront(&memProps, &budgetProps); |
| 14689 |
|
| 14690 |
GetVulkanFunctions().vkGetPhysicalDeviceMemoryProperties2KHR(m_PhysicalDevice, &memProps); |
| 14691 |
|
| 14692 |
{ |
| 14693 |
VmaMutexLockWrite lockWrite(m_Budget.m_BudgetMutex, m_UseMutex); |
| 14694 |
|
| 14695 |
for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex) |
| 14696 |
{ |
| 14697 |
m_Budget.m_VulkanUsage[heapIndex] = budgetProps.heapUsage[heapIndex]; |
| 14698 |
m_Budget.m_VulkanBudget[heapIndex] = budgetProps.heapBudget[heapIndex]; |
| 14699 |
m_Budget.m_BlockBytesAtBudgetFetch[heapIndex] = m_Budget.m_BlockBytes[heapIndex].load(); |
| 14700 |
|
| 14701 |
|
| 14702 |
if(m_Budget.m_VulkanBudget[heapIndex] == 0) |
| 14703 |
{ |
| 14704 |
m_Budget.m_VulkanBudget[heapIndex] = m_MemProps.memoryHeaps[heapIndex].size * 8 / 10; |
| 14705 |
} |
| 14706 |
else if(m_Budget.m_VulkanBudget[heapIndex] > m_MemProps.memoryHeaps[heapIndex].size) |
| 14707 |
{ |
| 14708 |
m_Budget.m_VulkanBudget[heapIndex] = m_MemProps.memoryHeaps[heapIndex].size; |
| 14709 |
} |
| 14710 |
if(m_Budget.m_VulkanUsage[heapIndex] == 0 && m_Budget.m_BlockBytesAtBudgetFetch[heapIndex] > 0) |
| 14711 |
{ |
| 14712 |
m_Budget.m_VulkanUsage[heapIndex] = m_Budget.m_BlockBytesAtBudgetFetch[heapIndex]; |
| 14713 |
} |
| 14714 |
} |
| 14715 |
m_Budget.m_OperationsSinceBudgetFetch = 0; |
| 14716 |
} |
| 14717 |
} |
| 14718 |
#endif |
| 14719 |
|
| 14720 |
void VmaAllocator_T::FillAllocation(const VmaAllocation hAllocation, uint8_t pattern) |
| 14721 |
{ |
| 14722 |
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS && |
| 14723 |
hAllocation->IsMappingAllowed() && |
| 14724 |
(m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) |
| 14725 |
{ |
| 14726 |
void* pData = VMA_NULL; |
| 14727 |
VkResult res = Map(hAllocation, &pData); |
| 14728 |
if(res == VK_SUCCESS) |
| 14729 |
{ |
| 14730 |
memset(pData, (int)pattern, (size_t)hAllocation->GetSize()); |
| 14731 |
FlushOrInvalidateAllocation(hAllocation, 0, VK_WHOLE_SIZE, VMA_CACHE_FLUSH); |
| 14732 |
Unmap(hAllocation); |
| 14733 |
} |
| 14734 |
else |
| 14735 |
{ |
| 14736 |
VMA_ASSERT(0 && "VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation."); |
| 14737 |
} |
| 14738 |
} |
| 14739 |
} |
| 14740 |
|
| 14741 |
uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits() |
| 14742 |
{ |
| 14743 |
uint32_t memoryTypeBits = m_GpuDefragmentationMemoryTypeBits.load(); |
| 14744 |
if(memoryTypeBits == UINT32_MAX) |
| 14745 |
{ |
| 14746 |
memoryTypeBits = CalculateGpuDefragmentationMemoryTypeBits(); |
| 14747 |
m_GpuDefragmentationMemoryTypeBits.store(memoryTypeBits); |
| 14748 |
} |
| 14749 |
return memoryTypeBits; |
| 14750 |
} |
| 14751 |
|
| 14752 |
#if VMA_STATS_STRING_ENABLED |
| 14753 |
void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json) |
| 14754 |
{ |
| 14755 |
json.WriteString("DefaultPools"); |
| 14756 |
json.BeginObject(); |
| 14757 |
{ |
| 14758 |
for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 14759 |
{ |
| 14760 |
VmaBlockVector* pBlockVector = m_pBlockVectors[memTypeIndex]; |
| 14761 |
VmaDedicatedAllocationList& dedicatedAllocList = m_DedicatedAllocations[memTypeIndex]; |
| 14762 |
if (pBlockVector != VMA_NULL) |
| 14763 |
{ |
| 14764 |
json.BeginString("Type "); |
| 14765 |
json.ContinueString(memTypeIndex); |
| 14766 |
json.EndString(); |
| 14767 |
json.BeginObject(); |
| 14768 |
{ |
| 14769 |
json.WriteString("PreferredBlockSize"); |
| 14770 |
json.WriteNumber(pBlockVector->GetPreferredBlockSize()); |
| 14771 |
|
| 14772 |
json.WriteString("Blocks"); |
| 14773 |
pBlockVector->PrintDetailedMap(json); |
| 14774 |
|
| 14775 |
json.WriteString("DedicatedAllocations"); |
| 14776 |
dedicatedAllocList.BuildStatsString(json); |
| 14777 |
} |
| 14778 |
json.EndObject(); |
| 14779 |
} |
| 14780 |
} |
| 14781 |
} |
| 14782 |
json.EndObject(); |
| 14783 |
|
| 14784 |
json.WriteString("CustomPools"); |
| 14785 |
json.BeginObject(); |
| 14786 |
{ |
| 14787 |
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex); |
| 14788 |
if (!m_Pools.IsEmpty()) |
| 14789 |
{ |
| 14790 |
for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) |
| 14791 |
{ |
| 14792 |
bool displayType = true; |
| 14793 |
size_t index = 0; |
| 14794 |
for (VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool)) |
| 14795 |
{ |
| 14796 |
VmaBlockVector& blockVector = pool->m_BlockVector; |
| 14797 |
if (blockVector.GetMemoryTypeIndex() == memTypeIndex) |
| 14798 |
{ |
| 14799 |
if (displayType) |
| 14800 |
{ |
| 14801 |
json.BeginString("Type "); |
| 14802 |
json.ContinueString(memTypeIndex); |
| 14803 |
json.EndString(); |
| 14804 |
json.BeginArray(); |
| 14805 |
displayType = false; |
| 14806 |
} |
| 14807 |
|
| 14808 |
json.BeginObject(); |
| 14809 |
{ |
| 14810 |
json.WriteString("Name"); |
| 14811 |
json.BeginString(); |
| 14812 |
json.ContinueString((uint64_t)index++); |
| 14813 |
if (pool->GetName()) |
| 14814 |
{ |
| 14815 |
json.ContinueString(" - "); |
| 14816 |
json.ContinueString(pool->GetName()); |
| 14817 |
} |
| 14818 |
json.EndString(); |
| 14819 |
|
| 14820 |
json.WriteString("PreferredBlockSize"); |
| 14821 |
json.WriteNumber(blockVector.GetPreferredBlockSize()); |
| 14822 |
|
| 14823 |
json.WriteString("Blocks"); |
| 14824 |
blockVector.PrintDetailedMap(json); |
| 14825 |
|
| 14826 |
json.WriteString("DedicatedAllocations"); |
| 14827 |
pool->m_DedicatedAllocations.BuildStatsString(json); |
| 14828 |
} |
| 14829 |
json.EndObject(); |
| 14830 |
} |
| 14831 |
} |
| 14832 |
|
| 14833 |
if (!displayType) |
| 14834 |
json.EndArray(); |
| 14835 |
} |
| 14836 |
} |
| 14837 |
} |
| 14838 |
json.EndObject(); |
| 14839 |
} |
| 14840 |
#endif |
| 14841 |
#endif |
| 14842 |
|
| 14843 |
|
| 14844 |
#ifndef _VMA_PUBLIC_INTERFACE |
| 14845 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator( |
| 14846 |
const VmaAllocatorCreateInfo* pCreateInfo, |
| 14847 |
VmaAllocator* pAllocator) |
| 14848 |
{ |
| 14849 |
VMA_ASSERT(pCreateInfo && pAllocator); |
| 14850 |
VMA_ASSERT(pCreateInfo->vulkanApiVersion == 0 || |
| 14851 |
(VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) == 1 && VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) <= 3)); |
| 14852 |
VMA_DEBUG_LOG("vmaCreateAllocator"); |
| 14853 |
*pAllocator = vma_new(pCreateInfo->pAllocationCallbacks, VmaAllocator_T)(pCreateInfo); |
| 14854 |
VkResult result = (*pAllocator)->Init(pCreateInfo); |
| 14855 |
if(result < 0) |
| 14856 |
{ |
| 14857 |
vma_delete(pCreateInfo->pAllocationCallbacks, *pAllocator); |
| 14858 |
*pAllocator = VK_NULL_HANDLE; |
| 14859 |
} |
| 14860 |
return result; |
| 14861 |
} |
| 14862 |
|
| 14863 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyAllocator( |
| 14864 |
VmaAllocator allocator) |
| 14865 |
{ |
| 14866 |
if(allocator != VK_NULL_HANDLE) |
| 14867 |
{ |
| 14868 |
VMA_DEBUG_LOG("vmaDestroyAllocator"); |
| 14869 |
VkAllocationCallbacks allocationCallbacks = allocator->m_AllocationCallbacks; |
| 14870 |
vma_delete(&allocationCallbacks, allocator); |
| 14871 |
} |
| 14872 |
} |
| 14873 |
|
| 14874 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocatorInfo(VmaAllocator allocator, VmaAllocatorInfo* pAllocatorInfo) |
| 14875 |
{ |
| 14876 |
VMA_ASSERT(allocator && pAllocatorInfo); |
| 14877 |
pAllocatorInfo->instance = allocator->m_hInstance; |
| 14878 |
pAllocatorInfo->physicalDevice = allocator->GetPhysicalDevice(); |
| 14879 |
pAllocatorInfo->device = allocator->m_hDevice; |
| 14880 |
} |
| 14881 |
|
| 14882 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPhysicalDeviceProperties( |
| 14883 |
VmaAllocator allocator, |
| 14884 |
const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties) |
| 14885 |
{ |
| 14886 |
VMA_ASSERT(allocator && ppPhysicalDeviceProperties); |
| 14887 |
*ppPhysicalDeviceProperties = &allocator->m_PhysicalDeviceProperties; |
| 14888 |
} |
| 14889 |
|
| 14890 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryProperties( |
| 14891 |
VmaAllocator allocator, |
| 14892 |
const VkPhysicalDeviceMemoryProperties** ppPhysicalDeviceMemoryProperties) |
| 14893 |
{ |
| 14894 |
VMA_ASSERT(allocator && ppPhysicalDeviceMemoryProperties); |
| 14895 |
*ppPhysicalDeviceMemoryProperties = &allocator->m_MemProps; |
| 14896 |
} |
| 14897 |
|
| 14898 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryTypeProperties( |
| 14899 |
VmaAllocator allocator, |
| 14900 |
uint32_t memoryTypeIndex, |
| 14901 |
VkMemoryPropertyFlags* pFlags) |
| 14902 |
{ |
| 14903 |
VMA_ASSERT(allocator && pFlags); |
| 14904 |
VMA_ASSERT(memoryTypeIndex < allocator->GetMemoryTypeCount()); |
| 14905 |
*pFlags = allocator->m_MemProps.memoryTypes[memoryTypeIndex].propertyFlags; |
| 14906 |
} |
| 14907 |
|
| 14908 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetCurrentFrameIndex( |
| 14909 |
VmaAllocator allocator, |
| 14910 |
uint32_t frameIndex) |
| 14911 |
{ |
| 14912 |
VMA_ASSERT(allocator); |
| 14913 |
|
| 14914 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 14915 |
|
| 14916 |
allocator->SetCurrentFrameIndex(frameIndex); |
| 14917 |
} |
| 14918 |
|
| 14919 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStatistics( |
| 14920 |
VmaAllocator allocator, |
| 14921 |
VmaTotalStatistics* pStats) |
| 14922 |
{ |
| 14923 |
VMA_ASSERT(allocator && pStats); |
| 14924 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 14925 |
allocator->CalculateStatistics(pStats); |
| 14926 |
} |
| 14927 |
|
| 14928 |
VMA_CALL_PRE uint64_t VMA_CALL_POST vmaCalculateLazilyAllocatedBytes( |
| 14929 |
VmaAllocator allocator) |
| 14930 |
{ |
| 14931 |
VMA_ASSERT(allocator); |
| 14932 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 14933 |
VmaTotalStatistics stats; |
| 14934 |
allocator->CalculateStatistics(&stats); |
| 14935 |
uint64_t total_lazilily_allocated_bytes = 0; |
| 14936 |
for (uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex) { |
| 14937 |
for (uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex) { |
| 14938 |
if (allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex) { |
| 14939 |
VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags; |
| 14940 |
if (flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) |
| 14941 |
total_lazilily_allocated_bytes += stats.memoryType[typeIndex].statistics.allocationBytes; |
| 14942 |
} |
| 14943 |
} |
| 14944 |
} |
| 14945 |
return total_lazilily_allocated_bytes; |
| 14946 |
} |
| 14947 |
|
| 14948 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetHeapBudgets( |
| 14949 |
VmaAllocator allocator, |
| 14950 |
VmaBudget* pBudgets) |
| 14951 |
{ |
| 14952 |
VMA_ASSERT(allocator && pBudgets); |
| 14953 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 14954 |
allocator->GetHeapBudgets(pBudgets, 0, allocator->GetMemoryHeapCount()); |
| 14955 |
} |
| 14956 |
|
| 14957 |
#if VMA_STATS_STRING_ENABLED |
| 14958 |
|
| 14959 |
VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString( |
| 14960 |
VmaAllocator allocator, |
| 14961 |
char** ppStatsString, |
| 14962 |
VkBool32 detailedMap) |
| 14963 |
{ |
| 14964 |
VMA_ASSERT(allocator && ppStatsString); |
| 14965 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 14966 |
|
| 14967 |
VmaStringBuilder sb(allocator->GetAllocationCallbacks()); |
| 14968 |
{ |
| 14969 |
VmaBudget budgets[VK_MAX_MEMORY_HEAPS]; |
| 14970 |
allocator->GetHeapBudgets(budgets, 0, allocator->GetMemoryHeapCount()); |
| 14971 |
|
| 14972 |
VmaTotalStatistics stats; |
| 14973 |
allocator->CalculateStatistics(&stats); |
| 14974 |
|
| 14975 |
VmaJsonWriter json(allocator->GetAllocationCallbacks(), sb); |
| 14976 |
json.BeginObject(); |
| 14977 |
{ |
| 14978 |
json.WriteString("General"); |
| 14979 |
json.BeginObject(); |
| 14980 |
{ |
| 14981 |
const VkPhysicalDeviceProperties& deviceProperties = allocator->m_PhysicalDeviceProperties; |
| 14982 |
const VkPhysicalDeviceMemoryProperties& memoryProperties = allocator->m_MemProps; |
| 14983 |
|
| 14984 |
json.WriteString("API"); |
| 14985 |
json.WriteString("Vulkan"); |
| 14986 |
|
| 14987 |
json.WriteString("apiVersion"); |
| 14988 |
json.BeginString(); |
| 14989 |
json.ContinueString(VK_VERSION_MAJOR(deviceProperties.apiVersion)); |
| 14990 |
json.ContinueString("."); |
| 14991 |
json.ContinueString(VK_VERSION_MINOR(deviceProperties.apiVersion)); |
| 14992 |
json.ContinueString("."); |
| 14993 |
json.ContinueString(VK_VERSION_PATCH(deviceProperties.apiVersion)); |
| 14994 |
json.EndString(); |
| 14995 |
|
| 14996 |
json.WriteString("GPU"); |
| 14997 |
json.WriteString(deviceProperties.deviceName); |
| 14998 |
json.WriteString("deviceType"); |
| 14999 |
json.WriteNumber(static_cast<uint32_t>(deviceProperties.deviceType)); |
| 15000 |
|
| 15001 |
json.WriteString("maxMemoryAllocationCount"); |
| 15002 |
json.WriteNumber(deviceProperties.limits.maxMemoryAllocationCount); |
| 15003 |
json.WriteString("bufferImageGranularity"); |
| 15004 |
json.WriteNumber(deviceProperties.limits.bufferImageGranularity); |
| 15005 |
json.WriteString("nonCoherentAtomSize"); |
| 15006 |
json.WriteNumber(deviceProperties.limits.nonCoherentAtomSize); |
| 15007 |
|
| 15008 |
json.WriteString("memoryHeapCount"); |
| 15009 |
json.WriteNumber(memoryProperties.memoryHeapCount); |
| 15010 |
json.WriteString("memoryTypeCount"); |
| 15011 |
json.WriteNumber(memoryProperties.memoryTypeCount); |
| 15012 |
} |
| 15013 |
json.EndObject(); |
| 15014 |
} |
| 15015 |
{ |
| 15016 |
json.WriteString("Total"); |
| 15017 |
VmaPrintDetailedStatistics(json, stats.total); |
| 15018 |
} |
| 15019 |
{ |
| 15020 |
json.WriteString("MemoryInfo"); |
| 15021 |
json.BeginObject(); |
| 15022 |
{ |
| 15023 |
for (uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex) |
| 15024 |
{ |
| 15025 |
json.BeginString("Heap "); |
| 15026 |
json.ContinueString(heapIndex); |
| 15027 |
json.EndString(); |
| 15028 |
json.BeginObject(); |
| 15029 |
{ |
| 15030 |
const VkMemoryHeap& heapInfo = allocator->m_MemProps.memoryHeaps[heapIndex]; |
| 15031 |
json.WriteString("Flags"); |
| 15032 |
json.BeginArray(true); |
| 15033 |
{ |
| 15034 |
if (heapInfo.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) |
| 15035 |
json.WriteString("DEVICE_LOCAL"); |
| 15036 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 15037 |
if (heapInfo.flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) |
| 15038 |
json.WriteString("MULTI_INSTANCE"); |
| 15039 |
#endif |
| 15040 |
|
| 15041 |
VkMemoryHeapFlags flags = heapInfo.flags & |
| 15042 |
~(VK_MEMORY_HEAP_DEVICE_LOCAL_BIT |
| 15043 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 15044 |
| VK_MEMORY_HEAP_MULTI_INSTANCE_BIT |
| 15045 |
#endif |
| 15046 |
); |
| 15047 |
if (flags != 0) |
| 15048 |
json.WriteNumber(flags); |
| 15049 |
} |
| 15050 |
json.EndArray(); |
| 15051 |
|
| 15052 |
json.WriteString("Size"); |
| 15053 |
json.WriteNumber(heapInfo.size); |
| 15054 |
|
| 15055 |
json.WriteString("Budget"); |
| 15056 |
json.BeginObject(); |
| 15057 |
{ |
| 15058 |
json.WriteString("BudgetBytes"); |
| 15059 |
json.WriteNumber(budgets[heapIndex].budget); |
| 15060 |
json.WriteString("UsageBytes"); |
| 15061 |
json.WriteNumber(budgets[heapIndex].usage); |
| 15062 |
} |
| 15063 |
json.EndObject(); |
| 15064 |
|
| 15065 |
json.WriteString("Stats"); |
| 15066 |
VmaPrintDetailedStatistics(json, stats.memoryHeap[heapIndex]); |
| 15067 |
|
| 15068 |
json.WriteString("MemoryPools"); |
| 15069 |
json.BeginObject(); |
| 15070 |
{ |
| 15071 |
for (uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex) |
| 15072 |
{ |
| 15073 |
if (allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex) |
| 15074 |
{ |
| 15075 |
json.BeginString("Type "); |
| 15076 |
json.ContinueString(typeIndex); |
| 15077 |
json.EndString(); |
| 15078 |
json.BeginObject(); |
| 15079 |
{ |
| 15080 |
json.WriteString("Flags"); |
| 15081 |
json.BeginArray(true); |
| 15082 |
{ |
| 15083 |
VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags; |
| 15084 |
if (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) |
| 15085 |
json.WriteString("DEVICE_LOCAL"); |
| 15086 |
if (flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) |
| 15087 |
json.WriteString("HOST_VISIBLE"); |
| 15088 |
if (flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) |
| 15089 |
json.WriteString("HOST_COHERENT"); |
| 15090 |
if (flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) |
| 15091 |
json.WriteString("HOST_CACHED"); |
| 15092 |
if (flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) |
| 15093 |
json.WriteString("LAZILY_ALLOCATED"); |
| 15094 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 15095 |
if (flags & VK_MEMORY_PROPERTY_PROTECTED_BIT) |
| 15096 |
json.WriteString("PROTECTED"); |
| 15097 |
#endif |
| 15098 |
#if VK_AMD_device_coherent_memory |
| 15099 |
if (flags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY) |
| 15100 |
json.WriteString("DEVICE_COHERENT_AMD"); |
| 15101 |
if (flags & VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY) |
| 15102 |
json.WriteString("DEVICE_UNCACHED_AMD"); |
| 15103 |
#endif |
| 15104 |
|
| 15105 |
flags &= ~(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
| 15106 |
#if VMA_VULKAN_VERSION >= 1001000 |
| 15107 |
| VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT |
| 15108 |
#endif |
| 15109 |
#if VK_AMD_device_coherent_memory |
| 15110 |
| VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY |
| 15111 |
| VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY |
| 15112 |
#endif |
| 15113 |
| VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 15114 |
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
| 15115 |
| VK_MEMORY_PROPERTY_HOST_CACHED_BIT); |
| 15116 |
if (flags != 0) |
| 15117 |
json.WriteNumber(flags); |
| 15118 |
} |
| 15119 |
json.EndArray(); |
| 15120 |
|
| 15121 |
json.WriteString("Stats"); |
| 15122 |
VmaPrintDetailedStatistics(json, stats.memoryType[typeIndex]); |
| 15123 |
} |
| 15124 |
json.EndObject(); |
| 15125 |
} |
| 15126 |
} |
| 15127 |
|
| 15128 |
} |
| 15129 |
json.EndObject(); |
| 15130 |
} |
| 15131 |
json.EndObject(); |
| 15132 |
} |
| 15133 |
} |
| 15134 |
json.EndObject(); |
| 15135 |
} |
| 15136 |
|
| 15137 |
if (detailedMap == VK_TRUE) |
| 15138 |
allocator->PrintDetailedMap(json); |
| 15139 |
|
| 15140 |
json.EndObject(); |
| 15141 |
} |
| 15142 |
|
| 15143 |
*ppStatsString = VmaCreateStringCopy(allocator->GetAllocationCallbacks(), sb.GetData(), sb.GetLength()); |
| 15144 |
} |
| 15145 |
|
| 15146 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString( |
| 15147 |
VmaAllocator allocator, |
| 15148 |
char* pStatsString) |
| 15149 |
{ |
| 15150 |
if(pStatsString != VMA_NULL) |
| 15151 |
{ |
| 15152 |
VMA_ASSERT(allocator); |
| 15153 |
VmaFreeString(allocator->GetAllocationCallbacks(), pStatsString); |
| 15154 |
} |
| 15155 |
} |
| 15156 |
|
| 15157 |
#endif |
| 15158 |
|
| 15159 |
|
| 15160 |
|
| 15161 |
|
| 15162 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndex( |
| 15163 |
VmaAllocator allocator, |
| 15164 |
uint32_t memoryTypeBits, |
| 15165 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 15166 |
uint32_t* pMemoryTypeIndex) |
| 15167 |
{ |
| 15168 |
VMA_ASSERT(allocator != VK_NULL_HANDLE); |
| 15169 |
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL); |
| 15170 |
VMA_ASSERT(pMemoryTypeIndex != VMA_NULL); |
| 15171 |
|
| 15172 |
return allocator->FindMemoryTypeIndex(memoryTypeBits, pAllocationCreateInfo, VmaBufferImageUsage::UNKNOWN, pMemoryTypeIndex); |
| 15173 |
} |
| 15174 |
|
| 15175 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo( |
| 15176 |
VmaAllocator allocator, |
| 15177 |
const VkBufferCreateInfo* pBufferCreateInfo, |
| 15178 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 15179 |
uint32_t* pMemoryTypeIndex) |
| 15180 |
{ |
| 15181 |
VMA_ASSERT(allocator != VK_NULL_HANDLE); |
| 15182 |
VMA_ASSERT(pBufferCreateInfo != VMA_NULL); |
| 15183 |
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL); |
| 15184 |
VMA_ASSERT(pMemoryTypeIndex != VMA_NULL); |
| 15185 |
|
| 15186 |
const VkDevice hDev = allocator->m_hDevice; |
| 15187 |
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions(); |
| 15188 |
VkResult res; |
| 15189 |
|
| 15190 |
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 |
| 15191 |
if(funcs->vkGetDeviceBufferMemoryRequirements) |
| 15192 |
{ |
| 15193 |
|
| 15194 |
VkDeviceBufferMemoryRequirementsKHR devBufMemReq = {VK_STRUCTURE_TYPE_DEVICE_BUFFER_MEMORY_REQUIREMENTS_KHR}; |
| 15195 |
devBufMemReq.pCreateInfo = pBufferCreateInfo; |
| 15196 |
|
| 15197 |
VkMemoryRequirements2 memReq = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2}; |
| 15198 |
(*funcs->vkGetDeviceBufferMemoryRequirements)(hDev, &devBufMemReq, &memReq); |
| 15199 |
|
| 15200 |
res = allocator->FindMemoryTypeIndex( |
| 15201 |
memReq.memoryRequirements.memoryTypeBits, pAllocationCreateInfo, |
| 15202 |
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex); |
| 15203 |
} |
| 15204 |
else |
| 15205 |
#endif |
| 15206 |
{ |
| 15207 |
|
| 15208 |
VkBuffer hBuffer = VK_NULL_HANDLE; |
| 15209 |
res = funcs->vkCreateBuffer( |
| 15210 |
hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer); |
| 15211 |
if(res == VK_SUCCESS) |
| 15212 |
{ |
| 15213 |
VkMemoryRequirements memReq = {}; |
| 15214 |
funcs->vkGetBufferMemoryRequirements(hDev, hBuffer, &memReq); |
| 15215 |
|
| 15216 |
res = allocator->FindMemoryTypeIndex( |
| 15217 |
memReq.memoryTypeBits, pAllocationCreateInfo, |
| 15218 |
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex); |
| 15219 |
|
| 15220 |
funcs->vkDestroyBuffer( |
| 15221 |
hDev, hBuffer, allocator->GetAllocationCallbacks()); |
| 15222 |
} |
| 15223 |
} |
| 15224 |
return res; |
| 15225 |
} |
| 15226 |
|
| 15227 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo( |
| 15228 |
VmaAllocator allocator, |
| 15229 |
const VkImageCreateInfo* pImageCreateInfo, |
| 15230 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 15231 |
uint32_t* pMemoryTypeIndex) |
| 15232 |
{ |
| 15233 |
VMA_ASSERT(allocator != VK_NULL_HANDLE); |
| 15234 |
VMA_ASSERT(pImageCreateInfo != VMA_NULL); |
| 15235 |
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL); |
| 15236 |
VMA_ASSERT(pMemoryTypeIndex != VMA_NULL); |
| 15237 |
|
| 15238 |
const VkDevice hDev = allocator->m_hDevice; |
| 15239 |
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions(); |
| 15240 |
VkResult res; |
| 15241 |
|
| 15242 |
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 |
| 15243 |
if(funcs->vkGetDeviceImageMemoryRequirements) |
| 15244 |
{ |
| 15245 |
|
| 15246 |
VkDeviceImageMemoryRequirementsKHR devImgMemReq = {VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR}; |
| 15247 |
devImgMemReq.pCreateInfo = pImageCreateInfo; |
| 15248 |
VMA_ASSERT(pImageCreateInfo->tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT_COPY && (pImageCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT_COPY) == 0 && |
| 15249 |
"Cannot use this VkImageCreateInfo with vmaFindMemoryTypeIndexForImageInfo as I don't know what to pass as VkDeviceImageMemoryRequirements::planeAspect."); |
| 15250 |
|
| 15251 |
VkMemoryRequirements2 memReq = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2}; |
| 15252 |
(*funcs->vkGetDeviceImageMemoryRequirements)(hDev, &devImgMemReq, &memReq); |
| 15253 |
|
| 15254 |
res = allocator->FindMemoryTypeIndex( |
| 15255 |
memReq.memoryRequirements.memoryTypeBits, pAllocationCreateInfo, |
| 15256 |
VmaBufferImageUsage(*pImageCreateInfo), pMemoryTypeIndex); |
| 15257 |
} |
| 15258 |
else |
| 15259 |
#endif |
| 15260 |
{ |
| 15261 |
|
| 15262 |
VkImage hImage = VK_NULL_HANDLE; |
| 15263 |
res = funcs->vkCreateImage( |
| 15264 |
hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage); |
| 15265 |
if(res == VK_SUCCESS) |
| 15266 |
{ |
| 15267 |
VkMemoryRequirements memReq = {}; |
| 15268 |
funcs->vkGetImageMemoryRequirements(hDev, hImage, &memReq); |
| 15269 |
|
| 15270 |
res = allocator->FindMemoryTypeIndex( |
| 15271 |
memReq.memoryTypeBits, pAllocationCreateInfo, |
| 15272 |
VmaBufferImageUsage(*pImageCreateInfo), pMemoryTypeIndex); |
| 15273 |
|
| 15274 |
funcs->vkDestroyImage( |
| 15275 |
hDev, hImage, allocator->GetAllocationCallbacks()); |
| 15276 |
} |
| 15277 |
} |
| 15278 |
return res; |
| 15279 |
} |
| 15280 |
|
| 15281 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreatePool( |
| 15282 |
VmaAllocator allocator, |
| 15283 |
const VmaPoolCreateInfo* pCreateInfo, |
| 15284 |
VmaPool* pPool) |
| 15285 |
{ |
| 15286 |
VMA_ASSERT(allocator && pCreateInfo && pPool); |
| 15287 |
|
| 15288 |
VMA_DEBUG_LOG("vmaCreatePool"); |
| 15289 |
|
| 15290 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15291 |
|
| 15292 |
return allocator->CreatePool(pCreateInfo, pPool); |
| 15293 |
} |
| 15294 |
|
| 15295 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool( |
| 15296 |
VmaAllocator allocator, |
| 15297 |
VmaPool pool) |
| 15298 |
{ |
| 15299 |
VMA_ASSERT(allocator); |
| 15300 |
|
| 15301 |
if(pool == VK_NULL_HANDLE) |
| 15302 |
{ |
| 15303 |
return; |
| 15304 |
} |
| 15305 |
|
| 15306 |
VMA_DEBUG_LOG("vmaDestroyPool"); |
| 15307 |
|
| 15308 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15309 |
|
| 15310 |
allocator->DestroyPool(pool); |
| 15311 |
} |
| 15312 |
|
| 15313 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolStatistics( |
| 15314 |
VmaAllocator allocator, |
| 15315 |
VmaPool pool, |
| 15316 |
VmaStatistics* pPoolStats) |
| 15317 |
{ |
| 15318 |
VMA_ASSERT(allocator && pool && pPoolStats); |
| 15319 |
|
| 15320 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15321 |
|
| 15322 |
allocator->GetPoolStatistics(pool, pPoolStats); |
| 15323 |
} |
| 15324 |
|
| 15325 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculatePoolStatistics( |
| 15326 |
VmaAllocator allocator, |
| 15327 |
VmaPool pool, |
| 15328 |
VmaDetailedStatistics* pPoolStats) |
| 15329 |
{ |
| 15330 |
VMA_ASSERT(allocator && pool && pPoolStats); |
| 15331 |
|
| 15332 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15333 |
|
| 15334 |
allocator->CalculatePoolStatistics(pool, pPoolStats); |
| 15335 |
} |
| 15336 |
|
| 15337 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool) |
| 15338 |
{ |
| 15339 |
VMA_ASSERT(allocator && pool); |
| 15340 |
|
| 15341 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15342 |
|
| 15343 |
VMA_DEBUG_LOG("vmaCheckPoolCorruption"); |
| 15344 |
|
| 15345 |
return allocator->CheckPoolCorruption(pool); |
| 15346 |
} |
| 15347 |
|
| 15348 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName( |
| 15349 |
VmaAllocator allocator, |
| 15350 |
VmaPool pool, |
| 15351 |
const char** ppName) |
| 15352 |
{ |
| 15353 |
VMA_ASSERT(allocator && pool && ppName); |
| 15354 |
|
| 15355 |
VMA_DEBUG_LOG("vmaGetPoolName"); |
| 15356 |
|
| 15357 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15358 |
|
| 15359 |
*ppName = pool->GetName(); |
| 15360 |
} |
| 15361 |
|
| 15362 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName( |
| 15363 |
VmaAllocator allocator, |
| 15364 |
VmaPool pool, |
| 15365 |
const char* pName) |
| 15366 |
{ |
| 15367 |
VMA_ASSERT(allocator && pool); |
| 15368 |
|
| 15369 |
VMA_DEBUG_LOG("vmaSetPoolName"); |
| 15370 |
|
| 15371 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15372 |
|
| 15373 |
pool->SetName(pName); |
| 15374 |
} |
| 15375 |
|
| 15376 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory( |
| 15377 |
VmaAllocator allocator, |
| 15378 |
const VkMemoryRequirements* pVkMemoryRequirements, |
| 15379 |
const VmaAllocationCreateInfo* pCreateInfo, |
| 15380 |
VmaAllocation* pAllocation, |
| 15381 |
VmaAllocationInfo* pAllocationInfo) |
| 15382 |
{ |
| 15383 |
VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocation); |
| 15384 |
|
| 15385 |
VMA_DEBUG_LOG("vmaAllocateMemory"); |
| 15386 |
|
| 15387 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15388 |
|
| 15389 |
VkResult result = allocator->AllocateMemory( |
| 15390 |
*pVkMemoryRequirements, |
| 15391 |
false, |
| 15392 |
false, |
| 15393 |
VK_NULL_HANDLE, |
| 15394 |
VK_NULL_HANDLE, |
| 15395 |
VmaBufferImageUsage::UNKNOWN, |
| 15396 |
*pCreateInfo, |
| 15397 |
VMA_SUBALLOCATION_TYPE_UNKNOWN, |
| 15398 |
1, |
| 15399 |
pAllocation); |
| 15400 |
|
| 15401 |
if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS) |
| 15402 |
{ |
| 15403 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 15404 |
} |
| 15405 |
|
| 15406 |
return result; |
| 15407 |
} |
| 15408 |
|
| 15409 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryPages( |
| 15410 |
VmaAllocator allocator, |
| 15411 |
const VkMemoryRequirements* pVkMemoryRequirements, |
| 15412 |
const VmaAllocationCreateInfo* pCreateInfo, |
| 15413 |
size_t allocationCount, |
| 15414 |
VmaAllocation* pAllocations, |
| 15415 |
VmaAllocationInfo* pAllocationInfo) |
| 15416 |
{ |
| 15417 |
if(allocationCount == 0) |
| 15418 |
{ |
| 15419 |
return VK_SUCCESS; |
| 15420 |
} |
| 15421 |
|
| 15422 |
VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocations); |
| 15423 |
|
| 15424 |
VMA_DEBUG_LOG("vmaAllocateMemoryPages"); |
| 15425 |
|
| 15426 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15427 |
|
| 15428 |
VkResult result = allocator->AllocateMemory( |
| 15429 |
*pVkMemoryRequirements, |
| 15430 |
false, |
| 15431 |
false, |
| 15432 |
VK_NULL_HANDLE, |
| 15433 |
VK_NULL_HANDLE, |
| 15434 |
VmaBufferImageUsage::UNKNOWN, |
| 15435 |
*pCreateInfo, |
| 15436 |
VMA_SUBALLOCATION_TYPE_UNKNOWN, |
| 15437 |
allocationCount, |
| 15438 |
pAllocations); |
| 15439 |
|
| 15440 |
if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS) |
| 15441 |
{ |
| 15442 |
for(size_t i = 0; i < allocationCount; ++i) |
| 15443 |
{ |
| 15444 |
allocator->GetAllocationInfo(pAllocations[i], pAllocationInfo + i); |
| 15445 |
} |
| 15446 |
} |
| 15447 |
|
| 15448 |
return result; |
| 15449 |
} |
| 15450 |
|
| 15451 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForBuffer( |
| 15452 |
VmaAllocator allocator, |
| 15453 |
VkBuffer buffer, |
| 15454 |
const VmaAllocationCreateInfo* pCreateInfo, |
| 15455 |
VmaAllocation* pAllocation, |
| 15456 |
VmaAllocationInfo* pAllocationInfo) |
| 15457 |
{ |
| 15458 |
VMA_ASSERT(allocator && buffer != VK_NULL_HANDLE && pCreateInfo && pAllocation); |
| 15459 |
|
| 15460 |
VMA_DEBUG_LOG("vmaAllocateMemoryForBuffer"); |
| 15461 |
|
| 15462 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15463 |
|
| 15464 |
VkMemoryRequirements vkMemReq = {}; |
| 15465 |
bool requiresDedicatedAllocation = false; |
| 15466 |
bool prefersDedicatedAllocation = false; |
| 15467 |
allocator->GetBufferMemoryRequirements(buffer, vkMemReq, |
| 15468 |
requiresDedicatedAllocation, |
| 15469 |
prefersDedicatedAllocation); |
| 15470 |
|
| 15471 |
VkResult result = allocator->AllocateMemory( |
| 15472 |
vkMemReq, |
| 15473 |
requiresDedicatedAllocation, |
| 15474 |
prefersDedicatedAllocation, |
| 15475 |
buffer, |
| 15476 |
VK_NULL_HANDLE, |
| 15477 |
VmaBufferImageUsage::UNKNOWN, |
| 15478 |
*pCreateInfo, |
| 15479 |
VMA_SUBALLOCATION_TYPE_BUFFER, |
| 15480 |
1, |
| 15481 |
pAllocation); |
| 15482 |
|
| 15483 |
if(pAllocationInfo && result == VK_SUCCESS) |
| 15484 |
{ |
| 15485 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 15486 |
} |
| 15487 |
|
| 15488 |
return result; |
| 15489 |
} |
| 15490 |
|
| 15491 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForImage( |
| 15492 |
VmaAllocator allocator, |
| 15493 |
VkImage image, |
| 15494 |
const VmaAllocationCreateInfo* pCreateInfo, |
| 15495 |
VmaAllocation* pAllocation, |
| 15496 |
VmaAllocationInfo* pAllocationInfo) |
| 15497 |
{ |
| 15498 |
VMA_ASSERT(allocator && image != VK_NULL_HANDLE && pCreateInfo && pAllocation); |
| 15499 |
|
| 15500 |
VMA_DEBUG_LOG("vmaAllocateMemoryForImage"); |
| 15501 |
|
| 15502 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15503 |
|
| 15504 |
VkMemoryRequirements vkMemReq = {}; |
| 15505 |
bool requiresDedicatedAllocation = false; |
| 15506 |
bool prefersDedicatedAllocation = false; |
| 15507 |
allocator->GetImageMemoryRequirements(image, vkMemReq, |
| 15508 |
requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 15509 |
|
| 15510 |
VkResult result = allocator->AllocateMemory( |
| 15511 |
vkMemReq, |
| 15512 |
requiresDedicatedAllocation, |
| 15513 |
prefersDedicatedAllocation, |
| 15514 |
VK_NULL_HANDLE, |
| 15515 |
image, |
| 15516 |
VmaBufferImageUsage::UNKNOWN, |
| 15517 |
*pCreateInfo, |
| 15518 |
VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN, |
| 15519 |
1, |
| 15520 |
pAllocation); |
| 15521 |
|
| 15522 |
if(pAllocationInfo && result == VK_SUCCESS) |
| 15523 |
{ |
| 15524 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 15525 |
} |
| 15526 |
|
| 15527 |
return result; |
| 15528 |
} |
| 15529 |
|
| 15530 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory( |
| 15531 |
VmaAllocator allocator, |
| 15532 |
VmaAllocation allocation) |
| 15533 |
{ |
| 15534 |
VMA_ASSERT(allocator); |
| 15535 |
|
| 15536 |
if(allocation == VK_NULL_HANDLE) |
| 15537 |
{ |
| 15538 |
return; |
| 15539 |
} |
| 15540 |
|
| 15541 |
VMA_DEBUG_LOG("vmaFreeMemory"); |
| 15542 |
|
| 15543 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15544 |
|
| 15545 |
allocator->FreeMemory( |
| 15546 |
1, |
| 15547 |
&allocation); |
| 15548 |
} |
| 15549 |
|
| 15550 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages( |
| 15551 |
VmaAllocator allocator, |
| 15552 |
size_t allocationCount, |
| 15553 |
const VmaAllocation* pAllocations) |
| 15554 |
{ |
| 15555 |
if(allocationCount == 0) |
| 15556 |
{ |
| 15557 |
return; |
| 15558 |
} |
| 15559 |
|
| 15560 |
VMA_ASSERT(allocator); |
| 15561 |
|
| 15562 |
VMA_DEBUG_LOG("vmaFreeMemoryPages"); |
| 15563 |
|
| 15564 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15565 |
|
| 15566 |
allocator->FreeMemory(allocationCount, pAllocations); |
| 15567 |
} |
| 15568 |
|
| 15569 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo( |
| 15570 |
VmaAllocator allocator, |
| 15571 |
VmaAllocation allocation, |
| 15572 |
VmaAllocationInfo* pAllocationInfo) |
| 15573 |
{ |
| 15574 |
VMA_ASSERT(allocator && allocation && pAllocationInfo); |
| 15575 |
|
| 15576 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15577 |
|
| 15578 |
allocator->GetAllocationInfo(allocation, pAllocationInfo); |
| 15579 |
} |
| 15580 |
|
| 15581 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo2( |
| 15582 |
VmaAllocator allocator, |
| 15583 |
VmaAllocation allocation, |
| 15584 |
VmaAllocationInfo2* pAllocationInfo) |
| 15585 |
{ |
| 15586 |
VMA_ASSERT(allocator && allocation && pAllocationInfo); |
| 15587 |
|
| 15588 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15589 |
|
| 15590 |
allocator->GetAllocationInfo2(allocation, pAllocationInfo); |
| 15591 |
} |
| 15592 |
|
| 15593 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationUserData( |
| 15594 |
VmaAllocator allocator, |
| 15595 |
VmaAllocation allocation, |
| 15596 |
void* pUserData) |
| 15597 |
{ |
| 15598 |
VMA_ASSERT(allocator && allocation); |
| 15599 |
|
| 15600 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15601 |
|
| 15602 |
allocation->SetUserData(allocator, pUserData); |
| 15603 |
} |
| 15604 |
|
| 15605 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationName( |
| 15606 |
VmaAllocator VMA_NOT_NULL allocator, |
| 15607 |
VmaAllocation VMA_NOT_NULL allocation, |
| 15608 |
const char* VMA_NULLABLE pName) |
| 15609 |
{ |
| 15610 |
allocation->SetName(allocator, pName); |
| 15611 |
} |
| 15612 |
|
| 15613 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationMemoryProperties( |
| 15614 |
VmaAllocator VMA_NOT_NULL allocator, |
| 15615 |
VmaAllocation VMA_NOT_NULL allocation, |
| 15616 |
VkMemoryPropertyFlags* VMA_NOT_NULL pFlags) |
| 15617 |
{ |
| 15618 |
VMA_ASSERT(allocator && allocation && pFlags); |
| 15619 |
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex(); |
| 15620 |
*pFlags = allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags; |
| 15621 |
} |
| 15622 |
|
| 15623 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaMapMemory( |
| 15624 |
VmaAllocator allocator, |
| 15625 |
VmaAllocation allocation, |
| 15626 |
void** ppData) |
| 15627 |
{ |
| 15628 |
VMA_ASSERT(allocator && allocation && ppData); |
| 15629 |
|
| 15630 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15631 |
|
| 15632 |
return allocator->Map(allocation, ppData); |
| 15633 |
} |
| 15634 |
|
| 15635 |
VMA_CALL_PRE void VMA_CALL_POST vmaUnmapMemory( |
| 15636 |
VmaAllocator allocator, |
| 15637 |
VmaAllocation allocation) |
| 15638 |
{ |
| 15639 |
VMA_ASSERT(allocator && allocation); |
| 15640 |
|
| 15641 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15642 |
|
| 15643 |
allocator->Unmap(allocation); |
| 15644 |
} |
| 15645 |
|
| 15646 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFlushAllocation( |
| 15647 |
VmaAllocator allocator, |
| 15648 |
VmaAllocation allocation, |
| 15649 |
VkDeviceSize offset, |
| 15650 |
VkDeviceSize size) |
| 15651 |
{ |
| 15652 |
VMA_ASSERT(allocator && allocation); |
| 15653 |
|
| 15654 |
VMA_DEBUG_LOG("vmaFlushAllocation"); |
| 15655 |
|
| 15656 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15657 |
|
| 15658 |
return allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_FLUSH); |
| 15659 |
} |
| 15660 |
|
| 15661 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaInvalidateAllocation( |
| 15662 |
VmaAllocator allocator, |
| 15663 |
VmaAllocation allocation, |
| 15664 |
VkDeviceSize offset, |
| 15665 |
VkDeviceSize size) |
| 15666 |
{ |
| 15667 |
VMA_ASSERT(allocator && allocation); |
| 15668 |
|
| 15669 |
VMA_DEBUG_LOG("vmaInvalidateAllocation"); |
| 15670 |
|
| 15671 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15672 |
|
| 15673 |
return allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_INVALIDATE); |
| 15674 |
} |
| 15675 |
|
| 15676 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaFlushAllocations( |
| 15677 |
VmaAllocator allocator, |
| 15678 |
uint32_t allocationCount, |
| 15679 |
const VmaAllocation* allocations, |
| 15680 |
const VkDeviceSize* offsets, |
| 15681 |
const VkDeviceSize* sizes) |
| 15682 |
{ |
| 15683 |
VMA_ASSERT(allocator); |
| 15684 |
|
| 15685 |
if(allocationCount == 0) |
| 15686 |
{ |
| 15687 |
return VK_SUCCESS; |
| 15688 |
} |
| 15689 |
|
| 15690 |
VMA_ASSERT(allocations); |
| 15691 |
|
| 15692 |
VMA_DEBUG_LOG("vmaFlushAllocations"); |
| 15693 |
|
| 15694 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15695 |
|
| 15696 |
return allocator->FlushOrInvalidateAllocations(allocationCount, allocations, offsets, sizes, VMA_CACHE_FLUSH); |
| 15697 |
} |
| 15698 |
|
| 15699 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaInvalidateAllocations( |
| 15700 |
VmaAllocator allocator, |
| 15701 |
uint32_t allocationCount, |
| 15702 |
const VmaAllocation* allocations, |
| 15703 |
const VkDeviceSize* offsets, |
| 15704 |
const VkDeviceSize* sizes) |
| 15705 |
{ |
| 15706 |
VMA_ASSERT(allocator); |
| 15707 |
|
| 15708 |
if(allocationCount == 0) |
| 15709 |
{ |
| 15710 |
return VK_SUCCESS; |
| 15711 |
} |
| 15712 |
|
| 15713 |
VMA_ASSERT(allocations); |
| 15714 |
|
| 15715 |
VMA_DEBUG_LOG("vmaInvalidateAllocations"); |
| 15716 |
|
| 15717 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15718 |
|
| 15719 |
return allocator->FlushOrInvalidateAllocations(allocationCount, allocations, offsets, sizes, VMA_CACHE_INVALIDATE); |
| 15720 |
} |
| 15721 |
|
| 15722 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCopyMemoryToAllocation( |
| 15723 |
VmaAllocator allocator, |
| 15724 |
const void* pSrcHostPointer, |
| 15725 |
VmaAllocation dstAllocation, |
| 15726 |
VkDeviceSize dstAllocationLocalOffset, |
| 15727 |
VkDeviceSize size) |
| 15728 |
{ |
| 15729 |
VMA_ASSERT(allocator && pSrcHostPointer && dstAllocation); |
| 15730 |
|
| 15731 |
if(size == 0) |
| 15732 |
{ |
| 15733 |
return VK_SUCCESS; |
| 15734 |
} |
| 15735 |
|
| 15736 |
VMA_DEBUG_LOG("vmaCopyMemoryToAllocation"); |
| 15737 |
|
| 15738 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15739 |
|
| 15740 |
return allocator->CopyMemoryToAllocation(pSrcHostPointer, dstAllocation, dstAllocationLocalOffset, size); |
| 15741 |
} |
| 15742 |
|
| 15743 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCopyAllocationToMemory( |
| 15744 |
VmaAllocator allocator, |
| 15745 |
VmaAllocation srcAllocation, |
| 15746 |
VkDeviceSize srcAllocationLocalOffset, |
| 15747 |
void* pDstHostPointer, |
| 15748 |
VkDeviceSize size) |
| 15749 |
{ |
| 15750 |
VMA_ASSERT(allocator && srcAllocation && pDstHostPointer); |
| 15751 |
|
| 15752 |
if(size == 0) |
| 15753 |
{ |
| 15754 |
return VK_SUCCESS; |
| 15755 |
} |
| 15756 |
|
| 15757 |
VMA_DEBUG_LOG("vmaCopyAllocationToMemory"); |
| 15758 |
|
| 15759 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15760 |
|
| 15761 |
return allocator->CopyAllocationToMemory(srcAllocation, srcAllocationLocalOffset, pDstHostPointer, size); |
| 15762 |
} |
| 15763 |
|
| 15764 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckCorruption( |
| 15765 |
VmaAllocator allocator, |
| 15766 |
uint32_t memoryTypeBits) |
| 15767 |
{ |
| 15768 |
VMA_ASSERT(allocator); |
| 15769 |
|
| 15770 |
VMA_DEBUG_LOG("vmaCheckCorruption"); |
| 15771 |
|
| 15772 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15773 |
|
| 15774 |
return allocator->CheckCorruption(memoryTypeBits); |
| 15775 |
} |
| 15776 |
|
| 15777 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentation( |
| 15778 |
VmaAllocator allocator, |
| 15779 |
const VmaDefragmentationInfo* pInfo, |
| 15780 |
VmaDefragmentationContext* pContext) |
| 15781 |
{ |
| 15782 |
VMA_ASSERT(allocator && pInfo && pContext); |
| 15783 |
|
| 15784 |
VMA_DEBUG_LOG("vmaBeginDefragmentation"); |
| 15785 |
|
| 15786 |
if (pInfo->pool != VMA_NULL) |
| 15787 |
{ |
| 15788 |
|
| 15789 |
if (pInfo->pool->m_BlockVector.GetAlgorithm() & VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) |
| 15790 |
return VK_ERROR_FEATURE_NOT_PRESENT; |
| 15791 |
} |
| 15792 |
|
| 15793 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15794 |
|
| 15795 |
*pContext = vma_new(allocator, VmaDefragmentationContext_T)(allocator, *pInfo); |
| 15796 |
return VK_SUCCESS; |
| 15797 |
} |
| 15798 |
|
| 15799 |
VMA_CALL_PRE void VMA_CALL_POST vmaEndDefragmentation( |
| 15800 |
VmaAllocator allocator, |
| 15801 |
VmaDefragmentationContext context, |
| 15802 |
VmaDefragmentationStats* pStats) |
| 15803 |
{ |
| 15804 |
VMA_ASSERT(allocator && context); |
| 15805 |
|
| 15806 |
VMA_DEBUG_LOG("vmaEndDefragmentation"); |
| 15807 |
|
| 15808 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15809 |
|
| 15810 |
if (pStats) |
| 15811 |
context->GetStats(*pStats); |
| 15812 |
vma_delete(allocator, context); |
| 15813 |
} |
| 15814 |
|
| 15815 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentationPass( |
| 15816 |
VmaAllocator VMA_NOT_NULL allocator, |
| 15817 |
VmaDefragmentationContext VMA_NOT_NULL context, |
| 15818 |
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo) |
| 15819 |
{ |
| 15820 |
VMA_ASSERT(context && pPassInfo); |
| 15821 |
|
| 15822 |
VMA_DEBUG_LOG("vmaBeginDefragmentationPass"); |
| 15823 |
|
| 15824 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15825 |
|
| 15826 |
return context->DefragmentPassBegin(*pPassInfo); |
| 15827 |
} |
| 15828 |
|
| 15829 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaEndDefragmentationPass( |
| 15830 |
VmaAllocator VMA_NOT_NULL allocator, |
| 15831 |
VmaDefragmentationContext VMA_NOT_NULL context, |
| 15832 |
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo) |
| 15833 |
{ |
| 15834 |
VMA_ASSERT(context && pPassInfo); |
| 15835 |
|
| 15836 |
VMA_DEBUG_LOG("vmaEndDefragmentationPass"); |
| 15837 |
|
| 15838 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15839 |
|
| 15840 |
return context->DefragmentPassEnd(*pPassInfo); |
| 15841 |
} |
| 15842 |
|
| 15843 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory( |
| 15844 |
VmaAllocator allocator, |
| 15845 |
VmaAllocation allocation, |
| 15846 |
VkBuffer buffer) |
| 15847 |
{ |
| 15848 |
VMA_ASSERT(allocator && allocation && buffer); |
| 15849 |
|
| 15850 |
VMA_DEBUG_LOG("vmaBindBufferMemory"); |
| 15851 |
|
| 15852 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15853 |
|
| 15854 |
return allocator->BindBufferMemory(allocation, 0, buffer, VMA_NULL); |
| 15855 |
} |
| 15856 |
|
| 15857 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory2( |
| 15858 |
VmaAllocator allocator, |
| 15859 |
VmaAllocation allocation, |
| 15860 |
VkDeviceSize allocationLocalOffset, |
| 15861 |
VkBuffer buffer, |
| 15862 |
const void* pNext) |
| 15863 |
{ |
| 15864 |
VMA_ASSERT(allocator && allocation && buffer); |
| 15865 |
|
| 15866 |
VMA_DEBUG_LOG("vmaBindBufferMemory2"); |
| 15867 |
|
| 15868 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15869 |
|
| 15870 |
return allocator->BindBufferMemory(allocation, allocationLocalOffset, buffer, pNext); |
| 15871 |
} |
| 15872 |
|
| 15873 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory( |
| 15874 |
VmaAllocator allocator, |
| 15875 |
VmaAllocation allocation, |
| 15876 |
VkImage image) |
| 15877 |
{ |
| 15878 |
VMA_ASSERT(allocator && allocation && image); |
| 15879 |
|
| 15880 |
VMA_DEBUG_LOG("vmaBindImageMemory"); |
| 15881 |
|
| 15882 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15883 |
|
| 15884 |
return allocator->BindImageMemory(allocation, 0, image, VMA_NULL); |
| 15885 |
} |
| 15886 |
|
| 15887 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory2( |
| 15888 |
VmaAllocator allocator, |
| 15889 |
VmaAllocation allocation, |
| 15890 |
VkDeviceSize allocationLocalOffset, |
| 15891 |
VkImage image, |
| 15892 |
const void* pNext) |
| 15893 |
{ |
| 15894 |
VMA_ASSERT(allocator && allocation && image); |
| 15895 |
|
| 15896 |
VMA_DEBUG_LOG("vmaBindImageMemory2"); |
| 15897 |
|
| 15898 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15899 |
|
| 15900 |
return allocator->BindImageMemory(allocation, allocationLocalOffset, image, pNext); |
| 15901 |
} |
| 15902 |
|
| 15903 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer( |
| 15904 |
VmaAllocator allocator, |
| 15905 |
const VkBufferCreateInfo* pBufferCreateInfo, |
| 15906 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 15907 |
VkBuffer* pBuffer, |
| 15908 |
VmaAllocation* pAllocation, |
| 15909 |
VmaAllocationInfo* pAllocationInfo) |
| 15910 |
{ |
| 15911 |
VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && pBuffer && pAllocation); |
| 15912 |
|
| 15913 |
if(pBufferCreateInfo->size == 0) |
| 15914 |
{ |
| 15915 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 15916 |
} |
| 15917 |
if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_COPY) != 0 && |
| 15918 |
!allocator->m_UseKhrBufferDeviceAddress) |
| 15919 |
{ |
| 15920 |
VMA_ASSERT(0 && "Creating a buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT is not valid if VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT was not used."); |
| 15921 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 15922 |
} |
| 15923 |
|
| 15924 |
VMA_DEBUG_LOG("vmaCreateBuffer"); |
| 15925 |
|
| 15926 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 15927 |
|
| 15928 |
*pBuffer = VK_NULL_HANDLE; |
| 15929 |
*pAllocation = VK_NULL_HANDLE; |
| 15930 |
|
| 15931 |
|
| 15932 |
VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)( |
| 15933 |
allocator->m_hDevice, |
| 15934 |
pBufferCreateInfo, |
| 15935 |
allocator->GetAllocationCallbacks(), |
| 15936 |
pBuffer); |
| 15937 |
if(res >= 0) |
| 15938 |
{ |
| 15939 |
|
| 15940 |
VkMemoryRequirements vkMemReq = {}; |
| 15941 |
bool requiresDedicatedAllocation = false; |
| 15942 |
bool prefersDedicatedAllocation = false; |
| 15943 |
allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq, |
| 15944 |
requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 15945 |
|
| 15946 |
|
| 15947 |
res = allocator->AllocateMemory( |
| 15948 |
vkMemReq, |
| 15949 |
requiresDedicatedAllocation, |
| 15950 |
prefersDedicatedAllocation, |
| 15951 |
*pBuffer, |
| 15952 |
VK_NULL_HANDLE, |
| 15953 |
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), |
| 15954 |
*pAllocationCreateInfo, |
| 15955 |
VMA_SUBALLOCATION_TYPE_BUFFER, |
| 15956 |
1, |
| 15957 |
pAllocation); |
| 15958 |
|
| 15959 |
if(res >= 0) |
| 15960 |
{ |
| 15961 |
|
| 15962 |
if((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) |
| 15963 |
{ |
| 15964 |
res = allocator->BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL); |
| 15965 |
} |
| 15966 |
if(res >= 0) |
| 15967 |
{ |
| 15968 |
|
| 15969 |
#if VMA_STATS_STRING_ENABLED |
| 15970 |
(*pAllocation)->InitBufferUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5); |
| 15971 |
#endif |
| 15972 |
if(pAllocationInfo != VMA_NULL) |
| 15973 |
{ |
| 15974 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 15975 |
} |
| 15976 |
|
| 15977 |
return VK_SUCCESS; |
| 15978 |
} |
| 15979 |
allocator->FreeMemory( |
| 15980 |
1, |
| 15981 |
pAllocation); |
| 15982 |
*pAllocation = VK_NULL_HANDLE; |
| 15983 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); |
| 15984 |
*pBuffer = VK_NULL_HANDLE; |
| 15985 |
return res; |
| 15986 |
} |
| 15987 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); |
| 15988 |
*pBuffer = VK_NULL_HANDLE; |
| 15989 |
return res; |
| 15990 |
} |
| 15991 |
return res; |
| 15992 |
} |
| 15993 |
|
| 15994 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBufferWithAlignment( |
| 15995 |
VmaAllocator allocator, |
| 15996 |
const VkBufferCreateInfo* pBufferCreateInfo, |
| 15997 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 15998 |
VkDeviceSize minAlignment, |
| 15999 |
VkBuffer* pBuffer, |
| 16000 |
VmaAllocation* pAllocation, |
| 16001 |
VmaAllocationInfo* pAllocationInfo) |
| 16002 |
{ |
| 16003 |
VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && VmaIsPow2(minAlignment) && pBuffer && pAllocation); |
| 16004 |
|
| 16005 |
if(pBufferCreateInfo->size == 0) |
| 16006 |
{ |
| 16007 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16008 |
} |
| 16009 |
if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_COPY) != 0 && |
| 16010 |
!allocator->m_UseKhrBufferDeviceAddress) |
| 16011 |
{ |
| 16012 |
VMA_ASSERT(0 && "Creating a buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT is not valid if VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT was not used."); |
| 16013 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16014 |
} |
| 16015 |
|
| 16016 |
VMA_DEBUG_LOG("vmaCreateBufferWithAlignment"); |
| 16017 |
|
| 16018 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16019 |
|
| 16020 |
*pBuffer = VK_NULL_HANDLE; |
| 16021 |
*pAllocation = VK_NULL_HANDLE; |
| 16022 |
|
| 16023 |
|
| 16024 |
VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)( |
| 16025 |
allocator->m_hDevice, |
| 16026 |
pBufferCreateInfo, |
| 16027 |
allocator->GetAllocationCallbacks(), |
| 16028 |
pBuffer); |
| 16029 |
if(res >= 0) |
| 16030 |
{ |
| 16031 |
|
| 16032 |
VkMemoryRequirements vkMemReq = {}; |
| 16033 |
bool requiresDedicatedAllocation = false; |
| 16034 |
bool prefersDedicatedAllocation = false; |
| 16035 |
allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq, |
| 16036 |
requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 16037 |
|
| 16038 |
|
| 16039 |
vkMemReq.alignment = VMA_MAX(vkMemReq.alignment, minAlignment); |
| 16040 |
|
| 16041 |
|
| 16042 |
res = allocator->AllocateMemory( |
| 16043 |
vkMemReq, |
| 16044 |
requiresDedicatedAllocation, |
| 16045 |
prefersDedicatedAllocation, |
| 16046 |
*pBuffer, |
| 16047 |
VK_NULL_HANDLE, |
| 16048 |
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), |
| 16049 |
*pAllocationCreateInfo, |
| 16050 |
VMA_SUBALLOCATION_TYPE_BUFFER, |
| 16051 |
1, |
| 16052 |
pAllocation); |
| 16053 |
|
| 16054 |
if(res >= 0) |
| 16055 |
{ |
| 16056 |
|
| 16057 |
if((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) |
| 16058 |
{ |
| 16059 |
res = allocator->BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL); |
| 16060 |
} |
| 16061 |
if(res >= 0) |
| 16062 |
{ |
| 16063 |
|
| 16064 |
#if VMA_STATS_STRING_ENABLED |
| 16065 |
(*pAllocation)->InitBufferUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5); |
| 16066 |
#endif |
| 16067 |
if(pAllocationInfo != VMA_NULL) |
| 16068 |
{ |
| 16069 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 16070 |
} |
| 16071 |
|
| 16072 |
return VK_SUCCESS; |
| 16073 |
} |
| 16074 |
allocator->FreeMemory( |
| 16075 |
1, |
| 16076 |
pAllocation); |
| 16077 |
*pAllocation = VK_NULL_HANDLE; |
| 16078 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); |
| 16079 |
*pBuffer = VK_NULL_HANDLE; |
| 16080 |
return res; |
| 16081 |
} |
| 16082 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); |
| 16083 |
*pBuffer = VK_NULL_HANDLE; |
| 16084 |
return res; |
| 16085 |
} |
| 16086 |
return res; |
| 16087 |
} |
| 16088 |
|
| 16089 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingBuffer( |
| 16090 |
VmaAllocator VMA_NOT_NULL allocator, |
| 16091 |
VmaAllocation VMA_NOT_NULL allocation, |
| 16092 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 16093 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer) |
| 16094 |
{ |
| 16095 |
return vmaCreateAliasingBuffer2(allocator, allocation, 0, pBufferCreateInfo, pBuffer); |
| 16096 |
} |
| 16097 |
|
| 16098 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingBuffer2( |
| 16099 |
VmaAllocator VMA_NOT_NULL allocator, |
| 16100 |
VmaAllocation VMA_NOT_NULL allocation, |
| 16101 |
VkDeviceSize allocationLocalOffset, |
| 16102 |
const VkBufferCreateInfo* VMA_NOT_NULL pBufferCreateInfo, |
| 16103 |
VkBuffer VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pBuffer) |
| 16104 |
{ |
| 16105 |
VMA_ASSERT(allocator && pBufferCreateInfo && pBuffer && allocation); |
| 16106 |
VMA_ASSERT(allocationLocalOffset + pBufferCreateInfo->size <= allocation->GetSize()); |
| 16107 |
|
| 16108 |
VMA_DEBUG_LOG("vmaCreateAliasingBuffer2"); |
| 16109 |
|
| 16110 |
*pBuffer = VK_NULL_HANDLE; |
| 16111 |
|
| 16112 |
if (pBufferCreateInfo->size == 0) |
| 16113 |
{ |
| 16114 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16115 |
} |
| 16116 |
if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_COPY) != 0 && |
| 16117 |
!allocator->m_UseKhrBufferDeviceAddress) |
| 16118 |
{ |
| 16119 |
VMA_ASSERT(0 && "Creating a buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT is not valid if VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT was not used."); |
| 16120 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16121 |
} |
| 16122 |
|
| 16123 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16124 |
|
| 16125 |
|
| 16126 |
VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)( |
| 16127 |
allocator->m_hDevice, |
| 16128 |
pBufferCreateInfo, |
| 16129 |
allocator->GetAllocationCallbacks(), |
| 16130 |
pBuffer); |
| 16131 |
if (res >= 0) |
| 16132 |
{ |
| 16133 |
|
| 16134 |
res = allocator->BindBufferMemory(allocation, allocationLocalOffset, *pBuffer, VMA_NULL); |
| 16135 |
if (res >= 0) |
| 16136 |
{ |
| 16137 |
return VK_SUCCESS; |
| 16138 |
} |
| 16139 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); |
| 16140 |
} |
| 16141 |
return res; |
| 16142 |
} |
| 16143 |
|
| 16144 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyBuffer( |
| 16145 |
VmaAllocator allocator, |
| 16146 |
VkBuffer buffer, |
| 16147 |
VmaAllocation allocation) |
| 16148 |
{ |
| 16149 |
VMA_ASSERT(allocator); |
| 16150 |
|
| 16151 |
if(buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) |
| 16152 |
{ |
| 16153 |
return; |
| 16154 |
} |
| 16155 |
|
| 16156 |
VMA_DEBUG_LOG("vmaDestroyBuffer"); |
| 16157 |
|
| 16158 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16159 |
|
| 16160 |
if(buffer != VK_NULL_HANDLE) |
| 16161 |
{ |
| 16162 |
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks()); |
| 16163 |
} |
| 16164 |
|
| 16165 |
if(allocation != VK_NULL_HANDLE) |
| 16166 |
{ |
| 16167 |
allocator->FreeMemory( |
| 16168 |
1, |
| 16169 |
&allocation); |
| 16170 |
} |
| 16171 |
} |
| 16172 |
|
| 16173 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage( |
| 16174 |
VmaAllocator allocator, |
| 16175 |
const VkImageCreateInfo* pImageCreateInfo, |
| 16176 |
const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 16177 |
VkImage* pImage, |
| 16178 |
VmaAllocation* pAllocation, |
| 16179 |
VmaAllocationInfo* pAllocationInfo) |
| 16180 |
{ |
| 16181 |
VMA_ASSERT(allocator && pImageCreateInfo && pAllocationCreateInfo && pImage && pAllocation); |
| 16182 |
|
| 16183 |
if(pImageCreateInfo->extent.width == 0 || |
| 16184 |
pImageCreateInfo->extent.height == 0 || |
| 16185 |
pImageCreateInfo->extent.depth == 0 || |
| 16186 |
pImageCreateInfo->mipLevels == 0 || |
| 16187 |
pImageCreateInfo->arrayLayers == 0) |
| 16188 |
{ |
| 16189 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16190 |
} |
| 16191 |
|
| 16192 |
VMA_DEBUG_LOG("vmaCreateImage"); |
| 16193 |
|
| 16194 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16195 |
|
| 16196 |
*pImage = VK_NULL_HANDLE; |
| 16197 |
*pAllocation = VK_NULL_HANDLE; |
| 16198 |
|
| 16199 |
|
| 16200 |
VkResult res = (*allocator->GetVulkanFunctions().vkCreateImage)( |
| 16201 |
allocator->m_hDevice, |
| 16202 |
pImageCreateInfo, |
| 16203 |
allocator->GetAllocationCallbacks(), |
| 16204 |
pImage); |
| 16205 |
if(res >= 0) |
| 16206 |
{ |
| 16207 |
VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ? |
| 16208 |
VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL : |
| 16209 |
VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR; |
| 16210 |
|
| 16211 |
|
| 16212 |
VkMemoryRequirements vkMemReq = {}; |
| 16213 |
bool requiresDedicatedAllocation = false; |
| 16214 |
bool prefersDedicatedAllocation = false; |
| 16215 |
allocator->GetImageMemoryRequirements(*pImage, vkMemReq, |
| 16216 |
requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 16217 |
|
| 16218 |
res = allocator->AllocateMemory( |
| 16219 |
vkMemReq, |
| 16220 |
requiresDedicatedAllocation, |
| 16221 |
prefersDedicatedAllocation, |
| 16222 |
VK_NULL_HANDLE, |
| 16223 |
*pImage, |
| 16224 |
VmaBufferImageUsage(*pImageCreateInfo), |
| 16225 |
*pAllocationCreateInfo, |
| 16226 |
suballocType, |
| 16227 |
1, |
| 16228 |
pAllocation); |
| 16229 |
|
| 16230 |
if(res >= 0) |
| 16231 |
{ |
| 16232 |
|
| 16233 |
if((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) |
| 16234 |
{ |
| 16235 |
res = allocator->BindImageMemory(*pAllocation, 0, *pImage, VMA_NULL); |
| 16236 |
} |
| 16237 |
if(res >= 0) |
| 16238 |
{ |
| 16239 |
|
| 16240 |
#if VMA_STATS_STRING_ENABLED |
| 16241 |
(*pAllocation)->InitImageUsage(*pImageCreateInfo); |
| 16242 |
#endif |
| 16243 |
if(pAllocationInfo != VMA_NULL) |
| 16244 |
{ |
| 16245 |
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo); |
| 16246 |
} |
| 16247 |
|
| 16248 |
return VK_SUCCESS; |
| 16249 |
} |
| 16250 |
allocator->FreeMemory( |
| 16251 |
1, |
| 16252 |
pAllocation); |
| 16253 |
*pAllocation = VK_NULL_HANDLE; |
| 16254 |
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); |
| 16255 |
*pImage = VK_NULL_HANDLE; |
| 16256 |
return res; |
| 16257 |
} |
| 16258 |
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); |
| 16259 |
*pImage = VK_NULL_HANDLE; |
| 16260 |
return res; |
| 16261 |
} |
| 16262 |
return res; |
| 16263 |
} |
| 16264 |
|
| 16265 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingImage( |
| 16266 |
VmaAllocator VMA_NOT_NULL allocator, |
| 16267 |
VmaAllocation VMA_NOT_NULL allocation, |
| 16268 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 16269 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pImage) |
| 16270 |
{ |
| 16271 |
return vmaCreateAliasingImage2(allocator, allocation, 0, pImageCreateInfo, pImage); |
| 16272 |
} |
| 16273 |
|
| 16274 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAliasingImage2( |
| 16275 |
VmaAllocator VMA_NOT_NULL allocator, |
| 16276 |
VmaAllocation VMA_NOT_NULL allocation, |
| 16277 |
VkDeviceSize allocationLocalOffset, |
| 16278 |
const VkImageCreateInfo* VMA_NOT_NULL pImageCreateInfo, |
| 16279 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pImage) |
| 16280 |
{ |
| 16281 |
VMA_ASSERT(allocator && pImageCreateInfo && pImage && allocation); |
| 16282 |
|
| 16283 |
*pImage = VK_NULL_HANDLE; |
| 16284 |
|
| 16285 |
VMA_DEBUG_LOG("vmaCreateImage2"); |
| 16286 |
|
| 16287 |
if (pImageCreateInfo->extent.width == 0 || |
| 16288 |
pImageCreateInfo->extent.height == 0 || |
| 16289 |
pImageCreateInfo->extent.depth == 0 || |
| 16290 |
pImageCreateInfo->mipLevels == 0 || |
| 16291 |
pImageCreateInfo->arrayLayers == 0) |
| 16292 |
{ |
| 16293 |
return VK_ERROR_INITIALIZATION_FAILED; |
| 16294 |
} |
| 16295 |
|
| 16296 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16297 |
|
| 16298 |
|
| 16299 |
VkResult res = (*allocator->GetVulkanFunctions().vkCreateImage)( |
| 16300 |
allocator->m_hDevice, |
| 16301 |
pImageCreateInfo, |
| 16302 |
allocator->GetAllocationCallbacks(), |
| 16303 |
pImage); |
| 16304 |
if (res >= 0) |
| 16305 |
{ |
| 16306 |
|
| 16307 |
res = allocator->BindImageMemory(allocation, allocationLocalOffset, *pImage, VMA_NULL); |
| 16308 |
if (res >= 0) |
| 16309 |
{ |
| 16310 |
return VK_SUCCESS; |
| 16311 |
} |
| 16312 |
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); |
| 16313 |
} |
| 16314 |
return res; |
| 16315 |
} |
| 16316 |
|
| 16317 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyImage( |
| 16318 |
VmaAllocator VMA_NOT_NULL allocator, |
| 16319 |
VkImage VMA_NULLABLE_NON_DISPATCHABLE image, |
| 16320 |
VmaAllocation VMA_NULLABLE allocation) |
| 16321 |
{ |
| 16322 |
VMA_ASSERT(allocator); |
| 16323 |
|
| 16324 |
if(image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) |
| 16325 |
{ |
| 16326 |
return; |
| 16327 |
} |
| 16328 |
|
| 16329 |
VMA_DEBUG_LOG("vmaDestroyImage"); |
| 16330 |
|
| 16331 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK |
| 16332 |
|
| 16333 |
if(image != VK_NULL_HANDLE) |
| 16334 |
{ |
| 16335 |
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks()); |
| 16336 |
} |
| 16337 |
if(allocation != VK_NULL_HANDLE) |
| 16338 |
{ |
| 16339 |
allocator->FreeMemory( |
| 16340 |
1, |
| 16341 |
&allocation); |
| 16342 |
} |
| 16343 |
} |
| 16344 |
|
| 16345 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateVirtualBlock( |
| 16346 |
const VmaVirtualBlockCreateInfo* VMA_NOT_NULL pCreateInfo, |
| 16347 |
VmaVirtualBlock VMA_NULLABLE * VMA_NOT_NULL pVirtualBlock) |
| 16348 |
{ |
| 16349 |
VMA_ASSERT(pCreateInfo && pVirtualBlock); |
| 16350 |
VMA_ASSERT(pCreateInfo->size > 0); |
| 16351 |
VMA_DEBUG_LOG("vmaCreateVirtualBlock"); |
| 16352 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16353 |
*pVirtualBlock = vma_new(pCreateInfo->pAllocationCallbacks, VmaVirtualBlock_T)(*pCreateInfo); |
| 16354 |
VkResult res = (*pVirtualBlock)->Init(); |
| 16355 |
if(res < 0) |
| 16356 |
{ |
| 16357 |
vma_delete(pCreateInfo->pAllocationCallbacks, *pVirtualBlock); |
| 16358 |
*pVirtualBlock = VK_NULL_HANDLE; |
| 16359 |
} |
| 16360 |
return res; |
| 16361 |
} |
| 16362 |
|
| 16363 |
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyVirtualBlock(VmaVirtualBlock VMA_NULLABLE virtualBlock) |
| 16364 |
{ |
| 16365 |
if(virtualBlock != VK_NULL_HANDLE) |
| 16366 |
{ |
| 16367 |
VMA_DEBUG_LOG("vmaDestroyVirtualBlock"); |
| 16368 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16369 |
VkAllocationCallbacks allocationCallbacks = virtualBlock->m_AllocationCallbacks; |
| 16370 |
vma_delete(&allocationCallbacks, virtualBlock); |
| 16371 |
} |
| 16372 |
} |
| 16373 |
|
| 16374 |
VMA_CALL_PRE VkBool32 VMA_CALL_POST vmaIsVirtualBlockEmpty(VmaVirtualBlock VMA_NOT_NULL virtualBlock) |
| 16375 |
{ |
| 16376 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE); |
| 16377 |
VMA_DEBUG_LOG("vmaIsVirtualBlockEmpty"); |
| 16378 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16379 |
return virtualBlock->IsEmpty() ? VK_TRUE : VK_FALSE; |
| 16380 |
} |
| 16381 |
|
| 16382 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetVirtualAllocationInfo(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16383 |
VmaVirtualAllocation VMA_NOT_NULL_NON_DISPATCHABLE allocation, VmaVirtualAllocationInfo* VMA_NOT_NULL pVirtualAllocInfo) |
| 16384 |
{ |
| 16385 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && pVirtualAllocInfo != VMA_NULL); |
| 16386 |
VMA_DEBUG_LOG("vmaGetVirtualAllocationInfo"); |
| 16387 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16388 |
virtualBlock->GetAllocationInfo(allocation, *pVirtualAllocInfo); |
| 16389 |
} |
| 16390 |
|
| 16391 |
VMA_CALL_PRE VkResult VMA_CALL_POST vmaVirtualAllocate(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16392 |
const VmaVirtualAllocationCreateInfo* VMA_NOT_NULL pCreateInfo, VmaVirtualAllocation VMA_NULLABLE_NON_DISPATCHABLE* VMA_NOT_NULL pAllocation, |
| 16393 |
VkDeviceSize* VMA_NULLABLE pOffset) |
| 16394 |
{ |
| 16395 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && pCreateInfo != VMA_NULL && pAllocation != VMA_NULL); |
| 16396 |
VMA_DEBUG_LOG("vmaVirtualAllocate"); |
| 16397 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16398 |
return virtualBlock->Allocate(*pCreateInfo, *pAllocation, pOffset); |
| 16399 |
} |
| 16400 |
|
| 16401 |
VMA_CALL_PRE void VMA_CALL_POST vmaVirtualFree(VmaVirtualBlock VMA_NOT_NULL virtualBlock, VmaVirtualAllocation VMA_NULLABLE_NON_DISPATCHABLE allocation) |
| 16402 |
{ |
| 16403 |
if(allocation != VK_NULL_HANDLE) |
| 16404 |
{ |
| 16405 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE); |
| 16406 |
VMA_DEBUG_LOG("vmaVirtualFree"); |
| 16407 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16408 |
virtualBlock->Free(allocation); |
| 16409 |
} |
| 16410 |
} |
| 16411 |
|
| 16412 |
VMA_CALL_PRE void VMA_CALL_POST vmaClearVirtualBlock(VmaVirtualBlock VMA_NOT_NULL virtualBlock) |
| 16413 |
{ |
| 16414 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE); |
| 16415 |
VMA_DEBUG_LOG("vmaClearVirtualBlock"); |
| 16416 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16417 |
virtualBlock->Clear(); |
| 16418 |
} |
| 16419 |
|
| 16420 |
VMA_CALL_PRE void VMA_CALL_POST vmaSetVirtualAllocationUserData(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16421 |
VmaVirtualAllocation VMA_NOT_NULL_NON_DISPATCHABLE allocation, void* VMA_NULLABLE pUserData) |
| 16422 |
{ |
| 16423 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE); |
| 16424 |
VMA_DEBUG_LOG("vmaSetVirtualAllocationUserData"); |
| 16425 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16426 |
virtualBlock->SetAllocationUserData(allocation, pUserData); |
| 16427 |
} |
| 16428 |
|
| 16429 |
VMA_CALL_PRE void VMA_CALL_POST vmaGetVirtualBlockStatistics(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16430 |
VmaStatistics* VMA_NOT_NULL pStats) |
| 16431 |
{ |
| 16432 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && pStats != VMA_NULL); |
| 16433 |
VMA_DEBUG_LOG("vmaGetVirtualBlockStatistics"); |
| 16434 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16435 |
virtualBlock->GetStatistics(*pStats); |
| 16436 |
} |
| 16437 |
|
| 16438 |
VMA_CALL_PRE void VMA_CALL_POST vmaCalculateVirtualBlockStatistics(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16439 |
VmaDetailedStatistics* VMA_NOT_NULL pStats) |
| 16440 |
{ |
| 16441 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && pStats != VMA_NULL); |
| 16442 |
VMA_DEBUG_LOG("vmaCalculateVirtualBlockStatistics"); |
| 16443 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16444 |
virtualBlock->CalculateDetailedStatistics(*pStats); |
| 16445 |
} |
| 16446 |
|
| 16447 |
#if VMA_STATS_STRING_ENABLED |
| 16448 |
|
| 16449 |
VMA_CALL_PRE void VMA_CALL_POST vmaBuildVirtualBlockStatsString(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16450 |
char* VMA_NULLABLE * VMA_NOT_NULL ppStatsString, VkBool32 detailedMap) |
| 16451 |
{ |
| 16452 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && ppStatsString != VMA_NULL); |
| 16453 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16454 |
const VkAllocationCallbacks* allocationCallbacks = virtualBlock->GetAllocationCallbacks(); |
| 16455 |
VmaStringBuilder sb(allocationCallbacks); |
| 16456 |
virtualBlock->BuildStatsString(detailedMap != VK_FALSE, sb); |
| 16457 |
*ppStatsString = VmaCreateStringCopy(allocationCallbacks, sb.GetData(), sb.GetLength()); |
| 16458 |
} |
| 16459 |
|
| 16460 |
VMA_CALL_PRE void VMA_CALL_POST vmaFreeVirtualBlockStatsString(VmaVirtualBlock VMA_NOT_NULL virtualBlock, |
| 16461 |
char* VMA_NULLABLE pStatsString) |
| 16462 |
{ |
| 16463 |
if(pStatsString != VMA_NULL) |
| 16464 |
{ |
| 16465 |
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE); |
| 16466 |
VMA_DEBUG_GLOBAL_MUTEX_LOCK; |
| 16467 |
VmaFreeString(virtualBlock->GetAllocationCallbacks(), pStatsString); |
| 16468 |
} |
| 16469 |
} |
| 16470 |
#endif |
| 16471 |
#endif |
| 16472 |
#endif |
| 16473 |
|
| 16474 |
|
| 16475 |
|
| 16476 |
|
| 16477 |
|
| 16478 |
|
| 16479 |
|
| 16480 |
|
| 16481 |
|
| 16482 |
|
| 16483 |
|
| 16484 |
|
| 16485 |
|
| 16486 |
|
| 16487 |
|
| 16488 |
|
| 16489 |
|
| 16490 |
|
| 16491 |
|
| 16492 |
|
| 16493 |
|
| 16494 |
|
| 16495 |
|
| 16496 |
|
| 16497 |
|
| 16498 |
|
| 16499 |
|
| 16500 |
|
| 16501 |
|
| 16502 |
|
| 16503 |
|
| 16504 |
|
| 16505 |
|
| 16506 |
|
| 16507 |
|
| 16508 |
|
| 16509 |
|
| 16510 |
|
| 16511 |
|
| 16512 |
|
| 16513 |
|
| 16514 |
|
| 16515 |
|
| 16516 |
|
| 16517 |
|
| 16518 |
|
| 16519 |
|
| 16520 |
|
| 16521 |
|
| 16522 |
|
| 16523 |
|
| 16524 |
|
| 16525 |
|
| 16526 |
|
| 16527 |
|
| 16528 |
|
| 16529 |
|
| 16530 |
|
| 16531 |
|
| 16532 |
|
| 16533 |
|
| 16534 |
|
| 16535 |
|
| 16536 |
|
| 16537 |
|
| 16538 |
|
| 16539 |
|
| 16540 |
|
| 16541 |
|
| 16542 |
|
| 16543 |
|
| 16544 |
|
| 16545 |
|
| 16546 |
|
| 16547 |
|
| 16548 |
|
| 16549 |
|
| 16550 |
|
| 16551 |
|
| 16552 |
|
| 16553 |
|
| 16554 |
|
| 16555 |
|
| 16556 |
|
| 16557 |
|
| 16558 |
|
| 16559 |
|
| 16560 |
|
| 16561 |
|
| 16562 |
|
| 16563 |
|
| 16564 |
|
| 16565 |
|
| 16566 |
|
| 16567 |
|
| 16568 |
|
| 16569 |
|
| 16570 |
|
| 16571 |
|
| 16572 |
|
| 16573 |
|
| 16574 |
|
| 16575 |
|
| 16576 |
|
| 16577 |
|
| 16578 |
|
| 16579 |
|
| 16580 |
|
| 16581 |
|
| 16582 |
|
| 16583 |
|
| 16584 |
|
| 16585 |
|
| 16586 |
|
| 16587 |
|
| 16588 |
|
| 16589 |
|
| 16590 |
|
| 16591 |
|
| 16592 |
|
| 16593 |
|
| 16594 |
|
| 16595 |
|
| 16596 |
|
| 16597 |
|
| 16598 |
|
| 16599 |
|
| 16600 |
|
| 16601 |
|
| 16602 |
|
| 16603 |
|
| 16604 |
|
| 16605 |
|
| 16606 |
|
| 16607 |
|
| 16608 |
|
| 16609 |
|
| 16610 |
|
| 16611 |
|
| 16612 |
|
| 16613 |
|
| 16614 |
|
| 16615 |
|
| 16616 |
|
| 16617 |
|
| 16618 |
|
| 16619 |
|
| 16620 |
|
| 16621 |
|
| 16622 |
|
| 16623 |
|
| 16624 |
|
| 16625 |
|
| 16626 |
|
| 16627 |
|
| 16628 |
|
| 16629 |
|
| 16630 |
|
| 16631 |
|
| 16632 |
|
| 16633 |
|
| 16634 |
|
| 16635 |
|
| 16636 |
|
| 16637 |
|
| 16638 |
|
| 16639 |
|
| 16640 |
|
| 16641 |
|
| 16642 |
|
| 16643 |
|
| 16644 |
|
| 16645 |
|
| 16646 |
|
| 16647 |
|
| 16648 |
|
| 16649 |
|
| 16650 |
|
| 16651 |
|
| 16652 |
|
| 16653 |
|
| 16654 |
|
| 16655 |
|
| 16656 |
|
| 16657 |
|
| 16658 |
|
| 16659 |
|
| 16660 |
|
| 16661 |
|
| 16662 |
|
| 16663 |
|
| 16664 |
|
| 16665 |
|
| 16666 |
|
| 16667 |
|
| 16668 |
|
| 16669 |
|
| 16670 |
|
| 16671 |
|
| 16672 |
|
| 16673 |
|
| 16674 |
|
| 16675 |
|
| 16676 |
|
| 16677 |
|
| 16678 |
|
| 16679 |
|
| 16680 |
|
| 16681 |
|
| 16682 |
|
| 16683 |
|
| 16684 |
|
| 16685 |
|
| 16686 |
|
| 16687 |
|
| 16688 |
|
| 16689 |
|
| 16690 |
|
| 16691 |
|
| 16692 |
|
| 16693 |
|
| 16694 |
|
| 16695 |
|
| 16696 |
|
| 16697 |
|
| 16698 |
|
| 16699 |
|
| 16700 |
|
| 16701 |
|
| 16702 |
|
| 16703 |
|
| 16704 |
|
| 16705 |
|
| 16706 |
|
| 16707 |
|
| 16708 |
|
| 16709 |
|
| 16710 |
|
| 16711 |
|
| 16712 |
|
| 16713 |
|
| 16714 |
|
| 16715 |
|
| 16716 |
|
| 16717 |
|
| 16718 |
|
| 16719 |
|
| 16720 |
|
| 16721 |
|
| 16722 |
|
| 16723 |
|
| 16724 |
|
| 16725 |
|
| 16726 |
|
| 16727 |
|
| 16728 |
|
| 16729 |
|
| 16730 |
|
| 16731 |
|
| 16732 |
|
| 16733 |
|
| 16734 |
|
| 16735 |
|
| 16736 |
|
| 16737 |
|
| 16738 |
|
| 16739 |
|
| 16740 |
|
| 16741 |
|
| 16742 |
|
| 16743 |
|
| 16744 |
|
| 16745 |
|
| 16746 |
|
| 16747 |
|
| 16748 |
|
| 16749 |
|
| 16750 |
|
| 16751 |
|
| 16752 |
|
| 16753 |
|
| 16754 |
|
| 16755 |
|
| 16756 |
|
| 16757 |
|
| 16758 |
|
| 16759 |
|
| 16760 |
|
| 16761 |
|
| 16762 |
|
| 16763 |
|
| 16764 |
|
| 16765 |
|
| 16766 |
|
| 16767 |
|
| 16768 |
|
| 16769 |
|
| 16770 |
|
| 16771 |
|
| 16772 |
|
| 16773 |
|
| 16774 |
|
| 16775 |
|
| 16776 |
|
| 16777 |
|
| 16778 |
|
| 16779 |
|
| 16780 |
|
| 16781 |
|
| 16782 |
|
| 16783 |
|
| 16784 |
|
| 16785 |
|
| 16786 |
|
| 16787 |
|
| 16788 |
|
| 16789 |
|
| 16790 |
|
| 16791 |
|
| 16792 |
|
| 16793 |
|
| 16794 |
|
| 16795 |
|
| 16796 |
|
| 16797 |
|
| 16798 |
|
| 16799 |
|
| 16800 |
|
| 16801 |
|
| 16802 |
|
| 16803 |
|
| 16804 |
|
| 16805 |
|
| 16806 |
|
| 16807 |
|
| 16808 |
|
| 16809 |
|
| 16810 |
|
| 16811 |
|
| 16812 |
|
| 16813 |
|
| 16814 |
|
| 16815 |
|
| 16816 |
|
| 16817 |
|
| 16818 |
|
| 16819 |
|
| 16820 |
|
| 16821 |
|
| 16822 |
|
| 16823 |
|
| 16824 |
|
| 16825 |
|
| 16826 |
|
| 16827 |
|
| 16828 |
|
| 16829 |
|
| 16830 |
|
| 16831 |
|
| 16832 |
|
| 16833 |
|
| 16834 |
|
| 16835 |
|
| 16836 |
|
| 16837 |
|
| 16838 |
|
| 16839 |
|
| 16840 |
|
| 16841 |
|
| 16842 |
|
| 16843 |
|
| 16844 |
|
| 16845 |
|
| 16846 |
|
| 16847 |
|
| 16848 |
|
| 16849 |
|
| 16850 |
|
| 16851 |
|
| 16852 |
|
| 16853 |
|
| 16854 |
|
| 16855 |
|
| 16856 |
|
| 16857 |
|
| 16858 |
|
| 16859 |
|
| 16860 |
|
| 16861 |
|
| 16862 |
|
| 16863 |
|
| 16864 |
|
| 16865 |
|
| 16866 |
|
| 16867 |
|
| 16868 |
|
| 16869 |
|
| 16870 |
|
| 16871 |
|
| 16872 |
|
| 16873 |
|
| 16874 |
|
| 16875 |
|
| 16876 |
|
| 16877 |
|
| 16878 |
|
| 16879 |
|
| 16880 |
|
| 16881 |
|
| 16882 |
|
| 16883 |
|
| 16884 |
|
| 16885 |
|
| 16886 |
|
| 16887 |
|
| 16888 |
|
| 16889 |
|
| 16890 |
|
| 16891 |
|
| 16892 |
|
| 16893 |
|
| 16894 |
|
| 16895 |
|
| 16896 |
|
| 16897 |
|
| 16898 |
|
| 16899 |
|
| 16900 |
|
| 16901 |
|
| 16902 |
|
| 16903 |
|
| 16904 |
|
| 16905 |
|
| 16906 |
|
| 16907 |
|
| 16908 |
|
| 16909 |
|
| 16910 |
|
| 16911 |
|
| 16912 |
|
| 16913 |
|
| 16914 |
|
| 16915 |
|
| 16916 |
|
| 16917 |
|
| 16918 |
|
| 16919 |
|
| 16920 |
|
| 16921 |
|
| 16922 |
|
| 16923 |
|
| 16924 |
|
| 16925 |
|
| 16926 |
|
| 16927 |
|
| 16928 |
|
| 16929 |
|
| 16930 |
|
| 16931 |
|
| 16932 |
|
| 16933 |
|
| 16934 |
|
| 16935 |
|
| 16936 |
|
| 16937 |
|
| 16938 |
|
| 16939 |
|
| 16940 |
|
| 16941 |
|
| 16942 |
|
| 16943 |
|
| 16944 |
|
| 16945 |
|
| 16946 |
|
| 16947 |
|
| 16948 |
|
| 16949 |
|
| 16950 |
|
| 16951 |
|
| 16952 |
|
| 16953 |
|
| 16954 |
|
| 16955 |
|
| 16956 |
|
| 16957 |
|
| 16958 |
|
| 16959 |
|
| 16960 |
|
| 16961 |
|
| 16962 |
|
| 16963 |
|
| 16964 |
|
| 16965 |
|
| 16966 |
|
| 16967 |
|
| 16968 |
|
| 16969 |
|
| 16970 |
|
| 16971 |
|
| 16972 |
|
| 16973 |
|
| 16974 |
|
| 16975 |
|
| 16976 |
|
| 16977 |
|
| 16978 |
|
| 16979 |
|
| 16980 |
|
| 16981 |
|
| 16982 |
|
| 16983 |
|
| 16984 |
|
| 16985 |
|
| 16986 |
|
| 16987 |
|
| 16988 |
|
| 16989 |
|
| 16990 |
|
| 16991 |
|
| 16992 |
|
| 16993 |
|
| 16994 |
|
| 16995 |
|
| 16996 |
|
| 16997 |
|
| 16998 |
|
| 16999 |
|
| 17000 |
|
| 17001 |
|
| 17002 |
|
| 17003 |
|
| 17004 |
|
| 17005 |
|
| 17006 |
|
| 17007 |
|
| 17008 |
|
| 17009 |
|
| 17010 |
|
| 17011 |
|
| 17012 |
|
| 17013 |
|
| 17014 |
|
| 17015 |
|
| 17016 |
|
| 17017 |
|
| 17018 |
|
| 17019 |
|
| 17020 |
|
| 17021 |
|
| 17022 |
|
| 17023 |
|
| 17024 |
|
| 17025 |
|
| 17026 |
|
| 17027 |
|
| 17028 |
|
| 17029 |
|
| 17030 |
|
| 17031 |
|
| 17032 |
|
| 17033 |
|
| 17034 |
|
| 17035 |
|
| 17036 |
|
| 17037 |
|
| 17038 |
|
| 17039 |
|
| 17040 |
|
| 17041 |
|
| 17042 |
|
| 17043 |
|
| 17044 |
|
| 17045 |
|
| 17046 |
|
| 17047 |
|
| 17048 |
|
| 17049 |
|
| 17050 |
|
| 17051 |
|
| 17052 |
|
| 17053 |
|
| 17054 |
|
| 17055 |
|
| 17056 |
|
| 17057 |
|
| 17058 |
|
| 17059 |
|
| 17060 |
|
| 17061 |
|
| 17062 |
|
| 17063 |
|
| 17064 |
|
| 17065 |
|
| 17066 |
|
| 17067 |
|
| 17068 |
|
| 17069 |
|
| 17070 |
|
| 17071 |
|
| 17072 |
|
| 17073 |
|
| 17074 |
|
| 17075 |
|
| 17076 |
|
| 17077 |
|
| 17078 |
|
| 17079 |
|
| 17080 |
|
| 17081 |
|
| 17082 |
|
| 17083 |
|
| 17084 |
|
| 17085 |
|
| 17086 |
|
| 17087 |
|
| 17088 |
|
| 17089 |
|
| 17090 |
|
| 17091 |
|
| 17092 |
|
| 17093 |
|
| 17094 |
|
| 17095 |
|
| 17096 |
|
| 17097 |
|
| 17098 |
|
| 17099 |
|
| 17100 |
|
| 17101 |
|
| 17102 |
|
| 17103 |
|
| 17104 |
|
| 17105 |
|
| 17106 |
|
| 17107 |
|
| 17108 |
|
| 17109 |
|
| 17110 |
|
| 17111 |
|
| 17112 |
|
| 17113 |
|
| 17114 |
|
| 17115 |
|
| 17116 |
|
| 17117 |
|
| 17118 |
|
| 17119 |
|
| 17120 |
|
| 17121 |
|
| 17122 |
|
| 17123 |
|
| 17124 |
|
| 17125 |
|
| 17126 |
|
| 17127 |
|
| 17128 |
|
| 17129 |
|
| 17130 |
|
| 17131 |
|
| 17132 |
|
| 17133 |
|
| 17134 |
|
| 17135 |
|
| 17136 |
|
| 17137 |
|
| 17138 |
|
| 17139 |
|
| 17140 |
|
| 17141 |
|
| 17142 |
|
| 17143 |
|
| 17144 |
|
| 17145 |
|
| 17146 |
|
| 17147 |
|
| 17148 |
|
| 17149 |
|
| 17150 |
|
| 17151 |
|
| 17152 |
|
| 17153 |
|
| 17154 |
|
| 17155 |
|
| 17156 |
|
| 17157 |
|
| 17158 |
|
| 17159 |
|
| 17160 |
|
| 17161 |
|
| 17162 |
|
| 17163 |
|
| 17164 |
|
| 17165 |
|
| 17166 |
|
| 17167 |
|
| 17168 |
|
| 17169 |
|
| 17170 |
|
| 17171 |
|
| 17172 |
|
| 17173 |
|
| 17174 |
|
| 17175 |
|
| 17176 |
|
| 17177 |
|
| 17178 |
|
| 17179 |
|
| 17180 |
|
| 17181 |
|
| 17182 |
|
| 17183 |
|
| 17184 |
|
| 17185 |
|
| 17186 |
|
| 17187 |
|
| 17188 |
|
| 17189 |
|
| 17190 |
|
| 17191 |
|
| 17192 |
|
| 17193 |
|
| 17194 |
|
| 17195 |
|
| 17196 |
|
| 17197 |
|
| 17198 |
|
| 17199 |
|
| 17200 |
|
| 17201 |
|
| 17202 |
|
| 17203 |
|
| 17204 |
|
| 17205 |
|
| 17206 |
|
| 17207 |
|
| 17208 |
|
| 17209 |
|
| 17210 |
|
| 17211 |
|
| 17212 |
|
| 17213 |
|
| 17214 |
|
| 17215 |
|
| 17216 |
|
| 17217 |
|
| 17218 |
|
| 17219 |
|
| 17220 |
|
| 17221 |
|
| 17222 |
|
| 17223 |
|
| 17224 |
|
| 17225 |
|
| 17226 |
|
| 17227 |
|
| 17228 |
|
| 17229 |
|
| 17230 |
|
| 17231 |
|
| 17232 |
|
| 17233 |
|
| 17234 |
|
| 17235 |
|
| 17236 |
|
| 17237 |
|
| 17238 |
|
| 17239 |
|
| 17240 |
|
| 17241 |
|
| 17242 |
|
| 17243 |
|
| 17244 |
|
| 17245 |
|
| 17246 |
|
| 17247 |
|
| 17248 |
|
| 17249 |
|
| 17250 |
|
| 17251 |
|
| 17252 |
|
| 17253 |
|
| 17254 |
|
| 17255 |
|
| 17256 |
|
| 17257 |
|
| 17258 |
|
| 17259 |
|
| 17260 |
|
| 17261 |
|
| 17262 |
|
| 17263 |
|
| 17264 |
|
| 17265 |
|
| 17266 |
|
| 17267 |
|
| 17268 |
|
| 17269 |
|
| 17270 |
|
| 17271 |
|
| 17272 |
|
| 17273 |
|
| 17274 |
|
| 17275 |
|
| 17276 |
|
| 17277 |
|
| 17278 |
|
| 17279 |
|
| 17280 |
|
| 17281 |
|
| 17282 |
|
| 17283 |
|
| 17284 |
|
| 17285 |
|
| 17286 |
|
| 17287 |
|
| 17288 |
|
| 17289 |
|
| 17290 |
|
| 17291 |
|
| 17292 |
|
| 17293 |
|
| 17294 |
|
| 17295 |
|
| 17296 |
|
| 17297 |
|
| 17298 |
|
| 17299 |
|
| 17300 |
|
| 17301 |
|
| 17302 |
|
| 17303 |
|
| 17304 |
|
| 17305 |
|
| 17306 |
|
| 17307 |
|
| 17308 |
|
| 17309 |
|
| 17310 |
|
| 17311 |
|
| 17312 |
|
| 17313 |
|
| 17314 |
|
| 17315 |
|
| 17316 |
|
| 17317 |
|
| 17318 |
|
| 17319 |
|
| 17320 |
|
| 17321 |
|
| 17322 |
|
| 17323 |
|
| 17324 |
|
| 17325 |
|
| 17326 |
|
| 17327 |
|
| 17328 |
|
| 17329 |
|
| 17330 |
|
| 17331 |
|
| 17332 |
|
| 17333 |
|
| 17334 |
|
| 17335 |
|
| 17336 |
|
| 17337 |
|
| 17338 |
|
| 17339 |
|
| 17340 |
|
| 17341 |
|
| 17342 |
|
| 17343 |
|
| 17344 |
|
| 17345 |
|
| 17346 |
|
| 17347 |
|
| 17348 |
|
| 17349 |
|
| 17350 |
|
| 17351 |
|
| 17352 |
|
| 17353 |
|
| 17354 |
|
| 17355 |
|
| 17356 |
|
| 17357 |
|
| 17358 |
|
| 17359 |
|
| 17360 |
|
| 17361 |
|
| 17362 |
|
| 17363 |
|
| 17364 |
|
| 17365 |
|
| 17366 |
|
| 17367 |
|
| 17368 |
|
| 17369 |
|
| 17370 |
|
| 17371 |
|
| 17372 |
|
| 17373 |
|
| 17374 |
|
| 17375 |
|
| 17376 |
|
| 17377 |
|
| 17378 |
|
| 17379 |
|
| 17380 |
|
| 17381 |
|
| 17382 |
|
| 17383 |
|
| 17384 |
|
| 17385 |
|
| 17386 |
|
| 17387 |
|
| 17388 |
|
| 17389 |
|
| 17390 |
|
| 17391 |
|
| 17392 |
|
| 17393 |
|
| 17394 |
|
| 17395 |
|
| 17396 |
|
| 17397 |
|
| 17398 |
|
| 17399 |
|
| 17400 |
|
| 17401 |
|
| 17402 |
|
| 17403 |
|
| 17404 |
|
| 17405 |
|
| 17406 |
|
| 17407 |
|
| 17408 |
|
| 17409 |
|
| 17410 |
|
| 17411 |
|
| 17412 |
|
| 17413 |
|
| 17414 |
|
| 17415 |
|
| 17416 |
|
| 17417 |
|
| 17418 |
|
| 17419 |
|
| 17420 |
|
| 17421 |
|
| 17422 |
|
| 17423 |
|
| 17424 |
|
| 17425 |
|
| 17426 |
|
| 17427 |
|
| 17428 |
|
| 17429 |
|
| 17430 |
|
| 17431 |
|
| 17432 |
|
| 17433 |
|
| 17434 |
|
| 17435 |
|
| 17436 |
|
| 17437 |
|
| 17438 |
|
| 17439 |
|
| 17440 |
|
| 17441 |
|
| 17442 |
|
| 17443 |
|
| 17444 |
|
| 17445 |
|
| 17446 |
|
| 17447 |
|
| 17448 |
|
| 17449 |
|
| 17450 |
|
| 17451 |
|
| 17452 |
|
| 17453 |
|
| 17454 |
|
| 17455 |
|
| 17456 |
|
| 17457 |
|
| 17458 |
|
| 17459 |
|
| 17460 |
|
| 17461 |
|
| 17462 |
|
| 17463 |
|
| 17464 |
|
| 17465 |
|
| 17466 |
|
| 17467 |
|
| 17468 |
|
| 17469 |
|
| 17470 |
|
| 17471 |
|
| 17472 |
|
| 17473 |
|
| 17474 |
|
| 17475 |
|
| 17476 |
|
| 17477 |
|
| 17478 |
|
| 17479 |
|
| 17480 |
|
| 17481 |
|
| 17482 |
|
| 17483 |
|
| 17484 |
|
| 17485 |
|
| 17486 |
|
| 17487 |
|
| 17488 |
|
| 17489 |
|
| 17490 |
|
| 17491 |
|
| 17492 |
|
| 17493 |
|
| 17494 |
|
| 17495 |
|
| 17496 |
|
| 17497 |
|
| 17498 |
|
| 17499 |
|
| 17500 |
|
| 17501 |
|
| 17502 |
|
| 17503 |
|
| 17504 |
|
| 17505 |
|
| 17506 |
|
| 17507 |
|
| 17508 |
|
| 17509 |
|
| 17510 |
|
| 17511 |
|
| 17512 |
|
| 17513 |
|
| 17514 |
|
| 17515 |
|
| 17516 |
|
| 17517 |
|
| 17518 |
|
| 17519 |
|
| 17520 |
|
| 17521 |
|
| 17522 |
|
| 17523 |
|
| 17524 |
|
| 17525 |
|
| 17526 |
|
| 17527 |
|
| 17528 |
|
| 17529 |
|
| 17530 |
|
| 17531 |
|
| 17532 |
|
| 17533 |
|
| 17534 |
|
| 17535 |
|
| 17536 |
|
| 17537 |
|
| 17538 |
|
| 17539 |
|
| 17540 |
|
| 17541 |
|
| 17542 |
|
| 17543 |
|
| 17544 |
|
| 17545 |
|
| 17546 |
|
| 17547 |
|
| 17548 |
|
| 17549 |
|
| 17550 |
|
| 17551 |
|
| 17552 |
|
| 17553 |
|
| 17554 |
|
| 17555 |
|
| 17556 |
|
| 17557 |
|
| 17558 |
|
| 17559 |
|
| 17560 |
|
| 17561 |
|
| 17562 |
|
| 17563 |
|
| 17564 |
|
| 17565 |
|
| 17566 |
|
| 17567 |
|
| 17568 |
|
| 17569 |
|
| 17570 |
|
| 17571 |
|
| 17572 |
|
| 17573 |
|
| 17574 |
|
| 17575 |
|
| 17576 |
|
| 17577 |
|
| 17578 |
|
| 17579 |
|
| 17580 |
|
| 17581 |
|
| 17582 |
|
| 17583 |
|
| 17584 |
|
| 17585 |
|
| 17586 |
|
| 17587 |
|
| 17588 |
|
| 17589 |
|
| 17590 |
|
| 17591 |
|
| 17592 |
|
| 17593 |
|
| 17594 |
|
| 17595 |
|
| 17596 |
|
| 17597 |
|
| 17598 |
|
| 17599 |
|
| 17600 |
|
| 17601 |
|
| 17602 |
|
| 17603 |
|
| 17604 |
|
| 17605 |
|
| 17606 |
|
| 17607 |
|
| 17608 |
|
| 17609 |
|
| 17610 |
|
| 17611 |
|
| 17612 |
|
| 17613 |
|
| 17614 |
|
| 17615 |
|
| 17616 |
|
| 17617 |
|
| 17618 |
|
| 17619 |
|
| 17620 |
|
| 17621 |
|
| 17622 |
|
| 17623 |
|
| 17624 |
|
| 17625 |
|
| 17626 |
|
| 17627 |
|
| 17628 |
|
| 17629 |
|
| 17630 |
|
| 17631 |
|
| 17632 |
|
| 17633 |
|
| 17634 |
|
| 17635 |
|
| 17636 |
|
| 17637 |
|
| 17638 |
|
| 17639 |
|
| 17640 |
|
| 17641 |
|
| 17642 |
|
| 17643 |
|
| 17644 |
|
| 17645 |
|
| 17646 |
|
| 17647 |
|
| 17648 |
|
| 17649 |
|
| 17650 |
|
| 17651 |
|
| 17652 |
|
| 17653 |
|
| 17654 |
|
| 17655 |
|
| 17656 |
|
| 17657 |
|
| 17658 |
|
| 17659 |
|
| 17660 |
|
| 17661 |
|
| 17662 |
|
| 17663 |
|
| 17664 |
|
| 17665 |
|
| 17666 |
|
| 17667 |
|
| 17668 |
|
| 17669 |
|
| 17670 |
|
| 17671 |
|
| 17672 |
|
| 17673 |
|
| 17674 |
|
| 17675 |
|
| 17676 |
|
| 17677 |
|
| 17678 |
|
| 17679 |
|
| 17680 |
|
| 17681 |
|
| 17682 |
|
| 17683 |
|
| 17684 |
|
| 17685 |
|
| 17686 |
|
| 17687 |
|
| 17688 |
|
| 17689 |
|
| 17690 |
|
| 17691 |
|
| 17692 |
|
| 17693 |
|
| 17694 |
|
| 17695 |
|
| 17696 |
|
| 17697 |
|
| 17698 |
|
| 17699 |
|
| 17700 |
|
| 17701 |
|
| 17702 |
|
| 17703 |
|
| 17704 |
|
| 17705 |
|
| 17706 |
|
| 17707 |
|
| 17708 |
|
| 17709 |
|
| 17710 |
|
| 17711 |
|
| 17712 |
|
| 17713 |
|
| 17714 |
|
| 17715 |
|
| 17716 |
|
| 17717 |
|
| 17718 |
|
| 17719 |
|
| 17720 |
|
| 17721 |
|
| 17722 |
|
| 17723 |
|
| 17724 |
|
| 17725 |
|
| 17726 |
|
| 17727 |
|
| 17728 |
|
| 17729 |
|
| 17730 |
|
| 17731 |
|
| 17732 |
|
| 17733 |
|
| 17734 |
|
| 17735 |
|
| 17736 |
|
| 17737 |
|
| 17738 |
|
| 17739 |
|
| 17740 |
|
| 17741 |
|
| 17742 |
|
| 17743 |
|
| 17744 |
|
| 17745 |
|
| 17746 |
|
| 17747 |
|
| 17748 |
|
| 17749 |
|
| 17750 |
|
| 17751 |
|
| 17752 |
|
| 17753 |
|
| 17754 |
|
| 17755 |
|
| 17756 |
|
| 17757 |
|
| 17758 |
|
| 17759 |
|
| 17760 |
|
| 17761 |
|
| 17762 |
|
| 17763 |
|
| 17764 |
|
| 17765 |
|
| 17766 |
|
| 17767 |
|
| 17768 |
|
| 17769 |
|
| 17770 |
|
| 17771 |
|
| 17772 |
|
| 17773 |
|
| 17774 |
|
| 17775 |
|
| 17776 |
|
| 17777 |
|
| 17778 |
|
| 17779 |
|
| 17780 |
|
| 17781 |
|
| 17782 |
|
| 17783 |
|
| 17784 |
|
| 17785 |
|
| 17786 |
|
| 17787 |
|
| 17788 |
|
| 17789 |
|
| 17790 |
|
| 17791 |
|
| 17792 |
|
| 17793 |
|
| 17794 |
|
| 17795 |
|
| 17796 |
|
| 17797 |
|
| 17798 |
|
| 17799 |
|
| 17800 |
|
| 17801 |
|
| 17802 |
|
| 17803 |
|
| 17804 |
|
| 17805 |
|
| 17806 |
|
| 17807 |
|
| 17808 |
|
| 17809 |
|
| 17810 |
|
| 17811 |
|
| 17812 |
|
| 17813 |
|
| 17814 |
|
| 17815 |
|
| 17816 |
|
| 17817 |
|
| 17818 |
|
| 17819 |
|
| 17820 |
|
| 17821 |
|
| 17822 |
|
| 17823 |
|
| 17824 |
|
| 17825 |
|
| 17826 |
|
| 17827 |
|
| 17828 |
|
| 17829 |
|
| 17830 |
|
| 17831 |
|
| 17832 |
|
| 17833 |
|
| 17834 |
|
| 17835 |
|
| 17836 |
|
| 17837 |
|
| 17838 |
|
| 17839 |
|
| 17840 |
|
| 17841 |
|
| 17842 |
|
| 17843 |
|
| 17844 |
|
| 17845 |
|
| 17846 |
|
| 17847 |
|
| 17848 |
|
| 17849 |
|
| 17850 |
|
| 17851 |
|
| 17852 |
|
| 17853 |
|
| 17854 |
|
| 17855 |
|
| 17856 |
|
| 17857 |
|
| 17858 |
|
| 17859 |
|
| 17860 |
|
| 17861 |
|
| 17862 |
|
| 17863 |
|
| 17864 |
|
| 17865 |
|
| 17866 |
|
| 17867 |
|
| 17868 |
|
| 17869 |
|
| 17870 |
|
| 17871 |
|
| 17872 |
|
| 17873 |
|
| 17874 |
|
| 17875 |
|
| 17876 |
|
| 17877 |
|
| 17878 |
|
| 17879 |
|
| 17880 |
|
| 17881 |
|
| 17882 |
|
| 17883 |
|
| 17884 |
|
| 17885 |
|
| 17886 |
|
| 17887 |
|
| 17888 |
|
| 17889 |
|
| 17890 |
|
| 17891 |
|
| 17892 |
|
| 17893 |
|
| 17894 |
|
| 17895 |
|
| 17896 |
|
| 17897 |
|
| 17898 |
|
| 17899 |
|
| 17900 |
|
| 17901 |
|
| 17902 |
|
| 17903 |
|
| 17904 |
|
| 17905 |
|
| 17906 |
|
| 17907 |
|
| 17908 |
|
| 17909 |
|
| 17910 |
|
| 17911 |
|
| 17912 |
|
| 17913 |
|
| 17914 |
|
| 17915 |
|
| 17916 |
|
| 17917 |
|
| 17918 |
|
| 17919 |
|
| 17920 |
|
| 17921 |
|
| 17922 |
|
| 17923 |
|
| 17924 |
|
| 17925 |
|
| 17926 |
|
| 17927 |
|
| 17928 |
|
| 17929 |
|
| 17930 |
|
| 17931 |
|
| 17932 |
|
| 17933 |
|
| 17934 |
|
| 17935 |
|
| 17936 |
|
| 17937 |
|
| 17938 |
|
| 17939 |
|
| 17940 |
|
| 17941 |
|
| 17942 |
|
| 17943 |
|
| 17944 |
|
| 17945 |
|
| 17946 |
|
| 17947 |
|
| 17948 |
|
| 17949 |
|
| 17950 |
|
| 17951 |
|
| 17952 |
|
| 17953 |
|
| 17954 |
|
| 17955 |
|
| 17956 |
|
| 17957 |
|
| 17958 |
|
| 17959 |
|
| 17960 |
|
| 17961 |
|
| 17962 |
|
| 17963 |
|
| 17964 |
|
| 17965 |
|
| 17966 |
|
| 17967 |
|
| 17968 |
|
| 17969 |
|
| 17970 |
|
| 17971 |
|
| 17972 |
|
| 17973 |
|
| 17974 |
|
| 17975 |
|
| 17976 |
|
| 17977 |
|
| 17978 |
|
| 17979 |
|
| 17980 |
|
| 17981 |
|
| 17982 |
|
| 17983 |
|
| 17984 |
|
| 17985 |
|
| 17986 |
|
| 17987 |
|
| 17988 |
|
| 17989 |
|
| 17990 |
|
| 17991 |
|
| 17992 |
|
| 17993 |
|
| 17994 |
|
| 17995 |
|
| 17996 |
|
| 17997 |
|
| 17998 |
|
| 17999 |
|
| 18000 |
|
| 18001 |
|
| 18002 |
|
| 18003 |
|
| 18004 |
|
| 18005 |
|
| 18006 |
|
| 18007 |
|
| 18008 |
|
| 18009 |
|
| 18010 |
|
| 18011 |
|
| 18012 |
|
| 18013 |
|
| 18014 |
|
| 18015 |
|
| 18016 |
|
| 18017 |
|
| 18018 |
|
| 18019 |
|
| 18020 |
|
| 18021 |
|
| 18022 |
|
| 18023 |
|
| 18024 |
|
| 18025 |
|
| 18026 |
|
| 18027 |
|
| 18028 |
|
| 18029 |
|
| 18030 |
|
| 18031 |
|
| 18032 |
|
| 18033 |
|
| 18034 |
|
| 18035 |
|
| 18036 |
|
| 18037 |
|
| 18038 |
|
| 18039 |
|
| 18040 |
|
| 18041 |
|
| 18042 |
|
| 18043 |
|
| 18044 |
|
| 18045 |
|
| 18046 |
|
| 18047 |
|
| 18048 |
|
| 18049 |
|
| 18050 |
|
| 18051 |
|
| 18052 |
|
| 18053 |
|
| 18054 |
|
| 18055 |
|
| 18056 |
|
| 18057 |
|
| 18058 |
|
| 18059 |
|
| 18060 |
|
| 18061 |
|
| 18062 |
|
| 18063 |
|
| 18064 |
|
| 18065 |
|
| 18066 |
|
| 18067 |
|
| 18068 |
|
| 18069 |
|
| 18070 |
|
| 18071 |
|
| 18072 |
|
| 18073 |
|
| 18074 |
|
| 18075 |
|
| 18076 |
|
| 18077 |
|
| 18078 |
|
| 18079 |
|
| 18080 |
|
| 18081 |
|
| 18082 |
|
| 18083 |
|
| 18084 |
|
| 18085 |
|
| 18086 |
|
| 18087 |
|
| 18088 |
|
| 18089 |
|
| 18090 |
|
| 18091 |
|
| 18092 |
|
| 18093 |
|
| 18094 |
|
| 18095 |
|
| 18096 |
|
| 18097 |
|
| 18098 |
|
| 18099 |
|
| 18100 |
|
| 18101 |
|
| 18102 |
|
| 18103 |
|
| 18104 |
|
| 18105 |
|
| 18106 |
|
| 18107 |
|
| 18108 |
|
| 18109 |
|
| 18110 |
|
| 18111 |
|
| 18112 |
|
| 18113 |
|
| 18114 |
|
| 18115 |
|
| 18116 |
|
| 18117 |
|
| 18118 |
|
| 18119 |
|
| 18120 |
|
| 18121 |
|
| 18122 |
|
| 18123 |
|
| 18124 |
|
| 18125 |
|
| 18126 |
|
| 18127 |
|
| 18128 |
|
| 18129 |
|
| 18130 |
|
| 18131 |
|
| 18132 |
|
| 18133 |
|
| 18134 |
|
| 18135 |
|
| 18136 |
|
| 18137 |
|
| 18138 |
|
| 18139 |
|
| 18140 |
|
| 18141 |
|
| 18142 |
|
| 18143 |
|
| 18144 |
|
| 18145 |
|
| 18146 |
|
| 18147 |
|
| 18148 |
|
| 18149 |
|
| 18150 |
|
| 18151 |
|
| 18152 |
|
| 18153 |
|
| 18154 |
|
| 18155 |
|
| 18156 |
|
| 18157 |
|
| 18158 |
|
| 18159 |
|
| 18160 |
|
| 18161 |
|
| 18162 |
|
| 18163 |
|
| 18164 |
|
| 18165 |
|
| 18166 |
|
| 18167 |
|
| 18168 |
|
| 18169 |
|
| 18170 |
|
| 18171 |
|
| 18172 |
|
| 18173 |
|
| 18174 |
|
| 18175 |
|
| 18176 |
|
| 18177 |
|
| 18178 |
|
| 18179 |
|
| 18180 |
|
| 18181 |
|
| 18182 |
|
| 18183 |
|
| 18184 |
|
| 18185 |
|
| 18186 |
|
| 18187 |
|
| 18188 |
|
| 18189 |
|
| 18190 |
|
| 18191 |
|
| 18192 |
|
| 18193 |
|
| 18194 |
|
| 18195 |
|
| 18196 |
|
| 18197 |
|
| 18198 |
|
| 18199 |
|
| 18200 |
|
| 18201 |
|
| 18202 |
|
| 18203 |
|
| 18204 |
|
| 18205 |
|
| 18206 |
|
| 18207 |
|
| 18208 |
|
| 18209 |
|
| 18210 |
|
| 18211 |
|
| 18212 |
|
| 18213 |
|
| 18214 |
|
| 18215 |
|
| 18216 |
|
| 18217 |
|
| 18218 |
|
| 18219 |
|
| 18220 |
|
| 18221 |
|
| 18222 |
|
| 18223 |
|
| 18224 |
|
| 18225 |
|
| 18226 |
|
| 18227 |
|
| 18228 |
|
| 18229 |
|
| 18230 |
|
| 18231 |
|
| 18232 |
|
| 18233 |
|
| 18234 |
|
| 18235 |
|
| 18236 |
|
| 18237 |
|
| 18238 |
|
| 18239 |
|
| 18240 |
|
| 18241 |
|
| 18242 |
|
| 18243 |
|
| 18244 |
|
| 18245 |
|
| 18246 |
|
| 18247 |
|
| 18248 |
|
| 18249 |
|
| 18250 |
|
| 18251 |
|
| 18252 |
|
| 18253 |
|
| 18254 |
|
| 18255 |
|
| 18256 |
|
| 18257 |
|
| 18258 |
|
| 18259 |
|
| 18260 |
|
| 18261 |
|
| 18262 |
|
| 18263 |
|
| 18264 |
|
| 18265 |
|
| 18266 |
|
| 18267 |
|
| 18268 |
|
| 18269 |
|
| 18270 |
|
| 18271 |
|
| 18272 |
|
| 18273 |
|
| 18274 |
|
| 18275 |
|
| 18276 |
|
| 18277 |
|
| 18278 |
|
| 18279 |
|
| 18280 |
|
| 18281 |
|
| 18282 |
|
| 18283 |
|
| 18284 |
|
| 18285 |
|
| 18286 |
|
| 18287 |
|
| 18288 |
|
| 18289 |
|
| 18290 |
|
| 18291 |
|
| 18292 |
|
| 18293 |
|
| 18294 |
|
| 18295 |
|
| 18296 |
|
| 18297 |
|
| 18298 |
|
| 18299 |
|
| 18300 |
|
| 18301 |
|
| 18302 |
|
| 18303 |
|
| 18304 |
|
| 18305 |
|
| 18306 |
|
| 18307 |
|
| 18308 |
|
| 18309 |
|
| 18310 |
|
| 18311 |
|
| 18312 |
|
| 18313 |
|
| 18314 |
|
| 18315 |
|
| 18316 |
|
| 18317 |
|
| 18318 |
|
| 18319 |
|
| 18320 |
|
| 18321 |
|
| 18322 |
|
| 18323 |
|
| 18324 |
|
| 18325 |
|
| 18326 |
|
| 18327 |
|
| 18328 |
|
| 18329 |
|
| 18330 |
|
| 18331 |
|
| 18332 |
|
| 18333 |
|
| 18334 |
|
| 18335 |
|
| 18336 |
|
| 18337 |
|
| 18338 |
|
| 18339 |
|
| 18340 |
|
| 18341 |
|
| 18342 |
|
| 18343 |
|
| 18344 |
|
| 18345 |
|
| 18346 |
|
| 18347 |
|
| 18348 |
|
| 18349 |
|
| 18350 |
|
| 18351 |
|
| 18352 |
|
| 18353 |
|
| 18354 |
|
| 18355 |
|
| 18356 |
|
| 18357 |
|
| 18358 |
|
| 18359 |
|
| 18360 |
|
| 18361 |
|
| 18362 |
|
| 18363 |
|
| 18364 |
|
| 18365 |
|
| 18366 |
|
| 18367 |
|
| 18368 |
|
| 18369 |
|
| 18370 |
|
| 18371 |
|
| 18372 |
|
| 18373 |
|
| 18374 |
|
| 18375 |
|
| 18376 |
|
| 18377 |
|
| 18378 |
|
| 18379 |
|
| 18380 |
|
| 18381 |
|
| 18382 |
|
| 18383 |
|
| 18384 |
|
| 18385 |
|
| 18386 |
|
| 18387 |
|
| 18388 |
|
| 18389 |
|
| 18390 |
|
| 18391 |
|
| 18392 |
|
| 18393 |
|
| 18394 |
|
| 18395 |
|
| 18396 |
|
| 18397 |
|
| 18398 |
|
| 18399 |
|
| 18400 |
|
| 18401 |
|
| 18402 |
|
| 18403 |
|
| 18404 |
|
| 18405 |
|
| 18406 |
|
| 18407 |
|
| 18408 |
|
| 18409 |
|
| 18410 |
|
| 18411 |
|
| 18412 |
|
| 18413 |
|
| 18414 |
|
| 18415 |
|
| 18416 |
|
| 18417 |
|
| 18418 |
|
| 18419 |
|
| 18420 |
|
| 18421 |
|
| 18422 |
|
| 18423 |
|
| 18424 |
|
| 18425 |
|
| 18426 |
|
| 18427 |
|
| 18428 |
|
| 18429 |
|
| 18430 |
|
| 18431 |
|
| 18432 |
|
| 18433 |
|
| 18434 |
|
| 18435 |
|
| 18436 |
|
| 18437 |
|
| 18438 |
|
| 18439 |
|
| 18440 |
|
| 18441 |
|
| 18442 |
|
| 18443 |
|
| 18444 |
|
| 18445 |
|
| 18446 |
|
| 18447 |
|
| 18448 |
|
| 18449 |
|
| 18450 |
|
| 18451 |
|
| 18452 |
|
| 18453 |
|
| 18454 |
|
| 18455 |
|
| 18456 |
|
| 18457 |
|
| 18458 |
|
| 18459 |
|
| 18460 |
|
| 18461 |
|
| 18462 |
|
| 18463 |
|
| 18464 |
|
| 18465 |
|
| 18466 |
|
| 18467 |
|
| 18468 |
|
| 18469 |
|
| 18470 |
|
| 18471 |
|
| 18472 |
|
| 18473 |
|
| 18474 |
|
| 18475 |
|
| 18476 |
|
| 18477 |
|
| 18478 |
|
| 18479 |
|
| 18480 |
|
| 18481 |
|
| 18482 |
|
| 18483 |
|
| 18484 |
|
| 18485 |
|
| 18486 |
|
| 18487 |
|
| 18488 |
|
| 18489 |
|
| 18490 |
|
| 18491 |
|
| 18492 |
|
| 18493 |
|
| 18494 |
|
| 18495 |
|
| 18496 |
|
| 18497 |
|
| 18498 |
|
| 18499 |
|
| 18500 |
|
| 18501 |
|
| 18502 |
|
| 18503 |
|
| 18504 |
|
| 18505 |
|
| 18506 |
|
| 18507 |
|
| 18508 |
|
| 18509 |
|
| 18510 |
|
| 18511 |
|
| 18512 |
|
| 18513 |
|
| 18514 |
|
| 18515 |
|
| 18516 |
|
| 18517 |
|
| 18518 |
|
| 18519 |
|
| 18520 |
|
| 18521 |
|
| 18522 |
|
| 18523 |
|
| 18524 |
|
| 18525 |
|
| 18526 |
|
| 18527 |
|
| 18528 |
|
| 18529 |
|
| 18530 |
|
| 18531 |
|
| 18532 |
|
| 18533 |
|
| 18534 |
|
| 18535 |
|
| 18536 |
|
| 18537 |
|
| 18538 |
|
| 18539 |
|
| 18540 |
|
| 18541 |
|
| 18542 |
|
| 18543 |
|
| 18544 |
|
| 18545 |
|
| 18546 |
|
| 18547 |
|
| 18548 |
|
| 18549 |
|
| 18550 |
|
| 18551 |
|
| 18552 |
|
| 18553 |
|
| 18554 |
|
| 18555 |
|
| 18556 |
|
| 18557 |
|
| 18558 |
|
| 18559 |
|
| 18560 |
|
| 18561 |
|
| 18562 |
|
| 18563 |
|
| 18564 |
|
| 18565 |
|
| 18566 |
|
| 18567 |
|
| 18568 |
|
| 18569 |
|
| 18570 |
|
| 18571 |
|
| 18572 |
|
| 18573 |
|
| 18574 |
|
| 18575 |
|
| 18576 |
|
| 18577 |
|
| 18578 |
|
| 18579 |
|
| 18580 |
|
| 18581 |
|
| 18582 |
|
| 18583 |
|
| 18584 |
|
| 18585 |
|
| 18586 |
|
| 18587 |
|
| 18588 |
|
| 18589 |
|
| 18590 |
|
| 18591 |
|
| 18592 |
|
| 18593 |
|
| 18594 |
|
| 18595 |
|
| 18596 |
|
| 18597 |
|
| 18598 |
|
| 18599 |
|
| 18600 |
|
| 18601 |
|
| 18602 |
|
| 18603 |
|
| 18604 |
|
| 18605 |
|
| 18606 |
|
| 18607 |
|
| 18608 |
|
| 18609 |
|
| 18610 |
|
| 18611 |
|
| 18612 |
|
| 18613 |
|
| 18614 |
|
| 18615 |
|
| 18616 |
|
| 18617 |
|
| 18618 |
|
| 18619 |
|
| 18620 |
|
| 18621 |
|
| 18622 |
|
| 18623 |
|
| 18624 |
|
| 18625 |
|
| 18626 |
|
| 18627 |
|
| 18628 |
|
| 18629 |
|
| 18630 |
|
| 18631 |
|
| 18632 |
|
| 18633 |
|
| 18634 |
|
| 18635 |
|
| 18636 |
|
| 18637 |
|
| 18638 |
|
| 18639 |
|
| 18640 |
|
| 18641 |
|
| 18642 |
|
| 18643 |
|
| 18644 |
|
| 18645 |
|
| 18646 |
|
| 18647 |
|
| 18648 |
|
| 18649 |
|
| 18650 |
|
| 18651 |
|
| 18652 |
|
| 18653 |
|
| 18654 |
|
| 18655 |
|
| 18656 |
|
| 18657 |
|
| 18658 |
|
| 18659 |
|
| 18660 |
|
| 18661 |
|
| 18662 |
|
| 18663 |
|
| 18664 |
|
| 18665 |
|
| 18666 |
|
| 18667 |
|
| 18668 |
|
| 18669 |
|
| 18670 |
|
| 18671 |
|
| 18672 |
|
| 18673 |
|
| 18674 |
|
| 18675 |
|
| 18676 |
|
| 18677 |
|
| 18678 |
|
| 18679 |
|
| 18680 |
|
| 18681 |
|
| 18682 |
|
| 18683 |
|
| 18684 |
|
| 18685 |
|
| 18686 |
|
| 18687 |
|
| 18688 |
|
| 18689 |
|
| 18690 |
|
| 18691 |
|
| 18692 |
|
| 18693 |
|
| 18694 |
|
| 18695 |
|
| 18696 |
|
| 18697 |
|
| 18698 |
|
| 18699 |
|
| 18700 |
|
| 18701 |
|
| 18702 |
|
| 18703 |
|
| 18704 |
|
| 18705 |
|
| 18706 |
|
| 18707 |
|
| 18708 |
|
| 18709 |
|