blob: 98d81cbacc15df5f6ecea1f90f8f593caeda47fd [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;
Tony Barbour94310562015-04-22 15:10:33 -0600552 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800553
Tony Barbour94310562015-04-22 15:10:33 -0600554 buf.init(dev_, 20, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600555 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800556
557 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600558 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
559 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800560 cmd_.end();
561
562 submit_and_done();
563
564 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
565 EXPECT_EQ(0x11111111, data[0]);
566 EXPECT_EQ(0x22222222, data[1]);
567 EXPECT_EQ(0x22222222, data[2]);
568 EXPECT_EQ(0x22222222, data[3]);
569 EXPECT_EQ(0x22222222, data[4]);
570 buf.unmap();
571}
572
Tony Barbour01999182015-04-09 12:58:51 -0600573TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800574{
Tony Barbour8205d902015-04-16 15:59:00 -0600575 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600577 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800578
Tony Barbour94310562015-04-22 15:10:33 -0600579 buf.init(dev_, size, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600580 add_memory_ref(buf);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800581
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800582 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600583 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
584 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800585 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800586
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800587 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800588
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800589 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600590 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800591 for (offset = 0; offset < size / 2; offset += 4)
592 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
593 for (; offset < size; offset += 4)
594 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
595 buf.unmap();
596}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800597
Tony Barbour01999182015-04-09 12:58:51 -0600598TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800599{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600600 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600601 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800602
Tony Barbour94310562015-04-22 15:10:33 -0600603 buf.init(dev_, 64, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600604 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800605
606 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
608 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800609 cmd_.end();
610
611 submit_and_done();
612
613 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600614 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800615 for (offset = 0; offset < 32; offset += 4)
616 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
617 for (; offset < 64; offset += 4)
618 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
619 buf.unmap();
620}
621
Tony Barbour01999182015-04-09 12:58:51 -0600622TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800623{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600625 VkDeviceSize size = 4;
Tony Barbour94310562015-04-22 15:10:33 -0600626 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800627
628 cmd_.begin();
629 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600630 bufs[i].init(dev_, size, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600631 add_memory_ref(bufs[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600632 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800633 size <<= 1;
634 }
635 cmd_.end();
636
637 submit_and_done();
638
639 size = 4;
640 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
641 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600642 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800643 for (offset = 0; offset < size; offset += 4)
644 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
645 "Offset is: " << offset;
646 bufs[i].unmap();
647
648 size <<= 1;
649 }
650}
651
Tony Barbour01999182015-04-09 12:58:51 -0600652typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800653
Tony Barbour01999182015-04-09 12:58:51 -0600654TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800655{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600657 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800658
Tony Barbour94310562015-04-22 15:10:33 -0600659 src.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800660 uint32_t *data = static_cast<uint32_t *>(src.map());
661 data[0] = 0x11111111;
662 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600663 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800664
Tony Barbour94310562015-04-22 15:10:33 -0600665 dst.init(dev_, 4, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600666 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800667
668 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600669 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800670 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600671 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800672 cmd_.end();
673
674 submit_and_done();
675
676 data = static_cast<uint32_t *>(dst.map());
677 EXPECT_EQ(0x11111111, data[0]);
678 dst.unmap();
679}
680
Tony Barbour01999182015-04-09 12:58:51 -0600681TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800682{
Tony Barbour8205d902015-04-16 15:59:00 -0600683 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600684 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600685 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800686
Tony Barbour94310562015-04-22 15:10:33 -0600687 src.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800688 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600689 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800690 for (offset = 0; offset < size; offset += 4)
691 data[offset / 4] = offset;
692 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600693 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800694
Tony Barbour94310562015-04-22 15:10:33 -0600695 dst.init(dev_, size, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600696 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800697
698 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600699 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800700 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600701 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800702 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800703
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800704 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800705
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800706 data = static_cast<uint32_t *>(dst.map());
707 for (offset = 0; offset < size; offset += 4)
708 EXPECT_EQ(offset, data[offset / 4]);
709 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800710}
711
Tony Barbour01999182015-04-09 12:58:51 -0600712TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800713{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600714 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800715 /* well aligned */
716 { 0, 0, 256 },
717 { 0, 256, 128 },
718 { 0, 384, 64 },
719 { 0, 448, 32 },
720 { 0, 480, 16 },
721 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800722
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800723 /* ill aligned */
724 { 7, 510, 16 },
725 { 16, 530, 13 },
726 { 32, 551, 16 },
727 { 45, 570, 15 },
728 { 50, 590, 1 },
729 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600730 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600731 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +0800732
Tony Barbour94310562015-04-22 15:10:33 -0600733 src.init(dev_, 256, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800734 uint8_t *data = static_cast<uint8_t *>(src.map());
735 for (int i = 0; i < 256; i++)
736 data[i] = i;
737 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600738 add_memory_ref(src);
Chia-I Wucb67c652014-10-21 11:06:26 +0800739
Tony Barbour94310562015-04-22 15:10:33 -0600740 dst.init(dev_, 1024, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600741 add_memory_ref(dst);
Chia-I Wucb67c652014-10-21 11:06:26 +0800742
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800743 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600744 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800745 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800746
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800747 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800748
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800749 data = static_cast<uint8_t *>(dst.map());
750 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600751 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800752
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800753 for (int j = 0; j < r.copySize; j++) {
754 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
755 "Region is: " << i << "\n" <<
756 "Offset is: " << r.destOffset + j;
757 }
758 }
759 dst.unmap();
760}
Chia-I Wucb67c652014-10-21 11:06:26 +0800761
Tony Barbour01999182015-04-09 12:58:51 -0600762TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800763{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600765 VkEventCreateInfo event_info;
766 VkEvent event;
767 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000768 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600769 VkResult err;
Tony Barbour94310562015-04-22 15:10:33 -0600770 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyan55658c22014-12-04 11:08:39 +0000771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000773 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600774 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600775 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600776 // VkFlags flags; // Reserved
777 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000778 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000780
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600781 err = vkCreateEvent(dev_.obj(), &event_info, &event);
782 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000783
Mike Stroyan230e6252015-04-17 12:36:38 -0600784 err = vkGetObjectInfo(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Mike Stroyan55658c22014-12-04 11:08:39 +0000785 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600786 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000787
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600788 // VkResult VKAPI vkAllocMemory(
789 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600790 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600791 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600792 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600793 VkDeviceMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000794
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600795 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000796
Mike Stroyan55658c22014-12-04 11:08:39 +0000797 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600798 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000799 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600800 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
801 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
802 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
803 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000804
Mike Stroyan230e6252015-04-17 12:36:38 -0600805 err = vkQueueBindObjectMemory(queue_.obj(), VK_OBJECT_TYPE_EVENT, event, 0, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600806 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000807
Mike Stroyan230e6252015-04-17 12:36:38 -0600808 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600809 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800810
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800811 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600812 bufs[i].init(dev_, 4, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600813 add_memory_ref(bufs[i]);
Chia-I Wucb67c652014-10-21 11:06:26 +0800814
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800815 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
816 data[0] = 0x22222222 * (i + 1);
817 bufs[i].unmap();
818 }
819
820 cmd_.begin();
821
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600822 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800823 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600824 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600825 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600826 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000827
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600828 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600829 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 +0800830
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600831 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800832 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600833 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000834
835 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600836 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600837 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600838 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 +0800839
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000841
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
843 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000844 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600845 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000846
847 // Additional commands could go into the buffer here before the wait.
848
849 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600850 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_CPU_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600851 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600852 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000853
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800854 cmd_.end();
855
856 submit_and_done();
857
858 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
859 EXPECT_EQ(0x11111111, data[0]);
860 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000861
862 // All done with event memory, clean up
Mike Stroyan230e6252015-04-17 12:36:38 -0600863 err = vkQueueBindObjectMemory(queue_.obj(), VK_OBJECT_TYPE_EVENT, event, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600864 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000865
Mike Stroyan230e6252015-04-17 12:36:38 -0600866 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600867 ASSERT_VK_SUCCESS(err);
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600868
Mike Stroyan230e6252015-04-17 12:36:38 -0600869 err = vkFreeMemory(dev_.obj(), event_mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600870 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800871}
872
Tony Barbour01999182015-04-09 12:58:51 -0600873class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800874protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600875 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800876 {
Tony Barbour8205d902015-04-16 15:59:00 -0600877 first_linear_format_ = VK_FORMAT_UNDEFINED;
878 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800879
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600880 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800881 it != dev_.formats().end(); it++) {
882 if (it->features & features) {
883 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800884
Tony Barbour8205d902015-04-16 15:59:00 -0600885 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
886 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800887 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600888 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
889 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800890 first_optimal_format_ = it->format;
891 }
892 }
893 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800894
Chia-I Wu9feab842014-12-22 13:19:08 +0800895 void init_test_formats()
896 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600897 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800898 }
899
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600900 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800901 {
902 if (img.transparent()) {
903 checker.fill(img);
904 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800905 }
906
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800907 ASSERT_EQ(true, img.copyable());
908
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600909 vk_testing::Buffer in_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600910 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
911
912 in_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800913 checker.fill(in_buf);
914
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600915 add_memory_ref(in_buf);
916 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800917
918 // copy in and tile
919 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600920 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
921 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800922 checker.regions().size(), &checker.regions()[0]);
923 cmd_.end();
924
925 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800926 }
927
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600928 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800929 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800930 if (img.transparent()) {
931 DO(checker.check(img));
932 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800933 }
934
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800935 ASSERT_EQ(true, img.copyable());
936
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600937 vk_testing::Buffer out_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600938 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
939 out_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800940
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600941 add_memory_ref(img);
942 add_memory_ref(out_buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800943
944 // copy out and linearize
945 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600946 vkCmdCopyImageToBuffer(cmd_.obj(),
947 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600948 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800949 checker.regions().size(), &checker.regions()[0]);
950 cmd_.end();
951
952 submit_and_done();
953
954 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800955 }
956
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600957 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600958 VkFormat first_linear_format_;
959 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800960};
961
Tony Barbour01999182015-04-09 12:58:51 -0600962class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800963protected:
964 virtual void SetUp()
965 {
Tony Barbour01999182015-04-09 12:58:51 -0600966 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600967 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800968 ASSERT_NE(true, test_formats_.empty());
969 }
970
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600971 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800972 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600973 vk_testing::Buffer buf;
974 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -0600975 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800976
Tony Barbour94310562015-04-22 15:10:33 -0600977 buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800978 checker.fill(buf);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600979 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800980
Tony Barbour94310562015-04-22 15:10:33 -0600981 img.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600982 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800983
984 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600985 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600986 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600987 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800988 checker.regions().size(), &checker.regions()[0]);
989 cmd_.end();
990
991 submit_and_done();
992
993 check_dst(img, checker);
994 }
995
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600996 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800997 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600998 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800999 test_copy_memory_to_image(img_info, checker);
1000 }
1001
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001002 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001003 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001004 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001005 test_copy_memory_to_image(img_info, checker);
1006 }
1007};
1008
Tony Barbour01999182015-04-09 12:58:51 -06001009TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001010{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001011 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001012 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001013
1014 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001015 if (it->format == VK_FORMAT_UNDEFINED ||
1016 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1017 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001018 continue;
1019
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001020 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001021 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001022 img_info.format = it->format;
1023 img_info.extent.width = 64;
1024 img_info.extent.height = 64;
1025 img_info.tiling = it->tiling;
1026
1027 test_copy_memory_to_image(img_info);
1028 }
Chia-I Wu86822632014-11-22 15:09:42 +08001029}
1030
Tony Barbour01999182015-04-09 12:58:51 -06001031class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001032protected:
1033 virtual void SetUp()
1034 {
Tony Barbour01999182015-04-09 12:58:51 -06001035 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001036 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001037 ASSERT_NE(true, test_formats_.empty());
1038 }
1039
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001040 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001041 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001042 vk_testing::Image img;
1043 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -06001044 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu830fb332014-12-13 15:28:20 +08001045
Tony Barbour94310562015-04-22 15:10:33 -06001046 img.init(dev_, img_info, reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001047 fill_src(img, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001048 add_memory_ref(img);
Chia-I Wu830fb332014-12-13 15:28:20 +08001049
Tony Barbour94310562015-04-22 15:10:33 -06001050 buf.init(dev_, checker.buffer_size(), reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001051 add_memory_ref(buf);
Chia-I Wu830fb332014-12-13 15:28:20 +08001052
1053 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 vkCmdCopyImageToBuffer(cmd_.obj(),
1055 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001056 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001057 checker.regions().size(), &checker.regions()[0]);
1058 cmd_.end();
1059
1060 submit_and_done();
1061
1062 checker.check(buf);
1063 }
1064
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001065 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001066 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001067 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001068 test_copy_image_to_memory(img_info, checker);
1069 }
1070
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001071 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001072 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001073 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001074 test_copy_image_to_memory(img_info, checker);
1075 }
1076};
1077
Tony Barbour01999182015-04-09 12:58:51 -06001078TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001079{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001080 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001081 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001082
1083 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001084 if (it->format == VK_FORMAT_UNDEFINED ||
1085 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1086 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001087 continue;
1088
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001089 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001090 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001091 img_info.format = it->format;
1092 img_info.extent.width = 64;
1093 img_info.extent.height = 64;
1094 img_info.tiling = it->tiling;
1095
1096 test_copy_image_to_memory(img_info);
1097 }
1098}
1099
Tony Barbour01999182015-04-09 12:58:51 -06001100class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001101protected:
1102 virtual void SetUp()
1103 {
Tony Barbour01999182015-04-09 12:58:51 -06001104 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001105 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001106 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001107 }
1108
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001109 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1110 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001111 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001112 // convert VkImageCopy to two sets of VkBufferImageCopy
1113 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001114 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1116 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001117
Chia-I Wu714df452015-01-01 07:55:04 +08001118 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001119 src_region.imageSubresource = it->srcSubresource;
1120 src_region.imageOffset = it->srcOffset;
1121 src_region.imageExtent = it->extent;
1122 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001123
Chia-I Wu714df452015-01-01 07:55:04 +08001124 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001125 dst_region.imageSubresource = it->destSubresource;
1126 dst_region.imageOffset = it->destOffset;
1127 dst_region.imageExtent = it->extent;
1128 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001129
Tony Barbour8205d902015-04-16 15:59:00 -06001130 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001131 src_offset += vk_testing::get_format_size(src_info.format) * size;
1132 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001133 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001134
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001135 vk_testing::ImageChecker src_checker(src_info, src_regions);
1136 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour94310562015-04-22 15:10:33 -06001137 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001138
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001139 vk_testing::Image src;
Tony Barbour94310562015-04-22 15:10:33 -06001140 src.init(dev_, src_info, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001141 fill_src(src, src_checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001142 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001143
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001144 vk_testing::Image dst;
Tony Barbour94310562015-04-22 15:10:33 -06001145 dst.init(dev_, dst_info, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001146 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001147
1148 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001149 vkCmdCopyImage(cmd_.obj(),
1150 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1151 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001152 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001153 cmd_.end();
1154
1155 submit_and_done();
1156
1157 check_dst(dst, dst_checker);
1158 }
1159};
1160
Tony Barbour01999182015-04-09 12:58:51 -06001161TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001162{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001163 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001164 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001165
1166 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001167 if (it->format == VK_FORMAT_UNDEFINED ||
1168 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1169 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001170 continue;
1171
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001173 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001174 img_info.format = it->format;
1175 img_info.extent.width = 64;
1176 img_info.extent.height = 64;
1177 img_info.tiling = it->tiling;
1178
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001179 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001180 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001181 copy.destSubresource = copy.srcSubresource;
1182 copy.extent = img_info.extent;
1183
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001184 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001185 }
1186}
1187
Tony Barbour01999182015-04-09 12:58:51 -06001188class VkCmdCloneImageDataTest : public VkCmdBlitImageTest {
Chia-I Wub75939f2014-12-22 14:46:56 +08001189protected:
1190 virtual void SetUp()
1191 {
Tony Barbour01999182015-04-09 12:58:51 -06001192 VkCmdBlitTest::SetUp();
Chia-I Wub75939f2014-12-22 14:46:56 +08001193 init_test_formats();
1194 ASSERT_NE(true, test_formats_.empty());
1195 }
1196
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197 void test_clone_image_data(const VkImageCreateInfo &img_info)
Chia-I Wub75939f2014-12-22 14:46:56 +08001198 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001199 vk_testing::ImageChecker checker(img_info);
1200 vk_testing::Image src, dst;
Tony Barbour94310562015-04-22 15:10:33 -06001201 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wub75939f2014-12-22 14:46:56 +08001202
Tony Barbour94310562015-04-22 15:10:33 -06001203 src.init(dev_, img_info, reqs);
Chia-I Wub75939f2014-12-22 14:46:56 +08001204 if (src.transparent() || src.copyable())
1205 fill_src(src, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001206 add_memory_ref(src);
Chia-I Wub75939f2014-12-22 14:46:56 +08001207
Tony Barbour94310562015-04-22 15:10:33 -06001208 dst.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001209 add_memory_ref(dst);
Chia-I Wub75939f2014-12-22 14:46:56 +08001210
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001211 const VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wub75939f2014-12-22 14:46:56 +08001212
1213 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001214 vkCmdCloneImageData(cmd_.obj(), src.obj(), layout, dst.obj(), layout);
Chia-I Wub75939f2014-12-22 14:46:56 +08001215 cmd_.end();
1216
1217 submit_and_done();
1218
1219 // cannot verify
1220 if (!dst.transparent() && !dst.copyable())
1221 return;
1222
1223 check_dst(dst, checker);
1224 }
1225};
1226
Tony Barbour01999182015-04-09 12:58:51 -06001227TEST_F(VkCmdCloneImageDataTest, Basic)
Chia-I Wub75939f2014-12-22 14:46:56 +08001228{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001229 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wub75939f2014-12-22 14:46:56 +08001230 it != test_formats_.end(); it++) {
1231 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001232 if (it->format == VK_FORMAT_UNDEFINED ||
1233 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1234 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1235 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1236 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1237 (it->format >= VK_FORMAT_BC1_RGB_UNORM &&
1238 it->format <= VK_FORMAT_ASTC_12x12_SRGB) ||
1239 (it->format >= VK_FORMAT_D16_UNORM &&
1240 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT) ||
1241 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1242 it->format == VK_FORMAT_R64G64B64A64_SFLOAT)
Chia-I Wub75939f2014-12-22 14:46:56 +08001243 continue;
1244
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001245 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001246 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wub75939f2014-12-22 14:46:56 +08001247 img_info.format = it->format;
1248 img_info.extent.width = 64;
1249 img_info.extent.height = 64;
1250 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001251 img_info.flags = VK_IMAGE_CREATE_CLONEABLE_BIT;
Chia-I Wub75939f2014-12-22 14:46:56 +08001252
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001254 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001255 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wub75939f2014-12-22 14:46:56 +08001256
1257 test_clone_image_data(img_info);
1258 }
1259}
1260
Tony Barbour01999182015-04-09 12:58:51 -06001261class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001262protected:
Tony Barbour01999182015-04-09 12:58:51 -06001263 VkCmdClearColorImageTest() : test_raw_(false) {}
1264 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001265
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001266 virtual void SetUp()
1267 {
Tony Barbour01999182015-04-09 12:58:51 -06001268 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001269
1270 if (test_raw_)
1271 init_test_formats();
1272 else
Tony Barbour8205d902015-04-16 15:59:00 -06001273 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001274
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001275 ASSERT_NE(true, test_formats_.empty());
1276 }
1277
Chia-I Wu9feab842014-12-22 13:19:08 +08001278 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001279 float color[4];
1280 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001281 };
1282
1283 bool test_raw_;
1284
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001285 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001286 {
1287 std::vector<uint8_t> raw;
1288
1289 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001290 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001291 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001292 raw.push_back(color[0] * 255.0f);
1293 raw.push_back(color[1] * 255.0f);
1294 raw.push_back(color[2] * 255.0f);
1295 raw.push_back(color[3] * 255.0f);
1296 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001297 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001298 raw.push_back(color[2] * 255.0f);
1299 raw.push_back(color[1] * 255.0f);
1300 raw.push_back(color[0] * 255.0f);
1301 raw.push_back(color[3] * 255.0f);
1302 break;
1303 default:
1304 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001305 }
1306
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001307 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001308 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001310 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001311 {
1312 std::vector<uint8_t> raw;
1313
1314 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001315 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001316 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001317 raw.push_back(static_cast<uint8_t>(color[0]));
1318 raw.push_back(static_cast<uint8_t>(color[1]));
1319 raw.push_back(static_cast<uint8_t>(color[2]));
1320 raw.push_back(static_cast<uint8_t>(color[3]));
1321 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001322 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001323 raw.push_back(static_cast<uint8_t>(color[2]));
1324 raw.push_back(static_cast<uint8_t>(color[1]));
1325 raw.push_back(static_cast<uint8_t>(color[0]));
1326 raw.push_back(static_cast<uint8_t>(color[3]));
1327 break;
1328 default:
1329 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001330 }
1331
1332 return raw;
1333 }
1334
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001336 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001337 if (color.useRawValue)
1338 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001339 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001340 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001341 }
1342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001343 void test_clear_color_image(const VkImageCreateInfo &img_info,
1344 const VkClearColor &clear_color,
1345 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001346 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001347 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -06001348 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1349
1350 img.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001351 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001353 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1354 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1355 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1356 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001357 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001358 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 VK_MEMORY_INPUT_CPU_READ_BIT |
1360 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1361 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1362 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1363 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1364 VK_MEMORY_INPUT_SHADER_READ_BIT |
1365 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1366 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001367 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001368
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001369 std::vector<VkImageMemoryBarrier> to_clear;
1370 std::vector<VkImageMemoryBarrier *> p_to_clear;
1371 std::vector<VkImageMemoryBarrier> to_xfer;
1372 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001373
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001375 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001376 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001377 VK_IMAGE_LAYOUT_GENERAL,
1378 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001379 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001380 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001381 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001382 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1383 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001384 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001385 }
1386
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001387 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001388
Tony Barbour8205d902015-04-16 15:59:00 -06001389 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1390 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 +00001391
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001392 vkCmdClearColorImage(cmd_.obj(),
1393 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001394 clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001395
Tony Barbour8205d902015-04-16 15:59:00 -06001396 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 +08001397
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001398 cmd_.end();
1399
1400 submit_and_done();
1401
1402 // cannot verify
1403 if (!img.transparent() && !img.copyable())
1404 return;
1405
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001407
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001408 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001409 if (solid_pattern.empty())
1410 return;
1411
1412 checker.set_solid_pattern(solid_pattern);
1413 check_dst(img, checker);
1414 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001415
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001416 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001417 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001418 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001419 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001420 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001421 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001422 test_clear_color_image(img_info, c, ranges);
1423 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001424};
1425
Tony Barbour01999182015-04-09 12:58:51 -06001426TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001427{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001428 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001429 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001430 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001431
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001432 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001433 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001434 img_info.format = it->format;
1435 img_info.extent.width = 64;
1436 img_info.extent.height = 64;
1437 img_info.tiling = it->tiling;
1438
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001439 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001440 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001441 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001442
1443 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001444 }
1445}
1446
Tony Barbour01999182015-04-09 12:58:51 -06001447class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001448protected:
Tony Barbour01999182015-04-09 12:58:51 -06001449 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001450
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001451 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001452 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001453 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001454 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001455 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001456 c.useRawValue = true;
1457 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001458 test_clear_color_image(img_info, c, ranges);
1459 }
1460};
1461
Tony Barbour01999182015-04-09 12:58:51 -06001462TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001463{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001464 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001465 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001466 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001467
1468 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001469 if (it->format == VK_FORMAT_UNDEFINED ||
1470 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1471 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1472 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1473 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1474 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1475 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1476 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1477 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1478 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1479 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1480 (it->format >= VK_FORMAT_D16_UNORM &&
1481 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001482 continue;
1483
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001484 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001485 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001486 img_info.format = it->format;
1487 img_info.extent.width = 64;
1488 img_info.extent.height = 64;
1489 img_info.tiling = it->tiling;
1490
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001491 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001492 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001493 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001494
1495 test_clear_color_image_raw(img_info, color, ranges);
1496 }
1497}
1498
Tony Barbour01999182015-04-09 12:58:51 -06001499class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001500protected:
1501 virtual void SetUp()
1502 {
Tony Barbour01999182015-04-09 12:58:51 -06001503 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001504 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001505 ASSERT_NE(true, test_formats_.empty());
1506 }
1507
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001508 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001509 {
1510 std::vector<uint8_t> raw;
1511
1512 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001513 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001514 case VK_FORMAT_D16_UNORM:
1515 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001516 {
1517 const uint16_t unorm = depth * 65535.0f;
1518 raw.push_back(unorm & 0xff);
1519 raw.push_back(unorm >> 8);
1520 }
1521 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001522 case VK_FORMAT_D32_SFLOAT:
1523 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001524 {
1525 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001526 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001527 uint32_t u32;
1528 } u = { depth };
1529
1530 raw.push_back((u.u32 ) & 0xff);
1531 raw.push_back((u.u32 >> 8) & 0xff);
1532 raw.push_back((u.u32 >> 16) & 0xff);
1533 raw.push_back((u.u32 >> 24) & 0xff);
1534 }
1535 break;
1536 default:
1537 break;
1538 }
1539
1540 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001541 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001542 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001543 raw.push_back(stencil);
1544 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001545 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001546 raw.push_back(stencil);
1547 raw.push_back(0);
1548 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001549 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001550 raw.push_back(stencil);
1551 raw.push_back(0);
1552 raw.push_back(0);
1553 raw.push_back(0);
1554 break;
1555 default:
1556 break;
1557 }
1558
1559 return raw;
1560 }
1561
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001562 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001563 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001564 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001565 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001566 vk_testing::Image img;
Tony Barbour94310562015-04-22 15:10:33 -06001567 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1568
1569 img.init(dev_, img_info, reqs);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001570 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001571 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001572 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1573 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1574 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1575 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001576 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001577 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001578 VK_MEMORY_INPUT_CPU_READ_BIT |
1579 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1580 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1581 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1582 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1583 VK_MEMORY_INPUT_SHADER_READ_BIT |
1584 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1585 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001586 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001587
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001588 std::vector<VkImageMemoryBarrier> to_clear;
1589 std::vector<VkImageMemoryBarrier *> p_to_clear;
1590 std::vector<VkImageMemoryBarrier> to_xfer;
1591 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001592
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001593 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001594 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001595 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001596 VK_IMAGE_LAYOUT_GENERAL,
1597 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001598 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001599 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001600 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001601 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1602 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001603 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001604 }
1605
1606 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001607
Tony Barbour8205d902015-04-16 15:59:00 -06001608 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1609 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 +00001610
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001611 vkCmdClearDepthStencil(cmd_.obj(),
1612 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001613 depth, stencil,
1614 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001615
Tony Barbour8205d902015-04-16 15:59:00 -06001616 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 +00001617
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001618 cmd_.end();
1619
1620 submit_and_done();
1621
1622 // cannot verify
1623 if (!img.transparent() && !img.copyable())
1624 return;
1625
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001626 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001627
1628 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1629 check_dst(img, checker);
1630 }
1631};
1632
Tony Barbour01999182015-04-09 12:58:51 -06001633TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001634{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001635 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001636 it != test_formats_.end(); it++) {
1637 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001638 if (it->format == VK_FORMAT_S8_UINT ||
1639 it->format == VK_FORMAT_D24_UNORM ||
1640 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1641 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001642 continue;
1643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001645 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001646 img_info.format = it->format;
1647 img_info.extent.width = 64;
1648 img_info.extent.height = 64;
1649 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001650 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001651
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001652 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001653 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001655
1656 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1657 }
1658}
1659
1660}; // namespace
1661
Chia-I Wucb67c652014-10-21 11:06:26 +08001662int main(int argc, char **argv)
1663{
Chia-I Wucb67c652014-10-21 11:06:26 +08001664 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001665
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001666 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001667
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001668 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001669
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001670 if (!environment->parse_args(argc, argv))
1671 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001672
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001673 ::testing::AddGlobalTestEnvironment(environment);
1674
1675 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001676}