From 8d6b021a2a134068bc46a7773ae553f8d957b937 Mon Sep 17 00:00:00 2001 From: Yunchao He Date: Tue, 19 May 2020 17:43:03 +0000 Subject: [PATCH] Fix a bug for texture subresource Texture subresource total number is wrongly calculated. This change fixed the tiny bug. Bug: dawn:157 Change-Id: Id6dad7e60fa9fe63dac3567814486d3f9dfcee9e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21902 Reviewed-by: Austin Eng Commit-Queue: Yunchao He --- src/dawn_native/PassResourceUsageTracker.cpp | 13 ++++++------ src/dawn_native/Texture.cpp | 21 ++++++++++++-------- src/dawn_native/Texture.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/dawn_native/PassResourceUsageTracker.cpp b/src/dawn_native/PassResourceUsageTracker.cpp index 1f9c350062..dd1c022937 100644 --- a/src/dawn_native/PassResourceUsageTracker.cpp +++ b/src/dawn_native/PassResourceUsageTracker.cpp @@ -44,15 +44,15 @@ namespace dawn_native { textureUsage.usage |= usage; // Set usages for subresources - uint32_t subresourceCount = - texture->GetSubresourceIndex(texture->GetNumMipLevels(), texture->GetArrayLayers()); + uint32_t subresourceCount = texture->GetSubresourceCount(); if (!textureUsage.subresourceUsages.size()) { textureUsage.subresourceUsages = std::vector(subresourceCount, wgpu::TextureUsage::None); } - for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; ++mipLevel) { - for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; - ++arrayLayer) { + for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; + ++arrayLayer) { + for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; + ++mipLevel) { uint32_t subresourceIndex = texture->GetSubresourceIndex(mipLevel, arrayLayer); textureUsage.subresourceUsages[subresourceIndex] |= usage; } @@ -64,8 +64,7 @@ namespace dawn_native { PassTextureUsage& passTextureUsage = mTextureUsages[texture]; passTextureUsage.usage |= textureUsage.usage; - uint32_t subresourceCount = - texture->GetSubresourceIndex(texture->GetNumMipLevels(), texture->GetArrayLayers()); + uint32_t subresourceCount = texture->GetSubresourceCount(); ASSERT(textureUsage.subresourceUsages.size() == subresourceCount); if (!passTextureUsage.subresourceUsages.size()) { passTextureUsage.subresourceUsages = textureUsage.subresourceUsages; diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 1861c0c4f2..bc33ec794c 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -351,8 +351,7 @@ namespace dawn_native { mSampleCount(descriptor->sampleCount), mUsage(descriptor->usage), mState(state) { - uint32_t subresourceCount = - GetSubresourceIndex(descriptor->mipLevelCount, descriptor->arrayLayerCount); + uint32_t subresourceCount = GetSubresourceCount(); mIsSubresourceContentInitializedAtIndex = std::vector(subresourceCount, false); // Add readonly storage usage if the texture has a storage usage. The validation rules in @@ -399,6 +398,10 @@ namespace dawn_native { ASSERT(!IsError()); return mSampleCount; } + uint32_t TextureBase::GetSubresourceCount() const { + ASSERT(!IsError()); + return mMipLevelCount * mArrayLayerCount; + } wgpu::TextureUsage TextureBase::GetUsage() const { ASSERT(!IsError()); return mUsage; @@ -423,9 +426,10 @@ namespace dawn_native { uint32_t baseArrayLayer, uint32_t layerCount) const { ASSERT(!IsError()); - for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; ++mipLevel) { - for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; - ++arrayLayer) { + for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; + ++arrayLayer) { + for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; + ++mipLevel) { uint32_t subresourceIndex = GetSubresourceIndex(mipLevel, arrayLayer); ASSERT(subresourceIndex < mIsSubresourceContentInitializedAtIndex.size()); if (!mIsSubresourceContentInitializedAtIndex[subresourceIndex]) { @@ -442,9 +446,10 @@ namespace dawn_native { uint32_t baseArrayLayer, uint32_t layerCount) { ASSERT(!IsError()); - for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; ++mipLevel) { - for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; - ++arrayLayer) { + for (uint32_t arrayLayer = baseArrayLayer; arrayLayer < baseArrayLayer + layerCount; + ++arrayLayer) { + for (uint32_t mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount; + ++mipLevel) { uint32_t subresourceIndex = GetSubresourceIndex(mipLevel, arrayLayer); ASSERT(subresourceIndex < mIsSubresourceContentInitializedAtIndex.size()); mIsSubresourceContentInitializedAtIndex[subresourceIndex] = isInitialized; diff --git a/src/dawn_native/Texture.h b/src/dawn_native/Texture.h index d14696cd7a..7211839de8 100644 --- a/src/dawn_native/Texture.h +++ b/src/dawn_native/Texture.h @@ -55,6 +55,7 @@ namespace dawn_native { uint32_t GetArrayLayers() const; uint32_t GetNumMipLevels() const; uint32_t GetSampleCount() const; + uint32_t GetSubresourceCount() const; wgpu::TextureUsage GetUsage() const; TextureState GetTextureState() const; uint32_t GetSubresourceIndex(uint32_t mipLevel, uint32_t arraySlice) const;