-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
33 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
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
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,25 @@ | ||
#include <metal_stdlib> | ||
using namespace metal; | ||
|
||
struct Node { | ||
float2 position; | ||
float2 velocity; | ||
float2 fixation; | ||
}; | ||
|
||
kernel void applyCenterForce( | ||
device Node* nodes [[ buffer(0) ]], | ||
constant float2& center [[ buffer(1) ]], | ||
constant float& strength [[ buffer(2) ]], | ||
uint id [[ thread_position_in_grid ]], | ||
uint nodeCount [[ threads_per_grid ]]) | ||
{ | ||
float2 meanPosition = float2(0.0, 0.0); | ||
for (int i = 0; i < nodeCount; ++i) { | ||
meanPosition += nodes[i].position; | ||
} | ||
meanPosition /= float(nodeCount); | ||
|
||
float2 delta = (meanPosition - center) * strength; | ||
nodes[id].position -= delta; | ||
} |
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,28 @@ | ||
import Foundation | ||
import Metal | ||
import simd | ||
import MetalPerformanceShaders | ||
|
||
|
||
final public class MPSSimulation { | ||
init() { | ||
guard let device = MTLCreateSystemDefaultDevice() else { | ||
fatalError("") | ||
} | ||
|
||
guard let commandQueue = device.makeCommandQueue() else { | ||
fatalError("") | ||
} | ||
|
||
let library = device.makeDefaultLibrary() | ||
|
||
let function = library?.makeFunction(name: "") | ||
|
||
var pipelineState: MTLComputePipelineState | ||
do { | ||
pipelineState = try device.makeComputePipelineState(function: function!) | ||
} catch { | ||
fatalError("") | ||
} | ||
} | ||
} |
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