xref: /aosp_15_r20/external/swiftshader/src/Pipeline/Constants.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
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 // VK_SAMPLE_COUNT_4_BIT
25 // https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#primsrast-multisampling
26 static constexpr float VkSampleLocations4[][2] = {
27 	{ 0.375, 0.125 },
28 	{ 0.875, 0.375 },
29 	{ 0.125, 0.625 },
30 	{ 0.625, 0.875 },
31 };
32 
33 // Vulkan spec sample positions are relative to 0,0 in top left corner, with Y+ going down.
34 // Convert to our space, with 0,0 in center, and Y+ going up.
35 static constexpr float SampleLocationsX[4] = {
36 	VkSampleLocations4[0][0] - 0.5f,
37 	VkSampleLocations4[1][0] - 0.5f,
38 	VkSampleLocations4[2][0] - 0.5f,
39 	VkSampleLocations4[3][0] - 0.5f,
40 };
41 
42 static constexpr float SampleLocationsY[4] = {
43 	VkSampleLocations4[0][1] - 0.5f,
44 	VkSampleLocations4[1][1] - 0.5f,
45 	VkSampleLocations4[2][1] - 0.5f,
46 	VkSampleLocations4[3][1] - 0.5f,
47 };
48 
49 // Compute the yMin and yMax multisample offsets so that they are just
50 // large enough (+/- max range - epsilon) to include sample points
51 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;
52 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;
53 
54 struct Constants
55 {
56 	Constants();
57 
58 	unsigned int transposeBit0[16];
59 	unsigned int transposeBit1[16];
60 	unsigned int transposeBit2[16];
61 
62 	ushort4 cWeight[17];
63 	float4 uvWeight[17];
64 	float4 uvStart[17];
65 
66 	unsigned int occlusionCount[16];
67 
68 	byte8 maskB4Q[16];
69 	byte8 invMaskB4Q[16];
70 	word4 maskW4Q[16];
71 	word4 invMaskW4Q[16];
72 	dword4 maskD4X[16];
73 	dword4 invMaskD4X[16];
74 	qword maskQ0Q[16];
75 	qword maskQ1Q[16];
76 	qword maskQ2Q[16];
77 	qword maskQ3Q[16];
78 	qword invMaskQ0Q[16];
79 	qword invMaskQ1Q[16];
80 	qword invMaskQ2Q[16];
81 	qword invMaskQ3Q[16];
82 	dword4 maskX0X[16];
83 	dword4 maskX1X[16];
84 	dword4 maskX2X[16];
85 	dword4 maskX3X[16];
86 	dword4 invMaskX0X[16];
87 	dword4 invMaskX1X[16];
88 	dword4 invMaskX2X[16];
89 	dword4 invMaskX3X[16];
90 	dword2 maskD01Q[16];
91 	dword2 maskD23Q[16];
92 	dword2 invMaskD01Q[16];
93 	dword2 invMaskD23Q[16];
94 	qword2 maskQ01X[16];
95 	qword2 maskQ23X[16];
96 	qword2 invMaskQ01X[16];
97 	qword2 invMaskQ23X[16];
98 	word4 maskW01Q[4];
99 	dword4 maskD01X[4];
100 	word4 mask565Q[8];
101 	dword2 mask10Q[16];       // 4 bit writemask -> A2B10G10R10 bit patterns, replicated 2x
102 	word4 mask5551Q[16];      // 4 bit writemask -> A1R5G5B5 bit patterns, replicated 4x
103 	word4 maskr5g5b5a1Q[16];  // 4 bit writemask -> R5G5B5A1 bit patterns, replicated 4x
104 	word4 maskb5g5r5a1Q[16];  // 4 bit writemask -> B5G5R5A1 bit patterns, replicated 4x
105 	word4 mask4rgbaQ[16];     // 4 bit writemask -> R4G4B4A4 bit patterns, replicated 4x
106 	word4 mask4argbQ[16];     // 4 bit writemask -> A4R4G4B4 bit patterns, replicated 4x
107 	dword4 mask11X[8];        // 3 bit writemask -> B10G11R11 bit patterns, replicated 4x
108 
109 	unsigned short sRGBtoLinearFF_FF00[256];
110 
111 	// Centroid parameters
112 	float4 sampleX[4][16];
113 	float4 sampleY[4][16];
114 	float4 weight[16];
115 
116 	// Fragment offsets
117 	int Xf[4];
118 	int Yf[4];
119 
120 	const float SampleLocationsX[4] = {
121 		sw::SampleLocationsX[0],
122 		sw::SampleLocationsX[1],
123 		sw::SampleLocationsX[2],
124 		sw::SampleLocationsX[3],
125 	};
126 
127 	const float SampleLocationsY[4] = {
128 		sw::SampleLocationsY[0],
129 		sw::SampleLocationsY[1],
130 		sw::SampleLocationsY[2],
131 		sw::SampleLocationsY[3],
132 	};
133 
134 	float half2float[65536];
135 };
136 
137 }  // namespace sw
138 
139 #endif  // sw_Constants_hpp
140