blob: fff8b931a9ef477451f410dab244655e180eb0ff [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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#include "PixelProgram.hpp"
16
17#include "SamplerCore.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050018#include "Device/Primitive.hpp"
19#include "Device/Renderer.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040020
Nicolas Capens157ba262019-12-10 17:49:14 -050021namespace sw {
22
23// Union all cMask and return it as 4 booleans
24Int4 PixelProgram::maskAny(Int cMask[4]) const
Nicolas Capens68a82382018-10-02 13:16:55 -040025{
Nicolas Capens157ba262019-12-10 17:49:14 -050026 // See if at least 1 sample is used
27 Int maskUnion = cMask[0];
Nicolas Capens11cb8912020-01-14 00:24:05 -050028 for(auto i = 1u; i < state.multiSampleCount; i++)
Alexis Hetu920100c2019-07-15 17:25:02 -040029 {
Nicolas Capens157ba262019-12-10 17:49:14 -050030 maskUnion |= cMask[i];
31 }
Alexis Hetu920100c2019-07-15 17:25:02 -040032
Nicolas Capens157ba262019-12-10 17:49:14 -050033 // Convert to 4 booleans
34 Int4 laneBits = Int4(1, 2, 4, 8);
35 Int4 laneShiftsToMSB = Int4(31, 30, 29, 28);
36 Int4 mask(maskUnion);
37 mask = ((mask & laneBits) << laneShiftsToMSB) >> Int4(31);
38 return mask;
39}
40
41// Union all cMask/sMask/zMask and return it as 4 booleans
42Int4 PixelProgram::maskAny(Int cMask[4], Int sMask[4], Int zMask[4]) const
43{
44 // See if at least 1 sample is used
45 Int maskUnion = cMask[0] & sMask[0] & zMask[0];
Nicolas Capens11cb8912020-01-14 00:24:05 -050046 for(auto i = 1u; i < state.multiSampleCount; i++)
Nicolas Capens157ba262019-12-10 17:49:14 -050047 {
48 maskUnion |= (cMask[i] & sMask[i] & zMask[i]);
49 }
50
51 // Convert to 4 booleans
52 Int4 laneBits = Int4(1, 2, 4, 8);
53 Int4 laneShiftsToMSB = Int4(31, 30, 29, 28);
54 Int4 mask(maskUnion);
55 mask = ((mask & laneBits) << laneShiftsToMSB) >> Int4(31);
56 return mask;
57}
58
Ben Claytonbc1c067be2019-12-17 20:37:37 +000059void PixelProgram::setBuiltins(Int &x, Int &y, Float4 (&z)[4], Float4 &w, Int cMask[4])
Nicolas Capens157ba262019-12-10 17:49:14 -050060{
61 routine.setImmutableInputBuiltins(spirvShader);
62
Ben Clayton5beaef92019-12-03 12:23:35 +000063 // TODO(b/146486064): Consider only assigning these to the SpirvRoutine iff
64 // they are ever going to be read.
65 routine.fragCoord[0] = SIMD::Float(Float(x)) + SIMD::Float(0.5f, 1.5f, 0.5f, 1.5f);
66 routine.fragCoord[1] = SIMD::Float(Float(y)) + SIMD::Float(0.5f, 0.5f, 1.5f, 1.5f);
67 routine.fragCoord[2] = z[0]; // sample 0
68 routine.fragCoord[3] = w;
69 routine.pointCoord[0] = SIMD::Float(0.5f) +
70 SIMD::Float(Float(x) - (*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordX))));
71 routine.pointCoord[1] = SIMD::Float(0.5f) +
72 SIMD::Float(Float(y) - (*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordY))));
73 routine.invocationsPerSubgroup = SIMD::Width;
74 routine.helperInvocation = ~maskAny(cMask);
75 routine.windowSpacePosition[0] = x + SIMD::Int(0, 1, 0, 1);
76 routine.windowSpacePosition[1] = y + SIMD::Int(0, 0, 1, 1);
77 routine.viewID = *Pointer<Int>(data + OFFSET(DrawData, viewID));
78
Ben Claytonbc1c067be2019-12-17 20:37:37 +000079 routine.setInputBuiltin(spirvShader, spv::BuiltInViewIndex, [&](const SpirvShader::BuiltinMapping &builtin, Array<SIMD::Float> &value) {
Nicolas Capens157ba262019-12-10 17:49:14 -050080 assert(builtin.SizeInComponents == 1);
Ben Clayton5beaef92019-12-03 12:23:35 +000081 value[builtin.FirstComponent] = As<SIMD::Float>(SIMD::Int(routine.viewID));
Nicolas Capens157ba262019-12-10 17:49:14 -050082 });
83
Ben Claytonbc1c067be2019-12-17 20:37:37 +000084 routine.setInputBuiltin(spirvShader, spv::BuiltInFragCoord, [&](const SpirvShader::BuiltinMapping &builtin, Array<SIMD::Float> &value) {
Nicolas Capens157ba262019-12-10 17:49:14 -050085 assert(builtin.SizeInComponents == 4);
Ben Clayton5beaef92019-12-03 12:23:35 +000086 value[builtin.FirstComponent + 0] = routine.fragCoord[0];
87 value[builtin.FirstComponent + 1] = routine.fragCoord[1];
88 value[builtin.FirstComponent + 2] = routine.fragCoord[2];
89 value[builtin.FirstComponent + 3] = routine.fragCoord[3];
Nicolas Capens157ba262019-12-10 17:49:14 -050090 });
91
Ben Claytonbc1c067be2019-12-17 20:37:37 +000092 routine.setInputBuiltin(spirvShader, spv::BuiltInPointCoord, [&](const SpirvShader::BuiltinMapping &builtin, Array<SIMD::Float> &value) {
Nicolas Capens157ba262019-12-10 17:49:14 -050093 assert(builtin.SizeInComponents == 2);
Ben Claytonbc1c067be2019-12-17 20:37:37 +000094 value[builtin.FirstComponent + 0] = SIMD::Float(0.5f, 1.5f, 0.5f, 1.5f) +
95 SIMD::Float(Float(x) - (*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordX))));
96 value[builtin.FirstComponent + 1] = SIMD::Float(0.5f, 0.5f, 1.5f, 1.5f) +
97 SIMD::Float(Float(y) - (*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordY))));
Nicolas Capens157ba262019-12-10 17:49:14 -050098 });
99
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000100 routine.setInputBuiltin(spirvShader, spv::BuiltInSubgroupSize, [&](const SpirvShader::BuiltinMapping &builtin, Array<SIMD::Float> &value) {
Nicolas Capens157ba262019-12-10 17:49:14 -0500101 assert(builtin.SizeInComponents == 1);
102 value[builtin.FirstComponent] = As<SIMD::Float>(SIMD::Int(SIMD::Width));
103 });
104
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000105 routine.setInputBuiltin(spirvShader, spv::BuiltInHelperInvocation, [&](const SpirvShader::BuiltinMapping &builtin, Array<SIMD::Float> &value) {
Nicolas Capens157ba262019-12-10 17:49:14 -0500106 assert(builtin.SizeInComponents == 1);
Ben Clayton5beaef92019-12-03 12:23:35 +0000107 value[builtin.FirstComponent] = As<SIMD::Float>(routine.helperInvocation);
Nicolas Capens157ba262019-12-10 17:49:14 -0500108 });
Nicolas Capens157ba262019-12-10 17:49:14 -0500109}
110
111void PixelProgram::applyShader(Int cMask[4], Int sMask[4], Int zMask[4])
112{
113 routine.descriptorSets = data + OFFSET(DrawData, descriptorSets);
114 routine.descriptorDynamicOffsets = data + OFFSET(DrawData, descriptorDynamicOffsets);
115 routine.pushConstants = data + OFFSET(DrawData, pushConstants);
116 routine.constants = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, constants));
117
118 auto it = spirvShader->inputBuiltins.find(spv::BuiltInFrontFacing);
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500119 if(it != spirvShader->inputBuiltins.end())
Nicolas Capens157ba262019-12-10 17:49:14 -0500120 {
121 ASSERT(it->second.SizeInComponents == 1);
122 auto frontFacing = Int4(*Pointer<Int>(primitive + OFFSET(Primitive, clockwiseMask)));
123 routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<Float4>(frontFacing);
124 }
125
126 it = spirvShader->inputBuiltins.find(spv::BuiltInSampleMask);
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500127 if(it != spirvShader->inputBuiltins.end())
Nicolas Capens157ba262019-12-10 17:49:14 -0500128 {
129 static_assert(SIMD::Width == 4, "Expects SIMD width to be 4");
Alexis Hetu920100c2019-07-15 17:25:02 -0400130 Int4 laneBits = Int4(1, 2, 4, 8);
Nicolas Capens157ba262019-12-10 17:49:14 -0500131
132 Int4 inputSampleMask = Int4(1) & CmpNEQ(Int4(cMask[0]) & laneBits, Int4(0));
Nicolas Capens11cb8912020-01-14 00:24:05 -0500133 for(auto i = 1u; i < state.multiSampleCount; i++)
Nicolas Capens157ba262019-12-10 17:49:14 -0500134 {
135 inputSampleMask |= Int4(1 << i) & CmpNEQ(Int4(cMask[i]) & laneBits, Int4(0));
136 }
137
138 routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<Float4>(inputSampleMask);
139 // Sample mask input is an array, as the spec contemplates MSAA levels higher than 32.
140 // Fill any non-zero indices with 0.
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500141 for(auto i = 1u; i < it->second.SizeInComponents; i++)
Nicolas Capens157ba262019-12-10 17:49:14 -0500142 routine.getVariable(it->second.Id)[it->second.FirstComponent + i] = Float4(0);
Alexis Hetu920100c2019-07-15 17:25:02 -0400143 }
144
Nicolas Capens157ba262019-12-10 17:49:14 -0500145 // Note: all lanes initially active to facilitate derivatives etc. Actual coverage is
146 // handled separately, through the cMask.
147 auto activeLaneMask = SIMD::Int(0xFFFFFFFF);
148 auto storesAndAtomicsMask = maskAny(cMask, sMask, zMask);
149 routine.killMask = 0;
Alexis Hetu920100c2019-07-15 17:25:02 -0400150
Nicolas Capens157ba262019-12-10 17:49:14 -0500151 spirvShader->emit(&routine, activeLaneMask, storesAndAtomicsMask, descriptorSets);
152 spirvShader->emitEpilog(&routine);
153
154 for(int i = 0; i < RENDERTARGETS; i++)
155 {
156 c[i].x = routine.outputs[i * 4];
157 c[i].y = routine.outputs[i * 4 + 1];
158 c[i].z = routine.outputs[i * 4 + 2];
159 c[i].w = routine.outputs[i * 4 + 3];
Alexis Hetu920100c2019-07-15 17:25:02 -0400160 }
161
Nicolas Capens157ba262019-12-10 17:49:14 -0500162 clampColor(c);
163
164 if(spirvShader->getModes().ContainsKill)
Nicolas Capens68a82382018-10-02 13:16:55 -0400165 {
Nicolas Capens11cb8912020-01-14 00:24:05 -0500166 for(auto i = 0u; i < state.multiSampleCount; i++)
Chris Forbes02d4c0d2019-08-21 12:04:34 -0700167 {
Nicolas Capens157ba262019-12-10 17:49:14 -0500168 cMask[i] &= ~routine.killMask;
Nicolas Capens68a82382018-10-02 13:16:55 -0400169 }
170 }
171
Nicolas Capens157ba262019-12-10 17:49:14 -0500172 it = spirvShader->outputBuiltins.find(spv::BuiltInSampleMask);
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500173 if(it != spirvShader->outputBuiltins.end())
Nicolas Capens68a82382018-10-02 13:16:55 -0400174 {
Nicolas Capens157ba262019-12-10 17:49:14 -0500175 auto outputSampleMask = As<SIMD::Int>(routine.getVariable(it->second.Id)[it->second.FirstComponent]);
176
Nicolas Capens11cb8912020-01-14 00:24:05 -0500177 for(auto i = 0u; i < state.multiSampleCount; i++)
Nicolas Capens68a82382018-10-02 13:16:55 -0400178 {
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000179 cMask[i] &= SignMask(CmpNEQ(outputSampleMask & SIMD::Int(1 << i), SIMD::Int(0)));
Nicolas Capens68a82382018-10-02 13:16:55 -0400180 }
181 }
182
Nicolas Capens157ba262019-12-10 17:49:14 -0500183 it = spirvShader->outputBuiltins.find(spv::BuiltInFragDepth);
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500184 if(it != spirvShader->outputBuiltins.end())
Nicolas Capens68a82382018-10-02 13:16:55 -0400185 {
Nicolas Capens157ba262019-12-10 17:49:14 -0500186 oDepth = Min(Max(routine.getVariable(it->second.Id)[it->second.FirstComponent], Float4(0.0f)), Float4(1.0f));
Nicolas Capens68a82382018-10-02 13:16:55 -0400187 }
Nicolas Capens68a82382018-10-02 13:16:55 -0400188}
Nicolas Capens157ba262019-12-10 17:49:14 -0500189
190Bool PixelProgram::alphaTest(Int cMask[4])
191{
192 if(!state.alphaToCoverage)
193 {
194 return true;
195 }
196
197 alphaToCoverage(cMask, c[0].w);
198
199 Int pass = cMask[0];
200
Nicolas Capens11cb8912020-01-14 00:24:05 -0500201 for(unsigned int q = 1; q < state.multiSampleCount; q++)
Nicolas Capens157ba262019-12-10 17:49:14 -0500202 {
203 pass = pass | cMask[q];
204 }
205
206 return pass != 0x0;
207}
208
209void PixelProgram::rasterOperation(Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4])
210{
211 for(int index = 0; index < RENDERTARGETS; index++)
212 {
213 if(!state.colorWriteActive(index))
214 {
215 continue;
216 }
217
218 auto format = state.targetFormat[index];
219 switch(format)
220 {
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000221 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
222 case VK_FORMAT_R5G6B5_UNORM_PACK16:
223 case VK_FORMAT_B8G8R8A8_UNORM:
224 case VK_FORMAT_B8G8R8A8_SRGB:
225 case VK_FORMAT_R8G8B8A8_UNORM:
226 case VK_FORMAT_R8G8B8A8_SRGB:
227 case VK_FORMAT_R8G8_UNORM:
228 case VK_FORMAT_R8_UNORM:
229 case VK_FORMAT_R16G16_UNORM:
230 case VK_FORMAT_R16G16B16A16_UNORM:
231 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
232 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
233 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
Alexis Hetub8a61bf2020-01-09 15:26:34 -0500234 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
Nicolas Capens11cb8912020-01-14 00:24:05 -0500235 for(unsigned int q = 0; q < state.multiSampleCount; q++)
Nicolas Capens157ba262019-12-10 17:49:14 -0500236 {
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000237 if(state.multiSampleMask & (1 << q))
238 {
239 Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
240 Vector4s color;
Nicolas Capens157ba262019-12-10 17:49:14 -0500241
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000242 color.x = convertFixed16(c[index].x, false);
243 color.y = convertFixed16(c[index].y, false);
244 color.z = convertFixed16(c[index].z, false);
245 color.w = convertFixed16(c[index].w, false);
Nicolas Capens157ba262019-12-10 17:49:14 -0500246
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000247 alphaBlend(index, buffer, color, x);
248 writeColor(index, buffer, x, color, sMask[q], zMask[q], cMask[q]);
249 }
Nicolas Capens157ba262019-12-10 17:49:14 -0500250 }
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000251 break;
252 case VK_FORMAT_R16_SFLOAT:
253 case VK_FORMAT_R16G16_SFLOAT:
254 case VK_FORMAT_R16G16B16A16_SFLOAT:
255 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
256 case VK_FORMAT_R32_SFLOAT:
257 case VK_FORMAT_R32G32_SFLOAT:
258 case VK_FORMAT_R32G32B32A32_SFLOAT:
259 case VK_FORMAT_R32_SINT:
260 case VK_FORMAT_R32G32_SINT:
261 case VK_FORMAT_R32G32B32A32_SINT:
262 case VK_FORMAT_R32_UINT:
263 case VK_FORMAT_R32G32_UINT:
264 case VK_FORMAT_R32G32B32A32_UINT:
265 case VK_FORMAT_R16_SINT:
266 case VK_FORMAT_R16G16_SINT:
267 case VK_FORMAT_R16G16B16A16_SINT:
268 case VK_FORMAT_R16_UINT:
269 case VK_FORMAT_R16G16_UINT:
270 case VK_FORMAT_R16G16B16A16_UINT:
271 case VK_FORMAT_R8_SINT:
272 case VK_FORMAT_R8G8_SINT:
273 case VK_FORMAT_R8G8B8A8_SINT:
274 case VK_FORMAT_R8_UINT:
275 case VK_FORMAT_R8G8_UINT:
276 case VK_FORMAT_R8G8B8A8_UINT:
277 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
278 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
279 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
Alexis Hetub8a61bf2020-01-09 15:26:34 -0500280 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
Nicolas Capens11cb8912020-01-14 00:24:05 -0500281 for(unsigned int q = 0; q < state.multiSampleCount; q++)
Nicolas Capens157ba262019-12-10 17:49:14 -0500282 {
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000283 if(state.multiSampleMask & (1 << q))
284 {
285 Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
286 Vector4f color = c[index];
Nicolas Capens157ba262019-12-10 17:49:14 -0500287
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000288 alphaBlend(index, buffer, color, x);
289 writeColor(index, buffer, x, color, sMask[q], zMask[q], cMask[q]);
290 }
Nicolas Capens157ba262019-12-10 17:49:14 -0500291 }
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000292 break;
293 default:
Nicolas Capens865f8892020-01-21 14:27:10 -0500294 UNSUPPORTED("VkFormat: %d", int(format));
Nicolas Capens157ba262019-12-10 17:49:14 -0500295 }
296 }
297}
298
299void PixelProgram::clampColor(Vector4f oC[RENDERTARGETS])
300{
301 for(int index = 0; index < RENDERTARGETS; index++)
302 {
303 if(!state.colorWriteActive(index) && !(index == 0 && state.alphaToCoverage))
304 {
305 continue;
306 }
307
308 switch(state.targetFormat[index])
309 {
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000310 case VK_FORMAT_UNDEFINED:
311 break;
312 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
313 case VK_FORMAT_R5G6B5_UNORM_PACK16:
314 case VK_FORMAT_B8G8R8A8_UNORM:
315 case VK_FORMAT_B8G8R8A8_SRGB:
316 case VK_FORMAT_R8G8B8A8_UNORM:
317 case VK_FORMAT_R8G8B8A8_SRGB:
318 case VK_FORMAT_R8G8_UNORM:
319 case VK_FORMAT_R8_UNORM:
320 case VK_FORMAT_R16G16_UNORM:
321 case VK_FORMAT_R16G16B16A16_UNORM:
322 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
323 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
324 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
Alexis Hetub8a61bf2020-01-09 15:26:34 -0500325 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000326 oC[index].x = Max(oC[index].x, Float4(0.0f));
327 oC[index].x = Min(oC[index].x, Float4(1.0f));
328 oC[index].y = Max(oC[index].y, Float4(0.0f));
329 oC[index].y = Min(oC[index].y, Float4(1.0f));
330 oC[index].z = Max(oC[index].z, Float4(0.0f));
331 oC[index].z = Min(oC[index].z, Float4(1.0f));
332 oC[index].w = Max(oC[index].w, Float4(0.0f));
333 oC[index].w = Min(oC[index].w, Float4(1.0f));
334 break;
335 case VK_FORMAT_R32_SFLOAT:
336 case VK_FORMAT_R32G32_SFLOAT:
337 case VK_FORMAT_R32G32B32A32_SFLOAT:
338 case VK_FORMAT_R32_SINT:
339 case VK_FORMAT_R32G32_SINT:
340 case VK_FORMAT_R32G32B32A32_SINT:
341 case VK_FORMAT_R32_UINT:
342 case VK_FORMAT_R32G32_UINT:
343 case VK_FORMAT_R32G32B32A32_UINT:
344 case VK_FORMAT_R16_SFLOAT:
345 case VK_FORMAT_R16G16_SFLOAT:
346 case VK_FORMAT_R16G16B16A16_SFLOAT:
347 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
348 case VK_FORMAT_R16_SINT:
349 case VK_FORMAT_R16G16_SINT:
350 case VK_FORMAT_R16G16B16A16_SINT:
351 case VK_FORMAT_R16_UINT:
352 case VK_FORMAT_R16G16_UINT:
353 case VK_FORMAT_R16G16B16A16_UINT:
354 case VK_FORMAT_R8_SINT:
355 case VK_FORMAT_R8G8_SINT:
356 case VK_FORMAT_R8G8B8A8_SINT:
357 case VK_FORMAT_R8_UINT:
358 case VK_FORMAT_R8G8_UINT:
359 case VK_FORMAT_R8G8B8A8_UINT:
360 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
361 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
362 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
Alexis Hetub8a61bf2020-01-09 15:26:34 -0500363 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000364 break;
365 default:
Nicolas Capens865f8892020-01-21 14:27:10 -0500366 UNSUPPORTED("VkFormat: %d", int(state.targetFormat[index]));
Nicolas Capens157ba262019-12-10 17:49:14 -0500367 }
368 }
369}
370
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000371Float4 PixelProgram::linearToSRGB(const Float4 &x) // Approximates x^(1.0/2.2)
Nicolas Capens157ba262019-12-10 17:49:14 -0500372{
373 Float4 sqrtx = Rcp_pp(RcpSqrt_pp(x));
374 Float4 sRGB = sqrtx * Float4(1.14f) - x * Float4(0.14f);
375
376 return Min(Max(sRGB, Float4(0.0f)), Float4(1.0f));
377}
378
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000379} // namespace sw