Skip to content

Commit e94b369

Browse files
Replaced AnisotropicFilteringSupported member of SamplerProperties struct with MaxAnisotropy (API254004)
1 parent bf3d2c5 commit e94b369

13 files changed

Lines changed: 80 additions & 40 deletions

File tree

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 254003
33+
#define DILIGENT_API_VERSION 254004
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsEngine/interface/GraphicsTypes.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,8 +2081,9 @@ struct SamplerProperties
20812081
/// Indicates if device supports border texture addressing mode
20822082
Bool BorderSamplingModeSupported DEFAULT_INITIALIZER(False);
20832083

2084-
/// Indicates if device supports anisotropic filtering
2085-
Bool AnisotropicFilteringSupported DEFAULT_INITIALIZER(False);
2084+
/// Maximum anisotropy level supported by the device.
2085+
/// If anisotropic filtering is not supported, this value is 1.
2086+
Uint8 MaxAnisotropy DEFAULT_INITIALIZER(1);
20862087

20872088
/// Indicates if device supports MIP load bias
20882089
Bool LODBiasSupported DEFAULT_INITIALIZER(False);
@@ -2096,9 +2097,9 @@ struct SamplerProperties
20962097
/// - False otherwise.
20972098
constexpr bool operator==(const SamplerProperties& RHS) const
20982099
{
2099-
return BorderSamplingModeSupported == RHS.BorderSamplingModeSupported &&
2100-
AnisotropicFilteringSupported == RHS.AnisotropicFilteringSupported &&
2101-
LODBiasSupported == RHS.LODBiasSupported;
2100+
return BorderSamplingModeSupported == RHS.BorderSamplingModeSupported &&
2101+
MaxAnisotropy == RHS.MaxAnisotropy &&
2102+
LODBiasSupported == RHS.LODBiasSupported;
21022103
}
21032104
#endif
21042105

Graphics/GraphicsEngine/src/SamplerBase.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,14 +41,16 @@ namespace Diligent
4141

4242
void ValidateSamplerDesc(const SamplerDesc& Desc, const IRenderDevice* pDevice)
4343
{
44+
const auto& DeviceInfo = pDevice->GetDeviceInfo();
45+
const auto& AdapterInfo = pDevice->GetAdapterInfo();
4446
if (Desc.Flags & (SAMPLER_FLAG_SUBSAMPLED | SAMPLER_FLAG_SUBSAMPLED_COARSE_RECONSTRUCTION))
4547
{
46-
VERIFY_SAMPLER(pDevice->GetAdapterInfo().ShadingRate.CapFlags & SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET,
48+
VERIFY_SAMPLER(AdapterInfo.ShadingRate.CapFlags & SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET,
4749
"Subsampled sampler requires SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET capability.");
4850
}
4951
if (Desc.UnnormalizedCoords)
5052
{
51-
VERIFY_SAMPLER(pDevice->GetDeviceInfo().IsVulkanDevice() || pDevice->GetDeviceInfo().IsMetalDevice(),
53+
VERIFY_SAMPLER(DeviceInfo.IsVulkanDevice() || DeviceInfo.IsMetalDevice(),
5254
"Unnormalized coordinates are only supported in Vulkan and Metal.");
5355

5456
VERIFY_SAMPLER(Desc.MinFilter == Desc.MagFilter, "When UnnormalizedCoords is true, MinFilter and MagFilter must be equal.");
@@ -58,6 +60,12 @@ void ValidateSamplerDesc(const SamplerDesc& Desc, const IRenderDevice* pDevice)
5860
VERIFY_SAMPLER(!IsComparisonFilter(Desc.MinFilter), "When UnnormalizedCoords is true, MinFilter and MagFilter must not be comparison.");
5961
VERIFY_SAMPLER(!IsAnisotropicFilter(Desc.MinFilter), "When UnnormalizedCoords is true, MinFilter and MagFilter must not be anisotropic.");
6062
}
63+
if (IsAnisotropicFilter(Desc.MinFilter))
64+
{
65+
VERIFY_SAMPLER(AdapterInfo.Sampler.MaxAnisotropy >= Desc.MaxAnisotropy,
66+
"MaxAnisotropy (", Uint32{Desc.MaxAnisotropy}, ") exceeds the maximum supported anisotropy (", Uint32{AdapterInfo.Sampler.MaxAnisotropy},
67+
"). Check the value of AdapterInfo.Sampler.MaxAnisotropy to make sure it is correct.");
68+
}
6169
}
6270

6371
} // namespace Diligent

Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ GraphicsAdapterInfo EngineFactoryD3D11Impl::GetGraphicsAdapterInfo(void*
477477
// Sampler properties
478478
{
479479
auto& SamProps{AdapterInfo.Sampler};
480-
SamProps.BorderSamplingModeSupported = True;
481-
SamProps.AnisotropicFilteringSupported = True;
482-
SamProps.LODBiasSupported = True;
480+
SamProps.BorderSamplingModeSupported = True;
481+
SamProps.MaxAnisotropy = D3D11_DEFAULT_MAX_ANISOTROPY;
482+
SamProps.LODBiasSupported = True;
483483
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
484484
}
485485

Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,9 +1032,9 @@ GraphicsAdapterInfo EngineFactoryD3D12Impl::GetGraphicsAdapterInfo(void*
10321032
{
10331033

10341034
auto& SamProps{AdapterInfo.Sampler};
1035-
SamProps.BorderSamplingModeSupported = True;
1036-
SamProps.AnisotropicFilteringSupported = True;
1037-
SamProps.LODBiasSupported = True;
1035+
SamProps.BorderSamplingModeSupported = True;
1036+
SamProps.MaxAnisotropy = D3D12_DEFAULT_MAX_ANISOTROPY;
1037+
SamProps.LODBiasSupported = True;
10381038
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
10391039
}
10401040

Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -247,7 +247,11 @@
247247
#endif
248248

249249
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
250-
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0
250+
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
251+
#endif
252+
253+
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
254+
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
251255
#endif
252256

253257
#ifndef GL_TEXTURE_BORDER_COLOR

Graphics/GraphicsEngineOpenGL/include/GLStubsEmscripten.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -290,7 +290,11 @@
290290
#endif
291291

292292
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
293-
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0
293+
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
294+
#endif
295+
296+
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
297+
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
294298
#endif
295299

296300
#ifndef GL_TEXTURE_BORDER_COLOR

Graphics/GraphicsEngineOpenGL/include/GLStubsIOS.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -555,6 +555,15 @@
555555
#endif
556556

557557

558+
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
559+
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
560+
#endif
561+
562+
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
563+
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
564+
#endif
565+
566+
558567
#ifndef GL_DOUBLE
559568
# define GL_DOUBLE 0x140A
560569
#endif

Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,16 @@ void RenderDeviceGLImpl::InitAdapterInfo()
854854
TexProps.TextureView2DOn3DSupported = TexProps.TextureViewSupported;
855855
ASSERT_SIZEOF(TexProps, 32, "Did you add a new member to TextureProperites? Please initialize it here.");
856856

857-
SamProps.BorderSamplingModeSupported = True;
858-
SamProps.AnisotropicFilteringSupported = IsGL46OrAbove || CheckExtension("GL_ARB_texture_filter_anisotropic");
859-
SamProps.LODBiasSupported = True;
857+
SamProps.BorderSamplingModeSupported = True;
858+
if (IsGL46OrAbove || CheckExtension("GL_ARB_texture_filter_anisotropic"))
859+
{
860+
GLint MaxAnisotropy = 0;
861+
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &MaxAnisotropy);
862+
CHECK_GL_ERROR("glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY)");
863+
SamProps.MaxAnisotropy = static_cast<Uint8>(MaxAnisotropy);
864+
}
865+
866+
SamProps.LODBiasSupported = True;
860867
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
861868

862869
m_GLCaps.FramebufferSRGB = IsGL40OrAbove || CheckExtension("GL_ARB_framebuffer_sRGB");
@@ -925,9 +932,15 @@ void RenderDeviceGLImpl::InitAdapterInfo()
925932
TexProps.TextureView2DOn3DSupported = TexProps.TextureViewSupported;
926933
ASSERT_SIZEOF(TexProps, 32, "Did you add a new member to TextureProperites? Please initialize it here.");
927934

928-
SamProps.BorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && (IsGLES32OrAbove || strstr(Extensions, "texture_border_clamp"));
929-
SamProps.AnisotropicFilteringSupported = GL_TEXTURE_MAX_ANISOTROPY_EXT && strstr(Extensions, "texture_filter_anisotropic");
930-
SamProps.LODBiasSupported = GL_TEXTURE_LOD_BIAS && IsGLES31OrAbove;
935+
SamProps.BorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && (IsGLES32OrAbove || strstr(Extensions, "texture_border_clamp"));
936+
if (strstr(Extensions, "texture_filter_anisotropic"))
937+
{
938+
GLint MaxAnisotropy = 0;
939+
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &MaxAnisotropy);
940+
CHECK_GL_ERROR("glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY)");
941+
SamProps.MaxAnisotropy = static_cast<Uint8>(MaxAnisotropy);
942+
}
943+
SamProps.LODBiasSupported = GL_TEXTURE_LOD_BIAS && IsGLES31OrAbove;
931944
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
932945

933946
m_GLCaps.FramebufferSRGB = strstr(Extensions, "sRGB_write_control");

Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -101,12 +101,10 @@ SamplerGLImpl::SamplerGLImpl(IReferenceCounters* pRefCounters, class RenderDevic
101101
LOG_WARNING_MESSAGE("Texture LOD bias sampler attribute is not supported\n");
102102
}
103103

104-
if (SamPrpos.AnisotropicFilteringSupported) // Can be unsupported
105-
glSamplerParameterf(m_GlSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, bMipAnisotropic ? static_cast<float>(SamplerDesc.MaxAnisotropy) : 1.f);
106-
else
104+
if (bMinAnisotropic && SamPrpos.MaxAnisotropy > 1)
107105
{
108-
if (bMipAnisotropic && SamplerDesc.MaxAnisotropy != 1)
109-
LOG_WARNING_MESSAGE("Max anisotropy sampler attribute is not supported\n");
106+
float MaxAnisotropy = static_cast<float>(std::min(SamplerDesc.MaxAnisotropy, Uint32{SamPrpos.MaxAnisotropy}));
107+
glSamplerParameterf(m_GlSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, MaxAnisotropy);
110108
}
111109

112110
glSamplerParameteri(m_GlSampler, GL_TEXTURE_COMPARE_MODE, bMinComparison ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE);

0 commit comments

Comments
 (0)