-static void vkd3d_spirv_validate(const struct vkd3d_shader_code *spirv, +static bool vkd3d_spirv_validate(struct spirv_compiler *compiler, const struct vkd3d_shader_code *spirv, enum vkd3d_shader_spirv_environment environment) { spv_diagnostic diagnostic = NULL; spv_context context; - spv_result_t ret; + spv_result_t res; + bool ret = true; context = spvContextCreate(spv_target_env_from_vkd3d(environment)); - if ((ret = spvValidateBinary(context, spirv->code, spirv->size / sizeof(uint32_t), + if ((res = spvValidateBinary(context, spirv->code, spirv->size / sizeof(uint32_t), &diagnostic))) { - FIXME("Failed to validate SPIR-V binary, ret %d.\n", ret); - FIXME("Diagnostic message: %s.\n", debugstr_a(diagnostic->error)); + FIXME("Failed to validate SPIR-V binary, result %d.\n", res); + TRACE("Diagnostic message: %s.\n", debugstr_a(diagnostic->error)); + vkd3d_shader_trace_text(diagnostic->error, strlen(diagnostic->error)); + + if (compiler->config_flags & VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION) + { + spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_INVALID_SHADER, + "Execution generated an invalid shader:\n%s", diagnostic->error); + ret = false; + } } spvDiagnosticDestroy(diagnostic); spvContextDestroy(context); + + return ret; }
Could we just vkd3d_string_buffer_printf() diagnostic->error here? It would allow the caller to decide what to do with the error, slightly reduce the amount of code inside #ifdef, and probably avoid moving a bunch of code around as well.