From 265ed761313d287bbe2edef03d1fa48bb6ac8487 Mon Sep 17 00:00:00 2001 From: Dunedan Date: Thu, 19 Sep 2024 11:49:21 +0200 Subject: [PATCH] Simplify check for identical shaders Previously when checking if two SPIR-V shaders are identical the hashs of their file content would be compared and afterwards their (unhashed) file contents as well. Comparing the file contents isn't necessary, as the hash function used is a cryptographic one, which guarantees the hash can be used as a representative of the hashed data. --- source/tools/spirv/compile.py | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/source/tools/spirv/compile.py b/source/tools/spirv/compile.py index f8a637a370..e5170a1ad7 100755 --- a/source/tools/spirv/compile.py +++ b/source/tools/spirv/compile.py @@ -49,14 +49,6 @@ def calculate_hash(path): return hashlib.sha1(handle.read()).hexdigest() -def compare_spirv(path1, path2): - with open(path1, "rb") as handle: - spirv1 = handle.read() - with open(path2, "rb") as handle: - spirv2 = handle.read() - return spirv1 == spirv2 - - def resolve_if(defines, expression): for item in expression.strip().split("||"): item = item.strip() @@ -456,19 +448,10 @@ def build(rules, input_mod_path, output_mod_path, dependencies, program_name): spirv_hash = calculate_hash(output_spirv_path) if spirv_hash not in hashed_cache: - hashed_cache[spirv_hash] = [file_name] + hashed_cache[spirv_hash] = file_name else: - found_candidate = False - for candidate_name in hashed_cache[spirv_hash]: - candidate_path = os.path.join(output_spirv_mod_path, candidate_name) - if compare_spirv(output_spirv_path, candidate_path): - found_candidate = True - file_name = candidate_name - break - if found_candidate: - os.remove(output_spirv_path) - else: - hashed_cache[spirv_hash].append(file_name) + file_name = hashed_cache[spirv_hash] + os.remove(output_spirv_path) shader_element = ET.SubElement(program_root, shader["type"]) shader_element.set("file", "spirv/" + file_name)