Skip to content

Commit

Permalink
Allow 64-bit hex literals and const-evaluate unary ops (#6616)
Browse files Browse the repository at this point in the history
* Allow 64-bit hex literals

* Implement const evaluation for unary 64-bit ops

* Test 64-bit hex literals

* Add changelog entry
  • Loading branch information
SludgePhD authored Nov 26, 2024
1 parent 3016c56 commit a9f14c7
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 709 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]

- Fix an issue where `naga` CLI would incorrectly skip the first positional argument when `--stdin-file-path` was specified. By @ErichDonGubler in [#6480](https://github.com/gfx-rs/wgpu/pull/6480).
- Fix textureNumLevels in the GLSL backend. By @magcius in [#6483](https://github.com/gfx-rs/wgpu/pull/6483).
- Support 64-bit hex literals and unary operations in constants [#6616](https://github.com/gfx-rs/wgpu/pull/6616).
- Implement `quantizeToF16()` for WGSL frontend, and WGSL, SPIR-V, HLSL, MSL, and GLSL backends. By @jamienicol in [#6519](https://github.com/gfx-rs/wgpu/pull/6519).
- Add support for GLSL `usampler*` and `isampler*`. By @DavidPeicho in [#6513](https://github.com/gfx-rs/wgpu/pull/6513).

Expand Down Expand Up @@ -128,7 +129,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]

- Handle query set creation failure as an internal error that loses the `Device`, rather than panicking. By @ErichDonGubler in [#6505](https://github.com/gfx-rs/wgpu/pull/6505).
- Ensure that `Features::TIMESTAMP_QUERY` is set when using timestamp writes in render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Check for device mismatches when beginning render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Check for device mismatches when beginning render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Lower `QUERY_SET_MAX_QUERIES` (and enforced limits) from 8192 to 4096 to match WebGPU spec. By @ErichDonGubler in [#6525](https://github.com/gfx-rs/wgpu/pull/6525).
- Allow non-filterable float on texture bindings never used with samplers when using a derived bind group layout. By @ErichDonGubler in [#6531](https://github.com/gfx-rs/wgpu/pull/6531/).
- Replace potentially unsound usage of `PreHashedMap` with `FastHashMap`. By @jamienicol in [#6541](https://github.com/gfx-rs/wgpu/pull/6541).
Expand Down
7 changes: 6 additions & 1 deletion naga/src/front/wgsl/parse/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ fn parse(input: &str) -> (Result<Number, NumberError>, &str) {
rest_to_str!(bytes),
)
} else {
let kind = consume_map!(bytes, [b'i' => IntKind::I32, b'u' => IntKind::U32]);
let kind = consume_map!(bytes, [
b'i' => IntKind::I32,
b'u' => IntKind::U32,
b'l', b'i' => IntKind::I64,
b'l', b'u' => IntKind::U64,
]);

(parse_hex_int(digits, kind), rest_to_str!(bytes))
}
Expand Down
3 changes: 3 additions & 0 deletions naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,7 @@ impl<'a> ConstantEvaluator<'a> {
Expression::Literal(value) => Expression::Literal(match op {
UnaryOperator::Negate => match value {
Literal::I32(v) => Literal::I32(v.wrapping_neg()),
Literal::I64(v) => Literal::I64(v.wrapping_neg()),
Literal::F32(v) => Literal::F32(-v),
Literal::AbstractInt(v) => Literal::AbstractInt(v.wrapping_neg()),
Literal::AbstractFloat(v) => Literal::AbstractFloat(-v),
Expand All @@ -1753,7 +1754,9 @@ impl<'a> ConstantEvaluator<'a> {
},
UnaryOperator::BitwiseNot => match value {
Literal::I32(v) => Literal::I32(!v),
Literal::I64(v) => Literal::I64(!v),
Literal::U32(v) => Literal::U32(!v),
Literal::U64(v) => Literal::U64(!v),
Literal::AbstractInt(v) => Literal::AbstractInt(!v),
_ => return Err(ConstantEvaluatorError::InvalidUnaryOpArg),
},
Expand Down
6 changes: 3 additions & 3 deletions naga/tests/in/int64.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var<storage, read_write> output_arrays: StorageCompatible;
fn int64_function(x: i64) -> i64 {
var val: i64 = i64(constant_variable);
// A number too big for i32
val += 31li - 1002003004005006li;
val += 31li - 1002003004005006li + -0x7fffffffffffffffli;
// Constructing an i64 from an AbstractInt
val += val + i64(5);
// Constructing a i64 from other types and other types from u64.
Expand Down Expand Up @@ -89,8 +89,8 @@ fn int64_function(x: i64) -> i64 {

fn uint64_function(x: u64) -> u64 {
var val: u64 = u64(constant_variable);
// A number too big for u32
val += 31lu + 1002003004005006lu;
// Numbers too big for u32 (u64::MAX)
val += 31lu + 18446744073709551615lu - 0xfffffffffffffffflu;
// Constructing a u64 from an AbstractInt
val += val + u64(5);
// Constructing a u64 from other types and other types from u64.
Expand Down
226 changes: 113 additions & 113 deletions naga/tests/out/hlsl/int64.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -63,81 +63,81 @@ int64_t int64_function(int64_t x)
{
int64_t val = 20L;

int64_t _e6 = val;
val = (_e6 + (31L - 1002003004005006L));
int64_t _e8 = val;
int64_t _e11 = val;
val = (_e11 + (_e8 + 5L));
uint _e15 = input_uniform.val_u32_;
int64_t _e16 = val;
int64_t _e20 = val;
val = (_e20 + int64_t((_e15 + uint(_e16))));
int _e24 = input_uniform.val_i32_;
int64_t _e25 = val;
int64_t _e29 = val;
val = (_e29 + int64_t((_e24 + int(_e25))));
float _e33 = input_uniform.val_f32_;
int64_t _e34 = val;
int64_t _e38 = val;
val = (_e38 + int64_t((_e33 + float(_e34))));
int64_t _e42 = input_uniform.val_i64_;
int64_t _e45 = val;
val = (_e45 + (_e42).xxx.z);
uint64_t _e49 = input_uniform.val_u64_;
int64_t _e51 = val;
val = (_e51 + _e49);
uint64_t2 _e55 = input_uniform.val_u64_2_;
int64_t _e58 = val;
val = (_e58 + _e55.y);
uint64_t3 _e62 = input_uniform.val_u64_3_;
int64_t _e65 = val;
val = (_e65 + _e62.z);
uint64_t4 _e69 = input_uniform.val_u64_4_;
int64_t _e72 = val;
val = (_e72 + _e69.w);
int64_t _e78 = input_uniform.val_i64_;
int64_t _e81 = input_storage.Load<int64_t>(128);
output.Store(128, (_e78 + _e81));
int64_t2 _e87 = input_uniform.val_i64_2_;
int64_t2 _e90 = input_storage.Load<int64_t2>(144);
output.Store(144, (_e87 + _e90));
int64_t3 _e96 = input_uniform.val_i64_3_;
int64_t3 _e99 = input_storage.Load<int64_t3>(160);
output.Store(160, (_e96 + _e99));
int64_t4 _e105 = input_uniform.val_i64_4_;
int64_t4 _e108 = input_storage.Load<int64_t4>(192);
output.Store(192, (_e105 + _e108));
int64_t _e114[2] = Constructarray2_int64_t_(input_arrays.Load<int64_t>(16+0), input_arrays.Load<int64_t>(16+8));
val = (_e8 + ((31L - 1002003004005006L) + -9223372036854775807L));
int64_t _e10 = val;
int64_t _e13 = val;
val = (_e13 + (_e10 + 5L));
uint _e17 = input_uniform.val_u32_;
int64_t _e18 = val;
int64_t _e22 = val;
val = (_e22 + int64_t((_e17 + uint(_e18))));
int _e26 = input_uniform.val_i32_;
int64_t _e27 = val;
int64_t _e31 = val;
val = (_e31 + int64_t((_e26 + int(_e27))));
float _e35 = input_uniform.val_f32_;
int64_t _e36 = val;
int64_t _e40 = val;
val = (_e40 + int64_t((_e35 + float(_e36))));
int64_t _e44 = input_uniform.val_i64_;
int64_t _e47 = val;
val = (_e47 + (_e44).xxx.z);
uint64_t _e51 = input_uniform.val_u64_;
int64_t _e53 = val;
val = (_e53 + _e51);
uint64_t2 _e57 = input_uniform.val_u64_2_;
int64_t _e60 = val;
val = (_e60 + _e57.y);
uint64_t3 _e64 = input_uniform.val_u64_3_;
int64_t _e67 = val;
val = (_e67 + _e64.z);
uint64_t4 _e71 = input_uniform.val_u64_4_;
int64_t _e74 = val;
val = (_e74 + _e71.w);
int64_t _e80 = input_uniform.val_i64_;
int64_t _e83 = input_storage.Load<int64_t>(128);
output.Store(128, (_e80 + _e83));
int64_t2 _e89 = input_uniform.val_i64_2_;
int64_t2 _e92 = input_storage.Load<int64_t2>(144);
output.Store(144, (_e89 + _e92));
int64_t3 _e98 = input_uniform.val_i64_3_;
int64_t3 _e101 = input_storage.Load<int64_t3>(160);
output.Store(160, (_e98 + _e101));
int64_t4 _e107 = input_uniform.val_i64_4_;
int64_t4 _e110 = input_storage.Load<int64_t4>(192);
output.Store(192, (_e107 + _e110));
int64_t _e116[2] = Constructarray2_int64_t_(input_arrays.Load<int64_t>(16+0), input_arrays.Load<int64_t>(16+8));
{
int64_t _value2[2] = _e114;
int64_t _value2[2] = _e116;
output_arrays.Store(16+0, _value2[0]);
output_arrays.Store(16+8, _value2[1]);
}
int64_t _e115 = val;
int64_t _e117 = val;
val = (_e117 + abs(_e115));
int64_t _e119 = val;
int64_t _e120 = val;
val = (_e119 + abs(_e117));
int64_t _e121 = val;
int64_t _e122 = val;
int64_t _e123 = val;
val = (_e123 + clamp(_e119, _e120, _e121));
int64_t _e125 = val;
val = (_e125 + clamp(_e121, _e122, _e123));
int64_t _e127 = val;
int64_t _e130 = val;
val = (_e130 + dot((_e125).xx, (_e127).xx));
int64_t _e129 = val;
int64_t _e132 = val;
int64_t _e133 = val;
val = (_e132 + dot((_e127).xx, (_e129).xx));
int64_t _e134 = val;
int64_t _e135 = val;
val = (_e135 + max(_e132, _e133));
int64_t _e137 = val;
int64_t _e138 = val;
val = (_e137 + max(_e134, _e135));
int64_t _e139 = val;
int64_t _e140 = val;
val = (_e140 + min(_e137, _e138));
int64_t _e142 = val;
val = (_e142 + min(_e139, _e140));
int64_t _e144 = val;
val = (_e144 + sign(_e142));
int64_t _e146 = val;
return _e146;
val = (_e146 + sign(_e144));
int64_t _e148 = val;
return _e148;
}

typedef uint64_t ret_Constructarray2_uint64_t_[2];
Expand All @@ -150,78 +150,78 @@ uint64_t uint64_function(uint64_t x_1)
{
uint64_t val_1 = 20uL;

uint64_t _e6 = val_1;
val_1 = (_e6 + (31uL + 1002003004005006uL));
uint64_t _e8 = val_1;
uint64_t _e11 = val_1;
val_1 = (_e11 + (_e8 + 5uL));
uint _e15 = input_uniform.val_u32_;
uint64_t _e16 = val_1;
uint64_t _e20 = val_1;
val_1 = (_e20 + uint64_t((_e15 + uint(_e16))));
int _e24 = input_uniform.val_i32_;
uint64_t _e25 = val_1;
uint64_t _e29 = val_1;
val_1 = (_e29 + uint64_t((_e24 + int(_e25))));
float _e33 = input_uniform.val_f32_;
uint64_t _e34 = val_1;
uint64_t _e38 = val_1;
val_1 = (_e38 + uint64_t((_e33 + float(_e34))));
uint64_t _e42 = input_uniform.val_u64_;
uint64_t _e45 = val_1;
val_1 = (_e45 + (_e42).xxx.z);
int64_t _e49 = input_uniform.val_i64_;
uint64_t _e51 = val_1;
val_1 = (_e51 + _e49);
int64_t2 _e55 = input_uniform.val_i64_2_;
uint64_t _e58 = val_1;
val_1 = (_e58 + _e55.y);
int64_t3 _e62 = input_uniform.val_i64_3_;
uint64_t _e65 = val_1;
val_1 = (_e65 + _e62.z);
int64_t4 _e69 = input_uniform.val_i64_4_;
uint64_t _e72 = val_1;
val_1 = (_e72 + _e69.w);
uint64_t _e78 = input_uniform.val_u64_;
uint64_t _e81 = input_storage.Load<uint64_t>(16);
output.Store(16, (_e78 + _e81));
uint64_t2 _e87 = input_uniform.val_u64_2_;
uint64_t2 _e90 = input_storage.Load<uint64_t2>(32);
output.Store(32, (_e87 + _e90));
uint64_t3 _e96 = input_uniform.val_u64_3_;
uint64_t3 _e99 = input_storage.Load<uint64_t3>(64);
output.Store(64, (_e96 + _e99));
uint64_t4 _e105 = input_uniform.val_u64_4_;
uint64_t4 _e108 = input_storage.Load<uint64_t4>(96);
output.Store(96, (_e105 + _e108));
uint64_t _e114[2] = Constructarray2_uint64_t_(input_arrays.Load<uint64_t>(0+0), input_arrays.Load<uint64_t>(0+8));
val_1 = (_e8 + ((31uL + 18446744073709551615uL) - 18446744073709551615uL));
uint64_t _e10 = val_1;
uint64_t _e13 = val_1;
val_1 = (_e13 + (_e10 + 5uL));
uint _e17 = input_uniform.val_u32_;
uint64_t _e18 = val_1;
uint64_t _e22 = val_1;
val_1 = (_e22 + uint64_t((_e17 + uint(_e18))));
int _e26 = input_uniform.val_i32_;
uint64_t _e27 = val_1;
uint64_t _e31 = val_1;
val_1 = (_e31 + uint64_t((_e26 + int(_e27))));
float _e35 = input_uniform.val_f32_;
uint64_t _e36 = val_1;
uint64_t _e40 = val_1;
val_1 = (_e40 + uint64_t((_e35 + float(_e36))));
uint64_t _e44 = input_uniform.val_u64_;
uint64_t _e47 = val_1;
val_1 = (_e47 + (_e44).xxx.z);
int64_t _e51 = input_uniform.val_i64_;
uint64_t _e53 = val_1;
val_1 = (_e53 + _e51);
int64_t2 _e57 = input_uniform.val_i64_2_;
uint64_t _e60 = val_1;
val_1 = (_e60 + _e57.y);
int64_t3 _e64 = input_uniform.val_i64_3_;
uint64_t _e67 = val_1;
val_1 = (_e67 + _e64.z);
int64_t4 _e71 = input_uniform.val_i64_4_;
uint64_t _e74 = val_1;
val_1 = (_e74 + _e71.w);
uint64_t _e80 = input_uniform.val_u64_;
uint64_t _e83 = input_storage.Load<uint64_t>(16);
output.Store(16, (_e80 + _e83));
uint64_t2 _e89 = input_uniform.val_u64_2_;
uint64_t2 _e92 = input_storage.Load<uint64_t2>(32);
output.Store(32, (_e89 + _e92));
uint64_t3 _e98 = input_uniform.val_u64_3_;
uint64_t3 _e101 = input_storage.Load<uint64_t3>(64);
output.Store(64, (_e98 + _e101));
uint64_t4 _e107 = input_uniform.val_u64_4_;
uint64_t4 _e110 = input_storage.Load<uint64_t4>(96);
output.Store(96, (_e107 + _e110));
uint64_t _e116[2] = Constructarray2_uint64_t_(input_arrays.Load<uint64_t>(0+0), input_arrays.Load<uint64_t>(0+8));
{
uint64_t _value2[2] = _e114;
uint64_t _value2[2] = _e116;
output_arrays.Store(0+0, _value2[0]);
output_arrays.Store(0+8, _value2[1]);
}
uint64_t _e115 = val_1;
uint64_t _e117 = val_1;
val_1 = (_e117 + abs(_e115));
uint64_t _e119 = val_1;
uint64_t _e120 = val_1;
val_1 = (_e119 + abs(_e117));
uint64_t _e121 = val_1;
uint64_t _e122 = val_1;
uint64_t _e123 = val_1;
val_1 = (_e123 + clamp(_e119, _e120, _e121));
uint64_t _e125 = val_1;
val_1 = (_e125 + clamp(_e121, _e122, _e123));
uint64_t _e127 = val_1;
uint64_t _e130 = val_1;
val_1 = (_e130 + dot((_e125).xx, (_e127).xx));
uint64_t _e129 = val_1;
uint64_t _e132 = val_1;
uint64_t _e133 = val_1;
val_1 = (_e132 + dot((_e127).xx, (_e129).xx));
uint64_t _e134 = val_1;
uint64_t _e135 = val_1;
val_1 = (_e135 + max(_e132, _e133));
uint64_t _e137 = val_1;
uint64_t _e138 = val_1;
val_1 = (_e137 + max(_e134, _e135));
uint64_t _e139 = val_1;
uint64_t _e140 = val_1;
val_1 = (_e140 + min(_e137, _e138));
uint64_t _e142 = val_1;
return _e142;
val_1 = (_e142 + min(_e139, _e140));
uint64_t _e144 = val_1;
return _e144;
}

[numthreads(1, 1, 1)]
Expand Down
Loading

0 comments on commit a9f14c7

Please sign in to comment.