pub struct CompileOptions<'a> { /* private fields */ }
Expand description
An opaque object managing options to compilation.
Implementations§
Source§impl<'a> CompileOptions<'a>
impl<'a> CompileOptions<'a>
Sourcepub fn new() -> Result<CompileOptions<'a>>
pub fn new() -> Result<CompileOptions<'a>>
Returns a default-initialized compilation options object.
The default options are:
- Target environment: Vulkan
- Source language: GLSL
Returns Err(Error::InitializationError)
if creation failed.
Sourcepub fn clone(&self) -> Result<CompileOptions<'a>>
pub fn clone(&self) -> Result<CompileOptions<'a>>
Returns a copy of the given compilation options object.
Returns Err(Error::InitializationError)
if the clone operation failed (underlying call
returned null).
Sourcepub fn set_target_env(&mut self, env: TargetEnv, version: u32)
pub fn set_target_env(&mut self, env: TargetEnv, version: u32)
Sets the target environment to env
, affecting which warnings or errors
will be issued.
The default is Vulkan if not set.
version
will be used for distinguishing between different versions
of the target environment.
For example:
let mut options = shaderc::CompileOptions::new().unwrap();
options.set_target_env(shaderc::TargetEnv::Vulkan, shaderc::EnvVersion::Vulkan1_1 as u32);
Sourcepub fn set_target_spirv(&mut self, version: SpirvVersion)
pub fn set_target_spirv(&mut self, version: SpirvVersion)
Sets the target SPIR-V version. The generated module will use this version of SPIR-V. Each target environment determines what versions of SPIR-V it can consume. Defaults to the highest version of SPIR-V 1.0 which is required to be supported by the target environment. E.g. Default to SPIR-V 1.0 for Vulkan 1.0 and SPIR-V 1.3 for Vulkan 1.1.
Sourcepub fn set_source_language(&mut self, language: SourceLanguage)
pub fn set_source_language(&mut self, language: SourceLanguage)
Sets the source language.
The default is GLSL if not set.
Sourcepub fn set_forced_version_profile(&mut self, version: u32, profile: GlslProfile)
pub fn set_forced_version_profile(&mut self, version: u32, profile: GlslProfile)
Forces the GLSL language version
and profile
.
The version number is the same as would appear in the #version
directive in the source. Version and profile specified here
overrides the #version
directive in the source code. Use
GlslProfile::None
for GLSL versions that do not define profiles,
e.g., version below 150.
Sourcepub fn set_include_callback<F>(&mut self, f: F)
pub fn set_include_callback<F>(&mut self, f: F)
Sets the callback for handling the #include
directive.
The arguments to the callback are the name of the source being requested,
the type of include directive (Relative
for #include "foo"
, Standard
for #include <foo>
),
the name of the source containing the directive and the current include depth from the original
source.
The return value of the callback should be Ok
if the source was successfully found,
and an Err
containing some suitable error message to display otherwise. If the result is
Ok
, the resolved_name
of the ResolvedInclude
must be non-empty. All strings returned
from the callback must be convertible to CString
s, i.e. they must not contain the null
character. If these conditions are not met compilation will panic.
Behaviour note: If Err
is returned for a Relative
include request, the callback will be
tried again with Standard
, which is similar to include directive behaviour in C.
Sourcepub fn set_limit(&mut self, limit: Limit, value: i32)
pub fn set_limit(&mut self, limit: Limit, value: i32)
Sets the resource limit
to the given value
.
Sourcepub fn set_auto_bind_uniforms(&mut self, auto_bind: bool)
pub fn set_auto_bind_uniforms(&mut self, auto_bind: bool)
Sets whether the compiler should automatically assign bindings to uniforms that aren’t already explicitly bound in the shader source.
Sourcepub fn set_auto_combined_image_sampler(&mut self, auto_combine: bool)
pub fn set_auto_combined_image_sampler(&mut self, auto_combine: bool)
Sets whether the compiler should automatically remove sampler variables and convert image variables to combined image-sampler variables.
Sourcepub fn set_hlsl_io_mapping(&mut self, hlsl_iomap: bool)
pub fn set_hlsl_io_mapping(&mut self, hlsl_iomap: bool)
Sets whether the compiler should use HLSL IO mapping rules for bindings.
Defaults to false.
Sourcepub fn set_hlsl_offsets(&mut self, hlsl_offsets: bool)
pub fn set_hlsl_offsets(&mut self, hlsl_offsets: bool)
Sets whether the compiler should determine block member offsets using HLSL packing rules instead of standard GLSL rules.
Defaults to false. Only affects GLSL compilation. HLSL rules are always used when compiling HLSL.
Sourcepub fn set_binding_base(&mut self, resource_kind: ResourceKind, base: u32)
pub fn set_binding_base(&mut self, resource_kind: ResourceKind, base: u32)
Sets the base binding number used for for a resource type when automatically assigning bindings.
For GLSL compilation, sets the lowest automatically assigned number. For HLSL compilation, the regsiter number assigned to the resource is added to this specified base.
Sourcepub fn set_binding_base_for_stage(
&mut self,
shader_kind: ShaderKind,
resource_kind: ResourceKind,
base: u32,
)
pub fn set_binding_base_for_stage( &mut self, shader_kind: ShaderKind, resource_kind: ResourceKind, base: u32, )
Like set_binding_base
, but only takes effect when compiling the given shader stage.
Sourcepub fn set_hlsl_register_set_and_binding(
&mut self,
register: &str,
set: &str,
binding: &str,
)
pub fn set_hlsl_register_set_and_binding( &mut self, register: &str, set: &str, binding: &str, )
Sets a descriptor set and binding for an HLSL register in all shader stages.
Sourcepub fn set_auto_map_locations(&mut self, auto_map: bool)
pub fn set_auto_map_locations(&mut self, auto_map: bool)
Automatically assigns locations to shader inputs and outputs.
Sourcepub fn set_hlsl_register_set_and_binding_for_stage(
&mut self,
kind: ShaderKind,
register: &str,
set: &str,
binding: &str,
)
pub fn set_hlsl_register_set_and_binding_for_stage( &mut self, kind: ShaderKind, register: &str, set: &str, binding: &str, )
Like set_hlsl_register_set_and_binding
, but only takes effect when compiling
the given shader stage.
Sourcepub fn set_hlsl_functionality1(&mut self, enable: bool)
pub fn set_hlsl_functionality1(&mut self, enable: bool)
Sets whether the compiler should enable extension SPV_GOOGLE_hlsl_functionality1.
Sourcepub fn set_invert_y(&mut self, enable: bool)
pub fn set_invert_y(&mut self, enable: bool)
Sets whether the compiler should invert position.Y output in a vertex shader.
Sourcepub fn set_nan_clamp(&mut self, enable: bool)
pub fn set_nan_clamp(&mut self, enable: bool)
Sets whether the compiler generates code for max and min builtins which, if given a NaN operand, will return the other operand. Similarly, the clamp builtin will favour the non-NaN operands, as if clamp were implemented as a composition of max and min.
Sourcepub fn add_macro_definition(&mut self, name: &str, value: Option<&str>)
pub fn add_macro_definition(&mut self, name: &str, value: Option<&str>)
Adds a predefined macro to the compilation options.
This has the same effect as passing -Dname=value
to the command-line
compiler. If value
is None
, it has the same effect as passing
-Dname
to the command-line compiler. If a macro definition with the
same name has previously been added, the value is replaced with the
new value.
Sourcepub fn set_optimization_level(&mut self, level: OptimizationLevel)
pub fn set_optimization_level(&mut self, level: OptimizationLevel)
Sets the optimization level to level
.
If multiple invocations for this method, only the last one takes effect.
Sourcepub fn set_generate_debug_info(&mut self)
pub fn set_generate_debug_info(&mut self)
Sets the compiler mode to generate debug information in the output.
Sourcepub fn set_suppress_warnings(&mut self)
pub fn set_suppress_warnings(&mut self)
Sets the compiler mode to suppress warnings.
This overrides warnings-as-errors mode: when both suppress-warnings and warnings-as-errors modes are turned on, warning messages will be inhibited, and will not be emitted as error messages.
Sourcepub fn set_warnings_as_errors(&mut self)
pub fn set_warnings_as_errors(&mut self)
Sets the compiler mode to treat all warnings as errors.
Note that the suppress-warnings mode overrides this.