diff --git a/pxr/imaging/hd/material.cpp b/pxr/imaging/hd/material.cpp index e7c28e2881..6a8816fad2 100644 --- a/pxr/imaging/hd/material.cpp +++ b/pxr/imaging/hd/material.cpp @@ -270,6 +270,7 @@ _GetSamplerParameters( nodeTypeId, parameters, sdrNode, nodePath), _ResolveMagSamplerParameter( nodeTypeId, parameters, sdrNode, nodePath), + /*maxAnisotropy*/16, HdBorderColorTransparentBlack, /*enableCompare*/false, HdCmpFuncNever }; diff --git a/pxr/imaging/hd/types.cpp b/pxr/imaging/hd/types.cpp index 8224f03f11..32f5d52a30 100644 --- a/pxr/imaging/hd/types.cpp +++ b/pxr/imaging/hd/types.cpp @@ -109,7 +109,8 @@ HdSamplerParameters::HdSamplerParameters() HdSamplerParameters::HdSamplerParameters( HdWrap wrapS, HdWrap wrapT, HdWrap wrapR, - HdMinFilter minFilter, HdMagFilter magFilter, + HdMinFilter minFilter, HdMagFilter magFilter, + uint32_t maxAnisotropy, HdBorderColor borderColor, bool enableCompare, HdCompareFunction compareFunction) : wrapS(wrapS) @@ -117,6 +118,7 @@ HdSamplerParameters::HdSamplerParameters( , wrapR(wrapR) , minFilter(minFilter) , magFilter(magFilter) + , maxAnisotropy(maxAnisotropy) , borderColor(borderColor) , enableCompare(enableCompare) , compareFunction(compareFunction) @@ -131,6 +133,7 @@ HdSamplerParameters::operator==(const HdSamplerParameters &other) const (wrapR == other.wrapR) && (minFilter == other.minFilter) && (magFilter == other.magFilter) && + (maxAnisotropy == other.maxAnisotropy) && (borderColor == other.borderColor) && (enableCompare == other.enableCompare) && (compareFunction == other.compareFunction); diff --git a/pxr/imaging/hd/types.h b/pxr/imaging/hd/types.h index 7972ad90d2..9f08718132 100644 --- a/pxr/imaging/hd/types.h +++ b/pxr/imaging/hd/types.h @@ -117,13 +117,15 @@ class HdSamplerParameters { HdBorderColor borderColor; bool enableCompare; HdCompareFunction compareFunction; + uint32_t maxAnisotropy; HD_API HdSamplerParameters(); HD_API HdSamplerParameters(HdWrap wrapS, HdWrap wrapT, HdWrap wrapR, - HdMinFilter minFilter, HdMagFilter magFilter, + HdMinFilter minFilter, HdMagFilter magFilter, + uint32_t maxAnisotropy=16, HdBorderColor borderColor=HdBorderColorTransparentBlack, bool enableCompare=false, HdCompareFunction compareFunction=HdCmpFuncNever); diff --git a/pxr/imaging/hdSt/material.cpp b/pxr/imaging/hdSt/material.cpp index 5c66f893d1..361f92066e 100644 --- a/pxr/imaging/hdSt/material.cpp +++ b/pxr/imaging/hdSt/material.cpp @@ -104,6 +104,7 @@ _GetTextureHandleHash( samplerParams.wrapR, samplerParams.minFilter, samplerParams.magFilter, + samplerParams.maxAnisotropy, samplerParams.borderColor, samplerParams.enableCompare, samplerParams.compareFunction); diff --git a/pxr/imaging/hdSt/renderPassShader.cpp b/pxr/imaging/hdSt/renderPassShader.cpp index d7687179a8..1f3cf4971f 100644 --- a/pxr/imaging/hdSt/renderPassShader.cpp +++ b/pxr/imaging/hdSt/renderPassShader.cpp @@ -297,7 +297,7 @@ HdStRenderPassShader::UpdateAovInputTextures( for (const auto &namedTextureIdentifier : namedTextureIdentifiers) { static const HdSamplerParameters samplerParameters( HdWrapClamp, HdWrapClamp, HdWrapClamp, - HdMinFilterNearest, HdMagFilterNearest); + HdMinFilterNearest, HdMagFilterNearest, /*maxAnisotropy*/1); // Allocate texture handle for given identifier. HdStTextureHandleSharedPtr textureHandle = diff --git a/pxr/imaging/hdSt/samplerObject.cpp b/pxr/imaging/hdSt/samplerObject.cpp index 9aa8b6b0a6..c1335683ec 100644 --- a/pxr/imaging/hdSt/samplerObject.cpp +++ b/pxr/imaging/hdSt/samplerObject.cpp @@ -67,6 +67,7 @@ _ToHgiSamplerDesc(HdSamplerParameters const &samplerParameters) HdStHgiConversions::GetHgiSamplerAddressMode(samplerParameters.wrapT); desc.addressModeW = HdStHgiConversions::GetHgiSamplerAddressMode(samplerParameters.wrapR); + desc.maxAnisotropy = samplerParameters.maxAnisotropy; desc.borderColor = HdStHgiConversions::GetHgiBorderColor(samplerParameters.borderColor); desc.enableCompare = samplerParameters.enableCompare; @@ -198,6 +199,7 @@ HdSamplerParameters PTEX_SAMPLER_PARAMETERS( HdWrapClamp, HdMinFilterLinear, HdMagFilterLinear, + /*maxAnisotropy*/16, HdBorderColorTransparentBlack, /*enableCompare*/false, HdCmpFuncNever); @@ -209,6 +211,7 @@ HdSamplerParameters LAYOUT_SAMPLER_PARAMETERS( HdWrapRepeat, HdMinFilterNearest, HdMagFilterNearest, + /*maxAnisotropy*/1, HdBorderColorTransparentBlack, /*enableCompare*/false, HdCmpFuncNever); @@ -255,6 +258,7 @@ HdSamplerParameters UDIM_SAMPLER_PARAMETERS( HdWrapClamp, HdMinFilterLinearMipmapLinear, HdMagFilterLinear, + /*maxAnisotropy*/16, HdBorderColorTransparentBlack, /*enableCompare*/false, HdCmpFuncNever); diff --git a/pxr/imaging/hdSt/simpleLightingShader.cpp b/pxr/imaging/hdSt/simpleLightingShader.cpp index 58693c43b1..49e7731006 100644 --- a/pxr/imaging/hdSt/simpleLightingShader.cpp +++ b/pxr/imaging/hdSt/simpleLightingShader.cpp @@ -321,7 +321,7 @@ _MakeNamedTextureHandle( const HdSamplerParameters samplerParameters( wrapModeS, wrapModeT, wrapModeR, - minFilter, HdMagFilterLinear); + minFilter, HdMagFilterLinear, /*maxAnisotropy*/1); HdStTextureHandleSharedPtr const textureHandle = resourceRegistry->AllocateTextureHandle( @@ -451,7 +451,7 @@ HdStSimpleLightingShader::AllocateTextureHandles(HdRenderIndex const &renderInde static const HdSamplerParameters envSamplerParameters( HdWrapRepeat, HdWrapClamp, HdWrapClamp, - HdMinFilterLinearMipmapLinear, HdMagFilterLinear); + HdMinFilterLinearMipmapLinear, HdMagFilterLinear, /*maxAnisotropy*/1); _domeLightEnvironmentTextureHandle = resourceRegistry->AllocateTextureHandle( @@ -539,7 +539,7 @@ HdStSimpleLightingShader::AllocateTextureHandles(HdRenderIndex const &renderInde // for just-allocated texture objects. HdSamplerParameters const shadowSamplerParameters{ HdWrapClamp, HdWrapClamp, HdWrapClamp, - HdMinFilterLinear, HdMagFilterLinear, + HdMinFilterLinear, HdMagFilterLinear, /*maxAnisotropy*/1, HdBorderColorOpaqueWhite, /*enableCompare*/true, HdCmpFuncLEqual}; @@ -648,4 +648,3 @@ HdStSimpleLightingShader::GetNamedTextureHandles() const } PXR_NAMESPACE_CLOSE_SCOPE - diff --git a/pxr/imaging/hgi/sampler.cpp b/pxr/imaging/hgi/sampler.cpp index 993383929e..7c54f37463 100644 --- a/pxr/imaging/hgi/sampler.cpp +++ b/pxr/imaging/hgi/sampler.cpp @@ -8,6 +8,10 @@ PXR_NAMESPACE_OPEN_SCOPE +TF_DEFINE_ENV_SETTING(HGI_MAX_ANISOTROPY, 16, + "Maximum anisotropic filtering ratio for all samplers"); + + HgiSampler::HgiSampler(HgiSamplerDesc const& desc) : _descriptor(desc) { @@ -30,7 +34,8 @@ bool operator==(const HgiSamplerDesc& lhs, lhs.mipFilter == rhs.mipFilter && lhs.addressModeU == rhs.addressModeU && lhs.addressModeV == rhs.addressModeV && - lhs.addressModeW == rhs.addressModeW + lhs.addressModeW == rhs.addressModeW && + lhs.maxAnisotropy == rhs.maxAnisotropy ; } diff --git a/pxr/imaging/hgi/sampler.h b/pxr/imaging/hgi/sampler.h index a6dfb5537d..053caaa7af 100644 --- a/pxr/imaging/hgi/sampler.h +++ b/pxr/imaging/hgi/sampler.h @@ -8,6 +8,9 @@ #define PXR_IMAGING_HGI_SAMPLER_H #include "pxr/pxr.h" + +#include "pxr/base/tf/envSetting.h" + #include "pxr/imaging/hgi/api.h" #include "pxr/imaging/hgi/enums.h" #include "pxr/imaging/hgi/handle.h" @@ -18,6 +21,12 @@ PXR_NAMESPACE_OPEN_SCOPE +/// Sets the maximum anisotropic filtering ratio for all samplers. +/// By default this is 16x. The actual value used depends on the +/// device limits. A value of 1 effectively disables anisotropic sampling. +/// +HGI_API +extern TfEnvSetting HGI_MAX_ANISOTROPY; /// \struct HgiSamplerDesc /// @@ -42,6 +51,11 @@ PXR_NAMESPACE_OPEN_SCOPE /// Enables sampler comparison against a reference value during lookups. ///
  • compareFunction: /// The comparison function to apply if sampler compare is enabled.
  • +///
  • maxAnisotropy: +/// Maximum anisotropic filtering ratio. The default value of 16 corresponds +/// to the previously internal default value. The actual value used is subject +/// to the device maximum supported anisotropy and the HGI_MAX_ANISOTROPY +/// setting. A value of 1 effectively disables anisotropic sampling.
  • /// /// struct HgiSamplerDesc @@ -56,6 +70,7 @@ struct HgiSamplerDesc , borderColor(HgiBorderColorTransparentBlack) , enableCompare(false) , compareFunction(HgiCompareFunctionNever) + , maxAnisotropy(16) {} std::string debugName; @@ -68,6 +83,7 @@ struct HgiSamplerDesc HgiBorderColor borderColor; bool enableCompare; HgiCompareFunction compareFunction; + uint32_t maxAnisotropy; }; HGI_API diff --git a/pxr/imaging/hgiGL/sampler.cpp b/pxr/imaging/hgiGL/sampler.cpp index 555cf800bc..f3dc307382 100644 --- a/pxr/imaging/hgiGL/sampler.cpp +++ b/pxr/imaging/hgiGL/sampler.cpp @@ -68,11 +68,13 @@ HgiGLSampler::HgiGLSampler(HgiSamplerDesc const& desc) // when the filters are "nearest" to ensure those filters are used. if (minFilter != GL_NEAREST && minFilter != GL_NEAREST_MIPMAP_NEAREST && magFilter != GL_NEAREST) { - static const float maxAnisotropy = 16.0; + float aniso = 2.0f; + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso); glSamplerParameterf( _samplerId, GL_TEXTURE_MAX_ANISOTROPY_EXT, - maxAnisotropy); + std::min({aniso, static_cast(desc.maxAnisotropy), + static_cast(TfGetEnvSetting(HGI_MAX_ANISOTROPY))})); } glSamplerParameteri( diff --git a/pxr/imaging/hgiGL/texture.cpp b/pxr/imaging/hgiGL/texture.cpp index 25db1d25d7..90273e5eea 100644 --- a/pxr/imaging/hgiGL/texture.cpp +++ b/pxr/imaging/hgiGL/texture.cpp @@ -6,6 +6,7 @@ // #include "pxr/imaging/garch/glApi.h" +#include "pxr/imaging/hgi/sampler.h" #include "pxr/imaging/hgiGL/diagnostic.h" #include "pxr/imaging/hgiGL/conversions.h" #include "pxr/imaging/hgiGL/texture.h" @@ -14,6 +15,7 @@ PXR_NAMESPACE_OPEN_SCOPE + static void _GlTextureStorageND( @@ -254,7 +256,8 @@ HgiGLTexture::HgiGLTexture(HgiTextureDesc const & desc) glTextureParameterf( _textureId, GL_TEXTURE_MAX_ANISOTROPY_EXT, - aniso); + std::min(aniso, + static_cast(TfGetEnvSetting(HGI_MAX_ANISOTROPY)))); } const uint16_t mips = desc.mipLevels; diff --git a/pxr/imaging/hgiMetal/sampler.mm b/pxr/imaging/hgiMetal/sampler.mm index cf5ff71884..c5e4e20a50 100644 --- a/pxr/imaging/hgiMetal/sampler.mm +++ b/pxr/imaging/hgiMetal/sampler.mm @@ -38,8 +38,9 @@ if ((desc.minFilter != HgiSamplerFilterNearest || desc.mipFilter == HgiMipFilterLinear) && desc.magFilter != HgiSamplerFilterNearest) { - static const int maxAnisotropy = 16; - smpDesc.maxAnisotropy = maxAnisotropy; + static const uint32_t maxAnisotropy = 16; + smpDesc.maxAnisotropy = std::min({maxAnisotropy, desc.maxAnisotropy, + static_cast(TfGetEnvSetting(HGI_MAX_ANISOTROPY))}); } HGIMETAL_DEBUG_LABEL(smpDesc, _descriptor.debugName.c_str()); diff --git a/pxr/imaging/hgiVulkan/sampler.cpp b/pxr/imaging/hgiVulkan/sampler.cpp index 2ae2ce1cb5..25990055e4 100644 --- a/pxr/imaging/hgiVulkan/sampler.cpp +++ b/pxr/imaging/hgiVulkan/sampler.cpp @@ -52,7 +52,9 @@ HgiVulkanSampler::HgiVulkanSampler( HgiVulkanCapabilities const& caps = device->GetDeviceCapabilities(); sampler.anisotropyEnable = caps.vkDeviceFeatures.samplerAnisotropy; sampler.maxAnisotropy = sampler.anisotropyEnable ? - caps.vkDeviceProperties.limits.maxSamplerAnisotropy : 1.0f; + std::min({caps.vkDeviceProperties.limits.maxSamplerAnisotropy, + static_cast(desc.maxAnisotropy), + static_cast(TfGetEnvSetting(HGI_MAX_ANISOTROPY))}) : 1.0f; } TF_VERIFY(