blob: d2531b8e2c31a93686f3a52c7920f2bfefb82482 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001// VK tests
Chia-I Wud7414b02014-10-21 11:06:26 +08002//
Chia-I Wu998c2ac2014-12-08 14:30:10 +08003// Copyright (C) 2014 LunarG, Inc.
Chia-I Wud7414b02014-10-21 11:06:26 +08004//
Chia-I Wu998c2ac2014-12-08 14:30:10 +08005// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
Chia-I Wud7414b02014-10-21 11:06:26 +080011//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080012// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
Chia-I Wud7414b02014-10-21 11:06:26 +080014//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080015// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
Chia-I Wud7414b02014-10-21 11:06:26 +080022
23// Blit (copy, clear, and resolve) tests
24
Tony Barbour048f2812015-06-09 13:40:53 -060025#include "math.h"
Chia-I Wua9a506a2014-12-27 22:04:00 +080026#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060027#include "vktestbinding.h"
Tony Barbour92400bb2015-03-02 16:38:52 -070028#include "test_environment.h"
Chia-I Wud7414b02014-10-21 11:06:26 +080029
30#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
31
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060032namespace vk_testing {
Chia-I Wud7414b02014-10-21 11:06:26 +080033
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060034size_t get_format_size(VkFormat format);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080035
Chia-I Wu998c2ac2014-12-08 14:30:10 +080036class ImageChecker {
37public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060038 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080039 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060040 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
41 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080042
43 void set_solid_pattern(const std::vector<uint8_t> &solid);
44
Tony Barbourd1c35722015-04-16 15:59:00 -060045 VkDeviceSize buffer_size() const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080046 bool fill(Buffer &buf) const { return walk(FILL, buf); }
47 bool fill(Image &img) const { return walk(FILL, img); }
48 bool check(Buffer &buf) const { return walk(CHECK, buf); }
49 bool check(Image &img) const { return walk(CHECK, img); }
50
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060051 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu998c2ac2014-12-08 14:30:10 +080052
53 static void hash_salt_generate() { hash_salt_++; }
54
55private:
56 enum Action {
57 FILL,
58 CHECK,
59 };
60
61 enum Pattern {
62 HASH,
63 SOLID,
64 };
65
Mark Lobodzinski17caf572015-01-29 08:55:56 -060066 size_t buffer_cpp() const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060067 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080068
69 bool walk(Action action, Buffer &buf) const;
70 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060071 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080072
Chia-I Wu1b99bb22015-10-27 19:25:11 +080073 std::vector<uint8_t> pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080074
75 static uint32_t hash_salt_;
76
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060077 VkImageCreateInfo info_;
78 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080079
80 Pattern pattern_;
81 std::vector<uint8_t> pattern_solid_;
82};
83
Chia-I Wud7414b02014-10-21 11:06:26 +080084
Chia-I Wu998c2ac2014-12-08 14:30:10 +080085uint32_t ImageChecker::hash_salt_;
86
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060087ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080088 : info_(info), regions_(), pattern_(HASH)
89{
90 // create a region for every mip level in array slice 0
Tony Barbourd1c35722015-04-16 15:59:00 -060091 VkDeviceSize offset = 0;
Mark Lobodzinski17caf572015-01-29 08:55:56 -060092 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060093 VkBufferImageCopy region = {};
Chia-I Wu998c2ac2014-12-08 14:30:10 +080094
Chia-I Wu1a28fe02015-01-01 07:55:04 +080095 region.bufferOffset = offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080096 region.imageSubresource.mipLevel = lv;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060097 region.imageSubresource.baseArrayLayer = 0;
Chia-I Wua9a506a2014-12-27 22:04:00 +080098 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080099
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600100 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600101 if (info_.format != VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800102 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800103 regions_.push_back(region);
104 }
105
Tony Barbourd1c35722015-04-16 15:59:00 -0600106 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
107 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
108 info_.format == VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800109 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800110 regions_.push_back(region);
111 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800112 } else {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800113 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800114 regions_.push_back(region);
115 }
116
117 offset += buffer_layout(region).size;
118 }
119
120 // arraySize should be limited in our tests. If this proves to be an
121 // issue, we can store only the regions for array slice 0 and be smart.
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600122 if (info_.arrayLayers > 1) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600123 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600124 const uint32_t slice_region_count = regions_.size();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800125
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600126 regions_.reserve(slice_region_count * info_.arrayLayers);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800127
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600128 for (uint32_t slice = 1; slice < info_.arrayLayers; slice++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600129 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600130 VkBufferImageCopy region = regions_[i];
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800131
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800132 region.bufferOffset += slice_pitch * slice;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600133 region.imageSubresource.baseArrayLayer = slice;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800134 regions_.push_back(region);
135 }
136 }
137 }
138}
139
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600140ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800141 : info_(info), regions_(), pattern_(HASH)
142{
Tony Barbourd1c35722015-04-16 15:59:00 -0600143 VkDeviceSize offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600144 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800145 it != ranges.end(); it++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800146 for (uint32_t lv = 0; lv < it->levelCount; lv++) {
147 for (uint32_t layer = 0; layer < it->layerCount; layer++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600148 VkBufferImageCopy region = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800149 region.bufferOffset = offset;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600150 region.imageSubresource = Image::subresource(*it, lv, layer, 1);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800151 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800152
153 regions_.push_back(region);
154
155 offset += buffer_layout(region).size;
156 }
157 }
158 }
159}
160
161void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
162{
163 pattern_ = SOLID;
Chia-I Wu72e34332014-12-21 14:59:04 +0800164 pattern_solid_.clear();
165 pattern_solid_.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600166 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800167 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800168}
169
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600170size_t ImageChecker::buffer_cpp() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800171{
172 return get_format_size(info_.format);
173}
174
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600175VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800176{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600177 VkSubresourceLayout layout = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800178 layout.offset = region.bufferOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800179 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
180 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
181 layout.size = layout.depthPitch * region.imageExtent.depth;
182
183 return layout;
184}
185
Tony Barbourd1c35722015-04-16 15:59:00 -0600186VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800187{
Tony Barbourd1c35722015-04-16 15:59:00 -0600188 VkDeviceSize size = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800189
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600190 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800191 it != regions_.end(); it++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600192 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800193 if (size < layout.offset + layout.size)
194 size = layout.offset + layout.size;
195 }
196
197 return size;
198}
199
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600200bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
201 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800202{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600203 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
204 for (int32_t y = 0; y < region.imageExtent.height; y++) {
205 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800206 uint8_t *dst = static_cast<uint8_t *>(data);
207 dst += layout.offset + layout.depthPitch * z +
208 layout.rowPitch * y + buffer_cpp() * x;
209
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600210 VkOffset3D offset = region.imageOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800211 offset.x += x;
212 offset.y += y;
213 offset.z += z;
214
215 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
216 pattern_hash(region.imageSubresource, offset) :
217 pattern_solid_;
218 assert(val.size() == buffer_cpp());
219
220 if (action == FILL) {
221 memcpy(dst, &val[0], val.size());
222 } else {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600223 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800224 EXPECT_EQ(val[i], dst[i]) <<
Cody Northrop28026d42015-08-06 13:17:52 -0600225 "Offset is: (" << x << ", " << y << ", " << z << ")\n"
226 "Format is: (" << info_.format << ")\n";
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800227 if (val[i] != dst[i])
228 return false;
229 }
230 }
231 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800232 }
233 }
234
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800235 return true;
Chia-I Wud7414b02014-10-21 11:06:26 +0800236}
237
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800238bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800239{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800240 void *data = buf.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800241 if (!data)
242 return false;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800243
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600244 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800245 for (it = regions_.begin(); it != regions_.end(); it++) {
246 if (!walk_region(action, *it, buffer_layout(*it), data))
247 break;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800248 }
249
Chia-I Wu681d7a02015-07-03 13:44:34 +0800250 buf.memory().unmap();
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800251
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800252 return (it == regions_.end());
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800253}
254
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800255bool ImageChecker::walk(Action action, Image &img) const
256{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800257 void *data = img.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800258 if (!data)
259 return false;
260
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600261 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800262 for (it = regions_.begin(); it != regions_.end(); it++) {
263 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
264 break;
265 }
266
Chia-I Wu681d7a02015-07-03 13:44:34 +0800267 img.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800268
269 return (it == regions_.end());
270}
271
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800272std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800273{
274#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
275#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
276 const unsigned char input[] = {
277 HASH_BYTES(hash_salt_),
278 HASH_BYTES(subres.mipLevel),
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600279 HASH_BYTES(subres.baseArrayLayer),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800280 HASH_BYTES(offset.x),
281 HASH_BYTES(offset.y),
282 HASH_BYTES(offset.z),
283 };
284 unsigned long hash = 5381;
285
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600286 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800287 hash = ((hash << 5) + hash) + input[i];
288
289 const uint8_t output[4] = { HASH_BYTES(hash) };
290#undef HASH_BYTES
291#undef HASH_BYTE
292
Chia-I Wu72e34332014-12-21 14:59:04 +0800293 std::vector<uint8_t> val;
294 val.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600295 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800296 val.push_back(output[i % 4]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800297
298 return val;
299}
300
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600301size_t get_format_size(VkFormat format)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800302{
Tony Barbourfc3820f2015-05-14 17:15:33 -0600303 static bool format_table_unverified = true;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800304 static const struct format_info {
Courtney Goeltzenleuchterf3387652015-07-08 18:41:08 -0600305 VkFormat format;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600306 size_t size;
307 uint32_t channel_count;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800308 } format_table[VK_FORMAT_RANGE_SIZE] = {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600309 { VK_FORMAT_UNDEFINED, 0, 0 },
310 { VK_FORMAT_R4G4_UNORM, 1, 2 },
311 { VK_FORMAT_R4G4_USCALED, 1, 2 },
312 { VK_FORMAT_R4G4B4A4_UNORM, 2, 4 },
313 { VK_FORMAT_R4G4B4A4_USCALED, 2, 4 },
314 { VK_FORMAT_R5G6B5_UNORM, 2, 3 },
315 { VK_FORMAT_R5G6B5_USCALED, 2, 3 },
316 { VK_FORMAT_R5G5B5A1_UNORM, 2, 4 },
317 { VK_FORMAT_R5G5B5A1_USCALED, 2, 4 },
318 { VK_FORMAT_R8_UNORM, 1, 1 },
319 { VK_FORMAT_R8_SNORM, 1, 1 },
320 { VK_FORMAT_R8_USCALED, 1, 1 },
321 { VK_FORMAT_R8_SSCALED, 1, 1 },
322 { VK_FORMAT_R8_UINT, 1, 1 },
323 { VK_FORMAT_R8_SINT, 1, 1 },
324 { VK_FORMAT_R8_SRGB, 1, 1 },
325 { VK_FORMAT_R8G8_UNORM, 2, 2 },
326 { VK_FORMAT_R8G8_SNORM, 2, 2 },
327 { VK_FORMAT_R8G8_USCALED, 2, 2 },
328 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
329 { VK_FORMAT_R8G8_UINT, 2, 2 },
330 { VK_FORMAT_R8G8_SINT, 2, 2 },
331 { VK_FORMAT_R8G8_SRGB, 2, 2 },
332 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
333 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
334 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
335 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
336 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
337 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
338 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
339 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
340 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
341 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
342 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
343 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
344 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
345 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
346 { VK_FORMAT_R10G10B10A2_UNORM, 4, 4 },
347 { VK_FORMAT_R10G10B10A2_SNORM, 4, 4 },
348 { VK_FORMAT_R10G10B10A2_USCALED, 4, 4 },
349 { VK_FORMAT_R10G10B10A2_SSCALED, 4, 4 },
350 { VK_FORMAT_R10G10B10A2_UINT, 4, 4 },
351 { VK_FORMAT_R10G10B10A2_SINT, 4, 4 },
352 { VK_FORMAT_R16_UNORM, 2, 1 },
353 { VK_FORMAT_R16_SNORM, 2, 1 },
354 { VK_FORMAT_R16_USCALED, 2, 1 },
355 { VK_FORMAT_R16_SSCALED, 2, 1 },
356 { VK_FORMAT_R16_UINT, 2, 1 },
357 { VK_FORMAT_R16_SINT, 2, 1 },
358 { VK_FORMAT_R16_SFLOAT, 2, 1 },
359 { VK_FORMAT_R16G16_UNORM, 4, 2 },
360 { VK_FORMAT_R16G16_SNORM, 4, 2 },
361 { VK_FORMAT_R16G16_USCALED, 4, 2 },
362 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
363 { VK_FORMAT_R16G16_UINT, 4, 2 },
364 { VK_FORMAT_R16G16_SINT, 4, 2 },
365 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
366 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
367 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
368 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
369 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
370 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
371 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
372 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
373 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
374 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
375 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
376 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
377 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
378 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
379 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
380 { VK_FORMAT_R32_UINT, 4, 1 },
381 { VK_FORMAT_R32_SINT, 4, 1 },
382 { VK_FORMAT_R32_SFLOAT, 4, 1 },
383 { VK_FORMAT_R32G32_UINT, 8, 2 },
384 { VK_FORMAT_R32G32_SINT, 8, 2 },
385 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
386 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
387 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
388 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
389 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
390 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
391 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
392 { VK_FORMAT_R64_SFLOAT, 8, 1 },
393 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
394 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
395 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
396 { VK_FORMAT_R11G11B10_UFLOAT, 4, 3 },
397 { VK_FORMAT_R9G9B9E5_UFLOAT, 4, 3 },
398 { VK_FORMAT_D16_UNORM, 2, 1 },
Courtney Goeltzenleuchter286fb5f2015-09-10 17:17:43 -0600399 { VK_FORMAT_D24_UNORM_X8, 3, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600400 { VK_FORMAT_D32_SFLOAT, 4, 1 },
401 { VK_FORMAT_S8_UINT, 1, 1 },
402 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
403 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbour048f2812015-06-09 13:40:53 -0600404 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600405 { VK_FORMAT_BC1_RGB_UNORM, 8, 4 },
406 { VK_FORMAT_BC1_RGB_SRGB, 8, 4 },
407 { VK_FORMAT_BC1_RGBA_UNORM, 8, 4 },
408 { VK_FORMAT_BC1_RGBA_SRGB, 8, 4 },
409 { VK_FORMAT_BC2_UNORM, 16, 4 },
410 { VK_FORMAT_BC2_SRGB, 16, 4 },
411 { VK_FORMAT_BC3_UNORM, 16, 4 },
412 { VK_FORMAT_BC3_SRGB, 16, 4 },
413 { VK_FORMAT_BC4_UNORM, 8, 4 },
414 { VK_FORMAT_BC4_SNORM, 8, 4 },
415 { VK_FORMAT_BC5_UNORM, 16, 4 },
416 { VK_FORMAT_BC5_SNORM, 16, 4 },
417 { VK_FORMAT_BC6H_UFLOAT, 16, 4 },
418 { VK_FORMAT_BC6H_SFLOAT, 16, 4 },
419 { VK_FORMAT_BC7_UNORM, 16, 4 },
420 { VK_FORMAT_BC7_SRGB, 16, 4 },
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700421 // TODO: Initialize remaining compressed formats.
Tony Barbourfc3820f2015-05-14 17:15:33 -0600422 { VK_FORMAT_ETC2_R8G8B8_UNORM, 0, 0 },
423 { VK_FORMAT_ETC2_R8G8B8_SRGB, 0, 0 },
424 { VK_FORMAT_ETC2_R8G8B8A1_UNORM, 0, 0 },
425 { VK_FORMAT_ETC2_R8G8B8A1_SRGB, 0, 0 },
426 { VK_FORMAT_ETC2_R8G8B8A8_UNORM, 0, 0 },
427 { VK_FORMAT_ETC2_R8G8B8A8_SRGB, 0, 0 },
428 { VK_FORMAT_EAC_R11_UNORM, 0, 0 },
429 { VK_FORMAT_EAC_R11_SNORM, 0, 0 },
430 { VK_FORMAT_EAC_R11G11_UNORM, 0, 0 },
431 { VK_FORMAT_EAC_R11G11_SNORM, 0, 0 },
432 { VK_FORMAT_ASTC_4x4_UNORM, 0, 0 },
433 { VK_FORMAT_ASTC_4x4_SRGB, 0, 0 },
434 { VK_FORMAT_ASTC_5x4_UNORM, 0, 0 },
435 { VK_FORMAT_ASTC_5x4_SRGB, 0, 0 },
436 { VK_FORMAT_ASTC_5x5_UNORM, 0, 0 },
437 { VK_FORMAT_ASTC_5x5_SRGB, 0, 0 },
438 { VK_FORMAT_ASTC_6x5_UNORM, 0, 0 },
439 { VK_FORMAT_ASTC_6x5_SRGB, 0, 0 },
440 { VK_FORMAT_ASTC_6x6_UNORM, 0, 0 },
441 { VK_FORMAT_ASTC_6x6_SRGB, 0, 0 },
442 { VK_FORMAT_ASTC_8x5_UNORM, 0, 0 },
443 { VK_FORMAT_ASTC_8x5_SRGB, 0, 0 },
444 { VK_FORMAT_ASTC_8x6_UNORM, 0, 0 },
445 { VK_FORMAT_ASTC_8x6_SRGB, 0, 0 },
446 { VK_FORMAT_ASTC_8x8_UNORM, 0, 0 },
447 { VK_FORMAT_ASTC_8x8_SRGB, 0, 0 },
448 { VK_FORMAT_ASTC_10x5_UNORM, 0, 0 },
449 { VK_FORMAT_ASTC_10x5_SRGB, 0, 0 },
450 { VK_FORMAT_ASTC_10x6_UNORM, 0, 0 },
451 { VK_FORMAT_ASTC_10x6_SRGB, 0, 0 },
452 { VK_FORMAT_ASTC_10x8_UNORM, 0, 0 },
453 { VK_FORMAT_ASTC_10x8_SRGB, 0, 0 },
454 { VK_FORMAT_ASTC_10x10_UNORM, 0, 0 },
455 { VK_FORMAT_ASTC_10x10_SRGB, 0, 0 },
456 { VK_FORMAT_ASTC_12x10_UNORM, 0, 0 },
457 { VK_FORMAT_ASTC_12x10_SRGB, 0, 0 },
458 { VK_FORMAT_ASTC_12x12_UNORM, 0, 0 },
459 { VK_FORMAT_ASTC_12x12_SRGB, 0, 0 },
460 { VK_FORMAT_B4G4R4A4_UNORM, 2, 4 },
461 { VK_FORMAT_B5G5R5A1_UNORM, 2, 4 },
462 { VK_FORMAT_B5G6R5_UNORM, 2, 3 },
463 { VK_FORMAT_B5G6R5_USCALED, 2, 3 },
464 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
465 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
466 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
467 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
468 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
469 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
470 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
471 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
472 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
473 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
474 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
475 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
476 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
477 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
478 { VK_FORMAT_B10G10R10A2_UNORM, 4, 4 },
479 { VK_FORMAT_B10G10R10A2_SNORM, 4, 4 },
480 { VK_FORMAT_B10G10R10A2_USCALED, 4, 4 },
481 { VK_FORMAT_B10G10R10A2_SSCALED, 4, 4 },
482 { VK_FORMAT_B10G10R10A2_UINT, 4, 4 },
483 { VK_FORMAT_B10G10R10A2_SINT, 4, 4 },
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800484 };
Tony Barbourfc3820f2015-05-14 17:15:33 -0600485 if (format_table_unverified)
486 {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800487 for (unsigned int i = 0; i < VK_FORMAT_RANGE_SIZE; i++)
Tony Barbourfc3820f2015-05-14 17:15:33 -0600488 {
489 assert(format_table[i].format == i);
490 }
491 format_table_unverified = false;
492 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800493
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700494 return format_table[format].size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800495}
496
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600497VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800498{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600499 const VkExtent3D ext = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800500 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
501 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
502 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
503 };
504
505 return ext;
506}
507
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600508}; // namespace vk_testing
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800509
510namespace {
511
512#define DO(action) ASSERT_EQ(true, action);
513
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600514static vk_testing::Environment *environment;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800515
Tony Barbour6918cd52015-04-09 12:58:51 -0600516class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800517protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600518 VkCmdBlitTest() :
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800519 dev_(environment->default_device()),
Chia-I Wua9a506a2014-12-27 22:04:00 +0800520 queue_(*dev_.graphics_queues()[0]),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800521 pool_(dev_, vk_testing::CommandPool::create_info(dev_.graphics_queue_node_index_)),
522 cmd_(dev_, vk_testing::CommandBuffer::create_info(pool_.handle()))
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800523 {
524 // make sure every test uses a different pattern
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600525 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800526 }
527
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800528 bool submit_and_done()
529 {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600530 queue_.submit(cmd_);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800531 queue_.wait();
532 mem_refs_.clear();
533 return true;
534 }
535
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600536 vk_testing::Device &dev_;
537 vk_testing::Queue &queue_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800538 vk_testing::CommandPool pool_;
539 vk_testing::CommandBuffer cmd_;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800540
Chris Forbes9e50dab2015-07-11 19:11:39 +1200541 /* TODO: We should be able to remove these now */
Tony Barbourd1c35722015-04-16 15:59:00 -0600542 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800543};
544
Tony Barbour6918cd52015-04-09 12:58:51 -0600545typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800546
Tony Barbour6918cd52015-04-09 12:58:51 -0600547TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800548{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600549 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600550 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800551
Cody Northrop7fb43862015-06-22 14:56:14 -0600552 buf.init_as_dst(dev_, 20, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800553
554 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800555 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 4, 0x11111111);
556 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 4, 16, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800557 cmd_.end();
558
559 submit_and_done();
560
Chia-I Wu681d7a02015-07-03 13:44:34 +0800561 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800562 EXPECT_EQ(0x11111111, data[0]);
563 EXPECT_EQ(0x22222222, data[1]);
564 EXPECT_EQ(0x22222222, data[2]);
565 EXPECT_EQ(0x22222222, data[3]);
566 EXPECT_EQ(0x22222222, data[4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800567 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800568}
569
Tony Barbour6918cd52015-04-09 12:58:51 -0600570TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wud94726f2014-11-23 02:16:45 +0800571{
Tony Barbourd1c35722015-04-16 15:59:00 -0600572 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600573 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600574 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud94726f2014-11-23 02:16:45 +0800575
Cody Northrop7fb43862015-06-22 14:56:14 -0600576 buf.init_as_dst(dev_, size, reqs);
Chia-I Wud94726f2014-11-23 02:16:45 +0800577
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800578 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800579 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, size / 2, 0x11111111);
580 vkCmdFillBuffer(cmd_.handle(), buf.handle(), size / 2, size / 2, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800581 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800582
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800583 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800584
Chia-I Wu681d7a02015-07-03 13:44:34 +0800585 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600586 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800587 for (offset = 0; offset < size / 2; offset += 4)
588 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
589 for (; offset < size; offset += 4)
590 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800591 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800592}
Chia-I Wud94726f2014-11-23 02:16:45 +0800593
Tony Barbour6918cd52015-04-09 12:58:51 -0600594TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800595{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600596 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600597 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800598
Cody Northrop7fb43862015-06-22 14:56:14 -0600599 buf.init_as_dst(dev_, 64, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800600
601 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800602 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 48, 0x11111111);
603 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 32, 32, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800604 cmd_.end();
605
606 submit_and_done();
607
Chia-I Wu681d7a02015-07-03 13:44:34 +0800608 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600609 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800610 for (offset = 0; offset < 32; offset += 4)
611 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
612 for (; offset < 64; offset += 4)
613 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800614 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800615}
616
Tony Barbour6918cd52015-04-09 12:58:51 -0600617TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800618{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 vk_testing::Buffer bufs[9];
Tony Barbourd1c35722015-04-16 15:59:00 -0600620 VkDeviceSize size = 4;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600621 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800622
623 cmd_.begin();
624 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600625 bufs[i].init_as_dst(dev_, size, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800626 vkCmdFillBuffer(cmd_.handle(), bufs[i].handle(), 0, size, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800627 size <<= 1;
628 }
629 cmd_.end();
630
631 submit_and_done();
632
633 size = 4;
634 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800635 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600636 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800637 for (offset = 0; offset < size; offset += 4)
638 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
639 "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800640 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800641
642 size <<= 1;
643 }
644}
645
Tony Barbour6918cd52015-04-09 12:58:51 -0600646typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800647
Tony Barbour6918cd52015-04-09 12:58:51 -0600648TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800649{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600650 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600651 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800652
Cody Northrop7fb43862015-06-22 14:56:14 -0600653 src.init_as_src(dev_, 4, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800654 uint32_t *data = static_cast<uint32_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800655 data[0] = 0x11111111;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800656 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800657
Cody Northrop7fb43862015-06-22 14:56:14 -0600658 dst.init_as_dst(dev_, 4, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800659
660 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600661 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800662 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800663 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800664 cmd_.end();
665
666 submit_and_done();
667
Chia-I Wu681d7a02015-07-03 13:44:34 +0800668 data = static_cast<uint32_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800669 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800670 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800671}
672
Tony Barbour6918cd52015-04-09 12:58:51 -0600673TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800674{
Tony Barbourd1c35722015-04-16 15:59:00 -0600675 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600676 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600677 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800678
Cody Northropd2ad0342015-08-05 11:15:02 -0600679 src.init_as_src(dev_, size * sizeof(VkDeviceSize), reqs);
680 VkDeviceSize *data = static_cast<VkDeviceSize *>(src.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600681 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800682 for (offset = 0; offset < size; offset += 4)
683 data[offset / 4] = offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800684 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800685
Cody Northropd2ad0342015-08-05 11:15:02 -0600686 dst.init_as_dst(dev_, size * sizeof(VkDeviceSize), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800687
688 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600689 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800690 region.size = size * sizeof(VkDeviceSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800691 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800692 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800693
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800694 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800695
Cody Northropd2ad0342015-08-05 11:15:02 -0600696 data = static_cast<VkDeviceSize *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800697 for (offset = 0; offset < size; offset += 4)
698 EXPECT_EQ(offset, data[offset / 4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800699 dst.memory().unmap();
Chia-I Wud94726f2014-11-23 02:16:45 +0800700}
701
Tony Barbour6918cd52015-04-09 12:58:51 -0600702TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wud7414b02014-10-21 11:06:26 +0800703{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600704 const VkBufferCopy regions[] = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800705 /* well aligned */
706 { 0, 0, 256 },
707 { 0, 256, 128 },
708 { 0, 384, 64 },
709 { 0, 448, 32 },
710 { 0, 480, 16 },
711 { 0, 496, 8 },
Chia-I Wud7414b02014-10-21 11:06:26 +0800712
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800713 /* ill aligned */
714 { 7, 510, 16 },
715 { 16, 530, 13 },
716 { 32, 551, 16 },
717 { 45, 570, 15 },
718 { 50, 590, 1 },
719 };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600720 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600721 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +0800722
Cody Northrop7fb43862015-06-22 14:56:14 -0600723 src.init_as_src(dev_, 256, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800724 uint8_t *data = static_cast<uint8_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800725 for (int i = 0; i < 256; i++)
726 data[i] = i;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800727 src.memory().unmap();
Chia-I Wud7414b02014-10-21 11:06:26 +0800728
Cody Northrop7fb43862015-06-22 14:56:14 -0600729 dst.init_as_dst(dev_, 1024, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800730
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800731 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800732 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), ARRAY_SIZE(regions), regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800733 cmd_.end();
Chia-I Wud7414b02014-10-21 11:06:26 +0800734
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800735 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800736
Chia-I Wu681d7a02015-07-03 13:44:34 +0800737 data = static_cast<uint8_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800738 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600739 const VkBufferCopy &r = regions[i];
Chia-I Wud7414b02014-10-21 11:06:26 +0800740
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800741 for (int j = 0; j < r.size; j++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800742 EXPECT_EQ(r.srcOffset + j, data[r.dstOffset + j]) <<
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800743 "Region is: " << i << "\n" <<
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800744 "Offset is: " << r.dstOffset + j;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800745 }
746 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800747 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800748}
Chia-I Wud7414b02014-10-21 11:06:26 +0800749
Tony Barbour6918cd52015-04-09 12:58:51 -0600750TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800751{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600752 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753 VkEventCreateInfo event_info;
754 VkEvent event;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600755 VkResult err;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600756 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000757
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600758 // typedef struct VkEventCreateInfo_
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000759 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600760 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600761 // const void* pNext; // Pointer to next structure
762 // VkFlags flags; // Reserved
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600763 // } VkEventCreateInfo;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000764 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600765 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000766
Chia-I Wuf7458c52015-10-26 21:10:41 +0800767 err = vkCreateEvent(dev_.handle(), &event_info, NULL, &event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600768 ASSERT_VK_SUCCESS(err);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000769
Chia-I Wuf368b602015-07-03 10:41:20 +0800770 err = vkResetEvent(dev_.handle(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600771 ASSERT_VK_SUCCESS(err);
Chia-I Wud7414b02014-10-21 11:06:26 +0800772
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800773 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600774 bufs[i].init_as_src_and_dst(dev_, 4, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800775
Chia-I Wu681d7a02015-07-03 13:44:34 +0800776 uint32_t *data = static_cast<uint32_t *>(bufs[i].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800777 data[0] = 0x22222222 * (i + 1);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800778 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800779 }
780
781 cmd_.begin();
782
Chia-I Wu681d7a02015-07-03 13:44:34 +0800783 vkCmdFillBuffer(cmd_.handle(), bufs[0].handle(), 0, 4, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800784 // is this necessary?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600785 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800786 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600787 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000788
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600789 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
790 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +0800791 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800792
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600793 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800794 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800795 vkCmdCopyBuffer(cmd_.handle(), bufs[0].handle(), bufs[1].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000796
797 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800798 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600799 pmemory_barrier = &memory_barrier;
Chia-I Wu53534662015-10-26 17:08:33 +0800800 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800801
Chia-I Wu681d7a02015-07-03 13:44:34 +0800802 vkCmdCopyBuffer(cmd_.handle(), bufs[1].handle(), bufs[2].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000803
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600804 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
805 * This could be vkCmdPipelineBarrier.
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000806 */
Chia-I Wube2b9172015-07-03 11:49:42 +0800807 vkCmdSetEvent(cmd_.handle(), event, VK_PIPELINE_STAGE_TRANSFER_BIT);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000808
809 // Additional commands could go into the buffer here before the wait.
810
811 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800812 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600813 pmemory_barrier = &memory_barrier;
Chia-I Wube2b9172015-07-03 11:49:42 +0800814 vkCmdWaitEvents(cmd_.handle(), 1, &event, src_stages, dest_stages, 1, (const void **)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000815
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800816 cmd_.end();
817
818 submit_and_done();
819
Chia-I Wu681d7a02015-07-03 13:44:34 +0800820 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800821 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800822 bufs[2].memory().unmap();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000823
Chia-I Wuf7458c52015-10-26 21:10:41 +0800824 vkDestroyEvent(dev_.handle(), event, NULL);
Tony Barbour7db519b2015-06-26 11:49:05 -0600825
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800826}
827
Tony Barbour6918cd52015-04-09 12:58:51 -0600828class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800829protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600830 void init_test_formats(VkFlags features)
Chia-I Wud7414b02014-10-21 11:06:26 +0800831 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600832 first_linear_format_ = VK_FORMAT_UNDEFINED;
833 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wud7414b02014-10-21 11:06:26 +0800834
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600835 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800836 it != dev_.formats().end(); it++) {
837 if (it->features & features) {
838 test_formats_.push_back(*it);
Chia-I Wud7414b02014-10-21 11:06:26 +0800839
Tony Barbourd1c35722015-04-16 15:59:00 -0600840 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
841 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800842 first_linear_format_ = it->format;
Tony Barbourd1c35722015-04-16 15:59:00 -0600843 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
844 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800845 first_optimal_format_ = it->format;
846 }
847 }
848 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800849
Chia-I Wu5bc27862014-12-22 13:19:08 +0800850 void init_test_formats()
851 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600852 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu5bc27862014-12-22 13:19:08 +0800853 }
854
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600855 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800856 {
857 if (img.transparent()) {
858 checker.fill(img);
859 return;
Chia-I Wud7414b02014-10-21 11:06:26 +0800860 }
861
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800862 ASSERT_EQ(true, img.copyable());
863
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600864 vk_testing::Buffer in_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600865 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
866
Cody Northrop7fb43862015-06-22 14:56:14 -0600867 in_buf.init_as_src(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800868 checker.fill(in_buf);
869
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800870 // copy in and tile
871 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800872 vkCmdCopyBufferToImage(cmd_.handle(), in_buf.handle(),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800873 img.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800874 checker.regions().size(), &checker.regions()[0]);
875 cmd_.end();
876
877 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800878 }
879
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600880 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wud6479012014-11-22 15:09:42 +0800881 {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800882 if (img.transparent()) {
883 DO(checker.check(img));
884 return;
Chia-I Wud6479012014-11-22 15:09:42 +0800885 }
886
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800887 ASSERT_EQ(true, img.copyable());
888
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600889 vk_testing::Buffer out_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600890 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -0600891 out_buf.init_as_dst(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800892
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800893 // copy out and linearize
894 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800895 vkCmdCopyImageToBuffer(cmd_.handle(),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800896 img.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +0800897 out_buf.handle(),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800898 checker.regions().size(), &checker.regions()[0]);
899 cmd_.end();
900
901 submit_and_done();
902
903 DO(checker.check(out_buf));
Chia-I Wud6479012014-11-22 15:09:42 +0800904 }
905
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600906 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600907 VkFormat first_linear_format_;
908 VkFormat first_optimal_format_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800909};
910
Tony Barbour6918cd52015-04-09 12:58:51 -0600911class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800912protected:
913 virtual void SetUp()
914 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600915 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600916 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800917 ASSERT_NE(true, test_formats_.empty());
918 }
919
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600920 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800921 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600922 vk_testing::Buffer buf;
923 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -0600924 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
925 VkMemoryPropertyFlags image_reqs =
926 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800927
Cody Northrop7fb43862015-06-22 14:56:14 -0600928 buf.init_as_src(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800929 checker.fill(buf);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800930
Tony Barbour0c823b12015-05-21 13:26:05 -0600931 img.init(dev_, img_info, image_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800932
933 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800934 vkCmdCopyBufferToImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800935 buf.handle(),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800936 img.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800937 checker.regions().size(), &checker.regions()[0]);
938 cmd_.end();
939
940 submit_and_done();
941
942 check_dst(img, checker);
943 }
944
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600945 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800946 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600947 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800948 test_copy_memory_to_image(img_info, checker);
949 }
950
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600951 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800952 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600953 vk_testing::ImageChecker checker(img_info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800954 test_copy_memory_to_image(img_info, checker);
955 }
956};
957
Tony Barbour6918cd52015-04-09 12:58:51 -0600958TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800959{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600960 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800961 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700962
963 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -0600964 if (it->format == VK_FORMAT_UNDEFINED ||
965 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
966 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700967 continue;
968
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600969 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600970 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800971 img_info.format = it->format;
972 img_info.extent.width = 64;
973 img_info.extent.height = 64;
974 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800975 img_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
976 VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800977
978 test_copy_memory_to_image(img_info);
979 }
Chia-I Wud6479012014-11-22 15:09:42 +0800980}
981
Tony Barbour6918cd52015-04-09 12:58:51 -0600982class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu42b97b82014-12-13 15:28:20 +0800983protected:
984 virtual void SetUp()
985 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600986 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600987 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu42b97b82014-12-13 15:28:20 +0800988 ASSERT_NE(true, test_formats_.empty());
989 }
990
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600991 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu42b97b82014-12-13 15:28:20 +0800992 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600993 vk_testing::Image img;
994 vk_testing::Buffer buf;
Tony Barbour0c823b12015-05-21 13:26:05 -0600995 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 VkMemoryPropertyFlags image_reqs =
997 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu42b97b82014-12-13 15:28:20 +0800998
Tony Barbour0c823b12015-05-21 13:26:05 -0600999 img.init(dev_, img_info, image_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001000 fill_src(img, checker);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001001
Cody Northrop7fb43862015-06-22 14:56:14 -06001002 buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001003
1004 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001005 vkCmdCopyImageToBuffer(cmd_.handle(),
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001006 img.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +08001007 buf.handle(),
Chia-I Wu42b97b82014-12-13 15:28:20 +08001008 checker.regions().size(), &checker.regions()[0]);
1009 cmd_.end();
1010
1011 submit_and_done();
1012
1013 checker.check(buf);
1014 }
1015
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001016 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001017 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001018 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001019 test_copy_image_to_memory(img_info, checker);
1020 }
1021
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001022 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001023 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001024 vk_testing::ImageChecker checker(img_info);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001025 test_copy_image_to_memory(img_info, checker);
1026 }
1027};
1028
Tony Barbour6918cd52015-04-09 12:58:51 -06001029TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001030{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001031 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu42b97b82014-12-13 15:28:20 +08001032 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001033
1034 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001035 if (it->format == VK_FORMAT_UNDEFINED ||
1036 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1037 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001038 continue;
1039
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001040 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001041 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001042 img_info.format = it->format;
1043 img_info.extent.width = 64;
1044 img_info.extent.height = 64;
1045 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001046 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1047 VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy
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(),
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 src.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1107 dst.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
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;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001135
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001136 VkImageCopy copy = {};
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06001137 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001138 copy.dstSubresource = copy.srcSubresource;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001139 copy.extent = img_info.extent;
1140
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001141 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001142 }
1143}
1144
Tony Barbour6918cd52015-04-09 12:58:51 -06001145class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001146protected:
Chris Forbesf0796e12015-06-24 14:34:53 +12001147 VkCmdClearColorImageTest() {}
Chia-I Wu5bc27862014-12-22 13:19:08 +08001148
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001149 virtual void SetUp()
1150 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001151 VkCmdBlitTest::SetUp();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001152
Courtney Goeltzenleuchtercda30342015-09-10 16:25:49 -06001153 init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001154
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001155 ASSERT_NE(true, test_formats_.empty());
1156 }
1157
Chia-I Wu5bc27862014-12-22 13:19:08 +08001158 union Color {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001159 float color[4];
1160 uint32_t raw[4];
Chia-I Wu5bc27862014-12-22 13:19:08 +08001161 };
1162
Chris Forbesf0796e12015-06-24 14:34:53 +12001163 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001164 {
1165 std::vector<uint8_t> raw;
1166
1167 // TODO support all formats
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001168 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001169 case VK_FORMAT_R8G8B8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001170 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1171 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1172 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1173 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001174 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001175 case VK_FORMAT_B8G8R8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001176 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1177 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1178 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1179 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001180 break;
1181 default:
1182 break;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001183 }
1184
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001185 return raw;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001186 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001187
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001188 void test_clear_color_image(const VkImageCreateInfo &img_info,
Chris Forbesf0796e12015-06-24 14:34:53 +12001189 const VkClearColorValue &clear_color,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001190 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wud7414b02014-10-21 11:06:26 +08001191 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001192 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001193 VkMemoryPropertyFlags image_reqs =
1194 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001195
Tony Barbour0c823b12015-05-21 13:26:05 -06001196 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001197 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001198 VK_ACCESS_HOST_WRITE_BIT |
1199 VK_ACCESS_SHADER_WRITE_BIT |
1200 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1201 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1202 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001203 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001204 VK_ACCESS_HOST_READ_BIT |
1205 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1206 VK_ACCESS_INDEX_READ_BIT |
1207 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1208 VK_ACCESS_UNIFORM_READ_BIT |
1209 VK_ACCESS_SHADER_READ_BIT |
1210 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1211 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1212 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +08001213
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001214 std::vector<VkImageMemoryBarrier> to_clear;
1215 std::vector<VkImageMemoryBarrier *> p_to_clear;
1216 std::vector<VkImageMemoryBarrier> to_xfer;
1217 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wud7414b02014-10-21 11:06:26 +08001218
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001219 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001220 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001221 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001222 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001223 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001224 *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001225 p_to_clear.push_back(&to_clear.back());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001226 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001227 VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001228 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001229 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wud7414b02014-10-21 11:06:26 +08001230 }
1231
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001232 cmd_.begin();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001233
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001234 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1235 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Chia-I Wu53534662015-10-26 17:08:33 +08001236 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001237
Chia-I Wube2b9172015-07-03 11:49:42 +08001238 vkCmdClearColorImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001239 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001240 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001241
Chia-I Wu53534662015-10-26 17:08:33 +08001242 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001243
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001244 cmd_.end();
1245
1246 submit_and_done();
1247
1248 // cannot verify
1249 if (!img.transparent() && !img.copyable())
1250 return;
1251
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001252 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001253
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -06001254 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001255 if (solid_pattern.empty())
1256 return;
1257
1258 checker.set_solid_pattern(solid_pattern);
1259 check_dst(img, checker);
1260 }
Chia-I Wu5bc27862014-12-22 13:19:08 +08001261
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001262 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001263 const float color[4],
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001264 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu5bc27862014-12-22 13:19:08 +08001265 {
Chris Forbesf0796e12015-06-24 14:34:53 +12001266 VkClearColorValue c = {};
Cody Northrop85789d52015-08-25 15:26:38 -06001267 memcpy(c.float32, color, sizeof(c.float32));
Chia-I Wu5bc27862014-12-22 13:19:08 +08001268 test_clear_color_image(img_info, c, ranges);
1269 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001270};
1271
Tony Barbour6918cd52015-04-09 12:58:51 -06001272TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001273{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001274 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001275 it != test_formats_.end(); it++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001276 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barboura36f5282015-06-05 12:53:55 -06001277 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001278
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001279 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001280
Tony Barboura36f5282015-06-05 12:53:55 -06001281 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1282 continue;
1283
1284 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1285 continue;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001286
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001287 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001288 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001289 img_info.format = it->format;
1290 img_info.extent.width = 64;
1291 img_info.extent.height = 64;
1292 img_info.tiling = it->tiling;
Tony Barboure65788f2015-07-21 17:01:42 -06001293 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001295
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001296 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001297 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001298 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001299
1300 test_clear_color_image(img_info, color, ranges);
Chia-I Wud7414b02014-10-21 11:06:26 +08001301 }
1302}
1303
Tony Barbour6918cd52015-04-09 12:58:51 -06001304class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001305protected:
1306 virtual void SetUp()
1307 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001308 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001309 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001310 ASSERT_NE(true, test_formats_.empty());
1311 }
1312
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001313 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001314 {
1315 std::vector<uint8_t> raw;
1316
1317 // depth
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001318 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001319 case VK_FORMAT_D16_UNORM:
1320 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001321 {
Tony Barbour048f2812015-06-09 13:40:53 -06001322 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001323 raw.push_back(unorm & 0xff);
1324 raw.push_back(unorm >> 8);
1325 }
1326 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001327 case VK_FORMAT_D32_SFLOAT:
1328 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001329 {
1330 const union {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001331 float depth;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001332 uint32_t u32;
1333 } u = { depth };
1334
1335 raw.push_back((u.u32 ) & 0xff);
1336 raw.push_back((u.u32 >> 8) & 0xff);
1337 raw.push_back((u.u32 >> 16) & 0xff);
1338 raw.push_back((u.u32 >> 24) & 0xff);
1339 }
1340 break;
1341 default:
1342 break;
1343 }
1344
1345 // stencil
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001346 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001347 case VK_FORMAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001348 raw.push_back(stencil);
1349 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001350 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001351 raw.push_back(stencil);
1352 raw.push_back(0);
1353 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001354 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001355 raw.push_back(stencil);
1356 raw.push_back(0);
1357 raw.push_back(0);
1358 raw.push_back(0);
1359 break;
1360 default:
1361 break;
1362 }
1363
1364 return raw;
1365 }
1366
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001367 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001368 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001369 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001370 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001371 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001372 VkMemoryPropertyFlags image_reqs =
1373 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001374
Tony Barbour0c823b12015-05-21 13:26:05 -06001375 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001376 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001377 VK_ACCESS_HOST_WRITE_BIT |
1378 VK_ACCESS_SHADER_WRITE_BIT |
1379 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1380 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1381 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001382 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001383 VK_ACCESS_HOST_READ_BIT |
1384 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1385 VK_ACCESS_INDEX_READ_BIT |
1386 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1387 VK_ACCESS_UNIFORM_READ_BIT |
1388 VK_ACCESS_SHADER_READ_BIT |
1389 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1390 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1391 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001392
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001393 std::vector<VkImageMemoryBarrier> to_clear;
1394 std::vector<VkImageMemoryBarrier *> p_to_clear;
1395 std::vector<VkImageMemoryBarrier> to_xfer;
1396 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001397 unsigned int i = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001398
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001399 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001400 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001401 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001402 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001403 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001404 *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001405
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001406 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001407 VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001408 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001409 }
1410 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
1411 it != ranges.end(); it++) {
1412 p_to_clear.push_back(to_clear.data() + i);
1413 p_to_xfer.push_back(to_xfer.data() + i);
1414 i++;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001415 }
1416
1417 cmd_.begin();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001418
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001419 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1420 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Chia-I Wu53534662015-10-26 17:08:33 +08001421 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 +00001422
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001423 VkClearDepthStencilValue clear_value = {
1424 depth,
1425 stencil
1426 };
Chia-I Wube2b9172015-07-03 11:49:42 +08001427 vkCmdClearDepthStencilImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001428 img.handle(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001429 &clear_value,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001430 ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001431
Chia-I Wu53534662015-10-26 17:08:33 +08001432 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 +00001433
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001434 cmd_.end();
1435
1436 submit_and_done();
1437
1438 // cannot verify
1439 if (!img.transparent() && !img.copyable())
1440 return;
1441
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001442 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001443
1444 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1445 check_dst(img, checker);
1446 }
1447};
1448
Tony Barbour6918cd52015-04-09 12:58:51 -06001449TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001450{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001451 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001452 it != test_formats_.end(); it++) {
Tony Barboura36f5282015-06-05 12:53:55 -06001453 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001454
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001455 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001456
Tony Barboura36f5282015-06-05 12:53:55 -06001457 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1458 continue;
1459
1460 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1461 continue;
1462
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001463 // known driver issues
Tony Barbourd1c35722015-04-16 15:59:00 -06001464 if (it->format == VK_FORMAT_S8_UINT ||
Courtney Goeltzenleuchter286fb5f2015-09-10 17:17:43 -06001465 it->format == VK_FORMAT_D24_UNORM_X8 ||
Tony Barbourd1c35722015-04-16 15:59:00 -06001466 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1467 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001468 continue;
1469
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001470 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001471 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001472 img_info.format = it->format;
1473 img_info.extent.width = 64;
1474 img_info.extent.height = 64;
1475 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -06001476 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001477
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001478 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001479 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001480 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
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) {
1485 const VkImageSubresourceRange range2 =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001486 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_STENCIL_BIT);
Tony Barbour048f2812015-06-09 13:40:53 -06001487 ranges.push_back(range2);
1488 }
1489
1490
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001491 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1492 }
1493}
1494
1495}; // namespace
1496
Chia-I Wud7414b02014-10-21 11:06:26 +08001497int main(int argc, char **argv)
1498{
Chia-I Wud7414b02014-10-21 11:06:26 +08001499 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wud7414b02014-10-21 11:06:26 +08001500
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001501 vk_testing::set_error_callback(test_error_callback);
Chia-I Wua9a506a2014-12-27 22:04:00 +08001502
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001503 environment = new vk_testing::Environment();
Chia-I Wud7414b02014-10-21 11:06:26 +08001504
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001505 if (!environment->parse_args(argc, argv))
1506 return -1;
Chia-I Wud7414b02014-10-21 11:06:26 +08001507
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001508 ::testing::AddGlobalTestEnvironment(environment);
1509
1510 return RUN_ALL_TESTS();
Chia-I Wud7414b02014-10-21 11:06:26 +08001511}