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_VertexRoutine_hpp 16 #define sw_VertexRoutine_hpp 17 18 #include "ShaderCore.hpp" 19 #include "SpirvShader.hpp" 20 #include "Device/Color.hpp" 21 #include "Device/VertexProcessor.hpp" 22 23 namespace vk { 24 class PipelineLayout; 25 } 26 27 namespace sw { 28 29 class VertexRoutinePrototype : public VertexRoutineFunction 30 { 31 public: VertexRoutinePrototype()32 VertexRoutinePrototype() 33 : vertex(Arg<0>()) 34 , batch(Arg<1>()) 35 , task(Arg<2>()) 36 , data(Arg<3>()) 37 {} ~VertexRoutinePrototype()38 virtual ~VertexRoutinePrototype() {} 39 40 protected: 41 Pointer<Byte> vertex; 42 Pointer<UInt> batch; 43 Pointer<Byte> task; 44 Pointer<Byte> data; 45 }; 46 47 class VertexRoutine : public VertexRoutinePrototype 48 { 49 public: 50 VertexRoutine( 51 const VertexProcessor::State &state, 52 vk::PipelineLayout const *pipelineLayout, 53 SpirvShader const *spirvShader); 54 virtual ~VertexRoutine(); 55 56 void generate(); 57 58 protected: 59 Pointer<Byte> constants; 60 61 Int clipFlags; 62 Int cullMask; 63 64 SpirvRoutine routine; 65 66 const VertexProcessor::State &state; 67 SpirvShader const *const spirvShader; 68 69 private: 70 virtual void program(Pointer<UInt> &batch, UInt &vertexCount) = 0; 71 72 typedef VertexProcessor::State::Input Stream; 73 74 Vector4f readStream(Pointer<Byte> &buffer, UInt &stride, const Stream &stream, Pointer<UInt> &batch, 75 bool robustBufferAccess, UInt &robustnessSize, Int baseVertex); 76 void readInput(Pointer<UInt> &batch); 77 void computeClipFlags(); 78 void computeCullMask(); 79 void writeCache(Pointer<Byte> &vertexCache, Pointer<UInt> &tagCache, Pointer<UInt> &batch); 80 void writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cacheEntry); 81 }; 82 83 } // namespace sw 84 85 #endif // sw_VertexRoutine_hpp 86