-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
270 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const description = ``; | ||
|
||
import { TestGroup, pbool, pcombine, poptions } from '../../../framework/index.js'; | ||
|
||
import { MappingTest } from './mapping_test.js'; | ||
|
||
export const g = new TestGroup(MappingTest); | ||
|
||
g.test('createBufferMapped', async t => { | ||
const size = t.params.size; | ||
const [buffer, arrayBuffer] = t.device.createBufferMapped({ | ||
size, | ||
usage: GPUBufferUsage.COPY_SRC | (t.params.mappable ? GPUBufferUsage.MAP_WRITE : 0), | ||
}); | ||
await t.checkMapWrite(buffer, arrayBuffer, size); | ||
}).params( | ||
pcombine([ | ||
poptions('size', [12, 512 * 1024]), // | ||
pbool('mappable'), | ||
]) | ||
); | ||
|
||
g.test('createBufferMappedAsync', async t => { | ||
const size = t.params.size; | ||
const [buffer, arrayBuffer] = await t.device.createBufferMappedAsync({ | ||
size, | ||
usage: GPUBufferUsage.COPY_SRC | (t.params.mappable ? GPUBufferUsage.MAP_WRITE : 0), | ||
}); | ||
await t.checkMapWrite(buffer, arrayBuffer, size); | ||
}).params( | ||
pcombine([ | ||
poptions('size', [12, 512 * 1024]), // | ||
pbool('mappable'), | ||
]) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
export const description = ``; | ||
|
||
import { TestGroup, pbool, pcombine, poptions } from '../../../framework/index.js'; | ||
|
||
import { MappingTest } from './mapping_test.js'; | ||
|
||
export const g = new TestGroup(MappingTest); | ||
|
||
g.test('mapWriteAsync', async t => { | ||
const size = t.params.size; | ||
const buffer = t.device.createBuffer({ | ||
size, | ||
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_WRITE, | ||
}); | ||
|
||
const arrayBuffer = await buffer.mapWriteAsync(); | ||
await t.checkMapWrite(buffer, arrayBuffer, size); | ||
}).params(poptions('size', [12, 512 * 1024])); | ||
|
||
g.test('mapReadAsync', async t => { | ||
const size = t.params.size; | ||
|
||
const [buffer, init] = t.device.createBufferMapped({ | ||
size, | ||
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, | ||
}); | ||
|
||
const expected = new Uint32Array(new ArrayBuffer(size)); | ||
const data = new Uint32Array(init); | ||
for (let i = 0; i < data.length; ++i) { | ||
data[i] = expected[i] = i + 1; | ||
} | ||
buffer.unmap(); | ||
|
||
const actual = new Uint8Array(await buffer.mapReadAsync()); | ||
t.expectBuffer(actual, new Uint8Array(expected.buffer)); | ||
}).params(poptions('size', [12, 512 * 1024])); | ||
|
||
g.test('createBufferMapped', async t => { | ||
const size = t.params.size; | ||
const [buffer, arrayBuffer] = t.device.createBufferMapped({ | ||
size, | ||
usage: GPUBufferUsage.COPY_SRC | (t.params.mappable ? GPUBufferUsage.MAP_WRITE : 0), | ||
}); | ||
await t.checkMapWrite(buffer, arrayBuffer, size); | ||
}).params( | ||
pcombine([ | ||
poptions('size', [12, 512 * 1024]), // | ||
pbool('mappable'), | ||
]) | ||
); | ||
|
||
g.test('createBufferMappedAsync', async t => { | ||
const size = t.params.size; | ||
const [buffer, arrayBuffer] = await t.device.createBufferMappedAsync({ | ||
size, | ||
usage: GPUBufferUsage.COPY_SRC | (t.params.mappable ? GPUBufferUsage.MAP_WRITE : 0), | ||
}); | ||
await t.checkMapWrite(buffer, arrayBuffer, size); | ||
}).params( | ||
pcombine([ | ||
poptions('size', [12, 512 * 1024]), // | ||
pbool('mappable'), | ||
]) | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export const description = ``; | ||
|
||
import { TestGroup, pbool, pcombine } from '../../../framework/index.js'; | ||
import { GPUTest } from '../gpu_test.js'; | ||
|
||
class F extends GPUTest { | ||
checkDetach(buffer: GPUBuffer, arrayBuffer: ArrayBuffer, unmap: boolean, destroy: boolean): void { | ||
const view = new Uint8Array(arrayBuffer); | ||
this.expect(arrayBuffer.byteLength === 4); | ||
this.expect(view.length === 4); | ||
|
||
if (unmap) buffer.unmap(); | ||
if (destroy) buffer.destroy(); | ||
|
||
this.expect(arrayBuffer.byteLength === 0, 'ArrayBuffer should be detached'); | ||
this.expect(view.byteLength === 0, 'ArrayBufferView should be detached'); | ||
} | ||
} | ||
|
||
export const g = new TestGroup(F); | ||
|
||
g.test('mapWriteAsync', async t => { | ||
const buffer = t.device.createBuffer({ size: 4, usage: GPUBufferUsage.MAP_WRITE }); | ||
const arrayBuffer = await buffer.mapWriteAsync(); | ||
t.checkDetach(buffer, arrayBuffer, t.params.unmap, t.params.destroy); | ||
}).params([ | ||
{ unmap: true, destroy: false }, // | ||
{ unmap: false, destroy: true }, | ||
{ unmap: true, destroy: true }, | ||
]); | ||
|
||
g.test('mapReadAsync', async t => { | ||
const buffer = t.device.createBuffer({ size: 4, usage: GPUBufferUsage.MAP_READ }); | ||
const arrayBuffer = await buffer.mapReadAsync(); | ||
t.checkDetach(buffer, arrayBuffer, t.params.unmap, t.params.destroy); | ||
}).params([ | ||
{ unmap: true, destroy: false }, // | ||
{ unmap: false, destroy: true }, | ||
{ unmap: true, destroy: true }, | ||
]); | ||
|
||
g.test('create mapped', async t => { | ||
const desc = { | ||
size: 4, | ||
usage: GPUBufferUsage.MAP_WRITE, | ||
}; | ||
const [buffer, arrayBuffer] = t.params.async | ||
? await t.device.createBufferMappedAsync(desc) | ||
: t.device.createBufferMapped(desc); | ||
|
||
const view = new Uint8Array(arrayBuffer); | ||
t.expect(arrayBuffer.byteLength === 4); | ||
t.expect(view.length === 4); | ||
|
||
if (t.params.unmap) buffer.unmap(); | ||
if (t.params.destroy) buffer.destroy(); | ||
t.expect(arrayBuffer.byteLength === 0, 'ArrayBuffer should be detached'); | ||
t.expect(view.byteLength === 0, 'ArrayBufferView should be detached'); | ||
}).params( | ||
pcombine([ | ||
pbool('async'), // | ||
[ | ||
{ unmap: true, destroy: false }, | ||
{ unmap: false, destroy: true }, | ||
{ unmap: true, destroy: true }, | ||
], | ||
]) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export const description = ``; | ||
|
||
import { TestGroup } from '../../../framework/index.js'; | ||
import { GPUTest } from '../gpu_test.js'; | ||
|
||
function getBufferDesc(): GPUBufferDescriptor { | ||
return { | ||
size: Number.MAX_SAFE_INTEGER, | ||
usage: GPUBufferUsage.MAP_WRITE, | ||
}; | ||
} | ||
|
||
export const g = new TestGroup(GPUTest); | ||
|
||
g.test('mapWriteAsync', async t => { | ||
const buffer = t.device.createBuffer(getBufferDesc()); | ||
await t.shouldReject('RangeError', buffer.mapWriteAsync()); | ||
}); | ||
|
||
g.test('mapReadAsync', async t => { | ||
const buffer = t.device.createBuffer(getBufferDesc()); | ||
await t.shouldReject('RangeError', buffer.mapReadAsync()); | ||
}); | ||
|
||
g.test('createBufferMapped', async t => { | ||
await t.shouldThrow('RangeError', () => { | ||
t.device.createBufferMapped(getBufferDesc()); | ||
}); | ||
}); | ||
|
||
g.test('createBufferAsync', async t => { | ||
await t.shouldReject('RangeError', t.device.createBufferMappedAsync(getBufferDesc())); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GPUTest } from '../gpu_test.js'; | ||
|
||
export class MappingTest extends GPUTest { | ||
checkMapWrite(buffer: GPUBuffer, mappedContents: ArrayBuffer, size: number): Promise<void> { | ||
this.checkMapWriteZeroed(mappedContents, size); | ||
|
||
const mappedView = new Uint32Array(mappedContents); | ||
const expected = new Uint32Array(new ArrayBuffer(size)); | ||
this.expect(mappedView.byteLength === size); | ||
for (let i = 0; i < mappedView.length; ++i) { | ||
mappedView[i] = expected[i] = i + 1; | ||
} | ||
buffer.unmap(); | ||
|
||
return this.expectContents(buffer, expected); | ||
} | ||
|
||
checkMapWriteZeroed(arrayBuffer: ArrayBuffer, expectedSize: number): void { | ||
this.expect(arrayBuffer.byteLength === expectedSize); | ||
const view = new Uint8Array(arrayBuffer); | ||
this.expectZero(view); | ||
} | ||
|
||
expectZero(actual: Uint8Array): void { | ||
const size = actual.byteLength; | ||
for (let i = 0; i < size; ++i) { | ||
if (actual[i] !== 0) { | ||
this.fail(`at [${i}], expected zero, got ${actual[i]}`); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters