From d9c44442c8e7e35f7778098656c7c51a9cd8a32b Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Thu, 25 May 2023 17:24:02 +0200 Subject: [PATCH 1/3] Use Material::blend_flag for ShaderKey --- .../blender/draw/engines/eevee_next/eevee_material.cc | 2 +- .../blender/draw/engines/eevee_next/eevee_material.hh | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/blender/draw/engines/eevee_next/eevee_material.cc b/source/blender/draw/engines/eevee_next/eevee_material.cc index 34c5134f319..85fb57ace93 100644 --- a/source/blender/draw/engines/eevee_next/eevee_material.cc +++ b/source/blender/draw/engines/eevee_next/eevee_material.cc @@ -203,7 +203,7 @@ MaterialPass MaterialModule::material_pass_get(Object *ob, matpass.sub_pass = nullptr; } else { - ShaderKey shader_key(matpass.gpumat, geometry_type, pipeline_type); + ShaderKey shader_key(matpass.gpumat, geometry_type, pipeline_type, blender_mat->blend_flag); PassMain::Sub *shader_sub = shader_map_.lookup_or_add_cb(shader_key, [&]() { /* First time encountering this shader. Create a sub that will contain materials using it. */ diff --git a/source/blender/draw/engines/eevee_next/eevee_material.hh b/source/blender/draw/engines/eevee_next/eevee_material.hh index 0546c2e06bb..f3b2e6a5d61 100644 --- a/source/blender/draw/engines/eevee_next/eevee_material.hh +++ b/source/blender/draw/engines/eevee_next/eevee_material.hh @@ -108,7 +108,7 @@ static inline eMaterialGeometry to_material_geometry(const Object *ob) /** Unique key to identify each material in the hash-map. */ struct MaterialKey { - Material *mat; + ::Material *mat; uint64_t options; MaterialKey(::Material *mat_, eMaterialGeometry geometry, eMaterialPipeline surface_pipeline) @@ -145,10 +145,14 @@ struct ShaderKey { GPUShader *shader; uint64_t options; - ShaderKey(GPUMaterial *gpumat, eMaterialGeometry geometry, eMaterialPipeline pipeline) + ShaderKey(GPUMaterial *gpumat, + eMaterialGeometry geometry, + eMaterialPipeline pipeline, + char blend_flags) { shader = GPU_material_get_shader(gpumat); - options = shader_uuid_from_material_type(pipeline, geometry); + options = blend_flags; + options = (options << 6u) | shader_uuid_from_material_type(pipeline, geometry); options = (options << 16u) | shader_closure_bits_from_flag(gpumat); } -- 2.30.2 From ce507daa10ed6842fb44821c5c628c3705040c50 Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Thu, 25 May 2023 17:24:46 +0200 Subject: [PATCH 2/3] MaterialKey and ShaderKey improvements --- .../draw/engines/eevee_next/eevee_material.hh | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/source/blender/draw/engines/eevee_next/eevee_material.hh b/source/blender/draw/engines/eevee_next/eevee_material.hh index f3b2e6a5d61..cd6de227e7b 100644 --- a/source/blender/draw/engines/eevee_next/eevee_material.hh +++ b/source/blender/draw/engines/eevee_next/eevee_material.hh @@ -108,29 +108,28 @@ static inline eMaterialGeometry to_material_geometry(const Object *ob) /** Unique key to identify each material in the hash-map. */ struct MaterialKey { - ::Material *mat; - uint64_t options; + uint64_t hash_; - MaterialKey(::Material *mat_, eMaterialGeometry geometry, eMaterialPipeline surface_pipeline) - : mat(mat_) + MaterialKey(::Material *mat, eMaterialGeometry geometry, eMaterialPipeline surface_pipeline) { - options = shader_uuid_from_material_type(surface_pipeline, geometry); + uint64_t uuid = shader_uuid_from_material_type(surface_pipeline, geometry); + BLI_assert(uuid < sizeof(*mat)); + hash_ = uint64_t(mat) + uuid; } uint64_t hash() const { - BLI_assert(options < sizeof(*mat)); - return uint64_t(mat) + options; + return hash_; } bool operator<(const MaterialKey &k) const { - return (mat < k.mat) || (options < k.options); + return hash_ < k.hash_; } bool operator==(const MaterialKey &k) const { - return (mat == k.mat) && (options == k.options); + return hash_ == k.hash_; } }; @@ -142,33 +141,32 @@ struct MaterialKey { * \{ */ struct ShaderKey { - GPUShader *shader; - uint64_t options; + uint64_t hash_; ShaderKey(GPUMaterial *gpumat, eMaterialGeometry geometry, eMaterialPipeline pipeline, char blend_flags) { - shader = GPU_material_get_shader(gpumat); - options = blend_flags; - options = (options << 6u) | shader_uuid_from_material_type(pipeline, geometry); - options = (options << 16u) | shader_closure_bits_from_flag(gpumat); + hash_ = uint64_t(GPU_material_get_shader(gpumat)) / 2; + hash_ = (hash_ << 16u) | shader_closure_bits_from_flag(gpumat); + hash_ = (hash_ << 6u) | shader_uuid_from_material_type(pipeline, geometry); + hash_ = (hash_ << 4u) | blend_flags; } uint64_t hash() const { - return uint64_t(shader) + options; + return hash_; } bool operator<(const ShaderKey &k) const { - return (shader == k.shader) ? (options < k.options) : (shader < k.shader); + return hash_ < k.hash_; } bool operator==(const ShaderKey &k) const { - return (shader == k.shader) && (options == k.options); + return hash_ == k.hash_; } }; -- 2.30.2 From 075bccc215e1eb50818a794a26dcd32e345c77e8 Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Thu, 25 May 2023 17:44:28 +0200 Subject: [PATCH 3/3] Revert "MaterialKey and ShaderKey improvements" This reverts commit ce507daa10ed6842fb44821c5c628c3705040c50. --- .../draw/engines/eevee_next/eevee_material.hh | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/source/blender/draw/engines/eevee_next/eevee_material.hh b/source/blender/draw/engines/eevee_next/eevee_material.hh index cd6de227e7b..f3b2e6a5d61 100644 --- a/source/blender/draw/engines/eevee_next/eevee_material.hh +++ b/source/blender/draw/engines/eevee_next/eevee_material.hh @@ -108,28 +108,29 @@ static inline eMaterialGeometry to_material_geometry(const Object *ob) /** Unique key to identify each material in the hash-map. */ struct MaterialKey { - uint64_t hash_; + ::Material *mat; + uint64_t options; - MaterialKey(::Material *mat, eMaterialGeometry geometry, eMaterialPipeline surface_pipeline) + MaterialKey(::Material *mat_, eMaterialGeometry geometry, eMaterialPipeline surface_pipeline) + : mat(mat_) { - uint64_t uuid = shader_uuid_from_material_type(surface_pipeline, geometry); - BLI_assert(uuid < sizeof(*mat)); - hash_ = uint64_t(mat) + uuid; + options = shader_uuid_from_material_type(surface_pipeline, geometry); } uint64_t hash() const { - return hash_; + BLI_assert(options < sizeof(*mat)); + return uint64_t(mat) + options; } bool operator<(const MaterialKey &k) const { - return hash_ < k.hash_; + return (mat < k.mat) || (options < k.options); } bool operator==(const MaterialKey &k) const { - return hash_ == k.hash_; + return (mat == k.mat) && (options == k.options); } }; @@ -141,32 +142,33 @@ struct MaterialKey { * \{ */ struct ShaderKey { - uint64_t hash_; + GPUShader *shader; + uint64_t options; ShaderKey(GPUMaterial *gpumat, eMaterialGeometry geometry, eMaterialPipeline pipeline, char blend_flags) { - hash_ = uint64_t(GPU_material_get_shader(gpumat)) / 2; - hash_ = (hash_ << 16u) | shader_closure_bits_from_flag(gpumat); - hash_ = (hash_ << 6u) | shader_uuid_from_material_type(pipeline, geometry); - hash_ = (hash_ << 4u) | blend_flags; + shader = GPU_material_get_shader(gpumat); + options = blend_flags; + options = (options << 6u) | shader_uuid_from_material_type(pipeline, geometry); + options = (options << 16u) | shader_closure_bits_from_flag(gpumat); } uint64_t hash() const { - return hash_; + return uint64_t(shader) + options; } bool operator<(const ShaderKey &k) const { - return hash_ < k.hash_; + return (shader == k.shader) ? (options < k.options) : (shader < k.shader); } bool operator==(const ShaderKey &k) const { - return hash_ == k.hash_; + return (shader == k.shader) && (options == k.options); } }; -- 2.30.2