writer/hlsl: Implement atomics

Storage buffers are emitted as `ByteAddressBuffer`s in HLSL, so we have to jump through hoops to support atomic ops on storage buffer atomics.
Workgroup atomics are far more conventional, but very little code can be shared between these two code paths.

Bug: tint:892
Change-Id: If10ea866e3b67a093e87aca689d34065fd49b705
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54651
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-06-18 18:56:13 +00:00
committed by Ben Clayton
parent 0a32a724f4
commit e6d171ac66
68 changed files with 1819 additions and 830 deletions

View File

@@ -88,6 +88,19 @@ bool IsBarrierIntrinsic(IntrinsicType i) {
i == IntrinsicType::kStorageBarrier;
}
bool IsAtomicIntrinsic(IntrinsicType i) {
return i == sem::IntrinsicType::kAtomicLoad ||
i == sem::IntrinsicType::kAtomicStore ||
i == sem::IntrinsicType::kAtomicAdd ||
i == sem::IntrinsicType::kAtomicMax ||
i == sem::IntrinsicType::kAtomicMin ||
i == sem::IntrinsicType::kAtomicAnd ||
i == sem::IntrinsicType::kAtomicOr ||
i == sem::IntrinsicType::kAtomicXor ||
i == sem::IntrinsicType::kAtomicExchange ||
i == sem::IntrinsicType::kAtomicCompareExchangeWeak;
}
Intrinsic::Intrinsic(IntrinsicType type,
sem::Type* return_type,
const ParameterList& parameters,
@@ -136,5 +149,9 @@ bool Intrinsic::IsBarrier() const {
return IsBarrierIntrinsic(type_);
}
bool Intrinsic::IsAtomic() const {
return IsAtomicIntrinsic(type_);
}
} // namespace sem
} // namespace tint

View File

@@ -69,6 +69,11 @@ bool IsDataUnpackingIntrinsic(IntrinsicType i);
/// @returns true if the given `i` is a barrier intrinsic
bool IsBarrierIntrinsic(IntrinsicType i);
/// Determines if the given `i` is a atomic intrinsic
/// @param i the intrinsic
/// @returns true if the given `i` is a atomic intrinsic
bool IsAtomicIntrinsic(IntrinsicType i);
/// Intrinsic holds the semantic information for an intrinsic function.
class Intrinsic : public Castable<Intrinsic, CallTarget> {
public:
@@ -129,6 +134,9 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @returns true if intrinsic is a barrier intrinsic
bool IsBarrier() const;
/// @returns true if intrinsic is a atomic intrinsic
bool IsAtomic() const;
private:
IntrinsicType const type_;
PipelineStageSet const supported_stages_;