From 26ce3e47be66e372b7cc3a7ebfc1b4bf7a101971 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Tue, 9 May 2017 15:54:16 -0600 Subject: layers: GH1739, Add check for shader binary size VU 2816 says size must be a multiple of 4. Change-Id: I38749fe44e02cac4e40aa572c4e4ccec01d82279 --- layers/core_validation.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index feeb65ed..b4678a95 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -8780,23 +8780,30 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShade spv_result_t spv_valid = SPV_SUCCESS; if (!GetDisables(dev_data)->shader_validation) { - // 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; - - spv_valid = spvValidate(ctx, &binary, &diag); - if (spv_valid != SPV_SUCCESS) { - if (!dev_data->device_extensions.nv_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) { - skip |= log_msg(dev_data->report_data, - spv_valid == SPV_WARNING ? VK_DEBUG_REPORT_WARNING_BIT_EXT : VK_DEBUG_REPORT_ERROR_BIT_EXT, - VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", - "SPIR-V module not valid: %s", diag && diag->error ? diag->error : "(no error text)"); + if (!dev_data->device_extensions.nv_glsl_shader && (pCreateInfo->codeSize % 4)) { + skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, + __LINE__, VALIDATION_ERROR_02816, "SC", + "SPIR-V module not valid: Codesize must be a multiple of 4 but is " PRINTF_SIZE_T_SPECIFIER ". %s", + pCreateInfo->codeSize, validation_error_map[VALIDATION_ERROR_02816]); + } else { + // 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; + + spv_valid = spvValidate(ctx, &binary, &diag); + if (spv_valid != SPV_SUCCESS) { + if (!dev_data->device_extensions.nv_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) { + skip |= log_msg(dev_data->report_data, + spv_valid == SPV_WARNING ? VK_DEBUG_REPORT_WARNING_BIT_EXT : VK_DEBUG_REPORT_ERROR_BIT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 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); + spvDiagnosticDestroy(diag); + spvContextDestroy(ctx); + } if (skip) return VK_ERROR_VALIDATION_FAILED_EXT; } -- cgit v1.2.3