Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 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 | |
Antonio Maiorano | ae022fa | 2019-10-07 12:57:19 -0400 | [diff] [blame] | 18 | #include "System/Math.hpp" |
Ben Clayton | bc1c067 | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 19 | #include "System/Types.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 20 | #include "Vulkan/VkConfig.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 21 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 22 | namespace sw { |
| 23 | |
| 24 | struct Constants |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 25 | { |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 26 | Constants(); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 27 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 28 | unsigned int transposeBit0[16]; |
| 29 | unsigned int transposeBit1[16]; |
| 30 | unsigned int transposeBit2[16]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 31 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 32 | ushort4 cWeight[17]; |
| 33 | float4 uvWeight[17]; |
| 34 | float4 uvStart[17]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 35 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 36 | unsigned int occlusionCount[16]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 37 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 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]; |
Ben Clayton | bc1c067 | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 71 | dword2 mask10Q[16]; // 4 bit writemask -> A2B10G10R10 bit patterns, replicated 2x |
| 72 | word4 mask5551Q[16]; // 4 bit writemask -> A1R5G5B5 bit patterns, replicated 4x |
Alexis Hetu | f97fb9d | 2019-12-17 14:40:19 -0500 | [diff] [blame] | 73 | dword4 mask11X[8]; // 3 bit writemask -> B10G11R11 bit patterns, replicated 4x |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 74 | |
Nicolas Capens | 2883de9 | 2020-01-27 14:58:14 -0500 | [diff] [blame] | 75 | unsigned short sRGBtoLinearFF_FF00[256]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 76 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 77 | unsigned short linearToSRGB12_16[4096]; |
| 78 | unsigned short sRGBtoLinear12_16[4096]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 79 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 80 | // Centroid parameters |
| 81 | float4 sampleX[4][16]; |
| 82 | float4 sampleY[4][16]; |
| 83 | float4 weight[16]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 84 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 85 | // Fragment offsets |
| 86 | int Xf[4]; |
| 87 | int Yf[4]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 88 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 89 | float4 X[4]; |
| 90 | float4 Y[4]; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 91 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 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] = { |
Ben Clayton | bc1c067 | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 95 | { 0.375, 0.125 }, |
| 96 | { 0.875, 0.375 }, |
| 97 | { 0.125, 0.625 }, |
| 98 | { 0.625, 0.875 }, |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 99 | }; |
| 100 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 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] = { |
Alexis Hetu | b9fc42d | 2020-01-23 17:00:58 -0500 | [diff] [blame] | 111 | VkSampleLocations4[0][1] - 0.5f, |
| 112 | VkSampleLocations4[1][1] - 0.5f, |
| 113 | VkSampleLocations4[2][1] - 0.5f, |
| 114 | VkSampleLocations4[3][1] - 0.5f, |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 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 | 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 | |
| 143 | extern Constants constants; |
| 144 | |
Ben Clayton | bc1c067 | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 145 | } // namespace sw |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 146 | |
Ben Clayton | bc1c067 | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 147 | #endif // sw_Constants_hpp |