将memory_type_from_properties转移位置

This commit is contained in:
HuYingzhuo 2019-04-11 21:20:24 +08:00
parent 2e1f624090
commit fef0addac7
3 changed files with 25 additions and 22 deletions

View File

@ -166,4 +166,24 @@ RenderSurfaceAttribute::~RenderSurfaceAttribute()
if(surface)
vkDestroySurfaceKHR(instance,surface,nullptr);
}
bool RenderSurfaceAttribute::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex)
{
// Search memtypes to find first index with those properties
for(uint32_t i=0; i<memory_properties.memoryTypeCount; i++)
{
if((typeBits&1)==1)
{
// Type is available, does it match user properties?
if((memory_properties.memoryTypes[i].propertyFlags&requirements_mask)==requirements_mask)
{
*typeIndex=i;
return true;
}
}
typeBits>>=1;
}
// No memory types matched, return failure
return false;
}
VK_NAMESPACE_END

View File

@ -51,5 +51,7 @@ public:
RenderSurfaceAttribute(VkInstance inst,VkPhysicalDevice pd,VkSurfaceKHR s);
~RenderSurfaceAttribute();
bool CheckMemoryType(uint32_t,VkFlags,uint32_t *);
};//class RenderSurfaceAttribute
VK_NAMESPACE_END

View File

@ -171,27 +171,7 @@ namespace
return(true);
}
bool memory_type_from_properties(VkPhysicalDeviceMemoryProperties memory_properties,uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex)
{
// Search memtypes to find first index with those properties
for(uint32_t i=0; i<memory_properties.memoryTypeCount; i++)
{
if((typeBits&1)==1)
{
// Type is available, does it match user properties?
if((memory_properties.memoryTypes[i].propertyFlags&requirements_mask)==requirements_mask)
{
*typeIndex=i;
return true;
}
}
typeBits>>=1;
}
// No memory types matched, return failure
return false;
}
bool CreateDepthBuffer(RenderSurfaceAttribute *rsa)
{
VkImageCreateInfo image_info={};
@ -258,7 +238,8 @@ namespace
mem_alloc.memoryTypeIndex=0;
mem_alloc.allocationSize=mem_reqs.size;
bool pass=memory_type_from_properties(rsa->memory_properties,mem_reqs.memoryTypeBits,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&mem_alloc.memoryTypeIndex);
if(!rsa->CheckMemoryType(mem_reqs.memoryTypeBits,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&mem_alloc.memoryTypeIndex))
return(false);
if(vkAllocateMemory(rsa->device,&mem_alloc,nullptr,&rsa->depth.mem)!=VK_SUCCESS)
return(false);