-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cleanup-videoframe
- Loading branch information
Showing
8 changed files
with
683 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,293 @@ | ||
export const description = ` | ||
TODO: | ||
- interface matching between pipeline layout and shader | ||
- x= {compute, vertex, fragment, vertex+fragment}, visibilities | ||
- x= bind group index values, binding index values, multiple bindings | ||
- x= types of bindings | ||
- x= {equal, superset, subset} | ||
- x= {superset, subset} | ||
`; | ||
|
||
import { makeTestGroup } from '../../../common/framework/test_group.js'; | ||
import { | ||
kShaderStageCombinations, | ||
kShaderStages, | ||
ValidBindableResource, | ||
} from '../../capability_info.js'; | ||
import { GPUConst } from '../../constants.js'; | ||
|
||
import { ValidationTest } from './validation_test.js'; | ||
|
||
export const g = makeTestGroup(ValidationTest); | ||
type BindableResourceType = ValidBindableResource | 'readonlyStorageBuf'; | ||
const kBindableResources = [ | ||
'uniformBuf', | ||
'storageBuf', | ||
'readonlyStorageBuf', | ||
'filtSamp', | ||
'nonFiltSamp', | ||
'compareSamp', | ||
'sampledTex', | ||
'sampledTexMS', | ||
'readonlyStorageTex', | ||
'writeonlyStorageTex', | ||
'readwriteStorageTex', | ||
] as const; | ||
|
||
const bindGroupLayoutEntryContents = { | ||
compareSamp: { | ||
sampler: { | ||
type: 'comparison', | ||
}, | ||
}, | ||
filtSamp: { | ||
sampler: { | ||
type: 'filtering', | ||
}, | ||
}, | ||
nonFiltSamp: { | ||
sampler: { | ||
type: 'non-filtering', | ||
}, | ||
}, | ||
sampledTex: { | ||
texture: { | ||
sampleType: 'unfilterable-float', | ||
}, | ||
}, | ||
sampledTexMS: { | ||
texture: { | ||
sampleType: 'unfilterable-float', | ||
multisampled: true, | ||
}, | ||
}, | ||
storageBuf: { | ||
buffer: { | ||
type: 'storage', | ||
}, | ||
}, | ||
readonlyStorageBuf: { | ||
buffer: { | ||
type: 'read-only-storage', | ||
}, | ||
}, | ||
uniformBuf: { | ||
buffer: { | ||
type: 'uniform', | ||
}, | ||
}, | ||
readonlyStorageTex: { | ||
storageTexture: { | ||
format: 'r32float', | ||
access: 'read-only', | ||
}, | ||
}, | ||
writeonlyStorageTex: { | ||
storageTexture: { | ||
format: 'r32float', | ||
access: 'write-only', | ||
}, | ||
}, | ||
readwriteStorageTex: { | ||
storageTexture: { | ||
format: 'r32float', | ||
access: 'read-write', | ||
}, | ||
}, | ||
} as const; | ||
|
||
class F extends ValidationTest { | ||
createPipelineLayout( | ||
bindingInPipelineLayout: BindableResourceType, | ||
visibility: number | ||
): GPUPipelineLayout { | ||
return this.device.createPipelineLayout({ | ||
bindGroupLayouts: [ | ||
this.device.createBindGroupLayout({ | ||
entries: [ | ||
{ | ||
binding: 0, | ||
visibility, | ||
...bindGroupLayoutEntryContents[bindingInPipelineLayout], | ||
}, | ||
], | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
GetBindableResourceShaderDeclaration(bindableResource: BindableResourceType): string { | ||
switch (bindableResource) { | ||
case 'compareSamp': | ||
return 'var tmp : sampler_comparison'; | ||
case 'filtSamp': | ||
case 'nonFiltSamp': | ||
return 'var tmp : sampler'; | ||
case 'sampledTex': | ||
return 'var tmp : texture_2d<f32>'; | ||
case 'sampledTexMS': | ||
return 'var tmp : texture_multisampled_2d<f32>'; | ||
case 'storageBuf': | ||
return 'var<storage, read_write> tmp : vec4u'; | ||
case 'readonlyStorageBuf': | ||
return 'var<storage, read> tmp : vec4u'; | ||
case 'uniformBuf': | ||
return 'var<uniform> tmp : vec4u;'; | ||
case 'readonlyStorageTex': | ||
return 'var tmp : texture_storage_2d<r32float, read>'; | ||
case 'writeonlyStorageTex': | ||
return 'var tmp : texture_storage_2d<r32float, write>'; | ||
case 'readwriteStorageTex': | ||
return 'var tmp : texture_storage_2d<r32float, read_write>'; | ||
} | ||
} | ||
} | ||
|
||
const BindingResourceCompatibleWithShaderStages = function ( | ||
bindingResource: BindableResourceType, | ||
shaderStages: number | ||
): boolean { | ||
if ((shaderStages & GPUConst.ShaderStage.VERTEX) > 0) { | ||
switch (bindingResource) { | ||
case 'writeonlyStorageTex': | ||
case 'readwriteStorageTex': | ||
case 'storageBuf': | ||
return false; | ||
default: | ||
break; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
export const g = makeTestGroup(F); | ||
|
||
g.test('pipeline_layout_shader_exact_match') | ||
.desc( | ||
` | ||
Test that the binding type in the pipeline layout must match the related declaration in shader. | ||
Note that read-write storage textures in the pipeline layout can match write-only storage textures | ||
in the shader. | ||
` | ||
) | ||
.params(u => | ||
u | ||
.combine('bindingInPipelineLayout', kBindableResources) | ||
.combine('bindingInShader', kBindableResources) | ||
.beginSubcases() | ||
.combine('pipelineLayoutVisibility', kShaderStageCombinations) | ||
.combine('shaderStageWithBinding', kShaderStages) | ||
.combine('isBindingStaticallyUsed', [true, false] as const) | ||
.unless( | ||
p => | ||
// We don't test using non-filtering sampler in shader because it has the same declaration | ||
// as filtering sampler. | ||
p.bindingInShader === 'nonFiltSamp' || | ||
!BindingResourceCompatibleWithShaderStages( | ||
p.bindingInPipelineLayout, | ||
p.pipelineLayoutVisibility | ||
) || | ||
!BindingResourceCompatibleWithShaderStages(p.bindingInShader, p.shaderStageWithBinding) | ||
) | ||
) | ||
.fn(t => { | ||
const { | ||
bindingInPipelineLayout, | ||
bindingInShader, | ||
pipelineLayoutVisibility, | ||
shaderStageWithBinding, | ||
isBindingStaticallyUsed, | ||
} = t.params; | ||
|
||
const layout = t.createPipelineLayout(bindingInPipelineLayout, pipelineLayoutVisibility); | ||
const bindResourceDeclaration = `@group(0) @binding(0) ${t.GetBindableResourceShaderDeclaration( | ||
bindingInShader | ||
)}`; | ||
const staticallyUseBinding = isBindingStaticallyUsed ? '_ = tmp; ' : ''; | ||
const isAsync = false; | ||
|
||
let success = true; | ||
if (isBindingStaticallyUsed) { | ||
success = bindingInPipelineLayout === bindingInShader; | ||
|
||
// Filtering and non-filtering both have the same shader declaration. | ||
success ||= bindingInPipelineLayout === 'nonFiltSamp' && bindingInShader === 'filtSamp'; | ||
|
||
// Promoting storage textures that are read-write in the layout can be readonly in the shader. | ||
success ||= | ||
bindingInPipelineLayout === 'readwriteStorageTex' && | ||
bindingInShader === 'writeonlyStorageTex'; | ||
|
||
// The shader using the resource must be included in the visibility in the layout. | ||
success &&= (pipelineLayoutVisibility & shaderStageWithBinding) > 0; | ||
} | ||
|
||
switch (shaderStageWithBinding) { | ||
case GPUConst.ShaderStage.COMPUTE: { | ||
const computeShader = ` | ||
${bindResourceDeclaration}; | ||
@compute @workgroup_size(1) | ||
fn main() { | ||
${staticallyUseBinding} | ||
} | ||
`; | ||
t.doCreateComputePipelineTest(isAsync, success, { | ||
layout, | ||
compute: { | ||
module: t.device.createShaderModule({ | ||
code: computeShader, | ||
}), | ||
}, | ||
}); | ||
break; | ||
} | ||
case GPUConst.ShaderStage.VERTEX: { | ||
const vertexShader = ` | ||
${bindResourceDeclaration}; | ||
@vertex | ||
fn main() -> @builtin(position) vec4f { | ||
${staticallyUseBinding} | ||
return vec4f(); | ||
} | ||
`; | ||
t.doCreateRenderPipelineTest(isAsync, success, { | ||
layout, | ||
vertex: { | ||
module: t.device.createShaderModule({ | ||
code: vertexShader, | ||
}), | ||
}, | ||
}); | ||
break; | ||
} | ||
case GPUConst.ShaderStage.FRAGMENT: { | ||
const fragmentShader = ` | ||
${bindResourceDeclaration}; | ||
@fragment | ||
fn main() -> @location(0) vec4f { | ||
${staticallyUseBinding} | ||
return vec4f(); | ||
} | ||
`; | ||
t.doCreateRenderPipelineTest(isAsync, success, { | ||
layout, | ||
vertex: { | ||
module: t.device.createShaderModule({ | ||
code: ` | ||
@vertex | ||
fn main() -> @builtin(position) vec4f { | ||
return vec4f(); | ||
}`, | ||
}), | ||
}, | ||
fragment: { | ||
module: t.device.createShaderModule({ | ||
code: fragmentShader, | ||
}), | ||
targets: [ | ||
{ | ||
format: 'rgba8unorm', | ||
}, | ||
], | ||
}, | ||
}); | ||
break; | ||
} | ||
} | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/webgpu/compat/api/validation/createBindGroupLayout.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const description = ` | ||
Tests that, in compat mode, you can not create a bind group layout with unsupported storage texture formats. | ||
`; | ||
|
||
import { makeTestGroup } from '../../../../common/framework/test_group.js'; | ||
import { kCompatModeUnsupportedStorageTextureFormats } from '../../../format_info.js'; | ||
import { CompatibilityTest } from '../../compatibility_test.js'; | ||
|
||
export const g = makeTestGroup(CompatibilityTest); | ||
|
||
g.test('unsupportedStorageTextureFormats') | ||
.desc( | ||
` | ||
Tests that, in compat mode, you can not create a bind group layout with unsupported storage texture formats. | ||
` | ||
) | ||
.params(u => u.combine('format', kCompatModeUnsupportedStorageTextureFormats)) | ||
.fn(t => { | ||
const { format } = t.params; | ||
|
||
t.expectValidationError(() => { | ||
t.device.createBindGroupLayout({ | ||
entries: [ | ||
{ | ||
binding: 0, | ||
visibility: GPUShaderStage.COMPUTE, | ||
storageTexture: { | ||
format, | ||
}, | ||
}, | ||
], | ||
}); | ||
}, true); | ||
}); |
Oops, something went wrong.