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;