blob: e7022e3235f2c0052de4f74797bf75d81e9a8845 [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_Constants_hpp
16#define sw_Constants_hpp
17
Antonio Maioranoae022fa2019-10-07 12:57:19 -040018#include "System/Math.hpp"
Ben Claytonbc1c0672019-12-17 20:37:37 +000019#include "System/Types.hpp"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040020#include "Vulkan/VkConfig.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040021
Nicolas Capens157ba262019-12-10 17:49:14 -050022namespace sw {
23
24struct Constants
Nicolas Capens68a82382018-10-02 13:16:55 -040025{
Nicolas Capens157ba262019-12-10 17:49:14 -050026 Constants();
Nicolas Capens68a82382018-10-02 13:16:55 -040027
Nicolas Capens157ba262019-12-10 17:49:14 -050028 unsigned int transposeBit0[16];
29 unsigned int transposeBit1[16];
30 unsigned int transposeBit2[16];
Nicolas Capens68a82382018-10-02 13:16:55 -040031
Nicolas Capens157ba262019-12-10 17:49:14 -050032 ushort4 cWeight[17];
33 float4 uvWeight[17];
34 float4 uvStart[17];
Nicolas Capens68a82382018-10-02 13:16:55 -040035
Nicolas Capens157ba262019-12-10 17:49:14 -050036 unsigned int occlusionCount[16];
Nicolas Capens68a82382018-10-02 13:16:55 -040037
Nicolas Capens157ba262019-12-10 17:49:14 -050038 byte8 maskB4Q[16];
39 byte8 invMaskB4Q[16];
40 word4 maskW4Q[16];
41 word4 invMaskW4Q[16];
42 dword4 maskD4X[16];
43 dword4 invMaskD4X[16];
44 qword maskQ0Q[16];
45 qword maskQ1Q[16];
46 qword maskQ2Q[16];
47 qword maskQ3Q[16];
48 qword invMaskQ0Q[16];
49 qword invMaskQ1Q[16];
50 qword invMaskQ2Q[16];
51 qword invMaskQ3Q[16];
52 dword4 maskX0X[16];
53 dword4 maskX1X[16];
54 dword4 maskX2X[16];
55 dword4 maskX3X[16];
56 dword4 invMaskX0X[16];
57 dword4 invMaskX1X[16];
58 dword4 invMaskX2X[16];
59 dword4 invMaskX3X[16];
60 dword2 maskD01Q[16];
61 dword2 maskD23Q[16];
62 dword2 invMaskD01Q[16];
63 dword2 invMaskD23Q[16];
64 qword2 maskQ01X[16];
65 qword2 maskQ23X[16];
66 qword2 invMaskQ01X[16];
67 qword2 invMaskQ23X[16];
68 word4 maskW01Q[4];
69 dword4 maskD01X[4];
70 word4 mask565Q[8];
Ben Claytonbc1c0672019-12-17 20:37:37 +000071 dword2 mask10Q[16]; // 4 bit writemask -> A2B10G10R10 bit patterns, replicated 2x
72 word4 mask5551Q[16]; // 4 bit writemask -> A1R5G5B5 bit patterns, replicated 4x
Alexis Hetuf97fb9d2019-12-17 14:40:19 -050073 dword4 mask11X[8]; // 3 bit writemask -> B10G11R11 bit patterns, replicated 4x
Nicolas Capens68a82382018-10-02 13:16:55 -040074
Nicolas Capens2883de92020-01-27 14:58:14 -050075 unsigned short sRGBtoLinearFF_FF00[256];
Nicolas Capens68a82382018-10-02 13:16:55 -040076
Nicolas Capens157ba262019-12-10 17:49:14 -050077 unsigned short linearToSRGB12_16[4096];
78 unsigned short sRGBtoLinear12_16[4096];
Nicolas Capens68a82382018-10-02 13:16:55 -040079
Nicolas Capens157ba262019-12-10 17:49:14 -050080 // Centroid parameters
81 float4 sampleX[4][16];
82 float4 sampleY[4][16];
83 float4 weight[16];
Nicolas Capens68a82382018-10-02 13:16:55 -040084
Nicolas Capens157ba262019-12-10 17:49:14 -050085 // Fragment offsets
86 int Xf[4];
87 int Yf[4];
Nicolas Capens68a82382018-10-02 13:16:55 -040088
Nicolas Capens157ba262019-12-10 17:49:14 -050089 float4 X[4];
90 float4 Y[4];
Nicolas Capens68a82382018-10-02 13:16:55 -040091
Nicolas Capens157ba262019-12-10 17:49:14 -050092 // VK_SAMPLE_COUNT_4_BIT
93 // https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#primsrast-multisampling
94 static constexpr float VkSampleLocations4[][2] = {
Ben Claytonbc1c0672019-12-17 20:37:37 +000095 { 0.375, 0.125 },
96 { 0.875, 0.375 },
97 { 0.125, 0.625 },
98 { 0.625, 0.875 },
Nicolas Capens68a82382018-10-02 13:16:55 -040099 };
100
Nicolas Capens157ba262019-12-10 17:49:14 -0500101 // Vulkan spec sample positions are relative to 0,0 in top left corner, with Y+ going down.
102 // Convert to our space, with 0,0 in center, and Y+ going up.
103 static constexpr float SampleLocationsX[4] = {
104 VkSampleLocations4[0][0] - 0.5f,
105 VkSampleLocations4[1][0] - 0.5f,
106 VkSampleLocations4[2][0] - 0.5f,
107 VkSampleLocations4[3][0] - 0.5f,
108 };
109
110 static constexpr float SampleLocationsY[4] = {
Alexis Hetub9fc42d2020-01-23 17:00:58 -0500111 VkSampleLocations4[0][1] - 0.5f,
112 VkSampleLocations4[1][1] - 0.5f,
113 VkSampleLocations4[2][1] - 0.5f,
114 VkSampleLocations4[3][1] - 0.5f,
Nicolas Capens157ba262019-12-10 17:49:14 -0500115 };
116
117 // Compute the yMin and yMax multisample offsets so that they are just
118 // large enough (+/- max range - epsilon) to include sample points
119 static constexpr int yMinMultiSampleOffset = sw::toFixedPoint(1, vk::SUBPIXEL_PRECISION_BITS) - sw::toFixedPoint(sw::max(SampleLocationsY[0], SampleLocationsY[1], SampleLocationsY[2], SampleLocationsY[3]), vk::SUBPIXEL_PRECISION_BITS) - 1;
120 static constexpr int yMaxMultiSampleOffset = sw::toFixedPoint(1, vk::SUBPIXEL_PRECISION_BITS) + sw::toFixedPoint(sw::max(SampleLocationsY[0], SampleLocationsY[1], SampleLocationsY[2], SampleLocationsY[3]), vk::SUBPIXEL_PRECISION_BITS) - 1;
121
122 dword maxX[16];
123 dword maxY[16];
124 dword maxZ[16];
125 dword minX[16];
126 dword minY[16];
127 dword minZ[16];
128 dword fini[16];
129
130 dword4 maxPos;
131
132 float4 unscaleByte;
133 float4 unscaleSByte;
134 float4 unscaleShort;
135 float4 unscaleUShort;
136 float4 unscaleInt;
137 float4 unscaleUInt;
138 float4 unscaleFixed;
139
140 float half2float[65536];
141};
142
143extern Constants constants;
144
Ben Claytonbc1c0672019-12-17 20:37:37 +0000145} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -0400146
Ben Claytonbc1c0672019-12-17 20:37:37 +0000147#endif // sw_Constants_hpp