gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.62k stars 925 forks source link

Possible f32 to u32 conversion bug #6057

Open JMS55 opened 3 months ago

JMS55 commented 3 months ago

Description Using renderdoc, the conversion from f32 to u32 seems wrong in my shader.

Repro steps

_385 = -1.07374E+08
uint _396 = ConvertFToU(_395);
_396 = 4187593120 // Shouldn't this be 0?

Expected vs observed behavior I think the result should be 0u. It's not even u32::MAX, so something's weird.

Extra materials https://gpuweb.github.io/gpuweb/wgsl/#floating-point-conversion

Platform

2024-07-28T20:58:02.528730Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Home", kernel: "22631", cpu: "AMD Ryzen 5 2600 Six-Core Processor", core_count: "6", memory: "15.9 GiB" }
2024-07-28T20:58:03.450199Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3080", vendor: 4318, device: 8710, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "551.61", backend: Vulkan }

wgpu 0.21

JMS55 commented 3 months ago

This might be a weird renderdoc bug, not sure. I'd like confirmation though that u32(negative_float) is always 0, or if that's not what the spec is saying.

teoxoy commented 3 months ago

u32(negative_float) should be 0. But why do the repro steps contain ConvertFToU(_395)? that should be u32(_395).

This might be a weird renderdoc bug, not sure.

It would be worth investigating.

JMS55 commented 3 months ago

FYI this is naga's spirv output from a wgsl shader.