Skip to content

describe texel formats (for storage texture types) - #1112

Merged
dneto0 merged 7 commits into
gpuweb:mainfrom
dneto0:describe-image-formats
Nov 18, 2020
Merged

dneto0 merged 7 commits into
gpuweb:mainfrom
dneto0:describe-image-formats

Conversation

@dneto0

@dneto0 dneto0 commented Sep 25, 2020

Copy link
Copy Markdown
Contributor

I'd like to describe textures in more detail so we can more precisely describe the return type on texture builtin functions, and the sampled component type on sampled texture types.
I'd like to point back to a table in the "Texel formats" section introduced in this PR.

@dneto0
dneto0 marked this pull request as draft September 25, 2020 22:51
@dneto0
dneto0 force-pushed the describe-image-formats branch from cf3d473 to 89ab927 Compare September 25, 2020 22:53
@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Sep 25, 2020
@dneto0 dneto0 self-assigned this Sep 25, 2020
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
@dneto0
dneto0 force-pushed the describe-image-formats branch from f138b03 to 3e49e47 Compare September 25, 2020 23:14
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Outdated
<table class='data'>
<caption>Channel types</caption>
<thead>
<tr><td>Channel type<td>Number of stored bits<td>Interpetation of stored bits<td>Shader type<td>Shader value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd suggest changing this to 1 line per td to make it easier to read/work with

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did that for the headings.
But I left the rows as-is. I find it easier to both edit and scan for differences when they're horizontally organized

Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Outdated
A <dfn noexport>texel</dfn> is a scalar or vector used as the smallest independently addressible element of a [=texture=].
The word *texel* is short for *texture element*.

A <dfn noexport>texture</dfn> is a grid of texels supporting special operations useful for rendering.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: multi-dimensional grid (it can be 1, 2, 3 or even 4 if when we support 2D array multisampled textures)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The bullet points below describe dimensionality, and say it's 1,2,3 dimensions. There is also array-size, when the texture is arrayed.

Note that the compute shader workgroup-grid is 3-dimensional without explicitly calling it out as multi-dimensional.

Comment thread wgsl/index.bs Outdated
including data layouts, data types, and operations that cannot be expressed directly in the shader language.
Each texel has a unique grid coordinate within the texture.

An <dfn noexport>arrayed texture</dfn> is a texture which is organized as a homegeneous array of grids of texels.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: isn't the arrayness just an extra dimension for the multi-dimensional grid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was hoping to treat the array index specially. The regular grid coordinates have interpolation applied to them, but the array index does not. I suggest we add a note to revisit this editorially

Comment thread wgsl/index.bs Outdated

A texture has the following features:

: <dfn noexport>texel format</dfn>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about mip levels?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I've yet to capture that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added mip levels now. Thanks!

Comment thread wgsl/index.bs Outdated
<tr><td>8uint<td>8<td>unsigned integer |v| &isinv; {0,...,255}<td>u32<td> |v| &div; 255
<tr><td>8sint<td>8<td>signed integer |v| &isinv; {-128,...,127}<td>i32<td> |v| &div; 128
<tr><td>16uint<td>16<td>unsigned integer |v| &isinv; {0,...,65535}<td>u32<td> |v| &div; 65535
<tr><td>16sint<td>16<td>signed integer |v| &isinv; {-32768,...,32767}<td>i32<td> |v| &div; 32768

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that the WGSL spec should talk about the exact bit representation of texture, because there's weird formats like rgb9e5 and compressed ones. Only the component type matters, except for storage textures (which can have an exact bit representation described in this spec).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there is still value in describing the formats we do know and guarantee, such as 8unorm. For rgb9e5 we can figure something out and say it's more platform-dependent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand, should the WGSL spec just tell you that when you sample a texture with floating point component type you get an f32 and what f32 you get is described by the texture sampling part of the WebGPU specification? This way WGSL wouldn't care if it is r8unorm rg16float or bc1-rgba-unorm?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

well, I'm saying that it's generally useful that, for example, an r8unorm is one of the values between 0/255 and 255/255. This allows authors to adjust their expectations on sampling, or when writing to the color outputs.
Where exactly this is specified (WGSL or WebGPU spec) is not something that I feel strongly about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only reason WGSL needs texel-formats is to parameterize storage textures. The sampled and depth textures do not, and I'd like to eliminate those weirdly-shaped texel formats from the WGSL spec entirely.

See the modifications to the texture-ro and texture-wo sections in this MR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After removing the texel formats that require SPIR-V capability StorageImageExtendedFormats, we're left with:

  • r32uint
  • r32sint
  • r32float
  • rgba8unorm
  • rgba8snorm
  • rgba8uint
  • rgba8sint

I can delete all the other ones from the tables, and make this much simpler.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

where did 32-bit RG and RGBA formats go?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like rgba32float and rgba32ui, rgba32i are missing from list above but all of the rg formats appear to be in StorageImageExtendedFormats. https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#Image_Format

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting! So this is different from what Vulkan requires. I guess the StorageImageExtendedFormats on the SPIR-V side becomes an implementation detail, and we don't need to care about it on the API side.
Please just follow the table we have in the spec - https://gpuweb.github.io/gpuweb/#plain-color-formats

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had been reading the required format support for Vulkan. But I have not been following what was worked out already for WebGPU.
I'll follow the WebGPU table. Thanks!

Comment thread wgsl/index.bs Outdated
The word *texel* is short for *texture element*.

A <dfn noexport>texture</dfn> is a grid of texels supporting special operations useful for rendering.
A texture's representation is typically optimized for those operations, with many details hidden from the programmer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's a bit weird to call them "special operations useful for rendering" and then follow with "those operations", which assumes the users know what they are. Would be good to provide examples here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to defer those to the details of builtin functions. That's why later in this introductory section we get into the fact there's no direct access to texture storage and that everything is determined by the set of available texture builtins.

Maybe I can think of something that points forward to the builtins without going into details.

Frankly, I'm concerned about having to describe sampling operations. I'd rather not do that in the WGSL spec. Like, there's a lot of content in Vulkan's "14. Image operations". https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#textures

Comment thread wgsl/index.bs Outdated
<tr><td>8uint<td>8<td>unsigned integer |v| &isinv; {0,...,255}<td>u32<td> |v| &div; 255
<tr><td>8sint<td>8<td>signed integer |v| &isinv; {-128,...,127}<td>i32<td> |v| &div; 128
<tr><td>16uint<td>16<td>unsigned integer |v| &isinv; {0,...,65535}<td>u32<td> |v| &div; 65535
<tr><td>16sint<td>16<td>signed integer |v| &isinv; {-32768,...,32767}<td>i32<td> |v| &div; 32768

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there is still value in describing the formats we do know and guarantee, such as 8unorm. For rgb9e5 we can figure something out and say it's more platform-dependent.

@dneto0
dneto0 marked this pull request as ready for review September 28, 2020 22:14
@dneto0 dneto0 changed the title WIP: describe texel formats describe texel formats (for storage texture types) Sep 29, 2020
@dneto0

dneto0 commented Sep 29, 2020

Copy link
Copy Markdown
Contributor Author

@dneto0

dneto0 commented Sep 29, 2020

Copy link
Copy Markdown
Contributor Author

TODO: capture the concept of mip-levels.

Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Outdated
of the shader value to a stored texel value.
A write-only storage texture type is parameterized by a [=texel format=], which in turn
determines the conversion function as specified in [[#texel-formats]].
The *inverse* of the transfer function is used to convert the shader value to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it says "conversion function" and then "transfer function". Is this the same thing?

Comment thread wgsl/index.bs Outdated
of the shader value to a stored texel value.
A write-only storage texture type is parameterized by a [=texel format=], which in turn
determines the conversion function as specified in [[#texel-formats]].
The *inverse* of the transfer function is used to convert the shader value to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's not clear how the inversion works, i.e. would the values be rounded or truncated, for example

@dneto0

dneto0 commented Sep 29, 2020

Copy link
Copy Markdown
Contributor Author

@dneto0
dneto0 force-pushed the describe-image-formats branch from d4f2220 to 935e49a Compare September 29, 2020 17:59
@dneto0

dneto0 commented Sep 29, 2020

Copy link
Copy Markdown
Contributor Author

Rebased against main, and I've updated the gist preview

@kvark

kvark commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

My comment may have been lost, so repeating it here. Why did you remove RG32 and RGBA32 formats?

@dj2

dj2 commented Oct 1, 2020

Copy link
Copy Markdown
Member

The RG32 formats require StorageImageExtendedFormats. Looks like the RGBA32 ones are missing.

https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#Image_Format

@kvark

kvark commented Oct 2, 2020

Copy link
Copy Markdown
Contributor

@dj2 see #1112 (comment)

@dneto0

dneto0 commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

I've made the list of storage texture formats match what's already listed in the WebGPU table.

That adds the Rg32* formats. Even though those have mandatory in Vulkan, they still require the StorageImageExtendedFormats capability in SPIR-V. So I added back the "SPIR-V enabling capability" column.

I've updated the HTML preview: https://gistpreview.github.io/?4c60af08a8b1cca4501abecc93beae3f#texel-formats

I've added TODOs to move the description about how storage texture accesses work down to the texture builtins section. The write access needs a more explicitly spelled out description.

@dneto0
dneto0 force-pushed the describe-image-formats branch from 5b6339c to b858722 Compare October 26, 2020 19:49
@dneto0

dneto0 commented Oct 26, 2020

Copy link
Copy Markdown
Contributor Author

I've rebased against main, and collapsed the previous contents into a single commit.

@dneto0

dneto0 commented Oct 26, 2020

Copy link
Copy Markdown
Contributor Author

I've updated the HTML preview at https://gistpreview.github.io/?4c60af08a8b1cca4501abecc93beae3f

Note that other texture type changes are already in flight: #1180, #1182

I'd like to get these changes approved, modulo those other changes, which are basically orthogonal.

@dneto0
dneto0 force-pushed the describe-image-formats branch from b858722 to b034fc3 Compare November 9, 2020 23:39
@dneto0

dneto0 commented Nov 9, 2020

Copy link
Copy Markdown
Contributor Author

I've rebased on top of recent renamings of storage texture types, and:

  • added cross-references to WebGPU concepts
  • added mip levels to the list of texture properties.
  • fixed wordings.

Please take a look.

@github-actions

github-actions Bot commented Nov 9, 2020

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
b034fc3

@grorg

grorg commented Nov 17, 2020 •

Copy link
Copy Markdown
Contributor

Discussed at 2020-11-17 meeting.

Resolved: Accepted.

Comment thread wgsl/index.bs Resolved
- Drafted high level description of textures.

- Define texel formats
  - define texel formats in terms of channel format and channels
  - define correspondence to SPIR-V image formats
  - Describe how storage texture types are parameterized by texel formats.

- Fix 2D dimensionality on some OpTypeImage translations

- Fix signed/unsigned in 32-bit channel formats

- Respond to feedback
  - add brief forward reference to rendering operations as being invoked
  via texture builtins, then point to the sectionn.
  - Reorganized arrayed and non-arrayed textures as the two kinds of
  textures (hence as bullet points)
  - Add TODO for mip levels

- Specify defined shader values for missing texel format channels
  See gpuweb#1115

- Remove SPIR-V capability column for texel formats
  We will not allow storage images over texel formats
  requiring StorageImageExtendedFormats.  We will only use
  those enabled by the basic Shader capability, so there is no
  reason to list them.

- Only keep texel formats used for storage textures

- Match list of storage texture formats from WebGPU API

- Add cross-reference to texel formats table

- Add TODOs to move and strengthen the description of storage texture
  accesses down to where the texture builtin functions are described.

@mehmetoguzderin mehmetoguzderin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

@dneto0
dneto0 merged commit 01c7c57 into gpuweb:main Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wgsl WebGPU Shading Language Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants