1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
export const description = `
Basic tests.
`;
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { memcpy } from '../../../../common/util/util.js';
import { GPUTest } from '../../../gpu_test.js';
export const g = makeTestGroup(GPUTest);
g.test('empty').fn(async t => {
const encoder = t.device.createCommandEncoder();
const cmd = encoder.finish();
t.device.queue.submit([cmd]);
});
g.test('b2t2b').fn(async t => {
const data = new Uint32Array([0x01020304]);
const src = t.device.createBuffer({
mappedAtCreation: true,
size: 4,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
memcpy({ src: data }, { dst: src.getMappedRange() });
src.unmap();
const dst = t.device.createBuffer({
size: 4,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
const mid = t.device.createTexture({
size: { width: 1, height: 1, depthOrArrayLayers: 1 },
format: 'rgba8uint',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
});
const encoder = t.device.createCommandEncoder();
encoder.copyBufferToTexture(
{ buffer: src, bytesPerRow: 256 },
{ texture: mid, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ width: 1, height: 1, depthOrArrayLayers: 1 }
);
encoder.copyTextureToBuffer(
{ texture: mid, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ buffer: dst, bytesPerRow: 256 },
{ width: 1, height: 1, depthOrArrayLayers: 1 }
);
t.device.queue.submit([encoder.finish()]);
t.expectGPUBufferValuesEqual(dst, data);
});
g.test('b2t2t2b').fn(async t => {
const data = new Uint32Array([0x01020304]);
const src = t.device.createBuffer({
mappedAtCreation: true,
size: 4,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
memcpy({ src: data }, { dst: src.getMappedRange() });
src.unmap();
const dst = t.device.createBuffer({
size: 4,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
const midDesc: GPUTextureDescriptor = {
size: { width: 1, height: 1, depthOrArrayLayers: 1 },
format: 'rgba8uint',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
};
const mid1 = t.device.createTexture(midDesc);
const mid2 = t.device.createTexture(midDesc);
const encoder = t.device.createCommandEncoder();
encoder.copyBufferToTexture(
{ buffer: src, bytesPerRow: 256 },
{ texture: mid1, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ width: 1, height: 1, depthOrArrayLayers: 1 }
);
encoder.copyTextureToTexture(
{ texture: mid1, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ texture: mid2, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ width: 1, height: 1, depthOrArrayLayers: 1 }
);
encoder.copyTextureToBuffer(
{ texture: mid2, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
{ buffer: dst, bytesPerRow: 256 },
{ width: 1, height: 1, depthOrArrayLayers: 1 }
);
t.device.queue.submit([encoder.finish()]);
t.expectGPUBufferValuesEqual(dst, data);
});
|