use crate::{
device::Device, macros::vulkan_enum, Requires, RequiresAllOf, RequiresOneOf, ValidationError,
Version,
};
#[derive(Clone, Copy, Debug)]
pub struct TessellationState {
pub patch_control_points: u32,
pub domain_origin: TessellationDomainOrigin,
pub _ne: crate::NonExhaustive,
}
impl Default for TessellationState {
#[inline]
fn default() -> Self {
Self {
patch_control_points: 3,
domain_origin: TessellationDomainOrigin::default(),
_ne: crate::NonExhaustive(()),
}
}
}
impl TessellationState {
#[inline]
#[deprecated(since = "0.34.0", note = "use `TessellationState::default` instead")]
pub fn new() -> Self {
Self::default()
}
#[inline]
#[deprecated(since = "0.34.0")]
pub fn patch_control_points(mut self, num: u32) -> Self {
self.patch_control_points = num;
self
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
let &Self {
patch_control_points,
domain_origin,
_ne: _,
} = self;
let properties = device.physical_device().properties();
if patch_control_points == 0 {
return Err(Box::new(ValidationError {
context: "patch_control_points".into(),
problem: "is zero".into(),
vuids: &["VUID-VkPipelineTessellationStateCreateInfo-patchControlPoints-01214"],
..Default::default()
}));
}
if patch_control_points > properties.max_tessellation_patch_size {
return Err(Box::new(ValidationError {
context: "patch_control_points".into(),
problem: "exceeds the `max_tessellation_patch_size` limit".into(),
vuids: &["VUID-VkPipelineTessellationStateCreateInfo-patchControlPoints-01214"],
..Default::default()
}));
}
domain_origin.validate_device(device).map_err(|err| {
err.add_context("domain_origin").set_vuids(&[
"VUID-VkPipelineTessellationDomainOriginStateCreateInfo-domainOrigin-parameter",
])
})?;
if domain_origin != TessellationDomainOrigin::UpperLeft
&& !(device.api_version() >= Version::V1_1
|| device.enabled_extensions().khr_maintenance2)
{
return Err(Box::new(ValidationError {
context: "domain_origin".into(),
problem: "is not `TessellationDomainOrigin::UpperLeft`".into(),
requires_one_of: RequiresOneOf(&[
RequiresAllOf(&[Requires::APIVersion(Version::V1_2)]),
RequiresAllOf(&[Requires::DeviceExtension("khr_maintenance2")]),
]),
..Default::default()
}));
}
Ok(())
}
}
vulkan_enum! {
#[non_exhaustive]
TessellationDomainOrigin = TessellationDomainOrigin(i32);
UpperLeft = UPPER_LEFT,
LowerLeft = LOWER_LEFT,
}
impl Default for TessellationDomainOrigin {
#[inline]
fn default() -> Self {
Self::UpperLeft
}
}