1c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim/*------------------------------------------------------------------------
2c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * Vulkan Conformance Tests
3c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * ------------------------
4c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *
5c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * Copyright (c) 2015 The Khronos Group Inc.
6c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * Copyright (c) 2015 Imagination Technologies Ltd.
7c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *
8978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * Licensed under the Apache License, Version 2.0 (the "License");
9978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * you may not use this file except in compliance with the License.
10978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * You may obtain a copy of the License at
11c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *
12978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos *      http://www.apache.org/licenses/LICENSE-2.0
13c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *
14978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * Unless required by applicable law or agreed to in writing, software
15978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * distributed under the License is distributed on an "AS IS" BASIS,
16978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * See the License for the specific language governing permissions and
18978d3d585aa549eb1e729b51e9d85fc6477240f9Pyry Haulos * limitations under the License.
19c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *
20c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *//*!
21c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * \file
22c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim * \brief Utilities for clear values.
23c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim *//*--------------------------------------------------------------------*/
24c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
25c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim#include "vktPipelineClearUtil.hpp"
26c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim#include "vkImageUtil.hpp"
27c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim#include "tcuTextureUtil.hpp"
28c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
29c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimnamespace vkt
30c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
31c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimnamespace pipeline
32c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
33c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
34c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimusing namespace vk;
35c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
364698bb4451c7d984b7e070d524130deb5a775f1aDae Kimtcu::Vec4 defaultClearColor (const tcu::TextureFormat& format)
37c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
384698bb4451c7d984b7e070d524130deb5a775f1aDae Kim   if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT)
394698bb4451c7d984b7e070d524130deb5a775f1aDae Kim       return defaultClearColorUnorm();
404698bb4451c7d984b7e070d524130deb5a775f1aDae Kim   else
414698bb4451c7d984b7e070d524130deb5a775f1aDae Kim   {
424698bb4451c7d984b7e070d524130deb5a775f1aDae Kim       const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
434698bb4451c7d984b7e070d524130deb5a775f1aDae Kim       return (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
444698bb4451c7d984b7e070d524130deb5a775f1aDae Kim   }
45c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
46c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
47c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimtcu::IVec4 defaultClearColorInt (const tcu::TextureFormat& format)
48c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
49c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const tcu::TextureFormatInfo	formatInfo	= tcu::getTextureFormatInfo(format);
50c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const tcu::Vec4					color		= (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
51c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
52c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const tcu::IVec4				result		((deInt32)deFloatRound(color.x()), (deInt32)deFloatRound(color.y()),
53c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim												 (deInt32)deFloatRound(color.z()), (deInt32)deFloatRound(color.w()));
54c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
55c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return result;
56c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
57c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
58c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimtcu::UVec4 defaultClearColorUint (const tcu::TextureFormat& format)
59c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
60c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const tcu::TextureFormatInfo	formatInfo	= tcu::getTextureFormatInfo(format);
61c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const tcu::Vec4					color		= (defaultClearColorUnorm() - formatInfo.lookupBias) / formatInfo.lookupScale;
62c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
63c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	const	tcu::UVec4				result		((deUint32)deFloatRound(color.x()), (deUint32)deFloatRound(color.y()),
64c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim												 (deUint32)deFloatRound(color.z()), (deUint32)deFloatRound(color.w()));
65c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
66c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return result;
67c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
68c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
69c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimtcu::Vec4 defaultClearColorUnorm (void)
70c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
71c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return tcu::Vec4(0.39f, 0.58f, 0.93f, 1.0f);
72c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
73c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
74c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kimfloat defaultClearDepth (void)
75c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
76c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return 1.0f;
77c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
78c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
79c6e8b5a8389a64972259b357407b5e0f4edd5716Dae KimdeUint32 defaultClearStencil (void)
80c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
81c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return 0;
82c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
83c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
84c6e8b5a8389a64972259b357407b5e0f4edd5716Dae KimVkClearDepthStencilValue defaultClearDepthStencilValue (void)
85c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
86c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	VkClearDepthStencilValue clearDepthStencilValue;
87c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	clearDepthStencilValue.depth	= defaultClearDepth();
88c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	clearDepthStencilValue.stencil	= defaultClearStencil();
89c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
90c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return clearDepthStencilValue;
91c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
92c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
93c6e8b5a8389a64972259b357407b5e0f4edd5716Dae KimVkClearValue defaultClearValue (VkFormat clearFormat)
94c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim{
95c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	VkClearValue clearValue;
96c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
97c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	if (isDepthStencilFormat(clearFormat))
98c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	{
99c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		const VkClearDepthStencilValue dsValue = defaultClearDepthStencilValue();
1003d2071b82061ee418aa87064333069281133eddaPyry Haulos		clearValue.depthStencil.stencil	= dsValue.stencil;
1013d2071b82061ee418aa87064333069281133eddaPyry Haulos		clearValue.depthStencil.depth	= dsValue.depth;
102c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	}
103c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	else
104c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	{
105c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		const tcu::TextureFormat tcuClearFormat = mapVkFormat(clearFormat);
106c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		if (isUintFormat(clearFormat))
107c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		{
108c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim			const tcu::UVec4 defaultColor	= defaultClearColorUint(tcuClearFormat);
1093d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.uint32[0]			= defaultColor.x();
1103d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.uint32[1]			= defaultColor.y();
1113d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.uint32[2]			= defaultColor.z();
1123d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.uint32[3]			= defaultColor.w();
113c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		}
114c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		else if (isIntFormat(clearFormat))
115c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		{
116c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim			const tcu::IVec4 defaultColor	= defaultClearColorInt(tcuClearFormat);
1173d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.int32[0]			= defaultColor.x();
1183d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.int32[1]			= defaultColor.y();
1193d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.int32[2]			= defaultColor.z();
1203d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.int32[3]			= defaultColor.w();
121c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		}
122c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		else
123c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		{
1244698bb4451c7d984b7e070d524130deb5a775f1aDae Kim			const tcu::Vec4 defaultColor	= defaultClearColor(tcuClearFormat);
1253d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.float32[0]			= defaultColor.x();
1263d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.float32[1]			= defaultColor.y();
1273d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.float32[2]			= defaultColor.z();
1283d2071b82061ee418aa87064333069281133eddaPyry Haulos			clearValue.color.float32[3]			= defaultColor.w();
129c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim		}
130c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	}
131c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
132c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim	return clearValue;
133c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim}
134c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim
135c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim} // pipeline
136c6e8b5a8389a64972259b357407b5e0f4edd5716Dae Kim} // vkt
137