From 2abacaa03050d63b4424c5d244fd46dc6b4a1fca Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 21 Jul 2025 15:06:39 -0700 Subject: [PATCH] the ssr-history texture is not an array the descriptor used for SSR is different depending on the pass. In the color pass, it's used as the source of the SSRs buffers and is an array (refraction & reflection). In the SSR pass it's the history buffer and is just a 2D texture. --- filament/src/details/MaterialInstance.cpp | 4 ++- filament/src/ds/ColorPassDescriptorSet.cpp | 19 ----------- filament/src/ds/ColorPassDescriptorSet.h | 5 --- filament/src/ds/DescriptorSet.cpp | 33 ++++++++++++++++++- filament/src/ds/DescriptorSet.h | 3 +- filament/src/ds/SsrPassDescriptorSet.cpp | 2 +- .../include/private/filament/EngineEnums.h | 3 +- libs/filabridge/src/DescriptorSets.cpp | 2 +- 8 files changed, 41 insertions(+), 30 deletions(-) diff --git a/filament/src/details/MaterialInstance.cpp b/filament/src/details/MaterialInstance.cpp index a43ce8bc92..cd02b714fa 100644 --- a/filament/src/details/MaterialInstance.cpp +++ b/filament/src/details/MaterialInstance.cpp @@ -284,11 +284,13 @@ void FMaterialInstance::setParameterImpl(std::string_view const name, auto const& descriptorSetLayout = mMaterial->getDescriptorSetLayout(); DescriptorType const descriptorType = descriptorSetLayout.getDescriptorType(binding); TextureType const textureType = texture->getTextureType(); + SamplerType const samplerType = texture->getTarget(); FILAMENT_CHECK_PRECONDITION( - DescriptorSet::isTextureCompatibleWithDescriptor(textureType, descriptorType)) + DescriptorSet::isTextureCompatibleWithDescriptor(textureType, samplerType, descriptorType)) << "Texture format " << int(texture->getFormat()) << " of type " << to_string(textureType) + << " with sampler type " << to_string(samplerType) << " is not compatible with material \"" << getMaterial()->getName().c_str() << "\"" << " parameter \"" << name << "\"" << " of type " << to_string(descriptorType); diff --git a/filament/src/ds/ColorPassDescriptorSet.cpp b/filament/src/ds/ColorPassDescriptorSet.cpp index 8524b43adc..f570d2b9a6 100644 --- a/filament/src/ds/ColorPassDescriptorSet.cpp +++ b/filament/src/ds/ColorPassDescriptorSet.cpp @@ -345,25 +345,6 @@ void ColorPassDescriptorSet::prepareSSR(Handle ssr, s.ssrDistance = (ssrOptions.enabled && !disableSSR) ? ssrOptions.maxDistance : 0.0f; } -void ColorPassDescriptorSet::prepareHistorySSR(Handle ssr, - mat4f const& historyProjection, - mat4f const& uvFromViewMatrix, - ScreenSpaceReflectionsOptions const& ssrOptions) noexcept { - - setSampler(+PerViewBindingPoints::SSR, ssr, { - .filterMag = SamplerMagFilter::LINEAR, - .filterMin = SamplerMinFilter::LINEAR - }); - - auto& s = mUniforms.edit(); - s.ssrReprojection = historyProjection; - s.ssrUvFromViewMatrix = uvFromViewMatrix; - s.ssrThickness = ssrOptions.thickness; - s.ssrBias = ssrOptions.bias; - s.ssrDistance = ssrOptions.enabled ? ssrOptions.maxDistance : 0.0f; - s.ssrStride = ssrOptions.stride; -} - void ColorPassDescriptorSet::prepareStructure(Handle structure) noexcept { // sampler must be NEAREST setSampler(+PerViewBindingPoints::STRUCTURE, structure, {}); diff --git a/filament/src/ds/ColorPassDescriptorSet.h b/filament/src/ds/ColorPassDescriptorSet.h index 1bd9c0fb76..a4175415e9 100644 --- a/filament/src/ds/ColorPassDescriptorSet.h +++ b/filament/src/ds/ColorPassDescriptorSet.h @@ -117,11 +117,6 @@ public: float refractionLodOffset, ScreenSpaceReflectionsOptions const& ssrOptions) noexcept; - void prepareHistorySSR(TextureHandle ssr, - math::mat4f const& historyProjection, - math::mat4f const& uvFromViewMatrix, - ScreenSpaceReflectionsOptions const& ssrOptions) noexcept; - void prepareShadowMapping(backend::BufferObjectHandle shadowUniforms, bool highPrecision) noexcept; void prepareDirectionalLight(FEngine& engine, float exposure, diff --git a/filament/src/ds/DescriptorSet.cpp b/filament/src/ds/DescriptorSet.cpp index 2ed978aa8b..6448f96721 100644 --- a/filament/src/ds/DescriptorSet.cpp +++ b/filament/src/ds/DescriptorSet.cpp @@ -198,9 +198,40 @@ DescriptorSet DescriptorSet::duplicate( return set; } bool DescriptorSet::isTextureCompatibleWithDescriptor( - backend::TextureType t, backend::DescriptorType d) noexcept { + backend::TextureType t, backend::SamplerType s, backend::DescriptorType d) noexcept { using namespace backend; + switch (s) { + case SamplerType::SAMPLER_2D: + if (!is2dTypeDescriptor(d)) { + return false; + } + break; + case SamplerType::SAMPLER_2D_ARRAY: + if (!is2dArrayTypeDescriptor(d)) { + return false; + } + break; + case SamplerType::SAMPLER_CUBEMAP: + if (!isCubeTypeDescriptor(d)) { + return false; + } + break; + case SamplerType::SAMPLER_CUBEMAP_ARRAY: + if (!isCubeArrayTypeDescriptor(d)) { + return false; + } + break; + case SamplerType::SAMPLER_3D: + if (!is3dTypeDescriptor(d)) { + return false; + } + break; + case SamplerType::SAMPLER_EXTERNAL: + break; + } + + // check that the descriptor type is compatible with the texture format type switch (d) { case DescriptorType::SAMPLER_2D_FLOAT: case DescriptorType::SAMPLER_2D_ARRAY_FLOAT: diff --git a/filament/src/ds/DescriptorSet.h b/filament/src/ds/DescriptorSet.h index 881957bada..f8976f5140 100644 --- a/filament/src/ds/DescriptorSet.h +++ b/filament/src/ds/DescriptorSet.h @@ -86,7 +86,8 @@ public: } static bool isTextureCompatibleWithDescriptor( - backend::TextureType t, backend::DescriptorType d) noexcept; + backend::TextureType t, backend::SamplerType s, + backend::DescriptorType d) noexcept; private: struct Desc { diff --git a/filament/src/ds/SsrPassDescriptorSet.cpp b/filament/src/ds/SsrPassDescriptorSet.cpp index 1b7059b56c..dbb2507e6e 100644 --- a/filament/src/ds/SsrPassDescriptorSet.cpp +++ b/filament/src/ds/SsrPassDescriptorSet.cpp @@ -76,7 +76,7 @@ void SsrPassDescriptorSet::prepareHistorySSR(FEngine const& engine, Handle ssrVariantDes { DescriptorType::UNIFORM_BUFFER, ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT, +PerViewBindingPoints::FRAME_UNIFORMS }, { DescriptorType::UNIFORM_BUFFER, ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT, +PerViewBindingPoints::SHADOWS }, { DescriptorType::SAMPLER_2D_FLOAT, ShaderStageFlags::FRAGMENT, +PerViewBindingPoints::STRUCTURE, DescriptorFlags::UNFILTERABLE }, - { DescriptorType::SAMPLER_2D_ARRAY_FLOAT, ShaderStageFlags::FRAGMENT, +PerViewBindingPoints::SSR }, + { DescriptorType::SAMPLER_2D_FLOAT, ShaderStageFlags::FRAGMENT, +PerViewBindingPoints::SSR_HISTORY }, }; // Used for generating the color pass (i.e. the main pass). This is in fact a template that gets