blob: 340cdc08661fbb904776b06ae83ca6651530cb4a [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 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600320 { VK_FORMAT_R8_UNORM, 1, 1 },
321 { VK_FORMAT_R8_SNORM, 1, 1 },
322 { VK_FORMAT_R8_USCALED, 1, 1 },
323 { VK_FORMAT_R8_SSCALED, 1, 1 },
324 { VK_FORMAT_R8_UINT, 1, 1 },
325 { VK_FORMAT_R8_SINT, 1, 1 },
326 { VK_FORMAT_R8_SRGB, 1, 1 },
327 { VK_FORMAT_R8G8_UNORM, 2, 2 },
328 { VK_FORMAT_R8G8_SNORM, 2, 2 },
329 { VK_FORMAT_R8G8_USCALED, 2, 2 },
330 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
331 { VK_FORMAT_R8G8_UINT, 2, 2 },
332 { VK_FORMAT_R8G8_SINT, 2, 2 },
333 { VK_FORMAT_R8G8_SRGB, 2, 2 },
334 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
335 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
336 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
337 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
338 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
339 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
340 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800341 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
342 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
343 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
344 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
345 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
346 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
347 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600348 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
349 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
350 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
351 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
352 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
353 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
354 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800355 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
356 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
357 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
358 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
359 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
360 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
361 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
362 { VK_FORMAT_A2R10G10B10_UNORM_PACK32, 4, 4 },
363 { VK_FORMAT_A2R10G10B10_SNORM_PACK32, 4, 4 },
364 { VK_FORMAT_A2R10G10B10_USCALED_PACK32, 4, 4 },
365 { VK_FORMAT_A2R10G10B10_SSCALED_PACK32, 4, 4 },
366 { VK_FORMAT_A2R10G10B10_UINT_PACK32, 4, 4 },
367 { VK_FORMAT_A2R10G10B10_SINT_PACK32, 4, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800368 { VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 4 },
369 { VK_FORMAT_A2B10G10R10_SNORM_PACK32, 4, 4 },
370 { VK_FORMAT_A2B10G10R10_USCALED_PACK32, 4, 4 },
371 { VK_FORMAT_A2B10G10R10_SSCALED_PACK32, 4, 4 },
372 { VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 4 },
373 { VK_FORMAT_A2B10G10R10_SINT_PACK32, 4, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600374 { VK_FORMAT_R16_UNORM, 2, 1 },
375 { VK_FORMAT_R16_SNORM, 2, 1 },
376 { VK_FORMAT_R16_USCALED, 2, 1 },
377 { VK_FORMAT_R16_SSCALED, 2, 1 },
378 { VK_FORMAT_R16_UINT, 2, 1 },
379 { VK_FORMAT_R16_SINT, 2, 1 },
380 { VK_FORMAT_R16_SFLOAT, 2, 1 },
381 { VK_FORMAT_R16G16_UNORM, 4, 2 },
382 { VK_FORMAT_R16G16_SNORM, 4, 2 },
383 { VK_FORMAT_R16G16_USCALED, 4, 2 },
384 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
385 { VK_FORMAT_R16G16_UINT, 4, 2 },
386 { VK_FORMAT_R16G16_SINT, 4, 2 },
387 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
388 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
389 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
390 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
391 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
392 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
393 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
394 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
395 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
396 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
397 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
398 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
399 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
400 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
401 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
402 { VK_FORMAT_R32_UINT, 4, 1 },
403 { VK_FORMAT_R32_SINT, 4, 1 },
404 { VK_FORMAT_R32_SFLOAT, 4, 1 },
405 { VK_FORMAT_R32G32_UINT, 8, 2 },
406 { VK_FORMAT_R32G32_SINT, 8, 2 },
407 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
408 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
409 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
410 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
411 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
412 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
413 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
414 { VK_FORMAT_R64_SFLOAT, 8, 1 },
415 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
416 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
417 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800418 { VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4, 3 },
419 { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, 4, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600420 { VK_FORMAT_D16_UNORM, 2, 1 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800421 { VK_FORMAT_X8_D24_UNORM_PACK32, 3, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600422 { VK_FORMAT_D32_SFLOAT, 4, 1 },
423 { VK_FORMAT_S8_UINT, 1, 1 },
424 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
425 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbour048f2812015-06-09 13:40:53 -0600426 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Chia-I Wu53638c12015-11-10 16:44:23 +0800427 { VK_FORMAT_BC1_RGB_UNORM_BLOCK, 8, 4 },
428 { VK_FORMAT_BC1_RGB_SRGB_BLOCK, 8, 4 },
429 { VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4 },
430 { VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4 },
431 { VK_FORMAT_BC2_UNORM_BLOCK, 16, 4 },
432 { VK_FORMAT_BC2_SRGB_BLOCK, 16, 4 },
433 { VK_FORMAT_BC3_UNORM_BLOCK, 16, 4 },
434 { VK_FORMAT_BC3_SRGB_BLOCK, 16, 4 },
435 { VK_FORMAT_BC4_UNORM_BLOCK, 8, 4 },
436 { VK_FORMAT_BC4_SNORM_BLOCK, 8, 4 },
437 { VK_FORMAT_BC5_UNORM_BLOCK, 16, 4 },
438 { VK_FORMAT_BC5_SNORM_BLOCK, 16, 4 },
439 { VK_FORMAT_BC6H_UFLOAT_BLOCK, 16, 4 },
440 { VK_FORMAT_BC6H_SFLOAT_BLOCK, 16, 4 },
441 { VK_FORMAT_BC7_UNORM_BLOCK, 16, 4 },
442 { VK_FORMAT_BC7_SRGB_BLOCK, 16, 4 },
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700443 // TODO: Initialize remaining compressed formats.
Chia-I Wu53638c12015-11-10 16:44:23 +0800444 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 0, 0 },
445 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 0, 0 },
446 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 0, 0 },
447 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 0, 0 },
448 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 0, 0 },
449 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 0, 0 },
450 { VK_FORMAT_EAC_R11_UNORM_BLOCK, 0, 0 },
451 { VK_FORMAT_EAC_R11_SNORM_BLOCK, 0, 0 },
452 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 0, 0 },
453 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 0, 0 },
454 { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 0, 0 },
455 { VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 0, 0 },
456 { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 0, 0 },
457 { VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 0, 0 },
458 { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 0, 0 },
459 { VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 0, 0 },
460 { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 0, 0 },
461 { VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 0, 0 },
462 { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 0, 0 },
463 { VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 0, 0 },
464 { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 0, 0 },
465 { VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 0, 0 },
466 { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 0, 0 },
467 { VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 0, 0 },
468 { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 0, 0 },
469 { VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 0, 0 },
470 { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 0, 0 },
471 { VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 0, 0 },
472 { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 0, 0 },
473 { VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 0, 0 },
474 { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 0, 0 },
475 { VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 0, 0 },
476 { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 0, 0 },
477 { VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 0, 0 },
478 { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 0, 0 },
479 { VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 0, 0 },
480 { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 0, 0 },
481 { VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 0, 0 },
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800482 };
Tony Barbourfc3820f2015-05-14 17:15:33 -0600483 if (format_table_unverified)
484 {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800485 for (unsigned int i = 0; i < VK_FORMAT_RANGE_SIZE; i++)
Tony Barbourfc3820f2015-05-14 17:15:33 -0600486 {
487 assert(format_table[i].format == i);
488 }
489 format_table_unverified = false;
490 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800491
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700492 return format_table[format].size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800493}
494
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600495VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800496{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600497 const VkExtent3D ext = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800498 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
499 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
500 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
501 };
502
503 return ext;
504}
505
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600506}; // namespace vk_testing
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800507
508namespace {
509
510#define DO(action) ASSERT_EQ(true, action);
511
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512static vk_testing::Environment *environment;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800513
Tony Barbour6918cd52015-04-09 12:58:51 -0600514class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800515protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600516 VkCmdBlitTest() :
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800517 dev_(environment->default_device()),
Chia-I Wua9a506a2014-12-27 22:04:00 +0800518 queue_(*dev_.graphics_queues()[0]),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800519 pool_(dev_, vk_testing::CommandPool::create_info(dev_.graphics_queue_node_index_)),
520 cmd_(dev_, vk_testing::CommandBuffer::create_info(pool_.handle()))
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800521 {
522 // make sure every test uses a different pattern
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600523 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800524 }
525
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800526 bool submit_and_done()
527 {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600528 queue_.submit(cmd_);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800529 queue_.wait();
530 mem_refs_.clear();
531 return true;
532 }
533
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600534 vk_testing::Device &dev_;
535 vk_testing::Queue &queue_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800536 vk_testing::CommandPool pool_;
537 vk_testing::CommandBuffer cmd_;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800538
Chris Forbes9e50dab2015-07-11 19:11:39 +1200539 /* TODO: We should be able to remove these now */
Tony Barbourd1c35722015-04-16 15:59:00 -0600540 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800541};
542
Tony Barbour6918cd52015-04-09 12:58:51 -0600543typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800544
Tony Barbour6918cd52015-04-09 12:58:51 -0600545TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800546{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600547 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600548 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800549
Cody Northrop7fb43862015-06-22 14:56:14 -0600550 buf.init_as_dst(dev_, 20, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800551
552 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800553 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 4, 0x11111111);
554 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 4, 16, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800555 cmd_.end();
556
557 submit_and_done();
558
Chia-I Wu681d7a02015-07-03 13:44:34 +0800559 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800560 EXPECT_EQ(0x11111111, data[0]);
561 EXPECT_EQ(0x22222222, data[1]);
562 EXPECT_EQ(0x22222222, data[2]);
563 EXPECT_EQ(0x22222222, data[3]);
564 EXPECT_EQ(0x22222222, data[4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800565 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800566}
567
Tony Barbour6918cd52015-04-09 12:58:51 -0600568TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wud94726f2014-11-23 02:16:45 +0800569{
Tony Barbourd1c35722015-04-16 15:59:00 -0600570 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600571 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600572 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud94726f2014-11-23 02:16:45 +0800573
Cody Northrop7fb43862015-06-22 14:56:14 -0600574 buf.init_as_dst(dev_, size, reqs);
Chia-I Wud94726f2014-11-23 02:16:45 +0800575
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800576 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800577 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, size / 2, 0x11111111);
578 vkCmdFillBuffer(cmd_.handle(), buf.handle(), size / 2, size / 2, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800579 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800580
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800581 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800582
Chia-I Wu681d7a02015-07-03 13:44:34 +0800583 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600584 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800585 for (offset = 0; offset < size / 2; offset += 4)
586 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
587 for (; offset < size; offset += 4)
588 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800589 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800590}
Chia-I Wud94726f2014-11-23 02:16:45 +0800591
Tony Barbour6918cd52015-04-09 12:58:51 -0600592TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800593{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800596
Cody Northrop7fb43862015-06-22 14:56:14 -0600597 buf.init_as_dst(dev_, 64, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800598
599 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800600 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 48, 0x11111111);
601 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 32, 32, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800602 cmd_.end();
603
604 submit_and_done();
605
Chia-I Wu681d7a02015-07-03 13:44:34 +0800606 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600607 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800608 for (offset = 0; offset < 32; offset += 4)
609 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
610 for (; offset < 64; offset += 4)
611 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800612 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800613}
614
Tony Barbour6918cd52015-04-09 12:58:51 -0600615TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800616{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600617 vk_testing::Buffer bufs[9];
Tony Barbourd1c35722015-04-16 15:59:00 -0600618 VkDeviceSize size = 4;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600619 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800620
621 cmd_.begin();
622 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600623 bufs[i].init_as_dst(dev_, size, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800624 vkCmdFillBuffer(cmd_.handle(), bufs[i].handle(), 0, size, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800625 size <<= 1;
626 }
627 cmd_.end();
628
629 submit_and_done();
630
631 size = 4;
632 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800633 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600634 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800635 for (offset = 0; offset < size; offset += 4)
636 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
637 "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800638 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800639
640 size <<= 1;
641 }
642}
643
Tony Barbour6918cd52015-04-09 12:58:51 -0600644typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800645
Tony Barbour6918cd52015-04-09 12:58:51 -0600646TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800647{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600648 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600649 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800650
Cody Northrop7fb43862015-06-22 14:56:14 -0600651 src.init_as_src(dev_, 4, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800652 uint32_t *data = static_cast<uint32_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800653 data[0] = 0x11111111;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800654 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800655
Cody Northrop7fb43862015-06-22 14:56:14 -0600656 dst.init_as_dst(dev_, 4, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800657
658 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600659 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800660 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800661 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800662 cmd_.end();
663
664 submit_and_done();
665
Chia-I Wu681d7a02015-07-03 13:44:34 +0800666 data = static_cast<uint32_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800667 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800668 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800669}
670
Tony Barbour6918cd52015-04-09 12:58:51 -0600671TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800672{
Tony Barbourd1c35722015-04-16 15:59:00 -0600673 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600674 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600675 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800676
Cody Northropd2ad0342015-08-05 11:15:02 -0600677 src.init_as_src(dev_, size * sizeof(VkDeviceSize), reqs);
678 VkDeviceSize *data = static_cast<VkDeviceSize *>(src.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600679 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800680 for (offset = 0; offset < size; offset += 4)
681 data[offset / 4] = offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800682 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800683
Cody Northropd2ad0342015-08-05 11:15:02 -0600684 dst.init_as_dst(dev_, size * sizeof(VkDeviceSize), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800685
686 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600687 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800688 region.size = size * sizeof(VkDeviceSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800689 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800690 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800691
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800692 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800693
Cody Northropd2ad0342015-08-05 11:15:02 -0600694 data = static_cast<VkDeviceSize *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800695 for (offset = 0; offset < size; offset += 4)
696 EXPECT_EQ(offset, data[offset / 4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800697 dst.memory().unmap();
Chia-I Wud94726f2014-11-23 02:16:45 +0800698}
699
Tony Barbour6918cd52015-04-09 12:58:51 -0600700TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wud7414b02014-10-21 11:06:26 +0800701{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600702 const VkBufferCopy regions[] = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800703 /* well aligned */
704 { 0, 0, 256 },
705 { 0, 256, 128 },
706 { 0, 384, 64 },
707 { 0, 448, 32 },
708 { 0, 480, 16 },
709 { 0, 496, 8 },
Chia-I Wud7414b02014-10-21 11:06:26 +0800710
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800711 /* ill aligned */
712 { 7, 510, 16 },
713 { 16, 530, 13 },
714 { 32, 551, 16 },
715 { 45, 570, 15 },
716 { 50, 590, 1 },
717 };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600718 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600719 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +0800720
Cody Northrop7fb43862015-06-22 14:56:14 -0600721 src.init_as_src(dev_, 256, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800722 uint8_t *data = static_cast<uint8_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800723 for (int i = 0; i < 256; i++)
724 data[i] = i;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800725 src.memory().unmap();
Chia-I Wud7414b02014-10-21 11:06:26 +0800726
Cody Northrop7fb43862015-06-22 14:56:14 -0600727 dst.init_as_dst(dev_, 1024, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800728
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800729 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800730 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), ARRAY_SIZE(regions), regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800731 cmd_.end();
Chia-I Wud7414b02014-10-21 11:06:26 +0800732
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800733 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800734
Chia-I Wu681d7a02015-07-03 13:44:34 +0800735 data = static_cast<uint8_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800736 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600737 const VkBufferCopy &r = regions[i];
Chia-I Wud7414b02014-10-21 11:06:26 +0800738
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800739 for (int j = 0; j < r.size; j++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800740 EXPECT_EQ(r.srcOffset + j, data[r.dstOffset + j]) <<
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800741 "Region is: " << i << "\n" <<
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800742 "Offset is: " << r.dstOffset + j;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800743 }
744 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800745 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800746}
Chia-I Wud7414b02014-10-21 11:06:26 +0800747
Tony Barbour6918cd52015-04-09 12:58:51 -0600748TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800749{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600750 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600751 VkEventCreateInfo event_info;
752 VkEvent event;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753 VkResult err;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600754 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000755
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600756 // typedef struct VkEventCreateInfo_
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000757 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600758 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600759 // const void* pNext; // Pointer to next structure
760 // VkFlags flags; // Reserved
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600761 // } VkEventCreateInfo;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000762 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600763 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000764
Chia-I Wuf7458c52015-10-26 21:10:41 +0800765 err = vkCreateEvent(dev_.handle(), &event_info, NULL, &event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600766 ASSERT_VK_SUCCESS(err);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000767
Chia-I Wuf368b602015-07-03 10:41:20 +0800768 err = vkResetEvent(dev_.handle(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600769 ASSERT_VK_SUCCESS(err);
Chia-I Wud7414b02014-10-21 11:06:26 +0800770
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800771 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600772 bufs[i].init_as_src_and_dst(dev_, 4, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800773
Chia-I Wu681d7a02015-07-03 13:44:34 +0800774 uint32_t *data = static_cast<uint32_t *>(bufs[i].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800775 data[0] = 0x22222222 * (i + 1);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800776 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800777 }
778
779 cmd_.begin();
780
Chia-I Wu681d7a02015-07-03 13:44:34 +0800781 vkCmdFillBuffer(cmd_.handle(), bufs[0].handle(), 0, 4, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800782 // is this necessary?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600783 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800784 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600785 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000786
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600787 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
788 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +0800789 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800790
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600791 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800792 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800793 vkCmdCopyBuffer(cmd_.handle(), bufs[0].handle(), bufs[1].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000794
795 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800796 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600797 pmemory_barrier = &memory_barrier;
Chia-I Wu53534662015-10-26 17:08:33 +0800798 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800799
Chia-I Wu681d7a02015-07-03 13:44:34 +0800800 vkCmdCopyBuffer(cmd_.handle(), bufs[1].handle(), bufs[2].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000801
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600802 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
803 * This could be vkCmdPipelineBarrier.
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000804 */
Chia-I Wube2b9172015-07-03 11:49:42 +0800805 vkCmdSetEvent(cmd_.handle(), event, VK_PIPELINE_STAGE_TRANSFER_BIT);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000806
807 // Additional commands could go into the buffer here before the wait.
808
809 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800810 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600811 pmemory_barrier = &memory_barrier;
Chia-I Wube2b9172015-07-03 11:49:42 +0800812 vkCmdWaitEvents(cmd_.handle(), 1, &event, src_stages, dest_stages, 1, (const void **)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000813
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800814 cmd_.end();
815
816 submit_and_done();
817
Chia-I Wu681d7a02015-07-03 13:44:34 +0800818 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800819 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800820 bufs[2].memory().unmap();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000821
Chia-I Wuf7458c52015-10-26 21:10:41 +0800822 vkDestroyEvent(dev_.handle(), event, NULL);
Tony Barbour7db519b2015-06-26 11:49:05 -0600823
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800824}
825
Tony Barbour6918cd52015-04-09 12:58:51 -0600826class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800827protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600828 void init_test_formats(VkFlags features)
Chia-I Wud7414b02014-10-21 11:06:26 +0800829 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600830 first_linear_format_ = VK_FORMAT_UNDEFINED;
831 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wud7414b02014-10-21 11:06:26 +0800832
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600833 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800834 it != dev_.formats().end(); it++) {
835 if (it->features & features) {
836 test_formats_.push_back(*it);
Chia-I Wud7414b02014-10-21 11:06:26 +0800837
Tony Barbourd1c35722015-04-16 15:59:00 -0600838 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
839 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800840 first_linear_format_ = it->format;
Tony Barbourd1c35722015-04-16 15:59:00 -0600841 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
842 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800843 first_optimal_format_ = it->format;
844 }
845 }
846 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800847
Chia-I Wu5bc27862014-12-22 13:19:08 +0800848 void init_test_formats()
849 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600850 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu5bc27862014-12-22 13:19:08 +0800851 }
852
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600853 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800854 {
855 if (img.transparent()) {
856 checker.fill(img);
857 return;
Chia-I Wud7414b02014-10-21 11:06:26 +0800858 }
859
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800860 ASSERT_EQ(true, img.copyable());
861
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600862 vk_testing::Buffer in_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600863 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
864
Cody Northrop7fb43862015-06-22 14:56:14 -0600865 in_buf.init_as_src(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800866 checker.fill(in_buf);
867
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800868 // copy in and tile
869 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800870 vkCmdCopyBufferToImage(cmd_.handle(), in_buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700871 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800872 checker.regions().size(), &checker.regions()[0]);
873 cmd_.end();
874
875 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800876 }
877
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600878 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wud6479012014-11-22 15:09:42 +0800879 {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800880 if (img.transparent()) {
881 DO(checker.check(img));
882 return;
Chia-I Wud6479012014-11-22 15:09:42 +0800883 }
884
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800885 ASSERT_EQ(true, img.copyable());
886
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600887 vk_testing::Buffer out_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600888 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -0600889 out_buf.init_as_dst(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800890
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800891 // copy out and linearize
892 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800893 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700894 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +0800895 out_buf.handle(),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800896 checker.regions().size(), &checker.regions()[0]);
897 cmd_.end();
898
899 submit_and_done();
900
901 DO(checker.check(out_buf));
Chia-I Wud6479012014-11-22 15:09:42 +0800902 }
903
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600904 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600905 VkFormat first_linear_format_;
906 VkFormat first_optimal_format_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800907};
908
Tony Barbour6918cd52015-04-09 12:58:51 -0600909class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800910protected:
911 virtual void SetUp()
912 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600913 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600914 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800915 ASSERT_NE(true, test_formats_.empty());
916 }
917
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600918 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800919 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600920 vk_testing::Buffer buf;
921 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -0600922 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
923 VkMemoryPropertyFlags image_reqs =
924 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800925
Cody Northrop7fb43862015-06-22 14:56:14 -0600926 buf.init_as_src(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800927 checker.fill(buf);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800928
Tony Barbour0c823b12015-05-21 13:26:05 -0600929 img.init(dev_, img_info, image_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800930
931 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800932 vkCmdCopyBufferToImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800933 buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700934 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800935 checker.regions().size(), &checker.regions()[0]);
936 cmd_.end();
937
938 submit_and_done();
939
940 check_dst(img, checker);
941 }
942
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600943 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800944 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600945 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800946 test_copy_memory_to_image(img_info, checker);
947 }
948
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600949 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800950 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600951 vk_testing::ImageChecker checker(img_info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800952 test_copy_memory_to_image(img_info, checker);
953 }
954};
955
Tony Barbour6918cd52015-04-09 12:58:51 -0600956TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800957{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600958 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800959 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700960
961 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -0600962 if (it->format == VK_FORMAT_UNDEFINED ||
963 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
964 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700965 continue;
966
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600967 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600968 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800969 img_info.format = it->format;
970 img_info.extent.width = 64;
971 img_info.extent.height = 64;
972 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800973 img_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
974 VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700975 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800976
977 test_copy_memory_to_image(img_info);
978 }
Chia-I Wud6479012014-11-22 15:09:42 +0800979}
980
Tony Barbour6918cd52015-04-09 12:58:51 -0600981class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu42b97b82014-12-13 15:28:20 +0800982protected:
983 virtual void SetUp()
984 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600985 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600986 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu42b97b82014-12-13 15:28:20 +0800987 ASSERT_NE(true, test_formats_.empty());
988 }
989
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600990 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu42b97b82014-12-13 15:28:20 +0800991 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600992 vk_testing::Image img;
993 vk_testing::Buffer buf;
Tony Barbour0c823b12015-05-21 13:26:05 -0600994 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
995 VkMemoryPropertyFlags image_reqs =
996 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu42b97b82014-12-13 15:28:20 +0800997
Tony Barbour0c823b12015-05-21 13:26:05 -0600998 img.init(dev_, img_info, image_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +0800999 fill_src(img, checker);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001000
Cody Northrop7fb43862015-06-22 14:56:14 -06001001 buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001002
1003 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001004 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001005 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +08001006 buf.handle(),
Chia-I Wu42b97b82014-12-13 15:28:20 +08001007 checker.regions().size(), &checker.regions()[0]);
1008 cmd_.end();
1009
1010 submit_and_done();
1011
1012 checker.check(buf);
1013 }
1014
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001015 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001016 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001017 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001018 test_copy_image_to_memory(img_info, checker);
1019 }
1020
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001021 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001022 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001023 vk_testing::ImageChecker checker(img_info);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001024 test_copy_image_to_memory(img_info, checker);
1025 }
1026};
1027
Tony Barbour6918cd52015-04-09 12:58:51 -06001028TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001029{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001030 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu42b97b82014-12-13 15:28:20 +08001031 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001032
1033 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001034 if (it->format == VK_FORMAT_UNDEFINED ||
1035 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1036 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001037 continue;
1038
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001039 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001040 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001041 img_info.format = it->format;
1042 img_info.extent.width = 64;
1043 img_info.extent.height = 64;
1044 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001045 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1046 VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001047 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001048
1049 test_copy_image_to_memory(img_info);
1050 }
1051}
1052
Tony Barbour6918cd52015-04-09 12:58:51 -06001053class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001054protected:
1055 virtual void SetUp()
1056 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001057 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001058 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001059 ASSERT_NE(true, test_formats_.empty());
Chia-I Wu89078aa2014-11-22 16:24:41 +08001060 }
1061
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001062 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1063 const std::vector<VkImageCopy> &copies)
Chia-I Wu89078aa2014-11-22 16:24:41 +08001064 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001065 // convert VkImageCopy to two sets of VkBufferImageCopy
1066 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbourd1c35722015-04-16 15:59:00 -06001067 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001068 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1069 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wu89078aa2014-11-22 16:24:41 +08001070
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001071 src_region.bufferOffset = src_offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001072 src_region.imageSubresource = it->srcSubresource;
1073 src_region.imageOffset = it->srcOffset;
1074 src_region.imageExtent = it->extent;
1075 src_regions.push_back(src_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001076
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001077 dst_region.bufferOffset = src_offset;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001078 dst_region.imageSubresource = it->dstSubresource;
1079 dst_region.imageOffset = it->dstOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001080 dst_region.imageExtent = it->extent;
1081 dst_regions.push_back(dst_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001082
Tony Barbourd1c35722015-04-16 15:59:00 -06001083 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001084 src_offset += vk_testing::get_format_size(src_info.format) * size;
1085 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001086 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001087
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001088 vk_testing::ImageChecker src_checker(src_info, src_regions);
1089 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour0c823b12015-05-21 13:26:05 -06001090 VkMemoryPropertyFlags src_reqs =
1091 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1092 VkMemoryPropertyFlags dst_reqs =
1093 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1094
1095
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001096
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001097 vk_testing::Image src;
Tony Barbour0c823b12015-05-21 13:26:05 -06001098 src.init(dev_, src_info, src_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001099 fill_src(src, src_checker);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001100
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001101 vk_testing::Image dst;
Tony Barbour0c823b12015-05-21 13:26:05 -06001102 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001103
1104 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001105 vkCmdCopyImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001106 src.handle(), VK_IMAGE_LAYOUT_GENERAL,
1107 dst.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001108 copies.size(), &copies[0]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001109 cmd_.end();
1110
1111 submit_and_done();
1112
1113 check_dst(dst, dst_checker);
1114 }
1115};
1116
Tony Barbour6918cd52015-04-09 12:58:51 -06001117TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001118{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001119 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001120 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001121
1122 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001123 if (it->format == VK_FORMAT_UNDEFINED ||
1124 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1125 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001126 continue;
1127
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001128 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001129 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001130 img_info.format = it->format;
1131 img_info.extent.width = 64;
1132 img_info.extent.height = 64;
1133 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001134 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001135 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001136
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001137 VkImageCopy copy = {};
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06001138 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001139 copy.dstSubresource = copy.srcSubresource;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001140 copy.extent = img_info.extent;
1141
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001142 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001143 }
1144}
1145
Tony Barbour6918cd52015-04-09 12:58:51 -06001146class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001147protected:
Chris Forbesf0796e12015-06-24 14:34:53 +12001148 VkCmdClearColorImageTest() {}
Chia-I Wu5bc27862014-12-22 13:19:08 +08001149
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001150 virtual void SetUp()
1151 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001152 VkCmdBlitTest::SetUp();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001153
Courtney Goeltzenleuchtercda30342015-09-10 16:25:49 -06001154 init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001155
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001156 ASSERT_NE(true, test_formats_.empty());
1157 }
1158
Chia-I Wu5bc27862014-12-22 13:19:08 +08001159 union Color {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001160 float color[4];
1161 uint32_t raw[4];
Chia-I Wu5bc27862014-12-22 13:19:08 +08001162 };
1163
Chris Forbesf0796e12015-06-24 14:34:53 +12001164 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001165 {
1166 std::vector<uint8_t> raw;
1167
1168 // TODO support all formats
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001169 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001170 case VK_FORMAT_R8G8B8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001171 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1172 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1173 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1174 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001175 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001176 case VK_FORMAT_B8G8R8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001177 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1178 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1179 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1180 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001181 break;
1182 default:
1183 break;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001184 }
1185
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001186 return raw;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001187 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001188
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001189 void test_clear_color_image(const VkImageCreateInfo &img_info,
Chris Forbesf0796e12015-06-24 14:34:53 +12001190 const VkClearColorValue &clear_color,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001191 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wud7414b02014-10-21 11:06:26 +08001192 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001193 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001194 VkMemoryPropertyFlags image_reqs =
1195 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001196
Tony Barbour0c823b12015-05-21 13:26:05 -06001197 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001198 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001199 VK_ACCESS_HOST_WRITE_BIT |
1200 VK_ACCESS_SHADER_WRITE_BIT |
1201 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1202 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1203 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001204 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001205 VK_ACCESS_HOST_READ_BIT |
1206 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1207 VK_ACCESS_INDEX_READ_BIT |
1208 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1209 VK_ACCESS_UNIFORM_READ_BIT |
1210 VK_ACCESS_SHADER_READ_BIT |
1211 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1212 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1213 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +08001214
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001215 std::vector<VkImageMemoryBarrier> to_clear;
1216 std::vector<VkImageMemoryBarrier *> p_to_clear;
1217 std::vector<VkImageMemoryBarrier> to_xfer;
1218 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wud7414b02014-10-21 11:06:26 +08001219
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001220 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001221 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001222 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001223 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001224 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001225 *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001226 p_to_clear.push_back(&to_clear.back());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001227 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001228 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001229 VK_IMAGE_LAYOUT_GENERAL, *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001230 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wud7414b02014-10-21 11:06:26 +08001231 }
1232
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001233 cmd_.begin();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001234
Chia-I Wu89d0f942015-10-31 00:31:16 +08001235 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1236 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001237 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001238
Chia-I Wube2b9172015-07-03 11:49:42 +08001239 vkCmdClearColorImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001240 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001241 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001242
Chia-I Wu53534662015-10-26 17:08:33 +08001243 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001244
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001245 cmd_.end();
1246
1247 submit_and_done();
1248
1249 // cannot verify
1250 if (!img.transparent() && !img.copyable())
1251 return;
1252
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001253 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001254
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -06001255 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001256 if (solid_pattern.empty())
1257 return;
1258
1259 checker.set_solid_pattern(solid_pattern);
1260 check_dst(img, checker);
1261 }
Chia-I Wu5bc27862014-12-22 13:19:08 +08001262
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001263 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001264 const float color[4],
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001265 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu5bc27862014-12-22 13:19:08 +08001266 {
Chris Forbesf0796e12015-06-24 14:34:53 +12001267 VkClearColorValue c = {};
Cody Northrop85789d52015-08-25 15:26:38 -06001268 memcpy(c.float32, color, sizeof(c.float32));
Chia-I Wu5bc27862014-12-22 13:19:08 +08001269 test_clear_color_image(img_info, c, ranges);
1270 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001271};
1272
Tony Barbour6918cd52015-04-09 12:58:51 -06001273TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001274{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001275 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001276 it != test_formats_.end(); it++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001277 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barboura36f5282015-06-05 12:53:55 -06001278 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001279
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001280 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001281
Tony Barboura36f5282015-06-05 12:53:55 -06001282 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1283 continue;
1284
1285 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1286 continue;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001287
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001288 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001289 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001290 img_info.format = it->format;
1291 img_info.extent.width = 64;
1292 img_info.extent.height = 64;
1293 img_info.tiling = it->tiling;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001294 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barboure65788f2015-07-21 17:01:42 -06001295 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001296 VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001297
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001298 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001299 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001300 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001301
1302 test_clear_color_image(img_info, color, ranges);
Chia-I Wud7414b02014-10-21 11:06:26 +08001303 }
1304}
1305
Tony Barbour6918cd52015-04-09 12:58:51 -06001306class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001307protected:
1308 virtual void SetUp()
1309 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001310 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001311 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001312 ASSERT_NE(true, test_formats_.empty());
1313 }
1314
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001315 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001316 {
1317 std::vector<uint8_t> raw;
1318
1319 // depth
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001320 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001321 case VK_FORMAT_D16_UNORM:
1322 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001323 {
Tony Barbour048f2812015-06-09 13:40:53 -06001324 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001325 raw.push_back(unorm & 0xff);
1326 raw.push_back(unorm >> 8);
1327 }
1328 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001329 case VK_FORMAT_D32_SFLOAT:
1330 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001331 {
1332 const union {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001333 float depth;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001334 uint32_t u32;
1335 } u = { depth };
1336
1337 raw.push_back((u.u32 ) & 0xff);
1338 raw.push_back((u.u32 >> 8) & 0xff);
1339 raw.push_back((u.u32 >> 16) & 0xff);
1340 raw.push_back((u.u32 >> 24) & 0xff);
1341 }
1342 break;
1343 default:
1344 break;
1345 }
1346
1347 // stencil
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001348 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001349 case VK_FORMAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001350 raw.push_back(stencil);
1351 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001352 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001353 raw.push_back(stencil);
1354 raw.push_back(0);
1355 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001356 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001357 raw.push_back(stencil);
1358 raw.push_back(0);
1359 raw.push_back(0);
1360 raw.push_back(0);
1361 break;
1362 default:
1363 break;
1364 }
1365
1366 return raw;
1367 }
1368
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001369 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001370 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001371 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001372 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001373 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001374 VkMemoryPropertyFlags image_reqs =
1375 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001376
Tony Barbour0c823b12015-05-21 13:26:05 -06001377 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001378 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001379 VK_ACCESS_HOST_WRITE_BIT |
1380 VK_ACCESS_SHADER_WRITE_BIT |
1381 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1382 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1383 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001384 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001385 VK_ACCESS_HOST_READ_BIT |
1386 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1387 VK_ACCESS_INDEX_READ_BIT |
1388 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1389 VK_ACCESS_UNIFORM_READ_BIT |
1390 VK_ACCESS_SHADER_READ_BIT |
1391 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1392 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1393 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001394
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001395 std::vector<VkImageMemoryBarrier> to_clear;
1396 std::vector<VkImageMemoryBarrier *> p_to_clear;
1397 std::vector<VkImageMemoryBarrier> to_xfer;
1398 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001399 unsigned int i = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001400
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001401 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001402 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001403 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001404 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001405 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001406 *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001407
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001408 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001409 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001410 VK_IMAGE_LAYOUT_GENERAL, *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001411 }
1412 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
1413 it != ranges.end(); it++) {
1414 p_to_clear.push_back(to_clear.data() + i);
1415 p_to_xfer.push_back(to_xfer.data() + i);
1416 i++;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001417 }
1418
1419 cmd_.begin();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001420
Chia-I Wu89d0f942015-10-31 00:31:16 +08001421 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1422 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001423 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 +00001424
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001425 VkClearDepthStencilValue clear_value = {
1426 depth,
1427 stencil
1428 };
Chia-I Wube2b9172015-07-03 11:49:42 +08001429 vkCmdClearDepthStencilImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001430 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001431 &clear_value,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001432 ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001433
Chia-I Wu53534662015-10-26 17:08:33 +08001434 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 +00001435
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001436 cmd_.end();
1437
1438 submit_and_done();
1439
1440 // cannot verify
1441 if (!img.transparent() && !img.copyable())
1442 return;
1443
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001444 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001445
1446 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1447 check_dst(img, checker);
1448 }
1449};
1450
Tony Barbour6918cd52015-04-09 12:58:51 -06001451TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001452{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001453 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001454 it != test_formats_.end(); it++) {
Tony Barboura36f5282015-06-05 12:53:55 -06001455 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001456
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001457 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001458
Tony Barboura36f5282015-06-05 12:53:55 -06001459 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1460 continue;
1461
1462 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1463 continue;
1464
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001465 // known driver issues
Tony Barbourd1c35722015-04-16 15:59:00 -06001466 if (it->format == VK_FORMAT_S8_UINT ||
Chia-I Wu935f2ed2015-11-10 17:01:22 +08001467 it->format == VK_FORMAT_X8_D24_UNORM_PACK32 ||
Tony Barbourd1c35722015-04-16 15:59:00 -06001468 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1469 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001470 continue;
1471
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001472 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001473 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001474 img_info.format = it->format;
1475 img_info.extent.width = 64;
1476 img_info.extent.height = 64;
1477 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -06001478 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001479 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1480 VkImageAspectFlags aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001481
Tony Barbour048f2812015-06-09 13:40:53 -06001482 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1483 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1484 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001485 aspect |= VK_IMAGE_ASPECT_STENCIL_BIT;
1486 }
Tony Barbour048f2812015-06-09 13:40:53 -06001487
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001488 const VkImageSubresourceRange range =
1489 vk_testing::Image::subresource_range(img_info, aspect);
1490 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Tony Barbour048f2812015-06-09 13:40:53 -06001491
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001492 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1493 }
1494}
1495
1496}; // namespace
1497
Chia-I Wud7414b02014-10-21 11:06:26 +08001498int main(int argc, char **argv)
1499{
Chia-I Wud7414b02014-10-21 11:06:26 +08001500 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wud7414b02014-10-21 11:06:26 +08001501
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001502 vk_testing::set_error_callback(test_error_callback);
Chia-I Wua9a506a2014-12-27 22:04:00 +08001503
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001504 environment = new vk_testing::Environment();
Chia-I Wud7414b02014-10-21 11:06:26 +08001505
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001506 if (!environment->parse_args(argc, argv))
1507 return -1;
Chia-I Wud7414b02014-10-21 11:06:26 +08001508
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001509 ::testing::AddGlobalTestEnvironment(environment);
1510
1511 return RUN_ALL_TESTS();
Chia-I Wud7414b02014-10-21 11:06:26 +08001512}