vulkan,nir: Common YCbCr lowering code
Maybe we can do this as part of YCbCr for v3dv and/or turnip before they create yet another copy of the lowering code in ANV. In particular, here's what I think we roughly need:
struct vk_ycbcr_conversion
1. A common Copying ANV's....
struct vk_ycbcr_conversion {
struct vk_object_base base;
VkFormat format;
VkSamplerYcbcrModelConversion ycbcr_model;
VkSamplerYcbcrRange ycbcr_range;
VkComponentSwizzle mapping[4];
VkChromaLocation chroma_offsets[2];
VkFilter chroma_filter;
bool hroma_reconstruction;
};
Now that we've got common infrastructure creating and destroying these in common code should be trivial.
2. Format helpers
Right now, ANV's YCbCr conversion lowering code is based on the ANV format table. I'd love it if the "where do I find my chroma" type information were in something YCbCr specific and not in the ANV table. Sounds like a good thing to put in vk_format.h
.
3. Common NIR lowering
Most of this should be a copy+paste job as very little of the ANV code is really ANV-specific. The tricky bit will be that the lowering pass will need to take a callback:
typedef struct vk_ycbcr_conversion *
(nir_vk_ycbcr_conversion_cb)(void *data, uint32_t set,
uint32_t binding, uint32_t array_index);
nir_vk_lower_ycbcr_conversion(nir_shader *nir, nir_vk_ycbcr_conversion_cb cb, void *cb_data);
The callback, in case it isn't obvious, takes a descriptor triple and returns the YCbCr conversion object if one exists and NULL if the given triple doesn't point to a sampled image with a YCbCr conversion.