diff --git a/src/tests/end2end/CompressedTextureFormatTests.cpp b/src/tests/end2end/CompressedTextureFormatTests.cpp index 7783c4bcdd..cfe12d0a56 100644 --- a/src/tests/end2end/CompressedTextureFormatTests.cpp +++ b/src/tests/end2end/CompressedTextureFormatTests.cpp @@ -19,7 +19,7 @@ #include "common/Math.h" #include "utils/ComboRenderPipelineDescriptor.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" // The helper struct to configure the copies between buffers and textures. diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp index 0cb348c43b..096f5df1b2 100644 --- a/src/tests/end2end/CopyTests.cpp +++ b/src/tests/end2end/CopyTests.cpp @@ -18,7 +18,7 @@ #include "common/Constants.h" #include "common/Math.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" // For MinimumBufferSpec bytesPerRow and rowsPerImage, compute a default from the copy extent. diff --git a/src/tests/end2end/CopyTextureForBrowserTests.cpp b/src/tests/end2end/CopyTextureForBrowserTests.cpp index 1ca8ea47e9..1aca79d5c1 100644 --- a/src/tests/end2end/CopyTextureForBrowserTests.cpp +++ b/src/tests/end2end/CopyTextureForBrowserTests.cpp @@ -18,7 +18,7 @@ #include "common/Math.h" #include "utils/ComboRenderPipelineDescriptor.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" namespace { diff --git a/src/tests/end2end/DepthBiasTests.cpp b/src/tests/end2end/DepthBiasTests.cpp index 7a9d41e937..38213cf761 100644 --- a/src/tests/end2end/DepthBiasTests.cpp +++ b/src/tests/end2end/DepthBiasTests.cpp @@ -16,7 +16,7 @@ #include "common/Math.h" #include "tests/DawnTest.h" #include "utils/ComboRenderPipelineDescriptor.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" constexpr static unsigned int kRTSize = 2; diff --git a/src/tests/end2end/DepthStencilCopyTests.cpp b/src/tests/end2end/DepthStencilCopyTests.cpp index 87c1e4040e..8b875cea62 100644 --- a/src/tests/end2end/DepthStencilCopyTests.cpp +++ b/src/tests/end2end/DepthStencilCopyTests.cpp @@ -19,7 +19,7 @@ #include "common/Math.h" #include "utils/ComboRenderPipelineDescriptor.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" class DepthStencilCopyTests : public DawnTest { diff --git a/src/tests/end2end/QueueTests.cpp b/src/tests/end2end/QueueTests.cpp index 41281c807a..bc68d67a6a 100644 --- a/src/tests/end2end/QueueTests.cpp +++ b/src/tests/end2end/QueueTests.cpp @@ -21,7 +21,7 @@ #include "common/Math.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" class QueueTests : public DawnTest {}; diff --git a/src/tests/end2end/StorageTextureTests.cpp b/src/tests/end2end/StorageTextureTests.cpp index bdef9ac054..c8cb6a0411 100644 --- a/src/tests/end2end/StorageTextureTests.cpp +++ b/src/tests/end2end/StorageTextureTests.cpp @@ -18,7 +18,7 @@ #include "common/Constants.h" #include "common/Math.h" #include "utils/ComboRenderPipelineDescriptor.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" namespace { @@ -481,20 +481,6 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { return device.CreateBuffer(&descriptor); } - wgpu::TextureDimension ViewDimensionToTextureDimension( - const wgpu::TextureViewDimension dimension) { - switch (dimension) { - case wgpu::TextureViewDimension::e2D: - case wgpu::TextureViewDimension::e2DArray: - return wgpu::TextureDimension::e2D; - case wgpu::TextureViewDimension::e3D: - return wgpu::TextureDimension::e3D; - default: - UNREACHABLE(); - break; - } - } - wgpu::Texture CreateTextureWithTestData( const std::vector& initialTextureData, wgpu::TextureFormat format, @@ -527,7 +513,7 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { wgpu::Texture outputTexture = CreateTexture(format, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopyDst, kWidth, - kHeight, sliceCount, ViewDimensionToTextureDimension(dimension)); + kHeight, sliceCount, utils::ViewDimensionToTextureDimension(dimension)); wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); @@ -1025,9 +1011,9 @@ TEST_P(StorageTextureTests, Writeonly2DArrayOr3DStorageTexture) { // Prepare the write-only storage texture. for (wgpu::TextureViewDimension dimension : dimensions) { - wgpu::Texture writeonlyStorageTexture = - CreateTexture(kTextureFormat, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopySrc, - kWidth, kHeight, kSliceCount, ViewDimensionToTextureDimension(dimension)); + wgpu::Texture writeonlyStorageTexture = CreateTexture( + kTextureFormat, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopySrc, kWidth, + kHeight, kSliceCount, utils::ViewDimensionToTextureDimension(dimension)); // Write the expected pixel values into the write-only storage texture. const std::string computeShader = @@ -1060,9 +1046,9 @@ TEST_P(StorageTextureTests, ReadWrite2DArrayOr3DStorageTexture) { wgpu::Texture readonlyStorageTexture = CreateTextureWithTestData(initialTextureData, kTextureFormat, dimension); // Prepare the write-only storage texture. - wgpu::Texture writeonlyStorageTexture = - CreateTexture(kTextureFormat, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopySrc, - kWidth, kHeight, kSliceCount, ViewDimensionToTextureDimension(dimension)); + wgpu::Texture writeonlyStorageTexture = CreateTexture( + kTextureFormat, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopySrc, kWidth, + kHeight, kSliceCount, utils::ViewDimensionToTextureDimension(dimension)); // Read values from read-only storage texture and write into the write-only storage texture. const std::string computeShader = CommonReadWriteTestCode(kTextureFormat, dimension); diff --git a/src/tests/end2end/TextureFormatTests.cpp b/src/tests/end2end/TextureFormatTests.cpp index 08152960f2..31ba1dc499 100644 --- a/src/tests/end2end/TextureFormatTests.cpp +++ b/src/tests/end2end/TextureFormatTests.cpp @@ -17,7 +17,7 @@ #include "common/Assert.h" #include "common/Math.h" #include "utils/ComboRenderPipelineDescriptor.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" #include diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp index bd560bd84d..061b58e59b 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -17,7 +17,7 @@ #include "common/Math.h" #include "tests/unittests/validation/ValidationTest.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" class CopyCommandTest : public ValidationTest { diff --git a/src/tests/unittests/validation/CopyTextureForBrowserTests.cpp b/src/tests/unittests/validation/CopyTextureForBrowserTests.cpp index 02852d0bf7..ad93f7d152 100644 --- a/src/tests/unittests/validation/CopyTextureForBrowserTests.cpp +++ b/src/tests/unittests/validation/CopyTextureForBrowserTests.cpp @@ -17,7 +17,7 @@ #include "common/Math.h" #include "tests/unittests/validation/ValidationTest.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" class CopyTextureForBrowserTest : public ValidationTest { diff --git a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp index db52141e14..6cbcfa568c 100644 --- a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp +++ b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp @@ -16,7 +16,7 @@ #include "common/Math.h" #include "utils/TestUtils.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" namespace { diff --git a/src/tests/unittests/validation/StorageTextureValidationTests.cpp b/src/tests/unittests/validation/StorageTextureValidationTests.cpp index 6868daeb9b..8a10014948 100644 --- a/src/tests/unittests/validation/StorageTextureValidationTests.cpp +++ b/src/tests/unittests/validation/StorageTextureValidationTests.cpp @@ -15,7 +15,7 @@ #include "common/Assert.h" #include "tests/unittests/validation/ValidationTest.h" #include "utils/ComboRenderPipelineDescriptor.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" class StorageTextureValidationTests : public ValidationTest { @@ -718,13 +718,9 @@ TEST_F(StorageTextureValidationTests, StorageTextureViewDimensionInBindGroup) { for (wgpu::TextureViewDimension dimensionOfTextureView : kSupportedDimensions) { // Create a texture view with given texture view dimension. - wgpu::TextureDimension dimension = wgpu::TextureDimension::e2D; - if (dimensionOfTextureView == wgpu::TextureViewDimension::e3D) { - dimension = wgpu::TextureDimension::e3D; - } - wgpu::Texture texture = - CreateTexture(wgpu::TextureUsage::Storage, kStorageTextureFormat, 1, - kDepthOrArrayLayers, dimension); + wgpu::Texture texture = CreateTexture( + wgpu::TextureUsage::Storage, kStorageTextureFormat, 1, kDepthOrArrayLayers, + utils::ViewDimensionToTextureDimension(dimensionOfTextureView)); wgpu::TextureViewDescriptor textureViewDescriptor = kDefaultTextureViewDescriptor; textureViewDescriptor.dimension = dimensionOfTextureView; diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index 9fd2eec1ab..2bdfaa7bb6 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -16,7 +16,7 @@ #include "common/Constants.h" #include "utils/ComboRenderPipelineDescriptor.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" namespace { diff --git a/src/utils/BUILD.gn b/src/utils/BUILD.gn index ba8a0f41f1..f372b07464 100644 --- a/src/utils/BUILD.gn +++ b/src/utils/BUILD.gn @@ -78,8 +78,8 @@ static_library("dawn_utils") { "TerribleCommandBuffer.h", "TestUtils.cpp", "TestUtils.h", - "TextureFormatUtils.cpp", - "TextureFormatUtils.h", + "TextureUtils.cpp", + "TextureUtils.h", "Timer.h", "WGPUHelpers.cpp", "WGPUHelpers.h", diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 91ad7c314a..3ed0994f2f 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -27,8 +27,8 @@ target_sources(dawn_utils PRIVATE "TerribleCommandBuffer.h" "TestUtils.cpp" "TestUtils.h" - "TextureFormatUtils.cpp" - "TextureFormatUtils.h" + "TextureUtils.cpp" + "TextureUtils.h" "Timer.h" "WGPUHelpers.cpp" "WGPUHelpers.h" diff --git a/src/utils/TestUtils.cpp b/src/utils/TestUtils.cpp index 433ef3730f..adbdd28be1 100644 --- a/src/utils/TestUtils.cpp +++ b/src/utils/TestUtils.cpp @@ -17,7 +17,7 @@ #include "common/Assert.h" #include "common/Constants.h" #include "common/Math.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" #include "utils/WGPUHelpers.h" #include diff --git a/src/utils/TextureFormatUtils.cpp b/src/utils/TextureUtils.cpp similarity index 95% rename from src/utils/TextureFormatUtils.cpp rename to src/utils/TextureUtils.cpp index b4c0ad9e22..fd359a2e86 100644 --- a/src/utils/TextureFormatUtils.cpp +++ b/src/utils/TextureUtils.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "TextureFormatUtils.h" +#include "TextureUtils.h" namespace utils { bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format) { @@ -379,4 +379,22 @@ namespace utils { } } + wgpu::TextureDimension ViewDimensionToTextureDimension( + const wgpu::TextureViewDimension dimension) { + switch (dimension) { + case wgpu::TextureViewDimension::e2D: + case wgpu::TextureViewDimension::e2DArray: + case wgpu::TextureViewDimension::Cube: + case wgpu::TextureViewDimension::CubeArray: + return wgpu::TextureDimension::e2D; + case wgpu::TextureViewDimension::e3D: + return wgpu::TextureDimension::e3D; + // TODO(crbug.com/dawn/814): Implement for 1D texture. + case wgpu::TextureViewDimension::e1D: + default: + UNREACHABLE(); + break; + } + } + } // namespace utils diff --git a/src/utils/TextureFormatUtils.h b/src/utils/TextureUtils.h similarity index 95% rename from src/utils/TextureFormatUtils.h rename to src/utils/TextureUtils.h index 3c437c7005..51713f1f99 100644 --- a/src/utils/TextureFormatUtils.h +++ b/src/utils/TextureUtils.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef UTILS_TEXTURE_FORMAT_UTILS_H_ -#define UTILS_TEXTURE_FORMAT_UTILS_H_ +#ifndef UTILS_TEXTURE_UTILS_H_ +#define UTILS_TEXTURE_UTILS_H_ #include @@ -95,6 +95,9 @@ namespace utils { const char* GetWGSLColorTextureComponentType(wgpu::TextureFormat textureFormat); const char* GetWGSLImageFormatQualifier(wgpu::TextureFormat textureFormat); + + wgpu::TextureDimension ViewDimensionToTextureDimension( + const wgpu::TextureViewDimension dimension); } // namespace utils #endif diff --git a/src/utils/WGPUHelpers.h b/src/utils/WGPUHelpers.h index 09070ca25a..1c239dde9e 100644 --- a/src/utils/WGPUHelpers.h +++ b/src/utils/WGPUHelpers.h @@ -22,7 +22,7 @@ #include #include "common/Constants.h" -#include "utils/TextureFormatUtils.h" +#include "utils/TextureUtils.h" namespace utils {