• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture utility class
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktImageTexture.hpp"
25 
26 namespace vkt
27 {
28 namespace image
29 {
30 
checkInvariants(void) const31 void Texture::checkInvariants (void) const
32 {
33 	DE_ASSERT((m_numSamples == 1)  || (m_numSamples == 2)  || (m_numSamples == 4) || (m_numSamples == 8) ||
34 			  (m_numSamples == 16) || (m_numSamples == 32) || (m_numSamples == 64));
35 	DE_ASSERT(m_numLayers >= 1);
36 	DE_ASSERT(m_layerSize.x() >= 1 && m_layerSize.y() >= 1 && m_layerSize.z() >= 1);
37 
38 	switch (m_type)
39 	{
40 		case IMAGE_TYPE_1D:
41 		case IMAGE_TYPE_BUFFER:
42 			DE_ASSERT(m_numLayers == 1);
43 			DE_ASSERT(m_numSamples == 1);
44 			DE_ASSERT(m_layerSize.y() == 1 && m_layerSize.z() == 1);
45 			break;
46 
47 		case IMAGE_TYPE_1D_ARRAY:
48 			DE_ASSERT(m_numSamples == 1);
49 			DE_ASSERT(m_layerSize.y() == 1 && m_layerSize.z() == 1);
50 			break;
51 
52 		case IMAGE_TYPE_2D:
53 			DE_ASSERT(m_numLayers == 1);
54 			DE_ASSERT(m_layerSize.z() == 1);
55 			break;
56 
57 		case IMAGE_TYPE_2D_ARRAY:
58 			DE_ASSERT(m_layerSize.z() == 1);
59 			break;
60 
61 		case IMAGE_TYPE_CUBE:
62 			DE_ASSERT(m_numSamples == 1);
63 			DE_ASSERT(m_numLayers == 6);
64 			DE_ASSERT(m_layerSize.z() == 1);
65 			break;
66 
67 		case IMAGE_TYPE_CUBE_ARRAY:
68 			DE_ASSERT(m_numSamples == 1);
69 			DE_ASSERT(m_numLayers >= 6 && m_numLayers % 6 == 0);
70 			DE_ASSERT(m_layerSize.z() == 1);
71 			break;
72 
73 		case IMAGE_TYPE_3D:
74 			DE_ASSERT(m_numSamples == 1);
75 			DE_ASSERT(m_numLayers == 1);
76 			break;
77 
78 		default:
79 			DE_FATAL("Internal error");
80 			break;
81 	}
82 }
83 
Texture(const ImageType imageType,const tcu::IVec3 & imageLayerSize,const int layers,const int samples)84 Texture::Texture (const ImageType imageType, const tcu::IVec3& imageLayerSize, const int layers, const int samples)
85 	: m_layerSize	(imageLayerSize)
86 	, m_type		(imageType)
87 	, m_numLayers	(layers)
88 	, m_numSamples	(samples)
89 {
90 	checkInvariants();
91 }
92 
Texture(const Texture & other,const int samples)93 Texture::Texture (const Texture& other, const int samples)
94 	: m_layerSize	(other.m_layerSize)
95 	, m_type		(other.m_type)
96 	, m_numLayers	(other.m_numLayers)
97 	, m_numSamples	(samples)
98 {
99 	checkInvariants();
100 }
101 
size(void) const102 tcu::IVec3 Texture::size (void) const
103 {
104 	switch (m_type)
105 	{
106 		case IMAGE_TYPE_1D:
107 		case IMAGE_TYPE_BUFFER:
108 		case IMAGE_TYPE_2D:
109 		case IMAGE_TYPE_3D:
110 			return m_layerSize;
111 
112 		case IMAGE_TYPE_1D_ARRAY:
113 			return tcu::IVec3(m_layerSize.x(), m_numLayers, 1);
114 
115 		case IMAGE_TYPE_2D_ARRAY:
116 		case IMAGE_TYPE_CUBE:
117 		case IMAGE_TYPE_CUBE_ARRAY:
118 			return tcu::IVec3(m_layerSize.x(), m_layerSize.y(), m_numLayers);
119 
120 		default:
121 			DE_FATAL("Internal error");
122 			return tcu::IVec3();
123 	}
124 }
125 
dimension(void) const126 int Texture::dimension (void) const
127 {
128 	switch (m_type)
129 	{
130 		case IMAGE_TYPE_1D:
131 		case IMAGE_TYPE_BUFFER:
132 			return 1;
133 
134 		case IMAGE_TYPE_1D_ARRAY:
135 		case IMAGE_TYPE_2D:
136 			return 2;
137 
138 		case IMAGE_TYPE_2D_ARRAY:
139 		case IMAGE_TYPE_CUBE:
140 		case IMAGE_TYPE_CUBE_ARRAY:
141 		case IMAGE_TYPE_3D:
142 			return 3;
143 
144 		default:
145 			DE_FATAL("Internal error");
146 			return 0;
147 	}
148 }
149 
layerDimension(void) const150 int Texture::layerDimension (void) const
151 {
152 	switch (m_type)
153 	{
154 		case IMAGE_TYPE_1D:
155 		case IMAGE_TYPE_BUFFER:
156 		case IMAGE_TYPE_1D_ARRAY:
157 			return 1;
158 
159 		case IMAGE_TYPE_2D:
160 		case IMAGE_TYPE_2D_ARRAY:
161 		case IMAGE_TYPE_CUBE:
162 		case IMAGE_TYPE_CUBE_ARRAY:
163 			return 2;
164 
165 		case IMAGE_TYPE_3D:
166 			return 3;
167 
168 		default:
169 			DE_FATAL("Internal error");
170 			return 0;
171 	}
172 }
173 
174 } // image
175 } // vkt
176