Skip to content

Commit b455726

Browse files
Ok, this is bad
1 parent e32d30a commit b455726

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,34 +1035,55 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin,
10351035
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))));
10361036

10371037
if (cpuimg->getRegions().size())
1038-
{
10391038
params.usage |= asset::IImage::EUF_TRANSFER_DST_BIT;
1040-
}
1041-
1042-
if (needToCompMipsForThisImg(cpuimg))
1039+
1040+
const bool computeMips = needToCompMipsForThisImg(cpuimg);
1041+
if (computeMips)
10431042
{
10441043
params.usage |= asset::IImage::EUF_TRANSFER_SRC_BIT; // this is for blit
10451044
// I'm already adding usage flags for mip-mapping compute shader
10461045
params.usage |= asset::IImage::EUF_SAMPLED_BIT; // to read source mips
1047-
params.usage |= asset::IImage::EUF_STORAGE_BIT; // to write dst mips
1046+
// but we don't add the STORAGE USAGE
10481047
// TODO: will change when we do the blit on compute shader.
10491048
promotionRequest.usages.blitDst = true;
10501049
promotionRequest.usages.blitSrc = true;
10511050
}
10521051

1052+
auto physDev = _params.device->getPhysicalDevice();
10531053
promotionRequest.usages = promotionRequest.usages | params.usage;
1054-
auto newFormat = _params.utilities->getLogicalDevice()->getPhysicalDevice()->promoteImageFormat(promotionRequest, video::IGPUImage::ET_OPTIMAL);
1054+
auto newFormat = physDev->promoteImageFormat(promotionRequest, video::IGPUImage::ET_OPTIMAL);
1055+
auto newFormatIsStorable = physDev->getImageFormatUsagesOptimalTiling()[newFormat].storageImage;
10551056

10561057
// If Format Promotion failed try the same usages but with linear tiling.
1057-
if (params.format == asset::EF_UNKNOWN)
1058-
newFormat = _params.utilities->getLogicalDevice()->getPhysicalDevice()->promoteImageFormat(promotionRequest, video::IGPUImage::ET_LINEAR);
1058+
if (newFormat == asset::EF_UNKNOWN)
1059+
{
1060+
newFormat = physDev->promoteImageFormat(promotionRequest, video::IGPUImage::ET_LINEAR);
1061+
newFormatIsStorable = physDev->getImageFormatUsagesLinearTiling()[newFormat].storageImage;
1062+
}
10591063

1060-
assert(params.format != asset::EF_UNKNOWN); // No feasible supported format found for creating this image
1064+
assert(newFormat != asset::EF_UNKNOWN); // No feasible supported format found for creating this image
10611065
params.format = newFormat;
10621066

1067+
#if 0 // TODO: Bump our minimum Vulkan version to 1.2, then implement https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageFormatListCreateInfo.html in our API
1068+
// now add the STORAGE USAGE
1069+
if (computeMips)
1070+
{
1071+
// formats like SRGB etc. can't be stored to
1072+
params.usage |= asset::IImage::EUF_STORAGE_BIT;
1073+
// but image views with formats that are store-able can be created
1074+
if (!newFormatIsStorable)
1075+
{
1076+
params.flags |= asset::IImage::ECF_MUTABLE_FORMAT_BIT;
1077+
params.flags |= asset::IImage::ECF_EXTENDED_USAGE_BIT;
1078+
if (asset::isBlockCompressionFormat(newFormat))
1079+
params.flags |= asset::IImage::ECF_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT;
1080+
}
1081+
}
1082+
#endif
1083+
10631084
auto gpuimg = _params.device->createImage(std::move(params));
10641085
auto gpuimgMemReqs = gpuimg->getMemoryReqs();
1065-
gpuimgMemReqs.memoryTypeBits &= _params.device->getPhysicalDevice()->getDeviceLocalMemoryTypeBits();
1086+
gpuimgMemReqs.memoryTypeBits &= physDev->getDeviceLocalMemoryTypeBits();
10661087
auto gpuimgMem = _params.device->allocate(gpuimgMemReqs, gpuimg.get());
10671088

10681089
res->operator[](i) = std::move(gpuimg);

0 commit comments

Comments
 (0)