From 5528a3858df2647c0311507bcba43be5b4eaa845 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Feb 2019 10:39:25 +0000 Subject: [PATCH 01/21] Renamed StateComponent to StateCommand to better reflect it's functionality --- include/vsg/nodes/StateGroup.h | 18 +++++++++--------- include/vsg/vk/BindIndexBuffer.h | 2 +- include/vsg/vk/BindVertexBuffers.h | 2 +- include/vsg/vk/DescriptorSet.h | 2 +- include/vsg/vk/Pipeline.h | 2 +- include/vsg/vk/PushConstants.h | 2 +- src/vsg/nodes/StateGroup.cpp | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/vsg/nodes/StateGroup.h b/include/vsg/nodes/StateGroup.h index 2c76e5bb7c..f381d6bf67 100644 --- a/include/vsg/nodes/StateGroup.h +++ b/include/vsg/nodes/StateGroup.h @@ -22,10 +22,10 @@ namespace vsg class CommandBuffer; class Context; - class StateComponent : public Inherit + class StateCommand : public Inherit { public: - StateComponent(Allocator* allocator = nullptr) : Inherit(allocator) {} + StateCommand(Allocator* allocator = nullptr) : Inherit(allocator) {} virtual void compile(Context& /*context*/) {} @@ -33,9 +33,9 @@ namespace vsg virtual void popFrom(State& state) const = 0; protected: - virtual ~StateComponent() {} + virtual ~StateCommand() {} }; - VSG_type_name(vsg::StateComponent); + VSG_type_name(vsg::StateCommand); class VSG_DECLSPEC StateSet : public Inherit { @@ -45,7 +45,7 @@ namespace vsg void read(Input& input) override; void write(Output& output) const override; - using StateComponents = std::vector>; + using StateCommands = std::vector>; virtual void compile(Context& context) { @@ -71,12 +71,12 @@ namespace vsg } } - inline void add(ref_ptr component) + inline void add(ref_ptr component) { _stateComponents.push_back(component); } - StateComponents _stateComponents; + StateCommands _stateComponents; protected: virtual ~StateSet(); @@ -94,9 +94,9 @@ namespace vsg void read(Input& input) override; void write(Output& output) const override; - using StateComponents = std::vector>; + using StateCommands = std::vector>; - void add(ref_ptr component) + void add(ref_ptr component) { _stateset->add(component); } diff --git a/include/vsg/vk/BindIndexBuffer.h b/include/vsg/vk/BindIndexBuffer.h index e1d193d012..53fb9e06e8 100644 --- a/include/vsg/vk/BindIndexBuffer.h +++ b/include/vsg/vk/BindIndexBuffer.h @@ -19,7 +19,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - class VSG_DECLSPEC BindIndexBuffer : public Inherit + class VSG_DECLSPEC BindIndexBuffer : public Inherit { public: BindIndexBuffer(Buffer* buffer, VkDeviceSize offset, VkIndexType indexType) : diff --git a/include/vsg/vk/BindVertexBuffers.h b/include/vsg/vk/BindVertexBuffers.h index 1fd2b49d01..c0e37590cf 100644 --- a/include/vsg/vk/BindVertexBuffers.h +++ b/include/vsg/vk/BindVertexBuffers.h @@ -19,7 +19,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - class VSG_DECLSPEC BindVertexBuffers : public Inherit + class VSG_DECLSPEC BindVertexBuffers : public Inherit { public: BindVertexBuffers() : diff --git a/include/vsg/vk/DescriptorSet.h b/include/vsg/vk/DescriptorSet.h index b1447b836b..da05b899ff 100644 --- a/include/vsg/vk/DescriptorSet.h +++ b/include/vsg/vk/DescriptorSet.h @@ -47,7 +47,7 @@ namespace vsg using DescriptorSets = std::vector>; - class VSG_DECLSPEC BindDescriptorSets : public Inherit + class VSG_DECLSPEC BindDescriptorSets : public Inherit { public: BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) : diff --git a/include/vsg/vk/Pipeline.h b/include/vsg/vk/Pipeline.h index 6741d5bf77..8bcb80f75a 100644 --- a/include/vsg/vk/Pipeline.h +++ b/include/vsg/vk/Pipeline.h @@ -44,7 +44,7 @@ namespace vsg }; VSG_type_name(vsg::Pipeline); - class VSG_DECLSPEC BindPipeline : public Inherit + class VSG_DECLSPEC BindPipeline : public Inherit { public: BindPipeline(Pipeline* pipeline); diff --git a/include/vsg/vk/PushConstants.h b/include/vsg/vk/PushConstants.h index 8c5f0fb295..047255971d 100644 --- a/include/vsg/vk/PushConstants.h +++ b/include/vsg/vk/PushConstants.h @@ -19,7 +19,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - class VSG_DECLSPEC PushConstants : public Inherit + class VSG_DECLSPEC PushConstants : public Inherit { public: PushConstants(VkShaderStageFlags shaderFlags, uint32_t offset, Data* data); diff --git a/src/vsg/nodes/StateGroup.cpp b/src/vsg/nodes/StateGroup.cpp index 785fe185d6..404f8d50e8 100644 --- a/src/vsg/nodes/StateGroup.cpp +++ b/src/vsg/nodes/StateGroup.cpp @@ -30,10 +30,10 @@ void StateSet::read(Input& input) { Object::read(input); - _stateComponents.resize(input.readValue("NumStateComponents")); + _stateComponents.resize(input.readValue("NumStateCommands")); for (auto& child : _stateComponents) { - child = input.readObject("StateComponent"); + child = input.readObject("StateCommand"); } } @@ -41,10 +41,10 @@ void StateSet::write(Output& output) const { Object::write(output); - output.writeValue("NumStateComponents", _stateComponents.size()); + output.writeValue("NumStateCommands", _stateComponents.size()); for (auto& child : _stateComponents) { - output.writeObject("StateComponent", child.get()); + output.writeObject("StateCommand", child.get()); } } From 517f2b8f18bb865a0d875ac9652aec3d2e466332 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Feb 2019 14:44:21 +0000 Subject: [PATCH 02/21] Refactored StateGroup to manage a vector of StateCommands, and for StateSet to be a vector of StateAttribute, with StaeAttribute generating the Descriptor --- include/vsg/nodes/StateGroup.h | 82 ++++++++++++----------- include/vsg/traversals/CompileTraversal.h | 2 + include/vsg/vk/Command.h | 18 +++++ include/vsg/vk/DescriptorSet.h | 2 +- include/vsg/vk/Pipeline.h | 2 +- src/vsg/nodes/StateGroup.cpp | 60 ++++++++++++----- src/vsg/traversals/CompileTraversal.cpp | 2 +- 7 files changed, 108 insertions(+), 60 deletions(-) diff --git a/include/vsg/nodes/StateGroup.h b/include/vsg/nodes/StateGroup.h index f381d6bf67..c3da35827d 100644 --- a/include/vsg/nodes/StateGroup.h +++ b/include/vsg/nodes/StateGroup.h @@ -14,30 +14,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include +#include + +#include namespace vsg { // forward declare class State; class CommandBuffer; - class Context; - class StateCommand : public Inherit + // scene graph interface for encapsulating the creation Descriptor's such as for wrapping uniforms and textures + class StateAttribute : public Inherit { public: - StateCommand(Allocator* allocator = nullptr) : Inherit(allocator) {} - - virtual void compile(Context& /*context*/) {} + StateAttribute(Allocator* allocator = nullptr) : Inherit(allocator) {} - virtual void pushTo(State& state) const = 0; - virtual void popFrom(State& state) const = 0; + virtual ref_ptr compile(Context& /*context*/) = 0; protected: - virtual ~StateCommand() {} + virtual ~StateAttribute() {} }; - VSG_type_name(vsg::StateCommand); + VSG_type_name(vsg::StateAttribute); - class VSG_DECLSPEC StateSet : public Inherit + // scene graph interface for enacpsulating the binding of StateAttributes togther into a single VkCmdBindDescriptorSets/VkDescriptorSets + class VSG_DECLSPEC StateSet : public Inherit { public: StateSet(Allocator* allocator = nullptr); @@ -45,41 +47,39 @@ namespace vsg void read(Input& input) override; void write(Output& output) const override; - using StateCommands = std::vector>; + using StateAttributes = std::vector>; - virtual void compile(Context& context) - { - for(auto& component : _stateComponents) - { - component->compile(context); - } - } + virtual void compile(Context& context); virtual void pushTo(State& state) const { - for(auto& component : _stateComponents) - { - component->pushTo(state); - } + _bindDescriptorSets->pushTo(state); } virtual void popFrom(State& state) const { - for(auto& component : _stateComponents) - { - component->popFrom(state); - } + _bindDescriptorSets->pushTo(state); } - inline void add(ref_ptr component) + inline void add(ref_ptr attribute) { - _stateComponents.push_back(component); + _attributes.push_back(attribute); } - StateCommands _stateComponents; + void dispatch(CommandBuffer& commandBuffer) const override + { + _bindDescriptorSets->dispatch(commandBuffer); + } + + StateAttributes _attributes; + VkPipelineBindPoint _bindPoint; + uint32_t _firstSet; protected: virtual ~StateSet(); + + + ref_ptr _bindDescriptorSets; }; VSG_type_name(vsg::StateSet); @@ -89,35 +89,37 @@ namespace vsg public: StateGroup(Allocator* allocator = nullptr); - StateGroup(StateSet* stateset); - void read(Input& input) override; void write(Output& output) const override; using StateCommands = std::vector>; - void add(ref_ptr component) + void add(ref_ptr stateCommand) { - _stateset->add(component); + _stateCommands.push_back(stateCommand); } - void setStateSet(ref_ptr stateset) { _stateset = stateset; } - StateSet* getStateSet() { return _stateset; } - const StateSet* getStateSet() const { return _stateset; } - inline void pushTo(State& state) const { - _stateset->pushTo(state); + for(auto& stateCommand : _stateCommands) + { + stateCommand->pushTo(state); + } } inline void popFrom(State& state) const { - _stateset->popFrom(state); + for(auto& stateCommand : _stateCommands) + { + stateCommand->popFrom(state); + } } + virtual void compile(Context& context); + protected: virtual ~StateGroup(); - ref_ptr _stateset; + StateCommands _stateCommands; }; VSG_type_name(vsg::StateGroup); diff --git a/include/vsg/traversals/CompileTraversal.h b/include/vsg/traversals/CompileTraversal.h index 8710640254..3f4814761d 100644 --- a/include/vsg/traversals/CompileTraversal.h +++ b/include/vsg/traversals/CompileTraversal.h @@ -15,6 +15,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include + #include #include #include diff --git a/include/vsg/vk/Command.h b/include/vsg/vk/Command.h index 7edc9abd0d..8bfbafcd95 100644 --- a/include/vsg/vk/Command.h +++ b/include/vsg/vk/Command.h @@ -19,6 +19,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { class CommandBuffer; + class State; + class Context; class Command : public Inherit { @@ -28,4 +30,20 @@ namespace vsg virtual void dispatch(CommandBuffer& commandBuffer) const = 0; }; + + class StateCommand : public Inherit + { + public: + StateCommand(Allocator* allocator = nullptr) : Inherit(allocator) {} + + virtual void compile(Context& /*context*/) {} + + virtual void pushTo(State& state) const = 0; + virtual void popFrom(State& state) const = 0; + + protected: + virtual ~StateCommand() {} + }; + VSG_type_name(vsg::StateCommand); + } // namespace vsg diff --git a/include/vsg/vk/DescriptorSet.h b/include/vsg/vk/DescriptorSet.h index da05b899ff..956bd91e82 100644 --- a/include/vsg/vk/DescriptorSet.h +++ b/include/vsg/vk/DescriptorSet.h @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include #include #include diff --git a/include/vsg/vk/Pipeline.h b/include/vsg/vk/Pipeline.h index 8bcb80f75a..36c781457f 100644 --- a/include/vsg/vk/Pipeline.h +++ b/include/vsg/vk/Pipeline.h @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include namespace vsg diff --git a/src/vsg/nodes/StateGroup.cpp b/src/vsg/nodes/StateGroup.cpp index 404f8d50e8..c63027be39 100644 --- a/src/vsg/nodes/StateGroup.cpp +++ b/src/vsg/nodes/StateGroup.cpp @@ -18,7 +18,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; StateSet::StateSet(Allocator* allocator) : - Inherit(allocator) + Inherit(allocator), + _bindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS), + _firstSet(0) { } @@ -26,14 +28,29 @@ StateSet::~StateSet() { } +void StateSet::compile(Context& context) +{ + Descriptors descriptors; + descriptors.reserve(_attributes.size()); + for(auto& attribute : _attributes) + { + auto descriptor = attribute->compile(context); + if (descriptor) descriptors.push_back(descriptor); + } + + // should descriptorSetLayouts be provided by StateSet? A shared instance? + DescriptorSets descriptorSets{DescriptorSet::create(context.device, context.descriptorPool, context.descriptorSetLayouts, descriptors)}; + _bindDescriptorSets = BindDescriptorSets::create(_bindPoint, context.pipelineLayout, _firstSet, descriptorSets); +} + void StateSet::read(Input& input) { Object::read(input); - _stateComponents.resize(input.readValue("NumStateCommands")); - for (auto& child : _stateComponents) + _attributes.resize(input.readValue("NumStateAttributes")); + for (auto& child : _attributes) { - child = input.readObject("StateCommand"); + child = input.readObject("StateAttribute"); } } @@ -41,22 +58,15 @@ void StateSet::write(Output& output) const { Object::write(output); - output.writeValue("NumStateCommands", _stateComponents.size()); - for (auto& child : _stateComponents) + output.writeValue("NumStateAttributes", _attributes.size()); + for (auto& child : _attributes) { - output.writeObject("StateCommand", child.get()); + output.writeObject("StateAttribute", child.get()); } } StateGroup::StateGroup(Allocator* allocator) : - Inherit(allocator), - _stateset(new StateSet) -{ -} - -StateGroup::StateGroup(StateSet* stateset) : - Inherit(stateset ? stateset->getAllocator() : 0), - _stateset(stateset) + Inherit(allocator) { } @@ -68,12 +78,28 @@ void StateGroup::read(Input& input) { Group::read(input); - _stateset = input.readObject("StateSet"); + _stateCommands.resize(input.readValue("NumStateCommands")); + for (auto& child : _stateCommands) + { + child = input.readObject("StateCommand"); + } } void StateGroup::write(Output& output) const { Group::write(output); - output.writeObject("StateSet", _stateset.get()); + output.writeValue("NumStateCommands", _stateCommands.size()); + for (auto& child : _stateCommands) + { + output.writeObject("StateCommand", child.get()); + } +} + +void StateGroup::compile(Context& context) +{ + for(auto& stateCommand : _stateCommands) + { + stateCommand->compile(context); + } } diff --git a/src/vsg/traversals/CompileTraversal.cpp b/src/vsg/traversals/CompileTraversal.cpp index ebd7063057..a1db7ddd9f 100644 --- a/src/vsg/traversals/CompileTraversal.cpp +++ b/src/vsg/traversals/CompileTraversal.cpp @@ -70,7 +70,7 @@ void CompileTraversal::apply(Group& group) void CompileTraversal::apply(StateGroup& stateGroup) { // std::cout<<"CompileTraversal::apply(StateGroup&)"<compile(context); + stateGroup.compile(context); stateGroup.traverse(*this); } From 772931642ad99a32623de7b22f40a77781a0280e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Feb 2019 17:13:14 +0000 Subject: [PATCH 03/21] Fixed copy and paste bug. --- include/vsg/nodes/StateGroup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vsg/nodes/StateGroup.h b/include/vsg/nodes/StateGroup.h index c3da35827d..b14dff6ba4 100644 --- a/include/vsg/nodes/StateGroup.h +++ b/include/vsg/nodes/StateGroup.h @@ -58,7 +58,7 @@ namespace vsg virtual void popFrom(State& state) const { - _bindDescriptorSets->pushTo(state); + _bindDescriptorSets->popFrom(state); } inline void add(ref_ptr attribute) From e416a0991e8131e22728ccdd93a71ac7602921db Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Mar 2019 14:37:36 +0000 Subject: [PATCH 04/21] Refactored PipelineLayout so that the the main public class is now a data container that has a nested Implementation class to uses this data to create the appropriate the Vulkan object from this. --- include/vsg/traversals/CompileTraversal.h | 2 +- include/vsg/vk/CommandBuffer.h | 4 +- include/vsg/vk/ComputePipeline.h | 4 +- include/vsg/vk/DescriptorSet.h | 6 +-- include/vsg/vk/GraphicsPipeline.h | 4 +- include/vsg/vk/Pipeline.h | 8 ++-- include/vsg/vk/PipelineLayout.h | 45 ++++++++++++++++++----- src/vsg/vk/ComputePipeline.cpp | 4 +- src/vsg/vk/GraphicsPipeline.cpp | 4 +- src/vsg/vk/Pipeline.cpp | 2 +- src/vsg/vk/PipelineLayout.cpp | 33 +++++++++++++++-- src/vsg/vk/PushConstants.cpp | 2 +- 12 files changed, 85 insertions(+), 33 deletions(-) diff --git a/include/vsg/traversals/CompileTraversal.h b/include/vsg/traversals/CompileTraversal.h index 3f4814761d..483cac163f 100644 --- a/include/vsg/traversals/CompileTraversal.h +++ b/include/vsg/traversals/CompileTraversal.h @@ -33,7 +33,7 @@ namespace vsg ref_ptr descriptorPool; DescriptorSetLayouts descriptorSetLayouts; - ref_ptr pipelineLayout; + ref_ptr pipelineLayout; ref_ptr projMatrix; ref_ptr viewMatrix; diff --git a/include/vsg/vk/CommandBuffer.h b/include/vsg/vk/CommandBuffer.h index edc362d61d..b90eb3ea33 100644 --- a/include/vsg/vk/CommandBuffer.h +++ b/include/vsg/vk/CommandBuffer.h @@ -43,7 +43,7 @@ namespace vsg } const Pipeline* getCurrentPipeline() const { return _currentPipeline; } - const PipelineLayout* getCurrentPipelineLayout() const { return _currentPipelineLayout; } + const PipelineLayout::Implementation* getCurrentPipelineLayout() const { return _currentPipelineLayout; } protected: virtual ~CommandBuffer(); @@ -54,7 +54,7 @@ namespace vsg ref_ptr _device; ref_ptr _commandPool; ref_ptr _currentPipeline; - ref_ptr _currentPipelineLayout; + ref_ptr _currentPipelineLayout; }; template diff --git a/include/vsg/vk/ComputePipeline.h b/include/vsg/vk/ComputePipeline.h index 06c1a5d0e0..0ca9ea71cb 100644 --- a/include/vsg/vk/ComputePipeline.h +++ b/include/vsg/vk/ComputePipeline.h @@ -25,10 +25,10 @@ namespace vsg using Result = vsg::Result; /** Crreate a ComputePipeline.*/ - static Result create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); + static Result create(Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); protected: - ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); + ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); virtual ~ComputePipeline(); diff --git a/include/vsg/vk/DescriptorSet.h b/include/vsg/vk/DescriptorSet.h index 956bd91e82..9fe5e52541 100644 --- a/include/vsg/vk/DescriptorSet.h +++ b/include/vsg/vk/DescriptorSet.h @@ -50,7 +50,7 @@ namespace vsg class VSG_DECLSPEC BindDescriptorSets : public Inherit { public: - BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) : + BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout::Implementation* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) : _bindPoint(bindPoint), _pipelineLayout(pipelineLayout), _firstSet(firstSet), @@ -59,7 +59,7 @@ namespace vsg update(); } - BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, const DescriptorSets& descriptorSets) : + BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout::Implementation* pipelineLayout, const DescriptorSets& descriptorSets) : _bindPoint(bindPoint), _pipelineLayout(pipelineLayout), _firstSet(0), @@ -87,7 +87,7 @@ namespace vsg using VkDescriptorSets = std::vector; VkPipelineBindPoint _bindPoint; - ref_ptr _pipelineLayout; + ref_ptr _pipelineLayout; uint32_t _firstSet; DescriptorSets _descriptorSets; VkDescriptorSets _vkDescriptorSets; diff --git a/include/vsg/vk/GraphicsPipeline.h b/include/vsg/vk/GraphicsPipeline.h index c80883a8cf..b4511156da 100644 --- a/include/vsg/vk/GraphicsPipeline.h +++ b/include/vsg/vk/GraphicsPipeline.h @@ -43,7 +43,7 @@ namespace vsg using Result = vsg::Result; /** Crreate a GraphicsPipeline.*/ - static Result create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); + static Result create(Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); RenderPass* getRenderPass() { return _renderPass; } const RenderPass* getRenderPass() const { return _renderPass; } @@ -52,7 +52,7 @@ namespace vsg const GraphicsPipelineStates& getPipelineStates() const { return _pipelineStates; } protected: - GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); + GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); virtual ~GraphicsPipeline(); diff --git a/include/vsg/vk/Pipeline.h b/include/vsg/vk/Pipeline.h index 36c781457f..6bfd4f8866 100644 --- a/include/vsg/vk/Pipeline.h +++ b/include/vsg/vk/Pipeline.h @@ -21,7 +21,7 @@ namespace vsg class VSG_DECLSPEC Pipeline : public Inherit { public: - Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator = nullptr); + Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout::Implementation* pipelineLayout, AllocationCallbacks* allocator = nullptr); operator VkPipeline() const { return _pipeline; } @@ -30,8 +30,8 @@ namespace vsg Device* getDevice() { return _device; } const Device* getDevice() const { return _device; } - PipelineLayout* getPipelineLayout() { return _pipelineLayout; } - const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; } + PipelineLayout::Implementation* getPipelineLayout() { return _pipelineLayout; } + const PipelineLayout::Implementation* getPipelineLayout() const { return _pipelineLayout; } protected: virtual ~Pipeline(); @@ -39,7 +39,7 @@ namespace vsg VkPipeline _pipeline; VkPipelineBindPoint _bindPoint; ref_ptr _device; - ref_ptr _pipelineLayout; + ref_ptr _pipelineLayout; ref_ptr _allocator; }; VSG_type_name(vsg::Pipeline); diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index dc38186f75..f01e4fc92c 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -18,29 +18,56 @@ namespace vsg { using PushConstantRanges = std::vector; + class Context; class VSG_DECLSPEC PipelineLayout : public Inherit { public: - PipelineLayout(VkPipelineLayout pipelineLayout, const DescriptorSetLayouts& descrtorSetLayouts, Device* device, AllocationCallbacks* allocator = nullptr); + PipelineLayout(const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags=0); - using Result = vsg::Result; + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(VkPipelineLayout pipelineLayout, const DescriptorSetLayouts& descrtorSetLayouts, Device* device, AllocationCallbacks* allocator = nullptr); - static Result create(Device* device, const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags = 0, AllocationCallbacks* allocator = nullptr); + using Result = vsg::Result; - operator VkPipelineLayout() const { return _pipelineLayout; } + static Result create(Device* device, const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags = 0, AllocationCallbacks* allocator = nullptr); - Device* getDevice() { return _device; } - const Device* getDevice() const { return _device; } + operator VkPipelineLayout() const { return _pipelineLayout; } + + Device* getDevice() { return _device; } + const Device* getDevice() const { return _device; } + + protected: + virtual ~Implementation(); + + VkPipelineLayout _pipelineLayout; + DescriptorSetLayouts _descriptorSetLayouts; + + ref_ptr _device; + ref_ptr _allocator; + }; + + // compile the Vulkna PipelineLayout object, context parameter used for Device + void compile(Context& context); + + // remove the local reference to the Vulkan PipelineLayout implementation + void release() { _implementation = nullptr; } + + operator VkPipelineLayout() const { return *_implementation; } + + Implementation* implementation() { return _implementation; } + const Implementation* implementation() const { return _implementation; } protected: virtual ~PipelineLayout(); - VkPipelineLayout _pipelineLayout; DescriptorSetLayouts _descriptorSetLayouts; + PushConstantRanges _pushConstantRanges; + VkPipelineLayoutCreateFlags _flags; - ref_ptr _device; - ref_ptr _allocator; + ref_ptr _implementation; }; } // namespace vsg diff --git a/src/vsg/vk/ComputePipeline.cpp b/src/vsg/vk/ComputePipeline.cpp index 4fd164830d..526038469e 100644 --- a/src/vsg/vk/ComputePipeline.cpp +++ b/src/vsg/vk/ComputePipeline.cpp @@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -ComputePipeline::ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : +ComputePipeline::ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : Inherit(pipeline, VK_PIPELINE_BIND_POINT_COMPUTE, device, pipelineLayout, allocator), _shaderModule(shaderModule) { @@ -24,7 +24,7 @@ ComputePipeline::~ComputePipeline() { } -ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) +ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) { if (!device || !pipelineLayout || !shaderModule) { diff --git a/src/vsg/vk/GraphicsPipeline.cpp b/src/vsg/vk/GraphicsPipeline.cpp index c3f2dfd663..d639f2b4ed 100644 --- a/src/vsg/vk/GraphicsPipeline.cpp +++ b/src/vsg/vk/GraphicsPipeline.cpp @@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -GraphicsPipeline::GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : +GraphicsPipeline::GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : Inherit(pipeline, VK_PIPELINE_BIND_POINT_GRAPHICS, device, pipelineLayout, allocator), _renderPass(renderPass), _pipelineStates(pipelineStates) @@ -25,7 +25,7 @@ GraphicsPipeline::~GraphicsPipeline() { } -GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) +GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) { if (!device || !renderPass || !pipelineLayout) { diff --git a/src/vsg/vk/Pipeline.cpp b/src/vsg/vk/Pipeline.cpp index 03bb6e93e5..998074fb5d 100644 --- a/src/vsg/vk/Pipeline.cpp +++ b/src/vsg/vk/Pipeline.cpp @@ -20,7 +20,7 @@ using namespace vsg; // // Pipeline // -Pipeline::Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator) : +Pipeline::Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout::Implementation* pipelineLayout, AllocationCallbacks* allocator) : _pipeline(pipeline), _bindPoint(bindPoint), _device(device), diff --git a/src/vsg/vk/PipelineLayout.cpp b/src/vsg/vk/PipelineLayout.cpp index 797b5424aa..c7ad101ce9 100644 --- a/src/vsg/vk/PipelineLayout.cpp +++ b/src/vsg/vk/PipelineLayout.cpp @@ -11,10 +11,35 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include using namespace vsg; -PipelineLayout::PipelineLayout(VkPipelineLayout pipelineLayout, const DescriptorSetLayouts& descriptorSetLayouts, Device* device, AllocationCallbacks* allocator) : +////////////////////////////////////// +// +// PipelineLayout +// +PipelineLayout::PipelineLayout(const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags): + _descriptorSetLayouts(descriptorSetLayouts), + _pushConstantRanges(pushConstantRanges), + _flags(flags) +{ +} + +PipelineLayout::~PipelineLayout() +{ +} + +void PipelineLayout::compile(Context& context) +{ + if (!_implementation) _implementation = PipelineLayout::Implementation::create(context.device, _descriptorSetLayouts, _pushConstantRanges, _flags); +} + +////////////////////////////////////// +// +// PipelineLayout::Implementation +// +PipelineLayout::Implementation::Implementation(VkPipelineLayout pipelineLayout, const DescriptorSetLayouts& descriptorSetLayouts, Device* device, AllocationCallbacks* allocator) : _pipelineLayout(pipelineLayout), _descriptorSetLayouts(descriptorSetLayouts), _device(device), @@ -22,7 +47,7 @@ PipelineLayout::PipelineLayout(VkPipelineLayout pipelineLayout, const Descriptor { } -PipelineLayout::~PipelineLayout() +PipelineLayout::Implementation::~Implementation() { if (_pipelineLayout) { @@ -30,7 +55,7 @@ PipelineLayout::~PipelineLayout() } } -PipelineLayout::Result PipelineLayout::create(Device* device, const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags, AllocationCallbacks* allocator) +PipelineLayout::Implementation::Result PipelineLayout::Implementation::create(Device* device, const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags, AllocationCallbacks* allocator) { if (!device) { @@ -52,7 +77,7 @@ PipelineLayout::Result PipelineLayout::create(Device* device, const DescriptorSe VkResult result = vkCreatePipelineLayout(*device, &pipelineLayoutInfo, allocator, &pipelineLayout); if (result == VK_SUCCESS) { - return Result(new PipelineLayout(pipelineLayout, descriptorSetLayouts, device, allocator)); + return Result(new PipelineLayout::Implementation(pipelineLayout, descriptorSetLayouts, device, allocator)); } else { diff --git a/src/vsg/vk/PushConstants.cpp b/src/vsg/vk/PushConstants.cpp index afe79a8677..a94546854b 100644 --- a/src/vsg/vk/PushConstants.cpp +++ b/src/vsg/vk/PushConstants.cpp @@ -38,7 +38,7 @@ void PushConstants::popFrom(State& state) const void PushConstants::dispatch(CommandBuffer& commandBuffer) const { - const PipelineLayout* pipelineLayout = commandBuffer.getCurrentPipelineLayout(); + const PipelineLayout::Implementation* pipelineLayout = commandBuffer.getCurrentPipelineLayout(); if (pipelineLayout) { From 1fa3bf58de52be86a49002a04498622f711262d8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Mar 2019 16:10:19 +0000 Subject: [PATCH 05/21] Refaced DescriptorSetLayout into new Interface::Implementation arrangement. --- include/vsg/vk/DescriptorSetLayout.h | 42 ++++++++++++++++++++++------ include/vsg/vk/PipelineLayout.h | 4 +-- src/vsg/vk/DescriptorSetLayout.cpp | 31 +++++++++++++++++--- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/include/vsg/vk/DescriptorSetLayout.h b/include/vsg/vk/DescriptorSetLayout.h index 1ef81d5490..f4bd960dcb 100644 --- a/include/vsg/vk/DescriptorSetLayout.h +++ b/include/vsg/vk/DescriptorSetLayout.h @@ -17,26 +17,52 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { using DescriptorSetLayoutBindings = std::vector; + class Context; class VSG_DECLSPEC DescriptorSetLayout : public Inherit { public: - DescriptorSetLayout(Device* device, VkDescriptorSetLayout DescriptorSetLayout, AllocationCallbacks* allocator = nullptr); - using Result = vsg::Result; + DescriptorSetLayout(const DescriptorSetLayoutBindings& descriptorSetLayoutBindings); - static Result create(Device* device, const DescriptorSetLayoutBindings& descriptorSetLayoutBindings, AllocationCallbacks* allocator = nullptr); + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(Device* device, VkDescriptorSetLayout DescriptorSetLayout, AllocationCallbacks* allocator = nullptr); - operator const VkDescriptorSetLayout&() const { return _descriptorSetLayout; } + using Result = vsg::Result; + + static Result create(Device* device, const DescriptorSetLayoutBindings& descriptorSetLayoutBindings, AllocationCallbacks* allocator = nullptr); + + operator VkDescriptorSetLayout () const { return _descriptorSetLayout; } + + protected: + virtual ~Implementation(); + + ref_ptr _device; + VkDescriptorSetLayout _descriptorSetLayout; + ref_ptr _allocator; + }; + + // compile the Vulkna object, context parameter used for Device + void compile(Context& context); + + // remove the local reference to the Vulkan implementation + void release() { _implementation = nullptr; } + + operator VkDescriptorSetLayout() const { return *_implementation; } + + Implementation* implementation() { return _implementation; } + const Implementation* implementation() const { return _implementation; } protected: virtual ~DescriptorSetLayout(); - ref_ptr _device; - VkDescriptorSetLayout _descriptorSetLayout; - ref_ptr _allocator; + DescriptorSetLayoutBindings _descriptorSetLayoutBindings; + + ref_ptr _implementation; }; - using DescriptorSetLayouts = std::vector>; + using DescriptorSetLayouts = std::vector>; } // namespace vsg diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index f01e4fc92c..4258188256 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -49,10 +49,10 @@ namespace vsg ref_ptr _allocator; }; - // compile the Vulkna PipelineLayout object, context parameter used for Device + // compile the Vulkna object, context parameter used for Device void compile(Context& context); - // remove the local reference to the Vulkan PipelineLayout implementation + // remove the local reference to the Vulkan implementation void release() { _implementation = nullptr; } operator VkPipelineLayout() const { return *_implementation; } diff --git a/src/vsg/vk/DescriptorSetLayout.cpp b/src/vsg/vk/DescriptorSetLayout.cpp index 53f0cfdf25..8ec9c0ee11 100644 --- a/src/vsg/vk/DescriptorSetLayout.cpp +++ b/src/vsg/vk/DescriptorSetLayout.cpp @@ -11,17 +11,40 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include using namespace vsg; -DescriptorSetLayout::DescriptorSetLayout(Device* device, VkDescriptorSetLayout descriptorSetLayout, AllocationCallbacks* allocator) : +////////////////////////////////////// +// +// DescriptorSetLayout +// +DescriptorSetLayout::DescriptorSetLayout(const DescriptorSetLayoutBindings& descriptorSetLayoutBindings): + _descriptorSetLayoutBindings(descriptorSetLayoutBindings) +{ +} + +DescriptorSetLayout::~DescriptorSetLayout() +{ +} + +void DescriptorSetLayout::compile(Context& context) +{ + if (!_implementation) _implementation = DescriptorSetLayout::Implementation::create(context.device, _descriptorSetLayoutBindings); +} + +////////////////////////////////////// +// +// DescriptorSetLayout::Implementation +// +DescriptorSetLayout::Implementation::Implementation(Device* device, VkDescriptorSetLayout descriptorSetLayout, AllocationCallbacks* allocator) : _device(device), _descriptorSetLayout(descriptorSetLayout), _allocator(allocator) { } -DescriptorSetLayout::~DescriptorSetLayout() +DescriptorSetLayout::Implementation::~Implementation() { if (_descriptorSetLayout) { @@ -29,7 +52,7 @@ DescriptorSetLayout::~DescriptorSetLayout() } } -DescriptorSetLayout::Result DescriptorSetLayout::create(Device* device, const DescriptorSetLayoutBindings& descriptorSetLayoutBindings, AllocationCallbacks* allocator) +DescriptorSetLayout::Implementation::Result DescriptorSetLayout::Implementation::create(Device* device, const DescriptorSetLayoutBindings& descriptorSetLayoutBindings, AllocationCallbacks* allocator) { if (!device) { @@ -45,7 +68,7 @@ DescriptorSetLayout::Result DescriptorSetLayout::create(Device* device, const De VkResult result = vkCreateDescriptorSetLayout(*device, &layoutInfo, allocator, &descriptorSetLayout); if (result == VK_SUCCESS) { - return Result(new DescriptorSetLayout(device, descriptorSetLayout, allocator)); + return Result(new Implementation(device, descriptorSetLayout, allocator)); } else { From 6fd10e56ab69aa41f3766bfa582a2834dc393167 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 3 Mar 2019 15:58:30 +0000 Subject: [PATCH 06/21] Refactor of Pipeline/ComputePipeline/GraphicsPipeline, PipelineLayout and Descriptor classes to the new Inteface::Implementation paradigm. Removed the StateAttribute/StateSet classes as these are no longer required with DescriptorSet/Descriptor taking on this role directly. --- include/vsg/nodes/StateGroup.h | 58 -------------------- include/vsg/traversals/CompileTraversal.h | 3 +- include/vsg/vk/Command.h | 4 +- include/vsg/vk/CommandBuffer.h | 4 +- include/vsg/vk/ComputePipeline.h | 4 +- include/vsg/vk/Descriptor.h | 5 ++ include/vsg/vk/DescriptorSet.h | 64 +++++++++++++++-------- include/vsg/vk/DescriptorSetLayout.h | 8 +-- include/vsg/vk/GraphicsPipeline.h | 4 +- include/vsg/vk/Pipeline.h | 8 +-- include/vsg/vk/PipelineLayout.h | 5 +- src/vsg/nodes/StateGroup.cpp | 48 ----------------- src/vsg/traversals/CompileTraversal.cpp | 5 ++ src/vsg/vk/ComputePipeline.cpp | 4 +- src/vsg/vk/DescriptorSet.cpp | 46 +++++++++++++--- src/vsg/vk/GraphicsPipeline.cpp | 4 +- src/vsg/vk/Pipeline.cpp | 2 +- src/vsg/vk/PushConstants.cpp | 2 +- 18 files changed, 118 insertions(+), 160 deletions(-) diff --git a/include/vsg/nodes/StateGroup.h b/include/vsg/nodes/StateGroup.h index b14dff6ba4..10afffe5a6 100644 --- a/include/vsg/nodes/StateGroup.h +++ b/include/vsg/nodes/StateGroup.h @@ -25,64 +25,6 @@ namespace vsg class State; class CommandBuffer; - // scene graph interface for encapsulating the creation Descriptor's such as for wrapping uniforms and textures - class StateAttribute : public Inherit - { - public: - StateAttribute(Allocator* allocator = nullptr) : Inherit(allocator) {} - - virtual ref_ptr compile(Context& /*context*/) = 0; - - protected: - virtual ~StateAttribute() {} - }; - VSG_type_name(vsg::StateAttribute); - - // scene graph interface for enacpsulating the binding of StateAttributes togther into a single VkCmdBindDescriptorSets/VkDescriptorSets - class VSG_DECLSPEC StateSet : public Inherit - { - public: - StateSet(Allocator* allocator = nullptr); - - void read(Input& input) override; - void write(Output& output) const override; - - using StateAttributes = std::vector>; - - virtual void compile(Context& context); - - virtual void pushTo(State& state) const - { - _bindDescriptorSets->pushTo(state); - } - - virtual void popFrom(State& state) const - { - _bindDescriptorSets->popFrom(state); - } - - inline void add(ref_ptr attribute) - { - _attributes.push_back(attribute); - } - - void dispatch(CommandBuffer& commandBuffer) const override - { - _bindDescriptorSets->dispatch(commandBuffer); - } - - StateAttributes _attributes; - VkPipelineBindPoint _bindPoint; - uint32_t _firstSet; - - protected: - virtual ~StateSet(); - - - ref_ptr _bindDescriptorSets; - }; - VSG_type_name(vsg::StateSet); - class VSG_DECLSPEC StateGroup : public Inherit { diff --git a/include/vsg/traversals/CompileTraversal.h b/include/vsg/traversals/CompileTraversal.h index 483cac163f..31e0dd7330 100644 --- a/include/vsg/traversals/CompileTraversal.h +++ b/include/vsg/traversals/CompileTraversal.h @@ -32,8 +32,6 @@ namespace vsg VkQueue graphicsQueue = 0; ref_ptr descriptorPool; - DescriptorSetLayouts descriptorSetLayouts; - ref_ptr pipelineLayout; ref_ptr projMatrix; ref_ptr viewMatrix; @@ -60,6 +58,7 @@ namespace vsg ~CompileTraversal(); void apply(Object& object); + void apply(Command& command); void apply(Group& group); void apply(StateGroup& stateGroup); void apply(GraphicsNode& graphics); diff --git a/include/vsg/vk/Command.h b/include/vsg/vk/Command.h index 8bfbafcd95..6dcaddc953 100644 --- a/include/vsg/vk/Command.h +++ b/include/vsg/vk/Command.h @@ -28,6 +28,8 @@ namespace vsg Command(Allocator* allocator = nullptr) : Inherit(allocator) {} + virtual void compile(Context& /*context*/) {} + virtual void dispatch(CommandBuffer& commandBuffer) const = 0; }; @@ -36,8 +38,6 @@ namespace vsg public: StateCommand(Allocator* allocator = nullptr) : Inherit(allocator) {} - virtual void compile(Context& /*context*/) {} - virtual void pushTo(State& state) const = 0; virtual void popFrom(State& state) const = 0; diff --git a/include/vsg/vk/CommandBuffer.h b/include/vsg/vk/CommandBuffer.h index b90eb3ea33..edc362d61d 100644 --- a/include/vsg/vk/CommandBuffer.h +++ b/include/vsg/vk/CommandBuffer.h @@ -43,7 +43,7 @@ namespace vsg } const Pipeline* getCurrentPipeline() const { return _currentPipeline; } - const PipelineLayout::Implementation* getCurrentPipelineLayout() const { return _currentPipelineLayout; } + const PipelineLayout* getCurrentPipelineLayout() const { return _currentPipelineLayout; } protected: virtual ~CommandBuffer(); @@ -54,7 +54,7 @@ namespace vsg ref_ptr _device; ref_ptr _commandPool; ref_ptr _currentPipeline; - ref_ptr _currentPipelineLayout; + ref_ptr _currentPipelineLayout; }; template diff --git a/include/vsg/vk/ComputePipeline.h b/include/vsg/vk/ComputePipeline.h index 0ca9ea71cb..06c1a5d0e0 100644 --- a/include/vsg/vk/ComputePipeline.h +++ b/include/vsg/vk/ComputePipeline.h @@ -25,10 +25,10 @@ namespace vsg using Result = vsg::Result; /** Crreate a ComputePipeline.*/ - static Result create(Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); + static Result create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); protected: - ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); + ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); virtual ~ComputePipeline(); diff --git a/include/vsg/vk/Descriptor.h b/include/vsg/vk/Descriptor.h index c36aa50daf..01dc2af2d8 100644 --- a/include/vsg/vk/Descriptor.h +++ b/include/vsg/vk/Descriptor.h @@ -19,6 +19,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { + // forward declare + class Context; using DescriptorBufferInfos = std::vector; @@ -36,6 +38,9 @@ namespace vsg uint32_t _dstArrayElement; VkDescriptorType _descriptorType; + // compile the Vulkan object, context parameter used for Device + virtual void compile(Context& /*context*/) {} + virtual void assignTo(VkWriteDescriptorSet& wds, VkDescriptorSet descriptorSet) const { wds = {}; diff --git a/include/vsg/vk/DescriptorSet.h b/include/vsg/vk/DescriptorSet.h index 9fe5e52541..731795dd99 100644 --- a/include/vsg/vk/DescriptorSet.h +++ b/include/vsg/vk/DescriptorSet.h @@ -24,24 +24,50 @@ namespace vsg class VSG_DECLSPEC DescriptorSet : public Inherit { public: - DescriptorSet(VkDescriptorSet descriptorSet, Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors); - using Result = vsg::Result; + DescriptorSet(const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors); - static Result create(Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors); + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(VkDescriptorSet descriptorSet, Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors); + + using Result = vsg::Result; + + static Result create(Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors); + + void assign(const Descriptors& descriptors); + + operator VkDescriptorSet() const { return _descriptorSet; } + + protected: + virtual ~Implementation(); + + VkDescriptorSet _descriptorSet; + ref_ptr _device; + ref_ptr _descriptorPool; + DescriptorSetLayouts _descriptorSetLayouts; + Descriptors _descriptors; + }; + + // compile the Vulkan object, context parameter used for Device + void compile(Context& context); - void assign(const Descriptors& descriptors); + // remove the local reference to the Vulkan implementation + void release() { _implementation = nullptr; } - operator VkDescriptorSet() const { return _descriptorSet; } + operator VkDescriptorSet() const { return *_implementation; } + + Implementation* implementation() { return _implementation; } + const Implementation* implementation() const { return _implementation; } protected: virtual ~DescriptorSet(); - VkDescriptorSet _descriptorSet; - ref_ptr _device; - ref_ptr _descriptorPool; DescriptorSetLayouts _descriptorSetLayouts; Descriptors _descriptors; + + ref_ptr _implementation; }; VSG_type_name(vsg::DescriptorSet); @@ -50,46 +76,38 @@ namespace vsg class VSG_DECLSPEC BindDescriptorSets : public Inherit { public: - BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout::Implementation* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) : + BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) : _bindPoint(bindPoint), _pipelineLayout(pipelineLayout), _firstSet(firstSet), _descriptorSets(descriptorSets) { - update(); } - BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout::Implementation* pipelineLayout, const DescriptorSets& descriptorSets) : + BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, const DescriptorSets& descriptorSets) : _bindPoint(bindPoint), _pipelineLayout(pipelineLayout), _firstSet(0), _descriptorSets(descriptorSets) { - update(); } void pushTo(State& state) const override; void popFrom(State& state) const override; void dispatch(CommandBuffer& commandBuffer) const override; - void update() - { - _vkDescriptorSets.resize(_descriptorSets.size()); - for (size_t i = 0; i < _descriptorSets.size(); ++i) - { - _vkDescriptorSets[i] = *(_descriptorSets[i]); - } - } + // compile the Vulkan object, context parameter used for Device + void compile(Context& context) override; protected: virtual ~BindDescriptorSets() {} - using VkDescriptorSets = std::vector; - VkPipelineBindPoint _bindPoint; - ref_ptr _pipelineLayout; + ref_ptr _pipelineLayout; uint32_t _firstSet; DescriptorSets _descriptorSets; + + using VkDescriptorSets = std::vector; VkDescriptorSets _vkDescriptorSets; }; VSG_type_name(vsg::BindDescriptorSets); diff --git a/include/vsg/vk/DescriptorSetLayout.h b/include/vsg/vk/DescriptorSetLayout.h index f4bd960dcb..fdaa74b47d 100644 --- a/include/vsg/vk/DescriptorSetLayout.h +++ b/include/vsg/vk/DescriptorSetLayout.h @@ -16,9 +16,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - using DescriptorSetLayoutBindings = std::vector; + // forward declare class Context; + using DescriptorSetLayoutBindings = std::vector; + class VSG_DECLSPEC DescriptorSetLayout : public Inherit { public: @@ -44,7 +46,7 @@ namespace vsg ref_ptr _allocator; }; - // compile the Vulkna object, context parameter used for Device + // compile the Vulkan object, context parameter used for Device void compile(Context& context); // remove the local reference to the Vulkan implementation @@ -63,6 +65,6 @@ namespace vsg ref_ptr _implementation; }; - using DescriptorSetLayouts = std::vector>; + using DescriptorSetLayouts = std::vector>; } // namespace vsg diff --git a/include/vsg/vk/GraphicsPipeline.h b/include/vsg/vk/GraphicsPipeline.h index b4511156da..c80883a8cf 100644 --- a/include/vsg/vk/GraphicsPipeline.h +++ b/include/vsg/vk/GraphicsPipeline.h @@ -43,7 +43,7 @@ namespace vsg using Result = vsg::Result; /** Crreate a GraphicsPipeline.*/ - static Result create(Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); + static Result create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); RenderPass* getRenderPass() { return _renderPass; } const RenderPass* getRenderPass() const { return _renderPass; } @@ -52,7 +52,7 @@ namespace vsg const GraphicsPipelineStates& getPipelineStates() const { return _pipelineStates; } protected: - GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); + GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); virtual ~GraphicsPipeline(); diff --git a/include/vsg/vk/Pipeline.h b/include/vsg/vk/Pipeline.h index 6bfd4f8866..36c781457f 100644 --- a/include/vsg/vk/Pipeline.h +++ b/include/vsg/vk/Pipeline.h @@ -21,7 +21,7 @@ namespace vsg class VSG_DECLSPEC Pipeline : public Inherit { public: - Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout::Implementation* pipelineLayout, AllocationCallbacks* allocator = nullptr); + Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator = nullptr); operator VkPipeline() const { return _pipeline; } @@ -30,8 +30,8 @@ namespace vsg Device* getDevice() { return _device; } const Device* getDevice() const { return _device; } - PipelineLayout::Implementation* getPipelineLayout() { return _pipelineLayout; } - const PipelineLayout::Implementation* getPipelineLayout() const { return _pipelineLayout; } + PipelineLayout* getPipelineLayout() { return _pipelineLayout; } + const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; } protected: virtual ~Pipeline(); @@ -39,7 +39,7 @@ namespace vsg VkPipeline _pipeline; VkPipelineBindPoint _bindPoint; ref_ptr _device; - ref_ptr _pipelineLayout; + ref_ptr _pipelineLayout; ref_ptr _allocator; }; VSG_type_name(vsg::Pipeline); diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index 4258188256..89933f88a9 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -16,9 +16,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { + // forward declare + class Context; using PushConstantRanges = std::vector; - class Context; class VSG_DECLSPEC PipelineLayout : public Inherit { @@ -49,7 +50,7 @@ namespace vsg ref_ptr _allocator; }; - // compile the Vulkna object, context parameter used for Device + // compile the Vulkan object, context parameter used for Device void compile(Context& context); // remove the local reference to the Vulkan implementation diff --git a/src/vsg/nodes/StateGroup.cpp b/src/vsg/nodes/StateGroup.cpp index c63027be39..ac318b1de2 100644 --- a/src/vsg/nodes/StateGroup.cpp +++ b/src/vsg/nodes/StateGroup.cpp @@ -17,54 +17,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -StateSet::StateSet(Allocator* allocator) : - Inherit(allocator), - _bindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS), - _firstSet(0) -{ -} - -StateSet::~StateSet() -{ -} - -void StateSet::compile(Context& context) -{ - Descriptors descriptors; - descriptors.reserve(_attributes.size()); - for(auto& attribute : _attributes) - { - auto descriptor = attribute->compile(context); - if (descriptor) descriptors.push_back(descriptor); - } - - // should descriptorSetLayouts be provided by StateSet? A shared instance? - DescriptorSets descriptorSets{DescriptorSet::create(context.device, context.descriptorPool, context.descriptorSetLayouts, descriptors)}; - _bindDescriptorSets = BindDescriptorSets::create(_bindPoint, context.pipelineLayout, _firstSet, descriptorSets); -} - -void StateSet::read(Input& input) -{ - Object::read(input); - - _attributes.resize(input.readValue("NumStateAttributes")); - for (auto& child : _attributes) - { - child = input.readObject("StateAttribute"); - } -} - -void StateSet::write(Output& output) const -{ - Object::write(output); - - output.writeValue("NumStateAttributes", _attributes.size()); - for (auto& child : _attributes) - { - output.writeObject("StateAttribute", child.get()); - } -} - StateGroup::StateGroup(Allocator* allocator) : Inherit(allocator) { diff --git a/src/vsg/traversals/CompileTraversal.cpp b/src/vsg/traversals/CompileTraversal.cpp index a1db7ddd9f..897868cf1a 100644 --- a/src/vsg/traversals/CompileTraversal.cpp +++ b/src/vsg/traversals/CompileTraversal.cpp @@ -54,6 +54,11 @@ void CompileTraversal::apply(Object& object) object.traverse(*this); } +void CompileTraversal::apply(Command& command) +{ + command.compile(context); +} + void CompileTraversal::apply(Group& group) { auto graphics = dynamic_cast(&group); diff --git a/src/vsg/vk/ComputePipeline.cpp b/src/vsg/vk/ComputePipeline.cpp index 526038469e..4fd164830d 100644 --- a/src/vsg/vk/ComputePipeline.cpp +++ b/src/vsg/vk/ComputePipeline.cpp @@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -ComputePipeline::ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : +ComputePipeline::ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : Inherit(pipeline, VK_PIPELINE_BIND_POINT_COMPUTE, device, pipelineLayout, allocator), _shaderModule(shaderModule) { @@ -24,7 +24,7 @@ ComputePipeline::~ComputePipeline() { } -ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout::Implementation* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) +ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) { if (!device || !pipelineLayout || !shaderModule) { diff --git a/src/vsg/vk/DescriptorSet.cpp b/src/vsg/vk/DescriptorSet.cpp index 602982bf8c..8eaed910bc 100644 --- a/src/vsg/vk/DescriptorSet.cpp +++ b/src/vsg/vk/DescriptorSet.cpp @@ -15,7 +15,29 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -DescriptorSet::DescriptorSet(VkDescriptorSet descriptorSet, Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors) : +DescriptorSet::DescriptorSet(const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors): + _descriptorSetLayouts(descriptorSetLayouts), + _descriptors(descriptors) +{ +} + +DescriptorSet::~DescriptorSet() +{ +} + +void DescriptorSet::compile(Context& context) +{ + if (!_implementation) + { + // make sure all the contributing objects are compiled + for(auto& descriptorSetLayout : _descriptorSetLayouts) descriptorSetLayout->compile(context); + for(auto& descriptor : _descriptors) descriptor->compile(context); + + _implementation = DescriptorSet::Implementation::create(context.device, context.descriptorPool, _descriptorSetLayouts, _descriptors); + } +} + +DescriptorSet::Implementation::Implementation(VkDescriptorSet descriptorSet, Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors) : _descriptorSet(descriptorSet), _device(device), _descriptorPool(descriptorPool), @@ -24,7 +46,7 @@ DescriptorSet::DescriptorSet(VkDescriptorSet descriptorSet, Device* device, Desc assign(descriptors); } -DescriptorSet::~DescriptorSet() +DescriptorSet::Implementation::~Implementation() { if (_descriptorSet) { @@ -32,7 +54,7 @@ DescriptorSet::~DescriptorSet() } } -DescriptorSet::Result DescriptorSet::create(Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors) +DescriptorSet::Implementation::Result DescriptorSet::Implementation::create(Device* device, DescriptorPool* descriptorPool, const DescriptorSetLayouts& descriptorSetLayouts, const Descriptors& descriptors) { if (!device || !descriptorPool || descriptorSetLayouts.empty()) { @@ -45,6 +67,7 @@ DescriptorSet::Result DescriptorSet::create(Device* device, DescriptorPool* desc vkdescriptorSetLayouts.push_back(*descriptorSetLayout); } + VkDescriptorSetAllocateInfo descriptSetAllocateInfo = {}; descriptSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptSetAllocateInfo.descriptorPool = *descriptorPool; @@ -55,7 +78,7 @@ DescriptorSet::Result DescriptorSet::create(Device* device, DescriptorPool* desc VkResult result = vkAllocateDescriptorSets(*device, &descriptSetAllocateInfo, &descriptorSet); if (result == VK_SUCCESS) { - return Result(new DescriptorSet(descriptorSet, device, descriptorPool, descriptorSetLayouts, descriptors)); + return Result(new DescriptorSet::Implementation(descriptorSet, device, descriptorPool, descriptorSetLayouts, descriptors)); } else { @@ -63,7 +86,7 @@ DescriptorSet::Result DescriptorSet::create(Device* device, DescriptorPool* desc } } -void DescriptorSet::assign(const Descriptors& descriptors) +void DescriptorSet::Implementation::assign(const Descriptors& descriptors) { // should we doing anything about previous _descriptor that may have been assigned? _descriptors = descriptors; @@ -96,5 +119,16 @@ void BindDescriptorSets::popFrom(State& state) const void BindDescriptorSets::dispatch(CommandBuffer& commandBuffer) const { - vkCmdBindDescriptorSets(commandBuffer, _bindPoint, *_pipelineLayout, _firstSet, static_cast(_vkDescriptorSets.size()), _vkDescriptorSets.data(), 0, nullptr); + vkCmdBindDescriptorSets(commandBuffer, _bindPoint, *(_pipelineLayout), _firstSet, static_cast(_vkDescriptorSets.size()), _vkDescriptorSets.data(), 0, nullptr); +} + +void BindDescriptorSets::compile(Context& context) +{ + _vkDescriptorSets.resize(_descriptorSets.size()); + for (size_t i = 0; i < _descriptorSets.size(); ++i) + { + _descriptorSets[i]->compile(context); + + _vkDescriptorSets[i] = *(_descriptorSets[i]); + } } diff --git a/src/vsg/vk/GraphicsPipeline.cpp b/src/vsg/vk/GraphicsPipeline.cpp index d639f2b4ed..c3f2dfd663 100644 --- a/src/vsg/vk/GraphicsPipeline.cpp +++ b/src/vsg/vk/GraphicsPipeline.cpp @@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -GraphicsPipeline::GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : +GraphicsPipeline::GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : Inherit(pipeline, VK_PIPELINE_BIND_POINT_GRAPHICS, device, pipelineLayout, allocator), _renderPass(renderPass), _pipelineStates(pipelineStates) @@ -25,7 +25,7 @@ GraphicsPipeline::~GraphicsPipeline() { } -GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* renderPass, PipelineLayout::Implementation* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) +GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) { if (!device || !renderPass || !pipelineLayout) { diff --git a/src/vsg/vk/Pipeline.cpp b/src/vsg/vk/Pipeline.cpp index 998074fb5d..03bb6e93e5 100644 --- a/src/vsg/vk/Pipeline.cpp +++ b/src/vsg/vk/Pipeline.cpp @@ -20,7 +20,7 @@ using namespace vsg; // // Pipeline // -Pipeline::Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout::Implementation* pipelineLayout, AllocationCallbacks* allocator) : +Pipeline::Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator) : _pipeline(pipeline), _bindPoint(bindPoint), _device(device), diff --git a/src/vsg/vk/PushConstants.cpp b/src/vsg/vk/PushConstants.cpp index a94546854b..e0fcbe1e51 100644 --- a/src/vsg/vk/PushConstants.cpp +++ b/src/vsg/vk/PushConstants.cpp @@ -38,7 +38,7 @@ void PushConstants::popFrom(State& state) const void PushConstants::dispatch(CommandBuffer& commandBuffer) const { - const PipelineLayout::Implementation* pipelineLayout = commandBuffer.getCurrentPipelineLayout(); + const PipelineLayout::Implementation* pipelineLayout = commandBuffer.getCurrentPipelineLayout()->implementation(); if (pipelineLayout) { From 11d2dab30ee09bd045ab10583a993c4dc54f2e6d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 Mar 2019 17:36:33 +0000 Subject: [PATCH 07/21] Refactored GraphicsPipeline, ComputePipeline, PushConstant, Pipeline, PipelineLayout, ShadeerModule and related classes to work with the new Interface::Implemntation approach --- include/vsg/core/ConstVisitor.h | 6 +- include/vsg/core/Visitor.h | 6 +- include/vsg/traversals/DispatchTraversal.h | 4 + include/vsg/vk/CommandBuffer.h | 12 +-- include/vsg/vk/ComputePipeline.h | 66 ++++++++++-- include/vsg/vk/GraphicsPipeline.h | 87 ++++++++++++++-- include/vsg/vk/Pipeline.h | 67 ------------ include/vsg/vk/PipelineLayout.h | 10 ++ include/vsg/vk/ShaderModule.h | 58 ++++++----- include/vsg/vk/State.h | 87 ++++++++++++++-- src/vsg/CMakeLists.txt | 1 - src/vsg/core/ConstVisitor.cpp | 6 +- src/vsg/core/Visitor.cpp | 6 +- src/vsg/traversals/DispatchTraversal.cpp | 10 ++ src/vsg/viewer/GraphicsStage.cpp | 13 ++- src/vsg/viewer/Viewer.cpp | 9 ++ src/vsg/vk/ComputePipeline.cpp | 80 +++++++++++++-- src/vsg/vk/GraphicsPipeline.cpp | 113 +++++++++++++++++++-- src/vsg/vk/Pipeline.cpp | 65 ------------ src/vsg/vk/PipelineLayout.cpp | 14 ++- src/vsg/vk/PushConstants.cpp | 1 - src/vsg/vk/ShaderModule.cpp | 54 +++++----- 22 files changed, 520 insertions(+), 255 deletions(-) delete mode 100644 include/vsg/vk/Pipeline.h delete mode 100644 src/vsg/vk/Pipeline.cpp diff --git a/include/vsg/core/ConstVisitor.h b/include/vsg/core/ConstVisitor.h index 830f19b0b4..518fb390ba 100644 --- a/include/vsg/core/ConstVisitor.h +++ b/include/vsg/core/ConstVisitor.h @@ -32,7 +32,8 @@ namespace vsg class Command; class CommandBuffer; class RenderPass; - class BindPipeline; + class BindComputePipeline; + class BindGraphicsPipeline; class GraphicsPipeline; class ComputePipeline; class Draw; @@ -147,7 +148,8 @@ namespace vsg virtual void apply(const Command&); virtual void apply(const CommandBuffer&); virtual void apply(const RenderPass&); - virtual void apply(const BindPipeline&); + virtual void apply(const BindComputePipeline&); + virtual void apply(const BindGraphicsPipeline&); virtual void apply(const GraphicsPipeline&); virtual void apply(const ComputePipeline&); virtual void apply(const GraphicsPipelineState&); diff --git a/include/vsg/core/Visitor.h b/include/vsg/core/Visitor.h index 90de12d38e..5049819454 100644 --- a/include/vsg/core/Visitor.h +++ b/include/vsg/core/Visitor.h @@ -32,7 +32,8 @@ namespace vsg class Command; class CommandBuffer; class RenderPass; - class BindPipeline; + class BindComputePipeline; + class BindGraphicsPipeline; class GraphicsPipeline; class ComputePipeline; class Draw; @@ -147,7 +148,8 @@ namespace vsg virtual void apply(Command&); virtual void apply(CommandBuffer&); virtual void apply(RenderPass&); - virtual void apply(BindPipeline&); + virtual void apply(BindComputePipeline&); + virtual void apply(BindGraphicsPipeline&); virtual void apply(GraphicsPipeline&); virtual void apply(ComputePipeline&); virtual void apply(GraphicsPipelineState&); diff --git a/include/vsg/traversals/DispatchTraversal.h b/include/vsg/traversals/DispatchTraversal.h index cd1741f75a..c8d7f2fb76 100644 --- a/include/vsg/traversals/DispatchTraversal.h +++ b/include/vsg/traversals/DispatchTraversal.h @@ -14,6 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include namespace vsg { @@ -33,6 +34,9 @@ namespace vsg explicit DispatchTraversal(CommandBuffer* commandBuffer = nullptr); ~DispatchTraversal(); + void setProjectionMatrix(const dmat4& projMatrix); + void setViewMatrix(const dmat4& viewMatrix); + void apply(const Object& object); // scene graph nodes diff --git a/include/vsg/vk/CommandBuffer.h b/include/vsg/vk/CommandBuffer.h index edc362d61d..05b1076f9a 100644 --- a/include/vsg/vk/CommandBuffer.h +++ b/include/vsg/vk/CommandBuffer.h @@ -14,7 +14,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -#include +#include +#include namespace vsg { @@ -36,13 +37,7 @@ namespace vsg Device* getDevice() { return _device; } const Device* getDevice() const { return _device; } - void setCurrentPipeline(const Pipeline* pipeline) - { - _currentPipeline = pipeline; - _currentPipelineLayout = (pipeline != nullptr) ? pipeline->getPipelineLayout() : nullptr; - } - - const Pipeline* getCurrentPipeline() const { return _currentPipeline; } + void setCurrentPipelineLayout(const PipelineLayout* pipelineLayout) { _currentPipelineLayout = pipelineLayout; } const PipelineLayout* getCurrentPipelineLayout() const { return _currentPipelineLayout; } protected: @@ -53,7 +48,6 @@ namespace vsg ref_ptr _device; ref_ptr _commandPool; - ref_ptr _currentPipeline; ref_ptr _currentPipelineLayout; }; diff --git a/include/vsg/vk/ComputePipeline.h b/include/vsg/vk/ComputePipeline.h index 06c1a5d0e0..776393e8a2 100644 --- a/include/vsg/vk/ComputePipeline.h +++ b/include/vsg/vk/ComputePipeline.h @@ -12,27 +12,81 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include #include namespace vsg { - class VSG_DECLSPEC ComputePipeline : public Inherit + class VSG_DECLSPEC ComputePipeline : public Inherit { public: - using Result = vsg::Result; - /** Crreate a ComputePipeline.*/ - static Result create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); + ComputePipeline(PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); + + PipelineLayout* getPipelineLayout() { return _pipelineLayout; } + const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; } + + ShaderModule* getShaderModule() { return _shaderModule; } + const ShaderModule* getShaderModule() const { return _shaderModule; } + + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(VkPipeline pipeline, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); + + using Result = vsg::Result; + + /** Create a ComputePipeline.*/ + static Result create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator = nullptr); + + VkPipeline _pipeline; + ref_ptr _pipelineLayout; + ref_ptr _shaderModule; + ref_ptr _allocator; + }; + + // compile the Vulkan object, context parameter used for Device + void compile(Context& context); + + // remove the local reference to the Vulkan implementation + void release() { _implementation = nullptr; } + + operator VkPipeline() const { return _implementation->_pipeline; } protected: - ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator); virtual ~ComputePipeline(); + ref_ptr _pipelineLayout; ref_ptr _shaderModule; + ref_ptr _allocator; + + ref_ptr _implementation; + }; + + class VSG_DECLSPEC BindComputePipeline : public Inherit + { + public: + BindComputePipeline(ComputePipeline* pipeline); + + void setPipeline(ComputePipeline* pipeline) { _pipeline = pipeline; } + ComputePipeline* getPipeline() { return _pipeline; } + const ComputePipeline* getPipeline() const { return _pipeline; } + + void pushTo(State& state) const override; + void popFrom(State& state) const override; + void dispatch(CommandBuffer& commandBuffer) const override; + + // compile the Vulkan object, context parameter used for Device + void compile(Context& context) override; + + public: + virtual ~BindComputePipeline(); + + ref_ptr _pipeline; }; + VSG_type_name(vsg::BindComputePipeline); } // namespace vsg diff --git a/include/vsg/vk/GraphicsPipeline.h b/include/vsg/vk/GraphicsPipeline.h index c80883a8cf..d68ff5b0bd 100644 --- a/include/vsg/vk/GraphicsPipeline.h +++ b/include/vsg/vk/GraphicsPipeline.h @@ -13,7 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include #include #include #include @@ -30,6 +29,12 @@ namespace vsg virtual void apply(VkGraphicsPipelineCreateInfo& pipelineInfo) const = 0; + // compile the Vulkan object, context parameter used for Device + virtual void compile(Context& /*context*/) {} + + // remove the local reference to the Vulkan implementation + virtual void release() {} + protected: virtual ~GraphicsPipelineState() {} }; @@ -37,30 +42,86 @@ namespace vsg using GraphicsPipelineStates = std::vector>; - class VSG_DECLSPEC GraphicsPipeline : public Inherit + class VSG_DECLSPEC GraphicsPipeline : public Inherit { public: - using Result = vsg::Result; - /** Crreate a GraphicsPipeline.*/ - static Result create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); + GraphicsPipeline(PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); - RenderPass* getRenderPass() { return _renderPass; } - const RenderPass* getRenderPass() const { return _renderPass; } + PipelineLayout* getPipelineLayout() { return _pipelineLayout; } + const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; } GraphicsPipelineStates& getPipelineStates() { return _pipelineStates; } const GraphicsPipelineStates& getPipelineStates() const { return _pipelineStates; } + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); + virtual ~Implementation(); + + using Result = vsg::Result; + + /** Crreate a GraphicsPipeline.*/ + static Result create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator = nullptr); + + VkPipeline _pipeline; + + // TODO need to convert to use Implementation versions of RenderPass and PipelineLayout + ref_ptr _device; + ref_ptr _renderPass; + ref_ptr _pipelineLayout; + GraphicsPipelineStates _pipelineStates; + ref_ptr _allocator; + }; + + // compile the Vulkan object, context parameter used for Device + void compile(Context& context); + + // remove the local reference to the Vulkan implementation + void release() { _implementation = nullptr; } + + operator VkPipeline() const { return _implementation->_pipeline; } + protected: GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); virtual ~GraphicsPipeline(); + ref_ptr _device; ref_ptr _renderPass; + ref_ptr _pipelineLayout; GraphicsPipelineStates _pipelineStates; + ref_ptr _allocator; + + ref_ptr _implementation; }; VSG_type_name(vsg::GraphicsPipeline); + class VSG_DECLSPEC BindGraphicsPipeline : public Inherit + { + public: + BindGraphicsPipeline(GraphicsPipeline* pipeline); + + void setPipeline(GraphicsPipeline* pipeline) { _pipeline = pipeline; } + GraphicsPipeline* getPipeline() { return _pipeline; } + const GraphicsPipeline* getPipeline() const { return _pipeline; } + + void pushTo(State& state) const override; + void popFrom(State& state) const override; + void dispatch(CommandBuffer& commandBuffer) const override; + + // compile the Vulkan object, context parameter used for Device + void compile(Context& context) override; + + public: + virtual ~BindGraphicsPipeline(); + + ref_ptr _pipeline; + }; + VSG_type_name(vsg::BindGraphicsPipeline); + + class VSG_DECLSPEC ShaderStages : public Inherit { public: @@ -71,12 +132,9 @@ namespace vsg void setShaderModules(const ShaderModules& shaderModules) { _shaderModules = shaderModules; - update(); } const ShaderModules& getShaderModules() const { return _shaderModules; } - void update(); - std::size_t size() const { return _stages.size(); } VkPipelineShaderStageCreateInfo* data() { return _stages.data(); } @@ -84,12 +142,19 @@ namespace vsg void apply(VkGraphicsPipelineCreateInfo& pipelineInfo) const override; + // compile the Vulkan object, context parameter used for Device + void compile(Context& context); + + // remove the local reference to the Vulkan implementation + void release(); + protected: virtual ~ShaderStages(); + ShaderModules _shaderModules; + using Stages = std::vector; Stages _stages; - ShaderModules _shaderModules; }; VSG_type_name(vsg::ShaderStages); diff --git a/include/vsg/vk/Pipeline.h b/include/vsg/vk/Pipeline.h deleted file mode 100644 index 36c781457f..0000000000 --- a/include/vsg/vk/Pipeline.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -/* - -Copyright(c) 2018 Robert Osfield - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. - - */ - -#include -#include - -namespace vsg -{ - - class VSG_DECLSPEC Pipeline : public Inherit - { - public: - Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator = nullptr); - - operator VkPipeline() const { return _pipeline; } - - VkPipelineBindPoint getBindPoint() const { return _bindPoint; } - - Device* getDevice() { return _device; } - const Device* getDevice() const { return _device; } - - PipelineLayout* getPipelineLayout() { return _pipelineLayout; } - const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; } - - protected: - virtual ~Pipeline(); - - VkPipeline _pipeline; - VkPipelineBindPoint _bindPoint; - ref_ptr _device; - ref_ptr _pipelineLayout; - ref_ptr _allocator; - }; - VSG_type_name(vsg::Pipeline); - - class VSG_DECLSPEC BindPipeline : public Inherit - { - public: - BindPipeline(Pipeline* pipeline); - - void setPipeline(Pipeline* pipeline) { _pipeline = pipeline; } - Pipeline* getPipeline() { return _pipeline; } - const Pipeline* getPipeline() const { return _pipeline; } - - void pushTo(State& state) const override; - void popFrom(State& state) const override; - void dispatch(CommandBuffer& commandBuffer) const override; - - public: - virtual ~BindPipeline(); - - ref_ptr _pipeline; - }; - VSG_type_name(vsg::BindPipeline); - -} // namespace vsg diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index 89933f88a9..ca95487a8c 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -26,6 +26,16 @@ namespace vsg public: PipelineLayout(const DescriptorSetLayouts& descriptorSetLayouts, const PushConstantRanges& pushConstantRanges, VkPipelineLayoutCreateFlags flags=0); + DescriptorSetLayouts& getDescriptorSetLayouts() { return _descriptorSetLayouts; } + const DescriptorSetLayouts& getDescriptorSetLayouts() const { return _descriptorSetLayouts; } + + PushConstantRanges& getPushConstantRange() { return _pushConstantRanges; } + const PushConstantRanges& getPushConstantRange() const { return _pushConstantRanges; } + + VkPipelineLayoutCreateFlags& getVkPipelineLayoutCreateFlags() { return _flags; } + VkPipelineLayoutCreateFlags getVkPipelineLayoutCreateFlags() const { return _flags; } + + class VSG_DECLSPEC Implementation : public Inherit { public: diff --git a/include/vsg/vk/ShaderModule.h b/include/vsg/vk/ShaderModule.h index ff8e8cc77f..d0e0093f1c 100644 --- a/include/vsg/vk/ShaderModule.h +++ b/include/vsg/vk/ShaderModule.h @@ -17,6 +17,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { + // forward declare + class Context; + template bool readFile(T& buffer, const std::string& filename) { @@ -39,15 +42,15 @@ namespace vsg return true; } - class VSG_DECLSPEC Shader : public Inherit + class VSG_DECLSPEC ShaderModule : public Inherit { public: using Source = std::string; using SPIRV = std::vector; - Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const SPIRV& spirv); - Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source); - Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source, const SPIRV& spirv); + ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const SPIRV& spirv); + ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source); + ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source, const SPIRV& spirv); VkShaderStageFlagBits& stage() { return _stage; } VkShaderStageFlagBits stage() const { return _stage; } @@ -61,46 +64,47 @@ namespace vsg SPIRV& spirv() { return _spirv; } const SPIRV& spirv() const { return _spirv; } - using Result = vsg::Result; + using Result = vsg::Result; static Result read(VkShaderStageFlagBits stage, const std::string& entryPointName, const std::string& filename); void read(Input& input) override; void write(Output& output) const override; - protected: - virtual ~Shader(); + class VSG_DECLSPEC Implementation : public Inherit + { + public: + Implementation(VkShaderModule shaderModule, Device* device, AllocationCallbacks* allocator); + virtual ~Implementation(); - VkShaderStageFlagBits _stage; - std::string _entryPointName; - std::string _source; - SPIRV _spirv; - }; - VSG_type_name(vsg::Shader); + using Result = vsg::Result; - class VSG_DECLSPEC ShaderModule : public Inherit - { - public: - ShaderModule(VkShaderModule shaderModule, Device* device, Shader* shader, AllocationCallbacks* allocator = nullptr); + /** Create a ComputePipeline.*/ + static Result create(Device* device, ShaderModule* shader, AllocationCallbacks* allocator = nullptr); - using Result = vsg::Result; + operator VkShaderModule() const { return _shaderModule; } - static Result create(Device* device, Shader* shader, AllocationCallbacks* allocator = nullptr); + VkShaderModule _shaderModule; + ref_ptr _device; + ref_ptr _allocator; + }; - operator VkShaderModule() const { return _shaderModule; } + // compile the Vulkan object, context parameter used for Device + void compile(Context& context); - const Shader* getShader() const { return _shader; } + // remove the local reference to the Vulkan implementation + void release() { _implementation = nullptr; } - Device* getDevice() { return _device; } - const Device* getDevice() const { return _device; } + operator VkShaderModule() const { return _implementation->_shaderModule; } protected: virtual ~ShaderModule(); - VkShaderModule _shaderModule; + VkShaderStageFlagBits _stage; + std::string _entryPointName; + std::string _source; + SPIRV _spirv; - ref_ptr _device; - ref_ptr _shader; - ref_ptr _allocator; + ref_ptr _implementation; }; VSG_type_name(vsg::ShaderModule); diff --git a/include/vsg/vk/State.h b/include/vsg/vk/State.h index f0276f0b14..ccc2baafc2 100644 --- a/include/vsg/vk/State.h +++ b/include/vsg/vk/State.h @@ -16,7 +16,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include +#include +#include #include #include @@ -59,41 +60,113 @@ namespace vsg } }; + class MatrixStack + { + public: + MatrixStack(uint32_t in_offset=0) : + offset(in_offset) + { + // make sure there is an initial matrix + matrixStack.push(mat4()); + } + + using mat4Stack = std::stack; + using dmat4Stack = std::stack; + + mat4Stack matrixStack; + VkShaderStageFlags stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + uint32_t offset = 0; + bool dirty = false; + + inline void set(const mat4& matrix) + { + matrixStack = mat4Stack(); + matrixStack.push(matrix); + dirty = true; + } + + inline void set(const dmat4& matrix) + { + matrixStack = mat4Stack(); + matrixStack.push(matrix); + dirty = true; + } + + inline void push(const mat4& matrix) + { + matrixStack.push(matrix); + dirty = true; + } + + const mat4& top() const { return matrixStack.top(); } + + inline void pop() + { + matrixStack.pop(); + dirty = true; + } + + inline void dispatch(CommandBuffer& commandBuffer) + { + if (dirty) + { + const PipelineLayout::Implementation* pipelineLayout = commandBuffer.getCurrentPipelineLayout()->implementation(); + vkCmdPushConstants(commandBuffer, *pipelineLayout, stageFlags, offset, sizeof(vsg::mat4), matrixStack.top().data()); + dirty = false; + } + } + }; + class State : public Inherit { public: State() : dirty(false) {} - using PipelineStack = StateStack; + using ComputePipelineStack = StateStack; + using GraphicsPipelineStack = StateStack; using DescriptorStacks = std::vector>; using VertexBuffersStack = StateStack; using IndexBufferStack = StateStack; using PushConstantsMap = std::map>; bool dirty; - PipelineStack pipelineStack; + ComputePipelineStack computePipelineStack; + GraphicsPipelineStack graphicsPipelineStack; + DescriptorStacks descriptorStacks; + + MatrixStack projectionMatrixStack{0}; + MatrixStack viewMatrixStack{64}; + MatrixStack modelMatrixStack{128}; + + PushConstantsMap pushConstantsMap; + VertexBuffersStack vertexBuffersStack; IndexBufferStack indexBufferStack; - PushConstantsMap pushConstantsMap; inline void dispatch(CommandBuffer& commandBuffer) { if (dirty) { - pipelineStack.dispatch(commandBuffer); + computePipelineStack.dispatch(commandBuffer); + graphicsPipelineStack.dispatch(commandBuffer); for(auto& descriptorStack : descriptorStacks) { descriptorStack.dispatch(commandBuffer); } - vertexBuffersStack.dispatch(commandBuffer); - indexBufferStack.dispatch(commandBuffer); + projectionMatrixStack.dispatch(commandBuffer); + viewMatrixStack.dispatch(commandBuffer); + modelMatrixStack.dispatch(commandBuffer); + for (auto& pushConstantsStack : pushConstantsMap) { pushConstantsStack.second.dispatch(commandBuffer); } + + vertexBuffersStack.dispatch(commandBuffer); + indexBufferStack.dispatch(commandBuffer); dirty = false; } } diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 454ccf151d..addc72178c 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -72,7 +72,6 @@ set(SOURCES vk/Instance.cpp vk/MemoryManager.cpp vk/PhysicalDevice.cpp - vk/Pipeline.cpp vk/PipelineLayout.cpp vk/PushConstants.cpp vk/RenderPass.cpp diff --git a/src/vsg/core/ConstVisitor.cpp b/src/vsg/core/ConstVisitor.cpp index d476ec1cfc..fe7e2faa1e 100644 --- a/src/vsg/core/ConstVisitor.cpp +++ b/src/vsg/core/ConstVisitor.cpp @@ -305,7 +305,11 @@ void ConstVisitor::apply(const RenderPass& value) { apply(static_cast(value)); } -void ConstVisitor::apply(const BindPipeline& value) +void ConstVisitor::apply(const BindComputePipeline& value) +{ + apply(static_cast(value)); +} +void ConstVisitor::apply(const BindGraphicsPipeline& value) { apply(static_cast(value)); } diff --git a/src/vsg/core/Visitor.cpp b/src/vsg/core/Visitor.cpp index 1eb605202f..9d8be938e1 100644 --- a/src/vsg/core/Visitor.cpp +++ b/src/vsg/core/Visitor.cpp @@ -305,7 +305,11 @@ void Visitor::apply(RenderPass& value) { apply(static_cast(value)); } -void Visitor::apply(BindPipeline& value) +void Visitor::apply(BindComputePipeline& value) +{ + apply(static_cast(value)); +} +void Visitor::apply(BindGraphicsPipeline& value) { apply(static_cast(value)); } diff --git a/src/vsg/traversals/DispatchTraversal.cpp b/src/vsg/traversals/DispatchTraversal.cpp index 06a882fce2..659154e677 100644 --- a/src/vsg/traversals/DispatchTraversal.cpp +++ b/src/vsg/traversals/DispatchTraversal.cpp @@ -56,6 +56,16 @@ DispatchTraversal::~DispatchTraversal() delete _data; } +void DispatchTraversal::setProjectionMatrix(const dmat4& projMatrix) +{ + _data->_state.projectionMatrixStack.set(projMatrix); +} + +void DispatchTraversal::setViewMatrix(const dmat4& viewMatrix) +{ + _data->_state.viewMatrixStack.set(viewMatrix); +} + void DispatchTraversal::apply(const Object& object) { // std::cout<<"Visiting object"<(bindPipeline.getPipeline()); + GraphicsPipeline* graphicsPipeline = bindPipeline.getPipeline(); if (graphicsPipeline) { bool needToRegenerateGraphicsPipeline = false; @@ -44,11 +44,8 @@ namespace vsg } if (needToRegenerateGraphicsPipeline) { - - vsg::ref_ptr new_pipeline = vsg::GraphicsPipeline::create(graphicsPipeline->getRenderPass()->getDevice(), - graphicsPipeline->getRenderPass(), - graphicsPipeline->getPipelineLayout(), - graphicsPipeline->getPipelineStates()); + // TODO need to invoke a new compile traversal + vsg::ref_ptr new_pipeline = vsg::GraphicsPipeline::create(graphicsPipeline->getPipelineLayout(), graphicsPipeline->getPipelineStates()); bindPipeline.setPipeline(new_pipeline); } @@ -137,6 +134,8 @@ void GraphicsStage::populateCommandBuffer(CommandBuffer* commandBuffer, Framebuf // set up the dispatching of the commands into the command buffer DispatchTraversal dispatchTraversal(commandBuffer); + dispatchTraversal.setProjectionMatrix(_projMatrix->value()); + dispatchTraversal.setViewMatrix(_viewMatrix->value()); VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; diff --git a/src/vsg/viewer/Viewer.cpp b/src/vsg/viewer/Viewer.cpp index f98e825cef..5f4e8bc05c 100644 --- a/src/vsg/viewer/Viewer.cpp +++ b/src/vsg/viewer/Viewer.cpp @@ -285,9 +285,18 @@ void Viewer::compile() vsg::ref_ptr physicalDevice(window->physicalDevice()); vsg::ref_ptr device(window->device()); + // TODO need to traverse the stages to figure out the maxSets and descriptorPoolSizes, hardwire for now + uint32_t maxSets = 1090; + uint32_t maxDescriptors = 1000; + DescriptorPoolSizes descriptorPoolSizes + { + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, maxDescriptors} // type, descriptorCount // total descriptors of a type across all sets + }; + vsg::CompileTraversal compile; compile.context.device = window->device(); compile.context.commandPool = vsg::CommandPool::create(device, physicalDevice->getGraphicsFamily()); + compile.context.descriptorPool = vsg::DescriptorPool::create(device, maxSets, descriptorPoolSizes); compile.context.renderPass = window->renderPass(); compile.context.graphicsQueue = device->getQueue(physicalDevice->getGraphicsFamily()); diff --git a/src/vsg/vk/ComputePipeline.cpp b/src/vsg/vk/ComputePipeline.cpp index 4fd164830d..a7beee25aa 100644 --- a/src/vsg/vk/ComputePipeline.cpp +++ b/src/vsg/vk/ComputePipeline.cpp @@ -11,12 +11,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include +#include using namespace vsg; -ComputePipeline::ComputePipeline(VkPipeline pipeline, Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : - Inherit(pipeline, VK_PIPELINE_BIND_POINT_COMPUTE, device, pipelineLayout, allocator), - _shaderModule(shaderModule) +//////////////////////////////////////////////////////////////////////// +// +// ComputePipeline +// +ComputePipeline::ComputePipeline(PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : + _pipelineLayout(pipelineLayout), + _shaderModule(shaderModule), + _allocator(allocator) { } @@ -24,7 +31,29 @@ ComputePipeline::~ComputePipeline() { } -ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) +void ComputePipeline::compile(Context& context) +{ + if (!_implementation) + { + _pipelineLayout->compile(context); + _shaderModule->compile(context); + _implementation = ComputePipeline::Implementation::create(context.device, _pipelineLayout, _shaderModule, _allocator); + } +} + +//////////////////////////////////////////////////////////////////////// +// +// ComputePipeline::Implementation +// +ComputePipeline::Implementation::Implementation(VkPipeline pipeline, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) : + _pipeline(pipeline), + _pipelineLayout(pipelineLayout), + _shaderModule(shaderModule), + _allocator(allocator) +{ +} + +ComputePipeline::Implementation::Result ComputePipeline::Implementation::create(Device* device, PipelineLayout* pipelineLayout, ShaderModule* shaderModule, AllocationCallbacks* allocator) { if (!device || !pipelineLayout || !shaderModule) { @@ -35,7 +64,7 @@ ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout* stageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stageInfo.stage = VK_SHADER_STAGE_COMPUTE_BIT; stageInfo.module = *shaderModule; - stageInfo.pName = shaderModule->getShader()->entryPointName().c_str(); + stageInfo.pName = shaderModule->entryPointName().c_str(); VkComputePipelineCreateInfo pipelineInfo = {}; pipelineInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; @@ -47,10 +76,47 @@ ComputePipeline::Result ComputePipeline::create(Device* device, PipelineLayout* VkResult result = vkCreateComputePipelines(*device, VK_NULL_HANDLE, 1, &pipelineInfo, allocator, &pipeline); if (result == VK_SUCCESS) { - return Result(new ComputePipeline(pipeline, device, pipelineLayout, shaderModule, allocator)); + return Result(new ComputePipeline::Implementation(pipeline, pipelineLayout, shaderModule, allocator)); } else { - return ComputePipeline::Result("Error: vsg::Pipeline::createCompute(...) failed to create VkPipeline.", result); + return Result("Error: vsg::Pipeline::createCompute(...) failed to create VkPipeline.", result); } } + +//////////////////////////////////////////////////////////////////////// +// +// BindComputePipeline +// +BindComputePipeline::BindComputePipeline(ComputePipeline* pipeline) : + _pipeline(pipeline) +{ +} + +BindComputePipeline::~BindComputePipeline() +{ +} + +void BindComputePipeline::pushTo(State& state) const +{ + state.dirty = true; + state.computePipelineStack.push(this); +} + +void BindComputePipeline::popFrom(State& state) const +{ + state.dirty = true; + state.computePipelineStack.pop(); +} + +void BindComputePipeline::dispatch(CommandBuffer& commandBuffer) const +{ + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *_pipeline); + commandBuffer.setCurrentPipelineLayout(_pipeline->getPipelineLayout()); +} + +void BindComputePipeline::compile(Context& context) +{ + if (_pipeline) _pipeline->compile(context); +} + diff --git a/src/vsg/vk/GraphicsPipeline.cpp b/src/vsg/vk/GraphicsPipeline.cpp index c3f2dfd663..54ffebbd33 100644 --- a/src/vsg/vk/GraphicsPipeline.cpp +++ b/src/vsg/vk/GraphicsPipeline.cpp @@ -11,13 +11,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include using namespace vsg; -GraphicsPipeline::GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : - Inherit(pipeline, VK_PIPELINE_BIND_POINT_GRAPHICS, device, pipelineLayout, allocator), - _renderPass(renderPass), - _pipelineStates(pipelineStates) + +//////////////////////////////////////////////////////////////////////// +// +// GraphicsPipeline +// +GraphicsPipeline::GraphicsPipeline(PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator): + _pipelineLayout(pipelineLayout), + _pipelineStates(pipelineStates), + _allocator(allocator) { } @@ -25,11 +31,43 @@ GraphicsPipeline::~GraphicsPipeline() { } -GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) +void GraphicsPipeline::compile(Context& context) +{ + if (!_implementation) + { + _pipelineLayout->compile(context); + + for(auto& pipelineState : _pipelineStates) + { + pipelineState->compile(context); + } + + GraphicsPipelineStates full_pipelineStates = _pipelineStates; + full_pipelineStates.emplace_back(context.viewport); + + _implementation = GraphicsPipeline::Implementation::create(context.device, context.renderPass, _pipelineLayout, full_pipelineStates, _allocator); + } +} + +//////////////////////////////////////////////////////////////////////// +// +// GraphicsPipeline::Implementation +// +GraphicsPipeline::Implementation::Implementation(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) : + _pipeline(pipeline), + _device(device), + _renderPass(renderPass), + _pipelineLayout(pipelineLayout), + _pipelineStates(pipelineStates), + _allocator(allocator) +{ +} + +GraphicsPipeline::Implementation::Result GraphicsPipeline::Implementation::create(Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator) { if (!device || !renderPass || !pipelineLayout) { - return GraphicsPipeline::Result("Error: vsg::GraphicsPipeline::create(...) failed to create graphics pipeline, inputs not defined.", VK_ERROR_INVALID_EXTERNAL_HANDLE); + return Result("Error: vsg::GraphicsPipeline::create(...) failed to create graphics pipeline, inputs not defined.", VK_ERROR_INVALID_EXTERNAL_HANDLE); } VkGraphicsPipelineCreateInfo pipelineInfo = {}; @@ -48,14 +86,55 @@ GraphicsPipeline::Result GraphicsPipeline::create(Device* device, RenderPass* re VkResult result = vkCreateGraphicsPipelines(*device, VK_NULL_HANDLE, 1, &pipelineInfo, allocator, &pipeline); if (result == VK_SUCCESS) { - return Result(new GraphicsPipeline(pipeline, device, renderPass, pipelineLayout, pipelineStates, allocator)); + return Result(new Implementation(pipeline, device, renderPass, pipelineLayout, pipelineStates, allocator)); } else { - return GraphicsPipeline::Result("Error: vsg::Pipeline::createGraphics(...) failed to create VkPipeline.", result); + return Result("Error: vsg::Pipeline::createGraphics(...) failed to create VkPipeline.", result); } } +GraphicsPipeline::Implementation::~Implementation() +{ + vkDestroyPipeline(*_device, _pipeline, _allocator); +} + +//////////////////////////////////////////////////////////////////////// +// +// BindGraphicsPipeline +// +BindGraphicsPipeline::BindGraphicsPipeline(GraphicsPipeline* pipeline) : + _pipeline(pipeline) +{ +} + +BindGraphicsPipeline::~BindGraphicsPipeline() +{ +} + +void BindGraphicsPipeline::pushTo(State& state) const +{ + state.dirty = true; + state.graphicsPipelineStack.push(this); +} + +void BindGraphicsPipeline::popFrom(State& state) const +{ + state.dirty = true; + state.graphicsPipelineStack.pop(); +} + +void BindGraphicsPipeline::dispatch(CommandBuffer& commandBuffer) const +{ + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *_pipeline); + commandBuffer.setCurrentPipelineLayout(_pipeline->getPipelineLayout()); +} + +void BindGraphicsPipeline::compile(Context& context) +{ + if (_pipeline) _pipeline->compile(context); +} + //////////////////////////////////////////////////////////////////////// // // ShaderStages @@ -75,20 +154,32 @@ void ShaderStages::apply(VkGraphicsPipelineCreateInfo& pipelineInfo) const pipelineInfo.pStages = data(); } -void ShaderStages::update() +void ShaderStages::compile(Context& context) { _stages.resize(_shaderModules.size()); for (size_t i = 0; i < _shaderModules.size(); ++i) { VkPipelineShaderStageCreateInfo& stageInfo = (_stages)[i]; ShaderModule* sm = _shaderModules[i]; + sm->compile(context); stageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stageInfo.stage = sm->getShader()->stage(); + stageInfo.stage = sm->stage(); stageInfo.module = *sm; - stageInfo.pName = sm->getShader()->entryPointName().c_str(); + stageInfo.pName = sm->entryPointName().c_str(); + } +} + +void ShaderStages::release() +{ + for(auto& shaderModules : _shaderModules) + { + shaderModules->release(); } + + _stages.clear(); } + //////////////////////////////////////////////////////////////////////// // // VertexInputState diff --git a/src/vsg/vk/Pipeline.cpp b/src/vsg/vk/Pipeline.cpp deleted file mode 100644 index 03bb6e93e5..0000000000 --- a/src/vsg/vk/Pipeline.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - -Copyright(c) 2018 Robert Osfield - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. - - */ - -#include -#include -#include - -using namespace vsg; - -//////////////////////////////////////////////////////////////////////// -// -// Pipeline -// -Pipeline::Pipeline(VkPipeline pipeline, VkPipelineBindPoint bindPoint, Device* device, PipelineLayout* pipelineLayout, AllocationCallbacks* allocator) : - _pipeline(pipeline), - _bindPoint(bindPoint), - _device(device), - _pipelineLayout(pipelineLayout), - _allocator(allocator) -{ -} - -Pipeline::~Pipeline() -{ - if (_pipeline) - { - vkDestroyPipeline(*_device, _pipeline, _allocator); - } -} - -BindPipeline::BindPipeline(Pipeline* pipeline) : - _pipeline(pipeline) -{ -} - -BindPipeline::~BindPipeline() -{ -} - -void BindPipeline::pushTo(State& state) const -{ - state.dirty = true; - state.pipelineStack.push(this); -} - -void BindPipeline::popFrom(State& state) const -{ - state.dirty = true; - state.pipelineStack.pop(); -} - -void BindPipeline::dispatch(CommandBuffer& commandBuffer) const -{ - vkCmdBindPipeline(commandBuffer, _pipeline->getBindPoint(), *_pipeline); - commandBuffer.setCurrentPipeline(_pipeline); -} diff --git a/src/vsg/vk/PipelineLayout.cpp b/src/vsg/vk/PipelineLayout.cpp index c7ad101ce9..6c575dacba 100644 --- a/src/vsg/vk/PipelineLayout.cpp +++ b/src/vsg/vk/PipelineLayout.cpp @@ -32,7 +32,14 @@ PipelineLayout::~PipelineLayout() void PipelineLayout::compile(Context& context) { - if (!_implementation) _implementation = PipelineLayout::Implementation::create(context.device, _descriptorSetLayouts, _pushConstantRanges, _flags); + if (!_implementation) + { + for (auto dsl : _descriptorSetLayouts) + { + dsl->compile(context); + } + _implementation = PipelineLayout::Implementation::create(context.device, _descriptorSetLayouts, _pushConstantRanges, _flags); + } } ////////////////////////////////////// @@ -63,7 +70,10 @@ PipelineLayout::Implementation::Result PipelineLayout::Implementation::create(De } std::vector layouts; - for (auto dsl : descriptorSetLayouts) layouts.push_back(*dsl); + for (auto& dsl : descriptorSetLayouts) + { + layouts.push_back(*dsl); + } VkPipelineLayoutCreateInfo pipelineLayoutInfo; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; diff --git a/src/vsg/vk/PushConstants.cpp b/src/vsg/vk/PushConstants.cpp index e0fcbe1e51..77a56152ec 100644 --- a/src/vsg/vk/PushConstants.cpp +++ b/src/vsg/vk/PushConstants.cpp @@ -41,7 +41,6 @@ void PushConstants::dispatch(CommandBuffer& commandBuffer) const const PipelineLayout::Implementation* pipelineLayout = commandBuffer.getCurrentPipelineLayout()->implementation(); if (pipelineLayout) { - vkCmdPushConstants(commandBuffer, *pipelineLayout, _stageFlags, _offset, static_cast(_data->dataSize()), _data->dataPointer()); } } diff --git a/src/vsg/vk/ShaderModule.cpp b/src/vsg/vk/ShaderModule.cpp index a1664bebf2..96e6fe81a3 100644 --- a/src/vsg/vk/ShaderModule.cpp +++ b/src/vsg/vk/ShaderModule.cpp @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include using namespace vsg; @@ -19,21 +20,21 @@ using namespace vsg; // Shader // -Shader::Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const SPIRV& spirv) : +ShaderModule::ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const SPIRV& spirv) : _stage(stage), _entryPointName(entryPointName), _spirv(spirv) { } -Shader::Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source) : +ShaderModule::ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source) : _stage(stage), _entryPointName(entryPointName), _source(source) { } -Shader::Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source, const SPIRV& spirv) : +ShaderModule::ShaderModule(VkShaderStageFlagBits stage, const std::string& entryPointName, const Source& source, const SPIRV& spirv) : _stage(stage), _entryPointName(entryPointName), _source(source), @@ -41,24 +42,24 @@ Shader::Shader(VkShaderStageFlagBits stage, const std::string& entryPointName, c { } -Shader::~Shader() +ShaderModule::~ShaderModule() { } -Shader::Result Shader::read(VkShaderStageFlagBits stage, const std::string& entryPointName, const std::string& filename) +ShaderModule::Result ShaderModule::read(VkShaderStageFlagBits stage, const std::string& entryPointName, const std::string& filename) { SPIRV buffer; if (readFile(buffer, filename)) { - return Result(new Shader(stage, entryPointName, buffer)); + return Result(new ShaderModule(stage, entryPointName, buffer)); } else { - return Shader::Result("Error: vsg::Shader::read(..) failed to read shader file.", VK_INCOMPLETE); + return ShaderModule::Result("Error: vsg::ShaderModule::read(..) failed to read shader file.", VK_INCOMPLETE); } } -void Shader::read(Input& input) +void ShaderModule::read(Input& input) { Object::read(input); @@ -72,7 +73,7 @@ void Shader::read(Input& input) input.read(_spirv.size(), _spirv.data()); } -void Shader::write(Output& output) const +void ShaderModule::write(Output& output) const { Object::write(output); @@ -86,48 +87,45 @@ void Shader::write(Output& output) const output.write(_spirv.size(), _spirv.data()); } -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// ShaderModule -// -ShaderModule::ShaderModule(VkShaderModule shaderModule, Device* device, Shader* shader, AllocationCallbacks* allocator) : +void ShaderModule::compile(Context& context) +{ + if (!_implementation) _implementation = Implementation::create(context.device, this); +} + +ShaderModule::Implementation::Implementation(VkShaderModule shaderModule, Device* device, AllocationCallbacks* allocator): _shaderModule(shaderModule), _device(device), - _shader(shader), _allocator(allocator) { } -ShaderModule::~ShaderModule() +ShaderModule::Implementation::~Implementation() { - if (_shaderModule) - { - vkDestroyShaderModule(*_device, _shaderModule, _allocator); - } + vkDestroyShaderModule(*_device, _shaderModule, _allocator); } -ShaderModule::Result ShaderModule::create(Device* device, Shader* shader, AllocationCallbacks* allocator) +ShaderModule::Implementation::Result ShaderModule::Implementation::create(Device* device, ShaderModule* shaderModule, AllocationCallbacks* allocator) { - if (!device || !shader) + if (!device || !shaderModule) { return Result("Error: vsg::ShaderModule::create(...) failed, requires valid logical device and Shader.", VK_ERROR_INVALID_EXTERNAL_HANDLE); } - if (shader->spirv().empty()) + if (shaderModule->spirv().empty()) { return Result("Error: vsg::ShaderModule::create(...) failed. requires Shader with valid spirv contents.", VK_ERROR_INVALID_EXTERNAL_HANDLE); } VkShaderModuleCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - createInfo.codeSize = shader->spirv().size() * sizeof(Shader::SPIRV::value_type); - createInfo.pCode = shader->spirv().data(); + createInfo.codeSize = shaderModule->spirv().size() * sizeof(ShaderModule::SPIRV::value_type); + createInfo.pCode = shaderModule->spirv().data(); - VkShaderModule shaderModule; - VkResult result = vkCreateShaderModule(*device, &createInfo, allocator, &shaderModule); + VkShaderModule sm; + VkResult result = vkCreateShaderModule(*device, &createInfo, allocator, &sm); if (result == VK_SUCCESS) { - return Result(new ShaderModule(shaderModule, device, shader, allocator)); + return Result(new ShaderModule::Implementation(sm, device, allocator)); } else { From a803c9a10f9d4981532d900bf0d0743d39827a41 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 Mar 2019 17:52:16 +0000 Subject: [PATCH 08/21] Added beginnings of read/write support to GraphicsPipeline classes --- include/vsg/vk/GraphicsPipeline.h | 8 +++++-- src/vsg/vk/GraphicsPipeline.cpp | 36 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/vsg/vk/GraphicsPipeline.h b/include/vsg/vk/GraphicsPipeline.h index d68ff5b0bd..f6a999022e 100644 --- a/include/vsg/vk/GraphicsPipeline.h +++ b/include/vsg/vk/GraphicsPipeline.h @@ -83,9 +83,10 @@ namespace vsg operator VkPipeline() const { return _implementation->_pipeline; } - protected: - GraphicsPipeline(VkPipeline pipeline, Device* device, RenderPass* renderPass, PipelineLayout* pipelineLayout, const GraphicsPipelineStates& pipelineStates, AllocationCallbacks* allocator); + void read(Input& input) override; + void write(Output& output) const override; + protected: virtual ~GraphicsPipeline(); ref_ptr _device; @@ -114,6 +115,9 @@ namespace vsg // compile the Vulkan object, context parameter used for Device void compile(Context& context) override; + void read(Input& input) override; + void write(Output& output) const override; + public: virtual ~BindGraphicsPipeline(); diff --git a/src/vsg/vk/GraphicsPipeline.cpp b/src/vsg/vk/GraphicsPipeline.cpp index 54ffebbd33..38a751cbe7 100644 --- a/src/vsg/vk/GraphicsPipeline.cpp +++ b/src/vsg/vk/GraphicsPipeline.cpp @@ -49,6 +49,28 @@ void GraphicsPipeline::compile(Context& context) } } +void GraphicsPipeline::read(Input& input) +{ + Object::read(input); + + _pipelineStates.resize(input.readValue("NumPipelineStates")); + for (auto& pipelineState : _pipelineStates) + { + pipelineState = input.readObject("PipelineState"); + } +} + +void GraphicsPipeline::write(Output& output) const +{ + Object::write(output); + + output.writeValue("NumPipelineStates", _pipelineStates.size()); + for (auto& pipelineState : _pipelineStates) + { + output.writeObject("PipelineState", pipelineState.get()); + } +} + //////////////////////////////////////////////////////////////////////// // // GraphicsPipeline::Implementation @@ -135,6 +157,20 @@ void BindGraphicsPipeline::compile(Context& context) if (_pipeline) _pipeline->compile(context); } +void BindGraphicsPipeline::read(Input& input) +{ + StateCommand::read(input); + + _pipeline = input.readObject("GraphicsPipeline"); +} + +void BindGraphicsPipeline::write(Output& output) const +{ + StateCommand::write(output); + + output.writeObject("GraphicsPipeline", _pipeline.get()); +} + //////////////////////////////////////////////////////////////////////// // // ShaderStages From 6c72c1c8074d7f539db7d922d51743c1d596254c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 Mar 2019 18:18:27 +0000 Subject: [PATCH 09/21] Added serializer support for ShaderStages --- include/vsg/vk/GraphicsPipeline.h | 3 +++ src/vsg/vk/GraphicsPipeline.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/vsg/vk/GraphicsPipeline.h b/include/vsg/vk/GraphicsPipeline.h index f6a999022e..50be1c9916 100644 --- a/include/vsg/vk/GraphicsPipeline.h +++ b/include/vsg/vk/GraphicsPipeline.h @@ -152,6 +152,9 @@ namespace vsg // remove the local reference to the Vulkan implementation void release(); + void read(Input& input) override; + void write(Output& output) const override; + protected: virtual ~ShaderStages(); diff --git a/src/vsg/vk/GraphicsPipeline.cpp b/src/vsg/vk/GraphicsPipeline.cpp index 38a751cbe7..4eadf6548f 100644 --- a/src/vsg/vk/GraphicsPipeline.cpp +++ b/src/vsg/vk/GraphicsPipeline.cpp @@ -215,6 +215,28 @@ void ShaderStages::release() _stages.clear(); } +void ShaderStages::read(Input& input) +{ + Object::read(input); + + _shaderModules.resize(input.readValue("NumShaderModule")); + for (auto& shaderModule : _shaderModules) + { + shaderModule = input.readObject("ShaderModule"); + } +} + +void ShaderStages::write(Output& output) const +{ + Object::write(output); + + output.writeValue("NumShaderModule", _shaderModules.size()); + for (auto& shaderModule : _shaderModules) + { + output.writeObject("ShaderModule", shaderModule.get()); + } +} + //////////////////////////////////////////////////////////////////////// // From ef3e2097187c4c6862328399b5ba642302a95b67 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 11:20:12 +0000 Subject: [PATCH 10/21] Added vsg::Texture descriptor from osg2vsg project --- include/vsg/vk/Descriptor.h | 17 +++++++++++++ src/vsg/vk/Descriptor.cpp | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/vsg/vk/Descriptor.h b/include/vsg/vk/Descriptor.h index 01dc2af2d8..fc9fba24e7 100644 --- a/include/vsg/vk/Descriptor.h +++ b/include/vsg/vk/Descriptor.h @@ -184,4 +184,21 @@ namespace vsg std::vector _texelBufferViews; }; + class Texture : public Inherit + { + public: + Texture(); + + void compile(Context& context) override; + + void assignTo(VkWriteDescriptorSet& wds, VkDescriptorSet descriptorSet) const override; + + // settings + VkSamplerCreateInfo _samplerInfo; + ref_ptr _textureData; + + ref_ptr _implementation; + }; + VSG_type_name(vsg::Texture) + } // namespace vsg diff --git a/src/vsg/vk/Descriptor.cpp b/src/vsg/vk/Descriptor.cpp index edd12276d4..fb8782e595 100644 --- a/src/vsg/vk/Descriptor.cpp +++ b/src/vsg/vk/Descriptor.cpp @@ -12,11 +12,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include #include using namespace vsg; +///////////////////////////////////////////////////////////////////////////////////////// +// +// vsg::transferImageData +// ImageData vsg::transferImageData(Device* device, CommandPool* commandPool, VkQueue queue, const Data* data, Sampler* sampler) { if (!data) @@ -116,3 +121,48 @@ ImageData vsg::transferImageData(Device* device, CommandPool* commandPool, VkQue return ImageData(textureSampler, textureImageView, VK_IMAGE_LAYOUT_UNDEFINED); } + +///////////////////////////////////////////////////////////////////////////////////////// +// +// Texture +// +Texture::Texture() : + Inherit(0, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) +{ + // set default sampler info + _samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + _samplerInfo.minFilter = VK_FILTER_LINEAR; + _samplerInfo.magFilter = VK_FILTER_LINEAR; + _samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + _samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + _samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; +#if 1 + // requres Logical device to have deviceFeatures.samplerAnisotropy = VK_TRUE; set when creating the vsg::Device + _samplerInfo.anisotropyEnable = VK_TRUE; + _samplerInfo.maxAnisotropy = 16; +#else + _samplerInfo.anisotropyEnable = VK_FALSE; + _samplerInfo.maxAnisotropy = 1; +#endif + _samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + _samplerInfo.unnormalizedCoordinates = VK_FALSE; + _samplerInfo.compareEnable = VK_FALSE; + _samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; +} + +void Texture::compile(Context& context) +{ + ref_ptr sampler = Sampler::create(context.device, _samplerInfo, nullptr); + vsg::ImageData imageData = vsg::transferImageData(context.device, context.commandPool, context.graphicsQueue, _textureData, sampler); + if (!imageData.valid()) + { + return; + } + + _implementation = vsg::DescriptorImage::create(_dstBinding, _dstArrayElement, _descriptorType, vsg::ImageDataList{imageData}); +} + +void Texture::assignTo(VkWriteDescriptorSet& wds, VkDescriptorSet descriptorSet) const +{ + if (_implementation) _implementation->assignTo(wds, descriptorSet); +} From ad19af9df9763de270c06a697b79595f8f7b0ef4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 11:45:48 +0000 Subject: [PATCH 11/21] Added MatrixTransform node --- include/vsg/nodes/MatrixTransform.h | 47 +++++++++++++++++++++++++++++ src/vsg/CMakeLists.txt | 1 + src/vsg/nodes/MatrixTransform.cpp | 35 +++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 include/vsg/nodes/MatrixTransform.h create mode 100644 src/vsg/nodes/MatrixTransform.cpp diff --git a/include/vsg/nodes/MatrixTransform.h b/include/vsg/nodes/MatrixTransform.h new file mode 100644 index 0000000000..b86bd74bde --- /dev/null +++ b/include/vsg/nodes/MatrixTransform.h @@ -0,0 +1,47 @@ +#pragma once + +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include +#include + +namespace vsg +{ + + class MatrixTransform : public Inherit + { + public: + MatrixTransform(Allocator* allocator = nullptr); + MatrixTransform(const mat4& matrix, Allocator* allocator = nullptr); + + void setMatrix(const mat4& matrix) { (*_matrix) = matrix; } + mat4& getMatrix() { return _matrix->value(); } + const mat4& getMatrix() const { return _matrix->value(); } + + inline void pushTo(State& state) const + { + _pushConstant->pushTo(state); + } + + inline void popFrom(State& state) const + { + _pushConstant->popFrom(state); + } + + protected: + ref_ptr _matrix; + ref_ptr _pushConstant; + }; + VSG_type_name(vsg::MatrixTransform); + +} diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index addc72178c..73fd3dd52e 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -26,6 +26,7 @@ set(SOURCES nodes/Node.cpp nodes/QuadGroup.cpp nodes/StateGroup.cpp + nodes/MatrixTransform.cpp io/FileSystem.cpp diff --git a/src/vsg/nodes/MatrixTransform.cpp b/src/vsg/nodes/MatrixTransform.cpp new file mode 100644 index 0000000000..5aaa091504 --- /dev/null +++ b/src/vsg/nodes/MatrixTransform.cpp @@ -0,0 +1,35 @@ +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include +#include + +#include + +using namespace vsg; + +MatrixTransform::MatrixTransform(Allocator* allocator): + Inherit(allocator) +{ + _matrix = new mat4Value; + _pushConstant = vsg::PushConstants::create(VK_SHADER_STAGE_VERTEX_BIT, 128, _matrix); +} + +MatrixTransform::MatrixTransform(const mat4& matrix, Allocator* allocator): + Inherit(allocator) +{ + _matrix = new mat4Value(matrix); + _pushConstant = vsg::PushConstants::create(VK_SHADER_STAGE_VERTEX_BIT, 128, _matrix); +} + + + From 7a2289323f989c3669fb903257b7fecb19e237e1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 11:46:13 +0000 Subject: [PATCH 12/21] Improved PushConstants support for pushing/popping state --- src/vsg/vk/PushConstants.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vsg/vk/PushConstants.cpp b/src/vsg/vk/PushConstants.cpp index 77a56152ec..1b16d9cfc0 100644 --- a/src/vsg/vk/PushConstants.cpp +++ b/src/vsg/vk/PushConstants.cpp @@ -29,11 +29,13 @@ PushConstants::~PushConstants() void PushConstants::pushTo(State& state) const { state.pushConstantsMap[_offset].push(this); + state.dirty = true; } void PushConstants::popFrom(State& state) const { state.pushConstantsMap[_offset].pop(); + state.dirty = true; } void PushConstants::dispatch(CommandBuffer& commandBuffer) const From 937b02a10e943a2f59928b2c7bcea1a0d9f335be Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 11:46:54 +0000 Subject: [PATCH 13/21] Added support for MatrixTransform and Commands --- include/vsg/traversals/DispatchTraversal.h | 4 ++++ src/vsg/traversals/DispatchTraversal.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/vsg/traversals/DispatchTraversal.h b/include/vsg/traversals/DispatchTraversal.h index c8d7f2fb76..0f5e463d58 100644 --- a/include/vsg/traversals/DispatchTraversal.h +++ b/include/vsg/traversals/DispatchTraversal.h @@ -25,7 +25,9 @@ namespace vsg class QuadGroup; class LOD; class StateGroup; + class MatrixTransform; class Command; + class Commands; class CommandBuffer; class VSG_DECLSPEC DispatchTraversal : public Object @@ -45,7 +47,9 @@ namespace vsg void apply(const LOD& object); // Vulkan nodes + void apply(const MatrixTransform& mt); void apply(const StateGroup& object); + void apply(const Commands& commands); void apply(const Command& command); protected: diff --git a/src/vsg/traversals/DispatchTraversal.cpp b/src/vsg/traversals/DispatchTraversal.cpp index 659154e677..117b519249 100644 --- a/src/vsg/traversals/DispatchTraversal.cpp +++ b/src/vsg/traversals/DispatchTraversal.cpp @@ -16,6 +16,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include +#include #include #include @@ -108,7 +110,26 @@ void DispatchTraversal::apply(const StateGroup& stateGroup) stateGroup.popFrom(_data->_state); } +void DispatchTraversal::apply(const MatrixTransform& mt) +{ + mt.pushTo(_data->_state); + + mt.traverse(*this); + + mt.popFrom(_data->_state); +} + // Vulkan nodes +void DispatchTraversal::apply(const Commands& commands) +{ + // std::cout<<"Visiting Command "<_state.dispatch(*(_data->_commandBuffer)); + for(auto& command : commands.getChildren()) + { + command->dispatch(*(_data->_commandBuffer)); + } +} + void DispatchTraversal::apply(const Command& command) { // std::cout<<"Visiting Command "< Date: Wed, 6 Mar 2019 12:31:52 +0000 Subject: [PATCH 14/21] Update all.h --- include/vsg/all.h | 4 +++- src/vsg/CMakeLists.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/vsg/all.h b/include/vsg/all.h index 4756fe749b..272b4dab97 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -43,13 +43,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI // Node header files #include +#include #include #include +#include #include #include #include // Traversal header files +#include #include #include @@ -99,7 +102,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include #include #include diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 73fd3dd52e..9b37e17936 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES nodes/Commands.cpp nodes/Group.cpp + nodes/Geometry.cpp nodes/Node.cpp nodes/QuadGroup.cpp nodes/StateGroup.cpp From 4994377888386b91294f8be8879b390294826400 Mon Sep 17 00:00:00 2001 From: tomhog Date: Wed, 6 Mar 2019 12:32:28 +0000 Subject: [PATCH 15/21] Fixed struct first seen as class warning related to forward declaration of Context. Fixed conversion warning setting descriptorSetCount. --- include/vsg/vk/Command.h | 2 +- include/vsg/vk/Descriptor.h | 2 +- include/vsg/vk/DescriptorSetLayout.h | 2 +- include/vsg/vk/PipelineLayout.h | 2 +- include/vsg/vk/ShaderModule.h | 2 +- src/vsg/vk/DescriptorSet.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/vsg/vk/Command.h b/include/vsg/vk/Command.h index 6dcaddc953..7ffdb5c97b 100644 --- a/include/vsg/vk/Command.h +++ b/include/vsg/vk/Command.h @@ -20,7 +20,7 @@ namespace vsg { class CommandBuffer; class State; - class Context; + struct Context; class Command : public Inherit { diff --git a/include/vsg/vk/Descriptor.h b/include/vsg/vk/Descriptor.h index fc9fba24e7..a4b5c0f13d 100644 --- a/include/vsg/vk/Descriptor.h +++ b/include/vsg/vk/Descriptor.h @@ -20,7 +20,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - class Context; + struct Context; using DescriptorBufferInfos = std::vector; diff --git a/include/vsg/vk/DescriptorSetLayout.h b/include/vsg/vk/DescriptorSetLayout.h index fdaa74b47d..009c750a3c 100644 --- a/include/vsg/vk/DescriptorSetLayout.h +++ b/include/vsg/vk/DescriptorSetLayout.h @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - class Context; + struct Context; using DescriptorSetLayoutBindings = std::vector; diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index ca95487a8c..99fd5f5f3a 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - class Context; + struct Context; using PushConstantRanges = std::vector; diff --git a/include/vsg/vk/ShaderModule.h b/include/vsg/vk/ShaderModule.h index d0e0093f1c..51343586cc 100644 --- a/include/vsg/vk/ShaderModule.h +++ b/include/vsg/vk/ShaderModule.h @@ -18,7 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - class Context; + struct Context; template bool readFile(T& buffer, const std::string& filename) diff --git a/src/vsg/vk/DescriptorSet.cpp b/src/vsg/vk/DescriptorSet.cpp index 8eaed910bc..000c8e599f 100644 --- a/src/vsg/vk/DescriptorSet.cpp +++ b/src/vsg/vk/DescriptorSet.cpp @@ -71,7 +71,7 @@ DescriptorSet::Implementation::Result DescriptorSet::Implementation::create(Devi VkDescriptorSetAllocateInfo descriptSetAllocateInfo = {}; descriptSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptSetAllocateInfo.descriptorPool = *descriptorPool; - descriptSetAllocateInfo.descriptorSetCount = vkdescriptorSetLayouts.size(); + descriptSetAllocateInfo.descriptorSetCount = static_cast(vkdescriptorSetLayouts.size()); descriptSetAllocateInfo.pSetLayouts = vkdescriptorSetLayouts.data(); VkDescriptorSet descriptorSet; From ceb98d8edb1882152163cf7bdd652119553c2733 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 12:33:36 +0000 Subject: [PATCH 16/21] Moved vsg::Geometry from osg2vsg to core VSG --- include/vsg/nodes/Geometry.h | 47 ++++++++++++++++++++ src/vsg/nodes/Geometry.cpp | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 include/vsg/nodes/Geometry.h create mode 100644 src/vsg/nodes/Geometry.cpp diff --git a/include/vsg/nodes/Geometry.h b/include/vsg/nodes/Geometry.h new file mode 100644 index 0000000000..88a6b384e0 --- /dev/null +++ b/include/vsg/nodes/Geometry.h @@ -0,0 +1,47 @@ +#pragma once + +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include + +#include +#include +#include +#include +#include +#include + +namespace vsg +{ + class Geometry : public Inherit + { + public: + Geometry(Allocator* allocator = nullptr); + + void accept(DispatchTraversal& dv) const override; + + void compile(Context& context) override; + + using Commands = std::vector>; + + // settings + DataList _arrays; + ref_ptr _indices; + Commands _commands; + + // compiled objects + ref_ptr _renderImplementation; + }; + VSG_type_name(vsg::Geometry) + +} diff --git a/src/vsg/nodes/Geometry.cpp b/src/vsg/nodes/Geometry.cpp new file mode 100644 index 0000000000..397062c666 --- /dev/null +++ b/src/vsg/nodes/Geometry.cpp @@ -0,0 +1,84 @@ + +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + +#include + +#include + +using namespace vsg; + +#if 0 +#define DEBUG_OUTPUT std::cout +#else +#define DEBUG_OUTPUT if (false) std::cout +#endif + + +// +// Geometry node +// vertex arrays +// index arrays +// draw + draw DrawIndexed +// push constants for per geometry colours etc. +// +// Maps to a Group containing StateGroup + Binds + DrawIndex/Draw etc + Push constants +// +///////////////////////////////////////////////////////////////////////////////////////// +// +// Geometry +// +Geometry::Geometry(Allocator* allocator) : + Inherit(allocator) +{ +} + +void Geometry::accept(DispatchTraversal& dv) const +{ + if (_renderImplementation) _renderImplementation->accept(dv); +} + +void Geometry::compile(Context& context) +{ + auto vertexBufferData = vsg::createBufferAndTransferData(context.device, context.commandPool, context.graphicsQueue, _arrays, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE); + + _renderImplementation = new vsg::Group; + + // set up vertex buffer binding + vsg::ref_ptr bindVertexBuffers = vsg::BindVertexBuffers::create(0, vertexBufferData); // device dependent + _renderImplementation->addChild(bindVertexBuffers); // device dependent + + // set up index buffer binding + if(_indices &&_indices->dataSize() > 0) + { + auto indexBufferData = vsg::createBufferAndTransferData(context.device, context.commandPool, context.graphicsQueue, { _indices }, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE); + vsg::ref_ptr bindIndexBuffer = vsg::BindIndexBuffer::create(indexBufferData.front(), VK_INDEX_TYPE_UINT16); // device dependent + _renderImplementation->addChild(bindIndexBuffer); // device dependent + } + + // add the commands in the the _renderImplementation group. + for(auto& command : _commands) _renderImplementation->addChild(command); +} + From f78a1d06623f1fec654608342a2669f23c6f2b4e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 16:32:07 +0000 Subject: [PATCH 17/21] Changed struct to class to address warning --- include/vsg/traversals/CompileTraversal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/vsg/traversals/CompileTraversal.h b/include/vsg/traversals/CompileTraversal.h index 31e0dd7330..229c21733b 100644 --- a/include/vsg/traversals/CompileTraversal.h +++ b/include/vsg/traversals/CompileTraversal.h @@ -23,8 +23,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - struct Context + class Context { + public: ref_ptr device; ref_ptr commandPool; ref_ptr renderPass; From d331690ef1ea2ecbf8b33bdd9534c7f762907b7e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Mar 2019 17:06:03 +0000 Subject: [PATCH 18/21] Removed GraphicsNode and add Geometry and MatrixTransform to the Visitor + ConstVisitor classes --- include/vsg/core/ConstVisitor.h | 4 +++ include/vsg/core/Visitor.h | 4 +++ include/vsg/nodes/Geometry.h | 4 +-- include/vsg/nodes/StateGroup.h | 1 - include/vsg/traversals/CompileTraversal.h | 17 +---------- src/vsg/core/ConstVisitor.cpp | 10 ++++++ src/vsg/core/Visitor.cpp | 10 ++++++ src/vsg/traversals/CompileTraversal.cpp | 37 +++-------------------- 8 files changed, 35 insertions(+), 52 deletions(-) diff --git a/include/vsg/core/ConstVisitor.h b/include/vsg/core/ConstVisitor.h index 518fb390ba..340323bf81 100644 --- a/include/vsg/core/ConstVisitor.h +++ b/include/vsg/core/ConstVisitor.h @@ -27,6 +27,8 @@ namespace vsg class QuadGroup; class LOD; class StateGroup; + class MatrixTransform; + class Geometry; // forward declare vulkan classes class Command; @@ -143,6 +145,8 @@ namespace vsg virtual void apply(const QuadGroup&); virtual void apply(const LOD&); virtual void apply(const StateGroup&); + virtual void apply(const MatrixTransform&); + virtual void apply(const Geometry&); // Vulkan nodes virtual void apply(const Command&); diff --git a/include/vsg/core/Visitor.h b/include/vsg/core/Visitor.h index 5049819454..5d594410fb 100644 --- a/include/vsg/core/Visitor.h +++ b/include/vsg/core/Visitor.h @@ -27,6 +27,8 @@ namespace vsg class QuadGroup; class LOD; class StateGroup; + class MatrixTransform; + class Geometry; // forward declare vulkan classes class Command; @@ -143,6 +145,8 @@ namespace vsg virtual void apply(QuadGroup&); virtual void apply(LOD&); virtual void apply(StateGroup&); + virtual void apply(MatrixTransform&); + virtual void apply(Geometry&); // Vulkan nodes virtual void apply(Command&); diff --git a/include/vsg/nodes/Geometry.h b/include/vsg/nodes/Geometry.h index 88a6b384e0..72f8438ffb 100644 --- a/include/vsg/nodes/Geometry.h +++ b/include/vsg/nodes/Geometry.h @@ -23,14 +23,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - class Geometry : public Inherit + class Geometry : public Inherit { public: Geometry(Allocator* allocator = nullptr); void accept(DispatchTraversal& dv) const override; - void compile(Context& context) override; + void compile(Context& context); using Commands = std::vector>; diff --git a/include/vsg/nodes/StateGroup.h b/include/vsg/nodes/StateGroup.h index 10afffe5a6..b89ebfbb99 100644 --- a/include/vsg/nodes/StateGroup.h +++ b/include/vsg/nodes/StateGroup.h @@ -25,7 +25,6 @@ namespace vsg class State; class CommandBuffer; - class VSG_DECLSPEC StateGroup : public Inherit { public: diff --git a/include/vsg/traversals/CompileTraversal.h b/include/vsg/traversals/CompileTraversal.h index 229c21733b..4a721b6049 100644 --- a/include/vsg/traversals/CompileTraversal.h +++ b/include/vsg/traversals/CompileTraversal.h @@ -38,20 +38,6 @@ namespace vsg ref_ptr viewMatrix; }; - class GraphicsNode : public Inherit - { - public: - GraphicsNode(Allocator* allocator = nullptr): - Inherit(allocator) {} - - void read(Input& input) override; - void write(Output& output) const override; - - virtual void compile(Context& context) = 0; - }; - VSG_type_name(vsg::GraphicsNode) - - class VSG_DECLSPEC CompileTraversal : public Visitor { public: @@ -60,9 +46,8 @@ namespace vsg void apply(Object& object); void apply(Command& command); - void apply(Group& group); void apply(StateGroup& stateGroup); - void apply(GraphicsNode& graphics); + void apply(Geometry& geometry); Context context; }; diff --git a/src/vsg/core/ConstVisitor.cpp b/src/vsg/core/ConstVisitor.cpp index fe7e2faa1e..4df7909704 100644 --- a/src/vsg/core/ConstVisitor.cpp +++ b/src/vsg/core/ConstVisitor.cpp @@ -18,6 +18,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include +#include #include #include @@ -259,6 +261,14 @@ void ConstVisitor::apply(const ubvec4Array3D& value) { apply(static_cast(value)); } +void ConstVisitor::apply(const MatrixTransform& value) +{ + apply(static_cast(value)); +} +void ConstVisitor::apply(const Geometry& value) +{ + apply(static_cast(value)); +} //////////////////////////////////////////////////////////////////////////////// // diff --git a/src/vsg/core/Visitor.cpp b/src/vsg/core/Visitor.cpp index 9d8be938e1..a631be99c8 100644 --- a/src/vsg/core/Visitor.cpp +++ b/src/vsg/core/Visitor.cpp @@ -18,6 +18,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include +#include #include #include @@ -288,6 +290,14 @@ void Visitor::apply(StateGroup& value) { apply(static_cast(value)); } +void Visitor::apply(MatrixTransform& value) +{ + apply(static_cast(value)); +} +void Visitor::apply(Geometry& value) +{ + apply(static_cast(value)); +} //////////////////////////////////////////////////////////////////////////////// // diff --git a/src/vsg/traversals/CompileTraversal.cpp b/src/vsg/traversals/CompileTraversal.cpp index 897868cf1a..c724922405 100644 --- a/src/vsg/traversals/CompileTraversal.cpp +++ b/src/vsg/traversals/CompileTraversal.cpp @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include @@ -26,20 +27,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -///////////////////////////////////////////////////////////////////////////////////////// -// -// GraphicsNode -// -void GraphicsNode::read(Input& input) -{ - Group::read(input); -} - -void GraphicsNode::write(Output& output) const -{ - Group::write(output); -} - CompileTraversal::CompileTraversal() { } @@ -50,7 +37,6 @@ CompileTraversal::~CompileTraversal() void CompileTraversal::apply(Object& object) { - // std::cout<<"CompileTraversal::apply("<(&group); - if (graphics) - { - apply(*graphics); - } - else - { - group.traverse(*this); - } -} - void CompileTraversal::apply(StateGroup& stateGroup) { - // std::cout<<"CompileTraversal::apply(StateGroup&)"< Date: Thu, 7 Mar 2019 01:43:43 +0000 Subject: [PATCH 19/21] Added Uniform desctiptor type and UniformValue for adding values to the Uniform --- include/vsg/all.h | 1 + include/vsg/vk/Descriptor.h | 2 +- include/vsg/vk/Uniform.h | 148 ++++++++++++++++++++++++++++++++++++ src/vsg/CMakeLists.txt | 1 + src/vsg/viewer/Viewer.cpp | 3 +- src/vsg/vk/Uniform.cpp | 36 +++++++++ 6 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 include/vsg/vk/Uniform.h create mode 100644 src/vsg/vk/Uniform.cpp diff --git a/include/vsg/all.h b/include/vsg/all.h index 272b4dab97..cf1555c3a0 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -111,6 +111,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include // Input/Output header files #include diff --git a/include/vsg/vk/Descriptor.h b/include/vsg/vk/Descriptor.h index a4b5c0f13d..fe3c825d6b 100644 --- a/include/vsg/vk/Descriptor.h +++ b/include/vsg/vk/Descriptor.h @@ -184,7 +184,7 @@ namespace vsg std::vector _texelBufferViews; }; - class Texture : public Inherit + class VSG_DECLSPEC Texture : public Inherit { public: Texture(); diff --git a/include/vsg/vk/Uniform.h b/include/vsg/vk/Uniform.h new file mode 100644 index 0000000000..503d1258cc --- /dev/null +++ b/include/vsg/vk/Uniform.h @@ -0,0 +1,148 @@ +#pragma once + +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include +#include + +#define VSG_uniformValue(N, T) \ + using N = BasicUniformValue; \ + template<> \ + constexpr const char* type_name() noexcept { return "vsg::" #N; } + +namespace vsg +{ + template + class UniformValue : public Data + { + public: + using value_type = T; + + UniformValue() {} + UniformValue(const UniformValue& rhs) : + _value(rhs._value) {} + explicit UniformValue(const value_type& in_value) : + _value(in_value) {} + + std::size_t sizeofObject() const noexcept override { return sizeof(UniformValue); } + + void accept(Visitor& visitor) override { visitor.apply(*this); } + void accept(ConstVisitor& visitor) const override { visitor.apply(*this); } + + const char* className() const noexcept override { return type_name(); } + + void read(Input& input) override + { + Data::read(input); + } + + void write(Output& output) const override + { + Data::write(output); + } + + std::size_t valueSize() const override { return sizeof(value_type); } + std::size_t valueCount() const override { return 1; } + + std::size_t dataSize() const override { return sizeof(value_type); } + void* dataPointer() override { return &_value; } + const void* dataPointer() const override { return &_value; } + void* dataRelease() override { return nullptr; } + + std::size_t width() const override { return 1; } + std::size_t height() const override { return 1; } + std::size_t depth() const override { return 1; } + + UniformValue& operator=(const UniformValue& rhs) + { + _value = rhs._value; + return *this; + } + UniformValue& operator=(const value_type& rhs) + { + _value = rhs; + return *this; + } + + operator value_type&() { return _value; } + operator const value_type&() const { return _value; } + + value_type& value() { return _value; } + const value_type& value() const { return _value; } + + protected: + virtual ~UniformValue() {} + + private: + value_type _value; + }; + + template + class BasicUniformValue : public UniformValue + { + using base_type = UniformValue; + + void read(Input& input) override + { + base_type::read(input); + input.read("Value", value()); + } + + void write(Output& output) const override + { + base_type::write(output); + output.write("Value", value()); + } + }; + + VSG_uniformValue(boolUniformValue, bool); + VSG_uniformValue(intUniformValue, int); + VSG_uniformValue(uinUniformValue, unsigned int); + VSG_uniformValue(floatUniformValue, float); + VSG_uniformValue(doubleUniformValue, double); + + VSG_uniformValue(vec2UniformValue, vec2); + VSG_uniformValue(vec3UniformValue, vec3); + VSG_uniformValue(vec4UniformValue, vec4); + + VSG_uniformValue(dvec2UniformValue, dvec2); + VSG_uniformValue(dvec3UniformValue, dvec3); + VSG_uniformValue(dvec4UniformValue, dvec4); + + VSG_uniformValue(ubvec2UniformValue, ubvec2); + VSG_uniformValue(ubvec3UniformValue, ubvec3); + VSG_uniformValue(ubvec4UniformValue, ubvec4); + + VSG_uniformValue(mat3UniformValue, mat3); + VSG_uniformValue(dmat3UniformValue, dmat3); + + VSG_uniformValue(mat4UniformValue, mat4); + VSG_uniformValue(dmat4UniformValue, dmat4); + + class VSG_DECLSPEC Uniform : public Inherit + { + public: + Uniform(); + + void compile(Context& context) override; + + void assignTo(VkWriteDescriptorSet& wds, VkDescriptorSet descriptorSet) const override; + + // settings + DataList _dataList; + + ref_ptr _implementation; + }; + VSG_type_name(vsg::Uniform) + +} // namespace vsg diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 9b37e17936..3a997bedbb 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -82,6 +82,7 @@ set(SOURCES vk/ShaderModule.cpp vk/Surface.cpp vk/Swapchain.cpp + vk/Uniform.cpp ) # add platform specific Window implementation diff --git a/src/vsg/viewer/Viewer.cpp b/src/vsg/viewer/Viewer.cpp index 5f4e8bc05c..07948cd852 100644 --- a/src/vsg/viewer/Viewer.cpp +++ b/src/vsg/viewer/Viewer.cpp @@ -290,7 +290,8 @@ void Viewer::compile() uint32_t maxDescriptors = 1000; DescriptorPoolSizes descriptorPoolSizes { - {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, maxDescriptors} // type, descriptorCount // total descriptors of a type across all sets + { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, maxDescriptors }, // type, descriptorCount // total descriptors of a type across all sets + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, maxDescriptors } // type, descriptorCount // total descriptors of a type across all sets }; vsg::CompileTraversal compile; diff --git a/src/vsg/vk/Uniform.cpp b/src/vsg/vk/Uniform.cpp new file mode 100644 index 0000000000..666a417155 --- /dev/null +++ b/src/vsg/vk/Uniform.cpp @@ -0,0 +1,36 @@ +/* + +Copyright(c) 2018 Robert Osfield + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. + + */ + +#include +#include +#include + +#include + +using namespace vsg; + +Uniform::Uniform() : + Inherit(0, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) +{ +} + +void Uniform::compile(Context& context) +{ + auto bufferData = vsg::createHostVisibleBuffer(context.device, _dataList, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE); + vsg::copyDataListToBuffers(bufferData); + _implementation = vsg::DescriptorBuffer::create(_dstBinding, _dstArrayElement, _descriptorType, bufferData); +} + +void Uniform::assignTo(VkWriteDescriptorSet& wds, VkDescriptorSet descriptorSet) const +{ + if (_implementation) _implementation->assignTo(wds, descriptorSet); +} From 8ee8c4d61c65230af2242d76d6d72d15f7862e69 Mon Sep 17 00:00:00 2001 From: tomhog Date: Thu, 7 Mar 2019 01:49:27 +0000 Subject: [PATCH 20/21] Revert "Fixed struct first seen as class warning related to forward declaration of Context. Fixed conversion warning setting descriptorSetCount." This reverts commit 4994377888386b91294f8be8879b390294826400. --- include/vsg/vk/Command.h | 2 +- include/vsg/vk/Descriptor.h | 2 +- include/vsg/vk/DescriptorSetLayout.h | 2 +- include/vsg/vk/PipelineLayout.h | 2 +- include/vsg/vk/ShaderModule.h | 2 +- src/vsg/vk/DescriptorSet.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/vsg/vk/Command.h b/include/vsg/vk/Command.h index 7ffdb5c97b..6dcaddc953 100644 --- a/include/vsg/vk/Command.h +++ b/include/vsg/vk/Command.h @@ -20,7 +20,7 @@ namespace vsg { class CommandBuffer; class State; - struct Context; + class Context; class Command : public Inherit { diff --git a/include/vsg/vk/Descriptor.h b/include/vsg/vk/Descriptor.h index fe3c825d6b..b5db54390f 100644 --- a/include/vsg/vk/Descriptor.h +++ b/include/vsg/vk/Descriptor.h @@ -20,7 +20,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - struct Context; + class Context; using DescriptorBufferInfos = std::vector; diff --git a/include/vsg/vk/DescriptorSetLayout.h b/include/vsg/vk/DescriptorSetLayout.h index 009c750a3c..fdaa74b47d 100644 --- a/include/vsg/vk/DescriptorSetLayout.h +++ b/include/vsg/vk/DescriptorSetLayout.h @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - struct Context; + class Context; using DescriptorSetLayoutBindings = std::vector; diff --git a/include/vsg/vk/PipelineLayout.h b/include/vsg/vk/PipelineLayout.h index 99fd5f5f3a..ca95487a8c 100644 --- a/include/vsg/vk/PipelineLayout.h +++ b/include/vsg/vk/PipelineLayout.h @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - struct Context; + class Context; using PushConstantRanges = std::vector; diff --git a/include/vsg/vk/ShaderModule.h b/include/vsg/vk/ShaderModule.h index 51343586cc..d0e0093f1c 100644 --- a/include/vsg/vk/ShaderModule.h +++ b/include/vsg/vk/ShaderModule.h @@ -18,7 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // forward declare - struct Context; + class Context; template bool readFile(T& buffer, const std::string& filename) diff --git a/src/vsg/vk/DescriptorSet.cpp b/src/vsg/vk/DescriptorSet.cpp index 000c8e599f..8eaed910bc 100644 --- a/src/vsg/vk/DescriptorSet.cpp +++ b/src/vsg/vk/DescriptorSet.cpp @@ -71,7 +71,7 @@ DescriptorSet::Implementation::Result DescriptorSet::Implementation::create(Devi VkDescriptorSetAllocateInfo descriptSetAllocateInfo = {}; descriptSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptSetAllocateInfo.descriptorPool = *descriptorPool; - descriptSetAllocateInfo.descriptorSetCount = static_cast(vkdescriptorSetLayouts.size()); + descriptSetAllocateInfo.descriptorSetCount = vkdescriptorSetLayouts.size(); descriptSetAllocateInfo.pSetLayouts = vkdescriptorSetLayouts.data(); VkDescriptorSet descriptorSet; From 687bde4a83ce8622fbd38dff39b8fc3b8964d3bd Mon Sep 17 00:00:00 2001 From: tomhog Date: Thu, 7 Mar 2019 01:54:49 +0000 Subject: [PATCH 21/21] Fix cast warning --- src/vsg/vk/DescriptorSet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vsg/vk/DescriptorSet.cpp b/src/vsg/vk/DescriptorSet.cpp index 8eaed910bc..000c8e599f 100644 --- a/src/vsg/vk/DescriptorSet.cpp +++ b/src/vsg/vk/DescriptorSet.cpp @@ -71,7 +71,7 @@ DescriptorSet::Implementation::Result DescriptorSet::Implementation::create(Devi VkDescriptorSetAllocateInfo descriptSetAllocateInfo = {}; descriptSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptSetAllocateInfo.descriptorPool = *descriptorPool; - descriptSetAllocateInfo.descriptorSetCount = vkdescriptorSetLayouts.size(); + descriptSetAllocateInfo.descriptorSetCount = static_cast(vkdescriptorSetLayouts.size()); descriptSetAllocateInfo.pSetLayouts = vkdescriptorSetLayouts.data(); VkDescriptorSet descriptorSet;