-
Notifications
You must be signed in to change notification settings - Fork 82
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
bytesPerBlock refactors; generalize validation,image_copy,buffer_related over aspects #3490
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 |
---|---|---|
|
@@ -4,11 +4,28 @@ import { | |
SizedTextureFormat, | ||
kTextureFormatInfo, | ||
isCompressedTextureFormat, | ||
kCompressedTextureFormats, | ||
kDepthStencilFormats, | ||
} from '../../../format_info.js'; | ||
import { align } from '../../../util/math.js'; | ||
import { ImageCopyType } from '../../../util/texture/layout.js'; | ||
import { ValidationTest } from '../validation_test.js'; | ||
|
||
export const kReducedFormatsList = [ | ||
'r8unorm', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For testing compat copyT2B workaround impl purporse I'd like to also include ['r8snorm', 'rg8snorm', 'bgra8unorm'] |
||
'rg8uint', | ||
'rgba8snorm', | ||
'r16sint', | ||
'rg16float', | ||
'rgba16float', | ||
'r32float', | ||
'rg32float', | ||
'rgba32float', | ||
'rgb9e5ufloat', | ||
...kCompressedTextureFormats, | ||
...kDepthStencilFormats, | ||
] as const; | ||
|
||
export class ImageCopyTest extends ValidationTest { | ||
testRun( | ||
textureCopyView: GPUImageCopyTexture, | ||
|
@@ -123,7 +140,7 @@ export class ImageCopyTest extends ValidationTest { | |
|
||
testBuffer( | ||
buffer: GPUBuffer, | ||
texture: GPUTexture, | ||
texture: GPUImageCopyTexture, | ||
textureDataLayout: GPUImageDataLayout, | ||
size: GPUExtent3D, | ||
{ | ||
|
@@ -145,14 +162,14 @@ export class ImageCopyTest extends ValidationTest { | |
const data = new Uint8Array(dataSize); | ||
|
||
this.expectValidationError(() => { | ||
this.device.queue.writeTexture({ texture }, data, textureDataLayout, size); | ||
this.device.queue.writeTexture(texture, data, textureDataLayout, size); | ||
}, !success); | ||
|
||
break; | ||
} | ||
case 'CopyB2T': { | ||
const { encoder, validateFinish, validateFinishAndSubmit } = this.createEncoder('non-pass'); | ||
encoder.copyBufferToTexture({ buffer, ...textureDataLayout }, { texture }, size); | ||
encoder.copyBufferToTexture({ buffer, ...textureDataLayout }, texture, size); | ||
|
||
if (submit) { | ||
// validation error is expected to come from the submit and encoding should succeed | ||
|
@@ -165,13 +182,13 @@ export class ImageCopyTest extends ValidationTest { | |
break; | ||
} | ||
case 'CopyT2B': { | ||
if (this.isCompatibility && isCompressedTextureFormat(texture.format)) { | ||
if (this.isCompatibility && isCompressedTextureFormat(texture.texture.format)) { | ||
this.skip( | ||
'copyTextureToBuffer is not supported for compressed texture formats in compatibility mode.' | ||
); | ||
} | ||
const { encoder, validateFinish, validateFinishAndSubmit } = this.createEncoder('non-pass'); | ||
encoder.copyTextureToBuffer({ texture }, { buffer, ...textureDataLayout }, size); | ||
encoder.copyTextureToBuffer(texture, { buffer, ...textureDataLayout }, size); | ||
|
||
if (submit) { | ||
// validation error is expected to come from the submit and encoding should succeed | ||
|
@@ -244,7 +261,11 @@ export function texelBlockAlignmentTestExpanderForValueToCoordinate({ | |
} | ||
} | ||
|
||
// This is a helper function used for filtering test parameters | ||
/** | ||
* This is a helper function used for filtering test parameters. | ||
* | ||
* @deprecated Prefer `aspectCopyableWithMethod` if possible. | ||
*/ | ||
export function formatCopyableWithMethod({ format, method }: WithFormatAndMethod): boolean { | ||
const info = kTextureFormatInfo[format]; | ||
if (info.depth || info.stencil) { | ||
|
@@ -261,6 +282,20 @@ export function formatCopyableWithMethod({ format, method }: WithFormatAndMethod | |
} | ||
} | ||
|
||
/** True iff the (format,aspect) pair can be copied with this method. */ | ||
export function aspectCopyableWithMethod( | ||
format: GPUTextureFormat, | ||
aspect: 'color' | 'depth' | 'stencil', | ||
method: ImageCopyType | ||
) { | ||
const info = kTextureFormatInfo[format][aspect]!; | ||
if (method === 'CopyT2B') { | ||
return info.copySrc; | ||
} else { | ||
return info.copyDst; | ||
} | ||
} | ||
|
||
// This is a helper function used for filtering test parameters | ||
export function getACopyableAspectWithMethod({ | ||
format, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const description = ` | ||
Unittests for helpers in format_info.ts. | ||
`; | ||
|
||
import { Fixture } from '../common/framework/fixture.js'; | ||
import { makeTestGroup } from '../common/framework/test_group.js'; | ||
import { assert, objectEquals } from '../common/util/util.js'; | ||
|
||
import { kDepthStencilFormats, kTextureFormatInfo, resolvePerAspectFormat } from './format_info.js'; | ||
|
||
export const g = makeTestGroup(Fixture); | ||
|
||
g.test('resolvePerAspectFormat') | ||
.desc( | ||
`Test that resolvePerAspectFormat works and kTextureFormatInfo contains identical | ||
information for the combined and separate versions of that aspect.` | ||
) | ||
.fn(t => { | ||
for (const format of kDepthStencilFormats) { | ||
const info = kTextureFormatInfo[format]; | ||
if (info.depth) { | ||
const depthFormatInfo = kTextureFormatInfo[resolvePerAspectFormat(format, 'depth-only')]; | ||
assert(objectEquals(info.depth, depthFormatInfo.depth), 'Error in texture format table'); | ||
} | ||
if (info.stencil) { | ||
const stencilFormatInfo = | ||
kTextureFormatInfo[resolvePerAspectFormat(format, 'stencil-only')]; | ||
assert( | ||
objectEquals(info.stencil, stencilFormatInfo.stencil), | ||
'Error in texture format table' | ||
); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1558,6 +1558,31 @@ export const kValidTextureFormatsForCopyE2T = [ | |
// Other related stuff | ||
// | ||
|
||
/** | ||
* Pass this to `expandWithParams` to expand a format list into a format+aspect list. | ||
* | ||
* In some cases, `aspect` will be unset, invoking the default (which is always `"all"`). | ||
*/ | ||
export function* aspectParamsForTextureFormat(format: GPUTextureFormat): Generator<{ | ||
/** `GPUTextureAspect | undefined` to pass to WebGPU. */ | ||
aspect?: 'depth-only' | 'stencil-only'; | ||
/** Key for the aspect in the info table: `kTextureFormatInfo[format][_aspectKey]`. */ | ||
_aspectKey: 'color' | 'depth' | 'stencil'; | ||
}> { | ||
const info = kTextureFormatInfo[format]; | ||
if (info.color?.bytes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: why is here |
||
yield { _aspectKey: 'color' } as const; | ||
} | ||
if (info.depth?.bytes) { | ||
yield { aspect: 'depth-only', _aspectKey: 'depth' } as const; | ||
if (!info.stencil) yield { _aspectKey: 'depth' } as const; | ||
} | ||
if (info.stencil?.bytes) { | ||
yield { aspect: 'stencil-only', _aspectKey: 'stencil' } as const; | ||
if (!info.depth) yield { _aspectKey: 'stencil' } as const; | ||
} | ||
} | ||
|
||
const kDepthStencilFormatCapabilityInBufferTextureCopy = { | ||
// kUnsizedDepthStencilFormats | ||
depth24plus: { | ||
|
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.
The only
p.copyHeightInBlocks !== p._textureHeightInBlocks
case isp.copyHeightInBlocks = 0, p._textureHeightInBlocks = 1
which can be a no-op. I think it's better expand_textureHeightInBlocks
with[p.copyHeightInBlocks, pp.copyHeightInBlocks + 1]
for > 0 cases?