-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,204 additions
and
838 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved. | ||
* Copyright (c) 2024, Bradley Austin Davis. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 the "License"; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "allocated.h" | ||
|
||
namespace vkb | ||
{ | ||
|
||
namespace core | ||
{ | ||
|
||
[[nodiscard]] std::pair<VkBuffer, VmaAllocation> vma_create_buffer(VmaAllocator alloctor, const VkBufferCreateInfo &create_info, VmaAllocationCreateInfo &alloc_create_info, VmaAllocationInfo *alloc_info) | ||
{ | ||
VkBuffer handle = VK_NULL_HANDLE; | ||
VmaAllocation allocation = VK_NULL_HANDLE; | ||
|
||
// The existing code produces some weird combinations, like in gui.cpp where you see this... | ||
|
||
if (alloc_create_info.usage < VMA_MEMORY_USAGE_AUTO) | ||
{ | ||
alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO; | ||
} | ||
|
||
auto result = vmaCreateBuffer( | ||
alloctor, | ||
&create_info, | ||
&alloc_create_info, | ||
&handle, | ||
&allocation, | ||
alloc_info); | ||
|
||
if (result != VK_SUCCESS) | ||
{ | ||
throw VulkanException{result, "Cannot create Buffer"}; | ||
} | ||
return {handle, allocation}; | ||
} | ||
|
||
[[nodiscard]] std::pair<VkImage, VmaAllocation> vma_create_image(VmaAllocator alloctor, const VkImageCreateInfo &create_info, VmaAllocationCreateInfo &alloc_create_info, VmaAllocationInfo *alloc_info) | ||
{ | ||
VkImage handle = VK_NULL_HANDLE; | ||
VmaAllocation allocation = VK_NULL_HANDLE; | ||
|
||
#if 0 | ||
// If the image is an attachment, prefer dedicated memory | ||
constexpr VkImageUsageFlags attachment_only_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; | ||
if (create_info.usage & attachment_only_flags) | ||
{ | ||
alloc_create_info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; | ||
} | ||
|
||
if (create_info.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) | ||
{ | ||
alloc_create_info.preferredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; | ||
} | ||
#endif | ||
|
||
auto result = vmaCreateImage( | ||
alloctor, | ||
&create_info, | ||
&alloc_create_info, | ||
&handle, | ||
&allocation, | ||
alloc_info); | ||
|
||
if (result != VK_SUCCESS) | ||
{ | ||
throw VulkanException{result, "Cannot create Image"}; | ||
} | ||
|
||
return {handle, allocation}; | ||
} | ||
|
||
} // namespace core | ||
} // namespace vkb |
Oops, something went wrong.