Documentation
¶
Overview ¶
Package browser implements the WebGPU backend for browsers using syscall/js.
This package delegates all GPU operations to the browser's native WebGPU API (navigator.gpu) via JavaScript interop. It is only compiled on GOOS=js GOARCH=wasm.
Architecture: each Go type (Instance, Adapter, Device, Queue) wraps a js.Value reference to the corresponding GPUInstance / GPUAdapter / GPUDevice / GPUQueue JavaScript object. Methods are pre-bound at construction time to avoid repeated property lookups on the hot path (Ebiten pattern).
No core/ or hal/ packages are used — the browser validates GPU operations itself.
Index ¶
- Variables
- func AddressModeToJS(m gputypes.AddressMode) string
- func AwaitPromise(promise js.Value) (js.Value, error)
- func BlendFactorToJS(f gputypes.BlendFactor) string
- func BlendOperationToJS(op gputypes.BlendOperation) string
- func BufferBindingTypeToJS(t gputypes.BufferBindingType) string
- func BuildBindGroupDescriptor(label string, layoutRef js.Value, entries []BindGroupEntryJS) js.Value
- func BuildBindGroupLayoutDescriptor(label string, entries []BindGroupLayoutEntryJS) js.Value
- func BuildBufferDescriptor(label string, size uint64, usage uint64, mappedAtCreation bool) js.Value
- func BuildColorDict(r, g, b, a float64) js.Value
- func BuildCommandEncoderDescriptor(label string) js.Value
- func BuildComputePassDescriptor(label string) js.Value
- func BuildComputePipelineDescriptor(label string, layoutRef js.Value, moduleRef js.Value, entryPoint string) js.Value
- func BuildDeviceDescriptor(label string, requiredFeatures gputypes.Features, ...) js.Value
- func BuildExtent3D(width, height, depthOrArrayLayers uint32) js.Value
- func BuildImageCopyBuffer(buffer js.Value, offset uint64, bytesPerRow, rowsPerImage uint32) js.Value
- func BuildImageCopyTexture(texture js.Value, mipLevel uint32, originX, originY, originZ uint32) js.Value
- func BuildPipelineLayoutDescriptor(label string, layoutRefs []js.Value) js.Value
- func BuildRenderPassDescriptor(label string, colorAttachments []RenderPassColorAttachmentJS, ...) js.Value
- func BuildRenderPipelineDescriptor(desc *RenderPipelineDescriptorJS) js.Value
- func BuildRequestAdapterOptions(powerPreference gputypes.PowerPreference, forceFallback bool) js.Value
- func BuildSamplerDescriptor(label string, addressModeU, addressModeV, addressModeW gputypes.AddressMode, ...) js.Value
- func BuildShaderModuleDescriptor(label string, code string) js.Value
- func BuildSurfaceConfiguration(deviceRef js.Value, format gputypes.TextureFormat, usage gputypes.TextureUsage, ...) js.Value
- func BuildTexelCopyBufferLayout(offset uint64, bytesPerRow, rowsPerImage uint32) js.Value
- func BuildTextureDescriptor(label string, width, height, depthOrArrayLayers uint32, ...) js.Value
- func BuildTextureViewDescriptor(label string, format gputypes.TextureFormat, ...) js.Value
- func CompareFunctionToJS(f gputypes.CompareFunction) string
- func CompositeAlphaModeToJS(mode gputypes.CompositeAlphaMode) string
- func CullModeToJS(m gputypes.CullMode) string
- func ExtractFeatures(supported js.Value) gputypes.Features
- func ExtractLimits(jsLimits js.Value) gputypes.Limits
- func FilterModeToJS(m gputypes.FilterMode) string
- func FrontFaceToJS(f gputypes.FrontFace) string
- func GPUAvailable() bool
- func IndexFormatToJS(f gputypes.IndexFormat) string
- func LoadOpToJS(op gputypes.LoadOp) string
- func PowerPreferenceToJS(pref gputypes.PowerPreference) string
- func PresentModeToJS(mode gputypes.PresentMode) string
- func PrimitiveTopologyToJS(t gputypes.PrimitiveTopology) string
- func SamplerBindingTypeToJS(t gputypes.SamplerBindingType) string
- func StencilOperationToJS(op gputypes.StencilOperation) string
- func StorageTextureAccessToJS(a gputypes.StorageTextureAccess) string
- func StoreOpToJS(op gputypes.StoreOp) string
- func TextureAspectToJS(a gputypes.TextureAspect) string
- func TextureDimensionToJS(d gputypes.TextureDimension) string
- func TextureFormatFromJS(s string) gputypes.TextureFormat
- func TextureFormatToJS(f gputypes.TextureFormat) string
- func TextureSampleTypeToJS(t gputypes.TextureSampleType) string
- func TextureViewDimensionToJS(d gputypes.TextureViewDimension) string
- func VertexFormatToJS(f gputypes.VertexFormat) string
- func VertexStepModeToJS(m gputypes.VertexStepMode) string
- type Adapter
- type BindGroup
- type BindGroupEntryJS
- type BindGroupLayout
- type BindGroupLayoutEntryJS
- type BlendComponentJS
- type BlendStateJS
- type Buffer
- func (b *Buffer) Destroy()
- func (b *Buffer) GetMappedRangeBytes(offset, size uint64) ([]byte, error)
- func (b *Buffer) MapAsync(mode uint32, offset, size uint64) error
- func (b *Buffer) Ref() js.Value
- func (b *Buffer) SetMappedAtCreation()
- func (b *Buffer) Size() uint64
- func (b *Buffer) Unmap()
- func (b *Buffer) Usage() uint32
- func (b *Buffer) WriteMappedRange(offset uint64, data []byte) error
- type BufferBindingLayoutJS
- type ColorTargetStateJS
- type CommandBuffer
- type CommandEncoder
- func (e *CommandEncoder) BeginComputePass(desc js.Value) *ComputePassEncoder
- func (e *CommandEncoder) BeginRenderPass(desc js.Value) *RenderPassEncoder
- func (e *CommandEncoder) ClearBuffer(buffer js.Value, offset, size uint64)
- func (e *CommandEncoder) CopyBufferToBuffer(src js.Value, srcOffset uint64, dst js.Value, dstOffset uint64, size uint64)
- func (e *CommandEncoder) CopyBufferToTexture(source, destination, copySize js.Value)
- func (e *CommandEncoder) CopyTextureToBuffer(source, destination, copySize js.Value)
- func (e *CommandEncoder) CopyTextureToTexture(source, destination, copySize js.Value)
- func (e *CommandEncoder) Finish(desc js.Value) *CommandBuffer
- func (e *CommandEncoder) Ref() js.Value
- type ComputePassEncoder
- func (p *ComputePassEncoder) DispatchIndirect(buffer js.Value, offset uint64)
- func (p *ComputePassEncoder) DispatchWorkgroups(x, y, z uint32)
- func (p *ComputePassEncoder) End()
- func (p *ComputePassEncoder) Ref() js.Value
- func (p *ComputePassEncoder) SetBindGroup(index uint32, group js.Value, dynamicOffsets []uint32)
- func (p *ComputePassEncoder) SetPipeline(pipeline js.Value)
- type ComputePipeline
- type DepthStencilStateJS
- type Device
- func (d *Device) CreateBindGroup() js.Value
- func (d *Device) CreateBindGroupFromDesc(desc js.Value) *BindGroup
- func (d *Device) CreateBindGroupLayout() js.Value
- func (d *Device) CreateBindGroupLayoutFromDesc(desc js.Value) *BindGroupLayout
- func (d *Device) CreateBuffer() js.Value
- func (d *Device) CreateBufferFromDesc(desc js.Value) *Buffer
- func (d *Device) CreateCommandEncoder() js.Value
- func (d *Device) CreateComputePipeline() js.Value
- func (d *Device) CreateComputePipelineFromDesc(desc js.Value) *ComputePipeline
- func (d *Device) CreatePipelineLayout() js.Value
- func (d *Device) CreatePipelineLayoutFromDesc(desc js.Value) *PipelineLayout
- func (d *Device) CreateQuerySet() js.Value
- func (d *Device) CreateRenderPipeline() js.Value
- func (d *Device) CreateRenderPipelineFromDesc(desc js.Value) *RenderPipeline
- func (d *Device) CreateSampler() js.Value
- func (d *Device) CreateSamplerFromDesc(desc js.Value) *Sampler
- func (d *Device) CreateShaderModule() js.Value
- func (d *Device) CreateShaderModuleFromDesc(desc js.Value) *ShaderModule
- func (d *Device) CreateTexture() js.Value
- func (d *Device) CreateTextureFromDesc(desc js.Value) *Texture
- func (d *Device) Destroy()
- func (d *Device) Features() js.Value
- func (d *Device) Limits() js.Value
- func (d *Device) Queue() *Queue
- func (d *Device) Ref() js.Value
- type FragmentStateJS
- type Instance
- type JSError
- type MultisampleStateJS
- type PipelineLayout
- type PrimitiveStateJS
- type Queue
- type RenderPassColorAttachmentJS
- type RenderPassDepthStencilAttachmentJS
- type RenderPassEncoder
- func (p *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
- func (p *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, ...)
- func (p *RenderPassEncoder) DrawIndexedIndirect(buffer js.Value, offset uint64)
- func (p *RenderPassEncoder) DrawIndirect(buffer js.Value, offset uint64)
- func (p *RenderPassEncoder) End()
- func (p *RenderPassEncoder) Ref() js.Value
- func (p *RenderPassEncoder) SetBindGroup(index uint32, group js.Value, dynamicOffsets []uint32)
- func (p *RenderPassEncoder) SetBlendConstant(color js.Value)
- func (p *RenderPassEncoder) SetIndexBuffer(buffer js.Value, format string, offset uint64, size uint64)
- func (p *RenderPassEncoder) SetPipeline(pipeline js.Value)
- func (p *RenderPassEncoder) SetScissorRect(x, y, w, h uint32)
- func (p *RenderPassEncoder) SetStencilReference(ref uint32)
- func (p *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer js.Value, offset uint64, size uint64)
- func (p *RenderPassEncoder) SetViewport(x, y, w, h, minDepth, maxDepth float32)
- type RenderPipeline
- type RenderPipelineDescriptorJS
- type Sampler
- type SamplerBindingLayoutJS
- type ShaderModule
- type StencilFaceStateJS
- type StorageTextureBindingLayoutJS
- type Surface
- func (s *Surface) Canvas() js.Value
- func (s *Surface) Configure(config js.Value, width, height uint32, format string)
- func (s *Surface) Configured() bool
- func (s *Surface) Context() js.Value
- func (s *Surface) Destroy()
- func (s *Surface) Format() string
- func (s *Surface) GetCurrentTexture() (*Texture, error)
- func (s *Surface) GetPreferredCanvasFormat() string
- func (s *Surface) Height() uint32
- func (s *Surface) Unconfigure()
- func (s *Surface) Width() uint32
- type Texture
- type TextureBindingLayoutJS
- type TextureView
- type VertexAttributeJS
- type VertexBufferLayoutJS
- type VertexStateJS
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWebGPUNotSupported is returned when navigator.gpu is unavailable. ErrWebGPUNotSupported = errors.New("wgpu: WebGPU not supported in this browser") // (e.g., running in a non-browser WASM environment like Node.js without gpu). ErrNavigatorUnavailable = errors.New("wgpu: navigator not available") // ErrAdapterNotFound is returned when requestAdapter yields null // (no suitable GPU adapter found). ErrAdapterNotFound = errors.New("wgpu: no suitable GPU adapter found") // ErrDeviceCreationFailed is returned when requestDevice fails. ErrDeviceCreationFailed = errors.New("wgpu: device creation failed") )
Common browser WebGPU errors.
var ErrCanvasContextFailed = errors.New("wgpu: canvas.getContext(\"webgpu\") returned null; webgpu not available or canvas already in use")
ErrCanvasContextFailed is returned when canvas.getContext("webgpu") returns null. This happens when WebGPU is not available or the canvas is already bound to another context type (e.g., "2d" or "webgl2").
Matches Rust wgpu's CreateSurfaceErrorKind::Web for the null-context case.
Functions ¶
func AddressModeToJS ¶
func AddressModeToJS(m gputypes.AddressMode) string
AddressModeToJS converts a gputypes.AddressMode to JS string.
func AwaitPromise ¶
AwaitPromise blocks the calling goroutine until a JS Promise resolves or rejects.
On WASM, Go goroutines are cooperative (single-threaded). This function uses Promise.then/catch with a channel to yield the goroutine until the JS event loop resolves the promise. The caller MUST be on a goroutine (not the main goroutine) or the program will deadlock.
Pattern matches Rust wgpu's wasm_bindgen_futures::JsFuture::from(promise).
func BlendFactorToJS ¶
func BlendFactorToJS(f gputypes.BlendFactor) string
BlendFactorToJS converts a gputypes.BlendFactor to JS string.
func BlendOperationToJS ¶
func BlendOperationToJS(op gputypes.BlendOperation) string
BlendOperationToJS converts a gputypes.BlendOperation to JS string.
func BufferBindingTypeToJS ¶
func BufferBindingTypeToJS(t gputypes.BufferBindingType) string
BufferBindingTypeToJS converts a gputypes.BufferBindingType to JS string.
func BuildBindGroupDescriptor ¶
func BuildBindGroupDescriptor( label string, layoutRef js.Value, entries []BindGroupEntryJS, ) js.Value
BuildBindGroupDescriptor constructs a JS GPUBindGroupDescriptor object.
func BuildBindGroupLayoutDescriptor ¶
func BuildBindGroupLayoutDescriptor( label string, entries []BindGroupLayoutEntryJS, ) js.Value
BuildBindGroupLayoutDescriptor constructs a JS GPUBindGroupLayoutDescriptor object.
func BuildBufferDescriptor ¶
BuildBufferDescriptor constructs a JS GPUBufferDescriptor object.
func BuildColorDict ¶
BuildColorDict constructs a JS GPUColorDict { r, g, b, a }.
func BuildCommandEncoderDescriptor ¶
BuildCommandEncoderDescriptor constructs a JS GPUCommandEncoderDescriptor.
func BuildComputePassDescriptor ¶
BuildComputePassDescriptor constructs a JS GPUComputePassDescriptor.
func BuildComputePipelineDescriptor ¶
func BuildComputePipelineDescriptor( label string, layoutRef js.Value, moduleRef js.Value, entryPoint string, ) js.Value
BuildComputePipelineDescriptor constructs a JS GPUComputePipelineDescriptor.
func BuildDeviceDescriptor ¶
func BuildDeviceDescriptor( label string, requiredFeatures gputypes.Features, requiredLimits gputypes.Limits, ) js.Value
BuildDeviceDescriptor constructs a JS GPUDeviceDescriptor object.
Matches Rust wgpu WebAdapter::request_device which builds the JS descriptor with requiredFeatures array and requiredLimits object.
func BuildExtent3D ¶
BuildExtent3D constructs a JS GPUExtent3DDict.
func BuildImageCopyBuffer ¶
func BuildImageCopyBuffer(buffer js.Value, offset uint64, bytesPerRow, rowsPerImage uint32) js.Value
BuildImageCopyBuffer constructs a JS GPUTexelCopyBufferInfo (formerly GPUImageCopyBuffer).
func BuildImageCopyTexture ¶
func BuildImageCopyTexture(texture js.Value, mipLevel uint32, originX, originY, originZ uint32) js.Value
BuildImageCopyTexture constructs a JS GPUTexelCopyTextureInfo (formerly GPUImageCopyTexture).
func BuildPipelineLayoutDescriptor ¶
BuildPipelineLayoutDescriptor constructs a JS GPUPipelineLayoutDescriptor.
func BuildRenderPassDescriptor ¶
func BuildRenderPassDescriptor( label string, colorAttachments []RenderPassColorAttachmentJS, depthStencil *RenderPassDepthStencilAttachmentJS, ) js.Value
BuildRenderPassDescriptor constructs a JS GPURenderPassDescriptor.
Matches Rust wgpu's begin_render_pass which builds GpuRenderPassDescriptor with color attachments array and optional depth-stencil attachment.
func BuildRenderPipelineDescriptor ¶
func BuildRenderPipelineDescriptor(desc *RenderPipelineDescriptorJS) js.Value
BuildRenderPipelineDescriptor constructs a JS GPURenderPipelineDescriptor.
func BuildRequestAdapterOptions ¶
func BuildRequestAdapterOptions( powerPreference gputypes.PowerPreference, forceFallback bool, ) js.Value
BuildRequestAdapterOptions constructs a JS GPURequestAdapterOptions object.
func BuildSamplerDescriptor ¶
func BuildSamplerDescriptor( label string, addressModeU, addressModeV, addressModeW gputypes.AddressMode, magFilter, minFilter gputypes.FilterMode, mipmapFilter gputypes.FilterMode, lodMinClamp, lodMaxClamp float32, compare gputypes.CompareFunction, maxAnisotropy uint16, ) js.Value
BuildSamplerDescriptor constructs a JS GPUSamplerDescriptor object.
func BuildShaderModuleDescriptor ¶
BuildShaderModuleDescriptor constructs a JS GPUShaderModuleDescriptor object. On browser, WGSL code goes directly to the browser's createShaderModule.
func BuildSurfaceConfiguration ¶
func BuildSurfaceConfiguration( deviceRef js.Value, format gputypes.TextureFormat, usage gputypes.TextureUsage, alphaMode gputypes.CompositeAlphaMode, viewFormats []gputypes.TextureFormat, ) js.Value
BuildSurfaceConfiguration constructs a JS GPUCanvasConfiguration object.
The returned object is passed to GPUCanvasContext.configure(). Fields match the WebGPU spec GPUCanvasConfiguration dictionary:
- device: GPUDevice
- format: GPUTextureFormat string
- usage: GPUTextureUsageFlags (default: RENDER_ATTACHMENT)
- alphaMode: GPUCanvasAlphaMode ("opaque" or "premultiplied")
- viewFormats: sequence<GPUTextureFormat>
Note: the spec does not include width/height/presentMode in the configure() call. Canvas dimensions are set separately via canvas.width/canvas.height.
Matches Rust wgpu SurfaceInterface::configure for WebSurface which builds GpuCanvasConfiguration with device, format, usage, alpha_mode, view_formats.
func BuildTexelCopyBufferLayout ¶
BuildTexelCopyBufferLayout constructs a JS GPUTexelCopyBufferLayout (formerly GPUImageDataLayout).
func BuildTextureDescriptor ¶
func BuildTextureDescriptor( label string, width, height, depthOrArrayLayers uint32, mipLevelCount, sampleCount uint32, dimension gputypes.TextureDimension, format gputypes.TextureFormat, usage gputypes.TextureUsage, viewFormats []gputypes.TextureFormat, ) js.Value
BuildTextureDescriptor constructs a JS GPUTextureDescriptor object.
func BuildTextureViewDescriptor ¶
func BuildTextureViewDescriptor( label string, format gputypes.TextureFormat, dimension gputypes.TextureViewDimension, aspect gputypes.TextureAspect, baseMipLevel, mipLevelCount uint32, baseArrayLayer, arrayLayerCount uint32, ) js.Value
BuildTextureViewDescriptor constructs a JS GPUTextureViewDescriptor object.
func CompareFunctionToJS ¶
func CompareFunctionToJS(f gputypes.CompareFunction) string
CompareFunctionToJS converts a gputypes.CompareFunction to JS string.
func CompositeAlphaModeToJS ¶
func CompositeAlphaModeToJS(mode gputypes.CompositeAlphaMode) string
CompositeAlphaModeToJS converts a gputypes.CompositeAlphaMode to the WebGPU JS canvas alpha mode string.
Browser WebGPU only supports "opaque" and "premultiplied". PostMultiplied and Inherit are not valid on the web (Rust wgpu panics on those). Auto and Opaque both map to "opaque".
See: https://www.w3.org/TR/webgpu/#enumdef-gpucanvasalphamode
func CullModeToJS ¶
CullModeToJS converts a gputypes.CullMode to JS string.
func ExtractFeatures ¶
ExtractFeatures reads a GPUSupportedFeatures set and returns gputypes.Features.
GPUSupportedFeatures is a Set-like object. We check each known WebGPU feature string using .has(). Matches Rust wgpu's map_wgt_features.
func ExtractLimits ¶
ExtractLimits reads a GPUSupportedLimits object and returns gputypes.Limits.
GPUSupportedLimits has getter properties for each limit. We read them as float64 (JS numbers) and convert to the appropriate Go integer type. Matches Rust wgpu's map_wgt_limits.
func FilterModeToJS ¶
func FilterModeToJS(m gputypes.FilterMode) string
FilterModeToJS converts a gputypes.FilterMode to JS string.
func FrontFaceToJS ¶
FrontFaceToJS converts a gputypes.FrontFace to JS string.
func GPUAvailable ¶
func GPUAvailable() bool
GPUAvailable reports whether the browser supports WebGPU. It checks for the existence of navigator.gpu.
func IndexFormatToJS ¶
func IndexFormatToJS(f gputypes.IndexFormat) string
IndexFormatToJS converts a gputypes.IndexFormat to JS string.
func LoadOpToJS ¶
LoadOpToJS converts a gputypes.LoadOp to the WebGPU JS string. Returns "load" for LoadOpLoad, "clear" for LoadOpClear, and "load" as default.
func PowerPreferenceToJS ¶
func PowerPreferenceToJS(pref gputypes.PowerPreference) string
PowerPreferenceToJS converts a gputypes.PowerPreference to the JS string expected by GPURequestAdapterOptions.powerPreference.
Matches Rust wgpu's map of PowerPreference to GpuPowerPreference.
func PresentModeToJS ¶
func PresentModeToJS(mode gputypes.PresentMode) string
PresentModeToJS converts a gputypes.PresentMode to the WebGPU JS present mode string.
Browser WebGPU does not expose present mode control; the browser always uses FIFO (VSync). Rust wgpu panics on Mailbox/Immediate on the web. We return "fifo" for all modes since the browser ignores it anyway.
func PrimitiveTopologyToJS ¶
func PrimitiveTopologyToJS(t gputypes.PrimitiveTopology) string
PrimitiveTopologyToJS converts a gputypes.PrimitiveTopology to JS string.
func SamplerBindingTypeToJS ¶
func SamplerBindingTypeToJS(t gputypes.SamplerBindingType) string
SamplerBindingTypeToJS converts a gputypes.SamplerBindingType to JS string.
func StencilOperationToJS ¶
func StencilOperationToJS(op gputypes.StencilOperation) string
StencilOperationToJS converts a gputypes.StencilOperation to JS string.
func StorageTextureAccessToJS ¶
func StorageTextureAccessToJS(a gputypes.StorageTextureAccess) string
StorageTextureAccessToJS converts a gputypes.StorageTextureAccess to JS string.
func StoreOpToJS ¶
StoreOpToJS converts a gputypes.StoreOp to the WebGPU JS string. Returns "store" for StoreOpStore, "discard" for StoreOpDiscard, and "store" as default.
func TextureAspectToJS ¶
func TextureAspectToJS(a gputypes.TextureAspect) string
TextureAspectToJS converts a gputypes.TextureAspect to JS string.
func TextureDimensionToJS ¶
func TextureDimensionToJS(d gputypes.TextureDimension) string
TextureDimensionToJS converts a gputypes.TextureDimension to the WebGPU JS string.
func TextureFormatFromJS ¶
func TextureFormatFromJS(s string) gputypes.TextureFormat
TextureFormatFromJS converts a WebGPU JS texture format string to the corresponding gputypes.TextureFormat. Returns TextureFormatUndefined if the string is not recognized.
This is the reverse of TextureFormatToJS and is needed for parsing the preferred canvas format returned by navigator.gpu.getPreferredCanvasFormat().
func TextureFormatToJS ¶
func TextureFormatToJS(f gputypes.TextureFormat) string
TextureFormatToJS converts a gputypes.TextureFormat to the WebGPU JS string. Returns "" for TextureFormatUndefined.
func TextureSampleTypeToJS ¶
func TextureSampleTypeToJS(t gputypes.TextureSampleType) string
TextureSampleTypeToJS converts a gputypes.TextureSampleType to JS string.
func TextureViewDimensionToJS ¶
func TextureViewDimensionToJS(d gputypes.TextureViewDimension) string
TextureViewDimensionToJS converts a gputypes.TextureViewDimension to JS string.
func VertexFormatToJS ¶
func VertexFormatToJS(f gputypes.VertexFormat) string
VertexFormatToJS converts a gputypes.VertexFormat to JS string.
func VertexStepModeToJS ¶
func VertexStepModeToJS(m gputypes.VertexStepMode) string
VertexStepModeToJS converts a gputypes.VertexStepMode to JS string.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter wraps a browser GPUAdapter.
Matches Rust wgpu WebAdapter which holds the webgpu_sys::GpuAdapter inner value and pre-caches features/limits at construction time.
func (*Adapter) Features ¶
Features returns the cached GPUSupportedFeatures js.Value. Use convert.ExtractFeatures to convert to gputypes.Features.
func (*Adapter) Limits ¶
Limits returns the cached GPUSupportedLimits js.Value. Use convert.ExtractLimits to convert to gputypes.Limits.
func (*Adapter) RequestDevice ¶
RequestDevice requests a logical device from this adapter.
The descriptor parameter is a JS object matching GPUDeviceDescriptor (built by convert.go helpers). Pass js.Undefined() for default device.
Matches Rust wgpu WebAdapter::request_device which calls inner.request_device_with_descriptor and awaits the promise.
type BindGroup ¶
type BindGroup struct {
// contains filtered or unexported fields
}
BindGroup wraps a browser GPUBindGroup.
func NewBindGroup ¶
NewBindGroup constructs a BindGroup from a GPUBindGroup js.Value.
type BindGroupEntryJS ¶
type BindGroupEntryJS struct {
Binding uint32
// Exactly one of these should be set.
BufferRef js.Value // GPUBuffer ref
BufferOffset uint64
BufferSize uint64
SamplerRef js.Value // GPUSampler ref
TextureViewRef js.Value // GPUTextureView ref
}
BindGroupEntryJS holds a single bind group entry for JS conversion.
type BindGroupLayout ¶
type BindGroupLayout struct {
// contains filtered or unexported fields
}
BindGroupLayout wraps a browser GPUBindGroupLayout.
func NewBindGroupLayout ¶
func NewBindGroupLayout(ref js.Value) *BindGroupLayout
NewBindGroupLayout constructs a BindGroupLayout from a GPUBindGroupLayout js.Value.
func (*BindGroupLayout) Ref ¶
func (l *BindGroupLayout) Ref() js.Value
Ref returns the underlying GPUBindGroupLayout js.Value.
type BindGroupLayoutEntryJS ¶
type BindGroupLayoutEntryJS struct {
Binding uint32
Visibility uint32 // ShaderStages bitmask
// Exactly one of these should be non-nil.
Buffer *BufferBindingLayoutJS
Sampler *SamplerBindingLayoutJS
Texture *TextureBindingLayoutJS
StorageTexture *StorageTextureBindingLayoutJS
}
BindGroupLayoutEntryJS holds the data needed to build a single GPUBindGroupLayoutEntry JS object.
func (*BindGroupLayoutEntryJS) ToJS ¶
func (e *BindGroupLayoutEntryJS) ToJS() js.Value
ToJS converts to a JS object.
type BlendComponentJS ¶
BlendComponentJS holds a blend component for JS.
func (*BlendComponentJS) ToJS ¶
func (bc *BlendComponentJS) ToJS() js.Value
ToJS converts to a JS object.
type BlendStateJS ¶
type BlendStateJS struct {
Color BlendComponentJS
Alpha BlendComponentJS
}
BlendStateJS holds blend state for JS.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer wraps a browser GPUBuffer with mapping state tracking.
Holds a reference to the JavaScript GPUBuffer object and caches the size to avoid repeated JS property lookups. Tracks the mapped ArrayBuffer so that multiple Go-side GetMappedRange calls reuse a single JS mapping, matching the Rust wgpu WebBuffer/WebBufferMapState pattern -- the WebGPU spec forbids calling GPUBuffer.getMappedRange more than once for the same mapped region.
func (*Buffer) Destroy ¶
func (b *Buffer) Destroy()
Destroy calls GPUBuffer.destroy() to release GPU memory.
func (*Buffer) GetMappedRangeBytes ¶
GetMappedRangeBytes copies bytes from the mapped region [offset, offset+size) into a new Go byte slice. The buffer must be in the mapped state (MapAsync resolved or the buffer was created with mappedAtCreation: true).
Internally this obtains a Uint8Array view into the cached ArrayBuffer at the correct sub-range offset, then uses js.CopyBytesToGo to transfer data. Matches Rust wgpu WebBufferMappedRange which copies from JS to Rust/WASM heap.
func (*Buffer) MapAsync ¶
MapAsync maps the buffer for CPU access by calling GPUBuffer.mapAsync(mode, offset, size). Blocks the calling goroutine until the JS Promise resolves or rejects.
mode uses WebGPU GPUMapMode flags: 1 = MAP_READ, 2 = MAP_WRITE. The caller MUST be on a goroutine (not the main goroutine) or the program will deadlock, because AwaitPromise yields via a channel.
On success the mapped range is recorded so that subsequent GetMappedRangeBytes calls can cache the JS ArrayBuffer (matching Rust wgpu WebBuffer.set_mapped_range).
func (*Buffer) SetMappedAtCreation ¶
func (b *Buffer) SetMappedAtCreation()
SetMappedAtCreation records the mapped range for a buffer created with mappedAtCreation: true. The entire buffer [0, size) is mapped. This must be called immediately after NewBuffer for mappedAtCreation buffers so that GetMappedRangeBytes / WriteMappedRange work correctly.
func (*Buffer) Unmap ¶
func (b *Buffer) Unmap()
Unmap unmaps the buffer, making its mapped ranges invalid, and clears the cached ArrayBuffer. Matches Rust wgpu WebBuffer.unmap which calls inner.unmap() and sets mapped_buffer = None.
func (*Buffer) WriteMappedRange ¶
WriteMappedRange writes data into the mapped buffer at [offset, offset+len(data)). The buffer must be mapped with MAP_WRITE mode (or created with mappedAtCreation).
Internally creates a Uint8Array view into the cached ArrayBuffer and uses js.CopyBytesToJS to transfer data from Go to JS. On Unmap the browser flushes the written data to the GPU. Matches Rust wgpu WebBufferMappedRange.slice_mut + Drop write-back pattern.
type BufferBindingLayoutJS ¶
type BufferBindingLayoutJS struct {
Type string // "uniform", "storage", "read-only-storage"
HasDynamicOffset bool
MinBindingSize uint64
}
BufferBindingLayoutJS holds buffer binding layout data.
func (*BufferBindingLayoutJS) ToJS ¶
func (b *BufferBindingLayoutJS) ToJS() js.Value
ToJS converts to a JS object.
type ColorTargetStateJS ¶
type ColorTargetStateJS struct {
Format string
Blend *BlendStateJS
WriteMask uint32
}
ColorTargetStateJS holds a color target for JS.
func (*ColorTargetStateJS) ToJS ¶
func (c *ColorTargetStateJS) ToJS() js.Value
ToJS converts to a JS object.
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
CommandBuffer wraps a browser GPUCommandBuffer. A command buffer is an opaque handle to recorded GPU commands, ready for submission via Queue.Submit.
func (*CommandBuffer) Ref ¶
func (cb *CommandBuffer) Ref() js.Value
Ref returns the underlying GPUCommandBuffer js.Value.
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
CommandEncoder wraps a browser GPUCommandEncoder with pre-bound methods.
Pre-binding JS methods at construction time avoids repeated .Get("methodName") calls on every frame. The browser's GPUCommandEncoder records GPU commands that are later submitted via Queue.Submit.
Matches Rust wgpu WebCommandEncoder which holds the webgpu_sys::GpuCommandEncoder.
func NewCommandEncoder ¶
func NewCommandEncoder(ref js.Value) *CommandEncoder
NewCommandEncoder constructs a CommandEncoder from a GPUCommandEncoder js.Value. Pre-binds all recording methods to avoid property lookups on hot paths.
func (*CommandEncoder) BeginComputePass ¶
func (e *CommandEncoder) BeginComputePass(desc js.Value) *ComputePassEncoder
BeginComputePass begins a compute pass with the given JS descriptor. Returns a ComputePassEncoder wrapping the browser GPUComputePassEncoder.
func (*CommandEncoder) BeginRenderPass ¶
func (e *CommandEncoder) BeginRenderPass(desc js.Value) *RenderPassEncoder
BeginRenderPass begins a render pass with the given JS descriptor. Returns a RenderPassEncoder wrapping the browser GPURenderPassEncoder.
func (*CommandEncoder) ClearBuffer ¶
func (e *CommandEncoder) ClearBuffer(buffer js.Value, offset, size uint64)
ClearBuffer clears a buffer region to zero.
func (*CommandEncoder) CopyBufferToBuffer ¶
func (e *CommandEncoder) CopyBufferToBuffer(src js.Value, srcOffset uint64, dst js.Value, dstOffset uint64, size uint64)
CopyBufferToBuffer records a buffer-to-buffer copy command. Matches Rust wgpu: copy_buffer_to_buffer_with_f64_and_f64_and_f64.
func (*CommandEncoder) CopyBufferToTexture ¶
func (e *CommandEncoder) CopyBufferToTexture(source, destination, copySize js.Value)
CopyBufferToTexture records a buffer-to-texture copy command. source = GPUTexelCopyBufferInfo, destination = GPUTexelCopyTextureInfo, copySize = GPUExtent3DDict.
func (*CommandEncoder) CopyTextureToBuffer ¶
func (e *CommandEncoder) CopyTextureToBuffer(source, destination, copySize js.Value)
CopyTextureToBuffer records a texture-to-buffer copy command. source = GPUTexelCopyTextureInfo, destination = GPUTexelCopyBufferInfo, copySize = GPUExtent3DDict.
func (*CommandEncoder) CopyTextureToTexture ¶
func (e *CommandEncoder) CopyTextureToTexture(source, destination, copySize js.Value)
CopyTextureToTexture records a texture-to-texture copy command. source = GPUTexelCopyTextureInfo, destination = GPUTexelCopyTextureInfo, copySize = GPUExtent3DDict.
func (*CommandEncoder) Finish ¶
func (e *CommandEncoder) Finish(desc js.Value) *CommandBuffer
Finish completes command recording and returns a CommandBuffer. An optional descriptor (or js.Undefined()) can be passed for the label.
func (*CommandEncoder) Ref ¶
func (e *CommandEncoder) Ref() js.Value
Ref returns the underlying GPUCommandEncoder js.Value.
type ComputePassEncoder ¶
type ComputePassEncoder struct {
// contains filtered or unexported fields
}
ComputePassEncoder wraps a browser GPUComputePassEncoder with pre-bound methods.
Pre-binding JS methods at construction time avoids repeated property lookups during compute dispatch. Matches Rust wgpu WebComputePassEncoder which holds webgpu_sys::GpuComputePassEncoder.
func NewComputePassEncoder ¶
func NewComputePassEncoder(ref js.Value) *ComputePassEncoder
NewComputePassEncoder constructs a ComputePassEncoder from a GPUComputePassEncoder js.Value. Pre-binds all dispatch and state methods.
func (*ComputePassEncoder) DispatchIndirect ¶
func (p *ComputePassEncoder) DispatchIndirect(buffer js.Value, offset uint64)
DispatchIndirect dispatches compute work with GPU-generated parameters from an indirect buffer.
func (*ComputePassEncoder) DispatchWorkgroups ¶
func (p *ComputePassEncoder) DispatchWorkgroups(x, y, z uint32)
DispatchWorkgroups dispatches compute work. Matches Rust: dispatch_workgroups_with_workgroup_count_y_and_workgroup_count_z.
func (*ComputePassEncoder) Ref ¶
func (p *ComputePassEncoder) Ref() js.Value
Ref returns the underlying GPUComputePassEncoder js.Value.
func (*ComputePassEncoder) SetBindGroup ¶
func (p *ComputePassEncoder) SetBindGroup(index uint32, group js.Value, dynamicOffsets []uint32)
SetBindGroup sets a bind group at the given index.
When dynamicOffsets is non-empty, the offsets are passed as a Uint32Array, matching Rust wgpu's set_bind_group_with_u32_slice_and_f64_and_dynamic_offsets_data_length.
func (*ComputePassEncoder) SetPipeline ¶
func (p *ComputePassEncoder) SetPipeline(pipeline js.Value)
SetPipeline sets the active compute pipeline.
type ComputePipeline ¶
type ComputePipeline struct {
// contains filtered or unexported fields
}
ComputePipeline wraps a browser GPUComputePipeline.
func NewComputePipeline ¶
func NewComputePipeline(ref js.Value) *ComputePipeline
NewComputePipeline constructs a ComputePipeline from a GPUComputePipeline js.Value.
func (*ComputePipeline) GetBindGroupLayout ¶
func (p *ComputePipeline) GetBindGroupLayout(index uint32) *BindGroupLayout
GetBindGroupLayout returns the bind group layout at the given index. Wraps GPUComputePipeline.getBindGroupLayout(index).
func (*ComputePipeline) Ref ¶
func (p *ComputePipeline) Ref() js.Value
Ref returns the underlying GPUComputePipeline js.Value.
type DepthStencilStateJS ¶
type DepthStencilStateJS struct {
Format string
DepthWriteEnabled bool
DepthCompare string
StencilFront *StencilFaceStateJS
StencilBack *StencilFaceStateJS
StencilReadMask uint32
StencilWriteMask uint32
DepthBias int32
DepthBiasSlopeScale float32
DepthBiasClamp float32
}
DepthStencilStateJS holds depth-stencil state for JS.
func (*DepthStencilStateJS) ToJS ¶
func (d *DepthStencilStateJS) ToJS() js.Value
ToJS converts to a JS object.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device wraps a browser GPUDevice with pre-bound creation methods.
Pre-binding JS methods at construction time avoids repeated .Get("methodName") calls on every frame. This pattern is used by Ebiten and other Go WASM libraries for optimal performance.
Matches Rust wgpu WebDevice which holds the webgpu_sys::GpuDevice value.
func NewDevice ¶
NewDevice constructs a Device from a GPUDevice js.Value. Pre-binds all creation methods and extracts the queue.
func (*Device) CreateBindGroup ¶
CreateBindGroup returns the pre-bound createBindGroup function.
func (*Device) CreateBindGroupFromDesc ¶
CreateBindGroupFromDesc creates a GPUBindGroup from a JS descriptor object.
func (*Device) CreateBindGroupLayout ¶
CreateBindGroupLayout returns the pre-bound createBindGroupLayout function.
func (*Device) CreateBindGroupLayoutFromDesc ¶
func (d *Device) CreateBindGroupLayoutFromDesc(desc js.Value) *BindGroupLayout
CreateBindGroupLayoutFromDesc creates a GPUBindGroupLayout from a JS descriptor object.
func (*Device) CreateBuffer ¶
CreateBuffer returns the pre-bound createBuffer function. Call with: d.CreateBuffer().Invoke(descriptorObj)
func (*Device) CreateBufferFromDesc ¶
CreateBufferFromDesc creates a GPUBuffer from a JS descriptor object.
func (*Device) CreateCommandEncoder ¶
CreateCommandEncoder returns the pre-bound createCommandEncoder function.
func (*Device) CreateComputePipeline ¶
CreateComputePipeline returns the pre-bound createComputePipeline function.
func (*Device) CreateComputePipelineFromDesc ¶
func (d *Device) CreateComputePipelineFromDesc(desc js.Value) *ComputePipeline
CreateComputePipelineFromDesc creates a GPUComputePipeline from a JS descriptor object.
func (*Device) CreatePipelineLayout ¶
CreatePipelineLayout returns the pre-bound createPipelineLayout function.
func (*Device) CreatePipelineLayoutFromDesc ¶
func (d *Device) CreatePipelineLayoutFromDesc(desc js.Value) *PipelineLayout
CreatePipelineLayoutFromDesc creates a GPUPipelineLayout from a JS descriptor object.
func (*Device) CreateQuerySet ¶
CreateQuerySet returns the pre-bound createQuerySet function.
func (*Device) CreateRenderPipeline ¶
CreateRenderPipeline returns the pre-bound createRenderPipeline function.
func (*Device) CreateRenderPipelineFromDesc ¶
func (d *Device) CreateRenderPipelineFromDesc(desc js.Value) *RenderPipeline
CreateRenderPipelineFromDesc creates a GPURenderPipeline from a JS descriptor object.
func (*Device) CreateSampler ¶
CreateSampler returns the pre-bound createSampler function.
func (*Device) CreateSamplerFromDesc ¶
CreateSamplerFromDesc creates a GPUSampler from a JS descriptor object.
func (*Device) CreateShaderModule ¶
CreateShaderModule returns the pre-bound createShaderModule function.
func (*Device) CreateShaderModuleFromDesc ¶
func (d *Device) CreateShaderModuleFromDesc(desc js.Value) *ShaderModule
CreateShaderModuleFromDesc creates a GPUShaderModule from a JS descriptor object.
func (*Device) CreateTexture ¶
CreateTexture returns the pre-bound createTexture function.
func (*Device) CreateTextureFromDesc ¶
CreateTextureFromDesc creates a GPUTexture from a JS descriptor object.
func (*Device) Destroy ¶
func (d *Device) Destroy()
Destroy calls GPUDevice.destroy() to release GPU resources. After this call the device is no longer usable.
type FragmentStateJS ¶
type FragmentStateJS struct {
ModuleRef js.Value // GPUShaderModule
EntryPoint string
Targets []ColorTargetStateJS
}
FragmentStateJS holds fragment shader state for JS.
func (*FragmentStateJS) ToJS ¶
func (f *FragmentStateJS) ToJS() js.Value
ToJS converts to a JS object.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is the browser WebGPU entry point, wrapping navigator.gpu.
Matches Rust wgpu ContextWebGpu which holds an Option<Gpu>.
func NewInstance ¶
NewInstance creates a new browser WebGPU instance by accessing navigator.gpu.
Returns ErrNavigatorUnavailable if the navigator object is missing, or ErrWebGPUNotSupported if navigator.gpu is undefined (browser does not support WebGPU or the page is not in a secure context).
func (*Instance) GPU ¶
GPU returns the underlying navigator.gpu js.Value. Exposed for testing and advanced interop scenarios.
func (*Instance) RequestAdapter ¶
RequestAdapter requests a GPU adapter from the browser.
The options parameter is a JS object matching GPURequestAdapterOptions (built by convert.go helpers). Pass js.Undefined() for default options.
Returns ErrAdapterNotFound if the browser cannot find a suitable adapter (same as navigator.gpu.requestAdapter() returning null).
Matches Rust wgpu ContextWebGpu::request_adapter which calls gpu.request_adapter_with_options and awaits the promise.
type JSError ¶
type JSError struct {
// Message is the error message extracted from the JS error.
Message string
// Name is the JS error constructor name (e.g., "TypeError", "OperationError").
Name string
}
JSError wraps a JavaScript error value for Go error handling.
func NewJSError ¶
NewJSError creates a JSError from a js.Value. Returns nil if the value is null or undefined.
type MultisampleStateJS ¶
MultisampleStateJS holds multisample state for JS.
func (*MultisampleStateJS) ToJS ¶
func (m *MultisampleStateJS) ToJS() js.Value
ToJS converts to a JS object.
type PipelineLayout ¶
type PipelineLayout struct {
// contains filtered or unexported fields
}
PipelineLayout wraps a browser GPUPipelineLayout.
func NewPipelineLayout ¶
func NewPipelineLayout(ref js.Value) *PipelineLayout
NewPipelineLayout constructs a PipelineLayout from a GPUPipelineLayout js.Value.
func (*PipelineLayout) Ref ¶
func (l *PipelineLayout) Ref() js.Value
Ref returns the underlying GPUPipelineLayout js.Value.
type PrimitiveStateJS ¶
type PrimitiveStateJS struct {
Topology string // "triangle-list", etc.
StripIndexFormat string // "uint16", "uint32" (only for strip topologies)
FrontFace string // "ccw", "cw"
CullMode string // "none", "front", "back"
UnclippedDepth bool
}
PrimitiveStateJS holds primitive assembly state for JS.
func (*PrimitiveStateJS) ToJS ¶
func (p *PrimitiveStateJS) ToJS() js.Value
ToJS converts to a JS object.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue wraps a browser GPUQueue with pre-bound submission and write methods.
Pre-binding JS methods at construction time avoids repeated property lookups on every submit/write call. Matches Rust wgpu WebQueue.
func NewQueue ¶
NewQueue constructs a Queue from a GPUQueue js.Value. Pre-binds submit, writeBuffer, and writeTexture methods.
func (*Queue) Submit ¶
Submit submits an array of GPUCommandBuffer js.Values for execution. Rust wgpu collects command buffers into a js_sys::Array and calls queue.submit(&array).
func (*Queue) WriteBuffer ¶
WriteBuffer writes Go byte data to a GPU buffer.
Rust wgpu creates a Uint8Array from the data, then passes its .buffer() (ArrayBuffer) to writeBuffer. We use js.CopyBytesToJS for the Go-to-JS data transfer, which is the standard Go WASM pattern (equivalent to Rust's Uint8Array::from(data)).
Signature: queue.writeBuffer(buffer, bufferOffset, data, dataOffset, size)
func (*Queue) WriteTexture ¶
WriteTexture writes Go byte data to a GPU texture.
destination = GPUTexelCopyTextureInfo, dataLayout = GPUTexelCopyBufferLayout, size = GPUExtent3DDict.
Rust wgpu creates a Uint8Array from the data, passes .buffer() (ArrayBuffer) to writeTexture. We use js.CopyBytesToJS for the Go→JS transfer.
type RenderPassColorAttachmentJS ¶
type RenderPassColorAttachmentJS struct {
View js.Value // GPUTextureView
ResolveTarget js.Value // GPUTextureView or js.Undefined()
LoadOp string // "load" or "clear"
StoreOp string // "store" or "discard"
ClearR float64
ClearG float64
ClearB float64
ClearA float64
}
RenderPassColorAttachmentJS holds data for building a GPURenderPassColorAttachment.
type RenderPassDepthStencilAttachmentJS ¶
type RenderPassDepthStencilAttachmentJS struct {
View js.Value // GPUTextureView
DepthLoadOp string // "load" or "clear"
DepthStoreOp string // "store" or "discard"
DepthClearValue float32
DepthReadOnly bool
StencilLoadOp string // "load" or "clear"
StencilStoreOp string // "store" or "discard"
StencilClearValue uint32
StencilReadOnly bool
}
RenderPassDepthStencilAttachmentJS holds data for building a GPURenderPassDepthStencilAttachment.
type RenderPassEncoder ¶
type RenderPassEncoder struct {
// contains filtered or unexported fields
}
RenderPassEncoder wraps a browser GPURenderPassEncoder with pre-bound methods.
Pre-binding JS methods at construction time avoids repeated property lookups on the hot path (draw calls). This matches the Ebiten pattern used by Device.
Matches Rust wgpu WebRenderPassEncoder which holds webgpu_sys::GpuRenderPassEncoder.
func NewRenderPassEncoder ¶
func NewRenderPassEncoder(ref js.Value) *RenderPassEncoder
NewRenderPassEncoder constructs a RenderPassEncoder from a GPURenderPassEncoder js.Value. Pre-binds all draw and state-setting methods.
func (*RenderPassEncoder) Draw ¶
func (p *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
Draw draws primitives. Matches Rust: draw_with_instance_count_and_first_vertex_and_first_instance.
func (*RenderPassEncoder) DrawIndexed ¶
func (p *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, firstInstance uint32)
DrawIndexed draws indexed primitives. baseVertex is int32 (can be negative) per WebGPU spec. Matches Rust: draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance.
func (*RenderPassEncoder) DrawIndexedIndirect ¶
func (p *RenderPassEncoder) DrawIndexedIndirect(buffer js.Value, offset uint64)
DrawIndexedIndirect draws one indexed primitive with GPU-generated parameters.
func (*RenderPassEncoder) DrawIndirect ¶
func (p *RenderPassEncoder) DrawIndirect(buffer js.Value, offset uint64)
DrawIndirect draws primitives with GPU-generated parameters from an indirect buffer.
func (*RenderPassEncoder) End ¶
func (p *RenderPassEncoder) End()
End ends the render pass. Matches Rust WebRenderPassEncoder Drop which calls end().
func (*RenderPassEncoder) Ref ¶
func (p *RenderPassEncoder) Ref() js.Value
Ref returns the underlying GPURenderPassEncoder js.Value.
func (*RenderPassEncoder) SetBindGroup ¶
func (p *RenderPassEncoder) SetBindGroup(index uint32, group js.Value, dynamicOffsets []uint32)
SetBindGroup sets a bind group at the given index.
When dynamicOffsets is non-empty, the offsets are passed as a Uint32Array using the overload: setBindGroup(index, group, offsetsArray, 0, len). This matches Rust wgpu's set_bind_group_with_u32_slice_and_f64_and_dynamic_offsets_data_length.
func (*RenderPassEncoder) SetBlendConstant ¶
func (p *RenderPassEncoder) SetBlendConstant(color js.Value)
SetBlendConstant sets the blend constant color via a GPUColorDict. Matches Rust: set_blend_constant_with_gpu_color_dict.
func (*RenderPassEncoder) SetIndexBuffer ¶
func (p *RenderPassEncoder) SetIndexBuffer(buffer js.Value, format string, offset uint64, size uint64)
SetIndexBuffer sets the index buffer.
format is a WebGPU string: "uint16" or "uint32". If size is 0, the size parameter is omitted (meaning "rest of buffer"), matching Rust wgpu's set_index_buffer_with_f64 (no size variant).
func (*RenderPassEncoder) SetPipeline ¶
func (p *RenderPassEncoder) SetPipeline(pipeline js.Value)
SetPipeline sets the active render pipeline.
func (*RenderPassEncoder) SetScissorRect ¶
func (p *RenderPassEncoder) SetScissorRect(x, y, w, h uint32)
SetScissorRect sets the scissor rectangle for clipping.
func (*RenderPassEncoder) SetStencilReference ¶
func (p *RenderPassEncoder) SetStencilReference(ref uint32)
SetStencilReference sets the stencil reference value.
func (*RenderPassEncoder) SetVertexBuffer ¶
func (p *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer js.Value, offset uint64, size uint64)
SetVertexBuffer sets a vertex buffer for the given slot.
If size is 0, the size parameter is omitted (meaning "rest of buffer"), matching Rust wgpu's set_vertex_buffer_with_f64 (no size variant).
func (*RenderPassEncoder) SetViewport ¶
func (p *RenderPassEncoder) SetViewport(x, y, w, h, minDepth, maxDepth float32)
SetViewport sets the viewport transformation.
type RenderPipeline ¶
type RenderPipeline struct {
// contains filtered or unexported fields
}
RenderPipeline wraps a browser GPURenderPipeline.
func NewRenderPipeline ¶
func NewRenderPipeline(ref js.Value) *RenderPipeline
NewRenderPipeline constructs a RenderPipeline from a GPURenderPipeline js.Value.
func (*RenderPipeline) GetBindGroupLayout ¶
func (p *RenderPipeline) GetBindGroupLayout(index uint32) *BindGroupLayout
GetBindGroupLayout returns the bind group layout at the given index. Wraps GPURenderPipeline.getBindGroupLayout(index).
func (*RenderPipeline) Ref ¶
func (p *RenderPipeline) Ref() js.Value
Ref returns the underlying GPURenderPipeline js.Value.
type RenderPipelineDescriptorJS ¶
type RenderPipelineDescriptorJS struct {
Label string
LayoutRef js.Value // GPUPipelineLayout or js.Undefined() for "auto"
Vertex VertexStateJS
Primitive *PrimitiveStateJS
DepthStencil *DepthStencilStateJS
Multisample *MultisampleStateJS
Fragment *FragmentStateJS
}
RenderPipelineDescriptorJS holds render pipeline creation data.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler wraps a browser GPUSampler.
func NewSampler ¶
NewSampler constructs a Sampler from a GPUSampler js.Value.
type SamplerBindingLayoutJS ¶
type SamplerBindingLayoutJS struct {
Type string // "filtering", "non-filtering", "comparison"
}
SamplerBindingLayoutJS holds sampler binding layout data.
func (*SamplerBindingLayoutJS) ToJS ¶
func (s *SamplerBindingLayoutJS) ToJS() js.Value
ToJS converts to a JS object.
type ShaderModule ¶
type ShaderModule struct {
// contains filtered or unexported fields
}
ShaderModule wraps a browser GPUShaderModule.
On browser, shader modules hold WGSL code compiled by the browser's native shader compiler. No naga compilation happens -- the WGSL goes directly to the browser's createShaderModule.
func NewShaderModule ¶
func NewShaderModule(ref js.Value) *ShaderModule
NewShaderModule constructs a ShaderModule from a GPUShaderModule js.Value.
func (*ShaderModule) Ref ¶
func (m *ShaderModule) Ref() js.Value
Ref returns the underlying GPUShaderModule js.Value.
type StencilFaceStateJS ¶
StencilFaceStateJS holds stencil operations for a face.
func (*StencilFaceStateJS) ToJS ¶
func (s *StencilFaceStateJS) ToJS() js.Value
ToJS converts to a JS object.
type StorageTextureBindingLayoutJS ¶
type StorageTextureBindingLayoutJS struct {
Access string // "write-only", "read-only", "read-write"
Format string // texture format string
ViewDimension string
}
StorageTextureBindingLayoutJS holds storage texture binding layout data.
func (*StorageTextureBindingLayoutJS) ToJS ¶
func (s *StorageTextureBindingLayoutJS) ToJS() js.Value
ToJS converts to a JS object.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface wraps an HTML canvas element and its GPUCanvasContext.
On the browser, a "surface" is a canvas + the GPUCanvasContext obtained from canvas.getContext("webgpu"). The context is configured with a device, format, and size, then getCurrentTexture() returns the next frame texture.
Presentation happens automatically when the JS event loop runs -- there is no explicit present() call. This matches Rust wgpu WebSurface / WebSurfaceOutputDetail where present() and texture_discard() are both no-ops.
func NewSurface ¶
NewSurface creates a Surface from a canvas element by obtaining its GPUCanvasContext.
The gpu parameter is the navigator.gpu object (needed for getPreferredCanvasFormat). The canvas must be an HTMLCanvasElement or OffscreenCanvas.
Returns ErrCanvasContextFailed if getContext("webgpu") returns null (WebGPU not available or canvas already in use). Panics if getContext throws an exception (indicates misuse of canvas state).
Matches Rust wgpu ContextWebGpu::create_surface_from_context.
func (*Surface) Configure ¶
Configure sets the surface configuration on the GPUCanvasContext.
This sets the canvas dimensions and calls context.configure() with the provided parameters. After Configure, GetCurrentTexture() can be called.
Matches Rust wgpu SurfaceInterface::configure for WebSurface.
func (*Surface) Configured ¶
Configured reports whether the surface has been configured.
func (*Surface) Destroy ¶
func (s *Surface) Destroy()
Destroy releases the surface. On browser this unconfigures the context. Matches Rust wgpu Drop for WebSurface (no-op in Rust, but we unconfigure for clean teardown).
func (*Surface) GetCurrentTexture ¶
GetCurrentTexture returns the current frame texture from the GPUCanvasContext.
The returned GPUTexture is automatically presented when control returns to the browser event loop after the command buffer using it is submitted.
Returns an error if the surface is not configured.
Matches Rust wgpu SurfaceInterface::get_current_texture for WebSurface.
func (*Surface) GetPreferredCanvasFormat ¶
GetPreferredCanvasFormat returns the preferred texture format for the display.
This calls navigator.gpu.getPreferredCanvasFormat() which returns either "bgra8unorm" or "rgba8unorm" depending on the platform.
See: https://www.w3.org/TR/webgpu/#dom-gpu-getpreferredcanvasformat
Matches Rust wgpu SurfaceInterface::get_capabilities which reads gpu.get_preferred_canvas_format() to order the formats list.
func (*Surface) Unconfigure ¶
func (s *Surface) Unconfigure()
Unconfigure removes the surface configuration. After this call, GetCurrentTexture() will fail until Configure is called again.
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture wraps a browser GPUTexture.
func NewTexture ¶
NewTexture constructs a Texture from a GPUTexture js.Value.
func (*Texture) CreateView ¶
func (t *Texture) CreateView(desc js.Value) *TextureView
CreateView calls GPUTexture.createView() with the given descriptor. Pass js.Undefined() for default view parameters.
func (*Texture) Destroy ¶
func (t *Texture) Destroy()
Destroy calls GPUTexture.destroy() to release GPU memory.
type TextureBindingLayoutJS ¶
type TextureBindingLayoutJS struct {
SampleType string // "float", "unfilterable-float", "depth", "sint", "uint"
ViewDimension string // "2d", "cube", etc.
Multisampled bool
}
TextureBindingLayoutJS holds texture binding layout data.
func (*TextureBindingLayoutJS) ToJS ¶
func (t *TextureBindingLayoutJS) ToJS() js.Value
ToJS converts to a JS object.
type TextureView ¶
type TextureView struct {
// contains filtered or unexported fields
}
TextureView wraps a browser GPUTextureView.
func (*TextureView) Ref ¶
func (v *TextureView) Ref() js.Value
Ref returns the underlying GPUTextureView js.Value.
type VertexAttributeJS ¶
type VertexAttributeJS struct {
Format string // e.g. "float32x2"
Offset uint64
ShaderLocation uint32
}
VertexAttributeJS holds a vertex attribute for JS.
type VertexBufferLayoutJS ¶
type VertexBufferLayoutJS struct {
ArrayStride uint64
StepMode string // "vertex" or "instance"
Attributes []VertexAttributeJS
}
VertexBufferLayoutJS holds a vertex buffer layout for JS.
func (*VertexBufferLayoutJS) ToJS ¶
func (l *VertexBufferLayoutJS) ToJS() js.Value
ToJS converts to a JS object.
type VertexStateJS ¶
type VertexStateJS struct {
ModuleRef js.Value // GPUShaderModule
EntryPoint string
Buffers []VertexBufferLayoutJS
}
VertexStateJS holds vertex shader state for JS.