1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 *//*!
21 * \file
22 * \brief Utilities for clear values.
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktPipelineClearUtil.hpp"
26 #include "vkImageUtil.hpp"
27 #include "tcuTextureUtil.hpp"
28
29 namespace vkt
30 {
31 namespace pipeline
32 {
33
34 using namespace vk;
35
defaultClearColor(const tcu::TextureFormat & format)36 tcu::Vec4 defaultClearColor (const tcu::TextureFormat& format)
37 {
38 if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT)
39 return defaultClearColorUnorm();
40 else
41 {
42 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
43 return (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
44 }
45 }
46
defaultClearColorInt(const tcu::TextureFormat & format)47 tcu::IVec4 defaultClearColorInt (const tcu::TextureFormat& format)
48 {
49 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
50 const tcu::Vec4 color = (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
51
52 const tcu::IVec4 result ((deInt32)deFloatRound(color.x()), (deInt32)deFloatRound(color.y()),
53 (deInt32)deFloatRound(color.z()), (deInt32)deFloatRound(color.w()));
54
55 return result;
56 }
57
defaultClearColorUint(const tcu::TextureFormat & format)58 tcu::UVec4 defaultClearColorUint (const tcu::TextureFormat& format)
59 {
60 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
61 const tcu::Vec4 color = (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
62
63 const tcu::UVec4 result ((deUint32)deFloatRound(color.x()), (deUint32)deFloatRound(color.y()),
64 (deUint32)deFloatRound(color.z()), (deUint32)deFloatRound(color.w()));
65
66 return result;
67 }
68
defaultClearColorUnorm(void)69 tcu::Vec4 defaultClearColorUnorm (void)
70 {
71 return tcu::Vec4(0.39f, 0.58f, 0.93f, 1.0f);
72 }
73
defaultClearDepth(void)74 float defaultClearDepth (void)
75 {
76 return 1.0f;
77 }
78
defaultClearStencil(void)79 deUint32 defaultClearStencil (void)
80 {
81 return 0;
82 }
83
defaultClearDepthStencilValue(void)84 VkClearDepthStencilValue defaultClearDepthStencilValue (void)
85 {
86 VkClearDepthStencilValue clearDepthStencilValue;
87 clearDepthStencilValue.depth = defaultClearDepth();
88 clearDepthStencilValue.stencil = defaultClearStencil();
89
90 return clearDepthStencilValue;
91 }
92
defaultClearValue(VkFormat clearFormat)93 VkClearValue defaultClearValue (VkFormat clearFormat)
94 {
95 VkClearValue clearValue;
96
97 if (isDepthStencilFormat(clearFormat))
98 {
99 const VkClearDepthStencilValue dsValue = defaultClearDepthStencilValue();
100 clearValue.depthStencil.stencil = dsValue.stencil;
101 clearValue.depthStencil.depth = dsValue.depth;
102 }
103 else
104 {
105 const tcu::TextureFormat tcuClearFormat = mapVkFormat(clearFormat);
106 if (isUintFormat(clearFormat))
107 {
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();
113 }
114 else if (isIntFormat(clearFormat))
115 {
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();
121 }
122 else
123 {
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();
129 }
130 }
131
132 return clearValue;
133 }
134
135 } // pipeline
136 } // vkt
137