1 // Copyright (c) 2017 Google Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "source/spirv_validator_options.h"
20 bool spvParseUniversalLimitsOptions(const char* s
, spv_validator_limit
* type
) {
21 auto match
= [s
](const char* b
) {
22 return s
&& (0 == strncmp(s
, b
, strlen(b
)));
24 if (match("--max-struct-members")) {
25 *type
= spv_validator_limit_max_struct_members
;
26 } else if (match("--max-struct_depth")) {
27 *type
= spv_validator_limit_max_struct_depth
;
28 } else if (match("--max-local-variables")) {
29 *type
= spv_validator_limit_max_local_variables
;
30 } else if (match("--max-global-variables")) {
31 *type
= spv_validator_limit_max_global_variables
;
32 } else if (match("--max-switch-branches")) {
33 *type
= spv_validator_limit_max_global_variables
;
34 } else if (match("--max-function-args")) {
35 *type
= spv_validator_limit_max_function_args
;
36 } else if (match("--max-control-flow-nesting-depth")) {
37 *type
= spv_validator_limit_max_control_flow_nesting_depth
;
38 } else if (match("--max-access-chain-indexes")) {
39 *type
= spv_validator_limit_max_access_chain_indexes
;
40 } else if (match("--max-id-bound")) {
41 *type
= spv_validator_limit_max_id_bound
;
43 // The command line option for this validator limit has not been added.
44 // Therefore we return false.
51 spv_validator_options
spvValidatorOptionsCreate(void) {
52 return new spv_validator_options_t
;
55 void spvValidatorOptionsDestroy(spv_validator_options options
) {
59 void spvValidatorOptionsSetUniversalLimit(spv_validator_options options
,
60 spv_validator_limit limit_type
,
62 assert(options
&& "Validator options object may not be Null");
64 #define LIMIT(TYPE, FIELD) \
66 options->universal_limits_.FIELD = limit; \
68 LIMIT(spv_validator_limit_max_struct_members
, max_struct_members
)
69 LIMIT(spv_validator_limit_max_struct_depth
, max_struct_depth
)
70 LIMIT(spv_validator_limit_max_local_variables
, max_local_variables
)
71 LIMIT(spv_validator_limit_max_global_variables
, max_global_variables
)
72 LIMIT(spv_validator_limit_max_switch_branches
, max_switch_branches
)
73 LIMIT(spv_validator_limit_max_function_args
, max_function_args
)
74 LIMIT(spv_validator_limit_max_control_flow_nesting_depth
,
75 max_control_flow_nesting_depth
)
76 LIMIT(spv_validator_limit_max_access_chain_indexes
,
77 max_access_chain_indexes
)
78 LIMIT(spv_validator_limit_max_id_bound
, max_id_bound
)
83 void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options
,
85 options
->relax_struct_store
= val
;
88 void spvValidatorOptionsSetRelaxLogicalPointer(spv_validator_options options
,
90 options
->relax_logical_pointer
= val
;
93 void spvValidatorOptionsSetBeforeHlslLegalization(spv_validator_options options
,
95 options
->before_hlsl_legalization
= val
;
96 options
->relax_logical_pointer
= val
;
99 void spvValidatorOptionsSetRelaxBlockLayout(spv_validator_options options
,
101 options
->relax_block_layout
= val
;
104 void spvValidatorOptionsSetUniformBufferStandardLayout(
105 spv_validator_options options
, bool val
) {
106 options
->uniform_buffer_standard_layout
= val
;
109 void spvValidatorOptionsSetScalarBlockLayout(spv_validator_options options
,
111 options
->scalar_block_layout
= val
;
114 void spvValidatorOptionsSetWorkgroupScalarBlockLayout(spv_validator_options options
,
116 options
->workgroup_scalar_block_layout
= val
;
119 void spvValidatorOptionsSetSkipBlockLayout(spv_validator_options options
,
121 options
->skip_block_layout
= val
;
124 void spvValidatorOptionsSetAllowLocalSizeId(spv_validator_options options
,
126 options
->allow_localsizeid
= val
;
129 void spvValidatorOptionsSetFriendlyNames(spv_validator_options options
,
131 options
->use_friendly_names
= val
;