blob: cf2fd985efe2b4df4770d9033523b519c9faf89a [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());
165 for (int i = 0; i < buffer_cpp(); i++)
166 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 {
222 for (int i = 0; i < val.size(); i++) {
223 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());
293 for (int i = 0; i < buffer_cpp(); i++)
294 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{
301 static const struct format_info {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600302 size_t size;
303 uint32_t channel_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600304 } format_table[VK_NUM_FORMAT] = {
305 [VK_FORMAT_UNDEFINED] = { 0, 0 },
306 [VK_FORMAT_R4G4_UNORM] = { 1, 2 },
307 [VK_FORMAT_R4G4_USCALED] = { 1, 2 },
308 [VK_FORMAT_R4G4B4A4_UNORM] = { 2, 4 },
309 [VK_FORMAT_R4G4B4A4_USCALED] = { 2, 4 },
310 [VK_FORMAT_R5G6B5_UNORM] = { 2, 3 },
311 [VK_FORMAT_R5G6B5_USCALED] = { 2, 3 },
312 [VK_FORMAT_R5G5B5A1_UNORM] = { 2, 4 },
313 [VK_FORMAT_R5G5B5A1_USCALED] = { 2, 4 },
314 [VK_FORMAT_R8_UNORM] = { 1, 1 },
315 [VK_FORMAT_R8_SNORM] = { 1, 1 },
316 [VK_FORMAT_R8_USCALED] = { 1, 1 },
317 [VK_FORMAT_R8_SSCALED] = { 1, 1 },
318 [VK_FORMAT_R8_UINT] = { 1, 1 },
319 [VK_FORMAT_R8_SINT] = { 1, 1 },
320 [VK_FORMAT_R8_SRGB] = { 1, 1 },
321 [VK_FORMAT_R8G8_UNORM] = { 2, 2 },
322 [VK_FORMAT_R8G8_SNORM] = { 2, 2 },
323 [VK_FORMAT_R8G8_USCALED] = { 2, 2 },
324 [VK_FORMAT_R8G8_SSCALED] = { 2, 2 },
325 [VK_FORMAT_R8G8_UINT] = { 2, 2 },
326 [VK_FORMAT_R8G8_SINT] = { 2, 2 },
327 [VK_FORMAT_R8G8_SRGB] = { 2, 2 },
328 [VK_FORMAT_R8G8B8_UNORM] = { 3, 3 },
329 [VK_FORMAT_R8G8B8_SNORM] = { 3, 3 },
330 [VK_FORMAT_R8G8B8_USCALED] = { 3, 3 },
331 [VK_FORMAT_R8G8B8_SSCALED] = { 3, 3 },
332 [VK_FORMAT_R8G8B8_UINT] = { 3, 3 },
333 [VK_FORMAT_R8G8B8_SINT] = { 3, 3 },
334 [VK_FORMAT_R8G8B8_SRGB] = { 3, 3 },
335 [VK_FORMAT_R8G8B8A8_UNORM] = { 4, 4 },
336 [VK_FORMAT_R8G8B8A8_SNORM] = { 4, 4 },
337 [VK_FORMAT_R8G8B8A8_USCALED] = { 4, 4 },
338 [VK_FORMAT_R8G8B8A8_SSCALED] = { 4, 4 },
339 [VK_FORMAT_R8G8B8A8_UINT] = { 4, 4 },
340 [VK_FORMAT_R8G8B8A8_SINT] = { 4, 4 },
341 [VK_FORMAT_R8G8B8A8_SRGB] = { 4, 4 },
342 [VK_FORMAT_R10G10B10A2_UNORM] = { 4, 4 },
343 [VK_FORMAT_R10G10B10A2_SNORM] = { 4, 4 },
344 [VK_FORMAT_R10G10B10A2_USCALED] = { 4, 4 },
345 [VK_FORMAT_R10G10B10A2_SSCALED] = { 4, 4 },
346 [VK_FORMAT_R10G10B10A2_UINT] = { 4, 4 },
347 [VK_FORMAT_R10G10B10A2_SINT] = { 4, 4 },
348 [VK_FORMAT_R16_UNORM] = { 2, 1 },
349 [VK_FORMAT_R16_SNORM] = { 2, 1 },
350 [VK_FORMAT_R16_USCALED] = { 2, 1 },
351 [VK_FORMAT_R16_SSCALED] = { 2, 1 },
352 [VK_FORMAT_R16_UINT] = { 2, 1 },
353 [VK_FORMAT_R16_SINT] = { 2, 1 },
354 [VK_FORMAT_R16_SFLOAT] = { 2, 1 },
355 [VK_FORMAT_R16G16_UNORM] = { 4, 2 },
356 [VK_FORMAT_R16G16_SNORM] = { 4, 2 },
357 [VK_FORMAT_R16G16_USCALED] = { 4, 2 },
358 [VK_FORMAT_R16G16_SSCALED] = { 4, 2 },
359 [VK_FORMAT_R16G16_UINT] = { 4, 2 },
360 [VK_FORMAT_R16G16_SINT] = { 4, 2 },
361 [VK_FORMAT_R16G16_SFLOAT] = { 4, 2 },
362 [VK_FORMAT_R16G16B16_UNORM] = { 6, 3 },
363 [VK_FORMAT_R16G16B16_SNORM] = { 6, 3 },
364 [VK_FORMAT_R16G16B16_USCALED] = { 6, 3 },
365 [VK_FORMAT_R16G16B16_SSCALED] = { 6, 3 },
366 [VK_FORMAT_R16G16B16_UINT] = { 6, 3 },
367 [VK_FORMAT_R16G16B16_SINT] = { 6, 3 },
368 [VK_FORMAT_R16G16B16_SFLOAT] = { 6, 3 },
369 [VK_FORMAT_R16G16B16A16_UNORM] = { 8, 4 },
370 [VK_FORMAT_R16G16B16A16_SNORM] = { 8, 4 },
371 [VK_FORMAT_R16G16B16A16_USCALED] = { 8, 4 },
372 [VK_FORMAT_R16G16B16A16_SSCALED] = { 8, 4 },
373 [VK_FORMAT_R16G16B16A16_UINT] = { 8, 4 },
374 [VK_FORMAT_R16G16B16A16_SINT] = { 8, 4 },
375 [VK_FORMAT_R16G16B16A16_SFLOAT] = { 8, 4 },
376 [VK_FORMAT_R32_UINT] = { 4, 1 },
377 [VK_FORMAT_R32_SINT] = { 4, 1 },
378 [VK_FORMAT_R32_SFLOAT] = { 4, 1 },
379 [VK_FORMAT_R32G32_UINT] = { 8, 2 },
380 [VK_FORMAT_R32G32_SINT] = { 8, 2 },
381 [VK_FORMAT_R32G32_SFLOAT] = { 8, 2 },
382 [VK_FORMAT_R32G32B32_UINT] = { 12, 3 },
383 [VK_FORMAT_R32G32B32_SINT] = { 12, 3 },
384 [VK_FORMAT_R32G32B32_SFLOAT] = { 12, 3 },
385 [VK_FORMAT_R32G32B32A32_UINT] = { 16, 4 },
386 [VK_FORMAT_R32G32B32A32_SINT] = { 16, 4 },
387 [VK_FORMAT_R32G32B32A32_SFLOAT] = { 16, 4 },
388 [VK_FORMAT_R64_SFLOAT] = { 8, 1 },
389 [VK_FORMAT_R64G64_SFLOAT] = { 16, 2 },
390 [VK_FORMAT_R64G64B64_SFLOAT] = { 24, 3 },
391 [VK_FORMAT_R64G64B64A64_SFLOAT] = { 32, 4 },
392 [VK_FORMAT_R11G11B10_UFLOAT] = { 4, 3 },
393 [VK_FORMAT_R9G9B9E5_UFLOAT] = { 4, 3 },
394 [VK_FORMAT_D16_UNORM] = { 2, 1 },
395 [VK_FORMAT_D24_UNORM] = { 3, 1 },
396 [VK_FORMAT_D32_SFLOAT] = { 4, 1 },
397 [VK_FORMAT_S8_UINT] = { 1, 1 },
398 [VK_FORMAT_D16_UNORM_S8_UINT] = { 3, 2 },
399 [VK_FORMAT_D24_UNORM_S8_UINT] = { 4, 2 },
400 [VK_FORMAT_D32_SFLOAT_S8_UINT] = { 4, 2 },
401 [VK_FORMAT_BC1_RGB_UNORM] = { 8, 4 },
402 [VK_FORMAT_BC1_RGB_SRGB] = { 8, 4 },
403 [VK_FORMAT_BC1_RGBA_UNORM] = { 8, 4 },
404 [VK_FORMAT_BC1_RGBA_SRGB] = { 8, 4 },
405 [VK_FORMAT_BC2_UNORM] = { 16, 4 },
406 [VK_FORMAT_BC2_SRGB] = { 16, 4 },
407 [VK_FORMAT_BC3_UNORM] = { 16, 4 },
408 [VK_FORMAT_BC3_SRGB] = { 16, 4 },
409 [VK_FORMAT_BC4_UNORM] = { 8, 4 },
410 [VK_FORMAT_BC4_SNORM] = { 8, 4 },
411 [VK_FORMAT_BC5_UNORM] = { 16, 4 },
412 [VK_FORMAT_BC5_SNORM] = { 16, 4 },
413 [VK_FORMAT_BC6H_UFLOAT] = { 16, 4 },
414 [VK_FORMAT_BC6H_SFLOAT] = { 16, 4 },
415 [VK_FORMAT_BC7_UNORM] = { 16, 4 },
416 [VK_FORMAT_BC7_SRGB] = { 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700417 // TODO: Initialize remaining compressed formats.
Tony Barbour8205d902015-04-16 15:59:00 -0600418 [VK_FORMAT_ETC2_R8G8B8_UNORM] = { 0, 0 },
419 [VK_FORMAT_ETC2_R8G8B8_SRGB] = { 0, 0 },
420 [VK_FORMAT_ETC2_R8G8B8A1_UNORM] = { 0, 0 },
421 [VK_FORMAT_ETC2_R8G8B8A1_SRGB] = { 0, 0 },
422 [VK_FORMAT_ETC2_R8G8B8A8_UNORM] = { 0, 0 },
423 [VK_FORMAT_ETC2_R8G8B8A8_SRGB] = { 0, 0 },
424 [VK_FORMAT_EAC_R11_UNORM] = { 0, 0 },
425 [VK_FORMAT_EAC_R11_SNORM] = { 0, 0 },
426 [VK_FORMAT_EAC_R11G11_UNORM] = { 0, 0 },
427 [VK_FORMAT_EAC_R11G11_SNORM] = { 0, 0 },
428 [VK_FORMAT_ASTC_4x4_UNORM] = { 0, 0 },
429 [VK_FORMAT_ASTC_4x4_SRGB] = { 0, 0 },
430 [VK_FORMAT_ASTC_5x4_UNORM] = { 0, 0 },
431 [VK_FORMAT_ASTC_5x4_SRGB] = { 0, 0 },
432 [VK_FORMAT_ASTC_5x5_UNORM] = { 0, 0 },
433 [VK_FORMAT_ASTC_5x5_SRGB] = { 0, 0 },
434 [VK_FORMAT_ASTC_6x5_UNORM] = { 0, 0 },
435 [VK_FORMAT_ASTC_6x5_SRGB] = { 0, 0 },
436 [VK_FORMAT_ASTC_6x6_UNORM] = { 0, 0 },
437 [VK_FORMAT_ASTC_6x6_SRGB] = { 0, 0 },
438 [VK_FORMAT_ASTC_8x5_UNORM] = { 0, 0 },
439 [VK_FORMAT_ASTC_8x5_SRGB] = { 0, 0 },
440 [VK_FORMAT_ASTC_8x6_UNORM] = { 0, 0 },
441 [VK_FORMAT_ASTC_8x6_SRGB] = { 0, 0 },
442 [VK_FORMAT_ASTC_8x8_UNORM] = { 0, 0 },
443 [VK_FORMAT_ASTC_8x8_SRGB] = { 0, 0 },
444 [VK_FORMAT_ASTC_10x5_UNORM] = { 0, 0 },
445 [VK_FORMAT_ASTC_10x5_SRGB] = { 0, 0 },
446 [VK_FORMAT_ASTC_10x6_UNORM] = { 0, 0 },
447 [VK_FORMAT_ASTC_10x6_SRGB] = { 0, 0 },
448 [VK_FORMAT_ASTC_10x8_UNORM] = { 0, 0 },
449 [VK_FORMAT_ASTC_10x8_SRGB] = { 0, 0 },
450 [VK_FORMAT_ASTC_10x10_UNORM] = { 0, 0 },
451 [VK_FORMAT_ASTC_10x10_SRGB] = { 0, 0 },
452 [VK_FORMAT_ASTC_12x10_UNORM] = { 0, 0 },
453 [VK_FORMAT_ASTC_12x10_SRGB] = { 0, 0 },
454 [VK_FORMAT_ASTC_12x12_UNORM] = { 0, 0 },
455 [VK_FORMAT_ASTC_12x12_SRGB] = { 0, 0 },
456 [VK_FORMAT_B4G4R4A4_UNORM] = { 2, 4 },
457 [VK_FORMAT_B5G5R5A1_UNORM] = { 2, 4 },
458 [VK_FORMAT_B5G6R5_UNORM] = { 2, 3 },
459 [VK_FORMAT_B5G6R5_USCALED] = { 2, 3 },
460 [VK_FORMAT_B8G8R8_UNORM] = { 3, 3 },
461 [VK_FORMAT_B8G8R8_SNORM] = { 3, 3 },
462 [VK_FORMAT_B8G8R8_USCALED] = { 3, 3 },
463 [VK_FORMAT_B8G8R8_SSCALED] = { 3, 3 },
464 [VK_FORMAT_B8G8R8_UINT] = { 3, 3 },
465 [VK_FORMAT_B8G8R8_SINT] = { 3, 3 },
466 [VK_FORMAT_B8G8R8_SRGB] = { 3, 3 },
467 [VK_FORMAT_B8G8R8A8_UNORM] = { 4, 4 },
468 [VK_FORMAT_B8G8R8A8_SNORM] = { 4, 4 },
469 [VK_FORMAT_B8G8R8A8_USCALED] = { 4, 4 },
470 [VK_FORMAT_B8G8R8A8_SSCALED] = { 4, 4 },
471 [VK_FORMAT_B8G8R8A8_UINT] = { 4, 4 },
472 [VK_FORMAT_B8G8R8A8_SINT] = { 4, 4 },
473 [VK_FORMAT_B8G8R8A8_SRGB] = { 4, 4 },
474 [VK_FORMAT_B10G10R10A2_UNORM] = { 4, 4 },
475 [VK_FORMAT_B10G10R10A2_SNORM] = { 4, 4 },
476 [VK_FORMAT_B10G10R10A2_USCALED] = { 4, 4 },
477 [VK_FORMAT_B10G10R10A2_SSCALED] = { 4, 4 },
478 [VK_FORMAT_B10G10R10A2_UINT] = { 4, 4 },
479 [VK_FORMAT_B10G10R10A2_SINT] = { 4, 4 },
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800480 };
481
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700482 return format_table[format].size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800483}
484
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800486{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600487 const VkExtent3D ext = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800488 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
489 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
490 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
491 };
492
493 return ext;
494}
495
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496}; // namespace vk_testing
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800497
498namespace {
499
500#define DO(action) ASSERT_EQ(true, action);
501
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600502static vk_testing::Environment *environment;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800503
Tony Barbour01999182015-04-09 12:58:51 -0600504class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800505protected:
Tony Barbour01999182015-04-09 12:58:51 -0600506 VkCmdBlitTest() :
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800507 dev_(environment->default_device()),
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800508 queue_(*dev_.graphics_queues()[0]),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600509 cmd_(dev_, vk_testing::CmdBuffer::create_info(dev_.graphics_queue_node_index_))
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800510 {
511 // make sure every test uses a different pattern
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600512 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800513 }
514
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800515 bool submit_and_done()
516 {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600517 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800518 queue_.wait();
519 mem_refs_.clear();
520 return true;
521 }
522
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600523 vk_testing::Device &dev_;
524 vk_testing::Queue &queue_;
525 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800526
Tony Barbour8205d902015-04-16 15:59:00 -0600527 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800528};
529
Tony Barbour01999182015-04-09 12:58:51 -0600530typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800531
Tony Barbour01999182015-04-09 12:58:51 -0600532TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800533{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600534 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600535 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800536
Tony Barbour94310562015-04-22 15:10:33 -0600537 buf.init(dev_, 20, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800538
539 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
541 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800542 cmd_.end();
543
544 submit_and_done();
545
546 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
547 EXPECT_EQ(0x11111111, data[0]);
548 EXPECT_EQ(0x22222222, data[1]);
549 EXPECT_EQ(0x22222222, data[2]);
550 EXPECT_EQ(0x22222222, data[3]);
551 EXPECT_EQ(0x22222222, data[4]);
552 buf.unmap();
553}
554
Tony Barbour01999182015-04-09 12:58:51 -0600555TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800556{
Tony Barbour8205d902015-04-16 15:59:00 -0600557 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600558 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600559 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800560
Tony Barbour94310562015-04-22 15:10:33 -0600561 buf.init(dev_, size, reqs);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800562
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800563 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600564 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
565 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800566 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800567
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800568 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800569
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800570 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600571 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800572 for (offset = 0; offset < size / 2; offset += 4)
573 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
574 for (; offset < size; offset += 4)
575 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
576 buf.unmap();
577}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800578
Tony Barbour01999182015-04-09 12:58:51 -0600579TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800580{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600582 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800583
Tony Barbour94310562015-04-22 15:10:33 -0600584 buf.init(dev_, 64, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800585
586 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600587 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
588 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800589 cmd_.end();
590
591 submit_and_done();
592
593 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600594 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800595 for (offset = 0; offset < 32; offset += 4)
596 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
597 for (; offset < 64; offset += 4)
598 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
599 buf.unmap();
600}
601
Tony Barbour01999182015-04-09 12:58:51 -0600602TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800603{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600604 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600605 VkDeviceSize size = 4;
Tony Barbour94310562015-04-22 15:10:33 -0600606 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800607
608 cmd_.begin();
609 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600610 bufs[i].init(dev_, size, reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600611 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800612 size <<= 1;
613 }
614 cmd_.end();
615
616 submit_and_done();
617
618 size = 4;
619 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
620 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600621 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800622 for (offset = 0; offset < size; offset += 4)
623 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
624 "Offset is: " << offset;
625 bufs[i].unmap();
626
627 size <<= 1;
628 }
629}
630
Tony Barbour01999182015-04-09 12:58:51 -0600631typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800632
Tony Barbour01999182015-04-09 12:58:51 -0600633TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800634{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600636 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800637
Tony Barbour94310562015-04-22 15:10:33 -0600638 src.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800639 uint32_t *data = static_cast<uint32_t *>(src.map());
640 data[0] = 0x11111111;
641 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800642
Tony Barbour94310562015-04-22 15:10:33 -0600643 dst.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800644
645 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600646 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800647 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800649 cmd_.end();
650
651 submit_and_done();
652
653 data = static_cast<uint32_t *>(dst.map());
654 EXPECT_EQ(0x11111111, data[0]);
655 dst.unmap();
656}
657
Tony Barbour01999182015-04-09 12:58:51 -0600658TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800659{
Tony Barbour8205d902015-04-16 15:59:00 -0600660 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600662 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800663
Tony Barbour94310562015-04-22 15:10:33 -0600664 src.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800665 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600666 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800667 for (offset = 0; offset < size; offset += 4)
668 data[offset / 4] = offset;
669 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800670
Tony Barbour94310562015-04-22 15:10:33 -0600671 dst.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800672
673 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600674 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800675 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600676 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800677 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800678
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800679 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800680
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800681 data = static_cast<uint32_t *>(dst.map());
682 for (offset = 0; offset < size; offset += 4)
683 EXPECT_EQ(offset, data[offset / 4]);
684 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800685}
686
Tony Barbour01999182015-04-09 12:58:51 -0600687TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800688{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600689 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800690 /* well aligned */
691 { 0, 0, 256 },
692 { 0, 256, 128 },
693 { 0, 384, 64 },
694 { 0, 448, 32 },
695 { 0, 480, 16 },
696 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800697
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800698 /* ill aligned */
699 { 7, 510, 16 },
700 { 16, 530, 13 },
701 { 32, 551, 16 },
702 { 45, 570, 15 },
703 { 50, 590, 1 },
704 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600705 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600706 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +0800707
Tony Barbour94310562015-04-22 15:10:33 -0600708 src.init(dev_, 256, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800709 uint8_t *data = static_cast<uint8_t *>(src.map());
710 for (int i = 0; i < 256; i++)
711 data[i] = i;
712 src.unmap();
Chia-I Wucb67c652014-10-21 11:06:26 +0800713
Tony Barbour94310562015-04-22 15:10:33 -0600714 dst.init(dev_, 1024, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800715
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800716 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600717 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800718 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800719
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800720 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800721
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800722 data = static_cast<uint8_t *>(dst.map());
723 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800725
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800726 for (int j = 0; j < r.copySize; j++) {
727 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
728 "Region is: " << i << "\n" <<
729 "Offset is: " << r.destOffset + j;
730 }
731 }
732 dst.unmap();
733}
Chia-I Wucb67c652014-10-21 11:06:26 +0800734
Tony Barbour01999182015-04-09 12:58:51 -0600735TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800736{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600737 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600738 VkEventCreateInfo event_info;
739 VkEvent event;
740 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000741 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600742 VkResult err;
Tony Barbour94310562015-04-22 15:10:33 -0600743 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyan55658c22014-12-04 11:08:39 +0000744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000746 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600748 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749 // VkFlags flags; // Reserved
750 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000751 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000753
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 err = vkCreateEvent(dev_.obj(), &event_info, &event);
755 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000756
Mike Stroyan230e6252015-04-17 12:36:38 -0600757 err = vkGetObjectInfo(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Mike Stroyan55658c22014-12-04 11:08:39 +0000758 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600759 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000760
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 // VkResult VKAPI vkAllocMemory(
762 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600763 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600764 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600765 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600766 VkDeviceMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000767
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600768 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000769
Mike Stroyan55658c22014-12-04 11:08:39 +0000770 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600771 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000772 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600773 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
774 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
775 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
776 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000777
Mark Lobodzinski23182612015-05-29 09:32:35 -0500778 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000780
Mike Stroyan230e6252015-04-17 12:36:38 -0600781 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600782 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800783
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800784 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600785 bufs[i].init(dev_, 4, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800786
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800787 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
788 data[0] = 0x22222222 * (i + 1);
789 bufs[i].unmap();
790 }
791
792 cmd_.begin();
793
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600794 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800795 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600796 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600797 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600798 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000799
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600800 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600801 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 +0800802
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600803 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800804 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000806
807 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600808 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600809 pmemory_barrier = &memory_barrier;
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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600812 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000813
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
815 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000816 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600817 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000818
819 // Additional commands could go into the buffer here before the wait.
820
821 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600822 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_HOST_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600823 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600824 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000825
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800826 cmd_.end();
827
828 submit_and_done();
829
830 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
831 EXPECT_EQ(0x11111111, data[0]);
832 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000833
834 // All done with event memory, clean up
Mark Lobodzinski23182612015-05-29 09:32:35 -0500835 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600836 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000837
Mike Stroyan230e6252015-04-17 12:36:38 -0600838 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600839 ASSERT_VK_SUCCESS(err);
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600840
Mike Stroyan230e6252015-04-17 12:36:38 -0600841 err = vkFreeMemory(dev_.obj(), event_mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800843}
844
Tony Barbour01999182015-04-09 12:58:51 -0600845class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800846protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600847 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800848 {
Tony Barbour8205d902015-04-16 15:59:00 -0600849 first_linear_format_ = VK_FORMAT_UNDEFINED;
850 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800851
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600852 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800853 it != dev_.formats().end(); it++) {
854 if (it->features & features) {
855 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800856
Tony Barbour8205d902015-04-16 15:59:00 -0600857 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
858 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800859 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600860 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
861 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800862 first_optimal_format_ = it->format;
863 }
864 }
865 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800866
Chia-I Wu9feab842014-12-22 13:19:08 +0800867 void init_test_formats()
868 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600869 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800870 }
871
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600872 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800873 {
874 if (img.transparent()) {
875 checker.fill(img);
876 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800877 }
878
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800879 ASSERT_EQ(true, img.copyable());
880
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600881 vk_testing::Buffer in_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600882 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
883
884 in_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800885 checker.fill(in_buf);
886
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800887 // copy in and tile
888 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600889 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
890 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800891 checker.regions().size(), &checker.regions()[0]);
892 cmd_.end();
893
894 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800895 }
896
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600897 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800898 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800899 if (img.transparent()) {
900 DO(checker.check(img));
901 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800902 }
903
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800904 ASSERT_EQ(true, img.copyable());
905
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600906 vk_testing::Buffer out_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600907 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
908 out_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800909
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800910 // copy out and linearize
911 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600912 vkCmdCopyImageToBuffer(cmd_.obj(),
913 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600914 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800915 checker.regions().size(), &checker.regions()[0]);
916 cmd_.end();
917
918 submit_and_done();
919
920 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800921 }
922
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600923 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600924 VkFormat first_linear_format_;
925 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800926};
927
Tony Barbour01999182015-04-09 12:58:51 -0600928class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800929protected:
930 virtual void SetUp()
931 {
Tony Barbour01999182015-04-09 12:58:51 -0600932 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600933 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800934 ASSERT_NE(true, test_formats_.empty());
935 }
936
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600937 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800938 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600939 vk_testing::Buffer buf;
940 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -0600941 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800942
Tony Barbour94310562015-04-22 15:10:33 -0600943 buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800944 checker.fill(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800945
Tony Barbour94310562015-04-22 15:10:33 -0600946 img.init(dev_, img_info, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800947
948 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600949 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600950 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800952 checker.regions().size(), &checker.regions()[0]);
953 cmd_.end();
954
955 submit_and_done();
956
957 check_dst(img, checker);
958 }
959
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600960 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800961 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600962 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800963 test_copy_memory_to_image(img_info, checker);
964 }
965
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600966 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800967 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600968 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800969 test_copy_memory_to_image(img_info, checker);
970 }
971};
972
Tony Barbour01999182015-04-09 12:58:51 -0600973TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800974{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600975 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800976 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700977
978 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -0600979 if (it->format == VK_FORMAT_UNDEFINED ||
980 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
981 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700982 continue;
983
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600984 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -0600985 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800986 img_info.format = it->format;
987 img_info.extent.width = 64;
988 img_info.extent.height = 64;
989 img_info.tiling = it->tiling;
990
991 test_copy_memory_to_image(img_info);
992 }
Chia-I Wu86822632014-11-22 15:09:42 +0800993}
994
Tony Barbour01999182015-04-09 12:58:51 -0600995class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +0800996protected:
997 virtual void SetUp()
998 {
Tony Barbour01999182015-04-09 12:58:51 -0600999 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001000 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001001 ASSERT_NE(true, test_formats_.empty());
1002 }
1003
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001004 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001005 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001006 vk_testing::Image img;
1007 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -06001008 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu830fb332014-12-13 15:28:20 +08001009
Tony Barbour94310562015-04-22 15:10:33 -06001010 img.init(dev_, img_info, reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001011 fill_src(img, checker);
Chia-I Wu830fb332014-12-13 15:28:20 +08001012
Tony Barbour94310562015-04-22 15:10:33 -06001013 buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001014
1015 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001016 vkCmdCopyImageToBuffer(cmd_.obj(),
1017 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001018 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001019 checker.regions().size(), &checker.regions()[0]);
1020 cmd_.end();
1021
1022 submit_and_done();
1023
1024 checker.check(buf);
1025 }
1026
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001027 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001028 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001029 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001030 test_copy_image_to_memory(img_info, checker);
1031 }
1032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001033 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001034 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001035 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001036 test_copy_image_to_memory(img_info, checker);
1037 }
1038};
1039
Tony Barbour01999182015-04-09 12:58:51 -06001040TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001041{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001042 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001043 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001044
1045 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001046 if (it->format == VK_FORMAT_UNDEFINED ||
1047 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1048 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001049 continue;
1050
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001051 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001052 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001053 img_info.format = it->format;
1054 img_info.extent.width = 64;
1055 img_info.extent.height = 64;
1056 img_info.tiling = it->tiling;
1057
1058 test_copy_image_to_memory(img_info);
1059 }
1060}
1061
Tony Barbour01999182015-04-09 12:58:51 -06001062class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001063protected:
1064 virtual void SetUp()
1065 {
Tony Barbour01999182015-04-09 12:58:51 -06001066 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001067 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001068 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001069 }
1070
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001071 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1072 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001073 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001074 // convert VkImageCopy to two sets of VkBufferImageCopy
1075 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001076 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001077 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1078 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001079
Chia-I Wu714df452015-01-01 07:55:04 +08001080 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001081 src_region.imageSubresource = it->srcSubresource;
1082 src_region.imageOffset = it->srcOffset;
1083 src_region.imageExtent = it->extent;
1084 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001085
Chia-I Wu714df452015-01-01 07:55:04 +08001086 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001087 dst_region.imageSubresource = it->destSubresource;
1088 dst_region.imageOffset = it->destOffset;
1089 dst_region.imageExtent = it->extent;
1090 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001091
Tony Barbour8205d902015-04-16 15:59:00 -06001092 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001093 src_offset += vk_testing::get_format_size(src_info.format) * size;
1094 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001095 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001096
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001097 vk_testing::ImageChecker src_checker(src_info, src_regions);
1098 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour94310562015-04-22 15:10:33 -06001099 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001100
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001101 vk_testing::Image src;
Tony Barbour94310562015-04-22 15:10:33 -06001102 src.init(dev_, src_info, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001103 fill_src(src, src_checker);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001104
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001105 vk_testing::Image dst;
Tony Barbour94310562015-04-22 15:10:33 -06001106 dst.init(dev_, dst_info, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001107
1108 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001109 vkCmdCopyImage(cmd_.obj(),
1110 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1111 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001112 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001113 cmd_.end();
1114
1115 submit_and_done();
1116
1117 check_dst(dst, dst_checker);
1118 }
1119};
1120
Tony Barbour01999182015-04-09 12:58:51 -06001121TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001122{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001123 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001124 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001125
1126 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001127 if (it->format == VK_FORMAT_UNDEFINED ||
1128 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1129 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001130 continue;
1131
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001132 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001133 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001134 img_info.format = it->format;
1135 img_info.extent.width = 64;
1136 img_info.extent.height = 64;
1137 img_info.tiling = it->tiling;
1138
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001139 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001140 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001141 copy.destSubresource = copy.srcSubresource;
1142 copy.extent = img_info.extent;
1143
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001144 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001145 }
1146}
1147
Tony Barbour01999182015-04-09 12:58:51 -06001148class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001149protected:
Tony Barbour01999182015-04-09 12:58:51 -06001150 VkCmdClearColorImageTest() : test_raw_(false) {}
1151 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001152
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001153 virtual void SetUp()
1154 {
Tony Barbour01999182015-04-09 12:58:51 -06001155 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001156
1157 if (test_raw_)
1158 init_test_formats();
1159 else
Tony Barbour8205d902015-04-16 15:59:00 -06001160 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001161
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001162 ASSERT_NE(true, test_formats_.empty());
1163 }
1164
Chia-I Wu9feab842014-12-22 13:19:08 +08001165 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001166 float color[4];
1167 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001168 };
1169
1170 bool test_raw_;
1171
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001173 {
1174 std::vector<uint8_t> raw;
1175
1176 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001177 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001178 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001179 raw.push_back(color[0] * 255.0f);
1180 raw.push_back(color[1] * 255.0f);
1181 raw.push_back(color[2] * 255.0f);
1182 raw.push_back(color[3] * 255.0f);
1183 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001184 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001185 raw.push_back(color[2] * 255.0f);
1186 raw.push_back(color[1] * 255.0f);
1187 raw.push_back(color[0] * 255.0f);
1188 raw.push_back(color[3] * 255.0f);
1189 break;
1190 default:
1191 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001192 }
1193
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001194 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001195 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001196
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001198 {
1199 std::vector<uint8_t> raw;
1200
1201 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001202 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001203 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001204 raw.push_back(static_cast<uint8_t>(color[0]));
1205 raw.push_back(static_cast<uint8_t>(color[1]));
1206 raw.push_back(static_cast<uint8_t>(color[2]));
1207 raw.push_back(static_cast<uint8_t>(color[3]));
1208 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001209 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001210 raw.push_back(static_cast<uint8_t>(color[2]));
1211 raw.push_back(static_cast<uint8_t>(color[1]));
1212 raw.push_back(static_cast<uint8_t>(color[0]));
1213 raw.push_back(static_cast<uint8_t>(color[3]));
1214 break;
1215 default:
1216 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001217 }
1218
1219 return raw;
1220 }
1221
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001223 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001224 if (color.useRawValue)
1225 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001226 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001227 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001228 }
1229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001230 void test_clear_color_image(const VkImageCreateInfo &img_info,
1231 const VkClearColor &clear_color,
1232 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001233 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001234 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -06001235 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1236
1237 img.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001238 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001239 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001240 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1241 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1242 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001243 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001244 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001245 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001246 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1247 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1248 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1249 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1250 VK_MEMORY_INPUT_SHADER_READ_BIT |
1251 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1252 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001253 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001254
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001255 std::vector<VkImageMemoryBarrier> to_clear;
1256 std::vector<VkImageMemoryBarrier *> p_to_clear;
1257 std::vector<VkImageMemoryBarrier> to_xfer;
1258 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001260 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001261 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001262 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001263 VK_IMAGE_LAYOUT_GENERAL,
1264 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001265 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001266 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001267 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001268 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1269 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001270 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001271 }
1272
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001273 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001274
Tony Barbour8205d902015-04-16 15:59:00 -06001275 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1276 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 +00001277
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001278 vkCmdClearColorImage(cmd_.obj(),
1279 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06001280 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001281
Tony Barbour8205d902015-04-16 15:59:00 -06001282 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 +08001283
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001284 cmd_.end();
1285
1286 submit_and_done();
1287
1288 // cannot verify
1289 if (!img.transparent() && !img.copyable())
1290 return;
1291
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001292 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001293
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001294 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001295 if (solid_pattern.empty())
1296 return;
1297
1298 checker.set_solid_pattern(solid_pattern);
1299 check_dst(img, checker);
1300 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001301
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001302 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001303 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001304 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001305 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001306 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001307 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001308 test_clear_color_image(img_info, c, ranges);
1309 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001310};
1311
Tony Barbour01999182015-04-09 12:58:51 -06001312TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001313{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001315 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001316 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001317
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001318 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001319 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001320 img_info.format = it->format;
1321 img_info.extent.width = 64;
1322 img_info.extent.height = 64;
1323 img_info.tiling = it->tiling;
1324
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001325 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001327 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001328
1329 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001330 }
1331}
1332
Tony Barbour01999182015-04-09 12:58:51 -06001333class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001334protected:
Tony Barbour01999182015-04-09 12:58:51 -06001335 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001336
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001337 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001338 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001339 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001340 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001341 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001342 c.useRawValue = true;
1343 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001344 test_clear_color_image(img_info, c, ranges);
1345 }
1346};
1347
Tony Barbour01999182015-04-09 12:58:51 -06001348TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001349{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001350 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001351 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001352 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001353
1354 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001355 if (it->format == VK_FORMAT_UNDEFINED ||
1356 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1357 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1358 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1359 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1360 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1361 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1362 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1363 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1364 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1365 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1366 (it->format >= VK_FORMAT_D16_UNORM &&
1367 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001368 continue;
1369
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001371 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001372 img_info.format = it->format;
1373 img_info.extent.width = 64;
1374 img_info.extent.height = 64;
1375 img_info.tiling = it->tiling;
1376
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001378 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001379 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001380
1381 test_clear_color_image_raw(img_info, color, ranges);
1382 }
1383}
1384
Tony Barbour01999182015-04-09 12:58:51 -06001385class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001386protected:
1387 virtual void SetUp()
1388 {
Tony Barbour01999182015-04-09 12:58:51 -06001389 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001390 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001391 ASSERT_NE(true, test_formats_.empty());
1392 }
1393
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001394 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001395 {
1396 std::vector<uint8_t> raw;
1397
1398 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001399 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001400 case VK_FORMAT_D16_UNORM:
1401 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001402 {
1403 const uint16_t unorm = depth * 65535.0f;
1404 raw.push_back(unorm & 0xff);
1405 raw.push_back(unorm >> 8);
1406 }
1407 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001408 case VK_FORMAT_D32_SFLOAT:
1409 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001410 {
1411 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001412 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001413 uint32_t u32;
1414 } u = { depth };
1415
1416 raw.push_back((u.u32 ) & 0xff);
1417 raw.push_back((u.u32 >> 8) & 0xff);
1418 raw.push_back((u.u32 >> 16) & 0xff);
1419 raw.push_back((u.u32 >> 24) & 0xff);
1420 }
1421 break;
1422 default:
1423 break;
1424 }
1425
1426 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001427 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001428 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001429 raw.push_back(stencil);
1430 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001431 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001432 raw.push_back(stencil);
1433 raw.push_back(0);
1434 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001435 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001436 raw.push_back(stencil);
1437 raw.push_back(0);
1438 raw.push_back(0);
1439 raw.push_back(0);
1440 break;
1441 default:
1442 break;
1443 }
1444
1445 return raw;
1446 }
1447
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001448 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001449 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001450 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001451 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001452 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -06001453 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1454
1455 img.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001456 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001457 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001458 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1459 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1460 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001461 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001462 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001463 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001464 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1465 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1466 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1467 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1468 VK_MEMORY_INPUT_SHADER_READ_BIT |
1469 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1470 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001471 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473 std::vector<VkImageMemoryBarrier> to_clear;
1474 std::vector<VkImageMemoryBarrier *> p_to_clear;
1475 std::vector<VkImageMemoryBarrier> to_xfer;
1476 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001477
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001478 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001479 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001480 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001481 VK_IMAGE_LAYOUT_GENERAL,
1482 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001483 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001484 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001485 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001486 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1487 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001488 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001489 }
1490
1491 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001492
Tony Barbour8205d902015-04-16 15:59:00 -06001493 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1494 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 +00001495
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001496 vkCmdClearDepthStencil(cmd_.obj(),
1497 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001498 depth, stencil,
1499 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001500
Tony Barbour8205d902015-04-16 15:59:00 -06001501 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 +00001502
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001503 cmd_.end();
1504
1505 submit_and_done();
1506
1507 // cannot verify
1508 if (!img.transparent() && !img.copyable())
1509 return;
1510
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001511 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001512
1513 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1514 check_dst(img, checker);
1515 }
1516};
1517
Tony Barbour01999182015-04-09 12:58:51 -06001518TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001519{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001520 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001521 it != test_formats_.end(); it++) {
1522 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001523 if (it->format == VK_FORMAT_S8_UINT ||
1524 it->format == VK_FORMAT_D24_UNORM ||
1525 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1526 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001527 continue;
1528
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001529 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001530 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001531 img_info.format = it->format;
1532 img_info.extent.width = 64;
1533 img_info.extent.height = 64;
1534 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001535 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001536
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001537 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001538 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001539 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001540
1541 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1542 }
1543}
1544
1545}; // namespace
1546
Chia-I Wucb67c652014-10-21 11:06:26 +08001547int main(int argc, char **argv)
1548{
Chia-I Wucb67c652014-10-21 11:06:26 +08001549 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001550
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001551 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001552
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001553 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001554
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001555 if (!environment->parse_args(argc, argv))
1556 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001557
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001558 ::testing::AddGlobalTestEnvironment(environment);
1559
1560 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001561}