| 3178 | } |
| 3179 | |
| 3180 | bool BlockMetadata_Generic::Validate() const |
| 3181 | { |
| 3182 | D3D12MA_VALIDATE(!m_Suballocations.empty()); |
| 3183 | |
| 3184 | // Expected offset of new suballocation as calculated from previous ones. |
| 3185 | UINT64 calculatedOffset = 0; |
| 3186 | // Expected number of free suballocations as calculated from traversing their list. |
| 3187 | UINT calculatedFreeCount = 0; |
| 3188 | // Expected sum size of free suballocations as calculated from traversing their list. |
| 3189 | UINT64 calculatedSumFreeSize = 0; |
| 3190 | // Expected number of free suballocations that should be registered in |
| 3191 | // m_FreeSuballocationsBySize calculated from traversing their list. |
| 3192 | size_t freeSuballocationsToRegister = 0; |
| 3193 | // True if previous visited suballocation was free. |
| 3194 | bool prevFree = false; |
| 3195 | |
| 3196 | for (const auto& subAlloc : m_Suballocations) |
| 3197 | { |
| 3198 | // Actual offset of this suballocation doesn't match expected one. |
| 3199 | D3D12MA_VALIDATE(subAlloc.offset == calculatedOffset); |
| 3200 | |
| 3201 | const bool currFree = (subAlloc.type == SUBALLOCATION_TYPE_FREE); |
| 3202 | // Two adjacent free suballocations are invalid. They should be merged. |
| 3203 | D3D12MA_VALIDATE(!prevFree || !currFree); |
| 3204 | |
| 3205 | const Allocation* const alloc = (Allocation*)subAlloc.privateData; |
| 3206 | if (!IsVirtual()) |
| 3207 | { |
| 3208 | D3D12MA_VALIDATE(currFree == (alloc == NULL)); |
| 3209 | } |
| 3210 | |
| 3211 | if (currFree) |
| 3212 | { |
| 3213 | calculatedSumFreeSize += subAlloc.size; |
| 3214 | ++calculatedFreeCount; |
| 3215 | if (subAlloc.size >= MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) |
| 3216 | { |
| 3217 | ++freeSuballocationsToRegister; |
| 3218 | } |
| 3219 | |
| 3220 | // Margin required between allocations - every free space must be at least that large. |
| 3221 | D3D12MA_VALIDATE(subAlloc.size >= GetDebugMargin()); |
| 3222 | } |
| 3223 | else |
| 3224 | { |
| 3225 | if (!IsVirtual()) |
| 3226 | { |
| 3227 | D3D12MA_VALIDATE(alloc->GetOffset() == subAlloc.offset); |
| 3228 | D3D12MA_VALIDATE(alloc->GetSize() == subAlloc.size); |
| 3229 | } |
| 3230 | |
| 3231 | // Margin required between allocations - previous allocation must be free. |
| 3232 | D3D12MA_VALIDATE(GetDebugMargin() == 0 || prevFree); |
| 3233 | } |
| 3234 | |
| 3235 | calculatedOffset += subAlloc.size; |
| 3236 | prevFree = currFree; |
| 3237 | } |
no test coverage detected