Giter VIP home page Giter VIP logo

webgpu-native-examples's Introduction

WebGPU Native Examples and Demos

WebGPU is a new graphics and compute API designed by the “GPU for the Web” W3C community group. It aims to provide modern features such as “GPU compute” as well as lower overhead access to GPU hardware and better, more predictable performance. WebGPU should work with existing platform APIs such as Direct3D 12 from Microsoft, Metal from Apple, and Vulkan from the Khronos Group.

WebGPU is designed for the Web, used by JavaScript and WASM applications, and driven by the shared principles of Web APIs. However, it doesn’t have to be only for the Web though. Targeting WebGPU on native enables to write extremely portable and fairly performant graphics applications. The WebGPU API is beginner friendly, meaning that the API automates some of the aspects of low-level graphics APIs which have high complexity but low return on investment. It still has the core pieces of the next-gen APIs, such as command buffers, render passes, pipeline states and layouts. Because the complexity is reduced, users will be able to direct more focus towards writing efficiently application code.

From the very beginning, Google had both native and in-browser use of their implementation, which is now called Dawn. Mozilla has a shared interest in allowing developers to target a shared “WebGPU on native” target instead of a concrete “Dawn” or “wgpu-native”. This is achieved, by a shared header, and C-compatible libraries implementing it. However, this specification is still a moving target.

This repository contains a collection of open source C examples for WebGPU using Dawn the open-source and cross-platform implementation of the work-in-progress WebGPU standard.

Table of Contents

Supported Platforms

  • GNU/Linux

Get the Sources

This repository contains submodules for external dependencies, so when doing a fresh clone you need to clone recursively:

$ git clone --recursive https://github.com/samdauwe/webgpu-native-examples.git

Existing repositories can be updated manually:

$ git submodule init
$ git submodule update

Building for native with Dawn

The examples are built on top of Dawn, an open-source and cross-platform implementation of the work-in-progress WebGPU standard.

GNU/Linux

A helper bash script was created to fetch the latest version of "depot_tools" and "Dawn". With this approach only the Dawn code base is fetched in order to build the WebGPU implementation using CMake and without using the Chromium build system and dependency management.

The first step into building the WebGPU examples is running this script as follows:

$ cd external/dawn
$ bash download_dawn.sh

Note: running this script takes a while as it needs to pull several Gigabytes of dependencies from the internet.

The second step is building the examples:

$ mkdir build
$ cd build
$ cmake ..
$ make all

Docker container

To build and run the examples inside a Docker container, follow the steps as described below.

Build the Docker image:

$ bash ./build.sh -docker_build

Run the Docker container:

$ bash ./build.sh -docker_run

Once the docker container is running, update to the latest version of "depot_tools" and "Dawn":

$ bash ./build.sh -update_dawn

Note: The build toolchain from depot_tools will not be used for building Dawn. Therefore, if this steps fails when extracting the build toolchains (i.e. debian_sid_i386_sysroot.tar.xz) and you see an error similar to this:

tar: .: Cannot change ownership to uid 416578, gid 89939: Invalid argument

then just ignore this error, because the required Dawn source code is already fetched at this point.

Finally, build the samples

$ bash ./build.sh -webgpu_native_examples

Running the examples

Linux

The build step described in the previous section creates a subfolder "x64" in the build folder. This subfolder contains all libraries and assets needed to run examples. Instead of a separate executable for each different example, a different approach was chosen to create an example launcher. This launcher can be used as follows, "./wgpu_sample_launcher -s <example_name>" where <example_name> is the filename of the example without the extension, like for example:

$ ./wgpu_sample_launcher -s shadertoy

Project Layout

├─ 📂 assets/         # Assets (models, textures, shaders, etc.)
├─ 📂 doc/            # Documentation files
│  └─ 📁 images         # WebGPU diagram, logo
├─ 📂 docker/         # Contains the Dockerfile for building Docker image
├─ 📂 external/       # Dependencies dependencies
│  ├─ 📁 cglm           # Highly Optimized Graphics Math (glm) for C
│  ├─ 📁 dawn           # WebGPU implementation
│  └─ 📁 ...            # Other Dependencies (cgltf, cimgui, stb, etc.)
├─ 📂 lib/            # Custom libraries
│  └─ 📁 wgpu_native    # Helper functions using the Dawn C++ API exposed as C API
├─ 📂 screenshots/    # Contains screenshots for each functional example
├─ 📂 src/            # Helper functions and examples source code
│  ├─ 📁 core           # Base functions (input, camera, logging, etc.)
│  ├─ 📁 examples       # Examples source code, each example is located in a single file
│  ├─ 📁 platforms      # Platform dependent functionality (input handling, window creation, etc.)
│  ├─ 📁 webgpu         # WebGPU related helper functions (buffers & textures creation, etc.)
│  └─ 📄 main.c         # Example launcher main source file
├─ 📄 .clang-format   # Clang-format file for automatically formatting C code
├─ 📄 .gitmodules     # Used Git submodules
├─ 📄 .gitignore      # Ignore certain files in git repo
├─ 📄 build.sh        # bash script to automate different aspects of the build process
├─ 📄 CMakeLists.txt  # CMake build file
├─ 📄 LICENSE         # Repository License (Apache-2.0 License)
└─ 📃 README.md       # Read Me!

Examples

Basics

This example shows how to set up a swap chain and clearing the screen. The screen clearing animation shows a fade-in and fade-out effect.

Illustrates the coordinate systems used in WebGPU. WebGPU’s coordinate systems match DirectX and Metal’s coordinate systems in a graphics pipeline. Y-axis is up in normalized device coordinate (NDC): point(-1.0, -1.0) in NDC is located at the bottom-left corner of NDC. This example has several options for changing relevant pipeline state, and displaying meshes with WebGPU or Vulkan style coordinates.

Render Depth Texture
render_coordinates depth_coordinates texture_coordinates

Minimalistic render pipeline demonstrating how to render a full-screen colored quad.

This example shows how to render a static colored square in WebGPU with only using vertex buffers.

Basic and verbose example for getting a colored triangle rendered to the screen using WebGPU. This is meant as a starting point for learning WebGPU from the ground up.

This example shows some of the alignment requirements involved when updating and binding multiple slices of a uniform buffer.

This example provides example camera implementations

Bind groups are used to pass data to shader binding points. This example sets up bind groups & layouts, creates a single render pipeline based on the bind group layout and renders multiple objects with different bind groups.

Dynamic uniform buffers are used for rendering multiple objects with multiple matrices stored in a single uniform buffer object. Individual matrices are dynamically addressed upon bind group binding time, minimizing the number of required bind groups.

Loads a 2D texture from disk (including all mip levels), uses staging to upload it into video memory and samples from it using combined image samplers.

This example shows how to bind and sample textures.

This example shows how to render and sample from a cubemap texture.

Loads a cube map texture from disk containing six different faces. All faces and mip levels are uploaded into video memory, and the cubemap is displayed on a skybox as a backdrop and on a 3D model as a reflection.

Generates a 3D texture on the cpu (using perlin noise), uploads it to the device and samples it to render an animation. 3D textures store volumetric data and interpolate in all three dimensions.

This example shows how to render an equirectangular panorama consisting of a single rectangular image. The equirectangular input can be used for a 360 degrees viewing experience to achieve more realistic surroundings and convincing real-time effects.

This example shows how to how to load Basis Universal supercompressed GPU textures in a WebGPU application.

This example demonstrates order independent transparency using a per-pixel linked-list of translucent fragments.

This example shows the use of reversed z technique for better utilization of depth buffer precision. The left column uses regular method, while the right one uses reversed z technique. Both are using depth32float as their depth buffer format. A set of red and green planes are positioned very close to each other. Higher sets are placed further from camera (and are scaled for better visual purpose). To use reversed z to render your scene, you will need depth store value to be 0.0, depth compare function to be greater, and remap depth range by multiplying an additional matrix to your projection matrix.

Visualizes what all the sampler parameters do. Shows a textured plane at various scales (rotated, head-on, in perspective, and in vanishing perspective). The bottom-right view shows the raw contents of the 4 mipmap levels of the test texture (16x16, 8x8, 4x4, and 2x2).

This example shows how to render with conservative rasterization (native extension with limited support).

When enabled, any pixel touched by a triangle primitive is rasterized. This is useful for various advanced techniques, most prominently for implementing realtime voxelization.

The demonstration here is implemented by rendering a triangle to a low-resolution target and then upscaling it with nearest-neighbor filtering. The outlines of the triangle are then rendered in the original solution, using the same vertex shader as the triangle. Pixels only drawn with conservative rasterization enabled are colored red.

Note: Conservative rasterization not supported in Google Dawn.

This example shows how to render a single indexed triangle model as mesh, wireframe, or wireframe with thick lines, without the need to generate additional buffers for line rendering.

Uses vertex pulling to let the vertex shader decide which vertices to load, which allows us to render indexed triangle meshes as wireframes or even thick-wireframes.

  • A normal wireframe is obtained by drawing 3 lines (6 vertices) per triangle. The vertex shader then uses the index buffer to load the triangle vertices in the order in which we need them to draw lines.
  • A thick wireframe is obtained by rendering each of the 3 lines of a triangle as a quad (comprising 2 triangles). For each triangle of the indexed model, we are drawing a total of 3 lines/quads = 6 triangles = 18 vertices. Each of these 18 vertices belongs to one of three lines, and each vertex shader invocation loads the start and end of the corresponding line. The line is then projected to screen space, and the orthogonal of the screen-space line direction is used to shift the vertices of each quad into the appropriate directions to obtain a thick line.

Basic offscreen rendering in two passes. First pass renders the mirrored scene to a separate framebuffer with color and depth attachments, second pass samples from that color attachment for rendering a mirror surface.

WebGPU doesn't let you set the viewport’s values to be out-of-bounds. Therefore, the viewport’s values need to be clamped to the screen-size, which means the viewport values can’t be defined in a way that makes the viewport go off the screen. This example shows how to render a viewport out-of-bounds.

Uses the stencil buffer and its compare functionality for rendering a 3D model with dynamic outlines.

glTF

These samples show how implement different features of the glTF 2.0 3D format 3D transmission file format in detail.

Shows how to load a complete scene from a glTF 2.0 file. The structure of the glTF 2.0 scene is converted into the data structures required to render the scene with WebGPU.

Renders a complete scene loaded from an glTF 2.0 file. The sample uses the glTF model loading functions, and adds data structures, functions and shaders required to render a more complex scene using Crytek's Sponza model with per-material pipelines and normal mapping.

Advanced

This example shows how to achieve multisample anti-aliasing(MSAA) in WebGPU. The render pipeline is created with a sample count > 1. A new texture with a sample count > 1 is created and set as the color attachment instead of the swapchain. The swapchain is now specified as a resolve_target.

Implements multisample anti-aliasing (MSAA) using a renderpass with multisampled attachments that get resolved into the visible frame buffer.

Implements a high dynamic range rendering pipeline using 16/32 bit floating point precision for all internal formats, textures and calculations, including a bloom pass, manual exposure and tone mapping.

This example shows how to create a basic reflection pipeline.

This example shows how to sample from a depth texture to render shadows from a directional light source.

Generating a complete mip-chain at runtime instead of loading it from a file, by blitting from one mip level, starting with the actual texture image, down to the next smaller size until the lower 1x1 pixel end of the mip chain.

This example shows how to capture an image by rendering a scene to a texture, copying the texture to a buffer, and retrieving the image from the buffer so that it can be stored into a png image. Two render pipelines are used in this example: one for rendering the scene in a window and another pipeline for offscreen rendering. Note that a single offscreen render pipeline would be sufficient for "taking a screenshot," with the added benefit that this method would not require a window to be created.

Performance

Uses the instancing feature for rendering (many) instances of the same mesh from a single vertex buffer with variable parameters.

Demonstrated how to use occlusion queries to get the number of fragment samples that pass all the per-fragment tests for a set of drawing commands.

This example shows how to use render bundles. It renders a large number of meshes individually as a proxy for a more complex scene in order to demonstrate the reduction in time spent to issue render commands. (Typically a scene like this would make use of instancing to reduce draw overhead.)

Physically Based Rendering

Physical based rendering as a lighting technique that achieves a more realistic and dynamic look by applying approximations of bidirectional reflectance distribution functions based on measured real-world material parameters and environment lighting.

Demonstrates a basic specular BRDF implementation with solid materials and fixed light sources on a grid of objects with varying material parameters, demonstrating how metallic reflectance and surface roughness affect the appearance of pbr lit objects.

Adds image based lighting from an hdr environment cubemap to the PBR equation, using the surrounding environment as the light source. This adds an even more realistic look the scene as the light contribution used by the materials is now controlled by the environment. Also shows how to generate the BRDF 2D-LUT and irradiance and filtered cube maps from the environment map.

Renders a model specially crafted for a metallic-roughness PBR workflow with textures defining material parameters for the PRB equation (albedo, metallic, roughness, baked ambient occlusion, normal maps) in an image based lighting environment.

Deferred

These examples use a deferred shading setup.

This example shows how to do deferred rendering with webgpu. Render geometry info to multiple targets in the gBuffers in the first pass. In this sample we have 2 gBuffers for normals and albedo, along with a depth texture. And then do the lighting in a second pass with per fragment data read from gBuffers so it's independent of scene complexity. World-space positions are reconstructed from the depth texture and camera matrix. We also update light position in a compute shader, where further operations like tile/cluster culling could happen. The debug view shows the depth buffer on the left (flipped and scaled a bit to make it more visible), the normal G buffer in the middle, and the albedo G-buffer on the right side of the screen.

Compute Shader

A WebGPU port of the Animometer MotionMark benchmark.

A GPU compute particle simulation that mimics the flocking behavior of birds. A compute shader updates two ping-pong buffers which store particle data. The data is used to draw instanced particles.

This example shows how to blur an image using a compute shader.

Uses a compute shader to apply different convolution kernels (and effects) on an input image in realtime.

Attraction based 2D GPU particle system using compute shaders. Particle data is stored in a shader storage buffer and only modified on the GPU using compute particle updates with graphics pipeline vertex access.

Particle system using compute shaders. Particle data is stored in a shader storage buffer, particle movement is implemented using easing functions.

A simple N-body simulation based particle system implemented using WebGPU.

Simple GPU ray tracer with shadows and reflections using a compute shader. No scene geometry is rendered in the graphics pass.

A classic Cornell box, using a lightmap generated using software ray-tracing.

User Interface

Load and render a 2D text overlay created from the bitmap glyph data of a stb font file. This data is uploaded as a texture and used for displaying text on top of a 3D scene in a second pass.

Generates and renders a complex user interface with multiple windows, controls and user interaction on top of a 3D scene. The UI is generated using Dear ImGUI and updated each frame.

Effects

Demonstrates the basics of fullscreen shader effects. The scene is rendered into an offscreen framebuffer at lower resolution and rendered as a fullscreen quad atop the scene using a radial blur fragment shader.

Advanced fullscreen effect example adding a bloom effect to a scene. Glowing scene parts are rendered to a low res offscreen framebuffer that is applied atop the scene using a two pass separated gaussian blur.

This example demonstrates multiple different methods that employ fragment shaders to achieve additional perceptual depth on the surface of a cube mesh. Demonstrated methods include normal mapping, parallax mapping, and steep parallax mapping.

Implements multiple texture mapping methods to simulate depth based on texture information: Normal mapping, parallax mapping, steep parallax mapping and parallax occlusion mapping (best quality, worst performance).

This example shows how to use a post-processing effect to blend between two scenes. This example has been ported from this JavaScript implementation to native code.

Misc

WebGPU interpretation of glxgears. Procedurally generates and animates multiple gears.

This example shows how to upload video frames to WebGPU. Uses FFmpeg for the video decoding.

This example shows how to display a 360-degree video where the viewer has control of the viewing direction. Uses FFmpeg for the video decoding.

Minimal "shadertoy launcher" using WebGPU, demonstrating how to load an example Shadertoy shader 'Seascape'.

WebGPU implementation of the Gerstner Waves algorithm. This example has been ported from this JavaScript implementation to native code.

This example shows how to render an infinite landscape for the camera to meander around in. The terrain consists of a tiled planar mesh that is displaced with a heightmap. More technical details can be found on this page and this one.

A WebGPU example demonstrating pseudorandom number generation on the GPU. A 32-bit PCG hash is used which is fast enough to be useful for real-time, while also being high-quality enough for almost any graphics use-case.

This example shows how to make Conway's game of life. First, use compute shader to calculate how cells grow or die. Then use render pipeline to draw cells by using instance mesh.

A binary Conway game of life. This example has been ported from this JavaScript implementation to native code.

A conway game of life with paletted blurring over time. This example has been ported from this JavaScript implementation to native code.

WebGPU demo featuring marching cubes and bloom post-processing via compute shaders, physically based shading, deferred rendering, gamma correction and shadow mapping. This example has been ported from this TypeScript implementation to native code. More implementation details can be found in this blog post.

WebGPU demo featuring an implementation of Jos Stam's "Real-Time Fluid Dynamics for Games" paper. This example has been ported from this JavaScript implementation to native code.

This example shows how to map a GPU buffer and use the function wgpuBufferGetMappedRange. This example is based on the vertex_buffer test case.

This example shows how to efficiently draw several procedurally generated meshes. The par_shapes library is used to generate parametric surfaces and other simple shapes.

This example shows how to render tile maps using WebGPU. The map is rendered using two textures. One is the tileset, the other is a texture representing the map itself. Each pixel encodes the x/y coords of the tile from the tileset to draw. The example code has been ported from this JavaScript implementation to native code. More implementation details can be found in this blog post.

This example demonstrates how to render a torus knot mesh with blinn-phong lighting model.

This example demonstrates how to achieve normal mapping in WebGPU. A normal map uses RGB information that corresponds directly with the X, Y and Z axis in 3D space. This RGB information tells the 3D application the exact direction of the surface normals are oriented in for each and every polygon.

A simple WebGPU implementation of the "Pristine Grid" technique described in this wonderful little blog post. The example code has been ported from this JavaScript implementation to native code.

Dependencies

Just like all software, WebGPU Native Examples and Demos are built on the shoulders of incredible people! Here's a list of the used libraries.

System

  • CMake (>= 3.17)
  • FFmpeg used for video decoding (optional)

Available as git submodules or folders

  • basisu: Single File Basis Universal Transcoder.
  • cglm: Highly Optimized Graphics Math (glm) for C.
  • cgltf: Single-file glTF 2.0 loader and writer written in C99.
  • cimgui: c-api for Dear ImGui
  • cJSON: Ultralightweight JSON parser in ANSI C.
  • ktx: KTX (Khronos Texture) Library and Tools
  • rply: ANSI C Library for PLY file format input and output
  • sc: Portable, stand-alone C libraries and data structures. (C99)
  • stb: stb single-file public domain libraries for C/C++

Credits

A huge thanks to the authors of the following repositories who demonstrated the use of the WebGPU API and how to create a minimal example framework:

References

Roadmap

January 2024 - ...

The list given below summarizes possible examples or functionality that will be added in the future.

Done

License

Open-source under Apache 2.0 license.

webgpu-native-examples's People

Contributors

adamtassier avatar hubbardp avatar samdauwe avatar shrekshao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webgpu-native-examples's Issues

‘WGPURenderPassDepthStencilAttachment’ has no member named ‘clearDepth’

When following the build instructions in the readme the make all step fails on debian bullseye at:

.clearDepth = 1.0f,

error message:

In file included from /home/monkeykong/c/projects/webgpu-native-experiments/webgpu-native-examples/src/webgpu/context.h:4,
                 from /home/monkeykong/c/projects/webgpu-native-experiments/webgpu-native-examples/src/webgpu/context.c:1:
/home/monkeykong/c/projects/webgpu-native-experiments/webgpu-native-examples/build/dawn/gen/include/dawn/webgpu.h:1291:14: note: ‘viewFormatCount’ declared here
 1291 |     uint32_t viewFormatCount;
      |              ^~~~~~~~~~~~~~~
/home/monkeykong/c/projects/webgpu-native-experiments/webgpu-native-examples/src/webgpu/context.c:181:6: error: ‘WGPURenderPassDepthStencilAttachment’ has no member named ‘clearDepth’
  181 |     .clearDepth      = 1.0f,
      |      ^~~~~~~~~~
/home/monkeykong/c/projects/webgpu-native-experiments/webgpu-native-examples/src/webgpu/context.c:182:6: error: ‘WGPURenderPassDepthStencilAttachment’ has no member named ‘clearStencil’
  182 |     .clearStencil    = 0,
      |      ^~~~~~~~~~~~
make[2]: *** [CMakeFiles/wgpu_sample_launcher.dir/build.make:277: CMakeFiles/wgpu_sample_launcher.dir/src/webgpu/context.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1640: CMakeFiles/wgpu_sample_launcher.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

my system info:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Build error of latest commit

Hey friend,

trying to learn from your code.

Tried to build and encountered this error:

[ 87%] Building CXX object CMakeFiles/wgpu_native.dir/lib/wgpu_native/wgpu_native.cpp.o
/home/kai/git/webgpu-native-examples/lib/wgpu_native/wgpu_native.cpp: In function ‘WGPUAdapterImpl* WGPUImpl::RequestAdapter(WGPURequestAdapterOptions*)’:
/home/kai/git/webgpu-native-examples/lib/wgpu_native/wgpu_native.cpp:122:40: error: ‘class dawn::native::Instance’ has no member named ‘EnumerateAdapters’
  122 |     = gpuContext.dawn_native.instance->EnumerateAdapters();
      |                                        ^~~~~~~~~~~~~~~~~
/home/kai/git/webgpu-native-examples/lib/wgpu_native/wgpu_native.cpp: In function ‘void WGPUImpl::LogAvailableAdapters()’:
/home/kai/git/webgpu-native-examples/lib/wgpu_native/wgpu_native.cpp:149:52: error: ‘class dawn::native::Instance’ has no member named ‘EnumerateAdapters’
  149 |   for (auto&& a : gpuContext.dawn_native.instance->EnumerateAdapters()) {
      |                                                    ^~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/wgpu_native.dir/build.make:76: CMakeFiles/wgpu_native.dir/lib/wgpu_native/wgpu_native.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1463: CMakeFiles/wgpu_native.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Any hints would be appreciated a lot!
Lots of love,
Kai

Compilation error

Failing to compile on Linux Mint 21.1

/webgpu-native-examples/src/webgpu/shader.c: In function ‘wgpu_create_shader_module_from_wgsl’:
/webgpu-native-examples/src/webgpu/shader.c:115:6: error: ‘WGPUShaderModuleWGSLDescriptor’ has no member named ‘source’
  115 |     .source = source,
      |      ^~~~~~
make[2]: *** [CMakeFiles/wgpu_sample_launcher.dir/build.make:328: CMakeFiles/wgpu_sample_launcher.dir/src/webgpu/shader.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1510: CMakeFiles/wgpu_sample_launcher.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

did something change with latest Dawn?

Error with run sample

Hi, according to your guide, I has finished the compiler with webgpu-native-samples. But when run it , error accured,

-> error info:
nianrui@oppo:~/webgpu_module/webgpu-native-examples/build/Releasex64$ ./wgpu_sample_launcher triangle
17:19:47 INFO /home/nianrui/webgpu_module/webgpu-native-examples/src/main.c:19: Running example: triangle
GLFW Error occured, Error id: 65544, Description: X11: The DISPLAY environment variable is missing
Failed to initialize GLFW
Error: vkCreateInstance failed with VK_ERROR_INCOMPATIBLE_DRIVER
at CheckVkSuccessImpl (/home/nianrui/webgpu_module/webgpu-native-examples/external/dawn/dawn/src/dawn/native/vulkan/VulkanError.cpp:88)
at CreateVkInstance (/home/nianrui/webgpu_module/webgpu-native-examples/external/dawn/dawn/src/dawn/native/vulkan/BackendVk.cpp:363)
at Initialize (/home/nianrui/webgpu_module/webgpu-native-examples/external/dawn/dawn/src/dawn/native/vulkan/BackendVk.cpp:238)
at Create (/home/nianrui/webgpu_module/webgpu-native-examples/external/dawn/dawn/src/dawn/native/vulkan/BackendVk.cpp:168)
at operator() (/home/nianrui/webgpu_module/webgpu-native-examples/external/dawn/dawn/src/dawn/native/vulkan/BackendVk.cpp:423)

Available adapters:
Null backend ()
deviceID=0, vendorID=0x0, BackendType::Null, AdapterType::CPU
GLFW Error occured, Error id: 65537, Description: The GLFW library is not initialized
GLFW Error occured, Error id: 65537, Description: The GLFW library is not initialized

my environment is :
System: Linux oppo 4.15.0-175-generic #184-Ubuntu SMP Thu Mar 24 17:48:36 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
GPU: 00:02.0 VGA compatible controller: Intel Corporation Device 3e92

Did you met it?

how to support opengl bakend?

I'm using WSL2 Ubuntu on windows11 which can't support vulkan api so far!
I tried to disable vulkan and enable opengl options,but it seems useless.

CMake version mismatched for Dawn

I tried to build examples inside of the docker image like :
bash ./build.sh -webgpu_native_examples

But build procedure suddenly stops by below error :

-- Dawn: using SPIRV-Headers at /webgpu-native-examples/external/dawn/dawn/third_party/vulkan-deps/spirv-headers/src
-- Dawn: using SPIRV-Tools at /webgpu-native-examples/external/dawn/dawn/third_party/vulkan-deps/spirv-tools/src
CMake Error at external/dawn/dawn/third_party/vulkan-deps/spirv-tools/src/CMakeLists.txt:15 (cmake_minimum_required):  CMake 3.17.2 or higher is required.  You are running version 3.16.3

image

I think command for installing more recent version of CMake is required for the docker file

like (it works for me!) :

# Ubuntu 20.04 (Focal Fossa)
FROM ubuntu:20.04

# reference : https://www.softwarepronto.com/2022/09/dockerubuntu-installing-latest-cmake-on.html
RUN apt-get update \
  && apt-get -y install build-essential \
  && apt-get install -y wget \
  && rm -rf /var/lib/apt/lists/* \
  && wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \
      -q -O /tmp/cmake-install.sh \
      && chmod u+x /tmp/cmake-install.sh \
      && mkdir /opt/cmake-3.24.1 \
      && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
      && rm /tmp/cmake-install.sh \
      && ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin

# Install dependencies
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yq \
        sudo \
        wget \
        git ca-certificates openssl \
        # Dev
        pkg-config build-essential python3 \
        # X11 / XCB
        libxi-dev libxcursor-dev libxinerama-dev libxrandr-dev mesa-common-dev \
        xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev \
        # Libav
        libavdevice-dev \
        # Vulkan
        libvulkan1 libvulkan-dev mesa-vulkan-drivers vulkan-utils

# Remove sudoer password
RUN echo "${USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

Compilation error

running bash build.sh

Generate projects using GN
ERROR at //examples/BUILD.gn:29:1: Dependency not allowed.
static_library("dawn_sample_utils") {
^------------------------------------
The item //examples:dawn_sample_utils
can not depend on //src/common:dawn_internal
because it is not in //src/common:dawn_internal's visibility list: [
  //src/*
]

Build Dawn in Release mode (arch: x86_64)
Running ninja
ninja: Entering directory `out-linux-x86_64/Release'
ninja: error: loading 'build.ninja': No such file or directory
Release build for Dawn failed!
Install Dawn headers
include/dawn directory not found, creating...
directory created at include/dawn
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/gen/src/include/dawn/webgpu.h': No such file or directory
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/gen/src/include/dawn/dawn_proc_table.h': No such file or directory
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/gen/src/include/dawn/webgpu_cpp.h': No such file or directory
include/dawn_native directory not found, creating...
directory created at include/dawn_native
Install Dawn shared libraries
lib directory not found, creating...
directory created at lib
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/libc++.so': No such file or directory
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/libdawn_native.so': No such file or directory
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/libdawn_platform.so': No such file or directory
cp: cannot stat '/home/komm/Flush/webgpu-native-examples/external/dawn/dawn/out-linux-x86_64/Release/libdawn_proc.so': No such file or directory

[Help] shader文件读取异常

在定义shader文件后, 使用 FILE API来读取shader文件失败,求大神指教
1. vertex shader 定义

WGPUVertexState vertex_state_desc = wgpu_create_vertex_state(
wgpu_context, &(wgpu_vertex_state_t){
.shader_desc = (wgpu_shader_desc_t){
// Vertex shader SPIR-V
.file = "shaders/compute_boids/shader.vert.spv",
},
...
});

2. shader 文件读取, 问题是, 读到的文件size 是0, 但是file handle也不为NULL

FILE* file = fopen(filename, "rb");
if (file == NULL) {
printf("Unable to open file '%s'\n", filename);
return;
}
fseek(file, 0, SEEK_END);
result->size = ftell(file);
fseek(file, 0, SEEK_SET);
printf("shader_read_file %s, result->size %d\n",filename, result->size);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.