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