-
Notifications
You must be signed in to change notification settings - Fork 102
Add immediate size validation cases for pipeline creation #4573
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ Note: entry point matching tests are in shader_module/entry_point.spec.ts | |
| import { AllFeaturesMaxLimitsGPUTest } from '../.././gpu_test.js'; | ||
| import { makeTestGroup } from '../../../common/framework/test_group.js'; | ||
| import { keysOf } from '../../../common/util/data_tables.js'; | ||
| import { getGPU } from '../../../common/util/navigator_gpu.js'; | ||
| import { supportsImmediateData } from '../../../common/util/util.js'; | ||
| import { | ||
| isTextureFormatUsableWithStorageAccessMode, | ||
| kPossibleStorageTextureFormats, | ||
|
|
@@ -811,3 +813,74 @@ generates a validation error at createComputePipeline(Async) | |
| }; | ||
| vtu.doCreateComputePipelineTest(t, isAsync, success, descriptor); | ||
| }); | ||
|
|
||
| g.test('pipeline_creation_immediate_size_mismatch') | ||
| .desc( | ||
| ` | ||
| Validate that creating a pipeline fails if the shader uses immediate data | ||
| larger than the immediateSize specified in the pipeline layout, or larger than | ||
| maxImmediateSize if layout is 'auto'. | ||
| Also validates that using less or equal size is allowed. | ||
| ` | ||
| ) | ||
| .params(u => { | ||
| const kNumericCases = [ | ||
| { shaderSize: 16, layoutSize: 16 }, // Equal | ||
| { shaderSize: 12, layoutSize: 16 }, // Shader smaller | ||
| { shaderSize: 20, layoutSize: 16 }, // Shader larger (small diff) | ||
| { shaderSize: 32, layoutSize: 16 }, // Shader larger | ||
| ] as const; | ||
| const kMaxLimitsCases = [ | ||
| { shaderSize: 'max', layoutSize: 'auto' }, // Shader equal to limit (auto layout) | ||
| { shaderSize: 'max+4', layoutSize: 'auto' }, // Shader larger than limit (auto layout) | ||
| ] as const; | ||
| return u | ||
| .combine('isAsync', [true, false]) | ||
| .combineWithParams([...kNumericCases, ...kMaxLimitsCases] as const); | ||
| }) | ||
| .fn(t => { | ||
| t.skipIf(!supportsImmediateData(getGPU(t.rec)), 'Immediate data not supported'); | ||
|
|
||
| const { isAsync, shaderSize, layoutSize } = t.params; | ||
|
|
||
| const maxImmediateSize = t.device.limits.maxImmediateSize!; | ||
|
|
||
|
Comment on lines
+842
to
+847
|
||
| let actualLayout: GPUPipelineLayout | 'auto'; | ||
| let validSize: number; | ||
|
|
||
| if (layoutSize === 'auto') { | ||
| actualLayout = 'auto'; | ||
| // checked above | ||
| validSize = maxImmediateSize!; | ||
| } else { | ||
| actualLayout = t.device.createPipelineLayout({ | ||
| bindGroupLayouts: [], | ||
| immediateSize: layoutSize as number, | ||
| }); | ||
| validSize = layoutSize as number; | ||
| } | ||
|
|
||
| let actualShaderSize: number; | ||
| if (shaderSize === 'max') { | ||
| actualShaderSize = validSize; | ||
| } else if (shaderSize === 'max+4') { | ||
| actualShaderSize = validSize + 4; | ||
| } else { | ||
| actualShaderSize = shaderSize as number; | ||
| } | ||
|
|
||
| const code = ` | ||
| var<immediate> data: array<u32, ${actualShaderSize / 4}>; | ||
| fn use() { _ = data[0]; } | ||
| @compute @workgroup_size(1) fn main_compute() { use(); } | ||
| `; | ||
|
|
||
| const shouldError = actualShaderSize > validSize; | ||
|
|
||
| vtu.doCreateComputePipelineTest(t, isAsync, !shouldError, { | ||
| layout: actualLayout, | ||
| compute: { | ||
| module: t.device.createShaderModule({ code }), | ||
| }, | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ misc createRenderPipeline and createRenderPipelineAsync validation tests. | |||||||||||
| `; | ||||||||||||
|
|
||||||||||||
| import { makeTestGroup } from '../../../../common/framework/test_group.js'; | ||||||||||||
| import { getGPU } from '../../../../common/util/navigator_gpu.js'; | ||||||||||||
| import { supportsImmediateData } from '../../../../common/util/util.js'; | ||||||||||||
| import { | ||||||||||||
| isTextureFormatUsableWithStorageAccessMode, | ||||||||||||
| kPossibleStorageTextureFormats, | ||||||||||||
|
|
@@ -119,8 +121,10 @@ g.test('pipeline_layout,device_mismatch') | |||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| g.test('external_texture') | ||||||||||||
| .desc('Tests createRenderPipeline() with an external_texture') | ||||||||||||
| .desc('Tests createRenderPipeline(Async) with an external_texture') | ||||||||||||
| .params(u => u.combine('isAsync', [false, true])) | ||||||||||||
| .fn(t => { | ||||||||||||
| const { isAsync } = t.params; | ||||||||||||
| const shader = t.device.createShaderModule({ | ||||||||||||
| code: ` | ||||||||||||
| @vertex | ||||||||||||
|
|
@@ -149,7 +153,7 @@ g.test('external_texture') | |||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| vtu.doCreateRenderPipelineTest(t, false, true, descriptor); | ||||||||||||
| vtu.doCreateRenderPipelineTest(t, isAsync, true, descriptor); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| g.test('storage_texture,format') | ||||||||||||
|
|
@@ -192,3 +196,84 @@ generates a validation error at createComputePipeline(Async) | |||||||||||
| }; | ||||||||||||
| vtu.doCreateRenderPipelineTest(t, isAsync, success, descriptor); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| g.test('pipeline_creation_immediate_size_mismatch') | ||||||||||||
| .desc( | ||||||||||||
| ` | ||||||||||||
| Validate that creating a pipeline fails if the shader uses immediate data | ||||||||||||
| larger than the immediateSize specified in the pipeline layout, or larger than | ||||||||||||
| maxImmediateSize if layout is 'auto'. | ||||||||||||
| Also validates that using less or equal size is allowed. | ||||||||||||
| ` | ||||||||||||
| ) | ||||||||||||
| .params(u => { | ||||||||||||
| const kNumericCases = [ | ||||||||||||
| { vertexSize: 16, fragmentSize: 16, layoutSize: 16 }, // Equal | ||||||||||||
| { vertexSize: 12, fragmentSize: 12, layoutSize: 16 }, // Shader smaller | ||||||||||||
| { vertexSize: 20, fragmentSize: 20, layoutSize: 16 }, // Shader larger (small diff) | ||||||||||||
| { vertexSize: 32, fragmentSize: 32, layoutSize: 16 }, // Shader larger | ||||||||||||
| ] as const; | ||||||||||||
|
Comment on lines
+210
to
+215
|
||||||||||||
| const kMaxLimitsCases = [ | ||||||||||||
| { vertexSize: 'max', fragmentSize: 0, layoutSize: 'auto' }, // Vertex = Limit (Control) | ||||||||||||
| { vertexSize: 0, fragmentSize: 'max', layoutSize: 'auto' }, // Fragment = Limit (Control) | ||||||||||||
| { vertexSize: 'max', fragmentSize: 'max', layoutSize: 'auto' }, // Both at Limit (Control) | ||||||||||||
| { vertexSize: 'max+4', fragmentSize: 0, layoutSize: 'auto' }, // Vertex > Limit | ||||||||||||
| { vertexSize: 0, fragmentSize: 'max+4', layoutSize: 'auto' }, // Fragment > Limit | ||||||||||||
| ] as const; | ||||||||||||
| return u | ||||||||||||
| .combine('isAsync', [true, false]) | ||||||||||||
| .combineWithParams([...kNumericCases, ...kMaxLimitsCases] as const); | ||||||||||||
| }) | ||||||||||||
| .fn(t => { | ||||||||||||
| t.skipIf(!supportsImmediateData(getGPU(t.rec)), 'Immediate data not supported'); | ||||||||||||
|
|
||||||||||||
| const { isAsync, vertexSize, fragmentSize, layoutSize } = t.params; | ||||||||||||
|
|
||||||||||||
| const maxImmediateSize = t.device.limits.maxImmediateSize!; | ||||||||||||
|
||||||||||||
| const maxImmediateSize = t.device.limits.maxImmediateSize!; | |
| const maxImmediateSize = t.device.limits.maxImmediateSize; | |
| if (maxImmediateSize === undefined) { | |
| t.skip('Device limit maxImmediateSize is undefined'); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These numeric cases create a pipeline layout with immediateSize: 16 without checking that the device supports at least 16 bytes (maxImmediateSize >= 16). If maxImmediateSize is smaller, the test will fail for the wrong reason and the control cases won't be meaningful. Consider filtering/skipping when maxImmediateSize < 16 (or choosing sizes relative to the limit).