nak: Move DstsAsSlice::is_uniform() to its own trait

Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30443>
This commit is contained in:
Faith Ekstrand 2024-07-31 11:31:16 -05:00 committed by Marge Bot
parent 35353a7368
commit bc58881b9f
2 changed files with 6 additions and 22 deletions

View file

@ -1493,7 +1493,13 @@ pub trait DstsAsSlice {
assert!(r.contains(&(dst as *const Dst)));
unsafe { (dst as *const Dst).offset_from(r.start) as usize }
}
}
pub trait IsUniform {
fn is_uniform(&self) -> bool;
}
impl<T: DstsAsSlice> IsUniform for T {
fn is_uniform(&self) -> bool {
all_dsts_uniform(self.dsts_as_slice())
}
@ -5827,10 +5833,6 @@ impl DstsAsSlice for OpPhiDsts {
fn dst_types(&self) -> DstTypeList {
DstTypeList::Uniform(DstType::Vec)
}
fn is_uniform(&self) -> bool {
false
}
}
impl DisplayOp for OpPhiDsts {

View file

@ -184,7 +184,6 @@ fn derive_as_slice(
let mut as_slice_cases = TokenStream2::new();
let mut as_mut_slice_cases = TokenStream2::new();
let mut types_cases = TokenStream2::new();
let mut is_uniform_cases = TokenStream2::new();
for v in e.variants {
let case = v.ident;
as_slice_cases.extend(quote! {
@ -196,23 +195,7 @@ fn derive_as_slice(
types_cases.extend(quote! {
#ident::#case(x) => x.#types_fn(),
});
if search_type == "Dst" {
is_uniform_cases.extend(quote! {
#ident::#case(x) => x.is_uniform(),
});
}
}
let is_uniform_func = if search_type == "Dst" {
quote! {
fn is_uniform(&self) -> bool {
match self {
#is_uniform_cases
}
}
}
} else {
TokenStream2::new()
};
quote! {
impl #trait_name for #ident {
fn #as_slice(&self) -> &[#elem_type] {
@ -232,7 +215,6 @@ fn derive_as_slice(
#types_cases
}
}
#is_uniform_func
}
}
.into()