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

Initial Atomic<T> type implementation. #5125

Merged
merged 16 commits into from
Sep 20, 2024
Merged

Conversation

csyonghe
Copy link
Collaborator

@csyonghe csyonghe commented Sep 20, 2024

Closes #5084.

Todo: test new Atomic type for all existing targets as well as wgsl target.

@csyonghe csyonghe added the pr: non-breaking PRs without breaking changes label Sep 20, 2024
enum MemoryOrder
{
Relaxed = $(kIRMemoryOrder_Relaxed),
SeqCst = $(kIRMemoryOrder_SeqCst),

Choose a reason for hiding this comment

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

FWIW Vulkan doesn't actually support sequentially consistent atomics. We do support AcquireRelease which is close, but doesn't support some obscure use cases. I think it would be fine to only have Relaxed for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. SeqCst was added because metal supports it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess we can have AcquireRelease here and map it to SeqCst on metal.

Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Comment on lines +2789 to +2792
__intrinsic_op($(kIROp_AtomicInc))
[__ref] T increment(MemoryOrder order = MemoryOrder.Relaxed);
__intrinsic_op($(kIROp_AtomicDec))
[__ref] T decrement(MemoryOrder order = MemoryOrder.Relaxed);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would they return the original value too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, all atomic methods returns original values.

Comment on lines +2744 to +2745
extension float : IArithmeticAtomicable {}
extension half : IArithmeticAtomicable {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The interface definition is fine, because IArithmeticAtomicable is IAtomicable, and compareExchange is a IAtomicable method.

However this reminds me that the currently code emit logic for floating point atomics on HLSL is wrong. We should be using the InterlockedAddF32/F16 etc instead of InterlockedAdd.

source/slang/slang-emit-metal.cpp Show resolved Hide resolved
@csyonghe
Copy link
Collaborator Author

I am going to merge this first, and then attempt to fix the floating point intrinsics on hlsl later.

@csyonghe csyonghe merged commit 4908349 into shader-slang:master Sep 20, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WGSL: Intrinsics: atomics
3 participants