Skip to content
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
20 changes: 20 additions & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,23 @@ export function combinationsOfOneOrTwoUsages(usages: readonly number[]) {
}
return combinations;
}

/**
* Checks if the browser supports immediate data (experimental).
*
* Checks for:
* - `setImmediates` method on `GPURenderPassEncoder`, `GPUComputePassEncoder`, or `GPURenderBundleEncoder` prototypes.
* - `maxImmediateSize` property on `GPUSupportedLimits` prototype.
* - `immediate_address_space` feature in `gpu.wgslLanguageFeatures`.
*
* This helper is used to skip tests when the environment does not support immediate data functionality.
*/
export function supportsImmediateData(gpu: GPU): boolean {
return (
'setImmediates' in GPURenderPassEncoder.prototype ||
'setImmediates' in GPUComputePassEncoder.prototype ||
'setImmediates' in GPURenderBundleEncoder.prototype ||
'maxImmediateSize' in GPUSupportedLimits.prototype ||
gpu.wgslLanguageFeatures.has('immediate_address_space')
);
}
220 changes: 110 additions & 110 deletions src/resources/cache/hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/resources/cache/webgpu/shader/execution/bitcast.bin
Binary file not shown.
27 changes: 6 additions & 21 deletions src/webgpu/api/validation/encoding/cmds/setImmediates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ import { getGPU } from '../../../../../common/util/navigator_gpu.js';
import {
kTypedArrayBufferViews,
kTypedArrayBufferViewKeys,
supportsImmediateData,
} from '../../../../../common/util/util.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { kProgrammableEncoderTypes } from '../../../../util/command_buffer_maker.js';

class SetImmediatesTest extends AllFeaturesMaxLimitsGPUTest {
override async init() {
await super.init();
if (
!('setImmediates' in GPURenderPassEncoder.prototype) &&
!('setImmediates' in GPUComputePassEncoder.prototype) &&
!('setImmediates' in GPURenderBundleEncoder.prototype) &&
!('maxImmediateSize' in GPUSupportedLimits.prototype) &&
!getGPU(this.rec).wgslLanguageFeatures.has('immediate_address_space')
) {
if (!supportsImmediateData(getGPU(this.rec))) {
this.skip('setImmediates not supported');
}
}
Expand Down Expand Up @@ -66,10 +61,7 @@ g.test('alignment')
const data = new arrayBufferType(elementCount);

t.shouldThrow(isContentSizeAligned ? false : 'RangeError', () => {
// Cast to any to avoid Float16Array issues
// MAINTENANCE_TODO: remove this cast when the types are updated.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(encoder as any).setImmediates(rangeOffset, data as any, 0, elementCount);
encoder.setImmediates!(rangeOffset, data, 0, elementCount);
});

validateFinish(isRangeOffsetAligned);
Expand Down Expand Up @@ -128,10 +120,7 @@ g.test('overflow')
const data = new arrayBufferType(elementCount);

const doSetImmediates = () => {
// Cast to any to avoid Float16Array issues
// MAINTENANCE_TODO: remove this cast when the types are updated.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(encoder as any).setImmediates(rangeOffset, data as any, dataOffset, elementCount);
encoder.setImmediates!(rangeOffset, data, dataOffset, elementCount);
};

if (_expectedError === 'RangeError') {
Expand Down Expand Up @@ -168,9 +157,7 @@ g.test('out_of_bounds')
const arrayBufferType = kTypedArrayBufferViews[arrayType];
const elementSize = arrayBufferType.BYTES_PER_ELEMENT;

// MAINTENANCE_TODO: remove this cast when the types are updated.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const maxImmediateSize = (t.device.limits as any).maxImmediateSize;
const maxImmediateSize = t.device.limits.maxImmediateSize!;
if (maxImmediateSize === undefined) {
t.skip('maxImmediateSize not found');
}
Expand All @@ -191,9 +178,7 @@ g.test('out_of_bounds')
const dataOverLimit = elementCount > dataLength;

t.shouldThrow(dataOverLimit ? 'RangeError' : false, () => {
// MAINTENANCE_TODO: remove this cast when the types are updated.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(encoder as any).setImmediates(rangeOffset, data as any, 0, elementCount);
encoder.setImmediates!(rangeOffset, data, 0, elementCount);
});

if (!dataOverLimit) {
Expand Down
Loading