@@ -22,6 +22,19 @@ void LoadShader(std::vector<char>& out, const char* fileName);
2222// //////////////////////////////////////////////////////////////////////////////
2323// Class definitions
2424
25+ static uint32_t CalculateMipMapCount (uint32_t width, uint32_t height, uint32_t depth)
26+ {
27+ uint32_t mipMapCount = 1 ;
28+ while (width > 1 || height > 1 || depth > 1 )
29+ {
30+ ++mipMapCount;
31+ width /= 2 ;
32+ height /= 2 ;
33+ depth /= 2 ;
34+ }
35+ return mipMapCount;
36+ }
37+
2538class BaseImage
2639{
2740public:
@@ -85,13 +98,16 @@ void BaseImage::FillImageCreateInfo(RandomNumberGenerator& rand)
8598 constexpr uint32_t imageSizeMin = 8 ;
8699 constexpr uint32_t imageSizeMax = 2048 ;
87100
101+ const bool useMipMaps = rand.Generate () % 2 != 0 ;
102+
88103 ZeroMemory (&m_CreateInfo, sizeof (m_CreateInfo));
89104 m_CreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
90105 m_CreateInfo.imageType = VK_IMAGE_TYPE_2D;
91106 m_CreateInfo.extent .width = rand.Generate () % (imageSizeMax - imageSizeMin) + imageSizeMin;
92107 m_CreateInfo.extent .height = rand.Generate () % (imageSizeMax - imageSizeMin) + imageSizeMin;
93108 m_CreateInfo.extent .depth = 1 ;
94- m_CreateInfo.mipLevels = 1 ; // TODO ?
109+ m_CreateInfo.mipLevels = useMipMaps ?
110+ CalculateMipMapCount (m_CreateInfo.extent .width , m_CreateInfo.extent .height , m_CreateInfo.extent .depth ) : 1 ;
95111 m_CreateInfo.arrayLayers = 1 ;
96112 m_CreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
97113 m_CreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
0 commit comments