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

Placement of read_only attributes #1159

@dj2

Description

@dj2

From the discussion on #1120 there were concerns raised about the inconsistency with how read only is attributed on textures. Below I've listed the possibilities I can see, please comment with other possibilities if there is something I've missed.

Possible 0 (read_only on var declaration)

For buffers the read_only is on the variable declaration

[[block]] struct Buffer {
  [[offset(0)]] a : i32;
};
[[read_only, binding(0), set(0)]]
var <storage> buf : Buffer;

This is how textures exist now.

texture_sampled_1d<f32>
texture_sampled_1d_array<f32>
texture_sampled_2d<f32>
texture_sampled_2d_array<f32>
texture_sampled_3d<f32>
texture_sampled_cube<f32>
texture_sampled_cube_array<f32>

texture_multisampled_2d<f32>

texture_ro_1d<rgba32float>
texture_ro_1d_array<rgba32float>
texture_ro_2d<rgba32float>
texture_ro_2d_array<rgba32float>
texture_ro_3d<rgba32float>

texture_wo_1d<rgba32float>
texture_wo_1d_array<rgba32float>
texture_wo_2d<rgba32float>
texture_wo_2d_array<rgba32float>
texture_wo_3d<rgba32float>

texture_depth_2d
texture_depth_2d_array
texture_depth_cube
texture_depth_cube_array

sampler
sampler_comparison

Example

var tex : texture_sampled_2d<f32>;
var ro_tex : texture_ro_1d<rgba32float>;

Possible 1 (read_only as attribute)

For buffers, move the read_only to the declaration of the struct, making it part of the type.

[[block, read_only]] struct Buffer {
  [[offset(0)]] a : i32;
};
[[binding(0), set(0)]]
var <storage> buf : Buffer;

For textures, make the attributes part of the type declaration for the variable.

[[read_only]] texture_1d<rgba32float>
[[sampled]] texture_1d<f32>
[[write_only]] texture_1d<rgba32float>
[[depth]] texture_2d
sampler
[[comparison]] sampler

Example

var tex : [[sampled]] texture_2d<f32>;
var ro_tex : [[read_only]] texture_1d<rgba32float>;

Possible 2 (attribute at variable decl on type)

Put the read_only on the type assignment for buffers, matches with the textures from Possible 1.

[[block]] struct Buffer {
  [[offset(0)]] a : i32;
};
[[binding(0), set(0)]]
var <storage> buf : [[read_only]] Buffer;

Possible 3 (struct_ro)

Make a new struct declaration for read_only as struct_ro.

[[block]] struct_ro Buffer {
  [[offset(0)]] a : i32;
};
[[binding(0), set(0)]]
var <storage> buf : Buffer;

Same as we have now.

texture_sampled_1d<f32>
texture_sampled_1d_array<f32>
texture_sampled_2d<f32>
texture_sampled_2d_array<f32>
texture_sampled_3d<f32>
texture_sampled_cube<f32>
texture_sampled_cube_array<f32>

texture_multisampled_2d<f32>

texture_ro_1d<rgba32float>
texture_ro_1d_array<rgba32float>
texture_ro_2d<rgba32float>
texture_ro_2d_array<rgba32float>
texture_ro_3d<rgba32float>

texture_wo_1d<rgba32float>
texture_wo_1d_array<rgba32float>
texture_wo_2d<rgba32float>
texture_wo_2d_array<rgba32float>
texture_wo_3d<rgba32float>

texture_depth_2d
texture_depth_2d_array
texture_depth_cube
texture_depth_cube_array

sampler
sampler_comparison

Possible 4 (attributes on vars)

The read_only is on the variable declaration.

[[block]] struct Buffer {
  [[offset(0)]] a : i32;
};
[[read_only, binding(0), set(0)]]
var <storage> buf : Buffer;

Put the decorations on the variable decoration same as buffers.

[[read_only]] texture_1d<rgba32float>
[[sampled]] texture_1d<f32>
[[write_only]] texture_1d<rgba32float>
[[depth]] texture_2d
sampler
[[comparison]] sampler

Example

[[sampled]] var tex : texture_2d<f32>;
[[read_only]] var ro_tex : texture_1d<rgba32float>;

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions