### ComputePass Execution Example Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Example of starting a compute pass, setting a pipeline, and dispatching workgroups. ```go pass := encoder.BeginComputePass(&wgpu.ComputePassDescriptor{ Label: "Compute", }) pass.SetPipeline(computePipeline) pass.DispatchWorkgroups(16, 16, 1) pass.End() ``` -------------------------------- ### Create a ComputePipeline Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Example of initializing a compute pipeline with a compute shader module. ```go pipeline, err := device.CreateComputePipeline(&wgpu.ComputePipelineDescriptor{ Label: "Simulation", Compute: wgpu.ComputeState{ Module: computeShader, EntryPoint: "main", }, }) ``` -------------------------------- ### Create a RenderPipeline Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Example of initializing a render pipeline with vertex and fragment shader configurations. ```go pipeline, err := device.CreateRenderPipeline(&wgpu.RenderPipelineDescriptor{ Label: "Main Pipeline", Vertex: wgpu.VertexState{ Module: vertexShader, EntryPoint: "main", Buffers: []wgpu.VertexBufferLayout{ { ArrayStride: 16, Attributes: []wgpu.VertexAttribute{ {Format: wgpu.VertexFormatFloat32x4, Offset: 0, ShaderLocation: 0}, }, }, }, }, Fragment: &wgpu.FragmentState{ Module: fragmentShader, EntryPoint: "main", Targets: []wgpu.ColorTargetState{ { Format: wgpu.TextureFormatBGRA8Unorm, Blend: &wgpu.BlendStateAlphaBlending, WriteMask: wgpu.ColorWriteMaskAll, }, }, }, }) ``` -------------------------------- ### CreateBindGroupLayout Go Example Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Configures a bind group layout with specific resource entries and shader stage visibility. ```go descriptor := &wgpu.BindGroupLayoutDescriptor{ Label: "Camera Layout", Entries: []wgpu.BindGroupLayoutEntry{ { Binding: 0, Visibility: wgpu.ShaderStageVertex | wgpu.ShaderStageFragment, Buffer: &wgpu.BufferBindingLayout{ Type: wgpu.BufferBindingTypeUniform, }, }, }, } layout, err := device.CreateBindGroupLayout(descriptor) ``` -------------------------------- ### CreateShaderModule Go Example Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a shader module using WGSL source code defined in a descriptor. ```go shaderCode := ` @vertex fn vs_main(@builtin(vertex_index) idx: u32) -> @builtin(position) vec4 { let vertices = array( vec2(-1.0, -1.0), vec2( 1.0, -1.0), vec2( 0.0, 1.0), ); return vec4(vertices[idx], 0.0, 1.0); } @fragment fn fs_main() -> @location(0) vec4 { return vec4(1.0); } ` descriptor := &wgpu.ShaderModuleDescriptor{ Label: "Main Shader", WGSL: &wgpu.ShaderModuleWGSLDescriptor{ Code: shaderCode, }, } module, err := device.CreateShaderModule(descriptor) ``` -------------------------------- ### CreatePipelineLayout Go Example Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Defines a pipeline layout by specifying an array of bind group layouts. ```go descriptor := &wgpu.PipelineLayoutDescriptor{ Label: "Main Pipeline Layout", BindGroupLayouts: []*wgpu.BindGroupLayout{bindGroupLayout0, bindGroupLayout1}, } layout, err := device.CreatePipelineLayout(descriptor) ``` -------------------------------- ### Configure Texture Data Layout Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Example of setting up a texture data layout with the required 256-byte alignment for BytesPerRow. ```go layout := &wgpu.TextureDataLayout{ Offset: 0, BytesPerRow: 256, // Must be multiple of 256 RowsPerImage: height, } ``` -------------------------------- ### Initialize DepthStencilState Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Example of initializing a DepthStencilState struct with specific depth and stencil parameters. ```go depthState := &wgpu.DepthStencilState{ Format: wgpu.TextureFormatDepth32Float, DepthWriteEnabled: true, DepthCompare: wgpu.CompareFunctionLess, StencilFront: wgpu.StencilFaceState{ Compare: wgpu.CompareFunctionAlways, FailOp: wgpu.StencilOperationKeep, DepthFailOp: wgpu.StencilOperationKeep, PassOp: wgpu.StencilOperationIncrementClamp, }, StencilBack: wgpu.StencilFaceState{ Compare: wgpu.CompareFunctionAlways, FailOp: wgpu.StencilOperationKeep, DepthFailOp: wgpu.StencilOperationKeep, PassOp: wgpu.StencilOperationKeep, }, StencilReadMask: 0xFF, StencilWriteMask: 0xFF, } ``` -------------------------------- ### Configure Interleaved Vertex Buffer Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Example of setting up a vertex buffer layout with interleaved position and color data. ```go // Interleaved: position(float32x3) + color(float32x4) bufferLayout := wgpu.VertexBufferLayout{ ArrayStride: 28, // 3*4 + 4*4 StepMode: wgpu.VertexStepModeVertex, Attributes: []wgpu.VertexAttribute{ { Format: wgpu.VertexFormatFloat32x3, Offset: 0, ShaderLocation: 0, // @location(0) in shader }, { Format: wgpu.VertexFormatFloat32x4, Offset: 12, ShaderLocation: 1, // @location(1) in shader }, }, } ``` -------------------------------- ### RenderPassDescriptor Usage Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Example of configuring a render pass with color and depth/stencil attachments. ```go descriptor := &wgpu.RenderPassDescriptor{ Label: "Main Pass", ColorAttachments: []wgpu.RenderPassColorAttachment{ { View: colorView, LoadOp: wgpu.LoadOpClear, StoreOp: wgpu.StoreOpStore, ClearValue: wgpu.ColorBlue, }, }, DepthStencilAttachment: &wgpu.RenderPassDepthStencilAttachment{ View: depthView, DepthLoadOp: wgpu.LoadOpClear, DepthStoreOp: wgpu.StoreOpStore, DepthClearValue: 1.0, }, } pass := encoder.BeginRenderPass(descriptor) ``` -------------------------------- ### Get WebGPU Version Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Retrieves the current version of the WebGPU runtime as a uint32. ```go version := wgpu.GetVersion() ``` -------------------------------- ### GetQueue Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Gets the device's command queue for submitting work. ```APIDOC ## GetQueue ### Description Gets the device's command queue for submitting work. ### Signature `func (p *Device) GetQueue() *Queue` ### Returns - `*Queue` - Device queue ``` -------------------------------- ### Get Device Queue Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Retrieves the command queue for submitting work to the GPU. ```go queue := device.GetQueue() queue.Submit(commandBuffer) ``` -------------------------------- ### CopyBufferToBuffer Usage Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Example of copying data between two buffers with specified offsets and size. ```go err := encoder.CopyBufferToBuffer(srcBuffer, 0, dstBuffer, 256, 1024) ``` -------------------------------- ### GetLimits Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Gets the limits supported by this device. ```APIDOC ## GetLimits ### Description Gets the limits supported by this device. ### Signature `func (p *Device) GetLimits() SupportedLimits` ### Returns - `SupportedLimits` - Device resource limits ``` -------------------------------- ### Initialize WebGPU with Error Handling Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/errors.md Demonstrates how to check for errors when requesting adapters, devices, and creating buffers. ```go package main import ( "log" "github.com/cogentcore/webgpu" ) func main() { // Instance creation panics on failure instance := wgpu.CreateInstance(nil) defer instance.Release() // Adapter request returns error adapter, err := instance.RequestAdapter(nil) if err != nil { log.Fatal("No suitable adapter found") } // Device request returns error device, err := adapter.RequestDevice(nil) if err != nil { log.Fatal("Failed to request device") } defer device.Release() // Buffer creation returns error buf, err := device.CreateBuffer(&wgpu.BufferDescriptor{ Usage: wgpu.BufferUsageUniform, Size: 256, }) if err != nil { log.Fatal("Buffer creation failed:", err) } // Use buffer... } ``` -------------------------------- ### Create WebGPU Surface on Windows Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Initializes a surface using the Windows HWND handle. ```go surfaceDesc := &wgpu.SurfaceDescriptor{ WindowsHWND: &wgpu.SurfaceDescriptorFromWindowsHWND{ Hinstance: unsafe.Pointer(GetModuleHandleW(nil)), Hwnd: unsafe.Pointer(glfwGetWin32Window(window)), }, } surface := instance.CreateSurface(surfaceDesc) ``` -------------------------------- ### Create WebGPU Surface on Linux X11 Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Initializes a surface using Xlib display and window handles. ```go surfaceDesc := &wgpu.SurfaceDescriptor{ XlibWindow: &wgpu.SurfaceDescriptorFromXlibWindow{ Display: unsafe.Pointer(getXDisplay()), Window: uint32(getXWindow()), }, } surface := instance.CreateSurface(surfaceDesc) ``` -------------------------------- ### PushDebugGroup Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Starts a new debug group for nested command annotation. ```APIDOC ## func (p *CommandEncoder) PushDebugGroup(groupLabel string) error ### Description Pushes a debug group for nested command annotation. ### Parameters - **groupLabel** (string) - Required - Label for the group ### Returns - **error** - Validation error if any ``` -------------------------------- ### Render to a Surface in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Initializes the WebGPU instance, configures the surface, and executes a render loop to clear the screen and draw primitives. ```go // Setup instance := wgpu.CreateInstance(nil) adapter, _ := instance.RequestAdapter(nil) device, _ := adapter.RequestDevice(nil) queue := device.GetQueue() surface := instance.CreateSurface(surfaceDesc) // Configure caps := surface.GetCapabilities(adapter) surface.Configure(adapter, device, &wgpu.SurfaceConfiguration{ Usage: wgpu.TextureUsageRenderAttachment, Format: caps.Formats[0], Width: 800, Height: 600, PresentMode: wgpu.PresentModeFifo, }) // Render loop for { texture, _ := surface.GetCurrentTexture() view, _ := texture.CreateView(nil) encoder, _ := device.CreateCommandEncoder(nil) pass := encoder.BeginRenderPass(&wgpu.RenderPassDescriptor{ ColorAttachments: []wgpu.RenderPassColorAttachment{ {View: view, LoadOp: wgpu.LoadOpClear, StoreOp: wgpu.StoreOpStore, ClearValue: wgpu.ColorBlue}, }, }) pass.SetPipeline(pipeline) pass.Draw(3, 1, 0, 0) pass.End() buffer, _ := encoder.Finish(nil) queue.Submit(buffer) surface.Present() view.Release() } ``` -------------------------------- ### GetMappedRange Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/buffers-and-textures.md Gets a slice of the buffer's mapped memory for CPU access. ```APIDOC ## func (p *Buffer) GetMappedRange(offset, size uint) []byte ### Description Gets a slice of the buffer's mapped memory for CPU access. Only available if buffer was created with MappedAtCreation: true or after successful MapAsync. ### Parameters - **offset** (uint) - Required - Byte offset into the buffer - **size** (uint) - Required - Number of bytes to access ### Returns - **[]byte** - Slice of mapped buffer memory ### Example ```go data := buffer.GetMappedRange(0, 64) binary.LittleEndian.PutUint32(data[0:4], 42) buffer.Unmap() ``` ``` -------------------------------- ### Create WebGPU Instance Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Initializes a new WebGPU instance. Can be called with nil for defaults or with an InstanceDescriptor to specify backends and compiler paths. ```go // Create instance with default settings instance := wgpu.CreateInstance(nil) // Create instance with specific backends descriptor := &wgpu.InstanceDescriptor{ Backends: wgpu.InstanceBackendVulkan | wgpu.InstanceBackendMetal, } instance := wgpu.CreateInstance(descriptor) ``` -------------------------------- ### Create WebGPU Surface on Linux Wayland Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Initializes a surface using Wayland display and surface handles. ```go surfaceDesc := &wgpu.SurfaceDescriptor{ WaylandSurface: &wgpu.SurfaceDescriptorFromWaylandSurface{ Display: unsafe.Pointer(getWaylandDisplay()), Surface: unsafe.Pointer(getWaylandSurface()), }, } surface := instance.CreateSurface(surfaceDesc) ``` -------------------------------- ### Get Buffer Size in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/buffers-and-textures.md Retrieves the total size of the buffer in bytes. ```go size := buffer.GetSize() fmt.Printf("Buffer size: %d bytes\n", size) ``` -------------------------------- ### Create a Rendering Surface Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Initialize a surface using platform-specific window handles, such as Windows HWND. ```go // Windows surface from GLFW hwnd := unsafe.Pointer(glfwGetWin32Window(window)) hinstance := unsafe.Pointer(GetModuleHandleW(nil)) surfaceDesc := &wgpu.SurfaceDescriptor{ WindowsHWND: &wgpu.SurfaceDescriptorFromWindowsHWND{ Hinstance: hinstance, Hwnd: hwnd, }, } surface := instance.CreateSurface(surfaceDesc) ``` -------------------------------- ### CreateInstance Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Creates a new WebGPU Instance with optional configuration. ```APIDOC ## func CreateInstance(descriptor *InstanceDescriptor) *Instance ### Description Creates a new WebGPU Instance with optional configuration. Panics if the instance cannot be created. ### Parameters - **descriptor** (*InstanceDescriptor) - Optional - Configuration for instance creation ### Descriptor Fields - **Backends** (InstanceBackend) - Optional - Graphics backends to enable (Vulkan, Metal, D3D12, OpenGL) - **Dx12ShaderCompiler** (Dx12Compiler) - Optional - D3D12 shader compiler selection - **DxilPath** (string) - Optional - Path to DXIL compiler library - **DxcPath** (string) - Optional - Path to DXC compiler library ### Example ```go // Create instance with default settings instance := wgpu.CreateInstance(nil) // Create instance with specific backends descriptor := &wgpu.InstanceDescriptor{ Backends: wgpu.InstanceBackendVulkan | wgpu.InstanceBackendMetal, } instance := wgpu.CreateInstance(descriptor) ``` ``` -------------------------------- ### Create WebGPU Surface on macOS Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Initializes a surface using the Metal layer from an NSView. ```go surfaceDesc := &wgpu.SurfaceDescriptor{ MetalLayer: &wgpu.SurfaceDescriptorFromMetalLayer{ Layer: unsafe.Pointer(getMetalLayerFromNSView(view)), }, } surface := instance.CreateSurface(surfaceDesc) ``` -------------------------------- ### Configure Surface for Rendering Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Initializes the surface with specific dimensions, formats, and presentation modes using a device and adapter. ```go caps := surface.GetCapabilities(adapter) config := &wgpu.SurfaceConfiguration{ Usage: wgpu.TextureUsageRenderAttachment, Format: caps.Formats[0], Width: 800, Height: 600, PresentMode: wgpu.PresentModeMailbox, AlphaMode: wgpu.CompositeAlphaModeOpaque, } surface.Configure(adapter, device, config) ``` -------------------------------- ### Define InstanceDescriptor Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Configuration structure for initializing a WebGPU instance. ```go type InstanceDescriptor struct { Backends InstanceBackend Dx12ShaderCompiler Dx12Compiler DxilPath string DxcPath string } ``` -------------------------------- ### Get Mapped Range in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/buffers-and-textures.md Accesses a slice of the buffer's memory for CPU modification. Requires the buffer to be mapped at creation or via MapAsync. ```go // After CreateBuffer with MappedAtCreation: true data := buffer.GetMappedRange(0, 64) binary.LittleEndian.PutUint32(data[0:4], 42) buffer.Unmap() ``` -------------------------------- ### Create a Command Encoder Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Initializes a command encoder using a descriptor to record GPU commands. ```go descriptor := &wgpu.CommandEncoderDescriptor{ Label: "Main Encoder", } encoder, err := device.CreateCommandEncoder(descriptor) ``` -------------------------------- ### Define Instance struct Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Represents a WebGPU runtime instance. Must be created with CreateInstance() and released with Release(). ```go type Instance struct { ref C.WGPUInstance } ``` -------------------------------- ### Instance.CreateSurface Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Creates a rendering surface from platform-specific window information. ```APIDOC ## func (p *Instance) CreateSurface(descriptor *SurfaceDescriptor) *Surface ### Description Creates a rendering surface from platform-specific window information. ### Parameters - **descriptor** (*SurfaceDescriptor) - Optional - Platform-specific surface configuration ### Descriptor Fields - **Label** (string) - Optional - Human-readable label for debugging - **WindowsHWND** (*SurfaceDescriptorFromWindowsHWND) - Optional - Windows window handle - **XcbWindow** (*SurfaceDescriptorFromXcbWindow) - Optional - XCB window - **XlibWindow** (*SurfaceDescriptorFromXlibWindow) - Optional - Xlib window - **MetalLayer** (*SurfaceDescriptorFromMetalLayer) - Optional - Metal layer - **WaylandSurface** (*SurfaceDescriptorFromWaylandSurface) - Optional - Wayland surface - **AndroidNativeWindow** (*SurfaceDescriptorFromAndroidNativeWindow) - Optional - Android native window ### Returns - (*Surface) - New Surface reference ### Example ```go surfaceDesc := &wgpu.SurfaceDescriptor{ WindowsHWND: &wgpu.SurfaceDescriptorFromWindowsHWND{ Hinstance: hinstance, Hwnd: hwnd, }, } surface := instance.CreateSurface(surfaceDesc) ``` ``` -------------------------------- ### Use WebGPU Colors Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Assigning predefined colors or creating custom color instances. ```go clearValue := wgpu.ColorBlue // Or create custom custom := wgpu.Color{R: 0.5, G: 0.7, B: 0.9, A: 1.0} ``` -------------------------------- ### BeginComputePass Method Definition Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Method signature for initiating a compute shader dispatch pass. ```go func (p *CommandEncoder) BeginComputePass(descriptor *ComputePassDescriptor) *ComputePassEncoder ``` -------------------------------- ### Define SurfaceConfiguration Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Sets up rendering configuration for a surface. ```go type SurfaceConfiguration struct { Usage TextureUsage Format TextureFormat Width uint32 Height uint32 PresentMode PresentMode AlphaMode CompositeAlphaMode ViewFormats []TextureFormat } ``` -------------------------------- ### Configure Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Configures the surface for rendering with the specified adapter, device, and configuration settings. ```APIDOC ## func (p *Surface) Configure(adapter *Adapter, device *Device, config *SurfaceConfiguration) ### Description Configures the surface for rendering with the given device. ### Parameters - **adapter** (*Adapter) - Required - Adapter used to create device - **device** (*Device) - Required - Device for rendering - **config** (*SurfaceConfiguration) - Required - Surface configuration ### Configuration Fields - **Usage** (TextureUsage) - Required - How surface textures will be used - **Format** (TextureFormat) - Required - Texture format (must be from GetCapabilities) - **Width** (uint32) - Required - Surface width in pixels - **Height** (uint32) - Required - Surface height in pixels - **PresentMode** (PresentMode) - Optional - Presentation synchronization (Default: PresentModeFifo) - **AlphaMode** (CompositeAlphaMode) - Optional - Alpha blending mode (Default: CompositeAlphaModeAuto) - **ViewFormats** ([]TextureFormat) - Optional - Alternative view formats ``` -------------------------------- ### Instance.EnumerateAdapters Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Enumerates all available adapters matching optional criteria. ```APIDOC ## func (p *Instance) EnumerateAdapters(options *InstanceEnumerateAdapterOptons) []*Adapter ### Description Enumerates all available adapters matching optional criteria. ### Parameters - **options** (*InstanceEnumerateAdapterOptons) - Optional - Filter criteria for adapters ### Options Fields - **Backends** (InstanceBackend) - Optional - Backend types to enumerate ### Returns - ([]*Adapter) - Slice of matching adapters (nil if none found) ### Example ```go // Enumerate all adapters adapters := instance.EnumerateAdapters(nil) // Enumerate Vulkan adapters only options := &wgpu.InstanceEnumerateAdapterOptons{ Backends: wgpu.InstanceBackendVulkan, } adapters := instance.EnumerateAdapters(options) ``` ``` -------------------------------- ### Power Preference Definitions Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Enumerations for specifying power consumption preferences for adapter selection. ```go const ( PowerPreferenceUndefined PowerPreference = 0x00000000 PowerPreferenceLowPower PowerPreference = 0x00000001 PowerPreferenceHighPerformance PowerPreference = 0x00000002 ) ``` -------------------------------- ### Request a WebGPU Adapter Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Use RequestAdapter to obtain an adapter based on specific power or compatibility requirements. ```go options := &wgpu.RequestAdapterOptions{ PowerPreference: wgpu.PowerPreferenceHighPerformance, CompatibleSurface: surface, } adapter, err := instance.RequestAdapter(options) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Create a GPU Buffer Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Defines a buffer configuration using BufferDescriptor and initializes it via the device. ```go descriptor := &wgpu.BufferDescriptor{ Label: "Vertex Buffer", Usage: wgpu.BufferUsageVertex | wgpu.BufferUsageCopyDst, Size: 8192, } buffer, err := device.CreateBuffer(descriptor) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Define BufferInitDescriptor Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Parameters for creating and initializing a buffer with data. ```go type BufferInitDescriptor struct { Label string Contents []byte Usage BufferUsage } ``` -------------------------------- ### Enumerate Available Adapters Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Retrieve a list of available adapters, optionally filtered by backend type. ```go // Enumerate all adapters adapters := instance.EnumerateAdapters(nil) // Enumerate Vulkan adapters only options := &wgpu.InstanceEnumerateAdapterOptons{ Backends: wgpu.InstanceBackendVulkan, } adapters := instance.EnumerateAdapters(options) ``` -------------------------------- ### CreateSampler Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a sampler for texture sampling configuration. ```go func (p *Device) CreateSampler(descriptor *SamplerDescriptor) (*Sampler, error) ``` ```go descriptor := &wgpu.SamplerDescriptor{ Label: "Linear Sampler", MagFilter: wgpu.FilterModeLinear, MinFilter: wgpu.FilterModeLinear, MipmapFilter: wgpu.MipmapFilterModeLinear, } sampler, err := device.CreateSampler(descriptor) ``` -------------------------------- ### CreateBufferInit Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a GPU buffer initialized with the provided data. ```APIDOC ## func (p *Device) CreateBufferInit(descriptor *BufferInitDescriptor) (*Buffer, error) ### Description Creates a GPU buffer initialized with data. ### Parameters - **descriptor** (*BufferInitDescriptor) - Required - Buffer initialization config ### Descriptor Fields - **Label** (string) - Optional - Human-readable label - **Contents** ([]byte) - Required - Data to initialize buffer with - **Usage** (BufferUsage) - Required - How the buffer will be used ### Returns - (*Buffer, error) - Initialized buffer or error ``` -------------------------------- ### Adapter Type Definitions Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Enumerations for classifying GPU adapters. ```go const ( AdapterTypeDiscreteGPU AdapterType = 0x00000000 AdapterTypeIntegratedGPU AdapterType = 0x00000001 AdapterTypeCPU AdapterType = 0x00000002 AdapterTypeUnknown AdapterType = 0x00000003 ) ``` -------------------------------- ### Instance Backend Flags Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Flags used to enable specific graphics backends. ```go const ( InstanceBackendAll InstanceBackend = 0x0000000F InstanceBackendVulkan InstanceBackend = 0x00000001 InstanceBackendMetal InstanceBackend = 0x00000002 InstanceBackendDx12 InstanceBackend = 0x00000004 InstanceBackendGl InstanceBackend = 0x00000008 ) ``` -------------------------------- ### CreateRenderPipeline Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a render pipeline for 3D graphics rendering. ```go func (p *Device) CreateRenderPipeline(descriptor *RenderPipelineDescriptor) (*RenderPipeline, error) ``` -------------------------------- ### Retrieve adapter information in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Fetches metadata about the adapter, such as vendor, device name, and backend type. ```go info := adapter.GetInfo() fmt.Printf("Adapter: %s (%s)\n", info.Name, info.VendorName) fmt.Printf("Type: %s Backend: %s\n", info.AdapterType.String(), info.BackendType.String()) ``` -------------------------------- ### CreateComputePipeline Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a compute pipeline for compute shader execution. ```go func (p *Device) CreateComputePipeline(descriptor *ComputePipelineDescriptor) (*ComputePipeline, error) ``` -------------------------------- ### Define Version Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Represents the runtime version number. ```go type Version uint32 ``` -------------------------------- ### Define AdapterInfo Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Structure containing adapter metadata. ```go type AdapterInfo struct { VendorId uint32 VendorName string Architecture string DeviceId uint32 Name string DriverDescription string AdapterType AdapterType BackendType BackendType } ``` -------------------------------- ### Define DeviceDescriptor Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Configuration parameters for creating a logical WebGPU device. ```go type DeviceDescriptor struct { Label string RequiredFeatures []FeatureName RequiredLimits *RequiredLimits DeviceLostCallback DeviceLostCallback TracePath string } ``` -------------------------------- ### Instance.RequestAdapter Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Requests an adapter that meets the specified requirements. ```APIDOC ## func (p *Instance) RequestAdapter(options *RequestAdapterOptions) (*Adapter, error) ### Description Requests an adapter that meets the specified requirements. ### Parameters - **options** (*RequestAdapterOptions) - Optional - Selection criteria for the adapter ### Options Fields - **CompatibleSurface** (*Surface) - Optional - Surface the adapter must be compatible with - **PowerPreference** (PowerPreference) - Optional - Preference for power consumption vs performance - **ForceFallbackAdapter** (bool) - Optional - Force use of fallback adapter if preferred one unavailable - **BackendType** (BackendType) - Optional - Specific backend to request ### Returns - (*Adapter, error) - Adapter reference or error ### Example ```go options := &wgpu.RequestAdapterOptions{ PowerPreference: wgpu.PowerPreferenceHighPerformance, CompatibleSurface: surface, } adapter, err := instance.RequestAdapter(options) ``` ``` -------------------------------- ### Queue.Submit Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Submits a variable-length list of command buffers to the GPU for execution and returns a submission index for synchronization. ```APIDOC ## func (p *Queue) Submit(commands ...*CommandBuffer) SubmissionIndex ### Description Submits command buffers to the GPU for execution. ### Parameters - **commands** (...*CommandBuffer) - Optional - Variable-length list of command buffers ### Returns - **SubmissionIndex** - Index of the submission for synchronization ``` -------------------------------- ### CreateBindGroup Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a bind group that binds resources to a layout. ```go func (p *Device) CreateBindGroup(descriptor *BindGroupDescriptor) (*BindGroup, error) ``` -------------------------------- ### Define RenderBundle struct Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Prerecorded render commands. Created with Device.CreateRenderBundleEncoder(). Executed with ExecuteBundles(). ```go type RenderBundle struct { ref C.WGPURenderBundle } ``` -------------------------------- ### Draw Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Records a draw command with indexed vertices. ```go func (p *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32) ``` -------------------------------- ### Enumerate adapter features in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Retrieves a slice of all features supported by the adapter. ```go features := adapter.EnumerateFeatures() for _, feature := range features { fmt.Println(feature.String()) } ``` -------------------------------- ### Define WebGPU Colors Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Predefined color constants available in wgpu/wgpu_ext.go. ```go var ( ColorTransparent = Color{0, 0, 0, 0} // Transparent black ColorBlack = Color{0, 0, 0, 1} // Opaque black ColorWhite = Color{1, 1, 1, 1} // Opaque white ColorRed = Color{1, 0, 0, 1} // Opaque red ColorGreen = Color{0, 1, 0, 1} // Opaque green ColorBlue = Color{0, 0, 1, 1} // Opaque blue ) ``` -------------------------------- ### WebGPU API Surface Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/INDEX.md The core API surface for interacting with WebGPU, covering initialization, resource creation, command recording, and execution. ```APIDOC ## WebGPU API Reference ### Initialization - `CreateInstance` -> `Instance` - `Instance.RequestAdapter` -> `Adapter` - `Instance.CreateSurface` -> `Surface` - `Adapter.RequestDevice` -> `Device` ### Resources - `Device.CreateBuffer` -> `Buffer` - `Device.CreateTexture` -> `Texture` - `Device.CreateShaderModule` -> `ShaderModule` - `Device.CreateRenderPipeline` -> `RenderPipeline` - `Device.CreateComputePipeline` -> `ComputePipeline` - `Device.CreateSampler` -> `Sampler` - `Device.CreateCommandEncoder` -> `CommandEncoder` ### Command Recording - `CommandEncoder.BeginRenderPass` -> `RenderPassEncoder` - `CommandEncoder.BeginComputePass` -> `ComputePassEncoder` - `RenderPassEncoder/ComputePassEncoder.End` -> `void` - `CommandEncoder.Finish` -> `CommandBuffer` ### Execution - `Device.GetQueue` -> `Queue` - `Queue.Submit(CommandBuffer...)` -> `SubmissionIndex` - `Surface.GetCurrentTexture` -> `Texture` - `Surface.Present()` -> `void` ``` -------------------------------- ### Retrieve adapter limits in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Fetches the hardware limits and constraints supported by the adapter. ```go limits := adapter.GetLimits() fmt.Printf("Max texture dimension 2D: %d\n", limits.Limits.MaxTextureDimension2D) fmt.Printf("Max buffers: %d\n", limits.Limits.MaxBufferSize) ``` -------------------------------- ### Release Instance Resources Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Cleans up the instance and all associated resources. Typically used with defer to ensure cleanup upon function exit. ```go func (p *Instance) Release() ``` ```go defer instance.Release() ``` -------------------------------- ### Check for adapter feature support in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Verifies if a specific feature is supported by the adapter. ```go if adapter.HasFeature(wgpu.FeatureNameIndirectFirstInstance) { fmt.Println("Indirect first instance rendering supported") } ``` -------------------------------- ### SetViewport Method Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Sets the viewport for rendering. ```go func (p *RenderPassEncoder) SetViewport(x, y, width, height, minDepth, maxDepth float32) ``` -------------------------------- ### Configure Over Blend Component Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Blend component for standard alpha compositing. ```go var BlendComponentOver = BlendComponent{ SrcFactor: BlendFactorOne, DstFactor: BlendFactorOneMinusSrcAlpha, Operation: BlendOperationAdd, } ``` -------------------------------- ### GetCapabilities Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Queries the capabilities of the surface for a given adapter, returning supported formats and modes. ```APIDOC ## func (p *Surface) GetCapabilities(adapter *Adapter) SurfaceCapabilities ### Description Gets the capabilities of the surface with the given adapter. ### Parameters - **adapter** (*Adapter) - Required - Adapter to query capabilities for ### Returns - **SurfaceCapabilities** - Supported formats and modes ``` -------------------------------- ### Create an Initialized GPU Buffer Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a buffer pre-populated with data, which is automatically padded and unmapped after initialization. ```go data := []byte{1, 2, 3, 4, 5, 6, 7, 8} descriptor := &wgpu.BufferInitDescriptor{ Label: "Index Buffer", Contents: data, Usage: wgpu.BufferUsageIndex | wgpu.BufferUsageCopySrc, } buffer, err := device.CreateBufferInit(descriptor) ``` -------------------------------- ### Create a Texture View in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/buffers-and-textures.md Configures a texture view using a descriptor to specify dimensions, format, and mipmap levels. ```go func (p *Texture) CreateView(descriptor *TextureViewDescriptor) (*TextureView, error) ``` ```go descriptor := &wgpu.TextureViewDescriptor{ Label: "Main View", Dimension: wgpu.TextureViewDimension2D, Format: wgpu.TextureFormatRGBA8Unorm, } view, err := texture.CreateView(descriptor) ``` -------------------------------- ### Define Limits Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Structure defining GPU resource limits. ```go type Limits struct { MaxTextureDimension1D uint32 MaxTextureDimension2D uint32 MaxTextureDimension3D uint32 MaxTextureArrayLayers uint32 MaxBindGroups uint32 MaxBindingsPerBindGroup uint32 MaxDynamicUniformBuffersPerPipelineLayout uint32 MaxDynamicStorageBuffersPerPipelineLayout uint32 MaxSampledTexturesPerShaderStage uint32 MaxSamplersPerShaderStage uint32 MaxStorageBuffersPerShaderStage uint32 MaxStorageTexturesPerShaderStage uint32 MaxUniformBuffersPerShaderStage uint32 MaxUniformBufferBindingSize uint64 MaxStorageBufferBindingSize uint64 MinUniformBufferOffsetAlignment uint32 MinStorageBufferOffsetAlignment uint32 MaxVertexBuffers uint32 MaxBufferSize uint64 MaxVertexAttributes uint32 MaxVertexBufferArrayStride uint32 MaxInterStageShaderComponents uint32 MaxInterStageShaderVariables uint32 MaxColorAttachments uint32 MaxColorAttachmentBytesPerSample uint32 MaxComputeWorkgroupStorageSize uint32 MaxComputeInvocationsPerWorkgroup uint32 MaxComputeWorkgroupSizeX uint32 MaxComputeWorkgroupSizeY uint32 MaxComputeWorkgroupSizeZ uint32 MaxComputeWorkgroupsPerDimension uint32 MaxPushConstantSize uint32 } ``` -------------------------------- ### Upload Texture Data Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Creates a texture resource and uploads raw image data to the GPU using WriteTexture. ```go imageData := loadImageFile("texture.png") // []byte texture, _ := device.CreateTexture(&wgpu.TextureDescriptor{ Usage: wgpu.TextureUsageCopyDst | wgpu.TextureUsageTextureBinding, Size: wgpu.Extent3D{Width: 256, Height: 256, DepthOrArrayLayers: 1}, Format: wgpu.TextureFormatRGBA8Unorm, }) err := queue.WriteTexture( &wgpu.ImageCopyTexture{Texture: texture, Aspect: wgpu.TextureAspectAll}, imageData, &wgpu.TextureDataLayout{ Offset: 0, BytesPerRow: 256 * 4, RowsPerImage: 256, }, &wgpu.Extent3D{Width: 256, Height: 256, DepthOrArrayLayers: 1}, ) ``` -------------------------------- ### Submit Command Buffers in Go Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Submits a variable-length list of command buffers to the GPU and returns a submission index for synchronization. ```go func (p *Queue) Submit(commands ...*CommandBuffer) SubmissionIndex ``` ```go idx := queue.Submit(buffer1, buffer2) fmt.Printf("Submitted batch: %d\n", idx) ``` -------------------------------- ### Query Surface Capabilities Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Retrieves supported formats and modes for the surface. The SurfaceCapabilities struct defines the available options. ```go type SurfaceCapabilities struct { Formats []TextureFormat // Supported texture formats PresentModes []PresentMode // Supported present modes AlphaModes []CompositeAlphaMode // Supported alpha modes } ``` ```go caps := surface.GetCapabilities(adapter) fmt.Printf("Supported formats: %d\n", len(caps.Formats)) for _, format := range caps.Formats { fmt.Printf(" %s\n", format.String()) } ``` -------------------------------- ### Execute a Compute Shader Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/README.md Compiles a WGSL compute shader, creates a pipeline, and dispatches workgroups to the GPU. ```go computeShader, _ := device.CreateShaderModule(&wgpu.ShaderModuleDescriptor{ WGSL: &wgpu.ShaderModuleWGSLDescriptor{ Code: `@compute @workgroup_size(16, 16) fn main(@builtin(global_invocation_id) id: vec3) { // computation }`, }, }) pipeline, _ := device.CreateComputePipeline(&wgpu.ComputePipelineDescriptor{ Compute: wgpu.ComputeState{Module: computeShader}, }) encoder, _ := device.CreateCommandEncoder(nil) pass := encoder.BeginComputePass(nil) pass.SetPipeline(pipeline) pass.DispatchWorkgroups(256, 256, 1) pass.End() buffer, _ := encoder.Finish(nil) queue.Submit(buffer) ``` -------------------------------- ### Define Surface struct Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Rendering output target. Created with Instance.CreateSurface(). Configured with Surface.Configure(). ```go type Surface struct { deviceRef C.WGPUDevice ref C.WGPUSurface } ``` -------------------------------- ### Create a GPU Texture Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Configures a texture with specific dimensions, format, and usage flags for rendering or binding. ```go descriptor := &wgpu.TextureDescriptor{ Label: "Screen Texture", Usage: wgpu.TextureUsageRenderAttachment | wgpu.TextureUsageTextureBinding, Size: wgpu.Extent3D{ Width: 800, Height: 600, DepthOrArrayLayers: 1, }, Format: wgpu.TextureFormatBGRA8Unorm, MipLevelCount: 1, SampleCount: 1, } texture, err := device.CreateTexture(descriptor) ``` -------------------------------- ### Generate WebGPU Resource Report Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Retrieves allocation statistics for the runtime. Access specific backend details via the returned GlobalReport structure. ```go func (p *Instance) GenerateReport() GlobalReport ``` ```go type GlobalReport struct { Surfaces RegistryReport Vulkan *HubReport // nil if backend not in use Metal *HubReport // nil if backend not in use Dx12 *HubReport // nil if backend not in use Dx11 *HubReport // nil if backend not in use Gl *HubReport // nil if backend not in use } type HubReport struct { Adapters RegistryReport Devices RegistryReport PipelineLayouts RegistryReport ShaderModules RegistryReport BindGroupLayouts RegistryReport BindGroups RegistryReport CommandBuffers RegistryReport RenderBundles RegistryReport RenderPipelines RegistryReport ComputePipelines RegistryReport QuerySets RegistryReport Buffers RegistryReport Textures RegistryReport TextureViews RegistryReport Samplers RegistryReport } type RegistryReport struct { NumAllocated uint64 NumKeptFromUser uint64 NumReleasedFromUser uint64 NumError uint64 ElementSize uint64 } ``` ```go report := instance.GenerateReport() fmt.Printf("Allocated buffers: %d\n", report.Vulkan.Buffers.NumAllocated) ``` -------------------------------- ### Define SupportedLimits Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Structure wrapping adapter-supported limits. ```go type SupportedLimits struct { Limits Limits } ``` -------------------------------- ### Define Adapter struct Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Represents a specific GPU device. Obtained from Instance.RequestAdapter() or Instance.EnumerateAdapters(). ```go type Adapter struct { ref C.WGPUAdapter } ``` -------------------------------- ### Define BufferDescriptor Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Parameters for creating a GPU buffer. ```go type BufferDescriptor struct { Label string Usage BufferUsage Size uint64 MappedAtCreation bool } ``` -------------------------------- ### GetVersion Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Returns the version of the WebGPU runtime. ```APIDOC ## func GetVersion() Version ### Description Returns the version of the WebGPU runtime. ### Returns - **Version** (uint32) - The runtime version. ### Example ```go version := wgpu.GetVersion() ``` ``` -------------------------------- ### CreateComputePipeline Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a compute pipeline for compute shader execution. ```APIDOC ## func (p *Device) CreateComputePipeline(descriptor *ComputePipelineDescriptor) (*ComputePipeline, error) ### Description Creates a compute pipeline for compute shader execution. ### Parameters - **descriptor** (*ComputePipelineDescriptor) - Required - Pipeline configuration ### Returns - (*ComputePipeline, error) - Compute pipeline or error ``` -------------------------------- ### CreateShaderModule Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a shader module from WGSL source code or SPIR-V bytecode. ```APIDOC ## func (p *Device) CreateShaderModule(descriptor *ShaderModuleDescriptor) (*ShaderModule, error) ### Description Creates a shader module from WGSL source code or SPIR-V bytecode. ### Parameters - **descriptor** (*ShaderModuleDescriptor) - Required - Shader configuration ### Descriptor Fields - **Label** (string) - Optional - Human-readable label - **WGSL** (*ShaderModuleWGSLDescriptor) - Optional - WGSL source - **SPIRV** (*ShaderModuleSPIRVDescriptor) - Optional - SPIR-V bytecode ### Returns - (*ShaderModule, error) - Shader module or error ``` -------------------------------- ### Queue.Release Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Releases the reference to the GPU queue. ```APIDOC ## func (p *Queue) Release() ### Description Releases the queue reference. ``` -------------------------------- ### CreateSampler Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/device.md Creates a sampler for texture sampling configuration. ```APIDOC ## func (p *Device) CreateSampler(descriptor *SamplerDescriptor) (*Sampler, error) ### Description Creates a sampler for texture sampling configuration. ### Parameters - **descriptor** (*SamplerDescriptor) - Required - Sampler configuration ### Returns - (*Sampler, error) - Sampler or error ``` -------------------------------- ### Define RequestAdapterOptions Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Criteria used for selecting a suitable WebGPU adapter. ```go type RequestAdapterOptions struct { CompatibleSurface *Surface PowerPreference PowerPreference ForceFallbackAdapter bool BackendType BackendType } ``` -------------------------------- ### Device.CreateRenderPipeline Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Creates a new render pipeline using the provided RenderPipelineDescriptor configuration. ```APIDOC ## Device.CreateRenderPipeline ### Description Creates a new render pipeline for rasterization-based rendering based on the provided descriptor. ### Parameters - **descriptor** (RenderPipelineDescriptor) - Required - Configuration object containing vertex, fragment, and primitive states. ### Example ```go pipeline, err := device.CreateRenderPipeline(&wgpu.RenderPipelineDescriptor{ Label: "Main Pipeline", Vertex: wgpu.VertexState{ Module: vertexShader, EntryPoint: "main", Buffers: []wgpu.VertexBufferLayout{ { ArrayStride: 16, Attributes: []wgpu.VertexAttribute{ {Format: wgpu.VertexFormatFloat32x4, Offset: 0, ShaderLocation: 0}, }, }, }, }, Fragment: &wgpu.FragmentState{ Module: fragmentShader, EntryPoint: "main", Targets: []wgpu.ColorTargetState{ { Format: wgpu.TextureFormatBGRA8Unorm, Blend: &wgpu.BlendStateAlphaBlending, WriteMask: wgpu.ColorWriteMaskAll, }, }, }, }) ``` ``` -------------------------------- ### D3D12 Compiler Selection Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Enumeration for selecting the shader compiler for D3D12. ```go const ( Dx12CompilerFxc Dx12Compiler = 0x00000000 Dx12CompilerDxc Dx12Compiler = 0x00000001 ) ``` -------------------------------- ### Define SamplerBindingType Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Specifies sampler binding types. ```go const ( SamplerBindingTypeUndefined SamplerBindingType = 0x00000000 SamplerBindingTypeFiltering SamplerBindingType = 0x00000001 SamplerBindingTypeNonFiltering SamplerBindingType = 0x00000002 SamplerBindingTypeComparison SamplerBindingType = 0x00000003 ) ``` -------------------------------- ### Define VertexState Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Configuration structure for vertex shader stages. ```go type VertexState struct { Module *ShaderModule EntryPoint string Buffers []VertexBufferLayout } ``` -------------------------------- ### Configure Premultiplied Alpha Blending State Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Blend state configuration for premultiplied alpha textures. ```go var BlendStatePremultipliedAlphaBlending = BlendState{ Color: BlendComponentOver, Alpha: BlendComponentOver, } ``` -------------------------------- ### Define BindGroup struct Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/types.md Resource bindings. Created with Device.CreateBindGroup(). Set with SetBindGroup() in passes. ```go type BindGroup struct { ref C.WGPUBindGroup } ``` -------------------------------- ### Present Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/queue-and-surface.md Presents the rendered content to the display. This must be called once per frame after rendering. ```APIDOC ## func (p *Surface) Present() ### Description Presents the rendered content to the display. This method invalidates the texture returned by GetCurrentTexture. ``` -------------------------------- ### GetInfo Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/instance-and-adapter.md Retrieves metadata about this adapter. ```APIDOC ## func (p *Adapter) GetInfo() AdapterInfo ### Description Retrieves metadata about this adapter. ### Returns - **AdapterInfo** - Adapter metadata ### Example ```go info := adapter.GetInfo() fmt.Printf("Adapter: %s (%s)\n", info.Name, info.VendorName) fmt.Printf("Type: %s Backend: %s\n", info.AdapterType.String(), info.BackendType.String()) ``` ``` -------------------------------- ### Device.CreateComputePipeline Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/pipelines.md Creates a new compute pipeline using the provided ComputePipelineDescriptor configuration. ```APIDOC ## Device.CreateComputePipeline ### Description Creates a new compute pipeline for compute shader execution based on the provided descriptor. ### Parameters - **descriptor** (ComputePipelineDescriptor) - Required - Configuration object containing the compute stage state. ### Example ```go pipeline, err := device.CreateComputePipeline(&wgpu.ComputePipelineDescriptor{ Label: "Simulation", Compute: wgpu.ComputeState{ Module: computeShader, EntryPoint: "main", }, }) ``` ``` -------------------------------- ### Configure Alpha Blending State Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/configuration.md Blend state configuration for typical transparency. ```go var BlendStateAlphaBlending = BlendState{ Color: BlendComponent{ SrcFactor: BlendFactorSrcAlpha, DstFactor: BlendFactorOneMinusSrcAlpha, Operation: BlendOperationAdd, }, Alpha: BlendComponentOver, } ``` -------------------------------- ### Record CopyTextureToTexture command Source: https://github.com/cogentcore/webgpu/blob/main/_autodocs/api-reference/command-encoding-and-rendering.md Records a texture-to-texture copy command. ```go func (p *CommandEncoder) CopyTextureToTexture(source *ImageCopyTexture, destination *ImageCopyTexture, copySize *Extent3D) error ```