Skip to content

Commit

Permalink
Refactor shader/execution/expression/unary
Browse files Browse the repository at this point in the history
Issue #4178
  • Loading branch information
greggman committed Feb 25, 2025
1 parent 3d17e72 commit 2009ab8
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Execution Tests for unary address-of and indirection (dereference)

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { keysOf } from '../../../../../common/util/data_tables.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { ScalarKind, scalarType } from '../../../../util/conversion.js';
import { sparseScalarF32Range } from '../../../../util/math.js';
import {
Expand All @@ -13,7 +13,7 @@ import {
run,
} from '../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

// All the ways to deref an expression
const kDerefCases = {
Expand Down Expand Up @@ -52,12 +52,10 @@ Pointer expression dereference.
.combine('derefType', keysOf(kDerefCases))
.filter(p => !kDerefCases[p.derefType].requires_pointer_composite_access)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.scalarType === 'f16') {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const ty = scalarType(t.params.scalarType);
const cases = sparseScalarF32Range().map(e => {
return { input: ty.create(e), expected: ty.create(e) };
Expand Down Expand Up @@ -92,15 +90,15 @@ Pointer expression dereference as lhs of index accessor expression
.combine('derefType', keysOf(kDerefCases))
)
.beforeAllSubcases(t => {
if (t.params.scalarType === 'f16') {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
}
t.skipIf(
kDerefCases[t.params.derefType].requires_pointer_composite_access &&
!t.hasLanguageFeature('pointer_composite_access')
);
})
.fn(async t => {
if (t.params.scalarType === 'f16') {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
const ty = scalarType(t.params.scalarType);
const cases = sparseScalarF32Range().map(e => {
return { input: ty.create(e), expected: ty.create(e) };
Expand Down Expand Up @@ -135,15 +133,15 @@ Pointer expression dereference as lhs of member accessor expression
.combine('derefType', keysOf(kDerefCases))
)
.beforeAllSubcases(t => {
if (t.params.scalarType === 'f16') {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
}
t.skipIf(
kDerefCases[t.params.derefType].requires_pointer_composite_access &&
!t.hasLanguageFeature('pointer_composite_access')
);
})
.fn(async t => {
if (t.params.scalarType === 'f16') {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
const ty = scalarType(t.params.scalarType);
const cases = sparseScalarF32Range().map(e => {
return { input: ty.create(e), expected: ty.create(e) };
Expand Down Expand Up @@ -181,15 +179,15 @@ Pointer expression dereference as lhs of swizzle expression
.combine('derefType', keysOf(kDerefCases))
)
.beforeAllSubcases(t => {
if (t.params.scalarType === 'f16') {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
}
t.skipIf(
kDerefCases[t.params.derefType].requires_pointer_composite_access &&
!t.hasLanguageFeature('pointer_composite_access')
);
})
.fn(async t => {
if (t.params.scalarType === 'f16') {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
const ty = scalarType(t.params.scalarType);
const cases = sparseScalarF32Range().map(e => {
return { input: ty.create(e), expected: ty.create(e) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Execution Tests for Type.abstractFloat arithmetic unary expression operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './af_arithmetic.cache.js';
import { abstractFloatUnary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('negation')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Execution Tests for assignment of AbstractFloats
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import {
ShaderBuilder,
Expand All @@ -23,7 +23,7 @@ function abstract_assignment(): ShaderBuilder {
return abstractFloatShaderBuilder(value => `${value}`);
}

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('abstract')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-conversion')
Expand Down Expand Up @@ -66,11 +66,9 @@ g.test('f16')
concretizing to f16
`
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.params(u => u.combine('inputSource', onlyConstInputSource))
.fn(async t => {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
const cases = await d.get('f16');
await run(t, concrete_assignment(), [Type.abstractFloat], Type.f16, t.params, cases);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Execution Tests for the abstract integer arithmetic unary expression operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './ai_arithmetic.cache.js';
import { abstractIntUnary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('negation')
.specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Execution Tests for assignment of AbstractInts
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import {
ShaderBuilder,
Expand All @@ -23,7 +23,7 @@ function abstract_assignment(): ShaderBuilder {
return abstractIntShaderBuilder(value => `${value}`);
}

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('abstract')
.specURL('https://www.w3.org/TR/WGSL/#abstract-types')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Execution Tests for the Type.abstractInt bitwise complement operation
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { abstractInt, Type } from '../../../../util/conversion.js';
import { fullI64Range } from '../../../../util/math.js';
import { onlyConstInputSource, run } from '../expression.js';

import { abstractIntUnary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('complement')
.specURL('https://www.w3.org/TR/WGSL/#bit-expr')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Execution Tests for the boolean conversion operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import { ShaderBuilder, allInputSources, run } from '../expression.js';

import { d } from './bool_conversion.cache.js';
import { unary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

/** Generate expression builder based on how the test case is to be vectorized */
function vectorizeToExpression(vectorize: undefined | 2 | 3 | 4): ShaderBuilder {
Expand Down Expand Up @@ -108,10 +108,8 @@ The result is false if e is 0.0 or -0.0, and true otherwise.
.params(u =>
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase('shader-f16');
})
.fn(async t => {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
const cases = await d.get('f16');
await run(t, vectorizeToExpression(t.params.vectorize), [Type.f16], Type.bool, t.params, cases);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Execution Tests for the boolean unary logical expression operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { bool, Type } from '../../../../util/conversion.js';
import { allInputSources, run } from '../expression.js';

import { unary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('negation')
.specURL('https://www.w3.org/TR/WGSL/#logical-expr')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Execution Tests for the f16 arithmetic unary expression operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
import { Type } from '../../../../util/conversion.js';
import { allInputSources, run } from '../expression.js';

import { d } from './f16_arithmetic.cache.js';
import { unary } from './unary.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('negation')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
Expand All @@ -23,10 +23,8 @@ Accuracy: Correctly rounded
.params(u =>
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
const cases = await d.get('negation');
await run(t, unary('-'), [Type.f16], Type.f16, t.params, cases);
});
Loading

0 comments on commit 2009ab8

Please sign in to comment.