Skip to content

Commit 5c845d4

Browse files
committed
hotfix: Constrain view layers to actual layers.
1 parent 6ec68f6 commit 5c845d4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/video_core/amdgpu/resource.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,13 @@ struct Image {
227227
}
228228

229229
[[nodiscard]] u32 NumLayers() const noexcept {
230+
// Depth is the number of layers for Array images.
230231
u32 slices = depth + 1;
231-
const auto img_type = static_cast<ImageType>(type);
232-
if (img_type == ImageType::Color3D) {
232+
if (GetType() == ImageType::Color3D) {
233+
// Depth is the actual texture depth for 3D images.
233234
slices = 1;
234-
} else if (img_type == ImageType::Cube) {
235+
} else if (IsCube()) {
236+
// Depth is the number of full cubes for Cube images.
235237
slices *= 6;
236238
}
237239
if (pow2pad) {
@@ -315,7 +317,9 @@ struct Image {
315317
case ImageType::Color2DMsaaArray:
316318
return 1;
317319
default:
318-
return last_level - base_level + 1;
320+
// Constrain to actual number of available levels.
321+
const auto max_level = std::min<u32>(last_level + 1, NumLevels());
322+
return max_level > base_level ? max_level - base_level : 1;
319323
}
320324
}
321325

@@ -327,7 +331,9 @@ struct Image {
327331
case ImageType::Color3D:
328332
return 1;
329333
default:
330-
return last_array - base_array + 1;
334+
// Constrain to actual number of available layers.
335+
const auto max_array = std::min<u32>(last_array + 1, NumLayers());
336+
return max_array > base_array ? max_array - base_array : 1;
331337
}
332338
}
333339
};

0 commit comments

Comments
 (0)