| 1 | // 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 | |
| 18 | #include <Pipeline/SpirvShader.hpp> |
| 19 | #include "Context.hpp" |
| 20 | #include "Memset.hpp" |
| 21 | #include "RoutineCache.hpp" |
| 22 | #include "System/Types.hpp" |
| 23 | |
| 24 | namespace sw |
| 25 | { |
| 26 | struct Primitive; |
| 27 | struct Triangle; |
| 28 | struct Polygon; |
| 29 | struct Vertex; |
| 30 | struct DrawCall; |
| 31 | struct DrawData; |
| 32 | |
| 33 | using SetupFunction = FunctionT<int(Primitive* primitive, const Triangle* triangle, const Polygon* polygon, const DrawData* draw)>; |
| 34 | |
| 35 | class SetupProcessor |
| 36 | { |
| 37 | public: |
| 38 | struct States : Memset<States> |
| 39 | { |
| 40 | States() : Memset(this, 0) {} |
| 41 | |
| 42 | uint32_t computeHash(); |
| 43 | |
| 44 | bool isDrawPoint : 1; |
| 45 | bool isDrawLine : 1; |
| 46 | bool isDrawTriangle : 1; |
| 47 | bool applySlopeDepthBias : 1; |
| 48 | bool interpolateZ : 1; |
| 49 | bool interpolateW : 1; |
| 50 | VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM); |
| 51 | VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM); |
| 52 | unsigned int multiSample : 3; // 1, 2 or 4 |
| 53 | bool rasterizerDiscard : 1; |
| 54 | |
| 55 | SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS]; |
| 56 | }; |
| 57 | |
| 58 | struct State : States |
| 59 | { |
| 60 | bool operator==(const State &states) const; |
| 61 | |
| 62 | uint32_t hash; |
| 63 | }; |
| 64 | |
| 65 | using RoutineType = SetupFunction::RoutineType; |
| 66 | |
| 67 | SetupProcessor(); |
| 68 | |
| 69 | ~SetupProcessor(); |
| 70 | |
| 71 | protected: |
| 72 | State update(const sw::Context* context) const; |
| 73 | RoutineType routine(const State &state); |
| 74 | |
| 75 | void setRoutineCacheSize(int cacheSize); |
| 76 | |
| 77 | private: |
| 78 | using RoutineCacheType = RoutineCacheT<State, SetupFunction::CFunctionType>; |
| 79 | RoutineCacheType *routineCache; |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | #endif // sw_SetupProcessor_hpp |
| 84 | |