Use max enum instead of static array of legal values (#4571)

This commit is contained in:
Ryan Harrison 2021-10-13 17:53:11 -04:00 committed by GitHub
parent 0292d6b16a
commit d31218c560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 17 deletions

View File

@ -87,23 +87,15 @@ RandomGenerator::RandomGenerator(const uint8_t* data, size_t size) {
}
spv_target_env RandomGenerator::GetTargetEnv() {
// SPV_ENV_WEBGPU_0 is intentionally omitted here, since it is deprecated and
// using it will cause asserts.
static const std::array<spv_target_env, 23> envs = {
SPV_ENV_UNIVERSAL_1_0, SPV_ENV_VULKAN_1_0,
SPV_ENV_UNIVERSAL_1_1, SPV_ENV_UNIVERSAL_1_2,
SPV_ENV_UNIVERSAL_1_3, SPV_ENV_VULKAN_1_1,
SPV_ENV_OPENCL_1_2, SPV_ENV_OPENCL_EMBEDDED_1_2,
SPV_ENV_OPENCL_2_0, SPV_ENV_OPENCL_EMBEDDED_2_0,
SPV_ENV_OPENCL_EMBEDDED_2_1, SPV_ENV_OPENCL_EMBEDDED_2_2,
SPV_ENV_OPENCL_2_1, SPV_ENV_OPENCL_2_2,
SPV_ENV_UNIVERSAL_1_4, SPV_ENV_VULKAN_1_1_SPIRV_1_4,
SPV_ENV_UNIVERSAL_1_5, SPV_ENV_VULKAN_1_2,
SPV_ENV_OPENGL_4_0, SPV_ENV_OPENGL_4_1,
SPV_ENV_OPENGL_4_2, SPV_ENV_OPENGL_4_3,
SPV_ENV_OPENGL_4_5};
spv_target_env result;
return envs[RandomUInt(&engine_, 0lu, envs.size())];
// Need to check that the generated value isn't for a deprecated target env.
do {
result = static_cast<spv_target_env>(
RandomUInt(&engine_, 0u, static_cast<unsigned int>(SPV_ENV_MAX)));
} while (!spvIsValidEnv(result));
return result;
}
uint64_t RandomGenerator::CalculateSeed(const uint8_t* data, size_t size) {

View File

@ -44,7 +44,7 @@ class RandomGenerator {
/// @param size - number of elements in |data|, must be > 0
static uint64_t CalculateSeed(const uint8_t* data, size_t size);
/// Get random target env.
/// Get random valid target env.
spv_target_env GetTargetEnv();
private: