blob: 967d75a6ea8d03f402dec27e4b2acd2716e9abad [file] [log] [blame]
Chia-I Wud7414b02014-10-21 11:06:26 +08001//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06002// Copyright (C) 2015 Valve Corporation
Chia-I Wud7414b02014-10-21 11:06:26 +08003//
Chia-I Wu998c2ac2014-12-08 14:30:10 +08004// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
Chia-I Wud7414b02014-10-21 11:06:26 +080010//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080011// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
Chia-I Wud7414b02014-10-21 11:06:26 +080013//
Chia-I Wu998c2ac2014-12-08 14:30:10 +080014// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060021//
22// Author: Chia-I Wu <olv@lunarg.com>
23// Author: Jeremy Hayes <jeremy@lunarg.com>
24// Author: Mike Stroyan <mike@LunarG.com>
Chia-I Wud7414b02014-10-21 11:06:26 +080025
26// Blit (copy, clear, and resolve) tests
27
Tony Barbour048f2812015-06-09 13:40:53 -060028#include "math.h"
Chia-I Wua9a506a2014-12-27 22:04:00 +080029#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060030#include "vktestbinding.h"
Tony Barbour92400bb2015-03-02 16:38:52 -070031#include "test_environment.h"
Chia-I Wud7414b02014-10-21 11:06:26 +080032
33#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
34
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060035namespace vk_testing {
Chia-I Wud7414b02014-10-21 11:06:26 +080036
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060037size_t get_format_size(VkFormat format);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080038
Chia-I Wu998c2ac2014-12-08 14:30:10 +080039class ImageChecker {
40public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060041 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080042 : info_(info), regions_(regions), pattern_(HASH) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060043 explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges);
44 explicit ImageChecker(const VkImageCreateInfo &info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +080045
46 void set_solid_pattern(const std::vector<uint8_t> &solid);
47
Tony Barbourd1c35722015-04-16 15:59:00 -060048 VkDeviceSize buffer_size() const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080049 bool fill(Buffer &buf) const { return walk(FILL, buf); }
50 bool fill(Image &img) const { return walk(FILL, img); }
51 bool check(Buffer &buf) const { return walk(CHECK, buf); }
52 bool check(Image &img) const { return walk(CHECK, img); }
53
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060054 const std::vector<VkBufferImageCopy> &regions() const { return regions_; }
Chia-I Wu998c2ac2014-12-08 14:30:10 +080055
56 static void hash_salt_generate() { hash_salt_++; }
57
58private:
59 enum Action {
60 FILL,
61 CHECK,
62 };
63
64 enum Pattern {
65 HASH,
66 SOLID,
67 };
68
Mark Lobodzinski17caf572015-01-29 08:55:56 -060069 size_t buffer_cpp() const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060070 VkSubresourceLayout buffer_layout(const VkBufferImageCopy &region) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080071
72 bool walk(Action action, Buffer &buf) const;
73 bool walk(Action action, Image &img) const;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060074 bool walk_region(Action action, const VkBufferImageCopy &region, const VkSubresourceLayout &layout, void *data) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080075
Chia-I Wu1b99bb22015-10-27 19:25:11 +080076 std::vector<uint8_t> pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080077
78 static uint32_t hash_salt_;
79
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060080 VkImageCreateInfo info_;
81 std::vector<VkBufferImageCopy> regions_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080082
83 Pattern pattern_;
84 std::vector<uint8_t> pattern_solid_;
85};
86
Chia-I Wud7414b02014-10-21 11:06:26 +080087
Chia-I Wu998c2ac2014-12-08 14:30:10 +080088uint32_t ImageChecker::hash_salt_;
89
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060090ImageChecker::ImageChecker(const VkImageCreateInfo &info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +080091 : info_(info), regions_(), pattern_(HASH)
92{
93 // create a region for every mip level in array slice 0
Tony Barbourd1c35722015-04-16 15:59:00 -060094 VkDeviceSize offset = 0;
Mark Lobodzinski17caf572015-01-29 08:55:56 -060095 for (uint32_t lv = 0; lv < info_.mipLevels; lv++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060096 VkBufferImageCopy region = {};
Chia-I Wu998c2ac2014-12-08 14:30:10 +080097
Chia-I Wu1a28fe02015-01-01 07:55:04 +080098 region.bufferOffset = offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +080099 region.imageSubresource.mipLevel = lv;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600100 region.imageSubresource.baseArrayLayer = 0;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800101 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800102
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600103 if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600104 if (info_.format != VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800105 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800106 regions_.push_back(region);
107 }
108
Tony Barbourd1c35722015-04-16 15:59:00 -0600109 if (info_.format == VK_FORMAT_D16_UNORM_S8_UINT ||
110 info_.format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
111 info_.format == VK_FORMAT_S8_UINT) {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800112 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800113 regions_.push_back(region);
114 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800115 } else {
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800116 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800117 regions_.push_back(region);
118 }
119
120 offset += buffer_layout(region).size;
121 }
122
123 // arraySize should be limited in our tests. If this proves to be an
124 // issue, we can store only the regions for array slice 0 and be smart.
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600125 if (info_.arrayLayers > 1) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600126 const VkDeviceSize slice_pitch = offset;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600127 const uint32_t slice_region_count = regions_.size();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800128
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600129 regions_.reserve(slice_region_count * info_.arrayLayers);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800130
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600131 for (uint32_t slice = 1; slice < info_.arrayLayers; slice++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600132 for (uint32_t i = 0; i < slice_region_count; i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600133 VkBufferImageCopy region = regions_[i];
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800134
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800135 region.bufferOffset += slice_pitch * slice;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600136 region.imageSubresource.baseArrayLayer = slice;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800137 regions_.push_back(region);
138 }
139 }
140 }
141}
142
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600143ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800144 : info_(info), regions_(), pattern_(HASH)
145{
Tony Barbourd1c35722015-04-16 15:59:00 -0600146 VkDeviceSize offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600147 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800148 it != ranges.end(); it++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800149 for (uint32_t lv = 0; lv < it->levelCount; lv++) {
150 for (uint32_t layer = 0; layer < it->layerCount; layer++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600151 VkBufferImageCopy region = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800152 region.bufferOffset = offset;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600153 region.imageSubresource = Image::subresource(*it, lv, layer, 1);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800154 region.imageExtent = Image::extent(info_.extent, lv);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800155
156 regions_.push_back(region);
157
158 offset += buffer_layout(region).size;
159 }
160 }
161 }
162}
163
164void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid)
165{
166 pattern_ = SOLID;
Chia-I Wu72e34332014-12-21 14:59:04 +0800167 pattern_solid_.clear();
168 pattern_solid_.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600169 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800170 pattern_solid_.push_back(solid[i % solid.size()]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800171}
172
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600173size_t ImageChecker::buffer_cpp() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800174{
175 return get_format_size(info_.format);
176}
177
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600178VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy &region) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800179{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600180 VkSubresourceLayout layout = {};
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800181 layout.offset = region.bufferOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800182 layout.rowPitch = buffer_cpp() * region.imageExtent.width;
183 layout.depthPitch = layout.rowPitch * region.imageExtent.height;
Jon Ashburn2b2f90c2015-12-30 14:39:53 -0700184 layout.arrayPitch = layout.depthPitch;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800185 layout.size = layout.depthPitch * region.imageExtent.depth;
186
187 return layout;
188}
189
Tony Barbourd1c35722015-04-16 15:59:00 -0600190VkDeviceSize ImageChecker::buffer_size() const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800191{
Tony Barbourd1c35722015-04-16 15:59:00 -0600192 VkDeviceSize size = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800193
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600194 for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800195 it != regions_.end(); it++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600196 const VkSubresourceLayout layout = buffer_layout(*it);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800197 if (size < layout.offset + layout.size)
198 size = layout.offset + layout.size;
199 }
200
201 return size;
202}
203
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600204bool ImageChecker::walk_region(Action action, const VkBufferImageCopy &region,
205 const VkSubresourceLayout &layout, void *data) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800206{
Jon Ashburn2b2f90c2015-12-30 14:39:53 -0700207 //TODO handle array layers > 1
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600208 for (int32_t z = 0; z < region.imageExtent.depth; z++) {
209 for (int32_t y = 0; y < region.imageExtent.height; y++) {
210 for (int32_t x = 0; x < region.imageExtent.width; x++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800211 uint8_t *dst = static_cast<uint8_t *>(data);
212 dst += layout.offset + layout.depthPitch * z +
213 layout.rowPitch * y + buffer_cpp() * x;
214
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600215 VkOffset3D offset = region.imageOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800216 offset.x += x;
217 offset.y += y;
218 offset.z += z;
219
220 const std::vector<uint8_t> &val = (pattern_ == HASH) ?
221 pattern_hash(region.imageSubresource, offset) :
222 pattern_solid_;
223 assert(val.size() == buffer_cpp());
224
225 if (action == FILL) {
226 memcpy(dst, &val[0], val.size());
227 } else {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600228 for (size_t i = 0; i < val.size(); i++) {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800229 EXPECT_EQ(val[i], dst[i]) <<
Cody Northrop28026d42015-08-06 13:17:52 -0600230 "Offset is: (" << x << ", " << y << ", " << z << ")\n"
231 "Format is: (" << info_.format << ")\n";
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800232 if (val[i] != dst[i])
233 return false;
234 }
235 }
236 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800237 }
238 }
239
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800240 return true;
Chia-I Wud7414b02014-10-21 11:06:26 +0800241}
242
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800243bool ImageChecker::walk(Action action, Buffer &buf) const
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800244{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800245 void *data = buf.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800246 if (!data)
247 return false;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800248
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600249 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800250 for (it = regions_.begin(); it != regions_.end(); it++) {
251 if (!walk_region(action, *it, buffer_layout(*it), data))
252 break;
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800253 }
254
Chia-I Wu681d7a02015-07-03 13:44:34 +0800255 buf.memory().unmap();
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800256
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800257 return (it == regions_.end());
Chia-I Wu5b22bc72014-11-22 02:51:25 +0800258}
259
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800260bool ImageChecker::walk(Action action, Image &img) const
261{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800262 void *data = img.memory().map();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800263 if (!data)
264 return false;
265
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 std::vector<VkBufferImageCopy>::const_iterator it;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800267 for (it = regions_.begin(); it != regions_.end(); it++) {
268 if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data))
269 break;
270 }
271
Chia-I Wu681d7a02015-07-03 13:44:34 +0800272 img.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800273
274 return (it == regions_.end());
275}
276
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800277std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800278{
279#define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff)
280#define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3)
281 const unsigned char input[] = {
282 HASH_BYTES(hash_salt_),
283 HASH_BYTES(subres.mipLevel),
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600284 HASH_BYTES(subres.baseArrayLayer),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800285 HASH_BYTES(offset.x),
286 HASH_BYTES(offset.y),
287 HASH_BYTES(offset.z),
288 };
289 unsigned long hash = 5381;
290
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600291 for (int32_t i = 0; i < ARRAY_SIZE(input); i++)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800292 hash = ((hash << 5) + hash) + input[i];
293
294 const uint8_t output[4] = { HASH_BYTES(hash) };
295#undef HASH_BYTES
296#undef HASH_BYTE
297
Chia-I Wu72e34332014-12-21 14:59:04 +0800298 std::vector<uint8_t> val;
299 val.reserve(buffer_cpp());
Tony Barbourfc3820f2015-05-14 17:15:33 -0600300 for (size_t i = 0; i < buffer_cpp(); i++)
Chia-I Wu72e34332014-12-21 14:59:04 +0800301 val.push_back(output[i % 4]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800302
303 return val;
304}
305
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600306size_t get_format_size(VkFormat format)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800307{
Tony Barbourfc3820f2015-05-14 17:15:33 -0600308 static bool format_table_unverified = true;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800309 static const struct format_info {
Courtney Goeltzenleuchterf3387652015-07-08 18:41:08 -0600310 VkFormat format;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600311 size_t size;
312 uint32_t channel_count;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800313 } format_table[VK_FORMAT_RANGE_SIZE] = {
Tony Barbourfc3820f2015-05-14 17:15:33 -0600314 { VK_FORMAT_UNDEFINED, 0, 0 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800315 { VK_FORMAT_R4G4_UNORM_PACK8, 1, 2 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800316 { VK_FORMAT_R4G4B4A4_UNORM_PACK16, 2, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800317 { VK_FORMAT_B4G4R4A4_UNORM_PACK16, 2, 4 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800318 { VK_FORMAT_R5G6B5_UNORM_PACK16, 2, 3 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800319 { VK_FORMAT_B5G6R5_UNORM_PACK16, 2, 3 },
Chia-I Wucaa5aaa2015-11-10 17:01:22 +0800320 { VK_FORMAT_R5G5B5A1_UNORM_PACK16, 2, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800321 { VK_FORMAT_B5G5R5A1_UNORM_PACK16, 2, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800322 { VK_FORMAT_A1R5G5B5_UNORM_PACK16, 2, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600323 { VK_FORMAT_R8_UNORM, 1, 1 },
324 { VK_FORMAT_R8_SNORM, 1, 1 },
325 { VK_FORMAT_R8_USCALED, 1, 1 },
326 { VK_FORMAT_R8_SSCALED, 1, 1 },
327 { VK_FORMAT_R8_UINT, 1, 1 },
328 { VK_FORMAT_R8_SINT, 1, 1 },
329 { VK_FORMAT_R8_SRGB, 1, 1 },
330 { VK_FORMAT_R8G8_UNORM, 2, 2 },
331 { VK_FORMAT_R8G8_SNORM, 2, 2 },
332 { VK_FORMAT_R8G8_USCALED, 2, 2 },
333 { VK_FORMAT_R8G8_SSCALED, 2, 2 },
334 { VK_FORMAT_R8G8_UINT, 2, 2 },
335 { VK_FORMAT_R8G8_SINT, 2, 2 },
336 { VK_FORMAT_R8G8_SRGB, 2, 2 },
337 { VK_FORMAT_R8G8B8_UNORM, 3, 3 },
338 { VK_FORMAT_R8G8B8_SNORM, 3, 3 },
339 { VK_FORMAT_R8G8B8_USCALED, 3, 3 },
340 { VK_FORMAT_R8G8B8_SSCALED, 3, 3 },
341 { VK_FORMAT_R8G8B8_UINT, 3, 3 },
342 { VK_FORMAT_R8G8B8_SINT, 3, 3 },
343 { VK_FORMAT_R8G8B8_SRGB, 3, 3 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800344 { VK_FORMAT_B8G8R8_UNORM, 3, 3 },
345 { VK_FORMAT_B8G8R8_SNORM, 3, 3 },
346 { VK_FORMAT_B8G8R8_USCALED, 3, 3 },
347 { VK_FORMAT_B8G8R8_SSCALED, 3, 3 },
348 { VK_FORMAT_B8G8R8_UINT, 3, 3 },
349 { VK_FORMAT_B8G8R8_SINT, 3, 3 },
350 { VK_FORMAT_B8G8R8_SRGB, 3, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600351 { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 },
352 { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 },
353 { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 },
354 { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 },
355 { VK_FORMAT_R8G8B8A8_UINT, 4, 4 },
356 { VK_FORMAT_R8G8B8A8_SINT, 4, 4 },
357 { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800358 { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 },
359 { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 },
360 { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 },
361 { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 },
362 { VK_FORMAT_B8G8R8A8_UINT, 4, 4 },
363 { VK_FORMAT_B8G8R8A8_SINT, 4, 4 },
364 { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800365 { VK_FORMAT_A8B8G8R8_UNORM_PACK32, 4, 4 },
366 { VK_FORMAT_A8B8G8R8_SNORM_PACK32, 4, 4 },
367 { VK_FORMAT_A8B8G8R8_USCALED_PACK32, 4, 4 },
368 { VK_FORMAT_A8B8G8R8_SSCALED_PACK32, 4, 4 },
369 { VK_FORMAT_A8B8G8R8_UINT_PACK32, 4, 4 },
370 { VK_FORMAT_A8B8G8R8_SINT_PACK32, 4, 4 },
371 { VK_FORMAT_A8B8G8R8_SRGB_PACK32, 4, 4 },
Chia-I Wu08bee5e2015-11-10 17:01:22 +0800372 { VK_FORMAT_A2R10G10B10_UNORM_PACK32, 4, 4 },
373 { VK_FORMAT_A2R10G10B10_SNORM_PACK32, 4, 4 },
374 { VK_FORMAT_A2R10G10B10_USCALED_PACK32, 4, 4 },
375 { VK_FORMAT_A2R10G10B10_SSCALED_PACK32, 4, 4 },
376 { VK_FORMAT_A2R10G10B10_UINT_PACK32, 4, 4 },
377 { VK_FORMAT_A2R10G10B10_SINT_PACK32, 4, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800378 { VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 4 },
379 { VK_FORMAT_A2B10G10R10_SNORM_PACK32, 4, 4 },
380 { VK_FORMAT_A2B10G10R10_USCALED_PACK32, 4, 4 },
381 { VK_FORMAT_A2B10G10R10_SSCALED_PACK32, 4, 4 },
382 { VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 4 },
383 { VK_FORMAT_A2B10G10R10_SINT_PACK32, 4, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600384 { VK_FORMAT_R16_UNORM, 2, 1 },
385 { VK_FORMAT_R16_SNORM, 2, 1 },
386 { VK_FORMAT_R16_USCALED, 2, 1 },
387 { VK_FORMAT_R16_SSCALED, 2, 1 },
388 { VK_FORMAT_R16_UINT, 2, 1 },
389 { VK_FORMAT_R16_SINT, 2, 1 },
390 { VK_FORMAT_R16_SFLOAT, 2, 1 },
391 { VK_FORMAT_R16G16_UNORM, 4, 2 },
392 { VK_FORMAT_R16G16_SNORM, 4, 2 },
393 { VK_FORMAT_R16G16_USCALED, 4, 2 },
394 { VK_FORMAT_R16G16_SSCALED, 4, 2 },
395 { VK_FORMAT_R16G16_UINT, 4, 2 },
396 { VK_FORMAT_R16G16_SINT, 4, 2 },
397 { VK_FORMAT_R16G16_SFLOAT, 4, 2 },
398 { VK_FORMAT_R16G16B16_UNORM, 6, 3 },
399 { VK_FORMAT_R16G16B16_SNORM, 6, 3 },
400 { VK_FORMAT_R16G16B16_USCALED, 6, 3 },
401 { VK_FORMAT_R16G16B16_SSCALED, 6, 3 },
402 { VK_FORMAT_R16G16B16_UINT, 6, 3 },
403 { VK_FORMAT_R16G16B16_SINT, 6, 3 },
404 { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 },
405 { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 },
406 { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 },
407 { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 },
408 { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 },
409 { VK_FORMAT_R16G16B16A16_UINT, 8, 4 },
410 { VK_FORMAT_R16G16B16A16_SINT, 8, 4 },
411 { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 },
412 { VK_FORMAT_R32_UINT, 4, 1 },
413 { VK_FORMAT_R32_SINT, 4, 1 },
414 { VK_FORMAT_R32_SFLOAT, 4, 1 },
415 { VK_FORMAT_R32G32_UINT, 8, 2 },
416 { VK_FORMAT_R32G32_SINT, 8, 2 },
417 { VK_FORMAT_R32G32_SFLOAT, 8, 2 },
418 { VK_FORMAT_R32G32B32_UINT, 12, 3 },
419 { VK_FORMAT_R32G32B32_SINT, 12, 3 },
420 { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 },
421 { VK_FORMAT_R32G32B32A32_UINT, 16, 4 },
422 { VK_FORMAT_R32G32B32A32_SINT, 16, 4 },
423 { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800424 { VK_FORMAT_R64_UINT, 8, 1 },
425 { VK_FORMAT_R64_SINT, 8, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600426 { VK_FORMAT_R64_SFLOAT, 8, 1 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800427 { VK_FORMAT_R64G64_UINT, 16, 2 },
428 { VK_FORMAT_R64G64_SINT, 16, 2 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600429 { VK_FORMAT_R64G64_SFLOAT, 16, 2 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800430 { VK_FORMAT_R64G64B64_UINT, 24, 3 },
431 { VK_FORMAT_R64G64B64_SINT, 24, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600432 { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 },
Chia-I Wu0a84a702015-11-10 17:01:22 +0800433 { VK_FORMAT_R64G64B64A64_UINT, 32, 4 },
434 { VK_FORMAT_R64G64B64A64_SINT, 32, 4 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600435 { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800436 { VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4, 3 },
437 { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, 4, 3 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600438 { VK_FORMAT_D16_UNORM, 2, 1 },
Chia-I Wu935f2ed2015-11-10 17:01:22 +0800439 { VK_FORMAT_X8_D24_UNORM_PACK32, 3, 1 },
Tony Barbourfc3820f2015-05-14 17:15:33 -0600440 { VK_FORMAT_D32_SFLOAT, 4, 1 },
441 { VK_FORMAT_S8_UINT, 1, 1 },
442 { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 },
443 { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 },
Tony Barbour048f2812015-06-09 13:40:53 -0600444 { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 },
Chia-I Wu53638c12015-11-10 16:44:23 +0800445 { VK_FORMAT_BC1_RGB_UNORM_BLOCK, 8, 4 },
446 { VK_FORMAT_BC1_RGB_SRGB_BLOCK, 8, 4 },
447 { VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4 },
448 { VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4 },
449 { VK_FORMAT_BC2_UNORM_BLOCK, 16, 4 },
450 { VK_FORMAT_BC2_SRGB_BLOCK, 16, 4 },
451 { VK_FORMAT_BC3_UNORM_BLOCK, 16, 4 },
452 { VK_FORMAT_BC3_SRGB_BLOCK, 16, 4 },
453 { VK_FORMAT_BC4_UNORM_BLOCK, 8, 4 },
454 { VK_FORMAT_BC4_SNORM_BLOCK, 8, 4 },
455 { VK_FORMAT_BC5_UNORM_BLOCK, 16, 4 },
456 { VK_FORMAT_BC5_SNORM_BLOCK, 16, 4 },
457 { VK_FORMAT_BC6H_UFLOAT_BLOCK, 16, 4 },
458 { VK_FORMAT_BC6H_SFLOAT_BLOCK, 16, 4 },
459 { VK_FORMAT_BC7_UNORM_BLOCK, 16, 4 },
460 { VK_FORMAT_BC7_SRGB_BLOCK, 16, 4 },
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700461 // TODO: Initialize remaining compressed formats.
Chia-I Wu53638c12015-11-10 16:44:23 +0800462 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 0, 0 },
463 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 0, 0 },
464 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 0, 0 },
465 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 0, 0 },
466 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 0, 0 },
467 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 0, 0 },
468 { VK_FORMAT_EAC_R11_UNORM_BLOCK, 0, 0 },
469 { VK_FORMAT_EAC_R11_SNORM_BLOCK, 0, 0 },
470 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 0, 0 },
471 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 0, 0 },
472 { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 0, 0 },
473 { VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 0, 0 },
474 { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 0, 0 },
475 { VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 0, 0 },
476 { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 0, 0 },
477 { VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 0, 0 },
478 { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 0, 0 },
479 { VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 0, 0 },
480 { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 0, 0 },
481 { VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 0, 0 },
482 { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 0, 0 },
483 { VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 0, 0 },
484 { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 0, 0 },
485 { VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 0, 0 },
486 { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 0, 0 },
487 { VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 0, 0 },
488 { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 0, 0 },
489 { VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 0, 0 },
490 { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 0, 0 },
491 { VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 0, 0 },
492 { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 0, 0 },
493 { VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 0, 0 },
494 { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 0, 0 },
495 { VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 0, 0 },
496 { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 0, 0 },
497 { VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 0, 0 },
498 { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 0, 0 },
499 { VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 0, 0 },
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800500 };
Tony Barbourfc3820f2015-05-14 17:15:33 -0600501 if (format_table_unverified)
502 {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800503 for (unsigned int i = 0; i < VK_FORMAT_RANGE_SIZE; i++)
Tony Barbourfc3820f2015-05-14 17:15:33 -0600504 {
505 assert(format_table[i].format == i);
506 }
507 format_table_unverified = false;
508 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800509
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700510 return format_table[format].size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800511}
512
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600513VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800514{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600515 const VkExtent3D ext = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800516 (extent.width >> mip_level) ? extent.width >> mip_level : 1,
517 (extent.height >> mip_level) ? extent.height >> mip_level : 1,
518 (extent.depth >> mip_level) ? extent.depth >> mip_level : 1,
519 };
520
521 return ext;
522}
523
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600524}; // namespace vk_testing
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800525
526namespace {
527
528#define DO(action) ASSERT_EQ(true, action);
529
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600530static vk_testing::Environment *environment;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800531
Tony Barbour6918cd52015-04-09 12:58:51 -0600532class VkCmdBlitTest : public ::testing::Test {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800533protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600534 VkCmdBlitTest() :
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800535 dev_(environment->default_device()),
Chia-I Wua9a506a2014-12-27 22:04:00 +0800536 queue_(*dev_.graphics_queues()[0]),
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 pool_(dev_, vk_testing::CommandPool::create_info(dev_.graphics_queue_node_index_)),
538 cmd_(dev_, vk_testing::CommandBuffer::create_info(pool_.handle()))
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800539 {
540 // make sure every test uses a different pattern
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600541 vk_testing::ImageChecker::hash_salt_generate();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800542 }
543
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800544 bool submit_and_done()
545 {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600546 queue_.submit(cmd_);
Chia-I Wua9a506a2014-12-27 22:04:00 +0800547 queue_.wait();
548 mem_refs_.clear();
549 return true;
550 }
551
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600552 vk_testing::Device &dev_;
553 vk_testing::Queue &queue_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800554 vk_testing::CommandPool pool_;
555 vk_testing::CommandBuffer cmd_;
Chia-I Wua9a506a2014-12-27 22:04:00 +0800556
Chris Forbes9e50dab2015-07-11 19:11:39 +1200557 /* TODO: We should be able to remove these now */
Tony Barbourd1c35722015-04-16 15:59:00 -0600558 std::vector<VkDeviceMemory> mem_refs_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800559};
560
Tony Barbour6918cd52015-04-09 12:58:51 -0600561typedef VkCmdBlitTest VkCmdFillBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800562
Tony Barbour6918cd52015-04-09 12:58:51 -0600563TEST_F(VkCmdFillBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800564{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600566 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800567
Cody Northrop7fb43862015-06-22 14:56:14 -0600568 buf.init_as_dst(dev_, 20, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800569
570 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800571 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 4, 0x11111111);
572 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 4, 16, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800573 cmd_.end();
574
575 submit_and_done();
576
Chia-I Wu681d7a02015-07-03 13:44:34 +0800577 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800578 EXPECT_EQ(0x11111111, data[0]);
579 EXPECT_EQ(0x22222222, data[1]);
580 EXPECT_EQ(0x22222222, data[2]);
581 EXPECT_EQ(0x22222222, data[3]);
582 EXPECT_EQ(0x22222222, data[4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800583 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800584}
585
Tony Barbour6918cd52015-04-09 12:58:51 -0600586TEST_F(VkCmdFillBufferTest, Large)
Chia-I Wud94726f2014-11-23 02:16:45 +0800587{
Tony Barbourd1c35722015-04-16 15:59:00 -0600588 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600589 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600590 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud94726f2014-11-23 02:16:45 +0800591
Cody Northrop7fb43862015-06-22 14:56:14 -0600592 buf.init_as_dst(dev_, size, reqs);
Chia-I Wud94726f2014-11-23 02:16:45 +0800593
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800594 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800595 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, size / 2, 0x11111111);
596 vkCmdFillBuffer(cmd_.handle(), buf.handle(), size / 2, size / 2, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800597 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800598
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800599 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800600
Chia-I Wu681d7a02015-07-03 13:44:34 +0800601 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600602 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800603 for (offset = 0; offset < size / 2; offset += 4)
604 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
605 for (; offset < size; offset += 4)
606 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800607 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800608}
Chia-I Wud94726f2014-11-23 02:16:45 +0800609
Tony Barbour6918cd52015-04-09 12:58:51 -0600610TEST_F(VkCmdFillBufferTest, Overlap)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800611{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600612 vk_testing::Buffer buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600613 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800614
Cody Northrop7fb43862015-06-22 14:56:14 -0600615 buf.init_as_dst(dev_, 64, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800616
617 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800618 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 48, 0x11111111);
619 vkCmdFillBuffer(cmd_.handle(), buf.handle(), 32, 32, 0x22222222);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800620 cmd_.end();
621
622 submit_and_done();
623
Chia-I Wu681d7a02015-07-03 13:44:34 +0800624 const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600625 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800626 for (offset = 0; offset < 32; offset += 4)
627 EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset;
628 for (; offset < 64; offset += 4)
629 EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800630 buf.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800631}
632
Tony Barbour6918cd52015-04-09 12:58:51 -0600633TEST_F(VkCmdFillBufferTest, MultiAlignments)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800634{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600635 vk_testing::Buffer bufs[9];
Tony Barbourd1c35722015-04-16 15:59:00 -0600636 VkDeviceSize size = 4;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600637 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800638
639 cmd_.begin();
640 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600641 bufs[i].init_as_dst(dev_, size, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800642 vkCmdFillBuffer(cmd_.handle(), bufs[i].handle(), 0, size, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800643 size <<= 1;
644 }
645 cmd_.end();
646
647 submit_and_done();
648
649 size = 4;
650 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800651 const uint32_t *data = static_cast<const uint32_t *>(bufs[i].memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600652 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800653 for (offset = 0; offset < size; offset += 4)
654 EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" <<
655 "Offset is: " << offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800656 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800657
658 size <<= 1;
659 }
660}
661
Tony Barbour6918cd52015-04-09 12:58:51 -0600662typedef VkCmdBlitTest VkCmdCopyBufferTest;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800663
Tony Barbour6918cd52015-04-09 12:58:51 -0600664TEST_F(VkCmdCopyBufferTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800665{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600666 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600667 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800668
Cody Northrop7fb43862015-06-22 14:56:14 -0600669 src.init_as_src(dev_, 4, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800670 uint32_t *data = static_cast<uint32_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800671 data[0] = 0x11111111;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800672 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800673
Cody Northrop7fb43862015-06-22 14:56:14 -0600674 dst.init_as_dst(dev_, 4, reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800675
676 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600677 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800678 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800679 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800680 cmd_.end();
681
682 submit_and_done();
683
Chia-I Wu681d7a02015-07-03 13:44:34 +0800684 data = static_cast<uint32_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800685 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800686 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800687}
688
Tony Barbour6918cd52015-04-09 12:58:51 -0600689TEST_F(VkCmdCopyBufferTest, Large)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800690{
Tony Barbourd1c35722015-04-16 15:59:00 -0600691 const VkDeviceSize size = 32 * 1024 * 1024;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600692 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600693 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800694
Cody Northropd2ad0342015-08-05 11:15:02 -0600695 src.init_as_src(dev_, size * sizeof(VkDeviceSize), reqs);
696 VkDeviceSize *data = static_cast<VkDeviceSize *>(src.memory().map());
Tony Barbourd1c35722015-04-16 15:59:00 -0600697 VkDeviceSize offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800698 for (offset = 0; offset < size; offset += 4)
699 data[offset / 4] = offset;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800700 src.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800701
Cody Northropd2ad0342015-08-05 11:15:02 -0600702 dst.init_as_dst(dev_, size * sizeof(VkDeviceSize), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800703
704 cmd_.begin();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600705 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800706 region.size = size * sizeof(VkDeviceSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800707 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, &region);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800708 cmd_.end();
Chia-I Wud94726f2014-11-23 02:16:45 +0800709
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800710 submit_and_done();
Chia-I Wud94726f2014-11-23 02:16:45 +0800711
Cody Northropd2ad0342015-08-05 11:15:02 -0600712 data = static_cast<VkDeviceSize *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800713 for (offset = 0; offset < size; offset += 4)
714 EXPECT_EQ(offset, data[offset / 4]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800715 dst.memory().unmap();
Chia-I Wud94726f2014-11-23 02:16:45 +0800716}
717
Tony Barbour6918cd52015-04-09 12:58:51 -0600718TEST_F(VkCmdCopyBufferTest, MultiAlignments)
Chia-I Wud7414b02014-10-21 11:06:26 +0800719{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600720 const VkBufferCopy regions[] = {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800721 /* well aligned */
722 { 0, 0, 256 },
723 { 0, 256, 128 },
724 { 0, 384, 64 },
725 { 0, 448, 32 },
726 { 0, 480, 16 },
727 { 0, 496, 8 },
Chia-I Wud7414b02014-10-21 11:06:26 +0800728
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800729 /* ill aligned */
730 { 7, 510, 16 },
731 { 16, 530, 13 },
732 { 32, 551, 16 },
733 { 45, 570, 15 },
734 { 50, 590, 1 },
735 };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600736 vk_testing::Buffer src, dst;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600737 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +0800738
Cody Northrop7fb43862015-06-22 14:56:14 -0600739 src.init_as_src(dev_, 256, reqs);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800740 uint8_t *data = static_cast<uint8_t *>(src.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800741 for (int i = 0; i < 256; i++)
742 data[i] = i;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800743 src.memory().unmap();
Chia-I Wud7414b02014-10-21 11:06:26 +0800744
Cody Northrop7fb43862015-06-22 14:56:14 -0600745 dst.init_as_dst(dev_, 1024, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800746
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800747 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800748 vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), ARRAY_SIZE(regions), regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800749 cmd_.end();
Chia-I Wud7414b02014-10-21 11:06:26 +0800750
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800751 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800752
Chia-I Wu681d7a02015-07-03 13:44:34 +0800753 data = static_cast<uint8_t *>(dst.memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800754 for (int i = 0; i < ARRAY_SIZE(regions); i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600755 const VkBufferCopy &r = regions[i];
Chia-I Wud7414b02014-10-21 11:06:26 +0800756
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800757 for (int j = 0; j < r.size; j++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800758 EXPECT_EQ(r.srcOffset + j, data[r.dstOffset + j]) <<
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800759 "Region is: " << i << "\n" <<
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800760 "Offset is: " << r.dstOffset + j;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800761 }
762 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800763 dst.memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800764}
Chia-I Wud7414b02014-10-21 11:06:26 +0800765
Tony Barbour6918cd52015-04-09 12:58:51 -0600766TEST_F(VkCmdCopyBufferTest, RAWHazard)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800767{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600768 vk_testing::Buffer bufs[3];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600769 VkEventCreateInfo event_info;
770 VkEvent event;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600771 VkResult err;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600772 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000773
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600774 // typedef struct VkEventCreateInfo_
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000775 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600776 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600777 // const void* pNext; // Pointer to next structure
778 // VkFlags flags; // Reserved
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600779 // } VkEventCreateInfo;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000780 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600781 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000782
Chia-I Wuf7458c52015-10-26 21:10:41 +0800783 err = vkCreateEvent(dev_.handle(), &event_info, NULL, &event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600784 ASSERT_VK_SUCCESS(err);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000785
Chia-I Wuf368b602015-07-03 10:41:20 +0800786 err = vkResetEvent(dev_.handle(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600787 ASSERT_VK_SUCCESS(err);
Chia-I Wud7414b02014-10-21 11:06:26 +0800788
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800789 for (int i = 0; i < ARRAY_SIZE(bufs); i++) {
Cody Northrop7fb43862015-06-22 14:56:14 -0600790 bufs[i].init_as_src_and_dst(dev_, 4, reqs);
Chia-I Wud7414b02014-10-21 11:06:26 +0800791
Chia-I Wu681d7a02015-07-03 13:44:34 +0800792 uint32_t *data = static_cast<uint32_t *>(bufs[i].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800793 data[0] = 0x22222222 * (i + 1);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800794 bufs[i].memory().unmap();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800795 }
796
797 cmd_.begin();
798
Chia-I Wu681d7a02015-07-03 13:44:34 +0800799 vkCmdFillBuffer(cmd_.handle(), bufs[0].handle(), 0, 4, 0x11111111);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800800 // is this necessary?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600801 VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800802 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600803 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000804
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600805 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
806 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +0800807 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800808
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600809 VkBufferCopy region = {};
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800810 region.size = 4;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800811 vkCmdCopyBuffer(cmd_.handle(), bufs[0].handle(), bufs[1].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000812
813 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800814 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600815 pmemory_barrier = &memory_barrier;
Chia-I Wu53534662015-10-26 17:08:33 +0800816 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800817
Chia-I Wu681d7a02015-07-03 13:44:34 +0800818 vkCmdCopyBuffer(cmd_.handle(), bufs[1].handle(), bufs[2].handle(), 1, &region);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000819
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600820 /* Use vkCmdSetEvent and vkCmdWaitEvents to test them.
821 * This could be vkCmdPipelineBarrier.
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000822 */
Chia-I Wube2b9172015-07-03 11:49:42 +0800823 vkCmdSetEvent(cmd_.handle(), event, VK_PIPELINE_STAGE_TRANSFER_BIT);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000824
825 // Additional commands could go into the buffer here before the wait.
826
827 memory_barrier = bufs[1].buffer_memory_barrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800828 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 0, 4);
Mark Lobodzinski837ef922015-01-29 14:24:14 -0600829 pmemory_barrier = &memory_barrier;
Chia-I Wube2b9172015-07-03 11:49:42 +0800830 vkCmdWaitEvents(cmd_.handle(), 1, &event, src_stages, dest_stages, 1, (const void **)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000831
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800832 cmd_.end();
833
834 submit_and_done();
835
Chia-I Wu681d7a02015-07-03 13:44:34 +0800836 const uint32_t *data = static_cast<const uint32_t *>(bufs[2].memory().map());
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800837 EXPECT_EQ(0x11111111, data[0]);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800838 bufs[2].memory().unmap();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000839
Chia-I Wuf7458c52015-10-26 21:10:41 +0800840 vkDestroyEvent(dev_.handle(), event, NULL);
Tony Barbour7db519b2015-06-26 11:49:05 -0600841
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800842}
843
Tony Barbour6918cd52015-04-09 12:58:51 -0600844class VkCmdBlitImageTest : public VkCmdBlitTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800845protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600846 void init_test_formats(VkFlags features)
Chia-I Wud7414b02014-10-21 11:06:26 +0800847 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600848 first_linear_format_ = VK_FORMAT_UNDEFINED;
849 first_optimal_format_ = VK_FORMAT_UNDEFINED;
Chia-I Wud7414b02014-10-21 11:06:26 +0800850
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600851 for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800852 it != dev_.formats().end(); it++) {
853 if (it->features & features) {
854 test_formats_.push_back(*it);
Chia-I Wud7414b02014-10-21 11:06:26 +0800855
Tony Barbourd1c35722015-04-16 15:59:00 -0600856 if (it->tiling == VK_IMAGE_TILING_LINEAR &&
857 first_linear_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800858 first_linear_format_ = it->format;
Tony Barbourd1c35722015-04-16 15:59:00 -0600859 if (it->tiling == VK_IMAGE_TILING_OPTIMAL &&
860 first_optimal_format_ == VK_FORMAT_UNDEFINED)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800861 first_optimal_format_ = it->format;
862 }
863 }
864 }
Chia-I Wud7414b02014-10-21 11:06:26 +0800865
Chia-I Wu5bc27862014-12-22 13:19:08 +0800866 void init_test_formats()
867 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600868 init_test_formats(static_cast<VkFlags>(-1));
Chia-I Wu5bc27862014-12-22 13:19:08 +0800869 }
870
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600871 void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800872 {
873 if (img.transparent()) {
874 checker.fill(img);
875 return;
Chia-I Wud7414b02014-10-21 11:06:26 +0800876 }
877
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800878 ASSERT_EQ(true, img.copyable());
879
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600880 vk_testing::Buffer in_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600881 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
882
Cody Northrop7fb43862015-06-22 14:56:14 -0600883 in_buf.init_as_src(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800884 checker.fill(in_buf);
885
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800886 // copy in and tile
887 cmd_.begin();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800888 vkCmdCopyBufferToImage(cmd_.handle(), in_buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700889 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800890 checker.regions().size(), &checker.regions()[0]);
891 cmd_.end();
892
893 submit_and_done();
Chia-I Wud7414b02014-10-21 11:06:26 +0800894 }
895
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600896 void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker)
Chia-I Wud6479012014-11-22 15:09:42 +0800897 {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800898 if (img.transparent()) {
899 DO(checker.check(img));
900 return;
Chia-I Wud6479012014-11-22 15:09:42 +0800901 }
902
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800903 ASSERT_EQ(true, img.copyable());
904
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600905 vk_testing::Buffer out_buf;
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600906 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -0600907 out_buf.init_as_dst(dev_, checker.buffer_size(), reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800908
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800909 // copy out and linearize
910 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800911 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700912 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +0800913 out_buf.handle(),
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800914 checker.regions().size(), &checker.regions()[0]);
915 cmd_.end();
916
917 submit_and_done();
918
919 DO(checker.check(out_buf));
Chia-I Wud6479012014-11-22 15:09:42 +0800920 }
921
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600922 std::vector<vk_testing::Device::Format> test_formats_;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600923 VkFormat first_linear_format_;
924 VkFormat first_optimal_format_;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800925};
926
Tony Barbour6918cd52015-04-09 12:58:51 -0600927class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800928protected:
929 virtual void SetUp()
930 {
Tony Barbour6918cd52015-04-09 12:58:51 -0600931 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -0600932 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800933 ASSERT_NE(true, test_formats_.empty());
934 }
935
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600936 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800937 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600938 vk_testing::Buffer buf;
939 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -0600940 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
941 VkMemoryPropertyFlags image_reqs =
942 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800943
Cody Northrop7fb43862015-06-22 14:56:14 -0600944 buf.init_as_src(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800945 checker.fill(buf);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800946
Tony Barbour0c823b12015-05-21 13:26:05 -0600947 img.init(dev_, img_info, image_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800948
949 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +0800950 vkCmdCopyBufferToImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800951 buf.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700952 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800953 checker.regions().size(), &checker.regions()[0]);
954 cmd_.end();
955
956 submit_and_done();
957
958 check_dst(img, checker);
959 }
960
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600961 void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800962 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600963 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800964 test_copy_memory_to_image(img_info, checker);
965 }
966
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600967 void test_copy_memory_to_image(const VkImageCreateInfo &img_info)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800968 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600969 vk_testing::ImageChecker checker(img_info);
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800970 test_copy_memory_to_image(img_info, checker);
971 }
972};
973
Tony Barbour6918cd52015-04-09 12:58:51 -0600974TEST_F(VkCmdCopyBufferToImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800975{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600976 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800977 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700978
979 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -0600980 if (it->format == VK_FORMAT_UNDEFINED ||
981 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
982 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700983 continue;
984
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600985 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600986 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800987 img_info.format = it->format;
988 img_info.extent.width = 64;
989 img_info.extent.height = 64;
990 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800991 img_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
992 VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -0700993 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +0800994
995 test_copy_memory_to_image(img_info);
996 }
Chia-I Wud6479012014-11-22 15:09:42 +0800997}
998
Tony Barbour6918cd52015-04-09 12:58:51 -0600999class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest {
Chia-I Wu42b97b82014-12-13 15:28:20 +08001000protected:
1001 virtual void SetUp()
1002 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001003 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001004 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001005 ASSERT_NE(true, test_formats_.empty());
1006 }
1007
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001008 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001009 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001010 vk_testing::Image img;
1011 vk_testing::Buffer buf;
Tony Barbour0c823b12015-05-21 13:26:05 -06001012 VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1013 VkMemoryPropertyFlags image_reqs =
1014 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001015
Tony Barbour0c823b12015-05-21 13:26:05 -06001016 img.init(dev_, img_info, image_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001017 fill_src(img, checker);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001018
Cody Northrop7fb43862015-06-22 14:56:14 -06001019 buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001020
1021 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001022 vkCmdCopyImageToBuffer(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001023 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Chia-I Wu681d7a02015-07-03 13:44:34 +08001024 buf.handle(),
Chia-I Wu42b97b82014-12-13 15:28:20 +08001025 checker.regions().size(), &checker.regions()[0]);
1026 cmd_.end();
1027
1028 submit_and_done();
1029
1030 checker.check(buf);
1031 }
1032
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001033 void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> &regions)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001034 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001035 vk_testing::ImageChecker checker(img_info, regions);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001036 test_copy_image_to_memory(img_info, checker);
1037 }
1038
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001039 void test_copy_image_to_memory(const VkImageCreateInfo &img_info)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001040 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001041 vk_testing::ImageChecker checker(img_info);
Chia-I Wu42b97b82014-12-13 15:28:20 +08001042 test_copy_image_to_memory(img_info, checker);
1043 }
1044};
1045
Tony Barbour6918cd52015-04-09 12:58:51 -06001046TEST_F(VkCmdCopyImageToBufferTest, Basic)
Chia-I Wu42b97b82014-12-13 15:28:20 +08001047{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001048 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu42b97b82014-12-13 15:28:20 +08001049 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001050
1051 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001052 if (it->format == VK_FORMAT_UNDEFINED ||
1053 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1054 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001055 continue;
1056
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001057 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001058 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001059 img_info.format = it->format;
1060 img_info.extent.width = 64;
1061 img_info.extent.height = 64;
1062 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001063 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1064 VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001065 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu42b97b82014-12-13 15:28:20 +08001066
1067 test_copy_image_to_memory(img_info);
1068 }
1069}
1070
Tony Barbour6918cd52015-04-09 12:58:51 -06001071class VkCmdCopyImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001072protected:
1073 virtual void SetUp()
1074 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001075 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001076 init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001077 ASSERT_NE(true, test_formats_.empty());
Chia-I Wu89078aa2014-11-22 16:24:41 +08001078 }
1079
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001080 void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info,
1081 const std::vector<VkImageCopy> &copies)
Chia-I Wu89078aa2014-11-22 16:24:41 +08001082 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001083 // convert VkImageCopy to two sets of VkBufferImageCopy
1084 std::vector<VkBufferImageCopy> src_regions, dst_regions;
Tony Barbourd1c35722015-04-16 15:59:00 -06001085 VkDeviceSize src_offset = 0, dst_offset = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001086 for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) {
1087 VkBufferImageCopy src_region = {}, dst_region = {};
Chia-I Wu89078aa2014-11-22 16:24:41 +08001088
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001089 src_region.bufferOffset = src_offset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001090 src_region.imageSubresource = it->srcSubresource;
1091 src_region.imageOffset = it->srcOffset;
1092 src_region.imageExtent = it->extent;
1093 src_regions.push_back(src_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001094
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001095 dst_region.bufferOffset = src_offset;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001096 dst_region.imageSubresource = it->dstSubresource;
1097 dst_region.imageOffset = it->dstOffset;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001098 dst_region.imageExtent = it->extent;
1099 dst_regions.push_back(dst_region);
Chia-I Wu89078aa2014-11-22 16:24:41 +08001100
Tony Barbourd1c35722015-04-16 15:59:00 -06001101 const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001102 src_offset += vk_testing::get_format_size(src_info.format) * size;
1103 dst_offset += vk_testing::get_format_size(dst_info.format) * size;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001104 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001105
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001106 vk_testing::ImageChecker src_checker(src_info, src_regions);
1107 vk_testing::ImageChecker dst_checker(dst_info, dst_regions);
Tony Barbour0c823b12015-05-21 13:26:05 -06001108 VkMemoryPropertyFlags src_reqs =
1109 (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1110 VkMemoryPropertyFlags dst_reqs =
1111 (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
1112
1113
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001114
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001115 vk_testing::Image src;
Tony Barbour0c823b12015-05-21 13:26:05 -06001116 src.init(dev_, src_info, src_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001117 fill_src(src, src_checker);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001118
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001119 vk_testing::Image dst;
Tony Barbour0c823b12015-05-21 13:26:05 -06001120 dst.init(dev_, dst_info, dst_reqs);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001121
1122 cmd_.begin();
Chia-I Wube2b9172015-07-03 11:49:42 +08001123 vkCmdCopyImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001124 src.handle(), VK_IMAGE_LAYOUT_GENERAL,
1125 dst.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001126 copies.size(), &copies[0]);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001127 cmd_.end();
1128
1129 submit_and_done();
1130
1131 check_dst(dst, dst_checker);
1132 }
1133};
1134
Tony Barbour6918cd52015-04-09 12:58:51 -06001135TEST_F(VkCmdCopyImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001136{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001137 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001138 it != test_formats_.end(); it++) {
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001139
1140 // not sure what to do here
Tony Barbourd1c35722015-04-16 15:59:00 -06001141 if (it->format == VK_FORMAT_UNDEFINED ||
1142 (it->format >= VK_FORMAT_B8G8R8_UNORM &&
1143 it->format <= VK_FORMAT_B8G8R8_SRGB))
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001144 continue;
1145
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001146 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001147 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001148 img_info.format = it->format;
1149 img_info.extent.width = 64;
1150 img_info.extent.height = 64;
1151 img_info.tiling = it->tiling;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001152 img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001153 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001154
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001155 VkImageCopy copy = {};
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06001156 copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001157 copy.dstSubresource = copy.srcSubresource;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001158 copy.extent = img_info.extent;
1159
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001160 test_copy_image(img_info, img_info, std::vector<VkImageCopy>(&copy, &copy + 1));
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001161 }
1162}
1163
Tony Barbour6918cd52015-04-09 12:58:51 -06001164class VkCmdClearColorImageTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001165protected:
Chris Forbesf0796e12015-06-24 14:34:53 +12001166 VkCmdClearColorImageTest() {}
Chia-I Wu5bc27862014-12-22 13:19:08 +08001167
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001168 virtual void SetUp()
1169 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001170 VkCmdBlitTest::SetUp();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001171
Courtney Goeltzenleuchtercda30342015-09-10 16:25:49 -06001172 init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001173
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001174 ASSERT_NE(true, test_formats_.empty());
1175 }
1176
Chia-I Wu5bc27862014-12-22 13:19:08 +08001177 union Color {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001178 float color[4];
1179 uint32_t raw[4];
Chia-I Wu5bc27862014-12-22 13:19:08 +08001180 };
1181
Chris Forbesf0796e12015-06-24 14:34:53 +12001182 std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001183 {
1184 std::vector<uint8_t> raw;
1185
1186 // TODO support all formats
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001187 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001188 case VK_FORMAT_R8G8B8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001189 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1190 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1191 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1192 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001193 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001194 case VK_FORMAT_B8G8R8A8_UNORM:
Cody Northrop85789d52015-08-25 15:26:38 -06001195 raw.push_back((uint8_t)(color.float32[2] * 255.0f));
1196 raw.push_back((uint8_t)(color.float32[1] * 255.0f));
1197 raw.push_back((uint8_t)(color.float32[0] * 255.0f));
1198 raw.push_back((uint8_t)(color.float32[3] * 255.0f));
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001199 break;
1200 default:
1201 break;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001202 }
1203
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001204 return raw;
Chia-I Wu89078aa2014-11-22 16:24:41 +08001205 }
Chia-I Wu89078aa2014-11-22 16:24:41 +08001206
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001207 void test_clear_color_image(const VkImageCreateInfo &img_info,
Chris Forbesf0796e12015-06-24 14:34:53 +12001208 const VkClearColorValue &clear_color,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001209 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wud7414b02014-10-21 11:06:26 +08001210 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001211 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001212 VkMemoryPropertyFlags image_reqs =
1213 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001214
Tony Barbour0c823b12015-05-21 13:26:05 -06001215 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001216 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001217 VK_ACCESS_HOST_WRITE_BIT |
1218 VK_ACCESS_SHADER_WRITE_BIT |
1219 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1220 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1221 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001222 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001223 VK_ACCESS_HOST_READ_BIT |
1224 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1225 VK_ACCESS_INDEX_READ_BIT |
1226 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1227 VK_ACCESS_UNIFORM_READ_BIT |
1228 VK_ACCESS_SHADER_READ_BIT |
1229 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1230 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1231 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wud7414b02014-10-21 11:06:26 +08001232
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001233 std::vector<VkImageMemoryBarrier> to_clear;
1234 std::vector<VkImageMemoryBarrier *> p_to_clear;
1235 std::vector<VkImageMemoryBarrier> to_xfer;
1236 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Chia-I Wud7414b02014-10-21 11:06:26 +08001237
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001238 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001239 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001240 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001241 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001242 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001243 *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001244 p_to_clear.push_back(&to_clear.back());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001245 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001246 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001247 VK_IMAGE_LAYOUT_GENERAL, *it));
Mark Lobodzinski837ef922015-01-29 14:24:14 -06001248 p_to_xfer.push_back(&to_xfer.back());
Chia-I Wud7414b02014-10-21 11:06:26 +08001249 }
1250
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001251 cmd_.begin();
Chia-I Wu5bc27862014-12-22 13:19:08 +08001252
Chia-I Wu89d0f942015-10-31 00:31:16 +08001253 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1254 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001255 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001256
Chia-I Wube2b9172015-07-03 11:49:42 +08001257 vkCmdClearColorImage(cmd_.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001258 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001259 &clear_color, ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001260
Chia-I Wu53534662015-10-26 17:08:33 +08001261 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]);
Chia-I Wu5bc27862014-12-22 13:19:08 +08001262
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001263 cmd_.end();
1264
1265 submit_and_done();
1266
1267 // cannot verify
1268 if (!img.transparent() && !img.copyable())
1269 return;
1270
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001271 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001272
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -06001273 const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001274 if (solid_pattern.empty())
1275 return;
1276
1277 checker.set_solid_pattern(solid_pattern);
1278 check_dst(img, checker);
1279 }
Chia-I Wu5bc27862014-12-22 13:19:08 +08001280
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001281 void test_clear_color_image(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001282 const float color[4],
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001283 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu5bc27862014-12-22 13:19:08 +08001284 {
Chris Forbesf0796e12015-06-24 14:34:53 +12001285 VkClearColorValue c = {};
Cody Northrop85789d52015-08-25 15:26:38 -06001286 memcpy(c.float32, color, sizeof(c.float32));
Chia-I Wu5bc27862014-12-22 13:19:08 +08001287 test_clear_color_image(img_info, c, ranges);
1288 }
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001289};
1290
Tony Barbour6918cd52015-04-09 12:58:51 -06001291TEST_F(VkCmdClearColorImageTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001292{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001293 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001294 it != test_formats_.end(); it++) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001295 const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
Tony Barboura36f5282015-06-05 12:53:55 -06001296 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001297
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001298 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001299
Tony Barboura36f5282015-06-05 12:53:55 -06001300 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1301 continue;
1302
1303 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1304 continue;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001305
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001306 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001307 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001308 img_info.format = it->format;
1309 img_info.extent.width = 64;
1310 img_info.extent.height = 64;
1311 img_info.tiling = it->tiling;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001312 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barboure65788f2015-07-21 17:01:42 -06001313 img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001314 VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001315
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001316 const VkImageSubresourceRange range =
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -06001317 vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001318 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001319
1320 test_clear_color_image(img_info, color, ranges);
Chia-I Wud7414b02014-10-21 11:06:26 +08001321 }
1322}
1323
Tony Barbour6918cd52015-04-09 12:58:51 -06001324class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest {
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001325protected:
1326 virtual void SetUp()
1327 {
Tony Barbour6918cd52015-04-09 12:58:51 -06001328 VkCmdBlitTest::SetUp();
Tony Barbourd1c35722015-04-16 15:59:00 -06001329 init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001330 ASSERT_NE(true, test_formats_.empty());
1331 }
1332
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001333 std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001334 {
1335 std::vector<uint8_t> raw;
1336
1337 // depth
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001338 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001339 case VK_FORMAT_D16_UNORM:
1340 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001341 {
Tony Barbour048f2812015-06-09 13:40:53 -06001342 const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001343 raw.push_back(unorm & 0xff);
1344 raw.push_back(unorm >> 8);
1345 }
1346 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001347 case VK_FORMAT_D32_SFLOAT:
1348 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001349 {
1350 const union {
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001351 float depth;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001352 uint32_t u32;
1353 } u = { depth };
1354
1355 raw.push_back((u.u32 ) & 0xff);
1356 raw.push_back((u.u32 >> 8) & 0xff);
1357 raw.push_back((u.u32 >> 16) & 0xff);
1358 raw.push_back((u.u32 >> 24) & 0xff);
1359 }
1360 break;
1361 default:
1362 break;
1363 }
1364
1365 // stencil
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001366 switch (format) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001367 case VK_FORMAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001368 raw.push_back(stencil);
1369 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001370 case VK_FORMAT_D16_UNORM_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001371 raw.push_back(stencil);
1372 raw.push_back(0);
1373 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001374 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001375 raw.push_back(stencil);
1376 raw.push_back(0);
1377 raw.push_back(0);
1378 raw.push_back(0);
1379 break;
1380 default:
1381 break;
1382 }
1383
1384 return raw;
1385 }
1386
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001387 void test_clear_depth_stencil(const VkImageCreateInfo &img_info,
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001388 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001389 const std::vector<VkImageSubresourceRange> &ranges)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001390 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001391 vk_testing::Image img;
Tony Barbour0c823b12015-05-21 13:26:05 -06001392 VkMemoryPropertyFlags image_reqs =
1393 (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001394
Tony Barbour0c823b12015-05-21 13:26:05 -06001395 img.init(dev_, img_info, image_reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001396 const VkFlags all_cache_outputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001397 VK_ACCESS_HOST_WRITE_BIT |
1398 VK_ACCESS_SHADER_WRITE_BIT |
1399 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1400 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1401 VK_ACCESS_TRANSFER_WRITE_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001402 const VkFlags all_cache_inputs =
Chia-I Wua4594202015-10-27 19:54:37 +08001403 VK_ACCESS_HOST_READ_BIT |
1404 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
1405 VK_ACCESS_INDEX_READ_BIT |
1406 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
1407 VK_ACCESS_UNIFORM_READ_BIT |
1408 VK_ACCESS_SHADER_READ_BIT |
1409 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
1410 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
1411 VK_ACCESS_MEMORY_READ_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001412
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001413 std::vector<VkImageMemoryBarrier> to_clear;
1414 std::vector<VkImageMemoryBarrier *> p_to_clear;
1415 std::vector<VkImageMemoryBarrier> to_xfer;
1416 std::vector<VkImageMemoryBarrier *> p_to_xfer;
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001417 unsigned int i = 0;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001418
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001419 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001420 it != ranges.end(); it++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001421 to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001422 VK_IMAGE_LAYOUT_GENERAL,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001423 VK_IMAGE_LAYOUT_GENERAL,
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001424 *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001425
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001426 to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001427 VK_IMAGE_LAYOUT_GENERAL,
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001428 VK_IMAGE_LAYOUT_GENERAL, *it));
Jon Ashburn0aae9d62015-07-31 08:44:44 -06001429 }
1430 for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin();
1431 it != ranges.end(); it++) {
1432 p_to_clear.push_back(to_clear.data() + i);
1433 p_to_xfer.push_back(to_xfer.data() + i);
1434 i++;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001435 }
1436
1437 cmd_.begin();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001438
Chia-I Wu89d0f942015-10-31 00:31:16 +08001439 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1440 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Chia-I Wu53534662015-10-26 17:08:33 +08001441 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_clear.size(), (const void * const*) p_to_clear.data());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001442
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001443 VkClearDepthStencilValue clear_value = {
1444 depth,
1445 stencil
1446 };
Chia-I Wube2b9172015-07-03 11:49:42 +08001447 vkCmdClearDepthStencilImage(cmd_.handle(),
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001448 img.handle(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06001449 &clear_value,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001450 ranges.size(), &ranges[0]);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001451
Chia-I Wu53534662015-10-26 17:08:33 +08001452 vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_xfer.size(), (const void * const*)p_to_xfer.data());
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001453
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001454 cmd_.end();
1455
1456 submit_and_done();
1457
1458 // cannot verify
1459 if (!img.transparent() && !img.copyable())
1460 return;
1461
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001462 vk_testing::ImageChecker checker(img_info, ranges);
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001463
1464 checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil));
1465 check_dst(img, checker);
1466 }
1467};
1468
Tony Barbour6918cd52015-04-09 12:58:51 -06001469TEST_F(VkCmdClearDepthStencilTest, Basic)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001470{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001471 for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin();
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001472 it != test_formats_.end(); it++) {
Tony Barboura36f5282015-06-05 12:53:55 -06001473 VkFormatProperties props;
Tony Barboura36f5282015-06-05 12:53:55 -06001474
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001475 vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props);
Chris Forbesbc0bb772015-06-21 22:55:02 +12001476
Tony Barboura36f5282015-06-05 12:53:55 -06001477 if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1478 continue;
1479
1480 if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1481 continue;
1482
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001483 // known driver issues
Tony Barbourd1c35722015-04-16 15:59:00 -06001484 if (it->format == VK_FORMAT_S8_UINT ||
Chia-I Wu935f2ed2015-11-10 17:01:22 +08001485 it->format == VK_FORMAT_X8_D24_UNORM_PACK32 ||
Tony Barbourd1c35722015-04-16 15:59:00 -06001486 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1487 it->format == VK_FORMAT_D24_UNORM_S8_UINT)
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001488 continue;
1489
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001490 VkImageCreateInfo img_info = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -06001491 img_info.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001492 img_info.format = it->format;
1493 img_info.extent.width = 64;
1494 img_info.extent.height = 64;
1495 img_info.tiling = it->tiling;
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -06001496 img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001497 img_info.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1498 VkImageAspectFlags aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001499
Tony Barbour048f2812015-06-09 13:40:53 -06001500 if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT ||
1501 it->format == VK_FORMAT_D16_UNORM_S8_UINT ||
1502 it->format == VK_FORMAT_D24_UNORM_S8_UINT) {
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001503 aspect |= VK_IMAGE_ASPECT_STENCIL_BIT;
1504 }
Tony Barbour048f2812015-06-09 13:40:53 -06001505
Tony Barbour0d1fc5c2015-11-03 13:02:03 -07001506 const VkImageSubresourceRange range =
1507 vk_testing::Image::subresource_range(img_info, aspect);
1508 std::vector<VkImageSubresourceRange> ranges(&range, &range + 1);
Tony Barbour048f2812015-06-09 13:40:53 -06001509
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001510 test_clear_depth_stencil(img_info, 0.25f, 63, ranges);
1511 }
1512}
1513
1514}; // namespace
1515
Chia-I Wud7414b02014-10-21 11:06:26 +08001516int main(int argc, char **argv)
1517{
Chia-I Wud7414b02014-10-21 11:06:26 +08001518 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wud7414b02014-10-21 11:06:26 +08001519
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001520 vk_testing::set_error_callback(test_error_callback);
Chia-I Wua9a506a2014-12-27 22:04:00 +08001521
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001522 environment = new vk_testing::Environment();
Chia-I Wud7414b02014-10-21 11:06:26 +08001523
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001524 if (!environment->parse_args(argc, argv))
1525 return -1;
Chia-I Wud7414b02014-10-21 11:06:26 +08001526
Chia-I Wu998c2ac2014-12-08 14:30:10 +08001527 ::testing::AddGlobalTestEnvironment(environment);
1528
1529 return RUN_ALL_TESTS();
Chia-I Wud7414b02014-10-21 11:06:26 +08001530}