Commit 45510ad8 by Nicolas Capens Committed by Nicolas Capens

Validate the SPIR-V code in debug builds

https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkShaderModuleCreateInfo.html states that the "code must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix" This makes it the application's responsibility to only pass valid SPIR-V code to vkCreateShaderModule. However, improperly validated code may cause bugs which are hard to root cause, so validate in our implementation as well in debug builds. This can also help with fuzzing efforts. Bug: b/158228522 Change-Id: Ib4f41fa70a021fb902e1f8504005b87c92286942 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/45569Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent f3b74473
......@@ -14,6 +14,8 @@
#include "VkShaderModule.hpp"
#include "spirv-tools/libspirv.hpp"
#include <cstring>
namespace vk {
......@@ -26,6 +28,11 @@ ShaderModule::ShaderModule(const VkShaderModuleCreateInfo *pCreateInfo, void *me
{
memcpy(code, pCreateInfo->pCode, pCreateInfo->codeSize);
wordCount = static_cast<uint32_t>(pCreateInfo->codeSize / sizeof(uint32_t));
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1);
ASSERT(spirvTools.Validate(getCode())); // The SPIR-V code passed to vkCreateShaderModule must be valid (b/158228522)
#endif
}
void ShaderModule::destroy(const VkAllocationCallbacks *pAllocator)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment