-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metal] Move Metal shader code to shaders/ folder (#611)
- Loading branch information
Showing
5 changed files
with
109 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
using atomic_int = int; | ||
using atomic_uint = unsigned int; | ||
|
||
namespace metal { | ||
|
||
using memory_order = bool; | ||
memory_order memory_order_relaxed = false; | ||
|
||
} // namespace metal | ||
|
||
template <typename T> | ||
bool atomic_compare_exchange_weak_explicit(T *object, T *expected, T desired, | ||
metal::memory_order) { | ||
const T val = *object; | ||
if (val == *expected) { | ||
*object = desired; | ||
return true; | ||
} | ||
*expected = val; | ||
return false; | ||
} | ||
|
||
template <typename T> | ||
bool atomic_fetch_or_explicit(T *object, T operand, metal::memory_order) { | ||
const T result = *object; | ||
*object = (result | operand); | ||
return result; | ||
} | ||
|
||
template <typename T> | ||
bool atomic_fetch_and_explicit(T *object, T operand, metal::memory_order) { | ||
const T result = *object; | ||
*object = (result & operand); | ||
return result; | ||
} | ||
|
||
template <typename T> | ||
T atomic_fetch_add_explicit(T *object, T operand, metal::memory_order) { | ||
const T result = *object; | ||
*object += operand; | ||
return result; | ||
} | ||
|
||
template <typename T> | ||
T atomic_load_explicit(T *object, metal::memory_order) { | ||
return *object; | ||
} | ||
|
||
template <typename T> | ||
void atomic_store_explicit(T *object, T desired, metal::memory_order) { | ||
*object = desired; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#undef device | ||
#undef constant | ||
#undef thread | ||
#undef kernel | ||
|
||
#undef byte | ||
|
||
#undef STR2 | ||
#undef STR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifdef TI_INSIDE_METAL_CODEGEN | ||
|
||
#ifndef TI_METAL_NESTED_INCLUDE | ||
#define STR2(...) #__VA_ARGS__ | ||
#define STR(...) STR2(__VA_ARGS__) | ||
#else | ||
// If we are emitting to Metal source code, and the shader file is included by | ||
// some other shader file, then skip emitting the code for the nested shader, | ||
// otherwise there could be a symbol redefinition error. That is, we only emit | ||
// the source code for the shader being directly included by the host side. | ||
#define STR(...) | ||
#endif // TI_METAL_NESTED_INCLUDE | ||
|
||
#else | ||
|
||
#include <cstdint> | ||
|
||
#define STR(...) __VA_ARGS__ | ||
|
||
#define device | ||
#define constant | ||
#define thread | ||
#define kernel | ||
|
||
#define byte char | ||
|
||
#include "taichi/platform/metal/shaders/atomic_stubs.h" | ||
|
||
#endif // TI_INSIDE_METAL_CODEGEN |