Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing vendor-specific/tied memory property flag detection #771

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/ktxvulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture *vkTexture);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_VkUploadEx_WithSuballocator(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
VkImageUsageFlags usageFlags,
VkImageLayout finalLayout,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_VkUploadEx(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
Expand All @@ -260,6 +267,13 @@ KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture *vkTexture);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_VkUploadEx_WithSuballocator(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
VkImageUsageFlags usageFlags,
VkImageLayout finalLayout,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_VkUploadEx(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
Expand Down
42 changes: 42 additions & 0 deletions lib/vkloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,27 @@ ktxTexture_VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}

/** @memberof ktxTexture1
* @~English
* @brief Create a Vulkan image object from a ktxTexture1 object.
*
* This simplly calls ktxTexture_VkUploadEx_WithSuballocator.
*
* @copydetails ktxTexture::ktxTexture_VkUploadEx_WithSuballocator
*/
KTX_error_code
ktxTexture1_VkUploadEx_WithSuballocator(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
VkImageUsageFlags usageFlags,
VkImageLayout finalLayout,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks)
{
return ktxTexture_VkUploadEx_WithSuballocator(ktxTexture(This), vdi, vkTexture,
tiling, usageFlags, finalLayout,
subAllocatorCallbacks);
}

/** @memberof ktxTexture1
* @~English
* @brief Create a Vulkan image object from a ktxTexture1 object.
Expand Down Expand Up @@ -1510,6 +1531,27 @@ ktxTexture1_VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}

/** @memberof ktxTexture2
* @~English
* @brief Create a Vulkan image object from a ktxTexture2 object.
*
* This simplly calls ktxTexture_VkUploadEx_WithSuballocator.
*
* @copydetails ktxTexture::ktxTexture_VkUploadEx_WithSuballocator
*/
KTX_error_code
ktxTexture2_VkUploadEx_WithSuballocator(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
VkImageUsageFlags usageFlags,
VkImageLayout finalLayout,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks)
{
return ktxTexture_VkUploadEx_WithSuballocator(ktxTexture(This), vdi, vkTexture,
tiling, usageFlags, finalLayout,
subAllocatorCallbacks);
}

/** @memberof ktxTexture2
* @~English
* @brief Create a Vulkan image object from a ktxTexture2 object.
Expand Down
2 changes: 1 addition & 1 deletion tests/loadtests/vkloadtests/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Texture::Texture(VulkanContext& vkctx,
if (useSubAlloc == UseSuballocator::Yes)
{
VkInstance vkInst = vkctx.instance;
VMA_CALLBACKS::InitVMA(vdi.physicalDevice, vdi.device, vkInst);
VMA_CALLBACKS::InitVMA(vdi.physicalDevice, vdi.device, vkInst, vdi.deviceMemoryProperties);

ktxresult = ktxTexture_VkUploadEx_WithSuballocator(kTexture, &vdi, &texture,
static_cast<VkImageTiling>(tiling),
Expand Down
9 changes: 7 additions & 2 deletions tests/loadtests/vkloadtests/VulkanLoadTestSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ namespace VMA_CALLBACKS
{
VmaAllocator vmaAllocator;
std::mt19937_64 mt64;
VkPhysicalDeviceMemoryProperties cachedDevMemProps;

void InitVMA(VkPhysicalDevice& physicalDevice, VkDevice& device, VkInstance& instance)
void InitVMA(VkPhysicalDevice& physicalDevice, VkDevice& device, VkInstance& instance,
VkPhysicalDeviceMemoryProperties& devMemProps)
{
cachedDevMemProps = devMemProps;

VmaVulkanFunctions vulkanFunctions = {};
vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;
vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr;
Expand Down Expand Up @@ -75,7 +79,8 @@ namespace VMA_CALLBACKS
{
uint64_t allocId = mt64();
VmaAllocationCreateInfo pCreateInfo = {};
if (allocInfo->memoryTypeIndex == 8)
if ((cachedDevMemProps.memoryTypes[allocInfo->memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ||
(cachedDevMemProps.memoryTypes[allocInfo->memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
toomuchvoltage marked this conversation as resolved.
Show resolved Hide resolved
{
pCreateInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
pCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
Expand Down
3 changes: 2 additions & 1 deletion tests/loadtests/vkloadtests/VulkanLoadTestSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace VMA_CALLBACKS
{
void InitVMA(VkPhysicalDevice& physicalDevice, VkDevice& device, VkInstance& instance);
void InitVMA(VkPhysicalDevice& physicalDevice, VkDevice& device, VkInstance& instance,
VkPhysicalDeviceMemoryProperties& devMemProps);
void DestroyVMA();
uint64_t AllocMemCWrapper(VkMemoryAllocateInfo* allocInfo, VkMemoryRequirements* memReq, uint64_t* numPages);
VkResult BindBufferMemoryCWrapper(VkBuffer buffer, uint64_t allocId);
Expand Down