| 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 "Context.hpp" | 
|---|
| 19 | #include "RoutineCache.hpp" | 
|---|
| 20 | #include "Shader/VertexShader.hpp" | 
|---|
| 21 | #include "Shader/PixelShader.hpp" | 
|---|
| 22 | #include "Common/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 | class SetupProcessor | 
|---|
| 34 | { | 
|---|
| 35 | public: | 
|---|
| 36 | struct States : Memset<States> | 
|---|
| 37 | { | 
|---|
| 38 | States() : Memset(this, 0) {} | 
|---|
| 39 |  | 
|---|
| 40 | uint32_t computeHash(); | 
|---|
| 41 |  | 
|---|
| 42 | bool isDrawPoint               : 1; | 
|---|
| 43 | bool isDrawLine                : 1; | 
|---|
| 44 | bool isDrawTriangle            : 1; | 
|---|
| 45 | bool isDrawSolidTriangle       : 1; | 
|---|
| 46 | bool interpolateZ              : 1; | 
|---|
| 47 | bool interpolateW              : 1; | 
|---|
| 48 | bool perspective               : 1; | 
|---|
| 49 | bool pointSprite               : 1; | 
|---|
| 50 | unsigned int positionRegister  : BITS(VERTEX_OUTPUT_LAST); | 
|---|
| 51 | unsigned int pointSizeRegister : BITS(VERTEX_OUTPUT_LAST); | 
|---|
| 52 | CullMode cullMode              : BITS(CULL_LAST); | 
|---|
| 53 | bool twoSidedStencil           : 1; | 
|---|
| 54 | bool slopeDepthBias            : 1; | 
|---|
| 55 | bool vFace                     : 1; | 
|---|
| 56 | unsigned int multiSample       : 3;   // 1, 2 or 4 | 
|---|
| 57 | bool rasterizerDiscard         : 1; | 
|---|
| 58 |  | 
|---|
| 59 | struct Gradient | 
|---|
| 60 | { | 
|---|
| 61 | unsigned char attribute : BITS(VERTEX_OUTPUT_LAST); | 
|---|
| 62 | bool flat               : 1; | 
|---|
| 63 | bool wrap               : 1; | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | union | 
|---|
| 67 | { | 
|---|
| 68 | struct | 
|---|
| 69 | { | 
|---|
| 70 | Gradient color[2][4]; | 
|---|
| 71 | Gradient texture[8][4]; | 
|---|
| 72 | Gradient fog; | 
|---|
| 73 | }; | 
|---|
| 74 |  | 
|---|
| 75 | Gradient gradient[MAX_FRAGMENT_INPUTS][4]; | 
|---|
| 76 | }; | 
|---|
| 77 | }; | 
|---|
| 78 |  | 
|---|
| 79 | struct State : States | 
|---|
| 80 | { | 
|---|
| 81 | bool operator==(const State &states) const; | 
|---|
| 82 |  | 
|---|
| 83 | uint32_t hash; | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw); | 
|---|
| 87 |  | 
|---|
| 88 | SetupProcessor(Context *context); | 
|---|
| 89 |  | 
|---|
| 90 | ~SetupProcessor(); | 
|---|
| 91 |  | 
|---|
| 92 | protected: | 
|---|
| 93 | State update() const; | 
|---|
| 94 | std::shared_ptr<Routine> routine(const State &state); | 
|---|
| 95 |  | 
|---|
| 96 | void setRoutineCacheSize(int cacheSize); | 
|---|
| 97 |  | 
|---|
| 98 | private: | 
|---|
| 99 | Context *const context; | 
|---|
| 100 |  | 
|---|
| 101 | RoutineCache<State> *routineCache; | 
|---|
| 102 | }; | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | #endif   // sw_SetupProcessor_hpp | 
|---|
| 106 |  | 
|---|