-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
108 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import MetalKit | ||
import SwiftUI | ||
|
||
// BlitBuffer pass | ||
class BlitBufferPass: MetalPass{ | ||
let component: BlitBuffer | ||
|
||
init(_ component: BlitBuffer){ | ||
self.component = component | ||
} | ||
func setup(device: MTLDevice, library: MTLLibrary){ | ||
} | ||
func encode(_ commandBuffer: MTLCommandBuffer,_ drawable: CAMetalDrawable?) { | ||
|
||
guard let inBuffer = component.inBuffer | ||
else{ | ||
print("BlitBuffer: no inBuffer!") | ||
return | ||
} | ||
guard let outBuffer = component.outBuffer | ||
else{ | ||
print("BlitBuffer: no outBuffer!") | ||
return | ||
} | ||
let elementSize = inBuffer.elementSize! | ||
let count: Int | ||
if let c = component.count{ | ||
count = c | ||
}else{ | ||
count = inBuffer.count | ||
} | ||
|
||
let size = count*elementSize | ||
let inOffset = component.sourceOffset*size | ||
let outOffset = component.destinationOffset*size | ||
|
||
let blitBufferEncoder = commandBuffer.makeBlitCommandEncoder() | ||
blitBufferEncoder?.copy(from: inBuffer.buffer!, sourceOffset: inOffset, | ||
to: outBuffer.buffer!, destinationOffset: outOffset, | ||
size: size) | ||
blitBufferEncoder?.endEncoding() | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
Sources/MetalBuilder/ResultBuilderComponents/BlitBuffer.swift
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,37 @@ | ||
|
||
import MetalKit | ||
import SwiftUI | ||
|
||
/// BlitBuffer Component | ||
/// | ||
/// initializes a blit pass | ||
public struct BlitBuffer: MetalBuilderComponent{ | ||
var inBuffer: BufferContainer? | ||
var outBuffer: BufferContainer? | ||
|
||
var sourceOffset: Int = 0 | ||
var destinationOffset: Int = 0 | ||
var count: Int? | ||
|
||
public init(){ | ||
} | ||
} | ||
|
||
// chaining dunctions | ||
public extension BlitBuffer{ | ||
func source<T>(_ container: MTLBufferContainer<T>)->BlitBuffer{ | ||
var b = self | ||
b.inBuffer = container | ||
return b | ||
} | ||
func destination<T>(_ container: MTLBufferContainer<T>)->BlitBuffer{ | ||
var b = self | ||
b.outBuffer = container | ||
return b | ||
} | ||
func count(count: Int)->BlitBuffer{ | ||
var b = self | ||
b.count = count | ||
return b | ||
} | ||
} |
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