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 "Memset.hpp" 20 #include "RoutineCache.hpp" 21 #include "System/Types.hpp" 22 #include <Pipeline/SpirvShader.hpp> 23 24 #include <memory> 25 26 namespace sw { 27 28 struct Primitive; 29 struct Triangle; 30 struct Polygon; 31 struct Vertex; 32 struct DrawCall; 33 struct DrawData; 34 35 using SetupFunction = FunctionT<int(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw)>; 36 37 class SetupProcessor 38 { 39 public: 40 struct States : Memset<States> 41 { Statessw::SetupProcessor::States42 States() 43 : Memset(this, 0) 44 {} 45 46 uint32_t computeHash(); 47 48 bool isDrawPoint : 1; 49 bool isDrawLine : 1; 50 bool isDrawTriangle : 1; 51 bool fixedPointDepthBuffer : 1; 52 bool applyConstantDepthBias : 1; 53 bool applySlopeDepthBias : 1; 54 bool applyDepthBiasClamp : 1; 55 bool interpolateZ : 1; 56 bool interpolateW : 1; 57 VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM); 58 VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM); 59 unsigned int multiSampleCount : 3; // 1, 2 or 4 60 bool enableMultiSampling : 1; 61 bool rasterizerDiscard : 1; 62 unsigned int numClipDistances : 4; // [0 - 8] 63 unsigned int numCullDistances : 4; // [0 - 8] 64 65 SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS]; 66 }; 67 68 struct State : States 69 { 70 bool operator==(const State &states) const; 71 72 uint32_t hash; 73 }; 74 75 using RoutineType = SetupFunction::RoutineType; 76 77 SetupProcessor(); 78 79 State update(const vk::GraphicsState &pipelineState, const sw::SpirvShader *fragmentShader, const sw::SpirvShader *vertexShader, const vk::Attachments &attachments) const; 80 RoutineType routine(const State &state); 81 82 void setRoutineCacheSize(int cacheSize); 83 84 private: 85 using RoutineCacheType = RoutineCache<State, SetupFunction::CFunctionType>; 86 std::unique_ptr<RoutineCacheType> routineCache; 87 }; 88 89 } // namespace sw 90 91 namespace std { 92 93 template<> 94 struct hash<sw::SetupProcessor::State> 95 { operator ()std::hash96 uint64_t operator()(const sw::SetupProcessor::State &state) const 97 { 98 return state.hash; 99 } 100 }; 101 102 } // namespace std 103 104 #endif // sw_SetupProcessor_hpp 105