Skip to content

Commit ba0b4d5

Browse files
Fix validation errors by adding the STORAGE and SAMPLED usages to any image that needs its mips computed
Also stop computing mips for images that have some regions specified already in non-base mip levels
1 parent df93ae2 commit ba0b4d5

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,17 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin,
847847
}
848848
}
849849

850-
auto needToCompMipsForThisImg = [](const asset::ICPUImage* img) -> bool {
851-
if (img->getRegions().size() == 0u)
850+
auto needToCompMipsForThisImg = [](const asset::ICPUImage* img) -> bool
851+
{
852+
if (img->getRegions().empty())
852853
return false;
853854
auto format = img->getCreationParameters().format;
854855
if (asset::isIntegerFormat(format) || asset::isBlockCompressionFormat(format))
855856
return false;
857+
// its enough to define a single mipmap region above the base level to prevent automatic computation
858+
for (auto& region : img->getRegions())
859+
if (region.imageSubresource.mipLevel)
860+
return false;
856861
return true;
857862
};
858863

@@ -1025,8 +1030,8 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin,
10251030
promotionRequest.originalFormat = params.format;
10261031
promotionRequest.usages = {};
10271032

1028-
const bool integerFmt = asset::isIntegerFormat(params.format);
1029-
if (!integerFmt)
1033+
// override the mip-count if its not an integer format and there was no mip-pyramid specified
1034+
if (params.mipLevels==1u && !asset::isIntegerFormat(params.format))
10301035
params.mipLevels = 1u + static_cast<uint32_t>(std::log2(static_cast<float>(core::max<uint32_t>(core::max<uint32_t>(params.extent.width, params.extent.height), params.extent.depth))));
10311036

10321037
if (cpuimg->getRegions().size())
@@ -1036,7 +1041,10 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin,
10361041

10371042
if (needToCompMipsForThisImg(cpuimg))
10381043
{
1039-
params.usage |= asset::IImage::EUF_TRANSFER_SRC_BIT;
1044+
params.usage |= asset::IImage::EUF_TRANSFER_SRC_BIT; // this is for blit
1045+
// I'm already adding usage flags for mip-mapping compute shader
1046+
params.usage |= asset::IImage::EUF_SAMPLED_BIT; // to read source mips
1047+
params.usage |= asset::IImage::EUF_STORAGE_BIT; // to write dst mips
10401048
// TODO: will change when we do the blit on compute shader.
10411049
promotionRequest.usages.blitDst = true;
10421050
promotionRequest.usages.blitSrc = true;
@@ -1095,12 +1103,8 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin,
10951103

10961104
if (needToCompMipsForThisImg(cpuimg))
10971105
{
1098-
// Todo(achal): Remove this API check once OpenGL(ES) does its format usage reporting correctly
1099-
if (_params.device->getAPIType() == EAT_VULKAN)
1100-
{
1101-
assert(_params.device->getPhysicalDevice()->getImageFormatUsagesOptimalTiling()[gpuimg->getCreationParameters().format].sampledImage);
1102-
assert(asset::isFloatingPointFormat(gpuimg->getCreationParameters().format) || asset::isNormalizedFormat(gpuimg->getCreationParameters().format)); // // for blits, can lift are polyphase compute
1103-
}
1106+
assert(_params.device->getPhysicalDevice()->getImageFormatUsagesOptimalTiling()[gpuimg->getCreationParameters().format].sampledImage);
1107+
assert(asset::isFloatingPointFormat(gpuimg->getCreationParameters().format) || asset::isNormalizedFormat(gpuimg->getCreationParameters().format));
11041108
cmdComputeMip(cpuimg, gpuimg, newLayout);
11051109
}
11061110
else

0 commit comments

Comments
 (0)