Browse Source

Vk: Improve PhysicalDevice::getMemoryType(...) and doc++

Signed-off-by: Squareys <squareys@googlemail.com>
pull/202/head
Squareys 10 years ago committed by Squareys
parent
commit
ba28bdafd3
  1. 17
      src/Magnum/Vk/PhysicalDevice.cpp
  2. 23
      src/Magnum/Vk/PhysicalDevice.h

17
src/Magnum/Vk/PhysicalDevice.cpp

@ -82,18 +82,21 @@ UnsignedInt PhysicalDevice::getQueueFamilyIndex(QueueFamily family) {
CORRADE_ASSERT(false, "The device does not support the given queue family.", -1); // TODO
}
UnsignedInt PhysicalDevice::getMemoryType(UnsignedInt typeBits, VkFlags properties) {
UnsignedInt PhysicalDevice::getMemoryType(UnsignedInt supportedTypeBits, MemoryProperties properties) {
if(_deviceMemoryProperties.memoryHeapCount == 0 && _deviceMemoryProperties.memoryTypeCount == 0) {
/* first query for physical device memory properties */
vkGetPhysicalDeviceMemoryProperties(_physicalDevice, &_deviceMemoryProperties);
}
for (uint32_t i = 0; i < 32; i++) {
if((typeBits & 1) != 0) {
if((_deviceMemoryProperties.memoryTypes[i].propertyFlags & properties) == properties) {
return i;
}
const UnsignedInt p = UnsignedInt(properties);
for (UnsignedInt i = 0; i < 32; ++i) {
/* check whether the memory type at index i is supported */
const UnsignedInt memoryTypeSupported = (supportedTypeBits >> i) & 1;
if(memoryTypeSupported != 0 &&
(_deviceMemoryProperties.memoryTypes[i].propertyFlags & p) == p) {
/* memory type and properties match */
return i;
}
typeBits >>= 1;
}
CORRADE_ASSERT(false, "Physical devices does not support memory with given properties.", -1); // TODO

23
src/Magnum/Vk/PhysicalDevice.h

@ -33,11 +33,24 @@
#include "Magnum/Magnum.h"
#include "Magnum/Vk/visibility.h"
#include <Corrade/Containers/EnumSet.h>
#include "vulkan.h"
namespace Magnum { namespace Vk {
enum class MemoryProperty: UnsignedInt {
DeviceLocal = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
HostVisible = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Coherent = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
HostCached = VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
LazilyAllocated = VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT,
};
typedef Corrade::Containers::EnumSet<MemoryProperty> MemoryProperties;
CORRADE_ENUMSET_OPERATORS(MemoryProperties)
enum class QueueFamily: UnsignedInt {
Graphics = VK_QUEUE_GRAPHICS_BIT,
Compute = VK_QUEUE_COMPUTE_BIT,
@ -106,7 +119,15 @@ class MAGNUM_VK_EXPORT PhysicalDevice {
return deviceProperties;
}
UnsignedInt getMemoryType(UnsignedInt typeBits, VkFlags properties);
/**
* @brief Get the index of the memory type with properties
* @param supportedTypeBits A bit set with a bit for every memory type index. A
* bit at index i should be set if the memory type at index i
* is supported by the resource for which to get the memory type.
* @param properties Properties required by the memory type
* @return Index of the memory type for this device
*/
UnsignedInt getMemoryType(UnsignedInt supportedTypeBits, MemoryProperties properties);
private:
VkPhysicalDevice _physicalDevice;

Loading…
Cancel
Save