spirv-val: Add an option to use friendly names or not (#4951)

The always-friendly messages make it harder to debug when the
disassembly is later generated without friendly names.

Additionally, the friendly-name-mapper is slow.  Disabling it improves
performance of an ANGLE test that creates numerous shaders by ~5%.
This commit is contained in:
Shahbaz Youssefi 2022-09-30 12:22:00 -04:00 committed by GitHub
parent 3ec6b3698e
commit 07d361b675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1016 additions and 797 deletions

View File

@ -670,6 +670,10 @@ SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetSkipBlockLayout(
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowLocalSizeId(
spv_validator_options options, bool val);
// Whether friendly names should be used in validation error messages.
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetFriendlyNames(
spv_validator_options options, bool val);
// Creates an optimizer options object with default options. Returns a valid
// options object. The object remains valid until it is passed into
// |spvOptimizerOptionsDestroy|.

View File

@ -148,6 +148,11 @@ class ValidatorOptions {
spvValidatorOptionsSetBeforeHlslLegalization(options_, val);
}
// Whether friendly names should be used in validation error messages.
void SetFriendlyNames(bool val) {
spvValidatorOptionsSetFriendlyNames(options_, val);
}
private:
spv_validator_options options_;
};

View File

@ -125,3 +125,8 @@ void spvValidatorOptionsSetAllowLocalSizeId(spv_validator_options options,
bool val) {
options->allow_localsizeid = val;
}
void spvValidatorOptionsSetFriendlyNames(spv_validator_options options,
bool val) {
options->use_friendly_names = val;
}

View File

@ -48,7 +48,8 @@ struct spv_validator_options_t {
workgroup_scalar_block_layout(false),
skip_block_layout(false),
allow_localsizeid(false),
before_hlsl_legalization(false) {}
before_hlsl_legalization(false),
use_friendly_names(true) {}
validator_universal_limits_t universal_limits_;
bool relax_struct_store;
@ -60,6 +61,7 @@ struct spv_validator_options_t {
bool skip_block_layout;
bool allow_localsizeid;
bool before_hlsl_legalization;
bool use_friendly_names;
};
#endif // SOURCE_SPIRV_VALIDATOR_OPTIONS_H_

View File

@ -208,9 +208,12 @@ ValidationState_t::ValidationState_t(const spv_const_context ctx,
}
UpdateFeaturesBasedOnSpirvVersion(&features_, version_);
friendly_mapper_ = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
context_, words_, num_words_);
name_mapper_ = friendly_mapper_->GetNameMapper();
name_mapper_ = spvtools::GetTrivialNameMapper();
if (options_->use_friendly_names) {
friendly_mapper_ = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
context_, words_, num_words_);
name_mapper_ = friendly_mapper_->GetNameMapper();
}
}
void ValidationState_t::preallocateStorage() {

File diff suppressed because it is too large Load Diff