diff options
| author | Chris Forbes <chrisforbes@google.com> | 2016-04-04 10:48:35 +1200 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-04-28 08:26:44 -0600 |
| commit | 777e3bc97fb733c3e3551f3c76bf1318ac1ef2d5 (patch) | |
| tree | d1507414bba8e5974866505ec00401f950021004 | |
| parent | 5ed1012173e73609129b473b5a253a6f1a53a5e1 (diff) | |
| download | usermoji-777e3bc97fb733c3e3551f3c76bf1318ac1ef2d5.tar.xz | |
layers: Integrate SPIRV-Tools validator
Signed-off-by: Chris Forbes <chrisforbes@google.com>
| -rw-r--r-- | layers/core_validation.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index b5b911fe..abbfcc54 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -60,6 +60,7 @@ #include "vk_layer_data.h" #include "vk_layer_extension_utils.h" #include "vk_layer_utils.h" +#include "spirv-tools/libspirv.h" #if defined __ANDROID__ #include <android/log.h> @@ -915,14 +916,6 @@ static spirv_inst_iter find_entrypoint(shader_module *src, char const *name, VkS return src->end(); } -bool shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo) { - uint32_t *words = (uint32_t *)pCreateInfo->pCode; - size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t); - - /* Just validate that the header makes sense. */ - return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version; -} - static char const *storage_class_name(unsigned sc) { switch (sc) { case spv::StorageClassInput: @@ -8904,11 +8897,24 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice dev VkShaderModule *pShaderModule) { layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); bool skip_call = false; - if (!shader_is_spirv(pCreateInfo)) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, - /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC", "Shader is not SPIR-V"); + + /* Use SPIRV-Tools validator to try and catch any issues with the module itself */ + spv_context ctx = spvContextCreate(SPV_ENV_VULKAN_1_0); + spv_const_binary_t binary { pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t) }; + spv_diagnostic diag = nullptr; + + auto result = spvValidate(ctx, &binary, &diag); + if (result != SPV_SUCCESS) { + skip_call |= log_msg(my_data->report_data, + result == SPV_WARNING ? VK_DEBUG_REPORT_WARNING_BIT_EXT : VK_DEBUG_REPORT_ERROR_BIT_EXT, + VkDebugReportObjectTypeEXT(0), 0, + __LINE__, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", "SPIR-V module not valid: %s", + diag && diag->error ? diag->error : "(no error text)"); } + spvDiagnosticDestroy(diag); + spvContextDestroy(ctx); + if (skip_call) return VK_ERROR_VALIDATION_FAILED_EXT; |
