vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
GraphicsPipeline.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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
20namespace 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 virtual void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const = 0;
39
40 public:
41 int compare(const Object& rhs) const override;
42 void read(Input& input) override;
43 void write(Output& output) const override;
44
45 protected:
46 virtual ~GraphicsPipelineState() {}
47 };
48 VSG_type_name(vsg::GraphicsPipelineState);
49
50 using GraphicsPipelineStates = std::vector<ref_ptr<GraphicsPipelineState>>;
51 extern VSG_DECLSPEC void mergeGraphicsPipelineStates(Mask mask, GraphicsPipelineStates& dest_PipelineStates, ref_ptr<GraphicsPipelineState> src_PipelineState);
52 extern VSG_DECLSPEC void mergeGraphicsPipelineStates(Mask mask, GraphicsPipelineStates& dest_PipelineStates, const GraphicsPipelineStates& src_PipelineStates);
53
55 class VSG_DECLSPEC GraphicsPipeline : public Inherit<Object, GraphicsPipeline>
56 {
57 public:
59
60 GraphicsPipeline(PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass = 0);
61
63 VkPipeline vk(uint32_t viewID) const { return _implementation[viewID]->_pipeline; }
64
66 VkPipeline validated_vk(uint32_t viewID) const { return (viewID < _implementation.size()) ? (_implementation[viewID] ? _implementation[viewID]->_pipeline : 0) : 0; }
67
69 ShaderStages stages;
70 GraphicsPipelineStates pipelineStates;
72 uint32_t subpass;
73
74 int compare(const Object& rhs_object) const override;
75
76 void read(Input& input) override;
77 void write(Output& output) const override;
78
79 // compile the Vulkan object, context parameter used for Device
80 void compile(Context& context);
81
82 // remove the local reference to the Vulkan implementation
83 void release(uint32_t viewID)
84 {
85 if (viewID < static_cast<uint32_t>(_implementation.size())) _implementation[viewID] = {};
86 }
87 void release() { _implementation.clear(); }
88
89 protected:
90 virtual ~GraphicsPipeline();
91
92 struct Implementation : public Inherit<Object, Implementation>
93 {
94 Implementation(Context& context, Device* device, const RenderPass* renderPass, const PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass);
95
96 virtual ~Implementation();
97
98 VkPipeline _pipeline;
99
100 ref_ptr<Device> _device;
101 };
102
103 std::vector<ref_ptr<Implementation>> _implementation;
104 };
105 VSG_type_name(vsg::GraphicsPipeline);
106
108 class VSG_DECLSPEC BindGraphicsPipeline : public Inherit<StateCommand, BindGraphicsPipeline>
109 {
110 public:
111 BindGraphicsPipeline(GraphicsPipeline* in_pipeline = nullptr);
112
115
116 int compare(const Object& rhs_object) const override;
117
118 void read(Input& input) override;
119 void write(Output& output) const override;
120
121 void record(CommandBuffer& commandBuffer) const override;
122
123 // compile the Vulkan object, context parameter used for Device
124 void compile(Context& context) override;
125
126 virtual void release();
127
128 public:
129 virtual ~BindGraphicsPipeline();
130 };
131 VSG_type_name(vsg::BindGraphicsPipeline);
132
133} // namespace vsg
BindGraphicsPipeline state command encapsulates the vkCmdBindPipeline call for a GraphicsPipeline.
Definition GraphicsPipeline.h:109
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:114
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
GraphicsPipeline encapsulates graphics VkPipeline and the VkGraphicsPipelineCreateInfo settings used ...
Definition GraphicsPipeline.h:56
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:66
ShaderStages stages
VkGraphicsPipelineCreateInfo settings.
Definition GraphicsPipeline.h:69
VkPipeline vk(uint32_t viewID) const
return the Vulkan Pipeline for specified viewID.
Definition GraphicsPipeline.h:63
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,...
Definition Inherit.h:28
Definition Input.h:44
Definition Object.h:60
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:93