• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_Constants_hpp
16 #define sw_Constants_hpp
17 
18 #include "System/Math.hpp"
19 #include "System/Types.hpp"
20 #include "Vulkan/VkConfig.hpp"
21 
22 namespace sw {
23 
24 struct Constants
25 {
26 	static const Constants &Get();
27 
28 	unsigned int transposeBit0[16];
29 	unsigned int transposeBit1[16];
30 	unsigned int transposeBit2[16];
31 
32 	ushort4 cWeight[17];
33 	float4 uvWeight[17];
34 	float4 uvStart[17];
35 
36 	unsigned int occlusionCount[16];
37 
38 	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];
71 	dword2 mask10Q[16];   // 4 bit writemask -> A2B10G10R10 bit patterns, replicated 2x
72 	word4 mask5551Q[16];  // 4 bit writemask -> A1R5G5B5 bit patterns, replicated 4x
73 	dword4 mask11X[8];    // 3 bit writemask -> B10G11R11 bit patterns, replicated 4x
74 
75 	unsigned short sRGBtoLinearFF_FF00[256];
76 
77 	unsigned short linearToSRGB12_16[4096];
78 	unsigned short sRGBtoLinear12_16[4096];
79 
80 	// Centroid parameters
81 	float4 sampleX[4][16];
82 	float4 sampleY[4][16];
83 	float4 weight[16];
84 
85 	// Fragment offsets
86 	int Xf[4];
87 	int Yf[4];
88 
89 	float4 X[4];
90 	float4 Y[4];
91 
92 	// 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] = {
95 		{ 0.375, 0.125 },
96 		{ 0.875, 0.375 },
97 		{ 0.125, 0.625 },
98 		{ 0.625, 0.875 },
99 	};
100 
101 	// 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] = {
111 		VkSampleLocations4[0][1] - 0.5f,
112 		VkSampleLocations4[1][1] - 0.5f,
113 		VkSampleLocations4[2][1] - 0.5f,
114 		VkSampleLocations4[3][1] - 0.5f,
115 	};
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 	float4 unscaleByte;
131 	float4 unscaleSByte;
132 	float4 unscaleShort;
133 	float4 unscaleUShort;
134 	float4 unscaleInt;
135 	float4 unscaleUInt;
136 	float4 unscaleFixed;
137 
138 	float half2float[65536];
139 
140 private:
141 	Constants();
142 };
143 
144 }  // namespace sw
145 
146 #endif  // sw_Constants_hpp
147