Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: gpu/vulkan/vulkan_command_buffer.cc

Issue 1776453003: Added initial implementation of Vulkan Render Passes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn_vulkan
Patch Set: Ensure vulkan handles all initialized to null, check destruction in destructor Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/vulkan/vulkan_command_buffer.h"
6
7 #include "gpu/vulkan/vulkan_implementation.h"
8
9 namespace gfx {
10
11 VulkanCommandBuffer::VulkanCommandBuffer(VkCommandPool command_pool,
12 bool primary)
13 : primary_(primary), command_pool_(command_pool) {}
14
15 VulkanCommandBuffer::~VulkanCommandBuffer() {
16 DCHECK_EQ(reinterpret_cast<VkCommandBuffer>(VK_NULL_HANDLE), command_buffer_);
piman 2016/03/09 01:25:33 nit: static_cast
David Yen 2016/03/10 01:39:48 Done.
17 DCHECK(!recording_);
18 }
19
20 bool VulkanCommandBuffer::Initialize() {
21 VkCommandBufferAllocateInfo command_buffer_info = {};
22 command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23 command_buffer_info.commandPool = command_pool_;
24 command_buffer_info.level = primary_ ? VK_COMMAND_BUFFER_LEVEL_PRIMARY
25 : VK_COMMAND_BUFFER_LEVEL_SECONDARY;
26 command_buffer_info.commandBufferCount = 1;
27
28 VkResult result = vkAllocateCommandBuffers(
29 GetVulkanDevice(), &command_buffer_info, &command_buffer_);
30 if (VK_SUCCESS != result) {
31 LOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result;
piman 2016/03/09 01:25:33 nit: DLOG
David Yen 2016/03/10 01:39:48 Done.
32 return false;
33 }
34 return true;
35 }
36
37 void VulkanCommandBuffer::Destroy() {
38 if (VK_NULL_HANDLE != command_buffer_) {
39 vkFreeCommandBuffers(GetVulkanDevice(), command_pool_, 1, &command_buffer_);
40 command_buffer_ = VK_NULL_HANDLE;
41 }
42 }
43
44 bool VulkanCommandBuffer::Submit() {
45 DCHECK(primary_);
46 VkSubmitInfo submit_info = {};
47 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
48 submit_info.commandBufferCount = 1;
49 submit_info.pCommandBuffers = &command_buffer_;
50 VkResult result =
51 vkQueueSubmit(GetVulkanQueue(), 1, &submit_info, VK_NULL_HANDLE);
52 PostExecution();
53 if (VK_SUCCESS != result) {
54 LOG(ERROR) << "vkQueueSubmit() failed: " << result;
piman 2016/03/09 01:25:33 nit: DLOG
David Yen 2016/03/10 01:39:48 Done.
55 return false;
56 }
57
58 return true;
59 }
60
61 void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) {
62 DCHECK(!primary_);
63 vkCmdExecuteCommands(primary_command_buffer, 1, &command_buffer_);
64 PostExecution();
65 }
66
67 void VulkanCommandBuffer::PostExecution() {
68 if (record_type_ == RECORD_TYPE_SINGLE_USE) {
69 // Clear upon next use.
70 record_type_ = RECORD_TYPE_DIRTY;
71 } else if (record_type_ == RECORD_TYPE_MULTI_USE) {
72 // Can no longer record new items unless marked as clear.
73 record_type_ = RECORD_TYPE_RECORDED;
74 }
75 }
76
77 void VulkanCommandBuffer::ResetIfDirty() {
78 DCHECK(!recording_);
79 if (record_type_ == RECORD_TYPE_DIRTY) {
80 vkResetCommandPool(GetVulkanDevice(), command_pool_,
81 VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
82 record_type_ = RECORD_TYPE_EMPTY;
83 }
84 }
85
86 CommandBufferRecorderBase::~CommandBufferRecorderBase() {
87 vkEndCommandBuffer(handle_);
88 };
89
90 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698