MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / parse_entry_attrs

Function parse_entry_attrs

crates/rustc_codegen_spirv/src/symbols.rs:591–736  ·  view source on GitHub ↗

for a given entry, gather up the additional attributes in this case ExecutionMode's, some have extra arguments others are specified with x, y, or z components ie #[spirv(fragment(origin_lower_left))] or #[spirv(gl_compute(local_size_x=64, local_size_y=8))]

(
    sym: &Symbols,
    arg: &NestedMetaItem,
    name: &Ident,
    execution_model: ExecutionModel,
)

Source from the content-addressed store, hash-verified

589// others are specified with x, y, or z components
590// ie #[spirv(fragment(origin_lower_left))] or #[spirv(gl_compute(local_size_x=64, local_size_y=8))]
591fn parse_entry_attrs(
592 sym: &Symbols,
593 arg: &NestedMetaItem,
594 name: &Ident,
595 execution_model: ExecutionModel,
596) -> Result<Entry, ParseAttrError> {
597 use ExecutionMode::*;
598 use ExecutionModel::*;
599 let mut entry = Entry::from(execution_model);
600 let mut origin_mode: Option<ExecutionMode> = None;
601 let mut local_size: Option<[u32; 3]> = None;
602 let mut local_size_hint: Option<[u32; 3]> = None;
603 // Reserved
604 //let mut max_workgroup_size_intel: Option<[u32; 3]> = None;
605 if let Some(attrs) = arg.meta_item_list() {
606 for attr in attrs {
607 if let Some(attr_name) = attr.ident() {
608 if let Some((execution_mode, extra_dim)) = sym.execution_modes.get(&attr_name.name)
609 {
610 use ExecutionModeExtraDim::*;
611 let val = match extra_dim {
612 None | Tuple => Option::None,
613 _ => Some(parse_attr_int_value(attr)?),
614 };
615 match execution_mode {
616 OriginUpperLeft | OriginLowerLeft => {
617 origin_mode.replace(*execution_mode);
618 }
619 LocalSize => {
620 if local_size.is_none() {
621 local_size.replace(parse_local_size_attr(attr)?);
622 } else {
623 return Err((
624 attr_name.span,
625 String::from(
626 "`#[spirv(compute(threads))]` may only be specified once",
627 ),
628 ));
629 }
630 }
631 LocalSizeHint => {
632 let val = val.unwrap();
633 if local_size_hint.is_none() {
634 local_size_hint.replace([1, 1, 1]);
635 }
636 let local_size_hint = local_size_hint.as_mut().unwrap();
637 match extra_dim {
638 X => {
639 local_size_hint[0] = val;
640 }
641 Y => {
642 local_size_hint[1] = val;
643 }
644 Z => {
645 local_size_hint[2] = val;
646 }
647 _ => unreachable!(),
648 }

Callers 1

parse_attrs_for_checkingFunction · 0.85

Calls 4

parse_attr_int_valueFunction · 0.85
parse_local_size_attrFunction · 0.85
spanMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected