logo
Expand description

Conversion from sampled YCbCr image data to RGB shader data.

A sampler YCbCr conversion is an object that assists a sampler when converting from YCbCr formats and/or YCbCr texel input data. It is used to read frames of video data within a shader, possibly to apply it as texture on a rendered primitive. Sampler YCbCr conversion can only be used with certain formats, and conversely, some formats require the use of a sampler YCbCr conversion to be sampled at all.

A sampler YCbCr conversion can only be used with a combined image sampler descriptor in a descriptor set. The conversion must be attached on both the image view and sampler in the descriptor, and the sampler must be included in the descriptor set layout as an immutable sampler.

Examples

use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet};
use vulkano::descriptor_set::layout::{DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo, DescriptorType};
use vulkano::format::Format;
use vulkano::image::{ImmutableImage, ImageCreateFlags, ImageDimensions, ImageUsage, MipmapsCount};
use vulkano::image::view::{ImageView, ImageViewCreateInfo};
use vulkano::sampler::{Sampler, SamplerCreateInfo};
use vulkano::sampler::ycbcr::{SamplerYcbcrConversion, SamplerYcbcrConversionCreateInfo, SamplerYcbcrModelConversion};
use vulkano::shader::ShaderStage;

let conversion = SamplerYcbcrConversion::new(device.clone(), SamplerYcbcrConversionCreateInfo {
    format: Some(Format::G8_B8_R8_3PLANE_420_UNORM),
    ycbcr_model: SamplerYcbcrModelConversion::YcbcrIdentity,
    ..Default::default()
})
.unwrap();

let sampler = Sampler::new(device.clone(), SamplerCreateInfo {
    sampler_ycbcr_conversion: Some(conversion.clone()),
    ..Default::default()
})
.unwrap();

let descriptor_set_layout = DescriptorSetLayout::new(
    device.clone(),
        DescriptorSetLayoutCreateInfo {
        bindings: [(
            0,
            DescriptorSetLayoutBinding {
                stages: ShaderStage::Fragment.into(),
                immutable_samplers: vec![sampler],
                ..DescriptorSetLayoutBinding::descriptor_type(DescriptorType::CombinedImageSampler)
            },
        )]
        .into(),
        ..Default::default()
    },
).unwrap();

let (image, future) = ImmutableImage::from_iter(
    image_data,
    ImageDimensions::Dim2d { width: 1920, height: 1080, array_layers: 1 },
    MipmapsCount::One,
    Format::G8_B8_R8_3PLANE_420_UNORM,
    queue.clone(),
).unwrap();

let create_info = ImageViewCreateInfo {
    sampler_ycbcr_conversion: Some(conversion.clone()),
    ..ImageViewCreateInfo::from_image(&image)
};
let image_view = ImageView::new(image, create_info).unwrap();

let descriptor_set = PersistentDescriptorSet::new(
    descriptor_set_layout.clone(),
    [WriteDescriptorSet::image_view(0, image_view)],
).unwrap();

Structs

Describes how sampled image data should converted from a YCbCr representation to an RGB one.
Parameters to create a new SamplerYcbcrConversion.

Enums

For formats with chroma subsampling, the location where the chroma components are sampled, relative to the luma component.
Error that can happen when creating a SamplerYcbcrConversion.
The conversion between the color model of the source image and the color model of the shader.
How the numeric range of the input data is converted.