这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wgsl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ index.html: index.bs
bikeshed --die-on=everything spec index.bs

online:
curl https://api.csswg.org/bikeshed/ -F file=@index.bs -F output=err
curl https://api.csswg.org/bikeshed/ -F file=@index.bs -F force=1 > index.html
323 changes: 323 additions & 0 deletions wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,153 @@ The result type depends on the number of letters provided. Assuming a `vec4<f32>
</xmp>
</div>

# Textures # {#textures}

## Texture Types ## {#texture-types}

### Sampled Texture ### {#texture-sampled}

<pre class='def'>
`texture_sampled_1d<type>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to be used a lot, I think we should shorten it to just texture_Xd, implying the sampling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that if we want to go the implicit route.

%1 = OpTypeImage %type 1D 0 0 0 1 Unknown

`texture_sampled_1d_array<type>`
%1 = OpTypeImage %type 1D 0 1 0 1 Unknown

`texture_sampled_2d<type>`
%1 = OpTypeImage %type 2D 0 0 0 1 Unknown

`texture_sampled_2d_array<type>`
%1 = OpTypeImage %type 2D 0 1 0 1 Unknown

`texture_sampled_3d<type>`
%1 = OpTypeImage %type 3D 0 0 0 1 Unknown

`texture_sampled_2d_ms<type>`
%1 = OpTypeImage %type 2D 0 0 1 1 Unknown

`texture_sampled_2d_ms_array<type>`
%1 = OpTypeImage %type 2D 0 1 1 1 Unknown

`texture_sampled_cube<type>`
%1 = OpTypeImage %type Cube 0 0 0 1 Unknown

`texture_sampled_cube_array<type>`
%1 = OpTypeImage %type Cube 0 1 0 1 Unknown
</pre>
* type must be `f32`, `i32` or `u32`
* The parameterized type for the images is the type after conversion from sampling.
E.g. you can have an image with texels with 8bit unorm components, but when you sample
them you get a 32-bit float result (or vec-of-f32).

### Read-only Storage Texture ### {#texture-ro}
<pre class='def'>
`texture_ro_1d<type, image_storage_type>`
%1 = OpTypeImage %type 1D 0 0 0 2 image_storage_type

`texture_ro_1d_array<type, image_storage_type>`
%1 = OpTypeImage %type 1D 0 1 0 2 image_storage_type

`texture_ro_2d<type, image_storage_type>`
%1 = OpTypeImage %type 2D 0 0 0 2 image_storage_type

`texture_ro_2d_array<type, image_storage_type>`
%1 = OpTypeImage %type 2D 0 1 0 2 image_storage_type

`texture_ro_3d<type, image_storage_type>`
%1 = OpTypeImage %type 3D 0 0 0 2 image_storage_type
</pre>
* type must be `f32`, `i32` or `u32`
* The parameterized type for the images is the type after conversion from reading.
E.g. you can have an image with texels with 8bit unorm components, but when you read
them you get a 32-bit float result (or vec-of-f32).

### Write-only Storage Texture ### {#texture-wo}
<pre class='def'>
`texture_wo_1d<image_storage_type>`
%1 = OpTypeImage %void 1D 0 0 0 2 image_storage_type

`texture_wo_1d_array<image_storage_type>`
%1 = OpTypeImage %void 1D 0 1 0 2 image_storage_type

`texture_wo_2d<image_storage_type>`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the types here to be void as they can't be sampled or read.

%1 = OpTypeImage %void 2D 0 0 0 2 image_storage_type

`texture_wo_2d_array<image_storage_type>`
%1 = OpTypeImage %void 2D 0 1 0 2 image_storage_type

`texture_wo_3d<image_storage_type>`
%1 = OpTypeImage %void 3D 0 0 0 2 image_storage_type
</pre>

### Depth Texture ### {#texture-depth}
<pre class='def'>
`texture_depth_2d`
%1 = OpTypeImage %f32 2D 1 0 0 1 Unknown

`texture_depth_2d_array`
%1 = OpTypeImage %f32 2D 1 1 0 1 Unknown

`texture_depth_cube`
%1 = OpTypeImage %f32 Cube 1 0 0 1 Unknown

`texture_depth_cube_array`
%1 = OpTypeImage %f32 Cube 1 1 0 1 Unknown
</pre>

### Samplers ### {#texture-sampler}
<pre class='def'>
sampler
OpTypeSampler

sampler_comparison
OpTypeSampler
</pre>

## Texture Functions ## {#texture-functions}

<pre class='def'>
`vec4<type> texture_load(texture_ro, i32 coords, i32 level_of_detail)`
`vec4<type> texture_load(texture_ro, vec2<i32> coords, i32 level_of_detail)`
`vec4<type> texture_load(texture_ro, vec3<i32> coords, i32 level_of_detail)`
%32 = OpImageFetch %v4float %texture_ro %coords Lod %level_of_detail

TODO(dsinclair): Texture load on a sampled texture

TODO(dsinclair): Texture load on multi-sampled texture

TODO(dsinclair): Add `texture_write` method for texture_wo with integral coords

TODO(dsinclair): Allow a small constant offset on the coordinate? May not be portable.

`vec4<type> texture_sample(texture_sampled, sampler, f32 coords)`
`vec4<type> texture_sample(texture_sampled, sampler, vec2<f32> coords)`
`vec4<type> texture_sample(texture_sampled, sampler, vec3<f32> coords)`
`vec4<type> texture_sample(texture_sampled, sampler, vec4<f32> coords)`
%24 = OpImageSampleImplicitLod %v4float %sampled_image %coords

`vec4<type> texture_sample_level(texture_sampled, sampler, f32 coords, f32 lod)`
`vec4<type> texture_sample_level(texture_sampled, sampler, vec2<f32> coords, f32 lod)`
`vec4<type> texture_sample_level(texture_sampled, sampler, vec3<f32> coords, f32 lod)`
`vec4<type> texture_sample_level(texture_sampled, sampler, vec4<f32> coords, f32 lod)`
%25 = OpImageSampleExplicitLod %v4float %sampled_image %coords Lod %lod

`vec4<type> texture_sample_bias(texture_sampled, sampler, f32 coords, f32 bias)`
`vec4<type> texture_sample_bias(texture_sampled, sampler, vec2<f32> coords, f32 bias)`
`vec4<type> texture_sample_bias(texture_sampled, sampler, vec3<f32> coords, f32 bias)`
`vec4<type> texture_sample_bias(texture_sampled, sampler, vec4<f32> coords, f32 bias)`
%19 = OpImageSampleImplicitLod %v4float %sampled_image %coords Bias %bias

`f32 texture_sample_compare(texture_depth, sampler_comparison, f32 coords, f32 depth_reference)`
`f32 texture_sample_compare(texture_depth, sampler_comparison, vec2<f32> coords, f32 depth_reference)`
`f32 texture_sample_compare(texture_depth, sampler_comparison, vec3<f32> coords, f32 depth_reference)`
%65 = OpImageSampleDrefImplicitLod %float %sampled_image %coord %depth_reference Lod %float_0

TODO(dsinclair): Add Level-of-Detail via explicit gradient. "Grad" image operand in SPIR-V

TODO(dsinclair): Need gather operations
</pre>

# Grammar # {#grammar}

## Scoping ## {#scoping}
Expand Down Expand Up @@ -529,7 +676,32 @@ Note: literals are parsed greedy. This means that for statements like `a -5`
<tr><td>`MAT4x3`<td>mat4x3 # column x row
<tr><td>`MAT4x4`<td>mat4x4 # column x row
<tr><td>`POINTER`<td>ptr
<tr><td>`SAMPLER`<td>sampler
<tr><td>`SAMPLER_COMPARISON`<td>sampler_comparison
<tr><td>`STRUCT`<td>struct
<tr><td>`TEXTURE_SAMPLED_1D`<td>texture_sampled_1d
<tr><td>`TEXTURE_SAMPLED_1D_ARRAY`<td>texture_sampled_1d_array
<tr><td>`TEXTURE_SAMPLED_2D`<td>texture_sampled_2d
<tr><td>`TEXTURE_SAMPLED_2D_ARRAY`<td>texture_sampled_2d_array
<tr><td>`TEXTURE_SAMPLED_2D_MS`<td>texture_sampled_2d_ms
<tr><td>`TEXTURE_SAMPLED_2D_MS_ARRAY`<td>texture_sampled_2d_ms_array
<tr><td>`TEXTURE_SAMPLED_3D`<td>texture_sampled_3d
<tr><td>`TEXTURE_SAMPLED_CUBE`<td>texture_sampled_cube
<tr><td>`TEXTURE_SAMPLED_CUBE_ARRAY`<td>texture_sampled_cube_array
<tr><td>`TEXTURE_RO_1D`<td>texture_ro_1d
<tr><td>`TEXTURE_RO_1D_ARRAY`<td>texture_ro_1d_array
<tr><td>`TEXTURE_RO_2D`<td>texture_ro_2d
<tr><td>`TEXTURE_RO_2D_ARRAY`<td>texture_ro_2d_array
<tr><td>`TEXTURE_RO_3D`<td>texture_ro_3d
<tr><td>`TEXTURE_WO_1D`<td>texture_wo_1d
<tr><td>`TEXTURE_WO_1D_ARRAY`<td>texture_wo_1d_array
<tr><td>`TEXTURE_WO_2D`<td>texture_wo_2d
<tr><td>`TEXTURE_WO_2D_ARRAY`<td>texture_wo_2d_array
<tr><td>`TEXTURE_WO_3D`<td>texture_wo_3d
<tr><td>`TEXTURE_DEPTH_2D`<td>texture_depth_2d
<tr><td>`TEXTURE_DEPTH_2D_ARRAY`<td>texture_depth_2d_array
<tr><td>`TEXTURE_DEPTH_CUBE`<td>texture_depth_cube
<tr><td>`TEXTURE_DEPTH_CUBE_ARRAY`<td>texture_depth_cube_array
<tr><td>`UINT32`<td>u32
<tr><td>`VEC2`<td>vec2
<tr><td>`VEC3`<td>vec3
Expand Down Expand Up @@ -578,6 +750,42 @@ Note: literals are parsed greedy. This means that for statements like `a -5`
<tr><td>`VAR`<td>var
<tr><td>`VERTEX`<td>vertex
<tr><td>`WORKGROUP`<td>workgroup
<tr><td><td>
<tr><td>`R8UNORM`<td>r8unorm
<tr><td>`R8SNORM`<td>r8snorm
<tr><td>`R8UINT`<td>r8uint
<tr><td>`R8SINT`<td>r8sint
<tr><td>`R16UINT`<td>r16uint
<tr><td>`R16SINT`<td>r16sint
<tr><td>`R16FLOAT`<td>r16float
<tr><td>`RG8UNORM`<td>rg8unorm
<tr><td>`RG8SNORM`<td>rg8snorm
<tr><td>`RG8UINT`<td>rg8uint
<tr><td>`RG8SINT`<td>rg8sint
<tr><td>`R32UINT`<td>r32uint
<tr><td>`R32SINT`<td>r32sint
<tr><td>`R32FLOAT`<td>r32float
<tr><td>`RG16UINT`<td>rg16uint
<tr><td>`RG16SINT`<td>rg16sint
<tr><td>`RG16FLOAT`<td>rg16float
<tr><td>`RGBA8UNORM`<td>rgba8unorm
<tr><td>`RGBA8UNORM-SRGB`<td>rgba8unorm_srgb
<tr><td>`RGBA8SNORM`<td>rgba8snorm
<tr><td>`RGBA8UINT`<td>rgba8uint
<tr><td>`RGBA8SINT`<td>rgba8sint
<tr><td>`BGRA8UNORM`<td>bgraunorm
<tr><td>`BGRA8UNORM-SRGB`<td>bgra8unorm_srgb
<tr><td>`RGB10A2UNORM`<td>rgb10a2unorm
<tr><td>`RG11B10FLOAT`<td>rg11b10float
<tr><td>`RG32UINT`<td>rg32uint
<tr><td>`RG32SINT`<td>rg32sint
<tr><td>`RG32FLOAT`<td>rg32float
<tr><td>`RGBA16UINT`<td>rgba16uint
<tr><td>`RGBA16SINT`<td>rgba16sint
<tr><td>`RGBA16FLOAT`<td>rgba16float
<tr><td>`RGBA32UINT`<td>rgba32uint
<tr><td>`RGBA32SINT`<td>rgba32sint
<tr><td>`RGBA32FLOAT`<td>rgba32float
</table>

## Reserved Keywords ## {#reserved-keywords}
Expand Down Expand Up @@ -709,11 +917,126 @@ module header and each usage of a GLSL method will add the appropriate
<pre class='def'>
global_variable_decl
: variable_decoration_list? variable_decl
| variable_decoration_list? sampler_or_texture_decl
| variable_decoration_list? variable_decl EQUAL const_expr

global_constant_decl
: CONST variable_ident_decl EQUAL const_expr

sampler_or_texture_decl
: VAR variable_storage_decoration? IDENT COLON texture_sampler_types

texture_sampler_types
: sampler_type
| depth_texture_type
| sampled_texture_type LESS_THAN type_decl GREATER_THAN
| storage_texture_type LESS_THAN image_storage_type GREATER_THAN

sampler_type
: SAMPLER
| SAMPLER_COMPARISON

sampled_texture_type
: TEXTURE_SAMPLED_1D
| TEXTURE_SAMPLED_1D_ARRAY
| TEXTURE_SAMPLED_2D
| TEXTURE_SAMPLED_2D_ARRAY
| TEXTURE_SAMPLED_2D_MS
| TEXTURE_SAMPLED_2D_MS_ARRAY
| TEXTURE_SAMPLED_3D
| TEXTURE_SAMPLED_CUBE
| TEXTURE_SAMPLED_CUBE_ARRAY

storage_texture_type
: TEXTURE_RO_1D
| TEXTURE_RO_1D_ARRAY
| TEXTURE_RO_2D
| TEXTURE_RO_2D_ARRAY
| TEXTURE_RO_3D
| TEXTURE_WO_1D
| TEXTURE_WO_1D_ARRAY
| TEXTURE_WO_2D
| TEXTURE_WO_2D_ARRAY
| TEXTURE_WO_3D

depth_texture_type
: TEXTURE_DEPTH_2D
| TEXTURE_DEPTH_2D_ARRAY
| TEXTURE_DEPTH_CUBE
| TEXTURE_DEPTH_CUBE_ARRAY

image_storage_type
: R8UNORM
R8 -- Capability: StorageImageExtendedFormats
| R8SNORM
R8Snorm -- Capability: StorageImageExtendedFormats
| R8UINT
R8ui -- Capability: StorageImageExtendedFormats
| R8SINT
R8i -- Capability: StorageImageExtendedFormats
| R16UINT
R16ui -- Capability: StorageImageExtendedFormats
| R16SINT
R16i -- Capability: StorageImageExtendedFormats
| R16FLOAT
R16f -- Capability: StorageImageExtendedFormats
| RG8UNORM
Rg8 -- Capability: StorageImageExtendedFormats
| RG8SNORM
Rg8Snorm -- Capability: StorageImageExtendedFormats
| RG8UINT
Rg8ui -- Capability: StorageImageExtendedFormats
| RG8SINT
Rg8i -- Capability: StorageImageExtendedFormats
| R32UINT
R32ui
| R32SINT
R32i
| R32FLOAT
R32f
| RG16UINT
Rg16ui -- Capability: StorageImageExtendedFormats
| RG16SINT
Rg16i -- Capability: StorageImageExtendedFormats
| RG16FLOAT
Rg16f -- Capability: StorageImageExtendedFormats
| RGBA8UNORM
Rgba8
| RGBA8UNORM-SRGB
???
| RGBA8SNORM
Rgba8Snorm
| RGBA8UINT
Rgba8ui
| RGBA8SINT
Rgba8i
| BGRA8UNORM
Rgba8 ???
| BGRA8UNORM-SRGB
???
| RGB10A2UNORM
Rgb10A2 -- Capability: StorageImageExtendedFormats
| RG11B10FLOAT
R11fG11fB10f -- Capability: StorageImageExtendedFormats
| RG32UINT
Rg32ui -- Capability: StorageImageExtendedFormats
| RG32SINT
Rg32i -- Capability: StorageImageExtendedFormats
| RG32FLOAT
Rg32f -- Capability: StorageImageExtendedFormats
| RGBA16UINT
Rgba16ui
| RGBA16SINT
Rgba16i
| RGBA16FLOAT
Rgba16f
| RGBA32UINT
Rgba32ui
| RGBA32SINT
Rgba32i
| RGBA32FLOAT
Rgba32f

variable_decoration_list
: ATTR_LEFT (variable_decoration COMMA)* variable_decoration ATTR_RIGHT

Expand Down