mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 11:40:05 +00:00
Add utility to generate a logging string for a given environment (#2314)
Fixes #2313
This commit is contained in:
parent
a64c651e18
commit
3a3ad2ec50
@ -248,3 +248,39 @@ bool spvIsWebGPUEnv(spv_target_env env) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string spvLogStringForEnv(spv_target_env env) {
|
||||
switch (env) {
|
||||
case SPV_ENV_OPENCL_1_2:
|
||||
case SPV_ENV_OPENCL_2_0:
|
||||
case SPV_ENV_OPENCL_2_1:
|
||||
case SPV_ENV_OPENCL_2_2:
|
||||
case SPV_ENV_OPENCL_EMBEDDED_1_2:
|
||||
case SPV_ENV_OPENCL_EMBEDDED_2_0:
|
||||
case SPV_ENV_OPENCL_EMBEDDED_2_1:
|
||||
case SPV_ENV_OPENCL_EMBEDDED_2_2: {
|
||||
return "OpenCL";
|
||||
}
|
||||
case SPV_ENV_OPENGL_4_0:
|
||||
case SPV_ENV_OPENGL_4_1:
|
||||
case SPV_ENV_OPENGL_4_2:
|
||||
case SPV_ENV_OPENGL_4_3:
|
||||
case SPV_ENV_OPENGL_4_5: {
|
||||
return "OpenGL";
|
||||
}
|
||||
case SPV_ENV_VULKAN_1_0:
|
||||
case SPV_ENV_VULKAN_1_1: {
|
||||
return "Vulkan";
|
||||
}
|
||||
case SPV_ENV_WEBGPU_0: {
|
||||
return "WebGPU";
|
||||
}
|
||||
case SPV_ENV_UNIVERSAL_1_0:
|
||||
case SPV_ENV_UNIVERSAL_1_1:
|
||||
case SPV_ENV_UNIVERSAL_1_2:
|
||||
case SPV_ENV_UNIVERSAL_1_3: {
|
||||
return "Universal";
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
#ifndef SOURCE_SPIRV_TARGET_ENV_H_
|
||||
#define SOURCE_SPIRV_TARGET_ENV_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "spirv-tools/libspirv.h"
|
||||
|
||||
// Parses s into *env and returns true if successful. If unparsable, returns
|
||||
@ -33,4 +35,8 @@ bool spvIsWebGPUEnv(spv_target_env env);
|
||||
// Returns the version number for the given SPIR-V target environment.
|
||||
uint32_t spvVersionForTargetEnv(spv_target_env env);
|
||||
|
||||
// Returns a string to use in logging messages that indicates the class of
|
||||
// environment, i.e. "Vulkan", "WebGPU", "OpenCL", etc.
|
||||
std::string spvLogStringForEnv(spv_target_env env);
|
||||
|
||||
#endif // SOURCE_SPIRV_TARGET_ENV_H_
|
||||
|
@ -110,11 +110,10 @@ spv_result_t ValidateTypeArray(ValidationState_t& _, const Instruction* inst) {
|
||||
if ((spvIsVulkanEnv(_.context()->target_env) ||
|
||||
spvIsWebGPUEnv(_.context()->target_env)) &&
|
||||
element_type->opcode() == SpvOpTypeRuntimeArray) {
|
||||
const char* env_text =
|
||||
spvIsVulkanEnv(_.context()->target_env) ? "Vulkan" : "WebGPU";
|
||||
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
||||
<< "OpTypeArray Element Type <id> '" << _.getIdName(element_type_id)
|
||||
<< "' is not valid in " << env_text << " environment.";
|
||||
<< "' is not valid in "
|
||||
<< spvLogStringForEnv(_.context()->target_env) << " environments.";
|
||||
}
|
||||
|
||||
const auto length_index = 2;
|
||||
@ -175,12 +174,10 @@ spv_result_t ValidateTypeRuntimeArray(ValidationState_t& _,
|
||||
if ((spvIsVulkanEnv(_.context()->target_env) ||
|
||||
spvIsWebGPUEnv(_.context()->target_env)) &&
|
||||
element_type->opcode() == SpvOpTypeRuntimeArray) {
|
||||
const char* env_text =
|
||||
spvIsVulkanEnv(_.context()->target_env) ? "Vulkan" : "WebGPU";
|
||||
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
||||
<< "OpTypeRuntimeArray Element Type <id> '"
|
||||
<< _.getIdName(element_id) << "' is not valid in " << env_text
|
||||
<< " environment.";
|
||||
<< _.getIdName(element_id) << "' is not valid in "
|
||||
<< spvLogStringForEnv(_.context()->target_env) << " environments.";
|
||||
}
|
||||
|
||||
return SPV_SUCCESS;
|
||||
@ -235,11 +232,10 @@ spv_result_t ValidateTypeStruct(ValidationState_t& _, const Instruction* inst) {
|
||||
const bool is_last_member =
|
||||
member_type_index == inst->operands().size() - 1;
|
||||
if (!is_last_member) {
|
||||
const char* env_text =
|
||||
spvIsVulkanEnv(_.context()->target_env) ? "Vulkan" : "WebGPU";
|
||||
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
||||
<< "In " << env_text << ", OpTypeRuntimeArray must only be used "
|
||||
<< "for the last member of an OpTypeStruct";
|
||||
<< "In " << spvLogStringForEnv(_.context()->target_env)
|
||||
<< ", OpTypeRuntimeArray must only be used for the last member "
|
||||
"of an OpTypeStruct";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2179,7 +2179,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '3[%_runtimearr_2]' is not "
|
||||
"valid in Vulkan environment.\n %_runtimearr__runtimearr_2 = "
|
||||
"valid in Vulkan environments.\n %_runtimearr__runtimearr_2 = "
|
||||
"OpTypeRuntimeArray %_runtimearr_2\n"));
|
||||
}
|
||||
|
||||
@ -2210,7 +2210,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '3[%_runtimearr_2]' is not "
|
||||
"valid in WebGPU environment.\n %_runtimearr__runtimearr_2 = "
|
||||
"valid in WebGPU environments.\n %_runtimearr__runtimearr_2 = "
|
||||
"OpTypeRuntimeArray %_runtimearr_2\n"));
|
||||
}
|
||||
|
||||
@ -2242,7 +2242,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '4[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_runtimearr__runtimearr_uint = "
|
||||
"valid in Vulkan environments.\n %_runtimearr__runtimearr_uint = "
|
||||
"OpTypeRuntimeArray %_runtimearr_uint\n"));
|
||||
}
|
||||
|
||||
@ -2304,7 +2304,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '5[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_runtimearr__runtimearr_uint = "
|
||||
"valid in Vulkan environments.\n %_runtimearr__runtimearr_uint = "
|
||||
"OpTypeRuntimeArray %_runtimearr_uint\n"));
|
||||
}
|
||||
|
||||
@ -2340,7 +2340,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '5[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_runtimearr__runtimearr_uint = "
|
||||
"valid in Vulkan environments.\n %_runtimearr__runtimearr_uint = "
|
||||
"OpTypeRuntimeArray %_runtimearr_uint\n"));
|
||||
}
|
||||
|
||||
@ -2370,7 +2370,7 @@ OpFunctionEnd
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("OpTypeArray Element Type <id> '5[%_runtimearr_4]' is not "
|
||||
"valid in Vulkan environment.\n %_arr__runtimearr_4_uint_1 = "
|
||||
"valid in Vulkan environments.\n %_arr__runtimearr_4_uint_1 = "
|
||||
"OpTypeArray %_runtimearr_4 %uint_1\n"));
|
||||
}
|
||||
|
||||
@ -2402,7 +2402,7 @@ OpFunctionEnd
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("OpTypeArray Element Type <id> '5[%_runtimearr_4]' is not "
|
||||
"valid in WebGPU environment.\n %_arr__runtimearr_4_uint_1 = "
|
||||
"valid in WebGPU environments.\n %_arr__runtimearr_4_uint_1 = "
|
||||
"OpTypeArray %_runtimearr_4 %uint_1\n"));
|
||||
}
|
||||
|
||||
@ -2436,7 +2436,7 @@ OpFunctionEnd
|
||||
getDiagnosticString(),
|
||||
HasSubstr(
|
||||
"OpTypeRuntimeArray Element Type <id> '6[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_runtimearr__runtimearr_uint = "
|
||||
"valid in Vulkan environments.\n %_runtimearr__runtimearr_uint = "
|
||||
"OpTypeRuntimeArray %_runtimearr_uint\n"));
|
||||
}
|
||||
|
||||
@ -2468,9 +2468,10 @@ OpFunctionEnd
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("OpTypeArray Element Type <id> '6[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_arr__runtimearr_uint_uint_1 "
|
||||
"= OpTypeArray %_runtimearr_uint %uint_1\n"));
|
||||
HasSubstr(
|
||||
"OpTypeArray Element Type <id> '6[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environments.\n %_arr__runtimearr_uint_uint_1 "
|
||||
"= OpTypeArray %_runtimearr_uint %uint_1\n"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateMemory,
|
||||
@ -2504,9 +2505,10 @@ OpFunctionEnd
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("OpTypeArray Element Type <id> '6[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environment.\n %_arr__runtimearr_uint_uint_1 "
|
||||
"= OpTypeArray %_runtimearr_uint %uint_1\n"));
|
||||
HasSubstr(
|
||||
"OpTypeArray Element Type <id> '6[%_runtimearr_uint]' is not "
|
||||
"valid in Vulkan environments.\n %_arr__runtimearr_uint_uint_1 "
|
||||
"= OpTypeArray %_runtimearr_uint %uint_1\n"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateMemory, VulkanRTAStructInsideRTAWithRuntimeDescriptorArrayGood) {
|
||||
|
Loading…
Reference in New Issue
Block a user