pub fn entry_stub(
        &self,
        instance: &Instance<'_>,
        fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
        entry_func: SpirvValue,
        name: String,
        entry: Entry,
    ) {
        let local_id = match instance.def_id().as_local() {
            Some(id) => id,
            None => {
                self.tcx
                    .sess
                    .err(&format!("Cannot declare {} as an entry point", name));
                return;
            }
        };
        let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_id);
        let body = self.tcx.hir().body(self.tcx.hir().body_owned_by(fn_hir_id));
        for (abi, arg) in fn_abi.args.iter().zip(body.params) {
            if let PassMode::Direct(_) = abi.mode {
            } else {
                self.tcx.sess.span_err(
                    arg.span,
                    &format!("PassMode {:?} invalid for entry point parameter", abi.mode),
                )
            }
        }
        if let PassMode::Ignore = fn_abi.ret.mode {
        } else {
            self.tcx.sess.span_err(
                self.tcx.hir().span(fn_hir_id),
                &format!(
                    "PassMode {:?} invalid for entry point return type",
                    fn_abi.ret.mode
                ),
            )
        }
        let execution_model = entry.execution_model;
        let fn_id = if execution_model == ExecutionModel::Kernel {
            self.kernel_entry_stub(entry_func, name, execution_model)
        } else {
            self.shader_entry_stub(
                self.tcx.def_span(instance.def_id()),
                entry_func,
                fn_abi,
                body.params,
                name,
                execution_model,
            )
        };
        let mut emit = self.emit_global();
        entry
            .execution_modes
            .iter()
            .for_each(|(execution_mode, execution_mode_extra)| {
                emit.execution_mode(fn_id, *execution_mode, execution_mode_extra);
            });
    }
// Entry points declare their "interface" (all uniforms, inputs, outputs, etc.) as parameters.
// spir-v uses globals to declare the interface. So, we need to generate a lil stub for the
// "real" main that collects all those global variables and calls the user-defined main
// function.
Entry points declare their "interface" (all uniforms, inputs, outputs, etc.) as parameters.
spir-v uses globals to declare the interface. So, we need to generate a lil stub for the
"real" main that collects all those global variables and calls the user-defined main
function.
Entry points declare their " interface " ( all uniforms inputs outputs etc . ) as parameters . spir - v uses globals to declare the interface . So we need to generate a lil stub for the " real " main that collects all those global variables and calls the user - defined main function .
pub fn entry_stub(
        &self,
        instance: &Instance<'_>,
        fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
        entry_func: SpirvValue,
        name: String,
        entry: Entry,
    ) {
        let local_id = match instance.def_id().as_local() {
            Some(id) => id,
            None => {
                self.tcx
                    .sess
                    .err(&format!("Cannot declare {} as an entry point", name));
                return;
            }
        };
        let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_id);
        let body = self.tcx.hir().body(self.tcx.hir().body_owned_by(fn_hir_id));
        for (abi, arg) in fn_abi.args.iter().zip(body.params) {
            if let PassMode::Direct(_) = abi.mode {
            } else {
                self.tcx.sess.span_err(
                    arg.span,
                    &format!("PassMode {:?} invalid for entry point parameter", abi.mode),
                )
            }
        }
        if let PassMode::Ignore = fn_abi.ret.mode {
        } else {
            self.tcx.sess.span_err(
                self.tcx.hir().span(fn_hir_id),
                &format!(
                    "PassMode {:?} invalid for entry point return type",
                    fn_abi.ret.mode
                ),
            )
        }
        let execution_model = entry.execution_model;
        let fn_id = if execution_model == ExecutionModel::Kernel {
            self.kernel_entry_stub(entry_func, name, execution_model)
        } else {
            self.shader_entry_stub(
                self.tcx.def_span(instance.def_id()),
                entry_func,
                fn_abi,
                body.params,
                name,
                execution_model,
            )
        };
        let mut emit = self.emit_global();
        entry
            .execution_modes
            .iter()
            .for_each(|(execution_mode, execution_mode_extra)| {
                emit.execution_mode(fn_id, *execution_mode, execution_mode_extra);
            });
    }
pub fn entry_stub ( & self , instance : & Instance < ' _ > , fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > , entry_func : SpirvValue , name : String , entry : Entry , ) { let local_id = match instance . def_id ( ) . as_local ( ) { Some ( id ) => id , None => { self . tcx . sess . err ( & format ! ( " " name ) ) ; return ; } } ; let fn_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( local_id ) ; let body = self . tcx . hir ( ) . body ( self . tcx . hir ( ) . body_owned_by ( fn_hir_id ) ) ; for ( abi , arg ) in fn_abi . args . iter ( ) . zip ( body . params ) { if let PassMode :: Direct ( _ ) = abi . mode { } else { self . tcx . sess . span_err ( arg . span , & format ! ( " " abi mode ) , ) } } if let PassMode :: Ignore = fn_abi . ret . mode { } else { self . tcx . sess . span_err ( self . tcx . hir ( ) . span ( fn_hir_id ) , & format ! ( " " fn_abi ret mode ) , ) } let execution_model = entry . execution_model ; let fn_id = if execution_model == ExecutionModel :: Kernel { self . kernel_entry_stub ( entry_func , name , execution_model ) } else { self . shader_entry_stub ( self . tcx . def_span ( instance . def_id ( ) ) , entry_func , fn_abi , body . params , name , execution_model , ) } ; let mut emit = self . emit_global ( ) ; entry . execution_modes . iter ( ) . for_each ( | ( execution_mode , execution_mode_extra ) | { emit . execution_mode ( fn_id , * execution_mode , execution_mode_extra ) ; } ) ; }
Entry points declare their "interface" (all uniforms, inputs, outputs, etc.)
Entry points declare their " interface " ( all uniforms inputs outputs etc . )
&self
instance
&Instance<'_>
fn_abi
&FnAbi<'tcx, Ty<'tcx>>
entry_func
SpirvValue
name
String
entry
Entry
&self
instance
&Instance<'_>
fn_abi
&FnAbi<'tcx, Ty<'tcx>>
entry_func
SpirvValue
name
String
entry
Entry