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