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/Types.hpp" |
19 | #include "System/Math.hpp" |
20 | #include "Vulkan/VkConfig.h" |
21 | |
22 | namespace sw |
23 | { |
24 | struct Constants |
25 | { |
26 | Constants(); |
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 | |
74 | unsigned short sRGBtoLinear8_16[256]; |
75 | |
76 | unsigned short linearToSRGB12_16[4096]; |
77 | unsigned short sRGBtoLinear12_16[4096]; |
78 | |
79 | // Centroid parameters |
80 | float4 sampleX[4][16]; |
81 | float4 sampleY[4][16]; |
82 | float4 weight[16]; |
83 | |
84 | // Fragment offsets |
85 | int Xf[4]; |
86 | int Yf[4]; |
87 | |
88 | float4 X[4]; |
89 | float4 Y[4]; |
90 | |
91 | // VK_SAMPLE_COUNT_4_BIT |
92 | // https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#primsrast-multisampling |
93 | static constexpr float VkSampleLocations4[][2] = { |
94 | {0.375, 0.125}, |
95 | {0.875, 0.375}, |
96 | {0.125, 0.625}, |
97 | {0.625, 0.875}, |
98 | }; |
99 | |
100 | // Vulkan spec sample positions are relative to 0,0 in top left corner, with Y+ going down. |
101 | // Convert to our space, with 0,0 in center, and Y+ going up. |
102 | static constexpr float SampleLocationsX[4] = { |
103 | VkSampleLocations4[0][0] - 0.5f, |
104 | VkSampleLocations4[1][0] - 0.5f, |
105 | VkSampleLocations4[2][0] - 0.5f, |
106 | VkSampleLocations4[3][0] - 0.5f, |
107 | }; |
108 | |
109 | static constexpr float SampleLocationsY[4] = { |
110 | -(VkSampleLocations4[0][1] - 0.5f), |
111 | -(VkSampleLocations4[1][1] - 0.5f), |
112 | -(VkSampleLocations4[2][1] - 0.5f), |
113 | -(VkSampleLocations4[3][1] - 0.5f), |
114 | }; |
115 | |
116 | // Compute the yMin and yMax multisample offsets so that they are just |
117 | // large enough (+/- max range - epsilon) to include sample points |
118 | 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; |
119 | 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; |
120 | |
121 | dword maxX[16]; |
122 | dword maxY[16]; |
123 | dword maxZ[16]; |
124 | dword minX[16]; |
125 | dword minY[16]; |
126 | dword minZ[16]; |
127 | dword fini[16]; |
128 | |
129 | dword4 maxPos; |
130 | |
131 | float4 unscaleByte; |
132 | float4 unscaleSByte; |
133 | float4 unscaleShort; |
134 | float4 unscaleUShort; |
135 | float4 unscaleInt; |
136 | float4 unscaleUInt; |
137 | float4 unscaleFixed; |
138 | |
139 | float half2float[65536]; |
140 | }; |
141 | |
142 | extern Constants constants; |
143 | } |
144 | |
145 | #endif // sw_Constants_hpp |
146 | |