Skip to content

Commit

Permalink
Replaced AnisotropicFilteringSupported member of SamplerProperties st…
Browse files Browse the repository at this point in the history
…ruct with MaxAnisotropy (API254004)
  • Loading branch information
TheMostDiligent committed Jan 12, 2024
1 parent bf3d2c5 commit e94b369
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngine/interface/APIInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,7 +30,7 @@
/// \file
/// Diligent API information

#define DILIGENT_API_VERSION 254003
#define DILIGENT_API_VERSION 254004

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

Expand Down
11 changes: 6 additions & 5 deletions Graphics/GraphicsEngine/interface/GraphicsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2081,8 +2081,9 @@ struct SamplerProperties
/// Indicates if device supports border texture addressing mode
Bool BorderSamplingModeSupported DEFAULT_INITIALIZER(False);

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

/// Indicates if device supports MIP load bias
Bool LODBiasSupported DEFAULT_INITIALIZER(False);
Expand All @@ -2096,9 +2097,9 @@ struct SamplerProperties
/// - False otherwise.
constexpr bool operator==(const SamplerProperties& RHS) const
{
return BorderSamplingModeSupported == RHS.BorderSamplingModeSupported &&
AnisotropicFilteringSupported == RHS.AnisotropicFilteringSupported &&
LODBiasSupported == RHS.LODBiasSupported;
return BorderSamplingModeSupported == RHS.BorderSamplingModeSupported &&
MaxAnisotropy == RHS.MaxAnisotropy &&
LODBiasSupported == RHS.LODBiasSupported;
}
#endif

Expand Down
14 changes: 11 additions & 3 deletions Graphics/GraphicsEngine/src/SamplerBase.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,14 +41,16 @@ namespace Diligent

void ValidateSamplerDesc(const SamplerDesc& Desc, const IRenderDevice* pDevice)
{
const auto& DeviceInfo = pDevice->GetDeviceInfo();
const auto& AdapterInfo = pDevice->GetAdapterInfo();
if (Desc.Flags & (SAMPLER_FLAG_SUBSAMPLED | SAMPLER_FLAG_SUBSAMPLED_COARSE_RECONSTRUCTION))
{
VERIFY_SAMPLER(pDevice->GetAdapterInfo().ShadingRate.CapFlags & SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET,
VERIFY_SAMPLER(AdapterInfo.ShadingRate.CapFlags & SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET,
"Subsampled sampler requires SHADING_RATE_CAP_FLAG_SUBSAMPLED_RENDER_TARGET capability.");
}
if (Desc.UnnormalizedCoords)
{
VERIFY_SAMPLER(pDevice->GetDeviceInfo().IsVulkanDevice() || pDevice->GetDeviceInfo().IsMetalDevice(),
VERIFY_SAMPLER(DeviceInfo.IsVulkanDevice() || DeviceInfo.IsMetalDevice(),
"Unnormalized coordinates are only supported in Vulkan and Metal.");

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

} // namespace Diligent
6 changes: 3 additions & 3 deletions Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ GraphicsAdapterInfo EngineFactoryD3D11Impl::GetGraphicsAdapterInfo(void*
// Sampler properties
{
auto& SamProps{AdapterInfo.Sampler};
SamProps.BorderSamplingModeSupported = True;
SamProps.AnisotropicFilteringSupported = True;
SamProps.LODBiasSupported = True;
SamProps.BorderSamplingModeSupported = True;
SamProps.MaxAnisotropy = D3D11_DEFAULT_MAX_ANISOTROPY;
SamProps.LODBiasSupported = True;
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
}

Expand Down
6 changes: 3 additions & 3 deletions Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,9 +1032,9 @@ GraphicsAdapterInfo EngineFactoryD3D12Impl::GetGraphicsAdapterInfo(void*
{

auto& SamProps{AdapterInfo.Sampler};
SamProps.BorderSamplingModeSupported = True;
SamProps.AnisotropicFilteringSupported = True;
SamProps.LODBiasSupported = True;
SamProps.BorderSamplingModeSupported = True;
SamProps.MaxAnisotropy = D3D12_DEFAULT_MAX_ANISOTROPY;
SamProps.LODBiasSupported = True;
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
}

Expand Down
8 changes: 6 additions & 2 deletions Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -247,7 +247,11 @@
#endif

#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif

#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
#endif

#ifndef GL_TEXTURE_BORDER_COLOR
Expand Down
8 changes: 6 additions & 2 deletions Graphics/GraphicsEngineOpenGL/include/GLStubsEmscripten.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -290,7 +290,11 @@
#endif

#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif

#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
#endif

#ifndef GL_TEXTURE_BORDER_COLOR
Expand Down
11 changes: 10 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLStubsIOS.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -555,6 +555,15 @@
#endif


#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif

#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
#endif


#ifndef GL_DOUBLE
# define GL_DOUBLE 0x140A
#endif
Expand Down
25 changes: 19 additions & 6 deletions Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,16 @@ void RenderDeviceGLImpl::InitAdapterInfo()
TexProps.TextureView2DOn3DSupported = TexProps.TextureViewSupported;
ASSERT_SIZEOF(TexProps, 32, "Did you add a new member to TextureProperites? Please initialize it here.");

SamProps.BorderSamplingModeSupported = True;
SamProps.AnisotropicFilteringSupported = IsGL46OrAbove || CheckExtension("GL_ARB_texture_filter_anisotropic");
SamProps.LODBiasSupported = True;
SamProps.BorderSamplingModeSupported = True;
if (IsGL46OrAbove || CheckExtension("GL_ARB_texture_filter_anisotropic"))
{
GLint MaxAnisotropy = 0;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &MaxAnisotropy);
CHECK_GL_ERROR("glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY)");
SamProps.MaxAnisotropy = static_cast<Uint8>(MaxAnisotropy);
}

SamProps.LODBiasSupported = True;
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");

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

SamProps.BorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && (IsGLES32OrAbove || strstr(Extensions, "texture_border_clamp"));
SamProps.AnisotropicFilteringSupported = GL_TEXTURE_MAX_ANISOTROPY_EXT && strstr(Extensions, "texture_filter_anisotropic");
SamProps.LODBiasSupported = GL_TEXTURE_LOD_BIAS && IsGLES31OrAbove;
SamProps.BorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && (IsGLES32OrAbove || strstr(Extensions, "texture_border_clamp"));
if (strstr(Extensions, "texture_filter_anisotropic"))
{
GLint MaxAnisotropy = 0;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &MaxAnisotropy);
CHECK_GL_ERROR("glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY)");
SamProps.MaxAnisotropy = static_cast<Uint8>(MaxAnisotropy);
}
SamProps.LODBiasSupported = GL_TEXTURE_LOD_BIAS && IsGLES31OrAbove;
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");

m_GLCaps.FramebufferSRGB = strstr(Extensions, "sRGB_write_control");
Expand Down
10 changes: 4 additions & 6 deletions Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -101,12 +101,10 @@ SamplerGLImpl::SamplerGLImpl(IReferenceCounters* pRefCounters, class RenderDevic
LOG_WARNING_MESSAGE("Texture LOD bias sampler attribute is not supported\n");
}

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

glSamplerParameteri(m_GlSampler, GL_TEXTURE_COMPARE_MODE, bMinComparison ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE);
Expand Down
6 changes: 3 additions & 3 deletions Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ GraphicsAdapterInfo GetPhysicalDeviceGraphicsAdapterInfo(const VulkanUtilities::
// Sampler properties
{
auto& SamProps{AdapterInfo.Sampler};
SamProps.BorderSamplingModeSupported = True;
SamProps.AnisotropicFilteringSupported = vkFeatures.samplerAnisotropy;
SamProps.LODBiasSupported = True;
SamProps.BorderSamplingModeSupported = True;
SamProps.MaxAnisotropy = static_cast<Uint8>(vkDeviceLimits.maxSamplerAnisotropy);
SamProps.LODBiasSupported = True;
ASSERT_SIZEOF(SamProps, 3, "Did you add a new member to SamplerProperites? Please initialize it here.");
}

Expand Down
1 change: 1 addition & 0 deletions ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Current progress

* Replaced `AnisotropicFilteringSupported` member of `SamplerProperties` struct with `MaxAnisotropy` (API254004)
* Added `TextureSubresourceViews` device feature (API254003)
* Added device context rendering statistics (API254002)
* Added `DeviceContextStats` struct
Expand Down
10 changes: 6 additions & 4 deletions Tests/DiligentCoreAPITest/src/SamplerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -117,7 +117,9 @@ TEST(FilterTypeTest, AnisotropicFilter)
{
auto* pEnv = GPUTestingEnvironment::GetInstance();
auto* pDevice = pEnv->GetDevice();
if (!pDevice->GetAdapterInfo().Sampler.AnisotropicFilteringSupported)

const Uint32 MaxAnisotropy = pDevice->GetAdapterInfo().Sampler.MaxAnisotropy;
if (MaxAnisotropy <= 1)
GTEST_SKIP() << "Anisotropic filtering is not supported by this device";

GPUTestingEnvironment::ScopedReleaseResources AutoreleaseResources;
Expand All @@ -129,7 +131,7 @@ TEST(FilterTypeTest, AnisotropicFilter)
SamplerDesc.MagFilter = FILTER_TYPE_ANISOTROPIC;
SamplerDesc.MipFilter = FILTER_TYPE_ANISOTROPIC;

SamplerDesc.MaxAnisotropy = 4;
SamplerDesc.MaxAnisotropy = std::min(4u, MaxAnisotropy);
RefCntAutoPtr<ISampler> pSampler;
pDevice->CreateSampler(SamplerDesc, &pSampler);
ASSERT_TRUE(pSampler);
Expand All @@ -143,7 +145,7 @@ TEST(FilterTypeTest, AnisotropicFilter)
SamplerDesc.MagFilter = FILTER_TYPE_COMPARISON_ANISOTROPIC;
SamplerDesc.MipFilter = FILTER_TYPE_COMPARISON_ANISOTROPIC;

SamplerDesc.MaxAnisotropy = 4;
SamplerDesc.MaxAnisotropy = std::min(4u, MaxAnisotropy);
RefCntAutoPtr<ISampler> pSampler;
pDevice->CreateSampler(SamplerDesc, &pSampler);
ASSERT_TRUE(pSampler);
Expand Down

0 comments on commit e94b369

Please sign in to comment.