MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / doCopyTestMapAsync

Function doCopyTestMapAsync

test/webgpu_basic_rendering.cpp:256–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void doCopyTestMapAsync(ScopedCounter scope, bool useRange) {
257 static constexpr uint32_t kValue = 0x01020304;
258 size_t size = useRange ? 12 : 4;
259 wgpu::Buffer src;
260 {
261 wgpu::BufferDescriptor descriptor{};
262 descriptor.size = size;
263 descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
264 src = device.CreateBuffer(&descriptor);
265 }
266 size_t offset = useRange ? 8 : 0;
267
268 std::string functionName = __FUNCTION__;
269 src.MapAsync(
270 wgpu::MapMode::Write, offset, 4, wgpu::CallbackMode::AllowSpontaneous,
271 [=](wgpu::MapAsyncStatus status, wgpu::StringView message) {
272 if (message.length) {
273 printf("src.MapAsync: %.*s\n", int(message.length), message.data);
274 }
275 assert(status == wgpu::MapAsyncStatus::Success);
276
277 uint32_t* ptr = static_cast<uint32_t*>(useRange ?
278 src.GetMappedRange(offset, 4) :
279 src.GetMappedRange());
280 printf("%s: getMappedRange -> %p%s\n", functionName.c_str(),
281 ptr, ptr ? "" : " <------- FAILED");
282 assert(ptr != nullptr);
283 *ptr = kValue;
284 src.Unmap();
285
286 wgpu::Buffer dst;
287 {
288 wgpu::BufferDescriptor descriptor{};
289 descriptor.size = 4;
290 descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
291 dst = device.CreateBuffer(&descriptor);
292 }
293
294 wgpu::CommandBuffer commands;
295 {
296 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
297 encoder.CopyBufferToBuffer(src, offset, dst, 0, 4);
298 commands = encoder.Finish();
299 }
300 queue.Submit(1, &commands);
301
302 issueContentsCheck(scope, functionName, dst, kValue);
303 });
304}
305
306void doRenderTest(ScopedCounter scope) {
307 wgpu::Texture readbackTexture;

Callers 1

runFunction · 0.85

Calls 6

printfFunction · 0.85
issueContentsCheckFunction · 0.85
FinishMethod · 0.80
assertFunction · 0.50
c_strMethod · 0.45
UnmapMethod · 0.45

Tested by

no test coverage detected