Bug 212013 - Nonmappable buffers with createBufferMapped() doesn't work
Summary: Nonmappable buffers with createBufferMapped() doesn't work
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGPU (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-18 02:01 PDT by Myles C. Maxfield
Modified: 2020-05-18 17:02 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2020-05-18 02:01:32 PDT
See the comments in https://bugs.webkit.org/show_bug.cgi?id=211882
Comment 1 Radar WebKit Bug Importer 2020-05-18 02:03:58 PDT
<rdar://problem/63332658>
Comment 2 Myles C. Maxfield 2020-05-18 17:02:47 PDT
If you copy/paste this into WebKit, it takes 11 seconds to complete. However, if you put it in a sample project, it takes less than 1 second to complete. Maybe the sandbox is interfering?

    id<MTLDevice> device = MTLCreateSystemDefaultDevice();
    MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor new];
    textureDescriptor.textureType = MTLTextureType2DArray;
    textureDescriptor.pixelFormat = MTLPixelFormatRGBA8Unorm;
    textureDescriptor.width = 512;
    textureDescriptor.height = 512;
    textureDescriptor.depth = 1;
    textureDescriptor.mipmapLevelCount = 9;
    textureDescriptor.sampleCount = 1;
    textureDescriptor.arrayLength = 2;
    textureDescriptor.storageMode = MTLStorageModePrivate;
    textureDescriptor.usage = MTLTextureUsageShaderRead;
    id<MTLTexture> texture = [device newTextureWithDescriptor:textureDescriptor];

    id<MTLBuffer> buffer = [device newBufferWithLength:1048576 options:MTLStorageModeShared];
    uint8_t* p = (uint8_t*)buffer.contents;
    for (int i = 0; i < 512; ++i) {
        for (int j = 0; j < 512; ++j) {
            p[i * 512 * 4 + j * 4 + 0] = 0;
            p[i * 512 * 4 + j * 4 + 1] = 255;
            p[i * 512 * 4 + j * 4 + 2] = 0;
            p[i * 512 * 4 + j * 4 + 3] = 255;
        }
    }
    id<MTLCommandQueue> queue = [device newCommandQueue];
    id<MTLCommandBuffer> commandBuffer = [queue commandBuffer];
    id<MTLBlitCommandEncoder> commandEncoder = [commandBuffer blitCommandEncoder];
    [commandEncoder copyFromBuffer:buffer sourceOffset:0 sourceBytesPerRow:2048 sourceBytesPerImage:1048576 sourceSize:MTLSizeMake(512, 512, 1) toTexture:texture destinationSlice:0 destinationLevel:0 destinationOrigin: MTLOriginMake(0, 0, 0)];
    [commandEncoder endEncoding];
    [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
        NSLog(@"Test Done.");
    }];
    NSLog(@"Test committing");
    [commandBuffer commit];
    [[NSRunLoop mainRunLoop] run];