Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 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 |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 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. |
| 14 | |
| 15 | #ifndef VK_PIPELINE_HPP_ |
| 16 | #define VK_PIPELINE_HPP_ |
| 17 | |
| 18 | #include "VkObject.hpp" |
Alexis Hetu | c0f92f2 | 2018-11-15 16:25:38 -0500 | [diff] [blame] | 19 | #include "Device/Renderer.hpp" |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 20 | |
Chris Forbes | af4ed53 | 2018-12-06 18:33:27 -0800 | [diff] [blame] | 21 | namespace sw { class SpirvShader; } |
| 22 | |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 23 | namespace vk |
| 24 | { |
| 25 | |
| 26 | class Pipeline |
| 27 | { |
| 28 | public: |
Alexis Hetu | e6e76c6 | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 29 | operator VkPipeline() |
| 30 | { |
| 31 | return reinterpret_cast<VkPipeline>(this); |
| 32 | } |
| 33 | |
| 34 | void destroy(const VkAllocationCallbacks* pAllocator) |
| 35 | { |
| 36 | destroyPipeline(pAllocator); |
| 37 | } |
| 38 | |
| 39 | virtual void destroyPipeline(const VkAllocationCallbacks* pAllocator) = 0; |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 40 | #ifndef NDEBUG |
| 41 | virtual VkPipelineBindPoint bindPoint() const = 0; |
| 42 | #endif |
| 43 | }; |
| 44 | |
Alexis Hetu | e6e76c6 | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 45 | class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline> |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 46 | { |
| 47 | public: |
| 48 | GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem); |
| 49 | ~GraphicsPipeline() = delete; |
Alexis Hetu | e6e76c6 | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 50 | void destroyPipeline(const VkAllocationCallbacks* pAllocator) override; |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 51 | |
| 52 | #ifndef NDEBUG |
| 53 | VkPipelineBindPoint bindPoint() const override |
| 54 | { |
| 55 | return VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 56 | } |
| 57 | #endif |
| 58 | |
| 59 | static size_t ComputeRequiredAllocationSize(const VkGraphicsPipelineCreateInfo* pCreateInfo); |
Alexis Hetu | c0f92f2 | 2018-11-15 16:25:38 -0500 | [diff] [blame] | 60 | |
| 61 | void compileShaders(const VkAllocationCallbacks* pAllocator, const VkGraphicsPipelineCreateInfo* pCreateInfo); |
| 62 | |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 63 | uint32_t computePrimitiveCount(uint32_t vertexCount) const; |
Alexis Hetu | c0f92f2 | 2018-11-15 16:25:38 -0500 | [diff] [blame] | 64 | const sw::Context& getContext() const; |
| 65 | const sw::Rect& getScissor() const; |
| 66 | const VkViewport& getViewport() const; |
| 67 | const sw::Color<float>& getBlendConstants() const; |
| 68 | |
| 69 | private: |
Chris Forbes | af4ed53 | 2018-12-06 18:33:27 -0800 | [diff] [blame] | 70 | sw::SpirvShader *vertexShader = nullptr; |
| 71 | sw::SpirvShader *fragmentShader = nullptr; |
| 72 | |
Alexis Hetu | c0f92f2 | 2018-11-15 16:25:38 -0500 | [diff] [blame] | 73 | sw::Context context; |
| 74 | sw::Rect scissor; |
| 75 | VkViewport viewport; |
| 76 | sw::Color<float> blendConstants; |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 77 | }; |
| 78 | |
Alexis Hetu | e6e76c6 | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 79 | class ComputePipeline : public Pipeline, public ObjectBase<ComputePipeline, VkPipeline> |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 80 | { |
| 81 | public: |
| 82 | ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem); |
| 83 | ~ComputePipeline() = delete; |
Alexis Hetu | e6e76c6 | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 84 | void destroyPipeline(const VkAllocationCallbacks* pAllocator) override; |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 85 | |
| 86 | #ifndef NDEBUG |
| 87 | VkPipelineBindPoint bindPoint() const override |
| 88 | { |
| 89 | return VK_PIPELINE_BIND_POINT_COMPUTE; |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | static size_t ComputeRequiredAllocationSize(const VkComputePipelineCreateInfo* pCreateInfo); |
| 94 | }; |
| 95 | |
| 96 | static inline Pipeline* Cast(VkPipeline object) |
| 97 | { |
| 98 | return reinterpret_cast<Pipeline*>(object); |
| 99 | } |
| 100 | |
| 101 | } // namespace vk |
| 102 | |
| 103 | #endif // VK_PIPELINE_HPP_ |