CopyTextureForBrowser(): Validate src/dst texture state

The validation of CopyTextureForBrwoser() fails to valid src and dst
texture state. And a bug has been caught by cts
webgpu:api,validation,queue,copyToTexture,CopyExternalImageToTexture:destination_texture,state:*
after changing CopyExternalImageToTexture() to use CopyTextureForBroswer()
to upload CPU resource.

The CL fix this.

Bug: dawn:1306
Change-Id: Ie4cfd174dc9f54f6cf2099226c4e1cc00ed1d446
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/80900
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Yan,Shaobo 2022-02-18 06:26:11 +00:00 committed by Dawn LUCI CQ
parent 1220bbcbd2
commit 893889b0bb
2 changed files with 42 additions and 2 deletions

View File

@ -222,8 +222,7 @@ namespace dawn::native {
static_assert(sizeof(Uniform) == 176); static_assert(sizeof(Uniform) == 176);
// TODO(crbug.com/dawn/856): Expand copyTextureForBrowser to support any // TODO(crbug.com/dawn/856): Expand copyTextureForBrowser to support any
// non-depth, non-stencil, non-compressed texture format pair copy. Now this API // non-depth, non-stencil, non-compressed texture format pair copy.
// supports CopyImageBitmapToTexture normal format pairs.
MaybeError ValidateCopyTextureFormatConversion(const wgpu::TextureFormat srcFormat, MaybeError ValidateCopyTextureFormatConversion(const wgpu::TextureFormat srcFormat,
const wgpu::TextureFormat dstFormat) { const wgpu::TextureFormat dstFormat) {
switch (srcFormat) { switch (srcFormat) {
@ -258,6 +257,12 @@ namespace dawn::native {
return {}; return {};
} }
MaybeError ValidateTextureState(const TextureBase* texture) {
DAWN_INVALID_IF(texture->GetTextureState() == TextureBase::TextureState::Destroyed,
"Destroyed texture %s used in CopyTextureForBrowser().", texture);
return {};
}
RenderPipelineBase* GetCachedPipeline(InternalPipelineStore* store, RenderPipelineBase* GetCachedPipeline(InternalPipelineStore* store,
wgpu::TextureFormat dstFormat) { wgpu::TextureFormat dstFormat) {
auto pipeline = store->copyTextureForBrowserPipelines.find(dstFormat); auto pipeline = store->copyTextureForBrowserPipelines.find(dstFormat);
@ -327,6 +332,9 @@ namespace dawn::native {
DAWN_TRY(device->ValidateObject(source->texture)); DAWN_TRY(device->ValidateObject(source->texture));
DAWN_TRY(device->ValidateObject(destination->texture)); DAWN_TRY(device->ValidateObject(destination->texture));
DAWN_TRY(ValidateTextureState(source->texture));
DAWN_TRY(ValidateTextureState(destination->texture));
DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *source, *copySize), DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *source, *copySize),
"validating the ImageCopyTexture for the source"); "validating the ImageCopyTexture for the source");
DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *destination, *copySize), DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *destination, *copySize),

View File

@ -157,6 +157,38 @@ TEST_F(CopyTextureForBrowserTest, IncorrectUsage) {
noCopyDstUsageSource, 0, {0, 0, 0}, {16, 16, 1}); noCopyDstUsageSource, 0, {0, 0, 0}, {16, 16, 1});
} }
// Test source or destination texture is destroyed.
TEST_F(CopyTextureForBrowserTest, DestroyedTexture) {
wgpu::Texture source =
Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding);
wgpu::Texture destination =
Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment);
wgpu::CopyTextureForBrowserOptions options = {};
// Valid src and dst textures.
{
TestCopyTextureForBrowser(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0,
{0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
}
// Destroyed src texture.
{
source.Destroy();
TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
{0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
}
// Destroyed dst texture.
{
destination.Destroy();
TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
{0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
}
}
// Test non-zero value origin in source and OOB copy rects. // Test non-zero value origin in source and OOB copy rects.
TEST_F(CopyTextureForBrowserTest, OutOfBounds) { TEST_F(CopyTextureForBrowserTest, OutOfBounds) {
wgpu::Texture source = wgpu::Texture source =