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