webgpu Texture::GetFormat always returns 0 and Buffer::GetMapState MIA.

20 views
Skip to first unread message

Mark Sibly

unread,
Feb 7, 2023, 7:33:09 PM2/7/23
to emscripten-discuss
Hi,

I'm writing an emscripten/webgpu app and Texture::GetFormat() is always returning 0. The texture is otherwise working and usable so I can work around it for now.

GetFormat works as expected with the same code built natively using the dawn lib, and GetWidth and GetHeight are also working fin on both emscripten and native.

Here's my texture creation code:

    wgpu::Extent3D size = {width, height, 1};

    wgpu::TextureDescriptor desc;
    desc.usage = usage;
    desc.dimension = wgpu::TextureDimension::e2D;
    desc.size = size;
    desc.format = format;
    desc.mipLevelCount = mipmap ? (uint32_t)std::floor(log2(std::min(width, height))) + 1 : 1;
    desc.sampleCount = 1;

    log() << "### Creating texture:" << (int)desc.format << desc.size.width << desc.size.height;

    auto texture = device.CreateTexture(&desc);

    log() << "### Created texture:" << (int)texture.GetFormat() << texture.GetWidth() << texture.GetHeight();

I had a quick look at the library_webgpu.js code but the 2 lines there look fine.

Also, emscripten wgpu::Buffer appears to be missing the GetMapState() member, ditto
wgpuBufferGetMapState.

Bye!
Mark

Mark Sibly

unread,
Mar 1, 2023, 5:49:19 PM3/1/23
to emscripten-discuss
Hi,

OK, the problem with emscripten wgpu::Texture::GetFormat is in the wgpuTextureGetFormat function in library_webgpu.js

This is currently just directly returning webgpu texture.format, which is a string (eg: "rgba8unorm"), but dawn texture formats are ints so this needs to be converted.

I verified this is the problem by hacking wgpuTextureGetFormat to handle just the formats I use:

wgpuTextureGetFormat: function(textureId) {
    var texture = WebGPU.mgrTexture.get(textureId);
    // Note: This switch currently MIA!
    switch(texture.format) {
    case 'rgba8unorm':return 18;
    case 'rgba8unorm-srgb':return 19;
    }
    return 0;
},

Bye!
Mark
Reply all
Reply to author
Forward
Message has been deleted
0 new messages