You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Used within a shader not much would change, the registers are (usually) 32bit anyway and you'd want to do the actual comparison directly afterwards anyway to reduce it to bools, which on many platforms have more compact storage. (eg. on AMD they represent bools by bits in a scalar register instead of using vector registers.)
The bigger issue is when the Ordering enum is written to or read from a buffer, as their representation between CPU and GPU would now differ and any struct containing Ordering as a member would me misaligned.
This would open up the discussion if we should automatically widen u8 and u16 to u32 for arbirary types that are used only within the shader, and whether to bitpack them automagically when loading / storing them to a buffer.
But honestly pretty much all desktop devices support U8 and U16 loads and stores anyway...
What about a way simpler solution: Overwrite the method {u8, u16, u32, ..., f32}::max and min to just do what f32::clamp does, which does not use the Ordinal enum at all:
pubfnclamp(mutself,min:f32,max:f32) -> f32{assert!(min <= max,"min > max, or either was NaN. min = {min:?}, max = {max:?}");ifself < min {self = min;}ifself > max {self = max;}self}
Exactly, it would just make those common methods work without breaking anything else. Now everything using Ordinal directly or implementing Ord / PartialOrd would still fail to compile without OpCapability U8. But I think that's a fine tradeoff, as comparing custom types is rarely done on GPUs anyway, whereas min and maxing int / floats is used everywhere.
Hello. In this issue, OpCapability U8 is mentioned. But I was unable to find anything about this on the Web. So I suppose you actually meant OpCapability Int8.
This issue was opened in November 2024. But in December 2024, Vulkan 1.4 was released. This new version made Vulkan's shaderInt8 feature, which maps to OpCapability Int8 in SPIR-V, a mandatory requirement.
So, I would like to suggest just adding an optional Vulkan 1.4 version gate that will just enable OpCapability Int8 for all generated SPIR-V bytecode. This will be a much easier solution than method override and the rabbit hole of integer promotion, and will make idiomatic Rust code (PartialOrd, u32::max, u32::min) work on an only increasing number of devices onwards.
If you think this is a good idea, I can look into this. :)
For completeness sake: Vulkan 1.4 requires both Int8 and Int16, source.
However, even though vulkan 1.4 drivers are required to offer those features, when you create your instance you must still enable them to tell the driver you want to use them. So us implicitly enabling them for the vk1.4 target requires end users to always enable the feature, even if they're not using them. And if you're on wgpu, you'll be big sad cause you don't get access to the VkInstanceCreateInfo to enable said features.
That's a decent amount of effort and pretty much everyone will disable it cause it makes getting rust-gpu up and running more complicated... don't see the value in adding that
Activity
LegNeato commentedon Nov 19, 2024
Wouldn't that mean it takes more space on devices that support OpCapability U8?
Firestar99 commentedon Nov 19, 2024
Used within a shader not much would change, the registers are (usually) 32bit anyway and you'd want to do the actual comparison directly afterwards anyway to reduce it to bools, which on many platforms have more compact storage. (eg. on AMD they represent bools by bits in a scalar register instead of using vector registers.)
The bigger issue is when the
Orderingenum is written to or read from a buffer, as their representation between CPU and GPU would now differ and any struct containingOrderingas a member would me misaligned.This would open up the discussion if we should automatically widen u8 and u16 to u32 for arbirary types that are used only within the shader, and whether to bitpack them automagically when loading / storing them to a buffer.
But honestly pretty much all desktop devices support U8 and U16 loads and stores anyway...
Firestar99 commentedon Nov 30, 2024
What about a way simpler solution: Overwrite the method
{u8, u16, u32, ..., f32}::maxandminto just do whatf32::clampdoes, which does not use theOrdinalenum at all:LegNeato commentedon Nov 30, 2024
What do we lose with that? I assume nothing?
Firestar99 commentedon Nov 30, 2024
Exactly, it would just make those common methods work without breaking anything else. Now everything using
Ordinaldirectly or implementingOrd/PartialOrdwould still fail to compile withoutOpCapability U8. But I think that's a fine tradeoff, as comparing custom types is rarely done on GPUs anyway, whereas min and maxing int / floats is used everywhere.LegNeato commentedon Nov 30, 2024
I assume the impl with Ordinal is there for a reason, so perhaps we could even switch back to that when
OpCapability U8is used.Fix cuda toolkit installation in CI (Rust-GPU#147)
mikwielgus commentedon Oct 9, 2026
Hello. In this issue,
OpCapability U8is mentioned. But I was unable to find anything about this on the Web. So I suppose you actually meantOpCapability Int8.This issue was opened in November 2024. But in December 2024, Vulkan 1.4 was released. This new version made Vulkan's
shaderInt8feature, which maps toOpCapability Int8in SPIR-V, a mandatory requirement.So, I would like to suggest just adding an optional Vulkan 1.4 version gate that will just enable
OpCapability Int8for all generatedSPIR-Vbytecode. This will be a much easier solution than method override and the rabbit hole of integer promotion, and will make idiomatic Rust code (PartialOrd,u32::max,u32::min) work on an only increasing number of devices onwards.If you think this is a good idea, I can look into this. :)
Firestar99 commentedon Oct 12, 2026
For completeness sake: Vulkan 1.4 requires both Int8 and Int16, source.
However, even though vulkan 1.4 drivers are required to offer those features, when you create your instance you must still enable them to tell the driver you want to use them. So us implicitly enabling them for the vk1.4 target requires end users to always enable the feature, even if they're not using them. And if you're on wgpu, you'll be big sad cause you don't get access to the VkInstanceCreateInfo to enable said features.
mikwielgus commentedon Oct 12, 2026
I wasn't aware of this, that's a bummer.
But then perhaps we could at least have something akin to the Rust's default features mechanism?
Firestar99 commentedon Oct 12, 2026
That's a decent amount of effort and pretty much everyone will disable it cause it makes getting rust-gpu up and running more complicated... don't see the value in adding that