vsg  1.1.0
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:
33  Inherit(), mask(gp.mask) {}
34 
36  Mask mask = MASK_ALL;
37 
38  int compare(const Object& rhs) const override;
39  void read(Input& input) override;
40  void write(Output& output) const override;
41 
42  virtual void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const = 0;
43 
44  protected:
45  virtual ~GraphicsPipelineState() {}
46  };
47  VSG_type_name(vsg::GraphicsPipelineState);
48 
49  using GraphicsPipelineStates = std::vector<ref_ptr<GraphicsPipelineState>>;
50  extern VSG_DECLSPEC void mergeGraphicsPipelineStates(Mask mask, GraphicsPipelineStates& dest_PipelineStates, ref_ptr<GraphicsPipelineState> src_PipelineState);
51  extern VSG_DECLSPEC void mergeGraphicsPipelineStates(Mask mask, GraphicsPipelineStates& dest_PipelineStates, const GraphicsPipelineStates& src_PipelineStates);
52 
54  class VSG_DECLSPEC GraphicsPipeline : public Inherit<Object, GraphicsPipeline>
55  {
56  public:
58 
59  GraphicsPipeline(PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass = 0);
60 
62  VkPipeline vk(uint32_t viewID) const { return _implementation[viewID]->_pipeline; }
63 
65  VkPipeline validated_vk(uint32_t viewID) const { return (viewID < _implementation.size()) ? (_implementation[viewID] ? _implementation[viewID]->_pipeline : 0) : 0; }
66 
68  ShaderStages stages;
69  GraphicsPipelineStates pipelineStates;
71  uint32_t subpass;
72 
73  int compare(const Object& rhs_object) const override;
74 
75  void read(Input& input) override;
76  void write(Output& output) const override;
77 
78  // compile the Vulkan object, context parameter used for Device
79  void compile(Context& context);
80 
81  // remove the local reference to the Vulkan implementation
82  void release(uint32_t viewID) { _implementation[viewID] = {}; }
83  void release() { _implementation.clear(); }
84 
85  protected:
86  virtual ~GraphicsPipeline();
87 
88  struct Implementation : public Inherit<Object, Implementation>
89  {
90  Implementation(Context& context, Device* device, const RenderPass* renderPass, const PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass);
91 
92  virtual ~Implementation();
93 
94  VkPipeline _pipeline;
95 
96  ref_ptr<Device> _device;
97  };
98 
99  std::vector<ref_ptr<Implementation>> _implementation;
100  };
101  VSG_type_name(vsg::GraphicsPipeline);
102 
104  class VSG_DECLSPEC BindGraphicsPipeline : public Inherit<StateCommand, BindGraphicsPipeline>
105  {
106  public:
107  BindGraphicsPipeline(GraphicsPipeline* in_pipeline = nullptr);
108 
111 
112  int compare(const Object& rhs_object) const override;
113 
114  void read(Input& input) override;
115  void write(Output& output) const override;
116 
117  void record(CommandBuffer& commandBuffer) const override;
118 
119  // compile the Vulkan object, context parameter used for Device
120  void compile(Context& context) override;
121 
122  virtual void release();
123 
124  public:
125  virtual ~BindGraphicsPipeline();
126  };
127  VSG_type_name(vsg::BindGraphicsPipeline);
128 
129 } // namespace vsg
BindGraphicsPipeline state command encapsulates the vkCmdBindPipeline call for a GraphicsPipeline.
Definition: GraphicsPipeline.h:105
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:110
CommandBuffer encapsulates VkCommandBuffer.
Definition: CommandBuffer.h:27
Definition: Context.h:67
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
Definition: GraphicsPipeline.h:29
Mask mask
apply GraphicsPipelineState when (mask & view.mask) is non zero
Definition: GraphicsPipeline.h:36
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
GraphicsPipeline encapsulates graphics VkPipeline and the VkGraphicsPipelineCreateInfo settings used ...
Definition: GraphicsPipeline.h:55
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,...
VkPipeline validated_vk(uint32_t viewID) const
variant of vk(viewID) method that is slower but adds validation of the viewID parameter
Definition: GraphicsPipeline.h:65
ShaderStages stages
VkGraphicsPipelineCreateInfo settings.
Definition: GraphicsPipeline.h:68
VkPipeline vk(uint32_t viewID) const
return the Vulkan Pipeline for specified viewID.
Definition: GraphicsPipeline.h:62
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Definition: Output.h:41
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:89