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 <enga@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He 2020-05-19 17:43:03 +00:00 committed by Commit Bot service account
parent 9b54466be4
commit 8d6b021a2a
3 changed files with 20 additions and 15 deletions

View File

@ -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<wgpu::TextureUsage>(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 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;

View File

@ -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<bool>(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 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 mipLevel = baseMipLevel; mipLevel < baseMipLevel + levelCount;
++mipLevel) {
uint32_t subresourceIndex = GetSubresourceIndex(mipLevel, arrayLayer);
ASSERT(subresourceIndex < mIsSubresourceContentInitializedAtIndex.size());
mIsSubresourceContentInitializedAtIndex[subresourceIndex] = isInitialized;

View File

@ -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;