From f0cd62b37c5dfbbdb3fb205f1be2b8beba0dfed4 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Wed, 12 Oct 2022 09:55:09 -0700 Subject: Shader caching (#2432) * Changed all getEntryPointCode calls to use RendererBase::getEntryPointCodeFromShaderCache * Hashing hooked up, tests pass but need to add more to fully test functionality * checkpoint * Checkpoint: File system creation seems functional, saving is broken * checkpoint: Fixed filename generation from MD5 hash, shader blob might be going missing ahead of pipeline state creation * Fixed a lot of bugs related to hash code generation, shader cache is likely working but needs further testing * Added workaround for module loading by re-creating the test device, shader cache test functional * Vulkan shader caching bug fixed, checkpoint commit before more refinement * pre-ToT merge checkpoint * checkpoint commit, improving cache keys * Significantly expanded items included in the dependency hash for Module; Added dependency hash functions to SpecializedComponentType and RenamedEntryPointComponentType * Temporarily disable shader cache test * Mid cleanup changes, solution successfully builds * Added several helper update functions to slang-md5 to help simplify usage; Added a function under ISession to compute a hash for all linkage-related items; Function renames and cleaned up some comments * Ran premake.bat; Renamed getASTBasedHashCode to computeASTBasedHash * Added slang unit tests for Checksum and MD5; Extended gfx shader cache test to test with multiple shader files and one shader file with multiple entry points * Solution builds and shader cache tests pass, but at least a couple other tests now failing * ran premake.bat * More cleanup changes * Added shaderCachePath field to IDevice desc in gfx.slang, gfx-smoke.slang should be functional * ran premake * cleanup changes; Adding test printf to getEntryPointCodeFromShaderCache to see if output can be seen in CI * Removed debugging printfs; Added handling for getEntryPointCode() failing * Cleanup changes; Jonathan's fixes to SerialWriter to zero initialize otherwise uninitialized memory; Change to SwizzleExpr creation to zero initialize elementCount * Changed enable_if_t to enable_if * Fixed enable_if * Added test for import vs include and changes to included and imported files; Fixed build errors in CUDA; Renamed shader cache statistics fields * cleanup changes * Readd removed file * Restructured computeDependencyBasedHash calls, added computeDependencyBasedHashImpl to all classes dervied from ComponentType * Applied same restructuring to the AST hash functions * Cleanup changes; Moved HashBuilder out to slang-digest.h and added some helper functions to streamline the process of adding items to a hash * Cleanup; Fixed incorrect expected results for shader import and include test --- tools/slang-unit-test/unit-test-checksum.cpp | 32 +++++++++ tools/slang-unit-test/unit-test-md5.cpp | 97 ++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tools/slang-unit-test/unit-test-checksum.cpp create mode 100644 tools/slang-unit-test/unit-test-md5.cpp (limited to 'tools/slang-unit-test') diff --git a/tools/slang-unit-test/unit-test-checksum.cpp b/tools/slang-unit-test/unit-test-checksum.cpp new file mode 100644 index 000000000..8980bd31f --- /dev/null +++ b/tools/slang-unit-test/unit-test-checksum.cpp @@ -0,0 +1,32 @@ +// unit-test-checksum.cpp + +#include "tools/unit-test/slang-unit-test.h" + +#include "../../source/slang/slang-hash-utils.h" + +using namespace Slang; + +SLANG_UNIT_TEST(checksum) +{ + { + slang::Digest testA; + testA.values[0] = 1; + testA.values[1] = 2; + testA.values[2] = 3; + testA.values[3] = 4; + + String testAString = hashToString(testA); + SLANG_CHECK(testAString.equals(String("00000001000000020000000300000004"))); + } + + { + slang::Digest testC; + testC.values[0] = 0x11111111; + testC.values[1] = 0x22222222; + testC.values[2] = 0x33333333; + testC.values[3] = 0x44444444; + + String testCString = hashToString(testC); + SLANG_CHECK(testCString.equals(String("11111111222222223333333344444444"))); + } +} diff --git a/tools/slang-unit-test/unit-test-md5.cpp b/tools/slang-unit-test/unit-test-md5.cpp new file mode 100644 index 000000000..95235e0ed --- /dev/null +++ b/tools/slang-unit-test/unit-test-md5.cpp @@ -0,0 +1,97 @@ +// unit-test-md5.cpp +#include "tools/unit-test/slang-unit-test.h" + +#include "../../source/core/slang-md5.h" +#include "../../source/core/slang-string.h" +#include "../../source/slang/slang-hash-utils.h" + +using namespace Slang; + +SLANG_UNIT_TEST(md5hash) +{ + { + // Raw numerical values, etc. + MD5Context testCtx; + MD5HashGen testHashGen; + testHashGen.init(&testCtx); + + int64_t valueA = -1; + uint64_t valueB = 1; + testHashGen.update(&testCtx, valueA); + testHashGen.update(&testCtx, valueB); + + slang::Digest testA; + testHashGen.finalize(&testCtx, &testA); + + String testAString = hashToString(testA); + SLANG_CHECK(testAString.equals(String("E271A15BD2BD98081390630579266F74"))); + } + + { + // List + MD5Context testCtx; + MD5HashGen testHashGen; + testHashGen.init(&testCtx); + + List listA; + listA.add(1); + listA.add(2); + listA.add(3); + listA.add(4); + testHashGen.update(&testCtx, listA); + + slang::Digest testB; + testHashGen.finalize(&testCtx, &testB); + + String testBString = hashToString(testB); + SLANG_CHECK(testBString.equals(String("8AD852437539AA78D60CF70BA5CA7BF2"))); + } + + { + // UnownedStringSlice + MD5Context testCtx; + MD5HashGen testHashGen; + testHashGen.init(&testCtx); + + UnownedStringSlice stringSlice = UnownedStringSlice("String Slice Test"); + testHashGen.update(&testCtx, stringSlice); + + slang::Digest testC; + testHashGen.finalize(&testCtx, &testC); + + String testCString = hashToString(testC); + SLANG_CHECK(testCString.equals(String("8EC56C5DDFA424183957CFD01633605B"))); + } + + { + // String + MD5Context testCtx; + MD5HashGen testHashGen; + testHashGen.init(&testCtx); + + String str = String("String Test"); + testHashGen.update(&testCtx, str); + + slang::Digest testD; + testHashGen.finalize(&testCtx, &testD); + + String testDString = hashToString(testD); + SLANG_CHECK(testDString.equals(String("CC795ADF40C7702106A5F01C24CEB0CE"))); + } + + { + // Hash + MD5Context testCtx; + MD5HashGen testHashGen; + testHashGen.init(&testCtx); + + slang::Digest Hash; + testHashGen.update(&testCtx, Hash); + + slang::Digest testE; + testHashGen.finalize(&testCtx, &testE); + + String testEString = hashToString(testE); + SLANG_CHECK(testEString.equals(String("3613E74ABFF94BE42E75D279A5184823"))); + } +} -- cgit v1.2.3