blob: d3159f2c55151e73e3a22dcbce96a689ebee6673 [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
Chia-I Wu9dac52d2014-12-27 22:04:00 +080025#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060026#include "vktestbinding.h"
Tony Barbour34888cf2015-03-02 16:38:52 -070027#include "test_environment.h"
Chia-I Wucb67c652014-10-21 11:06:26 +080028
29#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031namespace vk_testing {
Chia-I Wucb67c652014-10-21 11:06:26 +080032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060033size_t get_format_size(VkFormat format);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080034
Chia-I Wu6170c9e2014-12-08 14:30:10 +080035class ImageChecker {
36public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060037 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080038 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060039 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
40 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080041
42 void set_solid_pattern(const std::vector<uint8_t> &solid);
43
Tony Barbour8205d902015-04-16 15:59:00 -060044 VkDeviceSize buffer_size() const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080045 bool fill(Buffer &buf) const { return walk(FILL, buf); }
46 bool fill(Image &img) const { return walk(FILL, img); }
47 bool check(Buffer &buf) const { return walk(CHECK, buf); }
48 bool check(Image &img) const { return walk(CHECK, img); }
49
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060050 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu6170c9e2014-12-08 14:30:10 +080051
52 static void hash_salt_generate() { hash_salt_++; }
53
54private:
55 enum Action {
56 FILL,
57 CHECK,
58 };
59
60 enum Pattern {
61 HASH,
62 SOLID,
63 };
64
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060065 size_t buffer_cpp() const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060066 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080067
68 bool walk(Action action, Buffer &buf) const;
69 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060070 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080071
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060072 std::vector<uint8_t> pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080073
74 static uint32_t hash_salt_;
75
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060076 VkImageCreateInfo info_;
77 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080078
79 Pattern pattern_;
80 std::vector<uint8_t> pattern_solid_;
81};
82
Chia-I Wucb67c652014-10-21 11:06:26 +080083
Chia-I Wu6170c9e2014-12-08 14:30:10 +080084uint32_t ImageChecker::hash_salt_;
85
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060086ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080087 : info_(info), regions_(), pattern_(HASH)
88{
89 // create a region for every mip level in array slice 0
Tony Barbour8205d902015-04-16 15:59:00 -060090 VkDeviceSize offset = 0;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060091 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060092 VkBufferImageCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +080093
Chia-I Wu714df452015-01-01 07:55:04 +080094 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080095 region.imageSubresource.mipLevel = lv;
96 region.imageSubresource.arraySlice = 0;
Chia-I Wu9dac52d2014-12-27 22:04:00 +080097 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080098
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_BIT) {
Tony Barbour8205d902015-04-16 15:59:00 -0600100 if (info_.format != VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101 region.imageSubresource.aspect = VK_IMAGE_ASPECT_DEPTH;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800102 regions_.push_back(region);
103 }
104
Tony Barbour8205d902015-04-16 15:59:00 -0600105 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
106 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
107 info_.format == VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 region.imageSubresource.aspect = VK_IMAGE_ASPECT_STENCIL;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800109 regions_.push_back(region);
110 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800111 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 region.imageSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800113 regions_.push_back(region);
114 }
115
116 offset += buffer_layout(region).size;
117 }
118
119 // arraySize should be limited in our tests. If this proves to be an
120 // issue, we can store only the regions for array slice 0 and be smart.
121 if (info_.arraySize > 1) {
Tony Barbour8205d902015-04-16 15:59:00 -0600122 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 const uint32_t slice_region_count = regions_.size();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800124
125 regions_.reserve(slice_region_count * info_.arraySize);
126
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600127 for (uint32_t slice = 1; slice < info_.arraySize; slice++) {
128 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600129 VkBufferImageCopy region = regions_[i];
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800130
Chia-I Wu714df452015-01-01 07:55:04 +0800131 region.bufferOffset += slice_pitch * slice;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800132 region.imageSubresource.arraySlice = slice;
133 regions_.push_back(region);
134 }
135 }
136 }
137}
138
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800140 : info_(info), regions_(), pattern_(HASH)
141{
Tony Barbour8205d902015-04-16 15:59:00 -0600142 VkDeviceSize offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800144 it != ranges.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600145 for (uint32_t lv = 0; lv < it->mipLevels; lv++) {
146 for (uint32_t slice = 0; slice < it->arraySize; slice++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600147 VkBufferImageCopy region = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800148 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800149 region.imageSubresource = Image::subresource(*it, lv, slice);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800150 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800151
152 regions_.push_back(region);
153
154 offset += buffer_layout(region).size;
155 }
156 }
157 }
158}
159
160void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
161{
162 pattern_ = SOLID;
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800163 pattern_solid_.clear();
164 pattern_solid_.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600165 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800166 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800167}
168
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600169size_t ImageChecker::buffer_cpp() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800170{
171 return get_format_size(info_.format);
172}
173
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600174VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800175{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600176 VkSubresourceLayout layout = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800177 layout.offset = region.bufferOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800178 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
179 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
180 layout.size = layout.depthPitch * region.imageExtent.depth;
181
182 return layout;
183}
184
Tony Barbour8205d902015-04-16 15:59:00 -0600185VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800186{
Tony Barbour8205d902015-04-16 15:59:00 -0600187 VkDeviceSize size = 0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800188
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600189 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800190 it != regions_.end(); it++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600191 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800192 if (size < layout.offset + layout.size)
193 size = layout.offset + layout.size;
194 }
195
196 return size;
197}
198
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600199bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
200 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800201{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600202 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
203 for (int32_t y = 0; y < region.imageExtent.height; y++) {
204 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800205 uint8_t *dst = static_cast<uint8_t *>(data);
206 dst += layout.offset + layout.depthPitch * z +
207 layout.rowPitch * y + buffer_cpp() * x;
208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600209 VkOffset3D offset = region.imageOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800210 offset.x += x;
211 offset.y += y;
212 offset.z += z;
213
214 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
215 pattern_hash(region.imageSubresource, offset) :
216 pattern_solid_;
217 assert(val.size() == buffer_cpp());
218
219 if (action == FILL) {
220 memcpy(dst, &val[0], val.size());
221 } else {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600222 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800223 EXPECT_EQ(val[i], dst[i]) <<
224 "Offset is: (" << x << ", " << y << ", " << z << ")";
225 if (val[i] != dst[i])
226 return false;
227 }
228 }
229 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800230 }
231 }
232
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800233 return true;
Chia-I Wucb67c652014-10-21 11:06:26 +0800234}
235
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800236bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800237{
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800238 void *data = buf.map();
239 if (!data)
240 return false;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800243 for (it = regions_.begin(); it != regions_.end(); it++) {
244 if (!walk_region(action, *it, buffer_layout(*it), data))
245 break;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800246 }
247
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800248 buf.unmap();
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800249
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800250 return (it == regions_.end());
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800251}
252
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800253bool ImageChecker::walk(Action action, Image &img) const
254{
255 void *data = img.map();
256 if (!data)
257 return false;
258
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600259 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800260 for (it = regions_.begin(); it != regions_.end(); it++) {
261 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
262 break;
263 }
264
265 img.unmap();
266
267 return (it == regions_.end());
268}
269
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800271{
272#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
273#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
274 const unsigned char input[] = {
275 HASH_BYTES(hash_salt_),
276 HASH_BYTES(subres.mipLevel),
277 HASH_BYTES(subres.arraySlice),
278 HASH_BYTES(offset.x),
279 HASH_BYTES(offset.y),
280 HASH_BYTES(offset.z),
281 };
282 unsigned long hash = 5381;
283
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600284 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800285 hash = ((hash << 5) + hash) + input[i];
286
287 const uint8_t output[4] = { HASH_BYTES(hash) };
288#undef HASH_BYTES
289#undef HASH_BYTE
290
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800291 std::vector<uint8_t> val;
292 val.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600293 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800294 val.push_back(output[i % 4]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800295
296 return val;
297}
298
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600299size_t get_format_size(VkFormat format)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800300{
Tony Barbourae2d5f42015-05-14 17:15:33 -0600301 static bool format_table_unverified = true;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800302 static const struct format_info {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600303 VkFormat_ format;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600304 size_t size;
305 uint32_t channel_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600306 } format_table[VK_NUM_FORMAT] = {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600307 { VK_FORMAT_UNDEFINED, 0, 0 },
308 { VK_FORMAT_R4G4_UNORM, 1, 2 },
309 { VK_FORMAT_R4G4_USCALED, 1, 2 },
310 { VK_FORMAT_R4G4B4A4_UNORM, 2, 4 },
311 { VK_FORMAT_R4G4B4A4_USCALED, 2, 4 },
312 { VK_FORMAT_R5G6B5_UNORM, 2, 3 },
313 { VK_FORMAT_R5G6B5_USCALED, 2, 3 },
314 { VK_FORMAT_R5G5B5A1_UNORM, 2, 4 },
315 { VK_FORMAT_R5G5B5A1_USCALED, 2, 4 },
316 { VK_FORMAT_R8_UNORM, 1, 1 },
317 { VK_FORMAT_R8_SNORM, 1, 1 },
318 { VK_FORMAT_R8_USCALED, 1, 1 },
319 { VK_FORMAT_R8_SSCALED, 1, 1 },
320 { VK_FORMAT_R8_UINT, 1, 1 },
321 { VK_FORMAT_R8_SINT, 1, 1 },
322 { VK_FORMAT_R8_SRGB, 1, 1 },
323 { VK_FORMAT_R8G8_UNORM, 2, 2 },
324 { VK_FORMAT_R8G8_SNORM, 2, 2 },
325 { VK_FORMAT_R8G8_USCALED, 2, 2 },
326 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
327 { VK_FORMAT_R8G8_UINT, 2, 2 },
328 { VK_FORMAT_R8G8_SINT, 2, 2 },
329 { VK_FORMAT_R8G8_SRGB, 2, 2 },
330 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
331 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
332 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
333 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
334 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
335 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
336 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
337 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
338 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
339 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
340 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
341 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
342 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
343 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
344 { VK_FORMAT_R10G10B10A2_UNORM, 4, 4 },
345 { VK_FORMAT_R10G10B10A2_SNORM, 4, 4 },
346 { VK_FORMAT_R10G10B10A2_USCALED, 4, 4 },
347 { VK_FORMAT_R10G10B10A2_SSCALED, 4, 4 },
348 { VK_FORMAT_R10G10B10A2_UINT, 4, 4 },
349 { VK_FORMAT_R10G10B10A2_SINT, 4, 4 },
350 { VK_FORMAT_R16_UNORM, 2, 1 },
351 { VK_FORMAT_R16_SNORM, 2, 1 },
352 { VK_FORMAT_R16_USCALED, 2, 1 },
353 { VK_FORMAT_R16_SSCALED, 2, 1 },
354 { VK_FORMAT_R16_UINT, 2, 1 },
355 { VK_FORMAT_R16_SINT, 2, 1 },
356 { VK_FORMAT_R16_SFLOAT, 2, 1 },
357 { VK_FORMAT_R16G16_UNORM, 4, 2 },
358 { VK_FORMAT_R16G16_SNORM, 4, 2 },
359 { VK_FORMAT_R16G16_USCALED, 4, 2 },
360 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
361 { VK_FORMAT_R16G16_UINT, 4, 2 },
362 { VK_FORMAT_R16G16_SINT, 4, 2 },
363 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
364 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
365 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
366 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
367 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
368 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
369 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
370 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
371 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
372 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
373 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
374 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
375 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
376 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
377 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
378 { VK_FORMAT_R32_UINT, 4, 1 },
379 { VK_FORMAT_R32_SINT, 4, 1 },
380 { VK_FORMAT_R32_SFLOAT, 4, 1 },
381 { VK_FORMAT_R32G32_UINT, 8, 2 },
382 { VK_FORMAT_R32G32_SINT, 8, 2 },
383 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
384 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
385 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
386 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
387 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
388 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
389 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
390 { VK_FORMAT_R64_SFLOAT, 8, 1 },
391 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
392 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
393 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
394 { VK_FORMAT_R11G11B10_UFLOAT, 4, 3 },
395 { VK_FORMAT_R9G9B9E5_UFLOAT, 4, 3 },
396 { VK_FORMAT_D16_UNORM, 2, 1 },
397 { VK_FORMAT_D24_UNORM, 3, 1 },
398 { VK_FORMAT_D32_SFLOAT, 4, 1 },
399 { VK_FORMAT_S8_UINT, 1, 1 },
400 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
401 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
402 { VK_FORMAT_D32_SFLOAT_S8_UINT, 4, 2 },
403 { VK_FORMAT_BC1_RGB_UNORM, 8, 4 },
404 { VK_FORMAT_BC1_RGB_SRGB, 8, 4 },
405 { VK_FORMAT_BC1_RGBA_UNORM, 8, 4 },
406 { VK_FORMAT_BC1_RGBA_SRGB, 8, 4 },
407 { VK_FORMAT_BC2_UNORM, 16, 4 },
408 { VK_FORMAT_BC2_SRGB, 16, 4 },
409 { VK_FORMAT_BC3_UNORM, 16, 4 },
410 { VK_FORMAT_BC3_SRGB, 16, 4 },
411 { VK_FORMAT_BC4_UNORM, 8, 4 },
412 { VK_FORMAT_BC4_SNORM, 8, 4 },
413 { VK_FORMAT_BC5_UNORM, 16, 4 },
414 { VK_FORMAT_BC5_SNORM, 16, 4 },
415 { VK_FORMAT_BC6H_UFLOAT, 16, 4 },
416 { VK_FORMAT_BC6H_SFLOAT, 16, 4 },
417 { VK_FORMAT_BC7_UNORM, 16, 4 },
418 { VK_FORMAT_BC7_SRGB, 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700419 // TODO: Initialize remaining compressed formats.
Tony Barbourae2d5f42015-05-14 17:15:33 -0600420 { VK_FORMAT_ETC2_R8G8B8_UNORM, 0, 0 },
421 { VK_FORMAT_ETC2_R8G8B8_SRGB, 0, 0 },
422 { VK_FORMAT_ETC2_R8G8B8A1_UNORM, 0, 0 },
423 { VK_FORMAT_ETC2_R8G8B8A1_SRGB, 0, 0 },
424 { VK_FORMAT_ETC2_R8G8B8A8_UNORM, 0, 0 },
425 { VK_FORMAT_ETC2_R8G8B8A8_SRGB, 0, 0 },
426 { VK_FORMAT_EAC_R11_UNORM, 0, 0 },
427 { VK_FORMAT_EAC_R11_SNORM, 0, 0 },
428 { VK_FORMAT_EAC_R11G11_UNORM, 0, 0 },
429 { VK_FORMAT_EAC_R11G11_SNORM, 0, 0 },
430 { VK_FORMAT_ASTC_4x4_UNORM, 0, 0 },
431 { VK_FORMAT_ASTC_4x4_SRGB, 0, 0 },
432 { VK_FORMAT_ASTC_5x4_UNORM, 0, 0 },
433 { VK_FORMAT_ASTC_5x4_SRGB, 0, 0 },
434 { VK_FORMAT_ASTC_5x5_UNORM, 0, 0 },
435 { VK_FORMAT_ASTC_5x5_SRGB, 0, 0 },
436 { VK_FORMAT_ASTC_6x5_UNORM, 0, 0 },
437 { VK_FORMAT_ASTC_6x5_SRGB, 0, 0 },
438 { VK_FORMAT_ASTC_6x6_UNORM, 0, 0 },
439 { VK_FORMAT_ASTC_6x6_SRGB, 0, 0 },
440 { VK_FORMAT_ASTC_8x5_UNORM, 0, 0 },
441 { VK_FORMAT_ASTC_8x5_SRGB, 0, 0 },
442 { VK_FORMAT_ASTC_8x6_UNORM, 0, 0 },
443 { VK_FORMAT_ASTC_8x6_SRGB, 0, 0 },
444 { VK_FORMAT_ASTC_8x8_UNORM, 0, 0 },
445 { VK_FORMAT_ASTC_8x8_SRGB, 0, 0 },
446 { VK_FORMAT_ASTC_10x5_UNORM, 0, 0 },
447 { VK_FORMAT_ASTC_10x5_SRGB, 0, 0 },
448 { VK_FORMAT_ASTC_10x6_UNORM, 0, 0 },
449 { VK_FORMAT_ASTC_10x6_SRGB, 0, 0 },
450 { VK_FORMAT_ASTC_10x8_UNORM, 0, 0 },
451 { VK_FORMAT_ASTC_10x8_SRGB, 0, 0 },
452 { VK_FORMAT_ASTC_10x10_UNORM, 0, 0 },
453 { VK_FORMAT_ASTC_10x10_SRGB, 0, 0 },
454 { VK_FORMAT_ASTC_12x10_UNORM, 0, 0 },
455 { VK_FORMAT_ASTC_12x10_SRGB, 0, 0 },
456 { VK_FORMAT_ASTC_12x12_UNORM, 0, 0 },
457 { VK_FORMAT_ASTC_12x12_SRGB, 0, 0 },
458 { VK_FORMAT_B4G4R4A4_UNORM, 2, 4 },
459 { VK_FORMAT_B5G5R5A1_UNORM, 2, 4 },
460 { VK_FORMAT_B5G6R5_UNORM, 2, 3 },
461 { VK_FORMAT_B5G6R5_USCALED, 2, 3 },
462 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
463 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
464 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
465 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
466 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
467 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
468 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
469 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
470 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
471 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
472 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
473 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
474 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
475 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
476 { VK_FORMAT_B10G10R10A2_UNORM, 4, 4 },
477 { VK_FORMAT_B10G10R10A2_SNORM, 4, 4 },
478 { VK_FORMAT_B10G10R10A2_USCALED, 4, 4 },
479 { VK_FORMAT_B10G10R10A2_SSCALED, 4, 4 },
480 { VK_FORMAT_B10G10R10A2_UINT, 4, 4 },
481 { VK_FORMAT_B10G10R10A2_SINT, 4, 4 },
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800482 };
Tony Barbourae2d5f42015-05-14 17:15:33 -0600483 if (format_table_unverified)
484 {
485 for (unsigned int i = 0; i < VK_NUM_FORMAT; i++)
486 {
487 assert(format_table[i].format == i);
488 }
489 format_table_unverified = false;
490 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800491
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700492 return format_table[format].size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800493}
494
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600495VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800496{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600497 const VkExtent3D ext = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800498 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
499 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
500 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
501 };
502
503 return ext;
504}
505
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600506}; // namespace vk_testing
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800507
508namespace {
509
510#define DO(action) ASSERT_EQ(true, action);
511
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600512static vk_testing::Environment *environment;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800513
Tony Barbour01999182015-04-09 12:58:51 -0600514class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800515protected:
Tony Barbour01999182015-04-09 12:58:51 -0600516 VkCmdBlitTest() :
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800517 dev_(environment->default_device()),
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800518 queue_(*dev_.graphics_queues()[0]),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600519 cmd_(dev_, vk_testing::CmdBuffer::create_info(dev_.graphics_queue_node_index_))
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800520 {
521 // make sure every test uses a different pattern
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600522 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800523 }
524
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800525 bool submit_and_done()
526 {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600527 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800528 queue_.wait();
529 mem_refs_.clear();
530 return true;
531 }
532
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600533 vk_testing::Device &dev_;
534 vk_testing::Queue &queue_;
535 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800536
Tony Barbour8205d902015-04-16 15:59:00 -0600537 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800538};
539
Tony Barbour01999182015-04-09 12:58:51 -0600540typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800541
Tony Barbour01999182015-04-09 12:58:51 -0600542TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800543{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600544 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600545 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800546
Tony Barbour94310562015-04-22 15:10:33 -0600547 buf.init(dev_, 20, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800548
549 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600550 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
551 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800552 cmd_.end();
553
554 submit_and_done();
555
556 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
557 EXPECT_EQ(0x11111111, data[0]);
558 EXPECT_EQ(0x22222222, data[1]);
559 EXPECT_EQ(0x22222222, data[2]);
560 EXPECT_EQ(0x22222222, data[3]);
561 EXPECT_EQ(0x22222222, data[4]);
562 buf.unmap();
563}
564
Tony Barbour01999182015-04-09 12:58:51 -0600565TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800566{
Tony Barbour8205d902015-04-16 15:59:00 -0600567 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600569 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800570
Tony Barbour94310562015-04-22 15:10:33 -0600571 buf.init(dev_, size, reqs);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800572
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800573 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600574 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
575 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800576 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800577
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800578 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800579
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800580 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600581 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800582 for (offset = 0; offset < size / 2; offset += 4)
583 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
584 for (; offset < size; offset += 4)
585 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
586 buf.unmap();
587}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800588
Tony Barbour01999182015-04-09 12:58:51 -0600589TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800590{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600591 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600592 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800593
Tony Barbour94310562015-04-22 15:10:33 -0600594 buf.init(dev_, 64, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800595
596 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600597 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
598 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800599 cmd_.end();
600
601 submit_and_done();
602
603 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600604 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800605 for (offset = 0; offset < 32; offset += 4)
606 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
607 for (; offset < 64; offset += 4)
608 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
609 buf.unmap();
610}
611
Tony Barbour01999182015-04-09 12:58:51 -0600612TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800613{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600614 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600615 VkDeviceSize size = 4;
Tony Barbour94310562015-04-22 15:10:33 -0600616 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800617
618 cmd_.begin();
619 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600620 bufs[i].init(dev_, size, reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800622 size <<= 1;
623 }
624 cmd_.end();
625
626 submit_and_done();
627
628 size = 4;
629 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
630 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600631 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800632 for (offset = 0; offset < size; offset += 4)
633 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
634 "Offset is: " << offset;
635 bufs[i].unmap();
636
637 size <<= 1;
638 }
639}
640
Tony Barbour01999182015-04-09 12:58:51 -0600641typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800642
Tony Barbour01999182015-04-09 12:58:51 -0600643TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800644{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600645 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600646 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800647
Tony Barbour94310562015-04-22 15:10:33 -0600648 src.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800649 uint32_t *data = static_cast<uint32_t *>(src.map());
650 data[0] = 0x11111111;
651 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800652
Tony Barbour94310562015-04-22 15:10:33 -0600653 dst.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800654
655 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600656 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800657 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800659 cmd_.end();
660
661 submit_and_done();
662
663 data = static_cast<uint32_t *>(dst.map());
664 EXPECT_EQ(0x11111111, data[0]);
665 dst.unmap();
666}
667
Tony Barbour01999182015-04-09 12:58:51 -0600668TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800669{
Tony Barbour8205d902015-04-16 15:59:00 -0600670 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600671 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600672 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800673
Tony Barbour94310562015-04-22 15:10:33 -0600674 src.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800675 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600676 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800677 for (offset = 0; offset < size; offset += 4)
678 data[offset / 4] = offset;
679 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800680
Tony Barbour94310562015-04-22 15:10:33 -0600681 dst.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800682
683 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600684 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800685 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600686 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800687 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800688
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800689 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800690
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800691 data = static_cast<uint32_t *>(dst.map());
692 for (offset = 0; offset < size; offset += 4)
693 EXPECT_EQ(offset, data[offset / 4]);
694 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800695}
696
Tony Barbour01999182015-04-09 12:58:51 -0600697TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800698{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600699 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800700 /* well aligned */
701 { 0, 0, 256 },
702 { 0, 256, 128 },
703 { 0, 384, 64 },
704 { 0, 448, 32 },
705 { 0, 480, 16 },
706 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800707
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800708 /* ill aligned */
709 { 7, 510, 16 },
710 { 16, 530, 13 },
711 { 32, 551, 16 },
712 { 45, 570, 15 },
713 { 50, 590, 1 },
714 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600715 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600716 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +0800717
Tony Barbour94310562015-04-22 15:10:33 -0600718 src.init(dev_, 256, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800719 uint8_t *data = static_cast<uint8_t *>(src.map());
720 for (int i = 0; i < 256; i++)
721 data[i] = i;
722 src.unmap();
Chia-I Wucb67c652014-10-21 11:06:26 +0800723
Tony Barbour94310562015-04-22 15:10:33 -0600724 dst.init(dev_, 1024, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800725
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800726 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600727 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800728 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800729
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800730 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800731
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800732 data = static_cast<uint8_t *>(dst.map());
733 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600734 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800735
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800736 for (int j = 0; j < r.copySize; j++) {
737 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
738 "Region is: " << i << "\n" <<
739 "Offset is: " << r.destOffset + j;
740 }
741 }
742 dst.unmap();
743}
Chia-I Wucb67c652014-10-21 11:06:26 +0800744
Tony Barbour01999182015-04-09 12:58:51 -0600745TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800746{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600747 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600748 VkEventCreateInfo event_info;
749 VkEvent event;
750 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000751 size_t data_size = sizeof(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 Barbour43cdc952015-05-21 13:26:05 -0600769 data_size = sizeof(mem_req);
Mike Stroyan230e6252015-04-17 12:36:38 -0600770 err = vkGetObjectInfo(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Tony Barbour43cdc952015-05-21 13:26:05 -0600771 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600772 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000773
Tony Barbour43cdc952015-05-21 13:26:05 -0600774 if (mem_req.size) {
Mike Stroyan55658c22014-12-04 11:08:39 +0000775
Tony Barbour43cdc952015-05-21 13:26:05 -0600776 // VkResult VKAPI vkAllocMemory(
777 // VkDevice device,
778 // const VkMemoryAllocInfo* pAllocInfo,
779 // VkDeviceMemory* pMem);
Mike Stroyan55658c22014-12-04 11:08:39 +0000780
Tony Barbour43cdc952015-05-21 13:26:05 -0600781 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000782
Tony Barbour43cdc952015-05-21 13:26:05 -0600783 memset(&mem_info, 0, sizeof(mem_info));
784 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
785 mem_info.allocationSize = mem_req.size;
786 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
787 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
788 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
789 ASSERT_VK_SUCCESS(err);
790
791 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
792 ASSERT_VK_SUCCESS(err);
793 }
Mike Stroyan55658c22014-12-04 11:08:39 +0000794
Mike Stroyan230e6252015-04-17 12:36:38 -0600795 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600796 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800797
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800798 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600799 bufs[i].init(dev_, 4, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800800
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800801 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
802 data[0] = 0x22222222 * (i + 1);
803 bufs[i].unmap();
804 }
805
806 cmd_.begin();
807
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600808 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800809 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600810 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600811 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600815 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 +0800816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800818 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600819 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000820
821 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600822 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600823 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600824 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 +0800825
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600826 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000827
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600828 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
829 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000830 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000832
833 // Additional commands could go into the buffer here before the wait.
834
835 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600836 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_HOST_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600837 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600838 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000839
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800840 cmd_.end();
841
842 submit_and_done();
843
844 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
845 EXPECT_EQ(0x11111111, data[0]);
846 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000847
Tony Barbour43cdc952015-05-21 13:26:05 -0600848 if (mem_req.size) {
849 // All done with event memory, clean up
850 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_NULL_HANDLE, 0);
851 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000852
Tony Barbour43cdc952015-05-21 13:26:05 -0600853 err = vkFreeMemory(dev_.obj(), event_mem);
854 ASSERT_VK_SUCCESS(err);
855 }
Mike Stroyan230e6252015-04-17 12:36:38 -0600856 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800858}
859
Tony Barbour01999182015-04-09 12:58:51 -0600860class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800861protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600862 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800863 {
Tony Barbour8205d902015-04-16 15:59:00 -0600864 first_linear_format_ = VK_FORMAT_UNDEFINED;
865 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800866
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600867 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800868 it != dev_.formats().end(); it++) {
869 if (it->features & features) {
870 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800871
Tony Barbour8205d902015-04-16 15:59:00 -0600872 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
873 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800874 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600875 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
876 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800877 first_optimal_format_ = it->format;
878 }
879 }
880 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800881
Chia-I Wu9feab842014-12-22 13:19:08 +0800882 void init_test_formats()
883 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600884 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800885 }
886
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600887 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800888 {
889 if (img.transparent()) {
890 checker.fill(img);
891 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800892 }
893
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800894 ASSERT_EQ(true, img.copyable());
895
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600896 vk_testing::Buffer in_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600897 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
898
899 in_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800900 checker.fill(in_buf);
901
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800902 // copy in and tile
903 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600904 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
905 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800906 checker.regions().size(), &checker.regions()[0]);
907 cmd_.end();
908
909 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800910 }
911
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600912 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800913 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800914 if (img.transparent()) {
915 DO(checker.check(img));
916 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800917 }
918
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800919 ASSERT_EQ(true, img.copyable());
920
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600921 vk_testing::Buffer out_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600922 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
923 out_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800924
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800925 // copy out and linearize
926 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600927 vkCmdCopyImageToBuffer(cmd_.obj(),
928 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600929 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800930 checker.regions().size(), &checker.regions()[0]);
931 cmd_.end();
932
933 submit_and_done();
934
935 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800936 }
937
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600938 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600939 VkFormat first_linear_format_;
940 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800941};
942
Tony Barbour01999182015-04-09 12:58:51 -0600943class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800944protected:
945 virtual void SetUp()
946 {
Tony Barbour01999182015-04-09 12:58:51 -0600947 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600948 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800949 ASSERT_NE(true, test_formats_.empty());
950 }
951
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600952 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800953 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600954 vk_testing::Buffer buf;
955 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -0600956 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
957 VkMemoryPropertyFlags image_reqs =
958 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800959
Tony Barbour43cdc952015-05-21 13:26:05 -0600960 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800961 checker.fill(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800962
Tony Barbour43cdc952015-05-21 13:26:05 -0600963 img.init(dev_, img_info, image_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800964
965 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600966 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600967 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600968 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800969 checker.regions().size(), &checker.regions()[0]);
970 cmd_.end();
971
972 submit_and_done();
973
974 check_dst(img, checker);
975 }
976
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600977 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800978 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600979 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800980 test_copy_memory_to_image(img_info, checker);
981 }
982
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600983 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800984 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600985 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800986 test_copy_memory_to_image(img_info, checker);
987 }
988};
989
Tony Barbour01999182015-04-09 12:58:51 -0600990TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800991{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600992 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800993 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700994
995 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -0600996 if (it->format == VK_FORMAT_UNDEFINED ||
997 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
998 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700999 continue;
1000
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001001 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001002 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001003 img_info.format = it->format;
1004 img_info.extent.width = 64;
1005 img_info.extent.height = 64;
1006 img_info.tiling = it->tiling;
1007
1008 test_copy_memory_to_image(img_info);
1009 }
Chia-I Wu86822632014-11-22 15:09:42 +08001010}
1011
Tony Barbour01999182015-04-09 12:58:51 -06001012class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001013protected:
1014 virtual void SetUp()
1015 {
Tony Barbour01999182015-04-09 12:58:51 -06001016 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001017 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001018 ASSERT_NE(true, test_formats_.empty());
1019 }
1020
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001021 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001022 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001023 vk_testing::Image img;
1024 vk_testing::Buffer buf;
Tony Barbour43cdc952015-05-21 13:26:05 -06001025 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1026 VkMemoryPropertyFlags image_reqs =
1027 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu830fb332014-12-13 15:28:20 +08001028
Tony Barbour43cdc952015-05-21 13:26:05 -06001029 img.init(dev_, img_info, image_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001030 fill_src(img, checker);
Chia-I Wu830fb332014-12-13 15:28:20 +08001031
Tony Barbour43cdc952015-05-21 13:26:05 -06001032 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001033
1034 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001035 vkCmdCopyImageToBuffer(cmd_.obj(),
1036 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001037 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001038 checker.regions().size(), &checker.regions()[0]);
1039 cmd_.end();
1040
1041 submit_and_done();
1042
1043 checker.check(buf);
1044 }
1045
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001046 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001047 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001048 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001049 test_copy_image_to_memory(img_info, checker);
1050 }
1051
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001052 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001053 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001055 test_copy_image_to_memory(img_info, checker);
1056 }
1057};
1058
Tony Barbour01999182015-04-09 12:58:51 -06001059TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001060{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001061 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001062 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001063
1064 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001065 if (it->format == VK_FORMAT_UNDEFINED ||
1066 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1067 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001068 continue;
1069
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001071 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001072 img_info.format = it->format;
1073 img_info.extent.width = 64;
1074 img_info.extent.height = 64;
1075 img_info.tiling = it->tiling;
1076
1077 test_copy_image_to_memory(img_info);
1078 }
1079}
1080
Tony Barbour01999182015-04-09 12:58:51 -06001081class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001082protected:
1083 virtual void SetUp()
1084 {
Tony Barbour01999182015-04-09 12:58:51 -06001085 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001086 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001087 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001088 }
1089
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001090 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1091 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001092 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001093 // convert VkImageCopy to two sets of VkBufferImageCopy
1094 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001095 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1097 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001098
Chia-I Wu714df452015-01-01 07:55:04 +08001099 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001100 src_region.imageSubresource = it->srcSubresource;
1101 src_region.imageOffset = it->srcOffset;
1102 src_region.imageExtent = it->extent;
1103 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001104
Chia-I Wu714df452015-01-01 07:55:04 +08001105 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001106 dst_region.imageSubresource = it->destSubresource;
1107 dst_region.imageOffset = it->destOffset;
1108 dst_region.imageExtent = it->extent;
1109 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001110
Tony Barbour8205d902015-04-16 15:59:00 -06001111 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001112 src_offset += vk_testing::get_format_size(src_info.format) * size;
1113 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001114 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001115
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001116 vk_testing::ImageChecker src_checker(src_info, src_regions);
1117 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour43cdc952015-05-21 13:26:05 -06001118 VkMemoryPropertyFlags src_reqs =
1119 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1120 VkMemoryPropertyFlags dst_reqs =
1121 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1122
1123
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001124
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 vk_testing::Image src;
Tony Barbour43cdc952015-05-21 13:26:05 -06001126 src.init(dev_, src_info, src_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001127 fill_src(src, src_checker);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001128
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001129 vk_testing::Image dst;
Tony Barbour43cdc952015-05-21 13:26:05 -06001130 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001131
1132 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001133 vkCmdCopyImage(cmd_.obj(),
1134 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1135 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001136 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001137 cmd_.end();
1138
1139 submit_and_done();
1140
1141 check_dst(dst, dst_checker);
1142 }
1143};
1144
Tony Barbour01999182015-04-09 12:58:51 -06001145TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001146{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001147 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001148 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001149
1150 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001151 if (it->format == VK_FORMAT_UNDEFINED ||
1152 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1153 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001154 continue;
1155
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001156 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001157 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001158 img_info.format = it->format;
1159 img_info.extent.width = 64;
1160 img_info.extent.height = 64;
1161 img_info.tiling = it->tiling;
1162
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001163 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001164 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001165 copy.destSubresource = copy.srcSubresource;
1166 copy.extent = img_info.extent;
1167
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001168 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001169 }
1170}
1171
Tony Barbour01999182015-04-09 12:58:51 -06001172class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001173protected:
Tony Barbour01999182015-04-09 12:58:51 -06001174 VkCmdClearColorImageTest() : test_raw_(false) {}
1175 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001176
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001177 virtual void SetUp()
1178 {
Tony Barbour01999182015-04-09 12:58:51 -06001179 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001180
1181 if (test_raw_)
1182 init_test_formats();
1183 else
Tony Barbour8205d902015-04-16 15:59:00 -06001184 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001185
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001186 ASSERT_NE(true, test_formats_.empty());
1187 }
1188
Chia-I Wu9feab842014-12-22 13:19:08 +08001189 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001190 float color[4];
1191 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001192 };
1193
1194 bool test_raw_;
1195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001196 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001197 {
1198 std::vector<uint8_t> raw;
1199
1200 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001201 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001202 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001203 raw.push_back(color[0] * 255.0f);
1204 raw.push_back(color[1] * 255.0f);
1205 raw.push_back(color[2] * 255.0f);
1206 raw.push_back(color[3] * 255.0f);
1207 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001208 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001209 raw.push_back(color[2] * 255.0f);
1210 raw.push_back(color[1] * 255.0f);
1211 raw.push_back(color[0] * 255.0f);
1212 raw.push_back(color[3] * 255.0f);
1213 break;
1214 default:
1215 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001216 }
1217
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001218 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001219 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001220
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001221 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001222 {
1223 std::vector<uint8_t> raw;
1224
1225 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001226 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001227 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001228 raw.push_back(static_cast<uint8_t>(color[0]));
1229 raw.push_back(static_cast<uint8_t>(color[1]));
1230 raw.push_back(static_cast<uint8_t>(color[2]));
1231 raw.push_back(static_cast<uint8_t>(color[3]));
1232 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001233 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001234 raw.push_back(static_cast<uint8_t>(color[2]));
1235 raw.push_back(static_cast<uint8_t>(color[1]));
1236 raw.push_back(static_cast<uint8_t>(color[0]));
1237 raw.push_back(static_cast<uint8_t>(color[3]));
1238 break;
1239 default:
1240 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001241 }
1242
1243 return raw;
1244 }
1245
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001246 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001247 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001248 if (color.useRawValue)
1249 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001250 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001251 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001252 }
1253
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001254 void test_clear_color_image(const VkImageCreateInfo &img_info,
1255 const VkClearColor &clear_color,
1256 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001257 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001258 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001259 VkMemoryPropertyFlags image_reqs =
1260 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001261
Tony Barbour43cdc952015-05-21 13:26:05 -06001262 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001263 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001264 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001265 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1266 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1267 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001268 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001269 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001270 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001271 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1272 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1273 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1274 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1275 VK_MEMORY_INPUT_SHADER_READ_BIT |
1276 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1277 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001278 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001279
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001280 std::vector<VkImageMemoryBarrier> to_clear;
1281 std::vector<VkImageMemoryBarrier *> p_to_clear;
1282 std::vector<VkImageMemoryBarrier> to_xfer;
1283 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001284
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001285 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001286 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001287 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001288 VK_IMAGE_LAYOUT_GENERAL,
1289 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001290 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001291 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001292 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001293 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1294 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001295 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001296 }
1297
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001298 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001299
Tony Barbour8205d902015-04-16 15:59:00 -06001300 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1301 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 +00001302
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 vkCmdClearColorImage(cmd_.obj(),
1304 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06001305 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001306
Tony Barbour8205d902015-04-16 15:59:00 -06001307 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 +08001308
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001309 cmd_.end();
1310
1311 submit_and_done();
1312
1313 // cannot verify
1314 if (!img.transparent() && !img.copyable())
1315 return;
1316
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001317 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001318
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001319 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001320 if (solid_pattern.empty())
1321 return;
1322
1323 checker.set_solid_pattern(solid_pattern);
1324 check_dst(img, checker);
1325 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001326
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001327 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001328 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001329 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001330 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001331 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001332 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001333 test_clear_color_image(img_info, c, ranges);
1334 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001335};
1336
Tony Barbour01999182015-04-09 12:58:51 -06001337TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001338{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001339 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001340 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001341 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001343 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001344 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001345 img_info.format = it->format;
1346 img_info.extent.width = 64;
1347 img_info.extent.height = 64;
1348 img_info.tiling = it->tiling;
1349
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001350 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001351 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001353
1354 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001355 }
1356}
1357
Tony Barbour01999182015-04-09 12:58:51 -06001358class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001359protected:
Tony Barbour01999182015-04-09 12:58:51 -06001360 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001361
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001362 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001363 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001364 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001365 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001366 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001367 c.useRawValue = true;
1368 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001369 test_clear_color_image(img_info, c, ranges);
1370 }
1371};
1372
Tony Barbour01999182015-04-09 12:58:51 -06001373TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001374{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001375 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001376 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001377 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001378
1379 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001380 if (it->format == VK_FORMAT_UNDEFINED ||
1381 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1382 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1383 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1384 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1385 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1386 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1387 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1388 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1389 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1390 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1391 (it->format >= VK_FORMAT_D16_UNORM &&
1392 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001393 continue;
1394
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001395 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001396 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001397 img_info.format = it->format;
1398 img_info.extent.width = 64;
1399 img_info.extent.height = 64;
1400 img_info.tiling = it->tiling;
1401
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001402 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001403 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001404 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001405
1406 test_clear_color_image_raw(img_info, color, ranges);
1407 }
1408}
1409
Tony Barbour01999182015-04-09 12:58:51 -06001410class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001411protected:
1412 virtual void SetUp()
1413 {
Tony Barbour01999182015-04-09 12:58:51 -06001414 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001415 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001416 ASSERT_NE(true, test_formats_.empty());
1417 }
1418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001419 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001420 {
1421 std::vector<uint8_t> raw;
1422
1423 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001424 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001425 case VK_FORMAT_D16_UNORM:
1426 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001427 {
1428 const uint16_t unorm = depth * 65535.0f;
1429 raw.push_back(unorm & 0xff);
1430 raw.push_back(unorm >> 8);
1431 }
1432 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001433 case VK_FORMAT_D32_SFLOAT:
1434 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001435 {
1436 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001437 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001438 uint32_t u32;
1439 } u = { depth };
1440
1441 raw.push_back((u.u32 ) & 0xff);
1442 raw.push_back((u.u32 >> 8) & 0xff);
1443 raw.push_back((u.u32 >> 16) & 0xff);
1444 raw.push_back((u.u32 >> 24) & 0xff);
1445 }
1446 break;
1447 default:
1448 break;
1449 }
1450
1451 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001452 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001453 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001454 raw.push_back(stencil);
1455 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001456 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001457 raw.push_back(stencil);
1458 raw.push_back(0);
1459 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001460 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001461 raw.push_back(stencil);
1462 raw.push_back(0);
1463 raw.push_back(0);
1464 raw.push_back(0);
1465 break;
1466 default:
1467 break;
1468 }
1469
1470 return raw;
1471 }
1472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001474 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001475 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001476 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001477 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001478 VkMemoryPropertyFlags image_reqs =
1479 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001480
Tony Barbour43cdc952015-05-21 13:26:05 -06001481 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001482 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001483 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001484 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1485 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1486 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001487 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001488 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001489 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001490 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1491 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1492 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1493 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1494 VK_MEMORY_INPUT_SHADER_READ_BIT |
1495 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1496 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001497 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001499 std::vector<VkImageMemoryBarrier> to_clear;
1500 std::vector<VkImageMemoryBarrier *> p_to_clear;
1501 std::vector<VkImageMemoryBarrier> to_xfer;
1502 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001503
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001504 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001505 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001506 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001507 VK_IMAGE_LAYOUT_GENERAL,
1508 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001509 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001510 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001511 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001512 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1513 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001514 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001515 }
1516
1517 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001518
Tony Barbour8205d902015-04-16 15:59:00 -06001519 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1520 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 +00001521
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001522 vkCmdClearDepthStencil(cmd_.obj(),
1523 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001524 depth, stencil,
1525 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001526
Tony Barbour8205d902015-04-16 15:59:00 -06001527 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 +00001528
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001529 cmd_.end();
1530
1531 submit_and_done();
1532
1533 // cannot verify
1534 if (!img.transparent() && !img.copyable())
1535 return;
1536
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001537 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001538
1539 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1540 check_dst(img, checker);
1541 }
1542};
1543
Tony Barbour01999182015-04-09 12:58:51 -06001544TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001545{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001546 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001547 it != test_formats_.end(); it++) {
1548 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001549 if (it->format == VK_FORMAT_S8_UINT ||
1550 it->format == VK_FORMAT_D24_UNORM ||
1551 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1552 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001553 continue;
1554
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001555 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001556 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001557 img_info.format = it->format;
1558 img_info.extent.width = 64;
1559 img_info.extent.height = 64;
1560 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001561 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001563 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001564 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001565 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001566
1567 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1568 }
1569}
1570
1571}; // namespace
1572
Chia-I Wucb67c652014-10-21 11:06:26 +08001573int main(int argc, char **argv)
1574{
Chia-I Wucb67c652014-10-21 11:06:26 +08001575 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001577 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001579 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001580
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001581 if (!environment->parse_args(argc, argv))
1582 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001583
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001584 ::testing::AddGlobalTestEnvironment(environment);
1585
1586 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001587}