1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Utilities for clear values.
23 *//*--------------------------------------------------------------------*/
25 #include "vktPipelineClearUtil.hpp"
26 #include "vkImageUtil.hpp"
27 #include "tcuTextureUtil.hpp"
36 tcu::Vec4 defaultClearColor (const tcu::TextureFormat& format)
38 if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT)
39 return defaultClearColorUnorm();
42 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
43 return (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
47 tcu::IVec4 defaultClearColorInt (const tcu::TextureFormat& format)
49 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
50 const tcu::Vec4 color = (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
52 const tcu::IVec4 result ((deInt32)deFloatRound(color.x()), (deInt32)deFloatRound(color.y()),
53 (deInt32)deFloatRound(color.z()), (deInt32)deFloatRound(color.w()));
58 tcu::UVec4 defaultClearColorUint (const tcu::TextureFormat& format)
60 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
61 const tcu::Vec4 color = (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
63 const tcu::UVec4 result ((deUint32)deFloatRound(color.x()), (deUint32)deFloatRound(color.y()),
64 (deUint32)deFloatRound(color.z()), (deUint32)deFloatRound(color.w()));
69 tcu::Vec4 defaultClearColorUnorm (void)
71 return tcu::Vec4(0.39f, 0.58f, 0.93f, 1.0f);
74 float defaultClearDepth (void)
79 deUint32 defaultClearStencil (void)
84 VkClearDepthStencilValue defaultClearDepthStencilValue (void)
86 VkClearDepthStencilValue clearDepthStencilValue;
87 clearDepthStencilValue.depth = defaultClearDepth();
88 clearDepthStencilValue.stencil = defaultClearStencil();
90 return clearDepthStencilValue;
93 VkClearValue defaultClearValue (VkFormat clearFormat)
95 VkClearValue clearValue;
97 if (isDepthStencilFormat(clearFormat))
99 const VkClearDepthStencilValue dsValue = defaultClearDepthStencilValue();
100 clearValue.depthStencil.stencil = dsValue.stencil;
101 clearValue.depthStencil.depth = dsValue.depth;
105 const tcu::TextureFormat tcuClearFormat = mapVkFormat(clearFormat);
106 if (isUintFormat(clearFormat))
108 const tcu::UVec4 defaultColor = defaultClearColorUint(tcuClearFormat);
109 clearValue.color.uint32[0] = defaultColor.x();
110 clearValue.color.uint32[1] = defaultColor.y();
111 clearValue.color.uint32[2] = defaultColor.z();
112 clearValue.color.uint32[3] = defaultColor.w();
114 else if (isIntFormat(clearFormat))
116 const tcu::IVec4 defaultColor = defaultClearColorInt(tcuClearFormat);
117 clearValue.color.int32[0] = defaultColor.x();
118 clearValue.color.int32[1] = defaultColor.y();
119 clearValue.color.int32[2] = defaultColor.z();
120 clearValue.color.int32[3] = defaultColor.w();
124 const tcu::Vec4 defaultColor = defaultClearColor(tcuClearFormat);
125 clearValue.color.float32[0] = defaultColor.x();
126 clearValue.color.float32[1] = defaultColor.y();
127 clearValue.color.float32[2] = defaultColor.z();
128 clearValue.color.float32[3] = defaultColor.w();