Skip to content

Commit

Permalink
Compat: Fix canvas configure test for compat (#3310)
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman authored Jan 24, 2024
1 parent 90f74ba commit c9f7acb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class F extends TextureTestMixin(GPUTest) {
align(dstBlocksPerRow * bytesPerBlock, 4);

if (isCompressedTextureFormat(dstTexture.format) && this.isCompatibility) {
assert(viewCompatible(srcFormat, dstFormat));
assert(viewCompatible(this.isCompatibility, srcFormat, dstFormat));
// compare by rendering. We need the expected texture to match
// the dstTexture so we'll create a texture where we supply
// all of the data in JavaScript.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ g.test('texture_binding')
.combine('format', kRegularTextureFormats)
.combine('viewFormat', kRegularTextureFormats)
.filter(
({ format, viewFormat }) => format !== viewFormat && viewCompatible(format, viewFormat)
({ format, viewFormat }) =>
format !== viewFormat && viewCompatible(false, format, viewFormat)
)
)
.beforeAllSubcases(t => {
Expand Down Expand Up @@ -202,7 +203,8 @@ in view format and match in base format.`
.combine('format', kRenderableColorTextureFormats)
.combine('viewFormat', kRenderableColorTextureFormats)
.filter(
({ format, viewFormat }) => format !== viewFormat && viewCompatible(format, viewFormat)
({ format, viewFormat }) =>
format !== viewFormat && viewCompatible(false, format, viewFormat)
)
.combine('sampleCount', [1, 4])
)
Expand Down
4 changes: 1 addition & 3 deletions src/webgpu/api/validation/createTexture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,7 @@ g.test('viewFormats')

t.skipIfTextureFormatNotSupported(format, viewFormat);

const compatible = t.isCompatibility
? viewFormat === format
: viewCompatible(format, viewFormat);
const compatible = viewCompatible(t.isCompatibility, format, viewFormat);

// Test the viewFormat in the list.
t.expectValidationError(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/webgpu/api/validation/createView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ g.test('format')
const { blockWidth, blockHeight } = kTextureFormatInfo[textureFormat];

t.skipIfTextureFormatNotSupported(textureFormat, viewFormat);
// Compatibility mode does not support format reinterpretation.
t.skipIf(t.isCompatibility && viewFormat !== undefined && viewFormat !== textureFormat);

const compatible = viewFormat === undefined || viewCompatible(textureFormat, viewFormat);
const compatible =
viewFormat === undefined || viewCompatible(t.isCompatibility, textureFormat, viewFormat);

const texture = t.device.createTexture({
format: textureFormat,
Expand Down
8 changes: 6 additions & 2 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1910,8 +1910,12 @@ export function textureDimensionAndFormatCompatible(
*
* This function may need to be generalized to use `baseFormat` from `kTextureFormatInfo`.
*/
export function viewCompatible(a: GPUTextureFormat, b: GPUTextureFormat): boolean {
return a === b || a + '-srgb' === b || b + '-srgb' === a;
export function viewCompatible(
compatibilityMode: boolean,
a: GPUTextureFormat,
b: GPUTextureFormat
): boolean {
return compatibilityMode ? a === b : a === b || a + '-srgb' === b || b + '-srgb' === a;
}

export function getFeaturesForFormats<T>(
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/web_platform/canvas/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ g.test('viewFormats')
const ctx = canvas.getContext('webgpu');
assert(ctx instanceof GPUCanvasContext, 'Failed to get WebGPU context from canvas');

const compatible = viewCompatible(format, viewFormat);
const compatible = viewCompatible(t.isCompatibility, format, viewFormat);

// Test configure() produces an error if the formats aren't compatible.
t.expectValidationError(() => {
Expand Down

0 comments on commit c9f7acb

Please sign in to comment.