spirv_tools_sys/val.rs
1use crate::shared;
2
3#[repr(C)]
4pub struct ValidatorOptions {
5 _unused: [u8; 0],
6}
7
8#[derive(Copy, Clone, Debug)]
9#[repr(C)]
10pub enum ValidatorLimits {
11 StructMembers,
12 StructDepth,
13 LocalVariables,
14 GlobalVariables,
15 SwitchBranches,
16 FunctionArgs,
17 ControlFlowNestingDepth,
18 AccessChainIndexes,
19 IdBound,
20}
21
22extern "C" {
23 /// Validates a SPIR-V binary for correctness. Any errors will be written into
24 /// *diagnostic if diagnostic is non-null, otherwise the context's message
25 /// consumer will be used.
26 ///
27 /// Validate for SPIR-V spec rules for the SPIR-V version named in the
28 /// binary's header (at word offset 1). Additionally, if the context target
29 /// environment is a client API (such as Vulkan 1.1), then validate for that
30 /// client API version, to the extent that it is verifiable from data in the
31 /// binary itself.
32 #[link_name = "spvValidate"]
33 pub fn validate(
34 tool: *const shared::ToolContext,
35 binary: *const shared::Binary,
36 diagnostic: *mut *mut crate::diagnostics::Diagnostic,
37 ) -> crate::shared::SpirvResult;
38
39 /// Validates a SPIR-V binary for correctness. Uses the provided Validator
40 /// options. Any errors will be written into *diagnostic if diagnostic is
41 /// non-null, otherwise the context's message consumer will be used.
42 ///
43 /// Validate for SPIR-V spec rules for the SPIR-V version named in the
44 /// binary's header (at word offset 1). Additionally, if the context target
45 /// environment is a client API (such as Vulkan 1.1), then validate for that
46 /// client API version, to the extent that it is verifiable from data in the
47 /// binary itself, or in the validator options.
48 #[link_name = "spvValidateWithOptions"]
49 pub fn validate_with_options(
50 tool: *const shared::ToolContext,
51 options: *const ValidatorOptions,
52 binary: *const shared::Binary,
53 diagnostic: *mut *mut crate::diagnostics::Diagnostic,
54 ) -> crate::shared::SpirvResult;
55
56 /// Creates a Validator options object with default options. Returns a valid
57 /// options object. The object remains valid until it is passed into
58 /// spvValidatorOptionsDestroy.
59 #[link_name = "spvValidatorOptionsCreate"]
60 pub fn validator_options_create() -> *mut ValidatorOptions;
61
62 /// Destroys the given Validator options object.
63 #[link_name = "spvValidatorOptionsDestroy"]
64 pub fn validator_options_destroy(opts: *mut ValidatorOptions);
65
66 /// Records the maximum Universal Limit that is considered valid in the given
67 /// Validator options object. <options> argument must be a valid options object.
68 #[link_name = "spvValidatorOptionsSetUniversalLimit"]
69 pub fn validator_options_set_limit(
70 opts: *mut ValidatorOptions,
71 limit_type: ValidatorLimits,
72 limit: u32,
73 );
74
75 /// Record whether or not the validator should relax the rules on types for
76 /// stores to structs. When relaxed, it will allow a type mismatch as long as
77 /// the types are structs with the same layout. Two structs have the same layout
78 /// if
79 ///
80 /// 1) the members of the structs are either the same type or are structs with
81 /// same layout, and
82 ///
83 /// 2) the decorations that affect the memory layout are identical for both
84 /// types. Other decorations are not relevant.
85 #[link_name = "spvValidatorOptionsSetRelaxStoreStruct"]
86 pub fn validator_options_set_relax_store_struct(opts: *mut ValidatorOptions, toggle: bool);
87
88 /// Records whether or not the validator should relax the rules on pointer usage
89 /// in logical addressing mode.
90 ///
91 /// When relaxed, it will allow the following usage cases of pointers:
92 /// 1) OpVariable allocating an object whose type is a pointer type
93 /// 2) OpReturnValue returning a pointer value
94 #[link_name = "spvValidatorOptionsSetRelaxLogicalPointer"]
95 pub fn validator_options_set_relax_logical_pointer(opts: *mut ValidatorOptions, toggle: bool);
96
97 /// Records whether or not the validator should relax the rules because it is
98 /// expected that the optimizations will make the code legal.
99 ///
100 /// When relaxed, it will allow the following:
101 /// 1) It will allow relaxed logical pointers. Setting this option will also
102 /// set that option.
103 /// 2) Pointers that are pass as parameters to function calls do not have to
104 /// match the storage class of the formal parameter.
105 /// 3) Pointers that are actaul parameters on function calls do not have to point
106 /// to the same type pointed as the formal parameter. The types just need to
107 /// logically match.
108 #[link_name = "spvValidatorOptionsSetBeforeHlslLegalization"]
109 pub fn validator_options_set_before_legalization(opts: *mut ValidatorOptions, toggle: bool);
110
111 /// Records whether the validator should use "relaxed" block layout rules.
112 /// Relaxed layout rules are described by Vulkan extension
113 /// VK_KHR_relaxed_block_layout, and they affect uniform blocks, storage blocks,
114 /// and push constants.
115 ///
116 /// This is enabled by default when targeting Vulkan 1.1 or later.
117 /// Relaxed layout is more permissive than the default rules in Vulkan 1.0.
118 #[link_name = "spvValidatorOptionsSetRelaxBlockLayout"]
119 pub fn validator_options_set_relax_block_layout(opts: *mut ValidatorOptions, toggle: bool);
120
121 /// Records whether the validator should use standard block layout rules for
122 /// uniform blocks.
123 #[link_name = "spvValidatorOptionsSetUniformBufferStandardLayout"]
124 pub fn validator_options_set_uniform_buffer_standard_layout(
125 opts: *mut ValidatorOptions,
126 toggle: bool,
127 );
128
129 /// Records whether the validator should use "scalar" block layout rules.
130 /// Scalar layout rules are more permissive than relaxed block layout.
131 ///
132 /// See Vulkan extnesion VK_EXT_scalar_block_layout. The scalar alignment is
133 /// defined as follows:
134 /// - scalar alignment of a scalar is the scalar size
135 /// - scalar alignment of a vector is the scalar alignment of its component
136 /// - scalar alignment of a matrix is the scalar alignment of its component
137 /// - scalar alignment of an array is the scalar alignment of its element
138 /// - scalar alignment of a struct is the max scalar alignment among its
139 /// members
140 ///
141 /// For a struct in Uniform, StorageClass, or PushConstant:
142 /// - a member Offset must be a multiple of the member's scalar alignment
143 /// - ArrayStride or MatrixStride must be a multiple of the array or matrix
144 /// scalar alignment
145 #[link_name = "spvValidatorOptionsSetScalarBlockLayout"]
146 pub fn validator_options_set_scalar_block_layout(opts: *mut ValidatorOptions, toggle: bool);
147
148 /// Records whether or not the validator should skip validating standard
149 /// uniform/storage block layout.
150 #[link_name = "spvValidatorOptionsSetSkipBlockLayout"]
151 pub fn validator_options_set_skip_block_layout(opts: *mut ValidatorOptions, toggle: bool);
152}