1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2021 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "vk_command_buffer.h" 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "vk_command_pool.h" 27bf215546Sopenharmony_ci#include "vk_common_entrypoints.h" 28bf215546Sopenharmony_ci#include "vk_device.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ciVkResult 31bf215546Sopenharmony_civk_command_buffer_init(struct vk_command_buffer *command_buffer, 32bf215546Sopenharmony_ci struct vk_command_pool *pool, 33bf215546Sopenharmony_ci VkCommandBufferLevel level) 34bf215546Sopenharmony_ci{ 35bf215546Sopenharmony_ci memset(command_buffer, 0, sizeof(*command_buffer)); 36bf215546Sopenharmony_ci vk_object_base_init(pool->base.device, &command_buffer->base, 37bf215546Sopenharmony_ci VK_OBJECT_TYPE_COMMAND_BUFFER); 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci command_buffer->pool = pool; 40bf215546Sopenharmony_ci command_buffer->level = level; 41bf215546Sopenharmony_ci vk_dynamic_graphics_state_init(&command_buffer->dynamic_graphics_state); 42bf215546Sopenharmony_ci vk_cmd_queue_init(&command_buffer->cmd_queue, &pool->alloc); 43bf215546Sopenharmony_ci util_dynarray_init(&command_buffer->labels, NULL); 44bf215546Sopenharmony_ci command_buffer->region_begin = true; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci list_add(&command_buffer->pool_link, &pool->command_buffers); 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci return VK_SUCCESS; 49bf215546Sopenharmony_ci} 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_civoid 52bf215546Sopenharmony_civk_command_buffer_reset(struct vk_command_buffer *command_buffer) 53bf215546Sopenharmony_ci{ 54bf215546Sopenharmony_ci vk_dynamic_graphics_state_clear(&command_buffer->dynamic_graphics_state); 55bf215546Sopenharmony_ci vk_command_buffer_reset_render_pass(command_buffer); 56bf215546Sopenharmony_ci vk_cmd_queue_reset(&command_buffer->cmd_queue); 57bf215546Sopenharmony_ci util_dynarray_clear(&command_buffer->labels); 58bf215546Sopenharmony_ci command_buffer->region_begin = true; 59bf215546Sopenharmony_ci} 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_civoid 62bf215546Sopenharmony_civk_command_buffer_finish(struct vk_command_buffer *command_buffer) 63bf215546Sopenharmony_ci{ 64bf215546Sopenharmony_ci list_del(&command_buffer->pool_link); 65bf215546Sopenharmony_ci vk_command_buffer_reset_render_pass(command_buffer); 66bf215546Sopenharmony_ci vk_cmd_queue_finish(&command_buffer->cmd_queue); 67bf215546Sopenharmony_ci util_dynarray_fini(&command_buffer->labels); 68bf215546Sopenharmony_ci vk_object_base_finish(&command_buffer->base); 69bf215546Sopenharmony_ci} 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 72bf215546Sopenharmony_civk_common_CmdExecuteCommands(VkCommandBuffer commandBuffer, 73bf215546Sopenharmony_ci uint32_t commandBufferCount, 74bf215546Sopenharmony_ci const VkCommandBuffer *pCommandBuffers) 75bf215546Sopenharmony_ci{ 76bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_command_buffer, primary, commandBuffer); 77bf215546Sopenharmony_ci const struct vk_device_dispatch_table *disp = 78bf215546Sopenharmony_ci primary->base.device->command_dispatch_table; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci for (uint32_t i = 0; i < commandBufferCount; i++) { 81bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_command_buffer, secondary, pCommandBuffers[i]); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci vk_cmd_queue_execute(&secondary->cmd_queue, commandBuffer, disp); 84bf215546Sopenharmony_ci } 85bf215546Sopenharmony_ci} 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 88bf215546Sopenharmony_civk_common_CmdBindVertexBuffers(VkCommandBuffer commandBuffer, 89bf215546Sopenharmony_ci uint32_t firstBinding, 90bf215546Sopenharmony_ci uint32_t bindingCount, 91bf215546Sopenharmony_ci const VkBuffer *pBuffers, 92bf215546Sopenharmony_ci const VkDeviceSize *pOffsets) 93bf215546Sopenharmony_ci{ 94bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, commandBuffer); 95bf215546Sopenharmony_ci const struct vk_device_dispatch_table *disp = 96bf215546Sopenharmony_ci &cmd_buffer->base.device->dispatch_table; 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci disp->CmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, 99bf215546Sopenharmony_ci pBuffers, pOffsets, NULL, NULL); 100bf215546Sopenharmony_ci} 101