Skip to content

Commit

Permalink
DO NOT SUBMIT: Add coverage of 1-byte component vertex formats and un…
Browse files Browse the repository at this point in the history
…orm8x4-bgra
  • Loading branch information
Kangz committed Nov 1, 2024
1 parent 8328265 commit ff3f0f6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 21 deletions.
60 changes: 43 additions & 17 deletions src/webgpu/api/operation/vertex_state/correctness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,25 +427,51 @@ struct VSOutputs {

case 'unorm': {
if (formatInfo.bytesPerComponent === 'packed') {
assert(format === 'unorm10-10-10-2'); // This is the only packed format for now.
assert(bitSize === 0);

/* prettier-ignore */
const data = [
[ 0, 0, 0, 0],
[1023, 1023, 1023, 3],
[ 243, 567, 765, 2],
];
const vertexData = new Uint32Array(data.map(makeRgb10a2)).buffer;
const expectedData = new Float32Array(data.flat().map(normalizeRgb10a2)).buffer;

return {
shaderBaseType: 'f32',
testComponentCount: data.flat().length,
expectedData,
vertexData,
floatTolerance: 0.1 / 1023,
};
switch (format) {
case 'unorm10-10-10-2': {
/* prettier-ignore */
const data = [
[ 0, 0, 0, 0],
[1023, 1023, 1023, 3],
[ 243, 567, 765, 2],
];
const vertexData = new Uint32Array(data.map(makeRgb10a2)).buffer;
const expectedData = new Float32Array(data.flat().map(normalizeRgb10a2)).buffer;

return {
shaderBaseType: 'f32',
testComponentCount: data.flat().length,
expectedData,
vertexData,
floatTolerance: 0.1 / 1023,
};
}

case 'unorm8x4-bgra' as GPUVertexFormat: {
const data = [42, 0, 1, 2, 3, 4, 128, 255];
const vertexData = new Uint8Array(data).buffer;
const expectedData = new Float32Array(
data.map(v => normalizedIntegerAsFloat(v, 8, false))
);

for (let i = 0; i + 2 < expectedData.length; i += 4) {
const r = expectedData[i + 0];
const b = expectedData[i + 2];
expectedData[i + 0] = b;
expectedData[i + 2] = r;
}

return {
shaderBaseType: 'f32',
testComponentCount: data.length,
expectedData: expectedData.buffer,
vertexData,
floatTolerance: 0.1 / 255,
};
}
}
}

/* prettier-ignore */
Expand Down
29 changes: 25 additions & 4 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export type VertexFormatInfo = {
/** Number of components. */
readonly componentCount: 1 | 2 | 3 | 4;
/** Size in bytes. */
readonly byteSize: 2 | 4 | 8 | 12 | 16;
readonly byteSize: 1 | 2 | 4 | 8 | 12 | 16;
/** The completely matching WGSL type for vertex format */
readonly wgslType:
| 'f32'
Expand All @@ -267,29 +267,49 @@ export type VertexFormatInfo = {
};
/** Per-GPUVertexFormat info. */
export const kVertexFormatInfo: {
readonly [k in GPUVertexFormat]: VertexFormatInfo;
readonly [k in
| GPUVertexFormat
| 'uint8'
| 'sint8'
| 'unorm8'
| 'snorm8'
| 'uint16'
| 'sint16'
| 'unorm16'
| 'snorm16'
| 'float16'
| 'unorm8x4-bgra']: VertexFormatInfo;
} =
/* prettier-ignore */ makeTable(
['bytesPerComponent', 'type', 'componentCount', 'byteSize', 'wgslType'] as const,
[ , , , , ] as const, {
// 8 bit components
'uint8': [ 1, 'uint', 1, 1, 'u32'],
'uint8x2': [ 1, 'uint', 2, 2, 'vec2<u32>'],
'uint8x4': [ 1, 'uint', 4, 4, 'vec4<u32>'],
'sint8': [ 1, 'sint', 1, 1, 'i32'],
'sint8x2': [ 1, 'sint', 2, 2, 'vec2<i32>'],
'sint8x4': [ 1, 'sint', 4, 4, 'vec4<i32>'],
'unorm8': [ 1, 'unorm', 1, 1, 'f32'],
'unorm8x2': [ 1, 'unorm', 2, 2, 'vec2<f32>'],
'unorm8x4': [ 1, 'unorm', 4, 4, 'vec4<f32>'],
'snorm8': [ 1, 'snorm', 1, 1, 'f32'],
'snorm8x2': [ 1, 'snorm', 2, 2, 'vec2<f32>'],
'snorm8x4': [ 1, 'snorm', 4, 4, 'vec4<f32>'],
// 16 bit components
'uint16': [ 2, 'uint', 1, 2, 'u32'],
'uint16x2': [ 2, 'uint', 2, 4, 'vec2<u32>'],
'uint16x4': [ 2, 'uint', 4, 8, 'vec4<u32>'],
'sint16': [ 2, 'sint', 1, 2, 'i32'],
'sint16x2': [ 2, 'sint', 2, 4, 'vec2<i32>'],
'sint16x4': [ 2, 'sint', 4, 8, 'vec4<i32>'],
'unorm16': [ 2, 'unorm', 1, 2, 'f32'],
'unorm16x2': [ 2, 'unorm', 2, 4, 'vec2<f32>'],
'unorm16x4': [ 2, 'unorm', 4, 8, 'vec4<f32>'],
'snorm16': [ 2, 'snorm', 1, 2, 'f32'],
'snorm16x2': [ 2, 'snorm', 2, 4, 'vec2<f32>'],
'snorm16x4': [ 2, 'snorm', 4, 8, 'vec4<f32>'],
'float16': [ 2, 'float', 1, 2, 'f32'],
'float16x2': [ 2, 'float', 2, 4, 'vec2<f32>'],
'float16x4': [ 2, 'float', 4, 8, 'vec4<f32>'],
// 32 bit components
Expand All @@ -306,10 +326,11 @@ export const kVertexFormatInfo: {
'sint32x3': [ 4, 'sint', 3, 12, 'vec3<i32>'],
'sint32x4': [ 4, 'sint', 4, 16, 'vec4<i32>'],
// 32 bit packed
'unorm10-10-10-2': [ 'packed', 'unorm', 4, 4, 'vec4<f32>']
'unorm10-10-10-2': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
'unorm8x4-bgra': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
} as const);
/** List of all GPUVertexFormat values. */
export const kVertexFormats = keysOf(kVertexFormatInfo);
export const kVertexFormats = keysOf(kVertexFormatInfo) as readonly GPUVertexFormat[];

// Typedefs for bindings

Expand Down
11 changes: 11 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
"webgpu:api,validation,buffer,mapping:unmap,state,mappingPending:*": { "subcaseMS": 22.951 },
"webgpu:api,validation,buffer,mapping:unmap,state,unmapped:*": { "subcaseMS": 74.200 },
"webgpu:api,validation,capability_checks,features,clip_distances:createRenderPipeline,at_over:*": { "subcaseMS": 13.700 },
"webgpu:api,validation,capability_checks,features,clip_distances:createRenderPipeline,max_vertex_output_location:*": { "subcaseMS": 267.295 },
"webgpu:api,validation,capability_checks,features,query_types:createQuerySet:*": { "subcaseMS": 10.451 },
"webgpu:api,validation,capability_checks,features,query_types:timestamp:*": { "subcaseMS": 1.200 },
"webgpu:api,validation,capability_checks,features,texture_formats:canvas_configuration:*": { "subcaseMS": 4.339 },
Expand Down Expand Up @@ -434,6 +435,7 @@
"webgpu:api,validation,createView:format:*": { "subcaseMS": 0.742 },
"webgpu:api,validation,createView:mip_levels:*": { "subcaseMS": 0.436 },
"webgpu:api,validation,createView:texture_state:*": { "subcaseMS": 0.400 },
"webgpu:api,validation,createView:texture_view_usage:*": { "subcaseMS": 3106.634 },
"webgpu:api,validation,debugMarker:push_pop_call_count_unbalance,command_encoder:*": { "subcaseMS": 1.522 },
"webgpu:api,validation,debugMarker:push_pop_call_count_unbalance,render_compute_pass:*": { "subcaseMS": 0.601 },
"webgpu:api,validation,encoding,beginComputePass:timestampWrites,invalid_query_set:*": { "subcaseMS": 0.201 },
Expand Down Expand Up @@ -652,6 +654,9 @@
"webgpu:api,validation,queue,destroyed,texture:setBindGroup:*": { "subcaseMS": 5.783 },
"webgpu:api,validation,queue,destroyed,texture:writeTexture:*": { "subcaseMS": 16.601 },
"webgpu:api,validation,queue,submit:command_buffer,device_mismatch:*": { "subcaseMS": 0.467 },
"webgpu:api,validation,queue,submit:command_buffer,duplicate_buffers:*": { "subcaseMS": 0.981 },
"webgpu:api,validation,queue,submit:command_buffer,invalid_submit_invalidates:*": { "subcaseMS": 0.820 },
"webgpu:api,validation,queue,submit:command_buffer,submit_invalidates:*": { "subcaseMS": 1.120 },
"webgpu:api,validation,queue,writeBuffer:buffer,device_mismatch:*": { "subcaseMS": 16.000 },
"webgpu:api,validation,queue,writeBuffer:buffer_state:*": { "subcaseMS": 6.201 },
"webgpu:api,validation,queue,writeBuffer:ranges:*": { "subcaseMS": 17.600 },
Expand Down Expand Up @@ -706,13 +711,17 @@
"webgpu:api,validation,render_pass,resolve:resolve_attachment:*": { "subcaseMS": 6.205 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depthCompare_optional:*": { "subcaseMS": 21.401 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depthWriteEnabled_optional:*": { "subcaseMS": 16.950 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depth_bias:*": { "subcaseMS": 45.563 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depth_test:*": { "subcaseMS": 3.407 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depth_write,frag_depth:*": { "subcaseMS": 6.465 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:depth_write:*": { "subcaseMS": 4.113 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:format:*": { "subcaseMS": 3.521 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_test:*": { "subcaseMS": 3.124 },
"webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_write:*": { "subcaseMS": 3.183 },
"webgpu:api,validation,render_pipeline,float32_blendable:create_render_pipeline:*": { "subcaseMS": 78.452 },
"webgpu:api,validation,render_pipeline,fragment_state:color_target_exists:*": { "subcaseMS": 29.150 },
"webgpu:api,validation,render_pipeline,fragment_state:dual_source_blending,color_target_count:*": { "subcaseMS": 38.712 },
"webgpu:api,validation,render_pipeline,fragment_state:dual_source_blending,use_blend_src:*": { "subcaseMS": 316.418 },
"webgpu:api,validation,render_pipeline,fragment_state:limits,maxColorAttachmentBytesPerSample,aligned:*": { "subcaseMS": 0.991 },
"webgpu:api,validation,render_pipeline,fragment_state:limits,maxColorAttachmentBytesPerSample,unaligned:*": { "subcaseMS": 14.750 },
"webgpu:api,validation,render_pipeline,fragment_state:limits,maxColorAttachments:*": { "subcaseMS": 9.351 },
Expand All @@ -734,6 +743,7 @@
"webgpu:api,validation,render_pipeline,inter_stage:type:*": { "subcaseMS": 6.170 },
"webgpu:api,validation,render_pipeline,misc:basic:*": { "subcaseMS": 0.901 },
"webgpu:api,validation,render_pipeline,misc:external_texture:*": { "subcaseMS": 35.189 },
"webgpu:api,validation,render_pipeline,misc:no_attachment:*": { "subcaseMS": 2.264 },
"webgpu:api,validation,render_pipeline,misc:pipeline_layout,device_mismatch:*": { "subcaseMS": 8.700 },
"webgpu:api,validation,render_pipeline,misc:vertex_state_only:*": { "subcaseMS": 1.125 },
"webgpu:api,validation,render_pipeline,multisample_state:alpha_to_coverage,count:*": { "subcaseMS": 3.200 },
Expand Down Expand Up @@ -796,6 +806,7 @@
"webgpu:api,validation,resource_usages,texture,in_render_misc:subresources,set_bind_group_on_same_index_depth_stencil_texture:*": { "subcaseMS": 0.925 },
"webgpu:api,validation,resource_usages,texture,in_render_misc:subresources,set_unused_bind_group:*": { "subcaseMS": 6.200 },
"webgpu:api,validation,resource_usages,texture,in_render_misc:subresources,texture_usages_in_copy_and_render_pass:*": { "subcaseMS": 4.763 },
"webgpu:api,validation,resource_usages,texture,in_render_misc:subresources,texture_view_usages:*": { "subcaseMS": 24.999 },
"webgpu:api,validation,shader_module,entry_point:compute:*": { "subcaseMS": 4.439 },
"webgpu:api,validation,shader_module,entry_point:compute_undefined_entry_point_and_extra_stage:*": { "subcaseMS": 17.075 },
"webgpu:api,validation,shader_module,entry_point:fragment:*": { "subcaseMS": 5.865 },
Expand Down

0 comments on commit ff3f0f6

Please sign in to comment.