1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef VK_PIPELINE_HPP_
16 #define VK_PIPELINE_HPP_
18 #include "VkObject.hpp"
19 #include "Device/Renderer.hpp"
21 namespace sw { class SpirvShader; }
31 Pipeline(PipelineLayout const *layout);
35 return reinterpret_cast<VkPipeline>(this);
38 void destroy(const VkAllocationCallbacks* pAllocator)
40 destroyPipeline(pAllocator);
43 virtual void destroyPipeline(const VkAllocationCallbacks* pAllocator) = 0;
45 virtual VkPipelineBindPoint bindPoint() const = 0;
48 PipelineLayout const * getLayout() const { return layout; }
51 PipelineLayout const *layout = nullptr;
54 class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline>
57 GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem);
58 ~GraphicsPipeline() = delete;
59 void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
62 VkPipelineBindPoint bindPoint() const override
64 return VK_PIPELINE_BIND_POINT_GRAPHICS;
68 static size_t ComputeRequiredAllocationSize(const VkGraphicsPipelineCreateInfo* pCreateInfo);
70 void compileShaders(const VkAllocationCallbacks* pAllocator, const VkGraphicsPipelineCreateInfo* pCreateInfo);
72 uint32_t computePrimitiveCount(uint32_t vertexCount) const;
73 const sw::Context& getContext() const;
74 const VkRect2D& getScissor() const;
75 const VkViewport& getViewport() const;
76 const sw::Color<float>& getBlendConstants() const;
79 sw::SpirvShader *vertexShader = nullptr;
80 sw::SpirvShader *fragmentShader = nullptr;
85 sw::Color<float> blendConstants;
88 class ComputePipeline : public Pipeline, public ObjectBase<ComputePipeline, VkPipeline>
91 ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem);
92 ~ComputePipeline() = delete;
93 void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
96 VkPipelineBindPoint bindPoint() const override
98 return VK_PIPELINE_BIND_POINT_COMPUTE;
102 static size_t ComputeRequiredAllocationSize(const VkComputePipelineCreateInfo* pCreateInfo);
104 void compileShaders(const VkAllocationCallbacks* pAllocator, const VkComputePipelineCreateInfo* pCreateInfo);
106 void run(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ,
107 size_t numDescriptorSets, VkDescriptorSet *descriptorSets, sw::PushConstantStorage const &pushConstants);
110 sw::SpirvShader *shader = nullptr;
111 rr::Routine *routine = nullptr;
114 static inline Pipeline* Cast(VkPipeline object)
116 return reinterpret_cast<Pipeline*>(object);
121 #endif // VK_PIPELINE_HPP_