@@ -204,12 +204,14 @@ HdSt_DomeLightComputationGPU::HdSt_DomeLightComputationGPU(
204204 const TfToken & shaderToken,
205205 const bool useCubemapAsSourceTexture,
206206 HdStSimpleLightingShaderPtr const &lightingShader,
207+ const unsigned int computedCubeMapDim,
207208 const unsigned int numLevels,
208209 const unsigned int level,
209210 const float roughness)
210211 : _shaderToken(shaderToken),
211212 _useCubemapAsSourceTexture(useCubemapAsSourceTexture),
212213 _lightingShader(lightingShader),
214+ _computedCubeMapDim(computedCubeMapDim),
213215 _numLevels(numLevels),
214216 _level(level),
215217 _roughness(roughness)
@@ -328,7 +330,7 @@ HdSt_DomeLightComputationGPU::Execute(
328330 // We are either generating a cubemap with 6 equal-sized faces from the
329331 // latlong texture, or a single 2D lookup texture that will
330332 // be the size of one face of the cubemap.
331- width = HdSt_ComputeDomeLightCubemapDimensions (srcDim)[ 0 ] ;
333+ width = _computedCubeMapDim ;
332334 height = width;
333335 }
334336
@@ -475,11 +477,29 @@ void HdSt_DomeLightMipmapComputationGPU::Execute(
475477 srcTextureObject->GenerateMipmaps ();
476478}
477479
478- GfVec3i HdSt_ComputeDomeLightCubemapDimensions (
479- const GfVec3i& srcDim)
480+ int HdSt_ComputeDomeLightCubemapWidth (
481+ const std::string& domeLightFilePath,
482+ const HgiTextureDesc& domelightTextureDesc,
483+ const unsigned int cubemapTargetMemoryMB)
480484{
481- const int width = std::max (srcDim[0 ] / 4 , 1 );
482- return { width, width, 1 };
485+ // Standard cubemap width calculation
486+ const int cubemapWidth = std::max (domelightTextureDesc.dimensions [0 ] / 4 , 1 );
487+
488+ if (cubemapTargetMemoryMB == 0 ) {
489+ return cubemapWidth;
490+ }
491+
492+ // Cubemap width calculation based on the target memory
493+ const size_t MB = 1048576 ;
494+ size_t blockWidth, blockHeight;
495+ const size_t bytesPerTexel = HgiGetDataSizeOfFormat (
496+ domelightTextureDesc.format , &blockWidth, &blockHeight);
497+ const size_t bytesPerPixel = bytesPerTexel / (blockHeight * blockWidth);
498+ // The 0.75 factor is to account for all lower mipmaps
499+ const int targetMemoryWidth =
500+ sqrt ((0.75 * cubemapTargetMemoryMB * MB) / (6 * bytesPerPixel));
501+
502+ return std::min (targetMemoryWidth, cubemapWidth);
483503}
484504
485505PXR_NAMESPACE_CLOSE_SCOPE
0 commit comments