diff --git a/src/common/Constants.h b/src/common/Constants.h index 289df4b614..423fe0bf94 100644 --- a/src/common/Constants.h +++ b/src/common/Constants.h @@ -58,11 +58,13 @@ static constexpr float kLodMin = 0.0; static constexpr float kLodMax = 1000.0; // Max texture size constants -static constexpr uint32_t kMaxTextureSize = 8192u; -static constexpr uint32_t kMaxTexture2DArrayLayers = 256u; +static constexpr uint32_t kMaxTextureDimension1D = 8192u; +static constexpr uint32_t kMaxTextureDimension2D = 8192u; +static constexpr uint32_t kMaxTextureDimension3D = 2048u; +static constexpr uint32_t kMaxTextureArrayLayers = 2048u; static constexpr uint32_t kMaxTexture2DMipLevels = 14u; -static_assert(1 << (kMaxTexture2DMipLevels - 1) == kMaxTextureSize, - "kMaxTexture2DMipLevels and kMaxTextureSize size mismatch"); +static_assert(1 << (kMaxTexture2DMipLevels - 1) == kMaxTextureDimension2D, + "kMaxTexture2DMipLevels and kMaxTextureDimension2D size mismatch"); // Offset alignment for CopyB2B. Strictly speaking this alignment is required only // on macOS, but we decide to do it on all platforms. diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index c812958333..84f5a568ae 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -89,7 +89,8 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Swapchain size can't be empty"); } - if (descriptor->width > kMaxTextureSize || descriptor->height > kMaxTextureSize) { + if (descriptor->width > kMaxTextureDimension2D || + descriptor->height > kMaxTextureDimension2D) { return DAWN_VALIDATION_ERROR("Swapchain size too big"); } } diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 171f02b04c..310829a161 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -155,8 +155,8 @@ namespace dawn_native { MaybeError ValidateTextureSize(const TextureDescriptor* descriptor, const Format* format) { ASSERT(descriptor->size.width != 0 && descriptor->size.height != 0); - if (descriptor->size.width > kMaxTextureSize || - descriptor->size.height > kMaxTextureSize) { + if (descriptor->size.width > kMaxTextureDimension2D || + descriptor->size.height > kMaxTextureDimension2D) { return DAWN_VALIDATION_ERROR("Texture max size exceeded"); } @@ -176,7 +176,7 @@ namespace dawn_native { } if (descriptor->dimension == wgpu::TextureDimension::e2D && - descriptor->size.depth > kMaxTexture2DArrayLayers) { + descriptor->size.depth > kMaxTextureArrayLayers) { return DAWN_VALIDATION_ERROR("Texture 2D array layer count exceeded"); } if (descriptor->mipLevelCount > kMaxTexture2DMipLevels) { @@ -444,12 +444,12 @@ namespace dawn_native { uint32_t TextureBase::GetSubresourceIndex(uint32_t mipLevel, uint32_t arraySlice, Aspect aspect) const { - ASSERT(arraySlice <= kMaxTexture2DArrayLayers); + ASSERT(arraySlice <= kMaxTextureArrayLayers); ASSERT(mipLevel <= kMaxTexture2DMipLevels); ASSERT(HasOneBit(aspect)); - static_assert(kMaxTexture2DMipLevels <= - std::numeric_limits::max() / kMaxTexture2DArrayLayers, - "texture size overflows uint32_t"); + static_assert( + kMaxTexture2DMipLevels <= std::numeric_limits::max() / kMaxTextureArrayLayers, + "texture size overflows uint32_t"); return mipLevel + GetNumMipLevels() * (arraySlice + GetArrayLayers() * GetAspectIndex(aspect)); } diff --git a/src/tests/end2end/SwapChainValidationTests.cpp b/src/tests/end2end/SwapChainValidationTests.cpp index bc68d96f10..31081b0cfc 100644 --- a/src/tests/end2end/SwapChainValidationTests.cpp +++ b/src/tests/end2end/SwapChainValidationTests.cpp @@ -128,23 +128,23 @@ TEST_P(SwapChainValidationTests, InvalidCreationSize) { ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &desc)); } - // A width of kMaxTextureSize is valid but kMaxTextureSize + 1 isn't. + // A width of kMaxTextureDimension2D is valid but kMaxTextureDimension2D + 1 isn't. { wgpu::SwapChainDescriptor desc = goodDescriptor; - desc.width = kMaxTextureSize; + desc.width = kMaxTextureDimension2D; device.CreateSwapChain(surface, &desc); - desc.width = kMaxTextureSize + 1; + desc.width = kMaxTextureDimension2D + 1; ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &desc)); } - // A height of kMaxTextureSize is valid but kMaxTextureSize + 1 isn't. + // A height of kMaxTextureDimension2D is valid but kMaxTextureDimension2D + 1 isn't. { wgpu::SwapChainDescriptor desc = goodDescriptor; - desc.height = kMaxTextureSize; + desc.height = kMaxTextureDimension2D; device.CreateSwapChain(surface, &desc); - desc.height = kMaxTextureSize + 1; + desc.height = kMaxTextureDimension2D + 1; ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &desc)); } } diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index 7638e29ee3..a1a3e1b4a8 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -213,26 +213,26 @@ namespace { TEST_F(TextureValidationTest, ArrayLayerCount) { wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); - // Array layer count exceeding kMaxTexture2DArrayLayers is not allowed + // Array layer count exceeding kMaxTextureArrayLayers is not allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.depth = kMaxTexture2DArrayLayers + 1u; + descriptor.size.depth = kMaxTextureArrayLayers + 1u; ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); } - // Array layer count less than kMaxTexture2DArrayLayers is allowed; + // Array layer count less than kMaxTextureArrayLayers is allowed; { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.depth = kMaxTexture2DArrayLayers >> 1; + descriptor.size.depth = kMaxTextureArrayLayers >> 1; device.CreateTexture(&descriptor); } - // Array layer count equal to kMaxTexture2DArrayLayers is allowed; + // Array layer count equal to kMaxTextureArrayLayers is allowed; { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.depth = kMaxTexture2DArrayLayers; + descriptor.size.depth = kMaxTextureArrayLayers; device.CreateTexture(&descriptor); } @@ -242,29 +242,29 @@ namespace { TEST_F(TextureValidationTest, TextureSize) { wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); - // Texture size exceeding kMaxTextureSize is not allowed + // Texture size exceeding kMaxTextureDimension2D is not allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.width = kMaxTextureSize + 1u; - descriptor.size.height = kMaxTextureSize + 1u; + descriptor.size.width = kMaxTextureDimension2D + 1u; + descriptor.size.height = kMaxTextureDimension2D + 1u; ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); } - // Texture size less than kMaxTextureSize is allowed + // Texture size less than kMaxTextureDimension2D is allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.width = kMaxTextureSize >> 1; - descriptor.size.height = kMaxTextureSize >> 1; + descriptor.size.width = kMaxTextureDimension2D >> 1; + descriptor.size.height = kMaxTextureDimension2D >> 1; device.CreateTexture(&descriptor); } - // Texture equal to kMaxTextureSize is allowed + // Texture equal to kMaxTextureDimension2D is allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.size.width = kMaxTextureSize; - descriptor.size.height = kMaxTextureSize; + descriptor.size.width = kMaxTextureDimension2D; + descriptor.size.height = kMaxTextureDimension2D; device.CreateTexture(&descriptor); }