aboutsummaryrefslogtreecommitdiff
path: root/layers/core_validation.cpp
diff options
context:
space:
mode:
authorMark Lobodzinski <mark@lunarg.com>2017-05-09 15:54:16 -0600
committerMark Lobodzinski <mark@lunarg.com>2017-05-10 11:12:42 -0600
commit26ce3e47be66e372b7cc3a7ebfc1b4bf7a101971 (patch)
tree98a2596e2e97711f5856867fa292a12fbdf9a0b4 /layers/core_validation.cpp
parent976fec72e794a73e547ffd3f995582f5e556481e (diff)
downloadusermoji-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/core_validation.cpp')
-rw-r--r--layers/core_validation.cpp37
1 files changed, 22 insertions, 15 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;
}