Skip to content
Open
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
57 changes: 33 additions & 24 deletions src/webgpu/shader/validation/shader_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ export class ShaderValidationTest extends AllFeaturesMaxLimitsGPUTest {
if (options?.autoSkipIfFeatureNotAvailable !== false) {
skipIfCodeNeedsFeatureAndDeviceDoesNotHaveFeature(this, code);
}
let shaderModule: GPUShaderModule;
this.expectGPUError(
'validation',
() => {
shaderModule = this.device.createShaderModule({ code });
},
expectedResult !== true
);

const error = new Error();
this.eventualAsyncExpectation(async () => {
const compilationInfo = await shaderModule!.getCompilationInfo();
this.eventualAsyncExpectation(async (niceStack: Error) => {
if (expectedResult !== true) {
this.device.pushErrorScope('validation');
}
const shaderModule = this.device.createShaderModule({ code });

if (expectedResult !== true) {
const gpuError = await this.device.popErrorScope();
if (!(gpuError instanceof GPUValidationError)) {
niceStack.message = `Expected validation error`;
this.rec.expectationFailed(niceStack);
}
}

const compilationInfo = await shaderModule.getCompilationInfo();

// MAINTENANCE_TODO: Pretty-print error messages with source context.
const messagesLog =
Expand All @@ -83,6 +87,7 @@ export class ShaderValidationTest extends AllFeaturesMaxLimitsGPUTest {
'\n\n---- shader ----\n' +
code;

const error = new Error();
if (compilationInfo.messages.some(m => m.type === 'error')) {
if (expectedResult) {
error.message = `Unexpected compilationInfo 'error' message.\n` + messagesLog;
Expand Down Expand Up @@ -124,7 +129,7 @@ export class ShaderValidationTest extends AllFeaturesMaxLimitsGPUTest {

const error = new Error();
this.eventualAsyncExpectation(async () => {
const compilationInfo = await shaderModule!.getCompilationInfo();
const compilationInfo = await shaderModule.getCompilationInfo();

// MAINTENANCE_TODO: Pretty-print error messages with source context.
const messagesLog = compilationInfo.messages
Expand Down Expand Up @@ -255,18 +260,21 @@ export class UniqueFeaturesAndLimitsShaderValidationTest extends UniqueFeaturesO
* ```
*/
expectCompileResult(expectedResult: boolean, code: string) {
let shaderModule: GPUShaderModule;
this.expectGPUError(
'validation',
() => {
shaderModule = this.device.createShaderModule({ code });
},
expectedResult !== true
);
this.eventualAsyncExpectation(async (niceStack: Error) => {
if (expectedResult !== true) {
this.device.pushErrorScope('validation');
}
const shaderModule = this.device.createShaderModule({ code });

const error = new Error();
this.eventualAsyncExpectation(async () => {
const compilationInfo = await shaderModule!.getCompilationInfo();
if (expectedResult !== true) {
const gpuError = await this.device.popErrorScope();
if (!(gpuError instanceof GPUValidationError)) {
niceStack.message = `Expected validation error`;
this.rec.expectationFailed(niceStack);
}
}

const compilationInfo = await shaderModule.getCompilationInfo();

// MAINTENANCE_TODO: Pretty-print error messages with source context.
const messagesLog =
Expand All @@ -276,6 +284,7 @@ export class UniqueFeaturesAndLimitsShaderValidationTest extends UniqueFeaturesO
'\n\n---- shader ----\n' +
code;

const error = new Error();
if (compilationInfo.messages.some(m => m.type === 'error')) {
if (expectedResult) {
error.message = `Unexpected compilationInfo 'error' message.\n` + messagesLog;
Expand Down Expand Up @@ -317,7 +326,7 @@ export class UniqueFeaturesAndLimitsShaderValidationTest extends UniqueFeaturesO

const error = new Error();
this.eventualAsyncExpectation(async () => {
const compilationInfo = await shaderModule!.getCompilationInfo();
const compilationInfo = await shaderModule.getCompilationInfo();

// MAINTENANCE_TODO: Pretty-print error messages with source context.
const messagesLog = compilationInfo.messages
Expand Down