Skip to content

Commit

Permalink
Include a maximum value for spv_target_env (KhronosGroup#4559)
Browse files Browse the repository at this point in the history
To allow querying the range of target environments (to ensure that a
target environment value is within the valid range of the associated
enum), this change adds a maximum value to the spv_target_env
enumeration.
  • Loading branch information
afd authored Oct 6, 2021
1 parent 63a3912 commit 0c4deeb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ typedef enum {

SPV_ENV_UNIVERSAL_1_5, // SPIR-V 1.5 latest revision, no other restrictions.
SPV_ENV_VULKAN_1_2, // Vulkan 1.2 latest revision.
SPV_ENV_MAX // Keep this as the last enum value.
} spv_target_env;

// SPIR-V Validator can be parameterized with the following Universal Limits.
Expand Down
31 changes: 25 additions & 6 deletions source/spirv_target_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const char* spvTargetEnvDescription(spv_target_env env) {
case SPV_ENV_VULKAN_1_1:
return "SPIR-V 1.3 (under Vulkan 1.1 semantics)";
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_UNIVERSAL_1_4:
return "SPIR-V 1.4";
Expand All @@ -72,6 +72,9 @@ const char* spvTargetEnvDescription(spv_target_env env) {
return "SPIR-V 1.5";
case SPV_ENV_VULKAN_1_2:
return "SPIR-V 1.5 (under Vulkan 1.2 semantics)";
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return "";
}
Expand Down Expand Up @@ -102,14 +105,17 @@ uint32_t spvVersionForTargetEnv(spv_target_env env) {
case SPV_ENV_VULKAN_1_1:
return SPV_SPIRV_VERSION_WORD(1, 3);
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_UNIVERSAL_1_4:
case SPV_ENV_VULKAN_1_1_SPIRV_1_4:
return SPV_SPIRV_VERSION_WORD(1, 4);
case SPV_ENV_UNIVERSAL_1_5:
case SPV_ENV_VULKAN_1_2:
return SPV_SPIRV_VERSION_WORD(1, 5);
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return SPV_SPIRV_VERSION_WORD(0, 0);
}
Expand Down Expand Up @@ -212,7 +218,10 @@ bool spvIsVulkanEnv(spv_target_env env) {
case SPV_ENV_VULKAN_1_2:
return true;
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return false;
Expand Down Expand Up @@ -246,7 +255,10 @@ bool spvIsOpenCLEnv(spv_target_env env) {
case SPV_ENV_OPENCL_2_2:
return true;
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return false;
Expand Down Expand Up @@ -280,7 +292,10 @@ bool spvIsOpenGLEnv(spv_target_env env) {
case SPV_ENV_OPENGL_4_5:
return true;
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return false;
Expand Down Expand Up @@ -313,6 +328,7 @@ bool spvIsValidEnv(spv_target_env env) {
case SPV_ENV_OPENGL_4_5:
return true;
case SPV_ENV_WEBGPU_0:
case SPV_ENV_MAX:
break;
}
return false;
Expand Down Expand Up @@ -352,7 +368,10 @@ std::string spvLogStringForEnv(spv_target_env env) {
return "Universal";
}
case SPV_ENV_WEBGPU_0:
assert(false);
assert(false && "Deprecated target environment value.");
break;
case SPV_ENV_MAX:
assert(false && "Invalid target environment value.");
break;
}
return "Unknown";
Expand Down

0 comments on commit 0c4deeb

Please sign in to comment.