-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathbuffer_related.spec.ts
More file actions
243 lines (218 loc) · 8.34 KB
/
buffer_related.spec.ts
File metadata and controls
243 lines (218 loc) · 8.34 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
export const description = `Validation tests for buffer related parameters for buffer <-> texture copies`;
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kTextureDimensions } from '../../../capability_info.js';
import { GPUConst } from '../../../constants.js';
import {
aspectParamsForTextureFormat,
kTextureFormatInfo,
textureDimensionAndFormatCompatible,
} from '../../../format_info.js';
import { kResourceStates } from '../../../gpu_test.js';
import { kImageCopyTypes } from '../../../util/texture/layout.js';
import { ImageCopyTest, aspectCopyableWithMethod, kReducedFormatsList } from './image_copy.js';
export const g = makeTestGroup(ImageCopyTest);
g.test('buffer_state')
.desc(
`
Test that the buffer must be valid and not destroyed.
- for all buffer <-> texture copy methods
- for various buffer states
`
)
.params(u =>
u //
// B2B copy validations are at api,validation,encoding,cmds,copyBufferToBuffer.spec.ts
.combine('method', ['CopyB2T', 'CopyT2B'] as const)
.combine('state', kResourceStates)
)
.fn(t => {
const { method, state } = t.params;
// A valid buffer.
const buffer = t.createBufferWithState(state, {
size: 16,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
// Invalid buffer will fail finish, and destroyed buffer will fail submit
const submit = state !== 'invalid';
const success = state === 'valid';
const texture = t.device.createTexture({
size: { width: 2, height: 2, depthOrArrayLayers: 1 },
format: 'rgba8unorm',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
});
t.testBuffer(
buffer,
{ texture },
{ bytesPerRow: 0 },
{ width: 0, height: 0, depthOrArrayLayers: 0 },
{ dataSize: 16, method, success, submit }
);
});
g.test('buffer,device_mismatch')
.desc('Tests the image copies cannot be called with a buffer created from another device')
.paramsSubcasesOnly(u =>
u.combine('method', ['CopyB2T', 'CopyT2B'] as const).combine('mismatched', [true, false])
)
.beforeAllSubcases(t => {
t.selectMismatchedDeviceOrSkipTestCase(undefined);
})
.fn(t => {
const { method, mismatched } = t.params;
const sourceDevice = mismatched ? t.mismatchedDevice : t.device;
const buffer = sourceDevice.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
t.trackForCleanup(buffer);
const texture = t.device.createTexture({
size: { width: 2, height: 2, depthOrArrayLayers: 1 },
format: 'rgba8unorm',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
});
const success = !mismatched;
// Expect success in both finish and submit, or validation error in finish
t.testBuffer(
buffer,
{ texture },
{ bytesPerRow: 0 },
{ width: 0, height: 0, depthOrArrayLayers: 0 },
{ dataSize: 16, method, success, submit: success }
);
});
g.test('usage')
.desc(
`
Test the buffer must have the appropriate COPY_SRC/COPY_DST usage.
TODO update such that it tests
- for all buffer source usages
- for all buffer destination usages
`
)
.params(u =>
u
// B2B copy validations are at api,validation,encoding,cmds,copyBufferToBuffer.spec.ts
.combine('method', ['CopyB2T', 'CopyT2B'] as const)
.beginSubcases()
.combine('usage', [
GPUConst.BufferUsage.COPY_SRC | GPUConst.BufferUsage.UNIFORM,
GPUConst.BufferUsage.COPY_DST | GPUConst.BufferUsage.UNIFORM,
GPUConst.BufferUsage.COPY_SRC | GPUConst.BufferUsage.COPY_DST,
])
)
.fn(t => {
const { method, usage } = t.params;
const buffer = t.device.createBuffer({
size: 16,
usage,
});
const success =
method === 'CopyB2T'
? (usage & GPUBufferUsage.COPY_SRC) !== 0
: (usage & GPUBufferUsage.COPY_DST) !== 0;
const texture = t.device.createTexture({
size: { width: 2, height: 2, depthOrArrayLayers: 1 },
format: 'rgba8unorm',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
});
// Expect success in both finish and submit, or validation error in finish
t.testBuffer(
buffer,
{ texture },
{ bytesPerRow: 0 },
{ width: 0, height: 0, depthOrArrayLayers: 0 },
{ dataSize: 16, method, success, submit: success }
);
});
g.test('bytes_per_row_alignment')
.desc(
`
Test that bytesPerRow must be a multiple of 256 for CopyB2T and CopyT2B if it is required.
- for all copy methods between linear data and textures
- for all texture dimensions
- for all sized (format,aspect) pairs, except for a bunch of redundant "regular" color formats
- for various bytesPerRow (aligned to 256 or not)
- for various number of blocks rows copied (0 or not)
`
)
.params(u =>
u //
.combine('method', kImageCopyTypes)
.combine('dimension', kTextureDimensions)
.combine('format', kReducedFormatsList)
.expandWithParams(p => aspectParamsForTextureFormat(p.format))
.filter(p => aspectCopyableWithMethod(p.format, p._aspectKey, p.method))
.filter(({ dimension, format }) => textureDimensionAndFormatCompatible(dimension, format))
.beginSubcases()
.combineWithParams([
// valid: height<=1
{ copyHeightInBlocks: 0, bytesPerRow: 1 },
{ copyHeightInBlocks: 0, bytesPerRow: undefined },
{ copyHeightInBlocks: 1, bytesPerRow: 1 },
{ copyHeightInBlocks: 1, bytesPerRow: undefined },
// valid: multiples of 256
{ copyHeightInBlocks: 2, bytesPerRow: 0 },
{ copyHeightInBlocks: 2, bytesPerRow: 512 },
{ copyHeightInBlocks: 2, bytesPerRow: 256 },
// valid only for writeTexture
{ copyHeightInBlocks: 2, bytesPerRow: 128 },
{ copyHeightInBlocks: 2, bytesPerRow: 1 }, // with 1-byte formats
{ copyHeightInBlocks: 2, bytesPerRow: 2 }, // with <=2-byte formats
{ copyHeightInBlocks: 2, bytesPerRow: 8 }, // with <=8-byte formats
{ copyHeightInBlocks: 2, bytesPerRow: 32 }, // with <=32-byte formats
])
.expand('_textureHeightInBlocks', p => [
p.copyHeightInBlocks === 0 ? 1 : p.copyHeightInBlocks,
])
.unless(p => p.dimension === '1d' && p.copyHeightInBlocks > 1)
// Depth/stencil format copies must copy the whole subresource.
.unless(p => p._aspectKey !== 'color' && p.copyHeightInBlocks !== p._textureHeightInBlocks)
// bytesPerRow must be specified and it must be equal or greater than the bytes size of each row if we are copying multiple rows.
// Note that we are copying one single block on each row in this test.
.filter(
({ format, _aspectKey, bytesPerRow }) =>
bytesPerRow === undefined || bytesPerRow >= kTextureFormatInfo[format][_aspectKey]!.bytes!
)
)
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
t.skipIfTextureFormatNotSupported(t.params.format);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
const {
method,
dimension,
format,
aspect,
bytesPerRow,
copyHeightInBlocks,
_textureHeightInBlocks,
} = t.params;
const info = kTextureFormatInfo[format];
const buffer = t.device.createBuffer({
size: 512 * 8 * 16,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
let success = false;
// writeTexture doesn't require bytesPerRow to be 256-byte aligned.
if (method === 'WriteTexture') success = true;
// If the copy height <= 1, bytesPerRow is not required.
if (copyHeightInBlocks <= 1 && bytesPerRow === undefined) success = true;
// If bytesPerRow > 0 and it is a multiple of 256, it will succeed if other parameters are valid.
if (bytesPerRow !== undefined && bytesPerRow > 0 && bytesPerRow % 256 === 0) success = true;
const size = [info.blockWidth, _textureHeightInBlocks * info.blockHeight, 1];
const texture = t.device.createTexture({
size,
dimension,
format,
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
});
const copySize = [info.blockWidth, copyHeightInBlocks * info.blockHeight, 1];
// Expect success in both finish and submit, or validation error in finish
t.testBuffer(buffer, { texture, aspect }, { bytesPerRow }, copySize, {
dataSize: 512 * 8 * 16,
method,
success,
submit: success,
});
});