Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to WebGPU instead of Vulkan for 3D / 2D rendering. #1112

Merged
merged 218 commits into from
Aug 17, 2024
Merged

switch to WebGPU instead of Vulkan for 3D / 2D rendering. #1112

merged 218 commits into from
Aug 17, 2024

Conversation

rcoreilly
Copy link
Member

@rcoreilly rcoreilly commented Aug 3, 2024

This mega-branch contains a new version of vgpu that works with WebGPU instead of vulkan.

Overall WebGPU is much simpler and cleaner than vulkan, and, critically, works on the web.

The top-level gpu package contains the full implementation and supporting packages, replacing vgpu and associated packages.

gpudraw replaces vdraw and has an improved interface, updating the system.Drawer interface used for basic 2D image compositing during rendering.

This is not done yet but maybe @kkoreilly wants to make any comments on the gpudraw api at this point?

(Edit from @kkoreilly):
For GitHub purposes, this fixes #290, fixes #481, fixes #483, fixes #507, fixes #682, fixes #911, fixes #1018, fixes #1063, fixes #1101, fixes #1106, fixes #1115 (#507 and #682 are the primary issues)

rcoreilly and others added 30 commits July 26, 2024 18:58
…uff. next is memory (need to re-remember how all that works)
…ng instead of complicating the values to be as dynamic as all that -- just need to pre-gather all the objects to be rendered first, get all their model matricies, and other per-object data, and then upload those as vertex per-instance data.. push constants sure are so much easier..
…Float32Matrix4 over 4 vector4s with proper interleaving.
…eration. can independently update bindings per group so that's good for textures -- definitely the way to go.
@kkoreilly
Copy link
Member

I verified that this works on all browsers on all platforms to the extent possible:

Full support on:

  • Chrome and Opera on macOS and Windows
  • Edge on Windows

2D backup support on:

  • Firefox on macOS, Windows, Linux, and Android
  • Safari on macOS and iOS
  • Chrome on Linux and Android

Note that we will gradually enable support for the current 2D backup platforms as they develop sufficient support, but currently they do not have such (#1144).

Additionally, I have verified that this works natively on macOS, Windows, Linux, iOS, and Android. Therefore, this is ready to be merged.

@kkoreilly kkoreilly marked this pull request as ready for review August 17, 2024 22:34
@kkoreilly kkoreilly merged commit 4ecd94f into main Aug 17, 2024
1 check passed
@kkoreilly kkoreilly deleted the wgpu branch August 17, 2024 22:35
@theclapp
Copy link

Nice work!

Can confirm it still works on my Debian Linux VM, and my Windows 10 VM.

The macOS native version doesn't seem to spike my laptop fans any more, either, so that's great, too. (Detail: it doesn't spike my "cpu package gpu" power usage, which was, I think, the "smoking gun" on the fans.)

@rcoreilly
Copy link
Member Author

@theclapp great news on the power usage on intel mac -- I had noticed on my intel mac that the vulkan version seemed to push the fans a lot.

Could you also run this command:

go run cogentcore.org/core/gpu/cmd/webgpuinfo@latest 

on your linux vm and report the results here? I'm curious what the "backend type" says there, and what the limits are, etc. And you've tried examples/xyz on it and that all works?

@theclapp
Copy link

webgpuinfo output
go: downloading cogentcore.org/core v0.3.2
[wgpu] [Warn] Unable to find extension: VK_EXT_swapchain_colorspace

########################
WebGPU Adapter number: 0
{
        "VendorId": 65541,
        "VendorName": "0x10005",
        "Architecture": "",
        "DeviceId": 0,
        "Name": "0x0",
        "DriverDescription": "llvmpipe (LLVM 15.0.6, 256 bits)",
        "AdapterType": 2,
        "BackendType": 6
}

{
        "Limits": {
                "MaxTextureDimension1D": 16384,
                "MaxTextureDimension2D": 16384,
                "MaxTextureDimension3D": 4096,
                "MaxTextureArrayLayers": 2048,
                "MaxBindGroups": 8,
                "MaxBindingsPerBindGroup": 1000,
                "MaxDynamicUniformBuffersPerPipelineLayout": 256,
                "MaxDynamicStorageBuffersPerPipelineLayout": 256,
                "MaxSampledTexturesPerShaderStage": 128,
                "MaxSamplersPerShaderStage": 32,
                "MaxStorageBuffersPerShaderStage": 32,
                "MaxStorageTexturesPerShaderStage": 64,
                "MaxUniformBuffersPerShaderStage": 15,
                "MaxUniformBufferBindingSize": 65536,
                "MaxStorageBufferBindingSize": 134217728,
                "MinUniformBufferOffsetAlignment": 32,
                "MinStorageBufferOffsetAlignment": 32,
                "MaxVertexBuffers": 16,
                "MaxBufferSize": 2147483647,
                "MaxVertexAttributes": 32,
                "MaxVertexBufferArrayStride": 2048,
                "MaxInterStageShaderComponents": 128,
                "MaxInterStageShaderVariables": 0,
                "MaxColorAttachments": 0,
                "MaxColorAttachmentBytesPerSample": 0,
                "MaxComputeWorkgroupStorageSize": 32768,
                "MaxComputeInvocationsPerWorkgroup": 1024,
                "MaxComputeWorkgroupSizeX": 1024,
                "MaxComputeWorkgroupSizeY": 1024,
                "MaxComputeWorkgroupSizeZ": 1024,
                "MaxComputeWorkgroupsPerDimension": 65535,
                "MaxPushConstantSize": 775102547
        }
}


########################
WebGPU Adapter number: 1
{
        "VendorId": 65541,
        "VendorName": "0x10005",
        "Architecture": "",
        "DeviceId": 0,
        "Name": "0x0",
        "DriverDescription": "llvmpipe (LLVM 15.0.6, 256 bits)",
        "AdapterType": 2,
        "BackendType": 7
}

{
        "Limits": {
                "MaxTextureDimension1D": 16384,
                "MaxTextureDimension2D": 16384,
                "MaxTextureDimension3D": 2048,
                "MaxTextureArrayLayers": 2048,
                "MaxBindGroups": 8,
                "MaxBindingsPerBindGroup": 65535,
                "MaxDynamicUniformBuffersPerPipelineLayout": 15,
                "MaxDynamicStorageBuffersPerPipelineLayout": 16,
                "MaxSampledTexturesPerShaderStage": 16,
                "MaxSamplersPerShaderStage": 16,
                "MaxStorageBuffersPerShaderStage": 16,
                "MaxStorageTexturesPerShaderStage": 32,
                "MaxUniformBuffersPerShaderStage": 15,
                "MaxUniformBufferBindingSize": 65536,
                "MaxStorageBufferBindingSize": 134217728,
                "MinUniformBufferOffsetAlignment": 32,
                "MinStorageBufferOffsetAlignment": 32,
                "MaxVertexBuffers": 16,
                "MaxBufferSize": 2147483647,
                "MaxVertexAttributes": 16,
                "MaxVertexBufferArrayStride": 2048,
                "MaxInterStageShaderComponents": 128,
                "MaxInterStageShaderVariables": 0,
                "MaxColorAttachments": 0,
                "MaxColorAttachmentBytesPerSample": 0,
                "MaxComputeWorkgroupStorageSize": 32768,
                "MaxComputeInvocationsPerWorkgroup": 1024,
                "MaxComputeWorkgroupSizeX": 1024,
                "MaxComputeWorkgroupSizeY": 1024,
                "MaxComputeWorkgroupSizeZ": 1024,
                "MaxComputeWorkgroupsPerDimension": 65535,
                "MaxPushConstantSize": 0
        }
}

And yes, the xyz demo seems to work, too. 🎉

@kkoreilly
Copy link
Member

Great, thank you for the information!

@gedw99
Copy link

gedw99 commented Aug 19, 2024

you guys are kicking it !!!

@kkoreilly
Copy link
Member

Thank you!

@gedw99
Copy link

gedw99 commented Aug 19, 2024

question:

"2D backup support on:

Firefox on macOS, Windows, Linux, and Android
Safari on macOS and iOS
Chrome on Linux and Android"

SO does this mean that 2D works on Mac and IOS without having to turn on WebGPU support in the settings ? Quite curious , because it really matters to users.

@kkoreilly
Copy link
Member

Yes, 2D works automatically on all platforms on which WebGPU is not yet supported.

@gedw99
Copy link

gedw99 commented Aug 19, 2024

supported

Yes, 2D works automatically on all platforms on which WebGPU is not yet supported.

thanks @kkoreilly - will pull latest and give it a whirl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment