• 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_GRAPHICS_PIPELINE_H_
16 #define SRC_VULKAN_GRAPHICS_PIPELINE_H_
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "amber/result.h"
22 #include "amber/value.h"
23 #include "amber/vulkan_header.h"
24 #include "src/format.h"
25 #include "src/pipeline.h"
26 #include "src/vulkan/frame_buffer.h"
27 #include "src/vulkan/index_buffer.h"
28 #include "src/vulkan/pipeline.h"
29 #include "src/vulkan/vertex_buffer.h"
30 
31 namespace amber {
32 
33 class ProbeCommand;
34 
35 namespace vulkan {
36 
37 class CommandPool;
38 
39 /// Wrapper around a graphics pipeline.
40 class GraphicsPipeline : public Pipeline {
41  public:
42   GraphicsPipeline(
43       Device* device,
44       const std::vector<amber::Pipeline::BufferInfo>& color_buffers,
45       amber::Pipeline::BufferInfo depth_stencil_buffer,
46       const std::vector<amber::Pipeline::BufferInfo>& resolve_targets,
47       uint32_t fence_timeout_ms,
48       const std::vector<VkPipelineShaderStageCreateInfo>&);
49   ~GraphicsPipeline() override;
50 
51   Result Initialize(uint32_t width, uint32_t height, CommandPool* pool);
52 
53   Result SetIndexBuffer(Buffer* buffer);
54 
55   Result Clear();
56 
57   Result SetClearColor(float r, float g, float b, float a);
58   Result SetClearStencil(uint32_t stencil);
59   Result SetClearDepth(float depth);
60 
61   Result Draw(const DrawArraysCommand* command, VertexBuffer* vertex_buffer);
62 
GetVkRenderPass()63   VkRenderPass GetVkRenderPass() const { return render_pass_; }
GetFrameBuffer()64   FrameBuffer* GetFrameBuffer() const { return frame_.get(); }
65 
GetWidth()66   uint32_t GetWidth() const { return frame_width_; }
GetHeight()67   uint32_t GetHeight() const { return frame_height_; }
68 
SetPatchControlPoints(uint32_t points)69   void SetPatchControlPoints(uint32_t points) {
70     patch_control_points_ = points;
71   }
72 
73  private:
74   Result CreateVkGraphicsPipeline(const PipelineData* pipeline_data,
75                                   VkPrimitiveTopology topology,
76                                   const VertexBuffer* vertex_buffer,
77                                   const VkPipelineLayout& pipeline_layout,
78                                   VkPipeline* pipeline);
79   Result CreateRenderPass();
80   Result SendVertexBufferDataIfNeeded(VertexBuffer* vertex_buffer);
81 
82   VkPipelineDepthStencilStateCreateInfo GetVkPipelineDepthStencilInfo(
83       const PipelineData* pipeline_data);
84   std::vector<VkPipelineColorBlendAttachmentState>
85   GetVkPipelineColorBlendAttachmentState(const PipelineData* pipeline_data);
86 
87   VkRenderPass render_pass_ = VK_NULL_HANDLE;
88   std::unique_ptr<FrameBuffer> frame_;
89 
90   // color buffers and resolve targets are owned by the amber::Pipeline.
91   std::vector<const amber::Pipeline::BufferInfo*> color_buffers_;
92   std::vector<const amber::Pipeline::BufferInfo*> resolve_targets_;
93   amber::Pipeline::BufferInfo depth_stencil_buffer_;
94   std::unique_ptr<IndexBuffer> index_buffer_;
95 
96   uint32_t frame_width_ = 0;
97   uint32_t frame_height_ = 0;
98 
99   float clear_color_r_ = 0;
100   float clear_color_g_ = 0;
101   float clear_color_b_ = 0;
102   float clear_color_a_ = 0;
103   uint32_t clear_stencil_ = 0;
104   float clear_depth_ = 1.0f;
105   uint32_t patch_control_points_ = 3;
106 };
107 
108 }  // namespace vulkan
109 }  // namespace amber
110 
111 #endif  // SRC_VULKAN_GRAPHICS_PIPELINE_H_
112