1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright 2018 The Amber Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_VULKAN_GRAPHICS_PIPELINE_H_
#define SRC_VULKAN_GRAPHICS_PIPELINE_H_
#include <memory>
#include <vector>
#include "amber/result.h"
#include "amber/value.h"
#include "amber/vulkan_header.h"
#include "src/buffer_data.h"
#include "src/format.h"
#include "src/pipeline.h"
#include "src/vulkan/frame_buffer.h"
#include "src/vulkan/index_buffer.h"
#include "src/vulkan/pipeline.h"
#include "src/vulkan/vertex_buffer.h"
namespace amber {
class ProbeCommand;
namespace vulkan {
class CommandPool;
class GraphicsPipeline : public Pipeline {
public:
GraphicsPipeline(
Device* device,
const VkPhysicalDeviceProperties& properties,
const VkPhysicalDeviceMemoryProperties& memory_properties,
const std::vector<amber::Pipeline::BufferInfo>& color_buffers,
VkFormat depth_stencil_format,
uint32_t fence_timeout_ms,
const std::vector<VkPipelineShaderStageCreateInfo>&);
~GraphicsPipeline() override;
Result Initialize(uint32_t width,
uint32_t height,
CommandPool* pool,
VkQueue queue);
Result SetIndexBuffer(Buffer* buffer);
Result Clear();
Result ClearBuffer(const VkClearValue& clear_value,
VkImageAspectFlags aspect);
Result SetClearColor(float r, float g, float b, float a);
Result SetClearStencil(uint32_t stencil);
Result SetClearDepth(float depth);
Result Draw(const DrawArraysCommand* command, VertexBuffer* vertex_buffer);
VkRenderPass GetVkRenderPass() const { return render_pass_; }
FrameBuffer* GetFrame() const { return frame_.get(); }
uint32_t GetWidth() const { return frame_width_; }
uint32_t GetHeight() const { return frame_height_; }
void SetPatchControlPoints(uint32_t points) {
patch_control_points_ = points;
}
private:
Result CreateVkGraphicsPipeline(const PipelineData* pipeline_data,
VkPrimitiveTopology topology,
const VertexBuffer* vertex_buffer,
const VkPipelineLayout& pipeline_layout,
VkPipeline* pipeline);
Result CreateRenderPass();
Result SendVertexBufferDataIfNeeded(VertexBuffer* vertex_buffer);
// TODO(jaebaek): Implement image/ssbo probe.
Result SubmitProbeCommand();
Result VerifyPixels(const uint32_t x,
const uint32_t y,
const uint32_t width,
const uint32_t height,
const ProbeCommand* command);
VkPipelineDepthStencilStateCreateInfo GetVkPipelineDepthStencilInfo(
const PipelineData* pipeline_data);
VkPipelineColorBlendAttachmentState GetVkPipelineColorBlendAttachmentState(
const PipelineData* pipeline_data);
VkRenderPass render_pass_ = VK_NULL_HANDLE;
std::unique_ptr<FrameBuffer> frame_;
// color buffers are owned by the amber::Pipeline.
std::vector<const amber::Pipeline::BufferInfo*> color_buffers_;
VkFormat depth_stencil_format_;
std::unique_ptr<IndexBuffer> index_buffer_;
uint32_t frame_width_ = 0;
uint32_t frame_height_ = 0;
float clear_color_r_ = 0;
float clear_color_g_ = 0;
float clear_color_b_ = 0;
float clear_color_a_ = 0;
uint32_t clear_stencil_ = 0;
float clear_depth_ = 1.0f;
uint32_t patch_control_points_ = 3;
};
} // namespace vulkan
} // namespace amber
#endif // SRC_VULKAN_GRAPHICS_PIPELINE_H_
|