blob: 756e1b3a6dad3a13c0ed1b09eb9bcbe020d1b2c0 [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
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060044 VkGpuSize 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
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060090 VkGpuSize 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) {
100 if (info_.format != VK_FMT_S8_UINT) {
101 region.imageSubresource.aspect = VK_IMAGE_ASPECT_DEPTH;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800102 regions_.push_back(region);
103 }
104
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600105 if (info_.format == VK_FMT_D16_UNORM_S8_UINT ||
106 info_.format == VK_FMT_D32_SFLOAT_S8_UINT ||
107 info_.format == VK_FMT_S8_UINT) {
108 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) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 const VkGpuSize 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{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600142 VkGpuSize offset = 0;
143 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
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600185VkGpuSize ImageChecker::buffer_size() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800186{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187 VkGpuSize 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;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600304 } format_table[VK_NUM_FMT] = {
305 [VK_FMT_UNDEFINED] = { 0, 0 },
306 [VK_FMT_R4G4_UNORM] = { 1, 2 },
307 [VK_FMT_R4G4_USCALED] = { 1, 2 },
308 [VK_FMT_R4G4B4A4_UNORM] = { 2, 4 },
309 [VK_FMT_R4G4B4A4_USCALED] = { 2, 4 },
310 [VK_FMT_R5G6B5_UNORM] = { 2, 3 },
311 [VK_FMT_R5G6B5_USCALED] = { 2, 3 },
312 [VK_FMT_R5G5B5A1_UNORM] = { 2, 4 },
313 [VK_FMT_R5G5B5A1_USCALED] = { 2, 4 },
314 [VK_FMT_R8_UNORM] = { 1, 1 },
315 [VK_FMT_R8_SNORM] = { 1, 1 },
316 [VK_FMT_R8_USCALED] = { 1, 1 },
317 [VK_FMT_R8_SSCALED] = { 1, 1 },
318 [VK_FMT_R8_UINT] = { 1, 1 },
319 [VK_FMT_R8_SINT] = { 1, 1 },
320 [VK_FMT_R8_SRGB] = { 1, 1 },
321 [VK_FMT_R8G8_UNORM] = { 2, 2 },
322 [VK_FMT_R8G8_SNORM] = { 2, 2 },
323 [VK_FMT_R8G8_USCALED] = { 2, 2 },
324 [VK_FMT_R8G8_SSCALED] = { 2, 2 },
325 [VK_FMT_R8G8_UINT] = { 2, 2 },
326 [VK_FMT_R8G8_SINT] = { 2, 2 },
327 [VK_FMT_R8G8_SRGB] = { 2, 2 },
328 [VK_FMT_R8G8B8_UNORM] = { 3, 3 },
329 [VK_FMT_R8G8B8_SNORM] = { 3, 3 },
330 [VK_FMT_R8G8B8_USCALED] = { 3, 3 },
331 [VK_FMT_R8G8B8_SSCALED] = { 3, 3 },
332 [VK_FMT_R8G8B8_UINT] = { 3, 3 },
333 [VK_FMT_R8G8B8_SINT] = { 3, 3 },
334 [VK_FMT_R8G8B8_SRGB] = { 3, 3 },
335 [VK_FMT_R8G8B8A8_UNORM] = { 4, 4 },
336 [VK_FMT_R8G8B8A8_SNORM] = { 4, 4 },
337 [VK_FMT_R8G8B8A8_USCALED] = { 4, 4 },
338 [VK_FMT_R8G8B8A8_SSCALED] = { 4, 4 },
339 [VK_FMT_R8G8B8A8_UINT] = { 4, 4 },
340 [VK_FMT_R8G8B8A8_SINT] = { 4, 4 },
341 [VK_FMT_R8G8B8A8_SRGB] = { 4, 4 },
342 [VK_FMT_R10G10B10A2_UNORM] = { 4, 4 },
343 [VK_FMT_R10G10B10A2_SNORM] = { 4, 4 },
344 [VK_FMT_R10G10B10A2_USCALED] = { 4, 4 },
345 [VK_FMT_R10G10B10A2_SSCALED] = { 4, 4 },
346 [VK_FMT_R10G10B10A2_UINT] = { 4, 4 },
347 [VK_FMT_R10G10B10A2_SINT] = { 4, 4 },
348 [VK_FMT_R16_UNORM] = { 2, 1 },
349 [VK_FMT_R16_SNORM] = { 2, 1 },
350 [VK_FMT_R16_USCALED] = { 2, 1 },
351 [VK_FMT_R16_SSCALED] = { 2, 1 },
352 [VK_FMT_R16_UINT] = { 2, 1 },
353 [VK_FMT_R16_SINT] = { 2, 1 },
354 [VK_FMT_R16_SFLOAT] = { 2, 1 },
355 [VK_FMT_R16G16_UNORM] = { 4, 2 },
356 [VK_FMT_R16G16_SNORM] = { 4, 2 },
357 [VK_FMT_R16G16_USCALED] = { 4, 2 },
358 [VK_FMT_R16G16_SSCALED] = { 4, 2 },
359 [VK_FMT_R16G16_UINT] = { 4, 2 },
360 [VK_FMT_R16G16_SINT] = { 4, 2 },
361 [VK_FMT_R16G16_SFLOAT] = { 4, 2 },
362 [VK_FMT_R16G16B16_UNORM] = { 6, 3 },
363 [VK_FMT_R16G16B16_SNORM] = { 6, 3 },
364 [VK_FMT_R16G16B16_USCALED] = { 6, 3 },
365 [VK_FMT_R16G16B16_SSCALED] = { 6, 3 },
366 [VK_FMT_R16G16B16_UINT] = { 6, 3 },
367 [VK_FMT_R16G16B16_SINT] = { 6, 3 },
368 [VK_FMT_R16G16B16_SFLOAT] = { 6, 3 },
369 [VK_FMT_R16G16B16A16_UNORM] = { 8, 4 },
370 [VK_FMT_R16G16B16A16_SNORM] = { 8, 4 },
371 [VK_FMT_R16G16B16A16_USCALED] = { 8, 4 },
372 [VK_FMT_R16G16B16A16_SSCALED] = { 8, 4 },
373 [VK_FMT_R16G16B16A16_UINT] = { 8, 4 },
374 [VK_FMT_R16G16B16A16_SINT] = { 8, 4 },
375 [VK_FMT_R16G16B16A16_SFLOAT] = { 8, 4 },
376 [VK_FMT_R32_UINT] = { 4, 1 },
377 [VK_FMT_R32_SINT] = { 4, 1 },
378 [VK_FMT_R32_SFLOAT] = { 4, 1 },
379 [VK_FMT_R32G32_UINT] = { 8, 2 },
380 [VK_FMT_R32G32_SINT] = { 8, 2 },
381 [VK_FMT_R32G32_SFLOAT] = { 8, 2 },
382 [VK_FMT_R32G32B32_UINT] = { 12, 3 },
383 [VK_FMT_R32G32B32_SINT] = { 12, 3 },
384 [VK_FMT_R32G32B32_SFLOAT] = { 12, 3 },
385 [VK_FMT_R32G32B32A32_UINT] = { 16, 4 },
386 [VK_FMT_R32G32B32A32_SINT] = { 16, 4 },
387 [VK_FMT_R32G32B32A32_SFLOAT] = { 16, 4 },
388 [VK_FMT_R64_SFLOAT] = { 8, 1 },
389 [VK_FMT_R64G64_SFLOAT] = { 16, 2 },
390 [VK_FMT_R64G64B64_SFLOAT] = { 24, 3 },
391 [VK_FMT_R64G64B64A64_SFLOAT] = { 32, 4 },
392 [VK_FMT_R11G11B10_UFLOAT] = { 4, 3 },
393 [VK_FMT_R9G9B9E5_UFLOAT] = { 4, 3 },
394 [VK_FMT_D16_UNORM] = { 2, 1 },
395 [VK_FMT_D24_UNORM] = { 3, 1 },
396 [VK_FMT_D32_SFLOAT] = { 4, 1 },
397 [VK_FMT_S8_UINT] = { 1, 1 },
398 [VK_FMT_D16_UNORM_S8_UINT] = { 3, 2 },
399 [VK_FMT_D24_UNORM_S8_UINT] = { 4, 2 },
400 [VK_FMT_D32_SFLOAT_S8_UINT] = { 4, 2 },
401 [VK_FMT_BC1_RGB_UNORM] = { 8, 4 },
402 [VK_FMT_BC1_RGB_SRGB] = { 8, 4 },
403 [VK_FMT_BC1_RGBA_UNORM] = { 8, 4 },
404 [VK_FMT_BC1_RGBA_SRGB] = { 8, 4 },
405 [VK_FMT_BC2_UNORM] = { 16, 4 },
406 [VK_FMT_BC2_SRGB] = { 16, 4 },
407 [VK_FMT_BC3_UNORM] = { 16, 4 },
408 [VK_FMT_BC3_SRGB] = { 16, 4 },
409 [VK_FMT_BC4_UNORM] = { 8, 4 },
410 [VK_FMT_BC4_SNORM] = { 8, 4 },
411 [VK_FMT_BC5_UNORM] = { 16, 4 },
412 [VK_FMT_BC5_SNORM] = { 16, 4 },
413 [VK_FMT_BC6H_UFLOAT] = { 16, 4 },
414 [VK_FMT_BC6H_SFLOAT] = { 16, 4 },
415 [VK_FMT_BC7_UNORM] = { 16, 4 },
416 [VK_FMT_BC7_SRGB] = { 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700417 // TODO: Initialize remaining compressed formats.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 [VK_FMT_ETC2_R8G8B8_UNORM] = { 0, 0 },
419 [VK_FMT_ETC2_R8G8B8_SRGB] = { 0, 0 },
420 [VK_FMT_ETC2_R8G8B8A1_UNORM] = { 0, 0 },
421 [VK_FMT_ETC2_R8G8B8A1_SRGB] = { 0, 0 },
422 [VK_FMT_ETC2_R8G8B8A8_UNORM] = { 0, 0 },
423 [VK_FMT_ETC2_R8G8B8A8_SRGB] = { 0, 0 },
424 [VK_FMT_EAC_R11_UNORM] = { 0, 0 },
425 [VK_FMT_EAC_R11_SNORM] = { 0, 0 },
426 [VK_FMT_EAC_R11G11_UNORM] = { 0, 0 },
427 [VK_FMT_EAC_R11G11_SNORM] = { 0, 0 },
428 [VK_FMT_ASTC_4x4_UNORM] = { 0, 0 },
429 [VK_FMT_ASTC_4x4_SRGB] = { 0, 0 },
430 [VK_FMT_ASTC_5x4_UNORM] = { 0, 0 },
431 [VK_FMT_ASTC_5x4_SRGB] = { 0, 0 },
432 [VK_FMT_ASTC_5x5_UNORM] = { 0, 0 },
433 [VK_FMT_ASTC_5x5_SRGB] = { 0, 0 },
434 [VK_FMT_ASTC_6x5_UNORM] = { 0, 0 },
435 [VK_FMT_ASTC_6x5_SRGB] = { 0, 0 },
436 [VK_FMT_ASTC_6x6_UNORM] = { 0, 0 },
437 [VK_FMT_ASTC_6x6_SRGB] = { 0, 0 },
438 [VK_FMT_ASTC_8x5_UNORM] = { 0, 0 },
439 [VK_FMT_ASTC_8x5_SRGB] = { 0, 0 },
440 [VK_FMT_ASTC_8x6_UNORM] = { 0, 0 },
441 [VK_FMT_ASTC_8x6_SRGB] = { 0, 0 },
442 [VK_FMT_ASTC_8x8_UNORM] = { 0, 0 },
443 [VK_FMT_ASTC_8x8_SRGB] = { 0, 0 },
444 [VK_FMT_ASTC_10x5_UNORM] = { 0, 0 },
445 [VK_FMT_ASTC_10x5_SRGB] = { 0, 0 },
446 [VK_FMT_ASTC_10x6_UNORM] = { 0, 0 },
447 [VK_FMT_ASTC_10x6_SRGB] = { 0, 0 },
448 [VK_FMT_ASTC_10x8_UNORM] = { 0, 0 },
449 [VK_FMT_ASTC_10x8_SRGB] = { 0, 0 },
450 [VK_FMT_ASTC_10x10_UNORM] = { 0, 0 },
451 [VK_FMT_ASTC_10x10_SRGB] = { 0, 0 },
452 [VK_FMT_ASTC_12x10_UNORM] = { 0, 0 },
453 [VK_FMT_ASTC_12x10_SRGB] = { 0, 0 },
454 [VK_FMT_ASTC_12x12_UNORM] = { 0, 0 },
455 [VK_FMT_ASTC_12x12_SRGB] = { 0, 0 },
456 [VK_FMT_B4G4R4A4_UNORM] = { 2, 4 },
457 [VK_FMT_B5G5R5A1_UNORM] = { 2, 4 },
458 [VK_FMT_B5G6R5_UNORM] = { 2, 3 },
459 [VK_FMT_B5G6R5_USCALED] = { 2, 3 },
460 [VK_FMT_B8G8R8_UNORM] = { 3, 3 },
461 [VK_FMT_B8G8R8_SNORM] = { 3, 3 },
462 [VK_FMT_B8G8R8_USCALED] = { 3, 3 },
463 [VK_FMT_B8G8R8_SSCALED] = { 3, 3 },
464 [VK_FMT_B8G8R8_UINT] = { 3, 3 },
465 [VK_FMT_B8G8R8_SINT] = { 3, 3 },
466 [VK_FMT_B8G8R8_SRGB] = { 3, 3 },
467 [VK_FMT_B8G8R8A8_UNORM] = { 4, 4 },
468 [VK_FMT_B8G8R8A8_SNORM] = { 4, 4 },
469 [VK_FMT_B8G8R8A8_USCALED] = { 4, 4 },
470 [VK_FMT_B8G8R8A8_SSCALED] = { 4, 4 },
471 [VK_FMT_B8G8R8A8_UINT] = { 4, 4 },
472 [VK_FMT_B8G8R8A8_SINT] = { 4, 4 },
473 [VK_FMT_B8G8R8A8_SRGB] = { 4, 4 },
474 [VK_FMT_B10G10R10A2_UNORM] = { 4, 4 },
475 [VK_FMT_B10G10R10A2_SNORM] = { 4, 4 },
476 [VK_FMT_B10G10R10A2_USCALED] = { 4, 4 },
477 [VK_FMT_B10G10R10A2_SSCALED] = { 4, 4 },
478 [VK_FMT_B10G10R10A2_UINT] = { 4, 4 },
479 [VK_FMT_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 {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600517 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800518 queue_.wait();
519 mem_refs_.clear();
520 return true;
521 }
522
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600523 void add_memory_ref(const vk_testing::Object &obj)
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800524 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600525 const std::vector<VkGpuMemory> mems = obj.memories();
526 for (std::vector<VkGpuMemory>::const_iterator it = mems.begin(); it != mems.end(); it++) {
527 std::vector<VkGpuMemory>::iterator ref;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800528 for (ref = mem_refs_.begin(); ref != mem_refs_.end(); ref++) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600529 if (*ref == *it)
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800530 break;
531 }
532
533 if (ref == mem_refs_.end()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600534 mem_refs_.push_back(*it);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800535 }
536 }
537 }
538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539 vk_testing::Device &dev_;
540 vk_testing::Queue &queue_;
541 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800542
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600543 std::vector<VkGpuMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800544};
545
Tony Barbour01999182015-04-09 12:58:51 -0600546typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800547
Tony Barbour01999182015-04-09 12:58:51 -0600548TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800549{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600550 vk_testing::Buffer buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800551
552 buf.init(dev_, 20);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600553 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800554
555 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600556 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
557 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800558 cmd_.end();
559
560 submit_and_done();
561
562 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
563 EXPECT_EQ(0x11111111, data[0]);
564 EXPECT_EQ(0x22222222, data[1]);
565 EXPECT_EQ(0x22222222, data[2]);
566 EXPECT_EQ(0x22222222, data[3]);
567 EXPECT_EQ(0x22222222, data[4]);
568 buf.unmap();
569}
570
Tony Barbour01999182015-04-09 12:58:51 -0600571TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800572{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600573 const VkGpuSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600574 vk_testing::Buffer buf;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800575
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800576 buf.init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600577 add_memory_ref(buf);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800578
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800579 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
581 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800582 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800583
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800584 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800585
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800586 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587 VkGpuSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800588 for (offset = 0; offset < size / 2; offset += 4)
589 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
590 for (; offset < size; offset += 4)
591 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
592 buf.unmap();
593}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800594
Tony Barbour01999182015-04-09 12:58:51 -0600595TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800596{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600597 vk_testing::Buffer buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800598
599 buf.init(dev_, 64);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600600 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800601
602 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600603 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
604 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800605 cmd_.end();
606
607 submit_and_done();
608
609 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600610 VkGpuSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800611 for (offset = 0; offset < 32; offset += 4)
612 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
613 for (; offset < 64; offset += 4)
614 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
615 buf.unmap();
616}
617
Tony Barbour01999182015-04-09 12:58:51 -0600618TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800619{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 vk_testing::Buffer bufs[9];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600621 VkGpuSize size = 4;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800622
623 cmd_.begin();
624 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
625 bufs[i].init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600626 add_memory_ref(bufs[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800628 size <<= 1;
629 }
630 cmd_.end();
631
632 submit_and_done();
633
634 size = 4;
635 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
636 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637 VkGpuSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800638 for (offset = 0; offset < size; offset += 4)
639 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
640 "Offset is: " << offset;
641 bufs[i].unmap();
642
643 size <<= 1;
644 }
645}
646
Tony Barbour01999182015-04-09 12:58:51 -0600647typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800648
Tony Barbour01999182015-04-09 12:58:51 -0600649TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800650{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600651 vk_testing::Buffer src, dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800652
653 src.init(dev_, 4);
654 uint32_t *data = static_cast<uint32_t *>(src.map());
655 data[0] = 0x11111111;
656 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600657 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800658
659 dst.init(dev_, 4);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600660 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800661
662 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600663 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800664 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800666 cmd_.end();
667
668 submit_and_done();
669
670 data = static_cast<uint32_t *>(dst.map());
671 EXPECT_EQ(0x11111111, data[0]);
672 dst.unmap();
673}
674
Tony Barbour01999182015-04-09 12:58:51 -0600675TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800676{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600677 const VkGpuSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 vk_testing::Buffer src, dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800679
680 src.init(dev_, size);
681 uint32_t *data = static_cast<uint32_t *>(src.map());
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600682 VkGpuSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800683 for (offset = 0; offset < size; offset += 4)
684 data[offset / 4] = offset;
685 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600686 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800687
688 dst.init(dev_, size);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600689 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800690
691 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600692 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800693 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600694 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800695 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800696
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800697 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800698
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800699 data = static_cast<uint32_t *>(dst.map());
700 for (offset = 0; offset < size; offset += 4)
701 EXPECT_EQ(offset, data[offset / 4]);
702 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800703}
704
Tony Barbour01999182015-04-09 12:58:51 -0600705TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800706{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800708 /* well aligned */
709 { 0, 0, 256 },
710 { 0, 256, 128 },
711 { 0, 384, 64 },
712 { 0, 448, 32 },
713 { 0, 480, 16 },
714 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800715
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800716 /* ill aligned */
717 { 7, 510, 16 },
718 { 16, 530, 13 },
719 { 32, 551, 16 },
720 { 45, 570, 15 },
721 { 50, 590, 1 },
722 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 vk_testing::Buffer src, dst;
Chia-I Wucb67c652014-10-21 11:06:26 +0800724
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800725 src.init(dev_, 256);
726 uint8_t *data = static_cast<uint8_t *>(src.map());
727 for (int i = 0; i < 256; i++)
728 data[i] = i;
729 src.unmap();
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600730 add_memory_ref(src);
Chia-I Wucb67c652014-10-21 11:06:26 +0800731
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800732 dst.init(dev_, 1024);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600733 add_memory_ref(dst);
Chia-I Wucb67c652014-10-21 11:06:26 +0800734
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800735 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800737 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800738
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800739 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800740
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800741 data = static_cast<uint8_t *>(dst.map());
742 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600743 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800744
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800745 for (int j = 0; j < r.copySize; j++) {
746 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
747 "Region is: " << i << "\n" <<
748 "Offset is: " << r.destOffset + j;
749 }
750 }
751 dst.unmap();
752}
Chia-I Wucb67c652014-10-21 11:06:26 +0800753
Tony Barbour01999182015-04-09 12:58:51 -0600754TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800755{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600756 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757 VkEventCreateInfo event_info;
758 VkEvent event;
759 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000760 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 VkResult err;
Mike Stroyan55658c22014-12-04 11:08:39 +0000762
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000764 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600765 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600766 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600767 // VkFlags flags; // Reserved
768 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000769 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600770 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000771
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600772 err = vkCreateEvent(dev_.obj(), &event_info, &event);
773 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000774
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 err = vkGetObjectInfo(event, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Mike Stroyan55658c22014-12-04 11:08:39 +0000776 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600777 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 // VkResult VKAPI vkAllocMemory(
780 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600781 // const VkMemoryAllocInfo* pAllocInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600782 // VkGpuMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600783 VkMemoryAllocInfo mem_info;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600784 VkGpuMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000785
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600786 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000787
Mike Stroyan55658c22014-12-04 11:08:39 +0000788 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600789 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000790 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600791 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
792 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
793 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
794 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000795
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500796 err = vkQueueBindObjectMemory(queue_.obj(), event, 0, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600797 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000798
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600799 err = vkResetEvent(event);
800 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800801
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800802 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
803 bufs[i].init(dev_, 4);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600804 add_memory_ref(bufs[i]);
Chia-I Wucb67c652014-10-21 11:06:26 +0800805
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800806 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
807 data[0] = 0x22222222 * (i + 1);
808 bufs[i].unmap();
809 }
810
811 cmd_.begin();
812
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600813 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800814 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600815 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600816 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000818
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600819 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
820 VkPipelineBarrier pipeline_barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600821 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +0000822 pipeline_barrier.eventCount = 1;
823 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600824 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +0000825 pipeline_barrier.memBarrierCount = 1;
Mark Lobodzinski628a8a52015-02-02 11:55:52 -0600826 pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600827 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800828
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600829 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800830 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000832
833 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600834 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600835 pmemory_barrier = &memory_barrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600836 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +0000837 pipeline_barrier.eventCount = 1;
838 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600839 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +0000840 pipeline_barrier.memBarrierCount = 1;
Mark Lobodzinski628a8a52015-02-02 11:55:52 -0600841 pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800843
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600844 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000845
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600846 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
847 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000848 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600849 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000850
851 // Additional commands could go into the buffer here before the wait.
852
853 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600854 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_CPU_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600855 pmemory_barrier = &memory_barrier;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600856 VkEventWaitInfo wait_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 wait_info.sType = VK_STRUCTURE_TYPE_EVENT_WAIT_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000858 wait_info.eventCount = 1;
859 wait_info.pEvents = &event;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600860 wait_info.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +0000861 wait_info.memBarrierCount = 1;
Mark Lobodzinski628a8a52015-02-02 11:55:52 -0600862 wait_info.ppMemBarriers = (const void **)&pmemory_barrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 vkCmdWaitEvents(cmd_.obj(), &wait_info);
Mike Stroyan55658c22014-12-04 11:08:39 +0000864
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800865 cmd_.end();
866
867 submit_and_done();
868
869 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
870 EXPECT_EQ(0x11111111, data[0]);
871 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000872
873 // All done with event memory, clean up
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500874 err = vkQueueBindObjectMemory(queue_.obj(), event, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600875 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000876
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600877 err = vkDestroyObject(event);
878 ASSERT_VK_SUCCESS(err);
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600879
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600880 err = vkFreeMemory(event_mem);
881 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800882}
883
Tony Barbour01999182015-04-09 12:58:51 -0600884class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800885protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600886 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800887 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600888 first_linear_format_ = VK_FMT_UNDEFINED;
889 first_optimal_format_ = VK_FMT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800890
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600891 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800892 it != dev_.formats().end(); it++) {
893 if (it->features & features) {
894 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800895
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600896 if (it->tiling == VK_LINEAR_TILING &&
897 first_linear_format_ == VK_FMT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800898 first_linear_format_ = it->format;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600899 if (it->tiling == VK_OPTIMAL_TILING &&
900 first_optimal_format_ == VK_FMT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800901 first_optimal_format_ = it->format;
902 }
903 }
904 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800905
Chia-I Wu9feab842014-12-22 13:19:08 +0800906 void init_test_formats()
907 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600908 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800909 }
910
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600911 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800912 {
913 if (img.transparent()) {
914 checker.fill(img);
915 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800916 }
917
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800918 ASSERT_EQ(true, img.copyable());
919
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600920 vk_testing::Buffer in_buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800921 in_buf.init(dev_, checker.buffer_size());
922 checker.fill(in_buf);
923
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600924 add_memory_ref(in_buf);
925 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800926
927 // copy in and tile
928 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
930 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800931 checker.regions().size(), &checker.regions()[0]);
932 cmd_.end();
933
934 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800935 }
936
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600937 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800938 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800939 if (img.transparent()) {
940 DO(checker.check(img));
941 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800942 }
943
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800944 ASSERT_EQ(true, img.copyable());
945
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600946 vk_testing::Buffer out_buf;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800947 out_buf.init(dev_, checker.buffer_size());
948
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600949 add_memory_ref(img);
950 add_memory_ref(out_buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800951
952 // copy out and linearize
953 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600954 vkCmdCopyImageToBuffer(cmd_.obj(),
955 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600956 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800957 checker.regions().size(), &checker.regions()[0]);
958 cmd_.end();
959
960 submit_and_done();
961
962 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800963 }
964
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600965 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600966 VkFormat first_linear_format_;
967 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800968};
969
Tony Barbour01999182015-04-09 12:58:51 -0600970class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800971protected:
972 virtual void SetUp()
973 {
Tony Barbour01999182015-04-09 12:58:51 -0600974 VkCmdBlitTest::SetUp();
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600975 init_test_formats(VK_FORMAT_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800976 ASSERT_NE(true, test_formats_.empty());
977 }
978
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600979 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800980 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600981 vk_testing::Buffer buf;
982 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800983
984 buf.init(dev_, checker.buffer_size());
985 checker.fill(buf);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600986 add_memory_ref(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800987
988 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600989 add_memory_ref(img);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800990
991 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600992 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600993 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600994 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800995 checker.regions().size(), &checker.regions()[0]);
996 cmd_.end();
997
998 submit_and_done();
999
1000 check_dst(img, checker);
1001 }
1002
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001003 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001004 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001005 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001006 test_copy_memory_to_image(img_info, checker);
1007 }
1008
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001009 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001010 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001011 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001012 test_copy_memory_to_image(img_info, checker);
1013 }
1014};
1015
Tony Barbour01999182015-04-09 12:58:51 -06001016TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001017{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001019 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001020
1021 // not sure what to do here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001022 if (it->format == VK_FMT_UNDEFINED ||
1023 (it->format >= VK_FMT_B8G8R8_UNORM &&
1024 it->format <= VK_FMT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001025 continue;
1026
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001027 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001028 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001029 img_info.format = it->format;
1030 img_info.extent.width = 64;
1031 img_info.extent.height = 64;
1032 img_info.tiling = it->tiling;
1033
1034 test_copy_memory_to_image(img_info);
1035 }
Chia-I Wu86822632014-11-22 15:09:42 +08001036}
1037
Tony Barbour01999182015-04-09 12:58:51 -06001038class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001039protected:
1040 virtual void SetUp()
1041 {
Tony Barbour01999182015-04-09 12:58:51 -06001042 VkCmdBlitTest::SetUp();
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001043 init_test_formats(VK_FORMAT_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001044 ASSERT_NE(true, test_formats_.empty());
1045 }
1046
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001048 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001049 vk_testing::Image img;
1050 vk_testing::Buffer buf;
Chia-I Wu830fb332014-12-13 15:28:20 +08001051
1052 img.init(dev_, img_info);
1053 fill_src(img, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001054 add_memory_ref(img);
Chia-I Wu830fb332014-12-13 15:28:20 +08001055
1056 buf.init(dev_, checker.buffer_size());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001057 add_memory_ref(buf);
Chia-I Wu830fb332014-12-13 15:28:20 +08001058
1059 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001060 vkCmdCopyImageToBuffer(cmd_.obj(),
1061 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001062 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001063 checker.regions().size(), &checker.regions()[0]);
1064 cmd_.end();
1065
1066 submit_and_done();
1067
1068 checker.check(buf);
1069 }
1070
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001071 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001072 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001073 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001074 test_copy_image_to_memory(img_info, checker);
1075 }
1076
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001077 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001078 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001079 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001080 test_copy_image_to_memory(img_info, checker);
1081 }
1082};
1083
Tony Barbour01999182015-04-09 12:58:51 -06001084TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001085{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001086 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001087 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001088
1089 // not sure what to do here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001090 if (it->format == VK_FMT_UNDEFINED ||
1091 (it->format >= VK_FMT_B8G8R8_UNORM &&
1092 it->format <= VK_FMT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001093 continue;
1094
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001095 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001096 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001097 img_info.format = it->format;
1098 img_info.extent.width = 64;
1099 img_info.extent.height = 64;
1100 img_info.tiling = it->tiling;
1101
1102 test_copy_image_to_memory(img_info);
1103 }
1104}
1105
Tony Barbour01999182015-04-09 12:58:51 -06001106class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001107protected:
1108 virtual void SetUp()
1109 {
Tony Barbour01999182015-04-09 12:58:51 -06001110 VkCmdBlitTest::SetUp();
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001111 init_test_formats(VK_FORMAT_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001112 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001113 }
1114
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1116 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001117 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 // convert VkImageCopy to two sets of VkBufferImageCopy
1119 std::vector<VkBufferImageCopy> src_regions, dst_regions;
1120 VkGpuSize src_offset = 0, dst_offset = 0;
1121 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1122 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001123
Chia-I Wu714df452015-01-01 07:55:04 +08001124 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001125 src_region.imageSubresource = it->srcSubresource;
1126 src_region.imageOffset = it->srcOffset;
1127 src_region.imageExtent = it->extent;
1128 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001129
Chia-I Wu714df452015-01-01 07:55:04 +08001130 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001131 dst_region.imageSubresource = it->destSubresource;
1132 dst_region.imageOffset = it->destOffset;
1133 dst_region.imageExtent = it->extent;
1134 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001135
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001136 const VkGpuSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001137 src_offset += vk_testing::get_format_size(src_info.format) * size;
1138 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001139 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001140
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001141 vk_testing::ImageChecker src_checker(src_info, src_regions);
1142 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001143
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001144 vk_testing::Image src;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001145 src.init(dev_, src_info);
1146 fill_src(src, src_checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001147 add_memory_ref(src);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001148
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001149 vk_testing::Image dst;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001150 dst.init(dev_, dst_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001151 add_memory_ref(dst);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001152
1153 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001154 vkCmdCopyImage(cmd_.obj(),
1155 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1156 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001157 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001158 cmd_.end();
1159
1160 submit_and_done();
1161
1162 check_dst(dst, dst_checker);
1163 }
1164};
1165
Tony Barbour01999182015-04-09 12:58:51 -06001166TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001167{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001168 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001169 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001170
1171 // not sure what to do here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001172 if (it->format == VK_FMT_UNDEFINED ||
1173 (it->format >= VK_FMT_B8G8R8_UNORM &&
1174 it->format <= VK_FMT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001175 continue;
1176
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001177 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001178 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001179 img_info.format = it->format;
1180 img_info.extent.width = 64;
1181 img_info.extent.height = 64;
1182 img_info.tiling = it->tiling;
1183
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001184 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001185 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001186 copy.destSubresource = copy.srcSubresource;
1187 copy.extent = img_info.extent;
1188
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001189 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001190 }
1191}
1192
Tony Barbour01999182015-04-09 12:58:51 -06001193class VkCmdCloneImageDataTest : public VkCmdBlitImageTest {
Chia-I Wub75939f2014-12-22 14:46:56 +08001194protected:
1195 virtual void SetUp()
1196 {
Tony Barbour01999182015-04-09 12:58:51 -06001197 VkCmdBlitTest::SetUp();
Chia-I Wub75939f2014-12-22 14:46:56 +08001198 init_test_formats();
1199 ASSERT_NE(true, test_formats_.empty());
1200 }
1201
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001202 void test_clone_image_data(const VkImageCreateInfo &img_info)
Chia-I Wub75939f2014-12-22 14:46:56 +08001203 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001204 vk_testing::ImageChecker checker(img_info);
1205 vk_testing::Image src, dst;
Chia-I Wub75939f2014-12-22 14:46:56 +08001206
1207 src.init(dev_, img_info);
1208 if (src.transparent() || src.copyable())
1209 fill_src(src, checker);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001210 add_memory_ref(src);
Chia-I Wub75939f2014-12-22 14:46:56 +08001211
1212 dst.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001213 add_memory_ref(dst);
Chia-I Wub75939f2014-12-22 14:46:56 +08001214
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001215 const VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wub75939f2014-12-22 14:46:56 +08001216
1217 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001218 vkCmdCloneImageData(cmd_.obj(), src.obj(), layout, dst.obj(), layout);
Chia-I Wub75939f2014-12-22 14:46:56 +08001219 cmd_.end();
1220
1221 submit_and_done();
1222
1223 // cannot verify
1224 if (!dst.transparent() && !dst.copyable())
1225 return;
1226
1227 check_dst(dst, checker);
1228 }
1229};
1230
Tony Barbour01999182015-04-09 12:58:51 -06001231TEST_F(VkCmdCloneImageDataTest, Basic)
Chia-I Wub75939f2014-12-22 14:46:56 +08001232{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001233 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wub75939f2014-12-22 14:46:56 +08001234 it != test_formats_.end(); it++) {
1235 // not sure what to do here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001236 if (it->format == VK_FMT_UNDEFINED ||
1237 (it->format >= VK_FMT_R32G32B32_UINT &&
1238 it->format <= VK_FMT_R32G32B32_SFLOAT) ||
1239 (it->format >= VK_FMT_B8G8R8_UNORM &&
1240 it->format <= VK_FMT_B8G8R8_SRGB) ||
1241 (it->format >= VK_FMT_BC1_RGB_UNORM &&
1242 it->format <= VK_FMT_ASTC_12x12_SRGB) ||
1243 (it->format >= VK_FMT_D16_UNORM &&
1244 it->format <= VK_FMT_D32_SFLOAT_S8_UINT) ||
1245 it->format == VK_FMT_R64G64B64_SFLOAT ||
1246 it->format == VK_FMT_R64G64B64A64_SFLOAT)
Chia-I Wub75939f2014-12-22 14:46:56 +08001247 continue;
1248
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 img_info.imageType = VK_IMAGE_2D;
Chia-I Wub75939f2014-12-22 14:46:56 +08001251 img_info.format = it->format;
1252 img_info.extent.width = 64;
1253 img_info.extent.height = 64;
1254 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001255 img_info.flags = VK_IMAGE_CREATE_CLONEABLE_BIT;
Chia-I Wub75939f2014-12-22 14:46:56 +08001256
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001257 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001258 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001259 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wub75939f2014-12-22 14:46:56 +08001260
1261 test_clone_image_data(img_info);
1262 }
1263}
1264
Tony Barbour01999182015-04-09 12:58:51 -06001265class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001266protected:
Tony Barbour01999182015-04-09 12:58:51 -06001267 VkCmdClearColorImageTest() : test_raw_(false) {}
1268 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001269
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001270 virtual void SetUp()
1271 {
Tony Barbour01999182015-04-09 12:58:51 -06001272 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001273
1274 if (test_raw_)
1275 init_test_formats();
1276 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001277 init_test_formats(VK_FORMAT_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001278
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001279 ASSERT_NE(true, test_formats_.empty());
1280 }
1281
Chia-I Wu9feab842014-12-22 13:19:08 +08001282 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001283 float color[4];
1284 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001285 };
1286
1287 bool test_raw_;
1288
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001289 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001290 {
1291 std::vector<uint8_t> raw;
1292
1293 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001294 switch (format) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001295 case VK_FMT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001296 raw.push_back(color[0] * 255.0f);
1297 raw.push_back(color[1] * 255.0f);
1298 raw.push_back(color[2] * 255.0f);
1299 raw.push_back(color[3] * 255.0f);
1300 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001301 case VK_FMT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001302 raw.push_back(color[2] * 255.0f);
1303 raw.push_back(color[1] * 255.0f);
1304 raw.push_back(color[0] * 255.0f);
1305 raw.push_back(color[3] * 255.0f);
1306 break;
1307 default:
1308 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001309 }
1310
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001311 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001312 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001313
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001314 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001315 {
1316 std::vector<uint8_t> raw;
1317
1318 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001319 switch (format) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001320 case VK_FMT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001321 raw.push_back(static_cast<uint8_t>(color[0]));
1322 raw.push_back(static_cast<uint8_t>(color[1]));
1323 raw.push_back(static_cast<uint8_t>(color[2]));
1324 raw.push_back(static_cast<uint8_t>(color[3]));
1325 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 case VK_FMT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001327 raw.push_back(static_cast<uint8_t>(color[2]));
1328 raw.push_back(static_cast<uint8_t>(color[1]));
1329 raw.push_back(static_cast<uint8_t>(color[0]));
1330 raw.push_back(static_cast<uint8_t>(color[3]));
1331 break;
1332 default:
1333 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001334 }
1335
1336 return raw;
1337 }
1338
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001339 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001340 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001341 if (color.useRawValue)
1342 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001343 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001344 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001345 }
1346
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001347 void test_clear_color_image(const VkImageCreateInfo &img_info,
1348 const VkClearColor &clear_color,
1349 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001350 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001351 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001352 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001353 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1356 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1357 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1358 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001359 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001360 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001361 VK_MEMORY_INPUT_CPU_READ_BIT |
1362 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1363 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1364 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1365 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1366 VK_MEMORY_INPUT_SHADER_READ_BIT |
1367 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1368 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001369 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001370
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371 std::vector<VkImageMemoryBarrier> to_clear;
1372 std::vector<VkImageMemoryBarrier *> p_to_clear;
1373 std::vector<VkImageMemoryBarrier> to_xfer;
1374 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001375
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001376 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001377 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001378 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001379 VK_IMAGE_LAYOUT_GENERAL,
1380 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001381 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001382 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001383 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001384 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1385 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001386 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001387 }
1388
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001389 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001390
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001391 VkPipeEvent set_events[] = { VK_PIPE_EVENT_GPU_COMMANDS_COMPLETE };
1392 VkPipelineBarrier pipeline_barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001393 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +00001394 pipeline_barrier.eventCount = 1;
1395 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001396 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +00001397 pipeline_barrier.memBarrierCount = to_clear.size();
Mark Lobodzinski628a8a52015-02-02 11:55:52 -06001398 pipeline_barrier.ppMemBarriers = (const void **)&p_to_clear[0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001399 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +00001400
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001401 vkCmdClearColorImage(cmd_.obj(),
1402 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001403 clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001404
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001405 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +00001406 pipeline_barrier.eventCount = 1;
1407 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +00001409 pipeline_barrier.memBarrierCount = to_xfer.size();
Mark Lobodzinski628a8a52015-02-02 11:55:52 -06001410 pipeline_barrier.ppMemBarriers = (const void **)&p_to_xfer[0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001411 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Chia-I Wu9feab842014-12-22 13:19:08 +08001412
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001413 cmd_.end();
1414
1415 submit_and_done();
1416
1417 // cannot verify
1418 if (!img.transparent() && !img.copyable())
1419 return;
1420
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001421 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001422
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001423 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001424 if (solid_pattern.empty())
1425 return;
1426
1427 checker.set_solid_pattern(solid_pattern);
1428 check_dst(img, checker);
1429 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001430
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001431 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001432 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001433 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001434 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001435 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001436 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001437 test_clear_color_image(img_info, c, ranges);
1438 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001439};
1440
Tony Barbour01999182015-04-09 12:58:51 -06001441TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001442{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001443 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001444 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001445 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001446
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001447 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001448 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001449 img_info.format = it->format;
1450 img_info.extent.width = 64;
1451 img_info.extent.height = 64;
1452 img_info.tiling = it->tiling;
1453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001454 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001455 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001456 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001457
1458 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001459 }
1460}
1461
Tony Barbour01999182015-04-09 12:58:51 -06001462class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001463protected:
Tony Barbour01999182015-04-09 12:58:51 -06001464 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001466 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001467 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001468 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001469 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001470 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001471 c.useRawValue = true;
1472 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001473 test_clear_color_image(img_info, c, ranges);
1474 }
1475};
1476
Tony Barbour01999182015-04-09 12:58:51 -06001477TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001478{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001479 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001480 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001481 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001482
1483 // not sure what to do here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001484 if (it->format == VK_FMT_UNDEFINED ||
1485 (it->format >= VK_FMT_R8G8B8_UNORM &&
1486 it->format <= VK_FMT_R8G8B8_SRGB) ||
1487 (it->format >= VK_FMT_B8G8R8_UNORM &&
1488 it->format <= VK_FMT_B8G8R8_SRGB) ||
1489 (it->format >= VK_FMT_R16G16B16_UNORM &&
1490 it->format <= VK_FMT_R16G16B16_SFLOAT) ||
1491 (it->format >= VK_FMT_R32G32B32_UINT &&
1492 it->format <= VK_FMT_R32G32B32_SFLOAT) ||
1493 it->format == VK_FMT_R64G64B64_SFLOAT ||
1494 it->format == VK_FMT_R64G64B64A64_SFLOAT ||
1495 (it->format >= VK_FMT_D16_UNORM &&
1496 it->format <= VK_FMT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001497 continue;
1498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001499 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001500 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001501 img_info.format = it->format;
1502 img_info.extent.width = 64;
1503 img_info.extent.height = 64;
1504 img_info.tiling = it->tiling;
1505
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001506 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001507 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001508 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001509
1510 test_clear_color_image_raw(img_info, color, ranges);
1511 }
1512}
1513
Tony Barbour01999182015-04-09 12:58:51 -06001514class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001515protected:
1516 virtual void SetUp()
1517 {
Tony Barbour01999182015-04-09 12:58:51 -06001518 VkCmdBlitTest::SetUp();
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001519 init_test_formats(VK_FORMAT_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001520 ASSERT_NE(true, test_formats_.empty());
1521 }
1522
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001523 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001524 {
1525 std::vector<uint8_t> raw;
1526
1527 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001528 switch (format) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001529 case VK_FMT_D16_UNORM:
1530 case VK_FMT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001531 {
1532 const uint16_t unorm = depth * 65535.0f;
1533 raw.push_back(unorm & 0xff);
1534 raw.push_back(unorm >> 8);
1535 }
1536 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001537 case VK_FMT_D32_SFLOAT:
1538 case VK_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001539 {
1540 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001541 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001542 uint32_t u32;
1543 } u = { depth };
1544
1545 raw.push_back((u.u32 ) & 0xff);
1546 raw.push_back((u.u32 >> 8) & 0xff);
1547 raw.push_back((u.u32 >> 16) & 0xff);
1548 raw.push_back((u.u32 >> 24) & 0xff);
1549 }
1550 break;
1551 default:
1552 break;
1553 }
1554
1555 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001556 switch (format) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001557 case VK_FMT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001558 raw.push_back(stencil);
1559 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001560 case VK_FMT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001561 raw.push_back(stencil);
1562 raw.push_back(0);
1563 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001564 case VK_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001565 raw.push_back(stencil);
1566 raw.push_back(0);
1567 raw.push_back(0);
1568 raw.push_back(0);
1569 break;
1570 default:
1571 break;
1572 }
1573
1574 return raw;
1575 }
1576
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001577 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001578 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001579 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001580 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 vk_testing::Image img;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001582 img.init(dev_, img_info);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001583 add_memory_ref(img);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001585 VK_MEMORY_OUTPUT_CPU_WRITE_BIT |
1586 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1587 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1588 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001589 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001590 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001591 VK_MEMORY_INPUT_CPU_READ_BIT |
1592 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1593 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1594 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1595 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1596 VK_MEMORY_INPUT_SHADER_READ_BIT |
1597 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1598 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001599 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001600
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001601 std::vector<VkImageMemoryBarrier> to_clear;
1602 std::vector<VkImageMemoryBarrier *> p_to_clear;
1603 std::vector<VkImageMemoryBarrier> to_xfer;
1604 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001605
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001606 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001607 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001608 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001609 VK_IMAGE_LAYOUT_GENERAL,
1610 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001611 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001612 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001613 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001614 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1615 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001616 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001617 }
1618
1619 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001620
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001621 VkPipeEvent set_events[] = { VK_PIPE_EVENT_GPU_COMMANDS_COMPLETE };
1622 VkPipelineBarrier pipeline_barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001623 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +00001624 pipeline_barrier.eventCount = 1;
1625 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001626 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +00001627 pipeline_barrier.memBarrierCount = to_clear.size();
Mark Lobodzinski628a8a52015-02-02 11:55:52 -06001628 pipeline_barrier.ppMemBarriers = (const void **)&p_to_clear[0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001629 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +00001630
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001631 vkCmdClearDepthStencil(cmd_.obj(),
1632 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001633 depth, stencil,
1634 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001635
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001636 pipeline_barrier.sType = VK_STRUCTURE_TYPE_PIPELINE_BARRIER;
Mike Stroyan55658c22014-12-04 11:08:39 +00001637 pipeline_barrier.eventCount = 1;
1638 pipeline_barrier.pEvents = set_events;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001639 pipeline_barrier.waitEvent = VK_WAIT_EVENT_TOP_OF_PIPE;
Mike Stroyan55658c22014-12-04 11:08:39 +00001640 pipeline_barrier.memBarrierCount = to_xfer.size();
Mark Lobodzinski628a8a52015-02-02 11:55:52 -06001641 pipeline_barrier.ppMemBarriers = (const void **)&p_to_xfer[0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001642 vkCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +00001643
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001644 cmd_.end();
1645
1646 submit_and_done();
1647
1648 // cannot verify
1649 if (!img.transparent() && !img.copyable())
1650 return;
1651
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001652 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001653
1654 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1655 check_dst(img, checker);
1656 }
1657};
1658
Tony Barbour01999182015-04-09 12:58:51 -06001659TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001660{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001661 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001662 it != test_formats_.end(); it++) {
1663 // known driver issues
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001664 if (it->format == VK_FMT_S8_UINT ||
1665 it->format == VK_FMT_D24_UNORM ||
1666 it->format == VK_FMT_D16_UNORM_S8_UINT ||
1667 it->format == VK_FMT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001668 continue;
1669
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001670 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001671 img_info.imageType = VK_IMAGE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001672 img_info.format = it->format;
1673 img_info.extent.width = 64;
1674 img_info.extent.height = 64;
1675 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001676 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001677
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001678 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001679 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001680 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001681
1682 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1683 }
1684}
1685
1686}; // namespace
1687
Chia-I Wucb67c652014-10-21 11:06:26 +08001688int main(int argc, char **argv)
1689{
Chia-I Wucb67c652014-10-21 11:06:26 +08001690 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001691
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001692 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001693
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001694 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001695
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001696 if (!environment->parse_args(argc, argv))
1697 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001698
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001699 ::testing::AddGlobalTestEnvironment(environment);
1700
1701 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001702}