blob: 8bf7c8885fa39527fee1808458d471459578f0c6 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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
Nicolas Capens68a82382018-10-02 13:16:55 -040018#include "ShaderCore.hpp"
Chris Forbes1845d5e2018-12-27 11:50:15 -080019#include "SpirvShader.hpp"
Nicolas Capens8bcd1742019-06-12 11:41:14 -040020#include "Device/VertexProcessor.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040021
Ben Claytonbc1c0672019-12-17 20:37:37 +000022namespace vk {
23class PipelineLayout;
24}
Nicolas Capens157ba262019-12-10 17:49:14 -050025
26namespace sw {
27
28class VertexRoutinePrototype : public VertexRoutineFunction
Ben Clayton76e9bc02019-02-26 15:02:18 +000029{
Nicolas Capens157ba262019-12-10 17:49:14 -050030public:
Ben Claytonbc1c0672019-12-17 20:37:37 +000031 VertexRoutinePrototype()
32 : vertex(Arg<0>())
33 , batch(Arg<1>())
34 , task(Arg<2>())
35 , data(Arg<3>())
36 {}
Nicolas Capens157ba262019-12-10 17:49:14 -050037 virtual ~VertexRoutinePrototype() {}
Ben Clayton76e9bc02019-02-26 15:02:18 +000038
Nicolas Capens157ba262019-12-10 17:49:14 -050039protected:
40 Pointer<Byte> vertex;
41 Pointer<UInt> batch;
42 Pointer<Byte> task;
43 Pointer<Byte> data;
44};
45
46class VertexRoutine : public VertexRoutinePrototype
Nicolas Capens68a82382018-10-02 13:16:55 -040047{
Nicolas Capens157ba262019-12-10 17:49:14 -050048public:
49 VertexRoutine(
Ben Claytonbc1c0672019-12-17 20:37:37 +000050 const VertexProcessor::State &state,
51 vk::PipelineLayout const *pipelineLayout,
52 SpirvShader const *spirvShader);
Nicolas Capens157ba262019-12-10 17:49:14 -050053 virtual ~VertexRoutine();
Nicolas Capens68a82382018-10-02 13:16:55 -040054
Nicolas Capens157ba262019-12-10 17:49:14 -050055 void generate();
Nicolas Capens68a82382018-10-02 13:16:55 -040056
Nicolas Capens157ba262019-12-10 17:49:14 -050057protected:
58 Pointer<Byte> constants;
Nicolas Capens68a82382018-10-02 13:16:55 -040059
Nicolas Capens157ba262019-12-10 17:49:14 -050060 Int clipFlags;
61 Int cullMask;
Nicolas Capens68a82382018-10-02 13:16:55 -040062
Nicolas Capens157ba262019-12-10 17:49:14 -050063 SpirvRoutine routine;
Nicolas Capens68a82382018-10-02 13:16:55 -040064
Nicolas Capens157ba262019-12-10 17:49:14 -050065 const VertexProcessor::State &state;
Ben Claytonbc1c0672019-12-17 20:37:37 +000066 SpirvShader const *const spirvShader;
Nicolas Capens68a82382018-10-02 13:16:55 -040067
Nicolas Capens157ba262019-12-10 17:49:14 -050068private:
Ben Claytonbc1c0672019-12-17 20:37:37 +000069 virtual void program(Pointer<UInt> &batch, UInt &vertexCount) = 0;
Nicolas Capens68a82382018-10-02 13:16:55 -040070
Nicolas Capens157ba262019-12-10 17:49:14 -050071 typedef VertexProcessor::State::Input Stream;
Nicolas Capens68a82382018-10-02 13:16:55 -040072
Nicolas Capens157ba262019-12-10 17:49:14 -050073 Vector4f readStream(Pointer<Byte> &buffer, UInt &stride, const Stream &stream, Pointer<UInt> &batch,
Ben Claytonbc1c0672019-12-17 20:37:37 +000074 bool robustBufferAccess, UInt &robustnessSize, Int baseVertex);
Nicolas Capens157ba262019-12-10 17:49:14 -050075 void readInput(Pointer<UInt> &batch);
76 void computeClipFlags();
77 void computeCullMask();
78 void writeCache(Pointer<Byte> &vertexCache, Pointer<UInt> &tagCache, Pointer<UInt> &batch);
79 void writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cacheEntry);
80};
Nicolas Capens68a82382018-10-02 13:16:55 -040081
Nicolas Capens157ba262019-12-10 17:49:14 -050082} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -040083
Ben Claytonbc1c0672019-12-17 20:37:37 +000084#endif // sw_VertexRoutine_hpp