static struct {
unsigned int flags;
int count;
+ int qfam;
+ VkCommandPool cmdpool;
} initq[MAX_INIT_QUEUE];
static int num_initq;
void vk_init_queue(unsigned int qflags, int count)
{
+ int i;
+
+ for(i=0; i<num_initq; i++) {
+ if(initq[i].flags == qflags) {
+ initq[i].count += count;
+ return;
+ }
+ }
+
if(num_initq >= MAX_INIT_QUEUE) {
fprintf(stderr, "vk_init_queue: too many queues\n");
return;
return q;
}
-VkQueue vk_getq(unsigned int flags)
+VkQueue vk_getq(unsigned int flags, int n)
+{
+ return vk_getq_fam(vk_find_qfamily(flags), n);
+}
+
+static VkCommandPool find_cmdpool(int qfam)
+{
+ int i;
+ VkCommandPoolCreateInfo pinf;
+
+ for(i=0; i<num_initq; i++) {
+ if(initq[i].qfam == qfam) {
+ if(!initq[i].cmdpool) {
+ /* allocate command pool for this queue family */
+ memset(&pinf, 0, sizeof pinf);
+ pinf.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
+ pinf.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
+ pinf.queueFamilyIndex = qfam;
+
+ if(vkCreateCommandPool(vkdev, &pinf, 0, &initq[i].cmdpool) != 0) {
+ fprintf(stderr, "ck_create_cmdbuf: failed to create command buffer pool\n");
+ return 0;
+ }
+ }
+ return initq[i].cmdpool;
+ }
+ }
+
+ fprintf(stderr, "vk_create_cmdbuf: failed to find command pool for queue family: %d\n", qfam);
+ return 0;
+}
+
+VkCommandBuffer vk_create_cmdbuf_fam(int qfam, int level)
{
- return vk_getq_fam(vk_find_qfamily(flags), 0);
+ VkCommandBufferAllocateInfo inf = {0};
+ VkCommandBuffer cmdbuf;
+ VkCommandPool cmdpool;
+
+ if(!(cmdpool = find_cmdpool(qfam))) {
+ return 0;
+ }
+
+ inf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
+ inf.commandPool = cmdpool;
+ inf.level = level;
+ inf.commandBufferCount = 1;
+
+ if(vkAllocateCommandBuffers(vkdev, &inf, &cmdbuf) != 0) {
+ fprintf(stderr, "vk_create_cmdbuf: failed to allocate command buffer\n");
+ return 0;
+ }
+ return cmdbuf;
+}
+
+VkCommandBuffer vk_create_cmdbuf(unsigned int qflags, int level)
+{
+ int qfam;
+
+ if((qfam = vk_find_qfamily(qflags)) == -1) {
+ fprintf(stderr, "vk_create_cmdbuf: failed to find matching queue family\n");
+ return 0;
+ }
+ return vk_create_cmdbuf_fam(qfam, level);
}
int vk_create_rpass(void)
initq[i].flags);
return -1;
}
+ initq[i].qfam = qfam;
+ initq[i].cmdpool = 0;
+
qinf[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
qinf[i].queueFamilyIndex = qfam;
qinf[i].queueCount = initq[i].count;
int vk_find_qfamily(unsigned int flags);
VkQueue vk_getq_fam(int fam, int n);
-VkQueue vk_getq(unsigned int flags);
+VkQueue vk_getq(unsigned int flags, int n);
+
+VkCommandBuffer vk_create_cmdbuf_fam(int qfam, int level);
+VkCommandBuffer vk_create_cmdbuf(unsigned int qflags, int level);
int vk_create_rpass(void);
void vk_free_rpass(int rp);