blob: a84f818a9d0b6ff9a5bd4b837217e1c2f5bcc593 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// Copyright 2016 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 sw_SetupProcessor_hpp
16#define sw_SetupProcessor_hpp
17
Chris Forbes26f1a862019-02-02 15:23:01 -080018#include <Pipeline/SpirvShader.hpp>
Nicolas Capens68a82382018-10-02 13:16:55 -040019#include "Context.hpp"
20#include "RoutineCache.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050021#include "System/Types.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040022
23namespace sw
24{
25 struct Primitive;
26 struct Triangle;
27 struct Polygon;
28 struct Vertex;
29 struct DrawCall;
30 struct DrawData;
31
32 class SetupProcessor
33 {
34 public:
Nicolas Capense8993212019-06-21 12:21:08 -040035 struct States : Memset<States>
Nicolas Capens68a82382018-10-02 13:16:55 -040036 {
Nicolas Capense8993212019-06-21 12:21:08 -040037 States() : Memset(this, 0) {}
38
39 uint32_t computeHash();
Nicolas Capens68a82382018-10-02 13:16:55 -040040
41 bool isDrawPoint : 1;
42 bool isDrawLine : 1;
43 bool isDrawTriangle : 1;
Nicolas Capens68a82382018-10-02 13:16:55 -040044 bool interpolateZ : 1;
45 bool interpolateW : 1;
Alexis Hetu72d81042019-06-10 10:23:23 -040046 VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM);
Chris Forbesd2452552019-02-22 09:45:06 -080047 VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
Nicolas Capens68a82382018-10-02 13:16:55 -040048 bool slopeDepthBias : 1;
Nicolas Capens68a82382018-10-02 13:16:55 -040049 unsigned int multiSample : 3; // 1, 2 or 4
50 bool rasterizerDiscard : 1;
51
Chris Forbes26f1a862019-02-02 15:23:01 -080052 SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS];
Nicolas Capens68a82382018-10-02 13:16:55 -040053 };
54
55 struct State : States
56 {
Nicolas Capens68a82382018-10-02 13:16:55 -040057 bool operator==(const State &states) const;
58
Nicolas Capense8993212019-06-21 12:21:08 -040059 uint32_t hash;
Nicolas Capens68a82382018-10-02 13:16:55 -040060 };
61
62 typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
63
Alexis Hetu2e4f6e82019-05-08 15:52:21 -040064 SetupProcessor();
Nicolas Capens68a82382018-10-02 13:16:55 -040065
66 ~SetupProcessor();
67
68 protected:
Alexis Hetu2e4f6e82019-05-08 15:52:21 -040069 State update(const sw::Context* context) const;
Ben Clayton6897e9b2019-07-16 17:27:27 +010070 std::shared_ptr<Routine> routine(const State &state);
Nicolas Capens68a82382018-10-02 13:16:55 -040071
72 void setRoutineCacheSize(int cacheSize);
73
74 private:
Nicolas Capens68a82382018-10-02 13:16:55 -040075 RoutineCache<State> *routineCache;
76 };
77}
78
79#endif // sw_SetupProcessor_hpp