vsg  1.0.4
VulkanSceneGraph library
GraphicsPipeline.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/state/PipelineLayout.h>
16 #include <vsg/state/ShaderStage.h>
17 #include <vsg/state/StateCommand.h>
18 #include <vsg/vk/RenderPass.h>
19 
20 namespace vsg
21 {
22  // forward declare
23  class Context;
24 
28  class VSG_DECLSPEC GraphicsPipelineState : public Inherit<Object, GraphicsPipelineState>
29  {
30  public:
32 
33  virtual void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const = 0;
34 
35  protected:
36  virtual ~GraphicsPipelineState() {}
37  };
38  VSG_type_name(vsg::GraphicsPipelineState);
39 
40  using GraphicsPipelineStates = std::vector<ref_ptr<GraphicsPipelineState>>;
41  extern VSG_DECLSPEC void mergeGraphicsPipelineStates(GraphicsPipelineStates& dest_PipelineStates, ref_ptr<GraphicsPipelineState> src_PipelineState);
42  extern VSG_DECLSPEC void mergeGraphicsPipelineStates(GraphicsPipelineStates& dest_PipelineStates, const GraphicsPipelineStates& src_PipelineStates);
43 
45  class VSG_DECLSPEC GraphicsPipeline : public Inherit<Object, GraphicsPipeline>
46  {
47  public:
49 
50  GraphicsPipeline(PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass = 0);
51 
52  VkPipeline vk(uint32_t deviceID) const { return _implementation[deviceID]->_pipeline; }
53 
55  ShaderStages stages;
56  GraphicsPipelineStates pipelineStates;
58  ref_ptr<RenderPass> renderPass;
59  uint32_t subpass;
60 
61  int compare(const Object& rhs_object) const override;
62 
63  void read(Input& input) override;
64  void write(Output& output) const override;
65 
66  // compile the Vulkan object, context parameter used for Device
67  void compile(Context& context);
68 
69  // remove the local reference to the Vulkan implementation
70  void release(uint32_t viewID) { _implementation[viewID] = {}; }
71  void release() { _implementation.clear(); }
72 
73  protected:
74  virtual ~GraphicsPipeline();
75 
76  struct Implementation : public Inherit<Object, Implementation>
77  {
78  Implementation(Context& context, Device* device, const RenderPass* renderPass, const PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass);
79 
80  virtual ~Implementation();
81 
82  VkPipeline _pipeline;
83 
84  ref_ptr<Device> _device;
85  };
86 
87  std::vector<ref_ptr<Implementation>> _implementation;
88  };
89  VSG_type_name(vsg::GraphicsPipeline);
90 
92  class VSG_DECLSPEC BindGraphicsPipeline : public Inherit<StateCommand, BindGraphicsPipeline>
93  {
94  public:
95  BindGraphicsPipeline(GraphicsPipeline* in_pipeline = nullptr);
96 
99 
100  int compare(const Object& rhs_object) const override;
101 
102  void read(Input& input) override;
103  void write(Output& output) const override;
104 
105  void record(CommandBuffer& commandBuffer) const override;
106 
107  // compile the Vulkan object, context parameter used for Device
108  void compile(Context& context) override;
109 
110  virtual void release();
111 
112  public:
113  virtual ~BindGraphicsPipeline();
114  };
115  VSG_type_name(vsg::BindGraphicsPipeline);
116 
117 } // namespace vsg
BindGraphicsPipeline state command encapsulates the vkCmdBindPipeline call for a GraphicsPipeline.
Definition: GraphicsPipeline.h:93
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
ref_ptr< GraphicsPipeline > pipeline
pipeline to pass in the vkCmdBindPipeline call;
Definition: GraphicsPipeline.h:98
CommandBuffer encapsulates VkCommandBuffer.
Definition: CommandBuffer.h:27
Definition: Context.h:67
Device encapsulate vkDeivce, a logical handle to the PhysicalDevice with capabilities specified durin...
Definition: Device.h:37
Definition: GraphicsPipeline.h:29
GraphicsPipeline encapsulates graphics VkPipeline and the VkGraphicsPipelineCreateInfo settings used ...
Definition: GraphicsPipeline.h:46
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
ShaderStages stages
VkGraphicsPipelineCreateInfo settings.
Definition: GraphicsPipeline.h:55
Definition: Inherit.h:28
Definition: Input.h:43
Definition: Object.h:42
Definition: Output.h:40
PipelineLayout encapsulates VkPipelineLayout and the VkPipelineLayoutCreateInfo settings used to set ...
Definition: PipelineLayout.h:27
RenderPass encapsulation of VkRenderPass.
Definition: RenderPass.h:86
Definition: ref_ptr.h:22
Definition: GraphicsPipeline.h:77