Fix #106312: Workbench: Texture interpolation is shared across material

This was caused by the Material Sub pass being
shared for all materials using a same texture.
This patch simply adds the sampler state inside the
Map key. This will create one unique subpass for each
texture and for each sampler state.

Pull Request: https://projects.blender.org/blender/blender/pulls/141978
This commit is contained in:
Clément Foucault
2025-07-15 22:47:17 +02:00
parent 2cf9cba182
commit 4ebaee0aa1
3 changed files with 27 additions and 2 deletions

View File

@@ -95,7 +95,7 @@ PassMain::Sub &MeshPass::get_subpass(eGeometryType geometry_type,
};
return *texture_subpass_map_.lookup_or_add_cb(
TextureSubPassKey(*texture->gpu.texture, geometry_type), add_cb);
{*texture->gpu.texture, texture->sampler_state, geometry_type}, add_cb);
}
return get_subpass(geometry_type, eShaderType::MATERIAL);

View File

@@ -278,7 +278,22 @@ struct SceneResources {
class MeshPass : public PassMain {
private:
using TextureSubPassKey = std::pair<GPUTexture *, eGeometryType>;
struct TextureSubPassKey {
GPUTexture *texture;
GPUSamplerState sampler_state;
eGeometryType geom_type;
uint64_t hash() const
{
return get_default_hash(texture, sampler_state.as_uint(), geom_type);
}
bool operator==(TextureSubPassKey const &rhs) const
{
return this->texture == rhs.texture && this->sampler_state == rhs.sampler_state &&
this->geom_type == rhs.geom_type;
}
};
Map<TextureSubPassKey, PassMain::Sub *> texture_subpass_map_;

View File

@@ -623,6 +623,16 @@ struct GPUSamplerState {
return serialized_parameters;
}
uint32_t as_uint() const
{
uint32_t value = filtering;
value = (value << 4) | extend_x;
value = (value << 4) | extend_yz;
value = (value << 8) | custom_type;
value = (value << 8) | type;
return value;
}
bool operator==(GPUSamplerState const &rhs) const
{
return this->filtering == rhs.filtering && this->extend_x == rhs.extend_x &&