Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit TypedArray allocations #3114

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export class BufferSyncTest extends GPUTest {

// Create a 1x1 texture, and initialize it to a specified value for all elements.
async createTextureWithValue(initValue: number): Promise<GPUTexture> {
// This is not hot in profiles; optimize if this gets used more heavily.
const data = new Uint32Array(1).fill(initValue);
const texture = this.trackForCleanup(
this.device.createTexture({
Expand Down Expand Up @@ -446,6 +447,7 @@ export class BufferSyncTest extends GPUTest {

// Write buffer via writeBuffer API on queue
writeByWriteBuffer(buffer: GPUBuffer, value: number) {
// This is not hot in profiles; optimize if this gets used more heavily.
const data = new Uint32Array(1).fill(value);
this.device.queue.writeBuffer(buffer, 0, data);
}
Expand Down Expand Up @@ -919,12 +921,14 @@ export class BufferSyncTest extends GPUTest {
}

verifyData(buffer: GPUBuffer, expectedValue: number) {
// This is not hot in profiles; optimize if this gets used more heavily.
const bufferData = new Uint32Array(1);
bufferData[0] = expectedValue;
this.expectGPUBufferValuesEqual(buffer, bufferData);
}

verifyDataTwoValidValues(buffer: GPUBuffer, expectedValue1: number, expectedValue2: number) {
// This is not hot in profiles; optimize if this gets used more heavily.
const bufferData1 = new Uint32Array(1);
bufferData1[0] = expectedValue1;
const bufferData2 = new Uint32Array(1);
Expand Down
5 changes: 2 additions & 3 deletions src/webgpu/shader/execution/flow_control/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ ${main_wgsl.extra}

// returns a string that shows the outputted values to help understand the whole trace.
const print_output_value = () => {
return `Output values (length: ${outputCount}): ${outputs.data
.slice(1, outputCount + 1)
.join(', ')}`;
const subarray = outputs.data.subarray(1, outputCount + 1);
return `Output values (length: ${outputCount}): ${subarray.join(', ')}`;
};

// returns a colorized string of the expect_order() call, highlighting
Expand Down
40 changes: 20 additions & 20 deletions src/webgpu/shader/execution/memory_model/memory_model_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ export class MemoryModelTester {
size: testLocationsSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE,
}),
srcBuf: this.test.makeBufferWithContents(
new Uint32Array(testLocationsSize).fill(0),
GPUBufferUsage.COPY_SRC
),
srcBuf: this.test.device.createBuffer({
size: testLocationsSize,
usage: GPUBufferUsage.COPY_SRC,
}),
size: testLocationsSize,
};

Expand All @@ -216,10 +216,10 @@ export class MemoryModelTester {
size: readResultsSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE,
}),
srcBuf: this.test.makeBufferWithContents(
new Uint32Array(readResultsSize).fill(0),
GPUBufferUsage.COPY_SRC
),
srcBuf: this.test.device.createBuffer({
size: readResultsSize,
usage: GPUBufferUsage.COPY_SRC,
}),
size: readResultsSize,
};

Expand All @@ -229,10 +229,10 @@ export class MemoryModelTester {
size: testResultsSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
}),
srcBuf: this.test.makeBufferWithContents(
new Uint32Array(testResultsSize).fill(0),
GPUBufferUsage.COPY_SRC
),
srcBuf: this.test.device.createBuffer({
size: testResultsSize,
usage: GPUBufferUsage.COPY_SRC,
}),
size: testResultsSize,
};

Expand All @@ -255,10 +255,10 @@ export class MemoryModelTester {
size: barrierSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE,
}),
srcBuf: this.test.makeBufferWithContents(
new Uint32Array(barrierSize).fill(0),
GPUBufferUsage.COPY_SRC
),
srcBuf: this.test.device.createBuffer({
size: barrierSize,
usage: GPUBufferUsage.COPY_SRC,
}),
size: barrierSize,
};

Expand All @@ -268,10 +268,10 @@ export class MemoryModelTester {
size: scratchpadSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE,
}),
srcBuf: this.test.makeBufferWithContents(
new Uint32Array(scratchpadSize).fill(0),
GPUBufferUsage.COPY_SRC
),
srcBuf: this.test.device.createBuffer({
size: scratchpadSize,
usage: GPUBufferUsage.COPY_SRC,
}),
size: scratchpadSize,
};

Expand Down
2 changes: 2 additions & 0 deletions src/webgpu/web_platform/reftests/canvas_colorspace.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { kCanvasAlphaModes, kCanvasColorSpaces } from '../../capability_info.js'
import { runRefTest } from './gpu_ref_test.js';

function bgra8UnormFromRgba8Unorm(rgba8Unorm: Uint8Array) {
// This is used only once. May need to optimize if reused.
const bgra8Unorm = rgba8Unorm.slice();
for (let i = 0; i < bgra8Unorm.length; i += 4) {
[bgra8Unorm[i], bgra8Unorm[i + 2]] = [bgra8Unorm[i + 2], bgra8Unorm[i]];
Expand All @@ -13,6 +14,7 @@ function bgra8UnormFromRgba8Unorm(rgba8Unorm: Uint8Array) {
}

function rgba16floatFromRgba8unorm(rgba8Unorm: Uint8Array) {
// This is used only once. May need to optimize if reused.
const rgba16Float = new Float16Array(rgba8Unorm.length);
for (let i = 0; i < rgba8Unorm.length; ++i) {
rgba16Float[i] = rgba8Unorm[i] / 255;
Expand Down
1 change: 1 addition & 0 deletions src/webgpu/web_platform/reftests/canvas_complex.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function run(
size: rows * bytesPerRow,
usage: GPUBufferUsage.COPY_SRC,
});
// These are run only once per test, so there are no wasted reallocations below.
let red: Uint8Array | Uint16Array;
let green: Uint8Array | Uint16Array;
let blue: Uint8Array | Uint16Array;
Expand Down