1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
// Copyright (c) 2016 The vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
//! Configures how the color output of the fragment shader is written to the attachment.
//!
//! # Blending in details
//!
//! There are three kinds of color attachments for the purpose of blending:
//!
//! - Attachments with a floating-point or fixed point format.
//! - Attachments with a (non-normalized) integer format.
//! - Attachments with a normalized integer format.
//!
//! For floating-point and fixed-point formats, the blending operation is applied. For integer
//! formats, the logic operation is applied. For normalized integer formats, the logic operation
//! will take precedence if it is activated, otherwise the blending operation is applied.
use crate::{
device::Device,
macros::{vulkan_bitflags, vulkan_enum},
Requires, RequiresAllOf, RequiresOneOf, ValidationError,
};
use std::iter;
/// Describes how the color output of the fragment shader is written to the attachment. See the
/// documentation of the `blend` module for more info.
#[derive(Clone, Debug)]
pub struct ColorBlendState {
/// Additional properties of the color blend state.
///
/// The default value is empty.
pub flags: ColorBlendStateFlags,
/// Sets the logical operation to perform between the incoming fragment color and the existing
/// fragment in the framebuffer attachment.
///
/// If set to `Some`, the [`logic_op`](crate::device::Features::logic_op) feature must be
/// enabled on the device.
///
/// The default value is `None`.
pub logic_op: Option<LogicOp>,
/// Sets the blend and output state for each color attachment. The number of elements must match
/// the number of color attachments in the subpass.
///
/// If there are multiple elements, and the `blend` and `color_write_mask` members of each
/// element differ, then the [`independent_blend`](crate::device::Features::independent_blend)
/// feature must be enabled on the device.
///
/// The default value is empty,
/// which must be overridden if the subpass has color attachments.
pub attachments: Vec<ColorBlendAttachmentState>,
/// The constant color to use for some of the `BlendFactor` variants.
///
/// The default value is `[0.0; 4]`.
pub blend_constants: [f32; 4],
pub _ne: crate::NonExhaustive,
}
impl Default for ColorBlendState {
/// Returns [`ColorBlendState::new(1)`].
#[inline]
fn default() -> Self {
Self {
flags: ColorBlendStateFlags::empty(),
logic_op: None,
attachments: Vec::new(),
blend_constants: [0.0; 4],
_ne: crate::NonExhaustive(()),
}
}
}
impl ColorBlendState {
/// Returns a default `ColorBlendState` with `count` duplicates of `attachment_state`.
#[inline]
pub fn with_attachment_states(count: u32, attachment_state: ColorBlendAttachmentState) -> Self {
Self {
attachments: iter::repeat(attachment_state)
.take(count as usize)
.collect(),
..Default::default()
}
}
/// Creates a `ColorBlendState` with logical operations disabled, blend constants set to zero,
/// and `num` attachment entries that have blending disabled, and color write and all color
/// components enabled.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn new(num: u32) -> Self {
Self {
flags: ColorBlendStateFlags::empty(),
logic_op: None,
attachments: (0..num)
.map(|_| ColorBlendAttachmentState::default())
.collect(),
blend_constants: [0.0; 4],
_ne: crate::NonExhaustive(()),
}
}
/// Enables logical operations with the given logical operation.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn logic_op(mut self, logic_op: LogicOp) -> Self {
self.logic_op = Some(logic_op);
self
}
/// Enables blending for all attachments, with the given parameters.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn blend(mut self, blend: AttachmentBlend) -> Self {
self.attachments
.iter_mut()
.for_each(|attachment_state| attachment_state.blend = Some(blend));
self
}
/// Enables blending for all attachments, with alpha blending.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn blend_alpha(mut self) -> Self {
self.attachments
.iter_mut()
.for_each(|attachment_state| attachment_state.blend = Some(AttachmentBlend::alpha()));
self
}
/// Enables blending for all attachments, with additive blending.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn blend_additive(mut self) -> Self {
self.attachments.iter_mut().for_each(|attachment_state| {
attachment_state.blend = Some(AttachmentBlend::additive())
});
self
}
/// Sets the color write mask for all attachments.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn color_write_mask(mut self, color_write_mask: ColorComponents) -> Self {
self.attachments
.iter_mut()
.for_each(|attachment_state| attachment_state.color_write_mask = color_write_mask);
self
}
/// Sets the blend constants.
#[inline]
#[deprecated(since = "0.34.0")]
pub fn blend_constants(mut self, constants: [f32; 4]) -> Self {
self.blend_constants = constants;
self
}
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
let &Self {
flags,
logic_op,
ref attachments,
blend_constants: _,
_ne: _,
} = self;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkPipelineColorBlendStateCreateInfo-flags-parameter"])
})?;
if let Some(logic_op) = logic_op {
if !device.enabled_features().logic_op {
return Err(Box::new(ValidationError {
context: "logic_op".into(),
problem: "is `Some`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"logic_op",
)])]),
vuids: &["VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00606"],
}));
}
logic_op.validate_device(device).map_err(|err| {
err.add_context("logic_op")
.set_vuids(&["VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00607"])
})?;
}
if device.enabled_features().independent_blend {
for (index, state) in attachments.iter().enumerate() {
state
.validate(device)
.map_err(|err| err.add_context(format!("attachments[{}]", index)))?;
}
} else if let Some(first) = attachments.first() {
first
.validate(device)
.map_err(|err| err.add_context("attachments[0]"))?;
for (index, state) in attachments.iter().enumerate().skip(1) {
if state != first {
return Err(Box::new(ValidationError {
problem: format!(
"`attachments[{}]` does not equal `attachments[0]`",
index
)
.into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"independent_blend",
)])]),
vuids: &["VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605"],
..Default::default()
}));
}
}
}
Ok(())
}
}
vulkan_bitflags! {
#[non_exhaustive]
/// Flags specifying additional properties of the color blend state.
ColorBlendStateFlags = PipelineColorBlendStateCreateFlags(u32);
/* TODO: enable
// TODO: document
RASTERIZATION_ORDER_ATTACHMENT_ACCESS = RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_rasterization_order_attachment_access)]),
RequiresAllOf([DeviceExtension(arm_rasterization_order_attachment_access)]),
]), */
}
vulkan_enum! {
#[non_exhaustive]
/// Which logical operation to apply to the output values.
///
/// The operation is applied individually for each channel (red, green, blue and alpha).
///
/// Only relevant for integer or unsigned attachments.
///
/// Also note that some implementations don't support logic operations.
LogicOp = LogicOp(i32);
/// Returns `0`.
Clear = CLEAR,
/// Returns `source & destination`.
And = AND,
/// Returns `source & !destination`.
AndReverse = AND_REVERSE,
/// Returns `source`.
Copy = COPY,
/// Returns `!source & destination`.
AndInverted = AND_INVERTED,
/// Returns `destination`.
Noop = NO_OP,
/// Returns `source ^ destination`.
Xor = XOR,
/// Returns `source | destination`.
Or = OR,
/// Returns `!(source | destination)`.
Nor = NOR,
/// Returns `!(source ^ destination)`.
Equivalent = EQUIVALENT,
/// Returns `!destination`.
Invert = INVERT,
/// Returns `source | !destination.
OrReverse = OR_REVERSE,
/// Returns `!source`.
CopyInverted = COPY_INVERTED,
/// Returns `!source | destination`.
OrInverted = OR_INVERTED,
/// Returns `!(source & destination)`.
Nand = NAND,
/// Returns `!0` (all bits set to 1).
Set = SET,
}
impl Default for LogicOp {
#[inline]
fn default() -> LogicOp {
LogicOp::Noop
}
}
/// Describes how a framebuffer color attachment is handled in the pipeline during the color
/// blend stage.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ColorBlendAttachmentState {
/// The blend parameters for the attachment.
///
/// If set to `None`, blending is disabled, and all incoming pixels will be used directly.
///
/// The default value is `None`.
pub blend: Option<AttachmentBlend>,
/// Sets which components of the final pixel value are written to the attachment.
///
/// The default value is `ColorComponents::all()`.
pub color_write_mask: ColorComponents,
/// Sets whether anything at all is written to the attachment. If enabled, the pixel data
/// that is written is determined by the `color_write_mask`. If disabled, the mask is ignored
/// and nothing is written.
///
/// If set to anything other than `Fixed(true)`, the
/// [`color_write_enable`](crate::device::Features::color_write_enable) feature must be enabled
/// on the device.
///
/// The default value is `true`.
pub color_write_enable: bool,
}
impl Default for ColorBlendAttachmentState {
#[inline]
fn default() -> Self {
Self {
blend: None,
color_write_mask: ColorComponents::all(),
color_write_enable: true,
}
}
}
impl ColorBlendAttachmentState {
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
let &Self {
ref blend,
color_write_mask: _,
color_write_enable,
} = self;
if let Some(blend) = blend {
blend
.validate(device)
.map_err(|err| err.add_context("blend"))?;
}
if !color_write_enable && !device.enabled_features().color_write_enable {
return Err(Box::new(ValidationError {
context: "color_write_enable".into(),
problem: "is `false`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"color_write_enable",
)])]),
vuids: &["VUID-VkPipelineColorWriteCreateInfoEXT-pAttachments-04801"],
}));
}
Ok(())
}
}
/// Describes how the blending system should behave for an attachment.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AttachmentBlend {
/// The operation to apply to the source color component before applying `color_op`.
///
/// The default value is [`BlendFactor::SrcColor`].
pub src_color_blend_factor: BlendFactor,
/// The operation to apply to the destination color component before applying `color_op`.
///
/// The default value is [`BlendFactor::Zero`].
pub dst_color_blend_factor: BlendFactor,
/// The operation to apply between the color components of the source and destination pixels,
/// to produce the final pixel value.
///
/// The default value is [`BlendOp::Add`].
pub color_blend_op: BlendOp,
/// The operation to apply to the source alpha component before applying `alpha_op`.
///
/// The default value is [`BlendFactor::SrcColor`].
pub src_alpha_blend_factor: BlendFactor,
/// The operation to apply to the destination alpha component before applying `alpha_op`.
///
/// The default value is [`BlendFactor::Zero`].
pub dst_alpha_blend_factor: BlendFactor,
/// The operation to apply between the alpha component of the source and destination pixels,
/// to produce the final pixel value.
///
/// The default value is [`BlendOp::Add`].
pub alpha_blend_op: BlendOp,
}
impl Default for AttachmentBlend {
#[inline]
fn default() -> Self {
Self {
src_color_blend_factor: BlendFactor::SrcColor,
dst_color_blend_factor: BlendFactor::Zero,
color_blend_op: BlendOp::Add,
src_alpha_blend_factor: BlendFactor::SrcColor,
dst_alpha_blend_factor: BlendFactor::Zero,
alpha_blend_op: BlendOp::Add,
}
}
}
impl AttachmentBlend {
/// Builds an `AttachmentBlend` where the output of the fragment shader is ignored and the
/// destination is untouched.
#[inline]
pub fn ignore_source() -> Self {
Self {
src_color_blend_factor: BlendFactor::Zero,
dst_color_blend_factor: BlendFactor::DstColor,
color_blend_op: BlendOp::Add,
src_alpha_blend_factor: BlendFactor::Zero,
dst_alpha_blend_factor: BlendFactor::DstColor,
alpha_blend_op: BlendOp::Add,
}
}
/// Builds an `AttachmentBlend` where the output will be merged with the existing value
/// based on the alpha of the source.
#[inline]
pub fn alpha() -> Self {
Self {
src_color_blend_factor: BlendFactor::SrcAlpha,
dst_color_blend_factor: BlendFactor::OneMinusSrcAlpha,
color_blend_op: BlendOp::Add,
src_alpha_blend_factor: BlendFactor::SrcAlpha,
dst_alpha_blend_factor: BlendFactor::OneMinusSrcAlpha,
alpha_blend_op: BlendOp::Add,
}
}
/// Builds an `AttachmentBlend` where the colors are added, and alpha is set to the maximum of
/// the two.
#[inline]
pub fn additive() -> Self {
Self {
src_color_blend_factor: BlendFactor::One,
dst_color_blend_factor: BlendFactor::One,
color_blend_op: BlendOp::Add,
src_alpha_blend_factor: BlendFactor::One,
dst_alpha_blend_factor: BlendFactor::One,
alpha_blend_op: BlendOp::Max,
}
}
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
let &Self {
src_color_blend_factor,
dst_color_blend_factor,
color_blend_op,
src_alpha_blend_factor,
dst_alpha_blend_factor,
alpha_blend_op,
} = self;
src_color_blend_factor
.validate_device(device)
.map_err(|err| {
err.add_context("src_color_blend_factor").set_vuids(&[
"VUID-VkPipelineColorBlendAttachmentState-srcColorBlendFactor-parameter",
])
})?;
dst_color_blend_factor
.validate_device(device)
.map_err(|err| {
err.add_context("dst_color_blend_factor").set_vuids(&[
"VUID-VkPipelineColorBlendAttachmentState-dstColorBlendFactor-parameter",
])
})?;
color_blend_op.validate_device(device).map_err(|err| {
err.add_context("color_blend_op")
.set_vuids(&["VUID-VkPipelineColorBlendAttachmentState-colorBlendOp-parameter"])
})?;
src_alpha_blend_factor
.validate_device(device)
.map_err(|err| {
err.add_context("src_alpha_blend_factor").set_vuids(&[
"VUID-VkPipelineColorBlendAttachmentState-srcAlphaBlendFactor-parameter",
])
})?;
dst_alpha_blend_factor
.validate_device(device)
.map_err(|err| {
err.add_context("dst_alpha_blend_factor").set_vuids(&[
"VUID-VkPipelineColorBlendAttachmentState-dstAlphaBlendFactor-parameter",
])
})?;
alpha_blend_op.validate_device(device).map_err(|err| {
err.add_context("alpha_blend_op")
.set_vuids(&["VUID-VkPipelineColorBlendAttachmentState-alphaBlendOp-parameter"])
})?;
if !device.enabled_features().dual_src_blend {
if matches!(
src_color_blend_factor,
BlendFactor::Src1Color
| BlendFactor::OneMinusSrc1Color
| BlendFactor::Src1Alpha
| BlendFactor::OneMinusSrc1Alpha
) {
return Err(Box::new(ValidationError {
context: "src_color_blend_factor".into(),
problem: "is `BlendFactor::Src1*`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"dual_src_blend",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-srcColorBlendFactor-00608"],
}));
}
if matches!(
dst_color_blend_factor,
BlendFactor::Src1Color
| BlendFactor::OneMinusSrc1Color
| BlendFactor::Src1Alpha
| BlendFactor::OneMinusSrc1Alpha
) {
return Err(Box::new(ValidationError {
context: "dst_color_blend_factor".into(),
problem: "is `BlendFactor::Src1*`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"dual_src_blend",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-dstColorBlendFactor-00609"],
}));
}
if matches!(
src_alpha_blend_factor,
BlendFactor::Src1Color
| BlendFactor::OneMinusSrc1Color
| BlendFactor::Src1Alpha
| BlendFactor::OneMinusSrc1Alpha
) {
return Err(Box::new(ValidationError {
context: "src_alpha_blend_factor".into(),
problem: "is `BlendFactor::Src1*`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"dual_src_blend",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-srcAlphaBlendFactor-00610"],
}));
}
if matches!(
dst_alpha_blend_factor,
BlendFactor::Src1Color
| BlendFactor::OneMinusSrc1Color
| BlendFactor::Src1Alpha
| BlendFactor::OneMinusSrc1Alpha
) {
return Err(Box::new(ValidationError {
context: "dst_alpha_blend_factor".into(),
problem: "is `BlendFactor::Src1*`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"dual_src_blend",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-dstAlphaBlendFactor-00611"],
}));
}
}
if device.enabled_extensions().khr_portability_subset
&& !device.enabled_features().constant_alpha_color_blend_factors
{
if matches!(
src_color_blend_factor,
BlendFactor::ConstantAlpha | BlendFactor::OneMinusConstantAlpha
) {
return Err(Box::new(ValidationError {
problem: "this device is a portability subset device, and \
`src_color_blend_factor` is `BlendFactor::ConstantAlpha` or \
`BlendFactor::OneMinusConstantAlpha`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"constant_alpha_color_blend_factors",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-constantAlphaColorBlendFactors-04454"],
..Default::default()
}));
}
if matches!(
dst_color_blend_factor,
BlendFactor::ConstantAlpha | BlendFactor::OneMinusConstantAlpha
) {
return Err(Box::new(ValidationError {
problem: "this device is a portability subset device, and \
`dst_color_blend_factor` is `BlendFactor::ConstantAlpha` or \
`BlendFactor::OneMinusConstantAlpha`".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"constant_alpha_color_blend_factors",
)])]),
vuids: &["VUID-VkPipelineColorBlendAttachmentState-constantAlphaColorBlendFactors-04455"],
..Default::default()
}));
}
}
Ok(())
}
}
impl From<AttachmentBlend> for ash::vk::PipelineColorBlendAttachmentState {
#[inline]
fn from(val: AttachmentBlend) -> Self {
ash::vk::PipelineColorBlendAttachmentState {
blend_enable: ash::vk::TRUE,
src_color_blend_factor: val.src_color_blend_factor.into(),
dst_color_blend_factor: val.dst_color_blend_factor.into(),
color_blend_op: val.color_blend_op.into(),
src_alpha_blend_factor: val.src_alpha_blend_factor.into(),
dst_alpha_blend_factor: val.dst_alpha_blend_factor.into(),
alpha_blend_op: val.alpha_blend_op.into(),
color_write_mask: ash::vk::ColorComponentFlags::empty(),
}
}
}
vulkan_enum! {
#[non_exhaustive]
/// The operation that takes `source` (output from the fragment shader), `destination` (value
/// currently in the framebuffer attachment) and `blend_constant` input values,
/// and produces new inputs to be fed to `BlendOp`.
///
/// Some operations take `source1` as an input, representing the second source value. The
/// [`dual_src_blend`](crate::device::Features::dual_src_blend) feature must be enabled on the
/// device when these are used.
BlendFactor = BlendFactor(i32);
/// Always `0`.
Zero = ZERO,
/// Always `1`.
One = ONE,
/// `source` component-wise.
SrcColor = SRC_COLOR,
/// `1 - source` component-wise.
OneMinusSrcColor = ONE_MINUS_SRC_COLOR,
/// `destination` component-wise.
DstColor = DST_COLOR,
/// `1 - destination` component-wise.
OneMinusDstColor = ONE_MINUS_DST_COLOR,
/// `source.a` for all components.
SrcAlpha = SRC_ALPHA,
/// `1 - source.a` for all components.
OneMinusSrcAlpha = ONE_MINUS_SRC_ALPHA,
/// `destination.a` for all components.
DstAlpha = DST_ALPHA,
/// `1 - destination.a` for all components.
OneMinusDstAlpha = ONE_MINUS_DST_ALPHA,
/// `blend_constants` component-wise.
ConstantColor = CONSTANT_COLOR,
/// `1 - blend_constants` component-wise.
OneMinusConstantColor = ONE_MINUS_CONSTANT_COLOR,
/// `blend_constants.a` for all components.
///
/// On [portability subset](crate::instance#portability-subset-devices-and-the-enumerate_portability-flag)
/// devices, if this value is used for the `color_source` or `color_destination` blend factors,
/// then the
/// [`constant_alpha_color_blend_factors`](crate::device::Features::constant_alpha_color_blend_factors)
/// feature must be enabled on the device.
ConstantAlpha = CONSTANT_ALPHA,
/// `1 - blend_constants.a` for all components.
///
/// On [portability subset](crate::instance#portability-subset-devices-and-the-enumerate_portability-flag)
/// devices, if this value is used for the `color_source` or `color_destination` blend factors,
/// then the
/// [`constant_alpha_color_blend_factors`](crate::device::Features::constant_alpha_color_blend_factors)
/// feature must be enabled on the device.
OneMinusConstantAlpha = ONE_MINUS_CONSTANT_ALPHA,
/// For the alpha component, always `1`. For the color components,
/// `min(source.a, 1 - destination.a)` for all components.
SrcAlphaSaturate = SRC_ALPHA_SATURATE,
/// `source1` component-wise.
Src1Color = SRC1_COLOR,
/// `1 - source1` component-wise.
OneMinusSrc1Color = ONE_MINUS_SRC1_COLOR,
/// `source1.a` for all components.
Src1Alpha = SRC1_ALPHA,
/// `1 - source1.a` for all components.
OneMinusSrc1Alpha = ONE_MINUS_SRC1_ALPHA,
}
vulkan_enum! {
#[non_exhaustive]
/// The arithmetic operation that is applied between the `source` and `destination` component
/// values, after the appropriate `BlendFactor` is applied to both.
BlendOp = BlendOp(i32);
/// `source + destination`.
Add = ADD,
/// `source - destination`.
Subtract = SUBTRACT,
/// `destination - source`.
ReverseSubtract = REVERSE_SUBTRACT,
/// `min(source, destination)`.
Min = MIN,
/// `max(source, destination)`.
Max = MAX,
/* TODO: enable
// TODO: document
Zero = ZERO_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Src = SRC_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Dst = DST_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
SrcOver = SRC_OVER_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
DstOver = DST_OVER_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
SrcIn = SRC_IN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
DstIn = DST_IN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
SrcOut = SRC_OUT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
DstOut = DST_OUT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
SrcAtop = SRC_ATOP_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
DstAtop = DST_ATOP_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Xor = XOR_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Multiply = MULTIPLY_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Screen = SCREEN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Overlay = OVERLAY_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Darken = DARKEN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Lighten = LIGHTEN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Colordodge = COLORDODGE_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Colorburn = COLORBURN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Hardlight = HARDLIGHT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Softlight = SOFTLIGHT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Difference = DIFFERENCE_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Exclusion = EXCLUSION_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Invert = INVERT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
InvertRgb = INVERT_RGB_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Lineardodge = LINEARDODGE_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Linearburn = LINEARBURN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Vividlight = VIVIDLIGHT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Linearlight = LINEARLIGHT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Pinlight = PINLIGHT_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Hardmix = HARDMIX_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
HslHue = HSL_HUE_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
HslSaturation = HSL_SATURATION_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
HslColor = HSL_COLOR_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
HslLuminosity = HSL_LUMINOSITY_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Plus = PLUS_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
PlusClamped = PLUS_CLAMPED_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
PlusClampedAlpha = PLUS_CLAMPED_ALPHA_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
PlusDarker = PLUS_DARKER_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Minus = MINUS_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
MinusClamped = MINUS_CLAMPED_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Contrast = CONTRAST_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
InvertOvg = INVERT_OVG_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Red = RED_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Green = GREEN_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
/* TODO: enable
// TODO: document
Blue = BLUE_EXT
RequiresOneOf([
RequiresAllOf([DeviceExtension(ext_blend_operation_advanced)]),
]),*/
}
vulkan_bitflags! {
/// A mask specifying color components that can be written to a framebuffer attachment.
ColorComponents = ColorComponentFlags(u32);
/// The red component.
R = R,
/// The green component.
G = G,
/// The blue component.
B = B,
/// The alpha component.
A = A,
}