Skip to content

mridulgoyal99/WebGPUAndroidSample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebGPUSample

This project is a basic sample application that demonstrates how to use the WebGPU API for Android within a Jetpack Compose application. It renders a simple, static red triangle on a blue background.

Overview

The purpose of this sample is to provide a clear and minimal example of the setup required to get WebGPU rendering on a surface in an Android app using modern development practices with Kotlin and Jetpack Compose.

How it Works

The application consists of three main components:

  1. MainActivity.kt: The main entry point for the application. It sets up the Jetpack Compose content.

  2. WebGpuSurface.kt: This file contains a Composable function that uses AndroidExternalSurface. This surface is provided to the WebGPU renderer. The rendering logic is launched in a coroutine when the surface is created.

  3. WebGpuRenderer.kt: This is the core of the sample. It handles all the WebGPU API interactions:

    • Initialization: Creates a WebGPU instance, adapter, and device for a given Android Surface.
    • Pipeline Setup: Compiles WGSL (WebGPU Shading Language) shader code and creates a GPURenderPipeline. The shaders in this sample draw a hardcoded triangle.
    • Rendering: The render() function executes the commands to draw a single frame. This includes creating a command encoder, starting a render pass, setting the pipeline, drawing the vertices, and submitting the commands to the device queue.

Code Structure

  • app/src/main/java/com/google/webgpu/webgpusample/
    • MainActivity.kt: The main activity that hosts the Compose UI.
    • WebGpuSurface.kt: The Jetpack Compose component that provides the rendering surface.
    • WebGpuRenderer.kt: The class that encapsulates all WebGPU rendering logic.

Building and Running

  1. Open the project in Android Studio.
  2. Ensure you have a WebGPU-compatible device or emulator selected.
  3. Build and run the application.

Requirements

  • An Android device or emulator with WebGPU support.
  • Android Studio.

Screenshot

Screenshot_20260202_043513

The application displays a single red triangle centered on a blue background.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages