• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_VULKAN_FRAME_BUFFER_H_
16 #define SRC_VULKAN_FRAME_BUFFER_H_
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "src/pipeline.h"
22 #include "src/vulkan/transfer_image.h"
23 
24 namespace amber {
25 namespace vulkan {
26 
27 class CommandBuffer;
28 class Device;
29 
30 /// Wrapper around a Vulkan FrameBuffer object.
31 class FrameBuffer {
32  public:
33   FrameBuffer(
34       Device* device,
35       const std::vector<const amber::Pipeline::BufferInfo*>& color_attachments,
36       amber::Pipeline::BufferInfo depth_stencil_attachment,
37       uint32_t width,
38       uint32_t height);
39   ~FrameBuffer();
40 
41   Result Initialize(VkRenderPass render_pass);
42 
43   void ChangeFrameToDrawLayout(CommandBuffer* command);
44   void ChangeFrameToProbeLayout(CommandBuffer* command);
45   void ChangeFrameToWriteLayout(CommandBuffer* command);
46 
GetVkFrameBuffer()47   VkFramebuffer GetVkFrameBuffer() const { return frame_; }
GetColorBufferPtr(size_t idx)48   const void* GetColorBufferPtr(size_t idx) const {
49     return color_images_[idx]->HostAccessibleMemoryPtr();
50   }
51 
52   // Only record the command for copying the image that backs this
53   // framebuffer to the host accessible buffer. The actual submission
54   // of the command must be done later.
55   void TransferImagesToHost(CommandBuffer* command);
56   void TransferImagesToDevice(CommandBuffer* command);
57 
58   void CopyImagesToBuffers();
59   void CopyBuffersToImages();
60 
GetWidth()61   uint32_t GetWidth() const { return width_; }
GetHeight()62   uint32_t GetHeight() const { return height_; }
63 
64  private:
65   void ChangeFrameLayout(CommandBuffer* command,
66                          VkImageLayout color_layout,
67                          VkPipelineStageFlags color_stage,
68                          VkImageLayout depth_layout,
69                          VkPipelineStageFlags depth_stage);
70 
71   Device* device_ = nullptr;
72   std::vector<const amber::Pipeline::BufferInfo*> color_attachments_;
73   amber::Pipeline::BufferInfo depth_stencil_attachment_;
74   VkFramebuffer frame_ = VK_NULL_HANDLE;
75   std::vector<std::unique_ptr<TransferImage>> color_images_;
76   std::unique_ptr<TransferImage> depth_stencil_image_;
77   uint32_t width_ = 0;
78   uint32_t height_ = 0;
79   uint32_t depth_ = 1;
80 };
81 
82 }  // namespace vulkan
83 }  // namespace amber
84 
85 #endif  // SRC_VULKAN_FRAME_BUFFER_H_
86