blob: 2a6dd0ef29215a9f645d3f2b659800442f756b94 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001// VK tests
Chia-I Wucb67c652014-10-21 11:06:26 +08002//
Chia-I Wu6170c9e2014-12-08 14:30:10 +08003// Copyright (C) 2014 LunarG, Inc.
Chia-I Wucb67c652014-10-21 11:06:26 +08004//
Chia-I Wu6170c9e2014-12-08 14:30:10 +08005// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
Chia-I Wucb67c652014-10-21 11:06:26 +080011//
Chia-I Wu6170c9e2014-12-08 14:30:10 +080012// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
Chia-I Wucb67c652014-10-21 11:06:26 +080014//
Chia-I Wu6170c9e2014-12-08 14:30:10 +080015// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
Chia-I Wucb67c652014-10-21 11:06:26 +080022
23// Blit (copy, clear, and resolve) tests
24
Chia-I Wu9dac52d2014-12-27 22:04:00 +080025#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060026#include "vktestbinding.h"
Tony Barbour34888cf2015-03-02 16:38:52 -070027#include "test_environment.h"
Chia-I Wucb67c652014-10-21 11:06:26 +080028
29#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031namespace vk_testing {
Chia-I Wucb67c652014-10-21 11:06:26 +080032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060033size_t get_format_size(VkFormat format);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080034
Chia-I Wu6170c9e2014-12-08 14:30:10 +080035class ImageChecker {
36public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060037 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080038 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060039 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
40 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080041
42 void set_solid_pattern(const std::vector<uint8_t> &solid);
43
Tony Barbour8205d902015-04-16 15:59:00 -060044 VkDeviceSize buffer_size() const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080045 bool fill(Buffer &buf) const { return walk(FILL, buf); }
46 bool fill(Image &img) const { return walk(FILL, img); }
47 bool check(Buffer &buf) const { return walk(CHECK, buf); }
48 bool check(Image &img) const { return walk(CHECK, img); }
49
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060050 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu6170c9e2014-12-08 14:30:10 +080051
52 static void hash_salt_generate() { hash_salt_++; }
53
54private:
55 enum Action {
56 FILL,
57 CHECK,
58 };
59
60 enum Pattern {
61 HASH,
62 SOLID,
63 };
64
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060065 size_t buffer_cpp() const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060066 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080067
68 bool walk(Action action, Buffer &buf) const;
69 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060070 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080071
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060072 std::vector<uint8_t> pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080073
74 static uint32_t hash_salt_;
75
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060076 VkImageCreateInfo info_;
77 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080078
79 Pattern pattern_;
80 std::vector<uint8_t> pattern_solid_;
81};
82
Chia-I Wucb67c652014-10-21 11:06:26 +080083
Chia-I Wu6170c9e2014-12-08 14:30:10 +080084uint32_t ImageChecker::hash_salt_;
85
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060086ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080087 : info_(info), regions_(), pattern_(HASH)
88{
89 // create a region for every mip level in array slice 0
Tony Barbour8205d902015-04-16 15:59:00 -060090 VkDeviceSize offset = 0;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060091 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060092 VkBufferImageCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +080093
Chia-I Wu714df452015-01-01 07:55:04 +080094 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080095 region.imageSubresource.mipLevel = lv;
96 region.imageSubresource.arraySlice = 0;
Chia-I Wu9dac52d2014-12-27 22:04:00 +080097 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080098
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_BIT) {
Tony Barbour8205d902015-04-16 15:59:00 -0600100 if (info_.format != VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101 region.imageSubresource.aspect = VK_IMAGE_ASPECT_DEPTH;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800102 regions_.push_back(region);
103 }
104
Tony Barbour8205d902015-04-16 15:59:00 -0600105 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
106 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
107 info_.format == VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 region.imageSubresource.aspect = VK_IMAGE_ASPECT_STENCIL;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800109 regions_.push_back(region);
110 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800111 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 region.imageSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800113 regions_.push_back(region);
114 }
115
116 offset += buffer_layout(region).size;
117 }
118
119 // arraySize should be limited in our tests. If this proves to be an
120 // issue, we can store only the regions for array slice 0 and be smart.
121 if (info_.arraySize > 1) {
Tony Barbour8205d902015-04-16 15:59:00 -0600122 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 const uint32_t slice_region_count = regions_.size();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800124
125 regions_.reserve(slice_region_count * info_.arraySize);
126
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600127 for (uint32_t slice = 1; slice < info_.arraySize; slice++) {
128 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600129 VkBufferImageCopy region = regions_[i];
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800130
Chia-I Wu714df452015-01-01 07:55:04 +0800131 region.bufferOffset += slice_pitch * slice;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800132 region.imageSubresource.arraySlice = slice;
133 regions_.push_back(region);
134 }
135 }
136 }
137}
138
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800140 : info_(info), regions_(), pattern_(HASH)
141{
Tony Barbour8205d902015-04-16 15:59:00 -0600142 VkDeviceSize offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800144 it != ranges.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600145 for (uint32_t lv = 0; lv < it->mipLevels; lv++) {
146 for (uint32_t slice = 0; slice < it->arraySize; slice++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600147 VkBufferImageCopy region = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800148 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800149 region.imageSubresource = Image::subresource(*it, lv, slice);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800150 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800151
152 regions_.push_back(region);
153
154 offset += buffer_layout(region).size;
155 }
156 }
157 }
158}
159
160void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
161{
162 pattern_ = SOLID;
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800163 pattern_solid_.clear();
164 pattern_solid_.reserve(buffer_cpp());
165 for (int i = 0; i < buffer_cpp(); i++)
166 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800167}
168
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600169size_t ImageChecker::buffer_cpp() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800170{
171 return get_format_size(info_.format);
172}
173
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600174VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800175{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600176 VkSubresourceLayout layout = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800177 layout.offset = region.bufferOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800178 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
179 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
180 layout.size = layout.depthPitch * region.imageExtent.depth;
181
182 return layout;
183}
184
Tony Barbour8205d902015-04-16 15:59:00 -0600185VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800186{
Tony Barbour8205d902015-04-16 15:59:00 -0600187 VkDeviceSize size = 0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800188
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600189 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800190 it != regions_.end(); it++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600191 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800192 if (size < layout.offset + layout.size)
193 size = layout.offset + layout.size;
194 }
195
196 return size;
197}
198
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600199bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
200 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800201{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600202 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
203 for (int32_t y = 0; y < region.imageExtent.height; y++) {
204 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800205 uint8_t *dst = static_cast<uint8_t *>(data);
206 dst += layout.offset + layout.depthPitch * z +
207 layout.rowPitch * y + buffer_cpp() * x;
208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600209 VkOffset3D offset = region.imageOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800210 offset.x += x;
211 offset.y += y;
212 offset.z += z;
213
214 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
215 pattern_hash(region.imageSubresource, offset) :
216 pattern_solid_;
217 assert(val.size() == buffer_cpp());
218
219 if (action == FILL) {
220 memcpy(dst, &val[0], val.size());
221 } else {
222 for (int i = 0; i < val.size(); i++) {
223 EXPECT_EQ(val[i], dst[i]) <<
224 "Offset is: (" << x << ", " << y << ", " << z << ")";
225 if (val[i] != dst[i])
226 return false;
227 }
228 }
229 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800230 }
231 }
232
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800233 return true;
Chia-I Wucb67c652014-10-21 11:06:26 +0800234}
235
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800236bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800237{
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800238 void *data = buf.map();
239 if (!data)
240 return false;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800243 for (it = regions_.begin(); it != regions_.end(); it++) {
244 if (!walk_region(action, *it, buffer_layout(*it), data))
245 break;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800246 }
247
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800248 buf.unmap();
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800249
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800250 return (it == regions_.end());
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800251}
252
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800253bool ImageChecker::walk(Action action, Image &img) const
254{
255 void *data = img.map();
256 if (!data)
257 return false;
258
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600259 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800260 for (it = regions_.begin(); it != regions_.end(); it++) {
261 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
262 break;
263 }
264
265 img.unmap();
266
267 return (it == regions_.end());
268}
269
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800271{
272#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
273#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
274 const unsigned char input[] = {
275 HASH_BYTES(hash_salt_),
276 HASH_BYTES(subres.mipLevel),
277 HASH_BYTES(subres.arraySlice),
278 HASH_BYTES(offset.x),
279 HASH_BYTES(offset.y),
280 HASH_BYTES(offset.z),
281 };
282 unsigned long hash = 5381;
283
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600284 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800285 hash = ((hash << 5) + hash) + input[i];
286
287 const uint8_t output[4] = { HASH_BYTES(hash) };
288#undef HASH_BYTES
289#undef HASH_BYTE
290
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800291 std::vector<uint8_t> val;
292 val.reserve(buffer_cpp());
293 for (int i = 0; i < buffer_cpp(); i++)
294 val.push_back(output[i % 4]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800295
296 return val;
297}
298
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600299size_t get_format_size(VkFormat format)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800300{
301 static const struct format_info {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600302 size_t size;
303 uint32_t channel_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600304 } format_table[VK_NUM_FORMAT] = {
305 [VK_FORMAT_UNDEFINED] = { 0, 0 },
306 [VK_FORMAT_R4G4_UNORM] = { 1, 2 },
307 [VK_FORMAT_R4G4_USCALED] = { 1, 2 },
308 [VK_FORMAT_R4G4B4A4_UNORM] = { 2, 4 },
309 [VK_FORMAT_R4G4B4A4_USCALED] = { 2, 4 },
310 [VK_FORMAT_R5G6B5_UNORM] = { 2, 3 },
311 [VK_FORMAT_R5G6B5_USCALED] = { 2, 3 },
312 [VK_FORMAT_R5G5B5A1_UNORM] = { 2, 4 },
313 [VK_FORMAT_R5G5B5A1_USCALED] = { 2, 4 },
314 [VK_FORMAT_R8_UNORM] = { 1, 1 },
315 [VK_FORMAT_R8_SNORM] = { 1, 1 },
316 [VK_FORMAT_R8_USCALED] = { 1, 1 },
317 [VK_FORMAT_R8_SSCALED] = { 1, 1 },
318 [VK_FORMAT_R8_UINT] = { 1, 1 },
319 [VK_FORMAT_R8_SINT] = { 1, 1 },
320 [VK_FORMAT_R8_SRGB] = { 1, 1 },
321 [VK_FORMAT_R8G8_UNORM] = { 2, 2 },
322 [VK_FORMAT_R8G8_SNORM] = { 2, 2 },
323 [VK_FORMAT_R8G8_USCALED] = { 2, 2 },
324 [VK_FORMAT_R8G8_SSCALED] = { 2, 2 },
325 [VK_FORMAT_R8G8_UINT] = { 2, 2 },
326 [VK_FORMAT_R8G8_SINT] = { 2, 2 },
327 [VK_FORMAT_R8G8_SRGB] = { 2, 2 },
328 [VK_FORMAT_R8G8B8_UNORM] = { 3, 3 },
329 [VK_FORMAT_R8G8B8_SNORM] = { 3, 3 },
330 [VK_FORMAT_R8G8B8_USCALED] = { 3, 3 },
331 [VK_FORMAT_R8G8B8_SSCALED] = { 3, 3 },
332 [VK_FORMAT_R8G8B8_UINT] = { 3, 3 },
333 [VK_FORMAT_R8G8B8_SINT] = { 3, 3 },
334 [VK_FORMAT_R8G8B8_SRGB] = { 3, 3 },
335 [VK_FORMAT_R8G8B8A8_UNORM] = { 4, 4 },
336 [VK_FORMAT_R8G8B8A8_SNORM] = { 4, 4 },
337 [VK_FORMAT_R8G8B8A8_USCALED] = { 4, 4 },
338 [VK_FORMAT_R8G8B8A8_SSCALED] = { 4, 4 },
339 [VK_FORMAT_R8G8B8A8_UINT] = { 4, 4 },
340 [VK_FORMAT_R8G8B8A8_SINT] = { 4, 4 },
341 [VK_FORMAT_R8G8B8A8_SRGB] = { 4, 4 },
342 [VK_FORMAT_R10G10B10A2_UNORM] = { 4, 4 },
343 [VK_FORMAT_R10G10B10A2_SNORM] = { 4, 4 },
344 [VK_FORMAT_R10G10B10A2_USCALED] = { 4, 4 },
345 [VK_FORMAT_R10G10B10A2_SSCALED] = { 4, 4 },
346 [VK_FORMAT_R10G10B10A2_UINT] = { 4, 4 },
347 [VK_FORMAT_R10G10B10A2_SINT] = { 4, 4 },
348 [VK_FORMAT_R16_UNORM] = { 2, 1 },
349 [VK_FORMAT_R16_SNORM] = { 2, 1 },
350 [VK_FORMAT_R16_USCALED] = { 2, 1 },
351 [VK_FORMAT_R16_SSCALED] = { 2, 1 },
352 [VK_FORMAT_R16_UINT] = { 2, 1 },
353 [VK_FORMAT_R16_SINT] = { 2, 1 },
354 [VK_FORMAT_R16_SFLOAT] = { 2, 1 },
355 [VK_FORMAT_R16G16_UNORM] = { 4, 2 },
356 [VK_FORMAT_R16G16_SNORM] = { 4, 2 },
357 [VK_FORMAT_R16G16_USCALED] = { 4, 2 },
358 [VK_FORMAT_R16G16_SSCALED] = { 4, 2 },
359 [VK_FORMAT_R16G16_UINT] = { 4, 2 },
360 [VK_FORMAT_R16G16_SINT] = { 4, 2 },
361 [VK_FORMAT_R16G16_SFLOAT] = { 4, 2 },
362 [VK_FORMAT_R16G16B16_UNORM] = { 6, 3 },
363 [VK_FORMAT_R16G16B16_SNORM] = { 6, 3 },
364 [VK_FORMAT_R16G16B16_USCALED] = { 6, 3 },
365 [VK_FORMAT_R16G16B16_SSCALED] = { 6, 3 },
366 [VK_FORMAT_R16G16B16_UINT] = { 6, 3 },
367 [VK_FORMAT_R16G16B16_SINT] = { 6, 3 },
368 [VK_FORMAT_R16G16B16_SFLOAT] = { 6, 3 },
369 [VK_FORMAT_R16G16B16A16_UNORM] = { 8, 4 },
370 [VK_FORMAT_R16G16B16A16_SNORM] = { 8, 4 },
371 [VK_FORMAT_R16G16B16A16_USCALED] = { 8, 4 },
372 [VK_FORMAT_R16G16B16A16_SSCALED] = { 8, 4 },
373 [VK_FORMAT_R16G16B16A16_UINT] = { 8, 4 },
374 [VK_FORMAT_R16G16B16A16_SINT] = { 8, 4 },
375 [VK_FORMAT_R16G16B16A16_SFLOAT] = { 8, 4 },
376 [VK_FORMAT_R32_UINT] = { 4, 1 },
377 [VK_FORMAT_R32_SINT] = { 4, 1 },
378 [VK_FORMAT_R32_SFLOAT] = { 4, 1 },
379 [VK_FORMAT_R32G32_UINT] = { 8, 2 },
380 [VK_FORMAT_R32G32_SINT] = { 8, 2 },
381 [VK_FORMAT_R32G32_SFLOAT] = { 8, 2 },
382 [VK_FORMAT_R32G32B32_UINT] = { 12, 3 },
383 [VK_FORMAT_R32G32B32_SINT] = { 12, 3 },
384 [VK_FORMAT_R32G32B32_SFLOAT] = { 12, 3 },
385 [VK_FORMAT_R32G32B32A32_UINT] = { 16, 4 },
386 [VK_FORMAT_R32G32B32A32_SINT] = { 16, 4 },
387 [VK_FORMAT_R32G32B32A32_SFLOAT] = { 16, 4 },
388 [VK_FORMAT_R64_SFLOAT] = { 8, 1 },
389 [VK_FORMAT_R64G64_SFLOAT] = { 16, 2 },
390 [VK_FORMAT_R64G64B64_SFLOAT] = { 24, 3 },
391 [VK_FORMAT_R64G64B64A64_SFLOAT] = { 32, 4 },
392 [VK_FORMAT_R11G11B10_UFLOAT] = { 4, 3 },
393 [VK_FORMAT_R9G9B9E5_UFLOAT] = { 4, 3 },
394 [VK_FORMAT_D16_UNORM] = { 2, 1 },
395 [VK_FORMAT_D24_UNORM] = { 3, 1 },
396 [VK_FORMAT_D32_SFLOAT] = { 4, 1 },
397 [VK_FORMAT_S8_UINT] = { 1, 1 },
398 [VK_FORMAT_D16_UNORM_S8_UINT] = { 3, 2 },
399 [VK_FORMAT_D24_UNORM_S8_UINT] = { 4, 2 },
400 [VK_FORMAT_D32_SFLOAT_S8_UINT] = { 4, 2 },
401 [VK_FORMAT_BC1_RGB_UNORM] = { 8, 4 },
402 [VK_FORMAT_BC1_RGB_SRGB] = { 8, 4 },
403 [VK_FORMAT_BC1_RGBA_UNORM] = { 8, 4 },
404 [VK_FORMAT_BC1_RGBA_SRGB] = { 8, 4 },
405 [VK_FORMAT_BC2_UNORM] = { 16, 4 },
406 [VK_FORMAT_BC2_SRGB] = { 16, 4 },
407 [VK_FORMAT_BC3_UNORM] = { 16, 4 },
408 [VK_FORMAT_BC3_SRGB] = { 16, 4 },
409 [VK_FORMAT_BC4_UNORM] = { 8, 4 },
410 [VK_FORMAT_BC4_SNORM] = { 8, 4 },
411 [VK_FORMAT_BC5_UNORM] = { 16, 4 },
412 [VK_FORMAT_BC5_SNORM] = { 16, 4 },
413 [VK_FORMAT_BC6H_UFLOAT] = { 16, 4 },
414 [VK_FORMAT_BC6H_SFLOAT] = { 16, 4 },
415 [VK_FORMAT_BC7_UNORM] = { 16, 4 },
416 [VK_FORMAT_BC7_SRGB] = { 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700417 // TODO: Initialize remaining compressed formats.
Tony Barbour8205d902015-04-16 15:59:00 -0600418 [VK_FORMAT_ETC2_R8G8B8_UNORM] = { 0, 0 },
419 [VK_FORMAT_ETC2_R8G8B8_SRGB] = { 0, 0 },
420 [VK_FORMAT_ETC2_R8G8B8A1_UNORM] = { 0, 0 },
421 [VK_FORMAT_ETC2_R8G8B8A1_SRGB] = { 0, 0 },
422 [VK_FORMAT_ETC2_R8G8B8A8_UNORM] = { 0, 0 },
423 [VK_FORMAT_ETC2_R8G8B8A8_SRGB] = { 0, 0 },
424 [VK_FORMAT_EAC_R11_UNORM] = { 0, 0 },
425 [VK_FORMAT_EAC_R11_SNORM] = { 0, 0 },
426 [VK_FORMAT_EAC_R11G11_UNORM] = { 0, 0 },
427 [VK_FORMAT_EAC_R11G11_SNORM] = { 0, 0 },
428 [VK_FORMAT_ASTC_4x4_UNORM] = { 0, 0 },
429 [VK_FORMAT_ASTC_4x4_SRGB] = { 0, 0 },
430 [VK_FORMAT_ASTC_5x4_UNORM] = { 0, 0 },
431 [VK_FORMAT_ASTC_5x4_SRGB] = { 0, 0 },
432 [VK_FORMAT_ASTC_5x5_UNORM] = { 0, 0 },
433 [VK_FORMAT_ASTC_5x5_SRGB] = { 0, 0 },
434 [VK_FORMAT_ASTC_6x5_UNORM] = { 0, 0 },
435 [VK_FORMAT_ASTC_6x5_SRGB] = { 0, 0 },
436 [VK_FORMAT_ASTC_6x6_UNORM] = { 0, 0 },
437 [VK_FORMAT_ASTC_6x6_SRGB] = { 0, 0 },
438 [VK_FORMAT_ASTC_8x5_UNORM] = { 0, 0 },
439 [VK_FORMAT_ASTC_8x5_SRGB] = { 0, 0 },
440 [VK_FORMAT_ASTC_8x6_UNORM] = { 0, 0 },
441 [VK_FORMAT_ASTC_8x6_SRGB] = { 0, 0 },
442 [VK_FORMAT_ASTC_8x8_UNORM] = { 0, 0 },
443 [VK_FORMAT_ASTC_8x8_SRGB] = { 0, 0 },
444 [VK_FORMAT_ASTC_10x5_UNORM] = { 0, 0 },
445 [VK_FORMAT_ASTC_10x5_SRGB] = { 0, 0 },
446 [VK_FORMAT_ASTC_10x6_UNORM] = { 0, 0 },
447 [VK_FORMAT_ASTC_10x6_SRGB] = { 0, 0 },
448 [VK_FORMAT_ASTC_10x8_UNORM] = { 0, 0 },
449 [VK_FORMAT_ASTC_10x8_SRGB] = { 0, 0 },
450 [VK_FORMAT_ASTC_10x10_UNORM] = { 0, 0 },
451 [VK_FORMAT_ASTC_10x10_SRGB] = { 0, 0 },
452 [VK_FORMAT_ASTC_12x10_UNORM] = { 0, 0 },
453 [VK_FORMAT_ASTC_12x10_SRGB] = { 0, 0 },
454 [VK_FORMAT_ASTC_12x12_UNORM] = { 0, 0 },
455 [VK_FORMAT_ASTC_12x12_SRGB] = { 0, 0 },
456 [VK_FORMAT_B4G4R4A4_UNORM] = { 2, 4 },
457 [VK_FORMAT_B5G5R5A1_UNORM] = { 2, 4 },
458 [VK_FORMAT_B5G6R5_UNORM] = { 2, 3 },
459 [VK_FORMAT_B5G6R5_USCALED] = { 2, 3 },
460 [VK_FORMAT_B8G8R8_UNORM] = { 3, 3 },
461 [VK_FORMAT_B8G8R8_SNORM] = { 3, 3 },
462 [VK_FORMAT_B8G8R8_USCALED] = { 3, 3 },
463 [VK_FORMAT_B8G8R8_SSCALED] = { 3, 3 },
464 [VK_FORMAT_B8G8R8_UINT] = { 3, 3 },
465 [VK_FORMAT_B8G8R8_SINT] = { 3, 3 },
466 [VK_FORMAT_B8G8R8_SRGB] = { 3, 3 },
467 [VK_FORMAT_B8G8R8A8_UNORM] = { 4, 4 },
468 [VK_FORMAT_B8G8R8A8_SNORM] = { 4, 4 },
469 [VK_FORMAT_B8G8R8A8_USCALED] = { 4, 4 },
470 [VK_FORMAT_B8G8R8A8_SSCALED] = { 4, 4 },
471 [VK_FORMAT_B8G8R8A8_UINT] = { 4, 4 },
472 [VK_FORMAT_B8G8R8A8_SINT] = { 4, 4 },
473 [VK_FORMAT_B8G8R8A8_SRGB] = { 4, 4 },
474 [VK_FORMAT_B10G10R10A2_UNORM] = { 4, 4 },
475 [VK_FORMAT_B10G10R10A2_SNORM] = { 4, 4 },
476 [VK_FORMAT_B10G10R10A2_USCALED] = { 4, 4 },
477 [VK_FORMAT_B10G10R10A2_SSCALED] = { 4, 4 },
478 [VK_FORMAT_B10G10R10A2_UINT] = { 4, 4 },
479 [VK_FORMAT_B10G10R10A2_SINT] = { 4, 4 },
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800480 };
481
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700482 return format_table[format].size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800483}
484
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800486{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600487 const VkExtent3D ext = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800488 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
489 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
490 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
491 };
492
493 return ext;
494}
495
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496}; // namespace vk_testing
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800497
498namespace {
499
500#define DO(action) ASSERT_EQ(true, action);
501
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600502static vk_testing::Environment *environment;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800503
Tony Barbour01999182015-04-09 12:58:51 -0600504class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800505protected:
Tony Barbour01999182015-04-09 12:58:51 -0600506 VkCmdBlitTest() :
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800507 dev_(environment->default_device()),
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800508 queue_(*dev_.graphics_queues()[0]),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600509 cmd_(dev_, vk_testing::CmdBuffer::create_info(dev_.graphics_queue_node_index_))
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800510 {
511 // make sure every test uses a different pattern
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600512 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800513 }
514
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800515 bool submit_and_done()
516 {
Mark Lobodzinski2c01d182015-04-17 11:44:25 -0500517 queue_.add_mem_references(mem_refs_);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600518 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800519 queue_.wait();
520 mem_refs_.clear();
521 return true;
522 }
523
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524 void add_memory_ref(const vk_testing::Object &obj)
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800525 {
Tony Barbour8205d902015-04-16 15:59:00 -0600526 const std::vector<VkDeviceMemory> mems = obj.memories();
527 for (std::vector<VkDeviceMemory>::const_iterator it = mems.begin(); it != mems.end(); it++) {
528 std::vector<VkDeviceMemory>::iterator ref;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800529 for (ref = mem_refs_.begin(); ref != mem_refs_.end(); ref++) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600530 if (*ref == *it)
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800531 break;
532 }
533
534 if (ref == mem_refs_.end()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600535 mem_refs_.push_back(*it);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800536 }
537 }
538 }
539
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 vk_testing::Device &dev_;
541 vk_testing::Queue &queue_;
542 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800543
Tony Barbour8205d902015-04-16 15:59:00 -0600544 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800545};
546
Tony Barbour01999182015-04-09 12:58:51 -0600547typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800548
Tony Barbour01999182015-04-09 12:58:51 -0600549TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800550{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551 vk_testing::Buffer buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800552
553 buf.init(dev_, 20);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600554 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800555
556 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600557 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
558 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800559 cmd_.end();
560
561 submit_and_done();
562
563 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
564 EXPECT_EQ(0x11111111, data[0]);
565 EXPECT_EQ(0x22222222, data[1]);
566 EXPECT_EQ(0x22222222, data[2]);
567 EXPECT_EQ(0x22222222, data[3]);
568 EXPECT_EQ(0x22222222, data[4]);
569 buf.unmap();
570}
571
Tony Barbour01999182015-04-09 12:58:51 -0600572TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800573{
Tony Barbour8205d902015-04-16 15:59:00 -0600574 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600575 vk_testing::Buffer buf;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800576
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800577 buf.init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600578 add_memory_ref(buf);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800579
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800580 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
582 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800583 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800584
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800585 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800586
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800587 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600588 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800589 for (offset = 0; offset < size / 2; offset += 4)
590 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
591 for (; offset < size; offset += 4)
592 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
593 buf.unmap();
594}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800595
Tony Barbour01999182015-04-09 12:58:51 -0600596TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800597{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 vk_testing::Buffer buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800599
600 buf.init(dev_, 64);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600601 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800602
603 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600604 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
605 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800606 cmd_.end();
607
608 submit_and_done();
609
610 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600611 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800612 for (offset = 0; offset < 32; offset += 4)
613 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
614 for (; offset < 64; offset += 4)
615 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
616 buf.unmap();
617}
618
Tony Barbour01999182015-04-09 12:58:51 -0600619TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800620{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600622 VkDeviceSize size = 4;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800623
624 cmd_.begin();
625 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
626 bufs[i].init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600627 add_memory_ref(bufs[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600628 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800629 size <<= 1;
630 }
631 cmd_.end();
632
633 submit_and_done();
634
635 size = 4;
636 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
637 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600638 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800639 for (offset = 0; offset < size; offset += 4)
640 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
641 "Offset is: " << offset;
642 bufs[i].unmap();
643
644 size <<= 1;
645 }
646}
647
Tony Barbour01999182015-04-09 12:58:51 -0600648typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800649
Tony Barbour01999182015-04-09 12:58:51 -0600650TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800651{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600652 vk_testing::Buffer src, dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800653
654 src.init(dev_, 4);
655 uint32_t *data = static_cast<uint32_t *>(src.map());
656 data[0] = 0x11111111;
657 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600658 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800659
660 dst.init(dev_, 4);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600661 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800662
663 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600664 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800665 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600666 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800667 cmd_.end();
668
669 submit_and_done();
670
671 data = static_cast<uint32_t *>(dst.map());
672 EXPECT_EQ(0x11111111, data[0]);
673 dst.unmap();
674}
675
Tony Barbour01999182015-04-09 12:58:51 -0600676TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800677{
Tony Barbour8205d902015-04-16 15:59:00 -0600678 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 vk_testing::Buffer src, dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800680
681 src.init(dev_, size);
682 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600683 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800684 for (offset = 0; offset < size; offset += 4)
685 data[offset / 4] = offset;
686 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600687 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800688
689 dst.init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600690 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800691
692 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600693 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800694 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600695 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800696 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800697
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800698 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800699
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800700 data = static_cast<uint32_t *>(dst.map());
701 for (offset = 0; offset < size; offset += 4)
702 EXPECT_EQ(offset, data[offset / 4]);
703 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800704}
705
Tony Barbour01999182015-04-09 12:58:51 -0600706TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800707{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600708 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800709 /* well aligned */
710 { 0, 0, 256 },
711 { 0, 256, 128 },
712 { 0, 384, 64 },
713 { 0, 448, 32 },
714 { 0, 480, 16 },
715 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800716
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800717 /* ill aligned */
718 { 7, 510, 16 },
719 { 16, 530, 13 },
720 { 32, 551, 16 },
721 { 45, 570, 15 },
722 { 50, 590, 1 },
723 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600724 vk_testing::Buffer src, dst;
Chia-I Wucb67c652014-10-21 11:06:26 +0800725
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800726 src.init(dev_, 256);
727 uint8_t *data = static_cast<uint8_t *>(src.map());
728 for (int i = 0; i < 256; i++)
729 data[i] = i;
730 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600731 add_memory_ref(src);
Chia-I Wucb67c652014-10-21 11:06:26 +0800732
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800733 dst.init(dev_, 1024);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600734 add_memory_ref(dst);
Chia-I Wucb67c652014-10-21 11:06:26 +0800735
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800736 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600737 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800738 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800739
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800740 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800741
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800742 data = static_cast<uint8_t *>(dst.map());
743 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600744 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800745
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800746 for (int j = 0; j < r.copySize; j++) {
747 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
748 "Region is: " << i << "\n" <<
749 "Offset is: " << r.destOffset + j;
750 }
751 }
752 dst.unmap();
753}
Chia-I Wucb67c652014-10-21 11:06:26 +0800754
Tony Barbour01999182015-04-09 12:58:51 -0600755TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800756{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600757 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 VkEventCreateInfo event_info;
759 VkEvent event;
760 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000761 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600762 VkResult err;
Mike Stroyan55658c22014-12-04 11:08:39 +0000763
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000765 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600766 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600767 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768 // VkFlags flags; // Reserved
769 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000770 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600771 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000772
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600773 err = vkCreateEvent(dev_.obj(), &event_info, &event);
774 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000775
Mike Stroyan230e6252015-04-17 12:36:38 -0600776 err = vkGetObjectInfo(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Mike Stroyan55658c22014-12-04 11:08:39 +0000777 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600778 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000779
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600780 // VkResult VKAPI vkAllocMemory(
781 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600782 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600783 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600784 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600785 VkDeviceMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000786
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000788
Mike Stroyan55658c22014-12-04 11:08:39 +0000789 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600790 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000791 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600792 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
793 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
794 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
795 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000796
Mike Stroyan230e6252015-04-17 12:36:38 -0600797 err = vkQueueBindObjectMemory(queue_.obj(), VK_OBJECT_TYPE_EVENT, event, 0, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600798 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000799
Mike Stroyan230e6252015-04-17 12:36:38 -0600800 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600801 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800802
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800803 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
804 bufs[i].init(dev_, 4);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600805 add_memory_ref(bufs[i]);
Chia-I Wucb67c652014-10-21 11:06:26 +0800806
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800807 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
808 data[0] = 0x22222222 * (i + 1);
809 bufs[i].unmap();
810 }
811
812 cmd_.begin();
813
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800815 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600816 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600817 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600818 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000819
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600820 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600821 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&pmemory_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800822
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600823 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800824 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600825 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000826
827 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600828 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600829 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600830 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&pmemory_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800831
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600832 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000833
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600834 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
835 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000836 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600837 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000838
839 // Additional commands could go into the buffer here before the wait.
840
841 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600842 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_CPU_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600843 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600844 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000845
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800846 cmd_.end();
847
848 submit_and_done();
849
850 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
851 EXPECT_EQ(0x11111111, data[0]);
852 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000853
854 // All done with event memory, clean up
Mike Stroyan230e6252015-04-17 12:36:38 -0600855 err = vkQueueBindObjectMemory(queue_.obj(), VK_OBJECT_TYPE_EVENT, event, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600856 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000857
Mike Stroyan230e6252015-04-17 12:36:38 -0600858 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 ASSERT_VK_SUCCESS(err);
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600860
Mike Stroyan230e6252015-04-17 12:36:38 -0600861 err = vkFreeMemory(dev_.obj(), event_mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600862 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800863}
864
Tony Barbour01999182015-04-09 12:58:51 -0600865class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800866protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600867 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800868 {
Tony Barbour8205d902015-04-16 15:59:00 -0600869 first_linear_format_ = VK_FORMAT_UNDEFINED;
870 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800871
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600872 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800873 it != dev_.formats().end(); it++) {
874 if (it->features & features) {
875 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800876
Tony Barbour8205d902015-04-16 15:59:00 -0600877 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
878 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800879 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600880 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
881 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800882 first_optimal_format_ = it->format;
883 }
884 }
885 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800886
Chia-I Wu9feab842014-12-22 13:19:08 +0800887 void init_test_formats()
888 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600889 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800890 }
891
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600892 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800893 {
894 if (img.transparent()) {
895 checker.fill(img);
896 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800897 }
898
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800899 ASSERT_EQ(true, img.copyable());
900
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600901 vk_testing::Buffer in_buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800902 in_buf.init(dev_, checker.buffer_size());
903 checker.fill(in_buf);
904
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600905 add_memory_ref(in_buf);
906 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800907
908 // copy in and tile
909 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600910 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
911 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800912 checker.regions().size(), &checker.regions()[0]);
913 cmd_.end();
914
915 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800916 }
917
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600918 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800919 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800920 if (img.transparent()) {
921 DO(checker.check(img));
922 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800923 }
924
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800925 ASSERT_EQ(true, img.copyable());
926
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600927 vk_testing::Buffer out_buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800928 out_buf.init(dev_, checker.buffer_size());
929
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600930 add_memory_ref(img);
931 add_memory_ref(out_buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800932
933 // copy out and linearize
934 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600935 vkCmdCopyImageToBuffer(cmd_.obj(),
936 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600937 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800938 checker.regions().size(), &checker.regions()[0]);
939 cmd_.end();
940
941 submit_and_done();
942
943 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800944 }
945
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600946 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600947 VkFormat first_linear_format_;
948 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800949};
950
Tony Barbour01999182015-04-09 12:58:51 -0600951class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800952protected:
953 virtual void SetUp()
954 {
Tony Barbour01999182015-04-09 12:58:51 -0600955 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600956 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800957 ASSERT_NE(true, test_formats_.empty());
958 }
959
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600960 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800961 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600962 vk_testing::Buffer buf;
963 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800964
965 buf.init(dev_, checker.buffer_size());
966 checker.fill(buf);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600967 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800968
969 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600970 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800971
972 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600973 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600974 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600975 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800976 checker.regions().size(), &checker.regions()[0]);
977 cmd_.end();
978
979 submit_and_done();
980
981 check_dst(img, checker);
982 }
983
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600984 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800985 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600986 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800987 test_copy_memory_to_image(img_info, checker);
988 }
989
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600990 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800991 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600992 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800993 test_copy_memory_to_image(img_info, checker);
994 }
995};
996
Tony Barbour01999182015-04-09 12:58:51 -0600997TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800998{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600999 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001000 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001001
1002 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001003 if (it->format == VK_FORMAT_UNDEFINED ||
1004 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1005 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001006 continue;
1007
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001008 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001009 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001010 img_info.format = it->format;
1011 img_info.extent.width = 64;
1012 img_info.extent.height = 64;
1013 img_info.tiling = it->tiling;
1014
1015 test_copy_memory_to_image(img_info);
1016 }
Chia-I Wu86822632014-11-22 15:09:42 +08001017}
1018
Tony Barbour01999182015-04-09 12:58:51 -06001019class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001020protected:
1021 virtual void SetUp()
1022 {
Tony Barbour01999182015-04-09 12:58:51 -06001023 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001024 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001025 ASSERT_NE(true, test_formats_.empty());
1026 }
1027
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001028 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001029 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001030 vk_testing::Image img;
1031 vk_testing::Buffer buf;
Chia-I Wu830fb332014-12-13 15:28:20 +08001032
1033 img.init(dev_, img_info);
1034 fill_src(img, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001035 add_memory_ref(img);
Chia-I Wu830fb332014-12-13 15:28:20 +08001036
1037 buf.init(dev_, checker.buffer_size());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001038 add_memory_ref(buf);
Chia-I Wu830fb332014-12-13 15:28:20 +08001039
1040 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001041 vkCmdCopyImageToBuffer(cmd_.obj(),
1042 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001043 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001044 checker.regions().size(), &checker.regions()[0]);
1045 cmd_.end();
1046
1047 submit_and_done();
1048
1049 checker.check(buf);
1050 }
1051
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001052 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001053 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001055 test_copy_image_to_memory(img_info, checker);
1056 }
1057
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001058 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001059 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001060 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001061 test_copy_image_to_memory(img_info, checker);
1062 }
1063};
1064
Tony Barbour01999182015-04-09 12:58:51 -06001065TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001066{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001067 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001068 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001069
1070 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001071 if (it->format == VK_FORMAT_UNDEFINED ||
1072 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1073 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001074 continue;
1075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001076 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001077 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001078 img_info.format = it->format;
1079 img_info.extent.width = 64;
1080 img_info.extent.height = 64;
1081 img_info.tiling = it->tiling;
1082
1083 test_copy_image_to_memory(img_info);
1084 }
1085}
1086
Tony Barbour01999182015-04-09 12:58:51 -06001087class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001088protected:
1089 virtual void SetUp()
1090 {
Tony Barbour01999182015-04-09 12:58:51 -06001091 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001092 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001093 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001094 }
1095
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1097 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001098 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001099 // convert VkImageCopy to two sets of VkBufferImageCopy
1100 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001101 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001102 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1103 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001104
Chia-I Wu714df452015-01-01 07:55:04 +08001105 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001106 src_region.imageSubresource = it->srcSubresource;
1107 src_region.imageOffset = it->srcOffset;
1108 src_region.imageExtent = it->extent;
1109 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001110
Chia-I Wu714df452015-01-01 07:55:04 +08001111 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001112 dst_region.imageSubresource = it->destSubresource;
1113 dst_region.imageOffset = it->destOffset;
1114 dst_region.imageExtent = it->extent;
1115 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001116
Tony Barbour8205d902015-04-16 15:59:00 -06001117 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001118 src_offset += vk_testing::get_format_size(src_info.format) * size;
1119 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001120 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001121
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001122 vk_testing::ImageChecker src_checker(src_info, src_regions);
1123 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001124
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 vk_testing::Image src;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001126 src.init(dev_, src_info);
1127 fill_src(src, src_checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001128 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001129
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001130 vk_testing::Image dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001131 dst.init(dev_, dst_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001132 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001133
1134 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001135 vkCmdCopyImage(cmd_.obj(),
1136 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1137 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001138 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001139 cmd_.end();
1140
1141 submit_and_done();
1142
1143 check_dst(dst, dst_checker);
1144 }
1145};
1146
Tony Barbour01999182015-04-09 12:58:51 -06001147TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001148{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001149 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001150 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001151
1152 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001153 if (it->format == VK_FORMAT_UNDEFINED ||
1154 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1155 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001156 continue;
1157
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001158 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001159 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001160 img_info.format = it->format;
1161 img_info.extent.width = 64;
1162 img_info.extent.height = 64;
1163 img_info.tiling = it->tiling;
1164
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001165 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001166 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001167 copy.destSubresource = copy.srcSubresource;
1168 copy.extent = img_info.extent;
1169
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001170 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001171 }
1172}
1173
Tony Barbour01999182015-04-09 12:58:51 -06001174class VkCmdCloneImageDataTest : public VkCmdBlitImageTest {
Chia-I Wub75939f2014-12-22 14:46:56 +08001175protected:
1176 virtual void SetUp()
1177 {
Tony Barbour01999182015-04-09 12:58:51 -06001178 VkCmdBlitTest::SetUp();
Chia-I Wub75939f2014-12-22 14:46:56 +08001179 init_test_formats();
1180 ASSERT_NE(true, test_formats_.empty());
1181 }
1182
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001183 void test_clone_image_data(const VkImageCreateInfo &img_info)
Chia-I Wub75939f2014-12-22 14:46:56 +08001184 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001185 vk_testing::ImageChecker checker(img_info);
1186 vk_testing::Image src, dst;
Chia-I Wub75939f2014-12-22 14:46:56 +08001187
1188 src.init(dev_, img_info);
1189 if (src.transparent() || src.copyable())
1190 fill_src(src, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001191 add_memory_ref(src);
Chia-I Wub75939f2014-12-22 14:46:56 +08001192
1193 dst.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001194 add_memory_ref(dst);
Chia-I Wub75939f2014-12-22 14:46:56 +08001195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001196 const VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wub75939f2014-12-22 14:46:56 +08001197
1198 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001199 vkCmdCloneImageData(cmd_.obj(), src.obj(), layout, dst.obj(), layout);
Chia-I Wub75939f2014-12-22 14:46:56 +08001200 cmd_.end();
1201
1202 submit_and_done();
1203
1204 // cannot verify
1205 if (!dst.transparent() && !dst.copyable())
1206 return;
1207
1208 check_dst(dst, checker);
1209 }
1210};
1211
Tony Barbour01999182015-04-09 12:58:51 -06001212TEST_F(VkCmdCloneImageDataTest, Basic)
Chia-I Wub75939f2014-12-22 14:46:56 +08001213{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001214 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wub75939f2014-12-22 14:46:56 +08001215 it != test_formats_.end(); it++) {
1216 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001217 if (it->format == VK_FORMAT_UNDEFINED ||
1218 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1219 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1220 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1221 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1222 (it->format >= VK_FORMAT_BC1_RGB_UNORM &&
1223 it->format <= VK_FORMAT_ASTC_12x12_SRGB) ||
1224 (it->format >= VK_FORMAT_D16_UNORM &&
1225 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT) ||
1226 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1227 it->format == VK_FORMAT_R64G64B64A64_SFLOAT)
Chia-I Wub75939f2014-12-22 14:46:56 +08001228 continue;
1229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001230 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001231 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wub75939f2014-12-22 14:46:56 +08001232 img_info.format = it->format;
1233 img_info.extent.width = 64;
1234 img_info.extent.height = 64;
1235 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001236 img_info.flags = VK_IMAGE_CREATE_CLONEABLE_BIT;
Chia-I Wub75939f2014-12-22 14:46:56 +08001237
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001238 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001239 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001240 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wub75939f2014-12-22 14:46:56 +08001241
1242 test_clone_image_data(img_info);
1243 }
1244}
1245
Tony Barbour01999182015-04-09 12:58:51 -06001246class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001247protected:
Tony Barbour01999182015-04-09 12:58:51 -06001248 VkCmdClearColorImageTest() : test_raw_(false) {}
1249 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001250
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001251 virtual void SetUp()
1252 {
Tony Barbour01999182015-04-09 12:58:51 -06001253 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001254
1255 if (test_raw_)
1256 init_test_formats();
1257 else
Tony Barbour8205d902015-04-16 15:59:00 -06001258 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001259
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001260 ASSERT_NE(true, test_formats_.empty());
1261 }
1262
Chia-I Wu9feab842014-12-22 13:19:08 +08001263 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001264 float color[4];
1265 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001266 };
1267
1268 bool test_raw_;
1269
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001270 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001271 {
1272 std::vector<uint8_t> raw;
1273
1274 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001275 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001276 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001277 raw.push_back(color[0] * 255.0f);
1278 raw.push_back(color[1] * 255.0f);
1279 raw.push_back(color[2] * 255.0f);
1280 raw.push_back(color[3] * 255.0f);
1281 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001282 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001283 raw.push_back(color[2] * 255.0f);
1284 raw.push_back(color[1] * 255.0f);
1285 raw.push_back(color[0] * 255.0f);
1286 raw.push_back(color[3] * 255.0f);
1287 break;
1288 default:
1289 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001290 }
1291
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001292 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001293 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001294
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001295 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001296 {
1297 std::vector<uint8_t> raw;
1298
1299 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001300 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001301 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001302 raw.push_back(static_cast<uint8_t>(color[0]));
1303 raw.push_back(static_cast<uint8_t>(color[1]));
1304 raw.push_back(static_cast<uint8_t>(color[2]));
1305 raw.push_back(static_cast<uint8_t>(color[3]));
1306 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001307 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001308 raw.push_back(static_cast<uint8_t>(color[2]));
1309 raw.push_back(static_cast<uint8_t>(color[1]));
1310 raw.push_back(static_cast<uint8_t>(color[0]));
1311 raw.push_back(static_cast<uint8_t>(color[3]));
1312 break;
1313 default:
1314 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001315 }
1316
1317 return raw;
1318 }
1319
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001320 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001321 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001322 if (color.useRawValue)
1323 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001324 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001325 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001326 }
1327
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 void test_clear_color_image(const VkImageCreateInfo &img_info,
1329 const VkClearColor &clear_color,
1330 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001331 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001332 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001333 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001334 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1337 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1338 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1339 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001340 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001341 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001342 VK_MEMORY_INPUT_CPU_READ_BIT |
1343 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1344 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1345 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1346 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1347 VK_MEMORY_INPUT_SHADER_READ_BIT |
1348 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1349 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001350 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001351
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352 std::vector<VkImageMemoryBarrier> to_clear;
1353 std::vector<VkImageMemoryBarrier *> p_to_clear;
1354 std::vector<VkImageMemoryBarrier> to_xfer;
1355 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001356
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001357 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001358 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001359 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001360 VK_IMAGE_LAYOUT_GENERAL,
1361 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001362 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001363 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001364 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1366 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001367 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001368 }
1369
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001370 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001371
Tony Barbour8205d902015-04-16 15:59:00 -06001372 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1373 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&p_to_clear[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001374
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001375 vkCmdClearColorImage(cmd_.obj(),
1376 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001377 clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001378
Tony Barbour8205d902015-04-16 15:59:00 -06001379 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, 1, (const void **)&p_to_xfer[0]);
Chia-I Wu9feab842014-12-22 13:19:08 +08001380
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001381 cmd_.end();
1382
1383 submit_and_done();
1384
1385 // cannot verify
1386 if (!img.transparent() && !img.copyable())
1387 return;
1388
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001389 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001390
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001391 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001392 if (solid_pattern.empty())
1393 return;
1394
1395 checker.set_solid_pattern(solid_pattern);
1396 check_dst(img, checker);
1397 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001398
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001399 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001400 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001401 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001402 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001403 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001404 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001405 test_clear_color_image(img_info, c, ranges);
1406 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001407};
1408
Tony Barbour01999182015-04-09 12:58:51 -06001409TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001410{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001411 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001412 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001413 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001414
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001415 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001416 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001417 img_info.format = it->format;
1418 img_info.extent.width = 64;
1419 img_info.extent.height = 64;
1420 img_info.tiling = it->tiling;
1421
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001422 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001423 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001424 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001425
1426 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001427 }
1428}
1429
Tony Barbour01999182015-04-09 12:58:51 -06001430class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001431protected:
Tony Barbour01999182015-04-09 12:58:51 -06001432 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001433
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001434 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001435 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001436 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001437 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001438 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001439 c.useRawValue = true;
1440 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001441 test_clear_color_image(img_info, c, ranges);
1442 }
1443};
1444
Tony Barbour01999182015-04-09 12:58:51 -06001445TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001446{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001447 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001448 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001449 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001450
1451 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001452 if (it->format == VK_FORMAT_UNDEFINED ||
1453 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1454 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1455 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1456 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1457 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1458 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1459 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1460 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1461 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1462 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1463 (it->format >= VK_FORMAT_D16_UNORM &&
1464 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001465 continue;
1466
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001467 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001468 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001469 img_info.format = it->format;
1470 img_info.extent.width = 64;
1471 img_info.extent.height = 64;
1472 img_info.tiling = it->tiling;
1473
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001474 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001475 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001476 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001477
1478 test_clear_color_image_raw(img_info, color, ranges);
1479 }
1480}
1481
Tony Barbour01999182015-04-09 12:58:51 -06001482class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001483protected:
1484 virtual void SetUp()
1485 {
Tony Barbour01999182015-04-09 12:58:51 -06001486 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001487 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001488 ASSERT_NE(true, test_formats_.empty());
1489 }
1490
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001491 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001492 {
1493 std::vector<uint8_t> raw;
1494
1495 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001496 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001497 case VK_FORMAT_D16_UNORM:
1498 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001499 {
1500 const uint16_t unorm = depth * 65535.0f;
1501 raw.push_back(unorm & 0xff);
1502 raw.push_back(unorm >> 8);
1503 }
1504 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001505 case VK_FORMAT_D32_SFLOAT:
1506 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001507 {
1508 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001509 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001510 uint32_t u32;
1511 } u = { depth };
1512
1513 raw.push_back((u.u32 ) & 0xff);
1514 raw.push_back((u.u32 >> 8) & 0xff);
1515 raw.push_back((u.u32 >> 16) & 0xff);
1516 raw.push_back((u.u32 >> 24) & 0xff);
1517 }
1518 break;
1519 default:
1520 break;
1521 }
1522
1523 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001524 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001525 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001526 raw.push_back(stencil);
1527 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001528 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001529 raw.push_back(stencil);
1530 raw.push_back(0);
1531 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001532 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001533 raw.push_back(stencil);
1534 raw.push_back(0);
1535 raw.push_back(0);
1536 raw.push_back(0);
1537 break;
1538 default:
1539 break;
1540 }
1541
1542 return raw;
1543 }
1544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001545 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001546 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001547 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001548 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001549 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001550 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001551 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001552 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001553 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1554 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1555 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1556 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001557 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001558 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001559 VK_MEMORY_INPUT_CPU_READ_BIT |
1560 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1561 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1562 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1563 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1564 VK_MEMORY_INPUT_SHADER_READ_BIT |
1565 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1566 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001567 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001568
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001569 std::vector<VkImageMemoryBarrier> to_clear;
1570 std::vector<VkImageMemoryBarrier *> p_to_clear;
1571 std::vector<VkImageMemoryBarrier> to_xfer;
1572 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001573
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001574 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001575 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001576 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001577 VK_IMAGE_LAYOUT_GENERAL,
1578 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001579 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001580 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001581 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001582 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1583 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001584 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001585 }
1586
1587 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001588
Tony Barbour8205d902015-04-16 15:59:00 -06001589 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1590 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, to_clear.size(), (const void **)&p_to_clear[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001591
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 vkCmdClearDepthStencil(cmd_.obj(),
1593 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001594 depth, stencil,
1595 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001596
Tony Barbour8205d902015-04-16 15:59:00 -06001597 vkCmdPipelineBarrier(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, set_events, to_xfer.size(), (const void **)&p_to_xfer[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001598
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001599 cmd_.end();
1600
1601 submit_and_done();
1602
1603 // cannot verify
1604 if (!img.transparent() && !img.copyable())
1605 return;
1606
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001607 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001608
1609 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1610 check_dst(img, checker);
1611 }
1612};
1613
Tony Barbour01999182015-04-09 12:58:51 -06001614TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001615{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001616 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001617 it != test_formats_.end(); it++) {
1618 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001619 if (it->format == VK_FORMAT_S8_UINT ||
1620 it->format == VK_FORMAT_D24_UNORM ||
1621 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1622 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001623 continue;
1624
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001625 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001626 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001627 img_info.format = it->format;
1628 img_info.extent.width = 64;
1629 img_info.extent.height = 64;
1630 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001631 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001632
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001633 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001634 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001635 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001636
1637 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1638 }
1639}
1640
1641}; // namespace
1642
Chia-I Wucb67c652014-10-21 11:06:26 +08001643int main(int argc, char **argv)
1644{
Chia-I Wucb67c652014-10-21 11:06:26 +08001645 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001646
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001648
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001649 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001650
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001651 if (!environment->parse_args(argc, argv))
1652 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001653
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001654 ::testing::AddGlobalTestEnvironment(environment);
1655
1656 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001657}