| 8733 | } |
| 8734 | |
| 8735 | bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress( |
| 8736 | VkDeviceSize allocSize, |
| 8737 | VkDeviceSize allocAlignment, |
| 8738 | VmaSuballocationType allocType, |
| 8739 | uint32_t strategy, |
| 8740 | VmaAllocationRequest* pAllocationRequest) |
| 8741 | { |
| 8742 | const VkDeviceSize blockSize = GetSize(); |
| 8743 | const VkDeviceSize bufferImageGranularity = GetBufferImageGranularity(); |
| 8744 | SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8745 | SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8746 | |
| 8747 | if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) |
| 8748 | { |
| 8749 | VMA_ASSERT(0 && "Trying to use pool with linear algorithm as double stack, while it is already being used as ring buffer."); |
| 8750 | return false; |
| 8751 | } |
| 8752 | |
| 8753 | // Try to allocate before 2nd.back(), or end of block if 2nd.empty(). |
| 8754 | if (allocSize > blockSize) |
| 8755 | { |
| 8756 | return false; |
| 8757 | } |
| 8758 | VkDeviceSize resultBaseOffset = blockSize - allocSize; |
| 8759 | if (!suballocations2nd.empty()) |
| 8760 | { |
| 8761 | const VmaSuballocation& lastSuballoc = suballocations2nd.back(); |
| 8762 | resultBaseOffset = lastSuballoc.offset - allocSize; |
| 8763 | if (allocSize > lastSuballoc.offset) |
| 8764 | { |
| 8765 | return false; |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | // Start from offset equal to end of free space. |
| 8770 | VkDeviceSize resultOffset = resultBaseOffset; |
| 8771 | |
| 8772 | const VkDeviceSize debugMargin = GetDebugMargin(); |
| 8773 | |
| 8774 | // Apply debugMargin at the end. |
| 8775 | if (debugMargin > 0) |
| 8776 | { |
| 8777 | if (resultOffset < debugMargin) |
| 8778 | { |
| 8779 | return false; |
| 8780 | } |
| 8781 | resultOffset -= debugMargin; |
| 8782 | } |
| 8783 | |
| 8784 | // Apply alignment. |
| 8785 | resultOffset = VmaAlignDown(resultOffset, allocAlignment); |
| 8786 | |
| 8787 | // Check next suballocations from 2nd for BufferImageGranularity conflicts. |
| 8788 | // Make bigger alignment if necessary. |
| 8789 | if (bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations2nd.empty()) |
| 8790 | { |
| 8791 | bool bufferImageGranularityConflict = false; |
| 8792 | for (size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; ) |
nothing calls this directly
no test coverage detected