blob: 039b33e9ee3ad485fff5873a9a4c4a4c17ae5d64 [file] [log] [blame]
Alexis Hetu000df8b2018-10-24 15:22:41 -04001// 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 Hetuc0f92f22018-11-15 16:25:38 -050019#include "Device/Renderer.hpp"
Alexis Hetu000df8b2018-10-24 15:22:41 -040020
Chris Forbesaf4ed532018-12-06 18:33:27 -080021namespace sw { class SpirvShader; }
22
Alexis Hetu000df8b2018-10-24 15:22:41 -040023namespace vk
24{
25
26class Pipeline
27{
28public:
Alexis Hetue6e76c62018-12-07 16:26:05 -050029 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 Hetu000df8b2018-10-24 15:22:41 -040040#ifndef NDEBUG
41 virtual VkPipelineBindPoint bindPoint() const = 0;
42#endif
43};
44
Alexis Hetue6e76c62018-12-07 16:26:05 -050045class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline>
Alexis Hetu000df8b2018-10-24 15:22:41 -040046{
47public:
48 GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem);
49 ~GraphicsPipeline() = delete;
Alexis Hetue6e76c62018-12-07 16:26:05 -050050 void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
Alexis Hetu000df8b2018-10-24 15:22:41 -040051
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 Hetuc0f92f22018-11-15 16:25:38 -050060
61 void compileShaders(const VkAllocationCallbacks* pAllocator, const VkGraphicsPipelineCreateInfo* pCreateInfo);
62
Alexis Hetuc65473d2018-12-07 16:26:05 -050063 uint32_t computePrimitiveCount(uint32_t vertexCount) const;
Alexis Hetuc0f92f22018-11-15 16:25:38 -050064 const sw::Context& getContext() const;
65 const sw::Rect& getScissor() const;
66 const VkViewport& getViewport() const;
67 const sw::Color<float>& getBlendConstants() const;
68
69private:
Chris Forbesaf4ed532018-12-06 18:33:27 -080070 sw::SpirvShader *vertexShader = nullptr;
71 sw::SpirvShader *fragmentShader = nullptr;
72
Alexis Hetuc0f92f22018-11-15 16:25:38 -050073 sw::Context context;
74 sw::Rect scissor;
75 VkViewport viewport;
76 sw::Color<float> blendConstants;
Alexis Hetu000df8b2018-10-24 15:22:41 -040077};
78
Alexis Hetue6e76c62018-12-07 16:26:05 -050079class ComputePipeline : public Pipeline, public ObjectBase<ComputePipeline, VkPipeline>
Alexis Hetu000df8b2018-10-24 15:22:41 -040080{
81public:
82 ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem);
83 ~ComputePipeline() = delete;
Alexis Hetue6e76c62018-12-07 16:26:05 -050084 void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
Alexis Hetu000df8b2018-10-24 15:22:41 -040085
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
96static inline Pipeline* Cast(VkPipeline object)
97{
98 return reinterpret_cast<Pipeline*>(object);
99}
100
101} // namespace vk
102
103#endif // VK_PIPELINE_HPP_