// Copyright 2020 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <algorithm> #include <array> #include <string> #include <vector> #include "dawn/common/Constants.h" #include "dawn/common/Math.h" #include "dawn/tests/DawnTest.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/TestUtils.h" #include "dawn/utils/TextureUtils.h" #include "dawn/utils/WGPUHelpers.h" namespace dawn { namespace { TextureFormat; DAWN_TEST_PARAM_STRUCT(…); constexpr std::array<wgpu::TextureFormat, 3> kValidDepthCopyTextureFormats = …; constexpr std::array<wgpu::TextureFormat, 1> kValidDepthCopyFromBufferFormats = …; uint32_t GetBytesPerPixel(wgpu::TextureFormat format, wgpu::TextureAspect aspect) { … } // Bytes of unorm 16 of 0.23 is 0x3AE1, of which the 2 bytes are different. // This helps better test unorm 16 compute emulation path. constexpr float kInitDepth = …; // Bytes of unorm 16 of 0.23 is 0xB0A3. // Use a non-zero clear depth to better test unorm16 compute emulation path. constexpr float kClearDepth = …; // Initialize other mip levels with differrent garbage values for better testing constexpr float kGarbageDepth = …; static_assert …; static_assert …; constexpr uint8_t kInitStencil = …; constexpr uint8_t kClearStencil = …; constexpr uint8_t kGarbageStencil = …; static_assert …; static_assert …; class DepthStencilCopyTests : public DawnTestWithParams<DepthStencilCopyTestParams> { … }; // Test copying both aspects in a T2T copy, then copying only stencil. TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyStencil) { … } // Test that part of a non-renderable stencil aspect can be copied. Notably, // this test has different behavior on some platforms than T2TBothAspectsThenCopyStencil. TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyNonRenderableStencil) { … } // Test that part of a non-renderable, non-zero mip stencil aspect can be copied. Notably, // this test has different behavior on some platforms than T2TBothAspectsThenCopyStencil. TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyNonRenderableNonZeroMipStencil) { … } // Test copying both aspects in a T2T copy, then copying only depth. TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyDepth) { … } // Test copying both aspects in a T2T copy, then copying only depth at a nonzero mip. TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyNonZeroMipDepth) { … } // Test copying both aspects in a T2T copy, then copying stencil, then copying depth TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyStencilThenDepth) { … } // Test copying both aspects in a T2T copy, then copying depth, then copying stencil TEST_P(DepthStencilCopyTests, T2TBothAspectsThenCopyDepthThenStencil) { … } class DepthCopyTests : public DepthStencilCopyTests { … }; // Test copying the depth-only aspect into a buffer. TEST_P(DepthCopyTests, FromDepthAspect) { … } // Test copying the depth-only aspect into a buffer at a non-zero offset. TEST_P(DepthCopyTests, FromDepthAspectToBufferAtNonZeroOffset) { … } // Test copying the non-zero mip, depth-only aspect into a buffer. TEST_P(DepthCopyTests, FromNonZeroMipDepthAspect) { … } // Test buffer content outside of copy extent is preserved. // This test is made specifially for compute blit for depth16unorm emulation path. // The texel size is 2 byte, while in the compute shader we have to write 4 byte at a time. // When the copy extent width is an odd number, buffer content outside of the copy range is // inevitably written. So we need to make sure the original content of the buffer that's outside of // the copy extent is still correctly preserved. TEST_P(DepthCopyTests, PreserveBufferContent) { … } // Test compact buffer size edge case. // This test is made specifially for compute blit for depth16unorm emulation path. // When format is depth16unorm and width is an odd number, the size of the most compact buffer copy // target can be something that's not a multiple of 4. We need to make sure access don't go out of // bounds in the shader, when still writing to array<u32> in the compute shader. TEST_P(DepthCopyTests, BufferCopySizeEdgeCase) { … } class DepthCopyTests_Compat : public DepthCopyTests { … }; // Test copying the depth-only aspect into a buffer. TEST_P(DepthCopyTests_Compat, FromDepthAspect_Cube) { … } // Test copying the depth-only aspect into a buffer at a non-zero offset. TEST_P(DepthCopyTests_Compat, FromDepthAspectToBufferAtNonZeroOffset) { … } // Test copying the non-zero mip, depth-only aspect into a buffer. TEST_P(DepthCopyTests_Compat, FromNonZeroMipDepthAspect) { … } class DepthCopyFromBufferTests : public DepthStencilCopyTests { … }; // Test copying the depth-only aspect from a buffer. TEST_P(DepthCopyFromBufferTests, BufferToDepthAspect) { … } // Test copying the depth-only aspect from a buffer at a non-zero offset. TEST_P(DepthCopyFromBufferTests, BufferToNonRenderableDepthAspectAtNonZeroOffset) { … } // Test copying the depth-only aspect from a buffer at a non-zero offset. TEST_P(DepthCopyFromBufferTests, BufferToRenderableDepthAspectAtNonZeroOffset) { … } class StencilCopyTests : public DepthStencilCopyTests { … }; // Test copying the stencil-only aspect into a buffer. TEST_P(StencilCopyTests, FromStencilAspect) { … } // Test copying the stencil-only aspect into a buffer at a non-zero offset TEST_P(StencilCopyTests, FromStencilAspectAtNonZeroOffset) { … } // Test copying the non-zero mip, stencil-only aspect into a buffer. TEST_P(StencilCopyTests, FromNonZeroMipStencilAspect) { … } // Test buffer content outside of copy extent is preserved. // This test is made specifially for compute blit for stencil8 emulation path. // The texel size is 1 byte, while in the compute shader we have to write 4 byte at a time. // When the texture width % 4 != 0, buffer content outside of the copy range is // inevitably written. So we need to make sure the original content of the buffer that's outside of // the copy extent is still correctly preserved. TEST_P(StencilCopyTests, PreserveBufferContent) { … } // Test compact buffer size edge case. // This test is made specifially for compute blit for stencil8 emulation path. // When texture width % 4 != 0, the size of the most compact buffer copy // target can be something that's not a multiple of 4. We need to make sure access don't go out of // bounds in the shader, when still writing to array<u32> in the compute shader. TEST_P(StencilCopyTests, BufferCopySizeEdgeCase) { … } // Test copying to the stencil-aspect of a texture TEST_P(StencilCopyTests, ToStencilAspect) { … } // Test copying to the stencil-aspect of a texture at non-zero offset TEST_P(StencilCopyTests, ToStencilAspectAtNonZeroOffset) { … } // Test uploading to the non-zero mip, stencil-only aspect of a texture, // and then checking the contents with a stencil test. TEST_P(StencilCopyTests, CopyNonzeroMipThenReadWithStencilTest) { … } class StencilCopyTests_Compat : public StencilCopyTests { … }; TEST_P(StencilCopyTests_Compat, FromStencilAspect) { … } // Test copying the stencil-only aspect into a buffer at a non-zero offset TEST_P(StencilCopyTests_Compat, FromStencilAspectAtNonZeroOffset) { … } // Test copying the non-zero mip, stencil-only aspect into a buffer. TEST_P(StencilCopyTests_Compat, FromNonZeroMipStencilAspect) { … } class DepthStencilCopyTests_RegressionDawn1083 : public DepthStencilCopyTests { … }; // Regression test for crbug.com/dawn/1083. Checks that T2T copies with // various mip/layer counts/offsets works. TEST_P(DepthStencilCopyTests_RegressionDawn1083, Run) { … } DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); DAWN_INSTANTIATE_TEST_P(…); } // anonymous namespace } // namespace dawn