这是indexloc提供的服务,不要输入任何密码
Skip to content

Proposal to enhance defining input/output variables. #1155

@dj2

Description

@dj2

Writing multiple shaders in a single file could benefit from collapsing, or moving module scoped input/output variables.

There are a few different possibilities here depending on how we want to proceed.

Multiple storage classes

[[location(0)]] var<out(vertex), in(fragment)> frag_color : vec4<f32>

Multiple locations

[[location(0, fragment), location(1, vertex)]] var<in(vertex), out(fragment)> colour : vec4<f32>

As structs

struct PerVertex {
  [[location(0)]] colour: vec4<f32>;
};
fn vertex() -> PerVertex {... }
fn fragment(v: PerVertex) -> vec4<f32> { .. }

As entry point parameters

fn fragment(
    [[location(0)]] colour : vec4<f32>,
) -> [[location(1)]] vec4<f32> {
}

[[stage(fragment)]]
fn frag(
  [[buildin(position)]] pos : vec4<f32>) -> void {}

[[stage(compute)]]
fn comp_main(
  [[builtin(invocation_id)]] gl_GlobalInvocationId : vec3<u32>,
  [[set(0), binding(0), uniform]] params : SimParams,
  [[set(0), binding(1), storage]] particlesA : Particles,
  [[set(0), binding(2), storage]] particlesB : Particles) -> void {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions