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

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: Layout transitions done through render passes 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_command_pool.h"
8 #include "gpu/vulkan/vulkan_implementation.h"
9
10 namespace gpu {
11
12 VulkanCommandBuffer::VulkanCommandBuffer(VulkanCommandPool* command_pool,
13 bool primary)
14 : primary_(primary), command_pool_(command_pool) {
15 command_pool_->IncrementCommandBufferCount();
16 }
17
18 VulkanCommandBuffer::~VulkanCommandBuffer() {
19 DCHECK_EQ(static_cast<VkCommandBuffer>(VK_NULL_HANDLE), command_buffer_);
20 DCHECK(!recording_);
21 command_pool_->DecrementCommandBufferCount();
22 }
23
24 bool VulkanCommandBuffer::Initialize() {
25 VkCommandBufferAllocateInfo command_buffer_info = {};
26 command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
27 command_buffer_info.commandPool = command_pool_->handle();
28 command_buffer_info.level = primary_ ? VK_COMMAND_BUFFER_LEVEL_PRIMARY
29 : VK_COMMAND_BUFFER_LEVEL_SECONDARY;
30 command_buffer_info.commandBufferCount = 1;
31
32 VkResult result = vkAllocateCommandBuffers(
33 GetVulkanDevice(), &command_buffer_info, &command_buffer_);
34 if (VK_SUCCESS != result) {
35 DLOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result;
36 return false;
37 }
38 return true;
39 }
40
41 void VulkanCommandBuffer::Destroy() {
42 if (VK_NULL_HANDLE != command_buffer_) {
43 vkFreeCommandBuffers(GetVulkanDevice(), command_pool_->handle(), 1,
44 &command_buffer_);
45 command_buffer_ = VK_NULL_HANDLE;
46 }
47 }
48
49 bool VulkanCommandBuffer::Submit(VkQueue queue,
50 uint32_t num_wait_semaphores,
51 VkSemaphore* wait_semaphores,
52 uint32_t num_signal_semaphores,
53 VkSemaphore* signal_semaphores) {
54 DCHECK(primary_);
55 VkSubmitInfo submit_info = {};
56 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
57 submit_info.commandBufferCount = 1;
58 submit_info.pCommandBuffers = &command_buffer_;
59 submit_info.waitSemaphoreCount = num_wait_semaphores;
60 submit_info.pWaitSemaphores = wait_semaphores;
61 submit_info.signalSemaphoreCount = num_signal_semaphores;
62 submit_info.pSignalSemaphores = signal_semaphores;
63
64 VkResult result = vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
65 PostExecution();
66 if (VK_SUCCESS != result) {
67 DLOG(ERROR) << "vkQueueSubmit() failed: " << result;
68 return false;
69 }
70
71 return true;
72 }
73
74 void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) {
75 DCHECK(!primary_);
76 vkCmdExecuteCommands(primary_command_buffer, 1, &command_buffer_);
77 PostExecution();
78 }
79
80 void VulkanCommandBuffer::PostExecution() {
81 if (record_type_ == RECORD_TYPE_SINGLE_USE) {
82 // Clear upon next use.
83 record_type_ = RECORD_TYPE_DIRTY;
84 } else if (record_type_ == RECORD_TYPE_MULTI_USE) {
85 // Can no longer record new items unless marked as clear.
86 record_type_ = RECORD_TYPE_RECORDED;
87 }
88 }
89
90 void VulkanCommandBuffer::ResetIfDirty() {
91 DCHECK(!recording_);
92 if (record_type_ == RECORD_TYPE_DIRTY) {
93 vkResetCommandPool(GetVulkanDevice(), command_pool_->handle(),
jchen10 2016/03/23 07:12:57 Would it be impertinent to ask whether vkResetComm
David Yen 2016/03/23 18:19:29 Good catch, not sure what happened here. Fixed.
94 VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
95 record_type_ = RECORD_TYPE_EMPTY;
96 }
97 }
98
99 CommandBufferRecorderBase::~CommandBufferRecorderBase() {
100 vkEndCommandBuffer(handle_);
101 };
102
103 ScopedMultiUseCommandBufferRecorder::ScopedMultiUseCommandBufferRecorder(
104 VulkanCommandBuffer& command_buffer)
105 : CommandBufferRecorderBase(command_buffer) {
106 ValidateMultiUse(command_buffer);
107 VkCommandBufferBeginInfo begin_info = {};
108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
109 vkBeginCommandBuffer(handle_, &begin_info);
110 }
111
112 ScopedSingleUseCommandBufferRecorder::ScopedSingleUseCommandBufferRecorder(
113 VulkanCommandBuffer& command_buffer)
114 : CommandBufferRecorderBase(command_buffer) {
115 ValidateSingleUse(command_buffer);
116 VkCommandBufferBeginInfo begin_info = {};
117 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
118 begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
119 vkBeginCommandBuffer(handle_, &begin_info);
120 }
121
122 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698