Merge 4ab9c9a0e8 into d3ac3f86f3
This commit is contained in:
commit
a827d8a7de
|
|
@ -17,7 +17,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='macos' executeOnSourceChanges='false'>
|
||||
<playground version='5.0' target-platform='macos'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
||||
|
|
@ -29,7 +29,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
let input: String?
|
||||
let library: MTLLibrary
|
||||
let vert_func: MTLFunction
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func createPipeline() {
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
let input: String?
|
||||
let library: MTLLibrary
|
||||
let vert_func: MTLFunction
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
func registerShaders() {
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
func registerShaders() {
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
|
||||
func registerShaders() {
|
||||
queue = device!.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
|
||||
func registerShaders() {
|
||||
queue = device!.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
|
||||
func registerShaders() {
|
||||
queue = device!.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class Render : NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
class func buildRenderPipelineWithDevice(device: MTLDevice, view: MTKView) throws -> MTLRenderPipelineState {
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { fatalError() }
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
let vertexFunction = library.makeFunction(name: "vertex_transform")
|
||||
|
|
@ -54,7 +54,7 @@ public class Render : NSObject, MTKViewDelegate {
|
|||
pipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
return try device.makeRenderPipelineState(descriptor: pipelineDescriptor)
|
||||
}
|
||||
|
||||
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
kernel void k(texture2d<float,access::write> o[[texture(0)]],
|
||||
uint2 gid[[thread_position_in_grid]]) {
|
||||
int width = o.get_width();
|
||||
int height = o.get_height();
|
||||
float2 uv = float2(gid) / float2(width, height);
|
||||
float3 color = mix(float3(1.0, 0.6, 0.1), float3(0.5, 0.8, 1.0), sqrt(1 - uv.y));
|
||||
float2 q = uv - float2(0.67, 0.25);
|
||||
float r = 0.2 + 0.1 * cos(atan2(q.x, q.y) * 9.0 + 20.0 * q.x);
|
||||
color *= smoothstep(r, r + 0.01, length(q));
|
||||
r = 0.03 + 0.002 * cos(120.0 * q.y) + exp(-50.0 * (1.0 - uv.y));
|
||||
color *= 1.0 - (1.0 - smoothstep(r, r + 0.002, abs(q.x - 0.25 * sin(2.0 * q.y)))) * smoothstep(0.0, 0.1, q.y);
|
||||
o.write(float4(color, 1.0), gid);
|
||||
}
|
||||
|
|
@ -13,7 +13,9 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
view.colorPixelFormat = .bgra8Unorm
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device.makeCommandQueue()
|
||||
let library = try! device.makeLibrary(source: shader, options: nil)
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { fatalError() }
|
||||
let input = try! String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try! device.makeLibrary(source: input, options: nil)
|
||||
let function = library.makeFunction(name:"k")!
|
||||
cps = try! device.makeComputePipelineState(function: function)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class Renderer: NSObject, MTKViewDelegate {
|
|||
queue = device.makeCommandQueue()
|
||||
let textureLoader = MTKTextureLoader(device: device)
|
||||
let url = Bundle.main.url(forResource: "nature", withExtension: "jpg")!
|
||||
guard let file = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let file = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let source = try String(contentsOfFile: file, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: source, options: nil)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='6.0' target-platform='macos' executeOnSourceChanges='false'/>
|
||||
<playground version='6.0' target-platform='macos'/>
|
||||
|
|
@ -11,7 +11,7 @@ guard let outBuffer = device.makeBuffer(bytes: myVector, length: length, options
|
|||
for (index, _) in myVector.enumerated() { myVector[index] = Float(index) }
|
||||
var inBuffer = device.makeBuffer(bytes: myVector, length: length, options: [])
|
||||
|
||||
let path = Bundle.main.path(forResource: "memory", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "memory", ofType: "txt")
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
let function = library.makeFunction(name: "compute")!
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='macos' executeOnSourceChanges='false'>
|
||||
<playground version='5.0' target-platform='macos'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
version = "3.0">
|
||||
<TimelineItems>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "file:///Users/mhorga/Desktop/metal/memory/memory_1.playground#CharacterRangeLen=2&CharacterRangeLoc=1554&EndingColumnNumber=14&EndingLineNumber=32&StartingColumnNumber=12&StartingLineNumber=32&Timestamp=528665184.878259"
|
||||
documentLocation = "file:///Users/matcegiela/Code/Metal/metal/memory/memory_1.playground#CharacterRangeLen=2&CharacterRangeLoc=1552&EndingColumnNumber=14&EndingLineNumber=32&StartingColumnNumber=12&StartingLineNumber=32&Timestamp=683824809.957611"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class MetalViewDelegate: NSObject, MTKViewDelegate {
|
|||
initializeBuffers()
|
||||
let library: MTLLibrary
|
||||
do {
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
let source = try String(contentsOfFile: path!, encoding: .utf8)
|
||||
library = try device.makeLibrary(source: source, options: nil)
|
||||
let descriptor = MTLRenderPipelineDescriptor()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
func initializeMetal() {
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
queue = device.makeCommandQueue()
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
func registerShaders() {
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device.makeCommandQueue()
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
|
||||
let path = Bundle.main.path(forResource: "Shaders", ofType: "txt")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class MetalView: NSObject, MTKViewDelegate {
|
|||
}
|
||||
|
||||
func registerShaders() {
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
|
||||
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "txt") else { return }
|
||||
do {
|
||||
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
|
||||
let library = try device.makeLibrary(source: input, options: nil)
|
||||
|
|
|
|||
Loading…
Reference in New Issue