[all] Remove old compute shader code
This commit is contained in:
parent
ddc0938ae4
commit
a49c370ceb
4 changed files with 0 additions and 117 deletions
|
@ -21,7 +21,6 @@
|
||||||
C0BBE3AA1F2E91D900E68524 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3A91F2E91D900E68524 /* Shaders.metal */; };
|
C0BBE3AA1F2E91D900E68524 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3A91F2E91D900E68524 /* Shaders.metal */; };
|
||||||
C0BBE3AC1F2E941200E68524 /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3AB1F2E941200E68524 /* Renderer.swift */; };
|
C0BBE3AC1F2E941200E68524 /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3AB1F2E941200E68524 /* Renderer.swift */; };
|
||||||
C0BBE3AD1F30CD7E00E68524 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0BBE3A71F2E893A00E68524 /* MetalKit.framework */; };
|
C0BBE3AD1F30CD7E00E68524 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0BBE3A71F2E893A00E68524 /* MetalKit.framework */; };
|
||||||
C0BBE3AF1F314C8200E68524 /* SamplingKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3AE1F314C8200E68524 /* SamplingKernel.metal */; };
|
|
||||||
C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0CE7BFF1F362C3F001516B6 /* Geometry.swift */; };
|
C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0CE7BFF1F362C3F001516B6 /* Geometry.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
@ -62,7 +61,6 @@
|
||||||
C0BBE3A71F2E893A00E68524 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; };
|
C0BBE3A71F2E893A00E68524 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; };
|
||||||
C0BBE3A91F2E91D900E68524 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
|
C0BBE3A91F2E91D900E68524 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
|
||||||
C0BBE3AB1F2E941200E68524 /* Renderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Renderer.swift; sourceTree = "<group>"; };
|
C0BBE3AB1F2E941200E68524 /* Renderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Renderer.swift; sourceTree = "<group>"; };
|
||||||
C0BBE3AE1F314C8200E68524 /* SamplingKernel.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = SamplingKernel.metal; sourceTree = "<group>"; };
|
|
||||||
C0CE7BFF1F362C3F001516B6 /* Geometry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Geometry.swift; sourceTree = "<group>"; };
|
C0CE7BFF1F362C3F001516B6 /* Geometry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Geometry.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
@ -155,7 +153,6 @@
|
||||||
C0BBE38F1F2E81B600E68524 /* Info.plist */,
|
C0BBE38F1F2E81B600E68524 /* Info.plist */,
|
||||||
C0BBE3A31F2E81C700E68524 /* Metaballs.swift */,
|
C0BBE3A31F2E81C700E68524 /* Metaballs.swift */,
|
||||||
C0CE7BFF1F362C3F001516B6 /* Geometry.swift */,
|
C0CE7BFF1F362C3F001516B6 /* Geometry.swift */,
|
||||||
C0BBE3AE1F314C8200E68524 /* SamplingKernel.metal */,
|
|
||||||
);
|
);
|
||||||
path = MetaballsKit;
|
path = MetaballsKit;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -376,7 +373,6 @@
|
||||||
files = (
|
files = (
|
||||||
C0BBE3A41F2E81C700E68524 /* Metaballs.swift in Sources */,
|
C0BBE3A41F2E81C700E68524 /* Metaballs.swift in Sources */,
|
||||||
C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */,
|
C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */,
|
||||||
C0BBE3AF1F314C8200E68524 /* SamplingKernel.metal in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -86,22 +86,11 @@ class Renderer: NSObject, MTKViewDelegate {
|
||||||
Vertex(position: Point(x: 1, y: 1), textureCoordinate: Point(x: 1, y: 1))
|
Vertex(position: Point(x: 1, y: 1), textureCoordinate: Point(x: 1, y: 1))
|
||||||
]
|
]
|
||||||
|
|
||||||
// do {
|
|
||||||
// try field.updateBuffers()
|
|
||||||
// } catch let e {
|
|
||||||
// NSLog("Error updating buffers: \(e)")
|
|
||||||
// }
|
|
||||||
field.update()
|
field.update()
|
||||||
|
|
||||||
let buffer = commandQueue.makeCommandBuffer()
|
let buffer = commandQueue.makeCommandBuffer()
|
||||||
buffer.label = "Render"
|
buffer.label = "Render"
|
||||||
|
|
||||||
// do {
|
|
||||||
// let _ = try field.computeEncoderForSamplingKernel(withDevice: device, commandBuffer: buffer)
|
|
||||||
// } catch let e {
|
|
||||||
// print("\(e)")
|
|
||||||
// }
|
|
||||||
|
|
||||||
if let renderPass = view.currentRenderPassDescriptor {
|
if let renderPass = view.currentRenderPassDescriptor {
|
||||||
let encoder = buffer.makeRenderCommandEncoder(descriptor: renderPass)
|
let encoder = buffer.makeRenderCommandEncoder(descriptor: renderPass)
|
||||||
encoder.label = "Render Pass"
|
encoder.label = "Render Pass"
|
||||||
|
|
|
@ -113,14 +113,8 @@ public class Field {
|
||||||
// MARK: - Metal Configuration
|
// MARK: - Metal Configuration
|
||||||
|
|
||||||
private var device: MTLDevice?
|
private var device: MTLDevice?
|
||||||
// private var sampleComputeState: MTLComputePipelineState?
|
|
||||||
public private(set) var parametersBuffer: MTLBuffer?
|
public private(set) var parametersBuffer: MTLBuffer?
|
||||||
public private(set) var ballBuffer: MTLBuffer?
|
public private(set) var ballBuffer: MTLBuffer?
|
||||||
// public private(set) var sampleTexture: MTLTexture?
|
|
||||||
|
|
||||||
// private var threadgroupCount = MTLSize()
|
|
||||||
// TODO: It might be possible to (more dynamically) right-size this.
|
|
||||||
// private var threadgroupSize = MTLSize(width: 16, height: 16, depth: 1)
|
|
||||||
|
|
||||||
/// Create the Metal buffer containing basic parameters of the simulation.
|
/// Create the Metal buffer containing basic parameters of the simulation.
|
||||||
private func populateParametersBuffer() {
|
private func populateParametersBuffer() {
|
||||||
|
@ -176,29 +170,6 @@ public class Field {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Metal texture to hold sample values created by the sampling compute shader.
|
|
||||||
/// @param device The Metal device to use to create the texture.
|
|
||||||
/// @return A new texture.
|
|
||||||
// private func makeSampleTextureIfNeeded(withDevice device: MTLDevice) -> MTLTexture? {
|
|
||||||
// if sampleTexture == nil {
|
|
||||||
// let desc = MTLTextureDescriptor()
|
|
||||||
// desc.pixelFormat = .r16Float
|
|
||||||
// desc.width = Int(size.width)
|
|
||||||
// desc.height = Int(size.height)
|
|
||||||
// desc.usage = [.shaderWrite, .shaderRead]
|
|
||||||
// sampleTexture = device.makeTexture(descriptor: desc)
|
|
||||||
// }
|
|
||||||
// return sampleTexture
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// Update the threadgroup divisions based on the size of the field.
|
|
||||||
/// @param size The size of the field.
|
|
||||||
// private func updateThreadgroupSizes(withFieldSize size: CGSize) {
|
|
||||||
// let width = Int(size.width)
|
|
||||||
// let height = Int(size.height)
|
|
||||||
// threadgroupCount = MTLSize(width: width + threadgroupSize.width - 1, height: height + threadgroupSize.height - 1, depth: 1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
private func write<T>(value: inout T, to ptr: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
|
private func write<T>(value: inout T, to ptr: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
|
||||||
let sizeOfType = MemoryLayout<T>.stride
|
let sizeOfType = MemoryLayout<T>.stride
|
||||||
ptr.copyBytes(from: &value, count: sizeOfType)
|
ptr.copyBytes(from: &value, count: sizeOfType)
|
||||||
|
@ -211,40 +182,7 @@ public class Field {
|
||||||
}
|
}
|
||||||
NSLog("Setting up Metal")
|
NSLog("Setting up Metal")
|
||||||
self.device = device
|
self.device = device
|
||||||
// sampleComputeState = try computePipelineStateForSamplingKernel(withDevice: device)
|
|
||||||
populateParametersBuffer()
|
populateParametersBuffer()
|
||||||
populateBallBuffer()
|
populateBallBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// public func computePipelineStateForSamplingKernel(withDevice device: MTLDevice) throws -> MTLComputePipelineState? {
|
|
||||||
// let bundle = Bundle(for: type(of: self))
|
|
||||||
// let library = try device.makeDefaultLibrary(bundle: bundle)
|
|
||||||
// guard let samplingKernel = library.makeFunction(name: "sampleFieldKernel") else {
|
|
||||||
// throw MetaballsError.metalError("Unable to create sampling kernel function")
|
|
||||||
// }
|
|
||||||
// let state = try device.makeComputePipelineState(function: samplingKernel)
|
|
||||||
// return state
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public func computeEncoderForSamplingKernel(withDevice device: MTLDevice, commandBuffer buffer: MTLCommandBuffer) throws -> MTLComputeCommandEncoder {
|
|
||||||
// guard let parametersBuffer = makeParametersBufferIfNeeded(withDevice: device),
|
|
||||||
// let ballBuffer = makeBallBufferIfNeeded(withDevice: device),
|
|
||||||
// let sampleTexture = makeSampleTextureIfNeeded(withDevice: device),
|
|
||||||
// let state = sampleComputeState
|
|
||||||
// else {
|
|
||||||
// throw MetaballsError.metalError("Missing Metal buffers or compute state")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// let encoder = buffer.makeComputeCommandEncoder()
|
|
||||||
// encoder.setComputePipelineState(state)
|
|
||||||
// encoder.setBuffer(parametersBuffer, offset: 0, at: 0)
|
|
||||||
// encoder.setBuffer(ballBuffer, offset: 0, at: 1)
|
|
||||||
// encoder.setTexture(sampleTexture, at: 0)
|
|
||||||
// encoder.dispatchThreadgroups(threadgroupCount, threadsPerThreadgroup: threadgroupSize)
|
|
||||||
// encoder.endEncoding()
|
|
||||||
//
|
|
||||||
// updateParametersBuffer()
|
|
||||||
//
|
|
||||||
// return encoder
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
//
|
|
||||||
// SamplingKernel.metal
|
|
||||||
// Metaballs
|
|
||||||
//
|
|
||||||
// Created by Eryn Wells on 8/1/17.
|
|
||||||
// Copyright © 2017 Eryn Wells. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <metal_stdlib>
|
|
||||||
using namespace metal;
|
|
||||||
|
|
||||||
// TODO: This is a dupe of the Ball struct. Is there a way to DRY this?
|
|
||||||
typedef struct {
|
|
||||||
float radius;
|
|
||||||
float2 position;
|
|
||||||
float2 velocity;
|
|
||||||
} Ball;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int2 size;
|
|
||||||
int numberOfBalls;
|
|
||||||
} Parameters;
|
|
||||||
|
|
||||||
kernel void
|
|
||||||
sampleFieldKernel(constant Parameters& parameters [[buffer(0)]],
|
|
||||||
constant Ball* balls [[buffer(1)]],
|
|
||||||
texture2d<half, access::write> samples [[texture(0)]],
|
|
||||||
uint2 gid [[thread_position_in_grid]])
|
|
||||||
{
|
|
||||||
float sample = 0.0;
|
|
||||||
// TODO: Get number of metaballs.
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
constant Ball& ball = balls[i];
|
|
||||||
float r2 = ball.radius * ball.radius;
|
|
||||||
float xDiff = gid[0] - ball.position[0];
|
|
||||||
float yDiff = gid[1] - ball.position[1];
|
|
||||||
sample += r2 / ((xDiff * xDiff) + (yDiff * yDiff));
|
|
||||||
}
|
|
||||||
samples.write(sample, gid);
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue