From 3f5d526e29f803152ed7883e933df839d2a98d06 Mon Sep 17 00:00:00 2001 From: Jari Komppa Date: Fri, 6 Apr 2018 22:53:29 +0300 Subject: [PATCH] Enable shader cache by default This change flips the command line option for the shader cache to be enabled by default. The change also incorporates shader cache truncation, which is enabled by default. This resets the shader cache on the start of a CTS run. For more performance the option can be disabled so the shader cache is used across CTS runs, but this may lead to very large shader cache files over time. Affects: dEQP-VK.* Components: Framework, Vulkan VK-GL-CTS issue: 899 Change-Id: Ia1bc8c932b6b280e2815f7de7f6e715b0e4edb27 --- external/vulkancts/README.md | 47 ++++++++++++++ external/vulkancts/framework/vulkan/vkPrograms.cpp | 70 ++++++++++++-------- .../vulkancts/modules/vulkan/vktBuildPrograms.cpp | 23 +++++-- framework/common/tcuCommandLine.cpp | 57 ++++++++-------- framework/common/tcuCommandLine.hpp | 75 +++++++++++----------- 5 files changed, 177 insertions(+), 95 deletions(-) diff --git a/external/vulkancts/README.md b/external/vulkancts/README.md index e5d0b71..5909794 100644 --- a/external/vulkancts/README.md +++ b/external/vulkancts/README.md @@ -157,6 +157,15 @@ platform requires a different path, it can be specified with: --deqp-log-filename= +By default, the shader cache will be written into the path "shadercache.bin". If the +platform requires a different path, it can be specified with: + + --deqp-shadercache-filename= + +If the shader cache is not desired, it can be disabled with: + + --deqp-shadercache=disable + No other command line options are allowed. ### Win32 @@ -415,3 +424,41 @@ SPIR-V which might get optimized out. Using this option will enable the optimizer on the hand-written SPIR-V as well, which may be useful in finding new bugs in drivers or the optimizer itself, but will likely invalidate the tests themselves. + + +Shader Cache +------------ + +The Vulkan CTS framework contains a shader cache for speeding up the running +of the CTS. Skipping shader compilation can significantly reduce runtime, +especially for repeated runs. + +Default behavior is to have the shader cache enabled, but truncated at the +start of the CTS run. This still gives the benefit of skipping shader +compilation for identical shaders in different tests (which there are many), +while making sure that the shader cache file does not grow indefinitely. + +The shader cache identifies the shaders by hashing the shader source code +along with various bits of information that may affect the shader compilation +(such as shader stage, CTS version, possible compilation flags, etc). If a +cached shader with matching hash is found, a byte-by-byte comparison of the +shader sources is made to make sure that the correct shader is being +retrieved from the cache. + +The behavior of the shader cache can be modified with the following command +line options: + + --deqp-shadercache=disable + +Disable the shader cache. All shaders will be compiled every time. + + --deqp-shadercache-filename= + +Set the name of the file where the cached shaders will be stored. This +option may be required for the shader cache to work at all on Android +targets. + + --deqp-shadercache-truncate=disable + +Do not truncate the shader cache file at startup. No shader compilation will +occur on repeated runs of the CTS. diff --git a/external/vulkancts/framework/vulkan/vkPrograms.cpp b/external/vulkancts/framework/vulkan/vkPrograms.cpp index 7e8f21b..b1e2047 100644 --- a/external/vulkancts/framework/vulkan/vkPrograms.cpp +++ b/external/vulkancts/framework/vulkan/vkPrograms.cpp @@ -354,6 +354,47 @@ void validateCompiledBinary(const vector& binary, glu::ShaderProgramIn de::Mutex cacheFileMutex; map > cacheFileIndex; +bool cacheFileFirstRun = true; + +void shaderCacheFirstRunCheck (const char* shaderCacheFile, bool truncate) +{ + cacheFileMutex.lock(); + if (cacheFileFirstRun) + { + cacheFileFirstRun = false; + if (truncate) + { + // Open file with "w" access to truncate it + FILE* f = fopen(shaderCacheFile, "wb"); + if (f) + fclose(f); + } + else + { + // Parse chunked shader cache file for hashes and offsets + FILE* file = fopen(shaderCacheFile, "rb"); + int count = 0; + if (file) + { + deUint32 chunksize = 0; + deUint32 hash = 0; + deUint32 offset = 0; + bool ok = true; + while (ok) + { + offset = (deUint32)ftell(file); + if (ok) ok = fread(&chunksize, 1, 4, file) == 4; + if (ok) ok = fread(&hash, 1, 4, file) == 4; + if (ok) cacheFileIndex[hash].push_back(offset); + if (ok) ok = fseek(file, offset + chunksize, SEEK_SET) == 0; + count++; + } + fclose(file); + } + } + } + cacheFileMutex.unlock(); +} std::string intToString (deUint32 integer) { @@ -364,30 +405,6 @@ std::string intToString (deUint32 integer) return temp_sstream.str(); } -// Parse chunked shader cache file for hashes and offsets -void shaderCacheParse (const char* shaderCacheFile) -{ - FILE* file = fopen(shaderCacheFile, "rb"); - int count = 0; - if (file) - { - deUint32 chunksize = 0; - deUint32 hash = 0; - deUint32 offset = 0; - bool ok = true; - while (ok) - { - offset = (deUint32)ftell(file); - if (ok) ok = fread(&chunksize, 1, 4, file) == 4; - if (ok) ok = fread(&hash, 1, 4, file) == 4; - if (ok) cacheFileIndex[hash].push_back(offset); - if (ok) ok = fseek(file, offset + chunksize, SEEK_SET) == 0; - count++; - } - fclose(file); - } -} - vk::ProgramBinary* shadercacheLoad (const std::string& shaderstring, const char* shaderCacheFilename) { deUint32 hash = deStringHash(shaderstring.c_str()); @@ -400,8 +417,6 @@ vk::ProgramBinary* shadercacheLoad (const std::string& shaderstring, const char* char* source = 0; bool ok = true; cacheFileMutex.lock(); - if (cacheFileIndex.empty()) - shaderCacheParse(shaderCacheFilename); if (cacheFileIndex.count(hash) == 0) { @@ -531,6 +546,7 @@ ProgramBinary* buildProgram (const GlslSource& program, glu::ShaderProgramInfo* if (commandLine.isShadercacheEnabled()) { + shaderCacheFirstRunCheck(commandLine.getShaderCacheFilename(), commandLine.isShaderCacheTruncateEnabled()); getCompileEnvironment(shaderstring); getBuildOptions(shaderstring, program.buildOptions, optimizationRecipe); @@ -607,6 +623,7 @@ ProgramBinary* buildProgram (const HlslSource& program, glu::ShaderProgramInfo* if (commandLine.isShadercacheEnabled()) { + shaderCacheFirstRunCheck(commandLine.getShaderCacheFilename(), commandLine.isShaderCacheTruncateEnabled()); getCompileEnvironment(shaderstring); getBuildOptions(shaderstring, program.buildOptions, optimizationRecipe); @@ -683,6 +700,7 @@ ProgramBinary* assembleProgram (const SpirVAsmSource& program, SpirVProgramInfo* if (commandLine.isShadercacheEnabled()) { + shaderCacheFirstRunCheck(commandLine.getShaderCacheFilename(), commandLine.isShaderCacheTruncateEnabled()); getCompileEnvironment(shaderstring); shaderstring += "Target Spir-V "; shaderstring += getSpirvVersionName(spirvVersion); diff --git a/external/vulkancts/modules/vulkan/vktBuildPrograms.cpp b/external/vulkancts/modules/vulkan/vktBuildPrograms.cpp index 3f29450..f74cc60 100644 --- a/external/vulkancts/modules/vulkan/vktBuildPrograms.cpp +++ b/external/vulkancts/modules/vulkan/vktBuildPrograms.cpp @@ -558,6 +558,7 @@ DE_DECLARE_COMMAND_LINE_OPT(Validate, bool); DE_DECLARE_COMMAND_LINE_OPT(VulkanVersion, deUint32); DE_DECLARE_COMMAND_LINE_OPT(ShaderCache, bool); DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheFilename, std::string); +DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheTruncate, bool); static const de::cmdline::NamedValue s_enableNames[] = { @@ -578,12 +579,13 @@ void registerOptions (de::cmdline::Parser& parser) DE_STATIC_ASSERT(vk::SPIRV_VERSION_1_3 + 1 == vk::SPIRV_VERSION_LAST); - parser << Option ("d", "dst-path", "Destination path", "out") - << Option ("n", "deqp-case", "Case path filter (works as in test binaries)") - << Option ("v", "validate-spv", "Validate generated SPIR-V binaries") - << Option ("t", "target-vulkan-version", "Target Vulkan version", s_vulkanVersion, "1.1") - << Option ("s", "shadercache", "Enable or disable shader cache", s_enableNames, "disable") - << Option ("r", "shadercache-filename", "Write shader cache to given file", "shadercache.bin"); + parser << Option("d", "dst-path", "Destination path", "out") + << Option("n", "deqp-case", "Case path filter (works as in test binaries)") + << Option("v", "validate-spv", "Validate generated SPIR-V binaries") + << Option("t", "target-vulkan-version", "Target Vulkan version", s_vulkanVersion, "1.1") + << Option("s", "shadercache", "Enable or disable shader cache", s_enableNames, "enable") + << Option("r", "shadercache-filename", "Write shader cache to given file", "shadercache.bin") + << Option("x", "shadercache-truncate", "Truncate shader cache before running", s_enableNames, "enable"); } } // opt @@ -629,6 +631,15 @@ int main (int argc, const char* argv[]) deqpArgv.push_back("disable"); } + if (cmdLine.hasOption()) + { + deqpArgv.push_back("--deqp-shadercache-truncate"); + if (cmdLine.getOption()) + deqpArgv.push_back("enable"); + else + deqpArgv.push_back("disable"); + } + if (!deqpCmdLine.parse((int)deqpArgv.size(), &deqpArgv[0])) return -1; } diff --git a/framework/common/tcuCommandLine.cpp b/framework/common/tcuCommandLine.cpp index 7a9a73a..2024159 100644 --- a/framework/common/tcuCommandLine.cpp +++ b/framework/common/tcuCommandLine.cpp @@ -93,6 +93,7 @@ DE_DECLARE_COMMAND_LINE_OPT(ShaderCache, bool); DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheFilename, std::string); DE_DECLARE_COMMAND_LINE_OPT(Optimization, int); DE_DECLARE_COMMAND_LINE_OPT(OptimizeSpirv, bool); +DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheTruncate, bool); static void parseIntList (const char* src, std::vector* dst) { @@ -182,10 +183,11 @@ void registerOptions (de::cmdline::Parser& parser) << Option (DE_NULL, "deqp-test-oom", "Run tests that exhaust memory on purpose", s_enableNames, TEST_OOM_DEFAULT) << Option (DE_NULL, "deqp-log-flush", "Enable or disable log file fflush", s_enableNames, "enable") << Option (DE_NULL, "deqp-validation", "Enable or disable test case validation", s_enableNames, "disable") - << Option (DE_NULL, "deqp-shadercache", "Enable or disable shader cache", s_enableNames, "disable") - << Option (DE_NULL, "deqp-shadercache-filename", "Write shader cache to given file", "shadercache.bin") << Option (DE_NULL, "deqp-optimization-recipe", "Shader optimization recipe (0=disabled)", "0") - << Option (DE_NULL, "deqp-optimize-spirv", "Apply optimization to spir-v shaders as well", s_enableNames, "disable"); + << Option (DE_NULL, "deqp-optimize-spirv", "Apply optimization to spir-v shaders as well", s_enableNames, "disable") + << Option (DE_NULL, "deqp-shadercache", "Enable or disable shader cache", s_enableNames, "enable") + << Option (DE_NULL, "deqp-shadercache-filename", "Write shader cache to given file", "shadercache.bin") + << Option (DE_NULL, "deqp-shadercache-truncate", "Truncate shader cache before running tests", s_enableNames, "enable"); } void registerLegacyOptions (de::cmdline::Parser& parser) @@ -779,30 +781,31 @@ bool CommandLine::parse (const std::string& cmdLine) return isOk; } -const char* CommandLine::getLogFileName (void) const { return m_cmdLine.getOption().c_str(); } -deUint32 CommandLine::getLogFlags (void) const { return m_logFlags; } -RunMode CommandLine::getRunMode (void) const { return m_cmdLine.getOption(); } -const char* CommandLine::getCaseListExportFile (void) const { return m_cmdLine.getOption().c_str(); } -WindowVisibility CommandLine::getVisibility (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isWatchDogEnabled (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isCrashHandlingEnabled (void) const { return m_cmdLine.getOption(); } -int CommandLine::getBaseSeed (void) const { return m_cmdLine.getOption(); } -int CommandLine::getTestIterationCount (void) const { return m_cmdLine.getOption(); } -int CommandLine::getSurfaceWidth (void) const { return m_cmdLine.getOption(); } -int CommandLine::getSurfaceHeight (void) const { return m_cmdLine.getOption(); } -SurfaceType CommandLine::getSurfaceType (void) const { return m_cmdLine.getOption(); } -ScreenRotation CommandLine::getScreenRotation (void) const { return m_cmdLine.getOption(); } -int CommandLine::getGLConfigId (void) const { return m_cmdLine.getOption(); } -int CommandLine::getCLPlatformId (void) const { return m_cmdLine.getOption(); } -const std::vector& CommandLine::getCLDeviceIds (void) const { return m_cmdLine.getOption(); } -int CommandLine::getVKDeviceId (void) const { return m_cmdLine.getOption(); } -int CommandLine::getVKDeviceGroupId (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isValidationEnabled (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isOutOfMemoryTestEnabled (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isShadercacheEnabled (void) const { return m_cmdLine.getOption(); } -const char* CommandLine::getShaderCacheFilename (void) const { return m_cmdLine.getOption().c_str(); } -int CommandLine::getOptimizationRecipe (void) const { return m_cmdLine.getOption(); } -bool CommandLine::isSpirvOptimizationEnabled (void) const { return m_cmdLine.getOption(); } +const char* CommandLine::getLogFileName (void) const { return m_cmdLine.getOption().c_str(); } +deUint32 CommandLine::getLogFlags (void) const { return m_logFlags; } +RunMode CommandLine::getRunMode (void) const { return m_cmdLine.getOption(); } +const char* CommandLine::getCaseListExportFile (void) const { return m_cmdLine.getOption().c_str(); } +WindowVisibility CommandLine::getVisibility (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isWatchDogEnabled (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isCrashHandlingEnabled (void) const { return m_cmdLine.getOption(); } +int CommandLine::getBaseSeed (void) const { return m_cmdLine.getOption(); } +int CommandLine::getTestIterationCount (void) const { return m_cmdLine.getOption(); } +int CommandLine::getSurfaceWidth (void) const { return m_cmdLine.getOption(); } +int CommandLine::getSurfaceHeight (void) const { return m_cmdLine.getOption(); } +SurfaceType CommandLine::getSurfaceType (void) const { return m_cmdLine.getOption(); } +ScreenRotation CommandLine::getScreenRotation (void) const { return m_cmdLine.getOption(); } +int CommandLine::getGLConfigId (void) const { return m_cmdLine.getOption(); } +int CommandLine::getCLPlatformId (void) const { return m_cmdLine.getOption(); } +const std::vector& CommandLine::getCLDeviceIds (void) const { return m_cmdLine.getOption(); } +int CommandLine::getVKDeviceId (void) const { return m_cmdLine.getOption(); } +int CommandLine::getVKDeviceGroupId (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isValidationEnabled (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isOutOfMemoryTestEnabled (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isShadercacheEnabled (void) const { return m_cmdLine.getOption(); } +const char* CommandLine::getShaderCacheFilename (void) const { return m_cmdLine.getOption().c_str(); } +bool CommandLine::isShaderCacheTruncateEnabled (void) const { return m_cmdLine.getOption(); } +int CommandLine::getOptimizationRecipe (void) const { return m_cmdLine.getOption(); } +bool CommandLine::isSpirvOptimizationEnabled (void) const { return m_cmdLine.getOption(); } const char* CommandLine::getGLContextType (void) const { diff --git a/framework/common/tcuCommandLine.hpp b/framework/common/tcuCommandLine.hpp index 7cefa51..85b24f5 100644 --- a/framework/common/tcuCommandLine.hpp +++ b/framework/common/tcuCommandLine.hpp @@ -121,101 +121,104 @@ private: class CommandLine { public: - CommandLine (void); - CommandLine (int argc, const char* const* argv); - explicit CommandLine (const std::string& cmdLine); - ~CommandLine (void); + CommandLine (void); + CommandLine (int argc, const char* const* argv); + explicit CommandLine (const std::string& cmdLine); + ~CommandLine (void); - bool parse (int argc, const char* const* argv); - bool parse (const std::string& cmdLine); + bool parse (int argc, const char* const* argv); + bool parse (const std::string& cmdLine); //! Get log file name (--deqp-log-filename) - const char* getLogFileName (void) const; + const char* getLogFileName (void) const; //! Get logging flags - deUint32 getLogFlags (void) const; + deUint32 getLogFlags (void) const; //! Get run mode (--deqp-runmode) - RunMode getRunMode (void) const; + RunMode getRunMode (void) const; //! Get caselist dump target file pattern (--deqp-caselist-export-file) - const char* getCaseListExportFile (void) const; + const char* getCaseListExportFile (void) const; //! Get default window visibility (--deqp-visibility) - WindowVisibility getVisibility (void) const; + WindowVisibility getVisibility (void) const; //! Get watchdog enable status (--deqp-watchdog) - bool isWatchDogEnabled (void) const; + bool isWatchDogEnabled (void) const; //! Get crash handling enable status (--deqp-crashhandler) - bool isCrashHandlingEnabled (void) const; + bool isCrashHandlingEnabled (void) const; //! Get base seed for randomization (--deqp-base-seed) - int getBaseSeed (void) const; + int getBaseSeed (void) const; //! Get test iteration count (--deqp-test-iteration-count) - int getTestIterationCount (void) const; + int getTestIterationCount (void) const; //! Get rendering target width (--deqp-surface-width) - int getSurfaceWidth (void) const; + int getSurfaceWidth (void) const; //! Get rendering target height (--deqp-surface-height) - int getSurfaceHeight (void) const; + int getSurfaceHeight (void) const; //! Get rendering taget type (--deqp-surface-type) - SurfaceType getSurfaceType (void) const; + SurfaceType getSurfaceType (void) const; //! Get screen rotation (--deqp-screen-rotation) - ScreenRotation getScreenRotation (void) const; + ScreenRotation getScreenRotation (void) const; //! Get GL context factory name (--deqp-gl-context-type) - const char* getGLContextType (void) const; + const char* getGLContextType (void) const; //! Get GL config ID (--deqp-gl-config-id) - int getGLConfigId (void) const; + int getGLConfigId (void) const; //! Get GL config name (--deqp-gl-config-name) - const char* getGLConfigName (void) const; + const char* getGLConfigName (void) const; //! Get GL context flags (--deqp-gl-context-flags) - const char* getGLContextFlags (void) const; + const char* getGLContextFlags (void) const; //! Get OpenCL platform ID (--deqp-cl-platform-id) - int getCLPlatformId (void) const; + int getCLPlatformId (void) const; //! Get OpenCL device IDs (--deqp-cl-device-ids) - void getCLDeviceIds (std::vector& deviceIds) const { deviceIds = getCLDeviceIds(); } - const std::vector& getCLDeviceIds (void) const; + void getCLDeviceIds (std::vector& deviceIds) const { deviceIds = getCLDeviceIds(); } + const std::vector& getCLDeviceIds (void) const; //! Get extra OpenCL program build options (--deqp-cl-build-options) - const char* getCLBuildOptions (void) const; + const char* getCLBuildOptions (void) const; //! Get EGL native display factory (--deqp-egl-display-type) - const char* getEGLDisplayType (void) const; + const char* getEGLDisplayType (void) const; //! Get EGL native window factory (--deqp-egl-window-type) - const char* getEGLWindowType (void) const; + const char* getEGLWindowType (void) const; //! Get EGL native pixmap factory (--deqp-egl-pixmap-type) - const char* getEGLPixmapType (void) const; + const char* getEGLPixmapType (void) const; //! Get Vulkan device ID (--deqp-vk-device-id) - int getVKDeviceId (void) const; + int getVKDeviceId (void) const; //! Get Vulkan device group ID (--deqp-vk-device-group-id) - int getVKDeviceGroupId (void) const; + int getVKDeviceGroupId (void) const; //! Enable development-time test case validation checks - bool isValidationEnabled (void) const; + bool isValidationEnabled (void) const; //! Should we run tests that exhaust memory (--deqp-test-oom) - bool isOutOfMemoryTestEnabled (void) const; + bool isOutOfMemoryTestEnabled (void) const; //! Should the shader cache be enabled (--deqp-shadercache) - bool isShadercacheEnabled (void) const; + bool isShadercacheEnabled (void) const; //! Get the filename for shader cache (--deqp-shadercache-filename) - const char* getShaderCacheFilename (void) const; + const char* getShaderCacheFilename (void) const; + + //! Should the shader cache be truncated before run (--deqp-shadercache-truncate) + bool isShaderCacheTruncateEnabled (void) const; //! Get shader optimization recipe (--deqp-optimization-recipe) int getOptimizationRecipe (void) const; -- 2.7.4