gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.41k stars 909 forks source link

[Naga] Document of `Expression::FunctionArgument` confuses me. #5208

Open 823984418 opened 8 months ago

823984418 commented 8 months ago

https://github.com/gfx-rs/wgpu/blob/faed98b45cdc105df78b110e3fd6ca3eef36efc7/naga/src/lib.rs#L1391C5-L1399C27

/// Reference a function parameter, by its index.
///
/// A `FunctionArgument` expression evaluates to a pointer to the argument's
/// value. You must use a [`Load`] expression to retrieve its value, or a
/// [`Store`] statement to assign it a new value.
///
/// [`Load`]: Expression::Load
/// [`Store`]: Statement::Store
FunctionArgument(u32),

But, it seems that there is no Load and Store.

fn foo(x: i32) -> i32 {
    return x;
}
Module {
    types: {
        [1]: Type {
            name: None,
            inner: Scalar(
                Scalar {
                    kind: Sint,
                    width: 4,
                },
            ),
        },
    },
    special_types: SpecialTypes {
        ray_desc: None,
        ray_intersection: None,
        predeclared_types: {},
    },
    constants: {},
    global_variables: {},
    const_expressions: {},
    functions: {
        [1]: Function {
            name: Some(
                "foo",
            ),
            arguments: [
                FunctionArgument {
                    name: Some(
                        "x",
                    ),
                    ty: [1],
                    binding: None,
                },
            ],
            result: Some(
                FunctionResult {
                    ty: [1],
                    binding: None,
                },
            ),
            local_variables: {},
            expressions: {
                [1]: FunctionArgument(
                    0,
                ),
            },
            named_expressions: {
                [1]: "x",
            },
            body: Block {
                body: [
                    Return {
                        value: Some(
                            [1],
                        ),
                    },
                ],
                span_info: [
                    Span {
                        start: 28,
                        end: 37,
                    },
                ],
            },
        },
    },
    entry_points: [],
}
teoxoy commented 8 months ago

I think the doc is out of date. Load/Store should only be used if the function argument is a pointer.