blob: af94856a141dd0052d7a3e91d27ac10c4f62d9d6 [file] [log] [blame]
Chia-I Wud7414b02014-10-21 11:06:26 +08001//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06002// Copyright (C) 2015 Valve Corporation
Chia-I Wud7414b02014-10-21 11:06:26 +08003//
Chia-I Wu998c2ac2014-12-08 14:30:10 +08004// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
Chia-I Wud7414b02014-10-21 11:06:26 +080010//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080011// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
Chia-I Wud7414b02014-10-21 11:06:26 +080013//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080014// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060021//
22// Author: Chia-I Wu <olv@lunarg.com>
23// Author: Jeremy Hayes <jeremy@lunarg.com>
24// Author: Mike Stroyan <mike@LunarG.com>
Chia-I Wud7414b02014-10-21 11:06:26 +080025
26// Blit (copy, clear, and resolve) tests
27
Tony Barbour048f2812015-06-09 13:40:53 -060028#include "math.h"
Chia-I Wua9a506a2014-12-27 22:04:00 +080029#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060030#include "vktestbinding.h"
Tony Barbour92400bb2015-03-02 16:38:52 -070031#include "test_environment.h"
Chia-I Wud7414b02014-10-21 11:06:26 +080032
33#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
34
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060035namespace vk_testing {
Chia-I Wud7414b02014-10-21 11:06:26 +080036
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060037size_t get_format_size(VkFormat format);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080038
Chia-I Wu998c2ac2014-12-08 14:30:10 +080039class ImageChecker {
40public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060041 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080042 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060043 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
44 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080045
46 void set_solid_pattern(const std::vector<uint8_t> &solid);
47
Tony Barbourd1c35722015-04-16 15:59:00 -060048 VkDeviceSize buffer_size() const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080049 bool fill(Buffer &buf) const { return walk(FILL, buf); }
50 bool fill(Image &img) const { return walk(FILL, img); }
51 bool check(Buffer &buf) const { return walk(CHECK, buf); }
52 bool check(Image &img) const { return walk(CHECK, img); }
53
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060054 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu998c2ac2014-12-08 14:30:10 +080055
56 static void hash_salt_generate() { hash_salt_++; }
57
58private:
59 enum Action {
60 FILL,
61 CHECK,
62 };
63
64 enum Pattern {
65 HASH,
66 SOLID,
67 };
68
Mark Lobodzinski17caf572015-01-29 08:55:56 -060069 size_t buffer_cpp() const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060070 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080071
72 bool walk(Action action, Buffer &buf) const;
73 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060074 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080075
Chia-I Wu1b99bb22015-10-27 19:25:11 +080076 std::vector<uint8_t> pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080077
78 static uint32_t hash_salt_;
79
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060080 VkImageCreateInfo info_;
81 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080082
83 Pattern pattern_;
84 std::vector<uint8_t> pattern_solid_;
85};
86
Chia-I Wud7414b02014-10-21 11:06:26 +080087
Chia-I Wu998c2ac2014-12-08 14:30:10 +080088uint32_t ImageChecker::hash_salt_;
89
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060090ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080091 : info_(info), regions_(), pattern_(HASH)
92{
93 // create a region for every mip level in array slice 0
Tony Barbourd1c35722015-04-16 15:59:00 -060094 VkDeviceSize offset = 0;
Mark Lobodzinski17caf572015-01-29 08:55:56 -060095 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060096 VkBufferImageCopy region = {};
Chia-I Wu998c2ac2014-12-08 14:30:10 +080097
Chia-I Wu1a28fe02015-01-01 07:55:04 +080098 region.bufferOffset = offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080099 region.imageSubresource.mipLevel = lv;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600100 region.imageSubresource.baseArrayLayer = 0;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800101 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800102
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600103 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600104 if (info_.format != VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800105 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800106 regions_.push_back(region);
107 }
108
Tony Barbourd1c35722015-04-16 15:59:00 -0600109 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
110 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
111 info_.format == VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800112 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800113 regions_.push_back(region);
114 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800115 } else {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800116 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800117 regions_.push_back(region);
118 }
119
120 offset += buffer_layout(region).size;
121 }
122
123 // arraySize should be limited in our tests. If this proves to be an
124 // issue, we can store only the regions for array slice 0 and be smart.
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600125 if (info_.arrayLayers > 1) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600126 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600127 const uint32_t slice_region_count = regions_.size();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800128
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600129 regions_.reserve(slice_region_count * info_.arrayLayers);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800130
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600131 for (uint32_t slice = 1; slice < info_.arrayLayers; slice++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600132 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600133 VkBufferImageCopy region = regions_[i];
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800134
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800135 region.bufferOffset += slice_pitch * slice;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600136 region.imageSubresource.baseArrayLayer = slice;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800137 regions_.push_back(region);
138 }
139 }
140 }
141}
142
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600143ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800144 : info_(info), regions_(), pattern_(HASH)
145{
Tony Barbourd1c35722015-04-16 15:59:00 -0600146 VkDeviceSize offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600147 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800148 it != ranges.end(); it++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800149 for (uint32_t lv = 0; lv < it->levelCount; lv++) {
150 for (uint32_t layer = 0; layer < it->layerCount; layer++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600151 VkBufferImageCopy region = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800152 region.bufferOffset = offset;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600153 region.imageSubresource = Image::subresource(*it, lv, layer, 1);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800154 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800155
156 regions_.push_back(region);
157
158 offset += buffer_layout(region).size;
159 }
160 }
161 }
162}
163
164void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
165{
166 pattern_ = SOLID;
Chia-I Wu72e34332014-12-21 14:59:04 +0800167 pattern_solid_.clear();
168 pattern_solid_.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600169 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800170 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800171}
172
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600173size_t ImageChecker::buffer_cpp() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800174{
175 return get_format_size(info_.format);
176}
177
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600178VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800179{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600180 VkSubresourceLayout layout = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800181 layout.offset = region.bufferOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800182 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
183 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
184 layout.size = layout.depthPitch * region.imageExtent.depth;
185
186 return layout;
187}
188
Tony Barbourd1c35722015-04-16 15:59:00 -0600189VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800190{
Tony Barbourd1c35722015-04-16 15:59:00 -0600191 VkDeviceSize size = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800192
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600193 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800194 it != regions_.end(); it++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600195 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800196 if (size < layout.offset + layout.size)
197 size = layout.offset + layout.size;
198 }
199
200 return size;
201}
202
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600203bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
204 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800205{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600206 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
207 for (int32_t y = 0; y < region.imageExtent.height; y++) {
208 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800209 uint8_t *dst = static_cast<uint8_t *>(data);
210 dst += layout.offset + layout.depthPitch * z +
211 layout.rowPitch * y + buffer_cpp() * x;
212
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600213 VkOffset3D offset = region.imageOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800214 offset.x += x;
215 offset.y += y;
216 offset.z += z;
217
218 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
219 pattern_hash(region.imageSubresource, offset) :
220 pattern_solid_;
221 assert(val.size() == buffer_cpp());
222
223 if (action == FILL) {
224 memcpy(dst, &val[0], val.size());
225 } else {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600226 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800227 EXPECT_EQ(val[i], dst[i]) <<
Cody Northrop28026d42015-08-06 13:17:52 -0600228 "Offset is: (" << x << ", " << y << ", " << z << ")\n"
229 "Format is: (" << info_.format << ")\n";
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800230 if (val[i] != dst[i])
231 return false;
232 }
233 }
234 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800235 }
236 }
237
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800238 return true;
Chia-I Wud7414b02014-10-21 11:06:26 +0800239}
240
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800241bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800242{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800243 void *data = buf.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800244 if (!data)
245 return false;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800246
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600247 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800248 for (it = regions_.begin(); it != regions_.end(); it++) {
249 if (!walk_region(action, *it, buffer_layout(*it), data))
250 break;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800251 }
252
Chia-I Wu681d7a02015-07-03 13:44:34 +0800253 buf.memory().unmap();
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800254
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800255 return (it == regions_.end());
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800256}
257
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800258bool ImageChecker::walk(Action action, Image &img) const
259{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800260 void *data = img.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800261 if (!data)
262 return false;
263
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600264 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800265 for (it = regions_.begin(); it != regions_.end(); it++) {
266 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
267 break;
268 }
269
Chia-I Wu681d7a02015-07-03 13:44:34 +0800270 img.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800271
272 return (it == regions_.end());
273}
274
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800275std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800276{
277#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
278#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
279 const unsigned char input[] = {
280 HASH_BYTES(hash_salt_),
281 HASH_BYTES(subres.mipLevel),
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600282 HASH_BYTES(subres.baseArrayLayer),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800283 HASH_BYTES(offset.x),
284 HASH_BYTES(offset.y),
285 HASH_BYTES(offset.z),
286 };
287 unsigned long hash = 5381;
288
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600289 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800290 hash = ((hash << 5) + hash) + input[i];
291
292 const uint8_t output[4] = { HASH_BYTES(hash) };
293#undef HASH_BYTES
294#undef HASH_BYTE
295
Chia-I Wu72e34332014-12-21 14:59:04 +0800296 std::vector<uint8_t> val;
297 val.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600298 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800299 val.push_back(output[i % 4]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800300
301 return val;
302}
303
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600304size_t get_format_size(VkFormat format)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800305{
Tony Barbourfc3820f2015-05-14 17:15:33 -0600306 static bool format_table_unverified = true;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800307 static const struct format_info {
Courtney Goeltzenleuchterf3387652015-07-08 18:41:08 -0600308 VkFormat format;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600309 size_t size;
310 uint32_t channel_count;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800311 } format_table[VK_FORMAT_RANGE_SIZE] = {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600312 { VK_FORMAT_UNDEFINED, 0, 0 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800313 { VK_FORMAT_R4G4_UNORM_PACK8, 1, 2 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800314 { VK_FORMAT_R4G4B4A4_UNORM_PACK16, 2, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800315 { VK_FORMAT_B4G4R4A4_UNORM_PACK16, 2, 4 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800316 { VK_FORMAT_R5G6B5_UNORM_PACK16, 2, 3 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800317 { VK_FORMAT_B5G6R5_UNORM_PACK16, 2, 3 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800318 { VK_FORMAT_R5G5B5A1_UNORM_PACK16, 2, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800319 { VK_FORMAT_B5G5R5A1_UNORM_PACK16, 2, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800320 { VK_FORMAT_A1R5G5B5_UNORM_PACK16, 2, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600321 { VK_FORMAT_R8_UNORM, 1, 1 },
322 { VK_FORMAT_R8_SNORM, 1, 1 },
323 { VK_FORMAT_R8_USCALED, 1, 1 },
324 { VK_FORMAT_R8_SSCALED, 1, 1 },
325 { VK_FORMAT_R8_UINT, 1, 1 },
326 { VK_FORMAT_R8_SINT, 1, 1 },
327 { VK_FORMAT_R8_SRGB, 1, 1 },
328 { VK_FORMAT_R8G8_UNORM, 2, 2 },
329 { VK_FORMAT_R8G8_SNORM, 2, 2 },
330 { VK_FORMAT_R8G8_USCALED, 2, 2 },
331 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
332 { VK_FORMAT_R8G8_UINT, 2, 2 },
333 { VK_FORMAT_R8G8_SINT, 2, 2 },
334 { VK_FORMAT_R8G8_SRGB, 2, 2 },
335 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
336 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
337 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
338 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
339 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
340 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
341 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800342 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
343 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
344 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
345 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
346 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
347 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
348 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600349 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
350 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
351 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
352 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
353 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
354 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
355 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800356 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
357 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
358 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
359 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
360 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
361 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
362 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800363 { VK_FORMAT_A8B8G8R8_UNORM_PACK32, 4, 4 },
364 { VK_FORMAT_A8B8G8R8_SNORM_PACK32, 4, 4 },
365 { VK_FORMAT_A8B8G8R8_USCALED_PACK32, 4, 4 },
366 { VK_FORMAT_A8B8G8R8_SSCALED_PACK32, 4, 4 },
367 { VK_FORMAT_A8B8G8R8_UINT_PACK32, 4, 4 },
368 { VK_FORMAT_A8B8G8R8_SINT_PACK32, 4, 4 },
369 { VK_FORMAT_A8B8G8R8_SRGB_PACK32, 4, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800370 { VK_FORMAT_A2R10G10B10_UNORM_PACK32, 4, 4 },
371 { VK_FORMAT_A2R10G10B10_SNORM_PACK32, 4, 4 },
372 { VK_FORMAT_A2R10G10B10_USCALED_PACK32, 4, 4 },
373 { VK_FORMAT_A2R10G10B10_SSCALED_PACK32, 4, 4 },
374 { VK_FORMAT_A2R10G10B10_UINT_PACK32, 4, 4 },
375 { VK_FORMAT_A2R10G10B10_SINT_PACK32, 4, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800376 { VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 4 },
377 { VK_FORMAT_A2B10G10R10_SNORM_PACK32, 4, 4 },
378 { VK_FORMAT_A2B10G10R10_USCALED_PACK32, 4, 4 },
379 { VK_FORMAT_A2B10G10R10_SSCALED_PACK32, 4, 4 },
380 { VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 4 },
381 { VK_FORMAT_A2B10G10R10_SINT_PACK32, 4, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600382 { VK_FORMAT_R16_UNORM, 2, 1 },
383 { VK_FORMAT_R16_SNORM, 2, 1 },
384 { VK_FORMAT_R16_USCALED, 2, 1 },
385 { VK_FORMAT_R16_SSCALED, 2, 1 },
386 { VK_FORMAT_R16_UINT, 2, 1 },
387 { VK_FORMAT_R16_SINT, 2, 1 },
388 { VK_FORMAT_R16_SFLOAT, 2, 1 },
389 { VK_FORMAT_R16G16_UNORM, 4, 2 },
390 { VK_FORMAT_R16G16_SNORM, 4, 2 },
391 { VK_FORMAT_R16G16_USCALED, 4, 2 },
392 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
393 { VK_FORMAT_R16G16_UINT, 4, 2 },
394 { VK_FORMAT_R16G16_SINT, 4, 2 },
395 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
396 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
397 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
398 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
399 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
400 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
401 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
402 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
403 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
404 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
405 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
406 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
407 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
408 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
409 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
410 { VK_FORMAT_R32_UINT, 4, 1 },
411 { VK_FORMAT_R32_SINT, 4, 1 },
412 { VK_FORMAT_R32_SFLOAT, 4, 1 },
413 { VK_FORMAT_R32G32_UINT, 8, 2 },
414 { VK_FORMAT_R32G32_SINT, 8, 2 },
415 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
416 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
417 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
418 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
419 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
420 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
421 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800422 { VK_FORMAT_R64_UINT, 8, 1 },
423 { VK_FORMAT_R64_SINT, 8, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600424 { VK_FORMAT_R64_SFLOAT, 8, 1 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800425 { VK_FORMAT_R64G64_UINT, 16, 2 },
426 { VK_FORMAT_R64G64_SINT, 16, 2 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600427 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800428 { VK_FORMAT_R64G64B64_UINT, 24, 3 },
429 { VK_FORMAT_R64G64B64_SINT, 24, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600430 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800431 { VK_FORMAT_R64G64B64A64_UINT, 32, 4 },
432 { VK_FORMAT_R64G64B64A64_SINT, 32, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600433 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800434 { VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4, 3 },
435 { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, 4, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600436 { VK_FORMAT_D16_UNORM, 2, 1 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800437 { VK_FORMAT_X8_D24_UNORM_PACK32, 3, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600438 { VK_FORMAT_D32_SFLOAT, 4, 1 },
439 { VK_FORMAT_S8_UINT, 1, 1 },
440 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
441 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbour048f2812015-06-09 13:40:53 -0600442 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Chia-I Wu53638c12015-11-10 16:44:23 +0800443 { VK_FORMAT_BC1_RGB_UNORM_BLOCK, 8, 4 },
444 { VK_FORMAT_BC1_RGB_SRGB_BLOCK, 8, 4 },
445 { VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4 },
446 { VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4 },
447 { VK_FORMAT_BC2_UNORM_BLOCK, 16, 4 },
448 { VK_FORMAT_BC2_SRGB_BLOCK, 16, 4 },
449 { VK_FORMAT_BC3_UNORM_BLOCK, 16, 4 },
450 { VK_FORMAT_BC3_SRGB_BLOCK, 16, 4 },
451 { VK_FORMAT_BC4_UNORM_BLOCK, 8, 4 },
452 { VK_FORMAT_BC4_SNORM_BLOCK, 8, 4 },
453 { VK_FORMAT_BC5_UNORM_BLOCK, 16, 4 },
454 { VK_FORMAT_BC5_SNORM_BLOCK, 16, 4 },
455 { VK_FORMAT_BC6H_UFLOAT_BLOCK, 16, 4 },
456 { VK_FORMAT_BC6H_SFLOAT_BLOCK, 16, 4 },
457 { VK_FORMAT_BC7_UNORM_BLOCK, 16, 4 },
458 { VK_FORMAT_BC7_SRGB_BLOCK, 16, 4 },
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700459 // TODO: Initialize remaining compressed formats.
Chia-I Wu53638c12015-11-10 16:44:23 +0800460 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 0, 0 },
461 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 0, 0 },
462 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 0, 0 },
463 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 0, 0 },
464 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 0, 0 },
465 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 0, 0 },
466 { VK_FORMAT_EAC_R11_UNORM_BLOCK, 0, 0 },
467 { VK_FORMAT_EAC_R11_SNORM_BLOCK, 0, 0 },
468 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 0, 0 },
469 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 0, 0 },
470 { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 0, 0 },
471 { VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 0, 0 },
472 { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 0, 0 },
473 { VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 0, 0 },
474 { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 0, 0 },
475 { VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 0, 0 },
476 { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 0, 0 },
477 { VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 0, 0 },
478 { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 0, 0 },
479 { VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 0, 0 },
480 { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 0, 0 },
481 { VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 0, 0 },
482 { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 0, 0 },
483 { VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 0, 0 },
484 { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 0, 0 },
485 { VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 0, 0 },
486 { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 0, 0 },
487 { VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 0, 0 },
488 { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 0, 0 },
489 { VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 0, 0 },
490 { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 0, 0 },
491 { VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 0, 0 },
492 { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 0, 0 },
493 { VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 0, 0 },
494 { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 0, 0 },
495 { VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 0, 0 },
496 { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 0, 0 },
497 { VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 0, 0 },
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800498 };
Tony Barbourfc3820f2015-05-14 17:15:33 -0600499 if (format_table_unverified)
500 {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800501 for (unsigned int i = 0; i < VK_FORMAT_RANGE_SIZE; i++)
Tony Barbourfc3820f2015-05-14 17:15:33 -0600502 {
503 assert(format_table[i].format == i);
504 }
505 format_table_unverified = false;
506 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800507
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700508 return format_table[format].size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800509}
510
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600511VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800512{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600513 const VkExtent3D ext = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800514 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
515 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
516 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
517 };
518
519 return ext;
520}
521
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600522}; // namespace vk_testing
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800523
524namespace {
525
526#define DO(action) ASSERT_EQ(true, action);
527
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600528static vk_testing::Environment *environment;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800529
Tony Barbour6918cd52015-04-09 12:58:51 -0600530class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800531protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600532 VkCmdBlitTest() :
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800533 dev_(environment->default_device()),
Chia-I Wua9a506a2014-12-27 22:04:00 +0800534 queue_(*dev_.graphics_queues()[0]),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800535 pool_(dev_, vk_testing::CommandPool::create_info(dev_.graphics_queue_node_index_)),
536 cmd_(dev_, vk_testing::CommandBuffer::create_info(pool_.handle()))
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800537 {
538 // make sure every test uses a different pattern
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600539 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800540 }
541
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800542 bool submit_and_done()
543 {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600544 queue_.submit(cmd_);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800545 queue_.wait();
546 mem_refs_.clear();
547 return true;
548 }
549
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600550 vk_testing::Device &dev_;
551 vk_testing::Queue &queue_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 vk_testing::CommandPool pool_;
553 vk_testing::CommandBuffer cmd_;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800554
Chris Forbes9e50dab2015-07-11 19:11:39 +1200555 /* TODO: We should be able to remove these now */
Tony Barbourd1c35722015-04-16 15:59:00 -0600556 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800557};
558
Tony Barbour6918cd52015-04-09 12:58:51 -0600559typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800560
Tony Barbour6918cd52015-04-09 12:58:51 -0600561TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800562{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600563 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600564 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800565
Cody Northrop7fb43862015-06-22 14:56:14 -0600566 buf.init_as_dst(dev_, 20, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800567
568 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800569 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 4, 0x11111111);
570 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 4, 16, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800571 cmd_.end();
572
573 submit_and_done();
574
Chia-I Wu681d7a02015-07-03 13:44:34 +0800575 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800576 EXPECT_EQ(0x11111111, data[0]);
577 EXPECT_EQ(0x22222222, data[1]);
578 EXPECT_EQ(0x22222222, data[2]);
579 EXPECT_EQ(0x22222222, data[3]);
580 EXPECT_EQ(0x22222222, data[4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800581 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800582}
583
Tony Barbour6918cd52015-04-09 12:58:51 -0600584TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wud94726f2014-11-23 02:16:45 +0800585{
Tony Barbourd1c35722015-04-16 15:59:00 -0600586 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600588 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud94726f2014-11-23 02:16:45 +0800589
Cody Northrop7fb43862015-06-22 14:56:14 -0600590 buf.init_as_dst(dev_, size, reqs);
Chia-I Wud94726f2014-11-23 02:16:45 +0800591
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800592 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800593 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, size / 2, 0x11111111);
594 vkCmdFillBuffer(cmd_.handle(), buf.handle(), size / 2, size / 2, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800595 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800596
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800597 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800598
Chia-I Wu681d7a02015-07-03 13:44:34 +0800599 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600600 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800601 for (offset = 0; offset < size / 2; offset += 4)
602 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
603 for (; offset < size; offset += 4)
604 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800605 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800606}
Chia-I Wud94726f2014-11-23 02:16:45 +0800607
Tony Barbour6918cd52015-04-09 12:58:51 -0600608TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800609{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600610 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600611 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800612
Cody Northrop7fb43862015-06-22 14:56:14 -0600613 buf.init_as_dst(dev_, 64, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800614
615 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800616 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 48, 0x11111111);
617 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 32, 32, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800618 cmd_.end();
619
620 submit_and_done();
621
Chia-I Wu681d7a02015-07-03 13:44:34 +0800622 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600623 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800624 for (offset = 0; offset < 32; offset += 4)
625 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
626 for (; offset < 64; offset += 4)
627 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800628 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800629}
630
Tony Barbour6918cd52015-04-09 12:58:51 -0600631TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800632{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 vk_testing::Buffer bufs[9];
Tony Barbourd1c35722015-04-16 15:59:00 -0600634 VkDeviceSize size = 4;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600635 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800636
637 cmd_.begin();
638 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600639 bufs[i].init_as_dst(dev_, size, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800640 vkCmdFillBuffer(cmd_.handle(), bufs[i].handle(), 0, size, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800641 size <<= 1;
642 }
643 cmd_.end();
644
645 submit_and_done();
646
647 size = 4;
648 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800649 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600650 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800651 for (offset = 0; offset < size; offset += 4)
652 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
653 "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800654 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800655
656 size <<= 1;
657 }
658}
659
Tony Barbour6918cd52015-04-09 12:58:51 -0600660typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800661
Tony Barbour6918cd52015-04-09 12:58:51 -0600662TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800663{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600664 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600665 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800666
Cody Northrop7fb43862015-06-22 14:56:14 -0600667 src.init_as_src(dev_, 4, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800668 uint32_t *data = static_cast<uint32_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800669 data[0] = 0x11111111;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800670 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800671
Cody Northrop7fb43862015-06-22 14:56:14 -0600672 dst.init_as_dst(dev_, 4, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800673
674 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600675 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800676 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800677 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800678 cmd_.end();
679
680 submit_and_done();
681
Chia-I Wu681d7a02015-07-03 13:44:34 +0800682 data = static_cast<uint32_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800683 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800684 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800685}
686
Tony Barbour6918cd52015-04-09 12:58:51 -0600687TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800688{
Tony Barbourd1c35722015-04-16 15:59:00 -0600689 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600690 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600691 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800692
Cody Northropd2ad0342015-08-05 11:15:02 -0600693 src.init_as_src(dev_, size * sizeof(VkDeviceSize), reqs);
694 VkDeviceSize *data = static_cast<VkDeviceSize *>(src.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600695 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800696 for (offset = 0; offset < size; offset += 4)
697 data[offset / 4] = offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800698 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800699
Cody Northropd2ad0342015-08-05 11:15:02 -0600700 dst.init_as_dst(dev_, size * sizeof(VkDeviceSize), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800701
702 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600703 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800704 region.size = size * sizeof(VkDeviceSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800705 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800706 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800707
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800708 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800709
Cody Northropd2ad0342015-08-05 11:15:02 -0600710 data = static_cast<VkDeviceSize *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800711 for (offset = 0; offset < size; offset += 4)
712 EXPECT_EQ(offset, data[offset / 4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800713 dst.memory().unmap();
Chia-I Wud94726f2014-11-23 02:16:45 +0800714}
715
Tony Barbour6918cd52015-04-09 12:58:51 -0600716TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wud7414b02014-10-21 11:06:26 +0800717{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600718 const VkBufferCopy regions[] = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800719 /* well aligned */
720 { 0, 0, 256 },
721 { 0, 256, 128 },
722 { 0, 384, 64 },
723 { 0, 448, 32 },
724 { 0, 480, 16 },
725 { 0, 496, 8 },
Chia-I Wud7414b02014-10-21 11:06:26 +0800726
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800727 /* ill aligned */
728 { 7, 510, 16 },
729 { 16, 530, 13 },
730 { 32, 551, 16 },
731 { 45, 570, 15 },
732 { 50, 590, 1 },
733 };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600734 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600735 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +0800736
Cody Northrop7fb43862015-06-22 14:56:14 -0600737 src.init_as_src(dev_, 256, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800738 uint8_t *data = static_cast<uint8_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800739 for (int i = 0; i < 256; i++)
740 data[i] = i;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800741 src.memory().unmap();
Chia-I Wud7414b02014-10-21 11:06:26 +0800742
Cody Northrop7fb43862015-06-22 14:56:14 -0600743 dst.init_as_dst(dev_, 1024, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800744
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800745 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800746 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), ARRAY_SIZE(regions), regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800747 cmd_.end();
Chia-I Wud7414b02014-10-21 11:06:26 +0800748
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800749 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800750
Chia-I Wu681d7a02015-07-03 13:44:34 +0800751 data = static_cast<uint8_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800752 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753 const VkBufferCopy &r = regions[i];
Chia-I Wud7414b02014-10-21 11:06:26 +0800754
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800755 for (int j = 0; j < r.size; j++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800756 EXPECT_EQ(r.srcOffset + j, data[r.dstOffset + j]) <<
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800757 "Region is: " << i << "\n" <<
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800758 "Offset is: " << r.dstOffset + j;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800759 }
760 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800761 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800762}
Chia-I Wud7414b02014-10-21 11:06:26 +0800763
Tony Barbour6918cd52015-04-09 12:58:51 -0600764TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800765{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600766 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600767 VkEventCreateInfo event_info;
768 VkEvent event;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600769 VkResult err;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600770 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000771
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600772 // typedef struct VkEventCreateInfo_
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000773 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600774 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600775 // const void* pNext; // Pointer to next structure
776 // VkFlags flags; // Reserved
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600777 // } VkEventCreateInfo;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000778 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600779 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000780
Chia-I Wuf7458c52015-10-26 21:10:41 +0800781 err = vkCreateEvent(dev_.handle(), &event_info, NULL, &event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600782 ASSERT_VK_SUCCESS(err);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000783
Chia-I Wuf368b602015-07-03 10:41:20 +0800784 err = vkResetEvent(dev_.handle(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600785 ASSERT_VK_SUCCESS(err);
Chia-I Wud7414b02014-10-21 11:06:26 +0800786
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800787 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600788 bufs[i].init_as_src_and_dst(dev_, 4, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800789
Chia-I Wu681d7a02015-07-03 13:44:34 +0800790 uint32_t *data = static_cast<uint32_t *>(bufs[i].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800791 data[0] = 0x22222222 * (i + 1);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800792 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800793 }
794
795 cmd_.begin();
796
Chia-I Wu681d7a02015-07-03 13:44:34 +0800797 vkCmdFillBuffer(cmd_.handle(), bufs[0].handle(), 0, 4, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800798 // is this necessary?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600799 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800800 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600801 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000802
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600803 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
804 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +0800805 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800806
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600807 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800808 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800809 vkCmdCopyBuffer(cmd_.handle(), bufs[0].handle(), bufs[1].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000810
811 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800812 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600813 pmemory_barrier = &memory_barrier;
Chia-I Wu53534662015-10-26 17:08:33 +0800814 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800815
Chia-I Wu681d7a02015-07-03 13:44:34 +0800816 vkCmdCopyBuffer(cmd_.handle(), bufs[1].handle(), bufs[2].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000817
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600818 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
819 * This could be vkCmdPipelineBarrier.
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000820 */
Chia-I Wube2b9172015-07-03 11:49:42 +0800821 vkCmdSetEvent(cmd_.handle(), event, VK_PIPELINE_STAGE_TRANSFER_BIT);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000822
823 // Additional commands could go into the buffer here before the wait.
824
825 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800826 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600827 pmemory_barrier = &memory_barrier;
Chia-I Wube2b9172015-07-03 11:49:42 +0800828 vkCmdWaitEvents(cmd_.handle(), 1, &event, src_stages, dest_stages, 1, (const void **)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000829
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800830 cmd_.end();
831
832 submit_and_done();
833
Chia-I Wu681d7a02015-07-03 13:44:34 +0800834 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800835 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800836 bufs[2].memory().unmap();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000837
Chia-I Wuf7458c52015-10-26 21:10:41 +0800838 vkDestroyEvent(dev_.handle(), event, NULL);
Tony Barbour7db519b2015-06-26 11:49:05 -0600839
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800840}
841
Tony Barbour6918cd52015-04-09 12:58:51 -0600842class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800843protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600844 void init_test_formats(VkFlags features)
Chia-I Wud7414b02014-10-21 11:06:26 +0800845 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600846 first_linear_format_ = VK_FORMAT_UNDEFINED;
847 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wud7414b02014-10-21 11:06:26 +0800848
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600849 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800850 it != dev_.formats().end(); it++) {
851 if (it->features & features) {
852 test_formats_.push_back(*it);
Chia-I Wud7414b02014-10-21 11:06:26 +0800853
Tony Barbourd1c35722015-04-16 15:59:00 -0600854 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
855 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800856 first_linear_format_ = it->format;
Tony Barbourd1c35722015-04-16 15:59:00 -0600857 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
858 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800859 first_optimal_format_ = it->format;
860 }
861 }
862 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800863
Chia-I Wu5bc27862014-12-22 13:19:08 +0800864 void init_test_formats()
865 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600866 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu5bc27862014-12-22 13:19:08 +0800867 }
868
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600869 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800870 {
871 if (img.transparent()) {
872 checker.fill(img);
873 return;
Chia-I Wud7414b02014-10-21 11:06:26 +0800874 }
875
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800876 ASSERT_EQ(true, img.copyable());
877
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600878 vk_testing::Buffer in_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600879 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
880
Cody Northrop7fb43862015-06-22 14:56:14 -0600881 in_buf.init_as_src(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800882 checker.fill(in_buf);
883
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800884 // copy in and tile
885 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800886 vkCmdCopyBufferToImage(cmd_.handle(), in_buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700887 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800888 checker.regions().size(), &checker.regions()[0]);
889 cmd_.end();
890
891 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800892 }
893
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600894 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wud6479012014-11-22 15:09:42 +0800895 {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800896 if (img.transparent()) {
897 DO(checker.check(img));
898 return;
Chia-I Wud6479012014-11-22 15:09:42 +0800899 }
900
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800901 ASSERT_EQ(true, img.copyable());
902
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600903 vk_testing::Buffer out_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600904 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -0600905 out_buf.init_as_dst(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800906
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800907 // copy out and linearize
908 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800909 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700910 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +0800911 out_buf.handle(),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800912 checker.regions().size(), &checker.regions()[0]);
913 cmd_.end();
914
915 submit_and_done();
916
917 DO(checker.check(out_buf));
Chia-I Wud6479012014-11-22 15:09:42 +0800918 }
919
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600920 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600921 VkFormat first_linear_format_;
922 VkFormat first_optimal_format_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800923};
924
Tony Barbour6918cd52015-04-09 12:58:51 -0600925class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800926protected:
927 virtual void SetUp()
928 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600929 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600930 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800931 ASSERT_NE(true, test_formats_.empty());
932 }
933
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600934 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800935 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600936 vk_testing::Buffer buf;
937 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -0600938 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
939 VkMemoryPropertyFlags image_reqs =
940 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800941
Cody Northrop7fb43862015-06-22 14:56:14 -0600942 buf.init_as_src(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800943 checker.fill(buf);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800944
Tony Barbour0c823b12015-05-21 13:26:05 -0600945 img.init(dev_, img_info, image_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800946
947 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800948 vkCmdCopyBufferToImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800949 buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700950 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800951 checker.regions().size(), &checker.regions()[0]);
952 cmd_.end();
953
954 submit_and_done();
955
956 check_dst(img, checker);
957 }
958
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600959 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800960 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600961 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800962 test_copy_memory_to_image(img_info, checker);
963 }
964
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600965 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800966 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600967 vk_testing::ImageChecker checker(img_info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800968 test_copy_memory_to_image(img_info, checker);
969 }
970};
971
Tony Barbour6918cd52015-04-09 12:58:51 -0600972TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800973{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600974 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800975 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700976
977 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -0600978 if (it->format == VK_FORMAT_UNDEFINED ||
979 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
980 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700981 continue;
982
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600983 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600984 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800985 img_info.format = it->format;
986 img_info.extent.width = 64;
987 img_info.extent.height = 64;
988 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800989 img_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
990 VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700991 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800992
993 test_copy_memory_to_image(img_info);
994 }
Chia-I Wud6479012014-11-22 15:09:42 +0800995}
996
Tony Barbour6918cd52015-04-09 12:58:51 -0600997class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu42b97b82014-12-13 15:28:20 +0800998protected:
999 virtual void SetUp()
1000 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001001 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001002 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001003 ASSERT_NE(true, test_formats_.empty());
1004 }
1005
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001006 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001007 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001008 vk_testing::Image img;
1009 vk_testing::Buffer buf;
Tony Barbour0c823b12015-05-21 13:26:05 -06001010 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1011 VkMemoryPropertyFlags image_reqs =
1012 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001013
Tony Barbour0c823b12015-05-21 13:26:05 -06001014 img.init(dev_, img_info, image_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001015 fill_src(img, checker);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001016
Cody Northrop7fb43862015-06-22 14:56:14 -06001017 buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001018
1019 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001020 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001021 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +08001022 buf.handle(),
Chia-I Wu42b97b82014-12-13 15:28:20 +08001023 checker.regions().size(), &checker.regions()[0]);
1024 cmd_.end();
1025
1026 submit_and_done();
1027
1028 checker.check(buf);
1029 }
1030
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001031 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001032 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001033 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001034 test_copy_image_to_memory(img_info, checker);
1035 }
1036
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001037 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001038 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001039 vk_testing::ImageChecker checker(img_info);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001040 test_copy_image_to_memory(img_info, checker);
1041 }
1042};
1043
Tony Barbour6918cd52015-04-09 12:58:51 -06001044TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001045{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001046 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu42b97b82014-12-13 15:28:20 +08001047 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001048
1049 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001050 if (it->format == VK_FORMAT_UNDEFINED ||
1051 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1052 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001053 continue;
1054
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001055 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001056 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001057 img_info.format = it->format;
1058 img_info.extent.width = 64;
1059 img_info.extent.height = 64;
1060 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001061 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1062 VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001063 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001064
1065 test_copy_image_to_memory(img_info);
1066 }
1067}
1068
Tony Barbour6918cd52015-04-09 12:58:51 -06001069class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001070protected:
1071 virtual void SetUp()
1072 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001073 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001074 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001075 ASSERT_NE(true, test_formats_.empty());
Chia-I Wu89078aa2014-11-22 16:24:41 +08001076 }
1077
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001078 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1079 const std::vector<VkImageCopy> &copies)
Chia-I Wu89078aa2014-11-22 16:24:41 +08001080 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001081 // convert VkImageCopy to two sets of VkBufferImageCopy
1082 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbourd1c35722015-04-16 15:59:00 -06001083 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001084 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1085 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wu89078aa2014-11-22 16:24:41 +08001086
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001087 src_region.bufferOffset = src_offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001088 src_region.imageSubresource = it->srcSubresource;
1089 src_region.imageOffset = it->srcOffset;
1090 src_region.imageExtent = it->extent;
1091 src_regions.push_back(src_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001092
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001093 dst_region.bufferOffset = src_offset;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001094 dst_region.imageSubresource = it->dstSubresource;
1095 dst_region.imageOffset = it->dstOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001096 dst_region.imageExtent = it->extent;
1097 dst_regions.push_back(dst_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001098
Tony Barbourd1c35722015-04-16 15:59:00 -06001099 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001100 src_offset += vk_testing::get_format_size(src_info.format) * size;
1101 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001102 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001103
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001104 vk_testing::ImageChecker src_checker(src_info, src_regions);
1105 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour0c823b12015-05-21 13:26:05 -06001106 VkMemoryPropertyFlags src_reqs =
1107 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1108 VkMemoryPropertyFlags dst_reqs =
1109 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1110
1111
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001112
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001113 vk_testing::Image src;
Tony Barbour0c823b12015-05-21 13:26:05 -06001114 src.init(dev_, src_info, src_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001115 fill_src(src, src_checker);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001116
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001117 vk_testing::Image dst;
Tony Barbour0c823b12015-05-21 13:26:05 -06001118 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001119
1120 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001121 vkCmdCopyImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001122 src.handle(), VK_IMAGE_LAYOUT_GENERAL,
1123 dst.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001124 copies.size(), &copies[0]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001125 cmd_.end();
1126
1127 submit_and_done();
1128
1129 check_dst(dst, dst_checker);
1130 }
1131};
1132
Tony Barbour6918cd52015-04-09 12:58:51 -06001133TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001134{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001135 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001136 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001137
1138 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001139 if (it->format == VK_FORMAT_UNDEFINED ||
1140 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1141 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001142 continue;
1143
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001144 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001145 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001146 img_info.format = it->format;
1147 img_info.extent.width = 64;
1148 img_info.extent.height = 64;
1149 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001150 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001151 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001152
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001153 VkImageCopy copy = {};
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06001154 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001155 copy.dstSubresource = copy.srcSubresource;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001156 copy.extent = img_info.extent;
1157
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001158 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001159 }
1160}
1161
Tony Barbour6918cd52015-04-09 12:58:51 -06001162class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001163protected:
Chris Forbesf0796e12015-06-24 14:34:53 +12001164 VkCmdClearColorImageTest() {}
Chia-I Wu5bc27862014-12-22 13:19:08 +08001165
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001166 virtual void SetUp()
1167 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001168 VkCmdBlitTest::SetUp();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001169
Courtney Goeltzenleuchtercda30342015-09-10 16:25:49 -06001170 init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001171
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001172 ASSERT_NE(true, test_formats_.empty());
1173 }
1174
Chia-I Wu5bc27862014-12-22 13:19:08 +08001175 union Color {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001176 float color[4];
1177 uint32_t raw[4];
Chia-I Wu5bc27862014-12-22 13:19:08 +08001178 };
1179
Chris Forbesf0796e12015-06-24 14:34:53 +12001180 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001181 {
1182 std::vector<uint8_t> raw;
1183
1184 // TODO support all formats
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001185 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001186 case VK_FORMAT_R8G8B8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001187 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1188 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1189 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1190 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001191 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001192 case VK_FORMAT_B8G8R8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001193 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1194 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1195 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1196 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001197 break;
1198 default:
1199 break;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001200 }
1201
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001202 return raw;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001203 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001204
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001205 void test_clear_color_image(const VkImageCreateInfo &img_info,
Chris Forbesf0796e12015-06-24 14:34:53 +12001206 const VkClearColorValue &clear_color,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001207 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wud7414b02014-10-21 11:06:26 +08001208 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001209 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001210 VkMemoryPropertyFlags image_reqs =
1211 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001212
Tony Barbour0c823b12015-05-21 13:26:05 -06001213 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001214 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001215 VK_ACCESS_HOST_WRITE_BIT |
1216 VK_ACCESS_SHADER_WRITE_BIT |
1217 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1218 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1219 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001220 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001221 VK_ACCESS_HOST_READ_BIT |
1222 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1223 VK_ACCESS_INDEX_READ_BIT |
1224 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1225 VK_ACCESS_UNIFORM_READ_BIT |
1226 VK_ACCESS_SHADER_READ_BIT |
1227 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1228 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1229 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +08001230
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001231 std::vector<VkImageMemoryBarrier> to_clear;
1232 std::vector<VkImageMemoryBarrier *> p_to_clear;
1233 std::vector<VkImageMemoryBarrier> to_xfer;
1234 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wud7414b02014-10-21 11:06:26 +08001235
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001236 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001237 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001238 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001239 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001240 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001241 *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001242 p_to_clear.push_back(&to_clear.back());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001243 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001244 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001245 VK_IMAGE_LAYOUT_GENERAL, *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001246 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wud7414b02014-10-21 11:06:26 +08001247 }
1248
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001249 cmd_.begin();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001250
Chia-I Wu89d0f942015-10-31 00:31:16 +08001251 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1252 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001253 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001254
Chia-I Wube2b9172015-07-03 11:49:42 +08001255 vkCmdClearColorImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001256 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001257 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001258
Chia-I Wu53534662015-10-26 17:08:33 +08001259 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001260
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001261 cmd_.end();
1262
1263 submit_and_done();
1264
1265 // cannot verify
1266 if (!img.transparent() && !img.copyable())
1267 return;
1268
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001269 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001270
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -06001271 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001272 if (solid_pattern.empty())
1273 return;
1274
1275 checker.set_solid_pattern(solid_pattern);
1276 check_dst(img, checker);
1277 }
Chia-I Wu5bc27862014-12-22 13:19:08 +08001278
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001279 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001280 const float color[4],
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001281 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu5bc27862014-12-22 13:19:08 +08001282 {
Chris Forbesf0796e12015-06-24 14:34:53 +12001283 VkClearColorValue c = {};
Cody Northrop85789d52015-08-25 15:26:38 -06001284 memcpy(c.float32, color, sizeof(c.float32));
Chia-I Wu5bc27862014-12-22 13:19:08 +08001285 test_clear_color_image(img_info, c, ranges);
1286 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001287};
1288
Tony Barbour6918cd52015-04-09 12:58:51 -06001289TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001290{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001291 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001292 it != test_formats_.end(); it++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001293 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barboura36f5282015-06-05 12:53:55 -06001294 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001295
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001296 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001297
Tony Barboura36f5282015-06-05 12:53:55 -06001298 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1299 continue;
1300
1301 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1302 continue;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001303
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001304 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001305 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001306 img_info.format = it->format;
1307 img_info.extent.width = 64;
1308 img_info.extent.height = 64;
1309 img_info.tiling = it->tiling;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001310 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barboure65788f2015-07-21 17:01:42 -06001311 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001312 VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001313
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001314 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001315 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001316 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001317
1318 test_clear_color_image(img_info, color, ranges);
Chia-I Wud7414b02014-10-21 11:06:26 +08001319 }
1320}
1321
Tony Barbour6918cd52015-04-09 12:58:51 -06001322class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001323protected:
1324 virtual void SetUp()
1325 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001326 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001327 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001328 ASSERT_NE(true, test_formats_.empty());
1329 }
1330
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001331 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001332 {
1333 std::vector<uint8_t> raw;
1334
1335 // depth
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001336 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001337 case VK_FORMAT_D16_UNORM:
1338 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001339 {
Tony Barbour048f2812015-06-09 13:40:53 -06001340 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001341 raw.push_back(unorm & 0xff);
1342 raw.push_back(unorm >> 8);
1343 }
1344 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001345 case VK_FORMAT_D32_SFLOAT:
1346 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001347 {
1348 const union {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001349 float depth;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001350 uint32_t u32;
1351 } u = { depth };
1352
1353 raw.push_back((u.u32 ) & 0xff);
1354 raw.push_back((u.u32 >> 8) & 0xff);
1355 raw.push_back((u.u32 >> 16) & 0xff);
1356 raw.push_back((u.u32 >> 24) & 0xff);
1357 }
1358 break;
1359 default:
1360 break;
1361 }
1362
1363 // stencil
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001364 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001365 case VK_FORMAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001366 raw.push_back(stencil);
1367 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001368 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001369 raw.push_back(stencil);
1370 raw.push_back(0);
1371 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001372 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001373 raw.push_back(stencil);
1374 raw.push_back(0);
1375 raw.push_back(0);
1376 raw.push_back(0);
1377 break;
1378 default:
1379 break;
1380 }
1381
1382 return raw;
1383 }
1384
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001385 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001386 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001387 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001388 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001389 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001390 VkMemoryPropertyFlags image_reqs =
1391 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001392
Tony Barbour0c823b12015-05-21 13:26:05 -06001393 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001394 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001395 VK_ACCESS_HOST_WRITE_BIT |
1396 VK_ACCESS_SHADER_WRITE_BIT |
1397 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1398 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1399 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001400 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001401 VK_ACCESS_HOST_READ_BIT |
1402 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1403 VK_ACCESS_INDEX_READ_BIT |
1404 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1405 VK_ACCESS_UNIFORM_READ_BIT |
1406 VK_ACCESS_SHADER_READ_BIT |
1407 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1408 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1409 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001410
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001411 std::vector<VkImageMemoryBarrier> to_clear;
1412 std::vector<VkImageMemoryBarrier *> p_to_clear;
1413 std::vector<VkImageMemoryBarrier> to_xfer;
1414 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001415 unsigned int i = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001416
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001417 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001418 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001419 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001420 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001421 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001422 *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001423
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001424 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001425 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001426 VK_IMAGE_LAYOUT_GENERAL, *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001427 }
1428 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
1429 it != ranges.end(); it++) {
1430 p_to_clear.push_back(to_clear.data() + i);
1431 p_to_xfer.push_back(to_xfer.data() + i);
1432 i++;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001433 }
1434
1435 cmd_.begin();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001436
Chia-I Wu89d0f942015-10-31 00:31:16 +08001437 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1438 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001439 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_clear.size(), (const void * const*) p_to_clear.data());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001440
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001441 VkClearDepthStencilValue clear_value = {
1442 depth,
1443 stencil
1444 };
Chia-I Wube2b9172015-07-03 11:49:42 +08001445 vkCmdClearDepthStencilImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001446 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001447 &clear_value,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001448 ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001449
Chia-I Wu53534662015-10-26 17:08:33 +08001450 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_xfer.size(), (const void * const*)p_to_xfer.data());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001451
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001452 cmd_.end();
1453
1454 submit_and_done();
1455
1456 // cannot verify
1457 if (!img.transparent() && !img.copyable())
1458 return;
1459
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001460 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001461
1462 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1463 check_dst(img, checker);
1464 }
1465};
1466
Tony Barbour6918cd52015-04-09 12:58:51 -06001467TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001468{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001469 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001470 it != test_formats_.end(); it++) {
Tony Barboura36f5282015-06-05 12:53:55 -06001471 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001472
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001473 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001474
Tony Barboura36f5282015-06-05 12:53:55 -06001475 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1476 continue;
1477
1478 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1479 continue;
1480
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001481 // known driver issues
Tony Barbourd1c35722015-04-16 15:59:00 -06001482 if (it->format == VK_FORMAT_S8_UINT ||
Chia-I Wu935f2ed2015-11-10 17:01:22 +08001483 it->format == VK_FORMAT_X8_D24_UNORM_PACK32 ||
Tony Barbourd1c35722015-04-16 15:59:00 -06001484 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1485 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001486 continue;
1487
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001488 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001489 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001490 img_info.format = it->format;
1491 img_info.extent.width = 64;
1492 img_info.extent.height = 64;
1493 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -06001494 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001495 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1496 VkImageAspectFlags aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001497
Tony Barbour048f2812015-06-09 13:40:53 -06001498 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1499 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1500 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001501 aspect |= VK_IMAGE_ASPECT_STENCIL_BIT;
1502 }
Tony Barbour048f2812015-06-09 13:40:53 -06001503
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001504 const VkImageSubresourceRange range =
1505 vk_testing::Image::subresource_range(img_info, aspect);
1506 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Tony Barbour048f2812015-06-09 13:40:53 -06001507
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001508 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1509 }
1510}
1511
1512}; // namespace
1513
Chia-I Wud7414b02014-10-21 11:06:26 +08001514int main(int argc, char **argv)
1515{
Chia-I Wud7414b02014-10-21 11:06:26 +08001516 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wud7414b02014-10-21 11:06:26 +08001517
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001518 vk_testing::set_error_callback(test_error_callback);
Chia-I Wua9a506a2014-12-27 22:04:00 +08001519
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001520 environment = new vk_testing::Environment();
Chia-I Wud7414b02014-10-21 11:06:26 +08001521
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001522 if (!environment->parse_args(argc, argv))
1523 return -1;
Chia-I Wud7414b02014-10-21 11:06:26 +08001524
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001525 ::testing::AddGlobalTestEnvironment(environment);
1526
1527 return RUN_ALL_TESTS();
Chia-I Wud7414b02014-10-21 11:06:26 +08001528}