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