Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elaborate conversions #983

Merged
merged 1 commit into from Sep 2, 2020
Merged

Elaborate conversions #983

merged 1 commit into from Sep 2, 2020

Conversation

dneto0
Copy link
Contributor

@dneto0 dneto0 commented Aug 7, 2020

  • Add a table for vector-value conversions
  • Define signed/unsigned reinterpration as equality modulo 2**32
  • Write a "floating point conversion" section, with TODOs for uncertain
    parts

@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Aug 7, 2020
@dneto0 dneto0 added this to the MVP milestone Aug 7, 2020
@dneto0 dneto0 added this to Under Discussion in WGSL Aug 7, 2020
@dneto0
Copy link
Contributor Author

dneto0 commented Aug 7, 2020

I left TODOs for conversion from floating point to integral, where there is rounding required or the result would be out of bounds.

wgsl/index.bs Outdated Show resolved Hide resolved
* Otherwise, the original value is not exactly representable.
* If the original value is different from but lies between two adjact values representable in the destination type,
then the result is one of those two values.
[SHORTNAME] does not specify whether the larger or smaller representable
Copy link
Member

Choose a reason for hiding this comment

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

Can we choose which one it is and have it specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be specifying the rounding mode.
Vulkan leaves that as an implementation detail.

https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#fundamentals-fp-conversion

When a value is converted to a defined floating-point representation, finite values falling between two representable finite values are rounded to one or the other. The rounding mode is not defined.

Note that OpenCL C has explicit conversion functions where the programmer can choose the rounding mode: rtz, rte, rtn, rtp
See https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#explicit-conversions (subsection "Rounding modes")

It would be extra cost to enforce a rounding mode.

Note: OpenCL C has a 'nextafter' builtin function that returns the next-larger representable floating point value, and I think you can exploit that.
(If memory serves correctly, nextafter is almost the same as as<f32>(1+as<u32>(x)) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an issue for this discussion.

@dneto0
Copy link
Contributor Author

dneto0 commented Aug 31, 2020

Rebased. Please take another look: @dj2

@dneto0 dneto0 moved this from Under Discussion to For Next Meeting in WGSL Aug 31, 2020
- Add a table for vector-value conversions
- Define signed/unsigned reinterpration as equality modulo 2**32
- Write a "floating point conversion" section, with TODOs for uncertain
  parts
- Add an issue for whether default rounding mode should be
  implementation-dependent
@dneto0
Copy link
Contributor Author

dneto0 commented Sep 1, 2020

I posted a gist of the result: https://gistpreview.github.io/?496822ce8507504fa349aad6c9826473#conversion-expr

(Go to the "Conversion expressions" section)

@grorg
Copy link
Contributor

grorg commented Sep 1, 2020

Discussed at 2020-09-01 meeting.

@dj2 dj2 merged commit 25524af into gpuweb:main Sep 2, 2020
WGSL automation moved this from For Next Meeting to Done Sep 2, 2020
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
…puweb#983)

* Implement validation,createRenderPipeline,pipeline_output_targets,blend_min_max

* Address reviewer's comments
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
WGSL
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants