#include "deStringUtil.hpp"
#include "deUniquePtr.hpp"
-#include <set>
#include <string>
#include <vector>
using std::string;
using std::vector;
-using std::set;
using namespace vk;
for (size_t rangeNdx = 0; rangeNdx < count; rangeNdx++)
{
- const VkDeviceSize size = (VkDeviceSize)(rng.getUint64() % (deUint64)maxSize);
+ const VkDeviceSize size = (maxSize > 1 ? (VkDeviceSize)(1 + (rng.getUint64() % (deUint64)(maxSize - 1))) : 1);
const VkDeviceSize offset = (VkDeviceSize)(rng.getUint64() % (deUint64)(maxSize - size + 1));
const VkMappedMemoryRange range =
MemoryMapping* MemoryObject::mapRandom (const DeviceInterface& vkd, VkDevice device, de::Random& rng)
{
- const VkDeviceSize size = (VkDeviceSize)(rng.getUint64() % (deUint64)m_size);
+ const VkDeviceSize size = (m_size > 1 ? (VkDeviceSize)(1 + (rng.getUint64() % (deUint64)(m_size - 1))) : 1);
const VkDeviceSize offset = (VkDeviceSize)(rng.getUint64() % (deUint64)(m_size - size + 1));
void* ptr;
MAX_MEMORY_USAGE_DIV = 8
};
+template<typename T>
+void removeFirstEqual (vector<T>& vec, const T& val)
+{
+ for (size_t ndx = 0; ndx < vec.size(); ndx++)
+ {
+ if (vec[ndx] == val)
+ {
+ vec[ndx] = vec.back();
+ vec.pop_back();
+ return;
+ }
+ }
+}
+
class MemoryHeap
{
public:
~MemoryHeap (void)
{
- for (set<MemoryObject*>::iterator iter = m_objects.begin(); iter != m_objects.end(); ++iter)
+ for (vector<MemoryObject*>::iterator iter = m_objects.begin(); iter != m_objects.end(); ++iter)
delete *iter;
}
MemoryObject* allocateRandom (const DeviceInterface& vkd, VkDevice device, de::Random& rng)
{
- const VkDeviceSize size = rng.getUint64() % ((m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage);
+ const VkDeviceSize size = 1 + (rng.getUint64() % ((m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage - 1));
const deUint32 type = rng.choose<deUint32>(m_memoryTypes.begin(), m_memoryTypes.end());
MemoryObject* const object = new MemoryObject(vkd, device, size, type);
m_usage += size;
- m_objects.insert(object);
+ m_objects.push_back(object);
return object;
}
void free (MemoryObject* object)
{
- DE_ASSERT(m_objects.find(object) != m_objects.end());
- m_objects.erase(object);
+ removeFirstEqual(m_objects, object);
m_usage -= object->getSize();
delete object;
}
vector<deUint32> m_memoryTypes;
VkDeviceSize m_usage;
- set<MemoryObject*> m_objects;
+ vector<MemoryObject*> m_objects;
};
class RandomMemoryMappingInstance : public TestInstance
const de::SharedPtr<MemoryHeap> heap (new MemoryHeap(heapInfo, memoryTypes[heapIndex]));
if (!heap->full())
- m_nonFullHeaps.insert(heap);
+ m_nonFullHeaps.push_back(heap);
}
}
}
MemoryObject* const object = m_rng.choose<MemoryObject*>(m_mappedMemoryObjects.begin(), m_mappedMemoryObjects.end());
// Remove mapping
- m_memoryMappings.erase(object->getMapping());
+ removeFirstEqual(m_memoryMappings, object->getMapping());
object->unmap();
- m_mappedMemoryObjects.erase(object);
- m_nonMappedMemoryObjects.insert(object);
+ removeFirstEqual(m_mappedMemoryObjects, object);
+ m_nonMappedMemoryObjects.push_back(object);
}
else if (!m_nonMappedMemoryObjects.empty() && m_rng.getFloat() < mapProbability)
{
MemoryObject* const object = m_rng.choose<MemoryObject*>(m_nonMappedMemoryObjects.begin(), m_nonMappedMemoryObjects.end());
MemoryMapping* mapping = object->mapRandom(vkd, device, m_rng);
- m_memoryMappings.insert(mapping);
- m_mappedMemoryObjects.insert(object);
- m_nonMappedMemoryObjects.erase(object);
+ m_memoryMappings.push_back(mapping);
+ m_mappedMemoryObjects.push_back(object);
+ removeFirstEqual(m_nonMappedMemoryObjects, object);
}
else
{
de::SharedPtr<MemoryHeap> const heap = m_rng.choose<de::SharedPtr<MemoryHeap> >(m_nonFullHeaps.begin(), m_nonFullHeaps.end());
if (heap->empty())
- m_nonEmptyHeaps.insert(heap);
+ m_nonEmptyHeaps.push_back(heap);
{
MemoryObject* const object = heap->allocateRandom(vkd, device, m_rng);
if (heap->full())
- m_nonFullHeaps.erase(heap);
+ removeFirstEqual(m_nonFullHeaps, heap);
- m_nonMappedMemoryObjects.insert(object);
+ m_nonMappedMemoryObjects.push_back(object);
}
}
else
// Remove mapping
if (object->getMapping())
- m_memoryMappings.erase(object->getMapping());
+ removeFirstEqual(m_memoryMappings, object->getMapping());
- m_mappedMemoryObjects.erase(object);
- m_nonMappedMemoryObjects.erase(object);
+ removeFirstEqual(m_mappedMemoryObjects, object);
+ removeFirstEqual(m_nonMappedMemoryObjects, object);
if (heap->full())
- m_nonFullHeaps.insert(heap);
+ m_nonFullHeaps.push_back(heap);
heap->free(object);
if (heap->empty())
- m_nonEmptyHeaps.erase(heap);
+ removeFirstEqual(m_nonEmptyHeaps, heap);
}
}
}
private:
- de::Random m_rng;
- size_t m_opNdx;
+ de::Random m_rng;
+ size_t m_opNdx;
- set<de::SharedPtr<MemoryHeap> > m_nonEmptyHeaps;
- set<de::SharedPtr<MemoryHeap> > m_nonFullHeaps;
+ vector<de::SharedPtr<MemoryHeap> > m_nonEmptyHeaps;
+ vector<de::SharedPtr<MemoryHeap> > m_nonFullHeaps;
- set<MemoryObject*> m_mappedMemoryObjects;
- set<MemoryObject*> m_nonMappedMemoryObjects;
- set<MemoryMapping*> m_memoryMappings;
+ vector<MemoryObject*> m_mappedMemoryObjects;
+ vector<MemoryObject*> m_nonMappedMemoryObjects;
+ vector<MemoryMapping*> m_memoryMappings;
};
enum Op