blob: fcacdb87e6bac63d43d0909caad0bc2499f6d56a [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_Primitive_hpp
16#define sw_Primitive_hpp
17
Ben Claytoneea9d352019-08-29 01:05:14 +010018#include "Memset.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040019#include "Vertex.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050020#include "Device/Config.hpp"
Ben Claytoneea9d352019-08-29 01:05:14 +010021#include "System/Build.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040022
Nicolas Capens157ba262019-12-10 17:49:14 -050023namespace sw {
24
Ben Claytonfccfc562019-12-17 20:37:31 +000025struct Triangle MEMORY_SANITIZER_ONLY(
26 : Memset<Triangle>)
Nicolas Capens68a82382018-10-02 13:16:55 -040027{
Ben Claytoneea9d352019-08-29 01:05:14 +010028#if MEMORY_SANITIZER_ENABLED
Nicolas Capens157ba262019-12-10 17:49:14 -050029 // Memory sanitizer cannot 'see' writes from JIT'd code, and can raise
30 // false-positives when read. By clearing the struct in the constructor,
31 // we can avoid triggering these false-positives.
Ben Claytonfccfc562019-12-17 20:37:31 +000032 inline Triangle()
33 : Memset<Triangle>(this, 0)
34 {}
35#endif // MEMORY_SANITIZER_ENABLED
Ben Claytoneea9d352019-08-29 01:05:14 +010036
Nicolas Capens157ba262019-12-10 17:49:14 -050037 Vertex v0;
38 Vertex v1;
39 Vertex v2;
40};
Nicolas Capens68a82382018-10-02 13:16:55 -040041
Ben Claytonfccfc562019-12-17 20:37:31 +000042struct PlaneEquation // z = A * x + B * y + C
Nicolas Capens157ba262019-12-10 17:49:14 -050043{
44 float4 A;
45 float4 B;
46 float4 C;
47};
Nicolas Capens68a82382018-10-02 13:16:55 -040048
Ben Claytonfccfc562019-12-17 20:37:31 +000049struct Primitive MEMORY_SANITIZER_ONLY(
50 : Memset<Primitive>)
Nicolas Capens157ba262019-12-10 17:49:14 -050051{
Ben Claytoneea9d352019-08-29 01:05:14 +010052#if MEMORY_SANITIZER_ENABLED
Nicolas Capens157ba262019-12-10 17:49:14 -050053 // Memory sanitizer cannot 'see' writes from JIT'd code, and can raise
54 // false-positives when read. By clearing the struct in the constructor,
55 // we can avoid triggering these false-positives.
Ben Claytonfccfc562019-12-17 20:37:31 +000056 inline Primitive()
57 : Memset<Primitive>(this, 0)
58 {}
59#endif // MEMORY_SANITIZER_ENABLED
Ben Claytoneea9d352019-08-29 01:05:14 +010060
Nicolas Capens157ba262019-12-10 17:49:14 -050061 int yMin;
62 int yMax;
Nicolas Capens68a82382018-10-02 13:16:55 -040063
Nicolas Capens157ba262019-12-10 17:49:14 -050064 float4 xQuad;
65 float4 yQuad;
Nicolas Capens68a82382018-10-02 13:16:55 -040066
Nicolas Capens157ba262019-12-10 17:49:14 -050067 float pointCoordX;
68 float pointCoordY;
Marc-Antoine Desrochesb44162f2020-03-05 13:35:43 -050069 float pointSizeInv;
Alexis Hetu95b1db92019-05-27 17:40:39 -040070
Nicolas Capens157ba262019-12-10 17:49:14 -050071 PlaneEquation z;
72 PlaneEquation w;
73 PlaneEquation V[MAX_INTERFACE_COMPONENTS];
Nicolas Capens68a82382018-10-02 13:16:55 -040074
Nicolas Capens157ba262019-12-10 17:49:14 -050075 PlaneEquation clipDistance[MAX_CLIP_DISTANCES];
76 PlaneEquation cullDistance[MAX_CULL_DISTANCES];
Ben Clayton9ad035b2019-08-09 23:44:09 +010077
Nicolas Capens157ba262019-12-10 17:49:14 -050078 // Masks for two-sided stencil
79 int64_t clockwiseMask;
80 int64_t invClockwiseMask;
Nicolas Capens68a82382018-10-02 13:16:55 -040081
Nicolas Capens157ba262019-12-10 17:49:14 -050082 struct Span
83 {
84 unsigned short left;
85 unsigned short right;
Nicolas Capens68a82382018-10-02 13:16:55 -040086 };
Nicolas Capens157ba262019-12-10 17:49:14 -050087
88 // The rasterizer adds a zero length span to the top and bottom of the polygon to allow
89 // for 2x2 pixel processing. We need an even number of spans to keep accesses aligned.
90 Span outlineUnderflow[2];
91 Span outline[OUTLINE_RESOLUTION];
92 Span outlineOverflow[2];
93};
94
95} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -040096
Ben Claytonfccfc562019-12-17 20:37:31 +000097#endif // sw_Primitive_hpp