Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1 | // XGL 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 | |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 25 | #include "test_common.h" |
| 26 | #include "xgltestbinding.h" |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 27 | |
| 28 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 29 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 30 | namespace xgl_testing { |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 31 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 32 | XGL_SIZE get_format_size(XGL_FORMAT format); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 33 | |
| 34 | class Environment : public ::testing::Environment { |
| 35 | public: |
| 36 | Environment(); |
| 37 | |
| 38 | bool parse_args(int argc, char **argv); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 39 | |
| 40 | virtual void SetUp(); |
| 41 | virtual void TearDown(); |
| 42 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 43 | const std::vector<Device *> &devices() { return devs_; } |
| 44 | Device &default_device() { return *(devs_[default_dev_]); } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 45 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 46 | private: |
| 47 | XGL_APPLICATION_INFO app_; |
| 48 | int default_dev_; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 50 | std::vector<Device *> devs_; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 51 | }; |
| 52 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 53 | class ImageChecker { |
| 54 | public: |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 55 | explicit ImageChecker(const XGL_IMAGE_CREATE_INFO &info, const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 56 | : info_(info), regions_(regions), pattern_(HASH) {} |
| 57 | explicit ImageChecker(const XGL_IMAGE_CREATE_INFO &info, const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges); |
| 58 | explicit ImageChecker(const XGL_IMAGE_CREATE_INFO &info); |
| 59 | |
| 60 | void set_solid_pattern(const std::vector<uint8_t> &solid); |
| 61 | |
| 62 | XGL_GPU_SIZE buffer_size() const; |
| 63 | bool fill(Buffer &buf) const { return walk(FILL, buf); } |
| 64 | bool fill(Image &img) const { return walk(FILL, img); } |
| 65 | bool check(Buffer &buf) const { return walk(CHECK, buf); } |
| 66 | bool check(Image &img) const { return walk(CHECK, img); } |
| 67 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 68 | const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions() const { return regions_; } |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 69 | |
| 70 | static void hash_salt_generate() { hash_salt_++; } |
| 71 | |
| 72 | private: |
| 73 | enum Action { |
| 74 | FILL, |
| 75 | CHECK, |
| 76 | }; |
| 77 | |
| 78 | enum Pattern { |
| 79 | HASH, |
| 80 | SOLID, |
| 81 | }; |
| 82 | |
| 83 | XGL_SIZE buffer_cpp() const; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 84 | XGL_SUBRESOURCE_LAYOUT buffer_layout(const XGL_BUFFER_IMAGE_COPY ®ion) const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 85 | |
| 86 | bool walk(Action action, Buffer &buf) const; |
| 87 | bool walk(Action action, Image &img) const; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 88 | bool walk_region(Action action, const XGL_BUFFER_IMAGE_COPY ®ion, const XGL_SUBRESOURCE_LAYOUT &layout, void *data) const; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 89 | |
| 90 | std::vector<uint8_t> pattern_hash(const XGL_IMAGE_SUBRESOURCE &subres, const XGL_OFFSET3D &offset) const; |
| 91 | |
| 92 | static uint32_t hash_salt_; |
| 93 | |
| 94 | XGL_IMAGE_CREATE_INFO info_; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 95 | std::vector<XGL_BUFFER_IMAGE_COPY> regions_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 96 | |
| 97 | Pattern pattern_; |
| 98 | std::vector<uint8_t> pattern_solid_; |
| 99 | }; |
| 100 | |
| 101 | Environment::Environment() : |
| 102 | default_dev_(0) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 103 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 104 | app_.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 105 | app_.pAppName = "xgl_testing"; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 106 | app_.appVersion = 1; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 107 | app_.pEngineName = "xgl_testing"; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 108 | app_.engineVersion = 1; |
| 109 | app_.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 110 | } |
| 111 | |
| 112 | bool Environment::parse_args(int argc, char **argv) |
| 113 | { |
| 114 | int i; |
| 115 | |
| 116 | for (i = 1; i < argc; i++) { |
| 117 | #define ARG(name) (strcmp(argv[i], name) == 0) |
| 118 | #define ARG_P(name) (i < argc - 1 && ARG(name)) |
| 119 | if (ARG_P("--gpu")) { |
| 120 | default_dev_ = atoi(argv[++i]); |
| 121 | } else { |
| 122 | break; |
| 123 | } |
| 124 | #undef ARG |
| 125 | #undef ARG_P |
| 126 | } |
| 127 | |
| 128 | if (i < argc) { |
| 129 | std::cout << |
| 130 | "invalid argument: " << argv[i] << "\n\n" << |
| 131 | "Usage: " << argv[0] << " <options>\n\n" << |
| 132 | "Options:\n" |
| 133 | " --gpu <n> Use GPU<n> as the default GPU\n"; |
| 134 | |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | void Environment::SetUp() |
| 142 | { |
| 143 | XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS]; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 144 | XGL_UINT count; |
| 145 | XGL_RESULT err; |
| 146 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 147 | err = xglInitAndEnumerateGpus(&app_, NULL, ARRAY_SIZE(gpus), &count, gpus); |
| 148 | ASSERT_EQ(XGL_SUCCESS, err); |
| 149 | ASSERT_GT(count, default_dev_); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 150 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 151 | devs_.reserve(count); |
| 152 | for (XGL_UINT i = 0; i < count; i++) { |
| 153 | devs_.push_back(new Device(gpus[i])); |
| 154 | if (i == default_dev_) { |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 155 | devs_[i]->init(); |
| 156 | ASSERT_NE(true, devs_[i]->graphics_queues().empty()); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 157 | } |
| 158 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 159 | } |
| 160 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 161 | void Environment::TearDown() |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 162 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 163 | // destroy devices first |
| 164 | for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++) |
| 165 | delete *it; |
| 166 | devs_.clear(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 167 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 168 | XGL_UINT dummy_count; |
| 169 | xglInitAndEnumerateGpus(&app_, NULL, 0, &dummy_count, NULL); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 170 | } |
| 171 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 172 | uint32_t ImageChecker::hash_salt_; |
| 173 | |
| 174 | ImageChecker::ImageChecker(const XGL_IMAGE_CREATE_INFO &info) |
| 175 | : info_(info), regions_(), pattern_(HASH) |
| 176 | { |
| 177 | // create a region for every mip level in array slice 0 |
| 178 | XGL_GPU_SIZE offset = 0; |
| 179 | for (XGL_UINT lv = 0; lv < info_.mipLevels; lv++) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 180 | XGL_BUFFER_IMAGE_COPY region = {}; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 181 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 182 | region.bufferOffset = offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 183 | region.imageSubresource.mipLevel = lv; |
| 184 | region.imageSubresource.arraySlice = 0; |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 185 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 186 | |
| 187 | if (info_.usage & XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 188 | if (info_.format != XGL_FMT_S8_UINT) { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 189 | region.imageSubresource.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 190 | regions_.push_back(region); |
| 191 | } |
| 192 | |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 193 | if (info_.format == XGL_FMT_D16_UNORM_S8_UINT || |
| 194 | info_.format == XGL_FMT_D32_SFLOAT_S8_UINT || |
| 195 | info_.format == XGL_FMT_S8_UINT) { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 196 | region.imageSubresource.aspect = XGL_IMAGE_ASPECT_STENCIL; |
| 197 | regions_.push_back(region); |
| 198 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 199 | } else { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 200 | region.imageSubresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 201 | regions_.push_back(region); |
| 202 | } |
| 203 | |
| 204 | offset += buffer_layout(region).size; |
| 205 | } |
| 206 | |
| 207 | // arraySize should be limited in our tests. If this proves to be an |
| 208 | // issue, we can store only the regions for array slice 0 and be smart. |
| 209 | if (info_.arraySize > 1) { |
| 210 | const XGL_GPU_SIZE slice_pitch = offset; |
| 211 | const XGL_UINT slice_region_count = regions_.size(); |
| 212 | |
| 213 | regions_.reserve(slice_region_count * info_.arraySize); |
| 214 | |
| 215 | for (XGL_UINT slice = 1; slice < info_.arraySize; slice++) { |
| 216 | for (XGL_UINT i = 0; i < slice_region_count; i++) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 217 | XGL_BUFFER_IMAGE_COPY region = regions_[i]; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 218 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 219 | region.bufferOffset += slice_pitch * slice; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 220 | region.imageSubresource.arraySlice = slice; |
| 221 | regions_.push_back(region); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | ImageChecker::ImageChecker(const XGL_IMAGE_CREATE_INFO &info, const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 228 | : info_(info), regions_(), pattern_(HASH) |
| 229 | { |
| 230 | XGL_GPU_SIZE offset = 0; |
| 231 | for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin(); |
| 232 | it != ranges.end(); it++) { |
| 233 | for (XGL_UINT lv = 0; lv < it->mipLevels; lv++) { |
| 234 | for (XGL_UINT slice = 0; slice < it->arraySize; slice++) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 235 | XGL_BUFFER_IMAGE_COPY region = {}; |
| 236 | region.bufferOffset = offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 237 | region.imageSubresource = Image::subresource(*it, lv, slice); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 238 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 239 | |
| 240 | regions_.push_back(region); |
| 241 | |
| 242 | offset += buffer_layout(region).size; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | void ImageChecker::set_solid_pattern(const std::vector<uint8_t> &solid) |
| 249 | { |
| 250 | pattern_ = SOLID; |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 251 | pattern_solid_.clear(); |
| 252 | pattern_solid_.reserve(buffer_cpp()); |
| 253 | for (int i = 0; i < buffer_cpp(); i++) |
| 254 | pattern_solid_.push_back(solid[i % solid.size()]); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | XGL_SIZE ImageChecker::buffer_cpp() const |
| 258 | { |
| 259 | return get_format_size(info_.format); |
| 260 | } |
| 261 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 262 | XGL_SUBRESOURCE_LAYOUT ImageChecker::buffer_layout(const XGL_BUFFER_IMAGE_COPY ®ion) const |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 263 | { |
| 264 | XGL_SUBRESOURCE_LAYOUT layout = {}; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 265 | layout.offset = region.bufferOffset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 266 | layout.rowPitch = buffer_cpp() * region.imageExtent.width; |
| 267 | layout.depthPitch = layout.rowPitch * region.imageExtent.height; |
| 268 | layout.size = layout.depthPitch * region.imageExtent.depth; |
| 269 | |
| 270 | return layout; |
| 271 | } |
| 272 | |
| 273 | XGL_GPU_SIZE ImageChecker::buffer_size() const |
| 274 | { |
| 275 | XGL_GPU_SIZE size = 0; |
| 276 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 277 | for (std::vector<XGL_BUFFER_IMAGE_COPY>::const_iterator it = regions_.begin(); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 278 | it != regions_.end(); it++) { |
| 279 | const XGL_SUBRESOURCE_LAYOUT layout = buffer_layout(*it); |
| 280 | if (size < layout.offset + layout.size) |
| 281 | size = layout.offset + layout.size; |
| 282 | } |
| 283 | |
| 284 | return size; |
| 285 | } |
| 286 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 287 | bool ImageChecker::walk_region(Action action, const XGL_BUFFER_IMAGE_COPY ®ion, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 288 | const XGL_SUBRESOURCE_LAYOUT &layout, void *data) const |
| 289 | { |
| 290 | for (XGL_INT z = 0; z < region.imageExtent.depth; z++) { |
| 291 | for (XGL_INT y = 0; y < region.imageExtent.height; y++) { |
| 292 | for (XGL_INT x = 0; x < region.imageExtent.width; x++) { |
| 293 | uint8_t *dst = static_cast<uint8_t *>(data); |
| 294 | dst += layout.offset + layout.depthPitch * z + |
| 295 | layout.rowPitch * y + buffer_cpp() * x; |
| 296 | |
| 297 | XGL_OFFSET3D offset = region.imageOffset; |
| 298 | offset.x += x; |
| 299 | offset.y += y; |
| 300 | offset.z += z; |
| 301 | |
| 302 | const std::vector<uint8_t> &val = (pattern_ == HASH) ? |
| 303 | pattern_hash(region.imageSubresource, offset) : |
| 304 | pattern_solid_; |
| 305 | assert(val.size() == buffer_cpp()); |
| 306 | |
| 307 | if (action == FILL) { |
| 308 | memcpy(dst, &val[0], val.size()); |
| 309 | } else { |
| 310 | for (int i = 0; i < val.size(); i++) { |
| 311 | EXPECT_EQ(val[i], dst[i]) << |
| 312 | "Offset is: (" << x << ", " << y << ", " << z << ")"; |
| 313 | if (val[i] != dst[i]) |
| 314 | return false; |
| 315 | } |
| 316 | } |
| 317 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 321 | return true; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 324 | bool ImageChecker::walk(Action action, Buffer &buf) const |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 325 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 326 | void *data = buf.map(); |
| 327 | if (!data) |
| 328 | return false; |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 329 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 330 | std::vector<XGL_BUFFER_IMAGE_COPY>::const_iterator it; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 331 | for (it = regions_.begin(); it != regions_.end(); it++) { |
| 332 | if (!walk_region(action, *it, buffer_layout(*it), data)) |
| 333 | break; |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 334 | } |
| 335 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 336 | buf.unmap(); |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 337 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 338 | return (it == regions_.end()); |
Chia-I Wu | 5b22bc7 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 339 | } |
| 340 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 341 | bool ImageChecker::walk(Action action, Image &img) const |
| 342 | { |
| 343 | void *data = img.map(); |
| 344 | if (!data) |
| 345 | return false; |
| 346 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 347 | std::vector<XGL_BUFFER_IMAGE_COPY>::const_iterator it; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 348 | for (it = regions_.begin(); it != regions_.end(); it++) { |
| 349 | if (!walk_region(action, *it, img.subresource_layout(it->imageSubresource), data)) |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | img.unmap(); |
| 354 | |
| 355 | return (it == regions_.end()); |
| 356 | } |
| 357 | |
| 358 | std::vector<uint8_t> ImageChecker::pattern_hash(const XGL_IMAGE_SUBRESOURCE &subres, const XGL_OFFSET3D &offset) const |
| 359 | { |
| 360 | #define HASH_BYTE(val, b) static_cast<uint8_t>((static_cast<uint32_t>(val) >> (b * 8)) & 0xff) |
| 361 | #define HASH_BYTES(val) HASH_BYTE(val, 0), HASH_BYTE(val, 1), HASH_BYTE(val, 2), HASH_BYTE(val, 3) |
| 362 | const unsigned char input[] = { |
| 363 | HASH_BYTES(hash_salt_), |
| 364 | HASH_BYTES(subres.mipLevel), |
| 365 | HASH_BYTES(subres.arraySlice), |
| 366 | HASH_BYTES(offset.x), |
| 367 | HASH_BYTES(offset.y), |
| 368 | HASH_BYTES(offset.z), |
| 369 | }; |
| 370 | unsigned long hash = 5381; |
| 371 | |
| 372 | for (XGL_INT i = 0; i < ARRAY_SIZE(input); i++) |
| 373 | hash = ((hash << 5) + hash) + input[i]; |
| 374 | |
| 375 | const uint8_t output[4] = { HASH_BYTES(hash) }; |
| 376 | #undef HASH_BYTES |
| 377 | #undef HASH_BYTE |
| 378 | |
Chia-I Wu | 72e3433 | 2014-12-21 14:59:04 +0800 | [diff] [blame] | 379 | std::vector<uint8_t> val; |
| 380 | val.reserve(buffer_cpp()); |
| 381 | for (int i = 0; i < buffer_cpp(); i++) |
| 382 | val.push_back(output[i % 4]); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 383 | |
| 384 | return val; |
| 385 | } |
| 386 | |
| 387 | XGL_SIZE get_format_size(XGL_FORMAT format) |
| 388 | { |
| 389 | static const struct format_info { |
| 390 | XGL_SIZE size; |
| 391 | XGL_UINT channel_count; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 392 | } format_table[XGL_NUM_FMT] = { |
| 393 | [XGL_FMT_UNDEFINED] = { 0, 0 }, |
| 394 | [XGL_FMT_R4G4_UNORM] = { 1, 2 }, |
| 395 | [XGL_FMT_R4G4_USCALED] = { 1, 2 }, |
| 396 | [XGL_FMT_R4G4B4A4_UNORM] = { 2, 4 }, |
| 397 | [XGL_FMT_R4G4B4A4_USCALED] = { 2, 4 }, |
| 398 | [XGL_FMT_R5G6B5_UNORM] = { 2, 3 }, |
| 399 | [XGL_FMT_R5G6B5_USCALED] = { 2, 3 }, |
| 400 | [XGL_FMT_R5G5B5A1_UNORM] = { 2, 4 }, |
| 401 | [XGL_FMT_R5G5B5A1_USCALED] = { 2, 4 }, |
| 402 | [XGL_FMT_R8_UNORM] = { 1, 1 }, |
| 403 | [XGL_FMT_R8_SNORM] = { 1, 1 }, |
| 404 | [XGL_FMT_R8_USCALED] = { 1, 1 }, |
| 405 | [XGL_FMT_R8_SSCALED] = { 1, 1 }, |
| 406 | [XGL_FMT_R8_UINT] = { 1, 1 }, |
| 407 | [XGL_FMT_R8_SINT] = { 1, 1 }, |
| 408 | [XGL_FMT_R8_SRGB] = { 1, 1 }, |
| 409 | [XGL_FMT_R8G8_UNORM] = { 2, 2 }, |
| 410 | [XGL_FMT_R8G8_SNORM] = { 2, 2 }, |
| 411 | [XGL_FMT_R8G8_USCALED] = { 2, 2 }, |
| 412 | [XGL_FMT_R8G8_SSCALED] = { 2, 2 }, |
| 413 | [XGL_FMT_R8G8_UINT] = { 2, 2 }, |
| 414 | [XGL_FMT_R8G8_SINT] = { 2, 2 }, |
| 415 | [XGL_FMT_R8G8_SRGB] = { 2, 2 }, |
| 416 | [XGL_FMT_R8G8B8_UNORM] = { 3, 3 }, |
| 417 | [XGL_FMT_R8G8B8_SNORM] = { 3, 3 }, |
| 418 | [XGL_FMT_R8G8B8_USCALED] = { 3, 3 }, |
| 419 | [XGL_FMT_R8G8B8_SSCALED] = { 3, 3 }, |
| 420 | [XGL_FMT_R8G8B8_UINT] = { 3, 3 }, |
| 421 | [XGL_FMT_R8G8B8_SINT] = { 3, 3 }, |
| 422 | [XGL_FMT_R8G8B8_SRGB] = { 3, 3 }, |
| 423 | [XGL_FMT_R8G8B8A8_UNORM] = { 4, 4 }, |
| 424 | [XGL_FMT_R8G8B8A8_SNORM] = { 4, 4 }, |
| 425 | [XGL_FMT_R8G8B8A8_USCALED] = { 4, 4 }, |
| 426 | [XGL_FMT_R8G8B8A8_SSCALED] = { 4, 4 }, |
| 427 | [XGL_FMT_R8G8B8A8_UINT] = { 4, 4 }, |
| 428 | [XGL_FMT_R8G8B8A8_SINT] = { 4, 4 }, |
| 429 | [XGL_FMT_R8G8B8A8_SRGB] = { 4, 4 }, |
| 430 | [XGL_FMT_R10G10B10A2_UNORM] = { 4, 4 }, |
| 431 | [XGL_FMT_R10G10B10A2_SNORM] = { 4, 4 }, |
| 432 | [XGL_FMT_R10G10B10A2_USCALED] = { 4, 4 }, |
| 433 | [XGL_FMT_R10G10B10A2_SSCALED] = { 4, 4 }, |
| 434 | [XGL_FMT_R10G10B10A2_UINT] = { 4, 4 }, |
| 435 | [XGL_FMT_R10G10B10A2_SINT] = { 4, 4 }, |
| 436 | [XGL_FMT_R16_UNORM] = { 2, 1 }, |
| 437 | [XGL_FMT_R16_SNORM] = { 2, 1 }, |
| 438 | [XGL_FMT_R16_USCALED] = { 2, 1 }, |
| 439 | [XGL_FMT_R16_SSCALED] = { 2, 1 }, |
| 440 | [XGL_FMT_R16_UINT] = { 2, 1 }, |
| 441 | [XGL_FMT_R16_SINT] = { 2, 1 }, |
| 442 | [XGL_FMT_R16_SFLOAT] = { 2, 1 }, |
| 443 | [XGL_FMT_R16G16_UNORM] = { 4, 2 }, |
| 444 | [XGL_FMT_R16G16_SNORM] = { 4, 2 }, |
| 445 | [XGL_FMT_R16G16_USCALED] = { 4, 2 }, |
| 446 | [XGL_FMT_R16G16_SSCALED] = { 4, 2 }, |
| 447 | [XGL_FMT_R16G16_UINT] = { 4, 2 }, |
| 448 | [XGL_FMT_R16G16_SINT] = { 4, 2 }, |
| 449 | [XGL_FMT_R16G16_SFLOAT] = { 4, 2 }, |
| 450 | [XGL_FMT_R16G16B16_UNORM] = { 6, 3 }, |
| 451 | [XGL_FMT_R16G16B16_SNORM] = { 6, 3 }, |
| 452 | [XGL_FMT_R16G16B16_USCALED] = { 6, 3 }, |
| 453 | [XGL_FMT_R16G16B16_SSCALED] = { 6, 3 }, |
| 454 | [XGL_FMT_R16G16B16_UINT] = { 6, 3 }, |
| 455 | [XGL_FMT_R16G16B16_SINT] = { 6, 3 }, |
| 456 | [XGL_FMT_R16G16B16_SFLOAT] = { 6, 3 }, |
| 457 | [XGL_FMT_R16G16B16A16_UNORM] = { 8, 4 }, |
| 458 | [XGL_FMT_R16G16B16A16_SNORM] = { 8, 4 }, |
| 459 | [XGL_FMT_R16G16B16A16_USCALED] = { 8, 4 }, |
| 460 | [XGL_FMT_R16G16B16A16_SSCALED] = { 8, 4 }, |
| 461 | [XGL_FMT_R16G16B16A16_UINT] = { 8, 4 }, |
| 462 | [XGL_FMT_R16G16B16A16_SINT] = { 8, 4 }, |
| 463 | [XGL_FMT_R16G16B16A16_SFLOAT] = { 8, 4 }, |
| 464 | [XGL_FMT_R32_UINT] = { 4, 1 }, |
| 465 | [XGL_FMT_R32_SINT] = { 4, 1 }, |
| 466 | [XGL_FMT_R32_SFLOAT] = { 4, 1 }, |
| 467 | [XGL_FMT_R32G32_UINT] = { 8, 2 }, |
| 468 | [XGL_FMT_R32G32_SINT] = { 8, 2 }, |
| 469 | [XGL_FMT_R32G32_SFLOAT] = { 8, 2 }, |
| 470 | [XGL_FMT_R32G32B32_UINT] = { 12, 3 }, |
| 471 | [XGL_FMT_R32G32B32_SINT] = { 12, 3 }, |
| 472 | [XGL_FMT_R32G32B32_SFLOAT] = { 12, 3 }, |
| 473 | [XGL_FMT_R32G32B32A32_UINT] = { 16, 4 }, |
| 474 | [XGL_FMT_R32G32B32A32_SINT] = { 16, 4 }, |
| 475 | [XGL_FMT_R32G32B32A32_SFLOAT] = { 16, 4 }, |
| 476 | [XGL_FMT_R64_SFLOAT] = { 8, 1 }, |
| 477 | [XGL_FMT_R64G64_SFLOAT] = { 16, 2 }, |
| 478 | [XGL_FMT_R64G64B64_SFLOAT] = { 24, 3 }, |
| 479 | [XGL_FMT_R64G64B64A64_SFLOAT] = { 32, 4 }, |
| 480 | [XGL_FMT_R11G11B10_UFLOAT] = { 4, 3 }, |
| 481 | [XGL_FMT_R9G9B9E5_UFLOAT] = { 4, 3 }, |
| 482 | [XGL_FMT_D16_UNORM] = { 2, 1 }, |
| 483 | [XGL_FMT_D24_UNORM] = { 3, 1 }, |
| 484 | [XGL_FMT_D32_SFLOAT] = { 4, 1 }, |
| 485 | [XGL_FMT_S8_UINT] = { 1, 1 }, |
| 486 | [XGL_FMT_D16_UNORM_S8_UINT] = { 3, 2 }, |
| 487 | [XGL_FMT_D24_UNORM_S8_UINT] = { 4, 2 }, |
| 488 | [XGL_FMT_D32_SFLOAT_S8_UINT] = { 4, 2 }, |
| 489 | [XGL_FMT_BC1_UNORM] = { 8, 4 }, |
| 490 | [XGL_FMT_BC1_SRGB] = { 8, 4 }, |
| 491 | [XGL_FMT_BC2_UNORM] = { 16, 4 }, |
| 492 | [XGL_FMT_BC2_SRGB] = { 16, 4 }, |
| 493 | [XGL_FMT_BC3_UNORM] = { 16, 4 }, |
| 494 | [XGL_FMT_BC3_SRGB] = { 16, 4 }, |
| 495 | [XGL_FMT_BC4_UNORM] = { 8, 4 }, |
| 496 | [XGL_FMT_BC4_SNORM] = { 8, 4 }, |
| 497 | [XGL_FMT_BC5_UNORM] = { 16, 4 }, |
| 498 | [XGL_FMT_BC5_SNORM] = { 16, 4 }, |
| 499 | [XGL_FMT_BC6H_UFLOAT] = { 16, 4 }, |
| 500 | [XGL_FMT_BC6H_SFLOAT] = { 16, 4 }, |
| 501 | [XGL_FMT_BC7_UNORM] = { 16, 4 }, |
| 502 | [XGL_FMT_BC7_SRGB] = { 16, 4 }, |
| 503 | // TODO: Initialize remaining compressed formats. |
| 504 | [XGL_FMT_ETC2_R8G8B8_UNORM] = { 0, 0 }, |
| 505 | [XGL_FMT_ETC2_R8G8B8A1_UNORM] = { 0, 0 }, |
| 506 | [XGL_FMT_ETC2_R8G8B8A8_UNORM] = { 0, 0 }, |
| 507 | [XGL_FMT_EAC_R11_UNORM] = { 0, 0 }, |
| 508 | [XGL_FMT_EAC_R11_SNORM] = { 0, 0 }, |
| 509 | [XGL_FMT_EAC_R11G11_UNORM] = { 0, 0 }, |
| 510 | [XGL_FMT_EAC_R11G11_SNORM] = { 0, 0 }, |
| 511 | [XGL_FMT_ASTC_4x4_UNORM] = { 0, 0 }, |
| 512 | [XGL_FMT_ASTC_4x4_SRGB] = { 0, 0 }, |
| 513 | [XGL_FMT_ASTC_4x5_UNORM] = { 0, 0 }, |
| 514 | [XGL_FMT_ASTC_4x5_SRGB] = { 0, 0 }, |
| 515 | [XGL_FMT_ASTC_5x5_UNORM] = { 0, 0 }, |
| 516 | [XGL_FMT_ASTC_5x5_SRGB] = { 0, 0 }, |
| 517 | [XGL_FMT_ASTC_6x5_UNORM] = { 0, 0 }, |
| 518 | [XGL_FMT_ASTC_6x5_SRGB] = { 0, 0 }, |
| 519 | [XGL_FMT_ASTC_6x6_UNORM] = { 0, 0 }, |
| 520 | [XGL_FMT_ASTC_6x6_SRGB] = { 0, 0 }, |
| 521 | [XGL_FMT_ASTC_8x5_UNORM] = { 0, 0 }, |
| 522 | [XGL_FMT_ASTC_8x5_SRGB] = { 0, 0 }, |
| 523 | [XGL_FMT_ASTC_8x6_UNORM] = { 0, 0 }, |
| 524 | [XGL_FMT_ASTC_8x6_SRGB] = { 0, 0 }, |
| 525 | [XGL_FMT_ASTC_8x8_UNORM] = { 0, 0 }, |
| 526 | [XGL_FMT_ASTC_8x8_SRGB] = { 0, 0 }, |
| 527 | [XGL_FMT_ASTC_10x5_UNORM] = { 0, 0 }, |
| 528 | [XGL_FMT_ASTC_10x5_SRGB] = { 0, 0 }, |
| 529 | [XGL_FMT_ASTC_10x6_UNORM] = { 0, 0 }, |
| 530 | [XGL_FMT_ASTC_10x6_SRGB] = { 0, 0 }, |
| 531 | [XGL_FMT_ASTC_10x8_UNORM] = { 0, 0 }, |
| 532 | [XGL_FMT_ASTC_10x8_SRGB] = { 0, 0 }, |
| 533 | [XGL_FMT_ASTC_10x10_UNORM] = { 0, 0 }, |
| 534 | [XGL_FMT_ASTC_10x10_SRGB] = { 0, 0 }, |
| 535 | [XGL_FMT_ASTC_12x10_UNORM] = { 0, 0 }, |
| 536 | [XGL_FMT_ASTC_12x10_SRGB] = { 0, 0 }, |
| 537 | [XGL_FMT_ASTC_12x12_UNORM] = { 0, 0 }, |
| 538 | [XGL_FMT_ASTC_12x12_SRGB] = { 0, 0 }, |
| 539 | [XGL_FMT_B5G6R5_UNORM] = { 2, 3 }, |
| 540 | [XGL_FMT_B5G6R5_USCALED] = { 2, 3 }, |
| 541 | [XGL_FMT_B8G8R8_UNORM] = { 3, 3 }, |
| 542 | [XGL_FMT_B8G8R8_SNORM] = { 3, 3 }, |
| 543 | [XGL_FMT_B8G8R8_USCALED] = { 3, 3 }, |
| 544 | [XGL_FMT_B8G8R8_SSCALED] = { 3, 3 }, |
| 545 | [XGL_FMT_B8G8R8_UINT] = { 3, 3 }, |
| 546 | [XGL_FMT_B8G8R8_SINT] = { 3, 3 }, |
| 547 | [XGL_FMT_B8G8R8_SRGB] = { 3, 3 }, |
| 548 | [XGL_FMT_B8G8R8A8_UNORM] = { 4, 4 }, |
| 549 | [XGL_FMT_B8G8R8A8_SNORM] = { 4, 4 }, |
| 550 | [XGL_FMT_B8G8R8A8_USCALED] = { 4, 4 }, |
| 551 | [XGL_FMT_B8G8R8A8_SSCALED] = { 4, 4 }, |
| 552 | [XGL_FMT_B8G8R8A8_UINT] = { 4, 4 }, |
| 553 | [XGL_FMT_B8G8R8A8_SINT] = { 4, 4 }, |
| 554 | [XGL_FMT_B8G8R8A8_SRGB] = { 4, 4 }, |
| 555 | [XGL_FMT_B10G10R10A2_UNORM] = { 4, 4 }, |
| 556 | [XGL_FMT_B10G10R10A2_SNORM] = { 4, 4 }, |
| 557 | [XGL_FMT_B10G10R10A2_USCALED] = { 4, 4 }, |
| 558 | [XGL_FMT_B10G10R10A2_SSCALED] = { 4, 4 }, |
| 559 | [XGL_FMT_B10G10R10A2_UINT] = { 4, 4 }, |
| 560 | [XGL_FMT_B10G10R10A2_SINT] = { 4, 4 }, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 561 | }; |
| 562 | |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 563 | return format_table[format].size; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | XGL_EXTENT3D get_mip_level_extent(const XGL_EXTENT3D &extent, XGL_UINT mip_level) |
| 567 | { |
| 568 | const XGL_EXTENT3D ext = { |
| 569 | (extent.width >> mip_level) ? extent.width >> mip_level : 1, |
| 570 | (extent.height >> mip_level) ? extent.height >> mip_level : 1, |
| 571 | (extent.depth >> mip_level) ? extent.depth >> mip_level : 1, |
| 572 | }; |
| 573 | |
| 574 | return ext; |
| 575 | } |
| 576 | |
| 577 | }; // namespace xgl_testing |
| 578 | |
| 579 | namespace { |
| 580 | |
| 581 | #define DO(action) ASSERT_EQ(true, action); |
| 582 | |
| 583 | xgl_testing::Environment *environment; |
| 584 | |
| 585 | class XglCmdBlitTest : public ::testing::Test { |
| 586 | protected: |
| 587 | XglCmdBlitTest() : |
| 588 | dev_(environment->default_device()), |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 589 | queue_(*dev_.graphics_queues()[0]), |
| 590 | cmd_(dev_, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS)) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 591 | { |
| 592 | // make sure every test uses a different pattern |
| 593 | xgl_testing::ImageChecker::hash_salt_generate(); |
| 594 | } |
| 595 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 596 | bool submit_and_done() |
| 597 | { |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 598 | queue_.submit(cmd_, mem_refs_); |
| 599 | queue_.wait(); |
| 600 | mem_refs_.clear(); |
| 601 | return true; |
| 602 | } |
| 603 | |
| 604 | void add_memory_ref(const xgl_testing::Object &obj, XGL_FLAGS flags) |
| 605 | { |
| 606 | const std::vector<XGL_GPU_MEMORY> mems = obj.memories(); |
| 607 | for (std::vector<XGL_GPU_MEMORY>::const_iterator it = mems.begin(); it != mems.end(); it++) { |
| 608 | std::vector<XGL_MEMORY_REF>::iterator ref; |
| 609 | for (ref = mem_refs_.begin(); ref != mem_refs_.end(); ref++) { |
| 610 | if (ref->mem == *it) |
| 611 | break; |
| 612 | } |
| 613 | |
| 614 | if (ref == mem_refs_.end()) { |
| 615 | XGL_MEMORY_REF tmp = {}; |
| 616 | tmp.mem = *it; |
| 617 | tmp.flags = flags; |
| 618 | mem_refs_.push_back(tmp); |
| 619 | } else { |
| 620 | ref->flags &= flags; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 625 | xgl_testing::Device &dev_; |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 626 | xgl_testing::Queue &queue_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 627 | xgl_testing::CmdBuffer cmd_; |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 628 | |
| 629 | std::vector<XGL_MEMORY_REF> mem_refs_; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 630 | }; |
| 631 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 632 | typedef XglCmdBlitTest XglCmdFillBufferTest; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 633 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 634 | TEST_F(XglCmdFillBufferTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 635 | { |
| 636 | xgl_testing::Buffer buf; |
| 637 | |
| 638 | buf.init(dev_, 20); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 639 | add_memory_ref(buf, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 640 | |
| 641 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 642 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111); |
| 643 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 644 | cmd_.end(); |
| 645 | |
| 646 | submit_and_done(); |
| 647 | |
| 648 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 649 | EXPECT_EQ(0x11111111, data[0]); |
| 650 | EXPECT_EQ(0x22222222, data[1]); |
| 651 | EXPECT_EQ(0x22222222, data[2]); |
| 652 | EXPECT_EQ(0x22222222, data[3]); |
| 653 | EXPECT_EQ(0x22222222, data[4]); |
| 654 | buf.unmap(); |
| 655 | } |
| 656 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 657 | TEST_F(XglCmdFillBufferTest, Large) |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 658 | { |
| 659 | const XGL_GPU_SIZE size = 32 * 1024 * 1024; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 660 | xgl_testing::Buffer buf; |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 661 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 662 | buf.init(dev_, size); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 663 | add_memory_ref(buf, 0); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 664 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 665 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 666 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111); |
| 667 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 668 | cmd_.end(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 669 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 670 | submit_and_done(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 671 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 672 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 673 | XGL_GPU_SIZE offset; |
| 674 | for (offset = 0; offset < size / 2; offset += 4) |
| 675 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 676 | for (; offset < size; offset += 4) |
| 677 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
| 678 | buf.unmap(); |
| 679 | } |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 680 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 681 | TEST_F(XglCmdFillBufferTest, Overlap) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 682 | { |
| 683 | xgl_testing::Buffer buf; |
| 684 | |
| 685 | buf.init(dev_, 64); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 686 | add_memory_ref(buf, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 687 | |
| 688 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 689 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111); |
| 690 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 691 | cmd_.end(); |
| 692 | |
| 693 | submit_and_done(); |
| 694 | |
| 695 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 696 | XGL_GPU_SIZE offset; |
| 697 | for (offset = 0; offset < 32; offset += 4) |
| 698 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 699 | for (; offset < 64; offset += 4) |
| 700 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
| 701 | buf.unmap(); |
| 702 | } |
| 703 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 704 | TEST_F(XglCmdFillBufferTest, MultiAlignments) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 705 | { |
| 706 | xgl_testing::Buffer bufs[9]; |
| 707 | XGL_GPU_SIZE size = 4; |
| 708 | |
| 709 | cmd_.begin(); |
| 710 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 711 | bufs[i].init(dev_, size); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 712 | add_memory_ref(bufs[i], 0); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 713 | xglCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 714 | size <<= 1; |
| 715 | } |
| 716 | cmd_.end(); |
| 717 | |
| 718 | submit_and_done(); |
| 719 | |
| 720 | size = 4; |
| 721 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 722 | const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map()); |
| 723 | XGL_GPU_SIZE offset; |
| 724 | for (offset = 0; offset < size; offset += 4) |
| 725 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" << |
| 726 | "Offset is: " << offset; |
| 727 | bufs[i].unmap(); |
| 728 | |
| 729 | size <<= 1; |
| 730 | } |
| 731 | } |
| 732 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 733 | typedef XglCmdBlitTest XglCmdCopyBufferTest; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 734 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 735 | TEST_F(XglCmdCopyBufferTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 736 | { |
| 737 | xgl_testing::Buffer src, dst; |
| 738 | |
| 739 | src.init(dev_, 4); |
| 740 | uint32_t *data = static_cast<uint32_t *>(src.map()); |
| 741 | data[0] = 0x11111111; |
| 742 | src.unmap(); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 743 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 744 | |
| 745 | dst.init(dev_, 4); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 746 | add_memory_ref(dst, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 747 | |
| 748 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 749 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 750 | region.copySize = 4; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 751 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, ®ion); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 752 | cmd_.end(); |
| 753 | |
| 754 | submit_and_done(); |
| 755 | |
| 756 | data = static_cast<uint32_t *>(dst.map()); |
| 757 | EXPECT_EQ(0x11111111, data[0]); |
| 758 | dst.unmap(); |
| 759 | } |
| 760 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 761 | TEST_F(XglCmdCopyBufferTest, Large) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 762 | { |
| 763 | const XGL_GPU_SIZE size = 32 * 1024 * 1024; |
| 764 | xgl_testing::Buffer src, dst; |
| 765 | |
| 766 | src.init(dev_, size); |
| 767 | uint32_t *data = static_cast<uint32_t *>(src.map()); |
| 768 | XGL_GPU_SIZE offset; |
| 769 | for (offset = 0; offset < size; offset += 4) |
| 770 | data[offset / 4] = offset; |
| 771 | src.unmap(); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 772 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 773 | |
| 774 | dst.init(dev_, size); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 775 | add_memory_ref(dst, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 776 | |
| 777 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 778 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 779 | region.copySize = size; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 780 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, ®ion); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 781 | cmd_.end(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 782 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 783 | submit_and_done(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 784 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 785 | data = static_cast<uint32_t *>(dst.map()); |
| 786 | for (offset = 0; offset < size; offset += 4) |
| 787 | EXPECT_EQ(offset, data[offset / 4]); |
| 788 | dst.unmap(); |
Chia-I Wu | d94726f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 789 | } |
| 790 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 791 | TEST_F(XglCmdCopyBufferTest, MultiAlignments) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 792 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 793 | const XGL_BUFFER_COPY regions[] = { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 794 | /* well aligned */ |
| 795 | { 0, 0, 256 }, |
| 796 | { 0, 256, 128 }, |
| 797 | { 0, 384, 64 }, |
| 798 | { 0, 448, 32 }, |
| 799 | { 0, 480, 16 }, |
| 800 | { 0, 496, 8 }, |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 801 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 802 | /* ill aligned */ |
| 803 | { 7, 510, 16 }, |
| 804 | { 16, 530, 13 }, |
| 805 | { 32, 551, 16 }, |
| 806 | { 45, 570, 15 }, |
| 807 | { 50, 590, 1 }, |
| 808 | }; |
| 809 | xgl_testing::Buffer src, dst; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 810 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 811 | src.init(dev_, 256); |
| 812 | uint8_t *data = static_cast<uint8_t *>(src.map()); |
| 813 | for (int i = 0; i < 256; i++) |
| 814 | data[i] = i; |
| 815 | src.unmap(); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 816 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 817 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 818 | dst.init(dev_, 1024); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 819 | add_memory_ref(dst, 0); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 820 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 821 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 822 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 823 | cmd_.end(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 824 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 825 | submit_and_done(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 826 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 827 | data = static_cast<uint8_t *>(dst.map()); |
| 828 | for (int i = 0; i < ARRAY_SIZE(regions); i++) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 829 | const XGL_BUFFER_COPY &r = regions[i]; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 830 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 831 | for (int j = 0; j < r.copySize; j++) { |
| 832 | EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) << |
| 833 | "Region is: " << i << "\n" << |
| 834 | "Offset is: " << r.destOffset + j; |
| 835 | } |
| 836 | } |
| 837 | dst.unmap(); |
| 838 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 839 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 840 | TEST_F(XglCmdCopyBufferTest, RAWHazard) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 841 | { |
| 842 | xgl_testing::Buffer bufs[3]; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 843 | XGL_EVENT_CREATE_INFO event_info; |
| 844 | XGL_EVENT event; |
| 845 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 846 | size_t data_size = sizeof(mem_req); |
| 847 | XGL_RESULT err; |
| 848 | |
| 849 | // typedef struct _XGL_EVENT_CREATE_INFO |
| 850 | // { |
| 851 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO |
| 852 | // const XGL_VOID* pNext; // Pointer to next structure |
| 853 | // XGL_FLAGS flags; // Reserved |
| 854 | // } XGL_EVENT_CREATE_INFO; |
| 855 | memset(&event_info, 0, sizeof(event_info)); |
| 856 | event_info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 857 | |
| 858 | err = xglCreateEvent(dev_.obj(), &event_info, &event); |
| 859 | ASSERT_XGL_SUCCESS(err); |
| 860 | |
| 861 | err = xglGetObjectInfo(event, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 862 | &data_size, &mem_req); |
| 863 | ASSERT_XGL_SUCCESS(err); |
| 864 | |
| 865 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 866 | // XGL_DEVICE device, |
| 867 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 868 | // XGL_GPU_MEMORY* pMem); |
| 869 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 870 | XGL_GPU_MEMORY event_mem; |
| 871 | |
| 872 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect events to require memory"; |
| 873 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 874 | memset(&mem_info, 0, sizeof(mem_info)); |
| 875 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 876 | mem_info.allocationSize = mem_req.size; |
Jon Ashburn | 205b422 | 2015-01-20 16:59:42 -0700 | [diff] [blame] | 877 | mem_info.memType = mem_req.memType; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 878 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
Jon Ashburn | e01ff7a | 2015-01-20 15:06:59 -0700 | [diff] [blame] | 879 | mem_info.memProps = XGL_MEMORY_PROPERTY_SHAREABLE_BIT; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 880 | err = xglAllocMemory(dev_.obj(), &mem_info, &event_mem); |
| 881 | ASSERT_XGL_SUCCESS(err); |
| 882 | |
Jon Ashburn | 9b6eae5 | 2015-01-15 10:39:19 -0700 | [diff] [blame] | 883 | err = xglBindObjectMemory(event, 0, event_mem, 0); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 884 | ASSERT_XGL_SUCCESS(err); |
| 885 | |
| 886 | err = xglResetEvent(event); |
| 887 | ASSERT_XGL_SUCCESS(err); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 888 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 889 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 890 | bufs[i].init(dev_, 4); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 891 | add_memory_ref(bufs[i], 0); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 892 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 893 | uint32_t *data = static_cast<uint32_t *>(bufs[i].map()); |
| 894 | data[0] = 0x22222222 * (i + 1); |
| 895 | bufs[i].unmap(); |
| 896 | } |
| 897 | |
| 898 | cmd_.begin(); |
| 899 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 900 | xglCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 901 | // is this necessary? |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 902 | XGL_BUFFER_MEMORY_BARRIER memory_barrier = bufs[0].buffer_memory_barrier( |
| 903 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4); |
| 904 | |
| 905 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_TRANSFER_COMPLETE }; |
| 906 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 907 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 908 | pipeline_barrier.eventCount = 1; |
| 909 | pipeline_barrier.pEvents = set_events; |
| 910 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 911 | pipeline_barrier.memBarrierCount = 1; |
| 912 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 913 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 914 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 915 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 916 | region.copySize = 4; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 917 | xglCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, ®ion); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 918 | |
| 919 | memory_barrier = bufs[1].buffer_memory_barrier( |
| 920 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4); |
| 921 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 922 | pipeline_barrier.eventCount = 1; |
| 923 | pipeline_barrier.pEvents = set_events; |
| 924 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 925 | pipeline_barrier.memBarrierCount = 1; |
| 926 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 927 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 928 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 929 | xglCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, ®ion); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 930 | |
| 931 | /* Use xglCmdSetEvent and xglCmdWaitEvents to test them. |
| 932 | * This could be xglCmdPipelineBarrier. |
| 933 | */ |
| 934 | xglCmdSetEvent(cmd_.obj(), event, XGL_SET_EVENT_TRANSFER_COMPLETE); |
| 935 | |
| 936 | // Additional commands could go into the buffer here before the wait. |
| 937 | |
| 938 | memory_barrier = bufs[1].buffer_memory_barrier( |
| 939 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_CPU_READ_BIT, 0, 4); |
| 940 | XGL_EVENT_WAIT_INFO wait_info = {}; |
| 941 | wait_info.sType = XGL_STRUCTURE_TYPE_EVENT_WAIT_INFO; |
| 942 | wait_info.eventCount = 1; |
| 943 | wait_info.pEvents = &event; |
| 944 | wait_info.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 945 | wait_info.memBarrierCount = 1; |
| 946 | wait_info.pMemBarriers = &memory_barrier; |
| 947 | xglCmdWaitEvents(cmd_.obj(), &wait_info); |
| 948 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 949 | cmd_.end(); |
| 950 | |
| 951 | submit_and_done(); |
| 952 | |
| 953 | const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map()); |
| 954 | EXPECT_EQ(0x11111111, data[0]); |
| 955 | bufs[2].unmap(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 956 | |
| 957 | // All done with event memory, clean up |
Jon Ashburn | 9b6eae5 | 2015-01-15 10:39:19 -0700 | [diff] [blame] | 958 | err = xglBindObjectMemory(event, 0, XGL_NULL_HANDLE, 0); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 959 | ASSERT_XGL_SUCCESS(err); |
| 960 | |
| 961 | err = xglDestroyObject(event); |
| 962 | ASSERT_XGL_SUCCESS(err); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | class XglCmdBlitImageTest : public XglCmdBlitTest { |
| 966 | protected: |
| 967 | void init_test_formats(XGL_FLAGS features) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 968 | { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 969 | first_linear_format_ = XGL_FMT_UNDEFINED; |
| 970 | first_optimal_format_ = XGL_FMT_UNDEFINED; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 971 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 972 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = dev_.formats().begin(); |
| 973 | it != dev_.formats().end(); it++) { |
| 974 | if (it->features & features) { |
| 975 | test_formats_.push_back(*it); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 976 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 977 | if (it->tiling == XGL_LINEAR_TILING && |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 978 | first_linear_format_ == XGL_FMT_UNDEFINED) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 979 | first_linear_format_ = it->format; |
| 980 | if (it->tiling == XGL_OPTIMAL_TILING && |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 981 | first_optimal_format_ == XGL_FMT_UNDEFINED) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 982 | first_optimal_format_ = it->format; |
| 983 | } |
| 984 | } |
| 985 | } |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 986 | |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 987 | void init_test_formats() |
| 988 | { |
| 989 | init_test_formats(static_cast<XGL_FLAGS>(-1)); |
| 990 | } |
| 991 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 992 | void fill_src(xgl_testing::Image &img, const xgl_testing::ImageChecker &checker) |
| 993 | { |
| 994 | if (img.transparent()) { |
| 995 | checker.fill(img); |
| 996 | return; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 997 | } |
| 998 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 999 | ASSERT_EQ(true, img.copyable()); |
| 1000 | |
| 1001 | xgl_testing::Buffer in_buf; |
| 1002 | in_buf.init(dev_, checker.buffer_size()); |
| 1003 | checker.fill(in_buf); |
| 1004 | |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1005 | add_memory_ref(in_buf, XGL_MEMORY_REF_READ_ONLY_BIT); |
| 1006 | add_memory_ref(img, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1007 | |
| 1008 | // copy in and tile |
| 1009 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1010 | xglCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(), img.obj(), |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1011 | checker.regions().size(), &checker.regions()[0]); |
| 1012 | cmd_.end(); |
| 1013 | |
| 1014 | submit_and_done(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1015 | } |
| 1016 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1017 | void check_dst(xgl_testing::Image &img, const xgl_testing::ImageChecker &checker) |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 1018 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1019 | if (img.transparent()) { |
| 1020 | DO(checker.check(img)); |
| 1021 | return; |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1024 | ASSERT_EQ(true, img.copyable()); |
| 1025 | |
| 1026 | xgl_testing::Buffer out_buf; |
| 1027 | out_buf.init(dev_, checker.buffer_size()); |
| 1028 | |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1029 | add_memory_ref(img, XGL_MEMORY_REF_READ_ONLY_BIT); |
| 1030 | add_memory_ref(out_buf, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1031 | |
| 1032 | // copy out and linearize |
| 1033 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1034 | xglCmdCopyImageToBuffer(cmd_.obj(), img.obj(), out_buf.obj(), |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1035 | checker.regions().size(), &checker.regions()[0]); |
| 1036 | cmd_.end(); |
| 1037 | |
| 1038 | submit_and_done(); |
| 1039 | |
| 1040 | DO(checker.check(out_buf)); |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1043 | std::vector<xgl_testing::Device::Format> test_formats_; |
| 1044 | XGL_FORMAT first_linear_format_; |
| 1045 | XGL_FORMAT first_optimal_format_; |
| 1046 | }; |
| 1047 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1048 | class XglCmdCopyBufferToImageTest : public XglCmdBlitImageTest { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1049 | protected: |
| 1050 | virtual void SetUp() |
| 1051 | { |
| 1052 | XglCmdBlitTest::SetUp(); |
| 1053 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 1054 | ASSERT_NE(true, test_formats_.empty()); |
| 1055 | } |
| 1056 | |
| 1057 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info, const xgl_testing::ImageChecker &checker) |
| 1058 | { |
| 1059 | xgl_testing::Buffer buf; |
| 1060 | xgl_testing::Image img; |
| 1061 | |
| 1062 | buf.init(dev_, checker.buffer_size()); |
| 1063 | checker.fill(buf); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1064 | add_memory_ref(buf, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1065 | |
| 1066 | img.init(dev_, img_info); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1067 | add_memory_ref(img, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1068 | |
| 1069 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1070 | xglCmdCopyBufferToImage(cmd_.obj(), buf.obj(), img.obj(), |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1071 | checker.regions().size(), &checker.regions()[0]); |
| 1072 | cmd_.end(); |
| 1073 | |
| 1074 | submit_and_done(); |
| 1075 | |
| 1076 | check_dst(img, checker); |
| 1077 | } |
| 1078 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1079 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info, const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1080 | { |
| 1081 | xgl_testing::ImageChecker checker(img_info, regions); |
| 1082 | test_copy_memory_to_image(img_info, checker); |
| 1083 | } |
| 1084 | |
| 1085 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info) |
| 1086 | { |
| 1087 | xgl_testing::ImageChecker checker(img_info); |
| 1088 | test_copy_memory_to_image(img_info, checker); |
| 1089 | } |
| 1090 | }; |
| 1091 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1092 | TEST_F(XglCmdCopyBufferToImageTest, Basic) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1093 | { |
| 1094 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1095 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1096 | |
| 1097 | // not sure what to do here |
| 1098 | if (it->format == XGL_FMT_UNDEFINED || |
| 1099 | (it->format >= XGL_FMT_B8G8R8_UNORM && |
| 1100 | it->format <= XGL_FMT_B8G8R8_SRGB)) |
| 1101 | continue; |
| 1102 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1103 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1104 | img_info.imageType = XGL_IMAGE_2D; |
| 1105 | img_info.format = it->format; |
| 1106 | img_info.extent.width = 64; |
| 1107 | img_info.extent.height = 64; |
| 1108 | img_info.tiling = it->tiling; |
| 1109 | |
| 1110 | test_copy_memory_to_image(img_info); |
| 1111 | } |
Chia-I Wu | d647901 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 1112 | } |
| 1113 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1114 | class XglCmdCopyImageToBufferTest : public XglCmdBlitImageTest { |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1115 | protected: |
| 1116 | virtual void SetUp() |
| 1117 | { |
| 1118 | XglCmdBlitTest::SetUp(); |
| 1119 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 1120 | ASSERT_NE(true, test_formats_.empty()); |
| 1121 | } |
| 1122 | |
| 1123 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info, const xgl_testing::ImageChecker &checker) |
| 1124 | { |
| 1125 | xgl_testing::Image img; |
| 1126 | xgl_testing::Buffer buf; |
| 1127 | |
| 1128 | img.init(dev_, img_info); |
| 1129 | fill_src(img, checker); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1130 | add_memory_ref(img, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1131 | |
| 1132 | buf.init(dev_, checker.buffer_size()); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1133 | add_memory_ref(buf, 0); |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1134 | |
| 1135 | cmd_.begin(); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1136 | xglCmdCopyImageToBuffer(cmd_.obj(), img.obj(), buf.obj(), |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1137 | checker.regions().size(), &checker.regions()[0]); |
| 1138 | cmd_.end(); |
| 1139 | |
| 1140 | submit_and_done(); |
| 1141 | |
| 1142 | checker.check(buf); |
| 1143 | } |
| 1144 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1145 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info, const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1146 | { |
| 1147 | xgl_testing::ImageChecker checker(img_info, regions); |
| 1148 | test_copy_image_to_memory(img_info, checker); |
| 1149 | } |
| 1150 | |
| 1151 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info) |
| 1152 | { |
| 1153 | xgl_testing::ImageChecker checker(img_info); |
| 1154 | test_copy_image_to_memory(img_info, checker); |
| 1155 | } |
| 1156 | }; |
| 1157 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1158 | TEST_F(XglCmdCopyImageToBufferTest, Basic) |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1159 | { |
| 1160 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1161 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1162 | |
| 1163 | // not sure what to do here |
| 1164 | if (it->format == XGL_FMT_UNDEFINED || |
| 1165 | (it->format >= XGL_FMT_B8G8R8_UNORM && |
| 1166 | it->format <= XGL_FMT_B8G8R8_SRGB)) |
| 1167 | continue; |
| 1168 | |
Chia-I Wu | 42b97b8 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1169 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1170 | img_info.imageType = XGL_IMAGE_2D; |
| 1171 | img_info.format = it->format; |
| 1172 | img_info.extent.width = 64; |
| 1173 | img_info.extent.height = 64; |
| 1174 | img_info.tiling = it->tiling; |
| 1175 | |
| 1176 | test_copy_image_to_memory(img_info); |
| 1177 | } |
| 1178 | } |
| 1179 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1180 | class XglCmdCopyImageTest : public XglCmdBlitImageTest { |
| 1181 | protected: |
| 1182 | virtual void SetUp() |
| 1183 | { |
| 1184 | XglCmdBlitTest::SetUp(); |
| 1185 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 1186 | ASSERT_NE(true, test_formats_.empty()); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1189 | void test_copy_image(const XGL_IMAGE_CREATE_INFO &src_info, const XGL_IMAGE_CREATE_INFO &dst_info, |
| 1190 | const std::vector<XGL_IMAGE_COPY> &copies) |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1191 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1192 | // convert XGL_IMAGE_COPY to two sets of XGL_BUFFER_IMAGE_COPY |
| 1193 | std::vector<XGL_BUFFER_IMAGE_COPY> src_regions, dst_regions; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1194 | XGL_GPU_SIZE src_offset = 0, dst_offset = 0; |
| 1195 | for (std::vector<XGL_IMAGE_COPY>::const_iterator it = copies.begin(); it != copies.end(); it++) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1196 | XGL_BUFFER_IMAGE_COPY src_region = {}, dst_region = {}; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1197 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1198 | src_region.bufferOffset = src_offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1199 | src_region.imageSubresource = it->srcSubresource; |
| 1200 | src_region.imageOffset = it->srcOffset; |
| 1201 | src_region.imageExtent = it->extent; |
| 1202 | src_regions.push_back(src_region); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1203 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1204 | dst_region.bufferOffset = src_offset; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1205 | dst_region.imageSubresource = it->destSubresource; |
| 1206 | dst_region.imageOffset = it->destOffset; |
| 1207 | dst_region.imageExtent = it->extent; |
| 1208 | dst_regions.push_back(dst_region); |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1209 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1210 | const XGL_GPU_SIZE size = it->extent.width * it->extent.height * it->extent.depth; |
| 1211 | src_offset += xgl_testing::get_format_size(src_info.format) * size; |
| 1212 | dst_offset += xgl_testing::get_format_size(dst_info.format) * size; |
| 1213 | } |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1214 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1215 | xgl_testing::ImageChecker src_checker(src_info, src_regions); |
| 1216 | xgl_testing::ImageChecker dst_checker(dst_info, dst_regions); |
| 1217 | |
| 1218 | xgl_testing::Image src; |
| 1219 | src.init(dev_, src_info); |
| 1220 | fill_src(src, src_checker); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1221 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1222 | |
| 1223 | xgl_testing::Image dst; |
| 1224 | dst.init(dev_, dst_info); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1225 | add_memory_ref(dst, 0); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1226 | |
| 1227 | cmd_.begin(); |
| 1228 | xglCmdCopyImage(cmd_.obj(), src.obj(), dst.obj(), copies.size(), &copies[0]); |
| 1229 | cmd_.end(); |
| 1230 | |
| 1231 | submit_and_done(); |
| 1232 | |
| 1233 | check_dst(dst, dst_checker); |
| 1234 | } |
| 1235 | }; |
| 1236 | |
| 1237 | TEST_F(XglCmdCopyImageTest, Basic) |
| 1238 | { |
| 1239 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1240 | it != test_formats_.end(); it++) { |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1241 | |
| 1242 | // not sure what to do here |
| 1243 | if (it->format == XGL_FMT_UNDEFINED || |
| 1244 | (it->format >= XGL_FMT_B8G8R8_UNORM && |
| 1245 | it->format <= XGL_FMT_B8G8R8_SRGB)) |
| 1246 | continue; |
| 1247 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1248 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1249 | img_info.imageType = XGL_IMAGE_2D; |
| 1250 | img_info.format = it->format; |
| 1251 | img_info.extent.width = 64; |
| 1252 | img_info.extent.height = 64; |
| 1253 | img_info.tiling = it->tiling; |
| 1254 | |
| 1255 | XGL_IMAGE_COPY copy = {}; |
| 1256 | copy.srcSubresource = xgl_testing::Image::subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0); |
| 1257 | copy.destSubresource = copy.srcSubresource; |
| 1258 | copy.extent = img_info.extent; |
| 1259 | |
| 1260 | test_copy_image(img_info, img_info, std::vector<XGL_IMAGE_COPY>(©, © + 1)); |
| 1261 | } |
| 1262 | } |
| 1263 | |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1264 | class XglCmdCloneImageDataTest : public XglCmdBlitImageTest { |
| 1265 | protected: |
| 1266 | virtual void SetUp() |
| 1267 | { |
| 1268 | XglCmdBlitTest::SetUp(); |
| 1269 | init_test_formats(); |
| 1270 | ASSERT_NE(true, test_formats_.empty()); |
| 1271 | } |
| 1272 | |
| 1273 | void test_clone_image_data(const XGL_IMAGE_CREATE_INFO &img_info) |
| 1274 | { |
| 1275 | xgl_testing::ImageChecker checker(img_info); |
| 1276 | xgl_testing::Image src, dst; |
| 1277 | |
| 1278 | src.init(dev_, img_info); |
| 1279 | if (src.transparent() || src.copyable()) |
| 1280 | fill_src(src, checker); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1281 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1282 | |
| 1283 | dst.init(dev_, img_info); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1284 | add_memory_ref(dst, 0); |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1285 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1286 | const XGL_IMAGE_LAYOUT layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1287 | |
| 1288 | cmd_.begin(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1289 | xglCmdCloneImageData(cmd_.obj(), src.obj(), layout, dst.obj(), layout); |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1290 | cmd_.end(); |
| 1291 | |
| 1292 | submit_and_done(); |
| 1293 | |
| 1294 | // cannot verify |
| 1295 | if (!dst.transparent() && !dst.copyable()) |
| 1296 | return; |
| 1297 | |
| 1298 | check_dst(dst, checker); |
| 1299 | } |
| 1300 | }; |
| 1301 | |
| 1302 | TEST_F(XglCmdCloneImageDataTest, Basic) |
| 1303 | { |
| 1304 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1305 | it != test_formats_.end(); it++) { |
| 1306 | // not sure what to do here |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1307 | if (it->format == XGL_FMT_UNDEFINED || |
| 1308 | (it->format >= XGL_FMT_R32G32B32_UINT && |
| 1309 | it->format <= XGL_FMT_R32G32B32_SFLOAT) || |
| 1310 | (it->format >= XGL_FMT_B8G8R8_UNORM && |
| 1311 | it->format <= XGL_FMT_B8G8R8_SRGB) || |
| 1312 | (it->format >= XGL_FMT_BC1_UNORM && |
| 1313 | it->format <= XGL_FMT_ASTC_12x12_SRGB) || |
| 1314 | (it->format >= XGL_FMT_D16_UNORM && |
| 1315 | it->format <= XGL_FMT_D32_SFLOAT_S8_UINT) || |
| 1316 | it->format == XGL_FMT_R64G64B64_SFLOAT || |
| 1317 | it->format == XGL_FMT_R64G64B64A64_SFLOAT) |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1318 | continue; |
| 1319 | |
| 1320 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1321 | img_info.imageType = XGL_IMAGE_2D; |
| 1322 | img_info.format = it->format; |
| 1323 | img_info.extent.width = 64; |
| 1324 | img_info.extent.height = 64; |
| 1325 | img_info.tiling = it->tiling; |
| 1326 | img_info.flags = XGL_IMAGE_CREATE_CLONEABLE_BIT; |
| 1327 | |
| 1328 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1329 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | 2bb96ef | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1330 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1331 | |
| 1332 | test_clone_image_data(img_info); |
| 1333 | } |
| 1334 | } |
| 1335 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1336 | class XglCmdClearColorImageTest : public XglCmdBlitImageTest { |
| 1337 | protected: |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1338 | XglCmdClearColorImageTest() : test_raw_(false) {} |
| 1339 | XglCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {} |
| 1340 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1341 | virtual void SetUp() |
| 1342 | { |
| 1343 | XglCmdBlitTest::SetUp(); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1344 | |
| 1345 | if (test_raw_) |
| 1346 | init_test_formats(); |
| 1347 | else |
| 1348 | init_test_formats(XGL_FORMAT_CONVERSION_BIT); |
| 1349 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1350 | ASSERT_NE(true, test_formats_.empty()); |
| 1351 | } |
| 1352 | |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1353 | union Color { |
| 1354 | XGL_FLOAT color[4]; |
| 1355 | XGL_UINT32 raw[4]; |
| 1356 | }; |
| 1357 | |
| 1358 | bool test_raw_; |
| 1359 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1360 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const XGL_FLOAT color[4]) |
| 1361 | { |
| 1362 | std::vector<uint8_t> raw; |
| 1363 | |
| 1364 | // TODO support all formats |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1365 | switch (format) { |
| 1366 | case XGL_FMT_R8G8B8A8_UNORM: |
| 1367 | raw.push_back(color[0] * 255.0f); |
| 1368 | raw.push_back(color[1] * 255.0f); |
| 1369 | raw.push_back(color[2] * 255.0f); |
| 1370 | raw.push_back(color[3] * 255.0f); |
| 1371 | break; |
| 1372 | case XGL_FMT_B8G8R8A8_UNORM: |
| 1373 | raw.push_back(color[2] * 255.0f); |
| 1374 | raw.push_back(color[1] * 255.0f); |
| 1375 | raw.push_back(color[0] * 255.0f); |
| 1376 | raw.push_back(color[3] * 255.0f); |
| 1377 | break; |
| 1378 | default: |
| 1379 | break; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1382 | return raw; |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1383 | } |
Chia-I Wu | 89078aa | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1384 | |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1385 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const XGL_UINT32 color[4]) |
| 1386 | { |
| 1387 | std::vector<uint8_t> raw; |
| 1388 | |
| 1389 | // TODO support all formats |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1390 | switch (format) { |
| 1391 | case XGL_FMT_R8G8B8A8_UNORM: |
| 1392 | raw.push_back(static_cast<uint8_t>(color[0])); |
| 1393 | raw.push_back(static_cast<uint8_t>(color[1])); |
| 1394 | raw.push_back(static_cast<uint8_t>(color[2])); |
| 1395 | raw.push_back(static_cast<uint8_t>(color[3])); |
| 1396 | break; |
| 1397 | case XGL_FMT_B8G8R8A8_UNORM: |
| 1398 | raw.push_back(static_cast<uint8_t>(color[2])); |
| 1399 | raw.push_back(static_cast<uint8_t>(color[1])); |
| 1400 | raw.push_back(static_cast<uint8_t>(color[0])); |
| 1401 | raw.push_back(static_cast<uint8_t>(color[3])); |
| 1402 | break; |
| 1403 | default: |
| 1404 | break; |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | return raw; |
| 1408 | } |
| 1409 | |
| 1410 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const Color &color) |
| 1411 | { |
| 1412 | if (test_raw_) |
| 1413 | return color_to_raw(format, color.raw); |
| 1414 | else |
| 1415 | return color_to_raw(format, color.color); |
| 1416 | } |
| 1417 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1418 | void test_clear_color_image(const XGL_IMAGE_CREATE_INFO &img_info, |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1419 | const Color &color, |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1420 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1421 | { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1422 | xgl_testing::Image img; |
| 1423 | img.init(dev_, img_info); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1424 | add_memory_ref(img, 0); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1425 | const XGL_FLAGS all_cache_outputs = |
| 1426 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1427 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1428 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1429 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1430 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1431 | const XGL_FLAGS all_cache_inputs = |
| 1432 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1433 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1434 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1435 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1436 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1437 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1438 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1439 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1440 | XGL_MEMORY_INPUT_COPY_BIT; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1441 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1442 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear; |
| 1443 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1444 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1445 | for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin(); |
| 1446 | it != ranges.end(); it++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1447 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1448 | XGL_IMAGE_LAYOUT_GENERAL, |
| 1449 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1450 | *it)); |
| 1451 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1452 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1453 | XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it)); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1454 | } |
| 1455 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1456 | cmd_.begin(); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1457 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1458 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1459 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1460 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1461 | pipeline_barrier.eventCount = 1; |
| 1462 | pipeline_barrier.pEvents = set_events; |
| 1463 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1464 | pipeline_barrier.memBarrierCount = to_clear.size(); |
| 1465 | pipeline_barrier.pMemBarriers = &to_clear[0]; |
| 1466 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1467 | |
| 1468 | if (test_raw_) { |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1469 | xglCmdClearColorImageRaw(cmd_.obj(), img.obj(), color.raw, ranges.size(), &ranges[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1470 | } else { |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1471 | xglCmdClearColorImage(cmd_.obj(), img.obj(), color.color, ranges.size(), &ranges[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1475 | pipeline_barrier.eventCount = 1; |
| 1476 | pipeline_barrier.pEvents = set_events; |
| 1477 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1478 | pipeline_barrier.memBarrierCount = to_xfer.size(); |
| 1479 | pipeline_barrier.pMemBarriers = &to_xfer[0]; |
| 1480 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1481 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1482 | cmd_.end(); |
| 1483 | |
| 1484 | submit_and_done(); |
| 1485 | |
| 1486 | // cannot verify |
| 1487 | if (!img.transparent() && !img.copyable()) |
| 1488 | return; |
| 1489 | |
| 1490 | xgl_testing::ImageChecker checker(img_info, ranges); |
| 1491 | |
| 1492 | const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, color); |
| 1493 | if (solid_pattern.empty()) |
| 1494 | return; |
| 1495 | |
| 1496 | checker.set_solid_pattern(solid_pattern); |
| 1497 | check_dst(img, checker); |
| 1498 | } |
Chia-I Wu | 5bc2786 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1499 | |
| 1500 | void test_clear_color_image(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1501 | const XGL_FLOAT color[4], |
| 1502 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1503 | { |
| 1504 | Color c; |
| 1505 | memcpy(c.color, color, sizeof(c.color)); |
| 1506 | test_clear_color_image(img_info, c, ranges); |
| 1507 | } |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | TEST_F(XglCmdClearColorImageTest, Basic) |
| 1511 | { |
| 1512 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1513 | it != test_formats_.end(); it++) { |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1514 | const XGL_FLOAT color[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; |
| 1515 | |
| 1516 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1517 | img_info.imageType = XGL_IMAGE_2D; |
| 1518 | img_info.format = it->format; |
| 1519 | img_info.extent.width = 64; |
| 1520 | img_info.extent.height = 64; |
| 1521 | img_info.tiling = it->tiling; |
| 1522 | |
| 1523 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1524 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1525 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1526 | |
| 1527 | test_clear_color_image(img_info, color, ranges); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | |
Chia-I Wu | d642238 | 2014-12-22 13:44:24 +0800 | [diff] [blame] | 1531 | class XglCmdClearColorImageRawTest : public XglCmdClearColorImageTest { |
| 1532 | protected: |
| 1533 | XglCmdClearColorImageRawTest() : XglCmdClearColorImageTest(true) {} |
| 1534 | |
| 1535 | void test_clear_color_image_raw(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1536 | const XGL_UINT32 color[4], |
| 1537 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1538 | { |
| 1539 | Color c; |
| 1540 | memcpy(c.raw, color, sizeof(c.raw)); |
| 1541 | test_clear_color_image(img_info, c, ranges); |
| 1542 | } |
| 1543 | }; |
| 1544 | |
| 1545 | TEST_F(XglCmdClearColorImageRawTest, Basic) |
| 1546 | { |
| 1547 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1548 | it != test_formats_.end(); it++) { |
| 1549 | const XGL_UINT32 color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 }; |
| 1550 | |
| 1551 | // not sure what to do here |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1552 | if (it->format == XGL_FMT_UNDEFINED || |
| 1553 | (it->format >= XGL_FMT_R8G8B8_UNORM && |
| 1554 | it->format <= XGL_FMT_R8G8B8_SRGB) || |
| 1555 | (it->format >= XGL_FMT_B8G8R8_UNORM && |
| 1556 | it->format <= XGL_FMT_B8G8R8_SRGB) || |
| 1557 | (it->format >= XGL_FMT_R16G16B16_UNORM && |
| 1558 | it->format <= XGL_FMT_R16G16B16_SFLOAT) || |
| 1559 | (it->format >= XGL_FMT_R32G32B32_UINT && |
| 1560 | it->format <= XGL_FMT_R32G32B32_SFLOAT) || |
| 1561 | it->format == XGL_FMT_R64G64B64_SFLOAT || |
| 1562 | it->format == XGL_FMT_R64G64B64A64_SFLOAT || |
| 1563 | (it->format >= XGL_FMT_D16_UNORM && |
| 1564 | it->format <= XGL_FMT_D32_SFLOAT_S8_UINT)) |
Chia-I Wu | d642238 | 2014-12-22 13:44:24 +0800 | [diff] [blame] | 1565 | continue; |
| 1566 | |
| 1567 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1568 | img_info.imageType = XGL_IMAGE_2D; |
| 1569 | img_info.format = it->format; |
| 1570 | img_info.extent.width = 64; |
| 1571 | img_info.extent.height = 64; |
| 1572 | img_info.tiling = it->tiling; |
| 1573 | |
| 1574 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1575 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | d642238 | 2014-12-22 13:44:24 +0800 | [diff] [blame] | 1576 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1577 | |
| 1578 | test_clear_color_image_raw(img_info, color, ranges); |
| 1579 | } |
| 1580 | } |
| 1581 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1582 | class XglCmdClearDepthStencilTest : public XglCmdBlitImageTest { |
| 1583 | protected: |
| 1584 | virtual void SetUp() |
| 1585 | { |
| 1586 | XglCmdBlitTest::SetUp(); |
| 1587 | init_test_formats(XGL_FORMAT_DEPTH_ATTACHMENT_BIT | |
| 1588 | XGL_FORMAT_STENCIL_ATTACHMENT_BIT); |
| 1589 | ASSERT_NE(true, test_formats_.empty()); |
| 1590 | } |
| 1591 | |
| 1592 | std::vector<uint8_t> ds_to_raw(XGL_FORMAT format, XGL_FLOAT depth, XGL_UINT32 stencil) |
| 1593 | { |
| 1594 | std::vector<uint8_t> raw; |
| 1595 | |
| 1596 | // depth |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1597 | switch (format) { |
| 1598 | case XGL_FMT_D16_UNORM: |
| 1599 | case XGL_FMT_D16_UNORM_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1600 | { |
| 1601 | const uint16_t unorm = depth * 65535.0f; |
| 1602 | raw.push_back(unorm & 0xff); |
| 1603 | raw.push_back(unorm >> 8); |
| 1604 | } |
| 1605 | break; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1606 | case XGL_FMT_D32_SFLOAT: |
| 1607 | case XGL_FMT_D32_SFLOAT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1608 | { |
| 1609 | const union { |
| 1610 | XGL_FLOAT depth; |
| 1611 | uint32_t u32; |
| 1612 | } u = { depth }; |
| 1613 | |
| 1614 | raw.push_back((u.u32 ) & 0xff); |
| 1615 | raw.push_back((u.u32 >> 8) & 0xff); |
| 1616 | raw.push_back((u.u32 >> 16) & 0xff); |
| 1617 | raw.push_back((u.u32 >> 24) & 0xff); |
| 1618 | } |
| 1619 | break; |
| 1620 | default: |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | // stencil |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1625 | switch (format) { |
| 1626 | case XGL_FMT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1627 | raw.push_back(stencil); |
| 1628 | break; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1629 | case XGL_FMT_D16_UNORM_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1630 | raw.push_back(stencil); |
| 1631 | raw.push_back(0); |
| 1632 | break; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1633 | case XGL_FMT_D32_SFLOAT_S8_UINT: |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1634 | raw.push_back(stencil); |
| 1635 | raw.push_back(0); |
| 1636 | raw.push_back(0); |
| 1637 | raw.push_back(0); |
| 1638 | break; |
| 1639 | default: |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | return raw; |
| 1644 | } |
| 1645 | |
| 1646 | void test_clear_depth_stencil(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1647 | XGL_FLOAT depth, XGL_UINT32 stencil, |
| 1648 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1649 | { |
| 1650 | xgl_testing::Image img; |
| 1651 | img.init(dev_, img_info); |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1652 | add_memory_ref(img, 0); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1653 | const XGL_FLAGS all_cache_outputs = |
| 1654 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1655 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1656 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1657 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1658 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1659 | const XGL_FLAGS all_cache_inputs = |
| 1660 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1661 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1662 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1663 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1664 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1665 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1666 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1667 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1668 | XGL_MEMORY_INPUT_COPY_BIT; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1669 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1670 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear; |
| 1671 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer; |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1672 | |
| 1673 | for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin(); |
| 1674 | it != ranges.end(); it++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1675 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1676 | XGL_IMAGE_LAYOUT_GENERAL, |
| 1677 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1678 | *it)); |
| 1679 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1680 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1681 | XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it)); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | cmd_.begin(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1685 | |
| 1686 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1687 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1688 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1689 | pipeline_barrier.eventCount = 1; |
| 1690 | pipeline_barrier.pEvents = set_events; |
| 1691 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1692 | pipeline_barrier.memBarrierCount = to_clear.size(); |
| 1693 | pipeline_barrier.pMemBarriers = &to_clear[0]; |
| 1694 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1695 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1696 | xglCmdClearDepthStencil(cmd_.obj(), img.obj(), depth, stencil, ranges.size(), &ranges[0]); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1697 | |
| 1698 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1699 | pipeline_barrier.eventCount = 1; |
| 1700 | pipeline_barrier.pEvents = set_events; |
| 1701 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1702 | pipeline_barrier.memBarrierCount = to_xfer.size(); |
| 1703 | pipeline_barrier.pMemBarriers = &to_xfer[0]; |
| 1704 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1705 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1706 | cmd_.end(); |
| 1707 | |
| 1708 | submit_and_done(); |
| 1709 | |
| 1710 | // cannot verify |
| 1711 | if (!img.transparent() && !img.copyable()) |
| 1712 | return; |
| 1713 | |
| 1714 | xgl_testing::ImageChecker checker(img_info, ranges); |
| 1715 | |
| 1716 | checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil)); |
| 1717 | check_dst(img, checker); |
| 1718 | } |
| 1719 | }; |
| 1720 | |
| 1721 | TEST_F(XglCmdClearDepthStencilTest, Basic) |
| 1722 | { |
| 1723 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1724 | it != test_formats_.end(); it++) { |
| 1725 | // known driver issues |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame^] | 1726 | if (it->format == XGL_FMT_S8_UINT || |
| 1727 | it->format == XGL_FMT_D24_UNORM || |
| 1728 | it->format == XGL_FMT_D16_UNORM_S8_UINT || |
| 1729 | it->format == XGL_FMT_D24_UNORM_S8_UINT) |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1730 | continue; |
| 1731 | |
| 1732 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1733 | img_info.imageType = XGL_IMAGE_2D; |
| 1734 | img_info.format = it->format; |
| 1735 | img_info.extent.width = 64; |
| 1736 | img_info.extent.height = 64; |
| 1737 | img_info.tiling = it->tiling; |
| 1738 | img_info.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
| 1739 | |
| 1740 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1741 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_DEPTH); |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1742 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1743 | |
| 1744 | test_clear_depth_stencil(img_info, 0.25f, 63, ranges); |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | }; // namespace |
| 1749 | |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1750 | int main(int argc, char **argv) |
| 1751 | { |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1752 | ::testing::InitGoogleTest(&argc, argv); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1753 | |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1754 | xgl_testing::set_error_callback(test_error_callback); |
| 1755 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1756 | environment = new xgl_testing::Environment(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1757 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1758 | if (!environment->parse_args(argc, argv)) |
| 1759 | return -1; |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1760 | |
Chia-I Wu | 998c2ac | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1761 | ::testing::AddGlobalTestEnvironment(environment); |
| 1762 | |
| 1763 | return RUN_ALL_TESTS(); |
Chia-I Wu | d7414b0 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1764 | } |