diff options
| author | Mark Lobodzinski <mark@lunarg.com> | 2017-05-09 15:54:16 -0600 |
|---|---|---|
| committer | Mark Lobodzinski <mark@lunarg.com> | 2017-05-10 11:12:42 -0600 |
| commit | 26ce3e47be66e372b7cc3a7ebfc1b4bf7a101971 (patch) | |
| tree | 98a2596e2e97711f5856867fa292a12fbdf9a0b4 /layers | |
| parent | 976fec72e794a73e547ffd3f995582f5e556481e (diff) | |
| download | usermoji-26ce3e47be66e372b7cc3a7ebfc1b4bf7a101971.tar.xz | |
layers: GH1739, Add check for shader binary size
VU 2816 says size must be a multiple of 4.
Change-Id: I38749fe44e02cac4e40aa572c4e4ccec01d82279
Diffstat (limited to 'layers')
| -rw-r--r-- | layers/core_validation.cpp | 37 | ||||
| -rw-r--r-- | layers/vk_validation_error_database.txt | 2 |
2 files changed, 23 insertions, 16 deletions
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; } diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt index bbe6c0b0..ea5d58d0 100644 --- a/layers/vk_validation_error_database.txt +++ b/layers/vk_validation_error_database.txt @@ -2636,7 +2636,7 @@ VALIDATION_ERROR_02812~^~N~^~Unknown~^~vkCmdBeginRenderPass~^~For more informati VALIDATION_ERROR_02813~^~N~^~Unknown~^~vkCmdBeginRenderPass~^~For more information refer to Vulkan Spec Section '7.4. Render Pass Commands' which states 'deviceRenderAreaCount must either be zero or equal to the number of physical devices in the logical device.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDeviceGroupRenderPassBeginInfoKHX)~^~ VALIDATION_ERROR_02814~^~N~^~Unknown~^~vkCmdBeginRenderPass~^~For more information refer to Vulkan Spec Section '7.4. Render Pass Commands' which states 'sType must be VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO_KHX' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDeviceGroupRenderPassBeginInfoKHX)~^~implicit VALIDATION_ERROR_02815~^~N~^~Unknown~^~vkCmdBeginRenderPass~^~For more information refer to Vulkan Spec Section '7.4. Render Pass Commands' which states 'If deviceRenderAreaCount is not 0, pDeviceRenderAreas must be a pointer to an array of deviceRenderAreaCount VkRect2D structures' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDeviceGroupRenderPassBeginInfoKHX)~^~implicit -VALIDATION_ERROR_02816~^~N~^~Unknown~^~vkCreateShaderModule~^~For more information refer to Vulkan Spec Section '8.1. Shader Modules' which states 'codeSize must be a multiple of 4 unless the VK_NV_glsl_shader extension is enabled, and pCode references GLSL code, codeSize can be a multiple of 1' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkShaderModuleCreateInfo)~^~ +VALIDATION_ERROR_02816~^~Y~^~InvalidSPIRVCodeSize~^~vkCreateShaderModule~^~For more information refer to Vulkan Spec Section '8.1. Shader Modules' which states 'codeSize must be a multiple of 4 unless the VK_NV_glsl_shader extension is enabled, and pCode references GLSL code, codeSize can be a multiple of 1' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkShaderModuleCreateInfo)~^~ VALIDATION_ERROR_02817~^~N~^~Unknown~^~vkCreateShaderModule~^~For more information refer to Vulkan Spec Section '8.1. Shader Modules' which states 'pCode must point to valid SPIR-V code, formatted and packed as described by the Khronos SPIR-V Specification or, if the VK_NV_glsl_shader extension is enabled, pCode can instead reference valid GLSL code which must be written to the GL_KHR_vulkan_glsl extension specification' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkShaderModuleCreateInfo)~^~ VALIDATION_ERROR_02818~^~N~^~Unknown~^~vkCreateShaderModule~^~For more information refer to Vulkan Spec Section '8.1. Shader Modules' which states 'pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix or, if the VK_NV_glsl_shader extension is enabled, pCode can be valid GLSL code written to the GL_KHR_vulkan_glsl GLSL extension specification' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkShaderModuleCreateInfo)~^~ VALIDATION_ERROR_02819~^~N~^~Unknown~^~vkCreateShaderModule~^~For more information refer to Vulkan Spec Section '8.1. Shader Modules' which states 'pCode must be a pointer to an array of /(codeSize /over 4/) uint32_t values' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkShaderModuleCreateInfo)~^~implicit |
