Skip to content

Placement of read_only attributes #1159

Closed

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>;

Activity

  1. added
    wgsl
    on Oct 20, 2020
  2. added this to the MVP milestone on Oct 20, 2020
  3. self-assigned this
    on Oct 20, 2020
  4. dj2 commented on Oct 20, 2020

    @dj2
    MemberAuthor

    Related to #923

  5. kvark commented on Oct 21, 2020

    @kvark
    Contributor

    Possible 5 (attributes and types)

    Buffers differentiating in types (struct_storage, struct_uniform, struct), but the access qualifier goes on the variable:

    struct_storage Buffer {
      [[offset(0)]] a : i32;
    };
    [[read_only, binding(0), set(0)]]
    var buf : Buffer;

    Same for textures:

    texture_sampled_1d<f32>
    ...
    texture_multisampled_2d<f32>
    
    texture_storage_1d<rgba32float>
    ...
    texture_depth_2d
    ...
    
    [[read_only, binding(0), set(0)]]
    var texture1 : texture_storage_1d_array<rgba32float>;
    [[write_only, binding(1), set(0)]]
    var texture2 : texture_storage_1d<rgba32float>;
    [[binding(2), set(0)]]
    var texture3 : texture_sampled_3d<f32>;

    And samplers are left as is:

    sampler
    sampler_comparison

    Possible 6 (full types)

    Buffers get the typing:

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

    Textures are unchanged from today.

    Note that I removed the [[block]] and <storage> because they are implied if we know that the buffer is a storage buffer by other means (types or decorations).

  6. dj2 commented on Oct 21, 2020

    @dj2
    MemberAuthor

    Possible 7 (I'm running out of things to call these)

    I like Possible 5, but what about leaving the <storage> and <uniform> on the var and just having a single struct.

    Example

    struct Buffer {
      [[offset(0)]] a : i32;
    };
    [[read_only, binding(0), set(0)]]
    var<storage> buf : Buffer;
    
    [[read_only, binding(0), set(0)]]
    var texture1 : texture_storage_1d_array<rgba32float>;
    [[write_only, binding(1), set(0)]]
    var texture2 : texture_storage_1d<rgba32float>;
    [[binding(2), set(0)]]
    var texture3 : texture_sampled_3d<f32>;
  7. dj2 commented on Oct 22, 2020

    @dj2
    MemberAuthor
    var ro_tex :  texture_storage_1d<read, rgba32float>;
    var tex : texture_1d<f32>
    
    [[block]] struct Buffer {
      [[offset(0)]] a : i32;
    };
    [[binding(0), set(0)]]
    var <storage> buf : [[access(read)]] Buffer;
    

    Possible access values:

    • read
    • write
    • read_write
  8. kvark commented on Oct 22, 2020

    @kvark
    Contributor

    Can we have the storage access qualifiers be similar between storage buffers and textures? I know that @dneto0 made an argument that they can be different. I don't think we have a strong reason to separate them though.

  9. dj2 commented on Oct 26, 2020

    @dj2
    MemberAuthor

    This was discussed at the VF2F (https://docs.google.com/document/d/1p1jREMgonZszFJ8eastnnDb36rKKm7xnDYnMjC6zj5c/edit?usp=sharing) with, I believe, the final concensus being:

    var ro_tex : texture_storage_1d<read, rgba32float>;
    var tex : texture_1d<f32>
    
    [[block]] struct Buffer {
      [[offset(0)]] a : i32;
    };
    [[binding(0), set(0)]]
    var <storage> buf : [[access(read)]] Buffer;

    We change to having sampled textures be the default one and the storage textures would have the longer name. So, texture_1d is a sampled texture and texture_storage_1d is a storage texture. Depth textures and samplers don't change from the current spec.

    The storage textures have an extra template argument which is read or write to specify if they are read only or write only. The read storage texture specifier will map to a OpDecorate %tbuf NonWritable and a write will map to OpDecorate %tbuf NonReadable.

    Storage buffer declarations have a decoration added access(read|write) to let us set the access permission for the storage buffer. Setting the read access will apply a OpDecorate %tbuf NonWritable to the structure and a write will apply a OpDecorate %tbuf NonReadable.

    @kvark @dneto0 @litherum please let me know if I got anything wrong in the above. This was what I understood we settled on at the F2F.

  10. dneto0 commented on Oct 26, 2020

    @dneto0
    Contributor

    The texture changes sound right.

    The storage buffer one, I'm not so sure the details were right. I think we had settled on "must give an attribute" for now, and then relax that later.
    For storage buffer, they are either read+write or read-only. (I think I really goofed on #935 saying there were write-only buffers...)

    So the buffer examples should be something like this.

    var <storage> buf : [[access(read)]] Buffer;      // can read, cannot write.
    var <storage> buf2 : [[access(read_write)]] Buffer;  // can both read and write
     var<uniform> b3 : Buffer; //  UBO.  Hence: read-only.  More restrictive layout rules.  Does not need a qualifier.
    
    
    -----
    edited: fixed the comment on the read-only buffer case.
    
  11. added a commit that references this issue on Nov 3, 2020
  12. grorg commented on Nov 10, 2020

    @grorg
    Contributor

    Are we simply waiting on the above issues to resolve this?

  13. dj2 commented on Nov 10, 2020

    @dj2
    MemberAuthor

    Once the related issues are done this should be complete I believe.

  14. kvark commented on Jan 29, 2021

    @kvark
    Contributor

    I believe this can be closed now 🎉 , given #1182 has landed.
    Please reopen otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wgsl

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions