Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 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 | |
Chris Forbes | 26f1a86 | 2019-02-02 15:23:01 -0800 | [diff] [blame] | 18 | #include <Pipeline/SpirvShader.hpp> |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 19 | #include "Context.hpp" |
| 20 | #include "RoutineCache.hpp" |
Nicolas Capens | 1d8c8db | 2018-11-05 16:30:42 -0500 | [diff] [blame] | 21 | #include "System/Types.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 22 | |
| 23 | namespace 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 Capens | e899321 | 2019-06-21 12:21:08 -0400 | [diff] [blame] | 35 | struct States : Memset<States> |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 36 | { |
Nicolas Capens | e899321 | 2019-06-21 12:21:08 -0400 | [diff] [blame] | 37 | States() : Memset(this, 0) {} |
| 38 | |
| 39 | uint32_t computeHash(); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 40 | |
| 41 | bool isDrawPoint : 1; |
| 42 | bool isDrawLine : 1; |
| 43 | bool isDrawTriangle : 1; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 44 | bool interpolateZ : 1; |
| 45 | bool interpolateW : 1; |
Alexis Hetu | 72d8104 | 2019-06-10 10:23:23 -0400 | [diff] [blame] | 46 | VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM); |
Chris Forbes | d245255 | 2019-02-22 09:45:06 -0800 | [diff] [blame] | 47 | VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 48 | bool slopeDepthBias : 1; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 49 | unsigned int multiSample : 3; // 1, 2 or 4 |
| 50 | bool rasterizerDiscard : 1; |
| 51 | |
Chris Forbes | 26f1a86 | 2019-02-02 15:23:01 -0800 | [diff] [blame] | 52 | SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct State : States |
| 56 | { |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 57 | bool operator==(const State &states) const; |
| 58 | |
Nicolas Capens | e899321 | 2019-06-21 12:21:08 -0400 | [diff] [blame] | 59 | uint32_t hash; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw); |
| 63 | |
Alexis Hetu | 2e4f6e8 | 2019-05-08 15:52:21 -0400 | [diff] [blame] | 64 | SetupProcessor(); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 65 | |
| 66 | ~SetupProcessor(); |
| 67 | |
| 68 | protected: |
Alexis Hetu | 2e4f6e8 | 2019-05-08 15:52:21 -0400 | [diff] [blame] | 69 | State update(const sw::Context* context) const; |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 70 | std::shared_ptr<Routine> routine(const State &state); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 71 | |
| 72 | void setRoutineCacheSize(int cacheSize); |
| 73 | |
| 74 | private: |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 75 | RoutineCache<State> *routineCache; |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | #endif // sw_SetupProcessor_hpp |