blob: 058f47feb4318c40fde87ea328061892cc2fabdc [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
Tony Barbourb223d482015-06-09 13:40:53 -060025#include "math.h"
Chia-I Wu9dac52d2014-12-27 22:04:00 +080026#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060027#include "vktestbinding.h"
Tony Barbour34888cf2015-03-02 16:38:52 -070028#include "test_environment.h"
Chia-I Wucb67c652014-10-21 11:06:26 +080029
30#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
31
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060032namespace vk_testing {
Chia-I Wucb67c652014-10-21 11:06:26 +080033
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060034size_t get_format_size(VkFormat format);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080035
Chia-I Wu6170c9e2014-12-08 14:30:10 +080036class ImageChecker {
37public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060038 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080039 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060040 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
41 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080042
43 void set_solid_pattern(const std::vector<uint8_t> &solid);
44
Tony Barbour8205d902015-04-16 15:59:00 -060045 VkDeviceSize buffer_size() const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080046 bool fill(Buffer &buf) const { return walk(FILL, buf); }
47 bool fill(Image &img) const { return walk(FILL, img); }
48 bool check(Buffer &buf) const { return walk(CHECK, buf); }
49 bool check(Image &img) const { return walk(CHECK, img); }
50
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060051 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu6170c9e2014-12-08 14:30:10 +080052
53 static void hash_salt_generate() { hash_salt_++; }
54
55private:
56 enum Action {
57 FILL,
58 CHECK,
59 };
60
61 enum Pattern {
62 HASH,
63 SOLID,
64 };
65
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060066 size_t buffer_cpp() const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060067 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080068
69 bool walk(Action action, Buffer &buf) const;
70 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060071 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080072
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060073 std::vector<uint8_t> pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080074
75 static uint32_t hash_salt_;
76
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060077 VkImageCreateInfo info_;
78 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080079
80 Pattern pattern_;
81 std::vector<uint8_t> pattern_solid_;
82};
83
Chia-I Wucb67c652014-10-21 11:06:26 +080084
Chia-I Wu6170c9e2014-12-08 14:30:10 +080085uint32_t ImageChecker::hash_salt_;
86
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060087ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +080088 : info_(info), regions_(), pattern_(HASH)
89{
90 // create a region for every mip level in array slice 0
Tony Barbour8205d902015-04-16 15:59:00 -060091 VkDeviceSize offset = 0;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060092 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093 VkBufferImageCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +080094
Chia-I Wu714df452015-01-01 07:55:04 +080095 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +080096 region.imageSubresource.mipLevel = lv;
97 region.imageSubresource.arraySlice = 0;
Chia-I Wu9dac52d2014-12-27 22:04:00 +080098 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +080099
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600100 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_BIT) {
Tony Barbour8205d902015-04-16 15:59:00 -0600101 if (info_.format != VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 region.imageSubresource.aspect = VK_IMAGE_ASPECT_DEPTH;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800103 regions_.push_back(region);
104 }
105
Tony Barbour8205d902015-04-16 15:59:00 -0600106 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
107 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
108 info_.format == VK_FORMAT_S8_UINT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600109 region.imageSubresource.aspect = VK_IMAGE_ASPECT_STENCIL;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800110 regions_.push_back(region);
111 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800112 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113 region.imageSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800114 regions_.push_back(region);
115 }
116
117 offset += buffer_layout(region).size;
118 }
119
120 // arraySize should be limited in our tests. If this proves to be an
121 // issue, we can store only the regions for array slice 0 and be smart.
122 if (info_.arraySize > 1) {
Tony Barbour8205d902015-04-16 15:59:00 -0600123 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600124 const uint32_t slice_region_count = regions_.size();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800125
126 regions_.reserve(slice_region_count * info_.arraySize);
127
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600128 for (uint32_t slice = 1; slice < info_.arraySize; slice++) {
129 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130 VkBufferImageCopy region = regions_[i];
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800131
Chia-I Wu714df452015-01-01 07:55:04 +0800132 region.bufferOffset += slice_pitch * slice;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800133 region.imageSubresource.arraySlice = slice;
134 regions_.push_back(region);
135 }
136 }
137 }
138}
139
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600140ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800141 : info_(info), regions_(), pattern_(HASH)
142{
Tony Barbour8205d902015-04-16 15:59:00 -0600143 VkDeviceSize offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800145 it != ranges.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600146 for (uint32_t lv = 0; lv < it->mipLevels; lv++) {
147 for (uint32_t slice = 0; slice < it->arraySize; slice++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600148 VkBufferImageCopy region = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800149 region.bufferOffset = offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800150 region.imageSubresource = Image::subresource(*it, lv, slice);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800151 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800152
153 regions_.push_back(region);
154
155 offset += buffer_layout(region).size;
156 }
157 }
158 }
159}
160
161void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
162{
163 pattern_ = SOLID;
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800164 pattern_solid_.clear();
165 pattern_solid_.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600166 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800167 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800168}
169
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600170size_t ImageChecker::buffer_cpp() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800171{
172 return get_format_size(info_.format);
173}
174
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600175VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800176{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600177 VkSubresourceLayout layout = {};
Chia-I Wu714df452015-01-01 07:55:04 +0800178 layout.offset = region.bufferOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800179 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
180 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
181 layout.size = layout.depthPitch * region.imageExtent.depth;
182
183 return layout;
184}
185
Tony Barbour8205d902015-04-16 15:59:00 -0600186VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800187{
Tony Barbour8205d902015-04-16 15:59:00 -0600188 VkDeviceSize size = 0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800189
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600190 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800191 it != regions_.end(); it++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800193 if (size < layout.offset + layout.size)
194 size = layout.offset + layout.size;
195 }
196
197 return size;
198}
199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
201 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800202{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600203 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
204 for (int32_t y = 0; y < region.imageExtent.height; y++) {
205 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800206 uint8_t *dst = static_cast<uint8_t *>(data);
207 dst += layout.offset + layout.depthPitch * z +
208 layout.rowPitch * y + buffer_cpp() * x;
209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210 VkOffset3D offset = region.imageOffset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800211 offset.x += x;
212 offset.y += y;
213 offset.z += z;
214
215 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
216 pattern_hash(region.imageSubresource, offset) :
217 pattern_solid_;
218 assert(val.size() == buffer_cpp());
219
220 if (action == FILL) {
221 memcpy(dst, &val[0], val.size());
222 } else {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600223 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800224 EXPECT_EQ(val[i], dst[i]) <<
225 "Offset is: (" << x << ", " << y << ", " << z << ")";
226 if (val[i] != dst[i])
227 return false;
228 }
229 }
230 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800231 }
232 }
233
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800234 return true;
Chia-I Wucb67c652014-10-21 11:06:26 +0800235}
236
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800237bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800238{
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800239 void *data = buf.map();
240 if (!data)
241 return false;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800242
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800244 for (it = regions_.begin(); it != regions_.end(); it++) {
245 if (!walk_region(action, *it, buffer_layout(*it), data))
246 break;
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800247 }
248
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800249 buf.unmap();
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800250
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800251 return (it == regions_.end());
Chia-I Wu3c3fd122014-11-22 02:51:25 +0800252}
253
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800254bool ImageChecker::walk(Action action, Image &img) const
255{
256 void *data = img.map();
257 if (!data)
258 return false;
259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800261 for (it = regions_.begin(); it != regions_.end(); it++) {
262 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
263 break;
264 }
265
266 img.unmap();
267
268 return (it == regions_.end());
269}
270
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresource &subres, const VkOffset3D &offset) const
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800272{
273#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
274#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
275 const unsigned char input[] = {
276 HASH_BYTES(hash_salt_),
277 HASH_BYTES(subres.mipLevel),
278 HASH_BYTES(subres.arraySlice),
279 HASH_BYTES(offset.x),
280 HASH_BYTES(offset.y),
281 HASH_BYTES(offset.z),
282 };
283 unsigned long hash = 5381;
284
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600285 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800286 hash = ((hash << 5) + hash) + input[i];
287
288 const uint8_t output[4] = { HASH_BYTES(hash) };
289#undef HASH_BYTES
290#undef HASH_BYTE
291
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800292 std::vector<uint8_t> val;
293 val.reserve(buffer_cpp());
Tony Barbourae2d5f42015-05-14 17:15:33 -0600294 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu4dce6af2014-12-21 14:59:04 +0800295 val.push_back(output[i % 4]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800296
297 return val;
298}
299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300size_t get_format_size(VkFormat format)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800301{
Tony Barbourae2d5f42015-05-14 17:15:33 -0600302 static bool format_table_unverified = true;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800303 static const struct format_info {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600304 VkFormat_ format;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600305 size_t size;
306 uint32_t channel_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600307 } format_table[VK_NUM_FORMAT] = {
Tony Barbourae2d5f42015-05-14 17:15:33 -0600308 { VK_FORMAT_UNDEFINED, 0, 0 },
309 { VK_FORMAT_R4G4_UNORM, 1, 2 },
310 { VK_FORMAT_R4G4_USCALED, 1, 2 },
311 { VK_FORMAT_R4G4B4A4_UNORM, 2, 4 },
312 { VK_FORMAT_R4G4B4A4_USCALED, 2, 4 },
313 { VK_FORMAT_R5G6B5_UNORM, 2, 3 },
314 { VK_FORMAT_R5G6B5_USCALED, 2, 3 },
315 { VK_FORMAT_R5G5B5A1_UNORM, 2, 4 },
316 { VK_FORMAT_R5G5B5A1_USCALED, 2, 4 },
317 { VK_FORMAT_R8_UNORM, 1, 1 },
318 { VK_FORMAT_R8_SNORM, 1, 1 },
319 { VK_FORMAT_R8_USCALED, 1, 1 },
320 { VK_FORMAT_R8_SSCALED, 1, 1 },
321 { VK_FORMAT_R8_UINT, 1, 1 },
322 { VK_FORMAT_R8_SINT, 1, 1 },
323 { VK_FORMAT_R8_SRGB, 1, 1 },
324 { VK_FORMAT_R8G8_UNORM, 2, 2 },
325 { VK_FORMAT_R8G8_SNORM, 2, 2 },
326 { VK_FORMAT_R8G8_USCALED, 2, 2 },
327 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
328 { VK_FORMAT_R8G8_UINT, 2, 2 },
329 { VK_FORMAT_R8G8_SINT, 2, 2 },
330 { VK_FORMAT_R8G8_SRGB, 2, 2 },
331 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
332 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
333 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
334 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
335 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
336 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
337 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
338 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
339 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
340 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
341 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
342 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
343 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
344 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
345 { VK_FORMAT_R10G10B10A2_UNORM, 4, 4 },
346 { VK_FORMAT_R10G10B10A2_SNORM, 4, 4 },
347 { VK_FORMAT_R10G10B10A2_USCALED, 4, 4 },
348 { VK_FORMAT_R10G10B10A2_SSCALED, 4, 4 },
349 { VK_FORMAT_R10G10B10A2_UINT, 4, 4 },
350 { VK_FORMAT_R10G10B10A2_SINT, 4, 4 },
351 { VK_FORMAT_R16_UNORM, 2, 1 },
352 { VK_FORMAT_R16_SNORM, 2, 1 },
353 { VK_FORMAT_R16_USCALED, 2, 1 },
354 { VK_FORMAT_R16_SSCALED, 2, 1 },
355 { VK_FORMAT_R16_UINT, 2, 1 },
356 { VK_FORMAT_R16_SINT, 2, 1 },
357 { VK_FORMAT_R16_SFLOAT, 2, 1 },
358 { VK_FORMAT_R16G16_UNORM, 4, 2 },
359 { VK_FORMAT_R16G16_SNORM, 4, 2 },
360 { VK_FORMAT_R16G16_USCALED, 4, 2 },
361 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
362 { VK_FORMAT_R16G16_UINT, 4, 2 },
363 { VK_FORMAT_R16G16_SINT, 4, 2 },
364 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
365 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
366 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
367 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
368 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
369 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
370 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
371 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
372 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
373 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
374 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
375 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
376 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
377 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
378 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
379 { VK_FORMAT_R32_UINT, 4, 1 },
380 { VK_FORMAT_R32_SINT, 4, 1 },
381 { VK_FORMAT_R32_SFLOAT, 4, 1 },
382 { VK_FORMAT_R32G32_UINT, 8, 2 },
383 { VK_FORMAT_R32G32_SINT, 8, 2 },
384 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
385 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
386 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
387 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
388 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
389 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
390 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
391 { VK_FORMAT_R64_SFLOAT, 8, 1 },
392 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
393 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
394 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
395 { VK_FORMAT_R11G11B10_UFLOAT, 4, 3 },
396 { VK_FORMAT_R9G9B9E5_UFLOAT, 4, 3 },
397 { VK_FORMAT_D16_UNORM, 2, 1 },
398 { VK_FORMAT_D24_UNORM, 3, 1 },
399 { VK_FORMAT_D32_SFLOAT, 4, 1 },
400 { VK_FORMAT_S8_UINT, 1, 1 },
401 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
402 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbourb223d482015-06-09 13:40:53 -0600403 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Tony Barbourae2d5f42015-05-14 17:15:33 -0600404 { VK_FORMAT_BC1_RGB_UNORM, 8, 4 },
405 { VK_FORMAT_BC1_RGB_SRGB, 8, 4 },
406 { VK_FORMAT_BC1_RGBA_UNORM, 8, 4 },
407 { VK_FORMAT_BC1_RGBA_SRGB, 8, 4 },
408 { VK_FORMAT_BC2_UNORM, 16, 4 },
409 { VK_FORMAT_BC2_SRGB, 16, 4 },
410 { VK_FORMAT_BC3_UNORM, 16, 4 },
411 { VK_FORMAT_BC3_SRGB, 16, 4 },
412 { VK_FORMAT_BC4_UNORM, 8, 4 },
413 { VK_FORMAT_BC4_SNORM, 8, 4 },
414 { VK_FORMAT_BC5_UNORM, 16, 4 },
415 { VK_FORMAT_BC5_SNORM, 16, 4 },
416 { VK_FORMAT_BC6H_UFLOAT, 16, 4 },
417 { VK_FORMAT_BC6H_SFLOAT, 16, 4 },
418 { VK_FORMAT_BC7_UNORM, 16, 4 },
419 { VK_FORMAT_BC7_SRGB, 16, 4 },
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700420 // TODO: Initialize remaining compressed formats.
Tony Barbourae2d5f42015-05-14 17:15:33 -0600421 { VK_FORMAT_ETC2_R8G8B8_UNORM, 0, 0 },
422 { VK_FORMAT_ETC2_R8G8B8_SRGB, 0, 0 },
423 { VK_FORMAT_ETC2_R8G8B8A1_UNORM, 0, 0 },
424 { VK_FORMAT_ETC2_R8G8B8A1_SRGB, 0, 0 },
425 { VK_FORMAT_ETC2_R8G8B8A8_UNORM, 0, 0 },
426 { VK_FORMAT_ETC2_R8G8B8A8_SRGB, 0, 0 },
427 { VK_FORMAT_EAC_R11_UNORM, 0, 0 },
428 { VK_FORMAT_EAC_R11_SNORM, 0, 0 },
429 { VK_FORMAT_EAC_R11G11_UNORM, 0, 0 },
430 { VK_FORMAT_EAC_R11G11_SNORM, 0, 0 },
431 { VK_FORMAT_ASTC_4x4_UNORM, 0, 0 },
432 { VK_FORMAT_ASTC_4x4_SRGB, 0, 0 },
433 { VK_FORMAT_ASTC_5x4_UNORM, 0, 0 },
434 { VK_FORMAT_ASTC_5x4_SRGB, 0, 0 },
435 { VK_FORMAT_ASTC_5x5_UNORM, 0, 0 },
436 { VK_FORMAT_ASTC_5x5_SRGB, 0, 0 },
437 { VK_FORMAT_ASTC_6x5_UNORM, 0, 0 },
438 { VK_FORMAT_ASTC_6x5_SRGB, 0, 0 },
439 { VK_FORMAT_ASTC_6x6_UNORM, 0, 0 },
440 { VK_FORMAT_ASTC_6x6_SRGB, 0, 0 },
441 { VK_FORMAT_ASTC_8x5_UNORM, 0, 0 },
442 { VK_FORMAT_ASTC_8x5_SRGB, 0, 0 },
443 { VK_FORMAT_ASTC_8x6_UNORM, 0, 0 },
444 { VK_FORMAT_ASTC_8x6_SRGB, 0, 0 },
445 { VK_FORMAT_ASTC_8x8_UNORM, 0, 0 },
446 { VK_FORMAT_ASTC_8x8_SRGB, 0, 0 },
447 { VK_FORMAT_ASTC_10x5_UNORM, 0, 0 },
448 { VK_FORMAT_ASTC_10x5_SRGB, 0, 0 },
449 { VK_FORMAT_ASTC_10x6_UNORM, 0, 0 },
450 { VK_FORMAT_ASTC_10x6_SRGB, 0, 0 },
451 { VK_FORMAT_ASTC_10x8_UNORM, 0, 0 },
452 { VK_FORMAT_ASTC_10x8_SRGB, 0, 0 },
453 { VK_FORMAT_ASTC_10x10_UNORM, 0, 0 },
454 { VK_FORMAT_ASTC_10x10_SRGB, 0, 0 },
455 { VK_FORMAT_ASTC_12x10_UNORM, 0, 0 },
456 { VK_FORMAT_ASTC_12x10_SRGB, 0, 0 },
457 { VK_FORMAT_ASTC_12x12_UNORM, 0, 0 },
458 { VK_FORMAT_ASTC_12x12_SRGB, 0, 0 },
459 { VK_FORMAT_B4G4R4A4_UNORM, 2, 4 },
460 { VK_FORMAT_B5G5R5A1_UNORM, 2, 4 },
461 { VK_FORMAT_B5G6R5_UNORM, 2, 3 },
462 { VK_FORMAT_B5G6R5_USCALED, 2, 3 },
463 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
464 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
465 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
466 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
467 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
468 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
469 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
470 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
471 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
472 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
473 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
474 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
475 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
476 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
477 { VK_FORMAT_B10G10R10A2_UNORM, 4, 4 },
478 { VK_FORMAT_B10G10R10A2_SNORM, 4, 4 },
479 { VK_FORMAT_B10G10R10A2_USCALED, 4, 4 },
480 { VK_FORMAT_B10G10R10A2_SSCALED, 4, 4 },
481 { VK_FORMAT_B10G10R10A2_UINT, 4, 4 },
482 { VK_FORMAT_B10G10R10A2_SINT, 4, 4 },
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800483 };
Tony Barbourae2d5f42015-05-14 17:15:33 -0600484 if (format_table_unverified)
485 {
486 for (unsigned int i = 0; i < VK_NUM_FORMAT; i++)
487 {
488 assert(format_table[i].format == i);
489 }
490 format_table_unverified = false;
491 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800492
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700493 return format_table[format].size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800494}
495
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800497{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600498 const VkExtent3D ext = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800499 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
500 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
501 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
502 };
503
504 return ext;
505}
506
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600507}; // namespace vk_testing
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800508
509namespace {
510
511#define DO(action) ASSERT_EQ(true, action);
512
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600513static vk_testing::Environment *environment;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800514
Tony Barbour01999182015-04-09 12:58:51 -0600515class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800516protected:
Tony Barbour01999182015-04-09 12:58:51 -0600517 VkCmdBlitTest() :
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800518 dev_(environment->default_device()),
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800519 queue_(*dev_.graphics_queues()[0]),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600520 cmd_(dev_, vk_testing::CmdBuffer::create_info(dev_.graphics_queue_node_index_))
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800521 {
522 // make sure every test uses a different pattern
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600523 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800524 }
525
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800526 bool submit_and_done()
527 {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600528 queue_.submit(cmd_);
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800529 queue_.wait();
530 mem_refs_.clear();
531 return true;
532 }
533
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600534 vk_testing::Device &dev_;
535 vk_testing::Queue &queue_;
536 vk_testing::CmdBuffer cmd_;
Chia-I Wu9dac52d2014-12-27 22:04:00 +0800537
Tony Barbour8205d902015-04-16 15:59:00 -0600538 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800539};
540
Tony Barbour01999182015-04-09 12:58:51 -0600541typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800542
Tony Barbour01999182015-04-09 12:58:51 -0600543TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800544{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600546 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800547
Tony Barbour94310562015-04-22 15:10:33 -0600548 buf.init(dev_, 20, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800549
550 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111);
552 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800553 cmd_.end();
554
555 submit_and_done();
556
557 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
558 EXPECT_EQ(0x11111111, data[0]);
559 EXPECT_EQ(0x22222222, data[1]);
560 EXPECT_EQ(0x22222222, data[2]);
561 EXPECT_EQ(0x22222222, data[3]);
562 EXPECT_EQ(0x22222222, data[4]);
563 buf.unmap();
564}
565
Tony Barbour01999182015-04-09 12:58:51 -0600566TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wuea9367f2014-11-23 02:16:45 +0800567{
Tony Barbour8205d902015-04-16 15:59:00 -0600568 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600569 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600570 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wuea9367f2014-11-23 02:16:45 +0800571
Tony Barbour94310562015-04-22 15:10:33 -0600572 buf.init(dev_, size, reqs);
Chia-I Wuea9367f2014-11-23 02:16:45 +0800573
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800574 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600575 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111);
576 vkCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800577 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800578
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800579 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800580
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800581 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600582 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800583 for (offset = 0; offset < size / 2; offset += 4)
584 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
585 for (; offset < size; offset += 4)
586 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
587 buf.unmap();
588}
Chia-I Wuea9367f2014-11-23 02:16:45 +0800589
Tony Barbour01999182015-04-09 12:58:51 -0600590TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800591{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600592 vk_testing::Buffer buf;
Tony Barbour94310562015-04-22 15:10:33 -0600593 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800594
Tony Barbour94310562015-04-22 15:10:33 -0600595 buf.init(dev_, 64, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800596
597 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111);
599 vkCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800600 cmd_.end();
601
602 submit_and_done();
603
604 const uint32_t *data = static_cast<const uint32_t *>(buf.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600605 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800606 for (offset = 0; offset < 32; offset += 4)
607 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
608 for (; offset < 64; offset += 4)
609 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
610 buf.unmap();
611}
612
Tony Barbour01999182015-04-09 12:58:51 -0600613TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800614{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 vk_testing::Buffer bufs[9];
Tony Barbour8205d902015-04-16 15:59:00 -0600616 VkDeviceSize size = 4;
Tony Barbour94310562015-04-22 15:10:33 -0600617 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800618
619 cmd_.begin();
620 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600621 bufs[i].init(dev_, size, reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 vkCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800623 size <<= 1;
624 }
625 cmd_.end();
626
627 submit_and_done();
628
629 size = 4;
630 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
631 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map());
Tony Barbour8205d902015-04-16 15:59:00 -0600632 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800633 for (offset = 0; offset < size; offset += 4)
634 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
635 "Offset is: " << offset;
636 bufs[i].unmap();
637
638 size <<= 1;
639 }
640}
641
Tony Barbour01999182015-04-09 12:58:51 -0600642typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800643
Tony Barbour01999182015-04-09 12:58:51 -0600644TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800645{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600646 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600647 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800648
Tony Barbour94310562015-04-22 15:10:33 -0600649 src.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800650 uint32_t *data = static_cast<uint32_t *>(src.map());
651 data[0] = 0x11111111;
652 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800653
Tony Barbour94310562015-04-22 15:10:33 -0600654 dst.init(dev_, 4, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800655
656 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600657 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800658 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800660 cmd_.end();
661
662 submit_and_done();
663
664 data = static_cast<uint32_t *>(dst.map());
665 EXPECT_EQ(0x11111111, data[0]);
666 dst.unmap();
667}
668
Tony Barbour01999182015-04-09 12:58:51 -0600669TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800670{
Tony Barbour8205d902015-04-16 15:59:00 -0600671 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600673 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800674
Tony Barbour94310562015-04-22 15:10:33 -0600675 src.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800676 uint32_t *data = static_cast<uint32_t *>(src.map());
Tony Barbour8205d902015-04-16 15:59:00 -0600677 VkDeviceSize offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800678 for (offset = 0; offset < size; offset += 4)
679 data[offset / 4] = offset;
680 src.unmap();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800681
Tony Barbour94310562015-04-22 15:10:33 -0600682 dst.init(dev_, size, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800683
684 cmd_.begin();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685 VkBufferCopy region = {};
Chia-I Wuea9367f2014-11-23 02:16:45 +0800686 region.copySize = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600687 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, &region);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800688 cmd_.end();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800689
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800690 submit_and_done();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800691
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800692 data = static_cast<uint32_t *>(dst.map());
693 for (offset = 0; offset < size; offset += 4)
694 EXPECT_EQ(offset, data[offset / 4]);
695 dst.unmap();
Chia-I Wuea9367f2014-11-23 02:16:45 +0800696}
697
Tony Barbour01999182015-04-09 12:58:51 -0600698TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wucb67c652014-10-21 11:06:26 +0800699{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600700 const VkBufferCopy regions[] = {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800701 /* well aligned */
702 { 0, 0, 256 },
703 { 0, 256, 128 },
704 { 0, 384, 64 },
705 { 0, 448, 32 },
706 { 0, 480, 16 },
707 { 0, 496, 8 },
Chia-I Wucb67c652014-10-21 11:06:26 +0800708
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800709 /* ill aligned */
710 { 7, 510, 16 },
711 { 16, 530, 13 },
712 { 32, 551, 16 },
713 { 45, 570, 15 },
714 { 50, 590, 1 },
715 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716 vk_testing::Buffer src, dst;
Tony Barbour94310562015-04-22 15:10:33 -0600717 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +0800718
Tony Barbour94310562015-04-22 15:10:33 -0600719 src.init(dev_, 256, reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800720 uint8_t *data = static_cast<uint8_t *>(src.map());
721 for (int i = 0; i < 256; i++)
722 data[i] = i;
723 src.unmap();
Chia-I Wucb67c652014-10-21 11:06:26 +0800724
Tony Barbour94310562015-04-22 15:10:33 -0600725 dst.init(dev_, 1024, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800726
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800727 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600728 vkCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800729 cmd_.end();
Chia-I Wucb67c652014-10-21 11:06:26 +0800730
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800731 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800732
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800733 data = static_cast<uint8_t *>(dst.map());
734 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600735 const VkBufferCopy &r = regions[i];
Chia-I Wucb67c652014-10-21 11:06:26 +0800736
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800737 for (int j = 0; j < r.copySize; j++) {
738 EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) <<
739 "Region is: " << i << "\n" <<
740 "Offset is: " << r.destOffset + j;
741 }
742 }
743 dst.unmap();
744}
Chia-I Wucb67c652014-10-21 11:06:26 +0800745
Tony Barbour01999182015-04-09 12:58:51 -0600746TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800747{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749 VkEventCreateInfo event_info;
750 VkEvent event;
751 VkMemoryRequirements mem_req;
Mike Stroyan55658c22014-12-04 11:08:39 +0000752 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600753 VkResult err;
Tony Barbour94310562015-04-22 15:10:33 -0600754 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbour43cdc952015-05-21 13:26:05 -0600755 VkMemoryAllocInfo mem_info;
756 VkDeviceMemory event_mem;
Mike Stroyan55658c22014-12-04 11:08:39 +0000757
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 // typedef struct VkEventCreateInfo_
Mike Stroyan55658c22014-12-04 11:08:39 +0000759 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600760 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600761 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600762 // VkFlags flags; // Reserved
763 // } VkEventCreateInfo;
Mike Stroyan55658c22014-12-04 11:08:39 +0000764 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyan55658c22014-12-04 11:08:39 +0000766
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600767 err = vkCreateEvent(dev_.obj(), &event_info, &event);
768 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000769
Tony Barbour43cdc952015-05-21 13:26:05 -0600770 data_size = sizeof(mem_req);
Mike Stroyan230e6252015-04-17 12:36:38 -0600771 err = vkGetObjectInfo(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Tony Barbour43cdc952015-05-21 13:26:05 -0600772 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600773 ASSERT_VK_SUCCESS(err);
Mike Stroyan55658c22014-12-04 11:08:39 +0000774
Tony Barbour43cdc952015-05-21 13:26:05 -0600775 if (mem_req.size) {
Mike Stroyan55658c22014-12-04 11:08:39 +0000776
Tony Barbour43cdc952015-05-21 13:26:05 -0600777 // VkResult VKAPI vkAllocMemory(
778 // VkDevice device,
779 // const VkMemoryAllocInfo* pAllocInfo,
780 // VkDeviceMemory* pMem);
Mike Stroyan55658c22014-12-04 11:08:39 +0000781
Tony Barbour43cdc952015-05-21 13:26:05 -0600782 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Mike Stroyan55658c22014-12-04 11:08:39 +0000783
Tony Barbour43cdc952015-05-21 13:26:05 -0600784 memset(&mem_info, 0, sizeof(mem_info));
785 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
786 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchterb25c9b92015-06-18 17:01:41 -0600787 mem_info.memProps = 0;
Tony Barbour43cdc952015-05-21 13:26:05 -0600788 err = vkAllocMemory(dev_.obj(), &mem_info, &event_mem);
789 ASSERT_VK_SUCCESS(err);
790
791 err = vkBindObjectMemory(dev_.obj(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
792 ASSERT_VK_SUCCESS(err);
793 }
Mike Stroyan55658c22014-12-04 11:08:39 +0000794
Mike Stroyan230e6252015-04-17 12:36:38 -0600795 err = vkResetEvent(dev_.obj(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600796 ASSERT_VK_SUCCESS(err);
Chia-I Wucb67c652014-10-21 11:06:26 +0800797
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800798 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Tony Barbour94310562015-04-22 15:10:33 -0600799 bufs[i].init(dev_, 4, reqs);
Chia-I Wucb67c652014-10-21 11:06:26 +0800800
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800801 uint32_t *data = static_cast<uint32_t *>(bufs[i].map());
802 data[0] = 0x22222222 * (i + 1);
803 bufs[i].unmap();
804 }
805
806 cmd_.begin();
807
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600808 vkCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800809 // is this necessary?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600810 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600811 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyan55658c22014-12-04 11:08:39 +0000813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814 VkPipeEvent set_events[] = { VK_PIPE_EVENT_TRANSFER_COMPLETE };
Tony Barbour8205d902015-04-16 15:59:00 -0600815 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 +0800816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 VkBufferCopy region = {};
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800818 region.copySize = 4;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600819 vkCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000820
821 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600822 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600823 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600824 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 +0800825
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600826 vkCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
Mike Stroyan55658c22014-12-04 11:08:39 +0000827
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600828 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
829 * This could be vkCmdPipelineBarrier.
Mike Stroyan55658c22014-12-04 11:08:39 +0000830 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831 vkCmdSetEvent(cmd_.obj(), event, VK_PIPE_EVENT_TRANSFER_COMPLETE);
Mike Stroyan55658c22014-12-04 11:08:39 +0000832
833 // Additional commands could go into the buffer here before the wait.
834
835 memory_barrier = bufs[1].buffer_memory_barrier(
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600836 VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_HOST_READ_BIT, 0, 4);
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -0600837 pmemory_barrier = &memory_barrier;
Tony Barbour8205d902015-04-16 15:59:00 -0600838 vkCmdWaitEvents(cmd_.obj(), VK_WAIT_EVENT_TOP_OF_PIPE, 1, &event, 1, (const void **)&pmemory_barrier);
Mike Stroyan55658c22014-12-04 11:08:39 +0000839
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800840 cmd_.end();
841
842 submit_and_done();
843
844 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map());
845 EXPECT_EQ(0x11111111, data[0]);
846 bufs[2].unmap();
Mike Stroyan55658c22014-12-04 11:08:39 +0000847
Tony Barbour43cdc952015-05-21 13:26:05 -0600848 if (mem_req.size) {
849 // All done with event memory, clean up
Tony Barbour43cdc952015-05-21 13:26:05 -0600850 err = vkFreeMemory(dev_.obj(), event_mem);
851 ASSERT_VK_SUCCESS(err);
852 }
Mike Stroyan230e6252015-04-17 12:36:38 -0600853 err = vkDestroyObject(dev_.obj(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854 ASSERT_VK_SUCCESS(err);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800855}
856
Tony Barbour01999182015-04-09 12:58:51 -0600857class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800858protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600859 void init_test_formats(VkFlags features)
Chia-I Wucb67c652014-10-21 11:06:26 +0800860 {
Tony Barbour8205d902015-04-16 15:59:00 -0600861 first_linear_format_ = VK_FORMAT_UNDEFINED;
862 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wucb67c652014-10-21 11:06:26 +0800863
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600864 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800865 it != dev_.formats().end(); it++) {
866 if (it->features & features) {
867 test_formats_.push_back(*it);
Chia-I Wucb67c652014-10-21 11:06:26 +0800868
Tony Barbour8205d902015-04-16 15:59:00 -0600869 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
870 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800871 first_linear_format_ = it->format;
Tony Barbour8205d902015-04-16 15:59:00 -0600872 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
873 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800874 first_optimal_format_ = it->format;
875 }
876 }
877 }
Chia-I Wucb67c652014-10-21 11:06:26 +0800878
Chia-I Wu9feab842014-12-22 13:19:08 +0800879 void init_test_formats()
880 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600881 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu9feab842014-12-22 13:19:08 +0800882 }
883
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600884 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800885 {
886 if (img.transparent()) {
887 checker.fill(img);
888 return;
Chia-I Wucb67c652014-10-21 11:06:26 +0800889 }
890
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800891 ASSERT_EQ(true, img.copyable());
892
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600893 vk_testing::Buffer in_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600894 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
895
896 in_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800897 checker.fill(in_buf);
898
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800899 // copy in and tile
900 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600901 vkCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(),
902 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800903 checker.regions().size(), &checker.regions()[0]);
904 cmd_.end();
905
906 submit_and_done();
Chia-I Wucb67c652014-10-21 11:06:26 +0800907 }
908
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600909 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu86822632014-11-22 15:09:42 +0800910 {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800911 if (img.transparent()) {
912 DO(checker.check(img));
913 return;
Chia-I Wu86822632014-11-22 15:09:42 +0800914 }
915
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800916 ASSERT_EQ(true, img.copyable());
917
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600918 vk_testing::Buffer out_buf;
Tony Barbour94310562015-04-22 15:10:33 -0600919 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
920 out_buf.init(dev_, checker.buffer_size(), reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800921
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800922 // copy out and linearize
923 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600924 vkCmdCopyImageToBuffer(cmd_.obj(),
925 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600926 out_buf.obj(),
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800927 checker.regions().size(), &checker.regions()[0]);
928 cmd_.end();
929
930 submit_and_done();
931
932 DO(checker.check(out_buf));
Chia-I Wu86822632014-11-22 15:09:42 +0800933 }
934
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600935 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600936 VkFormat first_linear_format_;
937 VkFormat first_optimal_format_;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800938};
939
Tony Barbour01999182015-04-09 12:58:51 -0600940class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800941protected:
942 virtual void SetUp()
943 {
Tony Barbour01999182015-04-09 12:58:51 -0600944 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -0600945 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800946 ASSERT_NE(true, test_formats_.empty());
947 }
948
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600949 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800950 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 vk_testing::Buffer buf;
952 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -0600953 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
954 VkMemoryPropertyFlags image_reqs =
955 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800956
Tony Barbour43cdc952015-05-21 13:26:05 -0600957 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800958 checker.fill(buf);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800959
Tony Barbour43cdc952015-05-21 13:26:05 -0600960 img.init(dev_, img_info, image_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800961
962 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 vkCmdCopyBufferToImage(cmd_.obj(),
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -0600964 buf.obj(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600965 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800966 checker.regions().size(), &checker.regions()[0]);
967 cmd_.end();
968
969 submit_and_done();
970
971 check_dst(img, checker);
972 }
973
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600974 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800975 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600976 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800977 test_copy_memory_to_image(img_info, checker);
978 }
979
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600980 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800981 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600982 vk_testing::ImageChecker checker(img_info);
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800983 test_copy_memory_to_image(img_info, checker);
984 }
985};
986
Tony Barbour01999182015-04-09 12:58:51 -0600987TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800988{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600989 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +0800990 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700991
992 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -0600993 if (it->format == VK_FORMAT_UNDEFINED ||
994 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
995 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700996 continue;
997
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600998 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -0600999 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001000 img_info.format = it->format;
1001 img_info.extent.width = 64;
1002 img_info.extent.height = 64;
1003 img_info.tiling = it->tiling;
1004
1005 test_copy_memory_to_image(img_info);
1006 }
Chia-I Wu86822632014-11-22 15:09:42 +08001007}
1008
Tony Barbour01999182015-04-09 12:58:51 -06001009class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu830fb332014-12-13 15:28:20 +08001010protected:
1011 virtual void SetUp()
1012 {
Tony Barbour01999182015-04-09 12:58:51 -06001013 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001014 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu830fb332014-12-13 15:28:20 +08001015 ASSERT_NE(true, test_formats_.empty());
1016 }
1017
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001018 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu830fb332014-12-13 15:28:20 +08001019 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001020 vk_testing::Image img;
1021 vk_testing::Buffer buf;
Tony Barbour43cdc952015-05-21 13:26:05 -06001022 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1023 VkMemoryPropertyFlags image_reqs =
1024 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu830fb332014-12-13 15:28:20 +08001025
Tony Barbour43cdc952015-05-21 13:26:05 -06001026 img.init(dev_, img_info, image_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001027 fill_src(img, checker);
Chia-I Wu830fb332014-12-13 15:28:20 +08001028
Tony Barbour43cdc952015-05-21 13:26:05 -06001029 buf.init(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu830fb332014-12-13 15:28:20 +08001030
1031 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001032 vkCmdCopyImageToBuffer(cmd_.obj(),
1033 img.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001034 buf.obj(),
Chia-I Wu830fb332014-12-13 15:28:20 +08001035 checker.regions().size(), &checker.regions()[0]);
1036 cmd_.end();
1037
1038 submit_and_done();
1039
1040 checker.check(buf);
1041 }
1042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001043 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu830fb332014-12-13 15:28:20 +08001044 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001045 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu830fb332014-12-13 15:28:20 +08001046 test_copy_image_to_memory(img_info, checker);
1047 }
1048
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001049 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu830fb332014-12-13 15:28:20 +08001050 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 vk_testing::ImageChecker checker(img_info);
Chia-I Wu830fb332014-12-13 15:28:20 +08001052 test_copy_image_to_memory(img_info, checker);
1053 }
1054};
1055
Tony Barbour01999182015-04-09 12:58:51 -06001056TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu830fb332014-12-13 15:28:20 +08001057{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001058 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu830fb332014-12-13 15:28:20 +08001059 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001060
1061 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001062 if (it->format == VK_FORMAT_UNDEFINED ||
1063 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1064 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001065 continue;
1066
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001067 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001068 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu830fb332014-12-13 15:28:20 +08001069 img_info.format = it->format;
1070 img_info.extent.width = 64;
1071 img_info.extent.height = 64;
1072 img_info.tiling = it->tiling;
1073
1074 test_copy_image_to_memory(img_info);
1075 }
1076}
1077
Tony Barbour01999182015-04-09 12:58:51 -06001078class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001079protected:
1080 virtual void SetUp()
1081 {
Tony Barbour01999182015-04-09 12:58:51 -06001082 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001083 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001084 ASSERT_NE(true, test_formats_.empty());
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001085 }
1086
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001087 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1088 const std::vector<VkImageCopy> &copies)
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001089 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001090 // convert VkImageCopy to two sets of VkBufferImageCopy
1091 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbour8205d902015-04-16 15:59:00 -06001092 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001093 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1094 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001095
Chia-I Wu714df452015-01-01 07:55:04 +08001096 src_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001097 src_region.imageSubresource = it->srcSubresource;
1098 src_region.imageOffset = it->srcOffset;
1099 src_region.imageExtent = it->extent;
1100 src_regions.push_back(src_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001101
Chia-I Wu714df452015-01-01 07:55:04 +08001102 dst_region.bufferOffset = src_offset;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001103 dst_region.imageSubresource = it->destSubresource;
1104 dst_region.imageOffset = it->destOffset;
1105 dst_region.imageExtent = it->extent;
1106 dst_regions.push_back(dst_region);
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001107
Tony Barbour8205d902015-04-16 15:59:00 -06001108 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001109 src_offset += vk_testing::get_format_size(src_info.format) * size;
1110 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001111 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001112
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001113 vk_testing::ImageChecker src_checker(src_info, src_regions);
1114 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour43cdc952015-05-21 13:26:05 -06001115 VkMemoryPropertyFlags src_reqs =
1116 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1117 VkMemoryPropertyFlags dst_reqs =
1118 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1119
1120
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001121
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001122 vk_testing::Image src;
Tony Barbour43cdc952015-05-21 13:26:05 -06001123 src.init(dev_, src_info, src_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001124 fill_src(src, src_checker);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001125
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001126 vk_testing::Image dst;
Tony Barbour43cdc952015-05-21 13:26:05 -06001127 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001128
1129 cmd_.begin();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001130 vkCmdCopyImage(cmd_.obj(),
1131 src.obj(), VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL,
1132 dst.obj(), VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001133 copies.size(), &copies[0]);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001134 cmd_.end();
1135
1136 submit_and_done();
1137
1138 check_dst(dst, dst_checker);
1139 }
1140};
1141
Tony Barbour01999182015-04-09 12:58:51 -06001142TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001143{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001144 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001145 it != test_formats_.end(); it++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001146
1147 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001148 if (it->format == VK_FORMAT_UNDEFINED ||
1149 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1150 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001151 continue;
1152
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001153 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001154 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001155 img_info.format = it->format;
1156 img_info.extent.width = 64;
1157 img_info.extent.height = 64;
1158 img_info.tiling = it->tiling;
1159
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001160 VkImageCopy copy = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001161 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR, 0, 0);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001162 copy.destSubresource = copy.srcSubresource;
1163 copy.extent = img_info.extent;
1164
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001165 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001166 }
1167}
1168
Tony Barbour01999182015-04-09 12:58:51 -06001169class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001170protected:
Tony Barbour01999182015-04-09 12:58:51 -06001171 VkCmdClearColorImageTest() : test_raw_(false) {}
1172 VkCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {}
Chia-I Wu9feab842014-12-22 13:19:08 +08001173
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001174 virtual void SetUp()
1175 {
Tony Barbour01999182015-04-09 12:58:51 -06001176 VkCmdBlitTest::SetUp();
Chia-I Wu9feab842014-12-22 13:19:08 +08001177
1178 if (test_raw_)
1179 init_test_formats();
1180 else
Tony Barbour8205d902015-04-16 15:59:00 -06001181 init_test_formats(VK_FORMAT_FEATURE_CONVERSION_BIT);
Chia-I Wu9feab842014-12-22 13:19:08 +08001182
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001183 ASSERT_NE(true, test_formats_.empty());
1184 }
1185
Chia-I Wu9feab842014-12-22 13:19:08 +08001186 union Color {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001187 float color[4];
1188 uint32_t raw[4];
Chia-I Wu9feab842014-12-22 13:19:08 +08001189 };
1190
1191 bool test_raw_;
1192
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001193 std::vector<uint8_t> color_to_raw(VkFormat format, const float color[4])
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001194 {
1195 std::vector<uint8_t> raw;
1196
1197 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001198 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001199 case VK_FORMAT_R8G8B8A8_UNORM:
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001200 raw.push_back((uint8_t)(color[0] * 255.0f));
1201 raw.push_back((uint8_t)(color[1] * 255.0f));
1202 raw.push_back((uint8_t)(color[2] * 255.0f));
1203 raw.push_back((uint8_t)(color[3] * 255.0f));
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001204 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001205 case VK_FORMAT_B8G8R8A8_UNORM:
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001206 raw.push_back((uint8_t)(color[2] * 255.0f));
1207 raw.push_back((uint8_t)(color[1] * 255.0f));
1208 raw.push_back((uint8_t)(color[0] * 255.0f));
1209 raw.push_back((uint8_t)(color[3] * 255.0f));
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001210 break;
1211 default:
1212 break;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001213 }
1214
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001215 return raw;
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001216 }
Chia-I Wuf7ff6b42014-11-22 16:24:41 +08001217
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 std::vector<uint8_t> color_to_raw(VkFormat format, const uint32_t color[4])
Chia-I Wu9feab842014-12-22 13:19:08 +08001219 {
1220 std::vector<uint8_t> raw;
1221
1222 // TODO support all formats
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001223 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001224 case VK_FORMAT_R8G8B8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001225 raw.push_back(static_cast<uint8_t>(color[0]));
1226 raw.push_back(static_cast<uint8_t>(color[1]));
1227 raw.push_back(static_cast<uint8_t>(color[2]));
1228 raw.push_back(static_cast<uint8_t>(color[3]));
1229 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001230 case VK_FORMAT_B8G8R8A8_UNORM:
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001231 raw.push_back(static_cast<uint8_t>(color[2]));
1232 raw.push_back(static_cast<uint8_t>(color[1]));
1233 raw.push_back(static_cast<uint8_t>(color[0]));
1234 raw.push_back(static_cast<uint8_t>(color[3]));
1235 break;
1236 default:
1237 break;
Chia-I Wu9feab842014-12-22 13:19:08 +08001238 }
1239
1240 return raw;
1241 }
1242
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001243 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColor &color)
Chia-I Wu9feab842014-12-22 13:19:08 +08001244 {
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001245 if (color.useRawValue)
1246 return color_to_raw(format, color.color.rawColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001247 else
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001248 return color_to_raw(format, color.color.floatColor);
Chia-I Wu9feab842014-12-22 13:19:08 +08001249 }
1250
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001251 void test_clear_color_image(const VkImageCreateInfo &img_info,
1252 const VkClearColor &clear_color,
1253 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wucb67c652014-10-21 11:06:26 +08001254 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001255 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001256 VkMemoryPropertyFlags image_reqs =
1257 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001258
Tony Barbour43cdc952015-05-21 13:26:05 -06001259 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001260 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001261 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001262 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1263 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1264 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001265 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001266 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001267 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001268 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1269 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1270 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1271 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1272 VK_MEMORY_INPUT_SHADER_READ_BIT |
1273 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1274 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001275 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wucb67c652014-10-21 11:06:26 +08001276
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001277 std::vector<VkImageMemoryBarrier> to_clear;
1278 std::vector<VkImageMemoryBarrier *> p_to_clear;
1279 std::vector<VkImageMemoryBarrier> to_xfer;
1280 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wucb67c652014-10-21 11:06:26 +08001281
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001282 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001283 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001284 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001285 VK_IMAGE_LAYOUT_GENERAL,
1286 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001287 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001288 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001289 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001290 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1291 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001292 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wucb67c652014-10-21 11:06:26 +08001293 }
1294
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001295 cmd_.begin();
Chia-I Wu9feab842014-12-22 13:19:08 +08001296
Tony Barbour8205d902015-04-16 15:59:00 -06001297 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1298 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 +00001299
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001300 vkCmdClearColorImage(cmd_.obj(),
1301 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06001302 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001303
Tony Barbour8205d902015-04-16 15:59:00 -06001304 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 +08001305
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001306 cmd_.end();
1307
1308 submit_and_done();
1309
1310 // cannot verify
1311 if (!img.transparent() && !img.copyable())
1312 return;
1313
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001315
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001316 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001317 if (solid_pattern.empty())
1318 return;
1319
1320 checker.set_solid_pattern(solid_pattern);
1321 check_dst(img, checker);
1322 }
Chia-I Wu9feab842014-12-22 13:19:08 +08001323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001324 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001325 const float color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001326 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu9feab842014-12-22 13:19:08 +08001327 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001329 memcpy(c.color.floatColor, color, sizeof(c.color.floatColor));
Chia-I Wu9feab842014-12-22 13:19:08 +08001330 test_clear_color_image(img_info, c, ranges);
1331 }
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001332};
1333
Tony Barbour01999182015-04-09 12:58:51 -06001334TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001335{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001337 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001338 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barbour2275eb42015-06-05 12:53:55 -06001339 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001340 VkResult err;
1341
Chris Forbesd7576302015-06-21 22:55:02 +12001342 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001343 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001344
Tony Barbour2275eb42015-06-05 12:53:55 -06001345 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1346 continue;
1347
1348 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1349 continue;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001350
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001351 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001352 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001353 img_info.format = it->format;
1354 img_info.extent.width = 64;
1355 img_info.extent.height = 64;
1356 img_info.tiling = it->tiling;
Tony Barbour2275eb42015-06-05 12:53:55 -06001357 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001358
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001359 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001360 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001361 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001362
1363 test_clear_color_image(img_info, color, ranges);
Chia-I Wucb67c652014-10-21 11:06:26 +08001364 }
1365}
1366
Tony Barbour01999182015-04-09 12:58:51 -06001367class VkCmdClearColorImageRawTest : public VkCmdClearColorImageTest {
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001368protected:
Tony Barbour01999182015-04-09 12:58:51 -06001369 VkCmdClearColorImageRawTest() : VkCmdClearColorImageTest(true) {}
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001370
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371 void test_clear_color_image_raw(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001372 const uint32_t color[4],
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001373 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001374 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001375 VkClearColor c = {};
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -06001376 c.useRawValue = true;
1377 memcpy(c.color.rawColor, color, sizeof(c.color.rawColor));
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001378 test_clear_color_image(img_info, c, ranges);
1379 }
1380};
1381
Tony Barbour01999182015-04-09 12:58:51 -06001382TEST_F(VkCmdClearColorImageRawTest, Basic)
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001383{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001384 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001385 it != test_formats_.end(); it++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001386 const uint32_t color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 };
Tony Barbour2275eb42015-06-05 12:53:55 -06001387 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001388 VkResult err;
1389
Chris Forbesd7576302015-06-21 22:55:02 +12001390 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001391 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001392
Tony Barbour2275eb42015-06-05 12:53:55 -06001393 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1394 continue;
1395
1396 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1397 continue;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001398
1399 // not sure what to do here
Tony Barbour8205d902015-04-16 15:59:00 -06001400 if (it->format == VK_FORMAT_UNDEFINED ||
1401 (it->format >= VK_FORMAT_R8G8B8_UNORM &&
1402 it->format <= VK_FORMAT_R8G8B8_SRGB) ||
1403 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1404 it->format <= VK_FORMAT_B8G8R8_SRGB) ||
1405 (it->format >= VK_FORMAT_R16G16B16_UNORM &&
1406 it->format <= VK_FORMAT_R16G16B16_SFLOAT) ||
1407 (it->format >= VK_FORMAT_R32G32B32_UINT &&
1408 it->format <= VK_FORMAT_R32G32B32_SFLOAT) ||
1409 it->format == VK_FORMAT_R64G64B64_SFLOAT ||
1410 it->format == VK_FORMAT_R64G64B64A64_SFLOAT ||
1411 (it->format >= VK_FORMAT_D16_UNORM &&
1412 it->format <= VK_FORMAT_D32_SFLOAT_S8_UINT))
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001413 continue;
1414
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001415 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001416 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001417 img_info.format = it->format;
1418 img_info.extent.width = 64;
1419 img_info.extent.height = 64;
1420 img_info.tiling = it->tiling;
Tony Barbour2275eb42015-06-05 12:53:55 -06001421 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001422
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001424 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001425 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu8dbe8562014-12-22 13:44:24 +08001426
1427 test_clear_color_image_raw(img_info, color, ranges);
1428 }
1429}
1430
Tony Barbour01999182015-04-09 12:58:51 -06001431class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001432protected:
1433 virtual void SetUp()
1434 {
Tony Barbour01999182015-04-09 12:58:51 -06001435 VkCmdBlitTest::SetUp();
Tony Barbour8205d902015-04-16 15:59:00 -06001436 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001437 ASSERT_NE(true, test_formats_.empty());
1438 }
1439
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001440 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001441 {
1442 std::vector<uint8_t> raw;
1443
1444 // depth
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001445 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001446 case VK_FORMAT_D16_UNORM:
1447 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001448 {
Tony Barbourb223d482015-06-09 13:40:53 -06001449 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001450 raw.push_back(unorm & 0xff);
1451 raw.push_back(unorm >> 8);
1452 }
1453 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001454 case VK_FORMAT_D32_SFLOAT:
1455 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001456 {
1457 const union {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001458 float depth;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001459 uint32_t u32;
1460 } u = { depth };
1461
1462 raw.push_back((u.u32 ) & 0xff);
1463 raw.push_back((u.u32 >> 8) & 0xff);
1464 raw.push_back((u.u32 >> 16) & 0xff);
1465 raw.push_back((u.u32 >> 24) & 0xff);
1466 }
1467 break;
1468 default:
1469 break;
1470 }
1471
1472 // stencil
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001473 switch (format) {
Tony Barbour8205d902015-04-16 15:59:00 -06001474 case VK_FORMAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001475 raw.push_back(stencil);
1476 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001477 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001478 raw.push_back(stencil);
1479 raw.push_back(0);
1480 break;
Tony Barbour8205d902015-04-16 15:59:00 -06001481 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001482 raw.push_back(stencil);
1483 raw.push_back(0);
1484 raw.push_back(0);
1485 raw.push_back(0);
1486 break;
1487 default:
1488 break;
1489 }
1490
1491 return raw;
1492 }
1493
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001494 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001495 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001496 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001497 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001498 vk_testing::Image img;
Tony Barbour43cdc952015-05-21 13:26:05 -06001499 VkMemoryPropertyFlags image_reqs =
1500 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour94310562015-04-22 15:10:33 -06001501
Tony Barbour43cdc952015-05-21 13:26:05 -06001502 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001503 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001504 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001505 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1506 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1507 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001508 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001509 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -06001510 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001511 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1512 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1513 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1514 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1515 VK_MEMORY_INPUT_SHADER_READ_BIT |
1516 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1517 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -06001518 VK_MEMORY_INPUT_TRANSFER_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001519
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001520 std::vector<VkImageMemoryBarrier> to_clear;
1521 std::vector<VkImageMemoryBarrier *> p_to_clear;
1522 std::vector<VkImageMemoryBarrier> to_xfer;
1523 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001524
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001525 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001526 it != ranges.end(); it++) {
Mike Stroyan55658c22014-12-04 11:08:39 +00001527 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001528 VK_IMAGE_LAYOUT_GENERAL,
1529 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Mike Stroyan55658c22014-12-04 11:08:39 +00001530 *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001531 p_to_clear.push_back(&to_clear.back());
Mike Stroyan55658c22014-12-04 11:08:39 +00001532 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001533 VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
1534 VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
Mark Lobodzinskid3eabd72015-01-29 14:24:14 -06001535 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001536 }
1537
1538 cmd_.begin();
Mike Stroyan55658c22014-12-04 11:08:39 +00001539
Tony Barbour8205d902015-04-16 15:59:00 -06001540 VkPipeEvent set_events[] = { VK_PIPE_EVENT_COMMANDS_COMPLETE };
1541 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 +00001542
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001543 vkCmdClearDepthStencil(cmd_.obj(),
1544 img.obj(), VK_IMAGE_LAYOUT_CLEAR_OPTIMAL,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001545 depth, stencil,
1546 ranges.size(), &ranges[0]);
Mike Stroyan55658c22014-12-04 11:08:39 +00001547
Tony Barbour8205d902015-04-16 15:59:00 -06001548 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 +00001549
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001550 cmd_.end();
1551
1552 submit_and_done();
1553
1554 // cannot verify
1555 if (!img.transparent() && !img.copyable())
1556 return;
1557
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001558 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001559
1560 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1561 check_dst(img, checker);
1562 }
1563};
1564
Tony Barbour01999182015-04-09 12:58:51 -06001565TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001566{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001567 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001568 it != test_formats_.end(); it++) {
Tony Barbour2275eb42015-06-05 12:53:55 -06001569 VkFormatProperties props;
Tony Barbour2275eb42015-06-05 12:53:55 -06001570 VkResult err;
1571
Chris Forbesd7576302015-06-21 22:55:02 +12001572 err = vkGetPhysicalDeviceFormatInfo(dev_.gpu().obj(), it->format, &props);
Tony Barbour2275eb42015-06-05 12:53:55 -06001573 ASSERT_EQ(err, VK_SUCCESS);
Chris Forbesd7576302015-06-21 22:55:02 +12001574
Tony Barbour2275eb42015-06-05 12:53:55 -06001575 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1576 continue;
1577
1578 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1579 continue;
1580
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001581 // known driver issues
Tony Barbour8205d902015-04-16 15:59:00 -06001582 if (it->format == VK_FORMAT_S8_UINT ||
1583 it->format == VK_FORMAT_D24_UNORM ||
1584 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1585 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001586 continue;
1587
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001588 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbour8205d902015-04-16 15:59:00 -06001589 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001590 img_info.format = it->format;
1591 img_info.extent.width = 64;
1592 img_info.extent.height = 64;
1593 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001594 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001595
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001596 const VkImageSubresourceRange range =
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001597 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001598 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001599
Tony Barbourb223d482015-06-09 13:40:53 -06001600 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1601 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1602 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
1603 const VkImageSubresourceRange range2 =
1604 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_STENCIL);
1605 ranges.push_back(range2);
1606 }
1607
1608
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001609 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1610 }
1611}
1612
1613}; // namespace
1614
Chia-I Wucb67c652014-10-21 11:06:26 +08001615int main(int argc, char **argv)
1616{
Chia-I Wucb67c652014-10-21 11:06:26 +08001617 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wucb67c652014-10-21 11:06:26 +08001618
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001619 vk_testing::set_error_callback(test_error_callback);
Chia-I Wu9dac52d2014-12-27 22:04:00 +08001620
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001621 environment = new vk_testing::Environment();
Chia-I Wucb67c652014-10-21 11:06:26 +08001622
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001623 if (!environment->parse_args(argc, argv))
1624 return -1;
Chia-I Wucb67c652014-10-21 11:06:26 +08001625
Chia-I Wu6170c9e2014-12-08 14:30:10 +08001626 ::testing::AddGlobalTestEnvironment(environment);
1627
1628 return RUN_ALL_TESTS();
Chia-I Wucb67c652014-10-21 11:06:26 +08001629}