| 209 | } |
| 210 | |
| 211 | void doCopyTestMappedAtCreation(ScopedCounter scope, bool useRange) { |
| 212 | static constexpr uint32_t kValue = 0x05060708; |
| 213 | size_t size = useRange ? 12 : 4; |
| 214 | wgpu::Buffer src; |
| 215 | { |
| 216 | wgpu::BufferDescriptor descriptor{}; |
| 217 | descriptor.size = size; |
| 218 | descriptor.usage = wgpu::BufferUsage::CopySrc; |
| 219 | descriptor.mappedAtCreation = true; |
| 220 | src = device.CreateBuffer(&descriptor); |
| 221 | } |
| 222 | size_t offset = useRange ? 8 : 0; |
| 223 | uint32_t* ptr = static_cast<uint32_t*>(useRange ? |
| 224 | src.GetMappedRange(offset, 4) : |
| 225 | src.GetMappedRange()); |
| 226 | printf("%s: getMappedRange -> %p%s\n", __FUNCTION__, |
| 227 | ptr, ptr ? "" : " <------- FAILED"); |
| 228 | assert(ptr != nullptr); |
| 229 | *ptr = kValue; |
| 230 | src.Unmap(); |
| 231 | |
| 232 | wgpu::Buffer dst; |
| 233 | { |
| 234 | wgpu::BufferDescriptor descriptor{}; |
| 235 | descriptor.size = 4; |
| 236 | descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead; |
| 237 | dst = device.CreateBuffer(&descriptor); |
| 238 | } |
| 239 | |
| 240 | // Write some random data to the buffer, just to verify that |
| 241 | // wgpuQueueWriteBuffer works. |
| 242 | char data[4]; |
| 243 | queue.WriteBuffer(dst, 0, data, sizeof(data)); |
| 244 | |
| 245 | wgpu::CommandBuffer commands; |
| 246 | { |
| 247 | wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); |
| 248 | encoder.CopyBufferToBuffer(src, offset, dst, 0, 4); |
| 249 | commands = encoder.Finish(); |
| 250 | } |
| 251 | queue.Submit(1, &commands); |
| 252 | |
| 253 | issueContentsCheck(scope, __FUNCTION__, dst, kValue); |
| 254 | } |
| 255 | |
| 256 | void doCopyTestMapAsync(ScopedCounter scope, bool useRange) { |
| 257 | static constexpr uint32_t kValue = 0x01020304; |