def create_render_resources(): global drawing_pool, cmd_draw, image_ready, rendering_done, render_fences # Render commands setup drawing_pool = hvk.create_command_pool( api, device, hvk.command_pool_create_info( queue_family_index=render_queue.family.index, flags=vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)) cmd_draw = hvk.allocate_command_buffers( api, device, hvk.command_buffer_allocate_info( command_pool=drawing_pool, command_buffer_count=len(swapchain_images))) # Render commands synchronisation resources info = hvk.semaphore_create_info() image_ready = hvk.create_semaphore(api, device, info) rendering_done = hvk.create_semaphore(api, device, info) info = hvk.fence_create_info(flags=vk.FENCE_CREATE_SIGNALED_BIT) render_fences = tuple( hvk.create_fence(api, device, info) for _ in range(len(swapchain_images)))
def _setup_compute_commands(self): engine, api, device = self.ctx compute_shaders = self.computes pool_create_info = hvk.command_pool_create_info( queue_family_index=0, flags=vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT) allocate_info = hvk.command_buffer_allocate_info( command_pool=0, command_buffer_count=0, level=vk.COMMAND_BUFFER_LEVEL_PRIMARY) # Count the number of compute command buffers that will be allocated per queue queues = tuple(engine.queues.values()) command_buffers_per_queues = [0 for q in queues] for index, queue in enumerate(queues): count = sum(1 for c in compute_shaders if c.queue is queue) command_buffers_per_queues[index] += count # Allocate a single command pool for every queue with at least 1 command buffer queue_pool_count = [] for index, count in enumerate(command_buffers_per_queues): if count == 0: continue queue = queues[index] pool_create_info.queue_family_index = queue.family.index pool = hvk.create_command_pool(api, device, pool_create_info) queue_pool_count.append((queue, pool, count)) # Allocate the commands buffers and link them with the compute process command_index = 0 command_buffers = [] for queue, pool, count in queue_pool_count: for c in compute_shaders: if c.queue != queue: continue c.command_index = command_index command_index += 1 allocate_info.command_pool = pool allocate_info.command_buffer_count = count buffers = hvk.allocate_command_buffers(api, device, allocate_info) command_buffers.extend(buffers) self.compute_pools = tuple((q, p) for q, p, _ in queue_pool_count) self.compute_commands = command_buffers
def create_staging_command(): global staging_pool, staging_cmd, staging_fence # Create staging resources for uploading staging_pool = hvk.create_command_pool( api, device, hvk.command_pool_create_info( queue_family_index=render_queue.family.index, flags=vk.COMMAND_POOL_CREATE_TRANSIENT_BIT | vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)) staging_cmd = hvk.allocate_command_buffers( api, device, hvk.command_buffer_allocate_info(command_pool=staging_pool, command_buffer_count=1))[0] staging_fence = hvk.create_fence(api, device, hvk.fence_create_info())
def _setup_render_commands(self): engine, api, device = self.ctx render_queue = engine.render_queue render_target = engine.render_target command_pool = hvk.create_command_pool( api, device, hvk.command_pool_create_info( queue_family_index=render_queue.family.index, flags=vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)) cmd_draw = hvk.allocate_command_buffers( api, device, hvk.command_buffer_allocate_info( command_pool=command_pool, command_buffer_count=render_target.framebuffer_count, level=vk.COMMAND_BUFFER_LEVEL_PRIMARY)) self.command_pool = command_pool self.render_commands = cmd_draw
def _setup_setup_commands(self): api, device = self.api, self.device render_queue = self.render_queue command_pool = hvk.create_command_pool(api, device, hvk.command_pool_create_info( queue_family_index = render_queue.family.index, flags = vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT )) cmds = hvk.allocate_command_buffers(api, device, hvk.command_buffer_allocate_info( command_pool = command_pool, command_buffer_count = 1 )) fence_info = hvk.fence_create_info() fence = hvk.create_fence(api, device, fence_info) self.command_pool = command_pool self.setup_command_buffer = cmds[0] self.setup_fence = fence