Skip to content

Commit

Permalink
Add validation tests on clip_distances and maxInterStageShaderVariabl…
Browse files Browse the repository at this point in the history
…es (#3951)

* Add validation tests on clip_distances and maxInterStageShaderVariables

* Small fix

* Address reviewer's comments
  • Loading branch information
Jiawei-Shao authored Sep 19, 2024
1 parent 93c2ca0 commit 561d525
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { range } from '../../../../../common/util/util.js';
import { align } from '../../../../util/math.js';
import { kMaximumLimitBaseParams, makeLimitTestGroup } from '../limits/limit_utils.js';

function getPipelineDescriptorWithClipDistances(
device: GPUDevice,
interStageShaderVariables: number,
pointList: boolean,
clipDistances: number
): GPURenderPipelineDescriptor {
const vertexOutputVariables =
interStageShaderVariables - (pointList ? 1 : 0) - align(clipDistances, 4) / 4;
const maxVertexOutputVariables =
device.limits.maxInterStageShaderVariables - (pointList ? 1 : 0) - align(clipDistances, 4) / 4;

const varyings = `
${range(vertexOutputVariables, i => `@location(${i}) v4_${i}: vec4f,`).join('\n')}
`;

const code = `
// test value : ${interStageShaderVariables}
// maxInterStageShaderVariables : ${device.limits.maxInterStageShaderVariables}
// num variables in vertex shader : ${vertexOutputVariables}${
pointList ? ' + point-list' : ''
}${
clipDistances > 0
? ` + ${align(clipDistances, 4) / 4} (clip_distances[${clipDistances}])`
: ''
}
// maxInterStageVariables: : ${maxVertexOutputVariables}
// num used inter stage variables : ${vertexOutputVariables}
enable clip_distances;
struct VSOut {
@builtin(position) p: vec4f,
${varyings}
${
clipDistances > 0
? `@builtin(clip_distances) clipDistances: array<f32, ${clipDistances}>,`
: ''
}
}
struct FSIn {
${varyings}
}
struct FSOut {
@location(0) color: vec4f,
}
@vertex fn vs() -> VSOut {
var o: VSOut;
o.p = vec4f(0);
return o;
}
@fragment fn fs(i: FSIn) -> FSOut {
var o: FSOut;
o.color = vec4f(0);
return o;
}
`;
const module = device.createShaderModule({ code });
const pipelineDescriptor: GPURenderPipelineDescriptor = {
layout: 'auto',
primitive: {
topology: pointList ? 'point-list' : 'triangle-list',
},
vertex: {
module,
},
fragment: {
module,
targets: [
{
format: 'rgba8unorm',
},
],
},
};
return pipelineDescriptor;
}

const limit = 'maxInterStageShaderVariables';
export const { g, description } = makeLimitTestGroup(limit);

g.test('createRenderPipeline,at_over')
.desc(`Test using at and over ${limit} limit with clip_distances in createRenderPipeline(Async)`)
.params(
kMaximumLimitBaseParams
.combine('async', [false, true])
.combine('pointList', [false, true])
.combine('clipDistances', [1, 2, 3, 4, 5, 6, 7, 8])
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase('clip-distances');
})
.fn(async t => {
const { limitTest, testValueName, async, pointList, clipDistances } = t.params;
await t.testDeviceWithRequestedMaximumLimits(
limitTest,
testValueName,
async ({ device, testValue, shouldError }) => {
const pipelineDescriptor = getPipelineDescriptorWithClipDistances(
device,
testValue,
pointList,
clipDistances
);

await t.testCreateRenderPipeline(pipelineDescriptor, async, shouldError);
},
undefined,
['clip-distances']
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,16 @@ export class LimitTestsImpl extends GPUTestBase {
limitTest: MaximumLimitValueTest,
testValueName: MaximumTestValue,
fn: (inputs: MaximumLimitTestInputs) => void | Promise<void>,
extraLimits?: LimitsRequest
extraLimits?: LimitsRequest,
extraFeatures: GPUFeatureName[] = []
) {
assert(!this._device);

const deviceAndLimits = await this._getDeviceWithRequestedMaximumLimit(limitTest, extraLimits);
const deviceAndLimits = await this._getDeviceWithRequestedMaximumLimit(
limitTest,
extraLimits,
extraFeatures
);
// If we request over the limit requestDevice will throw
if (!deviceAndLimits) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
"webgpu:api,validation,capability_checks,features,texture_formats:texture_descriptor:*": { "subcaseMS": 3.830 },
"webgpu:api,validation,capability_checks,features,texture_formats:texture_descriptor_view_formats:*": { "subcaseMS": 5.734 },
"webgpu:api,validation,capability_checks,features,texture_formats:texture_view_descriptor:*": { "subcaseMS": 4.113 },
"webgpu:api,validation,capability_checks,features,clip_distances:createRenderPipeline,at_over:*": { "subcaseMS": 13.7 },
"webgpu:api,validation,capability_checks,limits,maxBindGroups:createPipeline,at_over:*": { "subcaseMS": 10.990 },
"webgpu:api,validation,capability_checks,limits,maxBindGroups:createPipelineLayout,at_over:*": { "subcaseMS": 9.310 },
"webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,at_over:*": { "subcaseMS": 9.984 },
Expand Down

0 comments on commit 561d525

Please sign in to comment.