blob: 5caea9e8f092d339e2d6633a9414cd46d8c9d4e4 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001// VK tests
Chia-I Wucb67c652014-10-21 11:06:26 +08002//
Chia-I Wu6170c9e2014-12-08 14:30:10 +08003// Copyright (C) 2014 LunarG, Inc.
Chia-I Wucb67c652014-10-21 11:06:26 +08004//
Chia-I Wu6170c9e2014-12-08 14:30:10 +08005// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
Chia-I Wucb67c652014-10-21 11:06:26 +080011//
Chia-I Wu6170c9e2014-12-08 14:30:10 +080012// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
Chia-I Wucb67c652014-10-21 11:06:26 +080014//
Chia-I Wu6170c9e2014-12-08 14:30:10 +080015// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
Chia-I Wucb67c652014-10-21 11:06:26 +080022
23// Blit (copy, clear, and resolve) tests
24
Tony Barbourb223d482015-06-09 13:40:53 -060025#include "math.h"
Chia-I Wu9dac52d2014-12-27 22:04:00 +080026#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060027#include "vktestbinding.h"
Tony Barbour34888cf2015-03-02 16:38:52 -070028#include "test_environment.h"
Chia-I Wucb67c652014-10-21 11:06:26 +080029
30#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
31
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060032namespace vk_testing {
Chia-I Wucb67c652014-10-21 11:06:26 +080033
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060034size_t get_format_size(VkFormat format);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080035
Chia-I Wu6170c9e2014-12-08 14:30:10 +080036class ImageChecker {
37public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060038 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080039 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060040 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
41 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080042
43 void set_solid_pattern(const std::vector<uint8_t> &solid);
44
Tony Barbour8205d902015-04-16 15:59:00 -060045 VkDeviceSize buffer_size() const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080046 bool fill(Buffer &buf) const { return walk(FILL, buf); }
47 bool fill(Image &img) const { return walk(FILL, img); }
48 bool check(Buffer &buf) const { return walk(CHECK, buf); }
49 bool check(Image &img) const { return walk(CHECK, img); }
50
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060051 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu6170c9e2014-12-08 14:30:10 +080052
53 static void hash_salt_generate() { hash_salt_++; }
54
55private:
56 enum Action {
57 FILL,
58 CHECK,
59 };
60
61 enum Pattern {
62 HASH,
63 SOLID,
64 };
65
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060066 size_t buffer_cpp() const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060067 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080068
69 bool walk(Action action, Buffer &buf) const;
70 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060071 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080072
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060073 std::vector<uint8_t> pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080074
75 static uint32_t hash_salt_;
76
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060077 VkImageCreateInfo info_;
78 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080079
80 Pattern pattern_;
81 std::vector<uint8_t> pattern_solid_;
82};
83
Chia-I Wucb67c652014-10-21 11:06:26 +080084
Chia-I Wu6170c9e2014-12-08 14:30:10 +080085uint32_t ImageChecker::hash_salt_;
86
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060087ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080088 : info_(info), regions_(), pattern_(HASH)
89{
90 // create a region for every mip level in array slice 0
Tony Barbour8205d902015-04-16 15:59:00 -060091 VkDeviceSize offset = 0;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060092 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093 VkBufferImageCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +080094
Chia-I Wu714df452015-01-01 07:55:04 +080095 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080096 region.imageSubresource.mipLevel = lv;
97 region.imageSubresource.arraySlice = 0;
Chia-I Wu9dac52d2014-12-27 22:04:00 +080098 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080099
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600100 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_BIT) {
Tony Barbour8205d902015-04-16 15:59:00 -0600101 if (info_.format != VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 region.imageSubresource.aspect = VK_IMAGE_ASPECT_DEPTH;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800103 regions_.push_back(region);
104 }
105
Tony Barbour8205d902015-04-16 15:59:00 -0600106 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
107 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
108 info_.format == VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600109 region.imageSubresource.aspect = VK_IMAGE_ASPECT_STENCIL;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800110 regions_.push_back(region);
111 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800112 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113 region.imageSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800114 regions_.push_back(region);
115 }
116
117 offset += buffer_layout(region).size;
118 }
119
120 // arraySize should be limited in our tests. If this proves to be an
121 // issue, we can store only the regions for array slice 0 and be smart.
122 if (info_.arraySize > 1) {
Tony Barbour8205d902015-04-16 15:59:00 -0600123 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600124 const uint32_t slice_region_count = regions_.size();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800125
126 regions_.reserve(slice_region_count * info_.arraySize);
127
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600128 for (uint32_t slice = 1; slice < info_.arraySize; slice++) {
129 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130 VkBufferImageCopy region = regions_[i];
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800131
Chia-I Wu714df452015-01-01 07:55:04 +0800132 region.bufferOffset += slice_pitch * slice;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800133 region.imageSubresource.arraySlice = slice;
134 regions_.push_back(region);
135 }
136 }
137 }
138}
139
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600140ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800141 : info_(info), regions_(), pattern_(HASH)
142{
Tony Barbour8205d902015-04-16 15:59:00 -0600143 VkDeviceSize offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800145 it != ranges.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600146 for (uint32_t lv = 0; lv < it->mipLevels; lv++) {
147 for (uint32_t slice = 0; slice < it->arraySize; slice++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600148 VkBufferImageCopy region = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800149 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800150 region.imageSubresource = Image::subresource(*it, lv, slice);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800151 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800152
153 regions_.push_back(region);
154
155 offset += buffer_layout(region).size;
156 }
157 }
158 }
159}
160
161void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
162{
163 pattern_ = SOLID;
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800164 pattern_solid_.clear();
165 pattern_solid_.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600166 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800167 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800168}
169
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600170size_t ImageChecker::buffer_cpp() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800171{
172 return get_format_size(info_.format);
173}
174
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600175VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800176{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600177 VkSubresourceLayout layout = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800178 layout.offset = region.bufferOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800179 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
180 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
181 layout.size = layout.depthPitch * region.imageExtent.depth;
182
183 return layout;
184}
185
Tony Barbour8205d902015-04-16 15:59:00 -0600186VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800187{
Tony Barbour8205d902015-04-16 15:59:00 -0600188 VkDeviceSize size = 0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800189
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600190 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800191 it != regions_.end(); it++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800193 if (size < layout.offset + layout.size)
194 size = layout.offset + layout.size;
195 }
196
197 return size;
198}
199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
201 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800202{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600203 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
204 for (int32_t y = 0; y < region.imageExtent.height; y++) {
205 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800206 uint8_t *dst = static_cast<uint8_t *>(data);
207 dst += layout.offset + layout.depthPitch * z +
208 layout.rowPitch * y + buffer_cpp() * x;
209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210 VkOffset3D offset = region.imageOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800211 offset.x += x;
212 offset.y += y;
213 offset.z += z;
214
215 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
216 pattern_hash(region.imageSubresource, offset) :
217 pattern_solid_;
218 assert(val.size() == buffer_cpp());
219
220 if (action == FILL) {
221 memcpy(dst, &val[0], val.size());
222 } else {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600223 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800224 EXPECT_EQ(val[i], dst[i]) <<
225 "Offset is: (" << x << ", " << y << ", " << z << ")";
226 if (val[i] != dst[i])
227 return false;
228 }
229 }
230 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800231 }
232 }
233
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800234 return true;
Chia-I Wucb67c652014-10-21 11:06:26 +0800235}
236
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800237bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800238{
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800239 void *data = buf.map();
240 if (!data)
241 return false;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800242
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800244 for (it = regions_.begin(); it != regions_.end(); it++) {
245 if (!walk_region(action, *it, buffer_layout(*it), data))
246 break;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800247 }
248
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800249 buf.unmap();
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800250
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800251 return (it == regions_.end());
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800252}
253
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800254bool ImageChecker::walk(Action action, Image &img) const
255{
256 void *data = img.map();
257 if (!data)
258 return false;
259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800261 for (it = regions_.begin(); it != regions_.end(); it++) {
262 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
263 break;
264 }
265
266 img.unmap();
267
268 return (it == regions_.end());
269}
270
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800272{
273#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
274#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
275 const unsigned char input[] = {
276 HASH_BYTES(hash_salt_),
277 HASH_BYTES(subres.mipLevel),
278 HASH_BYTES(subres.arraySlice),
279 HASH_BYTES(offset.x),
280 HASH_BYTES(offset.y),
281 HASH_BYTES(offset.z),
282 };
283 unsigned long hash = 5381;
284
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600285 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800286 hash = ((hash << 5) + hash) + input[i];
287
288 const uint8_t output[4] = { HASH_BYTES(hash) };
289#undef HASH_BYTES
290#undef HASH_BYTE
291
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800292 std::vector<uint8_t> val;
293 val.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600294 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800295 val.push_back(output[i % 4]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800296
297 return val;
298}
299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300size_t get_format_size(VkFormat format)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800301{
Tony Barbourae2d5f42015-05-14 17:15:33 -0600302 static bool format_table_unverified = true;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800303 static const struct format_info {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600304 VkFormat_ format;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600305 size_t size;
306 uint32_t channel_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600307 } format_table[VK_NUM_FORMAT] = {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600308 { VK_FORMAT_UNDEFINED, 0, 0 },
309 { VK_FORMAT_R4G4_UNORM, 1, 2 },
310 { VK_FORMAT_R4G4_USCALED, 1, 2 },
311 { VK_FORMAT_R4G4B4A4_UNORM, 2, 4 },
312 { VK_FORMAT_R4G4B4A4_USCALED, 2, 4 },
313 { VK_FORMAT_R5G6B5_UNORM, 2, 3 },
314 { VK_FORMAT_R5G6B5_USCALED, 2, 3 },
315 { VK_FORMAT_R5G5B5A1_UNORM, 2, 4 },
316 { VK_FORMAT_R5G5B5A1_USCALED, 2, 4 },
317 { VK_FORMAT_R8_UNORM, 1, 1 },
318 { VK_FORMAT_R8_SNORM, 1, 1 },
319 { VK_FORMAT_R8_USCALED, 1, 1 },
320 { VK_FORMAT_R8_SSCALED, 1, 1 },
321 { VK_FORMAT_R8_UINT, 1, 1 },
322 { VK_FORMAT_R8_SINT, 1, 1 },
323 { VK_FORMAT_R8_SRGB, 1, 1 },
324 { VK_FORMAT_R8G8_UNORM, 2, 2 },
325 { VK_FORMAT_R8G8_SNORM, 2, 2 },
326 { VK_FORMAT_R8G8_USCALED, 2, 2 },
327 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
328 { VK_FORMAT_R8G8_UINT, 2, 2 },
329 { VK_FORMAT_R8G8_SINT, 2, 2 },
330 { VK_FORMAT_R8G8_SRGB, 2, 2 },
331 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
332 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
333 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
334 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
335 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
336 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
337 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
338 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
339 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
340 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
341 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
342 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
343 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
344 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
345 { VK_FORMAT_R10G10B10A2_UNORM, 4, 4 },
346 { VK_FORMAT_R10G10B10A2_SNORM, 4, 4 },
347 { VK_FORMAT_R10G10B10A2_USCALED, 4, 4 },
348 { VK_FORMAT_R10G10B10A2_SSCALED, 4, 4 },
349 { VK_FORMAT_R10G10B10A2_UINT, 4, 4 },
350 { VK_FORMAT_R10G10B10A2_SINT, 4, 4 },
351 { VK_FORMAT_R16_UNORM, 2, 1 },
352 { VK_FORMAT_R16_SNORM, 2, 1 },
353 { VK_FORMAT_R16_USCALED, 2, 1 },
354 { VK_FORMAT_R16_SSCALED, 2, 1 },
355 { VK_FORMAT_R16_UINT, 2, 1 },
356 { VK_FORMAT_R16_SINT, 2, 1 },
357 { VK_FORMAT_R16_SFLOAT, 2, 1 },
358 { VK_FORMAT_R16G16_UNORM, 4, 2 },
359 { VK_FORMAT_R16G16_SNORM, 4, 2 },
360 { VK_FORMAT_R16G16_USCALED, 4, 2 },
361 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
362 { VK_FORMAT_R16G16_UINT, 4, 2 },
363 { VK_FORMAT_R16G16_SINT, 4, 2 },
364 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
365 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
366 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
367 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
368 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
369 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
370 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
371 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
372 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
373 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
374 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
375 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
376 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
377 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
378 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
379 { VK_FORMAT_R32_UINT, 4, 1 },
380 { VK_FORMAT_R32_SINT, 4, 1 },
381 { VK_FORMAT_R32_SFLOAT, 4, 1 },
382 { VK_FORMAT_R32G32_UINT, 8, 2 },
383 { VK_FORMAT_R32G32_SINT, 8, 2 },
384 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
385 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
386 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
387 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
388 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
389 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
390 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
391 { VK_FORMAT_R64_SFLOAT, 8, 1 },
392 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
393 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
394 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
395 { VK_FORMAT_R11G11B10_UFLOAT, 4, 3 },
396 { VK_FORMAT_R9G9B9E5_UFLOAT, 4, 3 },
397 { VK_FORMAT_D16_UNORM, 2, 1 },
398 { VK_FORMAT_D24_UNORM, 3, 1 },
399 { VK_FORMAT_D32_SFLOAT, 4, 1 },
400 { VK_FORMAT_S8_UINT, 1, 1 },
401 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
402 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbourb223d482015-06-09 13:40:53 -0600403 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Tony Barbourae2d5f42015-05-14 17:15:33 -0600404 { VK_FORMAT_BC1_RGB_UNORM, 8, 4 },
405 { VK_FORMAT_BC1_RGB_SRGB, 8, 4 },
406 { VK_FORMAT_BC1_RGBA_UNORM, 8, 4 },
407 { VK_FORMAT_BC1_RGBA_SRGB, 8, 4 },
408 { VK_FORMAT_BC2_UNORM, 16, 4 },
409 { VK_FORMAT_BC2_SRGB, 16, 4 },
410 { VK_FORMAT_BC3_UNORM, 16, 4 },
411 { VK_FORMAT_BC3_SRGB, 16, 4 },
412 { VK_FORMAT_BC4_UNORM, 8, 4 },
413 { VK_FORMAT_BC4_SNORM, 8, 4 },
414 { VK_FORMAT_BC5_UNORM, 16, 4 },
415 { VK_FORMAT_BC5_SNORM, 16, 4 },
416 { VK_FORMAT_BC6H_UFLOAT, 16, 4 },
417 { VK_FORMAT_BC6H_SFLOAT, 16, 4 },
418 { VK_FORMAT_BC7_UNORM, 16, 4 },
419 { VK_FORMAT_BC7_SRGB, 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700420 // TODO: Initialize remaining compressed formats.
Tony Barbourae2d5f42015-05-14 17:15:33 -0600421 { VK_FORMAT_ETC2_R8G8B8_UNORM, 0, 0 },
422 { VK_FORMAT_ETC2_R8G8B8_SRGB, 0, 0 },
423 { VK_FORMAT_ETC2_R8G8B8A1_UNORM, 0, 0 },
424 { VK_FORMAT_ETC2_R8G8B8A1_SRGB, 0, 0 },
425 { VK_FORMAT_ETC2_R8G8B8A8_UNORM, 0, 0 },
426 { VK_FORMAT_ETC2_R8G8B8A8_SRGB, 0, 0 },
427 { VK_FORMAT_EAC_R11_UNORM, 0, 0 },
428 { VK_FORMAT_EAC_R11_SNORM, 0, 0 },
429 { VK_FORMAT_EAC_R11G11_UNORM, 0, 0 },
430 { VK_FORMAT_EAC_R11G11_SNORM, 0, 0 },
431 { VK_FORMAT_ASTC_4x4_UNORM, 0, 0 },
432 { VK_FORMAT_ASTC_4x4_SRGB, 0, 0 },
433 { VK_FORMAT_ASTC_5x4_UNORM, 0, 0 },
434 { VK_FORMAT_ASTC_5x4_SRGB, 0, 0 },
435 { VK_FORMAT_ASTC_5x5_UNORM, 0, 0 },
436 { VK_FORMAT_ASTC_5x5_SRGB, 0, 0 },
437 { VK_FORMAT_ASTC_6x5_UNORM, 0, 0 },
438 { VK_FORMAT_ASTC_6x5_SRGB, 0, 0 },
439 { VK_FORMAT_ASTC_6x6_UNORM, 0, 0 },
440 { VK_FORMAT_ASTC_6x6_SRGB, 0, 0 },
441 { VK_FORMAT_ASTC_8x5_UNORM, 0, 0 },
442 { VK_FORMAT_ASTC_8x5_SRGB, 0, 0 },
443 { VK_FORMAT_ASTC_8x6_UNORM, 0, 0 },
444 { VK_FORMAT_ASTC_8x6_SRGB, 0, 0 },
445 { VK_FORMAT_ASTC_8x8_UNORM, 0, 0 },
446 { VK_FORMAT_ASTC_8x8_SRGB, 0, 0 },
447 { VK_FORMAT_ASTC_10x5_UNORM, 0, 0 },
448 { VK_FORMAT_ASTC_10x5_SRGB, 0, 0 },
449 { VK_FORMAT_ASTC_10x6_UNORM, 0, 0 },
450 { VK_FORMAT_ASTC_10x6_SRGB, 0, 0 },
451 { VK_FORMAT_ASTC_10x8_UNORM, 0, 0 },
452 { VK_FORMAT_ASTC_10x8_SRGB, 0, 0 },
453 { VK_FORMAT_ASTC_10x10_UNORM, 0, 0 },
454 { VK_FORMAT_ASTC_10x10_SRGB, 0, 0 },
455 { VK_FORMAT_ASTC_12x10_UNORM, 0, 0 },
456 { VK_FORMAT_ASTC_12x10_SRGB, 0, 0 },
457 { VK_FORMAT_ASTC_12x12_UNORM, 0, 0 },
458 { VK_FORMAT_ASTC_12x12_SRGB, 0, 0 },
459 { VK_FORMAT_B4G4R4A4_UNORM, 2, 4 },
460 { VK_FORMAT_B5G5R5A1_UNORM, 2, 4 },
461 { VK_FORMAT_B5G6R5_UNORM, 2, 3 },
462 { VK_FORMAT_B5G6R5_USCALED, 2, 3 },
463 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
464 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
465 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
466 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
467 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
468 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
469 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
470 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
471 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
472 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
473 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
474 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
475 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
476 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
477 { VK_FORMAT_B10G10R10A2_UNORM, 4, 4 },
478 { VK_FORMAT_B10G10R10A2_SNORM, 4, 4 },
479 { VK_FORMAT_B10G10R10A2_USCALED, 4, 4 },
480 { VK_FORMAT_B10G10R10A2_SSCALED, 4, 4 },
481 { VK_FORMAT_B10G10R10A2_UINT, 4, 4 },
482 { VK_FORMAT_B10G10R10A2_SINT, 4, 4 },
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800483 };
Tony Barbourae2d5f42015-05-14 17:15:33 -0600484 if (format_table_unverified)
485 {
486 for (unsigned int i = 0; i < VK_NUM_FORMAT; i++)
487 {
488 assert(format_table[i].format == i);
489 }
490 format_table_unverified = false;
491 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800492
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700493 return format_table[format].size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800494}
495
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800497{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600498 const VkExtent3D ext = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800499 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
500 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
501 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
502 };
503
504 return ext;
505}
506
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600507}; // namespace vk_testing
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800508
509namespace {
510
511#define DO(action) ASSERT_EQ(true, action);
512
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600513static vk_testing::Environment *environment;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800514
Tony Barbour01999182015-04-09 12:58:51 -0600515class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800516protected:
Tony Barbour01999182015-04-09 12:58:51 -0600517 VkCmdBlitTest() :
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800518 dev_(environment->default_device()),
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800519 queue_(*dev_.graphics_queues()[0]),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600520 cmd_(dev_, vk_testing::CmdBuffer::create_info(dev_.graphics_queue_node_index_))
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800521 {
522 // make sure every test uses a different pattern
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600523 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800524 }
525
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800526 bool submit_and_done()
527 {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600528 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800529 queue_.wait();
530 mem_refs_.clear();
531 return true;
532 }
533
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600534 vk_testing::Device &dev_;
535 vk_testing::Queue &queue_;
536 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800537
Tony Barbour8205d902015-04-16 15:59:00 -0600538 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800539};
540
Tony Barbour01999182015-04-09 12:58:51 -0600541typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800542
Tony Barbour01999182015-04-09 12:58:51 -0600543TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800544{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600546 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800547
Tony Barbour94310562015-04-22 15:10:33 -0600548 buf.init(dev_, 20, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800549
550 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
552 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800553 cmd_.end();
554
555 submit_and_done();
556
557 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
558 EXPECT_EQ(0x11111111, data[0]);
559 EXPECT_EQ(0x22222222, data[1]);
560 EXPECT_EQ(0x22222222, data[2]);
561 EXPECT_EQ(0x22222222, data[3]);
562 EXPECT_EQ(0x22222222, data[4]);
563 buf.unmap();
564}
565
Tony Barbour01999182015-04-09 12:58:51 -0600566TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800567{
Tony Barbour8205d902015-04-16 15:59:00 -0600568 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600569 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600570 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800571
Tony Barbour94310562015-04-22 15:10:33 -0600572 buf.init(dev_, size, reqs);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800573
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800574 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600575 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
576 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800577 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800578
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800579 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800580
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800581 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600582 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800583 for (offset = 0; offset < size / 2; offset += 4)
584 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
585 for (; offset < size; offset += 4)
586 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
587 buf.unmap();
588}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800589
Tony Barbour01999182015-04-09 12:58:51 -0600590TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800591{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600592 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600593 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800594
Tony Barbour94310562015-04-22 15:10:33 -0600595 buf.init(dev_, 64, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800596
597 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
599 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800600 cmd_.end();
601
602 submit_and_done();
603
604 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600605 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800606 for (offset = 0; offset < 32; offset += 4)
607 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
608 for (; offset < 64; offset += 4)
609 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
610 buf.unmap();
611}
612
Tony Barbour01999182015-04-09 12:58:51 -0600613TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800614{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600616 VkDeviceSize size = 4;
Tony Barbour94310562015-04-22 15:10:33 -0600617 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800618
619 cmd_.begin();
620 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600621 bufs[i].init(dev_, size, reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800623 size <<= 1;
624 }
625 cmd_.end();
626
627 submit_and_done();
628
629 size = 4;
630 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
631 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600632 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800633 for (offset = 0; offset < size; offset += 4)
634 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
635 "Offset is: " << offset;
636 bufs[i].unmap();
637
638 size <<= 1;
639 }
640}
641
Tony Barbour01999182015-04-09 12:58:51 -0600642typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800643
Tony Barbour01999182015-04-09 12:58:51 -0600644TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800645{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600646 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600647 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800648
Tony Barbour94310562015-04-22 15:10:33 -0600649 src.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800650 uint32_t *data = static_cast<uint32_t *>(src.map());
651 data[0] = 0x11111111;
652 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800653
Tony Barbour94310562015-04-22 15:10:33 -0600654 dst.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800655
656 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600657 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800658 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800660 cmd_.end();
661
662 submit_and_done();
663
664 data = static_cast<uint32_t *>(dst.map());
665 EXPECT_EQ(0x11111111, data[0]);
666 dst.unmap();
667}
668
Tony Barbour01999182015-04-09 12:58:51 -0600669TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800670{
Tony Barbour8205d902015-04-16 15:59:00 -0600671 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600673 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800674
Tony Barbour94310562015-04-22 15:10:33 -0600675 src.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800676 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600677 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800678 for (offset = 0; offset < size; offset += 4)
679 data[offset / 4] = offset;
680 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800681
Tony Barbour94310562015-04-22 15:10:33 -0600682 dst.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800683
684 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800686 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600687 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800688 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800689
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800690 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800691
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800692 data = static_cast<uint32_t *>(dst.map());
693 for (offset = 0; offset < size; offset += 4)
694 EXPECT_EQ(offset, data[offset / 4]);
695 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800696}
697
Tony Barbour01999182015-04-09 12:58:51 -0600698TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800699{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600700 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800701 /* well aligned */
702 { 0, 0, 256 },
703 { 0, 256, 128 },
704 { 0, 384, 64 },
705 { 0, 448, 32 },
706 { 0, 480, 16 },
707 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800708
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800709 /* ill aligned */
710 { 7, 510, 16 },
711 { 16, 530, 13 },
712 { 32, 551, 16 },
713 { 45, 570, 15 },
714 { 50, 590, 1 },
715 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600717 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +0800718
Tony Barbour94310562015-04-22 15:10:33 -0600719 src.init(dev_, 256, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800720 uint8_t *data = static_cast<uint8_t *>(src.map());
721 for (int i = 0; i < 256; i++)
722 data[i] = i;
723 src.unmap();
Chia-I Wucb67c652014-10-21 11:06:26 +0800724
Tony Barbour94310562015-04-22 15:10:33 -0600725 dst.init(dev_, 1024, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800726
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800727 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600728 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800729 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800730
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800731 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800732
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800733 data = static_cast<uint8_t *>(dst.map());
734 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600735 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800736
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800737 for (int j = 0; j < r.copySize; j++) {
738 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
739 "Region is: " << i << "\n" <<
740 "Offset is: " << r.destOffset + j;
741 }
742 }
743 dst.unmap();
744}
Chia-I Wucb67c652014-10-21 11:06:26 +0800745
Tony Barbour01999182015-04-09 12:58:51 -0600746TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800747{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749 VkEventCreateInfo event_info;
750 VkEvent event;
751 VkMemoryRequirements mem_req;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752 VkResult err;
Tony Barbour94310562015-04-22 15:10:33 -0600753 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbour43cdc952015-05-21 13:26:05 -0600754 VkMemoryAllocInfo mem_info;
755 VkDeviceMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000758 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600760 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 // VkFlags flags; // Reserved
762 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000763 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000765
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766 err = vkCreateEvent(dev_.obj(), &event_info, &event);
767 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000768
Tony Barbour426b9052015-06-24 16:06:58 -0600769 err = vkGetObjectMemoryRequirements(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600770 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000771
Tony Barbour43cdc952015-05-21 13:26:05 -0600772 if (mem_req.size) {
Mike Stroyan55658c22014-12-04 11:08:39 +0000773
Tony Barbour43cdc952015-05-21 13:26:05 -0600774 // VkResult VKAPI vkAllocMemory(
775 // VkDevice device,
776 // const VkMemoryAllocInfo* pAllocInfo,
777 // VkDeviceMemory* pMem);
Mike Stroyan55658c22014-12-04 11:08:39 +0000778
Tony Barbour43cdc952015-05-21 13:26:05 -0600779 memset(&mem_info, 0, sizeof(mem_info));
780 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
781 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchterb25c9b92015-06-18 17:01:41 -0600782 mem_info.memProps = 0;
Tony Barbour43cdc952015-05-21 13:26:05 -0600783 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
784 ASSERT_VK_SUCCESS(err);
785
786 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
787 ASSERT_VK_SUCCESS(err);
788 }
Mike Stroyan55658c22014-12-04 11:08:39 +0000789
Mike Stroyan230e6252015-04-17 12:36:38 -0600790 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600791 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800792
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800793 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600794 bufs[i].init(dev_, 4, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800795
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800796 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
797 data[0] = 0x22222222 * (i + 1);
798 bufs[i].unmap();
799 }
800
801 cmd_.begin();
802
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600803 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800804 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600805 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600806 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600807 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000808
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600809 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600810 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&pmemory_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800811
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800813 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000815
816 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600817 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600818 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600819 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&pmemory_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800820
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600821 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000822
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600823 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
824 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000825 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600826 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000827
828 // Additional commands could go into the buffer here before the wait.
829
830 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600831 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_HOST_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600832 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600833 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000834
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800835 cmd_.end();
836
837 submit_and_done();
838
839 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
840 EXPECT_EQ(0x11111111, data[0]);
841 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000842
Tony Barbour43cdc952015-05-21 13:26:05 -0600843 if (mem_req.size) {
844 // All done with event memory, clean up
Tony Barbour43cdc952015-05-21 13:26:05 -0600845 err = vkFreeMemory(dev_.obj(), event_mem);
846 ASSERT_VK_SUCCESS(err);
847 }
Mike Stroyan230e6252015-04-17 12:36:38 -0600848 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600849 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800850}
851
Tony Barbour01999182015-04-09 12:58:51 -0600852class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800853protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600854 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800855 {
Tony Barbour8205d902015-04-16 15:59:00 -0600856 first_linear_format_ = VK_FORMAT_UNDEFINED;
857 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800858
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800860 it != dev_.formats().end(); it++) {
861 if (it->features & features) {
862 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800863
Tony Barbour8205d902015-04-16 15:59:00 -0600864 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
865 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800866 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600867 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
868 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800869 first_optimal_format_ = it->format;
870 }
871 }
872 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800873
Chia-I Wu9feab842014-12-22 13:19:08 +0800874 void init_test_formats()
875 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600876 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800877 }
878
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800880 {
881 if (img.transparent()) {
882 checker.fill(img);
883 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800884 }
885
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800886 ASSERT_EQ(true, img.copyable());
887
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600888 vk_testing::Buffer in_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600889 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
890
891 in_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800892 checker.fill(in_buf);
893
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800894 // copy in and tile
895 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600896 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
897 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800898 checker.regions().size(), &checker.regions()[0]);
899 cmd_.end();
900
901 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800902 }
903
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600904 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800905 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800906 if (img.transparent()) {
907 DO(checker.check(img));
908 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800909 }
910
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800911 ASSERT_EQ(true, img.copyable());
912
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600913 vk_testing::Buffer out_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600914 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
915 out_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800916
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800917 // copy out and linearize
918 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600919 vkCmdCopyImageToBuffer(cmd_.obj(),
920 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600921 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800922 checker.regions().size(), &checker.regions()[0]);
923 cmd_.end();
924
925 submit_and_done();
926
927 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800928 }
929
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600930 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600931 VkFormat first_linear_format_;
932 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800933};
934
Tony Barbour01999182015-04-09 12:58:51 -0600935class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800936protected:
937 virtual void SetUp()
938 {
Tony Barbour01999182015-04-09 12:58:51 -0600939 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600940 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800941 ASSERT_NE(true, test_formats_.empty());
942 }
943
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600944 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800945 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600946 vk_testing::Buffer buf;
947 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -0600948 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
949 VkMemoryPropertyFlags image_reqs =
950 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800951
Tony Barbour43cdc952015-05-21 13:26:05 -0600952 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800953 checker.fill(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800954
Tony Barbour43cdc952015-05-21 13:26:05 -0600955 img.init(dev_, img_info, image_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800956
957 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600959 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600960 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800961 checker.regions().size(), &checker.regions()[0]);
962 cmd_.end();
963
964 submit_and_done();
965
966 check_dst(img, checker);
967 }
968
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600969 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800970 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600971 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800972 test_copy_memory_to_image(img_info, checker);
973 }
974
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600975 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800976 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600977 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800978 test_copy_memory_to_image(img_info, checker);
979 }
980};
981
Tony Barbour01999182015-04-09 12:58:51 -0600982TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800983{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600984 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800985 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700986
987 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -0600988 if (it->format == VK_FORMAT_UNDEFINED ||
989 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
990 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700991 continue;
992
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600993 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -0600994 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800995 img_info.format = it->format;
996 img_info.extent.width = 64;
997 img_info.extent.height = 64;
998 img_info.tiling = it->tiling;
999
1000 test_copy_memory_to_image(img_info);
1001 }
Chia-I Wu86822632014-11-22 15:09:42 +08001002}
1003
Tony Barbour01999182015-04-09 12:58:51 -06001004class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001005protected:
1006 virtual void SetUp()
1007 {
Tony Barbour01999182015-04-09 12:58:51 -06001008 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001009 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001010 ASSERT_NE(true, test_formats_.empty());
1011 }
1012
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001013 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001014 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001015 vk_testing::Image img;
1016 vk_testing::Buffer buf;
Tony Barbour43cdc952015-05-21 13:26:05 -06001017 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1018 VkMemoryPropertyFlags image_reqs =
1019 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu830fb332014-12-13 15:28:20 +08001020
Tony Barbour43cdc952015-05-21 13:26:05 -06001021 img.init(dev_, img_info, image_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001022 fill_src(img, checker);
Chia-I Wu830fb332014-12-13 15:28:20 +08001023
Tony Barbour43cdc952015-05-21 13:26:05 -06001024 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001025
1026 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001027 vkCmdCopyImageToBuffer(cmd_.obj(),
1028 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001029 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001030 checker.regions().size(), &checker.regions()[0]);
1031 cmd_.end();
1032
1033 submit_and_done();
1034
1035 checker.check(buf);
1036 }
1037
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001038 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001039 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001040 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001041 test_copy_image_to_memory(img_info, checker);
1042 }
1043
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001044 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001045 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001046 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001047 test_copy_image_to_memory(img_info, checker);
1048 }
1049};
1050
Tony Barbour01999182015-04-09 12:58:51 -06001051TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001052{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001054 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001055
1056 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001057 if (it->format == VK_FORMAT_UNDEFINED ||
1058 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1059 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001060 continue;
1061
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001063 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001064 img_info.format = it->format;
1065 img_info.extent.width = 64;
1066 img_info.extent.height = 64;
1067 img_info.tiling = it->tiling;
1068
1069 test_copy_image_to_memory(img_info);
1070 }
1071}
1072
Tony Barbour01999182015-04-09 12:58:51 -06001073class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001074protected:
1075 virtual void SetUp()
1076 {
Tony Barbour01999182015-04-09 12:58:51 -06001077 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001078 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001079 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001080 }
1081
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001082 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1083 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001084 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001085 // convert VkImageCopy to two sets of VkBufferImageCopy
1086 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001087 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001088 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1089 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001090
Chia-I Wu714df452015-01-01 07:55:04 +08001091 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001092 src_region.imageSubresource = it->srcSubresource;
1093 src_region.imageOffset = it->srcOffset;
1094 src_region.imageExtent = it->extent;
1095 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001096
Chia-I Wu714df452015-01-01 07:55:04 +08001097 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001098 dst_region.imageSubresource = it->destSubresource;
1099 dst_region.imageOffset = it->destOffset;
1100 dst_region.imageExtent = it->extent;
1101 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001102
Tony Barbour8205d902015-04-16 15:59:00 -06001103 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001104 src_offset += vk_testing::get_format_size(src_info.format) * size;
1105 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001106 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001107
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001108 vk_testing::ImageChecker src_checker(src_info, src_regions);
1109 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour43cdc952015-05-21 13:26:05 -06001110 VkMemoryPropertyFlags src_reqs =
1111 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1112 VkMemoryPropertyFlags dst_reqs =
1113 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1114
1115
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001116
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001117 vk_testing::Image src;
Tony Barbour43cdc952015-05-21 13:26:05 -06001118 src.init(dev_, src_info, src_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001119 fill_src(src, src_checker);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001120
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001121 vk_testing::Image dst;
Tony Barbour43cdc952015-05-21 13:26:05 -06001122 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001123
1124 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 vkCmdCopyImage(cmd_.obj(),
1126 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1127 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001128 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001129 cmd_.end();
1130
1131 submit_and_done();
1132
1133 check_dst(dst, dst_checker);
1134 }
1135};
1136
Tony Barbour01999182015-04-09 12:58:51 -06001137TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001138{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001139 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001140 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001141
1142 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001143 if (it->format == VK_FORMAT_UNDEFINED ||
1144 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1145 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001146 continue;
1147
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001148 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001149 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001150 img_info.format = it->format;
1151 img_info.extent.width = 64;
1152 img_info.extent.height = 64;
1153 img_info.tiling = it->tiling;
1154
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001156 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001157 copy.destSubresource = copy.srcSubresource;
1158 copy.extent = img_info.extent;
1159
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001160 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001161 }
1162}
1163
Tony Barbour01999182015-04-09 12:58:51 -06001164class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001165protected:
Tony Barbour01999182015-04-09 12:58:51 -06001166 VkCmdClearColorImageTest() : test_raw_(false) {}
1167 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001168
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001169 virtual void SetUp()
1170 {
Tony Barbour01999182015-04-09 12:58:51 -06001171 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001172
1173 if (test_raw_)
1174 init_test_formats();
1175 else
Tony Barbour8205d902015-04-16 15:59:00 -06001176 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001177
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001178 ASSERT_NE(true, test_formats_.empty());
1179 }
1180
Chia-I Wu9feab842014-12-22 13:19:08 +08001181 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001182 float color[4];
1183 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001184 };
1185
1186 bool test_raw_;
1187
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001189 {
1190 std::vector<uint8_t> raw;
1191
1192 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001193 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001194 case VK_FORMAT_R8G8B8A8_UNORM:
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001195 raw.push_back((uint8_t)(color[0] * 255.0f));
1196 raw.push_back((uint8_t)(color[1] * 255.0f));
1197 raw.push_back((uint8_t)(color[2] * 255.0f));
1198 raw.push_back((uint8_t)(color[3] * 255.0f));
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001199 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001200 case VK_FORMAT_B8G8R8A8_UNORM:
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001201 raw.push_back((uint8_t)(color[2] * 255.0f));
1202 raw.push_back((uint8_t)(color[1] * 255.0f));
1203 raw.push_back((uint8_t)(color[0] * 255.0f));
1204 raw.push_back((uint8_t)(color[3] * 255.0f));
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001205 break;
1206 default:
1207 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001208 }
1209
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001210 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001211 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001212
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001213 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001214 {
1215 std::vector<uint8_t> raw;
1216
1217 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001218 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001219 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001220 raw.push_back(static_cast<uint8_t>(color[0]));
1221 raw.push_back(static_cast<uint8_t>(color[1]));
1222 raw.push_back(static_cast<uint8_t>(color[2]));
1223 raw.push_back(static_cast<uint8_t>(color[3]));
1224 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001225 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001226 raw.push_back(static_cast<uint8_t>(color[2]));
1227 raw.push_back(static_cast<uint8_t>(color[1]));
1228 raw.push_back(static_cast<uint8_t>(color[0]));
1229 raw.push_back(static_cast<uint8_t>(color[3]));
1230 break;
1231 default:
1232 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001233 }
1234
1235 return raw;
1236 }
1237
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001238 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001239 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001240 if (color.useRawValue)
1241 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001242 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001243 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001244 }
1245
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001246 void test_clear_color_image(const VkImageCreateInfo &img_info,
1247 const VkClearColor &clear_color,
1248 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001249 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001251 VkMemoryPropertyFlags image_reqs =
1252 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001253
Tony Barbour43cdc952015-05-21 13:26:05 -06001254 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001255 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001256 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001257 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1258 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1259 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001260 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001261 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001262 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001263 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1264 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1265 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1266 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1267 VK_MEMORY_INPUT_SHADER_READ_BIT |
1268 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1269 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001270 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001271
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001272 std::vector<VkImageMemoryBarrier> to_clear;
1273 std::vector<VkImageMemoryBarrier *> p_to_clear;
1274 std::vector<VkImageMemoryBarrier> to_xfer;
1275 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001276
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001277 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001278 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001279 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001280 VK_IMAGE_LAYOUT_GENERAL,
1281 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001282 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001283 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001284 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001285 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1286 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001287 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001288 }
1289
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001290 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001291
Tony Barbour8205d902015-04-16 15:59:00 -06001292 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1293 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&p_to_clear[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001294
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001295 vkCmdClearColorImage(cmd_.obj(),
1296 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06001297 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001298
Tony Barbour8205d902015-04-16 15:59:00 -06001299 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&p_to_xfer[0]);
Chia-I Wu9feab842014-12-22 13:19:08 +08001300
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001301 cmd_.end();
1302
1303 submit_and_done();
1304
1305 // cannot verify
1306 if (!img.transparent() && !img.copyable())
1307 return;
1308
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001309 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001310
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001311 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001312 if (solid_pattern.empty())
1313 return;
1314
1315 checker.set_solid_pattern(solid_pattern);
1316 check_dst(img, checker);
1317 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001318
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001319 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001320 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001322 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001323 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001324 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001325 test_clear_color_image(img_info, c, ranges);
1326 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001327};
1328
Tony Barbour01999182015-04-09 12:58:51 -06001329TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001330{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001332 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001333 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barbour2275eb42015-06-05 12:53:55 -06001334 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001335 VkResult err;
1336
Chris Forbesd7576302015-06-21 22:55:02 +12001337 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001338 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001339
Tony Barbour2275eb42015-06-05 12:53:55 -06001340 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1341 continue;
1342
1343 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1344 continue;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001346 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001347 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001348 img_info.format = it->format;
1349 img_info.extent.width = 64;
1350 img_info.extent.height = 64;
1351 img_info.tiling = it->tiling;
Tony Barbour2275eb42015-06-05 12:53:55 -06001352 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001353
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001356 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001357
1358 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001359 }
1360}
1361
Tony Barbour01999182015-04-09 12:58:51 -06001362class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001363protected:
Tony Barbour01999182015-04-09 12:58:51 -06001364 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001365
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001366 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001367 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001368 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001369 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001371 c.useRawValue = true;
1372 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001373 test_clear_color_image(img_info, c, ranges);
1374 }
1375};
1376
Tony Barbour01999182015-04-09 12:58:51 -06001377TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001378{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001379 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001380 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001381 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Tony Barbour2275eb42015-06-05 12:53:55 -06001382 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001383 VkResult err;
1384
Chris Forbesd7576302015-06-21 22:55:02 +12001385 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001386 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001387
Tony Barbour2275eb42015-06-05 12:53:55 -06001388 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1389 continue;
1390
1391 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1392 continue;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001393
1394 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001395 if (it->format == VK_FORMAT_UNDEFINED ||
1396 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1397 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1398 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1399 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1400 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1401 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1402 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1403 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1404 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1405 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1406 (it->format >= VK_FORMAT_D16_UNORM &&
1407 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001408 continue;
1409
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001410 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001411 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001412 img_info.format = it->format;
1413 img_info.extent.width = 64;
1414 img_info.extent.height = 64;
1415 img_info.tiling = it->tiling;
Tony Barbour2275eb42015-06-05 12:53:55 -06001416 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001417
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001418 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001419 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001420 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001421
1422 test_clear_color_image_raw(img_info, color, ranges);
1423 }
1424}
1425
Tony Barbour01999182015-04-09 12:58:51 -06001426class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001427protected:
1428 virtual void SetUp()
1429 {
Tony Barbour01999182015-04-09 12:58:51 -06001430 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001431 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001432 ASSERT_NE(true, test_formats_.empty());
1433 }
1434
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001435 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001436 {
1437 std::vector<uint8_t> raw;
1438
1439 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001440 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001441 case VK_FORMAT_D16_UNORM:
1442 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001443 {
Tony Barbourb223d482015-06-09 13:40:53 -06001444 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001445 raw.push_back(unorm & 0xff);
1446 raw.push_back(unorm >> 8);
1447 }
1448 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001449 case VK_FORMAT_D32_SFLOAT:
1450 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001451 {
1452 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001453 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001454 uint32_t u32;
1455 } u = { depth };
1456
1457 raw.push_back((u.u32 ) & 0xff);
1458 raw.push_back((u.u32 >> 8) & 0xff);
1459 raw.push_back((u.u32 >> 16) & 0xff);
1460 raw.push_back((u.u32 >> 24) & 0xff);
1461 }
1462 break;
1463 default:
1464 break;
1465 }
1466
1467 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001468 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001469 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001470 raw.push_back(stencil);
1471 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001472 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001473 raw.push_back(stencil);
1474 raw.push_back(0);
1475 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001476 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001477 raw.push_back(stencil);
1478 raw.push_back(0);
1479 raw.push_back(0);
1480 raw.push_back(0);
1481 break;
1482 default:
1483 break;
1484 }
1485
1486 return raw;
1487 }
1488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001489 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001490 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001491 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001492 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001493 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001494 VkMemoryPropertyFlags image_reqs =
1495 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001496
Tony Barbour43cdc952015-05-21 13:26:05 -06001497 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001498 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001499 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001500 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1501 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1502 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001503 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001504 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001505 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001506 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1507 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1508 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1509 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1510 VK_MEMORY_INPUT_SHADER_READ_BIT |
1511 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1512 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001513 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001514
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001515 std::vector<VkImageMemoryBarrier> to_clear;
1516 std::vector<VkImageMemoryBarrier *> p_to_clear;
1517 std::vector<VkImageMemoryBarrier> to_xfer;
1518 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001519
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001520 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001521 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001522 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001523 VK_IMAGE_LAYOUT_GENERAL,
1524 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001525 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001526 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001527 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001528 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1529 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001530 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001531 }
1532
1533 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001534
Tony Barbour8205d902015-04-16 15:59:00 -06001535 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1536 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, to_clear.size(), (const void **)&p_to_clear[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001537
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001538 vkCmdClearDepthStencil(cmd_.obj(),
1539 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001540 depth, stencil,
1541 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001542
Tony Barbour8205d902015-04-16 15:59:00 -06001543 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, to_xfer.size(), (const void **)&p_to_xfer[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001544
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001545 cmd_.end();
1546
1547 submit_and_done();
1548
1549 // cannot verify
1550 if (!img.transparent() && !img.copyable())
1551 return;
1552
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001553 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001554
1555 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1556 check_dst(img, checker);
1557 }
1558};
1559
Tony Barbour01999182015-04-09 12:58:51 -06001560TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001561{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001562 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001563 it != test_formats_.end(); it++) {
Tony Barbour2275eb42015-06-05 12:53:55 -06001564 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001565 VkResult err;
1566
Chris Forbesd7576302015-06-21 22:55:02 +12001567 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001568 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001569
Tony Barbour2275eb42015-06-05 12:53:55 -06001570 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1571 continue;
1572
1573 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1574 continue;
1575
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001576 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001577 if (it->format == VK_FORMAT_S8_UINT ||
1578 it->format == VK_FORMAT_D24_UNORM ||
1579 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1580 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001581 continue;
1582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001583 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001584 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001585 img_info.format = it->format;
1586 img_info.extent.width = 64;
1587 img_info.extent.height = 64;
1588 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001589 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001590
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001591 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001593 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001594
Tony Barbourb223d482015-06-09 13:40:53 -06001595 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1596 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1597 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
1598 const VkImageSubresourceRange range2 =
1599 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_STENCIL);
1600 ranges.push_back(range2);
1601 }
1602
1603
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001604 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1605 }
1606}
1607
1608}; // namespace
1609
Chia-I Wucb67c652014-10-21 11:06:26 +08001610int main(int argc, char **argv)
1611{
Chia-I Wucb67c652014-10-21 11:06:26 +08001612 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001613
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001614 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001615
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001616 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001617
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001618 if (!environment->parse_args(argc, argv))
1619 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001620
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001621 ::testing::AddGlobalTestEnvironment(environment);
1622
1623 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001624}