devicetest

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package devicetest holds the scenes that every backend of the explicit device runs (SPEC §27.12): Vulkan on lavapipe, Direct3D 12 under Wine, WebGPU in Chromium and the fake device. A scene draws with the device and compares what it reads back with what it should be, exactly where the result is exact and within a tolerance where an anti-aliased edge or a rounding differs between GPUs. The shaders in shaders/ are compiled by `glutter-gen shaders -package devicetest`; a program that is not a test does not link this package.

Flutter: no counterpart

Index

Constants

This section is empty.

Variables

View Source
var ShaderCompute = &explicit.Shader{
	Name: "compute",
	WGSL: `// Compute shaders of the device tests (SPEC §27.12, step 30.2): squares a million numbers, paints a
// storage texture, and writes the arguments of indirect draws and dispatches.

struct Params {
	count: u32,
	a: u32,
	b: u32,
	c: u32,
}

@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read> input: array<u32>;
@group(0) @binding(2) var<storage, read_write> output: array<u32>;
@group(1) @binding(0) var img: texture_storage_2d<rgba8unorm, write>;
@group(1) @binding(1) var<storage, read_write> args: array<u32>;

@compute @workgroup_size(64)
fn cs_square(@builtin(global_invocation_id) id: vec3<u32>) {
	if (id.x < params.count) {
		output[id.x] = input[id.x] * input[id.x];
	}
}

// Paints texel (x, y) of a texture of 4 by 4 with (x*60, y*60, 128, 255).
@compute @workgroup_size(2, 2)
fn cs_paint(@builtin(global_invocation_id) id: vec3<u32>) {
	textureStore(img, vec2<i32>(id.xy), vec4<f32>(f32(id.x) * 60.0 / 255.0, f32(id.y) * 60.0 / 255.0, 128.0 / 255.0, 1.0));
}

// The arguments of DrawIndirect: 3 vertices, 1 instance, the first vertex 0 and the first instance 0.
@compute @workgroup_size(1)
fn cs_draw_args() {
	args[0] = 3u;
	args[1] = 1u;
	args[2] = 0u;
	args[3] = 0u;
}

// The arguments of DrawIndexedIndirect: 3 indices, 1 instance, the first index 0, the base vertex 0 and
// the first instance 0.
@compute @workgroup_size(1)
fn cs_indexed_args() {
	args[0] = 3u;
	args[1] = 1u;
	args[2] = 0u;
	args[3] = 0u;
	args[4] = 0u;
}

// The arguments of DispatchIndirect: params.a workgroups in x.
@compute @workgroup_size(1)
fn cs_dispatch_args() {
	args[0] = params.a;
	args[1] = 1u;
	args[2] = 1u;
}
`,
	SPIRV: spirvCompute,
	HLSL: `struct Params {
    uint count;
    uint a;
    uint b;
    uint c;
};

cbuffer params : register(b0, space0) { Params params; }
ByteAddressBuffer input : register(t1, space0);
RWByteAddressBuffer output : register(u2, space0);
RWTexture2D<unorm float4> img : register(u0, space1);
RWByteAddressBuffer args : register(u1, space1);

[numthreads(64, 1, 1)]
void cs_square(uint3 id : SV_DispatchThreadID)
{
    uint _e4 = params.count;
    if ((id.x < _e4)) {
        uint _e12 = asuint(input.Load(id.x*4));
        uint _e16 = asuint(input.Load(id.x*4));
        output.Store(id.x*4, asuint((_e12 * _e16)));
        return;
    } else {
        return;
    }
}

[numthreads(2, 2, 1)]
void cs_paint(uint3 id_1 : SV_DispatchThreadID)
{
    img[int2(id_1.xy)] = float4(((float(id_1.x) * 60.0) / 255.0), ((float(id_1.y) * 60.0) / 255.0), 0.5019608, 1.0);
    return;
}

[numthreads(1, 1, 1)]
void cs_draw_args()
{
    args.Store(0, asuint(3u));
    args.Store(4, asuint(1u));
    args.Store(8, asuint(0u));
    args.Store(12, asuint(0u));
    return;
}

[numthreads(1, 1, 1)]
void cs_indexed_args()
{
    args.Store(0, asuint(3u));
    args.Store(4, asuint(1u));
    args.Store(8, asuint(0u));
    args.Store(12, asuint(0u));
    args.Store(16, asuint(0u));
    return;
}

[numthreads(1, 1, 1)]
void cs_dispatch_args()
{
    uint _e4 = params.a;
    args.Store(0, asuint(_e4));
    args.Store(4, asuint(1u));
    args.Store(8, asuint(1u));
    return;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "cs_square", Stage: explicit.ShaderStageCompute, WorkgroupSize: [3]int{64, 1, 1}, Bindings: []explicit.ShaderBinding{
			{Name: "params", Group: 0, Binding: 0, Kind: explicit.BindingUniformBuffer, Register: explicit.ShaderRegister{Class: "b", Space: 0, Index: 0}},
			{Name: "input", Group: 0, Binding: 1, Kind: explicit.BindingStorageBufferReadOnly, Register: explicit.ShaderRegister{Class: "t", Space: 0, Index: 1}},
			{Name: "output", Group: 0, Binding: 2, Kind: explicit.BindingStorageBuffer, Register: explicit.ShaderRegister{Class: "u", Space: 0, Index: 2}},
		}},
		{Name: "cs_paint", Stage: explicit.ShaderStageCompute, WorkgroupSize: [3]int{2, 2, 1}, Bindings: []explicit.ShaderBinding{
			{Name: "img", Group: 1, Binding: 0, Kind: explicit.BindingStorageTexture, StorageFormat: explicit.TextureFormatRGBA8Unorm, Register: explicit.ShaderRegister{Class: "u", Space: 1, Index: 0}},
		}},
		{Name: "cs_draw_args", Stage: explicit.ShaderStageCompute, WorkgroupSize: [3]int{1, 1, 1}, Bindings: []explicit.ShaderBinding{
			{Name: "args", Group: 1, Binding: 1, Kind: explicit.BindingStorageBuffer, Register: explicit.ShaderRegister{Class: "u", Space: 1, Index: 1}},
		}},
		{Name: "cs_indexed_args", Stage: explicit.ShaderStageCompute, WorkgroupSize: [3]int{1, 1, 1}, Bindings: []explicit.ShaderBinding{
			{Name: "args", Group: 1, Binding: 1, Kind: explicit.BindingStorageBuffer, Register: explicit.ShaderRegister{Class: "u", Space: 1, Index: 1}},
		}},
		{Name: "cs_dispatch_args", Stage: explicit.ShaderStageCompute, WorkgroupSize: [3]int{1, 1, 1}, Bindings: []explicit.ShaderBinding{
			{Name: "params", Group: 0, Binding: 0, Kind: explicit.BindingUniformBuffer, Register: explicit.ShaderRegister{Class: "b", Space: 0, Index: 0}},
			{Name: "args", Group: 1, Binding: 1, Kind: explicit.BindingStorageBuffer, Register: explicit.ShaderRegister{Class: "u", Space: 1, Index: 1}},
		}},
	},
}

ShaderCompute is shaders/compute.wgsl.

Flutter: no counterpart

View Source
var ShaderFill = &explicit.Shader{
	Name: "fill",
	WGSL: `// Full-screen scenes of the device tests (SPEC §27.12): a triangle that covers the target, and
// fragment shaders that write constants of every output type.

@vertex
fn vs_full(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> {
	var p = array<vec2<f32>, 3>(vec2<f32>(-1.0, -1.0), vec2<f32>(3.0, -1.0), vec2<f32>(-1.0, 3.0));
	return vec4<f32>(p[i], 0.0, 1.0);
}

@fragment
fn fs_float() -> @location(0) vec4<f32> {
	return vec4<f32>(0.25, 0.5, 0.75, 1.0);
}

@fragment
fn fs_uint() -> @location(0) vec4<u32> {
	return vec4<u32>(7u, 9u, 11u, 13u);
}

struct Targets {
	@location(0) a: vec4<f32>,
	@location(1) b: vec4<f32>,
	@location(2) c: vec4<u32>,
	@location(3) d: vec4<f32>,
}

@fragment
fn fs_four() -> Targets {
	var out: Targets;
	out.a = vec4<f32>(1.0, 0.0, 0.0, 0.5);
	out.b = vec4<f32>(1.0, 0.0, 0.0, 0.5);
	out.c = vec4<u32>(42u, 0u, 0u, 0u);
	out.d = vec4<f32>(0.5, 1.5, 2.5, 3.5);
	return out;
}
`,
	SPIRV: spirvFill,
	HLSL: `struct Targets {
    float4 a : SV_Target0;
    float4 b : SV_Target1;
    uint4 c : SV_Target2;
    float4 d : SV_Target3;
};

typedef float2 ret_Constructarray3_float2_[3];
ret_Constructarray3_float2_ Constructarray3_float2_(float2 arg0, float2 arg1, float2 arg2) {
    float2 ret[3] = { arg0, arg1, arg2 };
    return ret;
}

float4 vs_full(uint i : SV_VertexID) : SV_Position
{
    float2 p[3] = Constructarray3_float2_(float2(-1.0, -1.0), float2(3.0, -1.0), float2(-1.0, 3.0));

    float2 _e13 = p[min(uint(i), 2u)];
    return float4(_e13, 0.0, 1.0);
}

float4 fs_float() : SV_Target0
{
    return float4(0.25, 0.5, 0.75, 1.0);
}

uint4 fs_uint() : SV_Target0
{
    return uint4(7u, 9u, 11u, 13u);
}

Targets fs_four()
{
    Targets out_ = (Targets)0;

    out_.a = float4(1.0, 0.0, 0.0, 0.5);
    out_.b = float4(1.0, 0.0, 0.0, 0.5);
    out_.c = uint4(42u, 0u, 0u, 0u);
    out_.d = float4(0.5, 1.5, 2.5, 3.5);
    Targets _e25 = out_;
    Targets targets = _e25;
    return targets;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "vs_full", Stage: explicit.ShaderStageVertex, ReadsVertexIndex: true, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_float", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_uint", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_four", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
	},
}

ShaderFill is shaders/fill.wgsl.

Flutter: no counterpart

View Source
var ShaderInstance = &explicit.Shader{
	Name: "instance",
	WGSL: `// Two instances of a quad drawn as a triangle strip: instance 0 covers the left half of the target in
// red, instance 1 the right half in green (the instance index, SPEC §27.1).

struct VertexOut {
	@builtin(position) pos: vec4<f32>,
	@location(0) color: vec4<f32>,
}

@vertex
fn vs_instance(@builtin(vertex_index) v: u32, @builtin(instance_index) i: u32) -> VertexOut {
	var corner = array<vec2<f32>, 4>(vec2<f32>(0.0, 0.0), vec2<f32>(1.0, 0.0), vec2<f32>(0.0, 1.0), vec2<f32>(1.0, 1.0));
	var out: VertexOut;
	out.pos = vec4<f32>(-1.0 + corner[v].x + f32(i), -1.0 + 2.0 * corner[v].y, 0.0, 1.0);
	out.color = select(vec4<f32>(0.0, 1.0, 0.0, 1.0), vec4<f32>(1.0, 0.0, 0.0, 1.0), i == 0u);
	return out;
}

@fragment
fn fs_instance(in: VertexOut) -> @location(0) vec4<f32> {
	return in.color;
}
`,
	SPIRV: spirvInstance,
	HLSL: `struct VertexOut {
    float4 pos : SV_Position;
    float4 color : LOC0;
};

struct VertexOutput_vs_instance {
    float4 color : LOC0;
    float4 pos : SV_Position;
};

struct FragmentInput_fs_instance {
    float4 color_1 : LOC0;
    float4 pos_1 : SV_Position;
};

typedef float2 ret_Constructarray4_float2_[4];
ret_Constructarray4_float2_ Constructarray4_float2_(float2 arg0, float2 arg1, float2 arg2, float2 arg3) {
    float2 ret[4] = { arg0, arg1, arg2, arg3 };
    return ret;
}

VertexOutput_vs_instance vs_instance(uint v : SV_VertexID, uint i : SV_InstanceID)
{
    float2 corner[4] = Constructarray4_float2_(float2(0.0, 0.0), float2(1.0, 0.0), float2(0.0, 1.0), float2(1.0, 1.0));
    VertexOut out_ = (VertexOut)0;

    float _e20 = corner[min(uint(v), 3u)].x;
    float _e27 = corner[min(uint(v), 3u)].y;
    out_.pos = float4(((-1.0 + _e20) + float(i)), (-1.0 + (2.0 * _e27)), 0.0, 1.0);
    out_.color = ((i == 0u) ? float4(1.0, 0.0, 0.0, 1.0) : float4(0.0, 1.0, 0.0, 1.0));
    VertexOut _e49 = out_;
    VertexOut vertexout = _e49;
    VertexOutput_vs_instance vertexout_1 = { vertexout.color, vertexout.pos };
    return vertexout_1;
}

float4 fs_instance(FragmentInput_fs_instance fragmentinput_fs_instance) : SV_Target0
{
    VertexOut in_ = { fragmentinput_fs_instance.pos_1, fragmentinput_fs_instance.color_1 };
    return in_.color;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "vs_instance", Stage: explicit.ShaderStageVertex, ReadsInstanceIndex: true, ReadsVertexIndex: true, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_instance", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
	},
}

ShaderInstance is shaders/instance.wgsl.

Flutter: no counterpart

View Source
var ShaderSample = &explicit.Shader{
	Name: "sample",
	WGSL: `// Textures of every dimension and sample type, read into a color target (the texture scenes of the
// device tests). Params.v is the direction of the cube, or the layer or depth in z.

struct Params {
	v: vec4<f32>,
}

@group(0) @binding(0) var<uniform> params: Params;
@group(1) @binding(0) var cubeTex: texture_cube<f32>;
@group(1) @binding(1) var arrayTex: texture_2d_array<f32>;
@group(1) @binding(2) var volumeTex: texture_3d<f32>;
@group(1) @binding(3) var smp: sampler;
@group(1) @binding(4) var uintTex: texture_2d<u32>;
@group(1) @binding(5) var floatTex: texture_2d<f32>;

struct VertexOut {
	@builtin(position) pos: vec4<f32>,
	@location(0) uv: vec2<f32>,
}

@vertex
fn vs_uv(@builtin(vertex_index) i: u32) -> VertexOut {
	var p = array<vec2<f32>, 3>(vec2<f32>(-1.0, -1.0), vec2<f32>(3.0, -1.0), vec2<f32>(-1.0, 3.0));
	var out: VertexOut;
	out.pos = vec4<f32>(p[i], 0.0, 1.0);
	out.uv = vec2<f32>((p[i].x + 1.0) * 0.5, (1.0 - p[i].y) * 0.5);
	return out;
}

@fragment
fn fs_cube(in: VertexOut) -> @location(0) vec4<f32> {
	return textureSample(cubeTex, smp, params.v.xyz);
}

@fragment
fn fs_array(in: VertexOut) -> @location(0) vec4<f32> {
	return textureSample(arrayTex, smp, in.uv, i32(params.v.z));
}

@fragment
fn fs_volume(in: VertexOut) -> @location(0) vec4<f32> {
	return textureSample(volumeTex, smp, vec3<f32>(in.uv, params.v.z));
}

@fragment
fn fs_uint(in: VertexOut) -> @location(0) vec4<f32> {
	let v = textureLoad(uintTex, vec2<i32>(in.pos.xy), 0);
	return vec4<f32>(f32(v.x) / 255.0, f32(v.y) / 255.0, 0.0, 1.0);
}

@fragment
fn fs_float(in: VertexOut) -> @location(0) vec4<f32> {
	return textureLoad(floatTex, vec2<i32>(in.pos.xy), 0);
}
`,
	SPIRV: spirvSample,
	HLSL: `struct Params {
    float4 v;
};

struct VertexOut {
    float4 pos : SV_Position;
    float2 uv : LOC0;
};

cbuffer params : register(b0, space0) { Params params; }
TextureCube<float4> cubeTex : register(t0, space1);
Texture2DArray<float4> arrayTex : register(t1, space1);
Texture3D<float4> volumeTex : register(t2, space1);
SamplerState smp : register(s3, space1);
Texture2D<uint4> uintTex : register(t4, space1);
Texture2D<float4> floatTex : register(t5, space1);

struct VertexOutput_vs_uv {
    float2 uv : LOC0;
    float4 pos : SV_Position;
};

struct FragmentInput_fs_cube {
    float2 uv_1 : LOC0;
    float4 pos_1 : SV_Position;
};

struct FragmentInput_fs_array {
    float2 uv_2 : LOC0;
    float4 pos_2 : SV_Position;
};

struct FragmentInput_fs_volume {
    float2 uv_3 : LOC0;
    float4 pos_3 : SV_Position;
};

struct FragmentInput_fs_uint {
    float2 uv_4 : LOC0;
    float4 pos_4 : SV_Position;
};

struct FragmentInput_fs_float {
    float2 uv_5 : LOC0;
    float4 pos_5 : SV_Position;
};

typedef float2 ret_Constructarray3_float2_[3];
ret_Constructarray3_float2_ Constructarray3_float2_(float2 arg0, float2 arg1, float2 arg2) {
    float2 ret[3] = { arg0, arg1, arg2 };
    return ret;
}

VertexOutput_vs_uv vs_uv(uint i : SV_VertexID)
{
    float2 p[3] = Constructarray3_float2_(float2(-1.0, -1.0), float2(3.0, -1.0), float2(-1.0, 3.0));
    VertexOut out_ = (VertexOut)0;

    float2 _e15 = p[min(uint(i), 2u)];
    out_.pos = float4(_e15, 0.0, 1.0);
    float _e22 = p[min(uint(i), 2u)].x;
    float _e29 = p[min(uint(i), 2u)].y;
    out_.uv = float2(((_e22 + 1.0) * 0.5), ((1.0 - _e29) * 0.5));
    VertexOut _e35 = out_;
    VertexOut vertexout = _e35;
    VertexOutput_vs_uv vertexout_1 = { vertexout.uv, vertexout.pos };
    return vertexout_1;
}

float4 fs_cube(FragmentInput_fs_cube fragmentinput_fs_cube) : SV_Target0
{
    VertexOut in_ = { fragmentinput_fs_cube.pos_1, fragmentinput_fs_cube.uv_1 };
    float4 _e5 = params.v;
    float4 _e7 = cubeTex.Sample(smp, _e5.xyz);
    return _e7;
}

int naga_f2i32(float value) {
    return int(clamp(value, -2147483600.0, 2147483500.0));
}

float4 fs_array(FragmentInput_fs_array fragmentinput_fs_array) : SV_Target0
{
    VertexOut in_1 = { fragmentinput_fs_array.pos_2, fragmentinput_fs_array.uv_2 };
    float _e7 = params.v.z;
    float4 _e9 = arrayTex.Sample(smp, float3(in_1.uv, naga_f2i32(_e7)));
    return _e9;
}

float4 fs_volume(FragmentInput_fs_volume fragmentinput_fs_volume) : SV_Target0
{
    VertexOut in_2 = { fragmentinput_fs_volume.pos_3, fragmentinput_fs_volume.uv_3 };
    float _e7 = params.v.z;
    float4 _e9 = volumeTex.Sample(smp, float3(in_2.uv, _e7));
    return _e9;
}

int2 naga_f2i32(float2 value) {
    return int2(clamp(value, -2147483600.0, 2147483500.0));
}

float4 fs_uint(FragmentInput_fs_uint fragmentinput_fs_uint) : SV_Target0
{
    VertexOut in_3 = { fragmentinput_fs_uint.pos_4, fragmentinput_fs_uint.uv_4 };
    uint4 v = uintTex.Load(int3(naga_f2i32(in_3.pos.xy), int(0)));
    return float4((float(v.x) / 255.0), (float(v.y) / 255.0), 0.0, 1.0);
}

float4 fs_float(FragmentInput_fs_float fragmentinput_fs_float) : SV_Target0
{
    VertexOut in_4 = { fragmentinput_fs_float.pos_5, fragmentinput_fs_float.uv_5 };
    float4 _e6 = floatTex.Load(int3(naga_f2i32(in_4.pos.xy), int(0)));
    return _e6;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "vs_uv", Stage: explicit.ShaderStageVertex, ReadsVertexIndex: true, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_cube", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{
			{Name: "params", Group: 0, Binding: 0, Kind: explicit.BindingUniformBuffer, Register: explicit.ShaderRegister{Class: "b", Space: 0, Index: 0}},
			{Name: "cubeTex", Group: 1, Binding: 0, Kind: explicit.BindingSampledTexture, Dimension: explicit.TextureDimCube, Register: explicit.ShaderRegister{Class: "t", Space: 1, Index: 0}},
			{Name: "smp", Group: 1, Binding: 3, Kind: explicit.BindingSampler, Register: explicit.ShaderRegister{Class: "s", Space: 1, Index: 3}},
		}},
		{Name: "fs_array", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{
			{Name: "params", Group: 0, Binding: 0, Kind: explicit.BindingUniformBuffer, Register: explicit.ShaderRegister{Class: "b", Space: 0, Index: 0}},
			{Name: "arrayTex", Group: 1, Binding: 1, Kind: explicit.BindingSampledTexture, Dimension: explicit.TextureDim2DArray, Register: explicit.ShaderRegister{Class: "t", Space: 1, Index: 1}},
			{Name: "smp", Group: 1, Binding: 3, Kind: explicit.BindingSampler, Register: explicit.ShaderRegister{Class: "s", Space: 1, Index: 3}},
		}},
		{Name: "fs_volume", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{
			{Name: "params", Group: 0, Binding: 0, Kind: explicit.BindingUniformBuffer, Register: explicit.ShaderRegister{Class: "b", Space: 0, Index: 0}},
			{Name: "volumeTex", Group: 1, Binding: 2, Kind: explicit.BindingSampledTexture, Dimension: explicit.TextureDim3D, Register: explicit.ShaderRegister{Class: "t", Space: 1, Index: 2}},
			{Name: "smp", Group: 1, Binding: 3, Kind: explicit.BindingSampler, Register: explicit.ShaderRegister{Class: "s", Space: 1, Index: 3}},
		}},
		{Name: "fs_uint", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{
			{Name: "uintTex", Group: 1, Binding: 4, Kind: explicit.BindingSampledTexture, Sample: explicit.SampleTypeUint, Register: explicit.ShaderRegister{Class: "t", Space: 1, Index: 4}},
		}},
		{Name: "fs_float", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{
			{Name: "floatTex", Group: 1, Binding: 5, Kind: explicit.BindingSampledTexture, Sample: explicit.SampleTypeUnfilterableFloat, Register: explicit.ShaderRegister{Class: "t", Space: 1, Index: 5}},
		}},
	},
}

ShaderSample is shaders/sample.wgsl.

Flutter: no counterpart

View Source
var ShaderTri = &explicit.Shader{
	Name: "tri",
	WGSL: `// Triangles with a position and a color from a vertex buffer (the depth, stencil, culling, topology,
// write mask and multisampling scenes of the device tests).

struct VertexOut {
	@builtin(position) pos: vec4<f32>,
	@location(0) color: vec4<f32>,
}

@vertex
fn vs_tri(@location(0) pos: vec3<f32>, @location(1) color: vec4<f32>) -> VertexOut {
	var out: VertexOut;
	out.pos = vec4<f32>(pos, 1.0);
	out.color = color;
	return out;
}

@fragment
fn fs_tri(in: VertexOut) -> @location(0) vec4<f32> {
	return in.color;
}
`,
	SPIRV: spirvTri,
	HLSL: `struct VertexOut {
    float4 pos : SV_Position;
    float4 color : LOC0;
};

struct VertexOutput_vs_tri {
    float4 color_1 : LOC0;
    float4 pos_1 : SV_Position;
};

struct FragmentInput_fs_tri {
    float4 color_2 : LOC0;
    float4 pos_2 : SV_Position;
};

VertexOutput_vs_tri vs_tri(float3 pos : LOC0, float4 color : LOC1)
{
    VertexOut out_ = (VertexOut)0;

    out_.pos = float4(pos, 1.0);
    out_.color = color;
    VertexOut _e7 = out_;
    VertexOut vertexout = _e7;
    VertexOutput_vs_tri vertexout_1 = { vertexout.color, vertexout.pos };
    return vertexout_1;
}

float4 fs_tri(FragmentInput_fs_tri fragmentinput_fs_tri) : SV_Target0
{
    VertexOut in_ = { fragmentinput_fs_tri.pos_2, fragmentinput_fs_tri.color_2 };
    return in_.color;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "vs_tri", Stage: explicit.ShaderStageVertex, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_tri", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
	},
}

ShaderTri is shaders/tri.wgsl.

Flutter: no counterpart

View Source
var ShaderVformats = &explicit.Shader{
	Name: "vformats",
	WGSL: `// Vertex attributes of several formats (the vertex format scene of the device tests): a position
// from snorm16x2, a color from unorm8x4, an id from uint32, a half float and bytes of uint8x4.

struct VertexOut {
	@builtin(position) pos: vec4<f32>,
	@location(0) color: vec4<f32>,
}

@vertex
fn vs_formats(
	@location(0) p: vec2<f32>,
	@location(1) c: vec4<f32>,
	@location(2) id: u32,
	@location(3) h: vec2<f32>,
	@location(4) b: vec4<u32>,
) -> VertexOut {
	var out: VertexOut;
	out.pos = vec4<f32>(p, 0.0, 1.0);
	out.color = vec4<f32>(c.r, f32(id) / 255.0, h.x, f32(b.x) / 255.0);
	return out;
}

@fragment
fn fs_formats(in: VertexOut) -> @location(0) vec4<f32> {
	return in.color;
}
`,
	SPIRV: spirvVformats,
	HLSL: `struct VertexOut {
    float4 pos : SV_Position;
    float4 color : LOC0;
};

struct VertexOutput_vs_formats {
    float4 color : LOC0;
    float4 pos : SV_Position;
};

struct FragmentInput_fs_formats {
    float4 color_1 : LOC0;
    float4 pos_1 : SV_Position;
};

VertexOutput_vs_formats vs_formats(float2 p : LOC0, float4 c : LOC1, uint id : LOC2, float2 h : LOC3, uint4 b : LOC4)
{
    VertexOut out_ = (VertexOut)0;

    out_.pos = float4(p, 0.0, 1.0);
    out_.color = float4(c.x, (float(id) / 255.0), h.x, (float(b.x) / 255.0));
    VertexOut _e21 = out_;
    VertexOut vertexout = _e21;
    VertexOutput_vs_formats vertexout_1 = { vertexout.color, vertexout.pos };
    return vertexout_1;
}

float4 fs_formats(FragmentInput_fs_formats fragmentinput_fs_formats) : SV_Target0
{
    VertexOut in_ = { fragmentinput_fs_formats.pos_1, fragmentinput_fs_formats.color_1 };
    return in_.color;
}
`,
	Entries: []explicit.EntryPoint{
		{Name: "vs_formats", Stage: explicit.ShaderStageVertex, Bindings: []explicit.ShaderBinding{}},
		{Name: "fs_formats", Stage: explicit.ShaderStageFragment, Bindings: []explicit.ShaderBinding{}},
	},
}

ShaderVformats is shaders/vformats.wgsl.

Flutter: no counterpart

Functions

func Run

func Run(t T, env *Env)

Run runs every scene as a subtest and destroys the resources each one made.

Flutter: no counterpart

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector is a T that records the failures instead of reporting them to a test runner, for a program that is not a test. Its parts run one after the other on the calling goroutine.

Flutter: no counterpart

func NewCollector

func NewCollector() (*Collector, func() []Result)

NewCollector returns the T for the scenes of a program, and the function that returns the results of every part that ran, a part that has parts of its own included.

Flutter: no counterpart

func (*Collector) Errorf

func (c *Collector) Errorf(format string, args ...any)

Errorf implements T.

func (*Collector) Fatalf

func (c *Collector) Fatalf(format string, args ...any)

Fatalf implements T.

func (*Collector) Helper

func (c *Collector) Helper()

Helper implements T.

func (*Collector) Run

func (c *Collector) Run(name string, fn func(t T))

Run implements T.

func (*Collector) Skipf

func (c *Collector) Skipf(format string, args ...any)

Skipf implements T.

type Env

type Env struct {
	// Dev is the device under test.
	Dev explicit.Device
	// Pixels says that the device draws, so that the scenes compare what they read back. The fake
	// device does not: its scenes check only that the descriptors are valid.
	Pixels bool
	// Settle does what lets the reads of the frames submitted so far be delivered, and is called
	// until they are (30 seconds at most). A device that waits for the GPU in Submit needs nothing;
	// the fake device completes the reads, and WebGPU lets the browser's event loop run.
	Settle func()
	// Memory, when set, returns the bytes that the device holds outside the Go heap (C memory, GPU
	// memory), so that the scene of many frames can tell that nothing grows. The Go heap is always
	// counted.
	Memory func() int64
	// contains filtered or unexported fields
}

Env is what a scene runs on: a device, and how to wait for the reads of a frame.

Flutter: no counterpart

type Result

type Result struct {
	// Name is the names of the scene and its parts, joined with "/".
	Name string `json:"name"`
	// Failures are the messages of the failures; empty when it passed.
	Failures []string `json:"failures"`
	// Skipped is why the part did not run, when it did not.
	Skipped string `json:"skipped,omitempty"`
}

Result is what one part of a scene came to.

Flutter: no counterpart

type Scene

type Scene struct {
	// Name names the subtest.
	Name string
	// Run draws with env.Dev and checks the result.
	Run func(t T, env *Env)
}

Scene is one test that every backend runs.

Flutter: no counterpart

func Scenes

func Scenes() []Scene

Scenes returns every scene.

Flutter: no counterpart

type T

type T interface {
	// Helper marks the calling function as a helper.
	Helper()
	// Errorf records a failure and goes on.
	Errorf(format string, args ...any)
	// Fatalf records a failure and ends the scene.
	Fatalf(format string, args ...any)
	// Skipf ends the scene or the part without a failure: the device cannot do what it tests.
	Skipf(format string, args ...any)
	// Run runs fn as a part of the scene, with a name.
	Run(name string, fn func(t T))
}

T is what a scene needs of a test: T through gotest.Wrap, and Collector for a program that is not a test (the one that runs the scenes in a browser).

Flutter: no counterpart

Directories

Path Synopsis
Package gotest adapts *testing.T to devicetest.T. It imports testing, so only tests import it.
Package gotest adapts *testing.T to devicetest.T. It imports testing, so only tests import it.

Jump to

Keyboard shortcuts

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