blob: 612429f440aebeb068845b59b8b43259af2144d1 [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(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700873 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
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(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700896 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
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(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700936 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
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;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700977 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800978
979 test_copy_memory_to_image(img_info);
980 }
Chia-I Wud6479012014-11-22 15:09:42 +0800981}
982
Tony Barbour6918cd52015-04-09 12:58:51 -0600983class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu42b97b82014-12-13 15:28:20 +0800984protected:
985 virtual void SetUp()
986 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600987 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600988 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu42b97b82014-12-13 15:28:20 +0800989 ASSERT_NE(true, test_formats_.empty());
990 }
991
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600992 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu42b97b82014-12-13 15:28:20 +0800993 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600994 vk_testing::Image img;
995 vk_testing::Buffer buf;
Tony Barbour0c823b12015-05-21 13:26:05 -0600996 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
997 VkMemoryPropertyFlags image_reqs =
998 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu42b97b82014-12-13 15:28:20 +0800999
Tony Barbour0c823b12015-05-21 13:26:05 -06001000 img.init(dev_, img_info, image_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001001 fill_src(img, checker);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001002
Cody Northrop7fb43862015-06-22 14:56:14 -06001003 buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001004
1005 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001006 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001007 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +08001008 buf.handle(),
Chia-I Wu42b97b82014-12-13 15:28:20 +08001009 checker.regions().size(), &checker.regions()[0]);
1010 cmd_.end();
1011
1012 submit_and_done();
1013
1014 checker.check(buf);
1015 }
1016
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001017 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001018 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001019 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001020 test_copy_image_to_memory(img_info, checker);
1021 }
1022
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001023 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001024 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001025 vk_testing::ImageChecker checker(img_info);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001026 test_copy_image_to_memory(img_info, checker);
1027 }
1028};
1029
Tony Barbour6918cd52015-04-09 12:58:51 -06001030TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001031{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001032 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu42b97b82014-12-13 15:28:20 +08001033 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001034
1035 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001036 if (it->format == VK_FORMAT_UNDEFINED ||
1037 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1038 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001039 continue;
1040
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001041 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001042 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001043 img_info.format = it->format;
1044 img_info.extent.width = 64;
1045 img_info.extent.height = 64;
1046 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001047 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1048 VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001049 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001050
1051 test_copy_image_to_memory(img_info);
1052 }
1053}
1054
Tony Barbour6918cd52015-04-09 12:58:51 -06001055class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001056protected:
1057 virtual void SetUp()
1058 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001059 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001060 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001061 ASSERT_NE(true, test_formats_.empty());
Chia-I Wu89078aa2014-11-22 16:24:41 +08001062 }
1063
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001064 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1065 const std::vector<VkImageCopy> &copies)
Chia-I Wu89078aa2014-11-22 16:24:41 +08001066 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001067 // convert VkImageCopy to two sets of VkBufferImageCopy
1068 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbourd1c35722015-04-16 15:59:00 -06001069 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001070 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1071 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wu89078aa2014-11-22 16:24:41 +08001072
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001073 src_region.bufferOffset = src_offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001074 src_region.imageSubresource = it->srcSubresource;
1075 src_region.imageOffset = it->srcOffset;
1076 src_region.imageExtent = it->extent;
1077 src_regions.push_back(src_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001078
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001079 dst_region.bufferOffset = src_offset;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001080 dst_region.imageSubresource = it->dstSubresource;
1081 dst_region.imageOffset = it->dstOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001082 dst_region.imageExtent = it->extent;
1083 dst_regions.push_back(dst_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001084
Tony Barbourd1c35722015-04-16 15:59:00 -06001085 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001086 src_offset += vk_testing::get_format_size(src_info.format) * size;
1087 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001088 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001089
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001090 vk_testing::ImageChecker src_checker(src_info, src_regions);
1091 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour0c823b12015-05-21 13:26:05 -06001092 VkMemoryPropertyFlags src_reqs =
1093 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1094 VkMemoryPropertyFlags dst_reqs =
1095 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1096
1097
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001098
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001099 vk_testing::Image src;
Tony Barbour0c823b12015-05-21 13:26:05 -06001100 src.init(dev_, src_info, src_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001101 fill_src(src, src_checker);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001102
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001103 vk_testing::Image dst;
Tony Barbour0c823b12015-05-21 13:26:05 -06001104 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001105
1106 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001107 vkCmdCopyImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001108 src.handle(), VK_IMAGE_LAYOUT_GENERAL,
1109 dst.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001110 copies.size(), &copies[0]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001111 cmd_.end();
1112
1113 submit_and_done();
1114
1115 check_dst(dst, dst_checker);
1116 }
1117};
1118
Tony Barbour6918cd52015-04-09 12:58:51 -06001119TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001120{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001121 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001122 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001123
1124 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001125 if (it->format == VK_FORMAT_UNDEFINED ||
1126 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1127 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001128 continue;
1129
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001130 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001131 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001132 img_info.format = it->format;
1133 img_info.extent.width = 64;
1134 img_info.extent.height = 64;
1135 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001136 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001137 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001138
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001139 VkImageCopy copy = {};
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06001140 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001141 copy.dstSubresource = copy.srcSubresource;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001142 copy.extent = img_info.extent;
1143
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001144 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001145 }
1146}
1147
Tony Barbour6918cd52015-04-09 12:58:51 -06001148class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001149protected:
Chris Forbesf0796e12015-06-24 14:34:53 +12001150 VkCmdClearColorImageTest() {}
Chia-I Wu5bc27862014-12-22 13:19:08 +08001151
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001152 virtual void SetUp()
1153 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001154 VkCmdBlitTest::SetUp();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001155
Courtney Goeltzenleuchtercda30342015-09-10 16:25:49 -06001156 init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001157
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001158 ASSERT_NE(true, test_formats_.empty());
1159 }
1160
Chia-I Wu5bc27862014-12-22 13:19:08 +08001161 union Color {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001162 float color[4];
1163 uint32_t raw[4];
Chia-I Wu5bc27862014-12-22 13:19:08 +08001164 };
1165
Chris Forbesf0796e12015-06-24 14:34:53 +12001166 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001167 {
1168 std::vector<uint8_t> raw;
1169
1170 // TODO support all formats
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001171 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001172 case VK_FORMAT_R8G8B8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001173 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1174 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1175 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1176 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001177 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001178 case VK_FORMAT_B8G8R8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001179 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1180 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1181 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1182 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001183 break;
1184 default:
1185 break;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001186 }
1187
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001188 return raw;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001189 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001190
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001191 void test_clear_color_image(const VkImageCreateInfo &img_info,
Chris Forbesf0796e12015-06-24 14:34:53 +12001192 const VkClearColorValue &clear_color,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001193 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wud7414b02014-10-21 11:06:26 +08001194 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001195 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001196 VkMemoryPropertyFlags image_reqs =
1197 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001198
Tony Barbour0c823b12015-05-21 13:26:05 -06001199 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001200 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001201 VK_ACCESS_HOST_WRITE_BIT |
1202 VK_ACCESS_SHADER_WRITE_BIT |
1203 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1204 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1205 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001206 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001207 VK_ACCESS_HOST_READ_BIT |
1208 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1209 VK_ACCESS_INDEX_READ_BIT |
1210 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1211 VK_ACCESS_UNIFORM_READ_BIT |
1212 VK_ACCESS_SHADER_READ_BIT |
1213 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1214 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1215 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +08001216
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001217 std::vector<VkImageMemoryBarrier> to_clear;
1218 std::vector<VkImageMemoryBarrier *> p_to_clear;
1219 std::vector<VkImageMemoryBarrier> to_xfer;
1220 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wud7414b02014-10-21 11:06:26 +08001221
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001222 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001223 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001224 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001225 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001226 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001227 *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001228 p_to_clear.push_back(&to_clear.back());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001229 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001230 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001231 VK_IMAGE_LAYOUT_GENERAL, *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001232 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wud7414b02014-10-21 11:06:26 +08001233 }
1234
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001235 cmd_.begin();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001236
Chia-I Wu89d0f942015-10-31 00:31:16 +08001237 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1238 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001239 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001240
Chia-I Wube2b9172015-07-03 11:49:42 +08001241 vkCmdClearColorImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001242 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001243 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001244
Chia-I Wu53534662015-10-26 17:08:33 +08001245 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001246
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001247 cmd_.end();
1248
1249 submit_and_done();
1250
1251 // cannot verify
1252 if (!img.transparent() && !img.copyable())
1253 return;
1254
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001255 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001256
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -06001257 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001258 if (solid_pattern.empty())
1259 return;
1260
1261 checker.set_solid_pattern(solid_pattern);
1262 check_dst(img, checker);
1263 }
Chia-I Wu5bc27862014-12-22 13:19:08 +08001264
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001265 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001266 const float color[4],
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001267 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu5bc27862014-12-22 13:19:08 +08001268 {
Chris Forbesf0796e12015-06-24 14:34:53 +12001269 VkClearColorValue c = {};
Cody Northrop85789d52015-08-25 15:26:38 -06001270 memcpy(c.float32, color, sizeof(c.float32));
Chia-I Wu5bc27862014-12-22 13:19:08 +08001271 test_clear_color_image(img_info, c, ranges);
1272 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001273};
1274
Tony Barbour6918cd52015-04-09 12:58:51 -06001275TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001276{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001277 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001278 it != test_formats_.end(); it++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001279 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barboura36f5282015-06-05 12:53:55 -06001280 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001281
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001282 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001283
Tony Barboura36f5282015-06-05 12:53:55 -06001284 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1285 continue;
1286
1287 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1288 continue;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001289
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001290 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001291 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001292 img_info.format = it->format;
1293 img_info.extent.width = 64;
1294 img_info.extent.height = 64;
1295 img_info.tiling = it->tiling;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001296 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barboure65788f2015-07-21 17:01:42 -06001297 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001298 VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001299
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001300 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001301 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001302 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001303
1304 test_clear_color_image(img_info, color, ranges);
Chia-I Wud7414b02014-10-21 11:06:26 +08001305 }
1306}
1307
Tony Barbour6918cd52015-04-09 12:58:51 -06001308class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001309protected:
1310 virtual void SetUp()
1311 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001312 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001313 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001314 ASSERT_NE(true, test_formats_.empty());
1315 }
1316
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001317 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001318 {
1319 std::vector<uint8_t> raw;
1320
1321 // depth
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001322 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001323 case VK_FORMAT_D16_UNORM:
1324 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001325 {
Tony Barbour048f2812015-06-09 13:40:53 -06001326 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001327 raw.push_back(unorm & 0xff);
1328 raw.push_back(unorm >> 8);
1329 }
1330 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001331 case VK_FORMAT_D32_SFLOAT:
1332 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001333 {
1334 const union {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001335 float depth;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001336 uint32_t u32;
1337 } u = { depth };
1338
1339 raw.push_back((u.u32 ) & 0xff);
1340 raw.push_back((u.u32 >> 8) & 0xff);
1341 raw.push_back((u.u32 >> 16) & 0xff);
1342 raw.push_back((u.u32 >> 24) & 0xff);
1343 }
1344 break;
1345 default:
1346 break;
1347 }
1348
1349 // stencil
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001350 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001351 case VK_FORMAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001352 raw.push_back(stencil);
1353 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001354 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001355 raw.push_back(stencil);
1356 raw.push_back(0);
1357 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001358 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001359 raw.push_back(stencil);
1360 raw.push_back(0);
1361 raw.push_back(0);
1362 raw.push_back(0);
1363 break;
1364 default:
1365 break;
1366 }
1367
1368 return raw;
1369 }
1370
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001371 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001372 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001373 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001374 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001375 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001376 VkMemoryPropertyFlags image_reqs =
1377 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001378
Tony Barbour0c823b12015-05-21 13:26:05 -06001379 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001380 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001381 VK_ACCESS_HOST_WRITE_BIT |
1382 VK_ACCESS_SHADER_WRITE_BIT |
1383 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1384 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1385 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001386 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001387 VK_ACCESS_HOST_READ_BIT |
1388 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1389 VK_ACCESS_INDEX_READ_BIT |
1390 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1391 VK_ACCESS_UNIFORM_READ_BIT |
1392 VK_ACCESS_SHADER_READ_BIT |
1393 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1394 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1395 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001396
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001397 std::vector<VkImageMemoryBarrier> to_clear;
1398 std::vector<VkImageMemoryBarrier *> p_to_clear;
1399 std::vector<VkImageMemoryBarrier> to_xfer;
1400 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001401 unsigned int i = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001402
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001403 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001404 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001405 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001406 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001407 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001408 *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001409
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001410 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001411 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001412 VK_IMAGE_LAYOUT_GENERAL, *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001413 }
1414 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
1415 it != ranges.end(); it++) {
1416 p_to_clear.push_back(to_clear.data() + i);
1417 p_to_xfer.push_back(to_xfer.data() + i);
1418 i++;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001419 }
1420
1421 cmd_.begin();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001422
Chia-I Wu89d0f942015-10-31 00:31:16 +08001423 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1424 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001425 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 +00001426
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001427 VkClearDepthStencilValue clear_value = {
1428 depth,
1429 stencil
1430 };
Chia-I Wube2b9172015-07-03 11:49:42 +08001431 vkCmdClearDepthStencilImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001432 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001433 &clear_value,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001434 ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001435
Chia-I Wu53534662015-10-26 17:08:33 +08001436 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 +00001437
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001438 cmd_.end();
1439
1440 submit_and_done();
1441
1442 // cannot verify
1443 if (!img.transparent() && !img.copyable())
1444 return;
1445
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001446 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001447
1448 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1449 check_dst(img, checker);
1450 }
1451};
1452
Tony Barbour6918cd52015-04-09 12:58:51 -06001453TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001454{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001455 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001456 it != test_formats_.end(); it++) {
Tony Barboura36f5282015-06-05 12:53:55 -06001457 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001458
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001459 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001460
Tony Barboura36f5282015-06-05 12:53:55 -06001461 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1462 continue;
1463
1464 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1465 continue;
1466
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001467 // known driver issues
Tony Barbourd1c35722015-04-16 15:59:00 -06001468 if (it->format == VK_FORMAT_S8_UINT ||
Courtney Goeltzenleuchter286fb5f2015-09-10 17:17:43 -06001469 it->format == VK_FORMAT_D24_UNORM_X8 ||
Tony Barbourd1c35722015-04-16 15:59:00 -06001470 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1471 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001472 continue;
1473
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001474 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001475 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001476 img_info.format = it->format;
1477 img_info.extent.width = 64;
1478 img_info.extent.height = 64;
1479 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -06001480 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001481 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1482 VkImageAspectFlags aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001483
Tony Barbour048f2812015-06-09 13:40:53 -06001484 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1485 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1486 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001487 aspect |= VK_IMAGE_ASPECT_STENCIL_BIT;
1488 }
Tony Barbour048f2812015-06-09 13:40:53 -06001489
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001490 const VkImageSubresourceRange range =
1491 vk_testing::Image::subresource_range(img_info, aspect);
1492 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Tony Barbour048f2812015-06-09 13:40:53 -06001493
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001494 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1495 }
1496}
1497
1498}; // namespace
1499
Chia-I Wud7414b02014-10-21 11:06:26 +08001500int main(int argc, char **argv)
1501{
Chia-I Wud7414b02014-10-21 11:06:26 +08001502 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wud7414b02014-10-21 11:06:26 +08001503
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001504 vk_testing::set_error_callback(test_error_callback);
Chia-I Wua9a506a2014-12-27 22:04:00 +08001505
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001506 environment = new vk_testing::Environment();
Chia-I Wud7414b02014-10-21 11:06:26 +08001507
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001508 if (!environment->parse_args(argc, argv))
1509 return -1;
Chia-I Wud7414b02014-10-21 11:06:26 +08001510
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001511 ::testing::AddGlobalTestEnvironment(environment);
1512
1513 return RUN_ALL_TESTS();
Chia-I Wud7414b02014-10-21 11:06:26 +08001514}