diff --git a/src/dawn/native/CopyTextureForBrowserHelper.cpp b/src/dawn/native/CopyTextureForBrowserHelper.cpp index 4a55372cc6..b3168db36a 100644 --- a/src/dawn/native/CopyTextureForBrowserHelper.cpp +++ b/src/dawn/native/CopyTextureForBrowserHelper.cpp @@ -222,8 +222,7 @@ namespace dawn::native { static_assert(sizeof(Uniform) == 176); // TODO(crbug.com/dawn/856): Expand copyTextureForBrowser to support any - // non-depth, non-stencil, non-compressed texture format pair copy. Now this API - // supports CopyImageBitmapToTexture normal format pairs. + // non-depth, non-stencil, non-compressed texture format pair copy. MaybeError ValidateCopyTextureFormatConversion(const wgpu::TextureFormat srcFormat, const wgpu::TextureFormat dstFormat) { switch (srcFormat) { @@ -258,6 +257,12 @@ namespace dawn::native { 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, wgpu::TextureFormat dstFormat) { auto pipeline = store->copyTextureForBrowserPipelines.find(dstFormat); @@ -327,6 +332,9 @@ namespace dawn::native { DAWN_TRY(device->ValidateObject(source->texture)); DAWN_TRY(device->ValidateObject(destination->texture)); + DAWN_TRY(ValidateTextureState(source->texture)); + DAWN_TRY(ValidateTextureState(destination->texture)); + DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *source, *copySize), "validating the ImageCopyTexture for the source"); DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *destination, *copySize), diff --git a/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp b/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp index 5981a0b763..881c602346 100644 --- a/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp +++ b/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp @@ -157,6 +157,38 @@ TEST_F(CopyTextureForBrowserTest, IncorrectUsage) { 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_F(CopyTextureForBrowserTest, OutOfBounds) { wgpu::Texture source =