Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // VK tests |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 2 | // |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 3 | // Copyright (C) 2014 LunarG, Inc. |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 4 | // |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 5 | // 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 Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 11 | // |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 12 | // The above copyright notice and this permission notice shall be included |
| 13 | // in all copies or substantial portions of the Software. |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 14 | // |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 15 | // 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 Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 22 | |
| 23 | // Blit (copy, clear, and resolve) tests |
| 24 | |
Tony Barbour | 048f281 | 2015-06-09 13:40:53 -0600 | [diff] [blame] | 25 | #include "math.h" |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 26 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 27 | #include "vktestbinding.h" |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 28 | #include "test_environment.h" |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 29 | |
| 30 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 31 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 32 | namespace vk_testing { |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 33 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 34 | size_t get_format_size(VkFormat format); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 35 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 36 | class ImageChecker { |
| 37 | public: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 38 | explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkBufferImageCopy> ®ions) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 39 | : info_(info), regions_(regions), pattern_(HASH) {} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 40 | explicit ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges); |
| 41 | explicit ImageChecker(const VkImageCreateInfo &info); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 42 | |
| 43 | void set_solid_pattern(const std::vector<uint8_t> &solid); |
| 44 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 45 | VkDeviceSize buffer_size() const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 46 | 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 Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 51 | const std::vector<VkBufferImageCopy> ®ions() const { return regions_; } |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 52 | |
| 53 | static void hash_salt_generate() { hash_salt_++; } |
| 54 | |
| 55 | private: |
| 56 | enum Action { |
| 57 | FILL, |
| 58 | CHECK, |
| 59 | }; |
| 60 | |
| 61 | enum Pattern { |
| 62 | HASH, |
| 63 | SOLID, |
| 64 | }; |
| 65 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 66 | size_t buffer_cpp() const; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 67 | VkSubresourceLayout buffer_layout(const VkBufferImageCopy ®ion) const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 68 | |
| 69 | bool walk(Action action, Buffer &buf) const; |
| 70 | bool walk(Action action, Image &img) const; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 71 | bool walk_region(Action action, const VkBufferImageCopy ®ion, const VkSubresourceLayout &layout, void *data) const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 72 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 73 | std::vector<uint8_t> pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 74 | |
| 75 | static uint32_t hash_salt_; |
| 76 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 77 | VkImageCreateInfo info_; |
| 78 | std::vector<VkBufferImageCopy> regions_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 79 | |
| 80 | Pattern pattern_; |
| 81 | std::vector<uint8_t> pattern_solid_; |
| 82 | }; |
| 83 | |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 84 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 85 | uint32_t ImageChecker::hash_salt_; |
| 86 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 87 | ImageChecker::ImageChecker(const VkImageCreateInfo &info) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 88 | : info_(info), regions_(), pattern_(HASH) |
| 89 | { |
| 90 | // create a region for every mip level in array slice 0 |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 91 | VkDeviceSize offset = 0; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 92 | for (uint32_t lv = 0; lv < info_.mipLevels; lv++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 93 | VkBufferImageCopy region = {}; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 94 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 95 | region.bufferOffset = offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 96 | region.imageSubresource.mipLevel = lv; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 97 | region.imageSubresource.baseArrayLayer = 0; |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 98 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 99 | |
Courtney Goeltzenleuchter | 660f0ca | 2015-09-10 14:14:11 -0600 | [diff] [blame] | 100 | if (info_.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 101 | if (info_.format != VK_FORMAT_S8_UINT) { |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame^] | 102 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 103 | regions_.push_back(region); |
| 104 | } |
| 105 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 106 | 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) { |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame^] | 109 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 110 | regions_.push_back(region); |
| 111 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 112 | } else { |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame^] | 113 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 114 | 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. |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 122 | if (info_.arrayLayers > 1) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 123 | const VkDeviceSize slice_pitch = offset; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 124 | const uint32_t slice_region_count = regions_.size(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 125 | |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 126 | regions_.reserve(slice_region_count * info_.arrayLayers); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 127 | |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 128 | for (uint32_t slice = 1; slice < info_.arrayLayers; slice++) { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 129 | for (uint32_t i = 0; i < slice_region_count; i++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 130 | VkBufferImageCopy region = regions_[i]; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 131 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 132 | region.bufferOffset += slice_pitch * slice; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 133 | region.imageSubresource.baseArrayLayer = slice; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 134 | regions_.push_back(region); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 140 | ImageChecker::ImageChecker(const VkImageCreateInfo &info, const std::vector<VkImageSubresourceRange> &ranges) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 141 | : info_(info), regions_(), pattern_(HASH) |
| 142 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 143 | VkDeviceSize offset = 0; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 144 | for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 145 | it != ranges.end(); it++) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 146 | for (uint32_t lv = 0; lv < it->levelCount; lv++) { |
| 147 | for (uint32_t layer = 0; layer < it->layerCount; layer++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 148 | VkBufferImageCopy region = {}; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 149 | region.bufferOffset = offset; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 150 | region.imageSubresource = Image::subresource(*it, lv, layer, 1); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 151 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 152 | |
| 153 | regions_.push_back(region); |
| 154 | |
| 155 | offset += buffer_layout(region).size; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid) |
| 162 | { |
| 163 | pattern_ = SOLID; |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 164 | pattern_solid_.clear(); |
| 165 | pattern_solid_.reserve(buffer_cpp()); |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 166 | for (size_t i = 0; i < buffer_cpp(); i++) |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 167 | pattern_solid_.push_back(solid[i % solid.size()]); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 168 | } |
| 169 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 170 | size_t ImageChecker::buffer_cpp() const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 171 | { |
| 172 | return get_format_size(info_.format); |
| 173 | } |
| 174 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 175 | VkSubresourceLayout ImageChecker::buffer_layout(const VkBufferImageCopy ®ion) const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 176 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 177 | VkSubresourceLayout layout = {}; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 178 | layout.offset = region.bufferOffset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 179 | 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 Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 186 | VkDeviceSize ImageChecker::buffer_size() const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 187 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 188 | VkDeviceSize size = 0; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 189 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 190 | for (std::vector<VkBufferImageCopy>::const_iterator it = regions_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 191 | it != regions_.end(); it++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 192 | const VkSubresourceLayout layout = buffer_layout(*it); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 193 | if (size < layout.offset + layout.size) |
| 194 | size = layout.offset + layout.size; |
| 195 | } |
| 196 | |
| 197 | return size; |
| 198 | } |
| 199 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 200 | bool ImageChecker::walk_region(Action action, const VkBufferImageCopy ®ion, |
| 201 | const VkSubresourceLayout &layout, void *data) const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 202 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 203 | 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 Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 206 | uint8_t *dst = static_cast<uint8_t *>(data); |
| 207 | dst += layout.offset + layout.depthPitch * z + |
| 208 | layout.rowPitch * y + buffer_cpp() * x; |
| 209 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 210 | VkOffset3D offset = region.imageOffset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 211 | 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 Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 223 | for (size_t i = 0; i < val.size(); i++) { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 224 | EXPECT_EQ(val[i], dst[i]) << |
Cody Northrop | 28026d4 | 2015-08-06 13:17:52 -0600 | [diff] [blame] | 225 | "Offset is: (" << x << ", " << y << ", " << z << ")\n" |
| 226 | "Format is: (" << info_.format << ")\n"; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 227 | if (val[i] != dst[i]) |
| 228 | return false; |
| 229 | } |
| 230 | } |
| 231 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 235 | return true; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 238 | bool ImageChecker::walk(Action action, Buffer &buf) const |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 239 | { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 240 | void *data = buf.memory().map(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 241 | if (!data) |
| 242 | return false; |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 243 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 244 | std::vector<VkBufferImageCopy>::const_iterator it; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 245 | for (it = regions_.begin(); it != regions_.end(); it++) { |
| 246 | if (!walk_region(action, *it, buffer_layout(*it), data)) |
| 247 | break; |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 250 | buf.memory().unmap(); |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 251 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 252 | return (it == regions_.end()); |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 253 | } |
| 254 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 255 | bool ImageChecker::walk(Action action, Image &img) const |
| 256 | { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 257 | void *data = img.memory().map(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 258 | if (!data) |
| 259 | return false; |
| 260 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 261 | std::vector<VkBufferImageCopy>::const_iterator it; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 262 | for (it = regions_.begin(); it != regions_.end(); it++) { |
| 263 | if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data)) |
| 264 | break; |
| 265 | } |
| 266 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 267 | img.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 268 | |
| 269 | return (it == regions_.end()); |
| 270 | } |
| 271 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 272 | std::vector<uint8_t> ImageChecker::pattern_hash(const VkImageSubresourceLayers &subres, const VkOffset3D &offset) const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 273 | { |
| 274 | #define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff) |
| 275 | #define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3) |
| 276 | const unsigned char input[] = { |
| 277 | HASH_BYTES(hash_salt_), |
| 278 | HASH_BYTES(subres.mipLevel), |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 279 | HASH_BYTES(subres.baseArrayLayer), |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 280 | HASH_BYTES(offset.x), |
| 281 | HASH_BYTES(offset.y), |
| 282 | HASH_BYTES(offset.z), |
| 283 | }; |
| 284 | unsigned long hash = 5381; |
| 285 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 286 | for (int32_t i = 0; i < ARRAY_SIZE(input); i++) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 287 | hash = ((hash << 5) + hash) + input[i]; |
| 288 | |
| 289 | const uint8_t output[4] = { HASH_BYTES(hash) }; |
| 290 | #undef HASH_BYTES |
| 291 | #undef HASH_BYTE |
| 292 | |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 293 | std::vector<uint8_t> val; |
| 294 | val.reserve(buffer_cpp()); |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 295 | for (size_t i = 0; i < buffer_cpp(); i++) |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 296 | val.push_back(output[i % 4]); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 297 | |
| 298 | return val; |
| 299 | } |
| 300 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 301 | size_t get_format_size(VkFormat format) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 302 | { |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 303 | static bool format_table_unverified = true; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 304 | static const struct format_info { |
Courtney Goeltzenleuchter | f338765 | 2015-07-08 18:41:08 -0600 | [diff] [blame] | 305 | VkFormat format; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 306 | size_t size; |
| 307 | uint32_t channel_count; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 308 | } format_table[VK_FORMAT_RANGE_SIZE] = { |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 309 | { VK_FORMAT_UNDEFINED, 0, 0 }, |
| 310 | { VK_FORMAT_R4G4_UNORM, 1, 2 }, |
| 311 | { VK_FORMAT_R4G4_USCALED, 1, 2 }, |
| 312 | { VK_FORMAT_R4G4B4A4_UNORM, 2, 4 }, |
| 313 | { VK_FORMAT_R4G4B4A4_USCALED, 2, 4 }, |
| 314 | { VK_FORMAT_R5G6B5_UNORM, 2, 3 }, |
| 315 | { VK_FORMAT_R5G6B5_USCALED, 2, 3 }, |
| 316 | { VK_FORMAT_R5G5B5A1_UNORM, 2, 4 }, |
| 317 | { VK_FORMAT_R5G5B5A1_USCALED, 2, 4 }, |
| 318 | { VK_FORMAT_R8_UNORM, 1, 1 }, |
| 319 | { VK_FORMAT_R8_SNORM, 1, 1 }, |
| 320 | { VK_FORMAT_R8_USCALED, 1, 1 }, |
| 321 | { VK_FORMAT_R8_SSCALED, 1, 1 }, |
| 322 | { VK_FORMAT_R8_UINT, 1, 1 }, |
| 323 | { VK_FORMAT_R8_SINT, 1, 1 }, |
| 324 | { VK_FORMAT_R8_SRGB, 1, 1 }, |
| 325 | { VK_FORMAT_R8G8_UNORM, 2, 2 }, |
| 326 | { VK_FORMAT_R8G8_SNORM, 2, 2 }, |
| 327 | { VK_FORMAT_R8G8_USCALED, 2, 2 }, |
| 328 | { VK_FORMAT_R8G8_SSCALED, 2, 2 }, |
| 329 | { VK_FORMAT_R8G8_UINT, 2, 2 }, |
| 330 | { VK_FORMAT_R8G8_SINT, 2, 2 }, |
| 331 | { VK_FORMAT_R8G8_SRGB, 2, 2 }, |
| 332 | { VK_FORMAT_R8G8B8_UNORM, 3, 3 }, |
| 333 | { VK_FORMAT_R8G8B8_SNORM, 3, 3 }, |
| 334 | { VK_FORMAT_R8G8B8_USCALED, 3, 3 }, |
| 335 | { VK_FORMAT_R8G8B8_SSCALED, 3, 3 }, |
| 336 | { VK_FORMAT_R8G8B8_UINT, 3, 3 }, |
| 337 | { VK_FORMAT_R8G8B8_SINT, 3, 3 }, |
| 338 | { VK_FORMAT_R8G8B8_SRGB, 3, 3 }, |
| 339 | { VK_FORMAT_R8G8B8A8_UNORM, 4, 4 }, |
| 340 | { VK_FORMAT_R8G8B8A8_SNORM, 4, 4 }, |
| 341 | { VK_FORMAT_R8G8B8A8_USCALED, 4, 4 }, |
| 342 | { VK_FORMAT_R8G8B8A8_SSCALED, 4, 4 }, |
| 343 | { VK_FORMAT_R8G8B8A8_UINT, 4, 4 }, |
| 344 | { VK_FORMAT_R8G8B8A8_SINT, 4, 4 }, |
| 345 | { VK_FORMAT_R8G8B8A8_SRGB, 4, 4 }, |
| 346 | { VK_FORMAT_R10G10B10A2_UNORM, 4, 4 }, |
| 347 | { VK_FORMAT_R10G10B10A2_SNORM, 4, 4 }, |
| 348 | { VK_FORMAT_R10G10B10A2_USCALED, 4, 4 }, |
| 349 | { VK_FORMAT_R10G10B10A2_SSCALED, 4, 4 }, |
| 350 | { VK_FORMAT_R10G10B10A2_UINT, 4, 4 }, |
| 351 | { VK_FORMAT_R10G10B10A2_SINT, 4, 4 }, |
| 352 | { VK_FORMAT_R16_UNORM, 2, 1 }, |
| 353 | { VK_FORMAT_R16_SNORM, 2, 1 }, |
| 354 | { VK_FORMAT_R16_USCALED, 2, 1 }, |
| 355 | { VK_FORMAT_R16_SSCALED, 2, 1 }, |
| 356 | { VK_FORMAT_R16_UINT, 2, 1 }, |
| 357 | { VK_FORMAT_R16_SINT, 2, 1 }, |
| 358 | { VK_FORMAT_R16_SFLOAT, 2, 1 }, |
| 359 | { VK_FORMAT_R16G16_UNORM, 4, 2 }, |
| 360 | { VK_FORMAT_R16G16_SNORM, 4, 2 }, |
| 361 | { VK_FORMAT_R16G16_USCALED, 4, 2 }, |
| 362 | { VK_FORMAT_R16G16_SSCALED, 4, 2 }, |
| 363 | { VK_FORMAT_R16G16_UINT, 4, 2 }, |
| 364 | { VK_FORMAT_R16G16_SINT, 4, 2 }, |
| 365 | { VK_FORMAT_R16G16_SFLOAT, 4, 2 }, |
| 366 | { VK_FORMAT_R16G16B16_UNORM, 6, 3 }, |
| 367 | { VK_FORMAT_R16G16B16_SNORM, 6, 3 }, |
| 368 | { VK_FORMAT_R16G16B16_USCALED, 6, 3 }, |
| 369 | { VK_FORMAT_R16G16B16_SSCALED, 6, 3 }, |
| 370 | { VK_FORMAT_R16G16B16_UINT, 6, 3 }, |
| 371 | { VK_FORMAT_R16G16B16_SINT, 6, 3 }, |
| 372 | { VK_FORMAT_R16G16B16_SFLOAT, 6, 3 }, |
| 373 | { VK_FORMAT_R16G16B16A16_UNORM, 8, 4 }, |
| 374 | { VK_FORMAT_R16G16B16A16_SNORM, 8, 4 }, |
| 375 | { VK_FORMAT_R16G16B16A16_USCALED, 8, 4 }, |
| 376 | { VK_FORMAT_R16G16B16A16_SSCALED, 8, 4 }, |
| 377 | { VK_FORMAT_R16G16B16A16_UINT, 8, 4 }, |
| 378 | { VK_FORMAT_R16G16B16A16_SINT, 8, 4 }, |
| 379 | { VK_FORMAT_R16G16B16A16_SFLOAT, 8, 4 }, |
| 380 | { VK_FORMAT_R32_UINT, 4, 1 }, |
| 381 | { VK_FORMAT_R32_SINT, 4, 1 }, |
| 382 | { VK_FORMAT_R32_SFLOAT, 4, 1 }, |
| 383 | { VK_FORMAT_R32G32_UINT, 8, 2 }, |
| 384 | { VK_FORMAT_R32G32_SINT, 8, 2 }, |
| 385 | { VK_FORMAT_R32G32_SFLOAT, 8, 2 }, |
| 386 | { VK_FORMAT_R32G32B32_UINT, 12, 3 }, |
| 387 | { VK_FORMAT_R32G32B32_SINT, 12, 3 }, |
| 388 | { VK_FORMAT_R32G32B32_SFLOAT, 12, 3 }, |
| 389 | { VK_FORMAT_R32G32B32A32_UINT, 16, 4 }, |
| 390 | { VK_FORMAT_R32G32B32A32_SINT, 16, 4 }, |
| 391 | { VK_FORMAT_R32G32B32A32_SFLOAT, 16, 4 }, |
| 392 | { VK_FORMAT_R64_SFLOAT, 8, 1 }, |
| 393 | { VK_FORMAT_R64G64_SFLOAT, 16, 2 }, |
| 394 | { VK_FORMAT_R64G64B64_SFLOAT, 24, 3 }, |
| 395 | { VK_FORMAT_R64G64B64A64_SFLOAT, 32, 4 }, |
| 396 | { VK_FORMAT_R11G11B10_UFLOAT, 4, 3 }, |
| 397 | { VK_FORMAT_R9G9B9E5_UFLOAT, 4, 3 }, |
| 398 | { VK_FORMAT_D16_UNORM, 2, 1 }, |
Courtney Goeltzenleuchter | 286fb5f | 2015-09-10 17:17:43 -0600 | [diff] [blame] | 399 | { VK_FORMAT_D24_UNORM_X8, 3, 1 }, |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 400 | { VK_FORMAT_D32_SFLOAT, 4, 1 }, |
| 401 | { VK_FORMAT_S8_UINT, 1, 1 }, |
| 402 | { VK_FORMAT_D16_UNORM_S8_UINT, 3, 2 }, |
| 403 | { VK_FORMAT_D24_UNORM_S8_UINT, 4, 2 }, |
Tony Barbour | 048f281 | 2015-06-09 13:40:53 -0600 | [diff] [blame] | 404 | { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 2 }, |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 405 | { VK_FORMAT_BC1_RGB_UNORM, 8, 4 }, |
| 406 | { VK_FORMAT_BC1_RGB_SRGB, 8, 4 }, |
| 407 | { VK_FORMAT_BC1_RGBA_UNORM, 8, 4 }, |
| 408 | { VK_FORMAT_BC1_RGBA_SRGB, 8, 4 }, |
| 409 | { VK_FORMAT_BC2_UNORM, 16, 4 }, |
| 410 | { VK_FORMAT_BC2_SRGB, 16, 4 }, |
| 411 | { VK_FORMAT_BC3_UNORM, 16, 4 }, |
| 412 | { VK_FORMAT_BC3_SRGB, 16, 4 }, |
| 413 | { VK_FORMAT_BC4_UNORM, 8, 4 }, |
| 414 | { VK_FORMAT_BC4_SNORM, 8, 4 }, |
| 415 | { VK_FORMAT_BC5_UNORM, 16, 4 }, |
| 416 | { VK_FORMAT_BC5_SNORM, 16, 4 }, |
| 417 | { VK_FORMAT_BC6H_UFLOAT, 16, 4 }, |
| 418 | { VK_FORMAT_BC6H_SFLOAT, 16, 4 }, |
| 419 | { VK_FORMAT_BC7_UNORM, 16, 4 }, |
| 420 | { VK_FORMAT_BC7_SRGB, 16, 4 }, |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 421 | // TODO: Initialize remaining compressed formats. |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 422 | { VK_FORMAT_ETC2_R8G8B8_UNORM, 0, 0 }, |
| 423 | { VK_FORMAT_ETC2_R8G8B8_SRGB, 0, 0 }, |
| 424 | { VK_FORMAT_ETC2_R8G8B8A1_UNORM, 0, 0 }, |
| 425 | { VK_FORMAT_ETC2_R8G8B8A1_SRGB, 0, 0 }, |
| 426 | { VK_FORMAT_ETC2_R8G8B8A8_UNORM, 0, 0 }, |
| 427 | { VK_FORMAT_ETC2_R8G8B8A8_SRGB, 0, 0 }, |
| 428 | { VK_FORMAT_EAC_R11_UNORM, 0, 0 }, |
| 429 | { VK_FORMAT_EAC_R11_SNORM, 0, 0 }, |
| 430 | { VK_FORMAT_EAC_R11G11_UNORM, 0, 0 }, |
| 431 | { VK_FORMAT_EAC_R11G11_SNORM, 0, 0 }, |
| 432 | { VK_FORMAT_ASTC_4x4_UNORM, 0, 0 }, |
| 433 | { VK_FORMAT_ASTC_4x4_SRGB, 0, 0 }, |
| 434 | { VK_FORMAT_ASTC_5x4_UNORM, 0, 0 }, |
| 435 | { VK_FORMAT_ASTC_5x4_SRGB, 0, 0 }, |
| 436 | { VK_FORMAT_ASTC_5x5_UNORM, 0, 0 }, |
| 437 | { VK_FORMAT_ASTC_5x5_SRGB, 0, 0 }, |
| 438 | { VK_FORMAT_ASTC_6x5_UNORM, 0, 0 }, |
| 439 | { VK_FORMAT_ASTC_6x5_SRGB, 0, 0 }, |
| 440 | { VK_FORMAT_ASTC_6x6_UNORM, 0, 0 }, |
| 441 | { VK_FORMAT_ASTC_6x6_SRGB, 0, 0 }, |
| 442 | { VK_FORMAT_ASTC_8x5_UNORM, 0, 0 }, |
| 443 | { VK_FORMAT_ASTC_8x5_SRGB, 0, 0 }, |
| 444 | { VK_FORMAT_ASTC_8x6_UNORM, 0, 0 }, |
| 445 | { VK_FORMAT_ASTC_8x6_SRGB, 0, 0 }, |
| 446 | { VK_FORMAT_ASTC_8x8_UNORM, 0, 0 }, |
| 447 | { VK_FORMAT_ASTC_8x8_SRGB, 0, 0 }, |
| 448 | { VK_FORMAT_ASTC_10x5_UNORM, 0, 0 }, |
| 449 | { VK_FORMAT_ASTC_10x5_SRGB, 0, 0 }, |
| 450 | { VK_FORMAT_ASTC_10x6_UNORM, 0, 0 }, |
| 451 | { VK_FORMAT_ASTC_10x6_SRGB, 0, 0 }, |
| 452 | { VK_FORMAT_ASTC_10x8_UNORM, 0, 0 }, |
| 453 | { VK_FORMAT_ASTC_10x8_SRGB, 0, 0 }, |
| 454 | { VK_FORMAT_ASTC_10x10_UNORM, 0, 0 }, |
| 455 | { VK_FORMAT_ASTC_10x10_SRGB, 0, 0 }, |
| 456 | { VK_FORMAT_ASTC_12x10_UNORM, 0, 0 }, |
| 457 | { VK_FORMAT_ASTC_12x10_SRGB, 0, 0 }, |
| 458 | { VK_FORMAT_ASTC_12x12_UNORM, 0, 0 }, |
| 459 | { VK_FORMAT_ASTC_12x12_SRGB, 0, 0 }, |
| 460 | { VK_FORMAT_B4G4R4A4_UNORM, 2, 4 }, |
| 461 | { VK_FORMAT_B5G5R5A1_UNORM, 2, 4 }, |
| 462 | { VK_FORMAT_B5G6R5_UNORM, 2, 3 }, |
| 463 | { VK_FORMAT_B5G6R5_USCALED, 2, 3 }, |
| 464 | { VK_FORMAT_B8G8R8_UNORM, 3, 3 }, |
| 465 | { VK_FORMAT_B8G8R8_SNORM, 3, 3 }, |
| 466 | { VK_FORMAT_B8G8R8_USCALED, 3, 3 }, |
| 467 | { VK_FORMAT_B8G8R8_SSCALED, 3, 3 }, |
| 468 | { VK_FORMAT_B8G8R8_UINT, 3, 3 }, |
| 469 | { VK_FORMAT_B8G8R8_SINT, 3, 3 }, |
| 470 | { VK_FORMAT_B8G8R8_SRGB, 3, 3 }, |
| 471 | { VK_FORMAT_B8G8R8A8_UNORM, 4, 4 }, |
| 472 | { VK_FORMAT_B8G8R8A8_SNORM, 4, 4 }, |
| 473 | { VK_FORMAT_B8G8R8A8_USCALED, 4, 4 }, |
| 474 | { VK_FORMAT_B8G8R8A8_SSCALED, 4, 4 }, |
| 475 | { VK_FORMAT_B8G8R8A8_UINT, 4, 4 }, |
| 476 | { VK_FORMAT_B8G8R8A8_SINT, 4, 4 }, |
| 477 | { VK_FORMAT_B8G8R8A8_SRGB, 4, 4 }, |
| 478 | { VK_FORMAT_B10G10R10A2_UNORM, 4, 4 }, |
| 479 | { VK_FORMAT_B10G10R10A2_SNORM, 4, 4 }, |
| 480 | { VK_FORMAT_B10G10R10A2_USCALED, 4, 4 }, |
| 481 | { VK_FORMAT_B10G10R10A2_SSCALED, 4, 4 }, |
| 482 | { VK_FORMAT_B10G10R10A2_UINT, 4, 4 }, |
| 483 | { VK_FORMAT_B10G10R10A2_SINT, 4, 4 }, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 484 | }; |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 485 | if (format_table_unverified) |
| 486 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 487 | for (unsigned int i = 0; i < VK_FORMAT_RANGE_SIZE; i++) |
Tony Barbour | fc3820f | 2015-05-14 17:15:33 -0600 | [diff] [blame] | 488 | { |
| 489 | assert(format_table[i].format == i); |
| 490 | } |
| 491 | format_table_unverified = false; |
| 492 | } |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 493 | |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 494 | return format_table[format].size; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 495 | } |
| 496 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 497 | VkExtent3D get_mip_level_extent(const VkExtent3D &extent, uint32_t mip_level) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 498 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 499 | const VkExtent3D ext = { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 500 | (extent.width >> mip_level) ? extent.width >> mip_level : 1, |
| 501 | (extent.height >> mip_level) ? extent.height >> mip_level : 1, |
| 502 | (extent.depth >> mip_level) ? extent.depth >> mip_level : 1, |
| 503 | }; |
| 504 | |
| 505 | return ext; |
| 506 | } |
| 507 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 508 | }; // namespace vk_testing |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 509 | |
| 510 | namespace { |
| 511 | |
| 512 | #define DO(action) ASSERT_EQ(true, action); |
| 513 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 514 | static vk_testing::Environment *environment; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 515 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 516 | class VkCmdBlitTest : public ::testing::Test { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 517 | protected: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 518 | VkCmdBlitTest() : |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 519 | dev_(environment->default_device()), |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 520 | queue_(*dev_.graphics_queues()[0]), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 521 | pool_(dev_, vk_testing::CommandPool::create_info(dev_.graphics_queue_node_index_)), |
| 522 | cmd_(dev_, vk_testing::CommandBuffer::create_info(pool_.handle())) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 523 | { |
| 524 | // make sure every test uses a different pattern |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 525 | vk_testing::ImageChecker::hash_salt_generate(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 526 | } |
| 527 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 528 | bool submit_and_done() |
| 529 | { |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 530 | queue_.submit(cmd_); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 531 | queue_.wait(); |
| 532 | mem_refs_.clear(); |
| 533 | return true; |
| 534 | } |
| 535 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 536 | vk_testing::Device &dev_; |
| 537 | vk_testing::Queue &queue_; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 538 | vk_testing::CommandPool pool_; |
| 539 | vk_testing::CommandBuffer cmd_; |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 540 | |
Chris Forbes | 9e50dab | 2015-07-11 19:11:39 +1200 | [diff] [blame] | 541 | /* TODO: We should be able to remove these now */ |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 542 | std::vector<VkDeviceMemory> mem_refs_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 543 | }; |
| 544 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 545 | typedef VkCmdBlitTest VkCmdFillBufferTest; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 546 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 547 | TEST_F(VkCmdFillBufferTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 548 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 549 | vk_testing::Buffer buf; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 550 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 551 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 552 | buf.init_as_dst(dev_, 20, reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 553 | |
| 554 | cmd_.begin(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 555 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 4, 0x11111111); |
| 556 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), 4, 16, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 557 | cmd_.end(); |
| 558 | |
| 559 | submit_and_done(); |
| 560 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 561 | const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 562 | EXPECT_EQ(0x11111111, data[0]); |
| 563 | EXPECT_EQ(0x22222222, data[1]); |
| 564 | EXPECT_EQ(0x22222222, data[2]); |
| 565 | EXPECT_EQ(0x22222222, data[3]); |
| 566 | EXPECT_EQ(0x22222222, data[4]); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 567 | buf.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 568 | } |
| 569 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 570 | TEST_F(VkCmdFillBufferTest, Large) |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 571 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 572 | const VkDeviceSize size = 32 * 1024 * 1024; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 573 | vk_testing::Buffer buf; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 574 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 575 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 576 | buf.init_as_dst(dev_, size, reqs); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 577 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 578 | cmd_.begin(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 579 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, size / 2, 0x11111111); |
| 580 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), size / 2, size / 2, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 581 | cmd_.end(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 582 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 583 | submit_and_done(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 584 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 585 | const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map()); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 586 | VkDeviceSize offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 587 | for (offset = 0; offset < size / 2; offset += 4) |
| 588 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 589 | for (; offset < size; offset += 4) |
| 590 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 591 | buf.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 592 | } |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 593 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 594 | TEST_F(VkCmdFillBufferTest, Overlap) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 595 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 596 | vk_testing::Buffer buf; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 597 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 598 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 599 | buf.init_as_dst(dev_, 64, reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 600 | |
| 601 | cmd_.begin(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 602 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), 0, 48, 0x11111111); |
| 603 | vkCmdFillBuffer(cmd_.handle(), buf.handle(), 32, 32, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 604 | cmd_.end(); |
| 605 | |
| 606 | submit_and_done(); |
| 607 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 608 | const uint32_t *data = static_cast<const uint32_t *>(buf.memory().map()); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 609 | VkDeviceSize offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 610 | for (offset = 0; offset < 32; offset += 4) |
| 611 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 612 | for (; offset < 64; offset += 4) |
| 613 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 614 | buf.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 615 | } |
| 616 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 617 | TEST_F(VkCmdFillBufferTest, MultiAlignments) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 618 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 619 | vk_testing::Buffer bufs[9]; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 620 | VkDeviceSize size = 4; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 621 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 622 | |
| 623 | cmd_.begin(); |
| 624 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 625 | bufs[i].init_as_dst(dev_, size, reqs); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 626 | vkCmdFillBuffer(cmd_.handle(), bufs[i].handle(), 0, size, 0x11111111); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 627 | size <<= 1; |
| 628 | } |
| 629 | cmd_.end(); |
| 630 | |
| 631 | submit_and_done(); |
| 632 | |
| 633 | size = 4; |
| 634 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 635 | const uint32_t *data = static_cast<const uint32_t *>(bufs[i].memory().map()); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 636 | VkDeviceSize offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 637 | for (offset = 0; offset < size; offset += 4) |
| 638 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" << |
| 639 | "Offset is: " << offset; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 640 | bufs[i].memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 641 | |
| 642 | size <<= 1; |
| 643 | } |
| 644 | } |
| 645 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 646 | typedef VkCmdBlitTest VkCmdCopyBufferTest; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 647 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 648 | TEST_F(VkCmdCopyBufferTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 649 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 650 | vk_testing::Buffer src, dst; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 651 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 652 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 653 | src.init_as_src(dev_, 4, reqs); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 654 | uint32_t *data = static_cast<uint32_t *>(src.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 655 | data[0] = 0x11111111; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 656 | src.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 657 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 658 | dst.init_as_dst(dev_, 4, reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 659 | |
| 660 | cmd_.begin(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 661 | VkBufferCopy region = {}; |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 662 | region.size = 4; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 663 | vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, ®ion); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 664 | cmd_.end(); |
| 665 | |
| 666 | submit_and_done(); |
| 667 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 668 | data = static_cast<uint32_t *>(dst.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 669 | EXPECT_EQ(0x11111111, data[0]); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 670 | dst.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 671 | } |
| 672 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 673 | TEST_F(VkCmdCopyBufferTest, Large) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 674 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 675 | const VkDeviceSize size = 32 * 1024 * 1024; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 676 | vk_testing::Buffer src, dst; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 677 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 678 | |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 679 | src.init_as_src(dev_, size * sizeof(VkDeviceSize), reqs); |
| 680 | VkDeviceSize *data = static_cast<VkDeviceSize *>(src.memory().map()); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 681 | VkDeviceSize offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 682 | for (offset = 0; offset < size; offset += 4) |
| 683 | data[offset / 4] = offset; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 684 | src.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 685 | |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 686 | dst.init_as_dst(dev_, size * sizeof(VkDeviceSize), reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 687 | |
| 688 | cmd_.begin(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 689 | VkBufferCopy region = {}; |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 690 | region.size = size * sizeof(VkDeviceSize); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 691 | vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), 1, ®ion); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 692 | cmd_.end(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 693 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 694 | submit_and_done(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 695 | |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 696 | data = static_cast<VkDeviceSize *>(dst.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 697 | for (offset = 0; offset < size; offset += 4) |
| 698 | EXPECT_EQ(offset, data[offset / 4]); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 699 | dst.memory().unmap(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 700 | } |
| 701 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 702 | TEST_F(VkCmdCopyBufferTest, MultiAlignments) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 703 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 704 | const VkBufferCopy regions[] = { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 705 | /* well aligned */ |
| 706 | { 0, 0, 256 }, |
| 707 | { 0, 256, 128 }, |
| 708 | { 0, 384, 64 }, |
| 709 | { 0, 448, 32 }, |
| 710 | { 0, 480, 16 }, |
| 711 | { 0, 496, 8 }, |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 712 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 713 | /* ill aligned */ |
| 714 | { 7, 510, 16 }, |
| 715 | { 16, 530, 13 }, |
| 716 | { 32, 551, 16 }, |
| 717 | { 45, 570, 15 }, |
| 718 | { 50, 590, 1 }, |
| 719 | }; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 720 | vk_testing::Buffer src, dst; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 721 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 722 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 723 | src.init_as_src(dev_, 256, reqs); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 724 | uint8_t *data = static_cast<uint8_t *>(src.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 725 | for (int i = 0; i < 256; i++) |
| 726 | data[i] = i; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 727 | src.memory().unmap(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 728 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 729 | dst.init_as_dst(dev_, 1024, reqs); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 730 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 731 | cmd_.begin(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 732 | vkCmdCopyBuffer(cmd_.handle(), src.handle(), dst.handle(), ARRAY_SIZE(regions), regions); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 733 | cmd_.end(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 734 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 735 | submit_and_done(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 736 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 737 | data = static_cast<uint8_t *>(dst.memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 738 | for (int i = 0; i < ARRAY_SIZE(regions); i++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 739 | const VkBufferCopy &r = regions[i]; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 740 | |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 741 | for (int j = 0; j < r.size; j++) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 742 | EXPECT_EQ(r.srcOffset + j, data[r.dstOffset + j]) << |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 743 | "Region is: " << i << "\n" << |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 744 | "Offset is: " << r.dstOffset + j; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 745 | } |
| 746 | } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 747 | dst.memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 748 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 749 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 750 | TEST_F(VkCmdCopyBufferTest, RAWHazard) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 751 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 752 | vk_testing::Buffer bufs[3]; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 753 | VkEventCreateInfo event_info; |
| 754 | VkEvent event; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 755 | VkResult err; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 756 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 757 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 758 | // typedef struct VkEventCreateInfo_ |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 759 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 760 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 761 | // const void* pNext; // Pointer to next structure |
| 762 | // VkFlags flags; // Reserved |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 763 | // } VkEventCreateInfo; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 764 | memset(&event_info, 0, sizeof(event_info)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 765 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 766 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 767 | err = vkCreateEvent(dev_.handle(), &event_info, NULL, &event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 768 | ASSERT_VK_SUCCESS(err); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 769 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 770 | err = vkResetEvent(dev_.handle(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 771 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 772 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 773 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 774 | bufs[i].init_as_src_and_dst(dev_, 4, reqs); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 775 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 776 | uint32_t *data = static_cast<uint32_t *>(bufs[i].memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 777 | data[0] = 0x22222222 * (i + 1); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 778 | bufs[i].memory().unmap(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | cmd_.begin(); |
| 782 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 783 | vkCmdFillBuffer(cmd_.handle(), bufs[0].handle(), 0, 4, 0x11111111); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 784 | // is this necessary? |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 785 | VkBufferMemoryBarrier memory_barrier = bufs[0].buffer_memory_barrier( |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 786 | VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 787 | VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 788 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 789 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 790 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 791 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 792 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 793 | VkBufferCopy region = {}; |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 794 | region.size = 4; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 795 | vkCmdCopyBuffer(cmd_.handle(), bufs[0].handle(), bufs[1].handle(), 1, ®ion); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 796 | |
| 797 | memory_barrier = bufs[1].buffer_memory_barrier( |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 798 | VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_TRANSFER_BIT, 0, 4); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 799 | pmemory_barrier = &memory_barrier; |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 800 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&pmemory_barrier); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 801 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 802 | vkCmdCopyBuffer(cmd_.handle(), bufs[1].handle(), bufs[2].handle(), 1, ®ion); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 803 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 804 | /* Use vkCmdSetEvent and vkCmdWaitEvents to test them. |
| 805 | * This could be vkCmdPipelineBarrier. |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 806 | */ |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 807 | vkCmdSetEvent(cmd_.handle(), event, VK_PIPELINE_STAGE_TRANSFER_BIT); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 808 | |
| 809 | // Additional commands could go into the buffer here before the wait. |
| 810 | |
| 811 | memory_barrier = bufs[1].buffer_memory_barrier( |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 812 | VK_MEMORY_OUTPUT_TRANSFER_BIT, VK_MEMORY_INPUT_HOST_READ_BIT, 0, 4); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 813 | pmemory_barrier = &memory_barrier; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 814 | vkCmdWaitEvents(cmd_.handle(), 1, &event, src_stages, dest_stages, 1, (const void **)&pmemory_barrier); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 815 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 816 | cmd_.end(); |
| 817 | |
| 818 | submit_and_done(); |
| 819 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 820 | const uint32_t *data = static_cast<const uint32_t *>(bufs[2].memory().map()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 821 | EXPECT_EQ(0x11111111, data[0]); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 822 | bufs[2].memory().unmap(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 823 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 824 | vkDestroyEvent(dev_.handle(), event, NULL); |
Tony Barbour | 7db519b | 2015-06-26 11:49:05 -0600 | [diff] [blame] | 825 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 826 | } |
| 827 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 828 | class VkCmdBlitImageTest : public VkCmdBlitTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 829 | protected: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 830 | void init_test_formats(VkFlags features) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 831 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 832 | first_linear_format_ = VK_FORMAT_UNDEFINED; |
| 833 | first_optimal_format_ = VK_FORMAT_UNDEFINED; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 834 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 835 | for (std::vector<vk_testing::Device::Format>::const_iterator it = dev_.formats().begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 836 | it != dev_.formats().end(); it++) { |
| 837 | if (it->features & features) { |
| 838 | test_formats_.push_back(*it); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 839 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 840 | if (it->tiling == VK_IMAGE_TILING_LINEAR && |
| 841 | first_linear_format_ == VK_FORMAT_UNDEFINED) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 842 | first_linear_format_ = it->format; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 843 | if (it->tiling == VK_IMAGE_TILING_OPTIMAL && |
| 844 | first_optimal_format_ == VK_FORMAT_UNDEFINED) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 845 | first_optimal_format_ = it->format; |
| 846 | } |
| 847 | } |
| 848 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 849 | |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 850 | void init_test_formats() |
| 851 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 852 | init_test_formats(static_cast<VkFlags>(-1)); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 853 | } |
| 854 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 855 | void fill_src(vk_testing::Image &img, const vk_testing::ImageChecker &checker) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 856 | { |
| 857 | if (img.transparent()) { |
| 858 | checker.fill(img); |
| 859 | return; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 860 | } |
| 861 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 862 | ASSERT_EQ(true, img.copyable()); |
| 863 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 864 | vk_testing::Buffer in_buf; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 865 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 866 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 867 | in_buf.init_as_src(dev_, checker.buffer_size(), reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 868 | checker.fill(in_buf); |
| 869 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 870 | // copy in and tile |
| 871 | cmd_.begin(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 872 | vkCmdCopyBufferToImage(cmd_.handle(), in_buf.handle(), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 873 | img.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 874 | checker.regions().size(), &checker.regions()[0]); |
| 875 | cmd_.end(); |
| 876 | |
| 877 | submit_and_done(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 878 | } |
| 879 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 880 | void check_dst(vk_testing::Image &img, const vk_testing::ImageChecker &checker) |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 881 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 882 | if (img.transparent()) { |
| 883 | DO(checker.check(img)); |
| 884 | return; |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 885 | } |
| 886 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 887 | ASSERT_EQ(true, img.copyable()); |
| 888 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 889 | vk_testing::Buffer out_buf; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 890 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 891 | out_buf.init_as_dst(dev_, checker.buffer_size(), reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 892 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 893 | // copy out and linearize |
| 894 | cmd_.begin(); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 895 | vkCmdCopyImageToBuffer(cmd_.handle(), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 896 | img.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 897 | out_buf.handle(), |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 898 | checker.regions().size(), &checker.regions()[0]); |
| 899 | cmd_.end(); |
| 900 | |
| 901 | submit_and_done(); |
| 902 | |
| 903 | DO(checker.check(out_buf)); |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 904 | } |
| 905 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 906 | std::vector<vk_testing::Device::Format> test_formats_; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 907 | VkFormat first_linear_format_; |
| 908 | VkFormat first_optimal_format_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 909 | }; |
| 910 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 911 | class VkCmdCopyBufferToImageTest : public VkCmdBlitImageTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 912 | protected: |
| 913 | virtual void SetUp() |
| 914 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 915 | VkCmdBlitTest::SetUp(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 916 | init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 917 | ASSERT_NE(true, test_formats_.empty()); |
| 918 | } |
| 919 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 920 | void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 921 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 922 | vk_testing::Buffer buf; |
| 923 | vk_testing::Image img; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 924 | VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 925 | VkMemoryPropertyFlags image_reqs = |
| 926 | (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 927 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 928 | buf.init_as_src(dev_, checker.buffer_size(), buffer_reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 929 | checker.fill(buf); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 930 | |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 931 | img.init(dev_, img_info, image_reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 932 | |
| 933 | cmd_.begin(); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 934 | vkCmdCopyBufferToImage(cmd_.handle(), |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 935 | buf.handle(), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 936 | img.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 937 | checker.regions().size(), &checker.regions()[0]); |
| 938 | cmd_.end(); |
| 939 | |
| 940 | submit_and_done(); |
| 941 | |
| 942 | check_dst(img, checker); |
| 943 | } |
| 944 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 945 | void test_copy_memory_to_image(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> ®ions) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 946 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 947 | vk_testing::ImageChecker checker(img_info, regions); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 948 | test_copy_memory_to_image(img_info, checker); |
| 949 | } |
| 950 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 951 | void test_copy_memory_to_image(const VkImageCreateInfo &img_info) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 952 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 953 | vk_testing::ImageChecker checker(img_info); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 954 | test_copy_memory_to_image(img_info, checker); |
| 955 | } |
| 956 | }; |
| 957 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 958 | TEST_F(VkCmdCopyBufferToImageTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 959 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 960 | for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 961 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 962 | |
| 963 | // not sure what to do here |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 964 | if (it->format == VK_FORMAT_UNDEFINED || |
| 965 | (it->format >= VK_FORMAT_B8G8R8_UNORM && |
| 966 | it->format <= VK_FORMAT_B8G8R8_SRGB)) |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 967 | continue; |
| 968 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 969 | VkImageCreateInfo img_info = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 970 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 971 | img_info.format = it->format; |
| 972 | img_info.extent.width = 64; |
| 973 | img_info.extent.height = 64; |
| 974 | img_info.tiling = it->tiling; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 975 | img_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 976 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 977 | |
| 978 | test_copy_memory_to_image(img_info); |
| 979 | } |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 980 | } |
| 981 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 982 | class VkCmdCopyImageToBufferTest : public VkCmdBlitImageTest { |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 983 | protected: |
| 984 | virtual void SetUp() |
| 985 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 986 | VkCmdBlitTest::SetUp(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 987 | init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 988 | ASSERT_NE(true, test_formats_.empty()); |
| 989 | } |
| 990 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 991 | void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const vk_testing::ImageChecker &checker) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 992 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 993 | vk_testing::Image img; |
| 994 | vk_testing::Buffer buf; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 995 | VkMemoryPropertyFlags buffer_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 996 | VkMemoryPropertyFlags image_reqs = |
| 997 | (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 998 | |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 999 | img.init(dev_, img_info, image_reqs); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1000 | fill_src(img, checker); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1001 | |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 1002 | buf.init_as_dst(dev_, checker.buffer_size(), buffer_reqs); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1003 | |
| 1004 | cmd_.begin(); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 1005 | vkCmdCopyImageToBuffer(cmd_.handle(), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1006 | img.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 1007 | buf.handle(), |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1008 | checker.regions().size(), &checker.regions()[0]); |
| 1009 | cmd_.end(); |
| 1010 | |
| 1011 | submit_and_done(); |
| 1012 | |
| 1013 | checker.check(buf); |
| 1014 | } |
| 1015 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1016 | void test_copy_image_to_memory(const VkImageCreateInfo &img_info, const std::vector<VkBufferImageCopy> ®ions) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1017 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1018 | vk_testing::ImageChecker checker(img_info, regions); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1019 | test_copy_image_to_memory(img_info, checker); |
| 1020 | } |
| 1021 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1022 | void test_copy_image_to_memory(const VkImageCreateInfo &img_info) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1023 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1024 | vk_testing::ImageChecker checker(img_info); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1025 | test_copy_image_to_memory(img_info, checker); |
| 1026 | } |
| 1027 | }; |
| 1028 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1029 | TEST_F(VkCmdCopyImageToBufferTest, Basic) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1030 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1031 | for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1032 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1033 | |
| 1034 | // not sure what to do here |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1035 | if (it->format == VK_FORMAT_UNDEFINED || |
| 1036 | (it->format >= VK_FORMAT_B8G8R8_UNORM && |
| 1037 | it->format <= VK_FORMAT_B8G8R8_SRGB)) |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1038 | continue; |
| 1039 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1040 | VkImageCreateInfo img_info = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1041 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1042 | img_info.format = it->format; |
| 1043 | img_info.extent.width = 64; |
| 1044 | img_info.extent.height = 64; |
| 1045 | img_info.tiling = it->tiling; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1046 | img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 1047 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; // Going to fill it before copy |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1048 | |
| 1049 | test_copy_image_to_memory(img_info); |
| 1050 | } |
| 1051 | } |
| 1052 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1053 | class VkCmdCopyImageTest : public VkCmdBlitImageTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1054 | protected: |
| 1055 | virtual void SetUp() |
| 1056 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1057 | VkCmdBlitTest::SetUp(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1058 | init_test_formats(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1059 | ASSERT_NE(true, test_formats_.empty()); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1060 | } |
| 1061 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1062 | void test_copy_image(const VkImageCreateInfo &src_info, const VkImageCreateInfo &dst_info, |
| 1063 | const std::vector<VkImageCopy> &copies) |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1064 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1065 | // convert VkImageCopy to two sets of VkBufferImageCopy |
| 1066 | std::vector<VkBufferImageCopy> src_regions, dst_regions; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1067 | VkDeviceSize src_offset = 0, dst_offset = 0; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1068 | for (std::vector<VkImageCopy>::const_iterator it = copies.begin(); it != copies.end(); it++) { |
| 1069 | VkBufferImageCopy src_region = {}, dst_region = {}; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1070 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1071 | src_region.bufferOffset = src_offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1072 | src_region.imageSubresource = it->srcSubresource; |
| 1073 | src_region.imageOffset = it->srcOffset; |
| 1074 | src_region.imageExtent = it->extent; |
| 1075 | src_regions.push_back(src_region); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1076 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1077 | dst_region.bufferOffset = src_offset; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1078 | dst_region.imageSubresource = it->dstSubresource; |
| 1079 | dst_region.imageOffset = it->dstOffset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1080 | dst_region.imageExtent = it->extent; |
| 1081 | dst_regions.push_back(dst_region); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1082 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1083 | const VkDeviceSize size = it->extent.width * it->extent.height * it->extent.depth; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1084 | src_offset += vk_testing::get_format_size(src_info.format) * size; |
| 1085 | dst_offset += vk_testing::get_format_size(dst_info.format) * size; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1086 | } |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1087 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1088 | vk_testing::ImageChecker src_checker(src_info, src_regions); |
| 1089 | vk_testing::ImageChecker dst_checker(dst_info, dst_regions); |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1090 | VkMemoryPropertyFlags src_reqs = |
| 1091 | (src_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
| 1092 | VkMemoryPropertyFlags dst_reqs = |
| 1093 | (dst_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
| 1094 | |
| 1095 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1096 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1097 | vk_testing::Image src; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1098 | src.init(dev_, src_info, src_reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1099 | fill_src(src, src_checker); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1100 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1101 | vk_testing::Image dst; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1102 | dst.init(dev_, dst_info, dst_reqs); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1103 | |
| 1104 | cmd_.begin(); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 1105 | vkCmdCopyImage(cmd_.handle(), |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1106 | src.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 1107 | dst.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
Courtney Goeltzenleuchter | b3efe9b | 2015-03-25 11:25:10 -0600 | [diff] [blame] | 1108 | copies.size(), &copies[0]); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1109 | cmd_.end(); |
| 1110 | |
| 1111 | submit_and_done(); |
| 1112 | |
| 1113 | check_dst(dst, dst_checker); |
| 1114 | } |
| 1115 | }; |
| 1116 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1117 | TEST_F(VkCmdCopyImageTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1118 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1119 | for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1120 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1121 | |
| 1122 | // not sure what to do here |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1123 | if (it->format == VK_FORMAT_UNDEFINED || |
| 1124 | (it->format >= VK_FORMAT_B8G8R8_UNORM && |
| 1125 | it->format <= VK_FORMAT_B8G8R8_SRGB)) |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1126 | continue; |
| 1127 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1128 | VkImageCreateInfo img_info = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1129 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1130 | img_info.format = it->format; |
| 1131 | img_info.extent.width = 64; |
| 1132 | img_info.extent.height = 64; |
| 1133 | img_info.tiling = it->tiling; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1134 | img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1135 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1136 | VkImageCopy copy = {}; |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 1137 | copy.srcSubresource = vk_testing::Image::subresource(VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1138 | copy.dstSubresource = copy.srcSubresource; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1139 | copy.extent = img_info.extent; |
| 1140 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1141 | test_copy_image(img_info, img_info, std::vector<VkImageCopy>(©, © + 1)); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1145 | class VkCmdClearColorImageTest : public VkCmdBlitImageTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1146 | protected: |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 1147 | VkCmdClearColorImageTest() {} |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1148 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1149 | virtual void SetUp() |
| 1150 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1151 | VkCmdBlitTest::SetUp(); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1152 | |
Courtney Goeltzenleuchter | cda3034 | 2015-09-10 16:25:49 -0600 | [diff] [blame] | 1153 | init_test_formats(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1154 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1155 | ASSERT_NE(true, test_formats_.empty()); |
| 1156 | } |
| 1157 | |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1158 | union Color { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1159 | float color[4]; |
| 1160 | uint32_t raw[4]; |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1161 | }; |
| 1162 | |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 1163 | std::vector<uint8_t> color_to_raw(VkFormat format, const VkClearColorValue &color) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1164 | { |
| 1165 | std::vector<uint8_t> raw; |
| 1166 | |
| 1167 | // TODO support all formats |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1168 | switch (format) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1169 | case VK_FORMAT_R8G8B8A8_UNORM: |
Cody Northrop | 85789d5 | 2015-08-25 15:26:38 -0600 | [diff] [blame] | 1170 | raw.push_back((uint8_t)(color.float32[0] * 255.0f)); |
| 1171 | raw.push_back((uint8_t)(color.float32[1] * 255.0f)); |
| 1172 | raw.push_back((uint8_t)(color.float32[2] * 255.0f)); |
| 1173 | raw.push_back((uint8_t)(color.float32[3] * 255.0f)); |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1174 | break; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1175 | case VK_FORMAT_B8G8R8A8_UNORM: |
Cody Northrop | 85789d5 | 2015-08-25 15:26:38 -0600 | [diff] [blame] | 1176 | raw.push_back((uint8_t)(color.float32[2] * 255.0f)); |
| 1177 | raw.push_back((uint8_t)(color.float32[1] * 255.0f)); |
| 1178 | raw.push_back((uint8_t)(color.float32[0] * 255.0f)); |
| 1179 | raw.push_back((uint8_t)(color.float32[3] * 255.0f)); |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | default: |
| 1182 | break; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1185 | return raw; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1186 | } |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1187 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1188 | void test_clear_color_image(const VkImageCreateInfo &img_info, |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 1189 | const VkClearColorValue &clear_color, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1190 | const std::vector<VkImageSubresourceRange> &ranges) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1191 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1192 | vk_testing::Image img; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1193 | VkMemoryPropertyFlags image_reqs = |
| 1194 | (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 1195 | |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1196 | img.init(dev_, img_info, image_reqs); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1197 | const VkFlags all_cache_outputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1198 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1199 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1200 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1201 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1202 | VK_MEMORY_OUTPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1203 | const VkFlags all_cache_inputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1204 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1205 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1206 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1207 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1208 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1209 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 1210 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1211 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1212 | VK_MEMORY_INPUT_TRANSFER_BIT; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1213 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1214 | std::vector<VkImageMemoryBarrier> to_clear; |
| 1215 | std::vector<VkImageMemoryBarrier *> p_to_clear; |
| 1216 | std::vector<VkImageMemoryBarrier> to_xfer; |
| 1217 | std::vector<VkImageMemoryBarrier *> p_to_xfer; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1218 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1219 | for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1220 | it != ranges.end(); it++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1221 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1222 | VK_IMAGE_LAYOUT_GENERAL, |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1223 | VK_IMAGE_LAYOUT_GENERAL, |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1224 | *it)); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1225 | p_to_clear.push_back(&to_clear.back()); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1226 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1227 | VK_IMAGE_LAYOUT_GENERAL, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1228 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *it)); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1229 | p_to_xfer.push_back(&to_xfer.back()); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1232 | cmd_.begin(); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1233 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1234 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 1235 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 1236 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_clear[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1237 | |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 1238 | vkCmdClearColorImage(cmd_.handle(), |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 1239 | img.handle(), VK_IMAGE_LAYOUT_GENERAL, |
Courtney Goeltzenleuchter | d7a5cff | 2015-04-23 17:49:22 -0600 | [diff] [blame] | 1240 | &clear_color, ranges.size(), &ranges[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1241 | |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 1242 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, 1, (const void * const*)&p_to_xfer[0]); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1243 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1244 | cmd_.end(); |
| 1245 | |
| 1246 | submit_and_done(); |
| 1247 | |
| 1248 | // cannot verify |
| 1249 | if (!img.transparent() && !img.copyable()) |
| 1250 | return; |
| 1251 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1252 | vk_testing::ImageChecker checker(img_info, ranges); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1253 | |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 1254 | const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, clear_color); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1255 | if (solid_pattern.empty()) |
| 1256 | return; |
| 1257 | |
| 1258 | checker.set_solid_pattern(solid_pattern); |
| 1259 | check_dst(img, checker); |
| 1260 | } |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1261 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1262 | void test_clear_color_image(const VkImageCreateInfo &img_info, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1263 | const float color[4], |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1264 | const std::vector<VkImageSubresourceRange> &ranges) |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1265 | { |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 1266 | VkClearColorValue c = {}; |
Cody Northrop | 85789d5 | 2015-08-25 15:26:38 -0600 | [diff] [blame] | 1267 | memcpy(c.float32, color, sizeof(c.float32)); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1268 | test_clear_color_image(img_info, c, ranges); |
| 1269 | } |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1270 | }; |
| 1271 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1272 | TEST_F(VkCmdClearColorImageTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1273 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1274 | for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1275 | it != test_formats_.end(); it++) { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1276 | const float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1277 | VkFormatProperties props; |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1278 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 1279 | vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 1280 | |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1281 | if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) |
| 1282 | continue; |
| 1283 | |
| 1284 | if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) |
| 1285 | continue; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1286 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1287 | VkImageCreateInfo img_info = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1288 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1289 | img_info.format = it->format; |
| 1290 | img_info.extent.width = 64; |
| 1291 | img_info.extent.height = 64; |
| 1292 | img_info.tiling = it->tiling; |
Tony Barbour | e65788f | 2015-07-21 17:01:42 -0600 | [diff] [blame] | 1293 | img_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1294 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; // Going to check contents |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1295 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1296 | const VkImageSubresourceRange range = |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 1297 | vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1298 | std::vector<VkImageSubresourceRange> ranges(&range, &range + 1); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1299 | |
| 1300 | test_clear_color_image(img_info, color, ranges); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1304 | class VkCmdClearDepthStencilTest : public VkCmdBlitImageTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1305 | protected: |
| 1306 | virtual void SetUp() |
| 1307 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1308 | VkCmdBlitTest::SetUp(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1309 | init_test_formats(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1310 | ASSERT_NE(true, test_formats_.empty()); |
| 1311 | } |
| 1312 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1313 | std::vector<uint8_t> ds_to_raw(VkFormat format, float depth, uint32_t stencil) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1314 | { |
| 1315 | std::vector<uint8_t> raw; |
| 1316 | |
| 1317 | // depth |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1318 | switch (format) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1319 | case VK_FORMAT_D16_UNORM: |
| 1320 | case VK_FORMAT_D16_UNORM_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1321 | { |
Tony Barbour | 048f281 | 2015-06-09 13:40:53 -0600 | [diff] [blame] | 1322 | const uint16_t unorm = (uint16_t)roundf(depth * 65535.0f); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1323 | raw.push_back(unorm & 0xff); |
| 1324 | raw.push_back(unorm >> 8); |
| 1325 | } |
| 1326 | break; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1327 | case VK_FORMAT_D32_SFLOAT: |
| 1328 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1329 | { |
| 1330 | const union { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1331 | float depth; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1332 | uint32_t u32; |
| 1333 | } u = { depth }; |
| 1334 | |
| 1335 | raw.push_back((u.u32 ) & 0xff); |
| 1336 | raw.push_back((u.u32 >> 8) & 0xff); |
| 1337 | raw.push_back((u.u32 >> 16) & 0xff); |
| 1338 | raw.push_back((u.u32 >> 24) & 0xff); |
| 1339 | } |
| 1340 | break; |
| 1341 | default: |
| 1342 | break; |
| 1343 | } |
| 1344 | |
| 1345 | // stencil |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1346 | switch (format) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1347 | case VK_FORMAT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1348 | raw.push_back(stencil); |
| 1349 | break; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1350 | case VK_FORMAT_D16_UNORM_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1351 | raw.push_back(stencil); |
| 1352 | raw.push_back(0); |
| 1353 | break; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1354 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1355 | raw.push_back(stencil); |
| 1356 | raw.push_back(0); |
| 1357 | raw.push_back(0); |
| 1358 | raw.push_back(0); |
| 1359 | break; |
| 1360 | default: |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | return raw; |
| 1365 | } |
| 1366 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1367 | void test_clear_depth_stencil(const VkImageCreateInfo &img_info, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1368 | float depth, uint32_t stencil, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1369 | const std::vector<VkImageSubresourceRange> &ranges) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1370 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1371 | vk_testing::Image img; |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1372 | VkMemoryPropertyFlags image_reqs = |
| 1373 | (img_info.tiling == VK_IMAGE_TILING_LINEAR)?VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT:0; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 1374 | |
Tony Barbour | 0c823b1 | 2015-05-21 13:26:05 -0600 | [diff] [blame] | 1375 | img.init(dev_, img_info, image_reqs); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1376 | const VkFlags all_cache_outputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1377 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1378 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1379 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1380 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1381 | VK_MEMORY_OUTPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1382 | const VkFlags all_cache_inputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1383 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1384 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1385 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1386 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1387 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1388 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 1389 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1390 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1391 | VK_MEMORY_INPUT_TRANSFER_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1392 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1393 | std::vector<VkImageMemoryBarrier> to_clear; |
| 1394 | std::vector<VkImageMemoryBarrier *> p_to_clear; |
| 1395 | std::vector<VkImageMemoryBarrier> to_xfer; |
| 1396 | std::vector<VkImageMemoryBarrier *> p_to_xfer; |
Jon Ashburn | 0aae9d6 | 2015-07-31 08:44:44 -0600 | [diff] [blame] | 1397 | unsigned int i = 0; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1398 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1399 | for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1400 | it != ranges.end(); it++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1401 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1402 | VK_IMAGE_LAYOUT_GENERAL, |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1403 | VK_IMAGE_LAYOUT_GENERAL, |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1404 | *it)); |
Jon Ashburn | 0aae9d6 | 2015-07-31 08:44:44 -0600 | [diff] [blame] | 1405 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1406 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1407 | VK_IMAGE_LAYOUT_GENERAL, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1408 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *it)); |
Jon Ashburn | 0aae9d6 | 2015-07-31 08:44:44 -0600 | [diff] [blame] | 1409 | } |
| 1410 | for (std::vector<VkImageSubresourceRange>::const_iterator it = ranges.begin(); |
| 1411 | it != ranges.end(); it++) { |
| 1412 | p_to_clear.push_back(to_clear.data() + i); |
| 1413 | p_to_xfer.push_back(to_xfer.data() + i); |
| 1414 | i++; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | cmd_.begin(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1418 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1419 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 1420 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 1421 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_clear.size(), (const void * const*) p_to_clear.data()); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1422 | |
Courtney Goeltzenleuchter | 45df9e1 | 2015-09-15 18:03:22 -0600 | [diff] [blame] | 1423 | VkClearDepthStencilValue clear_value = { |
| 1424 | depth, |
| 1425 | stencil |
| 1426 | }; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 1427 | vkCmdClearDepthStencilImage(cmd_.handle(), |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 1428 | img.handle(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
Courtney Goeltzenleuchter | 45df9e1 | 2015-09-15 18:03:22 -0600 | [diff] [blame] | 1429 | &clear_value, |
Chris Forbes | d9be82b | 2015-06-22 17:21:59 +1200 | [diff] [blame] | 1430 | ranges.size(), &ranges[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1431 | |
Chia-I Wu | 5353466 | 2015-10-26 17:08:33 +0800 | [diff] [blame] | 1432 | vkCmdPipelineBarrier(cmd_.handle(), src_stages, dest_stages, 0, to_xfer.size(), (const void * const*)p_to_xfer.data()); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1433 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1434 | cmd_.end(); |
| 1435 | |
| 1436 | submit_and_done(); |
| 1437 | |
| 1438 | // cannot verify |
| 1439 | if (!img.transparent() && !img.copyable()) |
| 1440 | return; |
| 1441 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1442 | vk_testing::ImageChecker checker(img_info, ranges); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1443 | |
| 1444 | checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil)); |
| 1445 | check_dst(img, checker); |
| 1446 | } |
| 1447 | }; |
| 1448 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1449 | TEST_F(VkCmdClearDepthStencilTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1450 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1451 | for (std::vector<vk_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1452 | it != test_formats_.end(); it++) { |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1453 | VkFormatProperties props; |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1454 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 1455 | vkGetPhysicalDeviceFormatProperties(dev_.phy().handle(), it->format, &props); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 1456 | |
Tony Barbour | a36f528 | 2015-06-05 12:53:55 -0600 | [diff] [blame] | 1457 | if (it->tiling == VK_IMAGE_TILING_LINEAR && !(props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) |
| 1458 | continue; |
| 1459 | |
| 1460 | if (it->tiling == VK_IMAGE_TILING_OPTIMAL && !(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) |
| 1461 | continue; |
| 1462 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1463 | // known driver issues |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1464 | if (it->format == VK_FORMAT_S8_UINT || |
Courtney Goeltzenleuchter | 286fb5f | 2015-09-10 17:17:43 -0600 | [diff] [blame] | 1465 | it->format == VK_FORMAT_D24_UNORM_X8 || |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1466 | it->format == VK_FORMAT_D16_UNORM_S8_UINT || |
| 1467 | it->format == VK_FORMAT_D24_UNORM_S8_UINT) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1468 | continue; |
| 1469 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1470 | VkImageCreateInfo img_info = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1471 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1472 | img_info.format = it->format; |
| 1473 | img_info.extent.width = 64; |
| 1474 | img_info.extent.height = 64; |
| 1475 | img_info.tiling = it->tiling; |
Courtney Goeltzenleuchter | 660f0ca | 2015-09-10 14:14:11 -0600 | [diff] [blame] | 1476 | img_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1477 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1478 | const VkImageSubresourceRange range = |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 1479 | vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1480 | std::vector<VkImageSubresourceRange> ranges(&range, &range + 1); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1481 | |
Tony Barbour | 048f281 | 2015-06-09 13:40:53 -0600 | [diff] [blame] | 1482 | if (it->format == VK_FORMAT_D32_SFLOAT_S8_UINT || |
| 1483 | it->format == VK_FORMAT_D16_UNORM_S8_UINT || |
| 1484 | it->format == VK_FORMAT_D24_UNORM_S8_UINT) { |
| 1485 | const VkImageSubresourceRange range2 = |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 1486 | vk_testing::Image::subresource_range(img_info, VK_IMAGE_ASPECT_STENCIL_BIT); |
Tony Barbour | 048f281 | 2015-06-09 13:40:53 -0600 | [diff] [blame] | 1487 | ranges.push_back(range2); |
| 1488 | } |
| 1489 | |
| 1490 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1491 | test_clear_depth_stencil(img_info, 0.25f, 63, ranges); |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | }; // namespace |
| 1496 | |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1497 | int main(int argc, char **argv) |
| 1498 | { |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1499 | ::testing::InitGoogleTest(&argc, argv); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1500 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1501 | vk_testing::set_error_callback(test_error_callback); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1502 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1503 | environment = new vk_testing::Environment(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1504 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1505 | if (!environment->parse_args(argc, argv)) |
| 1506 | return -1; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1507 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1508 | ::testing::AddGlobalTestEnvironment(environment); |
| 1509 | |
| 1510 | return RUN_ALL_TESTS(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1511 | } |