-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcmd_alloc.cpp
70 lines (62 loc) · 2.2 KB
/
cmd_alloc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "precompiled.h"
VkCommandBuffer VkCommandPool_T::alloc()
{
// brain dead algorithm
for(VkCommandBuffer c : buffers)
{
if(!c->live)
{
c->live = true;
return c;
}
}
VkCommandBuffer ret = new VkCommandBuffer_T;
ret->live = true;
buffers.push_back(ret);
return ret;
}
VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device,
const VkCommandPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkCommandPool *pCommandPool)
{
*pCommandPool = new VkCommandPool_T;
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
const VkAllocationCallbacks *pAllocator)
{
for(VkCommandBuffer c : commandPool->buffers)
delete c;
delete commandPool;
}
VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device,
const VkCommandBufferAllocateInfo *pAllocateInfo,
VkCommandBuffer *pCommandBuffers)
{
for(uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++)
{
VkCommandBuffer cmd = pAllocateInfo->commandPool->alloc();
set_loader_magic_value(cmd);
pCommandBuffers[i] = cmd;
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
uint32_t commandBufferCount,
const VkCommandBuffer *pCommandBuffers)
{
for(uint32_t i = 0; i < commandBufferCount; i++)
pCommandBuffers[i]->live = false;
}
byte *VkCommandBuffer_T::pushbytes(size_t sz)
{
size_t spare = commandStream.capacity() - commandStream.size();
// if there's no spare capacity, allocate more
if(sz > spare)
commandStream.reserve(commandStream.capacity() * 2 + sz);
// resize up to the newly used bytes, then return
byte *ret = commandStream.data() + commandStream.size();
commandStream.resize(commandStream.size() + sz);
return ret;
}