Skip to content

Commit

Permalink
Fix vendor-specific/tied memory property flag detection (#771)
Browse files Browse the repository at this point in the history
* Add ktxTexture1/2 wrappers as well.
  • Loading branch information
toomuchvoltage authored Sep 17, 2023
1 parent aeca5e6 commit a100217
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
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 @@ -1474,6 +1474,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 @@ -1514,6 +1535,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))
{
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

0 comments on commit a100217

Please sign in to comment.