From 8268dc3e438533ccc91df7d0f799b9bc98ac2dbc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 15 Jan 2021 17:36:39 +0000 Subject: [PATCH] StorageTextureTests: Use textureNumLayers() Instead of hardcoding the number of array layers Bug: tint:140 Bug: tint:437 Change-Id: Ic9ea6a0e2853d8dbc29a840deff0e6938ff5e4d4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37849 Commit-Queue: Ben Clayton Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng --- src/tests/end2end/StorageTextureTests.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/tests/end2end/StorageTextureTests.cpp b/src/tests/end2end/StorageTextureTests.cpp index acbec69623..9ca549417f 100644 --- a/src/tests/end2end/StorageTextureTests.cpp +++ b/src/tests/end2end/StorageTextureTests.cpp @@ -285,12 +285,10 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { return ""; } - std::string CommonReadOnlyTestCode(wgpu::TextureFormat format, - int layerCount = 1, - bool is2DArray = false) { - // TODO(bclayton): Dynamically retrieve layerCount + std::string CommonReadOnlyTestCode(wgpu::TextureFormat format, bool is2DArray = false) { std::string componentFmt = utils::GetColorTextureComponentWGSLType(format); auto texelType = "vec4<" + componentFmt + ">"; + auto* layerCount = is2DArray ? "textureNumLayers(storageImage0)" : "1"; auto* textureLoad = is2DArray ? "textureLoad(storageImage0, vec2(x, y), i32(layer))" : "textureLoad(storageImage0, vec2(x, y))"; @@ -321,11 +319,10 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { std::string CommonWriteOnlyTestCode(const char* stage, wgpu::TextureFormat format, - int layerCount = 1, bool is2DArray = false) { - // TODO(bclayton): Dynamically retrieve layerCount std::string componentFmt = utils::GetColorTextureComponentWGSLType(format); auto texelType = "vec4<" + componentFmt + ">"; + auto* layerCount = is2DArray ? "textureNumLayers(storageImage0)" : "1"; auto* textureStore = is2DArray ? "textureStore(storageImage0, vec2(x, y), layer, expected)" : "textureStore(storageImage0, vec2(x, y), expected)"; @@ -351,10 +348,8 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { return ostream.str(); } - std::string CommonReadWriteTestCode(wgpu::TextureFormat format, - int layerCount = 1, - bool is2DArray = false) { - // TODO(bclayton): Dynamically retrieve layerCount + std::string CommonReadWriteTestCode(wgpu::TextureFormat format, bool is2DArray = false) { + auto* layerCount = is2DArray ? "textureNumLayers(storageImage0)" : "1"; auto* textureStore = is2DArray ? "textureStore(storageImage0, texcoord, layer, " "textureLoad(storageImage1, texcoord, layer))" : "textureStore(storageImage0, texcoord, " @@ -923,7 +918,7 @@ TEST_P(StorageTextureTests, Readonly2DArrayStorageTexture) { }; [[set(0), binding(1)]] var dstBuffer : DstBuffer; -)" << CommonReadOnlyTestCode(kTextureFormat, kArrayLayerCount, true) +)" << CommonReadOnlyTestCode(kTextureFormat, true) << R"( [[stage(compute)]] fn main() -> void { if (doTest()) { @@ -950,8 +945,7 @@ TEST_P(StorageTextureTests, Writeonly2DArrayStorageTexture) { kWidth, kHeight, kArrayLayerCount); // Write the expected pixel values into the write-only storage texture. - const std::string computeShader = - CommonWriteOnlyTestCode("compute", kTextureFormat, kArrayLayerCount, true); + const std::string computeShader = CommonWriteOnlyTestCode("compute", kTextureFormat, true); WriteIntoStorageTextureInComputePass(writeonlyStorageTexture, computeShader.c_str()); // Verify the pixel data in the write-only storage texture is expected.