Help us shape the future of Go! Take the 2026 Go Developer Survey

readback

package
v0.21.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package readback reads the GPU readback corpus under testdata/readback: small compute shaders with the values a GPU must write when it runs them.

naga cannot run a GPU. The corpus lives here, next to the compiler it checks; gogpu/wgpu runs it on every backend and adapter and compares the buffers it reads back. naga's own tests use this package to keep every case well formed and compilable on every backend, so a case that rots fails naga CI before it reaches a GPU run. testdata/readback/README.md is the format specification wgpu implements; this package is its reference reader.

Index

Constants

View Source
const FormatVersion = 2

FormatVersion is the newest case format this package reads; it reads every format from 1 up to it. A case declares its format, and a reader rejects a newer one, so a newer corpus fails loudly instead of being misread. Format 2 adds KnownFailure.Skip.

View Source
const ReadmeName = "README.md"

ReadmeName is the corpus README at the root of the tree, the only file outside an area directory.

Variables

Backends lists every backend of format 1.

Functions

func CheckModule

func CheckModule(spec *Spec, m *ir.Module) error

CheckModule checks that spec describes the shader m, a module from Module: the entry point is a compute one, every buffer it binds has a JSON binding of the same kind and at least the type's size, and the other way round, and the case requires shader-f16 exactly when the shader uses f16.

func Module

func Module(c *Case) (*ir.Module, error)

Module returns the IR a backend compiles for case c, as wgpu builds a compute pipeline from it: the WGSL frontend's module, validated with the capabilities the case requires, with its overrides processed for its entry point and pipeline constants. Processing for one entry point removes the globals it does not use, so the bindings left are the pipeline's.

Types

type Backend

type Backend string

Backend names a wgpu backend and, for DX12, the shader compiler path. A naga backend serves each: vulkan and software run SPIR-V, dx12-fxc runs HLSL through FXC, dx12-dxil runs naga's DXIL, gles runs GLSL and metal MSL.

const (
	BackendVulkan   Backend = "vulkan"
	BackendDX12FXC  Backend = "dx12-fxc"
	BackendDX12DXIL Backend = "dx12-dxil"
	BackendGLES     Backend = "gles"
	BackendMetal    Backend = "metal"
	BackendSoftware Backend = "software"
)

Backends of format 1.

type Binding

type Binding struct {
	Binding uint32 `json:"binding"`
	Kind    Kind   `json:"kind"`
	// Words are the initial contents.
	Words []Word `json:"words,omitempty"`
	// Len is the size in words when the buffer starts as Len copies of Fill.
	Len int `json:"len,omitempty"`
	// Fill is the initial value of every word when Len is set (default 0);
	// "fill" in Expect stands for it.
	Fill *Word `json:"fill,omitempty"`
	// Expect lists the acceptable contents after the dispatch (any of them);
	// each has exactly Size words. Only storage-rw bindings have it.
	Expect [][]ExpectWord `json:"expect,omitempty"`
	// Type says how to print the words in a failure: u32 (default), i32 or
	// f32. It does not change the comparison, which is bit for bit.
	Type string `json:"type,omitempty"`
}

Binding is one buffer at @group(0) @binding(Binding). Its initial contents are either Words, or Len copies of Fill.

func (*Binding) Expected

func (b *Binding) Expected() [][]uint32

Expected returns the acceptable contents after the dispatch, with "fill" replaced by the fill value.

func (*Binding) Initial

func (b *Binding) Initial() []uint32

Initial returns the buffer contents before the dispatch.

func (*Binding) Size

func (b *Binding) Size() int

Size returns the buffer size in 32-bit words.

type Case

type Case struct {
	// Name is "<area>/<name>", the case path without an extension.
	Name string
	// WGSL is the shader source.
	WGSL string
	// Spec is the decoded and checked JSON file.
	Spec Spec
}

Case is one corpus case: <area>/<name>.wgsl and its <area>/<name>.json.

func Load

func Load(fsys fs.FS) ([]Case, error)

Load reads every case of the corpus tree fsys, sorted by name. Every file but the README must belong to a case, and every case needs both files: a stray or half-added file is an error, not a skipped case.

type ExpectWord

type ExpectWord struct {
	Value uint32
	Fill  bool
}

ExpectWord is an expected word: a Word, or the string "fill" for the binding's fill value (the sentinel must still be there).

func (*ExpectWord) UnmarshalJSON

func (w *ExpectWord) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Kind

type Kind string

Kind is the kind of buffer a binding is.

const (
	KindStorageRead Kind = "storage-read" // var<storage, read>
	KindStorageRW   Kind = "storage-rw"   // var<storage, read_write>
	KindUniform     Kind = "uniform"      // var<uniform>
)

Buffer kinds of format 1.

type KnownFailure

type KnownFailure struct {
	Backend Backend `json:"backend"`
	Adapter string  `json:"adapter,omitempty"`
	Driver  string  `json:"driver,omitempty"`
	// Card is the kanban card that tracks the bug: a naga card ID, or
	// "gogpu/<repo>:<ID>" for a card of another gogpu repository.
	Card   string `json:"card"`
	Reason string `json:"reason"`
	// Skip (format 2) tells the runner not to dispatch the case on a matched
	// run, as Rust wgpu's FailureCase skip: the GPU hangs or the device is
	// lost, which would fail every case after it. A skipped run cannot report
	// an unexpected pass, so whoever works the card re-checks the case.
	Skip bool `json:"skip,omitempty"`
}

KnownFailure is an expected failure, as Rust wgpu's FailureCase: it matches a run on Backend whose adapter name and driver contain Adapter and Driver (case-insensitive; empty matches any). A matched case that passes is an error, so a fixed bug cannot hide behind a stale entry.

func (*KnownFailure) AllAdapters

func (k *KnownFailure) AllAdapters() bool

AllAdapters reports whether the entry matches every adapter of its backend.

type Spec

type Spec struct {
	// Format is the case format version, FormatVersion.
	Format int `json:"format"`
	// Desc says what the case checks and why it exists.
	Desc string `json:"desc"`
	// Entry is the name of the compute entry point to run.
	Entry string `json:"entry"`
	// Workgroups is the dispatch size: exactly three counts, each at least 1.
	Workgroups []uint32 `json:"workgroups"`
	// Constants are pipeline-constant values by override name or @id.
	Constants map[string]float64 `json:"constants,omitempty"`
	// Requires lists the WebGPU features the case needs; an adapter without
	// one skips the case.
	Requires []string `json:"requires,omitempty"`
	// Bindings are the buffers of @group(0), one per @binding.
	Bindings []Binding `json:"bindings"`
	// KnownFailures are the backends and adapters on which the case is
	// expected to fail, each tracked by a card.
	KnownFailures []KnownFailure `json:"knownFailures,omitempty"`
}

Spec is one case's JSON file.

func ParseSpec

func ParseSpec(data []byte) (Spec, error)

ParseSpec decodes one case's JSON and checks it against the rules of FormatVersion. Unknown fields are errors.

type Word

type Word uint32

Word is a 32-bit buffer word: a JSON integer in [0, 2^32) or a string "0x" followed by one to eight hex digits.

func (*Word) UnmarshalJSON

func (w *Word) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL