Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1 | // XGL tests |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 2 | // |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 3 | // Copyright (C) 2014 LunarG, Inc. |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 4 | // |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 11 | // |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 14 | // |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 22 | |
| 23 | // Blit (copy, clear, and resolve) tests |
| 24 | |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 25 | #include "test_common.h" |
| 26 | #include "xgltestbinding.h" |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 27 | |
| 28 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 29 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 30 | namespace xgl_testing { |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 31 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 32 | XGL_SIZE get_format_size(XGL_FORMAT format); |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 39 | |
| 40 | virtual void SetUp(); |
| 41 | virtual void TearDown(); |
| 42 | |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 45 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 46 | private: |
| 47 | XGL_APPLICATION_INFO app_; |
| 48 | int default_dev_; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 50 | std::vector<Device *> devs_; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 51 | }; |
| 52 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 53 | class ImageChecker { |
| 54 | public: |
Chia-I Wu | 714df45 | 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 | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 68 | const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions() const { return regions_; } |
Chia-I Wu | 6170c9e | 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 | 714df45 | 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 | 6170c9e | 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 | 714df45 | 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 | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 95 | std::vector<XGL_BUFFER_IMAGE_COPY> regions_; |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 103 | { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 104 | app_.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 105 | app_.pAppName = "xgl_testing"; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 106 | app_.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 107 | app_.pEngineName = "xgl_testing"; |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 144 | XGL_UINT count; |
| 145 | XGL_RESULT err; |
| 146 | |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 150 | |
Chia-I Wu | 6170c9e | 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 | 9dac52d | 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 | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 157 | } |
| 158 | } |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 159 | } |
| 160 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 161 | void Environment::TearDown() |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 162 | { |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 167 | |
Chia-I Wu | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 170 | } |
| 171 | |
Chia-I Wu | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 180 | XGL_BUFFER_IMAGE_COPY region = {}; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 181 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 182 | region.bufferOffset = offset; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 183 | region.imageSubresource.mipLevel = lv; |
| 184 | region.imageSubresource.arraySlice = 0; |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 185 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 186 | |
| 187 | if (info_.usage & XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT) { |
| 188 | if (info_.format.channelFormat != XGL_CH_FMT_R8) { |
| 189 | region.imageSubresource.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 190 | regions_.push_back(region); |
| 191 | } |
| 192 | |
| 193 | if (info_.format.channelFormat == XGL_CH_FMT_R16G8 || |
| 194 | info_.format.channelFormat == XGL_CH_FMT_R32G8 || |
| 195 | info_.format.channelFormat == XGL_CH_FMT_R8) { |
| 196 | region.imageSubresource.aspect = XGL_IMAGE_ASPECT_STENCIL; |
| 197 | regions_.push_back(region); |
| 198 | } |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 199 | } else { |
Chia-I Wu | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 217 | XGL_BUFFER_IMAGE_COPY region = regions_[i]; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 218 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 219 | region.bufferOffset += slice_pitch * slice; |
Chia-I Wu | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 235 | XGL_BUFFER_IMAGE_COPY region = {}; |
| 236 | region.bufferOffset = offset; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 237 | region.imageSubresource = Image::subresource(*it, lv, slice); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 238 | region.imageExtent = Image::extent(info_.extent, lv); |
Chia-I Wu | 6170c9e | 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 | 4dce6af | 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 | 6170c9e | 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 | 714df45 | 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 | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 263 | { |
| 264 | XGL_SUBRESOURCE_LAYOUT layout = {}; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 265 | layout.offset = region.bufferOffset; |
Chia-I Wu | 6170c9e | 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 | 714df45 | 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 | 6170c9e | 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 | 714df45 | 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 | 6170c9e | 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 | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 321 | return true; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 324 | bool ImageChecker::walk(Action action, Buffer &buf) const |
Chia-I Wu | 3c3fd12 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 325 | { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 326 | void *data = buf.map(); |
| 327 | if (!data) |
| 328 | return false; |
Chia-I Wu | 3c3fd12 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 329 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 330 | std::vector<XGL_BUFFER_IMAGE_COPY>::const_iterator it; |
Chia-I Wu | 6170c9e | 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 | 3c3fd12 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 334 | } |
| 335 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 336 | buf.unmap(); |
Chia-I Wu | 3c3fd12 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 337 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 338 | return (it == regions_.end()); |
Chia-I Wu | 3c3fd12 | 2014-11-22 02:51:25 +0800 | [diff] [blame] | 339 | } |
| 340 | |
Chia-I Wu | 6170c9e | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 347 | std::vector<XGL_BUFFER_IMAGE_COPY>::const_iterator it; |
Chia-I Wu | 6170c9e | 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 | 4dce6af | 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 | 6170c9e | 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; |
| 392 | } format_table[XGL_MAX_CH_FMT + 1] = { |
| 393 | [XGL_CH_FMT_UNDEFINED] = { 0, 0 }, |
| 394 | [XGL_CH_FMT_R4G4] = { 1, 2 }, |
| 395 | [XGL_CH_FMT_R4G4B4A4] = { 2, 4 }, |
| 396 | [XGL_CH_FMT_R5G6B5] = { 2, 3 }, |
| 397 | [XGL_CH_FMT_B5G6R5] = { 2, 3 }, |
| 398 | [XGL_CH_FMT_R5G5B5A1] = { 2, 4 }, |
| 399 | [XGL_CH_FMT_R8] = { 1, 1 }, |
| 400 | [XGL_CH_FMT_R8G8] = { 2, 2 }, |
| 401 | [XGL_CH_FMT_R8G8B8A8] = { 4, 4 }, |
| 402 | [XGL_CH_FMT_B8G8R8A8] = { 4, 4 }, |
| 403 | [XGL_CH_FMT_R10G11B11] = { 4, 3 }, |
| 404 | [XGL_CH_FMT_R11G11B10] = { 4, 3 }, |
| 405 | [XGL_CH_FMT_R10G10B10A2] = { 4, 4 }, |
| 406 | [XGL_CH_FMT_R16] = { 2, 1 }, |
| 407 | [XGL_CH_FMT_R16G16] = { 4, 2 }, |
| 408 | [XGL_CH_FMT_R16G16B16A16] = { 8, 4 }, |
| 409 | [XGL_CH_FMT_R32] = { 4, 1 }, |
| 410 | [XGL_CH_FMT_R32G32] = { 8, 2 }, |
| 411 | [XGL_CH_FMT_R32G32B32] = { 12, 3 }, |
| 412 | [XGL_CH_FMT_R32G32B32A32] = { 16, 4 }, |
| 413 | [XGL_CH_FMT_R16G8] = { 3, 2 }, |
| 414 | [XGL_CH_FMT_R32G8] = { 5, 2 }, |
| 415 | [XGL_CH_FMT_R9G9B9E5] = { 4, 3 }, |
| 416 | [XGL_CH_FMT_BC1] = { 8, 4 }, |
| 417 | [XGL_CH_FMT_BC2] = { 16, 4 }, |
| 418 | [XGL_CH_FMT_BC3] = { 16, 4 }, |
| 419 | [XGL_CH_FMT_BC4] = { 8, 4 }, |
| 420 | [XGL_CH_FMT_BC5] = { 16, 4 }, |
| 421 | [XGL_CH_FMT_BC6U] = { 16, 4 }, |
| 422 | [XGL_CH_FMT_BC6S] = { 16, 4 }, |
| 423 | [XGL_CH_FMT_BC7] = { 16, 4 }, |
| 424 | }; |
| 425 | |
| 426 | return format_table[format.channelFormat].size; |
| 427 | } |
| 428 | |
| 429 | XGL_EXTENT3D get_mip_level_extent(const XGL_EXTENT3D &extent, XGL_UINT mip_level) |
| 430 | { |
| 431 | const XGL_EXTENT3D ext = { |
| 432 | (extent.width >> mip_level) ? extent.width >> mip_level : 1, |
| 433 | (extent.height >> mip_level) ? extent.height >> mip_level : 1, |
| 434 | (extent.depth >> mip_level) ? extent.depth >> mip_level : 1, |
| 435 | }; |
| 436 | |
| 437 | return ext; |
| 438 | } |
| 439 | |
| 440 | }; // namespace xgl_testing |
| 441 | |
| 442 | namespace { |
| 443 | |
| 444 | #define DO(action) ASSERT_EQ(true, action); |
| 445 | |
| 446 | xgl_testing::Environment *environment; |
| 447 | |
| 448 | class XglCmdBlitTest : public ::testing::Test { |
| 449 | protected: |
| 450 | XglCmdBlitTest() : |
| 451 | dev_(environment->default_device()), |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 452 | queue_(*dev_.graphics_queues()[0]), |
| 453 | cmd_(dev_, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS)) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 454 | { |
| 455 | // make sure every test uses a different pattern |
| 456 | xgl_testing::ImageChecker::hash_salt_generate(); |
| 457 | } |
| 458 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 459 | bool submit_and_done() |
| 460 | { |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 461 | queue_.submit(cmd_, mem_refs_); |
| 462 | queue_.wait(); |
| 463 | mem_refs_.clear(); |
| 464 | return true; |
| 465 | } |
| 466 | |
| 467 | void add_memory_ref(const xgl_testing::Object &obj, XGL_FLAGS flags) |
| 468 | { |
| 469 | const std::vector<XGL_GPU_MEMORY> mems = obj.memories(); |
| 470 | for (std::vector<XGL_GPU_MEMORY>::const_iterator it = mems.begin(); it != mems.end(); it++) { |
| 471 | std::vector<XGL_MEMORY_REF>::iterator ref; |
| 472 | for (ref = mem_refs_.begin(); ref != mem_refs_.end(); ref++) { |
| 473 | if (ref->mem == *it) |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | if (ref == mem_refs_.end()) { |
| 478 | XGL_MEMORY_REF tmp = {}; |
| 479 | tmp.mem = *it; |
| 480 | tmp.flags = flags; |
| 481 | mem_refs_.push_back(tmp); |
| 482 | } else { |
| 483 | ref->flags &= flags; |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 488 | xgl_testing::Device &dev_; |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 489 | xgl_testing::Queue &queue_; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 490 | xgl_testing::CmdBuffer cmd_; |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 491 | |
| 492 | std::vector<XGL_MEMORY_REF> mem_refs_; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 493 | }; |
| 494 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 495 | typedef XglCmdBlitTest XglCmdFillBufferTest; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 496 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 497 | TEST_F(XglCmdFillBufferTest, Basic) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 498 | { |
| 499 | xgl_testing::Buffer buf; |
| 500 | |
| 501 | buf.init(dev_, 20); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 502 | add_memory_ref(buf, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 503 | |
| 504 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 505 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 4, 0x11111111); |
| 506 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 4, 16, 0x22222222); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 507 | cmd_.end(); |
| 508 | |
| 509 | submit_and_done(); |
| 510 | |
| 511 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 512 | EXPECT_EQ(0x11111111, data[0]); |
| 513 | EXPECT_EQ(0x22222222, data[1]); |
| 514 | EXPECT_EQ(0x22222222, data[2]); |
| 515 | EXPECT_EQ(0x22222222, data[3]); |
| 516 | EXPECT_EQ(0x22222222, data[4]); |
| 517 | buf.unmap(); |
| 518 | } |
| 519 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 520 | TEST_F(XglCmdFillBufferTest, Large) |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 521 | { |
| 522 | const XGL_GPU_SIZE size = 32 * 1024 * 1024; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 523 | xgl_testing::Buffer buf; |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 524 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 525 | buf.init(dev_, size); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 526 | add_memory_ref(buf, 0); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 527 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 528 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 529 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, size / 2, 0x11111111); |
| 530 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), size / 2, size / 2, 0x22222222); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 531 | cmd_.end(); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 532 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 533 | submit_and_done(); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 534 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 535 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 536 | XGL_GPU_SIZE offset; |
| 537 | for (offset = 0; offset < size / 2; offset += 4) |
| 538 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 539 | for (; offset < size; offset += 4) |
| 540 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
| 541 | buf.unmap(); |
| 542 | } |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 543 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 544 | TEST_F(XglCmdFillBufferTest, Overlap) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 545 | { |
| 546 | xgl_testing::Buffer buf; |
| 547 | |
| 548 | buf.init(dev_, 64); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 549 | add_memory_ref(buf, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 550 | |
| 551 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 552 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 0, 48, 0x11111111); |
| 553 | xglCmdFillBuffer(cmd_.obj(), buf.obj(), 32, 32, 0x22222222); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 554 | cmd_.end(); |
| 555 | |
| 556 | submit_and_done(); |
| 557 | |
| 558 | const uint32_t *data = static_cast<const uint32_t *>(buf.map()); |
| 559 | XGL_GPU_SIZE offset; |
| 560 | for (offset = 0; offset < 32; offset += 4) |
| 561 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Offset is: " << offset; |
| 562 | for (; offset < 64; offset += 4) |
| 563 | EXPECT_EQ(0x22222222, data[offset / 4]) << "Offset is: " << offset; |
| 564 | buf.unmap(); |
| 565 | } |
| 566 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 567 | TEST_F(XglCmdFillBufferTest, MultiAlignments) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 568 | { |
| 569 | xgl_testing::Buffer bufs[9]; |
| 570 | XGL_GPU_SIZE size = 4; |
| 571 | |
| 572 | cmd_.begin(); |
| 573 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 574 | bufs[i].init(dev_, size); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 575 | add_memory_ref(bufs[i], 0); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 576 | xglCmdFillBuffer(cmd_.obj(), bufs[i].obj(), 0, size, 0x11111111); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 577 | size <<= 1; |
| 578 | } |
| 579 | cmd_.end(); |
| 580 | |
| 581 | submit_and_done(); |
| 582 | |
| 583 | size = 4; |
| 584 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 585 | const uint32_t *data = static_cast<const uint32_t *>(bufs[i].map()); |
| 586 | XGL_GPU_SIZE offset; |
| 587 | for (offset = 0; offset < size; offset += 4) |
| 588 | EXPECT_EQ(0x11111111, data[offset / 4]) << "Buffser is: " << i << "\n" << |
| 589 | "Offset is: " << offset; |
| 590 | bufs[i].unmap(); |
| 591 | |
| 592 | size <<= 1; |
| 593 | } |
| 594 | } |
| 595 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 596 | typedef XglCmdBlitTest XglCmdCopyBufferTest; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 597 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 598 | TEST_F(XglCmdCopyBufferTest, Basic) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 599 | { |
| 600 | xgl_testing::Buffer src, dst; |
| 601 | |
| 602 | src.init(dev_, 4); |
| 603 | uint32_t *data = static_cast<uint32_t *>(src.map()); |
| 604 | data[0] = 0x11111111; |
| 605 | src.unmap(); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 606 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 607 | |
| 608 | dst.init(dev_, 4); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 609 | add_memory_ref(dst, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 610 | |
| 611 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 612 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 613 | region.copySize = 4; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 614 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, ®ion); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 615 | cmd_.end(); |
| 616 | |
| 617 | submit_and_done(); |
| 618 | |
| 619 | data = static_cast<uint32_t *>(dst.map()); |
| 620 | EXPECT_EQ(0x11111111, data[0]); |
| 621 | dst.unmap(); |
| 622 | } |
| 623 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 624 | TEST_F(XglCmdCopyBufferTest, Large) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 625 | { |
| 626 | const XGL_GPU_SIZE size = 32 * 1024 * 1024; |
| 627 | xgl_testing::Buffer src, dst; |
| 628 | |
| 629 | src.init(dev_, size); |
| 630 | uint32_t *data = static_cast<uint32_t *>(src.map()); |
| 631 | XGL_GPU_SIZE offset; |
| 632 | for (offset = 0; offset < size; offset += 4) |
| 633 | data[offset / 4] = offset; |
| 634 | src.unmap(); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 635 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 636 | |
| 637 | dst.init(dev_, size); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 638 | add_memory_ref(dst, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 639 | |
| 640 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 641 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 642 | region.copySize = size; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 643 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), 1, ®ion); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 644 | cmd_.end(); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 645 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 646 | submit_and_done(); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 647 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 648 | data = static_cast<uint32_t *>(dst.map()); |
| 649 | for (offset = 0; offset < size; offset += 4) |
| 650 | EXPECT_EQ(offset, data[offset / 4]); |
| 651 | dst.unmap(); |
Chia-I Wu | ea9367f | 2014-11-23 02:16:45 +0800 | [diff] [blame] | 652 | } |
| 653 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 654 | TEST_F(XglCmdCopyBufferTest, MultiAlignments) |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 655 | { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 656 | const XGL_BUFFER_COPY regions[] = { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 657 | /* well aligned */ |
| 658 | { 0, 0, 256 }, |
| 659 | { 0, 256, 128 }, |
| 660 | { 0, 384, 64 }, |
| 661 | { 0, 448, 32 }, |
| 662 | { 0, 480, 16 }, |
| 663 | { 0, 496, 8 }, |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 664 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 665 | /* ill aligned */ |
| 666 | { 7, 510, 16 }, |
| 667 | { 16, 530, 13 }, |
| 668 | { 32, 551, 16 }, |
| 669 | { 45, 570, 15 }, |
| 670 | { 50, 590, 1 }, |
| 671 | }; |
| 672 | xgl_testing::Buffer src, dst; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 673 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 674 | src.init(dev_, 256); |
| 675 | uint8_t *data = static_cast<uint8_t *>(src.map()); |
| 676 | for (int i = 0; i < 256; i++) |
| 677 | data[i] = i; |
| 678 | src.unmap(); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 679 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 680 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 681 | dst.init(dev_, 1024); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 682 | add_memory_ref(dst, 0); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 683 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 684 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 685 | xglCmdCopyBuffer(cmd_.obj(), src.obj(), dst.obj(), ARRAY_SIZE(regions), regions); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 686 | cmd_.end(); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 687 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 688 | submit_and_done(); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 689 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 690 | data = static_cast<uint8_t *>(dst.map()); |
| 691 | for (int i = 0; i < ARRAY_SIZE(regions); i++) { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 692 | const XGL_BUFFER_COPY &r = regions[i]; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 693 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 694 | for (int j = 0; j < r.copySize; j++) { |
| 695 | EXPECT_EQ(r.srcOffset + j, data[r.destOffset + j]) << |
| 696 | "Region is: " << i << "\n" << |
| 697 | "Offset is: " << r.destOffset + j; |
| 698 | } |
| 699 | } |
| 700 | dst.unmap(); |
| 701 | } |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 702 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 703 | TEST_F(XglCmdCopyBufferTest, RAWHazard) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 704 | { |
| 705 | xgl_testing::Buffer bufs[3]; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 706 | XGL_EVENT_CREATE_INFO event_info; |
| 707 | XGL_EVENT event; |
| 708 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 709 | size_t data_size = sizeof(mem_req); |
| 710 | XGL_RESULT err; |
| 711 | |
| 712 | // typedef struct _XGL_EVENT_CREATE_INFO |
| 713 | // { |
| 714 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO |
| 715 | // const XGL_VOID* pNext; // Pointer to next structure |
| 716 | // XGL_FLAGS flags; // Reserved |
| 717 | // } XGL_EVENT_CREATE_INFO; |
| 718 | memset(&event_info, 0, sizeof(event_info)); |
| 719 | event_info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 720 | |
| 721 | err = xglCreateEvent(dev_.obj(), &event_info, &event); |
| 722 | ASSERT_XGL_SUCCESS(err); |
| 723 | |
| 724 | err = xglGetObjectInfo(event, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 725 | &data_size, &mem_req); |
| 726 | ASSERT_XGL_SUCCESS(err); |
| 727 | |
| 728 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 729 | // XGL_DEVICE device, |
| 730 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 731 | // XGL_GPU_MEMORY* pMem); |
| 732 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 733 | XGL_GPU_MEMORY event_mem; |
| 734 | |
| 735 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect events to require memory"; |
| 736 | |
| 737 | XGL_UINT heapInfo[mem_req.heapCount]; |
| 738 | memset(&mem_info, 0, sizeof(mem_info)); |
| 739 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 740 | mem_info.allocationSize = mem_req.size; |
| 741 | mem_info.alignment = mem_req.alignment; |
| 742 | mem_info.heapCount = mem_req.heapCount; |
| 743 | mem_info.pHeaps = heapInfo; |
| 744 | memcpy(heapInfo, mem_req.pHeaps, sizeof(XGL_UINT)*mem_info.heapCount); |
| 745 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 746 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 747 | err = xglAllocMemory(dev_.obj(), &mem_info, &event_mem); |
| 748 | ASSERT_XGL_SUCCESS(err); |
| 749 | |
| 750 | err = xglBindObjectMemory(event, event_mem, 0); |
| 751 | ASSERT_XGL_SUCCESS(err); |
| 752 | |
| 753 | err = xglResetEvent(event); |
| 754 | ASSERT_XGL_SUCCESS(err); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 755 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 756 | for (int i = 0; i < ARRAY_SIZE(bufs); i++) { |
| 757 | bufs[i].init(dev_, 4); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 758 | add_memory_ref(bufs[i], 0); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 759 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 760 | uint32_t *data = static_cast<uint32_t *>(bufs[i].map()); |
| 761 | data[0] = 0x22222222 * (i + 1); |
| 762 | bufs[i].unmap(); |
| 763 | } |
| 764 | |
| 765 | cmd_.begin(); |
| 766 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 767 | xglCmdFillBuffer(cmd_.obj(), bufs[0].obj(), 0, 4, 0x11111111); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 768 | // is this necessary? |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 769 | XGL_BUFFER_MEMORY_BARRIER memory_barrier = bufs[0].buffer_memory_barrier( |
| 770 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4); |
| 771 | |
| 772 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_TRANSFER_COMPLETE }; |
| 773 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 774 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 775 | pipeline_barrier.eventCount = 1; |
| 776 | pipeline_barrier.pEvents = set_events; |
| 777 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 778 | pipeline_barrier.memBarrierCount = 1; |
| 779 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 780 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 781 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 782 | XGL_BUFFER_COPY region = {}; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 783 | region.copySize = 4; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 784 | xglCmdCopyBuffer(cmd_.obj(), bufs[0].obj(), bufs[1].obj(), 1, ®ion); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 785 | |
| 786 | memory_barrier = bufs[1].buffer_memory_barrier( |
| 787 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4); |
| 788 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 789 | pipeline_barrier.eventCount = 1; |
| 790 | pipeline_barrier.pEvents = set_events; |
| 791 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 792 | pipeline_barrier.memBarrierCount = 1; |
| 793 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 794 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 795 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 796 | xglCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, ®ion); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 797 | |
| 798 | /* Use xglCmdSetEvent and xglCmdWaitEvents to test them. |
| 799 | * This could be xglCmdPipelineBarrier. |
| 800 | */ |
| 801 | xglCmdSetEvent(cmd_.obj(), event, XGL_SET_EVENT_TRANSFER_COMPLETE); |
| 802 | |
| 803 | // Additional commands could go into the buffer here before the wait. |
| 804 | |
| 805 | memory_barrier = bufs[1].buffer_memory_barrier( |
| 806 | XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_CPU_READ_BIT, 0, 4); |
| 807 | XGL_EVENT_WAIT_INFO wait_info = {}; |
| 808 | wait_info.sType = XGL_STRUCTURE_TYPE_EVENT_WAIT_INFO; |
| 809 | wait_info.eventCount = 1; |
| 810 | wait_info.pEvents = &event; |
| 811 | wait_info.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 812 | wait_info.memBarrierCount = 1; |
| 813 | wait_info.pMemBarriers = &memory_barrier; |
| 814 | xglCmdWaitEvents(cmd_.obj(), &wait_info); |
| 815 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 816 | cmd_.end(); |
| 817 | |
| 818 | submit_and_done(); |
| 819 | |
| 820 | const uint32_t *data = static_cast<const uint32_t *>(bufs[2].map()); |
| 821 | EXPECT_EQ(0x11111111, data[0]); |
| 822 | bufs[2].unmap(); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 823 | |
| 824 | // All done with event memory, clean up |
| 825 | err = xglBindObjectMemory(event, XGL_NULL_HANDLE, 0); |
| 826 | ASSERT_XGL_SUCCESS(err); |
| 827 | |
| 828 | err = xglDestroyObject(event); |
| 829 | ASSERT_XGL_SUCCESS(err); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | class XglCmdBlitImageTest : public XglCmdBlitTest { |
| 833 | protected: |
| 834 | void init_test_formats(XGL_FLAGS features) |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 835 | { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 836 | first_linear_format_.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 837 | first_linear_format_.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 838 | first_optimal_format_.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 839 | first_optimal_format_.numericFormat = XGL_NUM_FMT_UNDEFINED; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 840 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 841 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = dev_.formats().begin(); |
| 842 | it != dev_.formats().end(); it++) { |
| 843 | if (it->features & features) { |
| 844 | test_formats_.push_back(*it); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 845 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 846 | if (it->tiling == XGL_LINEAR_TILING && |
| 847 | first_linear_format_.channelFormat == XGL_CH_FMT_UNDEFINED) |
| 848 | first_linear_format_ = it->format; |
| 849 | if (it->tiling == XGL_OPTIMAL_TILING && |
| 850 | first_optimal_format_.channelFormat == XGL_CH_FMT_UNDEFINED) |
| 851 | first_optimal_format_ = it->format; |
| 852 | } |
| 853 | } |
| 854 | } |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 855 | |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 856 | void init_test_formats() |
| 857 | { |
| 858 | init_test_formats(static_cast<XGL_FLAGS>(-1)); |
| 859 | } |
| 860 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 861 | void fill_src(xgl_testing::Image &img, const xgl_testing::ImageChecker &checker) |
| 862 | { |
| 863 | if (img.transparent()) { |
| 864 | checker.fill(img); |
| 865 | return; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 866 | } |
| 867 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 868 | ASSERT_EQ(true, img.copyable()); |
| 869 | |
| 870 | xgl_testing::Buffer in_buf; |
| 871 | in_buf.init(dev_, checker.buffer_size()); |
| 872 | checker.fill(in_buf); |
| 873 | |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 874 | add_memory_ref(in_buf, XGL_MEMORY_REF_READ_ONLY_BIT); |
| 875 | add_memory_ref(img, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 876 | |
| 877 | // copy in and tile |
| 878 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 879 | xglCmdCopyBufferToImage(cmd_.obj(), in_buf.obj(), img.obj(), |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 880 | checker.regions().size(), &checker.regions()[0]); |
| 881 | cmd_.end(); |
| 882 | |
| 883 | submit_and_done(); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 884 | } |
| 885 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 886 | void check_dst(xgl_testing::Image &img, const xgl_testing::ImageChecker &checker) |
Chia-I Wu | 8682263 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 887 | { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 888 | if (img.transparent()) { |
| 889 | DO(checker.check(img)); |
| 890 | return; |
Chia-I Wu | 8682263 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 891 | } |
| 892 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 893 | ASSERT_EQ(true, img.copyable()); |
| 894 | |
| 895 | xgl_testing::Buffer out_buf; |
| 896 | out_buf.init(dev_, checker.buffer_size()); |
| 897 | |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 898 | add_memory_ref(img, XGL_MEMORY_REF_READ_ONLY_BIT); |
| 899 | add_memory_ref(out_buf, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 900 | |
| 901 | // copy out and linearize |
| 902 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 903 | xglCmdCopyImageToBuffer(cmd_.obj(), img.obj(), out_buf.obj(), |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 904 | checker.regions().size(), &checker.regions()[0]); |
| 905 | cmd_.end(); |
| 906 | |
| 907 | submit_and_done(); |
| 908 | |
| 909 | DO(checker.check(out_buf)); |
Chia-I Wu | 8682263 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 910 | } |
| 911 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 912 | std::vector<xgl_testing::Device::Format> test_formats_; |
| 913 | XGL_FORMAT first_linear_format_; |
| 914 | XGL_FORMAT first_optimal_format_; |
| 915 | }; |
| 916 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 917 | class XglCmdCopyBufferToImageTest : public XglCmdBlitImageTest { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 918 | protected: |
| 919 | virtual void SetUp() |
| 920 | { |
| 921 | XglCmdBlitTest::SetUp(); |
| 922 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 923 | ASSERT_NE(true, test_formats_.empty()); |
| 924 | } |
| 925 | |
| 926 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info, const xgl_testing::ImageChecker &checker) |
| 927 | { |
| 928 | xgl_testing::Buffer buf; |
| 929 | xgl_testing::Image img; |
| 930 | |
| 931 | buf.init(dev_, checker.buffer_size()); |
| 932 | checker.fill(buf); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 933 | add_memory_ref(buf, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 934 | |
| 935 | img.init(dev_, img_info); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 936 | add_memory_ref(img, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 937 | |
| 938 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 939 | xglCmdCopyBufferToImage(cmd_.obj(), buf.obj(), img.obj(), |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 940 | checker.regions().size(), &checker.regions()[0]); |
| 941 | cmd_.end(); |
| 942 | |
| 943 | submit_and_done(); |
| 944 | |
| 945 | check_dst(img, checker); |
| 946 | } |
| 947 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 948 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info, const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 949 | { |
| 950 | xgl_testing::ImageChecker checker(img_info, regions); |
| 951 | test_copy_memory_to_image(img_info, checker); |
| 952 | } |
| 953 | |
| 954 | void test_copy_memory_to_image(const XGL_IMAGE_CREATE_INFO &img_info) |
| 955 | { |
| 956 | xgl_testing::ImageChecker checker(img_info); |
| 957 | test_copy_memory_to_image(img_info, checker); |
| 958 | } |
| 959 | }; |
| 960 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 961 | TEST_F(XglCmdCopyBufferToImageTest, Basic) |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 962 | { |
| 963 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 964 | it != test_formats_.end(); it++) { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 965 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 966 | img_info.imageType = XGL_IMAGE_2D; |
| 967 | img_info.format = it->format; |
| 968 | img_info.extent.width = 64; |
| 969 | img_info.extent.height = 64; |
| 970 | img_info.tiling = it->tiling; |
| 971 | |
| 972 | test_copy_memory_to_image(img_info); |
| 973 | } |
Chia-I Wu | 8682263 | 2014-11-22 15:09:42 +0800 | [diff] [blame] | 974 | } |
| 975 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 976 | class XglCmdCopyImageToBufferTest : public XglCmdBlitImageTest { |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 977 | protected: |
| 978 | virtual void SetUp() |
| 979 | { |
| 980 | XglCmdBlitTest::SetUp(); |
| 981 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 982 | ASSERT_NE(true, test_formats_.empty()); |
| 983 | } |
| 984 | |
| 985 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info, const xgl_testing::ImageChecker &checker) |
| 986 | { |
| 987 | xgl_testing::Image img; |
| 988 | xgl_testing::Buffer buf; |
| 989 | |
| 990 | img.init(dev_, img_info); |
| 991 | fill_src(img, checker); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 992 | add_memory_ref(img, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 993 | |
| 994 | buf.init(dev_, checker.buffer_size()); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 995 | add_memory_ref(buf, 0); |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 996 | |
| 997 | cmd_.begin(); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 998 | xglCmdCopyImageToBuffer(cmd_.obj(), img.obj(), buf.obj(), |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 999 | checker.regions().size(), &checker.regions()[0]); |
| 1000 | cmd_.end(); |
| 1001 | |
| 1002 | submit_and_done(); |
| 1003 | |
| 1004 | checker.check(buf); |
| 1005 | } |
| 1006 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1007 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info, const std::vector<XGL_BUFFER_IMAGE_COPY> ®ions) |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1008 | { |
| 1009 | xgl_testing::ImageChecker checker(img_info, regions); |
| 1010 | test_copy_image_to_memory(img_info, checker); |
| 1011 | } |
| 1012 | |
| 1013 | void test_copy_image_to_memory(const XGL_IMAGE_CREATE_INFO &img_info) |
| 1014 | { |
| 1015 | xgl_testing::ImageChecker checker(img_info); |
| 1016 | test_copy_image_to_memory(img_info, checker); |
| 1017 | } |
| 1018 | }; |
| 1019 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1020 | TEST_F(XglCmdCopyImageToBufferTest, Basic) |
Chia-I Wu | 830fb33 | 2014-12-13 15:28:20 +0800 | [diff] [blame] | 1021 | { |
| 1022 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1023 | it != test_formats_.end(); it++) { |
| 1024 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1025 | img_info.imageType = XGL_IMAGE_2D; |
| 1026 | img_info.format = it->format; |
| 1027 | img_info.extent.width = 64; |
| 1028 | img_info.extent.height = 64; |
| 1029 | img_info.tiling = it->tiling; |
| 1030 | |
| 1031 | test_copy_image_to_memory(img_info); |
| 1032 | } |
| 1033 | } |
| 1034 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1035 | class XglCmdCopyImageTest : public XglCmdBlitImageTest { |
| 1036 | protected: |
| 1037 | virtual void SetUp() |
| 1038 | { |
| 1039 | XglCmdBlitTest::SetUp(); |
| 1040 | init_test_formats(XGL_FORMAT_IMAGE_COPY_BIT); |
| 1041 | ASSERT_NE(true, test_formats_.empty()); |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1042 | } |
| 1043 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1044 | void test_copy_image(const XGL_IMAGE_CREATE_INFO &src_info, const XGL_IMAGE_CREATE_INFO &dst_info, |
| 1045 | const std::vector<XGL_IMAGE_COPY> &copies) |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1046 | { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1047 | // convert XGL_IMAGE_COPY to two sets of XGL_BUFFER_IMAGE_COPY |
| 1048 | std::vector<XGL_BUFFER_IMAGE_COPY> src_regions, dst_regions; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1049 | XGL_GPU_SIZE src_offset = 0, dst_offset = 0; |
| 1050 | for (std::vector<XGL_IMAGE_COPY>::const_iterator it = copies.begin(); it != copies.end(); it++) { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1051 | XGL_BUFFER_IMAGE_COPY src_region = {}, dst_region = {}; |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1052 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1053 | src_region.bufferOffset = src_offset; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1054 | src_region.imageSubresource = it->srcSubresource; |
| 1055 | src_region.imageOffset = it->srcOffset; |
| 1056 | src_region.imageExtent = it->extent; |
| 1057 | src_regions.push_back(src_region); |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1058 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1059 | dst_region.bufferOffset = src_offset; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1060 | dst_region.imageSubresource = it->destSubresource; |
| 1061 | dst_region.imageOffset = it->destOffset; |
| 1062 | dst_region.imageExtent = it->extent; |
| 1063 | dst_regions.push_back(dst_region); |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1064 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1065 | const XGL_GPU_SIZE size = it->extent.width * it->extent.height * it->extent.depth; |
| 1066 | src_offset += xgl_testing::get_format_size(src_info.format) * size; |
| 1067 | dst_offset += xgl_testing::get_format_size(dst_info.format) * size; |
| 1068 | } |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1069 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1070 | xgl_testing::ImageChecker src_checker(src_info, src_regions); |
| 1071 | xgl_testing::ImageChecker dst_checker(dst_info, dst_regions); |
| 1072 | |
| 1073 | xgl_testing::Image src; |
| 1074 | src.init(dev_, src_info); |
| 1075 | fill_src(src, src_checker); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1076 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1077 | |
| 1078 | xgl_testing::Image dst; |
| 1079 | dst.init(dev_, dst_info); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1080 | add_memory_ref(dst, 0); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1081 | |
| 1082 | cmd_.begin(); |
| 1083 | xglCmdCopyImage(cmd_.obj(), src.obj(), dst.obj(), copies.size(), &copies[0]); |
| 1084 | cmd_.end(); |
| 1085 | |
| 1086 | submit_and_done(); |
| 1087 | |
| 1088 | check_dst(dst, dst_checker); |
| 1089 | } |
| 1090 | }; |
| 1091 | |
| 1092 | TEST_F(XglCmdCopyImageTest, Basic) |
| 1093 | { |
| 1094 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1095 | it != test_formats_.end(); it++) { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1096 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1097 | img_info.imageType = XGL_IMAGE_2D; |
| 1098 | img_info.format = it->format; |
| 1099 | img_info.extent.width = 64; |
| 1100 | img_info.extent.height = 64; |
| 1101 | img_info.tiling = it->tiling; |
| 1102 | |
| 1103 | XGL_IMAGE_COPY copy = {}; |
| 1104 | copy.srcSubresource = xgl_testing::Image::subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0); |
| 1105 | copy.destSubresource = copy.srcSubresource; |
| 1106 | copy.extent = img_info.extent; |
| 1107 | |
| 1108 | test_copy_image(img_info, img_info, std::vector<XGL_IMAGE_COPY>(©, © + 1)); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1112 | class XglCmdCloneImageDataTest : public XglCmdBlitImageTest { |
| 1113 | protected: |
| 1114 | virtual void SetUp() |
| 1115 | { |
| 1116 | XglCmdBlitTest::SetUp(); |
| 1117 | init_test_formats(); |
| 1118 | ASSERT_NE(true, test_formats_.empty()); |
| 1119 | } |
| 1120 | |
| 1121 | void test_clone_image_data(const XGL_IMAGE_CREATE_INFO &img_info) |
| 1122 | { |
| 1123 | xgl_testing::ImageChecker checker(img_info); |
| 1124 | xgl_testing::Image src, dst; |
| 1125 | |
| 1126 | src.init(dev_, img_info); |
| 1127 | if (src.transparent() || src.copyable()) |
| 1128 | fill_src(src, checker); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1129 | add_memory_ref(src, XGL_MEMORY_REF_READ_ONLY_BIT); |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1130 | |
| 1131 | dst.init(dev_, img_info); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1132 | add_memory_ref(dst, 0); |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1133 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1134 | const XGL_IMAGE_LAYOUT layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1135 | |
| 1136 | cmd_.begin(); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1137 | xglCmdCloneImageData(cmd_.obj(), src.obj(), layout, dst.obj(), layout); |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1138 | cmd_.end(); |
| 1139 | |
| 1140 | submit_and_done(); |
| 1141 | |
| 1142 | // cannot verify |
| 1143 | if (!dst.transparent() && !dst.copyable()) |
| 1144 | return; |
| 1145 | |
| 1146 | check_dst(dst, checker); |
| 1147 | } |
| 1148 | }; |
| 1149 | |
| 1150 | TEST_F(XglCmdCloneImageDataTest, Basic) |
| 1151 | { |
| 1152 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1153 | it != test_formats_.end(); it++) { |
| 1154 | // not sure what to do here |
| 1155 | if (it->format.channelFormat == XGL_CH_FMT_UNDEFINED || |
| 1156 | (it->format.channelFormat >= XGL_CH_FMT_BC1 && |
| 1157 | it->format.channelFormat <= XGL_CH_FMT_BC7) || |
| 1158 | it->format.numericFormat == XGL_NUM_FMT_DS) |
| 1159 | continue; |
| 1160 | |
| 1161 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1162 | img_info.imageType = XGL_IMAGE_2D; |
| 1163 | img_info.format = it->format; |
| 1164 | img_info.extent.width = 64; |
| 1165 | img_info.extent.height = 64; |
| 1166 | img_info.tiling = it->tiling; |
| 1167 | img_info.flags = XGL_IMAGE_CREATE_CLONEABLE_BIT; |
| 1168 | |
| 1169 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1170 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | b75939f | 2014-12-22 14:46:56 +0800 | [diff] [blame] | 1171 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1172 | |
| 1173 | test_clone_image_data(img_info); |
| 1174 | } |
| 1175 | } |
| 1176 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1177 | class XglCmdClearColorImageTest : public XglCmdBlitImageTest { |
| 1178 | protected: |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1179 | XglCmdClearColorImageTest() : test_raw_(false) {} |
| 1180 | XglCmdClearColorImageTest(bool test_raw) : test_raw_(test_raw) {} |
| 1181 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1182 | virtual void SetUp() |
| 1183 | { |
| 1184 | XglCmdBlitTest::SetUp(); |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1185 | |
| 1186 | if (test_raw_) |
| 1187 | init_test_formats(); |
| 1188 | else |
| 1189 | init_test_formats(XGL_FORMAT_CONVERSION_BIT); |
| 1190 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1191 | ASSERT_NE(true, test_formats_.empty()); |
| 1192 | } |
| 1193 | |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1194 | union Color { |
| 1195 | XGL_FLOAT color[4]; |
| 1196 | XGL_UINT32 raw[4]; |
| 1197 | }; |
| 1198 | |
| 1199 | bool test_raw_; |
| 1200 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1201 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const XGL_FLOAT color[4]) |
| 1202 | { |
| 1203 | std::vector<uint8_t> raw; |
| 1204 | |
| 1205 | // TODO support all formats |
| 1206 | if (format.numericFormat == XGL_NUM_FMT_UNORM) { |
| 1207 | switch (format.channelFormat) { |
| 1208 | case XGL_CH_FMT_R8G8B8A8: |
| 1209 | raw.push_back(color[0] * 255.0f); |
| 1210 | raw.push_back(color[1] * 255.0f); |
| 1211 | raw.push_back(color[2] * 255.0f); |
| 1212 | raw.push_back(color[3] * 255.0f); |
| 1213 | break; |
| 1214 | case XGL_CH_FMT_B8G8R8A8: |
| 1215 | raw.push_back(color[2] * 255.0f); |
| 1216 | raw.push_back(color[1] * 255.0f); |
| 1217 | raw.push_back(color[0] * 255.0f); |
| 1218 | raw.push_back(color[3] * 255.0f); |
| 1219 | break; |
| 1220 | default: |
| 1221 | break; |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1225 | return raw; |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1226 | } |
Chia-I Wu | f7ff6b4 | 2014-11-22 16:24:41 +0800 | [diff] [blame] | 1227 | |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1228 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const XGL_UINT32 color[4]) |
| 1229 | { |
| 1230 | std::vector<uint8_t> raw; |
| 1231 | |
| 1232 | // TODO support all formats |
| 1233 | if (format.numericFormat == XGL_NUM_FMT_UNORM) { |
| 1234 | switch (format.channelFormat) { |
| 1235 | case XGL_CH_FMT_R8G8B8A8: |
| 1236 | raw.push_back(static_cast<uint8_t>(color[0])); |
| 1237 | raw.push_back(static_cast<uint8_t>(color[1])); |
| 1238 | raw.push_back(static_cast<uint8_t>(color[2])); |
| 1239 | raw.push_back(static_cast<uint8_t>(color[3])); |
| 1240 | break; |
| 1241 | case XGL_CH_FMT_B8G8R8A8: |
| 1242 | raw.push_back(static_cast<uint8_t>(color[2])); |
| 1243 | raw.push_back(static_cast<uint8_t>(color[1])); |
| 1244 | raw.push_back(static_cast<uint8_t>(color[0])); |
| 1245 | raw.push_back(static_cast<uint8_t>(color[3])); |
| 1246 | break; |
| 1247 | default: |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | return raw; |
| 1253 | } |
| 1254 | |
| 1255 | std::vector<uint8_t> color_to_raw(XGL_FORMAT format, const Color &color) |
| 1256 | { |
| 1257 | if (test_raw_) |
| 1258 | return color_to_raw(format, color.raw); |
| 1259 | else |
| 1260 | return color_to_raw(format, color.color); |
| 1261 | } |
| 1262 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1263 | void test_clear_color_image(const XGL_IMAGE_CREATE_INFO &img_info, |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1264 | const Color &color, |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1265 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1266 | { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1267 | xgl_testing::Image img; |
| 1268 | img.init(dev_, img_info); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1269 | add_memory_ref(img, 0); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1270 | const XGL_FLAGS all_cache_outputs = |
| 1271 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1272 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1273 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1274 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1275 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1276 | const XGL_FLAGS all_cache_inputs = |
| 1277 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1278 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1279 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1280 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1281 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1282 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1283 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1284 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1285 | XGL_MEMORY_INPUT_COPY_BIT; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1286 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1287 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear; |
| 1288 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1289 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1290 | for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin(); |
| 1291 | it != ranges.end(); it++) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1292 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1293 | XGL_IMAGE_LAYOUT_GENERAL, |
| 1294 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1295 | *it)); |
| 1296 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1297 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1298 | XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it)); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1301 | cmd_.begin(); |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1302 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1303 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1304 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1305 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1306 | pipeline_barrier.eventCount = 1; |
| 1307 | pipeline_barrier.pEvents = set_events; |
| 1308 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1309 | pipeline_barrier.memBarrierCount = to_clear.size(); |
| 1310 | pipeline_barrier.pMemBarriers = &to_clear[0]; |
| 1311 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1312 | |
| 1313 | if (test_raw_) { |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1314 | xglCmdClearColorImageRaw(cmd_.obj(), img.obj(), color.raw, ranges.size(), &ranges[0]); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1315 | } else { |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1316 | xglCmdClearColorImage(cmd_.obj(), img.obj(), color.color, ranges.size(), &ranges[0]); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1320 | pipeline_barrier.eventCount = 1; |
| 1321 | pipeline_barrier.pEvents = set_events; |
| 1322 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1323 | pipeline_barrier.memBarrierCount = to_xfer.size(); |
| 1324 | pipeline_barrier.pMemBarriers = &to_xfer[0]; |
| 1325 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1326 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1327 | cmd_.end(); |
| 1328 | |
| 1329 | submit_and_done(); |
| 1330 | |
| 1331 | // cannot verify |
| 1332 | if (!img.transparent() && !img.copyable()) |
| 1333 | return; |
| 1334 | |
| 1335 | xgl_testing::ImageChecker checker(img_info, ranges); |
| 1336 | |
| 1337 | const std::vector<uint8_t> solid_pattern = color_to_raw(img_info.format, color); |
| 1338 | if (solid_pattern.empty()) |
| 1339 | return; |
| 1340 | |
| 1341 | checker.set_solid_pattern(solid_pattern); |
| 1342 | check_dst(img, checker); |
| 1343 | } |
Chia-I Wu | 9feab84 | 2014-12-22 13:19:08 +0800 | [diff] [blame] | 1344 | |
| 1345 | void test_clear_color_image(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1346 | const XGL_FLOAT color[4], |
| 1347 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1348 | { |
| 1349 | Color c; |
| 1350 | memcpy(c.color, color, sizeof(c.color)); |
| 1351 | test_clear_color_image(img_info, c, ranges); |
| 1352 | } |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1353 | }; |
| 1354 | |
| 1355 | TEST_F(XglCmdClearColorImageTest, Basic) |
| 1356 | { |
| 1357 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1358 | it != test_formats_.end(); it++) { |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1359 | const XGL_FLOAT color[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; |
| 1360 | |
| 1361 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1362 | img_info.imageType = XGL_IMAGE_2D; |
| 1363 | img_info.format = it->format; |
| 1364 | img_info.extent.width = 64; |
| 1365 | img_info.extent.height = 64; |
| 1366 | img_info.tiling = it->tiling; |
| 1367 | |
| 1368 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1369 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1370 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1371 | |
| 1372 | test_clear_color_image(img_info, color, ranges); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
Chia-I Wu | 8dbe856 | 2014-12-22 13:44:24 +0800 | [diff] [blame] | 1376 | class XglCmdClearColorImageRawTest : public XglCmdClearColorImageTest { |
| 1377 | protected: |
| 1378 | XglCmdClearColorImageRawTest() : XglCmdClearColorImageTest(true) {} |
| 1379 | |
| 1380 | void test_clear_color_image_raw(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1381 | const XGL_UINT32 color[4], |
| 1382 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1383 | { |
| 1384 | Color c; |
| 1385 | memcpy(c.raw, color, sizeof(c.raw)); |
| 1386 | test_clear_color_image(img_info, c, ranges); |
| 1387 | } |
| 1388 | }; |
| 1389 | |
| 1390 | TEST_F(XglCmdClearColorImageRawTest, Basic) |
| 1391 | { |
| 1392 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1393 | it != test_formats_.end(); it++) { |
| 1394 | const XGL_UINT32 color[4] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444 }; |
| 1395 | |
| 1396 | // not sure what to do here |
| 1397 | if (it->format.channelFormat == XGL_CH_FMT_UNDEFINED || |
| 1398 | it->format.channelFormat == XGL_CH_FMT_R32G32B32 || |
| 1399 | it->format.numericFormat == XGL_NUM_FMT_DS) |
| 1400 | continue; |
| 1401 | |
| 1402 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1403 | img_info.imageType = XGL_IMAGE_2D; |
| 1404 | img_info.format = it->format; |
| 1405 | img_info.extent.width = 64; |
| 1406 | img_info.extent.height = 64; |
| 1407 | img_info.tiling = it->tiling; |
| 1408 | |
| 1409 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1410 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_COLOR); |
Chia-I Wu | 8dbe856 | 2014-12-22 13:44:24 +0800 | [diff] [blame] | 1411 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1412 | |
| 1413 | test_clear_color_image_raw(img_info, color, ranges); |
| 1414 | } |
| 1415 | } |
| 1416 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1417 | class XglCmdClearDepthStencilTest : public XglCmdBlitImageTest { |
| 1418 | protected: |
| 1419 | virtual void SetUp() |
| 1420 | { |
| 1421 | XglCmdBlitTest::SetUp(); |
| 1422 | init_test_formats(XGL_FORMAT_DEPTH_ATTACHMENT_BIT | |
| 1423 | XGL_FORMAT_STENCIL_ATTACHMENT_BIT); |
| 1424 | ASSERT_NE(true, test_formats_.empty()); |
| 1425 | } |
| 1426 | |
| 1427 | std::vector<uint8_t> ds_to_raw(XGL_FORMAT format, XGL_FLOAT depth, XGL_UINT32 stencil) |
| 1428 | { |
| 1429 | std::vector<uint8_t> raw; |
| 1430 | |
| 1431 | // depth |
| 1432 | switch (format.channelFormat) { |
| 1433 | case XGL_CH_FMT_R16: |
| 1434 | case XGL_CH_FMT_R16G8: |
| 1435 | { |
| 1436 | const uint16_t unorm = depth * 65535.0f; |
| 1437 | raw.push_back(unorm & 0xff); |
| 1438 | raw.push_back(unorm >> 8); |
| 1439 | } |
| 1440 | break; |
| 1441 | case XGL_CH_FMT_R32: |
| 1442 | case XGL_CH_FMT_R32G8: |
| 1443 | { |
| 1444 | const union { |
| 1445 | XGL_FLOAT depth; |
| 1446 | uint32_t u32; |
| 1447 | } u = { depth }; |
| 1448 | |
| 1449 | raw.push_back((u.u32 ) & 0xff); |
| 1450 | raw.push_back((u.u32 >> 8) & 0xff); |
| 1451 | raw.push_back((u.u32 >> 16) & 0xff); |
| 1452 | raw.push_back((u.u32 >> 24) & 0xff); |
| 1453 | } |
| 1454 | break; |
| 1455 | default: |
| 1456 | break; |
| 1457 | } |
| 1458 | |
| 1459 | // stencil |
| 1460 | switch (format.channelFormat) { |
| 1461 | case XGL_CH_FMT_R8: |
| 1462 | raw.push_back(stencil); |
| 1463 | break; |
| 1464 | case XGL_CH_FMT_R16G8: |
| 1465 | raw.push_back(stencil); |
| 1466 | raw.push_back(0); |
| 1467 | break; |
| 1468 | case XGL_CH_FMT_R32G8: |
| 1469 | raw.push_back(stencil); |
| 1470 | raw.push_back(0); |
| 1471 | raw.push_back(0); |
| 1472 | raw.push_back(0); |
| 1473 | break; |
| 1474 | default: |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | return raw; |
| 1479 | } |
| 1480 | |
| 1481 | void test_clear_depth_stencil(const XGL_IMAGE_CREATE_INFO &img_info, |
| 1482 | XGL_FLOAT depth, XGL_UINT32 stencil, |
| 1483 | const std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> &ranges) |
| 1484 | { |
| 1485 | xgl_testing::Image img; |
| 1486 | img.init(dev_, img_info); |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1487 | add_memory_ref(img, 0); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1488 | const XGL_FLAGS all_cache_outputs = |
| 1489 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1490 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1491 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1492 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1493 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1494 | const XGL_FLAGS all_cache_inputs = |
| 1495 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1496 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1497 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1498 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1499 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1500 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1501 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1502 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1503 | XGL_MEMORY_INPUT_COPY_BIT; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1504 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1505 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear; |
| 1506 | std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer; |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1507 | |
| 1508 | for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin(); |
| 1509 | it != ranges.end(); it++) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1510 | to_clear.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1511 | XGL_IMAGE_LAYOUT_GENERAL, |
| 1512 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1513 | *it)); |
| 1514 | to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs, |
| 1515 | XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1516 | XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it)); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | cmd_.begin(); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1520 | |
| 1521 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1522 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1523 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1524 | pipeline_barrier.eventCount = 1; |
| 1525 | pipeline_barrier.pEvents = set_events; |
| 1526 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1527 | pipeline_barrier.memBarrierCount = to_clear.size(); |
| 1528 | pipeline_barrier.pMemBarriers = &to_clear[0]; |
| 1529 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1530 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1531 | xglCmdClearDepthStencil(cmd_.obj(), img.obj(), depth, stencil, ranges.size(), &ranges[0]); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1532 | |
| 1533 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1534 | pipeline_barrier.eventCount = 1; |
| 1535 | pipeline_barrier.pEvents = set_events; |
| 1536 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1537 | pipeline_barrier.memBarrierCount = to_xfer.size(); |
| 1538 | pipeline_barrier.pMemBarriers = &to_xfer[0]; |
| 1539 | xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier); |
| 1540 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1541 | cmd_.end(); |
| 1542 | |
| 1543 | submit_and_done(); |
| 1544 | |
| 1545 | // cannot verify |
| 1546 | if (!img.transparent() && !img.copyable()) |
| 1547 | return; |
| 1548 | |
| 1549 | xgl_testing::ImageChecker checker(img_info, ranges); |
| 1550 | |
| 1551 | checker.set_solid_pattern(ds_to_raw(img_info.format, depth, stencil)); |
| 1552 | check_dst(img, checker); |
| 1553 | } |
| 1554 | }; |
| 1555 | |
| 1556 | TEST_F(XglCmdClearDepthStencilTest, Basic) |
| 1557 | { |
| 1558 | for (std::vector<xgl_testing::Device::Format>::const_iterator it = test_formats_.begin(); |
| 1559 | it != test_formats_.end(); it++) { |
| 1560 | // known driver issues |
| 1561 | if (it->format.channelFormat == XGL_CH_FMT_R8) |
| 1562 | continue; |
| 1563 | |
| 1564 | XGL_IMAGE_CREATE_INFO img_info = xgl_testing::Image::create_info(); |
| 1565 | img_info.imageType = XGL_IMAGE_2D; |
| 1566 | img_info.format = it->format; |
| 1567 | img_info.extent.width = 64; |
| 1568 | img_info.extent.height = 64; |
| 1569 | img_info.tiling = it->tiling; |
| 1570 | img_info.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
| 1571 | |
| 1572 | const XGL_IMAGE_SUBRESOURCE_RANGE range = |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1573 | xgl_testing::Image::subresource_range(img_info, XGL_IMAGE_ASPECT_DEPTH); |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1574 | std::vector<XGL_IMAGE_SUBRESOURCE_RANGE> ranges(&range, &range + 1); |
| 1575 | |
| 1576 | test_clear_depth_stencil(img_info, 0.25f, 63, ranges); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | }; // namespace |
| 1581 | |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1582 | int main(int argc, char **argv) |
| 1583 | { |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1584 | ::testing::InitGoogleTest(&argc, argv); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1585 | |
Chia-I Wu | 9dac52d | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 1586 | xgl_testing::set_error_callback(test_error_callback); |
| 1587 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1588 | environment = new xgl_testing::Environment(); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1589 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1590 | if (!environment->parse_args(argc, argv)) |
| 1591 | return -1; |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1592 | |
Chia-I Wu | 6170c9e | 2014-12-08 14:30:10 +0800 | [diff] [blame] | 1593 | ::testing::AddGlobalTestEnvironment(environment); |
| 1594 | |
| 1595 | return RUN_ALL_TESTS(); |
Chia-I Wu | cb67c65 | 2014-10-21 11:06:26 +0800 | [diff] [blame] | 1596 | } |