mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 11:18:08 +02:00
rusticl/format: move format table generation into a macro
Signed-off-by: Karol Herbst <git@karolherbst.de> Reviewed-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Nora Allen <blackcatgames@protonmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23714>
This commit is contained in:
parent
9112aeb4a4
commit
976ba09f57
1 changed files with 42 additions and 56 deletions
|
|
@ -40,41 +40,51 @@ pub struct RusticlImageFormat {
|
|||
// UNSIGNED_INT => x UINT
|
||||
// HALF_FLOAT => 16 FLOAT
|
||||
// FLOAT => 32 FLOAT
|
||||
#[rustfmt::skip]
|
||||
const fn cl_format_to_pipe(
|
||||
ch_order: cl_channel_order,
|
||||
ch_type: cl_channel_type
|
||||
) -> Option<pipe_format> {
|
||||
Some(match (ch_order, ch_type) {
|
||||
(CL_R, CL_HALF_FLOAT) => pipe_format::PIPE_FORMAT_R16_FLOAT,
|
||||
(CL_RGBA, CL_HALF_FLOAT) => pipe_format::PIPE_FORMAT_R16G16B16A16_FLOAT,
|
||||
macro_rules! cl_format_table {
|
||||
([$(($order: ident, $type: ident) => $pipe: expr,)+]) => {
|
||||
const fn cl_format_to_pipe(
|
||||
ch_order: cl_channel_order,
|
||||
ch_type: cl_channel_type
|
||||
) -> Option<pipe_format> {
|
||||
Some(match (ch_order, ch_type) {
|
||||
$(($order, $type) => $pipe,)+
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
(CL_R, CL_FLOAT) => pipe_format::PIPE_FORMAT_R32_FLOAT,
|
||||
(CL_RGBA, CL_FLOAT) => pipe_format::PIPE_FORMAT_R32G32B32A32_FLOAT,
|
||||
|
||||
(CL_R, CL_SIGNED_INT8) => pipe_format::PIPE_FORMAT_R8_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_SINT,
|
||||
(CL_R, CL_SIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_SINT,
|
||||
(CL_R, CL_SIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT32) => pipe_format::PIPE_FORMAT_R32G32B32A32_SINT,
|
||||
(CL_R, CL_UNSIGNED_INT8) => pipe_format::PIPE_FORMAT_R8_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_UINT,
|
||||
(CL_R, CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_UINT,
|
||||
(CL_R, CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32G32B32A32_UINT,
|
||||
|
||||
(CL_R, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_R8_UNORM,
|
||||
(CL_RGBA, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
(CL_BGRA, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_B8G8R8A8_UNORM,
|
||||
(CL_R, CL_UNORM_INT16) => pipe_format::PIPE_FORMAT_R16_UNORM,
|
||||
(CL_RGBA, CL_UNORM_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_UNORM,
|
||||
|
||||
_ => return None,
|
||||
})
|
||||
pub const FORMATS: &[RusticlImageFormat] = &[
|
||||
$(rusticl_image_format($order, $type),)+
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
cl_format_table!([
|
||||
(CL_R, CL_HALF_FLOAT) => pipe_format::PIPE_FORMAT_R16_FLOAT,
|
||||
(CL_RGBA, CL_HALF_FLOAT) => pipe_format::PIPE_FORMAT_R16G16B16A16_FLOAT,
|
||||
|
||||
(CL_R, CL_FLOAT) => pipe_format::PIPE_FORMAT_R32_FLOAT,
|
||||
(CL_RGBA, CL_FLOAT) => pipe_format::PIPE_FORMAT_R32G32B32A32_FLOAT,
|
||||
|
||||
(CL_R, CL_SIGNED_INT8) => pipe_format::PIPE_FORMAT_R8_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_SINT,
|
||||
(CL_R, CL_SIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_SINT,
|
||||
(CL_R, CL_SIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_SINT,
|
||||
(CL_RGBA, CL_SIGNED_INT32) => pipe_format::PIPE_FORMAT_R32G32B32A32_SINT,
|
||||
(CL_R, CL_UNSIGNED_INT8) => pipe_format::PIPE_FORMAT_R8_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_UINT,
|
||||
(CL_R, CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_UINT,
|
||||
(CL_R, CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_UINT,
|
||||
(CL_RGBA, CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32G32B32A32_UINT,
|
||||
|
||||
(CL_R, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_R8_UNORM,
|
||||
(CL_RGBA, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
(CL_BGRA, CL_UNORM_INT8) => pipe_format::PIPE_FORMAT_B8G8R8A8_UNORM,
|
||||
(CL_R, CL_UNORM_INT16) => pipe_format::PIPE_FORMAT_R16_UNORM,
|
||||
(CL_RGBA, CL_UNORM_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_UNORM,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const fn req_for_full_r_or_w(
|
||||
ch_order: cl_channel_order,
|
||||
|
|
@ -209,30 +219,6 @@ const fn rusticl_image_format(
|
|||
}
|
||||
}
|
||||
|
||||
pub const FORMATS: &[RusticlImageFormat] = &[
|
||||
rusticl_image_format(CL_R, CL_HALF_FLOAT),
|
||||
rusticl_image_format(CL_R, CL_FLOAT),
|
||||
rusticl_image_format(CL_R, CL_SIGNED_INT8),
|
||||
rusticl_image_format(CL_R, CL_SIGNED_INT16),
|
||||
rusticl_image_format(CL_R, CL_SIGNED_INT32),
|
||||
rusticl_image_format(CL_R, CL_UNORM_INT8),
|
||||
rusticl_image_format(CL_R, CL_UNORM_INT16),
|
||||
rusticl_image_format(CL_R, CL_UNSIGNED_INT8),
|
||||
rusticl_image_format(CL_R, CL_UNSIGNED_INT16),
|
||||
rusticl_image_format(CL_R, CL_UNSIGNED_INT32),
|
||||
rusticl_image_format(CL_RGBA, CL_HALF_FLOAT),
|
||||
rusticl_image_format(CL_RGBA, CL_FLOAT),
|
||||
rusticl_image_format(CL_RGBA, CL_SIGNED_INT8),
|
||||
rusticl_image_format(CL_RGBA, CL_SIGNED_INT16),
|
||||
rusticl_image_format(CL_RGBA, CL_SIGNED_INT32),
|
||||
rusticl_image_format(CL_RGBA, CL_UNORM_INT8),
|
||||
rusticl_image_format(CL_RGBA, CL_UNORM_INT16),
|
||||
rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT8),
|
||||
rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT16),
|
||||
rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT32),
|
||||
rusticl_image_format(CL_BGRA, CL_UNORM_INT8),
|
||||
];
|
||||
|
||||
pub trait CLFormatInfo {
|
||||
fn channels(&self) -> Option<u8>;
|
||||
fn format_info(&self) -> Option<(u8, bool)>;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue