vsg  1.1.0
VulkanSceneGraph library
RayTracingPipeline.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2019 Thomas Hogarth
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/raytracing/RayTracingShaderGroup.h>
16 #include <vsg/state/PipelineLayout.h>
17 #include <vsg/state/ShaderStage.h>
18 #include <vsg/state/StateCommand.h>
19 
20 namespace vsg
21 {
22 
25  class VSG_DECLSPEC RayTracingPipeline : public Inherit<Object, RayTracingPipeline>
26  {
27  public:
29 
30  RayTracingPipeline(PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const RayTracingShaderGroups& shaderGroups);
31 
32  int compare(const Object& rhs_object) const override;
33 
34  void read(Input& input) override;
35  void write(Output& output) const override;
36 
37  PipelineLayout* getPipelineLayout() { return _pipelineLayout; }
38  const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; }
39 
40  ShaderStages& getShaderStages() { return _shaderStages; }
41  const ShaderStages& getShaderStages() const { return _shaderStages; }
42 
43  RayTracingShaderGroups& getRayTracingShaderGroups() { return _rayTracingShaderGroups; }
44  const RayTracingShaderGroups& getRayTracingShaderGroups() const { return _rayTracingShaderGroups; }
45 
46  uint32_t& maxRecursionDepth() { return _maxRecursionDepth; }
47  const uint32_t& maxRecursionDepth() const { return _maxRecursionDepth; }
48 
49  // compile the Vulkan object, context parameter used for Device
50  void compile(Context& context);
51 
52  // remove the local reference to the Vulkan implementation
53  void release(uint32_t deviceID) { _implementation[deviceID] = {}; }
54  void release() { _implementation.clear(); }
55 
56  VkPipeline vk(uint32_t deviceID) const { return _implementation[deviceID]->_pipeline; }
57 
58  protected:
59  virtual ~RayTracingPipeline();
60 
61  struct Implementation : public Inherit<Object, Implementation>
62  {
63  Implementation(Context& context, RayTracingPipeline* rayTracingPipeline);
64  virtual ~Implementation();
65 
66  VkPipeline _pipeline;
67 
68  ref_ptr<Device> _device;
69  ref_ptr<PipelineLayout> _pipelineLayout;
70  ShaderStages _shaderStages;
71  RayTracingShaderGroups _shaderGroups;
72  };
73 
74  vk_buffer<ref_ptr<Implementation>> _implementation;
75 
76  ref_ptr<PipelineLayout> _pipelineLayout;
77  ShaderStages _shaderStages;
78  RayTracingShaderGroups _rayTracingShaderGroups;
79  uint32_t _maxRecursionDepth = 1;
80  };
81  VSG_type_name(vsg::RayTracingPipeline);
82 
84  class VSG_DECLSPEC BindRayTracingPipeline : public Inherit<StateCommand, BindRayTracingPipeline>
85  {
86  public:
87  BindRayTracingPipeline(RayTracingPipeline* pipeline = nullptr);
88 
89  int compare(const Object& rhs_object) const override;
90 
91  void read(Input& input) override;
92  void write(Output& output) const override;
93 
94  void setPipeline(RayTracingPipeline* pipeline) { _pipeline = pipeline; }
95  RayTracingPipeline* getPipeline() { return _pipeline; }
96  const RayTracingPipeline* getPipeline() const { return _pipeline; }
97 
98  void record(CommandBuffer& commandBuffer) const override;
99 
100  // compile the Vulkan object, context parameter used for Device
101  void compile(Context& context) override;
102 
103  virtual void release();
104 
105  public:
106  virtual ~BindRayTracingPipeline();
107 
108  ref_ptr<RayTracingPipeline> _pipeline;
109  };
110  VSG_type_name(vsg::BindRayTracingPipeline);
111 
112 } // namespace vsg
BindRayTracingPipeline state command encapsulates vkCmdBindPipeline for a RayTracingPipeline.
Definition: RayTracingPipeline.h:85
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,...
Definition: Context.h:67
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
Definition: RayTracingPipeline.h:26
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,...
Definition: ref_ptr.h:22
Definition: RayTracingPipeline.h:62
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28